@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
|
@@ -1,28 +1,63 @@
|
|
|
1
1
|
import { Compiler } from '../../dsl/compilers/index.js';
|
|
2
2
|
import { toDSLContext } from '../context.js';
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const HIDE_MODES = new WeakMap();
|
|
4
|
+
function normalizeHideMode(mode) {
|
|
5
|
+
if (mode === 'opacity' ||
|
|
6
|
+
mode === 'visibility') {
|
|
5
7
|
return mode;
|
|
8
|
+
}
|
|
6
9
|
return 'display';
|
|
7
|
-
}
|
|
8
|
-
|
|
10
|
+
}
|
|
11
|
+
function applyHideMode(el, mode, hide) {
|
|
12
|
+
const previousMode = HIDE_MODES.get(el);
|
|
13
|
+
if (previousMode &&
|
|
14
|
+
previousMode !== mode) {
|
|
15
|
+
resetHideMode(el, previousMode);
|
|
16
|
+
}
|
|
17
|
+
if (!hide) {
|
|
18
|
+
resetHideMode(el, mode);
|
|
19
|
+
HIDE_MODES.delete(el);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
HIDE_MODES.set(el, mode);
|
|
9
23
|
if (mode === 'opacity') {
|
|
10
|
-
el.style.opacity =
|
|
24
|
+
el.style.opacity = '0';
|
|
11
25
|
return;
|
|
12
26
|
}
|
|
13
27
|
if (mode === 'visibility') {
|
|
14
|
-
el.style.visibility =
|
|
28
|
+
el.style.visibility = 'hidden';
|
|
15
29
|
return;
|
|
16
30
|
}
|
|
17
|
-
el.style.display =
|
|
18
|
-
}
|
|
19
|
-
|
|
31
|
+
el.style.display = 'none';
|
|
32
|
+
}
|
|
33
|
+
function resetHideMode(el, mode) {
|
|
34
|
+
if (mode === 'opacity') {
|
|
35
|
+
el.style.opacity = '';
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (mode === 'visibility') {
|
|
39
|
+
el.style.visibility = '';
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
el.style.display = '';
|
|
43
|
+
}
|
|
44
|
+
function resetAppliedHideMode(el) {
|
|
45
|
+
const previousMode = HIDE_MODES.get(el);
|
|
46
|
+
if (!previousMode) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
resetHideMode(el, previousMode);
|
|
50
|
+
HIDE_MODES.delete(el);
|
|
51
|
+
}
|
|
52
|
+
export const handleHide = (el, ctx) => {
|
|
20
53
|
const { storeHide, storeHideType } = el.dataset;
|
|
21
|
-
if (!storeHide)
|
|
54
|
+
if (!storeHide) {
|
|
55
|
+
resetAppliedHideMode(el);
|
|
22
56
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
57
|
+
}
|
|
58
|
+
applyHideMode(el, normalizeHideMode(storeHideType), Compiler.boolean({
|
|
59
|
+
expr: storeHide,
|
|
60
|
+
ctx: toDSLContext(ctx)
|
|
61
|
+
}));
|
|
27
62
|
};
|
|
28
63
|
//# sourceMappingURL=hide.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide.js","sourceRoot":"","sources":["../../../../src/renders/attributes/hide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hide.js","sourceRoot":"","sources":["../../../../src/renders/attributes/hide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C,MAAM,UAAU,GAAG,IAAI,OAAO,EAAyB,CAAC;AAExD,SAAS,iBAAiB,CACxB,IAAa;IAEb,IACE,IAAI,KAAK,SAAS;QAClB,IAAI,KAAK,YAAY,EACrB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,aAAa,CACpB,EAAe,EACf,IAAc,EACd,IAAa;IAEb,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAExC,IACE,YAAY;QACZ,YAAY,KAAK,IAAI,EACrB,CAAC;QACD,aAAa,CACX,EAAE,EACF,YAAY,CACb,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,aAAa,CACX,EAAE,EACF,IAAI,CACL,CAAC;QACF,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO;IACT,CAAC;IAED,UAAU,CAAC,GAAG,CACZ,EAAE,EACF,IAAI,CACL,CAAC;IAEF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QACvB,OAAO;IACT,CAAC;IAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAC1B,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC/B,OAAO;IACT,CAAC;IAED,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;AAC5B,CAAC;AAED,SAAS,aAAa,CACpB,EAAe,EACf,IAAc;IAEd,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAC1B,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,SAAS,oBAAoB,CAC3B,EAAe;IAEf,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAExC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IAED,aAAa,CACX,EAAE,EACF,YAAY,CACb,CAAC;IACF,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,SAAS,EACT,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IAEf,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,oBAAoB,CAAC,EAAE,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,aAAa,CACX,EAAE,EACF,iBAAiB,CAAC,aAAa,CAAC,EAChC,QAAQ,CAAC,OAAO,CAAC;QACf,IAAI,EAAE,SAAS;QACf,GAAG,EAAG,YAAY,CAAC,GAAG,CAAC;KACxB,CAAC,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport type { RenderContext } from '../context.js';\nimport { toDSLContext } from '../context.js';\n\ntype HideMode = 'display' | 'opacity' | 'visibility';\n\nconst HIDE_MODES = new WeakMap<HTMLElement, HideMode>();\n\nfunction normalizeHideMode(\n mode?: string\n): HideMode {\n if (\n mode === 'opacity' ||\n mode === 'visibility'\n ) {\n return mode;\n }\n\n return 'display';\n}\n\nfunction applyHideMode(\n el: HTMLElement,\n mode: HideMode,\n hide: boolean\n): void {\n const previousMode = HIDE_MODES.get(el);\n\n if (\n previousMode &&\n previousMode !== mode\n ) {\n resetHideMode(\n el,\n previousMode\n );\n }\n\n if (!hide) {\n resetHideMode(\n el,\n mode\n );\n HIDE_MODES.delete(el);\n return;\n }\n\n HIDE_MODES.set(\n el,\n mode\n );\n\n if (mode === 'opacity') {\n el.style.opacity = '0';\n return;\n }\n\n if (mode === 'visibility') {\n el.style.visibility = 'hidden';\n return;\n }\n\n el.style.display = 'none';\n}\n\nfunction resetHideMode(\n el: HTMLElement,\n mode: HideMode\n): void {\n if (mode === 'opacity') {\n el.style.opacity = '';\n return;\n }\n\n if (mode === 'visibility') {\n el.style.visibility = '';\n return;\n }\n\n el.style.display = '';\n}\n\nfunction resetAppliedHideMode(\n el: HTMLElement\n): void {\n const previousMode = HIDE_MODES.get(el);\n\n if (!previousMode) {\n return;\n }\n\n resetHideMode(\n el,\n previousMode\n );\n HIDE_MODES.delete(el);\n}\n\nexport const handleHide = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeHide,\n storeHideType\n } = el.dataset;\n\n if (!storeHide) {\n resetAppliedHideMode(el);\n return;\n }\n\n applyHideMode(\n el,\n normalizeHideMode(storeHideType),\n Compiler.boolean({\n expr: storeHide,\n ctx : toDSLContext(ctx)\n })\n );\n};\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type AttributeHandler = (el: HTMLElement, ctx:
|
|
3
|
-
export declare const renderAttributes: (el: HTMLElement, ctx:
|
|
1
|
+
import type { RenderContext } from '../context.js';
|
|
2
|
+
export type AttributeHandler = (el: HTMLElement, ctx: RenderContext) => void | Promise<void>;
|
|
3
|
+
export declare const renderAttributes: (el: HTMLElement, ctx: RenderContext) => Promise<void>;
|
|
@@ -4,7 +4,6 @@ import { handleDiscount } from './discount.js';
|
|
|
4
4
|
import { handleHide } from './hide.js';
|
|
5
5
|
import { handlePrice } from './price.js';
|
|
6
6
|
import { handleSubscription } from './subscription.js';
|
|
7
|
-
// Dispatch known attribute handlers. Order matters for conflicts; keep hide last.
|
|
8
7
|
const handlers = [
|
|
9
8
|
handleDevices,
|
|
10
9
|
handleSubscription,
|
|
@@ -12,11 +11,10 @@ const handlers = [
|
|
|
12
11
|
handlePrice,
|
|
13
12
|
handleDiscount,
|
|
14
13
|
handleHide
|
|
15
|
-
// further handlers (devices, subscription, links) will be pushed here
|
|
16
14
|
];
|
|
17
15
|
export const renderAttributes = async (el, ctx) => {
|
|
18
|
-
for (const
|
|
19
|
-
await
|
|
16
|
+
for (const handler of handlers) {
|
|
17
|
+
await handler(el, ctx);
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renders/attributes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renders/attributes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAOvD,MAAM,QAAQ,GAAuB;IACnC,aAAa;IACb,kBAAkB;IAClB,aAAa;IACb,WAAW;IACX,cAAc;IACd,UAAU;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,EAAe,EACf,GAAkB,EACH,EAAE;IACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,CACX,EAAE,EACF,GAAG,CACJ,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { RenderContext } from '../context.js';\nimport { handleBuyLink } from './buyLink.js';\nimport { handleDevices } from './devices.js';\nimport { handleDiscount } from './discount.js';\nimport { handleHide } from './hide.js';\nimport { handlePrice } from './price.js';\nimport { handleSubscription } from './subscription.js';\n\nexport type AttributeHandler = (\n el: HTMLElement,\n ctx: RenderContext\n) => void | Promise<void>;\n\nconst handlers: AttributeHandler[] = [\n handleDevices,\n handleSubscription,\n handleBuyLink,\n handlePrice,\n handleDiscount,\n handleHide\n];\n\nexport const renderAttributes = async (\n el: HTMLElement,\n ctx: RenderContext\n): Promise<void> => {\n for (const handler of handlers) {\n await handler(\n el,\n ctx\n );\n }\n};\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const handlePrice: (el: HTMLElement, ctx:
|
|
1
|
+
import type { RenderContext } from '../context.js';
|
|
2
|
+
export declare const handlePrice: (el: HTMLElement, ctx: RenderContext) => void;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Compiler } from '../../dsl/compilers/index.js';
|
|
2
|
+
import { getDiscountedPrice } from '../context.js';
|
|
2
3
|
import { isPresent } from './utilty.js';
|
|
3
|
-
const OPTION_PRICE_TOKENS = [
|
|
4
|
-
|
|
4
|
+
const OPTION_PRICE_TOKENS = [
|
|
5
|
+
'full',
|
|
6
|
+
'discounted',
|
|
7
|
+
'full-monthly',
|
|
8
|
+
'discounted-monthly'
|
|
9
|
+
];
|
|
10
|
+
const COMPUTE_PRICE_TOKENS = [
|
|
5
11
|
'min-full',
|
|
6
12
|
'max-full',
|
|
7
13
|
'min-discounted',
|
|
@@ -11,64 +17,44 @@ const STATE_PRICE_TOKENS = [
|
|
|
11
17
|
'min-discounted-monthly',
|
|
12
18
|
'max-discounted-monthly'
|
|
13
19
|
];
|
|
14
|
-
const OPTION_PRICE_AVAILABLE = {
|
|
15
|
-
'full': (option) => isPresent(option.getPrice({ currency: false })),
|
|
16
|
-
'discounted': (option) => isPresent(option.getDiscountedPrice({ currency: false })),
|
|
17
|
-
'full-monthly': (option) => isPresent(option.getPrice({ currency: false, monthly: true })),
|
|
18
|
-
'discounted-monthly': (option) => isPresent(option.getDiscountedPrice({ currency: false, monthly: true }))
|
|
19
|
-
};
|
|
20
|
-
const OPTION_PRICE_RENDER = {
|
|
21
|
-
'full': (option) => option.getPrice(),
|
|
22
|
-
'discounted': (option) => option.getDiscountedPrice(),
|
|
23
|
-
'full-monthly': (option) => option.getPrice({ monthly: true }),
|
|
24
|
-
'discounted-monthly': (option) => option.getDiscountedPrice({ monthly: true })
|
|
25
|
-
};
|
|
26
|
-
const STATE_PRICE_AVAILABLE = {
|
|
27
|
-
'min-full': (state) => Boolean(state.price.min.fmt),
|
|
28
|
-
'max-full': (state) => Boolean(state.price.max.fmt),
|
|
29
|
-
'min-full-monthly': (state) => Boolean(state.price.monthly.min.fmt),
|
|
30
|
-
'max-full-monthly': (state) => Boolean(state.price.monthly.max.fmt),
|
|
31
|
-
'min-discounted': (state) => Boolean(state.discountedPrice.min.fmt),
|
|
32
|
-
'max-discounted': (state) => Boolean(state.discountedPrice.max.fmt),
|
|
33
|
-
'min-discounted-monthly': (state) => Boolean(state.discountedPrice.monthly.min.fmt),
|
|
34
|
-
'max-discounted-monthly': (state) => Boolean(state.discountedPrice.monthly.max.fmt)
|
|
35
|
-
};
|
|
36
|
-
const STATE_PRICE_RENDER = {
|
|
37
|
-
'min-full': (state) => state.price.min.fmt,
|
|
38
|
-
'max-full': (state) => state.price.max.fmt,
|
|
39
|
-
'min-full-monthly': (state) => state.price.monthly.min.fmt,
|
|
40
|
-
'max-full-monthly': (state) => state.price.monthly.max.fmt,
|
|
41
|
-
'min-discounted': (state) => state.discountedPrice.min.fmt,
|
|
42
|
-
'max-discounted': (state) => state.discountedPrice.max.fmt,
|
|
43
|
-
'min-discounted-monthly': (state) => state.discountedPrice.monthly.min.fmt,
|
|
44
|
-
'max-discounted-monthly': (state) => state.discountedPrice.monthly.max.fmt
|
|
45
|
-
};
|
|
46
|
-
// Handles both data-store-price (option-level) and data-store-context-price (state-level)
|
|
47
20
|
export const handlePrice = (el, ctx) => {
|
|
48
21
|
const { storePrice, storeContextPrice } = el.dataset;
|
|
49
22
|
const option = ctx.option;
|
|
50
|
-
// Option-level price
|
|
51
23
|
if (storePrice && option) {
|
|
24
|
+
const renderers = {
|
|
25
|
+
'full': () => option.getPrice(),
|
|
26
|
+
'discounted': () => getDiscountedPrice(option),
|
|
27
|
+
'full-monthly': () => option.getPrice({ monthly: true }),
|
|
28
|
+
'discounted-monthly': () => getDiscountedPrice(option, { monthly: true })
|
|
29
|
+
};
|
|
52
30
|
const chosen = Compiler.enum({
|
|
53
31
|
expr: storePrice,
|
|
54
32
|
allowed: OPTION_PRICE_TOKENS,
|
|
55
|
-
isAvailable: (token) =>
|
|
33
|
+
isAvailable: (token) => isPresent(renderers[token]())
|
|
56
34
|
});
|
|
57
35
|
if (chosen) {
|
|
58
|
-
el.textContent =
|
|
36
|
+
el.textContent = renderers[chosen]() ?? '';
|
|
59
37
|
return;
|
|
60
38
|
}
|
|
61
39
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
if (storeContextPrice && ctx.compute) {
|
|
41
|
+
const renderers = {
|
|
42
|
+
'min-full': () => ctx.compute?.price.min.fmt,
|
|
43
|
+
'max-full': () => ctx.compute?.price.max.fmt,
|
|
44
|
+
'min-discounted': () => ctx.compute?.discountedPrice.min.fmt,
|
|
45
|
+
'max-discounted': () => ctx.compute?.discountedPrice.max.fmt,
|
|
46
|
+
'min-full-monthly': () => ctx.compute?.price.monthly.min.fmt,
|
|
47
|
+
'max-full-monthly': () => ctx.compute?.price.monthly.max.fmt,
|
|
48
|
+
'min-discounted-monthly': () => ctx.compute?.discountedPrice.monthly.min.fmt,
|
|
49
|
+
'max-discounted-monthly': () => ctx.compute?.discountedPrice.monthly.max.fmt
|
|
50
|
+
};
|
|
65
51
|
const chosen = Compiler.enum({
|
|
66
52
|
expr: storeContextPrice,
|
|
67
|
-
allowed:
|
|
68
|
-
isAvailable: (token) =>
|
|
53
|
+
allowed: COMPUTE_PRICE_TOKENS,
|
|
54
|
+
isAvailable: (token) => isPresent(renderers[token]())
|
|
69
55
|
});
|
|
70
56
|
if (chosen) {
|
|
71
|
-
el.textContent =
|
|
57
|
+
el.textContent = renderers[chosen]() ?? '';
|
|
72
58
|
}
|
|
73
59
|
}
|
|
74
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"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","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport type { RenderContext } from '../context.js';\nimport { getDiscountedPrice } from '../context.js';\nimport { isPresent } from './utilty.js';\n\nconst OPTION_PRICE_TOKENS = [\n 'full',\n 'discounted',\n 'full-monthly',\n 'discounted-monthly'\n] as const;\n\ntype OptionPriceToken = typeof OPTION_PRICE_TOKENS[number];\n\nconst COMPUTE_PRICE_TOKENS = [\n 'min-full',\n 'max-full',\n 'min-discounted',\n 'max-discounted',\n 'min-full-monthly',\n 'max-full-monthly',\n 'min-discounted-monthly',\n 'max-discounted-monthly'\n] as const;\n\ntype ComputePriceToken = typeof COMPUTE_PRICE_TOKENS[number];\n\nexport const handlePrice = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storePrice,\n storeContextPrice\n } = el.dataset;\n const option = ctx.option;\n\n if (storePrice && option) {\n const renderers = {\n 'full' : () => option.getPrice(),\n 'discounted' : () => getDiscountedPrice(option),\n 'full-monthly' : () => option.getPrice({ monthly: true }),\n 'discounted-monthly': () =>\n getDiscountedPrice(\n option,\n { monthly: true }\n )\n } satisfies Record<OptionPriceToken, () => string | undefined>;\n\n const chosen = Compiler.enum<OptionPriceToken>({\n expr : storePrice,\n allowed : OPTION_PRICE_TOKENS,\n isAvailable: (token) => isPresent(renderers[token]())\n });\n\n if (chosen) {\n el.textContent = renderers[chosen]() ?? '';\n return;\n }\n }\n\n if (storeContextPrice && ctx.compute) {\n const renderers = {\n 'min-full' : () => ctx.compute?.price.min.fmt,\n 'max-full' : () => ctx.compute?.price.max.fmt,\n 'min-discounted' : () => ctx.compute?.discountedPrice.min.fmt,\n 'max-discounted' : () => ctx.compute?.discountedPrice.max.fmt,\n 'min-full-monthly' : () => ctx.compute?.price.monthly.min.fmt,\n 'max-full-monthly' : () => ctx.compute?.price.monthly.max.fmt,\n 'min-discounted-monthly': () =>\n ctx.compute?.discountedPrice.monthly.min.fmt,\n 'max-discounted-monthly': () =>\n ctx.compute?.discountedPrice.monthly.max.fmt\n } satisfies Record<ComputePriceToken, () => string | undefined>;\n\n const chosen = Compiler.enum<ComputePriceToken>({\n expr : storeContextPrice,\n allowed : COMPUTE_PRICE_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 handleSubscription: (el: HTMLElement, ctx:
|
|
1
|
+
import type { RenderContext } from '../context.js';
|
|
2
|
+
export declare const handleSubscription: (el: HTMLElement, ctx: RenderContext) => void;
|
|
@@ -1,34 +1,28 @@
|
|
|
1
1
|
import { Compiler } from '../../dsl/compilers/index.js';
|
|
2
2
|
import { formatSubscription } from '../../renders/format.js';
|
|
3
|
+
import { buildSelectOptions } from './utilty.js';
|
|
3
4
|
export const handleSubscription = (el, ctx) => {
|
|
4
5
|
const { storeSubscription, storeSubscriptionType, storeTextSingle, storeTextMany } = el.dataset;
|
|
5
|
-
if (storeSubscription === undefined)
|
|
6
|
+
if (storeSubscription === undefined || !ctx.option) {
|
|
6
7
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// input
|
|
8
|
+
}
|
|
9
|
+
const type = storeSubscriptionType === 'months'
|
|
10
|
+
? 'months'
|
|
11
|
+
: 'years';
|
|
12
12
|
if (el instanceof HTMLInputElement) {
|
|
13
|
-
const value = type === 'months'
|
|
13
|
+
const value = type === 'months'
|
|
14
|
+
? ctx.option.getSubscription()
|
|
15
|
+
: Math.floor(ctx.option.getSubscription() / 12);
|
|
14
16
|
el.value = String(value);
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
|
-
// select
|
|
18
19
|
if (el instanceof HTMLSelectElement) {
|
|
19
|
-
const selectedSubscription = option.getSubscription();
|
|
20
|
-
const available = Compiler.array(storeSubscription) ??
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const isSelected = sub === selectedSubscription;
|
|
24
|
-
const text = formatSubscription(sub, type, storeTextSingle, storeTextMany);
|
|
25
|
-
const htmlOption = new Option(text, String(sub), isSelected, isSelected);
|
|
26
|
-
htmlOption.setAttribute('data-store-set-subscription', String(sub));
|
|
27
|
-
el.add(htmlOption);
|
|
28
|
-
}
|
|
20
|
+
const selectedSubscription = ctx.option.getSubscription();
|
|
21
|
+
const available = Compiler.array(storeSubscription) ??
|
|
22
|
+
ctx.option.getProduct().getSubscriptions().values;
|
|
23
|
+
buildSelectOptions(el, available, selectedSubscription, (subscription) => formatSubscription(subscription, type, storeTextSingle, storeTextMany), 'data-store-set-subscription');
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
el.textContent = formatSubscription(option.getSubscription(), type, storeTextSingle, storeTextMany);
|
|
26
|
+
el.textContent = formatSubscription(ctx.option.getSubscription(), type, storeTextSingle, storeTextMany);
|
|
33
27
|
};
|
|
34
28
|
//# sourceMappingURL=subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IAEf,IAAI,iBAAiB,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACnD,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GACR,qBAAqB,KAAK,QAAQ;QAChC,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,OAAO,CAAC;IAEd,IAAI,EAAE,YAAY,gBAAgB,EAAE,CAAC;QACnC,MAAM,KAAK,GACT,IAAI,KAAK,QAAQ;YACf,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE;YAC9B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;QAEpD,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,IAAI,EAAE,YAAY,iBAAiB,EAAE,CAAC;QACpC,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAC1D,MAAM,SAAS,GACb,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC;YACjC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC;QAEpD,kBAAkB,CAChB,EAAE,EACF,SAAS,EACT,oBAAoB,EACpB,CAAC,YAAY,EAAE,EAAE,CAAC,kBAAkB,CAClC,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,aAAa,CACd,EACD,6BAA6B,CAC9B,CAAC;QAEF,OAAO;IACT,CAAC;IAED,EAAE,CAAC,WAAW,GAAG,kBAAkB,CACjC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,EAC5B,IAAI,EACJ,eAAe,EACf,aAAa,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport { formatSubscription } from '@/renders/format.js';\nimport type { RenderContext } from '../context.js';\nimport { buildSelectOptions } from './utilty.js';\n\nexport const handleSubscription = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeSubscription,\n storeSubscriptionType,\n storeTextSingle,\n storeTextMany\n } = el.dataset;\n\n if (storeSubscription === undefined || !ctx.option) {\n return;\n }\n\n const type =\n storeSubscriptionType === 'months'\n ? 'months'\n : 'years';\n\n if (el instanceof HTMLInputElement) {\n const value =\n type === 'months'\n ? ctx.option.getSubscription()\n : Math.floor(ctx.option.getSubscription() / 12);\n\n el.value = String(value);\n return;\n }\n\n if (el instanceof HTMLSelectElement) {\n const selectedSubscription = ctx.option.getSubscription();\n const available =\n Compiler.array(storeSubscription) ??\n ctx.option.getProduct().getSubscriptions().values;\n\n buildSelectOptions(\n el,\n available,\n selectedSubscription,\n (subscription) => formatSubscription(\n subscription,\n type,\n storeTextSingle,\n storeTextMany\n ),\n 'data-store-set-subscription'\n );\n\n return;\n }\n\n el.textContent = formatSubscription(\n ctx.option.getSubscription(),\n type,\n storeTextSingle,\n storeTextMany\n );\n};\n"]}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const isPresent: (value: unknown) => boolean;
|
|
2
2
|
export declare const resolveAnchor: (el: HTMLElement) => HTMLAnchorElement | null;
|
|
3
|
+
export type SelectOptionFormatter<T> = (value: T, index: number, values: readonly T[]) => string;
|
|
4
|
+
export declare const buildSelectOptions: <T>(select: HTMLSelectElement, values: readonly T[], selectedValue: T, formatLabel: SelectOptionFormatter<T>, setAttributeName: string) => void;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
export const isPresent = (value) => value !== null
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const resolveAnchor = (el) => el instanceof HTMLAnchorElement
|
|
1
|
+
export const isPresent = (value) => value !== null &&
|
|
2
|
+
value !== undefined &&
|
|
3
|
+
(typeof value !== 'number' || Number.isFinite(value));
|
|
4
|
+
export const resolveAnchor = (el) => el instanceof HTMLAnchorElement
|
|
5
|
+
? el
|
|
6
|
+
: el.querySelector('a');
|
|
7
|
+
export const buildSelectOptions = (select, values, selectedValue, formatLabel, setAttributeName) => {
|
|
8
|
+
select.options.length = 0;
|
|
9
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
10
|
+
const value = values[index];
|
|
11
|
+
const selected = value === selectedValue;
|
|
12
|
+
const label = formatLabel(value, index, values);
|
|
13
|
+
const option = new Option(label, String(value), selected, selected);
|
|
14
|
+
option.setAttribute(setAttributeName, String(value));
|
|
15
|
+
select.add(option);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
5
18
|
//# sourceMappingURL=utilty.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../../src/renders/attributes/utilty.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../../src/renders/attributes/utilty.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAc,EACL,EAAE,CACX,KAAK,KAAK,IAAI;IACd,KAAK,KAAK,SAAS;IACnB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,EAAe,EACW,EAAE,CAC5B,EAAE,YAAY,iBAAiB;IAC7B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC,EAAE,CAAC,aAAa,CAAoB,GAAG,CAAC,CAAC;AAQ/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAyB,EACzB,MAAoB,EACpB,aAAgB,EAChB,WAAqC,EACrC,gBAAwB,EAClB,EAAE;IACR,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAE1B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,KAAK,KAAK,aAAa,CAAC;QACzC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,KAAK,EACL,MAAM,CAAC,KAAK,CAAC,EACb,QAAQ,EACR,QAAQ,CACT,CAAC;QAEF,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC","sourcesContent":["export const isPresent = (\n value: unknown\n): boolean =>\n value !== null &&\n value !== undefined &&\n (typeof value !== 'number' || Number.isFinite(value));\n\nexport const resolveAnchor = (\n el: HTMLElement\n): HTMLAnchorElement | null =>\n el instanceof HTMLAnchorElement\n ? el\n : el.querySelector<HTMLAnchorElement>('a');\n\nexport type SelectOptionFormatter<T> = (\n value: T,\n index: number,\n values: readonly T[]\n) => string;\n\nexport const buildSelectOptions = <T>(\n select: HTMLSelectElement,\n values: readonly T[],\n selectedValue: T,\n formatLabel: SelectOptionFormatter<T>,\n setAttributeName: string\n): void => {\n select.options.length = 0;\n\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index];\n const selected = value === selectedValue;\n const label = formatLabel(value, index, values);\n const option = new Option(\n label,\n String(value),\n selected,\n selected\n );\n\n option.setAttribute(setAttributeName, String(value));\n select.add(option);\n }\n};\n"]}
|
|
@@ -1,11 +1,123 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { Product, ProductOption } from '@repobit/dex-store';
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { BdComputeResult } from '../compute/compute.expand.js';
|
|
2
|
+
import type { BdScope } from '../contexts/context.scope.js';
|
|
3
|
+
import type { Product, ProductOption, Store } from '@repobit/dex-store';
|
|
4
|
+
export type RenderContext = Readonly<{
|
|
5
|
+
scope?: BdScope;
|
|
6
|
+
store?: BdScope['store'];
|
|
7
|
+
product?: Product;
|
|
8
|
+
option?: ProductOption;
|
|
9
|
+
compute?: BdComputeResult;
|
|
10
|
+
}>;
|
|
10
11
|
export type DSLContext = Record<string, unknown>;
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Flattened option context exposed to Eta templates and the hide DSL.
|
|
14
|
+
*
|
|
15
|
+
* Mirrors the v1 `it.option.*` shape: every value is a pre-formatted string
|
|
16
|
+
* (currency-aware), so templates and hide expressions never need to call
|
|
17
|
+
* `option.getPrice()` directly. `links.trial` is the only callable — it
|
|
18
|
+
* resolves a trial URL for a given duration (e.g. `'30 days'`).
|
|
19
|
+
*/
|
|
20
|
+
export type TemplateOptionContext = Readonly<{
|
|
21
|
+
price: {
|
|
22
|
+
full: string;
|
|
23
|
+
discounted: string | undefined;
|
|
24
|
+
fullMonthly: string;
|
|
25
|
+
discountedMonthly: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
discount: {
|
|
28
|
+
percentage: string;
|
|
29
|
+
percentageMonthly: string;
|
|
30
|
+
value: string;
|
|
31
|
+
valueMonthly: string;
|
|
32
|
+
};
|
|
33
|
+
links: {
|
|
34
|
+
buy: string | undefined;
|
|
35
|
+
trial: (trialDuration: string) => string | undefined;
|
|
36
|
+
};
|
|
37
|
+
devices: number;
|
|
38
|
+
subscription: number;
|
|
39
|
+
}>;
|
|
40
|
+
export type TemplateProductContext = Readonly<{
|
|
41
|
+
id: string;
|
|
42
|
+
campaign: string | undefined;
|
|
43
|
+
name: string | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export type TemplateStateContext = Readonly<{
|
|
46
|
+
price: {
|
|
47
|
+
full: {
|
|
48
|
+
min: string;
|
|
49
|
+
max: string;
|
|
50
|
+
monthly: {
|
|
51
|
+
min: string;
|
|
52
|
+
max: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
discounted: {
|
|
56
|
+
min: string;
|
|
57
|
+
max: string;
|
|
58
|
+
monthly: {
|
|
59
|
+
min: string;
|
|
60
|
+
max: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
discount: {
|
|
65
|
+
percentage: {
|
|
66
|
+
min: string;
|
|
67
|
+
max: string;
|
|
68
|
+
monthly: {
|
|
69
|
+
min: string;
|
|
70
|
+
max: string;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
value: {
|
|
74
|
+
min: string;
|
|
75
|
+
max: string;
|
|
76
|
+
monthly: {
|
|
77
|
+
min: string;
|
|
78
|
+
max: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
scenarios: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Shape consumed by Eta templates and the hide DSL.
|
|
86
|
+
*
|
|
87
|
+
* Mirrors the v1 `it.*` layout: `option` / `product` / `state` are flattened
|
|
88
|
+
* DTOs, and `ctx` is an alias of `state`. `derived` is intentionally kept
|
|
89
|
+
* nested (see {@link BdScopedTemplateContext}) — v1 merged derived into the
|
|
90
|
+
* root via `deepmerge`; v2 exposes it explicitly so consumers can tell
|
|
91
|
+
* user-provided values apart from store-provided ones.
|
|
92
|
+
*/
|
|
93
|
+
export type TemplateDslContext = Readonly<{
|
|
94
|
+
store: Store | undefined;
|
|
95
|
+
product: TemplateProductContext | undefined;
|
|
96
|
+
option: TemplateOptionContext | undefined;
|
|
97
|
+
state: TemplateStateContext | undefined;
|
|
98
|
+
ctx: TemplateStateContext | undefined;
|
|
99
|
+
}>;
|
|
100
|
+
export declare function createRenderContext(scope: BdScope | undefined, compute: BdComputeResult | undefined): RenderContext;
|
|
101
|
+
export declare function toDSLContext(ctx: RenderContext): DSLContext;
|
|
102
|
+
/**
|
|
103
|
+
* Build the flattened, v1-shaped DSL context.
|
|
104
|
+
*
|
|
105
|
+
* Used by both the hide DSL compiler (`renders/attributes/hide.ts`) and the
|
|
106
|
+
* Eta template controller (`core/node.scope.ts`) so the two surfaces agree
|
|
107
|
+
* on `it.option.*` / `it.product.*` / `it.state.*` / `it.ctx.*`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function buildTemplateDslContext(input: {
|
|
110
|
+
store: Store | undefined;
|
|
111
|
+
product: Product | undefined;
|
|
112
|
+
option: ProductOption | undefined;
|
|
113
|
+
state: BdComputeResult | undefined;
|
|
114
|
+
}): TemplateDslContext;
|
|
115
|
+
export declare function getDiscountedPrice(option: ProductOption, params?: {
|
|
116
|
+
monthly?: boolean;
|
|
117
|
+
}): string | undefined;
|
|
118
|
+
export declare function getDiscount(option: ProductOption, params?: {
|
|
119
|
+
monthly?: boolean;
|
|
120
|
+
percentage?: boolean;
|
|
121
|
+
symbol?: boolean;
|
|
122
|
+
}): string | undefined;
|
|
123
|
+
export declare function getProductName(product: Product): string | undefined;
|