@umxr/bagsy 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +257 -2
- package/dist/chunk-CJV4SIV7.js +244 -0
- package/dist/chunk-CJV4SIV7.js.map +1 -0
- package/dist/chunk-QV3JPND6.js +375 -0
- package/dist/chunk-QV3JPND6.js.map +1 -0
- package/dist/client-CXCgpFGa.d.ts +169 -0
- package/dist/element.d.ts +169 -0
- package/dist/element.js +566 -0
- package/dist/element.js.map +1 -0
- package/dist/hydrogen.d.ts +73 -0
- package/dist/hydrogen.js +89 -0
- package/dist/hydrogen.js.map +1 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +174 -0
- package/dist/react.js +403 -0
- package/dist/react.js.map +1 -0
- package/dist/relay-0l6VcQp9.d.ts +25 -0
- package/dist/server.d.ts +96 -0
- package/dist/server.js +10 -0
- package/dist/server.js.map +1 -0
- package/dist/styles.css +157 -0
- package/dist/transport-Chh09xIP.d.ts +1022 -0
- package/package.json +89 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Transport, components } from './index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bagsy-button product-id="123">` — a save/unsave toggle.
|
|
5
|
+
*
|
|
6
|
+
* Attributes: `product-id` (required, numeric or GID), `variant-id` (save a
|
|
7
|
+
* specific variant), `variant-source` (follow the selected variant in the
|
|
8
|
+
* product form on the page), `label` / `label-saved` (text, also used as the
|
|
9
|
+
* accessible name), `icon-only`. Reflects `saved` for styling.
|
|
10
|
+
* Default look: `@umxr/bagsy/styles.css`. Style with `--bagsy-accent`,
|
|
11
|
+
* `--bagsy-color`, `--bagsy-background`, `--bagsy-border`, `--bagsy-radius`,
|
|
12
|
+
* `--bagsy-padding`, or `bagsy-button::part(button | icon | label)`.
|
|
13
|
+
* Put your own markup inside to replace the default icon and label.
|
|
14
|
+
*/
|
|
15
|
+
declare class BagsyButton extends HTMLElement {
|
|
16
|
+
static observedAttributes: string[];
|
|
17
|
+
private button;
|
|
18
|
+
private label;
|
|
19
|
+
private unwatch?;
|
|
20
|
+
private busy;
|
|
21
|
+
private onVariantChange;
|
|
22
|
+
constructor();
|
|
23
|
+
connectedCallback(): void;
|
|
24
|
+
disconnectedCallback(): void;
|
|
25
|
+
/** Follow the selected variant in the product form, preferring this section's form. */
|
|
26
|
+
private syncVariant;
|
|
27
|
+
attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
|
|
28
|
+
get productId(): string;
|
|
29
|
+
get variantId(): string | undefined;
|
|
30
|
+
private subscribe;
|
|
31
|
+
private render;
|
|
32
|
+
private onClick;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `<bagsy-count>` — how many items are in the shopper's wishlist, e.g. for a
|
|
37
|
+
* header link. Renders plain text so it inherits theme styles. Add
|
|
38
|
+
* `hide-empty` to hide it at zero.
|
|
39
|
+
*/
|
|
40
|
+
declare class BagsyCount extends HTMLElement {
|
|
41
|
+
private onCount;
|
|
42
|
+
connectedCallback(): void;
|
|
43
|
+
disconnectedCallback(): void;
|
|
44
|
+
private render;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Image = {
|
|
48
|
+
url: string;
|
|
49
|
+
altText: string | null;
|
|
50
|
+
width: number | null;
|
|
51
|
+
height: number | null;
|
|
52
|
+
} | null;
|
|
53
|
+
type Money = {
|
|
54
|
+
amount: string;
|
|
55
|
+
currencyCode: string;
|
|
56
|
+
};
|
|
57
|
+
/** One card: a saved product, or a saved variant of one. */
|
|
58
|
+
interface Card {
|
|
59
|
+
productId: string;
|
|
60
|
+
variantId?: string;
|
|
61
|
+
title: string;
|
|
62
|
+
variantTitle?: string;
|
|
63
|
+
handle: string;
|
|
64
|
+
available: boolean;
|
|
65
|
+
image: Image;
|
|
66
|
+
price: Money;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `<bagsy-wishlist>`: the shopper's saved products as a grid of cards, or a
|
|
70
|
+
* shared list when the URL has `?bagsy_share=<token>`.
|
|
71
|
+
*
|
|
72
|
+
* Product data comes live from the store's Storefront API (tokenless, same
|
|
73
|
+
* origin), so titles, prices and availability match the shopper's market.
|
|
74
|
+
* Attributes: `country`, `language`, `share` (show share controls),
|
|
75
|
+
* `empty-text`, `remove-label`, `save-label`, `saved-label`, `sold-out-label`,
|
|
76
|
+
* `share-label`, `unshare-label`, `copied-label`, `unshared-label`,
|
|
77
|
+
* `shared-heading`, `shared-missing-text`. Renders light DOM with
|
|
78
|
+
* `bagsy-wishlist__*` classes, styled by `@umxr/bagsy/styles.css`.
|
|
79
|
+
*/
|
|
80
|
+
declare class BagsyWishlist extends HTMLElement {
|
|
81
|
+
private shared;
|
|
82
|
+
private onChange;
|
|
83
|
+
private text;
|
|
84
|
+
connectedCallback(): void;
|
|
85
|
+
disconnectedCallback(): void;
|
|
86
|
+
private loadOwn;
|
|
87
|
+
private loadShared;
|
|
88
|
+
/** Saved items → live cards, in saved order. Deleted or unpublished products drop out. */
|
|
89
|
+
cards(items: {
|
|
90
|
+
productId: string;
|
|
91
|
+
variantId?: string | null;
|
|
92
|
+
}[]): Promise<Card[]>;
|
|
93
|
+
private shareControls;
|
|
94
|
+
private actionButton;
|
|
95
|
+
private message;
|
|
96
|
+
private renderEmpty;
|
|
97
|
+
private grid;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface BagsyConfig {
|
|
101
|
+
/** Shopify `routes.root_url`, e.g. `/` or `/en-gb`. */
|
|
102
|
+
root?: string;
|
|
103
|
+
/** Whether Shopify has a logged-in customer for this page. */
|
|
104
|
+
customer?: boolean;
|
|
105
|
+
/** Override the proxy base URL entirely (tests, custom setups). */
|
|
106
|
+
baseUrl?: string;
|
|
107
|
+
fetch?: typeof fetch;
|
|
108
|
+
}
|
|
109
|
+
interface ChangeDetail {
|
|
110
|
+
productId: string;
|
|
111
|
+
variantId?: string;
|
|
112
|
+
saved: boolean;
|
|
113
|
+
}
|
|
114
|
+
type Listener = () => void;
|
|
115
|
+
/**
|
|
116
|
+
* One per page: a single client, one batched `/saved` lookup for every button
|
|
117
|
+
* on the page, optimistic toggles, and the guest → customer merge on login.
|
|
118
|
+
*/
|
|
119
|
+
declare class BagsyStore extends EventTarget {
|
|
120
|
+
private config;
|
|
121
|
+
/** Use with any `@umxr/bagsy` operation, e.g. `listLists(Bagsy.transport)`. */
|
|
122
|
+
readonly transport: Transport;
|
|
123
|
+
private saved;
|
|
124
|
+
private pending;
|
|
125
|
+
private flush?;
|
|
126
|
+
private listeners;
|
|
127
|
+
/** Resolves once any pending guest merge has finished. */
|
|
128
|
+
readonly ready: Promise<void>;
|
|
129
|
+
count?: number;
|
|
130
|
+
/** Storefront root without a trailing slash: '' or '/en-gb'. */
|
|
131
|
+
readonly root: string;
|
|
132
|
+
constructor(config?: BagsyConfig);
|
|
133
|
+
/** Fold the pre-login guest list into the customer's, once. */
|
|
134
|
+
private mergeGuestIfNeeded;
|
|
135
|
+
/** Subscribe to a product's saved state; triggers a (batched) lookup. */
|
|
136
|
+
watch(productId: string, listener: Listener): () => void;
|
|
137
|
+
isSaved(productId: string, variantId?: string): boolean | undefined;
|
|
138
|
+
/** Optimistic: listeners see the new state immediately and revert on failure. */
|
|
139
|
+
toggle(productId: string, variantId?: string): Promise<boolean>;
|
|
140
|
+
/** Items in the default list, newest first. */
|
|
141
|
+
items(): AsyncGenerator<{
|
|
142
|
+
id: string;
|
|
143
|
+
listId: string;
|
|
144
|
+
productId: components["schemas"]["ProductGid"];
|
|
145
|
+
variantId?: components["schemas"]["VariantGid"] | null;
|
|
146
|
+
quantity: number;
|
|
147
|
+
note?: string | null;
|
|
148
|
+
addedAt: string;
|
|
149
|
+
}, void, any>;
|
|
150
|
+
private countRequest?;
|
|
151
|
+
/** Load the count once per page; later calls share the first request. */
|
|
152
|
+
ensureCount(): Promise<number>;
|
|
153
|
+
/** Number of items in the default list, for header badges. */
|
|
154
|
+
loadCount(): Promise<number>;
|
|
155
|
+
private adjustCount;
|
|
156
|
+
private queue;
|
|
157
|
+
private notify;
|
|
158
|
+
private emit;
|
|
159
|
+
}
|
|
160
|
+
/** The page's store, configured from the app embed's JSON on first use. */
|
|
161
|
+
declare function getStore(): BagsyStore;
|
|
162
|
+
/** Replace the page store (tests, or custom setups before elements connect). */
|
|
163
|
+
declare function setStore(store: BagsyStore | undefined): void;
|
|
164
|
+
|
|
165
|
+
/** Register the elements. Safe to call more than once. */
|
|
166
|
+
declare function define(): void;
|
|
167
|
+
|
|
168
|
+
export { BagsyButton, BagsyCount, BagsyStore, BagsyWishlist, define, getStore, setStore };
|
|
169
|
+
export type { BagsyConfig, ChangeDetail };
|