sanity-plugin-internationalized-array 5.0.0-canary.0 → 5.0.0

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/dist/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useLanguageFilterStudioContext, languageFilter } from "@sanity/language-filter";
3
- import { isSanityDocument, useSchema, setIfMissing, insert, PatchEvent, useClient, useWorkspace, useFormValue, defineDocumentFieldAction, set, ArrayOfObjectsItem, MemberItemError, defineField, unset, isDocumentSchemaType, definePlugin, isObjectInputProps } from "sanity";
3
+ import { useClient, useWorkspace, useGetFormValue, useSchema, isSanityDocument, setIfMissing, insert, PatchEvent, isDocumentSchemaType, defineDocumentFieldAction, useFormValue, set, ArrayOfObjectsItem, MemberItemError, defineField, unset, definePlugin, isObjectInputProps } from "sanity";
4
4
  import { c } from "react/compiler-runtime";
5
- import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Flex, Spinner, Label, MenuButton, Menu, MenuItem, Tooltip } from "@sanity/ui";
6
- import { createContext, useContext, useDeferredValue, use, useCallback, useEffect, createElement } from "react";
7
- import { useDocumentPane } from "sanity/structure";
5
+ import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Flex, Spinner, Label, MenuButton, Tooltip, MenuItem, Menu } from "@sanity/ui";
8
6
  import { randomKey } from "@sanity/util/content";
7
+ import { useDocumentPane } from "sanity/structure";
9
8
  import { AddIcon, TranslateIcon, WarningOutlineIcon, RemoveCircleIcon } from "@sanity/icons";
10
- import { get, upperFirst, camelCase } from "lodash-es";
11
- const namespace = "sanity-plugin-internationalized-array", functionCache = /* @__PURE__ */ new Map(), functionKeyCache = /* @__PURE__ */ new WeakMap(), promiseCache = /* @__PURE__ */ new Map();
9
+ import { createContext, useContext, useDeferredValue, use, useCallback, useEffect, createElement } from "react";
10
+ import get from "lodash-es/get.js";
11
+ import camelCase from "lodash-es/camelCase.js";
12
+ import upperFirst from "lodash-es/upperFirst.js";
13
+ const namespace = "sanity-plugin-internationalized-array", functionKeyCache = /* @__PURE__ */ new WeakMap(), promiseCache = /* @__PURE__ */ new Map(), functionCache = /* @__PURE__ */ new Map();
12
14
  function stringifyCacheKey(key) {
13
15
  return JSON.stringify(key);
14
16
  }
@@ -65,6 +67,7 @@ const preloadWithKey = (fn, key) => {
65
67
  buttonLocations: ["field"],
66
68
  buttonAddAll: !0,
67
69
  languageDisplay: "codeOnly",
70
+ includeForDocumentType: (documentType) => documentType !== "translation.metadata",
68
71
  languageFilter: {
69
72
  documentTypes: []
70
73
  }
@@ -95,86 +98,6 @@ const preloadWithKey = (fn, key) => {
95
98
  function getLanguageDisplay(languageDisplay, title, code) {
96
99
  return languageDisplay === "codeOnly" ? code.toUpperCase() : languageDisplay === "titleOnly" ? title : languageDisplay === "titleAndCode" ? `${title} (${code.toUpperCase()})` : title;
97
100
  }
98
- function AddButtons(props) {
99
- const $ = c(6), {
100
- languages,
101
- readOnly,
102
- value,
103
- handleClick
104
- } = props, {
105
- languageDisplay
106
- } = useInternationalizedArrayContext();
107
- let t0;
108
- return $[0] !== handleClick || $[1] !== languageDisplay || $[2] !== languages || $[3] !== readOnly || $[4] !== value ? (t0 = languages.length > 0 ? /* @__PURE__ */ jsx(Grid, { columns: Math.min(languages.length, MAX_COLUMNS[languageDisplay]), gap: 2, "data-testid": "add-buttons-grid", children: languages.map((language) => {
109
- const languageTitle = getLanguageDisplay(languageDisplay, language.title, language.id);
110
- return /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", fontSize: 1, "data-testid": `add-${language.id}`, disabled: readOnly || !!value?.find((item) => item[LANGUAGE_FIELD_NAME] === language.id), text: languageTitle, icon: languages.length > MAX_COLUMNS[languageDisplay] && languageDisplay === "codeOnly" ? void 0 : AddIcon, value: language.id, onClick: () => handleClick(language.id) }, language.id);
111
- }) }) : null, $[0] = handleClick, $[1] = languageDisplay, $[2] = languages, $[3] = readOnly, $[4] = value, $[5] = t0) : t0 = $[5], t0;
112
- }
113
- function DocumentAddButtons(props) {
114
- const $ = c(14), {
115
- filteredLanguages
116
- } = useInternationalizedArrayContext(), value = isSanityDocument(props.value) ? props.value : void 0, toast = useToast(), {
117
- onChange
118
- } = useDocumentPane(), schema = useSchema();
119
- let t0;
120
- $[0] !== value ? (t0 = getDocumentsToTranslate(value, []), $[0] = value, $[1] = t0) : t0 = $[1];
121
- const documentsToTranslation = t0;
122
- let t1;
123
- $[2] !== schema ? (t1 = (typeName) => {
124
- if (!typeName)
125
- return;
126
- const match = typeName.match(/^internationalizedArray(.+)Value$/);
127
- if (!match || !match[1])
128
- return;
129
- const baseTypeName = match[1].charAt(0).toLowerCase() + match[1].slice(1), arrayBasedTypes = /* @__PURE__ */ new Set(["body", "htmlContent", "blockContent", "portableText"]);
130
- if (arrayBasedTypes.has(baseTypeName))
131
- return [];
132
- const schemaType = schema.get(typeName);
133
- if (schemaType && "fields" in schemaType) {
134
- const valueField = schemaType.fields.find(_temp$3);
135
- if (valueField) {
136
- const fieldType = valueField.type;
137
- if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || fieldType?.name && arrayBasedTypes.has(fieldType.name))
138
- return [];
139
- }
140
- }
141
- }, $[2] = schema, $[3] = t1) : t1 = $[3];
142
- const getInitialValueForType = t1;
143
- let t2;
144
- $[4] !== documentsToTranslation || $[5] !== filteredLanguages || $[6] !== getInitialValueForType || $[7] !== onChange || $[8] !== toast ? (t2 = async (languageId) => {
145
- const alreadyTranslated = documentsToTranslation.filter((translation) => translation?.[LANGUAGE_FIELD_NAME] === languageId), removeDuplicates = documentsToTranslation.reduce((filteredTranslations, translation_0) => (alreadyTranslated.filter((alreadyTranslation) => alreadyTranslation.pathString === translation_0.pathString).length > 0 || filteredTranslations.filter((filteredTranslation) => filteredTranslation.path === translation_0.path).length > 0 || filteredTranslations.push(translation_0), filteredTranslations), []);
146
- if (removeDuplicates.length === 0) {
147
- const language = filteredLanguages.find((l) => l.id === languageId);
148
- toast.push({
149
- status: "warning",
150
- title: `No missing translations for ${language?.title || languageId} found.`
151
- });
152
- return;
153
- }
154
- const patches = [];
155
- for (const toTranslate of removeDuplicates) {
156
- const path = toTranslate.path, initialValue = getInitialValueForType(toTranslate._type), ifMissing = setIfMissing([], path), insertValue = insert([{
157
- _key: randomKey(),
158
- [LANGUAGE_FIELD_NAME]: languageId,
159
- _type: toTranslate._type,
160
- value: initialValue
161
- }], "after", [...path, -1]);
162
- patches.push(ifMissing), patches.push(insertValue);
163
- }
164
- onChange(PatchEvent.from(patches.flat()));
165
- }, $[4] = documentsToTranslation, $[5] = filteredLanguages, $[6] = getInitialValueForType, $[7] = onChange, $[8] = toast, $[9] = t2) : t2 = $[9];
166
- const handleDocumentButtonClick = t2;
167
- let t3;
168
- $[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Add translation to internationalized fields" }) }), $[10] = t3) : t3 = $[10];
169
- let t4;
170
- return $[11] !== filteredLanguages || $[12] !== handleDocumentButtonClick ? (t4 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
171
- t3,
172
- /* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, readOnly: !1, value: void 0, handleClick: handleDocumentButtonClick })
173
- ] }), $[11] = filteredLanguages, $[12] = handleDocumentButtonClick, $[13] = t4) : t4 = $[13], t4;
174
- }
175
- function _temp$3(f) {
176
- return f.name === "value";
177
- }
178
101
  const getSelectedValue = (select, document) => {
179
102
  if (!select || !document)
180
103
  return {};
@@ -193,8 +116,9 @@ function useInternationalizedArrayContext() {
193
116
  return useContext(InternationalizedArrayContext);
194
117
  }
195
118
  function InternationalizedArrayProvider(props) {
196
- const $ = c(38), {
197
- internationalizedArray: internationalizedArray2
119
+ const $ = c(33), {
120
+ internationalizedArray: internationalizedArray2,
121
+ documentType
198
122
  } = props;
199
123
  let t0;
200
124
  $[0] !== internationalizedArray2.apiVersion ? (t0 = {
@@ -243,73 +167,166 @@ function InternationalizedArrayProvider(props) {
243
167
  const languagesPromise = t4, languages = languagesPromise ? use(languagesPromise) : internationalizedArray2.languages, {
244
168
  selectedLanguageIds,
245
169
  options: languageFilterOptions
246
- } = useLanguageFilterStudioContext(), documentType = deferredDocument ? deferredDocument._type : void 0;
170
+ } = useLanguageFilterStudioContext();
247
171
  let t5;
248
- $[19] !== documentType || $[20] !== languageFilterOptions ? (t5 = typeof documentType == "string" && languageFilterOptions.documentTypes.includes(documentType), $[19] = documentType, $[20] = languageFilterOptions, $[21] = t5) : t5 = $[21];
172
+ $[19] !== documentType || $[20] !== languageFilterOptions.documentTypes ? (t5 = languageFilterOptions.documentTypes.includes(documentType), $[19] = documentType, $[20] = languageFilterOptions.documentTypes, $[21] = t5) : t5 = $[21];
249
173
  const languageFilterEnabled = t5;
250
174
  let t6;
251
175
  $[22] !== languageFilterEnabled || $[23] !== languages || $[24] !== selectedLanguageIds ? (t6 = languageFilterEnabled ? languages.filter((language) => selectedLanguageIds.includes(language.id)) : languages, $[22] = languageFilterEnabled, $[23] = languages, $[24] = selectedLanguageIds, $[25] = t6) : t6 = $[25];
252
176
  const filteredLanguages = t6;
253
177
  let t7;
254
- $[26] !== internationalizedArray2.buttonLocations ? (t7 = internationalizedArray2.buttonLocations.includes("document"), $[26] = internationalizedArray2.buttonLocations, $[27] = t7) : t7 = $[27];
255
- const showDocumentButtons = t7;
256
- let t8;
257
- $[28] !== filteredLanguages || $[29] !== internationalizedArray2 || $[30] !== languages ? (t8 = {
178
+ $[26] !== filteredLanguages || $[27] !== internationalizedArray2 || $[28] !== languages ? (t7 = {
258
179
  ...internationalizedArray2,
259
180
  languages,
260
181
  filteredLanguages
261
- }, $[28] = filteredLanguages, $[29] = internationalizedArray2, $[30] = languages, $[31] = t8) : t8 = $[31];
262
- const context = t8;
263
- let t9;
264
- $[32] !== props || $[33] !== showDocumentButtons ? (t9 = showDocumentButtons ? /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
265
- /* @__PURE__ */ jsx(DocumentAddButtons, { value: props.value }),
266
- props.renderDefault(props)
267
- ] }) : props.renderDefault(props), $[32] = props, $[33] = showDocumentButtons, $[34] = t9) : t9 = $[34];
268
- let t10;
269
- return $[35] !== context || $[36] !== t9 ? (t10 = /* @__PURE__ */ jsx(InternationalizedArrayContext.Provider, { value: context, children: t9 }), $[35] = context, $[36] = t9, $[37] = t10) : t10 = $[37], t10;
182
+ }, $[26] = filteredLanguages, $[27] = internationalizedArray2, $[28] = languages, $[29] = t7) : t7 = $[29];
183
+ const context = t7;
184
+ let t8;
185
+ return $[30] !== context || $[31] !== props.children ? (t8 = /* @__PURE__ */ jsx(InternationalizedArrayContext.Provider, { value: context, children: props.children }), $[30] = context, $[31] = props.children, $[32] = t8) : t8 = $[32], t8;
270
186
  }
