dom-render 1.0.74 → 1.0.77

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. package/Config.d.ts +38 -36
  2. package/Config.js +2 -2
  3. package/DomRender.d.ts +28 -27
  4. package/DomRender.js +90 -88
  5. package/DomRenderProxy.d.ts +29 -29
  6. package/DomRenderProxy.js +342 -327
  7. package/README.MD +638 -567
  8. package/RawSet.d.ts +140 -118
  9. package/RawSet.js +771 -905
  10. package/components/ComponentSet.d.ts +7 -0
  11. package/components/ComponentSet.js +14 -0
  12. package/dist/bundle.js +3789 -3214
  13. package/events/EventManager.d.ts +48 -47
  14. package/events/EventManager.js +530 -499
  15. package/iterators/Range.d.ts +22 -22
  16. package/iterators/Range.js +65 -65
  17. package/lifecycle/OnBeforeReturnGet.d.ts +3 -3
  18. package/lifecycle/OnBeforeReturnGet.js +2 -2
  19. package/lifecycle/OnBeforeReturnSet.d.ts +3 -3
  20. package/lifecycle/OnBeforeReturnSet.js +2 -2
  21. package/lifecycle/OnCreateRender.d.ts +3 -3
  22. package/lifecycle/OnCreateRender.js +2 -2
  23. package/lifecycle/OnDestroyRender.d.ts +4 -4
  24. package/lifecycle/OnDestroyRender.js +2 -2
  25. package/lifecycle/OnInitRender.d.ts +7 -7
  26. package/lifecycle/OnInitRender.js +2 -2
  27. package/lifecycle/OnProxyDomRender.d.ts +4 -0
  28. package/lifecycle/OnProxyDomRender.js +2 -0
  29. package/managers/RenderManager.d.ts +3 -3
  30. package/managers/RenderManager.js +18 -18
  31. package/messenger/DefaultMessenger.d.ts +3 -0
  32. package/messenger/DefaultMessenger.js +27 -0
  33. package/messenger/Messenger.d.ts +78 -0
  34. package/messenger/Messenger.js +201 -0
  35. package/operators/Appender.d.ts +7 -12
  36. package/operators/Appender.js +32 -39
  37. package/operators/AttrExpresion.d.ts +0 -0
  38. package/operators/AttrExpresion.js +44 -0
  39. package/operators/Dr.d.ts +4 -0
  40. package/operators/Dr.js +62 -0
  41. package/operators/DrAppender.d.ts +4 -0
  42. package/operators/DrAppender.js +65 -0
  43. package/operators/DrFor.d.ts +4 -0
  44. package/operators/DrFor.js +62 -0
  45. package/operators/DrForOf.d.ts +4 -0
  46. package/operators/DrForOf.js +65 -0
  47. package/operators/DrForm.d.ts +4 -0
  48. package/operators/DrForm.js +100 -0
  49. package/operators/DrIf.d.ts +4 -0
  50. package/operators/DrIf.js +72 -0
  51. package/operators/DrInnerHTML.d.ts +4 -0
  52. package/operators/DrInnerHTML.js +60 -0
  53. package/operators/DrInnerText.d.ts +4 -0
  54. package/operators/DrInnerText.js +58 -0
  55. package/operators/DrPre.d.ts +4 -0
  56. package/operators/DrPre.js +30 -0
  57. package/operators/DrRepeat.d.ts +4 -0
  58. package/operators/DrRepeat.js +63 -0
  59. package/operators/DrTargetAttr.d.ts +4 -0
  60. package/operators/DrTargetAttr.js +55 -0
  61. package/operators/DrTargetElement.d.ts +4 -0
  62. package/operators/DrTargetElement.js +65 -0
  63. package/operators/DrThis.d.ts +4 -0
  64. package/operators/DrThis.js +59 -0
  65. package/operators/OperatorRender.d.ts +41 -0
  66. package/operators/OperatorRender.js +21 -0
  67. package/package.json +94 -94
  68. package/routers/HashRouter.d.ts +9 -9
  69. package/routers/HashRouter.js +53 -53
  70. package/routers/PathRouter.d.ts +9 -9
  71. package/routers/PathRouter.js +52 -52
  72. package/routers/Router.d.ts +25 -25
  73. package/routers/Router.js +116 -116
  74. package/types/Types.d.ts +14 -14
  75. package/types/Types.js +36 -36
  76. package/utils/clipboard/ClipBoardUtils.d.ts +6 -6
  77. package/utils/clipboard/ClipBoardUtils.js +25 -25
  78. package/utils/dom/DomUtils.d.ts +13 -13
  79. package/utils/dom/DomUtils.js +47 -47
  80. package/utils/location/LocationUtils.d.ts +16 -16
  81. package/utils/location/LocationUtils.js +57 -57
  82. package/utils/node/NodeUtils.d.ts +10 -10
  83. package/utils/node/NodeUtils.js +27 -27
  84. package/utils/random/RandomUtils.d.ts +7 -7
  85. package/utils/random/RandomUtils.js +47 -47
  86. package/utils/script/ScriptUtils.d.ts +14 -14
  87. package/utils/script/ScriptUtils.js +89 -89
  88. package/utils/storage/StorageUtils.d.ts +9 -9
  89. package/utils/storage/StorageUtils.js +48 -48
  90. package/utils/string/StringUtils.d.ts +5 -5
  91. package/utils/string/StringUtils.js +41 -41
  92. package/utils/valid/ValidUtils.d.ts +10 -10
  93. package/utils/valid/ValidUtils.js +78 -78
  94. package/validators/AllCheckedValidatorArray.d.ts +6 -6
  95. package/validators/AllCheckedValidatorArray.js +32 -32
  96. package/validators/AllUnCheckedValidatorArray.d.ts +6 -6
  97. package/validators/AllUnCheckedValidatorArray.js +32 -32
  98. package/validators/CheckedValidator.d.ts +5 -5
  99. package/validators/CheckedValidator.js +32 -32
  100. package/validators/CountEqualsCheckedValidatorArray.d.ts +7 -7
  101. package/validators/CountEqualsCheckedValidatorArray.js +34 -34
  102. package/validators/CountEqualsUnCheckedValidatorArray.d.ts +7 -7
  103. package/validators/CountEqualsUnCheckedValidatorArray.js +34 -34
  104. package/validators/CountGreaterThanCheckedValidatorArray.d.ts +7 -7
  105. package/validators/CountGreaterThanCheckedValidatorArray.js +34 -34
  106. package/validators/CountGreaterThanEqualsCheckedValidatorArray.d.ts +7 -7
  107. package/validators/CountGreaterThanEqualsCheckedValidatorArray.js +34 -34
  108. package/validators/CountGreaterThanEqualsUnCheckedValidatorArray.d.ts +7 -7
  109. package/validators/CountGreaterThanEqualsUnCheckedValidatorArray.js +34 -34
  110. package/validators/CountGreaterThanUnCheckedValidatorArray.d.ts +7 -7
  111. package/validators/CountGreaterThanUnCheckedValidatorArray.js +34 -34
  112. package/validators/CountLessThanCheckedValidatorArray.d.ts +7 -7
  113. package/validators/CountLessThanCheckedValidatorArray.js +34 -34
  114. package/validators/CountLessThanEqualsCheckedValidatorArray.d.ts +7 -7
  115. package/validators/CountLessThanEqualsCheckedValidatorArray.js +34 -34
  116. package/validators/CountLessThanEqualsUnCheckedValidatorArray.d.ts +7 -7
  117. package/validators/CountLessThanEqualsUnCheckedValidatorArray.js +34 -34
  118. package/validators/CountLessThanUnCheckedValidatorArray.d.ts +7 -7
  119. package/validators/CountLessThanUnCheckedValidatorArray.js +34 -34
  120. package/validators/CountUnCheckedValidatorArray.d.ts +7 -7
  121. package/validators/CountUnCheckedValidatorArray.js +34 -34
  122. package/validators/EmptyValidator.d.ts +5 -5
  123. package/validators/EmptyValidator.js +33 -33
  124. package/validators/ExcludeCheckedValidatorArray.d.ts +8 -8
  125. package/validators/ExcludeCheckedValidatorArray.js +41 -41
  126. package/validators/FormValidator.d.ts +7 -7
  127. package/validators/FormValidator.js +37 -37
  128. package/validators/IncludeCheckedValidatorArray.d.ts +8 -8
  129. package/validators/IncludeCheckedValidatorArray.js +41 -41
  130. package/validators/MultipleValidator.d.ts +8 -8
  131. package/validators/MultipleValidator.js +48 -48
  132. package/validators/NonPassValidator.d.ts +5 -5
  133. package/validators/NonPassValidator.js +31 -31
  134. package/validators/NotEmptyValidator.d.ts +5 -5
  135. package/validators/NotEmptyValidator.js +34 -34
  136. package/validators/NotRegExpTestValidator.d.ts +6 -6
  137. package/validators/NotRegExpTestValidator.js +42 -42
  138. package/validators/PassValidator.d.ts +5 -5
  139. package/validators/PassValidator.js +31 -31
  140. package/validators/RegExpTestValidator.d.ts +6 -6
  141. package/validators/RegExpTestValidator.js +43 -43
  142. package/validators/RequiredValidator.d.ts +5 -5
  143. package/validators/RequiredValidator.js +33 -33
  144. package/validators/UnCheckedValidator.d.ts +5 -5
  145. package/validators/UnCheckedValidator.js +32 -32
  146. package/validators/ValidMultipleValidator.d.ts +9 -9
  147. package/validators/ValidMultipleValidator.js +34 -34
  148. package/validators/ValidValidator.d.ts +6 -6
  149. package/validators/ValidValidator.js +33 -33
  150. package/validators/ValidValidatorArray.d.ts +7 -7
  151. package/validators/ValidValidatorArray.js +33 -33
  152. package/validators/Validator.d.ts +57 -57
  153. package/validators/Validator.js +242 -242
  154. package/validators/ValidatorArray.d.ts +17 -17
  155. package/validators/ValidatorArray.js +99 -99
  156. package/validators/ValueEqualsValidator.d.ts +6 -6
  157. package/validators/ValueEqualsValidator.js +33 -33
  158. package/validators/ValueNotEqualsValidator.d.ts +6 -6
  159. package/validators/ValueNotEqualsValidator.js +33 -33
