sanity-plugin-internationalized-array 5.0.0-canary.1 → 5.0.1
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/README.md +76 -3
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +442 -359
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +8 -8
- package/package.json +13 -7
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 {
|
|
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,
|
|
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 {
|
|
11
|
-
|
|
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(
|
|
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,173 @@ function InternationalizedArrayProvider(props) {
|
|
|
243
167
|
const languagesPromise = t4, languages = languagesPromise ? use(languagesPromise) : internationalizedArray2.languages, {
|
|
244
168
|
selectedLanguageIds,
|
|
245
169
|
options: languageFilterOptions
|
|
246
|
-
} = useLanguageFilterStudioContext()
|
|
170
|
+
} = useLanguageFilterStudioContext();
|
|
247
171
|
let t5;
|
|
248
|
-
$[19] !== documentType || $[20] !== languageFilterOptions ? (t5 =
|
|
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] !==
|
|
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
|
-
}, $[
|
|
262
|
-
const context =
|
|
263
|
-
let
|
|
264
|
-
$[
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
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] !==
|
|
287
|
-
|
|
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
|
-
$[
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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, visited = /* @__PURE__ */ new Set()) {
|
|
303
|
+
for (const field of fields)
|
|
304
|
+
if (!visited.has(field.type)) {
|
|
305
|
+
if (visited.add(field.type), field.type.name.startsWith("internationalizedArray") || field.type.jsonType === "object" && hasInternationalizedArrayInFields(field.type.fields, visited))
|
|
306
|
+
return !0;
|
|
307
|
+
if (field.type.jsonType === "array" && field.type.of.length > 0)
|
|
308
|
+
for (const item of field.type.of) {
|
|
309
|
+
if ("name" in item && typeof item.name == "string" && item.name.startsWith("internationalizedArray"))
|
|
310
|
+
return !0;
|
|
311
|
+
if ("fields" in item && Array.isArray(item.fields)) {
|
|
312
|
+
if (visited.has(item))
|
|
313
|
+
continue;
|
|
314
|
+
if (visited.add(item), hasInternationalizedArrayInFields(item.fields, visited))
|
|
315
|
+
return !0;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return !1;
|
|
320
|
+
}
|
|
321
|
+
function InternationalizedArrayLayout(props) {
|
|
322
|
+
const $ = c(10), schemaType = useSchema().get(props.documentType);
|
|
323
|
+
if (!schemaType) {
|
|
324
|
+
console.error(`Schema type not found: ${props.documentType}`);
|
|
325
|
+
let t02;
|
|
326
|
+
return $[0] !== props ? (t02 = props.renderDefault(props), $[0] = props, $[1] = t02) : t02 = $[1], t02;
|
|
297
327
|
}
|
|
298
|
-
if (
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}), $[7] = customProps, $[8] = t32) : t32 = $[8], t32;
|
|
328
|
+
if (hasInternationalizedArrayField(schemaType) && props.pluginConfig.includeForDocumentType(props.documentType)) {
|
|
329
|
+
const t02 = props.pluginConfig, t1 = props.documentType;
|
|
330
|
+
let t2;
|
|
331
|
+
$[2] !== props ? (t2 = props.renderDefault(props), $[2] = props, $[3] = t2) : t2 = $[3];
|
|
332
|
+
let t3;
|
|
333
|
+
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;
|
|
305
334
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
let t3;
|
|
309
|
-
return $[9] !== customProps ? (t3 = customProps.renderDefault({
|
|
310
|
-
...customProps,
|
|
311
|
-
level: 0
|
|
312
|
-
}), $[9] = customProps, $[10] = t3) : t3 = $[10], t3;
|
|
335
|
+
let t0;
|
|
336
|
+
return $[8] !== props ? (t0 = props.renderDefault(props), $[8] = props, $[9] = t0) : t0 = $[9], t0;
|
|
313
337
|
}
|
|
314
338
|
function Preload(props) {
|
|
315
339
|
const $ = c(2);
|
|
@@ -451,7 +475,13 @@ function pascalCase(string) {
|
|
|
451
475
|
function createFieldName(name, addValue = !1) {
|
|
452
476
|
return addValue ? ["internationalizedArray", pascalCase(name), "Value"].join("") : ["internationalizedArray", pascalCase(name)].join("");
|
|
453
477
|
}
|
|
454
|
-
const
|
|
478
|
+
const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLanguageIds, parentValue, languages) => {
|
|
479
|
+
if (isInternationalizedArrayItemType(enclosingType.name)) {
|
|
480
|
+
const language = typeof parentValue?.[LANGUAGE_FIELD_NAME] == "string" ? parentValue?.[LANGUAGE_FIELD_NAME] : typeof parentValue?._key == "string" ? parentValue?._key : null;
|
|
481
|
+
return !language || languages.find((l) => l.id === language) ? language ? selectedLanguageIds.includes(language) : !1 : !0;
|
|
482
|
+
}
|
|
483
|
+
return !0;
|
|
484
|
+
}, schemaExample = {
|
|
455
485
|
languages: [{
|
|
456
486
|
id: "en",
|
|
457
487
|
title: "English"
|
|
@@ -484,76 +514,52 @@ function Feedback() {
|
|
|
484
514
|
] }) }), $[3] = t3) : t3 = $[3], t3;
|
|
485
515
|
}
|
|
486
516
|
function MigrationBanner(t0) {
|
|
487
|
-
const $ = c(
|
|
488
|
-
|
|
489
|
-
languages
|
|
517
|
+
const $ = c(11), {
|
|
518
|
+
itemsNeedingMigration
|
|
490
519
|
} = t0;
|
|
491
|
-
|
|
492
|
-
let t2;
|
|
493
|
-
bb0: {
|
|
494
|
-
if (!value?.length || !languages?.length) {
|
|
495
|
-
let t33;
|
|
496
|
-
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t33 = [], $[0] = t33) : t33 = $[0], t2 = t33;
|
|
497
|
-
break bb0;
|
|
498
|
-
}
|
|
499
|
-
let t32;
|
|
500
|
-
$[1] !== languages ? (t32 = new Set(languages.map(_temp$2)), $[1] = languages, $[2] = t32) : t32 = $[2];
|
|
501
|
-
const languageIds = t32;
|
|
502
|
-
let t42;
|
|
503
|
-
if ($[3] !== languageIds || $[4] !== value) {
|
|
504
|
-
let t52;
|
|
505
|
-
$[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;
|
|
506
|
-
} else
|
|
507
|
-
t42 = $[5];
|
|
508
|
-
t2 = t42;
|
|
509
|
-
}
|
|
510
|
-
const itemsNeedingMigration = t2;
|
|
511
|
-
if (!(itemsNeedingMigration.length > 0))
|
|
520
|
+
if (!itemsNeedingMigration.length)
|
|
512
521
|
return null;
|
|
513
|
-
let
|
|
514
|
-
$[
|
|
515
|
-
let
|
|
516
|
-
$[
|
|
517
|
-
const
|
|
518
|
-
let
|
|
519
|
-
$[
|
|
522
|
+
let t1;
|
|
523
|
+
$[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];
|
|
524
|
+
let t2;
|
|
525
|
+
$[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Data migration required" }), $[1] = t2) : t2 = $[1];
|
|
526
|
+
const t3 = itemsNeedingMigration.length === 1 ? "" : "s", t4 = itemsNeedingMigration.length === 1 ? "needs" : "need";
|
|
527
|
+
let t5;
|
|
528
|
+
$[2] !== itemsNeedingMigration.length || $[3] !== t3 || $[4] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
|
|
520
529
|
itemsNeedingMigration.length,
|
|
521
530
|
" item",
|
|
522
|
-
|
|
531
|
+
t3,
|
|
523
532
|
" ",
|
|
524
|
-
|
|
533
|
+
t4,
|
|
525
534
|
" to be migrated to the v5 format."
|
|
526
|
-
] }), $[
|
|
535
|
+
] }), $[2] = itemsNeedingMigration.length, $[3] = t3, $[4] = t4, $[5] = t5) : t5 = $[5];
|
|
536
|
+
let t6;
|
|
537
|
+
$[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx("code", { children: "_key" }), $[6] = t6) : t6 = $[6];
|
|
538
|
+
let t7;
|
|
539
|
+
$[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = /* @__PURE__ */ jsx("code", { children: "language" }), $[7] = t7) : t7 = $[7];
|
|
527
540
|
let t8;
|
|
528
|
-
$[
|
|
529
|
-
let t9;
|
|
530
|
-
$[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t9 = /* @__PURE__ */ jsx("code", { children: "language" }), $[15] = t9) : t9 = $[15];
|
|
531
|
-
let t10;
|
|
532
|
-
$[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t10 = /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
541
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
533
542
|
"This field still uses the v4 format where language is stored in ",
|
|
534
|
-
|
|
543
|
+
t6,
|
|
535
544
|
". Migrate to the v5 format where language is stored in ",
|
|
536
|
-
|
|
545
|
+
t7,
|
|
537
546
|
".",
|
|
538
547
|
" ",
|
|
539
548
|
/* @__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" }),
|
|
540
549
|
"."
|
|
541
|
-
] }) }), $[
|
|
542
|
-
let
|
|
543
|
-
return $[
|
|
544
|
-
|
|
550
|
+
] }) }), $[8] = t8) : t8 = $[8];
|
|
551
|
+
let t9;
|
|
552
|
+
return $[9] !== t5 ? (t9 = /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, radius: 2, border: !0, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
|
|
553
|
+
t1,
|
|
545
554
|
/* @__PURE__ */ jsxs(Stack, { space: 2, flex: 1, children: [
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
555
|
+
t2,
|
|
556
|
+
t5,
|
|
557
|
+
t8
|
|
549
558
|
] })
|
|
550
|
-
] }) }), $[
|
|
551
|
-
}
|
|
552
|
-
function _temp$2(l) {
|
|
553
|
-
return l.id;
|
|
559
|
+
] }) }), $[9] = t5, $[10] = t9) : t9 = $[10], t9;
|
|
554
560
|
}
|
|
555
561
|
function InternationalizedArray(props) {
|
|
556
|
-
const $ = c(
|
|
562
|
+
const $ = c(102), {
|
|
557
563
|
members,
|
|
558
564
|
value: _value,
|
|
559
565
|
schemaType,
|
|
@@ -562,12 +568,13 @@ function InternationalizedArray(props) {
|
|
|
562
568
|
} = props, value = _value;
|
|
563
569
|
let t0;
|
|
564
570
|
$[0] !== value ? (t0 = value?.filter(_temp$1) ?? [], $[0] = value, $[1] = t0) : t0 = $[1];
|
|
565
|
-
const itemsNeedingMigration = t0.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), {
|
|
571
|
+
const itemsNeedingMigration = t0, shouldMigrateArray = itemsNeedingMigration.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), getFormValue = useGetFormValue(), {
|
|
566
572
|
languages,
|
|
567
573
|
filteredLanguages,
|
|
568
574
|
defaultLanguages,
|
|
569
575
|
buttonAddAll,
|
|
570
|
-
buttonLocations
|
|
576
|
+
buttonLocations,
|
|
577
|
+
languageFilter: builtInLanguageFilter
|
|
571
578
|
} = useInternationalizedArrayContext(), {
|
|
572
579
|
selectedLanguageIds,
|
|
573
580
|
options: languageFilterOptions
|
|
@@ -577,17 +584,21 @@ function InternationalizedArray(props) {
|
|
|
577
584
|
const documentType = useFormValue(t1);
|
|
578
585
|
let t2;
|
|
579
586
|
$[3] !== documentType || $[4] !== languageFilterOptions ? (t2 = typeof documentType == "string" && languageFilterOptions.documentTypes.includes(documentType), $[3] = documentType, $[4] = languageFilterOptions, $[5] = t2) : t2 = $[5];
|
|
580
|
-
const
|
|
587
|
+
const usingLanguageFilterPlugin = t2;
|
|
581
588
|
let t3;
|
|
582
|
-
$[6] !==
|
|
589
|
+
$[6] !== builtInLanguageFilter || $[7] !== documentType ? (t3 = typeof documentType == "string" && builtInLanguageFilter.documentTypes.includes(documentType), $[6] = builtInLanguageFilter, $[7] = documentType, $[8] = t3) : t3 = $[8];
|
|
590
|
+
const usingBuiltInLanguageFilter = t3;
|
|
591
|
+
let t4;
|
|
592
|
+
$[9] !== languageFilterOptions || $[10] !== languages || $[11] !== members || $[12] !== selectedLanguageIds || $[13] !== usingBuiltInLanguageFilter || $[14] !== usingLanguageFilterPlugin ? (t4 = usingLanguageFilterPlugin || usingBuiltInLanguageFilter ? members.filter((member) => {
|
|
583
593
|
if (member.kind !== "item")
|
|
584
594
|
return !1;
|
|
585
595
|
const valueMember = member.item.members[0];
|
|
586
|
-
return !valueMember || valueMember.kind !== "field" ? !1 : languageFilterOptions.filterField(member.item.schemaType, valueMember, selectedLanguageIds,
|
|
587
|
-
}) : members, $[
|
|
588
|
-
const filteredMembers =
|
|
589
|
-
let
|
|
590
|
-
$[
|
|
596
|
+
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);
|
|
597
|
+
}) : members, $[9] = languageFilterOptions, $[10] = languages, $[11] = members, $[12] = selectedLanguageIds, $[13] = usingBuiltInLanguageFilter, $[14] = usingLanguageFilterPlugin, $[15] = t4) : t4 = $[15];
|
|
598
|
+
const filteredMembers = t4;
|
|
599
|
+
let t5;
|
|
600
|
+
$[16] !== filteredLanguages || $[17] !== getFormValue || $[18] !== languages || $[19] !== onChange || $[20] !== props.path || $[21] !== schemaType.name ? (t5 = (addLanguageKeys) => {
|
|
601
|
+
const formValue = getFormValue(props.path);
|
|
591
602
|
if (!filteredLanguages?.length)
|
|
592
603
|
return;
|
|
593
604
|
const patches = createAddLanguagePatches({
|
|
@@ -595,139 +606,144 @@ function InternationalizedArray(props) {
|
|
|
595
606
|
schemaTypeName: schemaType.name,
|
|
596
607
|
languages,
|
|
597
608
|
filteredLanguages,
|
|
598
|
-
value
|
|
609
|
+
value: formValue
|
|
599
610
|
});
|
|
600
611
|
onChange([setIfMissing([]), ...patches]);
|
|
601
|
-
}, $[
|
|
602
|
-
const
|
|
612
|
+
}, $[16] = filteredLanguages, $[17] = getFormValue, $[18] = languages, $[19] = onChange, $[20] = props.path, $[21] = schemaType.name, $[22] = t5) : t5 = $[22];
|
|
613
|
+
const handleAddLanguages = t5, {
|
|
603
614
|
isDeleting
|
|
604
615
|
} = useDocumentPane();
|
|
605
|
-
let t5;
|
|
606
|
-
bb0: {
|
|
607
|
-
if (!value?.length) {
|
|
608
|
-
let t63;
|
|
609
|
-
$[18] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t63 = [], $[18] = t63) : t63 = $[18], t5 = t63;
|
|
610
|
-
break bb0;
|
|
611
|
-
}
|
|
612
|
-
let t62;
|
|
613
|
-
$[19] !== languages ? (t62 = new Set(languages.map(_temp2$1)), $[19] = languages, $[20] = t62) : t62 = $[20];
|
|
614
|
-
const languageIds = t62;
|
|
615
|
-
let t72;
|
|
616
|
-
if ($[21] !== languageIds || $[22] !== value) {
|
|
617
|
-
let t82;
|
|
618
|
-
$[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;
|
|
619
|
-
} else
|
|
620
|
-
t72 = $[23];
|
|
621
|
-
t5 = t72;
|
|
622
|
-
}
|
|
623
|
-
const addedLanguages = t5;
|
|
624
616
|
let t6;
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
617
|
+
$[23] !== value ? (t6 = value?.map(_temp2$1).filter(Boolean).join(","), $[23] = value, $[24] = t6) : t6 = $[24];
|
|
618
|
+
const languageKeysFromValue = t6;
|
|
619
|
+
let t7;
|
|
620
|
+
if ($[25] !== languageKeysFromValue || $[26] !== languages) {
|
|
621
|
+
bb0: {
|
|
622
|
+
const languageKeys = languageKeysFromValue?.split(",") || [];
|
|
623
|
+
if (!languageKeys?.length) {
|
|
624
|
+
let t82;
|
|
625
|
+
$[28] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t82 = [], $[28] = t82) : t82 = $[28], t7 = t82;
|
|
626
|
+
break bb0;
|
|
627
|
+
}
|
|
628
|
+
if (!languages?.length) {
|
|
629
|
+
let t82;
|
|
630
|
+
$[29] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t82 = [], $[29] = t82) : t82 = $[29], t7 = t82;
|
|
631
|
+
break bb0;
|
|
632
|
+
}
|
|
633
|
+
t7 = languages.filter((l) => languageKeys?.find((key) => key === l.id)).map(_temp3$1);
|
|
634
|
+
}
|
|
635
|
+
$[25] = languageKeysFromValue, $[26] = languages, $[27] = t7;
|
|
630
636
|
} else
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
let
|
|
634
|
-
$[
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
637
|
+
t7 = $[27];
|
|
638
|
+
const addedLanguages = t7;
|
|
639
|
+
let t8, t9;
|
|
640
|
+
$[30] !== addedLanguages || $[31] !== defaultLanguages || $[32] !== documentReadOnly || $[33] !== handleAddLanguages || $[34] !== isDeleting || $[35] !== languages || $[36] !== shouldMigrateArray ? (t8 = () => {
|
|
641
|
+
const hasAddedDefaultLanguages = defaultLanguages.filter((language) => languages.find((l_1) => l_1.id === language)).every((language_0) => addedLanguages.includes(language_0));
|
|
642
|
+
if (!isDeleting && !hasAddedDefaultLanguages && !shouldMigrateArray) {
|
|
643
|
+
const languagesToAdd = defaultLanguages.filter((language_1) => !addedLanguages.includes(language_1)).filter((language_2) => languages.find((l_2) => l_2.id === language_2)), timeout = setTimeout(() => {
|
|
644
|
+
documentReadOnly || handleAddLanguages(languagesToAdd);
|
|
638
645
|
});
|
|
639
646
|
return () => clearTimeout(timeout);
|
|
640
647
|
}
|
|
641
|
-
},
|
|
642
|
-
let
|
|
643
|
-
$[
|
|
648
|
+
}, 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);
|
|
649
|
+
let t10;
|
|
650
|
+
$[39] !== languages || $[40] !== onChange || $[41] !== toast || $[42] !== value ? (t10 = () => {
|
|
644
651
|
if (!value?.length || !languages?.length)
|
|
645
652
|
return;
|
|
646
653
|
const updatedValue = value.reduce((acc, v_1) => {
|
|
647
|
-
const newIndex = languages.findIndex((
|
|
654
|
+
const newIndex = languages.findIndex((l_3) => l_3.id === v_1?.[LANGUAGE_FIELD_NAME]);
|
|
648
655
|
return newIndex > -1 && (acc[newIndex] = v_1), acc;
|
|
649
656
|
}, []).filter(Boolean);
|
|
650
657
|
value?.length !== updatedValue.length && toast.push({
|
|
651
658
|
title: "There was an error reordering languages",
|
|
652
659
|
status: "warning"
|
|
653
660
|
}), onChange(set(updatedValue));
|
|
654
|
-
}, $[
|
|
655
|
-
const handleRestoreOrder =
|
|
656
|
-
let
|
|
661
|
+
}, $[39] = languages, $[40] = onChange, $[41] = toast, $[42] = value, $[43] = t10) : t10 = $[43];
|
|
662
|
+
const handleRestoreOrder = t10;
|
|
663
|
+
let t11;
|
|
657
664
|
bb1: {
|
|
658
665
|
if (!value?.length || !languages?.length) {
|
|
659
|
-
|
|
666
|
+
t11 = !0;
|
|
660
667
|
break bb1;
|
|
661
668
|
}
|
|
662
|
-
let
|
|
663
|
-
$[
|
|
669
|
+
let t122;
|
|
670
|
+
$[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;
|
|
664
671
|
}
|
|
665
|
-
const allKeysAreLanguages =
|
|
666
|
-
let t11;
|
|
667
|
-
$[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];
|
|
668
|
-
const languagesInUse = t11;
|
|
672
|
+
const allKeysAreLanguages = t11;
|
|
669
673
|
let t12;
|
|
670
674
|
bb2: {
|
|
671
|
-
if (!value?.length || !
|
|
675
|
+
if (!value?.length || !addedLanguages.length) {
|
|
672
676
|
let t133;
|
|
673
|
-
$[
|
|
677
|
+
$[47] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t133 = [], $[47] = t133) : t133 = $[47], t12 = t133;
|
|
674
678
|
break bb2;
|
|
675
679
|
}
|
|
676
680
|
let t132;
|
|
677
|
-
if ($[
|
|
681
|
+
if ($[48] !== addedLanguages || $[49] !== value) {
|
|
678
682
|
let t142;
|
|
679
|
-
$[
|
|
683
|
+
$[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;
|
|
680
684
|
} else
|
|
681
|
-
t132 = $[
|
|
685
|
+
t132 = $[50];
|
|
682
686
|
t12 = t132;
|
|
683
687
|
}
|
|
684
688
|
const languagesOutOfOrder = t12, languagesAreValid = !languages?.length || languages?.length && languages.every(_temp4$1);
|
|
685
689
|
let t13;
|
|
686
|
-
$[
|
|
690
|
+
$[53] !== allKeysAreLanguages || $[54] !== documentReadOnly || $[55] !== handleRestoreOrder || $[56] !== languagesOutOfOrder.length ? (t13 = () => {
|
|
687
691
|
languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
|
|
688
|
-
}, $[
|
|
692
|
+
}, $[53] = allKeysAreLanguages, $[54] = documentReadOnly, $[55] = handleRestoreOrder, $[56] = languagesOutOfOrder.length, $[57] = t13) : t13 = $[57];
|
|
689
693
|
let t14;
|
|
690
|
-
$[
|
|
694
|
+
$[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);
|
|
691
695
|
let t15;
|
|
692
|
-
$[
|
|
696
|
+
$[63] !== filteredLanguages || $[64] !== value ? (t15 = checkAllLanguagesArePresent(filteredLanguages, value), $[63] = filteredLanguages, $[64] = value, $[65] = t15) : t15 = $[65];
|
|
693
697
|
const allLanguagesArePresent = t15;
|
|
698
|
+
let t16;
|
|
699
|
+
$[66] !== filteredLanguages || $[67] !== handleAddLanguages ? (t16 = () => {
|
|
700
|
+
handleAddLanguages(filteredLanguages.map(_temp5));
|
|
701
|
+
}, $[66] = filteredLanguages, $[67] = handleAddLanguages, $[68] = t16) : t16 = $[68];
|
|
702
|
+
const addAllMissingLanguages = t16;
|
|
694
703
|
if (!languagesAreValid) {
|
|
695
|
-
let
|
|
696
|
-
return $[
|
|
704
|
+
let t172;
|
|
705
|
+
return $[69] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t172 = /* @__PURE__ */ jsx(Feedback, {}), $[69] = t172) : t172 = $[69], t172;
|
|
697
706
|
}
|
|
698
|
-
let t16;
|
|
699
|
-
$[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];
|
|
700
|
-
const addButtonsAreVisible = t16, fieldHasMembers = members?.length > 0;
|
|
701
707
|
let t17;
|
|
702
|
-
$[
|
|
708
|
+
$[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];
|
|
709
|
+
const addButtonsAreVisible = t17, fieldHasMembers = members?.length > 0;
|
|
703
710
|
let t18;
|
|
704
|
-
$[
|
|
711
|
+
$[75] !== filteredLanguages || $[76] !== value ? (t18 = createAddAllTitle(value, filteredLanguages), $[75] = filteredLanguages, $[76] = value, $[77] = t18) : t18 = $[77];
|
|
712
|
+
const addAllTitle = t18;
|
|
705
713
|
let t19;
|
|
706
|
-
$[
|
|
714
|
+
if ($[78] !== filteredMembers || $[79] !== props) {
|
|
715
|
+
let t202;
|
|
716
|
+
$[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;
|
|
717
|
+
} else
|
|
718
|
+
t19 = $[80];
|
|
707
719
|
let t20;
|
|
708
|
-
$[
|
|
709
|
-
/* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, value, readOnly, handleClick: handleAddLanguage }),
|
|
710
|
-
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
|
|
711
|
-
] }) : null, $[92] = addButtonsAreVisible, $[93] = allLanguagesArePresent, $[94] = buttonAddAll, $[95] = filteredLanguages, $[96] = handleAddLanguage, $[97] = readOnly, $[98] = value, $[99] = t20) : t20 = $[99];
|
|
720
|
+
$[83] !== itemsNeedingMigration ? (t20 = /* @__PURE__ */ jsx(MigrationBanner, { itemsNeedingMigration }), $[83] = itemsNeedingMigration, $[84] = t20) : t20 = $[84];
|
|
712
721
|
let t21;
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
722
|
+
$[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];
|
|
723
|
+
let t22;
|
|
724
|
+
$[88] !== addAllMissingLanguages || $[89] !== addAllTitle || $[90] !== addButtonsAreVisible || $[91] !== addedLanguages || $[92] !== allLanguagesArePresent || $[93] !== buttonAddAll || $[94] !== handleAddLanguages || $[95] !== readOnly ? (t22 = addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
725
|
+
/* @__PURE__ */ jsx(AddButtons, { languagesInUse: addedLanguages, readOnly, handleClick: handleAddLanguages }),
|
|
726
|
+
buttonAddAll ? /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", "data-testid": "add-all-languages", disabled: readOnly || allLanguagesArePresent, icon: AddIcon, text: addAllTitle, onClick: addAllMissingLanguages }) : null
|
|
727
|
+
] }) : null, $[88] = addAllMissingLanguages, $[89] = addAllTitle, $[90] = addButtonsAreVisible, $[91] = addedLanguages, $[92] = allLanguagesArePresent, $[93] = buttonAddAll, $[94] = handleAddLanguages, $[95] = readOnly, $[96] = t22) : t22 = $[96];
|
|
728
|
+
let t23;
|
|
729
|
+
return $[97] !== t19 || $[98] !== t20 || $[99] !== t21 || $[100] !== t22 ? (t23 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
716
730
|
t19,
|
|
717
|
-
t20
|
|
718
|
-
|
|
731
|
+
t20,
|
|
732
|
+
t21,
|
|
733
|
+
t22
|
|
734
|
+
] }), $[97] = t19, $[98] = t20, $[99] = t21, $[100] = t22, $[101] = t23) : t23 = $[101], t23;
|
|
719
735
|
}
|
|
720
|
-
function _temp5(
|
|
721
|
-
return
|
|
736
|
+
function _temp5(language_4) {
|
|
737
|
+
return language_4.id;
|
|
722
738
|
}
|
|
723
739
|
function _temp4$1(item) {
|
|
724
740
|
return item.id && item.title;
|
|
725
741
|
}
|
|
726
|
-
function _temp3$1(
|
|
727
|
-
return
|
|
742
|
+
function _temp3$1(l_0) {
|
|
743
|
+
return l_0.id;
|
|
728
744
|
}
|
|
729
|
-
function _temp2$1(
|
|
730
|
-
return
|
|
745
|
+
function _temp2$1(v_0) {
|
|
746
|
+
return v_0[LANGUAGE_FIELD_NAME] ?? v_0._key;
|
|
731
747
|
}
|
|
732
748
|
function _temp$1(v) {
|
|
733
749
|
return !v[LANGUAGE_FIELD_NAME];
|
|
@@ -747,6 +763,11 @@ var array = (config) => {
|
|
|
747
763
|
title: "Internationalized array",
|
|
748
764
|
type: "array",
|
|
749
765
|
components: {
|
|
766
|
+
field: (props) => props.renderDefault({
|
|
767
|
+
...props,
|
|
768
|
+
// Reset the level to avoid nested styling
|
|
769
|
+
level: 0
|
|
770
|
+
}),
|
|
750
771
|
input: InternationalizedArray
|
|
751
772
|
},
|
|
752
773
|
options: {
|
|
@@ -825,72 +846,149 @@ function getToneFromValidation(validations) {
|
|
|
825
846
|
if (validationLevels.has("warning"))
|
|
826
847
|
return "caution";
|
|
827
848
|
}
|
|
828
|
-
function
|
|
829
|
-
const $ = c(
|
|
849
|
+
function ChangeLanguageButton(props) {
|
|
850
|
+
const $ = c(24), {
|
|
851
|
+
value,
|
|
852
|
+
onChange,
|
|
853
|
+
path
|
|
854
|
+
} = props;
|
|
830
855
|
let t0;
|
|
831
|
-
$[0] !==
|
|
832
|
-
const parentValue = useFormValue(t0),
|
|
856
|
+
$[0] !== path ? (t0 = path.slice(0, -1), $[0] = path, $[1] = t0) : t0 = $[1];
|
|
857
|
+
const parentValue = useFormValue(t0), {
|
|
858
|
+
languages
|
|
859
|
+
} = useInternationalizedArrayContext();
|
|
833
860
|
let t1;
|
|
834
|
-
$[2] !==
|
|
861
|
+
$[2] !== parentValue ? (t1 = parentValue?.map(_temp) ?? [], $[2] = parentValue, $[3] = t1) : t1 = $[3];
|
|
862
|
+
const languageKeysInUse = t1;
|
|
863
|
+
let t2;
|
|
864
|
+
$[4] !== languages || $[5] !== onChange || $[6] !== value ? (t2 = (event) => {
|
|
865
|
+
const languageId = event?.currentTarget?.value;
|
|
866
|
+
!value || !languages?.length || !languages.find((l) => l.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
|
|
867
|
+
}, $[4] = languages, $[5] = onChange, $[6] = value, $[7] = t2) : t2 = $[7];
|
|
868
|
+
const handleKeyChange = t2, t3 = `Change "${value[LANGUAGE_FIELD_NAME]}"`;
|
|
869
|
+
let t4;
|
|
870
|
+
$[8] !== t3 ? (t4 = /* @__PURE__ */ jsx(Button, { fontSize: 1, text: t3 }), $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
871
|
+
const t5 = `${value[LANGUAGE_FIELD_NAME]}-change-key`;
|
|
872
|
+
let t6;
|
|
873
|
+
if ($[10] !== handleKeyChange || $[11] !== languageKeysInUse || $[12] !== languages) {
|
|
874
|
+
let t72;
|
|
875
|
+
$[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;
|
|
876
|
+
} else
|
|
877
|
+
t6 = $[13];
|
|
878
|
+
let t7;
|
|
879
|
+
$[17] !== t6 ? (t7 = /* @__PURE__ */ jsx(Menu, { children: t6 }), $[17] = t6, $[18] = t7) : t7 = $[18];
|
|
880
|
+
let t8;
|
|
881
|
+
$[19] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = {
|
|
882
|
+
portal: !0
|
|
883
|
+
}, $[19] = t8) : t8 = $[19];
|
|
884
|
+
let t9;
|
|
885
|
+
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;
|
|
886
|
+
}
|
|
887
|
+
function _temp(v) {
|
|
888
|
+
return v[LANGUAGE_FIELD_NAME];
|
|
889
|
+
}
|
|
890
|
+
function RemoveButton(t0) {
|
|
891
|
+
const $ = c(10), {
|
|
892
|
+
isDefault,
|
|
893
|
+
readOnly,
|
|
894
|
+
onChange
|
|
895
|
+
} = t0;
|
|
896
|
+
let t1;
|
|
897
|
+
$[0] !== onChange ? (t1 = () => {
|
|
898
|
+
onChange(unset());
|
|
899
|
+
}, $[0] = onChange, $[1] = t1) : t1 = $[1];
|
|
900
|
+
const handleUnset = t1, t2 = !isDefault;
|
|
901
|
+
let t3, t4;
|
|
902
|
+
$[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]);
|
|
903
|
+
const t5 = readOnly || isDefault;
|
|
904
|
+
let t6;
|
|
905
|
+
$[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];
|
|
906
|
+
let t7;
|
|
907
|
+
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;
|
|
908
|
+
}
|
|
909
|
+
function InternationalizedInput(props) {
|
|
910
|
+
const $ = c(51), originalOnChange = props.inputProps.onChange;
|
|
911
|
+
let t0;
|
|
912
|
+
$[0] !== originalOnChange || $[1] !== props.value?.value ? (t0 = (patches) => {
|
|
835
913
|
if (!Array.isArray(patches))
|
|
836
914
|
return originalOnChange(patches);
|
|
837
915
|
const valueField = props.value?.value;
|
|
838
|
-
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(
|
|
916
|
+
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp2)) {
|
|
839
917
|
const initPatch = valueField === void 0 ? {
|
|
840
918
|
type: "setIfMissing",
|
|
841
919
|
path: ["value"],
|
|
842
920
|
value: []
|
|
843
|
-
} : null, fixedPatches = patches.map(
|
|
921
|
+
} : null, fixedPatches = patches.map(_temp3), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
|
|
844
922
|
return originalOnChange(allPatches);
|
|
845
923
|
}
|
|
846
924
|
return originalOnChange(patches);
|
|
847
|
-
}, $[
|
|
848
|
-
const wrappedOnChange =
|
|
849
|
-
|
|
850
|
-
|
|
925
|
+
}, $[0] = originalOnChange, $[1] = props.value?.value, $[2] = t0) : t0 = $[2];
|
|
926
|
+
const wrappedOnChange = t0, t1 = props.inputProps;
|
|
927
|
+
let t2;
|
|
928
|
+
$[3] !== props.inputProps.members ? (t2 = props.inputProps.members.filter(_temp4), $[3] = props.inputProps.members, $[4] = t2) : t2 = $[4];
|
|
929
|
+
let t3;
|
|
930
|
+
$[5] !== props.inputProps || $[6] !== props.value || $[7] !== t2 || $[8] !== wrappedOnChange ? (t3 = {
|
|
931
|
+
...t1,
|
|
932
|
+
members: t2,
|
|
851
933
|
value: props.value,
|
|
852
934
|
onChange: wrappedOnChange
|
|
853
|
-
},
|
|
935
|
+
}, $[5] = props.inputProps, $[6] = props.value, $[7] = t2, $[8] = wrappedOnChange, $[9] = t3) : t3 = $[9];
|
|
936
|
+
const inlineProps = t3, {
|
|
854
937
|
validation,
|
|
855
938
|
value,
|
|
856
|
-
onChange,
|
|
857
939
|
readOnly
|
|
858
940
|
} = inlineProps, {
|
|
859
941
|
languages,
|
|
860
942
|
languageDisplay,
|
|
861
943
|
defaultLanguages
|
|
862
944
|
} = useInternationalizedArrayContext();
|
|
863
|
-
let
|
|
864
|
-
$[
|
|
865
|
-
const
|
|
866
|
-
const languageId = event?.currentTarget?.value;
|
|
867
|
-
!value || !languages?.length || !languages.find((l_0) => l_0.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
|
|
868
|
-
}, handleUnset = () => {
|
|
869
|
-
onChange(unset());
|
|
870
|
-
};
|
|
945
|
+
let t4;
|
|
946
|
+
$[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];
|
|
947
|
+
const keyIsValid = t4, itemNeedsMigration = !value[LANGUAGE_FIELD_NAME];
|
|
871
948
|
if (!languages) {
|
|
872
|
-
let
|
|
873
|
-
return $[
|
|
949
|
+
let t52;
|
|
950
|
+
return $[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t52 = /* @__PURE__ */ jsx(Spinner, {}), $[13] = t52) : t52 = $[13], t52;
|
|
874
951
|
}
|
|
875
|
-
|
|
952
|
+
let t5;
|
|
953
|
+
if ($[14] !== keyIsValid || $[15] !== languageDisplay || $[16] !== languages || $[17] !== value) {
|
|
954
|
+
let t62;
|
|
955
|
+
$[19] !== value ? (t62 = (l_0) => l_0.id === value[LANGUAGE_FIELD_NAME], $[19] = value, $[20] = t62) : t62 = $[20];
|
|
956
|
+
const language = languages.find(t62);
|
|
957
|
+
t5 = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", $[14] = keyIsValid, $[15] = languageDisplay, $[16] = languages, $[17] = value, $[18] = t5;
|
|
958
|
+
} else
|
|
959
|
+
t5 = $[18];
|
|
960
|
+
const languageTitle = t5;
|
|
961
|
+
let t6;
|
|
962
|
+
$[21] !== defaultLanguages || $[22] !== value ? (t6 = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), $[21] = defaultLanguages, $[22] = value, $[23] = t6) : t6 = $[23];
|
|
963
|
+
const isDefault = t6;
|
|
876
964
|
let t7;
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
|
|
965
|
+
$[24] !== validation ? (t7 = getToneFromValidation(validation), $[24] = validation, $[25] = t7) : t7 = $[25];
|
|
966
|
+
let t8;
|
|
967
|
+
$[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];
|
|
968
|
+
let t9;
|
|
969
|
+
$[33] !== inlineProps || $[34] !== props.inputProps ? (t9 = props.inputProps.renderInput(inlineProps), $[33] = inlineProps, $[34] = props.inputProps, $[35] = t9) : t9 = $[35];
|
|
970
|
+
let t10;
|
|
971
|
+
$[36] !== t9 ? (t10 = /* @__PURE__ */ jsx(Box, { flex: 1, children: t9 }), $[36] = t9, $[37] = t10) : t10 = $[37];
|
|
972
|
+
const t11 = !!readOnly;
|
|
973
|
+
let t12;
|
|
974
|
+
$[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];
|
|
975
|
+
let t13;
|
|
976
|
+
$[42] !== t10 || $[43] !== t12 ? (t13 = /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
977
|
+
t10,
|
|
978
|
+
t12
|
|
979
|
+
] }), $[42] = t10, $[43] = t12, $[44] = t13) : t13 = $[44];
|
|
980
|
+
let t14;
|
|
981
|
+
$[45] !== t13 || $[46] !== t8 ? (t14 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
982
|
+
t8,
|
|
983
|
+
t13
|
|
984
|
+
] }), $[45] = t13, $[46] = t8, $[47] = t14) : t14 = $[47];
|
|
985
|
+
let t15;
|
|
986
|
+
return $[48] !== t14 || $[49] !== t7 ? (t15 = /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t7, children: t14 }), $[48] = t14, $[49] = t7, $[50] = t15) : t15 = $[50], t15;
|
|
889
987
|
}
|
|
890
|
-
function
|
|
988
|
+
function _temp4(m) {
|
|
891
989
|
return m.kind === "field" && m.name === "value";
|
|
892
990
|
}
|
|
893
|
-
function
|
|
991
|
+
function _temp3(patch_0) {
|
|
894
992
|
if (!patch_0 || typeof patch_0 != "object")
|
|
895
993
|
return patch_0;
|
|
896
994
|
if (patch_0.type === "insert" && patch_0.path && Array.isArray(patch_0.path)) {
|
|
@@ -902,7 +1000,7 @@ function _temp2(patch_0) {
|
|
|
902
1000
|
}
|
|
903
1001
|
return patch_0;
|
|
904
1002
|
}
|
|
905
|
-
function
|
|
1003
|
+
function _temp2(patch) {
|
|
906
1004
|
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;
|
|
907
1005
|
}
|
|
908
1006
|
var object = (config) => {
|
|
@@ -915,14 +1013,25 @@ var object = (config) => {
|
|
|
915
1013
|
type: "object",
|
|
916
1014
|
components: {
|
|
917
1015
|
// @ts-expect-error - fix typings
|
|
918
|
-
item: InternationalizedInput
|
|
1016
|
+
item: InternationalizedInput,
|
|
1017
|
+
field: (props) => props.renderDefault({
|
|
1018
|
+
...props,
|
|
1019
|
+
// Reset the level to avoid nested styling
|
|
1020
|
+
level: 0
|
|
1021
|
+
})
|
|
919
1022
|
},
|
|
920
1023
|
fields: [
|
|
921
1024
|
defineField({
|
|
922
1025
|
...typeof type == "string" ? {
|
|
923
1026
|
type
|
|
924
1027
|
} : type,
|
|
925
|
-
name: "value"
|
|
1028
|
+
name: "value",
|
|
1029
|
+
components: {
|
|
1030
|
+
field: (props) => props.renderDefault({
|
|
1031
|
+
...props,
|
|
1032
|
+
title: ""
|
|
1033
|
+
})
|
|
1034
|
+
}
|
|
926
1035
|
}),
|
|
927
1036
|
// Hidden language field - stores the language identifier (e.g., 'en', 'fr')
|
|
928
1037
|
// This replaces the previous pattern of storing language in _key
|
|
@@ -941,37 +1050,7 @@ var object = (config) => {
|
|
|
941
1050
|
}
|
|
942
1051
|
});
|
|
943
1052
|
};
|
|
944
|
-
|
|
945
|
-
return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
|
|
946
|
-
}
|
|
947
|
-
function extractInnerFields(fields, path, maxDepth) {
|
|
948
|
-
return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
|
|
949
|
-
const thisFieldWithPath = {
|
|
950
|
-
path: [...path, field.name],
|
|
951
|
-
...field
|
|
952
|
-
};
|
|
953
|
-
if (field.type.jsonType === "object") {
|
|
954
|
-
const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth);
|
|
955
|
-
return acc.push(thisFieldWithPath, ...innerFields), acc;
|
|
956
|
-
} else if (field.type.jsonType === "array" && field.type.of.length && field.type.of.some((item) => "fields" in item)) {
|
|
957
|
-
const innerFields = field.type.of.flatMap((innerField) => extractInnerFields(
|
|
958
|
-
// @ts-expect-error - Fix TS assertion for array fields
|
|
959
|
-
innerField.fields,
|
|
960
|
-
[...path, field.name],
|
|
961
|
-
maxDepth
|
|
962
|
-
));
|
|
963
|
-
return acc.push(thisFieldWithPath, ...innerFields), acc;
|
|
964
|
-
}
|
|
965
|
-
return acc.push(thisFieldWithPath), acc;
|
|
966
|
-
}, []);
|
|
967
|
-
}
|
|
968
|
-
const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLanguageIds, parentValue) => {
|
|
969
|
-
if (isInternationalizedArrayItemType(enclosingType.name)) {
|
|
970
|
-
const language = typeof parentValue?.language == "string" ? parentValue?.language : null;
|
|
971
|
-
return language ? selectedLanguageIds.includes(language) : !1;
|
|
972
|
-
}
|
|
973
|
-
return !0;
|
|
974
|
-
}, internationalizedArray = definePlugin((config) => {
|
|
1053
|
+
const internationalizedArray = definePlugin((config) => {
|
|
975
1054
|
const pluginConfig = {
|
|
976
1055
|
...CONFIG_DEFAULT,
|
|
977
1056
|
...config
|
|
@@ -996,13 +1075,15 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
|
|
|
996
1075
|
},
|
|
997
1076
|
// Optional: render "add language" buttons as field actions
|
|
998
1077
|
document: {
|
|
1078
|
+
components: {
|
|
1079
|
+
unstable_layout: (props) => /* @__PURE__ */ jsx(InternationalizedArrayLayout, { ...props, pluginConfig })
|
|
1080
|
+
},
|
|
999
1081
|
unstable_fieldActions: buttonLocations.includes("unstable__fieldAction") ? (prev) => [...prev, internationalizedArrayFieldAction] : void 0
|
|
1000
1082
|
},
|
|
1001
1083
|
// Wrap document editor with a language provider
|
|
1002
1084
|
form: {
|
|
1003
1085
|
components: {
|
|
1004
|
-
|
|
1005
|
-
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 })
|
|
1086
|
+
input: (props) => props.id === "root" && isObjectInputProps(props) && hasInternationalizedArrayField(props.schemaType) && pluginConfig.includeForDocumentType(props.schemaType.name) ? /* @__PURE__ */ jsx(InternationalizedArrayFormInput, { ...props, pluginConfig }) : props.renderDefault(props)
|
|
1006
1087
|
}
|
|
1007
1088
|
},
|
|
1008
1089
|
// Register custom schema types for the outer array and the inner object
|
|
@@ -1018,8 +1099,10 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
|
|
|
1018
1099
|
},
|
|
1019
1100
|
plugins: languageFilterConfig?.documentTypes?.length > 0 ? [languageFilter({
|
|
1020
1101
|
documentTypes: languageFilterConfig.documentTypes,
|
|
1021
|
-
supportedLanguages: languages
|
|
1022
|
-
filterField
|
|
1102
|
+
supportedLanguages: languages
|
|
1103
|
+
// This is specifically not adding filterField avoid the default filter field implementation.
|
|
1104
|
+
// It will be filtered in `internationalizedArray` component and will have access to the resolved languages.
|
|
1105
|
+
// Rendering the fields if the language key is incorrect, providing an improved UX
|
|
1023
1106
|
})] : void 0
|
|
1024
1107
|
};
|
|
1025
1108
|
});
|