@usememos/editor 26.10.21 → 26.10.23
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/README.md +32 -7
- package/dist/base.css +1 -1
- package/dist/index.js +361 -55
- package/dist/index.js.map +3 -3
- package/dist/react.js.map +2 -2
- package/dist/style.css +30 -32
- package/dist/theme.css +57 -32
- package/dist/types/editor.d.ts +7 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/sourceMode.d.ts +15 -0
- package/dist/types/theme.d.ts +21 -5
- package/dist/types/view/dom.d.ts +3 -2
- package/package.json +1 -1
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 | '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;
|
|
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,MA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--mbe-line-height: 24px;
|
|
730
|
+
--mbe-leading: calc(var(--mbe-line-height) - var(--mbe-font-size));
|
|
730
731
|
--mbe-radius: 8px;
|
|
731
732
|
--mbe-text: light-dark(var(--mbe-text-light, oklch(0.2438 0.0269 95.7226)), var(--mbe-text-dark, oklch(0.9 0.006 255)));
|
|
732
733
|
--mbe-muted: light-dark(var(--mbe-muted-light, oklch(0.5559 0.0075 97.4233)), var(--mbe-muted-dark, oklch(0.72 0.007 255)));
|
|
@@ -739,6 +740,7 @@
|
|
|
739
740
|
--mbe-popup-border: light-dark( var(--mbe-popup-border-light, var(--mbe-border-light, oklch(0.8847 0.0069 97.3627))), var(--mbe-popup-border-dark, var(--mbe-border-dark, oklch(0.38 0.01 255))) );
|
|
740
741
|
--mbe-hover: light-dark(var(--mbe-hover-light, oklch(0.9245 0.0138 92.9892)), var(--mbe-hover-dark, oklch(0.39 0.018 250)));
|
|
741
742
|
--mbe-danger: light-dark(var(--mbe-danger-light, oklch(0.5 0.12 25)), var(--mbe-danger-dark, oklch(0.64 0.18 24)));
|
|
743
|
+
--mbe-highlight: light-dark(var(--mbe-highlight-light, #facc15), var(--mbe-highlight-dark, #facc15));
|
|
742
744
|
--mbe-popup-shadow:
|
|
743
745
|
0 4px 12px light-dark(transparent, rgb(0 0 0 / 0.35)),
|
|
744
746
|
0 4px 6px -1px light-dark(rgb(0 0 0 / 0.1), transparent),
|
|
@@ -751,14 +753,12 @@
|
|
|
751
753
|
--mbe-callout-warning: light-dark(var(--mbe-callout-warning-light, oklch(0.55 0.12 75)), var(--mbe-callout-warning-dark, oklch(0.74 0.14 80)));
|
|
752
754
|
--mbe-callout-caution: light-dark(var(--mbe-callout-caution-light, oklch(0.55 0.2 25)), var(--mbe-callout-caution-dark, oklch(0.68 0.19 25)));
|
|
753
755
|
}
|
|
754
|
-
:where([data-theme=light]) :is(.mbe-root, .mbe-ui),
|
|
755
|
-
.mbe-root[data-theme=light],
|
|
756
|
-
.mbe-ui[data-theme=light] {
|
|
756
|
+
:where([data-theme=light], .light) :is(.mbe-root, .mbe-ui),
|
|
757
|
+
:is(.mbe-root, .mbe-ui):is([data-theme=light], .light) {
|
|
757
758
|
color-scheme: light;
|
|
758
759
|
}
|
|
759
|
-
:where([data-theme=dark]) :is(.mbe-root, .mbe-ui),
|
|
760
|
-
.mbe-root[data-theme=dark],
|
|
761
|
-
.mbe-ui[data-theme=dark] {
|
|
760
|
+
:where([data-theme=dark], .dark) :is(.mbe-root, .mbe-ui),
|
|
761
|
+
:is(.mbe-root, .mbe-ui):is([data-theme=dark], .dark) {
|
|
762
762
|
color-scheme: dark;
|
|
763
763
|
}
|
|
764
764
|
.mbe-root {
|
|
@@ -770,22 +770,19 @@
|
|
|
770
770
|
}
|
|
771
771
|
:is(.mbe-root, .mbe-flow) > :is(h1, h2, h3, h4, h5, h6) {
|
|
772
772
|
font-weight: 600;
|
|
773
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
773
774
|
}
|
|
774
775
|
:is(.mbe-root, .mbe-flow) > h1 {
|
|
775
|
-
font-size:
|
|
776
|
-
line-height: 32px;
|
|
776
|
+
font-size: calc(var(--mbe-font-size) * 1.5);
|
|
777
777
|
}
|
|
778
778
|
:is(.mbe-root, .mbe-flow) > h2 {
|
|
779
|
-
font-size:
|
|
780
|
-
line-height: 28px;
|
|
779
|
+
font-size: calc(var(--mbe-font-size) * 1.25);
|
|
781
780
|
}
|
|
782
781
|
:is(.mbe-root, .mbe-flow) > h3 {
|
|
783
|
-
font-size:
|
|
784
|
-
line-height: 26px;
|
|
782
|
+
font-size: calc(var(--mbe-font-size) * 1.125);
|
|
785
783
|
}
|
|
786
784
|
:is(.mbe-root, .mbe-flow) > :is(h4, h5, h6) {
|
|
787
|
-
font-size:
|
|
788
|
-
line-height: 24px;
|
|
785
|
+
font-size: var(--mbe-font-size);
|
|
789
786
|
}
|
|
790
787
|
:is(.mbe-root, .mbe-flow) > h6 {
|
|
791
788
|
color: var(--mbe-muted);
|
|
@@ -827,7 +824,7 @@
|
|
|
827
824
|
background: var(--mbe-block-code-bg);
|
|
828
825
|
color: var(--mbe-muted);
|
|
829
826
|
font-size: 0.875em;
|
|
830
|
-
line-height:
|
|
827
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
831
828
|
}
|
|
832
829
|
.mbe-root .mbe-footnote-ref {
|
|
833
830
|
font-size: 0.75em;
|
|
@@ -924,8 +921,8 @@
|
|
|
924
921
|
padding: 6px 12px 0;
|
|
925
922
|
}
|
|
926
923
|
.mbe-root .mbe-code-lang {
|
|
927
|
-
font-size:
|
|
928
|
-
line-height:
|
|
924
|
+
font-size: calc(var(--mbe-font-size) * 0.75);
|
|
925
|
+
line-height: calc(1em + var(--mbe-leading) / 2);
|
|
929
926
|
font-family: var(--mbe-font);
|
|
930
927
|
color: var(--mbe-muted);
|
|
931
928
|
}
|
|
@@ -946,8 +943,8 @@
|
|
|
946
943
|
}
|
|
947
944
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre,
|
|
948
945
|
:is(.mbe-root, .mbe-flow) > pre.mbe-raw {
|
|
949
|
-
font-size:
|
|
950
|
-
line-height:
|
|
946
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
947
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
951
948
|
font-family: var(--mbe-mono);
|
|
952
949
|
}
|
|
953
950
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre {
|
|
@@ -959,6 +956,9 @@
|
|
|
959
956
|
border-radius: 0;
|
|
960
957
|
font: inherit;
|
|
961
958
|
}
|
|
959
|
+
.mbe-root > .mbe-source {
|
|
960
|
+
font-family: var(--mbe-mono);
|
|
961
|
+
}
|
|
962
962
|
:is(.mbe-root, .mbe-flow) > pre.mbe-raw {
|
|
963
963
|
color: var(--mbe-muted);
|
|
964
964
|
}
|
|
@@ -971,8 +971,8 @@
|
|
|
971
971
|
background: var(--mbe-block-code-bg);
|
|
972
972
|
border-radius: var(--mbe-radius);
|
|
973
973
|
padding: 10px 12px;
|
|
974
|
-
font-size:
|
|
975
|
-
line-height:
|
|
974
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
975
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
976
976
|
font-family: var(--mbe-mono);
|
|
977
977
|
}
|
|
978
978
|
.mbe-root .mbe-view-html pre code:not(.mbe-flow *) {
|
|
@@ -983,18 +983,16 @@
|
|
|
983
983
|
}
|
|
984
984
|
.mbe-root .mbe-view-html :is(h1, h2, h3, h4, h5, h6):not(.mbe-flow *) {
|
|
985
985
|
font-weight: 600;
|
|
986
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
986
987
|
}
|
|
987
988
|
.mbe-root .mbe-view-html h1:not(.mbe-flow *) {
|
|
988
|
-
font-size:
|
|
989
|
-
line-height: 32px;
|
|
989
|
+
font-size: calc(var(--mbe-font-size) * 1.5);
|
|
990
990
|
}
|
|
991
991
|
.mbe-root .mbe-view-html h2:not(.mbe-flow *) {
|
|
992
|
-
font-size:
|
|
993
|
-
line-height: 28px;
|
|
992
|
+
font-size: calc(var(--mbe-font-size) * 1.25);
|
|
994
993
|
}
|
|
995
994
|
.mbe-root .mbe-view-html h3:not(.mbe-flow *) {
|
|
996
|
-
font-size:
|
|
997
|
-
line-height: 26px;
|
|
995
|
+
font-size: calc(var(--mbe-font-size) * 1.125);
|
|
998
996
|
}
|
|
999
997
|
.mbe-root .mbe-view-html h6:not(.mbe-flow *) {
|
|
1000
998
|
color: var(--mbe-muted);
|
|
@@ -1010,8 +1008,8 @@
|
|
|
1010
1008
|
}
|
|
1011
1009
|
.mbe-root .mbe-view-html table:not(.mbe-flow *) {
|
|
1012
1010
|
border-collapse: collapse;
|
|
1013
|
-
font-size:
|
|
1014
|
-
line-height:
|
|
1011
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
1012
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
1015
1013
|
}
|
|
1016
1014
|
.mbe-root .mbe-view-html :is(th, td):not(.mbe-flow *) {
|
|
1017
1015
|
border: 1px solid var(--mbe-border);
|
|
@@ -1034,7 +1032,7 @@
|
|
|
1034
1032
|
background: var(--mbe-block-code-bg);
|
|
1035
1033
|
}
|
|
1036
1034
|
.mbe-root .mbe-view-html mark {
|
|
1037
|
-
background: color-mix(in oklab,
|
|
1035
|
+
background: color-mix(in oklab, var(--mbe-highlight) 40%, transparent);
|
|
1038
1036
|
color: inherit;
|
|
1039
1037
|
}
|
|
1040
1038
|
:is(.mbe-root, .mbe-flow) > .mbe-divider hr {
|
|
@@ -1042,8 +1040,8 @@
|
|
|
1042
1040
|
border-top: 1px solid var(--mbe-border);
|
|
1043
1041
|
}
|
|
1044
1042
|
:is(.mbe-root, .mbe-flow) > .mbe-table table {
|
|
1045
|
-
font-size:
|
|
1046
|
-
line-height:
|
|
1043
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
1044
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
1047
1045
|
border: 1px solid var(--mbe-border);
|
|
1048
1046
|
border-radius: var(--mbe-radius);
|
|
1049
1047
|
}
|
package/dist/theme.css
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
* so a document looks the same while editing and when read-only.
|
|
4
4
|
* Needs base.css, which holds the layout and all spacing between blocks.
|
|
5
5
|
* Every color, font and size is a custom property; the theme option's
|
|
6
|
-
* tokens set them (see theme.ts),
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* tokens set them (see theme.ts). In CSS, set --mbe-<name>-light and
|
|
7
|
+
* --mbe-<name>-dark on the root or any ancestor (:root works): the rules
|
|
8
|
+
* below read them with the default palette as fallback.
|
|
9
|
+
* Light and dark follow prefers-color-scheme; data-theme="light" or
|
|
10
|
+
* data-theme="dark", or a `light` or `dark` class (the Tailwind and shadcn
|
|
11
|
+
* convention), on the root or an ancestor forces one, as does the theme
|
|
12
|
+
* option's colorScheme.
|
|
10
13
|
*/
|
|
11
14
|
.mbe-root,
|
|
12
15
|
.mbe-ui {
|
|
@@ -16,6 +19,10 @@
|
|
|
16
19
|
--mbe-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
|
17
20
|
--mbe-font-size: 16px;
|
|
18
21
|
--mbe-line-height: 24px;
|
|
22
|
+
/* The room a line has around its text. Headings, code and tables size
|
|
23
|
+
their text from --mbe-font-size and add this leading to their lines,
|
|
24
|
+
so the rhythm an app sets for the body carries to them. */
|
|
25
|
+
--mbe-leading: calc(var(--mbe-line-height) - var(--mbe-font-size));
|
|
19
26
|
--mbe-radius: 8px;
|
|
20
27
|
/* Colors: light-dark() picks by the element's color-scheme. The theme
|
|
21
28
|
option's tokens set --mbe-<name>-light and --mbe-<name>-dark. */
|
|
@@ -36,6 +43,8 @@
|
|
|
36
43
|
);
|
|
37
44
|
--mbe-hover: light-dark(var(--mbe-hover-light, oklch(0.9245 0.0138 92.9892)), var(--mbe-hover-dark, oklch(0.39 0.018 250)));
|
|
38
45
|
--mbe-danger: light-dark(var(--mbe-danger-light, oklch(0.5 0.12 25)), var(--mbe-danger-dark, oklch(0.64 0.18 24)));
|
|
46
|
+
/* Behind <mark> in rendered HTML, as a tint. */
|
|
47
|
+
--mbe-highlight: light-dark(var(--mbe-highlight-light, #facc15), var(--mbe-highlight-dark, #facc15));
|
|
39
48
|
/* Two soft shadows in light, one darker and wider in dark. */
|
|
40
49
|
--mbe-popup-shadow: 0 4px 12px light-dark(transparent, rgb(0 0 0 / 0.35)), 0 4px 6px -1px light-dark(rgb(0 0 0 / 0.1), transparent),
|
|
41
50
|
0 2px 4px -2px light-dark(rgb(0 0 0 / 0.1), transparent);
|
|
@@ -48,14 +57,12 @@
|
|
|
48
57
|
--mbe-callout-warning: light-dark(var(--mbe-callout-warning-light, oklch(0.55 0.12 75)), var(--mbe-callout-warning-dark, oklch(0.74 0.14 80)));
|
|
49
58
|
--mbe-callout-caution: light-dark(var(--mbe-callout-caution-light, oklch(0.55 0.2 25)), var(--mbe-callout-caution-dark, oklch(0.68 0.19 25)));
|
|
50
59
|
}
|
|
51
|
-
:where([data-theme='light']) :is(.mbe-root, .mbe-ui),
|
|
52
|
-
.mbe-root[data-theme='light'],
|
|
53
|
-
.mbe-ui[data-theme='light'] {
|
|
60
|
+
:where([data-theme='light'], .light) :is(.mbe-root, .mbe-ui),
|
|
61
|
+
:is(.mbe-root, .mbe-ui):is([data-theme='light'], .light) {
|
|
54
62
|
color-scheme: light;
|
|
55
63
|
}
|
|
56
|
-
:where([data-theme='dark']) :is(.mbe-root, .mbe-ui),
|
|
57
|
-
.mbe-root[data-theme='dark'],
|
|
58
|
-
.mbe-ui[data-theme='dark'] {
|
|
64
|
+
:where([data-theme='dark'], .dark) :is(.mbe-root, .mbe-ui),
|
|
65
|
+
:is(.mbe-root, .mbe-ui):is([data-theme='dark'], .dark) {
|
|
59
66
|
color-scheme: dark;
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -70,12 +77,12 @@
|
|
|
70
77
|
background: var(--mbe-bg);
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
/* Headings: close to the body size. */
|
|
74
|
-
:is(.mbe-root, .mbe-flow) > :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; }
|
|
75
|
-
:is(.mbe-root, .mbe-flow) > h1 { font-size:
|
|
76
|
-
:is(.mbe-root, .mbe-flow) > h2 { font-size:
|
|
77
|
-
:is(.mbe-root, .mbe-flow) > h3 { font-size:
|
|
78
|
-
:is(.mbe-root, .mbe-flow) > :is(h4, h5, h6) { font-size:
|
|
80
|
+
/* Headings: close to the body size (24, 20, 18 and 16px at the defaults), each with the body's leading. */
|
|
81
|
+
:is(.mbe-root, .mbe-flow) > :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; line-height: calc(1em + var(--mbe-leading)); }
|
|
82
|
+
:is(.mbe-root, .mbe-flow) > h1 { font-size: calc(var(--mbe-font-size) * 1.5); }
|
|
83
|
+
:is(.mbe-root, .mbe-flow) > h2 { font-size: calc(var(--mbe-font-size) * 1.25); }
|
|
84
|
+
:is(.mbe-root, .mbe-flow) > h3 { font-size: calc(var(--mbe-font-size) * 1.125); }
|
|
85
|
+
:is(.mbe-root, .mbe-flow) > :is(h4, h5, h6) { font-size: var(--mbe-font-size); }
|
|
79
86
|
:is(.mbe-root, .mbe-flow) > h6 { color: var(--mbe-muted); }
|
|
80
87
|
|
|
81
88
|
/* Block selection */
|
|
@@ -105,7 +112,7 @@
|
|
|
105
112
|
background: var(--mbe-block-code-bg);
|
|
106
113
|
color: var(--mbe-muted);
|
|
107
114
|
font-size: 0.875em;
|
|
108
|
-
line-height:
|
|
115
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
109
116
|
}
|
|
110
117
|
/* Footnotes, rendered: a reference is a small raised label, a definition a small muted note. */
|
|
111
118
|
.mbe-root .mbe-footnote-ref { font-size: 0.75em; line-height: 0; color: var(--mbe-link); }
|
|
@@ -168,17 +175,30 @@
|
|
|
168
175
|
overflow: hidden;
|
|
169
176
|
}
|
|
170
177
|
.mbe-root .mbe-code-bar { padding: 6px 12px 0; }
|
|
171
|
-
/* Sizes and family apart: a font token of `inherit` leaves the family to inherit, without dropping the size. */
|
|
172
|
-
.mbe-root .mbe-code-lang {
|
|
178
|
+
/* Sizes and family apart: a font token of `inherit` leaves the family to inherit, without dropping the size. 12px on 16px lines at the defaults. */
|
|
179
|
+
.mbe-root .mbe-code-lang {
|
|
180
|
+
font-size: calc(var(--mbe-font-size) * 0.75);
|
|
181
|
+
line-height: calc(1em + var(--mbe-leading) / 2);
|
|
182
|
+
font-family: var(--mbe-font);
|
|
183
|
+
color: var(--mbe-muted);
|
|
184
|
+
}
|
|
173
185
|
.mbe-root .mbe-code-lang::placeholder { color: var(--mbe-muted); opacity: 1; }
|
|
174
186
|
.mbe-root .mbe-code-copy { color: var(--mbe-muted); border-radius: 4px; }
|
|
175
187
|
.mbe-root .mbe-code-copy:hover { color: var(--mbe-text); background: var(--mbe-hover); }
|
|
176
188
|
.mbe-root .mbe-code-copy.mbe-copied { color: var(--mbe-accent); }
|
|
177
|
-
/* Block source text: code blocks and raw blocks. */
|
|
189
|
+
/* Block source text: code blocks and raw blocks. 14px on 22px lines at the defaults. */
|
|
178
190
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre,
|
|
179
|
-
:is(.mbe-root, .mbe-flow) > pre.mbe-raw {
|
|
191
|
+
:is(.mbe-root, .mbe-flow) > pre.mbe-raw {
|
|
192
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
193
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
194
|
+
font-family: var(--mbe-mono);
|
|
195
|
+
}
|
|
180
196
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre { padding: 2px 12px 10px; }
|
|
181
197
|
: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); }
|
|
182
202
|
|
|
183
203
|
/* Raw blocks: Markdown kept as source (HTML, structure the editor cannot hold, extension syntax) */
|
|
184
204
|
:is(.mbe-root, .mbe-flow) > pre.mbe-raw { color: var(--mbe-muted); }
|
|
@@ -193,19 +213,23 @@
|
|
|
193
213
|
background: var(--mbe-block-code-bg);
|
|
194
214
|
border-radius: var(--mbe-radius);
|
|
195
215
|
padding: 10px 12px;
|
|
196
|
-
font-size:
|
|
197
|
-
line-height:
|
|
216
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
217
|
+
line-height: calc(1em + var(--mbe-leading));
|
|
198
218
|
font-family: var(--mbe-mono);
|
|
199
219
|
}
|
|
200
220
|
.mbe-root .mbe-view-html pre code:not(.mbe-flow *) { background: none; padding: 0; border-radius: 0; font: inherit; }
|
|
201
|
-
.mbe-root .mbe-view-html :is(h1, h2, h3, h4, h5, h6):not(.mbe-flow *) { font-weight: 600; }
|
|
202
|
-
.mbe-root .mbe-view-html h1:not(.mbe-flow *) { font-size:
|
|
203
|
-
.mbe-root .mbe-view-html h2:not(.mbe-flow *) { font-size:
|
|
204
|
-
.mbe-root .mbe-view-html h3:not(.mbe-flow *) { font-size:
|
|
221
|
+
.mbe-root .mbe-view-html :is(h1, h2, h3, h4, h5, h6):not(.mbe-flow *) { font-weight: 600; line-height: calc(1em + var(--mbe-leading)); }
|
|
222
|
+
.mbe-root .mbe-view-html h1:not(.mbe-flow *) { font-size: calc(var(--mbe-font-size) * 1.5); }
|
|
223
|
+
.mbe-root .mbe-view-html h2:not(.mbe-flow *) { font-size: calc(var(--mbe-font-size) * 1.25); }
|
|
224
|
+
.mbe-root .mbe-view-html h3:not(.mbe-flow *) { font-size: calc(var(--mbe-font-size) * 1.125); }
|
|
205
225
|
.mbe-root .mbe-view-html h6:not(.mbe-flow *) { color: var(--mbe-muted); }
|
|
206
226
|
.mbe-root .mbe-view-html hr:not(.mbe-flow *) { border: none; border-top: 1px solid var(--mbe-border); }
|
|
207
227
|
.mbe-root .mbe-view-html a:not(.mbe-link) { color: var(--mbe-link); text-decoration: underline; text-underline-offset: 2px; }
|
|
208
|
-
.mbe-root .mbe-view-html table:not(.mbe-flow *) {
|
|
228
|
+
.mbe-root .mbe-view-html table:not(.mbe-flow *) {
|
|
229
|
+
border-collapse: collapse;
|
|
230
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
231
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
232
|
+
}
|
|
209
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; }
|
|
210
234
|
.mbe-root .mbe-view-html th:not(.mbe-flow *) { font-weight: 500; background: var(--mbe-block-code-bg); }
|
|
211
235
|
.mbe-root .mbe-view-html kbd {
|
|
@@ -218,16 +242,17 @@
|
|
|
218
242
|
border-radius: 4px;
|
|
219
243
|
background: var(--mbe-block-code-bg);
|
|
220
244
|
}
|
|
221
|
-
.mbe-root .mbe-view-html mark { background: color-mix(in oklab,
|
|
245
|
+
.mbe-root .mbe-view-html mark { background: color-mix(in oklab, var(--mbe-highlight) 40%, transparent); color: inherit; }
|
|
222
246
|
|
|
223
247
|
/* Divider */
|
|
224
248
|
:is(.mbe-root, .mbe-flow) > .mbe-divider hr { border: none; border-top: 1px solid var(--mbe-border); }
|
|
225
249
|
|
|
226
250
|
/* Table: a light grid around every cell and a shaded header row, as in
|
|
227
|
-
Notion and Outline. Separate borders, so the outer corners can be round.
|
|
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. */
|
|
228
253
|
:is(.mbe-root, .mbe-flow) > .mbe-table table {
|
|
229
|
-
font-size:
|
|
230
|
-
line-height:
|
|
254
|
+
font-size: calc(var(--mbe-font-size) * 0.875);
|
|
255
|
+
line-height: calc(1em + var(--mbe-leading) * 0.75);
|
|
231
256
|
border: 1px solid var(--mbe-border);
|
|
232
257
|
border-radius: var(--mbe-radius);
|
|
233
258
|
}
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export interface EditorOptions {
|
|
|
28
28
|
taskToggle?: boolean;
|
|
29
29
|
/** `'source'` shows the whole document as its Markdown text. Default `'rich'`. */
|
|
30
30
|
mode?: EditorMode;
|
|
31
|
+
/**
|
|
32
|
+
* In source mode, Enter continues a list or task item and Tab and
|
|
33
|
+
* Shift+Tab nest list items. `false` makes Enter insert a line break and
|
|
34
|
+
* Tab indent as in a code block. Default true. Fixed for the editor's lifetime.
|
|
35
|
+
*/
|
|
36
|
+
smartLists?: boolean;
|
|
31
37
|
/** Focus on creation: `true` or `'start'` puts the caret at the start, `'end'` at the end. */
|
|
32
38
|
autofocus?: boolean | 'start' | 'end';
|
|
33
39
|
/** Attributes for the editable root, such as `autocorrect` or `aria-label`. */
|
|
@@ -288,6 +294,7 @@ export declare class Editor {
|
|
|
288
294
|
private wasReadOnly;
|
|
289
295
|
/** Task checkboxes stay usable while read-only. */
|
|
290
296
|
private taskToggle;
|
|
297
|
+
private readonly smartLists;
|
|
291
298
|
private readonly options;
|
|
292
299
|
/** The extensions in priority order, ending with the default keymap unless one was given. */
|
|
293
300
|
private readonly extensions;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type { MarkdownOptions } from './markdown/options.js';
|
|
|
13
13
|
export { docToHtml } from './clipboard/toHtml.js';
|
|
14
14
|
export { htmlToDoc } from './clipboard/fromHtml.js';
|
|
15
15
|
export type { BlockView, CodeDecorationContext, Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
|
|
16
|
-
export type
|
|
16
|
+
export { shadcnTheme, type ColorScheme, type Theme, type ThemeClasses, type ThemeColors, type ThemeTokens } from './theme.js';
|
|
17
17
|
export { defaultKeymap } from './extensions/keymap.js';
|
|
18
18
|
export { math, type MathOptions } from './extensions/math.js';
|
|
19
19
|
export { footnotes, type FootnotesOptions } from './extensions/footnotes.js';
|
|
@@ -2,7 +2,7 @@ import { Editor, type EditorOptions, type SuggestionState } from '@usememos/edit
|
|
|
2
2
|
import { type CSSProperties } from 'react';
|
|
3
3
|
export type { Editor, SuggestionState } from '@usememos/editor';
|
|
4
4
|
/** Constructor options that the React components take as props. */
|
|
5
|
-
type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'mode' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'headingIds' | 'onLinkClick' | 'theme' | 'toolbar' | 'linkCard' | 'slashMenu' | 'slashHint' | 'labels' | 'icons'>;
|
|
5
|
+
type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'mode' | 'smartLists' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'headingIds' | 'onLinkClick' | 'theme' | 'toolbar' | 'linkCard' | 'slashMenu' | 'slashHint' | 'labels' | 'icons'>;
|
|
6
6
|
export interface MarkdownEditorProps extends EditorProps {
|
|
7
7
|
/** Markdown. The editor updates only when this is not a value it emitted itself. */
|
|
8
8
|
value?: string;
|
|
@@ -26,6 +26,21 @@ export declare function insertSourceAt(state: EditorState, offset: number, inser
|
|
|
26
26
|
export declare function sourceDeleteBackward(state: EditorState, previous: (text: string, offset: number) => number): EditorState | null;
|
|
27
27
|
/** Delete: deletes the selection or the character after the caret; nothing at the end. */
|
|
28
28
|
export declare function sourceDeleteForward(state: EditorState, next: (text: string, offset: number) => number): EditorState | null;
|
|
29
|
+
/**
|
|
30
|
+
* Enter in source mode: on a list item, continues the list (the next number,
|
|
31
|
+
* an unticked task box); on an empty item, removes the marker, or outdents a
|
|
32
|
+
* nested item, as Enter in an empty item does in rich mode. Elsewhere, and
|
|
33
|
+
* before an item's marker, a line break.
|
|
34
|
+
*/
|
|
35
|
+
export declare function sourceEnter(state: EditorState): EditorState;
|
|
36
|
+
/**
|
|
37
|
+
* Tab and Shift+Tab in source mode on list items: nests the items under the
|
|
38
|
+
* item before them, or moves them out to their parent's level, with the
|
|
39
|
+
* lines nested under them, and numbers the lists they left and joined.
|
|
40
|
+
* Returns null when the selection is not on list items, for indenting as in
|
|
41
|
+
* a code block; returns the state unchanged when the item cannot move.
|
|
42
|
+
*/
|
|
43
|
+
export declare function sourceIndentList(state: EditorState, delta: 1 | -1): EditorState | null;
|
|
29
44
|
/** Where an offset in `before` moves to in `after`, when the change between them is one replaced range. */
|
|
30
45
|
export declare function mapOffset(offset: number, before: string, after: string): number;
|
|
31
46
|
interface Placed {
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface ThemeColors {
|
|
|
54
54
|
/** Highlighted menu items and toolbar buttons. */
|
|
55
55
|
readonly hover?: string;
|
|
56
56
|
readonly danger?: string;
|
|
57
|
+
/** Behind `<mark>` in rendered HTML, as a tint. */
|
|
58
|
+
readonly highlight?: string;
|
|
57
59
|
/** The icon of each callout type, and a light tint of it behind the text. */
|
|
58
60
|
readonly calloutNote?: string;
|
|
59
61
|
readonly calloutTip?: string;
|
|
@@ -63,9 +65,14 @@ export interface ThemeColors {
|
|
|
63
65
|
}
|
|
64
66
|
/** Values written as --mbe-* custom properties on the root and on popups. Numbers are pixels. */
|
|
65
67
|
export interface ThemeTokens {
|
|
66
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Colors in both schemes, for values that pick their own, such as
|
|
70
|
+
* `var(--primary)`. `light` and `dark` override them per scheme.
|
|
71
|
+
*/
|
|
72
|
+
readonly colors?: ThemeColors;
|
|
73
|
+
/** Colors in the light scheme. Missing values keep `colors`, then the default. */
|
|
67
74
|
readonly light?: ThemeColors;
|
|
68
|
-
/** Colors in the dark scheme. Missing values keep the default dark palette. */
|
|
75
|
+
/** Colors in the dark scheme. Missing values keep `colors`, then the default dark palette. */
|
|
69
76
|
readonly dark?: ThemeColors;
|
|
70
77
|
readonly font?: string;
|
|
71
78
|
readonly mono?: string;
|
|
@@ -76,8 +83,9 @@ export interface ThemeTokens {
|
|
|
76
83
|
}
|
|
77
84
|
/**
|
|
78
85
|
* `auto` follows `prefers-color-scheme`, or `data-theme="light"` or
|
|
79
|
-
* `data-theme="dark"` on the root or an
|
|
80
|
-
* page's `color-scheme`, for apps that
|
|
86
|
+
* `data-theme="dark"`, or a `light` or `dark` class, on the root or an
|
|
87
|
+
* ancestor. `inherit` follows the page's `color-scheme`, for apps that
|
|
88
|
+
* switch it themselves.
|
|
81
89
|
*/
|
|
82
90
|
export type ColorScheme = 'auto' | 'light' | 'dark' | 'inherit';
|
|
83
91
|
export interface Theme {
|
|
@@ -86,12 +94,20 @@ export interface Theme {
|
|
|
86
94
|
/** Default `auto`. */
|
|
87
95
|
readonly colorScheme?: ColorScheme;
|
|
88
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* The editor in an app styled with shadcn/ui: colors, font and radius from
|
|
99
|
+
* shadcn's CSS variables (`--foreground`, `--primary`, `--radius`, …), so the
|
|
100
|
+
* editor follows the app's theme, and light or dark from the `dark` class.
|
|
101
|
+
* Spread it to change a part: `{ tokens: { ...shadcnTheme.tokens, radius: 4 } }`.
|
|
102
|
+
*/
|
|
103
|
+
export declare const shadcnTheme: Theme;
|
|
89
104
|
/** Merges class maps; a later map wins for the same key, and `heading` and `token` merge per entry. */
|
|
90
105
|
export declare function mergeClasses(maps: readonly (ThemeClasses | undefined)[]): ThemeClasses;
|
|
91
106
|
/** The token properties that change how text measures: a view that laid out text (a diagram) renders again when one changes. */
|
|
92
107
|
export declare const FONT_PROPERTIES: readonly string[];
|
|
93
108
|
/**
|
|
94
109
|
* The custom properties for `tokens`. Colors go in `--mbe-<name>-light` and
|
|
95
|
-
* `--mbe-<name>-dark`, which the stylesheet picks between with `light-dark()
|
|
110
|
+
* `--mbe-<name>-dark`, which the stylesheet picks between with `light-dark()`;
|
|
111
|
+
* `colors` fills both, and `light` and `dark` win per scheme.
|
|
96
112
|
*/
|
|
97
113
|
export declare function tokenProperties(tokens: ThemeTokens | undefined): Map<string, string>;
|
package/dist/types/view/dom.d.ts
CHANGED
|
@@ -82,8 +82,9 @@ export declare function splitHtmlSpans(inline: Inline): Inline;
|
|
|
82
82
|
/**
|
|
83
83
|
* Runs of inline raw HTML that render as one piece: an opening tag through
|
|
84
84
|
* its closing tag, with the text between (`<kbd>Ctrl</kbd>`), or a single tag
|
|
85
|
-
* (`<br>`, an unmatched tag, a comment).
|
|
86
|
-
*
|
|
85
|
+
* (`<br>`, an unmatched tag, a comment). A run may cross a link, as the tags
|
|
86
|
+
* pass through other renderers verbatim and the browser pairs them. Offsets
|
|
87
|
+
* are into the container's text.
|
|
87
88
|
*/
|
|
88
89
|
export declare function htmlRuns(inline: Inline): {
|
|
89
90
|
from: number;
|