@dooboostore/simple-web-component 1.0.35 → 1.0.37
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 +58 -21
- package/dist/cjs/{elements/SwcAppEngine.js → SwcAppEngine.js} +6 -6
- package/dist/cjs/SwcAppEngine.js.map +7 -0
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +28 -26
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +122 -0
- package/dist/cjs/decorators/applySlot.js.map +7 -0
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +16 -15
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +59 -50
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +18 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +56 -8
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/elements/{SwcAppMixin.js → SwcApp.js} +107 -57
- package/dist/cjs/elements/SwcApp.js.map +7 -0
- package/dist/cjs/elements/index.js +21 -2
- package/dist/cjs/elements/index.js.map +3 -3
- package/dist/cjs/elements/tt/SwcAppMixin.js +1 -0
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +7 -0
- package/dist/cjs/elements/tt/SwcAsync.js +1 -0
- package/dist/cjs/elements/tt/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcChoose.js +1 -0
- package/dist/cjs/elements/tt/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcIf.js +1 -0
- package/dist/cjs/elements/tt/SwcIf.js.map +7 -0
- package/dist/cjs/elements/tt/SwcIfTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcLoop.js +1 -0
- package/dist/cjs/elements/tt/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcSubTemplates.js +1 -0
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/tt/register.js +1 -0
- package/dist/cjs/elements/tt/register.js.map +7 -0
- package/dist/cjs/index.js +12 -8
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types/window.d.js +16 -0
- package/dist/cjs/types/window.d.js.map +7 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +22 -19
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/{elements/SwcAppEngine.js → SwcAppEngine.js} +4 -4
- package/dist/esm/SwcAppEngine.js.map +7 -0
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +28 -26
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +103 -0
- package/dist/esm/decorators/applySlot.js.map +7 -0
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +16 -15
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +60 -51
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +18 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +56 -8
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/elements/{SwcAppMixin.js → SwcApp.js} +102 -53
- package/dist/esm/elements/SwcApp.js.map +7 -0
- package/dist/esm/elements/index.js +7 -1
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/elements/tt/SwcAppMixin.js +1 -0
- package/dist/esm/elements/tt/SwcAppMixin.js.map +7 -0
- package/dist/esm/elements/tt/SwcAsync.js +1 -0
- package/dist/esm/elements/tt/SwcAsync.js.map +7 -0
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcChoose.js +1 -0
- package/dist/esm/elements/tt/SwcChoose.js.map +7 -0
- package/dist/esm/elements/tt/SwcChooseTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcIf.js +1 -0
- package/dist/esm/elements/tt/SwcIf.js.map +7 -0
- package/dist/esm/elements/tt/SwcIfTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcLoop.js +1 -0
- package/dist/esm/elements/tt/SwcLoop.js.map +7 -0
- package/dist/esm/elements/tt/SwcLoopTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcSubTemplates.js +1 -0
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/tt/register.js +1 -0
- package/dist/esm/elements/tt/register.js.map +7 -0
- package/dist/esm/index.js +13 -9
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types/window.d.js +1 -0
- package/dist/esm/types/window.d.js.map +7 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +22 -19
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4189 -456
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/{elements/SwcAppEngine.d.ts → SwcAppEngine.d.ts} +9 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -0
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +9 -9
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +27 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -0
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +4 -9
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +21 -6
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts +7 -0
- package/dist/types/elements/SwcApp.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +2 -1
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +1 -0
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcAsync.d.ts +1 -0
- package/dist/types/elements/tt/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcChoose.d.ts +1 -0
- package/dist/types/elements/tt/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcIf.d.ts +1 -0
- package/dist/types/elements/{SwcIf.d.ts.map → tt/SwcIf.d.ts.map} +1 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcLoop.d.ts +1 -0
- package/dist/types/elements/tt/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +1 -0
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/tt/register.d.ts +1 -0
- package/dist/types/elements/tt/register.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +5 -5
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +13 -12
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4189 -456
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/{elements/SwcAppEngine.ts → SwcAppEngine.ts} +12 -7
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +30 -27
- package/src/decorators/applySlot.ts +228 -0
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +20 -19
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +10 -12
- package/src/decorators/elementDefine.ts +80 -57
- package/src/decorators/emitCustomEvent.ts +21 -26
- package/src/decorators/index.ts +2 -1
- package/src/decorators/lifecycles.ts +76 -11
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/elements/{SwcAppMixin.ts → SwcApp.ts} +98 -31
- package/src/elements/index.ts +11 -1
- package/src/elements/tt/SwcAppMixin.ts +13 -0
- package/src/elements/tt/SwcAsync.ts +139 -0
- package/src/elements/tt/SwcAsyncTemplate.ts +126 -0
- package/src/elements/tt/SwcChoose.ts +182 -0
- package/src/elements/tt/SwcChooseTemplate.ts +229 -0
- package/src/elements/tt/SwcIf.ts +145 -0
- package/src/elements/tt/SwcIfTemplate.ts +158 -0
- package/src/elements/tt/SwcLoop.ts +222 -0
- package/src/elements/tt/SwcLoopTemplate.ts +255 -0
- package/src/elements/tt/SwcSubTemplates.ts +6 -0
- package/src/elements/tt/register.ts +720 -0
- package/src/index.ts +13 -9
- package/src/types/window.d.ts +43 -0
- package/src/types.ts +9 -8
- package/src/utils/Utils.ts +28 -24
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/cjs/elements/SwcAppEngine.js.map +0 -7
- package/dist/cjs/elements/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/SwcAsync.js +0 -129
- package/dist/cjs/elements/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/SwcChoose.js +0 -155
- package/dist/cjs/elements/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/SwcIf.js +0 -117
- package/dist/cjs/elements/SwcIf.js.map +0 -7
- package/dist/cjs/elements/SwcLoop.js +0 -176
- package/dist/cjs/elements/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/SwcSubTemplates.js +0 -13
- package/dist/cjs/elements/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/register.js +0 -1026
- package/dist/cjs/elements/register.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/elements/SwcAppEngine.js.map +0 -7
- package/dist/esm/elements/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/SwcAsync.js +0 -129
- package/dist/esm/elements/SwcAsync.js.map +0 -7
- package/dist/esm/elements/SwcChoose.js +0 -155
- package/dist/esm/elements/SwcChoose.js.map +0 -7
- package/dist/esm/elements/SwcIf.js +0 -117
- package/dist/esm/elements/SwcIf.js.map +0 -7
- package/dist/esm/elements/SwcLoop.js +0 -176
- package/dist/esm/elements/SwcLoop.js.map +0 -7
- package/dist/esm/elements/SwcSubTemplates.js +0 -13
- package/dist/esm/elements/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/register.js +0 -1007
- package/dist/esm/elements/register.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -20
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +0 -1
- package/dist/types/elements/SwcAppMixin.d.ts +0 -386
- package/dist/types/elements/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/SwcAsync.d.ts +0 -2
- package/dist/types/elements/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/SwcChoose.d.ts +0 -2
- package/dist/types/elements/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/SwcIf.d.ts +0 -2
- package/dist/types/elements/SwcLoop.d.ts +0 -2
- package/dist/types/elements/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/SwcSubTemplates.d.ts +0 -13
- package/dist/types/elements/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/register.d.ts +0 -4
- package/dist/types/elements/register.d.ts.map +0 -1
- package/src/elements/SwcAsync.ts +0 -126
- package/src/elements/SwcChoose.ts +0 -190
- package/src/elements/SwcIf.ts +0 -124
- package/src/elements/SwcLoop.ts +0 -205
- package/src/elements/SwcSubTemplates.ts +0 -6
- package/src/elements/register.ts +0 -1022
package/src/elements/SwcAsync.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { changedAttributeHost } from '../decorators/changedAttributeHost';
|
|
2
|
-
import { SwcUtils } from '../utils/Utils';
|
|
3
|
-
import { FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
4
|
-
import { ConvertUtils } from '@dooboostore/core-web';
|
|
5
|
-
import { attributeHost } from '../decorators';
|
|
6
|
-
|
|
7
|
-
class SwcAsync extends HTMLTemplateElement {
|
|
8
|
-
@attributeHost('value')
|
|
9
|
-
_value: any;
|
|
10
|
-
@attributeHost('replace-wrap-start')
|
|
11
|
-
_replaceWrapStart: string | null;
|
|
12
|
-
@attributeHost('replace-wrap-end')
|
|
13
|
-
_replaceWrapEnd: string | null; resultValue?: any;
|
|
14
|
-
|
|
15
|
-
get value(): boolean {
|
|
16
|
-
return this._value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set value(nv: any) {
|
|
20
|
-
this.executeAsync(nv);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private _nodes: Node[] = [];
|
|
24
|
-
|
|
25
|
-
@changedAttributeHost('value')
|
|
26
|
-
private setValue(valueAttr?: string | null) {
|
|
27
|
-
this.executeAsync(this._value);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// @changedAttributeHost('replace-wrap')
|
|
31
|
-
// private setReplaceWrap() {
|
|
32
|
-
// this.executeAsync(this._value);
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
private executeAsync(result: any = this._value) {
|
|
36
|
-
if (result === undefined || result === null) {
|
|
37
|
-
this.refresh('default');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (result instanceof Promise) {
|
|
42
|
-
this.refresh('loading');
|
|
43
|
-
result
|
|
44
|
-
.then(v => {
|
|
45
|
-
this.resultValue = v;
|
|
46
|
-
this.refresh('success');
|
|
47
|
-
})
|
|
48
|
-
.catch(e => {
|
|
49
|
-
console.error('[SWC-ASYNC] Promise rejected:', e);
|
|
50
|
-
this.resultValue = e;
|
|
51
|
-
this.refresh('error');
|
|
52
|
-
});
|
|
53
|
-
} else {
|
|
54
|
-
this.resultValue = result;
|
|
55
|
-
this.refresh('success');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {
|
|
60
|
-
let config: any = undefined;
|
|
61
|
-
if (wrap) {
|
|
62
|
-
config = {
|
|
63
|
-
expression: {
|
|
64
|
-
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
65
|
-
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
66
|
-
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const ae = new ActionExpression(html, config);
|
|
71
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
72
|
-
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
for (const expr of ae.getExpressions('replace')) {
|
|
75
|
-
try {
|
|
76
|
-
const value = FunctionUtils.executeReturn({
|
|
77
|
-
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
78
|
-
context,
|
|
79
|
-
args: groupArgs
|
|
80
|
-
});
|
|
81
|
-
ae.replace(expr, String(value));
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return ae.getUnprocessedTemplate();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
refresh(state: string = 'default') {
|
|
90
|
-
// console.log('rrrrrrrrrrrrrrrrr', state);
|
|
91
|
-
this.cleanup();
|
|
92
|
-
const portal = SwcUtils.getParentContainer(this);
|
|
93
|
-
if (!portal) return;
|
|
94
|
-
|
|
95
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
96
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
97
|
-
|
|
98
|
-
const t = this.content.querySelector(`template[is="swc-${state}"]`) as HTMLTemplateElement;
|
|
99
|
-
if (t) {
|
|
100
|
-
let htmlString = t.innerHTML;
|
|
101
|
-
const groupArgs = { ...helperSet, $value: this._value, $state: state, $templateHost: this };
|
|
102
|
-
|
|
103
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
104
|
-
|
|
105
|
-
const temp = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
106
|
-
temp.innerHTML = htmlString;
|
|
107
|
-
const content = temp.content;
|
|
108
|
-
|
|
109
|
-
this._nodes = Array.from(content.childNodes);
|
|
110
|
-
this._nodes.forEach((node: any) => {
|
|
111
|
-
if (node instanceof HTMLElement) (node as any).__template_swc_host = this;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
portal.insertBefore(content, this.nextSibling);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private cleanup() {
|
|
119
|
-
this._nodes.forEach(n => n.parentElement?.removeChild(n));
|
|
120
|
-
this._nodes = [];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
disconnectedCallback() {
|
|
124
|
-
this.cleanup();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { changedAttributeHost } from '../decorators/changedAttributeHost';
|
|
2
|
-
import { SwcUtils } from '../utils/Utils';
|
|
3
|
-
import { FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
4
|
-
import { ConvertUtils } from '@dooboostore/core-web';
|
|
5
|
-
import { SwcChooseInterface } from '../types';
|
|
6
|
-
import { attributeHost, getAttributeValue, getElementConfig } from '../decorators';
|
|
7
|
-
|
|
8
|
-
class SwcChoose extends HTMLTemplateElement implements SwcChooseInterface {
|
|
9
|
-
_value: any;
|
|
10
|
-
|
|
11
|
-
@attributeHost('replace-wrap-start')
|
|
12
|
-
_replaceWrapStart: string | null;
|
|
13
|
-
@attributeHost('replace-wrap-end')
|
|
14
|
-
_replaceWrapEnd: string | null;
|
|
15
|
-
|
|
16
|
-
private _nodes: Node[] = [];
|
|
17
|
-
private _previousTemplate: HTMLTemplateElement | null = null;
|
|
18
|
-
|
|
19
|
-
get value(): any {
|
|
20
|
-
return this._value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set value(nv: any) {
|
|
24
|
-
this._value = nv;
|
|
25
|
-
this.refresh(this._value);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor() {
|
|
29
|
-
super();
|
|
30
|
-
// console.log('swc chooooooooooooooooooooooooose constructor called!');
|
|
31
|
-
// console.log('swc cccccccss', this.getAttribute('value'));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// static get observedAttributes() {
|
|
35
|
-
// return ['value'];
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
attributeChangedCallback(na, o, n) {
|
|
39
|
-
// console.log('-----------------choooooooose attr origin', na, o, n);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@changedAttributeHost('value')
|
|
43
|
-
private setValue(value: any, o: string, n: string) {
|
|
44
|
-
console.log('chooooooose value', value)
|
|
45
|
-
this._value = value;
|
|
46
|
-
this.refresh(this._value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// @changedAttributeHost('replace-wrap')
|
|
50
|
-
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
51
|
-
// this.refresh();
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {
|
|
55
|
-
let config: any = undefined;
|
|
56
|
-
if (wrap) {
|
|
57
|
-
config = {
|
|
58
|
-
expression: {
|
|
59
|
-
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
60
|
-
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
61
|
-
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const ae = new ActionExpression(html, config);
|
|
66
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
67
|
-
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
for (const expr of ae.getExpressions('replace')) {
|
|
70
|
-
try {
|
|
71
|
-
const value = FunctionUtils.executeReturn({
|
|
72
|
-
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
73
|
-
context,
|
|
74
|
-
args: groupArgs
|
|
75
|
-
});
|
|
76
|
-
ae.replace(expr, String(value));
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return ae.getUnprocessedTemplate();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
refresh(value?: any) {
|
|
85
|
-
value = getAttributeValue(this, 'value') ?? this._value;
|
|
86
|
-
console.log('[DEBUG] SwcChoose.refresh called, value:', value);
|
|
87
|
-
const portal = SwcUtils.getParentContainer(this);
|
|
88
|
-
if (!portal) {
|
|
89
|
-
console.log('[DEBUG] SwcChoose portal is null!');
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;
|
|
94
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
95
|
-
const groupArgs = { ...helperSet, $value: value, $templateHost: this };
|
|
96
|
-
|
|
97
|
-
const templates = Array.from(this.content.querySelectorAll('template'));
|
|
98
|
-
let selected: HTMLTemplateElement | null = null;
|
|
99
|
-
|
|
100
|
-
for (const t of templates) {
|
|
101
|
-
if (t.getAttribute('is') === 'swc-when') {
|
|
102
|
-
const attrVal = t.getAttribute('test') || '';
|
|
103
|
-
let matches = false;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const result = FunctionUtils.executeReturn({
|
|
108
|
-
script: attrVal,
|
|
109
|
-
context: t,
|
|
110
|
-
args: groupArgs
|
|
111
|
-
});
|
|
112
|
-
matches = !!result;
|
|
113
|
-
// Use ActionExpression to parse and extract script from value attribute
|
|
114
|
-
// const ae = new ActionExpression(attrVal);
|
|
115
|
-
// const expr = ae.getFirstExpression('replace');
|
|
116
|
-
|
|
117
|
-
// if (expr) {
|
|
118
|
-
// const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
119
|
-
// const result = FunctionUtils.executeReturn({
|
|
120
|
-
// script: decodedScript,
|
|
121
|
-
// context: t,
|
|
122
|
-
// args: groupArgs
|
|
123
|
-
// });
|
|
124
|
-
// matches = !!result;
|
|
125
|
-
// } else {
|
|
126
|
-
// matches = String(attrVal) === String(value);
|
|
127
|
-
// }
|
|
128
|
-
|
|
129
|
-
if (matches) {
|
|
130
|
-
selected = t;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const target = selected || (this.content.querySelector('template[is="swc-otherwise"]') as HTMLTemplateElement);
|
|
137
|
-
|
|
138
|
-
const skipValue = target?.getAttribute?.('skip-if-same');
|
|
139
|
-
const skipValue2 = this._previousTemplate?.getAttribute?.('skip-if-same');
|
|
140
|
-
const hasSkipIfSame = target?.hasAttribute?.('skip-if-same');
|
|
141
|
-
const isSame = this._previousTemplate === target;
|
|
142
|
-
// console.log('---rrrr---', this._previousTemplate, target, hasSkipIfSame, isSame, skipValue, skipValue2);
|
|
143
|
-
if (hasSkipIfSame && isSame) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
this.cleanup();
|
|
148
|
-
this._previousTemplate = target;
|
|
149
|
-
|
|
150
|
-
if (target) {
|
|
151
|
-
let htmlString = target.innerHTML;
|
|
152
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
153
|
-
|
|
154
|
-
const result = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
155
|
-
result.innerHTML = htmlString;
|
|
156
|
-
const processedFragment = result.content;
|
|
157
|
-
|
|
158
|
-
// console.log('[DEBUG] SwcChoose processedFragment children:', processedFragment._childNodesInternal?.length);
|
|
159
|
-
this._nodes = Array.from(processedFragment.childNodes);
|
|
160
|
-
|
|
161
|
-
const setTemplateHost = (element: HTMLElement) => {
|
|
162
|
-
(element as any).__swc_template_host = this;
|
|
163
|
-
Array.from(element.children).forEach((child: any) => {
|
|
164
|
-
if (child instanceof HTMLElement) {
|
|
165
|
-
setTemplateHost(child);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
this._nodes.forEach((node: any) => {
|
|
171
|
-
if (node instanceof HTMLElement) {
|
|
172
|
-
setTemplateHost(node as HTMLElement);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${(portal as any)?.isConnected}`);
|
|
177
|
-
portal.insertBefore(processedFragment, this.nextSibling);
|
|
178
|
-
console.log('[DEBUG] SwcChoose after insertBefore');
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private cleanup() {
|
|
183
|
-
this._nodes.forEach(n => n.parentElement?.removeChild(n));
|
|
184
|
-
this._nodes = [];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
disconnectedCallback() {
|
|
188
|
-
this.cleanup();
|
|
189
|
-
}
|
|
190
|
-
}
|
package/src/elements/SwcIf.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { changedAttributeHost } from '../decorators/changedAttributeHost';
|
|
2
|
-
import { SwcUtils } from '../utils/Utils';
|
|
3
|
-
import { FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
4
|
-
import { ConvertUtils } from '@dooboostore/core-web';
|
|
5
|
-
import { SwcIfInterface } from '../types';
|
|
6
|
-
import { attributeHost, getAttributeValue } from '../decorators';
|
|
7
|
-
|
|
8
|
-
class SwcIf extends HTMLTemplateElement implements SwcIfInterface {
|
|
9
|
-
// id =
|
|
10
|
-
// @attributeHost('value')
|
|
11
|
-
_value: any;
|
|
12
|
-
|
|
13
|
-
@attributeHost('replace-wrap-start')
|
|
14
|
-
_replaceWrapStart: string | null;
|
|
15
|
-
@attributeHost('replace-wrap-end')
|
|
16
|
-
_replaceWrapEnd: string | null;
|
|
17
|
-
|
|
18
|
-
@attributeHost('skip-if-same')
|
|
19
|
-
_skipIfSame: string | null;
|
|
20
|
-
|
|
21
|
-
private _nodes: Node[] = [];
|
|
22
|
-
|
|
23
|
-
get value(): boolean {
|
|
24
|
-
return this._value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
set value(nv: any) {
|
|
28
|
-
// this._value = nv;
|
|
29
|
-
this.refresh(nv);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor() {
|
|
33
|
-
super();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@changedAttributeHost('value')
|
|
37
|
-
private setValue(value: any, o: string, n: string) {
|
|
38
|
-
this._value = value;
|
|
39
|
-
this.refresh(this._value);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// @changedAttributeHost('replace-wrap')
|
|
43
|
-
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
44
|
-
// this.refresh();
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {
|
|
48
|
-
let config: any = undefined;
|
|
49
|
-
if (wrap) {
|
|
50
|
-
config = {
|
|
51
|
-
expression: {
|
|
52
|
-
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
53
|
-
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
54
|
-
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const ae = new ActionExpression(html, config);
|
|
59
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
60
|
-
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
for (const expr of ae.getExpressions('replace')) {
|
|
63
|
-
try {
|
|
64
|
-
const value = FunctionUtils.executeReturn({
|
|
65
|
-
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
66
|
-
context,
|
|
67
|
-
args: groupArgs
|
|
68
|
-
});
|
|
69
|
-
ae.replace(expr, String(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return ae.getUnprocessedTemplate();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
refresh(value?: any) {
|
|
78
|
-
const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value);
|
|
79
|
-
|
|
80
|
-
// skip-if-same 속성이 존재하고(true/빈 문자열), 이전 값과 새로운 값이 완전히 동일하면 렌더링 스킵!
|
|
81
|
-
if (this.hasAttribute('skip-if-same') && this._value === targetValue && this._nodes.length > 0) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.cleanup();
|
|
86
|
-
this._value = targetValue;
|
|
87
|
-
|
|
88
|
-
const portal = this.parentElement;
|
|
89
|
-
if (!portal || !this._value) return;
|
|
90
|
-
|
|
91
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
92
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
93
|
-
|
|
94
|
-
let htmlString = this.innerHTML;
|
|
95
|
-
const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };
|
|
96
|
-
|
|
97
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
98
|
-
|
|
99
|
-
const result = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
100
|
-
result.innerHTML = htmlString;
|
|
101
|
-
const processedFragment = result.content;
|
|
102
|
-
|
|
103
|
-
this._nodes = Array.from(processedFragment.childNodes);
|
|
104
|
-
this._nodes.forEach((node: any) => {
|
|
105
|
-
if (node instanceof HTMLElement) (node as any).__swc_template_host = this;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
portal.insertBefore(processedFragment, this.nextSibling);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private cleanup() {
|
|
112
|
-
this._nodes.forEach(n => {
|
|
113
|
-
const realNode = (n as any).__upgraded_instance || n;
|
|
114
|
-
if (realNode.parentElement) {
|
|
115
|
-
realNode.parentElement.removeChild(realNode);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
this._nodes = [];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
disconnectedCallback() {
|
|
122
|
-
this.cleanup();
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/elements/SwcLoop.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { changedAttributeHost } from '../decorators/changedAttributeHost';
|
|
2
|
-
import { SwcUtils } from '../utils/Utils';
|
|
3
|
-
import { FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
4
|
-
import { ConvertUtils } from '@dooboostore/core-web';
|
|
5
|
-
import { attributeHost, getAttributeValue } from '../decorators';
|
|
6
|
-
|
|
7
|
-
class SwcLoop extends HTMLTemplateElement {
|
|
8
|
-
_value: any[] = [];
|
|
9
|
-
|
|
10
|
-
@attributeHost('replace-wrap-start')
|
|
11
|
-
_replaceWrapStart: string | null;
|
|
12
|
-
@attributeHost('replace-wrap-end')
|
|
13
|
-
_replaceWrapEnd: string | null;
|
|
14
|
-
|
|
15
|
-
private _nodeGroups: Node[][] = [];
|
|
16
|
-
|
|
17
|
-
get value(): any[] {
|
|
18
|
-
return this._value;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
set value(nv: any[]) {
|
|
22
|
-
this._value = nv;
|
|
23
|
-
this.refresh(nv);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getValue(index: number) {
|
|
27
|
-
return this._value?.[index];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
super();
|
|
32
|
-
// console.log('swc SwcLoop constructor called!');
|
|
33
|
-
// console.log('swc SwcLoop', this.getAttribute('value'));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@changedAttributeHost('value')
|
|
37
|
-
private setValue(value: any, o: string, n: string) {
|
|
38
|
-
this._value = value;
|
|
39
|
-
this.refresh(this._value);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// @changedAttributeHost('replace-wrap')
|
|
43
|
-
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
44
|
-
// this.refresh();
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {
|
|
48
|
-
let config: any = undefined;
|
|
49
|
-
config = {
|
|
50
|
-
expression: {
|
|
51
|
-
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
52
|
-
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
53
|
-
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const ae = new ActionExpression(html, config);
|
|
57
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
58
|
-
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
const expressions = ae.getExpressions('replace');
|
|
61
|
-
for (const expr of expressions) {
|
|
62
|
-
const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
63
|
-
try {
|
|
64
|
-
const value = FunctionUtils.executeReturn({
|
|
65
|
-
script: script,
|
|
66
|
-
context,
|
|
67
|
-
args: groupArgs
|
|
68
|
-
});
|
|
69
|
-
ae.replace(expr, String(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return ae.getUnprocessedTemplate();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private createFragmentAndNodes(items: any[], helperSet: any, startIndex: number = 0): { fragment: DocumentFragment; newNodesGroup: Node[][] } {
|
|
78
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
79
|
-
const fragment = win.document.createDocumentFragment();
|
|
80
|
-
const newNodesGroup: Node[][] = [];
|
|
81
|
-
|
|
82
|
-
items.forEach((item, i) => {
|
|
83
|
-
const index = startIndex + i;
|
|
84
|
-
let htmlString = this.innerHTML;
|
|
85
|
-
const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
|
|
86
|
-
|
|
87
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
88
|
-
|
|
89
|
-
const temp = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
90
|
-
temp.innerHTML = htmlString;
|
|
91
|
-
|
|
92
|
-
const content = temp.content;
|
|
93
|
-
const nodes = Array.from(content.childNodes);
|
|
94
|
-
|
|
95
|
-
const setTemplateHost = (element: HTMLElement) => {
|
|
96
|
-
(element as any).__swc_template_host = this;
|
|
97
|
-
Array.from(element.children).forEach((child: any) => {
|
|
98
|
-
if (child instanceof HTMLElement) {
|
|
99
|
-
setTemplateHost(child);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
nodes.forEach((node: any) => {
|
|
105
|
-
if (node instanceof HTMLElement) {
|
|
106
|
-
setTemplateHost(node as HTMLElement);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
newNodesGroup.push(nodes);
|
|
110
|
-
fragment.appendChild(content);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return { fragment, newNodesGroup };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
appendItem(...items: any[]) {
|
|
117
|
-
if (!items || items.length <= 0) return;
|
|
118
|
-
const portal = SwcUtils.getParentContainer(this);
|
|
119
|
-
if (!portal) return;
|
|
120
|
-
|
|
121
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
122
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
123
|
-
|
|
124
|
-
const startIndex = this._value ? this._value.length : 0;
|
|
125
|
-
|
|
126
|
-
// 내부 상태(value) 업데이트 (기존 배열에 새 아이템 추가)
|
|
127
|
-
if (this._value !== items) {
|
|
128
|
-
this._value = [...(this._value || []), ...items];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
132
|
-
this._nodeGroups.push(...newNodesGroup);
|
|
133
|
-
|
|
134
|
-
console.log('뭐야 씨발');
|
|
135
|
-
// append 위치 계산: 기존에 그려진 마지막 노드 뒤에 삽입, 없으면 템플릿 바로 뒤에 삽입
|
|
136
|
-
let insertReference: Node | null = this.nextSibling;
|
|
137
|
-
if (this._nodeGroups.length > items.length) {
|
|
138
|
-
const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
139
|
-
if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
140
|
-
const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
141
|
-
insertReference = lastNode.nextSibling;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
portal.insertBefore(fragment, insertReference);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async prependItem(...items: any[]) {
|
|
149
|
-
if (!items || items.length <= 0) return;
|
|
150
|
-
const portal = SwcUtils.getParentContainer(this);
|
|
151
|
-
if (!portal) return;
|
|
152
|
-
|
|
153
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
154
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
155
|
-
|
|
156
|
-
// 내부 상태(value) 업데이트 (기존 배열의 앞쪽에 새 아이템 추가)
|
|
157
|
-
if (this._value !== items) {
|
|
158
|
-
this._value = [...items, ...(this._value || [])];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
|
|
162
|
-
|
|
163
|
-
// 기존의 nodeGroups 배열 맨 앞에 새로운 그룹들을 추가
|
|
164
|
-
this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
165
|
-
|
|
166
|
-
// prepend 위치: 이 템플릿(SwcLoop) 노드의 바로 다음 위치 (가장 위)
|
|
167
|
-
portal.insertBefore(fragment, this.nextSibling);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
refresh(value?: any) {
|
|
171
|
-
// 1. 그릴 대상 확정
|
|
172
|
-
const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value ?? []);
|
|
173
|
-
|
|
174
|
-
// 2. 화면 정리
|
|
175
|
-
this.cleanup();
|
|
176
|
-
|
|
177
|
-
// 3. 상태 완전 교체 (이어붙이지 않음!)
|
|
178
|
-
this._value = targetValue;
|
|
179
|
-
|
|
180
|
-
if (!this._value || this._value.length <= 0) return;
|
|
181
|
-
|
|
182
|
-
// 4. 화면 다시 그리기 (appendItem을 쓰지 않고 바로 그리기)
|
|
183
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
184
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
185
|
-
helperSet.$templateHost = this;
|
|
186
|
-
const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
|
|
187
|
-
|
|
188
|
-
this._nodeGroups = newNodesGroup;
|
|
189
|
-
const portal = SwcUtils.getParentContainer(this);
|
|
190
|
-
if (portal) {
|
|
191
|
-
// console.log('append????!~~~~~!?',fragment)
|
|
192
|
-
portal.insertBefore(fragment, this.nextSibling);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private cleanup() {
|
|
197
|
-
console.log('누가 cleanup');
|
|
198
|
-
this._nodeGroups.forEach(nodes => nodes.forEach(n => n.parentElement?.removeChild(n)));
|
|
199
|
-
this._nodeGroups = [];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
disconnectedCallback() {
|
|
203
|
-
this.cleanup();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
class SwcLoading extends HTMLTemplateElement {}
|
|
2
|
-
class SwcError extends HTMLTemplateElement {}
|
|
3
|
-
class SwcSuccess extends HTMLTemplateElement {}
|
|
4
|
-
class SwcWhen extends HTMLTemplateElement {}
|
|
5
|
-
class SwcOtherwise extends HTMLTemplateElement {}
|
|
6
|
-
class SwcDefault extends HTMLTemplateElement {}
|