sanity-plugin-markdown 3.0.1 → 4.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 +138 -15
- package/lib/_chunks/plugin-b7a179e6.js +162 -0
- package/lib/_chunks/plugin-b7a179e6.js.map +1 -0
- package/lib/_chunks/plugin-ca10aa4c.js +151 -0
- package/lib/_chunks/plugin-ca10aa4c.js.map +1 -0
- package/lib/index.d.ts +108 -0
- package/lib/index.esm.js +2 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +11 -1
- package/lib/index.js.map +1 -1
- package/lib/indexNext.esm.js +2 -0
- package/lib/indexNext.esm.js.map +1 -0
- package/lib/indexNext.js +11 -0
- package/lib/indexNext.js.map +1 -0
- package/package.json +45 -26
- package/src/commonExports.ts +4 -0
- package/src/components/MarkdownInput.tsx +108 -0
- package/src/components/MarkdownInputStyles.tsx +61 -0
- package/src/components/useSimpleMdeReact.tsx +12 -0
- package/src/index.ts +2 -15
- package/src/indexNext.ts +1 -0
- package/src/plugin.tsx +54 -0
- package/src/schema.ts +26 -3
- package/lib/src/index.d.ts +0 -37
- package/src/components/Editor.tsx +0 -134
- package/src/hooks/useDebounce.ts +0 -14
package/lib/index.esm.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import 'easymde/dist/easymde.min.css';
|
|
2
|
+
export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType } from './_chunks/plugin-ca10aa4c.js';
|
|
2
3
|
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
require('easymde/dist/easymde.min.css');
|
|
7
|
+
var plugin = require('./_chunks/plugin-b7a179e6.js');
|
|
8
|
+
exports.MarkdownInput = plugin.MarkdownInput;
|
|
9
|
+
exports.defaultMdeTools = plugin.defaultMdeTools;
|
|
10
|
+
exports.markdownSchema = plugin.markdownSchema;
|
|
11
|
+
exports.markdownSchemaType = plugin.markdownSchemaType;
|
|
2
12
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexNext.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/lib/indexNext.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var plugin = require('./_chunks/plugin-b7a179e6.js');
|
|
7
|
+
exports.MarkdownInput = plugin.MarkdownInput;
|
|
8
|
+
exports.defaultMdeTools = plugin.defaultMdeTools;
|
|
9
|
+
exports.markdownSchema = plugin.markdownSchema;
|
|
10
|
+
exports.markdownSchemaType = plugin.markdownSchemaType;
|
|
11
|
+
//# sourceMappingURL=indexNext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexNext.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-markdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -15,76 +15,95 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "
|
|
18
|
+
"url": "git@github.com:sanity-io/sanity-plugin-markdown.git"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"author": "Sanity.io <hello@sanity.io>",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"types": "./lib/
|
|
24
|
+
"types": "./lib/index.d.ts",
|
|
25
25
|
"source": "./src/index.ts",
|
|
26
|
-
"import": "./lib/index.esm.js",
|
|
27
26
|
"require": "./lib/index.js",
|
|
27
|
+
"import": "./lib/index.esm.js",
|
|
28
28
|
"default": "./lib/index.esm.js"
|
|
29
29
|
},
|
|
30
|
+
"./next": {
|
|
31
|
+
"types": "./lib/index.d.ts",
|
|
32
|
+
"source": "./src/indexNext.ts",
|
|
33
|
+
"require": "./lib/indexNext.js",
|
|
34
|
+
"import": "./lib/indexNext.esm.js",
|
|
35
|
+
"default": "./lib/indexNext.esm.js"
|
|
36
|
+
},
|
|
30
37
|
"./package.json": "./package.json"
|
|
31
38
|
},
|
|
32
39
|
"main": "./lib/index.js",
|
|
33
40
|
"module": "./lib/index.esm.js",
|
|
34
41
|
"source": "./src/index.ts",
|
|
35
|
-
"types": "./lib/
|
|
42
|
+
"types": "./lib/index.d.ts",
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
"next": [
|
|
46
|
+
"./lib/index.d.ts"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
36
50
|
"files": [
|
|
37
|
-
"src",
|
|
38
51
|
"lib",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
52
|
+
"sanity.json",
|
|
53
|
+
"src",
|
|
54
|
+
"v2-incompatible.js"
|
|
41
55
|
],
|
|
42
56
|
"scripts": {
|
|
43
57
|
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
|
|
44
|
-
"build": "pkg-utils build --strict",
|
|
58
|
+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
|
|
45
59
|
"clean": "rimraf lib",
|
|
46
60
|
"compile": "tsc --noEmit",
|
|
47
|
-
"format": "prettier
|
|
61
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
48
62
|
"link-watch": "plugin-kit link-watch",
|
|
49
63
|
"lint": "eslint .",
|
|
50
64
|
"prepare": "husky install",
|
|
51
|
-
"prepublishOnly": "
|
|
52
|
-
"watch": "pkg-utils watch"
|
|
65
|
+
"prepublishOnly": "run-s build",
|
|
66
|
+
"watch": "pkg-utils watch --strict"
|
|
53
67
|
},
|
|
54
68
|
"dependencies": {
|
|
55
69
|
"@sanity/incompatible-plugin": "^1.0.4",
|
|
56
70
|
"@sanity/ui": "^1.0.0",
|
|
57
|
-
"
|
|
58
|
-
"rehype-sanitize": "^5.0.1"
|
|
71
|
+
"react-simplemde-editor": "^5.2.0"
|
|
59
72
|
},
|
|
60
73
|
"devDependencies": {
|
|
61
74
|
"@commitlint/cli": "^17.2.0",
|
|
62
75
|
"@commitlint/config-conventional": "^17.2.0",
|
|
63
|
-
"@sanity/pkg-utils": "^
|
|
64
|
-
"@sanity/plugin-kit": "^
|
|
76
|
+
"@sanity/pkg-utils": "^2.2.6",
|
|
77
|
+
"@sanity/plugin-kit": "^3.1.7",
|
|
65
78
|
"@sanity/semantic-release-preset": "^2.0.2",
|
|
79
|
+
"@types/react": "^18.0.26",
|
|
66
80
|
"@types/styled-components": "^5.1.26",
|
|
67
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
68
|
-
"@typescript-eslint/parser": "^5.
|
|
69
|
-
"
|
|
70
|
-
"eslint
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
82
|
+
"@typescript-eslint/parser": "^5.48.0",
|
|
83
|
+
"easymde": "^2.18.0",
|
|
84
|
+
"eslint": "^8.31.0",
|
|
85
|
+
"eslint-config-prettier": "^8.6.0",
|
|
71
86
|
"eslint-config-sanity": "^6.0.0",
|
|
72
87
|
"eslint-plugin-prettier": "^4.2.1",
|
|
73
|
-
"eslint-plugin-react": "^7.31.
|
|
88
|
+
"eslint-plugin-react": "^7.31.11",
|
|
74
89
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
75
90
|
"husky": "^8.0.1",
|
|
76
91
|
"lint-staged": "^13.0.3",
|
|
77
|
-
"
|
|
92
|
+
"npm-run-all": "^4.1.5",
|
|
93
|
+
"prettier": "^2.8.1",
|
|
78
94
|
"prettier-plugin-packagejson": "^2.3.0",
|
|
79
|
-
"react": "^18",
|
|
95
|
+
"react": "^18.2.0",
|
|
96
|
+
"react-dom": "^18.2.0",
|
|
97
|
+
"react-is": "^18.2.0",
|
|
80
98
|
"rimraf": "^3.0.2",
|
|
81
|
-
"sanity": "^3.
|
|
99
|
+
"sanity": "^3.1.4",
|
|
82
100
|
"styled-components": "^5.3.6",
|
|
83
|
-
"typescript": "^4.
|
|
101
|
+
"typescript": "^4.9.4"
|
|
84
102
|
},
|
|
85
103
|
"peerDependencies": {
|
|
104
|
+
"easymde": "^2",
|
|
86
105
|
"react": "^18",
|
|
87
|
-
"sanity": "^3
|
|
106
|
+
"sanity": "^3",
|
|
88
107
|
"styled-components": "^5.2"
|
|
89
108
|
},
|
|
90
109
|
"engines": {
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {type Options as EasyMdeOptions} from 'easymde'
|
|
2
|
+
import React, {Suspense, useCallback, useMemo} from 'react'
|
|
3
|
+
// dont import non-types here, it will break SSR on next
|
|
4
|
+
import type {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
5
|
+
import {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'
|
|
6
|
+
import {MarkdownOptions} from '../schema'
|
|
7
|
+
import {MarkdownInputStyles} from './MarkdownInputStyles'
|
|
8
|
+
import {useSimpleMdeReact} from './useSimpleMdeReact'
|
|
9
|
+
import {Box, Text} from '@sanity/ui'
|
|
10
|
+
|
|
11
|
+
export interface MarkdownInputProps extends StringInputProps {
|
|
12
|
+
/**
|
|
13
|
+
* These are passed along directly to
|
|
14
|
+
*
|
|
15
|
+
* Note: MarkdownInput sets certain reactMdeProps.options by default.
|
|
16
|
+
* These will be merged with any custom options.
|
|
17
|
+
* */
|
|
18
|
+
reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const defaultMdeTools: EasyMdeOptions['toolbar'] = [
|
|
22
|
+
'heading',
|
|
23
|
+
'bold',
|
|
24
|
+
'italic',
|
|
25
|
+
'|',
|
|
26
|
+
'quote',
|
|
27
|
+
'unordered-list',
|
|
28
|
+
'ordered-list',
|
|
29
|
+
'|',
|
|
30
|
+
'link',
|
|
31
|
+
'image',
|
|
32
|
+
'code',
|
|
33
|
+
'|',
|
|
34
|
+
'preview',
|
|
35
|
+
'side-by-side',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export function MarkdownInput(props: MarkdownInputProps) {
|
|
39
|
+
const {
|
|
40
|
+
value = '',
|
|
41
|
+
onChange,
|
|
42
|
+
elementProps: {onBlur, onFocus, ref},
|
|
43
|
+
reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},
|
|
44
|
+
schemaType,
|
|
45
|
+
} = props
|
|
46
|
+
const client = useClient({apiVersion: '2022-01-01'})
|
|
47
|
+
const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}
|
|
48
|
+
|
|
49
|
+
const imageUpload = useCallback(
|
|
50
|
+
(file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {
|
|
51
|
+
client.assets
|
|
52
|
+
.upload('image', file)
|
|
53
|
+
.then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))
|
|
54
|
+
.catch((e) => {
|
|
55
|
+
console.error(e)
|
|
56
|
+
onError(e.message)
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
[client, imageUrl]
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const mdeOptions: EasyMdeOptions = useMemo(() => {
|
|
63
|
+
return {
|
|
64
|
+
autofocus: false,
|
|
65
|
+
spellChecker: false,
|
|
66
|
+
sideBySideFullscreen: false,
|
|
67
|
+
uploadImage: true,
|
|
68
|
+
imageUploadFunction: imageUpload,
|
|
69
|
+
toolbar: defaultMdeTools,
|
|
70
|
+
status: false,
|
|
71
|
+
...mdeCustomOptions,
|
|
72
|
+
}
|
|
73
|
+
}, [imageUpload, mdeCustomOptions])
|
|
74
|
+
|
|
75
|
+
const handleChange = useCallback(
|
|
76
|
+
(newValue: string) => {
|
|
77
|
+
onChange(PatchEvent.from(newValue ? set(newValue) : unset()))
|
|
78
|
+
},
|
|
79
|
+
[onChange]
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
const SimpleMdeReact = useSimpleMdeReact()
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<MarkdownInputStyles>
|
|
86
|
+
{SimpleMdeReact && (
|
|
87
|
+
<Suspense
|
|
88
|
+
fallback={
|
|
89
|
+
<Box padding={3}>
|
|
90
|
+
<Text>Loading editor...</Text>
|
|
91
|
+
</Box>
|
|
92
|
+
}
|
|
93
|
+
>
|
|
94
|
+
<SimpleMdeReact
|
|
95
|
+
{...reactMdeProps}
|
|
96
|
+
ref={ref}
|
|
97
|
+
value={value}
|
|
98
|
+
onChange={handleChange}
|
|
99
|
+
onBlur={onBlur}
|
|
100
|
+
onFocus={onFocus}
|
|
101
|
+
options={mdeOptions}
|
|
102
|
+
spellCheck={false}
|
|
103
|
+
/>
|
|
104
|
+
</Suspense>
|
|
105
|
+
)}
|
|
106
|
+
</MarkdownInputStyles>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import {Box} from '@sanity/ui'
|
|
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
|
+
`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {lazy, useEffect, useState} from 'react'
|
|
2
|
+
|
|
3
|
+
export const SimpleMdeReact = lazy(() => import('react-simplemde-editor'))
|
|
4
|
+
|
|
5
|
+
export function useSimpleMdeReact() {
|
|
6
|
+
const [mounted, setMounted] = useState(false)
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
requestAnimationFrame(() => setMounted(true))
|
|
9
|
+
}, [])
|
|
10
|
+
|
|
11
|
+
return mounted ? SimpleMdeReact : null
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {definePlugin} from 'sanity'
|
|
3
|
-
import {markdownSchemaType, MarkdownDefinition} from './schema'
|
|
1
|
+
import 'easymde/dist/easymde.min.css'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
const MarkdownEditor = Editor
|
|
7
|
-
|
|
8
|
-
export {MarkdownEditor, markdownSchemaType}
|
|
9
|
-
export type {MarkdownDefinition}
|
|
10
|
-
|
|
11
|
-
export const markdownSchema = definePlugin({
|
|
12
|
-
name: 'markdown-editor',
|
|
13
|
-
schema: {
|
|
14
|
-
types: [markdownSchemaType],
|
|
15
|
-
},
|
|
16
|
-
})
|
|
3
|
+
export * from './commonExports'
|
package/src/indexNext.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './commonExports'
|
package/src/plugin.tsx
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import {defineType, StringDefinition} from 'sanity'
|
|
2
|
-
import {
|
|
2
|
+
import {MarkdownInput} from './components/MarkdownInput'
|
|
3
|
+
import {SanityImageAssetDocument} from '@sanity/client'
|
|
3
4
|
|
|
4
|
-
const markdownTypeName = 'markdown' as const
|
|
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
|
+
}
|
|
5
27
|
|
|
6
28
|
/**
|
|
7
29
|
* @public
|
|
8
30
|
*/
|
|
9
31
|
export interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
10
32
|
type: typeof markdownTypeName
|
|
33
|
+
options?: MarkdownOptions
|
|
11
34
|
}
|
|
12
35
|
|
|
13
36
|
declare module '@sanity/types' {
|
|
@@ -21,5 +44,5 @@ export const markdownSchemaType = defineType({
|
|
|
21
44
|
type: 'string',
|
|
22
45
|
name: markdownTypeName,
|
|
23
46
|
title: 'Markdown',
|
|
24
|
-
|
|
47
|
+
components: {input: MarkdownInput},
|
|
25
48
|
})
|
package/lib/src/index.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
import {ForwardRefExoticComponent} from 'react'
|
|
4
|
-
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
-
import {RefAttributes} from 'react'
|
|
6
|
-
import {StringDefinition} from 'sanity'
|
|
7
|
-
import {StringInputProps} from 'sanity'
|
|
8
|
-
import {StringSchemaType} from 'sanity'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export declare interface MarkdownDefinition
|
|
14
|
-
extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
15
|
-
type: typeof markdownTypeName
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export declare const MarkdownEditor: ForwardRefExoticComponent<
|
|
19
|
-
StringInputProps<StringSchemaType> & RefAttributes<any>
|
|
20
|
-
>
|
|
21
|
-
|
|
22
|
-
export declare const markdownSchema: Plugin_2<void>
|
|
23
|
-
|
|
24
|
-
export declare const markdownSchemaType: {
|
|
25
|
-
type: 'string'
|
|
26
|
-
name: 'markdown'
|
|
27
|
-
} & Omit<StringDefinition, 'preview'>
|
|
28
|
-
|
|
29
|
-
declare const markdownTypeName: 'markdown'
|
|
30
|
-
|
|
31
|
-
export {}
|
|
32
|
-
|
|
33
|
-
declare module '@sanity/types' {
|
|
34
|
-
interface IntrinsicDefinitions {
|
|
35
|
-
markdown: MarkdownDefinition
|
|
36
|
-
}
|
|
37
|
-
}
|