@drawbridge/components 0.1.47 → 0.1.48

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.
Files changed (114) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain.js +1 -0
  10. package/dist/bridge/form-subdomain.mjs +2 -1
  11. package/dist/bridge/lib/age-gate.js +12 -0
  12. package/dist/bridge/lib/age-gate.mjs +11 -0
  13. package/dist/bridge/lib/cart.js +79 -0
  14. package/dist/bridge/lib/cart.mjs +48 -0
  15. package/dist/bridge/lib/checkout-kit.js +2 -32
  16. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  17. package/dist/bridge/product-tile.js +9 -6
  18. package/dist/bridge/product-tile.mjs +9 -6
  19. package/dist/bridge/template-layout.js +237 -122
  20. package/dist/bridge/template-layout.mjs +237 -122
  21. package/dist/bridge/template-modal.js +28 -73
  22. package/dist/bridge/template-modal.mjs +29 -74
  23. package/dist/dashboard/buttons-subscription.js +1 -1
  24. package/dist/dashboard/buttons-subscription.mjs +1 -1
  25. package/dist/dashboard/campaign-form.js +7 -2
  26. package/dist/dashboard/campaign-form.mjs +7 -2
  27. package/dist/dashboard/card-order.js +22 -4
  28. package/dist/dashboard/card-order.mjs +22 -4
  29. package/dist/dashboard/embed-stripe.js +145 -0
  30. package/dist/dashboard/embed-stripe.mjs +116 -0
  31. package/dist/dashboard/form-admin-provider.js +71 -17
  32. package/dist/dashboard/form-admin-provider.mjs +71 -17
  33. package/dist/dashboard/form-file-upload.js +3 -2
  34. package/dist/dashboard/form-file-upload.mjs +4 -3
  35. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  36. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  37. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  38. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  39. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  40. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  41. package/dist/dashboard/form-organization-campaign.js +82 -0
  42. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  43. package/dist/dashboard/form-organization-connection.js +48 -6
  44. package/dist/dashboard/form-organization-connection.mjs +48 -7
  45. package/dist/dashboard/form-organization-product.js +1461 -0
  46. package/dist/dashboard/form-organization-product.mjs +1425 -0
  47. package/dist/dashboard/form-organization-workflow.js +72 -1
  48. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  49. package/dist/dashboard/form-otc.js +4 -5
  50. package/dist/dashboard/form-otc.mjs +4 -5
  51. package/dist/dashboard/form-stripe.js +12 -5
  52. package/dist/dashboard/form-stripe.mjs +12 -5
  53. package/dist/dashboard/input-fields.js +11 -158
  54. package/dist/dashboard/input-fields.mjs +11 -158
  55. package/dist/dashboard/input-file.js +21 -4
  56. package/dist/dashboard/input-file.mjs +21 -4
  57. package/dist/dashboard/input-gallery.js +201 -0
  58. package/dist/dashboard/input-gallery.mjs +172 -0
  59. package/dist/dashboard/lib/connection-controls.js +5 -2
  60. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  61. package/dist/dashboard/lib/form-page.js +1 -1
  62. package/dist/dashboard/lib/form-page.mjs +1 -1
  63. package/dist/dashboard/lib/products.js +169 -0
  64. package/dist/dashboard/lib/products.mjs +135 -0
  65. package/dist/dashboard/lib/settings-paths.js +35 -0
  66. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  67. package/dist/dashboard/lib/uppy.js +10 -1
  68. package/dist/dashboard/lib/uppy.mjs +11 -2
  69. package/dist/dashboard/order-sections.js +456 -6
  70. package/dist/dashboard/order-sections.mjs +453 -7
  71. package/dist/dashboard/provider-ui.js +9 -7
  72. package/dist/dashboard/provider-ui.mjs +9 -7
  73. package/dist/dashboard/shipping-rates.js +404 -0
  74. package/dist/dashboard/shipping-rates.mjs +371 -0
  75. package/dist/dashboard/template-buyer.js +301 -0
  76. package/dist/dashboard/template-buyer.mjs +267 -0
  77. package/dist/input-checkbox.js +28 -10
  78. package/dist/input-checkbox.mjs +28 -10
  79. package/dist/product.js +96 -24
  80. package/dist/product.mjs +97 -25
  81. package/dist/shared/lib/helpers.js +54 -6
  82. package/dist/shared/lib/helpers.mjs +53 -8
  83. package/dist/shared/order-summary.js +139 -0
  84. package/dist/shared/order-summary.mjs +110 -0
  85. package/package.json +74 -4
  86. package/types/bridge/cart-drawer.d.ts +31 -0
  87. package/types/bridge/fields.d.ts +14 -2
  88. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  89. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  90. package/types/bridge/lib/age-gate.d.ts +5 -0
  91. package/types/bridge/lib/cart.d.ts +44 -0
  92. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  93. package/types/dashboard/card-order.d.ts +6 -0
  94. package/types/dashboard/embed-stripe.d.ts +25 -0
  95. package/types/dashboard/form-admin-provider.d.ts +9 -2
  96. package/types/dashboard/form-file-upload.d.ts +2 -1
  97. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  98. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  99. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  100. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  101. package/types/dashboard/form-organization-connection.d.ts +11 -0
  102. package/types/dashboard/form-organization-product.d.ts +24 -0
  103. package/types/dashboard/form-otc.d.ts +5 -1
  104. package/types/dashboard/form-stripe.d.ts +3 -2
  105. package/types/dashboard/input-file.d.ts +2 -0
  106. package/types/dashboard/input-gallery.d.ts +14 -0
  107. package/types/dashboard/lib/products.d.ts +14 -0
  108. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  109. package/types/dashboard/order-sections.d.ts +24 -1
  110. package/types/dashboard/shipping-rates.d.ts +26 -0
  111. package/types/dashboard/template-buyer.d.ts +50 -0
  112. package/types/input-checkbox.d.ts +2 -0
  113. package/types/shared/lib/helpers.d.ts +4 -0
  114. package/types/shared/order-summary.d.ts +19 -0