271
- const getLanguageId = (fieldParent) => {
272
- try {
273
- return typeof fieldParent == "object" && fieldParent !== null && // Checks if it's an internationalized array item
274
- "_type" in fieldParent && typeof fieldParent._type == "string" && fieldParent._type.startsWith("internationalizedArray") && // Checks if the language field name is in the field and if it's a string
275
- LANGUAGE_FIELD_NAME in fieldParent && typeof fieldParent[LANGUAGE_FIELD_NAME] == "string" ? fieldParent[LANGUAGE_FIELD_NAME] : void 0;
276
- } catch (error) {
277
- console.error("Error getting language id", error);
278
- return;
279
- }
280
- };
281
- function InternationalizedField(props) {
282
- const $ = c(11), {
283
- languages
187
+ function AddButtons(props) {
188
+ const $ = c(15), {
189
+ readOnly,
190
+ languagesInUse,
191
+ handleClick
192
+ } = props, {
193
+ languageDisplay,
194
+ filteredLanguages: languages
284
195
  } = useInternationalizedArrayContext();
196
+ if (!languages.length)
197
+ return null;
198
+ const t0 = Math.min(languages.length, MAX_COLUMNS[languageDisplay]);
199
+ let t1;
200
+ if ($[0] !== handleClick || $[1] !== languageDisplay || $[2] !== languages || $[3] !== languagesInUse || $[4] !== readOnly) {
201
+ let t22;
202
+ $[6] !== handleClick || $[7] !== languageDisplay || $[8] !== languages.length || $[9] !== languagesInUse || $[10] !== readOnly ? (t22 = (language) => {
203
+ const languageTitle = getLanguageDisplay(languageDisplay, language.title, language.id);
204
+ return /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", fontSize: 1, "data-testid": `add-${language.id}`, disabled: readOnly || languagesInUse.includes(language.id), text: languageTitle, icon: languages.length > MAX_COLUMNS[languageDisplay] && languageDisplay === "codeOnly" ? void 0 : AddIcon, value: language.id, onClick: () => handleClick(language.id) }, language.id);
205
+ }, $[6] = handleClick, $[7] = languageDisplay, $[8] = languages.length, $[9] = languagesInUse, $[10] = readOnly, $[11] = t22) : t22 = $[11], t1 = languages.map(t22), $[0] = handleClick, $[1] = languageDisplay, $[2] = languages, $[3] = languagesInUse, $[4] = readOnly, $[5] = t1;
206
+ } else
207
+ t1 = $[5];
208
+ let t2;
209
+ return $[12] !== t0 || $[13] !== t1 ? (t2 = /* @__PURE__ */ jsx(Grid, { columns: t0, gap: 2, "data-testid": "add-buttons-grid", children: t1 }), $[12] = t0, $[13] = t1, $[14] = t2) : t2 = $[14], t2;
210
+ }
211
+ function DocumentAddButtons() {
212
+ const $ = c(12), getFormValue = useGetFormValue(), {
213
+ filteredLanguages
214
+ } = useInternationalizedArrayContext(), toast = useToast(), {
215
+ onChange
216
+ } = useDocumentPane(), schema = useSchema();
285
217
  let t0;
286
- $[0] !== props.path ? (t0 = props.path.slice(0, -1), $[0] = props.path, $[1] = t0) : t0 = $[1];
287
- const fieldParent = useFormValue(t0), languageId = getLanguageId(fieldParent), hasValidLanguageId = languageId ? languages.some((l) => l.id === languageId) : !1, t1 = props.title?.toLowerCase() === "value" && hasValidLanguageId ? "" : props.title;
218
+ $[0] !== schema ? (t0 = (typeName) => {
219
+ if (!typeName)
220
+ return;
221
+ const match = typeName.match(/^internationalizedArray(.+)Value$/);
222
+ if (!match || !match[1])
223
+ return;
224
+ const baseTypeName = match[1].charAt(0).toLowerCase() + match[1].slice(1), arrayBasedTypes = /* @__PURE__ */ new Set(["body", "htmlContent", "blockContent", "portableText"]);
225
+ if (arrayBasedTypes.has(baseTypeName))
226
+ return [];
227
+ const schemaType = schema.get(typeName);
228
+ if (schemaType && "fields" in schemaType) {
229
+ const valueField = schemaType.fields.find(_temp$2);
230
+ if (valueField) {
231
+ const fieldType = valueField.type;
232
+ if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || fieldType?.name && arrayBasedTypes.has(fieldType.name))
233
+ return [];
234
+ }
235
+ }
236
+ }, $[0] = schema, $[1] = t0) : t0 = $[1];
237
+ const getInitialValueForType = t0;
238
+ let t1;
239
+ $[2] !== filteredLanguages || $[3] !== getFormValue || $[4] !== getInitialValueForType || $[5] !== onChange || $[6] !== toast ? (t1 = async (languageId) => {
240
+ const value = getFormValue([]);
241
+ if (!isSanityDocument(value)) {
242
+ toast.push({
243
+ status: "error",
244
+ title: "No document value found"
245
+ });
246
+ return;
247
+ }
248
+ const documentsToTranslation = getDocumentsToTranslate(value, []), alreadyTranslated = documentsToTranslation.filter((translation) => translation?.[LANGUAGE_FIELD_NAME] === languageId), removeDuplicates = documentsToTranslation.reduce((filteredTranslations, translation_0) => (alreadyTranslated.filter((alreadyTranslation) => alreadyTranslation.pathString === translation_0.pathString).length > 0 || filteredTranslations.filter((filteredTranslation) => filteredTranslation.path === translation_0.path).length > 0 || filteredTranslations.push(translation_0), filteredTranslations), []);
249
+ if (removeDuplicates.length === 0) {
250
+ const language = filteredLanguages.find((l) => l.id === languageId);
251
+ toast.push({
252
+ status: "warning",
253
+ title: `No missing translations for ${language?.title || languageId} found.`
254
+ });
255
+ return;
256
+ }
257
+ const patches = [];
258
+ for (const toTranslate of removeDuplicates) {
259
+ const path = toTranslate.path, initialValue = getInitialValueForType(toTranslate._type), ifMissing = setIfMissing([], path), insertValue = insert([{
260
+ _key: randomKey(),
261
+ [LANGUAGE_FIELD_NAME]: languageId,
262
+ _type: toTranslate._type,
263
+ value: initialValue
264
+ }], "after", [...path, -1]);
265
+ patches.push(ifMissing), patches.push(insertValue);
266
+ }
267
+ onChange(PatchEvent.from(patches.flat()));
268
+ }, $[2] = filteredLanguages, $[3] = getFormValue, $[4] = getInitialValueForType, $[5] = onChange, $[6] = toast, $[7] = t1) : t1 = $[7];
269
+ const handleDocumentButtonClick = t1;
288
270
  let t2;
289
- $[2] !== props || $[3] !== t1 ? (t2 = {
290
- ...props,
291
- title: t1
292
- }, $[2] = props, $[3] = t1, $[4] = t2) : t2 = $[4];
293
- const customProps = t2;
294
- if (!customProps.schemaType.name.startsWith("internationalizedArray")) {
295
- let t32;
296
- return $[5] !== customProps ? (t32 = customProps.renderDefault(customProps), $[5] = customProps, $[6] = t32) : t32 = $[6], t32;
271
+ $[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Add translation to internationalized fields" }) }), $[8] = t2) : t2 = $[8];
272
+ let t3;
273
+ $[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = [], $[9] = t3) : t3 = $[9];
274
+ let t4;
275
+ return $[10] !== handleDocumentButtonClick ? (t4 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
276
+ t2,
277
+ /* @__PURE__ */ jsx(AddButtons, { readOnly: !1, handleClick: handleDocumentButtonClick, languagesInUse: t3 })
278
+ ] }), $[10] = handleDocumentButtonClick, $[11] = t4) : t4 = $[11], t4;
279
+ }
280
+ function _temp$2(f) {
281
+ return f.name === "value";
282
+ }
283
+ function InternationalizedArrayFormInput(props) {
284
+ const $ = c(7);
285
+ if (props.pluginConfig?.buttonLocations?.includes("document")) {
286
+ let t02;
287
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(DocumentAddButtons, {}), $[0] = t02) : t02 = $[0];
288
+ let t1;
289
+ $[1] !== props ? (t1 = props.renderDefault(props), $[1] = props, $[2] = t1) : t1 = $[2];
290
+ let t2;
291
+ return $[3] !== t1 ? (t2 = /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
292
+ t02,
293
+ t1
294
+ ] }), $[3] = t1, $[4] = t2) : t2 = $[4], t2;
295
+ }
296
+ let t0;
297
+ return $[5] !== props ? (t0 = props.renderDefault(props), $[5] = props, $[6] = t0) : t0 = $[6], t0;
298
+ }
299
+ function hasInternationalizedArrayField(schemaType) {
300
+ return isDocumentSchemaType(schemaType) ? hasInternationalizedArrayInFields(schemaType.fields) : !1;
301
+ }
302
+ function hasInternationalizedArrayInFields(fields) {
303
+ for (const field of fields) {
304
+ if (field.type.name.startsWith("internationalizedArray") || field.type.jsonType === "object" && hasInternationalizedArrayInFields(field.type.fields))
305
+ return !0;
306
+ if (field.type.jsonType === "array" && field.type.of.length > 0) {
307
+ for (const item of field.type.of)
308
+ if ("name" in item && typeof item.name == "string" && item.name.startsWith("internationalizedArray") || "fields" in item && Array.isArray(item.fields) && hasInternationalizedArrayInFields(item.fields))
309
+ return !0;
310
+ }
297
311
  }
298
- if (customProps.schemaType.name === "reference" && customProps.value) {
299
- let t32;
300
- return $[7] !== customProps ? (t32 = customProps.renderDefault({
301
- ...customProps,
302
- title: "",
303
- level: 0
304
- }), $[7] = customProps, $[8] = t32) : t32 = $[8], t32;
312
+ return !1;
313
+ }
314
+ function InternationalizedArrayLayout(props) {
315
+ const $ = c(10), schemaType = useSchema().get(props.documentType);
316
+ if (!schemaType) {
317
+ console.error(`Schema type not found: ${props.documentType}`);
318
+ let t02;
319
+ return $[0] !== props ? (t02 = props.renderDefault(props), $[0] = props, $[1] = t02) : t02 = $[1], t02;
305
320
  }
306
- if (customProps.schemaType.name === "string" || customProps.schemaType.name === "number" || customProps.schemaType.name === "text")
307
- return customProps.children;
308
- let t3;
309
- return $[9] !== customProps ? (t3 = customProps.renderDefault({
310
- ...customProps,
311
- level: 0
312
- }), $[9] = customProps, $[10] = t3) : t3 = $[10], t3;
321
+ if (hasInternationalizedArrayField(schemaType) && props.pluginConfig.includeForDocumentType(props.documentType)) {
322
+ const t02 = props.pluginConfig, t1 = props.documentType;
323
+ let t2;
324
+ $[2] !== props ? (t2 = props.renderDefault(props), $[2] = props, $[3] = t2) : t2 = $[3];
325
+ let t3;
326
+ return $[4] !== props.documentType || $[5] !== props.pluginConfig || $[6] !== t2 ? (t3 = /* @__PURE__ */ jsx(InternationalizedArrayProvider, { internationalizedArray: t02, documentType: t1, children: t2 }), $[4] = props.documentType, $[5] = props.pluginConfig, $[6] = t2, $[7] = t3) : t3 = $[7], t3;
327
+ }
328
+ let t0;
329
+ return $[8] !== props ? (t0 = props.renderDefault(props), $[8] = props, $[9] = t0) : t0 = $[9], t0;
313
330
  }
314
331
  function Preload(props) {
315
332
  const $ = c(2);
@@ -451,7 +468,13 @@ function pascalCase(string) {
451
468
  function createFieldName(name, addValue = !1) {
452
469
  return addValue ? ["internationalizedArray", pascalCase(name), "Value"].join("") : ["internationalizedArray", pascalCase(name)].join("");
453
470
  }
454
- const schemaExample = {
471
+ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLanguageIds, parentValue, languages) => {
472
+ if (isInternationalizedArrayItemType(enclosingType.name)) {
473
+ const language = typeof parentValue?.[LANGUAGE_FIELD_NAME] == "string" ? parentValue?.[LANGUAGE_FIELD_NAME] : typeof parentValue?._key == "string" ? parentValue?._key : null;
474
+ return !language || languages.find((l) => l.id === language) ? language ? selectedLanguageIds.includes(language) : !1 : !0;
475
+ }
476
+ return !0;
477
+ }, schemaExample = {
455
478
  languages: [{
456
479
  id: "en",
457
480
  title: "English"
@@ -484,82 +507,52 @@ function Feedback() {
484
507
  ] }) }), $[3] = t3) : t3 = $[3], t3;
485
508
  }
