@dooboostore/simple-web-component 1.0.19 → 1.0.21
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 +2028 -146
- package/dist/cjs/decorators/addEventListener.js +4 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/appendChild.js +4 -4
- package/dist/cjs/decorators/appendChild.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +141 -0
- package/dist/cjs/decorators/attribute.js.map +7 -0
- package/dist/cjs/decorators/changedAttribute.js +5 -5
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/classList.js +4 -4
- package/dist/cjs/decorators/classList.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +36 -9
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +4 -4
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +4 -4
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/onConnectedInnerHtml.js +4 -4
- package/dist/cjs/decorators/onConnectedInnerHtml.js.map +2 -2
- package/dist/cjs/decorators/query.js +4 -4
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +4 -4
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/replaceChildren.js +5 -5
- package/dist/cjs/decorators/replaceChildren.js.map +2 -2
- package/dist/cjs/decorators/setAttribute.js +46 -20
- package/dist/cjs/decorators/setAttribute.js.map +2 -2
- package/dist/cjs/decorators/style.js +4 -4
- package/dist/cjs/decorators/style.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -8
- package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +28 -1
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +4 -4
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +4 -4
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +4 -4
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +4 -4
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +13 -13
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +7 -7
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/decorators/addEventListener.js +1 -1
- package/dist/esm/decorators/addEventListener.js.map +1 -1
- package/dist/esm/decorators/appendChild.js +1 -1
- package/dist/esm/decorators/appendChild.js.map +1 -1
- package/dist/esm/decorators/attribute.js +122 -0
- package/dist/esm/decorators/attribute.js.map +7 -0
- package/dist/esm/decorators/changedAttribute.js +1 -1
- package/dist/esm/decorators/changedAttribute.js.map +1 -1
- package/dist/esm/decorators/classList.js +1 -1
- package/dist/esm/decorators/classList.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +31 -4
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +1 -1
- package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +1 -1
- package/dist/esm/decorators/lifecycles.js.map +1 -1
- package/dist/esm/decorators/onConnectedInnerHtml.js +1 -1
- package/dist/esm/decorators/onConnectedInnerHtml.js.map +1 -1
- package/dist/esm/decorators/query.js +1 -1
- package/dist/esm/decorators/query.js.map +1 -1
- package/dist/esm/decorators/queryAll.js +1 -1
- package/dist/esm/decorators/queryAll.js.map +1 -1
- package/dist/esm/decorators/replaceChildren.js +1 -1
- package/dist/esm/decorators/replaceChildren.js.map +1 -1
- package/dist/esm/decorators/setAttribute.js +42 -16
- package/dist/esm/decorators/setAttribute.js.map +2 -2
- package/dist/esm/decorators/style.js +1 -1
- package/dist/esm/decorators/style.js.map +1 -1
- package/dist/esm/elements/SwcAppEngine.js +4 -4
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +28 -1
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +1 -1
- package/dist/esm/elements/SwcAsync.js.map +1 -1
- package/dist/esm/elements/SwcChoose.js +1 -1
- package/dist/esm/elements/SwcChoose.js.map +1 -1
- package/dist/esm/elements/SwcIf.js +1 -1
- package/dist/esm/elements/SwcIf.js.map +1 -1
- package/dist/esm/elements/SwcLoop.js +1 -1
- package/dist/esm/elements/SwcLoop.js.map +1 -1
- package/dist/esm/elements/register.js +1 -1
- package/dist/esm/elements/register.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +2 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +5910 -3839
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/attribute.d.ts +23 -0
- package/dist/types/decorators/attribute.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/setAttribute.d.ts +3 -0
- package/dist/types/decorators/setAttribute.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +5 -4
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +5910 -3839
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -5
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/appendChild.ts +1 -1
- package/src/decorators/attribute.ts +158 -0
- package/src/decorators/changedAttribute.ts +1 -1
- package/src/decorators/classList.ts +1 -1
- package/src/decorators/elementDefine.ts +38 -5
- package/src/decorators/emitCustomEvent.ts +1 -1
- package/src/decorators/index.ts +1 -0
- package/src/decorators/lifecycles.ts +1 -1
- package/src/decorators/onConnectedInnerHtml.ts +1 -1
- package/src/decorators/query.ts +1 -1
- package/src/decorators/queryAll.ts +1 -1
- package/src/decorators/replaceChildren.ts +1 -1
- package/src/decorators/setAttribute.ts +49 -17
- package/src/decorators/style.ts +1 -1
- package/src/elements/SwcAppEngine.ts +9 -8
- package/src/elements/SwcAppMixin.ts +32 -1
- package/src/elements/SwcAsync.ts +1 -1
- package/src/elements/SwcChoose.ts +1 -1
- package/src/elements/SwcIf.ts +1 -1
- package/src/elements/SwcLoop.ts +1 -1
- package/src/elements/register.ts +1 -1
- package/src/index.ts +3 -2
- package/src/router/ElementRouter.ts +2 -2
- package/src/types.ts +2 -1
|
@@ -23,19 +23,19 @@ __export(setAttribute_exports, {
|
|
|
23
23
|
setAttribute: () => setAttribute
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(setAttribute_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_core = require("@dooboostore/core");
|
|
27
27
|
var import_elementDefine = require("./elementDefine");
|
|
28
28
|
var import_Utils = require("../utils/Utils");
|
|
29
29
|
const SET_ATTRIBUTE_METADATA_KEY = Symbol("simple-web-component:set-attribute");
|
|
30
|
-
function setAttribute(selector, name) {
|
|
30
|
+
function setAttribute(selector, name, options = {}) {
|
|
31
31
|
return (target, propertyKey, descriptor) => {
|
|
32
32
|
const constructor = target.constructor;
|
|
33
|
-
let metaList =
|
|
33
|
+
let metaList = import_core.ReflectUtils.getOwnMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor);
|
|
34
34
|
if (!metaList) {
|
|
35
35
|
metaList = /* @__PURE__ */ new Map();
|
|
36
|
-
|
|
36
|
+
import_core.ReflectUtils.defineMetadata(SET_ATTRIBUTE_METADATA_KEY, metaList, constructor);
|
|
37
37
|
}
|
|
38
|
-
metaList.set(propertyKey, { propertyKey, selector, name });
|
|
38
|
+
metaList.set(propertyKey, { propertyKey, selector, name, options });
|
|
39
39
|
const original = descriptor.value;
|
|
40
40
|
descriptor.value = async function(...args) {
|
|
41
41
|
(0, import_elementDefine.ensureInit)(this);
|
|
@@ -44,21 +44,47 @@ function setAttribute(selector, name) {
|
|
|
44
44
|
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
45
45
|
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
46
46
|
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
47
|
+
const targetEls = [];
|
|
48
|
+
const r = options.root || "auto";
|
|
49
|
+
const applyRoot = (t) => {
|
|
50
|
+
if (!t) return;
|
|
51
|
+
if (r === "auto") {
|
|
52
|
+
targetEls.push(t.shadowRoot || t);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (r === "light" || r === "all") targetEls.push(t);
|
|
56
|
+
if ((r === "shadow" || r === "all") && t.shadowRoot) targetEls.push(t.shadowRoot);
|
|
57
|
+
};
|
|
58
|
+
if (selector === ":window") targetEls.push(currentWin);
|
|
59
|
+
else if (selector === ":document") targetEls.push(currentWin.document);
|
|
60
|
+
else if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
61
|
+
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
62
|
+
else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
|
|
63
|
+
else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
|
|
64
|
+
else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
65
|
+
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
66
|
+
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
67
|
+
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
68
|
+
else if (selector === ":host" || !selector) applyRoot(this);
|
|
69
|
+
else {
|
|
70
|
+
const roots = [];
|
|
71
|
+
if (r === "shadow") {
|
|
72
|
+
if (this.shadowRoot) roots.push(this.shadowRoot);
|
|
73
|
+
} else if (r === "light") {
|
|
74
|
+
roots.push(this);
|
|
75
|
+
} else if (r === "all") {
|
|
76
|
+
roots.push(this);
|
|
77
|
+
if (this.shadowRoot) roots.push(this.shadowRoot);
|
|
78
|
+
} else {
|
|
79
|
+
roots.push(this.shadowRoot || this);
|
|
80
|
+
}
|
|
81
|
+
roots.forEach((root) => targetEls.push(...root.querySelectorAll(selector)));
|
|
82
|
+
}
|
|
83
|
+
targetEls.forEach((targetEl) => {
|
|
84
|
+
if (!targetEl || typeof targetEl.setAttribute !== "function") return;
|
|
59
85
|
if (res === null) targetEl.removeAttribute(name);
|
|
60
86
|
else targetEl.setAttribute(name, String(res));
|
|
61
|
-
}
|
|
87
|
+
});
|
|
62
88
|
}
|
|
63
89
|
return res;
|
|
64
90
|
};
|
|
@@ -66,11 +92,11 @@ function setAttribute(selector, name) {
|
|
|
66
92
|
}
|
|
67
93
|
const getSetAttributeMetadata = (target) => {
|
|
68
94
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
69
|
-
return
|
|
95
|
+
return import_core.ReflectUtils.getMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor);
|
|
70
96
|
};
|
|
71
97
|
const findAllSetAttributeMetadata = (target) => {
|
|
72
98
|
const result = /* @__PURE__ */ new Map();
|
|
73
|
-
const maps =
|
|
99
|
+
const maps = import_core.ReflectUtils.findAllMetadata(SET_ATTRIBUTE_METADATA_KEY, target);
|
|
74
100
|
maps.forEach((map) => {
|
|
75
101
|
if (map instanceof Map) {
|
|
76
102
|
map.forEach((v, k) => result.set(k, v));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/setAttribute.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport interface SetAttributeMetadata {\n propertyKey: string | symbol;\n selector: string;\n name: string;\n options: SwcQueryOptions;\n}\n\nexport const SET_ATTRIBUTE_METADATA_KEY = Symbol('simple-web-component:set-attribute');\n\n/**\n * @setAttribute decorator to surgically update an attribute of a target element.\n * Usage: @setAttribute(':host', 'count')\n * Usage: @setAttribute('#child', 'disabled')\n */\nexport function setAttribute(selector: string, name: string): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options?: SwcQueryOptions): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options: SwcQueryOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor) as Map<string | symbol, SetAttributeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, SetAttributeMetadata>();\n ReflectUtils.defineMetadata(SET_ATTRIBUTE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, name, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const hostSet = SwcUtils.getHostSet(this as any);\n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n\n const targetEls: any[] = [];\n const r = options.root || 'auto';\n\n const applyRoot = (t: any) => {\n if (!t) return;\n if (r === 'auto') {\n targetEls.push((t as any).shadowRoot || t);\n return;\n }\n if (r === 'light' || r === 'all') targetEls.push(t);\n if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);\n };\n\n if (selector === ':window') targetEls.push(currentWin);\n else if (selector === ':document') targetEls.push(currentWin.document as any);\n else if (selector === ':parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === ':appHost') applyRoot(hostSet.$appHost);\n else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);\n else if (selector === ':host' || !selector) applyRoot(this);\n else {\n const roots: any[] = [];\n if (r === 'shadow') {\n if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);\n } else if (r === 'light') {\n roots.push(this as any);\n } else if (r === 'all') {\n roots.push(this as any);\n if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);\n } else {\n roots.push((this as any).shadowRoot || (this as any));\n }\n roots.forEach(root => targetEls.push(...root.querySelectorAll(selector)));\n }\n\n targetEls.forEach(targetEl => {\n if (!targetEl || typeof (targetEl as any).setAttribute !== 'function') return;\n if (res === null) (targetEl as any).removeAttribute(name);\n else (targetEl as any).setAttribute(name, String(res));\n })\n }\n return res;\n };\n };\n}\n\nexport const getSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor);\n};\n\nexport const findAllSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> => {\n const result = new Map<string | symbol, SetAttributeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, SetAttributeMetadata>>(SET_ATTRIBUTE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA6C;AAC7C,mBAAyB;AAUlB,MAAM,6BAA6B,OAAO,oCAAoC;AAS9E,SAAS,aAAa,UAAkB,MAAc,UAA2B,CAAC,GAAoB;AAC3G,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,yBAAa,eAAe,4BAA4B,WAAW;AAClF,QAAI,CAAC,UAAU;AACb,iBAAW,oBAAI,IAA2C;AAC1D,+BAAa,eAAe,4BAA4B,UAAU,WAAW;AAAA,IAC/E;AACA,aAAS,IAAI,aAAa,EAAE,aAAa,UAAU,MAAM,QAAQ,CAAC;AAElE,UAAM,WAAW,WAAW;AAC5B,eAAW,QAAQ,kBAAmB,MAAa;AACjD,2CAAW,IAAI;AACf,YAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI;AAC3C,UAAI,QAAQ,QAAW;AACr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Y,OAAM,KAAM,KAAa,UAAU;AAAA,UACnE,OAAO;AACL,kBAAM,KAAM,KAAa,cAAe,IAAY;AAAA,UACtD;AACA,gBAAM,QAAQ,UAAQ,UAAU,KAAK,GAAG,KAAK,iBAAiB,QAAQ,CAAC,CAAC;AAAA,QAC1E;AAEA,kBAAU,QAAQ,cAAY;AAC5B,cAAI,CAAC,YAAY,OAAQ,SAAiB,iBAAiB,WAAY;AACvE,cAAI,QAAQ,KAAM,CAAC,SAAiB,gBAAgB,IAAI;AAAA,cACnD,CAAC,SAAiB,aAAa,MAAM,OAAO,GAAG,CAAC;AAAA,QACvD,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,0BAA0B,CAAC,WAAwE;AAC9G,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,4BAA4B,WAAW;AACzE;AAEO,MAAM,8BAA8B,CAAC,WAA4D;AACtG,QAAM,SAAS,oBAAI,IAA2C;AAC9D,QAAM,OAAO,yBAAa,gBAA4D,4BAA4B,MAAM;AACxH,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,7 +24,7 @@ __export(style_exports, {
|
|
|
24
24
|
updateStyle: () => updateStyle
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(style_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_core = require("@dooboostore/core");
|
|
28
28
|
var import_elementDefine = require("./elementDefine");
|
|
29
29
|
var import_Utils = require("../utils/Utils");
|
|
30
30
|
const STYLE_METADATA_KEY = Symbol("simple-web-component:style");
|
|
@@ -32,10 +32,10 @@ function createStyleDecorator(action) {
|
|
|
32
32
|
return (selector) => {
|
|
33
33
|
return (target, propertyKey, descriptor) => {
|
|
34
34
|
const constructor = target.constructor;
|
|
35
|
-
let metaList =
|
|
35
|
+
let metaList = import_core.ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor);
|
|
36
36
|
if (!metaList) {
|
|
37
37
|
metaList = /* @__PURE__ */ new Map();
|
|
38
|
-
|
|
38
|
+
import_core.ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);
|
|
39
39
|
}
|
|
40
40
|
metaList.set(propertyKey, { propertyKey, selector, action });
|
|
41
41
|
const original = descriptor.value;
|
|
@@ -77,7 +77,7 @@ const updateStyle = createStyleDecorator("update");
|
|
|
77
77
|
const removeStyle = createStyleDecorator("remove");
|
|
78
78
|
const findAllStyleMetadata = (target) => {
|
|
79
79
|
const result = /* @__PURE__ */ new Map();
|
|
80
|
-
const maps =
|
|
80
|
+
const maps = import_core.ReflectUtils.findAllMetadata(STYLE_METADATA_KEY, target);
|
|
81
81
|
maps.forEach((map) => {
|
|
82
82
|
if (map instanceof Map) {
|
|
83
83
|
map.forEach((v, k) => result.set(k, v));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/style.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\nexport interface StyleMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: StyleAction;\n}\n\nexport const STYLE_METADATA_KEY = Symbol('simple-web-component:style');\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: string): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const hostSet = SwcUtils.getHostSet(this as any);\n let targetEl: HTMLElement | null = null;\n if (selector === ':host' || !selector) targetEl = this as any;\n else if (selector === ':parentHost') targetEl = hostSet.$parentHost;\n else if (selector === ':appHost') targetEl = hostSet.$appHost;\n else targetEl = (this.shadowRoot || (this as any)).querySelector(selector);\n\n if (targetEl) {\n if (action === 'set') {\n targetEl.style.cssText = '';\n if (typeof res === 'object' && res !== null) {\n Object.assign(targetEl.style, res);\n } else if (typeof res === 'string') {\n targetEl.style.cssText = res;\n }\n } else if (action === 'update') {\n if (typeof res === 'object' && res !== null) {\n Object.assign(targetEl.style, res);\n }\n } else if (action === 'remove') {\n const props = Array.isArray(res) ? res : [res];\n props.forEach(p => targetEl!.style.removeProperty(String(p)));\n }\n }\n }\n return res;\n };\n };\n };\n}\n\n/**\n * @setStyle decorator to surgically set styles on a target element (replaces all existing styles).\n * Usage: @setStyle('#box') getStyles() { return { color: 'red', display: 'block' }; }\n */\nexport const setStyle = createStyleDecorator('set');\n\n/**\n * @updateStyle decorator to surgically update styles on a target element (merges with existing styles).\n * Usage: @updateStyle('#box') updateStyles() { return { color: 'blue' }; }\n */\nexport const updateStyle = createStyleDecorator('update');\n\n/**\n * @removeStyle decorator to surgically remove styles from a target element.\n * Usage: @removeStyle('#box') clearStyles() { return ['color', 'display']; }\n */\nexport const removeStyle = createStyleDecorator('remove');\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleMetadata> => {\n const result = new Map<string | symbol, StyleMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleMetadata>>(STYLE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAUlB,MAAM,qBAAqB,OAAO,4BAA4B;AAErE,SAAS,qBAAqB,QAAqB;AACjD,SAAO,CAAC,aAAsC;AAC5C,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,oBAAoB,WAAW;AAC1E,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAAoC;AACnD,iCAAa,eAAe,oBAAoB,UAAU,WAAW;AAAA,MACvE;AACA,eAAS,IAAI,aAAa,EAAE,aAAa,UAAU,OAAO,CAAC;AAE3D,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,kBAAmB,MAAa;AACjD,6CAAW,IAAI;AACf,cAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI;AAC3C,YAAI,QAAQ,QAAW;AACrB,gBAAM,UAAU,sBAAS,WAAW,IAAW;AAC/C,cAAI,WAA+B;AACnC,cAAI,aAAa,WAAW,CAAC,SAAU,YAAW;AAAA,mBACzC,aAAa,cAAe,YAAW,QAAQ;AAAA,mBAC/C,aAAa,WAAY,YAAW,QAAQ;AAAA,cAChD,aAAY,KAAK,cAAe,MAAc,cAAc,QAAQ;AAEzE,cAAI,UAAU;AACZ,gBAAI,WAAW,OAAO;AACpB,uBAAS,MAAM,UAAU;AACzB,kBAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,uBAAO,OAAO,SAAS,OAAO,GAAG;AAAA,cACnC,WAAW,OAAO,QAAQ,UAAU;AAClC,yBAAS,MAAM,UAAU;AAAA,cAC3B;AAAA,YACF,WAAW,WAAW,UAAU;AAC9B,kBAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,uBAAO,OAAO,SAAS,OAAO,GAAG;AAAA,cACnC;AAAA,YACF,WAAW,WAAW,UAAU;AAC9B,oBAAM,QAAQ,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AAC7C,oBAAM,QAAQ,OAAK,SAAU,MAAM,eAAe,OAAO,CAAC,CAAC,CAAC;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAMO,MAAM,WAAW,qBAAqB,KAAK;AAM3C,MAAM,cAAc,qBAAqB,QAAQ;AAMjD,MAAM,cAAc,qBAAqB,QAAQ;AAEjD,MAAM,uBAAuB,CAAC,WAAqD;AACxF,QAAM,SAAS,oBAAI,IAAoC;AACvD,QAAM,OAAO,yBAAa,gBAAqD,oBAAoB,MAAM;AACzG,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,12 +21,12 @@ __export(SwcAppEngine_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(SwcAppEngine_exports);
|
|
23
23
|
var import_SimpleApplication = require("@dooboostore/simple-boot/SimpleApplication");
|
|
24
|
-
var
|
|
25
|
-
var
|
|
24
|
+
var import_core_web = require("@dooboostore/core-web");
|
|
25
|
+
var import_core_web2 = require("@dooboostore/core-web");
|
|
26
26
|
var import_ElementRouter = require("../router/ElementRouter");
|
|
27
27
|
var import_SimOption = require("@dooboostore/simple-boot/SimOption");
|
|
28
|
-
var
|
|
29
|
-
var
|
|
28
|
+
var import_core_web3 = require("@dooboostore/core-web");
|
|
29
|
+
var import_core3 = require("@dooboostore/core");
|
|
30
30
|
var import_Utils = require("../utils/Utils");
|
|
31
31
|
class SwcAppEngine {
|
|
32
32
|
constructor(host) {
|
|
@@ -42,7 +42,7 @@ class SwcAppEngine {
|
|
|
42
42
|
const configStr = this.host.getAttribute("swc-get-application-config");
|
|
43
43
|
if (configStr) {
|
|
44
44
|
try {
|
|
45
|
-
userConfig =
|
|
45
|
+
userConfig = import_core3.FunctionUtils.executeReturn({
|
|
46
46
|
script: configStr,
|
|
47
47
|
context: this.host,
|
|
48
48
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this.host)
|
|
@@ -62,9 +62,9 @@ class SwcAppEngine {
|
|
|
62
62
|
...userConfig
|
|
63
63
|
};
|
|
64
64
|
if (_config.routeType === "path") {
|
|
65
|
-
this.router = new
|
|
65
|
+
this.router = new import_core_web.PathRouter({ window: _config.window, firstUrl: _config.path });
|
|
66
66
|
} else if (_config.routeType === "hash") {
|
|
67
|
-
this.router = new
|
|
67
|
+
this.router = new import_core_web2.HashRouter({ window: _config.window, firstUrl: _config.path });
|
|
68
68
|
} else if (_config.routeType === "element") {
|
|
69
69
|
this.router = new import_ElementRouter.ElementRouter({ window: _config.window, firstUrl: _config.path });
|
|
70
70
|
}
|
|
@@ -77,7 +77,7 @@ class SwcAppEngine {
|
|
|
77
77
|
}
|
|
78
78
|
this.simpleApplication = new import_SimpleApplication.SimpleApplication(new import_SimOption.SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));
|
|
79
79
|
const otherInstanceSim = /* @__PURE__ */ new Map();
|
|
80
|
-
if (this.router) otherInstanceSim.set(
|
|
80
|
+
if (this.router) otherInstanceSim.set(import_core_web3.Router, this.router);
|
|
81
81
|
this.simpleApplication.run(otherInstanceSim);
|
|
82
82
|
const data = this.simpleApplication.sim(_config.rootRouter);
|
|
83
83
|
if (data instanceof Node) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAppEngine.ts"],
|
|
4
|
-
"sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAkC;AAClC,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web';\nimport { HashRouter } from '@dooboostore/core-web';\nimport { ElementRouter } from '../router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot/SimOption';\nimport { Router, RouterEventType } from '@dooboostore/core-web';\nimport { Subscription } from '@dooboostore/core';\nimport { ConstructorType, OptionalType } from '@dooboostore/core';\nimport { FunctionUtils } from '@dooboostore/core';\nimport { SwcUtils } from '../utils/Utils';\n\nexport type SwcConfigType = {\n rootRouter: ConstructorType<any> | symbol;\n routeType: 'path' | 'hash' | 'element';\n connectMode?: 'direct' | 'swap';\n path?: string;\n window: Window;\n};\n\nexport type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _isInitialized = false;\n\n constructor(private host: HTMLElement) {}\n\n async connect(config?: SwcAttributeConfigType) {\n if (this._isInitialized) return;\n\n let userConfig = config;\n const win = this.host.ownerDocument?.defaultView || window;\n const Node = (win as any).Node as typeof globalThis.Node;\n if (!userConfig) {\n const configStr = this.host.getAttribute('swc-get-application-config');\n if (configStr) {\n try {\n userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this.host,\n args: SwcUtils.getHelperAndHostSet(win, this.host)\n });\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Script execution failed:', e);\n }\n }\n }\n\n if (!userConfig) return;\n this._isInitialized = true;\n\n try {\n if (userConfig.rootRouter) {\n const _config: SwcConfigType = {\n routeType: 'element',\n window: win,\n ...userConfig\n } as SwcConfigType;\n\n // Router Selection\n if (_config.routeType === 'path') {\n this.router = new PathRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'hash') {\n this.router = new HashRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'element') {\n this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });\n }\n\n // Routing sync\n if (this.router) {\n this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n if (route.triggerPoint === 'end') {\n this.simpleApplication?.routing(route.path);\n }\n });\n }\n\n\n // App start\n this.simpleApplication = new SimpleApplication(new SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));\n\n const otherInstanceSim = new Map<any, any>();\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n // Rendering\n const data = this.simpleApplication.sim(_config.rootRouter);\n if (data instanceof Node) {\n if (this.host.shadowRoot) this.host.shadowRoot.replaceChildren(data);\n else this.host.replaceChildren(data);\n }\n\n if (_config.path) this.router?.go(_config.path);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAkC;AAClC,sBAA2B;AAC3B,IAAAA,mBAA2B;AAC3B,2BAA8B;AAC9B,uBAA0B;AAC1B,IAAAA,mBAAwC;AAGxC,IAAAC,eAA8B;AAC9B,mBAAyB;AAYlB,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AAFpB,SAAQ,iBAAiB;AAAA,EAEe;AAAA,EAExC,MAAM,QAAQ,QAAiC;AAC7C,QAAI,KAAK,eAAgB;AAEzB,QAAI,aAAa;AACjB,UAAM,MAAM,KAAK,KAAK,eAAe,eAA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;AAC3C,YAAI,KAAK,OAAQ,kBAAiB,IAAI,yBAAQ,KAAK,MAAM;AACzD,aAAK,kBAAkB,IAAI,gBAAgB;AAG3C,cAAM,OAAO,KAAK,kBAAkB,IAAI,QAAQ,UAAU;AAC1D,YAAI,gBAAgB,MAAM;AACxB,cAAI,KAAK,KAAK,WAAY,MAAK,KAAK,WAAW,gBAAgB,IAAI;AAAA,cAC9D,MAAK,KAAK,gBAAgB,IAAI;AAAA,QACrC;AAEA,YAAI,QAAQ,KAAM,MAAK,QAAQ,GAAG,QAAQ,IAAI;AAAA,MAChD;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,CAAC;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
|
|
6
|
+
"names": ["import_core_web", "import_core"]
|
|
7
7
|
}
|
|
@@ -34,7 +34,34 @@ function SwcAppMixin(Base) {
|
|
|
34
34
|
return this.__swc_engine.router;
|
|
35
35
|
}
|
|
36
36
|
async connect(config) {
|
|
37
|
-
|
|
37
|
+
const mode = config?.connectMode || "direct";
|
|
38
|
+
if (mode !== "swap") {
|
|
39
|
+
await this.__swc_engine.connect(config);
|
|
40
|
+
this.setAttribute("swc-connect-mode", "direct");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const parent = this.parentNode;
|
|
44
|
+
if (!parent) {
|
|
45
|
+
await this.__swc_engine.connect(config);
|
|
46
|
+
this.setAttribute("swc-connect-mode", "direct");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const clonedApp = this.cloneNode(true);
|
|
50
|
+
clonedApp.style.display = "none";
|
|
51
|
+
parent.insertBefore(clonedApp, this.nextSibling);
|
|
52
|
+
try {
|
|
53
|
+
await clonedApp.connect({ ...config || {}, connectMode: "direct" });
|
|
54
|
+
if (this.parentNode) {
|
|
55
|
+
this.parentNode.removeChild(this);
|
|
56
|
+
}
|
|
57
|
+
clonedApp.setAttribute("swc-connect-mode", "swap");
|
|
58
|
+
clonedApp.style.display = "";
|
|
59
|
+
} catch (e) {
|
|
60
|
+
if (clonedApp.parentNode) {
|
|
61
|
+
clonedApp.parentNode.removeChild(clonedApp);
|
|
62
|
+
}
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
38
65
|
}
|
|
39
66
|
connectedCallback() {
|
|
40
67
|
if (super.connectedCallback) super.connectedCallback();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAppMixin.ts"],
|
|
4
|
-
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType } from './SwcAppEngine';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n return class extends Base {\n __swc_engine = new SwcAppEngine(this as any);\n\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n await this.__swc_engine.connect(config);\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n this.connect();\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this.__swc_engine.disconnect();\n }\n\n async routing(path: string) {\n await this.__swc_engine.router?.go(path);\n }\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAqD;AAE9C,SAAS,YAA6D,MAAS;AACpF,SAAO,cAAc,KAAK;AAAA,IAAnB;AAAA;AACL,0BAAe,IAAI,iCAAa,IAAW;AAAA;AAAA,IAE3C,IAAI,oBAAoB;AACtB,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,IAAI,SAAS;AACX,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IAEA,MAAM,QAAQ,QAAiC;AAC7C,YAAM,KAAK,aAAa,QAAQ,MAAM;AAAA,
|
|
4
|
+
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType } from './SwcAppEngine';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n return class extends Base {\n __swc_engine = new SwcAppEngine(this as any);\n\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n const mode = config?.connectMode || 'direct';\n\n if (mode !== 'swap') {\n await this.__swc_engine.connect(config);\n this.setAttribute('swc-connect-mode', 'direct');\n return;\n }\n\n const parent = this.parentNode;\n if (!parent) {\n await this.__swc_engine.connect(config);\n this.setAttribute('swc-connect-mode', 'direct');\n return;\n }\n\n const clonedApp = this.cloneNode(true) as any;\n clonedApp.style.display = 'none';\n parent.insertBefore(clonedApp, this.nextSibling);\n\n try {\n await clonedApp.connect({ ...(config || {}), connectMode: 'direct' });\n if (this.parentNode) {\n this.parentNode.removeChild(this);\n }\n clonedApp.setAttribute('swc-connect-mode', 'swap');\n clonedApp.style.display = '';\n } catch (e) {\n if (clonedApp.parentNode) {\n clonedApp.parentNode.removeChild(clonedApp);\n }\n throw e;\n }\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n this.connect();\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this.__swc_engine.disconnect();\n }\n\n async routing(path: string) {\n await this.__swc_engine.router?.go(path);\n }\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAqD;AAE9C,SAAS,YAA6D,MAAS;AACpF,SAAO,cAAc,KAAK;AAAA,IAAnB;AAAA;AACL,0BAAe,IAAI,iCAAa,IAAW;AAAA;AAAA,IAE3C,IAAI,oBAAoB;AACtB,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,IAAI,SAAS;AACX,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IAEA,MAAM,QAAQ,QAAiC;AAC7C,YAAM,OAAO,QAAQ,eAAe;AAEpC,UAAI,SAAS,QAAQ;AACnB,cAAM,KAAK,aAAa,QAAQ,MAAM;AACtC,aAAK,aAAa,oBAAoB,QAAQ;AAC9C;AAAA,MACF;AAEA,YAAM,SAAS,KAAK;AACpB,UAAI,CAAC,QAAQ;AACX,cAAM,KAAK,aAAa,QAAQ,MAAM;AACtC,aAAK,aAAa,oBAAoB,QAAQ;AAC9C;AAAA,MACF;AAEA,YAAM,YAAY,KAAK,UAAU,IAAI;AACrC,gBAAU,MAAM,UAAU;AAC1B,aAAO,aAAa,WAAW,KAAK,WAAW;AAE/C,UAAI;AACF,cAAM,UAAU,QAAQ,EAAE,GAAI,UAAU,CAAC,GAAI,aAAa,SAAS,CAAC;AACpE,YAAI,KAAK,YAAY;AACnB,eAAK,WAAW,YAAY,IAAI;AAAA,QAClC;AACA,kBAAU,aAAa,oBAAoB,MAAM;AACjD,kBAAU,MAAM,UAAU;AAAA,MAC5B,SAAS,GAAG;AACV,YAAI,UAAU,YAAY;AACxB,oBAAU,WAAW,YAAY,SAAS;AAAA,QAC5C;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IAEA,oBAAoB;AAElB,UAAI,MAAM,kBAAmB,OAAM,kBAAkB;AACrD,WAAK,QAAQ;AAAA,IACf;AAAA,IAEA,uBAAuB;AAErB,UAAI,MAAM,qBAAsB,OAAM,qBAAqB;AAC3D,WAAK,aAAa,WAAW;AAAA,IAC/B;AAAA,IAEA,MAAM,QAAQ,MAAc;AAC1B,YAAM,KAAK,aAAa,QAAQ,GAAG,IAAI;AAAA,IACzC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(SwcAsync_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(SwcAsync_exports);
|
|
23
23
|
var import_changedAttribute = require("../decorators/changedAttribute");
|
|
24
24
|
var import_Utils = require("../utils/Utils");
|
|
25
|
-
var
|
|
25
|
+
var import_core = require("@dooboostore/core");
|
|
26
26
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
27
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
28
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -43,7 +43,7 @@ class SwcAsync extends HTMLTemplateElement {
|
|
|
43
43
|
if (!portalScript)
|
|
44
44
|
return this.parentElement;
|
|
45
45
|
const win = this.ownerDocument?.defaultView || window;
|
|
46
|
-
const res =
|
|
46
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
47
47
|
script: portalScript,
|
|
48
48
|
context: this,
|
|
49
49
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
@@ -58,14 +58,14 @@ class SwcAsync extends HTMLTemplateElement {
|
|
|
58
58
|
const script = this.getAttribute(attr);
|
|
59
59
|
if (!script)
|
|
60
60
|
return;
|
|
61
|
-
|
|
61
|
+
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
62
62
|
}
|
|
63
63
|
refresh() {
|
|
64
64
|
const script = this.getAttribute("on-get-value");
|
|
65
65
|
if (!script)
|
|
66
66
|
return;
|
|
67
67
|
const win = this.ownerDocument?.defaultView || window;
|
|
68
|
-
const result =
|
|
68
|
+
const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
|
|
69
69
|
if (result instanceof Promise) {
|
|
70
70
|
this.render("loading");
|
|
71
71
|
result.then((v) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAsync.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,
|
|
4
|
+
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttribute('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) return;\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n\n if (result instanceof Promise) {\n this.render('loading');\n result\n .then(v => {\n this._value = v;\n this.render('success');\n })\n .catch(e => this.render('error'));\n } else {\n this._value = result;\n this.render('success');\n }\n }\n\n private render(state: string) {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,iBAAiB,oBAAmB;EAAjD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EAsFxB;EApFU,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,sBAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,UAAO;AACb,UAAM,SAAS,KAAK,aAAa,cAAc;AAC/C,QAAI,CAAC;AAAQ;AACb,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,SAAS,0BAAc,cAAc,EAAE,QA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C,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA5DQ,WAAA;MADP,0CAAiB,cAAc;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(SwcChoose_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(SwcChoose_exports);
|
|
23
23
|
var import_changedAttribute = require("../decorators/changedAttribute");
|
|
24
24
|
var import_Utils = require("../utils/Utils");
|
|
25
|
-
var
|
|
25
|
+
var import_core = require("@dooboostore/core");
|
|
26
26
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
27
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
28
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -50,7 +50,7 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
50
50
|
if (!portalScript)
|
|
51
51
|
return this.parentElement;
|
|
52
52
|
const win = this.ownerDocument?.defaultView || window;
|
|
53
|
-
const res =
|
|
53
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
54
54
|
script: portalScript,
|
|
55
55
|
context: this,
|
|
56
56
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
@@ -65,7 +65,7 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
65
65
|
const script = this.getAttribute(attr);
|
|
66
66
|
if (!script)
|
|
67
67
|
return;
|
|
68
|
-
|
|
68
|
+
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
69
69
|
}
|
|
70
70
|
refresh() {
|
|
71
71
|
const script = this.getAttribute("on-get-value");
|
|
@@ -74,7 +74,7 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
const win = this.ownerDocument?.defaultView || window;
|
|
77
|
-
const result =
|
|
77
|
+
const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
|
|
78
78
|
this.value = result;
|
|
79
79
|
}
|
|
80
80
|
render() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,
|
|
4
|
+
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttribute('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) {\n this.value = null;\n return;\n }\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n this.value = result;\n }\n\n private render() {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when' && String(t.getAttribute('value')) === String(this._value)) {\n selected = t;\n break;\n }\n }\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n if (target) {\n const clone = target.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EA8FxB;EA5FE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEQ,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,U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AAM,WAAW,KAAK,OAAO,OAAO,OAAK,EAAE,aAAa,CAAC;AACzD,YAAM,YAAY,EAAE,GAAG,WAAW,QAAQ,KAAK,QAAQ,QAAQ,KAAK,QAAQ,WAAW,UAAU,eAAe,SAAS,CAAC,EAAC;AAE3H,WAAK,OAAO,QAAQ,CAAC,GAAG,YAAW;AACjC,YAAI,aAAa;AAAc,YAAU,aAAa;AACtD,aAAK,sBAAsB,iBAAiB,EAAE,GAAG,WAAW,OAAO,GAAG,YAAY,SAAS,YAAY,EAAE,aAAa,EAAC,CAAE;MAC3H,CAAC;AAED,WAAK,sBAAsB,kBAAkB,SAAS;AAEtD,UAAI,WAAW,KAAK,eAAe;AACjC,eAAO,aAAa,OAAO,KAAK,WAAW;MAC7C,OAAO;AACL,eAAO,YAAY,KAAK;MAC1B;IACF;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA5DQ,WAAA;MADP,0CAAiB,cAAc;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(SwcIf_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(SwcIf_exports);
|
|
23
23
|
var import_changedAttribute = require("../decorators/changedAttribute");
|
|
24
24
|
var import_Utils = require("../utils/Utils");
|
|
25
|
-
var
|
|
25
|
+
var import_core = require("@dooboostore/core");
|
|
26
26
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
27
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
28
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -50,7 +50,7 @@ class SwcIf extends HTMLTemplateElement {
|
|
|
50
50
|
if (!portalScript)
|
|
51
51
|
return this.parentElement;
|
|
52
52
|
const win = this.ownerDocument?.defaultView || window;
|
|
53
|
-
const res =
|
|
53
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
54
54
|
script: portalScript,
|
|
55
55
|
context: this,
|
|
56
56
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
@@ -65,7 +65,7 @@ class SwcIf extends HTMLTemplateElement {
|
|
|
65
65
|
const script = this.getAttribute(attr);
|
|
66
66
|
if (!script)
|
|
67
67
|
return;
|
|
68
|
-
|
|
68
|
+
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
69
69
|
}
|
|
70
70
|
refreshValue() {
|
|
71
71
|
const script = this.getAttribute("on-get-value");
|
|
@@ -74,7 +74,7 @@ class SwcIf extends HTMLTemplateElement {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
const win = this.ownerDocument?.defaultView || window;
|
|
77
|
-
const res =
|
|
77
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
78
78
|
script,
|
|
79
79
|
context: this,
|
|
80
80
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcIf.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,
|
|
4
|
+
"sourcesContent": ["import { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcIf extends HTMLTemplateElement {\n private _value = false;\n private _nodes: Node[] = [];\n\n get value(): boolean {\n return this._value;\n }\n set value(nv: any) {\n this._value = Boolean(nv);\n this.render();\n }\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttribute('on-get-value')\n private refreshValue() {\n const script = this.getAttribute('on-get-value');\n if (!script) {\n this.value = false;\n return;\n }\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof Promise) {\n res.then(v => (this.value = v)).catch(() => (this.value = false));\n } else {\n this.value = res;\n }\n }\n\n private render() {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n let targetTpl: HTMLTemplateElement | null = null;\n if (this._value) {\n targetTpl = this;\n } else {\n targetTpl = this.content.querySelector('template[is=\"swc-default\"]') as HTMLTemplateElement;\n }\n\n if (targetTpl) {\n const clone = targetTpl.content.cloneNode(true) as DocumentFragment;\n // If it's the host template, remove sub-templates from clone\n if (targetTpl === this) {\n clone.querySelectorAll('template[is^=\"swc-\"]').forEach(t => t.remove());\n }\n\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n this._nodes.forEach((node, nodeIdx) => {\n if (node instanceof HTMLElement) (node as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: node, $nodeIndex: nodeIdx, $isElement: node.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refreshValue();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,8BAAiC;AACjC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,cAAc,oBAAmB;EAA9C,cAAA;;AACU,SAAA,SAAS;AACT,SAAA,SAAiB,CAAA;EAyG3B;EAvGE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS,QAAQ,EAAE;AACxB,SAAK,OAAM;EACb;EAEQ,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,sBAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,eAAY;AAClB,UAAM,SAAS,KAAK,aAAa,cAAc;AAC/C,QAAI,CAAC,QAAQ;AACX,WAAK,QAAQ;AACb;IACF;AACA,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;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b,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,aAAY;EACnB;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAvEQ,WAAA;MADP,0CAAiB,cAAc;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(SwcLoop_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(SwcLoop_exports);
|
|
23
23
|
var import_changedAttribute = require("../decorators/changedAttribute");
|
|
24
24
|
var import_Utils = require("../utils/Utils");
|
|
25
|
-
var
|
|
25
|
+
var import_core = require("@dooboostore/core");
|
|
26
26
|
var __decorate = function(decorators, target, key, desc) {
|
|
27
27
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
28
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -50,7 +50,7 @@ class SwcLoop extends HTMLTemplateElement {
|
|
|
50
50
|
if (!portalScript)
|
|
51
51
|
return this.parentElement;
|
|
52
52
|
const win = this.ownerDocument?.defaultView || window;
|
|
53
|
-
const res =
|
|
53
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
54
54
|
script: portalScript,
|
|
55
55
|
context: this,
|
|
56
56
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|
|
@@ -65,7 +65,7 @@ class SwcLoop extends HTMLTemplateElement {
|
|
|
65
65
|
const script = this.getAttribute(attr);
|
|
66
66
|
if (!script)
|
|
67
67
|
return;
|
|
68
|
-
|
|
68
|
+
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
69
69
|
}
|
|
70
70
|
_cleanup() {
|
|
71
71
|
this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
|
|
@@ -78,7 +78,7 @@ class SwcLoop extends HTMLTemplateElement {
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
const win = this.ownerDocument?.defaultView || window;
|
|
81
|
-
const res =
|
|
81
|
+
const res = import_core.FunctionUtils.executeReturn({
|
|
82
82
|
script,
|
|
83
83
|
context: this,
|
|
84
84
|
args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
|