@drawbridge/components 0.1.46 → 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 (162) 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-shop.js +4 -1
  10. package/dist/bridge/form-subdomain-shop.mjs +4 -1
  11. package/dist/bridge/form-subdomain.js +24 -5
  12. package/dist/bridge/form-subdomain.mjs +25 -6
  13. package/dist/bridge/lib/age-gate.js +12 -0
  14. package/dist/bridge/lib/age-gate.mjs +11 -0
  15. package/dist/bridge/lib/cart.js +79 -0
  16. package/dist/bridge/lib/cart.mjs +48 -0
  17. package/dist/bridge/lib/checkout-kit.js +2 -32
  18. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  19. package/dist/bridge/lib/entry.js +41 -0
  20. package/dist/bridge/lib/entry.mjs +40 -0
  21. package/dist/bridge/product-tile.js +13 -6
  22. package/dist/bridge/product-tile.mjs +13 -6
  23. package/dist/bridge/template-layout.js +263 -129
  24. package/dist/bridge/template-layout.mjs +264 -130
  25. package/dist/bridge/template-modal.js +39 -74
  26. package/dist/bridge/template-modal.mjs +40 -75
  27. package/dist/dashboard/avatar.js +2 -3
  28. package/dist/dashboard/avatar.mjs +2 -3
  29. package/dist/dashboard/buttons-subscription.js +1 -1
  30. package/dist/dashboard/buttons-subscription.mjs +1 -1
  31. package/dist/dashboard/campaign-form.js +179 -155
  32. package/dist/dashboard/campaign-form.mjs +179 -155
  33. package/dist/dashboard/campaign-share.js +347 -0
  34. package/dist/dashboard/campaign-share.mjs +314 -0
  35. package/dist/dashboard/card-affiliate.js +1 -1
  36. package/dist/dashboard/card-affiliate.mjs +1 -1
  37. package/dist/dashboard/card-campaign-switch.js +4 -1
  38. package/dist/dashboard/card-campaign-switch.mjs +4 -1
  39. package/dist/dashboard/card-order.js +22 -4
  40. package/dist/dashboard/card-order.mjs +22 -4
  41. package/dist/dashboard/embed-stripe.js +145 -0
  42. package/dist/dashboard/embed-stripe.mjs +116 -0
  43. package/dist/dashboard/form-admin-provider.js +71 -17
  44. package/dist/dashboard/form-admin-provider.mjs +71 -17
  45. package/dist/dashboard/form-file-upload.js +3 -2
  46. package/dist/dashboard/form-file-upload.mjs +4 -3
  47. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  48. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  49. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  50. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  51. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  52. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  53. package/dist/dashboard/form-organization-campaign-page.js +73 -39
  54. package/dist/dashboard/form-organization-campaign-page.mjs +73 -39
  55. package/dist/dashboard/form-organization-campaign.js +82 -0
  56. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  57. package/dist/dashboard/form-organization-connection.js +48 -6
  58. package/dist/dashboard/form-organization-connection.mjs +48 -7
  59. package/dist/dashboard/form-organization-product.js +1461 -0
  60. package/dist/dashboard/form-organization-product.mjs +1425 -0
  61. package/dist/dashboard/form-organization-workflow.js +72 -1
  62. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  63. package/dist/dashboard/form-otc.js +4 -5
  64. package/dist/dashboard/form-otc.mjs +4 -5
  65. package/dist/dashboard/form-stripe.js +12 -5
  66. package/dist/dashboard/form-stripe.mjs +12 -5
  67. package/dist/dashboard/input-combobox.js +6 -0
  68. package/dist/dashboard/input-combobox.mjs +6 -0
  69. package/dist/dashboard/input-fields.js +37 -161
  70. package/dist/dashboard/input-fields.mjs +37 -161
  71. package/dist/dashboard/input-file.js +21 -4
  72. package/dist/dashboard/input-file.mjs +21 -4
  73. package/dist/dashboard/input-font.js +2 -0
  74. package/dist/dashboard/input-font.mjs +2 -0
  75. package/dist/dashboard/input-gallery.js +201 -0
  76. package/dist/dashboard/input-gallery.mjs +172 -0
  77. package/dist/dashboard/input-group-ai.js +15 -3
  78. package/dist/dashboard/input-group-ai.mjs +15 -3
  79. package/dist/dashboard/lib/ab-tests.js +2 -2
  80. package/dist/dashboard/lib/ab-tests.mjs +2 -2
  81. package/dist/dashboard/lib/connection-controls.js +5 -2
  82. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  83. package/dist/dashboard/lib/form-page.js +1 -1
  84. package/dist/dashboard/lib/form-page.mjs +1 -1
  85. package/dist/dashboard/lib/menu.js +19 -0
  86. package/dist/dashboard/lib/menu.mjs +18 -0
  87. package/dist/dashboard/lib/products.js +169 -0
  88. package/dist/dashboard/lib/products.mjs +135 -0
  89. package/dist/dashboard/lib/settings-paths.js +35 -0
  90. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  91. package/dist/dashboard/lib/uppy.js +10 -1
  92. package/dist/dashboard/lib/uppy.mjs +11 -2
  93. package/dist/dashboard/menu.js +13 -2
  94. package/dist/dashboard/menu.mjs +13 -2
  95. package/dist/dashboard/order-sections.js +456 -6
  96. package/dist/dashboard/order-sections.mjs +453 -7
  97. package/dist/dashboard/preview.js +119 -52
  98. package/dist/dashboard/preview.mjs +119 -52
  99. package/dist/dashboard/provider-ui.js +9 -7
  100. package/dist/dashboard/provider-ui.mjs +9 -7
  101. package/dist/dashboard/recharts.js +10 -4
  102. package/dist/dashboard/recharts.mjs +10 -4
  103. package/dist/dashboard/shipping-rates.js +404 -0
  104. package/dist/dashboard/shipping-rates.mjs +371 -0
  105. package/dist/dashboard/template-buyer.js +301 -0
  106. package/dist/dashboard/template-buyer.mjs +267 -0
  107. package/dist/dashboard/template-dashboard.js +11 -1
  108. package/dist/dashboard/template-dashboard.mjs +11 -1
  109. package/dist/dashboard/template-design.js +209 -130
  110. package/dist/dashboard/template-design.mjs +210 -131
  111. package/dist/dashboard/template-ui.js +157 -55
  112. package/dist/dashboard/template-ui.mjs +158 -56
  113. package/dist/icons/flags.js +134 -0
  114. package/dist/icons/flags.mjs +115 -0
  115. package/dist/input-checkbox.js +28 -10
  116. package/dist/input-checkbox.mjs +28 -10
  117. package/dist/product.js +96 -24
  118. package/dist/product.mjs +97 -25
  119. package/dist/shared/carousel.js +14 -5
  120. package/dist/shared/carousel.mjs +14 -5
  121. package/dist/shared/lib/helpers.js +54 -6
  122. package/dist/shared/lib/helpers.mjs +53 -8
  123. package/dist/shared/order-summary.js +139 -0
  124. package/dist/shared/order-summary.mjs +110 -0
  125. package/package.json +84 -4
  126. package/types/bridge/cart-drawer.d.ts +31 -0
  127. package/types/bridge/fields.d.ts +14 -2
  128. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  129. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  130. package/types/bridge/form-subdomain.d.ts +13 -0
  131. package/types/bridge/lib/age-gate.d.ts +5 -0
  132. package/types/bridge/lib/cart.d.ts +44 -0
  133. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  134. package/types/bridge/lib/entry.d.ts +5 -0
  135. package/types/bridge/product-tile.d.ts +2 -0
  136. package/types/dashboard/campaign-share.d.ts +16 -0
  137. package/types/dashboard/card-order.d.ts +6 -0
  138. package/types/dashboard/embed-stripe.d.ts +25 -0
  139. package/types/dashboard/form-admin-provider.d.ts +9 -2
  140. package/types/dashboard/form-file-upload.d.ts +2 -1
  141. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  142. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  143. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  144. package/types/dashboard/form-organization-campaign-page.d.ts +8 -1
  145. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  146. package/types/dashboard/form-organization-connection.d.ts +11 -0
  147. package/types/dashboard/form-organization-product.d.ts +24 -0
  148. package/types/dashboard/form-otc.d.ts +5 -1
  149. package/types/dashboard/form-stripe.d.ts +3 -2
  150. package/types/dashboard/input-combobox.d.ts +2 -0
  151. package/types/dashboard/input-file.d.ts +2 -0
  152. package/types/dashboard/input-gallery.d.ts +14 -0
  153. package/types/dashboard/lib/products.d.ts +14 -0
  154. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  155. package/types/dashboard/order-sections.d.ts +24 -1
  156. package/types/dashboard/preview.d.ts +11 -3
  157. package/types/dashboard/shipping-rates.d.ts +26 -0
  158. package/types/dashboard/template-buyer.d.ts +50 -0
  159. package/types/icons/flags.d.ts +5 -0
  160. package/types/input-checkbox.d.ts +2 -0
  161. package/types/shared/lib/helpers.d.ts +4 -0
  162. 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,
