@drawbridge/components 0.1.47 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain.js +1 -0
  10. package/dist/bridge/form-subdomain.mjs +2 -1
  11. package/dist/bridge/lib/age-gate.js +12 -0
  12. package/dist/bridge/lib/age-gate.mjs +11 -0
  13. package/dist/bridge/lib/cart.js +79 -0
  14. package/dist/bridge/lib/cart.mjs +48 -0
  15. package/dist/bridge/lib/checkout-kit.js +2 -32
  16. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  17. package/dist/bridge/product-tile.js +9 -6
  18. package/dist/bridge/product-tile.mjs +9 -6
  19. package/dist/bridge/template-layout.js +237 -122
  20. package/dist/bridge/template-layout.mjs +237 -122
  21. package/dist/bridge/template-modal.js +28 -73
  22. package/dist/bridge/template-modal.mjs +29 -74
  23. package/dist/dashboard/buttons-subscription.js +1 -1
  24. package/dist/dashboard/buttons-subscription.mjs +1 -1
  25. package/dist/dashboard/campaign-form.js +7 -2
  26. package/dist/dashboard/campaign-form.mjs +7 -2
  27. package/dist/dashboard/card-order.js +22 -4
  28. package/dist/dashboard/card-order.mjs +22 -4
  29. package/dist/dashboard/embed-stripe.js +145 -0
  30. package/dist/dashboard/embed-stripe.mjs +116 -0
  31. package/dist/dashboard/form-admin-provider.js +71 -17
  32. package/dist/dashboard/form-admin-provider.mjs +71 -17
  33. package/dist/dashboard/form-file-upload.js +3 -2
  34. package/dist/dashboard/form-file-upload.mjs +4 -3
  35. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  36. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  37. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  38. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  39. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  40. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  41. package/dist/dashboard/form-organization-campaign.js +82 -0
  42. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  43. package/dist/dashboard/form-organization-connection.js +48 -6
  44. package/dist/dashboard/form-organization-connection.mjs +48 -7
  45. package/dist/dashboard/form-organization-product.js +1461 -0
  46. package/dist/dashboard/form-organization-product.mjs +1425 -0
  47. package/dist/dashboard/form-organization-workflow.js +72 -1
  48. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  49. package/dist/dashboard/form-otc.js +4 -5
  50. package/dist/dashboard/form-otc.mjs +4 -5
  51. package/dist/dashboard/form-stripe.js +12 -5
  52. package/dist/dashboard/form-stripe.mjs +12 -5
  53. package/dist/dashboard/input-fields.js +11 -158
  54. package/dist/dashboard/input-fields.mjs +11 -158
  55. package/dist/dashboard/input-file.js +21 -4
  56. package/dist/dashboard/input-file.mjs +21 -4
  57. package/dist/dashboard/input-gallery.js +201 -0
  58. package/dist/dashboard/input-gallery.mjs +172 -0
  59. package/dist/dashboard/lib/connection-controls.js +5 -2
  60. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  61. package/dist/dashboard/lib/form-page.js +1 -1
  62. package/dist/dashboard/lib/form-page.mjs +1 -1
  63. package/dist/dashboard/lib/products.js +169 -0
  64. package/dist/dashboard/lib/products.mjs +135 -0
  65. package/dist/dashboard/lib/settings-paths.js +35 -0
  66. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  67. package/dist/dashboard/lib/uppy.js +10 -1
  68. package/dist/dashboard/lib/uppy.mjs +11 -2
  69. package/dist/dashboard/order-sections.js +456 -6
  70. package/dist/dashboard/order-sections.mjs +453 -7
  71. package/dist/dashboard/provider-ui.js +9 -7
  72. package/dist/dashboard/provider-ui.mjs +9 -7
  73. package/dist/dashboard/shipping-rates.js +404 -0
  74. package/dist/dashboard/shipping-rates.mjs +371 -0
  75. package/dist/dashboard/template-buyer.js +301 -0
  76. package/dist/dashboard/template-buyer.mjs +267 -0
  77. package/dist/input-checkbox.js +28 -10
  78. package/dist/input-checkbox.mjs +28 -10
  79. package/dist/product.js +96 -24
  80. package/dist/product.mjs +97 -25
  81. package/dist/shared/lib/helpers.js +54 -6
  82. package/dist/shared/lib/helpers.mjs +53 -8
  83. package/dist/shared/order-summary.js +139 -0
  84. package/dist/shared/order-summary.mjs +110 -0
  85. package/package.json +74 -4
  86. package/types/bridge/cart-drawer.d.ts +31 -0
  87. package/types/bridge/fields.d.ts +14 -2
  88. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  89. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  90. package/types/bridge/lib/age-gate.d.ts +5 -0
  91. package/types/bridge/lib/cart.d.ts +44 -0
  92. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  93. package/types/dashboard/card-order.d.ts +6 -0
  94. package/types/dashboard/embed-stripe.d.ts +25 -0
  95. package/types/dashboard/form-admin-provider.d.ts +9 -2
  96. package/types/dashboard/form-file-upload.d.ts +2 -1
  97. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  98. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  99. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  100. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  101. package/types/dashboard/form-organization-connection.d.ts +11 -0
  102. package/types/dashboard/form-organization-product.d.ts +24 -0
  103. package/types/dashboard/form-otc.d.ts +5 -1
  104. package/types/dashboard/form-stripe.d.ts +3 -2
  105. package/types/dashboard/input-file.d.ts +2 -0
  106. package/types/dashboard/input-gallery.d.ts +14 -0
  107. package/types/dashboard/lib/products.d.ts +14 -0
  108. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  109. package/types/dashboard/order-sections.d.ts +24 -1
  110. package/types/dashboard/shipping-rates.d.ts +26 -0
  111. package/types/dashboard/template-buyer.d.ts +50 -0
  112. package/types/input-checkbox.d.ts +2 -0
  113. package/types/shared/lib/helpers.d.ts +4 -0
  114. package/types/shared/order-summary.d.ts +19 -0
