@usethrottle/storefront-react 0.0.0-stage → 0.1.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/CLAUDE.md +67 -0
- package/README.md +119 -2
- package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
- package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
- package/dist/account/index.cjs +69 -0
- package/dist/account/index.cjs.map +1 -0
- package/dist/account/index.d.cts +23 -0
- package/dist/account/index.d.ts +23 -0
- package/dist/account/index.js +68 -0
- package/dist/account/index.js.map +1 -0
- package/dist/chunk-2LCPIY2P.cjs +16 -0
- package/dist/chunk-2LCPIY2P.cjs.map +1 -0
- package/dist/chunk-3A72UY6T.js +2126 -0
- package/dist/chunk-3A72UY6T.js.map +1 -0
- package/dist/chunk-3JMIVAHN.js +185 -0
- package/dist/chunk-3JMIVAHN.js.map +1 -0
- package/dist/chunk-4J6AGWNC.cjs +24 -0
- package/dist/chunk-4J6AGWNC.cjs.map +1 -0
- package/dist/chunk-4U6MYDZV.js +17 -0
- package/dist/chunk-4U6MYDZV.js.map +1 -0
- package/dist/chunk-66HDJVPS.js +22 -0
- package/dist/chunk-66HDJVPS.js.map +1 -0
- package/dist/chunk-6X2OZSNV.cjs +83 -0
- package/dist/chunk-6X2OZSNV.cjs.map +1 -0
- package/dist/chunk-6ZMMZ245.cjs +2127 -0
- package/dist/chunk-6ZMMZ245.cjs.map +1 -0
- package/dist/chunk-7R37CVAB.cjs +23 -0
- package/dist/chunk-7R37CVAB.cjs.map +1 -0
- package/dist/chunk-A3IFWQUV.js +368 -0
- package/dist/chunk-A3IFWQUV.js.map +1 -0
- package/dist/chunk-AYC2YK4E.cjs +95 -0
- package/dist/chunk-AYC2YK4E.cjs.map +1 -0
- package/dist/chunk-AZV5U7YB.cjs +18 -0
- package/dist/chunk-AZV5U7YB.cjs.map +1 -0
- package/dist/chunk-CE2SKNQP.cjs +71 -0
- package/dist/chunk-CE2SKNQP.cjs.map +1 -0
- package/dist/chunk-D76CRI4X.js +2175 -0
- package/dist/chunk-D76CRI4X.js.map +1 -0
- package/dist/chunk-DOAII637.cjs +186 -0
- package/dist/chunk-DOAII637.cjs.map +1 -0
- package/dist/chunk-DYHHAOMG.cjs +17 -0
- package/dist/chunk-DYHHAOMG.cjs.map +1 -0
- package/dist/chunk-EYSVU5SJ.js +196 -0
- package/dist/chunk-EYSVU5SJ.js.map +1 -0
- package/dist/chunk-HSUUDZWS.js +37 -0
- package/dist/chunk-HSUUDZWS.js.map +1 -0
- package/dist/chunk-HZ6VEN6Q.cjs +101 -0
- package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
- package/dist/chunk-IJOTLGPT.js +16 -0
- package/dist/chunk-IJOTLGPT.js.map +1 -0
- package/dist/chunk-ISDATHVC.js +219 -0
- package/dist/chunk-ISDATHVC.js.map +1 -0
- package/dist/chunk-LW2A6USV.js +100 -0
- package/dist/chunk-LW2A6USV.js.map +1 -0
- package/dist/chunk-M4YXSLRG.cjs +369 -0
- package/dist/chunk-M4YXSLRG.cjs.map +1 -0
- package/dist/chunk-NDUEJJLP.cjs +2176 -0
- package/dist/chunk-NDUEJJLP.cjs.map +1 -0
- package/dist/chunk-NNE4FYRT.js +820 -0
- package/dist/chunk-NNE4FYRT.js.map +1 -0
- package/dist/chunk-NW3EFHY2.js +15 -0
- package/dist/chunk-NW3EFHY2.js.map +1 -0
- package/dist/chunk-NZRUQUN5.js +167 -0
- package/dist/chunk-NZRUQUN5.js.map +1 -0
- package/dist/chunk-P6HHE57S.cjs +38 -0
- package/dist/chunk-P6HHE57S.cjs.map +1 -0
- package/dist/chunk-PHY7AY27.cjs +197 -0
- package/dist/chunk-PHY7AY27.cjs.map +1 -0
- package/dist/chunk-PNJOFFTL.cjs +128 -0
- package/dist/chunk-PNJOFFTL.cjs.map +1 -0
- package/dist/chunk-PXZQ4ONA.js +127 -0
- package/dist/chunk-PXZQ4ONA.js.map +1 -0
- package/dist/chunk-Q3VTUBPP.js +82 -0
- package/dist/chunk-Q3VTUBPP.js.map +1 -0
- package/dist/chunk-Q3XFD5UI.js +45 -0
- package/dist/chunk-Q3XFD5UI.js.map +1 -0
- package/dist/chunk-QM7KTT7F.js +94 -0
- package/dist/chunk-QM7KTT7F.js.map +1 -0
- package/dist/chunk-RLWZOLXL.js +70 -0
- package/dist/chunk-RLWZOLXL.js.map +1 -0
- package/dist/chunk-SV53BRP2.js +23 -0
- package/dist/chunk-SV53BRP2.js.map +1 -0
- package/dist/chunk-VWXJO427.cjs +821 -0
- package/dist/chunk-VWXJO427.cjs.map +1 -0
- package/dist/chunk-WIIOJDHR.cjs +220 -0
- package/dist/chunk-WIIOJDHR.cjs.map +1 -0
- package/dist/chunk-XQHGFWLG.cjs +46 -0
- package/dist/chunk-XQHGFWLG.cjs.map +1 -0
- package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
- package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
- package/dist/index-RSj2Rg62.d.cts +8 -0
- package/dist/index-RSj2Rg62.d.ts +8 -0
- package/dist/index.cjs +2829 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1718 -0
- package/dist/index.d.ts +1718 -0
- package/dist/index.js +2828 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata-QhKw-tvz.d.cts +188 -0
- package/dist/metadata-QhKw-tvz.d.ts +188 -0
- package/dist/next/client.cjs +84 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +40 -0
- package/dist/next/client.d.ts +40 -0
- package/dist/next/client.js +83 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/index.cjs +1090 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +218 -0
- package/dist/next/index.d.ts +218 -0
- package/dist/next/index.js +1049 -0
- package/dist/next/index.js.map +1 -0
- package/dist/server/index.cjs +994 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +229 -0
- package/dist/server/index.d.ts +229 -0
- package/dist/server/index.js +951 -0
- package/dist/server/index.js.map +1 -0
- package/dist/styles.css +2111 -0
- package/dist/use-part-DCfFk7kf.d.ts +24 -0
- package/dist/use-part-DgjPBL_O.d.cts +24 -0
- package/package.json +121 -3
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkHZ6VEN6Qcjs = require('./chunk-HZ6VEN6Q.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkDYHHAOMGcjs = require('./chunk-DYHHAOMG.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
|
|
12
|
+
|
|
13
|
+
// src/url/shop-list-query.ts
|
|
14
|
+
var _url = require('@usethrottle/catalog/url');
|
|
15
|
+
var LITE_FIELDS = [
|
|
16
|
+
"availability",
|
|
17
|
+
"badges",
|
|
18
|
+
"brand",
|
|
19
|
+
"featured",
|
|
20
|
+
"handle",
|
|
21
|
+
"images",
|
|
22
|
+
"lowStock",
|
|
23
|
+
"optionSwatches",
|
|
24
|
+
"priceRange",
|
|
25
|
+
"productType",
|
|
26
|
+
"rating",
|
|
27
|
+
"seo",
|
|
28
|
+
"title",
|
|
29
|
+
"variantCount"
|
|
30
|
+
];
|
|
31
|
+
function cardFields(settings) {
|
|
32
|
+
return settings.card.showBadges && settings.badges.custom.length > 0 ? [...LITE_FIELDS, "tags"] : void 0;
|
|
33
|
+
}
|
|
34
|
+
function shopListQuery(query, source, settings, o = {}) {
|
|
35
|
+
const { listing } = settings;
|
|
36
|
+
const filters = {};
|
|
37
|
+
for (const [key, values] of Object.entries(query.filters)) filters[key] = [...values];
|
|
38
|
+
for (const [key, range] of Object.entries(query.ranges)) (filters[key] ??= []).push(_url.formatRange.call(void 0, range));
|
|
39
|
+
const out = {
|
|
40
|
+
limit: listing.pageSize,
|
|
41
|
+
facets: true,
|
|
42
|
+
...o.fields ? { fields: o.fields } : {},
|
|
43
|
+
...query.page > 1 ? { page: query.page } : {},
|
|
44
|
+
...query.q ? { q: query.q } : {},
|
|
45
|
+
...Object.keys(filters).length > 0 ? { filters } : {},
|
|
46
|
+
...source.kind === "collection" ? { collection: source.handle } : {},
|
|
47
|
+
...source.kind === "category" ? { category: source.handle } : {},
|
|
48
|
+
...source.kind === "tag" ? { tags: [source.handle] } : {}
|
|
49
|
+
};
|
|
50
|
+
if (query.sort !== listing.defaultSort) {
|
|
51
|
+
const usable = query.sort === "relevance" ? Boolean(query.q) : query.sort === "manual" ? o.manualCollection === true : true;
|
|
52
|
+
if (usable) out.sort = query.sort;
|
|
53
|
+
} else if ((source.kind === "all" || source.kind === "category" || source.kind === "tag") && !["featured", "relevance", "manual"].includes(listing.defaultSort)) {
|
|
54
|
+
out.sort = listing.defaultSort;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/merch/product-source.ts
|
|
60
|
+
var MAX_MERCH_LIMIT = 96;
|
|
61
|
+
function clampLimit(limit) {
|
|
62
|
+
return Number.isFinite(limit) ? Math.min(MAX_MERCH_LIMIT, Math.max(1, Math.floor(limit))) : 1;
|
|
63
|
+
}
|
|
64
|
+
function manualHandles(source) {
|
|
65
|
+
return [...new Set(source.handles.filter((h) => typeof h === "string" && h.trim() !== ""))];
|
|
66
|
+
}
|
|
67
|
+
function isEmptySource(source) {
|
|
68
|
+
if (source.kind === "manual") return manualHandles(source).length === 0;
|
|
69
|
+
if (source.kind === "collection" || source.kind === "category" || source.kind === "tag") return source.handle.trim() === "";
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function productSourceQuery(source, limit, o = {}) {
|
|
73
|
+
const more = o.fields ? { fields: o.fields } : {};
|
|
74
|
+
const size = clampLimit(limit);
|
|
75
|
+
switch (source.kind) {
|
|
76
|
+
case "collection":
|
|
77
|
+
return { collection: source.handle, limit: size, ...more };
|
|
78
|
+
case "category":
|
|
79
|
+
return { category: source.handle, limit: size, ...more };
|
|
80
|
+
case "tag":
|
|
81
|
+
return { tags: [source.handle], limit: size, ...more };
|
|
82
|
+
case "featured":
|
|
83
|
+
return { featured: true, limit: size, ...more };
|
|
84
|
+
case "newest":
|
|
85
|
+
case "best_rated":
|
|
86
|
+
return { sort: source.kind, limit: size, ...more };
|
|
87
|
+
case "manual": {
|
|
88
|
+
const handles = manualHandles(source).slice(0, size);
|
|
89
|
+
return { handles, limit: Math.max(1, handles.length), ...more };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function orderByHandles(products, handles) {
|
|
94
|
+
const byHandle = new Map(products.map((p) => [p.handle, p]));
|
|
95
|
+
return handles.flatMap((h) => {
|
|
96
|
+
const found = byHandle.get(h);
|
|
97
|
+
return found ? [found] : [];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function sourceProducts(source, products, limit) {
|
|
101
|
+
const ordered = source.kind === "manual" ? orderByHandles(products, manualHandles(source)) : [...products];
|
|
102
|
+
return ordered.slice(0, clampLimit(limit));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/merch/use-merch.ts
|
|
106
|
+
var _react = require('@usethrottle/catalog/react');
|
|
107
|
+
var _react3 = require('react');
|
|
108
|
+
var MERCH_STALE_MS = 36e5;
|
|
109
|
+
function seedOf(data, limit) {
|
|
110
|
+
return {
|
|
111
|
+
products: data.products,
|
|
112
|
+
page: { number: 1, limit, total: null, pageCount: null, nextCursor: null },
|
|
113
|
+
...data.priceContext ? { priceContext: data.priceContext } : {}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function useMerchProducts(source, o) {
|
|
117
|
+
const { settings } = _chunkVWXJO427cjs.useStorefront.call(void 0, );
|
|
118
|
+
const empty = isEmptySource(source);
|
|
119
|
+
const sourceKey = JSON.stringify(source);
|
|
120
|
+
const query = _react3.useMemo.call(void 0,
|
|
121
|
+
() => productSourceQuery(source, o.limit, { fields: cardFields(settings) }),
|
|
122
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
123
|
+
[sourceKey, o.limit, settings]
|
|
124
|
+
);
|
|
125
|
+
const seed = _react3.useMemo.call(void 0, () => o.initialData ? seedOf(o.initialData, o.limit) : void 0, [o.initialData, o.limit]);
|
|
126
|
+
const list = _react.useProducts.call(void 0, query, { enabled: !empty, initialData: seed, staleTimeMs: MERCH_STALE_MS });
|
|
127
|
+
const needTitle = Boolean(o.withTitle) && source.kind === "collection" && !empty && !_optionalChain([o, 'access', _ => _.initialData, 'optionalAccess', _2 => _2.title]);
|
|
128
|
+
const handle = needTitle && source.kind === "collection" ? source.handle : null;
|
|
129
|
+
const first = _react.useCollection.call(void 0, handle, { staleTimeMs: MERCH_STALE_MS });
|
|
130
|
+
const renamed = first.data && "redirectTo" in first.data ? first.data.redirectTo : null;
|
|
131
|
+
const second = _react.useCollection.call(void 0, renamed, { staleTimeMs: MERCH_STALE_MS });
|
|
132
|
+
const found = [first.data, second.data].find((d) => d && "collection" in d);
|
|
133
|
+
const title = _nullishCoalesce(_optionalChain([o, 'access', _3 => _3.initialData, 'optionalAccess', _4 => _4.title]), () => ( (found && "collection" in found ? found.collection.title : void 0)));
|
|
134
|
+
const titleLoading = needTitle && (first.isLoading || renamed !== null && second.isLoading);
|
|
135
|
+
const products = _react3.useMemo.call(void 0,
|
|
136
|
+
() => list.data && !empty ? sourceProducts(source, list.data.products, o.limit) : [],
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
[list.data, empty, sourceKey, o.limit]
|
|
139
|
+
);
|
|
140
|
+
const arrivedAt = _react3.useMemo.call(void 0, () => (/* @__PURE__ */ new Date()).toISOString(), [list.data]);
|
|
141
|
+
const generatedAt = o.initialData && _optionalChain([list, 'access', _5 => _5.data, 'optionalAccess', _6 => _6.products]) === o.initialData.products ? o.initialData.generatedAt : arrivedAt;
|
|
142
|
+
const status = empty || list.data && !titleLoading ? "ready" : list.error && !list.data ? "error" : "loading";
|
|
143
|
+
return {
|
|
144
|
+
products,
|
|
145
|
+
status,
|
|
146
|
+
generatedAt,
|
|
147
|
+
...title ? { title } : {},
|
|
148
|
+
..._optionalChain([list, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.priceContext]) ? { priceContext: list.data.priceContext } : {}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function useListAnalytics(listName, products) {
|
|
152
|
+
const track = _chunkDYHHAOMGcjs.useTrack.call(void 0, );
|
|
153
|
+
const { currency: provided } = _chunkVWXJO427cjs.useStorefront.call(void 0, );
|
|
154
|
+
const sent = _react3.useRef.call(void 0, null);
|
|
155
|
+
const currency = _nullishCoalesce(_optionalChain([products, 'access', _9 => _9.find, 'call', _10 => _10((p) => p.priceRange), 'optionalAccess', _11 => _11.priceRange, 'optionalAccess', _12 => _12.currency]), () => ( provided));
|
|
156
|
+
const handles = products.map((p) => p.handle).join(",");
|
|
157
|
+
_react3.useEffect.call(void 0, () => {
|
|
158
|
+
if (products.length === 0 || !currency) return;
|
|
159
|
+
const key = `${_nullishCoalesce(listName, () => ( ""))}|${handles}`;
|
|
160
|
+
if (sent.current === key) return;
|
|
161
|
+
sent.current = key;
|
|
162
|
+
track("view_item_list", {
|
|
163
|
+
currency,
|
|
164
|
+
...listName ? { item_list_name: listName } : {},
|
|
165
|
+
items: products.map((p, index) => _chunkHZ6VEN6Qcjs.toGa4Item.call(void 0, p, { index, listName }))
|
|
166
|
+
});
|
|
167
|
+
}, [listName, handles, currency, track]);
|
|
168
|
+
return (product) => {
|
|
169
|
+
const index = products.findIndex((p) => p.handle === product.handle);
|
|
170
|
+
const cur = _nullishCoalesce(_optionalChain([product, 'access', _13 => _13.priceRange, 'optionalAccess', _14 => _14.currency]), () => ( currency));
|
|
171
|
+
if (!cur) return;
|
|
172
|
+
track("select_item", { currency: cur, ...listName ? { item_list_name: listName } : {}, items: [_chunkHZ6VEN6Qcjs.toGa4Item.call(void 0, product, { index: index < 0 ? void 0 : index, listName })] });
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
exports.cardFields = cardFields; exports.shopListQuery = shopListQuery; exports.isEmptySource = isEmptySource; exports.productSourceQuery = productSourceQuery; exports.orderByHandles = orderByHandles; exports.MERCH_STALE_MS = MERCH_STALE_MS; exports.useMerchProducts = useMerchProducts; exports.useListAnalytics = useListAnalytics;
|
|
186
|
+
//# sourceMappingURL=chunk-DOAII637.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-DOAII637.cjs","../src/url/shop-list-query.ts","../src/merch/product-source.ts","../src/merch/use-merch.ts"],"names":[],"mappings":"AAAA,6rBAAY;AACZ;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACVA,+CAA4B;AAK5B,IAAM,YAAA,EAAc;AAAA,EAClB,cAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,gBAAA;AAAA,EACA,Y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AAA,IACA,GAAI,MAAA,EAAQ,EAAE,MAAM,EAAA,EAAI,CAAC,CAAA;AAAA,IACzB,mBAAI,IAAA,qBAAK,IAAA,6BAAM,eAAA,EAAe,EAAE,YAAA,EAAc,IAAA,CAAK,IAAA,CAAK,aAAa,EAAA,EAAI,CAAC;AAAA,EAC5E,CAAA;AACF;AAMO,SAAS,gBAAA,CAAiB,QAAA,EAA8B,QAAA,EAAkE;AAC/H,EAAA,MAAM,MAAA,EAAQ,wCAAA,CAAS;AACvB,EAAA,MAAM,EAAE,QAAA,EAAU,SAAS,EAAA,EAAI,6CAAA,CAAc;AAC7C,EAAA,MAAM,KAAA,EAAO,4BAAA,IAA0B,CAAA;AACvC,EAAA,MAAM,SAAA,mCAAW,QAAA,qBAAS,IAAA,qBAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,UAAU,CAAA,+BAAG,UAAA,+BAAY,UAAA,UAAY,UAAA;AAC7E,EAAA,MAAM,QAAA,EAAU,QAAA,CAAS,GAAA,CAAI,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,MAAM,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAEtD,EAAA,+BAAA,CAAU,EAAA,GAAM;AACd,IAAA,GAAA,CAAI,QAAA,CAAS,OAAA,IAAW,EAAA,GAAK,CAAC,QAAA,EAAU,MAAA;AACxC,IAAA,MAAM,IAAA,EAAM,CAAA,mBAAA;AACH,IAAA;AACJ,IAAA;AACC,IAAA;AACJ,MAAA;AACI,MAAA;AACG,MAAA;AACR,IAAA;AAGW,EAAA;AAEN,EAAA;AACA,IAAA;AACM,IAAA;AACF,IAAA;AACJ,IAAA;AACR,EAAA;AACF;AHqDiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-DOAII637.cjs","sourcesContent":[null,"import type { ProductsQuery } from '@usethrottle/catalog';\nimport { formatRange } from '@usethrottle/catalog/url';\nimport type { NormalizedSettings } from '../settings/normalize';\nimport type { ShopQuery, ShopSource } from './shop-query';\n\n/** What the catalog's list answer carries by default (`fields: 'lite'`), as the keys `fields` takes. */\nconst LITE_FIELDS = [\n 'availability',\n 'badges',\n 'brand',\n 'featured',\n 'handle',\n 'images',\n 'lowStock',\n 'optionSwatches',\n 'priceRange',\n 'productType',\n 'rating',\n 'seo',\n 'title',\n 'variantCount',\n] as const;\n\n/**\n * The `fields` a product list asks for. A custom tag badge needs the product's\n * tags, which the default (lite) answer leaves out. Undefined otherwise, so the\n * request is the default one.\n */\nexport function cardFields(settings: NormalizedSettings): readonly string[] | undefined {\n return settings.card.showBadges && settings.badges.custom.length > 0 ? [...LITE_FIELDS, 'tags'] : undefined;\n}\n\n/**\n * The `products.list` query for a listing. Pure, and the one place it is built:\n * the server loader and a client island both call it, so the island's request\n * matches the server's and starts on its answer (`initialData`).\n *\n * The page's path (`source`) names the collection, category or tag. A sort that\n * is not the store's default counts as asked for (the URL omits the default):\n * it is kept when it makes sense, `relevance` only with a search and `manual`\n * only on a manual collection (`manualCollection`). With no sort asked for, the\n * shop, a category or a tag takes `listing.defaultSort` (`featured` is the\n * catalog's own default); a collection keeps its own order and a search keeps\n * relevance. Pass `fields` from `cardFields(settings)`.\n */\nexport function shopListQuery(\n query: ShopQuery,\n source: ShopSource,\n settings: NormalizedSettings,\n o: { fields?: readonly string[]; manualCollection?: boolean } = {},\n): ProductsQuery {\n const { listing } = settings;\n const filters: Record<string, string[]> = {};\n for (const [key, values] of Object.entries(query.filters)) filters[key] = [...values];\n for (const [key, range] of Object.entries(query.ranges)) (filters[key] ??= []).push(formatRange(range));\n const out: ProductsQuery = {\n limit: listing.pageSize,\n facets: true,\n ...(o.fields ? { fields: o.fields } : {}),\n ...(query.page > 1 ? { page: query.page } : {}),\n ...(query.q ? { q: query.q } : {}),\n ...(Object.keys(filters).length > 0 ? { filters } : {}),\n ...(source.kind === 'collection' ? { collection: source.handle } : {}),\n ...(source.kind === 'category' ? { category: source.handle } : {}),\n ...(source.kind === 'tag' ? { tags: [source.handle] } : {}),\n };\n if (query.sort !== listing.defaultSort) {\n const usable =\n query.sort === 'relevance' ? Boolean(query.q) : query.sort === 'manual' ? o.manualCollection === true : true;\n if (usable) out.sort = query.sort;\n } else if (\n (source.kind === 'all' || source.kind === 'category' || source.kind === 'tag') &&\n !['featured', 'relevance', 'manual'].includes(listing.defaultSort)\n ) {\n out.sort = listing.defaultSort;\n }\n return out;\n}\n","// Server-safe: types and pure functions only (`./server` re-exports it), so nothing here imports React.\nimport type { ListProduct, ProductsQuery } from '@usethrottle/catalog';\n\n/** What a section lists. Plain data, so a Builder can store it as a widget's prop. */\nexport type ProductSource =\n | { kind: 'collection' | 'category' | 'tag'; handle: string }\n | { kind: 'featured' | 'newest' | 'best_rated' }\n | { kind: 'manual'; handles: string[] };\n\n/** The catalog's `products.list` query. */\nexport type ListQuery = ProductsQuery;\n\n/**\n * What `loadMerchProducts` answers and a section's `initialData` takes. Plain JSON.\n * `title` is a collection's own title and `priceContext` is the list answer's; both are optional.\n */\nexport type MerchProductsData = {\n products: ListProduct[];\n /** When the server built this answer (ISO 8601). The `new` badge ages against it. */\n generatedAt: string;\n title?: string;\n priceContext?: 'anonymous' | 'customer' | 'email_unverified' | 'anonymous_fallback';\n};\n\n/** The most one products request may ask for (the catalog's page limit). */\nexport const MAX_MERCH_LIMIT = 96;\n\n/** `limit` as a whole number from 1 to the catalog's page limit. */\nexport function clampLimit(limit: number): number {\n return Number.isFinite(limit) ? Math.min(MAX_MERCH_LIMIT, Math.max(1, Math.floor(limit))) : 1;\n}\n\n/** The handles of a manual source, without blanks or repeats, in the given order. */\nexport function manualHandles(source: Extract<ProductSource, { kind: 'manual' }>): string[] {\n return [...new Set(source.handles.filter((h) => typeof h === 'string' && h.trim() !== ''))];\n}\n\n/** A source that names nothing (a blank handle, no manual handles) lists nothing and asks for nothing. */\nexport function isEmptySource(source: ProductSource): boolean {\n if (source.kind === 'manual') return manualHandles(source).length === 0;\n if (source.kind === 'collection' || source.kind === 'category' || source.kind === 'tag') return source.handle.trim() === '';\n return false;\n}\n\n/**\n * The `products.list` query for a source: the shelf mapping of Meridian\n * `lib/home.ts` (`featured` is the featured flag; `newest` and `best_rated` are\n * those sorts). A `manual` source asks for its handles in one request; the\n * catalog does not promise their order, so `orderByHandles` restores it.\n * `fields` is `cardFields(settings)`, the same one the server loader uses.\n */\nexport function productSourceQuery(source: ProductSource, limit: number, o: { fields?: readonly string[] } = {}): ListQuery {\n const more = o.fields ? { fields: o.fields } : {};\n const size = clampLimit(limit);\n switch (source.kind) {\n case 'collection':\n return { collection: source.handle, limit: size, ...more };\n case 'category':\n return { category: source.handle, limit: size, ...more };\n case 'tag':\n return { tags: [source.handle], limit: size, ...more };\n case 'featured':\n return { featured: true, limit: size, ...more };\n case 'newest':\n case 'best_rated':\n return { sort: source.kind, limit: size, ...more };\n case 'manual': {\n const handles = manualHandles(source).slice(0, size);\n return { handles, limit: Math.max(1, handles.length), ...more };\n }\n }\n}\n\n/** A manual source's products in the order its handles give; one the catalog did not answer is left out. */\nexport function orderByHandles(products: readonly ListProduct[], handles: readonly string[]): ListProduct[] {\n const byHandle = new Map(products.map((p) => [p.handle, p]));\n return handles.flatMap((h) => {\n const found = byHandle.get(h);\n return found ? [found] : [];\n });\n}\n\n/** What a source's answer shows: a manual source in its own order, every source cut to `limit`. */\nexport function sourceProducts(source: ProductSource, products: readonly ListProduct[], limit: number): ListProduct[] {\n const ordered = source.kind === 'manual' ? orderByHandles(products, manualHandles(source)) : [...products];\n return ordered.slice(0, clampLimit(limit));\n}\n","import type { ListProduct, StorefrontListAnswer } from '@usethrottle/catalog';\nimport { useCollection, useProducts } from '@usethrottle/catalog/react';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { toGa4Item } from '../analytics/items';\nimport { useTrack } from '../analytics/use-track';\nimport { useStorefront } from '../provider/context';\nimport { cardFields } from '../url/shop-list-query';\nimport {\n isEmptySource,\n productSourceQuery,\n sourceProducts,\n type MerchProductsData,\n type ProductSource,\n} from './product-source';\n\n/** A merchandising read is fresh for an hour: the storefront generation watch invalidates it when the merchant publishes. */\nexport const MERCH_STALE_MS = 3_600_000;\n\n/** What a merchandising read answers: the products, a status and when the data was made. */\nexport type MerchProducts = {\n products: ListProduct[];\n /** `loading` until the first answer (a section shows a placeholder), `error` when there is none (a section renders nothing). */\n status: 'ready' | 'loading' | 'error';\n /** When the data was made (ISO). The server's time for `initialData`, else when the browser got the answer. */\n generatedAt: string;\n /** A collection's title, when `withTitle` asked for it and the catalog has one. */\n title?: string;\n priceContext?: MerchProductsData['priceContext'];\n};\n\n/** `initialData` as the catalog hook's seed. The hook reads only `products` and `priceContext` from it. */\nfunction seedOf(data: MerchProductsData, limit: number): StorefrontListAnswer {\n return {\n products: data.products,\n page: { number: 1, limit, total: null, pageCount: null, nextCursor: null },\n ...(data.priceContext ? { priceContext: data.priceContext } : {}),\n } as StorefrontListAnswer;\n}\n\n/**\n * The products of a source: one `products.list` request however many cards it\n * shows (a manual source's handles go in one request). With `initialData` (from\n * `loadMerchProducts`) the first render has the answer and makes no request.\n * `withTitle` also reads a collection's title, unless `initialData` has it.\n */\nexport function useMerchProducts(\n source: ProductSource,\n o: { limit: number; initialData?: MerchProductsData; withTitle?: boolean },\n): MerchProducts {\n const { settings } = useStorefront();\n const empty = isEmptySource(source);\n const sourceKey = JSON.stringify(source);\n // `source` is compared by value: an inline object must not make a new request on every render.\n const query = useMemo(\n () => productSourceQuery(source, o.limit, { fields: cardFields(settings) }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [sourceKey, o.limit, settings],\n );\n const seed = useMemo(() => (o.initialData ? seedOf(o.initialData, o.limit) : undefined), [o.initialData, o.limit]);\n const list = useProducts(query, { enabled: !empty, initialData: seed, staleTimeMs: MERCH_STALE_MS });\n\n const needTitle = Boolean(o.withTitle) && source.kind === 'collection' && !empty && !o.initialData?.title;\n const handle = needTitle && source.kind === 'collection' ? source.handle : null;\n const first = useCollection(handle, { staleTimeMs: MERCH_STALE_MS });\n const renamed = first.data && 'redirectTo' in first.data ? first.data.redirectTo : null;\n const second = useCollection(renamed, { staleTimeMs: MERCH_STALE_MS });\n const found = [first.data, second.data].find((d) => d && 'collection' in d);\n const title = o.initialData?.title ?? (found && 'collection' in found ? found.collection.title : undefined);\n const titleLoading = needTitle && (first.isLoading || (renamed !== null && second.isLoading));\n\n const products = useMemo(\n () => (list.data && !empty ? sourceProducts(source, list.data.products, o.limit) : []),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [list.data, empty, sourceKey, o.limit],\n );\n // Browser-fetched data has no server time: its own arrival is the best the `new` badge has.\n const arrivedAt = useMemo(() => new Date().toISOString(), [list.data]);\n const generatedAt = o.initialData && list.data?.products === o.initialData.products ? o.initialData.generatedAt : arrivedAt;\n\n const status = empty || (list.data && !titleLoading) ? 'ready' : list.error && !list.data ? 'error' : 'loading';\n return {\n products,\n status,\n generatedAt,\n ...(title ? { title } : {}),\n ...(list.data?.priceContext ? { priceContext: list.data.priceContext } : {}),\n };\n}\n\n/**\n * `view_item_list` once per list (the same handles under the same name), when\n * the products are first ready. Returns `select_item` for a card's `onSelect`.\n */\nexport function useListAnalytics(listName: string | undefined, products: readonly ListProduct[]): (product: ListProduct) => void {\n const track = useTrack();\n const { currency: provided } = useStorefront();\n const sent = useRef<string | null>(null);\n const currency = products.find((p) => p.priceRange)?.priceRange?.currency ?? provided;\n const handles = products.map((p) => p.handle).join(',');\n\n useEffect(() => {\n if (products.length === 0 || !currency) return;\n const key = `${listName ?? ''}|${handles}`;\n if (sent.current === key) return;\n sent.current = key;\n track('view_item_list', {\n currency,\n ...(listName ? { item_list_name: listName } : {}),\n items: products.map((p, index) => toGa4Item(p, { index, listName })),\n });\n // `products` is read through `handles`: the event is about which products, not about a new array.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [listName, handles, currency, track]);\n\n return (product) => {\n const index = products.findIndex((p) => p.handle === product.handle);\n const cur = product.priceRange?.currency ?? currency;\n if (!cur) return;\n track('select_item', { currency: cur, ...(listName ? { item_list_name: listName } : {}), items: [toGa4Item(product, { index: index < 0 ? undefined : index, listName })] });\n };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
|
|
6
|
+
|
|
7
|
+
// src/analytics/use-track.ts
|
|
8
|
+
var _react = require('react');
|
|
9
|
+
function useTrack() {
|
|
10
|
+
const { analytics } = _chunkVWXJO427cjs.useStorefront.call(void 0, );
|
|
11
|
+
return _react.useCallback.call(void 0, (event, payload) => analytics.track(event, payload), [analytics]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.useTrack = useTrack;
|
|
17
|
+
//# sourceMappingURL=chunk-DYHHAOMG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-DYHHAOMG.cjs","../src/analytics/use-track.ts"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACE;AACF,wDAA6B;AAC7B;AACA;ACLA,8BAA4B;AAKrB,SAAS,QAAA,CAAA,EAAyC;AACvD,EAAA,MAAM,EAAE,UAAU,EAAA,EAAI,6CAAA,CAAc;AACpC,EAAA,OAAO,gCAAA,CAAa,KAAA,EAAO,OAAA,EAAA,GAAY,SAAA,CAAU,KAAA,CAAM,KAAA,EAAO,OAAO,CAAA,EAAG,CAAC,SAAS,CAAC,CAAA;AACrF;ADGA;AACA;AACE;AACF,4BAAC","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-DYHHAOMG.cjs","sourcesContent":[null,"import { useCallback } from 'react';\nimport { useStorefront } from '../provider/context';\nimport type { StorefrontAnalytics } from './types';\n\n/** Reports an event to the provider's `analytics` adapter (a no-op unless one was given). */\nexport function useTrack(): StorefrontAnalytics['track'] {\n const { analytics } = useStorefront();\n return useCallback((event, payload) => analytics.track(event, payload), [analytics]);\n}\n"]}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
ProductPage,
|
|
4
|
+
QuietRouter
|
|
5
|
+
} from "./chunk-D76CRI4X.js";
|
|
6
|
+
import {
|
|
7
|
+
MERCH_STALE_MS
|
|
8
|
+
} from "./chunk-3JMIVAHN.js";
|
|
9
|
+
import {
|
|
10
|
+
routeHref,
|
|
11
|
+
toGa4Item
|
|
12
|
+
} from "./chunk-LW2A6USV.js";
|
|
13
|
+
import {
|
|
14
|
+
useTrack
|
|
15
|
+
} from "./chunk-IJOTLGPT.js";
|
|
16
|
+
import {
|
|
17
|
+
useStrings
|
|
18
|
+
} from "./chunk-Q3XFD5UI.js";
|
|
19
|
+
import {
|
|
20
|
+
usePart,
|
|
21
|
+
useStorefront
|
|
22
|
+
} from "./chunk-NNE4FYRT.js";
|
|
23
|
+
|
|
24
|
+
// src/shopper/QuickAdd.tsx
|
|
25
|
+
import { useCart, useProduct } from "@usethrottle/catalog/react";
|
|
26
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
27
|
+
import { createPortal } from "react-dom";
|
|
28
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
var PANEL_GAP = 8;
|
|
30
|
+
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
31
|
+
function anchorFor(button, dir) {
|
|
32
|
+
const rect = button.getBoundingClientRect();
|
|
33
|
+
const below = rect.top < window.innerHeight / 2;
|
|
34
|
+
const inlineEnd = Math.max(PANEL_GAP, dir === "rtl" ? rect.left : window.innerWidth - rect.right);
|
|
35
|
+
return {
|
|
36
|
+
host: button.closest(".tsf-root"),
|
|
37
|
+
style: {
|
|
38
|
+
position: "fixed",
|
|
39
|
+
insetInlineEnd: inlineEnd,
|
|
40
|
+
...below ? { insetBlockStart: rect.bottom + PANEL_GAP } : { insetBlockEnd: window.innerHeight - rect.top + PANEL_GAP },
|
|
41
|
+
maxBlockSize: `calc(100vh - ${2 * PANEL_GAP}px)`
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function QuickAdd({ product, ...local }) {
|
|
46
|
+
const { currency, settings, dir } = useStorefront();
|
|
47
|
+
const { t } = useStrings();
|
|
48
|
+
const track = useTrack();
|
|
49
|
+
const cart = useCart(currency ? { currency } : void 0);
|
|
50
|
+
const title = product.title ?? product.handle;
|
|
51
|
+
const panelId = useId();
|
|
52
|
+
const trigger = useRef(null);
|
|
53
|
+
const panelRef = useRef(null);
|
|
54
|
+
const [anchor, setAnchor] = useState(null);
|
|
55
|
+
const open = anchor !== null;
|
|
56
|
+
const [busy, setBusy] = useState(false);
|
|
57
|
+
const [message, setMessage] = useState(null);
|
|
58
|
+
const soldOut = product.availability === "out_of_stock";
|
|
59
|
+
const single = (product.variantCount ?? product.variants?.length) === 1;
|
|
60
|
+
const part = usePart("quick-add", local);
|
|
61
|
+
const button = usePart("quick-add-button", local);
|
|
62
|
+
const panel = usePart("quick-add-panel", local);
|
|
63
|
+
const heading = usePart("quick-add-title", local);
|
|
64
|
+
const status = usePart("quick-add-message", local);
|
|
65
|
+
const close = useCallback(() => {
|
|
66
|
+
setAnchor(null);
|
|
67
|
+
trigger.current?.focus();
|
|
68
|
+
}, []);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!open) return;
|
|
71
|
+
const away = (event) => {
|
|
72
|
+
if (event.target instanceof Node && panelRef.current?.contains(event.target)) return;
|
|
73
|
+
setAnchor(null);
|
|
74
|
+
};
|
|
75
|
+
const onKey = (event) => {
|
|
76
|
+
if (event.key === "Escape") close();
|
|
77
|
+
};
|
|
78
|
+
const onPointer = (event) => {
|
|
79
|
+
const target = event.target;
|
|
80
|
+
if (!panelRef.current?.contains(target) && !trigger.current?.contains(target)) setAnchor(null);
|
|
81
|
+
};
|
|
82
|
+
panelRef.current?.focus();
|
|
83
|
+
document.addEventListener("keydown", onKey);
|
|
84
|
+
document.addEventListener("mousedown", onPointer);
|
|
85
|
+
window.addEventListener("scroll", away, true);
|
|
86
|
+
window.addEventListener("resize", away);
|
|
87
|
+
return () => {
|
|
88
|
+
document.removeEventListener("keydown", onKey);
|
|
89
|
+
document.removeEventListener("mousedown", onPointer);
|
|
90
|
+
window.removeEventListener("scroll", away, true);
|
|
91
|
+
window.removeEventListener("resize", away);
|
|
92
|
+
};
|
|
93
|
+
}, [open, close]);
|
|
94
|
+
const panelNode = anchor && !single ? /* @__PURE__ */ jsxs(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
...panel,
|
|
98
|
+
ref: panelRef,
|
|
99
|
+
id: panelId,
|
|
100
|
+
role: "group",
|
|
101
|
+
tabIndex: -1,
|
|
102
|
+
"aria-label": t("shopper.quickAdd.panelFor", { title }),
|
|
103
|
+
style: anchor.style,
|
|
104
|
+
onKeyDown: (event) => {
|
|
105
|
+
if (event.key !== "Tab") return;
|
|
106
|
+
const items = [...event.currentTarget.querySelectorAll(FOCUSABLE)];
|
|
107
|
+
const at = document.activeElement;
|
|
108
|
+
const leaving = event.shiftKey ? at === event.currentTarget || at === items[0] : at === items.at(-1) || items.length === 0;
|
|
109
|
+
if (!leaving) return;
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
close();
|
|
112
|
+
},
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ jsx("p", { ...heading, children: title }),
|
|
115
|
+
/* @__PURE__ */ jsx(QuietRouter, { pathname: routeHref(settings, "product", product.handle), children: /* @__PURE__ */ jsxs(ProductPage.Root, { handle: product.handle, ...local, children: [
|
|
116
|
+
/* @__PURE__ */ jsx(ProductPage.VariantPicker, { ...local }),
|
|
117
|
+
/* @__PURE__ */ jsx(ProductPage.AddToCart, { ...local })
|
|
118
|
+
] }) })
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
) : null;
|
|
122
|
+
const [asked, setAsked] = useState(false);
|
|
123
|
+
const read = useProduct(asked && single && !product.variants?.length ? product.handle : null, { staleTimeMs: MERCH_STALE_MS });
|
|
124
|
+
const readVariants = read.data && "product" in read.data ? read.data.product.variants : void 0;
|
|
125
|
+
const variants = product.variants?.length ? product.variants : readVariants;
|
|
126
|
+
const add = useCallback(
|
|
127
|
+
async (sku) => {
|
|
128
|
+
try {
|
|
129
|
+
if (!sku) {
|
|
130
|
+
setMessage({ tone: "refused", text: t("shopper.quickAdd.unavailable") });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await cart.add(sku, 1);
|
|
134
|
+
const cur = product.priceRange?.currency ?? currency;
|
|
135
|
+
if (cur) track("add_to_cart", { currency: cur, items: [{ ...toGa4Item(product, { variantSku: sku, quantity: 1 }), item_id: sku }] });
|
|
136
|
+
setMessage({ tone: "ok", text: t("shopper.quickAdd.added", { title }) });
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
139
|
+
setMessage({ tone: "refused", text: t("shopper.quickAdd.failed") });
|
|
140
|
+
} finally {
|
|
141
|
+
setBusy(false);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[cart, currency, product, t, title, track]
|
|
145
|
+
);
|
|
146
|
+
const waiting = useRef(false);
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!waiting.current) return;
|
|
149
|
+
if (variants) {
|
|
150
|
+
waiting.current = false;
|
|
151
|
+
void add(variants[0]?.sku);
|
|
152
|
+
} else if (read.error) {
|
|
153
|
+
waiting.current = false;
|
|
154
|
+
setMessage({ tone: "refused", text: t("shopper.quickAdd.failed") });
|
|
155
|
+
setBusy(false);
|
|
156
|
+
}
|
|
157
|
+
}, [variants, read.error, add, t]);
|
|
158
|
+
const addOne = () => {
|
|
159
|
+
if (busy) return;
|
|
160
|
+
setBusy(true);
|
|
161
|
+
setMessage(null);
|
|
162
|
+
if (variants) {
|
|
163
|
+
void add(variants[0]?.sku);
|
|
164
|
+
} else {
|
|
165
|
+
waiting.current = true;
|
|
166
|
+
setAsked(true);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return /* @__PURE__ */ jsxs("div", { ...part, "data-quick-add": product.handle, children: [
|
|
170
|
+
soldOut ? null : /* @__PURE__ */ jsx(
|
|
171
|
+
"button",
|
|
172
|
+
{
|
|
173
|
+
...button,
|
|
174
|
+
ref: trigger,
|
|
175
|
+
type: "button",
|
|
176
|
+
"aria-label": t(single ? "shopper.quickAdd.buttonFor" : "shopper.quickAdd.chooseFor", { title }),
|
|
177
|
+
"aria-expanded": single ? void 0 : open,
|
|
178
|
+
"aria-controls": single || !open ? void 0 : panelId,
|
|
179
|
+
"aria-disabled": busy || void 0,
|
|
180
|
+
"data-adding": busy ? "true" : void 0,
|
|
181
|
+
onClick: (event) => {
|
|
182
|
+
if (single) addOne();
|
|
183
|
+
else setAnchor(open ? null : anchorFor(event.currentTarget, dir));
|
|
184
|
+
},
|
|
185
|
+
children: single ? t("shopper.quickAdd.button") : t("shopper.quickAdd.choose")
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
/* @__PURE__ */ jsx("p", { ...status, role: "status", "aria-live": "polite", "data-tone": message?.tone, children: message?.text }),
|
|
189
|
+
panelNode && anchor?.host ? createPortal(panelNode, anchor.host) : panelNode
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
QuickAdd
|
|
195
|
+
};
|
|
196
|
+
//# sourceMappingURL=chunk-EYSVU5SJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shopper/QuickAdd.tsx"],"sourcesContent":["import type { ListProduct } from '@usethrottle/catalog';\nimport { useCart, useProduct } from '@usethrottle/catalog/react';\nimport { useCallback, useEffect, useId, useRef, useState } from 'react';\nimport type { CSSProperties } from 'react';\nimport { createPortal } from 'react-dom';\nimport { toGa4Item } from '../analytics/items';\nimport { useTrack } from '../analytics/use-track';\nimport { MERCH_STALE_MS } from '../merch/use-merch';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { ProductPage } from '../product';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { routeHref } from '../url/routes';\nimport { QuietRouter } from './quiet-router';\n\n/** The quick add button of a card: a one-click add for a product with one variant, an options panel for the rest. */\nexport type QuickAddProps = UsePartLocal & {\n /** The product the card shows. */\n product: ListProduct;\n};\n\n/** Where the options panel sits: in the storefront root (the card's picture clips whatever overflows it), by the button. */\ntype PanelAnchor = { host: HTMLElement | null; style: CSSProperties };\n\nconst PANEL_GAP = 8;\nconst FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nfunction anchorFor(button: HTMLElement, dir: 'ltr' | 'rtl'): PanelAnchor {\n const rect = button.getBoundingClientRect();\n const below = rect.top < window.innerHeight / 2;\n const inlineEnd = Math.max(PANEL_GAP, dir === 'rtl' ? rect.left : window.innerWidth - rect.right);\n return {\n host: button.closest<HTMLElement>('.tsf-root'),\n style: {\n position: 'fixed',\n insetInlineEnd: inlineEnd,\n ...(below ? { insetBlockStart: rect.bottom + PANEL_GAP } : { insetBlockEnd: window.innerHeight - rect.top + PANEL_GAP }),\n maxBlockSize: `calc(100vh - ${2 * PANEL_GAP}px)`,\n },\n };\n}\n\n/**\n * Adds a product to the cart from its card. A product with one variant is added at once (one\n * quantity); otherwise the button opens a small panel with the product's options and its own add\n * button. The sold-out product has no quick add.\n *\n * Keyboard: opening the panel moves focus into it. Tab through its controls; Tab past the last control or\n * Shift+Tab out of the first closes the panel and returns focus to the button, so the next Tab continues\n * from the card (the panel sits at the end of the storefront root, not after the button). Escape also closes\n * it and returns focus to the button, and so does a click outside.\n */\nexport function QuickAdd({ product, ...local }: QuickAddProps) {\n const { currency, settings, dir } = useStorefront();\n const { t } = useStrings();\n const track = useTrack();\n const cart = useCart(currency ? { currency } : undefined);\n const title = product.title ?? product.handle;\n const panelId = useId();\n const trigger = useRef<HTMLButtonElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const [anchor, setAnchor] = useState<PanelAnchor | null>(null);\n const open = anchor !== null;\n const [busy, setBusy] = useState(false);\n const [message, setMessage] = useState<{ tone: 'ok' | 'refused'; text: string } | null>(null);\n\n const soldOut = product.availability === 'out_of_stock';\n const single = (product.variantCount ?? product.variants?.length) === 1;\n\n const part = usePart('quick-add', local);\n const button = usePart('quick-add-button', local);\n const panel = usePart('quick-add-panel', local);\n const heading = usePart('quick-add-title', local);\n const status = usePart('quick-add-message', local);\n\n const close = useCallback(() => {\n setAnchor(null);\n trigger.current?.focus();\n }, []);\n\n useEffect(() => {\n if (!open) return;\n // The panel is placed once, from the button: moving the page or the window closes it.\n const away = (event: Event) => {\n if (event.target instanceof Node && panelRef.current?.contains(event.target)) return;\n setAnchor(null);\n };\n const onKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape') close();\n };\n const onPointer = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!panelRef.current?.contains(target) && !trigger.current?.contains(target)) setAnchor(null);\n };\n panelRef.current?.focus();\n document.addEventListener('keydown', onKey);\n document.addEventListener('mousedown', onPointer);\n window.addEventListener('scroll', away, true);\n window.addEventListener('resize', away);\n return () => {\n document.removeEventListener('keydown', onKey);\n document.removeEventListener('mousedown', onPointer);\n window.removeEventListener('scroll', away, true);\n window.removeEventListener('resize', away);\n };\n }, [open, close]);\n\n const panelNode =\n anchor && !single ? (\n <div\n {...panel}\n ref={panelRef}\n id={panelId}\n role=\"group\"\n tabIndex={-1}\n aria-label={t('shopper.quickAdd.panelFor', { title })}\n style={anchor.style}\n onKeyDown={(event) => {\n // The panel sits at the end of the storefront root, not after the button: leaving it either way\n // would land far from the card. Tab past its last control, or Shift+Tab out of its first, closes it\n // and returns to the button, so the next Tab continues from the card.\n if (event.key !== 'Tab') return;\n const items = [...event.currentTarget.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const at = document.activeElement;\n const leaving = event.shiftKey ? at === event.currentTarget || at === items[0] : at === items.at(-1) || items.length === 0;\n if (!leaving) return;\n event.preventDefault();\n close();\n }}\n >\n <p {...heading}>{title}</p>\n <QuietRouter pathname={routeHref(settings, 'product', product.handle)}>\n <ProductPage.Root handle={product.handle} {...local}>\n <ProductPage.VariantPicker {...local} />\n <ProductPage.AddToCart {...local} />\n </ProductPage.Root>\n </QuietRouter>\n </div>\n ) : null;\n\n // A list answer names no SKU. The product is read through the hook cache, on the first click only\n // (one request, then kept for an hour like the other reads), so a second click needs no request.\n const [asked, setAsked] = useState(false);\n const read = useProduct(asked && single && !product.variants?.length ? product.handle : null, { staleTimeMs: MERCH_STALE_MS });\n const readVariants = read.data && 'product' in read.data ? read.data.product.variants : undefined;\n const variants = product.variants?.length ? product.variants : readVariants;\n\n const add = useCallback(\n async (sku: string | undefined) => {\n try {\n if (!sku) {\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.unavailable') });\n return;\n }\n await cart.add(sku, 1);\n const cur = product.priceRange?.currency ?? currency;\n // A list product has no variants to price from, so the item is the product's with this variant's SKU.\n if (cur) track('add_to_cart', { currency: cur, items: [{ ...toGa4Item(product, { variantSku: sku, quantity: 1 }), item_id: sku }] });\n setMessage({ tone: 'ok', text: t('shopper.quickAdd.added', { title }) });\n } catch (error) {\n if (error instanceof DOMException && error.name === 'AbortError') return;\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.failed') });\n } finally {\n setBusy(false);\n }\n },\n [cart, currency, product, t, title, track],\n );\n\n // The click that had to wait for the product finishes here.\n const waiting = useRef(false);\n useEffect(() => {\n if (!waiting.current) return;\n if (variants) {\n waiting.current = false;\n void add(variants[0]?.sku);\n } else if (read.error) {\n waiting.current = false;\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.failed') });\n setBusy(false);\n }\n }, [variants, read.error, add, t]);\n\n const addOne = () => {\n if (busy) return;\n setBusy(true);\n setMessage(null);\n if (variants) {\n void add(variants[0]?.sku);\n } else {\n waiting.current = true;\n setAsked(true);\n }\n };\n\n return (\n <div {...part} data-quick-add={product.handle}>\n {soldOut ? null : (\n <button\n {...button}\n ref={trigger}\n type=\"button\"\n aria-label={t(single ? 'shopper.quickAdd.buttonFor' : 'shopper.quickAdd.chooseFor', { title })}\n aria-expanded={single ? undefined : open}\n aria-controls={single || !open ? undefined : panelId}\n aria-disabled={busy || undefined}\n data-adding={busy ? 'true' : undefined}\n onClick={(event) => {\n if (single) addOne();\n else setAnchor(open ? null : anchorFor(event.currentTarget, dir));\n }}\n >\n {single ? t('shopper.quickAdd.button') : t('shopper.quickAdd.choose')}\n </button>\n )}\n <p {...status} role=\"status\" aria-live=\"polite\" data-tone={message?.tone}>\n {message?.text}\n </p>\n {panelNode && anchor?.host ? createPortal(panelNode, anchor.host) : panelNode}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,SAAS,kBAAkB;AACpC,SAAS,aAAa,WAAW,OAAO,QAAQ,gBAAgB;AAEhE,SAAS,oBAAoB;AA8HrB,cAEE,YAFF;AA1GR,IAAM,YAAY;AAClB,IAAM,YAAY;AAElB,SAAS,UAAU,QAAqB,KAAiC;AACvE,QAAM,OAAO,OAAO,sBAAsB;AAC1C,QAAM,QAAQ,KAAK,MAAM,OAAO,cAAc;AAC9C,QAAM,YAAY,KAAK,IAAI,WAAW,QAAQ,QAAQ,KAAK,OAAO,OAAO,aAAa,KAAK,KAAK;AAChG,SAAO;AAAA,IACL,MAAM,OAAO,QAAqB,WAAW;AAAA,IAC7C,OAAO;AAAA,MACL,UAAU;AAAA,MACV,gBAAgB;AAAA,MAChB,GAAI,QAAQ,EAAE,iBAAiB,KAAK,SAAS,UAAU,IAAI,EAAE,eAAe,OAAO,cAAc,KAAK,MAAM,UAAU;AAAA,MACtH,cAAc,gBAAg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@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
usePart
|
|
4
|
+
} from "./chunk-NNE4FYRT.js";
|
|
5
|
+
|
|
6
|
+
// src/pieces/Image.tsx
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function cssAspectRatio(ratio) {
|
|
9
|
+
if (!Number.isFinite(ratio) || ratio <= 0) return "1 / 1";
|
|
10
|
+
for (let height = 1; height <= 20; height += 1) {
|
|
11
|
+
const width = Math.round(ratio * height);
|
|
12
|
+
if (width > 0 && Math.abs(width / height - ratio) < 1e-6) return `${width} / ${height}`;
|
|
13
|
+
}
|
|
14
|
+
return String(ratio);
|
|
15
|
+
}
|
|
16
|
+
function Image({ src, alt, aspectRatio, sizes, srcSet, priority, classNames, className, unstyled }) {
|
|
17
|
+
const part = usePart("image", { classNames, className, unstyled });
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"img",
|
|
20
|
+
{
|
|
21
|
+
...part,
|
|
22
|
+
src,
|
|
23
|
+
alt,
|
|
24
|
+
srcSet,
|
|
25
|
+
sizes: srcSet ? sizes : void 0,
|
|
26
|
+
style: { aspectRatio: cssAspectRatio(aspectRatio) },
|
|
27
|
+
loading: priority ? "eager" : "lazy",
|
|
28
|
+
fetchPriority: priority ? "high" : void 0,
|
|
29
|
+
decoding: "async"
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
Image
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=chunk-HSUUDZWS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pieces/Image.tsx"],"sourcesContent":["import { usePart, type UsePartLocal } from '../parts';\n\n/** A picture that reserves its space: `aspectRatio` is required and becomes an inline `aspect-ratio`. */\nexport type ImageProps = UsePartLocal & {\n /** The image URL. */\n src: string;\n /** The alternative text. Pass an empty string for a purely decorative picture. */\n alt: string;\n /** Width over height. Space is reserved from it, so the layout does not move when the image loads. */\n aspectRatio: number;\n /** The `sizes` attribute, for a responsive `srcSet`. */\n sizes?: string;\n /** The `srcset` attribute: the same picture at several widths. */\n srcSet?: string;\n /** The largest paint of the page: loaded eagerly, fetched first. */\n priority?: boolean;\n};\n\n/** `0.8` as `\"4 / 5\"`: the ratio of the smallest whole numbers that match, else the number itself. */\nexport function cssAspectRatio(ratio: number): string {\n if (!Number.isFinite(ratio) || ratio <= 0) return '1 / 1';\n for (let height = 1; height <= 20; height += 1) {\n const width = Math.round(ratio * height);\n if (width > 0 && Math.abs(width / height - ratio) < 1e-6) return `${width} / ${height}`;\n }\n return String(ratio);\n}\n\n/** An image that always reserves its space (an inline `aspect-ratio`). */\nexport function Image({ src, alt, aspectRatio, sizes, srcSet, priority, classNames, className, unstyled }: ImageProps) {\n const part = usePart('image', { classNames, className, unstyled });\n return (\n <img\n {...part}\n src={src}\n alt={alt}\n srcSet={srcSet}\n sizes={srcSet ? sizes : undefined}\n style={{ aspectRatio: cssAspectRatio(aspectRatio) }}\n loading={priority ? 'eager' : 'lazy'}\n fetchPriority={priority ? 'high' : undefined}\n decoding=\"async\"\n />\n );\n}\n"],"mappings":";;;;;;AAgCI;AAbG,SAAS,eAAe,OAAuB;AACpD,MAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,EAAG,QAAO;AAClD,WAAS,SAAS,GAAG,UAAU,IAAI,UAAU,GAAG;AAC9C,UAAM,QAAQ,KAAK,MAAM,QAAQ,MAAM;AACvC,QAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,SAAS,KAAK,IAAI,KAAM,QAAO,GAAG,KAAK,MAAM,MAAM;AAAA,EACvF;AACA,SAAO,OAAO,KAAK;AACrB;AAGO,SAAS,MAAM,EAAE,KAAK,KAAK,aAAa,OAAO,QAAQ,UAAU,YAAY,WAAW,SAAS,GAAe;AACrH,QAAM,OAAO,QAAQ,SAAS,EAAE,YAAY,WAAW,SAAS,CAAC;AACjE,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,SAAS,QAAQ;AAAA,MACxB,OAAO,EAAE,aAAa,eAAe,WAAW,EAAE;AAAA,MAClD,SAAS,WAAW,UAAU;AAAA,MAC9B,eAAe,WAAW,SAAS;AAAA,MACnC,UAAS;AAAA;AAAA,EACX;AAEJ;","names":[]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkXQHGFWLGcjs = require('./chunk-XQHGFWLG.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
|
|
10
|
+
|
|
11
|
+
// src/url/routes.ts
|
|
12
|
+
var fill = (pattern, name, value) => pattern.split(`{${name}}`).join(encodeURIComponent(value));
|
|
13
|
+
function routeHref(settings, kind, value, site) {
|
|
14
|
+
if (kind === "search") return fill(settings.routes.search, "q", value);
|
|
15
|
+
const pattern = kind === "page" && _optionalChain([site, 'optionalAccess', _ => _.routes, 'access', _2 => _2.page]) ? site.routes.page : settings.routes[kind];
|
|
16
|
+
return fill(pattern, kind === "tag" ? "tag" : "handle", value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/analytics/items.ts
|
|
20
|
+
var _money = require('@usethrottle/money');
|
|
21
|
+
var decimal = (minor, currency) => Number(_money.toDecimalString.call(void 0, minor, currency));
|
|
22
|
+
function toGa4Item(product, o = {}) {
|
|
23
|
+
const variant = o.variantSku ? _optionalChain([product, 'access', _3 => _3.variants, 'optionalAccess', _4 => _4.find, 'call', _5 => _5((v) => v.sku === o.variantSku)]) : void 0;
|
|
24
|
+
const currency = _nullishCoalesce(_optionalChain([variant, 'optionalAccess', _6 => _6.currency]), () => ( _optionalChain([product, 'access', _7 => _7.priceRange, 'optionalAccess', _8 => _8.currency])));
|
|
25
|
+
const minor = variant ? _nullishCoalesce(variant.salePriceMinor, () => ( variant.priceMinor)) : _optionalChain([product, 'access', _9 => _9.priceRange, 'optionalAccess', _10 => _10.minMinor]);
|
|
26
|
+
return {
|
|
27
|
+
item_id: _nullishCoalesce(_optionalChain([variant, 'optionalAccess', _11 => _11.sku]), () => ( product.handle)),
|
|
28
|
+
item_name: _nullishCoalesce(product.title, () => ( product.handle)),
|
|
29
|
+
...product.brand ? { item_brand: product.brand } : {},
|
|
30
|
+
..._optionalChain([variant, 'optionalAccess', _12 => _12.title]) ? { item_variant: variant.title } : {},
|
|
31
|
+
...o.listName ? { item_list_name: o.listName } : {},
|
|
32
|
+
...o.index !== void 0 ? { index: o.index } : {},
|
|
33
|
+
...minor !== null && minor !== void 0 && currency ? { price: decimal(minor, currency) } : {},
|
|
34
|
+
...o.quantity !== void 0 ? { quantity: o.quantity } : {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/pieces/Money.tsx
|
|
39
|
+
|
|
40
|
+
var _ui = require('@usethrottle/ui');
|
|
41
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
42
|
+
function Money({ minor, currency, compareAtMinor, classNames, className, unstyled }) {
|
|
43
|
+
const local = { classNames, unstyled };
|
|
44
|
+
const part = _chunkVWXJO427cjs.usePart.call(void 0, "money", { ...local, className });
|
|
45
|
+
const compare = _chunkVWXJO427cjs.usePart.call(void 0, "money-compare", local);
|
|
46
|
+
const { t } = _chunkXQHGFWLGcjs.useStrings.call(void 0, );
|
|
47
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
48
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...part, "data-minor": minor, "data-currency": currency, children: _money.formatMoney.call(void 0, minor, currency) }),
|
|
49
|
+
compareAtMinor !== void 0 && compareAtMinor > minor ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "s", { ...compare, "data-minor": compareAtMinor, "data-currency": currency, children: [
|
|
50
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ui.VisuallyHidden, { children: t("pieces.price.compareAt") }),
|
|
51
|
+
_money.formatMoney.call(void 0, compareAtMinor, currency)
|
|
52
|
+
] }) : null
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/pieces/Price.tsx
|
|
57
|
+
|
|
58
|
+
function Price({ minor, currency, compareAtMinor, priceContext, classNames, className, unstyled }) {
|
|
59
|
+
const local = { classNames, unstyled };
|
|
60
|
+
const part = _chunkVWXJO427cjs.usePart.call(void 0, "price", { ...local, className });
|
|
61
|
+
const label = _chunkVWXJO427cjs.usePart.call(void 0, "price-label", local);
|
|
62
|
+
const hint = _chunkVWXJO427cjs.usePart.call(void 0, "price-hint", local);
|
|
63
|
+
const { settings } = _chunkVWXJO427cjs.useStorefront.call(void 0, );
|
|
64
|
+
const { t } = _chunkXQHGFWLGcjs.useStrings.call(void 0, );
|
|
65
|
+
const showCompare = priceContext === "customer" ? settings.card.showCompareAt : true;
|
|
66
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { ...part, "data-price-context": priceContext, "data-minor": minor, "data-currency": currency, children: [
|
|
67
|
+
priceContext === "customer" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...label, children: t("pieces.price.customer") }) : null,
|
|
68
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Money, { ...local, minor, currency, compareAtMinor: showCompare ? compareAtMinor : void 0 }),
|
|
69
|
+
priceContext === "email_unverified" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...hint, children: t("pieces.price.verifyEmail") }) : null
|
|
70
|
+
] });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/pieces/StarRating.tsx
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
var STARS = [1, 2, 3, 4, 5];
|
|
77
|
+
function StarRating({ value, count, size = "md", classNames, className, unstyled }) {
|
|
78
|
+
const local = { classNames, unstyled };
|
|
79
|
+
const root = _chunkVWXJO427cjs.usePart.call(void 0, "star-rating", { ...local, className });
|
|
80
|
+
const stars = _chunkVWXJO427cjs.usePart.call(void 0, "star-rating-stars", local);
|
|
81
|
+
const countPart = _chunkVWXJO427cjs.usePart.call(void 0, "star-rating-count", local);
|
|
82
|
+
const { t } = _chunkXQHGFWLGcjs.useStrings.call(void 0, );
|
|
83
|
+
const average = Math.min(5, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
84
|
+
const halves = Math.round(average * 2);
|
|
85
|
+
const shown = Math.round(average * 10) / 10;
|
|
86
|
+
const label = count === void 0 ? t("pieces.rating.label", { value: shown }) : t(count === 1 ? "pieces.rating.labelWithOne" : "pieces.rating.labelWithCount", { value: shown, count });
|
|
87
|
+
const px = size === "sm" ? 14 : 18;
|
|
88
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { ...root, "data-size": size, children: [
|
|
89
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...stars, role: "img", "aria-label": label, children: STARS.map((n) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ui.Icon, { name: halves >= n * 2 ? "star" : halves === n * 2 - 1 ? "star-half" : "star-empty", size: px }, n)) }),
|
|
90
|
+
count !== void 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...countPart, "aria-hidden": "true", children: t("pieces.rating.count", { count }) }) : null
|
|
91
|
+
] });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
exports.routeHref = routeHref; exports.toGa4Item = toGa4Item; exports.Money = Money; exports.Price = Price; exports.StarRating = StarRating;
|
|
101
|
+
//# sourceMappingURL=chunk-HZ6VEN6Q.cjs.map
|