sanity-plugin-internationalized-array 1.1.1 → 1.2.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/lib/esm/index.js DELETED
@@ -1,487 +0,0 @@
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 {useToast as $gGrEF$useToast, 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(``);
29
- }
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
- // Wrappers required because of bug with passing down "as" prop
41
- // https://github.com/styled-components/styled-components/issues/2449
42
- // Table
43
- const $32ee6db03f46d8dd$var$TableWrapper = (props = {})=>{
44
- return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
45
- as: "table",
46
- ...props
47
- });
48
- };
49
- const $32ee6db03f46d8dd$var$StyledTable = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$TableWrapper)(()=>(0, $gGrEF$css)`
50
- display: table;
51
- width: 100%;
52
-
53
- &:not([hidden]) {
54
- display: table;
55
- }
56
- `);
57
- function $32ee6db03f46d8dd$export$54ec01a60f47d33d(props) {
58
- const { children: children , ...rest } = props;
59
- return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledTable, {
60
- ...rest,
61
- children: children
62
- });
63
- }
64
- // Row
65
- const $32ee6db03f46d8dd$var$RowWrapper = (props = {})=>{
66
- return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
67
- as: "tr",
68
- ...props
69
- });
70
- };
71
- const $32ee6db03f46d8dd$var$StyledRow = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$RowWrapper)(()=>(0, $gGrEF$css)`
72
- display: table-row;
73
-
74
- &:not([hidden]) {
75
- display: table-row;
76
- }
77
- `);
78
- function $32ee6db03f46d8dd$export$b05581f4e764e162(props) {
79
- const { children: children , ...rest } = props;
80
- return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledRow, {
81
- ...rest,
82
- children: children
83
- });
84
- }
85
- // Cell
86
- const $32ee6db03f46d8dd$var$CellWrapper = (props = {})=>{
87
- return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
88
- as: "td",
89
- ...props
90
- });
91
- };
92
- const $32ee6db03f46d8dd$var$StyledCell = (0, $gGrEF$styledcomponents)($32ee6db03f46d8dd$var$CellWrapper)(()=>(0, $gGrEF$css)`
93
- display: table-cell;
94
-
95
- &:not([hidden]) {
96
- display: table-cell;
97
- }
98
- `);
99
- function $32ee6db03f46d8dd$export$1e4baea7053fc0e3(props) {
100
- const { children: children , ...rest } = props;
101
- return /*#__PURE__*/ (0, $gGrEF$jsx)($32ee6db03f46d8dd$var$StyledCell, {
102
- ...rest,
103
- children: children
104
- });
105
- }
106
-
107
-
108
-
109
-
110
-
111
-
112
- const $e183d660634d2ba0$var$schemaExample = {
113
- languages: [
114
- {
115
- id: "en",
116
- title: "English"
117
- },
118
- {
119
- id: "no",
120
- title: "Norsk"
121
- },
122
- ]
123
- };
124
- function $e183d660634d2ba0$export$2e2bcd8739ae039() {
125
- return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
126
- tone: "caution",
127
- border: true,
128
- radius: 2,
129
- padding: 3,
130
- children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
131
- space: 4,
132
- children: [
133
- /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Text), {
134
- children: [
135
- "An array of language objects must be passed into the ",
136
- /*#__PURE__*/ (0, $gGrEF$jsx)("code", {
137
- children: "internationalizedArray"
138
- }),
139
- " ",
140
- "helper function, each with an ",
141
- /*#__PURE__*/ (0, $gGrEF$jsx)("code", {
142
- children: "id"
143
- }),
144
- " and ",
145
- /*#__PURE__*/ (0, $gGrEF$jsx)("code", {
146
- children: "title"
147
- }),
148
- " field. Example:"
149
- ]
150
- }),
151
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
152
- padding: 2,
153
- border: true,
154
- radius: 2,
155
- children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Code), {
156
- size: 1,
157
- language: "javascript",
158
- children: JSON.stringify($e183d660634d2ba0$var$schemaExample, null, 2)
159
- })
160
- })
161
- ]
162
- })
163
- });
164
- }
165
-
166
-
167
- function $85e3448f0a0a82fa$export$16423358d6ebe294(validations) {
168
- if (!validations.length) return `default`;
169
- const validationLevels = validations.map((v)=>v.level);
170
- if (validationLevels.includes("error")) return `critical`;
171
- else if (validationLevels.includes("warning")) return `caution`;
172
- return `default`;
173
- }
174
-
175
-
176
- function $e3540aa1271cf9b1$export$2e2bcd8739ae039(props) {
177
- const { members: members , value: value , schemaType: schemaType , onChange: onChange } = props;
178
- const readOnly = typeof schemaType.readOnly === "boolean" ? schemaType.readOnly : false;
179
- const { options: options } = schemaType;
180
- const toast = (0, $gGrEF$useToast)();
181
- const languages = (0, $gGrEF$useMemo)(()=>options?.languages ?? [], [
182
- options
183
- ]);
184
- const handleAddLanguage = (0, $gGrEF$useCallback)((languageId)=>{
185
- // Create new items
186
- const newItems = languageId ? [
187
- {
188
- _key: languageId
189
- }
190
- ] : languages.filter((language)=>value?.length ? !value.find((v)=>v._key === language.id) : true).map((language)=>({
191
- _key: language.id
192
- }));
193
- // Insert new items in the correct order
194
- const languagesInUse = value?.length ? value.map((v)=>v) : [];
195
- const insertions = newItems.map((item)=>{
196
- // What's the original index of this language?
197
- const languageIndex = languages.findIndex((l)=>item._key === l.id);
198
- // What languages are there beyond that index?
199
- const remainingLanguages = languages.slice(languageIndex + 1);
200
- // So what is the index in the current value array of the next language in the language array?
201
- const nextLanguageIndex = languagesInUse.findIndex((l)=>// eslint-disable-next-line max-nested-callbacks
202
- remainingLanguages.find((r)=>r.id === l._key));
203
- // Keep local state up to date incase multiple insertions are being made
204
- if (nextLanguageIndex < 0) languagesInUse.push(item);
205
- else languagesInUse.splice(nextLanguageIndex, 0, item);
206
- return nextLanguageIndex < 0 ? (0, $gGrEF$insert)([
207
- item
208
- ], "after", [
209
- nextLanguageIndex
210
- ]) : (0, $gGrEF$insert)([
211
- item
212
- ], "before", [
213
- nextLanguageIndex
214
- ]);
215
- });
216
- onChange([
217
- (0, $gGrEF$setIfMissing)([]),
218
- ...insertions
219
- ]);
220
- }, [
221
- languages,
222
- onChange,
223
- value
224
- ]);
225
- const handleUnsetByKey = (0, $gGrEF$useCallback)((_key)=>{
226
- onChange((0, $gGrEF$unset)([
227
- {
228
- _key: _key
229
- }
230
- ]));
231
- }, [
232
- onChange
233
- ]);
234
- // TODO: This is lazy, reordering and re-setting the whole array – it could be surgical
235
- const handleRestoreOrder = (0, $gGrEF$useCallback)(()=>{
236
- if (!value?.length) return;
237
- console.log(value);
238
- // Create a new value array in the correct order
239
- // This would also strip out values that don't have a language as the key
240
- const updatedValue = value.reduce((acc, v)=>{
241
- const newIndex = languages.findIndex((l)=>l.id === v?._key);
242
- if (newIndex > -1) acc[newIndex] = v;
243
- return acc;
244
- }, []).filter(Boolean);
245
- if (value.length !== updatedValue.length) toast.push({
246
- title: "There was an error reordering languages",
247
- status: "warning"
248
- });
249
- onChange((0, $gGrEF$set)(updatedValue));
250
- }, [
251
- toast,
252
- languages,
253
- onChange,
254
- value
255
- ]);
256
- const allKeysAreLanguages = (0, $gGrEF$useMemo)(()=>{
257
- return value?.every((v)=>languages.find((l)=>l?.id === v?._key));
258
- }, [
259
- value,
260
- languages
261
- ]);
262
- // Check languages are in the correct order
263
- const languagesOutOfOrder = (0, $gGrEF$useMemo)(()=>{
264
- if (!value?.length) return [];
265
- const languagesInUse = languages.filter((l)=>value.find((v)=>v._key === l.id));
266
- return value.map((v, vIndex)=>vIndex === languagesInUse.findIndex((l)=>l.id === v._key) ? null : v).filter(Boolean);
267
- }, [
268
- value,
269
- languages
270
- ]);
271
- const languagesAreValid = (0, $gGrEF$useMemo)(()=>!languages?.length || languages?.length && languages.every((item)=>item.id && item.title), [
272
- languages
273
- ]);
274
- if (!languagesAreValid) return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $e183d660634d2ba0$export$2e2bcd8739ae039), {});
275
- return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
276
- space: 2,
277
- children: [
278
- members?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$54ec01a60f47d33d), {
279
- children: /*#__PURE__*/ (0, $gGrEF$jsx)("tbody", {
280
- children: members.map((member)=>/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $32ee6db03f46d8dd$export$b05581f4e764e162), {
281
- tone: member?.item?.validation?.length > 0 ? (0, $85e3448f0a0a82fa$export$16423358d6ebe294)(member.item.validation) : undefined,
282
- children: [
283
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
284
- style: {
285
- verticalAlign: "bottom"
286
- },
287
- children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
288
- paddingY: 3,
289
- paddingRight: 2,
290
- children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Label), {
291
- muted: true,
292
- size: 1,
293
- children: member.key
294
- })
295
- })
296
- }),
297
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
298
- paddingRight: 2,
299
- style: {
300
- width: `100%`
301
- },
302
- children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$MemberItem), {
303
- ...props,
304
- member: member
305
- })
306
- }),
307
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $32ee6db03f46d8dd$export$1e4baea7053fc0e3), {
308
- style: {
309
- verticalAlign: "bottom"
310
- },
311
- children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Flex), {
312
- align: "center",
313
- justify: "flex-end",
314
- gap: 3,
315
- children: [
316
- member?.item?.validation?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
317
- paddingLeft: 2,
318
- children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$FormFieldValidationStatus), {
319
- validation: member.item.validation
320
- })
321
- }) : null,
322
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
323
- mode: "ghost",
324
- icon: (0, $gGrEF$RemoveIcon),
325
- tone: "critical",
326
- disabled: typeof readOnly === "boolean" ? readOnly : false,
327
- onClick: ()=>handleUnsetByKey(member.key)
328
- })
329
- ]
330
- })
331
- })
332
- ]
333
- }, member.key))
334
- })
335
- }) : null,
336
- languagesOutOfOrder.length > 0 && allKeysAreLanguages ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
337
- tone: "caution",
338
- icon: (0, $gGrEF$RestoreIcon),
339
- onClick: ()=>handleRestoreOrder(),
340
- text: "Restore order of languages"
341
- }) : null,
342
- languages?.length > 0 ? /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
343
- space: 2,
344
- children: [
345
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Grid), {
346
- columns: Math.min(languages.length, 5),
347
- gap: 2,
348
- children: languages.map((language)=>/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
349
- tone: "primary",
350
- mode: "ghost",
351
- fontSize: 1,
352
- disabled: readOnly || Boolean(value?.find((item)=>item._key === language.id)),
353
- text: language.id.toUpperCase(),
354
- icon: (0, $gGrEF$AddIcon),
355
- onClick: ()=>handleAddLanguage(language.id)
356
- }, language.id))
357
- }),
358
- /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
359
- tone: "primary",
360
- mode: "ghost",
361
- disabled: readOnly || value && value?.length >= languages?.length,
362
- icon: (0, $gGrEF$AddIcon),
363
- text: value?.length ? `Add missing languages` : `Add all languages`,
364
- onClick: ()=>handleAddLanguage()
365
- })
366
- ]
367
- }) : null
368
- ]
369
- });
370
- }
371
-
372
-
373
- var $581a585556642695$export$2e2bcd8739ae039 = (config)=>{
374
- const { languages: languages , type: type } = config;
375
- const typeName = typeof type === `string` ? type : type.name;
376
- const arrayName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName);
377
- const objectName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName, true);
378
- return (0, $gGrEF$defineField)({
379
- name: arrayName,
380
- title: "Internationalized array",
381
- type: "array",
382
- components: {
383
- input: (0, $e3540aa1271cf9b1$export$2e2bcd8739ae039)
384
- },
385
- options: {
386
- languages: languages
387
- },
388
- of: [
389
- (0, $gGrEF$defineField)({
390
- name: objectName,
391
- type: objectName
392
- })
393
- ],
394
- validation: (rule)=>rule.max(languages?.length).custom((value, context)=>{
395
- const { languages: contextLanguages } = context?.type?.options ?? {};
396
- const nonLanguageKeys = value?.length ? value.filter((item)=>!contextLanguages.find((language)=>item._key === language.id)) : [];
397
- if (nonLanguageKeys.length) return {
398
- message: `Array item keys must be valid languages registered to the field type`,
399
- paths: nonLanguageKeys.map((item)=>[
400
- {
401
- _key: item._key
402
- }
403
- ])
404
- };
405
- const valuesByLanguage = value?.length ? value.filter((item)=>Boolean(item?._key)).reduce((acc, cur)=>{
406
- if (acc[cur._key]) return {
407
- ...acc,
408
- [cur._key]: [
409
- ...acc[cur._key],
410
- cur
411
- ]
412
- };
413
- return {
414
- ...acc,
415
- [cur._key]: [
416
- cur
417
- ]
418
- };
419
- }, {}) : {};
420
- const duplicateValues = Object.values(valuesByLanguage).filter((item)=>item?.length > 1).flat();
421
- if (duplicateValues.length) return {
422
- message: "There can only be one field per language",
423
- paths: duplicateValues.map((item)=>[
424
- {
425
- _key: item._key
426
- }
427
- ])
428
- };
429
- return true;
430
- })
431
- });
432
- };
433
-
434
-
435
-
436
-
437
- var $3d48ee33fe42e7bc$export$2e2bcd8739ae039 = (config)=>{
438
- const { type: type } = config;
439
- const typeName = typeof type === `string` ? type : type.name;
440
- const objectName = (0, $5c51df8bc000fd76$export$ab1ce2a474f41f52)(typeName, true);
441
- return (0, $gGrEF$defineField)({
442
- name: objectName,
443
- title: `Internationalized array ${type}`,
444
- type: "object",
445
- fields: [
446
- typeof type === `string` ? (0, $gGrEF$defineField)({
447
- name: "value",
448
- type: type
449
- }) : {
450
- ...type,
451
- name: "value"
452
- },
453
- ]
454
- });
455
- };
456
-
457
-
458
- const $91a08798d183e77b$var$CONFIG_DEFAULT = {
459
- languages: [],
460
- fieldTypes: []
461
- };
462
- const $91a08798d183e77b$export$bec7eb13daf35f0e = (0, $gGrEF$createPlugin)((config = $91a08798d183e77b$var$CONFIG_DEFAULT)=>{
463
- const { languages: languages , fieldTypes: fieldTypes } = {
464
- ...$91a08798d183e77b$var$CONFIG_DEFAULT,
465
- ...config
466
- };
467
- return {
468
- name: "sanity-plugin-internationalized-array",
469
- schema: {
470
- types: [
471
- ...fieldTypes.map((type)=>(0, $581a585556642695$export$2e2bcd8739ae039)({
472
- type: type,
473
- languages: languages
474
- })),
475
- ...fieldTypes.map((type)=>(0, $3d48ee33fe42e7bc$export$2e2bcd8739ae039)({
476
- type: type
477
- })),
478
- ]
479
- }
480
- };
481
- });
482
-
483
-
484
-
485
-
486
- export {$91a08798d183e77b$export$bec7eb13daf35f0e as internationalizedArray};
487
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;ACAA;ACAA;ACAO,SAAS,yCAAS,CAAC,MAAc,EAAE;IACxC,OAAO,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC,GAAK,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;CAC9D;AAEM,SAAS,yCAAS,CAAC,MAAc,EAAE;IACxC,OAAO,MAAM,CACV,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CACV,GAAG,CAAC,CAAC,IAAI,GAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAC3D,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACb;AAEM,SAAS,yCAAU,CAAC,MAAc,EAAE;IACzC,OAAO,yCAAS,CAAC,yCAA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AQ;QACd,MAAM,EAAE;YACN,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,GAEpB,CAAA,GAAA,kBAAW,CAAA,CAAC;gBACV,IAAI,EAAE,OAAO;sBACb,IAAI;aACL,CAAC,GAEF;gBAAC,GAAG,IAAI;gBAAE,IAAI,EAAE,OAAO;aAAC;SAC7B;KACF,CAAC,CAAA;CACH;;;APvBD,MAAM,oCAAc,GAAG;IACrB,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,EAAE;CACf;AAEM,MAAM,yCAAsB,GAAG,CAAA,GAAA,mBAAY,CAAA,CAAe,CAAC,MAAM,GAAG,oCAAc,GAAK;IAC5F,MAAM,aAAC,SAAS,CAAA,cAAE,UAAU,CAAA,EAAC,GAAG;QAAC,GAAG,oCAAc;QAAE,GAAG,MAAM;KAAC;IAE9D,OAAO;QACL,IAAI,EAAE,uCAAuC;QAC7C,MAAM,EAAE;YACN,KAAK,EAAE;mBACF,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,GAAK,CAAA,GAAA,wCAAK,CAAA,CAAC;8BAAC,IAAI;mCAAE,SAAS;qBAAC,CAAC,CAAC;mBAClD,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,GAAK,CAAA,GAAA,wCAAM,CAAA,CAAC;8BAAC,IAAI;qBAAC,CAAC,CAAC;aAC5C;SACF;KACF,CAAA;CACF,CAAC;;ADtBF","sources":["src/index.ts","src/plugin.tsx","src/schema/array.ts","src/components/createFieldName.ts","src/components/InternationalizedArrayInput.tsx","src/components/Table.tsx","src/components/Feedback.tsx","src/components/getToneFromValidation.ts","src/schema/object.ts"],"sourcesContent":["export {internationalizedArray} from './plugin'\n","import {createPlugin} from 'sanity'\nimport {PluginConfig} from './types'\nimport array from './schema/array'\nimport object from './schema/object'\n\nconst CONFIG_DEFAULT = {\n languages: [],\n fieldTypes: [],\n}\n\nexport const internationalizedArray = createPlugin<PluginConfig>((config = CONFIG_DEFAULT) => {\n const {languages, fieldTypes} = {...CONFIG_DEFAULT, ...config}\n\n return {\n name: 'sanity-plugin-internationalized-array',\n schema: {\n types: [\n ...fieldTypes.map((type) => array({type, languages})),\n ...fieldTypes.map((type) => object({type})),\n ],\n },\n }\n})\n","import {defineField, Rule, Schema} from 'sanity'\n\nimport {createFieldName} from '../components/createFieldName'\nimport InternationalizedArrayInput from '../components/InternationalizedArrayInput'\nimport {Language, Value} from '../types'\n\ntype ArrayFactoryConfig = {\n languages: Language[]\n type: string | Schema.FieldDefinition\n}\n\nexport default (config: ArrayFactoryConfig): Schema.FieldDefinition<'array'> => {\n const {languages, type} = config\n const typeName = typeof type === `string` ? type : type.name\n const arrayName = createFieldName(typeName)\n const objectName = createFieldName(typeName, true)\n\n return defineField({\n name: arrayName,\n title: 'Internationalized array',\n type: 'array',\n components: {input: InternationalizedArrayInput},\n options: {languages},\n of: [defineField({name: objectName, type: objectName})],\n validation: (rule: Rule) =>\n rule.max(languages?.length).custom<Value[]>((value, context) => {\n const {languages: contextLanguages}: {languages: Language[]} = context?.type?.options ?? {}\n const nonLanguageKeys = value?.length\n ? value.filter((item) => !contextLanguages.find((language) => item._key === language.id))\n : []\n if (nonLanguageKeys.length) {\n return {\n message: `Array item keys must be valid languages registered to the field type`,\n paths: nonLanguageKeys.map((item) => [{_key: item._key}]),\n }\n }\n\n // Ensure there's no duplicate `language` fields\n type KeyedValues = {\n [key: string]: Value[]\n }\n\n const valuesByLanguage = value?.length\n ? value\n .filter((item) => Boolean(item?._key))\n .reduce((acc, cur) => {\n if (acc[cur._key]) {\n return {...acc, [cur._key]: [...acc[cur._key], cur]}\n }\n return {\n ...acc,\n [cur._key]: [cur],\n }\n }, {} as KeyedValues)\n : {}\n const duplicateValues = Object.values(valuesByLanguage)\n .filter((item) => item?.length > 1)\n .flat()\n if (duplicateValues.length) {\n return {\n message: 'There can only be one field per language',\n paths: duplicateValues.map((item) => [{_key: item._key}]),\n }\n }\n\n return true\n }),\n })\n}\n","export function camelCase(string: string) {\n return string.replace(/-([a-z])/g, (g) => g[1].toUpperCase())\n}\n\nexport function titleCase(string: string) {\n return string\n .split(` `)\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(` `)\n}\n\nexport function pascalCase(string: string) {\n return titleCase(camelCase(string))\n}\n\nexport function createFieldName(name: string, addValue = false): string {\n return addValue\n ? [`internationalizedArray`, pascalCase(name), `Value`].join(``)\n : [`internationalizedArray`, pascalCase(name)].join(``)\n}\n","import React, {useCallback, useMemo} from 'react'\nimport {\n ArrayOfObjectsInputProps,\n MemberItem,\n unset,\n insert,\n set,\n setIfMissing,\n FormFieldValidationStatus,\n} from 'sanity/form'\nimport {Box, Button, Flex, Grid, Label, Stack, useToast} from '@sanity/ui'\n\nimport {Language, Value, ArraySchemaWithLanguageOptions} from '../types'\nimport {Table, TableCell, TableRow} from './Table'\nimport {AddIcon, RemoveIcon, RestoreIcon} from '@sanity/icons'\nimport Feedback from './Feedback'\nimport {getToneFromValidation} from './getToneFromValidation'\n\nexport type InternationalizedArrayInputProps = ArrayOfObjectsInputProps<\n Value,\n ArraySchemaWithLanguageOptions\n>\n\nexport default function InternationalizedArrayInput(props: InternationalizedArrayInputProps) {\n const {members, value, schemaType, onChange} = props\n const readOnly = typeof schemaType.readOnly === 'boolean' ? schemaType.readOnly : false\n const {options} = schemaType\n const toast = useToast()\n\n const languages: Language[] = useMemo(() => options?.languages ?? [], [options])\n\n const handleAddLanguage = useCallback(\n (languageId?: string) => {\n // Create new items\n const newItems = languageId\n ? // Just one for this language\n [{_key: languageId}]\n : // Or one for every missing language\n languages\n .filter((language) =>\n value?.length ? !value.find((v) => v._key === language.id) : true\n )\n .map((language) => ({_key: language.id}))\n\n // Insert new items in the correct order\n const languagesInUse = value?.length ? value.map((v) => v) : []\n\n const insertions = newItems.map((item) => {\n // What's the original index of this language?\n const languageIndex = languages.findIndex((l) => item._key === l.id)\n\n // What languages are there beyond that index?\n const remainingLanguages = languages.slice(languageIndex + 1)\n\n // So what is the index in the current value array of the next language in the language array?\n const nextLanguageIndex = languagesInUse.findIndex((l) =>\n // eslint-disable-next-line max-nested-callbacks\n remainingLanguages.find((r) => r.id === l._key)\n )\n\n // Keep local state up to date incase multiple insertions are being made\n if (nextLanguageIndex < 0) {\n languagesInUse.push(item)\n } else {\n languagesInUse.splice(nextLanguageIndex, 0, item)\n }\n\n return nextLanguageIndex < 0\n ? // No next language (-1), add to end of array\n insert([item], 'after', [nextLanguageIndex])\n : // Next language found, insert before that\n insert([item], 'before', [nextLanguageIndex])\n })\n\n onChange([setIfMissing([]), ...insertions])\n },\n [languages, onChange, value]\n )\n\n const handleUnsetByKey = useCallback(\n (_key: string) => {\n onChange(unset([{_key}]))\n },\n [onChange]\n )\n\n // TODO: This is lazy, reordering and re-setting the whole array – it could be surgical\n const handleRestoreOrder = useCallback(() => {\n if (!value?.length) {\n return\n }\n\n console.log(value)\n\n // Create a new value array in the correct order\n // This would also strip out values that don't have a language as the key\n const updatedValue = value\n .reduce((acc, v) => {\n const newIndex = languages.findIndex((l) => l.id === v?._key)\n\n if (newIndex > -1) {\n acc[newIndex] = v\n }\n\n return acc\n }, [] as Value[])\n .filter(Boolean)\n\n if (value.length !== updatedValue.length) {\n toast.push({\n title: 'There was an error reordering languages',\n status: 'warning',\n })\n }\n\n onChange(set(updatedValue))\n }, [toast, languages, onChange, value])\n\n const allKeysAreLanguages = useMemo(() => {\n return value?.every((v) => languages.find((l) => l?.id === v?._key))\n }, [value, languages])\n\n // Check languages are in the correct order\n const languagesOutOfOrder = useMemo(() => {\n if (!value?.length) {\n return []\n }\n\n const languagesInUse = languages.filter((l) => value.find((v) => v._key === l.id))\n\n return value\n .map((v, vIndex) => (vIndex === languagesInUse.findIndex((l) => l.id === v._key) ? null : v))\n .filter(Boolean)\n }, [value, languages])\n\n const languagesAreValid = useMemo(\n () =>\n !languages?.length || (languages?.length && languages.every((item) => item.id && item.title)),\n [languages]\n )\n\n if (!languagesAreValid) {\n return <Feedback />\n }\n\n return (\n <Stack space={2}>\n {members?.length > 0 ? (\n <Table>\n <tbody>\n {members.map((member) => (\n <TableRow\n key={member.key}\n tone={\n member?.item?.validation?.length > 0\n ? getToneFromValidation(member.item.validation)\n : undefined\n }\n >\n <TableCell style={{verticalAlign: 'bottom'}}>\n <Box paddingY={3} paddingRight={2}>\n <Label muted size={1}>\n {member.key}\n </Label>\n </Box>\n </TableCell>\n <TableCell paddingRight={2} style={{width: `100%`}}>\n {/* This renders the entire field default with title */}\n <MemberItem {...props} member={member} />\n </TableCell>\n <TableCell style={{verticalAlign: 'bottom'}}>\n <Flex align=\"center\" justify=\"flex-end\" gap={3}>\n {/* Possibly unncessary, validation shows up in <MemberItem /> */}\n {member?.item?.validation?.length > 0 ? (\n <Box paddingLeft={2}>\n <FormFieldValidationStatus validation={member.item.validation} />\n </Box>\n ) : null}\n <Button\n mode=\"ghost\"\n icon={RemoveIcon}\n tone=\"critical\"\n disabled={typeof readOnly === 'boolean' ? readOnly : false}\n onClick={() => handleUnsetByKey(member.key)}\n />\n </Flex>\n </TableCell>\n </TableRow>\n ))}\n </tbody>\n </Table>\n ) : null}\n\n {languagesOutOfOrder.length > 0 && allKeysAreLanguages ? (\n <Button\n tone=\"caution\"\n icon={RestoreIcon}\n onClick={() => handleRestoreOrder()}\n text=\"Restore order of languages\"\n />\n ) : null}\n\n {languages?.length > 0 ? (\n <Stack space={2}>\n {/* No more than 5 columns */}\n <Grid columns={Math.min(languages.length, 5)} gap={2}>\n {languages.map((language) => (\n <Button\n key={language.id}\n tone=\"primary\"\n mode=\"ghost\"\n fontSize={1}\n disabled={readOnly || Boolean(value?.find((item) => item._key === language.id))}\n text={language.id.toUpperCase()}\n icon={AddIcon}\n onClick={() => handleAddLanguage(language.id)}\n />\n ))}\n </Grid>\n <Button\n tone=\"primary\"\n mode=\"ghost\"\n disabled={readOnly || (value && value?.length >= languages?.length)}\n icon={AddIcon}\n text={value?.length ? `Add missing languages` : `Add all languages`}\n onClick={() => handleAddLanguage()}\n />\n </Stack>\n ) : null}\n </Stack>\n )\n}\n","import React from 'react'\nimport styled, {css} from 'styled-components'\nimport {Box, BoxProps, Card, CardProps} from '@sanity/ui'\n\n// Wrappers required because of bug with passing down \"as\" prop\n// https://github.com/styled-components/styled-components/issues/2449\n\n// Table\nconst TableWrapper = (props = {}) => {\n return <Box as=\"table\" {...props} />\n}\n\nconst StyledTable = styled(TableWrapper)(\n () =>\n css`\n display: table;\n width: 100%;\n\n &:not([hidden]) {\n display: table;\n }\n `\n)\n\ntype TableProps = BoxProps & {\n children: React.ReactNode\n style?: React.CSSProperties\n}\n\nexport function Table(props: TableProps) {\n const {children, ...rest} = props\n\n return <StyledTable {...rest}>{children}</StyledTable>\n}\n\n// Row\nconst RowWrapper = (props = {}) => {\n return <Card as=\"tr\" {...props} />\n}\n\nconst StyledRow = styled(RowWrapper)(\n () =>\n css`\n display: table-row;\n\n &:not([hidden]) {\n display: table-row;\n }\n `\n)\n\ntype TableRowProps = CardProps & {\n children: React.ReactNode\n style?: React.CSSProperties\n}\n\nexport function TableRow(props: TableRowProps) {\n const {children, ...rest} = props\n\n return <StyledRow {...rest}>{children}</StyledRow>\n}\n\n// Cell\nconst CellWrapper = (props = {}) => {\n return <Box as=\"td\" {...props} />\n}\n\nconst StyledCell = styled(CellWrapper)(\n () =>\n css`\n display: table-cell;\n\n &:not([hidden]) {\n display: table-cell;\n }\n `\n)\n\ntype TableCellProps = BoxProps & {\n children: React.ReactNode\n style?: React.CSSProperties\n}\n\nexport function TableCell(props: TableCellProps) {\n const {children, ...rest} = props\n\n return <StyledCell {...rest}>{children}</StyledCell>\n}\n","import {Text, Card, Stack, Code} from '@sanity/ui'\nimport React from 'react'\n\nconst schemaExample = {\n languages: [\n {id: 'en', title: 'English'},\n {id: 'no', title: 'Norsk'},\n ],\n}\n\nexport default function Feedback() {\n return (\n <Card tone=\"caution\" border radius={2} padding={3}>\n <Stack space={4}>\n <Text>\n An array of language objects must be passed into the <code>internationalizedArray</code>{' '}\n helper function, each with an <code>id</code> and <code>title</code> field. Example:\n </Text>\n <Card padding={2} border radius={2}>\n <Code size={1} language=\"javascript\">\n {JSON.stringify(schemaExample, null, 2)}\n </Code>\n </Card>\n </Stack>\n </Card>\n )\n}\n","import {NodeValidation} from 'sanity/form'\nimport {CardTone} from '@sanity/ui'\n\nexport function getToneFromValidation(validations: NodeValidation[]): CardTone {\n if (!validations.length) {\n return `default`\n }\n\n const validationLevels = validations.map((v) => v.level)\n\n if (validationLevels.includes('error')) {\n return `critical`\n } else if (validationLevels.includes('warning')) {\n return `caution`\n }\n\n return `default`\n}\n","import {defineField, Schema} from 'sanity'\n\nimport {createFieldName} from '../components/createFieldName'\n\ntype ObjectFactoryConfig = {\n type: string | Schema.FieldDefinition\n}\n\nexport default (config: ObjectFactoryConfig): Schema.FieldDefinition<'object'> => {\n const {type} = config\n const typeName = typeof type === `string` ? type : type.name\n const objectName = createFieldName(typeName, true)\n\n return defineField({\n name: objectName,\n title: `Internationalized array ${type}`,\n type: 'object',\n fields: [\n typeof type === `string`\n ? // Define a basic field if all we have is the string name\n defineField({\n name: 'value',\n type,\n })\n : // Pass in the configured options, but overwrite the name\n {...type, name: 'value'},\n ],\n })\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}
@@ -1,12 +0,0 @@
1
- import { Schema } from "sanity";
2
- type Language = {
3
- id: string;
4
- title: string;
5
- };
6
- type PluginConfig = {
7
- languages: Language[];
8
- fieldTypes: (string | Schema.FieldDefinition)[];
9
- };
10
- export const internationalizedArray: import("sanity").Plugin<PluginConfig>;
11
-
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";AAEA,gBAAuB;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAqBD,oBAA2B;IACzB,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,UAAU,EAAE,CAAC,MAAM,GAAG,OAAO,eAAe,CAAC,EAAE,CAAA;CAChD,CAAA;AQnBD,OAAO,MAAM,6DAYX,CAAA","sources":["src/src/types.ts","src/src/components/createFieldName.ts","src/src/components/Table.tsx","src/src/components/Feedback.tsx","src/src/components/getToneFromValidation.ts","src/src/components/InternationalizedArrayInput.tsx","src/src/schema/array.ts","src/src/schema/object.ts","src/src/plugin.tsx","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"export {internationalizedArray} from './plugin'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../"}