@repobit/dex-store-elements 1.7.2 → 2.0.0
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.
- package/CHANGELOG.md +5 -905
- package/README.md +9 -7
- package/dist/src/actions/action.adapter.d.ts +36 -0
- package/dist/src/actions/action.adapter.js +183 -0
- package/dist/src/actions/action.adapter.js.map +1 -0
- package/dist/src/actions/action.attributes.d.ts +15 -0
- package/dist/src/actions/action.attributes.js +137 -0
- package/dist/src/actions/action.attributes.js.map +1 -0
- package/dist/src/actions/action.registry.d.ts +4 -0
- package/dist/src/actions/action.registry.js +119 -0
- package/dist/src/actions/action.registry.js.map +1 -0
- package/dist/src/actions/index.d.ts +3 -2
- package/dist/src/actions/index.js +3 -80
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/compute/compute.expand.d.ts +70 -0
- package/dist/src/compute/compute.expand.js +319 -0
- package/dist/src/compute/compute.expand.js.map +1 -0
- package/dist/src/compute/compute.scan.d.ts +54 -0
- package/dist/src/compute/compute.scan.js +160 -0
- package/dist/src/compute/compute.scan.js.map +1 -0
- package/dist/src/compute/option-resolver.d.ts +31 -0
- package/dist/src/compute/option-resolver.js +147 -0
- package/dist/src/compute/option-resolver.js.map +1 -0
- package/dist/src/contexts/context.compute.d.ts +12 -0
- package/dist/src/contexts/context.compute.js +4 -0
- package/dist/src/contexts/context.compute.js.map +1 -0
- package/dist/src/contexts/context.scope.d.ts +139 -0
- package/dist/src/contexts/context.scope.js +48 -0
- package/dist/src/contexts/context.scope.js.map +1 -0
- package/dist/src/controllers/controller.action-resolve.d.ts +110 -0
- package/dist/src/controllers/controller.action-resolve.js +203 -0
- package/dist/src/controllers/controller.action-resolve.js.map +1 -0
- package/dist/src/controllers/controller.action-topology.d.ts +59 -0
- package/dist/src/controllers/controller.action-topology.js +130 -0
- package/dist/src/controllers/controller.action-topology.js.map +1 -0
- package/dist/src/controllers/controller.compute.d.ts +72 -0
- package/dist/src/controllers/controller.compute.js +110 -0
- package/dist/src/controllers/controller.compute.js.map +1 -0
- package/dist/src/controllers/controller.resolve.d.ts +78 -0
- package/dist/src/controllers/controller.resolve.js +205 -0
- package/dist/src/controllers/controller.resolve.js.map +1 -0
- package/dist/src/core/action-topology.d.ts +62 -0
- package/dist/src/core/action-topology.js +67 -0
- package/dist/src/core/action-topology.js.map +1 -0
- package/dist/src/core/actions.d.ts +64 -0
- package/dist/src/core/actions.js +47 -0
- package/dist/src/core/actions.js.map +1 -0
- package/dist/src/core/node.element.d.ts +179 -0
- package/dist/src/core/node.element.js +573 -0
- package/dist/src/core/node.element.js.map +1 -0
- package/dist/src/core/node.scope.d.ts +374 -0
- package/dist/src/core/node.scope.js +558 -0
- package/dist/src/core/node.scope.js.map +1 -0
- package/dist/src/core/option-update.d.ts +11 -0
- package/dist/src/core/option-update.js +59 -0
- package/dist/src/core/option-update.js.map +1 -0
- package/dist/src/dsl/compilers/array/compiler.js +13 -14
- package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/boolean/compiler.d.ts +1 -1
- package/dist/src/dsl/compilers/boolean/compiler.js +14 -27
- package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/enum/compiler.js +7 -10
- package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/index.d.ts +1 -1
- package/dist/src/dsl/compilers/index.js +5 -5
- package/dist/src/dsl/compilers/index.js.map +1 -1
- package/dist/src/dsl/utilty.d.ts +0 -4
- package/dist/src/dsl/utilty.js +3 -30
- package/dist/src/dsl/utilty.js.map +1 -1
- package/dist/src/eta/batch.d.ts +123 -0
- package/dist/src/eta/batch.js +162 -0
- package/dist/src/eta/batch.js.map +1 -0
- package/dist/src/eta/batcher.d.ts +184 -0
- package/dist/src/eta/batcher.js +335 -0
- package/dist/src/eta/batcher.js.map +1 -0
- package/dist/src/eta/cache.d.ts +36 -0
- package/dist/src/eta/cache.js +56 -0
- package/dist/src/eta/cache.js.map +1 -0
- package/dist/src/eta/controller.d.ts +608 -0
- package/dist/src/eta/controller.js +1036 -0
- package/dist/src/eta/controller.js.map +1 -0
- package/dist/src/eta/factory.d.ts +74 -0
- package/dist/src/eta/factory.js +121 -0
- package/dist/src/eta/factory.js.map +1 -0
- package/dist/src/eta/idle.d.ts +39 -0
- package/dist/src/eta/idle.js +52 -0
- package/dist/src/eta/idle.js.map +1 -0
- package/dist/src/eta/index.d.ts +52 -0
- package/dist/src/eta/index.js +13 -0
- package/dist/src/eta/index.js.map +1 -0
- package/dist/src/eta/observer.d.ts +263 -0
- package/dist/src/eta/observer.js +263 -0
- package/dist/src/eta/observer.js.map +1 -0
- package/dist/src/eta/operations.d.ts +41 -0
- package/dist/src/eta/operations.js +59 -0
- package/dist/src/eta/operations.js.map +1 -0
- package/dist/src/eta/source-registry.d.ts +198 -0
- package/dist/src/eta/source-registry.js +267 -0
- package/dist/src/eta/source-registry.js.map +1 -0
- package/dist/src/eta/template-index.d.ts +285 -0
- package/dist/src/eta/template-index.js +642 -0
- package/dist/src/eta/template-index.js.map +1 -0
- package/dist/src/eta/types.d.ts +529 -0
- package/dist/src/eta/types.js +2 -0
- package/dist/src/eta/types.js.map +1 -0
- package/dist/src/index.d.ts +21 -9
- package/dist/src/index.js +22 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/nodes/node.context.d.ts +5 -3
- package/dist/src/nodes/node.context.js +48 -3
- package/dist/src/nodes/node.context.js.map +1 -1
- package/dist/src/nodes/node.option.d.ts +11 -31
- package/dist/src/nodes/node.option.js +158 -222
- package/dist/src/nodes/node.option.js.map +1 -1
- package/dist/src/nodes/node.product.d.ts +7 -11
- package/dist/src/nodes/node.product.js +85 -64
- package/dist/src/nodes/node.product.js.map +1 -1
- package/dist/src/renders/attributes/buyLink.d.ts +2 -2
- package/dist/src/renders/attributes/buyLink.js +14 -11
- package/dist/src/renders/attributes/buyLink.js.map +1 -1
- package/dist/src/renders/attributes/devices.d.ts +2 -2
- package/dist/src/renders/attributes/devices.js +9 -19
- package/dist/src/renders/attributes/devices.js.map +1 -1
- package/dist/src/renders/attributes/discount.d.ts +2 -2
- package/dist/src/renders/attributes/discount.js +56 -44
- package/dist/src/renders/attributes/discount.js.map +1 -1
- package/dist/src/renders/attributes/hide.d.ts +2 -2
- package/dist/src/renders/attributes/hide.js +49 -14
- package/dist/src/renders/attributes/hide.js.map +1 -1
- package/dist/src/renders/attributes/index.d.ts +3 -3
- package/dist/src/renders/attributes/index.js +2 -4
- package/dist/src/renders/attributes/index.js.map +1 -1
- package/dist/src/renders/attributes/price.d.ts +2 -2
- package/dist/src/renders/attributes/price.js +30 -44
- package/dist/src/renders/attributes/price.js.map +1 -1
- package/dist/src/renders/attributes/subscription.d.ts +2 -2
- package/dist/src/renders/attributes/subscription.js +14 -20
- package/dist/src/renders/attributes/subscription.js.map +1 -1
- package/dist/src/renders/attributes/utilty.d.ts +2 -0
- package/dist/src/renders/attributes/utilty.js +17 -4
- package/dist/src/renders/attributes/utilty.js.map +1 -1
- package/dist/src/renders/context.d.ts +122 -10
- package/dist/src/renders/context.js +140 -80
- package/dist/src/renders/context.js.map +1 -1
- package/dist/src/renders/format.js +2 -2
- package/dist/src/renders/format.js.map +1 -1
- package/dist/src/renders/index.d.ts +6 -2
- package/dist/src/renders/index.js +67 -29
- package/dist/src/renders/index.js.map +1 -1
- package/dist/src/renders/observe.d.ts +1 -4
- package/dist/src/renders/observe.js +10 -24
- package/dist/src/renders/observe.js.map +1 -1
- package/dist/src/renders/render.wrapper.d.ts +37 -0
- package/dist/src/renders/render.wrapper.js +147 -0
- package/dist/src/renders/render.wrapper.js.map +1 -0
- package/dist/src/templating/eta.js +1 -4
- package/dist/src/templating/eta.js.map +1 -1
- package/package.json +4 -5
- package/dist/src/actions/action.button.d.ts +0 -2
- package/dist/src/actions/action.button.js +0 -8
- package/dist/src/actions/action.button.js.map +0 -1
- package/dist/src/actions/action.input.d.ts +0 -2
- package/dist/src/actions/action.input.js +0 -43
- package/dist/src/actions/action.input.js.map +0 -1
- package/dist/src/actions/action.select.d.ts +0 -2
- package/dist/src/actions/action.select.js +0 -14
- package/dist/src/actions/action.select.js.map +0 -1
- package/dist/src/actions/utilty.d.ts +0 -16
- package/dist/src/actions/utilty.js +0 -149
- package/dist/src/actions/utilty.js.map +0 -1
- package/dist/src/contexts/context.datalayer.d.ts +0 -9
- package/dist/src/contexts/context.datalayer.js +0 -3
- package/dist/src/contexts/context.datalayer.js.map +0 -1
- package/dist/src/contexts/context.derived.d.ts +0 -12
- package/dist/src/contexts/context.derived.js +0 -3
- package/dist/src/contexts/context.derived.js.map +0 -1
- package/dist/src/contexts/context.option.d.ts +0 -5
- package/dist/src/contexts/context.option.js +0 -3
- package/dist/src/contexts/context.option.js.map +0 -1
- package/dist/src/contexts/context.product.d.ts +0 -5
- package/dist/src/contexts/context.product.js +0 -3
- package/dist/src/contexts/context.product.js.map +0 -1
- package/dist/src/contexts/context.state.d.ts +0 -28
- package/dist/src/contexts/context.state.js +0 -3
- package/dist/src/contexts/context.state.js.map +0 -1
- package/dist/src/contexts/context.store.d.ts +0 -5
- package/dist/src/contexts/context.store.js +0 -3
- package/dist/src/contexts/context.store.js.map +0 -1
- package/dist/src/controllers/collect-controller.d.ts +0 -39
- package/dist/src/controllers/collect-controller.js +0 -161
- package/dist/src/controllers/collect-controller.js.map +0 -1
- package/dist/src/controllers/compute-controller.d.ts +0 -55
- package/dist/src/controllers/compute-controller.js +0 -350
- package/dist/src/controllers/compute-controller.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +0 -25
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +0 -192
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +0 -28
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +0 -206
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +0 -21
- package/dist/src/controllers/eta-renderer/eta-renderer.js +0 -77
- package/dist/src/controllers/eta-renderer/eta-renderer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +0 -24
- package/dist/src/controllers/eta-renderer/eta-template-cache.js +0 -61
- package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-types.d.ts +0 -11
- package/dist/src/controllers/eta-renderer/eta-types.js +0 -1
- package/dist/src/controllers/eta-renderer/eta-types.js.map +0 -1
- package/dist/src/controllers/eta-renderer/index.d.ts +0 -2
- package/dist/src/controllers/eta-renderer/index.js +0 -2
- package/dist/src/controllers/eta-renderer/index.js.map +0 -1
- package/dist/src/controllers/event-pipeline-controller.d.ts +0 -28
- package/dist/src/controllers/event-pipeline-controller.js +0 -72
- package/dist/src/controllers/event-pipeline-controller.js.map +0 -1
- package/dist/src/events/events.d.ts +0 -75
- package/dist/src/events/events.js +0 -78
- package/dist/src/events/events.js.map +0 -1
- package/dist/src/nodes/node.root.d.ts +0 -16
- package/dist/src/nodes/node.root.js +0 -49
- package/dist/src/nodes/node.root.js.map +0 -1
- package/dist/src/nodes/node.state.d.ts +0 -88
- package/dist/src/nodes/node.state.js +0 -330
- package/dist/src/nodes/node.state.js.map +0 -1
- package/dist/src/renders/utility.d.ts +0 -32
- package/dist/src/renders/utility.js +0 -191
- 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 {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
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
|
-
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
47
|
+
return [
|
|
48
|
+
parentScope,
|
|
49
|
+
action?.id ?? productId,
|
|
50
|
+
action?.campaign ?? campaign,
|
|
51
|
+
action?.bundle ?? bundle
|
|
52
|
+
];
|
|
29
53
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
71
|
+
this.clearScope();
|
|
72
|
+
return;
|
|
53
73
|
}
|
|
54
|
-
const product = await store.getProduct({ id, campaign });
|
|
55
74
|
this.product = product;
|
|
56
|
-
|
|
75
|
+
this.productId = productId;
|
|
76
|
+
this.campaign = campaign;
|
|
77
|
+
this.bundle = bundle;
|
|
78
|
+
this.publishScope(extendBdProductScope(parentScope, product, actionContext.transition));
|
|
57
79
|
},
|
|
58
|
-
|
|
80
|
+
onDisabled: () => {
|
|
81
|
+
this.product = undefined;
|
|
82
|
+
this.clearScope();
|
|
83
|
+
}
|
|
59
84
|
});
|
|
60
85
|
}
|
|
61
|
-
|
|
62
|
-
this.
|
|
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({
|
|
91
|
+
property({
|
|
92
|
+
attribute: 'product-id',
|
|
93
|
+
reflect: true
|
|
94
|
+
})
|
|
83
95
|
], ProductNode.prototype, "productId", void 0);
|
|
84
96
|
__decorate([
|
|
85
|
-
property({
|
|
97
|
+
property({
|
|
98
|
+
reflect: true
|
|
99
|
+
})
|
|
86
100
|
], ProductNode.prototype, "campaign", void 0);
|
|
87
101
|
__decorate([
|
|
88
|
-
|
|
89
|
-
|
|
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,
|
|
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,SAAQ,eAAe;IAAhD;;QAgBE,WAAM,GAAG,KAAK,CAAC;QAOE,cAAS,GACxB,IAAI,yBAAyB,CAC3B,IAAI,EACJ;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,GAAG,EAAE,CAAC;gBACV,IAAI,CAAC,WAAW;gBAChB,IAAI,CAAC,SAAS;gBACd,IAAI,CAAC,QAAQ;gBACb,IAAI,CAAC,MAAM;aACH;YACV,UAAU,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,CAC5B,WAAW,EAAE,UAAU;YACzB,MAAM,EAAE,CAAC,CACP,WAAW,EACX,SAAS,EACT,QAAQ,EACR,MAAM,CACP,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;gBACnB,MAAM,MAAM,GACV,UAAU,EAAE,OAAO,CAAC,IAAI,KAAK,YAAY;oBACvC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM;oBAC3B,CAAC,CAAC,SAAS,CAAC;gBAEhB;;;;;;;;;;mBAUG;gBACH,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;oBACnB,OAAO;wBACL,WAAW;wBACX,SAAS;wBACT,QAAQ;wBACR,MAAM;qBACE,CAAC;gBACb,CAAC;gBAED,OAAO;oBACL,WAAW;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ACD,UAAU,EAAE,GAAG,EAAE;gBACf,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBACzB,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,CAAC;SACF,CACF,CAAC;IAKN,CAAC;IAHC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAtIC;IAJC,QAAQ,CAAC;QACR,SAAS,EAAE,YAAY;QACvB,OAAO,EAAI,IAAI;KAChB,CAAC;8CACiB;AAKnB;IAHC,QAAQ,CAAC;QACR,OAAO,EAAE,IAAI;KACd,CAAC;6CACgB;AAMlB;IAJC,QAAQ,CAAC;QACR,IAAI,EAAK,OAAO;QAChB,OAAO,EAAE,IAAI;KACd,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 {
|
|
2
|
-
export declare const handleBuyLink: (el: HTMLElement, ctx:
|
|
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
|
|
16
|
-
|
|
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
|
|
22
|
+
link.dataset.buyPrice = discountedPrice ?? String(fullPrice);
|
|
20
23
|
link.dataset.oldPrice = String(fullPrice);
|
|
21
|
-
link.dataset.
|
|
22
|
-
|
|
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,
|
|
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,GAAG,CAC3B,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IAEpC,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAE/B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACpC,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAEnD,MAAM,SAAS,GAAG,YAAY;QAC5B,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,CAAC,IAAI,GAAG,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;IACnD,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,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,SAAS;QACpB,GAAG,MAAM,CAAC,UAAU,EAAE,KAAK,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC;AAC3D,CAAC,CAAC","sourcesContent":["import type { RenderContext } from '../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 {
|
|
2
|
-
export declare const handleDevices: (el: HTMLElement, ctx:
|
|
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
|
-
|
|
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) ??
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
2
|
-
export declare const handleDiscount: (el: HTMLElement, ctx:
|
|
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 = [
|
|
4
|
-
|
|
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) =>
|
|
59
|
+
isAvailable: (token) => isPresent(available[token]())
|
|
56
60
|
});
|
|
57
61
|
if (chosen) {
|
|
58
|
-
el.textContent =
|
|
62
|
+
el.textContent = renderers[chosen]() ?? '';
|
|
59
63
|
return;
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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:
|
|
68
|
-
isAvailable: (token) =>
|
|
79
|
+
allowed: COMPUTE_DISCOUNT_TOKENS,
|
|
80
|
+
isAvailable: (token) => isPresent(renderers[token]())
|
|
69
81
|
});
|
|
70
82
|
if (chosen) {
|
|
71
|
-
el.textContent =
|
|
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,
|
|
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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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 {
|
|
2
|
-
export declare const handleHide: (el: HTMLElement, ctx:
|
|
1
|
+
import type { RenderContext } from '../context.js';
|
|
2
|
+
export declare const handleHide: (el: HTMLElement, ctx: RenderContext) => void;
|