@@ -16,10 +16,26 @@ import Link from "next/link";
16
16
  import { request } from "@drawbridge/drawbridge-utils/fetch";
17
17
  import constants from "./lib/constants.mjs";
18
18
  import { checkout as checkoutKit, ensureCheckoutKit } from "./lib/checkout-kit.mjs";
19
+ import { cartAlive, cartCount as countOf, cartKey, withQuantity } from "./lib/cart.mjs";
19
20
  import { useTracking } from "./provider-analytics.mjs";
20
21
  import { afterOrder, awardingOn, buttonText, copy, formOn, previewStep } from "./lib/entry.mjs";
21
22
  import { leadEndpoint } from "./lib/url.mjs";
22
23
  const TemplateModal = dynamic(() => import("./template-modal.mjs"), { ssr: false });
24
+ const CartDrawer = dynamic(() => import("./cart-drawer.mjs"), { ssr: false });
25
+ const stored = (key) => {
26
+ try {
27
+ return JSON.parse(window.localStorage.getItem(key) || "null");
28
+ } catch {
29
+ return null;
30
+ }
31
+ };
32
+ const store = (key, value) => {
33
+ try {
34
+ if (value) window.localStorage.setItem(key, JSON.stringify(value));
35
+ else window.localStorage.removeItem(key);
36
+ } catch {
37
+ }
38
+ };
23
39
  const TemplateLayout = ({
24
40
  params,
25
41
  result,
@@ -44,6 +60,11 @@ const TemplateLayout = ({
44
60
  const style = data == null ? void 0 : data.style;
45
61
  const [cart, setCart] = useState(null);
46
62
  const [cartLoading, setCartLoading] = useState(true);
63
+ const [drawer, setDrawer] = useState({ open: false, pay: null });
64
+ const [drawerOpened, setDrawerOpened] = useState(false);
65
+ const [cut, setCut] = useState([]);
66
+ const [submitted, setSubmitted] = useState(null);
67
+ const leadCode = searchParams.get("m");
47
68
  const [modal, setModal] = useState(Boolean(submissionId));
48
69
  const [opened, setOpened] = useState(Boolean(submissionId));
49
70
  const [panel, setPanel] = useState(submissionId ? {
@@ -62,45 +83,86 @@ const TemplateLayout = ({
62
83
  name: null,
63
84
  data: {}
64
85
  });
65
- const cartCount = useMemo(
66
- () => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + (line.quantity || 0), 0),
67
- [cart]
68
- );
86
+ const cartCount = countOf(cart);
69
87
  const cartRoot = "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart";
70
- const cartStorageKey = "cart:" + (params == null ? void 0 : params.subdomain);
71
- const checkout = useCallback(
72
- (args = {}) => checkoutKit({
73
- affiliate,
74
- campaign: data == null ? void 0 : data.campaign,
75
- onComplete: () => {
76
- if (typeof window !== "undefined") {
77
- window.localStorage.removeItem(cartStorageKey);
78
- window.localStorage.removeItem(cartStorageKey + "_expiry");
79
- }
80
- ;
88
+ const cartStorageKey = cartKey({ campaign: result == null ? void 0 : result.campaign, subdomain: params == null ? void 0 : params.subdomain });
89
+ const who = useMemo(
90
+ () => ({
91
+ ...affiliate && { affiliate },
92
+ ...leadCode && { code: leadCode },
93
+ ...(data == null ? void 0 : data.page) && { page: data.page },
94
+ ...submitted && { submission: submitted }
95
+ }),
96
+ [affiliate, data == null ? void 0 : data.page, leadCode, submitted]
97
+ );
98
+ const openDrawer = useCallback(
99
+ (pay = null) => {
100
+ setDrawerOpened(true);
101
+ setDrawer({ open: true, pay });
102
+ },
103
+ []
104
+ );
105
+ const closeDrawer = useCallback(() => setDrawer((current) => ({ ...current, open: false })), []);
106
+ const paid = useCallback(
107
+ (id) => {
108
+ if (!id || id === (cart == null ? void 0 : cart.id)) {
109
+ store(cartStorageKey, null);
81
110
  setCart(null);
82
- setPanel({
83
- name: "purchase",
84
- data: {
85
- message: copy(data, "purchase")
86
- }
87
- });
88
- setModal(true);
111
+ setCut([]);
112
+ }
113
+ ;
114
+ setDrawer({ open: false, pay: null });
115
+ setPanel({
116
+ name: "purchase",
117
+ data: {
118
+ message: copy(data, "purchase")
119
+ }
120
+ });
121
+ setModal(true);
122
+ },
123
+ [cart == null ? void 0 : cart.id, cartStorageKey, data]
124
+ );
125
+ const storeCheckout = useCallback(
126
+ (paying) => checkoutKit({
127
+ checkoutUrl: paying == null ? void 0 : paying.checkoutUrl,
128
+ onComplete: () => paid(paying == null ? void 0 : paying.id),
129
+ onOpen: () => {
130
+ setModal(false);
131
+ closeDrawer();
89
132
  },
90
- onOpen: () => setModal(false),
91
- onRedirect: redirectToCheckout,
92
- organization: data == null ? void 0 : data.organization,
93
- page: data == null ? void 0 : data.page,
94
- slug: params == null ? void 0 : params.slug,
95
- subdomain: params == null ? void 0 : params.subdomain,
96
- ...args
133
+ onRedirect: redirectToCheckout
97
134
  }),
98
- [affiliate, cartStorageKey, data, params == null ? void 0 : params.slug, params == null ? void 0 : params.subdomain, redirectToCheckout]
135
+ [closeDrawer, paid, redirectToCheckout]
136
+ );
137
+ const startCheckout = useCallback(
138
+ (paying) => (paying == null ? void 0 : paying.checkoutUrl) ? storeCheckout(paying) : openDrawer(paying),
139
+ [openDrawer, storeCheckout]
140
+ );
141
+ const checkout = useCallback(
142
+ async (args = {}) => {
143
+ var _a2;
144
+ if (!args.lines) return args.checkoutUrl ? storeCheckout({ checkoutUrl: args.checkoutUrl }) : null;
145
+ const response = await request({
146
+ body: {
147
+ ...who,
148
+ ...args.advertisement && { advertisement: args.advertisement },
149
+ lines: args.lines
150
+ },
151
+ endpoint: cartRoot,
152
+ method: "POST"
153
+ });
154
+ if (!((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id)) return null;
155
+ setModal(false);
156
+ startCheckout(response.result);
157
+ return response.result;
158
+ },
159
+ [cartRoot, startCheckout, storeCheckout, who]
99
160
  );
100
161
  const openCheckout = useCallback(
101
162
  (checkoutUrl) => checkout({ checkoutUrl }),
102
163
  [checkout]
103
164
  );
165
+ if (drawer.open && !drawerOpened) setDrawerOpened(true);
104
166
  if ((modal || (panel == null ? void 0 : panel.name)) && !opened) setOpened(true);
105
167
  useEffect(
106
168
  () => {
@@ -140,140 +202,138 @@ const TemplateLayout = ({
140
202
  useEffect(
141
203
  () => {
142
204
  if (typeof window === "undefined") return;
143
- const cartId = window.localStorage.getItem(cartStorageKey);
144
- const cartExpiry = window.localStorage.getItem(cartStorageKey + "_expiry");
145
- const expired = !cartExpiry || Date.now() - Number(cartExpiry) > 864e5;
146
- if (!cartId || expired) {
147
- if (cartId && expired) {
148
- window.localStorage.removeItem(cartStorageKey);
149
- window.localStorage.removeItem(cartStorageKey + "_expiry");
150
- }
151
- ;
205
+ const kept = stored(cartStorageKey);
206
+ if (!(kept == null ? void 0 : kept.id) || !cartAlive(kept.made)) {
207
+ if (kept) store(cartStorageKey, null);
152
208
  setCartLoading(false);
153
209
  return;
154
210
  }
155
211
  ;
156
212
  request({
157
- endpoint: cartRoot + "?cartId=" + encodeURIComponent(cartId),
213
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(kept.id),
158
214
  method: "GET"
159
215
  }).then(({ result: result2 }) => {
160
216
  if (result2 == null ? void 0 : result2.id) {
161
217
  setCart(result2);
162
218
  } else {
163
- window.localStorage.removeItem(cartStorageKey);
164
- window.localStorage.removeItem(cartStorageKey + "_expiry");
219
+ store(cartStorageKey, null);
165
220
  }
166
221
  ;
167
222
  }).catch(() => {
168
- window.localStorage.removeItem(cartStorageKey);
169
- window.localStorage.removeItem(cartStorageKey + "_expiry");
223
+ store(cartStorageKey, null);
170
224
  }).finally(() => {
171
225
  setCartLoading(false);
172
226
  });
173
227
  },
174
228
  [cartRoot, cartStorageKey]
175
229
  );
230
+ const linkedCart = searchParams.get("drwbrdg_cart");
231
+ useEffect(
232
+ () => {
233
+ if (!linkedCart) return;
234
+ request({
235
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(linkedCart),
236
+ method: "GET"
237
+ }).then(({ result: result2 }) => {
238
+ var _a2;
239
+ if ((result2 == null ? void 0 : result2.id) && ((_a2 = result2.lines) == null ? void 0 : _a2.length)) startCheckout(result2);
240
+ }).catch(() => {
241
+ });
242
+ },
243
+ // Once per cart named: startCheckout changes with the page's cart.
244
+ // eslint-disable-next-line react-hooks/exhaustive-deps
245
+ [cartRoot, linkedCart]
246
+ );
176
247
  const onAddToCart = useCallback(
177
248
  async ({ variant }) => {
178
249
  var _a2;
179
- const attributes = [
180
- ...(data == null ? void 0 : data.campaign) ? [{ key: "_drwbrdg_ca", value: data.campaign }] : [],
181
- ...(data == null ? void 0 : data.organization) ? [{ key: "_drwbrdg_or", value: data.organization }] : [],
182
- ...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
183
- ...(data == null ? void 0 : data.page) ? [{ key: "_drwbrdg_pg", value: data.page }] : []
184
- ];
185
250
  const line = {
186
- attributes,
187
251
  merchandiseId: variant.id,
188
252
  quantity: 1
189
253
  };
254
+ const create = () => request({
255
+ body: {
256
+ ...who,
257
+ lines: [line]
258
+ },
259
+ endpoint: cartRoot,
260
+ method: "POST"
261
+ });
190
262
  let response;
191
263
  if (cart == null ? void 0 : cart.id) {
192
264
  try {
193
265
  response = await request({
194
266
  body: {
267
+ ...who,
195
268
  cartId: cart.id,
196
269
  lines: [line]
197
270
  },
198
271
  endpoint: cartRoot + "/lines",
199
272
  method: "POST"
200
273
  });
201
- } catch {
202
- response = await request({
203
- body: {
204
- lines: [line]
205
- },
206
- endpoint: cartRoot,
207
- method: "POST"
208
- });
274
+ } catch (error) {
275
+ if ((error == null ? void 0 : error.status) === 400) throw error;
276
+ response = await create();
209
277
  }
210
278
  } else {
211
- response = await request({
212
- body: {
213
- lines: [line]
214
- },
215
- endpoint: cartRoot,
216
- method: "POST"
217
- });
279
+ response = await create();
218
280
  }
219
281
  ;
220
282
  if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
221
- if (typeof window !== "undefined") {
222
- window.localStorage.setItem(cartStorageKey, response.result.id);
223
- window.localStorage.setItem(cartStorageKey + "_expiry", String(Date.now()));
224
- }
225
- ;
283
+ if (response.result.id !== (cart == null ? void 0 : cart.id)) store(cartStorageKey, { id: response.result.id, made: Date.now() });
226
284
  setCart(response.result);
227
- setModal(true);
285
+ setCut([]);
286
+ setModal(false);
287
+ openDrawer();
228
288
  }
229
289
  ;
230
290
  return response == null ? void 0 : response.result;
231
291
  },
232
- [affiliate, cart, cartRoot, cartStorageKey, data]
292
+ [cart, cartRoot, cartStorageKey, openDrawer, who]
233
293
  );
234
- const onCartLineUpdate = useCallback(
235
- async (lineId, quantity) => {
294
+ const changeLine = useCallback(
295
+ async (lineId, quantity, send) => {
236
296
  var _a2;
237
297
  if (!(cart == null ? void 0 : cart.id)) return;
238
- const response = await request({
239
- body: {
240
- cartId: cart.id,
241
- lines: [
242
- {
243
- id: lineId,
244
- quantity
245
- }
246
- ]
247
- },
248
- endpoint: cartRoot + "/lines",
249
- method: "PUT"
250
- });
251
- if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
298
+ const before = cart;
299
+ setCart(withQuantity(cart, lineId, quantity));
300
+ try {
301
+ const response = await send();
302
+ if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
303
+ } catch (error) {
304
+ setCart(before);
305
+ throw error;
306
+ }
252
307
  },
253
- [cart, cartRoot]
308
+ [cart]
309
+ );
310
+ const onCartLineUpdate = useCallback(
311
+ (lineId, quantity) => changeLine(lineId, quantity, () => request({
312
+ body: {
313
+ ...who,
314
+ cartId: cart == null ? void 0 : cart.id,
315
+ lines: [
316
+ {
317
+ id: lineId,
318
+ quantity
319
+ }
320
+ ]
321
+ },
322
+ endpoint: cartRoot + "/lines",
323
+ method: "PUT"
324
+ })),
325
+ [cart == null ? void 0 : cart.id, cartRoot, changeLine, who]
254
326
  );
255
327
  const onCartLineRemove = useCallback(
256
- async (lineId) => {
257
- var _a2, _b2;
258
- if (!(cart == null ? void 0 : cart.id)) return;
259
- const response = await request({
260
- body: {
261
- cartId: cart.id,
262
- lineIds: [lineId]
263
- },
264
- endpoint: cartRoot + "/lines",
265
- method: "DELETE"
266
- });
267
- if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
268
- setCart(response.result);
269
- if (!((_b2 = response.result.lines) == null ? void 0 : _b2.length) && typeof window !== "undefined") {
270
- window.localStorage.removeItem(cartStorageKey);
271
- }
272
- ;
273
- }
274
- ;
275
- },
276
- [cart, cartRoot, cartStorageKey]
328
+ (lineId) => changeLine(lineId, 0, () => request({
329
+ body: {
330
+ cartId: cart == null ? void 0 : cart.id,
331
+ lineIds: [lineId]
332
+ },
333
+ endpoint: cartRoot + "/lines",
334
+ method: "DELETE"
335
+ })),
336
+ [cart == null ? void 0 : cart.id, cartRoot, changeLine]
277
337
  );
278
338
  const tracking = useTracking({
279
339
  params,
@@ -380,8 +440,21 @@ const TemplateLayout = ({
380
440
  }
381
441
  });
382
442
  setModal(true);
443
+ if (id) {
444
+ setSubmitted(id);
445
+ if (cart == null ? void 0 : cart.id) request({
446
+ body: {
447
+ cartId: cart.id,
448
+ submission: id
449
+ },
450
+ endpoint: cartRoot,
451
+ method: "PUT"
452
+ }).catch(() => {
453
+ });
454
+ }
455
+ ;
383
456
  },
384
- [affiliate, data, params, preview, style]
457
+ [affiliate, cart == null ? void 0 : cart.id, cartRoot, data, params, preview, style]
385
458
  );
386
459
  const leadMission = searchParams.get("open");
387
460
  const leadUrl = submissionId ? null : leadEndpoint({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
@@ -454,7 +527,7 @@ const TemplateLayout = ({
454
527
  return {
455
528
  branding: branding(),
456
529
  brandingCompact: branding(true),
457
- close: (name) => {
530
+ close: (name, onClose) => {
458
531
  var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
459
532
  return /* @__PURE__ */ jsx(
460
533
  Button,
@@ -463,7 +536,7 @@ const TemplateLayout = ({
463
536
  "aria-label": "Close Modal",
464
537
  inline: true,
465
538
  onClick: () => {
466
- setModal(false);
539
+ (onClose || (() => setModal(false)))();
467
540
  tracking.track({
468
541
  name: "button-" + name + "-close"
469
542
  });
@@ -614,10 +687,7 @@ const TemplateLayout = ({
614
687
  "aria-label": "Open Shop",
615
688
  inline: true,
616
689
  onClick: () => {
617
- setPanel({
618
- name
619
- });
620
- setModal(true);
690
+ openDrawer();
621
691
  tracking.track({
622
692
  name: "button-" + name + "-open"
623
693
  });
@@ -671,7 +741,7 @@ const TemplateLayout = ({
671
741
  }
672
742
  };
673
743
  },
674
- [cartCount, cartLoading, data, face, preview, style, tracking]
744
+ [cartCount, cartLoading, data, face, openDrawer, preview, style, tracking]
675
745
  );
676
746
  const props = {
677
747
  affiliate,
@@ -723,20 +793,65 @@ const TemplateLayout = ({
723
793
  }
724
794
  }
725
795
  ),
796
+ drawerOpened && /* @__PURE__ */ jsx(
797
+ CartDrawer,
798
+ {
799
+ ...{
800
+ button: buttons.close("cart", closeDrawer),
801
+ cart,
802
+ cut,
803
+ fonts,
804
+ // The back arrow on the first step: the cart, as it was.
805
+ onBack: () => setDrawer({ open: true, pay: null }),
806
+ onCart: (next) => {
807
+ if ((next == null ? void 0 : next.id) && next.id === (cart == null ? void 0 : cart.id)) {
808
+ setCart(next);
809
+ setCut(next.cut || []);
810
+ }
811
+ ;
812
+ },
813
+ onCheckout: startCheckout,
814
+ onClose: closeDrawer,
815
+ onLineRemove: onCartLineRemove,
816
+ onLineUpdate: onCartLineUpdate,
817
+ // @story shop/recommended-products
818
+ // A recommended row opens its product over the cart.
819
+ onOpenProduct: (product) => {
820
+ setPanel({
821
+ name: "product",
822
+ data: {
823
+ product
824
+ }
825
+ });
826
+ setModal(true);
827
+ },
828
+ onPaid: () => {
829
+ var _a3;
830
+ return paid((_a3 = drawer.pay) == null ? void 0 : _a3.id);
831
+ },
832
+ open: drawer.open,
833
+ params: {
834
+ ...params,
835
+ token
836
+ },
837
+ pay: drawer.pay,
838
+ preview,
839
+ style,
840
+ tracking
841
+ }
842
+ }
843
+ ),
726
844
  opened && /* @__PURE__ */ jsx(
727
845
  TemplateModal,
728
846
  {
729
847
  ...{
730
848
  buttons,
731
- cart,
732
849
  checkout,
733
850
  data,
734
851
  fonts,
735
852
  iframe,
736
853
  modal,
737
854
  onAddToCart,
738
- onCartLineRemove,
739
- onCartLineUpdate,
740
855
  openCheckout,
741
856
  panel,
742
857
  params,
@@ -53,15 +53,12 @@ var import_entry = require("./lib/entry");
53
53
  var import_motion = require("../shared/lib/motion");
54
54
  const TemplateModal = ({
55
55
  buttons,
56
- cart,
57
56
  checkout,
58
57
  data,
59
58
  fonts,
60
59
  iframe,
61
60
  modal,
62
61
  onAddToCart,
63
- onCartLineRemove,
64
- onCartLineUpdate,
65
62
  openCheckout,
66
63
  panel,
67
64
  params,
@@ -79,27 +76,6 @@ const TemplateModal = ({
79
76
  var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
80
77
  const agreements = (data == null ? void 0 : data.agreements) || {};
81
78
  switch (panel == null ? void 0 : panel.name) {
82
- case "cart":
83
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
84
- import_form_subdomain_shop_modal.FormSubdomainCart,
85
- {
86
- ...{
87
- button: buttons.close("cart"),
88
- cart,
89
- onLineRemove: onCartLineRemove,
90
- onLineUpdate: onCartLineUpdate,
91
- onSuccess: ({ result }) => {
92
- tracking.track({
93
- name: "shop-checkout",
94
- data: result
95
- });
96
- openCheckout(result.checkoutUrl);
97
- },
98
- style,
99
- tracking
100
- }
101
- }
102
- );
103
79
  case "enter":
104
80
  if (!(0, import_entry.formOn)(data)) return null;
105
81
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
@@ -481,60 +457,39 @@ const TemplateModal = ({
481
457
  }
482
458
  )
483
459
  ] });
460
+ // @story checkout/cart
461
+ // A product in its own window, which shows no cart of its own: Add to
462
+ // cart closes it onto the cart drawer ( template-layout.js ).
484
463
  case "product":
485
464
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
486
- import_form_subdomain_shop_modal.FormSubdomainCart,
465
+ import_form_subdomain_shop_modal.FormSubdomainProduct,
487
466
  {
488
467
  ...{
489
- cart,
490
- drawer: !((_v = (_u = panel.data) == null ? void 0 : _u.product) == null ? void 0 : _v.sample),
491
- onLineRemove: onCartLineRemove,
492
- onLineUpdate: onCartLineUpdate,
493
- onSuccess: ({ result }) => {
494
- tracking.track({
495
- name: "shop-checkout",
496
- data: result
497
- });
498
- openCheckout(result.checkoutUrl);
468
+ back: (_u = panel.data) == null ? void 0 : _u.back,
469
+ button: buttons.close("product"),
470
+ onAddToCart: async (item) => {
471
+ var _a3, _b3, _c3, _d3, _e3, _f3;
472
+ await onAddToCart(item);
473
+ const productSlug = (_b3 = (_a3 = item.product) == null ? void 0 : _a3.title) == null ? void 0 : _b3.toLowerCase().replace(/\s+/g, "-");
474
+ const isDefaultVariant = !((_c3 = item.variant) == null ? void 0 : _c3.title) || ((_d3 = item.variant) == null ? void 0 : _d3.title) === "Default Title";
475
+ if (isDefaultVariant) {
476
+ tracking.track({ name: "product-" + productSlug + "-add-cart" });
477
+ } else {
478
+ const variantSlug = (_f3 = (_e3 = item.variant) == null ? void 0 : _e3.title) == null ? void 0 : _f3.toLowerCase().replace(/\s+/g, "-");
479
+ tracking.track({ name: "product-" + productSlug + "-" + variantSlug + "-add-cart" });
480
+ }
481
+ ;
499
482
  },
500
- style,
501
- tracking
502
- },
503
- children: (setShow) => {
504
- var _a3, _b3;
505
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
506
- import_form_subdomain_shop_modal.FormSubdomainProduct,
507
- {
508
- ...{
509
- back: (_a3 = panel.data) == null ? void 0 : _a3.back,
510
- button: buttons.close("product"),
511
- onAddToCart: async (item) => {
512
- var _a4, _b4, _c3, _d3, _e3, _f3;
513
- await onAddToCart(item);
514
- const productSlug = (_b4 = (_a4 = item.product) == null ? void 0 : _a4.title) == null ? void 0 : _b4.toLowerCase().replace(/\s+/g, "-");
515
- const isDefaultVariant = !((_c3 = item.variant) == null ? void 0 : _c3.title) || ((_d3 = item.variant) == null ? void 0 : _d3.title) === "Default Title";
516
- if (isDefaultVariant) {
517
- tracking.track({ name: "product-" + productSlug + "-add-cart" });
518
- } else {
519
- const variantSlug = (_f3 = (_e3 = item.variant) == null ? void 0 : _e3.title) == null ? void 0 : _f3.toLowerCase().replace(/\s+/g, "-");
520
- tracking.track({ name: "product-" + productSlug + "-" + variantSlug + "-add-cart" });
521
- }
522
- ;
523
- setShow(true);
524
- },
525
- onError: ({ message }) => setPanel({
526
- name: "error",
527
- data: {
528
- message
529
- }
530
- }),
531
- checkout,
532
- tracking,
533
- product: (_b3 = panel.data) == null ? void 0 : _b3.product,
534
- style
535
- }
483
+ onError: ({ message }) => setPanel({
484
+ name: "error",
485
+ data: {
486
+ message
536
487
  }
537
- );
488
+ }),
489
+ checkout,
490
+ tracking,
491
+ product: (_v = panel.data) == null ? void 0 : _v.product,
492
+ style
538
493
  }
539
494
  }
540
495
  );
@@ -601,7 +556,7 @@ const TemplateModal = ({
601
556
  return null;
602
557
  }
603
558
  },
604
- [buttons, cart, checkout, data, iframe, onAddToCart, onCartLineRemove, onCartLineUpdate, openCheckout, panel, params, preview, style, submission, tracking]
559
+ [buttons, checkout, data, iframe, onAddToCart, openCheckout, panel, params, preview, style, submission, tracking]
605
560
  );
606
561
  return (
607
562
  // reCAPTCHA stays scoped to the modal — this whole module is