@dooboostore/simple-web-component 1.0.38 → 1.0.40
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/LICENSE.md +7 -0
- package/README.md +88 -871
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +194 -111
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +82 -80
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +213 -0
- package/dist/cjs/decorators/applyProperty.js.map +7 -0
- package/dist/cjs/decorators/applySlot.js +93 -82
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +14 -34
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -2
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +4 -4
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/state.js +0 -1
- package/dist/cjs/decorators/state.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +196 -113
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +82 -80
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +194 -0
- package/dist/esm/decorators/applyProperty.js.map +7 -0
- package/dist/esm/decorators/applySlot.js +93 -82
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +14 -34
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -2
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +4 -4
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/state.js +0 -1
- package/dist/esm/decorators/state.js.map +2 -2
- package/dist/esm/elements/SwcApp.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +525 -513
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +56 -15
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +28 -24
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -0
- package/dist/types/decorators/applyProperty.d.ts.map +1 -0
- package/dist/types/decorators/applySlot.d.ts +17 -15
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -2
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +4 -4
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -6
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +525 -513
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/applyAttribute.ts +311 -126
- package/src/decorators/applyNode.ts +108 -105
- package/src/decorators/applyProperty.ts +302 -0
- package/src/decorators/applySlot.ts +112 -94
- package/src/decorators/changedAttributeThis.ts +1 -1
- package/src/decorators/elementDefine.ts +44 -33
- package/src/decorators/index.ts +2 -3
- package/src/decorators/lifecycles.ts +6 -6
- package/src/decorators/state.ts +0 -1
- package/src/elements/SwcApp.ts +0 -1
- package/src/types/index.ts +7 -7
- package/dist/cjs/decorators/attribute.js +0 -187
- package/dist/cjs/decorators/attribute.js.map +0 -7
- package/dist/cjs/decorators/setProperty.js +0 -109
- package/dist/cjs/decorators/setProperty.js.map +0 -7
- package/dist/esm/decorators/attribute.js +0 -168
- package/dist/esm/decorators/attribute.js.map +0 -7
- package/dist/esm/decorators/setProperty.js +0 -90
- package/dist/esm/decorators/setProperty.js.map +0 -7
- package/dist/types/decorators/attribute.d.ts +0 -31
- package/dist/types/decorators/attribute.d.ts.map +0 -1
- package/dist/types/decorators/setProperty.d.ts +0 -17
- package/dist/types/decorators/setProperty.d.ts.map +0 -1
- package/src/decorators/attribute.ts +0 -223
- package/src/decorators/setProperty.ts +0 -112
|
@@ -37,69 +37,60 @@ export interface ApplyNodeMetadata {
|
|
|
37
37
|
|
|
38
38
|
export const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');
|
|
39
39
|
|
|
40
|
-
const normalizeNodes = (res: any, doc: Document): Node[] => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const applyToDom = (currentThis: any, targetEl: HTMLElement, res:
|
|
40
|
+
// const normalizeNodes = (res: any, doc: Document): Node[] => {
|
|
41
|
+
// const items = Array.isArray(res) ? res : [res];
|
|
42
|
+
// return items.map(it => {
|
|
43
|
+
// if (it instanceof Node) return it;
|
|
44
|
+
// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
|
|
45
|
+
// });
|
|
46
|
+
// };
|
|
47
|
+
|
|
48
|
+
const applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string, pos: ApplyNodePosition, win: Window, host?: any) => {
|
|
49
49
|
if (!targetEl) return;
|
|
50
|
-
|
|
51
|
-
// console.log('------------',currentThis.tagName, res)
|
|
52
50
|
const doc = win.document;
|
|
53
51
|
const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);
|
|
54
52
|
const id = currentThis._swcId;
|
|
55
|
-
// Allow processHtml to run here so all DOM insertions go through a single
|
|
56
|
-
// processing point. processHtml may mutate Node[] in-place or return a
|
|
57
|
-
// transformed string result for text processing.
|
|
58
|
-
try {
|
|
59
|
-
if (typeof res === 'string') {
|
|
60
|
-
const processed = SwcUtils.projectProcessHtml(id, res as string, doc);
|
|
61
|
-
if (processed !== undefined) res = processed;
|
|
62
|
-
} else if (res) {
|
|
63
|
-
SwcUtils.projectProcessHtml(id, res, doc);
|
|
64
|
-
}
|
|
65
|
-
} catch (e) {
|
|
66
|
-
// swallow and proceed with original res
|
|
67
|
-
}
|
|
68
53
|
|
|
69
|
-
if (pos === 'innerHtml') {
|
|
70
|
-
targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
54
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
const nodes: Node[] = [];
|
|
56
|
+
|
|
57
|
+
if (typeof res === 'string' && pos === 'innerHtml') {
|
|
58
|
+
const t = win.document.createElement('template');
|
|
59
|
+
t.innerHTML = res;
|
|
60
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
61
|
+
} else if (typeof res === 'string' && pos === 'innerText') {
|
|
62
|
+
nodes.push(win.document.createTextNode(res));
|
|
79
63
|
}
|
|
80
64
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
stateContext[it.name] = currentThis[it.propertyKey]
|
|
84
|
-
})
|
|
85
|
-
new ElementApply(currentThis, {id: currentThis._swcId}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
|
|
65
|
+
SwcUtils.projectProcessHtml(id, nodes, doc);
|
|
66
|
+
|
|
86
67
|
|
|
87
68
|
|
|
88
69
|
const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
89
|
-
const nodes = normalizeNodes(res, doc);
|
|
70
|
+
// const nodes = normalizeNodes(res, doc);
|
|
90
71
|
if (pos === 'replace') {
|
|
91
72
|
if (!isShadowRoot) targetEl.replaceWith(...nodes);
|
|
73
|
+
} else if (pos === 'innerHtml') {
|
|
74
|
+
targetEl.replaceChildren(...nodes);
|
|
75
|
+
} else if (pos === 'innerText') {
|
|
76
|
+
targetEl.replaceChildren(...nodes);
|
|
92
77
|
} else if (pos === 'replaceChildren') {
|
|
93
78
|
targetEl.replaceChildren(...nodes);
|
|
94
79
|
} else {
|
|
95
80
|
if (pos === 'beforeEnd') {
|
|
96
|
-
console.log('tarbbbbbbbbbbbbbb')
|
|
97
81
|
targetEl.append(...nodes)
|
|
98
82
|
}
|
|
99
83
|
else if (pos === 'afterBegin') targetEl.prepend(...nodes);
|
|
100
84
|
else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
|
|
101
85
|
else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
|
|
102
86
|
}
|
|
87
|
+
|
|
88
|
+
const stateContext: any = {...hostSet};
|
|
89
|
+
findAllStateMetadata(currentThis).forEach(it => {
|
|
90
|
+
stateContext[it.name] = currentThis[it.propertyKey]
|
|
91
|
+
})
|
|
92
|
+
new ElementApply(targetEl, {id: id}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
|
|
93
|
+
return nodes;
|
|
103
94
|
};
|
|
104
95
|
|
|
105
96
|
/**
|
|
@@ -146,8 +137,6 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
|
|
|
146
137
|
return targetRoot ? targetRoot.querySelector(selector) : null;
|
|
147
138
|
};
|
|
148
139
|
|
|
149
|
-
|
|
150
|
-
console.log('fffffffffff')
|
|
151
140
|
const targetEl = getTarget();
|
|
152
141
|
const res = original.apply(this, args);
|
|
153
142
|
|
|
@@ -164,16 +153,17 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
|
|
|
164
153
|
}
|
|
165
154
|
};
|
|
166
155
|
|
|
167
|
-
if (res instanceof Promise) {
|
|
168
|
-
// 비동기일 때만 로딩 표시
|
|
169
|
-
if (targetEl && options.fallback) {
|
|
170
|
-
const loadingRes = options.fallback.call(this, hostSet);
|
|
171
|
-
// applyToDom expects a Window as the 4th argument
|
|
172
|
-
applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin);
|
|
173
|
-
}
|
|
174
156
|
|
|
157
|
+
const fallbackNodes: Node[] = [];
|
|
158
|
+
if (targetEl && options.fallback) {
|
|
159
|
+
const loadingRes = options.fallback.call(this, hostSet);
|
|
160
|
+
// applyToDom expects a Window as the 4th argument
|
|
161
|
+
fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (res instanceof Promise) {
|
|
175
165
|
return res.then(finalRes => {
|
|
176
|
-
|
|
166
|
+
fallbackNodes.forEach((it: any)=>it.remove());
|
|
177
167
|
if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
|
|
178
168
|
return finalRes;
|
|
179
169
|
});
|
|
@@ -185,17 +175,6 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
|
|
|
185
175
|
};
|
|
186
176
|
}
|
|
187
177
|
|
|
188
|
-
export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {
|
|
189
|
-
const result = new Map<string | symbol, ApplyNodeMetadata>();
|
|
190
|
-
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);
|
|
191
|
-
maps.forEach(map => {
|
|
192
|
-
if (map instanceof Map) {
|
|
193
|
-
map.forEach((v, k) => result.set(k, v));
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
return result;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
178
|
export function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;
|
|
200
179
|
export function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
201
180
|
export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
@@ -205,111 +184,135 @@ export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symb
|
|
|
205
184
|
return applyNode('$this', {...option, ...opt});
|
|
206
185
|
}
|
|
207
186
|
|
|
208
|
-
export function
|
|
209
|
-
export function
|
|
210
|
-
export function
|
|
187
|
+
export function replaceChildrenNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
|
|
188
|
+
export function replaceChildrenNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
189
|
+
export function replaceChildrenNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
211
190
|
const option: ApplyNodeOptions = {position: 'replaceChildren'};
|
|
212
191
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
213
192
|
const opt = targetOrOptions || {};
|
|
214
193
|
return applyNode('$this', {...opt, ...option});
|
|
215
194
|
}
|
|
216
195
|
|
|
217
|
-
export function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
218
|
-
export function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
219
|
-
export function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
220
|
-
const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
|
|
221
|
-
if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
|
|
222
|
-
const opt = targetOrOptions || {};
|
|
223
|
-
return applyNode('$this', {...opt, ...options});
|
|
224
|
-
}
|
|
225
196
|
|
|
226
|
-
|
|
227
|
-
export function
|
|
228
|
-
export function
|
|
197
|
+
|
|
198
|
+
export function beforeEndNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
|
|
199
|
+
export function beforeEndNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
200
|
+
export function beforeEndNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
229
201
|
const options: ApplyNodeOptions = {position: 'beforeEnd'};
|
|
230
202
|
if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
|
|
231
203
|
const opt = targetOrOptions || {};
|
|
232
204
|
return applyNode('$this', {...opt, ...options});
|
|
233
205
|
}
|
|
234
206
|
|
|
235
|
-
export function
|
|
236
|
-
export function
|
|
237
|
-
export function
|
|
207
|
+
export function beforeEndLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
208
|
+
export function beforeEndLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
209
|
+
export function beforeEndLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
238
210
|
const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}
|
|
239
211
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
240
212
|
const opt = targetOrOptions || {};
|
|
241
213
|
return applyNode('$this', {...opt, ...option});
|
|
242
214
|
}
|
|
243
|
-
|
|
244
|
-
export function
|
|
245
|
-
export function
|
|
215
|
+
|
|
216
|
+
export function beforeEndShadowNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
217
|
+
export function beforeEndShadowNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
218
|
+
export function beforeEndShadowNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
246
219
|
const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}
|
|
247
220
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
248
221
|
const opt = targetOrOptions || {};
|
|
249
222
|
return applyNode('$this', {...opt, ...option});
|
|
250
223
|
}
|
|
251
224
|
|
|
252
|
-
export function
|
|
253
|
-
export function
|
|
254
|
-
export function
|
|
225
|
+
export function afterBeginNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
|
|
226
|
+
export function afterBeginNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
227
|
+
export function afterBeginNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
255
228
|
const option: ApplyNodeOptions = {position: 'afterBegin'};
|
|
256
229
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
257
230
|
const opt = targetOrOptions || {};
|
|
258
231
|
return applyNode('$this', {...opt, ...option});
|
|
259
232
|
}
|
|
260
233
|
|
|
261
|
-
export function
|
|
262
|
-
export function
|
|
263
|
-
export function
|
|
234
|
+
export function afterBeginLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
235
|
+
export function afterBeginLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
236
|
+
export function afterBeginLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
264
237
|
const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}
|
|
265
238
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
266
239
|
const opt = targetOrOptions || {};
|
|
267
240
|
return applyNode('$this', {...opt, ...option});
|
|
268
241
|
}
|
|
269
242
|
|
|
270
|
-
export function
|
|
271
|
-
export function
|
|
272
|
-
export function
|
|
243
|
+
export function innerHtmlNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
|
|
244
|
+
export function innerHtmlNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
245
|
+
export function innerHtmlNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
273
246
|
const option: ApplyNodeOptions = {position: 'innerHtml'}
|
|
274
247
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
275
248
|
const opt = targetOrOptions || {};
|
|
276
249
|
return applyNode('$this', {...opt, ...option});
|
|
277
250
|
}
|
|
278
251
|
|
|
279
|
-
export function
|
|
280
|
-
export function
|
|
281
|
-
export function
|
|
252
|
+
export function innerTextNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
|
|
253
|
+
export function innerTextNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
254
|
+
export function innerTextNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
255
|
+
const option: ApplyNodeOptions = {position: 'innerText'}
|
|
256
|
+
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
257
|
+
const opt = targetOrOptions || {};
|
|
258
|
+
return applyNode('$this', {...opt, ...option});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function innerHtmlLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
262
|
+
export function innerHtmlLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
263
|
+
export function innerHtmlLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
282
264
|
const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};
|
|
283
265
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
284
266
|
const opt = targetOrOptions || {};
|
|
285
267
|
return applyNode('$this', {...opt, ...option});
|
|
286
268
|
}
|
|
287
269
|
|
|
288
|
-
export function
|
|
289
|
-
export function
|
|
290
|
-
export function
|
|
270
|
+
export function replaceChildrenLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
|
|
271
|
+
export function replaceChildrenLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
272
|
+
export function replaceChildrenLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
291
273
|
const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
|
|
292
274
|
if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
|
|
293
275
|
const opt = targetOrOptions || {};
|
|
294
276
|
return applyNode('$this', {...opt, ...option});
|
|
295
277
|
}
|
|
296
278
|
|
|
297
|
-
export function
|
|
279
|
+
export function replaceChildrenNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
|
|
298
280
|
return applyNode(selector, {...options, position: 'replaceChildren'});
|
|
299
281
|
}
|
|
300
282
|
|
|
301
|
-
export function
|
|
283
|
+
export function innerHtmlNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
|
|
302
284
|
return applyNode(selector, {...options, position: 'innerHtml'});
|
|
303
285
|
}
|
|
304
286
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
287
|
+
export function innerHtmlLightNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
|
|
288
|
+
return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});
|
|
289
|
+
}
|
|
308
290
|
|
|
309
|
-
export function
|
|
291
|
+
export function innerHtmlShadowNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
|
|
292
|
+
return applyNode(selector, {...options, position: 'innerHtml', root: 'shadow'});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function innerTextNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
|
|
310
296
|
return applyNode(selector, {...options, position: 'innerText'});
|
|
311
297
|
}
|
|
312
298
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
299
|
+
export function innerTextLightNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
|
|
300
|
+
return applyNode(selector, {...options, position: 'innerText', root: 'light'});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function innerTextShadowNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
|
|
304
|
+
return applyNode(selector, {...options, position: 'innerText', root: 'shadow'});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {
|
|
310
|
+
const result = new Map<string | symbol, ApplyNodeMetadata>();
|
|
311
|
+
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);
|
|
312
|
+
maps.forEach(map => {
|
|
313
|
+
if (map instanceof Map) {
|
|
314
|
+
map.forEach((v, k) => result.set(k, v));
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return result;
|
|
318
|
+
};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
+
import { ensureInit, getElementConfig } from './elementDefine';
|
|
3
|
+
import { SwcUtils } from '../utils/Utils';
|
|
4
|
+
import { SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
|
+
|
|
6
|
+
export interface PropertyOptions extends SwcQueryOptions {
|
|
7
|
+
name?: string | symbol;
|
|
8
|
+
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PropertyMetadata {
|
|
12
|
+
propertyKey: string | symbol;
|
|
13
|
+
selector: string;
|
|
14
|
+
targetPropertyKey: string | symbol;
|
|
15
|
+
options: PropertyOptions;
|
|
16
|
+
type: 'property' | 'method';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const PROPERTY_METADATA_KEY = Symbol.for('simple-web-component:property');
|
|
20
|
+
|
|
21
|
+
// ============================================
|
|
22
|
+
// Utilities
|
|
23
|
+
// ============================================
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Resolve target elements based on selector and options
|
|
27
|
+
* Handles special selectors ($this, $host, etc.) and CSS selectors
|
|
28
|
+
* Returns HTMLElement[] but can include Window and Document for property access
|
|
29
|
+
*/
|
|
30
|
+
export const resolvePropertyTargets = (inst: any, selector: string, options: PropertyOptions): any[] => {
|
|
31
|
+
const conf = getElementConfig(inst);
|
|
32
|
+
const currentWin = conf.window;
|
|
33
|
+
const r = options.root || 'auto';
|
|
34
|
+
const results: any[] = [];
|
|
35
|
+
|
|
36
|
+
const applyRoot = (target: any) => {
|
|
37
|
+
if (!target) return;
|
|
38
|
+
if (r === 'auto') {
|
|
39
|
+
results.push(target);
|
|
40
|
+
} else {
|
|
41
|
+
if (r === 'light' || r === 'all') results.push(target);
|
|
42
|
+
if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (selector === '$this' || !selector) {
|
|
47
|
+
applyRoot(inst);
|
|
48
|
+
} else if (selector === '$window') {
|
|
49
|
+
results.push(currentWin);
|
|
50
|
+
} else if (selector === '$document') {
|
|
51
|
+
results.push(currentWin.document);
|
|
52
|
+
} else {
|
|
53
|
+
const hostSet = SwcUtils.getHostSet(inst);
|
|
54
|
+
if (selector === '$host') applyRoot(hostSet.$host);
|
|
55
|
+
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
56
|
+
else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);
|
|
57
|
+
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
58
|
+
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
59
|
+
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
|
|
60
|
+
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
|
|
61
|
+
else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
|
|
62
|
+
else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
63
|
+
else {
|
|
64
|
+
if (r === 'shadow') {
|
|
65
|
+
const found = inst.shadowRoot?.querySelectorAll(selector);
|
|
66
|
+
if (found) results.push(...found);
|
|
67
|
+
} else if (r === 'light') {
|
|
68
|
+
const found = inst.querySelectorAll(selector);
|
|
69
|
+
if (found) results.push(...found);
|
|
70
|
+
} else if (r === 'all') {
|
|
71
|
+
const sMatch = inst.shadowRoot?.querySelectorAll(selector);
|
|
72
|
+
const lMatch = inst.querySelectorAll(selector);
|
|
73
|
+
if (sMatch) results.push(...sMatch);
|
|
74
|
+
if (lMatch) results.push(...lMatch);
|
|
75
|
+
} else {
|
|
76
|
+
const found = (inst.shadowRoot || inst).querySelectorAll(selector);
|
|
77
|
+
if (found) results.push(...found);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @applyProperty decorator - set/get element properties
|
|
86
|
+
*
|
|
87
|
+
* Usage:
|
|
88
|
+
* - @applyProperty('selector', 'propertyName') - Set property with explicit name
|
|
89
|
+
* - @applyProperty('selector') - Use property name as target property name
|
|
90
|
+
* - @applyProperty('selector', { name: 'propertyName' }) - Set property via options
|
|
91
|
+
* - Return null/undefined to skip setting
|
|
92
|
+
*/
|
|
93
|
+
export function applyProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
94
|
+
export function applyProperty(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
95
|
+
export function applyProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
|
|
96
|
+
return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
|
|
97
|
+
// ensureInit(target as any);
|
|
98
|
+
|
|
99
|
+
const constructor = target.constructor;
|
|
100
|
+
const metaType: 'property' | 'method' = descriptor && typeof descriptor.value === 'function' ? 'method' : 'property';
|
|
101
|
+
|
|
102
|
+
// Parse arguments
|
|
103
|
+
let finalOptions: PropertyOptions = {};
|
|
104
|
+
let targetPropertyKey: string | symbol;
|
|
105
|
+
|
|
106
|
+
if (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol') {
|
|
107
|
+
// applyProperty('selector', 'propertyName', options?)
|
|
108
|
+
targetPropertyKey = targetPropertyKeyOrOptions;
|
|
109
|
+
finalOptions = options || {};
|
|
110
|
+
} else if (targetPropertyKeyOrOptions) {
|
|
111
|
+
// applyProperty('selector', options)
|
|
112
|
+
finalOptions = targetPropertyKeyOrOptions;
|
|
113
|
+
targetPropertyKey = finalOptions.name || propertyKey;
|
|
114
|
+
} else {
|
|
115
|
+
// applyProperty('selector')
|
|
116
|
+
targetPropertyKey = propertyKey;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Store metadata
|
|
120
|
+
let metaList = ReflectUtils.getOwnMetadata(PROPERTY_METADATA_KEY, constructor) as PropertyMetadata[];
|
|
121
|
+
if (!metaList) {
|
|
122
|
+
metaList = [];
|
|
123
|
+
ReflectUtils.defineMetadata(PROPERTY_METADATA_KEY, metaList, constructor);
|
|
124
|
+
}
|
|
125
|
+
metaList.push({
|
|
126
|
+
propertyKey,
|
|
127
|
+
selector,
|
|
128
|
+
targetPropertyKey,
|
|
129
|
+
options: finalOptions,
|
|
130
|
+
type: metaType
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Helper: apply resolved value to targets
|
|
134
|
+
const applyValueToTargets = (inst: any, resolvedValue: any) => {
|
|
135
|
+
if (resolvedValue === undefined) return resolvedValue;
|
|
136
|
+
|
|
137
|
+
const targetEls = resolvePropertyTargets(inst, selector, finalOptions);
|
|
138
|
+
const conf = getElementConfig(inst);
|
|
139
|
+
const currentWin = conf.window;
|
|
140
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
|
|
141
|
+
|
|
142
|
+
targetEls.forEach(targetEl => {
|
|
143
|
+
// Apply filter if provided
|
|
144
|
+
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: inst, helper: hostSet })) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
|
|
149
|
+
(targetEl as any)[targetPropertyKey] = resolvedRes;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return resolvedValue;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Method decorator: wrap method to apply its return value to properties
|
|
156
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
157
|
+
const original = descriptor.value;
|
|
158
|
+
descriptor.value = function (...args: any[]) {
|
|
159
|
+
ensureInit(this);
|
|
160
|
+
const res = (original as any).apply(this, args);
|
|
161
|
+
|
|
162
|
+
if (res instanceof Promise) {
|
|
163
|
+
return res.then((v: any) => { applyValueToTargets(this, v); return v; });
|
|
164
|
+
} else {
|
|
165
|
+
applyValueToTargets(this, res);
|
|
166
|
+
return res;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Property decorator: define getter/setter to proxy to element properties
|
|
173
|
+
Object.defineProperty(target, propertyKey, {
|
|
174
|
+
configurable: true,
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get(this: any) {
|
|
177
|
+
ensureInit(this);
|
|
178
|
+
// Read from matched elements
|
|
179
|
+
const targetEls = resolvePropertyTargets(this, selector, finalOptions);
|
|
180
|
+
const conf = getElementConfig(this);
|
|
181
|
+
const currentWin = conf.window;
|
|
182
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
183
|
+
|
|
184
|
+
// Apply filter
|
|
185
|
+
const filtered = targetEls.filter(el => {
|
|
186
|
+
if (finalOptions.filter && !finalOptions.filter(el, (el as any)[targetPropertyKey], { currentThis: this, helper: hostSet })) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const values = filtered.map(el => (el as any)[targetPropertyKey]);
|
|
193
|
+
return values.length === 1 ? values[0] : values;
|
|
194
|
+
},
|
|
195
|
+
set(this: any, value: any) {
|
|
196
|
+
ensureInit(this);
|
|
197
|
+
applyValueToTargets(this, value);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ============================================
|
|
204
|
+
// Convenience Aliases
|
|
205
|
+
// ============================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @property - Alias for @applyProperty
|
|
209
|
+
*/
|
|
210
|
+
export function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
211
|
+
export function property(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
212
|
+
export function property(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
|
|
213
|
+
return applyProperty(selector, targetPropertyKeyOrOptions as any, options);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @propertyThis - Apply property on $this element
|
|
218
|
+
* Can be used as: @propertyThis or @propertyThis('propertyName') or @propertyThis({ name: 'propertyName' })
|
|
219
|
+
*/
|
|
220
|
+
export function propertyThis(target: Object, propertyKey: string | symbol): void;
|
|
221
|
+
export function propertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
222
|
+
export function propertyThis(options?: PropertyOptions): MethodDecorator & PropertyDecorator;
|
|
223
|
+
export function propertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
|
|
224
|
+
// Direct decorator usage: @propertyThis
|
|
225
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
|
|
226
|
+
(typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
|
|
227
|
+
// Called as @propertyThis (target, propertyKey)
|
|
228
|
+
return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Called with parameters
|
|
232
|
+
if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {
|
|
233
|
+
// @propertyThis('propertyName', options?)
|
|
234
|
+
return applyProperty('$this', targetOrOptions, propertyKeyOrOptions);
|
|
235
|
+
} else if (targetOrOptions && typeof targetOrOptions === 'object') {
|
|
236
|
+
// @propertyThis({ name: 'propertyName' })
|
|
237
|
+
return applyProperty('$this', undefined as any, targetOrOptions);
|
|
238
|
+
} else {
|
|
239
|
+
// @propertyThis() or @propertyThis
|
|
240
|
+
return applyProperty('$this', undefined as any, {});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @setProperty - Alias for @applyProperty (method-decorator semantics)
|
|
246
|
+
*/
|
|
247
|
+
export function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
|
|
248
|
+
export function setProperty(selector: string, options?: PropertyOptions): MethodDecorator;
|
|
249
|
+
export function setProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator {
|
|
250
|
+
return applyProperty(selector, targetPropertyKeyOrOptions as any, options) as MethodDecorator;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @setPropertyThis - Set property on $this element
|
|
255
|
+
* Can be used as: @setPropertyThis or @setPropertyThis('propertyName') or @setPropertyThis({ name: 'propertyName' })
|
|
256
|
+
*/
|
|
257
|
+
export function setPropertyThis(target: Object, propertyKey: string | symbol): void;
|
|
258
|
+
export function setPropertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
|
|
259
|
+
export function setPropertyThis(options?: PropertyOptions): MethodDecorator;
|
|
260
|
+
export function setPropertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
|
|
261
|
+
// Direct decorator usage: @setPropertyThis
|
|
262
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
|
|
263
|
+
(typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
|
|
264
|
+
// Called as @setPropertyThis (target, propertyKey)
|
|
265
|
+
return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Called with parameters
|
|
269
|
+
if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {
|
|
270
|
+
// @setPropertyThis('propertyName', options?)
|
|
271
|
+
return applyProperty('$this', targetOrOptions, propertyKeyOrOptions) as MethodDecorator;
|
|
272
|
+
} else if (targetOrOptions && typeof targetOrOptions === 'object') {
|
|
273
|
+
// @setPropertyThis({ name: 'propertyName' })
|
|
274
|
+
return applyProperty('$this', undefined as any, targetOrOptions) as MethodDecorator;
|
|
275
|
+
} else {
|
|
276
|
+
// @setPropertyThis() or @setPropertyThis
|
|
277
|
+
return applyProperty('$this', undefined as any, {}) as MethodDecorator;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
// ============================================
|
|
284
|
+
// Metadata Helpers
|
|
285
|
+
// ============================================
|
|
286
|
+
|
|
287
|
+
export const findAllPropertyMetadata = (target: any): PropertyMetadata[] => {
|
|
288
|
+
const actualTarget = target instanceof Function ? target : target.constructor;
|
|
289
|
+
return ReflectUtils.findAllMetadata<PropertyMetadata[]>(PROPERTY_METADATA_KEY, actualTarget).flat();
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// Backward compatibility alias
|
|
293
|
+
export const findAllPropertyApplyMetadata = (target: any): Map<string | symbol, PropertyMetadata> => {
|
|
294
|
+
const result = new Map<string | symbol, PropertyMetadata>();
|
|
295
|
+
findAllPropertyMetadata(target).forEach(meta => {
|
|
296
|
+
result.set(meta.propertyKey, meta);
|
|
297
|
+
});
|
|
298
|
+
return result;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
export default applyProperty;
|