@dooboostore/simple-web-component 1.0.30 → 1.0.32
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 +220 -1
- package/dist/cjs/decorators/applyStyle.js +1 -1
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -1
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +29 -12
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/elements/SwcAppEngine.js +3 -3
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +1 -8
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +71 -78
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +66 -81
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +52 -96
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +60 -103
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/SwcSubTemplates.js +0 -27
- package/dist/cjs/elements/SwcSubTemplates.js.map +2 -2
- package/dist/cjs/elements/register.js +314 -343
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +1 -8
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +31 -24
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +1 -1
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +18 -2
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +27 -10
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/elements/SwcAppEngine.js +3 -3
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +1 -8
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +72 -60
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +67 -63
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +53 -78
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +61 -85
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/SwcSubTemplates.js +0 -8
- package/dist/esm/elements/SwcSubTemplates.js.map +2 -2
- package/dist/esm/elements/register.js +246 -275
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +1 -8
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +31 -24
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2223 -2009
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +1 -11
- package/dist/types/elements/SwcAsync.d.ts.map +1 -1
- package/dist/types/elements/SwcChoose.d.ts +1 -13
- package/dist/types/elements/SwcChoose.d.ts.map +1 -1
- package/dist/types/elements/SwcIf.d.ts +1 -13
- package/dist/types/elements/SwcIf.d.ts.map +1 -1
- package/dist/types/elements/SwcLoop.d.ts +1 -13
- package/dist/types/elements/SwcLoop.d.ts.map +1 -1
- package/dist/types/elements/SwcSubTemplates.d.ts +6 -6
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/types/types.d.ts +11 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +10 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2223 -2009
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/applyStyle.ts +1 -1
- package/src/decorators/attribute.ts +35 -30
- package/src/decorators/elementDefine.ts +32 -10
- package/src/elements/SwcAppEngine.ts +3 -3
- package/src/elements/SwcAppMixin.ts +6 -27
- package/src/elements/SwcAsync.ts +75 -57
- package/src/elements/SwcChoose.ts +69 -77
- package/src/elements/SwcIf.ts +50 -75
- package/src/elements/SwcLoop.ts +56 -82
- package/src/elements/SwcSubTemplates.ts +6 -6
- package/src/elements/register.ts +234 -285
- package/src/router/ElementRouter.ts +1 -12
- package/src/types.ts +9 -2
- package/src/utils/Utils.ts +48 -37
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var SwcChoose_exports = {};
|
|
19
|
-
__export(SwcChoose_exports, {
|
|
20
|
-
SwcChoose: () => SwcChoose
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(SwcChoose_exports);
|
|
23
1
|
var import_changedAttributeHost = require("../decorators/changedAttributeHost");
|
|
24
2
|
var import_Utils = require("../utils/Utils");
|
|
25
3
|
var import_core = require("@dooboostore/core");
|
|
4
|
+
var import_core_web = require("@dooboostore/core-web");
|
|
5
|
+
var import_decorators = require("../decorators");
|
|
26
6
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -36,56 +16,64 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
36
16
|
constructor() {
|
|
37
17
|
super(...arguments);
|
|
38
18
|
this._nodes = [];
|
|
39
|
-
this._value = null;
|
|
40
19
|
this._previousTemplate = null;
|
|
41
20
|
}
|
|
42
21
|
get value() {
|
|
43
22
|
return this._value;
|
|
44
23
|
}
|
|
45
24
|
set value(nv) {
|
|
46
|
-
this.
|
|
47
|
-
this.render();
|
|
25
|
+
this.refresh(nv);
|
|
48
26
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!script)
|
|
52
|
-
return;
|
|
53
|
-
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
27
|
+
setValue() {
|
|
28
|
+
this.refresh();
|
|
54
29
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
setReplaceWrap(replaceWrapAttr) {
|
|
31
|
+
this.refresh();
|
|
32
|
+
}
|
|
33
|
+
replaceExpressions(html, groupArgs, context, wrap) {
|
|
34
|
+
const config = wrap ? { wrapExpression: wrap } : void 0;
|
|
35
|
+
const ae = new import_core.ActionExpression(html, config);
|
|
36
|
+
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
37
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
38
|
+
for (const expr of ae.getExpressions(filterOptions)) {
|
|
39
|
+
try {
|
|
40
|
+
const value = import_core.FunctionUtils.executeReturn({
|
|
41
|
+
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
42
|
+
context,
|
|
43
|
+
args: groupArgs
|
|
44
|
+
});
|
|
45
|
+
ae.replace(expr, String(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
48
|
+
}
|
|
68
49
|
}
|
|
50
|
+
return ae.getUnprocessedTemplate();
|
|
69
51
|
}
|
|
70
|
-
|
|
52
|
+
refresh(value = this._value) {
|
|
53
|
+
const portal = this.parentElement;
|
|
54
|
+
if (!portal)
|
|
55
|
+
return;
|
|
71
56
|
const win = this.ownerDocument?.defaultView || window;
|
|
72
57
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
58
|
+
const groupArgs = { ...helperSet, $value: value };
|
|
73
59
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
74
60
|
let selected = null;
|
|
75
61
|
for (const t of templates) {
|
|
76
62
|
if (t.getAttribute("is") === "swc-when") {
|
|
63
|
+
const attrVal = t.getAttribute("value") || "";
|
|
77
64
|
let matches = false;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
const ae = new import_core.ActionExpression(attrVal);
|
|
66
|
+
const expr = ae.getFirstExpression("replace");
|
|
67
|
+
if (expr) {
|
|
68
|
+
const decodedScript = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
81
69
|
const result = import_core.FunctionUtils.executeReturn({
|
|
82
|
-
script,
|
|
70
|
+
script: decodedScript,
|
|
83
71
|
context: t,
|
|
84
|
-
args:
|
|
72
|
+
args: groupArgs
|
|
85
73
|
});
|
|
86
|
-
matches = result
|
|
74
|
+
matches = !!result;
|
|
87
75
|
} else {
|
|
88
|
-
matches = String(
|
|
76
|
+
matches = String(attrVal) === String(value);
|
|
89
77
|
}
|
|
90
78
|
if (matches) {
|
|
91
79
|
selected = t;
|
|
@@ -94,54 +82,51 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
85
|
+
const skipValue = target?.getAttribute?.("skip-if-same");
|
|
86
|
+
const skipValue2 = this._previousTemplate?.getAttribute?.("skip-if-same");
|
|
87
|
+
const hasSkipIfSame = target?.hasAttribute?.("skip-if-same");
|
|
88
|
+
const isSame = this._previousTemplate === target;
|
|
89
|
+
if (hasSkipIfSame && isSame) {
|
|
100
90
|
return;
|
|
101
91
|
}
|
|
102
92
|
this.cleanup();
|
|
103
93
|
this._previousTemplate = target;
|
|
104
94
|
if (target) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
Array.from(n.attributes).forEach((attr) => {
|
|
113
|
-
const value = attr.value || "";
|
|
114
|
-
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
115
|
-
const script = value.slice(2, -2).trim();
|
|
116
|
-
const result = import_core.FunctionUtils.executeReturn({
|
|
117
|
-
script,
|
|
118
|
-
context: n,
|
|
119
|
-
args: { ...groupArgs, $value: this._value }
|
|
120
|
-
});
|
|
121
|
-
n.setAttribute(attr.name, String(result));
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
127
|
-
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
95
|
+
let htmlString = target.innerHTML;
|
|
96
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
|
|
97
|
+
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
98
|
+
result.innerHTML = htmlString;
|
|
99
|
+
const processedFragment = result.content;
|
|
100
|
+
this._nodes = Array.from(processedFragment.childNodes);
|
|
101
|
+
portal.insertBefore(processedFragment, this.nextSibling);
|
|
128
102
|
}
|
|
129
103
|
}
|
|
130
104
|
cleanup() {
|
|
131
105
|
this._nodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
132
106
|
this._nodes = [];
|
|
133
107
|
}
|
|
134
|
-
connectedCallback() {
|
|
135
|
-
this.refresh();
|
|
136
|
-
}
|
|
137
108
|
disconnectedCallback() {
|
|
138
109
|
this.cleanup();
|
|
139
110
|
}
|
|
140
111
|
}
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, import_decorators.attributeHost)("value"),
|
|
114
|
+
__metadata("design:type", Object)
|
|
115
|
+
], SwcChoose.prototype, "_value", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, import_decorators.attributeHost)("replace-wrap"),
|
|
118
|
+
__metadata("design:type", String)
|
|
119
|
+
], SwcChoose.prototype, "_replaceWrap", void 0);
|
|
141
120
|
__decorate([
|
|
142
121
|
(0, import_changedAttributeHost.changedAttributeHost)("value"),
|
|
143
122
|
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", []),
|
|
124
|
+
__metadata("design:returntype", void 0)
|
|
125
|
+
], SwcChoose.prototype, "setValue", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, import_changedAttributeHost.changedAttributeHost)("replace-wrap"),
|
|
128
|
+
__metadata("design:type", Function),
|
|
144
129
|
__metadata("design:paramtypes", [String]),
|
|
145
130
|
__metadata("design:returntype", void 0)
|
|
146
|
-
], SwcChoose.prototype, "
|
|
131
|
+
], SwcChoose.prototype, "setReplaceWrap", null);
|
|
147
132
|
//# sourceMappingURL=SwcChoose.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcChooseInterface } from '../types';\nimport { attributeHost } from '../decorators';\n\nclass SwcChoose extends HTMLTemplateElement implements SwcChooseInterface {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodes: Node[] = [];\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n this.refresh(nv);\n }\n\n @changedAttributeHost('value')\n private setValue() {\n this.refresh();\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap(replaceWrapAttr?: string | null) {\n this.refresh();\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value = this._value) {\n const portal = this.parentElement;\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const groupArgs = { ...helperSet, $value: value };\n\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when') {\n const attrVal = t.getAttribute('value') || '';\n let matches = false;\n\n // Use ActionExpression to parse and extract script from value attribute\n const ae = new ActionExpression(attrVal);\n const expr = ae.getFirstExpression('replace');\n\n if (expr) {\n const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n const result = FunctionUtils.executeReturn({\n script: decodedScript,\n context: t,\n args: groupArgs\n });\n matches = !!result;\n } else {\n matches = String(attrVal) === String(value);\n }\n\n if (matches) {\n selected = t;\n break;\n }\n }\n }\n\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n const skipValue = target?.getAttribute?.('skip-if-same');\n const skipValue2 = this._previousTemplate?.getAttribute?.('skip-if-same');\n const hasSkipIfSame = target?.hasAttribute?.('skip-if-same');\n const isSame = this._previousTemplate === target;\n // console.log('---rrrr---', this._previousTemplate, target, hasSkipIfSame, isSame, skipValue, skipValue2);\n if (hasSkipIfSame && isSame) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n let htmlString = target.innerHTML;\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,kCAAqC;AACrC,mBAAyB;A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CAAc,cAAc;;;AAerB,WAAA;MADP,kDAAqB,OAAO;;;;;AAMrB,WAAA;MADP,kDAAqB,cAAc;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var SwcIf_exports = {};
|
|
19
|
-
__export(SwcIf_exports, {
|
|
20
|
-
SwcIf: () => SwcIf
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(SwcIf_exports);
|
|
23
1
|
var import_changedAttributeHost = require("../decorators/changedAttributeHost");
|
|
24
2
|
var import_Utils = require("../utils/Utils");
|
|
25
3
|
var import_core = require("@dooboostore/core");
|
|
4
|
+
var import_core_web = require("@dooboostore/core-web");
|
|
5
|
+
var import_decorators = require("../decorators");
|
|
26
6
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -35,105 +15,81 @@ var __metadata = function(k, v) {
|
|
|
35
15
|
class SwcIf extends HTMLTemplateElement {
|
|
36
16
|
constructor() {
|
|
37
17
|
super(...arguments);
|
|
38
|
-
this._value = false;
|
|
39
18
|
this._nodes = [];
|
|
40
19
|
}
|
|
41
20
|
get value() {
|
|
42
21
|
return this._value;
|
|
43
22
|
}
|
|
44
23
|
set value(nv) {
|
|
45
|
-
this.
|
|
46
|
-
this.render();
|
|
24
|
+
this.refresh(nv);
|
|
47
25
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
replaceExpressions(html, groupArgs, context, wrap) {
|
|
27
|
+
const config = wrap ? { wrapExpression: wrap } : void 0;
|
|
28
|
+
const ae = new import_core.ActionExpression(html, config);
|
|
29
|
+
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
52
30
|
const win = this.ownerDocument?.defaultView || window;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
for (const expr of ae.getExpressions(filterOptions)) {
|
|
32
|
+
try {
|
|
33
|
+
const value = import_core.FunctionUtils.executeReturn({
|
|
34
|
+
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
35
|
+
context,
|
|
36
|
+
args: groupArgs
|
|
37
|
+
});
|
|
38
|
+
ae.replace(expr, String(value));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return ae.getUnprocessedTemplate();
|
|
63
44
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!script)
|
|
67
|
-
return;
|
|
68
|
-
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
45
|
+
setValue(valueAttr) {
|
|
46
|
+
this.refresh();
|
|
69
47
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!script) {
|
|
73
|
-
this.value = false;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
77
|
-
const res = import_core.FunctionUtils.executeReturn({
|
|
78
|
-
script,
|
|
79
|
-
context: this,
|
|
80
|
-
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
81
|
-
});
|
|
82
|
-
if (res instanceof Promise) {
|
|
83
|
-
res.then((v) => this.value = v).catch(() => this.value = false);
|
|
84
|
-
} else {
|
|
85
|
-
this.value = res;
|
|
86
|
-
}
|
|
48
|
+
setReplaceWrap(replaceWrapAttr) {
|
|
49
|
+
this.refresh();
|
|
87
50
|
}
|
|
88
|
-
|
|
51
|
+
refresh(value = this._value) {
|
|
89
52
|
this.cleanup();
|
|
90
|
-
const portal = this.
|
|
91
|
-
if (!portal)
|
|
53
|
+
const portal = this.parentElement;
|
|
54
|
+
if (!portal || !value)
|
|
92
55
|
return;
|
|
93
56
|
const win = this.ownerDocument?.defaultView || window;
|
|
94
57
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (targetTpl === this) {
|
|
104
|
-
clone.querySelectorAll('template[is^="swc-"]').forEach((t) => t.remove());
|
|
105
|
-
}
|
|
106
|
-
this._nodes = Array.from(clone.childNodes);
|
|
107
|
-
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
108
|
-
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
109
|
-
this._nodes.forEach((node, nodeIdx) => {
|
|
110
|
-
if (node instanceof HTMLElement)
|
|
111
|
-
node.__swc_host = this;
|
|
112
|
-
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: node, $nodeIndex: nodeIdx, $isElement: node.nodeType === 1 });
|
|
113
|
-
});
|
|
114
|
-
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
115
|
-
if (portal === this.parentElement) {
|
|
116
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
117
|
-
} else {
|
|
118
|
-
portal.appendChild(clone);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
58
|
+
let htmlString = this.innerHTML;
|
|
59
|
+
const groupArgs = { ...helperSet, $value: value };
|
|
60
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
|
|
61
|
+
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
62
|
+
result.innerHTML = htmlString;
|
|
63
|
+
const processedFragment = result.content;
|
|
64
|
+
this._nodes = Array.from(processedFragment.childNodes);
|
|
65
|
+
portal.insertBefore(processedFragment, this.nextSibling);
|
|
121
66
|
}
|
|
122
67
|
cleanup() {
|
|
123
68
|
this._nodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
124
69
|
this._nodes = [];
|
|
125
70
|
}
|
|
126
|
-
connectedCallback() {
|
|
127
|
-
this.refreshValue();
|
|
128
|
-
}
|
|
129
71
|
disconnectedCallback() {
|
|
130
72
|
this.cleanup();
|
|
131
73
|
}
|
|
132
74
|
}
|
|
133
75
|
__decorate([
|
|
134
|
-
(0,
|
|
76
|
+
(0, import_decorators.attributeHost)("value"),
|
|
77
|
+
__metadata("design:type", Object)
|
|
78
|
+
], SwcIf.prototype, "_value", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, import_decorators.attributeHost)("replace-wrap"),
|
|
81
|
+
__metadata("design:type", String)
|
|
82
|
+
], SwcIf.prototype, "_replaceWrap", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, import_changedAttributeHost.changedAttributeHost)("value"),
|
|
85
|
+
__metadata("design:type", Function),
|
|
86
|
+
__metadata("design:paramtypes", [String]),
|
|
87
|
+
__metadata("design:returntype", void 0)
|
|
88
|
+
], SwcIf.prototype, "setValue", null);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, import_changedAttributeHost.changedAttributeHost)("replace-wrap"),
|
|
135
91
|
__metadata("design:type", Function),
|
|
136
|
-
__metadata("design:paramtypes", []),
|
|
92
|
+
__metadata("design:paramtypes", [String]),
|
|
137
93
|
__metadata("design:returntype", void 0)
|
|
138
|
-
], SwcIf.prototype, "
|
|
94
|
+
], SwcIf.prototype, "setReplaceWrap", null);
|
|
139
95
|
//# sourceMappingURL=SwcIf.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcIf.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcIfInterface } from '../types';\nimport { attributeHost } from '../decorators';\n\nclass SwcIf extends HTMLTemplateElement implements SwcIfInterface {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodes: Node[] = [];\n\n get value(): boolean {\n return this._value;\n }\n\n set value(nv: any) {\n // this._value = nv;\n this.refresh(nv);\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n \n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n @changedAttributeHost('value')\n private setValue(valueAttr?: string | null) {\n this.refresh();\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap(replaceWrapAttr?: string | null) {\n this.refresh();\n }\n\n refresh(value = this._value) {\n this.cleanup();\n const portal = this.parentElement;\n if (!portal || !value) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $value: value };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAE7B,wBAA8B;;;;;;;;;;AAE9B,MAAM,cAAc,oBAAmB;EAAvC,cAAA;;AAOU,SAAA,SAAiB,CAAA;EAwE3B;EAtEE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AAEf,SAAK,QAAQ,EAAE;EACjB;EAEQ,mBAAmB,MAAc,WAAgB,SAAc,MAAoB;AACzF,UAAM,SAAS,OAAO,EAAE,gBAAgB,KAAI,IAAK;AACjD,UAAM,KAAK,IAAI,6BAAiB,MAAM,MAAM;AAC5C,UAAM,gBAAgB,OAAO,EAAE,MAAM,WAAoB,KAAI,IAAK;AAClE,UAAM,MAA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