@drawbridge/components 0.1.48 → 0.1.49

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 (125) hide show
  1. package/dist/bridge/fields.js +0 -278
  2. package/dist/bridge/fields.mjs +1 -276
  3. package/dist/bridge/form-subdomain-shop-modal.js +274 -234
  4. package/dist/bridge/form-subdomain-shop-modal.mjs +275 -233
  5. package/dist/bridge/form-subdomain.js +0 -7
  6. package/dist/bridge/form-subdomain.mjs +2 -9
  7. package/dist/bridge/lib/age-gate.js +0 -12
  8. package/dist/bridge/lib/age-gate.mjs +0 -11
  9. package/dist/bridge/lib/checkout-kit.js +32 -2
  10. package/dist/bridge/lib/checkout-kit.mjs +32 -2
  11. package/dist/bridge/lib/entry.js +0 -3
  12. package/dist/bridge/lib/entry.mjs +0 -2
  13. package/dist/bridge/product-tile.js +6 -9
  14. package/dist/bridge/product-tile.mjs +6 -9
  15. package/dist/bridge/template-layout.js +122 -237
  16. package/dist/bridge/template-layout.mjs +122 -237
  17. package/dist/bridge/template-modal.js +73 -28
  18. package/dist/bridge/template-modal.mjs +74 -29
  19. package/dist/dashboard/buttons-subscription.js +1 -1
  20. package/dist/dashboard/buttons-subscription.mjs +1 -1
  21. package/dist/dashboard/campaign-form.js +2 -7
  22. package/dist/dashboard/campaign-form.mjs +2 -7
  23. package/dist/dashboard/card-order.js +4 -22
  24. package/dist/dashboard/card-order.mjs +4 -22
  25. package/dist/dashboard/document-blocks.js +17 -4
  26. package/dist/dashboard/document-blocks.mjs +17 -4
  27. package/dist/dashboard/form-admin-provider.js +17 -71
  28. package/dist/dashboard/form-admin-provider.mjs +17 -71
  29. package/dist/dashboard/form-file-upload.js +2 -3
  30. package/dist/dashboard/form-file-upload.mjs +3 -4
  31. package/dist/dashboard/form-organization-campaign-advertisements.js +6 -47
  32. package/dist/dashboard/form-organization-campaign-advertisements.mjs +6 -47
  33. package/dist/dashboard/form-organization-campaign-agreement.js +121 -83
  34. package/dist/dashboard/form-organization-campaign-agreement.mjs +121 -83
  35. package/dist/dashboard/form-organization-campaign.js +0 -82
  36. package/dist/dashboard/form-organization-campaign.mjs +0 -81
  37. package/dist/dashboard/form-organization-connection.js +6 -48
  38. package/dist/dashboard/form-organization-connection.mjs +7 -48
  39. package/dist/dashboard/form-organization-workflow.js +1 -72
  40. package/dist/dashboard/form-organization-workflow.mjs +1 -69
  41. package/dist/dashboard/form-otc.js +5 -4
  42. package/dist/dashboard/form-otc.mjs +5 -4
  43. package/dist/dashboard/form-stripe.js +5 -12
  44. package/dist/dashboard/form-stripe.mjs +5 -12
  45. package/dist/dashboard/input-fields.js +158 -11
  46. package/dist/dashboard/input-fields.mjs +158 -11
  47. package/dist/dashboard/input-file.js +4 -21
  48. package/dist/dashboard/input-file.mjs +4 -21
  49. package/dist/dashboard/lib/connection-controls.js +2 -5
  50. package/dist/dashboard/lib/connection-controls.mjs +1 -3
  51. package/dist/dashboard/lib/form-page.js +1 -1
  52. package/dist/dashboard/lib/form-page.mjs +1 -1
  53. package/dist/dashboard/lib/uppy.js +1 -10
  54. package/dist/dashboard/lib/uppy.mjs +2 -11
  55. package/dist/dashboard/order-sections.js +6 -456
  56. package/dist/dashboard/order-sections.mjs +7 -453
  57. package/dist/dashboard/provider-ui.js +7 -9
  58. package/dist/dashboard/provider-ui.mjs +7 -9
  59. package/dist/dashboard/template-ui.js +12 -4
  60. package/dist/dashboard/template-ui.mjs +12 -4
  61. package/dist/input-checkbox.js +10 -28
  62. package/dist/input-checkbox.mjs +10 -28
  63. package/dist/product.js +24 -96
  64. package/dist/product.mjs +25 -97
  65. package/dist/shared/lib/helpers.js +6 -54
  66. package/dist/shared/lib/helpers.mjs +8 -53
  67. package/package.json +4 -74
  68. package/types/bridge/fields.d.ts +2 -14
  69. package/types/bridge/form-subdomain-shop-modal.d.ts +3 -27
  70. package/types/bridge/lib/age-gate.d.ts +0 -5
  71. package/types/bridge/lib/checkout-kit.d.ts +10 -2
  72. package/types/bridge/lib/entry.d.ts +0 -3
  73. package/types/dashboard/card-order.d.ts +0 -6
  74. package/types/dashboard/document-blocks.d.ts +3 -2
  75. package/types/dashboard/form-admin-provider.d.ts +2 -9
  76. package/types/dashboard/form-file-upload.d.ts +1 -2
  77. package/types/dashboard/form-organization-campaign-advertisements.d.ts +0 -3
  78. package/types/dashboard/form-organization-campaign-agreement.d.ts +5 -2
  79. package/types/dashboard/form-organization-campaign.d.ts +0 -3
  80. package/types/dashboard/form-organization-connection.d.ts +0 -11
  81. package/types/dashboard/form-otc.d.ts +1 -5
  82. package/types/dashboard/form-stripe.d.ts +2 -3
  83. package/types/dashboard/input-file.d.ts +0 -2
  84. package/types/dashboard/order-sections.d.ts +1 -24
  85. package/types/input-checkbox.d.ts +0 -2
  86. package/types/shared/lib/helpers.d.ts +0 -4
  87. package/dist/bridge/cart-drawer.js +0 -152
  88. package/dist/bridge/cart-drawer.mjs +0 -123
  89. package/dist/bridge/form-subdomain-checkout.js +0 -687
  90. package/dist/bridge/form-subdomain-checkout.mjs +0 -665
  91. package/dist/bridge/lib/cart.js +0 -79
  92. package/dist/bridge/lib/cart.mjs +0 -48
  93. package/dist/dashboard/embed-stripe.js +0 -145
  94. package/dist/dashboard/embed-stripe.mjs +0 -116
  95. package/dist/dashboard/form-organization-campaign-field-birthday.js +0 -193
  96. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +0 -164
  97. package/dist/dashboard/form-organization-campaign-field-rating.js +0 -246
  98. package/dist/dashboard/form-organization-campaign-field-rating.mjs +0 -217
  99. package/dist/dashboard/form-organization-product.js +0 -1461
  100. package/dist/dashboard/form-organization-product.mjs +0 -1425
  101. package/dist/dashboard/input-gallery.js +0 -201
  102. package/dist/dashboard/input-gallery.mjs +0 -172
  103. package/dist/dashboard/lib/products.js +0 -169
  104. package/dist/dashboard/lib/products.mjs +0 -135
  105. package/dist/dashboard/lib/settings-paths.js +0 -35
  106. package/dist/dashboard/lib/settings-paths.mjs +0 -11
  107. package/dist/dashboard/shipping-rates.js +0 -404
  108. package/dist/dashboard/shipping-rates.mjs +0 -371
  109. package/dist/dashboard/template-buyer.js +0 -301
  110. package/dist/dashboard/template-buyer.mjs +0 -267
  111. package/dist/shared/order-summary.js +0 -139
  112. package/dist/shared/order-summary.mjs +0 -110
  113. package/types/bridge/cart-drawer.d.ts +0 -31
  114. package/types/bridge/form-subdomain-checkout.d.ts +0 -20
  115. package/types/bridge/lib/cart.d.ts +0 -44
  116. package/types/dashboard/embed-stripe.d.ts +0 -25
  117. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +0 -31
  118. package/types/dashboard/form-organization-campaign-field-rating.d.ts +0 -33
  119. package/types/dashboard/form-organization-product.d.ts +0 -24
  120. package/types/dashboard/input-gallery.d.ts +0 -14
  121. package/types/dashboard/lib/products.d.ts +0 -14
  122. package/types/dashboard/lib/settings-paths.d.ts +0 -5
  123. package/types/dashboard/shipping-rates.d.ts +0 -26
  124. package/types/dashboard/template-buyer.d.ts +0 -50
  125. package/types/shared/order-summary.d.ts +0 -19
