@repobit/dex-store-elements 1.2.4 → 1.2.6

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 CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.6](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.2.5...@repobit/dex-store-elements@1.2.6) (2025-10-31)
7
+
8
+ **Note:** Version bump only for package @repobit/dex-store-elements
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.2.5](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.2.4...@repobit/dex-store-elements@1.2.5) (2025-10-28)
15
+
16
+ **Note:** Version bump only for package @repobit/dex-store-elements
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.2.4](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.2.3...@repobit/dex-store-elements@1.2.4) (2025-10-20)
7
23
 
8
24
 
package/README.md CHANGED
@@ -35,6 +35,21 @@ Peer dependencies are resolved automatically by npm; no extra install command is
35
35
  provider: { name: 'vlaicu' }
36
36
  });
37
37
 
38
+ // Optional: analytics data layer callback
39
+ // Fires once per <bd-option> that sets `data-layer-event`
40
+ root.dataLayer = ({ option, event }) => {
41
+ // Example GTM-style push; adapt fields as needed
42
+ window.dataLayer?.push({
43
+ event,
44
+ productId : option.getProduct().getId(),
45
+ campaign : option.getProduct().getCampaign(),
46
+ variation : option.getVariation(), // e.g. "5-12"
47
+ devices : option.getDevices(),
48
+ subscription: option.getSubscription(),
49
+ price : option.getDiscountedPrice({ currency: false })
50
+ });
51
+ };
52
+
38
53
  // Optional: define derived values/functions for templates + hide DSL
