sanity-plugin-internationalized-array 1.0.0 → 1.1.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 +70 -24
- package/lib/cjs/index.js +149 -130
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +148 -117
- package/lib/esm/index.js.map +1 -1
- package/lib/types/index.d.ts +4 -11
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/components/InternationalizedArrayInput.tsx +7 -5
- package/src/components/createFieldName.ts +20 -0
- package/src/index.ts +1 -0
- package/src/plugin.tsx +23 -0
- package/src/schema/array.ts +69 -0
- package/src/schema/object.ts +29 -0
- package/src/types.ts +4 -2
- package/src/index.tsx +0 -51
- package/src/internationalizedArray.ts +0 -111
package/lib/esm/index.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import {defineField as $
|
|
2
|
-
import {jsx as $
|
|
3
|
-
import {useMemo as $
|
|
4
|
-
import {insert as $
|
|
5
|
-
import {Stack as $
|
|
6
|
-
import {RemoveIcon as $
|
|
7
|
-
import $
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {createPlugin as $gGrEF$createPlugin, defineField as $gGrEF$defineField} from "sanity";
|
|
2
|
+
import {jsx as $gGrEF$jsx, jsxs as $gGrEF$jsxs} from "react/jsx-runtime";
|
|
3
|
+
import {useMemo as $gGrEF$useMemo, useCallback as $gGrEF$useCallback} from "react";
|
|
4
|
+
import {insert as $gGrEF$insert, setIfMissing as $gGrEF$setIfMissing, unset as $gGrEF$unset, set as $gGrEF$set, MemberItem as $gGrEF$MemberItem, FormFieldValidationStatus as $gGrEF$FormFieldValidationStatus} from "sanity/form";
|
|
5
|
+
import {Stack as $gGrEF$Stack, Box as $gGrEF$Box, Label as $gGrEF$Label, Flex as $gGrEF$Flex, Button as $gGrEF$Button, Grid as $gGrEF$Grid, Card as $gGrEF$Card, Text as $gGrEF$Text, Code as $gGrEF$Code} from "@sanity/ui";
|
|
6
|
+
import {RemoveIcon as $gGrEF$RemoveIcon, RestoreIcon as $gGrEF$RestoreIcon, AddIcon as $gGrEF$AddIcon} from "@sanity/icons";
|
|
7
|
+
import $gGrEF$styledcomponents, {css as $gGrEF$css} from "styled-components";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function $5c51df8bc000fd76$export$8a7688a96d852767(string) {
|
|
12
|
+
return string.replace(/-([a-z])/g, (g)=>g[1].toUpperCase());
|
|
13
|
+
}
|
|
14
|
+
function $5c51df8bc000fd76$export$348afa8c9ff47183(string) {
|
|
15
|
+
return string.split(` `).map((word)=>word.charAt(0).toUpperCase() + word.slice(1)).join(` `);
|
|
16
|
+
}
|
|
17
|
+
function $5c51df8bc000fd76$export$26c6f48841fe1a8a(string) {
|
|
18
|
+
return $5c51df8bc000fd76$export$348afa8c9ff47183($5c51df8bc000fd76$export$8a7688a96d852767(string));
|
|
19
|
+
}
|
|
20
|
+
function $5c51df8bc000fd76$export$ab1ce2a474f41f52(name, addValue = false) {
|
|
21
|
+
return addValue ? [
|
|
22
|
+
`internationalizedArray`,
|
|
23
|
+
$5c51df8bc000fd76$export$26c6f48841fe1a8a(name),
|
|
24
|
+
`Value`
|
|
25
|
+
].join(``) : [
|
|
26
|
+
`internationalizedArray`,
|
|
27
|
+
$5c51df8bc000fd76$export$26c6f48841fe1a8a(name)
|
|
28
|
+
].join(``);
|
|
11
29
|
}
|
|
12
|
-
var $e7e26cac6788e7ab$exports = {};
|
|
13
30
|
|
|
14
|
-
$parcel$export($e7e26cac6788e7ab$exports, "internationalizedArray", () => $e7e26cac6788e7ab$export$bec7eb13daf35f0e);
|
|
15
31
|
|
|
16
32
|
|
|
17
33
|
|
|
@@ -25,12 +41,12 @@ $parcel$export($e7e26cac6788e7ab$exports, "internationalizedArray", () => $e7e26
|
|
|
25
41
|
// https://github.com/styled-components/styled-components/issues/2449
|
|
26
42
|
// Table
|
|
27
43
|
const $32ee6db03f46d8dd$var$TableWrapper = (props = {})=>{
|
|
28
|
-
return /*#__PURE__*/ (0, $
|
|
44
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
29
45
|
as: "table",
|
|
30
46
|
...props
|
|
31
47
|
});
|
|
32
48
|
};
|
|
33
|
-
const $32ee6db03f46d8dd$var$StyledTable = (0, $
|
|
49
|
+
const $32ee6db03f46d8dd$var$StyledTable = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$TableWrapper)(()=>(0, $gGrEF$css)`
|
|
34
50
|
display: table;
|
|
35
51
|
width: 100%;
|
|
36
52
|
|
|
@@ -40,19 +56,19 @@ const $32ee6db03f46d8dd$var$StyledTable = (0, $7XdDa$styledcomponents)($32ee6db0
|
|
|
40
56
|
`);
|
|
41
57
|
function $32ee6db03f46d8dd$export$54ec01a60f47d33d(props) {
|
|
42
58
|
const { children: children , ...rest } = props;
|
|
43
|
-
return /*#__PURE__*/ (0, $
|
|
59
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledTable, {
|
|
44
60
|
...rest,
|
|
45
61
|
children: children
|
|
46
62
|
});
|
|
47
63
|
}
|
|
48
64
|
// Row
|
|
49
65
|
const $32ee6db03f46d8dd$var$RowWrapper = (props = {})=>{
|
|
50
|
-
return /*#__PURE__*/ (0, $
|
|
66
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
51
67
|
as: "tr",
|
|
52
68
|
...props
|
|
53
69
|
});
|
|
54
70
|
};
|
|
55
|
-
const $32ee6db03f46d8dd$var$StyledRow = (0, $
|
|
71
|
+
const $32ee6db03f46d8dd$var$StyledRow = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$RowWrapper)(()=>(0, $gGrEF$css)`
|
|
56
72
|
display: table-row;
|
|
57
73
|
|
|
58
74
|
&:not([hidden]) {
|
|
@@ -61,19 +77,19 @@ const $32ee6db03f46d8dd$var$StyledRow = (0, $7XdDa$styledcomponents)($32ee6db03f
|
|
|
61
77
|
`);
|
|
62
78
|
function $32ee6db03f46d8dd$export$b05581f4e764e162(props) {
|
|
63
79
|
const { children: children , ...rest } = props;
|
|
64
|
-
return /*#__PURE__*/ (0, $
|
|
80
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledRow, {
|
|
65
81
|
...rest,
|
|
66
82
|
children: children
|
|
67
83
|
});
|
|
68
84
|
}
|
|
69
85
|
// Cell
|
|
70
86
|
const $32ee6db03f46d8dd$var$CellWrapper = (props = {})=>{
|
|
71
|
-
return /*#__PURE__*/ (0, $
|
|
87
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
72
88
|
as: "td",
|
|
73
89
|
...props
|
|
74
90
|
});
|
|
75
91
|
};
|
|
76
|
-
const $32ee6db03f46d8dd$var$StyledCell = (0, $
|
|
92
|
+
const $32ee6db03f46d8dd$var$StyledCell = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$CellWrapper)(()=>(0, $gGrEF$css)`
|
|
77
93
|
display: table-cell;
|
|
78
94
|
|
|
79
95
|
&:not([hidden]) {
|
|
@@ -82,7 +98,7 @@ const $32ee6db03f46d8dd$var$StyledCell = (0, $7XdDa$styledcomponents)($32ee6db03
|
|
|
82
98
|
`);
|
|
83
99
|
function $32ee6db03f46d8dd$export$1e4baea7053fc0e3(props) {
|
|
84
100
|
const { children: children , ...rest } = props;
|
|
85
|
-
return /*#__PURE__*/ (0, $
|
|
101
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledCell, {
|
|
86
102
|
...rest,
|
|
87
103
|
children: children
|
|
88
104
|
});
|
|
@@ -106,37 +122,37 @@ const $e183d660634d2ba0$var$schemaExample = {
|
|
|
106
122
|
]
|
|
107
123
|
};
|
|
108
124
|
function $e183d660634d2ba0$export$2e2bcd8739ae039() {
|
|
109
|
-
return /*#__PURE__*/ (0, $
|
|
125
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
110
126
|
tone: "caution",
|
|
111
127
|
border: true,
|
|
112
128
|
radius: 2,
|
|
113
129
|
padding: 3,
|
|
114
|
-
children: /*#__PURE__*/ (0, $
|
|
130
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
115
131
|
space: 4,
|
|
116
132
|
children: [
|
|
117
|
-
/*#__PURE__*/ (0, $
|
|
133
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Text), {
|
|
118
134
|
children: [
|
|
119
135
|
"An array of language objects must be passed into the ",
|
|
120
|
-
/*#__PURE__*/ (0, $
|
|
136
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
121
137
|
children: "internationalizedArray"
|
|
122
138
|
}),
|
|
123
139
|
" ",
|
|
124
140
|
"helper function, each with an ",
|
|
125
|
-
/*#__PURE__*/ (0, $
|
|
141
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
126
142
|
children: "id"
|
|
127
143
|
}),
|
|
128
144
|
" and ",
|
|
129
|
-
/*#__PURE__*/ (0, $
|
|
145
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
130
146
|
children: "title"
|
|
131
147
|
}),
|
|
132
148
|
" field. Example:"
|
|
133
149
|
]
|
|
134
150
|
}),
|
|
135
|
-
/*#__PURE__*/ (0, $
|
|
151
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
136
152
|
padding: 2,
|
|
137
153
|
border: true,
|
|
138
154
|
radius: 2,
|
|
139
|
-
children: /*#__PURE__*/ (0, $
|
|
155
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Code), {
|
|
140
156
|
size: 1,
|
|
141
157
|
language: "javascript",
|
|
142
158
|
children: JSON.stringify($e183d660634d2ba0$var$schemaExample, null, 2)
|
|
@@ -161,10 +177,10 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
161
177
|
const { members: members , value: value , schemaType: schemaType , onChange: onChange } = props;
|
|
162
178
|
const readOnly = typeof schemaType.readOnly === "boolean" ? schemaType.readOnly : false;
|
|
163
179
|
const { options: options } = schemaType;
|
|
164
|
-
const languages = (0, $
|
|
180
|
+
const languages = (0, $gGrEF$useMemo)(()=>options?.languages ?? [], [
|
|
165
181
|
options
|
|
166
182
|
]);
|
|
167
|
-
const handleAddLanguage = (0, $
|
|
183
|
+
const handleAddLanguage = (0, $gGrEF$useCallback)((languageId)=>{
|
|
168
184
|
// Create new items
|
|
169
185
|
const newItems = languageId ? [
|
|
170
186
|
{
|
|
@@ -181,22 +197,23 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
181
197
|
// What languages are there beyond that index?
|
|
182
198
|
const remainingLanguages = languages.slice(languageIndex + 1);
|
|
183
199
|
// So what is the index in the current value array of the next language in the language array?
|
|
184
|
-
const nextLanguageIndex = languagesInUse.findIndex((l)
|
|
200
|
+
const nextLanguageIndex = languagesInUse.findIndex((l)=>// eslint-disable-next-line max-nested-callbacks
|
|
201
|
+
remainingLanguages.find((r)=>r.id === l._key));
|
|
185
202
|
// Keep local state up to date incase multiple insertions are being made
|
|
186
203
|
if (nextLanguageIndex < 0) languagesInUse.push(item);
|
|
187
204
|
else languagesInUse.splice(nextLanguageIndex, 0, item);
|
|
188
|
-
return nextLanguageIndex < 0 ? (0, $
|
|
205
|
+
return nextLanguageIndex < 0 ? (0, $gGrEF$insert)([
|
|
189
206
|
item
|
|
190
207
|
], "after", [
|
|
191
208
|
nextLanguageIndex
|
|
192
|
-
]) : (0, $
|
|
209
|
+
]) : (0, $gGrEF$insert)([
|
|
193
210
|
item
|
|
194
211
|
], "before", [
|
|
195
212
|
nextLanguageIndex
|
|
196
213
|
]);
|
|
197
214
|
});
|
|
198
215
|
onChange([
|
|
199
|
-
(0, $
|
|
216
|
+
(0, $gGrEF$setIfMissing)([]),
|
|
200
217
|
...insertions
|
|
201
218
|
]);
|
|
202
219
|
}, [
|
|
@@ -204,8 +221,8 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
204
221
|
onChange,
|
|
205
222
|
value
|
|
206
223
|
]);
|
|
207
|
-
const handleUnsetByKey = (0, $
|
|
208
|
-
onChange((0, $
|
|
224
|
+
const handleUnsetByKey = (0, $gGrEF$useCallback)((_key)=>{
|
|
225
|
+
onChange((0, $gGrEF$unset)([
|
|
209
226
|
{
|
|
210
227
|
_key: _key
|
|
211
228
|
}
|
|
@@ -214,7 +231,7 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
214
231
|
onChange
|
|
215
232
|
]);
|
|
216
233
|
// TODO: This is lazy, reordering and re-setting the whole array – it could be surgical
|
|
217
|
-
const handleRestoreOrder = (0, $
|
|
234
|
+
const handleRestoreOrder = (0, $gGrEF$useCallback)(()=>{
|
|
218
235
|
if (!value?.length) return;
|
|
219
236
|
// Create a new value array in the correct order
|
|
220
237
|
// This would also strip out values that don't have a language as the key
|
|
@@ -223,20 +240,20 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
223
240
|
if (newIndex) acc[newIndex] = v;
|
|
224
241
|
return acc;
|
|
225
242
|
}, []).filter(Boolean);
|
|
226
|
-
onChange((0, $
|
|
243
|
+
onChange((0, $gGrEF$set)(updatedValue));
|
|
227
244
|
}, [
|
|
228
245
|
languages,
|
|
229
246
|
onChange,
|
|
230
247
|
value
|
|
231
248
|
]);
|
|
232
|
-
const allKeysAreLanguages = (0, $
|
|
249
|
+
const allKeysAreLanguages = (0, $gGrEF$useMemo)(()=>{
|
|
233
250
|
return value?.every((v)=>languages.find((l)=>l?.id === v?._key));
|
|
234
251
|
}, [
|
|
235
252
|
value,
|
|
236
253
|
languages
|
|
237
254
|
]);
|
|
238
255
|
// Check languages are in the correct order
|
|
239
|
-
const languagesOutOfOrder = (0, $
|
|
256
|
+
const languagesOutOfOrder = (0, $gGrEF$useMemo)(()=>{
|
|
240
257
|
if (!value?.length) return [];
|
|
241
258
|
const languagesInUse = languages.filter((l)=>value.find((v)=>v._key === l.id));
|
|
242
259
|
return value.map((v, vIndex)=>vIndex === languagesInUse.findIndex((l)=>l.id === v._key) ? null : v).filter(Boolean);
|
|
@@ -244,60 +261,60 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
244
261
|
value,
|
|
245
262
|
languages
|
|
246
263
|
]);
|
|
247
|
-
const languagesAreValid = (0, $
|
|
264
|
+
const languagesAreValid = (0, $gGrEF$useMemo)(()=>!languages?.length || languages?.length && languages.every((item)=>item.id && item.title), [
|
|
248
265
|
languages
|
|
249
266
|
]);
|
|
250
|
-
if (!languagesAreValid) return /*#__PURE__*/ (0, $
|
|
251
|
-
return /*#__PURE__*/ (0, $
|
|
267
|
+
if (!languagesAreValid) return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $e183d660634d2ba0$export$2e2bcd8739ae039), {});
|
|
268
|
+
return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
252
269
|
space: 2,
|
|
253
270
|
children: [
|
|
254
|
-
members?.length > 0 ? /*#__PURE__*/ (0, $
|
|
255
|
-
children: /*#__PURE__*/ (0, $
|
|
256
|
-
children: members.map((member)=>/*#__PURE__*/ (0, $
|
|
271
|
+
members?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$54ec01a60f47d33d), {
|
|
272
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)("tbody", {
|
|
273
|
+
children: members.map((member)=>/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $32ee6db03f46d8dd$export$b05581f4e764e162), {
|
|
257
274
|
tone: member?.item?.validation?.length > 0 ? (0, $85e3448f0a0a82fa$export$16423358d6ebe294)(member.item.validation) : undefined,
|
|
258
275
|
children: [
|
|
259
|
-
/*#__PURE__*/ (0, $
|
|
276
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
|
|
260
277
|
style: {
|
|
261
278
|
verticalAlign: "bottom"
|
|
262
279
|
},
|
|
263
|
-
children: /*#__PURE__*/ (0, $
|
|
280
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
264
281
|
paddingY: 3,
|
|
265
282
|
paddingRight: 2,
|
|
266
|
-
children: /*#__PURE__*/ (0, $
|
|
283
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Label), {
|
|
267
284
|
muted: true,
|
|
268
285
|
size: 1,
|
|
269
286
|
children: member.key
|
|
270
287
|
})
|
|
271
288
|
})
|
|
272
289
|
}),
|
|
273
|
-
/*#__PURE__*/ (0, $
|
|
290
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
|
|
274
291
|
paddingRight: 2,
|
|
275
292
|
style: {
|
|
276
293
|
width: `100%`
|
|
277
294
|
},
|
|
278
|
-
children: /*#__PURE__*/ (0, $
|
|
295
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$MemberItem), {
|
|
279
296
|
...props,
|
|
280
297
|
member: member
|
|
281
298
|
})
|
|
282
299
|
}),
|
|
283
|
-
/*#__PURE__*/ (0, $
|
|
300
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
|
|
284
301
|
style: {
|
|
285
302
|
verticalAlign: "bottom"
|
|
286
303
|
},
|
|
287
|
-
children: /*#__PURE__*/ (0, $
|
|
304
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Flex), {
|
|
288
305
|
align: "center",
|
|
289
306
|
justify: "flex-end",
|
|
290
307
|
gap: 3,
|
|
291
308
|
children: [
|
|
292
|
-
member
|
|
309
|
+
member?.item?.validation?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
293
310
|
paddingLeft: 2,
|
|
294
|
-
children: /*#__PURE__*/ (0, $
|
|
311
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$FormFieldValidationStatus), {
|
|
295
312
|
validation: member.item.validation
|
|
296
313
|
})
|
|
297
314
|
}) : null,
|
|
298
|
-
/*#__PURE__*/ (0, $
|
|
315
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
299
316
|
mode: "ghost",
|
|
300
|
-
icon: (0, $
|
|
317
|
+
icon: (0, $gGrEF$RemoveIcon),
|
|
301
318
|
tone: "critical",
|
|
302
319
|
disabled: typeof readOnly === "boolean" ? readOnly : false,
|
|
303
320
|
onClick: ()=>handleUnsetByKey(member.key)
|
|
@@ -309,33 +326,33 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
309
326
|
}, member.key))
|
|
310
327
|
})
|
|
311
328
|
}) : null,
|
|
312
|
-
languagesOutOfOrder.length > 0 && allKeysAreLanguages ? /*#__PURE__*/ (0, $
|
|
329
|
+
languagesOutOfOrder.length > 0 && allKeysAreLanguages ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
313
330
|
tone: "caution",
|
|
314
|
-
icon: (0, $
|
|
331
|
+
icon: (0, $gGrEF$RestoreIcon),
|
|
315
332
|
onClick: ()=>handleRestoreOrder(),
|
|
316
333
|
text: "Restore order of languages"
|
|
317
334
|
}) : null,
|
|
318
|
-
|
|
335
|
+
languages?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
319
336
|
space: 2,
|
|
320
337
|
children: [
|
|
321
|
-
/*#__PURE__*/ (0, $
|
|
338
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Grid), {
|
|
322
339
|
columns: Math.min(languages.length, 5),
|
|
323
340
|
gap: 2,
|
|
324
|
-
children: languages.map((language)=>/*#__PURE__*/ (0, $
|
|
341
|
+
children: languages.map((language)=>/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
325
342
|
tone: "primary",
|
|
326
343
|
mode: "ghost",
|
|
327
344
|
fontSize: 1,
|
|
328
345
|
disabled: readOnly || Boolean(value?.find((item)=>item._key === language.id)),
|
|
329
346
|
text: language.id.toUpperCase(),
|
|
330
|
-
icon: (0, $
|
|
347
|
+
icon: (0, $gGrEF$AddIcon),
|
|
331
348
|
onClick: ()=>handleAddLanguage(language.id)
|
|
332
349
|
}, language.id))
|
|
333
350
|
}),
|
|
334
|
-
/*#__PURE__*/ (0, $
|
|
351
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
335
352
|
tone: "primary",
|
|
336
353
|
mode: "ghost",
|
|
337
354
|
disabled: readOnly || value && value?.length >= languages?.length,
|
|
338
|
-
icon: (0, $
|
|
355
|
+
icon: (0, $gGrEF$AddIcon),
|
|
339
356
|
text: value?.length ? `Add missing languages` : `Add all languages`,
|
|
340
357
|
onClick: ()=>handleAddLanguage()
|
|
341
358
|
})
|
|
@@ -346,22 +363,14 @@ function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
|
|
|
346
363
|
}
|
|
347
364
|
|
|
348
365
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
type
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
config?.validation
|
|
358
|
-
];
|
|
359
|
-
return (0, $7XdDa$defineField)({
|
|
360
|
-
name: name,
|
|
361
|
-
title: config?.title ?? undefined,
|
|
362
|
-
group: config?.group ?? undefined,
|
|
363
|
-
hidden: config?.hidden ?? undefined,
|
|
364
|
-
readOnly: config?.readOnly ?? undefined,
|
|
366
|
+
var $581a585556642695$export$2e2bcd8739ae039 = (config)=>{
|
|
367
|
+
const { languages: languages , type: type } = config;
|
|
368
|
+
const typeName = typeof type === `string` ? type : type.name;
|
|
369
|
+
const arrayName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName);
|
|
370
|
+
const objectName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName, true);
|
|
371
|
+
return (0, $gGrEF$defineField)({
|
|
372
|
+
name: arrayName,
|
|
373
|
+
title: "Internationalized array",
|
|
365
374
|
type: "array",
|
|
366
375
|
components: {
|
|
367
376
|
input: (0, $e3540aa1271cf9b1$export$2e2bcd8739ae039)
|
|
@@ -370,33 +379,12 @@ function $e7e26cac6788e7ab$export$bec7eb13daf35f0e(config = $e7e26cac6788e7ab$va
|
|
|
370
379
|
languages: languages
|
|
371
380
|
},
|
|
372
381
|
of: [
|
|
373
|
-
{
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
name: "value",
|
|
378
|
-
type: type
|
|
379
|
-
},
|
|
380
|
-
],
|
|
381
|
-
preview: {
|
|
382
|
-
select: {
|
|
383
|
-
title: "value",
|
|
384
|
-
key: "_key"
|
|
385
|
-
},
|
|
386
|
-
prepare (select) {
|
|
387
|
-
const { title: title , key: key } = select;
|
|
388
|
-
return {
|
|
389
|
-
title: title,
|
|
390
|
-
subtitle: key.toUpperCase()
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
},
|
|
382
|
+
(0, $gGrEF$defineField)({
|
|
383
|
+
name: objectName,
|
|
384
|
+
type: objectName
|
|
385
|
+
})
|
|
395
386
|
],
|
|
396
|
-
|
|
397
|
-
validation: (rule)=>{
|
|
398
|
-
const rules = [];
|
|
399
|
-
rules.push(rule.custom((value, context)=>{
|
|
387
|
+
validation: (rule)=>rule.max(languages?.length).custom((value, context)=>{
|
|
400
388
|
const { languages: contextLanguages } = context?.type?.options ?? {};
|
|
401
389
|
const nonLanguageKeys = value?.length ? value.filter((item)=>!contextLanguages.find((language)=>item._key === language.id)) : [];
|
|
402
390
|
if (nonLanguageKeys.length) return {
|
|
@@ -432,18 +420,61 @@ function $e7e26cac6788e7ab$export$bec7eb13daf35f0e(config = $e7e26cac6788e7ab$va
|
|
|
432
420
|
])
|
|
433
421
|
};
|
|
434
422
|
return true;
|
|
435
|
-
})
|
|
436
|
-
if (languages?.length) rules.push(rule.max(languages.length));
|
|
437
|
-
return [
|
|
438
|
-
...rules,
|
|
439
|
-
...configValidation
|
|
440
|
-
].filter(Boolean);
|
|
441
|
-
}
|
|
423
|
+
})
|
|
442
424
|
});
|
|
443
|
-
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
var $3d48ee33fe42e7bc$export$2e2bcd8739ae039 = (config)=>{
|
|
431
|
+
const { type: type } = config;
|
|
432
|
+
const typeName = typeof type === `string` ? type : type.name;
|
|
433
|
+
const objectName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName, true);
|
|
434
|
+
return (0, $gGrEF$defineField)({
|
|
435
|
+
name: objectName,
|
|
436
|
+
title: `Internationalized array ${type}`,
|
|
437
|
+
type: "object",
|
|
438
|
+
fields: [
|
|
439
|
+
typeof type === `string` ? (0, $gGrEF$defineField)({
|
|
440
|
+
name: "value",
|
|
441
|
+
type: type
|
|
442
|
+
}) : {
|
|
443
|
+
...type,
|
|
444
|
+
name: "value"
|
|
445
|
+
},
|
|
446
|
+
]
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
const $91a08798d183e77b$var$CONFIG_DEFAULT = {
|
|
452
|
+
languages: [],
|
|
453
|
+
fieldTypes: []
|
|
454
|
+
};
|
|
455
|
+
const $91a08798d183e77b$export$bec7eb13daf35f0e = (0, $gGrEF$createPlugin)((config = $91a08798d183e77b$var$CONFIG_DEFAULT)=>{
|
|
456
|
+
const { languages: languages , fieldTypes: fieldTypes } = {
|
|
457
|
+
...$91a08798d183e77b$var$CONFIG_DEFAULT,
|
|
458
|
+
...config
|
|
459
|
+
};
|
|
460
|
+
return {
|
|
461
|
+
name: "sanity-plugin-internationalized-array",
|
|
462
|
+
schema: {
|
|
463
|
+
types: [
|
|
464
|
+
...fieldTypes.map((type)=>(0, $581a585556642695$export$2e2bcd8739ae039)({
|
|
465
|
+
type: type,
|
|
466
|
+
languages: languages
|
|
467
|
+
})),
|
|
468
|
+
...fieldTypes.map((type)=>(0, $3d48ee33fe42e7bc$export$2e2bcd8739ae039)({
|
|
469
|
+
type: type
|
|
470
|
+
})),
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
});
|
|
444
475
|
|
|
445
476
|
|
|
446
477
|
|
|
447
478
|
|
|
448
|
-
export {$
|
|
479
|
+
export {$91a08798d183e77b$export$bec7eb13daf35f0e as internationalizedArray};
|
|
449
480
|
//# sourceMappingURL=index.js.map
|