@dooboostore/simple-web-component 1.0.16 → 1.0.17

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 (98) hide show
  1. package/README.md +93 -0
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/elementDefine.js +133 -62
  4. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  5. package/dist/cjs/decorators/query.js +22 -0
  6. package/dist/cjs/decorators/query.js.map +2 -2
  7. package/dist/cjs/decorators/queryAll.js +14 -0
  8. package/dist/cjs/decorators/queryAll.js.map +2 -2
  9. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  10. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  11. package/dist/cjs/elements/SwcAsync.js +188 -0
  12. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  13. package/dist/cjs/elements/SwcChoose.js +155 -0
  14. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  15. package/dist/cjs/elements/SwcIf.js +167 -0
  16. package/dist/cjs/elements/SwcIf.js.map +7 -0
  17. package/dist/cjs/elements/SwcLoop.js +246 -0
  18. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  19. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  20. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  21. package/dist/cjs/elements/index.js +7 -0
  22. package/dist/cjs/elements/index.js.map +2 -2
  23. package/dist/cjs/index.js +1 -1
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils/Utils.js +74 -37
  27. package/dist/cjs/utils/Utils.js.map +3 -3
  28. package/dist/esm/decorators/addEventListener.js.map +2 -2
  29. package/dist/esm/decorators/elementDefine.js +133 -62
  30. package/dist/esm/decorators/elementDefine.js.map +3 -3
  31. package/dist/esm/decorators/query.js +22 -0
  32. package/dist/esm/decorators/query.js.map +2 -2
  33. package/dist/esm/decorators/queryAll.js +14 -0
  34. package/dist/esm/decorators/queryAll.js.map +2 -2
  35. package/dist/esm/elements/SwcAppEngine.js +2 -1
  36. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  37. package/dist/esm/elements/SwcAsync.js +169 -0
  38. package/dist/esm/elements/SwcAsync.js.map +7 -0
  39. package/dist/esm/elements/SwcChoose.js +136 -0
  40. package/dist/esm/elements/SwcChoose.js.map +7 -0
  41. package/dist/esm/elements/SwcIf.js +148 -0
  42. package/dist/esm/elements/SwcIf.js.map +7 -0
  43. package/dist/esm/elements/SwcLoop.js +227 -0
  44. package/dist/esm/elements/SwcLoop.js.map +7 -0
  45. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  46. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  47. package/dist/esm/elements/index.js +7 -0
  48. package/dist/esm/elements/index.js.map +2 -2
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils/Utils.js +74 -37
  53. package/dist/esm/utils/Utils.js.map +3 -3
  54. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1047 -140
  55. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  56. package/dist/types/decorators/addEventListener.d.ts +1 -0
  57. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  58. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  59. package/dist/types/decorators/query.d.ts +0 -2
  60. package/dist/types/decorators/query.d.ts.map +1 -1
  61. package/dist/types/decorators/queryAll.d.ts +0 -2
  62. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  63. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  64. package/dist/types/elements/SwcAsync.d.ts +16 -0
  65. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  66. package/dist/types/elements/SwcChoose.d.ts +13 -0
  67. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  68. package/dist/types/elements/SwcIf.d.ts +15 -0
  69. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  70. package/dist/types/elements/SwcLoop.d.ts +20 -0
  71. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  72. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  73. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  74. package/dist/types/elements/index.d.ts +7 -0
  75. package/dist/types/elements/index.d.ts.map +1 -1
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/types.d.ts +8 -0
  79. package/dist/types/types.d.ts.map +1 -1
  80. package/dist/types/utils/Utils.d.ts +16 -10
  81. package/dist/types/utils/Utils.d.ts.map +1 -1
  82. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1047 -140
  83. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  84. package/package.json +10 -3
  85. package/src/decorators/addEventListener.ts +1 -0
  86. package/src/decorators/elementDefine.ts +137 -66
  87. package/src/decorators/query.ts +20 -2
  88. package/src/decorators/queryAll.ts +16 -2
  89. package/src/elements/SwcAppEngine.ts +2 -1
  90. package/src/elements/SwcAsync.ts +163 -0
  91. package/src/elements/SwcChoose.ts +127 -0
  92. package/src/elements/SwcIf.ts +134 -0
  93. package/src/elements/SwcLoop.ts +215 -0
  94. package/src/elements/SwcSubTemplates.ts +19 -0
  95. package/src/elements/index.ts +8 -3
  96. package/src/index.ts +1 -1
  97. package/src/types.ts +9 -1
  98. package/src/utils/Utils.ts +86 -36
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcIf.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\nimport { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\n\n@elementDefine({ name: 'swc-if', extends: 'template' })\nexport class SwcIf extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _getTarget(): Element | DocumentFragment | null {\n const script = this.getAttribute('on-get-portal');\n if (!script) return null;\n try {\n const res = FunctionUtils.executeReturn({\n script,\n context: this,\n args: SwcUtils.getHelperAndHostSet(window, this)\n });\n if (typeof res === 'string') return document.querySelector(res);\n if (res instanceof Node) return res as any;\n } catch (e) {\n console.error('[SwcIf] Portal target error:', e);\n }\n return null;\n }\n\n private _executeCallback(attrName: string, extraArgs: Record<string, any>) {\n const script = this.getAttribute(attrName);\n if (!script) return;\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });\n } catch (e) {\n console.error(`[SwcIf] Error in ${attrName}:`, e);\n }\n }\n\n @changedAttribute('on-get-value')\n private refresh(newValue?: string | null) {\n const script = newValue !== undefined ? newValue : this.getAttribute('on-get-value');\n if (!script) {\n this.value = null;\n return;\n }\n if (!this.parentElement) return;\n\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n const result = FunctionUtils.executeReturn({\n script,\n context: this,\n args: helperHostSet\n });\n this.value = result;\n } catch (e) {\n console.error('[SwcIf] Error in on-get-value:', e);\n this.value = null;\n }\n }\n\n private render() {\n this.cleanup();\n if (!this.parentElement) return;\n\n let fragment: DocumentFragment | null = null;\n const ctx: any = { $value: this._value, $nodes: [], $elements: [] };\n\n if (this._value) {\n const clone = this.content.cloneNode(true) as DocumentFragment;\n Array.from(clone.querySelectorAll('template[is=\"swc-default\"]')).forEach(t => t.remove());\n fragment = clone;\n } else {\n const t = this.content.querySelector('template[is=\"swc-default\"]') as HTMLTemplateElement;\n if (t) fragment = t.content.cloneNode(true) as DocumentFragment;\n }\n\n if (fragment) {\n this.mount(fragment, ctx);\n }\n }\n\n private mount(fragment: DocumentFragment, ctx: any) {\n const nodes = Array.from(fragment.childNodes);\n const elements = nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n\n Object.assign(ctx, {\n $nodes: nodes,\n $elements: elements,\n $firstNode: nodes[0],\n $lastNode: nodes[nodes.length - 1],\n $firstElement: elements[0],\n $lastElement: elements[elements.length - 1]\n });\n\n this._executeCallback('on-clone-nodes', ctx);\n nodes.forEach((node, nodeIndex) => {\n if (node instanceof HTMLElement) (node as any).__swc_host = this;\n this._executeCallback('on-clone-node', { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });\n });\n\n this._nodes = nodes;\n const target = this._getTarget();\n if (target) {\n target.appendChild(fragment);\n } else {\n this.parentElement?.insertBefore(fragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n if (n.parentElement) n.parentElement.removeChild(n);\n });\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8B;AAC9B,8BAAiC;AACjC,mBAAyB;AACzB,2BAA8B;;;;;;;;;;AAGvB,IAAM,QAAN,MAAMA,eAAc,oBAAmB;EAAvC,cAAA;;AACG,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EA6HxB;EA3HE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEQ,aAAU;AAChB,UAAM,SAAS,KAAK,aAAa,eAAe;AAChD,QAAI,CAAC;AAAQ,aAAO;AACpB,QAAI;AACF,YAAM,MAAM,mCAAc,cAAc;QACtC;QACA,SAAS;QACT,MAAM,sBAAS,oBAAoB,QAAQ,IAAI;OAChD;AACD,UAAI,OAAO,QAAQ;AAAU,eAAO,SAAS,cAAc,GAAG;AAC9D,UAAI,eAAe;AAAM,eAAO;IAClC,SAAS,GAAG;AACV,cAAQ,MAAM,gCAAgC,CAAC;IACjD;AACA,WAAO;E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AAQ;AAChD,UAAM,QAAQ,MAAM,KAAK,SAAS,UAAU;AAC5C,UAAM,WAAW,MAAM,OAAO,OAAK,EAAE,aAAa,CAAC;AAEnD,WAAO,OAAO,KAAK;MACjB,QAAQ;MACR,WAAW;MACX,YAAY,MAAM,CAAC;MACnB,WAAW,MAAM,MAAM,SAAS,CAAC;MACjC,eAAe,SAAS,CAAC;MACzB,cAAc,SAAS,SAAS,SAAS,CAAC;KAC3C;AAED,SAAK,iBAAiB,kBAAkB,GAAG;AAC3C,UAAM,QAAQ,CAAC,MAAM,cAAa;AAChC,UAAI,gBAAgB;AAAc,aAAa,aAAa;AAC5D,WAAK,iBAAiB,iBAAiB,EAAE,GAAG,KAAK,OAAO,MAAM,YAAY,WAAW,YAAY,KAAK,aAAa,EAAC,CAAE;IACxH,CAAC;AAED,SAAK,SAAS;AACd,UAAM,SAAS,KAAK,WAAU;AAC9B,QAAI,QAAQ;AACV,aAAO,YAAY,QAAQ;IAC7B,OAAO;AACL,WAAK,eAAe,aAAa,UAAU,KAAK,WAAW;IAC7D;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAI;AACtB,UAAI,EAAE;AAAe,UAAE,cAAc,YAAY,CAAC;IACpD,CAAC;AACD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AApFQ,WAAA;MADP,0CAAiB,cAAc;;;;;AAzCrB,QAAK,WAAA;MADjB,oCAAc,EAAE,MAAM,UAAU,SAAS,WAAU,CAAE;GACzC,KAAK;",
6
+ "names": ["SwcIf"]
7
+ }
@@ -0,0 +1,246 @@
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 SwcLoop_exports = {};
19
+ __export(SwcLoop_exports, {
20
+ SwcLoop: () => SwcLoop
21
+ });
22
+ module.exports = __toCommonJS(SwcLoop_exports);
23
+ var import_elementDefine = require("../decorators/elementDefine");
24
+ var import_changedAttribute = require("../decorators/changedAttribute");
25
+ var import_Utils = require("../utils/Utils");
26
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
27
+ var __decorate = function(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ };
33
+ var __metadata = function(k, v) {
34
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
+ };
36
+ let SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._value = [];
40
+ this._nodes = [];
41
+ this._defaultNodes = [];
42
+ }
43
+ get value() {
44
+ return this._value;
45
+ }
46
+ set value(nv) {
47
+ this._value = Array.isArray(nv) ? [...nv] : [];
48
+ this.render();
49
+ }
50
+ getNodes(index) {
51
+ return this._nodes[index] || null;
52
+ }
53
+ _getTarget() {
54
+ const script = this.getAttribute("on-get-portal");
55
+ if (!script)
56
+ return null;
57
+ try {
58
+ const res = import_FunctionUtils.FunctionUtils.executeReturn({
59
+ script,
60
+ context: this,
61
+ args: import_Utils.SwcUtils.getHelperAndHostSet(window, this)
62
+ });
63
+ if (typeof res === "string")
64
+ return document.querySelector(res);
65
+ if (res instanceof Node)
66
+ return res;
67
+ } catch (e) {
68
+ console.error("[SwcLoop] Portal target error:", e);
69
+ }
70
+ return null;
71
+ }
72
+ append(...items) {
73
+ if (!items.length || !this.parentElement)
74
+ return;
75
+ if (this._defaultNodes.length > 0)
76
+ this._cleanupDefault();
77
+ const fragment = document.createDocumentFragment();
78
+ const startIndex = this._value.length;
79
+ items.forEach((item, i) => {
80
+ const index = startIndex + i;
81
+ const nodes = this._createItemNodes(item, index);
82
+ if (nodes) {
83
+ this._nodes.push(nodes);
84
+ nodes.forEach((n) => fragment.appendChild(n));
85
+ this._value.push(item);
86
+ } else {
87
+ this._nodes.push(null);
88
+ this._value.push(null);
89
+ }
90
+ });
91
+ const target = this._getTarget();
92
+ if (target) {
93
+ target.appendChild(fragment);
94
+ } else {
95
+ const lastValidIdx = this._nodes.length - items.length - 1;
96
+ let refNode = this;
97
+ for (let i = lastValidIdx; i >= 0; i--) {
98
+ const group = this._nodes[i];
99
+ if (group && group.length > 0) {
100
+ refNode = group[group.length - 1];
101
+ break;
102
+ }
103
+ }
104
+ this.parentElement.insertBefore(fragment, refNode.nextSibling);
105
+ }
106
+ }
107
+ remove(index) {
108
+ const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
109
+ if (targetIdx < 0 || targetIdx >= this._nodes.length)
110
+ return;
111
+ const nodes = this._nodes[targetIdx];
112
+ if (nodes) {
113
+ nodes.forEach((n) => {
114
+ if (n.parentElement)
115
+ n.parentElement.removeChild(n);
116
+ });
117
+ this._nodes[targetIdx] = null;
118
+ this._value[targetIdx] = null;
119
+ }
120
+ const activeRows = this._value.filter((v) => v !== null);
121
+ if (activeRows.length === 0) {
122
+ this.render();
123
+ }
124
+ }
125
+ _createItemNodes(item, index) {
126
+ const clone = this.content.cloneNode(true);
127
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
128
+ const nodes = Array.from(clone.childNodes);
129
+ const elements = nodes.filter((n) => n.nodeType === 1);
130
+ const groupCtx = {
131
+ $index: index,
132
+ $item: item,
133
+ $nodes: nodes,
134
+ $elements: elements,
135
+ $firstNode: nodes[0],
136
+ $lastNode: nodes[nodes.length - 1],
137
+ $firstElement: elements[0],
138
+ $lastElement: elements[elements.length - 1],
139
+ $isFirst: index === 0,
140
+ $isLast: index === this._value.length - 1,
141
+ $isEven: index % 2 === 0,
142
+ $isOdd: index % 2 !== 0,
143
+ $count: this._value.length
144
+ };
145
+ this._executeCallback("on-clone-nodes", groupCtx);
146
+ nodes.forEach((node, nodeIndex) => {
147
+ if (node instanceof HTMLElement)
148
+ node.__swc_host = this;
149
+ this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
150
+ });
151
+ return nodes;
152
+ }
153
+ _executeCallback(attrName, extraArgs) {
154
+ const script = this.getAttribute(attrName);
155
+ if (!script)
156
+ return;
157
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
158
+ try {
159
+ import_FunctionUtils.FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
160
+ } catch (e) {
161
+ console.error(`[SwcLoop] Error in ${attrName}:`, e);
162
+ }
163
+ }
164
+ refreshValue(newValue) {
165
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
166
+ if (!script) {
167
+ this.value = [];
168
+ return;
169
+ }
170
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
171
+ try {
172
+ const res = import_FunctionUtils.FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
173
+ if (Array.isArray(res)) {
174
+ this.value = res;
175
+ }
176
+ } catch (e) {
177
+ console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
178
+ this.value = [];
179
+ }
180
+ }
181
+ render() {
182
+ this._cleanup();
183
+ if (!this.parentElement)
184
+ return;
185
+ const activeRows = this._value.filter((v) => v !== null);
186
+ const target = this._getTarget();
187
+ if (activeRows.length === 0) {
188
+ const t = this.content.querySelector('template[is="swc-default"]');
189
+ if (t) {
190
+ const clone = t.content.cloneNode(true);
191
+ this._defaultNodes = Array.from(clone.childNodes);
192
+ this._defaultNodes.forEach((n) => {
193
+ if (n instanceof HTMLElement)
194
+ n.__swc_host = this;
195
+ });
196
+ if (target)
197
+ target.appendChild(clone);
198
+ else
199
+ this.parentElement.insertBefore(clone, this.nextSibling);
200
+ }
201
+ return;
202
+ }
203
+ const fragment = document.createDocumentFragment();
204
+ this._value.forEach((item, index) => {
205
+ if (item === null) {
206
+ this._nodes.push(null);
207
+ return;
208
+ }
209
+ const nodes = this._createItemNodes(item, index);
210
+ this._nodes.push(nodes);
211
+ nodes.forEach((n) => fragment.appendChild(n));
212
+ });
213
+ if (target)
214
+ target.appendChild(fragment);
215
+ else
216
+ this.parentElement.insertBefore(fragment, this.nextSibling);
217
+ }
218
+ _cleanup() {
219
+ this._nodes.forEach((group) => {
220
+ if (group)
221
+ group.forEach((node) => node.parentElement?.removeChild(node));
222
+ });
223
+ this._nodes = [];
224
+ this._cleanupDefault();
225
+ }
226
+ _cleanupDefault() {
227
+ this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
228
+ this._defaultNodes = [];
229
+ }
230
+ connectedCallback() {
231
+ this.refreshValue();
232
+ }
233
+ disconnectedCallback() {
234
+ this._cleanup();
235
+ }
236
+ };
237
+ __decorate([
238
+ (0, import_changedAttribute.changedAttribute)("on-get-value"),
239
+ __metadata("design:type", Function),
240
+ __metadata("design:paramtypes", [String]),
241
+ __metadata("design:returntype", void 0)
242
+ ], SwcLoop.prototype, "refreshValue", null);
243
+ SwcLoop = __decorate([
244
+ (0, import_elementDefine.elementDefine)({ name: "swc-loop", extends: "template" })
245
+ ], SwcLoop);
246
+ //# sourceMappingURL=SwcLoop.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcLoop.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\nimport { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\n\n@elementDefine({ name: 'swc-loop', extends: 'template' })\nexport class SwcLoop extends HTMLTemplateElement {\n private _value: any[] = [];\n private _nodes: (Node[] | null)[] = [];\n private _defaultNodes: Node[] = [];\n\n get value(): any[] {\n return this._value;\n }\n\n set value(nv: any[]) {\n this._value = Array.isArray(nv) ? [...nv] : [];\n this.render();\n }\n\n getNodes(index: number): Node[] | null {\n return this._nodes[index] || null;\n }\n\n private _getTarget(): Element | DocumentFragment | null {\n const script = this.getAttribute('on-get-portal');\n if (!script) return null;\n try {\n const res = FunctionUtils.executeReturn({\n script,\n context: this,\n args: SwcUtils.getHelperAndHostSet(window, this)\n });\n if (typeof res === 'string') return document.querySelector(res);\n if (res instanceof Node) return res as any;\n } catch (e) {\n console.error('[SwcLoop] Portal target error:', e);\n }\n return null;\n }\n\n append(...items: any[]) {\n if (!items.length || !this.parentElement) return;\n if (this._defaultNodes.length > 0) this._cleanupDefault();\n\n const fragment = document.createDocumentFragment();\n const startIndex = this._value.length;\n\n items.forEach((item, i) => {\n const index = startIndex + i;\n const nodes = this._createItemNodes(item, index);\n if (nodes) {\n this._nodes.push(nodes);\n nodes.forEach(n => fragment.appendChild(n));\n this._value.push(item);\n } else {\n this._nodes.push(null);\n this._value.push(null);\n }\n });\n\n const target = this._getTarget();\n if (target) {\n target.appendChild(fragment);\n } else {\n const lastValidIdx = this._nodes.length - items.length - 1;\n let refNode: Node = this;\n for (let i = lastValidIdx; i >= 0; i--) {\n const group = this._nodes[i];\n if (group && group.length > 0) {\n refNode = group[group.length - 1];\n break;\n }\n }\n this.parentElement.insertBefore(fragment, refNode.nextSibling);\n }\n }\n\n remove(index?: number) {\n const targetIdx = index !== undefined ? index : this._nodes.length - 1;\n if (targetIdx < 0 || targetIdx >= this._nodes.length) return;\n\n const nodes = this._nodes[targetIdx];\n if (nodes) {\n nodes.forEach(n => {\n if (n.parentElement) n.parentElement.removeChild(n);\n });\n this._nodes[targetIdx] = null;\n this._value[targetIdx] = null;\n }\n\n const activeRows = this._value.filter(v => v !== null);\n if (activeRows.length === 0) {\n this.render();\n }\n }\n\n private _createItemNodes(item: any, index: number): Node[] {\n const clone = this.content.cloneNode(true) as DocumentFragment;\n Array.from(clone.querySelectorAll('template[is=\"swc-default\"]')).forEach(t => t.remove());\n\n const nodes = Array.from(clone.childNodes);\n const elements = nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n\n const groupCtx = {\n $index: index,\n $item: item,\n $nodes: nodes,\n $elements: elements,\n $firstNode: nodes[0],\n $lastNode: nodes[nodes.length - 1],\n $firstElement: elements[0],\n $lastElement: elements[elements.length - 1],\n $isFirst: index === 0,\n $isLast: index === this._value.length - 1,\n $isEven: index % 2 === 0,\n $isOdd: index % 2 !== 0,\n $count: this._value.length\n };\n\n this._executeCallback('on-clone-nodes', groupCtx);\n nodes.forEach((node, nodeIndex) => {\n if (node instanceof HTMLElement) (node as any).__swc_host = this;\n this._executeCallback('on-clone-node', { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });\n });\n\n return nodes;\n }\n\n private _executeCallback(attrName: string, extraArgs: Record<string, any>) {\n const script = this.getAttribute(attrName);\n if (!script) return;\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });\n } catch (e) {\n console.error(`[SwcLoop] Error in ${attrName}:`, e);\n }\n }\n\n @changedAttribute('on-get-value')\n private refreshValue(newValue?: string | null) {\n const script = newValue !== undefined ? newValue : this.getAttribute('on-get-value');\n if (!script) {\n this.value = [];\n return;\n }\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });\n if (Array.isArray(res)) {\n this.value = res;\n }\n } catch (e) {\n console.error('[SwcLoop] Failed to get value from on-get-value script:', e);\n this.value = [];\n }\n }\n\n render() {\n this._cleanup();\n if (!this.parentElement) return;\n\n const activeRows = this._value.filter(v => v !== null);\n const target = this._getTarget();\n\n if (activeRows.length === 0) {\n const t = this.content.querySelector('template[is=\"swc-default\"]') as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._defaultNodes = Array.from(clone.childNodes);\n this._defaultNodes.forEach(n => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n });\n if (target) target.appendChild(clone);\n else this.parentElement.insertBefore(clone, this.nextSibling);\n }\n return;\n }\n\n const fragment = document.createDocumentFragment();\n this._value.forEach((item, index) => {\n if (item === null) {\n this._nodes.push(null);\n return;\n }\n const nodes = this._createItemNodes(item, index);\n this._nodes.push(nodes);\n nodes.forEach(n => fragment.appendChild(n));\n });\n\n if (target) target.appendChild(fragment);\n else this.parentElement.insertBefore(fragment, this.nextSibling);\n }\n\n private _cleanup() {\n this._nodes.forEach(group => {\n if (group) group.forEach(node => node.parentElement?.removeChild(node));\n });\n this._nodes = [];\n this._cleanupDefault();\n }\n\n private _cleanupDefault() {\n this._defaultNodes.forEach(n => n.parentElement?.removeChild(n));\n this._defaultNodes = [];\n }\n\n connectedCallback() {\n this.refreshValue();\n }\n disconnectedCallback() {\n this._cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8B;AAC9B,8BAAiC;AACjC,mBAAyB;AACzB,2BAA8B;;;;;;;;;;AAGvB,IAAM,UAAN,MAAMA,iBAAgB,oBAAmB;EAAzC,cAAA;;AACG,SAAA,SAAgB,CAAA;AAChB,SAAA,SAA4B,CAAA;AAC5B,SAAA,gBAAwB,CAAA;EA6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
+ 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 SwcSubTemplates_exports = {};
19
+ __export(SwcSubTemplates_exports, {
20
+ SwcDefault: () => SwcDefault,
21
+ SwcError: () => SwcError,
22
+ SwcLoading: () => SwcLoading,
23
+ SwcOtherwise: () => SwcOtherwise,
24
+ SwcSuccess: () => SwcSuccess,
25
+ SwcWhen: () => SwcWhen
26
+ });
27
+ module.exports = __toCommonJS(SwcSubTemplates_exports);
28
+ var import_elementDefine = require("../decorators/elementDefine");
29
+ var __decorate = function(decorators, target, key, desc) {
30
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
34
+ };
35
+ let SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
36
+ };
37
+ SwcLoading = __decorate([
38
+ (0, import_elementDefine.elementDefine)({ name: "swc-loading", extends: "template" })
39
+ ], SwcLoading);
40
+ let SwcError = class SwcError2 extends HTMLTemplateElement {
41
+ };
42
+ SwcError = __decorate([
43
+ (0, import_elementDefine.elementDefine)({ name: "swc-error", extends: "template" })
44
+ ], SwcError);
45
+ let SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
46
+ };
47
+ SwcSuccess = __decorate([
48
+ (0, import_elementDefine.elementDefine)({ name: "swc-success", extends: "template" })
49
+ ], SwcSuccess);
50
+ let SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
51
+ };
52
+ SwcWhen = __decorate([
53
+ (0, import_elementDefine.elementDefine)({ name: "swc-when", extends: "template" })
54
+ ], SwcWhen);
55
+ let SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
56
+ };
57
+ SwcOtherwise = __decorate([
58
+ (0, import_elementDefine.elementDefine)({ name: "swc-otherwise", extends: "template" })
59
+ ], SwcOtherwise);
60
+ let SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
61
+ };
62
+ SwcDefault = __decorate([
63
+ (0, import_elementDefine.elementDefine)({ name: "swc-default", extends: "template" })
64
+ ], SwcDefault);
65
+ //# sourceMappingURL=SwcSubTemplates.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcSubTemplates.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\n\n@elementDefine({ name: 'swc-loading', extends: 'template' })\nexport class SwcLoading extends HTMLTemplateElement {}\n\n@elementDefine({ name: 'swc-error', extends: 'template' })\nexport class SwcError extends HTMLTemplateElement {}\n\n@elementDefine({ name: 'swc-success', extends: 'template' })\nexport class SwcSuccess extends HTMLTemplateElement {}\n\n@elementDefine({ name: 'swc-when', extends: 'template' })\nexport class SwcWhen extends HTMLTemplateElement {}\n\n@elementDefine({ name: 'swc-otherwise', extends: 'template' })\nexport class SwcOtherwise extends HTMLTemplateElement {}\n\n@elementDefine({ name: 'swc-default', extends: 'template' })\nexport class SwcDefault extends HTMLTemplateElement {}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8B;;;;;;;AAGvB,IAAM,aAAN,MAAMA,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;MADtB,oCAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;AAGhB,IAAM,WAAN,MAAMC,kBAAiB,oBAAmB;;AAApC,WAAQ,WAAA;MADpB,oCAAc,EAAE,MAAM,aAAa,SAAS,WAAU,CAAE;GAC5C,QAAQ;AAGd,IAAM,aAAN,MAAMC,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;MADtB,oCAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;AAGhB,IAAM,UAAN,MAAMC,iBAAgB,oBAAmB;;AAAnC,UAAO,WAAA;MADnB,oCAAc,EAAE,MAAM,YAAY,SAAS,WAAU,CAAE;GAC3C,OAAO;AAGb,IAAM,eAAN,MAAMC,sBAAqB,oBAAmB;;AAAxC,eAAY,WAAA;MADxB,oCAAc,EAAE,MAAM,iBAAiB,SAAS,WAAU,CAAE;GAChD,YAAY;AAGlB,IAAM,aAAN,MAAMC,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;MADtB,oCAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;",
6
+ "names": ["SwcLoading", "SwcError", "SwcSuccess", "SwcWhen", "SwcOtherwise", "SwcDefault"]
7
+ }
@@ -15,4 +15,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
15
  var elements_exports = {};
