@dooboostore/simple-web-component 1.0.24 → 1.0.26
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 +162 -33
- 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 +87 -194
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/{style.js → applyStyle.js} +50 -60
- package/dist/cjs/decorators/applyStyle.js.map +7 -0
- package/dist/cjs/decorators/attribute.js +10 -16
- 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 +1 -1
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +1 -1
- 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/utils/Utils.js +1 -1
- 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 +87 -194
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/{style.js → applyStyle.js} +47 -57
- package/dist/esm/decorators/applyStyle.js.map +7 -0
- package/dist/esm/decorators/attribute.js +10 -16
- 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 +1 -1
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +1 -1
- 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/utils/Utils.js +1 -1
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2853 -574
- 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 +15 -123
- 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 +10 -19
- 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.map +1 -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/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2853 -574
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +2 -2
- 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 +112 -330
- package/src/decorators/applyStyle.ts +128 -0
- package/src/decorators/attribute.ts +21 -55
- package/src/decorators/changedAttributeHost.ts +1 -1
- 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 +1 -1
- package/src/decorators/queryAll.ts +1 -1
- package/src/elements/SwcAppEngine.ts +32 -4
- package/src/elements/SwcAppMixin.ts +2 -0
- package/src/utils/Utils.ts +2 -1
- package/dist/cjs/decorators/classList.js +0 -177
- 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.map +0 -7
- package/dist/esm/decorators/classList.js +0 -158
- 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.map +0 -7
- package/dist/types/decorators/classList.d.ts +0 -71
- 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 -58
- package/dist/types/decorators/style.d.ts.map +0 -1
- package/src/decorators/classList.ts +0 -234
- package/src/decorators/setAttribute.ts +0 -114
- package/src/decorators/style.ts +0 -185
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from "@dooboostore/core";
|
|
2
2
|
import { ensureInit } from "./elementDefine.js";
|
|
3
3
|
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
-
const STYLE_METADATA_KEY = Symbol("simple-web-component:style");
|
|
4
|
+
const STYLE_METADATA_KEY = Symbol.for("simple-web-component:style");
|
|
5
5
|
function createStyleDecorator(action) {
|
|
6
6
|
return (selector, options = {}) => {
|
|
7
7
|
return (target, propertyKey, descriptor) => {
|
|
@@ -17,18 +17,14 @@ function createStyleDecorator(action) {
|
|
|
17
17
|
ensureInit(this);
|
|
18
18
|
const res = await original.apply(this, args);
|
|
19
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 };
|
|
20
23
|
const r = options.root || "auto";
|
|
21
|
-
const hostSet = SwcUtils.getHostSet(this);
|
|
22
24
|
const targetEls = [];
|
|
23
25
|
const applyRoot = (t) => {
|
|
24
|
-
if (!t || !(t instanceof HTMLElement)) return;
|
|
25
|
-
|
|
26
|
-
targetEls.push(t);
|
|
27
|
-
} else {
|
|
28
|
-
if (r === "light" || r === "all") targetEls.push(t);
|
|
29
|
-
if ((r === "shadow" || r === "all") && t.shadowRoot) {
|
|
30
|
-
}
|
|
31
|
-
}
|
|
26
|
+
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
27
|
+
targetEls.push(t);
|
|
32
28
|
};
|
|
33
29
|
if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
34
30
|
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
@@ -38,71 +34,63 @@ function createStyleDecorator(action) {
|
|
|
38
34
|
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
39
35
|
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
40
36
|
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
41
|
-
else if (selector === ":host" || !selector) applyRoot(
|
|
37
|
+
else if (selector === ":host" || !selector) applyRoot(host);
|
|
42
38
|
else {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} else if (r === "light") {
|
|
47
|
-
const found = this.querySelectorAll(selector);
|
|
48
|
-
if (found) targetEls.push(...Array.from(found));
|
|
49
|
-
} else if (r === "all") {
|
|
50
|
-
const sFound = this.shadowRoot?.querySelectorAll(selector);
|
|
51
|
-
const lFound = this.querySelectorAll(selector);
|
|
52
|
-
if (sFound) targetEls.push(...Array.from(sFound));
|
|
53
|
-
if (lFound) targetEls.push(...Array.from(lFound));
|
|
54
|
-
} else {
|
|
55
|
-
const found = (this.shadowRoot || this).querySelectorAll(selector);
|
|
39
|
+
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
40
|
+
if (targetRoot) {
|
|
41
|
+
const found = targetRoot.querySelectorAll(selector);
|
|
56
42
|
if (found) targetEls.push(...Array.from(found));
|
|
57
43
|
}
|
|
58
44
|
}
|
|
59
45
|
targetEls.forEach((targetEl) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
70
60
|
}
|
|
71
61
|
} else if (action === "remove") {
|
|
72
|
-
|
|
73
|
-
|
|
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
|
+
}
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
return res;
|
|
78
77
|
};
|
|
78
|
+
return descriptor;
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (propertyKey !== void 0) {
|
|
85
|
-
const decorator = createStyleDecorator("set")(":host", {});
|
|
86
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
87
|
-
}
|
|
88
|
-
return createStyleDecorator("set")(":host", targetOrOptions || {});
|
|
82
|
+
function applyStyle(selector, action = "update", options = {}) {
|
|
83
|
+
return createStyleDecorator(action)(selector, options);
|
|
89
84
|
}
|
|
85
|
+
const setStyle = (selector, options = {}) => createStyleDecorator("set")(selector, options);
|
|
90
86
|
const updateStyle = (selector, options = {}) => createStyleDecorator("update")(selector, options);
|
|
91
|
-
function updateStyleHost(targetOrOptions, propertyKey, descriptor) {
|
|
92
|
-
if (propertyKey !== void 0) {
|
|
93
|
-
const decorator = createStyleDecorator("update")(":host", {});
|
|
94
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
95
|
-
}
|
|
96
|
-
return createStyleDecorator("update")(":host", targetOrOptions || {});
|
|
97
|
-
}
|
|
98
87
|
const removeStyle = (selector, options = {}) => createStyleDecorator("remove")(selector, options);
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
const decorator = createStyleDecorator("remove")(":host", {});
|
|
102
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
103
|
-
}
|
|
104
|
-
return createStyleDecorator("remove")(":host", targetOrOptions || {});
|
|
88
|
+
function applyStyleHost(action = "update", options = {}) {
|
|
89
|
+
return createStyleDecorator(action)(":host", options);
|
|
105
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);
|
|
106
94
|
const findAllStyleMetadata = (target) => {
|
|
107
95
|
const result = /* @__PURE__ */ new Map();
|
|
108
96
|
const maps = ReflectUtils.findAllMetadata(STYLE_METADATA_KEY, target);
|
|
@@ -115,6 +103,8 @@ const findAllStyleMetadata = (target) => {
|
|
|
115
103
|
};
|
|
116
104
|
export {
|
|
117
105
|
STYLE_METADATA_KEY,
|
|
106
|
+
applyStyle,
|
|
107
|
+
applyStyleHost,
|
|
118
108
|
findAllStyleMetadata,
|
|
119
109
|
removeStyle,
|
|
120
110
|
removeStyleHost,
|
|
@@ -123,4 +113,4 @@ export {
|
|
|
123
113
|
updateStyle,
|
|
124
114
|
updateStyleHost
|
|
125
115
|
};
|
|
126
|
-
//# sourceMappingURL=
|
|
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,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,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from "@dooboostore/core";
|
|
2
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,13 +123,9 @@ function attribute(selector, options = {}) {
|
|
|
126
123
|
});
|
|
127
124
|
};
|
|
128
125
|
}
|
|
129
|
-
const findAllAttributeMetadata = (target) => {
|
|
130
|
-
return ReflectUtils.findAllMetadata(ATTRIBUTE_METADATA_KEY, target).flat();
|
|
131
|
-
};
|
|
132
126
|
function attributeHost(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
133
127
|
if (propertyKeyOrOptions !== void 0 && (typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol")) {
|
|
134
|
-
|
|
135
|
-
return attribute(":host", { name: fieldName })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
128
|
+
return attribute(":host", { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
136
129
|
}
|
|
137
130
|
if (typeof targetOrAttrOrOptions === "string") {
|
|
138
131
|
const attrName = targetOrAttrOrOptions;
|
|
@@ -141,18 +134,19 @@ function attributeHost(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
|
141
134
|
} else if (typeof targetOrAttrOrOptions === "object") {
|
|
142
135
|
const options = targetOrAttrOrOptions;
|
|
143
136
|
return (target, propertyKey) => {
|
|
144
|
-
|
|
145
|
-
return attribute(":host", { ...options, name: fieldName })(target, propertyKey);
|
|
137
|
+
return attribute(":host", { ...options, name: String(propertyKey) })(target, propertyKey);
|
|
146
138
|
};
|
|
147
139
|
} else {
|
|
148
140
|
return (target, propertyKey) => {
|
|
149
|
-
|
|
150
|
-
return attribute(":host", { name: fieldName })(target, propertyKey);
|
|
141
|
+
return attribute(":host", { name: String(propertyKey) })(target, propertyKey);
|
|
151
142
|
};
|
|
152
143
|
}
|
|
153
144
|
}
|
|
145
|
+
const findAllAttributeMetadata = (target) => {
|
|
146
|
+
return ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, target).flat();
|
|
147
|
+
};
|
|
154
148
|
export {
|
|
155
|
-
|
|
149
|
+
ATTRIBUTE_FIELD_METADATA_KEY,
|
|
156
150
|
attribute,
|
|
157
151
|
attributeHost,
|
|
158
152
|
findAllAttributeMetadata,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/attribute.ts"],
|
|
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
|
|
5
|
-
"mappings": "AAAA,SAAQ,oBAAmB;AAC3B,SAAoB,wBAAuB;AAC3C,SAAQ,gBAAe;AAgBhB,MAAM,
|
|
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,IA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AA0B,UAAU;AAC7C,UAAM,WAAW;AACjB,UAAM,UAAW,OAAO,yBAAyB,WAAW,uBAAuB,CAAC;AACpF,WAAO,UAAU,SAAS,EAAE,GAAG,SAAS,MAAM,SAAS,CAAC;AAAA,EAC1D,WAAW,OAAO,0BAA0B,UAAU;AACpD,UAAM,UAAU;AAChB,WAAO,CAAC,QAAgB,gBAAiC;AACvD,aAAO,UAAU,SAAS,EAAE,GAAG,SAAS,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC1F;AAAA,EACF,OAAO;AACL,WAAO,CAAC,QAAgB,gBAAiC;AACvD,aAAO,UAAU,SAAS,EAAE,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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/changedAttributeHost.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:on-attribute-changed');\n\n/**\n * @changedAttributeHost decorator - fires when any attribute on :host changes\n * Usage: @changedAttributeHost('data-product-id')\n */\nexport function changedAttributeHost(attributeName?: string): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as Map<string, (string | symbol)[]>;\n if (!meta) {\n meta = new Map<string, (string | symbol)[]>();\n ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);\n }\n\n const name = attributeName || String(propertyKey);\n let methods = meta.get(name);\n if (!methods) {\n methods = [];\n meta.set(name, methods);\n }\n if (!methods.includes(propertyKey)) methods.push(propertyKey);\n };\n}\n\nexport const getChangedAttributeMetadata = (target: any): Map<string, (string | symbol)[]> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n\nexport const findAllAttributeChangedMetadata = (target: any): Map<string, (string | symbol)[]> => {\n return ReflectUtils.findAllMapMetadata<string, string | symbol>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, target);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,oBAAmB;AAEpB,MAAM,oCAAoC,OAAO,2CAA2C;
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for('simple-web-component:on-attribute-changed');\n\n/**\n * @changedAttributeHost decorator - fires when any attribute on :host changes\n * Usage: @changedAttributeHost('data-product-id')\n */\nexport function changedAttributeHost(attributeName?: string): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as Map<string, (string | symbol)[]>;\n if (!meta) {\n meta = new Map<string, (string | symbol)[]>();\n ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);\n }\n\n const name = attributeName || String(propertyKey);\n let methods = meta.get(name);\n if (!methods) {\n methods = [];\n meta.set(name, methods);\n }\n if (!methods.includes(propertyKey)) methods.push(propertyKey);\n };\n}\n\nexport const getChangedAttributeMetadata = (target: any): Map<string, (string | symbol)[]> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n\nexport const findAllAttributeChangedMetadata = (target: any): Map<string, (string | symbol)[]> => {\n return ReflectUtils.findAllMapMetadata<string, string | symbol>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, target);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,oBAAmB;AAEpB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAMhG,SAAS,qBAAqB,eAAyC;AAC5E,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,aAAa,eAAe,mCAAmC,WAAW;AACrF,QAAI,CAAC,MAAM;AACT,aAAO,oBAAI,IAAiC;AAC5C,mBAAa,eAAe,mCAAmC,MAAM,WAAW;AAAA,IAClF;AAEA,UAAM,OAAO,iBAAiB,OAAO,WAAW;AAChD,QAAI,UAAU,KAAK,IAAI,IAAI;AAC3B,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAC;AACX,WAAK,IAAI,MAAM,OAAO;AAAA,IACxB;AACA,QAAI,CAAC,QAAQ,SAAS,WAAW,EAAG,SAAQ,KAAK,WAAW;AAAA,EAC9D;AACF;AAEO,MAAM,8BAA8B,CAAC,WAA8D;AACxG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,mCAAmC,WAAW;AAChF;AAEO,MAAM,kCAAkC,CAAC,WAAkD;AAChG,SAAO,aAAa,mBAA4C,mCAAmC,MAAM;AAC3G;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,13 +4,13 @@ import { getAddEventListenerMetadata } from "./addEventListener.js";
|
|
|
4
4
|
import { ON_CONSTRUCTOR_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata } from "./lifecycles.js";
|
|
5
5
|
import { getEmitCustomEventMetadataList } from "./emitCustomEvent.js";
|
|
6
6
|
import { findAllAttributeChangedMetadata } from "./changedAttributeHost.js";
|
|
7
|
-
import {
|
|
7
|
+
import { findAllAttributeApplyMetadata } from "./applyAttribute.js";
|
|
8
8
|
import { findAllAttributeMetadata } from "./attribute.js";
|
|
9
9
|
import { SwcUtils } from "../utils/Utils.js";
|
|
10
10
|
import { HTML_TAG_ENTRIES, DOM_EVENT_NAMES } from "../config/config.js";
|
|
11
11
|
import { SituationTypeContainer, SituationTypeContainers } from "@dooboostore/simple-boot/decorators/inject/Inject";
|
|
12
12
|
import { InjectSituationType } from "../types.js";
|
|
13
|
-
const ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
|
|
13
|
+
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
14
14
|
const getElementConfig = (target) => {
|
|
15
15
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
16
16
|
return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
@@ -125,7 +125,6 @@ const setupPrototype = (proto) => {
|
|
|
125
125
|
const oldHandler = handlers.get(attrName);
|
|
126
126
|
if (oldHandler) el.removeEventListener(eventName, oldHandler);
|
|
127
127
|
const handler = async (event) => {
|
|
128
|
-
console.log("execute handler", event);
|
|
129
128
|
const parent = SwcUtils.findNearestSwcHost(el);
|
|
130
129
|
const hostSet = SwcUtils.getHostSet(parent || el);
|
|
131
130
|
const conf = getElementConfig(this);
|
|
@@ -146,7 +145,6 @@ const setupPrototype = (proto) => {
|
|
|
146
145
|
};
|
|
147
146
|
proto.__swc_executeAttributeEvent = async function(el, attrName, script, event) {
|
|
148
147
|
ensureInit(this);
|
|
149
|
-
console.log("execute handler2", event);
|
|
150
148
|
const parent = SwcUtils.findNearestSwcHost(el);
|
|
151
149
|
const hostSet = SwcUtils.getHostSet(parent || el);
|
|
152
150
|
const conf = getElementConfig(this);
|
|
@@ -186,12 +184,22 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
186
184
|
const emitCustomEventList = getEmitCustomEventMetadataList(constructor) || [];
|
|
187
185
|
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === ":host" || meta.selector === "");
|
|
188
186
|
const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
|
|
189
|
-
const addHostEventListenerList = addEventListenerList.filter((meta) => meta.selector === ":host" || meta.selector === "");
|
|
190
187
|
const attrChangeMap = findAllAttributeChangedMetadata(constructor);
|
|
191
188
|
const attributeList = findAllAttributeMetadata(constructor);
|
|
189
|
+
const applyAttributeMap = findAllAttributeApplyMetadata(constructor);
|
|
192
190
|
const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
|
|
193
191
|
const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
194
|
-
const
|
|
192
|
+
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.options.name).filter(Boolean);
|
|
193
|
+
const attributeListNames = attributeList.map((it) => it.options.name || String(it.propertyKey));
|
|
194
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([
|
|
195
|
+
...metadata.observedAttributes ?? [],
|
|
196
|
+
...attrChangeMap.keys(),
|
|
197
|
+
...attributeApplyNames,
|
|
198
|
+
...attributeListNames,
|
|
199
|
+
...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean),
|
|
200
|
+
...swcLifecycleAttributes,
|
|
201
|
+
...swcOnEvents
|
|
202
|
+
])];
|
|
195
203
|
const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
|
|
196
204
|
const proto = constructor.prototype;
|
|
197
205
|
setupPrototype(proto);
|
|
@@ -210,7 +218,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
210
218
|
for (const m of bMethods) this._invokeLifecycleMethod(m, hostSet);
|
|
211
219
|
}
|
|
212
220
|
attributeList.forEach((meta) => {
|
|
213
|
-
const attrName = meta.options.name || String(meta.propertyKey);
|
|
214
221
|
if (meta.options.connectedInitialize === true) {
|
|
215
222
|
this.__swc_syncing_init = true;
|
|
216
223
|
try {
|
|
@@ -350,22 +357,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
350
357
|
}
|
|
351
358
|
});
|
|
352
359
|
});
|
|
353
|
-
addHostEventListenerList.forEach((meta) => {
|
|
354
|
-
const { type, options } = meta;
|
|
355
|
-
const opts = { capture: options.capture, once: options.once, passive: options.passive };
|
|
356
|
-
const handler = async (event) => {
|
|
357
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
358
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
359
|
-
if (options.preventDefault) event.preventDefault();
|
|
360
|
-
const currentHostSet = SwcUtils.getHostSet(this);
|
|
361
|
-
const args = { event, ...currentHostSet, $el: this, $root: this.getRootNode() };
|
|
362
|
-
await this[meta.propertyKey](event, currentHostSet, args);
|
|
363
|
-
};
|
|
364
|
-
this.addEventListener(type, handler, opts);
|
|
365
|
-
if (options.removeOnDisconnected === true) {
|
|
366
|
-
this._boundListeners.push({ target: this, type, handler, options: opts });
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
360
|
if (originalConnected) originalConnected.apply(this);
|
|
370
361
|
const aMethods = findAllLifecycleMetadata(this, ON_AFTER_CONNECTED_METADATA_KEY);
|
|
371
362
|
if (aMethods) {
|