@usememos/editor 26.10.24 → 26.10.26

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/dist/react.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/react/index.tsx"],
4
- "sourcesContent": ["import { Editor, type EditorOptions, type SuggestionState } from '@usememos/editor';\nimport { type CSSProperties, type ForwardedRef, forwardRef, useEffect, useRef, useState } from 'react';\nimport { flushSync } from 'react-dom';\n\nexport type { Editor, SuggestionState } from '@usememos/editor';\n\n/** Constructor options that the React components take as props. */\ntype EditorProps = Pick<\n EditorOptions,\n | 'markdown'\n | 'extensions'\n | 'placeholder'\n | 'mode'\n | 'smartLists'\n | 'editable'\n | 'taskToggle'\n | 'autofocus'\n | 'attributes'\n | 'resolveUrl'\n | 'referrerPolicy'\n | 'headingIds'\n | 'onLinkClick'\n | 'theme'\n | 'toolbar'\n | 'linkCard'\n | 'slashMenu'\n | 'slashHint'\n | 'labels'\n | 'icons'\n>;\n\nexport interface MarkdownEditorProps extends EditorProps {\n /** Markdown. The editor updates only when this is not a value it emitted itself. */\n value?: string;\n /** Initial Markdown for uncontrolled use. */\n defaultValue?: string;\n /** Called after document changes, at most once per animation frame. */\n onChange?: (markdown: string) => void;\n /** Called on Mod+Enter or Ctrl+Enter with the current Markdown. */\n onSubmit?: (markdown: string) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n className?: string;\n style?: CSSProperties;\n}\n\n/** Options that `setOptions` applies without recreating the editor. `extensions` updates suggestion callbacks only. */\nconst LIVE = ['placeholder', 'mode', 'editable', 'taskToggle', 'attributes', 'resolveUrl', 'onLinkClick', 'theme', 'extensions'] as const;\n\n/** The extension list's identity for recreating the editor: names, so an inline array does not recreate it on every render. */\nconst extensionKey = (extensions: EditorOptions['extensions']) => (extensions ?? []).map((e) => e.name).join('\\n');\n\n/**\n * The editor as a controlled React component. A `ref` gives the core `Editor`.\n *\n * `placeholder`, `mode`, `editable`, `taskToggle`, `attributes`, `resolveUrl`, `onLinkClick` and `theme` update live.\n * A change to the names in `extensions` recreates the editor, keeping its\n * Markdown; with the same names, the callbacks of `suggestion()` extensions\n * (`items`, `command`, `match`, `allow`) update live. Other props are read\n * when the editor is created; change the component's `key` to apply new values.\n *\n * A `value` that arrives while an input method is composing text is applied\n * when the composition ends, so it does not break the composition.\n */\nexport const MarkdownEditor = forwardRef(function MarkdownEditor(props: MarkdownEditorProps, ref: ForwardedRef<Editor | null>) {\n const container = useRef<HTMLDivElement>(null);\n const editorRef = useRef<Editor | null>(null);\n // Values the editor emitted that the parent has not passed back yet, oldest\n // first. While the user keeps typing, React may hand back an older one;\n // those echoes must not reset the document.\n const pending = useRef<string[]>([]);\n // An outside value that arrived during IME composition.\n const deferred = useRef<string | null>(null);\n // Callbacks are read through a ref so changing them does not recreate the editor.\n const latest = useRef(props);\n latest.current = props;\n const extensions = extensionKey(props.extensions);\n\n useEffect(() => {\n const { value, defaultValue, onChange, onSubmit, onFocus, onBlur, className, style, ...options } = latest.current;\n const previous = editorRef.current;\n const editor = new Editor({\n ...options,\n element: container.current!,\n content: previous?.getMarkdown() ?? value ?? defaultValue ?? '',\n onChange: (markdown) => {\n pending.current.push(markdown);\n if (pending.current.length > 100) pending.current.shift();\n // Render the parent's update now, as React does for a native input's\n // onChange. Left to React's scheduler, it can still be waiting when\n // the parent sets a new value (clearing the box on submit) that equals\n // the value it last rendered; the value effect would then not run.\n flushSync(() => latest.current.onChange?.(markdown));\n },\n onSubmit: (markdown) => latest.current.onSubmit?.(markdown),\n onFocus: () => latest.current.onFocus?.(),\n onBlur: () => latest.current.onBlur?.(),\n });\n editorRef.current = editor;\n pending.current = [];\n assignRef(ref, editor);\n const root = container.current!;\n const onCompositionEnd = () => {\n // Runs after the editor's own compositionend handler, which was added first.\n const value = deferred.current;\n deferred.current = null;\n if (value !== null && value !== editor.getMarkdown()) {\n pending.current = [];\n editor.setMarkdown(value);\n }\n };\n root.addEventListener('compositionend', onCompositionEnd);\n return () => {\n root.removeEventListener('compositionend', onCompositionEnd);\n editor.destroy();\n if (editorRef.current === editor) editorRef.current = null;\n assignRef(ref, null);\n };\n // Recreate only when the extension names change; see the note on the component.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [extensions]);\n\n useEffect(() => {\n const editor = editorRef.current;\n if (!editor || props.value === undefined) return;\n const echo = pending.current.indexOf(props.value);\n if (echo >= 0) {\n // The parent caught up to a value the editor emitted.\n pending.current.splice(0, echo + 1);\n return;\n }\n if (props.value === editor.getMarkdown()) return;\n if (editor.isComposing) {\n deferred.current = props.value;\n return;\n }\n pending.current = [];\n editor.setMarkdown(props.value);\n }, [props.value]);\n\n useLiveOptions(editorRef, props);\n\n return <div ref={container} className={props.className} style={props.style} />;\n});\n\n/** Applies the live options when they change. */\nfunction useLiveOptions(editorRef: { current: Editor | null }, props: EditorProps): void {\n const applied = useRef<{ editor: Editor | null; props: Partial<EditorProps> }>({ editor: null, props: {} });\n useEffect(() => {\n const editor = editorRef.current;\n if (!editor) return;\n if (applied.current.editor !== editor) {\n // A new editor was created with these props.\n applied.current = { editor, props: { ...props } };\n return;\n }\n const changed: Partial<Pick<EditorOptions, (typeof LIVE)[number]>> = {};\n let any = false;\n for (const key of LIVE) {\n if (props[key] === applied.current.props[key]) continue;\n (changed as Record<string, unknown>)[key] = key === 'editable' ? (props.editable ?? true) : key === 'mode' ? (props.mode ?? 'rich') : key === 'taskToggle' ? (props.taskToggle ?? false) : props[key];\n any = true;\n }\n applied.current = { editor, props: { ...props } };\n if (any) editor.setOptions(changed);\n });\n}\n\n/**\n * Creates an editor for the lifetime of the component, or until a value in\n * `deps` changes. Returns null until the editor exists. Pair it with\n * `<EditorContent editor={editor} />`, which shows it.\n *\n * Callbacks in `options` are read when called, so they may change between\n * renders without recreating the editor. So do the callbacks of\n * `suggestion()` extensions, matched by name.\n */\nexport function useEditor(options: Omit<EditorOptions, 'element'>, deps: readonly unknown[] = []): Editor | null {\n const [editor, setEditor] = useState<Editor | null>(null);\n const latest = useRef(options);\n latest.current = options;\n\n useEffect(() => {\n if (editor && options.extensions) editor.setOptions({ extensions: options.extensions });\n }, [editor, options.extensions]);\n\n useEffect(() => {\n const o = latest.current;\n const element = document.createElement('div');\n const instance = new Editor({\n ...o,\n element,\n // A detached element cannot take focus; EditorContent focuses once mounted.\n autofocus: false,\n onChange: (markdown, e) => latest.current.onChange?.(markdown, e),\n onSubmit: (markdown, e) => latest.current.onSubmit?.(markdown, e),\n onFocus: (e) => latest.current.onFocus?.(e),\n onBlur: (e) => latest.current.onBlur?.(e),\n onLinkClick: (ctx) => latest.current.onLinkClick?.(ctx),\n });\n if (o.autofocus) pendingAutofocus.set(instance, o.autofocus === 'end' ? 'end' : 'start');\n setEditor(instance);\n return () => {\n instance.destroy();\n setEditor(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return editor;\n}\n\n/**\n * The open autocomplete popup of `editor`, or of its suggestion `name`, and\n * a re-render on each change. With `render: false` on a suggestion, draw your\n * own popup from it: put it at `state.anchorRect()`, give the listbox\n * `id={state.listboxId}` and each option `id={state.optionId(i)}`, highlight\n * `state.active`, and call `editor.suggestion.accept(i)` on click.\n */\nexport function useSuggestion(editor: Editor | null, name?: string): SuggestionState | null {\n const select = (state: SuggestionState | null | undefined) => (state && (name === undefined || state.name === name) ? state : null);\n const [state, setState] = useState<SuggestionState | null>(() => select(editor?.suggestion.state));\n useEffect(() => {\n if (!editor) {\n setState(null);\n return;\n }\n setState(select(editor.suggestion.state));\n return editor.on('suggestionChange', ({ state }) => setState(select(state)));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor, name]);\n return state;\n}\n\nexport interface EditorContentProps {\n editor: Editor | null;\n className?: string;\n style?: CSSProperties;\n}\n\n/** Shows an editor created with `useEditor`. */\nexport function EditorContent({ editor, className, style }: EditorContentProps) {\n const container = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const host = container.current;\n if (!editor || !host) return;\n host.appendChild(editor.root);\n const autofocus = pendingAutofocus.get(editor);\n if (autofocus) {\n pendingAutofocus.delete(editor);\n editor.commands.focus(autofocus);\n }\n return () => {\n if (editor.root.parentNode === host) host.removeChild(editor.root);\n };\n }, [editor]);\n return <div ref={container} className={className} style={style} />;\n}\n\n/** Where to focus an editor from `useEditor` once `EditorContent` mounts it. */\nconst pendingAutofocus = new WeakMap<Editor, 'start' | 'end'>();\n\nfunction assignRef<T>(ref: ForwardedRef<T>, value: T): void {\n if (typeof ref === 'function') ref(value);\n else if (ref) ref.current = value;\n}\n"],
5
- "mappings": ";AAAA,SAAS,cAAwD;AACjE,SAAgD,YAAY,WAAW,QAAQ,gBAAgB;AAC/F,SAAS,iBAAiB;AA4IjB;AA/FT,IAAM,OAAO,CAAC,eAAe,QAAQ,YAAY,cAAc,cAAc,cAAc,eAAe,SAAS,YAAY;AAG/H,IAAM,eAAe,CAAC,gBAA6C,cAAc,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI;AAc1G,IAAM,iBAAiB,WAAW,SAASA,gBAAe,OAA4B,KAAkC;AAC7H,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,YAAY,OAAsB,IAAI;AAI5C,QAAM,UAAU,OAAiB,CAAC,CAAC;AAEnC,QAAM,WAAW,OAAsB,IAAI;AAE3C,QAAM,SAAS,OAAO,KAAK;AAC3B,SAAO,UAAU;AACjB,QAAM,aAAa,aAAa,MAAM,UAAU;AAEhD,YAAU,MAAM;AACd,UAAM,EAAE,OAAO,cAAc,UAAU,UAAU,SAAS,QAAQ,WAAW,OAAO,GAAG,QAAQ,IAAI,OAAO;AAC1G,UAAM,WAAW,UAAU;AAC3B,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,GAAG;AAAA,MACH,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU,YAAY,KAAK,SAAS,gBAAgB;AAAA,MAC7D,UAAU,CAAC,aAAa;AACtB,gBAA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AI;AAC5B,UAAM,YAAY,iBAAiB,IAAI,MAAM;AAC7C,QAAI,WAAW;AACb,uBAAiB,OAAO,MAAM;AAC9B,aAAO,SAAS,MAAM,SAAS;AAAA,IACjC;AACA,WAAO,MAAM;AACX,UAAI,OAAO,KAAK,eAAe,KAAM,MAAK,YAAY,OAAO,IAAI;AAAA,IACnE;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACX,SAAO,oBAAC,SAAI,KAAK,WAAW,WAAsB,OAAc;AAClE;AAGA,IAAM,mBAAmB,oBAAI,QAAiC;AAE9D,SAAS,UAAa,KAAsB,OAAgB;AAC1D,MAAI,OAAO,QAAQ,WAAY,KAAI,KAAK;AAAA,WAC/B,IAAK,KAAI,UAAU;AAC9B;",
4
+ "sourcesContent": ["import { Editor, type EditorOptions, type SuggestionState } from '@usememos/editor';\nimport { type CSSProperties, type ForwardedRef, forwardRef, useEffect, useRef, useState } from 'react';\nimport { flushSync } from 'react-dom';\n\nexport type { Editor, SuggestionState } from '@usememos/editor';\n\n/** Constructor options that the React components take as props. */\ntype EditorProps = Pick<\n EditorOptions,\n | 'markdown'\n | 'extensions'\n | 'placeholder'\n | 'mode'\n | 'smartLists'\n | 'sourceHighlighting'\n | 'editable'\n | 'taskToggle'\n | 'autofocus'\n | 'attributes'\n | 'resolveUrl'\n | 'referrerPolicy'\n | 'headingIds'\n | 'onLinkClick'\n | 'theme'\n | 'toolbar'\n | 'linkCard'\n | 'slashMenu'\n | 'slashHint'\n | 'labels'\n | 'icons'\n>;\n\nexport interface MarkdownEditorProps extends EditorProps {\n /** Markdown. The editor updates only when this is not a value it emitted itself. */\n value?: string;\n /** Initial Markdown for uncontrolled use. */\n defaultValue?: string;\n /** Called after document changes, at most once per animation frame. */\n onChange?: (markdown: string) => void;\n /** Called on Mod+Enter or Ctrl+Enter with the current Markdown. */\n onSubmit?: (markdown: string) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n className?: string;\n style?: CSSProperties;\n}\n\n/** Options that `setOptions` applies without recreating the editor. `extensions` updates suggestion callbacks only. */\nconst LIVE = ['placeholder', 'mode', 'editable', 'taskToggle', 'attributes', 'resolveUrl', 'onLinkClick', 'theme', 'extensions'] as const;\n\n/** The extension list's identity for recreating the editor: names, so an inline array does not recreate it on every render. */\nconst extensionKey = (extensions: EditorOptions['extensions']) => (extensions ?? []).map((e) => e.name).join('\\n');\n\n/**\n * The editor as a controlled React component. A `ref` gives the core `Editor`.\n *\n * `placeholder`, `mode`, `editable`, `taskToggle`, `attributes`, `resolveUrl`, `onLinkClick` and `theme` update live.\n * A change to the names in `extensions` recreates the editor, keeping its\n * Markdown; with the same names, the callbacks of `suggestion()` extensions\n * (`items`, `command`, `match`, `allow`) update live. Other props are read\n * when the editor is created; change the component's `key` to apply new values.\n *\n * A `value` that arrives while an input method is composing text is applied\n * when the composition ends, so it does not break the composition.\n */\nexport const MarkdownEditor = forwardRef(function MarkdownEditor(props: MarkdownEditorProps, ref: ForwardedRef<Editor | null>) {\n const container = useRef<HTMLDivElement>(null);\n const editorRef = useRef<Editor | null>(null);\n // Values the editor emitted that the parent has not passed back yet, oldest\n // first. While the user keeps typing, React may hand back an older one;\n // those echoes must not reset the document.\n const pending = useRef<string[]>([]);\n // An outside value that arrived during IME composition.\n const deferred = useRef<string | null>(null);\n // Callbacks are read through a ref so changing them does not recreate the editor.\n const latest = useRef(props);\n latest.current = props;\n const extensions = extensionKey(props.extensions);\n\n useEffect(() => {\n const { value, defaultValue, onChange, onSubmit, onFocus, onBlur, className, style, ...options } = latest.current;\n const previous = editorRef.current;\n const editor = new Editor({\n ...options,\n element: container.current!,\n content: previous?.getMarkdown() ?? value ?? defaultValue ?? '',\n onChange: (markdown) => {\n pending.current.push(markdown);\n if (pending.current.length > 100) pending.current.shift();\n // Render the parent's update now, as React does for a native input's\n // onChange. Left to React's scheduler, it can still be waiting when\n // the parent sets a new value (clearing the box on submit) that equals\n // the value it last rendered; the value effect would then not run.\n flushSync(() => latest.current.onChange?.(markdown));\n },\n onSubmit: (markdown) => latest.current.onSubmit?.(markdown),\n onFocus: () => latest.current.onFocus?.(),\n onBlur: () => latest.current.onBlur?.(),\n });\n editorRef.current = editor;\n pending.current = [];\n assignRef(ref, editor);\n const root = container.current!;\n const onCompositionEnd = () => {\n // Runs after the editor's own compositionend handler, which was added first.\n const value = deferred.current;\n deferred.current = null;\n if (value !== null && value !== editor.getMarkdown()) {\n pending.current = [];\n editor.setMarkdown(value);\n }\n };\n root.addEventListener('compositionend', onCompositionEnd);\n return () => {\n root.removeEventListener('compositionend', onCompositionEnd);\n editor.destroy();\n if (editorRef.current === editor) editorRef.current = null;\n assignRef(ref, null);\n };\n // Recreate only when the extension names change; see the note on the component.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [extensions]);\n\n useEffect(() => {\n const editor = editorRef.current;\n if (!editor || props.value === undefined) return;\n const echo = pending.current.indexOf(props.value);\n if (echo >= 0) {\n // The parent caught up to a value the editor emitted.\n pending.current.splice(0, echo + 1);\n return;\n }\n if (props.value === editor.getMarkdown()) return;\n if (editor.isComposing) {\n deferred.current = props.value;\n return;\n }\n pending.current = [];\n editor.setMarkdown(props.value);\n }, [props.value]);\n\n useLiveOptions(editorRef, props);\n\n return <div ref={container} className={props.className} style={props.style} />;\n});\n\n/** Applies the live options when they change. */\nfunction useLiveOptions(editorRef: { current: Editor | null }, props: EditorProps): void {\n const applied = useRef<{ editor: Editor | null; props: Partial<EditorProps> }>({ editor: null, props: {} });\n useEffect(() => {\n const editor = editorRef.current;\n if (!editor) return;\n if (applied.current.editor !== editor) {\n // A new editor was created with these props.\n applied.current = { editor, props: { ...props } };\n return;\n }\n const changed: Partial<Pick<EditorOptions, (typeof LIVE)[number]>> = {};\n let any = false;\n for (const key of LIVE) {\n if (props[key] === applied.current.props[key]) continue;\n (changed as Record<string, unknown>)[key] = key === 'editable' ? (props.editable ?? true) : key === 'mode' ? (props.mode ?? 'rich') : key === 'taskToggle' ? (props.taskToggle ?? false) : props[key];\n any = true;\n }\n applied.current = { editor, props: { ...props } };\n if (any) editor.setOptions(changed);\n });\n}\n\n/**\n * Creates an editor for the lifetime of the component, or until a value in\n * `deps` changes. Returns null until the editor exists. Pair it with\n * `<EditorContent editor={editor} />`, which shows it.\n *\n * Callbacks in `options` are read when called, so they may change between\n * renders without recreating the editor. So do the callbacks of\n * `suggestion()` extensions, matched by name.\n */\nexport function useEditor(options: Omit<EditorOptions, 'element'>, deps: readonly unknown[] = []): Editor | null {\n const [editor, setEditor] = useState<Editor | null>(null);\n const latest = useRef(options);\n latest.current = options;\n\n useEffect(() => {\n if (editor && options.extensions) editor.setOptions({ extensions: options.extensions });\n }, [editor, options.extensions]);\n\n useEffect(() => {\n const o = latest.current;\n const element = document.createElement('div');\n const instance = new Editor({\n ...o,\n element,\n // A detached element cannot take focus; EditorContent focuses once mounted.\n autofocus: false,\n onChange: (markdown, e) => latest.current.onChange?.(markdown, e),\n onSubmit: (markdown, e) => latest.current.onSubmit?.(markdown, e),\n onFocus: (e) => latest.current.onFocus?.(e),\n onBlur: (e) => latest.current.onBlur?.(e),\n onLinkClick: (ctx) => latest.current.onLinkClick?.(ctx),\n });\n if (o.autofocus) pendingAutofocus.set(instance, o.autofocus === 'end' ? 'end' : 'start');\n setEditor(instance);\n return () => {\n instance.destroy();\n setEditor(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return editor;\n}\n\n/**\n * The open autocomplete popup of `editor`, or of its suggestion `name`, and\n * a re-render on each change. With `render: false` on a suggestion, draw your\n * own popup from it: put it at `state.anchorRect()`, give the listbox\n * `id={state.listboxId}` and each option `id={state.optionId(i)}`, highlight\n * `state.active`, and call `editor.suggestion.accept(i)` on click.\n */\nexport function useSuggestion(editor: Editor | null, name?: string): SuggestionState | null {\n const select = (state: SuggestionState | null | undefined) => (state && (name === undefined || state.name === name) ? state : null);\n const [state, setState] = useState<SuggestionState | null>(() => select(editor?.suggestion.state));\n useEffect(() => {\n if (!editor) {\n setState(null);\n return;\n }\n setState(select(editor.suggestion.state));\n return editor.on('suggestionChange', ({ state }) => setState(select(state)));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor, name]);\n return state;\n}\n\nexport interface EditorContentProps {\n editor: Editor | null;\n className?: string;\n style?: CSSProperties;\n}\n\n/** Shows an editor created with `useEditor`. */\nexport function EditorContent({ editor, className, style }: EditorContentProps) {\n const container = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const host = container.current;\n if (!editor || !host) return;\n host.appendChild(editor.root);\n const autofocus = pendingAutofocus.get(editor);\n if (autofocus) {\n pendingAutofocus.delete(editor);\n editor.commands.focus(autofocus);\n }\n return () => {\n if (editor.root.parentNode === host) host.removeChild(editor.root);\n };\n }, [editor]);\n return <div ref={container} className={className} style={style} />;\n}\n\n/** Where to focus an editor from `useEditor` once `EditorContent` mounts it. */\nconst pendingAutofocus = new WeakMap<Editor, 'start' | 'end'>();\n\nfunction assignRef<T>(ref: ForwardedRef<T>, value: T): void {\n if (typeof ref === 'function') ref(value);\n else if (ref) ref.current = value;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,cAAwD;AACjE,SAAgD,YAAY,WAAW,QAAQ,gBAAgB;AAC/F,SAAS,iBAAiB;AA6IjB;AA/FT,IAAM,OAAO,CAAC,eAAe,QAAQ,YAAY,cAAc,cAAc,cAAc,eAAe,SAAS,YAAY;AAG/H,IAAM,eAAe,CAAC,gBAA6C,cAAc,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI;AAc1G,IAAM,iBAAiB,WAAW,SAASA,gBAAe,OAA4B,KAAkC;AAC7H,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,YAAY,OAAsB,IAAI;AAI5C,QAAM,UAAU,OAAiB,CAAC,CAAC;AAEnC,QAAM,WAAW,OAAsB,IAAI;AAE3C,QAAM,SAAS,OAAO,KAAK;AAC3B,SAAO,UAAU;AACjB,QAAM,aAAa,aAAa,MAAM,UAAU;AAEhD,YAAU,MAAM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AM,SAAS,OAAOA,MAAK,CAAC,CAAC;AAAA,EAE7E,GAAG,CAAC,QAAQ,IAAI,CAAC;AACjB,SAAO;AACT;AASO,SAAS,cAAc,EAAE,QAAQ,WAAW,MAAM,GAAuB;AAC9E,QAAM,YAAY,OAAuB,IAAI;AAC7C,YAAU,MAAM;AACd,UAAM,OAAO,UAAU;AACvB,QAAI,CAAC,UAAU,CAAC,KAAM;AACtB,SAAK,YAAY,OAAO,IAAI;AAC5B,UAAM,YAAY,iBAAiB,IAAI,MAAM;AAC7C,QAAI,WAAW;AACb,uBAAiB,OAAO,MAAM;AAC9B,aAAO,SAAS,MAAM,SAAS;AAAA,IACjC;AACA,WAAO,MAAM;AACX,UAAI,OAAO,KAAK,eAAe,KAAM,MAAK,YAAY,OAAO,IAAI;AAAA,IACnE;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACX,SAAO,oBAAC,SAAI,KAAK,WAAW,WAAsB,OAAc;AAClE;AAGA,IAAM,mBAAmB,oBAAI,QAAiC;AAE9D,SAAS,UAAa,KAAsB,OAAgB;AAC1D,MAAI,OAAO,QAAQ,WAAY,KAAI,KAAK;AAAA,WAC/B,IAAK,KAAI,UAAU;AAC9B;",
6
6
  "names": ["MarkdownEditor", "value", "state"]
7
7
  }
