@dooboostore/simple-web-component 1.0.16 → 1.0.18

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 (130) hide show
  1. package/README.md +109 -48
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/appendChild.js +48 -0
  4. package/dist/cjs/decorators/appendChild.js.map +7 -0
  5. package/dist/cjs/decorators/elementDefine.js +216 -67
  6. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  7. package/dist/cjs/decorators/index.js +2 -1
  8. package/dist/cjs/decorators/index.js.map +2 -2
  9. package/dist/cjs/decorators/{innerHtml.js → onConnectedInnerHtml.js} +8 -8
  10. package/dist/cjs/decorators/onConnectedInnerHtml.js.map +7 -0
  11. package/dist/cjs/decorators/query.js +38 -0
  12. package/dist/cjs/decorators/query.js.map +2 -2
  13. package/dist/cjs/decorators/queryAll.js +32 -0
  14. package/dist/cjs/decorators/queryAll.js.map +2 -2
  15. package/dist/cjs/decorators/replaceChildren.js +53 -0
  16. package/dist/cjs/decorators/replaceChildren.js.map +7 -0
  17. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  18. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  19. package/dist/cjs/elements/SwcAsync.js +188 -0
  20. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  21. package/dist/cjs/elements/SwcChoose.js +155 -0
  22. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  23. package/dist/cjs/elements/SwcIf.js +167 -0
  24. package/dist/cjs/elements/SwcIf.js.map +7 -0
  25. package/dist/cjs/elements/SwcLoop.js +246 -0
  26. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  27. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  28. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  29. package/dist/cjs/elements/index.js +7 -0
  30. package/dist/cjs/elements/index.js.map +2 -2
  31. package/dist/cjs/index.js +12 -2
  32. package/dist/cjs/index.js.map +2 -2
  33. package/dist/cjs/types.js.map +1 -1
  34. package/dist/cjs/utils/Utils.js +74 -37
  35. package/dist/cjs/utils/Utils.js.map +3 -3
  36. package/dist/esm/decorators/addEventListener.js.map +2 -2
  37. package/dist/esm/decorators/appendChild.js +29 -0
  38. package/dist/esm/decorators/appendChild.js.map +7 -0
  39. package/dist/esm/decorators/elementDefine.js +216 -67
  40. package/dist/esm/decorators/elementDefine.js.map +3 -3
  41. package/dist/esm/decorators/index.js +2 -1
  42. package/dist/esm/decorators/index.js.map +2 -2
  43. package/dist/esm/decorators/{innerHtml.js → onConnectedInnerHtml.js} +5 -5
  44. package/dist/esm/decorators/onConnectedInnerHtml.js.map +7 -0
  45. package/dist/esm/decorators/query.js +38 -0
  46. package/dist/esm/decorators/query.js.map +2 -2
  47. package/dist/esm/decorators/queryAll.js +32 -0
  48. package/dist/esm/decorators/queryAll.js.map +2 -2
  49. package/dist/esm/decorators/replaceChildren.js +34 -0
  50. package/dist/esm/decorators/replaceChildren.js.map +7 -0
  51. package/dist/esm/elements/SwcAppEngine.js +2 -1
  52. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  53. package/dist/esm/elements/SwcAsync.js +169 -0
  54. package/dist/esm/elements/SwcAsync.js.map +7 -0
  55. package/dist/esm/elements/SwcChoose.js +136 -0
  56. package/dist/esm/elements/SwcChoose.js.map +7 -0
  57. package/dist/esm/elements/SwcIf.js +148 -0
  58. package/dist/esm/elements/SwcIf.js.map +7 -0
  59. package/dist/esm/elements/SwcLoop.js +227 -0
  60. package/dist/esm/elements/SwcLoop.js.map +7 -0
  61. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  62. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  63. package/dist/esm/elements/index.js +7 -0
  64. package/dist/esm/elements/index.js.map +2 -2
  65. package/dist/esm/index.js +8 -2
  66. package/dist/esm/index.js.map +2 -2
  67. package/dist/esm/types.js.map +1 -1
  68. package/dist/esm/utils/Utils.js +74 -37
  69. package/dist/esm/utils/Utils.js.map +3 -3
  70. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1226 -149
  71. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  72. package/dist/types/decorators/addEventListener.d.ts +1 -0
  73. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  74. package/dist/types/decorators/appendChild.d.ts +17 -0
  75. package/dist/types/decorators/appendChild.d.ts.map +1 -0
  76. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  77. package/dist/types/decorators/index.d.ts +2 -1
  78. package/dist/types/decorators/index.d.ts.map +1 -1
  79. package/dist/types/decorators/onConnectedInnerHtml.d.ts +15 -0
  80. package/dist/types/decorators/onConnectedInnerHtml.d.ts.map +1 -0
  81. package/dist/types/decorators/query.d.ts +0 -2
  82. package/dist/types/decorators/query.d.ts.map +1 -1
  83. package/dist/types/decorators/queryAll.d.ts +0 -2
  84. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  85. package/dist/types/decorators/replaceChildren.d.ts +9 -0
  86. package/dist/types/decorators/replaceChildren.d.ts.map +1 -0
  87. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  88. package/dist/types/elements/SwcAsync.d.ts +16 -0
  89. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  90. package/dist/types/elements/SwcChoose.d.ts +13 -0
  91. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  92. package/dist/types/elements/SwcIf.d.ts +15 -0
  93. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  94. package/dist/types/elements/SwcLoop.d.ts +20 -0
  95. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  96. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  97. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  98. package/dist/types/elements/index.d.ts +7 -0
  99. package/dist/types/elements/index.d.ts.map +1 -1
  100. package/dist/types/index.d.ts +5 -2
  101. package/dist/types/index.d.ts.map +1 -1
  102. package/dist/types/types.d.ts +8 -0
  103. package/dist/types/types.d.ts.map +1 -1
  104. package/dist/types/utils/Utils.d.ts +16 -10
  105. package/dist/types/utils/Utils.d.ts.map +1 -1
  106. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1226 -149
  107. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  108. package/package.json +10 -3
  109. package/src/decorators/addEventListener.ts +1 -0
  110. package/src/decorators/appendChild.ts +42 -0
  111. package/src/decorators/elementDefine.ts +225 -71
  112. package/src/decorators/index.ts +2 -1
  113. package/src/decorators/{innerHtml.ts → onConnectedInnerHtml.ts} +7 -6
  114. package/src/decorators/query.ts +32 -2
  115. package/src/decorators/queryAll.ts +32 -2
  116. package/src/decorators/replaceChildren.ts +35 -0
  117. package/src/elements/SwcAppEngine.ts +2 -1
  118. package/src/elements/SwcAsync.ts +163 -0
  119. package/src/elements/SwcChoose.ts +127 -0
  120. package/src/elements/SwcIf.ts +134 -0
  121. package/src/elements/SwcLoop.ts +215 -0
  122. package/src/elements/SwcSubTemplates.ts +19 -0
  123. package/src/elements/index.ts +8 -3
  124. package/src/index.ts +5 -2
  125. package/src/types.ts +9 -1
  126. package/src/utils/Utils.ts +86 -36
  127. package/dist/cjs/decorators/innerHtml.js.map +0 -7
  128. package/dist/esm/decorators/innerHtml.js.map +0 -7
  129. package/dist/types/decorators/innerHtml.d.ts +0 -12
  130. package/dist/types/decorators/innerHtml.d.ts.map +0 -1
