@usememos/editor 26.10.28 → 26.10.30
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 +51 -1
- package/dist/index.js +85 -85
- package/dist/index.js.map +4 -4
- package/dist/react.js +2 -2
- package/dist/react.js.map +3 -3
- package/dist/types/editor.d.ts +16 -0
- package/dist/types/extension.d.ts +6 -2
- package/dist/types/index.d.ts +6 -1
- package/dist/types/markdown/htmlSection.d.ts +2 -0
- package/dist/types/markdown/tree.d.ts +26 -0
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/view/html.d.ts +29 -0
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Editor as h}from"@usememos/editor";import{forwardRef as x,useEffect as f,useRef as d,useState as S}from"react";import{flushSync as P}from"react-dom";import{jsx as y}from"react/jsx-runtime";var b=["placeholder","mode","editable","taskToggle","attributes","resolveUrl","onLinkClick","theme","extensions"],M=
|
|
2
|
-
`),D=x(function(
|
|
1
|
+
import{Editor as h}from"@usememos/editor";import{forwardRef as x,useEffect as f,useRef as d,useState as S}from"react";import{flushSync as P}from"react-dom";import{jsx as y}from"react/jsx-runtime";var b=["placeholder","mode","editable","taskToggle","attributes","resolveUrl","onLinkClick","theme","extensions"],M=e=>(e??[]).map(t=>t.name).join(`
|
|
2
|
+
`),D=x(function(t,r){let s=d(null),n=d(null),o=d([]),i=d(null),l=d(t);l.current=t;let u=M(t.extensions);return f(()=>{let{value:c,defaultValue:m,onChange:O,onSubmit:F,onFocus:T,onBlur:R,className:N,style:B,...C}=l.current,w=n.current,g=new h({...C,element:s.current,content:w?.getMarkdown()??c??m??"",onChange:a=>{o.current.push(a),o.current.length>100&&o.current.shift(),P(()=>l.current.onChange?.(a))},onSubmit:a=>l.current.onSubmit?.(a),onFocus:()=>l.current.onFocus?.(),onBlur:()=>l.current.onBlur?.()});n.current=g,o.current=[],v(r,g);let k=s.current,p=()=>{let a=i.current;i.current=null,a!==null&&a!==g.getMarkdown()&&(o.current=[],g.setMarkdown(a))};return k.addEventListener("compositionend",p),()=>{k.removeEventListener("compositionend",p),g.destroy(),n.current===g&&(n.current=null),v(r,null)}},[u]),f(()=>{let c=n.current;if(!c||t.value===void 0)return;let m=o.current.indexOf(t.value);if(m>=0){o.current.splice(0,m+1);return}if(t.value!==c.getMarkdown()){if(c.isComposing){i.current=t.value;return}o.current=[],c.setMarkdown(t.value)}},[t.value]),L(n,t),y("div",{ref:s,className:t.className,style:t.style})});function L(e,t){let r=d({editor:null,props:{}});f(()=>{let s=e.current;if(!s)return;if(r.current.editor!==s){r.current={editor:s,props:{...t}};return}let n={},o=!1;for(let i of b)t[i]!==r.current.props[i]&&(n[i]=i==="editable"?t.editable??!0:i==="mode"?t.mode??"rich":i==="taskToggle"?t.taskToggle??!1:t[i],o=!0);r.current={editor:s,props:{...t}},o&&s.setOptions(n)})}function U(e,t=[]){let[r,s]=S(null),n=d(e);return n.current=e,f(()=>{r&&e.extensions&&r.setOptions({extensions:e.extensions})},[r,e.extensions]),f(()=>{let o=n.current,i=document.createElement("div"),l=new h({...o,element:i,autofocus:!1,onChange:(u,c)=>n.current.onChange?.(u,c),onSubmit:(u,c)=>n.current.onSubmit?.(u,c),onFocus:u=>n.current.onFocus?.(u),onBlur:u=>n.current.onBlur?.(u),onLinkClick:u=>n.current.onLinkClick?.(u)});return o.autofocus&&E.set(l,o.autofocus==="end"?"end":"start"),s(l),()=>{l.destroy(),s(null)}},t),r}function z(e,t){let r=o=>o&&(t===void 0||o.name===t)?o:null,[s,n]=S(()=>r(e?.suggestion.state));return f(()=>{if(!e){n(null);return}return n(r(e.suggestion.state)),e.on("suggestionChange",({state:o})=>n(r(o)))},[e,t]),s}function A({editor:e,className:t,style:r}){let s=d(null);return f(()=>{let n=s.current;if(!e||!n)return;n.appendChild(e.root);let o=E.get(e);return o&&(E.delete(e),e.commands.focus(o)),()=>{e.root.parentNode===n&&n.removeChild(e.root)}},[e]),y("div",{ref:s,className:t,style:r})}var E=new WeakMap;function v(e,t){typeof e=="function"?e(t):e&&(e.current=t)}export{A as EditorContent,D as MarkdownEditor,U as useEditor,z as useSuggestion};
|
|
3
3
|
//# sourceMappingURL=react.js.map
|
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 | '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,OAAS,UAAAA,MAAwD,mBACjE,OAAgD,cAAAC,EAAY,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAC/F,OAAS,aAAAC,MAAiB,
|
|
6
|
-
"names": ["Editor", "forwardRef", "useEffect", "useRef", "useState", "flushSync", "jsx", "LIVE", "extensionKey", "extensions", "MarkdownEditor", "props", "ref", "container", "editorRef", "pending", "deferred", "latest", "value", "defaultValue", "onChange", "onSubmit", "onFocus", "onBlur", "className", "style", "options", "previous", "editor", "markdown", "assignRef", "root", "onCompositionEnd", "echo", "useLiveOptions", "applied", "changed", "any", "key", "useEditor", "deps", "setEditor", "element", "instance", "
|
|
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 | 'sanitizeHtml'\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,OAAS,UAAAA,MAAwD,mBACjE,OAAgD,cAAAC,EAAY,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAC/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
|
6
|
+
"names": ["Editor", "forwardRef", "useEffect", "useRef", "useState", "flushSync", "jsx", "LIVE", "extensionKey", "extensions", "e", "MarkdownEditor", "props", "ref", "container", "editorRef", "pending", "deferred", "latest", "value", "defaultValue", "onChange", "onSubmit", "onFocus", "onBlur", "className", "style", "options", "previous", "editor", "markdown", "assignRef", "root", "onCompositionEnd", "echo", "useLiveOptions", "applied", "changed", "any", "key", "useEditor", "deps", "setEditor", "element", "instance", "ctx", "pendingAutofocus", "useSuggestion", "name", "select", "state", "setState", "EditorContent", "host", "autofocus"]
|
|
7
7
|
}
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { type Widget, type WidgetRender } from './widgets.js';
|
|
|
9
9
|
import { type Block, type CalloutType, type EditorState, type HeadingLevel, type Position, type Selection } from './model.js';
|
|
10
10
|
import { type ToolbarItem } from './ui/toolbar.js';
|
|
11
11
|
import { type ResolveUrl } from './view/dom.js';
|
|
12
|
+
import { type SanitizeHtml } from './view/html.js';
|
|
12
13
|
import { type Theme } from './theme.js';
|
|
13
14
|
import { type EditorMode } from './sourceMode.js';
|
|
14
15
|
export interface EditorOptions {
|
|
@@ -55,6 +56,13 @@ export interface EditorOptions {
|
|
|
55
56
|
resolveUrl?: ResolveUrl;
|
|
56
57
|
/** `referrerpolicy` for images, such as `no-referrer`. Fixed for the editor's lifetime. */
|
|
57
58
|
referrerPolicy?: ReferrerPolicy;
|
|
59
|
+
/**
|
|
60
|
+
* Renders raw HTML: the editor parses an HTML block or an inline run with
|
|
61
|
+
* the browser's parser and this decides what of the tree reaches the page.
|
|
62
|
+
* Without it, HTML shows as its source. See `SanitizeHtml`. Fixed for the
|
|
63
|
+
* editor's lifetime.
|
|
64
|
+
*/
|
|
65
|
+
sanitizeHtml?: SanitizeHtml;
|
|
58
66
|
/** A copy button on code blocks, which copies the code. Default true. Fixed for the editor's lifetime. */
|
|
59
67
|
codeCopy?: boolean;
|
|
60
68
|
/**
|
|
@@ -451,6 +459,14 @@ export declare class Editor {
|
|
|
451
459
|
private insertSourceMarkdown;
|
|
452
460
|
private undo;
|
|
453
461
|
private redo;
|
|
462
|
+
/**
|
|
463
|
+
* The rectangle for a selection with no text to measure (an empty block, or
|
|
464
|
+
* a caret next to an atom): the box of the content at `pos`. In source mode
|
|
465
|
+
* an empty line is an element of its own inside the text, so the box of the
|
|
466
|
+
* element at `node` stands in when it is one: the whole text's box would put
|
|
467
|
+
* the caret at the top of the document and scroll the view there.
|
|
468
|
+
*/
|
|
469
|
+
private emptyRect;
|
|
454
470
|
/** Scrolls the editor and the elements around it so the caret is visible. */
|
|
455
471
|
private scrollCaretIntoView;
|
|
456
472
|
destroy(): void;
|
|
@@ -109,9 +109,13 @@ export interface Extension {
|
|
|
109
109
|
* language (`code:mermaid`) renders code blocks of that language, such as
|
|
110
110
|
* diagrams. While editing, a token shows its source when the caret touches
|
|
111
111
|
* it, and a block when the selection is in it; clicking either does the
|
|
112
|
-
* same. Read-only always shows the rendered view.
|
|
112
|
+
* same. Read-only always shows the rendered view. Raw HTML is not a
|
|
113
|
+
* syntax an extension renders: the editor parses it and the `sanitizeHtml`
|
|
114
|
+
* option decides what is shown, so `html` is not a key here.
|
|
113
115
|
*/
|
|
114
|
-
readonly views?: Readonly<Record<string, SyntaxView
|
|
116
|
+
readonly views?: Readonly<Record<string, SyntaxView>> & {
|
|
117
|
+
readonly html?: never;
|
|
118
|
+
};
|
|
115
119
|
/**
|
|
116
120
|
* Draws the blocks `match` picks with `render`, in place of the editor's
|
|
117
121
|
* own rendering; see `BlockView`. `editor.refreshViews(name)`, with this
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ export { TOOLBAR_ITEMS, type ToolbarItem } from './ui/toolbar.js';
|
|
|
4
4
|
export type { Icon, IconName, Icons } from './icons.js';
|
|
5
5
|
export * from './model.js';
|
|
6
6
|
export * as commands from './commands.js';
|
|
7
|
-
export { parseMarkdown } from './markdown/parse.js';
|
|
7
|
+
export { parseMarkdown, parseAst } from './markdown/parse.js';
|
|
8
|
+
export { inlineNodesText, pieceEnd } from './markdown/ast.js';
|
|
9
|
+
export type { BlockNode, BlockQuoteNode, CodeBlockNode, CodeNode, ContentLine, ContentSource, HeadingNode, HtmlBlockNode, ImageNode, ImageNodeAlign, InlineNode, LinkNode, ListItemNode, ListNode, ParagraphNode, Positioned, Range, RawNode, Root, SourceLines, SyntaxRange, TableAlign, TableNode, TextNode, TextPiece, } from './markdown/ast.js';
|
|
10
|
+
export { visit, nodeChildren, sourceRange, type TreeNode, type Visitor } from './markdown/tree.js';
|
|
11
|
+
export { lineTable, type LineTable } from './markdown/sourceMap.js';
|
|
8
12
|
export { parseInline } from './markdown/inline.js';
|
|
9
13
|
export { serializeMarkdown, serializeInline, type SerializeOptions } from './markdown/serialize.js';
|
|
10
14
|
export { loadMarkdown, type MarkdownSource } from './markdown/source.js';
|
|
@@ -28,3 +32,4 @@ export type { SuggestionState } from './suggest/controller.js';
|
|
|
28
32
|
export type { Widget, WidgetRender } from './widgets.js';
|
|
29
33
|
export { fileHandler, type FileHandlerOptions } from './extensions/fileHandler.js';
|
|
30
34
|
export { defaultResolveUrl, type ResolveUrl, type UrlKind } from './view/dom.js';
|
|
35
|
+
export type { SanitizeHtml, SanitizeHtmlContext, SanitizedHtml } from './view/html.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Block } from '../model.js';
|
|
2
2
|
import type { BlockNode } from './ast.js';
|
|
3
3
|
import { type MarkdownOptions } from './options.js';
|
|
4
|
+
/** Elements that have no closing tag. */
|
|
5
|
+
export declare const VOID_ELEMENTS: Set<string>;
|
|
4
6
|
/**
|
|
5
7
|
* When top-level block `i` is an HTML block that leaves elements open, the
|
|
6
8
|
* index of the HTML block that closes them all. Returns `i` when there is
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BlockNode, ContentSource, InlineNode, ListItemNode, Range, Root } from './ast.js';
|
|
2
|
+
import { type LineTable } from './sourceMap.js';
|
|
3
|
+
/** A node of the syntax tree: the root, a block, a list item or an inline node. */
|
|
4
|
+
export type TreeNode = Root | BlockNode | ListItemNode | InlineNode;
|
|
5
|
+
/**
|
|
6
|
+
* Called for every node in document order with its ancestors, the root
|
|
7
|
+
* first. Return false to skip the node's children.
|
|
8
|
+
*/
|
|
9
|
+
export type Visitor = (node: TreeNode, ancestors: readonly TreeNode[]) => void | false;
|
|
10
|
+
/**
|
|
11
|
+
* The nodes under `node`, in document order: a list's items, an item's
|
|
12
|
+
* blocks, a table's cells' inline nodes row by row, an image's description.
|
|
13
|
+
*/
|
|
14
|
+
export declare function nodeChildren(node: TreeNode): readonly TreeNode[];
|
|
15
|
+
/** Visits `node` and everything under it, in document order. */
|
|
16
|
+
export declare function visit(node: TreeNode, visitor: Visitor): void;
|
|
17
|
+
/**
|
|
18
|
+
* Where a range of a leaf block's content is in the source text: the
|
|
19
|
+
* offsets of an inline node's `pos`, or of a code block's text, mapped back
|
|
20
|
+
* through the block's `source` (`ParagraphNode.source`, a table cell's entry
|
|
21
|
+
* in `TableNode.sources`). The result is `from` inclusive, `to` exclusive,
|
|
22
|
+
* and spans the prefixes of the lines between (quote markers, list
|
|
23
|
+
* indentation) when the range crosses a line. `text` is the Markdown the
|
|
24
|
+
* tree was parsed from, or its `lineTable`, for many lookups in one text.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sourceRange(text: string | LineTable, source: ContentSource, range: Range): Range;
|
|
@@ -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' | 'smartLists' | 'sourceHighlighting' | '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' | 'sourceHighlighting' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'sanitizeHtml' | '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;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Editor } from '../editor.js';
|
|
2
|
+
import type { SyntaxView } from '../extension.js';
|
|
3
|
+
/** What `sanitizeHtml` gets besides the tree. */
|
|
4
|
+
export interface SanitizeHtmlContext {
|
|
5
|
+
readonly editor: Editor;
|
|
6
|
+
/**
|
|
7
|
+
* `'block'` for an HTML block, including a section with Markdown between
|
|
8
|
+
* its tags; `'inline'` for a run of inline HTML in a paragraph, heading,
|
|
9
|
+
* list item, quote or table cell.
|
|
10
|
+
*/
|
|
11
|
+
readonly kind: 'inline' | 'block';
|
|
12
|
+
}
|
|
13
|
+
/** The tree to attach, or nothing to show the source instead. */
|
|
14
|
+
export type SanitizedHtml = Node | null | undefined | void;
|
|
15
|
+
/**
|
|
16
|
+
* Decides what of a piece of raw HTML reaches the page. Gets the HTML parsed
|
|
17
|
+
* into a `DocumentFragment` that is not in the page, so nothing in it has
|
|
18
|
+
* run or loaded yet, and returns the tree to attach: the fragment itself
|
|
19
|
+
* after removing what is not allowed, another node, or nothing to show the
|
|
20
|
+
* source instead. Text in the tree holds the editor's markers for the
|
|
21
|
+
* Markdown between the tags, which the editor renders itself and puts in
|
|
22
|
+
* place of the markers after the sanitizer has run; a sanitizer keeps text,
|
|
23
|
+
* so the markers survive. May return a promise, for a sanitizer loaded on
|
|
24
|
+
* demand: the HTML shows nothing until it settles, and a rejection shows
|
|
25
|
+
* the source.
|
|
26
|
+
*/
|
|
27
|
+
export type SanitizeHtml = (tree: DocumentFragment, ctx: SanitizeHtmlContext) => SanitizedHtml | PromiseLike<SanitizedHtml>;
|
|
28
|
+
/** The `html` view: raw HTML parsed by the browser and passed through `sanitize`. */
|
|
29
|
+
export declare function htmlView(sanitize: SanitizeHtml): SyntaxView;
|