@dooboostore/simple-web-component 1.0.34 → 1.0.36

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 (170) hide show
  1. package/README.md +44 -51
  2. package/dist/cjs/decorators/addEventListener.js +12 -4
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +19 -18
  5. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  6. package/dist/cjs/decorators/applyClass.js +23 -22
  7. package/dist/cjs/decorators/applyClass.js.map +2 -2
  8. package/dist/cjs/decorators/applyNode.js +22 -17
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applyStyle.js +20 -19
  11. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  12. package/dist/cjs/decorators/attribute.js +17 -16
  13. package/dist/cjs/decorators/attribute.js.map +2 -2
  14. package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
  15. package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
  16. package/dist/cjs/decorators/elementDefine.js +234 -188
  17. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  18. package/dist/cjs/decorators/emitCustomEvent.js +24 -16
  19. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  20. package/dist/cjs/decorators/index.js +1 -1
  21. package/dist/cjs/decorators/index.js.map +1 -1
  22. package/dist/cjs/decorators/lifecycles.js +15 -17
  23. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  24. package/dist/cjs/decorators/query.js +38 -60
  25. package/dist/cjs/decorators/query.js.map +2 -2
  26. package/dist/cjs/decorators/queryAll.js +31 -63
  27. package/dist/cjs/decorators/queryAll.js.map +2 -2
  28. package/dist/cjs/decorators/setProperty.js +13 -12
  29. package/dist/cjs/decorators/setProperty.js.map +2 -2
  30. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  31. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  32. package/dist/cjs/elements/SwcAppEngine.js +8 -2
  33. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  34. package/dist/cjs/elements/SwcAppMixin.js +120 -65
  35. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  36. package/dist/cjs/elements/SwcAsync.js +31 -21
  37. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  38. package/dist/cjs/elements/SwcChoose.js +53 -34
  39. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  40. package/dist/cjs/elements/SwcIf.js +54 -32
  41. package/dist/cjs/elements/SwcIf.js.map +2 -2
  42. package/dist/cjs/elements/SwcLoop.js +111 -37
  43. package/dist/cjs/elements/SwcLoop.js.map +2 -2
  44. package/dist/cjs/elements/register.js +249 -122
  45. package/dist/cjs/elements/register.js.map +2 -2
  46. package/dist/cjs/router/ElementRouter.js +4 -2
  47. package/dist/cjs/router/ElementRouter.js.map +1 -1
  48. package/dist/cjs/types.js.map +1 -1
  49. package/dist/cjs/utils/Utils.js +31 -17
  50. package/dist/cjs/utils/Utils.js.map +2 -2
  51. package/dist/esm/decorators/addEventListener.js +12 -4
  52. package/dist/esm/decorators/addEventListener.js.map +2 -2
  53. package/dist/esm/decorators/applyAttribute.js +19 -18
  54. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  55. package/dist/esm/decorators/applyClass.js +23 -22
  56. package/dist/esm/decorators/applyClass.js.map +2 -2
  57. package/dist/esm/decorators/applyNode.js +22 -17
  58. package/dist/esm/decorators/applyNode.js.map +2 -2
  59. package/dist/esm/decorators/applyStyle.js +20 -19
  60. package/dist/esm/decorators/applyStyle.js.map +2 -2
  61. package/dist/esm/decorators/attribute.js +17 -16
  62. package/dist/esm/decorators/attribute.js.map +2 -2
  63. package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
  64. package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
  65. package/dist/esm/decorators/elementDefine.js +233 -187
  66. package/dist/esm/decorators/elementDefine.js.map +2 -2
  67. package/dist/esm/decorators/emitCustomEvent.js +24 -16
  68. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  69. package/dist/esm/decorators/index.js +1 -1
  70. package/dist/esm/decorators/index.js.map +1 -1
  71. package/dist/esm/decorators/lifecycles.js +15 -17
  72. package/dist/esm/decorators/lifecycles.js.map +2 -2
  73. package/dist/esm/decorators/query.js +38 -60
  74. package/dist/esm/decorators/query.js.map +2 -2
  75. package/dist/esm/decorators/queryAll.js +31 -63
  76. package/dist/esm/decorators/queryAll.js.map +2 -2
  77. package/dist/esm/decorators/setProperty.js +13 -12
  78. package/dist/esm/decorators/setProperty.js.map +2 -2
  79. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  80. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  81. package/dist/esm/elements/SwcAppEngine.js +9 -2
  82. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  83. package/dist/esm/elements/SwcAppMixin.js +122 -66
  84. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  85. package/dist/esm/elements/SwcAsync.js +32 -22
  86. package/dist/esm/elements/SwcAsync.js.map +2 -2
  87. package/dist/esm/elements/SwcChoose.js +54 -35
  88. package/dist/esm/elements/SwcChoose.js.map +2 -2
  89. package/dist/esm/elements/SwcIf.js +55 -33
  90. package/dist/esm/elements/SwcIf.js.map +2 -2
  91. package/dist/esm/elements/SwcLoop.js +112 -38
  92. package/dist/esm/elements/SwcLoop.js.map +2 -2
  93. package/dist/esm/elements/register.js +250 -123
  94. package/dist/esm/elements/register.js.map +2 -2
  95. package/dist/esm/router/ElementRouter.js +5 -2
  96. package/dist/esm/router/ElementRouter.js.map +1 -1
  97. package/dist/esm/types.js.map +1 -1
  98. package/dist/esm/utils/Utils.js +31 -17
  99. package/dist/esm/utils/Utils.js.map +2 -2
  100. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
  101. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  102. package/dist/types/decorators/addEventListener.d.ts +5 -7
  103. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  104. package/dist/types/decorators/applyAttribute.d.ts +4 -4
  105. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  106. package/dist/types/decorators/applyClass.d.ts +6 -6
  107. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  108. package/dist/types/decorators/applyNode.d.ts +7 -6
  109. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  110. package/dist/types/decorators/applyStyle.d.ts +4 -4
  111. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  112. package/dist/types/decorators/attribute.d.ts +5 -5
  113. package/dist/types/decorators/attribute.d.ts.map +1 -1
  114. package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
  115. package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
  116. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  117. package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
  118. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  119. package/dist/types/decorators/index.d.ts +1 -1
  120. package/dist/types/decorators/lifecycles.d.ts +10 -7
  121. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  122. package/dist/types/decorators/query.d.ts +17 -63
  123. package/dist/types/decorators/query.d.ts.map +1 -1
  124. package/dist/types/decorators/queryAll.d.ts +6 -63
  125. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  126. package/dist/types/decorators/setProperty.d.ts +1 -1
  127. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  128. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
  129. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  130. package/dist/types/elements/SwcAppEngine.d.ts +4 -1
  131. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  132. package/dist/types/elements/SwcAppMixin.d.ts +11 -8
  133. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  134. package/dist/types/elements/register.d.ts.map +1 -1
  135. package/dist/types/types.d.ts +3 -2
  136. package/dist/types/types.d.ts.map +1 -1
  137. package/dist/types/utils/Utils.d.ts +11 -8
  138. package/dist/types/utils/Utils.d.ts.map +1 -1
  139. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
  140. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  141. package/package.json +3 -3
  142. package/src/decorators/addEventListener.ts +11 -9
  143. package/src/decorators/applyAttribute.ts +16 -15
  144. package/src/decorators/applyClass.ts +18 -17
  145. package/src/decorators/applyNode.ts +34 -21
  146. package/src/decorators/applyStyle.ts +17 -16
  147. package/src/decorators/attribute.ts +21 -20
  148. package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
  149. package/src/decorators/elementDefine.ts +402 -358
  150. package/src/decorators/emitCustomEvent.ts +40 -31
  151. package/src/decorators/index.ts +1 -1
  152. package/src/decorators/lifecycles.ts +11 -10
  153. package/src/decorators/query.ts +51 -124
  154. package/src/decorators/queryAll.ts +30 -127
  155. package/src/decorators/setProperty.ts +12 -11
  156. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
  157. package/src/elements/SwcAppEngine.ts +10 -3
  158. package/src/elements/SwcAppMixin.ts +177 -97
  159. package/src/elements/SwcAsync.ts +32 -21
  160. package/src/elements/SwcChoose.ts +74 -37
  161. package/src/elements/SwcIf.ts +60 -23
  162. package/src/elements/SwcLoop.ts +141 -28
  163. package/src/elements/register.ts +300 -102
  164. package/src/types.ts +6 -5
  165. package/src/utils/Utils.ts +40 -23
  166. package/tsconfig.json +2 -2
  167. package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
  168. package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
  169. package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
  170. package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
