sanity-plugin-media 2.3.0 → 2.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-media",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "This version of `sanity-plugin-media` is for Sanity Studio V3.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -1,17 +1,12 @@
1
1
  import {Flex} from '@sanity/ui'
2
- import React, {ComponentProps} from 'react'
2
+ import React from 'react'
3
3
  import Browser from '../Browser'
4
- import {ToolOptionsProvider} from '../../contexts/ToolOptionsContext'
5
- import {Tool as SanityTool} from 'sanity'
6
- import {MediaToolOptions} from '@types'
7
4
 
8
- const Tool = ({tool: {options}}: ComponentProps<SanityTool<MediaToolOptions>['component']>) => {
5
+ const Tool = () => {
9
6
  return (
10
- <ToolOptionsProvider options={options}>
11
- <Flex direction="column" height="fill" flex={1}>
12
- <Browser />
13
- </Flex>
14
- </ToolOptionsProvider>
7
+ <Flex direction="column" height="fill" flex={1}>
8
+ <Browser />
9
+ </Flex>
15
10
  )
16
11
  }
17
12
 
@@ -9,7 +9,7 @@ type ContextProps = {
9
9
  const ToolOptionsContext = createContext<ContextProps | null>(null)
10
10
 
11
11
  type Props = {
12
- options?: MediaToolOptions
12
+ options?: MediaToolOptions | void
13
13
  }
14
14
 
15
15
  export const ToolOptionsProvider = ({options, children}: PropsWithChildren<Props>) => {
@@ -30,5 +30,3 @@ export const useToolOptions = () => {
30
30
 
31
31
  return context
32
32
  }
33
-
34
- export default ToolOptionsContext
package/src/index.ts CHANGED
@@ -1,47 +1,2 @@
1
- import {definePlugin} from 'sanity'
2
- import {ImageIcon} from '@sanity/icons'
3
- import type {AssetSource} from 'sanity'
4
- import FormBuilderTool from './components/FormBuilderTool'
5
- import Tool from './components/Tool'
6
- import mediaTag from './schemas/tag'
7
- import {MediaToolOptions} from '@types'
8
-
9
- const plugin = {
10
- icon: ImageIcon,
11
- name: 'media',
12
- title: 'Media'
13
- }
14
-
15
- export const mediaAssetSource: AssetSource = {
16
- ...plugin,
17
- component: FormBuilderTool
18
- }
19
-
20
- export const media = definePlugin<MediaToolOptions | void>(options => ({
21
- name: 'media',
22
- form: {
23
- file: {
24
- assetSources: prev => {
25
- return [...prev, mediaAssetSource]
26
- }
27
- },
28
- image: {
29
- assetSources: prev => {
30
- return [...prev, mediaAssetSource]
31
- }
32
- }
33
- },
34
- schema: {
35
- types: [mediaTag]
36
- },
37
- tools: prev => {
38
- return [
39
- ...prev,
40
- {
41
- ...plugin,
42
- options,
43
- component: Tool
44
- }
45
- ]
46
- }
47
- }))
1
+ export {media, mediaAssetSource} from './plugin'
2
+ export type {MediaToolOptions} from '@types'
package/src/plugin.tsx ADDED
@@ -0,0 +1,53 @@
1
+ import React from 'react'
2
+ import {AssetSource, Tool as SanityTool, definePlugin} from 'sanity'
3
+ import {ImageIcon} from '@sanity/icons'
4
+ import FormBuilderTool from './components/FormBuilderTool'
5
+ import Tool from './components/Tool'
6
+ import mediaTag from './schemas/tag'
7
+ import {MediaToolOptions} from '@types'
8
+ import {ToolOptionsProvider} from './contexts/ToolOptionsContext'
9
+
10
+ const plugin = {
11
+ icon: ImageIcon,
12
+ name: 'media',
13
+ title: 'Media'
14
+ }
15
+
16
+ export const mediaAssetSource = {
17
+ ...plugin,
18
+ component: FormBuilderTool
19
+ } satisfies AssetSource
20
+
21
+ const tool = {
22
+ ...plugin,
23
+ component: Tool
24
+ } satisfies SanityTool
25
+
26
+ export const media = definePlugin<MediaToolOptions | void>(options => ({
27
+ name: 'media',
28
+ studio: {
29
+ components: {
30
+ layout: props => (
31
+ <ToolOptionsProvider options={options}>{props.renderDefault(props)}</ToolOptionsProvider>
32
+ )
33
+ }
34
+ },
35
+ form: {
36
+ file: {
37
+ assetSources: prev => {
38
+ return [...prev, mediaAssetSource]
39
+ }
40
+ },
41
+ image: {
42
+ assetSources: prev => {
43
+ return [...prev, mediaAssetSource]
44
+ }
45
+ }
46
+ },
47
+ schema: {
48
+ types: [mediaTag]
49
+ },
50
+ tools: prev => {
51
+ return [...prev, tool]
52
+ }
53
+ }))