@dooboostore/simple-web-component 1.0.16 → 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 +93 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +133 -62
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/query.js +22 -0
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +14 -0
- 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.map +1 -1
- package/dist/cjs/utils/Utils.js +74 -37
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +133 -62
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/query.js +22 -0
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +14 -0
- 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.map +1 -1
- package/dist/esm/utils/Utils.js +74 -37
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1047 -140
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +1 -0
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +0 -2
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +0 -2
- 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 +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +16 -10
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1047 -140
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +1 -0
- package/src/decorators/elementDefine.ts +137 -66
- package/src/decorators/query.ts +20 -2
- package/src/decorators/queryAll.ts +16 -2
- 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 +9 -1
- package/src/utils/Utils.ts +86 -36
package/src/utils/Utils.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import { SwcAppInterface, HostSet } from '../types';
|
|
1
|
+
import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';
|
|
2
2
|
import { getElementConfig } from '../decorators/elementDefine';
|
|
3
3
|
|
|
4
4
|
export const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export namespace SwcUtils {
|
|
7
|
+
export const getHelperSet = (win: Window): HelperSet => {
|
|
8
|
+
const doc: Document = win.document;
|
|
9
|
+
return {
|
|
10
|
+
$d: doc,
|
|
11
|
+
$w: win,
|
|
12
|
+
$q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),
|
|
13
|
+
$qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],
|
|
14
|
+
$qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement
|
|
15
|
+
} as const;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {
|
|
19
|
+
const helperSet = getHelperSet(win);
|
|
20
|
+
const hostSet = getHostSet(el);
|
|
21
|
+
return {
|
|
22
|
+
...helperSet,
|
|
23
|
+
...hostSet
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getValueByPath = (obj: any, path: string, rootName: string) => {
|
|
8
28
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
9
29
|
|
|
10
30
|
const parts = path.split('.');
|
|
@@ -15,58 +35,87 @@ export class SwcUtils {
|
|
|
15
35
|
current = current[part];
|
|
16
36
|
}
|
|
17
37
|
return current;
|
|
18
|
-
}
|
|
38
|
+
};
|
|
19
39
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Finds the nearest logical SWC host for an element.
|
|
42
|
+
* Checks __swc_host property first, then climbs the DOM tree.
|
|
43
|
+
*/
|
|
44
|
+
export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {
|
|
45
|
+
if ((el as any).__swc_host) return (el as any).__swc_host;
|
|
23
46
|
|
|
24
|
-
|
|
47
|
+
let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;
|
|
48
|
+
while (current && current !== document && current !== window) {
|
|
49
|
+
if (current.__swc_host) return current.__swc_host;
|
|
25
50
|
if (getElementConfig(current)) return current as HTMLElement;
|
|
26
|
-
current = current.parentElement || (current?.
|
|
51
|
+
current = current.parentElement || (current.getRootNode?.() as any)?.host;
|
|
27
52
|
}
|
|
28
53
|
return undefined;
|
|
29
|
-
}
|
|
54
|
+
};
|
|
30
55
|
|
|
31
56
|
/**
|
|
32
57
|
* Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
|
|
33
58
|
*/
|
|
34
|
-
|
|
59
|
+
export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {
|
|
35
60
|
const hosts: HTMLElement[] = [];
|
|
36
|
-
let current =
|
|
61
|
+
let current = findNearestSwcHost(el);
|
|
37
62
|
while (current) {
|
|
38
63
|
hosts.push(current);
|
|
39
|
-
|
|
64
|
+
// To find the next ancestor, we must start searching from the PARENT of the found host
|
|
65
|
+
current = findNearestSwcHost(current);
|
|
40
66
|
}
|
|
41
67
|
return hosts.reverse();
|
|
42
|
-
}
|
|
68
|
+
};
|
|
43
69
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
export const getHosts = (el: HTMLElement): HTMLElement[] => {
|
|
71
|
+
const ancestors = findAllSwcHosts(el);
|
|
72
|
+
if (getElementConfig(el)) return [...ancestors, el];
|
|
73
|
+
return ancestors;
|
|
74
|
+
};
|
|
47
75
|
|
|
48
|
-
|
|
49
|
-
return el;
|
|
50
|
-
|
|
76
|
+
export const getHost = (el: HTMLElement): HTMLElement | undefined => {
|
|
77
|
+
if (getElementConfig(el)) return el;
|
|
78
|
+
return findNearestSwcHost(el);
|
|
79
|
+
};
|
|
51
80
|
|
|
52
|
-
|
|
53
|
-
const hosts =
|
|
81
|
+
export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {
|
|
82
|
+
const hosts = getHosts(el);
|
|
54
83
|
return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];
|
|
55
|
-
}
|
|
84
|
+
};
|
|
56
85
|
|
|
57
|
-
|
|
58
|
-
const appHosts =
|
|
86
|
+
export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {
|
|
87
|
+
const appHosts = getAppHosts(el);
|
|
59
88
|
const appHostsWithoutSelf = appHosts.filter(h => h !== el);
|
|
60
|
-
// Nearest app host is the last one in [root, ..., parent]
|
|
61
89
|
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;
|
|
62
|
-
}
|
|
90
|
+
};
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
export const getHostSet = (el: HTMLElement): HostSet => {
|
|
93
|
+
const isSwc = !!getElementConfig(el);
|
|
94
|
+
const ancestors = findAllSwcHosts(el); // [root, ..., parent]
|
|
95
|
+
|
|
96
|
+
let $host: HTMLElement;
|
|
97
|
+
let $parentHost: HTMLElement | null;
|
|
98
|
+
|
|
99
|
+
if (isSwc) {
|
|
100
|
+
$host = el;
|
|
101
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
102
|
+
} else {
|
|
103
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
104
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
108
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
109
|
+
|
|
110
|
+
// Collect loop contexts
|
|
111
|
+
const loopContext: Record<string, any> = {};
|
|
112
|
+
let curr: any = el;
|
|
113
|
+
while (curr && curr !== document.documentElement) {
|
|
114
|
+
if (curr.__swc_loop_context) {
|
|
115
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
116
|
+
}
|
|
117
|
+
curr = curr.parentElement || (curr.getRootNode() as any).host;
|
|
118
|
+
}
|
|
70
119
|
|
|
71
120
|
const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];
|
|
72
121
|
const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;
|
|
@@ -81,7 +130,8 @@ export class SwcUtils {
|
|
|
81
130
|
$appHost,
|
|
82
131
|
$appHosts,
|
|
83
132
|
$firstAppHost,
|
|
84
|
-
$lastAppHost: $appHost
|
|
85
|
-
|
|
86
|
-
|
|
133
|
+
$lastAppHost: $appHost,
|
|
134
|
+
...loopContext
|
|
135
|
+
} as any;
|
|
136
|
+
};
|
|
87
137
|
}
|