@lime-bundles/widget 1.0.0 → 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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @lime-bundles/widget
2
2
 
3
- Framework-agnostic `<lime-bundle>` custom element for rendering Lime Bundles on any storefront: Astro, Vue, Svelte, plain HTML, classic Shopify themes via `<script>` tag.
3
+ Drop-in `<lime-bundle>` web component for the **Lime Bundles Shopify app**. Embed merchant-configured bundles on any JavaScript-enabled headless storefront (Hydrogen, Astro, Vue, Svelte, plain HTML). If you're not a merchant using Lime Bundles, this package probably isn't what you're looking for.
4
+
5
+ Ships the full widget your merchants see in the admin preview: header, save badge, product list with count bubbles, savings bar, pricing footer, themed CTA.
4
6
 
5
7
  ## Install
6
8
 
@@ -20,9 +22,9 @@ Or via CDN, zero build step:
20
22
  <script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
21
23
  ```
22
24
 
23
- ## Usage: the paste-and-go default
25
+ ## Paste-and-go
24
26
 
25
- One snippet in your product page template. The widget auto-detects the current product from the URL (`/products/<handle>`) and renders every active bundle for it. On "Add bundle", the widget calls Shopify's tokenless Storefront Cart API and redirects to checkout with the bundle discount applied. No cart code required.
27
+ One snippet in your product page template. The widget resolves the current product from the URL (`/products/<handle>`) and renders every active bundle configured for it. Clicking **Add bundle** calls Shopify's tokenless Storefront Cart API and redirects to checkout with the discount applied.
26
28
 
27
29
  ```html
28
30
  <script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
@@ -32,124 +34,126 @@ One snippet in your product page template. The widget auto-detects the current p
32
34
  ></lime-bundle>
33
35
  ```
34
36
 
35
- ### BYO cart
37
+ Generate the token at `/app/settings/headless` in your Lime Bundles admin. It's a read-only Storefront Access Token (bundle metaobjects + product listings only), safe to ship in HTML.
36
38
 
37
- If you have your own cart, listen for `lime-bundle:add-to-cart` and call `event.preventDefault()` to suppress the default redirect:
39
+ ## BYO cart
38
40
 
39
- ```html
40
- <script>
41
- document.querySelector("lime-bundle").addEventListener(
42
- "lime-bundle:add-to-cart",
43
- async (event) => {
44
- event.preventDefault();
45
- await myCart.linesAdd(event.detail.lines);
46
- },
47
- );
48
- </script>
41
+ Listen for `lime-bundle:add-to-cart` and call `event.preventDefault()` to suppress the default redirect:
42
+
43
+ ```js
44
+ document.querySelector("lime-bundle").addEventListener(
45
+ "lime-bundle:add-to-cart",
46
+ async (event) => {
47
+ event.preventDefault();
48
+ await myCart.linesAdd(event.detail.lines);
49
+ },
50
+ );
49
51
  ```
50
52
 
51
53
  ## Attributes
52
54
 
53
55
  | Attribute | Required | Purpose |
54
56
  |---|:-:|---|
55
- | `shop-domain` | ✓ | Your shop domain, e.g. `my-shop.myshopify.com`. |
56
- | `storefront-token` | ✓ | Public Storefront Access Token. Generated in `/app/settings/headless`. |
57
- | `bundle-gid` | | Pin one specific bundle. When set, overrides auto-detect. |
58
- | `product-handle` | | Render bundles for a specific product handle. Overrides URL detection. |
59
- | `app-url` | | Lime Bundles app URL; enables analytics when set. |
60
- | `analytics` | | Set to `"false"` to suppress analytics even with `app-url` set. |
61
- | `locale` | | BCP-47 tag forwarded to Storefront API. |
57
+ | `shop-domain` | ✓ | `*.myshopify.com` domain. |
58
+ | `storefront-token` | ✓ | Storefront Access Token from `/app/settings/headless`. |
59
+ | `bundle-gid` | | Render one specific bundle. Overrides auto-detect. |
60
+ | `product-handle` | | Render bundles for this handle. Overrides URL detection. |
61
+ | `app-url` | | Enables impression + add-to-cart analytics when set. |
62
+ | `analytics` | | `"false"` suppresses analytics even when `app-url` is set. |
63
+ | `locale` | | BCP-47 tag forwarded to the Storefront API. |
62
64
 
