@electrolux-oss/sanity-plugin-media 3.0.0 → 4.0.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
@@ -1,9 +1,16 @@
1
- # Sanity Media Plugin - Electrolux Version (for Sanity Studio v4)
1
+ # Sanity Media Plugin - Electrolux Version (for Sanity Studio v5 and v6)
2
2
 
3
- > This plugin is for **Sanity Studio v4**.
3
+ > This plugin supports **Sanity Studio v5 and v6**.
4
4
  > This is a forked version of Sanitys own [Media Plugin (v4.0.0)](https://github.com/sanity-io/sanity-plugin-media)
5
5
 
6
- ## :warning: Breaking changes - (v2.0.0 → v3.0.0)
6
+ ## :warning: Breaking changes - (v3.0.0 → v4.0.0)
7
+
8
+ ### **v3 → v4**
9
+
10
+ This release targets **Sanity Studio v5 and v6**. Support for Studio v4 has been dropped, and the
11
+ package is now **ESM-only** (the CommonJS build has been removed).
12
+ Projects must be on Studio v5 or v6 (and React 19.2.2 or newer) before upgrading to v4.
13
+
7
14
  ### **v2 → v3**
8
15
 
9
16
  This release upgrades the plugin’s peer dependency from **React 18** to **React 19**.
@@ -11,7 +18,7 @@ Projects using this plugin must update to React 19 before upgrading to v3.
11
18
 
12
19
  ## What is it?
13
20
 
14
- A Sanity Studio v4 plugin that extends media handling capabilities with custom enhancements, based on a fork of an original plugin by Sanity.io.
21
+ A Sanity Studio v5 / v6 plugin that extends media handling capabilities with custom enhancements, based on a fork of an original plugin by Sanity.io.
15
22
 
16
23
  A convenient way to browse, manage and refine your [Sanity](https://www.sanity.io/) assets.
17
24
 
@@ -20,11 +27,9 @@ Use it standalone as a browser, or optionally hook it up as a [custom asset sour
20
27
  ![Grid view](https://user-images.githubusercontent.com/209129/108927411-21aa7f00-7638-11eb-9cf7-334598ac4103.png)
21
28
  _Default grid view_
22
29
 
23
-
24
- _Asset details tab_ | _Asset alt texts tab_
25
- :-------------------------:|:-------------------------:
26
- ![first](https://github.com/user-attachments/assets/477b6576-a1a4-42e2-b2c2-2d2e962eb366) | ![second](https://github.com/user-attachments/assets/2c5bd907-1b60-48c6-a007-2f7304409007)
27
-
30
+ | _Asset details tab_ | _Asset alt texts tab_ |
31
+ | :---------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |
32
+ | ![first](https://github.com/user-attachments/assets/477b6576-a1a4-42e2-b2c2-2d2e962eb366) | ![second](https://github.com/user-attachments/assets/2c5bd907-1b60-48c6-a007-2f7304409007) |
28
33
 
29
34
  ## Features
30
35
 
@@ -58,18 +63,18 @@ _Asset details tab_ | _Asset alt texts tab_
58
63
  - Define a list of available languages to enable multi-language alt texts for assets.
59
64
  - See example of how to enable this feature [here](###plugin-config).
60
65
 
61
- ## Install (Sanity Studio v4)
66
+ ## Install (Sanity Studio v5 and v6)
62
67
 
63
68
  In your Sanity project folder:
64
69
 
65
70
  ```zsh
66
- npm install --save sanity-plugin-media
71
+ npm install --save @electrolux-oss/sanity-plugin-media
67
72
  ```
68
73
 
69
74
  or
70
75
 
71
76
  ```zsh
72
- yarn add sanity-plugin-media
77
+ yarn add @electrolux-oss/sanity-plugin-media
73
78
  ```
74
79
 
75
80
  ## Usage
@@ -77,19 +82,19 @@ yarn add sanity-plugin-media
77
82
  Add it as a plugin in your `sanity.config.ts` (or .js) file:
78
83
 
79
84
  ```js
80
- import { media } from 'sanity-plugin-media'
85
+ import { media } from '@electrolux-oss/sanity-plugin-media'
81
86
 
82
87
  export default defineConfig({
83
88
  // ...
84
89
  plugins: [
85
- media(
90
+ media({
86
91
  languages: [
87
92
  { code: 'en-US', title: 'English', default: true },
88
93
  { code: 'sv-SE', title: 'Swedish' },
89
94
  { code: 'fr-FR', title: 'French' },
90
95
  { code: 'de-DE', title: 'German' }
91
- ],
92
- )
96
+ ]
97
+ })
93
98
  ]
94
99
  })
95
100
  ```
@@ -101,7 +106,7 @@ This will enable the Media plugin as both a standalone tool (accessible in your
101
106
  You can configure your studio to use this asset source either exclusively, or conditionally enable it based on the type of asset (image or file).
102
107
 
103
108
  ```js
104
- import { media, mediaAssetSource } from 'sanity-plugin-media'
109
+ import { media, mediaAssetSource } from '@electrolux-oss/sanity-plugin-media'
105
110
 
106
111
  export default defineConfig({
107
112
  // ...
@@ -126,7 +131,7 @@ export default defineConfig({
126
131
  plugins: [
127
132
  media({
128
133
  // { code: string; title: string, default?: boolean }[] - the list of languages used for alt texts
129
- // NOTE! Set only one language to default: true.
134
+ // NOTE! Set only one language to default: true.
130
135
  languages: [
131
136
  { code: 'en-US', title: 'English', default: true },
132
137
  { code: 'sv-SE', title: 'Swedish' },
@@ -137,14 +142,19 @@ export default defineConfig({
137
142
  enabled: true,
138
143
  // boolean - enables an optional "Credit Line" field in the plugin.
139
144
  // Used to store credits e.g. photographer, licence information
140
- excludeSources: ['unsplash'],
145
+ excludeSources: ['unsplash']
141
146
  // string | string[] - when used with 3rd party asset sources, you may
142
147
  // wish to prevent users overwriting the creditLine based on the `source.name`
143
148
  },
144
- maximumUploadSize: 10000000
149
+ maximumUploadSize: 10000000,
145
150
  // number - maximum file size (in bytes) that can be uploaded through the plugin interface
151
+ directUploads: true,
152
+ // boolean - enable / disable direct uploads through the plugin interface (default true)
153
+ components: {
154
+ details: CustomDetails
155
+ }
146
156
  })
147
- ],
157
+ ]
148
158
  })
149
159
  ```
150
160
 
@@ -155,17 +165,20 @@ export default defineConfig({
155
165
  **Step 1: Set up the plugin for local development**
156
166
 
157
167
  In the plugin directory, run:
168
+
158
169
  ```zsh
159
170
  npm run link-watch
160
171
  ```
161
172
 
162
173
  This will:
174
+
163
175
  - Build your plugin automatically whenever code changes
164
176
  - Publish the package to a local yalc repository
165
177
 
166
178
  **Step 2: Link the plugin to your studio**
167
179
 
168
180
  In your studio project directory, run:
181
+
169
182
  ```zsh
170
183
  npx yalc add @electrolux-oss/sanity-plugin-media && npm install
171
184
  ```
@@ -173,18 +186,21 @@ npx yalc add @electrolux-oss/sanity-plugin-media && npm install
173
186
  **Step 3: Verify the setup**
174
187
 
175
188
  Check your studio's `package.json` - you should see:
189
+
176
190
  ```json
177
191
  "@electrolux-oss/sanity-plugin-media": "file:.yalc/@electrolux-oss/sanity-plugin-media"
178
192
  ```
179
193
 
180
194
  Now you can use the local version of the plugin:
195
+
181
196
  ```typescript
182
- import { workflow } from '@electrolux-oss/sanity-plugin-media'
197
+ import { media } from '@electrolux-oss/sanity-plugin-media'
183
198
  ```
184
199
 
185
200
  ### Making changes
186
201
 
187
202
  When you modify the plugin code:
203
+
188
204
  1. The `link-watch` command will automatically rebuild
189
205
  2. In your studio, run `npx yalc update` to pull the latest changes
190
206
  3. Restart your dev server: `npm run dev`
package/dist/index.d.ts CHANGED
@@ -1,14 +1,193 @@
1
1
  import { AssetSourceComponentProps } from 'sanity'
2
+ import type { ComponentType } from 'react'
3
+ import type { Control } from 'react-hook-form'
4
+ import type { FieldErrors } from 'react-hook-form'
2
5
  import { ForwardRefExoticComponent } from 'react'
3
6
  import { JSX } 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 type { 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<AssetFormSchemaObject>
18
+
19
+ declare type AssetFormSchemaObject = ReturnType<typeof createAssetFormSchema>
20
+
21
+ declare const createAssetFormSchema: (
22
+ languages: MediaToolOptions['languages'],
23
+ validateAltTexts?: boolean
24
+ ) => z.ZodObject<
25
+ {
26
+ altText: z.ZodOptional<z.ZodString>
27
+ altTexts:
28
+ | z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>
29
+ | z.ZodEffects<
30
+ z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>,
31
+ Record<string, string | null>,
32
+ Record<string, string | null>
33
+ >
34
+ creditLine: z.ZodOptional<z.ZodString>
35
+ description: z.ZodOptional<z.ZodString>
36
+ opt: z.ZodObject<
37
+ {
38
+ media: z.ZodObject<
39
+ {
40
+ tags: z.ZodNullable<
41
+ z.ZodArray<
42
+ z.ZodObject<
43
+ {
44
+ label: z.ZodString
45
+ value: z.ZodString
46
+ },
47
+ 'strip',
48
+ z.ZodTypeAny,
49
+ {
50
+ label: string
51
+ value: string
52
+ },
53
+ {
54
+ label: string
55
+ value: string
56
+ }
57
+ >,
58
+ 'many'
59
+ >
60
+ >
61
+ },
62
+ 'strip',
63
+ z.ZodTypeAny,
64
+ {
65
+ tags:
66
+ | {
67
+ label: string
68
+ value: string
69
+ }[]
70
+ | null
71
+ },
72
+ {
73
+ tags:
74
+ | {
75
+ label: string
76
+ value: string
77
+ }[]
78
+ | null
79
+ }
80
+ >
81
+ },
82
+ 'strip',
83
+ z.ZodTypeAny,
84
+ {
85
+ media: {
86
+ tags:
87
+ | {
88
+ label: string
89
+ value: string
90
+ }[]
91
+ | null
92
+ }
93
+ },
94
+ {
95
+ media: {
96
+ tags:
97
+ | {
98
+ label: string
99
+ value: string
100
+ }[]
101
+ | null
102
+ }
103
+ }
104
+ >
105
+ originalFilename: z.ZodString
106
+ title: z.ZodOptional<z.ZodString>
107
+ },
108
+ 'strip',
109
+ z.ZodTypeAny,
110
+ {
111
+ altTexts: Record<string, string | null>
112
+ opt: {
113
+ media: {
114
+ tags:
115
+ | {
116
+ label: string
117
+ value: string
118
+ }[]
119
+ | null
120
+ }
121
+ }
122
+ originalFilename: string
123
+ altText?: string | undefined
124
+ creditLine?: string | undefined
125
+ description?: string | undefined
126
+ title?: string | undefined
127
+ },
128
+ {
129
+ altTexts: Record<string, string | null>
130
+ opt: {
131
+ media: {
132
+ tags:
133
+ | {
134
+ label: string
135
+ value: string
136
+ }[]
137
+ | null
138
+ }
139
+ }
140
+ originalFilename: string
141
+ altText?: string | undefined
142
+ creditLine?: string | undefined
143
+ description?: string | undefined
144
+ title?: string | undefined
145
+ }
146
+ >
147
+
148
+ declare type CustomFields = {
149
+ altText?: string
150
+ altTexts?: Record<string, string>
151
+ description?: string
152
+ opt?: {
153
+ media?: {
154
+ tags?: SanityReference[]
155
+ }
156
+ }
157
+ title?: string
158
+ }
159
+
160
+ declare type DetailsProps = {
161
+ formUpdating: boolean
162
+ handleCreateTag: (title: string) => void
163
+ control: Control<AssetFormData>
164
+ errors: FieldErrors<AssetFormData>
165
+ register: UseFormRegister<AssetFormData>
166
+ allTagOptions: TagSelectOption[]
167
+ assetTagOptions: TagSelectOption[] | null
168
+ currentAsset: Asset
169
+ creditLine?: {
170
+ enabled: boolean
171
+ excludeSources?: string | string[] | undefined
172
+ }
173
+ }
174
+
175
+ declare type FileAsset = SanityAssetDocument &
176
+ CustomFields & {
177
+ _type: 'sanity.fileAsset'
178
+ }
179
+
180
+ declare type ImageAsset = SanityImageAssetDocument &
181
+ CustomFields & {
182
+ _type: 'sanity.imageAsset'
183
+ creditLine?: string
184
+ }
7
185
 
8
186
  export declare const media: Plugin_2<void | MediaToolOptions>
9
187
 
10
188
  export declare const mediaAssetSource: {
11
- component: (props: AssetSourceComponentProps) => JSX.Element
189
+ component: (props: AssetSourceComponentProps) => JSX
190
+ uploadMode: 'component'
12
191
  icon: ForwardRefExoticComponent<
13
192
  Omit<SVGProps<SVGSVGElement>, 'ref'> & RefAttributes<SVGSVGElement>
14
193
  >
@@ -23,10 +202,43 @@ export declare type MediaToolOptions = {
23
202
  default?: boolean
24
203
  }[]
25
204
  maximumUploadSize?: number
205
+ components?: {
206
+ details?: ComponentType<
207
+ DetailsProps & {
208
+ renderDefaultDetails: (props: DetailsProps) => JSX.Element
209
+ }
210
+ >
211
+ }
26
212
  creditLine: {
27
213
  enabled: boolean
28
214
  excludeSources?: string | string[]
29
215
  }
216
+ directUploads?: boolean
30
217
  }
31
218
 
219
+ declare type SanityReference = {
220
+ _ref: string
221
+ _type: 'reference'
222
+ _weak?: boolean
223
+ }
224
+
225
+ declare const tagOptionSchema: z.ZodObject<
226
+ {
227
+ label: z.ZodString
228
+ value: z.ZodString
229
+ },
230
+ 'strip',
231
+ z.ZodTypeAny,
232
+ {
233
+ label: string
234
+ value: string
235
+ },
236
+ {
237
+ label: string
238
+ value: string
239
+ }
240
+ >
241
+
242
+ declare type TagSelectOption = z.infer<typeof tagOptionSchema>
243
+
32
244
  export {}