@@ -23,8 +23,27 @@ __export(Utils_exports, {
23
23
  module.exports = __toCommonJS(Utils_exports);
24
24
  var import_elementDefine = require("../decorators/elementDefine");
25
25
  const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
26
- class SwcUtils {
27
- static getValueByPath(obj, path, rootName) {
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) => {
28
47
  if (!obj || !path) return SWC_NOT_FOUND;
29
48
  const parts = path.split(".");
30
49
  let current = obj;
@@ -33,49 +52,66 @@ class SwcUtils {
33
52
  current = current[part];
34
53
  }
35
54
  return current;
36
- }
37
- static findNearestSwcHost(el) {
38
- let current = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
39
- current = current?.parentElement || current?.getRootNode()?.host;
40
- while (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;
41
61
  if ((0, import_elementDefine.getElementConfig)(current)) return current;
42
- current = current.parentElement || current?.getRootNode()?.host;
62
+ current = current.parentElement || current.getRootNode?.()?.host;
43
63
  }
44
64
  return void 0;
45
- }
46
- /**
47
- * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
48
- */
49
- static findAllSwcHosts(el) {
65
+ };
66
+ SwcUtils2.findAllSwcHosts = (el) => {
50
67
  const hosts = [];
51
- let current = this.findNearestSwcHost(el);
68
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
52
69
  while (current) {
53
70
  hosts.push(current);
54
- current = this.findNearestSwcHost(current);
71
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
55
72
  }
56
73
  return hosts.reverse();
57
- }
58
- static getHosts(el) {
59
- return [...this.findAllSwcHosts(el), el];
60
- }
61
- static getHost(el) {
62
- return el;
63
- }
64
- static getAppHosts(el) {
65
- 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);
66
86
  return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
67
- }
68
- static getAppHost(el) {
69
- const appHosts = this.getAppHosts(el);
87
+ };
88
+ SwcUtils2.getAppHost = (el) => {
89
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
70
90
  const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
71
91
  return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
72
- }
73
- static getHostSet(el) {
74
- const ancestors = this.findAllSwcHosts(el);
75
- const $host = el;
76
- const $hosts = [...ancestors, $host];
77
- const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
78
- const $firstHost = ancestors.length > 0 ? ancestors[0] : null;
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
+ }
79
115
  const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
80
116
  const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
81
117
  const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
@@ -88,8 +124,9 @@ class SwcUtils {
88
124
  $appHost,
89
125
  $appHosts,
90
126
  $firstAppHost,
91
- $lastAppHost: $appHost
127
+ $lastAppHost: $appHost,
128
+ ...loopContext
92
129
  };
93
- }
94
- }
130
+ };
131
+ })(SwcUtils || (SwcUtils = {}));
95
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 { SwcAppInterface, HostSet } from '../types';\nimport { getElementConfig } from '../decorators/elementDefine';\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport class SwcUtils {\n static 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 static findNearestSwcHost(el: HTMLElement | Node): HTMLElement | undefined {\n let current: any = el instanceof Node && !(el instanceof HTMLElement) ? (el as any).host : el;\n current = current?.parentElement || (current?.getRootNode() as any)?.host;\n\n while (current) {\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 static findAllSwcHosts(el: HTMLElement | Node): HTMLElement[] {\n const hosts: HTMLElement[] = [];\n let current = this.findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n current = this.findNearestSwcHost(current);\n }\n return hosts.reverse();\n }\n\n static getHosts(el: HTMLElement): HTMLElement[] {\n return [...this.findAllSwcHosts(el), el];\n }\n\n static getHost(el: HTMLElement): HTMLElement | undefined {\n return el;\n }\n\n static getAppHosts(el: HTMLElement): SwcAppInterface[] {\n const hosts = this.getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n }\n\n static getAppHost(el: HTMLElement): SwcAppInterface | undefined {\n const appHosts = this.getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n // Nearest app host is the last one in [root, ..., parent]\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n }\n\n static getHostSet(el: HTMLElement): HostSet {\n const ancestors = this.findAllSwcHosts(el); // [root, ..., parent]\n const $host = el;\n const $hosts = [...ancestors, $host]; // [root, ..., parent, self]\n const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n const $firstHost = ancestors.length > 0 ? ancestors[0] : null;\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 };\n }\n}\n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AAI,GAAG,WAAW,UAAU,CAAC;AAAA,EACzH;AAAA,EAEA,OAAO,WAAW,IAA8C;AAC9D,UAAM,WAAW,KAAK,YAAY,EAAE;AACpC,UAAM,sBAAsB,SAAS,OAAO,OAAK,MAAM,EAAE;AAEzD,WAAO,oBAAoB,SAAS,IAAI,oBAAoB,oBAAoB,SAAS,CAAC,IAAI;AAAA,EAChG;AAAA,EAEA,OAAO,WAAW,IAA0B;AAC1C,UAAM,YAAY,KAAK,gBAAgB,EAAE;AACzC,UAAM,QAAQ;AACd,UAAM,SAAS,CAAC,GAAG,WAAW,KAAK;AACnC,UAAM,cAAc,UAAU,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI;AAC7E,UAAM,aAAa,UAAU,SAAS,IAAI,UAAU,CAAC,IAAI;AAEzD,UAAM,YAAY,OAAO,OAAO,OAAK,EAAE,QAAQ,YAAY,MAAM,aAAa,EAAE,aAAa,IAAI,GAAG,WAAW,UAAU,CAAC;AAC1H,UAAM,WAAW,UAAU,SAAS,IAAK,UAAU,UAAU,SAAS,CAAC,MAAM,KAAM,UAAU,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI,OAAQ,UAAU,UAAU,SAAS,CAAC,IAAK;AACvL,UAAM,gBAAgB,UAAU,SAAS,IAAI,UAAU,CAAC,IAAI;AAE5D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAChB;AAAA,EACF;AACF;",
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;A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,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI;AACjE,oBAAc,UAAU,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI;AAAA,IACzE;AAEA,UAAM,SAAS,QAAQ,CAAC,GAAG,WAAW,EAAE,IAAI;AAC5C,UAAM,aAAa,OAAO,SAAS,IAAI,OAAO,CAAC,IAAI;AAGnD,UAAM,cAAmC,CAAC;AAC1C,QAAI,OAAY;AAChB,WAAO,QAAQ,SAAS,SAAS,iBAAiB;AAChD,UAAI,KAAK,oBAAoB;AAC3B,eAAO,OAAO,aAAa,KAAK,kBAAkB;AAAA,MACpD;AACA,aAAO,KAAK,iBAAkB,KAAK,YAAY,EAAU;AAAA,IAC3D;AAEA,UAAM,YAAY,OAAO,OAAO,OAAK,EAAE,QAAQ,YAAY,MAAM,aAAa,EAAE,aAAa,IAAI,GAAG,WAAW,UAAU,CAAC;AAC1H,UAAM,WAAW,UAAU,SAAS,IAAK,UAAU,UAAU,SAAS,CAAC,MAAM,KAAM,UAAU,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI,OAAQ,UAAU,UAAU,SAAS,CAAC,IAAK;AACvL,UAAM,gBAAgB,UAAU,SAAS,IAAI,UAAU,CAAC,IAAI;AAE5D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,GAAG;AAAA,IACL;AAAA,EACF;AAAA,GAlIe;",
6
+ "names": ["SwcUtils"]
7
7
  }
@@ -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 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}\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;AAoBtB,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;",
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
  }
