@repobit/dex-store-elements 1.4.2 → 1.4.4

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 (96) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +15 -4
  3. package/dist/src/actions/action.button.js +4 -11
  4. package/dist/src/actions/action.button.js.map +1 -1
  5. package/dist/src/actions/action.input.js +28 -22
  6. package/dist/src/actions/action.input.js.map +1 -1
  7. package/dist/src/actions/action.select.js +10 -8
  8. package/dist/src/actions/action.select.js.map +1 -1
  9. package/dist/src/actions/index.d.ts +1 -1
  10. package/dist/src/actions/index.js +45 -49
  11. package/dist/src/actions/index.js.map +1 -1
  12. package/dist/src/actions/utilty.d.ts +1 -0
  13. package/dist/src/actions/utilty.js +59 -29
  14. package/dist/src/actions/utilty.js.map +1 -1
  15. package/dist/src/contexts/context.datalayer.js.map +1 -1
  16. package/dist/src/contexts/context.derived.js.map +1 -1
  17. package/dist/src/contexts/context.option.js.map +1 -1
  18. package/dist/src/contexts/context.product.js.map +1 -1
  19. package/dist/src/contexts/context.state.js.map +1 -1
  20. package/dist/src/contexts/context.store.js.map +1 -1
  21. package/dist/src/controllers/collect-controller.d.ts +39 -0
  22. package/dist/src/controllers/collect-controller.js +161 -0
  23. package/dist/src/controllers/collect-controller.js.map +1 -0
  24. package/dist/src/controllers/compute-controller.d.ts +55 -0
  25. package/dist/src/controllers/compute-controller.js +350 -0
  26. package/dist/src/controllers/compute-controller.js.map +1 -0
  27. package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +21 -0
  28. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +152 -0
  29. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +1 -0
  30. package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +28 -0
  31. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +206 -0
  32. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +1 -0
  33. package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +21 -0
  34. package/dist/src/controllers/eta-renderer/eta-renderer.js +77 -0
  35. package/dist/src/controllers/eta-renderer/eta-renderer.js.map +1 -0
  36. package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +21 -0
  37. package/dist/src/controllers/eta-renderer/eta-template-cache.js +52 -0
  38. package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +1 -0
  39. package/dist/src/controllers/eta-renderer/eta-types.d.ts +11 -0
  40. package/dist/src/controllers/eta-renderer/eta-types.js +1 -0
  41. package/dist/src/controllers/eta-renderer/eta-types.js.map +1 -0
  42. package/dist/src/controllers/eta-renderer/index.d.ts +2 -0
  43. package/dist/src/controllers/eta-renderer/index.js +2 -0
  44. package/dist/src/controllers/eta-renderer/index.js.map +1 -0
  45. package/dist/src/controllers/event-pipeline-controller.d.ts +28 -0
  46. package/dist/src/controllers/event-pipeline-controller.js +72 -0
  47. package/dist/src/controllers/event-pipeline-controller.js.map +1 -0
  48. package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
  49. package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
  50. package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
  51. package/dist/src/dsl/compilers/index.js.map +1 -1
  52. package/dist/src/dsl/utilty.js.map +1 -1
  53. package/dist/src/events/events.js.map +1 -1
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/nodes/node.context.js.map +1 -1
  56. package/dist/src/nodes/node.option.d.ts +4 -2
  57. package/dist/src/nodes/node.option.js +56 -56
  58. package/dist/src/nodes/node.option.js.map +1 -1
  59. package/dist/src/nodes/node.product.d.ts +4 -3
  60. package/dist/src/nodes/node.product.js +16 -28
  61. package/dist/src/nodes/node.product.js.map +1 -1
  62. package/dist/src/nodes/node.root.js.map +1 -1
  63. package/dist/src/nodes/node.state.d.ts +18 -70
  64. package/dist/src/nodes/node.state.js +42 -862
  65. package/dist/src/nodes/node.state.js.map +1 -1
  66. package/dist/src/renders/attributes/buyLink.js +12 -8
  67. package/dist/src/renders/attributes/buyLink.js.map +1 -1
  68. package/dist/src/renders/attributes/devices.js +10 -10
  69. package/dist/src/renders/attributes/devices.js.map +1 -1
  70. package/dist/src/renders/attributes/discount.js +60 -81
  71. package/dist/src/renders/attributes/discount.js.map +1 -1
  72. package/dist/src/renders/attributes/hide.js +21 -26
  73. package/dist/src/renders/attributes/hide.js.map +1 -1
  74. package/dist/src/renders/attributes/index.js.map +1 -1
  75. package/dist/src/renders/attributes/price.js +60 -81
  76. package/dist/src/renders/attributes/price.js.map +1 -1
  77. package/dist/src/renders/attributes/subscription.js +11 -11
  78. package/dist/src/renders/attributes/subscription.js.map +1 -1
  79. package/dist/src/renders/attributes/trialLink.js +5 -4
  80. package/dist/src/renders/attributes/trialLink.js.map +1 -1
  81. package/dist/src/renders/attributes/utilty.d.ts +2 -0
  82. package/dist/src/renders/attributes/utilty.js +5 -0
  83. package/dist/src/renders/attributes/utilty.js.map +1 -0
  84. package/dist/src/renders/context.js.map +1 -1
  85. package/dist/src/renders/format.js.map +1 -1
  86. package/dist/src/renders/index.d.ts +1 -1
  87. package/dist/src/renders/index.js +46 -50
  88. package/dist/src/renders/index.js.map +1 -1
  89. package/dist/src/renders/observe.js.map +1 -1
  90. package/dist/src/renders/utility.js +46 -38
  91. package/dist/src/renders/utility.js.map +1 -1
  92. package/dist/src/templating/eta.js.map +1 -1
  93. package/package.json +2 -2
  94. package/dist/src/contexts/context.event.d.ts +0 -5
  95. package/dist/src/contexts/context.event.js +0 -3
  96. package/dist/src/contexts/context.event.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.4.4](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.3...@repobit/dex-store-elements@1.4.4) (2026-03-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **DEX-26778:** fix no discount price ([f08d636](https://github.com/bitdefender/dex-core/commit/f08d63626a15f536bfdbd4f6f47bc4f3fcabab97))
12
+
13
+
14
+
15
+ ## [1.4.3](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.2...@repobit/dex-store-elements@1.4.3) (2026-03-03)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **DEX-21811:** add checked option for input ([4c6ed58](https://github.com/bitdefender/dex-core/commit/4c6ed58fae48c8fda372b6ddac3d706e4ed96e46))
21
+ * **DEX-21811:** fix refactor bug ([aa37307](https://github.com/bitdefender/dex-core/commit/aa37307a989ea3882dcfc287f25157ccf13c6d8c))
22
+
23
+
24
+
6
25
  ## [1.4.2](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.1...@repobit/dex-store-elements@1.4.2) (2025-12-17)
7
26
 
8
27
 
package/README.md CHANGED
@@ -55,8 +55,12 @@ Peer dependencies are resolved automatically by npm; no extra install command is
55
55
  mails: (p) => ((option?.getDevices?.() ?? 0) / p) * 100
56
56
  });
57
57
 
58
- registerActionNodes(root);
59
- registerRenderNodes(root);
58
+ const disposeActions = registerActionNodes(root);
59
+ const disposeRenders = registerRenderNodes(root);
60
+
61
+ // Optional teardown (for SPA route changes/unmounts)
62
+ // disposeActions();
63
+ // disposeRenders();
60
64
  });
61
65
  </script>
62
66
 
@@ -289,7 +293,10 @@ Example:
289
293
  });
