sanity-plugin-markdown

9.0.29.0.3
dist/commonExports.js.map
dist/commonExports.js.mapDeleted
−1
Index: package/dist/commonExports.js.map
===================================================================
--- package/dist/commonExports.js.map
+++ package/dist/commonExports.js.map
@@ -1,1 +0,0 @@
-{"version":3,"file":"commonExports.js","names":["Box","Text","Options","EasyMdeOptions","lazy","Suspense","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","SimpleMDEReactProps","PatchEvent","set","StringInputProps","unset","useClient","styled","MarkdownOptions","SimpleMdeReact","MarkdownInputStyles","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","MarkdownInputProps","reactMdeProps","Omit","defaultMdeTools","MarkdownInput","props","$","_c","value","t0","onChange","elementProps","t1","t2","schemaType","focused","undefined","onBlur","onFocus","ref","elementRef","t3","mdeCustomOptions","options","t4","Symbol","for","apiVersion","client","t5","imageUrl","shouldAutoFocus","setShouldAutoFocus","t6","current","t7","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","imageUpload","t8","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","autofocus","mdeOptions","t10","t9","node","raf","requestAnimationFrame","contains","document","activeElement","cancelAnimationFrame","raf_0","t11","newValue","from","handleChange","t12","fallback","SanityImageAssetDocument","defineType","StringDefinition","MarkdownInput","markdownTypeName","MarkdownOptions","imageUrl","imageAsset","MarkdownDefinition","Omit","type","options","IntrinsicDefinitions","markdown","markdownSchemaType","name","title","components","input","definePlugin","Plugin","StringInputProps","markdownSchemaType","MarkdownConfig","input","props","React","ReactElement","markdownSchema","config","name","schema","types","components"],"sources":["../src/components/MarkdownInput.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["// TODO: when upgrading to @sanity/ui@4 start using the new tokens\n// oxlint-disable typescript/no-deprecated\n\nimport {Box, Text} from '@sanity/ui'\n// `import type` (not an inline type specifier) so the bundle keeps no side-effect\n// `import 'easymde'`, which would break SSR/Node (easymde touches `document` on load)\nimport type {Options as EasyMdeOptions} from 'easymde'\nimport {\n  lazy,\n  Suspense,\n  useCallback,\n  useEffect,\n  useImperativeHandle,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n// dont import non-types here, it will break SSR on next\nimport type {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, type StringInputProps, unset, useClient} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {MarkdownOptions} from '../schema'\n\nconst SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nconst MarkdownInputStyles = styled(Box)`\n  & .CodeMirror.CodeMirror {\n    color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n    border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n    background-color: inherit;\n  }\n\n  & .cm-s-easymde .CodeMirror-cursor {\n    border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n  }\n\n  & .editor-toolbar,\n  .editor-preview-side {\n    border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n  }\n\n  & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n    background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};\n  }\n\n  & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n    background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n  }\n\n  & .editor-toolbar > * {\n    color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n  }\n\n  & .editor-toolbar > .active,\n  .editor-toolbar > button:hover,\n  .editor-preview pre,\n  .cm-s-easymde .cm-comment {\n    background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n  }\n\n  & .editor-preview {\n    background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n\n    & h1,\n    h2,\n    h3,\n    h4,\n    h5,\n    h6 {\n      font-size: revert;\n    }\n\n    & ul,\n    li {\n      list-style: revert;\n      padding: revert;\n    }\n\n    & a {\n      text-decoration: revert;\n    }\n  }\n`\n\nexport interface MarkdownInputProps extends StringInputProps {\n  /**\n   * These are passed along directly to\n   *\n   * Note: MarkdownInput sets certain reactMdeProps.options by default.\n   * These will be merged with any custom options.\n   */\n  reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>\n}\n\nexport const defaultMdeTools: EasyMdeOptions['toolbar'] = [\n  'heading',\n  'bold',\n  'italic',\n  '|',\n  'quote',\n  'unordered-list',\n  'ordered-list',\n  '|',\n  'link',\n  'image',\n  'code',\n  '|',\n  'preview',\n  'side-by-side',\n]\n\nexport function MarkdownInput(props: MarkdownInputProps): React.JSX.Element {\n  const {\n    value = '',\n    onChange,\n    elementProps: {onBlur, onFocus, ref: elementRef},\n    reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n    schemaType,\n    focused,\n  } = props\n  const client = useClient({apiVersion: '2022-01-01'})\n  // oxlint-disable-next-line no-unsafe-type-assertion\n  const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\n  const [shouldAutoFocus, setShouldAutoFocus] = useState(false)\n  const ref = useRef<HTMLDivElement>(null)\n\n  // Forward ref to parent form state\n  useImperativeHandle(elementRef, () => ref.current)\n\n  const imageUpload = useCallback(\n    (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {\n      client.assets\n        .upload('image', file)\n        .then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))\n        .catch((e) => {\n          console.error(e)\n          onError(e.message)\n        })\n    },\n    [client, imageUrl],\n  )\n\n  const mdeOptions: EasyMdeOptions = useMemo(() => {\n    return {\n      spellChecker: false,\n      sideBySideFullscreen: false,\n      uploadImage: true,\n      imageUploadFunction: imageUpload,\n      toolbar: defaultMdeTools,\n      status: false,\n      ...mdeCustomOptions,\n      autofocus: shouldAutoFocus,\n    }\n  }, [imageUpload, mdeCustomOptions, shouldAutoFocus])\n\n  useEffect(() => {\n    const node = ref.current\n    if (!node) return undefined\n\n    if (focused && !shouldAutoFocus) {\n      // Do not set autofocus if the field already has focus\n      const raf = requestAnimationFrame(() =>\n        setShouldAutoFocus(!node.contains(document.activeElement)),\n      )\n      return () => cancelAnimationFrame(raf)\n    }\n\n    if (!focused && shouldAutoFocus) {\n      // If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state\n      const raf = requestAnimationFrame(() =>\n        setShouldAutoFocus(node.contains(document.activeElement)),\n      )\n      return () => cancelAnimationFrame(raf)\n    }\n\n    return undefined\n  }, [focused, shouldAutoFocus])\n\n  const handleChange = useCallback(\n    (newValue: string) => {\n      onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n    },\n    [onChange],\n  )\n\n  return (\n    <MarkdownInputStyles>\n      <Suspense fallback={fallback}>\n        <SimpleMdeReact\n          {...reactMdeProps}\n          ref={ref}\n          value={value}\n          onChange={handleChange}\n          onBlur={onBlur}\n          onFocus={onFocus}\n          options={mdeOptions}\n          spellCheck={false}\n        />\n      </Suspense>\n    </MarkdownInputStyles>\n  )\n}\n\nconst fallback = (\n  <Box padding={3}>\n    <Text>Loading editor...</Text>\n  </Box>\n)\n","import type {SanityImageAssetDocument} from '@sanity/client'\nimport {defineType, type StringDefinition} from 'sanity'\n\nimport {MarkdownInput} from './components/MarkdownInput'\n\nexport const markdownTypeName = 'markdown'\n\nexport interface MarkdownOptions {\n  /**\n   * Used to create image url for any uploaded image.\n   * The function will be invoked whenever an image is pasted or dragged into the\n   * markdown editor, after upload completes.\n   *\n   * The default implementation uses\n   * ```js\n   * imageAsset => `${imageAsset.url}?w=450`\n   * ```\n   * ## Example\n   * ```js\n   * {\n   *   imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`\n   * }\n   * ```\n   * @param imageAsset\n   */\n  imageUrl?: (imageAsset: SanityImageAssetDocument) => string\n}\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n  type: typeof markdownTypeName\n  options?: MarkdownOptions\n}\n\ndeclare module 'sanity' {\n  // makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember\n  export interface IntrinsicDefinitions {\n    markdown: MarkdownDefinition\n  }\n}\n\nexport const markdownSchemaType = defineType({\n  type: 'string',\n  name: markdownTypeName,\n  title: 'Markdown',\n  components: {input: MarkdownInput},\n})\n","import {definePlugin, type Plugin, type StringInputProps} from 'sanity'\n\nimport {markdownSchemaType} from './schema'\n\nexport interface MarkdownConfig {\n  /**\n   * When provided, will replace the default input component.\n   *\n   * Use this to customize MarkdownInput by wrapping it in a custom component,\n   * and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n   * via the `reactMdeProps` prop.\n   *\n   * ### Example\n   *\n   * ```tsx\n   * // CustomMarkdownInput.tsx\n   * import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'\n   *\n   * export function CustomMarkdownInput(props) {\n   *   const reactMdeProps: MarkdownInputProps['reactMdeProps'] =\n   *     useMemo(() => {\n   *       return {\n   *         options: {\n   *           toolbar: ['bold', 'italic'],\n   *           // more options available, see:\n   *           // https://github.com/Ionaru/easy-markdown-editor#options-list\n   *         },\n   *         // more props available, see:\n   *         // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n   *       }\n   *     }, [])\n   *\n   *   return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />\n   * }\n   *\n   * // studio.config.ts\n   * markdownSchema({input: CustomMarkdownInput})\n   * ```\n   */\n  input?: (props: StringInputProps) => React.ReactElement\n}\n\nexport const markdownSchema: Plugin<MarkdownConfig | void> = definePlugin(\n  (config: MarkdownConfig | void) => {\n    return {\n      name: 'markdown-editor',\n      schema: {\n        types: [\n          config && config.input\n            ? {...markdownSchemaType, components: {input: config.input}}\n            : markdownSchemaType,\n        ],\n      },\n    }\n  },\n)\n"],"mappings":";;;;;;AAwBA,MAAMoB,iBAAiBhB,WAAW,OAAO,yBAAyB,GAE5DiB,sBAAsBH,OAAOlB,GAAG,CAAC,CAAA,WAAA;;;qCAEzB,EAACsB,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,GAAE,iBACvC,EA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