@repobit/dex-store-elements 1.7.3 → 2.0.1

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 (227) hide show
  1. package/CHANGELOG.md +6 -906
  2. package/README.md +308 -283
  3. package/dist/src/actions/action.adapter.d.ts +36 -0
  4. package/dist/src/actions/action.adapter.js +183 -0
  5. package/dist/src/actions/action.adapter.js.map +1 -0
  6. package/dist/src/actions/action.attributes.d.ts +15 -0
  7. package/dist/src/actions/action.attributes.js +137 -0
  8. package/dist/src/actions/action.attributes.js.map +1 -0
  9. package/dist/src/actions/action.registry.d.ts +4 -0
  10. package/dist/src/actions/action.registry.js +119 -0
  11. package/dist/src/actions/action.registry.js.map +1 -0
  12. package/dist/src/actions/index.d.ts +3 -2
  13. package/dist/src/actions/index.js +3 -80
  14. package/dist/src/actions/index.js.map +1 -1
  15. package/dist/src/compute/compute.expand.d.ts +70 -0
  16. package/dist/src/compute/compute.expand.js +319 -0
  17. package/dist/src/compute/compute.expand.js.map +1 -0
  18. package/dist/src/compute/compute.scan.d.ts +54 -0
  19. package/dist/src/compute/compute.scan.js +160 -0
  20. package/dist/src/compute/compute.scan.js.map +1 -0
  21. package/dist/src/compute/option-resolver.d.ts +31 -0
  22. package/dist/src/compute/option-resolver.js +147 -0
  23. package/dist/src/compute/option-resolver.js.map +1 -0
  24. package/dist/src/contexts/context.compute.d.ts +12 -0
  25. package/dist/src/contexts/context.compute.js +4 -0
  26. package/dist/src/contexts/context.compute.js.map +1 -0
  27. package/dist/src/contexts/context.scope.d.ts +139 -0
  28. package/dist/src/contexts/context.scope.js +48 -0
  29. package/dist/src/contexts/context.scope.js.map +1 -0
  30. package/dist/src/controllers/controller.action-resolve.d.ts +110 -0
  31. package/dist/src/controllers/controller.action-resolve.js +203 -0
  32. package/dist/src/controllers/controller.action-resolve.js.map +1 -0
  33. package/dist/src/controllers/controller.action-topology.d.ts +59 -0
  34. package/dist/src/controllers/controller.action-topology.js +130 -0
  35. package/dist/src/controllers/controller.action-topology.js.map +1 -0
  36. package/dist/src/controllers/controller.compute.d.ts +72 -0
  37. package/dist/src/controllers/controller.compute.js +110 -0
  38. package/dist/src/controllers/controller.compute.js.map +1 -0
  39. package/dist/src/controllers/controller.resolve.d.ts +78 -0
  40. package/dist/src/controllers/controller.resolve.js +205 -0
  41. package/dist/src/controllers/controller.resolve.js.map +1 -0
  42. package/dist/src/core/action-topology.d.ts +62 -0
  43. package/dist/src/core/action-topology.js +67 -0
  44. package/dist/src/core/action-topology.js.map +1 -0
  45. package/dist/src/core/actions.d.ts +64 -0
  46. package/dist/src/core/actions.js +47 -0
  47. package/dist/src/core/actions.js.map +1 -0
  48. package/dist/src/core/node.element.d.ts +179 -0
  49. package/dist/src/core/node.element.js +573 -0
  50. package/dist/src/core/node.element.js.map +1 -0
  51. package/dist/src/core/node.scope.d.ts +374 -0
  52. package/dist/src/core/node.scope.js +558 -0
  53. package/dist/src/core/node.scope.js.map +1 -0
  54. package/dist/src/core/option-update.d.ts +11 -0
  55. package/dist/src/core/option-update.js +59 -0
  56. package/dist/src/core/option-update.js.map +1 -0
  57. package/dist/src/dsl/compilers/array/compiler.js +13 -14
  58. package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
  59. package/dist/src/dsl/compilers/boolean/compiler.d.ts +1 -1
  60. package/dist/src/dsl/compilers/boolean/compiler.js +14 -27
  61. package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
  62. package/dist/src/dsl/compilers/enum/compiler.js +7 -10
  63. package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
  64. package/dist/src/dsl/compilers/index.d.ts +1 -1
  65. package/dist/src/dsl/compilers/index.js +5 -5
  66. package/dist/src/dsl/compilers/index.js.map +1 -1
  67. package/dist/src/dsl/utilty.d.ts +0 -4
  68. package/dist/src/dsl/utilty.js +3 -30
  69. package/dist/src/dsl/utilty.js.map +1 -1
  70. package/dist/src/eta/batch.d.ts +123 -0
  71. package/dist/src/eta/batch.js +162 -0
  72. package/dist/src/eta/batch.js.map +1 -0
  73. package/dist/src/eta/batcher.d.ts +184 -0
  74. package/dist/src/eta/batcher.js +335 -0
  75. package/dist/src/eta/batcher.js.map +1 -0
  76. package/dist/src/eta/cache.d.ts +36 -0
  77. package/dist/src/eta/cache.js +56 -0
  78. package/dist/src/eta/cache.js.map +1 -0
  79. package/dist/src/eta/controller.d.ts +608 -0
  80. package/dist/src/eta/controller.js +1036 -0
  81. package/dist/src/eta/controller.js.map +1 -0
  82. package/dist/src/eta/factory.d.ts +74 -0
  83. package/dist/src/eta/factory.js +121 -0
  84. package/dist/src/eta/factory.js.map +1 -0
  85. package/dist/src/eta/idle.d.ts +39 -0
  86. package/dist/src/eta/idle.js +52 -0
  87. package/dist/src/eta/idle.js.map +1 -0
  88. package/dist/src/eta/index.d.ts +52 -0
  89. package/dist/src/eta/index.js +13 -0
  90. package/dist/src/eta/index.js.map +1 -0
  91. package/dist/src/eta/observer.d.ts +263 -0
  92. package/dist/src/eta/observer.js +263 -0
  93. package/dist/src/eta/observer.js.map +1 -0
  94. package/dist/src/eta/operations.d.ts +41 -0
  95. package/dist/src/eta/operations.js +59 -0
  96. package/dist/src/eta/operations.js.map +1 -0
  97. package/dist/src/eta/source-registry.d.ts +198 -0
  98. package/dist/src/eta/source-registry.js +267 -0
  99. package/dist/src/eta/source-registry.js.map +1 -0
  100. package/dist/src/eta/template-index.d.ts +285 -0
  101. package/dist/src/eta/template-index.js +642 -0
  102. package/dist/src/eta/template-index.js.map +1 -0
  103. package/dist/src/eta/types.d.ts +529 -0
  104. package/dist/src/eta/types.js +2 -0
  105. package/dist/src/eta/types.js.map +1 -0
  106. package/dist/src/index.d.ts +21 -9
  107. package/dist/src/index.js +22 -11
  108. package/dist/src/index.js.map +1 -1
  109. package/dist/src/nodes/node.context.d.ts +5 -3
  110. package/dist/src/nodes/node.context.js +48 -3
  111. package/dist/src/nodes/node.context.js.map +1 -1
  112. package/dist/src/nodes/node.option.d.ts +11 -31
  113. package/dist/src/nodes/node.option.js +158 -222
  114. package/dist/src/nodes/node.option.js.map +1 -1
  115. package/dist/src/nodes/node.product.d.ts +7 -11
  116. package/dist/src/nodes/node.product.js +85 -64
  117. package/dist/src/nodes/node.product.js.map +1 -1
  118. package/dist/src/renders/attributes/buyLink.d.ts +2 -2
  119. package/dist/src/renders/attributes/buyLink.js +14 -11
  120. package/dist/src/renders/attributes/buyLink.js.map +1 -1
  121. package/dist/src/renders/attributes/devices.d.ts +2 -2
  122. package/dist/src/renders/attributes/devices.js +9 -19
  123. package/dist/src/renders/attributes/devices.js.map +1 -1
  124. package/dist/src/renders/attributes/discount.d.ts +2 -2
  125. package/dist/src/renders/attributes/discount.js +56 -44
  126. package/dist/src/renders/attributes/discount.js.map +1 -1
  127. package/dist/src/renders/attributes/hide.d.ts +2 -2
  128. package/dist/src/renders/attributes/hide.js +49 -14
  129. package/dist/src/renders/attributes/hide.js.map +1 -1
  130. package/dist/src/renders/attributes/index.d.ts +3 -3
  131. package/dist/src/renders/attributes/index.js +2 -4
  132. package/dist/src/renders/attributes/index.js.map +1 -1
  133. package/dist/src/renders/attributes/price.d.ts +2 -2
  134. package/dist/src/renders/attributes/price.js +30 -44
  135. package/dist/src/renders/attributes/price.js.map +1 -1
  136. package/dist/src/renders/attributes/subscription.d.ts +2 -2
  137. package/dist/src/renders/attributes/subscription.js +14 -20
  138. package/dist/src/renders/attributes/subscription.js.map +1 -1
  139. package/dist/src/renders/attributes/utilty.d.ts +2 -0
  140. package/dist/src/renders/attributes/utilty.js +17 -4
  141. package/dist/src/renders/attributes/utilty.js.map +1 -1
  142. package/dist/src/renders/context.d.ts +122 -10
  143. package/dist/src/renders/context.js +140 -80
  144. package/dist/src/renders/context.js.map +1 -1
  145. package/dist/src/renders/format.js +2 -2
  146. package/dist/src/renders/format.js.map +1 -1
  147. package/dist/src/renders/index.d.ts +6 -2
  148. package/dist/src/renders/index.js +67 -29
  149. package/dist/src/renders/index.js.map +1 -1
  150. package/dist/src/renders/observe.d.ts +1 -4
  151. package/dist/src/renders/observe.js +10 -24
  152. package/dist/src/renders/observe.js.map +1 -1
  153. package/dist/src/renders/render.wrapper.d.ts +37 -0
  154. package/dist/src/renders/render.wrapper.js +147 -0
  155. package/dist/src/renders/render.wrapper.js.map +1 -0
  156. package/dist/src/templating/eta.js +1 -4
  157. package/dist/src/templating/eta.js.map +1 -1
  158. package/package.json +4 -5
  159. package/dist/src/actions/action.button.d.ts +0 -2
  160. package/dist/src/actions/action.button.js +0 -8
  161. package/dist/src/actions/action.button.js.map +0 -1
  162. package/dist/src/actions/action.input.d.ts +0 -2
  163. package/dist/src/actions/action.input.js +0 -43
  164. package/dist/src/actions/action.input.js.map +0 -1
  165. package/dist/src/actions/action.select.d.ts +0 -2
  166. package/dist/src/actions/action.select.js +0 -14
  167. package/dist/src/actions/action.select.js.map +0 -1
  168. package/dist/src/actions/utilty.d.ts +0 -16
  169. package/dist/src/actions/utilty.js +0 -149
  170. package/dist/src/actions/utilty.js.map +0 -1
  171. package/dist/src/contexts/context.datalayer.d.ts +0 -9
  172. package/dist/src/contexts/context.datalayer.js +0 -3
  173. package/dist/src/contexts/context.datalayer.js.map +0 -1
  174. package/dist/src/contexts/context.derived.d.ts +0 -12
  175. package/dist/src/contexts/context.derived.js +0 -3
  176. package/dist/src/contexts/context.derived.js.map +0 -1
  177. package/dist/src/contexts/context.option.d.ts +0 -5
  178. package/dist/src/contexts/context.option.js +0 -3
  179. package/dist/src/contexts/context.option.js.map +0 -1
  180. package/dist/src/contexts/context.product.d.ts +0 -5
  181. package/dist/src/contexts/context.product.js +0 -3
  182. package/dist/src/contexts/context.product.js.map +0 -1
  183. package/dist/src/contexts/context.state.d.ts +0 -28
  184. package/dist/src/contexts/context.state.js +0 -3
  185. package/dist/src/contexts/context.state.js.map +0 -1
  186. package/dist/src/contexts/context.store.d.ts +0 -5
  187. package/dist/src/contexts/context.store.js +0 -3
  188. package/dist/src/contexts/context.store.js.map +0 -1
  189. package/dist/src/controllers/collect-controller.d.ts +0 -39
  190. package/dist/src/controllers/collect-controller.js +0 -161
  191. package/dist/src/controllers/collect-controller.js.map +0 -1
  192. package/dist/src/controllers/compute-controller.d.ts +0 -55
  193. package/dist/src/controllers/compute-controller.js +0 -350
  194. package/dist/src/controllers/compute-controller.js.map +0 -1
  195. package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +0 -25
  196. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +0 -192
  197. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +0 -1
  198. package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +0 -28
  199. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +0 -206
  200. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +0 -1
  201. package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +0 -21
  202. package/dist/src/controllers/eta-renderer/eta-renderer.js +0 -77
  203. package/dist/src/controllers/eta-renderer/eta-renderer.js.map +0 -1
  204. package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +0 -24
  205. package/dist/src/controllers/eta-renderer/eta-template-cache.js +0 -61
  206. package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +0 -1
  207. package/dist/src/controllers/eta-renderer/eta-types.d.ts +0 -11
  208. package/dist/src/controllers/eta-renderer/eta-types.js +0 -1
  209. package/dist/src/controllers/eta-renderer/eta-types.js.map +0 -1
  210. package/dist/src/controllers/eta-renderer/index.d.ts +0 -2
  211. package/dist/src/controllers/eta-renderer/index.js +0 -2
  212. package/dist/src/controllers/eta-renderer/index.js.map +0 -1
  213. package/dist/src/controllers/event-pipeline-controller.d.ts +0 -28
  214. package/dist/src/controllers/event-pipeline-controller.js +0 -72
  215. package/dist/src/controllers/event-pipeline-controller.js.map +0 -1
  216. package/dist/src/events/events.d.ts +0 -75
  217. package/dist/src/events/events.js +0 -78
  218. package/dist/src/events/events.js.map +0 -1
  219. package/dist/src/nodes/node.root.d.ts +0 -16
  220. package/dist/src/nodes/node.root.js +0 -49
  221. package/dist/src/nodes/node.root.js.map +0 -1
  222. package/dist/src/nodes/node.state.d.ts +0 -88
  223. package/dist/src/nodes/node.state.js +0 -330
  224. package/dist/src/nodes/node.state.js.map +0 -1
  225. package/dist/src/renders/utility.d.ts +0 -32
  226. package/dist/src/renders/utility.js +0 -191
  227. package/dist/src/renders/utility.js.map +0 -1
