sanity-plugin-internationalized-array 1.6.0 → 1.6.2
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 +30 -4
- package/lib/{src/index.d.ts → index.d.ts} +6 -1
- package/lib/index.esm.js +9483 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +9483 -4
- package/lib/index.js.map +1 -1
- package/package.json +49 -37
- package/src/cache.ts +1 -0
- package/src/components/Feedback.tsx +4 -4
- package/src/components/InternationalizedArray.tsx +30 -17
- package/src/components/InternationalizedInput.tsx +35 -10
- package/src/components/Preload.tsx +6 -3
- package/src/components/getSelectedValue.ts +3 -1
- package/src/components/getToneFromValidation.ts +3 -1
- package/src/plugin.tsx +33 -24
- package/src/schema/array.ts +12 -7
- package/src/schema/object.ts +2 -8
- package/src/types.ts +7 -1
- package/src/components/Table.tsx +0 -88
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
> This is the **Sanity Studio v3 version** of sanity-plugin-internationalized-array.
|
|
2
2
|
>
|
|
3
|
-
> For the v2 version, please refer to the [v2-branch](https://github.com/
|
|
3
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-internationalized-array/tree/studio-v2).
|
|
4
4
|
|
|
5
5
|
# sanity-plugin-internationalized-array
|
|
6
6
|
|
|
7
7
|
A helper function that renders a custom input component for writing localized fields of content into an array.
|
|
8
8
|
|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -76,6 +76,32 @@ languages: async () => {
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
The async function contains a configured Sanity Client in the first parameter, allowing you to store Language options as documents. Your query should return an array of objects with an `id` and `title`.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
languages: async (client) => {
|
|
83
|
+
const response = await client.fetch(`*[_type == "language"]{ id, title }`)
|
|
84
|
+
return response
|
|
85
|
+
},
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Additionally, you can "pick" fields from a document, to pass into the query. For example, if you have a concept of "Markets" where only certain language fields are required in certain markets.
|
|
89
|
+
|
|
90
|
+
In this example, each language document has an array of strings called `markets` to declare where that language can be used. And the document being authored has a single `market` field.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
select: {
|
|
94
|
+
market: 'market'
|
|
95
|
+
},
|
|
96
|
+
languages: async (client, {market = ``}) => {
|
|
97
|
+
const response = await client.fetch(
|
|
98
|
+
`*[_type == "language" && $market in markets]{ id, title }`,
|
|
99
|
+
{market}
|
|
100
|
+
)
|
|
101
|
+
return response
|
|
102
|
+
},
|
|
103
|
+
```
|
|
104
|
+
|
|
79
105
|
## Using more complex field types
|
|
80
106
|
|
|
81
107
|
For more control over the `value` field, you can pass a schema definition into the `fieldTypes` array.
|
|
@@ -135,7 +161,7 @@ Using GROQ filters you can query for a specific language key like so:
|
|
|
135
161
|
|
|
136
162
|
## Migrate from objects to arrays
|
|
137
163
|
|
|
138
|
-
[See the migration script](https://github.com/
|
|
164
|
+
[See the migration script](https://github.com/sanity-io/sanity-plugin-internationalized-array/blob/main/migrations/transformObjectToArray.js) inside `./migrations/transformObjectToArray.js` of this Repo.
|
|
139
165
|
|
|
140
166
|
Follow the instructions inside the script and set the `_type` and field name you wish to target.
|
|
141
167
|
|
|
@@ -196,7 +222,7 @@ on how to run this plugin with hotreload in the studio.
|
|
|
196
222
|
|
|
197
223
|
### Release new version
|
|
198
224
|
|
|
199
|
-
Run ["CI & Release" workflow](https://github.com/
|
|
225
|
+
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-internationalized-array/actions/workflows/main.yml).
|
|
200
226
|
Make sure to select the main branch and check "Release new version".
|
|
201
227
|
|
|
202
228
|
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
@@ -5,7 +5,12 @@ import type {Rule} from 'sanity'
|
|
|
5
5
|
import type {RuleTypeConstraint} from 'sanity'
|
|
6
6
|
import type {SanityClient} from 'sanity'
|
|
7
7
|
|
|
8
|
-
export declare type AllowedType =
|
|
8
|
+
export declare type AllowedType =
|
|
9
|
+
| 'string'
|
|
10
|
+
| 'number'
|
|
11
|
+
| 'boolean'
|
|
12
|
+
| 'text'
|
|
13
|
+
| 'reference'
|
|
9
14
|
|
|
10
15
|
export declare type ArrayConfig = {
|
|
11
16
|
name: string
|