@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
|
@@ -7,7 +7,7 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
7
7
|
var __metadata = function(k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { elementDefine, attributeHost, changedAttributeHost } from "../decorators/index.js";
|
|
10
|
+
import { getElementConfig, elementDefine, attributeHost, changedAttributeHost, getAttributeValue } from "../decorators/index.js";
|
|
11
11
|
import { SwcAppMixin } from "./SwcAppMixin.js";
|
|
12
12
|
import { SwcUtils } from "../utils/Utils.js";
|
|
13
13
|
import { FunctionUtils, ActionExpression } from "@dooboostore/core";
|
|
@@ -111,22 +111,38 @@ const registerAllElements = (w) => {
|
|
|
111
111
|
elementDefine("swc-app", { window: w })
|
|
112
112
|
], SwcApp);
|
|
113
113
|
let SwcIf = class SwcIf extends HTMLTemplateElement {
|
|
114
|
-
constructor() {
|
|
115
|
-
super(...arguments);
|
|
116
|
-
this._nodes = [];
|
|
117
|
-
}
|
|
118
114
|
get value() {
|
|
119
115
|
return this._value;
|
|
120
116
|
}
|
|
121
117
|
set value(nv) {
|
|
122
118
|
this.refresh(nv);
|
|
123
119
|
}
|
|
120
|
+
constructor() {
|
|
121
|
+
super();
|
|
122
|
+
this._nodes = [];
|
|
123
|
+
}
|
|
124
|
+
setValue(value, o, n) {
|
|
125
|
+
this._value = value;
|
|
126
|
+
this.refresh(this._value);
|
|
127
|
+
}
|
|
128
|
+
// @changedAttributeHost('replace-wrap')
|
|
129
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
130
|
+
// this.refresh();
|
|
131
|
+
// }
|
|
124
132
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
125
|
-
|
|
133
|
+
let config = void 0;
|
|
134
|
+
if (wrap) {
|
|
135
|
+
config = {
|
|
136
|
+
expression: {
|
|
137
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
138
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
139
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
126
143
|
const ae = new ActionExpression(html, config);
|
|
127
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
128
144
|
const win = this.ownerDocument?.defaultView || window;
|
|
129
|
-
for (const expr of ae.getExpressions(
|
|
145
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
130
146
|
try {
|
|
131
147
|
const value = FunctionUtils.executeReturn({
|
|
132
148
|
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -140,30 +156,38 @@ const registerAllElements = (w) => {
|
|
|
140
156
|
}
|
|
141
157
|
return ae.getUnprocessedTemplate();
|
|
142
158
|
}
|
|
143
|
-
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
refresh(value = this._value) {
|
|
159
|
+
refresh(value) {
|
|
160
|
+
const targetValue = value !== void 0 ? value : getAttributeValue(this, "value") ?? this._value;
|
|
161
|
+
if (this.hasAttribute("skip-if-same") && this._value === targetValue && this._nodes.length > 0) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
150
164
|
this.cleanup();
|
|
165
|
+
this._value = targetValue;
|
|
151
166
|
const portal = this.parentElement;
|
|
152
|
-
if (!portal || !
|
|
167
|
+
if (!portal || !this._value)
|
|
153
168
|
return;
|
|
154
169
|
const win = this.ownerDocument?.defaultView || window;
|
|
155
170
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
156
171
|
let htmlString = this.innerHTML;
|
|
157
|
-
const groupArgs = { ...helperSet, $value:
|
|
158
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
172
|
+
const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };
|
|
173
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
159
174
|
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
160
175
|
result.innerHTML = htmlString;
|
|
161
176
|
const processedFragment = result.content;
|
|
162
177
|
this._nodes = Array.from(processedFragment.childNodes);
|
|
178
|
+
this._nodes.forEach((node) => {
|
|
179
|
+
if (node instanceof HTMLElement)
|
|
180
|
+
node.__swc_template_host = this;
|
|
181
|
+
});
|
|
163
182
|
portal.insertBefore(processedFragment, this.nextSibling);
|
|
164
183
|
}
|
|
165
184
|
cleanup() {
|
|
166
|
-
this._nodes.forEach((n) =>
|
|
185
|
+
this._nodes.forEach((n) => {
|
|
186
|
+
const realNode = n.__upgraded_instance || n;
|
|
187
|
+
if (realNode.parentElement) {
|
|
188
|
+
realNode.parentElement.removeChild(realNode);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
167
191
|
this._nodes = [];
|
|
168
192
|
}
|
|
169
193
|
disconnectedCallback() {
|
|
@@ -171,54 +195,68 @@ const registerAllElements = (w) => {
|
|
|
171
195
|
}
|
|
172
196
|
};
|
|
173
197
|
__decorate([
|
|
174
|
-
attributeHost("
|
|
175
|
-
__metadata("design:type",
|
|
176
|
-
], SwcIf.prototype, "
|
|
198
|
+
attributeHost("replace-wrap-start"),
|
|
199
|
+
__metadata("design:type", String)
|
|
200
|
+
], SwcIf.prototype, "_replaceWrapStart", void 0);
|
|
177
201
|
__decorate([
|
|
178
|
-
attributeHost("replace-wrap"),
|
|
202
|
+
attributeHost("replace-wrap-end"),
|
|
179
203
|
__metadata("design:type", String)
|
|
180
|
-
], SwcIf.prototype, "
|
|
204
|
+
], SwcIf.prototype, "_replaceWrapEnd", void 0);
|
|
205
|
+
__decorate([
|
|
206
|
+
attributeHost("skip-if-same"),
|
|
207
|
+
__metadata("design:type", String)
|
|
208
|
+
], SwcIf.prototype, "_skipIfSame", void 0);
|
|
181
209
|
__decorate([
|
|
182
210
|
changedAttributeHost("value"),
|
|
183
211
|
__metadata("design:type", Function),
|
|
184
|
-
__metadata("design:paramtypes", [String]),
|
|
212
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
185
213
|
__metadata("design:returntype", void 0)
|
|
186
214
|
], SwcIf.prototype, "setValue", null);
|
|
187
|
-
__decorate([
|
|
188
|
-
changedAttributeHost("replace-wrap"),
|
|
189
|
-
__metadata("design:type", Function),
|
|
190
|
-
__metadata("design:paramtypes", [String]),
|
|
191
|
-
__metadata("design:returntype", void 0)
|
|
192
|
-
], SwcIf.prototype, "setReplaceWrap", null);
|
|
193
215
|
SwcIf = __decorate([
|
|
194
|
-
elementDefine("swc-if", { extends: "template", window: w })
|
|
216
|
+
elementDefine("swc-if", { extends: "template", window: w }),
|
|
217
|
+
__metadata("design:paramtypes", [])
|
|
195
218
|
], SwcIf);
|
|
196
219
|
let SwcLoop = class SwcLoop extends HTMLTemplateElement {
|
|
197
|
-
constructor() {
|
|
198
|
-
super(...arguments);
|
|
199
|
-
this._nodeGroups = [];
|
|
200
|
-
}
|
|
201
220
|
get value() {
|
|
202
221
|
return this._value;
|
|
203
222
|
}
|
|
204
223
|
set value(nv) {
|
|
224
|
+
this._value = nv;
|
|
205
225
|
this.refresh(nv);
|
|
206
226
|
}
|
|
207
|
-
|
|
208
|
-
this.
|
|
227
|
+
getValue(index) {
|
|
228
|
+
return this._value?.[index];
|
|
229
|
+
}
|
|
230
|
+
constructor() {
|
|
231
|
+
super();
|
|
232
|
+
this._value = [];
|
|
233
|
+
this._nodeGroups = [];
|
|
209
234
|
}
|
|
210
|
-
|
|
211
|
-
this.
|
|
235
|
+
setValue(value, o, n) {
|
|
236
|
+
this._value = value;
|
|
237
|
+
this.refresh(this._value);
|
|
212
238
|
}
|
|
239
|
+
// @changedAttributeHost('replace-wrap')
|
|
240
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
241
|
+
// this.refresh();
|
|
242
|
+
// }
|
|
213
243
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
214
|
-
|
|
244
|
+
let config = void 0;
|
|
245
|
+
config = {
|
|
246
|
+
expression: {
|
|
247
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
248
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
249
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
250
|
+
}
|
|
251
|
+
};
|
|
215
252
|
const ae = new ActionExpression(html, config);
|
|
216
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
217
253
|
const win = this.ownerDocument?.defaultView || window;
|
|
218
|
-
|
|
254
|
+
const expressions = ae.getExpressions("replace");
|
|
255
|
+
for (const expr of expressions) {
|
|
256
|
+
const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
219
257
|
try {
|
|
220
258
|
const value = FunctionUtils.executeReturn({
|
|
221
|
-
script
|
|
259
|
+
script,
|
|
222
260
|
context,
|
|
223
261
|
args: groupArgs
|
|
224
262
|
});
|
|
@@ -229,30 +267,95 @@ const registerAllElements = (w) => {
|
|
|
229
267
|
}
|
|
230
268
|
return ae.getUnprocessedTemplate();
|
|
231
269
|
}
|
|
232
|
-
|
|
233
|
-
this.cleanup();
|
|
234
|
-
if (value?.length <= 0)
|
|
235
|
-
return;
|
|
236
|
-
const portal = this.parentElement;
|
|
237
|
-
if (!portal)
|
|
238
|
-
return;
|
|
270
|
+
createFragmentAndNodes(items, helperSet, startIndex = 0) {
|
|
239
271
|
const win = this.ownerDocument?.defaultView || window;
|
|
240
|
-
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
241
272
|
const fragment = win.document.createDocumentFragment();
|
|
242
|
-
|
|
273
|
+
const newNodesGroup = [];
|
|
274
|
+
items.forEach((item, i) => {
|
|
275
|
+
const index = startIndex + i;
|
|
243
276
|
let htmlString = this.innerHTML;
|
|
244
277
|
const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
|
|
245
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
278
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
246
279
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
247
280
|
temp.innerHTML = htmlString;
|
|
248
281
|
const content = temp.content;
|
|
249
282
|
const nodes = Array.from(content.childNodes);
|
|
250
|
-
|
|
283
|
+
const setTemplateHost = (element) => {
|
|
284
|
+
element.__swc_template_host = this;
|
|
285
|
+
Array.from(element.children).forEach((child) => {
|
|
286
|
+
if (child instanceof HTMLElement) {
|
|
287
|
+
setTemplateHost(child);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
nodes.forEach((node) => {
|
|
292
|
+
if (node instanceof HTMLElement) {
|
|
293
|
+
setTemplateHost(node);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
newNodesGroup.push(nodes);
|
|
251
297
|
fragment.appendChild(content);
|
|
252
298
|
});
|
|
299
|
+
return { fragment, newNodesGroup };
|
|
300
|
+
}
|
|
301
|
+
appendItem(...items) {
|
|
302
|
+
if (!items || items.length <= 0)
|
|
303
|
+
return;
|
|
304
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
305
|
+
if (!portal)
|
|
306
|
+
return;
|
|
307
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
308
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
309
|
+
const startIndex = this._value ? this._value.length : 0;
|
|
310
|
+
if (this._value !== items) {
|
|
311
|
+
this._value = [...this._value || [], ...items];
|
|
312
|
+
}
|
|
313
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
314
|
+
this._nodeGroups.push(...newNodesGroup);
|
|
315
|
+
console.log("\uBB50\uC57C \uC528\uBC1C");
|
|
316
|
+
let insertReference = this.nextSibling;
|
|
317
|
+
if (this._nodeGroups.length > items.length) {
|
|
318
|
+
const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
319
|
+
if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
320
|
+
const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
321
|
+
insertReference = lastNode.nextSibling;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
portal.insertBefore(fragment, insertReference);
|
|
325
|
+
}
|
|
326
|
+
async prependItem(...items) {
|
|
327
|
+
if (!items || items.length <= 0)
|
|
328
|
+
return;
|
|
329
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
330
|
+
if (!portal)
|
|
331
|
+
return;
|
|
332
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
333
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
334
|
+
if (this._value !== items) {
|
|
335
|
+
this._value = [...items, ...this._value || []];
|
|
336
|
+
}
|
|
337
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
|
|
338
|
+
this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
253
339
|
portal.insertBefore(fragment, this.nextSibling);
|
|
254
340
|
}
|
|
341
|
+
refresh(value) {
|
|
342
|
+
const targetValue = value !== void 0 ? value : getAttributeValue(this, "value") ?? this._value ?? [];
|
|
343
|
+
this.cleanup();
|
|
344
|
+
this._value = targetValue;
|
|
345
|
+
if (!this._value || this._value.length <= 0)
|
|
346
|
+
return;
|
|
347
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
348
|
+
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
349
|
+
helperSet.$templateHost = this;
|
|
350
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
|
|
351
|
+
this._nodeGroups = newNodesGroup;
|
|
352
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
353
|
+
if (portal) {
|
|
354
|
+
portal.insertBefore(fragment, this.nextSibling);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
255
357
|
cleanup() {
|
|
358
|
+
console.log("\uB204\uAC00 cleanup");
|
|
256
359
|
this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
|
|
257
360
|
this._nodeGroups = [];
|
|
258
361
|
}
|
|
@@ -261,52 +364,64 @@ const registerAllElements = (w) => {
|
|
|
261
364
|
}
|
|
262
365
|
};
|
|
263
366
|
__decorate([
|
|
264
|
-
attributeHost("
|
|
265
|
-
__metadata("design:type",
|
|
266
|
-
], SwcLoop.prototype, "
|
|
367
|
+
attributeHost("replace-wrap-start"),
|
|
368
|
+
__metadata("design:type", String)
|
|
369
|
+
], SwcLoop.prototype, "_replaceWrapStart", void 0);
|
|
267
370
|
__decorate([
|
|
268
|
-
attributeHost("replace-wrap"),
|
|
371
|
+
attributeHost("replace-wrap-end"),
|
|
269
372
|
__metadata("design:type", String)
|
|
270
|
-
], SwcLoop.prototype, "
|
|
373
|
+
], SwcLoop.prototype, "_replaceWrapEnd", void 0);
|
|
271
374
|
__decorate([
|
|
272
375
|
changedAttributeHost("value"),
|
|
273
376
|
__metadata("design:type", Function),
|
|
274
|
-
__metadata("design:paramtypes", []),
|
|
377
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
275
378
|
__metadata("design:returntype", void 0)
|
|
276
379
|
], SwcLoop.prototype, "setValue", null);
|
|
277
|
-
__decorate([
|
|
278
|
-
changedAttributeHost("replace-wrap"),
|
|
279
|
-
__metadata("design:type", Function),
|
|
280
|
-
__metadata("design:paramtypes", []),
|
|
281
|
-
__metadata("design:returntype", void 0)
|
|
282
|
-
], SwcLoop.prototype, "setReplaceWrap", null);
|
|
283
380
|
SwcLoop = __decorate([
|
|
284
|
-
elementDefine("swc-loop", { extends: "template", window: w })
|
|
381
|
+
elementDefine("swc-loop", { extends: "template", window: w }),
|
|
382
|
+
__metadata("design:paramtypes", [])
|
|
285
383
|
], SwcLoop);
|
|
286
384
|
let SwcChoose = class SwcChoose extends HTMLTemplateElement {
|
|
287
|
-
constructor() {
|
|
288
|
-
super(...arguments);
|
|
289
|
-
this._nodes = [];
|
|
290
|
-
this._previousTemplate = null;
|
|
291
|
-
}
|
|
292
385
|
get value() {
|
|
293
386
|
return this._value;
|
|
294
387
|
}
|
|
295
388
|
set value(nv) {
|
|
296
|
-
this.
|
|
389
|
+
this._value = nv;
|
|
390
|
+
this.refresh(this._value);
|
|
297
391
|
}
|
|
298
|
-
|
|
299
|
-
|
|
392
|
+
constructor() {
|
|
393
|
+
super();
|
|
394
|
+
this._nodes = [];
|
|
395
|
+
this._previousTemplate = null;
|
|
300
396
|
}
|
|
301
|
-
|
|
302
|
-
|
|
397
|
+
// static get observedAttributes() {
|
|
398
|
+
// return ['value'];
|
|
399
|
+
// }
|
|
400
|
+
attributeChangedCallback(na, o, n) {
|
|
303
401
|
}
|
|
402
|
+
setValue(value, o, n) {
|
|
403
|
+
console.log("chooooooose value", value);
|
|
404
|
+
this._value = value;
|
|
405
|
+
this.refresh(this._value);
|
|
406
|
+
}
|
|
407
|
+
// @changedAttributeHost('replace-wrap')
|
|
408
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
409
|
+
// this.refresh();
|
|
410
|
+
// }
|
|
304
411
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
305
|
-
|
|
412
|
+
let config = void 0;
|
|
413
|
+
if (wrap) {
|
|
414
|
+
config = {
|
|
415
|
+
expression: {
|
|
416
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
417
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
418
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
306
422
|
const ae = new ActionExpression(html, config);
|
|
307
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
308
423
|
const win = this.ownerDocument?.defaultView || window;
|
|
309
|
-
for (const expr of ae.getExpressions(
|
|
424
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
310
425
|
try {
|
|
311
426
|
const value = FunctionUtils.executeReturn({
|
|
312
427
|
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -320,32 +435,29 @@ const registerAllElements = (w) => {
|
|
|
320
435
|
}
|
|
321
436
|
return ae.getUnprocessedTemplate();
|
|
322
437
|
}
|
|
323
|
-
refresh(value
|
|
324
|
-
|
|
325
|
-
|
|
438
|
+
refresh(value) {
|
|
439
|
+
value = getAttributeValue(this, "value") ?? this._value;
|
|
440
|
+
console.log("[DEBUG] SwcChoose.refresh called, value:", value);
|
|
441
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
442
|
+
if (!portal) {
|
|
443
|
+
console.log("[DEBUG] SwcChoose portal is null!");
|
|
326
444
|
return;
|
|
327
|
-
|
|
445
|
+
}
|
|
446
|
+
const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;
|
|
328
447
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
329
|
-
const groupArgs = { ...helperSet, $value: value };
|
|
448
|
+
const groupArgs = { ...helperSet, $value: value, $templateHost: this };
|
|
330
449
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
331
450
|
let selected = null;
|
|
332
451
|
for (const t of templates) {
|
|
333
452
|
if (t.getAttribute("is") === "swc-when") {
|
|
334
|
-
const attrVal = t.getAttribute("
|
|
453
|
+
const attrVal = t.getAttribute("test") || "";
|
|
335
454
|
let matches = false;
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
context: t,
|
|
343
|
-
args: groupArgs
|
|
344
|
-
});
|
|
345
|
-
matches = !!result;
|
|
346
|
-
} else {
|
|
347
|
-
matches = String(attrVal) === String(value);
|
|
348
|
-
}
|
|
455
|
+
const result = FunctionUtils.executeReturn({
|
|
456
|
+
script: attrVal,
|
|
457
|
+
context: t,
|
|
458
|
+
args: groupArgs
|
|
459
|
+
});
|
|
460
|
+
matches = !!result;
|
|
349
461
|
if (matches) {
|
|
350
462
|
selected = t;
|
|
351
463
|
break;
|
|
@@ -364,12 +476,27 @@ const registerAllElements = (w) => {
|
|
|
364
476
|
this._previousTemplate = target;
|
|
365
477
|
if (target) {
|
|
366
478
|
let htmlString = target.innerHTML;
|
|
367
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
479
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
368
480
|
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
369
481
|
result.innerHTML = htmlString;
|
|
370
482
|
const processedFragment = result.content;
|
|
371
483
|
this._nodes = Array.from(processedFragment.childNodes);
|
|
484
|
+
const setTemplateHost = (element) => {
|
|
485
|
+
element.__swc_template_host = this;
|
|
486
|
+
Array.from(element.children).forEach((child) => {
|
|
487
|
+
if (child instanceof HTMLElement) {
|
|
488
|
+
setTemplateHost(child);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
this._nodes.forEach((node) => {
|
|
493
|
+
if (node instanceof HTMLElement) {
|
|
494
|
+
setTemplateHost(node);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${portal?.isConnected}`);
|
|
372
498
|
portal.insertBefore(processedFragment, this.nextSibling);
|
|
499
|
+
console.log("[DEBUG] SwcChoose after insertBefore");
|
|
373
500
|
}
|
|
374
501
|
}
|
|
375
502
|
cleanup() {
|
|
@@ -381,27 +508,22 @@ const registerAllElements = (w) => {
|
|
|
381
508
|
}
|
|
382
509
|
};
|
|
383
510
|
__decorate([
|
|
384
|
-
attributeHost("
|
|
385
|
-
__metadata("design:type",
|
|
386
|
-
], SwcChoose.prototype, "
|
|
511
|
+
attributeHost("replace-wrap-start"),
|
|
512
|
+
__metadata("design:type", String)
|
|
513
|
+
], SwcChoose.prototype, "_replaceWrapStart", void 0);
|
|
387
514
|
__decorate([
|
|
388
|
-
attributeHost("replace-wrap"),
|
|
515
|
+
attributeHost("replace-wrap-end"),
|
|
389
516
|
__metadata("design:type", String)
|
|
390
|
-
], SwcChoose.prototype, "
|
|
517
|
+
], SwcChoose.prototype, "_replaceWrapEnd", void 0);
|
|
391
518
|
__decorate([
|
|
392
519
|
changedAttributeHost("value"),
|
|
393
520
|
__metadata("design:type", Function),
|
|
394
|
-
__metadata("design:paramtypes", []),
|
|
521
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
395
522
|
__metadata("design:returntype", void 0)
|
|
396
523
|
], SwcChoose.prototype, "setValue", null);
|
|
397
|
-
__decorate([
|
|
398
|
-
changedAttributeHost("replace-wrap"),
|
|
399
|
-
__metadata("design:type", Function),
|
|
400
|
-
__metadata("design:paramtypes", [String]),
|
|
401
|
-
__metadata("design:returntype", void 0)
|
|
402
|
-
], SwcChoose.prototype, "setReplaceWrap", null);
|
|
403
524
|
SwcChoose = __decorate([
|
|
404
|
-
elementDefine("swc-choose", { extends: "template", window: w })
|
|
525
|
+
elementDefine("swc-choose", { extends: "template", window: w }),
|
|
526
|
+
__metadata("design:paramtypes", [])
|
|
405
527
|
], SwcChoose);
|
|
406
528
|
let SwcAsync = class SwcAsync extends HTMLTemplateElement {
|
|
407
529
|
constructor() {
|
|
@@ -417,9 +539,10 @@ const registerAllElements = (w) => {
|
|
|
417
539
|
setValue(valueAttr) {
|
|
418
540
|
this.executeAsync(this._value);
|
|
419
541
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
542
|
+
// @changedAttributeHost('replace-wrap')
|
|
543
|
+
// private setReplaceWrap() {
|
|
544
|
+
// this.executeAsync(this._value);
|
|
545
|
+
// }
|
|
423
546
|
executeAsync(result = this._value) {
|
|
424
547
|
if (result === void 0 || result === null) {
|
|
425
548
|
this.refresh("default");
|
|
@@ -441,11 +564,19 @@ const registerAllElements = (w) => {
|
|
|
441
564
|
}
|
|
442
565
|
}
|
|
443
566
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
444
|
-
|
|
567
|
+
let config = void 0;
|
|
568
|
+
if (wrap) {
|
|
569
|
+
config = {
|
|
570
|
+
expression: {
|
|
571
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
572
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
573
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
}
|
|
445
577
|
const ae = new ActionExpression(html, config);
|
|
446
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
447
578
|
const win = this.ownerDocument?.defaultView || window;
|
|
448
|
-
for (const expr of ae.getExpressions(
|
|
579
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
449
580
|
try {
|
|
450
581
|
const value = FunctionUtils.executeReturn({
|
|
451
582
|
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -460,9 +591,8 @@ const registerAllElements = (w) => {
|
|
|
460
591
|
return ae.getUnprocessedTemplate();
|
|
461
592
|
}
|
|
462
593
|
refresh(state = "default") {
|
|
463
|
-
console.log("rrrrrrrrrrrrrrrrr", state);
|
|
464
594
|
this.cleanup();
|
|
465
|
-
const portal = this
|
|
595
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
466
596
|
if (!portal)
|
|
467
597
|
return;
|
|
468
598
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -470,12 +600,16 @@ const registerAllElements = (w) => {
|
|
|
470
600
|
const t = this.content.querySelector(`template[is="swc-${state}"]`);
|
|
471
601
|
if (t) {
|
|
472
602
|
let htmlString = t.innerHTML;
|
|
473
|
-
const groupArgs = { ...helperSet, $value: this._value, $state: state };
|
|
474
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
603
|
+
const groupArgs = { ...helperSet, $value: this._value, $state: state, $templateHost: this };
|
|
604
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
475
605
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
476
606
|
temp.innerHTML = htmlString;
|
|
477
607
|
const content = temp.content;
|
|
478
608
|
this._nodes = Array.from(content.childNodes);
|
|
609
|
+
this._nodes.forEach((node) => {
|
|
610
|
+
if (node instanceof HTMLElement)
|
|
611
|
+
node.__template_swc_host = this;
|
|
612
|
+
});
|
|
479
613
|
portal.insertBefore(content, this.nextSibling);
|
|
480
614
|
}
|
|
481
615
|
}
|
|
@@ -492,21 +626,19 @@ const registerAllElements = (w) => {
|
|
|
492
626
|
__metadata("design:type", Object)
|
|
493
627
|
], SwcAsync.prototype, "_value", void 0);
|
|
494
628
|
__decorate([
|
|
495
|
-
attributeHost("replace-wrap"),
|
|
629
|
+
attributeHost("replace-wrap-start"),
|
|
630
|
+
__metadata("design:type", String)
|
|
631
|
+
], SwcAsync.prototype, "_replaceWrapStart", void 0);
|
|
632
|
+
__decorate([
|
|
633
|
+
attributeHost("replace-wrap-end"),
|
|
496
634
|
__metadata("design:type", String)
|
|
497
|
-
], SwcAsync.prototype, "
|
|
635
|
+
], SwcAsync.prototype, "_replaceWrapEnd", void 0);
|
|
498
636
|
__decorate([
|
|
499
637
|
changedAttributeHost("value"),
|
|
500
638
|
__metadata("design:type", Function),
|
|
501
639
|
__metadata("design:paramtypes", [String]),
|
|
502
640
|
__metadata("design:returntype", void 0)
|
|
503
641
|
], SwcAsync.prototype, "setValue", null);
|
|
504
|
-
__decorate([
|
|
505
|
-
changedAttributeHost("replace-wrap"),
|
|
506
|
-
__metadata("design:type", Function),
|
|
507
|
-
__metadata("design:paramtypes", []),
|
|
508
|
-
__metadata("design:returntype", void 0)
|
|
509
|
-
], SwcAsync.prototype, "setReplaceWrap", null);
|
|
510
642
|
SwcAsync = __decorate([
|
|
511
643
|
elementDefine("swc-async", { extends: "template", window: w })
|
|
512
644
|
], SwcAsync);
|