sanity-plugin-markdown 3.0.0-v3-studio.1 → 3.0.0-v3-studio.3
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/lib/index.d.ts +17 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +21 -16
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +18 -14
- package/lib/index.modern.js.map +1 -1
- package/package.json +13 -13
- package/src/components/Editor.tsx +8 -5
- package/src/index.ts +5 -12
- package/src/schema.ts +27 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { StringDefinition } from "sanity";
|
|
2
|
+
declare const markdownTypeName: "markdown";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
7
|
+
type: typeof markdownTypeName;
|
|
8
|
+
}
|
|
9
|
+
declare module '@sanity/types' {
|
|
10
|
+
interface IntrinsicDefinitions {
|
|
11
|
+
markdown: MarkdownDefinition;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export const markdownSchemaType: {
|
|
15
|
+
type: "string";
|
|
16
|
+
name: "markdown";
|
|
17
|
+
} & Omit<StringDefinition, "preview">;
|
|
1
18
|
export const MarkdownEditor: import("react").ForwardRefExoticComponent<import("sanity").StringInputProps<import("sanity").StringSchemaType> & import("react").RefAttributes<any>>;
|
|
2
19
|
export const markdownSchema: import("sanity").Plugin<void>;
|
|
3
20
|
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";AEGA,QAAA,MAAM,4BAAsC,CAAA;AAE5C;;GAEG;AACH,mCAAoC,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC/F,IAAI,EAAE,uBAAuB,CAAA;CAC9B;AAED,eAAe,eAAe,CAAC;IAE7B,UAAiB,oBAAoB;QACnC,QAAQ,EAAE,kBAAkB,CAAA;KAC7B;CACF;AAED,OAAO,MAAM;;;qCAOX,CAAA;ACrBF,OAAA,MAAM,oKAAuB,CAAA;AAK7B,OAAO,MAAM,6CAKX,CAAA","sources":["src/src/hooks/useDebounce.ts","src/src/components/Editor.tsx","src/src/schema.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,"import {MarkdownEditor as Editor} from './components/Editor'\nimport {createPlugin} from 'sanity'\nimport {markdownSchemaType, MarkdownDefinition} from './schema'\n\n// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:\nconst MarkdownEditor = Editor\n\nexport {MarkdownEditor, markdownSchemaType}\nexport type {MarkdownDefinition}\n\nexport const markdownSchema = createPlugin({\n name: 'markdown-editor',\n schema: {\n types: [markdownSchemaType],\n },\n})\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var $3KLdq$sanity = require("sanity");
|
|
2
2
|
var $3KLdq$reactjsxruntime = require("react/jsx-runtime");
|
|
3
3
|
var $3KLdq$uiwreactmdeditor = require("@uiw/react-md-editor");
|
|
4
|
-
var $3KLdq$sanityform = require("sanity/form");
|
|
5
4
|
var $3KLdq$react = require("react");
|
|
6
5
|
var $3KLdq$sanityui = require("@sanity/ui");
|
|
7
6
|
var $3KLdq$rehypesanitize = require("rehype-sanitize");
|
|
@@ -15,6 +14,7 @@ function $parcel$interopDefault(a) {
|
|
|
15
14
|
|
|
16
15
|
$parcel$export(module.exports, "MarkdownEditor", () => $244e63ca53592e4d$export$18a9461578883ec4);
|
|
17
16
|
$parcel$export(module.exports, "markdownSchema", () => $244e63ca53592e4d$export$f225414958dd8925);
|
|
17
|
+
$parcel$export(module.exports, "markdownSchemaType", () => $83686b2c306f69a9$export$244155b8997cef98);
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
@@ -38,21 +38,21 @@ function $84fd43422be26bd7$export$2e2bcd8739ae039(value, delay) {
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
const $067e75d167fd097d$export$18a9461578883ec4 = /*#__PURE__*/ (0, $3KLdq$react.forwardRef)(function MarkdownEditor(props, ref) {
|
|
41
|
-
const { value: value = "" ,
|
|
41
|
+
const { value: value = "" , onChange: onChange , elementProps: { onBlur: onBlur , onFocus: onFocus } , readOnly: readOnly , } = props;
|
|
42
42
|
const [editedValue, setEditedValue] = (0, $3KLdq$react.useState)(value);
|
|
43
43
|
const debouncedValue = (0, $84fd43422be26bd7$export$2e2bcd8739ae039)(editedValue, 100);
|
|
44
|
-
// const
|
|
44
|
+
// const client = useClient({apiVersion: '2021-03-25'})
|
|
45
45
|
(0, $3KLdq$react.useEffect)(()=>{
|
|
46
46
|
setEditedValue(value);
|
|
47
47
|
}, [
|
|
48
48
|
value
|
|
49
49
|
]);
|
|
50
50
|
(0, $3KLdq$react.useEffect)(()=>{
|
|
51
|
-
if (!debouncedValue && value) onChange((0, $3KLdq$
|
|
52
|
-
(0, $3KLdq$
|
|
51
|
+
if (!debouncedValue && value) onChange((0, $3KLdq$sanity.PatchEvent).from([
|
|
52
|
+
(0, $3KLdq$sanity.unset)()
|
|
53
53
|
]));
|
|
54
|
-
else if (debouncedValue !== value) onChange((0, $3KLdq$
|
|
55
|
-
(0, $3KLdq$
|
|
54
|
+
else if (debouncedValue !== value) onChange((0, $3KLdq$sanity.PatchEvent).from([
|
|
55
|
+
(0, $3KLdq$sanity.set)(debouncedValue)
|
|
56
56
|
]));
|
|
57
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
58
|
}, [
|
|
@@ -60,7 +60,6 @@ const $067e75d167fd097d$export$18a9461578883ec4 = /*#__PURE__*/ (0, $3KLdq$react
|
|
|
60
60
|
onChange
|
|
61
61
|
]);
|
|
62
62
|
/* const saveImage = async function* (data: any) {
|
|
63
|
-
const client = sanityClient.withConfig({apiVersion: '2021-03-25'})
|
|
64
63
|
|
|
65
64
|
let success = true
|
|
66
65
|
const result = await client.assets
|
|
@@ -107,20 +106,26 @@ const $067e75d167fd097d$export$18a9461578883ec4 = /*#__PURE__*/ (0, $3KLdq$react
|
|
|
107
106
|
|
|
108
107
|
|
|
109
108
|
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
const $83686b2c306f69a9$var$markdownTypeName = "markdown";
|
|
112
|
+
const $83686b2c306f69a9$export$244155b8997cef98 = (0, $3KLdq$sanity.defineType)({
|
|
113
|
+
type: "string",
|
|
114
|
+
name: $83686b2c306f69a9$var$markdownTypeName,
|
|
115
|
+
title: "Markdown",
|
|
116
|
+
components: {
|
|
117
|
+
input: (0, $067e75d167fd097d$export$18a9461578883ec4)
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
|
|
110
122
|
// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
|
|
111
123
|
const $244e63ca53592e4d$export$18a9461578883ec4 = (0, $067e75d167fd097d$export$18a9461578883ec4);
|
|
112
124
|
const $244e63ca53592e4d$export$f225414958dd8925 = (0, $3KLdq$sanity.createPlugin)({
|
|
113
125
|
name: "markdown-editor",
|
|
114
126
|
schema: {
|
|
115
127
|
types: [
|
|
116
|
-
(0, $
|
|
117
|
-
type: "string",
|
|
118
|
-
name: "markdown",
|
|
119
|
-
title: "Markdown",
|
|
120
|
-
components: {
|
|
121
|
-
input: $244e63ca53592e4d$export$18a9461578883ec4
|
|
122
|
-
}
|
|
123
|
-
}),
|
|
128
|
+
(0, $83686b2c306f69a9$export$244155b8997cef98)
|
|
124
129
|
]
|
|
125
130
|
}
|
|
126
131
|
});
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;ACAA;;ACAA;AAEe,kDAAqB,KAAc,EAAE,KAAa,EAAE;IACjE,MAAM,CAAC,cAAc,EAA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CAAA,GAAA,+CAAc,CAAA;qBAAC;iBAAC;aAClC;YACD,OAAO,EAAC,MAAM;UACd,AACH;MACG,CACP;CACF,CAAC;;ADtEF;;AGAA;;AAGA,MAAM,sCAAgB,GAAG,UAAU,AAAS;AAgBrC,MAAM,yCAAkB,GAAG,CAAA,GAAA,wBAAU,CAAA,CAAC;IAC3C,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,sCAAgB;IACtB,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE;QACV,KAAK,EAAE,CAAA,GAAA,yCAAc,CAAA;KACtB;CACF,CAAC;;;AHtBF,6FAA6F;AAC7F,MAAM,yCAAc,GAAG,CAAA,GAAA,yCAAM,CAAA;AAKtB,MAAM,yCAAc,GAAG,CAAA,GAAA,0BAAY,CAAA,CAAC;IACzC,IAAI,EAAE,iBAAiB;IACvB,MAAM,EAAE;QACN,KAAK,EAAE;YAAC,CAAA,GAAA,yCAAkB,CAAA;SAAC;KAC5B;CACF,CAAC","sources":["src/index.ts","src/components/Editor.tsx","src/hooks/useDebounce.ts","src/schema.ts"],"sourcesContent":["import {MarkdownEditor as Editor} from './components/Editor'\nimport {createPlugin} from 'sanity'\nimport {markdownSchemaType, MarkdownDefinition} from './schema'\n\n// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:\nconst MarkdownEditor = Editor\n\nexport {MarkdownEditor, markdownSchemaType}\nexport type {MarkdownDefinition}\n\nexport const markdownSchema = createPlugin({\n name: 'markdown-editor',\n schema: {\n types: [markdownSchemaType],\n },\n})\n","import MDEditor from '@uiw/react-md-editor'\nimport useDebounce from '../hooks/useDebounce'\nimport {StringInputProps, PatchEvent, set, unset} from 'sanity'\nimport React, {forwardRef, Ref, useEffect, useState} from 'react'\nimport {Card, useTheme} from '@sanity/ui'\nimport rehypeSanitize from 'rehype-sanitize'\n\nexport const MarkdownEditor = forwardRef(function MarkdownEditor(\n props: StringInputProps,\n ref: Ref<any>\n) {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus},\n readOnly,\n } = props\n const [editedValue, setEditedValue] = useState<string | undefined>(value)\n const debouncedValue = useDebounce(editedValue, 100)\n // const client = useClient({apiVersion: '2021-03-25'})\n\n useEffect(() => {\n setEditedValue(value)\n }, [value])\n\n useEffect(() => {\n if (!debouncedValue && value) {\n onChange(PatchEvent.from([unset()]))\n } else if (debouncedValue !== value) {\n onChange(PatchEvent.from([set(debouncedValue)]))\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [debouncedValue, onChange])\n\n /* const saveImage = async function* (data: any) {\n\n let success = true\n const result = await client.assets\n .upload('image', data)\n .then((doc) => `${doc.url}?w=450`)\n .catch(() => {\n success = false\n return `Error: Could not upload file. Only images are supported.`\n })\n\n yield result\n return success\n }*/\n\n const {sanity: studioTheme} = useTheme()\n return (\n <div ref={ref} data-color-mode={studioTheme.color.dark ? 'dark' : 'light'}>\n {readOnly ? (\n <Card border padding={3}>\n <MDEditor.Markdown source={value} rehypePlugins={[[rehypeSanitize]]} />\n </Card>\n ) : (\n <MDEditor\n value={editedValue}\n onChange={setEditedValue}\n onBlur={onBlur}\n onFocus={onFocus}\n previewOptions={{\n rehypePlugins: [[rehypeSanitize]],\n }}\n preview=\"edit\"\n />\n )}\n </div>\n )\n})\n","import {useState, useEffect} from 'react'\n\nexport default function useDebounce(value: unknown, delay: number) {\n const [debouncedValue, setDebouncedValue] = useState(value)\n useEffect(() => {\n const handler = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n return () => clearTimeout(handler)\n }, [value, delay])\n\n return debouncedValue\n}\n","import {defineType, StringDefinition} from 'sanity'\nimport {MarkdownEditor} from './components/Editor'\n\nconst markdownTypeName = 'markdown' as const\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\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: {\n input: MarkdownEditor,\n },\n})\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
package/lib/index.modern.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {createPlugin as $jPEKE$createPlugin, defineType as $jPEKE$defineType} from "sanity";
|
|
1
|
+
import {createPlugin as $jPEKE$createPlugin, PatchEvent as $jPEKE$PatchEvent, unset as $jPEKE$unset, set as $jPEKE$set, defineType as $jPEKE$defineType} from "sanity";
|
|
2
2
|
import {jsx as $jPEKE$jsx} from "react/jsx-runtime";
|
|
3
3
|
import $jPEKE$uiwreactmdeditor from "@uiw/react-md-editor";
|
|
4
|
-
import {PatchEvent as $jPEKE$PatchEvent, unset as $jPEKE$unset, set as $jPEKE$set} from "sanity/form";
|
|
5
4
|
import {forwardRef as $jPEKE$forwardRef, useState as $jPEKE$useState, useEffect as $jPEKE$useEffect} from "react";
|
|
6
5
|
import {useTheme as $jPEKE$useTheme, Card as $jPEKE$Card} from "@sanity/ui";
|
|
7
6
|
import $jPEKE$rehypesanitize from "rehype-sanitize";
|
|
@@ -29,10 +28,10 @@ function $a9f5cf746146e5f0$export$2e2bcd8739ae039(value, delay) {
|
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
const $483dd42bf797352b$export$18a9461578883ec4 = /*#__PURE__*/ (0, $jPEKE$forwardRef)(function MarkdownEditor(props, ref) {
|
|
32
|
-
const { value: value = "" ,
|
|
31
|
+
const { value: value = "" , onChange: onChange , elementProps: { onBlur: onBlur , onFocus: onFocus } , readOnly: readOnly , } = props;
|
|
33
32
|
const [editedValue, setEditedValue] = (0, $jPEKE$useState)(value);
|
|
34
33
|
const debouncedValue = (0, $a9f5cf746146e5f0$export$2e2bcd8739ae039)(editedValue, 100);
|
|
35
|
-
// const
|
|
34
|
+
// const client = useClient({apiVersion: '2021-03-25'})
|
|
36
35
|
(0, $jPEKE$useEffect)(()=>{
|
|
37
36
|
setEditedValue(value);
|
|
38
37
|
}, [
|
|
@@ -51,7 +50,6 @@ const $483dd42bf797352b$export$18a9461578883ec4 = /*#__PURE__*/ (0, $jPEKE$forwa
|
|
|
51
50
|
onChange
|
|
52
51
|
]);
|
|
53
52
|
/* const saveImage = async function* (data: any) {
|
|
54
|
-
const client = sanityClient.withConfig({apiVersion: '2021-03-25'})
|
|
55
53
|
|
|
56
54
|
let success = true
|
|
57
55
|
const result = await client.assets
|
|
@@ -98,24 +96,30 @@ const $483dd42bf797352b$export$18a9461578883ec4 = /*#__PURE__*/ (0, $jPEKE$forwa
|
|
|
98
96
|
|
|
99
97
|
|
|
100
98
|
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const $12cb8b58be9d76a6$var$markdownTypeName = "markdown";
|
|
102
|
+
const $12cb8b58be9d76a6$export$244155b8997cef98 = (0, $jPEKE$defineType)({
|
|
103
|
+
type: "string",
|
|
104
|
+
name: $12cb8b58be9d76a6$var$markdownTypeName,
|
|
105
|
+
title: "Markdown",
|
|
106
|
+
components: {
|
|
107
|
+
input: (0, $483dd42bf797352b$export$18a9461578883ec4)
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
|
|
101
112
|
// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
|
|
102
113
|
const $df9eabe9bda49ea8$export$18a9461578883ec4 = (0, $483dd42bf797352b$export$18a9461578883ec4);
|
|
103
114
|
const $df9eabe9bda49ea8$export$f225414958dd8925 = (0, $jPEKE$createPlugin)({
|
|
104
115
|
name: "markdown-editor",
|
|
105
116
|
schema: {
|
|
106
117
|
types: [
|
|
107
|
-
(0, $
|
|
108
|
-
type: "string",
|
|
109
|
-
name: "markdown",
|
|
110
|
-
title: "Markdown",
|
|
111
|
-
components: {
|
|
112
|
-
input: $df9eabe9bda49ea8$export$18a9461578883ec4
|
|
113
|
-
}
|
|
114
|
-
}),
|
|
118
|
+
(0, $12cb8b58be9d76a6$export$244155b8997cef98)
|
|
115
119
|
]
|
|
116
120
|
}
|
|
117
121
|
});
|
|
118
122
|
|
|
119
123
|
|
|
120
|
-
export {$df9eabe9bda49ea8$export$18a9461578883ec4 as MarkdownEditor, $df9eabe9bda49ea8$export$f225414958dd8925 as markdownSchema};
|
|
124
|
+
export {$df9eabe9bda49ea8$export$18a9461578883ec4 as MarkdownEditor, $df9eabe9bda49ea8$export$f225414958dd8925 as markdownSchema, $12cb8b58be9d76a6$export$244155b8997cef98 as markdownSchemaType};
|
|
121
125
|
//# sourceMappingURL=index.modern.js.map
|
package/lib/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;ACAA;;ACAA;AAEe,kDAAqB,KAAc,EAAE,KAAa,EAAE;IACjE,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,CAAA,GAAA,eAAQ,CAAA,CAAC,KAAK,CAAC;IAC3D,CAAA,GAAA,gBAAS,CAAA,CAAC,IAAM;QACd,MAAM,OAAO,GAAG,UAAU,CAAC,IAAM;YAC/B,iBAAiB,CAAC,KAAK,CAAC;SACzB,EAAE,KAAK,CAAC;QAET,OAAO,IAAM,YAAY,CAAC,OAAO,CAAC,CAAA;KACnC,EAAE;QAAC,KAAK;QAAE,KAAK;KAAC,CAAC;IAElB,OAAO,cAAc,CAAA;CACtB;;;;;;;ADNM,MAAM,yCAAc,iBAAG,CAAA,GAAA,iBAAU,CAAA,CAAC,SAAS,cAAc,CAC9D,KAAuB,EACvB,GAAa,EACb;IACA,MAAM,SACJ,KAAK,GAAG,EAAE,aACV,QAAQ,CAAA,EACR,YAAY,EAAE,UAAC,MAAM,CAAA,WAAE,OAAO,CAAA,EAAC,CAAA,YAC/B,QAAQ,CAAA,IACT,GAAG,KAAK;IACT,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,CAAA,GAAA,eAAQ,CA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xB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,OAAO;YAChB,cAAc,EAAE;gBACd,aAAa,EAAE;oBAAC;wBAAC,CAAA,GAAA,qBAAc,CAAA;qBAAC;iBAAC;aAClC;YACD,OAAO,EAAC,MAAM;UACd,AACH;MACG,CACP;CACF,CAAC;;ADtEF;;AGAA;;AAGA,MAAM,sCAAgB,GAAG,UAAU,AAAS;AAgBrC,MAAM,yCAAkB,GAAG,CAAA,GAAA,iBAAU,CAAA,CAAC;IAC3C,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,sCAAgB;IACtB,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE;QACV,KAAK,EAAE,CAAA,GAAA,yCAAc,CAAA;KACtB;CACF,CAAC;;;AHtBF,6FAA6F;AAC7F,MAAM,yCAAc,GAAG,CAAA,GAAA,yCAAM,CAAA;AAKtB,MAAM,yCAAc,GAAG,CAAA,GAAA,mBAAY,CAAA,CAAC;IACzC,IAAI,EAAE,iBAAiB;IACvB,MAAM,EAAE;QACN,KAAK,EAAE;YAAC,CAAA,GAAA,yCAAkB,CAAA;SAAC;KAC5B;CACF,CAAC","sources":["src/index.ts","src/components/Editor.tsx","src/hooks/useDebounce.ts","src/schema.ts"],"sourcesContent":["import {MarkdownEditor as Editor} from './components/Editor'\nimport {createPlugin} from 'sanity'\nimport {markdownSchemaType, MarkdownDefinition} from './schema'\n\n// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:\nconst MarkdownEditor = Editor\n\nexport {MarkdownEditor, markdownSchemaType}\nexport type {MarkdownDefinition}\n\nexport const markdownSchema = createPlugin({\n name: 'markdown-editor',\n schema: {\n types: [markdownSchemaType],\n },\n})\n","import MDEditor from '@uiw/react-md-editor'\nimport useDebounce from '../hooks/useDebounce'\nimport {StringInputProps, PatchEvent, set, unset} from 'sanity'\nimport React, {forwardRef, Ref, useEffect, useState} from 'react'\nimport {Card, useTheme} from '@sanity/ui'\nimport rehypeSanitize from 'rehype-sanitize'\n\nexport const MarkdownEditor = forwardRef(function MarkdownEditor(\n props: StringInputProps,\n ref: Ref<any>\n) {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus},\n readOnly,\n } = props\n const [editedValue, setEditedValue] = useState<string | undefined>(value)\n const debouncedValue = useDebounce(editedValue, 100)\n // const client = useClient({apiVersion: '2021-03-25'})\n\n useEffect(() => {\n setEditedValue(value)\n }, [value])\n\n useEffect(() => {\n if (!debouncedValue && value) {\n onChange(PatchEvent.from([unset()]))\n } else if (debouncedValue !== value) {\n onChange(PatchEvent.from([set(debouncedValue)]))\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [debouncedValue, onChange])\n\n /* const saveImage = async function* (data: any) {\n\n let success = true\n const result = await client.assets\n .upload('image', data)\n .then((doc) => `${doc.url}?w=450`)\n .catch(() => {\n success = false\n return `Error: Could not upload file. Only images are supported.`\n })\n\n yield result\n return success\n }*/\n\n const {sanity: studioTheme} = useTheme()\n return (\n <div ref={ref} data-color-mode={studioTheme.color.dark ? 'dark' : 'light'}>\n {readOnly ? (\n <Card border padding={3}>\n <MDEditor.Markdown source={value} rehypePlugins={[[rehypeSanitize]]} />\n </Card>\n ) : (\n <MDEditor\n value={editedValue}\n onChange={setEditedValue}\n onBlur={onBlur}\n onFocus={onFocus}\n previewOptions={{\n rehypePlugins: [[rehypeSanitize]],\n }}\n preview=\"edit\"\n />\n )}\n </div>\n )\n})\n","import {useState, useEffect} from 'react'\n\nexport default function useDebounce(value: unknown, delay: number) {\n const [debouncedValue, setDebouncedValue] = useState(value)\n useEffect(() => {\n const handler = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n return () => clearTimeout(handler)\n }, [value, delay])\n\n return debouncedValue\n}\n","import {defineType, StringDefinition} from 'sanity'\nimport {MarkdownEditor} from './components/Editor'\n\nconst markdownTypeName = 'markdown' as const\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\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: {\n input: MarkdownEditor,\n },\n})\n"],"names":[],"version":3,"file":"index.modern.js.map","sourceRoot":"../"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-markdown",
|
|
3
|
-
"version": "3.0.0-v3-studio.
|
|
3
|
+
"version": "3.0.0-v3-studio.3",
|
|
4
4
|
"description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf lib",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@reach/auto-id": "^0.17.0",
|
|
42
|
-
"@sanity/incompatible-plugin": "^1.0.
|
|
43
|
-
"@sanity/ui": "^0.
|
|
42
|
+
"@sanity/incompatible-plugin": "^1.0.4",
|
|
43
|
+
"@sanity/ui": "^0.38.0",
|
|
44
44
|
"@uiw/react-md-editor": "^3.18.1",
|
|
45
45
|
"rehype-sanitize": "^5.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@commitlint/cli": "^
|
|
49
|
-
"@commitlint/config-conventional": "^
|
|
48
|
+
"@commitlint/cli": "^17.1.2",
|
|
49
|
+
"@commitlint/config-conventional": "^17.1.0",
|
|
50
50
|
"@parcel/packager-ts": "^2.7.0",
|
|
51
51
|
"@parcel/transformer-typescript-types": "^2.7.0",
|
|
52
|
-
"@sanity/plugin-kit": "^1.0.
|
|
53
|
-
"@sanity/semantic-release-preset": "^2.0.
|
|
52
|
+
"@sanity/plugin-kit": "^1.1.0-ecosystem-preset.5",
|
|
53
|
+
"@sanity/semantic-release-preset": "^2.0.1",
|
|
54
54
|
"@types/styled-components": "^5.1.25",
|
|
55
55
|
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
56
56
|
"@typescript-eslint/parser": "^5.12.0",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"eslint-plugin-prettier": "4.0.0",
|
|
61
61
|
"eslint-plugin-react": "^7.28.0",
|
|
62
62
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
63
|
-
"husky": "^
|
|
64
|
-
"lint-staged": "^
|
|
63
|
+
"husky": "^8.0.1",
|
|
64
|
+
"lint-staged": "^13.0.3",
|
|
65
65
|
"parcel": "^2.7.0",
|
|
66
66
|
"prettier": "^2.5.1",
|
|
67
|
-
"react": "^
|
|
67
|
+
"react": "^18.0.0",
|
|
68
68
|
"rimraf": "^3.0.2",
|
|
69
|
-
"sanity": "3.0.0-dev-preview.
|
|
69
|
+
"sanity": "3.0.0-dev-preview.21",
|
|
70
70
|
"styled-components": "^5.2.0",
|
|
71
|
-
"typescript": "
|
|
71
|
+
"typescript": "4.7.4"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"react": "^
|
|
74
|
+
"react": "^18.0.0",
|
|
75
75
|
"sanity": "dev-preview",
|
|
76
76
|
"styled-components": "^5.2.0"
|
|
77
77
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import MDEditor from '@uiw/react-md-editor'
|
|
2
2
|
import useDebounce from '../hooks/useDebounce'
|
|
3
|
-
import {PatchEvent, set, unset} from 'sanity
|
|
4
|
-
import {StringInputProps} from 'sanity'
|
|
3
|
+
import {StringInputProps, PatchEvent, set, unset} from 'sanity'
|
|
5
4
|
import React, {forwardRef, Ref, useEffect, useState} from 'react'
|
|
6
5
|
import {Card, useTheme} from '@sanity/ui'
|
|
7
6
|
import rehypeSanitize from 'rehype-sanitize'
|
|
@@ -10,10 +9,15 @@ export const MarkdownEditor = forwardRef(function MarkdownEditor(
|
|
|
10
9
|
props: StringInputProps,
|
|
11
10
|
ref: Ref<any>
|
|
12
11
|
) {
|
|
13
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
value = '',
|
|
14
|
+
onChange,
|
|
15
|
+
elementProps: {onBlur, onFocus},
|
|
16
|
+
readOnly,
|
|
17
|
+
} = props
|
|
14
18
|
const [editedValue, setEditedValue] = useState<string | undefined>(value)
|
|
15
19
|
const debouncedValue = useDebounce(editedValue, 100)
|
|
16
|
-
// const
|
|
20
|
+
// const client = useClient({apiVersion: '2021-03-25'})
|
|
17
21
|
|
|
18
22
|
useEffect(() => {
|
|
19
23
|
setEditedValue(value)
|
|
@@ -29,7 +33,6 @@ export const MarkdownEditor = forwardRef(function MarkdownEditor(
|
|
|
29
33
|
}, [debouncedValue, onChange])
|
|
30
34
|
|
|
31
35
|
/* const saveImage = async function* (data: any) {
|
|
32
|
-
const client = sanityClient.withConfig({apiVersion: '2021-03-25'})
|
|
33
36
|
|
|
34
37
|
let success = true
|
|
35
38
|
const result = await client.assets
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import {MarkdownEditor as Editor} from './components/Editor'
|
|
2
|
-
import {createPlugin
|
|
2
|
+
import {createPlugin} from 'sanity'
|
|
3
|
+
import {markdownSchemaType, MarkdownDefinition} from './schema'
|
|
3
4
|
|
|
4
5
|
// re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
|
|
5
6
|
const MarkdownEditor = Editor
|
|
6
7
|
|
|
7
|
-
export {MarkdownEditor}
|
|
8
|
+
export {MarkdownEditor, markdownSchemaType}
|
|
9
|
+
export type {MarkdownDefinition}
|
|
8
10
|
|
|
9
11
|
export const markdownSchema = createPlugin({
|
|
10
12
|
name: 'markdown-editor',
|
|
11
13
|
schema: {
|
|
12
|
-
types: [
|
|
13
|
-
defineType({
|
|
14
|
-
type: 'string',
|
|
15
|
-
name: 'markdown',
|
|
16
|
-
title: 'Markdown',
|
|
17
|
-
components: {
|
|
18
|
-
input: MarkdownEditor,
|
|
19
|
-
},
|
|
20
|
-
}),
|
|
21
|
-
],
|
|
14
|
+
types: [markdownSchemaType],
|
|
22
15
|
},
|
|
23
16
|
})
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {defineType, StringDefinition} from 'sanity'
|
|
2
|
+
import {MarkdownEditor} from './components/Editor'
|
|
3
|
+
|
|
4
|
+
const markdownTypeName = 'markdown' as const
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
|
|
10
|
+
type: typeof markdownTypeName
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module '@sanity/types' {
|
|
14
|
+
// makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember
|
|
15
|
+
export interface IntrinsicDefinitions {
|
|
16
|
+
markdown: MarkdownDefinition
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const markdownSchemaType = defineType({
|
|
21
|
+
type: 'string',
|
|
22
|
+
name: markdownTypeName,
|
|
23
|
+
title: 'Markdown',
|
|
24
|
+
components: {
|
|
25
|
+
input: MarkdownEditor,
|
|
26
|
+
},
|
|
27
|
+
})
|