package/dist/style.css CHANGED
@@ -312,6 +312,9 @@
312
312
  tab-size: 4;
313
313
  overflow-wrap: anywhere;
314
314
  }
315
+ .mbe-root > .mbe-source .mbe-source-line {
316
+ display: block;
317
+ }
315
318
  :is(.mbe-root, .mbe-flow) > .mbe-code pre {
316
319
  margin: 0;
317
320
  }
@@ -332,6 +335,34 @@
332
335
  cursor: default;
333
336
  white-space: normal;
334
337
  }
338
+ :is(.mbe-root, .mbe-flow, .mbe-footnotes) > .mbe-footnote {
339
+ display: grid;
340
+ grid-template-columns: auto 1fr;
341
+ column-gap: 0.375em;
342
+ align-items: baseline;
343
+ }
344
+ :is(.mbe-root, .mbe-flow, .mbe-footnotes) > .mbe-footnote > :last-child {
345
+ min-width: 0;
346
+ }
347
+ .mbe-root > .mbe-footnote-collected {
348
+ display: none;
349
+ }
350
+ .mbe-root > .mbe-footnotes {
351
+ margin-top: 16px;
352
+ cursor: default;
353
+ }
354
+ .mbe-root > .mbe-footnotes > .mbe-footnote + .mbe-footnote {
355
+ margin-top: 4px;
356
+ }
357
+ .mbe-root .mbe-footnote-backref {
358
+ display: inline-flex;
359
+ align-items: center;
360
+ vertical-align: -0.125em;
361
+ }
362
+ .mbe-root .mbe-footnote-backref .mbe-icon {
363
+ width: 0.875em;
364
+ height: 0.875em;
365
+ }
335
366
  .mbe-root.mbe-readonly :is([data-mbe-tag], [data-mbe-mention]) {
336
367
  cursor: pointer;
337
368
  }
