import { useUniqueId } from "@charcuterie/logic" import { defaultKeymap, history, historyKeymap, } from "@codemirror/commands" import { markdown, markdownLanguage, } from "@codemirror/lang-markdown" import { Compartment, EditorState } from "@codemirror/state" import { EditorView, keymap, placeholder as placeholderExtension, } from "@codemirror/view" import type { ReactNode } from "react" import { useEffect, useRef, useState } from "react" import type { MarkdownEditorIcons, MarkdownImageUpload, } from "../MarkdownEditor/MarkdownEditor.tsx" import type { MarkdownSelection } from "../MarkdownEditor/markdownCommands.ts" import { continueList, getMinimalEdit, indentLines, insertLink, insertText, isLinkPaste, MARKDOWN_LINE_PREFIXES, outdentLines, toggleHeading, toggleInlineMarker, toggleLinePrefix, toMarkdownImage, wrapSelectionInLink, } from "../MarkdownEditor/markdownCommands.ts" import { Switch } from "../Switch/Switch.tsx" import type { SlotProps } from "../slotProps.ts" import { Toolbar } from "../Toolbar/Toolbar.tsx" import { toClassName } from "../toClassName.ts" import { livePreview, setLivePreviewRawMode, } from "./livePreview.ts" export type MarkdownEditorCodeMirrorProps = SlotProps & { className?: string /** * **Initial** only, and the same uncontrolled contract as the * sibling `MarkdownEditor` — for the same reason, one layer over: * reassigning the whole document from outside throws away the * undo history that belonged to it. Swap documents with a `key`. */ defaultValue?: string /** Start in raw-markdown mode. **Initial** only. */ isRawModeDefault?: boolean icons?: MarkdownEditorIcons isDisabled?: boolean isReadOnly?: boolean /** * The accessible name. Omit it inside a `Field`, which supplies a * real `