sanity-plugin-media 4.1.0 → 4.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.
Files changed (62) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +56 -4
  3. package/dist/index.d.mts +131 -57
  4. package/dist/index.d.ts +131 -57
  5. package/dist/index.js +273 -106
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +273 -106
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +11 -4
  10. package/src/__tests__/fixtures/createEpicTestStore.ts +27 -0
  11. package/src/__tests__/fixtures/listenMock.ts +9 -0
  12. package/src/__tests__/fixtures/mockSanityClient.ts +84 -0
  13. package/src/__tests__/fixtures/renderWithProviders.tsx +54 -0
  14. package/src/__tests__/fixtures/rootState.ts +27 -0
  15. package/src/__tests__/fixtures/withinDialog.ts +28 -0
  16. package/src/components/Browser/Browser.test.tsx +44 -0
  17. package/src/components/CardAsset/CardAsset.test.tsx +322 -0
  18. package/src/components/DialogAssetEdit/Details.tsx +123 -44
  19. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +215 -0
  20. package/src/components/DialogAssetEdit/index.tsx +138 -30
  21. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +120 -0
  22. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +164 -0
  23. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +62 -0
  24. package/src/components/ReduxProvider/index.tsx +2 -1
  25. package/src/components/UploadDropzone/UploadDropzone.test.tsx +39 -0
  26. package/src/constants.ts +6 -0
  27. package/src/contexts/ToolOptionsContext.tsx +6 -3
  28. package/src/formSchema/index.test.ts +55 -0
  29. package/src/formSchema/index.ts +28 -12
  30. package/src/hooks/useVersionedClient.ts +1 -1
  31. package/src/modules/assets/deleteAndUpdateEpics.test.ts +86 -0
  32. package/src/modules/assets/fetchEpic.test.ts +72 -0
  33. package/src/modules/assets/reducer.test.ts +90 -0
  34. package/src/modules/assets/tagsAndListenerEpics.test.ts +205 -0
  35. package/src/modules/dialog/epics.test.ts +167 -0
  36. package/src/modules/dialog/reducer.test.ts +184 -0
  37. package/src/modules/notifications/epics.test.ts +373 -0
  38. package/src/modules/notifications/index.ts +24 -4
  39. package/src/modules/notifications/reducer.test.ts +53 -0
  40. package/src/modules/search/index.test.ts +35 -0
  41. package/src/modules/selectors.test.ts +20 -0
  42. package/src/modules/tags/epics.test.ts +95 -0
  43. package/src/modules/tags/index.test.ts +41 -0
  44. package/src/modules/uploads/epics.test.ts +108 -0
  45. package/src/modules/uploads/index.test.ts +58 -0
  46. package/src/operators/checkTagName.test.ts +28 -0
  47. package/src/types/index.ts +23 -7
  48. package/src/utils/blocksToText.test.ts +42 -0
  49. package/src/utils/constructFilter.test.ts +119 -0
  50. package/src/utils/generatePreviewBlobUrl.test.ts +69 -0
  51. package/src/utils/getAssetResolution.test.ts +12 -0
  52. package/src/utils/getDocumentAssetIds.test.ts +49 -0
  53. package/src/utils/getSchemeColor.test.ts +11 -0
  54. package/src/utils/getTagSelectOptions.test.ts +43 -0
  55. package/src/utils/getUniqueDocuments.test.ts +25 -0
  56. package/src/utils/imageDprUrl.test.ts +45 -0
  57. package/src/utils/isSupportedAssetType.test.ts +15 -0
  58. package/src/utils/isSupportedAssetType.ts +15 -0
  59. package/src/utils/sanitizeFormData.test.ts +58 -0
  60. package/src/utils/typeGuards.test.ts +17 -0
  61. package/src/utils/uploadSanityAsset.test.ts +28 -0
  62. package/src/utils/withMaxConcurrency.test.ts +42 -0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sanity.io
3
+ Copyright (c) 2026 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
@@ -95,7 +95,6 @@ export default defineConfig({
95
95
  })
96
96
  ```
97
97
 
98
-
99
98
  ### Plugin Config
100
99
 
101
100
  ```ts
