@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.
Files changed (91) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +88 -871
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +194 -111
  5. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  6. package/dist/cjs/decorators/applyNode.js +82 -80
  7. package/dist/cjs/decorators/applyNode.js.map +2 -2
  8. package/dist/cjs/decorators/applyProperty.js +213 -0
  9. package/dist/cjs/decorators/applyProperty.js.map +7 -0
  10. package/dist/cjs/decorators/applySlot.js +93 -82
  11. package/dist/cjs/decorators/applySlot.js.map +3 -3
  12. package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
  13. package/dist/cjs/decorators/elementDefine.js +14 -34
  14. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  15. package/dist/cjs/decorators/index.js +2 -2
  16. package/dist/cjs/decorators/index.js.map +2 -2
  17. package/dist/cjs/decorators/lifecycles.js +4 -4
  18. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  19. package/dist/cjs/decorators/state.js +0 -1
  20. package/dist/cjs/decorators/state.js.map +2 -2
  21. package/dist/cjs/elements/SwcApp.js.map +2 -2
  22. package/dist/cjs/types/index.js.map +1 -1
  23. package/dist/esm/SwcAppEngine.js.map +2 -2
  24. package/dist/esm/decorators/applyAttribute.js +196 -113
  25. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  26. package/dist/esm/decorators/applyNode.js +82 -80
  27. package/dist/esm/decorators/applyNode.js.map +2 -2
  28. package/dist/esm/decorators/applyProperty.js +194 -0
  29. package/dist/esm/decorators/applyProperty.js.map +7 -0
  30. package/dist/esm/decorators/applySlot.js +93 -82
  31. package/dist/esm/decorators/applySlot.js.map +3 -3
  32. package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
  33. package/dist/esm/decorators/elementDefine.js +14 -34
  34. package/dist/esm/decorators/elementDefine.js.map +2 -2
  35. package/dist/esm/decorators/index.js +2 -2
  36. package/dist/esm/decorators/index.js.map +1 -1
  37. package/dist/esm/decorators/lifecycles.js +4 -4
  38. package/dist/esm/decorators/lifecycles.js.map +2 -2
  39. package/dist/esm/decorators/state.js +0 -1
  40. package/dist/esm/decorators/state.js.map +2 -2
  41. package/dist/esm/elements/SwcApp.js.map +2 -2
  42. package/dist/esm/types/index.js.map +1 -1
  43. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +525 -513
  44. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  45. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  46. package/dist/types/decorators/applyAttribute.d.ts +56 -15
  47. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  48. package/dist/types/decorators/applyNode.d.ts +28 -24
  49. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  50. package/dist/types/decorators/applyProperty.d.ts +61 -0
  51. package/dist/types/decorators/applyProperty.d.ts.map +1 -0
  52. package/dist/types/decorators/applySlot.d.ts +17 -15
  53. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  54. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  55. package/dist/types/decorators/index.d.ts +2 -2
  56. package/dist/types/decorators/index.d.ts.map +1 -1
  57. package/dist/types/decorators/lifecycles.d.ts +4 -4
  58. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  59. package/dist/types/decorators/state.d.ts.map +1 -1
  60. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  61. package/dist/types/types/index.d.ts +1 -6
  62. package/dist/types/types/index.d.ts.map +1 -1
  63. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +525 -513
  64. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  65. package/package.json +1 -1
  66. package/src/SwcAppEngine.ts +1 -0
  67. package/src/decorators/applyAttribute.ts +311 -126
  68. package/src/decorators/applyNode.ts +108 -105
  69. package/src/decorators/applyProperty.ts +302 -0
  70. package/src/decorators/applySlot.ts +112 -94
  71. package/src/decorators/changedAttributeThis.ts +1 -1
  72. package/src/decorators/elementDefine.ts +44 -33
  73. package/src/decorators/index.ts +2 -3
  74. package/src/decorators/lifecycles.ts +6 -6
  75. package/src/decorators/state.ts +0 -1
  76. package/src/elements/SwcApp.ts +0 -1
  77. package/src/types/index.ts +7 -7
  78. package/dist/cjs/decorators/attribute.js +0 -187
  79. package/dist/cjs/decorators/attribute.js.map +0 -7
  80. package/dist/cjs/decorators/setProperty.js +0 -109
  81. package/dist/cjs/decorators/setProperty.js.map +0 -7
  82. package/dist/esm/decorators/attribute.js +0 -168
  83. package/dist/esm/decorators/attribute.js.map +0 -7
  84. package/dist/esm/decorators/setProperty.js +0 -90
  85. package/dist/esm/decorators/setProperty.js.map +0 -7
  86. package/dist/types/decorators/attribute.d.ts +0 -31
  87. package/dist/types/decorators/attribute.d.ts.map +0 -1
  88. package/dist/types/decorators/setProperty.d.ts +0 -17
  89. package/dist/types/decorators/setProperty.d.ts.map +0 -1
  90. package/src/decorators/attribute.ts +0 -223
  91. package/src/decorators/setProperty.ts +0 -112
