sanity-plugin-markdown

9.0.129.0.13
dist/commonExports-DUIsA63O.js.map
+dist/commonExports-DUIsA63O.js.mapNew file
+1
Index: package/dist/commonExports-DUIsA63O.js.map
===================================================================
--- package/dist/commonExports-DUIsA63O.js.map
+++ package/dist/commonExports-DUIsA63O.js.map
@@ -0,0 +1,1 @@
+{"version":3,"file":"commonExports-DUIsA63O.js","names":["{onBlur, onFocus, ref: elementRef}","{options: mdeCustomOptions, ...reactMdeProps} = {}","value = ''","{apiVersion: '2022-01-01'}","(schemaType.options as MarkdownOptions | undefined) ?? {}","options","() => ref.current","(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    }","client.assets","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      spellChecker: false,\n      sideBySideFullscreen: false,\n      uploadImage: true,\n      imageUploadFunction: imageUpload,\n      toolbar: defaultMdeTools,\n      status: false,\n      ...mdeCustomOptions,\n      autofocus: shouldAutoFocus,\n    }","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])","[focused, shouldAutoFocus]","() => {\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  }","raf","(newValue: string) => {\n      onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n    }","useCallback(\n    (newValue: string) => {\n      onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n    },\n    [onChange],\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>"],"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,MAAM,iBAAiB,WAAW,OAAO,yBAAyB,GAE5D,sBAAsB,OAAO,GAAG,CAAC,CAAA,WAAA;;;AAEzB,CAAA,CAAA,mCAAA,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,iBACxC,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,OAAO,8EAKnD,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,yDAK/C,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,OAAO,yGAI/C,EAAC,YAAW,MAAM,OAAO,MAAM,YAAY,SAAS,SAAS,GAAG,qFAIhE,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,iCAI1D,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,+HAOpC,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,wCAI/C,EAAC,YAAW,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG,i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