sanity-plugin-internationalized-array 3.2.1 → 3.2.2

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.
package/lib/index.js CHANGED
@@ -58,26 +58,18 @@ const namespace = "sanity-plugin-internationalized-array", version = "v1", funct
58
58
  buttonLocations: ["field"],
59
59
  buttonAddAll: !0,
60
60
  languageDisplay: "codeOnly"
61
- };
62
- var __defProp$9 = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
63
- for (var prop in b || (b = {}))
64
- __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
65
- if (__getOwnPropSymbols$9)
66
- for (var prop of __getOwnPropSymbols$9(b))
67
- __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
68
- return a;
69
- }, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
70
- const getDocumentsToTranslate = (value, rootPath = []) => {
61
+ }, getDocumentsToTranslate = (value, rootPath = []) => {
71
62
  if (Array.isArray(value)) {
72
63
  const arrayRootPath = [...rootPath], internationalizedValues = value.filter((item) => {
73
64
  if (Array.isArray(item)) return !1;
74
65
  if (typeof item == "object") {
75
- const type = item == null ? void 0 : item._type;
76
- return (type == null ? void 0 : type.startsWith("internationalizedArray")) && (type == null ? void 0 : type.endsWith("Value"));
66
+ const type = item?._type;
67
+ return type?.startsWith("internationalizedArray") && type?.endsWith("Value");
77
68
  }
78
69
  return !1;
79
70
  });
80
- return internationalizedValues.length > 0 ? internationalizedValues.map((internationalizedValue) => __spreadProps$8(__spreadValues$9({}, internationalizedValue), {
71
+ return internationalizedValues.length > 0 ? internationalizedValues.map((internationalizedValue) => ({
72
+ ...internationalizedValue,
81
73
  path: arrayRootPath,
82
74
  pathString: arrayRootPath.join(".")
83
75
  })) : value.length > 0 ? value.map(
@@ -98,7 +90,7 @@ const getDocumentsToTranslate = (value, rootPath = []) => {
98
90
  function getLanguageDisplay(languageDisplay, title, code) {
99
91
  return languageDisplay === "codeOnly" ? code.toUpperCase() : languageDisplay === "titleOnly" ? title : languageDisplay === "titleAndCode" ? `${title} (${code.toUpperCase()})` : title;
100
92
  }
101
- function AddButtons(props) {
93
+ function AddButtons$1(props) {
102
94
  const { languages, readOnly, value, onClick } = props, { languageDisplay } = useInternationalizedArrayContext();
103
95
  return languages.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
104
96
  ui.Grid,
@@ -117,7 +109,7 @@ function AddButtons(props) {
117
109
  tone: "primary",
118
110
  mode: "ghost",
119
111
  fontSize: 1,
120
- disabled: readOnly || !!(value != null && value.find((item) => item._key === language.id)),
112
+ disabled: readOnly || !!value?.find((item) => item._key === language.id),
121
113
  text: languageTitle,
122
114
  icon: languages.length > MAX_COLUMNS[languageDisplay] && languageDisplay === "codeOnly" ? void 0 : icons.AddIcon,
123
115
  value: language.id,
@@ -129,11 +121,10 @@ function AddButtons(props) {
129
121
  }
130
122
  ) : null;
131
123
  }
132
- var AddButtons$1 = react.memo(AddButtons);
124
+ var AddButtons = react.memo(AddButtons$1);
133
125
  function DocumentAddButtons(props) {
134
126
  const { filteredLanguages } = useInternationalizedArrayContext(), value = sanity.isSanityDocument(props.value) ? props.value : void 0, toast = ui.useToast(), { onChange } = structure.useDocumentPane(), schema = sanity.useSchema(), documentsToTranslation = getDocumentsToTranslate(value, []), getInitialValueForType = react.useCallback(
135
127
  (typeName) => {
136
- var _a;
137
128
  if (!typeName) return;
138
129
  const match = typeName.match(/^internationalizedArray(.+)Value$/);
139
130
  if (!match) return;
@@ -148,13 +139,13 @@ function DocumentAddButtons(props) {
148
139
  try {
149
140
  const schemaType = schema.get(typeName);
150
141
  if (schemaType) {
151
- const valueField = (_a = schemaType == null ? void 0 : schemaType.fields) == null ? void 0 : _a.find(
142
+ const valueField = schemaType?.fields?.find(
152
143
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
144
  (f) => f.name === "value"
154
145
  );
155
146
  if (valueField) {
156
147
  const fieldType = valueField.type;
157
- if ((fieldType == null ? void 0 : fieldType.jsonType) === "array" || (fieldType == null ? void 0 : fieldType.name) === "array" || (fieldType == null ? void 0 : fieldType.type) === "array" || (fieldType == null ? void 0 : fieldType.of) !== void 0 || arrayBasedTypes.includes(fieldType == null ? void 0 : fieldType.name))
148
+ if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || arrayBasedTypes.includes(fieldType?.name))
158
149
  return [];
159
150
  }
160
151
  }
@@ -178,7 +169,7 @@ function DocumentAddButtons(props) {
178
169
  return;
179
170
  }
180
171
  const alreadyTranslated = documentsToTranslation.filter(
181
- (translation) => (translation == null ? void 0 : translation._key) === languageId
172
+ (translation) => translation?._key === languageId
182
173
  ), removeDuplicates = documentsToTranslation.reduce((filteredTranslations, translation) => alreadyTranslated.filter(
183
174
  (alreadyTranslation) => alreadyTranslation.pathString === translation.pathString
184
175
  ).length > 0 || filteredTranslations.filter(
@@ -214,7 +205,7 @@ function DocumentAddButtons(props) {
214
205
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
215
206
  /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "Add translation to internationalized fields" }) }),
216
207
  /* @__PURE__ */ jsxRuntime.jsx(
217
- AddButtons$1,
208
+ AddButtons,
218
209
  {
219
210
  languages: filteredLanguages,
220
211
  readOnly: !1,
@@ -231,36 +222,28 @@ const getSelectedValue = (select, document) => {
231
222
  for (const [key, path] of Object.entries(selection)) {
232
223
  let value = get__default.default(document, path);
233
224
  Array.isArray(value) && (value = value.filter(
234
- (item) => typeof item == "object" ? (item == null ? void 0 : item._type) === "reference" && "_ref" in item : !0
225
+ (item) => typeof item == "object" ? item?._type === "reference" && "_ref" in item : !0
235
226
  )), selectedValue[key] = value;
236
227
  }
237
228
  return selectedValue;
238
- };
239
- var __defProp$8 = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
240
- for (var prop in b || (b = {}))
241
- __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
242
- if (__getOwnPropSymbols$8)
243
- for (var prop of __getOwnPropSymbols$8(b))
244
- __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
245
- return a;
246
- }, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
247
- const InternationalizedArrayContext = react.createContext(__spreadProps$7(__spreadValues$8({}, CONFIG_DEFAULT), {
229
+ }, InternationalizedArrayContext = react.createContext({
230
+ ...CONFIG_DEFAULT,
248
231
  languages: [],
249
232
  filteredLanguages: []
250
- }));
233
+ });
251
234
  function useInternationalizedArrayContext() {
252
235
  return react.useContext(InternationalizedArrayContext);
253
236
  }
254
237
  function InternationalizedArrayProvider(props) {
255
- const { internationalizedArray: internationalizedArray2 } = props, client = sanity.useClient({ apiVersion: internationalizedArray2.apiVersion }), workspace = sanity.useWorkspace(), { formState } = structure.useDocumentPane(), deferredDocument = react.useDeferredValue(formState == null ? void 0 : formState.value), selectedValue = react.useMemo(
238
+ const { internationalizedArray: internationalizedArray2 } = props, client = sanity.useClient({ apiVersion: internationalizedArray2.apiVersion }), workspace = sanity.useWorkspace(), { formState } = structure.useDocumentPane(), deferredDocument = react.useDeferredValue(formState?.value), selectedValue = react.useMemo(
256
239
  () => getSelectedValue(internationalizedArray2.select, deferredDocument),
257
240
  [internationalizedArray2.select, deferredDocument]
258
241
  ), workspaceId = react.useMemo(() => {
259
- if (workspace != null && workspace.name)
242
+ if (workspace?.name)
260
243
  return workspace.name;
261
244
  const workspaceKey = {
262
- name: workspace == null ? void 0 : workspace.name,
263
- title: workspace == null ? void 0 : workspace.title
245
+ name: workspace?.name,
246
+ title: workspace?.title
264
247
  // Add other stable properties as needed
265
248
  };
266
249
  return JSON.stringify(workspaceKey);
@@ -292,7 +275,7 @@ function InternationalizedArrayProvider(props) {
292
275
  (language) => selectedLanguageIds.includes(language.id)
293
276
  ) : languages;
294
277
  }, [deferredDocument, languageFilterOptions, languages, selectedLanguageIds]), showDocumentButtons = internationalizedArray2.buttonLocations.includes("document"), context = react.useMemo(
295
- () => __spreadProps$7(__spreadValues$8({}, internationalizedArray2), { languages, filteredLanguages }),
278
+ () => ({ ...internationalizedArray2, languages, filteredLanguages }),
296
279
  [filteredLanguages, internationalizedArray2, languages]
297
280
  );
298
281
  return /* @__PURE__ */ jsxRuntime.jsx(InternationalizedArrayContext.Provider, { value: context, children: showDocumentButtons ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 5, children: [
@@ -300,30 +283,24 @@ function InternationalizedArrayProvider(props) {
300
283
  props.renderDefault(props)
301
284
  ] }) : props.renderDefault(props) });
302
285
  }
303
- var __defProp$7 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
304
- for (var prop in b || (b = {}))
305
- __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
306
- if (__getOwnPropSymbols$7)
307
- for (var prop of __getOwnPropSymbols$7(b))
308
- __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
309
- return a;
310
- }, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
311
286
  function InternationalizedField(props) {
312
287
  const { languages } = useInternationalizedArrayContext(), customProps = react.useMemo(() => {
313
- var _a;
314
- const pathSegment = props.path.slice(0, -1)[1], languageId = typeof pathSegment == "object" && "_key" in pathSegment ? pathSegment._key : void 0, hasValidLanguageId = languageId ? languages.some((l) => l.id === languageId) : !1, shouldHideTitle = ((_a = props.title) == null ? void 0 : _a.toLowerCase()) === "value" && hasValidLanguageId;
315
- return __spreadProps$6(__spreadValues$7({}, props), {
288
+ const pathSegment = props.path.slice(0, -1)[1], languageId = typeof pathSegment == "object" && "_key" in pathSegment ? pathSegment._key : void 0, hasValidLanguageId = languageId ? languages.some((l) => l.id === languageId) : !1, shouldHideTitle = props.title?.toLowerCase() === "value" && hasValidLanguageId;
289
+ return {
290
+ ...props,
316
291
  title: shouldHideTitle ? "" : props.title
317
- });
292
+ };
318
293
  }, [props, languages]);
319
- return customProps.schemaType.name.startsWith("internationalizedArray") ? customProps.schemaType.name === "reference" && customProps.value ? customProps.renderDefault(__spreadProps$6(__spreadValues$7({}, customProps), {
294
+ return customProps.schemaType.name.startsWith("internationalizedArray") ? customProps.schemaType.name === "reference" && customProps.value ? customProps.renderDefault({
295
+ ...customProps,
320
296
  title: "",
321
297
  level: 0
322
298
  // Reset the level to avoid nested styling
323
- })) : customProps.schemaType.name === "string" || customProps.schemaType.name === "number" || customProps.schemaType.name === "text" ? customProps.children : customProps.renderDefault(__spreadProps$6(__spreadValues$7({}, customProps), {
299
+ }) : customProps.schemaType.name === "string" || customProps.schemaType.name === "number" || customProps.schemaType.name === "text" ? customProps.children : customProps.renderDefault({
300
+ ...customProps,
324
301
  level: 0
325
302
  // Reset the level to avoid nested styling
326
- })) : customProps.renderDefault(customProps);
303
+ }) : customProps.renderDefault(customProps);
327
304
  }
328
305
  var Preload = react.memo(function(props) {
329
306
  const client = sanity.useClient({ apiVersion: props.apiVersion }), cacheKey = createCacheKey({});
@@ -339,19 +316,11 @@ function checkAllLanguagesArePresent(languages, value) {
339
316
  return languagesInUseIds.length === filteredLanguageIds.length && languagesInUseIds.every((l) => filteredLanguageIds.includes(l));
340
317
  }
341
318
  function createAddAllTitle(value, languages) {
342
- return value != null && value.length ? `Add missing ${languages.length - value.length === 1 ? "language" : "languages"}` : languages.length === 1 ? `Add ${languages[0].title} Field` : "Add all languages";
319
+ return value?.length ? `Add missing ${languages.length - value.length === 1 ? "language" : "languages"}` : languages.length === 1 ? `Add ${languages[0].title} Field` : "Add all languages";
343
320
  }
344
321
  function createValueSchemaTypeName(schemaType) {
345
322
  return `${schemaType.name}Value`;
346
323
  }
347
- var __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
348
- for (var prop in b || (b = {}))
349
- __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
350
- if (__getOwnPropSymbols$6)
351
- for (var prop of __getOwnPropSymbols$6(b))
352
- __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
353
- return a;
354
- }, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
355
324
  function createAddLanguagePatches(config) {
356
325
  const {
357
326
  addLanguageKeys,
@@ -360,13 +329,15 @@ function createAddLanguagePatches(config) {
360
329
  filteredLanguages,
361
330
  value,
362
331
  path = []
363
- } = config, itemBase = { _type: createValueSchemaTypeName(schemaType) }, newItems = Array.isArray(addLanguageKeys) && addLanguageKeys.length > 0 ? addLanguageKeys.map((id) => __spreadProps$5(__spreadValues$6({}, itemBase), {
332
+ } = config, itemBase = { _type: createValueSchemaTypeName(schemaType) }, newItems = Array.isArray(addLanguageKeys) && addLanguageKeys.length > 0 ? addLanguageKeys.map((id) => ({
333
+ ...itemBase,
364
334
  _key: id
365
335
  })) : filteredLanguages.filter(
366
- (language) => value != null && value.length ? !value.find((v) => v._key === language.id) : !0
367
- ).map((language) => __spreadProps$5(__spreadValues$6({}, itemBase), {
336
+ (language) => value?.length ? !value.find((v) => v._key === language.id) : !0
337
+ ).map((language) => ({
338
+ ...itemBase,
368
339
  _key: language.id
369
- })), languagesInUse = value != null && value.length ? value.map((v) => v) : [];
340
+ })), languagesInUse = value?.length ? value.map((v) => v) : [];
370
341
  return newItems.map((item) => {
371
342
  const languageIndex = languages.findIndex((l) => item._key === l.id), remainingLanguages = languages.slice(languageIndex + 1), nextLanguageIndex = languagesInUse.findIndex(
372
343
  (l) => (
@@ -384,7 +355,7 @@ function createAddLanguagePatches(config) {
384
355
  });
385
356
  }
386
357
  const createTranslateFieldActions = (fieldActionProps, { languages, filteredLanguages }) => languages.map((language) => {
387
- const value = sanity.useFormValue(fieldActionProps.path), disabled = value && Array.isArray(value) ? !!(value != null && value.find((item) => item._key === language.id)) : !1, hidden = !filteredLanguages.some((f) => f.id === language.id), { onChange } = structure.useDocumentPane(), onAction = react.useCallback(() => {
358
+ const value = sanity.useFormValue(fieldActionProps.path), disabled = value && Array.isArray(value) ? !!value?.find((item) => item._key === language.id) : !1, hidden = !filteredLanguages.some((f) => f.id === language.id), { onChange } = structure.useDocumentPane(), onAction = react.useCallback(() => {
388
359
  const { schemaType, path } = fieldActionProps, addLanguageKeys = [language.id], patches = createAddLanguagePatches({
389
360
  addLanguageKeys,
390
361
  schemaType,
@@ -426,8 +397,7 @@ const createTranslateFieldActions = (fieldActionProps, { languages, filteredLang
426
397
  }, internationalizedArrayFieldAction = sanity.defineDocumentFieldAction({
427
398
  name: "internationalizedArray",
428
399
  useAction(fieldActionProps) {
429
- var _a, _b;
430
- const isInternationalizedArrayField = (_b = (_a = fieldActionProps == null ? void 0 : fieldActionProps.schemaType) == null ? void 0 : _a.type) == null ? void 0 : _b.name.startsWith(
400
+ const isInternationalizedArrayField = fieldActionProps?.schemaType?.type?.name.startsWith(
431
401
  "internationalizedArray"
432
402
  ), { languages, filteredLanguages } = useInternationalizedArrayContext(), translateFieldActions = createTranslateFieldActions(
433
403
  fieldActionProps,
@@ -483,14 +453,6 @@ function Feedback() {
483
453
  /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 2, border: !0, radius: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Code, { size: 1, language: "javascript", children: JSON.stringify(schemaExample, null, 2) }) })
484
454
  ] }) });
485
455
  }
486
- var __defProp$5 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
487
- for (var prop in b || (b = {}))
488
- __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
489
- if (__getOwnPropSymbols$5)
490
- for (var prop of __getOwnPropSymbols$5(b))
491
- __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
492
- return a;
493
- }, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
494
456
  function InternationalizedArray(props) {
495
457
  const {
496
458
  members,
@@ -518,10 +480,9 @@ function InternationalizedArray(props) {
518
480
  [languageFilterEnabled, members, languageFilterOptions, selectedLanguageIds]
519
481
  ), handleAddLanguage = react.useCallback(
520
482
  async (param) => {
521
- var _a;
522
- if (!(filteredLanguages != null && filteredLanguages.length))
483
+ if (!filteredLanguages?.length)
523
484
  return;
524
- const addLanguageKeys = Array.isArray(param) ? param : [(_a = param == null ? void 0 : param.currentTarget) == null ? void 0 : _a.value].filter(Boolean), patches = createAddLanguagePatches({
485
+ const addLanguageKeys = Array.isArray(param) ? param : [param?.currentTarget?.value].filter(Boolean), patches = createAddLanguagePatches({
525
486
  addLanguageKeys,
526
487
  schemaType,
527
488
  languages,
@@ -549,23 +510,23 @@ function InternationalizedArray(props) {
549
510
  documentReadOnly
550
511
  ]);
551
512
  const handleRestoreOrder = react.useCallback(() => {
552
- if (!(value != null && value.length) || !(languages != null && languages.length))
513
+ if (!value?.length || !languages?.length)
553
514
  return;
554
515
  const updatedValue = value.reduce((acc, v) => {
555
- const newIndex = languages.findIndex((l) => l.id === (v == null ? void 0 : v._key));
516
+ const newIndex = languages.findIndex((l) => l.id === v?._key);
556
517
  return newIndex > -1 && (acc[newIndex] = v), acc;
557
518
  }, []).filter(Boolean);
558
- (value == null ? void 0 : value.length) !== updatedValue.length && toast.push({
519
+ value?.length !== updatedValue.length && toast.push({
559
520
  title: "There was an error reordering languages",
560
521
  status: "warning"
561
522
  }), onChange(sanity.set(updatedValue));
562
- }, [toast, languages, onChange, value]), allKeysAreLanguages = react.useMemo(() => !(value != null && value.length) || !(languages != null && languages.length) ? !0 : value == null ? void 0 : value.every((v) => languages.find((l) => (l == null ? void 0 : l.id) === (v == null ? void 0 : v._key))), [value, languages]), languagesInUse = react.useMemo(
563
- () => languages && languages.length > 1 ? languages.filter((l) => value == null ? void 0 : value.find((v) => v._key === l.id)) : [],
523
+ }, [toast, languages, onChange, value]), allKeysAreLanguages = react.useMemo(() => !value?.length || !languages?.length ? !0 : value?.every((v) => languages.find((l) => l?.id === v?._key)), [value, languages]), languagesInUse = react.useMemo(
524
+ () => languages && languages.length > 1 ? languages.filter((l) => value?.find((v) => v._key === l.id)) : [],
564
525
  [languages, value]
565
- ), languagesOutOfOrder = react.useMemo(() => !(value != null && value.length) || !languagesInUse.length ? [] : value.map(
526
+ ), languagesOutOfOrder = react.useMemo(() => !value?.length || !languagesInUse.length ? [] : value.map(
566
527
  (v, vIndex) => vIndex === languagesInUse.findIndex((l) => l.id === v._key) ? null : v
567
528
  ).filter(Boolean), [value, languagesInUse]), languagesAreValid = react.useMemo(
568
- () => !(languages != null && languages.length) || (languages == null ? void 0 : languages.length) && languages.every((item) => item.id && item.title),
529
+ () => !languages?.length || languages?.length && languages.every((item) => item.id && item.title),
569
530
  [languages]
570
531
  );
571
532
  react.useEffect(() => {
@@ -580,21 +541,22 @@ function InternationalizedArray(props) {
580
541
  const addButtonsAreVisible = (
581
542
  // Plugin was configured to display buttons here (default!)
582
543
  buttonLocations.includes("field") && // There's at least one language visible
583
- (filteredLanguages == null ? void 0 : filteredLanguages.length) > 0 && // Not every language has a value yet
544
+ filteredLanguages?.length > 0 && // Not every language has a value yet
584
545
  !allLanguagesArePresent
585
- ), fieldHasMembers = (members == null ? void 0 : members.length) > 0;
546
+ ), fieldHasMembers = members?.length > 0;
586
547
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
587
548
  fieldHasMembers ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: filteredMembers.map((member) => member.kind === "item" ? /* @__PURE__ */ react.createElement(
588
549
  sanity.ArrayOfObjectsItem,
589
- __spreadProps$4(__spreadValues$5({}, props), {
550
+ {
551
+ ...props,
590
552
  key: member.key,
591
553
  member
592
- })
554
+ }
593
555
  ) : /* @__PURE__ */ jsxRuntime.jsx(sanity.MemberItemError, { member }, member.key)) }) : null,
594
556
  !addButtonsAreVisible && !fieldHasMembers ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { border: !0, tone: "transparent", padding: 3, radius: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "This internationalized field currently has no translations." }) }) : null,
595
557
  addButtonsAreVisible ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
596
558
  /* @__PURE__ */ jsxRuntime.jsx(
597
- AddButtons$1,
559
+ AddButtons,
598
560
  {
599
561
  languages: filteredLanguages,
600
562
  value,
@@ -617,17 +579,9 @@ function InternationalizedArray(props) {
617
579
  ] });
618
580
  }
619
581
  function getLanguagesFieldOption(schemaType) {
620
- var _a;
621
- return schemaType ? ((_a = schemaType.options) == null ? void 0 : _a.languages) || getLanguagesFieldOption(schemaType.type) : void 0;
582
+ return schemaType ? schemaType.options?.languages || getLanguagesFieldOption(schemaType.type) : void 0;
622
583
  }
623
- var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
624
- for (var prop in b || (b = {}))
625
- __hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
626
- if (__getOwnPropSymbols$4)
627
- for (var prop of __getOwnPropSymbols$4(b))
628
- __propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
629
- return a;
630
- }, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), array = (config) => {
584
+ var array = (config) => {
631
585
  const { apiVersion, select, languages, type } = config, typeName = typeof type == "string" ? type : type.name, arrayName = createFieldName(typeName), objectName = createFieldName(typeName, !0);
632
586
  return sanity.defineField({
633
587
  name: arrayName,
@@ -643,19 +597,19 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
643
597
  languages
644
598
  },
645
599
  of: [
646
- sanity.defineField(__spreadProps$3(__spreadValues$4({}, typeof type == "string" ? {} : type), {
600
+ sanity.defineField({
601
+ ...typeof type == "string" ? {} : type,
647
602
  name: objectName,
648
603
  type: objectName
649
- }))
604
+ })
650
605
  ],
651
606
  // @ts-expect-error - fix typings
652
607
  validation: (rule) => rule.custom(async (value, context) => {
653
- var _a;
654
- if (!value || value.length === 0 || value.length === 1 && !((_a = value[0]) != null && _a._key))
608
+ if (!value || value.length === 0 || value.length === 1 && !value[0]?._key)
655
609
  return !0;
656
610
  const selectedValue = getSelectedValue(select, context.document), client = context.getClient({ apiVersion });
657
611
  let contextLanguages = [];
658
- const languagesFieldOption = getLanguagesFieldOption(context == null ? void 0 : context.type);
612
+ const languagesFieldOption = getLanguagesFieldOption(context?.type);
659
613
  if (Array.isArray(languagesFieldOption))
660
614
  contextLanguages = languagesFieldOption;
661
615
  else if (Array.isArray(peek(selectedValue)))
@@ -682,7 +636,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
682
636
  if (value && value.length > contextLanguages.length)
683
637
  return `Cannot be more than ${contextLanguages.length === 1 ? "1 item" : `${contextLanguages.length} items`}`;
684
638
  const languageIds = new Set(contextLanguages.map((lang) => lang.id)), nonLanguageKeys = value.filter(
685
- (item) => (item == null ? void 0 : item._key) && !languageIds.has(item._key)
639
+ (item) => item?._key && !languageIds.has(item._key)
686
640
  );
687
641
  if (nonLanguageKeys.length)
688
642
  return {
@@ -691,7 +645,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
691
645
  };
692
646
  const seenKeys = /* @__PURE__ */ new Set(), duplicateValues = [];
693
647
  for (const item of value)
694
- item != null && item._key && (seenKeys.has(item._key) ? duplicateValues.push(item) : seenKeys.add(item._key));
648
+ item?._key && (seenKeys.has(item._key) ? duplicateValues.push(item) : seenKeys.add(item._key));
695
649
  return duplicateValues.length ? {
696
650
  message: "There can only be one field per language",
697
651
  paths: duplicateValues.map((item) => [{ _key: item._key }])
@@ -700,7 +654,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
700
654
  });
701
655
  };
702
656
  function getToneFromValidation(validations) {
703
- if (!(validations != null && validations.length))
657
+ if (!validations?.length)
704
658
  return;
705
659
  const validationLevels = validations.map((v) => v.level);
706
660
  if (validationLevels.includes("error"))
@@ -708,31 +662,22 @@ function getToneFromValidation(validations) {
708
662
  if (validationLevels.includes("warning"))
709
663
  return "caution";
710
664
  }
711
- var __defProp$3 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
712
- for (var prop in b || (b = {}))
713
- __hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
714
- if (__getOwnPropSymbols$3)
715
- for (var prop of __getOwnPropSymbols$3(b))
716
- __propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
717
- return a;
718
- }, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
719
665
  function InternationalizedInput(props) {
720
666
  const parentValue = sanity.useFormValue(
721
667
  props.path.slice(0, -1)
722
668
  ), originalOnChange = props.inputProps.onChange, wrappedOnChange = react.useCallback(
723
669
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
724
670
  (patches) => {
725
- var _a;
726
671
  if (!Array.isArray(patches))
727
672
  return originalOnChange(patches);
728
- const valueField = (_a = props.value) == null ? void 0 : _a.value;
673
+ const valueField = props.value?.value;
729
674
  if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some((patch) => !patch || typeof patch != "object" ? !1 : patch.type === "insert" && patch.path && Array.isArray(patch.path) && patch.path.length > 0 ? patch.path[0] === "value" || typeof patch.path[0] == "number" : !1)) {
730
675
  const initPatch = valueField === void 0 ? { type: "setIfMissing", path: ["value"], value: [] } : null, fixedPatches = patches.map((patch) => {
731
676
  if (!patch || typeof patch != "object")
732
677
  return patch;
733
678
  if (patch.type === "insert" && patch.path && Array.isArray(patch.path)) {
734
679
  const fixedPath = patch.path[0] === "value" ? patch.path : ["value", ...patch.path];
735
- return __spreadProps$2(__spreadValues$3({}, patch), { path: fixedPath });
680
+ return { ...patch, path: fixedPath };
736
681
  }
737
682
  return patch;
738
683
  }), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
@@ -741,7 +686,8 @@ function InternationalizedInput(props) {
741
686
  return originalOnChange(patches);
742
687
  },
743
688
  [props.value, originalOnChange]
744
- ), inlineProps = __spreadProps$2(__spreadValues$3({}, props.inputProps), {
689
+ ), inlineProps = {
690
+ ...props.inputProps,
745
691
  // This is the magic that makes inline editing work?
746
692
  members: props.inputProps.members.filter(
747
693
  (m) => m.kind === "field" && m.name === "value"
@@ -751,17 +697,13 @@ function InternationalizedInput(props) {
751
697
  value: props.value,
752
698
  // Use our wrapped onChange handler
753
699
  onChange: wrappedOnChange
754
- }), { validation, value, onChange, readOnly } = inlineProps, { languages, languageDisplay, defaultLanguages } = useInternationalizedArrayContext(), languageKeysInUse = react.useMemo(
755
- () => {
756
- var _a;
757
- return (_a = parentValue == null ? void 0 : parentValue.map((v) => v._key)) != null ? _a : [];
758
- },
700
+ }, { validation, value, onChange, readOnly } = inlineProps, { languages, languageDisplay, defaultLanguages } = useInternationalizedArrayContext(), languageKeysInUse = react.useMemo(
701
+ () => parentValue?.map((v) => v._key) ?? [],
759
702
  [parentValue]
760
- ), keyIsValid = languages != null && languages.length ? languages.find((l) => l.id === value._key) : !1, handleKeyChange = react.useCallback(
703
+ ), keyIsValid = languages?.length ? languages.find((l) => l.id === value._key) : !1, handleKeyChange = react.useCallback(
761
704
  (event) => {
762
- var _a;
763
- const languageId = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.value;
764
- !value || !(languages != null && languages.length) || !languages.find((l) => l.id === languageId) || onChange([sanity.set(languageId, ["_key"])]);
705
+ const languageId = event?.currentTarget?.value;
706
+ !value || !languages?.length || !languages.find((l) => l.id === languageId) || onChange([sanity.set(languageId, ["_key"])]);
765
707
  },
766
708
  [onChange, value, languages]
767
709
  ), handleUnset = react.useCallback(() => {
@@ -814,14 +756,7 @@ function InternationalizedInput(props) {
814
756
  ] })
815
757
  ] }) });
816
758
  }
817
- var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
818
- for (var prop in b || (b = {}))
819
- __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
820
- if (__getOwnPropSymbols$2)
821
- for (var prop of __getOwnPropSymbols$2(b))
822
- __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
823
- return a;
824
- }, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), object = (config) => {
759
+ var object = (config) => {
825
760
  const { type } = config, typeName = typeof type == "string" ? type : type.name, objectName = createFieldName(typeName, !0);
826
761
  return sanity.defineField({
827
762
  name: objectName,
@@ -832,9 +767,10 @@ var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties,
832
767
  item: InternationalizedInput
833
768
  },
834
769
  fields: [
835
- sanity.defineField(__spreadProps$1(__spreadValues$2({}, typeof type == "string" ? { type } : type), {
770
+ sanity.defineField({
771
+ ...typeof type == "string" ? { type } : type,
836
772
  name: "value"
837
- }))
773
+ })
838
774
  ],
839
775
  preview: {
840
776
  select: {
@@ -843,20 +779,13 @@ var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties,
843
779
  }
844
780
  }
845
781
  });
846
- }, __defProp$1 = Object.defineProperty, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
847
- for (var prop in b || (b = {}))
848
- __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
849
- if (__getOwnPropSymbols$1)
850
- for (var prop of __getOwnPropSymbols$1(b))
851
- __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
852
- return a;
853
782
  };
854
783
  function flattenSchemaType(schemaType) {
855
784
  return sanity.isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
856
785
  }
857
786
  function extractInnerFields(fields, path, maxDepth) {
858
787
  return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
859
- const thisFieldWithPath = __spreadValues$1({ path: [...path, field.name] }, field);
788
+ const thisFieldWithPath = { path: [...path, field.name], ...field };
860
789
  if (field.type.jsonType === "object") {
861
790
  const innerFields = extractInnerFields(
862
791
  field.type.fields,
@@ -878,21 +807,12 @@ function extractInnerFields(fields, path, maxDepth) {
878
807
  return [...acc, thisFieldWithPath];
879
808
  }, []);
880
809
  }
881
- var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
882
- for (var prop in b || (b = {}))
883
- __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
884
- if (__getOwnPropSymbols)
885
- for (var prop of __getOwnPropSymbols(b))
886
- __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
887
- return a;
888
- }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
889
810
  const internationalizedArray = sanity.definePlugin((config) => {
890
- const pluginConfig = __spreadValues(__spreadValues({}, CONFIG_DEFAULT), config), {
811
+ const pluginConfig = { ...CONFIG_DEFAULT, ...config }, {
891
812
  apiVersion = "2025-10-15",
892
813
  select,
893
814
  languages,
894
815
  fieldTypes,
895
- defaultLanguages,
896
816
  buttonLocations
897
817
  } = pluginConfig;
898
818
  return {
@@ -913,16 +833,17 @@ const internationalizedArray = sanity.definePlugin((config) => {
913
833
  // Wrap document editor with a language provider
914
834
  form: {
915
835
  components: {
916
- field: (props) => /* @__PURE__ */ jsxRuntime.jsx(InternationalizedField, __spreadValues({}, props)),
836
+ field: (props) => /* @__PURE__ */ jsxRuntime.jsx(InternationalizedField, { ...props }),
917
837
  input: (props) => !(props.id === "root" && sanity.isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).map(
918
838
  (field) => field.type.name
919
839
  ).some(
920
840
  (name) => name.startsWith("internationalizedArray")
921
841
  ) ? props.renderDefault(props) : /* @__PURE__ */ jsxRuntime.jsx(
922
842
  InternationalizedArrayProvider,
923
- __spreadProps(__spreadValues({}, props), {
843
+ {
844
+ ...props,
924
845
  internationalizedArray: pluginConfig
925
- })
846
+ }
926
847
  )
927
848
  }
928
849
  },
@@ -930,7 +851,7 @@ const internationalizedArray = sanity.definePlugin((config) => {
930
851
  schema: {
931
852
  types: [
932
853
  ...fieldTypes.map(
933
- (type) => array({ type, apiVersion, select, languages, defaultLanguages })
854
+ (type) => array({ type, apiVersion, select, languages })
934
855
  ),
935
856
  ...fieldTypes.map((type) => object({ type }))
936
857
  ]