@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.
- package/README.md +93 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +133 -62
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/query.js +22 -0
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +14 -0
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +2 -1
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +188 -0
- package/dist/cjs/elements/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/SwcChoose.js +155 -0
- package/dist/cjs/elements/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/SwcIf.js +167 -0
- package/dist/cjs/elements/SwcIf.js.map +7 -0
- package/dist/cjs/elements/SwcLoop.js +246 -0
- package/dist/cjs/elements/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/SwcSubTemplates.js +65 -0
- package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/index.js +7 -0
- package/dist/cjs/elements/index.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +74 -37
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +133 -62
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/query.js +22 -0
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +14 -0
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +2 -1
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +169 -0
- package/dist/esm/elements/SwcAsync.js.map +7 -0
- package/dist/esm/elements/SwcChoose.js +136 -0
- package/dist/esm/elements/SwcChoose.js.map +7 -0
- package/dist/esm/elements/SwcIf.js +148 -0
- package/dist/esm/elements/SwcIf.js.map +7 -0
- package/dist/esm/elements/SwcLoop.js +227 -0
- package/dist/esm/elements/SwcLoop.js.map +7 -0
- package/dist/esm/elements/SwcSubTemplates.js +46 -0
- package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/index.js +7 -0
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +74 -37
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1047 -140
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +1 -0
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +0 -2
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +0 -2
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +16 -0
- package/dist/types/elements/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/SwcChoose.d.ts +13 -0
- package/dist/types/elements/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/SwcIf.d.ts +15 -0
- package/dist/types/elements/SwcIf.d.ts.map +1 -0
- package/dist/types/elements/SwcLoop.d.ts +20 -0
- package/dist/types/elements/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +7 -0
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +16 -10
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1047 -140
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +1 -0
- package/src/decorators/elementDefine.ts +137 -66
- package/src/decorators/query.ts +20 -2
- package/src/decorators/queryAll.ts +16 -2
- package/src/elements/SwcAppEngine.ts +2 -1
- package/src/elements/SwcAsync.ts +163 -0
- package/src/elements/SwcChoose.ts +127 -0
- package/src/elements/SwcIf.ts +134 -0
- package/src/elements/SwcLoop.ts +215 -0
- package/src/elements/SwcSubTemplates.ts +19 -0
- package/src/elements/index.ts +8 -3
- package/src/index.ts +1 -1
- package/src/types.ts +9 -1
- package/src/utils/Utils.ts +86 -36
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefine } from "../decorators/elementDefine.js";
|
|
11
|
+
import { changedAttribute } from "../decorators/changedAttribute.js";
|
|
12
|
+
import { SwcUtils } from "../utils/Utils.js";
|
|
13
|
+
import { FunctionUtils } from "@dooboostore/core/function/FunctionUtils";
|
|
14
|
+
let SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this._value = [];
|
|
18
|
+
this._nodes = [];
|
|
19
|
+
this._defaultNodes = [];
|
|
20
|
+
}
|
|
21
|
+
get value() {
|
|
22
|
+
return this._value;
|
|
23
|
+
}
|
|
24
|
+
set value(nv) {
|
|
25
|
+
this._value = Array.isArray(nv) ? [...nv] : [];
|
|
26
|
+
this.render();
|
|
27
|
+
}
|
|
28
|
+
getNodes(index) {
|
|
29
|
+
return this._nodes[index] || null;
|
|
30
|
+
}
|
|
31
|
+
_getTarget() {
|
|
32
|
+
const script = this.getAttribute("on-get-portal");
|
|
33
|
+
if (!script)
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
const res = FunctionUtils.executeReturn({
|
|
37
|
+
script,
|
|
38
|
+
context: this,
|
|
39
|
+
args: SwcUtils.getHelperAndHostSet(window, this)
|
|
40
|
+
});
|
|
41
|
+
if (typeof res === "string")
|
|
42
|
+
return document.querySelector(res);
|
|
43
|
+
if (res instanceof Node)
|
|
44
|
+
return res;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error("[SwcLoop] Portal target error:", e);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
append(...items) {
|
|
51
|
+
if (!items.length || !this.parentElement)
|
|
52
|
+
return;
|
|
53
|
+
if (this._defaultNodes.length > 0)
|
|
54
|
+
this._cleanupDefault();
|
|
55
|
+
const fragment = document.createDocumentFragment();
|
|
56
|
+
const startIndex = this._value.length;
|
|
57
|
+
items.forEach((item, i) => {
|
|
58
|
+
const index = startIndex + i;
|
|
59
|
+
const nodes = this._createItemNodes(item, index);
|
|
60
|
+
if (nodes) {
|
|
61
|
+
this._nodes.push(nodes);
|
|
62
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
63
|
+
this._value.push(item);
|
|
64
|
+
} else {
|
|
65
|
+
this._nodes.push(null);
|
|
66
|
+
this._value.push(null);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const target = this._getTarget();
|
|
70
|
+
if (target) {
|
|
71
|
+
target.appendChild(fragment);
|
|
72
|
+
} else {
|
|
73
|
+
const lastValidIdx = this._nodes.length - items.length - 1;
|
|
74
|
+
let refNode = this;
|
|
75
|
+
for (let i = lastValidIdx; i >= 0; i--) {
|
|
76
|
+
const group = this._nodes[i];
|
|
77
|
+
if (group && group.length > 0) {
|
|
78
|
+
refNode = group[group.length - 1];
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.parentElement.insertBefore(fragment, refNode.nextSibling);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
remove(index) {
|
|
86
|
+
const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
|
|
87
|
+
if (targetIdx < 0 || targetIdx >= this._nodes.length)
|
|
88
|
+
return;
|
|
89
|
+
const nodes = this._nodes[targetIdx];
|
|
90
|
+
if (nodes) {
|
|
91
|
+
nodes.forEach((n) => {
|
|
92
|
+
if (n.parentElement)
|
|
93
|
+
n.parentElement.removeChild(n);
|
|
94
|
+
});
|
|
95
|
+
this._nodes[targetIdx] = null;
|
|
96
|
+
this._value[targetIdx] = null;
|
|
97
|
+
}
|
|
98
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
99
|
+
if (activeRows.length === 0) {
|
|
100
|
+
this.render();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
_createItemNodes(item, index) {
|
|
104
|
+
const clone = this.content.cloneNode(true);
|
|
105
|
+
Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
|
|
106
|
+
const nodes = Array.from(clone.childNodes);
|
|
107
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
108
|
+
const groupCtx = {
|
|
109
|
+
$index: index,
|
|
110
|
+
$item: item,
|
|
111
|
+
$nodes: nodes,
|
|
112
|
+
$elements: elements,
|
|
113
|
+
$firstNode: nodes[0],
|
|
114
|
+
$lastNode: nodes[nodes.length - 1],
|
|
115
|
+
$firstElement: elements[0],
|
|
116
|
+
$lastElement: elements[elements.length - 1],
|
|
117
|
+
$isFirst: index === 0,
|
|
118
|
+
$isLast: index === this._value.length - 1,
|
|
119
|
+
$isEven: index % 2 === 0,
|
|
120
|
+
$isOdd: index % 2 !== 0,
|
|
121
|
+
$count: this._value.length
|
|
122
|
+
};
|
|
123
|
+
this._executeCallback("on-clone-nodes", groupCtx);
|
|
124
|
+
nodes.forEach((node, nodeIndex) => {
|
|
125
|
+
if (node instanceof HTMLElement)
|
|
126
|
+
node.__swc_host = this;
|
|
127
|
+
this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
|
|
128
|
+
});
|
|
129
|
+
return nodes;
|
|
130
|
+
}
|
|
131
|
+
_executeCallback(attrName, extraArgs) {
|
|
132
|
+
const script = this.getAttribute(attrName);
|
|
133
|
+
if (!script)
|
|
134
|
+
return;
|
|
135
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
136
|
+
try {
|
|
137
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
138
|
+
} catch (e) {
|
|
139
|
+
console.error(`[SwcLoop] Error in ${attrName}:`, e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
refreshValue(newValue) {
|
|
143
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
144
|
+
if (!script) {
|
|
145
|
+
this.value = [];
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
149
|
+
try {
|
|
150
|
+
const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
|
|
151
|
+
if (Array.isArray(res)) {
|
|
152
|
+
this.value = res;
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
|
|
156
|
+
this.value = [];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
render() {
|
|
160
|
+
this._cleanup();
|
|
161
|
+
if (!this.parentElement)
|
|
162
|
+
return;
|
|
163
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
164
|
+
const target = this._getTarget();
|
|
165
|
+
if (activeRows.length === 0) {
|
|
166
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
167
|
+
if (t) {
|
|
168
|
+
const clone = t.content.cloneNode(true);
|
|
169
|
+
this._defaultNodes = Array.from(clone.childNodes);
|
|
170
|
+
this._defaultNodes.forEach((n) => {
|
|
171
|
+
if (n instanceof HTMLElement)
|
|
172
|
+
n.__swc_host = this;
|
|
173
|
+
});
|
|
174
|
+
if (target)
|
|
175
|
+
target.appendChild(clone);
|
|
176
|
+
else
|
|
177
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const fragment = document.createDocumentFragment();
|
|
182
|
+
this._value.forEach((item, index) => {
|
|
183
|
+
if (item === null) {
|
|
184
|
+
this._nodes.push(null);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const nodes = this._createItemNodes(item, index);
|
|
188
|
+
this._nodes.push(nodes);
|
|
189
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
190
|
+
});
|
|
191
|
+
if (target)
|
|
192
|
+
target.appendChild(fragment);
|
|
193
|
+
else
|
|
194
|
+
this.parentElement.insertBefore(fragment, this.nextSibling);
|
|
195
|
+
}
|
|
196
|
+
_cleanup() {
|
|
197
|
+
this._nodes.forEach((group) => {
|
|
198
|
+
if (group)
|
|
199
|
+
group.forEach((node) => node.parentElement?.removeChild(node));
|
|
200
|
+
});
|
|
201
|
+
this._nodes = [];
|
|
202
|
+
this._cleanupDefault();
|
|
203
|
+
}
|
|
204
|
+
_cleanupDefault() {
|
|
205
|
+
this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
206
|
+
this._defaultNodes = [];
|
|
207
|
+
}
|
|
208
|
+
connectedCallback() {
|
|
209
|
+
this.refreshValue();
|
|
210
|
+
}
|
|
211
|
+
disconnectedCallback() {
|
|
212
|
+
this._cleanup();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
__decorate([
|
|
216
|
+
changedAttribute("on-get-value"),
|
|
217
|
+
__metadata("design:type", Function),
|
|
218
|
+
__metadata("design:paramtypes", [String]),
|
|
219
|
+
__metadata("design:returntype", void 0)
|
|
220
|
+
], SwcLoop.prototype, "refreshValue", null);
|
|
221
|
+
SwcLoop = __decorate([
|
|
222
|
+
elementDefine({ name: "swc-loop", extends: "template" })
|
|
223
|
+
], SwcLoop);
|
|
224
|
+
export {
|
|
225
|
+
SwcLoop
|
|
226
|
+
};
|
|
227
|
+
//# 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,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAGvB,IAAM,UAAN,MAAMA,iBAAgB,oBAAmB;EAAzC,cAAA;;AACG,SAAA,SAAgB,CAAA;AAChB,SAAA,SAA4B,CAAA;AAC5B,SAAA,gBAAwB,CAAA;EA6MlC;EA3ME,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAS;AACjB,SAAK,SAAS,MAAM,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAA;AAC5C,SAAK,OAAM;EACb;EAEA,SAAS,OAAa;AACpB,WAAO,KAAK,OAAO,KAAK,KAAK;EAC/B;EAEQ,aAAU;AAChB,UAAM,SAAS,KAAK,aAAa,eAAe;AAChD,QAAI,CAAC;AAAQ,aAAO;AACpB,QAAI;AACF,YAAM,MAAM,cAAc,cAAc;QACtC;QACA,SAAS;QACT,MAAM,SAAS,oBAAoB,QAAQ,IAAI;OAChD;AACD,UAAI,OAAO,QAAQ;AAAU,eAAO,SAAS,cAAc,GAAG;AAC9D,UAAI,eAAe;AAAM,eAAO;IAClC,SAAS,GAAG;AACV,cAAQ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C;IAC5C,CAAC;AAED,QAAI;AAAQ,aAAO,YAAY,QAAQ;;AAClC,WAAK,cAAc,aAAa,UAAU,KAAK,WAAW;EACjE;EAEQ,WAAQ;AACd,SAAK,OAAO,QAAQ,WAAQ;AAC1B,UAAI;AAAO,cAAM,QAAQ,UAAQ,KAAK,eAAe,YAAY,IAAI,CAAC;IACxE,CAAC;AACD,SAAK,SAAS,CAAA;AACd,SAAK,gBAAe;EACtB;EAEQ,kBAAe;AACrB,SAAK,cAAc,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AAC/D,SAAK,gBAAgB,CAAA;EACvB;EAEA,oBAAiB;AACf,SAAK,aAAY;EACnB;EACA,uBAAoB;AAClB,SAAK,SAAQ;EACf;;AAxEQ,WAAA;EADP,iBAAiB,cAAc;;;;;AAtIrB,UAAO,WAAA;EADnB,cAAc,EAAE,MAAM,YAAY,SAAS,WAAU,CAAE;GAC3C,OAAO;",
|
|
6
|
+
"names": ["SwcLoop"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { elementDefine } from "../decorators/elementDefine.js";
|
|
8
|
+
let SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
|
|
9
|
+
};
|
|
10
|
+
SwcLoading = __decorate([
|
|
11
|
+
elementDefine({ name: "swc-loading", extends: "template" })
|
|
12
|
+
], SwcLoading);
|
|
13
|
+
let SwcError = class SwcError2 extends HTMLTemplateElement {
|
|
14
|
+
};
|
|
15
|
+
SwcError = __decorate([
|
|
16
|
+
elementDefine({ name: "swc-error", extends: "template" })
|
|
17
|
+
], SwcError);
|
|
18
|
+
let SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
|
|
19
|
+
};
|
|
20
|
+
SwcSuccess = __decorate([
|
|
21
|
+
elementDefine({ name: "swc-success", extends: "template" })
|
|
22
|
+
], SwcSuccess);
|
|
23
|
+
let SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
|
|
24
|
+
};
|
|
25
|
+
SwcWhen = __decorate([
|
|
26
|
+
elementDefine({ name: "swc-when", extends: "template" })
|
|
27
|
+
], SwcWhen);
|
|
28
|
+
let SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
|
|
29
|
+
};
|
|
30
|
+
SwcOtherwise = __decorate([
|
|
31
|
+
elementDefine({ name: "swc-otherwise", extends: "template" })
|
|
32
|
+
], SwcOtherwise);
|
|
33
|
+
let SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
|
|
34
|
+
};
|
|
35
|
+
SwcDefault = __decorate([
|
|
36
|
+
elementDefine({ name: "swc-default", extends: "template" })
|
|
37
|
+
], SwcDefault);
|
|
38
|
+
export {
|
|
39
|
+
SwcDefault,
|
|
40
|
+
SwcError,
|
|
41
|
+
SwcLoading,
|
|
42
|
+
SwcOtherwise,
|
|
43
|
+
SwcSuccess,
|
|
44
|
+
SwcWhen
|
|
45
|
+
};
|
|
46
|
+
//# 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,SAAS,qBAAqB;AAGvB,IAAM,aAAN,MAAMA,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;EADtB,cAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;AAGhB,IAAM,WAAN,MAAMC,kBAAiB,oBAAmB;;AAApC,WAAQ,WAAA;EADpB,cAAc,EAAE,MAAM,aAAa,SAAS,WAAU,CAAE;GAC5C,QAAQ;AAGd,IAAM,aAAN,MAAMC,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;EADtB,cAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;AAGhB,IAAM,UAAN,MAAMC,iBAAgB,oBAAmB;;AAAnC,UAAO,WAAA;EADnB,cAAc,EAAE,MAAM,YAAY,SAAS,WAAU,CAAE;GAC3C,OAAO;AAGb,IAAM,eAAN,MAAMC,sBAAqB,oBAAmB;;AAAxC,eAAY,WAAA;EADxB,cAAc,EAAE,MAAM,iBAAiB,SAAS,WAAU,CAAE;GAChD,YAAY;AAGlB,IAAM,aAAN,MAAMC,oBAAmB,oBAAmB;;AAAtC,aAAU,WAAA;EADtB,cAAc,EAAE,MAAM,eAAe,SAAS,WAAU,CAAE;GAC9C,UAAU;",
|
|
6
|
+
"names": ["SwcLoading", "SwcError", "SwcSuccess", "SwcWhen", "SwcOtherwise", "SwcDefault"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export * from "./is/index.js";
|
|
2
|
+
export * from "./SwcSubTemplates.js";
|
|
3
|
+
export * from "./SwcLoop.js";
|
|
4
|
+
export * from "./SwcIf.js";
|
|
5
|
+
export * from "./SwcChoose.js";
|
|
6
|
+
export * from "./SwcAsync.js";
|
|
7
|
+
export * from "./SwcApp.js";
|
|
8
|
+
export * from "./SwcAppEngine.js";
|
|
2
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/index.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
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,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,6 @@ export * from "./decorators/query.js";
|
|
|
9
9
|
export * from "./decorators/queryAll.js";
|
|
10
10
|
export * from "./decorators/addEventListener.js";
|
|
11
11
|
export * from "./types.js";
|
|
12
|
-
export * from "./elements/
|
|
12
|
+
export * from "./elements/index.js";
|
|
13
13
|
export * from "./utils/Utils.js";
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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
|
|
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
5
|
"mappings": "AAAA,OAAO;AAGP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -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": "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
|
}
|
package/dist/esm/utils/Utils.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { getElementConfig } from "../decorators/elementDefine.js";
|
|
2
2
|
const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var SwcUtils;
|
|
4
|
+
((SwcUtils2) => {
|
|
5
|
+
SwcUtils2.getHelperSet = (win) => {
|
|
6
|
+
const doc = win.document;
|
|
7
|
+
return {
|
|
8
|
+
$d: doc,
|
|
9
|
+
$w: win,
|
|
10
|
+
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
11
|
+
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
12
|
+
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
SwcUtils2.getHelperAndHostSet = (win, el) => {
|
|
16
|
+
const helperSet = (0, SwcUtils2.getHelperSet)(win);
|
|
17
|
+
const hostSet = (0, SwcUtils2.getHostSet)(el);
|
|
18
|
+
return {
|
|
19
|
+
...helperSet,
|
|
20
|
+
...hostSet
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
SwcUtils2.getValueByPath = (obj, path, rootName) => {
|
|
5
24
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
6
25
|
const parts = path.split(".");
|
|
7
26
|
let current = obj;
|
|
@@ -10,49 +29,66 @@ class SwcUtils {
|
|
|
10
29
|
current = current[part];
|
|
11
30
|
}
|
|
12
31
|
return current;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
current =
|
|
17
|
-
while (current) {
|
|
32
|
+
};
|
|
33
|
+
SwcUtils2.findNearestSwcHost = (el) => {
|
|
34
|
+
if (el.__swc_host) return el.__swc_host;
|
|
35
|
+
let current = el.parentElement || el.getRootNode?.()?.host;
|
|
36
|
+
while (current && current !== document && current !== window) {
|
|
37
|
+
if (current.__swc_host) return current.__swc_host;
|
|
18
38
|
if (getElementConfig(current)) return current;
|
|
19
|
-
current = current.parentElement || current?.
|
|
39
|
+
current = current.parentElement || current.getRootNode?.()?.host;
|
|
20
40
|
}
|
|
21
41
|
return void 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
* Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
|
|
25
|
-
*/
|
|
26
|
-
static findAllSwcHosts(el) {
|
|
42
|
+
};
|
|
43
|
+
SwcUtils2.findAllSwcHosts = (el) => {
|
|
27
44
|
const hosts = [];
|
|
28
|
-
let current =
|
|
45
|
+
let current = (0, SwcUtils2.findNearestSwcHost)(el);
|
|
29
46
|
while (current) {
|
|
30
47
|
hosts.push(current);
|
|
31
|
-
current =
|
|
48
|
+
current = (0, SwcUtils2.findNearestSwcHost)(current);
|
|
32
49
|
}
|
|
33
50
|
return hosts.reverse();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
};
|
|
52
|
+
SwcUtils2.getHosts = (el) => {
|
|
53
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
54
|
+
if (getElementConfig(el)) return [...ancestors, el];
|
|
55
|
+
return ancestors;
|
|
56
|
+
};
|
|
57
|
+
SwcUtils2.getHost = (el) => {
|
|
58
|
+
if (getElementConfig(el)) return el;
|
|
59
|
+
return (0, SwcUtils2.findNearestSwcHost)(el);
|
|
60
|
+
};
|
|
61
|
+
SwcUtils2.getAppHosts = (el) => {
|
|
62
|
+
const hosts = (0, SwcUtils2.getHosts)(el);
|
|
43
63
|
return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const appHosts =
|
|
64
|
+
};
|
|
65
|
+
SwcUtils2.getAppHost = (el) => {
|
|
66
|
+
const appHosts = (0, SwcUtils2.getAppHosts)(el);
|
|
47
67
|
const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
|
|
48
68
|
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
};
|
|
70
|
+
SwcUtils2.getHostSet = (el) => {
|
|
71
|
+
const isSwc = !!getElementConfig(el);
|
|
72
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
73
|
+
let $host;
|
|
74
|
+
let $parentHost;
|
|
75
|
+
if (isSwc) {
|
|
76
|
+
$host = el;
|
|
77
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
78
|
+
} else {
|
|
79
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
80
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
81
|
+
}
|
|
82
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
83
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
84
|
+
const loopContext = {};
|
|
85
|
+
let curr = el;
|
|
86
|
+
while (curr && curr !== document.documentElement) {
|
|
87
|
+
if (curr.__swc_loop_context) {
|
|
88
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
89
|
+
}
|
|
90
|
+
curr = curr.parentElement || curr.getRootNode().host;
|
|
91
|
+
}
|
|
56
92
|
const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
|
|
57
93
|
const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
|
|
58
94
|
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
@@ -65,10 +101,11 @@ class SwcUtils {
|
|
|
65
101
|
$appHost,
|
|
66
102
|
$appHosts,
|
|
67
103
|
$firstAppHost,
|
|
68
|
-
$lastAppHost: $appHost
|
|
104
|
+
$lastAppHost: $appHost,
|
|
105
|
+
...loopContext
|
|
69
106
|
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
107
|
+
};
|
|
108
|
+
})(SwcUtils || (SwcUtils = {}));
|
|
72
109
|
export {
|
|
73
110
|
SWC_NOT_FOUND,
|
|
74
111
|
SwcUtils
|
|
@@ -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
|
|
5
|
-
"mappings": "AACA,SAAS,wBAAwB;AAE1B,MAAM,gBAAgB,OAAO,eAAe;AAE5C,MAAM,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["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": "AACA,SAAS,wBAAwB;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,QAA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