@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
@@ -48,10 +48,26 @@ var import_link = __toESM(require("next/link"));
48
48
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
49
49
  var import_constants = __toESM(require("./lib/constants"));
50
50
  var import_checkout_kit = require("./lib/checkout-kit");
51
+ var import_cart = require("./lib/cart");
51
52
  var import_provider_analytics = require("./provider-analytics");
52
53
  var import_entry = require("./lib/entry");
53
54
  var import_url = require("./lib/url");
54
55
  const TemplateModal = (0, import_dynamic.default)(() => import("./template-modal"), { ssr: false });
56
+ const CartDrawer = (0, import_dynamic.default)(() => import("./cart-drawer"), { ssr: false });
57
+ const stored = (key) => {
58
+ try {
59
+ return JSON.parse(window.localStorage.getItem(key) || "null");
60
+ } catch {
61
+ return null;
62
+ }
63
+ };
64
+ const store = (key, value) => {
65
+ try {
66
+ if (value) window.localStorage.setItem(key, JSON.stringify(value));
67
+ else window.localStorage.removeItem(key);
68
+ } catch {
69
+ }
70
+ };
55
71
  const TemplateLayout = ({
56
72
  params,
57
73
  result,
@@ -76,6 +92,11 @@ const TemplateLayout = ({
76
92
  const style = data == null ? void 0 : data.style;
77
93
  const [cart, setCart] = (0, import_react.useState)(null);
78
94
  const [cartLoading, setCartLoading] = (0, import_react.useState)(true);
95
+ const [drawer, setDrawer] = (0, import_react.useState)({ open: false, pay: null });
96
+ const [drawerOpened, setDrawerOpened] = (0, import_react.useState)(false);
97
+ const [cut, setCut] = (0, import_react.useState)([]);
98
+ const [submitted, setSubmitted] = (0, import_react.useState)(null);
99
+ const leadCode = searchParams.get("m");
79
100
  const [modal, setModal] = (0, import_react.useState)(Boolean(submissionId));
80
101
  const [opened, setOpened] = (0, import_react.useState)(Boolean(submissionId));
81
102
  const [panel, setPanel] = (0, import_react.useState)(submissionId ? {
@@ -94,45 +115,86 @@ const TemplateLayout = ({
94
115
  name: null,
95
116
  data: {}
96
117
  });
97
- const cartCount = (0, import_react.useMemo)(
98
- () => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + (line.quantity || 0), 0),
99
- [cart]
100
- );
118
+ const cartCount = (0, import_cart.cartCount)(cart);
101
119
  const cartRoot = "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart";
102
- const cartStorageKey = "cart:" + (params == null ? void 0 : params.subdomain);
103
- const checkout = (0, import_react.useCallback)(
104
- (args = {}) => (0, import_checkout_kit.checkout)({
105
- affiliate,
106
- campaign: data == null ? void 0 : data.campaign,
107
- onComplete: () => {
108
- if (typeof window !== "undefined") {
109
- window.localStorage.removeItem(cartStorageKey);
110
- window.localStorage.removeItem(cartStorageKey + "_expiry");
111
- }
112
- ;
120
+ const cartStorageKey = (0, import_cart.cartKey)({ campaign: result == null ? void 0 : result.campaign, subdomain: params == null ? void 0 : params.subdomain });
121
+ const who = (0, import_react.useMemo)(
122
+ () => ({
123
+ ...affiliate && { affiliate },
124
+ ...leadCode && { code: leadCode },
125
+ ...(data == null ? void 0 : data.page) && { page: data.page },
126
+ ...submitted && { submission: submitted }
127
+ }),
128
+ [affiliate, data == null ? void 0 : data.page, leadCode, submitted]
129
+ );
130
+ const openDrawer = (0, import_react.useCallback)(
131
+ (pay = null) => {
132
+ setDrawerOpened(true);
133
+ setDrawer({ open: true, pay });
134
+ },
135
+ []
136
+ );
137
+ const closeDrawer = (0, import_react.useCallback)(() => setDrawer((current) => ({ ...current, open: false })), []);
138
+ const paid = (0, import_react.useCallback)(
139
+ (id) => {
140
+ if (!id || id === (cart == null ? void 0 : cart.id)) {
141
+ store(cartStorageKey, null);
113
142
  setCart(null);
114
- setPanel({
115
- name: "purchase",
116
- data: {
117
- message: (0, import_entry.copy)(data, "purchase")
118
- }
119
- });
120
- setModal(true);
143
+ setCut([]);
144
+ }
145
+ ;
146
+ setDrawer({ open: false, pay: null });
147
+ setPanel({
148
+ name: "purchase",
149
+ data: {
150
+ message: (0, import_entry.copy)(data, "purchase")
151
+ }
152
+ });
153
+ setModal(true);
154
+ },
155
+ [cart == null ? void 0 : cart.id, cartStorageKey, data]
156
+ );
157
+ const storeCheckout = (0, import_react.useCallback)(
158
+ (paying) => (0, import_checkout_kit.checkout)({
159
+ checkoutUrl: paying == null ? void 0 : paying.checkoutUrl,
160
+ onComplete: () => paid(paying == null ? void 0 : paying.id),
161
+ onOpen: () => {
162
+ setModal(false);
163
+ closeDrawer();
121
164
  },
122
- onOpen: () => setModal(false),
123
- onRedirect: redirectToCheckout,
124
- organization: data == null ? void 0 : data.organization,
125
- page: data == null ? void 0 : data.page,
126
- slug: params == null ? void 0 : params.slug,
127
- subdomain: params == null ? void 0 : params.subdomain,
128
- ...args
165
+ onRedirect: redirectToCheckout
129
166
  }),
130
- [affiliate, cartStorageKey, data, params == null ? void 0 : params.slug, params == null ? void 0 : params.subdomain, redirectToCheckout]
167
+ [closeDrawer, paid, redirectToCheckout]
168
+ );
169
+ const startCheckout = (0, import_react.useCallback)(
170
+ (paying) => (paying == null ? void 0 : paying.checkoutUrl) ? storeCheckout(paying) : openDrawer(paying),
171
+ [openDrawer, storeCheckout]
172
+ );
173
+ const checkout = (0, import_react.useCallback)(
174
+ async (args = {}) => {
175
+ var _a2;
176
+ if (!args.lines) return args.checkoutUrl ? storeCheckout({ checkoutUrl: args.checkoutUrl }) : null;
177
+ const response = await (0, import_fetch.request)({
178
+ body: {
179
+ ...who,
180
+ ...args.advertisement && { advertisement: args.advertisement },
181
+ lines: args.lines
182
+ },
183
+ endpoint: cartRoot,
184
+ method: "POST"
185
+ });
186
+ if (!((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id)) return null;
187
+ setModal(false);
188
+ startCheckout(response.result);
189
+ return response.result;
190
+ },
191
+ [cartRoot, startCheckout, storeCheckout, who]
131
192
  );
132
193
  const openCheckout = (0, import_react.useCallback)(
133
194
  (checkoutUrl) => checkout({ checkoutUrl }),
134
195
  [checkout]
135
196
  );
197
+ if (drawer.open && !drawerOpened) setDrawerOpened(true);
136
198
  if ((modal || (panel == null ? void 0 : panel.name)) && !opened) setOpened(true);
137
199
  (0, import_react.useEffect)(
138
200
  () => {
@@ -172,140 +234,138 @@ const TemplateLayout = ({
172
234
  (0, import_react.useEffect)(
173
235
  () => {
174
236
  if (typeof window === "undefined") return;
175
- const cartId = window.localStorage.getItem(cartStorageKey);
176
- const cartExpiry = window.localStorage.getItem(cartStorageKey + "_expiry");
177
- const expired = !cartExpiry || Date.now() - Number(cartExpiry) > 864e5;
178
- if (!cartId || expired) {
179
- if (cartId && expired) {
180
- window.localStorage.removeItem(cartStorageKey);
181
- window.localStorage.removeItem(cartStorageKey + "_expiry");
182
- }
183
- ;
237
+ const kept = stored(cartStorageKey);
238
+ if (!(kept == null ? void 0 : kept.id) || !(0, import_cart.cartAlive)(kept.made)) {
239
+ if (kept) store(cartStorageKey, null);
184
240
  setCartLoading(false);
185
241
  return;
186
242
  }
187
243
  ;
188
244
  (0, import_fetch.request)({
189
- endpoint: cartRoot + "?cartId=" + encodeURIComponent(cartId),
245
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(kept.id),
190
246
  method: "GET"
191
247
  }).then(({ result: result2 }) => {
192
248
  if (result2 == null ? void 0 : result2.id) {
193
249
  setCart(result2);
194
250
  } else {
195
- window.localStorage.removeItem(cartStorageKey);
196
- window.localStorage.removeItem(cartStorageKey + "_expiry");
251
+ store(cartStorageKey, null);
197
252
  }
198
253
  ;
199
254
  }).catch(() => {
200
- window.localStorage.removeItem(cartStorageKey);
201
- window.localStorage.removeItem(cartStorageKey + "_expiry");
255
+ store(cartStorageKey, null);
202
256
  }).finally(() => {
203
257
  setCartLoading(false);
204
258
  });
205
259
  },
206
260
  [cartRoot, cartStorageKey]
207
261
  );
262
+ const linkedCart = searchParams.get("drwbrdg_cart");
263
+ (0, import_react.useEffect)(
264
+ () => {
265
+ if (!linkedCart) return;
266
+ (0, import_fetch.request)({
267
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(linkedCart),
268
+ method: "GET"
269
+ }).then(({ result: result2 }) => {
270
+ var _a2;
271
+ if ((result2 == null ? void 0 : result2.id) && ((_a2 = result2.lines) == null ? void 0 : _a2.length)) startCheckout(result2);
272
+ }).catch(() => {
273
+ });
274
+ },
275
+ // Once per cart named: startCheckout changes with the page's cart.
276
+ // eslint-disable-next-line react-hooks/exhaustive-deps
277
+ [cartRoot, linkedCart]
278
+ );
208
279
  const onAddToCart = (0, import_react.useCallback)(
209
280
  async ({ variant }) => {
210
281
  var _a2;
211
- const attributes = [
212
- ...(data == null ? void 0 : data.campaign) ? [{ key: "_drwbrdg_ca", value: data.campaign }] : [],
213
- ...(data == null ? void 0 : data.organization) ? [{ key: "_drwbrdg_or", value: data.organization }] : [],
214
- ...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
215
- ...(data == null ? void 0 : data.page) ? [{ key: "_drwbrdg_pg", value: data.page }] : []
216
- ];
217
282
  const line = {
218
- attributes,
219
283
  merchandiseId: variant.id,
220
284
  quantity: 1
221
285
  };
286
+ const create = () => (0, import_fetch.request)({
287
+ body: {
288
+ ...who,
289
+ lines: [line]
290
+ },
291
+ endpoint: cartRoot,
292
+ method: "POST"
293
+ });
222
294
  let response;
223
295
  if (cart == null ? void 0 : cart.id) {
224
296
  try {
225
297
  response = await (0, import_fetch.request)({
226
298
  body: {
299
+ ...who,
227
300
  cartId: cart.id,
228
301
  lines: [line]
229
302
  },
230
303
  endpoint: cartRoot + "/lines",
231
304
  method: "POST"
232
305
  });
233
- } catch {
234
- response = await (0, import_fetch.request)({
235
- body: {
236
- lines: [line]
237
- },
238
- endpoint: cartRoot,
239
- method: "POST"
240
- });
306
+ } catch (error) {
307
+ if ((error == null ? void 0 : error.status) === 400) throw error;
308
+ response = await create();
241
309
  }
242
310
  } else {
243
- response = await (0, import_fetch.request)({
244
- body: {
245
- lines: [line]
246
- },
247
- endpoint: cartRoot,
248
- method: "POST"
249
- });
311
+ response = await create();
250
312
  }
251
313
  ;
252
314
  if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
253
- if (typeof window !== "undefined") {
254
- window.localStorage.setItem(cartStorageKey, response.result.id);
255
- window.localStorage.setItem(cartStorageKey + "_expiry", String(Date.now()));
256
- }
257
- ;
315
+ if (response.result.id !== (cart == null ? void 0 : cart.id)) store(cartStorageKey, { id: response.result.id, made: Date.now() });
258
316
  setCart(response.result);
259
- setModal(true);
317
+ setCut([]);
318
+ setModal(false);
319
+ openDrawer();
260
320
  }
261
321
  ;
262
322
  return response == null ? void 0 : response.result;
263
323
  },
264
- [affiliate, cart, cartRoot, cartStorageKey, data]
324
+ [cart, cartRoot, cartStorageKey, openDrawer, who]
265
325
  );
266
- const onCartLineUpdate = (0, import_react.useCallback)(
267
- async (lineId, quantity) => {
326
+ const changeLine = (0, import_react.useCallback)(
327
+ async (lineId, quantity, send) => {
268
328
  var _a2;
269
329
  if (!(cart == null ? void 0 : cart.id)) return;
270
- const response = await (0, import_fetch.request)({
271
- body: {
272
- cartId: cart.id,
273
- lines: [
274
- {
275
- id: lineId,
276
- quantity
277
- }
278
- ]
279
- },
280
- endpoint: cartRoot + "/lines",
281
- method: "PUT"
282
- });
283
- if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
330
+ const before = cart;
331
+ setCart((0, import_cart.withQuantity)(cart, lineId, quantity));
332
+ try {
333
+ const response = await send();
334
+ if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
335
+ } catch (error) {
336
+ setCart(before);
337
+ throw error;
338
+ }
284
339
  },
285
- [cart, cartRoot]
340
+ [cart]
341
+ );
342
+ const onCartLineUpdate = (0, import_react.useCallback)(
343
+ (lineId, quantity) => changeLine(lineId, quantity, () => (0, import_fetch.request)({
344
+ body: {
345
+ ...who,
346
+ cartId: cart == null ? void 0 : cart.id,
347
+ lines: [
348
+ {
349
+ id: lineId,
350
+ quantity
351
+ }
352
+ ]
353
+ },
354
+ endpoint: cartRoot + "/lines",
355
+ method: "PUT"
356
+ })),
357
+ [cart == null ? void 0 : cart.id, cartRoot, changeLine, who]
286
358
  );
287
359
  const onCartLineRemove = (0, import_react.useCallback)(
288
- async (lineId) => {
289
- var _a2, _b2;
290
- if (!(cart == null ? void 0 : cart.id)) return;
291
- const response = await (0, import_fetch.request)({
292
- body: {
293
- cartId: cart.id,
294
- lineIds: [lineId]
295
- },
296
- endpoint: cartRoot + "/lines",
297
- method: "DELETE"
298
- });
299
- if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
300
- setCart(response.result);
301
- if (!((_b2 = response.result.lines) == null ? void 0 : _b2.length) && typeof window !== "undefined") {
302
- window.localStorage.removeItem(cartStorageKey);
303
- }
304
- ;
305
- }
306
- ;
307
- },
308
- [cart, cartRoot, cartStorageKey]
360
+ (lineId) => changeLine(lineId, 0, () => (0, import_fetch.request)({
361
+ body: {
362
+ cartId: cart == null ? void 0 : cart.id,
363
+ lineIds: [lineId]
364
+ },
365
+ endpoint: cartRoot + "/lines",
366
+ method: "DELETE"
367
+ })),
368
+ [cart == null ? void 0 : cart.id, cartRoot, changeLine]
309
369
  );
310
370
  const tracking = (0, import_provider_analytics.useTracking)({
311
371
  params,
@@ -412,8 +472,21 @@ const TemplateLayout = ({
412
472
  }
413
473
  });
414
474
  setModal(true);
475
+ if (id) {
476
+ setSubmitted(id);
477
+ if (cart == null ? void 0 : cart.id) (0, import_fetch.request)({
478
+ body: {
479
+ cartId: cart.id,
480
+ submission: id
481
+ },
482
+ endpoint: cartRoot,
483
+ method: "PUT"
484
+ }).catch(() => {
485
+ });
486
+ }
487
+ ;
415
488
  },
416
- [affiliate, data, params, preview, style]
489
+ [affiliate, cart == null ? void 0 : cart.id, cartRoot, data, params, preview, style]
417
490
  );
418
491
  const leadMission = searchParams.get("open");
419
492
  const leadUrl = submissionId ? null : (0, import_url.leadEndpoint)({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
@@ -486,7 +559,7 @@ const TemplateLayout = ({
486
559
  return {
487
560
  branding: branding(),
488
561
  brandingCompact: branding(true),
489
- close: (name) => {
562
+ close: (name, onClose) => {
490
563
  var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
491
564
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
492
565
  import_button.default,
@@ -495,7 +568,7 @@ const TemplateLayout = ({
495
568
  "aria-label": "Close Modal",
496
569
  inline: true,
497
570
  onClick: () => {
498
- setModal(false);
571
+ (onClose || (() => setModal(false)))();
499
572
  tracking.track({
500
573
  name: "button-" + name + "-close"
501
574
  });
@@ -646,10 +719,7 @@ const TemplateLayout = ({
646
719
  "aria-label": "Open Shop",
647
720
  inline: true,
648
721
  onClick: () => {
649
- setPanel({
650
- name
651
- });
652
- setModal(true);
722
+ openDrawer();
653
723
  tracking.track({
654
724
  name: "button-" + name + "-open"
655
725
  });
@@ -703,7 +773,7 @@ const TemplateLayout = ({
703
773
  }
704
774
  };
705
775
  },
706
- [cartCount, cartLoading, data, face, preview, style, tracking]
776
+ [cartCount, cartLoading, data, face, openDrawer, preview, style, tracking]
707
777
  );
708
778
  const props = {
709
779
  affiliate,
@@ -755,20 +825,65 @@ const TemplateLayout = ({
755
825
  }
756
826
  }
757
827
  ),
828
+ drawerOpened && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
829
+ CartDrawer,
830
+ {
831
+ ...{
832
+ button: buttons.close("cart", closeDrawer),
833
+ cart,
834
+ cut,
835
+ fonts,
836
+ // The back arrow on the first step: the cart, as it was.
837
+ onBack: () => setDrawer({ open: true, pay: null }),
838
+ onCart: (next) => {
839
+ if ((next == null ? void 0 : next.id) && next.id === (cart == null ? void 0 : cart.id)) {
840
+ setCart(next);
841
+ setCut(next.cut || []);
842
+ }
843
+ ;
844
+ },
845
+ onCheckout: startCheckout,
846
+ onClose: closeDrawer,
847
+ onLineRemove: onCartLineRemove,
848
+ onLineUpdate: onCartLineUpdate,
849
+ // @story shop/recommended-products
850
+ // A recommended row opens its product over the cart.
851
+ onOpenProduct: (product) => {
852
+ setPanel({
853
+ name: "product",
854
+ data: {
855
+ product
856
+ }
857
+ });
858
+ setModal(true);
859
+ },
860
+ onPaid: () => {
861
+ var _a3;
862
+ return paid((_a3 = drawer.pay) == null ? void 0 : _a3.id);
863
+ },
864
+ open: drawer.open,
865
+ params: {
866
+ ...params,
867
+ token
868
+ },
869
+ pay: drawer.pay,
870
+ preview,
871
+ style,
872
+ tracking
873
+ }
874
+ }
875
+ ),
758
876
  opened && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
759
877
  TemplateModal,
760
878
  {
761
879
  ...{
762
880
  buttons,
763
- cart,
764
881
  checkout,
765
882
  data,
766
883
  fonts,
767
884
  iframe,
768
885
  modal,
769
886
  onAddToCart,
770
- onCartLineRemove,
771
- onCartLineUpdate,
772
887
  openCheckout,
773
888
  panel,
774
889
  params,