sanity-plugin-internationalized-array 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +374 -274
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useClient, useWorkspace, useGetFormValue, useSchema, isSanityDocument, setIfMissing, insert, PatchEvent, isDocumentSchemaType, defineDocumentFieldAction, useFormValue, set, ArrayOfObjectsItem, MemberItemError, defineField, unset, definePlugin, isObjectInputProps } from "sanity";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Spinner, Label, MenuButton, Menu, MenuItem, Flex, Tooltip } from "@sanity/ui";
|
|
6
|
-
import { createContext, useContext, useDeferredValue, use, useCallback, useEffect, createElement } from "react";
|
|
4
|
+
import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Spinner, Label, Flex, MenuButton, Tooltip, MenuItem, Menu } from "@sanity/ui";
|
|
7
5
|
import { useDocumentPane } from "sanity/structure";
|
|
8
6
|
import { AddIcon, TranslateIcon, RemoveCircleIcon } from "@sanity/icons";
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { useLanguageFilterStudioContext } from "@sanity/language-filter";
|
|
8
|
+
import { createContext, useContext, useDeferredValue, use, useCallback, useEffect, createElement } from "react";
|
|
9
|
+
import get from "lodash-es/get.js";
|
|
10
|
+
import camelCase from "lodash-es/camelCase.js";
|
|
11
|
+
import upperFirst from "lodash-es/upperFirst.js";
|
|
12
|
+
const namespace = "sanity-plugin-internationalized-array", functionKeyCache = /* @__PURE__ */ new WeakMap(), promiseCache = /* @__PURE__ */ new Map(), functionCache = /* @__PURE__ */ new Map();
|
|
11
13
|
function stringifyCacheKey(key) {
|
|
12
14
|
return JSON.stringify(key);
|
|
13
15
|
}
|
|
@@ -63,7 +65,8 @@ const preloadWithKey = (fn, key) => {
|
|
|
63
65
|
apiVersion: "2025-10-15",
|
|
64
66
|
buttonLocations: ["field"],
|
|
65
67
|
buttonAddAll: !0,
|
|
66
|
-
languageDisplay: "codeOnly"
|
|
68
|
+
languageDisplay: "codeOnly",
|
|
69
|
+
includeForDocumentType: (documentType) => documentType !== "translation.metadata"
|
|
67
70
|
}, getDocumentsToTranslate = (value, rootPath = []) => {
|
|
68
71
|
if (Array.isArray(value)) {
|
|
69
72
|
const arrayRootPath = [...rootPath], internationalizedValues = value.filter((item) => {
|
|
@@ -91,84 +94,6 @@ const preloadWithKey = (fn, key) => {
|
|
|
91
94
|
function getLanguageDisplay(languageDisplay, title, code) {
|
|
92
95
|
return languageDisplay === "codeOnly" ? code.toUpperCase() : languageDisplay === "titleOnly" ? title : languageDisplay === "titleAndCode" ? `${title} (${code.toUpperCase()})` : title;
|
|
93
96
|
}
|
|
94
|
-
function AddButtons(props) {
|
|
95
|
-
const $ = c(6), {
|
|
96
|
-
languages,
|
|
97
|
-
readOnly,
|
|
98
|
-
value,
|
|
99
|
-
handleClick
|
|
100
|
-
} = props, {
|
|
101
|
-
languageDisplay
|
|
102
|
-
} = useInternationalizedArrayContext();
|
|
103
|
-
let t0;
|
|
104
|
-
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, children: languages.map((language) => {
|
|
105
|
-
const languageTitle = getLanguageDisplay(languageDisplay, language.title, language.id);
|
|
106
|
-
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);
|
|
107
|
-
}) }) : null, $[0] = handleClick, $[1] = languageDisplay, $[2] = languages, $[3] = readOnly, $[4] = value, $[5] = t0) : t0 = $[5], t0;
|
|
108
|
-
}
|
|
109
|
-
function DocumentAddButtons(props) {
|
|
110
|
-
const $ = c(13), {
|
|
111
|
-
filteredLanguages
|
|
112
|
-
} = useInternationalizedArrayContext(), value = isSanityDocument(props.value) ? props.value : void 0, toast = useToast(), {
|
|
113
|
-
onChange
|
|
114
|
-
} = useDocumentPane(), schema = useSchema();
|
|
115
|
-
let t0;
|
|
116
|
-
$[0] !== value ? (t0 = getDocumentsToTranslate(value, []), $[0] = value, $[1] = t0) : t0 = $[1];
|
|
117
|
-
const documentsToTranslation = t0;
|
|
118
|
-
let t1;
|
|
119
|
-
$[2] !== schema ? (t1 = (typeName) => {
|
|
120
|
-
if (!typeName)
|
|
121
|
-
return;
|
|
122
|
-
const match = typeName.match(/^internationalizedArray(.+)Value$/);
|
|
123
|
-
if (!match || !match[1])
|
|
124
|
-
return;
|
|
125
|
-
const baseTypeName = match[1].charAt(0).toLowerCase() + match[1].slice(1), arrayBasedTypes = /* @__PURE__ */ new Set(["body", "htmlContent", "blockContent", "portableText"]);
|
|
126
|
-
if (arrayBasedTypes.has(baseTypeName))
|
|
127
|
-
return [];
|
|
128
|
-
const schemaType = schema.get(typeName);
|
|
129
|
-
if (schemaType && "fields" in schemaType) {
|
|
130
|
-
const valueField = schemaType.fields.find(_temp$2);
|
|
131
|
-
if (valueField) {
|
|
132
|
-
const fieldType = valueField.type;
|
|
133
|
-
if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || fieldType?.name && arrayBasedTypes.has(fieldType.name))
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}, $[2] = schema, $[3] = t1) : t1 = $[3];
|
|
138
|
-
const getInitialValueForType = t1;
|
|
139
|
-
let t2;
|
|
140
|
-
$[4] !== documentsToTranslation || $[5] !== getInitialValueForType || $[6] !== onChange || $[7] !== toast ? (t2 = async (languageId) => {
|
|
141
|
-
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), []);
|
|
142
|
-
if (removeDuplicates.length === 0) {
|
|
143
|
-
toast.push({
|
|
144
|
-
status: "error",
|
|
145
|
-
title: "No internationalizedArray fields found in document root"
|
|
146
|
-
});
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const patches = [];
|
|
150
|
-
for (const toTranslate of removeDuplicates) {
|
|
151
|
-
const path = toTranslate.path, initialValue = getInitialValueForType(toTranslate._type), ifMissing = setIfMissing([], path), insertValue = insert([{
|
|
152
|
-
[LANGUAGE_FIELD_NAME]: languageId,
|
|
153
|
-
_type: toTranslate._type,
|
|
154
|
-
value: initialValue
|
|
155
|
-
}], "after", [...path, -1]);
|
|
156
|
-
patches.push(ifMissing), patches.push(insertValue);
|
|
157
|
-
}
|
|
158
|
-
onChange(PatchEvent.from(patches.flat()));
|
|
159
|
-
}, $[4] = documentsToTranslation, $[5] = getInitialValueForType, $[6] = onChange, $[7] = toast, $[8] = t2) : t2 = $[8];
|
|
160
|
-
const handleDocumentButtonClick = t2;
|
|
161
|
-
let t3;
|
|
162
|
-
$[9] === /* @__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" }) }), $[9] = t3) : t3 = $[9];
|
|
163
|
-
let t4;
|
|
164
|
-
return $[10] !== filteredLanguages || $[11] !== handleDocumentButtonClick ? (t4 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
165
|
-
t3,
|
|
166
|
-
/* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, readOnly: !1, value: void 0, handleClick: handleDocumentButtonClick })
|
|
167
|
-
] }), $[10] = filteredLanguages, $[11] = handleDocumentButtonClick, $[12] = t4) : t4 = $[12], t4;
|
|
168
|
-
}
|
|
169
|
-
function _temp$2(f) {
|
|
170
|
-
return f.name === "value";
|
|
171
|
-
}
|
|
172
97
|
const getSelectedValue = (select, document) => {
|
|
173
98
|
if (!select || !document)
|
|
174
99
|
return {};
|
|
@@ -187,8 +112,9 @@ function useInternationalizedArrayContext() {
|
|
|
187
112
|
return useContext(InternationalizedArrayContext);
|
|
188
113
|
}
|
|
189
114
|
function InternationalizedArrayProvider(props) {
|
|
190
|
-
const $ = c(
|
|
191
|
-
internationalizedArray: internationalizedArray2
|
|
115
|
+
const $ = c(33), {
|
|
116
|
+
internationalizedArray: internationalizedArray2,
|
|
117
|
+
documentType
|
|
192
118
|
} = props;
|
|
193
119
|
let t0;
|
|
194
120
|
$[0] !== internationalizedArray2.apiVersion ? (t0 = {
|
|
@@ -237,73 +163,162 @@ function InternationalizedArrayProvider(props) {
|
|
|
237
163
|
const languagesPromise = t4, languages = languagesPromise ? use(languagesPromise) : internationalizedArray2.languages, {
|
|
238
164
|
selectedLanguageIds,
|
|
239
165
|
options: languageFilterOptions
|
|
240
|
-
} = useLanguageFilterStudioContext()
|
|
166
|
+
} = useLanguageFilterStudioContext();
|
|
241
167
|
let t5;
|
|
242
|
-
$[19] !== documentType || $[20] !== languageFilterOptions ? (t5 =
|
|
168
|
+
$[19] !== documentType || $[20] !== languageFilterOptions.documentTypes ? (t5 = languageFilterOptions.documentTypes.includes(documentType), $[19] = documentType, $[20] = languageFilterOptions.documentTypes, $[21] = t5) : t5 = $[21];
|
|
243
169
|
const languageFilterEnabled = t5;
|
|
244
170
|
let t6;
|
|
245
171
|
$[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];
|
|
246
172
|
const filteredLanguages = t6;
|
|
247
173
|
let t7;
|
|
248
|
-
$[26] !==
|
|
249
|
-
const showDocumentButtons = t7;
|
|
250
|
-
let t8;
|
|
251
|
-
$[28] !== filteredLanguages || $[29] !== internationalizedArray2 || $[30] !== languages ? (t8 = {
|
|
174
|
+
$[26] !== filteredLanguages || $[27] !== internationalizedArray2 || $[28] !== languages ? (t7 = {
|
|
252
175
|
...internationalizedArray2,
|
|
253
176
|
languages,
|
|
254
177
|
filteredLanguages
|
|
255
|
-
}, $[
|
|
256
|
-
const context =
|
|
257
|
-
let
|
|
258
|
-
$[
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
"_type" in fieldParent && typeof fieldParent._type == "string" && fieldParent._type.startsWith("internationalizedArray") && // Checks if the language field name is in the field and if it's a string
|
|
269
|
-
LANGUAGE_FIELD_NAME in fieldParent && typeof fieldParent[LANGUAGE_FIELD_NAME] == "string" ? fieldParent[LANGUAGE_FIELD_NAME] : void 0;
|
|
270
|
-
} catch (error) {
|
|
271
|
-
console.error("Error getting language id", error);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
function InternationalizedField(props) {
|
|
276
|
-
const $ = c(11), {
|
|
277
|
-
languages
|
|
178
|
+
}, $[26] = filteredLanguages, $[27] = internationalizedArray2, $[28] = languages, $[29] = t7) : t7 = $[29];
|
|
179
|
+
const context = t7;
|
|
180
|
+
let t8;
|
|
181
|
+
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;
|
|
182
|
+
}
|
|
183
|
+
function AddButtons(props) {
|
|
184
|
+
const $ = c(15), {
|
|
185
|
+
readOnly,
|
|
186
|
+
languagesInUse,
|
|
187
|
+
handleClick
|
|
188
|
+
} = props, {
|
|
189
|
+
languageDisplay,
|
|
190
|
+
filteredLanguages: languages
|
|
278
191
|
} = useInternationalizedArrayContext();
|
|
192
|
+
if (!languages.length)
|
|
193
|
+
return null;
|
|
194
|
+
const t0 = Math.min(languages.length, MAX_COLUMNS[languageDisplay]);
|
|
195
|
+
let t1;
|
|
196
|
+
if ($[0] !== handleClick || $[1] !== languageDisplay || $[2] !== languages || $[3] !== languagesInUse || $[4] !== readOnly) {
|
|
197
|
+
let t22;
|
|
198
|
+
$[6] !== handleClick || $[7] !== languageDisplay || $[8] !== languages.length || $[9] !== languagesInUse || $[10] !== readOnly ? (t22 = (language) => {
|
|
199
|
+
const languageTitle = getLanguageDisplay(languageDisplay, language.title, language.id);
|
|
200
|
+
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);
|
|
201
|
+
}, $[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;
|
|
202
|
+
} else
|
|
203
|
+
t1 = $[5];
|
|
204
|
+
let t2;
|
|
205
|
+
return $[12] !== t0 || $[13] !== t1 ? (t2 = /* @__PURE__ */ jsx(Grid, { columns: t0, gap: 2, children: t1 }), $[12] = t0, $[13] = t1, $[14] = t2) : t2 = $[14], t2;
|
|
206
|
+
}
|
|
207
|
+
function DocumentAddButtons() {
|
|
208
|
+
const $ = c(11), getFormValue = useGetFormValue(), toast = useToast(), {
|
|
209
|
+
onChange
|
|
210
|
+
} = useDocumentPane(), schema = useSchema();
|
|
279
211
|
let t0;
|
|
280
|
-
$[0] !==
|
|
281
|
-
|
|
212
|
+
$[0] !== schema ? (t0 = (typeName) => {
|
|
213
|
+
if (!typeName)
|
|
214
|
+
return;
|
|
215
|
+
const match = typeName.match(/^internationalizedArray(.+)Value$/);
|
|
216
|
+
if (!match || !match[1])
|
|
217
|
+
return;
|
|
218
|
+
const baseTypeName = match[1].charAt(0).toLowerCase() + match[1].slice(1), arrayBasedTypes = /* @__PURE__ */ new Set(["body", "htmlContent", "blockContent", "portableText"]);
|
|
219
|
+
if (arrayBasedTypes.has(baseTypeName))
|
|
220
|
+
return [];
|
|
221
|
+
const schemaType = schema.get(typeName);
|
|
222
|
+
if (schemaType && "fields" in schemaType) {
|
|
223
|
+
const valueField = schemaType.fields.find(_temp$2);
|
|
224
|
+
if (valueField) {
|
|
225
|
+
const fieldType = valueField.type;
|
|
226
|
+
if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || fieldType?.name && arrayBasedTypes.has(fieldType.name))
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}, $[0] = schema, $[1] = t0) : t0 = $[1];
|
|
231
|
+
const getInitialValueForType = t0;
|
|
232
|
+
let t1;
|
|
233
|
+
$[2] !== getFormValue || $[3] !== getInitialValueForType || $[4] !== onChange || $[5] !== toast ? (t1 = async (languageId) => {
|
|
234
|
+
const value = getFormValue([]);
|
|
235
|
+
if (!isSanityDocument(value)) {
|
|
236
|
+
toast.push({
|
|
237
|
+
status: "error",
|
|
238
|
+
title: "No document value found"
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
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), []);
|
|
243
|
+
if (removeDuplicates.length === 0) {
|
|
244
|
+
toast.push({
|
|
245
|
+
status: "error",
|
|
246
|
+
title: "No internationalizedArray fields found in document root"
|
|
247
|
+
});
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const patches = [];
|
|
251
|
+
for (const toTranslate of removeDuplicates) {
|
|
252
|
+
const path = toTranslate.path, initialValue = getInitialValueForType(toTranslate._type), ifMissing = setIfMissing([], path), insertValue = insert([{
|
|
253
|
+
[LANGUAGE_FIELD_NAME]: languageId,
|
|
254
|
+
_type: toTranslate._type,
|
|
255
|
+
value: initialValue
|
|
256
|
+
}], "after", [...path, -1]);
|
|
257
|
+
patches.push(ifMissing), patches.push(insertValue);
|
|
258
|
+
}
|
|
259
|
+
onChange(PatchEvent.from(patches.flat()));
|
|
260
|
+
}, $[2] = getFormValue, $[3] = getInitialValueForType, $[4] = onChange, $[5] = toast, $[6] = t1) : t1 = $[6];
|
|
261
|
+
const handleDocumentButtonClick = t1;
|
|
282
262
|
let t2;
|
|
283
|
-
$[
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
263
|
+
$[7] === /* @__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" }) }), $[7] = t2) : t2 = $[7];
|
|
264
|
+
let t3;
|
|
265
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = [], $[8] = t3) : t3 = $[8];
|
|
266
|
+
let t4;
|
|
267
|
+
return $[9] !== handleDocumentButtonClick ? (t4 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
268
|
+
t2,
|
|
269
|
+
/* @__PURE__ */ jsx(AddButtons, { readOnly: !1, handleClick: handleDocumentButtonClick, languagesInUse: t3 })
|
|
270
|
+
] }), $[9] = handleDocumentButtonClick, $[10] = t4) : t4 = $[10], t4;
|
|
271
|
+
}
|
|
272
|
+
function _temp$2(f) {
|
|
273
|
+
return f.name === "value";
|
|
274
|
+
}
|
|
275
|
+
function InternationalizedArrayFormInput(props) {
|
|
276
|
+
const $ = c(7);
|
|
277
|
+
if (props.pluginConfig?.buttonLocations?.includes("document")) {
|
|
278
|
+
let t02;
|
|
279
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(DocumentAddButtons, {}), $[0] = t02) : t02 = $[0];
|
|
280
|
+
let t1;
|
|
281
|
+
$[1] !== props ? (t1 = props.renderDefault(props), $[1] = props, $[2] = t1) : t1 = $[2];
|
|
282
|
+
let t2;
|
|
283
|
+
return $[3] !== t1 ? (t2 = /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
|
|
284
|
+
t02,
|
|
285
|
+
t1
|
|
286
|
+
] }), $[3] = t1, $[4] = t2) : t2 = $[4], t2;
|
|
287
|
+
}
|
|
288
|
+
let t0;
|
|
289
|
+
return $[5] !== props ? (t0 = props.renderDefault(props), $[5] = props, $[6] = t0) : t0 = $[6], t0;
|
|
290
|
+
}
|
|
291
|
+
function hasInternationalizedArrayField(schemaType) {
|
|
292
|
+
return isDocumentSchemaType(schemaType) ? hasInternationalizedArrayInFields(schemaType.fields) : !1;
|
|
293
|
+
}
|
|
294
|
+
function hasInternationalizedArrayInFields(fields) {
|
|
295
|
+
for (const field of fields) {
|
|
296
|
+
if (field.type.name.startsWith("internationalizedArray") || field.type.jsonType === "object" && hasInternationalizedArrayInFields(field.type.fields))
|
|
297
|
+
return !0;
|
|
298
|
+
if (field.type.jsonType === "array" && field.type.of.length > 0) {
|
|
299
|
+
for (const item of field.type.of)
|
|
300
|
+
if ("name" in item && typeof item.name == "string" && item.name.startsWith("internationalizedArray") || "fields" in item && Array.isArray(item.fields) && hasInternationalizedArrayInFields(item.fields))
|
|
301
|
+
return !0;
|
|
302
|
+
}
|
|
291
303
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
304
|
+
return !1;
|
|
305
|
+
}
|
|
306
|
+
function InternationalizedArrayLayout(props) {
|
|
307
|
+
const $ = c(10), schemaType = useSchema().get(props.documentType);
|
|
308
|
+
if (!schemaType) {
|
|
309
|
+
console.error(`Schema type not found: ${props.documentType}`);
|
|
310
|
+
let t02;
|
|
311
|
+
return $[0] !== props ? (t02 = props.renderDefault(props), $[0] = props, $[1] = t02) : t02 = $[1], t02;
|
|
299
312
|
}
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
313
|
+
if (hasInternationalizedArrayField(schemaType) && props.pluginConfig.includeForDocumentType(props.documentType)) {
|
|
314
|
+
const t02 = props.pluginConfig, t1 = props.documentType;
|
|
315
|
+
let t2;
|
|
316
|
+
$[2] !== props ? (t2 = props.renderDefault(props), $[2] = props, $[3] = t2) : t2 = $[3];
|
|
317
|
+
let t3;
|
|
318
|
+
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;
|
|
319
|
+
}
|
|
320
|
+
let t0;
|
|
321
|
+
return $[8] !== props ? (t0 = props.renderDefault(props), $[8] = props, $[9] = t0) : t0 = $[9], t0;
|
|
307
322
|
}
|
|
308
323
|
function Preload(props) {
|
|
309
324
|
const $ = c(2);
|
|
@@ -476,13 +491,13 @@ function Feedback() {
|
|
|
476
491
|
] }) }), $[3] = t3) : t3 = $[3], t3;
|
|
477
492
|
}
|
|
478
493
|
function InternationalizedArray(props) {
|
|
479
|
-
const $ = c(
|
|
494
|
+
const $ = c(90), {
|
|
480
495
|
members,
|
|
481
496
|
value: _value,
|
|
482
497
|
schemaType,
|
|
483
498
|
onChange,
|
|
484
499
|
readOnly: documentReadOnly
|
|
485
|
-
} = props, value = _value, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), {
|
|
500
|
+
} = props, value = _value, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), getFormValue = useGetFormValue(), {
|
|
486
501
|
languages,
|
|
487
502
|
filteredLanguages,
|
|
488
503
|
defaultLanguages,
|
|
@@ -507,7 +522,8 @@ function InternationalizedArray(props) {
|
|
|
507
522
|
}) : members, $[4] = languageFilterEnabled, $[5] = languageFilterOptions, $[6] = members, $[7] = selectedLanguageIds, $[8] = t2) : t2 = $[8];
|
|
508
523
|
const filteredMembers = t2;
|
|
509
524
|
let t3;
|
|
510
|
-
$[9] !== filteredLanguages || $[10] !==
|
|
525
|
+
$[9] !== filteredLanguages || $[10] !== getFormValue || $[11] !== languages || $[12] !== onChange || $[13] !== props.path || $[14] !== schemaType.name ? (t3 = (addLanguageKeys) => {
|
|
526
|
+
const formValue = getFormValue(props.path);
|
|
511
527
|
if (!filteredLanguages?.length)
|
|
512
528
|
return;
|
|
513
529
|
const patches = createAddLanguagePatches({
|
|
@@ -515,55 +531,59 @@ function InternationalizedArray(props) {
|
|
|
515
531
|
schemaTypeName: schemaType.name,
|
|
516
532
|
languages,
|
|
517
533
|
filteredLanguages,
|
|
518
|
-
value
|
|
534
|
+
value: formValue
|
|
519
535
|
});
|
|
520
536
|
onChange([setIfMissing([]), ...patches]);
|
|
521
|
-
}, $[9] = filteredLanguages, $[10] =
|
|
522
|
-
const
|
|
537
|
+
}, $[9] = filteredLanguages, $[10] = getFormValue, $[11] = languages, $[12] = onChange, $[13] = props.path, $[14] = schemaType.name, $[15] = t3) : t3 = $[15];
|
|
538
|
+
const handleAddLanguages = t3, {
|
|
523
539
|
isDeleting
|
|
524
540
|
} = useDocumentPane();
|
|
525
541
|
let t4;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
let t53;
|
|
529
|
-
$[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t53 = [], $[15] = t53) : t53 = $[15], t4 = t53;
|
|
530
|
-
break bb0;
|
|
531
|
-
}
|
|
532
|
-
let t52;
|
|
533
|
-
$[16] !== value ? (t52 = value.map(_temp$1).filter(Boolean), $[16] = value, $[17] = t52) : t52 = $[17], t4 = t52;
|
|
534
|
-
}
|
|
535
|
-
const addedLanguages = t4;
|
|
542
|
+
$[16] !== value ? (t4 = value?.map(_temp$1).filter(Boolean).join(","), $[16] = value, $[17] = t4) : t4 = $[17];
|
|
543
|
+
const languageKeysFromValue = t4;
|
|
536
544
|
let t5;
|
|
537
|
-
if ($[18] !==
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
545
|
+
if ($[18] !== languageKeysFromValue || $[19] !== languages) {
|
|
546
|
+
bb0: {
|
|
547
|
+
const languageKeys = languageKeysFromValue?.split(",") || [];
|
|
548
|
+
if (!languageKeys?.length) {
|
|
549
|
+
let t62;
|
|
550
|
+
$[21] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t62 = [], $[21] = t62) : t62 = $[21], t5 = t62;
|
|
551
|
+
break bb0;
|
|
552
|
+
}
|
|
553
|
+
if (!languages?.length) {
|
|
554
|
+
let t62;
|
|
555
|
+
$[22] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t62 = [], $[22] = t62) : t62 = $[22], t5 = t62;
|
|
556
|
+
break bb0;
|
|
557
|
+
}
|
|
558
|
+
t5 = languages.filter((l) => languageKeys?.find((key) => key === l.id)).map(_temp2$1);
|
|
559
|
+
}
|
|
560
|
+
$[18] = languageKeysFromValue, $[19] = languages, $[20] = t5;
|
|
542
561
|
} else
|
|
543
|
-
t5 = $[
|
|
544
|
-
const
|
|
562
|
+
t5 = $[20];
|
|
563
|
+
const addedLanguages = t5;
|
|
545
564
|
let t6, t7;
|
|
546
|
-
$[
|
|
565
|
+
$[23] !== addedLanguages || $[24] !== defaultLanguages || $[25] !== documentReadOnly || $[26] !== handleAddLanguages || $[27] !== isDeleting || $[28] !== languages ? (t6 = () => {
|
|
566
|
+
const hasAddedDefaultLanguages = defaultLanguages.filter((language) => languages.find((l_1) => l_1.id === language)).every((language_0) => addedLanguages.includes(language_0));
|
|
547
567
|
if (!isDeleting && !hasAddedDefaultLanguages) {
|
|
548
|
-
const languagesToAdd = defaultLanguages.filter((language_1) => !addedLanguages.includes(language_1)).filter((language_2) => languages.find((
|
|
549
|
-
documentReadOnly ||
|
|
568
|
+
const languagesToAdd = defaultLanguages.filter((language_1) => !addedLanguages.includes(language_1)).filter((language_2) => languages.find((l_2) => l_2.id === language_2)), timeout = setTimeout(() => {
|
|
569
|
+
documentReadOnly || handleAddLanguages(languagesToAdd);
|
|
550
570
|
});
|
|
551
571
|
return () => clearTimeout(timeout);
|
|
552
572
|
}
|
|
553
|
-
}, t7 = [isDeleting,
|
|
573
|
+
}, t7 = [isDeleting, handleAddLanguages, defaultLanguages, addedLanguages, languages, documentReadOnly], $[23] = addedLanguages, $[24] = defaultLanguages, $[25] = documentReadOnly, $[26] = handleAddLanguages, $[27] = isDeleting, $[28] = languages, $[29] = t6, $[30] = t7) : (t6 = $[29], t7 = $[30]), useEffect(t6, t7);
|
|
554
574
|
let t8;
|
|
555
|
-
$[
|
|
575
|
+
$[31] !== languages || $[32] !== onChange || $[33] !== toast || $[34] !== value ? (t8 = () => {
|
|
556
576
|
if (!value?.length || !languages?.length)
|
|
557
577
|
return;
|
|
558
578
|
const updatedValue = value.reduce((acc, v_0) => {
|
|
559
|
-
const newIndex = languages.findIndex((
|
|
579
|
+
const newIndex = languages.findIndex((l_3) => l_3.id === v_0?.[LANGUAGE_FIELD_NAME]);
|
|
560
580
|
return newIndex > -1 && (acc[newIndex] = v_0), acc;
|
|
561
581
|
}, []).filter(Boolean);
|
|
562
582
|
value?.length !== updatedValue.length && toast.push({
|
|
563
583
|
title: "There was an error reordering languages",
|
|
564
584
|
status: "warning"
|
|
565
585
|
}), onChange(set(updatedValue));
|
|
566
|
-
}, $[
|
|
586
|
+
}, $[31] = languages, $[32] = onChange, $[33] = toast, $[34] = value, $[35] = t8) : t8 = $[35];
|
|
567
587
|
const handleRestoreOrder = t8;
|
|
568
588
|
let t9;
|
|
569
589
|
bb1: {
|
|
@@ -572,66 +592,78 @@ function InternationalizedArray(props) {
|
|
|
572
592
|
break bb1;
|
|
573
593
|
}
|
|
574
594
|
let t102;
|
|
575
|
-
$[
|
|
595
|
+
$[36] !== languages || $[37] !== value ? (t102 = value?.every((v_1) => languages.find((l_4) => l_4?.id === v_1?.[LANGUAGE_FIELD_NAME])), $[36] = languages, $[37] = value, $[38] = t102) : t102 = $[38], t9 = t102;
|
|
576
596
|
}
|
|
577
597
|
const allKeysAreLanguages = t9;
|
|
578
598
|
let t10;
|
|
579
|
-
$[43] !== languages || $[44] !== value ? (t10 = languages && languages.length > 1 ? languages.filter((l_3) => value?.find((v_2) => v_2[LANGUAGE_FIELD_NAME] === l_3.id)) : [], $[43] = languages, $[44] = value, $[45] = t10) : t10 = $[45];
|
|
580
|
-
const languagesInUse = t10;
|
|
581
|
-
let t11;
|
|
582
599
|
bb2: {
|
|
583
|
-
if (!value?.length || !
|
|
584
|
-
let
|
|
585
|
-
$[
|
|
600
|
+
if (!value?.length || !addedLanguages.length) {
|
|
601
|
+
let t113;
|
|
602
|
+
$[39] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t113 = [], $[39] = t113) : t113 = $[39], t10 = t113;
|
|
586
603
|
break bb2;
|
|
587
604
|
}
|
|
588
|
-
let
|
|
589
|
-
if ($[
|
|
590
|
-
let
|
|
591
|
-
$[
|
|
605
|
+
let t112;
|
|
606
|
+
if ($[40] !== addedLanguages || $[41] !== value) {
|
|
607
|
+
let t122;
|
|
608
|
+
$[43] !== addedLanguages ? (t122 = (v_2, vIndex) => vIndex === addedLanguages.findIndex((language_3) => language_3 === v_2[LANGUAGE_FIELD_NAME]) ? null : v_2, $[43] = addedLanguages, $[44] = t122) : t122 = $[44], t112 = value.map(t122).filter(Boolean), $[40] = addedLanguages, $[41] = value, $[42] = t112;
|
|
592
609
|
} else
|
|
593
|
-
|
|
594
|
-
|
|
610
|
+
t112 = $[42];
|
|
611
|
+
t10 = t112;
|
|
595
612
|
}
|
|
596
|
-
const languagesOutOfOrder =
|
|
597
|
-
let
|
|
598
|
-
$[
|
|
613
|
+
const languagesOutOfOrder = t10, languagesAreValid = !languages?.length || languages?.length && languages.every(_temp3$1);
|
|
614
|
+
let t11;
|
|
615
|
+
$[45] !== allKeysAreLanguages || $[46] !== documentReadOnly || $[47] !== handleRestoreOrder || $[48] !== languagesOutOfOrder.length ? (t11 = () => {
|
|
599
616
|
languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
|
|
600
|
-
}, $[
|
|
617
|
+
}, $[45] = allKeysAreLanguages, $[46] = documentReadOnly, $[47] = handleRestoreOrder, $[48] = languagesOutOfOrder.length, $[49] = t11) : t11 = $[49];
|
|
618
|
+
let t12;
|
|
619
|
+
$[50] !== allKeysAreLanguages || $[51] !== documentReadOnly || $[52] !== handleRestoreOrder || $[53] !== languagesOutOfOrder ? (t12 = [languagesOutOfOrder, allKeysAreLanguages, handleRestoreOrder, documentReadOnly], $[50] = allKeysAreLanguages, $[51] = documentReadOnly, $[52] = handleRestoreOrder, $[53] = languagesOutOfOrder, $[54] = t12) : t12 = $[54], useEffect(t11, t12);
|
|
601
620
|
let t13;
|
|
602
|
-
$[
|
|
621
|
+
$[55] !== filteredLanguages || $[56] !== value ? (t13 = checkAllLanguagesArePresent(filteredLanguages, value), $[55] = filteredLanguages, $[56] = value, $[57] = t13) : t13 = $[57];
|
|
622
|
+
const allLanguagesArePresent = t13;
|
|
603
623
|
let t14;
|
|
604
|
-
$[
|
|
605
|
-
|
|
624
|
+
$[58] !== filteredLanguages || $[59] !== handleAddLanguages ? (t14 = () => {
|
|
625
|
+
handleAddLanguages(filteredLanguages.map(_temp4$1));
|
|
626
|
+
}, $[58] = filteredLanguages, $[59] = handleAddLanguages, $[60] = t14) : t14 = $[60];
|
|
627
|
+
const addAllMissingLanguages = t14;
|
|
606
628
|
if (!languagesAreValid) {
|
|
607
629
|
let t152;
|
|
608
|
-
return $[
|
|
630
|
+
return $[61] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t152 = /* @__PURE__ */ jsx(Feedback, {}), $[61] = t152) : t152 = $[61], t152;
|
|
609
631
|
}
|
|
610
632
|
let t15;
|
|
611
|
-
$[
|
|
633
|
+
$[62] !== allLanguagesArePresent || $[63] !== buttonLocations || $[64] !== filteredLanguages.length ? (t15 = buttonLocations.includes("field") && filteredLanguages?.length > 0 && !allLanguagesArePresent, $[62] = allLanguagesArePresent, $[63] = buttonLocations, $[64] = filteredLanguages.length, $[65] = t15) : t15 = $[65];
|
|
612
634
|
const addButtonsAreVisible = t15, fieldHasMembers = members?.length > 0;
|
|
613
635
|
let t16;
|
|
614
|
-
$[
|
|
636
|
+
$[66] !== filteredLanguages || $[67] !== value ? (t16 = createAddAllTitle(value, filteredLanguages), $[66] = filteredLanguages, $[67] = value, $[68] = t16) : t16 = $[68];
|
|
637
|
+
const addAllTitle = t16;
|
|
615
638
|
let t17;
|
|
616
|
-
$[
|
|
639
|
+
if ($[69] !== filteredMembers || $[70] !== props) {
|
|
640
|
+
let t182;
|
|
641
|
+
$[72] !== props ? (t182 = (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), $[72] = props, $[73] = t182) : t182 = $[73], t17 = filteredMembers.map(t182), $[69] = filteredMembers, $[70] = props, $[71] = t17;
|
|
642
|
+
} else
|
|
643
|
+
t17 = $[71];
|
|
617
644
|
let t18;
|
|
618
|
-
$[
|
|
619
|
-
/* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, value, readOnly, handleClick: handleAddLanguage }),
|
|
620
|
-
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(_temp3$1)) }) : null
|
|
621
|
-
] }) : null, $[77] = addButtonsAreVisible, $[78] = allLanguagesArePresent, $[79] = buttonAddAll, $[80] = filteredLanguages, $[81] = handleAddLanguage, $[82] = readOnly, $[83] = value, $[84] = t18) : t18 = $[84];
|
|
645
|
+
$[74] !== addButtonsAreVisible || $[75] !== fieldHasMembers ? (t18 = !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, $[74] = addButtonsAreVisible, $[75] = fieldHasMembers, $[76] = t18) : t18 = $[76];
|
|
622
646
|
let t19;
|
|
623
|
-
|
|
624
|
-
|
|
647
|
+
$[77] !== addAllMissingLanguages || $[78] !== addAllTitle || $[79] !== addButtonsAreVisible || $[80] !== addedLanguages || $[81] !== allLanguagesArePresent || $[82] !== buttonAddAll || $[83] !== handleAddLanguages || $[84] !== readOnly ? (t19 = addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
648
|
+
/* @__PURE__ */ jsx(AddButtons, { languagesInUse: addedLanguages, readOnly, handleClick: handleAddLanguages }),
|
|
649
|
+
buttonAddAll ? /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", "data-testid": "add-all-languages", disabled: readOnly || allLanguagesArePresent, icon: AddIcon, text: addAllTitle, onClick: addAllMissingLanguages }) : null
|
|
650
|
+
] }) : null, $[77] = addAllMissingLanguages, $[78] = addAllTitle, $[79] = addButtonsAreVisible, $[80] = addedLanguages, $[81] = allLanguagesArePresent, $[82] = buttonAddAll, $[83] = handleAddLanguages, $[84] = readOnly, $[85] = t19) : t19 = $[85];
|
|
651
|
+
let t20;
|
|
652
|
+
return $[86] !== t17 || $[87] !== t18 || $[88] !== t19 ? (t20 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
625
653
|
t17,
|
|
626
|
-
t18
|
|
627
|
-
|
|
654
|
+
t18,
|
|
655
|
+
t19
|
|
656
|
+
] }), $[86] = t17, $[87] = t18, $[88] = t19, $[89] = t20) : t20 = $[89], t20;
|
|
628
657
|
}
|
|
629
|
-
function
|
|
630
|
-
return
|
|
658
|
+
function _temp4$1(language_4) {
|
|
659
|
+
return language_4.id;
|
|
631
660
|
}
|
|
632
|
-
function
|
|
661
|
+
function _temp3$1(item) {
|
|
633
662
|
return item.id && item.title;
|
|
634
663
|
}
|
|
664
|
+
function _temp2$1(l_0) {
|
|
665
|
+
return l_0.id;
|
|
666
|
+
}
|
|
635
667
|
function _temp$1(v) {
|
|
636
668
|
return v[LANGUAGE_FIELD_NAME] ?? v._key;
|
|
637
669
|
}
|
|
@@ -650,6 +682,11 @@ var array = (config) => {
|
|
|
650
682
|
title: "Internationalized array",
|
|
651
683
|
type: "array",
|
|
652
684
|
components: {
|
|
685
|
+
field: (props) => props.renderDefault({
|
|
686
|
+
...props,
|
|
687
|
+
// Reset the level to avoid nested styling
|
|
688
|
+
level: 0
|
|
689
|
+
}),
|
|
653
690
|
input: InternationalizedArray
|
|
654
691
|
},
|
|
655
692
|
options: {
|
|
@@ -716,75 +753,149 @@ function getToneFromValidation(validations) {
|
|
|
716
753
|
if (validationLevels.has("warning"))
|
|
717
754
|
return "caution";
|
|
718
755
|
}
|
|
719
|
-
function
|
|
720
|
-
const $ = c(
|
|
756
|
+
function ChangeLanguageButton(props) {
|
|
757
|
+
const $ = c(24), {
|
|
758
|
+
value,
|
|
759
|
+
onChange,
|
|
760
|
+
path
|
|
761
|
+
} = props;
|
|
721
762
|
let t0;
|
|
722
|
-
$[0] !==
|
|
723
|
-
const parentValue = useFormValue(t0),
|
|
763
|
+
$[0] !== path ? (t0 = path.slice(0, -1), $[0] = path, $[1] = t0) : t0 = $[1];
|
|
764
|
+
const parentValue = useFormValue(t0), {
|
|
765
|
+
languages
|
|
766
|
+
} = useInternationalizedArrayContext();
|
|
767
|
+
let t1;
|
|
768
|
+
$[2] !== parentValue ? (t1 = parentValue?.map(_temp) ?? [], $[2] = parentValue, $[3] = t1) : t1 = $[3];
|
|
769
|
+
const languageKeysInUse = t1;
|
|
770
|
+
let t2;
|
|
771
|
+
$[4] !== languages || $[5] !== onChange || $[6] !== value ? (t2 = (event) => {
|
|
772
|
+
const languageId = event?.currentTarget?.value;
|
|
773
|
+
!value || !languages?.length || !languages.find((l) => l.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
|
|
774
|
+
}, $[4] = languages, $[5] = onChange, $[6] = value, $[7] = t2) : t2 = $[7];
|
|
775
|
+
const handleKeyChange = t2, t3 = `Change "${value[LANGUAGE_FIELD_NAME]}"`;
|
|
776
|
+
let t4;
|
|
777
|
+
$[8] !== t3 ? (t4 = /* @__PURE__ */ jsx(Button, { fontSize: 1, text: t3 }), $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
778
|
+
const t5 = `${value[LANGUAGE_FIELD_NAME]}-change-key`;
|
|
779
|
+
let t6;
|
|
780
|
+
if ($[10] !== handleKeyChange || $[11] !== languageKeysInUse || $[12] !== languages) {
|
|
781
|
+
let t72;
|
|
782
|
+
$[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;
|
|
783
|
+
} else
|
|
784
|
+
t6 = $[13];
|
|
785
|
+
let t7;
|
|
786
|
+
$[17] !== t6 ? (t7 = /* @__PURE__ */ jsx(Menu, { children: t6 }), $[17] = t6, $[18] = t7) : t7 = $[18];
|
|
787
|
+
let t8;
|
|
788
|
+
$[19] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = {
|
|
789
|
+
portal: !0
|
|
790
|
+
}, $[19] = t8) : t8 = $[19];
|
|
791
|
+
let t9;
|
|
792
|
+
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;
|
|
793
|
+
}
|
|
794
|
+
function _temp(v) {
|
|
795
|
+
return v[LANGUAGE_FIELD_NAME];
|
|
796
|
+
}
|
|
797
|
+
function RemoveButton(t0) {
|
|
798
|
+
const $ = c(10), {
|
|
799
|
+
isDefault,
|
|
800
|
+
readOnly,
|
|
801
|
+
onChange
|
|
802
|
+
} = t0;
|
|
724
803
|
let t1;
|
|
725
|
-
$[
|
|
804
|
+
$[0] !== onChange ? (t1 = () => {
|
|
805
|
+
onChange(unset());
|
|
806
|
+
}, $[0] = onChange, $[1] = t1) : t1 = $[1];
|
|
807
|
+
const handleUnset = t1, t2 = !isDefault;
|
|
808
|
+
let t3, t4;
|
|
809
|
+
$[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]);
|
|
810
|
+
const t5 = readOnly || isDefault;
|
|
811
|
+
let t6;
|
|
812
|
+
$[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];
|
|
813
|
+
let t7;
|
|
814
|
+
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;
|
|
815
|
+
}
|
|
816
|
+
function InternationalizedInput(props) {
|
|
817
|
+
const $ = c(50), originalOnChange = props.inputProps.onChange;
|
|
818
|
+
let t0;
|
|
819
|
+
$[0] !== originalOnChange || $[1] !== props.value?.value ? (t0 = (patches) => {
|
|
726
820
|
if (!Array.isArray(patches))
|
|
727
821
|
return originalOnChange(patches);
|
|
728
822
|
const valueField = props.value?.value;
|
|
729
|
-
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(
|
|
823
|
+
if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp2)) {
|
|
730
824
|
const initPatch = valueField === void 0 ? {
|
|
731
825
|
type: "setIfMissing",
|
|
732
826
|
path: ["value"],
|
|
733
827
|
value: []
|
|
734
|
-
} : null, fixedPatches = patches.map(
|
|
828
|
+
} : null, fixedPatches = patches.map(_temp3), allPatches = initPatch ? [initPatch, ...fixedPatches] : fixedPatches;
|
|
735
829
|
return originalOnChange(allPatches);
|
|
736
830
|
}
|
|
737
831
|
return originalOnChange(patches);
|
|
738
|
-
}, $[
|
|
739
|
-
const wrappedOnChange =
|
|
740
|
-
|
|
741
|
-
|
|
832
|
+
}, $[0] = originalOnChange, $[1] = props.value?.value, $[2] = t0) : t0 = $[2];
|
|
833
|
+
const wrappedOnChange = t0, t1 = props.inputProps;
|
|
834
|
+
let t2;
|
|
835
|
+
$[3] !== props.inputProps.members ? (t2 = props.inputProps.members.filter(_temp4), $[3] = props.inputProps.members, $[4] = t2) : t2 = $[4];
|
|
836
|
+
let t3;
|
|
837
|
+
$[5] !== props.inputProps || $[6] !== props.value || $[7] !== t2 || $[8] !== wrappedOnChange ? (t3 = {
|
|
838
|
+
...t1,
|
|
839
|
+
members: t2,
|
|
742
840
|
value: props.value,
|
|
743
841
|
onChange: wrappedOnChange
|
|
744
|
-
},
|
|
842
|
+
}, $[5] = props.inputProps, $[6] = props.value, $[7] = t2, $[8] = wrappedOnChange, $[9] = t3) : t3 = $[9];
|
|
843
|
+
const inlineProps = t3, {
|
|
745
844
|
validation,
|
|
746
845
|
value,
|
|
747
|
-
onChange,
|
|
748
846
|
readOnly
|
|
749
847
|
} = inlineProps, {
|
|
750
848
|
languages,
|
|
751
849
|
languageDisplay,
|
|
752
850
|
defaultLanguages
|
|
753
851
|
} = useInternationalizedArrayContext();
|
|
754
|
-
let
|
|
755
|
-
$[
|
|
756
|
-
const
|
|
757
|
-
const languageId = event?.currentTarget?.value;
|
|
758
|
-
!value || !languages?.length || !languages.find((l_0) => l_0.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
|
|
759
|
-
}, handleUnset = () => {
|
|
760
|
-
onChange(unset());
|
|
761
|
-
};
|
|
852
|
+
let t4;
|
|
853
|
+
$[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];
|
|
854
|
+
const keyIsValid = t4;
|
|
762
855
|
if (!languages) {
|
|
763
|
-
let
|
|
764
|
-
return $[
|
|
856
|
+
let t52;
|
|
857
|
+
return $[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t52 = /* @__PURE__ */ jsx(Spinner, {}), $[13] = t52) : t52 = $[13], t52;
|
|
765
858
|
}
|
|
766
|
-
const language = languages.find((l_1) => l_1.id === value[LANGUAGE_FIELD_NAME]), languageTitle = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", isDefault = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), removeButton = /* @__PURE__ */ jsx(Button, { mode: "bleed", icon: RemoveCircleIcon, tone: "critical", disabled: readOnly || isDefault, onClick: handleUnset }), t3 = getToneFromValidation(validation), t4 = keyIsValid ? /* @__PURE__ */ jsx(Label, { muted: !0, size: 1, children: languageTitle }) : /* @__PURE__ */ jsx(MenuButton, { button: /* @__PURE__ */ jsx(Button, { fontSize: 1, text: `Change "${value[LANGUAGE_FIELD_NAME]}"` }), id: `${value[LANGUAGE_FIELD_NAME]}-change-key`, menu: /* @__PURE__ */ jsx(Menu, { children: languages.map((lang) => /* @__PURE__ */ jsx(MenuItem, { disabled: languageKeysInUse.includes(lang.id), fontSize: 1, text: lang.id.toLocaleUpperCase(), value: lang.id, onClick: handleKeyChange }, lang.id)) }), popover: {
|
|
767
|
-
portal: !0
|
|
768
|
-
} });
|
|
769
859
|
let t5;
|
|
770
|
-
$[
|
|
771
|
-
|
|
860
|
+
if ($[14] !== keyIsValid || $[15] !== languageDisplay || $[16] !== languages || $[17] !== value) {
|
|
861
|
+
let t62;
|
|
862
|
+
$[19] !== value ? (t62 = (l_0) => l_0.id === value[LANGUAGE_FIELD_NAME], $[19] = value, $[20] = t62) : t62 = $[20];
|
|
863
|
+
const language = languages.find(t62);
|
|
864
|
+
t5 = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", $[14] = keyIsValid, $[15] = languageDisplay, $[16] = languages, $[17] = value, $[18] = t5;
|
|
865
|
+
} else
|
|
866
|
+
t5 = $[18];
|
|
867
|
+
const languageTitle = t5;
|
|
868
|
+
let t6;
|
|
869
|
+
$[21] !== defaultLanguages || $[22] !== value ? (t6 = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), $[21] = defaultLanguages, $[22] = value, $[23] = t6) : t6 = $[23];
|
|
870
|
+
const isDefault = t6;
|
|
871
|
+
let t7;
|
|
872
|
+
$[24] !== validation ? (t7 = getToneFromValidation(validation), $[24] = validation, $[25] = t7) : t7 = $[25];
|
|
873
|
+
let t8;
|
|
874
|
+
$[26] !== keyIsValid || $[27] !== languageTitle || $[28] !== originalOnChange || $[29] !== props.path || $[30] !== value ? (t8 = keyIsValid ? /* @__PURE__ */ jsx(Label, { muted: !0, size: 1, children: languageTitle }) : /* @__PURE__ */ jsx(ChangeLanguageButton, { value, path: props.path, onChange: originalOnChange }), $[26] = keyIsValid, $[27] = languageTitle, $[28] = originalOnChange, $[29] = props.path, $[30] = value, $[31] = t8) : t8 = $[31];
|
|
772
875
|
let t9;
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
876
|
+
$[32] !== inlineProps || $[33] !== props.inputProps ? (t9 = props.inputProps.renderInput(inlineProps), $[32] = inlineProps, $[33] = props.inputProps, $[34] = t9) : t9 = $[34];
|
|
877
|
+
let t10;
|
|
878
|
+
$[35] !== t9 ? (t10 = /* @__PURE__ */ jsx(Box, { flex: 1, children: t9 }), $[35] = t9, $[36] = t10) : t10 = $[36];
|
|
879
|
+
const t11 = !!readOnly;
|
|
880
|
+
let t12;
|
|
881
|
+
$[37] !== isDefault || $[38] !== originalOnChange || $[39] !== t11 ? (t12 = /* @__PURE__ */ jsx(RemoveButton, { isDefault, readOnly: t11, onChange: originalOnChange }), $[37] = isDefault, $[38] = originalOnChange, $[39] = t11, $[40] = t12) : t12 = $[40];
|
|
882
|
+
let t13;
|
|
883
|
+
$[41] !== t10 || $[42] !== t12 ? (t13 = /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
884
|
+
t10,
|
|
885
|
+
t12
|
|
886
|
+
] }), $[41] = t10, $[42] = t12, $[43] = t13) : t13 = $[43];
|
|
887
|
+
let t14;
|
|
888
|
+
$[44] !== t13 || $[45] !== t8 ? (t14 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
889
|
+
t8,
|
|
890
|
+
t13
|
|
891
|
+
] }), $[44] = t13, $[45] = t8, $[46] = t14) : t14 = $[46];
|
|
892
|
+
let t15;
|
|
893
|
+
return $[47] !== t14 || $[48] !== t7 ? (t15 = /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t7, children: t14 }), $[47] = t14, $[48] = t7, $[49] = t15) : t15 = $[49], t15;
|
|
783
894
|
}
|
|
784
|
-
function
|
|
895
|
+
function _temp4(m) {
|
|
785
896
|
return m.kind === "field" && m.name === "value";
|
|
786
897
|
}
|
|
787
|
-
function
|
|
898
|
+
function _temp3(patch_0) {
|
|
788
899
|
if (!patch_0 || typeof patch_0 != "object")
|
|
789
900
|
return patch_0;
|
|
790
901
|
if (patch_0.type === "insert" && patch_0.path && Array.isArray(patch_0.path)) {
|
|
@@ -796,7 +907,7 @@ function _temp2(patch_0) {
|
|
|
796
907
|
}
|
|
797
908
|
return patch_0;
|
|
798
909
|
}
|
|
799
|
-
function
|
|
910
|
+
function _temp2(patch) {
|
|
800
911
|
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;
|
|
801
912
|
}
|
|
802
913
|
var object = (config) => {
|
|
@@ -809,13 +920,24 @@ var object = (config) => {
|
|
|
809
920
|
type: "object",
|
|
810
921
|
components: {
|
|
811
922
|
// @ts-expect-error - fix typings
|
|
812
|
-
item: InternationalizedInput
|
|
923
|
+
item: InternationalizedInput,
|
|
924
|
+
field: (props) => props.renderDefault({
|
|
925
|
+
...props,
|
|
926
|
+
// Reset the level to avoid nested styling
|
|
927
|
+
level: 0
|
|
928
|
+
})
|
|
813
929
|
},
|
|
814
930
|
fields: [defineField({
|
|
815
931
|
...typeof type == "string" ? {
|
|
816
932
|
type
|
|
817
933
|
} : type,
|
|
818
|
-
name: "value"
|
|
934
|
+
name: "value",
|
|
935
|
+
components: {
|
|
936
|
+
field: (props) => props.renderDefault({
|
|
937
|
+
...props,
|
|
938
|
+
title: ""
|
|
939
|
+
})
|
|
940
|
+
}
|
|
819
941
|
})],
|
|
820
942
|
preview: {
|
|
821
943
|
select: {
|
|
@@ -825,30 +947,6 @@ var object = (config) => {
|
|
|
825
947
|
}
|
|
826
948
|
});
|
|
827
949
|
};
|
|
828
|
-
function flattenSchemaType(schemaType) {
|
|
829
|
-
return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
|
|
830
|
-
}
|
|
831
|
-
function extractInnerFields(fields, path, maxDepth) {
|
|
832
|
-
return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
|
|
833
|
-
const thisFieldWithPath = {
|
|
834
|
-
path: [...path, field.name],
|
|
835
|
-
...field
|
|
836
|
-
};
|
|
837
|
-
if (field.type.jsonType === "object") {
|
|
838
|
-
const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth);
|
|
839
|
-
return acc.push(thisFieldWithPath, ...innerFields), acc;
|
|
840
|
-
} else if (field.type.jsonType === "array" && field.type.of.length && field.type.of.some((item) => "fields" in item)) {
|
|
841
|
-
const innerFields = field.type.of.flatMap((innerField) => extractInnerFields(
|
|
842
|
-
// @ts-expect-error - Fix TS assertion for array fields
|
|
843
|
-
innerField.fields,
|
|
844
|
-
[...path, field.name],
|
|
845
|
-
maxDepth
|
|
846
|
-
));
|
|
847
|
-
return acc.push(thisFieldWithPath, ...innerFields), acc;
|
|
848
|
-
}
|
|
849
|
-
return acc.push(thisFieldWithPath), acc;
|
|
850
|
-
}, []);
|
|
851
|
-
}
|
|
852
950
|
const internationalizedArray = definePlugin((config) => {
|
|
853
951
|
const pluginConfig = {
|
|
854
952
|
...CONFIG_DEFAULT,
|
|
@@ -873,13 +971,15 @@ const internationalizedArray = definePlugin((config) => {
|
|
|
873
971
|
},
|
|
874
972
|
// Optional: render "add language" buttons as field actions
|
|
875
973
|
document: {
|
|
974
|
+
components: {
|
|
975
|
+
unstable_layout: (props) => /* @__PURE__ */ jsx(InternationalizedArrayLayout, { ...props, pluginConfig })
|
|
976
|
+
},
|
|
876
977
|
unstable_fieldActions: buttonLocations.includes("unstable__fieldAction") ? (prev) => [...prev, internationalizedArrayFieldAction] : void 0
|
|
877
978
|
},
|
|
878
979
|
// Wrap document editor with a language provider
|
|
879
980
|
form: {
|
|
880
981
|
components: {
|
|
881
|
-
|
|
882
|
-
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 })
|
|
982
|
+
input: (props) => props.id === "root" && isObjectInputProps(props) && hasInternationalizedArrayField(props.schemaType) && pluginConfig.includeForDocumentType(props.schemaType.name) ? /* @__PURE__ */ jsx(InternationalizedArrayFormInput, { ...props, pluginConfig }) : props.renderDefault(props)
|
|
883
983
|
}
|
|
884
984
|
},
|
|
885
985
|
// Register custom schema types for the outer array and the inner object
|