@dooboostore/dom-render 1.0.100 → 1.0.103
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.
- package/DomRender.d.ts +21 -6
- package/DomRender.js +54 -23
- package/DomRenderProxy.d.ts +7 -3
- package/DomRenderProxy.js +120 -49
- package/README.MD +469 -112
- package/components/ComponentBase.d.ts +12 -10
- package/components/ComponentBase.js +92 -46
- package/components/ComponentSet.d.ts +2 -2
- package/components/appender/Appender.d.ts +2 -2
- package/components/checkbox/CheckBox.d.ts +4 -4
- package/components/choose/Choose.d.ts +4 -4
- package/components/choose/Choose.js +0 -16
- package/components/details/Details.d.ts +5 -5
- package/components/forOf/ForOf.d.ts +2 -2
- package/components/if/If.d.ts +2 -2
- package/components/index.d.ts +26 -24
- package/components/index.js +2 -1
- package/components/input/Input.d.ts +2 -2
- package/components/input/Input.js +27 -24
- package/components/promise/PromiseSwitch.d.ts +6 -6
- package/components/promise/PromiseSwitch.js +15 -0
- package/components/radio/Radio.d.ts +4 -4
- package/components/router/Route.d.ts +32 -0
- package/components/router/Route.js +116 -0
- package/components/select/Select.d.ts +3 -3
- package/components/select/Select.js +2 -2
- package/components/this/This.d.ts +9 -2
- package/components/this/This.js +24 -2
- package/components/timer/Timer.d.ts +2 -2
- package/configs/Config.d.ts +6 -1
- package/decorators/DomRenderNoProxy.d.ts +2 -0
- package/decorators/DomRenderNoProxy.js +15 -0
- package/dist/bundle.js +2 -0
- package/events/EventManager.d.ts +16 -4
- package/events/EventManager.js +320 -140
- package/index.d.ts +48 -1
- package/index.js +40 -0
- package/lifecycle/OnDestroyRender.d.ts +1 -1
- package/lifecycle/OnProxyDomRender.d.ts +1 -0
- package/lifecycle/OnProxyDomRender.js +1 -1
- package/operators/DrForOf.js +2 -1
- package/operators/DrIf.js +3 -2
- package/operators/DrTargetElement.js +2 -1
- package/operators/DrTargetElementIsElement.d.ts +0 -5
- package/operators/DrTargetElementIsElement.js +2 -1
- package/operators/DrThis.js +40 -11
- package/operators/OperatorExecuter.js +3 -1
- package/package.json +5 -4
- package/rawsets/Attrs.d.ts +2 -0
- package/rawsets/RawSet.d.ts +2 -2
- package/rawsets/RawSet.js +48 -33
- package/routers/HashRouter.d.ts +5 -4
- package/routers/HashRouter.js +8 -5
- package/routers/PathRouter.d.ts +5 -4
- package/routers/PathRouter.js +6 -4
- package/routers/Router.d.ts +22 -8
- package/routers/Router.js +44 -24
package/events/EventManager.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { ScriptUtils } from '@dooboostore/core-web/script/ScriptUtils';
|
|
3
|
-
import {
|
|
3
|
+
import { ElementUtils } from '@dooboostore/core-web/element/ElementUtils';
|
|
4
4
|
import { Range } from '../iterators/Range';
|
|
5
|
-
import {
|
|
5
|
+
import { getDomRenderConfig } from '../DomRenderProxy';
|
|
6
6
|
export class EventManager {
|
|
7
|
-
constructor() {
|
|
7
|
+
constructor(window) {
|
|
8
|
+
this.window = window;
|
|
8
9
|
this.eventNames = [
|
|
9
10
|
'click', 'mousedown', 'mouseup', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave', 'contextmenu',
|
|
10
11
|
'keyup', 'keydown', 'keypress', 'toggle',
|
|
11
12
|
'change', 'input', 'submit', 'resize', 'focus', 'blur',
|
|
12
|
-
'close', 'cancel'
|
|
13
|
-
/*
|
|
14
|
-
close 이벤트: <dialog>가 닫힐 때 발생. 사용자가 취소 버튼, 확인 버튼, 또는 dialog.close() 메서드로 닫을 때 모두 트리거됩니다.
|
|
15
|
-
cancel 이벤트: <dialog>가 ESC 키나 취소 버튼으로 닫힐 때 발생. close 이벤트의 하위 이벤트로 볼 수 있습니다.
|
|
16
|
-
*/
|
|
13
|
+
'close', 'cancel'
|
|
17
14
|
];
|
|
15
|
+
this.delegatableEventMap = {
|
|
16
|
+
mouseleave: 'mouseout',
|
|
17
|
+
mouseenter: 'mouseover',
|
|
18
|
+
focus: 'focusin',
|
|
19
|
+
blur: 'focusout',
|
|
20
|
+
};
|
|
21
|
+
this.directAttachEvents = new Set(['close']);
|
|
18
22
|
this.bindScript = `
|
|
19
23
|
const ${_a.VALUE_VARNAME} = this.__render.value;
|
|
20
24
|
const ${_a.SCRIPTS_VARNAME} = this.__render.scripts;
|
|
@@ -35,36 +39,210 @@ export class EventManager {
|
|
|
35
39
|
window === null || window === void 0 ? void 0 : window.addEventListener(eventName, (event) => {
|
|
36
40
|
const targetAttr = `dr-window-event-${eventName}`;
|
|
37
41
|
document.querySelectorAll(`[${targetAttr}]`).forEach(it => {
|
|
38
|
-
var _b;
|
|
39
42
|
const script = it.getAttribute(targetAttr);
|
|
40
43
|
if (script) {
|
|
41
|
-
const obj = it
|
|
42
|
-
const config = (
|
|
43
|
-
ScriptUtils.eval(`${this.bindScript} ${script} `,
|
|
44
|
-
__render: Object.freeze({
|
|
45
|
-
target: DomRenderFinalProxy.final(event.target),
|
|
46
|
-
element: it,
|
|
47
|
-
event: event,
|
|
48
|
-
range: Range.range,
|
|
49
|
-
scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj)
|
|
50
|
-
// ...EventManager.eventVariables
|
|
51
|
-
})
|
|
52
|
-
}));
|
|
44
|
+
const obj = this.findComponentInstance(it);
|
|
45
|
+
const config = getDomRenderConfig(obj);
|
|
46
|
+
ScriptUtils.eval(`${this.bindScript} ${script} `, this.createExecutionContext(event, it, obj, config));
|
|
53
47
|
}
|
|
54
48
|
});
|
|
55
49
|
});
|
|
56
50
|
});
|
|
51
|
+
const rootElement = this.window.document;
|
|
52
|
+
const listeningEvents = new Set();
|
|
53
|
+
this.eventNames.forEach(eventName => {
|
|
54
|
+
if (this.directAttachEvents.has(eventName)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const delegatedEventName = this.delegatableEventMap[eventName] || eventName;
|
|
58
|
+
if (listeningEvents.has(delegatedEventName)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
listeningEvents.add(delegatedEventName);
|
|
62
|
+
rootElement.addEventListener(delegatedEventName, this.handleEvent.bind(this), true);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
handleEvent(event) {
|
|
67
|
+
const handlers = this.collectHandlers(event);
|
|
68
|
+
// console.log('handlers', handlers, event);
|
|
69
|
+
for (const handler of handlers) {
|
|
70
|
+
if (event.cancelBubble) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
const componentInstance = this.findComponentInstance(handler.element);
|
|
74
|
+
if (!componentInstance) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// console.log('executeHandler', event,handler,componentInstance)
|
|
78
|
+
this.executeHandler(event, handler, componentInstance);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
collectHandlers(event) {
|
|
82
|
+
const handlers = [];
|
|
83
|
+
const root = this.window.document;
|
|
84
|
+
if (!root)
|
|
85
|
+
return handlers;
|
|
86
|
+
const initialTarget = event.target;
|
|
87
|
+
let currentTarget = (initialTarget.nodeType === 1)
|
|
88
|
+
? initialTarget
|
|
89
|
+
: initialTarget.parentElement;
|
|
90
|
+
const collectedElements = new Set();
|
|
91
|
+
const eventMap = {
|
|
92
|
+
mouseout: 'mouseleave',
|
|
93
|
+
mouseover: 'mouseenter',
|
|
94
|
+
focusout: 'blur',
|
|
95
|
+
focusin: 'focus'
|
|
96
|
+
};
|
|
97
|
+
const mappedEventName = eventMap[event.type] || event.type;
|
|
98
|
+
while (currentTarget) {
|
|
99
|
+
if (collectedElements.has(currentTarget)) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
// Priority 1: Link attributes
|
|
103
|
+
const matchingLinkAttr = _a.linkAttrs.find(la => la.event === mappedEventName && (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.hasAttribute(la.name)));
|
|
104
|
+
if (matchingLinkAttr) {
|
|
105
|
+
handlers.push({
|
|
106
|
+
element: currentTarget,
|
|
107
|
+
attr: matchingLinkAttr.name,
|
|
108
|
+
type: 'link',
|
|
109
|
+
priority: 1,
|
|
110
|
+
property: matchingLinkAttr.property
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Priority 2: dr-event-* attributes
|
|
114
|
+
const eventAttr = `${_a.attrPrefix}event-${mappedEventName}`;
|
|
115
|
+
if (currentTarget.hasAttribute(eventAttr)) {
|
|
116
|
+
handlers.push({
|
|
117
|
+
element: currentTarget,
|
|
118
|
+
attr: eventAttr,
|
|
119
|
+
type: 'event',
|
|
120
|
+
priority: 2
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Priority 3: dr-event with params
|
|
124
|
+
const eventParamAttr = _a.eventParam;
|
|
125
|
+
if (currentTarget.hasAttribute(eventParamAttr)) {
|
|
126
|
+
const bindEvents = currentTarget.getAttribute(`${eventParamAttr}:bind`);
|
|
127
|
+
if (bindEvents && bindEvents.split(',').map(s => s.trim()).includes(mappedEventName)) {
|
|
128
|
+
handlers.push({
|
|
129
|
+
element: currentTarget,
|
|
130
|
+
attr: eventParamAttr,
|
|
131
|
+
type: 'event-param',
|
|
132
|
+
priority: 3
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
collectedElements.add(currentTarget);
|
|
137
|
+
if (currentTarget === root.documentElement) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
currentTarget = currentTarget.parentElement;
|
|
141
|
+
}
|
|
142
|
+
return handlers.sort((a, b) => a.priority - b.priority);
|
|
143
|
+
}
|
|
144
|
+
findComponentInstance(element) {
|
|
145
|
+
let current = element;
|
|
146
|
+
const root = this.window.document;
|
|
147
|
+
while (current) {
|
|
148
|
+
if (current.obj) {
|
|
149
|
+
return current.obj;
|
|
150
|
+
}
|
|
151
|
+
if (current === root.documentElement) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
current = current.parentElement;
|
|
155
|
+
}
|
|
156
|
+
return this.window;
|
|
157
|
+
}
|
|
158
|
+
createExecutionContext(event, element, componentInstance, config, extraVars = {}) {
|
|
159
|
+
// console.log('---------->', config?.eventVariables)
|
|
160
|
+
return Object.assign(componentInstance, {
|
|
161
|
+
__render: Object.freeze(Object.assign(Object.assign({ event,
|
|
162
|
+
element, target: event.target, attribute: ElementUtils.getAttributeToObject(element), router: config === null || config === void 0 ? void 0 : config.router, range: Range.range, scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, componentInstance) }, config === null || config === void 0 ? void 0 : config.eventVariables), extraVars))
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
executeHandler(event, handler, componentInstance) {
|
|
166
|
+
const { element, type, attr } = handler;
|
|
167
|
+
const config = getDomRenderConfig(componentInstance);
|
|
168
|
+
switch (type) {
|
|
169
|
+
case 'link':
|
|
170
|
+
const varName = element.getAttribute(attr);
|
|
171
|
+
if (!varName || !handler.property)
|
|
172
|
+
return;
|
|
173
|
+
if (attr.includes('leave') || attr.includes('enter') || attr.includes('focus') || attr.includes('blur')) {
|
|
174
|
+
const relatedTarget = event.relatedTarget;
|
|
175
|
+
if (relatedTarget && element.contains(relatedTarget)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const ownerVariablePath = element.getAttribute(_a.ownerVariablePathAttrName);
|
|
180
|
+
let bindObj = componentInstance;
|
|
181
|
+
if (ownerVariablePath) {
|
|
182
|
+
bindObj = ScriptUtils.evalReturn(ownerVariablePath, componentInstance);
|
|
183
|
+
}
|
|
184
|
+
const mapScript = element.getAttribute(`${attr}:map`);
|
|
185
|
+
let value = element[handler.property];
|
|
186
|
+
if (mapScript) {
|
|
187
|
+
const context = this.createExecutionContext(event, element, bindObj, config, { value });
|
|
188
|
+
value = ScriptUtils.eval(`return ${mapScript}`, context);
|
|
189
|
+
}
|
|
190
|
+
if (typeof this.getValue(componentInstance, varName, bindObj) === 'function') {
|
|
191
|
+
this.getValue(componentInstance, varName, bindObj)(value, event);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
this.setValue(componentInstance, varName, value);
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case 'event':
|
|
198
|
+
const script = element.getAttribute(attr);
|
|
199
|
+
if (!script)
|
|
200
|
+
return;
|
|
201
|
+
if (attr.endsWith('mouseleave') || attr.endsWith('mouseenter') || attr.endsWith('blur') || attr.endsWith('focus')) {
|
|
202
|
+
const relatedTarget = event.relatedTarget;
|
|
203
|
+
if (relatedTarget && element.contains(relatedTarget)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const context = this.createExecutionContext(event, element, componentInstance, config);
|
|
208
|
+
const filterScript = element.getAttribute(`${attr}:filter`);
|
|
209
|
+
let filter = true;
|
|
210
|
+
// 개발자가 사용중에 문제가 발생될(디버깅) 버그를 유발할수있는 기능 흐름제어가 안될수있어 기능을 제거한다.
|
|
211
|
+
// if (filterScript) {
|
|
212
|
+
// filter = ScriptUtils.eval<boolean>(`${this.getBindScript(config)} return ${filterScript}`, context) ?? false;
|
|
213
|
+
// }
|
|
214
|
+
if (filter) {
|
|
215
|
+
ScriptUtils.eval(`${this.getBindScript(config)} ${script}`, context);
|
|
216
|
+
}
|
|
217
|
+
// 개발자가 사용중에 문제가 발생될(디버깅) 버그를 유발할수있는 기능 흐름제어가 안될수있어 기능을 제거한다.
|
|
218
|
+
// const hasDispatch = element.hasAttribute(`${attr}:dispatch`);
|
|
219
|
+
// if (hasDispatch) {
|
|
220
|
+
// element.dispatchEvent(new Event(event.type));
|
|
221
|
+
// }
|
|
222
|
+
break;
|
|
223
|
+
case 'event-param':
|
|
224
|
+
const paramScript = element.getAttribute(attr);
|
|
225
|
+
if (!paramScript)
|
|
226
|
+
return;
|
|
227
|
+
if (attr.endsWith('mouseleave') || attr.endsWith('mouseenter') || attr.endsWith('blur') || attr.endsWith('focus')) {
|
|
228
|
+
const relatedTarget = event.relatedTarget;
|
|
229
|
+
if (relatedTarget && element.contains(relatedTarget)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const attributes = ElementUtils.getAttributeToObject(element);
|
|
234
|
+
const params = {};
|
|
235
|
+
const prefix = attr + ':';
|
|
236
|
+
Object.entries(attributes).filter(([k, v]) => k.startsWith(prefix)).forEach(([k, v]) => {
|
|
237
|
+
params[k.slice(prefix.length)] = v;
|
|
238
|
+
});
|
|
239
|
+
const paramContext = this.createExecutionContext(event, element, componentInstance, config, { params });
|
|
240
|
+
ScriptUtils.eval(`${this.getBindScript(config)} ${paramScript}`, paramContext);
|
|
241
|
+
break;
|
|
57
242
|
}
|
|
58
243
|
}
|
|
59
|
-
// // 순환참조때문에 우선 여기에 뺴놓는다.
|
|
60
|
-
// public DomrenderProxyFinal(obj: any) {
|
|
61
|
-
// (obj as any)._DomRender_isFinal = true;
|
|
62
|
-
// return obj;
|
|
63
|
-
// }
|
|
64
|
-
// 중요 이벤트에 대상이될 Elements를 찾는다.
|
|
65
244
|
findAttrElements(fragment, config) {
|
|
66
245
|
var _b, _c;
|
|
67
|
-
// const datas: {name: string, value: string | null, element: Element}[] = [];
|
|
68
246
|
const elements = new Set();
|
|
69
247
|
const addAttributes = (_c = (_b = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _b === void 0 ? void 0 : _b.map(it => it.attrName)) !== null && _c !== void 0 ? _c : [];
|
|
70
248
|
addAttributes.concat([..._a.attrNames]).forEach(attrName => {
|
|
@@ -74,23 +252,12 @@ export class EventManager {
|
|
|
74
252
|
});
|
|
75
253
|
return elements;
|
|
76
254
|
}
|
|
77
|
-
// 중요 처음 이벤트 처리
|
|
78
|
-
// eslint-disable-next-line no-undef
|
|
79
255
|
applyEvent(obj, childNodes, config) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// if (it instanceof Element) {
|
|
85
|
-
// it.setAttribute('dr-thieVariableName', 'this')
|
|
86
|
-
// }
|
|
87
|
-
// })
|
|
88
|
-
// 중요 이벤트 걸어줌
|
|
89
|
-
this.eventNames.forEach(it => {
|
|
90
|
-
this.addDrEvents(obj, it, childNodes, config);
|
|
256
|
+
childNodes.forEach(node => {
|
|
257
|
+
if (node.nodeType === 1) {
|
|
258
|
+
node.obj = obj;
|
|
259
|
+
}
|
|
91
260
|
});
|
|
92
|
-
this.addDrEventPram(obj, _a.eventParam, childNodes, config);
|
|
93
|
-
// value
|
|
94
261
|
this.procAttr(childNodes, _a.valueAttrName, (it, attribute) => {
|
|
95
262
|
const script = attribute;
|
|
96
263
|
if (script) {
|
|
@@ -100,17 +267,78 @@ export class EventManager {
|
|
|
100
267
|
}
|
|
101
268
|
}
|
|
102
269
|
});
|
|
103
|
-
|
|
270
|
+
this.procAttr(childNodes, _a.checkedAttrName, (it, attribute) => {
|
|
271
|
+
const script = attribute;
|
|
272
|
+
if (script) {
|
|
273
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
274
|
+
if (it.checked !== data) {
|
|
275
|
+
it.checked = data;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
this.procAttr(childNodes, _a.selectedAttrName, (it, attribute) => {
|
|
280
|
+
const script = attribute;
|
|
281
|
+
if (script) {
|
|
282
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
283
|
+
if (it.selected !== data) {
|
|
284
|
+
it.selected = data;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
this.procAttr(childNodes, _a.readonlyAttrName, (it, attribute) => {
|
|
289
|
+
const script = attribute;
|
|
290
|
+
if (script) {
|
|
291
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
292
|
+
if (it.readOnly !== data) {
|
|
293
|
+
it.readOnly = data;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
this.procAttr(childNodes, _a.disabledAttrName, (it, attribute) => {
|
|
298
|
+
const script = attribute;
|
|
299
|
+
if (script) {
|
|
300
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
301
|
+
if (it.disabled !== data) {
|
|
302
|
+
it.disabled = data;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
this.procAttr(childNodes, _a.hiddenAttrName, (it, attribute) => {
|
|
307
|
+
const script = attribute;
|
|
308
|
+
if (script) {
|
|
309
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
310
|
+
if (it.hidden !== data) {
|
|
311
|
+
it.hidden = data;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
this.procAttr(childNodes, _a.requiredAttrName, (it, attribute) => {
|
|
316
|
+
const script = attribute;
|
|
317
|
+
if (script) {
|
|
318
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
319
|
+
if (it.required !== data) {
|
|
320
|
+
it.required = data;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
this.procAttr(childNodes, _a.openAttrName, (it, attribute) => {
|
|
325
|
+
const script = attribute;
|
|
326
|
+
if (script) {
|
|
327
|
+
const data = ScriptUtils.evalReturn(script, obj);
|
|
328
|
+
if (it.open !== data) {
|
|
329
|
+
it.open = data;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
104
333
|
this.procAttr(childNodes, _a.normalAttrMapAttrName, (it, attribute) => {
|
|
105
334
|
const map = new Map(JSON.parse(attribute));
|
|
106
335
|
map.forEach((v, k) => {
|
|
107
336
|
const data = ScriptUtils.eval(`const $element = this.element; return ${v} `, Object.assign(obj, {
|
|
108
337
|
__render: Object.freeze({
|
|
109
338
|
element: it,
|
|
110
|
-
attribute:
|
|
339
|
+
attribute: ElementUtils.getAttributeToObject(it)
|
|
111
340
|
})
|
|
112
341
|
}));
|
|
113
|
-
// console.log('-------normalAttribute---datadatadata',data)
|
|
114
342
|
if (data === null) {
|
|
115
343
|
it.removeAttribute(k);
|
|
116
344
|
}
|
|
@@ -119,25 +347,22 @@ export class EventManager {
|
|
|
119
347
|
}
|
|
120
348
|
});
|
|
121
349
|
});
|
|
122
|
-
// window event
|
|
123
350
|
_a.WINDOW_EVENTS.forEach(it => {
|
|
124
351
|
this.procAttr(childNodes, _a.attrPrefix + 'window-event-' + it, (it, attribute) => {
|
|
125
352
|
it.obj = obj;
|
|
126
353
|
});
|
|
127
354
|
});
|
|
128
|
-
// value-link event
|
|
129
355
|
_a.linkAttrs.forEach(linkInfo => {
|
|
130
356
|
this.procAttr(childNodes, linkInfo.name, (it, varName) => {
|
|
357
|
+
// console.log('ink??????????')
|
|
131
358
|
if (varName) {
|
|
132
359
|
const ownerVariablePathName = it.getAttribute(_a.ownerVariablePathAttrName);
|
|
133
360
|
const mapScript = it.getAttribute(`${linkInfo.name}:map`);
|
|
134
|
-
// const inMapScript = it.getAttribute(`${valueLinkAttrName}:in-map`);
|
|
135
361
|
let bindObj = obj;
|
|
136
362
|
if (ownerVariablePathName) {
|
|
137
363
|
bindObj = ScriptUtils.evalReturn(ownerVariablePathName, obj);
|
|
138
364
|
}
|
|
139
365
|
const getValue = this.getValue(obj, varName, bindObj);
|
|
140
|
-
// TODO: 아래 나중에 리팩토링 필요함
|
|
141
366
|
if (typeof getValue === 'function' && getValue) {
|
|
142
367
|
let setValue = it[linkInfo.property];
|
|
143
368
|
if (mapScript) {
|
|
@@ -150,64 +375,62 @@ export class EventManager {
|
|
|
150
375
|
if (mapScript) {
|
|
151
376
|
setValue = ScriptUtils.eval(`${this.getBindScript(config)} return ${mapScript}`, Object.assign(bindObj, { __render: Object.freeze(Object.assign({ element: it, target: bindObj, range: Range.range, value: setValue, scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }, config === null || config === void 0 ? void 0 : config.eventVariables)) }));
|
|
152
377
|
}
|
|
153
|
-
// console.log('------->',it.value, setValue)
|
|
154
378
|
if (setValue === null) {
|
|
155
379
|
it.removeAttribute(linkInfo.property);
|
|
156
380
|
}
|
|
157
381
|
else {
|
|
158
|
-
// console.log('-----------',it, setValue)
|
|
159
382
|
it[linkInfo.property] = setValue;
|
|
160
383
|
}
|
|
161
|
-
// 여기서 value가 먼저냐 value-link가 먼저냐 선을 정해야되는거네..-> 라고해서 undefined일때에는 element값을 먼저셋팅해준다.
|
|
162
384
|
}
|
|
163
385
|
else if (getValue === undefined) {
|
|
164
386
|
this.setValue(obj, varName, it[linkInfo.property]);
|
|
165
387
|
}
|
|
166
|
-
it.addEventListener(linkInfo.event, (event) => {
|
|
167
|
-
let value = it[linkInfo.property];
|
|
168
|
-
if (mapScript) {
|
|
169
|
-
value = ScriptUtils.eval(`${this.getBindScript(config)} return ${mapScript}`, Object.assign(bindObj, {
|
|
170
|
-
__render: Object.freeze(Object.assign({ event, element: it, attribute: DomUtils.getAttributeToObject(it), target: event.target, range: Range.range, scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }, config === null || config === void 0 ? void 0 : config.eventVariables))
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
if (typeof this.getValue(obj, varName, bindObj) === 'function') {
|
|
174
|
-
this.getValue(obj, varName, bindObj)(value, event);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this.setValue(obj, varName, value);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
388
|
}
|
|
181
389
|
});
|
|
182
390
|
});
|
|
183
|
-
|
|
391
|
+
this.directAttachEvents.forEach(eventName => {
|
|
392
|
+
const attr = `${_a.attrPrefix}event-${eventName}`;
|
|
393
|
+
this.procAttr(childNodes, attr, (element, script) => {
|
|
394
|
+
const handler = (event) => {
|
|
395
|
+
var _b;
|
|
396
|
+
const componentInstance = this.findComponentInstance(element);
|
|
397
|
+
if (!componentInstance)
|
|
398
|
+
return;
|
|
399
|
+
const context = this.createExecutionContext(event, element, componentInstance, config);
|
|
400
|
+
const filterScript = element.getAttribute(`${attr}:filter`);
|
|
401
|
+
let filter = true;
|
|
402
|
+
if (filterScript) {
|
|
403
|
+
filter = (_b = ScriptUtils.eval(`${this.getBindScript(config)} return ${filterScript}`, context)) !== null && _b !== void 0 ? _b : false;
|
|
404
|
+
}
|
|
405
|
+
if (filter) {
|
|
406
|
+
ScriptUtils.eval(`${this.getBindScript(config)} ${script}`, context);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
element.addEventListener(eventName, handler);
|
|
410
|
+
// TODO: Add logic to remove this listener when the element is destroyed.
|
|
411
|
+
});
|
|
412
|
+
});
|
|
184
413
|
this.procAttr(childNodes, _a.onInitAttrName, (it, attribute) => {
|
|
185
|
-
// it.removeAttribute(EventManager.onInitAttrName);
|
|
186
414
|
let script = attribute;
|
|
187
415
|
if (script) {
|
|
188
416
|
script = 'return ' + script;
|
|
189
417
|
}
|
|
190
418
|
if (script) {
|
|
191
419
|
ScriptUtils.eval(`${this.getBindScript(config)}; ${script} `, Object.assign(obj, {
|
|
192
|
-
__render: Object.freeze(Object.assign({ element: it, attribute:
|
|
420
|
+
__render: Object.freeze(Object.assign({ element: it, attribute: ElementUtils.getAttributeToObject(it) }, config === null || config === void 0 ? void 0 : config.eventVariables))
|
|
193
421
|
}));
|
|
194
422
|
}
|
|
195
423
|
});
|
|
196
424
|
this.onRenderedEvent(obj, childNodes, config);
|
|
197
425
|
this.changeVar(obj, childNodes, undefined, config);
|
|
198
|
-
// console.log('eventManager-applyEvent-->', config?.applyEvents)
|
|
199
426
|
const elements = Array.from(childNodes).filter(it => it.nodeType === 1).map(it => it);
|
|
200
427
|
elements.forEach(it => {
|
|
201
428
|
var _b;
|
|
202
429
|
(_b = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _b === void 0 ? void 0 : _b.filter(ta => it.getAttribute(ta.attrName) !== null).forEach(ta => ta.callBack(it, it.getAttribute(ta.attrName), obj));
|
|
203
430
|
});
|
|
204
431
|
}
|
|
205
|
-
// RawSet에서 replaceBody이후에 호출
|
|
206
432
|
onRenderedEvent(obj, childNodes, config) {
|
|
207
|
-
// console.log('--------onRenderedEvent', obj, childNodes);
|
|
208
|
-
// console.log(document.querySelectorAll(`[${EventManager.onRenderedInitAttrName}]`))
|
|
209
433
|
this.procAttr(childNodes, _a.onRenderedInitAttrName, (it, attribute) => {
|
|
210
|
-
// it.removeAttribute(EventManager.onRenderedInitAttrName);
|
|
211
434
|
if (!it.isConnected) {
|
|
212
435
|
return;
|
|
213
436
|
}
|
|
@@ -215,17 +438,15 @@ export class EventManager {
|
|
|
215
438
|
if (script) {
|
|
216
439
|
script = 'return ' + script;
|
|
217
440
|
}
|
|
218
|
-
// console.log('onRendered!!')
|
|
219
441
|
if (script) {
|
|
220
442
|
ScriptUtils.eval(`${this.getBindScript(config)}; ${script} `, Object.assign(obj, {
|
|
221
|
-
__render: Object.freeze(Object.assign({ element: it, attribute:
|
|
443
|
+
__render: Object.freeze(Object.assign({ element: it, attribute: ElementUtils.getAttributeToObject(it) }, config === null || config === void 0 ? void 0 : config.eventVariables))
|
|
222
444
|
}));
|
|
223
445
|
}
|
|
224
446
|
});
|
|
225
447
|
}
|
|
226
|
-
// eslint-disable-next-line no-undef
|
|
227
448
|
changeVar(obj, elements, varName, config) {
|
|
228
|
-
//
|
|
449
|
+
// console.log('changeVar', obj, elements, varName)
|
|
229
450
|
this.procAttr(elements, _a.styleAttrName, (it, attribute) => {
|
|
230
451
|
let script = attribute;
|
|
231
452
|
if (script) {
|
|
@@ -235,7 +456,7 @@ export class EventManager {
|
|
|
235
456
|
const data = ScriptUtils.eval(`const $element = this.__render.element; ${script} `, Object.assign(obj, {
|
|
236
457
|
__render: Object.freeze({
|
|
237
458
|
element: it,
|
|
238
|
-
attribute:
|
|
459
|
+
attribute: ElementUtils.getAttributeToObject(it)
|
|
239
460
|
})
|
|
240
461
|
}));
|
|
241
462
|
if (typeof data === 'string') {
|
|
@@ -253,7 +474,6 @@ export class EventManager {
|
|
|
253
474
|
}
|
|
254
475
|
}
|
|
255
476
|
});
|
|
256
|
-
// class
|
|
257
477
|
this.procAttr(elements, _a.classAttrName, (it, attribute) => {
|
|
258
478
|
let script = attribute;
|
|
259
479
|
if (script) {
|
|
@@ -263,7 +483,7 @@ export class EventManager {
|
|
|
263
483
|
const data = ScriptUtils.eval(`const $element = this.element; ${script} `, Object.assign(obj, {
|
|
264
484
|
__render: Object.freeze({
|
|
265
485
|
element: it,
|
|
266
|
-
attribute:
|
|
486
|
+
attribute: ElementUtils.getAttributeToObject(it)
|
|
267
487
|
})
|
|
268
488
|
}));
|
|
269
489
|
if (typeof data === 'string') {
|
|
@@ -286,63 +506,13 @@ export class EventManager {
|
|
|
286
506
|
}
|
|
287
507
|
}
|
|
288
508
|
});
|
|
289
|
-
// this.onRenderedEvent(obj,elements, config);
|
|
290
|
-
}
|
|
291
|
-
addDrEvents(obj, eventName, elements, config) {
|
|
292
|
-
// console.log('-------?', config?.router)
|
|
293
|
-
const attr = _a.attrPrefix + 'event-' + eventName;
|
|
294
|
-
this.procAttr(elements, attr, (it, attribute) => {
|
|
295
|
-
const script = attribute;
|
|
296
|
-
const hasDispatch = it.hasAttribute(`${attr}:dispatch`);
|
|
297
|
-
// console.log('hasDispatch',hasDispatch, attr, it);
|
|
298
|
-
it.addEventListener(eventName, (event) => {
|
|
299
|
-
let filter = true;
|
|
300
|
-
const filterScript = it.getAttribute(`${attr}:filter`);
|
|
301
|
-
const thisTarget = Object.assign(obj, {
|
|
302
|
-
__render: Object.freeze(Object.assign({ event, element: it, target: event.target, range: Range.range, attribute: DomUtils.getAttributeToObject(it), router: config === null || config === void 0 ? void 0 : config.router, scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj) }, config === null || config === void 0 ? void 0 : config.eventVariables))
|
|
303
|
-
});
|
|
304
|
-
if (filterScript) {
|
|
305
|
-
filter = ScriptUtils.eval(`${this.getBindScript(config)} return ${filterScript}`, thisTarget);
|
|
306
|
-
}
|
|
307
|
-
if (filter) {
|
|
308
|
-
ScriptUtils.eval(`${this.getBindScript(config)} ${script} `, thisTarget);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
if (hasDispatch) {
|
|
312
|
-
it.dispatchEvent(new Event(eventName));
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
// eslint-disable-next-line no-undef
|
|
317
|
-
addDrEventPram(obj, attr, elements, config) {
|
|
318
|
-
this.procAttr(elements, attr, (it, attribute, attributes) => {
|
|
319
|
-
const bind = attributes[attr + ':bind'];
|
|
320
|
-
if (bind) {
|
|
321
|
-
const script = attribute;
|
|
322
|
-
const params = {};
|
|
323
|
-
const prefix = attr + ':';
|
|
324
|
-
Object.entries(attributes).filter(([k, v]) => k.startsWith(prefix)).forEach(([k, v]) => {
|
|
325
|
-
params[k.slice(prefix.length)] = v;
|
|
326
|
-
});
|
|
327
|
-
bind.split(',').forEach(eventName => {
|
|
328
|
-
it.addEventListener(eventName.trim(), (event) => {
|
|
329
|
-
ScriptUtils.eval(`const $params = this.__render.params; ${this.getBindScript(config)} ${script} `, Object.assign(obj, {
|
|
330
|
-
__render: Object.freeze(Object.assign({ event, element: it, attribute: DomUtils.getAttributeToObject(it), target: event.target, range: Range.range, scripts: _a.setBindProperty(config === null || config === void 0 ? void 0 : config.scripts, obj), params }, config === null || config === void 0 ? void 0 : config.eventVariables))
|
|
331
|
-
}));
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
509
|
}
|
|
337
|
-
// eslint-disable-next-line no-undef
|
|
338
510
|
procAttr(elements = new Set(), attrName, callBack) {
|
|
339
511
|
const sets = new Set();
|
|
340
512
|
elements.forEach(it => {
|
|
341
|
-
// console.log('--->type', it, it.nodeType)
|
|
342
513
|
if (!it) {
|
|
343
514
|
return;
|
|
344
515
|
}
|
|
345
|
-
// Node.ELEMENT_NODE = 1
|
|
346
516
|
if (it.nodeType === 1) {
|
|
347
517
|
const e = it;
|
|
348
518
|
sets.add(e);
|
|
@@ -351,17 +521,15 @@ export class EventManager {
|
|
|
351
521
|
});
|
|
352
522
|
}
|
|
353
523
|
});
|
|
354
|
-
// console.log('---setr',sets);
|
|
355
524
|
sets.forEach(it => {
|
|
356
525
|
const attr = it.getAttribute(attrName);
|
|
357
|
-
const attrs =
|
|
526
|
+
const attrs = ElementUtils.getAttributeToObject(it);
|
|
358
527
|
if (attr) {
|
|
359
528
|
callBack(it, attr, attrs);
|
|
360
529
|
}
|
|
361
530
|
});
|
|
362
531
|
}
|
|
363
532
|
getValue(obj, name, bindObj) {
|
|
364
|
-
// let r = obj[name];
|
|
365
533
|
let r = ScriptUtils.evalReturn(name, obj);
|
|
366
534
|
if (typeof r === 'function') {
|
|
367
535
|
r = r.bind(bindObj !== null && bindObj !== void 0 ? bindObj : obj);
|
|
@@ -376,8 +544,6 @@ export class EventManager {
|
|
|
376
544
|
});
|
|
377
545
|
}
|
|
378
546
|
static isUsingThisVar(raws, varName) {
|
|
379
|
-
// console.log('isUsingV', raws)
|
|
380
|
-
// console.log('isUsingV', raws, varName, ScriptUtils.getVariablePaths(raws ?? ''))
|
|
381
547
|
if (varName && raws) {
|
|
382
548
|
if (varName.startsWith('this.')) {
|
|
383
549
|
varName = varName.replace(/this\./, '');
|
|
@@ -393,7 +559,6 @@ export class EventManager {
|
|
|
393
559
|
}
|
|
394
560
|
static setBindProperty(scripts, obj) {
|
|
395
561
|
if (scripts) {
|
|
396
|
-
// const newScripts = Object.assign({}, scripts)
|
|
397
562
|
const newScripts = Object.assign({}, scripts);
|
|
398
563
|
for (const [key, value] of Object.entries(newScripts)) {
|
|
399
564
|
if (typeof value === 'function') {
|
|
@@ -421,6 +586,14 @@ EventManager.ownerVariablePathAttrName = _a.attrPrefix + 'owner-variable-path';
|
|
|
421
586
|
EventManager.eventParam = _a.attrPrefix + 'event';
|
|
422
587
|
EventManager.onInitAttrName = _a.attrPrefix + 'on-init';
|
|
423
588
|
EventManager.valueAttrName = _a.attrPrefix + 'value';
|
|
589
|
+
EventManager.checkedAttrName = _a.attrPrefix + 'checked';
|
|
590
|
+
EventManager.selectedAttrName = _a.attrPrefix + 'selected';
|
|
591
|
+
EventManager.readonlyAttrName = _a.attrPrefix + 'readonly';
|
|
592
|
+
EventManager.disabledAttrName = _a.attrPrefix + 'disabled';
|
|
593
|
+
EventManager.hiddenAttrName = _a.attrPrefix + 'hidden';
|
|
594
|
+
EventManager.requiredAttrName = _a.attrPrefix + 'required';
|
|
595
|
+
EventManager.openAttrName = _a.attrPrefix + 'open';
|
|
596
|
+
// link는 쓰지 않는걸 추천한다 라이프 사이클 꼬인다 다른 프레임워크에서도 양방향은 지양 한다
|
|
424
597
|
EventManager.linkAttrs = [
|
|
425
598
|
{ name: _a.attrPrefix + 'value-link', property: 'value', event: 'input' },
|
|
426
599
|
{ name: _a.attrPrefix + 'hidden-link', property: 'value', event: 'input' },
|
|
@@ -428,6 +601,7 @@ EventManager.linkAttrs = [
|
|
|
428
601
|
{ name: _a.attrPrefix + 'checked-link', property: 'checked', event: 'change' },
|
|
429
602
|
{ name: _a.attrPrefix + 'open-link', property: 'open', event: 'toggle' },
|
|
430
603
|
];
|
|
604
|
+
// @ts-ignore 합성이벤트(Synthetic) 처리하면서 의미가 없어졌다
|
|
431
605
|
EventManager.linkTargetMapAttrName = _a.attrPrefix + 'link-variables';
|
|
432
606
|
EventManager.onRenderedInitAttrName = _a.attrPrefix + 'on-rendered-init';
|
|
433
607
|
EventManager.attrAttrName = _a.attrPrefix + 'attr';
|
|
@@ -457,12 +631,19 @@ EventManager.PARENT_THIS_PATH_VARNAME = '$parentPath';
|
|
|
457
631
|
EventManager.CURRENT_THIS_VARNAME = '$currentThis';
|
|
458
632
|
EventManager.CURRENT_THIS_PATH_VARNAME = '$currentThisPath';
|
|
459
633
|
EventManager.NEAR_THIS_PATH_VARNAME = '$nearThisPath';
|
|
460
|
-
EventManager.VARNAMES = [_a.SCRIPTS_VARNAME, _a.FAG_VARNAME, _a.RAWSET_VARNAME, _a.RANGE_VARNAME, _a.ROUTER_VARNAME, _a.ELEMENT_VARNAME, _a.TARGET_VARNAME, _a.EVENT_VARNAME, _a.COMPONENT_VARNAME, _a.INNERHTML_VARNAME, _a.ATTRIBUTE_VARNAME, _a.ATTRIBUTE_VARNAME, _a.CREATOR_META_DATA_VARNAME, _a.PARENT_THIS_PATH_VARNAME, _a.PARENT_THIS_VARNAME
|
|
634
|
+
EventManager.VARNAMES = [_a.SCRIPTS_VARNAME, _a.FAG_VARNAME, _a.RAWSET_VARNAME, _a.RANGE_VARNAME, _a.ROUTER_VARNAME, _a.ELEMENT_VARNAME, _a.TARGET_VARNAME, _a.EVENT_VARNAME, _a.COMPONENT_VARNAME, _a.INNERHTML_VARNAME, _a.ATTRIBUTE_VARNAME, _a.ATTRIBUTE_VARNAME, _a.CREATOR_META_DATA_VARNAME, _a.PARENT_THIS_PATH_VARNAME, _a.PARENT_THIS_VARNAME];
|
|
461
635
|
EventManager.WINDOW_EVENT_POPSTATE = 'popstate';
|
|
462
636
|
EventManager.WINDOW_EVENT_RESIZE = 'resize';
|
|
463
637
|
EventManager.WINDOW_EVENTS = [_a.WINDOW_EVENT_POPSTATE, _a.WINDOW_EVENT_RESIZE];
|
|
464
638
|
EventManager.attrNames = [
|
|
465
639
|
_a.valueAttrName,
|
|
640
|
+
_a.checkedAttrName,
|
|
641
|
+
_a.selectedAttrName,
|
|
642
|
+
_a.readonlyAttrName,
|
|
643
|
+
_a.disabledAttrName,
|
|
644
|
+
_a.hiddenAttrName,
|
|
645
|
+
_a.requiredAttrName,
|
|
646
|
+
_a.openAttrName,
|
|
466
647
|
_a.attrAttrName,
|
|
467
648
|
_a.normalAttrMapAttrName,
|
|
468
649
|
_a.styleAttrName,
|
|
@@ -473,5 +654,4 @@ EventManager.attrNames = [
|
|
|
473
654
|
..._a.linkAttrs.map(it => it.name),
|
|
474
655
|
_a.eventParam
|
|
475
656
|
];
|
|
476
|
-
export const eventManager = new EventManager();
|
|
477
657
|
//# sourceMappingURL=EventManager.js.map
|