sanity-plugin-internationalized-array 1.5.0 → 1.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Simeon Griggs
3
+ Copyright (c) 2023 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -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.
@@ -1,10 +1,16 @@
1
1
  import type {ArraySchemaType} from 'sanity'
2
+ import type {FieldDefinition} from 'sanity'
2
3
  import {Plugin as Plugin_2} from 'sanity'
3
4
  import type {Rule} from 'sanity'
4
5
  import type {RuleTypeConstraint} from 'sanity'
5
6
  import type {SanityClient} from 'sanity'
6
7
 
7
- export declare type AllowedType = 'string' | 'number' | 'boolean' | 'text' | 'reference'
8
+ export declare type AllowedType =
9
+ | 'string'
10
+ | 'number'
11
+ | 'boolean'
12
+ | 'text'
13
+ | 'reference'
8
14
 
9
15
  export declare type ArrayConfig = {
10
16
  name: string
@@ -25,7 +31,8 @@ export declare type ArrayConfig = {
25
31
 
26
32
  export declare type ArraySchemaWithLanguageOptions = ArraySchemaType & {
27
33
  options: {
28
- languages: Language[] | ((client: SanityClient) => Promise<Language[]>)
34
+ select?: Record<string, string>
35
+ languages: Language[] | LanguageCallback
29
36
  apiVersion: string
30
37
  }
31
38
  }
@@ -39,12 +46,30 @@ export declare type Language = {
39
46
  title: string
40
47
  }
41
48
 
49
+ export declare type LanguageCallback = (
50
+ client: SanityClient,
51
+ selectedValue: Record<string, unknown>
52
+ ) => Promise<Language[]>
53
+
42
54
  export declare type PluginConfig = {
43
55
  /**
44
56
  * https://www.sanity.io/docs/api-versioning
45
57
  * @defaultValue '2022-11-27'
46
58
  */
47
59
  apiVersion?: string
60
+ /**
61
+ * Specify fields that should be available in the language callback:
62
+ * ```tsx
63
+ * {
64
+ * select: {
65
+ * markets: 'markets'
66
+ * },
67
+ * languages: (client, {markets}) =>
68
+ * query.fetch(groq`*[_type == "language" && market in $markets]{id,title}`, {markets})
69
+ * }
70
+ * ```
71
+ */
72
+ select?: Record<string, string>
48
73
  /**
49
74
  * You can give it an array of language definitions:
50
75
  * ```tsx
@@ -72,7 +97,7 @@ export declare type PluginConfig = {
72
97
  * }
73
98
  * ```
74
99
  */
75
- languages: Language[] | ((client: SanityClient) => Promise<Language[]>)
100
+ languages: Language[] | LanguageCallback
76
101
  /**
77
102
  * Can be a string matching core field types, as well as custom ones:
78
103
  * ```tsx
@@ -96,7 +121,7 @@ export declare type PluginConfig = {
96
121
  * }
97
122
  * ```
98
123
  */
99
- fieldTypes: (string | RuleTypeConstraint)[]
124
+ fieldTypes: (string | RuleTypeConstraint | FieldDefinition)[]
100
125
  }
101
126
 
102
127
  export declare type Value = {