290
294
  };
291
295
 
292
- registerActionNodes(root);
296
+ const disposeActions = registerActionNodes(root);
297
+
298
+ // Optional teardown (for SPA route changes/unmounts)
299
+ // disposeActions();
293
300
  });
294
301
  </script>
295
302
 
@@ -313,13 +320,17 @@ Behavior notes
313
320
  - Source identifier: add `data-store-id="someId"` to tag the event's `storeId`. Providers with `ignore-events` that include `someId` will drop these events.
314
321
  - Initialize once per mount with:
315
322
  - `import { registerActionNodes } from '@repobit/dex-store-elements'`
316
- - `registerActionNodes(root)`
323
+ - `const disposeActions = registerActionNodes(root)`
324
+ - Call `disposeActions()` on teardown/unmount to disconnect observers.
317
325
 
318
326
  ## Registration and initialization
319
327
  - Element registration:
320
328
  - `import { registerContextNodes } from '@repobit/dex-store-elements'; registerContextNodes();`
321
329
  - Rendering: `import { registerRenderNodes } from '@repobit/dex-store-elements'`
322
330
  - Actions: `import { registerActionNodes } from '@repobit/dex-store-elements'`
331
+ - `registerRenderNodes(root)` returns a disposer: `() => void`
332
+ - `registerActionNodes(root)` returns a disposer: `() => void`
333
+ - Call disposers during teardown/unmount in long-lived apps (SPA route changes, dynamic mounts).
323
334
 
324
335
  Note: The package is side-effect free; elements are registered only when `registerContextNodes()` is called.
325
336
 
