sanity-plugin-markdown 4.1.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-markdown",
3
- "version": "4.1.2",
3
+ "version": "5.0.0",
4
4
  "description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -19,31 +19,29 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "author": "Sanity.io <hello@sanity.io>",
22
+ "sideEffects": false,
22
23
  "exports": {
23
24
  ".": {
24
- "types": "./lib/index.d.ts",
25
25
  "source": "./src/index.ts",
26
+ "import": "./lib/index.mjs",
26
27
  "require": "./lib/index.js",
27
- "import": "./lib/index.esm.js",
28
- "default": "./lib/index.esm.js"
28
+ "default": "./lib/index.js"
29
29
  },
30
30
  "./next": {
31
- "types": "./lib/index.d.ts",
32
31
  "source": "./src/indexNext.ts",
32
+ "import": "./lib/indexNext.mjs",
33
33
  "require": "./lib/indexNext.js",
34
- "import": "./lib/indexNext.esm.js",
35
- "default": "./lib/indexNext.esm.js"
34
+ "default": "./lib/indexNext.js"
36
35
  },
37
36
  "./package.json": "./package.json"
38
37
  },
39
38
  "main": "./lib/index.js",
40
39
  "module": "./lib/index.esm.js",
41
- "source": "./src/index.ts",
42
40
  "types": "./lib/index.d.ts",
43
41
  "typesVersions": {
44
42
  "*": {
45
43
  "next": [
46
- "./lib/index.d.ts"
44
+ "./lib/indexNext.d.ts"
47
45
  ]
48
46
  }
49
47
  },
@@ -54,60 +52,58 @@
54
52
  "v2-incompatible.js"
55
53
  ],
56
54
  "scripts": {
57
- "prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
58
- "build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
59
- "clean": "rimraf lib",
55
+ "build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
60
56
  "compile": "tsc --noEmit",
61
57
  "format": "prettier --write --cache --ignore-unknown .",
62
58
  "link-watch": "plugin-kit link-watch",
63
59
  "lint": "eslint .",
64
60
  "prepare": "husky install",
65
- "prepublishOnly": "run-s build",
61
+ "prepublishOnly": "npm run build",
66
62
  "watch": "pkg-utils watch --strict"
67
63
  },
64
+ "browserslist": "extends @sanity/browserslist-config",
65
+ "prettier": "@sanity/prettier-config",
68
66
  "dependencies": {
69
67
  "@sanity/incompatible-plugin": "^1.0.4",
70
- "@sanity/ui": "^1.0.0",
68
+ "@sanity/ui": "^2.8.9",
71
69
  "react-simplemde-editor": "^5.2.0"
72
70
  },
73
71
  "devDependencies": {
74
72
  "@commitlint/cli": "^17.2.0",
75
73
  "@commitlint/config-conventional": "^17.2.0",
76
- "@sanity/pkg-utils": "^2.2.6",
77
- "@sanity/plugin-kit": "^3.1.7",
74
+ "@sanity/pkg-utils": "^6.11.0",
75
+ "@sanity/plugin-kit": "^4.0.18",
76
+ "@sanity/prettier-config": "^1.0.3",
78
77
  "@sanity/semantic-release-preset": "^2.0.2",
79
- "@types/react": "^18.0.26",
80
- "@types/styled-components": "^5.1.26",
78
+ "@types/react": "^18.3.5",
81
79
  "@typescript-eslint/eslint-plugin": "^5.48.0",
82
80
  "@typescript-eslint/parser": "^5.48.0",
83
81
  "easymde": "^2.18.0",
84
82
  "eslint": "^8.31.0",
85
- "eslint-config-prettier": "^8.6.0",
83
+ "eslint-config-prettier": "^9.1.0",
86
84
  "eslint-config-sanity": "^6.0.0",
87
- "eslint-plugin-prettier": "^4.2.1",
88
- "eslint-plugin-react": "^7.31.11",
89
- "eslint-plugin-react-hooks": "^4.6.0",
85
+ "eslint-plugin-prettier": "^5.2.1",
86
+ "eslint-plugin-react": "^7.35.2",
87
+ "eslint-plugin-react-hooks": "^4.6.2",
90
88
  "husky": "^8.0.1",
91
89
  "lint-staged": "^13.0.3",
92
90
  "npm-run-all": "^4.1.5",
93
- "prettier": "^2.8.1",
94
- "prettier-plugin-packagejson": "^2.3.0",
95
- "react": "^18.2.0",
96
- "react-dom": "^18.2.0",
97
- "react-is": "^18.2.0",
98
- "rimraf": "^5.0.0",
99
- "sanity": "^3.1.4",
100
- "styled-components": "^5.3.6",
101
- "typescript": "^5.0.0"
91
+ "prettier": "^3.3.3",
92
+ "react": "^18.3.1",
93
+ "react-dom": "^18.3.1",
94
+ "react-is": "^18.3.1",
95
+ "sanity": "^3.57.1",
96
+ "styled-components": "^6.1.13",
97
+ "typescript": "5.5.4"
102
98
  },
103
99
  "peerDependencies": {
104
- "easymde": "^2",
105
- "react": "^18",
106
- "sanity": "^3",
107
- "styled-components": "^5.2 || ^6"
100
+ "easymde": "^2.18",
101
+ "react": "^18.3",
102
+ "sanity": "^3.23",
103
+ "styled-components": "^6.1"
108
104
  },
