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.mjs CHANGED
@@ -5,7 +5,7 @@ import { isSanityDocument, useSchema, setIfMissing, insert, PatchEvent, useClien
5
5
  import { useLanguageFilterStudioContext } from "@sanity/language-filter";
6
6
  import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Spinner, Label, MenuButton, Menu, MenuItem, Flex, Tooltip } from "@sanity/ui";
7
7
  import equal from "fast-deep-equal";
8
- import { memo, useCallback, createContext, useContext, useDeferredValue, useMemo, useEffect, createElement } from "react";
8
+ import { memo, useCallback, useContext, createContext, useDeferredValue, useMemo, useEffect, createElement } from "react";
9
9
  import { useDocumentPane } from "sanity/structure";
10
10
  import { AddIcon, TranslateIcon, RemoveCircleIcon } from "@sanity/icons";
11
11
  import get from "lodash/get.js";
@@ -47,26 +47,18 @@ const namespace = "sanity-plugin-internationalized-array", version = "v1", funct
47
47
  buttonLocations: ["field"],
48
48
  buttonAddAll: !0,
49
49
  languageDisplay: "codeOnly"
50
- };
51
- 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) => {
52
- for (var prop in b || (b = {}))
53
- __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
54
- if (__getOwnPropSymbols$9)
55
- for (var prop of __getOwnPropSymbols$9(b))
56
- __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
57
- return a;
58
- }, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
59
- const getDocumentsToTranslate = (value, rootPath = []) => {
50
+ }, getDocumentsToTranslate = (value, rootPath = []) => {
60
51
  if (Array.isArray(value)) {
61
52
  const arrayRootPath = [...rootPath], internationalizedValues = value.filter((item) => {
62
53
  if (Array.isArray(item)) return !1;
63
54
  if (typeof item == "object") {
64
- const type = item == null ? void 0 : item._type;
65
- return (type == null ? void 0 : type.startsWith("internationalizedArray")) && (type == null ? void 0 : type.endsWith("Value"));
55
+ const type = item?._type;
56
+ return type?.startsWith("internationalizedArray") && type?.endsWith("Value");
66
57
  }
67
58
  return !1;
68
59
  });
69
- return internationalizedValues.length > 0 ? internationalizedValues.map((internationalizedValue) => __spreadProps$8(__spreadValues$9({}, internationalizedValue), {
60
+ return internationalizedValues.length > 0 ? internationalizedValues.map((internationalizedValue) => ({
61
+ ...internationalizedValue,
70
62
  path: arrayRootPath,
71
63
  pathString: arrayRootPath.join(".")
72
64
  })) : value.length > 0 ? value.map(
@@ -87,7 +79,7 @@ const getDocumentsToTranslate = (value, rootPath = []) => {
87
79
  function getLanguageDisplay(languageDisplay, title, code) {
88
80
  return languageDisplay === "codeOnly" ? code.toUpperCase() : languageDisplay === "titleOnly" ? title : languageDisplay === "titleAndCode" ? `${title} (${code.toUpperCase()})` : title;
89
81
  }
90
- function AddButtons(props) {
82
+ function AddButtons$1(props) {
91
83
  const { languages, readOnly, value, onClick } = props, { languageDisplay } = useInternationalizedArrayContext();
92
84
  return languages.length > 0 ? /* @__PURE__ */ jsx(
93
85
  Grid,
@@ -106,7 +98,7 @@ function AddButtons(props) {
106
98
  tone: "primary",
107
99
  mode: "ghost",
108
100
  fontSize: 1,
109
- disabled: readOnly || !!(value != null && value.find((item) => item._key === language.id)),
101
+ disabled: readOnly || !!value?.find((item) => item._key === language.id),
110
102
  text: languageTitle,
111
103
  icon: languages.length > MAX_COLUMNS[languageDisplay] && languageDisplay === "codeOnly" ? void 0 : AddIcon,
112
104
  value: language.id,
@@ -118,11 +110,10 @@ function AddButtons(props) {
118
110
  }
119
111
  ) : null;
120
112
  }
121
- var AddButtons$1 = memo(AddButtons);
113
+ var AddButtons = memo(AddButtons$1);
122
114
  function DocumentAddButtons(props) {
123
115
  const { filteredLanguages } = useInternationalizedArrayContext(), value = isSanityDocument(props.value) ? props.value : void 0, toast = useToast(), { onChange } = useDocumentPane(), schema = useSchema(), documentsToTranslation = getDocumentsToTranslate(value, []), getInitialValueForType = useCallback(
124
116
  (typeName) => {
125
- var _a;
126
117
  if (!typeName) return;
127
118
  const match = typeName.match(/^internationalizedArray(.+)Value$/);
128
119
  if (!match) return;
@@ -137,13 +128,13 @@ function DocumentAddButtons(props) {
137
128
  try {
138
129
  const schemaType = schema.get(typeName);
139
130
  if (schemaType) {
140
- const valueField = (_a = schemaType == null ? void 0 : schemaType.fields) == null ? void 0 : _a.find(
131
+ const valueField = schemaType?.fields?.find(
141
132
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
133
  (f) => f.name === "value"
143
134
  );
144
135
  if (valueField) {
145
136
  const fieldType = valueField.type;
146
- 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))
137
+ if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || arrayBasedTypes.includes(fieldType?.name))
147
138
  return [];
148
139
  }
149
140
  }
@@ -167,7 +158,7 @@ function DocumentAddButtons(props) {
167
158
  return;
168
159
  }
169
160
  const alreadyTranslated = documentsToTranslation.filter(
170
- (translation) => (translation == null ? void 0 : translation._key) === languageId
161
+ (translation) => translation?._key === languageId
171
162
  ), removeDuplicates = documentsToTranslation.reduce((filteredTranslations, translation) => alreadyTranslated.filter(
172
163
  (alreadyTranslation) => alreadyTranslation.pathString === translation.pathString
173
164
  ).length > 0 || filteredTranslations.filter(
@@ -203,7 +194,7 @@ function DocumentAddButtons(props) {
203
194
  return /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
204
195
  /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Add translation to internationalized fields" }) }),
205
196
  /* @__PURE__ */ jsx(
206
- AddButtons$1,
197
+ AddButtons,
207
198
  {
208
199
  languages: filteredLanguages,
209
200
  readOnly: !1,
@@ -220,36 +211,28 @@ const getSelectedValue = (select, document) => {
220
211
  for (const [key, path] of Object.entries(selection)) {
221
212
  let value = get(document, path);
222
213
  Array.isArray(value) && (value = value.filter(
223
- (item) => typeof item == "object" ? (item == null ? void 0 : item._type) === "reference" && "_ref" in item : !0
214
+ (item) => typeof item == "object" ? item?._type === "reference" && "_ref" in item : !0
224
215
  )), selectedValue[key] = value;
225
216
  }
226
217
  return selectedValue;
227
- };
228
- 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) => {
229
- for (var prop in b || (b = {}))
230
- __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
231
- if (__getOwnPropSymbols$8)
232
- for (var prop of __getOwnPropSymbols$8(b))
233
- __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
234
- return a;
235
- }, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
236
- const InternationalizedArrayContext = createContext(__spreadProps$7(__spreadValues$8({}, CONFIG_DEFAULT), {
218
+ }, InternationalizedArrayContext = createContext({
219
+ ...CONFIG_DEFAULT,
237
220
  languages: [],
238
221
  filteredLanguages: []
239
- }));
222
+ });
240
223
  function useInternationalizedArrayContext() {
241
224
  return useContext(InternationalizedArrayContext);
242
225
  }
243
226
  function InternationalizedArrayProvider(props) {
244
- const { internationalizedArray: internationalizedArray2 } = props, client = useClient({ apiVersion: internationalizedArray2.apiVersion }), workspace = useWorkspace(), { formState } = useDocumentPane(), deferredDocument = useDeferredValue(formState == null ? void 0 : formState.value), selectedValue = useMemo(
227
+ const { internationalizedArray: internationalizedArray2 } = props, client = useClient({ apiVersion: internationalizedArray2.apiVersion }), workspace = useWorkspace(), { formState } = useDocumentPane(), deferredDocument = useDeferredValue(formState?.value), selectedValue = useMemo(
245
228
  () => getSelectedValue(internationalizedArray2.select, deferredDocument),
246
229
  [internationalizedArray2.select, deferredDocument]
247
230
  ), workspaceId = useMemo(() => {
248
- if (workspace != null && workspace.name)
231
+ if (workspace?.name)
249
232
  return workspace.name;
250
233
  const workspaceKey = {
251
- name: workspace == null ? void 0 : workspace.name,
252
- title: workspace == null ? void 0 : workspace.title
234
+ name: workspace?.name,
235
+ title: workspace?.title
253
236
  // Add other stable properties as needed
254
237
  };
255
238
  return JSON.stringify(workspaceKey);
@@ -281,7 +264,7 @@ function InternationalizedArrayProvider(props) {
281
264
  (language) => selectedLanguageIds.includes(language.id)
282
265
  ) : languages;
283
266
  }, [deferredDocument, languageFilterOptions, languages, selectedLanguageIds]), showDocumentButtons = internationalizedArray2.buttonLocations.includes("document"), context = useMemo(
284
- () => __spreadProps$7(__spreadValues$8({}, internationalizedArray2), { languages, filteredLanguages }),
267
+ () => ({ ...internationalizedArray2, languages, filteredLanguages }),
285
268
  [filteredLanguages, internationalizedArray2, languages]
286
269
  );
287
270
  return /* @__PURE__ */ jsx(InternationalizedArrayContext.Provider, { value: context, children: showDocumentButtons ? /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
@@ -289,30 +272,24 @@ function InternationalizedArrayProvider(props) {
289
272
  props.renderDefault(props)
290
273
  ] }) : props.renderDefault(props) });
291
274
  }
292
- 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) => {
293
- for (var prop in b || (b = {}))
294
- __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
295
- if (__getOwnPropSymbols$7)
296
- for (var prop of __getOwnPropSymbols$7(b))
297
- __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
298
- return a;
299
- }, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
300
275
  function InternationalizedField(props) {
301
276
  const { languages } = useInternationalizedArrayContext(), customProps = useMemo(() => {
302
- var _a;
303
- 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;
304
- return __spreadProps$6(__spreadValues$7({}, props), {
277
+ 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;
278
+ return {
279
+ ...props,
305
280
  title: shouldHideTitle ? "" : props.title
306
- });
281
+ };
307
282
  }, [props, languages]);
308
- return customProps.schemaType.name.startsWith("internationalizedArray") ? customProps.schemaType.name === "reference" && customProps.value ? customProps.renderDefault(__spreadProps$6(__spreadValues$7({}, customProps), {
283
+ return customProps.schemaType.name.startsWith("internationalizedArray") ? customProps.schemaType.name === "reference" && customProps.value ? customProps.renderDefault({
284
+ ...customProps,
309
285
  title: "",
310
286
  level: 0
311
287
  // Reset the level to avoid nested styling
312
- })) : customProps.schemaType.name === "string" || customProps.schemaType.name === "number" || customProps.schemaType.name === "text" ? customProps.children : customProps.renderDefault(__spreadProps$6(__spreadValues$7({}, customProps), {
288
+ }) : customProps.schemaType.name === "string" || customProps.schemaType.name === "number" || customProps.schemaType.name === "text" ? customProps.children : customProps.renderDefault({
289
+ ...customProps,
313
290
  level: 0
314
291
  // Reset the level to avoid nested styling
315
- })) : customProps.renderDefault(customProps);
292
+ }) : customProps.renderDefault(customProps);
316
293
  }
317
294
  var Preload = memo(function(props) {
318
295
  const client = useClient({ apiVersion: props.apiVersion }), cacheKey = createCacheKey({});
@@ -328,19 +305,11 @@ function checkAllLanguagesArePresent(languages, value) {
328
305
  return languagesInUseIds.length === filteredLanguageIds.length && languagesInUseIds.every((l) => filteredLanguageIds.includes(l));
329
306
  }
330
307
  function createAddAllTitle(value, languages) {
331
- 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";
308
+ return value?.length ? `Add missing ${languages.length - value.length === 1 ? "language" : "languages"}` : languages.length === 1 ? `Add ${languages[0].title} Field` : "Add all languages";
332
309
  }
333
310
  function createValueSchemaTypeName(schemaType) {
334
311
  return `${schemaType.name}Value`;
335
312
  }
336
- 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) => {
337
- for (var prop in b || (b = {}))
338
- __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
339
- if (__getOwnPropSymbols$6)
340
- for (var prop of __getOwnPropSymbols$6(b))
341
- __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
342
- return a;
343
- }, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
344
313
  function createAddLanguagePatches(config) {
345
314
  const {
346
315
  addLanguageKeys,
@@ -349,13 +318,15 @@ function createAddLanguagePatches(config) {
349
318
  filteredLanguages,
350
319
  value,
351
320
  path = []
352
- } = config, itemBase = { _type: createValueSchemaTypeName(schemaType) }, newItems = Array.isArray(addLanguageKeys) && addLanguageKeys.length > 0 ? addLanguageKeys.map((id) => __spreadProps$5(__spreadValues$6({}, itemBase), {
321
+ } = config, itemBase = { _type: createValueSchemaTypeName(schemaType) }, newItems = Array.isArray(addLanguageKeys) && addLanguageKeys.length > 0 ? addLanguageKeys.map((id) => ({
322
+ ...itemBase,
353
323
  _key: id
354
324
  })) : filteredLanguages.filter(
355
- (language) => value != null && value.length ? !value.find((v) => v._key === language.id) : !0
356
- ).map((language) => __spreadProps$5(__spreadValues$6({}, itemBase), {
325
+ (language) => value?.length ? !value.find((v) => v._key === language.id) : !0
326
+ ).map((language) => ({
327
+ ...itemBase,
357
328
  _key: language.id
358
- })), languagesInUse = value != null && value.length ? value.map((v) => v) : [];
329
+ })), languagesInUse = value?.length ? value.map((v) => v) : [];
359
330
  return newItems.map((item) => {
360
331
  const languageIndex = languages.findIndex((l) => item._key === l.id), remainingLanguages = languages.slice(languageIndex + 1), nextLanguageIndex = languagesInUse.findIndex(
361
332
  (l) => (
@@ -373,7 +344,7 @@ function createAddLanguagePatches(config) {
373
344
  });
374
345
  }
375
346
  const createTranslateFieldActions = (fieldActionProps, { languages, filteredLanguages }) => languages.map((language) => {
376
- const value = 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 } = useDocumentPane(), onAction = useCallback(() => {
347
+ const value = 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 } = useDocumentPane(), onAction = useCallback(() => {
377
348
  const { schemaType, path } = fieldActionProps, addLanguageKeys = [language.id], patches = createAddLanguagePatches({
378
349
  addLanguageKeys,
379
350
  schemaType,
@@ -415,8 +386,7 @@ const createTranslateFieldActions = (fieldActionProps, { languages, filteredLang
415
386
  }, internationalizedArrayFieldAction = defineDocumentFieldAction({
416
387
  name: "internationalizedArray",
417
388
  useAction(fieldActionProps) {
418
- var _a, _b;
419
- const isInternationalizedArrayField = (_b = (_a = fieldActionProps == null ? void 0 : fieldActionProps.schemaType) == null ? void 0 : _a.type) == null ? void 0 : _b.name.startsWith(
389
+ const isInternationalizedArrayField = fieldActionProps?.schemaType?.type?.name.startsWith(
420
390
  "internationalizedArray"
421
391
  ), { languages, filteredLanguages } = useInternationalizedArrayContext(), translateFieldActions = createTranslateFieldActions(
422
392
  fieldActionProps,
@@ -472,14 +442,6 @@ function Feedback() {
472
442
  /* @__PURE__ */ jsx(Card, { padding: 2, border: !0, radius: 2, children: /* @__PURE__ */ jsx(Code, { size: 1, language: "javascript", children: JSON.stringify(schemaExample, null, 2) }) })
473
443
  ] }) });
474
444
  }
475
- 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) => {
476
- for (var prop in b || (b = {}))
477
- __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
478
- if (__getOwnPropSymbols$5)
479
- for (var prop of __getOwnPropSymbols$5(b))
480
- __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
481
- return a;
482
- }, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
483
445
  function InternationalizedArray(props) {
484
446
  const {
485
447
  members,
@@ -507,10 +469,9 @@ function InternationalizedArray(props) {
507
469
  [languageFilterEnabled, members, languageFilterOptions, selectedLanguageIds]
508
470
  ), handleAddLanguage = useCallback(
509
471
  async (param) => {
510
- var _a;
511
- if (!(filteredLanguages != null && filteredLanguages.length))
472
+ if (!filteredLanguages?.length)
512
473
  return;
513
- const addLanguageKeys = Array.isArray(param) ? param : [(_a = param == null ? void 0 : param.currentTarget) == null ? void 0 : _a.value].filter(Boolean), patches = createAddLanguagePatches({
474
+ const addLanguageKeys = Array.isArray(param) ? param : [param?.currentTarget?.value].filter(Boolean), patches = createAddLanguagePatches({
514
475
  addLanguageKeys,
515
476
  schemaType,
516
477
  languages,
@@ -538,23 +499,23 @@ function InternationalizedArray(props) {
538
499
  documentReadOnly
539
500
  ]);
540
501
  const handleRestoreOrder = useCallback(() => {
541
- if (!(value != null && value.length) || !(languages != null && languages.length))
502
+ if (!value?.length || !languages?.length)
542
503
  return;
543
504
  const updatedValue = value.reduce((acc, v) => {
544
- const newIndex = languages.findIndex((l) => l.id === (v == null ? void 0 : v._key));
505
+ const newIndex = languages.findIndex((l) => l.id === v?._key);
545
506
  return newIndex > -1 && (acc[newIndex] = v), acc;
546
507
  }, []).filter(Boolean);
547
- (value == null ? void 0 : value.length) !== updatedValue.length && toast.push({
508
+ value?.length !== updatedValue.length && toast.push({
548
509
  title: "There was an error reordering languages",
549
510
  status: "warning"
550
511
  }), onChange(set(updatedValue));
551
- }, [toast, languages, onChange, value]), allKeysAreLanguages = 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 = useMemo(
552
- () => languages && languages.length > 1 ? languages.filter((l) => value == null ? void 0 : value.find((v) => v._key === l.id)) : [],
512
+ }, [toast, languages, onChange, value]), allKeysAreLanguages = useMemo(() => !value?.length || !languages?.length ? !0 : value?.every((v) => languages.find((l) => l?.id === v?._key)), [value, languages]), languagesInUse = useMemo(
513
+ () => languages && languages.length > 1 ? languages.filter((l) => value?.find((v) => v._key === l.id)) : [],
553
514
  [languages, value]
554
- ), languagesOutOfOrder = useMemo(() => !(value != null && value.length) || !languagesInUse.length ? [] : value.map(
515
+ ), languagesOutOfOrder = useMemo(() => !value?.length || !languagesInUse.length ? [] : value.map(
555
516
  (v, vIndex) => vIndex === languagesInUse.findIndex((l) => l.id === v._key) ? null : v
556
517
  ).filter(Boolean), [value, languagesInUse]), languagesAreValid = useMemo(
557
- () => !(languages != null && languages.length) || (languages == null ? void 0 : languages.length) && languages.every((item) => item.id && item.title),
518
+ () => !languages?.length || languages?.length && languages.every((item) => item.id && item.title),
558
519
  [languages]
559
520
  );
560
521
  useEffect(() => {
@@ -569,21 +530,22 @@ function InternationalizedArray(props) {
569
530
  const addButtonsAreVisible = (
570
531
  // Plugin was configured to display buttons here (default!)
571
532
  buttonLocations.includes("field") && // There's at least one language visible
572
- (filteredLanguages == null ? void 0 : filteredLanguages.length) > 0 && // Not every language has a value yet
533
+ filteredLanguages?.length > 0 && // Not every language has a value yet
573
534
  !allLanguagesArePresent
574
- ), fieldHasMembers = (members == null ? void 0 : members.length) > 0;
535
+ ), fieldHasMembers = members?.length > 0;
575
536
  return /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
576
537
  fieldHasMembers ? /* @__PURE__ */ jsx(Fragment, { children: filteredMembers.map((member) => member.kind === "item" ? /* @__PURE__ */ createElement(
577
538
  ArrayOfObjectsItem,
578
- __spreadProps$4(__spreadValues$5({}, props), {
539
+ {
540
+ ...props,
579
541
  key: member.key,
580
542
  member
581
- })
543
+ }
582
544
  ) : /* @__PURE__ */ jsx(MemberItemError, { member }, member.key)) }) : null,
583
545
  !addButtonsAreVisible && !fieldHasMembers ? /* @__PURE__ */ jsx(Card, { border: !0, tone: "transparent", padding: 3, radius: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: "This internationalized field currently has no translations." }) }) : null,
584
546
  addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
585
547
  /* @__PURE__ */ jsx(
586
- AddButtons$1,
548
+ AddButtons,
587
549
  {
588
550
  languages: filteredLanguages,
589
551
  value,
@@ -606,17 +568,9 @@ function InternationalizedArray(props) {
606
568
  ] });
607
569
  }
608
570
  function getLanguagesFieldOption(schemaType) {
609
- var _a;
610
- return schemaType ? ((_a = schemaType.options) == null ? void 0 : _a.languages) || getLanguagesFieldOption(schemaType.type) : void 0;
571
+ return schemaType ? schemaType.options?.languages || getLanguagesFieldOption(schemaType.type) : void 0;
611
572
  }
612
- 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) => {
613
- for (var prop in b || (b = {}))
614
- __hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
615
- if (__getOwnPropSymbols$4)
616
- for (var prop of __getOwnPropSymbols$4(b))
617
- __propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
618
- return a;
619
- }, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), array = (config) => {
573
+ var array = (config) => {
620
574
  const { apiVersion, select, languages, type } = config, typeName = typeof type == "string" ? type : type.name, arrayName = createFieldName(typeName), objectName = createFieldName(typeName, !0);
621
575
  return defineField({
622
576
  name: arrayName,
@@ -632,19 +586,19 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
632
586
  languages
633
587
  },
634
588
  of: [
635
- defineField(__spreadProps$3(__spreadValues$4({}, typeof type == "string" ? {} : type), {
589
+ defineField({
590
+ ...typeof type == "string" ? {} : type,
636
591
  name: objectName,
637
592
  type: objectName
638
- }))
593
+ })
639
594
  ],
640
595
  // @ts-expect-error - fix typings
641
596
  validation: (rule) => rule.custom(async (value, context) => {
642
- var _a;
643
- if (!value || value.length === 0 || value.length === 1 && !((_a = value[0]) != null && _a._key))
597
+ if (!value || value.length === 0 || value.length === 1 && !value[0]?._key)
644
598
  return !0;
645
599
  const selectedValue = getSelectedValue(select, context.document), client = context.getClient({ apiVersion });
646
600
  let contextLanguages = [];
647
- const languagesFieldOption = getLanguagesFieldOption(context == null ? void 0 : context.type);
601
+ const languagesFieldOption = getLanguagesFieldOption(context?.type);
648
602
  if (Array.isArray(languagesFieldOption))
649
603
  contextLanguages = languagesFieldOption;
650
604
  else if (Array.isArray(peek(selectedValue)))
@@ -671,7 +625,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
671
625
  if (value && value.length > contextLanguages.length)
672
626
  return `Cannot be more than ${contextLanguages.length === 1 ? "1 item" : `${contextLanguages.length} items`}`;
673
627
  const languageIds = new Set(contextLanguages.map((lang) => lang.id)), nonLanguageKeys = value.filter(
674
- (item) => (item == null ? void 0 : item._key) && !languageIds.has(item._key)
628
+ (item) => item?._key && !languageIds.has(item._key)
675
629
  );
676
630
  if (nonLanguageKeys.length)
677
631
  return {
@@ -680,7 +634,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
680
634
  };
681
635
  const seenKeys = /* @__PURE__ */ new Set(), duplicateValues = [];
682
636
  for (const item of value)
683
- item != null && item._key && (seenKeys.has(item._key) ? duplicateValues.push(item) : seenKeys.add(item._key));
637
+ item?._key && (seenKeys.has(item._key) ? duplicateValues.push(item) : seenKeys.add(item._key));
684
638
  return duplicateValues.length ? {
685
639
  message: "There can only be one field per language",
686
640
  paths: duplicateValues.map((item) => [{ _key: item._key }])
@@ -689,7 +643,7 @@ var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties,
689
643
  });
690
644
  };
691
645
  function getToneFromValidation(validations) {
692
- if (!(validations != null && validations.length))
646
+ if (!validations?.length)
693
647
  return;
694
648
  const validationLevels = validations.map((v) => v.level);
695
649
  if (validationLevels.includes("error"))
@@ -697,31 +651,22 @@ function getToneFromValidation(validations) {
697
651
  if (validationLevels.includes("warning"))
698
652
  return "caution";
699
653
  }
700
- 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) => {
701
- for (var prop in b || (b = {}))
702
- __hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
703
- if (__getOwnPropSymbols$3)
704
- for (var prop of __getOwnPropSymbols$3(b))
705
- __propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
706
- return a;
707
- }, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
708
654
  function InternationalizedInput(props) {
709
655
  const parentValue = useFormValue(
710
656
  props.path.slice(0, -1)
711
657
  ), originalOnChange = props.inputProps.onChange, wrappedOnChange = useCallback(
712
658
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
713
659
  (patches) => {
714
- var _a;
715
660
  if (!Array.isArray(patches))
716
661
  return originalOnChange(patches);
717
- const valueField = (_a = props.value) == null ? void 0 : _a.value;
662
+ const valueField = props.value?.value;
718
663
  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)) {
719
664
  const initPatch = valueField === void 0 ? { type: "setIfMissing", path: ["value"], value: [] } : null, fixedPatches = patches.map((patch) => {
720
665
  if (!patch || typeof patch != "object")
721
666
  return patch;
722
667
  if (patch.type === "insert" && patch.path && Array.isArray(patch.path)) {
723
668
  const fixedPath = patch.path[0] === "value" ? patch.path : ["value", ...patch.path];
724
- return __spreadProps$2(__spreadValues$3({}, patch), { path: fixedPath });
669
+ return { ...patch, path: fixedPath };
725
670
  }
726
671
  return patch;
727
672
  }), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
@@ -730,7 +675,8 @@ function InternationalizedInput(props) {
730
675
  return originalOnChange(patches);
731
676
  },
732
677
  [props.value, originalOnChange]
733
- ), inlineProps = __spreadProps$2(__spreadValues$3({}, props.inputProps), {
678
+ ), inlineProps = {
679
+ ...props.inputProps,
734
680
  // This is the magic that makes inline editing work?
735
681
  members: props.inputProps.members.filter(
736
682
  (m) => m.kind === "field" && m.name === "value"
@@ -740,17 +686,13 @@ function InternationalizedInput(props) {
740
686
  value: props.value,
741
687
  // Use our wrapped onChange handler
742
688
  onChange: wrappedOnChange
743
- }), { validation, value, onChange, readOnly } = inlineProps, { languages, languageDisplay, defaultLanguages } = useInternationalizedArrayContext(), languageKeysInUse = useMemo(
744
- () => {
745
- var _a;
746
- return (_a = parentValue == null ? void 0 : parentValue.map((v) => v._key)) != null ? _a : [];
747
- },
689
+ }, { validation, value, onChange, readOnly } = inlineProps, { languages, languageDisplay, defaultLanguages } = useInternationalizedArrayContext(), languageKeysInUse = useMemo(
690
+ () => parentValue?.map((v) => v._key) ?? [],
748
691
  [parentValue]
749
- ), keyIsValid = languages != null && languages.length ? languages.find((l) => l.id === value._key) : !1, handleKeyChange = useCallback(
692
+ ), keyIsValid = languages?.length ? languages.find((l) => l.id === value._key) : !1, handleKeyChange = useCallback(
750
693
  (event) => {
751
- var _a;
752
- const languageId = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.value;
753
- !value || !(languages != null && languages.length) || !languages.find((l) => l.id === languageId) || onChange([set(languageId, ["_key"])]);
694
+ const languageId = event?.currentTarget?.value;
695
+ !value || !languages?.length || !languages.find((l) => l.id === languageId) || onChange([set(languageId, ["_key"])]);
754
696
  },
755
697
  [onChange, value, languages]
756
698
  ), handleUnset = useCallback(() => {
@@ -803,14 +745,7 @@ function InternationalizedInput(props) {
803
745
  ] })
804
746
  ] }) });
805
747
  }
806
- 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) => {
807
- for (var prop in b || (b = {}))
808
- __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
809
- if (__getOwnPropSymbols$2)
810
- for (var prop of __getOwnPropSymbols$2(b))
811
- __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
812
- return a;
813
- }, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), object = (config) => {
748
+ var object = (config) => {
814
749
  const { type } = config, typeName = typeof type == "string" ? type : type.name, objectName = createFieldName(typeName, !0);
815
750
  return defineField({
816
751
  name: objectName,
@@ -821,9 +756,10 @@ var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties,
821
756
  item: InternationalizedInput
822
757
  },
823
758
  fields: [
824
- defineField(__spreadProps$1(__spreadValues$2({}, typeof type == "string" ? { type } : type), {
759
+ defineField({
760
+ ...typeof type == "string" ? { type } : type,
825
761
  name: "value"
826
- }))
762
+ })
827
763
  ],
828
764
  preview: {
829
765
  select: {
@@ -832,20 +768,13 @@ var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties,
832
768
  }
833
769
  }
834
770
  });
835
- }, __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) => {
836
- for (var prop in b || (b = {}))
837
- __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
838
- if (__getOwnPropSymbols$1)
839
- for (var prop of __getOwnPropSymbols$1(b))
840
- __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
841
- return a;
842
771
  };
843
772
  function flattenSchemaType(schemaType) {
844
773
  return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
845
774
  }
846
775
  function extractInnerFields(fields, path, maxDepth) {
847
776
  return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
848
- const thisFieldWithPath = __spreadValues$1({ path: [...path, field.name] }, field);
777
+ const thisFieldWithPath = { path: [...path, field.name], ...field };
849
778
  if (field.type.jsonType === "object") {
850
779
  const innerFields = extractInnerFields(
851
780
  field.type.fields,
@@ -867,21 +796,12 @@ function extractInnerFields(fields, path, maxDepth) {
867
796
  return [...acc, thisFieldWithPath];
868
797
  }, []);
869
798
  }
870
- 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) => {
871
- for (var prop in b || (b = {}))
872
- __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
873
- if (__getOwnPropSymbols)
874
- for (var prop of __getOwnPropSymbols(b))
875
- __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
876
- return a;
877
- }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
878
799
  const internationalizedArray = definePlugin((config) => {
879
- const pluginConfig = __spreadValues(__spreadValues({}, CONFIG_DEFAULT), config), {
800
+ const pluginConfig = { ...CONFIG_DEFAULT, ...config }, {
880
801
  apiVersion = "2025-10-15",
881
802
  select,
882
803
  languages,
883
804
  fieldTypes,
884
- defaultLanguages,
885
805
  buttonLocations
886
806
  } = pluginConfig;
887
807
  return {
@@ -902,16 +822,17 @@ const internationalizedArray = definePlugin((config) => {
902
822
  // Wrap document editor with a language provider
903
823
  form: {
904
824
  components: {
905
- field: (props) => /* @__PURE__ */ jsx(InternationalizedField, __spreadValues({}, props)),
825
+ field: (props) => /* @__PURE__ */ jsx(InternationalizedField, { ...props }),
906
826
  input: (props) => !(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).map(
907
827
  (field) => field.type.name
908
828
  ).some(
909
829
  (name) => name.startsWith("internationalizedArray")
910
830
  ) ? props.renderDefault(props) : /* @__PURE__ */ jsx(
911
831
  InternationalizedArrayProvider,
912
- __spreadProps(__spreadValues({}, props), {
832
+ {
833
+ ...props,
913
834
  internationalizedArray: pluginConfig
914
- })
835
+ }
915
836
  )
916
837
  }
917
838
  },
@@ -919,7 +840,7 @@ const internationalizedArray = definePlugin((config) => {
919
840
  schema: {
920
841
  types: [
921
842
  ...fieldTypes.map(
922
- (type) => array({ type, apiVersion, select, languages, defaultLanguages })
843
+ (type) => array({ type, apiVersion, select, languages })
923
844
  ),
924
845
  ...fieldTypes.map((type) => object({ type }))
925
846
  ]