@dooboostore/simple-web-component 1.0.39 → 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 +65 -46
- 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 +58 -43
- 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 +32 -26
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +17 -30
- 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/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 +58 -43
- 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 +32 -26
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +17 -30
- 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/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 +421 -394
- 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 +10 -10
- 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/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 +421 -394
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/applyAttribute.ts +311 -126
- package/src/decorators/applyNode.ts +68 -57
- package/src/decorators/applyProperty.ts +302 -0
- package/src/decorators/applySlot.ts +25 -18
- package/src/decorators/changedAttributeThis.ts +1 -1
- package/src/decorators/elementDefine.ts +41 -30
- package/src/decorators/index.ts +2 -3
- package/src/decorators/lifecycles.ts +6 -6
- 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
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils, FunctionUtils, ActionExpression } from "@dooboostore/core";
|
|
2
|
-
import { getElementConfig } from "./elementDefine.js";
|
|
3
|
-
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
-
import { ConvertUtils } from "@dooboostore/core-web";
|
|
5
|
-
const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for("simple-web-component:attribute-field");
|
|
6
|
-
const convertValue = (val, type) => {
|
|
7
|
-
if (val === null || val === void 0) return val;
|
|
8
|
-
if (type === Number) return Number(val);
|
|
9
|
-
if (type === Boolean) return val === "false" || val === "0" ? false : true;
|
|
10
|
-
return val;
|
|
11
|
-
};
|
|
12
|
-
const getAttributeValue = (inst, attrName, options) => {
|
|
13
|
-
const conf = getElementConfig(inst);
|
|
14
|
-
const currentWin = inst._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
15
|
-
const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];
|
|
16
|
-
const primaryTarget = targets[0];
|
|
17
|
-
if (primaryTarget && typeof primaryTarget.hasAttribute === "function" && primaryTarget.hasAttribute(attrName)) {
|
|
18
|
-
let domVal = primaryTarget.getAttribute(attrName);
|
|
19
|
-
const ae = new ActionExpression(domVal);
|
|
20
|
-
const expr = ae.getFirstExpression("callReturn");
|
|
21
|
-
if (expr) {
|
|
22
|
-
try {
|
|
23
|
-
const result = FunctionUtils.executeReturn({
|
|
24
|
-
script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),
|
|
25
|
-
context: inst,
|
|
26
|
-
args: SwcUtils.getHelperAndHostSet(currentWin, inst)
|
|
27
|
-
});
|
|
28
|
-
return convertValue(result, options?.type);
|
|
29
|
-
} catch (e) {
|
|
30
|
-
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);
|
|
31
|
-
return convertValue(domVal, options?.type);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return convertValue(domVal, options?.type);
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
};
|
|
38
|
-
const resolveTargetEls = (inst, selector, options, currentWin) => {
|
|
39
|
-
const r = options.root || "auto";
|
|
40
|
-
const results = [];
|
|
41
|
-
const applyRoot = (target) => {
|
|
42
|
-
if (!target) return;
|
|
43
|
-
if (r === "auto") {
|
|
44
|
-
results.push(target);
|
|
45
|
-
} else {
|
|
46
|
-
if (r === "light" || r === "all") results.push(target);
|
|
47
|
-
if ((r === "shadow" || r === "all") && target.shadowRoot) results.push(target.shadowRoot);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
if (selector === "$this" || !selector) {
|
|
51
|
-
applyRoot(inst);
|
|
52
|
-
} else if (selector === "$window") {
|
|
53
|
-
results.push(currentWin);
|
|
54
|
-
} else if (selector === "$document") {
|
|
55
|
-
results.push(currentWin.document);
|
|
56
|
-
} else {
|
|
57
|
-
const hostSet = SwcUtils.getHostSet(inst);
|
|
58
|
-
if (selector === "$host") applyRoot(hostSet.$host);
|
|
59
|
-
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
60
|
-
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
61
|
-
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
62
|
-
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
63
|
-
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
64
|
-
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
65
|
-
else {
|
|
66
|
-
if (r === "shadow") {
|
|
67
|
-
const found = inst.shadowRoot?.querySelectorAll(selector);
|
|
68
|
-
if (found) results.push(...found);
|
|
69
|
-
} else if (r === "light") {
|
|
70
|
-
const found = inst.querySelectorAll(selector);
|
|
71
|
-
if (found) results.push(...found);
|
|
72
|
-
} else if (r === "all") {
|
|
73
|
-
const sMatch = inst.shadowRoot?.querySelectorAll(selector);
|
|
74
|
-
const lMatch = inst.querySelectorAll(selector);
|
|
75
|
-
if (sMatch) results.push(...sMatch);
|
|
76
|
-
if (lMatch) results.push(...lMatch);
|
|
77
|
-
} else {
|
|
78
|
-
const found = (inst.shadowRoot || inst).querySelectorAll(selector);
|
|
79
|
-
if (found) results.push(...found);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return results;
|
|
84
|
-
};
|
|
85
|
-
function attribute(selector, options = {}) {
|
|
86
|
-
return (target, propertyKey) => {
|
|
87
|
-
const constructor = target.constructor;
|
|
88
|
-
const privateKey = Symbol(String(propertyKey));
|
|
89
|
-
const designType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
90
|
-
let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor);
|
|
91
|
-
if (!metaList) {
|
|
92
|
-
metaList = [];
|
|
93
|
-
ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);
|
|
94
|
-
}
|
|
95
|
-
metaList.push({ propertyKey, selector, options, privateKey });
|
|
96
|
-
const applySetAttribute = (inst, targets, attrName, nv) => {
|
|
97
|
-
targets.forEach((it) => {
|
|
98
|
-
if (it && typeof it.setAttribute === "function") {
|
|
99
|
-
if (nv === null) {
|
|
100
|
-
it.removeAttribute(attrName);
|
|
101
|
-
} else {
|
|
102
|
-
it.setAttribute(attrName, String(nv));
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
inst[privateKey] = nv;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
Object.defineProperty(target, propertyKey, {
|
|
111
|
-
get() {
|
|
112
|
-
const attrName = options.name || String(propertyKey);
|
|
113
|
-
const mergedOptions = {
|
|
114
|
-
...options,
|
|
115
|
-
selector,
|
|
116
|
-
type: options.type || designType
|
|
117
|
-
};
|
|
118
|
-
const result = getAttributeValue(this, attrName, mergedOptions);
|
|
119
|
-
return result !== null ? result : this[privateKey];
|
|
120
|
-
},
|
|
121
|
-
set(nv) {
|
|
122
|
-
const attrName = options.name || String(propertyKey);
|
|
123
|
-
const conf = getElementConfig(this);
|
|
124
|
-
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
125
|
-
const targets = resolveTargetEls(this, selector, options, currentWin);
|
|
126
|
-
applySetAttribute(this, targets, attrName, nv);
|
|
127
|
-
},
|
|
128
|
-
enumerable: true,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
} catch (err) {
|
|
132
|
-
console.error("[SWC] defineProperty error:", err);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function attributeThis(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
137
|
-
if (propertyKeyOrOptions !== void 0 && (typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol")) {
|
|
138
|
-
return attribute("$this", { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
139
|
-
}
|
|
140
|
-
if (typeof targetOrAttrOrOptions === "string") {
|
|
141
|
-
const attrName = targetOrAttrOrOptions;
|
|
142
|
-
const options = typeof propertyKeyOrOptions === "object" ? propertyKeyOrOptions : {};
|
|
143
|
-
return attribute("$this", { ...options, name: attrName });
|
|
144
|
-
} else if (typeof targetOrAttrOrOptions === "object") {
|
|
145
|
-
const options = targetOrAttrOrOptions;
|
|
146
|
-
return (target, propertyKey) => {
|
|
147
|
-
return attribute("$this", { ...options, name: String(propertyKey) })(target, propertyKey);
|
|
148
|
-
};
|
|
149
|
-
} else {
|
|
150
|
-
return (target, propertyKey) => {
|
|
151
|
-
return attribute("$this", { name: String(propertyKey) })(target, propertyKey);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const findAllAttributeMetadata = (target) => {
|
|
156
|
-
const actualTarget = target instanceof Function ? target : target.constructor;
|
|
157
|
-
return ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();
|
|
158
|
-
};
|
|
159
|
-
export {
|
|
160
|
-
ATTRIBUTE_FIELD_METADATA_KEY,
|
|
161
|
-
attribute,
|
|
162
|
-
attributeThis,
|
|
163
|
-
convertValue,
|
|
164
|
-
findAllAttributeMetadata,
|
|
165
|
-
getAttributeValue,
|
|
166
|
-
resolveTargetEls
|
|
167
|
-
};
|
|
168
|
-
//# sourceMappingURL=attribute.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/attribute.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils, FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\nimport { ConvertUtils } from '@dooboostore/core-web';\nexport interface AttributeFieldOptions extends SwcQueryOptions {\n name?: string;\n // connectedInitialize?: boolean;\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface AttributeFieldMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: AttributeFieldOptions;\n privateKey: symbol;\n}\n\nexport const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for('simple-web-component:attribute-field');\n\nconst convertValue = (val: string | null, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\nexport { convertValue };\n\nexport const getAttributeValue = (inst: any, attrName: string, options?: AttributeFieldOptions & { selector?: string }): any => {\n const conf = getElementConfig(inst);\n const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // If selector is not provided, use inst itself\n const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];\n\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function' && (primaryTarget as any).hasAttribute(attrName)) {\n let domVal = (primaryTarget as any).getAttribute(attrName);\n\n // \uD45C\uD604\uC2DD \uCCB4\uD06C\n const ae = new ActionExpression(domVal);\n const expr = ae.getFirstExpression('callReturn');\n if (expr) {\n try {\n const result = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),\n context: inst,\n args: SwcUtils.getHelperAndHostSet(currentWin, inst)\n });\n return convertValue(result, options?.type);\n } catch (e) {\n console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);\n return convertValue(domVal, options?.type);\n }\n }\n\n return convertValue(domVal, options?.type);\n }\n\n // If no target found, return null\n return null;\n};\n\nexport const resolveTargetEls = (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any): HTMLElement[] => {\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (selector === '$this' || !selector) {\n applyRoot(inst);\n } else if (selector === '$window') {\n results.push(currentWin);\n } else if (selector === '$document') {\n results.push(currentWin.document);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (selector === '$host') applyRoot(hostSet.$host);\n else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);\n else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(selector);\n const lMatch = inst.querySelectorAll(selector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(selector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @attribute decorator to sync a field value with an element's attribute.\n */\nexport function attribute(selector: string, options: AttributeFieldOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n const privateKey = Symbol(String(propertyKey));\n //\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n //\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor) as AttributeFieldMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);\n }\n metaList.push({ propertyKey, selector, options, privateKey });\n\n const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {\n targets.forEach(it => {\n // console.log('sssssssssssss', it, attrName, nv);\n if (it && typeof (it as any).setAttribute === 'function') {\n if (nv === null) {\n (it as any).removeAttribute(attrName);\n } else {\n (it as any).setAttribute(attrName, String(nv));\n }\n } else {\n inst[privateKey] = nv;\n }\n });\n };\n\n try {\n // Own property\uB97C \uC0AD\uC81C\uD558\uC5EC getter\uAC00 \uC791\uB3D9\uD558\uB3C4\uB85D \uD568\n // delete target[propertyKey];\n\n // const defineTarget = target instanceof Function ? target : (target as any).constructor;\n\n Object.defineProperty(target, propertyKey, {\n get(this: any) {\n const attrName = options.name || String(propertyKey);\n\n // Merge designType fallback into options once\n const mergedOptions = {\n ...options,\n selector,\n type: options.type || designType\n };\n\n const result = getAttributeValue(this, attrName, mergedOptions);\n return result !== null ? result : this[privateKey];\n },\n set(this: any, nv: any) {\n // this[propertyKey] = nv;\n // console.log('------>??settttt', this, nv, propertyKey);\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // if (!this.__swc_connected) {\n // this[privateKey] = nv;\n // return;\n // }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n applySetAttribute(this, targets, attrName, nv);\n },\n enumerable: true,\n configurable: true\n });\n } catch (err) {\n console.error('[SWC] defineProperty error:', err);\n }\n };\n}\n\n/**\n * @attributeThis decorator to sync a field value with the $this element's attribute.\n */\nexport function attributeThis(target: Object, propertyKey: string | symbol): void;\nexport function attributeThis(options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeThis(attrName: string): PropertyDecorator;\nexport function attributeThis(attrName: string, options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeThis(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {\n if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n return attribute('$this', { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);\n }\n\n if (typeof targetOrAttrOrOptions === 'string') {\n const attrName = targetOrAttrOrOptions;\n const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeFieldOptions;\n return attribute('$this', { ...options, name: attrName });\n } else if (typeof targetOrAttrOrOptions === 'object') {\n const options = targetOrAttrOrOptions as AttributeFieldOptions;\n return (target: Object, propertyKey: string | symbol) => {\n return attribute('$this', { ...options, name: String(propertyKey) })(target, propertyKey);\n };\n } else {\n return (target: Object, propertyKey: string | symbol) => {\n return attribute('$this', { name: String(propertyKey) })(target, propertyKey);\n };\n }\n}\n\nexport const findAllAttributeMetadata = (target: any): AttributeFieldMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<AttributeFieldMetadata[]>(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc,eAAe,wBAAwB;AAC9D,SAAqB,wBAAwB;AAC7C,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;AActB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,MAAM,eAAe,CAAC,KAAoB,SAAmB;AAC3D,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAIO,MAAM,oBAAoB,CAAC,MAAW,UAAkB,YAAiE;AAC9H,QAAM,OAAO,iBAAiB,IAAI;AAClC,QAAM,aAAa,KAAK,iBAAiB,IAAI,MAAO,OAAO,WAAW,cAAc,SAAS;AAG7F,QAAM,UAAU,SAAS,WAAW,iBAAiB,MAAM,QAAQ,UAAU,SAAS,UAAU,IAAI,CAAC,IAAI;AAEzG,QAAM,gBAAgB,QAAQ,CAAC;AAE/B,MAAI,iBAAiB,OAAQ,cAAsB,iBAAiB,cAAe,cAAsB,aAAa,QAAQ,GAAG;AAC/H,QAAI,SAAU,cAAsB,aAAa,QAAQ;AAGzD,UAAM,KAAK,IAAI,iBAAiB,MAAM;AACtC,UAAM,OAAO,GAAG,mBAAmB,YAAY;AAC/C,QAAI,MAAM;AACR,UAAI;AACF,cAAM,SAAS,cAAc,cAAc;AAAA,UACzC,QAAQ,aAAa,iBAAiB,KAAK,QAA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,EAC1D,WAAW,OAAO,0BAA0B,UAAU;AACpD,UAAM,UAAU;AAChB,WAAO,CAAC,QAAgB,gBAAiC;AACvD,aAAO,UAAU,SAAS,EAAE,GAAG,SAAS,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC1F;AAAA,EACF,OAAO;AACL,WAAO,CAAC,QAAgB,gBAAiC;AACvD,aAAO,UAAU,SAAS,EAAE,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC9E;AAAA,EACF;AACF;AAEO,MAAM,2BAA2B,CAAC,WAA0C;AACjF,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,aAAa,gBAA0C,8BAA8B,YAAY,EAAE,KAAK;AACjH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils } from "@dooboostore/core";
|
|
2
|
-
import { ensureInit } from "./elementDefine.js";
|
|
3
|
-
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
-
const PROPERTY_SET_METADATA_KEY = Symbol.for("simple-web-component:property-set");
|
|
5
|
-
const setProperty = (selector, propertyNameOrOptions, options = {}) => {
|
|
6
|
-
return (target, propertyKey, descriptor) => {
|
|
7
|
-
const constructor = target.constructor;
|
|
8
|
-
let metaList = ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor);
|
|
9
|
-
if (!metaList) {
|
|
10
|
-
metaList = /* @__PURE__ */ new Map();
|
|
11
|
-
ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);
|
|
12
|
-
}
|
|
13
|
-
let propertyName = typeof propertyNameOrOptions === "string" ? propertyNameOrOptions : void 0;
|
|
14
|
-
let finalOptions = options;
|
|
15
|
-
if (typeof propertyNameOrOptions === "object" && propertyNameOrOptions !== null) {
|
|
16
|
-
finalOptions = propertyNameOrOptions;
|
|
17
|
-
}
|
|
18
|
-
metaList.set(propertyKey, {
|
|
19
|
-
propertyKey,
|
|
20
|
-
selector,
|
|
21
|
-
options: { ...finalOptions, name: propertyName }
|
|
22
|
-
});
|
|
23
|
-
const original = descriptor.value;
|
|
24
|
-
descriptor.value = function(...args) {
|
|
25
|
-
ensureInit(this);
|
|
26
|
-
const res = original.apply(this, args);
|
|
27
|
-
const handleResult = (resolvedValue) => {
|
|
28
|
-
if (resolvedValue !== void 0) {
|
|
29
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
30
|
-
const host = this;
|
|
31
|
-
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
32
|
-
const r = finalOptions.root || "auto";
|
|
33
|
-
const targetEls = [];
|
|
34
|
-
const applyRoot = (t) => {
|
|
35
|
-
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
36
|
-
targetEls.push(t);
|
|
37
|
-
};
|
|
38
|
-
if (selector === "$this" || !selector) applyRoot(host);
|
|
39
|
-
else if (selector === "$host") applyRoot(hostSet.$host);
|
|
40
|
-
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
41
|
-
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
42
|
-
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
43
|
-
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
44
|
-
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
45
|
-
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
46
|
-
else if (selector === "$hosts") hostSet.$hosts.forEach(applyRoot);
|
|
47
|
-
else if (selector === "$appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
48
|
-
else {
|
|
49
|
-
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
50
|
-
if (targetRoot) {
|
|
51
|
-
const found = targetRoot.querySelectorAll(selector);
|
|
52
|
-
if (found) targetEls.push(...Array.from(found));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
targetEls.forEach((targetEl) => {
|
|
56
|
-
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
|
|
60
|
-
if (propertyName) {
|
|
61
|
-
targetEl[propertyName] = resolvedRes;
|
|
62
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
63
|
-
Object.entries(resolvedRes).forEach(([prop, val]) => {
|
|
64
|
-
const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
|
|
65
|
-
targetEl[prop] = finalVal;
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
targetEl.value = resolvedRes;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return resolvedValue;
|
|
73
|
-
};
|
|
74
|
-
if (res instanceof Promise) {
|
|
75
|
-
return res.then(handleResult);
|
|
76
|
-
} else {
|
|
77
|
-
return handleResult(res);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const setPropertyThis = (propertyNameOrOptions, options = {}) => {
|
|
83
|
-
return setProperty("$this", propertyNameOrOptions, options);
|
|
84
|
-
};
|
|
85
|
-
export {
|
|
86
|
-
PROPERTY_SET_METADATA_KEY,
|
|
87
|
-
setProperty,
|
|
88
|
-
setPropertyThis
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=setProperty.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/setProperty.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface PropertySetOptions extends SwcQueryOptions {\n name?: string;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface PropertySetMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: PropertySetOptions;\n}\n\nexport const PROPERTY_SET_METADATA_KEY = Symbol.for('simple-web-component:property-set');\n\nexport const setProperty = (selector: string, propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor) as Map<string | symbol, PropertySetMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, PropertySetMetadata>();\n ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);\n }\n\n let propertyName = typeof propertyNameOrOptions === 'string' ? propertyNameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof propertyNameOrOptions === 'object' && propertyNameOrOptions !== null) {\n finalOptions = propertyNameOrOptions as PropertySetOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n options: { ...finalOptions, name: propertyName } \n });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === '$this' || !selector) applyRoot(host);\n else if (selector === '$host') applyRoot(hostSet.$host);\n else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === '$appHost') applyRoot(hostSet.$appHost);\n else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (propertyName) {\n // Case: @setProperty(selector, 'propertyName')\n (targetEl as any)[propertyName] = resolvedRes;\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n // Case: @setProperty(selector) with Object return - assign multiple properties\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n (targetEl as any)[prop] = finalVal;\n });\n } else {\n // Simple value - assign to 'value' property by default\n (targetEl as any).value = resolvedRes;\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then(handleResult);\n } else {\n return handleResult(res);\n }\n };\n };\n};\n\nexport const setPropertyThis = (propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {\n return setProperty('$this', propertyNameOrOptions, options);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAclB,MAAM,4BAA4B,OAAO,IAAI,mCAAmC;AA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MACzB;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,kBAAkB,CAAC,uBAAqD,UAA8B,CAAC,MAAuB;AACzI,SAAO,YAAY,SAAS,uBAAuB,OAAO;AAC5D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { SwcQueryOptions } from '../types';
|
|
2
|
-
export interface AttributeFieldOptions extends SwcQueryOptions {
|
|
3
|
-
name?: string;
|
|
4
|
-
type?: typeof Number | typeof Boolean | typeof String;
|
|
5
|
-
}
|
|
6
|
-
export interface AttributeFieldMetadata {
|
|
7
|
-
propertyKey: string | symbol;
|
|
8
|
-
selector: string;
|
|
9
|
-
options: AttributeFieldOptions;
|
|
10
|
-
privateKey: symbol;
|
|
11
|
-
}
|
|
12
|
-
export declare const ATTRIBUTE_FIELD_METADATA_KEY: unique symbol;
|
|
13
|
-
declare const convertValue: (val: string | null, type: any) => any;
|
|
14
|
-
export { convertValue };
|
|
15
|
-
export declare const getAttributeValue: (inst: any, attrName: string, options?: AttributeFieldOptions & {
|
|
16
|
-
selector?: string;
|
|
17
|
-
}) => any;
|
|
18
|
-
export declare const resolveTargetEls: (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any) => HTMLElement[];
|
|
19
|
-
/**
|
|
20
|
-
* @attribute decorator to sync a field value with an element's attribute.
|
|
21
|
-
*/
|
|
22
|
-
export declare function attribute(selector: string, options?: AttributeFieldOptions): PropertyDecorator;
|
|
23
|
-
/**
|
|
24
|
-
* @attributeThis decorator to sync a field value with the $this element's attribute.
|
|
25
|
-
*/
|
|
26
|
-
export declare function attributeThis(target: Object, propertyKey: string | symbol): void;
|
|
27
|
-
export declare function attributeThis(options: AttributeFieldOptions): PropertyDecorator;
|
|
28
|
-
export declare function attributeThis(attrName: string): PropertyDecorator;
|
|
29
|
-
export declare function attributeThis(attrName: string, options: AttributeFieldOptions): PropertyDecorator;
|
|
30
|
-
export declare const findAllAttributeMetadata: (target: any) => Attribute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AAO,EAAE,qBAAqB,GAAG,iBAAiB,CAAC;AACjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAAC;AACnE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,CAAC;AAsBnG,eAAO,MAAM,wBAAwB,GAAI,QAAQ,GAAG,KAAG,sBAAsB,EAG5E,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SwcQueryOptions, HelperHostSet } from '../types';
|
|
2
|
-
export interface PropertySetOptions extends SwcQueryOptions {
|
|
3
|
-
name?: string;
|
|
4
|
-
filter?: (target: HTMLElement, value: any, meta: {
|
|
5
|
-
currentThis: any;
|
|
6
|
-
helper: HelperHostSet;
|
|
7
|
-
}) => boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface PropertySetMetadata {
|
|
10
|
-
propertyKey: string | symbol;
|
|
11
|
-
selector: string;
|
|
12
|
-
options: PropertySetOptions;
|
|
13
|
-
}
|
|
14
|
-
export declare const PROPERTY_SET_METADATA_KEY: unique symbol;
|
|
15
|
-
export declare const setProperty: (selector: string, propertyNameOrOptions?: string | PropertySetOptions, options?: PropertySetOptions) => MethodDecorator;
|
|
16
|
-
export declare const setPropertyThis: (propertyNameOrOptions?: string | PropertySetOptions, options?: PropertySetOptions) => MethodDecorator;
|
|
17
|
-
//# sourceMappingURL=setProperty.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setProperty.d.ts","sourceRoot":"","sources":["../../../src/decorators/setProperty.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE3E,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE;QAAC,WAAW,EAAE,GAAG,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAC,KAAK,OAAO,CAAC;CACxG;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,kBAAkB,CAAC;CAC7B;AAED,eAAO,MAAM,yBAAyB,eAAkD,CAAC;AAEzF,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,EAAE,wBAAwB,MAAM,GAAG,kBAAkB,EAAE,UAAS,kBAAuB,KAAG,eAyFrI,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,wBAAwB,MAAM,GAAG,kBAAkB,EAAE,UAAS,kBAAuB,KAAG,eAEvH,CAAC"}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils, FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
2
|
-
import { ensureInit, getElementConfig } from './elementDefine';
|
|
3
|
-
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
|
-
import { ConvertUtils } from '@dooboostore/core-web';
|
|
6
|
-
export interface AttributeFieldOptions extends SwcQueryOptions {
|
|
7
|
-
name?: string;
|
|
8
|
-
// connectedInitialize?: boolean;
|
|
9
|
-
type?: typeof Number | typeof Boolean | typeof String;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface AttributeFieldMetadata {
|
|
13
|
-
propertyKey: string | symbol;
|
|
14
|
-
selector: string;
|
|
15
|
-
options: AttributeFieldOptions;
|
|
16
|
-
privateKey: symbol;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for('simple-web-component:attribute-field');
|
|
20
|
-
|
|
21
|
-
const convertValue = (val: string | null, type: any): any => {
|
|
22
|
-
if (val === null || val === undefined) return val;
|
|
23
|
-
if (type === Number) return Number(val);
|
|
24
|
-
if (type === Boolean) return val === 'false' || val === '0' ? false : true;
|
|
25
|
-
return val;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { convertValue };
|
|
29
|
-
|
|
30
|
-
export const getAttributeValue = (inst: any, attrName: string, options?: AttributeFieldOptions & { selector?: string }): any => {
|
|
31
|
-
const conf = getElementConfig(inst);
|
|
32
|
-
const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);
|
|
33
|
-
|
|
34
|
-
// If selector is not provided, use inst itself
|
|
35
|
-
const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];
|
|
36
|
-
|
|
37
|
-
const primaryTarget = targets[0];
|
|
38
|
-
|
|
39
|
-
if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function' && (primaryTarget as any).hasAttribute(attrName)) {
|
|
40
|
-
let domVal = (primaryTarget as any).getAttribute(attrName);
|
|
41
|
-
|
|
42
|
-
// 표현식 체크
|
|
43
|
-
const ae = new ActionExpression(domVal);
|
|
44
|
-
const expr = ae.getFirstExpression('callReturn');
|
|
45
|
-
if (expr) {
|
|
46
|
-
try {
|
|
47
|
-
const result = FunctionUtils.executeReturn({
|
|
48
|
-
script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),
|
|
49
|
-
context: inst,
|
|
50
|
-
args: SwcUtils.getHelperAndHostSet(currentWin, inst)
|
|
51
|
-
});
|
|
52
|
-
return convertValue(result, options?.type);
|
|
53
|
-
} catch (e) {
|
|
54
|
-
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);
|
|
55
|
-
return convertValue(domVal, options?.type);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return convertValue(domVal, options?.type);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// If no target found, return null
|
|
63
|
-
return null;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const resolveTargetEls = (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any): HTMLElement[] => {
|
|
67
|
-
const r = options.root || 'auto';
|
|
68
|
-
const results: HTMLElement[] = [];
|
|
69
|
-
|
|
70
|
-
const applyRoot = (target: any) => {
|
|
71
|
-
if (!target) return;
|
|
72
|
-
if (r === 'auto') {
|
|
73
|
-
results.push(target);
|
|
74
|
-
} else {
|
|
75
|
-
if (r === 'light' || r === 'all') results.push(target);
|
|
76
|
-
if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
if (selector === '$this' || !selector) {
|
|
81
|
-
applyRoot(inst);
|
|
82
|
-
} else if (selector === '$window') {
|
|
83
|
-
results.push(currentWin);
|
|
84
|
-
} else if (selector === '$document') {
|
|
85
|
-
results.push(currentWin.document);
|
|
86
|
-
} else {
|
|
87
|
-
const hostSet = SwcUtils.getHostSet(inst);
|
|
88
|
-
if (selector === '$host') applyRoot(hostSet.$host);
|
|
89
|
-
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
90
|
-
else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);
|
|
91
|
-
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
92
|
-
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
93
|
-
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
|
|
94
|
-
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
|
|
95
|
-
else {
|
|
96
|
-
if (r === 'shadow') {
|
|
97
|
-
const found = inst.shadowRoot?.querySelectorAll(selector);
|
|
98
|
-
if (found) results.push(...found);
|
|
99
|
-
} else if (r === 'light') {
|
|
100
|
-
const found = inst.querySelectorAll(selector);
|
|
101
|
-
if (found) results.push(...found);
|
|
102
|
-
} else if (r === 'all') {
|
|
103
|
-
const sMatch = inst.shadowRoot?.querySelectorAll(selector);
|
|
104
|
-
const lMatch = inst.querySelectorAll(selector);
|
|
105
|
-
if (sMatch) results.push(...sMatch);
|
|
106
|
-
if (lMatch) results.push(...lMatch);
|
|
107
|
-
} else {
|
|
108
|
-
const found = (inst.shadowRoot || inst).querySelectorAll(selector);
|
|
109
|
-
if (found) results.push(...found);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return results;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @attribute decorator to sync a field value with an element's attribute.
|
|
118
|
-
*/
|
|
119
|
-
export function attribute(selector: string, options: AttributeFieldOptions = {}): PropertyDecorator {
|
|
120
|
-
return (target: Object, propertyKey: string | symbol) => {
|
|
121
|
-
const constructor = target.constructor;
|
|
122
|
-
const privateKey = Symbol(String(propertyKey));
|
|
123
|
-
//
|
|
124
|
-
const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);
|
|
125
|
-
//
|
|
126
|
-
let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor) as AttributeFieldMetadata[];
|
|
127
|
-
if (!metaList) {
|
|
128
|
-
metaList = [];
|
|
129
|
-
ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);
|
|
130
|
-
}
|
|
131
|
-
metaList.push({ propertyKey, selector, options, privateKey });
|
|
132
|
-
|
|
133
|
-
const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {
|
|
134
|
-
targets.forEach(it => {
|
|
135
|
-
// console.log('sssssssssssss', it, attrName, nv);
|
|
136
|
-
if (it && typeof (it as any).setAttribute === 'function') {
|
|
137
|
-
if (nv === null) {
|
|
138
|
-
(it as any).removeAttribute(attrName);
|
|
139
|
-
} else {
|
|
140
|
-
(it as any).setAttribute(attrName, String(nv));
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
inst[privateKey] = nv;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
// Own property를 삭제하여 getter가 작동하도록 함
|
|
150
|
-
// delete target[propertyKey];
|
|
151
|
-
|
|
152
|
-
// const defineTarget = target instanceof Function ? target : (target as any).constructor;
|
|
153
|
-
|
|
154
|
-
Object.defineProperty(target, propertyKey, {
|
|
155
|
-
get(this: any) {
|
|
156
|
-
const attrName = options.name || String(propertyKey);
|
|
157
|
-
|
|
158
|
-
// Merge designType fallback into options once
|
|
159
|
-
const mergedOptions = {
|
|
160
|
-
...options,
|
|
161
|
-
selector,
|
|
162
|
-
type: options.type || designType
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const result = getAttributeValue(this, attrName, mergedOptions);
|
|
166
|
-
return result !== null ? result : this[privateKey];
|
|
167
|
-
},
|
|
168
|
-
set(this: any, nv: any) {
|
|
169
|
-
// this[propertyKey] = nv;
|
|
170
|
-
// console.log('------>??settttt', this, nv, propertyKey);
|
|
171
|
-
const attrName = options.name || String(propertyKey);
|
|
172
|
-
const conf = getElementConfig(this);
|
|
173
|
-
const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);
|
|
174
|
-
|
|
175
|
-
// if (!this.__swc_connected) {
|
|
176
|
-
// this[privateKey] = nv;
|
|
177
|
-
// return;
|
|
178
|
-
// }
|
|
179
|
-
|
|
180
|
-
const targets = resolveTargetEls(this, selector, options, currentWin);
|
|
181
|
-
applySetAttribute(this, targets, attrName, nv);
|
|
182
|
-
},
|
|
183
|
-
enumerable: true,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
|
-
} catch (err) {
|
|
187
|
-
console.error('[SWC] defineProperty error:', err);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @attributeThis decorator to sync a field value with the $this element's attribute.
|
|
194
|
-
*/
|
|
195
|
-
export function attributeThis(target: Object, propertyKey: string | symbol): void;
|
|
196
|
-
export function attributeThis(options: AttributeFieldOptions): PropertyDecorator;
|
|
197
|
-
export function attributeThis(attrName: string): PropertyDecorator;
|
|
198
|
-
export function attributeThis(attrName: string, options: AttributeFieldOptions): PropertyDecorator;
|
|
199
|
-
export function attributeThis(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {
|
|
200
|
-
if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
|
|
201
|
-
return attribute('$this', { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (typeof targetOrAttrOrOptions === 'string') {
|
|
205
|
-
const attrName = targetOrAttrOrOptions;
|
|
206
|
-
const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeFieldOptions;
|
|
207
|
-
return attribute('$this', { ...options, name: attrName });
|
|
208
|
-
} else if (typeof targetOrAttrOrOptions === 'object') {
|
|
209
|
-
const options = targetOrAttrOrOptions as AttributeFieldOptions;
|
|
210
|
-
return (target: Object, propertyKey: string | symbol) => {
|
|
211
|
-
return attribute('$this', { ...options, name: String(propertyKey) })(target, propertyKey);
|
|
212
|
-
};
|
|
213
|
-
} else {
|
|
214
|
-
return (target: Object, propertyKey: string | symbol) => {
|
|
215
|
-
return attribute('$this', { name: String(propertyKey) })(target, propertyKey);
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export const findAllAttributeMetadata = (target: any): AttributeFieldMetadata[] => {
|
|
221
|
-
const actualTarget = target instanceof Function ? target : target.constructor;
|
|
222
|
-
return ReflectUtils.findAllMetadata<AttributeFieldMetadata[]>(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();
|
|
223
|
-
};
|