486
509
  function MigrationBanner(t0) {
487
- const $ = c(27), {
488
- value,
489
- languages,
490
- onChange,
491
- readOnly: t1
492
- } = t0, readOnly = t1 === void 0 ? !1 : t1, toast = useToast();
493
- let t2;
494
- bb0: {
495
- if (!value?.length || !languages?.length) {
496
- let t33;
497
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t33 = [], $[0] = t33) : t33 = $[0], t2 = t33;
498
- break bb0;
499
- }
500
- let t32;
501
- $[1] !== languages ? (t32 = new Set(languages.map(_temp$2)), $[1] = languages, $[2] = t32) : t32 = $[2];
502
- const languageIds = t32;
503
- let t42;
504
- if ($[3] !== languageIds || $[4] !== value) {
505
- let t52;
506
- $[6] !== languageIds ? (t52 = (item) => item._key && languageIds.has(item._key) && !item[LANGUAGE_FIELD_NAME], $[6] = languageIds, $[7] = t52) : t52 = $[7], t42 = value.filter(t52), $[3] = languageIds, $[4] = value, $[5] = t42;
507
- } else
508
- t42 = $[5];
509
- t2 = t42;
510
- }
511
- const itemsNeedingMigration = t2, needsMigration = itemsNeedingMigration.length > 0;
512
- let t3;
513
- $[8] !== itemsNeedingMigration.length || $[9] !== languages || $[10] !== needsMigration || $[11] !== onChange || $[12] !== toast || $[13] !== value ? (t3 = () => {
514
- if (!value?.length || !needsMigration)
515
- return;
516
- const languageIds_0 = new Set(languages.map(_temp2$2)), updatedValue = value.map((item_0) => item_0._key && languageIds_0.has(item_0._key) && !item_0[LANGUAGE_FIELD_NAME] ? {
517
- ...item_0,
518
- _key: randomKey(),
519
- [LANGUAGE_FIELD_NAME]: item_0._key
520
- } : item_0);
521
- onChange([set(updatedValue)]), toast.push({
522
- title: `Updated ${itemsNeedingMigration.length} item${itemsNeedingMigration.length === 1 ? "" : "s"} to new format`,
523
- status: "success"
524
- });
525
- }, $[8] = itemsNeedingMigration.length, $[9] = languages, $[10] = needsMigration, $[11] = onChange, $[12] = toast, $[13] = value, $[14] = t3) : t3 = $[14];
526
- const handleMigrateLanguages = t3;
527
- if (!needsMigration)
510
+ const $ = c(11), {
511
+ itemsNeedingMigration
512
+ } = t0;
513
+ if (!itemsNeedingMigration.length)
528
514
  return null;
529
- let t4;
530
- $[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }), $[15] = t4) : t4 = $[15];
515
+ let t1;
516
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }), $[0] = t1) : t1 = $[0];
517
+ let t2;
518
+ $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Data migration required" }), $[1] = t2) : t2 = $[1];
519
+ const t3 = itemsNeedingMigration.length === 1 ? "" : "s", t4 = itemsNeedingMigration.length === 1 ? "needs" : "need";
531
520
  let t5;