@@ -16,26 +16,10 @@ 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";
20
19
  import { useTracking } from "./provider-analytics.mjs";
21
20
  import { afterOrder, awardingOn, buttonText, copy, formOn, previewStep } from "./lib/entry.mjs";
22
21
  import { leadEndpoint } from "./lib/url.mjs";
23
22
  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
- };
39
23
  const TemplateLayout = ({
40
24
  params,
41
25
  result,
@@ -60,11 +44,6 @@ const TemplateLayout = ({
60
44
  const style = data == null ? void 0 : data.style;
61
45
  const [cart, setCart] = useState(null);
62
46
  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");
68
47
  const [modal, setModal] = useState(Boolean(submissionId));
69
48
  const [opened, setOpened] = useState(Boolean(submissionId));
70
49
  const [panel, setPanel] = useState(submissionId ? {
@@ -83,86 +62,45 @@ const TemplateLayout = ({
83
62
  name: null,
84
63
  data: {}
85
64
  });
86
- const cartCount = countOf(cart);
87
- const cartRoot = "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart";
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
- []
65
+ const cartCount = useMemo(
66
+ () => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + (line.quantity || 0), 0),
67
+ [cart]
104
68
  );
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);
110
- setCart(null);
111
- setCut([]);
112
- }
113
- ;
114
- setDrawer({ open: false, pay: null });
115
- setPanel({
116
- name: "purchase",
117
- data: {
118
- message: copy(data, "purchase")
69
+ 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");
119
79
  }
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();
80
+ ;
81
+ setCart(null);
82
+ setPanel({
83
+ name: "purchase",
84
+ data: {
85
+ message: copy(data, "purchase")
86
+ }
87
+ });
88
+ setModal(true);
132
89
  },
133
- onRedirect: redirectToCheckout
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
134
97
  }),
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]
98
+ [affiliate, cartStorageKey, data, params == null ? void 0 : params.slug, params == null ? void 0 : params.subdomain, redirectToCheckout]
160
99
  );
