@dooboostore/simple-web-component 1.0.23 → 1.0.25
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 +64 -3212
- package/dist/cjs/decorators/addEventListener.js +1 -1
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +148 -0
- package/dist/cjs/decorators/applyAttribute.js.map +7 -0
- package/dist/cjs/decorators/applyClass.js +164 -0
- package/dist/cjs/decorators/applyClass.js.map +7 -0
- package/dist/cjs/decorators/applyNode.js +97 -109
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +135 -0
- package/dist/cjs/decorators/applyStyle.js.map +7 -0
- package/dist/cjs/decorators/attribute.js +24 -11
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +1 -1
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +14 -23
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +5 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -3
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +9 -9
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +78 -3
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +78 -3
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +19 -4
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +2 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +141 -2
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +1 -1
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +129 -0
- package/dist/esm/decorators/applyAttribute.js.map +7 -0
- package/dist/esm/decorators/applyClass.js +145 -0
- package/dist/esm/decorators/applyClass.js.map +7 -0
- package/dist/esm/decorators/applyNode.js +97 -109
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +116 -0
- package/dist/esm/decorators/applyStyle.js.map +7 -0
- package/dist/esm/decorators/attribute.js +24 -11
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +1 -1
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +14 -23
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +5 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -3
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +9 -9
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +78 -3
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +78 -3
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +19 -4
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +2 -0
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +141 -2
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3191 -506
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -0
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -0
- package/dist/types/decorators/applyClass.d.ts +65 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -0
- package/dist/types/decorators/applyNode.d.ts +18 -104
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +21 -0
- package/dist/types/decorators/applyStyle.d.ts.map +1 -0
- package/dist/types/decorators/attribute.d.ts +12 -14
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- 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 +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -3
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +68 -4
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +70 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +7 -0
- 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 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +49 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3191 -506
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +147 -0
- package/src/decorators/applyClass.ts +158 -0
- package/src/decorators/applyNode.ts +126 -225
- package/src/decorators/applyStyle.ts +128 -0
- package/src/decorators/attribute.ts +42 -43
- package/src/decorators/changedAttributeHost.ts +2 -2
- package/src/decorators/elementDefine.ts +18 -39
- package/src/decorators/emitCustomEvent.ts +6 -3
- package/src/decorators/index.ts +3 -3
- package/src/decorators/lifecycles.ts +9 -11
- package/src/decorators/query.ts +148 -6
- package/src/decorators/queryAll.ts +149 -3
- package/src/elements/SwcAppEngine.ts +32 -4
- package/src/elements/SwcAppMixin.ts +2 -0
- package/src/index.ts +6 -6
- package/src/utils/Utils.ts +146 -1
- package/dist/cjs/decorators/classList.js +0 -134
- package/dist/cjs/decorators/classList.js.map +0 -7
- package/dist/cjs/decorators/setAttribute.js +0 -111
- package/dist/cjs/decorators/setAttribute.js.map +0 -7
- package/dist/cjs/decorators/style.js +0 -114
- package/dist/cjs/decorators/style.js.map +0 -7
- package/dist/cjs/utils/TemplateUtils.js +0 -109
- package/dist/cjs/utils/TemplateUtils.js.map +0 -7
- package/dist/esm/decorators/classList.js +0 -115
- package/dist/esm/decorators/classList.js.map +0 -7
- package/dist/esm/decorators/setAttribute.js +0 -92
- package/dist/esm/decorators/setAttribute.js.map +0 -7
- package/dist/esm/decorators/style.js +0 -95
- package/dist/esm/decorators/style.js.map +0 -7
- package/dist/esm/utils/TemplateUtils.js +0 -90
- package/dist/esm/utils/TemplateUtils.js.map +0 -7
- package/dist/types/decorators/classList.d.ts +0 -61
- package/dist/types/decorators/classList.d.ts.map +0 -1
- package/dist/types/decorators/setAttribute.d.ts +0 -23
- package/dist/types/decorators/setAttribute.d.ts.map +0 -1
- package/dist/types/decorators/style.d.ts +0 -49
- package/dist/types/decorators/style.d.ts.map +0 -1
- package/dist/types/utils/TemplateUtils.d.ts +0 -59
- package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
- package/src/decorators/classList.ts +0 -172
- package/src/decorators/setAttribute.ts +0 -113
- package/src/decorators/style.ts +0 -140
- package/src/utils/TemplateUtils.ts +0 -92
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
import { ReflectUtils } from "@dooboostore/core";
|
|
2
2
|
import { ensureInit, getElementConfig } from "./elementDefine.js";
|
|
3
|
-
|
|
3
|
+
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
+
const APPLY_NODE_METADATA_KEY = Symbol.for("simple-web-component:apply-node");
|
|
4
5
|
const normalizeNodes = (res, doc) => {
|
|
5
6
|
const items = Array.isArray(res) ? res : [res];
|
|
6
7
|
return items.map((it) => {
|
|
7
|
-
if (it instanceof Node)
|
|
8
|
-
return it;
|
|
8
|
+
if (it instanceof Node) return it;
|
|
9
9
|
return doc.createTextNode(it !== void 0 && it !== null ? String(it) : "");
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
+
const applyToDom = (targetEl, res, pos, doc) => {
|
|
13
|
+
if (!targetEl) return;
|
|
14
|
+
if (pos === "innerHtml") {
|
|
15
|
+
targetEl.innerHTML = res !== void 0 && res !== null ? String(res) : "";
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (pos === "innerText") {
|
|
19
|
+
if (targetEl.innerText !== void 0) {
|
|
20
|
+
targetEl.innerText = res !== void 0 && res !== null ? String(res) : "";
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const isShadowRoot = targetEl instanceof ShadowRoot;
|
|
25
|
+
const nodes = normalizeNodes(res, doc);
|
|
26
|
+
if (pos === "replace") {
|
|
27
|
+
if (!isShadowRoot) targetEl.replaceWith(...nodes);
|
|
28
|
+
} else if (pos === "replaceChildren") {
|
|
29
|
+
targetEl.replaceChildren(...nodes);
|
|
30
|
+
} else {
|
|
31
|
+
if (pos === "beforeEnd") targetEl.append(...nodes);
|
|
32
|
+
else if (pos === "afterBegin") targetEl.prepend(...nodes);
|
|
33
|
+
else if (pos === "beforeBegin" && !isShadowRoot) targetEl.before(...nodes);
|
|
34
|
+
else if (pos === "afterEnd" && !isShadowRoot) targetEl.after(...nodes);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
12
37
|
function applyNode(selector, options = { position: "beforeEnd" }) {
|
|
13
|
-
return (
|
|
14
|
-
const constructor =
|
|
38
|
+
return (targetObj, propertyKey, descriptor) => {
|
|
39
|
+
const constructor = targetObj.constructor;
|
|
15
40
|
let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor);
|
|
16
41
|
if (!metaList) {
|
|
17
42
|
metaList = /* @__PURE__ */ new Map();
|
|
@@ -19,81 +44,58 @@ function applyNode(selector, options = { position: "beforeEnd" }) {
|
|
|
19
44
|
}
|
|
20
45
|
metaList.set(propertyKey, { propertyKey, selector, options });
|
|
21
46
|
const original = descriptor.value;
|
|
22
|
-
descriptor.value =
|
|
47
|
+
descriptor.value = function(...args) {
|
|
23
48
|
ensureInit(this);
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const pos = options.position || "beforeEnd";
|
|
49
|
+
const conf = getElementConfig(this);
|
|
50
|
+
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
51
|
+
const currentDoc = currentWin.document;
|
|
52
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
53
|
+
const getTarget = () => {
|
|
30
54
|
const r = options.root || "auto";
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
if (r === "
|
|
35
|
-
|
|
36
|
-
if (r === "all")
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
const applyRoot = (t) => {
|
|
56
|
+
if (!t) return t;
|
|
57
|
+
if (r === "auto") return t.shadowRoot || t;
|
|
58
|
+
if (r === "shadow") return t.shadowRoot;
|
|
59
|
+
if (r === "light") return t;
|
|
60
|
+
if (r === "all") return t.shadowRoot || t;
|
|
61
|
+
return t;
|
|
62
|
+
};
|
|
63
|
+
if (selector === ":host") return applyRoot(this);
|
|
64
|
+
if (selector === ":parentHost") return applyRoot(hostSet.$parentHost);
|
|
65
|
+
if (selector === ":appHost") return applyRoot(hostSet.$appHost);
|
|
66
|
+
if (selector === ":firstHost") return applyRoot(hostSet.$firstHost);
|
|
67
|
+
if (selector === ":lastHost") return applyRoot(hostSet.$lastHost);
|
|
68
|
+
const targetRoot = applyRoot(this);
|
|
69
|
+
return targetRoot ? targetRoot.querySelector(selector) : null;
|
|
70
|
+
};
|
|
71
|
+
const targetEl = getTarget();
|
|
72
|
+
const res = original.apply(this, args);
|
|
73
|
+
const runApply = (target, val) => {
|
|
74
|
+
const pos = options.position || "beforeEnd";
|
|
75
|
+
const defaultFilter = (t, v) => {
|
|
76
|
+
if (v instanceof Node) return !t.contains(v);
|
|
77
|
+
if (pos === "innerHtml" && typeof v === "string") return t.innerHTML !== v;
|
|
78
|
+
if (pos === "replaceChildren" && v instanceof Node) return !t.contains(v);
|
|
79
|
+
return true;
|
|
39
80
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (r === "shadow" && this.shadowRoot) {
|
|
44
|
-
this.shadowRoot.replaceChildren();
|
|
45
|
-
} else {
|
|
46
|
-
this.remove();
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
const targetRoot = getTargetRoot();
|
|
50
|
-
if (targetRoot) {
|
|
51
|
-
const targets = targetRoot.querySelectorAll(selector);
|
|
52
|
-
targets.forEach((el) => el.remove());
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
let targetEl = null;
|
|
58
|
-
if (selector === ":host" || !selector) {
|
|
59
|
-
if (r === "shadow") {
|
|
60
|
-
targetEl = this.shadowRoot;
|
|
61
|
-
} else {
|
|
62
|
-
targetEl = this;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
const targetRoot = getTargetRoot();
|
|
66
|
-
targetEl = targetRoot ? targetRoot.querySelector(selector) : null;
|
|
67
|
-
}
|
|
68
|
-
if (targetEl) {
|
|
69
|
-
const isShadowRoot = targetEl instanceof ShadowRoot;
|
|
70
|
-
const nodes = normalizeNodes(res, currentDoc);
|
|
71
|
-
if (pos === "replace") {
|
|
72
|
-
if (!isShadowRoot) {
|
|
73
|
-
targetEl.replaceWith(...nodes);
|
|
74
|
-
}
|
|
75
|
-
} else if (pos === "replaceChildren") {
|
|
76
|
-
targetEl.replaceChildren(...nodes);
|
|
77
|
-
} else if (pos === "innerHtml") {
|
|
78
|
-
targetEl.innerHTML = res !== void 0 && res !== null ? String(res) : "";
|
|
79
|
-
} else if (pos === "innerText") {
|
|
80
|
-
if (targetEl.innerText !== void 0) {
|
|
81
|
-
targetEl.innerText = res !== void 0 && res !== null ? String(res) : "";
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
if (pos === "beforeEnd")
|
|
85
|
-
targetEl.append(...nodes);
|
|
86
|
-
else if (pos === "afterBegin")
|
|
87
|
-
targetEl.prepend(...nodes);
|
|
88
|
-
else if (pos === "beforeBegin" && !isShadowRoot)
|
|
89
|
-
targetEl.before(...nodes);
|
|
90
|
-
else if (pos === "afterEnd" && !isShadowRoot)
|
|
91
|
-
targetEl.after(...nodes);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
81
|
+
const activeFilter = options.filter || defaultFilter;
|
|
82
|
+
if (activeFilter(target, val, hostSet)) {
|
|
83
|
+
applyToDom(target, val, pos, currentDoc);
|
|
94
84
|
}
|
|
85
|
+
};
|
|
86
|
+
if (res instanceof Promise) {
|
|
87
|
+
if (targetEl && options.loading) {
|
|
88
|
+
const loadingRes = options.loading.call(this, hostSet);
|
|
89
|
+
applyToDom(targetEl, loadingRes, options.position || "beforeEnd", currentDoc);
|
|
90
|
+
}
|
|
91
|
+
return res.then((finalRes) => {
|
|
92
|
+
if (finalRes !== void 0 && targetEl) runApply(targetEl, finalRes);
|
|
93
|
+
return finalRes;
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
if (res !== void 0 && targetEl) runApply(targetEl, res);
|
|
97
|
+
return res;
|
|
95
98
|
}
|
|
96
|
-
return res;
|
|
97
99
|
};
|
|
98
100
|
};
|
|
99
101
|
}
|
|
@@ -107,49 +109,35 @@ const findAllApplyNodeMetadata = (target) => {
|
|
|
107
109
|
});
|
|
108
110
|
return result;
|
|
109
111
|
};
|
|
110
|
-
function applyNodeHost(
|
|
111
|
-
return applyNode(":host",
|
|
112
|
+
function applyNodeHost(targetOrOptions, propertyKey, descriptor) {
|
|
113
|
+
if (propertyKey !== void 0) return applyNode(":host", { position: "beforeEnd" })(targetOrOptions, propertyKey, descriptor);
|
|
114
|
+
const opt = targetOrOptions || {};
|
|
115
|
+
return applyNode(":host", { position: "beforeEnd", ...opt });
|
|
116
|
+
}
|
|
117
|
+
function applyReplaceChildrenNodeHost(targetOrOptions, propertyKey, descriptor) {
|
|
118
|
+
if (propertyKey !== void 0) return applyNode(":host", { position: "replaceChildren" })(targetOrOptions, propertyKey, descriptor);
|
|
119
|
+
const opt = targetOrOptions || {};
|
|
120
|
+
return applyNode(":host", { position: "replaceChildren", ...opt });
|
|
121
|
+
}
|
|
122
|
+
function applyInnerHtmlNodeHost(targetOrOptions, propertyKey, descriptor) {
|
|
123
|
+
if (propertyKey !== void 0) return applyNode(":host", { position: "innerHtml" })(targetOrOptions, propertyKey, descriptor);
|
|
124
|
+
const opt = targetOrOptions || {};
|
|
125
|
+
return applyNode(":host", { position: "innerHtml", ...opt });
|
|
126
|
+
}
|
|
127
|
+
function applyReplaceChildrenNode(selector, options = {}) {
|
|
128
|
+
return applyNode(selector, { ...options, position: "replaceChildren" });
|
|
129
|
+
}
|
|
130
|
+
function applyInnerHtmlNode(selector, options = {}) {
|
|
131
|
+
return applyNode(selector, { ...options, position: "innerHtml" });
|
|
112
132
|
}
|
|
113
|
-
const applyBeforeBeginNode = (selector, options = {}) => applyNode(selector, { ...options, position: "beforeBegin" });
|
|
114
|
-
const applyAfterBeginNode = (selector, options = {}) => applyNode(selector, { ...options, position: "afterBegin" });
|
|
115
|
-
const applyBeforeEndNode = (selector, options = {}) => applyNode(selector, { ...options, position: "beforeEnd" });
|
|
116
|
-
const applyAfterEndNode = (selector, options = {}) => applyNode(selector, { ...options, position: "afterEnd" });
|
|
117
|
-
const applyReplaceNode = (selector, options = {}) => applyNode(selector, { ...options, position: "replace" });
|
|
118
|
-
const applyReplaceChildrenNode = (selector, options = {}) => applyNode(selector, { ...options, position: "replaceChildren" });
|
|
119
|
-
const applyInnerHtmlNode = (selector, options = {}) => applyNode(selector, { ...options, position: "innerHtml" });
|
|
120
|
-
const applyInnerTextNode = (selector, options = {}) => applyNode(selector, { ...options, position: "innerText" });
|
|
121
|
-
const applyRemoveNode = (selector, options = {}) => applyNode(selector, { ...options, position: "remove" });
|
|
122
|
-
const applyBeforeBeginNodeHost = (options = {}) => applyNode(":host", { ...options, position: "beforeBegin" });
|
|
123
|
-
const applyAfterBeginNodeHost = (options = {}) => applyNode(":host", { ...options, position: "afterBegin" });
|
|
124
|
-
const applyBeforeEndNodeHost = (options = {}) => applyNode(":host", { ...options, position: "beforeEnd" });
|
|
125
|
-
const applyAfterEndNodeHost = (options = {}) => applyNode(":host", { ...options, position: "afterEnd" });
|
|
126
|
-
const applyReplaceNodeHost = (options = {}) => applyNode(":host", { ...options, position: "replace" });
|
|
127
|
-
const applyReplaceChildrenNodeHost = (options = {}) => applyNode(":host", { ...options, position: "replaceChildren" });
|
|
128
|
-
const applyInnerHtmlNodeHost = (options = {}) => applyNode(":host", { ...options, position: "innerHtml" });
|
|
129
|
-
const applyInnerTextNodeHost = (options = {}) => applyNode(":host", { ...options, position: "innerText" });
|
|
130
|
-
const applyRemoveNodeHost = (options = {}) => applyNode(":host", { ...options, position: "remove" });
|
|
131
133
|
export {
|
|
132
134
|
APPLY_NODE_METADATA_KEY,
|
|
133
|
-
applyAfterBeginNode,
|
|
134
|
-
applyAfterBeginNodeHost,
|
|
135
|
-
applyAfterEndNode,
|
|
136
|
-
applyAfterEndNodeHost,
|
|
137
|
-
applyBeforeBeginNode,
|
|
138
|
-
applyBeforeBeginNodeHost,
|
|
139
|
-
applyBeforeEndNode,
|
|
140
|
-
applyBeforeEndNodeHost,
|
|
141
135
|
applyInnerHtmlNode,
|
|
142
136
|
applyInnerHtmlNodeHost,
|
|
143
|
-
applyInnerTextNode,
|
|
144
|
-
applyInnerTextNodeHost,
|
|
145
137
|
applyNode,
|
|
146
138
|
applyNodeHost,
|
|
147
|
-
applyRemoveNode,
|
|
148
|
-
applyRemoveNodeHost,
|
|
149
139
|
applyReplaceChildrenNode,
|
|
150
140
|
applyReplaceChildrenNodeHost,
|
|
151
|
-
applyReplaceNode,
|
|
152
|
-
applyReplaceNodeHost,
|
|
153
141
|
findAllApplyNodeMetadata
|
|
154
142
|
};
|
|
155
143
|
//# sourceMappingURL=applyNode.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyNode.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcRootType } from '../types';\n\nexport type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';\n\nexport interface ApplyNodeOptions {\n position?: ApplyNodePosition;\n root?: SwcRootType;\n}\n\nexport interface ApplyNodeMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: ApplyNodeOptions;\n}\n\nexport const APPLY_NODE_METADATA_KEY = Symbol('simple-web-component:apply-node');\n\nconst normalizeNodes = (res: any, doc: Document): Node[] => {\n const items = Array.isArray(res) ? res : [res];\n return items.map(it => {\n if (it instanceof Node) return it;\n return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n });\n};\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n * \n * Usage examples:\n * @applyNode('#list') addItem() { return '<li>New Item</li>'; } // append at end\n * @applyNode('#header', { position: 'afterBegin' }) prependItem() { return '<h1>Title</h1>'; } // prepend at start\n * @applyNode('#item', { position: 'replace' }) replaceItem() { return '<div>Replaced</div>'; } // replace element\n * @applyNode('#list', { position: 'replaceChildren' }) updateList() { return [item1, item2]; } // replace all children\n * @applyNode('#notification', { position: 'remove' }) dismissNotification() { return shouldDismiss; } // remove if truthy\n * @applyNode('.items', { position: 'remove', root: 'shadow' }) clearItems() { return true; } // remove shadow DOM elements\n * \n * Positions:\n * - 'beforeEnd' (default): Append at end of target\n * - 'afterBegin': Prepend at start of target\n * - 'beforeBegin': Insert before target\n * - 'afterEnd': Insert after target\n * - 'replace': Replace the entire target element\n * - 'replaceChildren': Replace all children of target element\n * - 'innerHtml': Set target's innerHTML\n * - 'innerText': Set target's innerText\n * - 'remove': Remove target element if returned value is truthy\n * \n * Root Options:\n * - 'auto' (default): Search shadow DOM first, then light DOM\n * - 'shadow': Search only in shadow DOM\n * - 'light': Search only in light DOM\n * - 'all': Use both (shadow preferred for query, both for remove)\n */\nexport function applyNode(selector: string, options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ApplyNodeMetadata>();\n ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, 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 conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n const currentDoc = currentWin.document;\n\n const pos = options.position || 'beforeEnd';\n const r = options.root || 'auto';\n\n const getTargetRoot = () => {\n if (r === 'shadow') return this.shadowRoot;\n if (r === 'light') return this as any;\n if (r === 'all') return this.shadowRoot || (this as any);\n return this.shadowRoot || (this as any); // auto\n };\n\n if (pos === 'remove') {\n // Remove element(s) if returned value is truthy\n if (res) {\n if (selector === ':host' || !selector) {\n if (r === 'shadow' && this.shadowRoot) {\n // Remove all children from shadow DOM\n this.shadowRoot.replaceChildren();\n } else {\n // Remove the component itself\n (this as any).remove();\n }\n } else {\n const targetRoot = getTargetRoot();\n if (targetRoot) {\n const targets = targetRoot.querySelectorAll(selector);\n targets.forEach((el: Element) => el.remove());\n }\n }\n }\n } else {\n let targetEl: any = null;\n if (selector === ':host' || !selector) {\n if (r === 'shadow') {\n targetEl = this.shadowRoot; // Target shadow DOM root\n } else {\n targetEl = this as any; // Target the component itself\n }\n } else {\n const targetRoot = getTargetRoot();\n targetEl = targetRoot ? targetRoot.querySelector(selector) : null;\n }\n\n if (targetEl) {\n const isShadowRoot = targetEl instanceof ShadowRoot;\n const nodes = normalizeNodes(res, currentDoc);\n\n if (pos === 'replace') {\n // ShadowRoot doesn't support replaceWith\n if (!isShadowRoot) {\n targetEl.replaceWith(...nodes);\n }\n } else if (pos === 'replaceChildren') {\n // Replace all children of target element\n targetEl.replaceChildren(...nodes);\n } else if (pos === 'innerHtml') {\n // Set innerHTML\n targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n } else if (pos === 'innerText') {\n // Set innerText\n if (targetEl.innerText !== undefined) {\n targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n }\n } else {\n /*\n <!-- beforebegin -->\n <p>\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n </p>\n <!-- afterend -->\n */\n if (pos === 'beforeEnd') targetEl.append(...nodes);\n else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n }\n }\n }\n }\n return res;\n };\n };\n}\n\nexport const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {\n const result = new Map<string | symbol, ApplyNodeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_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\n/**\n * @applyNodeHost decorator - simplified version of @applyNode for :host selector\n * Usage: @applyNodeHost() addItem() { return '<li>New Item</li>'; }\n * Usage: @applyNodeHost({ position: 'afterBegin' }) prependItem() { return '<h1>Title</h1>'; }\n */\nexport function applyNodeHost(options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {\n return applyNode(':host', options);\n}\n\n// Convenience decorators for specific positions\n\n/**\n * @applyBeforeBeginNode - Insert before target element\n */\nexport const applyBeforeBeginNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'beforeBegin' });\n\n/**\n * @applyAfterBeginNode - Prepend to target element\n */\nexport const applyAfterBeginNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'afterBegin' });\n\n/**\n * @applyBeforeEndNode - Append to target element (default)\n */\nexport const applyBeforeEndNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'beforeEnd' });\n\n/**\n * @applyAfterEndNode - Insert after target element\n */\nexport const applyAfterEndNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'afterEnd' });\n\n/**\n * @applyReplaceNode - Replace entire target element\n */\nexport const applyReplaceNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'replace' });\n\n/**\n * @applyReplaceChildrenNode - Replace all children of target element\n */\nexport const applyReplaceChildrenNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'replaceChildren' });\n\n/**\n * @applyInnerHtmlNode - Set target's innerHTML\n */\nexport const applyInnerHtmlNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'innerHtml' });\n\n/**\n * @applyInnerTextNode - Set target's innerText\n */\nexport const applyInnerTextNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'innerText' });\n\n/**\n * @applyRemoveNode - Remove target element if truthy\n */\nexport const applyRemoveNode = (selector: string, options: ApplyNodeOptions = {}) => \n applyNode(selector, { ...options, position: 'remove' });\n\n// Host versions\n\n/**\n * @applyBeforeBeginNodeHost - Insert before :host\n */\nexport const applyBeforeBeginNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'beforeBegin' });\n\n/**\n * @applyAfterBeginNodeHost - Prepend to :host\n */\nexport const applyAfterBeginNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'afterBegin' });\n\n/**\n * @applyBeforeEndNodeHost - Append to :host\n */\nexport const applyBeforeEndNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'beforeEnd' });\n\n/**\n * @applyAfterEndNodeHost - Insert after :host\n */\nexport const applyAfterEndNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'afterEnd' });\n\n/**\n * @applyReplaceNodeHost - Replace :host\n */\nexport const applyReplaceNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'replace' });\n\n/**\n * @applyReplaceChildrenNodeHost - Replace children of :host\n */\nexport const applyReplaceChildrenNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'replaceChildren' });\n\n/**\n * @applyInnerHtmlNodeHost - Set :host innerHTML\n */\nexport const applyInnerHtmlNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'innerHtml' });\n\n/**\n * @applyInnerTextNodeHost - Set :host innerText\n */\nexport const applyInnerTextNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'innerText' });\n\n/**\n * @applyRemoveNodeHost - Remove :host if truthy\n */\nexport const applyRemoveNodeHost = (options: ApplyNodeOptions = {}) => \n applyNode(':host', { ...options, position: 'remove' });\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,wBAAwB;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { HelperHostSet, SwcRootType } from '../types';\nimport { SwcUtils } from \"../utils/Utils\";\n\nexport type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';\n\nexport interface ApplyNodeOptions {\n position?: ApplyNodePosition;\n root?: SwcRootType;\n /**\n * Filter function to determine whether to perform DOM operation.\n * If it returns false, the operation is skipped.\n */\n filter?: (target: HTMLElement | ShadowRoot, newValue: any, helper: HelperHostSet) => boolean;\n /**\n * Optional loading content to display while an async method is executing.\n */\n loading?: (helper: HelperHostSet) => any;\n}\n\nexport interface ApplyNodeMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: ApplyNodeOptions;\n}\n\nexport const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');\n\nconst normalizeNodes = (res: any, doc: Document): Node[] => {\n const items = Array.isArray(res) ? res : [res];\n return items.map(it => {\n if (it instanceof Node) return it;\n return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n });\n};\n\nconst applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, doc: Document) => {\n if (!targetEl) return;\n \n if (pos === 'innerHtml') {\n targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n return;\n }\n \n if (pos === 'innerText') {\n if (targetEl.innerText !== undefined) {\n targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n }\n return;\n }\n\n const isShadowRoot = targetEl instanceof ShadowRoot;\n const nodes = normalizeNodes(res, doc);\n if (pos === 'replace') {\n if (!isShadowRoot) targetEl.replaceWith(...nodes);\n } else if (pos === 'replaceChildren') {\n targetEl.replaceChildren(...nodes);\n } else {\n if (pos === 'beforeEnd') targetEl.append(...nodes);\n else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n }\n};\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applyNode(selector: string, options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ApplyNodeMetadata>();\n ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, options });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n \n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n \n const getTarget = () => {\n const r = options.root || 'auto';\n const applyRoot = (t: any) => {\n if (!t) return t;\n if (r === 'auto') return t.shadowRoot || t;\n if (r === 'shadow') return t.shadowRoot;\n if (r === 'light') return t;\n if (r === 'all') return t.shadowRoot || t;\n return t;\n };\n\n if (selector === ':host') return applyRoot(this);\n if (selector === ':parentHost') return applyRoot(hostSet.$parentHost);\n if (selector === ':appHost') return applyRoot(hostSet.$appHost);\n if (selector === ':firstHost') return applyRoot(hostSet.$firstHost);\n if (selector === ':lastHost') return applyRoot(hostSet.$lastHost);\n \n const targetRoot = applyRoot(this);\n return targetRoot ? targetRoot.querySelector(selector) : null;\n };\n\n const targetEl = getTarget();\n const res = original.apply(this, args);\n\n const runApply = (target: any, val: any) => {\n const pos = options.position || 'beforeEnd';\n \n // Intelligent Default Filter\n const defaultFilter = (t: any, v: any) => {\n if (v instanceof Node) return !t.contains(v);\n if (pos === 'innerHtml' && typeof v === 'string') return t.innerHTML !== v;\n if (pos === 'replaceChildren' && v instanceof Node) return !t.contains(v);\n return true;\n };\n \n const activeFilter = options.filter || defaultFilter;\n \n if (activeFilter(target, val, hostSet)) {\n applyToDom(target, val, pos, currentDoc);\n }\n };\n\n if (res instanceof Promise) {\n // \uBE44\uB3D9\uAE30\uC77C \uB54C\uB9CC \uB85C\uB529 \uD45C\uC2DC\n if (targetEl && options.loading) {\n const loadingRes = options.loading.call(this, hostSet);\n applyToDom(targetEl, loadingRes, options.position || 'beforeEnd', currentDoc);\n }\n\n return res.then(finalRes => {\n if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);\n return finalRes;\n });\n } else {\n if (res !== undefined && targetEl) runApply(targetEl, res);\n return res;\n }\n };\n };\n}\n\nexport const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {\n const result = new Map<string | symbol, ApplyNodeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_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\nexport function applyNodeHost(options: ApplyNodeOptions): MethodDecorator;\nexport function applyNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) return applyNode(':host', { position: 'beforeEnd' })(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode(':host', { position: 'beforeEnd', ...opt });\n}\n\nexport function applyReplaceChildrenNodeHost(options: ApplyNodeOptions): MethodDecorator;\nexport function applyReplaceChildrenNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyReplaceChildrenNodeHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) return applyNode(':host', { position: 'replaceChildren' })(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode(':host', { position: 'replaceChildren', ...opt });\n}\n\nexport function applyInnerHtmlNodeHost(options: ApplyNodeOptions): MethodDecorator;\nexport function applyInnerHtmlNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyInnerHtmlNodeHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) return applyNode(':host', { position: 'innerHtml' })(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode(':host', { position: 'innerHtml', ...opt });\n}\n\nexport function applyReplaceChildrenNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {\n return applyNode(selector, { ...options, position: 'replaceChildren' });\n}\n\nexport function applyInnerHtmlNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {\n return applyNode(selector, { ...options, position: 'innerHtml' });\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,wBAAwB;AAE7C,SAAS,gBAAgB;AAwBlB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;AAEnF,MAAM,iBAAiB,CAAC,KAAU,QAA0B;AAC1D,QAAM,QAAQ,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AAC7C,SAAO,MAAM,IAAI,QAAM;AACrB,QAAI,cAAc,KAAM,QAAO;AAC/B,WAAO,IAAI,eAAe,OAAO,UAAa,OAAO,OAAO,OAAO,EAAE,IAAI,EAAE;AAAA,EAC7E,CAAC;AACH;AAEA,MAAM,aAAa,CAAC,UAAe,KAAU,KAAwB,QAAkB;AACnF,MAAI,CAAC,SAAU;AAEf,MAAI,QAAQ,aAAa;AACrB,aAAS,YAAY,QAAQ,UAAa,QAAQ,OAAO,OAAO,G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C,SAAO,UAAU,SAAS,EAAE,UAAU,aAAa,GAAG,IAAI,CAAC;AAC7D;AAEO,SAAS,yBAAyB,UAAkB,UAA4B,CAAC,GAAoB;AACxG,SAAO,UAAU,UAAU,EAAE,GAAG,SAAS,UAAU,kBAAkB,CAAC;AAC1E;AAEO,SAAS,mBAAmB,UAAkB,UAA4B,CAAC,GAAoB;AAClG,SAAO,UAAU,UAAU,EAAE,GAAG,SAAS,UAAU,YAAY,CAAC;AACpE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ReflectUtils } from "@dooboostore/core";
|
|
2
|
+
import { ensureInit } from "./elementDefine.js";
|
|
3
|
+
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
+
const STYLE_METADATA_KEY = Symbol.for("simple-web-component:style");
|
|
5
|
+
function createStyleDecorator(action) {
|
|
6
|
+
return (selector, options = {}) => {
|
|
7
|
+
return (target, propertyKey, descriptor) => {
|
|
8
|
+
const constructor = target.constructor;
|
|
9
|
+
let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor);
|
|
10
|
+
if (!metaList) {
|
|
11
|
+
metaList = /* @__PURE__ */ new Map();
|
|
12
|
+
ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);
|
|
13
|
+
}
|
|
14
|
+
metaList.set(propertyKey, { propertyKey, selector, action, options });
|
|
15
|
+
const original = descriptor.value;
|
|
16
|
+
descriptor.value = async function(...args) {
|
|
17
|
+
ensureInit(this);
|
|
18
|
+
const res = await original.apply(this, args);
|
|
19
|
+
if (res !== void 0) {
|
|
20
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
21
|
+
const host = this;
|
|
22
|
+
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
23
|
+
const r = options.root || "auto";
|
|
24
|
+
const targetEls = [];
|
|
25
|
+
const applyRoot = (t) => {
|
|
26
|
+
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
27
|
+
targetEls.push(t);
|
|
28
|
+
};
|
|
29
|
+
if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
30
|
+
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
31
|
+
else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
|
|
32
|
+
else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
|
|
33
|
+
else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
34
|
+
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
35
|
+
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
36
|
+
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
37
|
+
else if (selector === ":host" || !selector) applyRoot(host);
|
|
38
|
+
else {
|
|
39
|
+
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
40
|
+
if (targetRoot) {
|
|
41
|
+
const found = targetRoot.querySelectorAll(selector);
|
|
42
|
+
if (found) targetEls.push(...Array.from(found));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
targetEls.forEach((targetEl) => {
|
|
46
|
+
const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
|
|
47
|
+
if (action === "set" || action === "update") {
|
|
48
|
+
if (action === "set") targetEl.style.cssText = "";
|
|
49
|
+
if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
50
|
+
Object.entries(resolvedRes).forEach(([prop, val]) => {
|
|
51
|
+
const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
|
|
52
|
+
if (finalVal === null || finalVal === void 0) {
|
|
53
|
+
targetEl.style.removeProperty(prop);
|
|
54
|
+
} else {
|
|
55
|
+
targetEl.style[prop] = String(finalVal);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} else if (typeof resolvedRes === "string") {
|
|
59
|
+
targetEl.style.cssText = resolvedRes;
|
|
60
|
+
}
|
|
61
|
+
} else if (action === "remove") {
|
|
62
|
+
if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
63
|
+
Object.entries(resolvedRes).forEach(([prop, val]) => {
|
|
64
|
+
const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
|
|
65
|
+
if (shouldRemove) {
|
|
66
|
+
targetEl.style.removeProperty(prop);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
|
|
71
|
+
props.forEach((p) => targetEl.style.removeProperty(String(p)));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return res;
|
|
77
|
+
};
|
|
78
|
+
return descriptor;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function applyStyle(selector, action = "update", options = {}) {
|
|
83
|
+
return createStyleDecorator(action)(selector, options);
|
|
84
|
+
}
|
|
85
|
+
const setStyle = (selector, options = {}) => createStyleDecorator("set")(selector, options);
|
|
86
|
+
const updateStyle = (selector, options = {}) => createStyleDecorator("update")(selector, options);
|
|
87
|
+
const removeStyle = (selector, options = {}) => createStyleDecorator("remove")(selector, options);
|
|
88
|
+
function applyStyleHost(action = "update", options = {}) {
|
|
89
|
+
return createStyleDecorator(action)(":host", options);
|
|
90
|
+
}
|
|
91
|
+
const setStyleHost = (options = {}) => createStyleDecorator("set")(":host", options);
|
|
92
|
+
const updateStyleHost = (options = {}) => createStyleDecorator("update")(":host", options);
|
|
93
|
+
const removeStyleHost = (options = {}) => createStyleDecorator("remove")(":host", options);
|
|
94
|
+
const findAllStyleMetadata = (target) => {
|
|
95
|
+
const result = /* @__PURE__ */ new Map();
|
|
96
|
+
const maps = ReflectUtils.findAllMetadata(STYLE_METADATA_KEY, target);
|
|
97
|
+
maps.forEach((map) => {
|
|
98
|
+
if (map instanceof Map) {
|
|
99
|
+
map.forEach((v, k) => result.set(k, v));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
STYLE_METADATA_KEY,
|
|
106
|
+
applyStyle,
|
|
107
|
+
applyStyleHost,
|
|
108
|
+
findAllStyleMetadata,
|
|
109
|
+
removeStyle,
|
|
110
|
+
removeStyleHost,
|
|
111
|
+
setStyle,
|
|
112
|
+
setStyleHost,
|
|
113
|
+
updateStyle,
|
|
114
|
+
updateStyleHost
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=applyStyle.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/applyStyle.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\nexport interface StyleApplyOptions extends SwcQueryOptions {}\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: string, options: StyleApplyOptions = {}): 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, StyleApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleApplyMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await (original as any).apply(this, args);\n if (res !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = options.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n 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(host);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;\n\n if (action === 'set' || action === 'update') {\n if (action === 'set') targetEl.style.cssText = '';\n \n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined) {\n targetEl.style.removeProperty(prop);\n } else {\n targetEl.style[prop as any] = String(finalVal);\n }\n });\n } else if (typeof resolvedRes === 'string') {\n targetEl.style.cssText = resolvedRes;\n }\n } else if (action === 'remove') {\n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) {\n targetEl.style.removeProperty(prop);\n }\n });\n } else {\n const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n props.forEach(p => targetEl.style.removeProperty(String(p)));\n }\n }\n });\n }\n return res;\n };\n return descriptor;\n };\n };\n}\n\nexport function applyStyle(selector: string, action: StyleAction = 'update', options: StyleApplyOptions = {}): MethodDecorator {\n return createStyleDecorator(action)(selector, options);\n}\n\nexport const setStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('set')(selector, options);\nexport const updateStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('update')(selector, options);\nexport const removeStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('remove')(selector, options);\n\n// Host versions\nexport function applyStyleHost(action: StyleAction = 'update', options: StyleApplyOptions = {}): MethodDecorator {\n return createStyleDecorator(action)(':host', options);\n}\nexport const setStyleHost = (options: StyleApplyOptions = {}) => createStyleDecorator('set')(':host', options);\nexport const updateStyleHost = (options: StyleApplyOptions = {}) => createStyleDecorator('update')(':host', options);\nexport const removeStyleHost = (options: StyleApplyOptions = {}) => createStyleDecorator('remove')(':host', options);\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {\n const result = new Map<string | symbol, StyleApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(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,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAclB,MAAM,qBAAqB,OAAO,IAAI,4BAA4B;AAEzE,SAAS,qBAAqB,QAAqB;AACjD,SAAO,CAAC,UAAkB,UAA6B,CAAC,MAAuB;AAC7E,WAAO,CAAC,QAAgB,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
2
|
import { getElementConfig } from "./elementDefine.js";
|
|
3
3
|
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
-
const
|
|
4
|
+
const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for("simple-web-component:attribute-field");
|
|
5
5
|
const convertValue = (val, type) => {
|
|
6
6
|
if (val === null || val === void 0) return val;
|
|
7
7
|
if (type === Number) return Number(val);
|
|
@@ -59,15 +59,14 @@ function attribute(selector, options = {}) {
|
|
|
59
59
|
const constructor = target.constructor;
|
|
60
60
|
const privateKey = Symbol(String(propertyKey));
|
|
61
61
|
const designType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
62
|
-
let metaList = ReflectUtils.getOwnMetadata(
|
|
62
|
+
let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor);
|
|
63
63
|
if (!metaList) {
|
|
64
64
|
metaList = [];
|
|
65
|
-
ReflectUtils.defineMetadata(
|
|
65
|
+
ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);
|
|
66
66
|
}
|
|
67
67
|
metaList.push({ propertyKey, selector, options, privateKey });
|
|
68
68
|
const applySetAttribute = (inst, targets, attrName, nv) => {
|
|
69
69
|
targets.forEach((it) => {
|
|
70
|
-
console.log("----->", it);
|
|
71
70
|
if (it && typeof it.setAttribute === "function") {
|
|
72
71
|
if (nv === null) {
|
|
73
72
|
it.removeAttribute(attrName);
|
|
@@ -85,7 +84,6 @@ function attribute(selector, options = {}) {
|
|
|
85
84
|
const conf = getElementConfig(this);
|
|
86
85
|
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
87
86
|
const targetType = options.type || designType;
|
|
88
|
-
console.log("type-->", propertyKey, targetType);
|
|
89
87
|
if (this.__swc_syncing_init || options.connectedInitialize && !this.__swc_connected) {
|
|
90
88
|
return convertValue(this[privateKey], targetType);
|
|
91
89
|
}
|
|
@@ -101,7 +99,6 @@ function attribute(selector, options = {}) {
|
|
|
101
99
|
return convertValue(this[privateKey], targetType);
|
|
102
100
|
},
|
|
103
101
|
set(nv) {
|
|
104
|
-
const targetType = options.type || designType;
|
|
105
102
|
const attrName = options.name || String(propertyKey);
|
|
106
103
|
const conf = getElementConfig(this);
|
|
107
104
|
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
@@ -126,14 +123,30 @@ function attribute(selector, options = {}) {
|
|
|
126
123
|
});
|
|
127
124
|
};
|
|
128
125
|
}
|
|
126
|
+
function attributeHost(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
127
|
+
if (propertyKeyOrOptions !== void 0 && (typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol")) {
|
|
128
|
+
return attribute(":host", { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
129
|
+
}
|
|
130
|
+
if (typeof targetOrAttrOrOptions === "string") {
|
|
131
|
+
const attrName = targetOrAttrOrOptions;
|
|
132
|
+
const options = typeof propertyKeyOrOptions === "object" ? propertyKeyOrOptions : {};
|
|
133
|
+
return attribute(":host", { ...options, name: attrName });
|
|
134
|
+
} else if (typeof targetOrAttrOrOptions === "object") {
|
|
135
|
+
const options = targetOrAttrOrOptions;
|
|
136
|
+
return (target, propertyKey) => {
|
|
137
|
+
return attribute(":host", { ...options, name: String(propertyKey) })(target, propertyKey);
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
return (target, propertyKey) => {
|
|
141
|
+
return attribute(":host", { name: String(propertyKey) })(target, propertyKey);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
129
145
|
const findAllAttributeMetadata = (target) => {
|
|
130
|
-
return ReflectUtils.findAllMetadata(
|
|
146
|
+
return ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, target).flat();
|
|
131
147
|
};
|
|
132
|
-
function attributeHost(attrName, options = {}) {
|
|
133
|
-
return attribute(":host", { ...options, name: attrName });
|
|
134
|
-
}
|
|
135
148
|
export {
|
|
136
|
-
|
|
149
|
+
ATTRIBUTE_FIELD_METADATA_KEY,
|
|
137
150
|
attribute,
|
|
138
151
|
attributeHost,
|
|
139
152
|
findAllAttributeMetadata,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/attribute.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport {SpecialSelector, SwcQueryOptions} from '../types';\n\nexport interface AttributeFieldOptions extends SwcQueryOptions {\n name?: string;\n connectedInitialize?: boolean;\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface AttributeFieldMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: AttributeFieldOptions;\n privateKey: symbol;\n}\n\nexport const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for('simple-web-component:attribute-field');\n\nconst convertValue = (val: string | null, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\nexport const resolveTargetEls = (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any): HTMLElement[] => {\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (selector === ':host' || !selector) {\n applyRoot(inst);\n } else if (selector === ':window') {\n results.push(currentWin);\n } else if (selector === ':document') {\n results.push(currentWin.document);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (selector === ':parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === ':appHost') applyRoot(hostSet.$appHost as any);\n else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(selector);\n const lMatch = inst.querySelectorAll(selector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(selector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @attribute decorator to sync a field value with an element's attribute.\n */\nexport function attribute(selector: string, options: AttributeFieldOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n const privateKey = Symbol(String(propertyKey));\n\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor) as AttributeFieldMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);\n }\n metaList.push({propertyKey, selector, options, privateKey});\n\n const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {\n targets.forEach(it => {\n if (it && typeof (it as any).setAttribute === 'function') {\n if (nv === null) {\n (it as any).removeAttribute(attrName);\n } else {\n (it as any).setAttribute(attrName, String(nv));\n }\n } else {\n inst[privateKey] = nv;\n }\n });\n };\n\n Object.defineProperty(target, propertyKey, {\n get(this: any) {\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n const targetType = options.type || designType;\n\n if (this.__swc_syncing_init || (options.connectedInitialize && !this.__swc_connected)) {\n return convertValue(this[privateKey], targetType);\n }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function') {\n if ((primaryTarget as any).hasAttribute(attrName)) {\n const domVal = (primaryTarget as any).getAttribute(attrName);\n return convertValue(domVal, targetType);\n }\n return null;\n }\n\n return convertValue(this[privateKey], targetType);\n },\n set(this: any, nv: any) {\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n if (this.__swc_syncing_init) {\n if (options.connectedInitialize === true) {\n const targets = resolveTargetEls(this, selector, options, currentWin);\n applySetAttribute(this, targets, attrName, nv);\n } else {\n this[privateKey] = nv;\n }\n return;\n }\n\n if (!this.__swc_connected) {\n this[privateKey] = nv;\n return;\n }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n applySetAttribute(this, targets, attrName, nv);\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\n/**\n * @attributeHost decorator to sync a field value with the :host element's attribute.\n */\nexport function attributeHost(target: Object, propertyKey: string | symbol): void;\nexport function attributeHost(options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeHost(attrName: string): PropertyDecorator;\nexport function attributeHost(attrName: string, options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeHost(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {\n if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n return attribute(':host', { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);\n }\n\n if (typeof targetOrAttrOrOptions === 'string') {\n const attrName = targetOrAttrOrOptions;\n const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeFieldOptions;\n return attribute(':host', { ...options, name: attrName });\n } else if (typeof targetOrAttrOrOptions === 'object') {\n const options = targetOrAttrOrOptions as AttributeFieldOptions;\n return (target: Object, propertyKey: string | symbol) => {\n return attribute(':host', { ...options, name: String(propertyKey) })(target, propertyKey);\n };\n } else {\n return (target: Object, propertyKey: string | symbol) => {\n return attribute(':host', { name: String(propertyKey) })(target, propertyKey);\n };\n }\n}\n\nexport const findAllAttributeMetadata = (target: any): AttributeFieldMetadata[] => {\n return ReflectUtils.findAllMetadata<AttributeFieldMetadata[]>(ATTRIBUTE_FIELD_METADATA_KEY, target).flat();\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,oBAAmB;AAC3B,SAAoB,wBAAuB;AAC3C,SAAQ,gBAAe;AAgBhB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,MAAM,eAAe,CAAC,KAAoB,SAAmB;AAC3D,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAEO,MAAM,mBAAmB,CAAC,MAAW,UAAkB,SAAgC,eAAmC;AAC/H,QAAM,IAAI,QAAQ,QAAQ;AAC1B,QAAM,UAAyB,CAAC;AAEhC,QAAM,YAAY,CAAC,WAAgB;AACjC,QAAI,CAAC,OAAQ;AACb,QAAI,MAAM,QAAQ;AAChB,cAAQ,KAAK,MAAM;AAAA,IACrB,OAAO;AACL,UAAI,MAAM,WAAW,MAAM,MAAO,SAAQ,KAAK,MAAM;AACrD,WAAK,MAAM,YAAY,MAAM,UAAU,OAAO,WAAY,SAAQ,KAAK,OAAO,UAAU;AAAA,IAC1F;AAAA,EACF;AAEA,MAAI,aAAa,WAAW,CAAC,UAAU;AACrC,cAAU,IAAI;AAAA,EAChB,WAAW,aAAa,WAAW;AACjC,YAAQ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E,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC9E;AAAA,EACF;AACF;AAEO,MAAM,2BAA2B,CAAC,WAA0C;AACjF,SAAO,aAAa,gBAA0C,8BAA8B,MAAM,EAAE,KAAK;AAC3G;",
|
|
6
6
|
"names": ["targets"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReflectUtils } from "@dooboostore/core";
|
|
2
|
-
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:on-attribute-changed");
|
|
2
|
+
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for("simple-web-component:on-attribute-changed");
|
|
3
3
|
function changedAttributeHost(attributeName) {
|
|
4
4
|
return (target, propertyKey) => {
|
|
5
5
|
const constructor = target.constructor;
|