@dooboostore/simple-web-component 1.0.34 → 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/applyNode.js +4 -0
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +1 -1
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +225 -180
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +10 -4
- 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/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -2
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +120 -65
- 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 +51 -32
- 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 +244 -117
- 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 +18 -4
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +4 -0
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/attribute.js +1 -1
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +226 -181
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +10 -4
- 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/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +9 -2
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +122 -66
- 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 +51 -32
- 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 +244 -117
- 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 +18 -4
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +319 -276
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/applyNode.d.ts +1 -0
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts +1 -0
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +10 -6
- 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/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +4 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +11 -8
- 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 +319 -276
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/decorators/applyNode.ts +13 -1
- package/src/decorators/attribute.ts +1 -1
- package/src/decorators/changedAttributeHost.ts +3 -2
- package/src/decorators/elementDefine.ts +397 -354
- package/src/decorators/emitCustomEvent.ts +29 -15
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
- package/src/elements/SwcAppEngine.ts +10 -3
- package/src/elements/SwcAppMixin.ts +177 -97
- package/src/elements/SwcAsync.ts +28 -17
- package/src/elements/SwcChoose.ts +71 -34
- package/src/elements/SwcIf.ts +59 -22
- package/src/elements/SwcLoop.ts +140 -27
- package/src/elements/register.ts +296 -98
- package/src/types.ts +1 -0
- package/src/utils/Utils.ts +23 -5
- package/tsconfig.json +2 -2
|
@@ -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,27 +364,22 @@ 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
385
|
get value() {
|
|
@@ -302,18 +400,28 @@ const registerAllElements = (w) => {
|
|
|
302
400
|
attributeChangedCallback(na, o, n) {
|
|
303
401
|
}
|
|
304
402
|
setValue(value, o, n) {
|
|
403
|
+
console.log("chooooooose value", value);
|
|
305
404
|
this._value = value;
|
|
306
405
|
this.refresh(this._value);
|
|
307
406
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
407
|
+
// @changedAttributeHost('replace-wrap')
|
|
408
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
409
|
+
// this.refresh();
|
|
410
|
+
// }
|
|
311
411
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
312
|
-
|
|
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
|
+
}
|
|
313
422
|
const ae = new ActionExpression(html, config);
|
|
314
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
315
423
|
const win = this.ownerDocument?.defaultView || window;
|
|
316
|
-
for (const expr of ae.getExpressions(
|
|
424
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
317
425
|
try {
|
|
318
426
|
const value = FunctionUtils.executeReturn({
|
|
319
427
|
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -329,31 +437,27 @@ const registerAllElements = (w) => {
|
|
|
329
437
|
}
|
|
330
438
|
refresh(value) {
|
|
331
439
|
value = getAttributeValue(this, "value") ?? this._value;
|
|
332
|
-
|
|
333
|
-
|
|
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!");
|
|
334
444
|
return;
|
|
445
|
+
}
|
|
335
446
|
const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;
|
|
336
447
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
337
|
-
const groupArgs = { ...helperSet, $value: value };
|
|
448
|
+
const groupArgs = { ...helperSet, $value: value, $templateHost: this };
|
|
338
449
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
339
450
|
let selected = null;
|
|
340
451
|
for (const t of templates) {
|
|
341
452
|
if (t.getAttribute("is") === "swc-when") {
|
|
342
|
-
const attrVal = t.getAttribute("
|
|
453
|
+
const attrVal = t.getAttribute("test") || "";
|
|
343
454
|
let matches = false;
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
context: t,
|
|
351
|
-
args: groupArgs
|
|
352
|
-
});
|
|
353
|
-
matches = !!result;
|
|
354
|
-
} else {
|
|
355
|
-
matches = String(attrVal) === String(value);
|
|
356
|
-
}
|
|
455
|
+
const result = FunctionUtils.executeReturn({
|
|
456
|
+
script: attrVal,
|
|
457
|
+
context: t,
|
|
458
|
+
args: groupArgs
|
|
459
|
+
});
|
|
460
|
+
matches = !!result;
|
|
357
461
|
if (matches) {
|
|
358
462
|
selected = t;
|
|
359
463
|
break;
|
|
@@ -372,12 +476,27 @@ const registerAllElements = (w) => {
|
|
|
372
476
|
this._previousTemplate = target;
|
|
373
477
|
if (target) {
|
|
374
478
|
let htmlString = target.innerHTML;
|
|
375
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
479
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
376
480
|
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
377
481
|
result.innerHTML = htmlString;
|
|
378
482
|
const processedFragment = result.content;
|
|
379
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}`);
|
|
380
498
|
portal.insertBefore(processedFragment, this.nextSibling);
|
|
499
|
+
console.log("[DEBUG] SwcChoose after insertBefore");
|
|
381
500
|
}
|
|
382
501
|
}
|
|
383
502
|
cleanup() {
|
|
@@ -389,21 +508,19 @@ const registerAllElements = (w) => {
|
|
|
389
508
|
}
|
|
390
509
|
};
|
|
391
510
|
__decorate([
|
|
392
|
-
attributeHost("replace-wrap"),
|
|
511
|
+
attributeHost("replace-wrap-start"),
|
|
393
512
|
__metadata("design:type", String)
|
|
394
|
-
], SwcChoose.prototype, "
|
|
513
|
+
], SwcChoose.prototype, "_replaceWrapStart", void 0);
|
|
514
|
+
__decorate([
|
|
515
|
+
attributeHost("replace-wrap-end"),
|
|
516
|
+
__metadata("design:type", String)
|
|
517
|
+
], SwcChoose.prototype, "_replaceWrapEnd", void 0);
|
|
395
518
|
__decorate([
|
|
396
519
|
changedAttributeHost("value"),
|
|
397
520
|
__metadata("design:type", Function),
|
|
398
521
|
__metadata("design:paramtypes", [Object, String, String]),
|
|
399
522
|
__metadata("design:returntype", void 0)
|
|
400
523
|
], SwcChoose.prototype, "setValue", null);
|
|
401
|
-
__decorate([
|
|
402
|
-
changedAttributeHost("replace-wrap"),
|
|
403
|
-
__metadata("design:type", Function),
|
|
404
|
-
__metadata("design:paramtypes", [String]),
|
|
405
|
-
__metadata("design:returntype", void 0)
|
|
406
|
-
], SwcChoose.prototype, "setReplaceWrap", null);
|
|
407
524
|
SwcChoose = __decorate([
|
|
408
525
|
elementDefine("swc-choose", { extends: "template", window: w }),
|
|
409
526
|
__metadata("design:paramtypes", [])
|
|
@@ -422,9 +539,10 @@ const registerAllElements = (w) => {
|
|
|
422
539
|
setValue(valueAttr) {
|
|
423
540
|
this.executeAsync(this._value);
|
|
424
541
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
542
|
+
// @changedAttributeHost('replace-wrap')
|
|
543
|
+
// private setReplaceWrap() {
|
|
544
|
+
// this.executeAsync(this._value);
|
|
545
|
+
// }
|
|
428
546
|
executeAsync(result = this._value) {
|
|
429
547
|
if (result === void 0 || result === null) {
|
|
430
548
|
this.refresh("default");
|
|
@@ -446,11 +564,19 @@ const registerAllElements = (w) => {
|
|
|
446
564
|
}
|
|
447
565
|
}
|
|
448
566
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
449
|
-
|
|
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
|
+
}
|
|
450
577
|
const ae = new ActionExpression(html, config);
|
|
451
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
452
578
|
const win = this.ownerDocument?.defaultView || window;
|
|
453
|
-
for (const expr of ae.getExpressions(
|
|
579
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
454
580
|
try {
|
|
455
581
|
const value = FunctionUtils.executeReturn({
|
|
456
582
|
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -465,9 +591,8 @@ const registerAllElements = (w) => {
|
|
|
465
591
|
return ae.getUnprocessedTemplate();
|
|
466
592
|
}
|
|
467
593
|
refresh(state = "default") {
|
|
468
|
-
console.log("rrrrrrrrrrrrrrrrr", state);
|
|
469
594
|
this.cleanup();
|
|
470
|
-
const portal = this
|
|
595
|
+
const portal = SwcUtils.getParentContainer(this);
|
|
471
596
|
if (!portal)
|
|
472
597
|
return;
|
|
473
598
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -475,12 +600,16 @@ const registerAllElements = (w) => {
|
|
|
475
600
|
const t = this.content.querySelector(`template[is="swc-${state}"]`);
|
|
476
601
|
if (t) {
|
|
477
602
|
let htmlString = t.innerHTML;
|
|
478
|
-
const groupArgs = { ...helperSet, $value: this._value, $state: state };
|
|
479
|
-
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 ?? "}#}" });
|
|
480
605
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
481
606
|
temp.innerHTML = htmlString;
|
|
482
607
|
const content = temp.content;
|
|
483
608
|
this._nodes = Array.from(content.childNodes);
|
|
609
|
+
this._nodes.forEach((node) => {
|
|
610
|
+
if (node instanceof HTMLElement)
|
|
611
|
+
node.__template_swc_host = this;
|
|
612
|
+
});
|
|
484
613
|
portal.insertBefore(content, this.nextSibling);
|
|
485
614
|
}
|
|
486
615
|
}
|
|
@@ -497,21 +626,19 @@ const registerAllElements = (w) => {
|
|
|
497
626
|
__metadata("design:type", Object)
|
|
498
627
|
], SwcAsync.prototype, "_value", void 0);
|
|
499
628
|
__decorate([
|
|
500
|
-
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"),
|
|
501
634
|
__metadata("design:type", String)
|
|
502
|
-
], SwcAsync.prototype, "
|
|
635
|
+
], SwcAsync.prototype, "_replaceWrapEnd", void 0);
|
|
503
636
|
__decorate([
|
|
504
637
|
changedAttributeHost("value"),
|
|
505
638
|
__metadata("design:type", Function),
|
|
506
639
|
__metadata("design:paramtypes", [String]),
|
|
507
640
|
__metadata("design:returntype", void 0)
|
|
508
641
|
], SwcAsync.prototype, "setValue", null);
|
|
509
|
-
__decorate([
|
|
510
|
-
changedAttributeHost("replace-wrap"),
|
|
511
|
-
__metadata("design:type", Function),
|
|
512
|
-
__metadata("design:paramtypes", []),
|
|
513
|
-
__metadata("design:returntype", void 0)
|
|
514
|
-
], SwcAsync.prototype, "setReplaceWrap", null);
|
|
515
642
|
SwcAsync = __decorate([
|
|
516
643
|
elementDefine("swc-async", { extends: "template", window: w })
|
|
517
644
|
], SwcAsync);
|