@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
@@ -9,10 +9,8 @@ import InputGroup from "../input-group.mjs";
9
9
  import InputCode from "../input-code.mjs";
10
10
  import Button from "../shared/button.mjs";
11
11
  const FormOtcCode = ({
12
- message,
13
12
  onError,
14
13
  onSuccess,
15
- title = "Authorization",
16
14
  values
17
15
  }) => {
18
16
  const [submitting, setSubmitting] = useState(false);
@@ -48,8 +46,11 @@ const FormOtcCode = ({
48
46
  disabled: submitting
49
47
  },
50
48
  children: [
51
- /* @__PURE__ */ jsx("h3", { children: title }),
52
- /* @__PURE__ */ jsx("p", { children: message || "A code will be sent to " + (values == null ? void 0 : values.identifier) })
49
+ /* @__PURE__ */ jsx("h3", { children: "Authorization" }),
50
+ /* @__PURE__ */ jsxs("p", { children: [
51
+ "A code will be sent to ",
52
+ values == null ? void 0 : values.identifier
53
+ ] })
53
54
  ]
54
55
  }
55
56
  ),
@@ -33,7 +33,6 @@ __export(form_stripe_exports, {
33
33
  module.exports = __toCommonJS(form_stripe_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_fetch = require("@drawbridge/drawbridge-utils/fetch");
38
37
  var import_stripe_js = require("@stripe/stripe-js");
39
38
  var import_navigation = require("next/navigation");
@@ -44,18 +43,14 @@ var import_empty = __toESM(require("../shared/empty"));
44
43
  var import_card_task = __toESM(require("./card-task"));
45
44
  var import_provider_resource = __toESM(require("./provider-resource"));
46
45
  var import_button = __toESM(require("../shared/button"));
47
- const loaders = /* @__PURE__ */ new Map();
48
- const stripeFor = (key) => {
49
- if (!loaders.has(key)) loaders.set(key, (0, import_stripe_js.loadStripe)(key));
50
- return loaders.get(key);
51
- };
46
+ const stripe = (0, import_stripe_js.loadStripe)(process.env.NEXT_PUBLIC_STRIPE_API_KEY);
52
47
  const FormStripeInner = ({
53
48
  button,
54
49
  disabled,
55
50
  onSuccess
56
51
  }) => {
57
52
  const path = (0, import_navigation.usePathname)();
58
- const stripe = (0, import_react_stripe_js.useStripe)();
53
+ const stripe2 = (0, import_react_stripe_js.useStripe)();
59
54
  const elements = (0, import_react_stripe_js.useElements)();
60
55
  const [addressReady, setAddressReady] = (0, import_react.useState)(false);
61
56
  const [error, setError] = (0, import_react.useState)(null);
@@ -81,7 +76,7 @@ const FormStripeInner = ({
81
76
  setAddressReady(false);
82
77
  setPaymentReady(false);
83
78
  setError(null);
84
- const { error: error2, setupIntent } = await stripe.confirmSetup({
79
+ const { error: error2, setupIntent } = await stripe2.confirmSetup({
85
80
  elements,
86
81
  confirmParams: {
87
82
  return_url: process.env.NEXT_PUBLIC_APP_URI + path
@@ -175,16 +170,14 @@ const FormStripe = ({
175
170
  disabled,
176
171
  onSuccess
177
172
  }) => {
178
- var _a, _b;
179
- const key = (_b = (_a = (0, import_react_query.useQueryClient)().getQueryData(["app"])) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey;
180
- if (!clientSecret || !key) {
173
+ if (!clientSecret) {
181
174
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_empty.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Payment was not initialized correctly" }) });
182
175
  }
183
176
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
184
177
  import_react_stripe_js.Elements,
185
178
  {
186
179
  ...{
187
- stripe: stripeFor(key),
180
+ stripe,
188
181
  options: {
189
182
  clientSecret,
190
183
  appearance: {
@@ -1,6 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
- import { useQueryClient } from "@tanstack/react-query";
4
3
  import { request } from "@drawbridge/drawbridge-utils/fetch";
5
4
  import { loadStripe } from "@stripe/stripe-js";
6
5
  import { usePathname } from "next/navigation";
@@ -11,18 +10,14 @@ import Empty from "../shared/empty.mjs";
11
10
  import CardTask from "./card-task.mjs";
12
11
  import ProviderResource from "./provider-resource.mjs";
13
12
  import Button from "../shared/button.mjs";
14
- const loaders = /* @__PURE__ */ new Map();
15
- const stripeFor = (key) => {
16
- if (!loaders.has(key)) loaders.set(key, loadStripe(key));
17
- return loaders.get(key);
18
- };
13
+ const stripe = loadStripe(process.env.NEXT_PUBLIC_STRIPE_API_KEY);
19
14
  const FormStripeInner = ({
20
15
  button,
21
16
  disabled,
22
17
  onSuccess
23
18
  }) => {
24
19
  const path = usePathname();
25
- const stripe = useStripe();
20
+ const stripe2 = useStripe();
26
21
  const elements = useElements();
27
22
  const [addressReady, setAddressReady] = useState(false);
28
23
  const [error, setError] = useState(null);
@@ -48,7 +43,7 @@ const FormStripeInner = ({
48
43
  setAddressReady(false);
49
44
  setPaymentReady(false);
50
45
  setError(null);
51
- const { error: error2, setupIntent } = await stripe.confirmSetup({
46
+ const { error: error2, setupIntent } = await stripe2.confirmSetup({
52
47
  elements,
53
48
  confirmParams: {
54
49
  return_url: process.env.NEXT_PUBLIC_APP_URI + path
@@ -142,16 +137,14 @@ const FormStripe = ({
142
137
  disabled,
143
138
  onSuccess
144
139
  }) => {
145
- var _a, _b;
146
- const key = (_b = (_a = useQueryClient().getQueryData(["app"])) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey;
147
- if (!clientSecret || !key) {
140
+ if (!clientSecret) {
148
141
  return /* @__PURE__ */ jsx(Empty, { children: /* @__PURE__ */ jsx("p", { children: "Payment was not initialized correctly" }) });
149
142
  }
150
143
  return /* @__PURE__ */ jsx(
151
144
  Elements,
152
145
  {
153
146
  ...{
154
- stripe: stripeFor(key),
147
+ stripe,
155
148
  options: {
156
149
  clientSecret,
157
150
  appearance: {
@@ -53,16 +53,19 @@ var import_input_combobox = __toESM(require("./input-combobox"));
53
53
  var import_input_text = __toESM(require("../input-text"));
54
54
  var import_input_textarea = __toESM(require("../input-textarea"));
55
55
  var import_input_switch = __toESM(require("../shared/input-switch"));
56
+ var import_input_array = require("./input-array");
56
57
  var import_input_file = __toESM(require("./input-file"));
57
- var import_input_gallery = __toESM(require("./input-gallery"));
58
58
  var import_hooks = require("./lib/hooks");
59
59
  var import_divider = __toESM(require("../shared/divider"));
60
60
  var import_button = __toESM(require("../shared/button"));
61
61
  var import_map_pin = __toESM(require("../icons/map-pin"));
62
62
  var import_lock = __toESM(require("../icons/lock"));
63
+ var import_plus = __toESM(require("../icons/plus"));
64
+ var import_trash = __toESM(require("../icons/trash"));
63
65
  var import_geo = require("./lib/geo");
64
66
  var import_loader = require("../shared/loader");
65
67
  var import_campaign = require("../shared/lib/campaign");
68
+ const FormReposition = (0, import_dynamic.default)(() => import("./form-reposition"), { loading: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.LoaderDynamic, {}), ssr: false });
66
69
  const InputGoogleAutocomplete = (0, import_dynamic.default)(() => import("./google").then((m) => m.InputGoogleAutocomplete), { loading: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.LoaderDynamic, {}), ssr: false });
67
70
  const switches = [
68
71
  {
@@ -863,17 +866,161 @@ const InputFieldsImages = ({ described, locked, organization, onUpdate, preview
863
866
  )
864
867
  ] });
865
868
  };
866
- const InputFieldsMedia = ({ organization, onUpdate, values = {} }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
867
- import_input_gallery.default,
868
- {
869
- ...{
870
- endpoint: "/organization/" + values.organization,
871
- onUpdate,
872
- organization,
873
- reposition: true
869
+ const InputFieldsMedia = ({ organization, onUpdate, values = {} }) => {
870
+ var _a, _b;
871
+ const queryClient = (0, import_react_query.useQueryClient)();
872
+ const modal = (0, import_hooks.useModal)({ queryClient });
873
+ const { control, formState, getValues, setValue } = (0, import_react_hook_form.useFormContext)();
874
+ const gallery = (0, import_react_hook_form.useWatch)({ control, name: "gallery" }) || [];
875
+ const taken = () => (getValues().gallery || []).map((item) => {
876
+ var _a2;
877
+ return (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.id;
878
+ }).filter(Boolean);
879
+ const change = (path, value) => {
880
+ setValue(path, value, { shouldDirty: true });
881
+ onUpdate == null ? void 0 : onUpdate(getValues());
882
+ };
883
+ const reposition = (index) => {
884
+ var _a2, _b2;
885
+ const item = getValues("gallery." + index);
886
+ modal.open({
887
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
888
+ FormReposition,
889
+ {
890
+ ...{
891
+ file: item == null ? void 0 : item.file,
892
+ onDone: (position) => {
893
+ change("gallery." + index + ".position", position);
894
+ modal.close();
895
+ },
896
+ page: getValues(),
897
+ position: item == null ? void 0 : item.position
898
+ }
899
+ }
900
+ ),
901
+ title: ((_b2 = (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) == null ? void 0 : _b2.includes("video")) ? "Reposition video" : "Reposition photo"
902
+ });
903
+ };
904
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
905
+ import_input_group.default,
906
+ {
907
+ ...{
908
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.gallery) == null ? void 0 : _b.message,
909
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
910
+ import_input_array.InputArraySortable,
911
+ {
912
+ ...{
913
+ control,
914
+ "data-guide": "form-input-gallery",
915
+ empty: "Gallery is empty",
916
+ name: "gallery",
917
+ onSort: () => onUpdate == null ? void 0 : onUpdate(getValues()),
918
+ renderButton: (append) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
919
+ import_input_file.default,
920
+ {
921
+ ...{
922
+ button: {
923
+ icon: import_plus.default,
924
+ text: "Add gallery item"
925
+ },
926
+ endpoint: "/organization/" + values.organization,
927
+ filters: {
928
+ id: {
929
+ $nin: taken()
930
+ }
931
+ },
932
+ onChange: (response) => {
933
+ append({ file: response });
934
+ onUpdate == null ? void 0 : onUpdate(getValues());
935
+ },
936
+ organization,
937
+ nullable: false,
938
+ value: null,
939
+ type: "media"
940
+ }
941
+ }
942
+ ),
943
+ renderControls: ({ index, remove }) => [
944
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
945
+ import_input_array.InputArrayControl,
946
+ {
947
+ ...{
948
+ onClick: () => {
949
+ remove(index);
950
+ onUpdate == null ? void 0 : onUpdate(getValues());
951
+ },
952
+ icon: import_trash.default
953
+ }
954
+ },
955
+ "gallery-control-remove-" + index
956
+ )
957
+ ]
958
+ },
959
+ children: ({ field, handle, index, update }) => {
960
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
961
+ const item = gallery[index] || field;
962
+ const editable = /^(image|video)\//.test(((_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) || "");
963
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
964
+ "div",
965
+ {
966
+ ...{
967
+ className: "flex items-center min-w-0 flex-1 space-x-3"
968
+ },
969
+ children: [
970
+ handle,
971
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
972
+ import_input_group.default,
973
+ {
974
+ ...{
975
+ error: ((_e = (_d = (_c = (_b2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _b2.gallery) == null ? void 0 : _c[index]) == null ? void 0 : _d.file) == null ? void 0 : _e.message) || ((_i = (_h = (_g = (_f = formState == null ? void 0 : formState.errors) == null ? void 0 : _f.gallery) == null ? void 0 : _g[index]) == null ? void 0 : _h.description) == null ? void 0 : _i.message),
976
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
977
+ import_input_file.default,
978
+ {
979
+ ...{
980
+ // The item's own description and crop.
981
+ description: item == null ? void 0 : item.description,
982
+ edited: Boolean(item == null ? void 0 : item.position),
983
+ endpoint: "/organization/" + values.organization,
984
+ filters: {
985
+ id: {
986
+ $nin: taken()
987
+ }
988
+ },
989
+ // Another file is another item: no description, no crop.
990
+ onChange: (response) => {
991
+ update(
992
+ index,
993
+ {
994
+ file: response
995
+ }
996
+ );
997
+ onUpdate == null ? void 0 : onUpdate(getValues());
998
+ },
999
+ onDescription: (text) => change("gallery." + index + ".description", text),
1000
+ ...editable && {
1001
+ onEdit: () => reposition(index)
1002
+ },
1003
+ organization,
1004
+ nullable: false,
1005
+ value: item == null ? void 0 : item.file,
1006
+ type: "media"
1007
+ }
1008
+ }
1009
+ )
1010
+ }
1011
+ }
1012
+ )
1013
+ ]
1014
+ }
1015
+ );
1016
+ }
1017
+ }
1018
+ ),
1019
+ label: "Gallery"
1020
+ }
874
1021
  }
875
- }
876
- );
1022
+ ) });
1023
+ };
877
1024
  // Annotate the CommonJS export names for ESM import in node:
878
1025
  0 && (module.exports = {
879
1026
  InputFieldsAddress,
@@ -14,13 +14,16 @@ import InputCombobox from "./input-combobox.mjs";
14
14
  import InputText from "../input-text.mjs";
15
15
  import InputTextarea from "../input-textarea.mjs";
16
16
  import InputSwitch from "../shared/input-switch.mjs";
17
+ import { InputArrayControl, InputArraySortable } from "./input-array.mjs";
17
18
  import InputFile from "./input-file.mjs";
18
- import InputGallery from "./input-gallery.mjs";
19
19
  import { useModal } from "./lib/hooks.mjs";
20
20
  import Divider from "../shared/divider.mjs";
21
21
  import Button from "../shared/button.mjs";
22
22
  import MapPin from "../icons/map-pin.mjs";
23
23
  import Lock from "../icons/lock.mjs";
24
+ import Plus from "../icons/plus.mjs";
25
+ import Trash from "../icons/trash.mjs";
26
+ const FormReposition = dynamic(() => import("./form-reposition.mjs"), { loading: () => /* @__PURE__ */ jsx(LoaderDynamic, {}), ssr: false });
24
27
  const InputGoogleAutocomplete = dynamic(() => import("./google.mjs").then((m) => m.InputGoogleAutocomplete), { loading: () => /* @__PURE__ */ jsx(LoaderDynamic, {}), ssr: false });
25
28
  import { getLocation, reverseGeocode } from "./lib/geo.mjs";
26
29
  import { LoaderDynamic } from "../shared/loader.mjs";
@@ -824,17 +827,161 @@ const InputFieldsImages = ({ described, locked, organization, onUpdate, preview
824
827
  )
825
828
  ] });
826
829
  };
827
- const InputFieldsMedia = ({ organization, onUpdate, values = {} }) => /* @__PURE__ */ jsx(
828
- InputGallery,
829
- {
830
- ...{
831
- endpoint: "/organization/" + values.organization,
832
- onUpdate,
833
- organization,
834
- reposition: true
830
+ const InputFieldsMedia = ({ organization, onUpdate, values = {} }) => {
831
+ var _a, _b;
832
+ const queryClient = useQueryClient();
833
+ const modal = useModal({ queryClient });
834
+ const { control, formState, getValues, setValue } = useFormContext();
835
+ const gallery = useWatch({ control, name: "gallery" }) || [];
836
+ const taken = () => (getValues().gallery || []).map((item) => {
837
+ var _a2;
838
+ return (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.id;
839
+ }).filter(Boolean);
840
+ const change = (path, value) => {
841
+ setValue(path, value, { shouldDirty: true });
842
+ onUpdate == null ? void 0 : onUpdate(getValues());
843
+ };
844
+ const reposition = (index) => {
845
+ var _a2, _b2;
846
+ const item = getValues("gallery." + index);
847
+ modal.open({
848
+ message: /* @__PURE__ */ jsx(
849
+ FormReposition,
850
+ {
851
+ ...{
852
+ file: item == null ? void 0 : item.file,
853
+ onDone: (position) => {
854
+ change("gallery." + index + ".position", position);
855
+ modal.close();
856
+ },
857
+ page: getValues(),
858
+ position: item == null ? void 0 : item.position
859
+ }
860
+ }
861
+ ),
862
+ title: ((_b2 = (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) == null ? void 0 : _b2.includes("video")) ? "Reposition video" : "Reposition photo"
863
+ });
864
+ };
865
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
866
+ InputGroup,
867
+ {
868
+ ...{
869
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.gallery) == null ? void 0 : _b.message,
870
+ input: /* @__PURE__ */ jsx(
871
+ InputArraySortable,
872
+ {
873
+ ...{
874
+ control,
875
+ "data-guide": "form-input-gallery",
876
+ empty: "Gallery is empty",
877
+ name: "gallery",
878
+ onSort: () => onUpdate == null ? void 0 : onUpdate(getValues()),
879
+ renderButton: (append) => /* @__PURE__ */ jsx(
880
+ InputFile,
881
+ {
882
+ ...{
883
+ button: {
884
+ icon: Plus,
885
+ text: "Add gallery item"
886
+ },
887
+ endpoint: "/organization/" + values.organization,
888
+ filters: {
889
+ id: {
890
+ $nin: taken()
891
+ }
892
+ },
893
+ onChange: (response) => {
894
+ append({ file: response });
895
+ onUpdate == null ? void 0 : onUpdate(getValues());
896
+ },
897
+ organization,
898
+ nullable: false,
899
+ value: null,
900
+ type: "media"
901
+ }
902
+ }
903
+ ),
904
+ renderControls: ({ index, remove }) => [
905
+ /* @__PURE__ */ jsx(
906
+ InputArrayControl,
907
+ {
908
+ ...{
909
+ onClick: () => {
910
+ remove(index);
911
+ onUpdate == null ? void 0 : onUpdate(getValues());
912
+ },
913
+ icon: Trash
914
+ }
915
+ },
916
+ "gallery-control-remove-" + index
917
+ )
918
+ ]
919
+ },
920
+ children: ({ field, handle, index, update }) => {
921
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
922
+ const item = gallery[index] || field;
923
+ const editable = /^(image|video)\//.test(((_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) || "");
924
+ return /* @__PURE__ */ jsxs(
925
+ "div",
926
+ {
927
+ ...{
928
+ className: "flex items-center min-w-0 flex-1 space-x-3"
929
+ },
930
+ children: [
931
+ handle,
932
+ /* @__PURE__ */ jsx(
933
+ InputGroup,
934
+ {
935
+ ...{
936
+ error: ((_e = (_d = (_c = (_b2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _b2.gallery) == null ? void 0 : _c[index]) == null ? void 0 : _d.file) == null ? void 0 : _e.message) || ((_i = (_h = (_g = (_f = formState == null ? void 0 : formState.errors) == null ? void 0 : _f.gallery) == null ? void 0 : _g[index]) == null ? void 0 : _h.description) == null ? void 0 : _i.message),
937
+ input: /* @__PURE__ */ jsx(
938
+ InputFile,
939
+ {
940
+ ...{
941
+ // The item's own description and crop.
942
+ description: item == null ? void 0 : item.description,
943
+ edited: Boolean(item == null ? void 0 : item.position),
944
+ endpoint: "/organization/" + values.organization,
945
+ filters: {
946
+ id: {
947
+ $nin: taken()
948
+ }
949
+ },
950
+ // Another file is another item: no description, no crop.
951
+ onChange: (response) => {
952
+ update(
953
+ index,
954
+ {
955
+ file: response
956
+ }
957
+ );
958
+ onUpdate == null ? void 0 : onUpdate(getValues());
959
+ },
960
+ onDescription: (text) => change("gallery." + index + ".description", text),
961
+ ...editable && {
962
+ onEdit: () => reposition(index)
963
+ },
964
+ organization,
965
+ nullable: false,
966
+ value: item == null ? void 0 : item.file,
967
+ type: "media"
968
+ }
969
+ }
970
+ )
971
+ }
972
+ }
973
+ )
974
+ ]
975
+ }
976
+ );
977
+ }
978
+ }
979
+ ),
980
+ label: "Gallery"
981
+ }
835
982
  }
836
- }
837
- );
983
+ ) });
984
+ };
838
985
  export {
839
986
  InputFieldsAddress,
840
987
  InputFieldsCampaign,
@@ -34,7 +34,6 @@ var import_jsx_runtime = require("react/jsx-runtime");
34
34
  var import_react_query = require("@tanstack/react-query");
35
35
  var import_hooks = require("./lib/hooks");
36
36
  var import_form_file = __toESM(require("./form-file"));
37
- var import_form_file_upload = __toESM(require("./form-file-upload"));
38
37
  var import_card_asset = __toESM(require("../shared/card-asset"));
39
38
  var import_upload = __toESM(require("../icons/upload"));
40
39
  var import_trash = __toESM(require("../icons/trash"));
@@ -44,10 +43,6 @@ var import_pencil = __toESM(require("../icons/pencil"));
44
43
  const InputFile = ({
45
44
  button = {},
46
45
  description,
47
- // @story products/digital-file
48
- // A product variant's digital file: the uploader alone, no Library to pick
49
- // from, and no thumbnail, since a private file has none.
50
- digital = false,
51
46
  disabled,
52
47
  edited = false,
53
48
  endpoint,
@@ -64,7 +59,7 @@ const InputFile = ({
64
59
  const modal = (0, import_hooks.useModal)({
65
60
  queryClient
66
61
  });
67
- if (digital ? value == null ? void 0 : value.id : value == null ? void 0 : value.sizes) {
62
+ if (value == null ? void 0 : value.sizes) {
68
63
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
69
64
  "div",
70
65
  {
@@ -79,7 +74,7 @@ const InputFile = ({
79
74
  className: "flex items-center space-x-3 border border-black rounded w-full py-2 px-2 bg-white"
80
75
  },
81
76
  children: [
82
- (value == null ? void 0 : value.mimetype) && !digital && (onEdit && !disabled ? (
77
+ (value == null ? void 0 : value.mimetype) && (onEdit && !disabled ? (
83
78
  // @story pages/reposition
84
79
  // The thumbnail is the button: a pencil over it on hover or focus,
85
80
  // the tooltip names the action, and a green ring once it is edited.
@@ -238,19 +233,7 @@ const InputFile = ({
238
233
  onClick: (event) => {
239
234
  event.preventDefault();
240
235
  modal.open({
241
- message: digital ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
- import_form_file_upload.default,
243
- {
244
- ...{
245
- endpoint,
246
- onSuccess: (response) => {
247
- onChange(response == null ? void 0 : response.result);
248
- modal.close();
249
- },
250
- type: "digital"
251
- }
252
- }
253
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
236
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
237
  import_form_file.default,
255
238
  {
256
239
  ...{
@@ -265,7 +248,7 @@ const InputFile = ({
265
248
  }
266
249
  }
267
250
  ),
268
- title: digital ? "Digital file" : "File uploader"
251
+ title: "File uploader"
269
252
  });
270
253
  },
271
254
  variant: "link"
@@ -2,7 +2,6 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useQueryClient } from "@tanstack/react-query";
3
3
  import { useModal } from "./lib/hooks.mjs";
4
4
  import FormFile from "./form-file.mjs";
5
- import FormFileUpload from "./form-file-upload.mjs";
6
5
  import CardAsset from "../shared/card-asset.mjs";
7
6
  import Upload from "../icons/upload.mjs";
8
7
  import Trash from "../icons/trash.mjs";
@@ -12,10 +11,6 @@ import Pencil from "../icons/pencil.mjs";
12
11
  const InputFile = ({
13
12
  button = {},
14
13
  description,
15
- // @story products/digital-file
16
- // A product variant's digital file: the uploader alone, no Library to pick
17
- // from, and no thumbnail, since a private file has none.
18
- digital = false,
19
14
  disabled,
20
15
  edited = false,
21
16
  endpoint,
@@ -32,7 +27,7 @@ const InputFile = ({
32
27
  const modal = useModal({
33
28
  queryClient
34
29
  });
35
- if (digital ? value == null ? void 0 : value.id : value == null ? void 0 : value.sizes) {
30
+ if (value == null ? void 0 : value.sizes) {
36
31
  return /* @__PURE__ */ jsxs(
37
32
  "div",
38
33
  {
@@ -47,7 +42,7 @@ const InputFile = ({
47
42
  className: "flex items-center space-x-3 border border-black rounded w-full py-2 px-2 bg-white"
48
43
  },
49
44
  children: [
50
- (value == null ? void 0 : value.mimetype) && !digital && (onEdit && !disabled ? (
45
+ (value == null ? void 0 : value.mimetype) && (onEdit && !disabled ? (
51
46
  // @story pages/reposition
52
47
  // The thumbnail is the button: a pencil over it on hover or focus,
53
48
  // the tooltip names the action, and a green ring once it is edited.
@@ -206,19 +201,7 @@ const InputFile = ({
206
201
  onClick: (event) => {
207
202
  event.preventDefault();
208
203
  modal.open({
209
- message: digital ? /* @__PURE__ */ jsx(
210
- FormFileUpload,
211
- {
212
- ...{
213
- endpoint,
214
- onSuccess: (response) => {
215
- onChange(response == null ? void 0 : response.result);
216
- modal.close();
217
- },
218
- type: "digital"
219
- }
220
- }
221
- ) : /* @__PURE__ */ jsx(
204
+ message: /* @__PURE__ */ jsx(
222
205
  FormFile,
223
206
  {
224
207
  ...{
@@ -233,7 +216,7 @@ const InputFile = ({
233
216
  }
234
217
  }
235
218
  ),
236
- title: digital ? "Digital file" : "File uploader"
219
+ title: "File uploader"
237
220
  });
238
221
  },
239
222
  variant: "link"
@@ -18,8 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var connection_controls_exports = {};
19
19
  __export(connection_controls_exports, {
20
20
  connectionControls: () => connectionControls,
21
- isConnected: () => isConnected,
22
- savable: () => savable
21
+ isConnected: () => isConnected
23
22
  });
24
23
  module.exports = __toCommonJS(connection_controls_exports);
25
24
  var import_reconnect = require("@drawbridge/drawbridge-utils/connections/reconnect");
@@ -32,10 +31,8 @@ const connectionControls = (connection) => {
32
31
  remove: (connection == null ? void 0 : connection.id) ? ((_a = connection == null ? void 0 : connection.connect) == null ? void 0 : _a.manage) && !paused ? "manage" : "disconnect" : null
33
32
  };
34
33
  };
35
- const savable = ({ actions, connected, inputs }) => !connected || (inputs || []).length > 0 || Boolean(actions == null ? void 0 : actions.update);
36
34
  // Annotate the CommonJS export names for ESM import in node:
37
35
  0 && (module.exports = {
38
36
  connectionControls,
39
- isConnected,
40
- savable
37
+ isConnected
41
38
  });