@@ -111,7 +110,7 @@ export default defineConfig({
111
110
  enabled: true,
112
111
  // boolean - enables an optional "Credit Line" field in the plugin.
113
112
  // Used to store credits e.g. photographer, licence information
114
- excludeSources: ['unsplash'],
113
+ excludeSources: ['unsplash']
115
114
  // string | string[] - when used with 3rd party asset sources, you may
116
115
  // wish to prevent users overwriting the creditLine based on the `source.name`
117
116
  },
@@ -122,13 +121,66 @@ export default defineConfig({
122
121
  components: {
123
122
  details: CustomDetails
124
123
  // Custom component for asset details (see below)
125
- }
124
+ },
126
125
  // Custom components to override default UI (see below)
126
+ locales: [
127
+ // { id: string, title: string, ...extra }[] - enable localization for asset fields. Each object must have a unique id and a human-readable title.
128
+ // When set, all localizable fields (title, altText, description, creditLine) will be shown in tabs by language.
129
+ {id: 'en', title: 'English'},
130
+ {id: 'it', title: 'Italian'},
131
+ {id: 'es', title: 'Spanish'},
132
+ {id: 'fr', title: 'French'},
133
+ {id: 'de', title: 'German'},
134
+ {id: 'pt', title: 'Portuguese'},
135
+ {id: 'ja', title: 'Japanese'},
136
+ {id: 'zh', title: 'Chinese'},
137
+ {id: 'ru', title: 'Russian'},
138
+ {id: 'ar', title: 'Arabic'}
139
+ ]
127
140
  })
128
- ],
141
+ ]
129
142
  })
