@sanity/cross-dataset-duplicator 1.0.0 → 1.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/LICENSE +1 -1
- package/README.md +4 -6
- package/lib/index.esm.js +1 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/src/index.d.ts +529 -1
- package/package.json +1 -1
- package/src/actions/DuplicateToAction.tsx +10 -24
- package/src/components/CrossDatasetDuplicator.tsx +6 -17
- package/src/components/CrossDatasetDuplicatorAction.tsx +14 -0
- package/src/components/CrossDatasetDuplicatorTool.tsx +18 -0
- package/src/context/ConfigProvider.tsx +30 -0
- package/src/helpers/constants.ts +9 -0
- package/src/index.ts +4 -35
- package/src/plugin.tsx +31 -0
- package/src/tool/index.ts +3 -6
- package/src/types/index.ts +10 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, {useContext} from 'react'
|
|
2
|
+
import {createContext} from 'react'
|
|
3
|
+
import {LayoutProps} from 'sanity'
|
|
4
|
+
|
|
5
|
+
import {DEFAULT_CONFIG} from '../helpers/constants'
|
|
6
|
+
import {PluginConfig} from '../types'
|
|
7
|
+
|
|
8
|
+
const CrossDatasetDuplicatorContext = createContext(DEFAULT_CONFIG)
|
|
9
|
+
|
|
10
|
+
type ConfigProviderProps = LayoutProps & {pluginConfig: PluginConfig}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Plugin config context hook from the Cross Dataset Duplicator plugin
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export function useCrossDatasetDuplicatorConfig() {
|
|
17
|
+
const pluginConfig = useContext(CrossDatasetDuplicatorContext)
|
|
18
|
+
|
|
19
|
+
return pluginConfig
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ConfigProvider(props: ConfigProviderProps) {
|
|
23
|
+
const {pluginConfig, ...rest} = props
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<CrossDatasetDuplicatorContext.Provider value={pluginConfig}>
|
|
27
|
+
{props.renderDefault(rest)}
|
|
28
|
+
</CrossDatasetDuplicatorContext.Provider>
|
|
29
|
+
)
|
|
30
|
+
}
|
package/src/helpers/constants.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
import {definePlugin, DocumentActionProps} from 'sanity'
|
|
2
|
-
|
|
3
|
-
import DuplicateToAction from './actions/DuplicateToAction'
|
|
4
|
-
import {crossDatasetDuplicatorTool} from './tool'
|
|
5
|
-
import {PluginConfig} from './types'
|
|
6
|
-
|
|
7
1
|
export * from './types'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
filter: '',
|
|
13
|
-
follow: ['outbound'],
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @sanity/cross-dataset-duplicator
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export const crossDatasetDuplicator = definePlugin<PluginConfig | void>((config = {}) => {
|
|
21
|
-
const pluginConfig = {...DEFAULT_CONFIG, ...config}
|
|
22
|
-
const {types} = pluginConfig
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
name: '@sanity/cross-dataset-duplicator',
|
|
26
|
-
tools: (prev) =>
|
|
27
|
-
pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool(pluginConfig)] : prev,
|
|
28
|
-
document: {
|
|
29
|
-
actions: (prev, {schemaType}) => {
|
|
30
|
-
return types && types.includes(schemaType)
|
|
31
|
-
? [...prev, (props: DocumentActionProps) => DuplicateToAction({...props, pluginConfig})]
|
|
32
|
-
: prev
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
})
|
|
2
|
+
export * from './plugin'
|
|
3
|
+
export * from './actions/DuplicateToAction'
|
|
4
|
+
export {useCrossDatasetDuplicatorConfig} from './context/ConfigProvider'
|
|
5
|
+
export {CrossDatasetDuplicatorAction} from './components/CrossDatasetDuplicatorAction'
|
package/src/plugin.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {definePlugin} from 'sanity'
|
|
2
|
+
|
|
3
|
+
import {DuplicateToAction} from './actions/DuplicateToAction'
|
|
4
|
+
import {ConfigProvider} from './context/ConfigProvider'
|
|
5
|
+
import {DEFAULT_CONFIG} from './helpers/constants'
|
|
6
|
+
import {crossDatasetDuplicatorTool} from './tool'
|
|
7
|
+
import {PluginConfig} from './types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Plugin: Cross Dataset Duplicator
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export const crossDatasetDuplicator = definePlugin<PluginConfig | void>((config = {}) => {
|
|
14
|
+
const pluginConfig = {...DEFAULT_CONFIG, ...config}
|
|
15
|
+
const {types} = pluginConfig
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
name: '@sanity/cross-dataset-duplicator',
|
|
19
|
+
tools: (prev) => (pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool()] : prev),
|
|
20
|
+
studio: {
|
|
21
|
+
components: {
|
|
22
|
+
layout: (props) => ConfigProvider({...props, pluginConfig}),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
document: {
|
|
26
|
+
actions: (prev, {schemaType}) => {
|
|
27
|
+
return types && types.includes(schemaType) ? [...prev, DuplicateToAction] : prev
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
})
|
package/src/tool/index.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type {Tool} from 'sanity'
|
|
2
2
|
import {LaunchIcon} from '@sanity/icons'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import {PluginConfig} from '../types'
|
|
4
|
+
import {CrossDatasetDuplicatorTool, MultiToolConfig} from '../components/CrossDatasetDuplicatorTool'
|
|
6
5
|
|
|
7
|
-
export const crossDatasetDuplicatorTool = (
|
|
6
|
+
export const crossDatasetDuplicatorTool = (): Tool<MultiToolConfig> => ({
|
|
8
7
|
title: 'Duplicator',
|
|
9
8
|
name: 'duplicator',
|
|
10
9
|
icon: LaunchIcon,
|
|
11
|
-
component:
|
|
10
|
+
component: CrossDatasetDuplicatorTool,
|
|
12
11
|
options: {
|
|
13
|
-
mode: 'tool',
|
|
14
12
|
docs: [],
|
|
15
|
-
pluginConfig,
|
|
16
13
|
},
|
|
17
14
|
})
|
package/src/types/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {SanityDocument} from 'sanity'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Plugin configuration
|
|
3
5
|
* @public
|
|
@@ -8,3 +10,11 @@ export interface PluginConfig {
|
|
|
8
10
|
filter?: string
|
|
9
11
|
follow?: ('inbound' | 'outbound')[]
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cross Dataset Duplicator document action props
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type CrossDatasetDuplicatorActionProps = {
|
|
19
|
+
docs: SanityDocument[]
|
|
20
|
+
}
|