dom-render
Advanced tools
Comparing version 1.0.11 to 1.0.12
import { Scope } from './Scope'; | ||
import { ScopeObject } from './ScopeObject'; | ||
export declare class Config { | ||
factoryScopeObject?: ((scope: Scope) => ScopeObject | undefined) | undefined; | ||
export declare type ScopeObjectFactory = (scope: Scope) => ScopeObject; | ||
export interface ConfigParam { | ||
factoryScopeObject?: ScopeObjectFactory; | ||
applyEvent?: (obj: any, elements: Element[]) => void; | ||
changeVar?: (obj: any, elements: Element[], varName: string) => void; | ||
targetAttributeNames?: string[]; | ||
} | ||
export declare class Config implements ConfigParam { | ||
start: string; | ||
end: string; | ||
constructor(factoryScopeObject?: ((scope: Scope) => ScopeObject | undefined) | undefined); | ||
factoryScopeObject?: ScopeObjectFactory; | ||
applyEvent?: (obj: any, elements: Element[]) => void; | ||
changeVar?: (obj: any, elements: Element[], varName: string) => void; | ||
targetAttributeNames?: string[]; | ||
constructor(configPram?: ConfigParam); | ||
} |
@@ -5,6 +5,9 @@ "use strict"; | ||
var Config = (function () { | ||
function Config(factoryScopeObject) { | ||
this.factoryScopeObject = factoryScopeObject; | ||
function Config(configPram) { | ||
this.start = '<!--%'; | ||
this.end = '%-->'; | ||
this.factoryScopeObject = configPram === null || configPram === void 0 ? void 0 : configPram.factoryScopeObject; | ||
this.applyEvent = configPram === null || configPram === void 0 ? void 0 : configPram.applyEvent; | ||
this.changeVar = configPram === null || configPram === void 0 ? void 0 : configPram.changeVar; | ||
this.targetAttributeNames = configPram === null || configPram === void 0 ? void 0 : configPram.targetAttributeNames; | ||
} | ||
@@ -11,0 +14,0 @@ return Config; |
@@ -50,5 +50,6 @@ 'use strict'; | ||
} | ||
class_1.prototype.findAttrElements = function (fragment) { | ||
class_1.prototype.findAttrElements = function (fragment, addAttributes) { | ||
if (addAttributes === void 0) { addAttributes = []; } | ||
var datas = []; | ||
this.attrNames.forEach(function (attrName) { | ||
addAttributes.concat(this.attrNames).forEach(function (attrName) { | ||
fragment.querySelectorAll("[" + attrName + "]").forEach(function (it) { | ||
@@ -60,4 +61,5 @@ datas.push({ name: attrName, value: it.getAttribute(attrName), element: it }); | ||
}; | ||
class_1.prototype.applyEvent = function (obj, childNodes) { | ||
class_1.prototype.applyEvent = function (obj, childNodes, config) { | ||
var _this = this; | ||
var _a; | ||
var elements = childNodes.filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; }); | ||
@@ -101,5 +103,6 @@ this.eventNames.forEach(function (it) { | ||
}); | ||
this.changeVar(obj, elements); | ||
this.changeVar(obj, elements, undefined, config); | ||
(_a = config === null || config === void 0 ? void 0 : config.applyEvent) === null || _a === void 0 ? void 0 : _a.call(config, obj, elements); | ||
}; | ||
class_1.prototype.changeVar = function (obj, elements, varName) { | ||
class_1.prototype.changeVar = function (obj, elements, varName, config) { | ||
var _this = this; | ||
@@ -122,2 +125,3 @@ this.procAttr(elements, this.attrPrefix + 'value-link', function (it, attribute) { | ||
var script = attribute; | ||
console.log('-atttt'); | ||
if (_this.isUsingThisVar(attribute, varName) || varName === undefined) { | ||
@@ -146,2 +150,5 @@ var data = (_a = Function("\"use strict\"; " + script + " ").bind(obj)()) !== null && _a !== void 0 ? _a : {}; | ||
}); | ||
if ((config === null || config === void 0 ? void 0 : config.changeVar) && varName) { | ||
config.changeVar(obj, elements.filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; }), varName); | ||
} | ||
}; | ||
@@ -161,3 +168,3 @@ class_1.prototype.addDrEvent = function (obj, eventName, elements) { | ||
if (elements === void 0) { elements = []; } | ||
elements.forEach(function (it) { | ||
elements === null || elements === void 0 ? void 0 : elements.forEach(function (it) { | ||
if (!it) { | ||
@@ -195,3 +202,3 @@ return; | ||
if (varName && raws) { | ||
for (var _i = 0, _a = Array.from(new Set(this.usingThisVar(varName)).values()); _i < _a.length; _i++) { | ||
for (var _i = 0, _a = this.usingThisVar(raws); _i < _a.length; _i++) { | ||
var raw = _a[_i]; | ||
@@ -211,8 +218,10 @@ if (raw.startsWith(varName)) { | ||
var varExec = varRegex.exec(raws); | ||
var usingVars = []; | ||
var usingVars = new Set(); | ||
while (varExec) { | ||
usingVars.push(varExec[1].replace('?', '')); | ||
var value = varExec[1].replace(/\?/g, ''); | ||
usingVars.add(value); | ||
value.split('.').forEach(function (it) { return usingVars.add(it); }); | ||
varExec = varRegex.exec(varExec.input); | ||
} | ||
return usingVars; | ||
return Array.from(usingVars); | ||
}; | ||
@@ -260,3 +269,3 @@ return class_1; | ||
ScopeResultSet.prototype.applyEvent = function () { | ||
eventManager.applyEvent(this.object._originObj, this.childNodes); | ||
eventManager.applyEvent(this.object._originObj, this.childNodes, this.object._scope.config); | ||
}; | ||
@@ -384,3 +393,3 @@ return ScopeResultSet; | ||
this._calls = []; | ||
this._writes = ''; | ||
this._writes = []; | ||
} | ||
@@ -390,11 +399,13 @@ ScopeObject.prototype.executeResultSet = function (script) { | ||
this.eval(script); | ||
var templateElement = this._scope.raws.document.createElement('template'); | ||
templateElement.innerHTML = this._writes; | ||
var startComment = this._scope.raws.document.createComment('scope start ' + this._uuid); | ||
var endComment = this._scope.raws.document.createComment('scope end ' + this._uuid); | ||
templateElement.content.childNodes.forEach(function (it) { | ||
if (it.nodeType === 1) { | ||
it.setAttribute('scope-uuid', _this._uuid); | ||
} | ||
}); | ||
var templateElement = this._scope.raws.document.createElement('template'); | ||
if (this._writes.length) { | ||
templateElement.innerHTML = this._writes.join(''); | ||
templateElement.content.childNodes.forEach(function (it) { | ||
if (it.nodeType === 1) { | ||
it.setAttribute('scope-uuid', _this._uuid); | ||
} | ||
}); | ||
} | ||
return new ScopeResultSet(this._uuid, this, templateElement.content, startComment, endComment, this._calls); | ||
@@ -406,7 +417,4 @@ }; | ||
ScopeObject.prototype.scopeEval = function (scope, script) { | ||
return Function("\"use strict\";\n const write = (str) => {\n this._appendWrite(str);\n };\n \n const include = (target) => {\n const uuid = this._makeUUID();\n const targetNode = this.getTargetNode(uuid);\n const rootScope = this._compileRootScope(target, targetNode, uuid);\n this._calls.push({name: 'include', parameter: [target], result: rootScope})\n \n if (rootScope) {\n this._appendWrite(\"<template include-scope-uuid='\" + uuid + \"'></template>\");\n }\n }\n \n " + this.customScript() + "\n \n " + script + "\n ").bind(scope)(); | ||
return Function("\"use strict\";\n const write = (str) => {\n this._writes.push(str);\n };\n \n const include = (target) => {\n const uuid = this._makeUUID();\n const targetNode = this.getTargetNode(uuid);\n const rootScope = this._compileRootScope(target, targetNode, uuid);\n this._calls.push({name: 'include', parameter: [target], result: rootScope})\n if (rootScope) {\n this._writes.push(\"<template include-scope-uuid='\" + uuid + \"'></template>\");\n }\n }\n \n " + this.customScript() + "\n \n " + script + "\n ").bind(scope)(); | ||
}; | ||
ScopeObject.prototype._appendWrite = function (str) { | ||
this._writes += str; | ||
}; | ||
ScopeObject.prototype._makeUUID = function () { | ||
@@ -418,3 +426,3 @@ return RandomUtils.uuid(); | ||
console.error('no Domrander Proxy Object -> var proxy = Domrender.proxy(target, ScopeRawSet)', target); | ||
return new Error('no Domrander compile Object'); | ||
throw new Error('no Domrander compile Object'); | ||
} | ||
@@ -434,6 +442,9 @@ var rawSet = target._ScopeObjectProxyHandler_rawSet; | ||
var Config = (function () { | ||
function Config(factoryScopeObject) { | ||
this.factoryScopeObject = factoryScopeObject; | ||
function Config(configPram) { | ||
this.start = '<!--%'; | ||
this.end = '%-->'; | ||
this.factoryScopeObject = configPram === null || configPram === void 0 ? void 0 : configPram.factoryScopeObject; | ||
this.applyEvent = configPram === null || configPram === void 0 ? void 0 : configPram.applyEvent; | ||
this.changeVar = configPram === null || configPram === void 0 ? void 0 : configPram.changeVar; | ||
this.targetAttributeNames = configPram === null || configPram === void 0 ? void 0 : configPram.targetAttributeNames; | ||
} | ||
@@ -659,3 +670,3 @@ return Config; | ||
if (this.scopeResult) { | ||
eventManager.changeVar(this.obj, this.scopeResult.childNodes, path); | ||
eventManager.changeVar(this.obj, this.scopeResult.childNodes, path, this.config); | ||
} | ||
@@ -699,3 +710,3 @@ }; | ||
childNodes.push(((_a = this.targetNode.node) !== null && _a !== void 0 ? _a : this.raws.document.body)); | ||
eventManager.findAttrElements(fragment).forEach(function (it) { | ||
eventManager.findAttrElements(fragment, this.config.targetAttributeNames).forEach(function (it) { | ||
childNodes.push(it.element); | ||
@@ -753,23 +764,36 @@ }); | ||
var ScopeObjectProxyHandler = (function () { | ||
function ScopeObjectProxyHandler(_rawSet) { | ||
function ScopeObjectProxyHandler(_rawSet, _targetOrigin, _excludeTyps) { | ||
if (_excludeTyps === void 0) { _excludeTyps = []; } | ||
this._rawSet = _rawSet; | ||
this._targetOrigin = _targetOrigin; | ||
this._excludeTyps = _excludeTyps; | ||
this._refs = []; | ||
this._rootScopes = new Map(); | ||
} | ||
ScopeObjectProxyHandler.prototype.run = function (_targetProxy, _targetOrigin, _rootScope) { | ||
ScopeObjectProxyHandler.prototype.run = function (_targetProxy, _rootScope) { | ||
var _this = this; | ||
this._targetProxy = _targetProxy; | ||
this._targetOrigin = _targetOrigin; | ||
if (_rootScope) { | ||
this._rootScopes.set(_rootScope.uuid, _rootScope); | ||
} | ||
var data = Object.keys(_targetOrigin) || []; | ||
data.forEach(function (it) { | ||
var data = Object.keys(this._targetOrigin) || []; | ||
data.filter(function (it) { return _this.isProxyTarget(_this._targetOrigin[it]); }).forEach(function (it) { | ||
_this._targetOrigin[it] = _this.proxy(_this._targetOrigin[it]); | ||
}); | ||
}; | ||
ScopeObjectProxyHandler.prototype.isProxyTarget = function (target) { | ||
var sw = false; | ||
if (target !== undefined && target !== null && | ||
typeof target === 'object' && | ||
!('_ScopeObjectProxyHandler_isProxy' in target) && | ||
!(target instanceof Scope) && | ||
this._excludeTyps.filter(function (it) { return target instanceof it; }).length === 0) { | ||
sw = true; | ||
} | ||
return sw; | ||
}; | ||
ScopeObjectProxyHandler.prototype.proxy = function (target) { | ||
var _a; | ||
if (typeof target === 'object' && !('_ScopeObjectProxyHandler_isProxy' in target) && !(target instanceof Scope)) { | ||
var scopeObjectProxyHandler = new ScopeObjectProxyHandler(this._rawSet); | ||
if (this.isProxyTarget(target)) { | ||
var scopeObjectProxyHandler = new ScopeObjectProxyHandler(this._rawSet, target); | ||
scopeObjectProxyHandler._refs.push(this._targetProxy); | ||
@@ -906,3 +930,3 @@ var targetProxy = new Proxy(target, scopeObjectProxyHandler); | ||
var root = new RootScope(scopeRaws, proxy, uuid, config, targetNode); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, target, root); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, root); | ||
return { target: proxy, rootScope: root }; | ||
@@ -913,3 +937,16 @@ }; | ||
}; | ||
DomRender.proxy = function (target, raws) { | ||
DomRender.proxyObjectRender = function (proxy, targetNode, config) { | ||
var _a, _b; | ||
if (config === void 0) { config = new Config(); } | ||
if (!('_ScopeObjectProxyHandler_isProxy' in proxy)) { | ||
console.error('no Domrander Proxy Object -> var proxy = Domrender.proxy(target, ScopeRawSet)', proxy); | ||
throw new Error('no Domrander compile Object'); | ||
} | ||
var raws = proxy._ScopeObjectProxyHandler_rawSet; | ||
var rootScope = new RootScope(new ScopeRawSet(document, raws.template, raws.styles), proxy, RandomUtils.uuid(), config, targetNode); | ||
(_b = (_a = proxy) === null || _a === void 0 ? void 0 : _a._ScopeObjectProxyHandler) === null || _b === void 0 ? void 0 : _b.run(proxy, rootScope); | ||
rootScope.executeRender(); | ||
}; | ||
DomRender.proxy = function (target, raws, excludeTyps) { | ||
if (excludeTyps === void 0) { excludeTyps = []; } | ||
var proxy; | ||
@@ -920,3 +957,3 @@ if ('_ScopeObjectProxyHandler_isProxy' in target) { | ||
else { | ||
proxy = new Proxy(target, new ScopeObjectProxyHandler(raws)); | ||
proxy = new Proxy(target, new ScopeObjectProxyHandler(raws, target, excludeTyps)); | ||
} | ||
@@ -923,0 +960,0 @@ return proxy; |
import { RootScope, TargetNode } from './RootScope'; | ||
import { Config } from './Config'; | ||
import { ConstructorType } from '../../simple-boot-core/dist/types/Types'; | ||
export declare type RawSet = { | ||
@@ -13,5 +14,6 @@ template: string; | ||
static compileRootScope<T>(document: Document, target: T, raws: RawSet, config: Config, targetNode?: TargetNode, uuid?: string): RootScope; | ||
static proxy<T>(target: T, raws: RawSet): T; | ||
static proxyObjectRender<T = any>(proxy: T, targetNode: TargetNode, config?: Config): void; | ||
static proxy<T>(target: T, raws: RawSet, excludeTyps?: ConstructorType<any>[]): T; | ||
static render<T>(document: Document, target: T, raws: RawSet, config: Config, targetNode?: TargetNode): T; | ||
static renderTarget<T>(target: T, document: Document, selector: string): T; | ||
} |
@@ -18,3 +18,3 @@ "use strict"; | ||
var root = new RootScope_1.RootScope(scopeRaws, proxy, uuid, config, targetNode); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, target, root); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, root); | ||
return { target: proxy, rootScope: root }; | ||
@@ -25,3 +25,17 @@ }; | ||
}; | ||
DomRender.proxy = function (target, raws) { | ||
DomRender.proxyObjectRender = function (proxy, targetNode, config) { | ||
var _a, _b, _c; | ||
if (config === void 0) { config = new Config_1.Config(); } | ||
if (!('_ScopeObjectProxyHandler_isProxy' in proxy)) { | ||
console.error('no Domrander Proxy Object -> var proxy = Domrender.proxy(target, ScopeRawSet)', proxy); | ||
throw new Error('no Domrander compile Object'); | ||
} | ||
var raws = proxy._ScopeObjectProxyHandler_rawSet; | ||
var rootScope = new RootScope_1.RootScope(new ScopeRawSet_1.ScopeRawSet(document, raws.template, raws.styles), proxy, RandomUtils_1.RandomUtils.uuid(), config, targetNode); | ||
(_b = (_a = proxy) === null || _a === void 0 ? void 0 : _a._ScopeObjectProxyHandler) === null || _b === void 0 ? void 0 : _b.run(proxy, rootScope); | ||
var targetObj = (_c = proxy._ScopeObjectProxyHandler_targetOrigin) !== null && _c !== void 0 ? _c : proxy; | ||
rootScope.executeRender(); | ||
}; | ||
DomRender.proxy = function (target, raws, excludeTyps) { | ||
if (excludeTyps === void 0) { excludeTyps = []; } | ||
var proxy; | ||
@@ -32,3 +46,3 @@ if ('_ScopeObjectProxyHandler_isProxy' in target) { | ||
else { | ||
proxy = new Proxy(target, new ScopeObjectProxyHandler_1.ScopeObjectProxyHandler(raws)); | ||
proxy = new Proxy(target, new ScopeObjectProxyHandler_1.ScopeObjectProxyHandler(raws, target, excludeTyps)); | ||
} | ||
@@ -35,0 +49,0 @@ return proxy; |
@@ -0,1 +1,2 @@ | ||
import { Config } from 'Config'; | ||
export declare const eventManager: { | ||
@@ -5,3 +6,3 @@ readonly attrPrefix: "dr-"; | ||
readonly attrNames: string[]; | ||
findAttrElements(fragment: DocumentFragment): { | ||
findAttrElements(fragment: DocumentFragment, addAttributes?: string[]): { | ||
name: string; | ||
@@ -11,4 +12,4 @@ value: string | null; | ||
}[]; | ||
applyEvent(obj: any, childNodes: ChildNode[]): void; | ||
changeVar(obj: any, elements: Element[] | ChildNode[], varName?: string | undefined): void; | ||
applyEvent(obj: any, childNodes: ChildNode[], config?: Config | undefined): void; | ||
changeVar(obj: any, elements: Element[] | ChildNode[], varName?: string | undefined, config?: Config | undefined): void; | ||
addDrEvent(obj: any, eventName: string, elements: Element[]): void; | ||
@@ -15,0 +16,0 @@ procAttr<T extends Element>(elements: Element[] | ChildNode[] | undefined, attrName: string, f: (h: T, value: string | null) => void): void; |
@@ -20,5 +20,6 @@ "use strict"; | ||
} | ||
class_1.prototype.findAttrElements = function (fragment) { | ||
class_1.prototype.findAttrElements = function (fragment, addAttributes) { | ||
if (addAttributes === void 0) { addAttributes = []; } | ||
var datas = []; | ||
this.attrNames.forEach(function (attrName) { | ||
addAttributes.concat(this.attrNames).forEach(function (attrName) { | ||
fragment.querySelectorAll("[" + attrName + "]").forEach(function (it) { | ||
@@ -30,4 +31,5 @@ datas.push({ name: attrName, value: it.getAttribute(attrName), element: it }); | ||
}; | ||
class_1.prototype.applyEvent = function (obj, childNodes) { | ||
class_1.prototype.applyEvent = function (obj, childNodes, config) { | ||
var _this = this; | ||
var _a; | ||
var elements = childNodes.filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; }); | ||
@@ -71,5 +73,6 @@ this.eventNames.forEach(function (it) { | ||
}); | ||
this.changeVar(obj, elements); | ||
this.changeVar(obj, elements, undefined, config); | ||
(_a = config === null || config === void 0 ? void 0 : config.applyEvent) === null || _a === void 0 ? void 0 : _a.call(config, obj, elements); | ||
}; | ||
class_1.prototype.changeVar = function (obj, elements, varName) { | ||
class_1.prototype.changeVar = function (obj, elements, varName, config) { | ||
var _this = this; | ||
@@ -92,2 +95,3 @@ this.procAttr(elements, this.attrPrefix + 'value-link', function (it, attribute) { | ||
var script = attribute; | ||
console.log('-atttt'); | ||
if (_this.isUsingThisVar(attribute, varName) || varName === undefined) { | ||
@@ -116,2 +120,5 @@ var data = (_a = Function("\"use strict\"; " + script + " ").bind(obj)()) !== null && _a !== void 0 ? _a : {}; | ||
}); | ||
if ((config === null || config === void 0 ? void 0 : config.changeVar) && varName) { | ||
config.changeVar(obj, elements.filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; }), varName); | ||
} | ||
}; | ||
@@ -131,3 +138,3 @@ class_1.prototype.addDrEvent = function (obj, eventName, elements) { | ||
if (elements === void 0) { elements = []; } | ||
elements.forEach(function (it) { | ||
elements === null || elements === void 0 ? void 0 : elements.forEach(function (it) { | ||
if (!it) { | ||
@@ -165,3 +172,3 @@ return; | ||
if (varName && raws) { | ||
for (var _i = 0, _a = Array.from(new Set(this.usingThisVar(varName)).values()); _i < _a.length; _i++) { | ||
for (var _i = 0, _a = this.usingThisVar(raws); _i < _a.length; _i++) { | ||
var raw = _a[_i]; | ||
@@ -181,10 +188,12 @@ if (raw.startsWith(varName)) { | ||
var varExec = varRegex.exec(raws); | ||
var usingVars = []; | ||
var usingVars = new Set(); | ||
while (varExec) { | ||
usingVars.push(varExec[1].replace('?', '')); | ||
var value = varExec[1].replace(/\?/g, ''); | ||
usingVars.add(value); | ||
value.split('.').forEach(function (it) { return usingVars.add(it); }); | ||
varExec = varRegex.exec(varExec.input); | ||
} | ||
return usingVars; | ||
return Array.from(usingVars); | ||
}; | ||
return class_1; | ||
}())(); |
{ | ||
"name": "dom-render", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"main": "DomRenderCompiler.js", | ||
@@ -56,2 +56,3 @@ "license": "MIT", | ||
"build": "rm -rf dist && tsc --outDir dist --declarationDir dist && rm -rf dist/dist && rollup -c", | ||
"build:ts:watch": "rm -rf dist && tsc --watch --outDir dist --declarationDir dist", | ||
"build:parcel": "parcel build ./src/*.ts --out-dir=dist-parcel --out-file dom-render.js", | ||
@@ -61,2 +62,3 @@ "bundle": "rollup -c", | ||
"dev:start": "npm run start --workspace=dev", | ||
"dev:serve": "npm run serve --workspace=dev", | ||
"npm-build": "npm run build && cp package.json dist && cp README.MD dist", | ||
@@ -71,2 +73,3 @@ "npm-publish": "npm run npm-build && npm publish ./dist", | ||
"@types/jest": "^26.0.22", | ||
"@types/node": "^16.4.6", | ||
"@typescript-eslint/eslint-plugin": "^4.16.1", | ||
@@ -80,2 +83,4 @@ "@typescript-eslint/parser": "^4.16.1", | ||
"jest": "^26.6.3", | ||
"parcel-bundler": "^1.12.5", | ||
"parcel-plugin-css-to-string": "^2.5.2", | ||
"rollup": "^2.52.8", | ||
@@ -85,6 +90,4 @@ "rollup-watch": "^4.3.1", | ||
"ts-jest": "^26.5.4", | ||
"parcel-bundler": "^1.12.5", | ||
"parcel-plugin-css-to-string": "^2.5.2", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
import { RootScope } from '../RootScope'; | ||
import { RawSet } from '../DomRender'; | ||
interface ConstructorType<T> { | ||
new (...args: any[]): T; | ||
} | ||
export declare type DepthType = { | ||
@@ -11,8 +14,10 @@ rootScopes: Map<string, RootScope>; | ||
_rawSet: RawSet; | ||
private _targetOrigin; | ||
private _excludeTyps; | ||
_refs: any[]; | ||
private _rootScopes; | ||
private _targetProxy?; | ||
private _targetOrigin?; | ||
constructor(_rawSet: RawSet); | ||
run(_targetProxy: any, _targetOrigin: any, _rootScope?: RootScope): void; | ||
constructor(_rawSet: RawSet, _targetOrigin: any, _excludeTyps?: ConstructorType<any>[]); | ||
run(_targetProxy: any, _rootScope?: RootScope): void; | ||
isProxyTarget(target: any): boolean; | ||
proxy(target: any): any; | ||
@@ -31,1 +36,2 @@ get(target: any, name: string, receiver: any): any; | ||
} | ||
export {}; |
@@ -8,23 +8,36 @@ "use strict"; | ||
var ScopeObjectProxyHandler = (function () { | ||
function ScopeObjectProxyHandler(_rawSet) { | ||
function ScopeObjectProxyHandler(_rawSet, _targetOrigin, _excludeTyps) { | ||
if (_excludeTyps === void 0) { _excludeTyps = []; } | ||
this._rawSet = _rawSet; | ||
this._targetOrigin = _targetOrigin; | ||
this._excludeTyps = _excludeTyps; | ||
this._refs = []; | ||
this._rootScopes = new Map(); | ||
} | ||
ScopeObjectProxyHandler.prototype.run = function (_targetProxy, _targetOrigin, _rootScope) { | ||
ScopeObjectProxyHandler.prototype.run = function (_targetProxy, _rootScope) { | ||
var _this = this; | ||
this._targetProxy = _targetProxy; | ||
this._targetOrigin = _targetOrigin; | ||
if (_rootScope) { | ||
this._rootScopes.set(_rootScope.uuid, _rootScope); | ||
} | ||
var data = Object.keys(_targetOrigin) || []; | ||
data.forEach(function (it) { | ||
var data = Object.keys(this._targetOrigin) || []; | ||
data.filter(function (it) { return _this.isProxyTarget(_this._targetOrigin[it]); }).forEach(function (it) { | ||
_this._targetOrigin[it] = _this.proxy(_this._targetOrigin[it]); | ||
}); | ||
}; | ||
ScopeObjectProxyHandler.prototype.isProxyTarget = function (target) { | ||
var sw = false; | ||
if (target !== undefined && target !== null && | ||
typeof target === 'object' && | ||
!('_ScopeObjectProxyHandler_isProxy' in target) && | ||
!(target instanceof Scope_1.Scope) && | ||
this._excludeTyps.filter(function (it) { return target instanceof it; }).length === 0) { | ||
sw = true; | ||
} | ||
return sw; | ||
}; | ||
ScopeObjectProxyHandler.prototype.proxy = function (target) { | ||
var _a; | ||
if (typeof target === 'object' && !('_ScopeObjectProxyHandler_isProxy' in target) && !(target instanceof Scope_1.Scope)) { | ||
var scopeObjectProxyHandler = new ScopeObjectProxyHandler(this._rawSet); | ||
if (this.isProxyTarget(target)) { | ||
var scopeObjectProxyHandler = new ScopeObjectProxyHandler(this._rawSet, target); | ||
scopeObjectProxyHandler._refs.push(this._targetProxy); | ||
@@ -31,0 +44,0 @@ var targetProxy = new Proxy(target, scopeObjectProxyHandler); |
@@ -70,3 +70,3 @@ "use strict"; | ||
if (this.scopeResult) { | ||
EventManager_1.eventManager.changeVar(this.obj, this.scopeResult.childNodes, path); | ||
EventManager_1.eventManager.changeVar(this.obj, this.scopeResult.childNodes, path, this.config); | ||
} | ||
@@ -111,3 +111,3 @@ }; | ||
childNodes.push(((_a = this.targetNode.node) !== null && _a !== void 0 ? _a : this.raws.document.body)); | ||
EventManager_1.eventManager.findAttrElements(fragment).forEach(function (it) { | ||
EventManager_1.eventManager.findAttrElements(fragment, this.config.targetAttributeNames).forEach(function (it) { | ||
childNodes.push(it.element); | ||
@@ -114,0 +114,0 @@ }); |
@@ -10,3 +10,3 @@ import { ScopeResultSet } from './ScopeResultSet'; | ||
[name: string]: any; | ||
_writes: string; | ||
_writes: never[]; | ||
constructor(_scope: Scope, _uuid?: string); | ||
@@ -16,3 +16,2 @@ executeResultSet(script: string): ScopeResultSet; | ||
private scopeEval; | ||
private _appendWrite; | ||
private _makeUUID; | ||
@@ -19,0 +18,0 @@ private _compileRootScope; |
@@ -14,3 +14,3 @@ "use strict"; | ||
this._calls = []; | ||
this._writes = ''; | ||
this._writes = []; | ||
} | ||
@@ -20,11 +20,13 @@ ScopeObject.prototype.executeResultSet = function (script) { | ||
this.eval(script); | ||
var templateElement = this._scope.raws.document.createElement('template'); | ||
templateElement.innerHTML = this._writes; | ||
var startComment = this._scope.raws.document.createComment('scope start ' + this._uuid); | ||
var endComment = this._scope.raws.document.createComment('scope end ' + this._uuid); | ||
templateElement.content.childNodes.forEach(function (it) { | ||
if (it.nodeType === 1) { | ||
it.setAttribute('scope-uuid', _this._uuid); | ||
} | ||
}); | ||
var templateElement = this._scope.raws.document.createElement('template'); | ||
if (this._writes.length) { | ||
templateElement.innerHTML = this._writes.join(''); | ||
templateElement.content.childNodes.forEach(function (it) { | ||
if (it.nodeType === 1) { | ||
it.setAttribute('scope-uuid', _this._uuid); | ||
} | ||
}); | ||
} | ||
return new ScopeResultSet_1.ScopeResultSet(this._uuid, this, templateElement.content, startComment, endComment, this._calls); | ||
@@ -36,7 +38,4 @@ }; | ||
ScopeObject.prototype.scopeEval = function (scope, script) { | ||
return Function("\"use strict\";\n const write = (str) => {\n this._appendWrite(str);\n };\n \n const include = (target) => {\n const uuid = this._makeUUID();\n const targetNode = this.getTargetNode(uuid);\n const rootScope = this._compileRootScope(target, targetNode, uuid);\n this._calls.push({name: 'include', parameter: [target], result: rootScope})\n \n if (rootScope) {\n this._appendWrite(\"<template include-scope-uuid='\" + uuid + \"'></template>\");\n }\n }\n \n " + this.customScript() + "\n \n " + script + "\n ").bind(scope)(); | ||
return Function("\"use strict\";\n const write = (str) => {\n this._writes.push(str);\n };\n \n const include = (target) => {\n const uuid = this._makeUUID();\n const targetNode = this.getTargetNode(uuid);\n const rootScope = this._compileRootScope(target, targetNode, uuid);\n this._calls.push({name: 'include', parameter: [target], result: rootScope})\n if (rootScope) {\n this._writes.push(\"<template include-scope-uuid='\" + uuid + \"'></template>\");\n }\n }\n \n " + this.customScript() + "\n \n " + script + "\n ").bind(scope)(); | ||
}; | ||
ScopeObject.prototype._appendWrite = function (str) { | ||
this._writes += str; | ||
}; | ||
ScopeObject.prototype._makeUUID = function () { | ||
@@ -48,3 +47,3 @@ return RandomUtils_1.RandomUtils.uuid(); | ||
console.error('no Domrander Proxy Object -> var proxy = Domrender.proxy(target, ScopeRawSet)', target); | ||
return new Error('no Domrander compile Object'); | ||
throw new Error('no Domrander compile Object'); | ||
} | ||
@@ -51,0 +50,0 @@ var rawSet = target._ScopeObjectProxyHandler_rawSet; |
@@ -43,3 +43,3 @@ "use strict"; | ||
ScopeResultSet.prototype.applyEvent = function () { | ||
EventManager_1.eventManager.applyEvent(this.object._originObj, this.childNodes); | ||
EventManager_1.eventManager.applyEvent(this.object._originObj, this.childNodes, this.object._scope.config); | ||
}; | ||
@@ -46,0 +46,0 @@ return ScopeResultSet; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
100264
2266
1
19