sanity-plugin-markdown 6.0.0 → 7.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 +0 -17
- package/dist/_chunks-dts/commonExports.d.ts +162 -0
- package/dist/_chunks-dts/commonExports.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/{lib/index.mjs → dist/index.js} +2 -2
- package/{lib → dist}/index.js.map +1 -1
- package/dist/indexNext.d.ts +2 -0
- package/dist/indexNext.js +180 -0
- package/dist/indexNext.js.map +1 -0
- package/package.json +30 -73
- package/lib/_chunks-cjs/plugin.js +0 -176
- package/lib/_chunks-cjs/plugin.js.map +0 -1
- package/lib/_chunks-es/plugin.mjs +0 -162
- package/lib/_chunks-es/plugin.mjs.map +0 -1
- package/lib/_legacy/plugin.esm.js +0 -162
- package/lib/_legacy/plugin.esm.js.map +0 -1
- package/lib/index.d.mts +0 -107
- package/lib/index.d.ts +0 -107
- package/lib/index.esm.js +0 -9
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js +0 -9
- package/lib/index.mjs.map +0 -1
- package/lib/indexNext.d.mts +0 -107
- package/lib/indexNext.d.ts +0 -107
- package/lib/indexNext.esm.js +0 -8
- package/lib/indexNext.esm.js.map +0 -1
- package/lib/indexNext.js +0 -8
- package/lib/indexNext.js.map +0 -1
- package/lib/indexNext.mjs +0 -8
- package/lib/indexNext.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/commonExports.ts +0 -4
- package/src/components/MarkdownInput.tsx +0 -142
- package/src/components/MarkdownInputStyles.tsx +0 -61
- package/src/components/sanity-ui.d.ts +0 -6
- package/src/index.ts +0 -3
- package/src/indexNext.ts +0 -1
- package/src/plugin.tsx +0 -54
- package/src/schema.ts +0 -48
- package/v2-incompatible.js +0 -11
package/lib/indexNext.d.mts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {JSX as JSX_2} from 'react'
|
|
2
|
-
import {Options} from 'easymde'
|
|
3
|
-
import {Plugin as Plugin_2} from 'sanity'
|
|
4
|
-
import {ReactElement} from 'react'
|
|
5
|
-
import {SanityImageAssetDocument} from '@sanity/client'
|
|
6
|
-
import type {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
7
|
-
import {StringDefinition} from 'sanity'
|
|
8
|
-
import {StringInputProps} from 'sanity'
|
|
9
|
-
|
|
10
|
-
export declare const defaultMdeTools: Options['toolbar']
|
|
11
|
-
|
|
12
|
-
export declare interface MarkdownConfig {
|
|
13
|
-
/**
|
|
14
|
-
* When provided, will replace the default input component.
|
|
15
|
-
*
|
|
16
|
-
* Use this to customize MarkdownInput by wrapping it in a custom component,
|
|
17
|
-
* and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
18
|
-
* via the `reactMdeProps` prop.
|
|
19
|
-
*
|
|
20
|
-
* ### Example
|
|
21
|
-
*
|
|
22
|
-
* ```tsx
|
|
23
|
-
* // CustomMarkdownInput.tsx
|
|
24
|
-
* import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'
|
|
25
|
-
*
|
|
26
|
-
* export function CustomMarkdownInput(props) {
|
|
27
|
-
* const reactMdeProps: MarkdownInputProps['reactMdeProps'] =
|
|
28
|
-
* useMemo(() => {
|
|
29
|
-
* return {
|
|
30
|
-
* options: {
|
|
31
|
-
* toolbar: ['bold', 'italic'],
|
|
32
|
-
* // more options available, see:
|
|
33
|
-
* // https://github.com/Ionaru/easy-markdown-editor#options-list
|
|
34
|
-
* },
|
|
35
|
-
* // more props available, see:
|
|
36
|
-
* // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
37
|
-
* }
|
|
38
|
-
* }, [])
|
|
39
|
-
*
|
|
40
|
-
* return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* // studio.config.ts
|
|
44
|
-
* markdownSchema({input: CustomMarkdownInput})
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
input?: (props: StringInputProps) => ReactElement
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
export declare interface MarkdownDefinition
|
|
54
|
-
extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
55
|
-
type: typeof markdownTypeName
|
|
56
|
-
options?: MarkdownOptions
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export declare function MarkdownInput(props: MarkdownInputProps): JSX_2.Element
|
|
60
|
-
|
|
61
|
-
export declare interface MarkdownInputProps extends StringInputProps {
|
|
62
|
-
/**
|
|
63
|
-
* These are passed along directly to
|
|
64
|
-
*
|
|
65
|
-
* Note: MarkdownInput sets certain reactMdeProps.options by default.
|
|
66
|
-
* These will be merged with any custom options.
|
|
67
|
-
*/
|
|
68
|
-
reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
declare interface MarkdownOptions {
|
|
72
|
-
/**
|
|
73
|
-
* Used to create image url for any uploaded image.
|
|
74
|
-
* The function will be invoked whenever an image is pasted or dragged into the
|
|
75
|
-
* markdown editor, after upload completes.
|
|
76
|
-
*
|
|
77
|
-
* The default implementation uses
|
|
78
|
-
* ```js
|
|
79
|
-
* imageAsset => `${imageAsset.url}?w=450`
|
|
80
|
-
* ```
|
|
81
|
-
* ## Example
|
|
82
|
-
* ```js
|
|
83
|
-
* {
|
|
84
|
-
* imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`
|
|
85
|
-
* }
|
|
86
|
-
* ```
|
|
87
|
-
* @param imageAsset
|
|
88
|
-
*/
|
|
89
|
-
imageUrl?: (imageAsset: SanityImageAssetDocument) => string
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export declare const markdownSchema: Plugin_2<void | MarkdownConfig>
|
|
93
|
-
|
|
94
|
-
export declare const markdownSchemaType: {
|
|
95
|
-
type: 'string'
|
|
96
|
-
name: 'markdown'
|
|
97
|
-
} & Omit<StringDefinition, 'preview'>
|
|
98
|
-
|
|
99
|
-
declare const markdownTypeName: 'markdown'
|
|
100
|
-
|
|
101
|
-
export {}
|
|
102
|
-
|
|
103
|
-
declare module '@sanity/types' {
|
|
104
|
-
interface IntrinsicDefinitions {
|
|
105
|
-
markdown: MarkdownDefinition
|
|
106
|
-
}
|
|
107
|
-
}
|
package/lib/indexNext.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {JSX as JSX_2} from 'react'
|
|
2
|
-
import {Options} from 'easymde'
|
|
3
|
-
import {Plugin as Plugin_2} from 'sanity'
|
|
4
|
-
import {ReactElement} from 'react'
|
|
5
|
-
import {SanityImageAssetDocument} from '@sanity/client'
|
|
6
|
-
import type {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
7
|
-
import {StringDefinition} from 'sanity'
|
|
8
|
-
import {StringInputProps} from 'sanity'
|
|
9
|
-
|
|
10
|
-
export declare const defaultMdeTools: Options['toolbar']
|
|
11
|
-
|
|
12
|
-
export declare interface MarkdownConfig {
|
|
13
|
-
/**
|
|
14
|
-
* When provided, will replace the default input component.
|
|
15
|
-
*
|
|
16
|
-
* Use this to customize MarkdownInput by wrapping it in a custom component,
|
|
17
|
-
* and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
18
|
-
* via the `reactMdeProps` prop.
|
|
19
|
-
*
|
|
20
|
-
* ### Example
|
|
21
|
-
*
|
|
22
|
-
* ```tsx
|
|
23
|
-
* // CustomMarkdownInput.tsx
|
|
24
|
-
* import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'
|
|
25
|
-
*
|
|
26
|
-
* export function CustomMarkdownInput(props) {
|
|
27
|
-
* const reactMdeProps: MarkdownInputProps['reactMdeProps'] =
|
|
28
|
-
* useMemo(() => {
|
|
29
|
-
* return {
|
|
30
|
-
* options: {
|
|
31
|
-
* toolbar: ['bold', 'italic'],
|
|
32
|
-
* // more options available, see:
|
|
33
|
-
* // https://github.com/Ionaru/easy-markdown-editor#options-list
|
|
34
|
-
* },
|
|
35
|
-
* // more props available, see:
|
|
36
|
-
* // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
37
|
-
* }
|
|
38
|
-
* }, [])
|
|
39
|
-
*
|
|
40
|
-
* return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* // studio.config.ts
|
|
44
|
-
* markdownSchema({input: CustomMarkdownInput})
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
input?: (props: StringInputProps) => ReactElement
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
export declare interface MarkdownDefinition
|
|
54
|
-
extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
55
|
-
type: typeof markdownTypeName
|
|
56
|
-
options?: MarkdownOptions
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export declare function MarkdownInput(props: MarkdownInputProps): JSX_2.Element
|
|
60
|
-
|
|
61
|
-
export declare interface MarkdownInputProps extends StringInputProps {
|
|
62
|
-
/**
|
|
63
|
-
* These are passed along directly to
|
|
64
|
-
*
|
|
65
|
-
* Note: MarkdownInput sets certain reactMdeProps.options by default.
|
|
66
|
-
* These will be merged with any custom options.
|
|
67
|
-
*/
|
|
68
|
-
reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
declare interface MarkdownOptions {
|
|
72
|
-
/**
|
|
73
|
-
* Used to create image url for any uploaded image.
|
|
74
|
-
* The function will be invoked whenever an image is pasted or dragged into the
|
|
75
|
-
* markdown editor, after upload completes.
|
|
76
|
-
*
|
|
77
|
-
* The default implementation uses
|
|
78
|
-
* ```js
|
|
79
|
-
* imageAsset => `${imageAsset.url}?w=450`
|
|
80
|
-
* ```
|
|
81
|
-
* ## Example
|
|
82
|
-
* ```js
|
|
83
|
-
* {
|
|
84
|
-
* imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`
|
|
85
|
-
* }
|
|
86
|
-
* ```
|
|
87
|
-
* @param imageAsset
|
|
88
|
-
*/
|
|
89
|
-
imageUrl?: (imageAsset: SanityImageAssetDocument) => string
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export declare const markdownSchema: Plugin_2<void | MarkdownConfig>
|
|
93
|
-
|
|
94
|
-
export declare const markdownSchemaType: {
|
|
95
|
-
type: 'string'
|
|
96
|
-
name: 'markdown'
|
|
97
|
-
} & Omit<StringDefinition, 'preview'>
|
|
98
|
-
|
|
99
|
-
declare const markdownTypeName: 'markdown'
|
|
100
|
-
|
|
101
|
-
export {}
|
|
102
|
-
|
|
103
|
-
declare module '@sanity/types' {
|
|
104
|
-
interface IntrinsicDefinitions {
|
|
105
|
-
markdown: MarkdownDefinition
|
|
106
|
-
}
|
|
107
|
-
}
|
package/lib/indexNext.esm.js
DELETED
package/lib/indexNext.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"indexNext.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/lib/indexNext.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var plugin = require("./_chunks-cjs/plugin.js");
|
|
4
|
-
exports.MarkdownInput = plugin.MarkdownInput;
|
|
5
|
-
exports.defaultMdeTools = plugin.defaultMdeTools;
|
|
6
|
-
exports.markdownSchema = plugin.markdownSchema;
|
|
7
|
-
exports.markdownSchemaType = plugin.markdownSchemaType;
|
|
8
|
-
//# sourceMappingURL=indexNext.js.map
|
package/lib/indexNext.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"indexNext.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/lib/indexNext.mjs
DELETED
package/lib/indexNext.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"indexNext.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/sanity.json
DELETED
package/src/commonExports.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {type Options as EasyMdeOptions} from 'easymde'
|
|
2
|
-
import {
|
|
3
|
-
lazy,
|
|
4
|
-
Suspense,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
useMemo,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
} from 'react'
|
|
12
|
-
// dont import non-types here, it will break SSR on next
|
|
13
|
-
import type {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
14
|
-
import {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'
|
|
15
|
-
import {MarkdownOptions} from '../schema'
|
|
16
|
-
import {MarkdownInputStyles} from './MarkdownInputStyles'
|
|
17
|
-
import {Box, Text} from '@sanity/ui'
|
|
18
|
-
|
|
19
|
-
const SimpleMdeReact = lazy(() => import('react-simplemde-editor'))
|
|
20
|
-
|
|
21
|
-
export interface MarkdownInputProps extends StringInputProps {
|
|
22
|
-
/**
|
|
23
|
-
* These are passed along directly to
|
|
24
|
-
*
|
|
25
|
-
* Note: MarkdownInput sets certain reactMdeProps.options by default.
|
|
26
|
-
* These will be merged with any custom options.
|
|
27
|
-
*/
|
|
28
|
-
reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const defaultMdeTools: EasyMdeOptions['toolbar'] = [
|
|
32
|
-
'heading',
|
|
33
|
-
'bold',
|
|
34
|
-
'italic',
|
|
35
|
-
'|',
|
|
36
|
-
'quote',
|
|
37
|
-
'unordered-list',
|
|
38
|
-
'ordered-list',
|
|
39
|
-
'|',
|
|
40
|
-
'link',
|
|
41
|
-
'image',
|
|
42
|
-
'code',
|
|
43
|
-
'|',
|
|
44
|
-
'preview',
|
|
45
|
-
'side-by-side',
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
export function MarkdownInput(props: MarkdownInputProps) {
|
|
49
|
-
const {
|
|
50
|
-
value = '',
|
|
51
|
-
onChange,
|
|
52
|
-
elementProps: {onBlur, onFocus, ref: elementRef},
|
|
53
|
-
reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},
|
|
54
|
-
schemaType,
|
|
55
|
-
focused,
|
|
56
|
-
} = props
|
|
57
|
-
const client = useClient({apiVersion: '2022-01-01'})
|
|
58
|
-
const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}
|
|
59
|
-
const [shouldAutoFocus, setShouldAutoFocus] = useState(false)
|
|
60
|
-
const ref = useRef<HTMLDivElement>(null)
|
|
61
|
-
|
|
62
|
-
// Forward ref to parent form state
|
|
63
|
-
useImperativeHandle(elementRef, () => ref.current)
|
|
64
|
-
|
|
65
|
-
const imageUpload = useCallback(
|
|
66
|
-
(file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {
|
|
67
|
-
client.assets
|
|
68
|
-
.upload('image', file)
|
|
69
|
-
.then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))
|
|
70
|
-
.catch((e) => {
|
|
71
|
-
console.error(e)
|
|
72
|
-
onError(e.message)
|
|
73
|
-
})
|
|
74
|
-
},
|
|
75
|
-
[client, imageUrl],
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
const mdeOptions: EasyMdeOptions = useMemo(() => {
|
|
79
|
-
return {
|
|
80
|
-
spellChecker: false,
|
|
81
|
-
sideBySideFullscreen: false,
|
|
82
|
-
uploadImage: true,
|
|
83
|
-
imageUploadFunction: imageUpload,
|
|
84
|
-
toolbar: defaultMdeTools,
|
|
85
|
-
status: false,
|
|
86
|
-
...mdeCustomOptions,
|
|
87
|
-
autofocus: shouldAutoFocus,
|
|
88
|
-
}
|
|
89
|
-
}, [imageUpload, mdeCustomOptions, shouldAutoFocus])
|
|
90
|
-
|
|
91
|
-
// eslint-disable-next-line consistent-return
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
const node = ref.current
|
|
94
|
-
if (!node) return undefined
|
|
95
|
-
|
|
96
|
-
if (focused && !shouldAutoFocus) {
|
|
97
|
-
// Do not set autofocus if the field already has focus
|
|
98
|
-
const raf = requestAnimationFrame(() =>
|
|
99
|
-
setShouldAutoFocus(!node.contains(document.activeElement)),
|
|
100
|
-
)
|
|
101
|
-
return () => cancelAnimationFrame(raf)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!focused && shouldAutoFocus) {
|
|
105
|
-
// If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state
|
|
106
|
-
const raf = requestAnimationFrame(() =>
|
|
107
|
-
setShouldAutoFocus(node.contains(document.activeElement)),
|
|
108
|
-
)
|
|
109
|
-
return () => cancelAnimationFrame(raf)
|
|
110
|
-
}
|
|
111
|
-
}, [focused, shouldAutoFocus])
|
|
112
|
-
|
|
113
|
-
const handleChange = useCallback(
|
|
114
|
-
(newValue: string) => {
|
|
115
|
-
onChange(PatchEvent.from(newValue ? set(newValue) : unset()))
|
|
116
|
-
},
|
|
117
|
-
[onChange],
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<MarkdownInputStyles>
|
|
122
|
-
<Suspense fallback={fallback}>
|
|
123
|
-
<SimpleMdeReact
|
|
124
|
-
{...reactMdeProps}
|
|
125
|
-
ref={ref}
|
|
126
|
-
value={value}
|
|
127
|
-
onChange={handleChange}
|
|
128
|
-
onBlur={onBlur}
|
|
129
|
-
onFocus={onFocus}
|
|
130
|
-
options={mdeOptions}
|
|
131
|
-
spellCheck={false}
|
|
132
|
-
/>
|
|
133
|
-
</Suspense>
|
|
134
|
-
</MarkdownInputStyles>
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const fallback = (
|
|
139
|
-
<Box padding={3}>
|
|
140
|
-
<Text>Loading editor...</Text>
|
|
141
|
-
</Box>
|
|
142
|
-
)
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import {Box} from '@sanity/ui'
|
|
2
|
-
import {styled} from 'styled-components'
|
|
3
|
-
|
|
4
|
-
export const MarkdownInputStyles = styled(Box)`
|
|
5
|
-
& .CodeMirror.CodeMirror {
|
|
6
|
-
color: ${({theme}) => theme.sanity.color.card.enabled.fg};
|
|
7
|
-
border-color: ${({theme}) => theme.sanity.color.card.enabled.border};
|
|
8
|
-
background-color: inherit;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
& .cm-s-easymde .CodeMirror-cursor {
|
|
12
|
-
border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
& .editor-toolbar,
|
|
16
|
-
.editor-preview-side {
|
|
17
|
-
border-color: ${({theme}) => theme.sanity.color.card.enabled.border};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
& .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
21
|
-
background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
& .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
25
|
-
background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
& .editor-toolbar > * {
|
|
29
|
-
color: ${({theme}) => theme.sanity.color.card.enabled.fg};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
& .editor-toolbar > .active,
|
|
33
|
-
.editor-toolbar > button:hover,
|
|
34
|
-
.editor-preview pre,
|
|
35
|
-
.cm-s-easymde .cm-comment {
|
|
36
|
-
background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
& .editor-preview {
|
|
40
|
-
background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
|
|
41
|
-
|
|
42
|
-
& h1,
|
|
43
|
-
h2,
|
|
44
|
-
h3,
|
|
45
|
-
h4,
|
|
46
|
-
h5,
|
|
47
|
-
h6 {
|
|
48
|
-
font-size: revert;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
& ul,
|
|
52
|
-
li {
|
|
53
|
-
list-style: revert;
|
|
54
|
-
padding: revert;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
& a {
|
|
58
|
-
text-decoration: revert;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
`
|
package/src/index.ts
DELETED
package/src/indexNext.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './commonExports'
|
package/src/plugin.tsx
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {definePlugin, StringInputProps} from 'sanity'
|
|
2
|
-
import {markdownSchemaType} from './schema'
|
|
3
|
-
import {ReactElement} from 'react'
|
|
4
|
-
|
|
5
|
-
export interface MarkdownConfig {
|
|
6
|
-
/**
|
|
7
|
-
* When provided, will replace the default input component.
|
|
8
|
-
*
|
|
9
|
-
* Use this to customize MarkdownInput by wrapping it in a custom component,
|
|
10
|
-
* and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
11
|
-
* via the `reactMdeProps` prop.
|
|
12
|
-
*
|
|
13
|
-
* ### Example
|
|
14
|
-
*
|
|
15
|
-
* ```tsx
|
|
16
|
-
* // CustomMarkdownInput.tsx
|
|
17
|
-
* import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'
|
|
18
|
-
*
|
|
19
|
-
* export function CustomMarkdownInput(props) {
|
|
20
|
-
* const reactMdeProps: MarkdownInputProps['reactMdeProps'] =
|
|
21
|
-
* useMemo(() => {
|
|
22
|
-
* return {
|
|
23
|
-
* options: {
|
|
24
|
-
* toolbar: ['bold', 'italic'],
|
|
25
|
-
* // more options available, see:
|
|
26
|
-
* // https://github.com/Ionaru/easy-markdown-editor#options-list
|
|
27
|
-
* },
|
|
28
|
-
* // more props available, see:
|
|
29
|
-
* // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
30
|
-
* }
|
|
31
|
-
* }, [])
|
|
32
|
-
*
|
|
33
|
-
* return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* // studio.config.ts
|
|
37
|
-
* markdownSchema({input: CustomMarkdownInput})
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
input?: (props: StringInputProps) => ReactElement
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const markdownSchema = definePlugin((config: MarkdownConfig | void) => {
|
|
44
|
-
return {
|
|
45
|
-
name: 'markdown-editor',
|
|
46
|
-
schema: {
|
|
47
|
-
types: [
|
|
48
|
-
config && config.input
|
|
49
|
-
? {...markdownSchemaType, components: {input: config.input}}
|
|
50
|
-
: markdownSchemaType,
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
}
|
|
54
|
-
})
|
package/src/schema.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {defineType, StringDefinition} from 'sanity'
|
|
2
|
-
import {MarkdownInput} from './components/MarkdownInput'
|
|
3
|
-
import {SanityImageAssetDocument} from '@sanity/client'
|
|
4
|
-
|
|
5
|
-
export const markdownTypeName = 'markdown' as const
|
|
6
|
-
|
|
7
|
-
export interface MarkdownOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Used to create image url for any uploaded image.
|
|
10
|
-
* The function will be invoked whenever an image is pasted or dragged into the
|
|
11
|
-
* markdown editor, after upload completes.
|
|
12
|
-
*
|
|
13
|
-
* The default implementation uses
|
|
14
|
-
* ```js
|
|
15
|
-
* imageAsset => `${imageAsset.url}?w=450`
|
|
16
|
-
* ```
|
|
17
|
-
* ## Example
|
|
18
|
-
* ```js
|
|
19
|
-
* {
|
|
20
|
-
* imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
* @param imageAsset
|
|
24
|
-
*/
|
|
25
|
-
imageUrl?: (imageAsset: SanityImageAssetDocument) => string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
32
|
-
type: typeof markdownTypeName
|
|
33
|
-
options?: MarkdownOptions
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
declare module '@sanity/types' {
|
|
37
|
-
// makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember
|
|
38
|
-
export interface IntrinsicDefinitions {
|
|
39
|
-
markdown: MarkdownDefinition
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const markdownSchemaType = defineType({
|
|
44
|
-
type: 'string',
|
|
45
|
-
name: markdownTypeName,
|
|
46
|
-
title: 'Markdown',
|
|
47
|
-
components: {input: MarkdownInput},
|
|
48
|
-
})
|
package/v2-incompatible.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
|
|
2
|
-
const {name, version, sanityExchangeUrl} = require('./package.json')
|
|
3
|
-
|
|
4
|
-
export default showIncompatiblePluginDialog({
|
|
5
|
-
name: name,
|
|
6
|
-
versions: {
|
|
7
|
-
v3: version,
|
|
8
|
-
v2: '^0.2.1',
|
|
9
|
-
},
|
|
10
|
-
sanityExchangeUrl,
|
|
11
|
-
})
|