161
100
  const openCheckout = useCallback(
162
101
  (checkoutUrl) => checkout({ checkoutUrl }),
163
102
  [checkout]
164
103
  );
165
- if (drawer.open && !drawerOpened) setDrawerOpened(true);
166
104
  if ((modal || (panel == null ? void 0 : panel.name)) && !opened) setOpened(true);
167
105
  useEffect(
168
106
  () => {
@@ -202,138 +140,140 @@ const TemplateLayout = ({
202
140
  useEffect(
203
141
  () => {
204
142
  if (typeof window === "undefined") return;
205
- const kept = stored(cartStorageKey);
206
- if (!(kept == null ? void 0 : kept.id) || !cartAlive(kept.made)) {
207
- if (kept) store(cartStorageKey, null);
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
+ ;
208
152
  setCartLoading(false);
209
153
  return;
210
154
  }
211
155
  ;
212
156
  request({
213
- endpoint: cartRoot + "?cartId=" + encodeURIComponent(kept.id),
157
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(cartId),
214
158
  method: "GET"
215
159
  }).then(({ result: result2 }) => {
216
160
  if (result2 == null ? void 0 : result2.id) {
217
161
  setCart(result2);
218
162
  } else {
219
- store(cartStorageKey, null);
163
+ window.localStorage.removeItem(cartStorageKey);
164
+ window.localStorage.removeItem(cartStorageKey + "_expiry");
220
165
  }
221
166
  ;
222
167
  }).catch(() => {
223
- store(cartStorageKey, null);
168
+ window.localStorage.removeItem(cartStorageKey);
169
+ window.localStorage.removeItem(cartStorageKey + "_expiry");
224
170
  }).finally(() => {
225
171
  setCartLoading(false);
226
172
  });
227
173
  },
228
174
  [cartRoot, cartStorageKey]
229
175
  );
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
- );
247
176
  const onAddToCart = useCallback(
248
177
  async ({ variant }) => {
249
178
  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
+ ];
250
185
  const line = {
186
+ attributes,
251
187
  merchandiseId: variant.id,
252
188
  quantity: 1
253
189
  };
254
- const create = () => request({
255
- body: {
256
- ...who,
257
- lines: [line]
258
- },
259
- endpoint: cartRoot,
260
- method: "POST"
261
- });
262
190
  let response;
263
191
  if (cart == null ? void 0 : cart.id) {
264
192
  try {
265
193
  response = await request({
266
194
  body: {
267
- ...who,
268
195
  cartId: cart.id,
269
196
  lines: [line]
270
197
  },
271
198
  endpoint: cartRoot + "/lines",
272
199
  method: "POST"
273
200
  });
274
- } catch (error) {
275
- if ((error == null ? void 0 : error.status) === 400) throw error;
276
- response = await create();
201
+ } catch {
202
+ response = await request({
203
+ body: {
204
+ lines: [line]
205
+ },
206
+ endpoint: cartRoot,
207
+ method: "POST"
208
+ });
277
209
  }
278
210
  } else {
279
- response = await create();
211
+ response = await request({
212
+ body: {
213
+ lines: [line]
214
+ },
215
+ endpoint: cartRoot,
216
+ method: "POST"
217
+ });
280
218
  }
281
219
  ;
282
220
  if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
283
- if (response.result.id !== (cart == null ? void 0 : cart.id)) store(cartStorageKey, { id: response.result.id, made: Date.now() });
221
+ if (typeof window !== "undefined") {
222
+ window.localStorage.setItem(cartStorageKey, response.result.id);
223
+ window.localStorage.setItem(cartStorageKey + "_expiry", String(Date.now()));
224
+ }
225
+ ;
284
226
  setCart(response.result);
285
- setCut([]);
286
- setModal(false);
287
- openDrawer();
227
+ setModal(true);
288
228
  }
289
229
  ;
290
230
  return response == null ? void 0 : response.result;
291
231
  },
292
- [cart, cartRoot, cartStorageKey, openDrawer, who]
232
+ [affiliate, cart, cartRoot, cartStorageKey, data]
293
233
  );
294
- const changeLine = useCallback(
295
- async (lineId, quantity, send) => {
234
+ const onCartLineUpdate = useCallback(
235
+ async (lineId, quantity) => {
296
236
  var _a2;
297
237
  if (!(cart == null ? void 0 : cart.id)) return;
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
- }
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);
307
252
  },
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]
253
+ [cart, cartRoot]
326
254
  );