@@ -384,14 +415,16 @@
384
415
  overflow-x: auto;
385
416
  }
386
417
  :is(.mbe-root, .mbe-flow) > .mbe-table table {
418
+ width: 100%;
387
419
  border-collapse: separate;
388
420
  border-spacing: 0;
389
421
  }
390
422
  :is(.mbe-root, .mbe-flow) > .mbe-table th,
391
423
  :is(.mbe-root, .mbe-flow) > .mbe-table td {
392
- padding: 4px 8px;
424
+ padding: 0.4375em 0.75em;
393
425
  vertical-align: top;
394
426
  text-align: start;
427
+ overflow-wrap: break-word;
395
428
  outline: none;
396
429
  }
397
430
  .mbe-root:not(.mbe-readonly) > .mbe-table :is(th, td).mbe-empty-content {
@@ -725,6 +758,7 @@
725
758
  "Liberation Mono",
726
759
  "Courier New",
727
760
  monospace;
761
+ --mbe-source-font: var(--mbe-font);
728
762
  --mbe-font-size: 16px;
729
763
  --mbe-line-height: 24px;
730
764
  --mbe-leading: calc(var(--mbe-line-height) - var(--mbe-font-size));
@@ -747,6 +781,7 @@
747
781
  0 2px 4px -2px light-dark(rgb(0 0 0 / 0.1), transparent);
748
782
  --mbe-block-code-bg: color-mix(in oklab, var(--mbe-code-bg) 45%, transparent);
749
783
  --mbe-quote-border: color-mix(in oklab, var(--mbe-muted) 25%, transparent);
784
+ --mbe-table-header-bg: color-mix(in oklab, var(--mbe-text) 5%, transparent);
750
785
  --mbe-callout-note: light-dark(var(--mbe-callout-note-light, oklch(0.55 0.17 255)), var(--mbe-callout-note-dark, oklch(0.68 0.15 255)));
751
786
  --mbe-callout-tip: light-dark(var(--mbe-callout-tip-light, oklch(0.52 0.13 150)), var(--mbe-callout-tip-dark, oklch(0.72 0.17 150)));
752
787
  --mbe-callout-important: light-dark(var(--mbe-callout-important-light, oklch(0.52 0.2 295)), var(--mbe-callout-important-dark, oklch(0.7 0.15 295)));
@@ -837,13 +872,35 @@
837
872
  .mbe-root.mbe-readonly [data-mbe-mention]:hover {
838
873
  text-decoration: underline;
839
874
  }
840
- :is(.mbe-root, .mbe-flow) > .mbe-footnote {
875
+ :is(.mbe-root, .mbe-flow, .mbe-footnotes) > .mbe-footnote {
841
876
  font-size: 0.875em;
842
877
  color: var(--mbe-muted);
843
878
  }
844
879
  .mbe-root .mbe-footnote-label {
845
- margin-inline-end: 0.375em;
880
+ font-size: 0.75em;
881
+ color: var(--mbe-link);
882
+ }
883
+ .mbe-root > .mbe-footnotes {
884
+ border-top: 1px solid var(--mbe-border);
885
+ padding-top: 8px;
886
+ }
887
+ .mbe-root .mbe-footnote-backref {
888
+ margin-inline-start: 0.375em;
889
+ padding: 0;
890
+ border: 0;
891
+ background: none;
892
+ font: inherit;
893
+ color: var(--mbe-muted);
894
+ opacity: 0.7;
895
+ cursor: pointer;
896
+ }
897
+ .mbe-root .mbe-footnote-backref:hover {
846
898
  color: var(--mbe-link);
899
+ opacity: 1;
900
+ }
901
+ .mbe-root .mbe-footnote-backref sup {
902
+ font-size: 0.75em;
903
+ line-height: 0;
847
904
  }
848
905
  :is(.mbe-root, .mbe-flow) > blockquote {
849
906
  border-inline-start: 3px solid var(--mbe-quote-border);
@@ -957,8 +1014,26 @@
957
1014
  font: inherit;
958
1015
  }
959
1016
  .mbe-root > .mbe-source {
1017
+ font-family: var(--mbe-source-font);
1018
+ }
1019
+ .mbe-root > .mbe-source :is(.mbe-src-marker, .mbe-src-html, .mbe-src-token, .mbe-src-escape, .mbe-src-lang) {
1020
+ color: var(--mbe-muted);
1021
+ }
1022
+ .mbe-root > .mbe-source :is(.mbe-src-heading, .mbe-src-strong) {
1023
+ font-weight: 600;
1024
+ }
1025
+ .mbe-root > .mbe-source .mbe-src-em {
1026
+ font-style: italic;
1027
+ }
1028
+ .mbe-root > .mbe-source .mbe-src-strike {
1029
+ text-decoration: line-through;
1030
+ }
1031
+ .mbe-root > .mbe-source :is(.mbe-src-code, .mbe-src-lang) {
960
1032
  font-family: var(--mbe-mono);
961
1033
  }
1034
+ .mbe-root > .mbe-source .mbe-src-url {
1035
+ color: var(--mbe-link);
1036
+ }
962
1037
  :is(.mbe-root, .mbe-flow) > pre.mbe-raw {
963
1038
  color: var(--mbe-muted);
964
1039
  }
@@ -1007,19 +1082,32 @@
1007
1082
  text-underline-offset: 2px;
1008
1083
  }
1009
1084
  .mbe-root .mbe-view-html table:not(.mbe-flow *) {
1010
- border-collapse: collapse;
1085
+ width: 100%;
1086
+ border-collapse: separate;
1087
+ border-spacing: 0;
1088
+ border: 1px solid var(--mbe-border);
1089
+ border-radius: var(--mbe-radius);
1011
1090
  font-size: calc(var(--mbe-font-size) * 0.875);
1012
1091
  line-height: calc(1em + var(--mbe-leading) * 0.75);
1013
1092
  }
1014
1093
  .mbe-root .mbe-view-html :is(th, td):not(.mbe-flow *) {
1015
- border: 1px solid var(--mbe-border);
1016
- padding: 6px 10px;
1094
+ padding: 0.4375em 0.75em;
1017
1095
  text-align: start;
1018
1096
  vertical-align: top;
1097
+ overflow-wrap: break-word;
1098
+ }
1099
+ .mbe-root .mbe-view-html tr:not(:first-child) > :is(th, td):not(.mbe-flow *) {
1100
+ border-top: 1px solid var(--mbe-border);
1019
1101
  }
1020
1102
  .mbe-root .mbe-view-html th:not(.mbe-flow *) {
1021
1103
  font-weight: 500;
1022
- background: var(--mbe-block-code-bg);
1104
+ background: var(--mbe-table-header-bg);
1105
+ }
1106
+ .mbe-root .mbe-view-html tr:first-child > :first-child:not(.mbe-flow *) {
1107
+ border-start-start-radius: calc(var(--mbe-radius) - 1px);
1108
+ }
1109
+ .mbe-root .mbe-view-html tr:first-child > :last-child:not(.mbe-flow *) {
1110
+ border-start-end-radius: calc(var(--mbe-radius) - 1px);
1023
1111
  }
1024
1112
  .mbe-root .mbe-view-html kbd {
1025
1113
  font-family: var(--mbe-mono);
@@ -1045,15 +1133,12 @@
1045
1133
  border: 1px solid var(--mbe-border);
1046
1134
  border-radius: var(--mbe-radius);
1047
1135
  }
1048
- :is(.mbe-root, .mbe-flow) > .mbe-table :is(th, td):not(:first-child) {
1049
- border-inline-start: 1px solid var(--mbe-border);
1050
- }
1051
1136
  :is(.mbe-root, .mbe-flow) > .mbe-table tr:not(:first-child) > * {
1052
1137
  border-top: 1px solid var(--mbe-border);
1053
1138
  }
1054
1139
  :is(.mbe-root, .mbe-flow) > .mbe-table th {
1055
1140
  font-weight: 500;
1056
- background: var(--mbe-block-code-bg);
1141
+ background: var(--mbe-table-header-bg);
1057
1142
  }
1058
1143
  :is(.mbe-root, .mbe-flow) > .mbe-table tr:first-child > :first-child {
1059
1144
  border-start-start-radius: calc(var(--mbe-radius) - 1px);
package/dist/theme.css CHANGED
@@ -17,6 +17,8 @@
17
17
  --mbe-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans',
18
18
  sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
19
19
  --mbe-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
20
+ /* Source mode's text: the body font, as Obsidian shows source; var(--mbe-mono) for an all-monospace view. */
21
+ --mbe-source-font: var(--mbe-font);
20
22
  --mbe-font-size: 16px;
21
23
  --mbe-line-height: 24px;
22
24
  /* The room a line has around its text. Headings, code and tables size
@@ -50,6 +52,8 @@
50
52
  0 2px 4px -2px light-dark(rgb(0 0 0 / 0.1), transparent);
51
53
  --mbe-block-code-bg: color-mix(in oklab, var(--mbe-code-bg) 45%, transparent);
52
54
  --mbe-quote-border: color-mix(in oklab, var(--mbe-muted) 25%, transparent);
55
+ /* Behind a table's header row: a tint of the text. */
56
+ --mbe-table-header-bg: color-mix(in oklab, var(--mbe-text) 5%, transparent);
53
57
  /* Callout colors: the icon, and a tint of it behind the text. */
54
58
  --mbe-callout-note: light-dark(var(--mbe-callout-note-light, oklch(0.55 0.17 255)), var(--mbe-callout-note-dark, oklch(0.68 0.15 255)));
55
59
  --mbe-callout-tip: light-dark(var(--mbe-callout-tip-light, oklch(0.52 0.13 150)), var(--mbe-callout-tip-dark, oklch(0.72 0.17 150)));
@@ -119,8 +123,24 @@
119
123
  .mbe-root.mbe-readonly .mbe-footnote-ref { cursor: pointer; }
120
124
  /* A mention with an onClick (tags.ts), read-only: underlined on hover, as a name that leads somewhere. */
121
125
  .mbe-root.mbe-readonly [data-mbe-mention]:hover { text-decoration: underline; }
122
- :is(.mbe-root, .mbe-flow) > .mbe-footnote { font-size: 0.875em; color: var(--mbe-muted); }
123
- .mbe-root .mbe-footnote-label { margin-inline-end: 0.375em; color: var(--mbe-link); }
126
+ :is(.mbe-root, .mbe-flow, .mbe-footnotes) > .mbe-footnote { font-size: 0.875em; color: var(--mbe-muted); }
127
+ .mbe-root .mbe-footnote-label { font-size: 0.75em; color: var(--mbe-link); }
128
+ /* The footnotes collected at the end, read-only: under a thin rule, in small
129
+ muted text. A backlink to each reference is a quiet arrow that takes the
130
+ link color on hover, not a boxed glyph. */
131
+ .mbe-root > .mbe-footnotes { border-top: 1px solid var(--mbe-border); padding-top: 8px; }
132
+ .mbe-root .mbe-footnote-backref {
133
+ margin-inline-start: 0.375em;
134
+ padding: 0;
135
+ border: 0;
136
+ background: none;
137
+ font: inherit;
138
+ color: var(--mbe-muted);
139
+ opacity: 0.7;
140
+ cursor: pointer;
141
+ }
142
+ .mbe-root .mbe-footnote-backref:hover { color: var(--mbe-link); opacity: 1; }
143
+ .mbe-root .mbe-footnote-backref sup { font-size: 0.75em; line-height: 0; }
124
144
 
125
145
  /* Quote */
126
146
  :is(.mbe-root, .mbe-flow) > blockquote {
@@ -195,10 +215,17 @@
195
215
  }
196
216
  :is(.mbe-root, .mbe-flow) > .mbe-code pre { padding: 2px 12px 10px; }
197
217
  :is(.mbe-root, .mbe-flow) > .mbe-code pre code { background: none; padding: 0; border-radius: 0; font: inherit; }
198
- /* Source mode: the whole document as Markdown text, in the mono font at the
199
- body's size and line height, so markers and indentation line up and a
200
- switch keeps the text's rhythm. */
201
- .mbe-root > .mbe-source { font-family: var(--mbe-mono); }
218
+ /* Source mode: the whole document as Markdown text, at the body's size and
219
+ line height, so a switch keeps the text's rhythm. Its highlighting changes
220
+ weight, slant and color, never size: markers dim, strong text is bold,
221
+ emphasis italic, headings heavier, code is mono, URLs take the link color. */
222
+ .mbe-root > .mbe-source { font-family: var(--mbe-source-font); }
223
+ .mbe-root > .mbe-source :is(.mbe-src-marker, .mbe-src-html, .mbe-src-token, .mbe-src-escape, .mbe-src-lang) { color: var(--mbe-muted); }
224
+ .mbe-root > .mbe-source :is(.mbe-src-heading, .mbe-src-strong) { font-weight: 600; }
225
+ .mbe-root > .mbe-source .mbe-src-em { font-style: italic; }
226
+ .mbe-root > .mbe-source .mbe-src-strike { text-decoration: line-through; }
227
+ .mbe-root > .mbe-source :is(.mbe-src-code, .mbe-src-lang) { font-family: var(--mbe-mono); }
228
+ .mbe-root > .mbe-source .mbe-src-url { color: var(--mbe-link); }
202
229
 
203
230
  /* Raw blocks: Markdown kept as source (HTML, structure the editor cannot hold, extension syntax) */
204
231
  :is(.mbe-root, .mbe-flow) > pre.mbe-raw { color: var(--mbe-muted); }
@@ -225,13 +252,21 @@
225
252
  .mbe-root .mbe-view-html h6:not(.mbe-flow *) { color: var(--mbe-muted); }
226
253
  .mbe-root .mbe-view-html hr:not(.mbe-flow *) { border: none; border-top: 1px solid var(--mbe-border); }
227
254
  .mbe-root .mbe-view-html a:not(.mbe-link) { color: var(--mbe-link); text-decoration: underline; text-underline-offset: 2px; }
255
+ /* HTML tables look like Markdown ones (the Table rules below). */
228
256
  .mbe-root .mbe-view-html table:not(.mbe-flow *) {
229
- border-collapse: collapse;
257
+ width: 100%;
258
+ border-collapse: separate;
259
+ border-spacing: 0;
260
+ border: 1px solid var(--mbe-border);
261
+ border-radius: var(--mbe-radius);
230
262
  font-size: calc(var(--mbe-font-size) * 0.875);
231
263
  line-height: calc(1em + var(--mbe-leading) * 0.75);
232
264
  }
233
- .mbe-root .mbe-view-html :is(th, td):not(.mbe-flow *) { border: 1px solid var(--mbe-border); padding: 6px 10px; text-align: start; vertical-align: top; }
234
- .mbe-root .mbe-view-html th:not(.mbe-flow *) { font-weight: 500; background: var(--mbe-block-code-bg); }
265
+ .mbe-root .mbe-view-html :is(th, td):not(.mbe-flow *) { padding: 0.4375em 0.75em; text-align: start; vertical-align: top; overflow-wrap: break-word; }
266
+ .mbe-root .mbe-view-html tr:not(:first-child) > :is(th, td):not(.mbe-flow *) { border-top: 1px solid var(--mbe-border); }
267
+ .mbe-root .mbe-view-html th:not(.mbe-flow *) { font-weight: 500; background: var(--mbe-table-header-bg); }
268
+ .mbe-root .mbe-view-html tr:first-child > :first-child:not(.mbe-flow *) { border-start-start-radius: calc(var(--mbe-radius) - 1px); }
269
+ .mbe-root .mbe-view-html tr:first-child > :last-child:not(.mbe-flow *) { border-start-end-radius: calc(var(--mbe-radius) - 1px); }
235
270
  .mbe-root .mbe-view-html kbd {
236
271
  font-family: var(--mbe-mono);
237
272
  font-size: 0.8125em;
@@ -247,18 +282,18 @@
247
282
  /* Divider */
248
283
  :is(.mbe-root, .mbe-flow) > .mbe-divider hr { border: none; border-top: 1px solid var(--mbe-border); }
249
284
 
250
- /* Table: a light grid around every cell and a shaded header row, as in
251
- Notion and Outline. Separate borders, so the outer corners can be round.
252
- 14px on 20px lines at the defaults: tighter rows than the body. */
285
+ /* Table, as claude.ai renders one: a round 1px frame, a tinted header row,
286
+ a line between rows and no vertical lines. Separate borders, so the outer
287
+ corners can be round. 14px on 20px lines at the defaults: tighter rows
288
+ than the body. */
253
289
  :is(.mbe-root, .mbe-flow) > .mbe-table table {
254
290
  font-size: calc(var(--mbe-font-size) * 0.875);
255
291
  line-height: calc(1em + var(--mbe-leading) * 0.75);
256
292
  border: 1px solid var(--mbe-border);
257
293
  border-radius: var(--mbe-radius);
258
294
  }
259
- :is(.mbe-root, .mbe-flow) > .mbe-table :is(th, td):not(:first-child) { border-inline-start: 1px solid var(--mbe-border); }
260
295
  :is(.mbe-root, .mbe-flow) > .mbe-table tr:not(:first-child) > * { border-top: 1px solid var(--mbe-border); }
261
- :is(.mbe-root, .mbe-flow) > .mbe-table th { font-weight: 500; background: var(--mbe-block-code-bg); }
296
+ :is(.mbe-root, .mbe-flow) > .mbe-table th { font-weight: 500; background: var(--mbe-table-header-bg); }
262
297
  /* The header's fill stays inside the round corners. */
263
298
  :is(.mbe-root, .mbe-flow) > .mbe-table tr:first-child > :first-child { border-start-start-radius: calc(var(--mbe-radius) - 1px); }
264
299
  :is(.mbe-root, .mbe-flow) > .mbe-table tr:first-child > :last-child { border-start-end-radius: calc(var(--mbe-radius) - 1px); }
@@ -26,7 +26,12 @@ export type Decorator = (ctx: DecorationContext) => readonly Decoration[];
26
26
  /** Whether a span is code, a link, an image, raw HTML or a token: text that is not plain prose. */
27
27
  export declare function isExcluded(span: Span): boolean;
28
28
  export declare function decorationContext(block: Block, content: Inline, cell?: Cell): DecorationContext;
29
+ /** Whether `[from, to)` overlaps any of `ranges`, which are sorted and do not overlap each other (as `excluded` is). */
29
30
  export declare function overlapsAny(from: number, to: number, ranges: readonly TextRange[]): boolean;
31
+ /** Whether two decorations are the same: range, class and attributes. */
32
+ export declare function sameDecoration(a: Decoration, b: Decoration): boolean;
33
+ /** Whether two lists hold the same decorations in the same order. */
34
+ export declare function sameDecorations(a: readonly Decoration[], b: readonly Decoration[]): boolean;
30
35
  /**
31
36
  * Splits content at decoration edges. Each piece is a span with the
32
37
  * decorations that cover it, in the order given. Spans for which `atomic`
@@ -34,6 +34,14 @@ export interface EditorOptions {
34
34
  * Tab indent as in a code block. Default true. Fixed for the editor's lifetime.
35
35
  */
36
36
  smartLists?: boolean;
37
+ /**
38
+ * In source mode, the Markdown syntax is highlighted: markers dimmed,
39
+ * strong text bold, emphasis italic, headings heavier, code and URLs
40
+ * tinted (classes `mbe-src-*`). `false` leaves the text plain; the
41
+ * extensions' decorations show either way. Default true. Fixed for the
42
+ * editor's lifetime.
43
+ */
44
+ sourceHighlighting?: boolean;
37
45
  /** Focus on creation: `true` or `'start'` puts the caret at the start, `'end'` at the end. */
38
46
  autofocus?: boolean | 'start' | 'end';
39
47
  /** Attributes for the editable root, such as `autocorrect` or `aria-label`. */
@@ -295,6 +303,9 @@ export declare class Editor {
295
303
  /** Task checkboxes stay usable while read-only. */
296
304
  private taskToggle;
297
305
  private readonly smartLists;
306
+ private readonly sourceHighlighting;
307
+ /** Source mode's decorations, computed once per text; a long text gets them a moment after the keystroke (see `SourceHighlighter`). */
308
+ private readonly sourceHighlighter;
298
309
  private readonly options;
299
310
  /** The extensions in priority order, ending with the default keymap unless one was given. */
300
311
  private readonly extensions;
@@ -436,7 +447,6 @@ export declare class Editor {
436
447
  /** Applies a command (a pure function of the state), records history, re-renders, and emits events. */
437
448
  run(command: (state: EditorState) => EditorState | null, kind?: ChangeKind): boolean;
438
449
  private createCommands;
439
- private toggleMark;
440
450
  /** `insertMarkdown` in source mode: the Markdown is inserted as text. */
441
451
  private insertSourceMarkdown;
442
452
  private undo;
@@ -490,6 +500,8 @@ export declare class Editor {
490
500
  * a table replaces the focused cell).
491
501
  */
492
502
  private paint;
503
+ /** Source mode's block with the exact markup, once it is read: only the lines whose highlighting changed are rendered again. */
504
+ private refreshSource;
493
505
  /** Heading ids from the `headingIds` option, computed again only when the document changes. */
494
506
  private applyHeadingIds;
495
507
  /**
@@ -636,6 +648,10 @@ export declare class Editor {
636
648
  private onScroll;
637
649
  private onCopy;
638
650
  private onPaste;
651
+ /** What a paste writes in source mode: the editor's own Markdown, other HTML as Markdown, else the text; inside a fence, the text as written. */
652
+ private pastedMarkdown;
653
+ /** The URL a paste makes a link of: the text, when it is one URL and the paste is not plain. */
654
+ private pastedUrl;
639
655
  /** Clipboard content as blocks: the editor's own Markdown, other HTML, or text as Markdown. */
640
656
  private pastedBlocks;
641
657
  private onDrop;
@@ -2,6 +2,7 @@ import type { Editor } from '../editor.js';
2
2
  import type { Extension } from '../extension.js';
3
3
  import type { Icon } from '../icons.js';
4
4
  import type { Block, Cell, Inline, Position } from '../model.js';
5
+ import type { EditorMode } from '../sourceMode.js';
5
6
  export interface SuggestionItem {
6
7
  /** Stable ID, for tests and keys. Defaults to the label. */
7
8
  readonly id?: string;
@@ -56,6 +57,8 @@ export interface SuggestionAllowContext {
56
57
  readonly excluded: boolean;
57
58
  /** True when the user asked for the popup (Ctrl+Space), rather than typing. */
58
59
  readonly explicit: boolean;
60
+ /** The editor's mode. In source mode `block` is the one block holding the Markdown text, and `excluded` covers its syntax, code and URLs too. */
61
+ readonly mode: EditorMode;
59
62
  }
60
63
  export interface SuggestionItemsContext {
61
64
  /** What the matcher returned; for the built-in matchers, the text between the trigger and the caret, unchanged. */
@@ -117,6 +120,8 @@ export interface SuggestionConfig<T extends SuggestionItem = SuggestionItem> {
117
120
  readonly allowSpaces?: boolean;
118
121
  /** Default matcher only: the trigger may follow any character. Default false: only the start of a line or whitespace. */
119
122
  readonly allowAnywhere?: boolean;
123
+ /** Never opens in source mode: for a suggestion whose items create blocks, such as the slash menu. */
124
+ readonly richOnly?: boolean;
120
125
  /** Waits until the query has not changed for this many ms before calling `items`. Default 0. */
121
126
  readonly debounce?: number;
122
127
  /** Most items shown. Default 50. */
@@ -105,6 +105,8 @@ declare const ICONS: {
105
105
  delete: readonly IconChild[];
106
106
  /** `arrow-up` */
107
107
  addRowAbove: string[];
108
+ /** `arrow-up`: a footnote's backlink to its reference. */
109
+ backToReference: string[];
108
110
  /** `arrow-down` */
109
111
  addRowBelow: string[];
110
112
  /** `arrow-left` */
@@ -9,6 +9,7 @@ export { parseInline } from './markdown/inline.js';
9
9
  export { serializeMarkdown, serializeInline, type SerializeOptions } from './markdown/serialize.js';
10
10
  export { loadMarkdown, type MarkdownSource } from './markdown/source.js';
11
11
  export type { EditorMode } from './sourceMode.js';
12
+ export type { MarkupKind } from './markdown/markup.js';
12
13
  export type { MarkdownOptions } from './markdown/options.js';
13
14
  export { docToHtml } from './clipboard/toHtml.js';
14
15
  export { htmlToDoc } from './clipboard/fromHtml.js';
@@ -9,6 +9,9 @@ export declare const DEFAULT_LABELS: {
9
9
  todoList: string;
10
10
  /** Accessible name of a task checkbox whose item has no text. */
11
11
  task: string;
12
+ /** The footnotes collected at the end of a read-only document, and a note's backlink to its reference. */
13
+ footnotes: string;
14
+ backToReference: string;
12
15
  quote: string;
13
16
  /** The slash menu item, and the title of a callout's block menu section. */
14
17
  callout: string;