@@ -1,187 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var attribute_exports = {};
19
- __export(attribute_exports, {
20
- ATTRIBUTE_FIELD_METADATA_KEY: () => ATTRIBUTE_FIELD_METADATA_KEY,
21
- attribute: () => attribute,
22
- attributeThis: () => attributeThis,
23
- convertValue: () => convertValue,
24
- findAllAttributeMetadata: () => findAllAttributeMetadata,
25
- getAttributeValue: () => getAttributeValue,
26
- resolveTargetEls: () => resolveTargetEls
27
- });
28
- module.exports = __toCommonJS(attribute_exports);
29
- var import_core = require("@dooboostore/core");
30
- var import_elementDefine = require("./elementDefine");
31
- var import_Utils = require("../utils/Utils");
32
- var import_core_web = require("@dooboostore/core-web");
33
- const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for("simple-web-component:attribute-field");
34
- const convertValue = (val, type) => {
35
- if (val === null || val === void 0) return val;
36
- if (type === Number) return Number(val);
37
- if (type === Boolean) return val === "false" || val === "0" ? false : true;
38
- return val;
39
- };
40
- const getAttributeValue = (inst, attrName, options) => {
41
- const conf = (0, import_elementDefine.getElementConfig)(inst);
42
- const currentWin = inst._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
43
- const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];
44
- const primaryTarget = targets[0];
45
- if (primaryTarget && typeof primaryTarget.hasAttribute === "function" && primaryTarget.hasAttribute(attrName)) {
46
- let domVal = primaryTarget.getAttribute(attrName);
47
- const ae = new import_core.ActionExpression(domVal);
48
- const expr = ae.getFirstExpression("callReturn");
49
- if (expr) {
50
- try {
51
- const result = import_core.FunctionUtils.executeReturn({
52
- script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),
53
- context: inst,
54
- args: import_Utils.SwcUtils.getHelperAndHostSet(currentWin, inst)
55
- });
56
- return convertValue(result, options?.type);
57
- } catch (e) {
58
- console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);
59
- return convertValue(domVal, options?.type);
60
- }
61
- }
62
- return convertValue(domVal, options?.type);
63
- }
64
- return null;
65
- };
66
- const resolveTargetEls = (inst, selector, options, currentWin) => {
67
- const r = options.root || "auto";
68
- const results = [];
69
- const applyRoot = (target) => {
70
- if (!target) return;
71
- if (r === "auto") {
72
- results.push(target);
73
- } else {
74
- if (r === "light" || r === "all") results.push(target);
75
- if ((r === "shadow" || r === "all") && target.shadowRoot) results.push(target.shadowRoot);
76
- }
77
- };
78
- if (selector === "$this" || !selector) {
79
- applyRoot(inst);
80
- } else if (selector === "$window") {
81
- results.push(currentWin);
82
- } else if (selector === "$document") {
83
- results.push(currentWin.document);
84
- } else {
85
- const hostSet = import_Utils.SwcUtils.getHostSet(inst);
86
- if (selector === "$host") applyRoot(hostSet.$host);
87
- else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
88
- else if (selector === "$appHost") applyRoot(hostSet.$appHost);
89
- else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
90
- else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
91
- else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
92
- else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
93
- else {
94
- if (r === "shadow") {
95
- const found = inst.shadowRoot?.querySelectorAll(selector);
96
- if (found) results.push(...found);
97
- } else if (r === "light") {
98
- const found = inst.querySelectorAll(selector);
99
- if (found) results.push(...found);
100
- } else if (r === "all") {
101
- const sMatch = inst.shadowRoot?.querySelectorAll(selector);
102
- const lMatch = inst.querySelectorAll(selector);
103
- if (sMatch) results.push(...sMatch);
104
- if (lMatch) results.push(...lMatch);
105
- } else {
106
- const found = (inst.shadowRoot || inst).querySelectorAll(selector);
107
- if (found) results.push(...found);
108
- }
109
- }
110
- }
111
- return results;
112
- };
113
- function attribute(selector, options = {}) {
114
- return (target, propertyKey) => {
115
- const constructor = target.constructor;
116
- const privateKey = Symbol(String(propertyKey));
117
- const designType = Reflect.getMetadata("design:type", target, propertyKey);
118
- let metaList = import_core.ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor);
119
- if (!metaList) {
120
- metaList = [];
121
- import_core.ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);
122
- }
123
- metaList.push({ propertyKey, selector, options, privateKey });
124
- const applySetAttribute = (inst, targets, attrName, nv) => {
125
- targets.forEach((it) => {
126
- if (it && typeof it.setAttribute === "function") {
127
- if (nv === null) {
128
- it.removeAttribute(attrName);
129
- } else {
130
- it.setAttribute(attrName, String(nv));
131
- }
132
- } else {
133
- inst[privateKey] = nv;
134
- }
135
- });
136
- };
137
- try {
138
- Object.defineProperty(target, propertyKey, {
139
- get() {
140
- const attrName = options.name || String(propertyKey);
141
- const mergedOptions = {
142
- ...options,
143
- selector,
144
- type: options.type || designType
145
- };
146
- const result = getAttributeValue(this, attrName, mergedOptions);
147
- return result !== null ? result : this[privateKey];
148
- },
149
- set(nv) {
150
- const attrName = options.name || String(propertyKey);
151
- const conf = (0, import_elementDefine.getElementConfig)(this);
152
- const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
153
- const targets = resolveTargetEls(this, selector, options, currentWin);
154
- applySetAttribute(this, targets, attrName, nv);
155
- },
156
- enumerable: true,
157
- configurable: true
158
- });
159
- } catch (err) {
160
- console.error("[SWC] defineProperty error:", err);
161
- }
162
- };
163
- }
164
- function attributeThis(targetOrAttrOrOptions, propertyKeyOrOptions) {
165
- if (propertyKeyOrOptions !== void 0 && (typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol")) {
166
- return attribute("$this", { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
167
- }
168
- if (typeof targetOrAttrOrOptions === "string") {
169
- const attrName = targetOrAttrOrOptions;
170
- const options = typeof propertyKeyOrOptions === "object" ? propertyKeyOrOptions : {};
171
- return attribute("$this", { ...options, name: attrName });
172
- } else if (typeof targetOrAttrOrOptions === "object") {
173
- const options = targetOrAttrOrOptions;
174
- return (target, propertyKey) => {
175
- return attribute("$this", { ...options, name: String(propertyKey) })(target, propertyKey);
176
- };
177
- } else {
178
- return (target, propertyKey) => {
179
- return attribute("$this", { name: String(propertyKey) })(target, propertyKey);
180
- };
181
- }
182
- }
183
- const findAllAttributeMetadata = (target) => {
184
- const actualTarget = target instanceof Function ? target : target.constructor;
185
- return import_core.ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();
186
- };
187
- //# 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBA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O,MAAM,2BAA2B,CAAC,WAA0C;AACjF,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,yBAAa,gBAA0C,8BAA8B,YAAY,EAAE,KAAK;AACjH;",
6
- "names": []
7
- }
@@ -1,109 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var setProperty_exports = {};
19
- __export(setProperty_exports, {
20
- PROPERTY_SET_METADATA_KEY: () => PROPERTY_SET_METADATA_KEY,
21
- setProperty: () => setProperty,
22
- setPropertyThis: () => setPropertyThis
23
- });
24
- module.exports = __toCommonJS(setProperty_exports);
25
- var import_core = require("@dooboostore/core");
26
- var import_elementDefine = require("./elementDefine");
27
- var import_Utils = require("../utils/Utils");
28
- const PROPERTY_SET_METADATA_KEY = Symbol.for("simple-web-component:property-set");
29
- const setProperty = (selector, propertyNameOrOptions, options = {}) => {
30
- return (target, propertyKey, descriptor) => {
31
- const constructor = target.constructor;
32
- let metaList = import_core.ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor);
33
- if (!metaList) {
34
- metaList = /* @__PURE__ */ new Map();
35
- import_core.ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);
36
- }
37
- let propertyName = typeof propertyNameOrOptions === "string" ? propertyNameOrOptions : void 0;
38
- let finalOptions = options;
39
- if (typeof propertyNameOrOptions === "object" && propertyNameOrOptions !== null) {
40
- finalOptions = propertyNameOrOptions;
41
- }
42
- metaList.set(propertyKey, {
43
- propertyKey,
44
- selector,
45
- options: { ...finalOptions, name: propertyName }
46
- });
47
- const original = descriptor.value;
48
- descriptor.value = function(...args) {
49
- (0, import_elementDefine.ensureInit)(this);
50
- const res = original.apply(this, args);
51
- const handleResult = (resolvedValue) => {
52
- if (resolvedValue !== void 0) {
53
- const win = this.ownerDocument?.defaultView || window;
54
- const host = this;
55
- const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
56
- const r = finalOptions.root || "auto";
57
- const targetEls = [];
58
- const applyRoot = (t) => {
59
- if (!t || !(t instanceof win.HTMLElement)) return;
60
- targetEls.push(t);
61
- };
62
- if (selector === "$this" || !selector) applyRoot(host);
63
- else if (selector === "$host") applyRoot(hostSet.$host);
64
- else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
65
- else if (selector === "$appHost") applyRoot(hostSet.$appHost);
66
- else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
67
- else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
68
- else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
69
- else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
70
- else if (selector === "$hosts") hostSet.$hosts.forEach(applyRoot);
71
- else if (selector === "$appHosts") hostSet.$appHosts.forEach(applyRoot);
72
- else {
73
- const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
74
- if (targetRoot) {
75
- const found = targetRoot.querySelectorAll(selector);
76
- if (found) targetEls.push(...Array.from(found));
77
- }
78
- }
79
- targetEls.forEach((targetEl) => {
80
- if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
81
- return;
82
- }
83
- const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
84
- if (propertyName) {
85
- targetEl[propertyName] = resolvedRes;
86
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
87
- Object.entries(resolvedRes).forEach(([prop, val]) => {
88
- const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
89
- targetEl[prop] = finalVal;
90
- });
91
- } else {
92
- targetEl.value = resolvedRes;
93
- }
94
- });
95
- }
96
- return resolvedValue;
97
- };
98
- if (res instanceof Promise) {
99
- return res.then(handleResult);
100
- } else {
101
- return handleResult(res);
102
- }
103
- };
104
- };
105
- };
106
- const setPropertyThis = (propertyNameOrOptions, options = {}) => {
107
- return setProperty("$this", propertyNameOrOptions, options);
108
- };
109
- //# 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAclB,MAAM,4BAA4B,OAAO,IAAI,mCAAmC;AAEhF,MAAM,cAAc,CAAC,UAAkB,uBAAqD,UAA8B,CAAC,MAAuB;AACvJ,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,yBAAa,eAAe,2BAA2B,WAAW;AACjF,QAAI,CAAC,UAAU;AACb,iBAAW,oBAAI,IAA0C;AACzD,+BAAa,eAAe,2BAA2B,UAAU,WAAW;AAAA,IAC9E;AAEA,QAAI,eAAe,OAAO,0BAA0B,WAAW,wBAAwB;AACvF,QAAI,eAAe;AAEnB,QAAI,OAAO,0BAA0B,YAAY,0BAA0B,MAAM;AAC/E,qBAAe;AAAA,IACjB;AAEA,aAAS,IAAI,aAAa;AAAA,MACxB;AAAA,MACA;AAAA,MACA,SAAS,EAAE,GAAG,cAAc,MAAM,aAAa;AAAA,IACjD,CAAC;AAED,UAAM,WAAW,WAAW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C,aAAa,OAAO,UAAU,eAAe,EAAC,aAAa,MAAM,QAAQ,QAAO,CAAC,GAAG;AAC9G;AAAA,YACF;AACA,kBAAM,cAAc,OAAO,kBAAkB,aAAc,cAAsB,UAAU,OAAO,IAAI;AAEtG,gBAAI,cAAc;AAEhB,cAAC,SAAiB,YAAY,IAAI;AAAA,YACpC,WAAW,OAAO,gBAAgB,YAAY,gBAAgB,QAAQ,CAAC,MAAM,QAAQ,WAAW,GAAG;AAEjG,qBAAO,QAAQ,WAAkB,EAAE,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM;AAC1D,sBAAM,WAAW,OAAO,QAAQ,aAAa,IAAI,UAAU,OAAO,IAAI;AACtE,gBAAC,SAAiB,IAAI,IAAI;AAAA,cAC5B,CAAC;AAAA,YACH,OAAO;AAEL,cAAC,SAAiB,QAAQ;AAAA,YAC5B;AAAA,UACF,CAAC;AAAA,QACH;AACA,eAAO;AAAA,MACT;AAEA,UAAI,eAAe,SAAS;AAC1B,eAAO,IAAI,KAAK,YAAY;AAAA,MAC9B,OAAO;AACL,eAAO,aAAa,GAAG;AAAA,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,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,cAA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I,WAAO,UAAU,SAAS,EAAE,MAAM,OAAO,oBAAoB,EAAE,CAAC,EAAE,uBAAuB,oBAAoB;AAAA,EAC/G;AAEA,MAAI,OAAO,0BAA0B,UAAU;AAC7C,UAAM,WAAW;AACjB,UAAM,UAAW,OAAO,yBAAyB,WAAW,uBAAuB,CAAC;AACpF,WAAO,UAAU,SAAS,EAAE,GAAG,SAAS,MAAM,SAAS,CAAC;AAAA,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