@@ -1,15 +1,8 @@
1
- import { ActionEvent, UpdateByDeltaEvent } from "../events/events.js";
2
- import { addEventListener, connectedCallback, readClickAttributes } from "./utilty.js";
1
+ import { addEventListener, dispatchActionAttributes, readClickAttributes } from "./utilty.js";
3
2
  export const button = (el) => {
4
- const action = () => {
5
- const attr = readClickAttributes(el);
6
- if ('type' in attr) {
7
- el.dispatchEvent(new UpdateByDeltaEvent(attr));
8
- return;
9
- }
10
- el.dispatchEvent(new ActionEvent(attr));
3
+ const onClick = () => {
4
+ dispatchActionAttributes(el, readClickAttributes(el));
11
5
  };
12
- connectedCallback(el);
13
- addEventListener(el, "click", action);
6
+ addEventListener(el, "click", onClick);
14
7
  };
15
8
  //# sourceMappingURL=action.button.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"action.button.js","sourceRoot":"","sources":["../../../src/actions/action.button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAc,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEhG,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAc,EAAE,EAAE;IAEvC,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,MAAM,IAAI,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;QAErC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,EAAE,CAAC,aAAa,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAA;YAC9C,OAAO;QACT,CAAC;QAED,EAAE,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;IACzC,CAAC,CAAC;IAEF,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACtB,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC,CAAA"}
1
+ {"version":3,"file":"action.button.js","sourceRoot":"","sources":["../../../src/actions/action.button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,gBAAgB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEvG,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAc,EAAE,EAAE;IACvC,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,wBAAwB,CAAC,EAAE,EAAE,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC;IAEF,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC,CAAA","sourcesContent":["import { ActionNode, addEventListener, dispatchActionAttributes, readClickAttributes } from \"./utilty\";\n\nexport const button = (el: ActionNode) => {\n const onClick = () => {\n dispatchActionAttributes(el, readClickAttributes(el));\n };\n\n addEventListener(el, \"click\", onClick);\n}\n"]}
@@ -1,36 +1,42 @@
1
- import { ActionEvent, UpdateByDeltaEvent } from "../events/events.js";
2
- import { addEventListener, readClickAttributes } from "./utilty.js";
1
+ import { addEventListener, dispatchActionAttributes, readClickAttributes } from "./utilty.js";
2
+ const toOptionalNumber = (value) => {
3
+ const trimmed = value.trim();
4
+ if (!trimmed)
5
+ return undefined;
6
+ const parsed = Number(trimmed);
7
+ return Number.isNaN(parsed) ? undefined : parsed;
8
+ };
3
9
  export const input = (el) => {
4
- const button = () => {
5
- const attr = readClickAttributes(el);
6
- if ('type' in attr) {
7
- el.dispatchEvent(new UpdateByDeltaEvent(attr));
8
- return;
9
- }
10
- el.dispatchEvent(new ActionEvent(attr));
10
+ const dispatchClickAction = () => {
11
+ dispatchActionAttributes(el, readClickAttributes(el));
11
12
  };
12
- const number = () => {
13
+ const dispatchDeltaFromValue = () => {
13
14
  const attr = readClickAttributes(el);
14
- if ('type' in attr) {
15
- el.dispatchEvent(new UpdateByDeltaEvent({
16
- type: attr.type,
17
- delta: Number(el.value),
18
- min: Number(el.min),
19
- max: Number(el.max),
20
- useAsValue: true,
21
- storeId: attr.storeId
22
- }));
15
+ if (!('type' in attr))
16
+ return;
17
+ const delta = toOptionalNumber(el.value);
18
+ if (delta === undefined)
23
19
  return;
24
- }
20
+ dispatchActionAttributes(el, {
21
+ type: attr.type,
22
+ delta,
23
+ min: toOptionalNumber(el.min),
24
+ max: toOptionalNumber(el.max),
25
+ useAsValue: true,
26
+ storeId: attr.storeId
27
+ });
25
28
  };
26
29
  switch (el.type) {
27
30
  case "checkbox":
28
31
  case "radio":
29
- addEventListener(el, "click", button);
32
+ if (el.checked) {
33
+ dispatchClickAction();
34
+ }
35
+ addEventListener(el, "click", dispatchClickAction);
30
36
  break;
31
37
  case "text":
32
38
  case "number":
33
- addEventListener(el, "change", number);
39
+ addEventListener(el, "change", dispatchDeltaFromValue);
34
40
  break;
35
41
  }
36
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"action.input.js","sourceRoot":"","sources":["../../../src/actions/action.input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAc,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE7E,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAgC,EAAE,EAAE;IACxD,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,MAAM,IAA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AAmB,EAAE,CAAC;YACxB,CAAC;YACD,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC;YACnD,MAAM;QACR,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ;YACX,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC;YACvD,MAAM;IACV,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { ActionNode, addEventListener, dispatchActionAttributes, readClickAttributes } from \"./utilty\";\n\nconst toOptionalNumber = (value: string): number | undefined => {\n const trimmed = value.trim();\n if (!trimmed) return undefined;\n const parsed = Number(trimmed);\n return Number.isNaN(parsed) ? undefined : parsed;\n};\n\nexport const input = (el: ActionNode<HTMLInputElement>) => {\n const dispatchClickAction = () => {\n dispatchActionAttributes(el, readClickAttributes(el));\n };\n\n const dispatchDeltaFromValue = () => {\n const attr = readClickAttributes(el);\n if (!('type' in attr)) return;\n\n const delta = toOptionalNumber(el.value);\n if (delta === undefined) return;\n\n dispatchActionAttributes(el, {\n type : attr.type,\n delta,\n min : toOptionalNumber(el.min),\n max : toOptionalNumber(el.max),\n useAsValue: true,\n storeId : attr.storeId\n });\n };\n\n switch (el.type) {\n case \"checkbox\":\n case \"radio\":\n if (el.checked) {\n dispatchClickAction();\n }\n addEventListener(el, \"click\", dispatchClickAction);\n break;\n case \"text\":\n case \"number\":\n addEventListener(el, \"change\", dispatchDeltaFromValue);\n break;\n }\n}\n"]}
@@ -1,12 +1,14 @@
1
- import { ActionEvent } from "../events/events.js";
2
- import { addEventListener, readClickAttributes } from "./utilty.js";
1
+ import { addEventListener, dispatchActionAttributes, readClickAttributes } from "./utilty.js";
3
2
  export const select = (el) => {
4
- const action = () => {
5
- const attr = readClickAttributes(el.selectedOptions[0]);
6
- if (!('type' in attr)) {
7
- el.dispatchEvent(new ActionEvent(attr));
8
- }
3
+ const onChange = () => {
4
+ const selected = el.selectedOptions[0];
5
+ if (!selected)
6
+ return;
7
+ const attr = readClickAttributes(selected);
8
+ if ('type' in attr)
9
+ return;
10
+ dispatchActionAttributes(el, attr);
9
11
  };
10
- addEventListener(el, "change", action);
12
+ addEventListener(el, "change", onChange);
11
13
  };
12
14
  //# sourceMappingURL=action.select.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"action.select.js","sourceRoot":"","sources":["../../../src/actions/action.select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAc,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE7E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAiC,EAAE,EAAE;IAE1D,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,MAAM,IAAI,GAAG,mBAAmB,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QAExD,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;QACzC,CAAC;IACH,CAAC,CAAC;IAEF,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC,CAAA"}
1
+ {"version":3,"file":"action.select.js","sourceRoot":"","sources":["../../../src/actions/action.select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,gBAAgB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEvG,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAiC,EAAE,EAAE;IAC1D,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,MAAM,QAAQ,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAEtB,MAAM,IAAI,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO;QAC3B,wBAAwB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC,CAAA","sourcesContent":["import { ActionNode, addEventListener, dispatchActionAttributes, readClickAttributes } from \"./utilty\";\n\nexport const select = (el: ActionNode<HTMLSelectElement>) => {\n const onChange = () => {\n const selected = el.selectedOptions[0];\n if (!selected) return;\n\n const attr = readClickAttributes(selected);\n if ('type' in attr) return;\n dispatchActionAttributes(el, attr);\n };\n\n addEventListener(el, \"change\", onChange);\n}\n"]}
@@ -1,2 +1,2 @@
1
- declare const registerActionNodes: (root: HTMLElement | ShadowRoot) => void;
1
+ declare const registerActionNodes: (root: HTMLElement | ShadowRoot) => () => void;
2
2
  export { registerActionNodes };
@@ -1,67 +1,55 @@
1
1
  import { cleanupActionNode, DATA_ACTION_NODE, handleActionNode } from "./utilty.js";
2
+ const SHADOW_HOST_SELECTOR = '[shadow]';
3
+ const isActionNode = (node) => node.matches(DATA_ACTION_NODE);
4
+ const forEachActionNode = (root, fn) => {
5
+ if (root instanceof HTMLElement && isActionNode(root)) {
6
+ fn(root);
7
+ }
8
+ root
9
+ .querySelectorAll(DATA_ACTION_NODE)
10
+ .forEach(fn);
11
+ };
12
+ const forEachShadowRoot = (root, fn) => {
13
+ if (root instanceof HTMLElement && root.hasAttribute('shadow') && root.shadowRoot) {
14
+ fn(root.shadowRoot);
15
+ }
16
+ root
17
+ .querySelectorAll(SHADOW_HOST_SELECTOR)
18
+ .forEach((host) => host.shadowRoot && fn(host.shadowRoot));
19
+ };
2
20
  const registerActionNodes = (root) => {
3
21
  const observed = new WeakSet();
22
+ const observers = new WeakMap();
23
+ const activeObservers = new Set();
24
+ const disconnect = (node) => {
25
+ const observer = observers.get(node);
26
+ if (!observer)
27
+ return;
28
+ observer.disconnect();
29
+ observers.delete(node);
30
+ activeObservers.delete(observer);
31
+ };
4
32
  const cleanupShadowTree = (shadowRoot) => {
5
- shadowRoot
6
- .querySelectorAll(DATA_ACTION_NODE)
7
- .forEach(n => cleanupActionNode(n));
8
- shadowRoot
9
- .querySelectorAll('[shadow]')
10
- .forEach(host => host.shadowRoot && cleanupShadowTree(host.shadowRoot));
33
+ forEachActionNode(shadowRoot, cleanupActionNode);
34
+ forEachShadowRoot(shadowRoot, cleanupShadowTree);
35
+ disconnect(shadowRoot);
11
36
  };
12
37
  const handleAdded = (node) => {
13
- if (node.matches(DATA_ACTION_NODE)) {
14
- handleActionNode(node);
15
- }
16
- node
17
- .querySelectorAll(DATA_ACTION_NODE)
18
- .forEach(handleActionNode);
19
- if (node.hasAttribute('shadow') && node.shadowRoot) {
20
- watch(node.shadowRoot);
21
- }
22
- node
23
- .querySelectorAll('[shadow]')
24
- .forEach(host => host.shadowRoot && watch(host.shadowRoot));
38
+ forEachActionNode(node, handleActionNode);
39
+ forEachShadowRoot(node, watch);
25
40
  };
26
41
  const handleRemoved = (node) => {
27
- if (node.matches(DATA_ACTION_NODE)) {
28
- cleanupActionNode(node);
29
- }
30
- node
31
- .querySelectorAll(DATA_ACTION_NODE)
32
- .forEach(n => cleanupActionNode(n));
33
- if (node.hasAttribute('shadow') && node.shadowRoot) {
34
- cleanupShadowTree(node.shadowRoot);
35
- }
36
- node
37
- .querySelectorAll('[shadow]')
38
- .forEach(host => host.shadowRoot && cleanupShadowTree(host.shadowRoot));
42
+ forEachActionNode(node, cleanupActionNode);
43
+ forEachShadowRoot(node, cleanupShadowTree);
39
44
  };
40
45
  const watch = (node) => {
41
46
  if (observed.has(node))
42
47
  return;
43
48
  observed.add(node);
44
- if (node instanceof HTMLElement && node.matches(DATA_ACTION_NODE)) {
45
- handleActionNode(node);
46
- }
47
- node
48
- .querySelectorAll(DATA_ACTION_NODE)
49
- .forEach(handleActionNode);
50
- if (node instanceof HTMLElement && node.hasAttribute('shadow') && node.shadowRoot) {
51
- watch(node.shadowRoot);
52
- }
53
- if ('querySelectorAll' in node) {
54
- node
55
- .querySelectorAll('[shadow]')
56
- .forEach(host => host.shadowRoot && watch(host.shadowRoot));
57
- }
49
+ forEachActionNode(node, handleActionNode);
50
+ forEachShadowRoot(node, watch);
58
51
  const mo = new MutationObserver(muts => {
59
52
  for (const m of muts) {
60
- if (m.type === 'attributes') {
61
- const attr = m.attributeName?.toLowerCase();
62
- if (attr === 'class' || attr === 'style')
63
- continue; // Ignore cosmetic-only mutations
64
- }
65
53
  for (const added of Array.from(m.addedNodes)) {
66
54
  if (!(added instanceof HTMLElement))
67
55
  continue;
@@ -78,8 +66,16 @@ const registerActionNodes = (root) => {
78
66
  childList: true,
79
67
  subtree: true
80
68
  });
69
+ observers.set(node, mo);
70
+ activeObservers.add(mo);
81
71
  };
82
72
  watch(root);
73
+ return () => {
74
+ for (const observer of activeObservers) {
75
+ observer.disconnect();
76
+ }
77
+ activeObservers.clear();
78
+ };
83
79
  };
84
80
  export { registerActionNodes };
85
81
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7F,MAAM,mBAAmB,GAAG,CAAC,IAA8B,EAAE,EAAE;IAC7D,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAQ,CAAC;IAErC,MAAM,iBAAiB,GAAG,CAAC,UAAsB,EAAE,EAAE;QACnD,UAAU;aACP,gBAAgB,CAAa,gBAAgB,CAAC;aAC9C,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAe,CAAC,CAAC,CAAC;QACpD,UAAU;aACP,gBAAgB,CAAc,UAAU,CAAC;aACzC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IA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AAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC;QACD,eAAe,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import { ActionNode, cleanupActionNode, DATA_ACTION_NODE, handleActionNode } from \"./utilty\";\n\nconst SHADOW_HOST_SELECTOR = '[shadow]';\n\nconst isActionNode = (node: HTMLElement): node is ActionNode => node.matches(DATA_ACTION_NODE);\n\nconst forEachActionNode = (root: HTMLElement | ShadowRoot, fn: (node: ActionNode) => void) => {\n if (root instanceof HTMLElement && isActionNode(root)) {\n fn(root);\n }\n\n root\n .querySelectorAll<ActionNode>(DATA_ACTION_NODE)\n .forEach(fn);\n};\n\nconst forEachShadowRoot = (root: HTMLElement | ShadowRoot, fn: (shadowRoot: ShadowRoot) => void) => {\n if (root instanceof HTMLElement && root.hasAttribute('shadow') && root.shadowRoot) {\n fn(root.shadowRoot);\n }\n\n root\n .querySelectorAll<HTMLElement>(SHADOW_HOST_SELECTOR)\n .forEach((host) => host.shadowRoot && fn(host.shadowRoot));\n};\n\nconst registerActionNodes = (root: HTMLElement | ShadowRoot) => {\n const observed = new WeakSet<Node>();\n const observers = new WeakMap<Node, MutationObserver>();\n const activeObservers = new Set<MutationObserver>();\n\n const disconnect = (node: Node) => {\n const observer = observers.get(node);\n if (!observer) return;\n observer.disconnect();\n observers.delete(node);\n activeObservers.delete(observer);\n };\n\n const cleanupShadowTree = (shadowRoot: ShadowRoot) => {\n forEachActionNode(shadowRoot, cleanupActionNode);\n forEachShadowRoot(shadowRoot, cleanupShadowTree);\n disconnect(shadowRoot);\n };\n\n const handleAdded = (node: HTMLElement) => {\n forEachActionNode(node, handleActionNode);\n forEachShadowRoot(node, watch);\n };\n\n const handleRemoved = (node: HTMLElement) => {\n forEachActionNode(node, cleanupActionNode);\n forEachShadowRoot(node, cleanupShadowTree);\n };\n\n const watch = (node: HTMLElement | ShadowRoot) => {\n if (observed.has(node)) return;\n observed.add(node);\n\n forEachActionNode(node, handleActionNode);\n forEachShadowRoot(node, watch);\n\n const mo = new MutationObserver(muts => {\n for (const m of muts) {\n for (const added of Array.from(m.addedNodes)) {\n if (!(added instanceof HTMLElement)) continue;\n handleAdded(added);\n }\n for (const removed of Array.from(m.removedNodes)) {\n if (!(removed instanceof HTMLElement)) continue;\n handleRemoved(removed);\n }\n }\n });\n\n mo.observe(node, {\n childList: true,\n subtree : true\n });\n observers.set(node, mo);\n activeObservers.add(mo);\n };\n\n watch(root);\n return () => {\n for (const observer of activeObservers) {\n observer.disconnect();\n }\n activeObservers.clear();\n };\n}\n\nexport { registerActionNodes };\n"]}
@@ -7,6 +7,7 @@ type WithStore = {
7
7
  export type ActionNode<T extends HTMLElement = HTMLElement> = T & WithStore;
8
8
  export declare const DATA_ACTION_NODE = "[data-store-action]";
9
9
  export declare const readClickAttributes: (el: HTMLElement) => ActionAttributes;
10
+ export declare const dispatchActionAttributes: (el: HTMLElement, attr: ActionAttributes) => void;
10
11
  export declare const connectedCallback: (el: ActionNode) => void;
11
12
  export declare const disconnectedCallback: (el: ActionNode) => void;
12
13
  export declare const handleActionNode: (node: ActionNode) => void;
@@ -1,10 +1,41 @@
1
- import { CollectActionEvent, CollectUpdateByDeltaEvent } from "../events/events.js";
1
+ import { ActionEvent, CollectActionEvent, CollectUpdateByDeltaEvent, UpdateByDeltaEvent } from "../events/events.js";
2
2
  import { button } from "./action.button.js";
3
3
  import { input } from "./action.input.js";
4
4
  import { select } from "./action.select.js";
5
5
  export const DATA_ACTION_NODE = "[data-store-action]";
6
6
  // Track initialized action nodes to ensure we don't wire them up twice
7
7
  const ACTION_BOUND = new WeakSet();
8
+ const ACTION_LISTENER_DISPOSERS = new WeakMap();
9
+ const ACTION_ORIGINAL_REMOVE = new WeakMap();
10
+ const shouldCollectForNode = (el) => !(el.dataset.storeNoCollect === '' || el.dataset.storeNoCollect === 'true');
11
+ const disconnectCollectedAction = (el) => {
12
+ if (el instanceof HTMLSelectElement) {
13
+ [...el.options].forEach((option) => disconnectedCallback(option));
14
+ return;
15
+ }
16
+ disconnectedCallback(el);
17
+ };
18
+ const teardownActionNode = (node) => {
19
+ const hadState = ACTION_BOUND.has(node)
20
+ || ACTION_LISTENER_DISPOSERS.has(node)
21
+ || ACTION_ORIGINAL_REMOVE.has(node);
22
+ if (!hadState)
23
+ return;
24
+ disconnectCollectedAction(node);
25
+ const listenerDisposers = ACTION_LISTENER_DISPOSERS.get(node);
26
+ if (listenerDisposers) {
27
+ for (const dispose of listenerDisposers) {
28
+ dispose();
29
+ }
30
+ ACTION_LISTENER_DISPOSERS.delete(node);
31
+ }
32
+ const originalRemove = ACTION_ORIGINAL_REMOVE.get(node);
33
+ if (originalRemove) {
34
+ node.remove = originalRemove;
35
+ }
36
+ ACTION_ORIGINAL_REMOVE.delete(node);
37
+ ACTION_BOUND.delete(node);
38
+ };
8
39
  export const readClickAttributes = (el) => {
9
40
  const ds = el.dataset;
10
41
  const storeId = ds.storeId || undefined;
@@ -29,6 +60,13 @@ export const readClickAttributes = (el) => {
29
60
  };
30
61
  }
31
62
  };
63
+ export const dispatchActionAttributes = (el, attr) => {
64
+ if ('type' in attr) {
65
+ el.dispatchEvent(new UpdateByDeltaEvent(attr));
66
+ return;
67
+ }
68
+ el.dispatchEvent(new ActionEvent(attr));
69
+ };
32
70
  const addLogic = async (el) => {
33
71
  if (el.updateComplete) {
34
72
  await el.updateComplete;
@@ -53,9 +91,7 @@ export const connectedCallback = (el) => {
53
91
  el.storeName = Symbol("action");
54
92
  }
55
93
  const attr = readClickAttributes(el);
56
- const noCollect = (el.dataset.storeNoCollect === '' || el.dataset.storeNoCollect === 'true');
57
- const shouldCollect = !noCollect;
58
- if (shouldCollect) {
94
+ if (shouldCollectForNode(el)) {
59
95
  if ('type' in attr) {
60
96
  el.dispatchEvent(new CollectUpdateByDeltaEvent({ name: el.storeName, update: attr }));
61
97
  }
@@ -66,10 +102,8 @@ export const connectedCallback = (el) => {
66
102
  };
67
103
  export const disconnectedCallback = (el) => {
68
104
  const attr = readClickAttributes(el);
69
- const noCollect = (el.dataset.storeNoCollect === '' || el.dataset.storeNoCollect === 'true');
70
- const shouldCollect = !noCollect;
71
- if (shouldCollect) {
72
- if ('storeSetType' in attr) {
105
+ if (shouldCollectForNode(el)) {
106
+ if ('type' in attr) {
73
107
  el.dispatchEvent(new CollectUpdateByDeltaEvent({
74
108
  name: el.storeName,
75
109
  update: null
@@ -90,30 +124,26 @@ export const handleActionNode = (node) => {
90
124
  addLogic(node);
91
125
  };
92
126
  export const cleanupActionNode = (node) => {
93
- // Fire disconnect events to clear collected actions
94
- if (node instanceof HTMLSelectElement) {
95
- [...node.options].forEach(option => disconnectedCallback(option));
96
- }
97
- else {
98
- disconnectedCallback(node);
99
- }
100
- ACTION_BOUND.delete(node);
127
+ teardownActionNode(node);
101
128
  };
102
129
  export const addEventListener = (el, type, listener) => {
103
130
  el.addEventListener(type, listener);
104
- const originalRemove = el.remove;
105
- el.remove = () => {
106
- if (el instanceof HTMLSelectElement) {
107
- [...el.options]
108
- .forEach(option => disconnectedCallback(option));
109
- }
110
- else {
111
- disconnectedCallback(el);
112
- }
131
+ let listenerDisposers = ACTION_LISTENER_DISPOSERS.get(el);
132
+ if (!listenerDisposers) {
133
+ listenerDisposers = new Set();
134
+ ACTION_LISTENER_DISPOSERS.set(el, listenerDisposers);
135
+ }
136
+ listenerDisposers.add(() => {
113
137
  el.removeEventListener(type, listener);
114
- // Allow re-initialization if element is re-attached later
115
- ACTION_BOUND.delete(el);
116
- originalRemove.call(el);
117
- };
138
+ });
139
+ const actionEl = el;
140
+ if (!ACTION_ORIGINAL_REMOVE.has(actionEl)) {
141
+ const originalRemove = actionEl.remove;
142
+ ACTION_ORIGINAL_REMOVE.set(actionEl, originalRemove);
143
+ actionEl.remove = () => {
144
+ teardownActionNode(actionEl);
145
+ originalRemove.call(actionEl);
146
+ };
147
+ }
118
148
  };
119
149
  //# sourceMappingURL=utilty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../src/actions/utilty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,kBAAkB,EAAE,yBAAyB,EAAiB,MAAM,iBAAiB,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAQzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,uEAAuE;AACvE,MAAM,YAAY,GAAG,IAAI,OAAO,EAAc,CAAC;AAE/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAe,EAAoB,EAAE;IACvE,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IACtB,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,IAAI,SAAS,CAAC;IAExC,IAAI,cAAc,IAAI,EAAE,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAQ,EAAE,CAAC,YAAqC;YACpD,KAAK,EAAO,EAAE,CAAC,aAAa,KAAK,MAAM,IAAI,EAAE,CAAC,aAAa,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC;YACpH,GAAG,EAAS,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,SAAS;YAC/C,GAAG,EAAS,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,SAAS;YAC/C,UAAU,EAAE,EAAE,CAAC,kBAAkB,KAAK,MAAM,IAAI,EAAE,CAAC,kBAAkB,KAAK,EAAE,IAAI,KAAK;YACrF,OAAO;SACR,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO;YACL,OAAO,EAAO,MAAM,CAAC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QAAQ,CAAC,MAAM,CAAC;QACvC,sBAAsB,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAErD,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;YACrB,kBAAkB,CAAC,QAAQ,CAAC,CAAC;YAC7B,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAA;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { Action, ActionEvent, CollectActionEvent, CollectUpdateByDeltaEvent, UpdateByDelta, UpdateByDeltaEvent } from \"@/events/events\";\nimport { button } from \"./action.button\";\nimport { input } from \"./action.input\";\nimport { select } from \"./action.select\";\n\nexport type ActionAttributes = UpdateByDelta | Action;\ntype WithStore = {\n storeName : symbol;\n updateComplete: Promise<void>;\n};\nexport type ActionNode<T extends HTMLElement = HTMLElement> = T & WithStore;\nexport const DATA_ACTION_NODE = \"[data-store-action]\";\n\n// Track initialized action nodes to ensure we don't wire them up twice\nconst ACTION_BOUND = new WeakSet<ActionNode>();\nconst ACTION_LISTENER_DISPOSERS = new WeakMap<HTMLElement, Set<() => void>>();\nconst ACTION_ORIGINAL_REMOVE = new WeakMap<ActionNode, () => void>();\n\nconst shouldCollectForNode = (el: HTMLElement) => !(el.dataset.storeNoCollect === '' || el.dataset.storeNoCollect === 'true');\n\nconst disconnectCollectedAction = (el: ActionNode) => {\n if (el instanceof HTMLSelectElement) {\n [...el.options].forEach((option) => disconnectedCallback(option as unknown as ActionNode));\n return;\n }\n\n disconnectedCallback(el);\n};\n\nconst teardownActionNode = (node: ActionNode) => {\n const hadState =\n ACTION_BOUND.has(node)\n || ACTION_LISTENER_DISPOSERS.has(node)\n || ACTION_ORIGINAL_REMOVE.has(node);\n if (!hadState) return;\n\n disconnectCollectedAction(node);\n\n const listenerDisposers = ACTION_LISTENER_DISPOSERS.get(node);\n if (listenerDisposers) {\n for (const dispose of listenerDisposers) {\n dispose();\n }\n ACTION_LISTENER_DISPOSERS.delete(node);\n }\n\n const originalRemove = ACTION_ORIGINAL_REMOVE.get(node);\n if (originalRemove) {\n node.remove = originalRemove;\n }\n\n ACTION_ORIGINAL_REMOVE.delete(node);\n ACTION_BOUND.delete(node);\n};\n\nexport const readClickAttributes = (el: HTMLElement): ActionAttributes => {\n const ds = el.dataset;\n const storeId = ds.storeId || undefined;\n\n if ('storeSetType' in ds) {\n return {\n type : ds.storeSetType as UpdateByDelta[\"type\"],\n delta : ds.storeSetDelta === \"next\" || ds.storeSetDelta === \"prev\" ? ds.storeSetDelta : Number(ds.storeSetDelta),\n min : Number(ds.storeSetMin) || undefined,\n max : Number(ds.storeSetMax) || undefined,\n useAsValue: ds.storeSetUseAsValue === 'true' || ds.storeSetUseAsValue === '' || false,\n storeId\n };\n } else {\n return {\n devices : Number(ds.storeSetDevices) || undefined,\n subscription: Number(ds.storeSetSubscription) || undefined,\n id : ds.storeSetId,\n campaign : ds.storeSetCampaign,\n bundle : ds.storeSetBundle === 'true' || ds.storeSetBundle === '' || false,\n storeId\n };\n }\n};\n\nexport const dispatchActionAttributes = (el: HTMLElement, attr: ActionAttributes) => {\n if ('type' in attr) {\n el.dispatchEvent(new UpdateByDeltaEvent(attr));\n return;\n }\n\n el.dispatchEvent(new ActionEvent(attr));\n};\n\nconst addLogic = async (el: ActionNode) => {\n if (el.updateComplete) {\n await el.updateComplete;\n }\n\n if (el instanceof HTMLInputElement) {\n connectedCallback(el);\n input(el);\n return;\n }\n\n if (el instanceof HTMLSelectElement) {\n [...el.options]\n .forEach(option => connectedCallback(option as unknown as ActionNode));\n select(el);\n return;\n }\n\n //treat everything else as a button\n button(el);\n connectedCallback(el);\n};\n\nexport const connectedCallback = (el: ActionNode) => {\n if (!el.storeName) {\n el.storeName = Symbol(\"action\");\n }\n\n const attr = readClickAttributes(el);\n if (shouldCollectForNode(el)) {\n if ('type' in attr) {\n el.dispatchEvent(new CollectUpdateByDeltaEvent({ name: el.storeName, update: attr }));\n } else {\n el.dispatchEvent(new CollectActionEvent({ name: el.storeName, action: attr }));\n }\n }\n};\n\nexport const disconnectedCallback = (el: ActionNode) => {\n const attr = readClickAttributes(el);\n if (shouldCollectForNode(el)) {\n if ('type' in attr) {\n el.dispatchEvent(new CollectUpdateByDeltaEvent({\n name : el.storeName,\n update: null\n }));\n } else {\n el.dispatchEvent(new CollectActionEvent({\n name : el.storeName,\n action: null\n }));\n }\n }\n};\n\nexport const handleActionNode = (node: ActionNode) => {\n if (ACTION_BOUND.has(node)) return;\n ACTION_BOUND.add(node);\n addLogic(node);\n};\n\nexport const cleanupActionNode = (node: ActionNode) => {\n teardownActionNode(node);\n};\n\nexport const addEventListener = (el: HTMLElement, type: \"click\" | \"change\", listener: (event: Event) => void) => {\n el.addEventListener(type, listener);\n\n let listenerDisposers = ACTION_LISTENER_DISPOSERS.get(el);\n if (!listenerDisposers) {\n listenerDisposers = new Set<() => void>();\n ACTION_LISTENER_DISPOSERS.set(el, listenerDisposers);\n }\n listenerDisposers.add(() => {\n el.removeEventListener(type, listener);\n });\n\n const actionEl = el as ActionNode;\n if (!ACTION_ORIGINAL_REMOVE.has(actionEl)) {\n const originalRemove = actionEl.remove;\n ACTION_ORIGINAL_REMOVE.set(actionEl, originalRemove);\n\n actionEl.remove = () => {\n teardownActionNode(actionEl);\n originalRemove.call(actionEl);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.datalayer.js","sourceRoot":"","sources":["../../../src/contexts/context.datalayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAU7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAuB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.datalayer.js","sourceRoot":"","sources":["../../../src/contexts/context.datalayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAU7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAuB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\nimport type { ProductOption } from '@repobit/dex-store';\n\nexport type dataLayerPayload = {\n option: ProductOption;\n event : \"all\" | \"info\" | \"comparison\" | (string & {});\n};\n\nexport type dataLayerContextType = ((payload: dataLayerPayload) => void) | undefined;\n\nexport const dataLayerContext = createContext<dataLayerContextType>(Symbol('dataLayer'));\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.derived.js","sourceRoot":"","sources":["../../../src/contexts/context.derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAa7C,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAwC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.derived.js","sourceRoot":"","sources":["../../../src/contexts/context.derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAa7C,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAwC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\nimport { Product, ProductOption, Store } from '@repobit/dex-store';\nimport { stateContextType } from './context.state';\n\nexport type Params = {\n product?: Product | null,\n option? : ProductOption | null,\n state? : stateContextType,\n store? : Store\n};\n\nexport type derivedContextType = (param: Params) => Promise<Record<string, unknown>>\n\nexport const derivedContext = createContext<derivedContextType | undefined | null>(Symbol('derived'));"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.option.js","sourceRoot":"","sources":["../../../src/contexts/context.option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAoB,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.option.js","sourceRoot":"","sources":["../../../src/contexts/context.option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAoB,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\nimport { ProductOption } from '@repobit/dex-store';\n\nexport type optionContextType = Promise<ProductOption | null | undefined> | undefined\nexport const optionContext = createContext<optionContextType>(Symbol('option'));"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.product.js","sourceRoot":"","sources":["../../../src/contexts/context.product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAqB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.product.js","sourceRoot":"","sources":["../../../src/contexts/context.product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAqB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\nimport type { Product } from '@repobit/dex-store';\n\nexport type productContextType = Product | null | undefined;\nexport const productContext = createContext<productContextType>(Symbol('product'));\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.state.js","sourceRoot":"","sources":["../../../src/contexts/context.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAuB7C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAmB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.state.js","sourceRoot":"","sources":["../../../src/contexts/context.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAuB7C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAmB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nexport type MinMax = {\n min: { value: number, fmt: string };\n max: { value: number, fmt: string };\n}\n\ntype Price = MinMax & {\n monthly: MinMax\n}\n\ntype Discount = MinMax & {\n monthly : MinMax,\n percentage: MinMax & {\n monthly: MinMax\n }\n}\n\nexport type stateContextType = {\n price : Price;\n discountedPrice: Price;\n discount : Discount;\n}\nexport const stateContext = createContext<stateContextType>(Symbol('state'));"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.store.js","sourceRoot":"","sources":["../../../src/contexts/context.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAmB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"context.store.js","sourceRoot":"","sources":["../../../src/contexts/context.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAmB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\nimport { Store } from '@repobit/dex-store';\n\nexport type storeContextType = Store | undefined\nexport const storeContext = createContext<storeContextType>(Symbol('store'));"]}
@@ -0,0 +1,39 @@
1
+ import type { CollectAction, CollectOption, CollectUpdateByDelta } from "../events/events.js";
2
+ import { ReactiveController, ReactiveControllerHost } from "lit";
3
+ type CollectHost = ReactiveControllerHost & {
4
+ storeName: symbol | string;
5
+ noCollect: boolean;
6
+ _options: Map<symbol | string, Promise<unknown[]>>;
7
+ _actions: Map<symbol | string, NonNullable<CollectAction["action"]>>;
8
+ _partialOptions: Map<symbol | string, NonNullable<CollectAction["action"]>>;
9
+ _partialBundleOptions: Map<symbol | string, NonNullable<CollectAction["action"]>>;
10
+ _deltaUpdates: Map<symbol | string, NonNullable<CollectUpdateByDelta["update"]>>;
11
+ dispatchEvent(evt: Event): boolean;
12
+ } & EventTarget;
13
+ export declare class CollectController implements ReactiveController {
14
+ private host;
15
+ private _computeAbort;
16
+ private _computeRun;
17
+ private _notifyParent;
18
+ private _contextualChildren;
19
+ private _prevCollect?;
20
+ private _toggleTask;
21
+ constructor(host: CollectHost, computeAbort: () => void, computeRun: () => void, notifyParent: () => void);
22
+ hostConnected(): void;
23
+ hostDisconnected(): void;
24
+ get toggleComplete(): Promise<void>;
25
+ collectOption(detail: CollectOption): void;
26
+ announceRemoval(): void;
27
+ waitForChildrenUpdateComplete(): Promise<void>;
28
+ getContextualChildren(): HTMLElement[];
29
+ private _collectOptionEvent;
30
+ private _collectActionEvent;
31
+ private _collectUpdateByDeltaEvent;
32
+ private _onCollectChild;
33
+ private _onCollectChildRemoved;
34
+ private _announceAsContextualChild;
35
+ private _announceContextualChildRemoved;
36
+ hostUpdate(): void;
37
+ hostUpdated(): void;
38
+ }
39
+ export {};