327
255
  const onCartLineRemove = useCallback(
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]
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]
337
277
  );
338
278
  const tracking = useTracking({
339
279
  params,
@@ -440,21 +380,8 @@ const TemplateLayout = ({
440
380
  }
441
381
  });
442
382
  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
- ;
456
383
  },
457
- [affiliate, cart == null ? void 0 : cart.id, cartRoot, data, params, preview, style]
384
+ [affiliate, data, params, preview, style]
458
385
  );
459
386
  const leadMission = searchParams.get("open");
460
387
  const leadUrl = submissionId ? null : leadEndpoint({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
@@ -527,7 +454,7 @@ const TemplateLayout = ({
527
454
  return {
528
455
  branding: branding(),
529
456
  brandingCompact: branding(true),
530
- close: (name, onClose) => {
457
+ close: (name) => {
531
458
  var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
532
459
  return /* @__PURE__ */ jsx(
533
460
  Button,
@@ -536,7 +463,7 @@ const TemplateLayout = ({
536
463
  "aria-label": "Close Modal",
537
464
  inline: true,
538
465
  onClick: () => {
539
- (onClose || (() => setModal(false)))();
466
+ setModal(false);
540
467
  tracking.track({
541
468
  name: "button-" + name + "-close"
542
469
  });
@@ -687,7 +614,10 @@ const TemplateLayout = ({
687
614
  "aria-label": "Open Shop",
688
615
  inline: true,
689
616
  onClick: () => {
690
- openDrawer();
617
+ setPanel({
618
+ name
619
+ });
620
+ setModal(true);
691
621
  tracking.track({
692
622
  name: "button-" + name + "-open"
693
623
  });
@@ -741,7 +671,7 @@ const TemplateLayout = ({
741
671
  }
742
672
  };
743
673
  },
744
- [cartCount, cartLoading, data, face, openDrawer, preview, style, tracking]
674
+ [cartCount, cartLoading, data, face, preview, style, tracking]
745
675
  );
746
676
  const props = {
747
677
  affiliate,
@@ -793,65 +723,20 @@ const TemplateLayout = ({
793
723
  }
794
724
  }
795
725
  ),
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
- ),
844
726
  opened && /* @__PURE__ */ jsx(
845
727
  TemplateModal,
846
728
  {
847
729
  ...{
848
730
  buttons,
731
+ cart,
849
732
  checkout,
850
733
  data,
851
734
  fonts,
852
735
  iframe,
853
736
  modal,
854
737
  onAddToCart,
738
+ onCartLineRemove,
739
+ onCartLineUpdate,
855
740
  openCheckout,
856
741
  panel,
857
742
  params,
@@ -53,12 +53,15 @@ var import_entry = require("./lib/entry");
53
53
  var import_motion = require("../shared/lib/motion");
54
54
  const TemplateModal = ({
55
55
  buttons,
56
+ cart,
56
57
  checkout,
57
58
  data,
58
59
  fonts,
59
60
  iframe,
60
61
  modal,
61
62
  onAddToCart,
63
+ onCartLineRemove,
64
+ onCartLineUpdate,
62
65
  openCheckout,
63
66
  panel,
64
67
  params,
@@ -76,6 +79,27 @@ const TemplateModal = ({
76
79
  var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
77
80
  const agreements = (data == null ? void 0 : data.agreements) || {};
78
81
  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
+ );
79
103
  case "enter":
80
104
  if (!(0, import_entry.formOn)(data)) return null;
81
105
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
@@ -457,39 +481,60 @@ const TemplateModal = ({
457
481
  }
458
482
  )
459
483
  ] });
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 ).
463
484
  case "product":
464
485
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
465
- import_form_subdomain_shop_modal.FormSubdomainProduct,
486
+ import_form_subdomain_shop_modal.FormSubdomainCart,
466
487
  {
467
488
  ...{
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
- ;
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);
482
499
  },
483
- onError: ({ message }) => setPanel({
484
- name: "error",
485
- data: {
486
- message
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
+ }
487
536
  }
488
- }),
489
- checkout,
490
- tracking,
491
- product: (_v = panel.data) == null ? void 0 : _v.product,
492
- style
537
+ );
493
538
  }
494
539
  }
495
540
  );
@@ -556,7 +601,7 @@ const TemplateModal = ({
556
601
  return null;
557
602
  }
558
603
  },
559
- [buttons, checkout, data, iframe, onAddToCart, openCheckout, panel, params, preview, style, submission, tracking]
604
+ [buttons, cart, checkout, data, iframe, onAddToCart, onCartLineRemove, onCartLineUpdate, openCheckout, panel, params, preview, style, submission, tracking]
560
605
  );
561
606
  return (
562
607
  // reCAPTCHA stays scoped to the modal — this whole module is