39
54
  root.derived = async ({ option }) => ({
40
55
  mails: (p) => ((option?.getDevices?.() ?? 0) / p) * 100
@@ -47,18 +62,18 @@ Peer dependencies are resolved automatically by npm; no extra install command is
47
62
 
48
63
  <bd-root store-name="root">
49
64
  <bd-product store-name="product" product-id="com.bitdefender.tsmd.v2">
50
- <bd-option devices="5" subscription="12">
65
+ <bd-option devices="5" subscription="12" data-layer-event="info">
51
66
  <!-- Attribute renderers (see below) -->
52
67
  <div data-store-render data-store-devices></div>
53
68
  <div data-store-render data-store-subscription data-store-subscription-type="years"></div>
54
69
  <div data-store-render data-store-price="discounted || full"></div>
55
70
  <a data-store-render data-store-buy-link>Buy</a>
56
71
  <!-- Eta template (text) -->
57
- <p>Now at only {{= it.option.discountedPrice }}!</p>
72
+ <p>Now at only {{= it.option.price.discounted }}!</p>
58
73
  <!-- Eta template (attribute, implicit) -->
59
74
  <div title="Devices {{= it.option.devices }}"></div>
60
75
  <!-- Hide via DSL using merged context -->
61
- <div data-store-render data-store-hide="!it.option.discountedPrice">
76
+ <div data-store-render data-store-hide="!it.option.price.discounted">
62
77
  Hidden when discounted price doesn't exists
63
78
  </div>
64
79
  <!-- Actions -->
@@ -162,8 +177,8 @@ Notes
162
177
  - `it.state.*` aggregated min/max data (also available under `it.ctx`)
163
178
  - any keys returned from your `root.derived`
164
179
  - Examples:
165
- - `data-store-hide="it.option.discountedPrice === 0"`
166
- - `data-store-hide="(it.state.price.min > 100) && (it.product.campaign === 'test')"`
180
+ - `data-store-hide="!it.option.price.discounted"` (hide when no discounted price)
181
+ - `data-store-hide="it.product.campaign === 'test'"`
167
182
 
168
183
  ## Eta templates
169
184
  - Text/HTML: any element that is not a provider and doesn’t contain nested providers is treated as a whole-template; `innerHTML` is compiled once and morphed via nanomorph. This preserves existing DOM event listeners and state.
@@ -176,12 +191,121 @@ Notes
176
191
  - your derived overlay merged at top-level (see below)
177
192
 
178
193
  ## Derived variables/functions
179
- - Provide a function at the root: `root.derived = async ({ option, product, state, store }) => ({ ... })`
194
+ - Provide a function at the root: `root.derived = async ({ option, product, state }) => ({ ... })`
180
195
  - The returned object is merged into the Eta/DSL context:
181
- - Example: `({ mails: (p) => (option.getDevices()/p)*100, option: { someVar: state.discount.value.min } })`
196
+ - Example: `({ mails: (p) => (option?.getDevices?.()/p)*100, option: { someVar: state.discount.value.min } })`
182
197
  - Use it in Eta: `{{= it.mails(10) }}` or `{{= it.option.someVar }}`
183
198
  - Use it in hide: `data-store-hide="it.mails(10) >= 50"`
184
199
 
200
+ ## DSL context reference
201
+ The DSL and Eta contexts use Eta’s default variable name `it`. The following keys are available:
202
+
203
+ - it.option
204
+ - price
205
+ - full: formatted full price (string)
206
+ - discounted: formatted discounted price (string)
207
+ - fullMonthly: formatted monthly full price (string)
208
+ - discountedMonthly: formatted monthly discounted price (string)
209
+ - discount
210
+ - value: formatted discount amount (string)
211
+ - percentage: formatted percentage discount with symbol (string)
212
+ - valueMonthly: formatted monthly discount amount (string)
213
+ - percentageMonthly: formatted monthly percentage with symbol (string)
214
+ - links
215
+ - buy: buy URL (string)
216
+ - trial: trial URL if available (string)
217
+ - devices: number
218
+ - subscription: number
219
+
220
+ - it.product
221
+ - id: string
222
+ - campaign: string
223
+ - name: string
224
+
225
+ - it.state (also available as `it.ctx`)
226
+ - price
227
+ - full
228
+ - min: formatted string
229
+ - max: formatted string
230
+ - monthly
231
+ - min: formatted string
232
+ - max: formatted string
233
+ - discounted
234
+ - min: formatted string
235
+ - max: formatted string
236
+ - monthly
237
+ - min: formatted string
238
+ - max: formatted string
239
+ - discount
240
+ - percentage
241
+ - min: formatted string
242
+ - max: formatted string
243
+ - monthly
244
+ - min: formatted string
245
+ - max: formatted string
246
+ - value
247
+ - min: formatted string
248
+ - max: formatted string
249
+ - monthly
250
+ - min: formatted string
251
+ - max: formatted string
252
+
253
+ Notes
254
+ - All price/discount values in the DSL are formatted strings (currency-aware). Do not perform numeric comparisons on them. Prefer truthiness checks (e.g., `!it.option.price.discounted`).
255
+ - `it.ctx` is an alias of `it.state` for convenience.
256
+
257
+ ## Data Layer
258
+ - Provide a function on `<bd-root>`: `root.dataLayer = ({ option, event }) => { ... }`.
259
+ - Called once per `<bd-option>` instance that declares `data-layer-event` (on first successful load).
260
+ - Safe if attached after the option loads; it still fires once when available.
261
+ - Intended for analytics (e.g., pushing to `window.dataLayer`).
262
+ - Event name is set on each `<bd-option>` with `data-layer-event`.
263
+ - Canonical values: `all`, `info`, `comparison`. Any custom string is also accepted.
264
+ - Payload shape passed to your callback:
265
+ - `event`: string event name.
266
+ - `option`: `ProductOption` from `@repobit/dex-store` with getters like `getProduct()`, `getVariation()`, `getDevices()`, `getSubscription()`, `getBuyLink()`, `getDiscountedPrice()`.
267
+
268
+ Example:
269
+
270
+ ```html
271
+ <script type="module">
272
+ import { registerContextNodes, registerActionNodes } from '@repobit/dex-store-elements';
273
+ import { Store } from '@repobit/dex-store';
274
+
275
+ window.addEventListener('DOMContentLoaded', async () => {
276
+ registerContextNodes();
277
+ const root = document.querySelector('bd-root');
278
+ root.store = new Store({ locale: 'en-us', provider: { name: 'vlaicu' } });
279
+
280
+ root.dataLayer = ({ option, event }) => {
281
+ window.dataLayer = window.dataLayer || [];
282
+ window.dataLayer.push({
283
+ event,
284
+ productId: option.getProduct().getId(),
285
+ campaign : option.getProduct().getCampaign(),
286
+ variation: option.getVariation(),
287
+ devices : option.getDevices(),
288
+ subscription: option.getSubscription()
289
+ });
290
+ };
291
+
292
+ registerActionNodes(root);
293
+ });
294
+ </script>
295
+
296
+ <bd-root store-name="root">
297
+ <bd-product store-name="product" product-id="com.bitdefender.tsmd.v2">
298
+ <bd-option devices="5" subscription="12" data-layer-event="info">
299
+ <!-- your UI here -->
300
+ </bd-option>
301
+ </bd-product>
302
+ </bd-root>
303
+ ```
304
+
305
+ Behavior notes
306
+ - Fires only once per `<bd-option>` instance (first load). Subsequent changes via actions or deltas do not trigger the callback again.
307
+ - Set different `data-layer-event` values on different options if you need multiple distinct analytics events.
308
+
185
309
  ## Actions
186
310
  - Add `data-store-action` to elements to emit store events.
187
311
  - Set absolute values: `data-store-set-devices`, `data-store-set-subscription`, `data-store-set-id`, `data-store-set-campaign`
@@ -1,7 +1,7 @@
1
1
  import type { ProductOption } from '@repobit/dex-store';
2
2
  export type dataLayerPayload = {
3
3
  option: ProductOption;
4
- event: "product-loaded" | "main-product-loaded" | "product-comparison" | (string & {});
4
+ event: "all" | "info" | "comparison" | (string & {});
5
5
  };
6
6
  export type dataLayerContextType = ((payload: dataLayerPayload) => void) | undefined;
7
7
  export declare const dataLayerContext: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repobit/dex-store-elements",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "HTML elements layer for pricings",
5
5
  "author": "Buga Adrian Alexandru <abuga@bitdefender.com>",
6
6
  "homepage": "https://github.com/bitdefender/dex-core#readme",
@@ -62,5 +62,5 @@
62
62
  ]
63
63
  }
64
64
  },
65
- "gitHead": "c38f5d5676fedc5a6adc0b1248803ac5ad376f86"
65
+ "gitHead": "45026ddb310bc191c78072fa27ab36ec1049fa0d"
66
66
  }