532
- $[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Data format update required" }), $[16] = t5) : t5 = $[16];
533
- const t6 = itemsNeedingMigration.length === 1 ? "" : "s", t7 = itemsNeedingMigration.length === 1 ? "s" : "";
521
+ $[2] !== itemsNeedingMigration.length || $[3] !== t3 || $[4] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
522
+ itemsNeedingMigration.length,
523
+ " item",
524
+ t3,
525
+ " ",
526
+ t4,
527
+ " to be migrated to the v5 format."
528
+ ] }), $[2] = itemsNeedingMigration.length, $[3] = t3, $[4] = t4, $[5] = t5) : t5 = $[5];
529
+ let t6;
530
+ $[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx("code", { children: "_key" }), $[6] = t6) : t6 = $[6];
531
+ let t7;
532
+ $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = /* @__PURE__ */ jsx("code", { children: "language" }), $[7] = t7) : t7 = $[7];
534
533
  let t8;
535
- $[17] !== itemsNeedingMigration.length || $[18] !== t6 || $[19] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Stack, { space: 2, flex: 1, children: [
536
- t5,
537
- /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
538
- itemsNeedingMigration.length,
539
- " item",
540
- t6,
541
- " need",
542
- t7,
543
- " to be updated to the new format."
544
- ] })
545
- ] }), $[17] = itemsNeedingMigration.length, $[18] = t6, $[19] = t7, $[20] = t8) : t8 = $[20];
534
+ $[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
535
+ "This field still uses the v4 format where language is stored in ",
536
+ t6,
537
+ ". Migrate to the v5 format where language is stored in ",
538
+ t7,
539
+ ".",
540
+ " ",
541
+ /* @__PURE__ */ jsx("a", { rel: "noopener noreferrer", target: "_blank", href: "https://github.com/sanity-io/plugins/blob/main/plugins/sanity-plugin-internationalized-array/README.md#migrate-from-v4-to-v5", children: "Learn more" }),
542
+ "."
543
+ ] }) }), $[8] = t8) : t8 = $[8];
546
544
  let t9;
547
- $[21] !== handleMigrateLanguages || $[22] !== readOnly ? (t9 = /* @__PURE__ */ jsx(Button, { tone: "caution", mode: "ghost", text: "Update Languages", onClick: handleMigrateLanguages, disabled: readOnly }), $[21] = handleMigrateLanguages, $[22] = readOnly, $[23] = t9) : t9 = $[23];
548
- let t10;
549
- return $[24] !== t8 || $[25] !== t9 ? (t10 = /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, radius: 2, border: !0, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
550
- t4,
551
- t8,
552
- t9
553
- ] }) }), $[24] = t8, $[25] = t9, $[26] = t10) : t10 = $[26], t10;
554
- }
555
- function _temp2$2(l_0) {
556
- return l_0.id;
557
- }
558
- function _temp$2(l) {
559
- return l.id;
545
+ return $[9] !== t5 ? (t9 = /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, radius: 2, border: !0, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
546
+ t1,
547
+ /* @__PURE__ */ jsxs(Stack, { space: 2, flex: 1, children: [
548
+ t2,
549
+ t5,
550
+ t8
551
+ ] })
552
+ ] }) }), $[9] = t5, $[10] = t9) : t9 = $[10], t9;
560
553
  }