@@ -1,499 +1,530 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventManager = exports.EventManager = void 0;
4
- var ScriptUtils_1 = require("../utils/script/ScriptUtils");
5
- var DomUtils_1 = require("../utils/dom/DomUtils");
6
- var Range_1 = require("../iterators/Range");
7
- var Types_1 = require("../types/Types");
8
- var EventManager = /** @class */ (function () {
9
- function EventManager() {
10
- var _this = this;
11
- this.eventNames = [
12
- 'click', 'mousedown', 'mouseup', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave', 'contextmenu',
13
- 'keyup', 'keydown', 'keypress',
14
- 'change', 'input', 'submit', 'resize', 'focus', 'blur'
15
- ];
16
- this.eventParam = EventManager.attrPrefix + 'event';
17
- this.attrNames = [
18
- EventManager.valueAttrName,
19
- EventManager.valueLinkAttrName,
20
- EventManager.attrAttrName,
21
- EventManager.styleAttrName,
22
- EventManager.classAttrName,
23
- EventManager.attrPrefix + 'window-event-' + EventManager.WINDOW_EVENT_POPSTATE,
24
- EventManager.attrPrefix + 'window-event-' + EventManager.WINDOW_EVENT_RESIZE,
25
- EventManager.onInitAttrName,
26
- this.eventParam
27
- ];
28
- this.bindScript = "\n const ".concat(EventManager.VALUE_VARNAME, " = this.__render.value;\n const ").concat(EventManager.SCRIPTS_VARNAME, " = this.__render.scripts;\n const ").concat(EventManager.RANGE_VARNAME, " = this.__render.range;\n const ").concat(EventManager.ROUTER_VARNAME, " = this.__render.router;\n const ").concat(EventManager.ATTRIBUTE_VARNAME, " = this.__render.attribute;\n const ").concat(EventManager.ELEMENT_VARNAME, " = this.__render.element;\n const ").concat(EventManager.TARGET_VARNAME, " = this.__render.target;\n const ").concat(EventManager.EVENT_VARNAME, " = this.__render.event;\n ");
29
- this.eventNames.forEach(function (it) {
30
- _this.attrNames.push(EventManager.attrPrefix + 'event-' + it);
31
- });
32
- if (typeof window !== 'undefined') {
33
- EventManager.WINDOW_EVENTS.forEach(function (eventName) {
34
- window === null || window === void 0 ? void 0 : window.addEventListener(eventName, function (event) {
35
- var targetAttr = "dr-window-event-".concat(eventName);
36
- document.querySelectorAll("[".concat(targetAttr, "]")).forEach(function (it) {
37
- var _a;
38
- var script = it.getAttribute(targetAttr);
39
- if (script) {
40
- var obj = it.obj;
41
- var config = (_a = obj === null || obj === void 0 ? void 0 : obj._DomRender_proxy) === null || _a === void 0 ? void 0 : _a.config;
42
- ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " ").concat(script, " "), Object.assign(obj, {
43
- __render: Object.freeze({
44
- target: Types_1.DomRenderFinalProxy.final(event.target),
45
- element: it,
46
- event: event,
47
- range: Range_1.Range.range,
48
- scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
49
- })
50
- }));
51
- }
52
- });
53
- });
54
- });
55
- }
56
- }
57
- // // 순환참조때문에 우선 여기에 뺴놓는다.
58
- // public DomrenderProxyFinal(obj: any) {
59
- // (obj as any)._DomRender_isFinal = true;
60
- // return obj;
61
- // }
62
- EventManager.prototype.findAttrElements = function (fragment, config) {
63
- var _a, _b;
64
- // const datas: {name: string, value: string | null, element: Element}[] = [];
65
- var elements = new Set();
66
- var addAttributes = (_b = (_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.map(function (it) { return it.attrName; })) !== null && _b !== void 0 ? _b : [];
67
- addAttributes.concat(this.attrNames).forEach(function (attrName) {
68
- fragment === null || fragment === void 0 ? void 0 : fragment.querySelectorAll("[".concat(attrName, "]")).forEach(function (it) {
69
- elements.add(it);
70
- });
71
- });
72
- return elements;
73
- };
74
- // eslint-disable-next-line no-undef
75
- EventManager.prototype.applyEvent = function (obj, childNodes, config) {
76
- var _this = this;
77
- // console.log('eventManager applyEvent==>', obj, childNodes, config)
78
- // Node.ELEMENT_NODE = 1
79
- // event
80
- // childNodes.forEach(it => {
81
- // if (it instanceof Element) {
82
- // it.setAttribute('dr-thieVariableName', 'this')
83
- // }
84
- // })
85
- this.eventNames.forEach(function (it) {
86
- _this.addDrEvents(obj, it, childNodes, config);
87
- });
88
- this.addDrEventPram(obj, this.eventParam, childNodes, config);
89
- // value
90
- this.procAttr(childNodes, EventManager.valueAttrName, function (it, attribute) {
91
- var script = attribute;
92
- if (script) {
93
- var data = ScriptUtils_1.ScriptUtils.evalReturn(script, obj);
94
- if (it.value !== data) {
95
- it.value = data;
96
- }
97
- }
98
- });
99
- // window event
100
- EventManager.WINDOW_EVENTS.forEach(function (it) {
101
- _this.procAttr(childNodes, EventManager.attrPrefix + 'window-event-' + it, function (it, attribute) {
102
- it.obj = obj;
103
- });
104
- });
105
- // on-init event
106
- this.procAttr(childNodes, EventManager.onInitAttrName, function (it, attribute) {
107
- var script = attribute;
108
- if (script) {
109
- script = 'return ' + script;
110
- }
111
- if (script) {
112
- var data = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, "; ").concat(script, " "), Object.assign(obj, {
113
- __render: Object.freeze({
114
- element: it
115
- })
116
- }));
117
- // console.log('onInit--->', obj, varName, it)
118
- // if (typeof this.getValue(obj, varName) === 'function') {
119
- // this.getValue(obj, varName)(it);
120
- // } else {
121
- // this.setValue(obj, varName, it);
122
- // }
123
- }
124
- });
125
- // value-link event
126
- this.procAttr(childNodes, EventManager.valueLinkAttrName, function (it, varName) {
127
- if (varName) {
128
- var ownerVariablePathName = it.getAttribute(EventManager.ownerVariablePathAttrName);
129
- var mapScript_1 = it.getAttribute("".concat(EventManager.valueLinkAttrName, ":map"));
130
- // const inMapScript = it.getAttribute(`${valueLinkAttrName}:in-map`);
131
- var bindObj_1 = obj;
132
- if (ownerVariablePathName) {
133
- bindObj_1 = ScriptUtils_1.ScriptUtils.evalReturn(ownerVariablePathName, obj);
134
- }
135
- var getValue = _this.getValue(obj, varName, bindObj_1);
136
- // 아래 나중에 리팩토링 필요함
137
- if (typeof getValue === 'function' && getValue) {
138
- var setValue = it.value;
139
- if (mapScript_1) {
140
- setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, { __render: Object.freeze({ element: it, target: bindObj_1, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
141
- }
142
- getValue(setValue);
143
- // 여기서 value가 먼저냐 value-link가 먼저냐 선을 정해야되는거네...
144
- }
145
- else if (getValue) {
146
- var setValue = getValue;
147
- if (mapScript_1) {
148
- setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, { __render: Object.freeze({ element: it, target: bindObj_1, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
149
- }
150
- it.value = setValue;
151
- // this.setValue(obj, varName, setValue)
152
- }
153
- // } else if (getValue) { // 이구분이 있어야되나?? 없어도될것같은데..
154
- // let setValue = getValue;
155
- // if (inMapScript) {
156
- // setValue = ScriptUtils.eval(`${this.bindScript} return ${inMapScript}`, Object.assign(bindObj, {__render: Object.freeze({element: it, target: bindObj, range: Range.range, value: setValue, scripts: EventManager.setBindProperty(config?.scripts, obj)})}));
157
- // }
158
- // this.setValue(obj, varName, setValue)
159
- // } else {
160
- // let setValue = it.value;
161
- // if (mapScript) {
162
- // setValue = ScriptUtils.eval(`${this.bindScript} return ${mapScript}`, Object.assign(bindObj, {__render: Object.freeze({element: it, target: bindObj, range: Range.range, value: setValue, scripts: EventManager.setBindProperty(config?.scripts, obj)})}));
163
- // }
164
- // this.setValue(obj, varName, setValue)
165
- // }
166
- it.addEventListener('input', function (event) {
167
- var value = it.value;
168
- if (mapScript_1) {
169
- value = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, {
170
- __render: Object.freeze({
171
- event: event,
172
- element: it,
173
- target: event.target,
174
- range: Range_1.Range.range,
175
- scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
176
- })
177
- }));
178
- }
179
- if (typeof _this.getValue(obj, varName, bindObj_1) === 'function') {
180
- _this.getValue(obj, varName, bindObj_1)(value, event);
181
- }
182
- else {
183
- _this.setValue(obj, varName, value);
184
- }
185
- });
186
- }
187
- });
188
- this.changeVar(obj, childNodes, undefined, config);
189
- // console.log('eventManager-applyEvent-->', config?.applyEvents)
190
- var elements = Array.from(childNodes).filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; });
191
- elements.forEach(function (it) {
192
- var _a;
193
- (_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName) !== null; }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
194
- });
195
- };
196
- // eslint-disable-next-line no-undef
197
- EventManager.prototype.changeVar = function (obj, elements, varName, config) {
198
- var _this = this;
199
- // console.log('-changeVar-->', obj, elements, varName)
200
- // value-link event
201
- this.procAttr(elements, EventManager.valueLinkAttrName, function (it, attribute) {
202
- var ownerVariablePathName = it.getAttribute(EventManager.ownerVariablePathAttrName);
203
- var bindObj = obj;
204
- if (ownerVariablePathName) {
205
- bindObj = ScriptUtils_1.ScriptUtils.evalReturn(ownerVariablePathName, obj);
206
- }
207
- var mapScript = it.getAttribute("".concat(EventManager.valueLinkAttrName, ":map"));
208
- if (attribute && attribute === varName) {
209
- var getValue = _this.getValue(obj, attribute, bindObj);
210
- if (typeof getValue === 'function' && getValue) {
211
- var setValue = it.value;
212
- if (mapScript) {
213
- setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript), Object.assign(bindObj, { __render: Object.freeze({ element: it, target: bindObj, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
214
- }
215
- getValue(setValue);
216
- }
217
- else { // if (getValue !== undefined && getValue !== null)
218
- var setValue = getValue;
219
- if (mapScript) {
220
- setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript), Object.assign(bindObj, { __render: Object.freeze({ element: it, target: bindObj, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
221
- }
222
- it.value = setValue;
223
- }
224
- }
225
- });
226
- // attribute
227
- this.procAttr(elements, EventManager.attrAttrName, function (it, attribute) {
228
- var script = attribute;
229
- if (script) {
230
- script = 'return ' + script;
231
- }
232
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
233
- var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
234
- __render: Object.freeze({
235
- element: it
236
- })
237
- }));
238
- if (typeof data === 'string') {
239
- data.split(',').forEach(function (sit) {
240
- var _a = sit.split('='), key = _a[0], value = _a[1];
241
- var s = value.trim();
242
- var k = key.trim();
243
- if (s === 'null') {
244
- it.removeAttribute(k);
245
- }
246
- else {
247
- it.setAttribute(k, s);
248
- }
249
- });
250
- }
251
- else if (Array.isArray(data)) {
252
- data.forEach(function (sit) {
253
- var _a = sit.split('='), key = _a[0], value = _a[1];
254
- var s = value.trim();
255
- var k = key.trim();
256
- if (s === 'null') {
257
- it.removeAttribute(k);
258
- }
259
- else {
260
- it.setAttribute(k, s);
261
- }
262
- });
263
- }
264
- else {
265
- for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
266
- var _b = _a[_i], key = _b[0], value = _b[1];
267
- if (value === null) {
268
- it.removeAttribute(key);
269
- }
270
- else {
271
- it.setAttribute(key, String(value));
272
- }
273
- }
274
- }
275
- }
276
- });
277
- // style
278
- this.procAttr(elements, EventManager.styleAttrName, function (it, attribute) {
279
- var script = attribute;
280
- if (script) {
281
- script = 'return ' + script;
282
- }
283
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
284
- var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
285
- __render: Object.freeze({
286
- element: it
287
- })
288
- }));
289
- if (typeof data === 'string') {
290
- it.setAttribute('style', data);
291
- }
292
- else if (Array.isArray(data)) {
293
- it.setAttribute('style', data.join(';'));
294
- }
295
- else {
296
- for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
297
- var _b = _a[_i], key = _b[0], value = _b[1];
298
- if (it instanceof HTMLElement) {
299
- it.style[key] = String(value);
300
- }
301
- }
302
- }
303
- }
304
- });
305
- // class
306
- this.procAttr(elements, EventManager.classAttrName, function (it, attribute) {
307
- var script = attribute;
308
- if (script) {
309
- script = 'return ' + script;
310
- }
311
- if (_this.isUsingThisVar(script, varName) || varName === undefined) {
312
- var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; ".concat(script, " "), Object.assign(obj, {
313
- __render: Object.freeze({
314
- element: it
315
- })
316
- }));
317
- if (typeof data === 'string') {
318
- it.setAttribute('class', data);
319
- }
320
- else if (Array.isArray(data)) {
321
- it.setAttribute('class', data.join(' '));
322
- }
323
- else {
324
- for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
325
- var _b = _a[_i], key = _b[0], value = _b[1];
326
- if (it instanceof HTMLElement) {
327
- if (value) {
328
- it.classList.add(key);
329
- }
330
- else {
331
- it.classList.remove(key);
332
- }
333
- }
334
- }
335
- }
336
- }
337
- });
338
- };
339
- // eslint-disable-next-line no-undef
340
- EventManager.prototype.addDrEvents = function (obj, eventName, elements, config) {
341
- var _this = this;
342
- var attr = EventManager.attrPrefix + 'event-' + eventName;
343
- this.procAttr(elements, attr, function (it, attribute) {
344
- var script = attribute;
345
- it.addEventListener(eventName, function (event) {
346
- var filter = true;
347
- var filterScript = it.getAttribute("".concat(attr, ":filter"));
348
- var attribute = DomUtils_1.DomUtils.getAttributeToObject(it);
349
- var thisTarget = Object.assign(obj, {
350
- __render: Object.freeze({
351
- event: event,
352
- element: it,
353
- target: event.target,
354
- range: Range_1.Range.range,
355
- attribute: attribute,
356
- router: config === null || config === void 0 ? void 0 : config.router,
357
- scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
358
- })
359
- });
360
- if (filterScript) {
361
- filter = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(filterScript), thisTarget);
362
- }
363
- if (filter) {
364
- ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " ").concat(script, " "), thisTarget);
365
- }
366
- });
367
- });
368
- };
369
- EventManager.prototype.addDrEventPram = function (obj, attr, elements, config) {
370
- var _this = this;
371
- this.procAttr(elements, attr, function (it, attribute, attributes) {
372
- var bind = attributes[attr + ':bind'];
373
- if (bind) {
374
- var script_1 = attribute;
375
- var params_1 = {};
376
- var prefix_1 = attr + ':';
377
- Object.entries(attributes).filter(function (_a) {
378
- var k = _a[0], v = _a[1];
379
- return k.startsWith(prefix_1);
380
- }).forEach(function (_a) {
381
- var k = _a[0], v = _a[1];
382
- params_1[k.slice(prefix_1.length)] = v;
383
- });
384
- bind.split(',').forEach(function (eventName) {
385
- it.addEventListener(eventName.trim(), function (event) {
386
- ScriptUtils_1.ScriptUtils.eval("const $params = this.__render.params; ".concat(_this.bindScript, " ").concat(script_1, " "), Object.assign(obj, {
387
- __render: Object.freeze({
388
- event: event,
389
- element: it,
390
- target: event.target,
391
- range: Range_1.Range.range,
392
- scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj),
393
- params: params_1
394
- })
395
- }));
396
- });
397
- });
398
- }
399
- });
400
- };
401
- // eslint-disable-next-line no-undef
402
- EventManager.prototype.procAttr = function (elements, attrName, callBack) {
403
- if (elements === void 0) { elements = new Set(); }
404
- var sets = new Set();
405
- elements.forEach(function (it) {
406
- // console.log('--->type', it, it.nodeType)
407
- if (!it) {
408
- return;
409
- }
410
- // Node.ELEMENT_NODE = 1
411
- if (it.nodeType === 1) {
412
- var e = it;
413
- sets.add(e);
414
- e.querySelectorAll("[".concat(attrName, "]")).forEach(function (it) {
415
- sets.add(it);
416
- });
417
- }
418
- });
419
- sets.forEach(function (it) {
420
- var attr = it.getAttribute(attrName);
421
- var attrs = DomUtils_1.DomUtils.getAttributeToObject(it);
422
- if (attr) {
423
- callBack(it, attr, attrs);
424
- }
425
- });
426
- };
427
- EventManager.prototype.getValue = function (obj, name, bindObj) {
428
- // let r = obj[name];
429
- var r = ScriptUtils_1.ScriptUtils.evalReturn(name, obj);
430
- if (typeof r === 'function') {
431
- r = r.bind(bindObj !== null && bindObj !== void 0 ? bindObj : obj);
432
- }
433
- return r;
434
- };
435
- EventManager.prototype.setValue = function (obj, name, value) {
436
- name = name.replaceAll('this.', 'this.this.');
437
- ScriptUtils_1.ScriptUtils.eval("".concat(name, " = this.value;"), {
438
- this: obj,
439
- value: value
440
- });
441
- };
442
- EventManager.prototype.isUsingThisVar = function (raws, varName) {
443
- // console.log('isUsingV', raws)
444
- // console.log('isUsingV', raws, varName, ScriptUtils.getVariablePaths(raws ?? ''))
445
- if (varName && raws) {
446
- if (varName.startsWith('this.')) {
447
- varName = varName.replace(/this\./, '');
448
- }
449
- EventManager.VARNAMES.forEach(function (it) {
450
- // raws = raws!.replace(RegExp(it.replace('$', '\\$'), 'g'), `this?.___${it}`);
451
- raws = raws.replace(RegExp(it.replace('$', '\\$'), 'g'), "this.___".concat(it));
452
- });
453
- var variablePaths = ScriptUtils_1.ScriptUtils.getVariablePaths(raws !== null && raws !== void 0 ? raws : '');
454
- return variablePaths.has(varName);
455
- }
456
- return false;
457
- };
458
- EventManager.setBindProperty = function (scripts, obj) {
459
- if (scripts) {
460
- // const newScripts = Object.assign({}, scripts)
461
- var newScripts = Object.assign({}, scripts);
462
- for (var _i = 0, _a = Object.entries(newScripts); _i < _a.length; _i++) {
463
- var _b = _a[_i], key = _b[0], value = _b[1];
464
- if (typeof value === 'function') {
465
- newScripts[key] = value.bind(obj);
466
- }
467
- }
468
- return newScripts;
469
- }
470
- };
471
- EventManager.ownerVariablePathAttrName = 'dr-owner-variable-path';
472
- EventManager.attrPrefix = 'dr-';
473
- EventManager.onInitAttrName = EventManager.attrPrefix + 'on-init';
474
- // public static readonly onComponentInitAttrName = EventManager.attrPrefix + 'on-component-init';
475
- EventManager.valueAttrName = EventManager.attrPrefix + 'value';
476
- EventManager.valueLinkAttrName = EventManager.attrPrefix + 'value-link';
477
- EventManager.attrAttrName = EventManager.attrPrefix + 'attr';
478
- EventManager.styleAttrName = EventManager.attrPrefix + 'style';
479
- EventManager.classAttrName = EventManager.attrPrefix + 'class';
480
- EventManager.VALUE_VARNAME = '$value';
481
- EventManager.SCRIPTS_VARNAME = '$scripts';
482
- EventManager.FAG_VARNAME = '$fag';
483
- EventManager.RAWSET_VARNAME = '$rawset';
484
- EventManager.RANGE_VARNAME = '$range';
485
- EventManager.ROUTER_VARNAME = '$router';
486
- EventManager.ELEMENT_VARNAME = '$element';
487
- EventManager.TARGET_VARNAME = '$target';
488
- EventManager.EVENT_VARNAME = '$event';
489
- EventManager.COMPONENT_VARNAME = '$component';
490
- EventManager.INNERHTML_VARNAME = '$innerHTML';
491
- EventManager.ATTRIBUTE_VARNAME = '$attribute';
492
- EventManager.VARNAMES = [EventManager.SCRIPTS_VARNAME, EventManager.FAG_VARNAME, EventManager.RAWSET_VARNAME, EventManager.RANGE_VARNAME, EventManager.ROUTER_VARNAME, EventManager.ELEMENT_VARNAME, EventManager.TARGET_VARNAME, EventManager.EVENT_VARNAME, EventManager.COMPONENT_VARNAME, EventManager.INNERHTML_VARNAME, EventManager.ATTRIBUTE_VARNAME];
493
- EventManager.WINDOW_EVENT_POPSTATE = 'popstate';
494
- EventManager.WINDOW_EVENT_RESIZE = 'resize';
495
- EventManager.WINDOW_EVENTS = [EventManager.WINDOW_EVENT_POPSTATE, EventManager.WINDOW_EVENT_RESIZE];
496
- return EventManager;
497
- }());
498
- exports.EventManager = EventManager;
499
- exports.eventManager = new EventManager();
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eventManager = exports.EventManager = void 0;
4
+ var ScriptUtils_1 = require("../utils/script/ScriptUtils");
5
+ var DomUtils_1 = require("../utils/dom/DomUtils");
6
+ var Range_1 = require("../iterators/Range");
7
+ var Types_1 = require("../types/Types");
8
+ var EventManager = /** @class */ (function () {
9
+ function EventManager() {
10
+ var _this = this;
11
+ this.eventNames = [
12
+ 'click', 'mousedown', 'mouseup', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave', 'contextmenu',
13
+ 'keyup', 'keydown', 'keypress',
14
+ 'change', 'input', 'submit', 'resize', 'focus', 'blur'
15
+ ];
16
+ this.eventParam = EventManager.attrPrefix + 'event';
17
+ this.attrNames = [
18
+ EventManager.valueAttrName,
19
+ EventManager.valueLinkAttrName,
20
+ EventManager.attrAttrName,
21
+ EventManager.normalAttrMapAttrName,
22
+ EventManager.styleAttrName,
23
+ EventManager.classAttrName,
24
+ EventManager.attrPrefix + 'window-event-' + EventManager.WINDOW_EVENT_POPSTATE,
25
+ EventManager.attrPrefix + 'window-event-' + EventManager.WINDOW_EVENT_RESIZE,
26
+ EventManager.onInitAttrName,
27
+ this.eventParam
28
+ ];
29
+ this.bindScript = "\n const ".concat(EventManager.VALUE_VARNAME, " = this.__render.value;\n const ").concat(EventManager.SCRIPTS_VARNAME, " = this.__render.scripts;\n const ").concat(EventManager.RANGE_VARNAME, " = this.__render.range;\n const ").concat(EventManager.ROUTER_VARNAME, " = this.__render.router;\n const ").concat(EventManager.ATTRIBUTE_VARNAME, " = this.__render.attribute;\n const ").concat(EventManager.ELEMENT_VARNAME, " = this.__render.element;\n const ").concat(EventManager.TARGET_VARNAME, " = this.__render.target;\n const ").concat(EventManager.EVENT_VARNAME, " = this.__render.event;\n ");
30
+ this.eventNames.forEach(function (it) {
31
+ _this.attrNames.push(EventManager.attrPrefix + 'event-' + it);
32
+ });
33
+ if (typeof window !== 'undefined') {
34
+ EventManager.WINDOW_EVENTS.forEach(function (eventName) {
35
+ window === null || window === void 0 ? void 0 : window.addEventListener(eventName, function (event) {
36
+ var targetAttr = "dr-window-event-".concat(eventName);
37
+ document.querySelectorAll("[".concat(targetAttr, "]")).forEach(function (it) {
38
+ var _a;
39
+ var script = it.getAttribute(targetAttr);
40
+ if (script) {
41
+ var obj = it.obj;
42
+ var config = (_a = obj === null || obj === void 0 ? void 0 : obj._DomRender_proxy) === null || _a === void 0 ? void 0 : _a.config;
43
+ ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " ").concat(script, " "), Object.assign(obj, {
44
+ __render: Object.freeze({
45
+ target: Types_1.DomRenderFinalProxy.final(event.target),
46
+ element: it,
47
+ event: event,
48
+ range: Range_1.Range.range,
49
+ scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
50
+ })
51
+ }));
52
+ }
53
+ });
54
+ });
55
+ });
56
+ }
57
+ }
58
+ // // 순환참조때문에 우선 여기에 뺴놓는다.
59
+ // public DomrenderProxyFinal(obj: any) {
60
+ // (obj as any)._DomRender_isFinal = true;
61
+ // return obj;
62
+ // }
63
+ EventManager.prototype.findAttrElements = function (fragment, config) {
64
+ var _a, _b;
65
+ // const datas: {name: string, value: string | null, element: Element}[] = [];
66
+ var elements = new Set();
67
+ var addAttributes = (_b = (_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.map(function (it) { return it.attrName; })) !== null && _b !== void 0 ? _b : [];
68
+ addAttributes.concat(this.attrNames).forEach(function (attrName) {
69
+ fragment === null || fragment === void 0 ? void 0 : fragment.querySelectorAll("[".concat(attrName, "]")).forEach(function (it) {
70
+ elements.add(it);
71
+ });
72
+ });
73
+ return elements;
74
+ };
75
+ // eslint-disable-next-line no-undef
76
+ EventManager.prototype.applyEvent = function (obj, childNodes, config) {
77
+ var _this = this;
78
+ // console.log('eventManager applyEvent==>', obj, childNodes, config)
79
+ // Node.ELEMENT_NODE = 1
80
+ // event
81
+ // childNodes.forEach(it => {
82
+ // if (it instanceof Element) {
83
+ // it.setAttribute('dr-thieVariableName', 'this')
84
+ // }
85
+ // })
86
+ this.eventNames.forEach(function (it) {
87
+ _this.addDrEvents(obj, it, childNodes, config);
88
+ });
89
+ this.addDrEventPram(obj, this.eventParam, childNodes, config);
90
+ // value
91
+ this.procAttr(childNodes, EventManager.valueAttrName, function (it, attribute) {
92
+ var script = attribute;
93
+ if (script) {
94
+ var data = ScriptUtils_1.ScriptUtils.evalReturn(script, obj);
95
+ if (it.value !== data) {
96
+ it.value = data;
97
+ }
98
+ }
99
+ });
100
+ // normal-attr-map
101
+ this.procAttr(childNodes, EventManager.normalAttrMapAttrName, function (it, attribute) {
102
+ var map = new Map(JSON.parse(attribute));
103
+ map.forEach(function (v, k) {
104
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; return ".concat(v, " "), Object.assign(obj, {
105
+ __render: Object.freeze({
106
+ element: it
107
+ })
108
+ }));
109
+ it.setAttribute(k, data);
110
+ });
111
+ });
112
+ // window event
113
+ EventManager.WINDOW_EVENTS.forEach(function (it) {
114
+ _this.procAttr(childNodes, EventManager.attrPrefix + 'window-event-' + it, function (it, attribute) {
115
+ it.obj = obj;
116
+ });
117
+ });
118
+ // on-init event
119
+ this.procAttr(childNodes, EventManager.onInitAttrName, function (it, attribute) {
120
+ var script = attribute;
121
+ if (script) {
122
+ script = 'return ' + script;
123
+ }
124
+ if (script) {
125
+ var data = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, "; ").concat(script, " "), Object.assign(obj, {
126
+ __render: Object.freeze({
127
+ element: it
128
+ })
129
+ }));
130
+ // console.log('onInit--->', obj, varName, it)
131
+ // if (typeof this.getValue(obj, varName) === 'function') {
132
+ // this.getValue(obj, varName)(it);
133
+ // } else {
134
+ // this.setValue(obj, varName, it);
135
+ // }
136
+ }
137
+ });
138
+ // value-link event
139
+ this.procAttr(childNodes, EventManager.valueLinkAttrName, function (it, varName) {
140
+ if (varName) {
141
+ var ownerVariablePathName = it.getAttribute(EventManager.ownerVariablePathAttrName);
142
+ var mapScript_1 = it.getAttribute("".concat(EventManager.valueLinkAttrName, ":map"));
143
+ // const inMapScript = it.getAttribute(`${valueLinkAttrName}:in-map`);
144
+ var bindObj_1 = obj;
145
+ if (ownerVariablePathName) {
146
+ bindObj_1 = ScriptUtils_1.ScriptUtils.evalReturn(ownerVariablePathName, obj);
147
+ }
148
+ var getValue = _this.getValue(obj, varName, bindObj_1);
149
+ // 아래 나중에 리팩토링 필요함
150
+ if (typeof getValue === 'function' && getValue) {
151
+ var setValue = it.value;
152
+ if (mapScript_1) {
153
+ setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, { __render: Object.freeze({ element: it, target: bindObj_1, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
154
+ }
155
+ getValue(setValue);
156
+ // 여기서 value가 먼저냐 value-link가 먼저냐 선을 정해야되는거네...
157
+ }
158
+ else if (getValue) {
159
+ var setValue = getValue;
160
+ if (mapScript_1) {
161
+ setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, { __render: Object.freeze({ element: it, target: bindObj_1, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
162
+ }
163
+ it.value = setValue;
164
+ // this.setValue(obj, varName, setValue)
165
+ }
166
+ // } else if (getValue) { // 이구분이 있어야되나?? 없어도될것같은데..
167
+ // let setValue = getValue;
168
+ // if (inMapScript) {
169
+ // setValue = ScriptUtils.eval(`${this.bindScript} return ${inMapScript}`, Object.assign(bindObj, {__render: Object.freeze({element: it, target: bindObj, range: Range.range, value: setValue, scripts: EventManager.setBindProperty(config?.scripts, obj)})}));
170
+ // }
171
+ // this.setValue(obj, varName, setValue)
172
+ // } else {
173
+ // let setValue = it.value;
174
+ // if (mapScript) {
175
+ // setValue = ScriptUtils.eval(`${this.bindScript} return ${mapScript}`, Object.assign(bindObj, {__render: Object.freeze({element: it, target: bindObj, range: Range.range, value: setValue, scripts: EventManager.setBindProperty(config?.scripts, obj)})}));
176
+ // }
177
+ // this.setValue(obj, varName, setValue)
178
+ // }
179
+ it.addEventListener('input', function (event) {
180
+ var value = it.value;
181
+ if (mapScript_1) {
182
+ value = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript_1), Object.assign(bindObj_1, {
183
+ __render: Object.freeze({
184
+ event: event,
185
+ element: it,
186
+ target: event.target,
187
+ range: Range_1.Range.range,
188
+ scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
189
+ })
190
+ }));
191
+ }
192
+ if (typeof _this.getValue(obj, varName, bindObj_1) === 'function') {
193
+ _this.getValue(obj, varName, bindObj_1)(value, event);
194
+ }
195
+ else {
196
+ _this.setValue(obj, varName, value);
197
+ }
198
+ });
199
+ }
200
+ });
201
+ this.changeVar(obj, childNodes, undefined, config);
202
+ // console.log('eventManager-applyEvent-->', config?.applyEvents)
203
+ var elements = Array.from(childNodes).filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; });
204
+ elements.forEach(function (it) {
205
+ var _a;
206
+ (_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName) !== null; }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
207
+ });
208
+ };
209
+ // eslint-disable-next-line no-undef
210
+ EventManager.prototype.changeVar = function (obj, elements, varName, config) {
211
+ var _this = this;
212
+ // console.log('-changeVar-->', obj, elements, varName);
213
+ // value-link event
214
+ this.procAttr(elements, EventManager.valueLinkAttrName, function (it, attribute) {
215
+ var ownerVariablePathName = it.getAttribute(EventManager.ownerVariablePathAttrName);
216
+ var bindObj = obj;
217
+ if (ownerVariablePathName) {
218
+ bindObj = ScriptUtils_1.ScriptUtils.evalReturn(ownerVariablePathName, obj);
219
+ }
220
+ var mapScript = it.getAttribute("".concat(EventManager.valueLinkAttrName, ":map"));
221
+ if (attribute && attribute === varName) {
222
+ var getValue = _this.getValue(obj, attribute, bindObj);
223
+ if (typeof getValue === 'function' && getValue) {
224
+ var setValue = it.value;
225
+ if (mapScript) {
226
+ setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript), Object.assign(bindObj, { __render: Object.freeze({ element: it, target: bindObj, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
227
+ }
228
+ getValue(setValue);
229
+ }
230
+ else { // if (getValue !== undefined && getValue !== null)
231
+ var setValue = getValue;
232
+ if (mapScript) {
233
+ setValue = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(mapScript), Object.assign(bindObj, { __render: Object.freeze({ element: it, target: bindObj, range: Range_1.Range.range, value: setValue, scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }) }));
234
+ }
235
+ it.value = setValue;
236
+ }
237
+ }
238
+ });
239
+ // attribute
240
+ this.procAttr(elements, EventManager.attrAttrName, function (it, attribute) {
241
+ var script = attribute;
242
+ if (script) {
243
+ script = 'return ' + script;
244
+ }
245
+ if (_this.isUsingThisVar(script, varName) || varName === undefined) {
246
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
247
+ __render: Object.freeze({
248
+ element: it
249
+ })
250
+ }));
251
+ if (typeof data === 'string') {
252
+ data.split(',').forEach(function (sit) {
253
+ var _a = sit.split('='), key = _a[0], value = _a[1];
254
+ var s = value.trim();
255
+ var k = key.trim();
256
+ if (s === 'null') {
257
+ it.removeAttribute(k);
258
+ }
259
+ else {
260
+ it.setAttribute(k, s);
261
+ }
262
+ });
263
+ }
264
+ else if (Array.isArray(data)) {
265
+ data.forEach(function (sit) {
266
+ var _a = sit.split('='), key = _a[0], value = _a[1];
267
+ var s = value.trim();
268
+ var k = key.trim();
269
+ if (s === 'null') {
270
+ it.removeAttribute(k);
271
+ }
272
+ else {
273
+ it.setAttribute(k, s);
274
+ }
275
+ });
276
+ }
277
+ else {
278
+ for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
279
+ var _b = _a[_i], key = _b[0], value = _b[1];
280
+ if (value === null) {
281
+ it.removeAttribute(key);
282
+ }
283
+ else {
284
+ it.setAttribute(key, String(value));
285
+ }
286
+ }
287
+ }
288
+ }
289
+ });
290
+ // style
291
+ this.procAttr(elements, EventManager.styleAttrName, function (it, attribute) {
292
+ var script = attribute;
293
+ if (script) {
294
+ script = 'return ' + script;
295
+ }
296
+ if (_this.isUsingThisVar(script, varName) || varName === undefined) {
297
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.__render.element; ".concat(script, " "), Object.assign(obj, {
298
+ __render: Object.freeze({
299
+ element: it
300
+ })
301
+ }));
302
+ if (typeof data === 'string') {
303
+ it.setAttribute('style', data);
304
+ }
305
+ else if (Array.isArray(data)) {
306
+ it.setAttribute('style', data.join(';'));
307
+ }
308
+ else {
309
+ for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
310
+ var _b = _a[_i], key = _b[0], value = _b[1];
311
+ if (it instanceof HTMLElement) {
312
+ it.style[key] = String(value);
313
+ }
314
+ }
315
+ }
316
+ }
317
+ });
318
+ // class
319
+ this.procAttr(elements, EventManager.classAttrName, function (it, attribute) {
320
+ var script = attribute;
321
+ if (script) {
322
+ script = 'return ' + script;
323
+ }
324
+ if (_this.isUsingThisVar(script, varName) || varName === undefined) {
325
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; ".concat(script, " "), Object.assign(obj, {
326
+ __render: Object.freeze({
327
+ element: it
328
+ })
329
+ }));
330
+ if (typeof data === 'string') {
331
+ it.setAttribute('class', data);
332
+ }
333
+ else if (Array.isArray(data)) {
334
+ it.setAttribute('class', data.join(' '));
335
+ }
336
+ else {
337
+ for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
338
+ var _b = _a[_i], key = _b[0], value = _b[1];
339
+ if (it instanceof HTMLElement) {
340
+ if (value) {
341
+ it.classList.add(key);
342
+ }
343
+ else {
344
+ it.classList.remove(key);
345
+ }
346
+ }
347
+ }
348
+ }
349
+ }
350
+ });
351
+ // normal-attr-map
352
+ this.procAttr(elements, EventManager.normalAttrMapAttrName, function (it, attribute) {
353
+ var map = new Map(JSON.parse(attribute));
354
+ map.forEach(function (v, k) {
355
+ // console.log('--->', v, k)
356
+ var isUsing = _this.isUsingThisVar(v, varName);
357
+ // console.log('---isUsing-->', varName, k, v, isUsing);
358
+ if (isUsing) {
359
+ var data = ScriptUtils_1.ScriptUtils.eval("const $element = this.element; return ".concat(v, " "), Object.assign(obj, {
360
+ __render: Object.freeze({
361
+ element: it
362
+ })
363
+ }));
364
+ it.setAttribute(k, data);
365
+ }
366
+ });
367
+ });
368
+ };
369
+ // eslint-disable-next-line no-undef
370
+ EventManager.prototype.addDrEvents = function (obj, eventName, elements, config) {
371
+ var _this = this;
372
+ var attr = EventManager.attrPrefix + 'event-' + eventName;
373
+ this.procAttr(elements, attr, function (it, attribute) {
374
+ var script = attribute;
375
+ it.addEventListener(eventName, function (event) {
376
+ var filter = true;
377
+ var filterScript = it.getAttribute("".concat(attr, ":filter"));
378
+ var attribute = DomUtils_1.DomUtils.getAttributeToObject(it);
379
+ var thisTarget = Object.assign(obj, {
380
+ __render: Object.freeze({
381
+ event: event,
382
+ element: it,
383
+ target: event.target,
384
+ range: Range_1.Range.range,
385
+ attribute: attribute,
386
+ router: config === null || config === void 0 ? void 0 : config.router,
387
+ scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
388
+ })
389
+ });
390
+ if (filterScript) {
391
+ filter = ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " return ").concat(filterScript), thisTarget);
392
+ }
393
+ if (filter) {
394
+ ScriptUtils_1.ScriptUtils.eval("".concat(_this.bindScript, " ").concat(script, " "), thisTarget);
395
+ }
396
+ });
397
+ });
398
+ };
399
+ EventManager.prototype.addDrEventPram = function (obj, attr, elements, config) {
400
+ var _this = this;
401
+ this.procAttr(elements, attr, function (it, attribute, attributes) {
402
+ var bind = attributes[attr + ':bind'];
403
+ if (bind) {
404
+ var script_1 = attribute;
405
+ var params_1 = {};
406
+ var prefix_1 = attr + ':';
407
+ Object.entries(attributes).filter(function (_a) {
408
+ var k = _a[0], v = _a[1];
409
+ return k.startsWith(prefix_1);
410
+ }).forEach(function (_a) {
411
+ var k = _a[0], v = _a[1];
412
+ params_1[k.slice(prefix_1.length)] = v;
413
+ });
414
+ bind.split(',').forEach(function (eventName) {
415
+ it.addEventListener(eventName.trim(), function (event) {
416
+ ScriptUtils_1.ScriptUtils.eval("const $params = this.__render.params; ".concat(_this.bindScript, " ").concat(script_1, " "), Object.assign(obj, {
417
+ __render: Object.freeze({
418
+ event: event,
419
+ element: it,
420
+ target: event.target,
421
+ range: Range_1.Range.range,
422
+ scripts: EventManager.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj),
423
+ params: params_1
424
+ })
425
+ }));
426
+ });
427
+ });
428
+ }
429
+ });
430
+ };
431
+ // eslint-disable-next-line no-undef
432
+ EventManager.prototype.procAttr = function (elements, attrName, callBack) {
433
+ if (elements === void 0) { elements = new Set(); }
434
+ var sets = new Set();
435
+ elements.forEach(function (it) {
436
+ // console.log('--->type', it, it.nodeType)
437
+ if (!it) {
438
+ return;
439
+ }
440
+ // Node.ELEMENT_NODE = 1
441
+ if (it.nodeType === 1) {
442
+ var e = it;
443
+ sets.add(e);
444
+ e.querySelectorAll("[".concat(attrName, "]")).forEach(function (it) {
445
+ sets.add(it);
446
+ });
447
+ }
448
+ });
449
+ sets.forEach(function (it) {
450
+ var attr = it.getAttribute(attrName);
451
+ var attrs = DomUtils_1.DomUtils.getAttributeToObject(it);
452
+ if (attr) {
453
+ callBack(it, attr, attrs);
454
+ }
455
+ });
456
+ };
457
+ EventManager.prototype.getValue = function (obj, name, bindObj) {
458
+ // let r = obj[name];
459
+ var r = ScriptUtils_1.ScriptUtils.evalReturn(name, obj);
460
+ if (typeof r === 'function') {
461
+ r = r.bind(bindObj !== null && bindObj !== void 0 ? bindObj : obj);
462
+ }
463
+ return r;
464
+ };
465
+ EventManager.prototype.setValue = function (obj, name, value) {
466
+ name = name.replaceAll('this.', 'this.this.');
467
+ ScriptUtils_1.ScriptUtils.eval("".concat(name, " = this.value;"), {
468
+ this: obj,
469
+ value: value
470
+ });
471
+ };
472
+ EventManager.prototype.isUsingThisVar = function (raws, varName) {
473
+ // console.log('isUsingV', raws)
474
+ // console.log('isUsingV', raws, varName, ScriptUtils.getVariablePaths(raws ?? ''))
475
+ if (varName && raws) {
476
+ if (varName.startsWith('this.')) {
477
+ varName = varName.replace(/this\./, '');
478
+ }
479
+ EventManager.VARNAMES.forEach(function (it) {
480
+ // raws = raws!.replace(RegExp(it.replace('$', '\\$'), 'g'), `this?.___${it}`);
481
+ raws = raws.replace(RegExp(it.replace('$', '\\$'), 'g'), "this.___".concat(it));
482
+ });
483
+ var variablePaths = ScriptUtils_1.ScriptUtils.getVariablePaths(raws !== null && raws !== void 0 ? raws : '');
484
+ return variablePaths.has(varName);
485
+ }
486
+ return false;
487
+ };
488
+ EventManager.setBindProperty = function (scripts, obj) {
489
+ if (scripts) {
490
+ // const newScripts = Object.assign({}, scripts)
491
+ var newScripts = Object.assign({}, scripts);
492
+ for (var _i = 0, _a = Object.entries(newScripts); _i < _a.length; _i++) {
493
+ var _b = _a[_i], key = _b[0], value = _b[1];
494
+ if (typeof value === 'function') {
495
+ newScripts[key] = value.bind(obj);
496
+ }
497
+ }
498
+ return newScripts;
499
+ }
500
+ };
501
+ EventManager.ownerVariablePathAttrName = 'dr-owner-variable-path';
502
+ EventManager.attrPrefix = 'dr-';
503
+ EventManager.onInitAttrName = EventManager.attrPrefix + 'on-init';
504
+ // public static readonly onComponentInitAttrName = EventManager.attrPrefix + 'on-component-init';
505
+ EventManager.valueAttrName = EventManager.attrPrefix + 'value';
506
+ EventManager.valueLinkAttrName = EventManager.attrPrefix + 'value-link';
507
+ EventManager.attrAttrName = EventManager.attrPrefix + 'attr';
508
+ EventManager.normalAttrMapAttrName = EventManager.attrPrefix + 'normal-attr-map';
509
+ EventManager.styleAttrName = EventManager.attrPrefix + 'style';
510
+ EventManager.classAttrName = EventManager.attrPrefix + 'class';
511
+ EventManager.VALUE_VARNAME = '$value';
512
+ EventManager.SCRIPTS_VARNAME = '$scripts';
513
+ EventManager.FAG_VARNAME = '$fag';
514
+ EventManager.RAWSET_VARNAME = '$rawset';
515
+ EventManager.RANGE_VARNAME = '$range';
516
+ EventManager.ROUTER_VARNAME = '$router';
517
+ EventManager.ELEMENT_VARNAME = '$element';
518
+ EventManager.TARGET_VARNAME = '$target';
519
+ EventManager.EVENT_VARNAME = '$event';
520
+ EventManager.COMPONENT_VARNAME = '$component';
521
+ EventManager.INNERHTML_VARNAME = '$innerHTML';
522
+ EventManager.ATTRIBUTE_VARNAME = '$attribute';
523
+ EventManager.VARNAMES = [EventManager.SCRIPTS_VARNAME, EventManager.FAG_VARNAME, EventManager.RAWSET_VARNAME, EventManager.RANGE_VARNAME, EventManager.ROUTER_VARNAME, EventManager.ELEMENT_VARNAME, EventManager.TARGET_VARNAME, EventManager.EVENT_VARNAME, EventManager.COMPONENT_VARNAME, EventManager.INNERHTML_VARNAME, EventManager.ATTRIBUTE_VARNAME];
524
+ EventManager.WINDOW_EVENT_POPSTATE = 'popstate';
525
+ EventManager.WINDOW_EVENT_RESIZE = 'resize';
526
+ EventManager.WINDOW_EVENTS = [EventManager.WINDOW_EVENT_POPSTATE, EventManager.WINDOW_EVENT_RESIZE];
527
+ return EventManager;
528
+ }());
529
+ exports.EventManager = EventManager;
530
+ exports.eventManager = new EventManager();