109
105
  "engines": {
110
- "node": ">=14"
106
+ "node": ">=18"
111
107
  },
112
108
  "sanityExchangeUrl": "https://www.sanity.io/plugins/sanity-plugin-markdown"
113
109
  }
@@ -1,20 +1,21 @@
1
1
  import {type Options as EasyMdeOptions} from 'easymde'
2
- import React, {Suspense, useCallback, useMemo} from 'react'
2
+ import {lazy, Suspense, useCallback, useMemo, useSyncExternalStore} from 'react'
3
3
  // dont import non-types here, it will break SSR on next
4
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
8
  import {Box, Text} from '@sanity/ui'
10
9
 
10
+ const SimpleMdeReact = lazy(() => import('react-simplemde-editor'))
11
+
11
12
  export interface MarkdownInputProps extends StringInputProps {
12
13
  /**
13
14
  * These are passed along directly to
14
15
  *
15
16
  * Note: MarkdownInput sets certain reactMdeProps.options by default.
16
17
  * These will be merged with any custom options.
17
- * */
18
+ */
18
19
  reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>
19
20
  }
20
21
 
@@ -56,7 +57,7 @@ export function MarkdownInput(props: MarkdownInputProps) {
56
57
  onError(e.message)
57
58
  })
58
59
  },
59
- [client, imageUrl]
60
+ [client, imageUrl],
60
61
  )
61
62
 
62
63
  const mdeOptions: EasyMdeOptions = useMemo(() => {
@@ -76,33 +77,42 @@ export function MarkdownInput(props: MarkdownInputProps) {
76
77
  (newValue: string) => {
77
78
  onChange(PatchEvent.from(newValue ? set(newValue) : unset()))
78
79
  },
79
- [onChange]
80
+ [onChange],
81
+ )
82
+
83
+ const mounted = useSyncExternalStore(
84
+ noop,
85
+ () => true,
86
+ () => false,
80
87
  )
81
88
 
82
- const SimpleMdeReact = useSimpleMdeReact()
89
+ if (!mounted) {
90
+ return <MarkdownInputStyles>{fallback}</MarkdownInputStyles>
91
+ }
83
92
 
84
93
  return (
85
94
  <MarkdownInputStyles>
86
- {SimpleMdeReact && (
87
- <Suspense
88
- fallback={
89
- <Box padding={3}>
90
- <Text>Loading editor...</Text>
91
- </Box>
92
- }
93
- >
94
- <SimpleMdeReact
95
- {...reactMdeProps}
96
- ref={ref}
97
- value={value}
98
- onChange={handleChange}
99
- onBlur={onBlur}
100
- onFocus={onFocus}
101
- options={mdeOptions}
102
- spellCheck={false}
103
- />
104
- </Suspense>
105
- )}
95
+ <Suspense fallback={fallback}>
96
+ <SimpleMdeReact
97
+ {...reactMdeProps}
98
+ ref={ref}
99
+ value={value}
100
+ onChange={handleChange}
101
+ onBlur={onBlur}
102
+ onFocus={onFocus}
103
+ options={mdeOptions}
104
+ spellCheck={false}
105
+ />
106
+ </Suspense>
106
107
  </MarkdownInputStyles>
107
108
  )
108
109
  }
110
+
111
+ // eslint-disable-next-line no-empty-function
112
+ const noop = () => () => {}
113
+
114
+ const fallback = (
115
+ <Box padding={3}>
116
+ <Text>Loading editor...</Text>
117
+ </Box>
118
+ )
@@ -1,63 +1,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
- })
1
+ import {Box} from '@sanity/ui'
2
+ import {styled} from 'styled-components'
3
+
4
+ export const MarkdownInputStyles = styled(Box)`
5
+ & .CodeMirror.CodeMirror {
6
+ color: ${({theme}) => theme.sanity.color.card.enabled.fg};
7
+ border-color: ${({theme}) => theme.sanity.color.card.enabled.border};
8
+ background-color: inherit;
9
+ }
10
+
11
+ & .cm-s-easymde .CodeMirror-cursor {
12
+ border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};
13
+ }
14
+
15
+ & .editor-toolbar,
16
+ .editor-preview-side {
17
+ border-color: ${({theme}) => theme.sanity.color.card.enabled.border};
18
+ }
19
+
20
+ & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
21
+ background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};
22
+ }
23
+
24
+ & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {
25
+ background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
26
+ }
27
+
28
+ & .editor-toolbar > * {
29
+ color: ${({theme}) => theme.sanity.color.card.enabled.fg};
30
+ }
31
+
32
+ & .editor-toolbar > .active,
33
+ .editor-toolbar > button:hover,
34
+ .editor-preview pre,
35
+ .cm-s-easymde .cm-comment {
36
+ background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
37
+ }
38
+
39
+ & .editor-preview {
40
+ background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};
41
+
42
+ & h1,
43
+ h2,
44
+ h3,
45
+ h4,
46
+ h5,
47
+ h6 {
48
+ font-size: revert;
49
+ }
50
+
51
+ & ul,
52
+ li {
53
+ list-style: revert;
54
+ padding: revert;
55
+ }
56
+
57
+ & a {
58
+ text-decoration: revert;
59
+ }
60
+ }
61
+ `
@@ -1,112 +0,0 @@
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
@@ -1 +0,0 @@
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,sBAA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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;"}
@@ -1,123 +0,0 @@
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