@dooboostore/simple-web-component 1.0.33 → 1.0.35

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