@@ -2,9 +2,9 @@ import { ReflectUtils, FunctionUtils, ActionExpression } from "@dooboostore/core
2
2
  import { getAddEventListenerMetadata } from "./addEventListener.js";
3
3
  import { ON_INITIALIZE_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata } from "./lifecycles.js";
4
4
  import { getEmitCustomEventMetadataList } from "./emitCustomEvent.js";
5
- import { findAllAttributeChangedMetadata, convertAttributeValue } from "./changedAttributeHost.js";
5
+ import { findAllAttributeChangedMetadata, convertAttributeValue } from "./changedAttributeThis.js";
6
6
  import { findAllAttributeApplyMetadata } from "./applyAttribute.js";
7
- import { findAllAttributeMetadata } from "./attribute.js";
7
+ import { findAllAttributeMetadata, getAttributeValue } from "./attribute.js";
8
8
  import { getQueryMetadata } from "./query.js";
9
9
  import { getQueryAllMetadata } from "./queryAll.js";
10
10
  import { SwcUtils } from "../utils/Utils.js";
@@ -41,7 +41,7 @@ const ensureInit = (inst) => {
41
41
  });
42
42
  }
43
43
  const hostSet = SwcUtils.getHostSet(inst);
44
- const appHosts = SwcUtils.findAllParentAppHostsDirect(inst);
44
+ const appHosts = SwcUtils.findAllAppHostsIncludingSelfDirect(inst);
45
45
  inst._executeSwcScript?.("swc-on-constructor", hostSet);
