sanity-plugin-internationalized-array 3.2.2 → 4.0.1
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/LICENSE +1 -1
- package/README.md +3 -34
- package/{lib → dist}/index.d.ts +41 -61
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +896 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -74
- package/lib/index.d.mts +0 -149
- package/lib/index.esm.js +0 -854
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js +0 -863
- package/lib/index.js.map +0 -1
- package/lib/index.mjs +0 -854
- package/lib/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/cache.ts +0 -148
- package/src/components/AddButtons.tsx +0 -60
- package/src/components/DocumentAddButtons.tsx +0 -183
- package/src/components/Feedback.tsx +0 -28
- package/src/components/InternationalizedArray.tsx +0 -286
- package/src/components/InternationalizedArrayContext.tsx +0 -136
- package/src/components/InternationalizedField.tsx +0 -57
- package/src/components/InternationalizedInput.tsx +0 -257
- package/src/components/Preload.tsx +0 -31
- package/src/components/createFieldName.ts +0 -20
- package/src/components/getSelectedValue.ts +0 -31
- package/src/components/getToneFromValidation.ts +0 -20
- package/src/constants.ts +0 -18
- package/src/fieldActions/index.ts +0 -138
- package/src/index.ts +0 -3
- package/src/plugin.tsx +0 -87
- package/src/schema/array.ts +0 -148
- package/src/schema/object.ts +0 -36
- package/src/types.ts +0 -135
- package/src/utils/checkAllLanguagesArePresent.ts +0 -14
- package/src/utils/createAddAllTitle.ts +0 -16
- package/src/utils/createAddLanguagePatches.ts +0 -84
- package/src/utils/createValueSchemaTypeName.ts +0 -5
- package/src/utils/flattenSchemaType.ts +0 -63
- package/src/utils/getDocumentsToTranslate.ts +0 -66
- package/src/utils/getLanguageDisplay.ts +0 -13
- package/src/utils/getLanguagesFieldOption.ts +0 -16
- package/v2-incompatible.js +0 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
> This is the **Sanity Studio v3 version** of sanity-plugin-internationalized-array.
|
|
2
|
-
>
|
|
3
|
-
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-internationalized-array/tree/studio-v2).
|
|
4
|
-
|
|
5
1
|
# sanity-plugin-internationalized-array
|
|
6
2
|
|
|
7
3
|
A plugin to register array fields with a custom input component to store field values in multiple languages, queryable by using the language ID as an array `_key`.
|
|
@@ -314,19 +310,14 @@ export default defineConfig({
|
|
|
314
310
|
// It's an internationalized array value
|
|
315
311
|
// And the array _key is the language of the field
|
|
316
312
|
const language =
|
|
317
|
-
pathEnd[1] === 'value' && isKeySegment(pathEnd[0])
|
|
318
|
-
? pathEnd[0]._key
|
|
319
|
-
: null
|
|
313
|
+
pathEnd[1] === 'value' && isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null
|
|
320
314
|
|
|
321
315
|
return language ? selectedLanguageIds.includes(language) : false
|
|
322
316
|
}
|
|
323
317
|
|
|
324
318
|
// Filter internationalized objects if you have them
|
|
325
319
|
// `localeString` must be registered as a custom schema type
|
|
326
|
-
if (
|
|
327
|
-
enclosingType.jsonType === 'object' &&
|
|
328
|
-
enclosingType.name.startsWith('locale')
|
|
329
|
-
) {
|
|
320
|
+
if (enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale')) {
|
|
330
321
|
return selectedLanguageIds.includes(member.name)
|
|
331
322
|
}
|
|
332
323
|
|
|
@@ -360,7 +351,7 @@ Using GROQ filters you can query for a specific language key like so:
|
|
|
360
351
|
|
|
361
352
|
## Migrate from objects to arrays
|
|
362
353
|
|
|
363
|
-
[See the migration script](
|
|
354
|
+
[See the migration script](./migrations/transformObjectToArray.ts) inside `./migrations/transformObjectToArray.ts` of this plugin.
|
|
364
355
|
|
|
365
356
|
Follow the instructions inside the script and set the `_type` and field name you wish to target.
|
|
366
357
|
|
|
@@ -404,28 +395,6 @@ greeting[].value
|
|
|
404
395
|
|
|
405
396
|
By using this plugin you can safely extend the number of languages without adding any additional query paths.
|
|
406
397
|
|
|
407
|
-
MIT © Sanity.io
|
|
408
|
-
See LICENSE
|
|
409
|
-
|
|
410
|
-
## License
|
|
411
|
-
|
|
412
|
-
MIT-licensed. See LICENSE.
|
|
413
|
-
|
|
414
|
-
## Develop & test
|
|
415
|
-
|
|
416
|
-
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
417
|
-
with default configuration for build & watch scripts.
|
|
418
|
-
|
|
419
|
-
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
420
|
-
on how to run this plugin with hotreload in the studio.
|
|
421
|
-
|
|
422
|
-
### Release new version
|
|
423
|
-
|
|
424
|
-
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-internationalized-array/actions/workflows/main.yml).
|
|
425
|
-
Make sure to select the main branch and check "Release new version".
|
|
426
|
-
|
|
427
|
-
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
428
|
-
|
|
429
398
|
## License
|
|
430
399
|
|
|
431
400
|
[MIT](LICENSE) © Simeon Griggs
|
package/{lib → dist}/index.d.ts
RENAMED
|
@@ -1,55 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
languages: Language[]
|
|
18
|
-
title?: string
|
|
19
|
-
group?: string
|
|
20
|
-
hidden?: boolean | (() => boolean)
|
|
21
|
-
readOnly?: boolean | (() => boolean)
|
|
22
|
-
validation?: Rule | Rule[]
|
|
1
|
+
import * as sanity0 from "sanity";
|
|
2
|
+
import { FieldDefinition, Rule, RuleTypeConstraint, SanityClient } from "sanity";
|
|
3
|
+
type Language = {
|
|
4
|
+
id: Intl.UnicodeBCP47LocaleIdentifier;
|
|
5
|
+
title: string;
|
|
6
|
+
};
|
|
7
|
+
type AllowedType = 'string' | 'number' | 'boolean' | 'text' | 'reference';
|
|
8
|
+
type ArrayConfig = {
|
|
9
|
+
name: string;
|
|
10
|
+
type: AllowedType;
|
|
11
|
+
languages: Language[];
|
|
12
|
+
title?: string;
|
|
13
|
+
group?: string;
|
|
14
|
+
hidden?: boolean | (() => boolean);
|
|
15
|
+
readOnly?: boolean | (() => boolean);
|
|
16
|
+
validation?: Rule | Rule[];
|
|
23
17
|
field?: {
|
|
24
|
-
[key: string]:
|
|
18
|
+
[key: string]: unknown;
|
|
25
19
|
options: {
|
|
26
|
-
[key: string]:
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
title: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export declare type LanguageCallback = (
|
|
41
|
-
client: SanityClient,
|
|
42
|
-
selectedValue: Record<string, unknown>
|
|
43
|
-
) => Promise<Language[]>
|
|
44
|
-
|
|
45
|
-
export declare type LanguageDisplay = 'titleOnly' | 'codeOnly' | 'titleAndCode'
|
|
46
|
-
|
|
47
|
-
export declare type PluginConfig = {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type Value = {
|
|
25
|
+
_key: string;
|
|
26
|
+
value?: unknown;
|
|
27
|
+
};
|
|
28
|
+
type LanguageCallback = (client: SanityClient, selectedValue: Record<string, unknown>) => Promise<Language[]>;
|
|
29
|
+
type LanguageDisplay = 'titleOnly' | 'codeOnly' | 'titleAndCode';
|
|
30
|
+
type PluginConfig = {
|
|
48
31
|
/**
|
|
49
32
|
* https://www.sanity.io/docs/api-versioning
|
|
50
33
|
* @defaultValue '2025-10-15'
|
|
51
34
|
*/
|
|
52
|
-
apiVersion?: string
|
|
35
|
+
apiVersion?: string;
|
|
53
36
|
/**
|
|
54
37
|
* Specify fields that should be available in the language callback:
|
|
55
38
|
* ```tsx
|
|
@@ -62,7 +45,7 @@ export declare type PluginConfig = {
|
|
|
62
45
|
* }
|
|
63
46
|
* ```
|
|
64
47
|
*/
|
|
65
|
-
select?: Record<string, string
|
|
48
|
+
select?: Record<string, string>;
|
|
66
49
|
/**
|
|
67
50
|
* You can give it an array of language definitions:
|
|
68
51
|
* ```tsx
|
|
@@ -90,7 +73,7 @@ export declare type PluginConfig = {
|
|
|
90
73
|
* }
|
|
91
74
|
* ```
|
|
92
75
|
*/
|
|
93
|
-
languages: Language[] | LanguageCallback
|
|
76
|
+
languages: Language[] | LanguageCallback;
|
|
94
77
|
/**
|
|
95
78
|
* You can specify a list of language IDs that should be pre-filled when creating a new document
|
|
96
79
|
* ```tsx
|
|
@@ -99,7 +82,7 @@ export declare type PluginConfig = {
|
|
|
99
82
|
* }
|
|
100
83
|
* ```
|
|
101
84
|
*/
|
|
102
|
-
defaultLanguages?: string[]
|
|
85
|
+
defaultLanguages?: string[];
|
|
103
86
|
/**
|
|
104
87
|
* Can be a string matching core field types, as well as custom ones:
|
|
105
88
|
* ```tsx
|
|
@@ -123,27 +106,24 @@ export declare type PluginConfig = {
|
|
|
123
106
|
* }
|
|
124
107
|
* ```
|
|
125
108
|
*/
|
|
126
|
-
fieldTypes: (string | RuleTypeConstraint | FieldDefinition)[]
|
|
109
|
+
fieldTypes: (string | RuleTypeConstraint | FieldDefinition)[];
|
|
127
110
|
/**
|
|
128
111
|
* Locations where the "+ EN" add language buttons are visible
|
|
129
112
|
* @defaultValue ['field']
|
|
130
113
|
* */
|
|
131
|
-
buttonLocations?: ('field' | 'unstable__fieldAction' | 'document')[]
|
|
114
|
+
buttonLocations?: ('field' | 'unstable__fieldAction' | 'document')[];
|
|
132
115
|
/**
|
|
133
116
|
* Show or hide the "Add missing languages" button
|
|
134
117
|
* @defaultValue true
|
|
135
118
|
* */
|
|
136
|
-
buttonAddAll?: boolean
|
|
119
|
+
buttonAddAll?: boolean;
|
|
137
120
|
/**
|
|
138
121
|
* How to display the languages on buttons and fields
|
|
139
122
|
* @defaultValue 'code'
|
|
140
123
|
* */
|
|
141
|
-
languageDisplay?: LanguageDisplay
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export {}
|
|
124
|
+
languageDisplay?: LanguageDisplay;
|
|
125
|
+
};
|
|
126
|
+
declare const clear: () => void;
|
|
127
|
+
declare const internationalizedArray: sanity0.Plugin<PluginConfig>;
|
|
128
|
+
export { AllowedType, ArrayConfig, Language, LanguageCallback, LanguageDisplay, PluginConfig, Value, clear, internationalizedArray };
|
|
129
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/cache.ts","../src/plugin.tsx"],"mappings":";;KAEY,QAAA;EACV,EAAA,EAAI,IAAA,CAAK,4BAAA;EACT,KAAA;AAAA;AAAA,KAGU,WAAA;AAAA,KAEA,WAAA;EACV,IAAA;EACA,IAAA,EAAM,WAAA;EACN,SAAA,EAAW,QAAA;EACX,KAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;EACA,UAAA,GAAa,IAAA,GAAO,IAAA;EACpB,KAAA;IAAA,CAAU,GAAA;IAAuB,OAAA;MAAA,CAAW,GAAA;IAAA;EAAA;AAAA;AAAA,KAGlC,KAAA;EACV,IAAA;EACA,KAAA;AAAA;AAAA,KAGU,gBAAA,IACV,MAAA,EAAQ,YAAA,EACR,aAAA,EAAe,MAAA,sBACZ,OAAA,CAAQ,QAAA;AAAA,KAED,eAAA;AAAA,KAEA,YAAA;EAtBJ;;;;EA2BN,UAAA;EAvBA;;;;;;;;;;;AAMF;EA8BE,MAAA,GAAS,MAAA;;;;AAzBX;;;;;;;;;;;;;;;;;AAKA;;;;;AAEA;;EA8CE,SAAA,EAAW,QAAA,KAAa,gBAAA;EA5Bf;;;;;;;;EAqCT,gBAAA;EArCA;;;;;;;;;;;;;;;;ACXF;;;;;;AC3BA;EFoGE,UAAA,YAAsB,kBAAA,GAAqB,eAAA;;;;;EAK3C,eAAA;;;;;EAKA,YAAA;;;;;EAKA,eAAA,GAAkB,eAAA;AAAA;AAAA,cCxFP,KAAA;AAAA,cC3BA,sBAAA,EAAsB,OAAA,CAAA,MAAA,CAAA,YAAA"}
|