561
554
  function InternationalizedArray(props) {
562
- const $ = c(105), {
555
+ const $ = c(102), {
563
556
  members,
564
557
  value: _value,
565
558
  schemaType,
@@ -568,12 +561,13 @@ function InternationalizedArray(props) {
568
561
  } = props, value = _value;
569
562
  let t0;
570
563
  $[0] !== value ? (t0 = value?.filter(_temp$1) ?? [], $[0] = value, $[1] = t0) : t0 = $[1];
571
- const itemsNeedingMigration = t0.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), {
564
+ const itemsNeedingMigration = t0, shouldMigrateArray = itemsNeedingMigration.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), getFormValue = useGetFormValue(), {
572
565
  languages,
573
566
  filteredLanguages,
574
567
  defaultLanguages,
575
568
  buttonAddAll,
576
- buttonLocations
569
+ buttonLocations,
570
+ languageFilter: builtInLanguageFilter
577
571
  } = useInternationalizedArrayContext(), {
578
572
  selectedLanguageIds,
579
573
  options: languageFilterOptions
@@ -583,17 +577,21 @@ function InternationalizedArray(props) {
583
577
  const documentType = useFormValue(t1);
584
578
  let t2;
585
579
  $[3] !== documentType || $[4] !== languageFilterOptions ? (t2 = typeof documentType == "string" && languageFilterOptions.documentTypes.includes(documentType), $[3] = documentType, $[4] = languageFilterOptions, $[5] = t2) : t2 = $[5];
586
- const languageFilterEnabled = t2;
580
+ const usingLanguageFilterPlugin = t2;
587
581
  let t3;
588
- $[6] !== languageFilterEnabled || $[7] !== languageFilterOptions || $[8] !== members || $[9] !== selectedLanguageIds || $[10] !== value ? (t3 = languageFilterEnabled ? members.filter((member) => {
582
+ $[6] !== builtInLanguageFilter || $[7] !== documentType ? (t3 = typeof documentType == "string" && builtInLanguageFilter.documentTypes.includes(documentType), $[6] = builtInLanguageFilter, $[7] = documentType, $[8] = t3) : t3 = $[8];
583
+ const usingBuiltInLanguageFilter = t3;
584
+ let t4;
585
+ $[9] !== languageFilterOptions || $[10] !== languages || $[11] !== members || $[12] !== selectedLanguageIds || $[13] !== usingBuiltInLanguageFilter || $[14] !== usingLanguageFilterPlugin ? (t4 = usingLanguageFilterPlugin || usingBuiltInLanguageFilter ? members.filter((member) => {
589
586
  if (member.kind !== "item")
590
587
  return !1;
591
588
  const valueMember = member.item.members[0];
592
- return !valueMember || valueMember.kind !== "field" ? !1 : languageFilterOptions.filterField(member.item.schemaType, valueMember, selectedLanguageIds, value[member.index]);
593
- }) : members, $[6] = languageFilterEnabled, $[7] = languageFilterOptions, $[8] = members, $[9] = selectedLanguageIds, $[10] = value, $[11] = t3) : t3 = $[11];
594
- const filteredMembers = t3;
595
- let t4;
596
- $[12] !== filteredLanguages || $[13] !== languages || $[14] !== onChange || $[15] !== schemaType.name || $[16] !== value ? (t4 = (addLanguageKeys) => {
589
+ return !valueMember || valueMember.kind !== "field" ? !1 : usingBuiltInLanguageFilter ? internationalizedArrayLanguageFilter(member.item.schemaType, valueMember, selectedLanguageIds, member.item.value, languages) : languageFilterOptions.filterField(member.item.schemaType, valueMember, selectedLanguageIds, member.item.value);
590
+ }) : members, $[9] = languageFilterOptions, $[10] = languages, $[11] = members, $[12] = selectedLanguageIds, $[13] = usingBuiltInLanguageFilter, $[14] = usingLanguageFilterPlugin, $[15] = t4) : t4 = $[15];
591
+ const filteredMembers = t4;
592
+ let t5;
593
+ $[16] !== filteredLanguages || $[17] !== getFormValue || $[18] !== languages || $[19] !== onChange || $[20] !== props.path || $[21] !== schemaType.name ? (t5 = (addLanguageKeys) => {
594
+ const formValue = getFormValue(props.path);
597
595
  if (!filteredLanguages?.length)
598
596
  return;
599
597
  const patches = createAddLanguagePatches({
@@ -601,139 +599,144 @@ function InternationalizedArray(props) {
601
599
  schemaTypeName: schemaType.name,
602
600
  languages,
603
601
  filteredLanguages,
604
- value
602
+ value: formValue
605
603
  });
606
604
  onChange([setIfMissing([]), ...patches]);
607
- }, $[12] = filteredLanguages, $[13] = languages, $[14] = onChange, $[15] = schemaType.name, $[16] = value, $[17] = t4) : t4 = $[17];
608
- const handleAddLanguage = t4, {
605
+ }, $[16] = filteredLanguages, $[17] = getFormValue, $[18] = languages, $[19] = onChange, $[20] = props.path, $[21] = schemaType.name, $[22] = t5) : t5 = $[22];
606
+ const handleAddLanguages = t5, {
609
607
  isDeleting
610
608
  } = useDocumentPane();
611
- let t5;
612
- bb0: {
613
- if (!value?.length) {
614
- let t63;
615
- $[18] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t63 = [], $[18] = t63) : t63 = $[18], t5 = t63;
616
- break bb0;
617
- }
618
- let t62;
619
- $[19] !== languages ? (t62 = new Set(languages.map(_temp2$1)), $[19] = languages, $[20] = t62) : t62 = $[20];
620
- const languageIds = t62;
621
- let t72;
622
- if ($[21] !== languageIds || $[22] !== value) {
623
- let t82;
624
- $[24] !== languageIds ? (t82 = (v_0) => v_0[LANGUAGE_FIELD_NAME] || (v_0._key && languageIds.has(v_0._key) ? v_0._key : null), $[24] = languageIds, $[25] = t82) : t82 = $[25], t72 = value.map(t82).filter(_temp3$1), $[21] = languageIds, $[22] = value, $[23] = t72;
625
- } else
626
- t72 = $[23];
627
- t5 = t72;
628
- }
629
- const addedLanguages = t5;
630
609
  let t6;
631
- if ($[26] !== addedLanguages || $[27] !== defaultLanguages || $[28] !== languages) {
632
- let t72;
633
- $[30] !== languages ? (t72 = (language_2) => languages.find((l) => l.id === language_2), $[30] = languages, $[31] = t72) : t72 = $[31];
634
- let t82;
635
- $[32] !== addedLanguages ? (t82 = (language_3) => addedLanguages.includes(language_3), $[32] = addedLanguages, $[33] = t82) : t82 = $[33], t6 = defaultLanguages.filter(t72).every(t82), $[26] = addedLanguages, $[27] = defaultLanguages, $[28] = languages, $[29] = t6;
610
+ $[23] !== value ? (t6 = value?.map(_temp2$1).filter(Boolean).join(","), $[23] = value, $[24] = t6) : t6 = $[24];
611
+ const languageKeysFromValue = t6;
612
+ let t7;
613
+ if ($[25] !== languageKeysFromValue || $[26] !== languages) {
614
+ bb0: {
615
+ const languageKeys = languageKeysFromValue?.split(",") || [];
616
+ if (!languageKeys?.length) {
617
+ let t82;
618
+ $[28] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t82 = [], $[28] = t82) : t82 = $[28], t7 = t82;
619
+ break bb0;
620
+ }
621
+ if (!languages?.length) {
622
+ let t82;
623
+ $[29] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t82 = [], $[29] = t82) : t82 = $[29], t7 = t82;
624
+ break bb0;
625
+ }
626
+ t7 = languages.filter((l) => languageKeys?.find((key) => key === l.id)).map(_temp3$1);
627
+ }
628
+ $[25] = languageKeysFromValue, $[26] = languages, $[27] = t7;
636
629
  } else
637
- t6 = $[29];
638
- const hasAddedDefaultLanguages = t6;
639
- let t7, t8;
640
- $[34] !== addedLanguages || $[35] !== defaultLanguages || $[36] !== documentReadOnly || $[37] !== handleAddLanguage || $[38] !== hasAddedDefaultLanguages || $[39] !== isDeleting || $[40] !== itemsNeedingMigration || $[41] !== languages ? (t7 = () => {
641
- if (!isDeleting && !hasAddedDefaultLanguages && !itemsNeedingMigration) {
642
- const languagesToAdd = defaultLanguages.filter((language_4) => !addedLanguages.includes(language_4)).filter((language_5) => languages.find((l_0) => l_0.id === language_5)), timeout = setTimeout(() => {
643
- documentReadOnly || handleAddLanguage(languagesToAdd);
630
+ t7 = $[27];
631
+ const addedLanguages = t7;
632
+ let t8, t9;
633
+ $[30] !== addedLanguages || $[31] !== defaultLanguages || $[32] !== documentReadOnly || $[33] !== handleAddLanguages || $[34] !== isDeleting || $[35] !== languages || $[36] !== shouldMigrateArray ? (t8 = () => {
634
+ const hasAddedDefaultLanguages = defaultLanguages.filter((language) => languages.find((l_1) => l_1.id === language)).every((language_0) => addedLanguages.includes(language_0));
635
+ if (!isDeleting && !hasAddedDefaultLanguages && !shouldMigrateArray) {
636
+ const languagesToAdd = defaultLanguages.filter((language_1) => !addedLanguages.includes(language_1)).filter((language_2) => languages.find((l_2) => l_2.id === language_2)), timeout = setTimeout(() => {
637
+ documentReadOnly || handleAddLanguages(languagesToAdd);
644
638
  });
645
639
  return () => clearTimeout(timeout);
646
640
  }
647
- }, t8 = [isDeleting, hasAddedDefaultLanguages, handleAddLanguage, defaultLanguages, addedLanguages, languages, documentReadOnly, itemsNeedingMigration], $[34] = addedLanguages, $[35] = defaultLanguages, $[36] = documentReadOnly, $[37] = handleAddLanguage, $[38] = hasAddedDefaultLanguages, $[39] = isDeleting, $[40] = itemsNeedingMigration, $[41] = languages, $[42] = t7, $[43] = t8) : (t7 = $[42], t8 = $[43]), useEffect(t7, t8);
648
- let t9;
649
- $[44] !== languages || $[45] !== onChange || $[46] !== toast || $[47] !== value ? (t9 = () => {
641
+ }, t9 = [isDeleting, handleAddLanguages, defaultLanguages, addedLanguages, languages, documentReadOnly, shouldMigrateArray], $[30] = addedLanguages, $[31] = defaultLanguages, $[32] = documentReadOnly, $[33] = handleAddLanguages, $[34] = isDeleting, $[35] = languages, $[36] = shouldMigrateArray, $[37] = t8, $[38] = t9) : (t8 = $[37], t9 = $[38]), useEffect(t8, t9);
642
+ let t10;
643
+ $[39] !== languages || $[40] !== onChange || $[41] !== toast || $[42] !== value ? (t10 = () => {
650
644
  if (!value?.length || !languages?.length)
651
645
  return;
652
646
  const updatedValue = value.reduce((acc, v_1) => {
653
- const newIndex = languages.findIndex((l_1) => l_1.id === v_1?.[LANGUAGE_FIELD_NAME]);
647
+ const newIndex = languages.findIndex((l_3) => l_3.id === v_1?.[LANGUAGE_FIELD_NAME]);
654
648
  return newIndex > -1 && (acc[newIndex] = v_1), acc;
655
649
  }, []).filter(Boolean);
656
650
  value?.length !== updatedValue.length && toast.push({
657
651
  title: "There was an error reordering languages",
658
652
  status: "warning"
659
653
  }), onChange(set(updatedValue));
660
- }, $[44] = languages, $[45] = onChange, $[46] = toast, $[47] = value, $[48] = t9) : t9 = $[48];
661
- const handleRestoreOrder = t9;
662
- let t10;
654
+ }, $[39] = languages, $[40] = onChange, $[41] = toast, $[42] = value, $[43] = t10) : t10 = $[43];
655
+ const handleRestoreOrder = t10;
656
+ let t11;
663
657
  bb1: {
664
658
  if (!value?.length || !languages?.length) {
665
- t10 = !0;
659
+ t11 = !0;
666
660
  break bb1;
667
661
  }
668
- let t112;
669
- $[49] !== languages || $[50] !== value ? (t112 = value?.every((v_2) => languages.find((l_2) => l_2?.id === v_2?.[LANGUAGE_FIELD_NAME])), $[49] = languages, $[50] = value, $[51] = t112) : t112 = $[51], t10 = t112;
662
+ let t122;
663
+ $[44] !== languages || $[45] !== value ? (t122 = value?.every((v_2) => languages.find((l_4) => l_4?.id === v_2?.[LANGUAGE_FIELD_NAME])), $[44] = languages, $[45] = value, $[46] = t122) : t122 = $[46], t11 = t122;
670
664
  }
671
- const allKeysAreLanguages = t10;
672
- let t11;
673
- $[52] !== languages || $[53] !== value ? (t11 = languages && languages.length > 1 ? languages.filter((l_3) => value?.find((v_3) => v_3[LANGUAGE_FIELD_NAME] === l_3.id)) : [], $[52] = languages, $[53] = value, $[54] = t11) : t11 = $[54];
674
- const languagesInUse = t11;
665
+ const allKeysAreLanguages = t11;
675
666
  let t12;
676
667
  bb2: {
677
- if (!value?.length || !languagesInUse.length) {
668
+ if (!value?.length || !addedLanguages.length) {
678
669
  let t133;
679
- $[55] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t133 = [], $[55] = t133) : t133 = $[55], t12 = t133;
670
+ $[47] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t133 = [], $[47] = t133) : t133 = $[47], t12 = t133;
680
671
  break bb2;
681
672
  }
682
673
  let t132;
683
- if ($[56] !== languagesInUse || $[57] !== value) {
674
+ if ($[48] !== addedLanguages || $[49] !== value) {
684
675
  let t142;
685
- $[59] !== languagesInUse ? (t142 = (v_4, vIndex) => vIndex === languagesInUse.findIndex((l_4) => l_4.id === v_4[LANGUAGE_FIELD_NAME]) ? null : v_4, $[59] = languagesInUse, $[60] = t142) : t142 = $[60], t132 = value.map(t142).filter(Boolean), $[56] = languagesInUse, $[57] = value, $[58] = t132;
676
+ $[51] !== addedLanguages ? (t142 = (v_3, vIndex) => vIndex === addedLanguages.findIndex((language_3) => language_3 === v_3[LANGUAGE_FIELD_NAME]) ? null : v_3, $[51] = addedLanguages, $[52] = t142) : t142 = $[52], t132 = value.map(t142).filter(Boolean), $[48] = addedLanguages, $[49] = value, $[50] = t132;
686
677
  } else
687
- t132 = $[58];
678
+ t132 = $[50];
688
679
  t12 = t132;
689
680
  }
690
681
  const languagesOutOfOrder = t12, languagesAreValid = !languages?.length || languages?.length && languages.every(_temp4$1);
691
682
  let t13;
692
- $[61] !== allKeysAreLanguages || $[62] !== documentReadOnly || $[63] !== handleRestoreOrder || $[64] !== languagesOutOfOrder.length ? (t13 = () => {
683
+ $[53] !== allKeysAreLanguages || $[54] !== documentReadOnly || $[55] !== handleRestoreOrder || $[56] !== languagesOutOfOrder.length ? (t13 = () => {
693
684
  languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
694
- }, $[61] = allKeysAreLanguages, $[62] = documentReadOnly, $[63] = handleRestoreOrder, $[64] = languagesOutOfOrder.length, $[65] = t13) : t13 = $[65];
685
+ }, $[53] = allKeysAreLanguages, $[54] = documentReadOnly, $[55] = handleRestoreOrder, $[56] = languagesOutOfOrder.length, $[57] = t13) : t13 = $[57];
695
686
  let t14;
696
- $[66] !== allKeysAreLanguages || $[67] !== documentReadOnly || $[68] !== handleRestoreOrder || $[69] !== languagesOutOfOrder ? (t14 = [languagesOutOfOrder, allKeysAreLanguages, handleRestoreOrder, documentReadOnly], $[66] = allKeysAreLanguages, $[67] = documentReadOnly, $[68] = handleRestoreOrder, $[69] = languagesOutOfOrder, $[70] = t14) : t14 = $[70], useEffect(t13, t14);
687
+ $[58] !== allKeysAreLanguages || $[59] !== documentReadOnly || $[60] !== handleRestoreOrder || $[61] !== languagesOutOfOrder ? (t14 = [languagesOutOfOrder, allKeysAreLanguages, handleRestoreOrder, documentReadOnly], $[58] = allKeysAreLanguages, $[59] = documentReadOnly, $[60] = handleRestoreOrder, $[61] = languagesOutOfOrder, $[62] = t14) : t14 = $[62], useEffect(t13, t14);
697
688
  let t15;
698
- $[71] !== filteredLanguages || $[72] !== value ? (t15 = checkAllLanguagesArePresent(filteredLanguages, value), $[71] = filteredLanguages, $[72] = value, $[73] = t15) : t15 = $[73];
689
+ $[63] !== filteredLanguages || $[64] !== value ? (t15 = checkAllLanguagesArePresent(filteredLanguages, value), $[63] = filteredLanguages, $[64] = value, $[65] = t15) : t15 = $[65];
699
690
  const allLanguagesArePresent = t15;
691
+ let t16;
692
+ $[66] !== filteredLanguages || $[67] !== handleAddLanguages ? (t16 = () => {
693
+ handleAddLanguages(filteredLanguages.map(_temp5));
694
+ }, $[66] = filteredLanguages, $[67] = handleAddLanguages, $[68] = t16) : t16 = $[68];
695
+ const addAllMissingLanguages = t16;
700
696
  if (!languagesAreValid) {
701
- let t162;
702
- return $[74] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t162 = /* @__PURE__ */ jsx(Feedback, {}), $[74] = t162) : t162 = $[74], t162;
697
+ let t172;
698
+ return $[69] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t172 = /* @__PURE__ */ jsx(Feedback, {}), $[69] = t172) : t172 = $[69], t172;
703
699
  }
704
- let t16;
705
- $[75] !== allLanguagesArePresent || $[76] !== buttonLocations || $[77] !== filteredLanguages?.length || $[78] !== itemsNeedingMigration ? (t16 = !itemsNeedingMigration && buttonLocations.includes("field") && filteredLanguages?.length > 0 && !allLanguagesArePresent, $[75] = allLanguagesArePresent, $[76] = buttonLocations, $[77] = filteredLanguages?.length, $[78] = itemsNeedingMigration, $[79] = t16) : t16 = $[79];
706
- const addButtonsAreVisible = t16, fieldHasMembers = members?.length > 0;
707
700
  let t17;
708
- $[80] !== languages || $[81] !== onChange || $[82] !== readOnly || $[83] !== value ? (t17 = /* @__PURE__ */ jsx(MigrationBanner, { value, languages, onChange, readOnly }), $[80] = languages, $[81] = onChange, $[82] = readOnly, $[83] = value, $[84] = t17) : t17 = $[84];
701
+ $[70] !== allLanguagesArePresent || $[71] !== buttonLocations || $[72] !== filteredLanguages.length || $[73] !== shouldMigrateArray ? (t17 = !shouldMigrateArray && buttonLocations.includes("field") && filteredLanguages?.length > 0 && !allLanguagesArePresent, $[70] = allLanguagesArePresent, $[71] = buttonLocations, $[72] = filteredLanguages.length, $[73] = shouldMigrateArray, $[74] = t17) : t17 = $[74];
702
+ const addButtonsAreVisible = t17, fieldHasMembers = members?.length > 0;
709
703
  let t18;
710
- $[85] !== fieldHasMembers || $[86] !== filteredMembers || $[87] !== props ? (t18 = fieldHasMembers ? /* @__PURE__ */ jsx(Fragment, { children: filteredMembers.map((member_0) => member_0.kind === "item" ? /* @__PURE__ */ createElement(ArrayOfObjectsItem, { ...props, key: member_0.key, member: member_0 }) : /* @__PURE__ */ jsx(MemberItemError, { member: member_0 }, member_0.key)) }) : null, $[85] = fieldHasMembers, $[86] = filteredMembers, $[87] = props, $[88] = t18) : t18 = $[88];
704
+ $[75] !== filteredLanguages || $[76] !== value ? (t18 = createAddAllTitle(value, filteredLanguages), $[75] = filteredLanguages, $[76] = value, $[77] = t18) : t18 = $[77];
705
+ const addAllTitle = t18;
711
706
  let t19;
712
- $[89] !== addButtonsAreVisible || $[90] !== fieldHasMembers ? (t19 = !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, $[89] = addButtonsAreVisible, $[90] = fieldHasMembers, $[91] = t19) : t19 = $[91];
707
+ if ($[78] !== filteredMembers || $[79] !== props) {
708
+ let t202;
709
+ $[81] !== props ? (t202 = (member_0) => member_0.kind === "item" ? /* @__PURE__ */ createElement(ArrayOfObjectsItem, { ...props, key: member_0.key, member: member_0 }) : /* @__PURE__ */ jsx(MemberItemError, { member: member_0 }, member_0.key), $[81] = props, $[82] = t202) : t202 = $[82], t19 = filteredMembers.map(t202), $[78] = filteredMembers, $[79] = props, $[80] = t19;
710
+ } else
711
+ t19 = $[80];
713
712
  let t20;
714
- $[92] !== addButtonsAreVisible || $[93] !== allLanguagesArePresent || $[94] !== buttonAddAll || $[95] !== filteredLanguages || $[96] !== handleAddLanguage || $[97] !== readOnly || $[98] !== value ? (t20 = addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
715
- /* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, value, readOnly, handleClick: handleAddLanguage }),
716
- buttonAddAll ? /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", "data-testid": "add-all-languages", disabled: readOnly || allLanguagesArePresent, icon: AddIcon, text: createAddAllTitle(value, filteredLanguages), onClick: () => handleAddLanguage(filteredLanguages.map(_temp5)) }) : null
717
- ] }) : null, $[92] = addButtonsAreVisible, $[93] = allLanguagesArePresent, $[94] = buttonAddAll, $[95] = filteredLanguages, $[96] = handleAddLanguage, $[97] = readOnly, $[98] = value, $[99] = t20) : t20 = $[99];
713
+ $[83] !== itemsNeedingMigration ? (t20 = /* @__PURE__ */ jsx(MigrationBanner, { itemsNeedingMigration }), $[83] = itemsNeedingMigration, $[84] = t20) : t20 = $[84];
718
714
  let t21;
719
- return $[100] !== t17 || $[101] !== t18 || $[102] !== t19 || $[103] !== t20 ? (t21 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
720
- t17,
721
- t18,
715
+ $[85] !== addButtonsAreVisible || $[86] !== fieldHasMembers ? (t21 = !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, $[85] = addButtonsAreVisible, $[86] = fieldHasMembers, $[87] = t21) : t21 = $[87];
716
+ let t22;
717
+ $[88] !== addAllMissingLanguages || $[89] !== addAllTitle || $[90] !== addButtonsAreVisible || $[91] !== addedLanguages || $[92] !== allLanguagesArePresent || $[93] !== buttonAddAll || $[94] !== handleAddLanguages || $[95] !== readOnly ? (t22 = addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
718
+ /* @__PURE__ */ jsx(AddButtons, { languagesInUse: addedLanguages, readOnly, handleClick: handleAddLanguages }),
719
+ buttonAddAll ? /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", "data-testid": "add-all-languages", disabled: readOnly || allLanguagesArePresent, icon: AddIcon, text: addAllTitle, onClick: addAllMissingLanguages }) : null
720
+ ] }) : null, $[88] = addAllMissingLanguages, $[89] = addAllTitle, $[90] = addButtonsAreVisible, $[91] = addedLanguages, $[92] = allLanguagesArePresent, $[93] = buttonAddAll, $[94] = handleAddLanguages, $[95] = readOnly, $[96] = t22) : t22 = $[96];
721
+ let t23;
722
+ return $[97] !== t19 || $[98] !== t20 || $[99] !== t21 || $[100] !== t22 ? (t23 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
722
723
  t19,
723
- t20
724
- ] }), $[100] = t17, $[101] = t18, $[102] = t19, $[103] = t20, $[104] = t21) : t21 = $[104], t21;
724
+ t20,
725
+ t21,
726
+ t22
727
+ ] }), $[97] = t19, $[98] = t20, $[99] = t21, $[100] = t22, $[101] = t23) : t23 = $[101], t23;
725
728
  }