46
46
  const cMethods = findAllLifecycleMetadata(inst, ON_INITIALIZE_METADATA_KEY);
47
47
  if (cMethods) {
@@ -59,7 +59,7 @@ const handleGlobalSwcEvent = async (event) => {
59
59
  if (!(node instanceof HTMLElement)) continue;
60
60
  const script = node.getAttribute?.(attrName);
61
61
  if (script && !getElementConfig(node)) {
62
- const host = SwcUtils.findNearestSwcHost(node);
62
+ const host = SwcUtils.findNearestSwcHostIncludingSelf(node);
63
63
  if (host && host.isConnected && typeof host.__swc_executeAttributeEvent === "function") {
64
64
  await host.__swc_executeAttributeEvent(node, attrName, script, event);
65
65
  event.__swc_handled = true;
@@ -103,7 +103,7 @@ const setupPrototype = (proto) => {
103
103
  proto._resolveWindow = function(localConfig) {
104
104
  ensureInit(this);
105
105
  if (localConfig?.window) return localConfig.window;
106
- const ancestors = SwcUtils.findAllSwcHosts(this);
106
+ const ancestors = SwcUtils.findAllSwcHostsIncludingSelf(this);
107
107
  for (let i = ancestors.length - 1; i >= 0; i--) {
108
108
  const aConf = getElementConfig(ancestors[i]);
109
109
  if (aConf?.window) return aConf.window;
@@ -117,7 +117,13 @@ const setupPrototype = (proto) => {
117
117
  const app = useHostSet?.$appHost?.simpleApplication;
118
118
  if (app) {
119
119
  const otherStorage = /* @__PURE__ */ new Map();
120
- const situations = new SituationTypeContainers([new SituationTypeContainer({ situationType: InjectSituationType.HOST_SET, data: useHostSet }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOST, data: useHostSet.$appHost }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOSTS, data: useHostSet.$appHosts }), new SituationTypeContainer({ situationType: InjectSituationType.HOST, data: useHostSet.$host }), new SituationTypeContainer({ situationType: InjectSituationType.HOSTS, data: useHostSet.$hosts }), new SituationTypeContainer({ situationType: InjectSituationType.FIRST_HOST, data: useHostSet.$firstHost }), new SituationTypeContainer({ situationType: InjectSituationType.LAST_HOST, data: useHostSet.$lastHost }), new SituationTypeContainer({ situationType: InjectSituationType.FIRST_APP_HOST, data: useHostSet.$firstAppHost }), new SituationTypeContainer({ situationType: InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
120
+ const situations = new SituationTypeContainers([new SituationTypeContainer({ situationType: InjectSituationType.HOST_SET, data: useHostSet }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOST, data: useHostSet.$appHost }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOSTS, data: useHostSet.$appHosts }), new SituationTypeContainer({
121
+ situationType: InjectSituationType.HOST,
122
+ data: useHostSet.$host
123
+ }), new SituationTypeContainer({ situationType: InjectSituationType.HOSTS, data: useHostSet.$hosts }), new SituationTypeContainer({ situationType: InjectSituationType.FIRST_HOST, data: useHostSet.$firstHost }), new SituationTypeContainer({ situationType: InjectSituationType.LAST_HOST, data: useHostSet.$lastHost }), new SituationTypeContainer({
124
+ situationType: InjectSituationType.FIRST_APP_HOST,
125
+ data: useHostSet.$firstAppHost
126
+ }), new SituationTypeContainer({ situationType: InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
121
127
  otherStorage.set(SituationTypeContainers, situations);
122
128
  return app.simstanceManager.executeBindParameterSim(
123
129
  {
@@ -201,7 +207,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
201
207
  metadata.extends = extendsTagName;
202
208
  }
203
209
  const emitCustomEventList = getEmitCustomEventMetadataList(constructor) || [];
204
- const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === ":host" || meta.selector === "");
210
+ const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
205
211
  const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
206
212
  const attrChangeMap = findAllAttributeChangedMetadata(constructor);
207
213
  const attributeList = findAllAttributeMetadata(constructor);
@@ -209,204 +215,245 @@ const elementDefine = (name, config = {}) => (constructor) => {
209
215
  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"];
210
216
  const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
211
217
  const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.options.name).filter(Boolean);
212
- const hostAttributes = attributeList.filter((it) => it.selector === ":host").map((it) => it.options.name || String(it.propertyKey));
213
- const proto = constructor.prototype;
218
+ const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.options.name || String(it.propertyKey));
214
219
  const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
215
- const mergedObservedAttributes = [.../* @__PURE__ */ new Set([
216
- ...metadata.observedAttributes ?? [],
217
- ...originalStaticObservedAttributes,
218
- ...attrChangeMap.keys(),
219
- ...attributeApplyNames,
220
- ...hostAttributes,
221
- ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean),
222
- ...swcLifecycleAttributes,
223
- ...swcOnEvents
224
- ])];
220
+ const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
225
221
  const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
222
+ const proto = constructor.prototype;
226
223
  setupPrototype(proto);
224
+ let helperHostSet = null;
227
225
  const originalConnected = proto.connectedCallback;
228
- proto.connectedCallback = function() {
226
+ proto.connectedCallback = async function() {
229
227
  ensureInit(this);
230
- const hostSet = SwcUtils.getHostSet(this);
231
- const appHost = hostSet.$appHost;
232
- const conf = getElementConfig(this);
233
- const currentWin = this._resolveWindow(conf);
234
- const shadowMode = conf?.useShadow || connectedInnerHtmlList.find((it) => it.options.useShadow)?.options.useShadow;
235
- if (shadowMode && !this.shadowRoot) {
236
- const mode = shadowMode === true ? "open" : shadowMode;
237
- this.attachShadow({ mode });
238
- }
239
- this._executeSwcScript("swc-on-before-connected", hostSet);
240
- const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
241
- if (bMethods) {
242
- for (const m of bMethods) this._invokeLifecycleMethod(m, hostSet);
243
- }
244
- if (connectedInnerHtmlList.length > 0) {
245
- let sContent = "", lContent = "";
246
- for (const meta of connectedInnerHtmlList) {
247
- const res = this._invokeLifecycleMethod(meta.propertyKey, hostSet);
248
- if (res !== void 0) {
249
- if (meta.options.useShadow || conf?.useShadow) sContent += res;
250
- else lContent += res;
251
- }
228
+ helperHostSet = SwcUtils.getHelperAndHostSet(win, this);
229
+ const appHost = helperHostSet.$appHost;
230
+ try {
231
+ if (appHost && typeof appHost._connected === "function") {
232
+ await appHost._connected(this);
233
+ } else if (appHost && typeof appHost) {
234
+ appHost._connected_safari ?? (appHost._connected_safari = []);
235
+ appHost._connected_safari.push(this);
252
236
  }
253
- try {
254
- if (this.shadowRoot) this.shadowRoot.innerHTML = sContent;
255
- if (lContent) this.innerHTML = lContent;
256
- } catch (e) {
257
- console.error("[ElementDefine] innerHTML setting error:", e);
258
- }
259
- }
260
- const root = this.getRootNode();
261
- if (!globalDelegatedRoots.has(root)) {
262
- DOM_EVENT_NAMES.forEach((type) => {
263
- root.addEventListener(type, handleGlobalSwcEvent);
264
- });
265
- globalDelegatedRoots.add(root);
266
- }
267
- const delegateListeners = [];
268
- const nonDelegateListeners = [];
269
- addEventListenerList.forEach((meta) => {
270
- if (meta.options.delegate && meta.selector !== ":window" && meta.selector !== ":document" && meta.selector !== ":parentHost" && meta.selector !== ":appHost" && meta.selector !== ":firstHost" && meta.selector !== ":lastHost" && meta.selector !== ":firstAppHost" && meta.selector !== ":lastAppHost" && meta.selector !== ":hosts" && meta.selector !== ":appHosts" && meta.selector !== ":host" && meta.selector !== "") {
271
- delegateListeners.push(meta);
272
- } else {
273
- nonDelegateListeners.push(meta);
237
+ const conf = getElementConfig(this);
238
+ const currentWin = this._resolveWindow(conf);
239
+ const shadowMode = conf?.useShadow || connectedInnerHtmlList.find((it) => it.options.useShadow)?.options.useShadow;
240
+ if (shadowMode && !this.shadowRoot) {
241
+ const mode = shadowMode === true ? "open" : shadowMode;
242
+ this.attachShadow({ mode });
274
243
  }
275
- });
276
- const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
277
- delegateListeners.forEach((meta) => {
278
- const r = meta.options.root || "auto";
279
- const rootKey = `${meta.type}:${r}`;
280
- if (!delegatesByTypeAndRoot.has(rootKey)) {
281
- delegatesByTypeAndRoot.set(rootKey, []);
244
+ const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
245
+ if (bMethods) {
246
+ for (const m of bMethods) await this._invokeLifecycleMethod(m, helperHostSet);
282
247
  }
283
- delegatesByTypeAndRoot.get(rootKey).push(meta);
284
- });
285
- delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
286
- const [type, rStr] = typeRootKey.split(":");
287
- const r = rStr === "auto" ? "auto" : rStr;
288
- const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
289
- const bindRoots = [];
290
- if (r === "auto") bindRoots.push(this.shadowRoot || this);
291
- else if (r === "light") bindRoots.push(this);
292
- else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
293
- else if (r === "all") {
294
- bindRoots.push(this);
295
- if (this.shadowRoot) bindRoots.push(this.shadowRoot);
248
+ this._executeSwcScript("swc-on-before-connected", helperHostSet);
249
+ if (connectedInnerHtmlList.length > 0) {
250
+ let sContent = "", lContent = "";
251
+ for (const meta of connectedInnerHtmlList) {
252
+ let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
253
+ const actionExpression = new ActionExpression(res, {
254
+ expression: {
255
+ replace: {
256
+ start: meta.options.replaceWrap?.start || "{%{",
257
+ end: meta.options.replaceWrap?.end || "}%}"
258
+ },
259
+ callReturn: {
260
+ start: meta.options.replaceWrap?.start || "{%{=",
261
+ end: meta.options.replaceWrap?.end || "}%}"
262
+ },
263
+ call: {
264
+ start: meta.options.replaceWrap?.start || "{%{@",
265
+ end: meta.options.replaceWrap?.end || "}%}"
266
+ }
267
+ }
268
+ });
269
+ actionExpression.getExpressions().filter((it) => it.type === "replace").forEach((it) => {
270
+ try {
271
+ const sr = FunctionUtils.executeReturn({ script: it.script, context: this, args: helperHostSet });
272
+ actionExpression.replace(it, sr);
273
+ } catch (e) {
274
+ console.error(`[SWC] Failed to execute connectedInnerHTML:`, e);
275
+ }
276
+ });
277
+ res = actionExpression.getUnprocessedTemplate();
278
+ if (res !== void 0) {
279
+ if (meta.options.useShadow || conf?.useShadow) sContent += res;
280
+ else lContent += res;
281
+ }
282
+ }
283
+ try {
284
+ if (this.shadowRoot) {
285
+ this.shadowRoot.innerHTML = sContent;
286
+ }
287
+ if (lContent) {
288
+ this.innerHTML = lContent;
289
+ }
290
+ } catch (e) {
291
+ console.error("[ElementDefine] innerHTML setting error:", e);
292
+ }
296
293
  }
297
- bindRoots.forEach((br) => {
298
- const sortedMetaList = [...metaList].sort((a, b) => {
299
- const aStop = a.options.stopPropagation ? 1 : 0;
300
- const bStop = b.options.stopPropagation ? 1 : 0;
301
- return bStop - aStop;
294
+ const root = this.getRootNode();
295
+ if (!globalDelegatedRoots.has(root)) {
296
+ DOM_EVENT_NAMES.forEach((type) => {
297
+ root.addEventListener(type, handleGlobalSwcEvent);
302
298
  });
303
- const unifiedHandler = async (event) => {
304
- for (const meta of sortedMetaList) {
305
- const { selector, options } = meta;
306
- const matchedEl = event.target.closest(selector);
307
- if (matchedEl && br.contains(matchedEl)) {
308
- if (options.filter) {
309
- const helper = SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
310
- if (!options.filter(event, helper)) {
311
- continue;
299
+ globalDelegatedRoots.add(root);
300
+ }
301
+ const delegateListeners = [];
302
+ const nonDelegateListeners = [];
303
+ addEventListenerList.forEach((meta) => {
304
+ if (meta.options.delegate && meta.selector !== "$window" && meta.selector !== "$document" && meta.selector !== "$host" && meta.selector !== "$appHost" && meta.selector !== "$firstHost" && meta.selector !== "$lastHost" && meta.selector !== "$firstAppHost" && meta.selector !== "$lastAppHost" && meta.selector !== "$hosts" && meta.selector !== "$appHosts" && meta.selector !== "$this" && meta.selector !== "") {
305
+ delegateListeners.push(meta);
306
+ } else {
307
+ nonDelegateListeners.push(meta);
308
+ }
309
+ });
310
+ const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
311
+ delegateListeners.forEach((meta) => {
312
+ const r = meta.options.root || "auto";
313
+ const rootKey = `${meta.type}:${r}`;
314
+ if (!delegatesByTypeAndRoot.has(rootKey)) {
315
+ delegatesByTypeAndRoot.set(rootKey, []);
316
+ }
317
+ delegatesByTypeAndRoot.get(rootKey).push(meta);
318
+ });
319
+ delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
320
+ const [type, rStr] = typeRootKey.split(":");
321
+ const r = rStr === "auto" ? "auto" : rStr;
322
+ const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
323
+ const bindRoots = [];
324
+ if (r === "auto") bindRoots.push(this.shadowRoot || this);
325
+ else if (r === "light") bindRoots.push(this);
326
+ else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
327
+ else if (r === "all") {
328
+ bindRoots.push(this);
329
+ if (this.shadowRoot) bindRoots.push(this.shadowRoot);
330
+ }
331
+ bindRoots.forEach((br) => {
332
+ const sortedMetaList = [...metaList].sort((a, b) => {
333
+ const aStop = a.options.stopPropagation ? 1 : 0;
334
+ const bStop = b.options.stopPropagation ? 1 : 0;
335
+ return bStop - aStop;
336
+ });
337
+ const unifiedHandler = async (event) => {
338
+ for (const meta of sortedMetaList) {
339
+ const { selector, options } = meta;
340
+ const matchedEl = event.target.closest(selector);
341
+ if (matchedEl && br.contains(matchedEl)) {
342
+ if (options.filter) {
343
+ const helper = SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
344
+ if (!options.filter(event, helper)) {
345
+ continue;
346
+ }
312
347
  }
348
+ if (options.stopPropagation) event.stopPropagation();
349
+ if (options.stopImmediatePropagation) event.stopImmediatePropagation();
350
+ if (options.preventDefault) event.preventDefault();
351
+ const currentHostSet = SwcUtils.getHostSet(this);
352
+ const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
353
+ await this[meta.propertyKey](event, { ...currentHostSet, $matchedElement: matchedEl }, args);
354
+ if (event.cancelBubble) break;
313
355
  }
314
- if (options.stopPropagation) event.stopPropagation();
315
- if (options.stopImmediatePropagation) event.stopImmediatePropagation();
316
- if (options.preventDefault) event.preventDefault();
317
- const currentHostSet = SwcUtils.getHostSet(this);
318
- const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
319
- await this[meta.propertyKey](event, currentHostSet, matchedEl, args);
320
- if (event.cancelBubble) break;
321
356
  }
357
+ };
358
+ br.addEventListener(type, unifiedHandler, opts);
359
+ this._boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts });
360
+ });
361
+ });
362
+ nonDelegateListeners.forEach((meta) => {
363
+ const { selector, type, options } = meta;
364
+ const opts = { capture: options.capture, once: options.once, passive: options.passive };
365
+ const bindTargets = [];
366
+ const r = options.root || "auto";
367
+ const applyRootOption = (target) => {
368
+ if (!target) return;
369
+ if (r === "auto") {
370
+ bindTargets.push(target.shadowRoot || target);
371
+ } else {
372
+ if (r === "light" || r === "all") bindTargets.push(target);
373
+ if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
322
374
  }
323
375
  };
324
- br.addEventListener(type, unifiedHandler, opts);
325
- this._boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts });
326
- });
327
- });
328
- nonDelegateListeners.forEach((meta) => {
329
- const { selector, type, options } = meta;
330
- const opts = { capture: options.capture, once: options.once, passive: options.passive };
331
- const bindTargets = [];
332
- const r = options.root || "auto";
333
- const applyRootOption = (target) => {
334
- if (!target) return;
335
- if (r === "auto") {
336
- bindTargets.push(target.shadowRoot || target);
337
- } else {
338
- if (r === "light" || r === "all") bindTargets.push(target);
339
- if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
340
- }
341
- };
342
- if (selector === ":window") bindTargets.push(currentWin);
343
- else if (selector === ":document") bindTargets.push(currentWin.document);
344
- else if (selector === ":parentHost") applyRootOption(hostSet.$parentHost);
345
- else if (selector === ":appHost") applyRootOption(hostSet.$appHost);
346
- else if (selector === ":firstHost") applyRootOption(hostSet.$firstHost);
347
- else if (selector === ":lastHost") applyRootOption(hostSet.$lastHost);
348
- else if (selector === ":firstAppHost") applyRootOption(hostSet.$firstAppHost);
349
- else if (selector === ":lastAppHost") applyRootOption(hostSet.$lastAppHost);
350
- else if (selector === ":hosts") hostSet.$hosts.forEach(applyRootOption);
351
- else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRootOption);
352
- else if (selector === ":host" || !selector) applyRootOption(this);
353
- else {
354
- const searchRoots = [];
355
- if (r === "auto") searchRoots.push(this.shadowRoot || this);
356
- else if (r === "light") searchRoots.push(this);
357
- else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
358
- else if (r === "all") {
359
- searchRoots.push(this);
360
- if (this.shadowRoot) searchRoots.push(this.shadowRoot);
376
+ if (selector === "$window") bindTargets.push(currentWin);
377
+ else if (selector === "$document") bindTargets.push(currentWin.document);
378
+ else if (selector === "$host") applyRootOption(helperHostSet.$host);
379
+ else if (selector === "$parentHost") applyRootOption(helperHostSet.$parentHost);
380
+ else if (selector === "$appHost") applyRootOption(helperHostSet.$appHost);
381
+ else if (selector === "$firstHost") applyRootOption(helperHostSet.$firstHost);
382
+ else if (selector === "$lastHost") applyRootOption(helperHostSet.$lastHost);
383
+ else if (selector === "$firstAppHost") applyRootOption(helperHostSet.$firstAppHost);
384
+ else if (selector === "$lastAppHost") applyRootOption(helperHostSet.$lastAppHost);
385
+ else if (selector === "$hosts") helperHostSet.$hosts.forEach(applyRootOption);
386
+ else if (selector === "$appHosts") helperHostSet.$appHosts.forEach(applyRootOption);
387
+ else if (selector === "$this" || !selector) applyRootOption(this);
388
+ else {
389
+ const searchRoots = [];
390
+ if (r === "auto") searchRoots.push(this.shadowRoot || this);
391
+ else if (r === "light") searchRoots.push(this);
392
+ else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
393
+ else if (r === "all") {
394
+ searchRoots.push(this);
395
+ if (this.shadowRoot) searchRoots.push(this.shadowRoot);
396
+ }
397
+ searchRoots.forEach((sr) => {
398
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
399
+ });
361
400
  }
362
- searchRoots.forEach((sr) => {
363
- sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
401
+ bindTargets.forEach((t) => {
402
+ const handler = async (event) => {
403
+ if (options.filter) {
404
+ const helper = SwcUtils.getHelperAndHostSet(currentWin, t);
405
+ if (!options.filter(event, { currentThis: this, helper })) {
406
+ return;
407
+ }
408
+ }
409
+ if (options.stopPropagation) event.stopPropagation();
410
+ if (options.stopImmediatePropagation) event.stopImmediatePropagation();
411
+ if (options.preventDefault) event.preventDefault();
412
+ const currentHostSet = SwcUtils.getHostSet(this);
413
+ const args = { event, ...currentHostSet, $el: t, $root: t };
414
+ await this[meta.propertyKey](event, { currentHostSet, $$matchedElement: event.currentTarget }, args);
415
+ };
416
+ t.addEventListener(type, handler, opts);
417
+ if (options.removeOnDisconnected === true || t === currentWin || t === currentWin.document) {
418
+ this._boundListeners.push({ target: t, type, handler, options: opts });
419
+ }
364
420
  });
421
+ });
422
+ if (originalConnected) await originalConnected.apply(this);
423
+ const aMethods = findAllLifecycleMetadata(this, ON_AFTER_CONNECTED_METADATA_KEY);
424
+ if (aMethods) {
425
+ for (const m of aMethods) await this._invokeLifecycleMethod(m, helperHostSet);
365
426
  }
366
- bindTargets.forEach((t) => {
367
- const handler = async (event) => {
368
- if (options.filter) {
369
- const helper = SwcUtils.getHelperAndHostSet(currentWin, t);
370
- if (!options.filter(event, { currentThis: this, helper })) {
371
- return;
427
+ this._executeSwcScript("swc-on-connected", helperHostSet);
428
+ this._executeSwcScript("swc-on-after-connected", helperHostSet);
429
+ this.__swc_connected = true;
430
+ for (let [name2, metaList] of Array.from(attrChangeMap)) {
431
+ for (const meta of metaList) {
432
+ if (meta.options.while === "connected") {
433
+ const val = getAttributeValue(this, name2, { type: meta.options.type });
434
+ if (val !== null) {
435
+ await this[meta.propertyKey](val, null, name2, helperHostSet);
372
436
  }
373
437
  }
374
- if (options.stopPropagation) event.stopPropagation();
375
- if (options.stopImmediatePropagation) event.stopImmediatePropagation();
376
- if (options.preventDefault) event.preventDefault();
377
- const currentHostSet = SwcUtils.getHostSet(this);
378
- const args = { event, ...currentHostSet, $el: t, $root: t };
379
- await this[meta.propertyKey](event, currentHostSet, args);
380
- };
381
- t.addEventListener(type, handler, opts);
382
- if (options.removeOnDisconnected === true || t === currentWin || t === currentWin.document) {
383
- this._boundListeners.push({ target: t, type, handler, options: opts });
384
438
  }
385
- });
386
- });
387
- if (originalConnected) originalConnected.apply(this);
388
- const aMethods = findAllLifecycleMetadata(this, ON_AFTER_CONNECTED_METADATA_KEY);
389
- if (aMethods) {
390
- for (const m of aMethods) this._invokeLifecycleMethod(m, hostSet);
391
- }
392
- this._executeSwcScript("swc-on-connected", hostSet);
393
- this._executeSwcScript("swc-on-after-connected", hostSet);
394
- this.__swc_connected = true;
395
- const appHostss = SwcUtils.findAllParentAppHostsDirect(this);
396
- if (appHost && typeof appHost._connected === "function") {
397
- appHost._connected(this);
398
- } else if (appHost && typeof appHost) {
399
- appHost._connected_safari ?? (appHost._connected_safari = []);
400
- appHost._connected_safari.push(this);
439
+ }
440
+ } finally {
441
+ if (appHost && typeof appHost._connectedDone === "function") {
442
+ await appHost._connectedDone(this);
443
+ }
401
444
  }
402
445
  };
403
446
  const originalDisconnected = proto.disconnectedCallback;
404
447
  proto.disconnectedCallback = function() {
405
- const hostSet = SwcUtils.getHostSet(this);
406
- this._executeSwcScript("swc-on-before-disconnected", hostSet);
448
+ console.log("disconnnnnnnnnnnnnnnnnnn", helperHostSet, this);
449
+ const appHost = helperHostSet.$appHost;
450
+ if (appHost && typeof appHost._disconnected === "function") {
451
+ appHost._disconnected(this);
452
+ }
453
+ this._executeSwcScript("swc-on-before-disconnected", helperHostSet);
407
454
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
408
455
  if (bMethods) {
409
- for (const m of bMethods) this._invokeLifecycleMethod(m, hostSet);
456
+ for (const m of bMethods) this._invokeLifecycleMethod(m, helperHostSet);
410
457
  }
411
458
  if (this._boundListeners) {
412
459
  this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
@@ -415,15 +462,11 @@ const elementDefine = (name, config = {}) => (constructor) => {
415
462
  if (originalDisconnected) originalDisconnected.apply(this);
416
463
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
417
464
  if (aMethods) {
418
- for (const m of aMethods) this._invokeLifecycleMethod(m, hostSet);
465
+ for (const m of aMethods) this._invokeLifecycleMethod(m, helperHostSet);
419
466
  }
420
- this._executeSwcScript("swc-on-disconnected", hostSet);
421
- this._executeSwcScript("swc-on-after-disconnected", hostSet);
467
+ this._executeSwcScript("swc-on-disconnected", helperHostSet);
468
+ this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
422
469
  this.__swc_connected = false;
423
- const appHost = hostSet.$appHost;
424
- if (appHost && typeof appHost._disconnected === "function") {
425
- appHost._disconnected(this);
426
- }
427
470
  };
428
471
  const originalAdopted = proto.adoptedCallback;
429
472
  proto.adoptedCallback = function() {
@@ -448,12 +491,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
448
491
  let processedVal = newVal;
449
492
  if (newVal !== null) {
450
493
  const ae = new ActionExpression(newVal);
451
- const expr = ae.getFirstExpression("call-return");
494
+ const expr = ae.getFirstExpression("callReturn");
452
495
  if (expr) {
453
496
  const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
454
497
  const helperAndHostSet = SwcUtils.getHelperAndHostSet(win2, this);
498
+ const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
455
499
  try {
456
- const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
457
500
  const result = FunctionUtils.executeReturn({
458
501
  script,
459
502
  context: this,
@@ -479,6 +522,9 @@ const elementDefine = (name, config = {}) => (constructor) => {
479
522
  const metaList = attrChangeMap.get(name2);
480
523
  if (metaList && Array.isArray(metaList)) {
481
524
  for (const meta of metaList) {
525
+ if (meta.options.while === "connected" && !this.__swc_connected) {
526
+ continue;
527
+ }
482
528
  const convertedVal = convertAttributeValue(processedVal, meta.options.type);
483
529
  this[meta.propertyKey](convertedVal, old, name2, hSet);
484
530
  }