sanity-plugin-markdown 4.0.0 → 4.1.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/LICENSE +1 -1
- package/README.md +14 -0
- package/lib/_chunks/plugin-0fd9aa65.js +112 -0
- package/lib/_chunks/plugin-0fd9aa65.js.map +1 -0
- package/lib/_chunks/plugin-fb6e236d.js +123 -0
- package/lib/_chunks/plugin-fb6e236d.js.map +1 -0
- package/lib/index.d.ts +3 -4
- package/lib/index.esm.js +1 -139
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +5 -149
- 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 +20 -6
- package/src/commonExports.ts +4 -0
- package/src/components/MarkdownInput.tsx +27 -13
- package/src/components/MarkdownInputStyles.tsx +63 -61
- package/src/components/useSimpleMdeReact.tsx +12 -0
- package/src/index.ts +2 -3
- package/src/indexNext.ts +1 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -53,6 +53,20 @@ const myDocument = {
|
|
|
53
53
|
]
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
|
+
### Next.js compatability
|
|
57
|
+
Next.js *without* Next 13 app directory does not support css imports from `node_modules`.
|
|
58
|
+
|
|
59
|
+
To use this plugin in this context (`pages` directory), use the `sanity-plugin-markdown/next` import instead of `sanity-plugin-markdown`:
|
|
60
|
+
```js
|
|
61
|
+
import { markdownSchema } from "sanity-plugin-markdown/next";
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Then, make sure to add
|
|
65
|
+
```js
|
|
66
|
+
import 'easymde/dist/easymde.min.css'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
to the top of `pages/_app.tsx`.
|
|
56
70
|
|
|
57
71
|
### Customizing the default markdown input editor
|
|
58
72
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import { useClient, PatchEvent, set, unset, defineType, definePlugin } from 'sanity';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { lazy, useState, useEffect, useCallback, useMemo, Suspense } from 'react';
|
|
6
|
+
import { Box, Text } from '@sanity/ui';
|
|
7
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
const MarkdownInputStyles = styled(Box)(_ref => {
|
|
9
|
+
let {
|
|
10
|
+
theme
|
|
11
|
+
} = _ref;
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n & .CodeMirror.CodeMirror {\n color: ", ";\n border-color: ", ";\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ", ";\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ", ";\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .editor-toolbar > * {\n color: ", ";\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ", ";\n }\n\n & .editor-preview {\n background-color: ", ";\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 "])), theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.border, theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.border, (_c = (_b = (_a = theme.sanity.color.selectable) == null ? void 0 : _a.primary) == null ? void 0 : _b.hovered) == null ? void 0 : _c.bg, theme.sanity.color.card.enabled.bg, theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.bg, theme.sanity.color.card.enabled.bg);
|
|
14
|
+
});
|
|
15
|
+
const SimpleMdeReact = lazy(() => import('react-simplemde-editor'));
|
|
16
|
+
function useSimpleMdeReact() {
|
|
17
|
+
const [mounted, setMounted] = useState(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
requestAnimationFrame(() => setMounted(true));
|
|
20
|
+
}, []);
|
|
21
|
+
return mounted ? SimpleMdeReact : null;
|
|
22
|
+
}
|
|
23
|
+
const defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
24
|
+
function MarkdownInput(props) {
|
|
25
|
+
var _a;
|
|
26
|
+
const {
|
|
27
|
+
value = "",
|
|
28
|
+
onChange,
|
|
29
|
+
elementProps: {
|
|
30
|
+
onBlur,
|
|
31
|
+
onFocus,
|
|
32
|
+
ref
|
|
33
|
+
},
|
|
34
|
+
reactMdeProps: {
|
|
35
|
+
options: mdeCustomOptions,
|
|
36
|
+
...reactMdeProps
|
|
37
|
+
} = {},
|
|
38
|
+
schemaType
|
|
39
|
+
} = props;
|
|
40
|
+
const client = useClient({
|
|
41
|
+
apiVersion: "2022-01-01"
|
|
42
|
+
});
|
|
43
|
+
const {
|
|
44
|
+
imageUrl
|
|
45
|
+
} = (_a = schemaType.options) != null ? _a : {};
|
|
46
|
+
const imageUpload = useCallback((file, onSuccess, onError) => {
|
|
47
|
+
client.assets.upload("image", file).then(doc => onSuccess(imageUrl ? imageUrl(doc) : "".concat(doc.url, "?w=450"))).catch(e => {
|
|
48
|
+
console.error(e);
|
|
49
|
+
onError(e.message);
|
|
50
|
+
});
|
|
51
|
+
}, [client, imageUrl]);
|
|
52
|
+
const mdeOptions = useMemo(() => {
|
|
53
|
+
return {
|
|
54
|
+
autofocus: false,
|
|
55
|
+
spellChecker: false,
|
|
56
|
+
sideBySideFullscreen: false,
|
|
57
|
+
uploadImage: true,
|
|
58
|
+
imageUploadFunction: imageUpload,
|
|
59
|
+
toolbar: defaultMdeTools,
|
|
60
|
+
status: false,
|
|
61
|
+
...mdeCustomOptions
|
|
62
|
+
};
|
|
63
|
+
}, [imageUpload, mdeCustomOptions]);
|
|
64
|
+
const handleChange = useCallback(newValue => {
|
|
65
|
+
onChange(PatchEvent.from(newValue ? set(newValue) : unset()));
|
|
66
|
+
}, [onChange]);
|
|
67
|
+
const SimpleMdeReact = useSimpleMdeReact();
|
|
68
|
+
return /* @__PURE__ */jsx(MarkdownInputStyles, {
|
|
69
|
+
children: SimpleMdeReact && /* @__PURE__ */jsx(Suspense, {
|
|
70
|
+
fallback: /* @__PURE__ */jsx(Box, {
|
|
71
|
+
padding: 3,
|
|
72
|
+
children: /* @__PURE__ */jsx(Text, {
|
|
73
|
+
children: "Loading editor..."
|
|
74
|
+
})
|
|
75
|
+
}),
|
|
76
|
+
children: /* @__PURE__ */jsx(SimpleMdeReact, {
|
|
77
|
+
...reactMdeProps,
|
|
78
|
+
ref,
|
|
79
|
+
value,
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onBlur,
|
|
82
|
+
onFocus,
|
|
83
|
+
options: mdeOptions,
|
|
84
|
+
spellCheck: false
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const markdownTypeName = "markdown";
|
|
90
|
+
const markdownSchemaType = defineType({
|
|
91
|
+
type: "string",
|
|
92
|
+
name: markdownTypeName,
|
|
93
|
+
title: "Markdown",
|
|
94
|
+
components: {
|
|
95
|
+
input: MarkdownInput
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const markdownSchema = definePlugin(config => {
|
|
99
|
+
return {
|
|
100
|
+
name: "markdown-editor",
|
|
101
|
+
schema: {
|
|
102
|
+
types: [config && config.input ? {
|
|
103
|
+
...markdownSchemaType,
|
|
104
|
+
components: {
|
|
105
|
+
input: config.input
|
|
106
|
+
}
|
|
107
|
+
} : markdownSchemaType]
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType };
|
|
112
|
+
//# sourceMappingURL=plugin-0fd9aa65.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-0fd9aa65.js","sources":["../../src/components/MarkdownInputStyles.tsx","../../src/components/useSimpleMdeReact.tsx","../../src/components/MarkdownInput.tsx","../../src/schema.ts","../../src/plugin.tsx"],"sourcesContent":["import {Box, type Theme} from '@sanity/ui'\nimport styled, {css} from 'styled-components'\n\nexport const MarkdownInputStyles = styled(Box)(({theme}: {theme: Theme}) => {\n return css`\n & .CodeMirror.CodeMirror {\n color: ${theme.sanity.color.card.enabled.fg};\n border-color: ${theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${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.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${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})\n","import {lazy, useEffect, useState} from 'react'\n\nexport const SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nexport function useSimpleMdeReact() {\n const [mounted, setMounted] = useState(false)\n useEffect(() => {\n requestAnimationFrame(() => setMounted(true))\n }, [])\n\n return mounted ? SimpleMdeReact : null\n}\n","import {type Options as EasyMdeOptions} from 'easymde'\nimport React, {Suspense, useCallback, useMemo} 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 {useSimpleMdeReact} from './useSimpleMdeReact'\nimport {Box, Text} from '@sanity/ui'\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},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\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 autofocus: false,\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n }\n }, [imageUpload, mdeCustomOptions])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange]\n )\n\n const SimpleMdeReact = useSimpleMdeReact()\n\n return (\n <MarkdownInputStyles>\n {SimpleMdeReact && (\n <Suspense\n fallback={\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n }\n >\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 )}\n </MarkdownInputStyles>\n )\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":["MarkdownInputStyles","styled","Box","_ref","theme","_a","_b","_c","css","_templateObject","_taggedTemplateLiteral","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","SimpleMdeReact","lazy","useSimpleMdeReact","mounted","setMounted","useState","useEffect","requestAnimationFrame","defaultMdeTools","MarkdownInput","props","value","onChange","elementProps","onBlur","onFocus","ref","reactMdeProps","options","mdeCustomOptions","schemaType","client","useClient","apiVersion","imageUrl","imageUpload","useCallback","file","onSuccess","onError","assets","upload","then","doc","concat","url","catch","e","console","error","message","mdeOptions","useMemo","autofocus","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","handleChange","newValue","PatchEvent","from","set","unset","jsx","children","Suspense","fallback","padding","Text","spellCheck","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","definePlugin","config","schema","types"],"mappings":";;;;;;;AAGO,MAAMA,sBAAsBC,MAAO,CAAAC,GAAG,EAAEC,IAAA,IAA6B;EAAA,IAA5B;IAACC;GAA2B,GAAAD,IAAA;EAH5E,IAAAE,EAAA,EAAAC,EAAA,EAAAC,EAAA;EAIS,OAAAC,GAAA,CAAAC,eAAA,KAAAA,eAAA,GAAAC,sBAAA,ikCAEMN,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAC,EAAA,EACzBX,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAE,MAAA,EAKhCZ,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAC,EAAA,EAKhCX,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAE,MAAA,EAI5B,CAAAT,EAAA,GAAA,CAAAD,EAAA,GAAA,CAAAD,EAAA,GAAAD,KAAA,CAAMO,OAAOC,KAAM,CAAAK,UAAA,KAAnB,mBAA+BC,OAA/B,KAAA,IAAA,GAAA,KAAA,CAAA,GAAAZ,EAAA,CAAwCa,YAAxC,IAAiD,GAAA,KAAA,CAAA,GAAAZ,EAAA,CAAAa,EAAA,EAIjDhB,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAM,EAAA,EAI3ChB,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAC,EAAA,EAOrBX,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAM,EAAA,EAIhChB,KAAM,CAAAO,MAAA,CAAOC,KAAM,CAAAC,IAAA,CAAKC,OAAQ,CAAAM,EAAA;AAsB1D,C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,CACd;IAAA,CACF;EAAA,CAEJ,CAAA;AAEJ;ACvGO,MAAMC,gBAAmB,GAAA,UAAA;AAsCzB,MAAMC,qBAAqBC,UAAW,CAAA;EAC3CC,IAAM,EAAA,QAAA;EACNC,IAAM,EAAAJ,gBAAA;EACNK,KAAO,EAAA,UAAA;EACPC,UAAA,EAAY;IAACC,KAAA,EAAO7D;EAAa;AACnC,CAAC,CAAA;ACLY,MAAA8D,cAAA,GAAiBC,YAAa,CAACC,MAAkC,IAAA;EACrE,OAAA;IACLN,IAAM,EAAA,iBAAA;IACNO,MAAQ,EAAA;MACNC,KAAO,EAAA,CACLF,MAAU,IAAAA,MAAA,CAAOH,KACb,GAAA;QAAC,GAAGN,kBAAA;QAAoBK,UAAY,EAAA;UAACC,KAAO,EAAAG,MAAA,CAAOH;QAAK;MACxD,CAAA,GAAAN,kBAAA;IAER;EAAA,CACF;AACF,CAAC,CAAA;"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _templateObject;
|
|
4
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
5
|
+
var sanity = require('sanity');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var ui = require('@sanity/ui');
|
|
9
|
+
var styled = require('styled-components');
|
|
10
|
+
function _interopDefaultCompat(e) {
|
|
11
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
12
|
+
default: e
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
16
|
+
const MarkdownInputStyles = styled__default.default(ui.Box)(_ref => {
|
|
17
|
+
let {
|
|
18
|
+
theme
|
|
19
|
+
} = _ref;
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
return styled.css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n & .CodeMirror.CodeMirror {\n color: ", ";\n border-color: ", ";\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ", ";\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ", ";\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .editor-toolbar > * {\n color: ", ";\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ", ";\n }\n\n & .editor-preview {\n background-color: ", ";\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 "])), theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.border, theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.border, (_c = (_b = (_a = theme.sanity.color.selectable) == null ? void 0 : _a.primary) == null ? void 0 : _b.hovered) == null ? void 0 : _c.bg, theme.sanity.color.card.enabled.bg, theme.sanity.color.card.enabled.fg, theme.sanity.color.card.enabled.bg, theme.sanity.color.card.enabled.bg);
|
|
22
|
+
});
|
|
23
|
+
const SimpleMdeReact = react.lazy(() => import('react-simplemde-editor'));
|
|
24
|
+
function useSimpleMdeReact() {
|
|
25
|
+
const [mounted, setMounted] = react.useState(false);
|
|
26
|
+
react.useEffect(() => {
|
|
27
|
+
requestAnimationFrame(() => setMounted(true));
|
|
28
|
+
}, []);
|
|
29
|
+
return mounted ? SimpleMdeReact : null;
|
|
30
|
+
}
|
|
31
|
+
const defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
32
|
+
function MarkdownInput(props) {
|
|
33
|
+
var _a;
|
|
34
|
+
const {
|
|
35
|
+
value = "",
|
|
36
|
+
onChange,
|
|
37
|
+
elementProps: {
|
|
38
|
+
onBlur,
|
|
39
|
+
onFocus,
|
|
40
|
+
ref
|
|
41
|
+
},
|
|
42
|
+
reactMdeProps: {
|
|
43
|
+
options: mdeCustomOptions,
|
|
44
|
+
...reactMdeProps
|
|
45
|
+
} = {},
|
|
46
|
+
schemaType
|
|
47
|
+
} = props;
|
|
48
|
+
const client = sanity.useClient({
|
|
49
|
+
apiVersion: "2022-01-01"
|
|
50
|
+
});
|
|
51
|
+
const {
|
|
52
|
+
imageUrl
|
|
53
|
+
} = (_a = schemaType.options) != null ? _a : {};
|
|
54
|
+
const imageUpload = react.useCallback((file, onSuccess, onError) => {
|
|
55
|
+
client.assets.upload("image", file).then(doc => onSuccess(imageUrl ? imageUrl(doc) : "".concat(doc.url, "?w=450"))).catch(e => {
|
|
56
|
+
console.error(e);
|
|
57
|
+
onError(e.message);
|
|
58
|
+
});
|
|
59
|
+
}, [client, imageUrl]);
|
|
60
|
+
const mdeOptions = react.useMemo(() => {
|
|
61
|
+
return {
|
|
62
|
+
autofocus: false,
|
|
63
|
+
spellChecker: false,
|
|
64
|
+
sideBySideFullscreen: false,
|
|
65
|
+
uploadImage: true,
|
|
66
|
+
imageUploadFunction: imageUpload,
|
|
67
|
+
toolbar: defaultMdeTools,
|
|
68
|
+
status: false,
|
|
69
|
+
...mdeCustomOptions
|
|
70
|
+
};
|
|
71
|
+
}, [imageUpload, mdeCustomOptions]);
|
|
72
|
+
const handleChange = react.useCallback(newValue => {
|
|
73
|
+
onChange(sanity.PatchEvent.from(newValue ? sanity.set(newValue) : sanity.unset()));
|
|
74
|
+
}, [onChange]);
|
|
75
|
+
const SimpleMdeReact = useSimpleMdeReact();
|
|
76
|
+
return /* @__PURE__ */jsxRuntime.jsx(MarkdownInputStyles, {
|
|
77
|
+
children: SimpleMdeReact && /* @__PURE__ */jsxRuntime.jsx(react.Suspense, {
|
|
78
|
+
fallback: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
79
|
+
padding: 3,
|
|
80
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
81
|
+
children: "Loading editor..."
|
|
82
|
+
})
|
|
83
|
+
}),
|
|
84
|
+
children: /* @__PURE__ */jsxRuntime.jsx(SimpleMdeReact, {
|
|
85
|
+
...reactMdeProps,
|
|
86
|
+
ref,
|
|
87
|
+
value,
|
|
88
|
+
onChange: handleChange,
|
|
89
|
+
onBlur,
|
|
90
|
+
onFocus,
|
|
91
|
+
options: mdeOptions,
|
|
92
|
+
spellCheck: false
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const markdownTypeName = "markdown";
|
|
98
|
+
const markdownSchemaType = sanity.defineType({
|
|
99
|
+
type: "string",
|
|
100
|
+
name: markdownTypeName,
|
|
101
|
+
title: "Markdown",
|
|
102
|
+
components: {
|
|
103
|
+
input: MarkdownInput
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const markdownSchema = sanity.definePlugin(config => {
|
|
107
|
+
return {
|
|
108
|
+
name: "markdown-editor",
|
|
109
|
+
schema: {
|
|
110
|
+
types: [config && config.input ? {
|
|
111
|
+
...markdownSchemaType,
|
|
112
|
+
components: {
|
|
113
|
+
input: config.input
|
|
114
|
+
}
|
|
115
|
+
} : markdownSchemaType]
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
exports.MarkdownInput = MarkdownInput;
|
|
120
|
+
exports.defaultMdeTools = defaultMdeTools;
|
|
121
|
+
exports.markdownSchema = markdownSchema;
|
|
122
|
+
exports.markdownSchemaType = markdownSchemaType;
|
|
123
|
+
//# sourceMappingURL=plugin-fb6e236d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-fb6e236d.js","sources":["../../src/components/MarkdownInputStyles.tsx","../../src/components/useSimpleMdeReact.tsx","../../src/components/MarkdownInput.tsx","../../src/schema.ts","../../src/plugin.tsx"],"sourcesContent":["import {Box, type Theme} from '@sanity/ui'\nimport styled, {css} from 'styled-components'\n\nexport const MarkdownInputStyles = styled(Box)(({theme}: {theme: Theme}) => {\n return css`\n & .CodeMirror.CodeMirror {\n color: ${theme.sanity.color.card.enabled.fg};\n border-color: ${theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${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.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${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})\n","import {lazy, useEffect, useState} from 'react'\n\nexport const SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nexport function useSimpleMdeReact() {\n const [mounted, setMounted] = useState(false)\n useEffect(() => {\n requestAnimationFrame(() => setMounted(true))\n }, [])\n\n return mounted ? SimpleMdeReact : null\n}\n","import {type Options as EasyMdeOptions} from 'easymde'\nimport React, {Suspense, useCallback, useMemo} 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 {useSimpleMdeReact} from './useSimpleMdeReact'\nimport {Box, Text} from '@sanity/ui'\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},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\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 autofocus: false,\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n }\n }, [imageUpload, mdeCustomOptions])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange]\n )\n\n const SimpleMdeReact = useSimpleMdeReact()\n\n return (\n <MarkdownInputStyles>\n {SimpleMdeReact && (\n <Suspense\n fallback={\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n }\n >\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 )}\n </MarkdownInputStyles>\n )\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":["MarkdownInputStyles","styled","Box","_ref","theme","_a","_b","_c","css","_templateObject","_taggedTemplateLiteral","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","SimpleMdeReact","lazy","useSimpleMdeReact","mounted","setMounted","useState","useEffect","requestAnimationFrame","defaultMdeTools","MarkdownInput","props","value","onChange","elementProps","onBlur","onFocus","ref","reactMdeProps","options","mdeCustomOptions","schemaType","client","useClient","apiVersion","imageUrl","imageUpload","useCallback","file","onSuccess","onError","assets","upload","then","doc","concat","url","catch","e","console","error","message","mdeOptions","useMemo","autofocus","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","handleChange","newValue","PatchEvent","from","set","unset","jsx","children","Suspense","fallback","padding","Text","spellCheck","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","definePlugin","config","schema","types"],"mappings":";;;;;;;;;;;;;;;AAGO,MAAMA,sBAAsBC,eAAAA,CAAAA,OAAO,CAAAC,EAAAA,CAAAA,GAAG,EAAEC,IAAA,IAA6B;EAAA,IAA5B;IAACC;GAA2B,GAAAD,IAAA;EAH5E,IAAAE,EAAA,EAAAC,EAAA,EAAAC,EAAA;E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B,MAAMC,qBAAqBC,MAAAA,CAAAA,UAAW,CAAA;EAC3CC,IAAM,EAAA,QAAA;EACNC,IAAM,EAAAJ,gBAAA;EACNK,KAAO,EAAA,UAAA;EACPC,UAAA,EAAY;IAACC,KAAA,EAAO7D;EAAa;AACnC,CAAC,CAAA;ACLY,MAAA8D,cAAA,GAAiBC,MAAAA,CAAAA,YAAa,CAACC,MAAkC,IAAA;EACrE,OAAA;IACLN,IAAM,EAAA,iBAAA;IACNO,MAAQ,EAAA;MACNC,KAAO,EAAA,CACLF,MAAU,IAAAA,MAAA,CAAOH,KACb,GAAA;QAAC,GAAGN,kBAAA;QAAoBK,UAAY,EAAA;UAACC,KAAO,EAAAG,MAAA,CAAOH;QAAK;MACxD,CAAA,GAAAN,kBAAA;IAER;EAAA,CACF;AACF,CAAC,CAAA;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {JSX as JSX_2} from 'react/jsx-runtime'
|
|
3
2
|
import {Options} from 'easymde'
|
|
4
3
|
import {Plugin as Plugin_2} from 'sanity'
|
|
5
4
|
import {ReactElement} from 'react'
|
|
6
5
|
import {SanityImageAssetDocument} from '@sanity/client'
|
|
7
|
-
import {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
6
|
+
import type {SimpleMDEReactProps} from 'react-simplemde-editor'
|
|
8
7
|
import {StringDefinition} from 'sanity'
|
|
9
8
|
import {StringInputProps} from 'sanity'
|
|
10
9
|
|
|
@@ -57,7 +56,7 @@ export declare interface MarkdownDefinition
|
|
|
57
56
|
options?: MarkdownOptions
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
export declare function MarkdownInput(props: MarkdownInputProps):
|
|
59
|
+
export declare function MarkdownInput(props: MarkdownInputProps): JSX_2.Element
|
|
61
60
|
|
|
62
61
|
export declare interface MarkdownInputProps extends StringInputProps {
|
|
63
62
|
/**
|
package/lib/index.esm.js
CHANGED
|
@@ -1,141 +1,3 @@
|
|
|
1
|
-
const _excluded = ["options"];
|
|
2
|
-
var _templateObject;
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
11
|
-
import { useClient, PatchEvent, set, unset, defineType, definePlugin } from 'sanity';
|
|
12
|
-
import { jsx } from 'react/jsx-runtime';
|
|
13
1
|
import 'easymde/dist/easymde.min.css';
|
|
14
|
-
|
|
15
|
-
import SimpleMdeReact from 'react-simplemde-editor';
|
|
16
|
-
import styled from 'styled-components';
|
|
17
|
-
import { Box } from '@sanity/ui';
|
|
18
|
-
const MarkdownInputStyles = styled(Box)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n & .CodeMirror.CodeMirror {\n color: ", ";\n border-color: ", ";\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ", ";\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ", ";\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .editor-toolbar > * {\n color: ", ";\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ", ";\n }\n\n & .editor-preview {\n background-color: ", ";\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"])), _ref => {
|
|
19
|
-
let {
|
|
20
|
-
theme
|
|
21
|
-
} = _ref;
|
|
22
|
-
return theme.sanity.color.card.enabled.fg;
|
|
23
|
-
}, _ref2 => {
|
|
24
|
-
let {
|
|
25
|
-
theme
|
|
26
|
-
} = _ref2;
|
|
27
|
-
return theme.sanity.color.card.enabled.border;
|
|
28
|
-
}, _ref3 => {
|
|
29
|
-
let {
|
|
30
|
-
theme
|
|
31
|
-
} = _ref3;
|
|
32
|
-
return theme.sanity.color.card.enabled.fg;
|
|
33
|
-
}, _ref4 => {
|
|
34
|
-
let {
|
|
35
|
-
theme
|
|
36
|
-
} = _ref4;
|
|
37
|
-
return theme.sanity.color.card.enabled.border;
|
|
38
|
-
}, _ref5 => {
|
|
39
|
-
let {
|
|
40
|
-
theme
|
|
41
|
-
} = _ref5;
|
|
42
|
-
return theme.sanity.color.selectable.primary.hovered.bg;
|
|
43
|
-
}, _ref6 => {
|
|
44
|
-
let {
|
|
45
|
-
theme
|
|
46
|
-
} = _ref6;
|
|
47
|
-
return theme.sanity.color.card.enabled.bg;
|
|
48
|
-
}, _ref7 => {
|
|
49
|
-
let {
|
|
50
|
-
theme
|
|
51
|
-
} = _ref7;
|
|
52
|
-
return theme.sanity.color.card.enabled.fg;
|
|
53
|
-
}, _ref8 => {
|
|
54
|
-
let {
|
|
55
|
-
theme
|
|
56
|
-
} = _ref8;
|
|
57
|
-
return theme.sanity.color.card.enabled.bg;
|
|
58
|
-
}, _ref9 => {
|
|
59
|
-
let {
|
|
60
|
-
theme
|
|
61
|
-
} = _ref9;
|
|
62
|
-
return theme.sanity.color.card.enabled.bg;
|
|
63
|
-
});
|
|
64
|
-
const defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
65
|
-
function MarkdownInput(props) {
|
|
66
|
-
var _a;
|
|
67
|
-
const {
|
|
68
|
-
value = "",
|
|
69
|
-
onChange,
|
|
70
|
-
elementProps: {
|
|
71
|
-
onBlur,
|
|
72
|
-
onFocus,
|
|
73
|
-
ref
|
|
74
|
-
},
|
|
75
|
-
reactMdeProps: {
|
|
76
|
-
options: mdeCustomOptions
|
|
77
|
-
} = {},
|
|
78
|
-
schemaType
|
|
79
|
-
} = props,
|
|
80
|
-
reactMdeProps = _objectWithoutProperties(props.reactMdeProps, _excluded);
|
|
81
|
-
const client = useClient({
|
|
82
|
-
apiVersion: "2022-01-01"
|
|
83
|
-
});
|
|
84
|
-
const {
|
|
85
|
-
imageUrl
|
|
86
|
-
} = (_a = schemaType.options) != null ? _a : {};
|
|
87
|
-
const imageUpload = useCallback((file, onSuccess, onError) => {
|
|
88
|
-
client.assets.upload("image", file).then(doc => onSuccess(imageUrl ? imageUrl(doc) : "".concat(doc.url, "?w=450"))).catch(e => {
|
|
89
|
-
console.error(e);
|
|
90
|
-
onError(e.message);
|
|
91
|
-
});
|
|
92
|
-
}, [client, imageUrl]);
|
|
93
|
-
const mdeOptions = useMemo(() => {
|
|
94
|
-
return _objectSpread({
|
|
95
|
-
autofocus: false,
|
|
96
|
-
spellChecker: false,
|
|
97
|
-
sideBySideFullscreen: false,
|
|
98
|
-
uploadImage: true,
|
|
99
|
-
imageUploadFunction: imageUpload,
|
|
100
|
-
toolbar: defaultMdeTools,
|
|
101
|
-
status: false
|
|
102
|
-
}, mdeCustomOptions);
|
|
103
|
-
}, [imageUpload, mdeCustomOptions]);
|
|
104
|
-
const handleChange = useCallback(newValue => {
|
|
105
|
-
onChange(PatchEvent.from(newValue ? set(newValue) : unset()));
|
|
106
|
-
}, [onChange]);
|
|
107
|
-
return /* @__PURE__ */jsx(MarkdownInputStyles, {
|
|
108
|
-
children: /* @__PURE__ */jsx(SimpleMdeReact, _objectSpread(_objectSpread({}, reactMdeProps), {}, {
|
|
109
|
-
ref,
|
|
110
|
-
value,
|
|
111
|
-
onChange: handleChange,
|
|
112
|
-
onBlur,
|
|
113
|
-
onFocus,
|
|
114
|
-
options: mdeOptions,
|
|
115
|
-
spellCheck: false
|
|
116
|
-
}))
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
const markdownTypeName = "markdown";
|
|
120
|
-
const markdownSchemaType = defineType({
|
|
121
|
-
type: "string",
|
|
122
|
-
name: markdownTypeName,
|
|
123
|
-
title: "Markdown",
|
|
124
|
-
components: {
|
|
125
|
-
input: MarkdownInput
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
const markdownSchema = definePlugin(config => {
|
|
129
|
-
return {
|
|
130
|
-
name: "markdown-editor",
|
|
131
|
-
schema: {
|
|
132
|
-
types: [config && config.input ? _objectSpread(_objectSpread({}, markdownSchemaType), {}, {
|
|
133
|
-
components: {
|
|
134
|
-
input: config.input
|
|
135
|
-
}
|
|
136
|
-
}) : markdownSchemaType]
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType };
|
|
2
|
+
export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType } from './_chunks/plugin-0fd9aa65.js';
|
|
141
3
|
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/components/MarkdownInputStyles.tsx","../src/components/MarkdownInput.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["import styled from 'styled-components'\nimport {Box} from '@sanity/ui'\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 'easymde/dist/easymde.min.css'\nimport {type Options as EasyMdeOptions} from 'easymde'\nimport React, {useCallback, useMemo} from 'react'\nimport SimpleMdeReact, {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'\nimport {MarkdownOptions} from '../schema'\nimport {MarkdownInputStyles} from './MarkdownInputStyles'\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},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\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 autofocus: false,\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n }\n }, [imageUpload, mdeCustomOptions])\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 <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 </MarkdownInputStyles>\n )\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":["MarkdownInputStyles","styled","Box","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","defaultMdeTools","MarkdownInput","props","_a","value","onChange","elementProps","onBlur","onFocus","ref","reactMdeProps","options","mdeCustomOptions","schemaType","client","useClient","apiVersion","imageUrl","imageUpload","useCallback","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","mdeOptions","useMemo","autofocus","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","handleChange","newValue","PatchEvent","from","set","unset","jsx","children","SimpleMdeReact","spellCheck","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","defin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eAAA;MACTyC,MAAQ,EAAA;IAAA,GACL7B,gBAAA;EACL,CACC,EAAA,CAACM,WAAa,EAAAN,gBAAgB,CAAC,CAAA;EAElC,MAAM8B,YAAe,GAAAvB,WAAA,CAClBwB,QAAqB,IAAA;IACXtC,QAAA,CAAAuC,UAAA,CAAWC,KAAKF,QAAW,GAAAG,GAAA,CAAIH,QAAQ,CAAI,GAAAI,KAAA,EAAO,CAAC,CAAA;EAC9D,CAAA,EACA,CAAC1C,QAAQ,CAAA,CACX;EAEA,OACG,eAAA2C,GAAA,CAAA9D,mBAAA,EAAA;IACC+D,QAAC,EAAA,eAAAD,GAAA,CAAAE,cAAA,kCACKxC,aAAA;MACJD,GAAA;MACAL,KAAA;MACAC,QAAU,EAAAqC,YAAA;MACVnC,MAAA;MACAC,OAAA;MACAG,OAAS,EAAAsB,UAAA;MACTkB,UAAY,EAAA;IAAA;EACd,CACF,CAAA;AAEJ;ACzFO,MAAMC,gBAAmB,GAAA,UAAA;AAsCzB,MAAMC,qBAAqBC,UAAW,CAAA;EAC3CC,IAAM,EAAA,QAAA;EACNC,IAAM,EAAAJ,gBAAA;EACNK,KAAO,EAAA,UAAA;EACPC,UAAA,EAAY;IAACC,KAAA,EAAO1D;EAAa;AACnC,CAAC,CAAA;ACLY,MAAA2D,cAAA,GAAiBC,YAAa,CAACC,MAAkC,IAAA;EACrE,OAAA;IACLN,IAAM,EAAA,iBAAA;IACNO,MAAQ,EAAA;MACNC,KAAO,EAAA,CACLF,MAAU,IAAAA,MAAA,CAAOH,KACb,mCAAIN,kBAAA;QAAoBK,UAAY,EAAA;UAACC,KAAO,EAAAG,MAAA,CAAOH;QAAK;MAAA,KACxDN,kBAAA;IAER;EAAA,CACF;AACF,CAAC,CAAA;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/lib/index.js
CHANGED
|
@@ -1,156 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const _excluded = ["options"];
|
|
4
|
-
var _templateObject;
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
9
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
13
3
|
Object.defineProperty(exports, '__esModule', {
|
|
14
4
|
value: true
|
|
15
5
|
});
|
|
16
|
-
var sanity = require('sanity');
|
|
17
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
18
6
|
require('easymde/dist/easymde.min.css');
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
25
|
-
default: e
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
var SimpleMdeReact__default = /*#__PURE__*/_interopDefaultCompat(SimpleMdeReact);
|
|
29
|
-
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
30
|
-
const MarkdownInputStyles = styled__default.default(ui.Box)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n & .CodeMirror.CodeMirror {\n color: ", ";\n border-color: ", ";\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ", ";\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ", ";\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ", ";\n }\n\n & .editor-toolbar > * {\n color: ", ";\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ", ";\n }\n\n & .editor-preview {\n background-color: ", ";\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"])), _ref => {
|
|
31
|
-
let {
|
|
32
|
-
theme
|
|
33
|
-
} = _ref;
|
|
34
|
-
return theme.sanity.color.card.enabled.fg;
|
|
35
|
-
}, _ref2 => {
|
|
36
|
-
let {
|
|
37
|
-
theme
|
|
38
|
-
} = _ref2;
|
|
39
|
-
return theme.sanity.color.card.enabled.border;
|
|
40
|
-
}, _ref3 => {
|
|
41
|
-
let {
|
|
42
|
-
theme
|
|
43
|
-
} = _ref3;
|
|
44
|
-
return theme.sanity.color.card.enabled.fg;
|
|
45
|
-
}, _ref4 => {
|
|
46
|
-
let {
|
|
47
|
-
theme
|
|
48
|
-
} = _ref4;
|
|
49
|
-
return theme.sanity.color.card.enabled.border;
|
|
50
|
-
}, _ref5 => {
|
|
51
|
-
let {
|
|
52
|
-
theme
|
|
53
|
-
} = _ref5;
|
|
54
|
-
return theme.sanity.color.selectable.primary.hovered.bg;
|
|
55
|
-
}, _ref6 => {
|
|
56
|
-
let {
|
|
57
|
-
theme
|
|
58
|
-
} = _ref6;
|
|
59
|
-
return theme.sanity.color.card.enabled.bg;
|
|
60
|
-
}, _ref7 => {
|
|
61
|
-
let {
|
|
62
|
-
theme
|
|
63
|
-
} = _ref7;
|
|
64
|
-
return theme.sanity.color.card.enabled.fg;
|
|
65
|
-
}, _ref8 => {
|
|
66
|
-
let {
|
|
67
|
-
theme
|
|
68
|
-
} = _ref8;
|
|
69
|
-
return theme.sanity.color.card.enabled.bg;
|
|
70
|
-
}, _ref9 => {
|
|
71
|
-
let {
|
|
72
|
-
theme
|
|
73
|
-
} = _ref9;
|
|
74
|
-
return theme.sanity.color.card.enabled.bg;
|
|
75
|
-
});
|
|
76
|
-
const defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
77
|
-
function MarkdownInput(props) {
|
|
78
|
-
var _a;
|
|
79
|
-
const {
|
|
80
|
-
value = "",
|
|
81
|
-
onChange,
|
|
82
|
-
elementProps: {
|
|
83
|
-
onBlur,
|
|
84
|
-
onFocus,
|
|
85
|
-
ref
|
|
86
|
-
},
|
|
87
|
-
reactMdeProps: {
|
|
88
|
-
options: mdeCustomOptions
|
|
89
|
-
} = {},
|
|
90
|
-
schemaType
|
|
91
|
-
} = props,
|
|
92
|
-
reactMdeProps = _objectWithoutProperties(props.reactMdeProps, _excluded);
|
|
93
|
-
const client = sanity.useClient({
|
|
94
|
-
apiVersion: "2022-01-01"
|
|
95
|
-
});
|
|
96
|
-
const {
|
|
97
|
-
imageUrl
|
|
98
|
-
} = (_a = schemaType.options) != null ? _a : {};
|
|
99
|
-
const imageUpload = react.useCallback((file, onSuccess, onError) => {
|
|
100
|
-
client.assets.upload("image", file).then(doc => onSuccess(imageUrl ? imageUrl(doc) : "".concat(doc.url, "?w=450"))).catch(e => {
|
|
101
|
-
console.error(e);
|
|
102
|
-
onError(e.message);
|
|
103
|
-
});
|
|
104
|
-
}, [client, imageUrl]);
|
|
105
|
-
const mdeOptions = react.useMemo(() => {
|
|
106
|
-
return _objectSpread({
|
|
107
|
-
autofocus: false,
|
|
108
|
-
spellChecker: false,
|
|
109
|
-
sideBySideFullscreen: false,
|
|
110
|
-
uploadImage: true,
|
|
111
|
-
imageUploadFunction: imageUpload,
|
|
112
|
-
toolbar: defaultMdeTools,
|
|
113
|
-
status: false
|
|
114
|
-
}, mdeCustomOptions);
|
|
115
|
-
}, [imageUpload, mdeCustomOptions]);
|
|
116
|
-
const handleChange = react.useCallback(newValue => {
|
|
117
|
-
onChange(sanity.PatchEvent.from(newValue ? sanity.set(newValue) : sanity.unset()));
|
|
118
|
-
}, [onChange]);
|
|
119
|
-
return /* @__PURE__ */jsxRuntime.jsx(MarkdownInputStyles, {
|
|
120
|
-
children: /* @__PURE__ */jsxRuntime.jsx(SimpleMdeReact__default.default, _objectSpread(_objectSpread({}, reactMdeProps), {}, {
|
|
121
|
-
ref,
|
|
122
|
-
value,
|
|
123
|
-
onChange: handleChange,
|
|
124
|
-
onBlur,
|
|
125
|
-
onFocus,
|
|
126
|
-
options: mdeOptions,
|
|
127
|
-
spellCheck: false
|
|
128
|
-
}))
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
const markdownTypeName = "markdown";
|
|
132
|
-
const markdownSchemaType = sanity.defineType({
|
|
133
|
-
type: "string",
|
|
134
|
-
name: markdownTypeName,
|
|
135
|
-
title: "Markdown",
|
|
136
|
-
components: {
|
|
137
|
-
input: MarkdownInput
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const markdownSchema = sanity.definePlugin(config => {
|
|
141
|
-
return {
|
|
142
|
-
name: "markdown-editor",
|
|
143
|
-
schema: {
|
|
144
|
-
types: [config && config.input ? _objectSpread(_objectSpread({}, markdownSchemaType), {}, {
|
|
145
|
-
components: {
|
|
146
|
-
input: config.input
|
|
147
|
-
}
|
|
148
|
-
}) : markdownSchemaType]
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
exports.MarkdownInput = MarkdownInput;
|
|
153
|
-
exports.defaultMdeTools = defaultMdeTools;
|
|
154
|
-
exports.markdownSchema = markdownSchema;
|
|
155
|
-
exports.markdownSchemaType = markdownSchemaType;
|
|
7
|
+
var plugin = require('./_chunks/plugin-fb6e236d.js');
|
|
8
|
+
exports.MarkdownInput = plugin.MarkdownInput;
|
|
9
|
+
exports.defaultMdeTools = plugin.defaultMdeTools;
|
|
10
|
+
exports.markdownSchema = plugin.markdownSchema;
|
|
11
|
+
exports.markdownSchemaType = plugin.markdownSchemaType;
|
|
156
12
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/components/MarkdownInputStyles.tsx","../src/components/MarkdownInput.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["import styled from 'styled-components'\nimport {Box} from '@sanity/ui'\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 'easymde/dist/easymde.min.css'\nimport {type Options as EasyMdeOptions} from 'easymde'\nimport React, {useCallback, useMemo} from 'react'\nimport SimpleMdeReact, {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'\nimport {MarkdownOptions} from '../schema'\nimport {MarkdownInputStyles} from './MarkdownInputStyles'\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},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\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 autofocus: false,\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n }\n }, [imageUpload, mdeCustomOptions])\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 <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 </MarkdownInputStyles>\n )\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":["MarkdownInputStyles","styled","Box","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","defaultMdeTools","MarkdownInput","props","_a","value","onChange","elementProps","onBlur","onFocus","ref","reactMdeProps","options","mdeCustomOptions","schemaType","client","useClient","apiVersion","imageUrl","imageUpload","useCallback","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","mdeOptions","useMemo","autofocus","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","handleChange","newValue","PatchEvent","from","set","unset","jsx","children","SimpleMdeReact","spellCheck","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","definePlugin","config","schema","types"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGa,MAAAA,mBAAA,GAAsBC,eAAAA,CAAAA,QAAOC,EAAAA,CAAAA,GAAG,CAAA,giCAEhC;EAAA,IAAC;IAACC;EAAK,CAAA;EAAA,OAAMA,MAAMC,MAAO,CAAAC,KAAA,CAAMC,KAAKC,OAAQ,CAAAC,EAAA;AAAA,GACtC;EAAA,IAAC;IAACL;EAAK,CAAA;EAAA,OAAMA,MAAMC,MAAO,CAAAC,KAAA,CAAMC,KAAKC,OAAQ,CAAAE,MAAA;AAAA,GAK7C;EAAA,IAAC;IAACN;EAAK,CAAA;EAAA,OAAMA,MAAMC,MAAO,CAAAC,KAAA,CAAMC,KAAKC,OAAQ,CAAAC,EAAA;AAAA,GAK7C;EAAA,IAAC;IAACL;EAAK,CAAA;EAAA,OAAMA,MAAMC,MAAO,CAAAC,KAAA,CAAMC,KAAKC,OAAQ,CAAAE,MAAA;AAAA,GAIzC;EAAA,IAAC;IAACN;EAAK,CAAA;EAAA,OAAMA,MAAMC,MAAO,CAAAC,KAAA,CAAMK,UAAW,CAAAC,OAAA,CAAQC,OAAQ,CAAAC,EAAA;AAAA,GAI3D;EAAA,IAAC;IAACV;EAAK,CAAA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,qBAAqBC,MAAAA,CAAAA,UAAW,CAAA;EAC3CC,IAAM,EAAA,QAAA;EACNC,IAAM,EAAAJ,gBAAA;EACNK,KAAO,EAAA,UAAA;EACPC,UAAA,EAAY;IAACC,KAAA,EAAO1D;EAAa;AACnC,CAAC,CAAA;ACLY,MAAA2D,cAAA,GAAiBC,MAAAA,CAAAA,YAAa,CAACC,MAAkC,IAAA;EACrE,OAAA;IACLN,IAAM,EAAA,iBAAA;IACNO,MAAQ,EAAA;MACNC,KAAO,EAAA,CACLF,MAAU,IAAAA,MAAA,CAAOH,KACb,mCAAIN,kBAAA;QAAoBK,UAAY,EAAA;UAACC,KAAO,EAAAG,MAAA,CAAOH;QAAK;MAAA,KACxDN,kBAAA;IAER;EAAA,CACF;AACF,CAAC,CAAA;;;;"}
|
|
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-fb6e236d.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": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -23,16 +23,30 @@
|
|
|
23
23
|
".": {
|
|
24
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
42
|
"types": "./lib/index.d.ts",
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
"next": [
|
|
46
|
+
"./lib/index.d.ts"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
36
50
|
"files": [
|
|
37
51
|
"lib",
|
|
38
52
|
"sanity.json",
|
|
@@ -59,8 +73,8 @@
|
|
|
59
73
|
"devDependencies": {
|
|
60
74
|
"@commitlint/cli": "^17.2.0",
|
|
61
75
|
"@commitlint/config-conventional": "^17.2.0",
|
|
62
|
-
"@sanity/pkg-utils": "^2.
|
|
63
|
-
"@sanity/plugin-kit": "^3.1.
|
|
76
|
+
"@sanity/pkg-utils": "^2.2.6",
|
|
77
|
+
"@sanity/plugin-kit": "^3.1.7",
|
|
64
78
|
"@sanity/semantic-release-preset": "^2.0.2",
|
|
65
79
|
"@types/react": "^18.0.26",
|
|
66
80
|
"@types/styled-components": "^5.1.26",
|
|
@@ -81,10 +95,10 @@
|
|
|
81
95
|
"react": "^18.2.0",
|
|
82
96
|
"react-dom": "^18.2.0",
|
|
83
97
|
"react-is": "^18.2.0",
|
|
84
|
-
"rimraf": "^
|
|
98
|
+
"rimraf": "^5.0.0",
|
|
85
99
|
"sanity": "^3.1.4",
|
|
86
100
|
"styled-components": "^5.3.6",
|
|
87
|
-
"typescript": "^
|
|
101
|
+
"typescript": "^5.0.0"
|
|
88
102
|
},
|
|
89
103
|
"peerDependencies": {
|
|
90
104
|
"easymde": "^2",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import 'easymde/dist/easymde.min.css'
|
|
2
1
|
import {type Options as EasyMdeOptions} from 'easymde'
|
|
3
|
-
import React, {useCallback, useMemo} from 'react'
|
|
4
|
-
import
|
|
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
5
|
import {PatchEvent, set, StringInputProps, unset, useClient} from 'sanity'
|
|
6
6
|
import {MarkdownOptions} from '../schema'
|
|
7
7
|
import {MarkdownInputStyles} from './MarkdownInputStyles'
|
|
8
|
+
import {useSimpleMdeReact} from './useSimpleMdeReact'
|
|
9
|
+
import {Box, Text} from '@sanity/ui'
|
|
8
10
|
|
|
9
11
|
export interface MarkdownInputProps extends StringInputProps {
|
|
10
12
|
/**
|
|
@@ -77,18 +79,30 @@ export function MarkdownInput(props: MarkdownInputProps) {
|
|
|
77
79
|
[onChange]
|
|
78
80
|
)
|
|
79
81
|
|
|
82
|
+
const SimpleMdeReact = useSimpleMdeReact()
|
|
83
|
+
|
|
80
84
|
return (
|
|
81
85
|
<MarkdownInputStyles>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
)}
|
|
92
106
|
</MarkdownInputStyles>
|
|
93
107
|
)
|
|
94
108
|
}
|
|
@@ -1,61 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export const MarkdownInputStyles = styled(Box)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
import {Box, type Theme} from '@sanity/ui'
|
|
2
|
+
import styled, {css} from 'styled-components'
|
|
3
|
+
|
|
4
|
+
export const MarkdownInputStyles = styled(Box)(({theme}: {theme: Theme}) => {
|
|
5
|
+
return css`
|
|
6
|
+
& .CodeMirror.CodeMirror {
|
|
7
|
+
color: ${theme.sanity.color.card.enabled.fg};
|
|
8
|
+
border-color: ${theme.sanity.color.card.enabled.border};
|
|
9
|
+
background-color: inherit;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
& .cm-s-easymde .CodeMirror-cursor {
|
|
13
|
+
border-color: ${theme.sanity.color.card.enabled.fg};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
& .editor-toolbar,
|
|
17
|
+
.editor-preview-side {
|
|
18
|
+
border-color: ${theme.sanity.color.card.enabled.border};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
& .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
22
|
+
background-color: ${theme.sanity.color.selectable?.primary?.hovered?.bg};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
& .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
|
|
26
|
+
background-color: ${theme.sanity.color.card.enabled.bg};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
& .editor-toolbar > * {
|
|
30
|
+
color: ${theme.sanity.color.card.enabled.fg};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
& .editor-toolbar > .active,
|
|
34
|
+
.editor-toolbar > button:hover,
|
|
35
|
+
.editor-preview pre,
|
|
36
|
+
.cm-s-easymde .cm-comment {
|
|
37
|
+
background-color: ${theme.sanity.color.card.enabled.bg};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
& .editor-preview {
|
|
41
|
+
background-color: ${theme.sanity.color.card.enabled.bg};
|
|
42
|
+
|
|
43
|
+
& h1,
|
|
44
|
+
h2,
|
|
45
|
+
h3,
|
|
46
|
+
h4,
|
|
47
|
+
h5,
|
|
48
|
+
h6 {
|
|
49
|
+
font-size: revert;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
& ul,
|
|
53
|
+
li {
|
|
54
|
+
list-style: revert;
|
|
55
|
+
padding: revert;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
& a {
|
|
59
|
+
text-decoration: revert;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`
|
|
63
|
+
})
|
|
@@ -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,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export {MarkdownInput, defaultMdeTools, type MarkdownInputProps} from './components/MarkdownInput'
|
|
1
|
+
import 'easymde/dist/easymde.min.css'
|
|
3
2
|
|
|
4
|
-
export
|
|
3
|
+
export * from './commonExports'
|
package/src/indexNext.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './commonExports'
|