@lime-bundles/widget 0.1.1 → 1.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 +155 -0
- package/dist/index.cjs +291 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -37
- package/dist/index.d.ts +74 -37
- package/dist/index.js +308 -219
- package/dist/index.js.map +1 -1
- package/dist/lime-bundle.global.js +127 -34
- package/dist/lime-bundle.global.js.map +1 -1
- package/package.json +2 -6
- package/dist/lime-thankyou.cjs +0 -2
- package/dist/lime-thankyou.cjs.map +0 -1
- package/dist/lime-thankyou.global.js +0 -2
- package/dist/lime-thankyou.global.js.map +0 -1
- package/dist/lime-thankyou.js +0 -2
- package/dist/lime-thankyou.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @lime-bundles/widget
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Via npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @lime-bundles/widget
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import "@lime-bundles/widget"; // registers <lime-bundle> globally
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or via CDN, zero build step:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage: the paste-and-go default
|
|
24
|
+
|
|
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.
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
|
|
29
|
+
<lime-bundle
|
|
30
|
+
shop-domain="my-shop.myshopify.com"
|
|
31
|
+
storefront-token="<YOUR_LIME_BUNDLES_TOKEN>"
|
|
32
|
+
></lime-bundle>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### BYO cart
|
|
36
|
+
|
|
37
|
+
If you have your own cart, listen for `lime-bundle:add-to-cart` and call `event.preventDefault()` to suppress the default redirect:
|
|
38
|
+
|
|
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>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Attributes
|
|
52
|
+
|
|
53
|
+
| Attribute | Required | Purpose |
|
|
54
|
+
|---|:-:|---|
|
|
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. |
|
|
62
|
+
|
|
63
|
+
Product resolution cascade when `bundle-gid` is absent: explicit `product-handle` → `<meta name="shopify:product-handle">` → `/products/<handle>` URL segment.
|
|
64
|
+
|
|
65
|
+
Changing any attribute at runtime re-fetches and re-renders.
|
|
66
|
+
|
|
67
|
+
## Events
|
|
68
|
+
|
|
69
|
+
### `lime-bundle:add-to-cart`
|
|
70
|
+
|
|
71
|
+
Fired on CTA click. `event.detail`:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
{
|
|
75
|
+
lines: CartLineInput[];
|
|
76
|
+
bundleType: "fixed" | "volume" | "mix_match";
|
|
77
|
+
bundleId: string;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
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.
|
|
86
|
+
|
|
87
|
+
## Framework snippets
|
|
88
|
+
|
|
89
|
+
**Astro:**
|
|
90
|
+
|
|
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>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Vue 3:**
|
|
102
|
+
|
|
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
|
+
/>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Configure `app.config.compilerOptions.isCustomElement = (tag) => tag === "lime-bundle"` to silence Vue's warning.
|
|
113
|
+
|
|
114
|
+
**Svelte:**
|
|
115
|
+
|
|
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
|
+
```
|
|
124
|
+
|
|
125
|
+
## Styling
|
|
126
|
+
|
|
127
|
+
Render happens inside a closed Shadow DOM. Override CSS custom properties on the host:
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<lime-bundle
|
|
131
|
+
style="--lb-primary-color: #e91e63; --lb-radius: 16px;"
|
|
132
|
+
shop-domain="..."
|
|
133
|
+
></lime-bundle>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Merchant custom CSS from `/app/settings/custom-css` is auto-fetched and injected on mount.
|
|
137
|
+
|
|
138
|
+
Full variable list: [css-variables.md](https://github.com/lime-app-dev/lime-bundles-app/blob/main/docs/headless/css-variables.md).
|
|
139
|
+
|
|
140
|
+
## Bundle size
|
|
141
|
+
|
|
142
|
+
`lime-bundle.js` (IIFE, gzipped) is <30 KB. No runtime framework dependency.
|
|
143
|
+
|
|
144
|
+
## Versioning
|
|
145
|
+
|
|
146
|
+
Major versions bump together with `@lime-bundles/core` and `@lime-bundles/react`.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT. See repo root.
|
|
151
|
+
|
|
152
|
+
## Links
|
|
153
|
+
|
|
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)
|