sanity-plugin-internationalized-array 4.0.2 → 5.0.0-canary.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 +141 -52
- package/dist/index.d.ts +45 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +257 -122
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +31 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +26 -0
- package/dist/migrations/index.js.map +1 -0
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useLanguageFilterStudioContext, languageFilter } from "@sanity/language-filter";
|
|
3
|
+
import { isSanityDocument, useSchema, setIfMissing, insert, PatchEvent, useClient, useWorkspace, useFormValue, defineDocumentFieldAction, set, ArrayOfObjectsItem, MemberItemError, defineField, unset, isDocumentSchemaType, definePlugin, isObjectInputProps } from "sanity";
|
|
3
4
|
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";
|
|
5
|
+
import { Grid, Button, useToast, Stack, Box, Text, Card, Code, Flex, Spinner, Label, MenuButton, Menu, MenuItem, Tooltip } from "@sanity/ui";
|
|
6
6
|
import { createContext, useContext, useDeferredValue, use, useCallback, useEffect, createElement } from "react";
|
|
7
7
|
import { useDocumentPane } from "sanity/structure";
|
|
8
|
-
import {
|
|
8
|
+
import { randomKey } from "@sanity/util/content";
|
|
9
|
+
import { AddIcon, TranslateIcon, WarningOutlineIcon, RemoveCircleIcon } from "@sanity/icons";
|
|
9
10
|
import { get, upperFirst, camelCase } from "lodash-es";
|
|
10
11
|
const namespace = "sanity-plugin-internationalized-array", functionCache = /* @__PURE__ */ new Map(), functionKeyCache = /* @__PURE__ */ new WeakMap(), promiseCache = /* @__PURE__ */ new Map();
|
|
11
12
|
function stringifyCacheKey(key) {
|
|
@@ -51,7 +52,7 @@ const preloadWithKey = (fn, key) => {
|
|
|
51
52
|
}, setFunctionCache = (fn, selectedValue, languages, workspaceId) => {
|
|
52
53
|
const key = createFunctionCacheKey(fn, selectedValue, workspaceId);
|
|
53
54
|
functionCache.set(key, languages);
|
|
54
|
-
}, LANGUAGE_FIELD_NAME = "
|
|
55
|
+
}, LANGUAGE_FIELD_NAME = "language", MAX_COLUMNS = {
|
|
55
56
|
codeOnly: 5,
|
|
56
57
|
titleOnly: 4,
|
|
57
58
|
titleAndCode: 3
|
|
@@ -63,7 +64,10 @@ const preloadWithKey = (fn, key) => {
|
|
|
63
64
|
apiVersion: "2025-10-15",
|
|
64
65
|
buttonLocations: ["field"],
|
|
65
66
|
buttonAddAll: !0,
|
|
66
|
-
languageDisplay: "codeOnly"
|
|
67
|
+
languageDisplay: "codeOnly",
|
|
68
|
+
languageFilter: {
|
|
69
|
+
documentTypes: []
|
|
70
|
+
}
|
|
67
71
|
}, getDocumentsToTranslate = (value, rootPath = []) => {
|
|
68
72
|
if (Array.isArray(value)) {
|
|
69
73
|
const arrayRootPath = [...rootPath], internationalizedValues = value.filter((item) => {
|
|
@@ -101,13 +105,13 @@ function AddButtons(props) {
|
|
|
101
105
|
languageDisplay
|
|
102
106
|
} = useInternationalizedArrayContext();
|
|
103
107
|
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) => {
|
|
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) => {
|
|
105
109
|
const languageTitle = getLanguageDisplay(languageDisplay, language.title, language.id);
|
|
106
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);
|
|
107
111
|
}) }) : null, $[0] = handleClick, $[1] = languageDisplay, $[2] = languages, $[3] = readOnly, $[4] = value, $[5] = t0) : t0 = $[5], t0;
|
|
108
112
|
}
|
|
109
113
|
function DocumentAddButtons(props) {
|
|
110
|
-
const $ = c(
|
|
114
|
+
const $ = c(14), {
|
|
111
115
|
filteredLanguages
|
|
112
116
|
} = useInternationalizedArrayContext(), value = isSanityDocument(props.value) ? props.value : void 0, toast = useToast(), {
|
|
113
117
|
onChange
|
|
@@ -127,7 +131,7 @@ function DocumentAddButtons(props) {
|
|
|
127
131
|
return [];
|
|
128
132
|
const schemaType = schema.get(typeName);
|
|
129
133
|
if (schemaType && "fields" in schemaType) {
|
|
130
|
-
const valueField = schemaType.fields.find(_temp$
|
|
134
|
+
const valueField = schemaType.fields.find(_temp$3);
|
|
131
135
|
if (valueField) {
|
|
132
136
|
const fieldType = valueField.type;
|
|
133
137
|
if (fieldType?.jsonType === "array" || fieldType?.name === "array" || fieldType?.type === "array" || fieldType?.of !== void 0 || fieldType?.name && arrayBasedTypes.has(fieldType.name))
|
|
@@ -137,18 +141,20 @@ function DocumentAddButtons(props) {
|
|
|
137
141
|
}, $[2] = schema, $[3] = t1) : t1 = $[3];
|
|
138
142
|
const getInitialValueForType = t1;
|
|
139
143
|
let t2;
|
|
140
|
-
$[4] !== documentsToTranslation || $[5] !==
|
|
144
|
+
$[4] !== documentsToTranslation || $[5] !== filteredLanguages || $[6] !== getInitialValueForType || $[7] !== onChange || $[8] !== toast ? (t2 = async (languageId) => {
|
|
141
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), []);
|
|
142
146
|
if (removeDuplicates.length === 0) {
|
|
147
|
+
const language = filteredLanguages.find((l) => l.id === languageId);
|
|
143
148
|
toast.push({
|
|
144
|
-
status: "
|
|
145
|
-
title:
|
|
149
|
+
status: "warning",
|
|
150
|
+
title: `No missing translations for ${language?.title || languageId} found.`
|
|
146
151
|
});
|
|
147
152
|
return;
|
|
148
153
|
}
|
|
149
154
|
const patches = [];
|
|
150
155
|
for (const toTranslate of removeDuplicates) {
|
|
151
156
|
const path = toTranslate.path, initialValue = getInitialValueForType(toTranslate._type), ifMissing = setIfMissing([], path), insertValue = insert([{
|
|
157
|
+
_key: randomKey(),
|
|
152
158
|
[LANGUAGE_FIELD_NAME]: languageId,
|
|
153
159
|
_type: toTranslate._type,
|
|
154
160
|
value: initialValue
|
|
@@ -156,17 +162,17 @@ function DocumentAddButtons(props) {
|
|
|
156
162
|
patches.push(ifMissing), patches.push(insertValue);
|
|
157
163
|
}
|
|
158
164
|
onChange(PatchEvent.from(patches.flat()));
|
|
159
|
-
}, $[4] = documentsToTranslation, $[5] =
|
|
165
|
+
}, $[4] = documentsToTranslation, $[5] = filteredLanguages, $[6] = getInitialValueForType, $[7] = onChange, $[8] = toast, $[9] = t2) : t2 = $[9];
|
|
160
166
|
const handleDocumentButtonClick = t2;
|
|
161
167
|
let t3;
|
|
162
|
-
$[
|
|
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];
|
|
163
169
|
let t4;
|
|
164
|
-
return $[
|
|
170
|
+
return $[11] !== filteredLanguages || $[12] !== handleDocumentButtonClick ? (t4 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
165
171
|
t3,
|
|
166
172
|
/* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, readOnly: !1, value: void 0, handleClick: handleDocumentButtonClick })
|
|
167
|
-
] }), $[
|
|
173
|
+
] }), $[11] = filteredLanguages, $[12] = handleDocumentButtonClick, $[13] = t4) : t4 = $[13], t4;
|
|
168
174
|
}
|
|
169
|
-
function _temp$
|
|
175
|
+
function _temp$3(f) {
|
|
170
176
|
return f.name === "value";
|
|
171
177
|
}
|
|
172
178
|
const getSelectedValue = (select, document) => {
|
|
@@ -343,8 +349,10 @@ function createAddLanguagePatches(config) {
|
|
|
343
349
|
const itemBase = {
|
|
344
350
|
_type: type
|
|
345
351
|
}, newItems = Array.isArray(addLanguageKeys) && addLanguageKeys.length > 0 ? addLanguageKeys.filter((id) => value?.length ? !value.find((v) => v[LANGUAGE_FIELD_NAME] === id) : !0).map((id) => Object.assign({}, itemBase, {
|
|
352
|
+
_key: randomKey(),
|
|
346
353
|
[LANGUAGE_FIELD_NAME]: id
|
|
347
354
|
})) : filteredLanguages.filter((language) => value?.length ? !value.find((v) => v[LANGUAGE_FIELD_NAME] === language.id) : !0).map((language) => Object.assign({}, itemBase, {
|
|
355
|
+
_key: randomKey(),
|
|
348
356
|
[LANGUAGE_FIELD_NAME]: language.id
|
|
349
357
|
})), languagesInUse = value?.length ? value.map((v) => v) : [];
|
|
350
358
|
return newItems.map((item) => {
|
|
@@ -475,14 +483,92 @@ function Feedback() {
|
|
|
475
483
|
/* @__PURE__ */ jsx(Card, { padding: 2, border: !0, radius: 2, children: /* @__PURE__ */ jsx(Code, { size: 1, language: "javascript", children: JSON.stringify(schemaExample, null, 2) }) })
|
|
476
484
|
] }) }), $[3] = t3) : t3 = $[3], t3;
|
|
477
485
|
}
|
|
486
|
+
function MigrationBanner(t0) {
|
|
487
|
+
const $ = c(27), {
|
|
488
|
+
value,
|
|
489
|
+
languages,
|
|
490
|
+
onChange,
|
|
491
|
+
readOnly: t1
|
|
492
|
+
} = t0, readOnly = t1 === void 0 ? !1 : t1, toast = useToast();
|
|
493
|
+
let t2;
|
|
494
|
+
bb0: {
|
|
495
|
+
if (!value?.length || !languages?.length) {
|
|
496
|
+
let t33;
|
|
497
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t33 = [], $[0] = t33) : t33 = $[0], t2 = t33;
|
|
498
|
+
break bb0;
|
|
499
|
+
}
|
|
500
|
+
let t32;
|
|
501
|
+
$[1] !== languages ? (t32 = new Set(languages.map(_temp$2)), $[1] = languages, $[2] = t32) : t32 = $[2];
|
|
502
|
+
const languageIds = t32;
|
|
503
|
+
let t42;
|
|
504
|
+
if ($[3] !== languageIds || $[4] !== value) {
|
|
505
|
+
let t52;
|
|
506
|
+
$[6] !== languageIds ? (t52 = (item) => item._key && languageIds.has(item._key) && !item[LANGUAGE_FIELD_NAME], $[6] = languageIds, $[7] = t52) : t52 = $[7], t42 = value.filter(t52), $[3] = languageIds, $[4] = value, $[5] = t42;
|
|
507
|
+
} else
|
|
508
|
+
t42 = $[5];
|
|
509
|
+
t2 = t42;
|
|
510
|
+
}
|
|
511
|
+
const itemsNeedingMigration = t2, needsMigration = itemsNeedingMigration.length > 0;
|
|
512
|
+
let t3;
|
|
513
|
+
$[8] !== itemsNeedingMigration.length || $[9] !== languages || $[10] !== needsMigration || $[11] !== onChange || $[12] !== toast || $[13] !== value ? (t3 = () => {
|
|
514
|
+
if (!value?.length || !needsMigration)
|
|
515
|
+
return;
|
|
516
|
+
const languageIds_0 = new Set(languages.map(_temp2$2)), updatedValue = value.map((item_0) => item_0._key && languageIds_0.has(item_0._key) && !item_0[LANGUAGE_FIELD_NAME] ? {
|
|
517
|
+
...item_0,
|
|
518
|
+
_key: randomKey(),
|
|
519
|
+
[LANGUAGE_FIELD_NAME]: item_0._key
|
|
520
|
+
} : item_0);
|
|
521
|
+
onChange([set(updatedValue)]), toast.push({
|
|
522
|
+
title: `Updated ${itemsNeedingMigration.length} item${itemsNeedingMigration.length === 1 ? "" : "s"} to new format`,
|
|
523
|
+
status: "success"
|
|
524
|
+
});
|
|
525
|
+
}, $[8] = itemsNeedingMigration.length, $[9] = languages, $[10] = needsMigration, $[11] = onChange, $[12] = toast, $[13] = value, $[14] = t3) : t3 = $[14];
|
|
526
|
+
const handleMigrateLanguages = t3;
|
|
527
|
+
if (!needsMigration)
|
|
528
|
+
return null;
|
|
529
|
+
let t4;
|
|
530
|
+
$[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }), $[15] = t4) : t4 = $[15];
|
|
531
|
+
let t5;
|
|
532
|
+
$[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Data format update required" }), $[16] = t5) : t5 = $[16];
|
|
533
|
+
const t6 = itemsNeedingMigration.length === 1 ? "" : "s", t7 = itemsNeedingMigration.length === 1 ? "s" : "";
|
|
534
|
+
let t8;
|
|
535
|
+
$[17] !== itemsNeedingMigration.length || $[18] !== t6 || $[19] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Stack, { space: 2, flex: 1, children: [
|
|
536
|
+
t5,
|
|
537
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
|
|
538
|
+
itemsNeedingMigration.length,
|
|
539
|
+
" item",
|
|
540
|
+
t6,
|
|
541
|
+
" need",
|
|
542
|
+
t7,
|
|
543
|
+
" to be updated to the new format."
|
|
544
|
+
] })
|
|
545
|
+
] }), $[17] = itemsNeedingMigration.length, $[18] = t6, $[19] = t7, $[20] = t8) : t8 = $[20];
|
|
546
|
+
let t9;
|
|
547
|
+
$[21] !== handleMigrateLanguages || $[22] !== readOnly ? (t9 = /* @__PURE__ */ jsx(Button, { tone: "caution", mode: "ghost", text: "Update Languages", onClick: handleMigrateLanguages, disabled: readOnly }), $[21] = handleMigrateLanguages, $[22] = readOnly, $[23] = t9) : t9 = $[23];
|
|
548
|
+
let t10;
|
|
549
|
+
return $[24] !== t8 || $[25] !== t9 ? (t10 = /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, radius: 2, border: !0, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
|
|
550
|
+
t4,
|
|
551
|
+
t8,
|
|
552
|
+
t9
|
|
553
|
+
] }) }), $[24] = t8, $[25] = t9, $[26] = t10) : t10 = $[26], t10;
|
|
554
|
+
}
|
|
555
|
+
function _temp2$2(l_0) {
|
|
556
|
+
return l_0.id;
|
|
557
|
+
}
|
|
558
|
+
function _temp$2(l) {
|
|
559
|
+
return l.id;
|
|
560
|
+
}
|
|
478
561
|
function InternationalizedArray(props) {
|
|
479
|
-
const $ = c(
|
|
562
|
+
const $ = c(105), {
|
|
480
563
|
members,
|
|
481
564
|
value: _value,
|
|
482
565
|
schemaType,
|
|
483
566
|
onChange,
|
|
484
567
|
readOnly: documentReadOnly
|
|
485
|
-
} = props, value = _value
|
|
568
|
+
} = props, value = _value;
|
|
569
|
+
let t0;
|
|
570
|
+
$[0] !== value ? (t0 = value?.filter(_temp$1) ?? [], $[0] = value, $[1] = t0) : t0 = $[1];
|
|
571
|
+
const itemsNeedingMigration = t0.length > 0, readOnly = typeof schemaType.readOnly == "boolean" ? schemaType.readOnly : !1, toast = useToast(), {
|
|
486
572
|
languages,
|
|
487
573
|
filteredLanguages,
|
|
488
574
|
defaultLanguages,
|
|
@@ -492,22 +578,22 @@ function InternationalizedArray(props) {
|
|
|
492
578
|
selectedLanguageIds,
|
|
493
579
|
options: languageFilterOptions
|
|
494
580
|
} = useLanguageFilterStudioContext();
|
|
495
|
-
let t0;
|
|
496
|
-
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = ["_type"], $[0] = t0) : t0 = $[0];
|
|
497
|
-
const documentType = useFormValue(t0);
|
|
498
581
|
let t1;
|
|
499
|
-
$[
|
|
500
|
-
const
|
|
582
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = ["_type"], $[2] = t1) : t1 = $[2];
|
|
583
|
+
const documentType = useFormValue(t1);
|
|
501
584
|
let t2;
|
|
502
|
-
$[
|
|
585
|
+
$[3] !== documentType || $[4] !== languageFilterOptions ? (t2 = typeof documentType == "string" && languageFilterOptions.documentTypes.includes(documentType), $[3] = documentType, $[4] = languageFilterOptions, $[5] = t2) : t2 = $[5];
|
|
586
|
+
const languageFilterEnabled = t2;
|
|
587
|
+
let t3;
|
|
588
|
+
$[6] !== languageFilterEnabled || $[7] !== languageFilterOptions || $[8] !== members || $[9] !== selectedLanguageIds || $[10] !== value ? (t3 = languageFilterEnabled ? members.filter((member) => {
|
|
503
589
|
if (member.kind !== "item")
|
|
504
590
|
return !1;
|
|
505
591
|
const valueMember = member.item.members[0];
|
|
506
|
-
return !valueMember || valueMember.kind !== "field" ? !1 : languageFilterOptions.filterField(member.item.schemaType, valueMember, selectedLanguageIds);
|
|
507
|
-
}) : members, $[
|
|
508
|
-
const filteredMembers =
|
|
509
|
-
let
|
|
510
|
-
$[
|
|
592
|
+
return !valueMember || valueMember.kind !== "field" ? !1 : languageFilterOptions.filterField(member.item.schemaType, valueMember, selectedLanguageIds, value[member.index]);
|
|
593
|
+
}) : members, $[6] = languageFilterEnabled, $[7] = languageFilterOptions, $[8] = members, $[9] = selectedLanguageIds, $[10] = value, $[11] = t3) : t3 = $[11];
|
|
594
|
+
const filteredMembers = t3;
|
|
595
|
+
let t4;
|
|
596
|
+
$[12] !== filteredLanguages || $[13] !== languages || $[14] !== onChange || $[15] !== schemaType.name || $[16] !== value ? (t4 = (addLanguageKeys) => {
|
|
511
597
|
if (!filteredLanguages?.length)
|
|
512
598
|
return;
|
|
513
599
|
const patches = createAddLanguagePatches({
|
|
@@ -518,122 +604,139 @@ function InternationalizedArray(props) {
|
|
|
518
604
|
value
|
|
519
605
|
});
|
|
520
606
|
onChange([setIfMissing([]), ...patches]);
|
|
521
|
-
}, $[
|
|
522
|
-
const handleAddLanguage =
|
|
607
|
+
}, $[12] = filteredLanguages, $[13] = languages, $[14] = onChange, $[15] = schemaType.name, $[16] = value, $[17] = t4) : t4 = $[17];
|
|
608
|
+
const handleAddLanguage = t4, {
|
|
523
609
|
isDeleting
|
|
524
610
|
} = useDocumentPane();
|
|
525
|
-
let
|
|
611
|
+
let t5;
|
|
526
612
|
bb0: {
|
|
527
613
|
if (!value?.length) {
|
|
528
|
-
let
|
|
529
|
-
$[
|
|
614
|
+
let t63;
|
|
615
|
+
$[18] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t63 = [], $[18] = t63) : t63 = $[18], t5 = t63;
|
|
530
616
|
break bb0;
|
|
531
617
|
}
|
|
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;
|
|
536
|
-
let t5;
|
|
537
|
-
if ($[18] !== addedLanguages || $[19] !== defaultLanguages || $[20] !== languages) {
|
|
538
618
|
let t62;
|
|
539
|
-
$[
|
|
619
|
+
$[19] !== languages ? (t62 = new Set(languages.map(_temp2$1)), $[19] = languages, $[20] = t62) : t62 = $[20];
|
|
620
|
+
const languageIds = t62;
|
|
540
621
|
let t72;
|
|
541
|
-
|
|
622
|
+
if ($[21] !== languageIds || $[22] !== value) {
|
|
623
|
+
let t82;
|
|
624
|
+
$[24] !== languageIds ? (t82 = (v_0) => v_0[LANGUAGE_FIELD_NAME] || (v_0._key && languageIds.has(v_0._key) ? v_0._key : null), $[24] = languageIds, $[25] = t82) : t82 = $[25], t72 = value.map(t82).filter(_temp3$1), $[21] = languageIds, $[22] = value, $[23] = t72;
|
|
625
|
+
} else
|
|
626
|
+
t72 = $[23];
|
|
627
|
+
t5 = t72;
|
|
628
|
+
}
|
|
629
|
+
const addedLanguages = t5;
|
|
630
|
+
let t6;
|
|
631
|
+
if ($[26] !== addedLanguages || $[27] !== defaultLanguages || $[28] !== languages) {
|
|
632
|
+
let t72;
|
|
633
|
+
$[30] !== languages ? (t72 = (language_2) => languages.find((l) => l.id === language_2), $[30] = languages, $[31] = t72) : t72 = $[31];
|
|
634
|
+
let t82;
|
|
635
|
+
$[32] !== addedLanguages ? (t82 = (language_3) => addedLanguages.includes(language_3), $[32] = addedLanguages, $[33] = t82) : t82 = $[33], t6 = defaultLanguages.filter(t72).every(t82), $[26] = addedLanguages, $[27] = defaultLanguages, $[28] = languages, $[29] = t6;
|
|
542
636
|
} else
|
|
543
|
-
|
|
544
|
-
const hasAddedDefaultLanguages =
|
|
545
|
-
let
|
|
546
|
-
$[
|
|
547
|
-
if (!isDeleting && !hasAddedDefaultLanguages) {
|
|
548
|
-
const languagesToAdd = defaultLanguages.filter((
|
|
637
|
+
t6 = $[29];
|
|
638
|
+
const hasAddedDefaultLanguages = t6;
|
|
639
|
+
let t7, t8;
|
|
640
|
+
$[34] !== addedLanguages || $[35] !== defaultLanguages || $[36] !== documentReadOnly || $[37] !== handleAddLanguage || $[38] !== hasAddedDefaultLanguages || $[39] !== isDeleting || $[40] !== itemsNeedingMigration || $[41] !== languages ? (t7 = () => {
|
|
641
|
+
if (!isDeleting && !hasAddedDefaultLanguages && !itemsNeedingMigration) {
|
|
642
|
+
const languagesToAdd = defaultLanguages.filter((language_4) => !addedLanguages.includes(language_4)).filter((language_5) => languages.find((l_0) => l_0.id === language_5)), timeout = setTimeout(() => {
|
|
549
643
|
documentReadOnly || handleAddLanguage(languagesToAdd);
|
|
550
644
|
});
|
|
551
645
|
return () => clearTimeout(timeout);
|
|
552
646
|
}
|
|
553
|
-
},
|
|
554
|
-
let
|
|
555
|
-
$[
|
|
647
|
+
}, t8 = [isDeleting, hasAddedDefaultLanguages, handleAddLanguage, defaultLanguages, addedLanguages, languages, documentReadOnly, itemsNeedingMigration], $[34] = addedLanguages, $[35] = defaultLanguages, $[36] = documentReadOnly, $[37] = handleAddLanguage, $[38] = hasAddedDefaultLanguages, $[39] = isDeleting, $[40] = itemsNeedingMigration, $[41] = languages, $[42] = t7, $[43] = t8) : (t7 = $[42], t8 = $[43]), useEffect(t7, t8);
|
|
648
|
+
let t9;
|
|
649
|
+
$[44] !== languages || $[45] !== onChange || $[46] !== toast || $[47] !== value ? (t9 = () => {
|
|
556
650
|
if (!value?.length || !languages?.length)
|
|
557
651
|
return;
|
|
558
|
-
const updatedValue = value.reduce((acc,
|
|
559
|
-
const newIndex = languages.findIndex((l_1) => l_1.id ===
|
|
560
|
-
return newIndex > -1 && (acc[newIndex] =
|
|
652
|
+
const updatedValue = value.reduce((acc, v_1) => {
|
|
653
|
+
const newIndex = languages.findIndex((l_1) => l_1.id === v_1?.[LANGUAGE_FIELD_NAME]);
|
|
654
|
+
return newIndex > -1 && (acc[newIndex] = v_1), acc;
|
|
561
655
|
}, []).filter(Boolean);
|
|
562
656
|
value?.length !== updatedValue.length && toast.push({
|
|
563
657
|
title: "There was an error reordering languages",
|
|
564
658
|
status: "warning"
|
|
565
659
|
}), onChange(set(updatedValue));
|
|
566
|
-
}, $[
|
|
567
|
-
const handleRestoreOrder =
|
|
568
|
-
let
|
|
660
|
+
}, $[44] = languages, $[45] = onChange, $[46] = toast, $[47] = value, $[48] = t9) : t9 = $[48];
|
|
661
|
+
const handleRestoreOrder = t9;
|
|
662
|
+
let t10;
|
|
569
663
|
bb1: {
|
|
570
664
|
if (!value?.length || !languages?.length) {
|
|
571
|
-
|
|
665
|
+
t10 = !0;
|
|
572
666
|
break bb1;
|
|
573
667
|
}
|
|
574
|
-
let
|
|
575
|
-
$[
|
|
668
|
+
let t112;
|
|
669
|
+
$[49] !== languages || $[50] !== value ? (t112 = value?.every((v_2) => languages.find((l_2) => l_2?.id === v_2?.[LANGUAGE_FIELD_NAME])), $[49] = languages, $[50] = value, $[51] = t112) : t112 = $[51], t10 = t112;
|
|
576
670
|
}
|
|
577
|
-
const allKeysAreLanguages =
|
|
578
|
-
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;
|
|
671
|
+
const allKeysAreLanguages = t10;
|
|
581
672
|
let t11;
|
|
673
|
+
$[52] !== languages || $[53] !== value ? (t11 = languages && languages.length > 1 ? languages.filter((l_3) => value?.find((v_3) => v_3[LANGUAGE_FIELD_NAME] === l_3.id)) : [], $[52] = languages, $[53] = value, $[54] = t11) : t11 = $[54];
|
|
674
|
+
const languagesInUse = t11;
|
|
675
|
+
let t12;
|
|
582
676
|
bb2: {
|
|
583
677
|
if (!value?.length || !languagesInUse.length) {
|
|
584
|
-
let
|
|
585
|
-
$[
|
|
678
|
+
let t133;
|
|
679
|
+
$[55] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t133 = [], $[55] = t133) : t133 = $[55], t12 = t133;
|
|
586
680
|
break bb2;
|
|
587
681
|
}
|
|
588
|
-
let
|
|
589
|
-
if ($[
|
|
590
|
-
let
|
|
591
|
-
$[
|
|
682
|
+
let t132;
|
|
683
|
+
if ($[56] !== languagesInUse || $[57] !== value) {
|
|
684
|
+
let t142;
|
|
685
|
+
$[59] !== languagesInUse ? (t142 = (v_4, vIndex) => vIndex === languagesInUse.findIndex((l_4) => l_4.id === v_4[LANGUAGE_FIELD_NAME]) ? null : v_4, $[59] = languagesInUse, $[60] = t142) : t142 = $[60], t132 = value.map(t142).filter(Boolean), $[56] = languagesInUse, $[57] = value, $[58] = t132;
|
|
592
686
|
} else
|
|
593
|
-
|
|
594
|
-
|
|
687
|
+
t132 = $[58];
|
|
688
|
+
t12 = t132;
|
|
595
689
|
}
|
|
596
|
-
const languagesOutOfOrder =
|
|
597
|
-
let t12;
|
|
598
|
-
$[52] !== allKeysAreLanguages || $[53] !== documentReadOnly || $[54] !== handleRestoreOrder || $[55] !== languagesOutOfOrder.length ? (t12 = () => {
|
|
599
|
-
languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
|
|
600
|
-
}, $[52] = allKeysAreLanguages, $[53] = documentReadOnly, $[54] = handleRestoreOrder, $[55] = languagesOutOfOrder.length, $[56] = t12) : t12 = $[56];
|
|
690
|
+
const languagesOutOfOrder = t12, languagesAreValid = !languages?.length || languages?.length && languages.every(_temp4$1);
|
|
601
691
|
let t13;
|
|
602
|
-
$[
|
|
692
|
+
$[61] !== allKeysAreLanguages || $[62] !== documentReadOnly || $[63] !== handleRestoreOrder || $[64] !== languagesOutOfOrder.length ? (t13 = () => {
|
|
693
|
+
languagesOutOfOrder.length > 0 && allKeysAreLanguages && !documentReadOnly && handleRestoreOrder();
|
|
694
|
+
}, $[61] = allKeysAreLanguages, $[62] = documentReadOnly, $[63] = handleRestoreOrder, $[64] = languagesOutOfOrder.length, $[65] = t13) : t13 = $[65];
|
|
603
695
|
let t14;
|
|
604
|
-
$[
|
|
605
|
-
|
|
696
|
+
$[66] !== allKeysAreLanguages || $[67] !== documentReadOnly || $[68] !== handleRestoreOrder || $[69] !== languagesOutOfOrder ? (t14 = [languagesOutOfOrder, allKeysAreLanguages, handleRestoreOrder, documentReadOnly], $[66] = allKeysAreLanguages, $[67] = documentReadOnly, $[68] = handleRestoreOrder, $[69] = languagesOutOfOrder, $[70] = t14) : t14 = $[70], useEffect(t13, t14);
|
|
697
|
+
let t15;
|
|
698
|
+
$[71] !== filteredLanguages || $[72] !== value ? (t15 = checkAllLanguagesArePresent(filteredLanguages, value), $[71] = filteredLanguages, $[72] = value, $[73] = t15) : t15 = $[73];
|
|
699
|
+
const allLanguagesArePresent = t15;
|
|
606
700
|
if (!languagesAreValid) {
|
|
607
|
-
let
|
|
608
|
-
return $[
|
|
701
|
+
let t162;
|
|
702
|
+
return $[74] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t162 = /* @__PURE__ */ jsx(Feedback, {}), $[74] = t162) : t162 = $[74], t162;
|
|
609
703
|
}
|
|
610
|
-
let t15;
|
|
611
|
-
$[66] !== allLanguagesArePresent || $[67] !== buttonLocations || $[68] !== filteredLanguages?.length ? (t15 = buttonLocations.includes("field") && filteredLanguages?.length > 0 && !allLanguagesArePresent, $[66] = allLanguagesArePresent, $[67] = buttonLocations, $[68] = filteredLanguages?.length, $[69] = t15) : t15 = $[69];
|
|
612
|
-
const addButtonsAreVisible = t15, fieldHasMembers = members?.length > 0;
|
|
613
704
|
let t16;
|
|
614
|
-
$[
|
|
705
|
+
$[75] !== allLanguagesArePresent || $[76] !== buttonLocations || $[77] !== filteredLanguages?.length || $[78] !== itemsNeedingMigration ? (t16 = !itemsNeedingMigration && buttonLocations.includes("field") && filteredLanguages?.length > 0 && !allLanguagesArePresent, $[75] = allLanguagesArePresent, $[76] = buttonLocations, $[77] = filteredLanguages?.length, $[78] = itemsNeedingMigration, $[79] = t16) : t16 = $[79];
|
|
706
|
+
const addButtonsAreVisible = t16, fieldHasMembers = members?.length > 0;
|
|
615
707
|
let t17;
|
|
616
|
-
$[
|
|
708
|
+
$[80] !== languages || $[81] !== onChange || $[82] !== readOnly || $[83] !== value ? (t17 = /* @__PURE__ */ jsx(MigrationBanner, { value, languages, onChange, readOnly }), $[80] = languages, $[81] = onChange, $[82] = readOnly, $[83] = value, $[84] = t17) : t17 = $[84];
|
|
617
709
|
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];
|
|
710
|
+
$[85] !== fieldHasMembers || $[86] !== filteredMembers || $[87] !== props ? (t18 = fieldHasMembers ? /* @__PURE__ */ jsx(Fragment, { children: filteredMembers.map((member_0) => member_0.kind === "item" ? /* @__PURE__ */ createElement(ArrayOfObjectsItem, { ...props, key: member_0.key, member: member_0 }) : /* @__PURE__ */ jsx(MemberItemError, { member: member_0 }, member_0.key)) }) : null, $[85] = fieldHasMembers, $[86] = filteredMembers, $[87] = props, $[88] = t18) : t18 = $[88];
|
|
622
711
|
let t19;
|
|
623
|
-
|
|
624
|
-
|
|
712
|
+
$[89] !== addButtonsAreVisible || $[90] !== fieldHasMembers ? (t19 = !addButtonsAreVisible && !fieldHasMembers ? /* @__PURE__ */ jsx(Card, { border: !0, tone: "transparent", padding: 3, radius: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: "This internationalized field currently has no translations." }) }) : null, $[89] = addButtonsAreVisible, $[90] = fieldHasMembers, $[91] = t19) : t19 = $[91];
|
|
713
|
+
let t20;
|
|
714
|
+
$[92] !== addButtonsAreVisible || $[93] !== allLanguagesArePresent || $[94] !== buttonAddAll || $[95] !== filteredLanguages || $[96] !== handleAddLanguage || $[97] !== readOnly || $[98] !== value ? (t20 = addButtonsAreVisible ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
715
|
+
/* @__PURE__ */ jsx(AddButtons, { languages: filteredLanguages, value, readOnly, handleClick: handleAddLanguage }),
|
|
716
|
+
buttonAddAll ? /* @__PURE__ */ jsx(Button, { tone: "primary", mode: "ghost", "data-testid": "add-all-languages", disabled: readOnly || allLanguagesArePresent, icon: AddIcon, text: createAddAllTitle(value, filteredLanguages), onClick: () => handleAddLanguage(filteredLanguages.map(_temp5)) }) : null
|
|
717
|
+
] }) : null, $[92] = addButtonsAreVisible, $[93] = allLanguagesArePresent, $[94] = buttonAddAll, $[95] = filteredLanguages, $[96] = handleAddLanguage, $[97] = readOnly, $[98] = value, $[99] = t20) : t20 = $[99];
|
|
718
|
+
let t21;
|
|
719
|
+
return $[100] !== t17 || $[101] !== t18 || $[102] !== t19 || $[103] !== t20 ? (t21 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
625
720
|
t17,
|
|
626
|
-
t18
|
|
627
|
-
|
|
721
|
+
t18,
|
|
722
|
+
t19,
|
|
723
|
+
t20
|
|
724
|
+
] }), $[100] = t17, $[101] = t18, $[102] = t19, $[103] = t20, $[104] = t21) : t21 = $[104], t21;
|
|
628
725
|
}
|
|
629
|
-
function
|
|
630
|
-
return
|
|
726
|
+
function _temp5(language_6) {
|
|
727
|
+
return language_6.id;
|
|
631
728
|
}
|
|
632
|
-
function
|
|
729
|
+
function _temp4$1(item) {
|
|
633
730
|
return item.id && item.title;
|
|
634
731
|
}
|
|
732
|
+
function _temp3$1(language_1) {
|
|
733
|
+
return !!language_1;
|
|
734
|
+
}
|
|
735
|
+
function _temp2$1(language) {
|
|
736
|
+
return language.id;
|
|
737
|
+
}
|
|
635
738
|
function _temp$1(v) {
|
|
636
|
-
return v[LANGUAGE_FIELD_NAME]
|
|
739
|
+
return !v[LANGUAGE_FIELD_NAME];
|
|
637
740
|
}
|
|
638
741
|
function getLanguagesFieldOption(schemaType) {
|
|
639
742
|
return schemaType ? schemaType.options?.languages || getLanguagesFieldOption(schemaType.type) : void 0;
|
|
@@ -665,7 +768,19 @@ var array = (config) => {
|
|
|
665
768
|
})],
|
|
666
769
|
// @ts-expect-error - fix typings
|
|
667
770
|
validation: (rule) => rule.custom(async (value, context) => {
|
|
668
|
-
if (!value || value.length === 0
|
|
771
|
+
if (!value || value.length === 0)
|
|
772
|
+
return !0;
|
|
773
|
+
const itemsMissingLanguage = value.filter((item) => item && !item[LANGUAGE_FIELD_NAME] && item._key);
|
|
774
|
+
if (itemsMissingLanguage.length > 0)
|
|
775
|
+
return {
|
|
776
|
+
message: "Language is required for each array item. Run the migration to update your data from the old format.",
|
|
777
|
+
paths: itemsMissingLanguage.flatMap((item) => [[{
|
|
778
|
+
_key: item._key
|
|
779
|
+
}], [{
|
|
780
|
+
_key: item._key
|
|
781
|
+
}, "value"]])
|
|
782
|
+
};
|
|
783
|
+
if (value.length === 1 && !value[0]?.[LANGUAGE_FIELD_NAME])
|
|
669
784
|
return !0;
|
|
670
785
|
const selectedValue = getSelectedValue(select, context.document), client = context.getClient({
|
|
671
786
|
apiVersion
|
|
@@ -717,7 +832,7 @@ function getToneFromValidation(validations) {
|
|
|
717
832
|
return "caution";
|
|
718
833
|
}
|
|
719
834
|
function InternationalizedInput(props) {
|
|
720
|
-
const $ = c(
|
|
835
|
+
const $ = c(11);
|
|
721
836
|
let t0;
|
|
722
837
|
$[0] !== props.path ? (t0 = props.path.slice(0, -1), $[0] = props.path, $[1] = t0) : t0 = $[1];
|
|
723
838
|
const parentValue = useFormValue(t0), originalOnChange = props.inputProps.onChange;
|
|
@@ -753,7 +868,7 @@ function InternationalizedInput(props) {
|
|
|
753
868
|
} = useInternationalizedArrayContext();
|
|
754
869
|
let t2;
|
|
755
870
|
$[5] !== parentValue ? (t2 = parentValue?.map(_temp4) ?? [], $[5] = parentValue, $[6] = t2) : t2 = $[6];
|
|
756
|
-
const languageKeysInUse = t2, keyIsValid = languages?.length ? languages.find((l) => l.id === value[LANGUAGE_FIELD_NAME]) : !1, handleKeyChange = (event) => {
|
|
871
|
+
const languageKeysInUse = t2, itemNeedsMigration = !value[LANGUAGE_FIELD_NAME], keyIsValid = languages?.length ? languages.find((l) => l.id === value[LANGUAGE_FIELD_NAME]) : !1, handleKeyChange = (event) => {
|
|
757
872
|
const languageId = event?.currentTarget?.value;
|
|
758
873
|
!value || !languages?.length || !languages.find((l_0) => l_0.id === languageId) || onChange([set(languageId, [LANGUAGE_FIELD_NAME])]);
|
|
759
874
|
}, handleUnset = () => {
|
|
@@ -763,17 +878,14 @@ function InternationalizedInput(props) {
|
|
|
763
878
|
let t32;
|
|
764
879
|
return $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t32 = /* @__PURE__ */ jsx(Spinner, {}), $[7] = t32) : t32 = $[7], t32;
|
|
765
880
|
}
|
|
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),
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
let t9;
|
|
773
|
-
return $[10] !== T0 || $[11] !== t8 ? (t9 = /* @__PURE__ */ jsx(T0, { flex: t6, tone: t7, children: t8 }), $[10] = T0, $[11] = t8, $[12] = t9) : t9 = $[12], /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t3, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
774
|
-
t5,
|
|
881
|
+
const language = languages.find((l_1) => l_1.id === value[LANGUAGE_FIELD_NAME]), languageTitle = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", isDefault = defaultLanguages.includes(value[LANGUAGE_FIELD_NAME]), removeButton = /* @__PURE__ */ jsx(Button, { mode: "bleed", icon: RemoveCircleIcon, tone: "critical", disabled: readOnly || isDefault, onClick: handleUnset }), t3 = getToneFromValidation(validation), T0 = Card, t4 = 1, t5 = "inherit", t6 = props.inputProps.renderInput(inlineProps);
|
|
882
|
+
let t7;
|
|
883
|
+
return $[8] !== T0 || $[9] !== t6 ? (t7 = /* @__PURE__ */ jsx(T0, { flex: t4, tone: t5, children: t6 }), $[8] = T0, $[9] = t6, $[10] = t7) : t7 = $[10], /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: t3, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
884
|
+
!itemNeedsMigration && /* @__PURE__ */ jsx(Card, { tone: "inherit", children: keyIsValid ? /* @__PURE__ */ jsx(Label, { muted: !0, size: 1, children: languageTitle }) : /* @__PURE__ */ jsx(MenuButton, { button: /* @__PURE__ */ jsx(Button, { fontSize: 1, text: `Change "${value[LANGUAGE_FIELD_NAME]}"` }), id: `${value[LANGUAGE_FIELD_NAME]}-change-key`, menu: /* @__PURE__ */ jsx(Menu, { children: languages.map((lang) => /* @__PURE__ */ jsx(MenuItem, { disabled: languageKeysInUse.includes(lang.id), fontSize: 1, text: lang.id.toLocaleUpperCase(), value: lang.id, onClick: handleKeyChange }, lang.id)) }), popover: {
|
|
885
|
+
portal: !0
|
|
886
|
+
} }) }),
|
|
775
887
|
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
776
|
-
|
|
888
|
+
t7,
|
|
777
889
|
/* @__PURE__ */ jsx(Card, { tone: "inherit", children: isDefault ? /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Can't remove default language" }), fallbackPlacements: ["right", "left"], placement: "top", portal: !0, children: /* @__PURE__ */ jsx("span", { children: removeButton }) }) : removeButton })
|
|
778
890
|
] })
|
|
779
891
|
] }) });
|
|
@@ -811,12 +923,22 @@ var object = (config) => {
|
|
|
811
923
|
// @ts-expect-error - fix typings
|
|
812
924
|
item: InternationalizedInput
|
|
813
925
|
},
|
|
814
|
-
fields: [
|
|
815
|
-
|
|
816
|
-
type
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
926
|
+
fields: [
|
|
927
|
+
defineField({
|
|
928
|
+
...typeof type == "string" ? {
|
|
929
|
+
type
|
|
930
|
+
} : type,
|
|
931
|
+
name: "value"
|
|
932
|
+
}),
|
|
933
|
+
// Hidden language field - stores the language identifier (e.g., 'en', 'fr')
|
|
934
|
+
// This replaces the previous pattern of storing language in _key
|
|
935
|
+
defineField({
|
|
936
|
+
name: "language",
|
|
937
|
+
type: "string",
|
|
938
|
+
hidden: !0,
|
|
939
|
+
validation: (Rule) => Rule.required()
|
|
940
|
+
})
|
|
941
|
+
],
|
|
820
942
|
preview: {
|
|
821
943
|
select: {
|
|
822
944
|
title: "value",
|
|
@@ -849,7 +971,13 @@ function extractInnerFields(fields, path, maxDepth) {
|
|
|
849
971
|
return acc.push(thisFieldWithPath), acc;
|
|
850
972
|
}, []);
|
|
851
973
|
}
|
|
852
|
-
const
|
|
974
|
+
const internationalizedArrayLanguageFilter = (enclosingType, _member, selectedLanguageIds, parentValue) => {
|
|
975
|
+
if (isInternationalizedArrayItemType(enclosingType.name)) {
|
|
976
|
+
const language = typeof parentValue?.language == "string" ? parentValue?.language : null;
|
|
977
|
+
return language ? selectedLanguageIds.includes(language) : !1;
|
|
978
|
+
}
|
|
979
|
+
return !0;
|
|
980
|
+
}, internationalizedArray = definePlugin((config) => {
|
|
853
981
|
const pluginConfig = {
|
|
854
982
|
...CONFIG_DEFAULT,
|
|
855
983
|
...config
|
|
@@ -858,7 +986,8 @@ const internationalizedArray = definePlugin((config) => {
|
|
|
858
986
|
select,
|
|
859
987
|
languages,
|
|
860
988
|
fieldTypes,
|
|
861
|
-
buttonLocations
|
|
989
|
+
buttonLocations,
|
|
990
|
+
languageFilter: languageFilterConfig
|
|
862
991
|
} = pluginConfig;
|
|
863
992
|
return {
|
|
864
993
|
name: "sanity-plugin-internationalized-array",
|
|
@@ -892,13 +1021,19 @@ const internationalizedArray = definePlugin((config) => {
|
|
|
892
1021
|
})), ...fieldTypes.map((type) => object({
|
|
893
1022
|
type
|
|
894
1023
|
}))]
|
|
895
|
-
}
|
|
1024
|
+
},
|
|
1025
|
+
plugins: languageFilterConfig?.documentTypes?.length > 0 ? [languageFilter({
|
|
1026
|
+
documentTypes: languageFilterConfig.documentTypes,
|
|
1027
|
+
supportedLanguages: languages,
|
|
1028
|
+
filterField: internationalizedArrayLanguageFilter
|
|
1029
|
+
})] : void 0
|
|
896
1030
|
};
|
|
897
1031
|
});
|
|
898
1032
|
export {
|
|
899
1033
|
LANGUAGE_FIELD_NAME,
|
|
900
1034
|
clear,
|
|
901
1035
|
internationalizedArray,
|
|
1036
|
+
internationalizedArrayLanguageFilter,
|
|
902
1037
|
isInternationalizedArrayItemType
|
|
903
1038
|
};
|
|
904
1039
|
//# sourceMappingURL=index.js.map
|