@@ -72,9 +88,15 @@ const TemplateLayout = ({
72
88
  );
73
89
  const [data, setData] = (0, import_react.useState)(result);
74
90
  const [iframe, setIframe] = (0, import_react.useState)(false);
91
+ const [face, setFace] = (0, import_react.useState)(null);
75
92
  const style = data == null ? void 0 : data.style;
76
93
  const [cart, setCart] = (0, import_react.useState)(null);
77
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");
78
100
  const [modal, setModal] = (0, import_react.useState)(Boolean(submissionId));
79
101
  const [opened, setOpened] = (0, import_react.useState)(Boolean(submissionId));
80
102
  const [panel, setPanel] = (0, import_react.useState)(submissionId ? {
@@ -93,45 +115,86 @@ const TemplateLayout = ({
93
115
  name: null,
94
116
  data: {}
95
117
  });
96
- const cartCount = (0, import_react.useMemo)(
97
- () => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + (line.quantity || 0), 0),
98
- [cart]
99
- );
118
+ const cartCount = (0, import_cart.cartCount)(cart);
100
119
  const cartRoot = "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart";
101
- const cartStorageKey = "cart:" + (params == null ? void 0 : params.subdomain);
102
- const checkout = (0, import_react.useCallback)(
103
- (args = {}) => (0, import_checkout_kit.checkout)({
104
- affiliate,
105
- campaign: data == null ? void 0 : data.campaign,
106
- onComplete: () => {
107
- if (typeof window !== "undefined") {
108
- window.localStorage.removeItem(cartStorageKey);
109
- window.localStorage.removeItem(cartStorageKey + "_expiry");
110
- }
111
- ;
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);
112
142
  setCart(null);
113
- setPanel({
114
- name: "purchase",
115
- data: {
116
- message: (0, import_entry.copy)(data, "purchase")
117
- }
118
- });
119
- 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();
120
164
  },
121
- onOpen: () => setModal(false),
122
- onRedirect: redirectToCheckout,
123
- organization: data == null ? void 0 : data.organization,
124
- page: data == null ? void 0 : data.page,
125
- slug: params == null ? void 0 : params.slug,
126
- subdomain: params == null ? void 0 : params.subdomain,
127
- ...args
165
+ onRedirect: redirectToCheckout
128
166
  }),
129
- [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]
130
192
  );
131
193
  const openCheckout = (0, import_react.useCallback)(
132
194
  (checkoutUrl) => checkout({ checkoutUrl }),
133
195
  [checkout]
134
196
  );
197
+ if (drawer.open && !drawerOpened) setDrawerOpened(true);
135
198
  if ((modal || (panel == null ? void 0 : panel.name)) && !opened) setOpened(true);
136
199
  (0, import_react.useEffect)(
137
200
  () => {
@@ -171,140 +234,138 @@ const TemplateLayout = ({
171
234
  (0, import_react.useEffect)(
172
235
  () => {
173
236
  if (typeof window === "undefined") return;
174
- const cartId = window.localStorage.getItem(cartStorageKey);
175
- const cartExpiry = window.localStorage.getItem(cartStorageKey + "_expiry");
176
- const expired = !cartExpiry || Date.now() - Number(cartExpiry) > 864e5;
177
- if (!cartId || expired) {
178
- if (cartId && expired) {
179
- window.localStorage.removeItem(cartStorageKey);
180
- window.localStorage.removeItem(cartStorageKey + "_expiry");
181
- }
182
- ;
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);
183
240
  setCartLoading(false);
184
241
  return;
185
242
  }
186
243
  ;
187
244
  (0, import_fetch.request)({
188
- endpoint: cartRoot + "?cartId=" + encodeURIComponent(cartId),
245
+ endpoint: cartRoot + "?cartId=" + encodeURIComponent(kept.id),
189
246
  method: "GET"
190
247
  }).then(({ result: result2 }) => {
191
248
  if (result2 == null ? void 0 : result2.id) {
192
249
  setCart(result2);
193
250
  } else {
194
- window.localStorage.removeItem(cartStorageKey);
195
- window.localStorage.removeItem(cartStorageKey + "_expiry");
251
+ store(cartStorageKey, null);
196
252
  }
197
253
  ;
198
254
  }).catch(() => {
199
- window.localStorage.removeItem(cartStorageKey);
200
- window.localStorage.removeItem(cartStorageKey + "_expiry");
255
+ store(cartStorageKey, null);
201
256
  }).finally(() => {
202
257
  setCartLoading(false);
203
258
  });
204
259
  },
205
260
  [cartRoot, cartStorageKey]
206
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
+ );
207
279
  const onAddToCart = (0, import_react.useCallback)(
208
280
  async ({ variant }) => {
209
281
  var _a2;
210
- const attributes = [
211
- ...(data == null ? void 0 : data.campaign) ? [{ key: "_drwbrdg_ca", value: data.campaign }] : [],
212
- ...(data == null ? void 0 : data.organization) ? [{ key: "_drwbrdg_or", value: data.organization }] : [],
213
- ...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
214
- ...(data == null ? void 0 : data.page) ? [{ key: "_drwbrdg_pg", value: data.page }] : []
215
- ];
216
282
  const line = {
217
- attributes,
218
283
  merchandiseId: variant.id,
219
284
  quantity: 1
220
285
  };
286
+ const create = () => (0, import_fetch.request)({
287
+ body: {
288
+ ...who,
289
+ lines: [line]
290
+ },
291
+ endpoint: cartRoot,
292
+ method: "POST"
293
+ });
221
294
  let response;
222
295
  if (cart == null ? void 0 : cart.id) {
223
296
  try {
224
297
  response = await (0, import_fetch.request)({
225
298
  body: {
299
+ ...who,
226
300
  cartId: cart.id,
227
301
  lines: [line]
228
302
  },
229
303
  endpoint: cartRoot + "/lines",
230
304
  method: "POST"
231
305
  });
232
- } catch {
233
- response = await (0, import_fetch.request)({
234
- body: {
235
- lines: [line]
236
- },
237
- endpoint: cartRoot,
238
- method: "POST"
239
- });
306
+ } catch (error) {
307
+ if ((error == null ? void 0 : error.status) === 400) throw error;
308
+ response = await create();
240
309
  }
241
310
  } else {
242
- response = await (0, import_fetch.request)({
243
- body: {
244
- lines: [line]
245
- },
246
- endpoint: cartRoot,
247
- method: "POST"
248
- });
311
+ response = await create();
249
312
  }
250
313
  ;
251
314
  if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
252
- if (typeof window !== "undefined") {
253
- window.localStorage.setItem(cartStorageKey, response.result.id);
254
- window.localStorage.setItem(cartStorageKey + "_expiry", String(Date.now()));
255
- }
256
- ;
315
+ if (response.result.id !== (cart == null ? void 0 : cart.id)) store(cartStorageKey, { id: response.result.id, made: Date.now() });
257
316
  setCart(response.result);
258
- setModal(true);
317
+ setCut([]);
318
+ setModal(false);
319
+ openDrawer();
259
320
  }
260
321
  ;
261
322
  return response == null ? void 0 : response.result;
262
323
  },
263
- [affiliate, cart, cartRoot, cartStorageKey, data]
324
+ [cart, cartRoot, cartStorageKey, openDrawer, who]
264
325
  );
265
- const onCartLineUpdate = (0, import_react.useCallback)(
266
- async (lineId, quantity) => {
326
+ const changeLine = (0, import_react.useCallback)(
327
+ async (lineId, quantity, send) => {
267
328
  var _a2;
268
329
  if (!(cart == null ? void 0 : cart.id)) return;
269
- const response = await (0, import_fetch.request)({
270
- body: {
271
- cartId: cart.id,
272
- lines: [
273
- {
274
- id: lineId,
275
- quantity
276
- }
277
- ]
278
- },
279
- endpoint: cartRoot + "/lines",
280
- method: "PUT"
281
- });
282
- 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
+ }
283
339
  },
284
- [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]
285
358
  );
286
359
  const onCartLineRemove = (0, import_react.useCallback)(
287
- async (lineId) => {
288
- var _a2, _b2;
289
- if (!(cart == null ? void 0 : cart.id)) return;
290
- const response = await (0, import_fetch.request)({
291
- body: {
292
- cartId: cart.id,
293
- lineIds: [lineId]
294
- },
295
- endpoint: cartRoot + "/lines",
296
- method: "DELETE"
297
- });
298
- if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
299
- setCart(response.result);
300
- if (!((_b2 = response.result.lines) == null ? void 0 : _b2.length) && typeof window !== "undefined") {
301
- window.localStorage.removeItem(cartStorageKey);
302
- }
303
- ;
304
- }
305
- ;
306
- },
307
- [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]
308
369
  );
309
370
  const tracking = (0, import_provider_analytics.useTracking)({
310
371
  params,
@@ -316,7 +377,7 @@ const TemplateLayout = ({
316
377
  event,
317
378
  preview: preview2
318
379
  }) => {
319
- var _a2, _b2, _c2, _d2, _e, _f, _g;
380
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k;
320
381
  let trusted = false;
321
382
  try {
322
383
  trusted = Boolean(
@@ -328,16 +389,34 @@ const TemplateLayout = ({
328
389
  if (preview2 && trusted) {
329
390
  setIframe(true);
330
391
  }
331
- if (preview2 && trusted && ((_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.update)) {
332
- const headline = ((_c2 = (_b2 = event == null ? void 0 : event.data) == null ? void 0 : _b2.update) == null ? void 0 : _c2.headline) || ((_d2 = result == null ? void 0 : result.data) == null ? void 0 : _d2.headline) || ((_f = (_e = import_constants.default) == null ? void 0 : _e.form) == null ? void 0 : _f.headline);
392
+ if (preview2 && trusted && ((_b2 = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.open) == null ? void 0 : _b2.step)) {
393
+ const shown = (0, import_entry.previewStep)({
394
+ ...result,
395
+ ...(_c2 = event == null ? void 0 : event.data) == null ? void 0 : _c2.update
396
+ }, event.data.open);
397
+ setFace(shown.face);
398
+ setModal(shown.modal);
399
+ if (((_d2 = shown.panel) == null ? void 0 : _d2.name) === "submission") setPanel({
400
+ name: "submission",
401
+ data: {
402
+ ...shown.panel.data,
403
+ preview: preview2,
404
+ style: result == null ? void 0 : result.style,
405
+ ...params
406
+ }
407
+ });
408
+ else if (shown.panel) setPanel(shown.panel);
409
+ }
410
+ if (preview2 && trusted && ((_e = event == null ? void 0 : event.data) == null ? void 0 : _e.update)) {
411
+ const headline = ((_g = (_f = event == null ? void 0 : event.data) == null ? void 0 : _f.update) == null ? void 0 : _g.headline) || ((_h = result == null ? void 0 : result.data) == null ? void 0 : _h.headline) || ((_j = (_i = import_constants.default) == null ? void 0 : _i.form) == null ? void 0 : _j.headline);
333
412
  setData({
334
413
  ...result,
335
- ...(_g = event == null ? void 0 : event.data) == null ? void 0 : _g.update,
414
+ ...(_k = event == null ? void 0 : event.data) == null ? void 0 : _k.update,
336
415
  headline
337
416
  });
338
417
  }
339
418
  },
340
- [result]
419
+ [params, result]
341
420
  );
342
421
  (0, import_react.useEffect)(
343
422
  () => {
@@ -393,8 +472,21 @@ const TemplateLayout = ({
393
472
  }
394
473
  });
395
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
+ ;
396
488
  },
397
- [affiliate, data, params, preview, style]
489
+ [affiliate, cart == null ? void 0 : cart.id, cartRoot, data, params, preview, style]
398
490
  );
399
491
  const leadMission = searchParams.get("open");
400
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 });
@@ -467,7 +559,7 @@ const TemplateLayout = ({
467
559
  return {
468
560
  branding: branding(),
469
561
  brandingCompact: branding(true),
470
- close: (name) => {
562
+ close: (name, onClose) => {
471
563
  var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
472
564
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
473
565
  import_button.default,
@@ -476,7 +568,7 @@ const TemplateLayout = ({
476
568
  "aria-label": "Close Modal",
477
569
  inline: true,
478
570
  onClick: () => {
479
- setModal(false);
571
+ (onClose || (() => setModal(false)))();
480
572
  tracking.track({
481
573
  name: "button-" + name + "-close"
482
574
  });
@@ -516,7 +608,7 @@ const TemplateLayout = ({
516
608
  import_button.default,
517
609
  {
518
610
  ...{
519
- disabled: !preview && !(data == null ? void 0 : data.valid),
611
+ disabled: !preview && !(data == null ? void 0 : data.valid) || face === "inactive",
520
612
  onClick: () => {
521
613
  setPanel({
522
614
  name: "enter"
@@ -528,7 +620,7 @@ const TemplateLayout = ({
528
620
  },
529
621
  style
530
622
  },
531
- children: (0, import_entry.buttonText)(data, preview || Boolean(data == null ? void 0 : data.valid))
623
+ children: face ? (0, import_entry.copy)(data, face) : (0, import_entry.buttonText)(data, preview || Boolean(data == null ? void 0 : data.valid))
532
624
  }
533
625
  ),
534
626
  menu: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -627,10 +719,7 @@ const TemplateLayout = ({
627
719
  "aria-label": "Open Shop",
628
720
  inline: true,
629
721
  onClick: () => {
630
- setPanel({
631
- name
632
- });
633
- setModal(true);
722
+ openDrawer();
634
723
  tracking.track({
635
724
  name: "button-" + name + "-open"
636
725
  });
@@ -684,7 +773,7 @@ const TemplateLayout = ({
684
773
  }
685
774
  };
686
775
  },
687
- [cartCount, cartLoading, data, preview, style, tracking]
776
+ [cartCount, cartLoading, data, face, openDrawer, preview, style, tracking]
688
777
  );
689
778
  const props = {
690
779
  affiliate,
@@ -736,20 +825,65 @@ const TemplateLayout = ({
736
825
  }
737
826
  }
738
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
+ ),
739
876
  opened && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
740
877
  TemplateModal,
741
878
  {
742
879
  ...{
743
880
  buttons,
744
- cart,
745
881
  checkout,
746
882
  data,
747
883
  fonts,
748
884
  iframe,
749
885
  modal,
750
886
  onAddToCart,
751
- onCartLineRemove,
752
- onCartLineUpdate,
753
887
  openCheckout,
754
888
  panel,
755
889
  params,