sanity-plugin-markdown 8.0.4-canary.1 → 8.0.4
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/dist/index.cjs +141 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +161 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.js +2 -119
- package/dist/index.js.map +1 -1
- package/dist/indexNext.js +119 -1
- package/dist/indexNext.js.map +1 -1
- package/package.json +7 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
+
require("easymde/dist/easymde.min.css");
|
|
23
|
+
var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), compilerRuntime = require("react/compiler-runtime"), ui = require("@sanity/ui"), react = require("react"), styledComponents = require("styled-components");
|
|
24
|
+
const SimpleMdeReact = react.lazy(() => import("react-simplemde-editor")), MarkdownInputStyles = styledComponents.styled(ui.Box).withConfig({
|
|
25
|
+
displayName: "MarkdownInputStyles",
|
|
26
|
+
componentId: "sc-syau23-0"
|
|
27
|
+
})`& .CodeMirror.CodeMirror{color:${({
|
|
28
|
+
theme
|
|
29
|
+
}) => theme.sanity.color.card.enabled.fg};border-color:${({
|
|
30
|
+
theme
|
|
31
|
+
}) => theme.sanity.color.card.enabled.border};background-color:inherit;}& .cm-s-easymde .CodeMirror-cursor{border-color:${({
|
|
32
|
+
theme
|
|
33
|
+
}) => theme.sanity.color.card.enabled.fg};}& .editor-toolbar,.editor-preview-side{border-color:${({
|
|
34
|
+
theme
|
|
35
|
+
}) => theme.sanity.color.card.enabled.border};}& .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected{background-color:${({
|
|
36
|
+
theme
|
|
37
|
+
}) => theme.sanity.color.selectable?.primary?.hovered?.bg};}& .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected{background-color:${({
|
|
38
|
+
theme
|
|
39
|
+
}) => theme.sanity.color.card.enabled.bg};}& .editor-toolbar > *{color:${({
|
|
40
|
+
theme
|
|
41
|
+
}) => theme.sanity.color.card.enabled.fg};}& .editor-toolbar > .active,.editor-toolbar > button:hover,.editor-preview pre,.cm-s-easymde .cm-comment{background-color:${({
|
|
42
|
+
theme
|
|
43
|
+
}) => theme.sanity.color.card.enabled.bg};}& .editor-preview{background-color:${({
|
|
44
|
+
theme
|
|
45
|
+
}) => theme.sanity.color.card.enabled.bg};& h1,h2,h3,h4,h5,h6{font-size:revert;}& ul,li{list-style:revert;padding:revert;}& a{text-decoration:revert;}}`, defaultMdeTools = ["heading", "bold", "italic", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "|", "preview", "side-by-side"];
|
|
46
|
+
function MarkdownInput(props) {
|
|
47
|
+
const $ = compilerRuntime.c(29), {
|
|
48
|
+
value: t0,
|
|
49
|
+
onChange,
|
|
50
|
+
elementProps: t1,
|
|
51
|
+
reactMdeProps: t2,
|
|
52
|
+
schemaType,
|
|
53
|
+
focused
|
|
54
|
+
} = props, value = t0 === void 0 ? "" : t0, {
|
|
55
|
+
onBlur,
|
|
56
|
+
onFocus,
|
|
57
|
+
ref: elementRef
|
|
58
|
+
} = t1;
|
|
59
|
+
let t3;
|
|
60
|
+
$[0] !== t2 ? (t3 = t2 === void 0 ? {} : t2, $[0] = t2, $[1] = t3) : t3 = $[1];
|
|
61
|
+
let mdeCustomOptions, reactMdeProps;
|
|
62
|
+
$[2] !== t3 ? ({
|
|
63
|
+
options: mdeCustomOptions,
|
|
64
|
+
...reactMdeProps
|
|
65
|
+
} = t3, $[2] = t3, $[3] = mdeCustomOptions, $[4] = reactMdeProps) : (mdeCustomOptions = $[3], reactMdeProps = $[4]);
|
|
66
|
+
let t4;
|
|
67
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
|
|
68
|
+
apiVersion: "2022-01-01"
|
|
69
|
+
}, $[5] = t4) : t4 = $[5];
|
|
70
|
+
const client = sanity.useClient(t4);
|
|
71
|
+
let t5;
|
|
72
|
+
$[6] !== schemaType.options ? (t5 = schemaType.options ?? {}, $[6] = schemaType.options, $[7] = t5) : t5 = $[7];
|
|
73
|
+
const {
|
|
74
|
+
imageUrl
|
|
75
|
+
} = t5, [shouldAutoFocus, setShouldAutoFocus] = react.useState(!1), ref = react.useRef(null);
|
|
76
|
+
let t6;
|
|
77
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = () => ref.current, $[8] = t6) : t6 = $[8], react.useImperativeHandle(elementRef, t6);
|
|
78
|
+
let t7;
|
|
79
|
+
$[9] !== client || $[10] !== imageUrl ? (t7 = (file, onSuccess, onError) => {
|
|
80
|
+
client.assets.upload("image", file).then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`)).catch((e) => {
|
|
81
|
+
console.error(e), onError(e.message);
|
|
82
|
+
});
|
|
83
|
+
}, $[9] = client, $[10] = imageUrl, $[11] = t7) : t7 = $[11];
|
|
84
|
+
const imageUpload = t7;
|
|
85
|
+
let t8;
|
|
86
|
+
$[12] !== imageUpload || $[13] !== mdeCustomOptions || $[14] !== shouldAutoFocus ? (t8 = {
|
|
87
|
+
spellChecker: !1,
|
|
88
|
+
sideBySideFullscreen: !1,
|
|
89
|
+
uploadImage: !0,
|
|
90
|
+
imageUploadFunction: imageUpload,
|
|
91
|
+
toolbar: defaultMdeTools,
|
|
92
|
+
status: !1,
|
|
93
|
+
...mdeCustomOptions,
|
|
94
|
+
autofocus: shouldAutoFocus
|
|
95
|
+
}, $[12] = imageUpload, $[13] = mdeCustomOptions, $[14] = shouldAutoFocus, $[15] = t8) : t8 = $[15];
|
|
96
|
+
const mdeOptions = t8;
|
|
97
|
+
let t10, t9;
|
|
98
|
+
$[16] !== focused || $[17] !== shouldAutoFocus ? (t9 = () => {
|
|
99
|
+
const node = ref.current;
|
|
100
|
+
if (node) {
|
|
101
|
+
if (focused && !shouldAutoFocus) {
|
|
102
|
+
const raf = requestAnimationFrame(() => setShouldAutoFocus(!node.contains(document.activeElement)));
|
|
103
|
+
return () => cancelAnimationFrame(raf);
|
|
104
|
+
}
|
|
105
|
+
if (!focused && shouldAutoFocus) {
|
|
106
|
+
const raf_0 = requestAnimationFrame(() => setShouldAutoFocus(node.contains(document.activeElement)));
|
|
107
|
+
return () => cancelAnimationFrame(raf_0);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, t10 = [focused, shouldAutoFocus], $[16] = focused, $[17] = shouldAutoFocus, $[18] = t10, $[19] = t9) : (t10 = $[18], t9 = $[19]), react.useEffect(t9, t10);
|
|
111
|
+
let t11;
|
|
112
|
+
$[20] !== onChange ? (t11 = (newValue) => {
|
|
113
|
+
onChange(sanity.PatchEvent.from(newValue ? sanity.set(newValue) : sanity.unset()));
|
|
114
|
+
}, $[20] = onChange, $[21] = t11) : t11 = $[21];
|
|
115
|
+
const handleChange = t11;
|
|
116
|
+
let t12;
|
|
117
|
+
return $[22] !== handleChange || $[23] !== mdeOptions || $[24] !== onBlur || $[25] !== onFocus || $[26] !== reactMdeProps || $[27] !== value ? (t12 = /* @__PURE__ */ jsxRuntime.jsx(MarkdownInputStyles, { children: /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.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;
|
|
118
|
+
}
|
|
119
|
+
const fallback = /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading editor..." }) }), markdownTypeName = "markdown", markdownSchemaType = sanity.defineType({
|
|
120
|
+
type: "string",
|
|
121
|
+
name: markdownTypeName,
|
|
122
|
+
title: "Markdown",
|
|
123
|
+
components: {
|
|
124
|
+
input: MarkdownInput
|
|
125
|
+
}
|
|
126
|
+
}), markdownSchema = sanity.definePlugin((config) => ({
|
|
127
|
+
name: "markdown-editor",
|
|
128
|
+
schema: {
|
|
129
|
+
types: [config && config.input ? {
|
|
130
|
+
...markdownSchemaType,
|
|
131
|
+
components: {
|
|
132
|
+
input: config.input
|
|
133
|
+
}
|
|
134
|
+
} : markdownSchemaType]
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
exports.MarkdownInput = MarkdownInput;
|
|
138
|
+
exports.defaultMdeTools = defaultMdeTools;
|
|
139
|
+
exports.markdownSchema = markdownSchema;
|
|
140
|
+
exports.markdownSchemaType = markdownSchemaType;
|
|
141
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","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 // oxlint-disable-next-line no-unsafe-type-assertion\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'\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 Plugin, 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: Plugin<MarkdownConfig | void> = definePlugin(\n (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)\n"],"names":["SimpleMdeReact","lazy","MarkdownInputStyles","styled","Box","withConfig","displayName","componentId","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","for","apiVersion","client","useClient","t5","imageUrl","shouldAutoFocus","setShouldAutoFocus","useState","useRef","t6","Symbol","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","jsx","Suspense","fallback","Text","markdownTypeName","markdownSchemaType","defineType","type","name","title","components","input","markdownSchema","definePlugin","config","schema","types"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAMA,iBAAiBC,MAAAA,KAAK,MAAM,OAAO,wBAAwB,CAAC,GAE5DC,sBAAsBC,iBAAAA,OAAOC,MAAG,EAACC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,mCAE1B,CAAC;AAAA,EAACC;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,EAAE,iBACxC,CAAC;AAAA,EAACL;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQE,MAAM,8EAKnD,CAAC;AAAA,EAACN;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,EAAE,yDAK/C,CAAC;AAAA,EAACL;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQE,MAAM,yGAI/C,CAAC;AAAA,EAACN;AAAK,MAAMA,MAAMC,OAAOC,MAAMK,YAAYC,SAASC,SAASC,EAAE,qFAIhE,CAAC;AAAA,EAACV;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQM,EAAE,iCAI1D,CAAC;AAAA,EAACV;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,EAAE,+HAOpC,CAAC;AAAA,EAACL;AAAK,MAAMA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQM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YAAAzD,QAAAY,QAAAZ,QAAAa,SAAAb,QAAAO,eAAAP,QAAAE,OAAAF,QAAA4E,OAAAA,MAAA5E,EAAA,EAAA,GAbtB4E;AAasB;AAI1B,MAAMG,0CACHjG,GAAAA,KAAA,EAAI,SAAS,GACZ,UAAA+F,2BAAAA,IAACG,GAAAA,MAAA,EAAK,+BAAiB,EAAA,CACzB,GCrMWC,mBAAmB,YAsCnBC,qBAAqBC,kBAAW;AAAA,EAC3CC,MAAM;AAAA,EACNC,MAAMJ;AAAAA,EACNK,OAAO;AAAA,EACPC,YAAY;AAAA,IAACC,OAAO1F;AAAAA,EAAAA;AACtB,CAAC,GCPY2F,iBAAgDC,OAAAA,aAC1DC,CAAAA,YACQ;AAAA,EACLN,MAAM;AAAA,EACNO,QAAQ;AAAA,IACNC,OAAO,CACLF,UAAUA,OAAOH,QACb;AAAA,MAAC,GAAGN;AAAAA,MAAoBK,YAAY;AAAA,QAACC,OAAOG,OAAOH;AAAAA,MAAAA;AAAAA,IAAK,IACxDN,kBAAkB;AAAA,EAAA;AAG5B,EAEJ;;;;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Plugin, StringDefinition, StringInputProps } from "sanity";
|
|
2
|
+
import { SimpleMDEReactProps } from "react-simplemde-editor";
|
|
3
|
+
import { Options } from "easymde";
|
|
4
|
+
/**
|
|
5
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
declare type Any = any;
|
|
9
|
+
/** @internal */
|
|
10
|
+
declare interface SanityAssetDocument extends SanityDocument {
|
|
11
|
+
url: string;
|
|
12
|
+
path: string;
|
|
13
|
+
size: number;
|
|
14
|
+
assetId: string;
|
|
15
|
+
mimeType: string;
|
|
16
|
+
sha1hash: string;
|
|
17
|
+
extension: string;
|
|
18
|
+
uploadId?: string;
|
|
19
|
+
originalFilename?: string;
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = { [P in keyof T]: T[P] } & {
|
|
23
|
+
_id: string;
|
|
24
|
+
_rev: string;
|
|
25
|
+
_type: string;
|
|
26
|
+
_createdAt: string;
|
|
27
|
+
_updatedAt: string;
|
|
28
|
+
/**
|
|
29
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
30
|
+
*/
|
|
31
|
+
_originalId?: string;
|
|
32
|
+
};
|
|
33
|
+
/** @internal */
|
|
34
|
+
declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
35
|
+
metadata: {
|
|
36
|
+
_type: 'sanity.imageMetadata';
|
|
37
|
+
hasAlpha: boolean;
|
|
38
|
+
isOpaque: boolean;
|
|
39
|
+
lqip?: string;
|
|
40
|
+
blurHash?: string;
|
|
41
|
+
dimensions: {
|
|
42
|
+
_type: 'sanity.imageDimensions';
|
|
43
|
+
aspectRatio: number;
|
|
44
|
+
height: number;
|
|
45
|
+
width: number;
|
|
46
|
+
};
|
|
47
|
+
palette?: {
|
|
48
|
+
_type: 'sanity.imagePalette';
|
|
49
|
+
darkMuted?: SanityImagePalette;
|
|
50
|
+
darkVibrant?: SanityImagePalette;
|
|
51
|
+
dominant?: SanityImagePalette;
|
|
52
|
+
lightMuted?: SanityImagePalette;
|
|
53
|
+
lightVibrant?: SanityImagePalette;
|
|
54
|
+
muted?: SanityImagePalette;
|
|
55
|
+
vibrant?: SanityImagePalette;
|
|
56
|
+
};
|
|
57
|
+
image?: {
|
|
58
|
+
_type: 'sanity.imageExifTags';
|
|
59
|
+
[key: string]: Any;
|
|
60
|
+
};
|
|
61
|
+
exif?: {
|
|
62
|
+
_type: 'sanity.imageExifMetadata';
|
|
63
|
+
[key: string]: Any;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
declare interface SanityImagePalette {
|
|
69
|
+
background: string;
|
|
70
|
+
foreground: string;
|
|
71
|
+
population: number;
|
|
72
|
+
title: string;
|
|
73
|
+
}
|
|
74
|
+
declare const markdownTypeName = "markdown";
|
|
75
|
+
interface MarkdownOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Used to create image url for any uploaded image.
|
|
78
|
+
* The function will be invoked whenever an image is pasted or dragged into the
|
|
79
|
+
* markdown editor, after upload completes.
|
|
80
|
+
*
|
|
81
|
+
* The default implementation uses
|
|
82
|
+
* ```js
|
|
83
|
+
* imageAsset => `${imageAsset.url}?w=450`
|
|
84
|
+
* ```
|
|
85
|
+
* ## Example
|
|
86
|
+
* ```js
|
|
87
|
+
* {
|
|
88
|
+
* imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
* @param imageAsset
|
|
92
|
+
*/
|
|
93
|
+
imageUrl?: (imageAsset: SanityImageAssetDocument) => string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
99
|
+
type: typeof markdownTypeName;
|
|
100
|
+
options?: MarkdownOptions;
|
|
101
|
+
}
|
|
102
|
+
declare module 'sanity' {
|
|
103
|
+
interface IntrinsicDefinitions {
|
|
104
|
+
markdown: MarkdownDefinition;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
declare const markdownSchemaType: {
|
|
108
|
+
type: "string";
|
|
109
|
+
name: "markdown";
|
|
110
|
+
} & Omit<StringDefinition, "preview">;
|
|
111
|
+
interface MarkdownInputProps extends StringInputProps {
|
|
112
|
+
/**
|
|
113
|
+
* These are passed along directly to
|
|
114
|
+
*
|
|
115
|
+
* Note: MarkdownInput sets certain reactMdeProps.options by default.
|
|
116
|
+
* These will be merged with any custom options.
|
|
117
|
+
*/
|
|
118
|
+
reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>;
|
|
119
|
+
}
|
|
120
|
+
declare const defaultMdeTools: Options['toolbar'];
|
|
121
|
+
declare function MarkdownInput(props: MarkdownInputProps): React.JSX.Element;
|
|
122
|
+
interface MarkdownConfig {
|
|
123
|
+
/**
|
|
124
|
+
* When provided, will replace the default input component.
|
|
125
|
+
*
|
|
126
|
+
* Use this to customize MarkdownInput by wrapping it in a custom component,
|
|
127
|
+
* and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
128
|
+
* via the `reactMdeProps` prop.
|
|
129
|
+
*
|
|
130
|
+
* ### Example
|
|
131
|
+
*
|
|
132
|
+
* ```tsx
|
|
133
|
+
* // CustomMarkdownInput.tsx
|
|
134
|
+
* import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'
|
|
135
|
+
*
|
|
136
|
+
* export function CustomMarkdownInput(props) {
|
|
137
|
+
* const reactMdeProps: MarkdownInputProps['reactMdeProps'] =
|
|
138
|
+
* useMemo(() => {
|
|
139
|
+
* return {
|
|
140
|
+
* options: {
|
|
141
|
+
* toolbar: ['bold', 'italic'],
|
|
142
|
+
* // more options available, see:
|
|
143
|
+
* // https://github.com/Ionaru/easy-markdown-editor#options-list
|
|
144
|
+
* },
|
|
145
|
+
* // more props available, see:
|
|
146
|
+
* // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
|
|
147
|
+
* }
|
|
148
|
+
* }, [])
|
|
149
|
+
*
|
|
150
|
+
* return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* // studio.config.ts
|
|
154
|
+
* markdownSchema({input: CustomMarkdownInput})
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
input?: (props: StringInputProps) => React.ReactElement;
|
|
158
|
+
}
|
|
159
|
+
declare const markdownSchema: Plugin<MarkdownConfig | void>;
|
|
160
|
+
export { type MarkdownConfig, type MarkdownDefinition, MarkdownInput, type MarkdownInputProps, defaultMdeTools, markdownSchema, markdownSchemaType };
|
|
161
|
+
//# sourceMappingURL=index.d.cts.map
|