sanity-plugin-markdown 6.0.0 → 7.0.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/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 +31 -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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { useClient, PatchEvent, set, unset, defineType, definePlugin } from "sanity";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { c } from "react-compiler-runtime";
|
|
4
|
+
import { Box, Text } from "@sanity/ui";
|
|
5
|
+
import { lazy, useState, useRef, useImperativeHandle, useEffect, Suspense } from "react";
|
|
6
|
+
import { styled } from "styled-components";
|
|
7
|
+
const SimpleMdeReact = lazy(() => import("react-simplemde-editor")), MarkdownInputStyles = styled(Box)`
|
|
8
|
+
& .CodeMirror.CodeMirror {
|
|
9
|
+
color: ${({
|
|
10
|
+
theme
|
|
11
|
+
}) => theme.sanity.color.card.enabled.fg};
|
|
12
|
+
border-color: ${({
|
|
13
|
+
theme
|
|
14
|
+
}) => theme.sanity.color.card.enabled.border};
|
|
15
|
+
background-color: inherit;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
& .cm-s-easymde .CodeMirror-cursor {
|
|
19
|
+
border-color: ${({
|
|
20
|
+
theme
|
|
21
|
+
}) => theme.sanity.color.card.enabled.fg};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
& .editor-toolbar,
|
|
25
|
+
.editor-preview-side {
|
|
26
|
+
border-color: ${({
|
|
27
|
+
theme
|
|
28
|
+
}) => theme.sanity.color.card.enabled.border};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
& .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
32
|
+
background-color: ${({
|
|
33
|
+
theme
|
|
34
|
+
}) => theme.sanity.color.selectable?.primary?.hovered?.bg};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
& .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
38
|
+
background-color: ${({
|
|
39
|
+
theme
|
|
40
|
+
}) => theme.sanity.color.card.enabled.bg};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
& .editor-toolbar > * {
|
|
44
|
+
color: ${({
|
|
45
|
+
theme
|
|
46
|
+
}) => theme.sanity.color.card.enabled.fg};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
& .editor-toolbar > .active,
|
|
50
|
+
.editor-toolbar > button:hover,
|
|
51
|
+
.editor-preview pre,
|
|
52
|
+
.cm-s-easymde .cm-comment {
|
|
53
|
+
background-color: ${({
|
|
54
|
+
theme
|
|
55
|
+
}) => theme.sanity.color.card.enabled.bg};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
& .editor-preview {
|
|
59
|
+
background-color: ${({
|
|
60
|
+
theme
|
|
61
|
+
}) => theme.sanity.color.card.enabled.bg};
|
|
62
|
+
|
|
63
|
+
& h1,
|
|
64
|
+
h2,
|
|
65
|
+
h3,
|
|
66
|
+
h4,
|
|
67
|
+
h5,
|
|
68
|
+
h6 {
|
|
69
|
+
font-size: revert;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
& ul,
|
|
73
|
+
li {
|
|
74
|
+
list-style: revert;
|
|
75
|
+
padding: revert;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
& a {
|
|
79
|
+
text-decoration: revert;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`, defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
83
|
+
function MarkdownInput(props) {
|
|
84
|
+
const $ = c(29), {
|
|
85
|
+
value: t0,
|
|
86
|
+
onChange,
|
|
87
|
+
elementProps: t1,
|
|
88
|
+
reactMdeProps: t2,
|
|
89
|
+
schemaType,
|
|
90
|
+
focused
|
|
91
|
+
} = props, value = t0 === void 0 ? "" : t0, {
|
|
92
|
+
onBlur,
|
|
93
|
+
onFocus,
|
|
94
|
+
ref: elementRef
|
|
95
|
+
} = t1;
|
|
96
|
+
let t3;
|
|
97
|
+
$[0] !== t2 ? (t3 = t2 === void 0 ? {} : t2, $[0] = t2, $[1] = t3) : t3 = $[1];
|
|
98
|
+
let mdeCustomOptions, reactMdeProps;
|
|
99
|
+
$[2] !== t3 ? ({
|
|
100
|
+
options: mdeCustomOptions,
|
|
101
|
+
...reactMdeProps
|
|
102
|
+
} = t3, $[2] = t3, $[3] = mdeCustomOptions, $[4] = reactMdeProps) : (mdeCustomOptions = $[3], reactMdeProps = $[4]);
|
|
103
|
+
let t4;
|
|
104
|
+
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t4 = {
|
|
105
|
+
apiVersion: "2022-01-01"
|
|
106
|
+
}, $[5] = t4) : t4 = $[5];
|
|
107
|
+
const client = useClient(t4);
|
|
108
|
+
let t5;
|
|
109
|
+
$[6] !== schemaType.options ? (t5 = schemaType.options ?? {}, $[6] = schemaType.options, $[7] = t5) : t5 = $[7];
|
|
110
|
+
const {
|
|
111
|
+
imageUrl
|
|
112
|
+
} = t5, [shouldAutoFocus, setShouldAutoFocus] = useState(!1), ref = useRef(null);
|
|
113
|
+
let t6;
|
|
114
|
+
$[8] === Symbol.for("react.memo_cache_sentinel") ? (t6 = () => ref.current, $[8] = t6) : t6 = $[8], useImperativeHandle(elementRef, t6);
|
|
115
|
+
let t7;
|
|
116
|
+
$[9] !== client || $[10] !== imageUrl ? (t7 = (file, onSuccess, onError) => {
|
|
117
|
+
client.assets.upload("image", file).then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`)).catch((e) => {
|
|
118
|
+
console.error(e), onError(e.message);
|
|
119
|
+
});
|
|
120
|
+
}, $[9] = client, $[10] = imageUrl, $[11] = t7) : t7 = $[11];
|
|
121
|
+
const imageUpload = t7;
|
|
122
|
+
let t8;
|
|
123
|
+
$[12] !== imageUpload || $[13] !== mdeCustomOptions || $[14] !== shouldAutoFocus ? (t8 = {
|
|
124
|
+
spellChecker: !1,
|
|
125
|
+
sideBySideFullscreen: !1,
|
|
126
|
+
uploadImage: !0,
|
|
127
|
+
imageUploadFunction: imageUpload,
|
|
128
|
+
toolbar: defaultMdeTools,
|
|
129
|
+
status: !1,
|
|
130
|
+
...mdeCustomOptions,
|
|
131
|
+
autofocus: shouldAutoFocus
|
|
132
|
+
}, $[12] = imageUpload, $[13] = mdeCustomOptions, $[14] = shouldAutoFocus, $[15] = t8) : t8 = $[15];
|
|
133
|
+
const mdeOptions = t8;
|
|
134
|
+
let t10, t9;
|
|
135
|
+
$[16] !== focused || $[17] !== shouldAutoFocus ? (t9 = () => {
|
|
136
|
+
const node = ref.current;
|
|
137
|
+
if (node) {
|
|
138
|
+
if (focused && !shouldAutoFocus) {
|
|
139
|
+
const raf = requestAnimationFrame(() => setShouldAutoFocus(!node.contains(document.activeElement)));
|
|
140
|
+
return () => cancelAnimationFrame(raf);
|
|
141
|
+
}
|
|
142
|
+
if (!focused && shouldAutoFocus) {
|
|
143
|
+
const raf_0 = requestAnimationFrame(() => setShouldAutoFocus(node.contains(document.activeElement)));
|
|
144
|
+
return () => cancelAnimationFrame(raf_0);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, t10 = [focused, shouldAutoFocus], $[16] = focused, $[17] = shouldAutoFocus, $[18] = t10, $[19] = t9) : (t10 = $[18], t9 = $[19]), useEffect(t9, t10);
|
|
148
|
+
let t11;
|
|
149
|
+
$[20] !== onChange ? (t11 = (newValue) => {
|
|
150
|
+
onChange(PatchEvent.from(newValue ? set(newValue) : unset()));
|
|
151
|
+
}, $[20] = onChange, $[21] = t11) : t11 = $[21];
|
|
152
|
+
const handleChange = t11;
|
|
153
|
+
let t12;
|
|
154
|
+
return $[22] !== handleChange || $[23] !== mdeOptions || $[24] !== onBlur || $[25] !== onFocus || $[26] !== reactMdeProps || $[27] !== value ? (t12 = /* @__PURE__ */ jsx(MarkdownInputStyles, { children: /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(SimpleMdeReact, { ...reactMdeProps, ref, value, onChange: handleChange, onBlur, onFocus, options: mdeOptions, spellCheck: !1 }) }) }), $[22] = handleChange, $[23] = mdeOptions, $[24] = onBlur, $[25] = onFocus, $[26] = reactMdeProps, $[27] = value, $[28] = t12) : t12 = $[28], t12;
|
|
155
|
+
}
|
|
156
|
+
const fallback = /* @__PURE__ */ jsx(Box, { padding: 3, children: /* @__PURE__ */ jsx(Text, { children: "Loading editor..." }) }), markdownTypeName = "markdown", markdownSchemaType = defineType({
|
|
157
|
+
type: "string",
|
|
158
|
+
name: markdownTypeName,
|
|
159
|
+
title: "Markdown",
|
|
160
|
+
components: {
|
|
161
|
+
input: MarkdownInput
|
|
162
|
+
}
|
|
163
|
+
}), markdownSchema = definePlugin((config) => ({
|
|
164
|
+
name: "markdown-editor",
|
|
165
|
+
schema: {
|
|
166
|
+
types: [config && config.input ? {
|
|
167
|
+
...markdownSchemaType,
|
|
168
|
+
components: {
|
|
169
|
+
input: config.input
|
|
170
|
+
}
|
|
171
|
+
} : markdownSchemaType]
|
|
172
|
+
}
|
|
173
|
+
}));
|
|
174
|
+
export {
|
|
175
|
+
MarkdownInput,
|
|
176
|
+
defaultMdeTools,
|
|
177
|
+
markdownSchema,
|
|
178
|
+
markdownSchemaType
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=indexNext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexNext.js","sources":["../src/components/MarkdownInput.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["// dont import non-types here, it will break SSR on next\nimport type {SimpleMDEReactProps} from 'react-simplemde-editor'\n\nimport {Box, Text} from '@sanity/ui'\nimport {type Options as EasyMdeOptions} from 'easymde'\nimport {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport {PatchEvent, set, type StringInputProps, unset, useClient} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {MarkdownOptions} from '../schema'\n\nconst SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nconst MarkdownInputStyles = styled(Box)`\n & .CodeMirror.CodeMirror {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n\n & h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n font-size: revert;\n }\n\n & ul,\n li {\n list-style: revert;\n padding: revert;\n }\n\n & a {\n text-decoration: revert;\n }\n }\n`\n\nexport interface MarkdownInputProps extends StringInputProps {\n /**\n * These are passed along directly to\n *\n * Note: MarkdownInput sets certain reactMdeProps.options by default.\n * These will be merged with any custom options.\n */\n reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>\n}\n\nexport const defaultMdeTools: EasyMdeOptions['toolbar'] = [\n 'heading',\n 'bold',\n 'italic',\n '|',\n 'quote',\n 'unordered-list',\n 'ordered-list',\n '|',\n 'link',\n 'image',\n 'code',\n '|',\n 'preview',\n 'side-by-side',\n]\n\nexport function MarkdownInput(props: MarkdownInputProps): React.JSX.Element {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus, ref: elementRef},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n focused,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\n const [shouldAutoFocus, setShouldAutoFocus] = useState(false)\n const ref = useRef<HTMLDivElement>(null)\n\n // Forward ref to parent form state\n useImperativeHandle(elementRef, () => ref.current)\n\n const imageUpload = useCallback(\n (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {\n client.assets\n .upload('image', file)\n .then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))\n .catch((e) => {\n console.error(e)\n onError(e.message)\n })\n },\n [client, imageUrl],\n )\n\n const mdeOptions: EasyMdeOptions = useMemo(() => {\n return {\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n autofocus: shouldAutoFocus,\n }\n }, [imageUpload, mdeCustomOptions, shouldAutoFocus])\n\n useEffect(() => {\n const node = ref.current\n if (!node) return undefined\n\n if (focused && !shouldAutoFocus) {\n // Do not set autofocus if the field already has focus\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(!node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n if (!focused && shouldAutoFocus) {\n // If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n return undefined\n }, [focused, shouldAutoFocus])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange],\n )\n\n return (\n <MarkdownInputStyles>\n <Suspense fallback={fallback}>\n <SimpleMdeReact\n {...reactMdeProps}\n ref={ref}\n value={value}\n onChange={handleChange}\n onBlur={onBlur}\n onFocus={onFocus}\n options={mdeOptions}\n spellCheck={false}\n />\n </Suspense>\n </MarkdownInputStyles>\n )\n}\n\nconst fallback = (\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n)\n","import type {SanityImageAssetDocument} from '@sanity/client'\n\nimport {defineType, type StringDefinition} from 'sanity'\n\nimport {MarkdownInput} from './components/MarkdownInput'\n\nexport const markdownTypeName = 'markdown' as const\n\nexport interface MarkdownOptions {\n /**\n * Used to create image url for any uploaded image.\n * The function will be invoked whenever an image is pasted or dragged into the\n * markdown editor, after upload completes.\n *\n * The default implementation uses\n * ```js\n * imageAsset => `${imageAsset.url}?w=450`\n * ```\n * ## Example\n * ```js\n * {\n * imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`\n * }\n * ```\n * @param imageAsset\n */\n imageUrl?: (imageAsset: SanityImageAssetDocument) => string\n}\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\n options?: MarkdownOptions\n}\n\ndeclare module 'sanity' {\n // makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n markdown: MarkdownDefinition\n }\n}\n\nexport const markdownSchemaType = defineType({\n type: 'string',\n name: markdownTypeName,\n title: 'Markdown',\n components: {input: MarkdownInput},\n})\n","import {definePlugin, type StringInputProps} from 'sanity'\n\nimport {markdownSchemaType} from './schema'\n\nexport interface MarkdownConfig {\n /**\n * When provided, will replace the default input component.\n *\n * Use this to customize MarkdownInput by wrapping it in a custom component,\n * and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * via the `reactMdeProps` prop.\n *\n * ### Example\n *\n * ```tsx\n * // CustomMarkdownInput.tsx\n * import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'\n *\n * export function CustomMarkdownInput(props) {\n * const reactMdeProps: MarkdownInputProps['reactMdeProps'] =\n * useMemo(() => {\n * return {\n * options: {\n * toolbar: ['bold', 'italic'],\n * // more options available, see:\n * // https://github.com/Ionaru/easy-markdown-editor#options-list\n * },\n * // more props available, see:\n * // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * }\n * }, [])\n *\n * return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />\n * }\n *\n * // studio.config.ts\n * markdownSchema({input: CustomMarkdownInput})\n * ```\n */\n input?: (props: StringInputProps) => React.ReactElement\n}\n\nexport const markdownSchema = definePlugin((config: MarkdownConfig | void) => {\n return {\n name: 'markdown-editor',\n schema: {\n types: [\n config && config.input\n ? {...markdownSchemaType, components: {input: config.input}}\n : markdownSchemaType,\n ],\n },\n }\n})\n"],"names":["SimpleMdeReact","lazy","MarkdownInputStyles","styled","Box","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","defaultMdeTools","MarkdownInput","props","$","_c","value","t0","onChange","elementProps","t1","reactMdeProps","t2","schemaType","focused","undefined","onBlur","onFocus","ref","elementRef","t3","mdeCustomOptions","options","t4","Symbol","for","apiVersion","client","useClient","t5","imageUrl","shouldAutoFocus","setShouldAutoFocus","useState","useRef","t6","current","useImperativeHandle","t7","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","imageUpload","t8","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","autofocus","mdeOptions","t10","t9","node","raf","requestAnimationFrame","contains","document","activeElement","cancelAnimationFrame","raf_0","useEffect","t11","newValue","PatchEvent","from","set","unset","handleChange","t12","fallback","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","definePlugin","config","schema","types"],"mappings":";;;;;;AAoBA,MAAMA,iBAAiBC,KAAK,MAAM,OAAO,wBAAwB,CAAC,GAE5DC,sBAAsBC,OAAOC,GAAG;AAAA;AAAA,aAEzB,CAAC;AAAA,EAACC;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,EAAE;AAAA,oBACxC,CAAC;AAAA,EAACL;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQE,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKnD,CAAC;AAAA,EAACN;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,oBAK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ACD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-markdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -9,93 +9,47 @@
|
|
|
9
9
|
"markdown",
|
|
10
10
|
"github flavored markdown"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.com/sanity-io/sanity-plugin-markdown#readme",
|
|
12
|
+
"homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-markdown#readme",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/sanity-io/
|
|
14
|
+
"url": "https://github.com/sanity-io/plugins/issues"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git@github.com
|
|
18
|
+
"url": "git+ssh://git@github.com/sanity-io/plugins.git",
|
|
19
|
+
"directory": "plugins/sanity-plugin-markdown"
|
|
19
20
|
},
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"author": "Sanity.io <hello@sanity.io>",
|
|
22
|
-
"
|
|
23
|
+
"type": "module",
|
|
23
24
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
|
|
26
|
-
"import": "./lib/index.mjs",
|
|
27
|
-
"require": "./lib/index.js",
|
|
28
|
-
"default": "./lib/index.js"
|
|
29
|
-
},
|
|
30
|
-
"./next": {
|
|
31
|
-
"source": "./src/indexNext.ts",
|
|
32
|
-
"import": "./lib/indexNext.mjs",
|
|
33
|
-
"require": "./lib/indexNext.js",
|
|
34
|
-
"default": "./lib/indexNext.js"
|
|
35
|
-
},
|
|
25
|
+
".": "./dist/index.js",
|
|
26
|
+
"./next": "./dist/indexNext.js",
|
|
36
27
|
"./package.json": "./package.json"
|
|
37
28
|
},
|
|
38
|
-
"
|
|
39
|
-
"module": "./lib/index.esm.js",
|
|
40
|
-
"types": "./lib/index.d.ts",
|
|
41
|
-
"typesVersions": {
|
|
42
|
-
"*": {
|
|
43
|
-
"next": [
|
|
44
|
-
"./lib/indexNext.d.ts"
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
},
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
48
30
|
"files": [
|
|
49
|
-
"
|
|
50
|
-
"sanity.json",
|
|
51
|
-
"src",
|
|
52
|
-
"v2-incompatible.js"
|
|
31
|
+
"dist"
|
|
53
32
|
],
|
|
54
|
-
"scripts": {
|
|
55
|
-
"build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
|
|
56
|
-
"compile": "tsc --noEmit",
|
|
57
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
58
|
-
"link-watch": "plugin-kit link-watch",
|
|
59
|
-
"lint": "eslint .",
|
|
60
|
-
"prepare": "husky install",
|
|
61
|
-
"prepublishOnly": "npm run build",
|
|
62
|
-
"watch": "pkg-utils watch --strict"
|
|
63
|
-
},
|
|
64
|
-
"browserslist": "extends @sanity/browserslist-config",
|
|
65
|
-
"prettier": "@sanity/prettier-config",
|
|
66
33
|
"dependencies": {
|
|
67
|
-
"@sanity/incompatible-plugin": "^1.0.5",
|
|
68
34
|
"@sanity/ui": "^3.0.5",
|
|
35
|
+
"react-compiler-runtime": "^1.0.0",
|
|
69
36
|
"react-simplemde-editor": "^5.2.0"
|
|
70
37
|
},
|
|
71
38
|
"devDependencies": {
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"@typescript-eslint/parser": "^5.62.0",
|
|
82
|
-
"easymde": "^2.18.0",
|
|
83
|
-
"eslint": "^8.57.0",
|
|
84
|
-
"eslint-config-prettier": "^9.1.0",
|
|
85
|
-
"eslint-config-sanity": "^6.0.0",
|
|
86
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
87
|
-
"eslint-plugin-react": "^7.35.2",
|
|
88
|
-
"eslint-plugin-react-hooks": "^4.6.2",
|
|
89
|
-
"husky": "^8.0.1",
|
|
90
|
-
"lint-staged": "^13.0.3",
|
|
91
|
-
"npm-run-all2": "^5.0.0",
|
|
92
|
-
"prettier": "^3.3.3",
|
|
93
|
-
"react": "^18.3.1",
|
|
94
|
-
"react-dom": "^18.3.1",
|
|
95
|
-
"react-is": "^18.3.1",
|
|
96
|
-
"sanity": "^4.1.1",
|
|
39
|
+
"@sanity/client": "7.13.1",
|
|
40
|
+
"@sanity/pkg-utils": "^10.1.1",
|
|
41
|
+
"@types/react": "^19.2.7",
|
|
42
|
+
"@typescript/native-preview": "7.0.0-dev.20251202.1",
|
|
43
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
44
|
+
"easymde": "^2.20.0",
|
|
45
|
+
"eslint": "^9.39.1",
|
|
46
|
+
"react": "^19.2.1",
|
|
47
|
+
"sanity": "^4.20.3",
|
|
97
48
|
"styled-components": "^6.1.19",
|
|
98
|
-
"typescript": "5.
|
|
49
|
+
"typescript": "5.9.3",
|
|
50
|
+
"@repo/eslint-config": "0.0.4",
|
|
51
|
+
"@repo/package.config": "0.0.0",
|
|
52
|
+
"@repo/tsconfig": "1.0.0"
|
|
99
53
|
},
|
|
100
54
|
"peerDependencies": {
|
|
101
55
|
"easymde": "^2.18",
|
|
@@ -104,7 +58,11 @@
|
|
|
104
58
|
"styled-components": "^6.1"
|
|
105
59
|
},
|
|
106
60
|
"engines": {
|
|
107
|
-
"node": ">=
|
|
61
|
+
"node": ">=20.19 <22 || >=22.12"
|
|
108
62
|
},
|
|
109
|
-
"
|
|
110
|
-
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "pkg build --strict --check --clean",
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"typecheck": "(cd ../.. && tsgo --project plugins/sanity-plugin-markdown/tsconfig.json)"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
14
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
15
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
16
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
17
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
18
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
19
|
-
mod
|
|
20
|
-
));
|
|
21
|
-
var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ui = require("@sanity/ui"), styledComponents = require("styled-components");
|
|
22
|
-
const MarkdownInputStyles = styledComponents.styled(ui.Box)`
|
|
23
|
-
& .CodeMirror.CodeMirror {
|
|
24
|
-
color: ${({ theme }) => theme.sanity.color.card.enabled.fg};
|
|
25
|
-
border-color: ${({ theme }) => theme.sanity.color.card.enabled.border};
|
|
26
|
-
background-color: inherit;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
& .cm-s-easymde .CodeMirror-cursor {
|
|
30
|
-
border-color: ${({ theme }) => theme.sanity.color.card.enabled.fg};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
& .editor-toolbar,
|
|
34
|
-
.editor-preview-side {
|
|
35
|
-
border-color: ${({ theme }) => theme.sanity.color.card.enabled.border};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
& .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
39
|
-
background-color: ${({ theme }) => theme.sanity.color.selectable?.primary?.hovered?.bg};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
& .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
43
|
-
background-color: ${({ theme }) => theme.sanity.color.card.enabled.bg};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
& .editor-toolbar > * {
|
|
47
|
-
color: ${({ theme }) => theme.sanity.color.card.enabled.fg};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
& .editor-toolbar > .active,
|
|
51
|
-
.editor-toolbar > button:hover,
|
|
52
|
-
.editor-preview pre,
|
|
53
|
-
.cm-s-easymde .cm-comment {
|
|
54
|
-
background-color: ${({ theme }) => theme.sanity.color.card.enabled.bg};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
& .editor-preview {
|
|
58
|
-
background-color: ${({ theme }) => theme.sanity.color.card.enabled.bg};
|
|
59
|
-
|
|
60
|
-
& h1,
|
|
61
|
-
h2,
|
|
62
|
-
h3,
|
|
63
|
-
h4,
|
|
64
|
-
h5,
|
|
65
|
-
h6 {
|
|
66
|
-
font-size: revert;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
& ul,
|
|
70
|
-
li {
|
|
71
|
-
list-style: revert;
|
|
72
|
-
padding: revert;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
& a {
|
|
76
|
-
text-decoration: revert;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
`, SimpleMdeReact = react.lazy(() => import("react-simplemde-editor")), defaultMdeTools = [
|
|
80
|
-
"heading",
|
|
81
|
-
"bold",
|
|
82
|
-
"italic",
|
|
83
|
-
"|",
|
|
84
|
-
"quote",
|
|
85
|
-
"unordered-list",
|
|
86
|
-
"ordered-list",
|
|
87
|
-
"|",
|
|
88
|
-
"link",
|
|
89
|
-
"image",
|
|
90
|
-
"code",
|
|
91
|
-
"|",
|
|
92
|
-
"preview",
|
|
93
|
-
"side-by-side"
|
|
94
|
-
];
|
|
95
|
-
function MarkdownInput(props) {
|
|
96
|
-
const {
|
|
97
|
-
value = "",
|
|
98
|
-
onChange,
|
|
99
|
-
elementProps: { onBlur, onFocus, ref: elementRef },
|
|
100
|
-
reactMdeProps: { options: mdeCustomOptions, ...reactMdeProps } = {},
|
|
101
|
-
schemaType,
|
|
102
|
-
focused
|
|
103
|
-
} = props, client = sanity.useClient({ apiVersion: "2022-01-01" }), { imageUrl } = schemaType.options ?? {}, [shouldAutoFocus, setShouldAutoFocus] = react.useState(!1), ref = react.useRef(null);
|
|
104
|
-
react.useImperativeHandle(elementRef, () => ref.current);
|
|
105
|
-
const imageUpload = react.useCallback(
|
|
106
|
-
(file, onSuccess, onError) => {
|
|
107
|
-
client.assets.upload("image", file).then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`)).catch((e) => {
|
|
108
|
-
console.error(e), onError(e.message);
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
[client, imageUrl]
|
|
112
|
-
), mdeOptions = react.useMemo(() => ({
|
|
113
|
-
spellChecker: !1,
|
|
114
|
-
sideBySideFullscreen: !1,
|
|
115
|
-
uploadImage: !0,
|
|
116
|
-
imageUploadFunction: imageUpload,
|
|
117
|
-
toolbar: defaultMdeTools,
|
|
118
|
-
status: !1,
|
|
119
|
-
...mdeCustomOptions,
|
|
120
|
-
autofocus: shouldAutoFocus
|
|
121
|
-
}), [imageUpload, mdeCustomOptions, shouldAutoFocus]);
|
|
122
|
-
react.useEffect(() => {
|
|
123
|
-
const node = ref.current;
|
|
124
|
-
if (node) {
|
|
125
|
-
if (focused && !shouldAutoFocus) {
|
|
126
|
-
const raf = requestAnimationFrame(
|
|
127
|
-
() => setShouldAutoFocus(!node.contains(document.activeElement))
|
|
128
|
-
);
|
|
129
|
-
return () => cancelAnimationFrame(raf);
|
|
130
|
-
}
|
|
131
|
-
if (!focused && shouldAutoFocus) {
|
|
132
|
-
const raf = requestAnimationFrame(
|
|
133
|
-
() => setShouldAutoFocus(node.contains(document.activeElement))
|
|
134
|
-
);
|
|
135
|
-
return () => cancelAnimationFrame(raf);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}, [focused, shouldAutoFocus]);
|
|
139
|
-
const handleChange = react.useCallback(
|
|
140
|
-
(newValue) => {
|
|
141
|
-
onChange(sanity.PatchEvent.from(newValue ? sanity.set(newValue) : sanity.unset()));
|
|
142
|
-
},
|
|
143
|
-
[onChange]
|
|
144
|
-
);
|
|
145
|
-
return /* @__PURE__ */ jsxRuntime.jsx(MarkdownInputStyles, { children: /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
146
|
-
SimpleMdeReact,
|
|
147
|
-
{
|
|
148
|
-
...reactMdeProps,
|
|
149
|
-
ref,
|
|
150
|
-
value,
|
|
151
|
-
onChange: handleChange,
|
|
152
|
-
onBlur,
|
|
153
|
-
onFocus,
|
|
154
|
-
options: mdeOptions,
|
|
155
|
-
spellCheck: !1
|
|
156
|
-
}
|
|
157
|
-
) }) });
|
|
158
|
-
}
|
|
159
|
-
const fallback = /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading editor..." }) }), markdownTypeName = "markdown", markdownSchemaType = sanity.defineType({
|
|
160
|
-
type: "string",
|
|
161
|
-
name: markdownTypeName,
|
|
162
|
-
title: "Markdown",
|
|
163
|
-
components: { input: MarkdownInput }
|
|
164
|
-
}), markdownSchema = sanity.definePlugin((config) => ({
|
|
165
|
-
name: "markdown-editor",
|
|
166
|
-
schema: {
|
|
167
|
-
types: [
|
|
168
|
-
config && config.input ? { ...markdownSchemaType, components: { input: config.input } } : markdownSchemaType
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
}));
|
|
172
|
-
exports.MarkdownInput = MarkdownInput;
|
|
173
|
-
exports.defaultMdeTools = defaultMdeTools;
|
|
174
|
-
exports.markdownSchema = markdownSchema;
|
|
175
|
-
exports.markdownSchemaType = markdownSchemaType;
|
|
176
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/components/MarkdownInputStyles.tsx","../../src/components/MarkdownInput.tsx","../../src/schema.ts","../../src/plugin.tsx"],"sourcesContent":["import {Box} from '@sanity/ui'\nimport {styled} from 'styled-components'\n\nexport const MarkdownInputStyles = styled(Box)`\n & .CodeMirror.CodeMirror {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n\n & h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n font-size: revert;\n }\n\n & ul,\n li {\n list-style: revert;\n padding: revert;\n }\n\n & a {\n text-decoration: revert;\n }\n }\n`\n","import {type Options as EasyMdeOptions} from 'easymde'\nimport {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react'\n// dont import non-types here, it will break SSR on next\nimport type {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'\nimport {MarkdownOptions} from '../schema'\nimport {MarkdownInputStyles} from './MarkdownInputStyles'\nimport {Box, Text} from '@sanity/ui'\n\nconst SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nexport interface MarkdownInputProps extends StringInputProps {\n /**\n * These are passed along directly to\n *\n * Note: MarkdownInput sets certain reactMdeProps.options by default.\n * These will be merged with any custom options.\n */\n reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>\n}\n\nexport const defaultMdeTools: EasyMdeOptions['toolbar'] = [\n 'heading',\n 'bold',\n 'italic',\n '|',\n 'quote',\n 'unordered-list',\n 'ordered-list',\n '|',\n 'link',\n 'image',\n 'code',\n '|',\n 'preview',\n 'side-by-side',\n]\n\nexport function MarkdownInput(props: MarkdownInputProps) {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus, ref: elementRef},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n focused,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\n const [shouldAutoFocus, setShouldAutoFocus] = useState(false)\n const ref = useRef<HTMLDivElement>(null)\n\n // Forward ref to parent form state\n useImperativeHandle(elementRef, () => ref.current)\n\n const imageUpload = useCallback(\n (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {\n client.assets\n .upload('image', file)\n .then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))\n .catch((e) => {\n console.error(e)\n onError(e.message)\n })\n },\n [client, imageUrl],\n )\n\n const mdeOptions: EasyMdeOptions = useMemo(() => {\n return {\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n autofocus: shouldAutoFocus,\n }\n }, [imageUpload, mdeCustomOptions, shouldAutoFocus])\n\n // eslint-disable-next-line consistent-return\n useEffect(() => {\n const node = ref.current\n if (!node) return undefined\n\n if (focused && !shouldAutoFocus) {\n // Do not set autofocus if the field already has focus\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(!node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n if (!focused && shouldAutoFocus) {\n // If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n }, [focused, shouldAutoFocus])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange],\n )\n\n return (\n <MarkdownInputStyles>\n <Suspense fallback={fallback}>\n <SimpleMdeReact\n {...reactMdeProps}\n ref={ref}\n value={value}\n onChange={handleChange}\n onBlur={onBlur}\n onFocus={onFocus}\n options={mdeOptions}\n spellCheck={false}\n />\n </Suspense>\n </MarkdownInputStyles>\n )\n}\n\nconst fallback = (\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n)\n","import {defineType, StringDefinition} from 'sanity'\nimport {MarkdownInput} from './components/MarkdownInput'\nimport {SanityImageAssetDocument} from '@sanity/client'\n\nexport const markdownTypeName = 'markdown' as const\n\nexport interface MarkdownOptions {\n /**\n * Used to create image url for any uploaded image.\n * The function will be invoked whenever an image is pasted or dragged into the\n * markdown editor, after upload completes.\n *\n * The default implementation uses\n * ```js\n * imageAsset => `${imageAsset.url}?w=450`\n * ```\n * ## Example\n * ```js\n * {\n * imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`\n * }\n * ```\n * @param imageAsset\n */\n imageUrl?: (imageAsset: SanityImageAssetDocument) => string\n}\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\n options?: MarkdownOptions\n}\n\ndeclare module '@sanity/types' {\n // makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n markdown: MarkdownDefinition\n }\n}\n\nexport const markdownSchemaType = defineType({\n type: 'string',\n name: markdownTypeName,\n title: 'Markdown',\n components: {input: MarkdownInput},\n})\n","import {definePlugin, StringInputProps} from 'sanity'\nimport {markdownSchemaType} from './schema'\nimport {ReactElement} from 'react'\n\nexport interface MarkdownConfig {\n /**\n * When provided, will replace the default input component.\n *\n * Use this to customize MarkdownInput by wrapping it in a custom component,\n * and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * via the `reactMdeProps` prop.\n *\n * ### Example\n *\n * ```tsx\n * // CustomMarkdownInput.tsx\n * import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'\n *\n * export function CustomMarkdownInput(props) {\n * const reactMdeProps: MarkdownInputProps['reactMdeProps'] =\n * useMemo(() => {\n * return {\n * options: {\n * toolbar: ['bold', 'italic'],\n * // more options available, see:\n * // https://github.com/Ionaru/easy-markdown-editor#options-list\n * },\n * // more props available, see:\n * // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * }\n * }, [])\n *\n * return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />\n * }\n *\n * // studio.config.ts\n * markdownSchema({input: CustomMarkdownInput})\n * ```\n */\n input?: (props: StringInputProps) => ReactElement\n}\n\nexport const markdownSchema = definePlugin((config: MarkdownConfig | void) => {\n return {\n name: 'markdown-editor',\n schema: {\n types: [\n config && config.input\n ? {...markdownSchemaType, components: {input: config.input}}\n : markdownSchemaType,\n ],\n },\n }\n})\n"],"names":["styled","Box","lazy","useClient","useState","useRef","useImperativeHandle","useCallback","useMemo","useEffect","PatchEvent","set","unset","jsx","Suspense","Text","defineType","definePlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,sBAAsBA,iBAAAA,OAAOC,MAAG;AAAA;AAAA,aAEhC,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA,oBACxC,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKnD,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,oBAK/C,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA,wBAI/C,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,YAAY,SAAS,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA,wBAIhE,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA,aAI1D,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAOpC,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA,wBAI/C,CAAC,EAAC,MAAA,MAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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