@drawbridge/components 0.1.48 → 0.1.50

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 +3 -3
  12. package/dist/bridge/lib/entry.mjs +2 -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 +123 -238
  16. package/dist/bridge/template-layout.mjs +124 -239
  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 +3 -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
@@ -8,7 +8,7 @@ import FormSubdomainHeader from "./form-subdomain-header.mjs";
8
8
  import FormSubdomainIssue from "./form-subdomain-issue.mjs";
9
9
  import FormSubdomainPrize from "./form-subdomain-prize.mjs";
10
10
  import ProviderRecaptcha from "../shared/provider-recaptcha.mjs";
11
- import { FormSubdomainProduct } from "./form-subdomain-shop-modal.mjs";
11
+ import { FormSubdomainCart, FormSubdomainProduct } from "./form-subdomain-shop-modal.mjs";
12
12
  import TemplateSubdomainLink from "./template-subdomain-link.mjs";
13
13
  import FormSubdomainMissions from "./form-subdomain-missions.mjs";
14
14
  import Tabs from "../shared/tabs.mjs";
@@ -21,12 +21,15 @@ import { afterOrder, agreementName, agreementTitles, copy, formOn, giveawayOn, m
21
21
  import { motion } from "../shared/lib/motion.mjs";
22
22
  const TemplateModal = ({
23
23
  buttons,
24
+ cart,
24
25
  checkout,
25
26
  data,
26
27
  fonts,
27
28
  iframe,
28
29
  modal,
29
30
  onAddToCart,
31
+ onCartLineRemove,
32
+ onCartLineUpdate,
30
33
  openCheckout,
31
34
  panel,
32
35
  params,
@@ -44,6 +47,27 @@ const TemplateModal = ({
44
47
  var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
45
48
  const agreements = (data == null ? void 0 : data.agreements) || {};
46
49
  switch (panel == null ? void 0 : panel.name) {
50
+ case "cart":
51
+ return /* @__PURE__ */ jsx(
52
+ FormSubdomainCart,
53
+ {
54
+ ...{
55
+ button: buttons.close("cart"),
56
+ cart,
57
+ onLineRemove: onCartLineRemove,
58
+ onLineUpdate: onCartLineUpdate,
59
+ onSuccess: ({ result }) => {
60
+ tracking.track({
61
+ name: "shop-checkout",
62
+ data: result
63
+ });
64
+ openCheckout(result.checkoutUrl);
65
+ },
66
+ style,
67
+ tracking
68
+ }
69
+ }
70
+ );
47
71
  case "enter":
48
72
  if (!formOn(data)) return null;
49
73
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -425,39 +449,60 @@ const TemplateModal = ({
425
449
  }
426
450
  )
427
451
  ] });
428
- // @story checkout/cart
429
- // A product in its own window, which shows no cart of its own: Add to
430
- // cart closes it onto the cart drawer ( template-layout.js ).
431
452
  case "product":
432
453
  return /* @__PURE__ */ jsx(
433
- FormSubdomainProduct,
454
+ FormSubdomainCart,
434
455
  {
435
456
  ...{
436
- back: (_u = panel.data) == null ? void 0 : _u.back,
437
- button: buttons.close("product"),
438
- onAddToCart: async (item) => {
439
- var _a3, _b3, _c3, _d3, _e3, _f3;
440
- await onAddToCart(item);
441
- const productSlug = (_b3 = (_a3 = item.product) == null ? void 0 : _a3.title) == null ? void 0 : _b3.toLowerCase().replace(/\s+/g, "-");
442
- const isDefaultVariant = !((_c3 = item.variant) == null ? void 0 : _c3.title) || ((_d3 = item.variant) == null ? void 0 : _d3.title) === "Default Title";
443
- if (isDefaultVariant) {
444
- tracking.track({ name: "product-" + productSlug + "-add-cart" });
445
- } else {
446
- const variantSlug = (_f3 = (_e3 = item.variant) == null ? void 0 : _e3.title) == null ? void 0 : _f3.toLowerCase().replace(/\s+/g, "-");
447
- tracking.track({ name: "product-" + productSlug + "-" + variantSlug + "-add-cart" });
448
- }
449
- ;
457
+ cart,
458
+ drawer: !((_v = (_u = panel.data) == null ? void 0 : _u.product) == null ? void 0 : _v.sample),
459
+ onLineRemove: onCartLineRemove,
460
+ onLineUpdate: onCartLineUpdate,
461
+ onSuccess: ({ result }) => {
462
+ tracking.track({
463
+ name: "shop-checkout",
464
+ data: result
465
+ });
466
+ openCheckout(result.checkoutUrl);
450
467
  },
451
- onError: ({ message }) => setPanel({
452
- name: "error",
453
- data: {
454
- message
468
+ style,
469
+ tracking
470
+ },
471
+ children: (setShow) => {
472
+ var _a3, _b3;
473
+ return /* @__PURE__ */ jsx(
474
+ FormSubdomainProduct,
475
+ {
476
+ ...{
477
+ back: (_a3 = panel.data) == null ? void 0 : _a3.back,
478
+ button: buttons.close("product"),
479
+ onAddToCart: async (item) => {
480
+ var _a4, _b4, _c3, _d3, _e3, _f3;
481
+ await onAddToCart(item);
482
+ const productSlug = (_b4 = (_a4 = item.product) == null ? void 0 : _a4.title) == null ? void 0 : _b4.toLowerCase().replace(/\s+/g, "-");
483
+ const isDefaultVariant = !((_c3 = item.variant) == null ? void 0 : _c3.title) || ((_d3 = item.variant) == null ? void 0 : _d3.title) === "Default Title";
484
+ if (isDefaultVariant) {
485
+ tracking.track({ name: "product-" + productSlug + "-add-cart" });
486
+ } else {
487
+ const variantSlug = (_f3 = (_e3 = item.variant) == null ? void 0 : _e3.title) == null ? void 0 : _f3.toLowerCase().replace(/\s+/g, "-");
488
+ tracking.track({ name: "product-" + productSlug + "-" + variantSlug + "-add-cart" });
489
+ }
490
+ ;
491
+ setShow(true);
492
+ },
493
+ onError: ({ message }) => setPanel({
494
+ name: "error",
495
+ data: {
496
+ message
497
+ }
498
+ }),
499
+ checkout,
500
+ tracking,
501
+ product: (_b3 = panel.data) == null ? void 0 : _b3.product,
502
+ style
503
+ }
455
504
  }
456
- }),
457
- checkout,
458
- tracking,
459
- product: (_v = panel.data) == null ? void 0 : _v.product,
460
- style
505
+ );
461
506
  }
462
507
  }
463
508
  );
@@ -524,7 +569,7 @@ const TemplateModal = ({
524
569
  return null;
525
570
  }
526
571
  },
527
- [buttons, checkout, data, iframe, onAddToCart, openCheckout, panel, params, preview, style, submission, tracking]
572
+ [buttons, cart, checkout, data, iframe, onAddToCart, onCartLineRemove, onCartLineUpdate, openCheckout, panel, params, preview, style, submission, tracking]
528
573
  );
529
574
  return (
530
575
  // reCAPTCHA stays scoped to the modal — this whole module is
@@ -241,7 +241,7 @@ const useSubscriptionActions = (params) => {
241
241
  },
242
242
  children: [
243
243
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Your subscription will cancel at the end of your current billing period. You'll keep all paid features until then." }),
244
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "After it cancels, you're on Free and workflow steps Free doesn't include stop running. Your campaigns, pages, brands and prizes will be drafted. They won't be deleted, but you'll need to reactivate each one if you re-subscribe." }),
244
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "After it cancels, your campaigns' workflows stop running, and your campaigns, pages, brands and prizes will be drafted. They won't be deleted, but you'll need to reactivate each one if you re-subscribe." }),
245
245
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Your subdomain and page addresses go back to their short IDs, your ads are drafted and your members lose access." }),
246
246
  smsNumber && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
247
247
  "Your SMS number, ",
@@ -205,7 +205,7 @@ const useSubscriptionActions = (params) => {
205
205
  },
206
206
  children: [
207
207
  /* @__PURE__ */ jsx("p", { children: "Your subscription will cancel at the end of your current billing period. You'll keep all paid features until then." }),
208
- /* @__PURE__ */ jsx("p", { children: "After it cancels, you're on Free and workflow steps Free doesn't include stop running. Your campaigns, pages, brands and prizes will be drafted. They won't be deleted, but you'll need to reactivate each one if you re-subscribe." }),
208
+ /* @__PURE__ */ jsx("p", { children: "After it cancels, your campaigns' workflows stop running, and your campaigns, pages, brands and prizes will be drafted. They won't be deleted, but you'll need to reactivate each one if you re-subscribe." }),
209
209
  /* @__PURE__ */ jsx("p", { children: "Your subdomain and page addresses go back to their short IDs, your ads are drafted and your members lose access." }),
210
210
  smsNumber && /* @__PURE__ */ jsxs("p", { children: [
211
211
  "Your SMS number, ",
@@ -614,8 +614,6 @@ const Step = ({
614
614
  collapsed,
615
615
  currency,
616
616
  fonts,
617
- // Every field type on the form, across its sections.
618
- formKeys,
619
617
  handle,
620
618
  last,
621
619
  params,
@@ -638,7 +636,6 @@ const Step = ({
638
636
  const on = (0, import_form_page.sectionOn)(section);
639
637
  const shown = on && !collapsed;
640
638
  const card = (0, import_preview.useCard)(section.id);
641
- const keys = formKeys || section.keys;
642
639
  const add = () => modal.open({
643
640
  message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
644
641
  Choices,
@@ -646,8 +643,8 @@ const Step = ({
646
643
  ...{
647
644
  choices: (section.inputs || []).map(({ slug, title, ...input }) => ({
648
645
  ...input,
649
- disabled: (0, import_form_page.addedOnce)(slug, keys),
650
- message: (0, import_form_page.addedOnce)(slug, keys) ? "Field has already been added" : input.granted === false ? input.message : null,
646
+ disabled: (0, import_form_page.addedOnce)(slug, section.keys),
647
+ message: (0, import_form_page.addedOnce)(slug, section.keys) ? "Field has already been added" : input.granted === false ? input.message : null,
651
648
  onClick: () => actions.manage({
652
649
  ...input,
653
650
  section,
@@ -1570,7 +1567,6 @@ const CampaignForm = ({
1570
1567
  });
1571
1568
  onOpened == null ? void 0 : onOpened();
1572
1569
  }, [open]);
1573
- const formKeys = (Array.isArray(sections) ? sections : []).flatMap((section) => (section == null ? void 0 : section.keys) || []);
1574
1570
  const choices = customs.map((section) => ({
1575
1571
  description: section.description,
1576
1572
  label: section.title,
@@ -1626,7 +1622,6 @@ const CampaignForm = ({
1626
1622
  collapsed,
1627
1623
  currency,
1628
1624
  fonts,
1629
- formKeys,
1630
1625
  handle,
1631
1626
  last: section.id === lastId,
1632
1627
  params,
@@ -582,8 +582,6 @@ const Step = ({
582
582
  collapsed,
583
583
  currency,
584
584
  fonts,
585
- // Every field type on the form, across its sections.
586
- formKeys,
587
585
  handle,
588
586
  last,
589
587
  params,
@@ -606,7 +604,6 @@ const Step = ({
606
604
  const on = sectionOn(section);
607
605
  const shown = on && !collapsed;
608
606
  const card = useCard(section.id);
609
- const keys = formKeys || section.keys;
610
607
  const add = () => modal.open({
611
608
  message: /* @__PURE__ */ jsx(
612
609
  Choices,
@@ -614,8 +611,8 @@ const Step = ({
614
611
  ...{
615
612
  choices: (section.inputs || []).map(({ slug, title, ...input }) => ({
616
613
  ...input,
617
- disabled: addedOnce(slug, keys),
618
- message: addedOnce(slug, keys) ? "Field has already been added" : input.granted === false ? input.message : null,
614
+ disabled: addedOnce(slug, section.keys),
615
+ message: addedOnce(slug, section.keys) ? "Field has already been added" : input.granted === false ? input.message : null,
619
616
  onClick: () => actions.manage({
620
617
  ...input,
621
618
  section,
@@ -1538,7 +1535,6 @@ const CampaignForm = ({
1538
1535
  });
1539
1536
  onOpened == null ? void 0 : onOpened();
1540
1537
  }, [open]);
1541
- const formKeys = (Array.isArray(sections) ? sections : []).flatMap((section) => (section == null ? void 0 : section.keys) || []);
1542
1538
  const choices = customs.map((section) => ({
1543
1539
  description: section.description,
1544
1540
  label: section.title,
@@ -1594,7 +1590,6 @@ const CampaignForm = ({
1594
1590
  collapsed,
1595
1591
  currency,
1596
1592
  fonts,
1597
- formKeys,
1598
1593
  handle,
1599
1594
  last: section.id === lastId,
1600
1595
  params,
@@ -34,14 +34,11 @@ var import_jsx_runtime = require("react/jsx-runtime");
34
34
  var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
35
35
  var import_card_data_item = __toESM(require("./card-data-item"));
36
36
  var import_card_shortcut = __toESM(require("./card-shortcut"));
37
- var import_button = __toESM(require("../shared/button"));
38
- var import_products = require("./lib/products");
39
37
  var import_answer_rows = require("./answer-rows");
40
38
  const className = "p-3 bg-white rounded shadow-[0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)]";
41
39
  const attributions = {
42
40
  conversion: "A campaign link brought the buyer to checkout, so the conversion fee applies.",
43
- redemption: "The buyer used one of your discount codes, so no fee applies.",
44
- sale: "This sale came through your campaign page, so the sales fee applies."
41
+ redemption: "The buyer used one of your discount codes, so no fee applies."
45
42
  };
46
43
  const date = (value) => value ? (0, import_drawbridge_utils.formatDateString)({
47
44
  date: value,
@@ -67,7 +64,7 @@ const lineSummary = ({ code, price, quantity = 0, variantTitle }) => [
67
64
  variantTitle,
68
65
  typeof price === "number" ? (0, import_drawbridge_utils.formatNumber)(quantity) + " \xD7 " + (0, import_drawbridge_utils.formatCurrency)({ code, value: price }) : "Quantity " + (0, import_drawbridge_utils.formatNumber)(quantity)
69
66
  ].filter(Boolean).join(" \xB7 ");
70
- const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
67
+ const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
71
68
  "div",
72
69
  {
73
70
  ...{
@@ -93,20 +90,7 @@ const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 &
93
90
  import_card_shortcut.default,
94
91
  {
95
92
  ...{
96
- ...onResend && typeof line.file === "string" && {
97
- controls: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
- import_button.default,
99
- {
100
- ...{
101
- onClick: onResend,
102
- size: "small",
103
- variant: "secondary"
104
- },
105
- children: "Resend download"
106
- }
107
- )
108
- },
109
- description: [lineSummary({ code, ...line }), typeof line.file === "string" ? (0, import_products.downloadsText)(line.downloads || 0) : null].filter(Boolean).join(" \xB7 "),
93
+ description: lineSummary({ code, ...line }),
110
94
  image: line.image,
111
95
  title: line.title || untitled
112
96
  }
@@ -265,7 +249,6 @@ const CardOrder = ({
265
249
  gross = 0,
266
250
  lines = [],
267
251
  net = 0,
268
- onResend,
269
252
  provider,
270
253
  purchasedAt,
271
254
  rate,
@@ -296,7 +279,7 @@ const CardOrder = ({
296
279
  className: "space-y-6"
297
280
  },
298
281
  children: [
299
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: attributions[(provider == null ? void 0 : provider.slug) === "stripe" ? "sale" : type] || attributions.conversion }),
282
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: attributions[type] || attributions.conversion }),
300
283
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
301
284
  "div",
302
285
  {
@@ -379,7 +362,6 @@ const CardOrder = ({
379
362
  label: "Products",
380
363
  // A store line always has a price.
381
364
  lines: lines.map((line) => ({ ...line, price: line.price || 0 })),
382
- onResend,
383
365
  untitled: "Untitled product"
384
366
  }
385
367
  }
@@ -2,14 +2,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { formatCurrency, formatDateString, formatNumber } from "@drawbridge/drawbridge-utils";
3
3
  import CardDataItem from "./card-data-item.mjs";
4
4
  import CardShortcut from "./card-shortcut.mjs";
5
- import Button from "../shared/button.mjs";
6
- import { downloadsText } from "./lib/products.mjs";
7
5
  import { answerRows } from "./answer-rows.mjs";
8
6
  const className = "p-3 bg-white rounded shadow-[0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)]";
9
7
  const attributions = {
10
8
  conversion: "A campaign link brought the buyer to checkout, so the conversion fee applies.",
11
- redemption: "The buyer used one of your discount codes, so no fee applies.",
12
- sale: "This sale came through your campaign page, so the sales fee applies."
9
+ redemption: "The buyer used one of your discount codes, so no fee applies."
13
10
  };
14
11
  const date = (value) => value ? formatDateString({
15
12
  date: value,
@@ -35,7 +32,7 @@ const lineSummary = ({ code, price, quantity = 0, variantTitle }) => [
35
32
  variantTitle,
36
33
  typeof price === "number" ? formatNumber(quantity) + " \xD7 " + formatCurrency({ code, value: price }) : "Quantity " + formatNumber(quantity)
37
34
  ].filter(Boolean).join(" \xB7 ");
38
- const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 && /* @__PURE__ */ jsxs(
35
+ const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PURE__ */ jsxs(
39
36
  "div",
40
37
  {
41
38
  ...{
@@ -61,20 +58,7 @@ const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 &
61
58
  CardShortcut,
62
59
  {
63
60
  ...{
64
- ...onResend && typeof line.file === "string" && {
65
- controls: /* @__PURE__ */ jsx(
66
- Button,
67
- {
68
- ...{
69
- onClick: onResend,
70
- size: "small",
71
- variant: "secondary"
72
- },
73
- children: "Resend download"
74
- }
75
- )
76
- },
77
- description: [lineSummary({ code, ...line }), typeof line.file === "string" ? downloadsText(line.downloads || 0) : null].filter(Boolean).join(" \xB7 "),
61
+ description: lineSummary({ code, ...line }),
78
62
  image: line.image,
79
63
  title: line.title || untitled
80
64
  }
@@ -233,7 +217,6 @@ const CardOrder = ({
233
217
  gross = 0,
234
218
  lines = [],
235
219
  net = 0,
236
- onResend,
237
220
  provider,
238
221
  purchasedAt,
239
222
  rate,
@@ -264,7 +247,7 @@ const CardOrder = ({
264
247
  className: "space-y-6"
265
248
  },
266
249
  children: [
267
- /* @__PURE__ */ jsx("p", { children: attributions[(provider == null ? void 0 : provider.slug) === "stripe" ? "sale" : type] || attributions.conversion }),
250
+ /* @__PURE__ */ jsx("p", { children: attributions[type] || attributions.conversion }),
268
251
  /* @__PURE__ */ jsxs(
269
252
  "div",
270
253
  {
@@ -347,7 +330,6 @@ const CardOrder = ({
347
330
  label: "Products",
348
331
  // A store line always has a price.
349
332
  lines: lines.map((line) => ({ ...line, price: line.price || 0 })),
350
- onResend,
351
333
  untitled: "Untitled product"
352
334
  }
353
335
  }
@@ -50,7 +50,15 @@ const mount = (dom, element) => {
50
50
  root.render(element);
51
51
  return () => setTimeout(() => root.unmount());
52
52
  };
53
+ const lockedCount = (doc, locked) => {
54
+ let count = 0;
55
+ doc.descendants((node) => {
56
+ count += node.type.name === "piece" && locked.includes(node.attrs.key) ? 1 : 0;
57
+ });
58
+ return count;
59
+ };
53
60
  const documentNodes = (options) => {
61
+ const locked = (options == null ? void 0 : options.locked) || [];
54
62
  const Piece = import_core.Node.create({
55
63
  name: "piece",
56
64
  atom: true,
@@ -88,7 +96,7 @@ const documentNodes = (options) => {
88
96
  }
89
97
  }
90
98
  ),
91
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
99
+ !locked.includes(node.attrs.key) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
100
  "span",
93
101
  {
94
102
  ...{
@@ -123,7 +131,12 @@ const documentNodes = (options) => {
123
131
  return Boolean((_b = (_a2 = event.target) == null ? void 0 : _a2.closest) == null ? void 0 : _b.call(_a2, "input, button"));
124
132
  }
125
133
  };
126
- }
134
+ },
135
+ addProseMirrorPlugins: () => locked.length ? [
136
+ new import_state.Plugin({
137
+ filterTransaction: (tr, state) => !tr.docChanged || tr.getMeta("preventUpdate") !== void 0 || lockedCount(tr.doc, locked) >= lockedCount(state.doc, locked)
138
+ })
139
+ ] : []
127
140
  });
128
141
  const Generated = import_core.Node.create({
129
142
  name: "generated",
@@ -206,7 +219,7 @@ const insertPiece = (editor, key) => {
206
219
  editor.view.dispatch(tr.scrollIntoView());
207
220
  editor.view.focus();
208
221
  };
209
- const documentBlocks = ({ data, insertable = [], onClaim }) => {
222
+ const documentBlocks = ({ data, insertable = [], locked, onClaim }) => {
210
223
  const text = ({ active, disabled, editor, tool }, title, label, on, run) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
211
224
  import_button.default,
212
225
  {
@@ -246,7 +259,7 @@ const documentBlocks = ({ data, insertable = [], onClaim }) => {
246
259
  return (_a2 = context.editor) == null ? void 0 : _a2.chain().focus().toggleHeading({ level: 2 }).run();
247
260
  });
248
261
  },
249
- extensions: documentNodes({ data, onClaim }),
262
+ extensions: documentNodes({ data, locked, onClaim }),
250
263
  insert: ({ disabled, editor }) => {
251
264
  const inDocument = present(editor);
252
265
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -15,7 +15,15 @@ const mount = (dom, element) => {
15
15
  root.render(element);
16
16
  return () => setTimeout(() => root.unmount());
17
17
  };
18
+ const lockedCount = (doc, locked) => {
19
+ let count = 0;
20
+ doc.descendants((node) => {
21
+ count += node.type.name === "piece" && locked.includes(node.attrs.key) ? 1 : 0;
22
+ });
23
+ return count;
24
+ };
18
25
  const documentNodes = (options) => {
26
+ const locked = (options == null ? void 0 : options.locked) || [];
19
27
  const Piece = Node.create({
20
28
  name: "piece",
21
29
  atom: true,
@@ -53,7 +61,7 @@ const documentNodes = (options) => {
53
61
  }
54
62
  }
55
63
  ),
56
- /* @__PURE__ */ jsx(
64
+ !locked.includes(node.attrs.key) && /* @__PURE__ */ jsx(
57
65
  "span",
58
66
  {
59
67
  ...{
@@ -88,7 +96,12 @@ const documentNodes = (options) => {
88
96
  return Boolean((_b = (_a2 = event.target) == null ? void 0 : _a2.closest) == null ? void 0 : _b.call(_a2, "input, button"));
89
97
  }
90
98
  };
91
- }
99
+ },
100
+ addProseMirrorPlugins: () => locked.length ? [
101
+ new Plugin({
102
+ filterTransaction: (tr, state) => !tr.docChanged || tr.getMeta("preventUpdate") !== void 0 || lockedCount(tr.doc, locked) >= lockedCount(state.doc, locked)
103
+ })
104
+ ] : []
92
105
  });
93
106
  const Generated = Node.create({
94
107
  name: "generated",
@@ -171,7 +184,7 @@ const insertPiece = (editor, key) => {
171
184
  editor.view.dispatch(tr.scrollIntoView());
172
185
  editor.view.focus();
173
186
  };
174
- const documentBlocks = ({ data, insertable = [], onClaim }) => {
187
+ const documentBlocks = ({ data, insertable = [], locked, onClaim }) => {
175
188
  const text = ({ active, disabled, editor, tool }, title, label, on, run) => /* @__PURE__ */ jsx(
176
189
  Button,
177
190
  {
@@ -211,7 +224,7 @@ const documentBlocks = ({ data, insertable = [], onClaim }) => {
211
224
  return (_a2 = context.editor) == null ? void 0 : _a2.chain().focus().toggleHeading({ level: 2 }).run();
212
225
  });
213
226
  },
214
- extensions: documentNodes({ data, onClaim }),
227
+ extensions: documentNodes({ data, locked, onClaim }),
215
228
  insert: ({ disabled, editor }) => {
216
229
  const inDocument = present(editor);
217
230
  return /* @__PURE__ */ jsx(
@@ -33,7 +33,6 @@ __export(form_admin_provider_exports, {
33
33
  module.exports = __toCommonJS(form_admin_provider_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_react = require("react");
36
- var import_react_query = require("@tanstack/react-query");
37
36
  var import_form = require("../shared/lib/form");
38
37
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
39
38
  var import_yup = __toESM(require("../shared/lib/yup"));
@@ -45,18 +44,11 @@ var import_input_switch = __toESM(require("../shared/input-switch"));
45
44
  var import_card_task = __toESM(require("./card-task"));
46
45
  var import_input_secret = __toESM(require("./input-secret"));
47
46
  var import_button = __toESM(require("../shared/button"));
48
- var import_form_organization_connection = require("./form-organization-connection");
49
- var import_settings_paths = require("./lib/settings-paths");
50
- const schemaFor = (field, enabled) => {
47
+ const schemaFor = (field) => {
51
48
  if (field.input === "switch") return import_yup.default.boolean().label(field.label);
52
49
  const rule = field.input === "email" ? import_yup.default.string().label(field.label).email() : import_yup.default.string().label(field.label);
53
- return enabled && field.required && !field.redact && !field.hook ? rule.required() : rule.nullable();
50
+ return field.required && !field.redact ? rule.when("enabled", { is: false, otherwise: (s) => s.required(), then: (s) => s.nullable() }) : rule.nullable();
54
51
  };
55
- const shape = (tree) => import_yup.default.object(
56
- Object.fromEntries(
57
- Object.entries(tree).map(([key, node]) => [key, import_yup.default.isSchema(node) ? node : shape(node)])
58
- )
59
- );
60
52
  const FormAdminProvider = ({
61
53
  onError,
62
54
  onSuccess,
@@ -69,37 +61,25 @@ const FormAdminProvider = ({
69
61
  // A row that has never been touched has no answer stored and is on, so
70
62
  // the box starts checked rather than empty.
71
63
  enabled: (values == null ? void 0 : values.enabled) !== false,
72
- ...(0, import_settings_paths.nestPaths)(
73
- fields.map((field) => [
74
- field.key,
75
- field.input === "switch" ? (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key) === true : field.redact ? "" : (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key) ?? ""
76
- ])
64
+ ...Object.fromEntries(
65
+ fields.map((field) => {
66
+ var _a, _b;
67
+ return [
68
+ field.key,
69
+ field.input === "switch" ? ((_a = values == null ? void 0 : values.settings) == null ? void 0 : _a[field.key]) === true : field.redact ? "" : ((_b = values == null ? void 0 : values.settings) == null ? void 0 : _b[field.key]) ?? ""
70
+ ];
71
+ })
77
72
  )
78
73
  }),
79
74
  [fields, values]
80
75
  );
81
76
  const schema = (0, import_react.useMemo)(
82
- () => import_yup.default.lazy((data) => shape({
77
+ () => import_yup.default.object({
83
78
  enabled: import_yup.default.boolean().label("Enabled"),
84
- ...(0, import_settings_paths.nestPaths)(fields.map((field) => [field.key, schemaFor(field, (data == null ? void 0 : data.enabled) !== false)]))
85
- })),
79
+ ...Object.fromEntries(fields.map((field) => [field.key, schemaFor(field)]))
80
+ }),
86
81
  [fields]
87
82
  );
88
- const hooked = (0, import_react.useMemo)(() => fields.filter((field) => field.hook), [fields]);
89
- const sourced = (0, import_react_query.useQueries)({
90
- queries: hooked.map((field) => ({
91
- enabled: Boolean(values == null ? void 0 : values.slug),
92
- queryFn: async () => {
93
- const { result } = await (0, import_fetch.request)({
94
- endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug) + "/hook/" + field.hook,
95
- params: { limit: 100 }
96
- });
97
- return ((result == null ? void 0 : result.items) || []).map((item) => ({ label: item.title, value: item.id }));
98
- },
99
- queryKey: ["admin-provider-hook", values == null ? void 0 : values.slug, field.hook, values == null ? void 0 : values.settings]
100
- }))
101
- });
102
- const optionsFor = Object.fromEntries(hooked.map((field, index) => [field.key, sourced[index]]));
103
83
  const [clearing, setClearing] = (0, import_react.useState)([]);
104
84
  (0, import_react.useEffect)(() => setClearing([]), [values == null ? void 0 : values.slug]);
105
85
  const { control, formState, handleSubmit } = (0, import_form.useForm)({
@@ -124,20 +104,10 @@ const FormAdminProvider = ({
124
104
  // admin then TYPED INTO is a replacement, not a removal. The api
125
105
  // applies `clear` after `settings`, so naming a key that also
126
106
  // carries a value deleted the value just typed and answered "Saved".
127
- //
128
- // `clear` stays a list of dotted keys; `settings` goes nested,
129
- // the shape the api stores.
130
- //
131
- // A PICKER EMPTIED IS A REMOVAL TOO. Its trash empties the value,
132
- // and blank would keep the saved one, so a picker that held a
133
- // saved value and is empty now is named here as well.
134
- clear: [
135
- ...clearing.filter((key) => !(0, import_settings_paths.readPath)(data, key)),
136
- ...fields.filter((field) => field.hook && !(0, import_settings_paths.readPath)(data, field.key) && (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key)).map((field) => field.key)
137
- ],
107
+ clear: clearing.filter((key) => !(data == null ? void 0 : data[key])),
138
108
  enabled: Boolean(data == null ? void 0 : data.enabled),
139
- settings: (0, import_settings_paths.nestPaths)(
140
- fields.map((field) => [field.key, (0, import_settings_paths.readPath)(data, field.key) ?? ""])
109
+ settings: Object.fromEntries(
110
+ fields.map((field) => [field.key, (data == null ? void 0 : data[field.key]) ?? ""])
141
111
  )
142
112
  },
143
113
  endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug),
@@ -263,35 +233,11 @@ const FormAdminProvider = ({
263
233
  value
264
234
  }
265
235
  }
266
- ) : field.input === "select" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
267
- import_input_group.default,
268
- {
269
- ...{
270
- error: (_a = (0, import_settings_paths.readPath)(formState == null ? void 0 : formState.errors, field.key)) == null ? void 0 : _a.message,
271
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
272
- import_form_organization_connection.Editable,
273
- {
274
- ...{
275
- endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug) + "/hook/" + field.hook,
276
- field,
277
- onChange,
278
- titleFor: (id) => {
279
- var _a2, _b2, _c;
280
- return ((_c = (_b2 = (_a2 = optionsFor[field.key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.find((option) => option.value === id)) == null ? void 0 : _c.label) || id;
281
- },
282
- value
283
- }
284
- }
285
- ),
286
- label: field.label,
287
- message: field.message
288
- }
289
- }
290
236
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
291
237
  import_input_group.default,
292
238
  {
293
239
  ...{
294
- error: (_b = (0, import_settings_paths.readPath)(formState == null ? void 0 : formState.errors, field.key)) == null ? void 0 : _b.message,
240
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[field.key]) == null ? void 0 : _b.message,
295
241
  input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
296
242
  import_input_text.default,
297
243
  {