@dooboostore/simple-web-component 1.0.33 → 1.0.35
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 +23 -30
- package/dist/cjs/decorators/addEventListener.js.map +1 -1
- package/dist/cjs/decorators/applyAttribute.js +67 -57
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +80 -70
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +5 -8
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +66 -56
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +35 -29
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +32 -12
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +238 -180
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +67 -48
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +50 -39
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +14 -8
- package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +154 -81
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +28 -18
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +68 -45
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +52 -30
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +109 -35
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +263 -131
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -2
- package/dist/cjs/router/ElementRouter.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +25 -7
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js.map +1 -1
- package/dist/esm/decorators/applyAttribute.js +67 -57
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +80 -70
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +5 -8
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +66 -56
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +35 -29
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +32 -12
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +240 -182
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +67 -48
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +50 -39
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +14 -7
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +156 -82
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +28 -18
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +69 -46
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +53 -31
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +110 -36
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +264 -132
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +5 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +25 -7
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +4 -1
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +5 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +4 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +5 -1
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +5 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -0
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +5 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +9 -3
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +12 -7
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +4 -1
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +5 -5
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +74 -61
- package/src/decorators/applyClass.ts +91 -77
- package/src/decorators/applyNode.ts +16 -13
- package/src/decorators/applyStyle.ts +75 -61
- package/src/decorators/attribute.ts +55 -43
- package/src/decorators/changedAttributeHost.ts +49 -15
- package/src/decorators/elementDefine.ts +401 -340
- package/src/decorators/emitCustomEvent.ts +92 -62
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/setProperty.ts +58 -44
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
- package/src/elements/SwcAppEngine.ts +19 -13
- package/src/elements/SwcAppMixin.ts +214 -102
- package/src/elements/SwcAsync.ts +28 -17
- package/src/elements/SwcChoose.ts +94 -36
- package/src/elements/SwcIf.ts +59 -22
- package/src/elements/SwcLoop.ts +140 -27
- package/src/elements/register.ts +319 -100
- package/src/types.ts +1 -0
- package/src/utils/Utils.ts +38 -10
- package/tsconfig.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcIf.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcIfInterface } from '../types';\nimport { attributeHost } from '../decorators';\n\nclass SwcIf extends HTMLTemplateElement implements SwcIfInterface {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAE7B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcIfInterface } from '../types';\nimport { attributeHost, getAttributeValue } from '../decorators';\n\nclass SwcIf extends HTMLTemplateElement implements SwcIfInterface {\n // id =\n // @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap-start')\n _replaceWrapStart: string | null;\n @attributeHost('replace-wrap-end')\n _replaceWrapEnd: string | null;\n\n @attributeHost('skip-if-same')\n _skipIfSame: string | null;\n\n private _nodes: Node[] = [];\n\n get value(): boolean {\n return this._value;\n }\n\n set value(nv: any) {\n // this._value = nv;\n this.refresh(nv);\n }\n\n constructor() {\n super();\n }\n\n @changedAttributeHost('value')\n private setValue(value: any, o: string, n: string) {\n this._value = value;\n this.refresh(this._value);\n }\n\n // @changedAttributeHost('replace-wrap')\n // private setReplaceWrap(replaceWrapAttr?: string | null) {\n // this.refresh();\n // }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {\n let config: any = undefined;\n if (wrap) {\n config = {\n expression: {\n replace: { start: `${wrap.start}`, end: `${wrap.end}` },\n callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },\n call: { start: `${wrap.start}@`, end: `${wrap.end}` }\n }\n };\n }\n const ae = new ActionExpression(html, config);\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions('replace')) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value?: any) {\n const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value);\n\n // skip-if-same 속성이 존재하고(true/빈 문자열), 이전 값과 새로운 값이 완전히 동일하면 렌더링 스킵!\n if (this.hasAttribute('skip-if-same') && this._value === targetValue && this._nodes.length > 0) {\n return;\n }\n\n this.cleanup();\n this._value = targetValue;\n\n const portal = this.parentElement;\n if (!portal || !this._value) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n this._nodes.forEach((node: any) => {\n if (node instanceof HTMLElement) (node as any).__swc_template_host = this;\n });\n\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n const realNode = (n as any).__upgraded_instance || n;\n if (realNode.parentElement) {\n realNode.parentElement.removeChild(realNode);\n }\n });\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAE7B,SAAS,eAAe,yBAAyB;AAEjD,MAAM,cAAc,oBAAmB;EAerC,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AAEf,SAAK,QAAQ,EAAE;EACjB;EAEA,cAAA;AACE,UAAK;AAZC,SAAA,SAAiB,CAAA;EAazB;EAGQ,SAAS,OAAY,GAAW,GAAS;AAC/C,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM;EAC1B;;;;;EAOQ,mBAAmB,MAAc,WAAgB,SAAc,MAAkC;AACvG,QAAI,SAAc;AAClB,QAAI,MAAM;AACR,eAAS;QACP,YAAY;UACV,SAAS,EAAE,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,GAAG,KAAK,GAAG,GAAE;UACrD,YAAY,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;UACzD,MAAM,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;;;IAGzD;AACA,UAAM,KAAK,IAAI,iBAAiB,MAAM,MAAM;AAC5C,UAAM,MAAM,KAAK,eAAe,eAAe;AAG/C,eAAW,QAAQ,GAAG,eAAe,SAAS,GAAG;AAC/C,UAAI;AACF,cAAM,QAAQ,cAAc,cAAc;UACxC,QAAQ,aAAa,iBAA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,SAAS,CAAA;EAChB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA7GA,WAAA;EADC,cAAc,oBAAoB;;;AAGnC,WAAA;EADC,cAAc,kBAAkB;;;AAIjC,WAAA;EADC,cAAc,cAAc;;;AAmBrB,WAAA;EADP,qBAAqB,OAAO;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,33 +11,48 @@ import { changedAttributeHost } from "../decorators/changedAttributeHost.js";
|
|
|
11
11
|
import { SwcUtils } from "../utils/Utils.js";
|
|
12
12
|
import { FunctionUtils, ActionExpression } from "@dooboostore/core";
|
|
13
13
|
import { ConvertUtils } from "@dooboostore/core-web";
|
|
14
|
-
import { attributeHost } from "../decorators/index.js";
|
|
14
|
+
import { attributeHost, getAttributeValue } from "../decorators/index.js";
|
|
15
15
|
class SwcLoop extends HTMLTemplateElement {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this._nodeGroups = [];
|
|
19
|
-
}
|
|
20
16
|
get value() {
|
|
21
17
|
return this._value;
|
|
22
18
|
}
|
|
23
19
|
set value(nv) {
|
|
20
|
+
this._value = nv;
|
|
24
21
|
this.refresh(nv);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
this.
|
|
23
|
+
getValue(index) {
|
|
24
|
+
return this._value?.[index];
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this._value = [];
|
|
29
|
+
this._nodeGroups = [];
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
+
setValue(value, o, n) {
|
|
32
|
+
this._value = value;
|
|
33
|
+
this.refresh(this._value);
|
|
31
34
|
}
|
|
35
|
+
// @changedAttributeHost('replace-wrap')
|
|
36
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
37
|
+
// this.refresh();
|
|
38
|
+
// }
|
|
32
39
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
33
|
-
|
|
40
|
+
let config = void 0;
|
|
41
|
+
config = {
|
|
42
|
+
expression: {
|
|
43
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
44
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
45
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
46
|
+
}
|
|
47
|
+
};
|
|
34
48
|
const ae = new ActionExpression(html, config);
|
|
35
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
36
49
|
const win = this.ownerDocument?.defaultView || window;
|
|
37
|
-
|
|
50
|
+
const expressions = ae.getExpressions("replace");
|
|
51
|
+
for (const expr of expressions) {
|
|
52
|
+
const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
38
53
|
try {
|
|
39
54
|
const value = FunctionUtils.executeReturn({
|
|
40
|
-
script
|
|
55
|
+
script,
|
|
41
56
|
context,
|
|
42
57
|
args: groupArgs
|
|
43
58
|
});
|
|
@@ -48,30 +63,95 @@ class SwcLoop extends HTMLTemplateElement {
|
|
|
48
63
|
}
|
|
49
64
|
return ae.getUnprocessedTemplate();
|
|
50
65
|
}
|
|
51
|
-
|
|
52
|
-
this.cleanup();
|
|
53
|
-
if (value?.length <= 0)
|
|
54
|
-
return;
|
|
55
|
-
const portal = this.parentElement;
|
|
56
|
-
if (!portal)
|
|
57
|
-
return;
|
|
66
|
+
createFragmentAndNodes(items, helperSet, startIndex = 0) {
|
|
58
67
|
const win = this.ownerDocument?.defaultView || window;
|
|
59
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
60
68
|
const fragment = win.document.createDocumentFragment();
|
|
61
|
-
|
|
69
|
+
const newNodesGroup = [];
|
|
70
|
+
items.forEach((item, i) => {
|
|
71
|
+
const index = startIndex + i;
|
|
62
72
|
let htmlString = this.innerHTML;
|
|
63
73
|
const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
|
|
64
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
74
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
65
75
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
66
76
|
temp.innerHTML = htmlString;
|
|
67
77
|
const content = temp.content;
|
|
68
78
|
const nodes = Array.from(content.childNodes);
|
|
69
|
-
|
|
79
|
+
const setTemplateHost = (element) => {
|
|
80
|
+
element.__swc_template_host = this;
|
|
81
|
+
Array.from(element.children).forEach((child) => {
|
|
82
|
+
if (child instanceof HTMLElement) {
|
|
83
|
+
setTemplateHost(child);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
nodes.forEach((node) => {
|
|
88
|
+
if (node instanceof HTMLElement) {
|
|
89
|
+
setTemplateHost(node);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
newNodesGroup.push(nodes);
|
|
70
93
|
fragment.appendChild(content);
|
|
71
94
|
});
|
|
95
|
+
return { fragment, newNodesGroup };
|
|
96
|
+
}
|
|
97
|
+
appendItem(...items) {
|
|
98
|
+
if (!items || items.length <= 0)
|
|
99
|
+
return;
|
|
100
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
101
|
+
if (!portal)
|
|
102
|
+
return;
|
|
103
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
104
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
105
|
+
const startIndex = this._value ? this._value.length : 0;
|
|
106
|
+
if (this._value !== items) {
|
|
107
|
+
this._value = [...this._value || [], ...items];
|
|
108
|
+
}
|
|
109
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
110
|
+
this._nodeGroups.push(...newNodesGroup);
|
|
111
|
+
console.log("\uBB50\uC57C \uC528\uBC1C");
|
|
112
|
+
let insertReference = this.nextSibling;
|
|
113
|
+
if (this._nodeGroups.length > items.length) {
|
|
114
|
+
const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
115
|
+
if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
116
|
+
const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
117
|
+
insertReference = lastNode.nextSibling;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
portal.insertBefore(fragment, insertReference);
|
|
121
|
+
}
|
|
122
|
+
async prependItem(...items) {
|
|
123
|
+
if (!items || items.length <= 0)
|
|
124
|
+
return;
|
|
125
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
126
|
+
if (!portal)
|
|
127
|
+
return;
|
|
128
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
129
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
130
|
+
if (this._value !== items) {
|
|
131
|
+
this._value = [...items, ...this._value || []];
|
|
132
|
+
}
|
|
133
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
|
|
134
|
+
this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
72
135
|
portal.insertBefore(fragment, this.nextSibling);
|
|
73
136
|
}
|
|
137
|
+
refresh(value) {
|
|
138
|
+
const targetValue = value !== void 0 ? value : getAttributeValue(this, "value") ?? this._value ?? [];
|
|
139
|
+
this.cleanup();
|
|
140
|
+
this._value = targetValue;
|
|
141
|
+
if (!this._value || this._value.length <= 0)
|
|
142
|
+
return;
|
|
143
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
144
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
145
|
+
helperSet.$templateHost = this;
|
|
146
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
|
|
147
|
+
this._nodeGroups = newNodesGroup;
|
|
148
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
149
|
+
if (portal) {
|
|
150
|
+
portal.insertBefore(fragment, this.nextSibling);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
74
153
|
cleanup() {
|
|
154
|
+
console.log("\uB204\uAC00 cleanup");
|
|
75
155
|
this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
|
|
76
156
|
this._nodeGroups = [];
|
|
77
157
|
}
|
|
@@ -80,23 +160,17 @@ class SwcLoop extends HTMLTemplateElement {
|
|
|
80
160
|
}
|
|
81
161
|
}
|
|
82
162
|
__decorate([
|
|
83
|
-
attributeHost("
|
|
84
|
-
__metadata("design:type",
|
|
85
|
-
], SwcLoop.prototype, "
|
|
163
|
+
attributeHost("replace-wrap-start"),
|
|
164
|
+
__metadata("design:type", String)
|
|
165
|
+
], SwcLoop.prototype, "_replaceWrapStart", void 0);
|
|
86
166
|
__decorate([
|
|
87
|
-
attributeHost("replace-wrap"),
|
|
167
|
+
attributeHost("replace-wrap-end"),
|
|
88
168
|
__metadata("design:type", String)
|
|
89
|
-
], SwcLoop.prototype, "
|
|
169
|
+
], SwcLoop.prototype, "_replaceWrapEnd", void 0);
|
|
90
170
|
__decorate([
|
|
91
171
|
changedAttributeHost("value"),
|
|
92
172
|
__metadata("design:type", Function),
|
|
93
|
-
__metadata("design:paramtypes", []),
|
|
173
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
94
174
|
__metadata("design:returntype", void 0)
|
|
95
175
|
], SwcLoop.prototype, "setValue", null);
|
|
96
|
-
__decorate([
|
|
97
|
-
changedAttributeHost("replace-wrap"),
|
|
98
|
-
__metadata("design:type", Function),
|
|
99
|
-
__metadata("design:paramtypes", []),
|
|
100
|
-
__metadata("design:returntype", void 0)
|
|
101
|
-
], SwcLoop.prototype, "setReplaceWrap", null);
|
|
102
176
|
//# sourceMappingURL=SwcLoop.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcLoop.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { attributeHost } from '../decorators';\n\nclass SwcLoop extends HTMLTemplateElement {\n @attributeHost('
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAC7B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { attributeHost, getAttributeValue } from '../decorators';\n\nclass SwcLoop extends HTMLTemplateElement {\n _value: any[] = [];\n\n @attributeHost('replace-wrap-start')\n _replaceWrapStart: string | null;\n @attributeHost('replace-wrap-end')\n _replaceWrapEnd: string | null;\n\n private _nodeGroups: Node[][] = [];\n\n get value(): any[] {\n return this._value;\n }\n\n set value(nv: any[]) {\n this._value = nv;\n this.refresh(nv);\n }\n\n getValue(index: number) {\n return this._value?.[index];\n }\n\n constructor() {\n super();\n // console.log('swc SwcLoop constructor called!');\n // console.log('swc SwcLoop', this.getAttribute('value'));\n }\n\n @changedAttributeHost('value')\n private setValue(value: any, o: string, n: string) {\n this._value = value;\n this.refresh(this._value);\n }\n\n // @changedAttributeHost('replace-wrap')\n // private setReplaceWrap(replaceWrapAttr?: string | null) {\n // this.refresh();\n // }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {\n let config: any = undefined;\n config = {\n expression: {\n replace: { start: `${wrap.start}`, end: `${wrap.end}` },\n callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },\n call: { start: `${wrap.start}@`, end: `${wrap.end}` }\n }\n };\n const ae = new ActionExpression(html, config);\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n const expressions = ae.getExpressions('replace');\n for (const expr of expressions) {\n const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n try {\n const value = FunctionUtils.executeReturn({\n script: script,\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n private createFragmentAndNodes(items: any[], helperSet: any, startIndex: number = 0): { fragment: DocumentFragment; newNodesGroup: Node[][] } {\n const win = this.ownerDocument?.defaultView || window;\n const fragment = win.document.createDocumentFragment();\n const newNodesGroup: Node[][] = [];\n\n items.forEach((item, i) => {\n const index = startIndex + i;\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});\n\n const temp = this.ownerDocument?.createElement('template') || document.createElement('template');\n temp.innerHTML = htmlString;\n\n const content = temp.content;\n const nodes = Array.from(content.childNodes);\n\n const setTemplateHost = (element: HTMLElement) => {\n (element as any).__swc_template_host = this;\n Array.from(element.children).forEach((child: any) => {\n if (child instanceof HTMLElement) {\n setTemplateHost(child);\n }\n });\n };\n\n nodes.forEach((node: any) => {\n if (node instanceof HTMLElement) {\n setTemplateHost(node as HTMLElement);\n }\n });\n newNodesGroup.push(nodes);\n fragment.appendChild(content);\n });\n\n return { fragment, newNodesGroup };\n }\n\n appendItem(...items: any[]) {\n if (!items || items.length <= 0) return;\n const portal = SwcUtils.getParentContainer(this);\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const startIndex = this._value ? this._value.length : 0;\n\n // 내부 상태(value) 업데이트 (기존 배열에 새 아이템 추가)\n if (this._value !== items) {\n this._value = [...(this._value || []), ...items];\n }\n\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);\n this._nodeGroups.push(...newNodesGroup);\n\n console.log('뭐야 씨발');\n // append 위치 계산: 기존에 그려진 마지막 노드 뒤에 삽입, 없으면 템플릿 바로 뒤에 삽입\n let insertReference: Node | null = this.nextSibling;\n if (this._nodeGroups.length > items.length) {\n const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];\n if (lastExistingGroup && lastExistingGroup.length > 0) {\n const lastNode = lastExistingGroup[lastExistingGroup.length - 1];\n insertReference = lastNode.nextSibling;\n }\n }\n\n portal.insertBefore(fragment, insertReference);\n }\n\n async prependItem(...items: any[]) {\n if (!items || items.length <= 0) return;\n const portal = SwcUtils.getParentContainer(this);\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n // 내부 상태(value) 업데이트 (기존 배열의 앞쪽에 새 아이템 추가)\n if (this._value !== items) {\n this._value = [...items, ...(this._value || [])];\n }\n\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);\n\n // 기존의 nodeGroups 배열 맨 앞에 새로운 그룹들을 추가\n this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];\n\n // prepend 위치: 이 템플릿(SwcLoop) 노드의 바로 다음 위치 (가장 위)\n portal.insertBefore(fragment, this.nextSibling);\n }\n\n refresh(value?: any) {\n // 1. 그릴 대상 확정\n const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value ?? []);\n\n // 2. 화면 정리\n this.cleanup();\n\n // 3. 상태 완전 교체 (이어붙이지 않음!)\n this._value = targetValue;\n\n if (!this._value || this._value.length <= 0) return;\n\n // 4. 화면 다시 그리기 (appendItem을 쓰지 않고 바로 그리기)\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n helperSet.$templateHost = this;\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);\n\n this._nodeGroups = newNodesGroup;\n const portal = SwcUtils.getParentContainer(this);\n if (portal) {\n // console.log('append????!~~~~~!?',fragment)\n portal.insertBefore(fragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n console.log('누가 cleanup');\n this._nodeGroups.forEach(nodes => nodes.forEach(n => n.parentElement?.removeChild(n)));\n this._nodeGroups = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAC7B,SAAS,eAAe,yBAAyB;AAEjD,MAAM,gBAAgB,oBAAmB;EAUvC,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAS;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,EAAE;EACjB;EAEA,SAAS,OAAa;AACpB,WAAO,KAAK,SAAS,KAAK;EAC5B;EAEA,cAAA;AACE,UAAK;AAvBP,SAAA,SAAgB,CAAA;AAOR,SAAA,cAAwB,CAAA;EAmBhC;EAGQ,SAAS,OAAY,GAAW,GAAS;AAC/C,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM;EAC1B;;;;;EAOQ,mBAAmB,MAAc,WAAgB,SAAc,MAAkC;AACvG,QAAI,SAAc;AAClB,aAAS;MACP,YAAY;QACV,SAAS,EAAE,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,GAAG,KAAK,GAAG,GAAE;QACrD,YAAY,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;QACzD,MAAM,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;;;AAGvD,UAAM,KAAK,IAAI,iBAAiB,MAAM,MAAM;AAC5C,UAAM,MAAM,KAAK,eAAe,eAAe;AAG/C,UAAM,cAAc,GAAG,eAAe,SAAS;AAC/C,eAAW,QAAQ,aAAa;AAC9B,YAAM,SAAS,aAAa,iBAAiB,KAAK,QAAQ,IAAI,QAAQ;AACtE,UAAI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