sanity-plugin-internationalized-array 5.0.0-canary.1 → 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/README.md +76 -3
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +435 -359
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +8 -8
- package/package.json +15 -9
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,166 @@ 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;
|
|
297
295
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
+
}
|
|
305
311
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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;
|
|
320
|
+
}
|
|
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
|
|
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,76 +507,52 @@ function Feedback() {
|
|
|
484
507
|
] }) }), $[3] = t3) : t3 = $[3], t3;
|
|
485
508
|
}
|
|
486
509
|
function MigrationBanner(t0) {
|
|
487
|
-
const $ = c(
|
|
488
|
-
|
|
489
|
-
languages
|
|
510
|
+
const $ = c(11), {
|
|
511
|
+
itemsNeedingMigration
|
|
490
512
|
} = 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))
|
|
513
|
+
if (!itemsNeedingMigration.length)
|
|
512
514
|
return null;
|
|
513
|
-
let
|
|
514
|
-
$[
|
|
515
|
-
let
|
|
516
|
-
$[
|
|
517
|
-
const
|
|
518
|
-
let
|
|
519
|
-
$[
|
|
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";
|
|
520
|
+
let t5;
|
|
521
|
+
$[2] !== itemsNeedingMigration.length || $[3] !== t3 || $[4] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
|
|
520
522
|
itemsNeedingMigration.length,
|
|
521
523
|
" item",
|
|
522
|
-
|
|
524
|
+
t3,
|
|
523
525
|
" ",
|
|
524
|
-
|
|
526
|
+
t4,
|
|
525
527
|
" to be migrated to the v5 format."
|
|
526
|
-
] }), $[
|
|
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];
|
|
527
533
|
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: [
|
|
534
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
533
535
|
"This field still uses the v4 format where language is stored in ",
|
|
534
|
-
|
|
536
|
+
t6,
|
|
535
537
|
". Migrate to the v5 format where language is stored in ",
|
|
536
|
-
|
|
538
|
+
t7,
|
|
537
539
|
".",
|
|
538
540
|
" ",
|
|
539
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" }),
|
|
540
542
|
"."
|
|
541
|
-
] }) }), $[
|
|
542
|
-
let
|
|
543
|
-
return $[
|
|
544
|
-
|
|
543
|
+
] }) }), $[8] = t8) : t8 = $[8];
|
|
544
|
+
let t9;
|
|
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,
|
|
545
547
|
/* @__PURE__ */ jsxs(Stack, { space: 2, flex: 1, children: [
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
548
|
+
t2,
|
|
549
|
+
t5,
|
|
550
|
+
t8
|
|
549
551
|
] })
|
|
550
|
-
] }) }), $[
|
|
551
|
-
}
|
|
552
|
-
function _temp$2(l) {
|
|
553
|
-
return l.id;
|
|
552
|
+
] }) }), $[9] = t5, $[10] = t9) : t9 = $[10], t9;
|
|
554
553
|
}
|
|
555
554
|
function InternationalizedArray(props) {
|
|
556
|
-
const $ = c(
|
|
555
|
+
const $ = c(102), {
|
|
557
556
|
members,
|
|
558
557
|
value: _value,
|
|
559
558
|
schemaType,
|
|
@@ -562,12 +561,13 @@ function InternationalizedArray(props) {
|
|
|
562
561
|
} = props, value = _value;
|
|
563
562
|
let t0;
|
|
564
563
|
$[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(), {
|
|
564
|
+
const itemsNeedingMigration = t0, shouldMigrateArray = itemsNeedingMigration.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), getFormValue = useGetFormValue(), {
|
|
566
565
|
languages,
|
|
567
566
|
filteredLanguages,
|
|
568
567
|
defaultLanguages,
|
|
569
568
|
buttonAddAll,
|
|
570
|
-
buttonLocations
|
|
569
|
+
buttonLocations,
|
|
570
|
+
languageFilter: builtInLanguageFilter
|
|
571
571
|
} = useInternationalizedArrayContext(), {
|
|
572
572
|
selectedLanguageIds,
|
|
573
573
|
options: languageFilterOptions
|
|
@@ -577,17 +577,21 @@ function InternationalizedArray(props) {
|
|
|
577
577
|
const documentType = useFormValue(t1);
|
|
578
578
|
let t2;
|
|
579
579
|
$[3] !== documentType || $[4] !== languageFilterOptions ? (t2 = typeof documentType == "string" && languageFilterOptions.documentTypes.includes(documentType), $[3] = documentType, $[4] = languageFilterOptions, $[5] = t2) : t2 = $[5];
|
|
580
|
-
const
|
|
580
|
+
const usingLanguageFilterPlugin = t2;
|
|
581
581
|
let t3;
|
|
582
|
-
$[6] !==
|
|
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) => {
|
|
583
586
|
if (member.kind !== "item")
|
|
584
587
|
return !1;
|
|
585
588
|
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
|
-
$[
|
|
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);
|
|
591
595
|
if (!filteredLanguages?.length)
|
|
592
596
|
return;
|
|
593
597
|
const patches = createAddLanguagePatches({
|
|
@@ -595,139 +599,144 @@ function InternationalizedArray(props) {
|
|
|
595
599
|
schemaTypeName: schemaType.name,
|
|
596
600
|
languages,
|
|
597
601
|
filteredLanguages,
|
|
598
|
-
value
|
|
602
|
+
value: formValue
|
|
599
603
|
});
|
|
600
604
|
onChange([setIfMissing([]), ...patches]);
|
|
601
|
-
}, $[
|
|
602
|
-
const
|
|
605
|
+
}, $[16] = filteredLanguages, $[17] = getFormValue, $[18] = languages, $[19] = onChange, $[20] = props.path, $[21] = schemaType.name, $[22] = t5) : t5 = $[22];
|
|
606
|
+
const handleAddLanguages = t5, {
|
|
603
607
|
isDeleting
|
|
604
608
|
} = 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
609
|
let t6;
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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;
|
|
630
629
|
} else
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
let
|
|
634
|
-
$[
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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);
|
|
638
638
|
});
|
|
639
639
|
return () => clearTimeout(timeout);
|
|
640
640
|
}
|
|
641
|
-
},
|
|
642
|
-
let
|
|
643
|
-
$[
|
|
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 = () => {
|
|
644
644
|
if (!value?.length || !languages?.length)
|
|
645
645
|
return;
|
|
646
646
|
const updatedValue = value.reduce((acc, v_1) => {
|
|
647
|
-
const newIndex = languages.findIndex((
|
|
647
|
+
const newIndex = languages.findIndex((l_3) => l_3.id === v_1?.[LANGUAGE_FIELD_NAME]);
|
|
648
648
|
return newIndex > -1 && (acc[newIndex] = v_1), acc;
|
|
649
649
|
}, []).filter(Boolean);
|
|
650
650
|
value?.length !== updatedValue.length && toast.push({
|
|
651
651
|
title: "There was an error reordering languages",
|
|
652
652
|
status: "warning"
|
|
653
653
|
}), onChange(set(updatedValue));
|
|
654
|
-
}, $[
|
|
655
|
-
const handleRestoreOrder =
|
|
656
|
-
let
|
|
654
|
+
}, $[39] = languages, $[40] = onChange, $[41] = toast, $[42] = value, $[43] = t10) : t10 = $[43];
|
|
655
|
+
const handleRestoreOrder = t10;
|
|
656
|
+
let t11;
|
|
657
657
|
bb1: {
|
|
658
658
|
if (!value?.length || !languages?.length) {
|
|
659
|
-
|
|
659
|
+
t11 = !0;
|
|
660
660
|
break bb1;
|
|
661
661
|
}
|
|
662
|
-
let
|
|
663
|
-
$[
|
|
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;
|
|
664
664
|
}
|
|
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;
|
|
665
|
+
const allKeysAreLanguages = t11;
|
|
669
666
|
let t12;
|
|
670
667
|
bb2: {
|
|
671
|
-
if (!value?.length || !
|
|
668
|
+
if (!value?.length || !addedLanguages.length) {
|
|
672
669
|
let t133;
|
|
673
|
-
$[
|
|
670
|
+
$[47] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t133 = [], $[47] = t133) : t133 = $[47], t12 = t133;
|
|
674
671
|
break bb2;
|
|
675
672
|
}
|
|
676
673
|
let t132;
|
|
677
|
-
if ($[
|
|
674
|
+
if ($[48] !== addedLanguages || $[49] !== value) {
|
|
678
675
|
let t142;
|
|
679
|
-
$[
|
|
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;
|
|
680
677
|
} else
|
|
681
|
-
t132 = $[
|
|
678
|
+
t132 = $[50];
|
|
682
679
|
t12 = t132;
|
|
683
680
|
}
|
|
684
681
|
const languagesOutOfOrder = t12, languagesAreValid = !languages?.length || languages?.length && languages.every(_temp4$1);
|
|
685
682
|
let t13;
|
|
686
|
-
$[
|
|
683
|
+
$[53] !== allKeysAreLanguages || $[54] !== documentReadOnly || $[55] !== handleRestoreOrder || $[56] !== languagesOutOfOrder.length ? (t13 = () => {
|
|
687
684
|
languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
|
|
688
|
-
}, $[
|
|
685
|
+
}, $[53] = allKeysAreLanguages, $[54] = documentReadOnly, $[55] = handleRestoreOrder, $[56] = languagesOutOfOrder.length, $[57] = t13) : t13 = $[57];
|
|
689
686
|
let t14;
|
|
690
|
-
$[
|
|
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);
|
|
691
688
|
let t15;
|
|
692
|
-
$[
|
|
689
|
+
$[63] !== filteredLanguages || $[64] !== value ? (t15 = checkAllLanguagesArePresent(filteredLanguages, value), $[63] = filteredLanguages, $[64] = value, $[65] = t15) : t15 = $[65];
|
|
693
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;
|
|
694
696
|
if (!languagesAreValid) {
|
|
695
|
-
let
|
|
696
|
-
return $[
|
|
697
|
+
let t172;
|
|
698
|
+
return $[69] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t172 = /* @__PURE__ */ jsx(Feedback, {}), $[69] = t172) : t172 = $[69], t172;
|
|
697
699
|
}
|
|
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
700
|
let t17;
|
|
702
|
-
$[
|
|
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;
|
|
703
703
|
let t18;
|
|
704
|
-
$[
|
|
704
|
+
$[75] !== filteredLanguages || $[76] !== value ? (t18 = createAddAllTitle(value, filteredLanguages), $[75] = filteredLanguages, $[76] = value, $[77] = t18) : t18 = $[77];
|
|
705
|
+
const addAllTitle = t18;
|
|
705
706
|
let t19;
|
|
706
|
-
$[
|
|
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];
|
|
707
712
|
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];
|
|
713
|
+
$[83] !== itemsNeedingMigration ? (t20 = /* @__PURE__ */ jsx(MigrationBanner, { itemsNeedingMigration }), $[83] = itemsNeedingMigration, $[84] = t20) : t20 = $[84];
|
|
712
714
|
let t21;
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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: [
|
|
716
723
|
t19,
|
|
717
|
-
t20
|
|
718
|
-
|
|
724
|
+
t20,
|
|
725
|
+
t21,
|
|
726
|
+
t22
|
|
727
|
+
] }), $[97] = t19, $[98] = t20, $[99] = t21, $[100] = t22, $[101] = t23) : t23 = $[101], t23;
|
|
719
728
|
}
|
|
720
|
-
function _temp5(
|
|
721
|
-
return
|
|
729
|
+
function _temp5(language_4) {
|
|
730
|
+
return language_4.id;
|
|
722
731
|
}
|
|
723
732
|
function _temp4$1(item) {
|
|
724
733
|
return item.id && item.title;
|
|
725
734
|
}
|
|
726
|
-
function _temp3$1(
|
|
727
|
-
return
|
|
735
|
+
function _temp3$1(l_0) {
|
|
736
|
+
return l_0.id;
|
|
728
737
|
}
|
|
729
|
-
function _temp2$1(
|
|
730
|
-
return
|
|
738
|
+
function _temp2$1(v_0) {
|
|
739
|
+
return v_0[LANGUAGE_FIELD_NAME] ?? v_0._key;
|
|
731
740
|
}
|
|
732
741
|
function _temp$1(v) {
|
|
733
742
|
return !v[LANGUAGE_FIELD_NAME];
|
|
@@ -747,6 +756,11 @@ var array = (config) => {
|
|
|
747
756
|
title: "Internationalized array",
|
|
748
757
|
type: "array",
|
|
749
758
|
components: {
|
|
759
|
+
field: (props) => props.renderDefault({
|
|
760
|
+
...props,
|
|
761
|
+
// Reset the level to avoid nested styling
|
|
762
|
+
level: 0
|
|
763
|
+
}),
|
|
750
764
|
input: InternationalizedArray
|
|
751
765
|
},
|
|
752
766
|
options: {
|
|
@@ -825,72 +839,149 @@ function getToneFromValidation(validations) {
|
|
|
825
839
|
if (validationLevels.has("warning"))
|
|
826
840
|
return "caution";
|
|
827
841
|
}
|
|
828
|
-
function
|
|
829
|
-
const $ = c(
|
|
842
|
+
function ChangeLanguageButton(props) {
|
|
843
|
+
const $ = c(24), {
|
|
844
|
+
value,
|
|
845
|
+
onChange,
|
|
846
|
+
path
|
|
847
|
+
} = props;
|
|
830
848
|
let t0;
|
|
831
|
-
$[0] !==
|
|
832
|
-
const parentValue = useFormValue(t0),
|
|
849
|
+
$[0] !== path ? (t0 = path.slice(0, -1), $[0] = path, $[1] = t0) : t0 = $[1];
|
|
850
|
+
const parentValue = useFormValue(t0), {
|
|
851
|
+
languages
|
|
852
|
+
} = useInternationalizedArrayContext();
|
|
853
|
+
let t1;
|
|
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;
|
|
833
889
|
let t1;
|
|
834
|
-
$[
|
|
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) => {
|
|
835
906
|
if (!Array.isArray(patches))
|
|
836
907
|
return originalOnChange(patches);
|
|
837
908
|
const valueField = props.value?.value;
|
|
838
|
-
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(
|
|
909
|
+
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp2)) {
|
|
839
910
|
const initPatch = valueField === void 0 ? {
|
|
840
911
|
type: "setIfMissing",
|
|
841
912
|
path: ["value"],
|
|
842
913
|
value: []
|
|
843
|
-
} : null, fixedPatches = patches.map(
|
|
914
|
+
} : null, fixedPatches = patches.map(_temp3), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
|
|
844
915
|
return originalOnChange(allPatches);
|
|
845
916
|
}
|
|
846
917
|
return originalOnChange(patches);
|
|
847
|
-
}, $[
|
|
848
|
-
const wrappedOnChange =
|
|
849
|
-
|
|
850
|
-
|
|
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,
|
|
851
926
|
value: props.value,
|
|
852
927
|
onChange: wrappedOnChange
|
|
853
|
-
},
|
|
928
|
+
}, $[5] = props.inputProps, $[6] = props.value, $[7] = t2, $[8] = wrappedOnChange, $[9] = t3) : t3 = $[9];
|
|
929
|
+
const inlineProps = t3, {
|
|
854
930
|
validation,
|
|
855
931
|
value,
|
|
856
|
-
onChange,
|
|
857
932
|
readOnly
|
|
858
933
|
} = inlineProps, {
|
|
859
934
|
languages,
|
|
860
935
|
languageDisplay,
|
|
861
936
|
defaultLanguages
|
|
862
937
|
} = 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
|
-
};
|
|
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];
|
|
871
941
|
if (!languages) {
|
|
872
|
-
let
|
|
873
|
-
return $[
|
|
942
|
+
let t52;
|
|
943
|
+
return $[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t52 = /* @__PURE__ */ jsx(Spinner, {}), $[13] = t52) : t52 = $[13], t52;
|
|
874
944
|
}
|
|
875
|
-
|
|
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;
|
|
876
957
|
let t7;
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
|
|
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;
|
|
889
980
|
}
|
|
890
|
-
function
|
|
981
|
+
function _temp4(m) {
|
|
891
982
|
return m.kind === "field" && m.name === "value";
|
|
892
983
|
}
|
|
893
|
-
function
|
|
984
|
+
function _temp3(patch_0) {
|
|
894
985
|
if (!patch_0 || typeof patch_0 != "object")
|
|
895
986
|
return patch_0;
|
|
896
987
|
if (patch_0.type === "insert" && patch_0.path && Array.isArray(patch_0.path)) {
|
|
@@ -902,7 +993,7 @@ function _temp2(patch_0) {
|
|
|
902
993
|
}
|
|
903
994
|
return patch_0;
|
|
904
995
|
}
|
|
905
|
-
function
|
|
996
|
+
function _temp2(patch) {
|
|
906
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;
|
|
907
998
|
}
|
|
908
999
|
var object = (config) => {
|
|
@@ -915,14 +1006,25 @@ var object = (config) => {
|
|
|
915
1006
|
type: "object",
|
|
916
1007
|
components: {
|
|
917
1008
|
// @ts-expect-error - fix typings
|
|
918
|
-
item: InternationalizedInput
|
|
1009
|
+
item: InternationalizedInput,
|
|
1010
|
+
field: (props) => props.renderDefault({
|
|
1011
|
+
...props,
|
|
1012
|
+
// Reset the level to avoid nested styling
|
|
1013
|
+
level: 0
|
|
1014
|
+
})
|
|
919
1015
|
},
|
|
920
1016
|
fields: [
|
|
921
1017
|
defineField({
|
|
922
1018
|
...typeof type == "string" ? {
|
|
923
1019
|
type
|
|
924
1020
|
} : type,
|
|
925
|
-
name: "value"
|
|
1021
|
+
name: "value",
|
|
1022
|
+
components: {
|
|
1023
|
+
field: (props) => props.renderDefault({
|
|
1024
|
+
...props,
|
|
1025
|
+
title: ""
|
|
1026
|
+
})
|
|
1027
|
+
}
|
|
926
1028
|
}),
|
|
927
1029
|
// Hidden language field - stores the language identifier (e.g., 'en', 'fr')
|
|
928
1030
|
// This replaces the previous pattern of storing language in _key
|
|
@@ -941,37 +1043,7 @@ var object = (config) => {
|
|
|
941
1043
|
}
|
|
942
1044
|
});
|
|
943
1045
|
};
|
|
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) => {
|
|
1046
|
+
const internationalizedArray = definePlugin((config) => {
|
|
975
1047
|
const pluginConfig = {
|
|
976
1048
|
...CONFIG_DEFAULT,
|
|
977
1049
|
...config
|
|
@@ -996,13 +1068,15 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
|
|
|
996
1068
|
},
|
|
997
1069
|
// Optional: render "add language" buttons as field actions
|
|
998
1070
|
document: {
|
|
1071
|
+
components: {
|
|
1072
|
+
unstable_layout: (props) => /* @__PURE__ */ jsx(InternationalizedArrayLayout, { ...props, pluginConfig })
|
|
1073
|
+
},
|
|
999
1074
|
unstable_fieldActions: buttonLocations.includes("unstable__fieldAction") ? (prev) => [...prev, internationalizedArrayFieldAction] : void 0
|
|
1000
1075
|
},
|
|
1001
1076
|
// Wrap document editor with a language provider
|
|
1002
1077
|
form: {
|
|
1003
1078
|
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 })
|
|
1079
|
+
input: (props) => props.id === "root" && isObjectInputProps(props) && hasInternationalizedArrayField(props.schemaType) && pluginConfig.includeForDocumentType(props.schemaType.name) ? /* @__PURE__ */ jsx(InternationalizedArrayFormInput, { ...props, pluginConfig }) : props.renderDefault(props)
|
|
1006
1080
|
}
|
|
1007
1081
|
},
|
|
1008
1082
|
// Register custom schema types for the outer array and the inner object
|
|
@@ -1018,8 +1092,10 @@ const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLa
|
|
|
1018
1092
|
},
|
|
1019
1093
|
plugins: languageFilterConfig?.documentTypes?.length > 0 ? [languageFilter({
|
|
1020
1094
|
documentTypes: languageFilterConfig.documentTypes,
|
|
1021
|
-
supportedLanguages: languages
|
|
1022
|
-
filterField
|
|
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
|
|
1023
1099
|
})] : void 0
|
|
1024
1100
|
};
|
|
1025
1101
|
});
|