@@ -14,16 +14,13 @@ 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";
18
17
  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 });
27
24
  const InputGoogleAutocomplete = dynamic(() => import("./google.mjs").then((m) => m.InputGoogleAutocomplete), { loading: () => /* @__PURE__ */ jsx(LoaderDynamic, {}), ssr: false });
28
25
  import { getLocation, reverseGeocode } from "./lib/geo.mjs";
29
26
  import { LoaderDynamic } from "../shared/loader.mjs";
@@ -827,161 +824,17 @@ const InputFieldsImages = ({ described, locked, organization, onUpdate, preview
827
824
  )
828
825
  ] });
829
826
  };
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
- }
827
+ const InputFieldsMedia = ({ organization, onUpdate, values = {} }) => /* @__PURE__ */ jsx(
828
+ InputGallery,
829
+ {
830
+ ...{
831
+ endpoint: "/organization/" + values.organization,
832
+ onUpdate,
833
+ organization,
834
+ reposition: true
982
835
  }
983
- ) });
984
- };
836
+ }
837
+ );
985
838
  export {
986
839
  InputFieldsAddress,
987
840
  InputFieldsCampaign,
@@ -34,6 +34,7 @@ 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"));
37
38
  var import_card_asset = __toESM(require("../shared/card-asset"));
38
39
  var import_upload = __toESM(require("../icons/upload"));
39
40
  var import_trash = __toESM(require("../icons/trash"));
@@ -43,6 +44,10 @@ var import_pencil = __toESM(require("../icons/pencil"));
43
44
  const InputFile = ({
44
45
  button = {},
45
46
  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,
46
51
  disabled,
47
52
  edited = false,
48
53
  endpoint,
@@ -59,7 +64,7 @@ const InputFile = ({
59
64
  const modal = (0, import_hooks.useModal)({
60
65
  queryClient
61
66
  });
62
- if (value == null ? void 0 : value.sizes) {
67
+ if (digital ? value == null ? void 0 : value.id : value == null ? void 0 : value.sizes) {
63
68
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
64
69
  "div",
65
70
  {
@@ -74,7 +79,7 @@ const InputFile = ({
74
79
  className: "flex items-center space-x-3 border border-black rounded w-full py-2 px-2 bg-white"
75
80
  },
76
81
  children: [
77
- (value == null ? void 0 : value.mimetype) && (onEdit && !disabled ? (
82
+ (value == null ? void 0 : value.mimetype) && !digital && (onEdit && !disabled ? (
78
83
  // @story pages/reposition
79
84
  // The thumbnail is the button: a pencil over it on hover or focus,
80
85
  // the tooltip names the action, and a green ring once it is edited.
@@ -233,7 +238,19 @@ const InputFile = ({
233
238
  onClick: (event) => {
234
239
  event.preventDefault();
235
240
  modal.open({
236
- message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
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)(
237
254
  import_form_file.default,
238
255
  {
239
256
  ...{
@@ -248,7 +265,7 @@ const InputFile = ({
248
265
  }
249
266
  }
250
267
  ),
251
- title: "File uploader"
268
+ title: digital ? "Digital file" : "File uploader"
252
269
  });
253
270
  },
254
271
  variant: "link"
@@ -2,6 +2,7 @@ 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";
5
6
  import CardAsset from "../shared/card-asset.mjs";
6
7
  import Upload from "../icons/upload.mjs";
7
8
  import Trash from "../icons/trash.mjs";
@@ -11,6 +12,10 @@ import Pencil from "../icons/pencil.mjs";
11
12
  const InputFile = ({
12
13
  button = {},
13
14
  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,
14
19
  disabled,
15
20
  edited = false,
16
21
  endpoint,
@@ -27,7 +32,7 @@ const InputFile = ({
27
32
  const modal = useModal({
28
33
  queryClient
29
34
  });
30
- if (value == null ? void 0 : value.sizes) {
35
+ if (digital ? value == null ? void 0 : value.id : value == null ? void 0 : value.sizes) {
31
36
  return /* @__PURE__ */ jsxs(
32
37
  "div",
33
38
  {
@@ -42,7 +47,7 @@ const InputFile = ({
42
47
  className: "flex items-center space-x-3 border border-black rounded w-full py-2 px-2 bg-white"
43
48
  },
44
49
  children: [
45
- (value == null ? void 0 : value.mimetype) && (onEdit && !disabled ? (
50
+ (value == null ? void 0 : value.mimetype) && !digital && (onEdit && !disabled ? (
46
51
  // @story pages/reposition
47
52
  // The thumbnail is the button: a pencil over it on hover or focus,
48
53
  // the tooltip names the action, and a green ring once it is edited.
@@ -201,7 +206,19 @@ const InputFile = ({
201
206
  onClick: (event) => {
202
207
  event.preventDefault();
203
208
  modal.open({
204
- message: /* @__PURE__ */ jsx(
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(
205
222
  FormFile,
206
223
  {
207
224
  ...{
@@ -216,7 +233,7 @@ const InputFile = ({
216
233
  }
217
234
  }
218
235
  ),
219
- title: "File uploader"
236
+ title: digital ? "Digital file" : "File uploader"
220
237
  });
221
238
  },
222
239
  variant: "link"
@@ -0,0 +1,201 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var input_gallery_exports = {};
29
+ __export(input_gallery_exports, {
30
+ default: () => input_gallery_default
31
+ });
32
+ module.exports = __toCommonJS(input_gallery_exports);
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ var import_react = require("react");
35
+ var import_react_hook_form = require("react-hook-form");
36
+ var import_react_query = require("@tanstack/react-query");
37
+ var import_dynamic = __toESM(require("next/dynamic"));
38
+ var import_input_group = __toESM(require("../input-group"));
39
+ var import_input_array = require("./input-array");
40
+ var import_input_file = __toESM(require("./input-file"));
41
+ var import_hooks = require("./lib/hooks");
42
+ var import_loader = require("../shared/loader");
43
+ var import_plus = __toESM(require("../icons/plus"));
44
+ var import_trash = __toESM(require("../icons/trash"));
45
+ const FormReposition = (0, import_dynamic.default)(() => import("./form-reposition"), { loading: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.LoaderDynamic, {}), ssr: false });
46
+ const InputGallery = ({ endpoint, label = "Gallery", name = "gallery", onUpdate, organization, reposition: repositions = false }) => {
47
+ var _a, _b;
48
+ const queryClient = (0, import_react_query.useQueryClient)();
49
+ const modal = (0, import_hooks.useModal)({ queryClient });
50
+ const { control, formState, getValues, setValue } = (0, import_react_hook_form.useFormContext)();
51
+ const gallery = (0, import_react_hook_form.useWatch)({ control, name }) || [];
52
+ const taken = () => (getValues(name) || []).map((item) => {
53
+ var _a2;
54
+ return (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.id;
55
+ }).filter(Boolean);
56
+ const change = (path, value) => {
57
+ setValue(path, value, { shouldDirty: true });
58
+ onUpdate == null ? void 0 : onUpdate(getValues());
59
+ };
60
+ const reposition = (index) => {
61
+ var _a2, _b2;
62
+ const item = getValues(name + "." + index);
63
+ modal.open({
64
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ FormReposition,
66
+ {
67
+ ...{
68
+ file: item == null ? void 0 : item.file,
69
+ onDone: (position) => {
70
+ change(name + "." + index + ".position", position);
71
+ modal.close();
72
+ },
73
+ page: getValues(),
74
+ position: item == null ? void 0 : item.position
75
+ }
76
+ }
77
+ ),
78
+ title: ((_b2 = (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) == null ? void 0 : _b2.includes("video")) ? "Reposition video" : "Reposition photo"
79
+ });
80
+ };
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
82
+ import_input_group.default,
83
+ {
84
+ ...{
85
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[name]) == null ? void 0 : _b.message,
86
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
87
+ import_input_array.InputArraySortable,
88
+ {
89
+ ...{
90
+ control,
91
+ "data-guide": "form-input-gallery",
92
+ empty: "Gallery is empty",
93
+ name,
94
+ onSort: () => onUpdate == null ? void 0 : onUpdate(getValues()),
95
+ renderButton: (append) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
96
+ import_input_file.default,
97
+ {
98
+ ...{
99
+ button: {
100
+ icon: import_plus.default,
101
+ text: "Add gallery item"
102
+ },
103
+ endpoint,
104
+ filters: {
105
+ id: {
106
+ $nin: taken()
107
+ }
108
+ },
109
+ onChange: (response) => {
110
+ append({ file: response });
111
+ onUpdate == null ? void 0 : onUpdate(getValues());
112
+ },
113
+ organization,
114
+ nullable: false,
115
+ value: null,
116
+ type: "media"
117
+ }
118
+ }
119
+ ),
120
+ renderControls: ({ index, remove }) => [
121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
+ import_input_array.InputArrayControl,
123
+ {
124
+ ...{
125
+ onClick: () => {
126
+ remove(index);
127
+ onUpdate == null ? void 0 : onUpdate(getValues());
128
+ },
129
+ icon: import_trash.default
130
+ }
131
+ },
132
+ "gallery-control-remove-" + index
133
+ )
134
+ ]
135
+ },
136
+ children: ({ field, handle, index, update }) => {
137
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
138
+ const item = gallery[index] || field;
139
+ const editable = /^(image|video)\//.test(((_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) || "");
140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
141
+ "div",
142
+ {
143
+ ...{
144
+ className: "flex items-center min-w-0 flex-1 space-x-3"
145
+ },
146
+ children: [
147
+ handle,
148
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
+ import_input_group.default,
150
+ {
151
+ ...{
152
+ error: ((_e = (_d = (_c = (_b2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _b2[name]) == 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[name]) == null ? void 0 : _g[index]) == null ? void 0 : _h.description) == null ? void 0 : _i.message),
153
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
154
+ import_input_file.default,
155
+ {
156
+ ...{
157
+ // The item's own description and crop.
158
+ description: item == null ? void 0 : item.description,
159
+ edited: Boolean(item == null ? void 0 : item.position),
160
+ endpoint,
161
+ filters: {
162
+ id: {
163
+ $nin: taken()
164
+ }
165
+ },
166
+ // Another file is another item: no description, no crop.
167
+ onChange: (response) => {
168
+ update(
169
+ index,
170
+ {
171
+ file: response
172
+ }
173
+ );
174
+ onUpdate == null ? void 0 : onUpdate(getValues());
175
+ },
176
+ onDescription: (text) => change(name + "." + index + ".description", text),
177
+ ...repositions && editable && {
178
+ onEdit: () => reposition(index)
179
+ },
180
+ organization,
181
+ nullable: false,
182
+ value: item == null ? void 0 : item.file,
183
+ type: "media"
184
+ }
185
+ }
186
+ )
187
+ }
188
+ }
189
+ )
190
+ ]
191
+ }
192
+ );
193
+ }
194
+ }
195
+ ),
196
+ label
197
+ }
198
+ }
199
+ ) });
200
+ };
201
+ var input_gallery_default = InputGallery;