@dooboostore/simple-web-component 1.0.15 → 1.0.17
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 +275 -91
- package/dist/cjs/decorators/addEventListener.js +2 -3
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +161 -34
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +2 -14
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/query.js +47 -36
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +42 -36
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +2 -1
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +188 -0
- package/dist/cjs/elements/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/SwcChoose.js +155 -0
- package/dist/cjs/elements/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/SwcIf.js +167 -0
- package/dist/cjs/elements/SwcIf.js.map +7 -0
- package/dist/cjs/elements/SwcLoop.js +246 -0
- package/dist/cjs/elements/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/SwcSubTemplates.js +65 -0
- package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/index.js +7 -0
- package/dist/cjs/elements/index.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/utils/Utils.js +92 -162
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.js +2 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +161 -34
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +2 -14
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/query.js +47 -36
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +42 -36
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +2 -1
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +169 -0
- package/dist/esm/elements/SwcAsync.js.map +7 -0
- package/dist/esm/elements/SwcChoose.js +136 -0
- package/dist/esm/elements/SwcChoose.js.map +7 -0
- package/dist/esm/elements/SwcIf.js +148 -0
- package/dist/esm/elements/SwcIf.js.map +7 -0
- package/dist/esm/elements/SwcLoop.js +227 -0
- package/dist/esm/elements/SwcLoop.js.map +7 -0
- package/dist/esm/elements/SwcSubTemplates.js +46 -0
- package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/index.js +7 -0
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +2 -2
- package/dist/esm/utils/Utils.js +92 -162
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1150 -326
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +10 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +4 -5
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +4 -5
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +16 -0
- package/dist/types/elements/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/SwcChoose.d.ts +13 -0
- package/dist/types/elements/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/SwcIf.d.ts +15 -0
- package/dist/types/elements/SwcIf.d.ts.map +1 -0
- package/dist/types/elements/SwcLoop.d.ts +20 -0
- package/dist/types/elements/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +7 -0
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +11 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +19 -21
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1150 -326
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +11 -7
- package/src/decorators/elementDefine.ts +165 -39
- package/src/decorators/emitCustomEvent.ts +5 -21
- package/src/decorators/query.ts +46 -41
- package/src/decorators/queryAll.ts +45 -41
- package/src/elements/SwcAppEngine.ts +2 -1
- package/src/elements/SwcAsync.ts +163 -0
- package/src/elements/SwcChoose.ts +127 -0
- package/src/elements/SwcIf.ts +134 -0
- package/src/elements/SwcLoop.ts +215 -0
- package/src/elements/SwcSubTemplates.ts +19 -0
- package/src/elements/index.ts +8 -3
- package/src/index.ts +1 -1
- package/src/types.ts +15 -5
- package/src/utils/Utils.ts +111 -197
package/dist/cjs/utils/Utils.js
CHANGED
|
@@ -21,182 +21,112 @@ __export(Utils_exports, {
|
|
|
21
21
|
SwcUtils: () => SwcUtils
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(Utils_exports);
|
|
24
|
+
var import_elementDefine = require("../decorators/elementDefine");
|
|
24
25
|
const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var SwcUtils;
|
|
27
|
+
((SwcUtils2) => {
|
|
28
|
+
SwcUtils2.getHelperSet = (win) => {
|
|
29
|
+
const doc = win.document;
|
|
30
|
+
return {
|
|
31
|
+
$d: doc,
|
|
32
|
+
$w: win,
|
|
33
|
+
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
34
|
+
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
35
|
+
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
SwcUtils2.getHelperAndHostSet = (win, el) => {
|
|
39
|
+
const helperSet = (0, SwcUtils2.getHelperSet)(win);
|
|
40
|
+
const hostSet = (0, SwcUtils2.getHostSet)(el);
|
|
41
|
+
return {
|
|
42
|
+
...helperSet,
|
|
43
|
+
...hostSet
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
SwcUtils2.getValueByPath = (obj, path, rootName) => {
|
|
27
47
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
28
48
|
const parts = path.split(".");
|
|
29
|
-
|
|
30
|
-
const subParts = parts.slice(1);
|
|
31
|
-
let subResult = obj;
|
|
32
|
-
for (const part of subParts) {
|
|
33
|
-
if (subResult === null || typeof subResult !== "object" || !(part in subResult)) return SWC_NOT_FOUND;
|
|
34
|
-
subResult = subResult[part];
|
|
35
|
-
}
|
|
36
|
-
return subResult;
|
|
37
|
-
}
|
|
38
|
-
let result = obj;
|
|
49
|
+
let current = obj;
|
|
39
50
|
for (const part of parts) {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
result = result[part];
|
|
51
|
+
if (current === null || current === void 0) return SWC_NOT_FOUND;
|
|
52
|
+
current = current[part];
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return new Function(...keys, `return (${expr})`).apply(null, values);
|
|
55
|
-
} catch {
|
|
56
|
-
return SWC_NOT_FOUND;
|
|
54
|
+
return current;
|
|
55
|
+
};
|
|
56
|
+
SwcUtils2.findNearestSwcHost = (el) => {
|
|
57
|
+
if (el.__swc_host) return el.__swc_host;
|
|
58
|
+
let current = el.parentElement || el.getRootNode?.()?.host;
|
|
59
|
+
while (current && current !== document && current !== window) {
|
|
60
|
+
if (current.__swc_host) return current.__swc_host;
|
|
61
|
+
if ((0, import_elementDefine.getElementConfig)(current)) return current;
|
|
62
|
+
current = current.parentElement || current.getRootNode?.()?.host;
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const context = {};
|
|
62
|
-
if (index !== void 0) {
|
|
63
|
-
context[asIndexKey] = index;
|
|
64
|
-
}
|
|
65
|
-
if (data !== null && data !== void 0) {
|
|
66
|
-
context[asKey] = data;
|
|
67
|
-
context["value"] = data;
|
|
68
|
-
}
|
|
69
|
-
const fullContext = { ...hostContext || {}, ...context };
|
|
70
|
-
const resolveExpr = (expr, match) => {
|
|
71
|
-
expr = expr.trim();
|
|
72
|
-
const simpleVal = SwcUtils.getValueByPath(data, expr, asKey);
|
|
73
|
-
if (simpleVal !== SWC_NOT_FOUND && typeof simpleVal !== "symbol") {
|
|
74
|
-
return simpleVal === null || simpleVal === void 0 ? "" : String(simpleVal);
|
|
75
|
-
}
|
|
76
|
-
const exprVal = SwcUtils.evalExpression(expr, fullContext);
|
|
77
|
-
if (exprVal !== SWC_NOT_FOUND && typeof exprVal !== "symbol") {
|
|
78
|
-
return exprVal === null || exprVal === void 0 ? "" : String(exprVal);
|
|
79
|
-
}
|
|
80
|
-
return match;
|
|
81
|
-
};
|
|
82
|
-
const walk = (n) => {
|
|
83
|
-
if (n.nodeType === Node.TEXT_NODE) {
|
|
84
|
-
if (!n._original) n._original = n.textContent;
|
|
85
|
-
let text = n._original;
|
|
86
|
-
text = text.replace(/{{(.*?)}}/g, (match, path) => {
|
|
87
|
-
return resolveExpr(path, match);
|
|
88
|
-
});
|
|
89
|
-
if (n.textContent !== text) n.textContent = text;
|
|
90
|
-
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
91
|
-
const el = n;
|
|
92
|
-
Array.from(el.attributes).forEach((a) => {
|
|
93
|
-
if (!a._original) a._original = a.value;
|
|
94
|
-
let val = a._original;
|
|
95
|
-
val = val.replace(/{{(.*?)}}/g, (match, path) => {
|
|
96
|
-
return resolveExpr(path, match);
|
|
97
|
-
});
|
|
98
|
-
if (a.value !== val) a.value = val;
|
|
99
|
-
});
|
|
100
|
-
el.childNodes.forEach(walk);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
walk(node);
|
|
104
|
-
}
|
|
105
|
-
static createReactiveProxy(target, onChange, onIndexChange) {
|
|
106
|
-
const makeRecursiveProxy = (obj) => {
|
|
107
|
-
if (typeof obj !== "object" || obj === null || obj instanceof Node) return obj;
|
|
108
|
-
if (obj.__swc_is_proxy) return obj;
|
|
109
|
-
const IS_PROXY_KEY = "__swc_is_proxy";
|
|
110
|
-
const proxy = new Proxy(obj, {
|
|
111
|
-
get: (t, prop) => {
|
|
112
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
113
|
-
if (typeof prop === "symbol") return t[prop];
|
|
114
|
-
return t[prop];
|
|
115
|
-
},
|
|
116
|
-
set: (t, prop, val) => {
|
|
117
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
118
|
-
if (typeof prop === "symbol") {
|
|
119
|
-
t[prop] = val;
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
const oldVal = t[prop];
|
|
123
|
-
if (oldVal === val) return true;
|
|
124
|
-
t[prop] = makeRecursiveProxy(val);
|
|
125
|
-
const isIndex = !isNaN(Number(prop)) && Array.isArray(t);
|
|
126
|
-
if (isIndex && onIndexChange) {
|
|
127
|
-
onIndexChange(Number(prop), val);
|
|
128
|
-
} else {
|
|
129
|
-
onChange();
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
},
|
|
133
|
-
deleteProperty: (t, prop) => {
|
|
134
|
-
delete t[prop];
|
|
135
|
-
onChange();
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return proxy;
|
|
140
|
-
};
|
|
141
|
-
return makeRecursiveProxy(target);
|
|
142
|
-
}
|
|
143
|
-
static findNearestSwcHost(el) {
|
|
144
|
-
const hosts = this.findAllSwcHosts(el);
|
|
145
|
-
return hosts.length > 0 ? hosts[hosts.length - 1] : null;
|
|
146
|
-
}
|
|
147
|
-
static findAllSwcHosts(el) {
|
|
64
|
+
return void 0;
|
|
65
|
+
};
|
|
66
|
+
SwcUtils2.findAllSwcHosts = (el) => {
|
|
148
67
|
const hosts = [];
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
curr = curr.parentElement || curr?.getRootNode()?.host;
|
|
68
|
+
let current = (0, SwcUtils2.findNearestSwcHost)(el);
|
|
69
|
+
while (current) {
|
|
70
|
+
hosts.push(current);
|
|
71
|
+
current = (0, SwcUtils2.findNearestSwcHost)(current);
|
|
154
72
|
}
|
|
155
73
|
return hosts.reverse();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
static getAppHosts(el) {
|
|
169
|
-
const hosts = this.getHosts(el);
|
|
74
|
+
};
|
|
75
|
+
SwcUtils2.getHosts = (el) => {
|
|
76
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
77
|
+
if ((0, import_elementDefine.getElementConfig)(el)) return [...ancestors, el];
|
|
78
|
+
return ancestors;
|
|
79
|
+
};
|
|
80
|
+
SwcUtils2.getHost = (el) => {
|
|
81
|
+
if ((0, import_elementDefine.getElementConfig)(el)) return el;
|
|
82
|
+
return (0, SwcUtils2.findNearestSwcHost)(el);
|
|
83
|
+
};
|
|
84
|
+
SwcUtils2.getAppHosts = (el) => {
|
|
85
|
+
const hosts = (0, SwcUtils2.getHosts)(el);
|
|
170
86
|
return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const appHosts =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const $
|
|
87
|
+
};
|
|
88
|
+
SwcUtils2.getAppHost = (el) => {
|
|
89
|
+
const appHosts = (0, SwcUtils2.getAppHosts)(el);
|
|
90
|
+
const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
|
|
91
|
+
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
|
|
92
|
+
};
|
|
93
|
+
SwcUtils2.getHostSet = (el) => {
|
|
94
|
+
const isSwc = !!(0, import_elementDefine.getElementConfig)(el);
|
|
95
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
96
|
+
let $host;
|
|
97
|
+
let $parentHost;
|
|
98
|
+
if (isSwc) {
|
|
99
|
+
$host = el;
|
|
100
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
101
|
+
} else {
|
|
102
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
103
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
104
|
+
}
|
|
105
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
106
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
107
|
+
const loopContext = {};
|
|
108
|
+
let curr = el;
|
|
109
|
+
while (curr && curr !== document.documentElement) {
|
|
110
|
+
if (curr.__swc_loop_context) {
|
|
111
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
112
|
+
}
|
|
113
|
+
curr = curr.parentElement || curr.getRootNode().host;
|
|
114
|
+
}
|
|
115
|
+
const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
|
|
116
|
+
const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
|
|
117
|
+
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
190
118
|
return {
|
|
191
|
-
$host
|
|
119
|
+
$host,
|
|
120
|
+
$parentHost,
|
|
192
121
|
$hosts,
|
|
193
122
|
$firstHost,
|
|
194
|
-
$lastHost,
|
|
195
|
-
$appHost
|
|
123
|
+
$lastHost: $parentHost,
|
|
124
|
+
$appHost,
|
|
196
125
|
$appHosts,
|
|
197
126
|
$firstAppHost,
|
|
198
|
-
$lastAppHost
|
|
127
|
+
$lastAppHost: $appHost,
|
|
128
|
+
...loopContext
|
|
199
129
|
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
130
|
+
};
|
|
131
|
+
})(SwcUtils || (SwcUtils = {}));
|
|
202
132
|
//# sourceMappingURL=Utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/Utils.ts"],
|
|
4
|
-
"sourcesContent": ["import {HostSet,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';\nimport { getElementConfig } from '../decorators/elementDefine';\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport namespace SwcUtils {\n export const getHelperSet = (win: Window): HelperSet => {\n const doc: Document = win.document;\n return {\n $d: doc,\n $w: win,\n $q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),\n $qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],\n $qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement\n } as const;\n };\n\n export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {\n const helperSet = getHelperSet(win);\n const hostSet = getHostSet(el);\n return {\n ...helperSet,\n ...hostSet\n };\n };\n\n export const getValueByPath = (obj: any, path: string, rootName: string) => {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n };\n\n /**\n * Finds the nearest logical SWC host for an element.\n * Checks __swc_host property first, then climbs the DOM tree.\n */\n export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {\n if ((el as any).__swc_host) return (el as any).__swc_host;\n\n let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;\n while (current && current !== document && current !== window) {\n if (current.__swc_host) return current.__swc_host;\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current.getRootNode?.() as any)?.host;\n }\n return undefined;\n };\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {\n const hosts: HTMLElement[] = [];\n let current = findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n // To find the next ancestor, we must start searching from the PARENT of the found host\n current = findNearestSwcHost(current);\n }\n return hosts.reverse();\n };\n\n export const getHosts = (el: HTMLElement): HTMLElement[] => {\n const ancestors = findAllSwcHosts(el);\n if (getElementConfig(el)) return [...ancestors, el];\n return ancestors;\n };\n\n export const getHost = (el: HTMLElement): HTMLElement | undefined => {\n if (getElementConfig(el)) return el;\n return findNearestSwcHost(el);\n };\n\n export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {\n const hosts = getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n };\n\n export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {\n const appHosts = getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n };\n\n export const getHostSet = (el: HTMLElement): HostSet => {\n const isSwc = !!getElementConfig(el);\n const ancestors = findAllSwcHosts(el); // [root, ..., parent]\n\n let $host: HTMLElement;\n let $parentHost: HTMLElement | null;\n\n if (isSwc) {\n $host = el;\n $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n } else {\n $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;\n $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;\n }\n\n const $hosts = isSwc ? [...ancestors, el] : ancestors;\n const $firstHost = $hosts.length > 0 ? $hosts[0] : null;\n\n // Collect loop contexts\n const loopContext: Record<string, any> = {};\n let curr: any = el;\n while (curr && curr !== document.documentElement) {\n if (curr.__swc_loop_context) {\n Object.assign(loopContext, curr.__swc_loop_context);\n }\n curr = curr.parentElement || (curr.getRootNode() as any).host;\n }\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost,\n ...loopContext\n } as any;\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAiC;AAE1B,MAAM,gBAAgB,OAAO,eAAe;AAE5C,IAAU;AAAA,CAAV,CAAUA,cAAV;AACE,EAAMA,UAAA,eAAe,CAAC,QAA2B;AACtD,UAAM,MAAgB,IAAI;AAC1B,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI,CAAC,KAAa,UAA4C,QAAQ,KAAK,cAAc,GAAG;AAAA,MAC5F,KAAK,CAAC,KAAa,SAA2C,MAAM,MAAM,QAAQ,KAAK,iBAAiB,GAAG,CAAC;AAAA,MAC5G,KAAK,CAAC,IAAY,UAAkC,QAAQ,KAAK,eAAe,EAAE;AAAA,IACpF;AAAA,EACF;AAEO,EAAMA,UAAA,sBAAsB,CAAC,KAAa,OAAmC;AAClF,UAAM,gBAAYA,UAAA,cAAa,GAAG;AAClC,UAAM,cAAUA,UAAA,YAAW,EAAE;AAC7B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AAEO,EAAMA,UAAA,iBAAiB,CAAC,KAAU,MAAc,aAAqB;AAC1E,QAAI,CAAC,OAAO,CAAC,KAAM,QAAO;AAE1B,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,QAAI,UAAU;AAEd,eAAW,QAAQ,OAAO;AACxB,UAAI,YAAY,QAAQ,YAAY,OAAW,QAAO;AACtD,gBAAU,QAAQ,IAAI;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AAMO,EAAMA,UAAA,qBAAqB,CAAC,OAAoD;AACrF,QAAK,GAAW,WAAY,QAAQ,GAAW;AAE/C,QAAI,UAAe,GAAG,iBAAk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} from "@dooboostore/core/reflect/ReflectUtils";
|
|
2
2
|
const ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
|
|
3
|
-
function addEventListener(
|
|
3
|
+
function addEventListener(selector, type, options = {}) {
|
|
4
4
|
return (target, propertyKey, descriptor) => {
|
|
5
5
|
const constructor = target.constructor;
|
|
6
|
-
const options = typeof arg1 === "string" ? { type: arg1, query: arg2 } : arg1;
|
|
7
6
|
let listeners = ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
8
7
|
if (!listeners) {
|
|
9
8
|
listeners = [];
|
|
10
9
|
ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
|
|
11
10
|
}
|
|
12
|
-
listeners.push({ options, propertyKey });
|
|
11
|
+
listeners.push({ selector, type, options, propertyKey });
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
const getAddEventListenerMetadata = (target) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/addEventListener.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport interface AddEventListenerOptions extends EventListenerOptions {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport interface AddEventListenerOptions extends EventListenerOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n stopPropagation?: boolean;\n stopImmediatePropagation?: boolean;\n preventDefault?: boolean;\n delegate?: boolean;\n removeOnDisconnected?: boolean;\n}\n\nexport interface AddEventListenerMetadata {\n selector: string;\n type: string;\n options: AddEventListenerOptions;\n propertyKey: string | symbol;\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol('simple-web-component:add-event-listener');\n\n/**\n * @addEventListener decorator to bind events to elements.\n * Usage: @addEventListener('.btn', 'click') onClick() { ... }\n * Usage: @addEventListener('', 'scroll', { passive: true }) onScroll() { ... }\n */\nexport function addEventListener(selector: string, type: string, options: AddEventListenerOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n if (!listeners) {\n listeners = [];\n ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);\n }\n listeners.push({ selector, type, options, propertyKey });\n };\n}\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAqBtB,MAAM,kCAAkC,OAAO,yCAAyC;AAOxF,SAAS,iBAAiB,UAAkB,MAAc,UAAmC,CAAC,GAAoB;AACvH,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAE3B,QAAI,YAAY,aAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,mBAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AACA,cAAU,KAAK,EAAE,UAAU,MAAM,SAAS,YAAY,CAAC;AAAA,EACzD;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,iCAAiC,WAAW;AAC9E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|