sanity-plugin-media 4.3.1 → 4.3.3

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 (147) hide show
  1. package/LICENSE +4 -4
  2. package/README.md +12 -12
  3. package/dist/{index.mjs → index.cjs} +1115 -1242
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +462 -0
  6. package/dist/index.d.ts +263 -195
  7. package/dist/index.js +1125 -1237
  8. package/dist/index.js.map +1 -1
  9. package/package.json +45 -68
  10. package/src/__tests__/fixtures/createEpicTestStore.ts +5 -4
  11. package/src/__tests__/fixtures/mockSanityClient.ts +8 -8
  12. package/src/__tests__/fixtures/renderWithProviders.tsx +8 -7
  13. package/src/__tests__/fixtures/rootState.ts +4 -4
  14. package/src/components/AssetGridVirtualized/index.tsx +8 -7
  15. package/src/components/AssetMetadata/index.tsx +6 -5
  16. package/src/components/AssetTableVirtualized/index.tsx +7 -6
  17. package/src/components/AutoTagInputWrapper/index.tsx +9 -4
  18. package/src/components/Browser/Browser.test.tsx +9 -8
  19. package/src/components/Browser/index.tsx +2 -1
  20. package/src/components/Browser/useBrowserInit.ts +9 -9
  21. package/src/components/ButtonAssetCopy/index.tsx +1 -0
  22. package/src/components/ButtonViewGroup/index.tsx +4 -3
  23. package/src/components/CardAsset/CardAsset.test.tsx +53 -52
  24. package/src/components/CardAsset/index.tsx +52 -49
  25. package/src/components/CardUpload/index.tsx +7 -6
  26. package/src/components/Controls/index.tsx +7 -6
  27. package/src/components/DebugControls/index.tsx +5 -4
  28. package/src/components/DialogAssetEdit/Details.tsx +3 -2
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +28 -27
  30. package/src/components/DialogAssetEdit/index.tsx +37 -37
  31. package/src/components/DialogConfirm/index.tsx +2 -1
  32. package/src/components/DialogSearchFacets/index.tsx +3 -2
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +16 -15
  34. package/src/components/DialogTagCreate/index.tsx +11 -10
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +28 -27
  36. package/src/components/DialogTagEdit/index.tsx +17 -16
  37. package/src/components/DialogTags/index.tsx +4 -3
  38. package/src/components/Dialogs/index.tsx +2 -3
  39. package/src/components/DocumentList/index.tsx +2 -3
  40. package/src/components/FileAssetPreview/index.tsx +2 -2
  41. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +12 -11
  42. package/src/components/FormBuilderTool/index.tsx +2 -1
  43. package/src/components/FormFieldInputLabel/index.tsx +1 -2
  44. package/src/components/FormFieldInputTags/index.tsx +4 -3
  45. package/src/components/FormSubmitButton/index.tsx +1 -1
  46. package/src/components/Header/index.tsx +3 -3
  47. package/src/components/Image/index.tsx +10 -4
  48. package/src/components/Items/index.tsx +5 -4
  49. package/src/components/Notifications/index.tsx +3 -2
  50. package/src/components/OrderSelect/index.tsx +4 -3
  51. package/src/components/PickedBar/index.tsx +2 -1
  52. package/src/components/Progress/index.tsx +3 -3
  53. package/src/components/ReduxProvider/index.tsx +15 -12
  54. package/src/components/SearchFacet/index.tsx +3 -2
  55. package/src/components/SearchFacetNumber/index.tsx +8 -8
  56. package/src/components/SearchFacetSelect/index.tsx +7 -8
  57. package/src/components/SearchFacetString/index.tsx +1 -1
  58. package/src/components/SearchFacetTags/index.tsx +13 -12
  59. package/src/components/SearchFacets/index.tsx +2 -3
  60. package/src/components/SearchFacetsControl/index.tsx +13 -12
  61. package/src/components/TableHeader/index.tsx +18 -17
  62. package/src/components/TableHeaderItem/index.tsx +4 -4
  63. package/src/components/TableRowAsset/index.tsx +37 -36
  64. package/src/components/TableRowUpload/index.tsx +7 -6
  65. package/src/components/Tag/index.tsx +8 -7
  66. package/src/components/TagView/index.tsx +2 -2
  67. package/src/components/TagViewHeader/index.tsx +5 -4
  68. package/src/components/TagsPanel/index.tsx +3 -3
  69. package/src/components/TagsVirtualized/index.tsx +25 -24
  70. package/src/components/TextInputSearch/index.tsx +3 -2
  71. package/src/components/UploadDropzone/UploadDropzone.test.tsx +8 -7
  72. package/src/components/UploadDropzone/index.tsx +14 -13
  73. package/src/config/orders.ts +6 -6
  74. package/src/config/searchFacets.ts +56 -55
  75. package/src/constants.ts +15 -14
  76. package/src/contexts/AssetSourceDispatchContext.tsx +1 -1
  77. package/src/contexts/ToolOptionsContext.tsx +6 -5
  78. package/src/formSchema/index.test.ts +6 -5
  79. package/src/formSchema/index.ts +5 -5
  80. package/src/hooks/useBreakpointIndex.ts +6 -6
  81. package/src/hooks/useKeyPress.ts +2 -2
  82. package/src/hooks/usePortalPopoverProps.ts +1 -1
  83. package/src/modules/assets/actions.ts +8 -7
  84. package/src/modules/assets/deleteAndUpdateEpics.test.ts +18 -17
  85. package/src/modules/assets/fetchEpic.test.ts +12 -11
  86. package/src/modules/assets/index.ts +134 -133
  87. package/src/modules/assets/reducer.test.ts +9 -8
  88. package/src/modules/assets/tagsAndListenerEpics.test.ts +36 -35
  89. package/src/modules/debug/index.ts +3 -3
  90. package/src/modules/dialog/actions.ts +2 -2
  91. package/src/modules/dialog/epics.test.ts +29 -28
  92. package/src/modules/dialog/index.ts +36 -35
  93. package/src/modules/dialog/reducer.test.ts +31 -30
  94. package/src/modules/index.ts +9 -9
  95. package/src/modules/notifications/epics.test.ts +71 -70
  96. package/src/modules/notifications/index.ts +50 -49
  97. package/src/modules/notifications/reducer.test.ts +8 -7
  98. package/src/modules/search/index.test.ts +2 -1
  99. package/src/modules/search/index.ts +22 -22
  100. package/src/modules/selected/index.ts +2 -2
  101. package/src/modules/selectors.test.ts +4 -3
  102. package/src/modules/selectors.ts +5 -5
  103. package/src/modules/tags/epics.test.ts +16 -15
  104. package/src/modules/tags/index.test.ts +2 -1
  105. package/src/modules/tags/index.ts +82 -81
  106. package/src/modules/uploads/actions.ts +3 -3
  107. package/src/modules/uploads/epics.test.ts +13 -12
  108. package/src/modules/uploads/index.test.ts +8 -7
  109. package/src/modules/uploads/index.ts +48 -47
  110. package/src/operators/checkTagName.test.ts +7 -6
  111. package/src/operators/checkTagName.ts +6 -5
  112. package/src/operators/debugThrottle.ts +4 -4
  113. package/src/plugin.tsx +18 -18
  114. package/src/schemas/tag.ts +7 -7
  115. package/src/styled/react-select/creatable.tsx +40 -39
  116. package/src/styled/react-select/single.tsx +39 -38
  117. package/src/types/index.ts +4 -3
  118. package/src/utils/applyMediaTags.ts +11 -10
  119. package/src/utils/blocksToText.test.ts +5 -4
  120. package/src/utils/blocksToText.ts +2 -2
  121. package/src/utils/constructFilter.test.ts +15 -14
  122. package/src/utils/constructFilter.ts +7 -7
  123. package/src/utils/generatePreviewBlobUrl.test.ts +6 -5
  124. package/src/utils/generatePreviewBlobUrl.ts +2 -2
  125. package/src/utils/getAssetResolution.test.ts +3 -2
  126. package/src/utils/getDocumentAssetIds.test.ts +7 -6
  127. package/src/utils/getDocumentAssetIds.ts +2 -2
  128. package/src/utils/getSchemeColor.test.ts +1 -0
  129. package/src/utils/getSchemeColor.ts +9 -9
  130. package/src/utils/getTagSelectOptions.test.ts +6 -5
  131. package/src/utils/getTagSelectOptions.ts +1 -1
  132. package/src/utils/getUniqueDocuments.test.ts +4 -3
  133. package/src/utils/getUniqueDocuments.ts +2 -2
  134. package/src/utils/imageDprUrl.test.ts +4 -3
  135. package/src/utils/imageDprUrl.ts +1 -1
  136. package/src/utils/isSupportedAssetType.test.ts +1 -0
  137. package/src/utils/mediaField.ts +4 -3
  138. package/src/utils/sanitizeFormData.test.ts +14 -13
  139. package/src/utils/typeGuards.test.ts +2 -1
  140. package/src/utils/uploadSanityAsset.test.ts +5 -4
  141. package/src/utils/uploadSanityAsset.ts +17 -16
  142. package/src/utils/withMaxConcurrency.test.ts +5 -4
  143. package/src/utils/withMaxConcurrency.ts +4 -4
  144. package/src/utils/zodFormResolver.ts +17 -0
  145. package/v2-incompatible.js +2 -2
  146. package/dist/index.d.mts +0 -394
  147. package/dist/index.mjs.map +0 -1