726
- function _temp5(language_6) {
727
- return language_6.id;
729
+ function _temp5(language_4) {
730
+ return language_4.id;
728
731
  }
729
732
  function _temp4$1(item) {
730
733
  return item.id && item.title;
731
734
  }
732
- function _temp3$1(language_1) {
733
- return !!language_1;
735
+ function _temp3$1(l_0) {
736
+ return l_0.id;
734
737
  }
735
- function _temp2$1(language) {
736
- return language.id;
738
+ function _temp2$1(v_0) {
739
+ return v_0[LANGUAGE_FIELD_NAME] ?? v_0._key;
737
740
  }
738
741
  function _temp$1(v) {
739
742
  return !v[LANGUAGE_FIELD_NAME];
@@ -753,6 +756,11 @@ var array = (config) => {
753
756
  title: "Internationalized array",
754
757
  type: "array",
755
758
  components: {
759
+ field: (props) => props.renderDefault({
760
+ ...props,
761
+ // Reset the level to avoid nested styling
762
+ level: 0
763
+ }),
756
764
  input: InternationalizedArray
757
765
  },
758
766
  options: {
@@ -831,72 +839,149 @@ function getToneFromValidation(validations) {
831
839
  if (validationLevels.has("warning"))
832
840
  return "caution";
833
841
  }
834
- function InternationalizedInput(props) {
835
- const $ = c(11);
842
+ function ChangeLanguageButton(props) {
843
+ const $ = c(24), {
844
+ value,
845
+ onChange,
846
+ path
847
+ } = props;
836
848
  let t0;
837
- $[0] !== props.path ? (t0 = props.path.slice(0, -1), $[0] = props.path, $[1] = t0) : t0 = $[1];
838
- const parentValue = useFormValue(t0), originalOnChange = props.inputProps.onChange;
849
+ $[0] !== path ? (t0 = path.slice(0, -1), $[0] = path, $[1] = t0) : t0 = $[1];
850
+ const parentValue = useFormValue(t0), {
851
+ languages
852
+ } = useInternationalizedArrayContext();
839
853
  let t1;
840
- $[2] !== originalOnChange || $[3] !== props.value?.value ? (t1 = (patches) => {
854
+ $[2] !== parentValue ? (t1 = parentValue?.map(_temp) ?? [], $[2] = parentValue, $[3] = t1) : t1 = $[3];
855
+ const languageKeysInUse = t1;
856
+ let t2;
857
+ $[4] !== languages || $[5] !== onChange || $[6] !== value ? (t2 = (event) => {
858
+ const languageId = event?.currentTarget?.value;
859
+ !value || !languages?.length || !languages.find((l) => l.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
860
+ }, $[4] = languages, $[5] = onChange, $[6] = value, $[7] = t2) : t2 = $[7];
861
+ const handleKeyChange = t2, t3 = `Change "${value[LANGUAGE_FIELD_NAME]}"`;
862
+ let t4;
863
+ $[8] !== t3 ? (t4 = /* @__PURE__ */ jsx(Button, { fontSize: 1, text: t3 }), $[8] = t3, $[9] = t4) : t4 = $[9];
864
+ const t5 = `${value[LANGUAGE_FIELD_NAME]}-change-key`;
865
+ let t6;
866
+ if ($[10] !== handleKeyChange || $[11] !== languageKeysInUse || $[12] !== languages) {
867
+ let t72;
868
+ $[14] !== handleKeyChange || $[15] !== languageKeysInUse ? (t72 = (lang) => /* @__PURE__ */ jsx(MenuItem, { disabled: languageKeysInUse.includes(lang.id), fontSize: 1, text: lang.id.toLocaleUpperCase(), value: lang.id, onClick: handleKeyChange }, lang.id), $[14] = handleKeyChange, $[15] = languageKeysInUse, $[16] = t72) : t72 = $[16], t6 = languages.map(t72), $[10] = handleKeyChange, $[11] = languageKeysInUse, $[12] = languages, $[13] = t6;
869
+ } else
870
+ t6 = $[13];
871
+ let t7;
872
+ $[17] !== t6 ? (t7 = /* @__PURE__ */ jsx(Menu, { children: t6 }), $[17] = t6, $[18] = t7) : t7 = $[18];
873
+ let t8;
874
+ $[19] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = {
875
+ portal: !0
876
+ }, $[19] = t8) : t8 = $[19];
877
+ let t9;
878
+ return $[20] !== t4 || $[21] !== t5 || $[22] !== t7 ? (t9 = /* @__PURE__ */ jsx(MenuButton, { button: t4, id: t5, menu: t7, popover: t8 }), $[20] = t4, $[21] = t5, $[22] = t7, $[23] = t9) : t9 = $[23], t9;
879
+ }
880
+ function _temp(v) {
881
+ return v[LANGUAGE_FIELD_NAME];
882
+ }
883
+ function RemoveButton(t0) {
884
+ const $ = c(10), {
885
+ isDefault,
886
+ readOnly,
887
+ onChange
888
+ } = t0;
889
+ let t1;
890
+ $[0] !== onChange ? (t1 = () => {
891
+ onChange(unset());
892
+ }, $[0] = onChange, $[1] = t1) : t1 = $[1];
893
+ const handleUnset = t1, t2 = !isDefault;
894
+ let t3, t4;
895
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Can't remove default language" }), t4 = ["right", "left"], $[2] = t3, $[3] = t4) : (t3 = $[2], t4 = $[3]);
896
+ const t5 = readOnly || isDefault;
897
+ let t6;
898
+ $[4] !== handleUnset || $[5] !== t5 ? (t6 = /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Button, { mode: "bleed", icon: RemoveCircleIcon, tone: "critical", disabled: t5, onClick: handleUnset }) }), $[4] = handleUnset, $[5] = t5, $[6] = t6) : t6 = $[6];
899
+ let t7;
900
+ return $[7] !== t2 || $[8] !== t6 ? (t7 = /* @__PURE__ */ jsx(Tooltip, { animate: !0, disabled: t2, content: t3, fallbackPlacements: t4, placement: "top", portal: !0, children: t6 }), $[7] = t2, $[8] = t6, $[9] = t7) : t7 = $[9], t7;
901
+ }
902
+ function InternationalizedInput(props) {
903
+ const $ = c(51), originalOnChange = props.inputProps.onChange;
904
+ let t0;
905
+ $[0] !== originalOnChange || $[1] !== props.value?.value ? (t0 = (patches) => {
841
906
  if (!Array.isArray(patches))
842
907
  return originalOnChange(patches);
843
908
  const valueField = props.value?.value;
844
- if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp)) {
909
+ if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp2)) {
845
910
  const initPatch = valueField === void 0 ? {
846
911
  type: "setIfMissing",
847
912
  path: ["value"],
848
913
  value: []
849
- } : null, fixedPatches = patches.map(_temp2), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
914
+ } : null, fixedPatches = patches.map(_temp3), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
850
915
  return originalOnChange(allPatches);
851
916
  }
852
917
  return originalOnChange(patches);
853
- }, $[2] = originalOnChange, $[3] = props.value?.value, $[4] = t1) : t1 = $[4];
854
- const wrappedOnChange = t1, inlineProps = {
855
- ...props.inputProps,
856
- members: props.inputProps.members.filter(_temp3),
918
+ }, $[0] = originalOnChange, $[1] = props.value?.value, $[2] = t0) : t0 = $[2];
919
+ const wrappedOnChange = t0, t1 = props.inputProps;
920
+ let t2;
921
+ $[3] !== props.inputProps.members ? (t2 = props.inputProps.members.filter(_temp4), $[3] = props.inputProps.members, $[4] = t2) : t2 = $[4];
922
+ let t3;
923
+ $[5] !== props.inputProps || $[6] !== props.value || $[7] !== t2 || $[8] !== wrappedOnChange ? (t3 = {
924
+ ...t1,
925
+ members: t2,
857
926
  value: props.value,
858
927
  onChange: wrappedOnChange
859
- }, {
928
+ }, $[5] = props.inputProps, $[6] = props.value, $[7] = t2, $[8] = wrappedOnChange, $[9] = t3) : t3 = $[9];
929
+ const inlineProps = t3, {
860
930
  validation,
861
931
  value,
862
- onChange,
863
932
  readOnly
864
933
  } = inlineProps, {
865
934
  languages,
866
935
  languageDisplay,
867
936
  defaultLanguages
868
937
  } = useInternationalizedArrayContext();
869
- let t2;
870
- $[5] !== parentValue ? (t2 = parentValue?.map(_temp4) ?? [], $[5] = parentValue, $[6] = t2) : t2 = $[6];
871
- const languageKeysInUse = t2, itemNeedsMigration = !value[LANGUAGE_FIELD_NAME], keyIsValid = languages?.length ? languages.find((l) => l.id === value[LANGUAGE_FIELD_NAME]) : !1, handleKeyChange = (event) => {
872
- const languageId = event?.currentTarget?.value;
873
- !value || !languages?.length || !languages.find((l_0) => l_0.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
874
- }, handleUnset = () => {
875
- onChange(unset());
876
- };
938
+ let t4;
939
+ $[10] !== languages || $[11] !== value ? (t4 = languages?.length ? languages.find((l) => l.id === value[LANGUAGE_FIELD_NAME]) : !1, $[10] = languages, $[11] = value, $[12] = t4) : t4 = $[12];
940
+ const keyIsValid = t4, itemNeedsMigration = !value[LANGUAGE_FIELD_NAME];
877
941
  if (!languages) {
878
- let t32;
879
- return $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t32 = /* @__PURE__ */ jsx(Spinner, {}), $[7] = t32) : t32 = $[7], t32;
942
+ let t52;
943
+ return $[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t52 = /* @__PURE__ */ jsx(Spinner, {}), $[13] = t52) : t52 = $[13], t52;
880
944
  }
881
- const language = languages.find((l_1) => l_1.id === value[LANGUAGE_FIELD_NAME]), languageTitle = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", isDefault = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), removeButton = /* @__PURE__ */ jsx(Button, { mode: "bleed", icon: RemoveCircleIcon, tone: "critical", disabled: readOnly || isDefault, onClick: handleUnset }), t3 = getToneFromValidation(validation), T0 = Card, t4 = 1, t5 = "inherit", t6 = props.inputProps.renderInput(inlineProps);
945
+ let t5;
946
+ if ($[14] !== keyIsValid || $[15] !== languageDisplay || $[16] !== languages || $[17] !== value) {
947
+ let t62;
948
+ $[19] !== value ? (t62 = (l_0) => l_0.id === value[LANGUAGE_FIELD_NAME], $[19] = value, $[20] = t62) : t62 = $[20];
949
+ const language = languages.find(t62);
950
+ t5 = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", $[14] = keyIsValid, $[15] = languageDisplay, $[16] = languages, $[17] = value, $[18] = t5;
951
+ } else
952
+ t5 = $[18];
953
+ const languageTitle = t5;
954
+ let t6;
955
+ $[21] !== defaultLanguages || $[22] !== value ? (t6 = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), $[21] = defaultLanguages, $[22] = value, $[23] = t6) : t6 = $[23];
956
+ const isDefault = t6;
882
957
  let t7;
883
- return $[8] !== T0 || $[9] !== t6 ? (t7 = /* @__PURE__ */ jsx(T0, { flex: t4, tone: t5, children: t6 }), $[8] = T0, $[9] = t6, $[10] = t7) : t7 = $[10], /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t3, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
884
- !itemNeedsMigration && /* @__PURE__ */ jsx(Card, { tone: "inherit", children: keyIsValid ? /* @__PURE__ */ jsx(Label, { muted: !0, size: 1, children: languageTitle }) : /* @__PURE__ */ jsx(MenuButton, { button: /* @__PURE__ */ jsx(Button, { fontSize: 1, text: `Change "${value[LANGUAGE_FIELD_NAME]}"` }), id: `${value[LANGUAGE_FIELD_NAME]}-change-key`, menu: /* @__PURE__ */ jsx(Menu, { children: languages.map((lang) => /* @__PURE__ */ jsx(MenuItem, { disabled: languageKeysInUse.includes(lang.id), fontSize: 1, text: lang.id.toLocaleUpperCase(), value: lang.id, onClick: handleKeyChange }, lang.id)) }), popover: {
885
- portal: !0
886
- } }) }),
887
- /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
888
- t7,
889
- /* @__PURE__ */ jsx(Card, { tone: "inherit", children: isDefault ? /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Can't remove default language" }), fallbackPlacements: ["right", "left"], placement: "top", portal: !0, children: /* @__PURE__ */ jsx("span", { children: removeButton }) }) : removeButton })
890
- ] })
891
- ] }) });
892
- }
893
- function _temp4(v) {
894
- return v[LANGUAGE_FIELD_NAME];
958
+ $[24] !== validation ? (t7 = getToneFromValidation(validation), $[24] = validation, $[25] = t7) : t7 = $[25];
959
+ let t8;
960
+ $[26] !== itemNeedsMigration || $[27] !== keyIsValid || $[28] !== languageTitle || $[29] !== originalOnChange || $[30] !== props.path || $[31] !== value ? (t8 = !itemNeedsMigration && /* @__PURE__ */ jsx(Card, { tone: "inherit", children: keyIsValid ? /* @__PURE__ */ jsx(Label, { muted: !0, size: 1, children: languageTitle }) : /* @__PURE__ */ jsx(ChangeLanguageButton, { value, path: props.path, onChange: originalOnChange }) }), $[26] = itemNeedsMigration, $[27] = keyIsValid, $[28] = languageTitle, $[29] = originalOnChange, $[30] = props.path, $[31] = value, $[32] = t8) : t8 = $[32];
961
+ let t9;
962
+ $[33] !== inlineProps || $[34] !== props.inputProps ? (t9 = props.inputProps.renderInput(inlineProps), $[33] = inlineProps, $[34] = props.inputProps, $[35] = t9) : t9 = $[35];
963
+ let t10;
964
+ $[36] !== t9 ? (t10 = /* @__PURE__ */ jsx(Box, { flex: 1, children: t9 }), $[36] = t9, $[37] = t10) : t10 = $[37];
965
+ const t11 = !!readOnly;
966
+ let t12;
967
+ $[38] !== isDefault || $[39] !== originalOnChange || $[40] !== t11 ? (t12 = /* @__PURE__ */ jsx(RemoveButton, { isDefault, readOnly: t11, onChange: originalOnChange }), $[38] = isDefault, $[39] = originalOnChange, $[40] = t11, $[41] = t12) : t12 = $[41];
968
+ let t13;
969
+ $[42] !== t10 || $[43] !== t12 ? (t13 = /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
970
+ t10,
971
+ t12
972
+ ] }), $[42] = t10, $[43] = t12, $[44] = t13) : t13 = $[44];
973
+ let t14;
974
+ $[45] !== t13 || $[46] !== t8 ? (t14 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
975
+ t8,
976
+ t13
977
+ ] }), $[45] = t13, $[46] = t8, $[47] = t14) : t14 = $[47];
978
+ let t15;
979
+ return $[48] !== t14 || $[49] !== t7 ? (t15 = /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t7, children: t14 }), $[48] = t14, $[49] = t7, $[50] = t15) : t15 = $[50], t15;
895
980
  }
