@usememos/editor 26.11.4 → 26.11.6
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 +1 -1
- package/dist/index.js +69 -68
- package/dist/index.js.map +3 -3
- package/dist/react.js +2 -2
- package/dist/react.js.map +3 -3
- package/dist/types/editor.d.ts +3 -2
- package/dist/types/keymap.d.ts +2 -0
- package/dist/types/ui/popup.d.ts +0 -2
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Editor as
|
|
2
|
-
`),
|
|
1
|
+
import{Editor as p}from"@usememos/editor";import{forwardRef as v,useEffect as a,useRef as c,useState as k}from"react";import{flushSync as C}from"react-dom";import{jsx as h}from"react/jsx-runtime";var x=["placeholder","mode","editable","taskToggle","attributes","resolveUrl","onLinkClick","theme","extensions"],w=e=>(e??[]).map(t=>t.name).join(`
|
|
2
|
+
`),H=v(function(t,r){let s=c(null),n=c(null),o=c([]),i=c(t);i.current=t;let d=w(t.extensions);return a(()=>{let{value:u,defaultValue:l,onChange:b,onSubmit:L,onFocus:M,onBlur:O,className:F,style:T,...S}=i.current,y=n.current,f=new p({...S,element:s.current,content:y?.getMarkdown()??u??l??"",onChange:g=>{o.current.push(g),o.current.length>100&&o.current.shift(),C(()=>i.current.onChange?.(g))},onSubmit:g=>i.current.onSubmit?.(g),onFocus:()=>i.current.onFocus?.(),onBlur:()=>i.current.onBlur?.()});return n.current=f,o.current=[],E(r,f),()=>{f.destroy(),n.current===f&&(n.current=null),E(r,null)}},[d]),a(()=>{let u=n.current;if(!u||t.value===void 0)return;let l=o.current.indexOf(t.value);if(l>=0){o.current.splice(0,l+1);return}o.current=[],u.syncControlledMarkdown(t.value)},[t.value]),P(n,t),h("div",{ref:s,className:t.className,style:t.style})});function P(e,t){let r=c({editor:null,props:{}});a(()=>{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 x)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 V(e,t=[]){let[r,s]=k(null),n=c(e);return n.current=e,a(()=>{r&&e.extensions&&r.setOptions({extensions:e.extensions})},[r,e.extensions]),a(()=>{let o=n.current,i=document.createElement("div"),d=new p({...o,element:i,autofocus:!1,onChange:(u,l)=>n.current.onChange?.(u,l),onSubmit:(u,l)=>n.current.onSubmit?.(u,l),onFocus:u=>n.current.onFocus?.(u),onBlur:u=>n.current.onBlur?.(u),onLinkClick:u=>n.current.onLinkClick?.(u)});return o.autofocus&&m.set(d,o.autofocus==="end"?"end":"start"),s(d),()=>{d.destroy(),s(null)}},t),r}function I(e,t){let r=o=>o&&(t===void 0||o.name===t)?o:null,[s,n]=k(()=>r(e?.suggestion.state));return a(()=>{if(!e){n(null);return}return n(r(e.suggestion.state)),e.on("suggestionChange",({state:o})=>n(r(o)))},[e,t]),s}function D({editor:e,className:t,style:r}){let s=c(null);return a(()=>{let n=s.current;if(!e||!n)return;n.appendChild(e.root);let o=m.get(e);return o&&(m.delete(e),e.commands.focus(o)),()=>{e.root.parentNode===n&&n.removeChild(e.root)}},[e]),h("div",{ref:s,className:t,style:r})}var m=new WeakMap;function E(e,t){typeof e=="function"?e(t):e&&(e.current=t)}export{D as EditorContent,H as MarkdownEditor,V as useEditor,I 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 | '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/F,OAAS,aAAAC,MAAiB,
|
|
6
|
-
"names": ["Editor", "forwardRef", "useEffect", "useRef", "useState", "flushSync", "jsx", "LIVE", "extensionKey", "extensions", "e", "MarkdownEditor", "props", "ref", "container", "editorRef", "pending", "
|
|
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 // 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 return () => {\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 pending.current = [];\n editor.syncControlledMarkdown(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,YA2HjB,cAAAC,MAAA,oBA5ET,IAAMC,EAAO,CAAC,cAAe,OAAQ,WAAY,aAAc,aAAc,aAAc,cAAe,QAAS,YAAY,EAGzHC,EAAgBC,IAA6CA,GAAc,CAAC,GAAG,IAAKC,GAAMA,EAAE,IAAI,EAAE,KAAK;AAAA,CAAI,EAcpGC,EAAiBV,EAAW,SAAwBW,EAA4BC,EAAkC,CAC7H,IAAMC,EAAYX,EAAuB,IAAI,EACvCY,EAAYZ,EAAsB,IAAI,EAItCa,EAAUb,EAAiB,CAAC,CAAC,EAE7Bc,EAASd,EAAOS,CAAK,EAC3BK,EAAO,QAAUL,EACjB,IAAMH,EAAaD,EAAaI,EAAM,UAAU,EAEhD,OAAAV,EAAU,IAAM,CACd,GAAM,CAAE,MAAAgB,EAAO,aAAAC,EAAc,SAAAC,EAAU,SAAAC,EAAU,QAAAC,EAAS,OAAAC,EAAQ,UAAAC,EAAW,MAAAC,EAAO,GAAGC,CAAQ,EAAIT,EAAO,QACpGU,EAAWZ,EAAU,QACrBa,EAAS,IAAI5B,EAAO,CACxB,GAAG0B,EACH,QAASZ,EAAU,QACnB,QAASa,GAAU,YAAY,GAAKT,GAASC,GAAgB,GAC7D,SAAWU,GAAa,CACtBb,EAAQ,QAAQ,KAAKa,CAAQ,EACzBb,EAAQ,QAAQ,OAAS,KAAKA,EAAQ,QAAQ,MAAM,EAKxDX,EA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ensionKey", "extensions", "e", "MarkdownEditor", "props", "ref", "container", "editorRef", "pending", "latest", "value", "defaultValue", "onChange", "onSubmit", "onFocus", "onBlur", "className", "style", "options", "previous", "editor", "markdown", "assignRef", "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
|
@@ -295,8 +295,7 @@ export declare class Editor {
|
|
|
295
295
|
* block, the marks for composed text, and whether it has an undo step yet.
|
|
296
296
|
*/
|
|
297
297
|
private composition;
|
|
298
|
-
|
|
299
|
-
private compositionEndedAt;
|
|
298
|
+
private pendingMarkdown;
|
|
300
299
|
/**
|
|
301
300
|
* The last Markdown shortcut that typing applied: the state with the typed
|
|
302
301
|
* characters, and the state the shortcut made. Backspace right after it
|
|
@@ -378,6 +377,7 @@ export declare class Editor {
|
|
|
378
377
|
/**
|
|
379
378
|
* Replaces the whole document. Does not emit `change`. By default clears
|
|
380
379
|
* undo history; with `history: 'keep'` the replacement is one undo step.
|
|
380
|
+
* During IME composition the latest replacement waits for the final input.
|
|
381
381
|
*/
|
|
382
382
|
setMarkdown(markdown: string, options?: {
|
|
383
383
|
history?: 'clear' | 'keep';
|
|
@@ -588,6 +588,7 @@ export declare class Editor {
|
|
|
588
588
|
private targetRange;
|
|
589
589
|
/** Events from the code-language input and other form controls inside the root are not editor input. */
|
|
590
590
|
private fromControl;
|
|
591
|
+
private restoreCommittedCaret;
|
|
591
592
|
private onBeforeInput;
|
|
592
593
|
/** Input that works differently on text in source mode. Returns true when handled. */
|
|
593
594
|
private onSourceInput;
|
package/dist/types/keymap.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { KeyHandler } from './extension.js';
|
|
2
|
+
/** WebKit can send the confirming key after compositionend with only keyCode 229. */
|
|
3
|
+
export declare function isCompositionKey(event: KeyboardEvent): boolean;
|
|
2
4
|
interface Binding {
|
|
3
5
|
readonly key: string;
|
|
4
6
|
readonly ctrl: boolean;
|
package/dist/types/ui/popup.d.ts
CHANGED
|
@@ -22,8 +22,6 @@ export declare function visibleViewport(view: Window): {
|
|
|
22
22
|
height: number;
|
|
23
23
|
};
|
|
24
24
|
export declare const isMac: boolean;
|
|
25
|
-
/** Safari, which sends the Enter that commits a composition after `compositionend`. */
|
|
26
|
-
export declare const isSafari: boolean;
|
|
27
25
|
/** True on touch devices, which have no hover and show their own menu over a selection. */
|
|
28
26
|
export declare const isTouch: () => boolean;
|
|
29
27
|
export declare class Popup {
|