@dooboostore/simple-web-component 1.0.0 → 1.0.2
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 +70 -78
- package/dist/cjs/decorators/addEventListener.js +42 -0
- package/dist/cjs/decorators/addEventListener.js.map +7 -0
- package/dist/cjs/decorators/attributeChanged.js +24 -4
- package/dist/cjs/decorators/attributeChanged.js.map +2 -2
- package/dist/cjs/decorators/{element.js → elementDefind.js} +91 -13
- package/dist/cjs/decorators/elementDefind.js.map +7 -0
- package/dist/cjs/decorators/query.js +53 -0
- package/dist/cjs/decorators/query.js.map +7 -0
- package/dist/cjs/decorators/queryAll.js +53 -0
- package/dist/cjs/decorators/queryAll.js.map +7 -0
- package/dist/cjs/elements/SwcChoose.js +117 -0
- package/dist/cjs/elements/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/SwcForOf.js +126 -0
- package/dist/cjs/elements/SwcForOf.js.map +7 -0
- package/dist/cjs/elements/SwcHTMLElementBase.js +102 -0
- package/dist/cjs/elements/SwcHTMLElementBase.js.map +7 -0
- package/dist/cjs/elements/SwcIf.js +127 -0
- package/dist/cjs/elements/SwcIf.js.map +7 -0
- package/dist/cjs/elements/SwcObject.js +115 -0
- package/dist/cjs/elements/SwcObject.js.map +7 -0
- package/dist/cjs/elements/SwcOther.js +56 -0
- package/dist/cjs/elements/SwcOther.js.map +7 -0
- package/dist/cjs/elements/SwcWhen.js +56 -0
- package/dist/cjs/elements/SwcWhen.js.map +7 -0
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +23 -0
- package/dist/esm/decorators/addEventListener.js.map +7 -0
- package/dist/esm/decorators/attributeChanged.js +24 -4
- package/dist/esm/decorators/attributeChanged.js.map +2 -2
- package/dist/esm/decorators/{element.js → elementDefind.js} +89 -11
- package/dist/esm/decorators/elementDefind.js.map +7 -0
- package/dist/esm/decorators/query.js +34 -0
- package/dist/esm/decorators/query.js.map +7 -0
- package/dist/esm/decorators/queryAll.js +34 -0
- package/dist/esm/decorators/queryAll.js.map +7 -0
- package/dist/esm/elements/SwcChoose.js +98 -0
- package/dist/esm/elements/SwcChoose.js.map +7 -0
- package/dist/esm/elements/SwcForOf.js +107 -0
- package/dist/esm/elements/SwcForOf.js.map +7 -0
- package/dist/esm/elements/SwcHTMLElementBase.js +83 -0
- package/dist/esm/elements/SwcHTMLElementBase.js.map +7 -0
- package/dist/esm/elements/SwcIf.js +108 -0
- package/dist/esm/elements/SwcIf.js.map +7 -0
- package/dist/esm/elements/SwcObject.js +96 -0
- package/dist/esm/elements/SwcObject.js.map +7 -0
- package/dist/esm/elements/SwcOther.js +37 -0
- package/dist/esm/elements/SwcOther.js.map +7 -0
- package/dist/esm/elements/SwcWhen.js +37 -0
- package/dist/esm/elements/SwcWhen.js.map +7 -0
- package/dist/esm/index.js +11 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +744 -14
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +16 -0
- package/dist/types/decorators/addEventListener.d.ts.map +1 -0
- package/dist/types/decorators/attributeChanged.d.ts +3 -1
- package/dist/types/decorators/attributeChanged.d.ts.map +1 -1
- package/dist/types/decorators/{element.d.ts → elementDefind.d.ts} +2 -2
- package/dist/types/decorators/elementDefind.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +13 -0
- package/dist/types/decorators/query.d.ts.map +1 -0
- package/dist/types/decorators/queryAll.d.ts +13 -0
- package/dist/types/decorators/queryAll.d.ts.map +1 -0
- package/dist/types/elements/SwcChoose.d.ts +12 -0
- package/dist/types/elements/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/SwcForOf.d.ts +14 -0
- package/dist/types/elements/SwcForOf.d.ts.map +1 -0
- package/dist/types/elements/SwcHTMLElementBase.d.ts +14 -0
- package/dist/types/elements/SwcHTMLElementBase.d.ts.map +1 -0
- package/dist/types/elements/SwcIf.d.ts +14 -0
- package/dist/types/elements/SwcIf.d.ts.map +1 -0
- package/dist/types/elements/SwcObject.d.ts +14 -0
- package/dist/types/elements/SwcObject.d.ts.map +1 -0
- package/dist/types/elements/SwcOther.d.ts +5 -0
- package/dist/types/elements/SwcOther.d.ts.map +1 -0
- package/dist/types/elements/SwcWhen.d.ts +5 -0
- package/dist/types/elements/SwcWhen.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +744 -14
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/decorators/addEventListener.ts +35 -0
- package/src/decorators/attributeChanged.ts +29 -6
- package/src/decorators/{element.ts → elementDefind.ts} +121 -11
- package/src/decorators/query.ts +46 -0
- package/src/decorators/queryAll.ts +46 -0
- package/src/elements/SwcChoose.ts +83 -0
- package/src/elements/SwcForOf.ts +95 -0
- package/src/elements/SwcHTMLElementBase.ts +93 -0
- package/src/elements/SwcIf.ts +92 -0
- package/src/elements/SwcObject.ts +78 -0
- package/src/elements/SwcOther.ts +14 -0
- package/src/elements/SwcWhen.ts +14 -0
- package/src/index.ts +12 -2
- package/dist/cjs/decorators/element.js.map +0 -7
- package/dist/esm/decorators/element.js.map +0 -7
- package/dist/types/decorators/element.d.ts.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
let SwcChoose = class SwcChoose2 extends HTMLElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this._observer = null;
|
|
15
|
+
this._value = void 0;
|
|
16
|
+
}
|
|
17
|
+
set value(val) {
|
|
18
|
+
this._value = val;
|
|
19
|
+
this.evaluate();
|
|
20
|
+
}
|
|
21
|
+
get value() {
|
|
22
|
+
return this._value;
|
|
23
|
+
}
|
|
24
|
+
styles() {
|
|
25
|
+
return `:host { display: contents; }`;
|
|
26
|
+
}
|
|
27
|
+
render() {
|
|
28
|
+
return `<slot id="choose-slot"></slot>`;
|
|
29
|
+
}
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
this._observer = new MutationObserver(() => this.evaluate());
|
|
32
|
+
this._observer.observe(this, { attributes: true, subtree: true, childList: true });
|
|
33
|
+
this.evaluate();
|
|
34
|
+
}
|
|
35
|
+
disconnectedCallback() {
|
|
36
|
+
this._observer?.disconnect();
|
|
37
|
+
}
|
|
38
|
+
evaluate() {
|
|
39
|
+
const whens = Array.from(this.querySelectorAll("swc-when"));
|
|
40
|
+
const other = this.querySelector("swc-other");
|
|
41
|
+
let matched = false;
|
|
42
|
+
const chooseValue = this.getAttribute("value") ?? this._value;
|
|
43
|
+
whens.forEach((when) => {
|
|
44
|
+
if (matched) {
|
|
45
|
+
when.style.display = "none";
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const testAttr = when.getAttribute("test");
|
|
49
|
+
if (testAttr === null)
|
|
50
|
+
return;
|
|
51
|
+
if (testAttr.includes("{{"))
|
|
52
|
+
return;
|
|
53
|
+
let isConditionMet = false;
|
|
54
|
+
if (chooseValue !== void 0 && chooseValue !== null) {
|
|
55
|
+
isConditionMet = String(chooseValue) === String(testAttr);
|
|
56
|
+
} else {
|
|
57
|
+
try {
|
|
58
|
+
if (testAttr === "true")
|
|
59
|
+
isConditionMet = true;
|
|
60
|
+
else if (testAttr === "false")
|
|
61
|
+
isConditionMet = false;
|
|
62
|
+
else
|
|
63
|
+
isConditionMet = !!new Function(`return ${testAttr}`)();
|
|
64
|
+
} catch (e) {
|
|
65
|
+
isConditionMet = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (isConditionMet) {
|
|
69
|
+
when.style.display = "";
|
|
70
|
+
matched = true;
|
|
71
|
+
} else {
|
|
72
|
+
when.style.display = "none";
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (other) {
|
|
76
|
+
other.style.display = matched ? "none" : "";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
__decorate([
|
|
81
|
+
style,
|
|
82
|
+
__metadata("design:type", Function),
|
|
83
|
+
__metadata("design:paramtypes", []),
|
|
84
|
+
__metadata("design:returntype", void 0)
|
|
85
|
+
], SwcChoose.prototype, "styles", null);
|
|
86
|
+
__decorate([
|
|
87
|
+
template,
|
|
88
|
+
__metadata("design:type", Function),
|
|
89
|
+
__metadata("design:paramtypes", []),
|
|
90
|
+
__metadata("design:returntype", void 0)
|
|
91
|
+
], SwcChoose.prototype, "render", null);
|
|
92
|
+
SwcChoose = __decorate([
|
|
93
|
+
elementDefind({ tagName: "swc-choose", useShadow: true })
|
|
94
|
+
], SwcChoose);
|
|
95
|
+
export {
|
|
96
|
+
SwcChoose
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=SwcChoose.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementDefind, template, style } from '../index';\n\n@elementDefind({ tagName: 'swc-choose', useShadow: true })\nexport class SwcChoose extends HTMLElement {\n private _observer: MutationObserver | null = null;\n private _value: any = undefined;\n\n set value(val: any) {\n this._value = val;\n this.evaluate();\n }\n\n get value() {\n return this._value;\n }\n\n @style\n styles() {\n return `:host { display: contents; }`;\n }\n\n @template\n render() {\n return `<slot id=\"choose-slot\"></slot>`;\n }\n\n connectedCallback() {\n this._observer = new MutationObserver(() => this.evaluate());\n this._observer.observe(this, { attributes: true, subtree: true, childList: true });\n this.evaluate();\n }\n\n disconnectedCallback() {\n this._observer?.disconnect();\n }\n\n private evaluate() {\n const whens = Array.from(this.querySelectorAll('swc-when'));\n const other = this.querySelector('swc-other');\n let matched = false;\n\n // 현재 choose에 설정된 value (문자열인 경우 \"null\", \"undefined\" 등 처리)\n const chooseValue = this.getAttribute('value') ?? this._value;\n\n whens.forEach(when => {\n if (matched) {\n (when as HTMLElement).style.display = 'none';\n return;\n }\n\n const testAttr = when.getAttribute('test');\n if (testAttr === null) return;\n if (testAttr.includes('{{')) return; // 아직 치환 전이면 스킵\n\n let isConditionMet = false;\n\n if (chooseValue !== undefined && chooseValue !== null) {\n // 1. 매칭 모드: choose의 value와 when의 test값이 같은지 비교\n isConditionMet = String(chooseValue) === String(testAttr);\n } else {\n // 2. 표현식 모드: testAttr 자체가 실행 가능한 코드인 경우\n try {\n if (testAttr === 'true') isConditionMet = true;\n else if (testAttr === 'false') isConditionMet = false;\n else isConditionMet = !!new Function(`return ${testAttr}`)();\n } catch (e) {\n isConditionMet = false;\n }\n }\n\n if (isConditionMet) {\n (when as HTMLElement).style.display = '';\n matched = true;\n } else {\n (when as HTMLElement).style.display = 'none';\n }\n });\n\n if (other) {\n (other as HTMLElement).style.display = matched ? 'none' : '';\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,eAAe,UAAU,aAAa;AAGxC,IAAM,YAAN,MAAMA,mBAAkB,YAAW;EAAnC,cAAA;;AACG,SAAA,YAAqC;AACrC,SAAA,SAAc;EA6ExB;EA3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ADC;;;;;AAMD,WAAA;EADC;;;;;AAlBU,YAAS,WAAA;EADrB,cAAc,EAAE,SAAS,cAAc,WAAW,KAAI,CAAE;GAC5C,SAAS;",
|
|
6
|
+
"names": ["SwcChoose"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
import { SwcHTMLElementBase } from "./SwcHTMLElementBase.js";
|
|
12
|
+
let SwcForOf = class SwcForOf2 extends SwcHTMLElementBase {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this._value = [];
|
|
16
|
+
}
|
|
17
|
+
set value(val) {
|
|
18
|
+
if (!Array.isArray(val))
|
|
19
|
+
val = [];
|
|
20
|
+
this._value = this.createReactiveProxy(val, () => this.renderAll(), (idx, v) => this.updateSingleRow(idx, v));
|
|
21
|
+
this.renderAll();
|
|
22
|
+
}
|
|
23
|
+
get value() {
|
|
24
|
+
return this._value;
|
|
25
|
+
}
|
|
26
|
+
styles() {
|
|
27
|
+
return `:host { display: contents; }`;
|
|
28
|
+
}
|
|
29
|
+
renderTemplate() {
|
|
30
|
+
return `<slot id="tpl-slot" style="display:none;"></slot>`;
|
|
31
|
+
}
|
|
32
|
+
connectedCallback() {
|
|
33
|
+
this.initCore();
|
|
34
|
+
this.renderAll();
|
|
35
|
+
}
|
|
36
|
+
updateSingleRow(index, newValue) {
|
|
37
|
+
const targets = this.querySelectorAll(`[slot="row-${index}"]`);
|
|
38
|
+
if (targets.length > 0) {
|
|
39
|
+
targets.forEach((target) => this.applyData(target, newValue, index));
|
|
40
|
+
} else {
|
|
41
|
+
this.renderRow(newValue, index);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
renderRow(item, index) {
|
|
45
|
+
if (!this.shadowRoot || this._masterTplNodes.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
const slotName = `row-${index}`;
|
|
48
|
+
if (!this.shadowRoot.querySelector(`slot[name="${slotName}"]`)) {
|
|
49
|
+
const slot = document.createElement("slot");
|
|
50
|
+
slot.name = slotName;
|
|
51
|
+
this.shadowRoot.appendChild(slot);
|
|
52
|
+
}
|
|
53
|
+
this._masterTplNodes.forEach((tplNode) => {
|
|
54
|
+
const clone = tplNode.cloneNode(true);
|
|
55
|
+
if (clone.nodeType === Node.ELEMENT_NODE) {
|
|
56
|
+
clone.setAttribute("slot", slotName);
|
|
57
|
+
clone.style.display = "";
|
|
58
|
+
} else if (clone.nodeType === Node.TEXT_NODE) {
|
|
59
|
+
if (clone.textContent?.trim().length === 0)
|
|
60
|
+
return;
|
|
61
|
+
const span = document.createElement("span");
|
|
62
|
+
span.setAttribute("slot", slotName);
|
|
63
|
+
span.appendChild(clone);
|
|
64
|
+
this.appendChild(span);
|
|
65
|
+
this.applyData(span, item, index);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.appendChild(clone);
|
|
69
|
+
this.applyData(clone, item, index);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
renderAll() {
|
|
73
|
+
if (this._masterTplNodes.length === 0 || !this.shadowRoot)
|
|
74
|
+
return;
|
|
75
|
+
Array.from(this.children).forEach((c) => {
|
|
76
|
+
const slot = c.getAttribute("slot");
|
|
77
|
+
if (slot && slot.startsWith("row-")) {
|
|
78
|
+
c.remove();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Array.from(this.shadowRoot.querySelectorAll("slot")).forEach((s) => {
|
|
82
|
+
if (s.id !== "tpl-slot")
|
|
83
|
+
s.remove();
|
|
84
|
+
});
|
|
85
|
+
this._value.forEach((item, index) => this.renderRow(item, index));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__decorate([
|
|
89
|
+
style,
|
|
90
|
+
__metadata("design:type", Function),
|
|
91
|
+
__metadata("design:paramtypes", []),
|
|
92
|
+
__metadata("design:returntype", void 0)
|
|
93
|
+
], SwcForOf.prototype, "styles", null);
|
|
94
|
+
__decorate([
|
|
95
|
+
template,
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", []),
|
|
98
|
+
__metadata("design:returntype", void 0)
|
|
99
|
+
], SwcForOf.prototype, "renderTemplate", null);
|
|
100
|
+
SwcForOf = __decorate([
|
|
101
|
+
elementDefind({ tagName: "swc-for-of", useShadow: true }),
|
|
102
|
+
__metadata("design:paramtypes", [])
|
|
103
|
+
], SwcForOf);
|
|
104
|
+
export {
|
|
105
|
+
SwcForOf
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=SwcForOf.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcForOf.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementDefind, template, style } from '../index';\nimport { SwcHTMLElementBase } from './SwcHTMLElementBase';\n\n@elementDefind({ tagName: 'swc-for-of', useShadow: true })\nexport class SwcForOf extends SwcHTMLElementBase {\n private _value: any[] = [];\n\n constructor() {\n super();\n }\n\n set value(val: any[]) {\n if (!Array.isArray(val)) val = [];\n this._value = this.createReactiveProxy(\n val,\n () => this.renderAll(),\n (idx, v) => this.updateSingleRow(idx, v)\n );\n this.renderAll();\n }\n\n get value(): any[] {\n return this._value;\n }\n\n @style\n styles() {\n return `:host { display: contents; }`;\n }\n\n @template\n renderTemplate() {\n return `<slot id=\"tpl-slot\" style=\"display:none;\"></slot>`;\n }\n\n connectedCallback() {\n this.initCore();\n this.renderAll();\n }\n\n public updateSingleRow(index: number, newValue: any) {\n const targets = this.querySelectorAll(`[slot=\"row-${index}\"]`);\n if (targets.length > 0) {\n targets.forEach(target => this.applyData(target, newValue, index));\n } else {\n this.renderRow(newValue, index);\n }\n }\n\n private renderRow(item: any, index: number) {\n if (!this.shadowRoot || this._masterTplNodes.length === 0) return;\n\n const slotName = `row-${index}`;\n if (!this.shadowRoot.querySelector(`slot[name=\"${slotName}\"]`)) {\n const slot = document.createElement('slot');\n slot.name = slotName;\n this.shadowRoot.appendChild(slot);\n }\n\n this._masterTplNodes.forEach(tplNode => {\n const clone = tplNode.cloneNode(true);\n if (clone.nodeType === Node.ELEMENT_NODE) {\n (clone as HTMLElement).setAttribute('slot', slotName);\n (clone as HTMLElement).style.display = '';\n } else if (clone.nodeType === Node.TEXT_NODE) {\n if (clone.textContent?.trim().length === 0) return;\n const span = document.createElement('span');\n span.setAttribute('slot', slotName);\n span.appendChild(clone);\n this.appendChild(span);\n this.applyData(span, item, index);\n return;\n }\n this.appendChild(clone);\n this.applyData(clone, item, index);\n });\n }\n\n private renderAll() {\n if (this._masterTplNodes.length === 0 || !this.shadowRoot) return;\n\n Array.from(this.children).forEach(c => {\n const slot = c.getAttribute('slot');\n if (slot && slot.startsWith('row-')) {\n c.remove();\n }\n });\n\n Array.from(this.shadowRoot.querySelectorAll('slot')).forEach(s => {\n if (s.id !== 'tpl-slot') s.remove();\n });\n\n this._value.forEach((item, index) => this.renderRow(item, index));\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,eAAe,UAAU,aAAa;AAC/C,SAAS,0BAA0B;AAG5B,IAAM,WAAN,MAAMA,kBAAiB,mBAAkB;EAG9C,cAAA;AACE,UAAK;AAHC,SAA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K;AACtB,aAAK,YAAY,IAAI;AACrB,aAAK,UAAU,MAAM,MAAM,KAAK;AAChC;MACF;AACA,WAAK,YAAY,KAAK;AACtB,WAAK,UAAU,OAAO,MAAM,KAAK;IACnC,CAAC;EACH;EAEQ,YAAS;AACf,QAAI,KAAK,gBAAgB,WAAW,KAAK,CAAC,KAAK;AAAY;AAE3D,UAAM,KAAK,KAAK,QAAQ,EAAE,QAAQ,OAAI;AACpC,YAAM,OAAO,EAAE,aAAa,MAAM;AAClC,UAAI,QAAQ,KAAK,WAAW,MAAM,GAAG;AACnC,UAAE,OAAM;MACV;IACF,CAAC;AAED,UAAM,KAAK,KAAK,WAAW,iBAAiB,MAAM,CAAC,EAAE,QAAQ,OAAI;AAC/D,UAAI,EAAE,OAAO;AAAY,UAAE,OAAM;IACnC,CAAC;AAED,SAAK,OAAO,QAAQ,CAAC,MAAM,UAAU,KAAK,UAAU,MAAM,KAAK,CAAC;EAClE;;AAnEA,WAAA;EADC;;;;;AAMD,WAAA;EADC;;;;;AA1BU,WAAQ,WAAA;EADpB,cAAc,EAAE,SAAS,cAAc,WAAW,KAAI,CAAE;;GAC5C,QAAQ;",
|
|
6
|
+
"names": ["SwcForOf"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class SwcHTMLElementBase extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
this._masterTplNodes = [];
|
|
5
|
+
this._asKey = "value";
|
|
6
|
+
this._asIndexKey = "index";
|
|
7
|
+
}
|
|
8
|
+
initCore() {
|
|
9
|
+
this._asKey = this.getAttribute("as") || "value";
|
|
10
|
+
this._asIndexKey = this.getAttribute("as-index") || "index";
|
|
11
|
+
const tplSlot = this.shadowRoot?.getElementById("tpl-slot");
|
|
12
|
+
if (tplSlot) {
|
|
13
|
+
this._masterTplNodes = tplSlot.assignedNodes().map((n) => n.cloneNode(true));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
getValueByPath(obj, path) {
|
|
17
|
+
if (path === this._asKey) return obj;
|
|
18
|
+
if (path.startsWith(`${this._asKey}.`)) {
|
|
19
|
+
return path.split(".").slice(1).reduce((acc, part) => acc && acc[part], obj);
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
applyData(node, data, index) {
|
|
24
|
+
const context = {};
|
|
25
|
+
if (index !== void 0) {
|
|
26
|
+
context[this._asIndexKey] = index.toString();
|
|
27
|
+
}
|
|
28
|
+
const walk = (n) => {
|
|
29
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
30
|
+
if (!n._original) n._original = n.textContent;
|
|
31
|
+
let text = n._original;
|
|
32
|
+
text = text.replace(/{{(.*?)}}/g, (match, path) => {
|
|
33
|
+
path = path.trim();
|
|
34
|
+
if (context[path] !== void 0) return context[path];
|
|
35
|
+
const val = this.getValueByPath(data, path);
|
|
36
|
+
return val !== void 0 ? val : match;
|
|
37
|
+
});
|
|
38
|
+
if (n.textContent !== text) n.textContent = text;
|
|
39
|
+
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
40
|
+
const el = n;
|
|
41
|
+
Array.from(el.attributes).forEach((a) => {
|
|
42
|
+
if (!a._original) a._original = a.value;
|
|
43
|
+
let val = a._original;
|
|
44
|
+
val = val.replace(/{{(.*?)}}/g, (match, path) => {
|
|
45
|
+
path = path.trim();
|
|
46
|
+
if (context[path] !== void 0) return context[path];
|
|
47
|
+
const v = this.getValueByPath(data, path);
|
|
48
|
+
return v !== void 0 ? v : match;
|
|
49
|
+
});
|
|
50
|
+
if (a.value !== val) a.value = val;
|
|
51
|
+
});
|
|
52
|
+
el.childNodes.forEach(walk);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
walk(node);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 객체/배열의 변경을 감지하는 Proxy 생성 유틸리티
|
|
59
|
+
*/
|
|
60
|
+
createReactiveProxy(target, onChange, onIndexChange) {
|
|
61
|
+
return new Proxy(target, {
|
|
62
|
+
set: (t, prop, val) => {
|
|
63
|
+
const isIndex = !isNaN(Number(prop));
|
|
64
|
+
t[prop] = val;
|
|
65
|
+
if (isIndex && onIndexChange) {
|
|
66
|
+
onIndexChange(Number(prop), val);
|
|
67
|
+
} else {
|
|
68
|
+
onChange();
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
deleteProperty: (t, prop) => {
|
|
73
|
+
delete t[prop];
|
|
74
|
+
onChange();
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
SwcHTMLElementBase
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=SwcHTMLElementBase.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcHTMLElementBase.ts"],
|
|
4
|
+
"sourcesContent": ["import { getTemplateMethod } from '../decorators/template';\nimport { getStyleMethod } from '../decorators/style';\n\nexport abstract class SwcHTMLElementBase extends HTMLElement {\n protected _masterTplNodes: Node[] = [];\n protected _asKey: string = 'value';\n protected _asIndexKey: string = 'index';\n\n constructor() {\n super();\n }\n\n protected initCore() {\n this._asKey = this.getAttribute('as') || 'value';\n this._asIndexKey = this.getAttribute('as-index') || 'index';\n const tplSlot = this.shadowRoot?.getElementById('tpl-slot') as HTMLSlotElement;\n if (tplSlot) {\n this._masterTplNodes = tplSlot.assignedNodes().map(n => n.cloneNode(true));\n }\n }\n\n protected getValueByPath(obj: any, path: string) {\n if (path === this._asKey) return obj;\n if (path.startsWith(`${this._asKey}.`)) {\n return path\n .split('.')\n .slice(1)\n .reduce((acc, part) => acc && acc[part], obj);\n }\n return undefined;\n }\n\n protected applyData(node: Node, data: any, index?: number) {\n const context: Record<string, any> = {};\n if (index !== undefined) {\n context[this._asIndexKey] = index.toString();\n }\n\n const walk = (n: Node) => {\n if (n.nodeType === Node.TEXT_NODE) {\n if (!(n as any)._original) (n as any)._original = n.textContent;\n let text = (n as any)._original;\n\n text = text.replace(/{{(.*?)}}/g, (match: string, path: string) => {\n path = path.trim();\n if (context[path] !== undefined) return context[path];\n const val = this.getValueByPath(data, path);\n return val !== undefined ? val : match;\n });\n if (n.textContent !== text) n.textContent = text;\n } else if (n.nodeType === Node.ELEMENT_NODE) {\n const el = n as Element;\n Array.from(el.attributes).forEach(a => {\n if (!(a as any)._original) (a as any)._original = a.value;\n let val = (a as any)._original;\n\n val = val.replace(/{{(.*?)}}/g, (match: string, path: string) => {\n path = path.trim();\n if (context[path] !== undefined) return context[path];\n const v = this.getValueByPath(data, path);\n return v !== undefined ? v : match;\n });\n if (a.value !== val) a.value = val;\n });\n el.childNodes.forEach(walk);\n }\n };\n walk(node);\n }\n\n /**\n * \uAC1D\uCCB4/\uBC30\uC5F4\uC758 \uBCC0\uACBD\uC744 \uAC10\uC9C0\uD558\uB294 Proxy \uC0DD\uC131 \uC720\uD2F8\uB9AC\uD2F0\n */\n protected createReactiveProxy(target: any, onChange: () => void, onIndexChange?: (index: number, val: any) => void) {\n return new Proxy(target, {\n set: (t, prop, val) => {\n const isIndex = !isNaN(Number(prop));\n t[prop] = val;\n if (isIndex && onIndexChange) {\n onIndexChange(Number(prop), val);\n } else {\n onChange();\n }\n return true;\n },\n deleteProperty: (t, prop) => {\n delete t[prop];\n onChange();\n return true;\n }\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAGO,MAAe,2BAA2B,YAAY;AAAA,EAK3D,cAAc;AACZ,UAAM;AALR,SAAU,kBAA0B,CAAC;AACrC,SAAU,SAAiB;AAC3B,SAAU,cAAsB;AAAA,EAIhC;AAAA,EAEU,WAAW;AACnB,SAAK,SAAS,KAAK,aAAa,IAAI,KAAK;AACzC,SAAK,cAAc,KAAK,aAAa,UAAU,KAAK;AACpD,UAAM,UAAU,KAAK,YAAY,eAAe,UAAU;AAC1D,QAA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AW,QAAO,QAAQ,IAAI;AACpD,kBAAM,IAAI,KAAK,eAAe,MAAM,IAAI;AACxC,mBAAO,MAAM,SAAY,IAAI;AAAA,UAC/B,CAAC;AACD,cAAI,EAAE,UAAU,IAAK,GAAE,QAAQ;AAAA,QACjC,CAAC;AACD,WAAG,WAAW,QAAQ,IAAI;AAAA,MAC5B;AAAA,IACF;AACA,SAAK,IAAI;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAoB,QAAa,UAAsB,eAAmD;AAClH,WAAO,IAAI,MAAM,QAAQ;AAAA,MACvB,KAAK,CAAC,GAAG,MAAM,QAAQ;AACrB,cAAM,UAAU,CAAC,MAAM,OAAO,IAAI,CAAC;AACnC,UAAE,IAAI,IAAI;AACV,YAAI,WAAW,eAAe;AAC5B,wBAAc,OAAO,IAAI,GAAG,GAAG;AAAA,QACjC,OAAO;AACL,mBAAS;AAAA,QACX;AACA,eAAO;AAAA,MACT;AAAA,MACA,gBAAgB,CAAC,GAAG,SAAS;AAC3B,eAAO,EAAE,IAAI;AACb,iBAAS;AACT,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
import { SwcHTMLElementBase } from "./SwcHTMLElementBase.js";
|
|
12
|
+
let SwcIf = class SwcIf2 extends SwcHTMLElementBase {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this._value = false;
|
|
16
|
+
this._observer = null;
|
|
17
|
+
}
|
|
18
|
+
set value(val) {
|
|
19
|
+
this._value = val;
|
|
20
|
+
this.render();
|
|
21
|
+
}
|
|
22
|
+
get value() {
|
|
23
|
+
return this._value;
|
|
24
|
+
}
|
|
25
|
+
styles() {
|
|
26
|
+
return `:host { display: contents; }`;
|
|
27
|
+
}
|
|
28
|
+
renderTemplate() {
|
|
29
|
+
return `<slot id="tpl-slot" style="display:none;"></slot>`;
|
|
30
|
+
}
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this.initCore();
|
|
33
|
+
this._observer = new MutationObserver(() => this.render());
|
|
34
|
+
this._observer.observe(this, { attributes: true });
|
|
35
|
+
this.render();
|
|
36
|
+
}
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this._observer?.disconnect();
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
if (!this.shadowRoot)
|
|
42
|
+
return;
|
|
43
|
+
const attrValue = this.getAttribute("value");
|
|
44
|
+
if (attrValue !== null && attrValue.includes("{{"))
|
|
45
|
+
return;
|
|
46
|
+
let displayValue = attrValue !== null ? attrValue : this._value;
|
|
47
|
+
let isTruthy = !!displayValue;
|
|
48
|
+
if (typeof displayValue === "string") {
|
|
49
|
+
if (displayValue === "false" || displayValue === "0" || displayValue === "")
|
|
50
|
+
isTruthy = false;
|
|
51
|
+
else {
|
|
52
|
+
try {
|
|
53
|
+
isTruthy = !!new Function(`return ${displayValue}`)();
|
|
54
|
+
} catch (e) {
|
|
55
|
+
isTruthy = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
Array.from(this.children).forEach((c) => {
|
|
60
|
+
if (c.getAttribute("slot") === "if-content") {
|
|
61
|
+
c.remove();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const existingSlot = this.shadowRoot.querySelector('slot[name="if-content"]');
|
|
65
|
+
if (existingSlot)
|
|
66
|
+
existingSlot.remove();
|
|
67
|
+
if (isTruthy && this._masterTplNodes.length > 0) {
|
|
68
|
+
const contentSlot = document.createElement("slot");
|
|
69
|
+
contentSlot.name = "if-content";
|
|
70
|
+
this.shadowRoot.appendChild(contentSlot);
|
|
71
|
+
this._masterTplNodes.forEach((tplNode) => {
|
|
72
|
+
const clone = tplNode.cloneNode(true);
|
|
73
|
+
if (clone.nodeType === Node.ELEMENT_NODE) {
|
|
74
|
+
clone.setAttribute("slot", "if-content");
|
|
75
|
+
} else if (clone.nodeType === Node.TEXT_NODE) {
|
|
76
|
+
if (clone.textContent?.trim().length === 0)
|
|
77
|
+
return;
|
|
78
|
+
const span = document.createElement("span");
|
|
79
|
+
span.setAttribute("slot", "if-content");
|
|
80
|
+
span.appendChild(clone);
|
|
81
|
+
this.appendChild(span);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.appendChild(clone);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
__decorate([
|
|
90
|
+
style,
|
|
91
|
+
__metadata("design:type", Function),
|
|
92
|
+
__metadata("design:paramtypes", []),
|
|
93
|
+
__metadata("design:returntype", void 0)
|
|
94
|
+
], SwcIf.prototype, "styles", null);
|
|
95
|
+
__decorate([
|
|
96
|
+
template,
|
|
97
|
+
__metadata("design:type", Function),
|
|
98
|
+
__metadata("design:paramtypes", []),
|
|
99
|
+
__metadata("design:returntype", void 0)
|
|
100
|
+
], SwcIf.prototype, "renderTemplate", null);
|
|
101
|
+
SwcIf = __decorate([
|
|
102
|
+
elementDefind({ tagName: "swc-if", useShadow: true }),
|
|
103
|
+
__metadata("design:paramtypes", [])
|
|
104
|
+
], SwcIf);
|
|
105
|
+
export {
|
|
106
|
+
SwcIf
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=SwcIf.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcIf.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementDefind, template, style } from '../index';\nimport { SwcHTMLElementBase } from './SwcHTMLElementBase';\n\n@elementDefind({ tagName: 'swc-if', useShadow: true })\nexport class SwcIf extends SwcHTMLElementBase {\n private _value: any = false;\n private _observer: MutationObserver | null = null;\n\n constructor() {\n super();\n }\n\n set value(val: any) {\n this._value = val;\n this.render();\n }\n\n get value(): any {\n return this._value;\n }\n\n @style\n styles() {\n return `:host { display: contents; }`;\n }\n\n @template\n renderTemplate() {\n return `<slot id=\"tpl-slot\" style=\"display:none;\"></slot>`;\n }\n\n connectedCallback() {\n this.initCore();\n this._observer = new MutationObserver(() => this.render());\n this._observer.observe(this, { attributes: true });\n this.render();\n }\n\n disconnectedCallback() {\n this._observer?.disconnect();\n }\n\n private render() {\n if (!this.shadowRoot) return;\n\n const attrValue = this.getAttribute('value');\n if (attrValue !== null && attrValue.includes('{{')) return;\n\n let displayValue = attrValue !== null ? attrValue : this._value;\n let isTruthy = !!displayValue;\n if (typeof displayValue === 'string') {\n if (displayValue === 'false' || displayValue === '0' || displayValue === '') isTruthy = false;\n else {\n try {\n isTruthy = !!new Function(`return ${displayValue}`)();\n } catch (e) {\n isTruthy = true;\n }\n }\n }\n\n Array.from(this.children).forEach(c => {\n if (c.getAttribute('slot') === 'if-content') {\n c.remove();\n }\n });\n\n const existingSlot = this.shadowRoot.querySelector('slot[name=\"if-content\"]');\n if (existingSlot) existingSlot.remove();\n\n if (isTruthy && this._masterTplNodes.length > 0) {\n const contentSlot = document.createElement('slot');\n contentSlot.name = 'if-content';\n this.shadowRoot.appendChild(contentSlot);\n\n this._masterTplNodes.forEach(tplNode => {\n const clone = tplNode.cloneNode(true);\n if (clone.nodeType === Node.ELEMENT_NODE) {\n (clone as HTMLElement).setAttribute('slot', 'if-content');\n } else if (clone.nodeType === Node.TEXT_NODE) {\n if (clone.textContent?.trim().length === 0) return;\n const span = document.createElement('span');\n span.setAttribute('slot', 'if-content');\n span.appendChild(clone);\n this.appendChild(span);\n return;\n }\n this.appendChild(clone);\n });\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,eAAe,UAAU,aAAa;AAC/C,SAAS,0BAA0B;AAG5B,IAAM,QAAN,MAAMA,eAAc,mBAAkB;EAI3C,cAAA;AACE,UAAK;AAJC,SAAA,SAAc;AACd,SAAA,YAAqC;EAI7C;EAEA,IAAI,MAAM,KAAQ;AAChB,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEA,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAGA,SAAM;AACJ,WAAO;EACT;EAGA,iBAAc;AACZ,WAAO;EACT;EAEA,oBAAiB;AACf,SAAK,SAAQ;AACb,SAAK,YAAY,IAAI,iBAAiB,MAAM,KAAK,OAAM,CAAE;AACzD,SAAK,UAAU,QAAQ,MAAM,EAAE,YAAY,KAAI,CAAE;AACjD,SAAK,OAAM;EACb;EAEA,uBAAoB;AAClB,SAAK,WAAW,WAAU;EAC5B;EAEQ,SAAM;AACZ,QAAI,CAAC,KAAK;AAAY;AAEtB,UAAM,YAAY,KAAK,aAAa,OAAO;AAC3C,QAAI,cAAc,QAAQ,UAAU,SAAS,IAAI;AAAG;AAEpD,QAAI,eAAe,cAAc,OAAO,YAAY,KAAK;AACzD,QAAI,WAAW,CAAC,CAAC;AACjB,QAAI,OAAO,iBAAiB,UAAU;AACpC,UAAI,iBAAiB,WAAW,iBAAiB,OAAO,iBAAiB;AAAI,mBAAW;WACnF;AACH,YAAI;AACF,qBAAW,CAAC,CAAC,IAAI,SAAS,UAAU,YAAY,EAAE,EAAC;QACrD,SAAS,GAAG;AACV,qBAAW;QACb;MACF;IACF;AAEA,UAAM,KAAK,KAAK,QAAQ,EAAE,QAAQ,OAAI;AACpC,UAAI,EAAE,aAAa,MAAM,MAAM,cAAc;AAC3C,UAAE,OAAM;MACV;IACF,CAAC;AAED,UAAM,eAAe,KAAK,WAAW,cAAc,yBAAyB;AAC5E,QAAI;AAAc,mBAAa,OAAM;AAErC,QAAI,YAAY,KAAK,gBAAgB,SAAS,GAAG;AAC/C,YAAM,cAAc,SAAS,cAAc,MAAM;AACjD,kBAAY,OAAO;AACnB,WAAK,WAAW,YAAY,WAAW;AAEvC,WAAK,gBAAgB,QAAQ,aAAU;AACrC,cAAM,QAAQ,QAAQ,UAAU,IAAI;AACpC,YAAI,MAAM,aAAa,KAAK,cAAc;AACvC,gBAAsB,aAAa,QAAQ,YAAY;QAC1D,WAAW,MAAM,aAAa,KAAK,WAAW;AAC5C,cAAI,MAAM,aAAa,KAAI,EAAG,WAAW;AAAG;AAC5C,gBAAM,OAAO,SAAS,cAAc,MAAM;AAC1C,eAAK,aAAa,QAAQ,YAAY;AACtC,eAAK,YAAY,KAAK;AACtB,eAAK,YAAY,IAAI;AACrB;QACF;AACA,aAAK,YAAY,KAAK;MACxB,CAAC;IACH;EACF;;AApEA,WAAA;EADC;;;;;AAMD,WAAA;EADC;;;;;AAtBU,QAAK,WAAA;EADjB,cAAc,EAAE,SAAS,UAAU,WAAW,KAAI,CAAE;;GACxC,KAAK;",
|
|
6
|
+
"names": ["SwcIf"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
import { SwcHTMLElementBase } from "./SwcHTMLElementBase.js";
|
|
12
|
+
let SwcObject = class SwcObject2 extends SwcHTMLElementBase {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this._value = {};
|
|
16
|
+
this._renderedNodes = [];
|
|
17
|
+
}
|
|
18
|
+
set value(val) {
|
|
19
|
+
if (typeof val !== "object" || val === null)
|
|
20
|
+
val = {};
|
|
21
|
+
this._value = this.createReactiveProxy(val, () => this.updateUI());
|
|
22
|
+
this.render();
|
|
23
|
+
}
|
|
24
|
+
get value() {
|
|
25
|
+
return this._value;
|
|
26
|
+
}
|
|
27
|
+
styles() {
|
|
28
|
+
return `:host { display: contents; }`;
|
|
29
|
+
}
|
|
30
|
+
renderTemplate() {
|
|
31
|
+
return `<slot id="tpl-slot" style="display:none;"></slot>`;
|
|
32
|
+
}
|
|
33
|
+
connectedCallback() {
|
|
34
|
+
this.initCore();
|
|
35
|
+
this.render();
|
|
36
|
+
}
|
|
37
|
+
updateUI() {
|
|
38
|
+
this._renderedNodes.forEach((node) => {
|
|
39
|
+
this.applyData(node, this._value);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
render() {
|
|
43
|
+
if (!this.shadowRoot || this._masterTplNodes.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
this._renderedNodes.forEach((n) => {
|
|
46
|
+
if (n.parentElement === this)
|
|
47
|
+
this.removeChild(n);
|
|
48
|
+
});
|
|
49
|
+
this._renderedNodes = [];
|
|
50
|
+
let slot = this.shadowRoot.querySelector('slot[name="obj-content"]');
|
|
51
|
+
if (!slot) {
|
|
52
|
+
slot = document.createElement("slot");
|
|
53
|
+
slot.name = "obj-content";
|
|
54
|
+
this.shadowRoot.appendChild(slot);
|
|
55
|
+
}
|
|
56
|
+
this._masterTplNodes.forEach((tplNode) => {
|
|
57
|
+
const clone = tplNode.cloneNode(true);
|
|
58
|
+
if (clone.nodeType === Node.ELEMENT_NODE) {
|
|
59
|
+
clone.setAttribute("slot", "obj-content");
|
|
60
|
+
} else if (clone.nodeType === Node.TEXT_NODE) {
|
|
61
|
+
if (clone.textContent?.trim().length === 0)
|
|
62
|
+
return;
|
|
63
|
+
const span = document.createElement("span");
|
|
64
|
+
span.setAttribute("slot", "obj-content");
|
|
65
|
+
span.appendChild(clone);
|
|
66
|
+
this.appendChild(span);
|
|
67
|
+
this._renderedNodes.push(span);
|
|
68
|
+
this.applyData(span, this._value);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.appendChild(clone);
|
|
72
|
+
this._renderedNodes.push(clone);
|
|
73
|
+
this.applyData(clone, this._value);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
style,
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", []),
|
|
81
|
+
__metadata("design:returntype", void 0)
|
|
82
|
+
], SwcObject.prototype, "styles", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
template,
|
|
85
|
+
__metadata("design:type", Function),
|
|
86
|
+
__metadata("design:paramtypes", []),
|
|
87
|
+
__metadata("design:returntype", void 0)
|
|
88
|
+
], SwcObject.prototype, "renderTemplate", null);
|
|
89
|
+
SwcObject = __decorate([
|
|
90
|
+
elementDefind({ tagName: "swc-object", useShadow: true }),
|
|
91
|
+
__metadata("design:paramtypes", [])
|
|
92
|
+
], SwcObject);
|
|
93
|
+
export {
|
|
94
|
+
SwcObject
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=SwcObject.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcObject.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementDefind, template, style } from '../index';\nimport { SwcHTMLElementBase } from './SwcHTMLElementBase';\n\n@elementDefind({ tagName: 'swc-object', useShadow: true })\nexport class SwcObject extends SwcHTMLElementBase {\n private _value: any = {};\n private _renderedNodes: Node[] = [];\n\n constructor() {\n super();\n }\n\n set value(val: any) {\n if (typeof val !== 'object' || val === null) val = {};\n this._value = this.createReactiveProxy(val, () => this.updateUI());\n this.render();\n }\n\n get value(): any {\n return this._value;\n }\n\n @style\n styles() {\n return `:host { display: contents; }`;\n }\n\n @template\n renderTemplate() {\n return `<slot id=\"tpl-slot\" style=\"display:none;\"></slot>`;\n }\n\n connectedCallback() {\n this.initCore();\n this.render();\n }\n\n private updateUI() {\n this._renderedNodes.forEach(node => {\n this.applyData(node, this._value);\n });\n }\n\n private render() {\n if (!this.shadowRoot || this._masterTplNodes.length === 0) return;\n\n this._renderedNodes.forEach(n => {\n if (n.parentElement === this) this.removeChild(n);\n });\n this._renderedNodes = [];\n\n let slot = this.shadowRoot.querySelector('slot[name=\"obj-content\"]');\n if (!slot) {\n slot = document.createElement('slot');\n (slot as HTMLSlotElement).name = 'obj-content';\n this.shadowRoot.appendChild(slot);\n }\n\n this._masterTplNodes.forEach(tplNode => {\n const clone = tplNode.cloneNode(true);\n if (clone.nodeType === Node.ELEMENT_NODE) {\n (clone as HTMLElement).setAttribute('slot', 'obj-content');\n } else if (clone.nodeType === Node.TEXT_NODE) {\n if (clone.textContent?.trim().length === 0) return;\n const span = document.createElement('span');\n span.setAttribute('slot', 'obj-content');\n span.appendChild(clone);\n this.appendChild(span);\n this._renderedNodes.push(span);\n this.applyData(span, this._value);\n return;\n }\n this.appendChild(clone);\n this._renderedNodes.push(clone);\n this.applyData(clone, this._value);\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,eAAe,UAAU,aAAa;AAC/C,SAAS,0BAA0B;A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AACrB,aAAK,eAAe,KAAK,IAAI;AAC7B,aAAK,UAAU,MAAM,KAAK,MAAM;AAChC;MACF;AACA,WAAK,YAAY,KAAK;AACtB,WAAK,eAAe,KAAK,KAAK;AAC9B,WAAK,UAAU,OAAO,KAAK,MAAM;IACnC,CAAC;EACH;;AArDA,WAAA;EADC;;;;;AAMD,WAAA;EADC;;;;;AAvBU,YAAS,WAAA;EADrB,cAAc,EAAE,SAAS,cAAc,WAAW,KAAI,CAAE;;GAC5C,SAAS;",
|
|
6
|
+
"names": ["SwcObject"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
let SwcOther = class SwcOther2 extends HTMLElement {
|
|
12
|
+
styles() {
|
|
13
|
+
return `:host { display: contents; }`;
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return `<slot></slot>`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
__decorate([
|
|
20
|
+
style,
|
|
21
|
+
__metadata("design:type", Function),
|
|
22
|
+
__metadata("design:paramtypes", []),
|
|
23
|
+
__metadata("design:returntype", void 0)
|
|
24
|
+
], SwcOther.prototype, "styles", null);
|
|
25
|
+
__decorate([
|
|
26
|
+
template,
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", []),
|
|
29
|
+
__metadata("design:returntype", void 0)
|
|
30
|
+
], SwcOther.prototype, "render", null);
|
|
31
|
+
SwcOther = __decorate([
|
|
32
|
+
elementDefind({ tagName: "swc-other", useShadow: true })
|
|
33
|
+
], SwcOther);
|
|
34
|
+
export {
|
|
35
|
+
SwcOther
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=SwcOther.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/elements/SwcOther.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementDefind, template, style } from '../index';\n\n@elementDefind({ tagName: 'swc-other', useShadow: true })\nexport class SwcOther extends HTMLElement {\n @style\n styles() {\n return `:host { display: contents; }`;\n }\n\n @template\n render() {\n return `<slot></slot>`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,eAAe,UAAU,aAAa;AAGxC,IAAM,WAAN,MAAMA,kBAAiB,YAAW;EAEvC,SAAM;AACJ,WAAO;EACT;EAGA,SAAM;AACJ,WAAO;EACT;;AAPA,WAAA;EADC;;;;;AAMD,WAAA;EADC;;;;;AANU,WAAQ,WAAA;EADpB,cAAc,EAAE,SAAS,aAAa,WAAW,KAAI,CAAE;GAC3C,QAAQ;",
|
|
6
|
+
"names": ["SwcOther"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = function(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { elementDefind, template, style } from "../index.js";
|
|
11
|
+
let SwcWhen = class SwcWhen2 extends HTMLElement {
|
|
12
|
+
styles() {
|
|
13
|
+
return `:host { display: contents; }`;
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return `<slot></slot>`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
__decorate([
|
|
20
|
+
style,
|
|
21
|
+
__metadata("design:type", Function),
|
|
22
|
+
__metadata("design:paramtypes", []),
|
|
23
|
+
__metadata("design:returntype", void 0)
|
|
24
|
+
], SwcWhen.prototype, "styles", null);
|
|
25
|
+
__decorate([
|
|
26
|
+
template,
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", []),
|
|
29
|
+
__metadata("design:returntype", void 0)
|
|
30
|
+
], SwcWhen.prototype, "render", null);
|
|
31
|
+
SwcWhen = __decorate([
|
|
32
|
+
elementDefind({ tagName: "swc-when", useShadow: true })
|
|
33
|
+
], SwcWhen);
|
|
34
|
+
export {
|
|
35
|
+
SwcWhen
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=SwcWhen.js.map
|