896
- function _temp3(m) {
981
+ function _temp4(m) {
897
982
  return m.kind === "field" && m.name === "value";
898
983
  }
899
- function _temp2(patch_0) {
984
+ function _temp3(patch_0) {
900
985
  if (!patch_0 || typeof patch_0 != "object")
901
986
  return patch_0;
902
987
  if (patch_0.type === "insert" && patch_0.path && Array.isArray(patch_0.path)) {
@@ -908,7 +993,7 @@ function _temp2(patch_0) {
908
993
  }
909
994
  return patch_0;
910
995
  }
911
- function _temp(patch) {
996
+ function _temp2(patch) {
912
997
  return !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;
913
998
  }
914
999
  var object = (config) => {
@@ -921,14 +1006,25 @@ var object = (config) => {
921
1006
  type: "object",
922
1007
  components: {
923
1008
  // @ts-expect-error - fix typings
924
- item: InternationalizedInput
1009
+ item: InternationalizedInput,
1010
+ field: (props) => props.renderDefault({
1011
+ ...props,
1012
+ // Reset the level to avoid nested styling
1013
+ level: 0
1014
+ })
925
1015
  },
926
1016
  fields: [
927
1017
  defineField({
928
1018
  ...typeof type == "string" ? {
929
1019
  type
930
1020
  } : type,
931
- name: "value"
1021
+ name: "value",
1022
+ components: {
1023
+ field: (props) => props.renderDefault({
1024
+ ...props,
1025
+ title: ""
1026
+ })
1027
+ }
932
1028
  }),
933
1029
  // Hidden language field - stores the language identifier (e.g., 'en', 'fr')
934
1030
  // This replaces the previous pattern of storing language in _key
@@ -947,37 +1043,7 @@ var object = (config) => {
947
1043
  }
948
1044
  });
949
1045
  };
950
- function flattenSchemaType(schemaType) {
951
- return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
952
- }
953
- function extractInnerFields(fields, path, maxDepth) {
954
- return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
955
- const thisFieldWithPath = {
956
- path: [...path, field.name],
957
- ...field
958
- };
959
- if (field.type.jsonType === "object") {
960
- const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth);
961
- return acc.push(thisFieldWithPath, ...innerFields), acc;
962
- } else if (field.type.jsonType === "array" && field.type.of.length && field.type.of.some((item) => "fields" in item)) {
963
- const innerFields = field.type.of.flatMap((innerField) => extractInnerFields(
964
- // @ts-expect-error - Fix TS assertion for array fields
965
- innerField.fields,
966
- [...path, field.name],
967
- maxDepth
968
- ));
969
- return acc.push(thisFieldWithPath, ...innerFields), acc;
970
- }
971
- return acc.push(thisFieldWithPath), acc;
972
- }, []);
973
- }
974
- const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLanguageIds, parentValue) => {
975
- if (isInternationalizedArrayItemType(enclosingType.name)) {
976
- const language = typeof parentValue?.language == "string" ? parentValue?.language : null;
977
- return language ? selectedLanguageIds.includes(language) : !1;
978
- }
979
- return !0;
980
- }, internationalizedArray = definePlugin((config) => {
1046
+ const internationalizedArray = definePlugin((config) => {
981
1047
  const pluginConfig = {
982
1048
  ...CONFIG_DEFAULT,
983
1049
  ...config
@@ -1002,13 +1068,15 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
1002
1068
  },
1003
1069
  // Optional: render "add language" buttons as field actions
1004
1070
  document: {
1071
+ components: {
1072
+ unstable_layout: (props) => /* @__PURE__ */ jsx(InternationalizedArrayLayout, { ...props, pluginConfig })
1073
+ },
1005
1074
  unstable_fieldActions: buttonLocations.includes("unstable__fieldAction") ? (prev) => [...prev, internationalizedArrayFieldAction] : void 0
1006
1075
  },
1007
1076
  // Wrap document editor with a language provider
1008
1077
  form: {
1009
1078
  components: {
1010
- field: (props) => /* @__PURE__ */ jsx(InternationalizedField, { ...props }),
1011
- input: (props) => !(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).map((field) => field.type.name).some((name) => name.startsWith("internationalizedArray")) ? props.renderDefault(props) : /* @__PURE__ */ jsx(InternationalizedArrayProvider, { ...props, internationalizedArray: pluginConfig })
1079
+ input: (props) => props.id === "root" && isObjectInputProps(props) && hasInternationalizedArrayField(props.schemaType) && pluginConfig.includeForDocumentType(props.schemaType.name) ? /* @__PURE__ */ jsx(InternationalizedArrayFormInput, { ...props, pluginConfig }) : props.renderDefault(props)
1012
1080
  }
1013
1081
  },
1014
1082
  // Register custom schema types for the outer array and the inner object
@@ -1024,8 +1092,10 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
1024
1092
  },
1025
1093
  plugins: languageFilterConfig?.documentTypes?.length > 0 ? [languageFilter({
1026
1094
  documentTypes: languageFilterConfig.documentTypes,
1027
- supportedLanguages: languages,
1028
- filterField: internationalizedArrayLanguageFilter
1095
+ supportedLanguages: languages
1096
+ // This is specifically not adding filterField avoid the default filter field implementation.
1097
+ // It will be filtered in `internationalizedArray` component and will have access to the resolved languages.
1098
+ // Rendering the fields if the language key is incorrect, providing an improved UX
1029
1099
  })] : void 0
1030
1100
  };
1031
1101
  });