@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
|
@@ -37,6 +37,7 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
37
37
|
super(...arguments);
|
|
38
38
|
this._nodes = [];
|
|
39
39
|
this._value = null;
|
|
40
|
+
this._previousTemplate = null;
|
|
40
41
|
}
|
|
41
42
|
get value() {
|
|
42
43
|
return this._value;
|
|
@@ -45,70 +46,85 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
45
46
|
this._value = nv;
|
|
46
47
|
this.render();
|
|
47
48
|
}
|
|
48
|
-
_resolvePortal() {
|
|
49
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
50
|
-
if (!portalScript)
|
|
51
|
-
return this.parentElement;
|
|
52
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
53
|
-
const res = import_core.FunctionUtils.executeReturn({
|
|
54
|
-
script: portalScript,
|
|
55
|
-
context: this,
|
|
56
|
-
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
57
|
-
});
|
|
58
|
-
if (res instanceof HTMLElement)
|
|
59
|
-
return res;
|
|
60
|
-
if (typeof res === "string")
|
|
61
|
-
return win.document.querySelector(res);
|
|
62
|
-
return this.parentElement;
|
|
63
|
-
}
|
|
64
49
|
_executeCloneCallback(attr, args) {
|
|
65
50
|
const script = this.getAttribute(attr);
|
|
66
51
|
if (!script)
|
|
67
52
|
return;
|
|
68
53
|
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
69
54
|
}
|
|
70
|
-
refresh() {
|
|
71
|
-
|
|
72
|
-
if (
|
|
55
|
+
refresh(valueAttr) {
|
|
56
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
57
|
+
if (valueAttr === null) {
|
|
73
58
|
this.value = null;
|
|
74
59
|
return;
|
|
75
60
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
62
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
63
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
64
|
+
const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
|
|
65
|
+
this.value = result;
|
|
66
|
+
} else {
|
|
67
|
+
this.value = valueAttr;
|
|
68
|
+
}
|
|
79
69
|
}
|
|
80
70
|
render() {
|
|
81
|
-
this.cleanup();
|
|
82
|
-
const portal = this._resolvePortal();
|
|
83
|
-
if (!portal)
|
|
84
|
-
return;
|
|
85
71
|
const win = this.ownerDocument?.defaultView || window;
|
|
86
72
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
87
73
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
88
74
|
let selected = null;
|
|
89
75
|
for (const t of templates) {
|
|
90
|
-
if (t.getAttribute("is") === "swc-when"
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
77
|
+
let matches = false;
|
|
78
|
+
const value = t.getAttribute("value") || "";
|
|
79
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
80
|
+
const script = value.slice(2, -2).trim();
|
|
81
|
+
const result = import_core.FunctionUtils.executeReturn({
|
|
82
|
+
script,
|
|
83
|
+
context: t,
|
|
84
|
+
args: { ...helperSet, $value: this._value }
|
|
85
|
+
});
|
|
86
|
+
matches = result === true;
|
|
87
|
+
} else {
|
|
88
|
+
matches = String(value) === String(this._value);
|
|
89
|
+
}
|
|
90
|
+
if (matches) {
|
|
91
|
+
selected = t;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
97
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
98
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
99
|
+
if (shouldSkip) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.cleanup();
|
|
103
|
+
this._previousTemplate = target;
|
|
96
104
|
if (target) {
|
|
97
105
|
const clone = target.content.cloneNode(true);
|
|
98
106
|
this._nodes = Array.from(clone.childNodes);
|
|
99
107
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
100
108
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
101
109
|
this._nodes.forEach((n, nodeIdx) => {
|
|
102
|
-
if (n instanceof HTMLElement)
|
|
103
|
-
n.__swc_host = this;
|
|
104
110
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
111
|
+
if (n instanceof HTMLElement) {
|
|
112
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
113
|
+
const value = attr.value || "";
|
|
114
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
115
|
+
const script = value.slice(2, -2).trim();
|
|
116
|
+
const result = import_core.FunctionUtils.executeReturn({
|
|
117
|
+
script,
|
|
118
|
+
context: n,
|
|
119
|
+
args: { ...groupArgs, $value: this._value }
|
|
120
|
+
});
|
|
121
|
+
n.setAttribute(attr.name, String(result));
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
105
125
|
});
|
|
106
126
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
107
|
-
|
|
108
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
109
|
-
} else {
|
|
110
|
-
portal.appendChild(clone);
|
|
111
|
-
}
|
|
127
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
112
128
|
}
|
|
113
129
|
}
|
|
114
130
|
cleanup() {
|
|
@@ -123,9 +139,9 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
123
139
|
}
|
|
124
140
|
}
|
|
125
141
|
__decorate([
|
|
126
|
-
(0, import_changedAttributeHost.changedAttributeHost)("
|
|
142
|
+
(0, import_changedAttributeHost.changedAttributeHost)("value"),
|
|
127
143
|
__metadata("design:type", Function),
|
|
128
|
-
__metadata("design:paramtypes", []),
|
|
144
|
+
__metadata("design:paramtypes", [String]),
|
|
129
145
|
__metadata("design:returntype", void 0)
|
|
130
146
|
], SwcChoose.prototype, "refresh", null);
|
|
131
147
|
//# sourceMappingURL=SwcChoose.js.map
|
|
@@ -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,kCAAqC;AACrC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;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
|
}
|
|
@@ -357,6 +357,7 @@ const registerAllElements = (w) => {
|
|
|
357
357
|
super(...arguments);
|
|
358
358
|
this._nodes = [];
|
|
359
359
|
this._value = null;
|
|
360
|
+
this._previousTemplate = null;
|
|
360
361
|
}
|
|
361
362
|
get value() {
|
|
362
363
|
return this._value;
|
|
@@ -365,70 +366,85 @@ const registerAllElements = (w) => {
|
|
|
365
366
|
this._value = nv;
|
|
366
367
|
this.render();
|
|
367
368
|
}
|
|
368
|
-
_resolvePortal() {
|
|
369
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
370
|
-
if (!portalScript)
|
|
371
|
-
return this.parentElement;
|
|
372
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
373
|
-
const res = import_core.FunctionUtils.executeReturn({
|
|
374
|
-
script: portalScript,
|
|
375
|
-
context: this,
|
|
376
|
-
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
377
|
-
});
|
|
378
|
-
if (res instanceof HTMLElement)
|
|
379
|
-
return res;
|
|
380
|
-
if (typeof res === "string")
|
|
381
|
-
return win.document.querySelector(res);
|
|
382
|
-
return this.parentElement;
|
|
383
|
-
}
|
|
384
369
|
_executeCloneCallback(attr, args) {
|
|
385
370
|
const script = this.getAttribute(attr);
|
|
386
371
|
if (!script)
|
|
387
372
|
return;
|
|
388
373
|
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
389
374
|
}
|
|
390
|
-
refresh() {
|
|
391
|
-
|
|
392
|
-
if (
|
|
375
|
+
refresh(valueAttr) {
|
|
376
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
377
|
+
if (valueAttr === null) {
|
|
393
378
|
this.value = null;
|
|
394
379
|
return;
|
|
395
380
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
381
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
382
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
383
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
384
|
+
const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
|
|
385
|
+
this.value = result;
|
|
386
|
+
} else {
|
|
387
|
+
this.value = valueAttr;
|
|
388
|
+
}
|
|
399
389
|
}
|
|
400
390
|
render() {
|
|
401
|
-
this.cleanup();
|
|
402
|
-
const portal = this._resolvePortal();
|
|
403
|
-
if (!portal)
|
|
404
|
-
return;
|
|
405
391
|
const win = this.ownerDocument?.defaultView || window;
|
|
406
392
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
407
393
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
408
394
|
let selected = null;
|
|
409
395
|
for (const t of templates) {
|
|
410
|
-
if (t.getAttribute("is") === "swc-when"
|
|
411
|
-
|
|
412
|
-
|
|
396
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
397
|
+
let matches = false;
|
|
398
|
+
const value = t.getAttribute("value") || "";
|
|
399
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
400
|
+
const script = value.slice(2, -2).trim();
|
|
401
|
+
const result = import_core.FunctionUtils.executeReturn({
|
|
402
|
+
script,
|
|
403
|
+
context: t,
|
|
404
|
+
args: { ...helperSet, $value: this._value }
|
|
405
|
+
});
|
|
406
|
+
matches = result === true;
|
|
407
|
+
} else {
|
|
408
|
+
matches = String(value) === String(this._value);
|
|
409
|
+
}
|
|
410
|
+
if (matches) {
|
|
411
|
+
selected = t;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
413
414
|
}
|
|
414
415
|
}
|
|
415
416
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
417
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
418
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
419
|
+
if (shouldSkip) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
this.cleanup();
|
|
423
|
+
this._previousTemplate = target;
|
|
416
424
|
if (target) {
|
|
417
425
|
const clone = target.content.cloneNode(true);
|
|
418
426
|
this._nodes = Array.from(clone.childNodes);
|
|
419
427
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
420
428
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
421
429
|
this._nodes.forEach((n, nodeIdx) => {
|
|
422
|
-
if (n instanceof HTMLElement)
|
|
423
|
-
n.__swc_host = this;
|
|
424
430
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
431
|
+
if (n instanceof HTMLElement) {
|
|
432
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
433
|
+
const value = attr.value || "";
|
|
434
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
435
|
+
const script = value.slice(2, -2).trim();
|
|
436
|
+
const result = import_core.FunctionUtils.executeReturn({
|
|
437
|
+
script,
|
|
438
|
+
context: n,
|
|
439
|
+
args: { ...groupArgs, $value: this._value }
|
|
440
|
+
});
|
|
441
|
+
n.setAttribute(attr.name, String(result));
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
425
445
|
});
|
|
426
446
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
427
|
-
|
|
428
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
429
|
-
} else {
|
|
430
|
-
portal.appendChild(clone);
|
|
431
|
-
}
|
|
447
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
432
448
|
}
|
|
433
449
|
}
|
|
434
450
|
cleanup() {
|
|
@@ -443,9 +459,9 @@ const registerAllElements = (w) => {
|
|
|
443
459
|
}
|
|
444
460
|
};
|
|
445
461
|
__decorate([
|
|
446
|
-
(0, import_changedAttributeHost.changedAttributeHost)("
|
|
462
|
+
(0, import_changedAttributeHost.changedAttributeHost)("value"),
|
|
447
463
|
__metadata("design:type", Function),
|
|
448
|
-
__metadata("design:paramtypes", []),
|
|
464
|
+
__metadata("design:paramtypes", [String]),
|
|
449
465
|
__metadata("design:returntype", void 0)
|
|
450
466
|
], SwcChoose.prototype, "refresh", null);
|
|
451
467
|
SwcChoose = __decorate([
|
|
@@ -481,8 +497,10 @@ const registerAllElements = (w) => {
|
|
|
481
497
|
}
|
|
482
498
|
refresh() {
|
|
483
499
|
const script = this.getAttribute("on-get-value");
|
|
484
|
-
if (!script)
|
|
500
|
+
if (!script) {
|
|
501
|
+
this.render("default");
|
|
485
502
|
return;
|
|
503
|
+
}
|
|
486
504
|
const win = this.ownerDocument?.defaultView || window;
|
|
487
505
|
const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
|
|
488
506
|
if (result instanceof Promise) {
|
|
@@ -527,6 +545,7 @@ const registerAllElements = (w) => {
|
|
|
527
545
|
this._nodes = [];
|
|
528
546
|
}
|
|
529
547
|
connectedCallback() {
|
|
548
|
+
console.log("[SwcAsync] connectedCallback called");
|
|
530
549
|
this.refresh();
|
|
531
550
|
}
|
|
532
551
|
disconnectedCallback() {
|
|
@@ -827,5 +846,78 @@ const registerAllElements = (w) => {
|
|
|
827
846
|
SwcAppBody = __decorate([
|
|
828
847
|
(0, import_elementDefine.elementDefine)("swc-app-body", { extends: "body", window: w })
|
|
829
848
|
], SwcAppBody);
|
|
849
|
+
return {
|
|
850
|
+
// Sub Templates
|
|
851
|
+
SwcLoading,
|
|
852
|
+
SwcError,
|
|
853
|
+
SwcSuccess,
|
|
854
|
+
SwcWhen,
|
|
855
|
+
SwcOtherwise,
|
|
856
|
+
SwcDefault,
|
|
857
|
+
// Core Elements
|
|
858
|
+
SwcApp,
|
|
859
|
+
SwcIf,
|
|
860
|
+
SwcLoop,
|
|
861
|
+
SwcChoose,
|
|
862
|
+
SwcAsync,
|
|
863
|
+
// App Elements
|
|
864
|
+
SwcAppAnchor,
|
|
865
|
+
SwcAppArea,
|
|
866
|
+
SwcAppAudio,
|
|
867
|
+
SwcAppBase,
|
|
868
|
+
SwcAppButton,
|
|
869
|
+
SwcAppCanvas,
|
|
870
|
+
SwcAppData,
|
|
871
|
+
SwcAppDataList,
|
|
872
|
+
SwcAppDetails,
|
|
873
|
+
SwcAppDialog,
|
|
874
|
+
SwcAppDiv,
|
|
875
|
+
SwcAppDList,
|
|
876
|
+
SwcAppEmbed,
|
|
877
|
+
SwcAppFieldSet,
|
|
878
|
+
SwcAppForm,
|
|
879
|
+
SwcAppHR,
|
|
880
|
+
SwcAppIFrame,
|
|
881
|
+
SwcAppImage,
|
|
882
|
+
SwcAppInput,
|
|
883
|
+
SwcAppLabel,
|
|
884
|
+
SwcAppLegend,
|
|
885
|
+
SwcAppLI,
|
|
886
|
+
SwcAppLink,
|
|
887
|
+
SwcAppMap,
|
|
888
|
+
SwcAppMeta,
|
|
889
|
+
SwcAppMeter,
|
|
890
|
+
SwcAppMod,
|
|
891
|
+
SwcAppObject,
|
|
892
|
+
SwcAppOList,
|
|
893
|
+
SwcAppOptGroup,
|
|
894
|
+
SwcAppOption,
|
|
895
|
+
SwcAppOutput,
|
|
896
|
+
SwcAppParagraph,
|
|
897
|
+
SwcAppParam,
|
|
898
|
+
SwcAppPicture,
|
|
899
|
+
SwcAppPre,
|
|
900
|
+
SwcAppProgress,
|
|
901
|
+
SwcAppQuote,
|
|
902
|
+
SwcAppScript,
|
|
903
|
+
SwcAppSelect,
|
|
904
|
+
SwcAppSlot,
|
|
905
|
+
SwcAppSource,
|
|
906
|
+
SwcAppSpan,
|
|
907
|
+
SwcAppStyle,
|
|
908
|
+
SwcAppTable,
|
|
909
|
+
SwcAppTableSection,
|
|
910
|
+
SwcAppTableCell,
|
|
911
|
+
SwcAppTemplate,
|
|
912
|
+
SwcAppTextArea,
|
|
913
|
+
SwcAppTime,
|
|
914
|
+
SwcAppTitle,
|
|
915
|
+
SwcAppTableRow,
|
|
916
|
+
SwcAppTrack,
|
|
917
|
+
SwcAppUList,
|
|
918
|
+
SwcAppVideo,
|
|
919
|
+
SwcAppHeading,
|
|
920
|
+
SwcAppBody
|
|
921
|
+
};
|
|
830
922
|
};
|
|
831
923
|
//# sourceMappingURL=register.js.map
|