dom-render 1.0.76 → 1.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ export declare class EventManager {
8
8
  static readonly valueAttrName: string;
9
9
  static readonly valueLinkAttrName: string;
10
10
  static readonly attrAttrName: string;
11
+ static readonly normalAttrMapAttrName: string;
11
12
  static readonly styleAttrName: string;
12
13
  static readonly classAttrName: string;
13
14
  readonly attrNames: string[];
@@ -37,7 +38,7 @@ export declare class EventManager {
37
38
  procAttr<T extends Element = Element>(elements: Set<Element> | Set<ChildNode> | undefined, attrName: string, callBack: (h: T, value: string, attributes: any) => void): void;
38
39
  getValue<T = any>(obj: any, name: string, bindObj?: any): T;
39
40
  setValue(obj: any, name: string, value?: any): void;
40
- isUsingThisVar(raws: string | null | undefined, varName: string | null | undefined): boolean;
41
+ static isUsingThisVar(raws: string | null | undefined, varName: string | null | undefined): boolean;
41
42
  static setBindProperty(scripts: {
42
43
  [p: string]: any;
43
44
  } | undefined, obj: any): {
@@ -18,6 +18,7 @@ var EventManager = /** @class */ (function () {
18
18
  EventManager.valueAttrName,
19
19
  EventManager.valueLinkAttrName,
20
20
  EventManager.attrAttrName,
21
+ EventManager.normalAttrMapAttrName,
21
22
  EventManager.styleAttrName,
22
23
  EventManager.classAttrName,
23
24
  EventManager.attrPrefix + 'window-event-' + EventManager.WINDOW_EVENT_POPSTATE,
@@ -59,6 +60,7 @@ var EventManager = /** @class */ (function () {
59
60
  // (obj as any)._DomRender_isFinal = true;
60
61
  // return obj;
61
62
  // }
63
+ // 중요 이벤트에 대상이될 Elements를 찾는다.
62
64
  EventManager.prototype.findAttrElements = function (fragment, config) {
63
65
  var _a, _b;
64
66
  // const datas: {name: string, value: string | null, element: Element}[] = [];
@@ -71,6 +73,7 @@ var EventManager = /** @class */ (function () {
71
73
  });
72
74
  return elements;
73
75
  };
76
+ // 중요 처음 이벤트 처리
74
77
  // eslint-disable-next-line no-undef
75
78
  EventManager.prototype.applyEvent = function (obj, childNodes, config) {
76
79
  var _this = this;
@@ -96,6 +99,18 @@ var EventManager = /** @class */ (function () {
96
99
  }
97
100
  }
98
101
  });
102
+ // normal-attr-map
103
+ this.procAttr(childNodes, EventManager.normalAttrMapAttrName, function (it, attribute) {
104
+ var map = new Map(JSON.parse(attribute));
105
+ map.forEach(function (v, k) {
106
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; return ".concat(v, " "), Object.assign(obj, {
107
+ __render: Object.freeze({
108
+ element: it
109
+ })
110
+ }));
111
+ it.setAttribute(k, data);
112
+ });
113
+ });
99
114
  // window event
100
115
  EventManager.WINDOW_EVENTS.forEach(function (it) {
101
116
  _this.procAttr(childNodes, EventManager.attrPrefix + 'window-event-' + it, function (it, attribute) {
@@ -109,7 +124,7 @@ var EventManager = /** @class */ (function () {
109
124
  script = 'return ' + script;
110
125
  }
111
126
  if (script) {
112
- var data = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, "; ").concat(script, " "), Object.assign(obj, {
127
+ ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, "; ").concat(script, " "), Object.assign(obj, {
113
128
  __render: Object.freeze({
114
129
  element: it
115
130
  })
@@ -133,7 +148,7 @@ var EventManager = /** @class */ (function () {
133
148
  bindObj_1 = ScriptUtils_1.ScriptUtils.evalReturn(ownerVariablePathName, obj);
134
149
  }
135
150
  var getValue = _this.getValue(obj, varName, bindObj_1);
136
- // 아래 나중에 리팩토링 필요함
151
+ // TODO: 아래 나중에 리팩토링 필요함
137
152
  if (typeof getValue === 'function' && getValue) {
138
153
  var setValue = it.value;
139
154
  if (mapScript_1) {
@@ -229,7 +244,7 @@ var EventManager = /** @class */ (function () {
229
244
  if (script) {
230
245
  script = 'return ' + script;
231
246
  }
232
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
247
+ if (EventManager.isUsingThisVar(script, varName) || varName === undefined) {
233
248
  var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
234
249
  __render: Object.freeze({
235
250
  element: it
@@ -280,7 +295,7 @@ var EventManager = /** @class */ (function () {
280
295
  if (script) {
281
296
  script = 'return ' + script;
282
297
  }
283
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
298
+ if (EventManager.isUsingThisVar(script, varName) || varName === undefined) {
284
299
  var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
285
300
  __render: Object.freeze({
286
301
  element: it
@@ -308,7 +323,7 @@ var EventManager = /** @class */ (function () {
308
323
  if (script) {
309
324
  script = 'return ' + script;
310
325
  }
311
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
326
+ if (EventManager.isUsingThisVar(script, varName) || varName === undefined) {
312
327
  var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; ".concat(script, " "), Object.assign(obj, {
313
328
  __render: Object.freeze({
314
329
  element: it
@@ -335,6 +350,23 @@ var EventManager = /** @class */ (function () {
335
350
  }
336
351
  }
337
352
  });
353
+ // 중요 변수값 바꼈을때 이벤트 타겟 찾는것 normal-attr-map
354
+ this.procAttr(elements, EventManager.normalAttrMapAttrName, function (it, attribute) {
355
+ var map = new Map(JSON.parse(attribute));
356
+ map.forEach(function (v, k) {
357
+ // console.log('--->', v, k)
358
+ var isUsing = EventManager.isUsingThisVar(v, varName);
359
+ // console.log('---isUsing--> varName:', varName, 'k:', k, 'v:', v, 'isUsing:', isUsing);
360
+ if (isUsing) {
361
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; return ".concat(v, " "), Object.assign(obj, {
362
+ __render: Object.freeze({
363
+ element: it
364
+ })
365
+ }));
366
+ it.setAttribute(k, data);
367
+ }
368
+ });
369
+ });
338
370
  };
339
371
  // eslint-disable-next-line no-undef
340
372
  EventManager.prototype.addDrEvents = function (obj, eventName, elements, config) {
@@ -366,6 +398,7 @@ var EventManager = /** @class */ (function () {
366
398
  });
367
399
  });
368
400
  };
401
+ // eslint-disable-next-line no-undef
369
402
  EventManager.prototype.addDrEventPram = function (obj, attr, elements, config) {
370
403
  var _this = this;
371
404
  this.procAttr(elements, attr, function (it, attribute, attributes) {
@@ -439,7 +472,7 @@ var EventManager = /** @class */ (function () {
439
472
  value: value
440
473
  });
441
474
  };
442
- EventManager.prototype.isUsingThisVar = function (raws, varName) {
475
+ EventManager.isUsingThisVar = function (raws, varName) {
443
476
  // console.log('isUsingV', raws)
444
477
  // console.log('isUsingV', raws, varName, ScriptUtils.getVariablePaths(raws ?? ''))
445
478
  if (varName && raws) {
@@ -475,6 +508,7 @@ var EventManager = /** @class */ (function () {
475
508
  EventManager.valueAttrName = EventManager.attrPrefix + 'value';
476
509
  EventManager.valueLinkAttrName = EventManager.attrPrefix + 'value-link';
477
510
  EventManager.attrAttrName = EventManager.attrPrefix + 'attr';
511
+ EventManager.normalAttrMapAttrName = EventManager.attrPrefix + 'normal-attr-map';
478
512
  EventManager.styleAttrName = EventManager.attrPrefix + 'style';
479
513
  EventManager.classAttrName = EventManager.attrPrefix + 'class';
480
514
  EventManager.VALUE_VARNAME = '$value';
@@ -0,0 +1,3 @@
1
+ export interface OnChangeAttrRender {
2
+ onChangeAttrRender(name: string, val: any): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import { ExecuteState, OperatorRender } from './OperatorRender';
2
- export declare class AttrExpresion extends OperatorRender {
3
- execRender(): ExecuteState;
4
- }
@@ -1,68 +1,44 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.AttrExpresion = void 0;
30
- var OperatorRender_1 = require("./OperatorRender");
31
- var ScriptUtils_1 = require("../utils/script/ScriptUtils");
32
- var RawSet_1 = require("../RawSet");
33
- var AttrExpresion = /** @class */ (function (_super) {
34
- __extends(AttrExpresion, _super);
35
- function AttrExpresion() {
36
- return _super !== null && _super.apply(this, arguments) || this;
37
- }
38
- AttrExpresion.prototype.execRender = function () {
39
- var _a;
40
- var _this = this;
41
- var _b;
42
- var targetAttrs = this.elementSource.element.getAttributeNames()
43
- .filter(function (it) { return RawSet_1.RawSet.isExporesion(_this.elementSource.element.getAttribute(it)); })
44
- .map(function (it) { return ({ name: it, expresion: RawSet_1.RawSet.exporesionGrouops(_this.elementSource.element.getAttribute(it))[0][1] }); })
45
- .filter(function (it) { return it.name.length > 0 && it.expresion.length > 0; })
46
- .map(function (it) {
47
- return "n.setAttribute('".concat(it.name, "', ").concat(it.expresion, ")");
48
- });
49
- // console.log('-----', targetAttrs)
50
- if ((targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.length) > 0) {
51
- var newTemp = this.source.config.window.document.createElement('temp');
52
- // console.log('------>', targetAttrs, targetAttrs.join(';'))
53
- ScriptUtils_1.ScriptUtils.eval("\n ".concat(this.render.bindScript, "\n const n = $element.cloneNode(true);\n ").concat(targetAttrs.join(';'), ";\n this.__render.fag.append(n);\n "), Object.assign(this.source.obj, {
54
- __render: Object.freeze(__assign({ fag: newTemp, targetAttrs: targetAttrs }, this.render))
55
- }));
56
- var tempalte = this.source.config.window.document.createElement('template');
57
- tempalte.innerHTML = newTemp.innerHTML;
58
- this.returnContainer.fag.append(tempalte.content);
59
- var rr = RawSet_1.RawSet.checkPointCreates(this.returnContainer.fag, this.source.config);
60
- (_b = this.elementSource.element.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(this.returnContainer.fag, this.elementSource.element);
61
- (_a = this.returnContainer.raws).push.apply(_a, rr);
62
- return OperatorRender_1.ExecuteState.EXECUTE;
63
- }
64
- return OperatorRender_1.ExecuteState.NO_EXECUTE;
65
- };
66
- return AttrExpresion;
67
- }(OperatorRender_1.OperatorRender));
68
- exports.AttrExpresion = AttrExpresion;
2
+ // import {ExecuteState, OperatorRender} from './OperatorRender';
3
+ // import {ScriptUtils} from '../utils/script/ScriptUtils';
4
+ // import {RawSet, Render} from '../RawSet';
5
+ //
6
+ // export class AttrExpresion extends OperatorRender {
7
+ // execRender(): ExecuteState {
8
+ // const targetAttrs = this.elementSource.element.getAttributeNames()
9
+ // .filter(it => RawSet.isExporesion(this.elementSource.element.getAttribute(it)))
10
+ // .map(it => ({name: it, expresion: RawSet.exporesionGrouops(this.elementSource.element.getAttribute(it))[0][1]}))
11
+ // .filter(it => it.name.length > 0 && it.expresion.length > 0)
12
+ // .map(it => {
13
+ // return `n.setAttribute('${it.name}', ${it.expresion})`;
14
+ // });
15
+ // // console.log('--!!!!!!!!!---', targetAttrs)
16
+ // if (targetAttrs?.length > 0) {
17
+ // const newTemp = this.source.config.window.document.createElement('temp');
18
+ // // console.log('------>', targetAttrs, targetAttrs.join(';'))
19
+ // ScriptUtils.eval(`
20
+ // ${this.render.bindScript}
21
+ // //const n = $element.cloneNode(true);
22
+ // const n = $element;
23
+ // ${targetAttrs.join(';')};
24
+ // // this.__render.fag.append(n);
25
+ // `, Object.assign(this.source.obj, {
26
+ // __render: Object.freeze({
27
+ // fag: newTemp,
28
+ // targetAttrs,
29
+ // ...this.render
30
+ // } as Render)
31
+ // }));
32
+ // // const tempalte = this.source.config.window.document.createElement('template');
33
+ // // tempalte.innerHTML = newTemp.innerHTML;
34
+ // // this.returnContainer.fag.append(tempalte.content);
35
+ // const rr = RawSet.checkPointCreates(this.render.element, this.source.config);
36
+ // // const rr = RawSet.checkPointCreates(this.returnContainer.fag, this.source.config);
37
+ // // this.elementSource.element.parentNode?.replaceChild(this.returnContainer.fag, this.elementSource.element);
38
+ // this.returnContainer.raws.push(...rr);
39
+ // // return ExecuteState.EXECUTE;
40
+ // return ExecuteState.NO_EXECUTE;
41
+ // }
42
+ // return ExecuteState.NO_EXECUTE;
43
+ // }
44
+ // }
@@ -32,8 +32,34 @@ var DrTargetElement = /** @class */ (function (_super) {
32
32
  if (targetElement) {
33
33
  var documentFragment = targetElement.callBack(this.elementSource.element, this.source.obj, this.rawSet, this.elementSource.attrs);
34
34
  if (documentFragment) {
35
+ // const targetAttrMap = this.elementSource.element.getAttribute(EventManager.normalAttrMapAttrName);
35
36
  var detectAction_1 = this.elementSource.element.getAttribute(RawSet_1.RawSet.DR_DETECT_NAME);
36
37
  var render_1 = documentFragment.render;
38
+ // console.log('-------drTargetElement->', render, targetAttrMap);
39
+ this.rawSet.fragment = documentFragment;
40
+ this.rawSet.data = render_1.component;
41
+ // const targetAttrs = this.elementSource.element.getAttributeNames()
42
+ // .filter(it => RawSet.isExporesion(this.elementSource.element.getAttribute(it)))
43
+ // .map(it => ({name: it, expresion: RawSet.exporesionGrouops(this.elementSource.element.getAttribute(it))[0][1]}))
44
+ // .filter(it => it.name.length > 0 && it.expresion.length > 0)
45
+ // .map(it => {
46
+ // return `n.setAttribute('${it.name}', ${it.expresion})`;
47
+ // });
48
+ // if (targetAttrMap) {
49
+ // ScriptUtils.eval(`
50
+ // ${this.render.bindScript}
51
+ // //const n = $element.cloneNode(true);
52
+ // const n = $element;
53
+ // ${targetAttrMap.join(';')};
54
+ // // this.__render.fag.append(n);
55
+ // `, Object.assign(this.source.obj, {
56
+ // __render: Object.freeze({
57
+ // fag: newTemp,
58
+ // targetAttrs: targetAttrMap,
59
+ // ...this.render
60
+ // } as Render)
61
+ // }));
62
+ // }
37
63
  if (detectAction_1 && render_1) {
38
64
  this.rawSet.detect = {
39
65
  action: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dom-render",
3
- "version": "1.0.76",
3
+ "version": "1.0.79",
4
4
  "main": "DomRender.js",
5
5
  "license": "MIT",
6
6
  "description": "dom-render",