@vitral/editor 0.2.8 → 0.2.10
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 +8 -0
- package/dist/buttons.js +3 -1
- package/dist/buttons.js.map +1 -1
- package/dist/editor.js +42 -4
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/math.d.ts +61 -0
- package/dist/math.js +404 -0
- package/dist/math.js.map +1 -0
- package/dist/render/toolbar.d.ts +2 -0
- package/dist/render/toolbar.js +17 -6
- package/dist/render/toolbar.js.map +1 -1
- package/dist/slash.js +2 -1
- package/dist/slash.js.map +1 -1
- package/dist/types.d.ts +43 -4
- package/package.json +6 -6
package/dist/slash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slash.js","names":[],"sources":["../src/slash.ts"],"sourcesContent":["import { editorSelectionRange, editorTextblocks, en, type EditorInstance, type EditorNode, type Locale } from '@vitral/core';\nimport { createOverlay, type OverlayTarget } from '@vitral/controls';\nimport type { Props } from '@vitral/dom';\nimport { slashMenuView } from './render/menus';\nimport type { CommandRunner, SlashCommand } from './types';\n\n/**\n * The menu a `/` opens, as a piece that attaches to any editor: the\n * framework-free one uses it, and so does a framework component that draws its\n * own toolbar. It watches the document, opens when a slash starts a word,\n * filters as it is typed, and takes the keys it needs while it is open.\n */\n\nexport interface SlashMenuOptions {\n editor: EditorInstance;\n /** The `contenteditable` element, where the keys are heard. */\n content: () => HTMLElement | null;\n /** What the menu hangs from: an element over the caret. */\n anchor: () => HTMLElement | null;\n /** The commands on offer; a function is read every time it opens. */\n commands: () => SlashCommand[];\n /** The classes and pass-through of the menu's parts. */\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Off while the editor is read-only. */\n enabled?: () => boolean;\n /** Puts the anchor where the caret is, before the menu opens. */\n place?: () => void;\n ids?: { slash: string; block: string };\n overlayTarget?: OverlayTarget;\n zIndex?: number;\n /** What to do with the command the reader chose; it runs itself by default. */\n onRun?: (command: SlashCommand) => void;\n}\n\nexport interface SlashMenu {\n readonly isOpen: boolean;\n /** Reads the document again: called on every change. */\n sync(): void;\n close(): void;\n destroy(): void;\n}\n\nexport function createSlashMenu(options: SlashMenuOptions): SlashMenu {\n let open: { query: string; active: number } | null = null;\n let element: HTMLElement | null = null;\n\n const locale = () => options.locale?.() ?? en;\n const ids = options.ids ?? { slash: 'vt-slash', block: 'vt-block' };\n const enabled = () => options.enabled?.() ?? true;\n\n /** What the query after the slash matches, by label, id and keyword. */\n function matches(query: string): SlashCommand[] {\n const needle = query.trim().toLocaleLowerCase(locale().code);\n const all = options.commands();\n if (!needle) return all;\n return all.filter((item) => [item.label, item.id, ...(item.keywords ?? [])].some((word) => word.toLocaleLowerCase(locale().code).includes(needle)));\n }\n\n const overlay = createOverlay({\n anchor: options.anchor,\n render: () =>\n open\n ? (slashMenuView({ locale: locale(), part: options.part, ids }, { query: open.query, items: matches(open.query), active: open.active }, { choose: run }) as never)\n : null,\n placement: 'bottom-start',\n target: () => options.overlayTarget,\n zIndex: options.zIndex,\n restoreFocus: false,\n onClose: () => (open = null)\n });\n\n /** The text of the block the caret is in, and where the caret is in it. */\n function caretText(): { text: string; offset: number } | null {\n const state = options.editor.state;\n if (!editorSelectionRange(state.selection).empty) return null;\n const blocks = editorTextblocks(state.doc);\n const path = state.selection.head.path;\n const block = blocks.find((entry) => entry.path.join('.') === path.join('.'))?.node ?? (path[0] === undefined ? undefined : (state.doc.content?.[path[0]] as EditorNode | undefined));\n if (!block) return null;\n const text = (block.content ?? []).map((child) => (typeof child === 'string' ? child : (child.text ?? ''))).join('');\n return { text, offset: state.selection.head.offset };\n }\n\n function sync() {\n if (!enabled()) return close();\n const caret = caretText();\n if (!caret) return close();\n const before = caret.text.slice(0, caret.offset);\n const at = before.lastIndexOf('/');\n const starts = at === 0 || (at > 0 && /\\s/.test(before[at - 1] ?? ''));\n if (at < 0 || !starts) return close();\n const query = before.slice(at + 1);\n if (/\\s/.test(query)) return close();\n open = { query, active: open && open.query === query ? open.active : 0 };\n options.place?.();\n overlay.open();\n overlay.update();\n }\n\n function close() {\n if (!overlay.isOpen) {\n open = null;\n return;\n }\n overlay.close();\n }\n\n /** Runs what the menu was pointing at, after taking the slash and its query out. */\n function run(index: number) {\n const items = matches(open?.query ?? '');\n const item = items[index];\n if (!item || !open) return;\n const remove = open.query.length + 1;\n close();\n for (let n = 0; n < remove; n++) options.editor.backspace('char');\n if (options.onRun) options.onRun(item);\n // An entry's own `run` is what an application writes a command of its\n // own with: without this it was only ever called by a host that passed\n // `onRun`, so a slash command with a `run` did nothing in Vue.\n else if (item.run) item.run(options.editor as unknown as CommandRunner);\n else if (item.command) (options.editor.run as (name: string, ...args: unknown[]) => boolean)(item.command[0], ...item.command.slice(1));\n }\n\n /**\n * While the menu is open those keys are the menu's. The listener is a\n * capturing one: the editor's own view listens on the same element, and an\n * Enter it heard would split the block the command is about to change.\n */\n function onKeydown(event: KeyboardEvent) {\n if (!open) return;\n const items = matches(open.query);\n const take = () => {\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n take();\n const step = event.key === 'ArrowDown' ? 1 : -1;\n open = { ...open, active: (open.active + step + items.length) % Math.max(1, items.length) };\n overlay.update();\n return;\n }\n if (event.key === 'Home' || event.key === 'End') {\n take();\n open = { ...open, active: event.key === 'Home' ? 0 : Math.max(0, items.length - 1) };\n overlay.update();\n return;\n }\n if (event.key === 'Enter' || event.key === 'Tab') {\n if (!items.length) return;\n take();\n run(open.active);\n return;\n }\n if (event.key === 'Escape') {\n take();\n close();\n }\n }\n\n function listen() {\n const next = options.content();\n if (next === element) return;\n element?.removeEventListener('keydown', onKeydown, true);\n element = next;\n element?.addEventListener('keydown', onKeydown, true);\n }\n\n const stop = options.editor.subscribe(() => {\n listen();\n sync();\n });\n listen();\n // The document may already be mid-word: a menu attached after a slash was\n // typed (a re-attach, a component that mounted late) opens straight away.\n sync();\n\n return {\n get isOpen() {\n return overlay.isOpen;\n },\n sync() {\n listen();\n sync();\n },\n close,\n destroy() {\n stop();\n element?.removeEventListener('keydown', onKeydown, true);\n element = null;\n overlay.destroy();\n }\n };\n}\n\n/** The blocks a slash offers when an application names none. */\nexport function defaultSlashCommands(locale: Locale): SlashCommand[] {\n const words = locale.editor;\n const entry = (id: string, icon: string, command: readonly [string, ...unknown[]]): SlashCommand => ({\n id,\n icon,\n label: words.slashCommands[id] ?? id,\n description: words.slashHints[id],\n command\n });\n return [\n entry('paragraph', 'pilcrow', ['setParagraph']),\n entry('heading1', 'heading1', ['toggleHeading', 1]),\n entry('heading2', 'heading2', ['toggleHeading', 2]),\n entry('heading3', 'heading3', ['toggleHeading', 3]),\n entry('bulletList', 'list', ['toggleBulletList']),\n entry('orderedList', 'listOrdered', ['toggleOrderedList']),\n entry('taskList', 'listChecks', ['toggleTaskList']),\n entry('blockquote', 'quote', ['toggleBlockquote']),\n entry('codeBlock', 'codeBlock', ['toggleCodeBlock']),\n entry('horizontalRule', 'horizontalRule', ['insertHorizontalRule']),\n entry('table', 'table', ['insertTable', 3, 3, true]),\n entry('image', 'image', ['insertImage', { src: '' }])\n ];\n}\n"],"mappings":";;;;AA2CA,SAAgB,gBAAgB,SAAsC;CAClE,IAAI,OAAiD;CACrD,IAAI,UAA8B;CAElC,MAAM,eAAe,QAAQ,SAAS,KAAK;CAC3C,MAAM,MAAM,QAAQ,OAAO;EAAE,OAAO;EAAY,OAAO;CAAW;CAClE,MAAM,gBAAgB,QAAQ,UAAU,KAAK;;CAG7C,SAAS,QAAQ,OAA+B;EAC5C,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,kBAAkB,OAAO,CAAC,CAAC,IAAI;EAC3D,MAAM,MAAM,QAAQ,SAAS;EAC7B,IAAI,CAAC,QAAQ,OAAO;EACpB,OAAO,IAAI,QAAQ,SAAS;GAAC,KAAK;GAAO,KAAK;GAAI,GAAI,KAAK,YA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AAC,CAAC;EAClD,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,cAAc,QAAQ,CAAC,kBAAkB,CAAC;EAChD,MAAM,eAAe,eAAe,CAAC,mBAAmB,CAAC;EACzD,MAAM,YAAY,cAAc,CAAC,gBAAgB,CAAC;EAClD,MAAM,cAAc,SAAS,CAAC,kBAAkB,CAAC;EACjD,MAAM,aAAa,aAAa,CAAC,iBAAiB,CAAC;EACnD,MAAM,kBAAkB,kBAAkB,CAAC,sBAAsB,CAAC;EAClE,MAAM,SAAS,SAAS;GAAC;GAAe;GAAG;GAAG;EAAI,CAAC;EACnD,MAAM,SAAS,SAAS,CAAC,eAAe,EAAE,KAAK,GAAG,CAAC,CAAC;CACxD;AACJ"}
|
|
1
|
+
{"version":3,"file":"slash.js","names":[],"sources":["../src/slash.ts"],"sourcesContent":["import { editorSelectionRange, editorTextblocks, en, type EditorInstance, type EditorNode, type Locale } from '@vitral/core';\nimport { createOverlay, type OverlayTarget } from '@vitral/controls';\nimport type { Props } from '@vitral/dom';\nimport { slashMenuView } from './render/menus';\nimport type { CommandRunner, SlashCommand } from './types';\n\n/**\n * The menu a `/` opens, as a piece that attaches to any editor: the\n * framework-free one uses it, and so does a framework component that draws its\n * own toolbar. It watches the document, opens when a slash starts a word,\n * filters as it is typed, and takes the keys it needs while it is open.\n */\n\nexport interface SlashMenuOptions {\n editor: EditorInstance;\n /** The `contenteditable` element, where the keys are heard. */\n content: () => HTMLElement | null;\n /** What the menu hangs from: an element over the caret. */\n anchor: () => HTMLElement | null;\n /** The commands on offer; a function is read every time it opens. */\n commands: () => SlashCommand[];\n /** The classes and pass-through of the menu's parts. */\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Off while the editor is read-only. */\n enabled?: () => boolean;\n /** Puts the anchor where the caret is, before the menu opens. */\n place?: () => void;\n ids?: { slash: string; block: string };\n overlayTarget?: OverlayTarget;\n zIndex?: number;\n /** What to do with the command the reader chose; it runs itself by default. */\n onRun?: (command: SlashCommand) => void;\n}\n\nexport interface SlashMenu {\n readonly isOpen: boolean;\n /** Reads the document again: called on every change. */\n sync(): void;\n close(): void;\n destroy(): void;\n}\n\nexport function createSlashMenu(options: SlashMenuOptions): SlashMenu {\n let open: { query: string; active: number } | null = null;\n let element: HTMLElement | null = null;\n\n const locale = () => options.locale?.() ?? en;\n const ids = options.ids ?? { slash: 'vt-slash', block: 'vt-block' };\n const enabled = () => options.enabled?.() ?? true;\n\n /** What the query after the slash matches, by label, id and keyword. */\n function matches(query: string): SlashCommand[] {\n const needle = query.trim().toLocaleLowerCase(locale().code);\n const all = options.commands();\n if (!needle) return all;\n return all.filter((item) => [item.label, item.id, ...(item.keywords ?? [])].some((word) => word.toLocaleLowerCase(locale().code).includes(needle)));\n }\n\n const overlay = createOverlay({\n anchor: options.anchor,\n render: () =>\n open\n ? (slashMenuView({ locale: locale(), part: options.part, ids }, { query: open.query, items: matches(open.query), active: open.active }, { choose: run }) as never)\n : null,\n placement: 'bottom-start',\n target: () => options.overlayTarget,\n zIndex: options.zIndex,\n restoreFocus: false,\n onClose: () => (open = null)\n });\n\n /** The text of the block the caret is in, and where the caret is in it. */\n function caretText(): { text: string; offset: number } | null {\n const state = options.editor.state;\n if (!editorSelectionRange(state.selection).empty) return null;\n const blocks = editorTextblocks(state.doc);\n const path = state.selection.head.path;\n const block = blocks.find((entry) => entry.path.join('.') === path.join('.'))?.node ?? (path[0] === undefined ? undefined : (state.doc.content?.[path[0]] as EditorNode | undefined));\n if (!block) return null;\n const text = (block.content ?? []).map((child) => (typeof child === 'string' ? child : (child.text ?? ''))).join('');\n return { text, offset: state.selection.head.offset };\n }\n\n function sync() {\n if (!enabled()) return close();\n const caret = caretText();\n if (!caret) return close();\n const before = caret.text.slice(0, caret.offset);\n const at = before.lastIndexOf('/');\n const starts = at === 0 || (at > 0 && /\\s/.test(before[at - 1] ?? ''));\n if (at < 0 || !starts) return close();\n const query = before.slice(at + 1);\n if (/\\s/.test(query)) return close();\n open = { query, active: open && open.query === query ? open.active : 0 };\n options.place?.();\n overlay.open();\n overlay.update();\n }\n\n function close() {\n if (!overlay.isOpen) {\n open = null;\n return;\n }\n overlay.close();\n }\n\n /** Runs what the menu was pointing at, after taking the slash and its query out. */\n function run(index: number) {\n const items = matches(open?.query ?? '');\n const item = items[index];\n if (!item || !open) return;\n const remove = open.query.length + 1;\n close();\n for (let n = 0; n < remove; n++) options.editor.backspace('char');\n if (options.onRun) options.onRun(item);\n // An entry's own `run` is what an application writes a command of its\n // own with: without this it was only ever called by a host that passed\n // `onRun`, so a slash command with a `run` did nothing in Vue.\n else if (item.run) item.run(options.editor as unknown as CommandRunner);\n else if (item.command) (options.editor.run as (name: string, ...args: unknown[]) => boolean)(item.command[0], ...item.command.slice(1));\n }\n\n /**\n * While the menu is open those keys are the menu's. The listener is a\n * capturing one: the editor's own view listens on the same element, and an\n * Enter it heard would split the block the command is about to change.\n */\n function onKeydown(event: KeyboardEvent) {\n if (!open) return;\n const items = matches(open.query);\n const take = () => {\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n take();\n const step = event.key === 'ArrowDown' ? 1 : -1;\n open = { ...open, active: (open.active + step + items.length) % Math.max(1, items.length) };\n overlay.update();\n return;\n }\n if (event.key === 'Home' || event.key === 'End') {\n take();\n open = { ...open, active: event.key === 'Home' ? 0 : Math.max(0, items.length - 1) };\n overlay.update();\n return;\n }\n if (event.key === 'Enter' || event.key === 'Tab') {\n if (!items.length) return;\n take();\n run(open.active);\n return;\n }\n if (event.key === 'Escape') {\n take();\n close();\n }\n }\n\n function listen() {\n const next = options.content();\n if (next === element) return;\n element?.removeEventListener('keydown', onKeydown, true);\n element = next;\n element?.addEventListener('keydown', onKeydown, true);\n }\n\n const stop = options.editor.subscribe(() => {\n listen();\n sync();\n });\n listen();\n // The document may already be mid-word: a menu attached after a slash was\n // typed (a re-attach, a component that mounted late) opens straight away.\n sync();\n\n return {\n get isOpen() {\n return overlay.isOpen;\n },\n sync() {\n listen();\n sync();\n },\n close,\n destroy() {\n stop();\n element?.removeEventListener('keydown', onKeydown, true);\n element = null;\n overlay.destroy();\n }\n };\n}\n\n/** The blocks a slash offers when an application names none. */\nexport function defaultSlashCommands(locale: Locale): SlashCommand[] {\n const words = locale.editor;\n const entry = (id: string, icon: string, command: readonly [string, ...unknown[]]): SlashCommand => ({\n id,\n icon,\n label: words.slashCommands[id] ?? id,\n description: words.slashHints[id],\n command\n });\n return [\n entry('paragraph', 'pilcrow', ['setParagraph']),\n entry('heading1', 'heading1', ['toggleHeading', 1]),\n entry('heading2', 'heading2', ['toggleHeading', 2]),\n entry('heading3', 'heading3', ['toggleHeading', 3]),\n entry('bulletList', 'list', ['toggleBulletList']),\n entry('orderedList', 'listOrdered', ['toggleOrderedList']),\n entry('taskList', 'listChecks', ['toggleTaskList']),\n entry('blockquote', 'quote', ['toggleBlockquote']),\n entry('codeBlock', 'codeBlock', ['toggleCodeBlock']),\n entry('horizontalRule', 'horizontalRule', ['insertHorizontalRule']),\n entry('table', 'table', ['insertTable', 3, 3, true]),\n entry('image', 'image', ['insertImage', { src: '' }]),\n // Not a command of the document's: the host opens its formula panel for it, and leaves it out where formulas are off.\n entry('math', 'sigma', ['math'])\n ];\n}\n"],"mappings":";;;;AA2CA,SAAgB,gBAAgB,SAAsC;CAClE,IAAI,OAAiD;CACrD,IAAI,UAA8B;CAElC,MAAM,eAAe,QAAQ,SAAS,KAAK;CAC3C,MAAM,MAAM,QAAQ,OAAO;EAAE,OAAO;EAAY,OAAO;CAAW;CAClE,MAAM,gBAAgB,QAAQ,UAAU,KAAK;;CAG7C,SAAS,QAAQ,OAA+B;EAC5C,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,kBAAkB,OAAO,CAAC,CAAC,IAAI;EAC3D,MAAM,MAAM,QAAQ,SAAS;EAC7B,IAAI,CAAC,QAAQ,OAAO;EACpB,OAAO,IAAI,QAAQ,SAAS;GAAC,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AClD,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,cAAc,QAAQ,CAAC,kBAAkB,CAAC;EAChD,MAAM,eAAe,eAAe,CAAC,mBAAmB,CAAC;EACzD,MAAM,YAAY,cAAc,CAAC,gBAAgB,CAAC;EAClD,MAAM,cAAc,SAAS,CAAC,kBAAkB,CAAC;EACjD,MAAM,aAAa,aAAa,CAAC,iBAAiB,CAAC;EACnD,MAAM,kBAAkB,kBAAkB,CAAC,sBAAsB,CAAC;EAClE,MAAM,SAAS,SAAS;GAAC;GAAe;GAAG;GAAG;EAAI,CAAC;EACnD,MAAM,SAAS,SAAS,CAAC,eAAe,EAAE,KAAK,GAAG,CAAC,CAAC;EAEpD,MAAM,QAAQ,SAAS,CAAC,MAAM,CAAC;CACnC;AACJ"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ import type { PassThrough } from '@vitral/dom';
|
|
|
7
7
|
* toolbar, which panels, what a host draws itself.
|
|
8
8
|
*/
|
|
9
9
|
/** What a toolbar can hold, by name. */
|
|
10
|
-
export type EditorToolbarItem = 'blockType' | 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'bold' | 'italic' | 'underline' | 'strike' | 'code' | 'color' | 'highlight' | 'bulletList' | 'orderedList' | 'taskList' | 'indent' | 'outdent' | 'blockquote' | 'codeBlock' | 'image' | 'table' | 'horizontalRule' | 'link' | 'undo' | 'redo' | 'clear' | 'find';
|
|
10
|
+
export type EditorToolbarItem = 'blockType' | 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'bold' | 'italic' | 'underline' | 'strike' | 'code' | 'color' | 'highlight' | 'bulletList' | 'orderedList' | 'taskList' | 'indent' | 'outdent' | 'blockquote' | 'codeBlock' | 'image' | 'table' | 'math' | 'horizontalRule' | 'link' | 'undo' | 'redo' | 'clear' | 'find';
|
|
11
11
|
/** The commands a plain button can run. */
|
|
12
|
-
export type EditorButtonCommand = Exclude<EditorToolbarItem, 'blockType' | 'color' | 'highlight' | 'image' | 'table' | 'find'>;
|
|
12
|
+
export type EditorButtonCommand = Exclude<EditorToolbarItem, 'blockType' | 'color' | 'highlight' | 'image' | 'table' | 'math' | 'find'>;
|
|
13
13
|
/** One entry of the menu a slash opens. */
|
|
14
14
|
/** Something a chip trigger offers: who or what the chip will stand for. */
|
|
15
15
|
export interface ChipSuggestion {
|
|
@@ -36,6 +36,34 @@ export interface ChipTrigger {
|
|
|
36
36
|
/** Given to every chip this trigger makes, unless its suggestion says otherwise. */
|
|
37
37
|
kind?: string;
|
|
38
38
|
}
|
|
39
|
+
/** A formula the formula panel offers ready-made, drawn on a button. */
|
|
40
|
+
export interface MathTemplate {
|
|
41
|
+
/** Identifies it, and is what a host matches on. */
|
|
42
|
+
id: string;
|
|
43
|
+
/** What it is called: the button's name. */
|
|
44
|
+
label: string;
|
|
45
|
+
/** What pressing it writes into the formula. */
|
|
46
|
+
latex: string;
|
|
47
|
+
}
|
|
48
|
+
/** How formulas are edited, where the defaults are not what is wanted. */
|
|
49
|
+
export interface EditorMathOptions {
|
|
50
|
+
/** The ready-made formulas the panel offers. The usual ones when left out; none for an empty list. */
|
|
51
|
+
templates?: MathTemplate[];
|
|
52
|
+
/**
|
|
53
|
+
* Whether a number, a letter or a sign of a formula pressed in the text is
|
|
54
|
+
* edited where it stands, in a box over it. On by default; off, a press
|
|
55
|
+
* anywhere on a formula opens the panel with that piece selected.
|
|
56
|
+
*/
|
|
57
|
+
inlineEdit?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* How a formula is written into the HTML the editor hands back:
|
|
60
|
+
* `'drawing'` (the default) puts its drawing inside it, so the HTML shows
|
|
61
|
+
* the formula anywhere, with nothing of Vitral's on the page; `'source'`
|
|
62
|
+
* writes the LaTeX alone, which is far smaller to store, and is drawn
|
|
63
|
+
* where it is shown with `renderMathIn`. Either is read back the same.
|
|
64
|
+
*/
|
|
65
|
+
output?: 'drawing' | 'source';
|
|
66
|
+
}
|
|
39
67
|
export interface SlashCommand {
|
|
40
68
|
/** Identifies it, and is what a host matches on. */
|
|
41
69
|
id: string;
|
|
@@ -92,6 +120,15 @@ export interface TextEditorConfig {
|
|
|
92
120
|
* once. Chips can also be put in with `run('insertChip', { id, label, kind })`.
|
|
93
121
|
*/
|
|
94
122
|
chips?: ChipTrigger | ChipTrigger[];
|
|
123
|
+
/**
|
|
124
|
+
* Formulas: the toolbar's formula button, the slash menu's entry, the
|
|
125
|
+
* panel that writes one in LaTeX, and editing one by pressing it in the
|
|
126
|
+
* text. On by default; `false` leaves formulas already in the document
|
|
127
|
+
* drawn and takes every way of making or changing one away. An object says
|
|
128
|
+
* which ready-made formulas the panel offers and whether a value is edited
|
|
129
|
+
* where it stands. One can also be put in with `run('insertMath', { latex })`.
|
|
130
|
+
*/
|
|
131
|
+
math?: boolean | EditorMathOptions;
|
|
95
132
|
/**
|
|
96
133
|
* Find and replace: Ctrl/⌘+F opens the bar over the text, Ctrl+H (⌘+⌥+F
|
|
97
134
|
* on a Mac) opens it with the replace row. On by default; `false` leaves
|
|
@@ -148,8 +185,10 @@ export interface TextEditorEvents {
|
|
|
148
185
|
/** The editor, as the outside sees it. */
|
|
149
186
|
export interface TextEditorHandle {
|
|
150
187
|
update(config: Partial<TextEditorConfig>): void;
|
|
151
|
-
/** The document as HTML. */
|
|
152
|
-
getHTML(
|
|
188
|
+
/** The document as HTML. `math` says how formulas are written in this one, whatever the editor's own setting. */
|
|
189
|
+
getHTML(options?: {
|
|
190
|
+
math?: 'drawing' | 'source';
|
|
191
|
+
}): string;
|
|
153
192
|
getJSON(): EditorNode;
|
|
154
193
|
getText(): string;
|
|
155
194
|
getMarkdown(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitral/editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Framework-free rich text editor for Vitral: the toolbar, the panels and the content area over @vitral/core's editor engine, which the Vue, React and Angular components wrap.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitral",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@vitral/
|
|
48
|
-
"@vitral/
|
|
49
|
-
"@vitral/dom": "0.2.
|
|
50
|
-
"@vitral/
|
|
51
|
-
"@vitral/
|
|
47
|
+
"@vitral/core": "0.2.10",
|
|
48
|
+
"@vitral/controls": "0.2.10",
|
|
49
|
+
"@vitral/dom": "0.2.10",
|
|
50
|
+
"@vitral/icons": "0.2.10",
|
|
51
|
+
"@vitral/styles": "0.2.10"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "vite build && tsc -p tsconfig.build.json"
|