sanity-plugin-media 3.0.5 → 4.1.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.
package/README.md CHANGED
@@ -95,10 +95,14 @@ export default defineConfig({
95
95
  })
96
96
  ```
97
97
 
98
+
98
99
  ### Plugin Config
99
100
 
100
101
  ```ts
101
102
  // sanity.config.ts
103
+ import {media} from 'sanity-plugin-media'
104
+ import {CustomDetails} from './MyCustomDetails'
105
+
102
106
  export default defineConfig({
103
107
  //...
104
108
  plugins: [
@@ -111,13 +115,40 @@ export default defineConfig({
111
115
  // string | string[] - when used with 3rd party asset sources, you may
112
116
  // wish to prevent users overwriting the creditLine based on the `source.name`
113
117
  },
114
- maximumUploadSize: 10000000
118
+ maximumUploadSize: 10000000,
115
119
  // number - maximum file size (in bytes) that can be uploaded through the plugin interface
120
+ directUploads: true,
121
+ // boolean - enable / disable direct uploads through the plugin interface (default true)
122
+ components: {
123
+ details: CustomDetails
124
+ // Custom component for asset details (see below)
125
+ }
126
+ // Custom components to override default UI (see below)
116
127
  })
117
128
  ],
118
129
  })
119
130
  ```
120
131
 
132
+ #### Custom Asset Details Component
133
+
134
+ Custom React component for the asset details form via the plugin config. This allows you to override or extend the default asset details UI.
135
+
136
+ Your component will receive all form props and a `renderDefaultDetails(props)` function for fallback or composition.
137
+
138
+ ```tsx
139
+ // Example custom details component
140
+ export function CustomDetails(props) {
141
+ // You can render the default details, or add your own fields
142
+ return (
143
+ <>
144
+ <h3>Custom header</h3>
145
+ {/* Change the UI as you see fit */}
146
+ {props.renderDefaultDetails(props)}
147
+ </>
148
+ )
149
+ }
150
+ ```
151
+
121
152
  ## Known issues
122
153
 
123
154
  <details>
package/dist/index.d.mts CHANGED
@@ -1,14 +1,177 @@
1
1
  import {AssetSourceComponentProps} from 'sanity'
2
+ import type {ComponentType} from 'react'
3
+ import {Control} from 'react-hook-form'
4
+ import {FieldErrors} from 'react-hook-form'
2
5
  import {ForwardRefExoticComponent} from 'react'
3
6
  import {JSX as JSX_2} from 'react'
4
7
  import {Plugin as Plugin_2} from 'sanity'
5
8
  import {RefAttributes} from 'react'
9
+ import type {SanityAssetDocument} from '@sanity/client'
10
+ import type {SanityImageAssetDocument} from '@sanity/client'
6
11
  import {SVGProps} from 'react'
12
+ import {UseFormRegister} from 'react-hook-form'
13
+ import * as z from 'zod'
14
+
15
+ declare type Asset = FileAsset | ImageAsset
16
+
17
+ declare type AssetFormData = z.infer<typeof assetFormSchema>
18
+
19
+ declare const assetFormSchema: z.ZodObject<
20
+ {
21
+ altText: z.ZodOptional<z.ZodString>
22
+ creditLine: z.ZodOptional<z.ZodString>
23
+ description: z.ZodOptional<z.ZodString>
24
+ opt: z.ZodObject<
25
+ {
26
+ media: z.ZodObject<
27
+ {
28
+ tags: z.ZodNullable<
29
+ z.ZodArray<
30
+ z.ZodObject<
31
+ {
32
+ label: z.ZodString
33
+ value: z.ZodString
34
+ },
35
+ 'strip',
36
+ z.ZodTypeAny,
37
+ {
38
+ label: string
39
+ value: string
40
+ },
41
+ {
42
+ label: string
43
+ value: string
44
+ }
45
+ >,
46
+ 'many'
47
+ >
48
+ >
49
+ },
50
+ 'strip',
51
+ z.ZodTypeAny,
52
+ {
53
+ tags:
54
+ | {
55
+ label: string
56
+ value: string
57
+ }[]
58
+ | null
59
+ },
60
+ {
61
+ tags:
62
+ | {
63
+ label: string
64
+ value: string
65
+ }[]
66
+ | null
67
+ }
68
+ >
69
+ },
70
+ 'strip',
71
+ z.ZodTypeAny,
72
+ {
73
+ media: {
74
+ tags:
75
+ | {
76
+ label: string
77
+ value: string
78
+ }[]
79
+ | null
80
+ }
81
+ },
82
+ {
83
+ media: {
84
+ tags:
85
+ | {
86
+ label: string
87
+ value: string
88
+ }[]
89
+ | null
90
+ }
91
+ }
92
+ >
93
+ originalFilename: z.ZodString
94
+ title: z.ZodOptional<z.ZodString>
95
+ },
96
+ 'strip',
97
+ z.ZodTypeAny,
98
+ {
99
+ opt: {
100
+ media: {
101
+ tags:
102
+ | {
103
+ label: string
104
+ value: string
105
+ }[]
106
+ | null
107
+ }
108
+ }
109
+ originalFilename: string
110
+ altText?: string | undefined
111
+ creditLine?: string | undefined
112
+ description?: string | undefined
113
+ title?: string | undefined
114
+ },
115
+ {
116
+ opt: {
117
+ media: {
118
+ tags:
119
+ | {
120
+ label: string
121
+ value: string
122
+ }[]
123
+ | null
124
+ }
125
+ }
126
+ originalFilename: string
127
+ altText?: string | undefined
128
+ creditLine?: string | undefined
129
+ description?: string | undefined
130
+ title?: string | undefined
131
+ }
132
+ >
133
+
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
+ declare type ImageAsset = SanityImageAssetDocument &
166
+ CustomFields & {
167
+ _type: 'sanity.imageAsset'
168
+ creditLine?: string
169
+ }
7
170
 
8
171
  export declare const media: Plugin_2<void | MediaToolOptions>
9
172
 
10
173
  export declare const mediaAssetSource: {
11
- component: (props: AssetSourceComponentProps) => JSX_2.Element
174
+ component: (props: AssetSourceComponentProps) => JSX_2
12
175
  icon: ForwardRefExoticComponent<
13
176
  Omit<SVGProps<SVGSVGElement>, 'ref'> & RefAttributes<SVGSVGElement>
14
177
  >
@@ -18,10 +181,43 @@ export declare const mediaAssetSource: {
18
181
 
19
182
  export declare type MediaToolOptions = {
20
183
  maximumUploadSize?: number
184
+ components?: {
185
+ details?: ComponentType<
186
+ DetailsProps & {
187
+ renderDefaultDetails: (props: DetailsProps) => JSX_2.Element
188
+ }
189
+ >
190
+ }
21
191
  creditLine: {
22
192
  enabled: boolean
23
193
  excludeSources?: string | string[]
24
194
  }
195
+ directUploads?: boolean
25
196
  }
26
197
 
198
+ declare type SanityReference = {
199
+ _ref: string
200
+ _type: 'reference'
201
+ _weak?: boolean
202
+ }
203
+
204
+ declare const tagOptionSchema: z.ZodObject<
205
+ {
206
+ label: z.ZodString
207
+ value: z.ZodString
208
+ },
209
+ 'strip',
210
+ z.ZodTypeAny,
211
+ {
212
+ label: string
213
+ value: string
214
+ },
215
+ {
216
+ label: string
217
+ value: string
218
+ }
219
+ >
220
+
221
+ declare type TagSelectOption = z.infer<typeof tagOptionSchema>
222
+
27
223
  export {}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,177 @@
1
1
  import {AssetSourceComponentProps} from 'sanity'
2
+ import type {ComponentType} from 'react'
3
+ import {Control} from 'react-hook-form'
4
+ import {FieldErrors} from 'react-hook-form'
2
5
  import {ForwardRefExoticComponent} from 'react'
3
6
  import {JSX as JSX_2} from 'react'
4
7
  import {Plugin as Plugin_2} from 'sanity'
5
8
  import {RefAttributes} from 'react'
9
+ import type {SanityAssetDocument} from '@sanity/client'
10
+ import type {SanityImageAssetDocument} from '@sanity/client'
6
11
  import {SVGProps} from 'react'
12
+ import {UseFormRegister} from 'react-hook-form'
13
+ import * as z from 'zod'
14
+
15
+ declare type Asset = FileAsset | ImageAsset
16
+
17
+ declare type AssetFormData = z.infer<typeof assetFormSchema>
18
+
19
+ declare const assetFormSchema: z.ZodObject<
20
+ {
21
+ altText: z.ZodOptional<z.ZodString>
22
+ creditLine: z.ZodOptional<z.ZodString>
23
+ description: z.ZodOptional<z.ZodString>
24
+ opt: z.ZodObject<
25
+ {
26
+ media: z.ZodObject<
27
+ {
28
+ tags: z.ZodNullable<
29
+ z.ZodArray<
30
+ z.ZodObject<
31
+ {
32
+ label: z.ZodString
33
+ value: z.ZodString
34
+ },
35
+ 'strip',
36
+ z.ZodTypeAny,
37
+ {
38
+ label: string
39
+ value: string
40
+ },
41
+ {
42
+ label: string
43
+ value: string
44
+ }
45
+ >,
46
+ 'many'
47
+ >
48
+ >
49
+ },
50
+ 'strip',
51
+ z.ZodTypeAny,
52
+ {
53
+ tags:
54
+ | {
55
+ label: string
56
+ value: string
57
+ }[]
58
+ | null
59
+ },
60
+ {
61
+ tags:
62
+ | {
63
+ label: string
64
+ value: string
65
+ }[]
66
+ | null
67
+ }
68
+ >
69
+ },
70
+ 'strip',
71
+ z.ZodTypeAny,
72
+ {
73
+ media: {
74
+ tags:
75
+ | {
76
+ label: string
77
+ value: string
78
+ }[]
79
+ | null
80
+ }
81
+ },
82
+ {
83
+ media: {
84
+ tags:
85
+ | {
86
+ label: string
87
+ value: string
88
+ }[]
89
+ | null
90
+ }
91
+ }
92
+ >
93
+ originalFilename: z.ZodString
94
+ title: z.ZodOptional<z.ZodString>
95
+ },
96
+ 'strip',
97
+ z.ZodTypeAny,
98
+ {
99
+ opt: {
100
+ media: {
101
+ tags:
102
+ | {
103
+ label: string
104
+ value: string
105
+ }[]
106
+ | null
107
+ }
108
+ }
109
+ originalFilename: string
110
+ altText?: string | undefined
111
+ creditLine?: string | undefined
112
+ description?: string | undefined
113
+ title?: string | undefined
114
+ },
115
+ {
116
+ opt: {
117
+ media: {
118
+ tags:
119
+ | {
120
+ label: string
121
+ value: string
122
+ }[]
123
+ | null
124
+ }
125
+ }
126
+ originalFilename: string
127
+ altText?: string | undefined
128
+ creditLine?: string | undefined
129
+ description?: string | undefined
130
+ title?: string | undefined
131
+ }
132
+ >
133
+
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
+ declare type ImageAsset = SanityImageAssetDocument &
166
+ CustomFields & {
167
+ _type: 'sanity.imageAsset'
168
+ creditLine?: string
169
+ }
7
170
 
8
171
  export declare const media: Plugin_2<void | MediaToolOptions>
9
172
 
10
173
  export declare const mediaAssetSource: {
11
- component: (props: AssetSourceComponentProps) => JSX_2.Element
174
+ component: (props: AssetSourceComponentProps) => JSX_2
12
175
  icon: ForwardRefExoticComponent<
13
176
  Omit<SVGProps<SVGSVGElement>, 'ref'> & RefAttributes<SVGSVGElement>
14
177
  >
@@ -18,10 +181,43 @@ export declare const mediaAssetSource: {
18
181
 
19
182
  export declare type MediaToolOptions = {
20
183
  maximumUploadSize?: number
184
+ components?: {
185
+ details?: ComponentType<
186
+ DetailsProps & {
187
+ renderDefaultDetails: (props: DetailsProps) => JSX_2.Element
188
+ }
189
+ >
190
+ }
21
191
  creditLine: {
22
192
  enabled: boolean
23
193
  excludeSources?: string | string[]
24
194
  }
195
+ directUploads?: boolean
25
196
  }
26
197
 
198
+ declare type SanityReference = {
199
+ _ref: string
200
+ _type: 'reference'
201
+ _weak?: boolean
202
+ }
203
+
204
+ declare const tagOptionSchema: z.ZodObject<
205
+ {
206
+ label: z.ZodString
207
+ value: z.ZodString
208
+ },
209
+ 'strip',
210
+ z.ZodTypeAny,
211
+ {
212
+ label: string
213
+ value: string
214
+ },
215
+ {
216
+ label: string
217
+ value: string
218
+ }
219
+ >
220
+
221
+ declare type TagSelectOption = z.infer<typeof tagOptionSchema>
222
+
27
223
  export {}