63
- Product resolution cascade when `bundle-gid` is absent: explicit `product-handle` → `<meta name="shopify:product-handle">` → `/products/<handle>` URL segment.
65
+ **Product resolution** (when `bundle-gid` is absent): explicit `product-handle` → `<meta name="shopify:product-handle">` → `/products/<handle>` URL segment.
64
66
 
65
67
  Changing any attribute at runtime re-fetches and re-renders.
66
68
 
67
69
  ## Events
68
70
 
71
+ All events bubble and pierce shadow-DOM boundaries (`composed: true`), so you can listen on any ancestor.
72
+
69
73
  ### `lime-bundle:add-to-cart`
70
74
 
71
- Fired on CTA click. `event.detail`:
75
+ Fired on CTA click. Cancelable: `event.preventDefault()` suppresses the default checkout redirect.
72
76
 
73
77
  ```ts
74
- {
75
- lines: CartLineInput[];
76
- bundleType: "fixed" | "volume" | "mix_match";
77
- bundleId: string;
78
+ event.detail: {
79
+ lines: CartLineInput[]; // merchandiseId + quantity + attributes
78
80
  }
79
81
  ```
80
82
 
81
- Every line's `attributes` array includes `{ key: "_lime_bundle_gid", value: bundleId }`. Preserve it on the way to Shopify cart mutation or purchase attribution breaks.
82
-
83
- ### `lime-bundle:error`
84
-
85
- Fired if bundle fetch / parse fails. `event.detail.error` is an `Error`. Render your own fallback UI in response.
83
+ Every line's `attributes[]` array includes `{ key: "_lime_bundle_gid", value: bundleId }`. Preserve it on the way to Shopify cart mutation or purchase attribution breaks.
86
84
 
87
- ## Framework snippets
85
+ ### `lime-bundle:loaded`
88
86
 
89
- **Astro:**
87
+ Fired once the bundle(s) have been fetched and parsed.
90
88
 
91
- ```astro
92
- <lime-bundle shop-domain="..." storefront-token={import.meta.env.PUBLIC_LIME_BUNDLES_TOKEN} bundle-gid="..." />
93
- <script>
94
- import "@lime-bundles/widget";
95
- document.querySelector("lime-bundle")!.addEventListener("lime-bundle:add-to-cart", (e: any) => {
96
- fetch("/api/cart-add", { method: "POST", body: JSON.stringify(e.detail.lines) });
97
- });
98
- </script>
89
+ ```ts
90
+ event.detail: {
91
+ bundleCount: number;
92
+ bundleTypes: Array<"fixed" | "volume" | "mix_match">;
93
+ }
99
94
  ```
100
95
 
101
- **Vue 3:**
96
+ ### `lime-bundle:error`
102
97
 
103
- ```vue
104
- <lime-bundle
105
- shop-domain="my-shop.myshopify.com"
106
- :storefront-token="token"
107
- bundle-gid="..."
108
- @lime-bundle:add-to-cart="handle"
109
- />
98
+ Fired if fetch or parse fails.
99
+
100
+ ```ts
101
+ event.detail: { message: string; code: string } // e.g. "LOAD_ERROR"
110
102
  ```
111
103
 
112
- Configure `app.config.compilerOptions.isCustomElement = (tag) => tag === "lime-bundle"` to silence Vue's warning.
104
+ The widget renders its own inline fallback; listen for this event if you want to hide the parent or report to your own telemetry.
113
105
 
114
- **Svelte:**
106
+ ## What the widget handles for you
115
107
 
