@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.
Files changed (98) hide show
  1. package/README.md +93 -0
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/elementDefine.js +133 -62
  4. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  5. package/dist/cjs/decorators/query.js +22 -0
  6. package/dist/cjs/decorators/query.js.map +2 -2
  7. package/dist/cjs/decorators/queryAll.js +14 -0
  8. package/dist/cjs/decorators/queryAll.js.map +2 -2
  9. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  10. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  11. package/dist/cjs/elements/SwcAsync.js +188 -0
  12. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  13. package/dist/cjs/elements/SwcChoose.js +155 -0
  14. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  15. package/dist/cjs/elements/SwcIf.js +167 -0
  16. package/dist/cjs/elements/SwcIf.js.map +7 -0
  17. package/dist/cjs/elements/SwcLoop.js +246 -0
  18. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  19. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  20. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  21. package/dist/cjs/elements/index.js +7 -0
  22. package/dist/cjs/elements/index.js.map +2 -2
  23. package/dist/cjs/index.js +1 -1
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils/Utils.js +74 -37
  27. package/dist/cjs/utils/Utils.js.map +3 -3
  28. package/dist/esm/decorators/addEventListener.js.map +2 -2
  29. package/dist/esm/decorators/elementDefine.js +133 -62
  30. package/dist/esm/decorators/elementDefine.js.map +3 -3
  31. package/dist/esm/decorators/query.js +22 -0
  32. package/dist/esm/decorators/query.js.map +2 -2
  33. package/dist/esm/decorators/queryAll.js +14 -0
  34. package/dist/esm/decorators/queryAll.js.map +2 -2
  35. package/dist/esm/elements/SwcAppEngine.js +2 -1
  36. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  37. package/dist/esm/elements/SwcAsync.js +169 -0
  38. package/dist/esm/elements/SwcAsync.js.map +7 -0
  39. package/dist/esm/elements/SwcChoose.js +136 -0
  40. package/dist/esm/elements/SwcChoose.js.map +7 -0
  41. package/dist/esm/elements/SwcIf.js +148 -0
  42. package/dist/esm/elements/SwcIf.js.map +7 -0
  43. package/dist/esm/elements/SwcLoop.js +227 -0
  44. package/dist/esm/elements/SwcLoop.js.map +7 -0
  45. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  46. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  47. package/dist/esm/elements/index.js +7 -0
  48. package/dist/esm/elements/index.js.map +2 -2
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils/Utils.js +74 -37
  53. package/dist/esm/utils/Utils.js.map +3 -3
  54. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1047 -140
  55. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  56. package/dist/types/decorators/addEventListener.d.ts +1 -0
  57. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  58. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  59. package/dist/types/decorators/query.d.ts +0 -2
  60. package/dist/types/decorators/query.d.ts.map +1 -1
  61. package/dist/types/decorators/queryAll.d.ts +0 -2
  62. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  63. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  64. package/dist/types/elements/SwcAsync.d.ts +16 -0
  65. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  66. package/dist/types/elements/SwcChoose.d.ts +13 -0
  67. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  68. package/dist/types/elements/SwcIf.d.ts +15 -0
  69. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  70. package/dist/types/elements/SwcLoop.d.ts +20 -0
  71. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  72. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  73. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  74. package/dist/types/elements/index.d.ts +7 -0
  75. package/dist/types/elements/index.d.ts.map +1 -1
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/types.d.ts +8 -0
  79. package/dist/types/types.d.ts.map +1 -1
  80. package/dist/types/utils/Utils.d.ts +16 -10
  81. package/dist/types/utils/Utils.d.ts.map +1 -1
  82. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1047 -140
  83. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  84. package/package.json +10 -3
  85. package/src/decorators/addEventListener.ts +1 -0
  86. package/src/decorators/elementDefine.ts +137 -66
  87. package/src/decorators/query.ts +20 -2
  88. package/src/decorators/queryAll.ts +16 -2
  89. package/src/elements/SwcAppEngine.ts +2 -1
  90. package/src/elements/SwcAsync.ts +163 -0
  91. package/src/elements/SwcChoose.ts +127 -0
  92. package/src/elements/SwcIf.ts +134 -0
  93. package/src/elements/SwcLoop.ts +215 -0
  94. package/src/elements/SwcSubTemplates.ts +19 -0
  95. package/src/elements/index.ts +8 -3
  96. package/src/index.ts +1 -1
  97. package/src/types.ts +9 -1
  98. package/src/utils/Utils.ts +86 -36
@@ -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 class SwcUtils {
7
- static getValueByPath(obj: any, path: string, rootName: string) {
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
- static findNearestSwcHost(el: HTMLElement | Node): HTMLElement | undefined {
21
- let current: any = el instanceof Node && !(el instanceof HTMLElement) ? (el as any).host : el;
22
- current = current?.parentElement || (current?.getRootNode() as any)?.host;
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
- while (current) {
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?.getRootNode() as any)?.host;
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
- static findAllSwcHosts(el: HTMLElement | Node): HTMLElement[] {
59
+ export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {
35
60
  const hosts: HTMLElement[] = [];
36
- let current = this.findNearestSwcHost(el);
61
+ let current = findNearestSwcHost(el);
37
62
  while (current) {
38
63
  hosts.push(current);
39
- current = this.findNearestSwcHost(current);
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
- static getHosts(el: HTMLElement): HTMLElement[] {
45
- return [...this.findAllSwcHosts(el), el];
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
- static getHost(el: HTMLElement): HTMLElement | undefined {
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
- static getAppHosts(el: HTMLElement): SwcAppInterface[] {
53
- const hosts = this.getHosts(el);
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
- static getAppHost(el: HTMLElement): SwcAppInterface | undefined {
58
- const appHosts = this.getAppHosts(el);
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
- static getHostSet(el: HTMLElement): HostSet {
65
- const ancestors = this.findAllSwcHosts(el); // [root, ..., parent]
66
- const $host = el;
67
- const $hosts = [...ancestors, $host]; // [root, ..., parent, self]
68
- const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
69
- const $firstHost = ancestors.length > 0 ? ancestors[0] : null;
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
  }