package/dist/index.d.mts DELETED
@@ -1,394 +0,0 @@
1
- import {AssetSourceComponentProps} from 'sanity'
2
- import type {ComponentType} from 'react'
3
- import {Control} from 'react-hook-form'
4
- import type {FieldDefinitionBase} from 'sanity'
5
- import {FieldErrors} from 'react-hook-form'
6
- import type {FileDefinition} from 'sanity'
7
- import {ForwardRefExoticComponent} from 'react'
8
- import type {ImageDefinition} from 'sanity'
9
- import {InputProps} from 'sanity'
10
- import {JSX as JSX_2} from 'react'
11
- import {Plugin as Plugin_2} from 'sanity'
12
- import {RefAttributes} from 'react'
13
- import type {SanityAssetDocument} from '@sanity/client'
14
- import type {SanityImageAssetDocument} from '@sanity/client'
15
- import {SVGProps} from 'react'
16
- import {UseFormRegister} from 'react-hook-form'
17
- import type {WidenInitialValue} from 'sanity'
18
- import type {WidenValidation} from 'sanity'
19
- import * as z from 'zod'
20
-
21
- declare type Asset = FileAsset | ImageAsset
22
-
23
- declare type AssetFormData = z.infer<ReturnType<typeof getAssetFormSchema>>
24
-
25
- /**
26
- * Input component that automatically applies media tags when an asset is selected or uploaded.
27
- *
28
- * Apply explicitly to image/file fields that should be auto-tagged:
29
- * ```ts
30
- * import {AutoTagInput} from 'sanity-plugin-media'
31
- *
32
- * defineField({
33
- * type: 'image',
34
- * options: { mediaTags: ['product'] }, // also pre-filters the media browser
35
- * components: { input: AutoTagInput },
36
- * })
37
- * ```
38
- *
39
- * Pass `mediaTags` as a prop to override or use without `options`:
40
- * ```ts
41
- * components: { input: (props) => <AutoTagInput {...props} mediaTags={['product']} /> }
42
- * ```
43
- */
44
- export declare function AutoTagInput(props: AutoTagInputProps): JSX_2
45
-
46
- export declare type AutoTagInputProps = InputProps & {
47
- mediaTags?: string[]
48
- }
49
-
50
- declare type CustomFields = {
51
- altText?: LocalizedString
52
- description?: LocalizedString
53
- opt?: {
54
- media?: {
55
- tags?: SanityReference[]
56
- }
57
- }
58
- title?: LocalizedString
59
- }
60
-
61
- declare type DetailsProps = {
62
- formUpdating: boolean
63
- handleCreateTag: (title: string) => void
64
- control: Control<AssetFormData>
65
- errors: FieldErrors<AssetFormData>
66
- register: UseFormRegister<AssetFormData>
67
- allTagOptions: TagSelectOption[]
68
- assetTagOptions: TagSelectOption[] | null
69
- currentAsset: Asset
70
- creditLine?: {
71
- enabled: boolean
72
- excludeSources?: string | string[] | undefined
73
- }
74
- locales?: Locale_2[]
75
- }
76
-
77
- declare type FileAsset = SanityAssetDocument &
78
- CustomFields & {
79
- _type: 'sanity.fileAsset'
80
- }
81
-
82
- declare type FileMediaFieldConfig = Omit<FileDefinition, 'options'> &
83
- FieldDefinitionBase & {
84
- name: string
85
- mediaTags: string[]
86
- options?: FileDefinition['options']
87
- }
88
-
89
- declare type FileMediaFieldResult = Omit<FileDefinition, 'options'> &
90
- FieldDefinitionBase & {
91
- options?: FileDefinition['options'] & {
92
- mediaTags: string[]
93
- }
94
- components: {
95
- input: typeof AutoTagInput
96
- }
97
- } & WidenValidation &
98
- WidenInitialValue
99
-
100
- declare function getAssetFormSchema(
101
- locales?: {
102
- id: string
103
- }[]
104
- ): z.ZodObject<
105
- {
106
- altText:
107
- | z.ZodOptional<z.ZodString>
108
- | z.ZodObject<
109
- Record<string, z.ZodTypeAny>,
110
- 'passthrough',
111
- z.ZodTypeAny,
112
- z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
113
- z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
114
- >
115
- creditLine:
116
- | z.ZodOptional<z.ZodString>
117
- | z.ZodObject<
118
- Record<string, z.ZodTypeAny>,
119
- 'passthrough',
120
- z.ZodTypeAny,
121
- z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
122
- z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
123
- >
124
- description:
125
- | z.ZodOptional<z.ZodString>
126
- | z.ZodObject<
127
- Record<string, z.ZodTypeAny>,
128
- 'passthrough',
129
- z.ZodTypeAny,
130
- z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
131
- z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
132
- >
133
- opt: z.ZodObject<
134
- {
135
- media: z.ZodObject<
136
- {
137
- tags: z.ZodNullable<
138
- z.ZodArray<
139
- z.ZodObject<
140
- {
141
- label: z.ZodString
142
- value: z.ZodString
143
- },
144
- 'strip',
145
- z.ZodTypeAny,
146
- {
147
- value: string
148
- label: string
149
- },
150
- {
151
- value: string
152
- label: string
153
- }
154
- >,
155
- 'many'
156
- >
157
- >
158
- },
159
- 'strip',
160
- z.ZodTypeAny,
161
- {
162
- tags:
163
- | {
164
- value: string
165
- label: string
166
- }[]
167
- | null
168
- },
169
- {
170
- tags:
171
- | {
172
- value: string
173
- label: string
174
- }[]
175
- | null
176
- }
177
- >
178
- },
179
- 'strip',
180
- z.ZodTypeAny,
181
- {
182
- media: {
183
- tags:
184
- | {
185
- value: string
186
- label: string
187
- }[]
188
- | null
189
- }
190
- },
191
- {
192
- media: {
193
- tags:
194
- | {
195
- value: string
196
- label: string
197
- }[]
198
- | null
199
- }
200
- }
201
- >
202
- originalFilename: z.ZodString
203
- title:
204
- | z.ZodOptional<z.ZodString>
205
- | z.ZodObject<
206
- Record<string, z.ZodTypeAny>,
207
- 'passthrough',
208
- z.ZodTypeAny,
209
- z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>,
210
- z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
211
- >
212
- },
213
- 'strip',
214
- z.ZodTypeAny,
215
- {
216
- opt: {
217
- media: {
218
- tags:
219
- | {
220
- value: string
221
- label: string
222
- }[]
223
- | null
224
- }
225
- }
226
- originalFilename: string
227
- altText?:
228
- | string
229
- | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
230
- | undefined
231
- creditLine?:
232
- | string
233
- | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
234
- | undefined
235
- description?:
236
- | string
237
- | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
238
- | undefined
239
- title?:
240
- | string
241
- | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
242
- | undefined
243
- },
244
- {
245
- opt: {
246
- media: {
247
- tags:
248
- | {
249
- value: string
250
- label: string
251
- }[]
252
- | null
253
- }
254
- }
255
- originalFilename: string
256
- altText?:
257
- | string
258
- | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
259
- | undefined
260
- creditLine?:
261
- | string
262
- | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
263
- | undefined
264
- description?:
265
- | string
266
- | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
267
- | undefined
268
- title?:
269
- | string
270
- | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, 'passthrough'>
271
- | undefined
272
- }
273
- >
274
-
275
- declare type ImageAsset = SanityImageAssetDocument &
276
- CustomFields & {
277
- _type: 'sanity.imageAsset'
278
- creditLine?: LocalizedString
279
- }
280
-
281
- declare type ImageMediaFieldConfig = Omit<ImageDefinition, 'options'> &
282
- FieldDefinitionBase & {
283
- name: string
284
- mediaTags: string[]
285
- options?: ImageDefinition['options']
286
- }
287
-
288
- declare type ImageMediaFieldResult = Omit<ImageDefinition, 'options'> &
289
- FieldDefinitionBase & {
290
- options?: ImageDefinition['options'] & {
291
- mediaTags: string[]
292
- }
293
- components: {
294
- input: typeof AutoTagInput
295
- }
296
- } & WidenValidation &
297
- WidenInitialValue
298
-
299
- declare type Locale_2 = {
300
- title: string
301
- id: string
302
- [key: string]: unknown
303
- }
304
-
305
- declare type LocalizedString = string | Record<string, string>
306
-
307
- export declare const media: Plugin_2<void | MediaToolOptions>
308
-
309
- export declare const mediaAssetSource: {
310
- component: (props: AssetSourceComponentProps) => JSX_2
311
- icon: ForwardRefExoticComponent<
312
- Omit<SVGProps<SVGSVGElement>, 'ref'> & RefAttributes<SVGSVGElement>
313
- >
314
- name: string
315
- title: string
316
- }
317
-
318
- /**
319
- * Defines an image or file field with automatic media tag application when an asset is selected.
320
- *
321
- * Pass `mediaTags` at the top level — they are moved into `options.mediaTags` (for media browser
322
- * pre-filtering) and wire up {@link AutoTagInput} as the field component automatically:
323
- * ```ts
324
- * import {mediaField} from 'sanity-plugin-media'
325
- *
326
- * mediaField({
327
- * name: 'coverImage',
328
- * type: 'image',
329
- * mediaTags: ['product-cover'],
330
- * options: { hotspot: true },
331
- * })
332
- * ```
333
- *
334
- * For file fields, set `type: 'file'`:
335
- * ```ts
336
- * mediaField({ name: 'drawing', type: 'file', mediaTags: ['model-drawing'] })
337
- * ```
338
- */
339
- export declare function mediaField(config: ImageMediaFieldConfig): ImageMediaFieldResult
340
-
341
- export declare function mediaField(config: FileMediaFieldConfig): FileMediaFieldResult
342
-
343
- export declare type MediaTagsOptions = {
344
- mediaTags?: string[]
345
- }
346
-
347
- export declare type MediaToolOptions = {
348
- maximumUploadSize?: number
349
- createTagsOnUpload?: boolean
350
- components?: {
351
- details?: ComponentType<
352
- DetailsProps & {
353
- renderDefaultDetails: (props: DetailsProps) => JSX_2.Element
354
- }
355
- >
356
- }
357
- creditLine?: {
358
- enabled: boolean
359
- excludeSources?: string | string[]
360
- }
361
- directUploads?: boolean
362
- /**
363
- * Optional locales following Sanity recommended scheme: [{ id, title }]
364
- * https://www.sanity.io/docs/studio/localization#k4da239411955
365
- */
366
- locales?: Locale_2[]
367
- }
368
-
369
- declare type SanityReference = {
370
- _ref: string
371
- _type: 'reference'
372
- _weak?: boolean
373
- }
374
-
375
- declare const tagOptionSchema: z.ZodObject<
376
- {
377
- label: z.ZodString
378
- value: z.ZodString
379
- },
380
- 'strip',
381
- z.ZodTypeAny,
382
- {
383
- value: string
384
- label: string
385
- },
386
- {
387
- value: string
388
- label: string
389
- }
390
- >
391
-
392
- declare type TagSelectOption = z.infer<typeof tagOptionSchema>
393
-
394
- export {}