@dooboostore/simple-web-component 1.0.29 → 1.0.30
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 +432 -27
- package/dist/cjs/decorators/elementDefine.js +2 -0
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +97 -0
- package/dist/cjs/decorators/setProperty.js.map +7 -0
- package/dist/cjs/elements/SwcAppMixin.js +1 -1
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +4 -1
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +54 -38
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/register.js +131 -39
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +11 -8
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +2 -0
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +78 -0
- package/dist/esm/decorators/setProperty.js.map +7 -0
- package/dist/esm/elements/SwcAppMixin.js +1 -1
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +4 -1
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -38
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/register.js +131 -39
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +11 -8
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +87 -8
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +13 -0
- package/dist/types/decorators/setProperty.d.ts.map +1 -0
- package/dist/types/elements/SwcAsync.d.ts.map +1 -1
- package/dist/types/elements/SwcChoose.d.ts +1 -1
- package/dist/types/elements/SwcChoose.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts +3 -1
- package/dist/types/elements/register.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/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +87 -8
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/decorators/elementDefine.ts +4 -0
- package/src/decorators/emitCustomEvent.ts +1 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/setProperty.ts +97 -0
- package/src/elements/SwcAppMixin.ts +2 -2
- package/src/elements/SwcAsync.ts +5 -1
- package/src/elements/SwcChoose.ts +76 -37
- package/src/elements/register.ts +158 -39
- package/src/index.ts +3 -1
- package/src/utils/Utils.ts +15 -11
|
@@ -15,6 +15,7 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this._nodes = [];
|
|
17
17
|
this._value = null;
|
|
18
|
+
this._previousTemplate = null;
|
|
18
19
|
}
|
|
19
20
|
get value() {
|
|
20
21
|
return this._value;
|
|
@@ -23,70 +24,85 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
23
24
|
this._value = nv;
|
|
24
25
|
this.render();
|
|
25
26
|
}
|
|
26
|
-
_resolvePortal() {
|
|
27
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
28
|
-
if (!portalScript)
|
|
29
|
-
return this.parentElement;
|
|
30
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
31
|
-
const res = FunctionUtils.executeReturn({
|
|
32
|
-
script: portalScript,
|
|
33
|
-
context: this,
|
|
34
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
35
|
-
});
|
|
36
|
-
if (res instanceof HTMLElement)
|
|
37
|
-
return res;
|
|
38
|
-
if (typeof res === "string")
|
|
39
|
-
return win.document.querySelector(res);
|
|
40
|
-
return this.parentElement;
|
|
41
|
-
}
|
|
42
27
|
_executeCloneCallback(attr, args) {
|
|
43
28
|
const script = this.getAttribute(attr);
|
|
44
29
|
if (!script)
|
|
45
30
|
return;
|
|
46
31
|
FunctionUtils.execute({ script, context: this, args });
|
|
47
32
|
}
|
|
48
|
-
refresh() {
|
|
49
|
-
|
|
50
|
-
if (
|
|
33
|
+
refresh(valueAttr) {
|
|
34
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
35
|
+
if (valueAttr === null) {
|
|
51
36
|
this.value = null;
|
|
52
37
|
return;
|
|
53
38
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
40
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
41
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
42
|
+
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
43
|
+
this.value = result;
|
|
44
|
+
} else {
|
|
45
|
+
this.value = valueAttr;
|
|
46
|
+
}
|
|
57
47
|
}
|
|
58
48
|
render() {
|
|
59
|
-
this.cleanup();
|
|
60
|
-
const portal = this._resolvePortal();
|
|
61
|
-
if (!portal)
|
|
62
|
-
return;
|
|
63
49
|
const win = this.ownerDocument?.defaultView || window;
|
|
64
50
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
65
51
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
66
52
|
let selected = null;
|
|
67
53
|
for (const t of templates) {
|
|
68
|
-
if (t.getAttribute("is") === "swc-when"
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
55
|
+
let matches = false;
|
|
56
|
+
const value = t.getAttribute("value") || "";
|
|
57
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
58
|
+
const script = value.slice(2, -2).trim();
|
|
59
|
+
const result = FunctionUtils.executeReturn({
|
|
60
|
+
script,
|
|
61
|
+
context: t,
|
|
62
|
+
args: { ...helperSet, $value: this._value }
|
|
63
|
+
});
|
|
64
|
+
matches = result === true;
|
|
65
|
+
} else {
|
|
66
|
+
matches = String(value) === String(this._value);
|
|
67
|
+
}
|
|
68
|
+
if (matches) {
|
|
69
|
+
selected = t;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
75
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
76
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
77
|
+
if (shouldSkip) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.cleanup();
|
|
81
|
+
this._previousTemplate = target;
|
|
74
82
|
if (target) {
|
|
75
83
|
const clone = target.content.cloneNode(true);
|
|
76
84
|
this._nodes = Array.from(clone.childNodes);
|
|
77
85
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
78
86
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
79
87
|
this._nodes.forEach((n, nodeIdx) => {
|
|
80
|
-
if (n instanceof HTMLElement)
|
|
81
|
-
n.__swc_host = this;
|
|
82
88
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
89
|
+
if (n instanceof HTMLElement) {
|
|
90
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
91
|
+
const value = attr.value || "";
|
|
92
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
93
|
+
const script = value.slice(2, -2).trim();
|
|
94
|
+
const result = FunctionUtils.executeReturn({
|
|
95
|
+
script,
|
|
96
|
+
context: n,
|
|
97
|
+
args: { ...groupArgs, $value: this._value }
|
|
98
|
+
});
|
|
99
|
+
n.setAttribute(attr.name, String(result));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
83
103
|
});
|
|
84
104
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
85
|
-
|
|
86
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
87
|
-
} else {
|
|
88
|
-
portal.appendChild(clone);
|
|
89
|
-
}
|
|
105
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
108
|
cleanup() {
|
|
@@ -101,9 +117,9 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
__decorate([
|
|
104
|
-
changedAttributeHost("
|
|
120
|
+
changedAttributeHost("value"),
|
|
105
121
|
__metadata("design:type", Function),
|
|
106
|
-
__metadata("design:paramtypes", []),
|
|
122
|
+
__metadata("design:paramtypes", [String]),
|
|
107
123
|
__metadata("design:returntype", void 0)
|
|
108
124
|
], SwcChoose.prototype, "refresh", null);
|
|
109
125
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('value')\n private refresh(valueAttr?: string | null) {\n valueAttr ??= this.getAttribute('value');\n if (valueAttr === null) {\n this.value = null;\n return;\n }\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (valueAttr.startsWith('{{') && valueAttr.endsWith('}}')) {\n const script = valueAttr.slice(2, -2).trim();\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n this.value = result;\n } else {\n // 일반 문자열 값\n this.value = valueAttr;\n }\n }\n\n private render() {\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when') {\n let matches = false;\n const value = t.getAttribute('value') || '';\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: t,\n args: { ...helperSet, $value: this._value }\n });\n // console.log('rrrrrrrrrrrrrr', result);\n matches = result === true;\n } else {\n // 일반 문자열 비교 (기존 방식)\n matches = String(value) === String(this._value);\n }\n\n if (matches) {\n selected = t;\n break;\n }\n }\n }\n\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n // skip-if-same attribute가 있고 이전과 같은 template이면 렌더링 스킵\n // 최상위 skip-if-same 또는 각 when/otherwise의 skip-if-same 체크\n const targetHasSkipIfSame = target?.hasAttribute('skip-if-same');\n const shouldSkip = (this.hasAttribute('skip-if-same') || targetHasSkipIfSame) && this._previousTemplate === target;\n if (shouldSkip) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n const clone = target.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n // 복제된 최상위 요소들은 SwcChoose의 직접 자식이 될 것이므로 __swc_host 설정 안 함\n this._nodes.forEach((n, nodeIdx) => {\n // if (n instanceof HTMLElement) (n as any).__swc_host = this; // 제거: 부모 체인 유지\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n\n // Attribute {{ }} 치환 - HTML string 차원에서 동적 치환\n if (n instanceof HTMLElement) {\n Array.from(n.attributes).forEach(attr => {\n const value = attr.value || '';\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: n,\n args: { ...groupArgs, $value: this._value }\n });\n n.setAttribute(attr.name, String(result));\n }\n });\n }\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n this.parentElement?.insertBefore(clone, this.nextSibling);\n // if (portal === this.parentElement) {\n // portal.insertBefore(clone, this.nextSibling);\n // } else {\n // portal.appendChild(clone);\n // }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -335,6 +335,7 @@ const registerAllElements = (w) => {
|
|
|
335
335
|
super(...arguments);
|
|
336
336
|
this._nodes = [];
|
|
337
337
|
this._value = null;
|
|
338
|
+
this._previousTemplate = null;
|
|
338
339
|
}
|
|
339
340
|
get value() {
|
|
340
341
|
return this._value;
|
|
@@ -343,70 +344,85 @@ const registerAllElements = (w) => {
|
|
|
343
344
|
this._value = nv;
|
|
344
345
|
this.render();
|
|
345
346
|
}
|
|
346
|
-
_resolvePortal() {
|
|
347
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
348
|
-
if (!portalScript)
|
|
349
|
-
return this.parentElement;
|
|
350
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
351
|
-
const res = FunctionUtils.executeReturn({
|
|
352
|
-
script: portalScript,
|
|
353
|
-
context: this,
|
|
354
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
355
|
-
});
|
|
356
|
-
if (res instanceof HTMLElement)
|
|
357
|
-
return res;
|
|
358
|
-
if (typeof res === "string")
|
|
359
|
-
return win.document.querySelector(res);
|
|
360
|
-
return this.parentElement;
|
|
361
|
-
}
|
|
362
347
|
_executeCloneCallback(attr, args) {
|
|
363
348
|
const script = this.getAttribute(attr);
|
|
364
349
|
if (!script)
|
|
365
350
|
return;
|
|
366
351
|
FunctionUtils.execute({ script, context: this, args });
|
|
367
352
|
}
|
|
368
|
-
refresh() {
|
|
369
|
-
|
|
370
|
-
if (
|
|
353
|
+
refresh(valueAttr) {
|
|
354
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
355
|
+
if (valueAttr === null) {
|
|
371
356
|
this.value = null;
|
|
372
357
|
return;
|
|
373
358
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
359
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
360
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
361
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
362
|
+
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
363
|
+
this.value = result;
|
|
364
|
+
} else {
|
|
365
|
+
this.value = valueAttr;
|
|
366
|
+
}
|
|
377
367
|
}
|
|
378
368
|
render() {
|
|
379
|
-
this.cleanup();
|
|
380
|
-
const portal = this._resolvePortal();
|
|
381
|
-
if (!portal)
|
|
382
|
-
return;
|
|
383
369
|
const win = this.ownerDocument?.defaultView || window;
|
|
384
370
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
385
371
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
386
372
|
let selected = null;
|
|
387
373
|
for (const t of templates) {
|
|
388
|
-
if (t.getAttribute("is") === "swc-when"
|
|
389
|
-
|
|
390
|
-
|
|
374
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
375
|
+
let matches = false;
|
|
376
|
+
const value = t.getAttribute("value") || "";
|
|
377
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
378
|
+
const script = value.slice(2, -2).trim();
|
|
379
|
+
const result = FunctionUtils.executeReturn({
|
|
380
|
+
script,
|
|
381
|
+
context: t,
|
|
382
|
+
args: { ...helperSet, $value: this._value }
|
|
383
|
+
});
|
|
384
|
+
matches = result === true;
|
|
385
|
+
} else {
|
|
386
|
+
matches = String(value) === String(this._value);
|
|
387
|
+
}
|
|
388
|
+
if (matches) {
|
|
389
|
+
selected = t;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
394
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
395
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
396
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
397
|
+
if (shouldSkip) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.cleanup();
|
|
401
|
+
this._previousTemplate = target;
|
|
394
402
|
if (target) {
|
|
395
403
|
const clone = target.content.cloneNode(true);
|
|
396
404
|
this._nodes = Array.from(clone.childNodes);
|
|
397
405
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
398
406
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
399
407
|
this._nodes.forEach((n, nodeIdx) => {
|
|
400
|
-
if (n instanceof HTMLElement)
|
|
401
|
-
n.__swc_host = this;
|
|
402
408
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
409
|
+
if (n instanceof HTMLElement) {
|
|
410
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
411
|
+
const value = attr.value || "";
|
|
412
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
413
|
+
const script = value.slice(2, -2).trim();
|
|
414
|
+
const result = FunctionUtils.executeReturn({
|
|
415
|
+
script,
|
|
416
|
+
context: n,
|
|
417
|
+
args: { ...groupArgs, $value: this._value }
|
|
418
|
+
});
|
|
419
|
+
n.setAttribute(attr.name, String(result));
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
403
423
|
});
|
|
404
424
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
405
|
-
|
|
406
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
407
|
-
} else {
|
|
408
|
-
portal.appendChild(clone);
|
|
409
|
-
}
|
|
425
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
410
426
|
}
|
|
411
427
|
}
|
|
412
428
|
cleanup() {
|
|
@@ -421,9 +437,9 @@ const registerAllElements = (w) => {
|
|
|
421
437
|
}
|
|
422
438
|
};
|
|
423
439
|
__decorate([
|
|
424
|
-
changedAttributeHost("
|
|
440
|
+
changedAttributeHost("value"),
|
|
425
441
|
__metadata("design:type", Function),
|
|
426
|
-
__metadata("design:paramtypes", []),
|
|
442
|
+
__metadata("design:paramtypes", [String]),
|
|
427
443
|
__metadata("design:returntype", void 0)
|
|
428
444
|
], SwcChoose.prototype, "refresh", null);
|
|
429
445
|
SwcChoose = __decorate([
|
|
@@ -459,8 +475,10 @@ const registerAllElements = (w) => {
|
|
|
459
475
|
}
|
|
460
476
|
refresh() {
|
|
461
477
|
const script = this.getAttribute("on-get-value");
|
|
462
|
-
if (!script)
|
|
478
|
+
if (!script) {
|
|
479
|
+
this.render("default");
|
|
463
480
|
return;
|
|
481
|
+
}
|
|
464
482
|
const win = this.ownerDocument?.defaultView || window;
|
|
465
483
|
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
466
484
|
if (result instanceof Promise) {
|
|
@@ -505,6 +523,7 @@ const registerAllElements = (w) => {
|
|
|
505
523
|
this._nodes = [];
|
|
506
524
|
}
|
|
507
525
|
connectedCallback() {
|
|
526
|
+
console.log("[SwcAsync] connectedCallback called");
|
|
508
527
|
this.refresh();
|
|
509
528
|
}
|
|
510
529
|
disconnectedCallback() {
|
|
@@ -805,6 +824,79 @@ const registerAllElements = (w) => {
|
|
|
805
824
|
SwcAppBody = __decorate([
|
|
806
825
|
elementDefine("swc-app-body", { extends: "body", window: w })
|
|
807
826
|
], SwcAppBody);
|
|
827
|
+
return {
|
|
828
|
+
// Sub Templates
|
|
829
|
+
SwcLoading,
|
|
830
|
+
SwcError,
|
|
831
|
+
SwcSuccess,
|
|
832
|
+
SwcWhen,
|
|
833
|
+
SwcOtherwise,
|
|
834
|
+
SwcDefault,
|
|
835
|
+
// Core Elements
|
|
836
|
+
SwcApp,
|
|
837
|
+
SwcIf,
|
|
838
|
+
SwcLoop,
|
|
839
|
+
SwcChoose,
|
|
840
|
+
SwcAsync,
|
|
841
|
+
// App Elements
|
|
842
|
+
SwcAppAnchor,
|
|
843
|
+
SwcAppArea,
|
|
844
|
+
SwcAppAudio,
|
|
845
|
+
SwcAppBase,
|
|
846
|
+
SwcAppButton,
|
|
847
|
+
SwcAppCanvas,
|
|
848
|
+
SwcAppData,
|
|
849
|
+
SwcAppDataList,
|
|
850
|
+
SwcAppDetails,
|
|
851
|
+
SwcAppDialog,
|
|
852
|
+
SwcAppDiv,
|
|
853
|
+
SwcAppDList,
|
|
854
|
+
SwcAppEmbed,
|
|
855
|
+
SwcAppFieldSet,
|
|
856
|
+
SwcAppForm,
|
|
857
|
+
SwcAppHR,
|
|
858
|
+
SwcAppIFrame,
|
|
859
|
+
SwcAppImage,
|
|
860
|
+
SwcAppInput,
|
|
861
|
+
SwcAppLabel,
|
|
862
|
+
SwcAppLegend,
|
|
863
|
+
SwcAppLI,
|
|
864
|
+
SwcAppLink,
|
|
865
|
+
SwcAppMap,
|
|
866
|
+
SwcAppMeta,
|
|
867
|
+
SwcAppMeter,
|
|
868
|
+
SwcAppMod,
|
|
869
|
+
SwcAppObject,
|
|
870
|
+
SwcAppOList,
|
|
871
|
+
SwcAppOptGroup,
|
|
872
|
+
SwcAppOption,
|
|
873
|
+
SwcAppOutput,
|
|
874
|
+
SwcAppParagraph,
|
|
875
|
+
SwcAppParam,
|
|
876
|
+
SwcAppPicture,
|
|
877
|
+
SwcAppPre,
|
|
878
|
+
SwcAppProgress,
|
|
879
|
+
SwcAppQuote,
|
|
880
|
+
SwcAppScript,
|
|
881
|
+
SwcAppSelect,
|
|
882
|
+
SwcAppSlot,
|
|
883
|
+
SwcAppSource,
|
|
884
|
+
SwcAppSpan,
|
|
885
|
+
SwcAppStyle,
|
|
886
|
+
SwcAppTable,
|
|
887
|
+
SwcAppTableSection,
|
|
888
|
+
SwcAppTableCell,
|
|
889
|
+
SwcAppTemplate,
|
|
890
|
+
SwcAppTextArea,
|
|
891
|
+
SwcAppTime,
|
|
892
|
+
SwcAppTitle,
|
|
893
|
+
SwcAppTableRow,
|
|
894
|
+
SwcAppTrack,
|
|
895
|
+
SwcAppUList,
|
|
896
|
+
SwcAppVideo,
|
|
897
|
+
SwcAppHeading,
|
|
898
|
+
SwcAppBody
|
|
899
|
+
};
|
|
808
900
|
};
|
|
809
901
|
export {
|
|
810
902
|
registerAllElements
|