16
16
  module.exports = __toCommonJS(elements_exports);
17
17
  __reExport(elements_exports, require("./is"), module.exports);
18
+ __reExport(elements_exports, require("./SwcSubTemplates"), module.exports);
19
+ __reExport(elements_exports, require("./SwcLoop"), module.exports);
20
+ __reExport(elements_exports, require("./SwcIf"), module.exports);
21
+ __reExport(elements_exports, require("./SwcChoose"), module.exports);
22
+ __reExport(elements_exports, require("./SwcAsync"), module.exports);
23
+ __reExport(elements_exports, require("./SwcApp"), module.exports);
24
+ __reExport(elements_exports, require("./SwcAppEngine"), module.exports);
18
25
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/index.ts"],
4
- "sourcesContent": ["// import {SwcHTMLElement} from \"./SwcHTMLElement\";\n\nexport * from './is'"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAEA,6BAAc,iBAFd;",
4
+ "sourcesContent": ["export * from './is';\nexport * from './SwcSubTemplates';\nexport * from './SwcLoop';\nexport * from './SwcIf';\nexport * from './SwcChoose';\nexport * from './SwcAsync';\nexport * from './SwcApp';\nexport * from './SwcAppEngine';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,iBAAd;AACA,6BAAc,8BADd;AAEA,6BAAc,sBAFd;AAGA,6BAAc,oBAHd;AAIA,6BAAc,wBAJd;AAKA,6BAAc,uBALd;AAMA,6BAAc,qBANd;AAOA,6BAAc,2BAPd;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -25,6 +25,6 @@ __reExport(src_exports, require("./decorators/query"), module.exports);
25
25
  __reExport(src_exports, require("./decorators/queryAll"), module.exports);
26
26
  __reExport(src_exports, require("./decorators/addEventListener"), module.exports);
27
27
  __reExport(src_exports, require("./types"), module.exports);
28
- __reExport(src_exports, require("./elements/is"), module.exports);
28
+ __reExport(src_exports, require("./elements"), module.exports);
29
29
  __reExport(src_exports, require("./utils/Utils"), module.exports);
30
30
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import 'reflect-metadata';\n\n// Decorators\nexport * from './decorators/elementDefine';\nexport * from './decorators/setAttribute';\nexport * from './decorators/changedAttribute';\nexport * from './decorators/innerHtml';\nexport * from './decorators/emitCustomEvent';\nexport * from './decorators/lifecycles';\nexport * from './decorators/query';\nexport * from './decorators/queryAll';\nexport * from './decorators/addEventListener';\n\n// Types\nexport * from './types';\n\n// Apps (Customized Built-in Elements)\nexport * from './elements/is';\n\n// Utilities\nexport * from './utils/Utils';\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAO;AAGP,wBAAc,uCAHd;AAIA,wBAAc,sCAJd;AAKA,wBAAc,0CALd;AAMA,wBAAc,mCANd;AAOA,wBAAc,yCAPd;AAQA,wBAAc,oCARd;AASA,wBAAc,+BATd;AAUA,wBAAc,kCAVd;AAWA,wBAAc,0CAXd;AAcA,wBAAc,oBAdd;AAiBA,wBAAc,0BAjBd;AAoBA,wBAAc,0BApBd;",
4
+ "sourcesContent": ["import 'reflect-metadata';\n\n// Decorators\nexport * from './decorators/elementDefine';\nexport * from './decorators/setAttribute';\nexport * from './decorators/changedAttribute';\nexport * from './decorators/innerHtml';\nexport * from './decorators/emitCustomEvent';\nexport * from './decorators/lifecycles';\nexport * from './decorators/query';\nexport * from './decorators/queryAll';\nexport * from './decorators/addEventListener';\n\n// Types\nexport * from './types';\n\n// Apps (Customized Built-in Elements)\nexport * from './elements';\n\n// Utilities\nexport * from './utils/Utils';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAO;AAGP,wBAAc,uCAHd;AAIA,wBAAc,sCAJd;AAKA,wBAAc,0CALd;AAMA,wBAAc,mCANd;AAOA,wBAAc,yCAPd;AAQA,wBAAc,oCARd;AASA,wBAAc,+BATd;AAUA,wBAAc,kCAVd;AAWA,wBAAc,0CAXd;AAcA,wBAAc,oBAdd;AAiBA,wBAAc,uBAjBd;AAoBA,wBAAc,0BApBd;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/types.ts"],
4
- "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { Router } from '@dooboostore/core-web/routers/Router';\n\nexport enum InjectSituationType {\n HOST_SET = 'SIMPLE_WEB_COMPONENT://HOSTSET',\n APP_HOST = 'SIMPLE_WEB_COMPONENT://APPHOST',\n APP_HOSTS = 'SIMPLE_WEB_COMPONENT://APPHOSTS',\n HOST = 'SIMPLE_WEB_COMPONENT://HOST',\n PARENT_HOST = 'SIMPLE_WEB_COMPONENT://PARENTHOST',\n HOSTS = 'SIMPLE_WEB_COMPONENT://HOSTS',\n FIRST_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTHOST',\n LAST_HOST = 'SIMPLE_WEB_COMPONENT://LASTHOST',\n FIRST_APP_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTAPPHOST',\n LAST_APP_HOST = 'SIMPLE_WEB_COMPONENT://LASTAPPHOST'\n}\n\nexport type HostSet = {\n $host: HTMLElement; // Current component itself\n $parentHost: HTMLElement | null; // Nearest parent SWC component\n $hosts: HTMLElement[]; // [self, parent, ..., top]\n $firstHost: HTMLElement | null; // Top-most SWC ancestor\n $lastHost: HTMLElement | null; // Same as $parentHost (for backward compatibility or clarity)\n $appHost: SwcAppInterface | null;\n $appHosts: SwcAppInterface[];\n $firstAppHost: SwcAppInterface | null;\n $lastAppHost: SwcAppInterface | null;\n};\n\nexport interface SwcAppInterface extends HTMLElement {\n simpleApplication?: SimpleApplication;\n router?: Router;\n routing(path: string): Promise<void>;\n}\n"],
4
+ "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { Router } from '@dooboostore/core-web/routers/Router';\n\nexport enum InjectSituationType {\n HOST_SET = 'SIMPLE_WEB_COMPONENT://HOSTSET',\n APP_HOST = 'SIMPLE_WEB_COMPONENT://APPHOST',\n APP_HOSTS = 'SIMPLE_WEB_COMPONENT://APPHOSTS',\n HOST = 'SIMPLE_WEB_COMPONENT://HOST',\n PARENT_HOST = 'SIMPLE_WEB_COMPONENT://PARENTHOST',\n HOSTS = 'SIMPLE_WEB_COMPONENT://HOSTS',\n FIRST_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTHOST',\n LAST_HOST = 'SIMPLE_WEB_COMPONENT://LASTHOST',\n FIRST_APP_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTAPPHOST',\n LAST_APP_HOST = 'SIMPLE_WEB_COMPONENT://LASTAPPHOST'\n}\nexport type HelperSet = {\n $d: Document;\n $w: Window;\n $q: (selector: string, root?: Element | Document | ShadowRoot) => HTMLElement | null;\n $qa: (selector: string, root?: Element | Document | ShadowRoot) => HTMLElement[];\n $qi: (selector: string, root?: Element | Document | ShadowRoot) => HTMLElement | null;\n}\nexport type HostSet = {\n $host: HTMLElement; // Current component itself\n $parentHost: HTMLElement | null; // Nearest parent SWC component\n $hosts: HTMLElement[]; // [self, parent, ..., top]\n $firstHost: HTMLElement | null; // Top-most SWC ancestor\n $lastHost: HTMLElement | null; // Same as $parentHost (for backward compatibility or clarity)\n $appHost: SwcAppInterface | null;\n $appHosts: SwcAppInterface[];\n $firstAppHost: SwcAppInterface | null;\n $lastAppHost: SwcAppInterface | null;\n};\n\nexport type HelperHostSet = HelperSet & HostSet;\n\nexport interface SwcAppInterface extends HTMLElement {\n simpleApplication?: SimpleApplication;\n router?: Router;\n routing(path: string): Promise<void>;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAK,sBAAL,kBAAKA,yBAAL;AACL,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,UAAO;AACP,EAAAA,qBAAA,iBAAc;AACd,EAAAA,qBAAA,WAAQ;AACR,EAAAA,qBAAA,gBAAa;AACb,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,oBAAiB;AACjB,EAAAA,qBAAA,mBAAgB;AAVN,SAAAA;AAAA,GAAA;",
6
6
  "names": ["InjectSituationType"]
7
7
  }
