@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,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
visitWithQuery
|
|
3
|
+
} from "./chunk-Y2IOBBN7.mjs";
|
|
4
|
+
import {
|
|
5
|
+
EmptyState,
|
|
6
|
+
cx
|
|
7
|
+
} from "./chunk-VX5TEJNU.mjs";
|
|
8
|
+
|
|
9
|
+
// src/account/AccountDownloads.tsx
|
|
10
|
+
import {
|
|
11
|
+
__,
|
|
12
|
+
trans_choice
|
|
13
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
14
|
+
import {
|
|
15
|
+
Alert,
|
|
16
|
+
Badge,
|
|
17
|
+
Button,
|
|
18
|
+
Card,
|
|
19
|
+
Clipboard,
|
|
20
|
+
Icon,
|
|
21
|
+
List,
|
|
22
|
+
ListItem,
|
|
23
|
+
Pagination
|
|
24
|
+
} from "@artisanpack-ui/react";
|
|
25
|
+
import { router, usePage } from "@inertiajs/react";
|
|
26
|
+
import { Fragment } from "react";
|
|
27
|
+
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
+
function ListPagination({
|
|
29
|
+
pagination,
|
|
30
|
+
pageName,
|
|
31
|
+
url,
|
|
32
|
+
dataAttribute
|
|
33
|
+
}) {
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Pagination,
|
|
36
|
+
{
|
|
37
|
+
page: pagination.currentPage,
|
|
38
|
+
pageCount: pagination.lastPage,
|
|
39
|
+
total: pagination.total,
|
|
40
|
+
perPage: pagination.perPage,
|
|
41
|
+
onPageChange: (page) => visitWithQuery(url, { [pageName]: 1 === page ? null : page }, [pageName]),
|
|
42
|
+
...{ [dataAttribute]: "" }
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function downloadFacts(row) {
|
|
47
|
+
if ("expired" === row.state) {
|
|
48
|
+
return /* @__PURE__ */ jsx("span", { "data-account-download-reason": "expired", children: null === row.expires ? __("This download has expired.") : __("This download expired on :date.", { date: row.expires }) });
|
|
49
|
+
}
|
|
50
|
+
if ("exhausted" === row.state) {
|
|
51
|
+
return /* @__PURE__ */ jsx("span", { "data-account-download-reason": "exhausted", children: __("You've used all the downloads for this file.") });
|
|
52
|
+
}
|
|
53
|
+
const facts = [
|
|
54
|
+
row.streaming ? __("Streaming") : null,
|
|
55
|
+
!row.streaming && null !== row.version ? __("Version :version", { version: row.version }) : null,
|
|
56
|
+
row.streaming ? null : null === row.remaining ? __("Unlimited downloads") : trans_choice(":count download left|:count downloads left", row.remaining, {
|
|
57
|
+
count: row.remaining
|
|
58
|
+
}),
|
|
59
|
+
null !== row.expires ? __("Available until :date", { date: row.expires }) : null,
|
|
60
|
+
null !== row.order ? __("Order :number", { number: row.order }) : null
|
|
61
|
+
].filter((fact) => null !== fact);
|
|
62
|
+
return facts.map((fact, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
63
|
+
index > 0 ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
65
|
+
/* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: ", " })
|
|
66
|
+
] }) : null,
|
|
67
|
+
fact
|
|
68
|
+
] }, fact));
|
|
69
|
+
}
|
|
70
|
+
function AccountDownloads({
|
|
71
|
+
downloads,
|
|
72
|
+
licenses,
|
|
73
|
+
failed,
|
|
74
|
+
catalogUrl
|
|
75
|
+
}) {
|
|
76
|
+
const { url } = usePage();
|
|
77
|
+
const hasFiles = downloads.items.length > 0;
|
|
78
|
+
const hasLicenses = licenses.items.length > 0;
|
|
79
|
+
const download = (event, row) => {
|
|
80
|
+
if (null === row.linkUrl || 0 !== event.button || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
router.post(row.linkUrl, {}, { preserveScroll: true });
|
|
85
|
+
};
|
|
86
|
+
return /* @__PURE__ */ jsxs("div", { className: "ec-downloads", "data-account-downloads": "", children: [
|
|
87
|
+
/* @__PURE__ */ jsx("p", { className: "ec-downloads__lead", children: __("Files and license keys from your orders.") }),
|
|
88
|
+
failed ? /* @__PURE__ */ jsx(
|
|
89
|
+
Alert,
|
|
90
|
+
{
|
|
91
|
+
color: "warning",
|
|
92
|
+
icon: "circle-alert",
|
|
93
|
+
title: __("Your downloads couldn't be loaded"),
|
|
94
|
+
description: __("Try again in a moment."),
|
|
95
|
+
"data-account-downloads-failed": ""
|
|
96
|
+
}
|
|
97
|
+
) : null,
|
|
98
|
+
!failed && !hasFiles && !hasLicenses ? /* @__PURE__ */ jsx(
|
|
99
|
+
EmptyState,
|
|
100
|
+
{
|
|
101
|
+
card: true,
|
|
102
|
+
icon: "download",
|
|
103
|
+
title: __("No downloads yet"),
|
|
104
|
+
description: __("Files and license keys from your orders will appear here."),
|
|
105
|
+
"data-account-no-downloads": "",
|
|
106
|
+
children: null !== catalogUrl ? /* @__PURE__ */ jsx(Button, { href: catalogUrl, color: "primary", children: __("Start shopping") }) : null
|
|
107
|
+
}
|
|
108
|
+
) : null,
|
|
109
|
+
hasFiles ? /* @__PURE__ */ jsxs(
|
|
110
|
+
Card,
|
|
111
|
+
{
|
|
112
|
+
className: "ec-order-card ec-order-card--flush",
|
|
113
|
+
role: "region",
|
|
114
|
+
"aria-labelledby": "ec-account-files",
|
|
115
|
+
"data-account-files": "",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsx("h2", { id: "ec-account-files", className: "ec-order-card__title ec-downloads__card-title", children: __("Files") }),
|
|
118
|
+
/* @__PURE__ */ jsx(List, { variant: "divided", className: "ec-downloads__files", children: downloads.items.map((row) => {
|
|
119
|
+
const product = row.product !== row.file ? row.product : null;
|
|
120
|
+
const name = null === product ? row.file : `${row.file} (${product})`;
|
|
121
|
+
return /* @__PURE__ */ jsx(
|
|
122
|
+
ListItem,
|
|
123
|
+
{
|
|
124
|
+
className: "ec-downloads__file",
|
|
125
|
+
"data-account-download": row.id,
|
|
126
|
+
"data-state": row.state,
|
|
127
|
+
leading: /* @__PURE__ */ jsx(
|
|
128
|
+
Icon,
|
|
129
|
+
{
|
|
130
|
+
name: row.streaming ? "play" : "file-text",
|
|
131
|
+
variant: "tile",
|
|
132
|
+
color: "neutral"
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
title: /* @__PURE__ */ jsx("span", { className: "ec-downloads__name", children: row.file }),
|
|
136
|
+
description: /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
137
|
+
null !== product ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
138
|
+
/* @__PURE__ */ jsx("span", { "data-account-download-product": "", children: product }),
|
|
139
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
140
|
+
/* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: ", " })
|
|
141
|
+
] }) : null,
|
|
142
|
+
downloadFacts(row)
|
|
143
|
+
] }),
|
|
144
|
+
trailing: null !== row.url ? row.streaming ? /* @__PURE__ */ jsx(
|
|
145
|
+
Button,
|
|
146
|
+
{
|
|
147
|
+
variant: "outline",
|
|
148
|
+
color: "neutral",
|
|
149
|
+
size: "sm",
|
|
150
|
+
leadingIcon: "external-link",
|
|
151
|
+
href: row.url,
|
|
152
|
+
target: "_blank",
|
|
153
|
+
rel: "noopener",
|
|
154
|
+
"aria-label": __("Play :file (opens in a new tab)", { file: name }),
|
|
155
|
+
"data-account-download-play": "",
|
|
156
|
+
children: __("Play")
|
|
157
|
+
}
|
|
158
|
+
) : /* @__PURE__ */ jsx(
|
|
159
|
+
Button,
|
|
160
|
+
{
|
|
161
|
+
variant: "outline",
|
|
162
|
+
color: "neutral",
|
|
163
|
+
size: "sm",
|
|
164
|
+
leadingIcon: "download",
|
|
165
|
+
href: row.url,
|
|
166
|
+
onClick: (event) => download(event, row),
|
|
167
|
+
"aria-label": __("Download :file", { file: name }),
|
|
168
|
+
"data-account-download-button": "",
|
|
169
|
+
children: __("Download")
|
|
170
|
+
}
|
|
171
|
+
) : "expired" === row.state ? /* @__PURE__ */ jsx(Badge, { color: "neutral", size: "sm", "data-account-download-badge": "expired", children: __("Expired") }) : "exhausted" === row.state ? /* @__PURE__ */ jsx(Badge, { color: "neutral", size: "sm", "data-account-download-badge": "exhausted", children: __("No downloads left") }) : void 0
|
|
172
|
+
},
|
|
173
|
+
row.id
|
|
174
|
+
);
|
|
175
|
+
}) }),
|
|
176
|
+
null !== downloads.pagination && downloads.pagination.lastPage > 1 ? /* @__PURE__ */ jsx("div", { className: "ec-downloads__pagination", children: /* @__PURE__ */ jsx(
|
|
177
|
+
ListPagination,
|
|
178
|
+
{
|
|
179
|
+
pagination: downloads.pagination,
|
|
180
|
+
pageName: "downloads",
|
|
181
|
+
url,
|
|
182
|
+
dataAttribute: "data-account-downloads-pagination"
|
|
183
|
+
}
|
|
184
|
+
) }) : null
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
) : null,
|
|
188
|
+
hasLicenses ? /* @__PURE__ */ jsxs(
|
|
189
|
+
Card,
|
|
190
|
+
{
|
|
191
|
+
className: "ec-order-card",
|
|
192
|
+
role: "region",
|
|
193
|
+
"aria-labelledby": "ec-account-licences",
|
|
194
|
+
"data-account-licences": "",
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ jsx("h2", { id: "ec-account-licences", className: "ec-order-card__title", children: __("License keys") }),
|
|
197
|
+
/* @__PURE__ */ jsx("ul", { className: "ec-downloads__licences", children: licenses.items.map((row) => /* @__PURE__ */ jsxs(
|
|
198
|
+
"li",
|
|
199
|
+
{
|
|
200
|
+
className: "ec-downloads__licence",
|
|
201
|
+
"data-account-licence": row.id,
|
|
202
|
+
"data-state": row.state,
|
|
203
|
+
children: [
|
|
204
|
+
/* @__PURE__ */ jsxs("div", { className: "ec-downloads__licence-head", children: [
|
|
205
|
+
/* @__PURE__ */ jsxs(
|
|
206
|
+
"h3",
|
|
207
|
+
{
|
|
208
|
+
id: `ec-account-licence-${row.id}`,
|
|
209
|
+
className: cx(
|
|
210
|
+
"ec-downloads__licence-name",
|
|
211
|
+
"active" !== row.state && "ec-downloads__licence-name--inactive"
|
|
212
|
+
),
|
|
213
|
+
children: [
|
|
214
|
+
row.product,
|
|
215
|
+
null !== row.variant ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
216
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
217
|
+
/* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: ", " }),
|
|
218
|
+
row.variant
|
|
219
|
+
] }) : null
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
"revoked" === row.state ? /* @__PURE__ */ jsx(Badge, { color: "error", size: "sm", "data-account-licence-badge": "revoked", children: __("Revoked") }) : "expired" === row.state ? /* @__PURE__ */ jsx(Badge, { color: "neutral", size: "sm", "data-account-licence-badge": "expired", children: __("Expired") }) : /* @__PURE__ */ jsx(Badge, { color: "success", size: "sm", "data-account-licence-badge": "active", children: null === row.expires ? __("Active") : __("Valid until :date", { date: row.expires }) })
|
|
224
|
+
] }),
|
|
225
|
+
"revoked" === row.state ? /* @__PURE__ */ jsx("p", { className: "ec-downloads__licence-note", "data-account-licence-reason": "revoked", children: __("This license key has been revoked.") }) : "expired" === row.state ? /* @__PURE__ */ jsx("p", { className: "ec-downloads__licence-note", "data-account-licence-reason": "expired", children: null === row.expires ? __("This license key has expired.") : __("This license key expired on :date.", { date: row.expires }) }) : (
|
|
226
|
+
// The group names the Copy button after its license.
|
|
227
|
+
/* @__PURE__ */ jsx("div", { role: "group", "aria-labelledby": `ec-account-licence-${row.id}`, children: /* @__PURE__ */ jsx(
|
|
228
|
+
Clipboard,
|
|
229
|
+
{
|
|
230
|
+
variant: "field",
|
|
231
|
+
size: "md",
|
|
232
|
+
value: row.key,
|
|
233
|
+
className: "ec-downloads__key",
|
|
234
|
+
"data-account-licence-key": "",
|
|
235
|
+
"data-account-licence-copy": ""
|
|
236
|
+
}
|
|
237
|
+
) })
|
|
238
|
+
),
|
|
239
|
+
"revoked" !== row.state ? /* @__PURE__ */ jsx("p", { className: "ec-downloads__licence-note", "data-account-licence-activations": "", children: null === row.limit ? trans_choice(":count activation|:count activations", row.activations, {
|
|
240
|
+
count: row.activations
|
|
241
|
+
}) : trans_choice(
|
|
242
|
+
":count of :limit activation used|:count of :limit activations used",
|
|
243
|
+
row.limit,
|
|
244
|
+
{ count: row.activations, limit: row.limit }
|
|
245
|
+
) }) : null
|
|
246
|
+
]
|
|
247
|
+
},
|
|
248
|
+
row.id
|
|
249
|
+
)) }),
|
|
250
|
+
null !== licenses.pagination && licenses.pagination.lastPage > 1 ? /* @__PURE__ */ jsx(
|
|
251
|
+
ListPagination,
|
|
252
|
+
{
|
|
253
|
+
pagination: licenses.pagination,
|
|
254
|
+
pageName: "licenses",
|
|
255
|
+
url,
|
|
256
|
+
dataAttribute: "data-account-licences-pagination"
|
|
257
|
+
}
|
|
258
|
+
) : null
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
) : null
|
|
262
|
+
] });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export {
|
|
266
|
+
AccountDownloads
|
|
267
|
+
};
|
|
268
|
+
//# sourceMappingURL=chunk-WUL34MB2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/account/AccountDownloads.tsx"],"sourcesContent":["/**\n * Downloads and license keys.\n *\n * Mirrors ecommerce-storefront-livewire's `account/downloads`: the lead\n * line, then two Cards. Files: a divided List, each row a file (or play)\n * icon tile, the file's name, then its product, version, downloads left,\n * expiry and order (or why it can't be downloaded), with an outline\n * \"Download\" or \"Play\" (opens in a new tab) at the end, or an \"Expired\" /\n * \"No downloads left\" Badge. License keys: each key's product and tier with\n * a state Badge, then the key in the design-system Clipboard field, and the\n * activations. No files and no keys is the EmptyState in a Card.\n *\n * The file links are plain links to the signed `downloads.file` and\n * `downloads.stream` routes, never Inertia visits. \"Download\" posts to\n * `linkUrl` for a freshly signed link when clicked, so a page left open\n * past the link's lifetime still works; its href is the fallback.\n *\n * @since 1.0.0\n */\n\nimport {\n __,\n trans_choice,\n type AccountDownloadsProps,\n type StorefrontAccountDownload,\n type StorefrontPagination,\n} from '@artisanpack-ui/ecommerce-storefront-core';\nimport {\n Alert,\n Badge,\n Button,\n Card,\n Clipboard,\n Icon,\n List,\n ListItem,\n Pagination,\n} from '@artisanpack-ui/react';\nimport { router, usePage } from '@inertiajs/react';\nimport { Fragment, type MouseEvent, type ReactElement, type ReactNode } from 'react';\n\nimport { EmptyState } from '../components/EmptyState';\nimport { cx } from '../internal/classes';\nimport { visitWithQuery } from '../product/support';\n\n/**\n * Props for {@link AccountDownloads}.\n *\n * @since 1.0.0\n */\nexport type AccountDownloadsViewProps = Omit<AccountDownloadsProps, 'shell'>;\n\n/**\n * A list's pager, paging with its own query key.\n *\n * @param props - The pagination, the query key, the current URL and a data attribute.\n * @returns The pager.\n */\nfunction ListPagination({\n pagination,\n pageName,\n url,\n dataAttribute,\n}: {\n pagination: StorefrontPagination;\n pageName: 'downloads' | 'licenses';\n url: string;\n dataAttribute: string;\n}): ReactElement {\n return (\n <Pagination\n page={pagination.currentPage}\n pageCount={pagination.lastPage}\n total={pagination.total}\n perPage={pagination.perPage}\n onPageChange={(page) =>\n visitWithQuery(url, { [pageName]: 1 === page ? null : page }, [pageName])\n }\n {...{ [dataAttribute]: '' }}\n />\n );\n}\n\n/**\n * What a file row says under its name.\n *\n * @param row - The file.\n * @returns The facts, separated by middots.\n */\nfunction downloadFacts(row: StorefrontAccountDownload): ReactNode {\n if ('expired' === row.state) {\n return (\n <span data-account-download-reason=\"expired\">\n {null === row.expires\n ? __('This download has expired.')\n : __('This download expired on :date.', { date: row.expires })}\n </span>\n );\n }\n\n if ('exhausted' === row.state) {\n return (\n <span data-account-download-reason=\"exhausted\">\n {__(\"You've used all the downloads for this file.\")}\n </span>\n );\n }\n\n const facts = [\n row.streaming ? __('Streaming') : null,\n !row.streaming && null !== row.version\n ? __('Version :version', { version: row.version })\n : null,\n row.streaming\n ? null\n : null === row.remaining\n ? __('Unlimited downloads')\n : trans_choice(':count download left|:count downloads left', row.remaining, {\n count: row.remaining,\n }),\n null !== row.expires ? __('Available until :date', { date: row.expires }) : null,\n null !== row.order ? __('Order :number', { number: row.order }) : null,\n ].filter((fact): fact is string => null !== fact);\n\n return facts.map((fact, index) => (\n <Fragment key={fact}>\n {index > 0 ? (\n <>\n <span aria-hidden=\"true\"> · </span>\n <span className=\"apui-sr-only\">, </span>\n </>\n ) : null}\n {fact}\n </Fragment>\n ));\n}\n\n/**\n * The downloads page's body.\n *\n * @since 1.0.0\n *\n * @param props - The files, the license keys and the catalog link.\n * @returns The downloads.\n */\nexport function AccountDownloads({\n downloads,\n licenses,\n failed,\n catalogUrl,\n}: AccountDownloadsViewProps): ReactElement {\n const { url } = usePage();\n const hasFiles = downloads.items.length > 0;\n const hasLicenses = licenses.items.length > 0;\n\n const download = (event: MouseEvent, row: StorefrontAccountDownload): void => {\n // A modified or middle click keeps the browser's own handling (a new\n // tab or window) on the plain signed link.\n if (\n null === row.linkUrl ||\n 0 !== event.button ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey\n ) {\n return;\n }\n\n event.preventDefault();\n router.post(row.linkUrl, {}, { preserveScroll: true });\n };\n\n return (\n <div className=\"ec-downloads\" data-account-downloads=\"\">\n <p className=\"ec-downloads__lead\">{__('Files and license keys from your orders.')}</p>\n\n {failed ? (\n <Alert\n color=\"warning\"\n icon=\"circle-alert\"\n title={__(\"Your downloads couldn't be loaded\")}\n description={__('Try again in a moment.')}\n data-account-downloads-failed=\"\"\n />\n ) : null}\n\n {!failed && !hasFiles && !hasLicenses ? (\n <EmptyState\n card\n icon=\"download\"\n title={__('No downloads yet')}\n description={__('Files and license keys from your orders will appear here.')}\n data-account-no-downloads=\"\"\n >\n {null !== catalogUrl ? (\n <Button href={catalogUrl} color=\"primary\">\n {__('Start shopping')}\n </Button>\n ) : null}\n </EmptyState>\n ) : null}\n\n {hasFiles ? (\n <Card\n className=\"ec-order-card ec-order-card--flush\"\n role=\"region\"\n aria-labelledby=\"ec-account-files\"\n data-account-files=\"\"\n >\n <h2 id=\"ec-account-files\" className=\"ec-order-card__title ec-downloads__card-title\">\n {__('Files')}\n </h2>\n\n <List variant=\"divided\" className=\"ec-downloads__files\">\n {downloads.items.map((row) => {\n // Two products can ship files with the same name, so the product goes along with it.\n const product = row.product !== row.file ? row.product : null;\n const name = null === product ? row.file : `${row.file} (${product})`;\n\n return (\n <ListItem\n key={row.id}\n className=\"ec-downloads__file\"\n data-account-download={row.id}\n data-state={row.state}\n leading={\n <Icon\n name={row.streaming ? 'play' : 'file-text'}\n variant=\"tile\"\n color=\"neutral\"\n />\n }\n title={<span className=\"ec-downloads__name\">{row.file}</span>}\n description={\n <>\n {null !== product ? (\n <>\n <span data-account-download-product=\"\">{product}</span>\n <span aria-hidden=\"true\"> · </span>\n <span className=\"apui-sr-only\">, </span>\n </>\n ) : null}\n {downloadFacts(row)}\n </>\n }\n trailing={\n null !== row.url ? (\n row.streaming ? (\n <Button\n variant=\"outline\"\n color=\"neutral\"\n size=\"sm\"\n leadingIcon=\"external-link\"\n href={row.url}\n target=\"_blank\"\n rel=\"noopener\"\n aria-label={__('Play :file (opens in a new tab)', { file: name })}\n data-account-download-play=\"\"\n >\n {__('Play')}\n </Button>\n ) : (\n <Button\n variant=\"outline\"\n color=\"neutral\"\n size=\"sm\"\n leadingIcon=\"download\"\n href={row.url}\n onClick={(event) => download(event, row)}\n aria-label={__('Download :file', { file: name })}\n data-account-download-button=\"\"\n >\n {__('Download')}\n </Button>\n )\n ) : 'expired' === row.state ? (\n <Badge color=\"neutral\" size=\"sm\" data-account-download-badge=\"expired\">\n {__('Expired')}\n </Badge>\n ) : 'exhausted' === row.state ? (\n <Badge color=\"neutral\" size=\"sm\" data-account-download-badge=\"exhausted\">\n {__('No downloads left')}\n </Badge>\n ) : undefined\n }\n />\n );\n })}\n </List>\n\n {null !== downloads.pagination && downloads.pagination.lastPage > 1 ? (\n <div className=\"ec-downloads__pagination\">\n <ListPagination\n pagination={downloads.pagination}\n pageName=\"downloads\"\n url={url}\n dataAttribute=\"data-account-downloads-pagination\"\n />\n </div>\n ) : null}\n </Card>\n ) : null}\n\n {hasLicenses ? (\n <Card\n className=\"ec-order-card\"\n role=\"region\"\n aria-labelledby=\"ec-account-licences\"\n data-account-licences=\"\"\n >\n <h2 id=\"ec-account-licences\" className=\"ec-order-card__title\">\n {__('License keys')}\n </h2>\n\n <ul className=\"ec-downloads__licences\">\n {licenses.items.map((row) => (\n <li\n key={row.id}\n className=\"ec-downloads__licence\"\n data-account-licence={row.id}\n data-state={row.state}\n >\n <div className=\"ec-downloads__licence-head\">\n <h3\n id={`ec-account-licence-${row.id}`}\n className={cx(\n 'ec-downloads__licence-name',\n 'active' !== row.state && 'ec-downloads__licence-name--inactive',\n )}\n >\n {row.product}\n {null !== row.variant ? (\n <>\n <span aria-hidden=\"true\"> · </span>\n <span className=\"apui-sr-only\">, </span>\n {row.variant}\n </>\n ) : null}\n </h3>\n\n {'revoked' === row.state ? (\n <Badge color=\"error\" size=\"sm\" data-account-licence-badge=\"revoked\">\n {__('Revoked')}\n </Badge>\n ) : 'expired' === row.state ? (\n <Badge color=\"neutral\" size=\"sm\" data-account-licence-badge=\"expired\">\n {__('Expired')}\n </Badge>\n ) : (\n <Badge color=\"success\" size=\"sm\" data-account-licence-badge=\"active\">\n {null === row.expires\n ? __('Active')\n : __('Valid until :date', { date: row.expires })}\n </Badge>\n )}\n </div>\n\n {'revoked' === row.state ? (\n <p className=\"ec-downloads__licence-note\" data-account-licence-reason=\"revoked\">\n {__('This license key has been revoked.')}\n </p>\n ) : 'expired' === row.state ? (\n <p className=\"ec-downloads__licence-note\" data-account-licence-reason=\"expired\">\n {null === row.expires\n ? __('This license key has expired.')\n : __('This license key expired on :date.', { date: row.expires })}\n </p>\n ) : (\n // The group names the Copy button after its license.\n <div role=\"group\" aria-labelledby={`ec-account-licence-${row.id}`}>\n <Clipboard\n variant=\"field\"\n size=\"md\"\n value={row.key}\n className=\"ec-downloads__key\"\n data-account-licence-key=\"\"\n data-account-licence-copy=\"\"\n />\n </div>\n )}\n\n {'revoked' !== row.state ? (\n <p className=\"ec-downloads__licence-note\" data-account-licence-activations=\"\">\n {null === row.limit\n ? trans_choice(':count activation|:count activations', row.activations, {\n count: row.activations,\n })\n : trans_choice(\n ':count of :limit activation used|:count of :limit activations used',\n row.limit,\n { count: row.activations, limit: row.limit },\n )}\n </p>\n ) : null}\n </li>\n ))}\n </ul>\n\n {null !== licenses.pagination && licenses.pagination.lastPage > 1 ? (\n <ListPagination\n pagination={licenses.pagination}\n pageName=\"licenses\"\n url={url}\n dataAttribute=\"data-account-licences-pagination\"\n />\n ) : null}\n </Card>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAoBA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,QAAQ,eAAe;AAChC,SAAS,gBAAoE;AA+BzE,SAyDI,YAAAA,WAzDJ,KAyDI,YAzDJ;AAZJ,SAAS,eAAe;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKiB;AACf,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAM,WAAW;AAAA,MACjB,WAAW,WAAW;AAAA,MACtB,OAAO,WAAW;AAAA,MAClB,SAAS,WAAW;AAAA,MACpB,cAAc,CAAC,SACb,eAAe,KAAK,EAAE,CAAC,QAAQ,GAAG,MAAM,OAAO,OAAO,KAAK,GAAG,CAAC,QAAQ,CAAC;AAAA,MAEzE,GAAG,EAAE,CAAC,aAAa,GAAG,GAAG;AAAA;AAAA,EAC5B;AAEJ;AAQA,SAAS,cAAc,KAA2C;AAChE,MAAI,cAAc,IAAI,OAAO;AAC3B,WACE,oBAAC,UAAK,gCAA6B,WAChC,mBAAS,IAAI,UACV,GAAG,4BAA4B,IAC/B,GAAG,mCAAmC,EAAE,MAAM,IAAI,QAAQ,CAAC,GACjE;AAAA,EAEJ;AAEA,MAAI,gBAA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mjs";
|
|
4
|
+
|
|
5
|
+
// src/components/Field.tsx
|
|
6
|
+
import { __ } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
7
|
+
import { Checkbox, Input, Password, Select, Textarea } from "@artisanpack-ui/react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
function Field({
|
|
10
|
+
id,
|
|
11
|
+
control = "input",
|
|
12
|
+
label = null,
|
|
13
|
+
hint = null,
|
|
14
|
+
error = null,
|
|
15
|
+
options = [],
|
|
16
|
+
placeholder = null,
|
|
17
|
+
optional = false,
|
|
18
|
+
maxLength = null,
|
|
19
|
+
leadingIcon = null,
|
|
20
|
+
errorKey,
|
|
21
|
+
name,
|
|
22
|
+
value,
|
|
23
|
+
checked,
|
|
24
|
+
required = false,
|
|
25
|
+
disabled,
|
|
26
|
+
type,
|
|
27
|
+
autoComplete,
|
|
28
|
+
inputMode,
|
|
29
|
+
onValueChange,
|
|
30
|
+
onCheckedChange,
|
|
31
|
+
onBlur,
|
|
32
|
+
attributes = {}
|
|
33
|
+
}) {
|
|
34
|
+
const key = filled(errorKey) ? errorKey : filled(name) ? name : null;
|
|
35
|
+
const fieldHint = filled(hint) ? hint : void 0;
|
|
36
|
+
const fieldError = filled(error) ? error : void 0;
|
|
37
|
+
let fieldLabel = filled(label) ? label : void 0;
|
|
38
|
+
if (void 0 !== fieldLabel && "checkbox" === control && required) {
|
|
39
|
+
fieldLabel = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
40
|
+
label,
|
|
41
|
+
/* @__PURE__ */ jsx("span", { "data-scope": "checkbox", "data-part": "required", "aria-hidden": "true", children: "*" })
|
|
42
|
+
] });
|
|
43
|
+
} else if (void 0 !== fieldLabel && optional && "checkbox" !== control) {
|
|
44
|
+
fieldLabel = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
+
label,
|
|
46
|
+
" ",
|
|
47
|
+
/* @__PURE__ */ jsx("span", { className: "ec-field__optional", children: __("(optional)") })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
const common = {
|
|
51
|
+
...attributes,
|
|
52
|
+
id,
|
|
53
|
+
name,
|
|
54
|
+
label: fieldLabel,
|
|
55
|
+
error: fieldError,
|
|
56
|
+
required,
|
|
57
|
+
disabled,
|
|
58
|
+
onBlur
|
|
59
|
+
};
|
|
60
|
+
let body;
|
|
61
|
+
switch (control) {
|
|
62
|
+
case "select":
|
|
63
|
+
body = /* @__PURE__ */ jsx(
|
|
64
|
+
Select,
|
|
65
|
+
{
|
|
66
|
+
...common,
|
|
67
|
+
hint: fieldHint,
|
|
68
|
+
options: options.map((option) => ({
|
|
69
|
+
value: option.value,
|
|
70
|
+
label: option.label,
|
|
71
|
+
...option.disabled ? { disabled: true } : {}
|
|
72
|
+
})),
|
|
73
|
+
placeholder: placeholder ?? void 0,
|
|
74
|
+
value,
|
|
75
|
+
autoComplete,
|
|
76
|
+
onValueChange: (next) => onValueChange?.(String(next))
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
break;
|
|
80
|
+
case "textarea":
|
|
81
|
+
body = /* @__PURE__ */ jsx(
|
|
82
|
+
Textarea,
|
|
83
|
+
{
|
|
84
|
+
...common,
|
|
85
|
+
hint: fieldHint,
|
|
86
|
+
placeholder: placeholder ?? void 0,
|
|
87
|
+
maxLength: maxLength ?? void 0,
|
|
88
|
+
value,
|
|
89
|
+
onValueChange
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
break;
|
|
93
|
+
case "password":
|
|
94
|
+
body = /* @__PURE__ */ jsx(
|
|
95
|
+
Password,
|
|
96
|
+
{
|
|
97
|
+
...common,
|
|
98
|
+
hint: fieldHint,
|
|
99
|
+
leadingIcon: leadingIcon ?? void 0,
|
|
100
|
+
value,
|
|
101
|
+
autocomplete: "new-password" === autoComplete ? "new-password" : "current-password",
|
|
102
|
+
onValueChange
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
break;
|
|
106
|
+
case "checkbox":
|
|
107
|
+
body = /* @__PURE__ */ jsx(
|
|
108
|
+
Checkbox,
|
|
109
|
+
{
|
|
110
|
+
...common,
|
|
111
|
+
description: fieldHint,
|
|
112
|
+
checked,
|
|
113
|
+
onCheckedChange
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
body = /* @__PURE__ */ jsx(
|
|
119
|
+
Input,
|
|
120
|
+
{
|
|
121
|
+
...common,
|
|
122
|
+
type,
|
|
123
|
+
hint: fieldHint,
|
|
124
|
+
placeholder: placeholder ?? void 0,
|
|
125
|
+
leadingIcon: leadingIcon ?? void 0,
|
|
126
|
+
value,
|
|
127
|
+
autoComplete,
|
|
128
|
+
inputMode,
|
|
129
|
+
maxLength: maxLength ?? void 0,
|
|
130
|
+
onValueChange
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return /* @__PURE__ */ jsx("div", { className: "ec-field", "data-ec-field": id, "data-field-key": key ?? void 0, children: body });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
Field
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=chunk-WYGOMIZK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Field.tsx"],"sourcesContent":["/**\n * `ec-field`: one form control with its label, hint and error, wrapped so\n * a form can find it by field key (the error summary's links focus it).\n *\n * Mirrors ecommerce-storefront-livewire's `<x-artisanpack-ec-field>`: an\n * Input, Select, Textarea, Password or Checkbox from the design system. An\n * optional field's label says \"(optional)\"; a required checkbox gets the\n * required star.\n *\n * @since 1.0.0\n */\n\nimport { __, type StorefrontFieldProps } from '@artisanpack-ui/ecommerce-storefront-core';\nimport { Checkbox, Input, Password, Select, Textarea } from '@artisanpack-ui/react';\nimport type { FocusEvent, ReactElement, ReactNode } from 'react';\n\nimport { filled } from '../internal/classes';\n\n/**\n * Props for {@link Field}.\n *\n * @since 1.0.0\n */\nexport interface FieldProps extends StorefrontFieldProps {\n /** The field's key in the page's `errors`, for `data-field-key`. Defaults to `name`. */\n errorKey?: string | null;\n name?: string;\n value?: string;\n checked?: boolean;\n required?: boolean;\n disabled?: boolean;\n type?: string;\n autoComplete?: string;\n inputMode?: 'text' | 'numeric' | 'decimal' | 'tel' | 'email' | 'url' | 'search' | 'none';\n /** Called with the new value of an input, select, textarea or password. */\n onValueChange?: (value: string) => void;\n /** Called with a checkbox's new state. */\n onCheckedChange?: (checked: boolean) => void;\n onBlur?: (event: FocusEvent<HTMLElement>) => void;\n /** Any other attributes for the control, such as `data-*`. */\n attributes?: Record<string, unknown>;\n}\n\n/**\n * A form field.\n *\n * @since 1.0.0\n *\n * @param props - The control, label, hint, error and value.\n * @returns The field.\n */\nexport function Field({\n id,\n control = 'input',\n label = null,\n hint = null,\n error = null,\n options = [],\n placeholder = null,\n optional = false,\n maxLength = null,\n leadingIcon = null,\n errorKey,\n name,\n value,\n checked,\n required = false,\n disabled,\n type,\n autoComplete,\n inputMode,\n onValueChange,\n onCheckedChange,\n onBlur,\n attributes = {},\n}: FieldProps): ReactElement {\n const key = filled(errorKey) ? errorKey : filled(name) ? name : null;\n const fieldHint = filled(hint) ? hint : undefined;\n const fieldError = filled(error) ? error : undefined;\n\n let fieldLabel: ReactNode = filled(label) ? label : undefined;\n\n if (undefined !== fieldLabel && 'checkbox' === control && required) {\n fieldLabel = (\n <>\n {label}\n <span data-scope=\"checkbox\" data-part=\"required\" aria-hidden=\"true\">\n *\n </span>\n </>\n );\n } else if (undefined !== fieldLabel && optional && 'checkbox' !== control) {\n fieldLabel = (\n <>\n {label} <span className=\"ec-field__optional\">{__('(optional)')}</span>\n </>\n );\n }\n\n const common = {\n ...attributes,\n id,\n name,\n label: fieldLabel,\n error: fieldError,\n required,\n disabled,\n onBlur,\n };\n\n let body: ReactElement;\n\n switch (control) {\n case 'select':\n body = (\n <Select\n {...common}\n hint={fieldHint}\n options={options.map((option) => ({\n value: option.value,\n label: option.label,\n ...(option.disabled ? { disabled: true } : {}),\n }))}\n placeholder={placeholder ?? undefined}\n value={value}\n autoComplete={autoComplete}\n onValueChange={(next) => onValueChange?.(String(next))}\n />\n );\n break;\n\n case 'textarea':\n body = (\n <Textarea\n {...common}\n hint={fieldHint}\n placeholder={placeholder ?? undefined}\n maxLength={maxLength ?? undefined}\n value={value}\n onValueChange={onValueChange}\n />\n );\n break;\n\n case 'password':\n body = (\n <Password\n {...common}\n hint={fieldHint}\n leadingIcon={leadingIcon ?? undefined}\n value={value}\n autocomplete={'new-password' === autoComplete ? 'new-password' : 'current-password'}\n onValueChange={onValueChange}\n />\n );\n break;\n\n case 'checkbox':\n body = (\n <Checkbox\n {...common}\n description={fieldHint}\n checked={checked}\n onCheckedChange={onCheckedChange}\n />\n );\n break;\n\n default:\n body = (\n <Input\n {...common}\n type={type}\n hint={fieldHint}\n placeholder={placeholder ?? undefined}\n leadingIcon={leadingIcon ?? undefined}\n value={value}\n autoComplete={autoComplete}\n inputMode={inputMode}\n maxLength={maxLength ?? undefined}\n onValueChange={onValueChange}\n />\n );\n }\n\n return (\n <div className=\"ec-field\" data-ec-field={id} data-field-key={key ?? undefined}>\n {body}\n </div>\n );\n}\n"],"mappings":";;;;;AAYA,SAAS,UAAqC;AAC9C,SAAS,UAAU,OAAO,UAAU,QAAQ,gBAAgB;AAuEtD,mBAEE,KAFF;AAjCC,SAAS,MAAM;AAAA,EACpB;AAAA,EACA,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU,CAAC;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa,CAAC;AAChB,GAA6B;AAC3B,QAAM,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AACH,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ,MAAM;AAAA,UACN,aAAa,eAAe;AAAA,UAC5B;AAAA,UACA,cAAc,mBAAmB,eAAe,iBAAiB;AAAA,UACjE;AAAA;AAAA,MACF;AAEF;AAAA,IAEF,KAAK;AACH,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ,aAAa;AAAA,UACb;AAAA,UACA;AAAA;AAAA,MACF;AAEF;AAAA,IAEF;AACE,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ;AAAA,UACA,MAAM;AAAA,UACN,aAAa,eAAe;AAAA,UAC5B,aAAa,eAAe;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,WAAW,aAAa;AAAA,UACxB;AAAA;AAAA,MACF;AAAA,EAEN;AAEA,SACE,oBAAC,SAAI,WAAU,YAAW,iBAAe,IAAI,kBAAgB,OAAO,QACjE,gBACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useStorefrontRouter
|
|
3
|
+
} from "./chunk-TPOKMH5E.mjs";
|
|
4
|
+
import {
|
|
5
|
+
isSameOrigin,
|
|
6
|
+
showResponseToasts,
|
|
7
|
+
useStorefrontPage
|
|
8
|
+
} from "./chunk-VX5TEJNU.mjs";
|
|
9
|
+
|
|
10
|
+
// src/product/support.ts
|
|
11
|
+
import { formatMoney } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
12
|
+
import { router } from "@inertiajs/react";
|
|
13
|
+
import { useCallback, useState } from "react";
|
|
14
|
+
var PURCHASE_ERROR_BAG = "purchase";
|
|
15
|
+
var REVIEW_ERROR_BAG = "review";
|
|
16
|
+
var PURCHASE_RELOAD = [
|
|
17
|
+
"ecommerceStorefront",
|
|
18
|
+
"ecommerceStorefrontCart",
|
|
19
|
+
"feedback",
|
|
20
|
+
"stock",
|
|
21
|
+
"soldOut"
|
|
22
|
+
];
|
|
23
|
+
var PURCHASE_SUCCESS_RELOAD = ["form"];
|
|
24
|
+
function useErrorBag(bag) {
|
|
25
|
+
const errors = useStorefrontPage().props.errors;
|
|
26
|
+
const bagged = null !== errors && "object" === typeof errors ? errors[bag] : void 0;
|
|
27
|
+
return null !== bagged && "object" === typeof bagged ? bagged : {};
|
|
28
|
+
}
|
|
29
|
+
function csrfToken() {
|
|
30
|
+
if ("undefined" === typeof document) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return document.querySelector('meta[name="csrf-token"]')?.content ?? null;
|
|
34
|
+
}
|
|
35
|
+
async function requestJson(url, body, signal) {
|
|
36
|
+
const headers = {
|
|
37
|
+
Accept: "application/json",
|
|
38
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
39
|
+
};
|
|
40
|
+
const token = csrfToken();
|
|
41
|
+
if (void 0 !== body) {
|
|
42
|
+
headers["Content-Type"] = "application/json";
|
|
43
|
+
}
|
|
44
|
+
if (null !== token && isSameOrigin(url)) {
|
|
45
|
+
headers["X-CSRF-TOKEN"] = token;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
method: void 0 === body ? "GET" : "POST",
|
|
50
|
+
headers,
|
|
51
|
+
body: void 0 === body ? void 0 : JSON.stringify(body),
|
|
52
|
+
credentials: "same-origin",
|
|
53
|
+
signal
|
|
54
|
+
});
|
|
55
|
+
if (429 === response.status) {
|
|
56
|
+
showResponseToasts(await response.json().catch(() => null));
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return response.ok ? await response.json() : null;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function linePrice(unit, quantity, locale) {
|
|
65
|
+
if (null === unit || null === unit.amount || null === quantity || quantity < 1) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return formatMoney(unit.amount * quantity, unit.currency, locale);
|
|
69
|
+
}
|
|
70
|
+
function useStorefrontPost(bag) {
|
|
71
|
+
const [processing, setProcessing] = useState(false);
|
|
72
|
+
const visits = useStorefrontRouter();
|
|
73
|
+
const post = useCallback(
|
|
74
|
+
(url, data, only = PURCHASE_RELOAD, onSuccess) => {
|
|
75
|
+
visits.post(url, data, {
|
|
76
|
+
errorBag: bag,
|
|
77
|
+
only,
|
|
78
|
+
preserveScroll: true,
|
|
79
|
+
preserveState: true,
|
|
80
|
+
onStart: () => setProcessing(true),
|
|
81
|
+
onFinish: () => setProcessing(false),
|
|
82
|
+
onSuccess: () => {
|
|
83
|
+
if (only === PURCHASE_RELOAD) {
|
|
84
|
+
visits.reload({ only: PURCHASE_SUCCESS_RELOAD });
|
|
85
|
+
}
|
|
86
|
+
onSuccess?.();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
[bag, visits]
|
|
91
|
+
);
|
|
92
|
+
return { post, processing };
|
|
93
|
+
}
|
|
94
|
+
function visitWithQuery(currentUrl, query, only, visits = router) {
|
|
95
|
+
const base = "undefined" !== typeof window ? window.location.origin : "http://localhost";
|
|
96
|
+
const url = new URL(currentUrl, base);
|
|
97
|
+
for (const [key, value] of Object.entries(query)) {
|
|
98
|
+
if (null === value) {
|
|
99
|
+
url.searchParams.delete(key);
|
|
100
|
+
} else {
|
|
101
|
+
url.searchParams.set(key, String(value));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
visits.get(
|
|
105
|
+
url.pathname + url.search + url.hash,
|
|
106
|
+
{},
|
|
107
|
+
{
|
|
108
|
+
only,
|
|
109
|
+
preserveScroll: true,
|
|
110
|
+
preserveState: true,
|
|
111
|
+
replace: true
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
PURCHASE_ERROR_BAG,
|
|
118
|
+
REVIEW_ERROR_BAG,
|
|
119
|
+
PURCHASE_RELOAD,
|
|
120
|
+
PURCHASE_SUCCESS_RELOAD,
|
|
121
|
+
useErrorBag,
|
|
122
|
+
requestJson,
|
|
123
|
+
linePrice,
|
|
124
|
+
useStorefrontPost,
|
|
125
|
+
visitWithQuery
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=chunk-Y2IOBBN7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/product/support.ts"],"sourcesContent":["/**\n * Shared plumbing for the product page, its purchase forms and sections:\n * the JSON calls (purchase form redraws, recently viewed), the Inertia\n * error bags that keep the form's and the review form's errors apart, and\n * the posts that add to the cart.\n *\n * @since 1.0.0\n */\n\nimport { formatMoney, type StorefrontMoney } from '@artisanpack-ui/ecommerce-storefront-core';\nimport { router } from '@inertiajs/react';\nimport { useCallback, useState } from 'react';\n\nimport { useStorefrontRouter, type StorefrontRouter } from '../internal/storefrontRouter';\n\nimport { isSameOrigin } from '../internal/sameOrigin';\nimport { showResponseToasts } from '../toasts';\nimport { useStorefrontPage } from '../useStorefront';\n\n/**\n * The error bag the purchase form and the \"Notify me\" signup post with.\n *\n * Livewire scoped each component's errors to it; Inertia shares one\n * `errors` prop per page, so the product page's forms each post with an\n * error bag (`X-Inertia-Error-Bag`) and read only their own.\n *\n * @since 1.0.0\n */\nexport const PURCHASE_ERROR_BAG = 'purchase';\n\n/**\n * The error bag the review form posts with.\n *\n * @since 1.0.0\n */\nexport const REVIEW_ERROR_BAG = 'review';\n\n/**\n * The props a write on the product page reloads: the shared props (the\n * header count, toasts and `cart.open`), the cart drawer, and the page's\n * own props the write can change.\n *\n * Not the purchase form (`form`): a write that fails validation redirects\n * back with these props, and a freshly presented form would replace what\n * the shopper chose and typed. {@link PURCHASE_SUCCESS_RELOAD} reloads it\n * after a write that worked.\n *\n * @since 1.0.0\n */\nexport const PURCHASE_RELOAD = [\n 'ecommerceStorefront',\n 'ecommerceStorefrontCart',\n 'feedback',\n 'stock',\n 'soldOut',\n];\n\n/**\n * The props reloaded after a product page write that worked: the purchase\n * form, presented again for the stock and cart the add left.\n *\n * @since 1.0.0\n */\nexport const PURCHASE_SUCCESS_RELOAD = ['form'];\n\n/**\n * The errors in one error bag of the page's `errors` prop.\n *\n * @since 1.0.0\n *\n * @param bag - The bag's name.\n * @returns The bag's errors, keyed by field.\n */\nexport function useErrorBag(bag: string): Record<string, string> {\n const errors = useStorefrontPage().props.errors as Record<string, unknown> | null | undefined;\n const bagged = null !== errors && 'object' === typeof errors ? errors[bag] : undefined;\n\n return null !== bagged && 'object' === typeof bagged ? (bagged as Record<string, string>) : {};\n}\n\n/**\n * The CSRF token the root view puts in `<meta name=\"csrf-token\">`.\n *\n * @returns The token, or null outside a browser or without the tag.\n */\nfunction csrfToken(): string | null {\n if ('undefined' === typeof document) {\n return null;\n }\n\n return document.querySelector<HTMLMetaElement>('meta[name=\"csrf-token\"]')?.content ?? null;\n}\n\n/**\n * Sends a JSON request to one of the storefront's JSON routes.\n *\n * A throttled answer (429) shows the toasts it carries and resolves null,\n * as does any other failure.\n *\n * @since 1.0.0\n *\n * @param url - The route's URL.\n * @param body - The JSON body for a POST, or undefined for a GET.\n * @param signal - Aborts the request.\n * @returns The decoded JSON, or null.\n */\nexport async function requestJson<T>(\n url: string,\n body?: unknown,\n signal?: AbortSignal,\n): Promise<T | null> {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'X-Requested-With': 'XMLHttpRequest',\n };\n const token = csrfToken();\n\n if (undefined !== body) {\n headers['Content-Type'] = 'application/json';\n }\n\n // The token only goes to this site, never to a URL a prop or a satellite\n // pointed elsewhere.\n if (null !== token && isSameOrigin(url)) {\n headers['X-CSRF-TOKEN'] = token;\n }\n\n try {\n const response = await fetch(url, {\n method: undefined === body ? 'GET' : 'POST',\n headers,\n body: undefined === body ? undefined : JSON.stringify(body),\n credentials: 'same-origin',\n signal,\n });\n\n if (429 === response.status) {\n showResponseToasts(await response.json().catch(() => null));\n\n return null;\n }\n\n return response.ok ? ((await response.json()) as T) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * A unit price times a quantity, formatted in the shopper's locale.\n *\n * @since 1.0.0\n *\n * @param unit - One unit's price.\n * @param quantity - How many.\n * @param locale - The locale.\n * @returns The line price, or null without a price or a quantity.\n */\nexport function linePrice(\n unit: StorefrontMoney | null,\n quantity: number | null,\n locale: string,\n): string | null {\n if (null === unit || null === unit.amount || null === quantity || quantity < 1) {\n return null;\n }\n\n return formatMoney(unit.amount * quantity, unit.currency, locale);\n}\n\n/**\n * Posts a write from the product page with Inertia, in an error bag,\n * keeping the page's state and scroll.\n *\n * @since 1.0.0\n *\n * @param bag - The error bag.\n * @returns `post(url, data, only?, onSuccess?)` and whether a post is running.\n */\nexport function useStorefrontPost(bag: string): {\n post: (\n url: string,\n data: Record<string, unknown>,\n only?: string[],\n onSuccess?: () => void,\n ) => void;\n processing: boolean;\n} {\n const [processing, setProcessing] = useState(false);\n const visits = useStorefrontRouter();\n\n const post = useCallback(\n (\n url: string,\n data: Record<string, unknown>,\n only: string[] = PURCHASE_RELOAD,\n onSuccess?: () => void,\n ): void => {\n visits.post(url, data, {\n errorBag: bag,\n only,\n preserveScroll: true,\n preserveState: true,\n onStart: () => setProcessing(true),\n onFinish: () => setProcessing(false),\n onSuccess: () => {\n // A write that worked presents the purchase form again (see\n // PURCHASE_RELOAD); a failed one keeps the shopper's input.\n if (only === PURCHASE_RELOAD) {\n visits.reload({ only: PURCHASE_SUCCESS_RELOAD });\n }\n\n onSuccess?.();\n },\n });\n },\n [bag, visits],\n );\n\n return { post, processing };\n}\n\n/**\n * Visits the current page again with changed query parameters, reloading\n * only some props (the reviews filter and page).\n *\n * @since 1.0.0\n *\n * @param currentUrl - The page's URL, as Inertia has it.\n * @param query - Parameters to set; null removes one.\n * @param only - The props to reload.\n * @param visits - The router to visit with (a block's, from `useStorefrontRouter()`); Inertia's by default.\n */\nexport function visitWithQuery(\n currentUrl: string,\n query: Record<string, string | number | null>,\n only: string[],\n visits: StorefrontRouter = router as unknown as StorefrontRouter,\n): void {\n const base = 'undefined' !== typeof window ? window.location.origin : 'http://localhost';\n const url = new URL(currentUrl, base);\n\n for (const [key, value] of Object.entries(query)) {\n if (null === value) {\n url.searchParams.delete(key);\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n\n visits.get(\n url.pathname + url.search + url.hash,\n {},\n {\n only,\n preserveScroll: true,\n preserveState: true,\n replace: true,\n },\n );\n}\n"],"mappings":";;;;;;;;;;AASA,SAAS,mBAAyC;AAClD,SAAS,cAAc;AACvB,SAAS,aAAa,gBAAgB;AAiB/B,IAAM,qBAAqB;AAO3B,IAAM,mBAAmB;AAczB,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,IAAM,0BAA0B,CAAC,MAAM;AAUvC,SAAS,YAAY,KAAqC;AAC/D,QAAM,SAAS,kBAAkB,EAAE,MAAM;AACzC,QAAM,SAAS,SAAS,UAAU,aAAa,OAAO,SAAS,OAAO,GAAG,IAAI;AAE7E,SAAO,SAAS,UAAU,aAAa,OAAO,SAAU,SAAoC,CAAC;AAC/F;AAOA,SAAS,YAA2B;AAClC,MAAI,gBAAgB,OAAO,UAAU;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,SAAS,cAA+B,yBAAyB,GAAG,WAAW;AACxF;AAeA,eAAsB,YACpB,KACA,MACA,QACmB;AACnB,QAAM,UAAkC;AAAA,IACtC,QAAQ;AAAA,IACR,oBAAoB;AAAA,EACtB;AACA,QAAM,QAAQ,UAAU;AAExB,MAAI,WAAc,MAAM;AACtB,YAAQ,cAAc,IAAI;AAAA,EAC5B;AAIA,MAAI,SAAS,SAAS,aAAa,GAAG,GAAG;AACvC,YAAQ,cAAc,IAAI;AAAA,EAC5B;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ,WAAc,OAAO,QAAQ;AAAA,MACrC;AAAA,MACA,MAAM,WAAc,OAAO,SAAY,KAAK,UAAU,IAAI;AAAA,MAC1D,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