@@ -4,88 +4,109 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { productContext } from "../contexts/context.product.js";
8
- import { ActionEvent } from "../events/events.js";
9
- import { toDSLContext } from "../renders/context.js";
10
- import { provide } from "@lit/context";
11
- import { Task } from "@lit/task";
12
- import { property } from "lit/decorators.js";
13
- import { StateNode } from "./node.state.js";
14
- export class ProductNode extends StateNode {
7
+ import { extendBdProductScope } from '../contexts/context.scope.js';
8
+ import { BdActionResolveController } from '../controllers/controller.action-resolve.js';
9
+ import { BdScopedElement } from '../core/node.scope.js';
10
+ import { property } from 'lit/decorators.js';
11
+ export class ProductNode extends BdScopedElement {
15
12
  constructor() {
16
13
  super(...arguments);
17
- // Use custom forward tasks; disable default passthrough.
18
- this.autoForward = false;
19
- // Reflect incoming product-change events and forward original event.
20
- this._productChangeEvent = new Task(this, {
21
- task: ([evt]) => {
22
- if (!evt)
23
- return null;
24
- if (this.isProductChange(evt)) {
25
- this.productId = evt.detail.id;
26
- this.campaign = evt.detail.campaign;
14
+ this.bundle = false;
15
+ this._workflow = new BdActionResolveController(this, {
16
+ name: 'product',
17
+ args: () => [
18
+ this.parentScope,
19
+ this.productId,
20
+ this.campaign,
21
+ this.bundle
22
+ ],
23
+ transition: ([parentScope]) => parentScope?.transition,
24
+ derive: ([parentScope, productId, campaign, bundle], { transition }) => {
25
+ const action = transition?.command.kind === 'set-action'
26
+ ? transition.command.action
27
+ : undefined;
28
+ /**
29
+ * Bundle-only actions (set-action with `bundle: true`)
30
+ * are NOT a product switch — they mean "add the named
31
+ * product as a bundle on the current option". The
32
+ * product node must keep publishing the current
33
+ * product scope so `OptionNode` can toggle the bundle
34
+ * against it. Forwarding `action.id` /
35
+ * `action.campaign` here would race the option node
36
+ * and produce a `scope.product` that disagrees with
37
+ * the resolved `scope.option`.
38
+ */
39
+ if (action?.bundle) {
40
+ return [
41
+ parentScope,
42
+ productId,
43
+ campaign,
44
+ bundle
45
+ ];
27
46
  }
28
- this._forwardAndNotify(evt);
47
+ return [
48
+ parentScope,
49
+ action?.id ?? productId,
50
+ action?.campaign ?? campaign,
51
+ action?.bundle ?? bundle
52
+ ];
29
53
  },
30
- args: () => [this._event]
31
- });
32
- // Synthesize product-change events when attributes change locally.
33
- this._forwardEventTask = new Task(this, {
34
- task: ([id, campaign]) => {
35
- const evt = this._event;
36
- if (evt && this.isProductChange(evt)) {
37
- const { id: evtId, campaign: evtCampaign } = evt.detail;
38
- if (evtId === id && evtCampaign === campaign) {
39
- return; // skip resynthesizing if mirroring incoming event
40
- }
41
- }
42
- if (id) {
43
- this._forwardAndNotify(new ActionEvent({ id, campaign }));
54
+ enabled: ([parentScope, productId]) => Boolean(parentScope?.store &&
55
+ productId),
56
+ resolve: async ([parentScope, productId, campaign]) => {
57
+ if (!parentScope?.store || !productId) {
58
+ return undefined;
44
59
  }
60
+ return await parentScope.store.getProduct({
61
+ id: productId,
62
+ campaign
63
+ });
45
64
  },
46
- args: () => [this.productId, this.campaign]
47
- });
48
- this._loadProductTask = new Task(this, {
49
- task: async ([store, id, campaign]) => {
50
- if (!store || !id) {
65
+ filterTransition: (candidate) => this._filterTransition(candidate),
66
+ commit: (product, [parentScope, productId, campaign, bundle], _resolveContext, actionContext) => {
67
+ if (!product ||
68
+ !parentScope ||
69
+ !productId) {
51
70
  this.product = undefined;
52
- return undefined;
71
+ this.clearScope();
72
+ return;
53
73
  }
54
- const product = await store.getProduct({ id, campaign });
55
74
  this.product = product;
56
- return product;
75
+ this.productId = productId;
76
+ this.campaign = campaign;
77
+ this.bundle = bundle;
78
+ this.publishScope(extendBdProductScope(parentScope, product, actionContext.transition));
57
79
  },
58
- args: () => [this._store, this.productId, this.campaign]
80
+ onDisabled: () => {
81
+ this.product = undefined;
82
+ this.clearScope();
83
+ }
59
84
  });
60
85
  }
61
- _forwardAndNotify(event) {
62
- this._forwardEvent(event);
63
- this._notifyParent();
64
- }
65
- getEtaArgs() {
66
- return [this.product, this.state, this._derived];
67
- }
68
- async buildEtaContext() {
69
- if (!this.product)
70
- return undefined;
71
- return await toDSLContext({ product: this.product, state: this.state, derived: this._derived });
72
- }
73
- async getUpdateComplete() {
74
- const result = await super.getUpdateComplete();
75
- await this._productChangeEvent.taskComplete;
76
- await this._forwardEventTask.taskComplete;
77
- await this._loadProductTask.taskComplete;
78
- return result;
86
+ get scope() {
87
+ return this.currentScope;
79
88
  }
80
89
  }
81
90
  __decorate([
82
- property({ attribute: 'product-id', reflect: true })
91
+ property({
92
+ attribute: 'product-id',
93
+ reflect: true
94
+ })
83
95
  ], ProductNode.prototype, "productId", void 0);
84
96
  __decorate([
85
- property({ reflect: true })
97
+ property({
98
+ reflect: true
99
+ })
86
100
  ], ProductNode.prototype, "campaign", void 0);
87
101
  __decorate([
88
- provide({ context: productContext }),
89
- property({ attribute: false })
102
+ property({
103
+ type: Boolean,
104
+ reflect: true
105
+ })
106
+ ], ProductNode.prototype, "bundle", void 0);
107
+ __decorate([
108
+ property({
109
+ attribute: false
110
+ })
90
111
  ], ProductNode.prototype, "product", void 0);
91
112
  //# sourceMappingURL=node.product.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.product.js","sourceRoot":"","sources":["../../../src/nodes/node.product.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBA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C;IACnD,CAAC;IAEQ,KAAK,CAAC,eAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QACpC,OAAO,MAAM,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClG,CAAC;IAES,KAAK,CAAC,iBAAiB;QAC/B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC/C,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC;QAC5C,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;QAC1C,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC;QACzC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAzEC;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8CAClC;AAGnB;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACV;AAIlB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4CACb","sourcesContent":["import { productContext } from \"@/contexts/context.product\";\nimport { ActionEvent } from \"@/events/events\";\nimport { toDSLContext } from \"@/renders/context\";\nimport { provide } from \"@lit/context\";\nimport { Task } from \"@lit/task\";\nimport type { Product } from \"@repobit/dex-store\";\nimport { property } from \"lit/decorators.js\";\nimport { StateNode } from \"./node.state\";\n\nexport class ProductNode extends StateNode {\n // Use custom forward tasks; disable default passthrough.\n autoForward = false;\n @property({ attribute: 'product-id', reflect: true })\n productId?: string;\n\n @property({ reflect: true })\n campaign?: string;\n\n @provide({ context: productContext })\n @property({ attribute: false })\n product?: Product;\n\n private _forwardAndNotify(event?: ActionEvent) {\n this._forwardEvent(event);\n this._notifyParent();\n }\n\n // Reflect incoming product-change events and forward original event.\n private _productChangeEvent = new Task(this, {\n task: ([evt]) => {\n if (!evt) return null;\n if (this.isProductChange(evt)) {\n this.productId = evt.detail.id;\n this.campaign = evt.detail.campaign;\n }\n this._forwardAndNotify(evt);\n },\n args: () => [this._event]\n });\n\n // Synthesize product-change events when attributes change locally.\n private _forwardEventTask = new Task(this, {\n task: ([id, campaign]) => {\n const evt = this._event;\n if (evt && this.isProductChange(evt)) {\n const { id: evtId, campaign: evtCampaign } = evt.detail;\n if (evtId === id && evtCampaign === campaign) {\n return; // skip resynthesizing if mirroring incoming event\n }\n }\n if (id) {\n this._forwardAndNotify(new ActionEvent({ id, campaign }));\n }\n },\n args: () => [this.productId, this.campaign]\n });\n\n private _loadProductTask = new Task(this, {\n task: async ([store, id, campaign]) => {\n if (!store || !id) {\n this.product = undefined;\n return undefined;\n }\n const product = await store.getProduct({ id, campaign });\n this.product = product;\n return product;\n },\n args: () => [this._store, this.productId, this.campaign]\n });\n\n override getEtaArgs(): unknown[] {\n return [this.product, this.state, this._derived];\n }\n\n override async buildEtaContext(): Promise<object | undefined> {\n if (!this.product) return undefined;\n return await toDSLContext({ product: this.product, state: this.state, derived: this._derived });\n }\n\n protected async getUpdateComplete() {\n const result = await super.getUpdateComplete();\n await this._productChangeEvent.taskComplete;\n await this._forwardEventTask.taskComplete;\n await this._loadProductTask.taskComplete;\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"node.product.js","sourceRoot":"","sources":["../../../src/nodes/node.product.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,oBAAoB,EAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,OAAO,WAAY,SA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d,CAAC;2CACa;AAKf;IAHC,QAAQ,CAAC;QACR,SAAS,EAAE,KAAK;KACjB,CAAC;4CACgB","sourcesContent":["import {\n extendBdProductScope,\n type BdScope\n} from '@/contexts/context.scope.js';\nimport { BdActionResolveController } from '@/controllers/controller.action-resolve.js';\nimport { BdScopedElement } from '@/core/node.scope.js';\nimport type { Product } from '@repobit/dex-store';\nimport { property } from 'lit/decorators.js';\n\nexport class ProductNode extends BdScopedElement {\n @property({\n attribute: 'product-id',\n reflect : true\n })\n productId?: string;\n\n @property({\n reflect: true\n })\n campaign?: string;\n\n @property({\n type : Boolean,\n reflect: true\n })\n bundle = false;\n\n @property({\n attribute: false\n })\n product?: Product;\n\n private readonly _workflow =\n new BdActionResolveController(\n this,\n {\n name: 'product',\n args: () => [\n this.parentScope,\n this.productId,\n this.campaign,\n this.bundle\n ] as const,\n transition: ([parentScope]) =>\n parentScope?.transition,\n derive: ([\n parentScope,\n productId,\n campaign,\n bundle\n ], { transition }) => {\n const action =\n transition?.command.kind === 'set-action'\n ? transition.command.action\n : undefined;\n\n /**\n * Bundle-only actions (set-action with `bundle: true`)\n * are NOT a product switch they mean \"add the named\n * product as a bundle on the current option\". The\n * product node must keep publishing the current\n * product scope so `OptionNode` can toggle the bundle\n * against it. Forwarding `action.id` /\n * `action.campaign` here would race the option node\n * and produce a `scope.product` that disagrees with\n * the resolved `scope.option`.\n */\n if (action?.bundle) {\n return [\n parentScope,\n productId,\n campaign,\n bundle\n ] as const;\n }\n\n return [\n parentScope,\n action?.id ?? productId,\n action?.campaign ?? campaign,\n action?.bundle ?? bundle\n ] as const;\n },\n enabled: ([parentScope, productId]) =>\n Boolean(\n parentScope?.store &&\n productId\n ),\n resolve: async ([\n parentScope,\n productId,\n campaign\n ]) => {\n if (!parentScope?.store || !productId) {\n return undefined;\n }\n\n return await parentScope.store.getProduct({\n id: productId,\n campaign\n });\n },\n filterTransition: (candidate) =>\n this._filterTransition(candidate),\n commit: (\n product,\n [\n parentScope,\n productId,\n campaign,\n bundle\n ],\n _resolveContext,\n actionContext\n ) => {\n if (\n !product ||\n !parentScope ||\n !productId\n ) {\n this.product = undefined;\n this.clearScope();\n return;\n }\n\n this.product = product;\n this.productId = productId;\n this.campaign = campaign;\n this.bundle = bundle;\n\n this.publishScope(\n extendBdProductScope(\n parentScope,\n product,\n actionContext.transition\n )\n );\n },\n onDisabled: () => {\n this.product = undefined;\n this.clearScope();\n }\n }\n );\n\n get scope(): BdScope | undefined {\n return this.currentScope;\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handleBuyLink: (el: HTMLElement, ctx: UnifiedContext) => void;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handleBuyLink: (el: HTMLElement, ctx: RenderContext) => void;
@@ -1,24 +1,27 @@
1
+ import { getDiscountedPrice } from '../context.js';
1
2
  import { resolveAnchor } from './utilty.js';
2
3
  export const handleBuyLink = (el, ctx) => {
3
4
  const { storeBuyLink } = el.dataset;
4
- if (storeBuyLink === undefined)
5
- return;
6
- const option = ctx.option;
7
- if (!option)
5
+ if (storeBuyLink === undefined || !ctx.option) {
8
6
  return;
7
+ }
9
8
  const link = resolveAnchor(el);
10
- if (!link)
9
+ if (!link) {
11
10
  return;
11
+ }
12
+ const option = ctx.option;
12
13
  const product = option.getProduct();
13
- const discountedPrice = option.getDiscountedPrice({ currency: false });
14
14
  const fullPrice = option.getPrice({ currency: false });
15
- const trialLink = storeBuyLink ? option.getTrialLink(storeBuyLink) : undefined;
16
- link.href = trialLink ?? option.getBuyLink();
15
+ const discountedPrice = getDiscountedPrice(option);
16
+ const trialLink = storeBuyLink
17
+ ? option.getTrialLink(storeBuyLink)
18
+ : undefined;
19
+ link.href = trialLink ?? option.getBuyLink() ?? '';
17
20
  link.dataset.product = product.getAlias();
18
21
  link.dataset.vlaicuProduct = product.getId();
19
- link.dataset.buyPrice = discountedPrice ? String(discountedPrice) : String(fullPrice);
22
+ link.dataset.buyPrice = discountedPrice ?? String(fullPrice);
20
23
  link.dataset.oldPrice = String(fullPrice);
21
- link.dataset.currency = product.getCurrency();
22
- link.dataset.variation = `${option.getDevices()}u-${option.getSubscription()}m`;
24
+ link.dataset.variation =
25
+ `${option.getDevices()}u-${option.getSubscription()}m`;
23
26
  };
24
27
  //# sourceMappingURL=buyLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buyLink.js","sourceRoot":"","sources":["../../../../src/renders/attributes/buyLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACpE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IACpC,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO;IACvC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO;IAElB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACpC,MAAM,eAAe,GAAG,MAAM,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IAEvD,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,IAAI,CAAC,IAAI,GAAG,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7C,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7C,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtF,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,KAAK,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC;AAClF,CAAC,CAAC","sourcesContent":["import type { UnifiedContext } from '../context';\nimport { resolveAnchor } from './utilty';\n\nexport const handleBuyLink = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storeBuyLink } = el.dataset;\n if (storeBuyLink === undefined) return;\n const option = ctx.option;\n if (!option) return;\n\n const link = resolveAnchor(el);\n if (!link) return;\n\n const product = option.getProduct();\n const discountedPrice = option.getDiscountedPrice({ currency: false });\n const fullPrice = option.getPrice({ currency: false });\n\n const trialLink = storeBuyLink ? option.getTrialLink(storeBuyLink) : undefined;\n link.href = trialLink ?? option.getBuyLink();\n link.dataset.product = product.getAlias();\n link.dataset.vlaicuProduct = product.getId();\n link.dataset.buyPrice = discountedPrice ? String(discountedPrice) : String(fullPrice);\n link.dataset.oldPrice = String(fullPrice);\n link.dataset.currency = product.getCurrency();\n link.dataset.variation = `${option.getDevices()}u-${option.getSubscription()}m`;\n};\n"]}
1
+ {"version":3,"file":"buyLink.js","sourceRoot":"","sources":["../../../../src/renders/attributes/buyLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa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context.js';\nimport { getDiscountedPrice } from '../context.js';\nimport { resolveAnchor } from './utilty.js';\n\nexport const handleBuyLink = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const { storeBuyLink } = el.dataset;\n\n if (storeBuyLink === undefined || !ctx.option) {\n return;\n }\n\n const link = resolveAnchor(el);\n\n if (!link) {\n return;\n }\n\n const option = ctx.option;\n const product = option.getProduct();\n const fullPrice = option.getPrice({ currency: false });\n const discountedPrice = getDiscountedPrice(option);\n\n const trialLink = storeBuyLink\n ? option.getTrialLink(storeBuyLink)\n : undefined;\n\n link.href = trialLink ?? option.getBuyLink() ?? '';\n link.dataset.product = product.getAlias();\n link.dataset.vlaicuProduct = product.getId();\n link.dataset.buyPrice = discountedPrice ?? String(fullPrice);\n link.dataset.oldPrice = String(fullPrice);\n link.dataset.variation =\n `${option.getDevices()}u-${option.getSubscription()}m`;\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handleDevices: (el: HTMLElement, ctx: UnifiedContext) => void;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handleDevices: (el: HTMLElement, ctx: RenderContext) => void;
@@ -1,32 +1,22 @@
1
1
  import { Compiler } from '../../dsl/compilers/index.js';
2
2
  import { formatDevices } from '../../renders/format.js';
3
+ import { buildSelectOptions } from './utilty.js';
3
4
  export const handleDevices = (el, ctx) => {
4
5
  const { storeDevices, storeTextSingle, storeTextMany } = el.dataset;
5
- if (storeDevices === undefined)
6
+ if (storeDevices === undefined || !ctx.option) {
6
7
  return;
7
- const option = ctx.option;
8
- if (!option)
9
- return;
10
- // input
8
+ }
11
9
  if (el instanceof HTMLInputElement) {
12
- el.value = String(option.getDevices());
10
+ el.value = String(ctx.option.getDevices());
13
11
  return;
14
12
  }
15
- // select
16
13
  if (el instanceof HTMLSelectElement) {
17
- const selectedDevices = option.getDevices();
18
- const available = Compiler.array(storeDevices) ?? option.getProduct().getDevices().values;
19
- el.options.length = 0;
20
- for (const device of available) {
21
- const isSelected = device === selectedDevices;
22
- const text = formatDevices(device, storeTextSingle, storeTextMany);
23
- const htmlOption = new Option(text, String(device), isSelected, isSelected);
24
- htmlOption.setAttribute('data-store-set-devices', String(device));
25
- el.add(htmlOption);
26
- }
14
+ const selectedDevices = ctx.option.getDevices();
15
+ const available = Compiler.array(storeDevices) ??
16
+ ctx.option.getProduct().getDevices().values;
17
+ buildSelectOptions(el, available, selectedDevices, (device) => formatDevices(device, storeTextSingle, storeTextMany), 'data-store-set-devices');
27
18
  return;
28
19
  }
29
- // generic content
30
- el.textContent = String(option.getDevices());
20
+ el.textContent = String(ctx.option.getDevices());
31
21
  };
32
22
  //# sourceMappingURL=devices.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"devices.js","sourceRoot":"","sources":["../../../../src/renders/attributes/devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACpE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IACpE,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO;IACvC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,QAAQ;IACR,IAAI,EAAE,YAAY,gBAAgB,EAAE,CAAC;QACnC,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,SAAS;IACT,IAAI,EAAE,YAAY,iBAAiB,EAAE,CAAC;QACpC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC;QAE1F,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACtB,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,CAAC;YAC/B,MAAM,UAAU,GAAG,MAAM,KAAK,eAAe,CAAC;YAC9C,MAAM,IAAI,GAAG,aAAa,CACxB,MAAM,EACN,eAAe,EACf,aAAa,CACd,CAAC;YACF,MAAM,UAAU,GAAG,IAAI,MAAM,CAC3B,IAAI,EACJ,MAAM,CAAC,MAAM,CAAC,EACd,UAAU,EACV,UAAU,CACX,CAAC;YACF,UAAU,CAAC,YAAY,CAAC,wBAAwB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAClE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC;QACD,OAAO;IACT,CAAC;IAED,kBAAkB;IAClB,EAAE,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport { formatDevices } from '@/renders/format';\nimport type { UnifiedContext } from '../context';\n\nexport const handleDevices = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storeDevices, storeTextSingle, storeTextMany } = el.dataset;\n if (storeDevices === undefined) return;\n const option = ctx.option;\n if (!option) return;\n\n // input\n if (el instanceof HTMLInputElement) {\n el.value = String(option.getDevices());\n return;\n }\n\n // select\n if (el instanceof HTMLSelectElement) {\n const selectedDevices = option.getDevices();\n const available = Compiler.array(storeDevices) ?? option.getProduct().getDevices().values;\n\n el.options.length = 0;\n for (const device of available) {\n const isSelected = device === selectedDevices;\n const text = formatDevices(\n device,\n storeTextSingle,\n storeTextMany\n );\n const htmlOption = new Option(\n text,\n String(device),\n isSelected,\n isSelected\n );\n htmlOption.setAttribute('data-store-set-devices', String(device));\n el.add(htmlOption);\n }\n return;\n }\n\n // generic content\n el.textContent = String(option.getDevices());\n};\n"]}
1
+ {"version":3,"file":"devices.js","sourceRoot":"","sources":["../../../../src/renders/attributes/devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,YAAY,EACZ,eAAe,EACf,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IAEf,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,IAAI,EAAE,YAAY,gBAAgB,EAAE,CAAC;QACnC,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC3C,OAAO;IACT,CAAC;IAED,IAAI,EAAE,YAAY,iBAAiB,EAAE,CAAC;QACpC,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAChD,MAAM,SAAS,GACb,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;YAC5B,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC;QAE9C,kBAAkB,CAChB,EAAE,EACF,SAAS,EACT,eAAe,EACf,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CACvB,MAAM,EACN,eAAe,EACf,aAAa,CACd,EACD,wBAAwB,CACzB,CAAC;QAEF,OAAO;IACT,CAAC;IAED,EAAE,CAAC,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport { formatDevices } from '@/renders/format.js';\nimport type { RenderContext } from '../context.js';\nimport { buildSelectOptions } from './utilty.js';\n\nexport const handleDevices = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeDevices,\n storeTextSingle,\n storeTextMany\n } = el.dataset;\n\n if (storeDevices === undefined || !ctx.option) {\n return;\n }\n\n if (el instanceof HTMLInputElement) {\n el.value = String(ctx.option.getDevices());\n return;\n }\n\n if (el instanceof HTMLSelectElement) {\n const selectedDevices = ctx.option.getDevices();\n const available =\n Compiler.array(storeDevices) ??\n ctx.option.getProduct().getDevices().values;\n\n buildSelectOptions(\n el,\n available,\n selectedDevices,\n (device) => formatDevices(\n device,\n storeTextSingle,\n storeTextMany\n ),\n 'data-store-set-devices'\n );\n\n return;\n }\n\n el.textContent = String(ctx.option.getDevices());\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handleDiscount: (el: HTMLElement, ctx: UnifiedContext) => void;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handleDiscount: (el: HTMLElement, ctx: RenderContext) => void;
@@ -1,7 +1,13 @@
1
1
  import { Compiler } from '../../dsl/compilers/index.js';
2
+ import { getDiscount } from '../context.js';
2
3
  import { isPresent } from './utilty.js';
3
- const OPTION_DISCOUNT_TOKENS = ['value', 'percentage', 'value-monthly', 'percentage-monthly'];
4
- const STATE_DISCOUNT_TOKENS = [
4
+ const OPTION_DISCOUNT_TOKENS = [
5
+ 'value',
6
+ 'percentage',
7
+ 'value-monthly',
8
+ 'percentage-monthly'
9
+ ];
10
+ const COMPUTE_DISCOUNT_TOKENS = [
5
11
  'min-value',
6
12
  'max-value',
7
13
  'min-percentage',
@@ -11,64 +17,70 @@ const STATE_DISCOUNT_TOKENS = [
11
17
  'min-percentage-monthly',
12
18
  'max-percentage-monthly'
13
19
  ];
14
- const OPTION_DISCOUNT_AVAILABLE = {
15
- 'value': (option) => isPresent(option.getDiscount({ symbol: false, percentage: false })),
16
- 'percentage': (option) => isPresent(option.getDiscount({ symbol: false, percentage: true })),
17
- 'value-monthly': (option) => isPresent(option.getDiscount({ symbol: false, percentage: false, monthly: true })),
18
- 'percentage-monthly': (option) => isPresent(option.getDiscount({ symbol: false, percentage: true, monthly: true }))
19
- };
20
- const OPTION_DISCOUNT_RENDER = {
21
- 'value': (option) => option.getDiscount({ percentage: false }),
22
- 'percentage': (option) => option.getDiscount({ percentage: true }),
23
- 'value-monthly': (option) => option.getDiscount({ percentage: false, monthly: true }),
24
- 'percentage-monthly': (option) => option.getDiscount({ percentage: true, monthly: true })
25
- };
26
- const STATE_DISCOUNT_AVAILABLE = {
27
- 'min-value': (state) => Boolean(state.discount.min.fmt),
28
- 'max-value': (state) => Boolean(state.discount.max.fmt),
29
- 'min-value-monthly': (state) => Boolean(state.discount.monthly.min.fmt),
30
- 'max-value-monthly': (state) => Boolean(state.discount.monthly.max.fmt),
31
- 'min-percentage': (state) => Boolean(state.discount.percentage.min.fmt),
32
- 'max-percentage': (state) => Boolean(state.discount.percentage.max.fmt),
33
- 'min-percentage-monthly': (state) => Boolean(state.discount.percentage.monthly.min.fmt),
34
- 'max-percentage-monthly': (state) => Boolean(state.discount.percentage.monthly.max.fmt)
35
- };
36
- const STATE_DISCOUNT_RENDER = {
37
- 'min-value': (state) => state.discount.min.fmt,
38
- 'max-value': (state) => state.discount.max.fmt,
39
- 'min-value-monthly': (state) => state.discount.monthly.min.fmt,
40
- 'max-value-monthly': (state) => state.discount.monthly.max.fmt,
41
- 'min-percentage': (state) => state.discount.percentage.min.fmt,
42
- 'max-percentage': (state) => state.discount.percentage.max.fmt,
43
- 'min-percentage-monthly': (state) => state.discount.percentage.monthly.min.fmt,
44
- 'max-percentage-monthly': (state) => state.discount.percentage.monthly.max.fmt
45
- };
46
- // Handles both data-store-discount (option-level) and data-store-context-discount (state-level)
47
20
  export const handleDiscount = (el, ctx) => {
48
21
  const { storeDiscount, storeContextDiscount } = el.dataset;
49
22
  const option = ctx.option;
50
- // Option-level discount
51
23
  if (storeDiscount && option) {
24
+ const renderers = {
25
+ 'value': () => getDiscount(option, { percentage: false }),
26
+ 'percentage': () => getDiscount(option, { percentage: true }),
27
+ 'value-monthly': () => getDiscount(option, {
28
+ percentage: false,
29
+ monthly: true
30
+ }),
31
+ 'percentage-monthly': () => getDiscount(option, {
32
+ percentage: true,
33
+ monthly: true
34
+ })
35
+ };
36
+ const available = {
37
+ 'value': () => getDiscount(option, {
38
+ symbol: false,
39
+ percentage: false
40
+ }),
41
+ 'percentage': () => getDiscount(option, {
42
+ symbol: false,
43
+ percentage: true
44
+ }),
45
+ 'value-monthly': () => getDiscount(option, {
46
+ symbol: false,
47
+ percentage: false,
48
+ monthly: true
49
+ }),
50
+ 'percentage-monthly': () => getDiscount(option, {
51
+ symbol: false,
52
+ percentage: true,
53
+ monthly: true
54
+ })
55
+ };
52
56
  const chosen = Compiler.enum({
53
57
  expr: storeDiscount,
54
58
  allowed: OPTION_DISCOUNT_TOKENS,
55
- isAvailable: (token) => OPTION_DISCOUNT_AVAILABLE[token](option)
59
+ isAvailable: (token) => isPresent(available[token]())
56
60
  });
57
61
  if (chosen) {
58
- el.textContent = OPTION_DISCOUNT_RENDER[chosen](option);
62
+ el.textContent = renderers[chosen]() ?? '';
59
63
  return;
60
64
  }
61
65
  }
62
- const state = ctx.state;
63
- // State-level discount
64
- if (storeContextDiscount && state) {
66
+ if (storeContextDiscount && ctx.compute) {
67
+ const renderers = {
68
+ 'min-value': () => ctx.compute?.discount.min.fmt,
69
+ 'max-value': () => ctx.compute?.discount.max.fmt,
70
+ 'min-percentage': () => ctx.compute?.discount.percentage.min.fmt,
71
+ 'max-percentage': () => ctx.compute?.discount.percentage.max.fmt,
72
+ 'min-value-monthly': () => ctx.compute?.discount.monthly.min.fmt,
73
+ 'max-value-monthly': () => ctx.compute?.discount.monthly.max.fmt,
74
+ 'min-percentage-monthly': () => ctx.compute?.discount.percentage.monthly.min.fmt,
75
+ 'max-percentage-monthly': () => ctx.compute?.discount.percentage.monthly.max.fmt
76
+ };
65
77
  const chosen = Compiler.enum({
66
78
  expr: storeContextDiscount,
67
- allowed: STATE_DISCOUNT_TOKENS,
68
- isAvailable: (token) => STATE_DISCOUNT_AVAILABLE[token](state)
79
+ allowed: COMPUTE_DISCOUNT_TOKENS,
80
+ isAvailable: (token) => isPresent(renderers[token]())
69
81
  });
70
82
  if (chosen) {
71
- el.textContent = STATE_DISCOUNT_RENDER[chosen](state);
83
+ el.textContent = renderers[chosen]() ?? '';
72
84
  }
73
85
  }
74
86
  };
@@ -1 +1 @@
1
- {"version":3,"file":"discount.js","sourceRoot":"","sources":["../../../../src/renders/attributes/discount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,CAAU,CAAC;AAIvG,MAAM,qBAAqB,GAAG;IAC5B,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,mBAAmB;IACnB,mBAAmB;IACnB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAIX,MAAM,yBAAyB,GAAG;IAChC,OAAO,EAAe,CAAC,MAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAChH,YAAY,EAAU,CAAC,MAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/G,eAAe,EAAO,CAAC,MAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,KA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CAAC,WAAW,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport type { UnifiedContext } from '../context';\nimport { isPresent } from './utilty';\n\nconst OPTION_DISCOUNT_TOKENS = ['value', 'percentage', 'value-monthly', 'percentage-monthly'] as const;\ntype OptionDiscountToken = typeof OPTION_DISCOUNT_TOKENS[number];\ntype OptionCtx = NonNullable<UnifiedContext['option']>;\n\nconst STATE_DISCOUNT_TOKENS = [\n 'min-value',\n 'max-value',\n 'min-percentage',\n 'max-percentage',\n 'min-value-monthly',\n 'max-value-monthly',\n 'min-percentage-monthly',\n 'max-percentage-monthly'\n] as const;\ntype StateDiscountToken = typeof STATE_DISCOUNT_TOKENS[number];\ntype StateCtx = NonNullable<UnifiedContext['state']>;\n\nconst OPTION_DISCOUNT_AVAILABLE = {\n 'value' : (option: OptionCtx) => isPresent(option.getDiscount({ symbol: false, percentage: false })),\n 'percentage' : (option: OptionCtx) => isPresent(option.getDiscount({ symbol: false, percentage: true })),\n 'value-monthly' : (option: OptionCtx) => isPresent(option.getDiscount({ symbol: false, percentage: false, monthly: true })),\n 'percentage-monthly': (option: OptionCtx) => isPresent(option.getDiscount({ symbol: false, percentage: true, monthly: true }))\n} satisfies Record<OptionDiscountToken, (option: OptionCtx) => boolean>;\n\nconst OPTION_DISCOUNT_RENDER = {\n 'value' : (option: OptionCtx) => option.getDiscount({ percentage: false }),\n 'percentage' : (option: OptionCtx) => option.getDiscount({ percentage: true }),\n 'value-monthly' : (option: OptionCtx) => option.getDiscount({ percentage: false, monthly: true }),\n 'percentage-monthly': (option: OptionCtx) => option.getDiscount({ percentage: true, monthly: true })\n} satisfies Record<OptionDiscountToken, (option: OptionCtx) => string>;\n\nconst STATE_DISCOUNT_AVAILABLE = {\n 'min-value' : (state: StateCtx) => Boolean(state.discount.min.fmt),\n 'max-value' : (state: StateCtx) => Boolean(state.discount.max.fmt),\n 'min-value-monthly' : (state: StateCtx) => Boolean(state.discount.monthly.min.fmt),\n 'max-value-monthly' : (state: StateCtx) => Boolean(state.discount.monthly.max.fmt),\n 'min-percentage' : (state: StateCtx) => Boolean(state.discount.percentage.min.fmt),\n 'max-percentage' : (state: StateCtx) => Boolean(state.discount.percentage.max.fmt),\n 'min-percentage-monthly': (state: StateCtx) => Boolean(state.discount.percentage.monthly.min.fmt),\n 'max-percentage-monthly': (state: StateCtx) => Boolean(state.discount.percentage.monthly.max.fmt)\n} satisfies Record<StateDiscountToken, (state: StateCtx) => boolean>;\n\nconst STATE_DISCOUNT_RENDER = {\n 'min-value' : (state: StateCtx) => state.discount.min.fmt,\n 'max-value' : (state: StateCtx) => state.discount.max.fmt,\n 'min-value-monthly' : (state: StateCtx) => state.discount.monthly.min.fmt,\n 'max-value-monthly' : (state: StateCtx) => state.discount.monthly.max.fmt,\n 'min-percentage' : (state: StateCtx) => state.discount.percentage.min.fmt,\n 'max-percentage' : (state: StateCtx) => state.discount.percentage.max.fmt,\n 'min-percentage-monthly': (state: StateCtx) => state.discount.percentage.monthly.min.fmt,\n 'max-percentage-monthly': (state: StateCtx) => state.discount.percentage.monthly.max.fmt\n} satisfies Record<StateDiscountToken, (state: StateCtx) => string>;\n\n// Handles both data-store-discount (option-level) and data-store-context-discount (state-level)\nexport const handleDiscount = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storeDiscount, storeContextDiscount } = el.dataset;\n const option = ctx.option;\n\n // Option-level discount\n if (storeDiscount && option) {\n const chosen = Compiler.enum<OptionDiscountToken>({\n expr : storeDiscount,\n allowed : OPTION_DISCOUNT_TOKENS,\n isAvailable: (token) => OPTION_DISCOUNT_AVAILABLE[token](option)\n });\n\n if (chosen) {\n el.textContent = OPTION_DISCOUNT_RENDER[chosen](option);\n return;\n }\n }\n\n const state = ctx.state;\n\n // State-level discount\n if (storeContextDiscount && state) {\n const chosen = Compiler.enum<StateDiscountToken>({\n expr : storeContextDiscount,\n allowed : STATE_DISCOUNT_TOKENS,\n isAvailable: (token) => STATE_DISCOUNT_AVAILABLE[token](state)\n });\n\n if (chosen) {\n el.textContent = STATE_DISCOUNT_RENDER[chosen](state);\n }\n }\n};\n"]}
1
+ {"version":3,"file":"discount.js","sourceRoot":"","sources":["../../../../src/renders/attributes/discount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,sBAAsB,GAAG;IAC7B,OAAO;IACP,YAAY;IACZ,eAAe;IACf,oBAAoB;CACZ,CAAC;AAIX,MAAM,uBAAuB,GAAG;IAC9B,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,mBAAmB;IACnB,mBAAmB;IACnB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAIX,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,aAAa,EACb,oBAAoB,EACrB,GAAG,EAAE,CAAC,OAAO,CAAC;IACf,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAE1B,IAAI,aAAa,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG;YAChB,OAAO,EAAE,GAAG,EAAE,CACZ,WAAW,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;YAC5C,YAAY,EAAE,GAAG,EAAE,CACjB,WAAW,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;YAC3C,eAAe,EAAE,GAAG,EAAE,CACpB,WAAW,CAAC,MAAM,EAAE;gBAClB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAK,IAAI;aACjB,CAAC;YACJ,oBAAoB,EAAE,GAAG,EAAE,CACzB,W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G,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG;YAC7D,gBAAgB,EAAU,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG;YACxE,gBAAgB,EAAU,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG;YACxE,mBAAmB,EAAO,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;YACrE,mBAAmB,EAAO,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;YACrE,wBAAwB,EAAE,GAAG,EAAE,CAC7B,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;YAClD,wBAAwB,EAAE,GAAG,EAAE,CAC7B,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;SACc,CAAC;QAEnE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAuB;YACjD,IAAI,EAAS,oBAAoB;YACjC,OAAO,EAAM,uBAAuB;YACpC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;SACtD,CAAC,CAAC;QAEH,IAAI,MAAM,EAAE,CAAC;YACX,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;QAC7C,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport type { RenderContext } from '../context.js';\nimport { getDiscount } from '../context.js';\nimport { isPresent } from './utilty.js';\n\nconst OPTION_DISCOUNT_TOKENS = [\n 'value',\n 'percentage',\n 'value-monthly',\n 'percentage-monthly'\n] as const;\n\ntype OptionDiscountToken = typeof OPTION_DISCOUNT_TOKENS[number];\n\nconst COMPUTE_DISCOUNT_TOKENS = [\n 'min-value',\n 'max-value',\n 'min-percentage',\n 'max-percentage',\n 'min-value-monthly',\n 'max-value-monthly',\n 'min-percentage-monthly',\n 'max-percentage-monthly'\n] as const;\n\ntype ComputeDiscountToken = typeof COMPUTE_DISCOUNT_TOKENS[number];\n\nexport const handleDiscount = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeDiscount,\n storeContextDiscount\n } = el.dataset;\n const option = ctx.option;\n\n if (storeDiscount && option) {\n const renderers = {\n 'value': () =>\n getDiscount(option, { percentage: false }),\n 'percentage': () =>\n getDiscount(option, { percentage: true }),\n 'value-monthly': () =>\n getDiscount(option, {\n percentage: false,\n monthly : true\n }),\n 'percentage-monthly': () =>\n getDiscount(option, {\n percentage: true,\n monthly : true\n })\n } satisfies Record<OptionDiscountToken, () => string | undefined>;\n\n const available = {\n 'value': () =>\n getDiscount(option, {\n symbol : false,\n percentage: false\n }),\n 'percentage': () =>\n getDiscount(option, {\n symbol : false,\n percentage: true\n }),\n 'value-monthly': () =>\n getDiscount(option, {\n symbol : false,\n percentage: false,\n monthly : true\n }),\n 'percentage-monthly': () =>\n getDiscount(option, {\n symbol : false,\n percentage: true,\n monthly : true\n })\n } satisfies Record<OptionDiscountToken, () => string | undefined>;\n\n const chosen = Compiler.enum<OptionDiscountToken>({\n expr : storeDiscount,\n allowed : OPTION_DISCOUNT_TOKENS,\n isAvailable: (token) => isPresent(available[token]())\n });\n\n if (chosen) {\n el.textContent = renderers[chosen]() ?? '';\n return;\n }\n }\n\n if (storeContextDiscount && ctx.compute) {\n const renderers = {\n 'min-value' : () => ctx.compute?.discount.min.fmt,\n 'max-value' : () => ctx.compute?.discount.max.fmt,\n 'min-percentage' : () => ctx.compute?.discount.percentage.min.fmt,\n 'max-percentage' : () => ctx.compute?.discount.percentage.max.fmt,\n 'min-value-monthly' : () => ctx.compute?.discount.monthly.min.fmt,\n 'max-value-monthly' : () => ctx.compute?.discount.monthly.max.fmt,\n 'min-percentage-monthly': () =>\n ctx.compute?.discount.percentage.monthly.min.fmt,\n 'max-percentage-monthly': () =>\n ctx.compute?.discount.percentage.monthly.max.fmt\n } satisfies Record<ComputeDiscountToken, () => string | undefined>;\n\n const chosen = Compiler.enum<ComputeDiscountToken>({\n expr : storeContextDiscount,\n allowed : COMPUTE_DISCOUNT_TOKENS,\n isAvailable: (token) => isPresent(renderers[token]())\n });\n\n if (chosen) {\n el.textContent = renderers[chosen]() ?? '';\n }\n }\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handleHide: (el: HTMLElement, ctx: UnifiedContext) => Promise<void>;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handleHide: (el: HTMLElement, ctx: RenderContext) => void;