@electrolux-oss/sanity-plugin-media 2.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 +63 -29
- package/dist/index.d.ts +213 -1
- package/dist/index.js +1671 -1316
- package/dist/index.js.map +1 -1
- package/package.json +33 -47
- package/dist/index.d.mts +0 -32
- package/dist/index.mjs +0 -5618
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
package/README.md
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
# Sanity Media Plugin - Electrolux Version (for Sanity Studio
|
|
1
|
+
# Sanity Media Plugin - Electrolux Version (for Sanity Studio v5 and v6)
|
|
2
2
|
|
|
3
|
-
> This plugin
|
|
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 - (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
|
+
|
|
14
|
+
### **v2 → v3**
|
|
15
|
+
|
|
16
|
+
This release upgrades the plugin’s peer dependency from **React 18** to **React 19**.
|
|
17
|
+
Projects using this plugin must update to React 19 before upgrading to v3.
|
|
18
|
+
|
|
6
19
|
## What is it?
|
|
7
20
|
|
|
8
|
-
A Sanity Studio
|
|
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.
|
|
9
22
|
|
|
10
23
|
A convenient way to browse, manage and refine your [Sanity](https://www.sanity.io/) assets.
|
|
11
24
|
|
|
@@ -14,11 +27,9 @@ Use it standalone as a browser, or optionally hook it up as a [custom asset sour
|
|
|
14
27
|

|
|
15
28
|
_Default grid view_
|
|
16
29
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
 | 
|
|
21
|
-
|
|
30
|
+
| _Asset details tab_ | _Asset alt texts tab_ |
|
|
31
|
+
| :---------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |
|
|
32
|
+
|  |  |
|
|
22
33
|
|
|
23
34
|
## Features
|
|
24
35
|
|
|
@@ -52,18 +63,18 @@ _Asset details tab_ | _Asset alt texts tab_
|
|
|
52
63
|
- Define a list of available languages to enable multi-language alt texts for assets.
|
|
53
64
|
- See example of how to enable this feature [here](###plugin-config).
|
|
54
65
|
|
|
55
|
-
## Install (Sanity Studio
|
|
66
|
+
## Install (Sanity Studio v5 and v6)
|
|
56
67
|
|
|
57
68
|
In your Sanity project folder:
|
|
58
69
|
|
|
59
70
|
```zsh
|
|
60
|
-
npm install --save sanity-plugin-media
|
|
71
|
+
npm install --save @electrolux-oss/sanity-plugin-media
|
|
61
72
|
```
|
|
62
73
|
|
|
63
74
|
or
|
|
64
75
|
|
|
65
76
|
```zsh
|
|
66
|
-
yarn add sanity-plugin-media
|
|
77
|
+
yarn add @electrolux-oss/sanity-plugin-media
|
|
67
78
|
```
|
|
68
79
|
|
|
69
80
|
## Usage
|
|
@@ -71,19 +82,19 @@ yarn add sanity-plugin-media
|
|
|
71
82
|
Add it as a plugin in your `sanity.config.ts` (or .js) file:
|
|
72
83
|
|
|
73
84
|
```js
|
|
74
|
-
import { media } from 'sanity-plugin-media'
|
|
85
|
+
import { media } from '@electrolux-oss/sanity-plugin-media'
|
|
75
86
|
|
|
76
87
|
export default defineConfig({
|
|
77
88
|
// ...
|
|
78
89
|
plugins: [
|
|
79
|
-
media(
|
|
90
|
+
media({
|
|
80
91
|
languages: [
|
|
81
92
|
{ code: 'en-US', title: 'English', default: true },
|
|
82
93
|
{ code: 'sv-SE', title: 'Swedish' },
|
|
83
94
|
{ code: 'fr-FR', title: 'French' },
|
|
84
95
|
{ code: 'de-DE', title: 'German' }
|
|
85
|
-
]
|
|
86
|
-
)
|
|
96
|
+
]
|
|
97
|
+
})
|
|
87
98
|
]
|
|
88
99
|
})
|
|
89
100
|
```
|
|
@@ -95,7 +106,7 @@ This will enable the Media plugin as both a standalone tool (accessible in your
|
|
|
95
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).
|
|
96
107
|
|
|
97
108
|
```js
|
|
98
|
-
import { media, mediaAssetSource } from 'sanity-plugin-media'
|
|
109
|
+
import { media, mediaAssetSource } from '@electrolux-oss/sanity-plugin-media'
|
|
99
110
|
|
|
100
111
|
export default defineConfig({
|
|
101
112
|
// ...
|
|
@@ -120,7 +131,7 @@ export default defineConfig({
|
|
|
120
131
|
plugins: [
|
|
121
132
|
media({
|
|
122
133
|
// { code: string; title: string, default?: boolean }[] - the list of languages used for alt texts
|
|
123
|
-
// NOTE! Set only one language to default: true.
|
|
134
|
+
// NOTE! Set only one language to default: true.
|
|
124
135
|
languages: [
|
|
125
136
|
{ code: 'en-US', title: 'English', default: true },
|
|
126
137
|
{ code: 'sv-SE', title: 'Swedish' },
|
|
@@ -131,14 +142,19 @@ export default defineConfig({
|
|
|
131
142
|
enabled: true,
|
|
132
143
|
// boolean - enables an optional "Credit Line" field in the plugin.
|
|
133
144
|
// Used to store credits e.g. photographer, licence information
|
|
134
|
-
excludeSources: ['unsplash']
|
|
145
|
+
excludeSources: ['unsplash']
|
|
135
146
|
// string | string[] - when used with 3rd party asset sources, you may
|
|
136
147
|
// wish to prevent users overwriting the creditLine based on the `source.name`
|
|
137
148
|
},
|
|
138
|
-
maximumUploadSize: 10000000
|
|
149
|
+
maximumUploadSize: 10000000,
|
|
139
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
|
+
}
|
|
140
156
|
})
|
|
141
|
-
]
|
|
157
|
+
]
|
|
142
158
|
})
|
|
143
159
|
```
|
|
144
160
|
|
|
@@ -146,27 +162,45 @@ export default defineConfig({
|
|
|
146
162
|
|
|
147
163
|
### Test your plugin locally
|
|
148
164
|
|
|
149
|
-
|
|
165
|
+
**Step 1: Set up the plugin for local development**
|
|
166
|
+
|
|
167
|
+
In the plugin directory, run:
|
|
168
|
+
|
|
150
169
|
```zsh
|
|
151
170
|
npm run link-watch
|
|
152
171
|
```
|
|
153
172
|
|
|
154
|
-
This will
|
|
173
|
+
This will:
|
|
155
174
|
|
|
156
|
-
|
|
175
|
+
- Build your plugin automatically whenever code changes
|
|
176
|
+
- Publish the package to a local yalc repository
|
|
177
|
+
|
|
178
|
+
**Step 2: Link the plugin to your studio**
|
|
179
|
+
|
|
180
|
+
In your studio project directory, run:
|
|
157
181
|
|
|
158
182
|
```zsh
|
|
159
|
-
npx yalc add @electrolux-oss/sanity-plugin-media &&
|
|
183
|
+
npx yalc add @electrolux-oss/sanity-plugin-media && npm install
|
|
160
184
|
```
|
|
161
185
|
|
|
162
|
-
|
|
186
|
+
**Step 3: Verify the setup**
|
|
163
187
|
|
|
164
|
-
|
|
165
|
-
|
|
188
|
+
Check your studio's `package.json` - you should see:
|
|
189
|
+
|
|
190
|
+
```json
|
|
191
|
+
"@electrolux-oss/sanity-plugin-media": "file:.yalc/@electrolux-oss/sanity-plugin-media"
|
|
166
192
|
```
|
|
167
193
|
|
|
168
|
-
|
|
194
|
+
Now you can use the local version of the plugin:
|
|
169
195
|
|
|
170
|
-
```
|
|
196
|
+
```typescript
|
|
171
197
|
import { media } from '@electrolux-oss/sanity-plugin-media'
|
|
172
198
|
```
|
|
199
|
+
|
|
200
|
+
### Making changes
|
|
201
|
+
|
|
202
|
+
When you modify the plugin code:
|
|
203
|
+
|
|
204
|
+
1. The `link-watch` command will automatically rebuild
|
|
205
|
+
2. In your studio, run `npx yalc update` to pull the latest changes
|
|
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
|
|
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 {}
|