130
143
  ```
131
144
 
145
+ ### Localization (Optional)
146
+
147
+ You can enable localization support by passing a `locales` array to the plugin config, following the [Sanity recommended scheme](https://www.sanity.io/docs/studio/localization#k4da239411955):
148
+
149
+ If omitted, localization features will be disabled and the plugin will work as usual.
150
+
151
+ **Fallback for missing translations:**
152
+ The plugin does not apply any automatic fallback for missing translations. You can decide how to handle this in your queries or frontend logic. For example, to show the default language if a translation is missing, you can use GROQ's `coalesce()`:
153
+
154
+ ```
155
+ coalesce(altText.it, altText.en)
156
+ ```
157
+
158
+ **UI note:**
159
+ When `locales` are provided, all localized fields (title, altText, description, creditLine) are grouped by language in tabs. Each tab shows all fields for a single language, making it easy to edit translations for many languages in a compact interface.
160
+
161
+ This will return the Italian value if present, otherwise English, otherwise French, etc. Adjust the order as needed for your project.
162
+
163
+ #### Migrating existing assets to localized format
164
+
165
+ If you enable `locales` on a project that already has assets with plain string fields (e.g. `title: "My photo"`), you should run the provided migration script to convert those fields to the localized object format (e.g. `title: {en: "My photo"}`).
166
+
167
+ **1. Edit the script** — open `scripts/migrate-to-localized-fields.ts` and set `DEFAULT_LOCALE_ID` to the locale id that your existing values should be mapped to.
168
+
169
+ **2. Run the migration:**
170
+
171
+ ```sh
172
+ npx sanity@latest migration run scripts/migrate-to-localized-fields.ts \
173
+ --project <projectId> --dataset <dataset>
174
+ ```
175
+
176
+ The script targets `sanity.imageAsset` and `sanity.fileAsset` documents and converts any plain string value in `title`, `altText`, `description`, and `creditLine` to `{[DEFAULT_LOCALE_ID]: value}`. Fields that are already in object format are left untouched.
177
+
178
+ > **Without migration:** Legacy string fields can also be migrated when an asset is edited and saved in the plugin. Running the script is still recommended to migrate all existing assets consistently before users start editing.
179
+
180
+ #### Removing locales
181
+
182
+ If you remove the `locales` option after assets have been saved in localized format, the plugin will show a warning in the asset edit dialog offering a **"Cleanup localized fields"** action. Clicking it removes locale keys that are no longer configured and, if no locales remain, flattens the fields back to plain strings.
183
+
132
184
  #### Custom Asset Details Component
133
185
 
134
186
  Custom React component for the asset details form via the plugin config. This allows you to override or extend the default asset details UI.
package/dist/index.d.mts CHANGED
@@ -14,13 +14,73 @@ import * as z from 'zod'
14
14
 
15
15
  declare type Asset = FileAsset | ImageAsset
16
16
 
17
- declare type AssetFormData = z.infer<typeof assetFormSchema>
17
+ declare type AssetFormData = z.infer<ReturnType<typeof getAssetFormSchema>>
18
18
 
19
- declare const assetFormSchema: z.ZodObject<
19
+ declare type CustomFields = {
20
+ altText?: LocalizedString
21
+ description?: LocalizedString
22
+ opt?: {
23
+ media?: {
24
+ tags?: SanityReference[]
25
+ }
26
+ }
27
+ title?: LocalizedString
28
+ }
29
+
30
+ declare type DetailsProps = {
31
+ formUpdating: boolean
32
+ handleCreateTag: (title: string) => void
33
+ control: Control<AssetFormData>
34
+ errors: FieldErrors<AssetFormData>
35
+ register: UseFormRegister<AssetFormData>
36
+ allTagOptions: TagSelectOption[]
37
+ assetTagOptions: TagSelectOption[] | null
38
+ currentAsset: Asset
39
+ creditLine?: {
40
+ enabled: boolean
41
+ excludeSources?: string | string[] | undefined
42
+ }
43
+ locales?: Locale_2[]
44
+ }
45
+
46
+ declare type FileAsset = SanityAssetDocument &
47
+ CustomFields & {
48
+ _type: 'sanity.fileAsset'
49
+ }
50
+
51
+ declare function getAssetFormSchema(
52
+ locales?: {
53
+ id: string
54
+ }[]
55
+ ): z.ZodObject<
20
56
  {
21
- altText: z.ZodOptional<z.ZodString>
22
- creditLine: z.ZodOptional<z.ZodString>
23
- description: z.ZodOptional<z.ZodString>
57
+ altText:
58
+ | z.ZodOptional<z.ZodString>
59
+ | z.ZodObject<
60
+ Record<string, z.ZodTypeAny>,
61
+ 'passthrough',
62
+ z.ZodTypeAny,
63
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
64
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
65
+ >
66
+ creditLine:
67
+ | z.ZodOptional<z.ZodString>
68
+ | z.ZodObject<
69
+ Record<string, z.ZodTypeAny>,
70
+ 'passthrough',
71
+ z.ZodTypeAny,
72
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
73
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
74
+ >
75
+ description:
76
+ | z.ZodOptional<z.ZodString>
77
+ | z.ZodObject<
78
+ Record<string, z.ZodTypeAny>,
79
+ 'passthrough',
80
+ z.ZodTypeAny,
81
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
82
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
83
+ >
24
84
  opt: z.ZodObject<
25
85
  {
26
86
  media: z.ZodObject<
@@ -35,12 +95,12 @@ declare const assetFormSchema: z.ZodObject<
35
95
  'strip',
36
96
  z.ZodTypeAny,
37
97
  {
38
- label: string
39
98
  value: string
99
+ label: string
40
100
  },
41
101
  {
42
- label: string
43
102
  value: string
103
+ label: string
44
104
  }
45
105
  >,
46
106
  'many'
@@ -52,16 +112,16 @@ declare const assetFormSchema: z.ZodObject<
52
112
  {
53
113
  tags:
54
114
  | {
55
- label: string
56
115
  value: string
116
+ label: string
57
117
  }[]
58
118
  | null
59
119
  },
60
120
  {
61
121
  tags:
62
122
  | {
63
- label: string
64
123
  value: string
124
+ label: string
65
125
  }[]
66
126
  | null
67
127
  }
@@ -73,8 +133,8 @@ declare const assetFormSchema: z.ZodObject<
73
133
  media: {
74
134
  tags:
75
135
  | {
76
- label: string
77
136
  value: string
137
+ label: string
78
138
  }[]
79
139
  | null
80
140
  }
@@ -83,15 +143,23 @@ declare const assetFormSchema: z.ZodObject<
83
143
  media: {
84
144
  tags:
85
145
  | {
86
- label: string
87
146
  value: string
147
+ label: string
88
148
  }[]
89
149
  | null
90
150
  }
91
151
  }
92
152
  >
93
153
  originalFilename: z.ZodString
94
- title: z.ZodOptional<z.ZodString>
154
+ title:
155
+ | z.ZodOptional<z.ZodString>
156
+ | z.ZodObject<
157
+ Record<string, z.ZodTypeAny>,
158
+ 'passthrough',
159
+ z.ZodTypeAny,
160
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
161
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
162
+ >
95
163
  },
96
164
  'strip',
97
165
  z.ZodTypeAny,
@@ -100,74 +168,75 @@ declare const assetFormSchema: z.ZodObject<
100
168
  media: {
101
169
  tags:
102
170
  | {
103
- label: string
104
171
  value: string
172
+ label: string
105
173
  }[]
106
174
  | null
107
175
  }
108
176
  }
109
177
  originalFilename: string
110
- altText?: string | undefined
111
- creditLine?: string | undefined
112
- description?: string | undefined
113
- title?: string | undefined
178
+ altText?:
179
+ | string
180
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
181
+ | undefined
182
+ creditLine?:
183
+ | string
184
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
185
+ | undefined
186
+ description?:
187
+ | string
188
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
189
+ | undefined
190
+ title?:
191
+ | string
192
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
193
+ | undefined
114
194
  },
115
195
  {
116
196
  opt: {
117
197
  media: {
118
198
  tags:
119
199
  | {
120
- label: string
121
200
  value: string
201
+ label: string
122
202
  }[]
123
203
  | null
124
204
  }
125
205
  }
126
206
  originalFilename: string
127
- altText?: string | undefined
128
- creditLine?: string | undefined
129
- description?: string | undefined
130
- title?: string | undefined
207
+ altText?:
208
+ | string
209
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
210
+ | undefined
211
+ creditLine?:
212
+ | string
213
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
214
+ | undefined
215
+ description?:
216
+ | string
217
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
218
+ | undefined
219
+ title?:
220
+ | string
221
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
222
+ | undefined
131
223
  }
132
224
  >
133
225
 
134
- declare type CustomFields = {
135
- altText?: string
136
- description?: string
137
- opt?: {
138
- media?: {
139
- tags?: SanityReference[]
140
- }
141
- }
142
- title?: string
143
- }
144
-
145
- declare type DetailsProps = {
146
- formUpdating: boolean
147
- handleCreateTag: (title: string) => void
148
- control: Control<AssetFormData>
149
- errors: FieldErrors<AssetFormData>
150
- register: UseFormRegister<AssetFormData>
151
- allTagOptions: TagSelectOption[]
152
- assetTagOptions: TagSelectOption[] | null
153
- currentAsset: Asset
154
- creditLine?: {
155
- enabled: boolean
156
- excludeSources?: string | string[] | undefined
157
- }
158
- }
159
-
160
- declare type FileAsset = SanityAssetDocument &
161
- CustomFields & {
162
- _type: 'sanity.fileAsset'
163
- }
164
-
165
226
  declare type ImageAsset = SanityImageAssetDocument &
166
227
  CustomFields & {
167
228
  _type: 'sanity.imageAsset'
168
- creditLine?: string
229
+ creditLine?: LocalizedString
169
230
  }
170
231
 
232
+ declare type Locale_2 = {
233
+ title: string
234
+ id: string
235
+ [key: string]: unknown
236
+ }
237
+
238
+ declare type LocalizedString = string | Record<string, string>
239
+
171
240
  export declare const media: Plugin_2<void | MediaToolOptions>
172
241
 
173
242
  export declare const mediaAssetSource: {
@@ -188,11 +257,16 @@ export declare type MediaToolOptions = {
188
257
  }
189
258
  >
190
259
  }
191
- creditLine: {
260
+ creditLine?: {
192
261
  enabled: boolean
193
262
  excludeSources?: string | string[]
194
263
  }
195
264
  directUploads?: boolean
265
+ /**
266
+ * Optional locales following Sanity recommended scheme: [{ id, title }]
267
+ * https://www.sanity.io/docs/studio/localization#k4da239411955
268
+ */
269
+ locales?: Locale_2[]
196
270
  }
197
271
 
198
272
  declare type SanityReference = {
@@ -209,12 +283,12 @@ declare const tagOptionSchema: z.ZodObject<
209
283
  'strip',
210
284
  z.ZodTypeAny,
211
285
  {
212
- label: string
213
286
  value: string
287
+ label: string
214
288
  },
215
289
  {
216
- label: string
217
290
  value: string
291
+ label: string
218
292
  }
219
293
  >
220
294
 
package/dist/index.d.ts CHANGED
@@ -14,13 +14,73 @@ import * as z from 'zod'
14
14
 
15
15
  declare type Asset = FileAsset | ImageAsset
16
16
 
17
- declare type AssetFormData = z.infer<typeof assetFormSchema>
17
+ declare type AssetFormData = z.infer<ReturnType<typeof getAssetFormSchema>>
18
18
 
19
- declare const assetFormSchema: z.ZodObject<
19
+ declare type CustomFields = {
20
+ altText?: LocalizedString
21
+ description?: LocalizedString
22
+ opt?: {
23
+ media?: {
24
+ tags?: SanityReference[]
25
+ }
26
+ }
27
+ title?: LocalizedString
28
+ }
29
+
30
+ declare type DetailsProps = {
31
+ formUpdating: boolean
32
+ handleCreateTag: (title: string) => void
33
+ control: Control<AssetFormData>
34
+ errors: FieldErrors<AssetFormData>
35
+ register: UseFormRegister<AssetFormData>
36
+ allTagOptions: TagSelectOption[]
37
+ assetTagOptions: TagSelectOption[] | null
38
+ currentAsset: Asset
39
+ creditLine?: {
40
+ enabled: boolean
41
+ excludeSources?: string | string[] | undefined
42
+ }
43
+ locales?: Locale_2[]
44
+ }
45
+
46
+ declare type FileAsset = SanityAssetDocument &
47
+ CustomFields & {
48
+ _type: 'sanity.fileAsset'
49
+ }
50
+
51
+ declare function getAssetFormSchema(
52
+ locales?: {
53
+ id: string
54
+ }[]
55
+ ): z.ZodObject<
20
56
  {
21
- altText: z.ZodOptional<z.ZodString>
22
- creditLine: z.ZodOptional<z.ZodString>
23
- description: z.ZodOptional<z.ZodString>
57
+ altText:
58
+ | z.ZodOptional<z.ZodString>
59
+ | z.ZodObject<
60
+ Record<string, z.ZodTypeAny>,
61
+ 'passthrough',
62
+ z.ZodTypeAny,
63
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
64
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
65
+ >
66
+ creditLine:
67
+ | z.ZodOptional<z.ZodString>
68
+ | z.ZodObject<
69
+ Record<string, z.ZodTypeAny>,
70
+ 'passthrough',
71
+ z.ZodTypeAny,
72
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
73
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
74
+ >
75
+ description:
76
+ | z.ZodOptional<z.ZodString>
77
+ | z.ZodObject<
78
+ Record<string, z.ZodTypeAny>,
79
+ 'passthrough',
80
+ z.ZodTypeAny,
81
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
82
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
83
+ >
24
84
  opt: z.ZodObject<
25
85
  {
26
86
  media: z.ZodObject<
@@ -35,12 +95,12 @@ declare const assetFormSchema: z.ZodObject<
35
95
  'strip',
36
96
  z.ZodTypeAny,
37
97
  {
38
- label: string
39
98
  value: string
99
+ label: string
40
100
  },
41
101
  {
42
- label: string
43
102
  value: string
103
+ label: string
44
104
  }
45
105
  >,
46
106
  'many'
@@ -52,16 +112,16 @@ declare const assetFormSchema: z.ZodObject<
52
112
  {
53
113
  tags:
54
114
  | {
55
- label: string
56
115
  value: string
116
+ label: string
57
117
  }[]
58
118
  | null
59
119
  },
60
120
  {
61
121
  tags:
62
122
  | {
63
- label: string
64
123
  value: string
124
+ label: string
65
125
  }[]
66
126
  | null
67
127
  }
@@ -73,8 +133,8 @@ declare const assetFormSchema: z.ZodObject<
73
133
  media: {
74
134
  tags:
75
135
  | {
76
- label: string
77
136
  value: string
137
+ label: string
78
138
  }[]
79
139
  | null
80
140
  }
@@ -83,15 +143,23 @@ declare const assetFormSchema: z.ZodObject<
83
143
  media: {
84
144
  tags:
85
145
  | {
86
- label: string
87
146
  value: string
147
+ label: string
88
148
  }[]
89
149
  | null
90
150
  }
91
151
  }
92
152
  >
93
153
  originalFilename: z.ZodString
94
- title: z.ZodOptional<z.ZodString>
154
+ title:
155
+ | z.ZodOptional<z.ZodString>
156
+ | z.ZodObject<
157
+ Record<string, z.ZodTypeAny>,
158
+ 'passthrough',
159
+ z.ZodTypeAny,
160
+ z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
161
+ z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
162
+ >
95
163
  },
96
164
  'strip',
97
165
  z.ZodTypeAny,
@@ -100,74 +168,75 @@ declare const assetFormSchema: z.ZodObject<
100
168
  media: {
101
169
  tags:
102
170
  | {
103
- label: string
104
171
  value: string
172
+ label: string
105
173
  }[]
106
174
  | null
107
175
  }
108
176
  }
109
177
  originalFilename: string
110
- altText?: string | undefined
111
- creditLine?: string | undefined
112
- description?: string | undefined
113
- title?: string | undefined
178
+ altText?:
179
+ | string
180
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
181
+ | undefined
182
+ creditLine?:
183
+ | string
184
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
185
+ | undefined
186
+ description?:
187
+ | string
188
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
189
+ | undefined
190
+ title?:
191
+ | string
192
+ | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
193
+ | undefined
114
194
  },
115
195
  {
116
196
  opt: {
117
197
  media: {
118
198
  tags:
119
199
  | {
120
- label: string
121
200
  value: string
201
+ label: string
122
202
  }[]
123
203
  | null
124
204
  }
125
205
  }
126
206
  originalFilename: string
127
- altText?: string | undefined
128
- creditLine?: string | undefined
129
- description?: string | undefined
130
- title?: string | undefined
207
+ altText?:
208
+ | string
209
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
210
+ | undefined
211
+ creditLine?:
212
+ | string
213
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
214
+ | undefined
215
+ description?:
216
+ | string
217
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
218
+ | undefined
219
+ title?:
220
+ | string
221
+ | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
222
+ | undefined
131
223
  }
132
224
  >
133
225
 
134
- declare type CustomFields = {
135
- altText?: string
136
- description?: string
137
- opt?: {
138
- media?: {
139
- tags?: SanityReference[]
140
- }
141
- }
142
- title?: string
143
- }
144
-
145
- declare type DetailsProps = {
146
- formUpdating: boolean
147
- handleCreateTag: (title: string) => void
148
- control: Control<AssetFormData>
149
- errors: FieldErrors<AssetFormData>
150
- register: UseFormRegister<AssetFormData>
151
- allTagOptions: TagSelectOption[]
152
- assetTagOptions: TagSelectOption[] | null
153
- currentAsset: Asset
154
- creditLine?: {
155
- enabled: boolean
156
- excludeSources?: string | string[] | undefined
157
- }
158
- }
159
-
160
- declare type FileAsset = SanityAssetDocument &
161
- CustomFields & {
162
- _type: 'sanity.fileAsset'
163
- }
164
-
165
226
  declare type ImageAsset = SanityImageAssetDocument &
166
227
  CustomFields & {
167
228
  _type: 'sanity.imageAsset'
168
- creditLine?: string
229
+ creditLine?: LocalizedString
169
230
  }
170
231
 
232
+ declare type Locale_2 = {
233
+ title: string
234
+ id: string
235
+ [key: string]: unknown
236
+ }
237
+
238
+ declare type LocalizedString = string | Record<string, string>
239
+
171
240
  export declare const media: Plugin_2<void | MediaToolOptions>
172
241
 
173
242
  export declare const mediaAssetSource: {
@@ -188,11 +257,16 @@ export declare type MediaToolOptions = {
188
257
  }
189
258
  >
190
259
  }
191
- creditLine: {
260
+ creditLine?: {
192
261
  enabled: boolean
193
262
  excludeSources?: string | string[]
194
263
  }
195
264
  directUploads?: boolean
265
+ /**
266
+ * Optional locales following Sanity recommended scheme: [{ id, title }]
267
+ * https://www.sanity.io/docs/studio/localization#k4da239411955
268
+ */
269
+ locales?: Locale_2[]
196
270
  }
197
271
 
198
272
  declare type SanityReference = {
@@ -209,12 +283,12 @@ declare const tagOptionSchema: z.ZodObject<
209
283
  'strip',
210
284
  z.ZodTypeAny,
211
285
  {
212
- label: string
213
286
  value: string
287
+ label: string
214
288
  },
215
289
  {
216
- label: string
217
290
  value: string
291
+ label: string
218
292
  }
219
293
  >
220
294