@@ -23,8 +23,27 @@ __export(Utils_exports, {
23
23
  module.exports = __toCommonJS(Utils_exports);
24
24
  var import_elementDefine = require("../decorators/elementDefine");
25
25
  const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
26
- class SwcUtils {
27
- static getValueByPath(obj, path, rootName) {
26
+ var SwcUtils;
27
+ ((SwcUtils2) => {
28
+ SwcUtils2.getHelperSet = (win) => {
29
+ const doc = win.document;
30
+ return {
31
+ $d: doc,
32
+ $w: win,
33
+ $q: (sel, root) => (root ?? doc).querySelector(sel),
34
+ $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
35
+ $qi: (id, root) => (root ?? doc).getElementById(id)
36
+ };
37
+ };
38
+ SwcUtils2.getHelperAndHostSet = (win, el) => {
39
+ const helperSet = (0, SwcUtils2.getHelperSet)(win);
40
+ const hostSet = (0, SwcUtils2.getHostSet)(el);
41
+ return {
42
+ ...helperSet,
43
+ ...hostSet
44
+ };
45
+ };
46
+ SwcUtils2.getValueByPath = (obj, path, rootName) => {
28
47
  if (!obj || !path) return SWC_NOT_FOUND;
29
48
  const parts = path.split(".");
30
49
  let current = obj;
@@ -33,49 +52,66 @@ class SwcUtils {
33
52
  current = current[part];
34
53
  }
35
54
  return current;
36
- }
37
- static findNearestSwcHost(el) {
38
- let current = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
39
- current = current?.parentElement || current?.getRootNode()?.host;
40
- while (current) {
55
+ };
56
+ SwcUtils2.findNearestSwcHost = (el) => {
57
+ if (el.__swc_host) return el.__swc_host;
58
+ let current = el.parentElement || el.getRootNode?.()?.host;
59
+ while (current && current !== document && current !== window) {
60
+ if (current.__swc_host) return current.__swc_host;
41
61
  if ((0, import_elementDefine.getElementConfig)(current)) return current;
42
- current = current.parentElement || current?.getRootNode()?.host;
62
+ current = current.parentElement || current.getRootNode?.()?.host;
43
63
  }
44
64
  return void 0;
45
- }
46
- /**
47
- * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
48
- */
49
- static findAllSwcHosts(el) {
65
+ };
66
+ SwcUtils2.findAllSwcHosts = (el) => {
50
67
  const hosts = [];
51
- let current = this.findNearestSwcHost(el);
68
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
52
69
  while (current) {
53
70
  hosts.push(current);
54
- current = this.findNearestSwcHost(current);
71
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
55
72
  }
56
73
  return hosts.reverse();
57
- }
58
- static getHosts(el) {
59
- return [...this.findAllSwcHosts(el), el];
60
- }
61
- static getHost(el) {
62
- return el;
63
- }
64
- static getAppHosts(el) {
65
- const hosts = this.getHosts(el);
74
+ };
75
+ SwcUtils2.getHosts = (el) => {
76
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
77
+ if ((0, import_elementDefine.getElementConfig)(el)) return [...ancestors, el];
78
+ return ancestors;
79
+ };
80
+ SwcUtils2.getHost = (el) => {
81
+ if ((0, import_elementDefine.getElementConfig)(el)) return el;
82
+ return (0, SwcUtils2.findNearestSwcHost)(el);
83
+ };
84
+ SwcUtils2.getAppHosts = (el) => {
85
+ const hosts = (0, SwcUtils2.getHosts)(el);
66
86
  return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
67
- }
68
- static getAppHost(el) {
69
- const appHosts = this.getAppHosts(el);
87
+ };
88
+ SwcUtils2.getAppHost = (el) => {
89
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
70
90
  const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
71
91
  return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
72
- }
73
- static getHostSet(el) {
74
- const ancestors = this.findAllSwcHosts(el);
75
- const $host = el;
76
- const $hosts = [...ancestors, $host];
77
- const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
78
- const $firstHost = ancestors.length > 0 ? ancestors[0] : null;
92
+ };
93
+ SwcUtils2.getHostSet = (el) => {
94
+ const isSwc = !!(0, import_elementDefine.getElementConfig)(el);
95
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
96
+ let $host;
97
+ let $parentHost;
98
+ if (isSwc) {
99
+ $host = el;
100
+ $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
101
+ } else {
102
+ $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
103
+ $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
104
+ }
105
+ const $hosts = isSwc ? [...ancestors, el] : ancestors;
106
+ const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
107
+ const loopContext = {};
108
+ let curr = el;
109
+ while (curr && curr !== document.documentElement) {
110
+ if (curr.__swc_loop_context) {
111
+ Object.assign(loopContext, curr.__swc_loop_context);
112
+ }
113
+ curr = curr.parentElement || curr.getRootNode().host;
114
+ }
79
115
  const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
80
116
  const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
81
117
  const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
@@ -88,8 +124,9 @@ class SwcUtils {
88
124
  $appHost,
89
125
  $appHosts,
90
126
  $firstAppHost,
91
- $lastAppHost: $appHost
127
+ $lastAppHost: $appHost,
128
+ ...loopContext
92
129
  };
93
- }
94
- }
130
+ };
131
+ })(SwcUtils || (SwcUtils = {}));
95
132
  //# sourceMappingURL=Utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/Utils.ts"],
4
- "sourcesContent": ["import { SwcAppInterface, HostSet } from '../types';\nimport { getElementConfig } from '../decorators/elementDefine';\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport class SwcUtils {\n static getValueByPath(obj: any, path: string, rootName: string) {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n }\n\n static findNearestSwcHost(el: HTMLElement | Node): HTMLElement | undefined {\n let current: any = el instanceof Node && !(el instanceof HTMLElement) ? (el as any).host : el;\n current = current?.parentElement || (current?.getRootNode() as any)?.host;\n\n while (current) {\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current?.getRootNode() as any)?.host;\n }\n return undefined;\n }\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n static findAllSwcHosts(el: HTMLElement | Node): HTMLElement[] {\n const hosts: HTMLElement[] = [];\n let current = this.findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n current = this.findNearestSwcHost(current);\n }\n return hosts.reverse();\n }\n\n static getHosts(el: HTMLElement): HTMLElement[] {\n return [...this.findAllSwcHosts(el), el];\n }\n\n static getHost(el: HTMLElement): HTMLElement | undefined {\n return el;\n }\n\n static getAppHosts(el: HTMLElement): SwcAppInterface[] {\n const hosts = this.getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n }\n\n static getAppHost(el: HTMLElement): SwcAppInterface | undefined {\n const appHosts = this.getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n // Nearest app host is the last one in [root, ..., parent]\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n }\n\n static getHostSet(el: HTMLElement): HostSet {\n const ancestors = this.findAllSwcHosts(el); // [root, ..., parent]\n const $host = el;\n const $hosts = [...ancestors, $host]; // [root, ..., parent, self]\n const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n const $firstHost = ancestors.length > 0 ? ancestors[0] : null;\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost\n };\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAiC;AAE1B,MAAM,gBAAgB,OAAO,eAAe;AAE5C,MAAM,SAAS;AAAA,EACpB,OAAO,eAAe,KAAU,MAAc,UAAkB;AAC9D,QAAI,CAAC,OAAO,CAAC,KAAM,QAAO;AAE1B,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,QAAI,UAAU;AAEd,eAAW,QAAQ,OAAO;AACxB,UAAI,YAAY,QAAQ,YAAY,OAAW,QAAO;AACtD,gBAAU,QAAQ,IAAI;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,mBAAmB,IAAiD;AACzE,QAAI,UAAe,cAAc,QAAQ,EAAE,cAAc,eAAgB,GAAW,OAAO;AAC3F,cAAU,SAAS,iBAAkB,SAAS,YAAY,GAAW;AAErE,WAAO,SAAS;AACd,cAAI,uCAAiB,OAAO,EAAG,QAAO;AACtC,gBAAU,QAAQ,iBAAkB,SAAS,YAAY,GAAW;AAAA,IACtE;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,gBAAgB,IAAuC;AAC5D,UAAM,QAAuB,CAAC;AAC9B,QAAI,UAAU,KAAK,mBAAmB,EAAE;AACxC,WAAO,SAAS;AACd,YAAM,KAAK,OAAO;AAClB,gBAAU,KAAK,mBAAmB,OAAO;AAAA,IAC3C;AACA,WAAO,MAAM,QAAQ;AAAA,EACvB;AAAA,EAEA,OAAO,SAAS,IAAgC;AAC9C,WAAO,CAAC,GAAG,KAAK,gBA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["import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';\nimport { getElementConfig } from '../decorators/elementDefine';\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport namespace SwcUtils {\n export const getHelperSet = (win: Window): HelperSet => {\n const doc: Document = win.document;\n return {\n $d: doc,\n $w: win,\n $q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),\n $qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],\n $qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement\n } as const;\n };\n\n export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {\n const helperSet = getHelperSet(win);\n const hostSet = getHostSet(el);\n return {\n ...helperSet,\n ...hostSet\n };\n };\n\n export const getValueByPath = (obj: any, path: string, rootName: string) => {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n };\n\n /**\n * Finds the nearest logical SWC host for an element.\n * Checks __swc_host property first, then climbs the DOM tree.\n */\n export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {\n if ((el as any).__swc_host) return (el as any).__swc_host;\n\n let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;\n while (current && current !== document && current !== window) {\n if (current.__swc_host) return current.__swc_host;\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current.getRootNode?.() as any)?.host;\n }\n return undefined;\n };\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {\n const hosts: HTMLElement[] = [];\n let current = findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n // To find the next ancestor, we must start searching from the PARENT of the found host\n current = findNearestSwcHost(current);\n }\n return hosts.reverse();\n };\n\n export const getHosts = (el: HTMLElement): HTMLElement[] => {\n const ancestors = findAllSwcHosts(el);\n if (getElementConfig(el)) return [...ancestors, el];\n return ancestors;\n };\n\n export const getHost = (el: HTMLElement): HTMLElement | undefined => {\n if (getElementConfig(el)) return el;\n return findNearestSwcHost(el);\n };\n\n export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {\n const hosts = getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n };\n\n export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {\n const appHosts = getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n };\n\n export const getHostSet = (el: HTMLElement): HostSet => {\n const isSwc = !!getElementConfig(el);\n const ancestors = findAllSwcHosts(el); // [root, ..., parent]\n\n let $host: HTMLElement;\n let $parentHost: HTMLElement | null;\n\n if (isSwc) {\n $host = el;\n $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n } else {\n $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;\n $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;\n }\n\n const $hosts = isSwc ? [...ancestors, el] : ancestors;\n const $firstHost = $hosts.length > 0 ? $hosts[0] : null;\n\n // Collect loop contexts\n const loopContext: Record<string, any> = {};\n let curr: any = el;\n while (curr && curr !== document.documentElement) {\n if (curr.__swc_loop_context) {\n Object.assign(loopContext, curr.__swc_loop_context);\n }\n curr = curr.parentElement || (curr.getRootNode() as any).host;\n }\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost,\n ...loopContext\n } as any;\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAiC;AAE1B,MAAM,gBAAgB,OAAO,eAAe;AAE5C,IAAU;AAAA,CAAV,CAAUA,cAAV;AACE,EAAMA,UAAA,eAAe,CAAC,QAA2B;AACtD,UAAM,MAAgB,IAAI;AAC1B,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI,CAAC,KAAa,UAA4C,QAAQ,KAAK,cAAc,GAAG;AAAA,MAC5F,KAAK,CAAC,KAAa,SAA2C,MAAM,MAAM,QAAQ,KAAK,iBAAiB,GAAG,CAAC;AAAA,MAC5G,KAAK,CAAC,IAAY,UAAkC,QAAQ,KAAK,eAAe,EAAE;AAAA,IACpF;AAAA,EACF;AAEO,EAAMA,UAAA,sBAAsB,CAAC,KAAa,OAAmC;AAClF,UAAM,gBAAYA,UAAA,cAAa,GAAG;AAClC,UAAM,cAAUA,UAAA,YAAW,EAAE;AAC7B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AAEO,EAAMA,UAAA,iBAAiB,CAAC,KAAU,MAAc,aAAqB;AAC1E,QAAI,CAAC,OAAO,CAAC,KAAM,QAAO;AAE1B,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,QAAI,UAAU;AAEd,eAAW,QAAQ,OAAO;AACxB,UAAI,YAAY,QAAQ,YAAY,OAAW,QAAO;AACtD,gBAAU,QAAQ,IAAI;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AAMO,EAAMA,UAAA,qBAAqB,CAAC,OAAoD;AACrF,QAAK,GAAW,WAAY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