@dooboostore/simple-web-component 1.0.47 → 1.0.49
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 +223 -27
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +412 -16
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +244 -225
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +5 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +244 -0
- package/dist/cjs/decorators/mutationObserver.js.map +7 -0
- package/dist/cjs/decorators/query.js +129 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +191 -0
- package/dist/cjs/decorators/resizeObserver.js.map +7 -0
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +413 -16
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +249 -230
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +5 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +226 -0
- package/dist/esm/decorators/mutationObserver.js.map +7 -0
- package/dist/esm/decorators/query.js +129 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +173 -0
- package/dist/esm/decorators/resizeObserver.js.map +7 -0
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2413 -889
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +93 -23
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +5 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +46 -0
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +63 -8
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +48 -0
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -0
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2413 -889
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +426 -23
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +301 -317
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +5 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +304 -0
- package/src/decorators/query.ts +182 -117
- package/src/decorators/resizeObserver.ts +235 -0
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAppMixin.js +0 -1
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsync.js +0 -1
- package/dist/cjs/elements/tt/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChoose.js +0 -1
- package/dist/cjs/elements/tt/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIf.js +0 -1
- package/dist/cjs/elements/tt/SwcIf.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoop.js +0 -1
- package/dist/cjs/elements/tt/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/tt/register.js +0 -1
- package/dist/cjs/elements/tt/register.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/elements/tt/SwcAppMixin.js +0 -1
- package/dist/esm/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsync.js +0 -1
- package/dist/esm/elements/tt/SwcAsync.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcChoose.js +0 -1
- package/dist/esm/elements/tt/SwcChoose.js.map +0 -7
- package/dist/esm/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcIf.js +0 -1
- package/dist/esm/elements/tt/SwcIf.js.map +0 -7
- package/dist/esm/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoop.js +0 -1
- package/dist/esm/elements/tt/SwcLoop.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/tt/register.js +0 -1
- package/dist/esm/elements/tt/register.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/tt/register.d.ts +0 -1
- package/dist/types/elements/tt/register.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/elements/tt/SwcAppMixin.ts +0 -13
- package/src/elements/tt/SwcAsync.ts +0 -139
- package/src/elements/tt/SwcAsyncTemplate.ts +0 -126
- package/src/elements/tt/SwcChoose.ts +0 -182
- package/src/elements/tt/SwcChooseTemplate.ts +0 -229
- package/src/elements/tt/SwcIf.ts +0 -145
- package/src/elements/tt/SwcIfTemplate.ts +0 -158
- package/src/elements/tt/SwcLoop.ts +0 -222
- package/src/elements/tt/SwcLoopTemplate.ts +0 -255
- package/src/elements/tt/SwcSubTemplates.ts +0 -6
- package/src/elements/tt/register.ts +0 -720
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// import {SwcUtils} from '../../utils/Utils';
|
|
2
|
-
// import {ActionExpression, FunctionUtils} from '@dooboostore/core';
|
|
3
|
-
// import {ConvertUtils} from '@dooboostore/core-web';
|
|
4
|
-
// import {elementDefine, getAttributeValue} from '../../decorators';
|
|
5
|
-
//
|
|
6
|
-
// export default async (w: Window) => {
|
|
7
|
-
// const tagName = 'swc-loop';
|
|
8
|
-
// const existing = w.customElements.get(tagName);
|
|
9
|
-
// if (existing) return existing;
|
|
10
|
-
//
|
|
11
|
-
// @elementDefine(tagName, { window: w })
|
|
12
|
-
// class SwcLoop extends w.HTMLElement {
|
|
13
|
-
//
|
|
14
|
-
// private _value: any[] = [];
|
|
15
|
-
// private _replaceWrapStart: string | null = null;
|
|
16
|
-
// private _replaceWrapEnd: string | null = null;
|
|
17
|
-
// private _nodeGroups: Node[][] = [];
|
|
18
|
-
// private innerHTMLUserData: string;
|
|
19
|
-
//
|
|
20
|
-
// static get observedAttributes() {
|
|
21
|
-
// return ['value', 'replace-wrap-start', 'replace-wrap-end'];
|
|
22
|
-
// }
|
|
23
|
-
//
|
|
24
|
-
// get value(): any[] {
|
|
25
|
-
// return this._value;
|
|
26
|
-
// }
|
|
27
|
-
//
|
|
28
|
-
// set value(nv: any[]) {
|
|
29
|
-
// this._value = nv;
|
|
30
|
-
// this.refresh(nv);
|
|
31
|
-
// }
|
|
32
|
-
//
|
|
33
|
-
// getValue(index: number) {
|
|
34
|
-
// return this._value?.[index];
|
|
35
|
-
// }
|
|
36
|
-
//
|
|
37
|
-
// connectedCallback() {
|
|
38
|
-
// this.style.display = 'none';
|
|
39
|
-
// this.innerHTMLUserData = this.innerHTML;
|
|
40
|
-
// console.log('iiiiiiiiiiii', this.innerHTMLUserData, this.innerHTML,)
|
|
41
|
-
// // this.innerHTML='';
|
|
42
|
-
// if (!this.id) {
|
|
43
|
-
// throw new Error('[SWC] SwcLoop must have an "id" attribute for reliable cleanup.');
|
|
44
|
-
// }
|
|
45
|
-
// if (this.hasAttribute('value')) {
|
|
46
|
-
// this.refresh();
|
|
47
|
-
// }
|
|
48
|
-
// }
|
|
49
|
-
//
|
|
50
|
-
// attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
51
|
-
// switch (name) {
|
|
52
|
-
// case 'value':
|
|
53
|
-
// this._value = newValue ? JSON.parse(newValue) : [];
|
|
54
|
-
// this.refresh(this._value);
|
|
55
|
-
// break;
|
|
56
|
-
// case 'replace-wrap-start':
|
|
57
|
-
// this._replaceWrapStart = newValue;
|
|
58
|
-
// break;
|
|
59
|
-
// case 'replace-wrap-end':
|
|
60
|
-
// this._replaceWrapEnd = newValue;
|
|
61
|
-
// break;
|
|
62
|
-
// }
|
|
63
|
-
// }
|
|
64
|
-
//
|
|
65
|
-
// private replaceExpressions(html: string, groupArgs: any, context: any, wrap: { start: string, end: string }): string {
|
|
66
|
-
// let config: any = undefined;
|
|
67
|
-
// config = {
|
|
68
|
-
// expression: {
|
|
69
|
-
// replace: {start: `${wrap.start}`, end: `${wrap.end}`},
|
|
70
|
-
// callReturn: {start: `${wrap.start}=`, end: `${wrap.end}`},
|
|
71
|
-
// call: {start: `${wrap.start}@`, end: `${wrap.end}`}
|
|
72
|
-
// }
|
|
73
|
-
// };
|
|
74
|
-
// const ae = new ActionExpression(html, config);
|
|
75
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
76
|
-
// const expressions = ae.getExpressions('replace');
|
|
77
|
-
// for (const expr of expressions) {
|
|
78
|
-
// const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
79
|
-
// try {
|
|
80
|
-
// const value = FunctionUtils.executeReturn({
|
|
81
|
-
// script: script,
|
|
82
|
-
// context,
|
|
83
|
-
// args: groupArgs
|
|
84
|
-
// });
|
|
85
|
-
// ae.replace(expr, String(value));
|
|
86
|
-
// } catch (e) {
|
|
87
|
-
// console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
88
|
-
// }
|
|
89
|
-
// }
|
|
90
|
-
// return ae.getUnprocessedTemplate();
|
|
91
|
-
// }
|
|
92
|
-
//
|
|
93
|
-
// private createFragmentAndNodes(items: any[], helperSet: any, startIndex: number = 0): { fragment: DocumentFragment; newNodesGroup: Node[][] } {
|
|
94
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
95
|
-
// const fragment = win.document.createDocumentFragment();
|
|
96
|
-
// const newNodesGroup: Node[][] = [];
|
|
97
|
-
// items.forEach((item, i) => {
|
|
98
|
-
// const index = startIndex + i;
|
|
99
|
-
// let htmlString = this.innerHTMLUserData;
|
|
100
|
-
// const groupArgs = {...helperSet, $item: item, $index: index, $value: this._value};
|
|
101
|
-
// htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start: this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
102
|
-
// const temp = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
103
|
-
// temp.innerHTML = htmlString;
|
|
104
|
-
// const content = temp.content;
|
|
105
|
-
// const nodes = Array.from(content.childNodes);
|
|
106
|
-
// const setTemplateHost = (element: HTMLElement) => {
|
|
107
|
-
// (element as any).__swc_template_host = this;
|
|
108
|
-
// Array.from(element.children).forEach((child: any) => {
|
|
109
|
-
// if (child instanceof HTMLElement) {
|
|
110
|
-
// setTemplateHost(child);
|
|
111
|
-
// }
|
|
112
|
-
// });
|
|
113
|
-
// };
|
|
114
|
-
// nodes.forEach((node: any) => {
|
|
115
|
-
// if (node instanceof HTMLElement) {
|
|
116
|
-
// setTemplateHost(node as HTMLElement);
|
|
117
|
-
// }
|
|
118
|
-
// });
|
|
119
|
-
// newNodesGroup.push(nodes);
|
|
120
|
-
// fragment.appendChild(content);
|
|
121
|
-
// });
|
|
122
|
-
// return {fragment, newNodesGroup};
|
|
123
|
-
// }
|
|
124
|
-
//
|
|
125
|
-
// appendItem(...items: any[]) {
|
|
126
|
-
// if (!items || items.length <= 0) return;
|
|
127
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
128
|
-
// if (!portal) return;
|
|
129
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
130
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
131
|
-
// const startIndex = this._value ? this._value.length : 0;
|
|
132
|
-
// if (this._value !== items) {
|
|
133
|
-
// this._value = [...(this._value || []), ...items];
|
|
134
|
-
// }
|
|
135
|
-
// const {fragment, newNodesGroup} = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
136
|
-
// this._nodeGroups.push(...newNodesGroup);
|
|
137
|
-
// let insertReference: Node | null = this.nextSibling;
|
|
138
|
-
// if (this._nodeGroups.length > items.length) {
|
|
139
|
-
// const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
140
|
-
// if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
141
|
-
// const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
142
|
-
// insertReference = lastNode.nextSibling;
|
|
143
|
-
// }
|
|
144
|
-
// }
|
|
145
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
146
|
-
// let current = this.nextSibling;
|
|
147
|
-
// let endpointNode: Node | null = null;
|
|
148
|
-
// while (current) {
|
|
149
|
-
// if (current.nodeType === 8 && (current as Comment).data === endpointText) {
|
|
150
|
-
// endpointNode = current;
|
|
151
|
-
// break;
|
|
152
|
-
// }
|
|
153
|
-
// current = current.nextSibling;
|
|
154
|
-
// }
|
|
155
|
-
// portal.insertBefore(fragment, endpointNode || this.nextSibling);
|
|
156
|
-
// }
|
|
157
|
-
//
|
|
158
|
-
// async prependItem(...items: any[]) {
|
|
159
|
-
// if (!items || items.length <= 0) return;
|
|
160
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
161
|
-
// if (!portal) return;
|
|
162
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
163
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
164
|
-
// if (this._value !== items) {
|
|
165
|
-
// this._value = [...items, ...(this._value || [])];
|
|
166
|
-
// }
|
|
167
|
-
// const {fragment, newNodesGroup} = this.createFragmentAndNodes(items, helperSet, 0);
|
|
168
|
-
// this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
169
|
-
// portal.insertBefore(fragment, this.nextSibling);
|
|
170
|
-
// }
|
|
171
|
-
//
|
|
172
|
-
// refresh(value?: any) {
|
|
173
|
-
// if (!this.id) return;
|
|
174
|
-
// const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value ?? []);
|
|
175
|
-
// this.cleanup();
|
|
176
|
-
// this._value = targetValue;
|
|
177
|
-
// if (!this._value || this._value.length <= 0) return;
|
|
178
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
179
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
180
|
-
// const groupArgs = {...helperSet, $value: value, $templateHost: this};
|
|
181
|
-
// const {fragment, newNodesGroup} = this.createFragmentAndNodes(this._value, groupArgs, 0);
|
|
182
|
-
// this._nodeGroups = newNodesGroup;
|
|
183
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
184
|
-
// if (portal) {
|
|
185
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
186
|
-
// const endpoint = this.ownerDocument?.createComment(endpointText) || document.createComment(endpointText);
|
|
187
|
-
// fragment.appendChild(endpoint);
|
|
188
|
-
// portal.insertBefore(fragment, this.nextSibling);
|
|
189
|
-
// }
|
|
190
|
-
// }
|
|
191
|
-
//
|
|
192
|
-
// private cleanup() {
|
|
193
|
-
// if (this.id) {
|
|
194
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
195
|
-
// if (portal) {
|
|
196
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
197
|
-
// let current = this.nextSibling;
|
|
198
|
-
// const toRemove: Node[] = [];
|
|
199
|
-
// while (current) {
|
|
200
|
-
// toRemove.push(current);
|
|
201
|
-
// if (current.nodeType === 8 && (current as Comment).data === endpointText) {
|
|
202
|
-
// toRemove.forEach(n => {
|
|
203
|
-
// const realNode = (n as any).__upgraded_instance || n;
|
|
204
|
-
// if (realNode.parentElement) {
|
|
205
|
-
// realNode.parentElement.removeChild(realNode);
|
|
206
|
-
// }
|
|
207
|
-
// });
|
|
208
|
-
// break;
|
|
209
|
-
// }
|
|
210
|
-
// current = current.nextSibling;
|
|
211
|
-
// }
|
|
212
|
-
// }
|
|
213
|
-
// }
|
|
214
|
-
// this._nodeGroups = [];
|
|
215
|
-
// }
|
|
216
|
-
//
|
|
217
|
-
// disconnectedCallback() {
|
|
218
|
-
// this.cleanup();
|
|
219
|
-
// }
|
|
220
|
-
// }
|
|
221
|
-
// return w.customElements.whenDefined(tagName);
|
|
222
|
-
// }
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// import { changedAttributeThis } from '../../decorators/changedAttributeThis';
|
|
2
|
-
// import { SwcUtils } from '../../utils/Utils';
|
|
3
|
-
// import { FunctionUtils, ActionExpression } from '@dooboostore/core';
|
|
4
|
-
// import { ConvertUtils } from '@dooboostore/core-web';
|
|
5
|
-
// import { attributeThis, getAttributeValue } from '../../decorators';
|
|
6
|
-
//
|
|
7
|
-
// export class SwcLoopTemplate extends HTMLTemplateElement {
|
|
8
|
-
// _value: any[] = [];
|
|
9
|
-
//
|
|
10
|
-
// @attributeThis('replace-wrap-start')
|
|
11
|
-
// _replaceWrapStart: string | null;
|
|
12
|
-
// @attributeThis('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
|
-
// connectedCallback() {
|
|
37
|
-
// if (!this.id) {
|
|
38
|
-
// throw new Error('[SWC] SwcLoop must have an "id" attribute for reliable cleanup.');
|
|
39
|
-
// }
|
|
40
|
-
// if (this.hasAttribute('value')) {
|
|
41
|
-
// this.refresh();
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
//
|
|
45
|
-
// @changedAttributeThis('value')
|
|
46
|
-
// private setValue(value: any, o: string, n: string) {
|
|
47
|
-
// if (!this.id) return;
|
|
48
|
-
// this._value = value;
|
|
49
|
-
// this.refresh(this._value);
|
|
50
|
-
// }
|
|
51
|
-
//
|
|
52
|
-
// // @changedAttributeThis('replace-wrap')
|
|
53
|
-
// // private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
54
|
-
// // this.refresh();
|
|
55
|
-
// // }
|
|
56
|
-
//
|
|
57
|
-
// private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {
|
|
58
|
-
// let config: any = undefined;
|
|
59
|
-
// config = {
|
|
60
|
-
// expression: {
|
|
61
|
-
// replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
62
|
-
// callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
63
|
-
// call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
64
|
-
// }
|
|
65
|
-
// };
|
|
66
|
-
// const ae = new ActionExpression(html, config);
|
|
67
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
68
|
-
//
|
|
69
|
-
// // @ts-ignore
|
|
70
|
-
// const expressions = ae.getExpressions('replace');
|
|
71
|
-
// for (const expr of expressions) {
|
|
72
|
-
// const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
73
|
-
// try {
|
|
74
|
-
// const value = FunctionUtils.executeReturn({
|
|
75
|
-
// script: script,
|
|
76
|
-
// context,
|
|
77
|
-
// args: groupArgs
|
|
78
|
-
// });
|
|
79
|
-
// ae.replace(expr, String(value));
|
|
80
|
-
// } catch (e) {
|
|
81
|
-
// console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
82
|
-
// }
|
|
83
|
-
// }
|
|
84
|
-
// return ae.getUnprocessedTemplate();
|
|
85
|
-
// }
|
|
86
|
-
//
|
|
87
|
-
// private createFragmentAndNodes(items: any[], helperSet: any, startIndex: number = 0): { fragment: DocumentFragment; newNodesGroup: Node[][] } {
|
|
88
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
89
|
-
// const fragment = win.document.createDocumentFragment();
|
|
90
|
-
// const newNodesGroup: Node[][] = [];
|
|
91
|
-
//
|
|
92
|
-
// items.forEach((item, i) => {
|
|
93
|
-
// const index = startIndex + i;
|
|
94
|
-
// let htmlString = this.innerHTML;
|
|
95
|
-
// const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
|
|
96
|
-
//
|
|
97
|
-
// htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});
|
|
98
|
-
//
|
|
99
|
-
// const temp = this.ownerDocument?.createElement('template') || document.createElement('template');
|
|
100
|
-
// temp.innerHTML = htmlString;
|
|
101
|
-
//
|
|
102
|
-
// const content = temp.content;
|
|
103
|
-
// const nodes = Array.from(content.childNodes);
|
|
104
|
-
//
|
|
105
|
-
// const setTemplateHost = (element: HTMLElement) => {
|
|
106
|
-
// (element as any).__swc_template_host = this;
|
|
107
|
-
// Array.from(element.children).forEach((child: any) => {
|
|
108
|
-
// if (child instanceof HTMLElement) {
|
|
109
|
-
// setTemplateHost(child);
|
|
110
|
-
// }
|
|
111
|
-
// });
|
|
112
|
-
// };
|
|
113
|
-
//
|
|
114
|
-
// nodes.forEach((node: any) => {
|
|
115
|
-
// if (node instanceof HTMLElement) {
|
|
116
|
-
// setTemplateHost(node as HTMLElement);
|
|
117
|
-
// }
|
|
118
|
-
// });
|
|
119
|
-
// newNodesGroup.push(nodes);
|
|
120
|
-
// fragment.appendChild(content);
|
|
121
|
-
// });
|
|
122
|
-
//
|
|
123
|
-
// return { fragment, newNodesGroup };
|
|
124
|
-
// }
|
|
125
|
-
//
|
|
126
|
-
// appendItem(...items: any[]) {
|
|
127
|
-
// if (!items || items.length <= 0) return;
|
|
128
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
129
|
-
// if (!portal) return;
|
|
130
|
-
//
|
|
131
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
132
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
133
|
-
//
|
|
134
|
-
// const startIndex = this._value ? this._value.length : 0;
|
|
135
|
-
//
|
|
136
|
-
// // 내부 상태(value) 업데이트 (기존 배열에 새 아이템 추가)
|
|
137
|
-
// if (this._value !== items) {
|
|
138
|
-
// this._value = [...(this._value || []), ...items];
|
|
139
|
-
// }
|
|
140
|
-
//
|
|
141
|
-
// const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
142
|
-
// this._nodeGroups.push(...newNodesGroup);
|
|
143
|
-
//
|
|
144
|
-
// // console.log('뭐야 씨발');
|
|
145
|
-
// // append 위치 계산: 기존에 그려진 마지막 노드 뒤에 삽입, 없으면 템플릿 바로 뒤에 삽입
|
|
146
|
-
// let insertReference: Node | null = this.nextSibling;
|
|
147
|
-
// if (this._nodeGroups.length > items.length) {
|
|
148
|
-
// const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
149
|
-
// if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
150
|
-
// const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
151
|
-
// insertReference = lastNode.nextSibling;
|
|
152
|
-
// }
|
|
153
|
-
// }
|
|
154
|
-
//
|
|
155
|
-
// // SSR endpoint handling: if we append, we should find the old endpoint and remove it or insert before it.
|
|
156
|
-
// // However, it's safer to just cleanup and redraw for now, OR find the endpoint.
|
|
157
|
-
// // For appendItem, we find the endpoint comment and insert before it.
|
|
158
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
159
|
-
// let current = this.nextSibling;
|
|
160
|
-
// let endpointNode: Node | null = null;
|
|
161
|
-
// while (current) {
|
|
162
|
-
// if (current.nodeType === 8 && (current as Comment).data === endpointText) {
|
|
163
|
-
// endpointNode = current;
|
|
164
|
-
// break;
|
|
165
|
-
// }
|
|
166
|
-
// current = current.nextSibling;
|
|
167
|
-
// }
|
|
168
|
-
//
|
|
169
|
-
// portal.insertBefore(fragment, endpointNode || this.nextSibling);
|
|
170
|
-
// }
|
|
171
|
-
//
|
|
172
|
-
// async prependItem(...items: any[]) {
|
|
173
|
-
// if (!items || items.length <= 0) return;
|
|
174
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
175
|
-
// if (!portal) return;
|
|
176
|
-
//
|
|
177
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
178
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
179
|
-
//
|
|
180
|
-
// // 내부 상태(value) 업데이트 (기존 배열의 앞쪽에 새 아이템 추가)
|
|
181
|
-
// if (this._value !== items) {
|
|
182
|
-
// this._value = [...items, ...(this._value || [])];
|
|
183
|
-
// }
|
|
184
|
-
//
|
|
185
|
-
// const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
|
|
186
|
-
//
|
|
187
|
-
// // 기존의 nodeGroups 배열 맨 앞에 새로운 그룹들을 추가
|
|
188
|
-
// this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
189
|
-
//
|
|
190
|
-
// // prepend 위치: 이 템플릿(SwcLoop) 노드의 바로 다음 위치 (가장 위)
|
|
191
|
-
// portal.insertBefore(fragment, this.nextSibling);
|
|
192
|
-
// }
|
|
193
|
-
//
|
|
194
|
-
// refresh(value?: any) {
|
|
195
|
-
// if (!this.id) return;
|
|
196
|
-
// // 1. 그릴 대상 확정
|
|
197
|
-
// const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value ?? []);
|
|
198
|
-
//
|
|
199
|
-
// // 2. 화면 정리
|
|
200
|
-
// this.cleanup();
|
|
201
|
-
//
|
|
202
|
-
// // 3. 상태 완전 교체 (이어붙이지 않음!)
|
|
203
|
-
// this._value = targetValue;
|
|
204
|
-
//
|
|
205
|
-
// if (!this._value || this._value.length <= 0) return;
|
|
206
|
-
//
|
|
207
|
-
// // 4. 화면 다시 그리기 (appendItem을 쓰지 않고 바로 그리기)
|
|
208
|
-
// const win = this.ownerDocument?.defaultView || window;
|
|
209
|
-
// const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
210
|
-
// helperSet.$templateHost = this;
|
|
211
|
-
// const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
|
|
212
|
-
//
|
|
213
|
-
// this._nodeGroups = newNodesGroup;
|
|
214
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
215
|
-
// if (portal) {
|
|
216
|
-
// // Add endpoint comment node
|
|
217
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
218
|
-
// const endpoint = this.ownerDocument?.createComment(endpointText) || document.createComment(endpointText);
|
|
219
|
-
// fragment.appendChild(endpoint);
|
|
220
|
-
//
|
|
221
|
-
// portal.insertBefore(fragment, this.nextSibling);
|
|
222
|
-
// }
|
|
223
|
-
// }
|
|
224
|
-
//
|
|
225
|
-
// private cleanup() {
|
|
226
|
-
// if (this.id) {
|
|
227
|
-
// const portal = SwcUtils.getParentContainer(this);
|
|
228
|
-
// if (portal) {
|
|
229
|
-
// const endpointText = `swc-loop endpoint id:${this.id}`;
|
|
230
|
-
// let current = this.nextSibling;
|
|
231
|
-
// const toRemove: Node[] = [];
|
|
232
|
-
//
|
|
233
|
-
// while (current) {
|
|
234
|
-
// toRemove.push(current);
|
|
235
|
-
// if (current.nodeType === 8 && (current as Comment).data === endpointText) {
|
|
236
|
-
// // Found the endpoint!
|
|
237
|
-
// toRemove.forEach(n => {
|
|
238
|
-
// const realNode = (n as any).__upgraded_instance || n;
|
|
239
|
-
// if (realNode.parentElement) {
|
|
240
|
-
// realNode.parentElement.removeChild(realNode);
|
|
241
|
-
// }
|
|
242
|
-
// });
|
|
243
|
-
// break;
|
|
244
|
-
// }
|
|
245
|
-
// current = current.nextSibling;
|
|
246
|
-
// }
|
|
247
|
-
// }
|
|
248
|
-
// }
|
|
249
|
-
// this._nodeGroups = [];
|
|
250
|
-
// }
|
|
251
|
-
//
|
|
252
|
-
// disconnectedCallback() {
|
|
253
|
-
// this.cleanup();
|
|
254
|
-
// }
|
|
255
|
-
// }
|
|
@@ -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 {}
|