sanity-plugin-markdown 3.0.0-v3-studio.4 → 3.0.0-v3-studio.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Rune Botten
3
+ Copyright (c) 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -39,7 +39,7 @@ Add it as a plugin in sanity.config.ts (or .js):
39
39
  ```js
40
40
  import { markdownSchema } from "sanity-plugin-markdown";
41
41
 
42
- export default createConfig({
42
+ export default defineConfig({
43
43
  // ...
44
44
  plugins: [
45
45
  markdownSchema(),
@@ -69,8 +69,7 @@ const myDocument = {
69
69
 
70
70
  ## License
71
71
 
72
- MIT © Sanity.io
73
- See LICENSE
72
+ MIT-licensed. See LICENSE.
74
73
 
75
74
  ## Develop & test
76
75
 
@@ -82,7 +81,7 @@ on how to run this plugin with hotreload in the studio.
82
81
 
83
82
  ### Release new version
84
83
 
85
- Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-markdown/actions).
86
- Make sure to select the main/v3 branch and check "Release new version".
84
+ Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-markdown/actions/workflows/main.yml).
85
+ Make sure to select the main branch and check "Release new version".
87
86
 
88
87
  Semantic release will only release on configured branches, so it is safe to run release on any branch.
@@ -0,0 +1,2 @@
1
+ function e(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function r(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}import{jsx as t}from"react/jsx-runtime";import n from"@uiw/react-md-editor";import{useState as o,useEffect as i,forwardRef as c}from"react";import{PatchEvent as a,unset as u,set as p,defineType as s,definePlugin as m}from"sanity";import{useTheme as l,Card as f}from"@sanity/ui";import d from"rehype-sanitize";const y=c((function(e,r){const{value:c="",onChange:s,elementProps:{onBlur:m,onFocus:y},readOnly:O}=e,[b,g]=o(c),w=function(e,r){const[t,n]=o(e);return i((()=>{const t=setTimeout((()=>{n(e)}),r);return()=>clearTimeout(t)}),[e,r]),t}(b,100);i((()=>{g(c)}),[c]),i((()=>{!w&&c?s(a.from([u()])):w!==c&&s(a.from([p(w)]))}),[w,s]);const{sanity:h}=l();return t("div",{ref:r,"data-color-mode":h.color.dark?"dark":"light",children:O?t(f,{border:!0,padding:3,children:t(n.Markdown,{source:c,rehypePlugins:[[d]]})}):t(n,{value:b,onChange:g,onBlur:m,onFocus:y,previewOptions:{rehypePlugins:[[d]]},preview:"edit"})})})),O=s(function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}({type:"string",name:"markdown",title:"Markdown"},{components:{input:y}})),b=y,g=m({name:"markdown-editor",schema:{types:[O]}});export{b as MarkdownEditor,g as markdownSchema,O as markdownSchemaType};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/components/Editor.tsx","../src/hooks/useDebounce.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["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: {input: MarkdownEditor}} as {}), //TODO revert when rc.1 ships\n})\n","import {MarkdownEditor as Editor} from './components/Editor'\nimport {definePlugin} 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 = definePlugin({\n name: 'markdown-editor',\n schema: {\n types: [markdownSchemaType],\n },\n})\n"],"names":["MarkdownEditor","forwardRef","props","ref","value","onChange","elementProps","onBlur","onFocus","readOnly","editedValue","setEditedValue","useState","debouncedValue","delay","setDebouncedValue","useEffect","handler","setTimeout","clearTimeout","useDebounce","PatchEvent","from","unset","set","sanity","studioTheme","useTheme","jsx","color","dark","children","Card","border","padding","MDEditor","Markdown","source","rehypePlugins","rehypeSanitize","previewOptions","preview","markdownSchemaType","defineType","_objectSpread","type","name","title","components","input","Editor","markdownSchema","definePlugin","schema","types"],"mappings":"2oBAOO,MAAMA,EAAiBC,GAAW,SACvCC,EACAC,GAEM,MAAAC,MACJA,EAAQ,GAAAC,SACRA,EACAC,cAAcC,OAACA,EAAAC,QAAQA,GAAOC,SAC9BA,GACEP,GACGQ,EAAaC,GAAkBC,EAA6BR,GAC7DS,EChBgB,SAAYT,EAAgBU,GAClD,MAAOD,EAAgBE,GAAqBH,EAASR,GAS9C,OARPY,GAAU,KACF,MAAAC,EAAUC,YAAW,KACzBH,EAAkBX,EAAK,GACtBU,GAEI,MAAA,IAAMK,aAAaF,EAAO,GAChC,CAACb,EAAOU,IAEJD,CACT,CDKyBO,CAAYV,EAAa,KAGhDM,GAAU,KACRL,EAAeP,EAAK,GACnB,CAACA,IAEJY,GAAU,MACHH,GAAkBT,EACrBC,EAASgB,EAAWC,KAAK,CAACC,OACjBV,IAAmBT,GAC5BC,EAASgB,EAAWC,KAAK,CAACE,EAAIX,KAChC,GAEC,CAACA,EAAgBR,IAiBpB,MAAOoB,OAAQC,GAAeC,IAC9B,OACGC,EAAA,MAAA,CAAIzB,MAAU,kBAAiBuB,EAAYG,MAAMC,KAAO,OAAS,QAC/DC,WACEH,EAAAI,EAAA,CAAKC,QAAM,EAACC,QAAS,EACpBH,SAAAH,EAACO,EAASC,SAAT,CAAkBC,OAAQjC,EAAOkC,cAAe,CAAC,CAACC,QAGpDX,EAAAO,EAAA,CACC/B,MAAOM,EACPL,SAAUM,EACVJ,SACAC,UACAgC,eAAgB,CACdF,cAAe,CAAC,CAACC,KAEnBE,QAAQ,UAKlB,IEnDaC,EAAqBC,iWAAWC,CAAA,CAC3CC,KAAM,SACNC,KAlBuB,WAmBvBC,MAAO,YACH,CAACC,WAAY,CAACC,MAAOjD,MClBrBA,EAAiBkD,EAKVC,EAAiBC,EAAa,CACzCN,KAAM,kBACNO,OAAQ,CACNC,MAAO,CAACZ"}
package/lib/index.js CHANGED
@@ -1,134 +1,2 @@
1
- var $3KLdq$sanity = require("sanity");
2
- var $3KLdq$reactjsxruntime = require("react/jsx-runtime");
3
- var $3KLdq$uiwreactmdeditor = require("@uiw/react-md-editor");
4
- var $3KLdq$react = require("react");
5
- var $3KLdq$sanityui = require("@sanity/ui");
6
- var $3KLdq$rehypesanitize = require("rehype-sanitize");
7
-
8
- function $parcel$export(e, n, v, s) {
9
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
- }
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
13
- }
14
-
15
- $parcel$export(module.exports, "MarkdownEditor", () => $244e63ca53592e4d$export$18a9461578883ec4);
16
- $parcel$export(module.exports, "markdownSchema", () => $244e63ca53592e4d$export$f225414958dd8925);
17
- $parcel$export(module.exports, "markdownSchemaType", () => $83686b2c306f69a9$export$244155b8997cef98);
18
-
19
-
20
-
21
- function $84fd43422be26bd7$export$2e2bcd8739ae039(value, delay) {
22
- const [debouncedValue, setDebouncedValue] = (0, $3KLdq$react.useState)(value);
23
- (0, $3KLdq$react.useEffect)(()=>{
24
- const handler = setTimeout(()=>{
25
- setDebouncedValue(value);
26
- }, delay);
27
- return ()=>clearTimeout(handler);
28
- }, [
29
- value,
30
- delay
31
- ]);
32
- return debouncedValue;
33
- }
34
-
35
-
36
-
37
-
38
-
39
-
40
- const $067e75d167fd097d$export$18a9461578883ec4 = /*#__PURE__*/ (0, $3KLdq$react.forwardRef)(function MarkdownEditor(props, ref) {
41
- const { value: value = "" , onChange: onChange , elementProps: { onBlur: onBlur , onFocus: onFocus } , readOnly: readOnly , } = props;
42
- const [editedValue, setEditedValue] = (0, $3KLdq$react.useState)(value);
43
- const debouncedValue = (0, $84fd43422be26bd7$export$2e2bcd8739ae039)(editedValue, 100);
44
- // const client = useClient({apiVersion: '2021-03-25'})
45
- (0, $3KLdq$react.useEffect)(()=>{
46
- setEditedValue(value);
47
- }, [
48
- value
49
- ]);
50
- (0, $3KLdq$react.useEffect)(()=>{
51
- if (!debouncedValue && value) onChange((0, $3KLdq$sanity.PatchEvent).from([
52
- (0, $3KLdq$sanity.unset)()
53
- ]));
54
- else if (debouncedValue !== value) onChange((0, $3KLdq$sanity.PatchEvent).from([
55
- (0, $3KLdq$sanity.set)(debouncedValue)
56
- ]));
57
- // eslint-disable-next-line react-hooks/exhaustive-deps
58
- }, [
59
- debouncedValue,
60
- onChange
61
- ]);
62
- /* const saveImage = async function* (data: any) {
63
-
64
- let success = true
65
- const result = await client.assets
66
- .upload('image', data)
67
- .then((doc) => `${doc.url}?w=450`)
68
- .catch(() => {
69
- success = false
70
- return `Error: Could not upload file. Only images are supported.`
71
- })
72
-
73
- yield result
74
- return success
75
- }*/ const { sanity: studioTheme } = (0, $3KLdq$sanityui.useTheme)();
76
- return /*#__PURE__*/ (0, $3KLdq$reactjsxruntime.jsx)("div", {
77
- ref: ref,
78
- "data-color-mode": studioTheme.color.dark ? "dark" : "light",
79
- children: readOnly ? /*#__PURE__*/ (0, $3KLdq$reactjsxruntime.jsx)((0, $3KLdq$sanityui.Card), {
80
- border: true,
81
- padding: 3,
82
- children: /*#__PURE__*/ (0, $3KLdq$reactjsxruntime.jsx)((0, ($parcel$interopDefault($3KLdq$uiwreactmdeditor))).Markdown, {
83
- source: value,
84
- rehypePlugins: [
85
- [
86
- (0, ($parcel$interopDefault($3KLdq$rehypesanitize)))
87
- ]
88
- ]
89
- })
90
- }) : /*#__PURE__*/ (0, $3KLdq$reactjsxruntime.jsx)((0, ($parcel$interopDefault($3KLdq$uiwreactmdeditor))), {
91
- value: editedValue,
92
- onChange: setEditedValue,
93
- onBlur: onBlur,
94
- onFocus: onFocus,
95
- previewOptions: {
96
- rehypePlugins: [
97
- [
98
- (0, ($parcel$interopDefault($3KLdq$rehypesanitize)))
99
- ]
100
- ]
101
- },
102
- preview: "edit"
103
- })
104
- });
105
- });
106
-
107
-
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
-
122
- // re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
123
- const $244e63ca53592e4d$export$18a9461578883ec4 = (0, $067e75d167fd097d$export$18a9461578883ec4);
124
- const $244e63ca53592e4d$export$f225414958dd8925 = (0, $3KLdq$sanity.createPlugin)({
125
- name: "markdown-editor",
126
- schema: {
127
- types: [
128
- (0, $83686b2c306f69a9$export$244155b8997cef98)
129
- ]
130
- }
131
- });
132
-
133
-
1
+ "use strict";function e(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function r(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),n=require("@uiw/react-md-editor"),o=require("react"),i=require("sanity"),u=require("@sanity/ui"),a=require("rehype-sanitize");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=c(n),f=c(a);const d=o.forwardRef((function(e,r){const{value:n="",onChange:a,elementProps:{onBlur:c,onFocus:d},readOnly:l}=e,[p,y]=o.useState(n),m=function(e,r){const[t,n]=o.useState(e);return o.useEffect((()=>{const t=setTimeout((()=>{n(e)}),r);return()=>clearTimeout(t)}),[e,r]),t}(p,100);o.useEffect((()=>{y(n)}),[n]),o.useEffect((()=>{!m&&n?a(i.PatchEvent.from([i.unset()])):m!==n&&a(i.PatchEvent.from([i.set(m)]))}),[m,a]);const{sanity:b}=u.useTheme();return t.jsx("div",{ref:r,"data-color-mode":b.color.dark?"dark":"light",children:l?t.jsx(u.Card,{border:!0,padding:3,children:t.jsx(s.default.Markdown,{source:n,rehypePlugins:[[f.default]]})}):t.jsx(s.default,{value:p,onChange:y,onBlur:c,onFocus:d,previewOptions:{rehypePlugins:[[f.default]]},preview:"edit"})})})),l=i.defineType(function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}({type:"string",name:"markdown",title:"Markdown"},{components:{input:d}})),p=d,y=i.definePlugin({name:"markdown-editor",schema:{types:[l]}});exports.MarkdownEditor=p,exports.markdownSchema=y,exports.markdownSchemaType=l;
134
2
  //# s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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":"../"}
1
+ {"version":3,"file":"index.js","sources":["../src/components/Editor.tsx","../src/hooks/useDebounce.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["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: {input: MarkdownEditor}} as {}), //TODO revert when rc.1 ships\n})\n","import {MarkdownEditor as Editor} from './components/Editor'\nimport {definePlugin} 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 = definePlugin({\n name: 'markdown-editor',\n schema: {\n types: [markdownSchemaType],\n },\n})\n"],"names":["MarkdownEditor","forwardRef","props","ref","value","onChange","elementProps","onBlur","onFocus","readOnly","editedValue","setEditedValue","useState","debouncedValue","delay","setDebouncedValue","useEffect","handler","setTimeout","clearTimeout","useDebounce","PatchEvent","from","unset","set","sanity","studioTheme","useTheme","jsx","color","dark","children","Card","border","padding","MDEditor","Markdown","source","rehypePlugins","rehypeSanitize","previewOptions","preview","markdownSchemaType","defineType","_objectSpread","type","name","title","components","input","Editor","markdownSchema","definePlugin","schema","types"],"mappings":"qpBAOO,MAAMA,EAAiBC,EAAAA,YAAW,SACvCC,EACAC,GAEM,MAAAC,MACJA,EAAQ,GAAAC,SACRA,EACAC,cAAcC,OAACA,EAAAC,QAAQA,GAAOC,SAC9BA,GACEP,GACGQ,EAAaC,GAAkBC,WAA6BR,GAC7DS,EChBgB,SAAYT,EAAgBU,GAClD,MAAOD,EAAgBE,GAAqBH,WAASR,GAS9C,OARPY,EAAAA,WAAU,KACF,MAAAC,EAAUC,YAAW,KACzBH,EAAkBX,EAAK,GACtBU,GAEI,MAAA,IAAMK,aAAaF,EAAO,GAChC,CAACb,EAAOU,IAEJD,CACT,CDKyBO,CAAYV,EAAa,KAGhDM,EAAAA,WAAU,KACRL,EAAeP,EAAK,GACnB,CAACA,IAEJY,EAAAA,WAAU,MACHH,GAAkBT,EACrBC,EAASgB,aAAWC,KAAK,CAACC,EAAAA,WACjBV,IAAmBT,GAC5BC,EAASgB,aAAWC,KAAK,CAACE,MAAIX,KAChC,GAEC,CAACA,EAAgBR,IAiBpB,MAAOoB,OAAQC,GAAeC,EAASA,WACvC,OACGC,EAAAA,IAAA,MAAA,CAAIzB,MAAU,kBAAiBuB,EAAYG,MAAMC,KAAO,OAAS,QAC/DC,WACEH,EAAAA,IAAAI,OAAA,CAAKC,QAAM,EAACC,QAAS,EACpBH,SAAAH,EAAAA,IAACO,UAASC,SAAT,CAAkBC,OAAQjC,EAAOkC,cAAe,CAAC,CAACC,EAAAA,cAGpDX,EAAAA,IAAAO,UAAA,CACC/B,MAAOM,EACPL,SAAUM,EACVJ,SACAC,UACAgC,eAAgB,CACdF,cAAe,CAAC,CAACC,EAAAA,WAEnBE,QAAQ,UAKlB,IEnDaC,EAAqBC,EAAAA,0WAAWC,CAAA,CAC3CC,KAAM,SACNC,KAlBuB,WAmBvBC,MAAO,YACH,CAACC,WAAY,CAACC,MAAOjD,MClBrBA,EAAiBkD,EAKVC,EAAiBC,EAAAA,aAAa,CACzCN,KAAM,kBACNO,OAAQ,CACNC,MAAO,CAACZ"}
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+
3
+ import {ForwardRefExoticComponent} from 'react'
4
+ import {Plugin as Plugin_2} from 'sanity'
5
+ import {RefAttributes} from 'react'
6
+ import {StringDefinition} from 'sanity'
7
+ import {StringInputProps} from 'sanity'
8
+ import {StringSchemaType} from 'sanity'
9
+
10
+ /**
11
+ * @public
12
+ */
13
+ export declare interface MarkdownDefinition
14
+ extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {
15
+ type: typeof markdownTypeName
16
+ }
17
+
18
+ export declare const MarkdownEditor: ForwardRefExoticComponent<
19
+ StringInputProps<StringSchemaType> & RefAttributes<any>
20
+ >
21
+
22
+ export declare const markdownSchema: Plugin_2<void>
23
+
24
+ export declare const markdownSchemaType: {
25
+ type: 'string'
26
+ name: 'markdown'
27
+ } & Omit<StringDefinition, 'preview'>
28
+
29
+ declare const markdownTypeName: 'markdown'
30
+
31
+ export {}
32
+
33
+ declare module '@sanity/types' {
34
+ interface IntrinsicDefinitions {
35
+ markdown: MarkdownDefinition;
36
+ }
37
+ }
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "sanity-plugin-markdown",
3
- "version": "3.0.0-v3-studio.4",
3
+ "version": "3.0.0-v3-studio.5",
4
4
  "description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
5
+ "author": "Sanity.io <hello@sanity.io>",
6
+ "license": "MIT",
5
7
  "scripts": {
6
8
  "clean": "rimraf lib",
7
- "prebuild": "npm run clean && plugin-kit verify-package --silent",
8
- "build": "parcel build --no-cache",
9
- "watch": "parcel watch",
9
+ "prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
10
+ "build": "pkg-utils build",
11
+ "watch": "pkg-utils watch",
10
12
  "link-watch": "plugin-kit link-watch",
11
13
  "lint": "eslint .",
12
14
  "format": "prettier src -w",
@@ -16,17 +18,22 @@
16
18
  },
17
19
  "source": "./src/index.ts",
18
20
  "main": "./lib/index.js",
19
- "module": "./lib/index.modern.js",
20
- "types": "./lib/index.d.ts",
21
+ "module": "./lib/index.esm.js",
22
+ "types": "./lib/src/index.d.ts",
21
23
  "exports": {
22
24
  ".": {
25
+ "types": "./lib/src/index.d.ts",
26
+ "source": "./src/index.ts",
27
+ "import": "./lib/index.esm.js",
23
28
  "require": "./lib/index.js",
24
- "default": "./lib/index.modern.js"
29
+ "default": "./lib/index.esm.js"
25
30
  }
26
31
  },
27
32
  "files": [
28
33
  "src",
29
- "lib"
34
+ "lib",
35
+ "v2-incompatible.js",
36
+ "sanity.json"
30
37
  ],
31
38
  "keywords": [
32
39
  "sanity",
@@ -35,8 +42,6 @@
35
42
  "markdown",
36
43
  "github flavored markdown"
37
44
  ],
38
- "author": "Sanity.io <hello@sanity.io>",
39
- "license": "MIT",
40
45
  "dependencies": {
41
46
  "@reach/auto-id": "^0.17.0",
42
47
  "@sanity/incompatible-plugin": "^1.0.4",
@@ -45,44 +50,45 @@
45
50
  "rehype-sanitize": "^5.0.1"
46
51
  },
47
52
  "devDependencies": {
48
- "@commitlint/cli": "^17.1.2",
49
- "@commitlint/config-conventional": "^17.1.0",
53
+ "@commitlint/cli": "^17.2.0",
54
+ "@commitlint/config-conventional": "^17.2.0",
50
55
  "@parcel/packager-ts": "^2.7.0",
51
56
  "@parcel/transformer-typescript-types": "^2.7.0",
52
- "@sanity/plugin-kit": "^1.1.0-ecosystem-preset.5",
53
- "@sanity/semantic-release-preset": "^2.0.1",
57
+ "@sanity/pkg-utils": "^1.16.2",
58
+ "@sanity/plugin-kit": "^2.0.6",
59
+ "@sanity/semantic-release-preset": "^2.0.2",
54
60
  "@types/styled-components": "^5.1.25",
55
- "@typescript-eslint/eslint-plugin": "^5.12.0",
56
- "@typescript-eslint/parser": "^5.12.0",
57
- "eslint": "^8.7.0",
58
- "eslint-config-prettier": "^8.3.0",
59
- "eslint-config-sanity": "^5.1.0",
60
- "eslint-plugin-prettier": "4.0.0",
61
- "eslint-plugin-react": "^7.28.0",
62
- "eslint-plugin-react-hooks": "^4.5.0",
61
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
62
+ "@typescript-eslint/parser": "^5.42.0",
63
+ "eslint": "^8.26.0",
64
+ "eslint-config-prettier": "^8.5.0",
65
+ "eslint-config-sanity": "^6.0.0",
66
+ "eslint-plugin-prettier": "^4.2.1",
67
+ "eslint-plugin-react": "^7.31.10",
68
+ "eslint-plugin-react-hooks": "^4.6.0",
63
69
  "husky": "^8.0.1",
64
70
  "lint-staged": "^13.0.3",
65
71
  "parcel": "^2.7.0",
66
- "prettier": "^2.5.1",
72
+ "prettier": "^2.7.1",
67
73
  "react": "^18.0.0",
68
74
  "rimraf": "^3.0.2",
69
- "sanity": "3.0.0-dev-preview.22",
75
+ "sanity": "dev-preview || 3.0.0-rc.0",
70
76
  "styled-components": "^5.2.0",
71
- "typescript": "4.7.4"
77
+ "typescript": "^4.8.4"
72
78
  },
73
79
  "peerDependencies": {
74
80
  "react": "^18.0.0",
75
- "sanity": "dev-preview || 3.0.0-dev-preview.22",
81
+ "sanity": "dev-preview || 3.0.0-rc.0",
76
82
  "styled-components": "^5.2.0"
77
83
  },
78
84
  "repository": {
79
85
  "type": "git",
80
- "url": "git+https://github.com/sanity-io/sanity-plugin-markdown.git"
86
+ "url": "https://github.com/sanity-io/sanity-plugin-markdown.git"
81
87
  },
82
88
  "bugs": {
83
89
  "url": "https://github.com/sanity-io/sanity-plugin-markdown/issues"
84
90
  },
85
- "homepage": "https://sanity.io",
91
+ "homepage": "https://github.com/sanity-io/sanity-plugin-markdown#readme",
86
92
  "sanityExchangeUrl": "https://www.sanity.io/plugins/sanity-plugin-markdown",
87
93
  "engines": {
88
94
  "node": ">=14.0.0"
package/sanity.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "parts": [
3
+ {
4
+ "implements": "part:@sanity/base/sanity-root",
5
+ "path": "./v2-incompatible.js"
6
+ }
7
+ ]
8
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {MarkdownEditor as Editor} from './components/Editor'
2
- import {createPlugin} from 'sanity'
2
+ import {definePlugin} from 'sanity'
3
3
  import {markdownSchemaType, MarkdownDefinition} from './schema'
4
4
 
5
5
  // re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
@@ -8,7 +8,7 @@ const MarkdownEditor = Editor
8
8
  export {MarkdownEditor, markdownSchemaType}
9
9
  export type {MarkdownDefinition}
10
10
 
11
- export const markdownSchema = createPlugin({
11
+ export const markdownSchema = definePlugin({
12
12
  name: 'markdown-editor',
13
13
  schema: {
14
14
  types: [markdownSchemaType],
package/src/schema.ts CHANGED
@@ -21,7 +21,5 @@ export const markdownSchemaType = defineType({
21
21
  type: 'string',
22
22
  name: markdownTypeName,
23
23
  title: 'Markdown',
24
- components: {
25
- input: MarkdownEditor,
26
- },
24
+ ...({components: {input: MarkdownEditor}} as {}), //TODO revert when rc.1 ships
27
25
  })
@@ -0,0 +1,11 @@
1
+ const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
2
+ const {name, version, sanityExchangeUrl} = require('./package.json')
3
+
4
+ export default showIncompatiblePluginDialog({
5
+ name: name,
6
+ versions: {
7
+ v3: version,
8
+ v2: '^0.2.1',
9
+ },
10
+ sanityExchangeUrl,
11
+ })
package/lib/index.d.ts DELETED
@@ -1,21 +0,0 @@
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">;
18
- export const MarkdownEditor: import("react").ForwardRefExoticComponent<import("sanity").StringInputProps<import("sanity").StringSchemaType> & import("react").RefAttributes<any>>;
19
- export const markdownSchema: import("sanity").Plugin<void>;
20
-
21
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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":"../"}
@@ -1,125 +0,0 @@
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
- import {jsx as $jPEKE$jsx} from "react/jsx-runtime";
3
- import $jPEKE$uiwreactmdeditor from "@uiw/react-md-editor";
4
- import {forwardRef as $jPEKE$forwardRef, useState as $jPEKE$useState, useEffect as $jPEKE$useEffect} from "react";
5
- import {useTheme as $jPEKE$useTheme, Card as $jPEKE$Card} from "@sanity/ui";
6
- import $jPEKE$rehypesanitize from "rehype-sanitize";
7
-
8
-
9
-
10
-
11
- function $a9f5cf746146e5f0$export$2e2bcd8739ae039(value, delay) {
12
- const [debouncedValue, setDebouncedValue] = (0, $jPEKE$useState)(value);
13
- (0, $jPEKE$useEffect)(()=>{
14
- const handler = setTimeout(()=>{
15
- setDebouncedValue(value);
16
- }, delay);
17
- return ()=>clearTimeout(handler);
18
- }, [
19
- value,
20
- delay
21
- ]);
22
- return debouncedValue;
23
- }
24
-
25
-
26
-
27
-
28
-
29
-
30
- const $483dd42bf797352b$export$18a9461578883ec4 = /*#__PURE__*/ (0, $jPEKE$forwardRef)(function MarkdownEditor(props, ref) {
31
- const { value: value = "" , onChange: onChange , elementProps: { onBlur: onBlur , onFocus: onFocus } , readOnly: readOnly , } = props;
32
- const [editedValue, setEditedValue] = (0, $jPEKE$useState)(value);
33
- const debouncedValue = (0, $a9f5cf746146e5f0$export$2e2bcd8739ae039)(editedValue, 100);
34
- // const client = useClient({apiVersion: '2021-03-25'})
35
- (0, $jPEKE$useEffect)(()=>{
36
- setEditedValue(value);
37
- }, [
38
- value
39
- ]);
40
- (0, $jPEKE$useEffect)(()=>{
41
- if (!debouncedValue && value) onChange((0, $jPEKE$PatchEvent).from([
42
- (0, $jPEKE$unset)()
43
- ]));
44
- else if (debouncedValue !== value) onChange((0, $jPEKE$PatchEvent).from([
45
- (0, $jPEKE$set)(debouncedValue)
46
- ]));
47
- // eslint-disable-next-line react-hooks/exhaustive-deps
48
- }, [
49
- debouncedValue,
50
- onChange
51
- ]);
52
- /* const saveImage = async function* (data: any) {
53
-
54
- let success = true
55
- const result = await client.assets
56
- .upload('image', data)
57
- .then((doc) => `${doc.url}?w=450`)
58
- .catch(() => {
59
- success = false
60
- return `Error: Could not upload file. Only images are supported.`
61
- })
62
-
63
- yield result
64
- return success
65
- }*/ const { sanity: studioTheme } = (0, $jPEKE$useTheme)();
66
- return /*#__PURE__*/ (0, $jPEKE$jsx)("div", {
67
- ref: ref,
68
- "data-color-mode": studioTheme.color.dark ? "dark" : "light",
69
- children: readOnly ? /*#__PURE__*/ (0, $jPEKE$jsx)((0, $jPEKE$Card), {
70
- border: true,
71
- padding: 3,
72
- children: /*#__PURE__*/ (0, $jPEKE$jsx)((0, $jPEKE$uiwreactmdeditor).Markdown, {
73
- source: value,
74
- rehypePlugins: [
75
- [
76
- (0, $jPEKE$rehypesanitize)
77
- ]
78
- ]
79
- })
80
- }) : /*#__PURE__*/ (0, $jPEKE$jsx)((0, $jPEKE$uiwreactmdeditor), {
81
- value: editedValue,
82
- onChange: setEditedValue,
83
- onBlur: onBlur,
84
- onFocus: onFocus,
85
- previewOptions: {
86
- rehypePlugins: [
87
- [
88
- (0, $jPEKE$rehypesanitize)
89
- ]
90
- ]
91
- },
92
- preview: "edit"
93
- })
94
- });
95
- });
96
-
97
-
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
-
112
- // re-exporting MarkdownEditor directly explodes @parcel/transformer-typescript-types :shrug:
113
- const $df9eabe9bda49ea8$export$18a9461578883ec4 = (0, $483dd42bf797352b$export$18a9461578883ec4);
114
- const $df9eabe9bda49ea8$export$f225414958dd8925 = (0, $jPEKE$createPlugin)({
115
- name: "markdown-editor",
116
- schema: {
117
- types: [
118
- (0, $12cb8b58be9d76a6$export$244155b8997cef98)
119
- ]
120
- }
121
- });
122
-
123
-
124
- export {$df9eabe9bda49ea8$export$18a9461578883ec4 as MarkdownEditor, $df9eabe9bda49ea8$export$f225414958dd8925 as markdownSchema, $12cb8b58be9d76a6$export$244155b8997cef98 as markdownSchemaType};
125
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
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,IA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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":"../"}