@@ -0,0 +1,29 @@
1
+ import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
2
+ const APPEND_CHILD_METADATA_KEY = Symbol("simple-web-component:append-child");
3
+ function appendChild(selector, options = { position: "lastChild" }) {
4
+ return (target, propertyKey) => {
5
+ const constructor = target.constructor;
6
+ let meta = ReflectUtils.getOwnMetadata(APPEND_CHILD_METADATA_KEY, constructor);
7
+ if (!meta) {
8
+ meta = /* @__PURE__ */ new Map();
9
+ ReflectUtils.defineMetadata(APPEND_CHILD_METADATA_KEY, meta, constructor);
10
+ }
11
+ meta.set(propertyKey, { propertyKey, selector, options });
12
+ };
13
+ }
14
+ const findAllAppendChildMetadata = (target) => {
15
+ const result = /* @__PURE__ */ new Map();
16
+ const maps = ReflectUtils.findAllMetadata(APPEND_CHILD_METADATA_KEY, target);
17
+ maps.forEach((map) => {
18
+ if (map instanceof Map) {
19
+ map.forEach((v, k) => result.set(k, v));
20
+ }
21
+ });
22
+ return result;
23
+ };
24
+ export {
25
+ APPEND_CHILD_METADATA_KEY,
26
+ appendChild,
27
+ findAllAppendChildMetadata
28
+ };
29
+ //# sourceMappingURL=appendChild.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/decorators/appendChild.ts"],
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport type AppendChildPosition = 'firstChild' | 'lastChild' | 'nextSibling' | 'previousSibling';\n\nexport interface AppendChildOptions {\n position?: AppendChildPosition;\n}\n\nexport interface AppendChildMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: AppendChildOptions;\n}\n\nexport const APPEND_CHILD_METADATA_KEY = Symbol('simple-web-component:append-child');\n\n/**\n * @appendChild decorator to surgically add nodes to a target element.\n * Usage: @appendChild('#list') addItem() { return '<li>New Item</li>'; }\n */\nexport function appendChild(selector: string, options: AppendChildOptions = { position: 'lastChild' }): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getOwnMetadata(APPEND_CHILD_METADATA_KEY, constructor) as Map<string | symbol, AppendChildMetadata>;\n if (!meta) {\n meta = new Map<string | symbol, AppendChildMetadata>();\n ReflectUtils.defineMetadata(APPEND_CHILD_METADATA_KEY, meta, constructor);\n }\n meta.set(propertyKey, { propertyKey, selector, options });\n };\n}\n\nexport const findAllAppendChildMetadata = (target: any): Map<string | symbol, AppendChildMetadata> => {\n const result = new Map<string | symbol, AppendChildMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, AppendChildMetadata>>(APPEND_CHILD_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;AActB,MAAM,4BAA4B,OAAO,mCAAmC;AAM5E,SAAS,YAAY,UAAkB,UAA8B,EAAE,UAAU,YAAY,GAAoB;AACtH,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,aAAa,eAAe,2BAA2B,WAAW;AAC7E,QAAI,CAAC,MAAM;AACT,aAAO,oBAAI,IAA0C;AACrD,mBAAa,eAAe,2BAA2B,MAAM,WAAW;AAAA,IAC1E;AACA,SAAK,IAAI,aAAa,EAAE,aAAa,UAAU,QAAQ,CAAC;AAAA,EAC1D;AACF;AAEO,MAAM,6BAA6B,CAAC,WAA2D;AACpG,QAAM,SAAS,oBAAI,IAA0C;AAC7D,QAAM,OAAO,aAAa,gBAA2D,2BAA2B,MAAM;AACtH,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,15 +1,19 @@
1
1
  import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
2
- import { getInnerHtmlMetadataList } from "./innerHtml.js";
2
+ import { FunctionUtils } from "@dooboostore/core/function/FunctionUtils";
3
+ import { getOnConnectedInnerHtmlMetadata } from "./onConnectedInnerHtml.js";
3
4
  import { getAddEventListenerMetadata } from "./addEventListener.js";
4
5
  import { 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 } from "./lifecycles.js";
5
6
  import { getEmitCustomEventMetadataList } from "./emitCustomEvent.js";
6
7
  import { findAllAttributeChangedMetadata } from "./changedAttribute.js";
7
8
  import { findAllSetAttributeMetadata } from "./setAttribute.js";
9
+ import { findAllReplaceChildrenMetadata } from "./replaceChildren.js";
10
+ import { findAllAppendChildMetadata } from "./appendChild.js";
8
11
  import { SwcUtils } from "../utils/Utils.js";
9
12
  import { HTML_TAG_ENTRIES, DOM_EVENT_NAMES } from "../config/config.js";
10
13
  import { SituationTypeContainer, SituationTypeContainers } from "@dooboostore/simple-boot/decorators/inject/Inject";
11
14
  import { InjectSituationType } from "../types.js";
12
15
  const ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
16
+ const globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
13
17
  function buildEnv(configWindow) {
14
18
  const win = configWindow || (typeof window !== "undefined" ? window : void 0);
15
19
  const doc = win?.document;
@@ -18,13 +22,7 @@ function buildEnv(configWindow) {
18
22
  if (win?.[cls])
19
23
  builtInTagMap.set(win[cls], tag);
20
24
  }
21
- const domHelpers = {
22
- $d: doc,
23
- $w: win,
24
- $q: (sel, root) => (root ?? doc).querySelector(sel),
25
- $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
26
- $qi: (id, root) => (root ?? doc).getElementById(id)
27
- };
25
+ const domHelpers = SwcUtils.getHelperSet(win);
28
26
  return { win, doc, builtInTagMap, domHelpers };
29
27
  }
30
28
  const getHandlers = (inst) => {
@@ -36,8 +34,6 @@ const elementDefine = (inConfig) => (constructor) => {
36
34
  const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
37
35
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
38
36
  config.window = win;
39
- const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
40
- const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
41
37
  let extendsTagName = config.extends;
42
38
  if (!extendsTagName) {
43
39
  let proto = constructor;
@@ -53,19 +49,19 @@ const elementDefine = (inConfig) => (constructor) => {
53
49
  const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
54
50
  const attrChangeMap = findAllAttributeChangedMetadata(constructor);
55
51
  const setAttrMap = findAllSetAttributeMetadata(constructor);
52
+ const replaceChildrenMap = findAllReplaceChildrenMetadata(constructor);
53
+ const appendChildMap = findAllAppendChildMetadata(constructor);
56
54
  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"];
57
55
  const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
58
56
  const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...attrChangeMap.keys(), ...setAttrMap.keys(), ...emitCustomEventList.map((it) => it.options.attributeName), ...swcLifecycleAttributes, ...swcOnEvents])];
59
- const innerHtmlList = getInnerHtmlMetadataList(constructor) || [];
57
+ const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
60
58
  const NewClass = class extends constructor {
61
59
  _executeSwcScript(attrName, hostSet, extraArgs = {}) {
62
60
  const script = this.getAttribute(attrName);
63
61
  if (script) {
64
62
  try {
65
63
  const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
66
- const argNames = Object.keys(args);
67
- const argValues = Object.values(args);
68
- new Function(...argNames, script).apply(this, argValues);
64
+ FunctionUtils.execute({ script, context: this, args });
69
65
  } catch (e) {
70
66
  console.error(`[SWC] Failed to execute ${attrName}:`, e);
71
67
  }
@@ -107,9 +103,13 @@ const elementDefine = (inConfig) => (constructor) => {
107
103
  el.removeEventListener(eventName, oldHandler);
108
104
  const handler = (event) => {
109
105
  const hostSet = SwcUtils.getHostSet(el);
110
- const argNames = Object.keys(hostSet);
111
- const argValues = Object.values(hostSet);
112
- new Function("event", "$data", ...argNames, ...SWC_DOM_HELPER_KEYS, script).call(el, event, event.detail, ...argValues, ...SWC_DOM_HELPER_VALS());
106
+ const args = {
107
+ event,
108
+ $data: event.detail,
109
+ ...hostSet,
110
+ ...SWC_DOM_HELPERS
111
+ };
112
+ FunctionUtils.execute({ script, context: el, args });
113
113
  };
114
114
  el.addEventListener(eventName, handler);
115
115
  handlers.set(attrName, handler);
@@ -118,9 +118,10 @@ const elementDefine = (inConfig) => (constructor) => {
118
118
  super(...args);
119
119
  this._swcId = Math.random().toString(36).substring(2, 11);
120
120
  this._emitHandlers = /* @__PURE__ */ new Map();
121
+ this._boundListeners = [];
121
122
  const hostSet = SwcUtils.getHostSet(this);
122
123
  this._executeSwcScript("swc-on-constructor", hostSet);
123
- if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
124
+ if (connectedInnerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
124
125
  this.attachShadow({ mode: "open" });
125
126
  }
126
127
  }
@@ -128,6 +129,9 @@ const elementDefine = (inConfig) => (constructor) => {
128
129
  return mergedObservedAttributes;
129
130
  }
130
131
  async connectedCallback() {
132
+ const conf = getElementConfig(this);
133
+ const currentWin = conf?.window || window;
134
+ const currentDoc = currentWin.document;
131
135
  const hostSet = SwcUtils.getHostSet(this);
132
136
  this._executeSwcScript("swc-on-before-connected", hostSet);
133
137
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
@@ -137,9 +141,9 @@ const elementDefine = (inConfig) => (constructor) => {
137
141
  }
138
142
  if (typeof this.initCore === "function")
139
143
  this.initCore();
140
- if (innerHtmlList.length > 0) {
144
+ if (connectedInnerHtmlList.length > 0) {
141
145
  let sContent = "", lContent = "";
142
- for (const meta of innerHtmlList) {
146
+ for (const meta of connectedInnerHtmlList) {
143
147
  const res = await this[meta.propertyKey]();
144
148
  if (res !== void 0) {
145
149
  if (meta.options.useShadow)
@@ -153,17 +157,88 @@ const elementDefine = (inConfig) => (constructor) => {
153
157
  if (lContent)
154
158
  this.innerHTML = lContent;
155
159
  }
160
+ const createDelegationHandler = (delegateHost) => (event) => {
161
+ if (event.__swc_handled)
162
+ return;
163
+ const path = event.composedPath();
164
+ const type = event.type;
165
+ const attrName = `swc-on-${type}`;
166
+ for (const node of path) {
167
+ if (node === delegateHost)
168
+ break;
169
+ if (!(node instanceof HTMLElement))
170
+ continue;
171
+ const script = node.getAttribute?.(attrName);
172
+ if (script && !getElementConfig(node)) {
173
+ const host = SwcUtils.findNearestSwcHost(node);
174
+ if (host) {
175
+ const childHostSet = SwcUtils.getHostSet(node);
176
+ const args = {
177
+ event,
178
+ $data: event.detail,
179
+ ...childHostSet,
180
+ ...SWC_DOM_HELPERS
181
+ };
182
+ FunctionUtils.execute({ script, context: node, args });
183
+ event.__swc_handled = true;
184
+ break;
185
+ }
186
+ }
187
+ }
188
+ };
189
+ DOM_EVENT_NAMES.forEach((type) => {
190
+ const handler = createDelegationHandler(this);
191
+ this.addEventListener(type, handler);
192
+ this._boundListeners.push({ target: this, type, handler });
193
+ });
194
+ const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
195
+ if (!hasParentHost) {
196
+ const root = this.getRootNode();
197
+ if (!globalDelegatedRoots.has(root)) {
198
+ DOM_EVENT_NAMES.forEach((type) => {
199
+ const handler = createDelegationHandler(root);
200
+ root.addEventListener(type, handler);
201
+ });
202
+ globalDelegatedRoots.add(root);
203
+ }
204
+ }
156
205
  addEventListenerList.forEach((meta) => {
157
206
  const { selector, type, options } = meta;
158
- const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
159
- if (delegate && selector && selector !== ":host") {
207
+ const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
208
+ const opts = { capture, once, passive };
209
+ const bindTargets = [];
210
+ if (selector === ":window") {
211
+ bindTargets.push(currentWin);
212
+ } else if (selector === ":document") {
213
+ bindTargets.push(currentDoc);
214
+ } else if (selector === ":parentHost") {
215
+ if (hostSet.$parentHost)
216
+ bindTargets.push(hostSet.$parentHost);
217
+ } else if (selector === ":appHost") {
218
+ if (hostSet.$appHost)
219
+ bindTargets.push(hostSet.$appHost);
220
+ } else if (selector === ":firstHost") {
221
+ if (hostSet.$firstHost)
222
+ bindTargets.push(hostSet.$firstHost);
223
+ } else if (selector === ":lastHost") {
224
+ if (hostSet.$lastHost)
225
+ bindTargets.push(hostSet.$lastHost);
226
+ } else if (selector === ":firstAppHost") {
227
+ if (hostSet.$firstAppHost)
228
+ bindTargets.push(hostSet.$firstAppHost);
229
+ } else if (selector === ":lastAppHost") {
230
+ if (hostSet.$lastAppHost)
231
+ bindTargets.push(hostSet.$lastAppHost);
232
+ } else if (!selector || selector === ":host") {
233
+ bindTargets.push(this);
234
+ } else if (delegate) {
160
235
  const bindRoots = [];
161
236
  const r = root || "auto";
162
- if (r === "auto") {
237
+ if (r === "auto")
163
238
  bindRoots.push(this.shadowRoot || this);
164
- } else if (r === "light") {
239
+ else if (r === "light")
165
240
  bindRoots.push(this);
166
- } else if (r === "shadow") {
241
+ else if (r === "shadow") {
167
242
  if (this.shadowRoot)
168
243
  bindRoots.push(this.shadowRoot);
169
244
  } else if (r === "all") {
@@ -171,62 +246,61 @@ const elementDefine = (inConfig) => (constructor) => {
171
246
  if (this.shadowRoot)
172
247
  bindRoots.push(this.shadowRoot);
173
248
  }
174
- bindRoots.forEach((bindRoot) => {
249
+ bindRoots.forEach((br) => {
175
250
  const handler = (event) => {
176
- const target = event.target;
177
- const matchedEl = target.closest(selector);
178
- if (matchedEl && bindRoot.contains(matchedEl)) {
251
+ const matchedEl = event.target.closest(selector);
252
+ if (matchedEl && br.contains(matchedEl)) {
179
253
  if (stopPropagation)
180
254
  event.stopPropagation();
181
255
  if (stopImmediatePropagation)
182
256
  event.stopImmediatePropagation();
183
257
  if (preventDefault)
184
258
  event.preventDefault();
185
- const hostSet2 = SwcUtils.getHostSet(this);
186
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2, matchedEl]);
259
+ const currentHostSet = SwcUtils.getHostSet(this);
260
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
187
261
  }
188
262
  };
189
- bindRoot.addEventListener(type, handler, { capture, once, passive });
263
+ br.addEventListener(type, handler, opts);
264
+ const self = this;
265
+ if (removeOnDisconnected === true || br !== self && br !== self.shadowRoot) {
266
+ this._boundListeners.push({ target: br, type, handler, options: opts });
267
+ }
190
268
  });
191
269
  } else {
192
- const targetEls = [];
193
- if (!selector || selector === ":host") {
194
- targetEls.push(this);
195
- } else {
196
- const searchRoots = [];
197
- const r = root || "auto";
198
- if (r === "auto") {
199
- searchRoots.push(this.shadowRoot || this);
200
- } else if (r === "light") {
201
- searchRoots.push(this);
202
- } else if (r === "shadow") {
203
- if (this.shadowRoot)
204
- searchRoots.push(this.shadowRoot);
205
- } else if (r === "all") {
206
- searchRoots.push(this);
207
- if (this.shadowRoot)
208
- searchRoots.push(this.shadowRoot);
209
- }
210
- searchRoots.forEach((sr) => {
211
- const found = sr.querySelectorAll(selector);
212
- found.forEach((el) => targetEls.push(el));
213
- });
270
+ const searchRoots = [];
271
+ const r = root || "auto";
272
+ if (r === "auto")
273
+ searchRoots.push(this.shadowRoot || this);
274
+ else if (r === "light")
275
+ searchRoots.push(this);
276
+ else if (r === "shadow") {
277
+ if (this.shadowRoot)
278
+ searchRoots.push(this.shadowRoot);
279
+ } else if (r === "all") {
280
+ searchRoots.push(this);
281
+ if (this.shadowRoot)
282
+ searchRoots.push(this.shadowRoot);
214
283
  }
215
- targetEls.forEach((el) => {
216
- const handler = (event) => {
217
- if (stopPropagation)
218
- event.stopPropagation();
219
- if (stopImmediatePropagation)
220
- event.stopImmediatePropagation();
221
- if (preventDefault)
222
- event.preventDefault();
223
- const hostSet2 = SwcUtils.getHostSet(this);
224
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
225
- };
226
- const opts = { capture, once, passive };
227
- el.addEventListener(type, handler, opts);
284
+ searchRoots.forEach((sr) => {
285
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
228
286
  });
229
287
  }
288
+ bindTargets.forEach((target) => {
289
+ const handler = (event) => {
290
+ if (stopPropagation)
291
+ event.stopPropagation();
292
+ if (stopImmediatePropagation)
293
+ event.stopImmediatePropagation();
294
+ if (preventDefault)
295
+ event.preventDefault();
296
+ const currentHostSet = SwcUtils.getHostSet(this);
297
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
298
+ };
299
+ target.addEventListener(type, handler, opts);
300
+ if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
301
+ this._boundListeners.push({ target, type, handler, options: opts });
302
+ }
303
+ });
230
304
  });
231
305
  if (super.connectedCallback)
232
306
  await super.connectedCallback();
@@ -244,6 +318,8 @@ const elementDefine = (inConfig) => (constructor) => {
244
318
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
245
319
  if (bMethods)
246
320
  bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
321
+ this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
322
+ this._boundListeners = [];
247
323
  if (super.disconnectedCallback)
248
324
  super.disconnectedCallback();
249
325
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -315,6 +391,79 @@ const elementDefine = (inConfig) => (constructor) => {
315
391
  };
316
392
  }
317
393
  });
394
+ replaceChildrenMap.forEach((selector, methodName) => {
395
+ const original = NewClass.prototype[methodName];
396
+ if (typeof original === "function") {
397
+ NewClass.prototype[methodName] = function(...args) {
398
+ const res = original.apply(this, args);
399
+ if (res !== void 0) {
400
+ const conf = getElementConfig(this);
401
+ const currentWin = conf?.window || window;
402
+ const currentDoc = currentWin.document;
403
+ let targetEl = null;
404
+ if (selector === ":host" || !selector) {
405
+ targetEl = this;
406
+ } else {
407
+ targetEl = (this.shadowRoot || this).querySelector(selector);
408
+ }
409
+ if (targetEl) {
410
+ const nodes = Array.isArray(res) ? res : [res];
411
+ const normalizedNodes = nodes.map((n) => {
412
+ if (typeof n === "string") {
413
+ const t = currentDoc.createElement("template");
414
+ t.innerHTML = n;
415
+ return t.content;
416
+ }
417
+ return n;
418
+ });
419
+ targetEl.replaceChildren(...normalizedNodes);
420
+ }
421
+ }
422
+ return res;
423
+ };
424
+ }
425
+ });
426
+ appendChildMap.forEach((meta, methodName) => {
427
+ const { selector, options } = meta;
428
+ const original = NewClass.prototype[methodName];
429
+ if (typeof original === "function") {
430
+ NewClass.prototype[methodName] = function(...args) {
431
+ const res = original.apply(this, args);
432
+ if (res !== void 0) {
433
+ const conf = getElementConfig(this);
434
+ const currentWin = conf?.window || window;
435
+ const currentDoc = currentWin.document;
436
+ let targetEl = null;
437
+ if (selector === ":host" || !selector) {
438
+ targetEl = this;
439
+ } else {
440
+ targetEl = (this.shadowRoot || this).querySelector(selector);
441
+ }
442
+ if (targetEl) {
443
+ const nodes = Array.isArray(res) ? res : [res];
444
+ const normalizedNodes = nodes.map((n) => {
445
+ if (typeof n === "string") {
446
+ const t = currentDoc.createElement("template");
447
+ t.innerHTML = n;
448
+ return t.content;
449
+ }
450
+ return n;
451
+ });
452
+ const pos = options.position || "lastChild";
453
+ if (pos === "lastChild")
454
+ targetEl.append(...normalizedNodes);
455
+ else if (pos === "firstChild")
456
+ targetEl.prepend(...normalizedNodes);
457
+ else if (pos === "nextSibling")
458
+ targetEl.after(...normalizedNodes);
459
+ else if (pos === "previousSibling")
460
+ targetEl.before(...normalizedNodes);
461
+ }
462
+ }
463
+ return res;
464
+ };
465
+ }
466
+ });
318
467
  const originalProto = constructor.prototype;
319
468
  const newProto = NewClass.prototype;
320
469
  Object.getOwnPropertyNames(originalProto).forEach((name) => {