116
- ```svelte
117
- <lime-bundle
118
- shop-domain="my-shop.myshopify.com"
119
- storefront-token={TOKEN}
120
- bundle-gid="..."
121
- on:lime-bundle:add-to-cart={handle}
122
- />
123
- ```
108
+ - **Merchant styling.** Every `--lb-*` CSS variable the merchant configured in the admin is applied inside the shadow root on render.
109
+ - **Custom CSS.** `shop.metafields["$app"].custom_css` is auto-fetched, sanitized, and injected.
110
+ - **Countdown timer.** When a bundle has `endsAt`, the widget ticks live and hides on expiry.
111
+ - **Variant dropdowns.** Products with multiple eligible variants render a `<select>`; switching live-updates the row price and bundle total.
112
+ - **Mix-match picker modal.** Full modal with search, quantity stepper, progress bar, focus trap, and keyboard navigation.
113
+ - **Out-of-stock handling.** Honours `widgetConfig.outOfStockBehavior` (`hide` vs `show_greyed_out`); hides the widget when the bundle is unfulfillable.
114
+ - **A/B testing.** Reads the merchant's A/B config, buckets the visitor via a first-party cookie, applies Variant B overrides.
115
+ - **Analytics.** Impression and add-to-cart events fire regardless of whether you override the cart.
124
116
 
125
117
  ## Styling
126
118
 
127
- Render happens inside a closed Shadow DOM. Override CSS custom properties on the host:
119
+ Override any CSS custom property on the host element:
128
120
 
129
121
  ```html
130
122
  <lime-bundle
131
- style="--lb-primary-color: #e91e63; --lb-radius: 16px;"
132
123
  shop-domain="..."
124
+ style="--lb-primary-color: #e91e63; --lb-radius: 16px;"
133
125
  ></lime-bundle>
134
126
  ```
135
127
 
136
- Merchant custom CSS from `/app/settings/custom-css` is auto-fetched and injected on mount.
128
+ Full variable reference: [css-variables.md](./docs/css-variables.md).
129
+
130
+ ## Non-React framework snippets
131
+
132
+ **Astro:**
133
+
134
+ ```astro
135
+ <lime-bundle shop-domain="..." storefront-token={import.meta.env.PUBLIC_LIME_BUNDLES_TOKEN} />
136
+ <script>
137
+ import "@lime-bundles/widget";
138
+ </script>
139
+ ```
140
+
141
+ **Vue 3.** Configure `app.config.compilerOptions.isCustomElement = (tag) => tag === "lime-bundle"` to silence the unknown-element warning.
137
142
 
138
- Full variable list: [css-variables.md](https://github.com/lime-app-dev/lime-bundles-app/blob/main/docs/headless/css-variables.md).
143
+ **Svelte.** No configuration needed; use `on:lime-bundle:add-to-cart={handler}`.
139
144
 
140
145
  ## Bundle size
141
146
 
142
- `lime-bundle.js` (IIFE, gzipped) is <30 KB. No runtime framework dependency.
147
+ IIFE build, gzipped: <30 KB. No runtime framework dependency.
143
148
 
144
- ## Versioning
149
+ ## Version policy
145
150
 
146
- Major versions bump together with `@lime-bundles/core` and `@lime-bundles/react`.
151
+ All three packages (`core`, `react`, `widget`) bump majors together. The v2.0.0 release closes full rendering parity with the admin preview.
147
152
 
148
153
  ## License
149
154
 
150
- MIT. See repo root.
155
+ MIT.
151
156
 
152
- ## Links
157
+ ## Support
153
158
 
154
- - [Web component guide](https://github.com/lime-app-dev/lime-bundles-app/blob/main/docs/headless/web-component.md)
155
- - [Report issues](https://github.com/lime-app-dev/lime-bundles-app/issues)
159
+ Merchant support and bug reports: email via the Lime Bundles listing on the Shopify App Store.