@artisanpack-ui/ecommerce-storefront-react 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +67 -2
- package/dist/Addresses-D3ESHG3L.mjs +27 -0
- package/dist/Addresses-D3ESHG3L.mjs.map +1 -0
- package/dist/CategoryShow-OAGROEMA.mjs +12 -0
- package/dist/CategoryShow-OAGROEMA.mjs.map +1 -0
- package/dist/Claim-CJ4UOAUD.mjs +22 -0
- package/dist/Claim-CJ4UOAUD.mjs.map +1 -0
- package/dist/Confirmation-TLMMBPWS.mjs +20 -0
- package/dist/Confirmation-TLMMBPWS.mjs.map +1 -0
- package/dist/Dashboard-ARXORMTL.mjs +24 -0
- package/dist/Dashboard-ARXORMTL.mjs.map +1 -0
- package/dist/Downloads-CEQBY7JO.mjs +25 -0
- package/dist/Downloads-CEQBY7JO.mjs.map +1 -0
- package/dist/Index-KRR3Q7EJ.mjs +12 -0
- package/dist/Index-KRR3Q7EJ.mjs.map +1 -0
- package/dist/Index-RLQFEBTX.mjs +22 -0
- package/dist/Index-RLQFEBTX.mjs.map +1 -0
- package/dist/Index-WDJYGR5Q.mjs +12 -0
- package/dist/Index-WDJYGR5Q.mjs.map +1 -0
- package/dist/Index-XYU5QLUT.mjs +23 -0
- package/dist/Index-XYU5QLUT.mjs.map +1 -0
- package/dist/Lookup-QNUQKUID.mjs +19 -0
- package/dist/Lookup-QNUQKUID.mjs.map +1 -0
- package/dist/OrderShow-RYTP62YA.mjs +27 -0
- package/dist/OrderShow-RYTP62YA.mjs.map +1 -0
- package/dist/Orders-LZW57GE6.mjs +25 -0
- package/dist/Orders-LZW57GE6.mjs.map +1 -0
- package/dist/Profile-ZAAWFCAL.mjs +25 -0
- package/dist/Profile-ZAAWFCAL.mjs.map +1 -0
- package/dist/Show-LFWUO3KR.mjs +14 -0
- package/dist/Show-LFWUO3KR.mjs.map +1 -0
- package/dist/TagShow-FXKXRGY2.mjs +12 -0
- package/dist/TagShow-FXKXRGY2.mjs.map +1 -0
- package/dist/chunk-5UUNH3EH.mjs +1888 -0
- package/dist/chunk-5UUNH3EH.mjs.map +1 -0
- package/dist/chunk-A3MMQ2RY.mjs +183 -0
- package/dist/chunk-A3MMQ2RY.mjs.map +1 -0
- package/dist/chunk-ABGPTZ3Q.mjs +198 -0
- package/dist/chunk-ABGPTZ3Q.mjs.map +1 -0
- package/dist/chunk-BJ3FJFZQ.mjs +32 -0
- package/dist/chunk-BJ3FJFZQ.mjs.map +1 -0
- package/dist/chunk-BSASRFQ7.mjs +89 -0
- package/dist/chunk-BSASRFQ7.mjs.map +1 -0
- package/dist/chunk-CGCW3555.mjs +148 -0
- package/dist/chunk-CGCW3555.mjs.map +1 -0
- package/dist/chunk-DWR23FJD.mjs +643 -0
- package/dist/chunk-DWR23FJD.mjs.map +1 -0
- package/dist/chunk-ENY3MH2W.mjs +148 -0
- package/dist/chunk-ENY3MH2W.mjs.map +1 -0
- package/dist/chunk-EWJLRWPO.mjs +280 -0
- package/dist/chunk-EWJLRWPO.mjs.map +1 -0
- package/dist/chunk-FL5XL3ET.mjs +212 -0
- package/dist/chunk-FL5XL3ET.mjs.map +1 -0
- package/dist/chunk-FOOP6UK3.mjs +218 -0
- package/dist/chunk-FOOP6UK3.mjs.map +1 -0
- package/dist/chunk-HCC7GTVO.mjs +115 -0
- package/dist/chunk-HCC7GTVO.mjs.map +1 -0
- package/dist/chunk-HXZMY3GE.mjs +2331 -0
- package/dist/chunk-HXZMY3GE.mjs.map +1 -0
- package/dist/chunk-IOL2YQ62.mjs +109 -0
- package/dist/chunk-IOL2YQ62.mjs.map +1 -0
- package/dist/chunk-JH7SFSZA.mjs +104 -0
- package/dist/chunk-JH7SFSZA.mjs.map +1 -0
- package/dist/chunk-JJOPX4PI.mjs +205 -0
- package/dist/chunk-JJOPX4PI.mjs.map +1 -0
- package/dist/chunk-LT3GG7YQ.mjs +32 -0
- package/dist/chunk-LT3GG7YQ.mjs.map +1 -0
- package/dist/chunk-MZFULGDI.mjs +267 -0
- package/dist/chunk-MZFULGDI.mjs.map +1 -0
- package/dist/chunk-O4WPMMSH.mjs +58 -0
- package/dist/chunk-O4WPMMSH.mjs.map +1 -0
- package/dist/chunk-OU3WYFIH.mjs +397 -0
- package/dist/chunk-OU3WYFIH.mjs.map +1 -0
- package/dist/chunk-P3NIV4YG.mjs +998 -0
- package/dist/chunk-P3NIV4YG.mjs.map +1 -0
- package/dist/chunk-PEBBSZ5R.mjs +201 -0
- package/dist/chunk-PEBBSZ5R.mjs.map +1 -0
- package/dist/chunk-T5OWL6EG.mjs +73 -0
- package/dist/chunk-T5OWL6EG.mjs.map +1 -0
- package/dist/chunk-THPUK35U.mjs +132 -0
- package/dist/chunk-THPUK35U.mjs.map +1 -0
- package/dist/chunk-TPOKMH5E.mjs +142 -0
- package/dist/chunk-TPOKMH5E.mjs.map +1 -0
- package/dist/chunk-VX5TEJNU.mjs +1898 -0
- package/dist/chunk-VX5TEJNU.mjs.map +1 -0
- package/dist/chunk-WUL34MB2.mjs +268 -0
- package/dist/chunk-WUL34MB2.mjs.map +1 -0
- package/dist/chunk-WYGOMIZK.mjs +140 -0
- package/dist/chunk-WYGOMIZK.mjs.map +1 -0
- package/dist/chunk-Y2IOBBN7.mjs +127 -0
- package/dist/chunk-Y2IOBBN7.mjs.map +1 -0
- package/dist/chunk-Y5BRPEHA.mjs +54 -0
- package/dist/chunk-Y5BRPEHA.mjs.map +1 -0
- package/dist/index.d.ts +4607 -0
- package/dist/index.mjs +1515 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +112 -4
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RelatedProducts
|
|
3
|
+
} from "./chunk-PEBBSZ5R.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useStorefrontRouter
|
|
6
|
+
} from "./chunk-TPOKMH5E.mjs";
|
|
7
|
+
import {
|
|
8
|
+
OrderTotals
|
|
9
|
+
} from "./chunk-T5OWL6EG.mjs";
|
|
10
|
+
import {
|
|
11
|
+
Field
|
|
12
|
+
} from "./chunk-WYGOMIZK.mjs";
|
|
13
|
+
import {
|
|
14
|
+
EmptyState,
|
|
15
|
+
LineControls,
|
|
16
|
+
Money,
|
|
17
|
+
addBuiltInRegistration,
|
|
18
|
+
cartActionUrl,
|
|
19
|
+
getRegistries,
|
|
20
|
+
postJson,
|
|
21
|
+
showResponseToasts,
|
|
22
|
+
useFocusAfterChange,
|
|
23
|
+
usePageErrors,
|
|
24
|
+
useStorefront
|
|
25
|
+
} from "./chunk-VX5TEJNU.mjs";
|
|
26
|
+
|
|
27
|
+
// src/cart/builtIns.ts
|
|
28
|
+
var registered = false;
|
|
29
|
+
function registerCartBuiltIns() {
|
|
30
|
+
if (registered) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
registered = true;
|
|
34
|
+
addBuiltInRegistration((registries) => {
|
|
35
|
+
registries.cartSections.register("related-products", RelatedProducts, { position: 10 });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/cart/ShippingEstimate.tsx
|
|
40
|
+
import {
|
|
41
|
+
__
|
|
42
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
43
|
+
import { Button, Icon, RadioGroup } from "@artisanpack-ui/react";
|
|
44
|
+
import { useState } from "react";
|
|
45
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
46
|
+
function quoteErrors(body) {
|
|
47
|
+
const errors = null !== body && "object" === typeof body ? body.errors : null;
|
|
48
|
+
const found = {};
|
|
49
|
+
if (null === errors || "object" !== typeof errors) {
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
for (const key of ["country", "region", "postcode", "rate"]) {
|
|
53
|
+
const messages = errors[key];
|
|
54
|
+
const first = Array.isArray(messages) ? messages[0] : messages;
|
|
55
|
+
if ("string" === typeof first) {
|
|
56
|
+
found[key] = first;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
61
|
+
async function fetchFormat(url, country) {
|
|
62
|
+
try {
|
|
63
|
+
const target = new URL(url, window.location.href);
|
|
64
|
+
target.searchParams.set("country", country);
|
|
65
|
+
const response = await fetch(target.toString(), {
|
|
66
|
+
headers: { Accept: "application/json", "X-Requested-With": "XMLHttpRequest" },
|
|
67
|
+
credentials: "same-origin"
|
|
68
|
+
});
|
|
69
|
+
return response.ok ? await response.json() : null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function ShippingEstimate({
|
|
75
|
+
estimate,
|
|
76
|
+
countries,
|
|
77
|
+
cartUrl,
|
|
78
|
+
formatUrl,
|
|
79
|
+
errors,
|
|
80
|
+
onAnnounce
|
|
81
|
+
}) {
|
|
82
|
+
const [country, setCountry] = useState(estimate.country);
|
|
83
|
+
const [region, setRegion] = useState(estimate.region);
|
|
84
|
+
const [postcode, setPostcode] = useState(estimate.postcode);
|
|
85
|
+
const [format, setFormat] = useState(estimate.format);
|
|
86
|
+
const [rates, setRates] = useState(null);
|
|
87
|
+
const [selectedRate, setSelectedRate] = useState(estimate.selectedRate);
|
|
88
|
+
const [fieldErrors, setFieldErrors] = useState({});
|
|
89
|
+
const [quoting, setQuoting] = useState(false);
|
|
90
|
+
const visits = useStorefrontRouter();
|
|
91
|
+
const rateError = fieldErrors.rate ?? errors.rate ?? null;
|
|
92
|
+
const changeCountry = (next) => {
|
|
93
|
+
setCountry(next);
|
|
94
|
+
setRegion("");
|
|
95
|
+
if (null === formatUrl || "" === next) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
void fetchFormat(formatUrl, next).then((loaded) => {
|
|
99
|
+
if (null !== loaded) {
|
|
100
|
+
setFormat(loaded);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const quote = async (event) => {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
setQuoting(true);
|
|
107
|
+
const { status, body } = await postJson(
|
|
108
|
+
cartActionUrl(cartUrl, "shipping-rates"),
|
|
109
|
+
{ country, region, postcode }
|
|
110
|
+
);
|
|
111
|
+
setQuoting(false);
|
|
112
|
+
if (429 === status) {
|
|
113
|
+
showResponseToasts(body);
|
|
114
|
+
onAnnounce(body?.announcement ?? "");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (422 === status) {
|
|
118
|
+
setFieldErrors(quoteErrors(body));
|
|
119
|
+
setRates(null);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
setFieldErrors({});
|
|
123
|
+
if (null === body) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
setRates(body.rates);
|
|
127
|
+
onAnnounce(body.announcement);
|
|
128
|
+
};
|
|
129
|
+
const chooseRate = (rate) => {
|
|
130
|
+
setSelectedRate(rate);
|
|
131
|
+
visits.post(
|
|
132
|
+
cartActionUrl(cartUrl, "shipping"),
|
|
133
|
+
{ country, region, postcode, rate },
|
|
134
|
+
{ preserveScroll: true, preserveState: true }
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
return /* @__PURE__ */ jsxs(
|
|
138
|
+
"details",
|
|
139
|
+
{
|
|
140
|
+
className: "ec-disclosure",
|
|
141
|
+
...null !== rates ? { open: true } : {},
|
|
142
|
+
"data-cart-estimate-disclosure": "",
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ jsxs("summary", { className: "ec-disclosure__summary", children: [
|
|
145
|
+
/* @__PURE__ */ jsx(Icon, { name: "truck", "aria-hidden": "true" }),
|
|
146
|
+
/* @__PURE__ */ jsx("span", { id: "ec-cart-estimate-heading", children: __("Estimate shipping") }),
|
|
147
|
+
/* @__PURE__ */ jsx(Icon, { name: "chevron-down", className: "ec-disclosure__chevron", "aria-hidden": "true" })
|
|
148
|
+
] }),
|
|
149
|
+
/* @__PURE__ */ jsxs(
|
|
150
|
+
"form",
|
|
151
|
+
{
|
|
152
|
+
onSubmit: (event) => void quote(event),
|
|
153
|
+
className: "ec-disclosure__body ec-cart-estimate",
|
|
154
|
+
"aria-labelledby": "ec-cart-estimate-heading",
|
|
155
|
+
noValidate: true,
|
|
156
|
+
"data-cart-estimate": "",
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsxs("div", { className: "ec-cart-estimate__fields", children: [
|
|
159
|
+
/* @__PURE__ */ jsx(
|
|
160
|
+
Field,
|
|
161
|
+
{
|
|
162
|
+
control: "select",
|
|
163
|
+
id: "ec-cart-estimate-country",
|
|
164
|
+
name: "country",
|
|
165
|
+
label: __("Country"),
|
|
166
|
+
options: countries,
|
|
167
|
+
placeholder: __("Select a country"),
|
|
168
|
+
autoComplete: "shipping country",
|
|
169
|
+
value: country,
|
|
170
|
+
error: fieldErrors.country ?? null,
|
|
171
|
+
onValueChange: changeCountry
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
format.regions.length > 0 ? /* @__PURE__ */ jsx(
|
|
175
|
+
Field,
|
|
176
|
+
{
|
|
177
|
+
control: "select",
|
|
178
|
+
id: "ec-cart-estimate-region",
|
|
179
|
+
name: "region",
|
|
180
|
+
label: __("Region"),
|
|
181
|
+
options: format.regions,
|
|
182
|
+
placeholder: __("Select one"),
|
|
183
|
+
autoComplete: "shipping address-level1",
|
|
184
|
+
value: region,
|
|
185
|
+
error: fieldErrors.region ?? null,
|
|
186
|
+
onValueChange: setRegion
|
|
187
|
+
}
|
|
188
|
+
) : null,
|
|
189
|
+
/* @__PURE__ */ jsx(
|
|
190
|
+
Field,
|
|
191
|
+
{
|
|
192
|
+
id: "ec-cart-estimate-postcode",
|
|
193
|
+
name: "postcode",
|
|
194
|
+
label: format.postcodeLabel,
|
|
195
|
+
autoComplete: "shipping postal-code",
|
|
196
|
+
maxLength: 32,
|
|
197
|
+
value: postcode,
|
|
198
|
+
error: fieldErrors.postcode ?? null,
|
|
199
|
+
onValueChange: setPostcode
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
] }),
|
|
203
|
+
/* @__PURE__ */ jsx(
|
|
204
|
+
Button,
|
|
205
|
+
{
|
|
206
|
+
variant: "outline",
|
|
207
|
+
color: "neutral",
|
|
208
|
+
type: "submit",
|
|
209
|
+
disabled: quoting,
|
|
210
|
+
"data-cart-estimate-submit": "",
|
|
211
|
+
children: __("Get shipping rates")
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
null !== rates && rates.length > 0 ? /* @__PURE__ */ jsx(
|
|
215
|
+
RadioGroup,
|
|
216
|
+
{
|
|
217
|
+
id: "ec-cart-estimate-rate",
|
|
218
|
+
label: __("Shipping option"),
|
|
219
|
+
variant: "cards",
|
|
220
|
+
options: rates.map((rate) => ({
|
|
221
|
+
value: rate.id,
|
|
222
|
+
label: rate.label,
|
|
223
|
+
meta: rate.amount.formatted ?? ""
|
|
224
|
+
})),
|
|
225
|
+
value: selectedRate,
|
|
226
|
+
error: rateError ?? void 0,
|
|
227
|
+
onValueChange: (value) => chooseRate(String(value)),
|
|
228
|
+
"data-cart-estimate-rates": ""
|
|
229
|
+
}
|
|
230
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
231
|
+
null !== rates && 0 === rates.length ? /* @__PURE__ */ jsx("p", { className: "ec-cart-estimate__none", "data-cart-estimate-none": "", children: __("No shipping options for this address.") }) : null,
|
|
232
|
+
null !== rateError ? /* @__PURE__ */ jsx("p", { className: "ec-cart-estimate__error", role: "alert", "data-cart-estimate-error": "", children: rateError }) : null
|
|
233
|
+
] })
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/cart/Cart.tsx
|
|
243
|
+
import {
|
|
244
|
+
__ as __2,
|
|
245
|
+
trans_choice
|
|
246
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
247
|
+
import { Badge, Button as Button2, Icon as Icon2, Link } from "@artisanpack-ui/react";
|
|
248
|
+
import { useEffect, useRef, useState as useState2 } from "react";
|
|
249
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
250
|
+
registerCartBuiltIns();
|
|
251
|
+
var WRITE_OPTIONS = { preserveScroll: true, preserveState: true };
|
|
252
|
+
function CartLineRow({ line, cartUrl, error, removing, onRemove }) {
|
|
253
|
+
const removeLabel = __2("Remove :name", { name: line.name });
|
|
254
|
+
const visits = useStorefrontRouter();
|
|
255
|
+
return /* @__PURE__ */ jsxs2("li", { className: "ec-cart-line ec-cart__line", "data-cart-line": line.id, children: [
|
|
256
|
+
/* @__PURE__ */ jsx2("span", { className: "ec-cart-line__thumb", "aria-hidden": "true", children: null !== line.image ? /* @__PURE__ */ jsx2(
|
|
257
|
+
"img",
|
|
258
|
+
{
|
|
259
|
+
src: line.image.url,
|
|
260
|
+
...null !== line.image.srcset ? { srcSet: line.image.srcset, sizes: "96px" } : {},
|
|
261
|
+
width: 96,
|
|
262
|
+
height: 96,
|
|
263
|
+
alt: "",
|
|
264
|
+
loading: "lazy",
|
|
265
|
+
decoding: "async"
|
|
266
|
+
}
|
|
267
|
+
) : /* @__PURE__ */ jsx2(Icon2, { name: "image" }) }),
|
|
268
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-cart-line__body", children: [
|
|
269
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-cart-line__head", children: [
|
|
270
|
+
/* @__PURE__ */ jsx2("h3", { className: "ec-cart-line__name", children: null !== line.url ? /* @__PURE__ */ jsx2("a", { href: line.url, children: line.name }) : line.name }),
|
|
271
|
+
/* @__PURE__ */ jsxs2("p", { className: "ec-cart-line__total", "data-cart-line-total": "", children: [
|
|
272
|
+
/* @__PURE__ */ jsx2("span", { className: "apui-sr-only", children: __2("Line total:") }),
|
|
273
|
+
line.free ? __2("Free") : /* @__PURE__ */ jsx2(Money, { money: line.total })
|
|
274
|
+
] })
|
|
275
|
+
] }),
|
|
276
|
+
line.options.length > 0 ? /* @__PURE__ */ jsxs2("p", { className: "ec-cart-line__options", children: [
|
|
277
|
+
/* @__PURE__ */ jsx2("span", { className: "apui-sr-only", children: __2("Options:") }),
|
|
278
|
+
line.options.join(" \xB7 ")
|
|
279
|
+
] }) : null,
|
|
280
|
+
/* @__PURE__ */ jsxs2("p", { className: "ec-cart-line__options", children: [
|
|
281
|
+
/* @__PURE__ */ jsx2("span", { className: "apui-sr-only", children: __2("Price each:") }),
|
|
282
|
+
/* @__PURE__ */ jsx2(Money, { money: line.unit }),
|
|
283
|
+
" ",
|
|
284
|
+
/* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: __2("each") })
|
|
285
|
+
] }),
|
|
286
|
+
line.free ? /* @__PURE__ */ jsx2(Badge, { variant: "soft", color: "success", size: "sm", leadingIcon: "gift", "data-cart-line-free": "", children: __2("Free gift") }) : null,
|
|
287
|
+
null !== line.unsellable ? /* @__PURE__ */ jsx2(
|
|
288
|
+
"p",
|
|
289
|
+
{
|
|
290
|
+
className: "ec-cart-line__problem",
|
|
291
|
+
"data-cart-line-unsellable": "",
|
|
292
|
+
...line.short ? { "data-cart-line-short": "" } : {},
|
|
293
|
+
children: line.unsellable
|
|
294
|
+
}
|
|
295
|
+
) : null,
|
|
296
|
+
null !== line.unsellable && !line.short ? /* @__PURE__ */ jsx2("div", { className: "ec-cart-line__controls", children: /* @__PURE__ */ jsx2(
|
|
297
|
+
Button2,
|
|
298
|
+
{
|
|
299
|
+
variant: "outline",
|
|
300
|
+
color: "neutral",
|
|
301
|
+
size: "sm",
|
|
302
|
+
"aria-label": removeLabel,
|
|
303
|
+
disabled: removing,
|
|
304
|
+
onClick: () => onRemove(line),
|
|
305
|
+
"data-cart-line-remove": "",
|
|
306
|
+
children: __2("Remove")
|
|
307
|
+
}
|
|
308
|
+
) }) : !line.free ? /* @__PURE__ */ jsx2(
|
|
309
|
+
LineControls,
|
|
310
|
+
{
|
|
311
|
+
id: `ec-cart-quantity-${line.id}`,
|
|
312
|
+
itemName: line.name,
|
|
313
|
+
size: "sm",
|
|
314
|
+
quantity: line.quantity,
|
|
315
|
+
max: line.maxQuantity,
|
|
316
|
+
error,
|
|
317
|
+
onCommit: (quantity) => {
|
|
318
|
+
if (null !== cartUrl) {
|
|
319
|
+
visits.patch(
|
|
320
|
+
cartActionUrl(cartUrl, `lines/${line.id}`),
|
|
321
|
+
{ quantity },
|
|
322
|
+
WRITE_OPTIONS
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
children: /* @__PURE__ */ jsx2(
|
|
327
|
+
Button2,
|
|
328
|
+
{
|
|
329
|
+
variant: "ghost",
|
|
330
|
+
color: "neutral",
|
|
331
|
+
size: "sm",
|
|
332
|
+
iconOnly: true,
|
|
333
|
+
leadingIcon: "trash",
|
|
334
|
+
"aria-label": removeLabel,
|
|
335
|
+
disabled: removing,
|
|
336
|
+
onClick: () => onRemove(line),
|
|
337
|
+
"data-cart-line-remove": ""
|
|
338
|
+
}
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
) : null
|
|
342
|
+
] })
|
|
343
|
+
] });
|
|
344
|
+
}
|
|
345
|
+
function CouponForm({
|
|
346
|
+
coupon,
|
|
347
|
+
cartUrl,
|
|
348
|
+
error
|
|
349
|
+
}) {
|
|
350
|
+
const [code, setCode] = useState2("");
|
|
351
|
+
const [applying, setApplying] = useState2(false);
|
|
352
|
+
const [removals, setRemovals] = useState2(0);
|
|
353
|
+
const visits = useStorefrontRouter();
|
|
354
|
+
useEffect(() => {
|
|
355
|
+
if (0 === removals || null !== coupon) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const timer = setTimeout(() => {
|
|
359
|
+
if (null === document.activeElement || document.activeElement === document.body) {
|
|
360
|
+
document.getElementById("ec-cart-coupon")?.focus();
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return () => clearTimeout(timer);
|
|
364
|
+
}, [removals, coupon]);
|
|
365
|
+
const apply = (event) => {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
if (null === cartUrl) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
setApplying(true);
|
|
371
|
+
visits.post(
|
|
372
|
+
cartActionUrl(cartUrl, "coupon"),
|
|
373
|
+
{ code },
|
|
374
|
+
{
|
|
375
|
+
...WRITE_OPTIONS,
|
|
376
|
+
onSuccess: () => setCode(""),
|
|
377
|
+
onFinish: () => setApplying(false)
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
};
|
|
381
|
+
const remove = (applied) => {
|
|
382
|
+
if (null === cartUrl) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
visits.delete(cartActionUrl(cartUrl, "coupon"), {
|
|
386
|
+
...WRITE_OPTIONS,
|
|
387
|
+
data: { code: applied },
|
|
388
|
+
onSuccess: () => setRemovals((count) => count + 1)
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
return /* @__PURE__ */ jsxs2("div", { className: "ec-cart-summary__coupon", "data-cart-coupon": "", children: [
|
|
392
|
+
/* @__PURE__ */ jsxs2("form", { onSubmit: apply, className: "ec-input-group", noValidate: true, children: [
|
|
393
|
+
/* @__PURE__ */ jsx2(
|
|
394
|
+
Field,
|
|
395
|
+
{
|
|
396
|
+
id: "ec-cart-coupon",
|
|
397
|
+
name: "code",
|
|
398
|
+
label: __2("Coupon code"),
|
|
399
|
+
autoComplete: "off",
|
|
400
|
+
maxLength: 64,
|
|
401
|
+
value: code,
|
|
402
|
+
error,
|
|
403
|
+
errorKey: "code",
|
|
404
|
+
onValueChange: setCode,
|
|
405
|
+
attributes: { autoCapitalize: "characters" }
|
|
406
|
+
}
|
|
407
|
+
),
|
|
408
|
+
/* @__PURE__ */ jsx2(
|
|
409
|
+
Button2,
|
|
410
|
+
{
|
|
411
|
+
variant: "outline",
|
|
412
|
+
color: "neutral",
|
|
413
|
+
type: "submit",
|
|
414
|
+
disabled: applying,
|
|
415
|
+
"data-cart-coupon-apply": "",
|
|
416
|
+
children: __2("Apply")
|
|
417
|
+
}
|
|
418
|
+
)
|
|
419
|
+
] }),
|
|
420
|
+
null !== coupon ? /* @__PURE__ */ jsxs2("p", { className: "ec-chip", "data-variant": "coupon", children: [
|
|
421
|
+
/* @__PURE__ */ jsx2(Icon2, { name: "tag", className: "ec-chip__icon", "aria-hidden": "true" }),
|
|
422
|
+
/* @__PURE__ */ jsx2("span", { className: "apui-sr-only", children: __2("Coupon applied:") }),
|
|
423
|
+
/* @__PURE__ */ jsx2("span", { "data-cart-coupon-code": "", children: coupon }),
|
|
424
|
+
/* @__PURE__ */ jsx2(
|
|
425
|
+
"button",
|
|
426
|
+
{
|
|
427
|
+
type: "button",
|
|
428
|
+
className: "ec-chip__remove",
|
|
429
|
+
"aria-label": __2("Remove coupon :code", { code: coupon }),
|
|
430
|
+
onClick: () => remove(coupon),
|
|
431
|
+
"data-cart-coupon-remove": "",
|
|
432
|
+
children: /* @__PURE__ */ jsx2(Icon2, { name: "x", "aria-hidden": "true" })
|
|
433
|
+
}
|
|
434
|
+
)
|
|
435
|
+
] }) : null
|
|
436
|
+
] });
|
|
437
|
+
}
|
|
438
|
+
function CartSection({ section }) {
|
|
439
|
+
const Component = getRegistries().cartSections.get(section.component)?.component;
|
|
440
|
+
if (void 0 === Component) {
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
return /* @__PURE__ */ jsx2("div", { "data-cart-section": section.key, children: /* @__PURE__ */ jsx2(Component, { ...section.props, sectionKey: section.key, section }) });
|
|
444
|
+
}
|
|
445
|
+
function Cart({
|
|
446
|
+
cart,
|
|
447
|
+
showTitle,
|
|
448
|
+
showCoupon,
|
|
449
|
+
estimate,
|
|
450
|
+
countries,
|
|
451
|
+
urls,
|
|
452
|
+
sections,
|
|
453
|
+
feedback
|
|
454
|
+
}) {
|
|
455
|
+
const shared = useStorefront();
|
|
456
|
+
const errors = usePageErrors();
|
|
457
|
+
const root = useRef(null);
|
|
458
|
+
const [removing, setRemoving] = useState2(null);
|
|
459
|
+
const [undoing, setUndoing] = useState2(false);
|
|
460
|
+
const visits = useStorefrontRouter();
|
|
461
|
+
const [quoteAnnouncement, setQuoteAnnouncement] = useState2(null);
|
|
462
|
+
const cartUrl = shared.cart.url;
|
|
463
|
+
const storefrontBase = shared.routes.storefront.base;
|
|
464
|
+
const blocked = cart.checkoutBlocked;
|
|
465
|
+
useFocusAfterChange(
|
|
466
|
+
root,
|
|
467
|
+
feedback,
|
|
468
|
+
"[data-cart-line-remove], [data-cart-empty] a, #ecommerce-storefront-content"
|
|
469
|
+
);
|
|
470
|
+
const announcement = null !== quoteAnnouncement && quoteAnnouncement.for === feedback ? quoteAnnouncement.message : feedback.announcement ?? "";
|
|
471
|
+
const onRemove = (line) => {
|
|
472
|
+
if (null === cartUrl) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
setRemoving(line.id);
|
|
476
|
+
visits.delete(cartActionUrl(cartUrl, `lines/${line.id}`), {
|
|
477
|
+
...WRITE_OPTIONS,
|
|
478
|
+
onFinish: () => setRemoving(null)
|
|
479
|
+
});
|
|
480
|
+
};
|
|
481
|
+
const undo = () => {
|
|
482
|
+
if (null === cartUrl) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
setUndoing(true);
|
|
486
|
+
visits.post(
|
|
487
|
+
cartActionUrl(cartUrl, "undo"),
|
|
488
|
+
{},
|
|
489
|
+
{ ...WRITE_OPTIONS, onFinish: () => setUndoing(false) }
|
|
490
|
+
);
|
|
491
|
+
};
|
|
492
|
+
return /* @__PURE__ */ jsxs2("div", { className: "ec-cart", "data-ecommerce-cart": "", ref: root, children: [
|
|
493
|
+
/* @__PURE__ */ jsx2(
|
|
494
|
+
"p",
|
|
495
|
+
{
|
|
496
|
+
className: "apui-sr-only",
|
|
497
|
+
role: "status",
|
|
498
|
+
"aria-live": "polite",
|
|
499
|
+
"aria-atomic": "true",
|
|
500
|
+
"data-cart-announcement": "",
|
|
501
|
+
children: announcement
|
|
502
|
+
}
|
|
503
|
+
),
|
|
504
|
+
showTitle ? /* @__PURE__ */ jsxs2("div", { className: "ec-cart__heading", children: [
|
|
505
|
+
/* @__PURE__ */ jsx2("h1", { className: "ec-cart__title", children: __2("Your cart") }),
|
|
506
|
+
cart.lines.length > 0 ? /* @__PURE__ */ jsx2("p", { className: "ec-cart__count", "data-cart-item-count": "", children: trans_choice(":count item|:count items", cart.count, { count: cart.count }) }) : null
|
|
507
|
+
] }) : null,
|
|
508
|
+
null !== feedback.removedLine && feedback.removedLine.undoable ? /* @__PURE__ */ jsxs2("div", { className: "ec-cart__undo", "data-cart-undo": "", children: [
|
|
509
|
+
/* @__PURE__ */ jsx2(Icon2, { name: "trash", "aria-hidden": "true" }),
|
|
510
|
+
/* @__PURE__ */ jsx2("p", { children: __2(":name was removed from your cart.", { name: feedback.removedLine.name }) }),
|
|
511
|
+
/* @__PURE__ */ jsx2(
|
|
512
|
+
Button2,
|
|
513
|
+
{
|
|
514
|
+
variant: "ghost",
|
|
515
|
+
color: "neutral",
|
|
516
|
+
size: "sm",
|
|
517
|
+
disabled: undoing,
|
|
518
|
+
onClick: undo,
|
|
519
|
+
"data-cart-undo-button": "",
|
|
520
|
+
children: __2("Undo")
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
] }) : null,
|
|
524
|
+
0 === cart.lines.length ? /* @__PURE__ */ jsx2(
|
|
525
|
+
EmptyState,
|
|
526
|
+
{
|
|
527
|
+
icon: "shopping-bag",
|
|
528
|
+
title: __2("Your cart is empty"),
|
|
529
|
+
description: __2("Find something you like and add it to your cart."),
|
|
530
|
+
card: true,
|
|
531
|
+
live: true,
|
|
532
|
+
"data-cart-empty": "",
|
|
533
|
+
children: null !== urls.catalog ? /* @__PURE__ */ jsx2(Button2, { href: urls.catalog, color: "primary", children: __2("Continue shopping") }) : null
|
|
534
|
+
}
|
|
535
|
+
) : /* @__PURE__ */ jsxs2("div", { className: "ec-cart__layout", children: [
|
|
536
|
+
/* @__PURE__ */ jsxs2("section", { className: "ec-cart__main", "aria-labelledby": "ec-cart-lines-heading", children: [
|
|
537
|
+
/* @__PURE__ */ jsx2("h2", { id: "ec-cart-lines-heading", className: "apui-sr-only", children: __2("Items in your cart") }),
|
|
538
|
+
/* @__PURE__ */ jsx2(
|
|
539
|
+
"ul",
|
|
540
|
+
{
|
|
541
|
+
role: "list",
|
|
542
|
+
className: "apui-card ec-cart__lines",
|
|
543
|
+
"data-surface": "default",
|
|
544
|
+
"data-cart-lines": "",
|
|
545
|
+
children: cart.lines.map((line) => /* @__PURE__ */ jsx2(
|
|
546
|
+
CartLineRow,
|
|
547
|
+
{
|
|
548
|
+
line,
|
|
549
|
+
cartUrl,
|
|
550
|
+
error: errors[`quantities.${line.id}`] ?? null,
|
|
551
|
+
removing: removing === line.id,
|
|
552
|
+
onRemove
|
|
553
|
+
},
|
|
554
|
+
line.id
|
|
555
|
+
))
|
|
556
|
+
}
|
|
557
|
+
),
|
|
558
|
+
null !== urls.catalog ? /* @__PURE__ */ jsx2(
|
|
559
|
+
Link,
|
|
560
|
+
{
|
|
561
|
+
href: urls.catalog,
|
|
562
|
+
standalone: true,
|
|
563
|
+
leadingIcon: "arrow-left",
|
|
564
|
+
className: "ec-cart__continue",
|
|
565
|
+
"data-cart-continue": "",
|
|
566
|
+
children: __2("Continue shopping")
|
|
567
|
+
}
|
|
568
|
+
) : null
|
|
569
|
+
] }),
|
|
570
|
+
/* @__PURE__ */ jsxs2(
|
|
571
|
+
"section",
|
|
572
|
+
{
|
|
573
|
+
className: "apui-card ec-cart-summary",
|
|
574
|
+
"data-surface": "default",
|
|
575
|
+
"aria-labelledby": "ec-cart-summary-heading",
|
|
576
|
+
"data-cart-summary": "",
|
|
577
|
+
children: [
|
|
578
|
+
/* @__PURE__ */ jsx2("h2", { id: "ec-cart-summary-heading", className: "ec-cart-summary__title", children: __2("Order summary") }),
|
|
579
|
+
showCoupon ? /* @__PURE__ */ jsx2(CouponForm, { coupon: cart.coupon, cartUrl, error: errors.code ?? null }) : null,
|
|
580
|
+
cart.requiresShipping && null !== estimate && null !== cartUrl ? /* @__PURE__ */ jsx2(
|
|
581
|
+
ShippingEstimate,
|
|
582
|
+
{
|
|
583
|
+
estimate,
|
|
584
|
+
countries,
|
|
585
|
+
cartUrl,
|
|
586
|
+
formatUrl: null === storefrontBase ? null : `${storefrontBase.replace(/\/+$/, "")}/address-format`,
|
|
587
|
+
errors,
|
|
588
|
+
onAnnounce: (message) => setQuoteAnnouncement({ message, for: feedback })
|
|
589
|
+
}
|
|
590
|
+
) : null,
|
|
591
|
+
null !== cart.totals ? /* @__PURE__ */ jsx2(OrderTotals, { totals: cart.totals }) : null,
|
|
592
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-cart-summary__actions", children: [
|
|
593
|
+
null !== blocked ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
594
|
+
/* @__PURE__ */ jsx2(
|
|
595
|
+
Button2,
|
|
596
|
+
{
|
|
597
|
+
color: "primary",
|
|
598
|
+
size: "lg",
|
|
599
|
+
leadingIcon: "lock",
|
|
600
|
+
className: "ec-cart-summary__checkout",
|
|
601
|
+
disabled: true,
|
|
602
|
+
"aria-describedby": "ec-cart-checkout-blocked",
|
|
603
|
+
"data-cart-checkout": "",
|
|
604
|
+
children: __2("Checkout")
|
|
605
|
+
}
|
|
606
|
+
),
|
|
607
|
+
/* @__PURE__ */ jsx2(
|
|
608
|
+
"p",
|
|
609
|
+
{
|
|
610
|
+
id: "ec-cart-checkout-blocked",
|
|
611
|
+
className: "ec-cart-summary__blocked",
|
|
612
|
+
"data-cart-checkout-blocked": "",
|
|
613
|
+
children: "short" === blocked ? __2("Lower the quantities marked to check out.") : __2("Remove the items that can't be bought to check out.")
|
|
614
|
+
}
|
|
615
|
+
)
|
|
616
|
+
] }) : null !== urls.checkout ? /* @__PURE__ */ jsx2(
|
|
617
|
+
Button2,
|
|
618
|
+
{
|
|
619
|
+
href: urls.checkout,
|
|
620
|
+
color: "primary",
|
|
621
|
+
size: "lg",
|
|
622
|
+
leadingIcon: "lock",
|
|
623
|
+
className: "ec-cart-summary__checkout",
|
|
624
|
+
"data-cart-checkout": "",
|
|
625
|
+
children: __2("Checkout")
|
|
626
|
+
}
|
|
627
|
+
) : null,
|
|
628
|
+
cart.requiresShipping ? /* @__PURE__ */ jsx2("p", { className: "ec-cart-summary__note", children: __2("Taxes are estimated until you enter your address.") }) : null
|
|
629
|
+
] })
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
)
|
|
633
|
+
] }),
|
|
634
|
+
sections.map((section) => /* @__PURE__ */ jsx2(CartSection, { section }, section.key))
|
|
635
|
+
] });
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export {
|
|
639
|
+
registerCartBuiltIns,
|
|
640
|
+
ShippingEstimate,
|
|
641
|
+
Cart
|
|
642
|
+
};
|
|
643
|
+
//# sourceMappingURL=chunk-DWR23FJD.mjs.map
|