@vitral/editor 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor.js +27 -1
- package/dist/editor.js.map +1 -1
- package/dist/find.d.ts +36 -0
- package/dist/find.js +319 -0
- package/dist/find.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/render/toolbar.d.ts +2 -0
- package/dist/render/toolbar.js +15 -2
- package/dist/render/toolbar.js.map +1 -1
- package/dist/types.d.ts +14 -2
- package/package.json +6 -6
package/dist/editor.js
CHANGED
|
@@ -3,8 +3,9 @@ import { bubbleView, toolbarView } from "./render/toolbar.js";
|
|
|
3
3
|
import { colorPanelView, imagePanelView, linkPanelView, tablePanelView } from "./render/menus.js";
|
|
4
4
|
import { createBlockHandle, defaultBlockActions } from "./block.js";
|
|
5
5
|
import { createChipMenu } from "./chips.js";
|
|
6
|
+
import { createFindBar } from "./find.js";
|
|
6
7
|
import { createSlashMenu, defaultSlashCommands } from "./slash.js";
|
|
7
|
-
import { activeEditorBlockType, activeEditorMark, ariaEditorShortcut, createEditor, createEditorView, editorLinkAt, editorLinkHint, editorPalette, editorSelectionRange, editorShortcutFor, en, followEditorLink, formatEditorShortcut, formatMessage, isEmptyEditorDoc, loadStyle, matchEditorPaletteColor, visuallyHidden } from "@vitral/core";
|
|
8
|
+
import { activeEditorBlockType, activeEditorMark, ariaEditorShortcut, createEditor, createEditorView, editorKeyName, editorLinkAt, editorLinkHint, editorPalette, editorSelectionRange, editorShortcutFor, en, followEditorLink, formatEditorShortcut, formatMessage, isEmptyEditorDoc, isMacPlatform, loadStyle, matchEditorPaletteColor, visuallyHidden } from "@vitral/core";
|
|
8
9
|
import { createOverlay, createSelect, createTooltips } from "@vitral/controls";
|
|
9
10
|
import { createRoot, h, mergeAttrs, partResolver } from "@vitral/dom";
|
|
10
11
|
import { registerIcons } from "@vitral/icons";
|
|
@@ -82,6 +83,7 @@ function createTextEditor(element, config = {}) {
|
|
|
82
83
|
json: editor.getJSON(),
|
|
83
84
|
text: editor.getText()
|
|
84
85
|
});
|
|
86
|
+
if (update.docChanged) findBar.sync();
|
|
85
87
|
if (update.selectionChanged) current.on?.["selection-change"]?.({
|
|
86
88
|
empty: collapsed(),
|
|
87
89
|
source: update.origin === "user" ? "user" : update.origin === "history" ? "history" : "api"
|
|
@@ -257,6 +259,24 @@ function createTextEditor(element, config = {}) {
|
|
|
257
259
|
overlayTarget: current.overlayTarget,
|
|
258
260
|
zIndex: current.zIndex
|
|
259
261
|
});
|
|
262
|
+
const findBar = createFindBar({
|
|
263
|
+
editor,
|
|
264
|
+
view: () => view,
|
|
265
|
+
part,
|
|
266
|
+
locale,
|
|
267
|
+
editable,
|
|
268
|
+
render: () => render(),
|
|
269
|
+
id: `${id}-find`
|
|
270
|
+
});
|
|
271
|
+
const onFindKey = (event) => {
|
|
272
|
+
if (current.find === false) return;
|
|
273
|
+
const name = editorKeyName(event);
|
|
274
|
+
const replace = name === (isMacPlatform() ? "Mod-Alt-f" : "Mod-h");
|
|
275
|
+
if (name !== "Mod-f" && !replace) return;
|
|
276
|
+
event.preventDefault();
|
|
277
|
+
findBar.open({ replace });
|
|
278
|
+
};
|
|
279
|
+
element.addEventListener("keydown", onFindKey);
|
|
260
280
|
/** The caret's own rectangle, as an element popups can be anchored to. */
|
|
261
281
|
function placeCaret() {
|
|
262
282
|
if (!caretEl || !contentEl) return;
|
|
@@ -312,6 +332,7 @@ function createTextEditor(element, config = {}) {
|
|
|
312
332
|
if (event.detail > 0) focus();
|
|
313
333
|
},
|
|
314
334
|
openLink: (event) => openLinkPanel(event),
|
|
335
|
+
openFind: () => findBar.isOpen ? findBar.close() : findBar.open(),
|
|
315
336
|
openImage: (event) => openPanel(imagePanel, "image", event),
|
|
316
337
|
openTable: (event) => openPanel(tablePanel, "table", event),
|
|
317
338
|
openColor: (kind, event) => {
|
|
@@ -428,6 +449,7 @@ function createTextEditor(element, config = {}) {
|
|
|
428
449
|
}));
|
|
429
450
|
root.render([
|
|
430
451
|
current.hooks?.toolbar ? current.hooks.toolbar() : current.toolbar === false ? null : toolbarView(drawn, toolbarGroups()),
|
|
452
|
+
findBar.view(),
|
|
431
453
|
contentView(),
|
|
432
454
|
h("span", mergeAttrs({
|
|
433
455
|
key: "caret",
|
|
@@ -502,9 +524,13 @@ function createTextEditor(element, config = {}) {
|
|
|
502
524
|
can,
|
|
503
525
|
isActive: (name, attrs) => editor.isActive(name, attrs),
|
|
504
526
|
focus,
|
|
527
|
+
openFind: (options) => findBar.open(options),
|
|
528
|
+
closeFind: () => findBar.close({ focusEditor: false }),
|
|
505
529
|
refresh: render,
|
|
506
530
|
destroy() {
|
|
507
531
|
stop();
|
|
532
|
+
element.removeEventListener("keydown", onFindKey);
|
|
533
|
+
findBar.destroy();
|
|
508
534
|
slashMenu.destroy();
|
|
509
535
|
chipMenu.destroy();
|
|
510
536
|
blockHandle.destroy();
|
package/dist/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","names":[],"sources":["../src/editor.ts"],"sourcesContent":["import {\n activeEditorBlockType,\n activeEditorMark,\n ariaEditorShortcut,\n createEditor as createEditorInstance,\n createEditorView,\n editorLinkAt,\n editorLinkHint,\n editorPalette,\n editorShortcutFor,\n editorSelectionRange,\n editorTextblocks,\n en,\n formatEditorShortcut,\n followEditorLink,\n formatMessage,\n isEmptyEditorDoc,\n loadStyle,\n matchEditorPaletteColor,\n visuallyHidden,\n type EditorColor,\n type EditorInstance,\n type EditorNode,\n type EditorView,\n type Locale\n} from '@vitral/core';\nimport { createOverlay, createSelect, createTooltips, type Overlay, type SelectHandle } from '@vitral/controls';\nimport { createRoot, h, mergeAttrs, partResolver, type Child, type Props } from '@vitral/dom';\nimport { registerIcons } from '@vitral/icons';\nimport { baseStyle, buttonStyle, editorStyle } from '@vitral/styles';\nimport { defaultBubbleMenu, defaultToolbar, editorIcons } from './buttons';\nimport { createBlockHandle, defaultBlockActions } from './block';\nimport { colorPanelView, imagePanelView, linkPanelView, tablePanelView, type LinkPanelState, type PanelContext } from './render/menus';\nimport { createChipMenu } from './chips';\nimport { createSlashMenu, defaultSlashCommands } from './slash';\nimport { bubbleView, toolbarView, type ToolbarContext } from './render/toolbar';\nimport type { TextEditorConfig, TextEditorHandle, EditorToolbarItem } from './types';\n\n/**\n * A rich text editor with no framework in it: the document, the commands and\n * the history are `@vitral/core`'s, the text itself is its view over a\n * `contenteditable` element, and everything around them — the toolbar, the\n * panels, the floating toolbar over a selection, the menu a `/` opens and the\n * handle beside a block — is drawn here.\n */\n\nlet counter = 0;\n\nexport function createTextEditor(element: HTMLElement, config: TextEditorConfig = {}): TextEditorHandle {\n let current: TextEditorConfig = { ...config };\n let view: EditorView | null = null;\n let contentEl: HTMLElement | null = null;\n let caretEl: HTMLElement | null = null;\n let blockSelect: SelectHandle | null = null;\n let blockSelectHost: HTMLElement | null = null;\n let link: LinkPanelState = { href: '', text: '', newTab: false, existing: false };\n const anchors = new Map<string, HTMLElement>();\n\n const id = config.id ?? `vt-texteditor-${++counter}`;\n const ids = { content: `${id}-content`, help: `${id}-help`, slash: `${id}-slash`, block: `${id}-block` };\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const palette = (): readonly EditorColor[] => current.palette ?? editorPalette;\n const part = partResolver({\n style: editorStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!config.unstyled) {\n const options = { nonce: config.nonce, cssLayer: config.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(buttonStyle.name, buttonStyle.css, options);\n loadStyle(editorStyle.name, editorStyle.css, options);\n }\n // The toolbar holds its own definitions, but the slash menu, the block\n // handle and any command an application names its own icon for are looked\n // up by name: the editor puts its set in the registry rather than drawing\n // a bar of empty buttons in an application that never registered them.\n // What each button is, shown the way every other Vitral control shows it.\n const tooltips = createTooltips(() => ({\n placement: 'bottom',\n unstyled: current.unstyled,\n nonce: current.nonce,\n cssLayer: current.cssLayer,\n zIndex: current.zIndex,\n pt: current.pt\n }));\n\n registerIcons(editorIcons);\n\n const editor: EditorInstance = createEditorInstance({\n content: current.content ?? '',\n maxLength: current.maxLength ?? null,\n historyDelay: current.historyDelay\n });\n\n const editable = () => !current.readonly && !current.disabled;\n const collapsed = () => editorSelectionRange(editor.state.selection).empty;\n const run = (name: string, ...args: unknown[]) => (editor.run as (n: string, ...a: unknown[]) => boolean)(name, ...args);\n const can = (name: string, ...args: unknown[]) => (editor.can as (n: string, ...a: unknown[]) => boolean)(name, ...args);\n\n // ---- what the outside hears ---------------------------------------------------------\n\n const stop = editor.subscribe((update) => {\n if (update.docChanged) {\n current.on?.change?.({ html: editor.getHTML(), json: editor.getJSON(), text: editor.getText() });\n }\n if (update.selectionChanged) {\n current.on?.['selection-change']?.({ empty: collapsed(), source: update.origin === 'user' ? 'user' : update.origin === 'history' ? 'history' : 'api' });\n }\n render();\n });\n\n // ---- the panels ------------------------------------------------------------------------\n\n const panelContext = (): PanelContext => ({ locale: locale(), part, ids });\n\n const anchorFor = (name: string) => () => anchors.get(name) ?? caretEl;\n\n function panel(name: string, render: () => ReturnType<typeof linkPanelView> | null, placement: 'bottom-start' | 'bottom-end' = 'bottom-start'): Overlay {\n return createOverlay({\n anchor: anchorFor(name),\n render,\n placement,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n onClose: () => renderPanels()\n });\n }\n\n const linkPanel = panel('link', () => linkPanelView(panelContext(), link, linkActions));\n const imagePanel = panel('image', () => imagePanelView(panelContext(), imageActions));\n const tablePanel = panel('table', () => tablePanelView(panelContext(), { insert: insertTable }));\n const colorPanel = panel('color', () => colorPanelView(panelContext(), { kind: colorKind, palette: palette(), chosen: colorOf(colorKind), onChoose: chooseColor }));\n let colorKind: 'color' | 'highlight' = 'color';\n\n const linkActions = {\n change: (patch: Partial<LinkPanelState>) => {\n link = { ...link, ...patch, error: undefined };\n linkPanel.update();\n },\n apply: () => {\n const href = link.href.trim();\n if (!href) {\n link = { ...link, error: locale().editor.invalidUrl };\n linkPanel.update();\n return;\n }\n run('setLink', href, { target: link.newTab ? '_blank' : null, text: link.text.trim() || undefined });\n linkPanel.close();\n focus();\n },\n remove: () => {\n run('unsetLink');\n linkPanel.close();\n focus();\n },\n open: () => {\n followEditorLink(link.href.trim());\n linkPanel.close();\n },\n cancel: () => {\n linkPanel.close();\n focus();\n }\n };\n\n /** The link editor, filled in with the link under the caret when there is one. */\n function openLinkPanel(event?: MouseEvent) {\n if (!editable()) return;\n const at = editorLinkAt(editor.state);\n link = { href: at?.href ?? '', text: at?.text ?? '', newTab: at?.target === '_blank', existing: !!at };\n if (!event) placeCaret();\n openPanel(linkPanel, 'link', event);\n }\n\n const imageActions = {\n insert: (src: string, alt: string) => {\n if (src.trim()) run('insertImage', { src: src.trim(), alt: alt.trim() });\n imagePanel.close();\n focus();\n },\n cancel: () => {\n imagePanel.close();\n focus();\n }\n };\n\n function insertTable(rows: number, columns: number) {\n run('insertTable', rows, columns, true);\n tablePanel.close();\n focus();\n }\n\n const colorOf = (kind: 'color' | 'highlight'): EditorColor | undefined => {\n const mark = activeEditorMark(editor.state, kind);\n const value = mark?.attrs?.color;\n if (typeof value !== 'string') return undefined;\n const name = matchEditorPaletteColor(value, kind, palette());\n return palette().find((color) => color.name === name);\n };\n\n function chooseColor(color: EditorColor | null) {\n run(colorKind === 'color' ? 'setColor' : 'setHighlight', color?.name ?? null);\n colorPanel.close();\n focus();\n }\n\n // ---- the floating toolbar over a selection -----------------------------------------------\n\n const bubble = createOverlay({\n anchor: () => caretEl,\n render: () => bubbleView(toolbarContext(), bubbleItems()) as never,\n placement: 'top',\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n restoreFocus: false\n });\n\n const bubbleItems = (): EditorToolbarItem[] => (Array.isArray(current.bubbleMenu) ? current.bubbleMenu : defaultBubbleMenu);\n\n function syncBubble() {\n const wanted = current.bubbleMenu !== false && editable() && !collapsed() && !editor.isEmpty();\n if (wanted) {\n placeCaret();\n bubble.open();\n bubble.update();\n } else bubble.close();\n }\n\n // ---- the menu a slash opens, and the handle beside a block ---------------------------------\n\n const chipMenu = createChipMenu({\n editor,\n content: () => contentEl,\n anchor: () => caretEl,\n triggers: () => (current.chips ? (Array.isArray(current.chips) ? current.chips : [current.chips]) : []),\n part,\n locale,\n enabled: () => !!current.chips && editable(),\n place: placeCaret,\n id: `${ids.slash}-chips`,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex\n });\n\n const slashMenu = createSlashMenu({\n editor,\n content: () => contentEl,\n anchor: () => caretEl,\n commands: () => (Array.isArray(current.slashMenu) ? current.slashMenu : defaultSlashCommands(locale())),\n part,\n locale,\n enabled: () => current.slashMenu !== false && editable(),\n place: placeCaret,\n ids,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex,\n onRun: (command) => {\n if (command.run) command.run(handle);\n else if (command.command) run(command.command[0], ...command.command.slice(1));\n focus();\n }\n });\n\n const blockHandle = createBlockHandle({\n editor,\n host: () => element,\n caretRect: () => view?.selectionRect() ?? null,\n content: () => contentEl,\n actions: () => (Array.isArray(current.blockMenu) ? current.blockMenu : defaultBlockActions(locale())),\n part,\n locale,\n enabled: () => current.blockMenu !== false && editable(),\n ids,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex\n });\n\n // ---- where a popup hangs from ---------------------------------------------------------------\n\n /** The caret's own rectangle, as an element popups can be anchored to. */\n function placeCaret() {\n if (!caretEl || !contentEl) return;\n const rect = view?.selectionRect();\n if (!rect) return;\n const host = element.getBoundingClientRect();\n caretEl.style.top = `${rect.top - host.top}px`;\n caretEl.style.left = `${rect.left - host.left}px`;\n caretEl.style.width = `${Math.max(1, rect.width)}px`;\n caretEl.style.height = `${rect.height}px`;\n }\n\n function openPanel(overlay: Overlay, name: string, event?: MouseEvent) {\n if (event) anchors.set(name, event.currentTarget as HTMLElement);\n else anchors.delete(name);\n closePanels(overlay);\n overlay.open();\n overlay.update();\n }\n\n const panels = () => [linkPanel, imagePanel, tablePanel, colorPanel];\n const closePanels = (except?: Overlay) => panels().forEach((overlay) => overlay !== except && overlay.close());\n const renderPanels = () => panels().forEach((overlay) => overlay.update());\n\n // ---- the toolbar -----------------------------------------------------------------------------\n\n function toolbarContext(): ToolbarContext {\n return {\n locale: locale(),\n part,\n editable: editable(),\n can,\n isActive: (name, attrs) => editor.isActive(name, attrs as never),\n shortcut: (name, args) => {\n const binding = editorShortcutFor(name, args);\n return binding ? { label: formatEditorShortcut(binding), aria: ariaEditorShortcut(binding) } : undefined;\n },\n colors: { text: colorOf('color'), highlight: colorOf('highlight') },\n ref: (name) => (el) => {\n if (el) anchors.set(name, el as HTMLElement);\n else anchors.delete(name);\n },\n on: {\n tip: (element, text) => tooltips.attach(element, text),\n command: (name, args, event) => {\n run(name, ...args);\n if (event.detail > 0) focus();\n },\n openLink: (event) => openLinkPanel(event),\n openImage: (event) => openPanel(imagePanel, 'image', event),\n openTable: (event) => openPanel(tablePanel, 'table', event),\n openColor: (kind, event) => {\n colorKind = kind;\n openPanel(colorPanel, kind, event);\n },\n blockSelect: (el) => {\n blockSelectHost = (el as HTMLElement | null) ?? null;\n syncBlockSelect();\n }\n }\n };\n }\n\n /** The block type, drawn by the control kit's select. */\n function syncBlockSelect() {\n if (!blockSelectHost) return;\n const words = locale().editor;\n const options = [\n { label: words.paragraph, value: 'paragraph' },\n { label: words.heading1, value: 'heading1' },\n { label: words.heading2, value: 'heading2' },\n { label: words.heading3, value: 'heading3' },\n { label: words.codeBlock, value: 'codeBlock' }\n ];\n const active = activeEditorBlockType(editor.state);\n const settings = {\n options,\n optionValue: 'value',\n value: active,\n size: 'small' as const,\n ariaLabel: words.blockType,\n disabled: !editable(),\n locale: locale(),\n unstyled: current.unstyled,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex,\n nonce: current.nonce,\n cssLayer: current.cssLayer\n };\n if (blockSelect) blockSelect.update(settings);\n else\n blockSelect = createSelect(blockSelectHost, {\n ...settings,\n onChange: (value) => {\n if (value === 'paragraph') run('setParagraph');\n else if (value === 'codeBlock') run('toggleCodeBlock');\n else run('toggleHeading', Number(String(value).slice(-1)));\n focus();\n }\n });\n }\n\n // ---- drawing --------------------------------------------------------------------------------\n\n const toolbarGroups = (): EditorToolbarItem[][] => (Array.isArray(current.toolbar) ? current.toolbar : defaultToolbar);\n\n function countText(): string {\n const words = locale().editor;\n const count = editor.characterCount();\n const characters = current.maxLength\n ? formatMessage(words.charactersLimit, { count, limit: current.maxLength })\n : formatMessage(count === 1 ? words.character : words.characters, { count });\n const mode = current.showCount === true ? 'characters' : current.showCount;\n if (mode === 'characters' || !mode) return characters;\n const wordCount = editor.wordCount();\n const wordText = formatMessage(wordCount === 1 ? words.word : words.words, { count: wordCount });\n return mode === 'words' ? wordText : `${wordText} · ${characters}`;\n }\n\n function contentView(): Child {\n return h(\n 'div',\n mergeAttrs({ key: 'content', id: ids.content }, part('content'), {\n class: isEmptyEditorDoc(editor.state.doc) ? 'vt-editor-content-empty' : undefined,\n role: 'textbox',\n 'aria-multiline': 'true',\n 'aria-label': current.ariaLabelledby ? undefined : current.ariaLabel,\n 'aria-labelledby': current.ariaLabelledby,\n 'aria-describedby': ids.help,\n 'aria-readonly': current.readonly ? 'true' : undefined,\n 'aria-disabled': current.disabled ? 'true' : undefined,\n 'aria-invalid': current.invalid ? 'true' : undefined,\n 'aria-placeholder': current.placeholder || undefined,\n 'data-placeholder': current.placeholder || undefined,\n contenteditable: editable() ? 'true' : 'false',\n tabindex: current.disabled ? '-1' : '0',\n spellcheck: 'true',\n translate: 'no',\n ref: (el: Element | null) => {\n const next = el as HTMLElement | null;\n if (next === contentEl) return;\n contentEl = next;\n attachView();\n },\n onFocus: (event: FocusEvent) => current.on?.focus?.(event),\n onBlur: (event: FocusEvent) => current.on?.blur?.(event)\n })\n );\n }\n\n function render() {\n const drawn = toolbarContext();\n root.attrs(part('root', { readonly: current.readonly, disabled: current.disabled, invalid: current.invalid }));\n root.render([\n current.hooks?.toolbar ? (current.hooks.toolbar() as Child) : current.toolbar === false ? null : toolbarView(drawn, toolbarGroups()),\n contentView(),\n h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'), { ref: (el: Element | null) => (caretEl = el as HTMLElement | null) })),\n h('span', { key: 'help', id: ids.help, style: visuallyHidden }, locale().editor.keyboardHelp),\n current.hooks?.footer\n ? (current.hooks.footer() as Child)\n : current.showCount\n ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), h('span', part('count', { limit: !!current.maxLength }), countText()))\n : null\n ]);\n syncBlockSelect();\n syncBubble();\n renderPanels();\n blockHandle.sync();\n }\n\n function attachView() {\n view?.destroy();\n view = null;\n if (!contentEl) return;\n view = createEditorView(contentEl, editor, {\n editable,\n taskLabel: locale().editor.taskDone,\n selectedClass: 'vt-editor-node-selected',\n emptyClass: 'vt-editor-content-empty',\n chipClass: (kind) => (current.unstyled ? undefined : ['vt-editor-chip', kind ? `vt-editor-chip-${kind}` : ''].filter(Boolean).join(' ')),\n // Ctrl/⌘+K opens the link editor, over the caret.\n handleKey: (_name, binding) => {\n if (binding?.[0] !== 'link' || !editable()) return false;\n openLinkPanel();\n return true;\n },\n linkHint: (href) => ({ ...tooltips.options(editorLinkHint(href, locale().editor.followLink)), placement: 'top' })\n });\n if (current.autofocus) view.focus();\n }\n\n const focus = () => view?.focus();\n\n render();\n\n const handle: TextEditorHandle = {\n element,\n update(next) {\n const content = 'content' in next;\n current = { ...current, ...next };\n if (content) editor.setContent(current.content ?? '', { emit: false });\n if ('maxLength' in next) editor.maxLength = current.maxLength ?? null;\n render();\n },\n getHTML: () => editor.getHTML(),\n getJSON: () => editor.getJSON(),\n getText: () => editor.getText(),\n getMarkdown: () => editor.getMarkdown(),\n typeText: (text) => {\n const typed = editor.typeText(text);\n render();\n return typed;\n },\n setContent: (value) => {\n editor.setContent(value);\n render();\n },\n run: (name, ...args) => {\n const applied = run(name, ...args);\n render();\n return applied;\n },\n can,\n isActive: (name, attrs) => editor.isActive(name, attrs as never),\n focus,\n refresh: render,\n destroy() {\n stop();\n slashMenu.destroy();\n chipMenu.destroy();\n blockHandle.destroy();\n [...panels(), bubble].forEach((overlay) => overlay.destroy());\n blockSelect?.destroy();\n tooltips.destroy();\n view?.destroy();\n root.clear();\n }\n };\n\n return handle;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,IAAI,UAAU;AAEd,SAAgB,iBAAiB,SAAsB,SAA2B,CAAC,GAAqB;CACpG,IAAI,UAA4B,EAAE,GAAG,OAAO;CAC5C,IAAI,OAA0B;CAC9B,IAAI,YAAgC;CACpC,IAAI,UAA8B;CAClC,IAAI,cAAmC;CACvC,IAAI,kBAAsC;CAC1C,IAAI,OAAuB;EAAE,MAAM;EAAI,MAAM;EAAI,QAAQ;EAAO,UAAU;CAAM;CAChF,MAAM,0BAAU,IAAI,IAAyB;CAE7C,MAAM,KAAK,OAAO,MAAM,iBAAiB,EAAE;CAC3C,MAAM,MAAM;EAAE,SAAS,GAAG,GAAG;EAAW,MAAM,GAAG,GAAG;EAAQ,OAAO,GAAG,GAAG;EAAS,OAAO,GAAG,GAAG;CAAQ;CACvG,MAAM,OAAO,WAAW,OAAO;CAC/B,MAAM,eAAuB,QAAQ,UAAU;CAC/C,MAAM,gBAAwC,QAAQ,WAAW;CACjE,MAAM,OAAO,aAAa;EACtB,OAAO;EACP,gBAAgB,CAAC,CAAC,QAAQ;EAC1B,eAAe,QAAQ;EACvB,UAAU,QAAQ;EAClB,aAAa;CACjB,CAAC;CAED,IAAI,CAAC,OAAO,UAAU;EAClB,MAAM,UAAU;GAAE,OAAO,OAAO;GAAO,UAAU,OAAO;EAAS;EACjE,UAAU,UAAU,MAAM,UAAU,KAAK,OAAO;EAChD,UAAU,YAAY,MAAM,YAAY,KAAK,OAAO;EACpD,UAAU,YAAY,MAAM,YAAY,KAAK,OAAO;CACxD;CAMA,MAAM,WAAW,sBAAsB;EACnC,WA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AW,IAAI,EAAE,MAAM,MAAM,CAAC;GACrE,IAAI,eAAe,MAAM,OAAO,YAAY,QAAQ,aAAa;GACjE,OAAO;EACX;EACA,eAAe,OAAO,QAAQ;EAC9B,eAAe,OAAO,QAAQ;EAC9B,eAAe,OAAO,QAAQ;EAC9B,mBAAmB,OAAO,YAAY;EACtC,WAAW,SAAS;GAChB,MAAM,QAAQ,OAAO,SAAS,IAAI;GAClC,OAAO;GACP,OAAO;EACX;EACA,aAAa,UAAU;GACnB,OAAO,WAAW,KAAK;GACvB,OAAO;EACX;EACA,MAAM,MAAM,GAAG,SAAS;GACpB,MAAM,UAAU,IAAI,MAAM,GAAG,IAAI;GACjC,OAAO;GACP,OAAO;EACX;EACA;EACA,WAAW,MAAM,UAAU,OAAO,SAAS,MAAM,KAAc;EAC/D;EACA,SAAS;EACT,UAAU;GACN,KAAK;GACL,UAAU,QAAQ;GAClB,SAAS,QAAQ;GACjB,YAAY,QAAQ;GACpB,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC,SAAS,YAAY,QAAQ,QAAQ,CAAC;GAC5D,aAAa,QAAQ;GACrB,SAAS,QAAQ;GACjB,MAAM,QAAQ;GACd,KAAK,MAAM;EACf;CACJ;CAEA,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"editor.js","names":[],"sources":["../src/editor.ts"],"sourcesContent":["import {\n activeEditorBlockType,\n activeEditorMark,\n ariaEditorShortcut,\n createEditor as createEditorInstance,\n createEditorView,\n editorLinkAt,\n editorKeyName,\n editorLinkHint,\n editorPalette,\n editorShortcutFor,\n editorSelectionRange,\n editorTextblocks,\n en,\n formatEditorShortcut,\n followEditorLink,\n formatMessage,\n isEmptyEditorDoc,\n isMacPlatform,\n loadStyle,\n matchEditorPaletteColor,\n visuallyHidden,\n type EditorColor,\n type EditorInstance,\n type EditorNode,\n type EditorView,\n type Locale\n} from '@vitral/core';\nimport { createOverlay, createSelect, createTooltips, type Overlay, type SelectHandle } from '@vitral/controls';\nimport { createRoot, h, mergeAttrs, partResolver, type Child, type Props } from '@vitral/dom';\nimport { registerIcons } from '@vitral/icons';\nimport { baseStyle, buttonStyle, editorStyle } from '@vitral/styles';\nimport { defaultBubbleMenu, defaultToolbar, editorIcons } from './buttons';\nimport { createBlockHandle, defaultBlockActions } from './block';\nimport { colorPanelView, imagePanelView, linkPanelView, tablePanelView, type LinkPanelState, type PanelContext } from './render/menus';\nimport { createChipMenu } from './chips';\nimport { createFindBar } from './find';\nimport { createSlashMenu, defaultSlashCommands } from './slash';\nimport { bubbleView, toolbarView, type ToolbarContext } from './render/toolbar';\nimport type { TextEditorConfig, TextEditorHandle, EditorToolbarItem } from './types';\n\n/**\n * A rich text editor with no framework in it: the document, the commands and\n * the history are `@vitral/core`'s, the text itself is its view over a\n * `contenteditable` element, and everything around them — the toolbar, the\n * panels, the floating toolbar over a selection, the menu a `/` opens and the\n * handle beside a block — is drawn here.\n */\n\nlet counter = 0;\n\nexport function createTextEditor(element: HTMLElement, config: TextEditorConfig = {}): TextEditorHandle {\n let current: TextEditorConfig = { ...config };\n let view: EditorView | null = null;\n let contentEl: HTMLElement | null = null;\n let caretEl: HTMLElement | null = null;\n let blockSelect: SelectHandle | null = null;\n let blockSelectHost: HTMLElement | null = null;\n let link: LinkPanelState = { href: '', text: '', newTab: false, existing: false };\n const anchors = new Map<string, HTMLElement>();\n\n const id = config.id ?? `vt-texteditor-${++counter}`;\n const ids = { content: `${id}-content`, help: `${id}-help`, slash: `${id}-slash`, block: `${id}-block` };\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const palette = (): readonly EditorColor[] => current.palette ?? editorPalette;\n const part = partResolver({\n style: editorStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!config.unstyled) {\n const options = { nonce: config.nonce, cssLayer: config.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(buttonStyle.name, buttonStyle.css, options);\n loadStyle(editorStyle.name, editorStyle.css, options);\n }\n // The toolbar holds its own definitions, but the slash menu, the block\n // handle and any command an application names its own icon for are looked\n // up by name: the editor puts its set in the registry rather than drawing\n // a bar of empty buttons in an application that never registered them.\n // What each button is, shown the way every other Vitral control shows it.\n const tooltips = createTooltips(() => ({\n placement: 'bottom',\n unstyled: current.unstyled,\n nonce: current.nonce,\n cssLayer: current.cssLayer,\n zIndex: current.zIndex,\n pt: current.pt\n }));\n\n registerIcons(editorIcons);\n\n const editor: EditorInstance = createEditorInstance({\n content: current.content ?? '',\n maxLength: current.maxLength ?? null,\n historyDelay: current.historyDelay\n });\n\n const editable = () => !current.readonly && !current.disabled;\n const collapsed = () => editorSelectionRange(editor.state.selection).empty;\n const run = (name: string, ...args: unknown[]) => (editor.run as (n: string, ...a: unknown[]) => boolean)(name, ...args);\n const can = (name: string, ...args: unknown[]) => (editor.can as (n: string, ...a: unknown[]) => boolean)(name, ...args);\n\n // ---- what the outside hears ---------------------------------------------------------\n\n const stop = editor.subscribe((update) => {\n if (update.docChanged) {\n current.on?.change?.({ html: editor.getHTML(), json: editor.getJSON(), text: editor.getText() });\n }\n if (update.docChanged) findBar.sync();\n if (update.selectionChanged) {\n current.on?.['selection-change']?.({ empty: collapsed(), source: update.origin === 'user' ? 'user' : update.origin === 'history' ? 'history' : 'api' });\n }\n render();\n });\n\n // ---- the panels ------------------------------------------------------------------------\n\n const panelContext = (): PanelContext => ({ locale: locale(), part, ids });\n\n const anchorFor = (name: string) => () => anchors.get(name) ?? caretEl;\n\n function panel(name: string, render: () => ReturnType<typeof linkPanelView> | null, placement: 'bottom-start' | 'bottom-end' = 'bottom-start'): Overlay {\n return createOverlay({\n anchor: anchorFor(name),\n render,\n placement,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n onClose: () => renderPanels()\n });\n }\n\n const linkPanel = panel('link', () => linkPanelView(panelContext(), link, linkActions));\n const imagePanel = panel('image', () => imagePanelView(panelContext(), imageActions));\n const tablePanel = panel('table', () => tablePanelView(panelContext(), { insert: insertTable }));\n const colorPanel = panel('color', () => colorPanelView(panelContext(), { kind: colorKind, palette: palette(), chosen: colorOf(colorKind), onChoose: chooseColor }));\n let colorKind: 'color' | 'highlight' = 'color';\n\n const linkActions = {\n change: (patch: Partial<LinkPanelState>) => {\n link = { ...link, ...patch, error: undefined };\n linkPanel.update();\n },\n apply: () => {\n const href = link.href.trim();\n if (!href) {\n link = { ...link, error: locale().editor.invalidUrl };\n linkPanel.update();\n return;\n }\n run('setLink', href, { target: link.newTab ? '_blank' : null, text: link.text.trim() || undefined });\n linkPanel.close();\n focus();\n },\n remove: () => {\n run('unsetLink');\n linkPanel.close();\n focus();\n },\n open: () => {\n followEditorLink(link.href.trim());\n linkPanel.close();\n },\n cancel: () => {\n linkPanel.close();\n focus();\n }\n };\n\n /** The link editor, filled in with the link under the caret when there is one. */\n function openLinkPanel(event?: MouseEvent) {\n if (!editable()) return;\n const at = editorLinkAt(editor.state);\n link = { href: at?.href ?? '', text: at?.text ?? '', newTab: at?.target === '_blank', existing: !!at };\n if (!event) placeCaret();\n openPanel(linkPanel, 'link', event);\n }\n\n const imageActions = {\n insert: (src: string, alt: string) => {\n if (src.trim()) run('insertImage', { src: src.trim(), alt: alt.trim() });\n imagePanel.close();\n focus();\n },\n cancel: () => {\n imagePanel.close();\n focus();\n }\n };\n\n function insertTable(rows: number, columns: number) {\n run('insertTable', rows, columns, true);\n tablePanel.close();\n focus();\n }\n\n const colorOf = (kind: 'color' | 'highlight'): EditorColor | undefined => {\n const mark = activeEditorMark(editor.state, kind);\n const value = mark?.attrs?.color;\n if (typeof value !== 'string') return undefined;\n const name = matchEditorPaletteColor(value, kind, palette());\n return palette().find((color) => color.name === name);\n };\n\n function chooseColor(color: EditorColor | null) {\n run(colorKind === 'color' ? 'setColor' : 'setHighlight', color?.name ?? null);\n colorPanel.close();\n focus();\n }\n\n // ---- the floating toolbar over a selection -----------------------------------------------\n\n const bubble = createOverlay({\n anchor: () => caretEl,\n render: () => bubbleView(toolbarContext(), bubbleItems()) as never,\n placement: 'top',\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n restoreFocus: false\n });\n\n const bubbleItems = (): EditorToolbarItem[] => (Array.isArray(current.bubbleMenu) ? current.bubbleMenu : defaultBubbleMenu);\n\n function syncBubble() {\n const wanted = current.bubbleMenu !== false && editable() && !collapsed() && !editor.isEmpty();\n if (wanted) {\n placeCaret();\n bubble.open();\n bubble.update();\n } else bubble.close();\n }\n\n // ---- the menu a slash opens, and the handle beside a block ---------------------------------\n\n const chipMenu = createChipMenu({\n editor,\n content: () => contentEl,\n anchor: () => caretEl,\n triggers: () => (current.chips ? (Array.isArray(current.chips) ? current.chips : [current.chips]) : []),\n part,\n locale,\n enabled: () => !!current.chips && editable(),\n place: placeCaret,\n id: `${ids.slash}-chips`,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex\n });\n\n const slashMenu = createSlashMenu({\n editor,\n content: () => contentEl,\n anchor: () => caretEl,\n commands: () => (Array.isArray(current.slashMenu) ? current.slashMenu : defaultSlashCommands(locale())),\n part,\n locale,\n enabled: () => current.slashMenu !== false && editable(),\n place: placeCaret,\n ids,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex,\n onRun: (command) => {\n if (command.run) command.run(handle);\n else if (command.command) run(command.command[0], ...command.command.slice(1));\n focus();\n }\n });\n\n const blockHandle = createBlockHandle({\n editor,\n host: () => element,\n caretRect: () => view?.selectionRect() ?? null,\n content: () => contentEl,\n actions: () => (Array.isArray(current.blockMenu) ? current.blockMenu : defaultBlockActions(locale())),\n part,\n locale,\n enabled: () => current.blockMenu !== false && editable(),\n ids,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex\n });\n\n // ---- find and replace ---------------------------------------------------------------------\n\n const findBar = createFindBar({\n editor,\n view: () => view,\n part,\n locale,\n editable,\n render: () => render(),\n id: `${id}-find`\n });\n\n // Ctrl/⌘+F finds and Ctrl+H (⌘+⌥+F on a Mac, where ⌘+H hides the app)\n // replaces, anywhere in the editor — the text, the toolbar or the bar.\n const onFindKey = (event: KeyboardEvent) => {\n if (current.find === false) return;\n const name = editorKeyName(event);\n const replace = name === (isMacPlatform() ? 'Mod-Alt-f' : 'Mod-h');\n if (name !== 'Mod-f' && !replace) return;\n event.preventDefault();\n findBar.open({ replace });\n };\n element.addEventListener('keydown', onFindKey);\n\n // ---- where a popup hangs from ---------------------------------------------------------------\n\n /** The caret's own rectangle, as an element popups can be anchored to. */\n function placeCaret() {\n if (!caretEl || !contentEl) return;\n const rect = view?.selectionRect();\n if (!rect) return;\n const host = element.getBoundingClientRect();\n caretEl.style.top = `${rect.top - host.top}px`;\n caretEl.style.left = `${rect.left - host.left}px`;\n caretEl.style.width = `${Math.max(1, rect.width)}px`;\n caretEl.style.height = `${rect.height}px`;\n }\n\n function openPanel(overlay: Overlay, name: string, event?: MouseEvent) {\n if (event) anchors.set(name, event.currentTarget as HTMLElement);\n else anchors.delete(name);\n closePanels(overlay);\n overlay.open();\n overlay.update();\n }\n\n const panels = () => [linkPanel, imagePanel, tablePanel, colorPanel];\n const closePanels = (except?: Overlay) => panels().forEach((overlay) => overlay !== except && overlay.close());\n const renderPanels = () => panels().forEach((overlay) => overlay.update());\n\n // ---- the toolbar -----------------------------------------------------------------------------\n\n function toolbarContext(): ToolbarContext {\n return {\n locale: locale(),\n part,\n editable: editable(),\n can,\n isActive: (name, attrs) => editor.isActive(name, attrs as never),\n shortcut: (name, args) => {\n const binding = editorShortcutFor(name, args);\n return binding ? { label: formatEditorShortcut(binding), aria: ariaEditorShortcut(binding) } : undefined;\n },\n colors: { text: colorOf('color'), highlight: colorOf('highlight') },\n ref: (name) => (el) => {\n if (el) anchors.set(name, el as HTMLElement);\n else anchors.delete(name);\n },\n on: {\n tip: (element, text) => tooltips.attach(element, text),\n command: (name, args, event) => {\n run(name, ...args);\n if (event.detail > 0) focus();\n },\n openLink: (event) => openLinkPanel(event),\n openFind: () => (findBar.isOpen ? findBar.close() : findBar.open()),\n openImage: (event) => openPanel(imagePanel, 'image', event),\n openTable: (event) => openPanel(tablePanel, 'table', event),\n openColor: (kind, event) => {\n colorKind = kind;\n openPanel(colorPanel, kind, event);\n },\n blockSelect: (el) => {\n blockSelectHost = (el as HTMLElement | null) ?? null;\n syncBlockSelect();\n }\n }\n };\n }\n\n /** The block type, drawn by the control kit's select. */\n function syncBlockSelect() {\n if (!blockSelectHost) return;\n const words = locale().editor;\n const options = [\n { label: words.paragraph, value: 'paragraph' },\n { label: words.heading1, value: 'heading1' },\n { label: words.heading2, value: 'heading2' },\n { label: words.heading3, value: 'heading3' },\n { label: words.codeBlock, value: 'codeBlock' }\n ];\n const active = activeEditorBlockType(editor.state);\n const settings = {\n options,\n optionValue: 'value',\n value: active,\n size: 'small' as const,\n ariaLabel: words.blockType,\n disabled: !editable(),\n locale: locale(),\n unstyled: current.unstyled,\n overlayTarget: current.overlayTarget,\n zIndex: current.zIndex,\n nonce: current.nonce,\n cssLayer: current.cssLayer\n };\n if (blockSelect) blockSelect.update(settings);\n else\n blockSelect = createSelect(blockSelectHost, {\n ...settings,\n onChange: (value) => {\n if (value === 'paragraph') run('setParagraph');\n else if (value === 'codeBlock') run('toggleCodeBlock');\n else run('toggleHeading', Number(String(value).slice(-1)));\n focus();\n }\n });\n }\n\n // ---- drawing --------------------------------------------------------------------------------\n\n const toolbarGroups = (): EditorToolbarItem[][] => (Array.isArray(current.toolbar) ? current.toolbar : defaultToolbar);\n\n function countText(): string {\n const words = locale().editor;\n const count = editor.characterCount();\n const characters = current.maxLength\n ? formatMessage(words.charactersLimit, { count, limit: current.maxLength })\n : formatMessage(count === 1 ? words.character : words.characters, { count });\n const mode = current.showCount === true ? 'characters' : current.showCount;\n if (mode === 'characters' || !mode) return characters;\n const wordCount = editor.wordCount();\n const wordText = formatMessage(wordCount === 1 ? words.word : words.words, { count: wordCount });\n return mode === 'words' ? wordText : `${wordText} · ${characters}`;\n }\n\n function contentView(): Child {\n return h(\n 'div',\n mergeAttrs({ key: 'content', id: ids.content }, part('content'), {\n class: isEmptyEditorDoc(editor.state.doc) ? 'vt-editor-content-empty' : undefined,\n role: 'textbox',\n 'aria-multiline': 'true',\n 'aria-label': current.ariaLabelledby ? undefined : current.ariaLabel,\n 'aria-labelledby': current.ariaLabelledby,\n 'aria-describedby': ids.help,\n 'aria-readonly': current.readonly ? 'true' : undefined,\n 'aria-disabled': current.disabled ? 'true' : undefined,\n 'aria-invalid': current.invalid ? 'true' : undefined,\n 'aria-placeholder': current.placeholder || undefined,\n 'data-placeholder': current.placeholder || undefined,\n contenteditable: editable() ? 'true' : 'false',\n tabindex: current.disabled ? '-1' : '0',\n spellcheck: 'true',\n translate: 'no',\n ref: (el: Element | null) => {\n const next = el as HTMLElement | null;\n if (next === contentEl) return;\n contentEl = next;\n attachView();\n },\n onFocus: (event: FocusEvent) => current.on?.focus?.(event),\n onBlur: (event: FocusEvent) => current.on?.blur?.(event)\n })\n );\n }\n\n function render() {\n const drawn = toolbarContext();\n root.attrs(part('root', { readonly: current.readonly, disabled: current.disabled, invalid: current.invalid }));\n root.render([\n current.hooks?.toolbar ? (current.hooks.toolbar() as Child) : current.toolbar === false ? null : toolbarView(drawn, toolbarGroups()),\n findBar.view(),\n contentView(),\n h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'), { ref: (el: Element | null) => (caretEl = el as HTMLElement | null) })),\n h('span', { key: 'help', id: ids.help, style: visuallyHidden }, locale().editor.keyboardHelp),\n current.hooks?.footer\n ? (current.hooks.footer() as Child)\n : current.showCount\n ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), h('span', part('count', { limit: !!current.maxLength }), countText()))\n : null\n ]);\n syncBlockSelect();\n syncBubble();\n renderPanels();\n blockHandle.sync();\n }\n\n function attachView() {\n view?.destroy();\n view = null;\n if (!contentEl) return;\n view = createEditorView(contentEl, editor, {\n editable,\n taskLabel: locale().editor.taskDone,\n selectedClass: 'vt-editor-node-selected',\n emptyClass: 'vt-editor-content-empty',\n chipClass: (kind) => (current.unstyled ? undefined : ['vt-editor-chip', kind ? `vt-editor-chip-${kind}` : ''].filter(Boolean).join(' ')),\n // Ctrl/⌘+K opens the link editor, over the caret.\n handleKey: (_name, binding) => {\n if (binding?.[0] !== 'link' || !editable()) return false;\n openLinkPanel();\n return true;\n },\n linkHint: (href) => ({ ...tooltips.options(editorLinkHint(href, locale().editor.followLink)), placement: 'top' })\n });\n if (current.autofocus) view.focus();\n }\n\n const focus = () => view?.focus();\n\n render();\n\n const handle: TextEditorHandle = {\n element,\n update(next) {\n const content = 'content' in next;\n current = { ...current, ...next };\n if (content) editor.setContent(current.content ?? '', { emit: false });\n if ('maxLength' in next) editor.maxLength = current.maxLength ?? null;\n render();\n },\n getHTML: () => editor.getHTML(),\n getJSON: () => editor.getJSON(),\n getText: () => editor.getText(),\n getMarkdown: () => editor.getMarkdown(),\n typeText: (text) => {\n const typed = editor.typeText(text);\n render();\n return typed;\n },\n setContent: (value) => {\n editor.setContent(value);\n render();\n },\n run: (name, ...args) => {\n const applied = run(name, ...args);\n render();\n return applied;\n },\n can,\n isActive: (name, attrs) => editor.isActive(name, attrs as never),\n focus,\n openFind: (options) => findBar.open(options),\n closeFind: () => findBar.close({ focusEditor: false }),\n refresh: render,\n destroy() {\n stop();\n element.removeEventListener('keydown', onFindKey);\n findBar.destroy();\n slashMenu.destroy();\n chipMenu.destroy();\n blockHandle.destroy();\n [...panels(), bubble].forEach((overlay) => overlay.destroy());\n blockSelect?.destroy();\n tooltips.destroy();\n view?.destroy();\n root.clear();\n }\n };\n\n return handle;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiDA,IAAI,UAAU;AAEd,SAAgB,iBAAiB,SAAsB,SAA2B,CAAC,GAAqB;CACpG,IAAI,UAA4B,EAAE,GAAG,OAAO;CAC5C,IAAI,OAA0B;CAC9B,IAAI,YAAgC;CACpC,IAAI,UAA8B;CAClC,IAAI,cAAmC;CACvC,IAAI,kBAAsC;CAC1C,IAAI,OAAuB;EAAE,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AI,EAAE,MAAM,MAAM,CAAC;GACrE,IAAI,eAAe,MAAM,OAAO,YAAY,QAAQ,aAAa;GACjE,OAAO;EACX;EACA,eAAe,OAAO,QAAQ;EAC9B,eAAe,OAAO,QAAQ;EAC9B,eAAe,OAAO,QAAQ;EAC9B,mBAAmB,OAAO,YAAY;EACtC,WAAW,SAAS;GAChB,MAAM,QAAQ,OAAO,SAAS,IAAI;GAClC,OAAO;GACP,OAAO;EACX;EACA,aAAa,UAAU;GACnB,OAAO,WAAW,KAAK;GACvB,OAAO;EACX;EACA,MAAM,MAAM,GAAG,SAAS;GACpB,MAAM,UAAU,IAAI,MAAM,GAAG,IAAI;GACjC,OAAO;GACP,OAAO;EACX;EACA;EACA,WAAW,MAAM,UAAU,OAAO,SAAS,MAAM,KAAc;EAC/D;EACA,WAAW,YAAY,QAAQ,KAAK,OAAO;EAC3C,iBAAiB,QAAQ,MAAM,EAAE,aAAa,MAAM,CAAC;EACrD,SAAS;EACT,UAAU;GACN,KAAK;GACL,QAAQ,oBAAoB,WAAW,SAAS;GAChD,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,SAAS,QAAQ;GACjB,YAAY,QAAQ;GACpB,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC,SAAS,YAAY,QAAQ,QAAQ,CAAC;GAC5D,aAAa,QAAQ;GACrB,SAAS,QAAQ;GACjB,MAAM,QAAQ;GACd,KAAK,MAAM;EACf;CACJ;CAEA,OAAO;AACX"}
|
package/dist/find.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type EditorInstance, type EditorMatch, type EditorView, type Locale } from '@vitral/core';
|
|
2
|
+
import { type Child, type Props } from '@vitral/dom';
|
|
3
|
+
/**
|
|
4
|
+
* The bar that finds words in an editor and replaces them, over the text the
|
|
5
|
+
* way a code editor's does. Every match is painted with the CSS Custom
|
|
6
|
+
* Highlight API — nothing is added to the document, so the words stay what
|
|
7
|
+
* they are for undo, for a screen reader and for the caret — and where a
|
|
8
|
+
* browser has no highlights the count and the selection still work.
|
|
9
|
+
*/
|
|
10
|
+
export interface FindBarOptions {
|
|
11
|
+
editor: EditorInstance;
|
|
12
|
+
view: () => EditorView | null;
|
|
13
|
+
part: (name: string, state?: unknown) => Props;
|
|
14
|
+
locale?: () => Locale;
|
|
15
|
+
/** Whether the words can be changed; without it the bar only finds. */
|
|
16
|
+
editable?: () => boolean;
|
|
17
|
+
/** The bar changed and wants drawing again. */
|
|
18
|
+
render: () => void;
|
|
19
|
+
id?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface FindBar {
|
|
22
|
+
readonly isOpen: boolean;
|
|
23
|
+
open(options?: {
|
|
24
|
+
replace?: boolean;
|
|
25
|
+
query?: string;
|
|
26
|
+
}): void;
|
|
27
|
+
close(options?: {
|
|
28
|
+
focusEditor?: boolean;
|
|
29
|
+
}): void;
|
|
30
|
+
/** The document changed: find again and repaint. */
|
|
31
|
+
sync(): void;
|
|
32
|
+
view(): Child;
|
|
33
|
+
matches(): readonly EditorMatch[];
|
|
34
|
+
destroy(): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function createFindBar(options: FindBarOptions): FindBar;
|
package/dist/find.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { iconView } from "./render/toolbar.js";
|
|
2
|
+
import { editorInlineText, editorNodeAt, en, findInEditor, formatMessage, replaceEditorMatches } from "@vitral/core";
|
|
3
|
+
import { h, mergeAttrs } from "@vitral/dom";
|
|
4
|
+
//#region src/find.ts
|
|
5
|
+
var painted = /* @__PURE__ */ new Map();
|
|
6
|
+
function repaint() {
|
|
7
|
+
const registry = typeof CSS !== "undefined" ? CSS.highlights : void 0;
|
|
8
|
+
const Highlight = globalThis.Highlight;
|
|
9
|
+
if (!registry || !Highlight) return;
|
|
10
|
+
const all = [];
|
|
11
|
+
const current = [];
|
|
12
|
+
for (const entry of painted.values()) {
|
|
13
|
+
all.push(...entry.all);
|
|
14
|
+
if (entry.current) current.push(entry.current);
|
|
15
|
+
}
|
|
16
|
+
if (all.length) registry.set("vt-find", new Highlight(...all));
|
|
17
|
+
else registry.delete("vt-find");
|
|
18
|
+
if (current.length) registry.set("vt-find-current", new Highlight(...current));
|
|
19
|
+
else registry.delete("vt-find-current");
|
|
20
|
+
}
|
|
21
|
+
function createFindBar(options) {
|
|
22
|
+
const key = {};
|
|
23
|
+
const locale = () => options.locale?.() ?? en;
|
|
24
|
+
const editable = () => options.editable?.() ?? true;
|
|
25
|
+
const id = options.id ?? "vt-find";
|
|
26
|
+
let isOpen = false;
|
|
27
|
+
let replacing = false;
|
|
28
|
+
let query = "";
|
|
29
|
+
let replacement = "";
|
|
30
|
+
const flags = {
|
|
31
|
+
caseSensitive: false,
|
|
32
|
+
wholeWord: false,
|
|
33
|
+
regex: false
|
|
34
|
+
};
|
|
35
|
+
let found = [];
|
|
36
|
+
let current = 0;
|
|
37
|
+
let input = null;
|
|
38
|
+
let wantFocus = false;
|
|
39
|
+
let scrollToCurrent = false;
|
|
40
|
+
function search() {
|
|
41
|
+
found = isOpen ? findInEditor(options.editor.state.doc, query, flags) : [];
|
|
42
|
+
if (current >= found.length) current = Math.max(0, found.length - 1);
|
|
43
|
+
}
|
|
44
|
+
/** The first match at or after the caret, so opening the bar starts where the reader is. */
|
|
45
|
+
function nearestToCaret() {
|
|
46
|
+
const head = options.editor.state.selection.head;
|
|
47
|
+
const index = found.findIndex((m) => {
|
|
48
|
+
const order = m.path.join(".").localeCompare(head.path.join("."), void 0, { numeric: true });
|
|
49
|
+
return order > 0 || order === 0 && m.to > head.offset;
|
|
50
|
+
});
|
|
51
|
+
current = index === -1 ? 0 : index;
|
|
52
|
+
}
|
|
53
|
+
function rangeOf(match) {
|
|
54
|
+
const view = options.view();
|
|
55
|
+
const start = view?.domFromPos({
|
|
56
|
+
path: match.path,
|
|
57
|
+
offset: match.from
|
|
58
|
+
});
|
|
59
|
+
const end = view?.domFromPos({
|
|
60
|
+
path: match.path,
|
|
61
|
+
offset: match.to
|
|
62
|
+
});
|
|
63
|
+
if (!start || !end || typeof document === "undefined") return null;
|
|
64
|
+
try {
|
|
65
|
+
const range = document.createRange();
|
|
66
|
+
range.setStart(start.node, start.offset);
|
|
67
|
+
range.setEnd(end.node, end.offset);
|
|
68
|
+
return range;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let queued = false;
|
|
74
|
+
function paint() {
|
|
75
|
+
if (queued) return;
|
|
76
|
+
queued = true;
|
|
77
|
+
queueMicrotask(() => {
|
|
78
|
+
queued = false;
|
|
79
|
+
if (wantFocus && input) {
|
|
80
|
+
wantFocus = false;
|
|
81
|
+
input.focus();
|
|
82
|
+
input.select();
|
|
83
|
+
}
|
|
84
|
+
if (!isOpen || !found.length) {
|
|
85
|
+
painted.delete(key);
|
|
86
|
+
repaint();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const all = found.map(rangeOf).filter((r) => !!r);
|
|
90
|
+
const now = found[current] ? rangeOf(found[current]) : null;
|
|
91
|
+
painted.set(key, {
|
|
92
|
+
all,
|
|
93
|
+
current: now
|
|
94
|
+
});
|
|
95
|
+
repaint();
|
|
96
|
+
if (scrollToCurrent && now) {
|
|
97
|
+
scrollToCurrent = false;
|
|
98
|
+
(now.startContainer.nodeType === 1 ? now.startContainer : now.startContainer.parentElement)?.scrollIntoView?.({
|
|
99
|
+
block: "nearest",
|
|
100
|
+
inline: "nearest"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function changed() {
|
|
106
|
+
search();
|
|
107
|
+
options.render();
|
|
108
|
+
paint();
|
|
109
|
+
}
|
|
110
|
+
function go(step) {
|
|
111
|
+
if (!found.length) return;
|
|
112
|
+
current = (current + step + found.length) % found.length;
|
|
113
|
+
scrollToCurrent = true;
|
|
114
|
+
options.render();
|
|
115
|
+
paint();
|
|
116
|
+
}
|
|
117
|
+
/** Leaves the current match selected in the document, where Escape takes the reader. */
|
|
118
|
+
function selectCurrent() {
|
|
119
|
+
const match = found[current];
|
|
120
|
+
if (!match) return;
|
|
121
|
+
options.editor.setSelection({
|
|
122
|
+
anchor: {
|
|
123
|
+
path: match.path,
|
|
124
|
+
offset: match.from
|
|
125
|
+
},
|
|
126
|
+
head: {
|
|
127
|
+
path: match.path,
|
|
128
|
+
offset: match.to
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function replaceOne() {
|
|
133
|
+
const match = found[current];
|
|
134
|
+
if (!match || !editable()) return;
|
|
135
|
+
options.editor.apply(replaceEditorMatches(options.editor.state, [match], replacement, flags), {
|
|
136
|
+
origin: "user",
|
|
137
|
+
history: "other"
|
|
138
|
+
});
|
|
139
|
+
search();
|
|
140
|
+
scrollToCurrent = true;
|
|
141
|
+
options.render();
|
|
142
|
+
paint();
|
|
143
|
+
}
|
|
144
|
+
function replaceAll() {
|
|
145
|
+
if (!found.length || !editable()) return;
|
|
146
|
+
options.editor.apply(replaceEditorMatches(options.editor.state, found, replacement, flags), {
|
|
147
|
+
origin: "user",
|
|
148
|
+
history: "other"
|
|
149
|
+
});
|
|
150
|
+
search();
|
|
151
|
+
options.render();
|
|
152
|
+
paint();
|
|
153
|
+
}
|
|
154
|
+
const close = ({ focusEditor = true } = {}) => {
|
|
155
|
+
if (!isOpen) return;
|
|
156
|
+
if (focusEditor) selectCurrent();
|
|
157
|
+
isOpen = false;
|
|
158
|
+
found = [];
|
|
159
|
+
painted.delete(key);
|
|
160
|
+
repaint();
|
|
161
|
+
options.render();
|
|
162
|
+
if (focusEditor) options.view()?.focus();
|
|
163
|
+
};
|
|
164
|
+
const toggle = (name, label, glyph) => h("button", mergeAttrs({
|
|
165
|
+
key: name,
|
|
166
|
+
type: "button"
|
|
167
|
+
}, options.part("findToggle", { active: flags[name] }), {
|
|
168
|
+
"aria-label": label,
|
|
169
|
+
"aria-pressed": flags[name] ? "true" : "false",
|
|
170
|
+
title: label,
|
|
171
|
+
onClick: () => {
|
|
172
|
+
flags[name] = !flags[name];
|
|
173
|
+
changed();
|
|
174
|
+
}
|
|
175
|
+
}), glyph);
|
|
176
|
+
const iconButton = (name, label, icon, onClick, disabled = false) => h("button", mergeAttrs({
|
|
177
|
+
key: name,
|
|
178
|
+
type: "button"
|
|
179
|
+
}, options.part("button", { disabled }), {
|
|
180
|
+
"aria-label": label,
|
|
181
|
+
title: label,
|
|
182
|
+
disabled,
|
|
183
|
+
onClick
|
|
184
|
+
}), iconView(icon, options.part("buttonIcon")));
|
|
185
|
+
function view() {
|
|
186
|
+
if (!isOpen) return null;
|
|
187
|
+
const words = locale().editor;
|
|
188
|
+
const canReplace = editable();
|
|
189
|
+
const count = !query ? "" : found.length ? formatMessage(words.matchCount, {
|
|
190
|
+
current: current + 1,
|
|
191
|
+
total: found.length
|
|
192
|
+
}) : words.noMatches;
|
|
193
|
+
const keydown = (event) => {
|
|
194
|
+
if (event.key === "Escape") {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
close();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return h("div", mergeAttrs({
|
|
200
|
+
key: "find",
|
|
201
|
+
id,
|
|
202
|
+
role: "search"
|
|
203
|
+
}, options.part("find"), {
|
|
204
|
+
"aria-label": words.find,
|
|
205
|
+
onKeydown: keydown
|
|
206
|
+
}), h("div", mergeAttrs({ key: "row" }, options.part("findRow")), canReplace ? h("button", mergeAttrs({
|
|
207
|
+
key: "expand",
|
|
208
|
+
type: "button"
|
|
209
|
+
}, options.part("button"), {
|
|
210
|
+
"aria-label": words.toggleReplace,
|
|
211
|
+
title: words.toggleReplace,
|
|
212
|
+
"aria-expanded": replacing ? "true" : "false",
|
|
213
|
+
"aria-controls": `${id}-replace`,
|
|
214
|
+
onClick: () => {
|
|
215
|
+
replacing = !replacing;
|
|
216
|
+
options.render();
|
|
217
|
+
}
|
|
218
|
+
}), iconView(replacing ? "chevronDown" : "chevronRight", options.part("buttonIcon"))) : null, h("span", {
|
|
219
|
+
key: "query",
|
|
220
|
+
class: "vt-field vt-field-sm vt-editor-find-field"
|
|
221
|
+
}, h("input", {
|
|
222
|
+
type: "text",
|
|
223
|
+
class: "vt-field-input",
|
|
224
|
+
value: query,
|
|
225
|
+
placeholder: words.find,
|
|
226
|
+
"aria-label": words.find,
|
|
227
|
+
"aria-describedby": `${id}-count`,
|
|
228
|
+
spellcheck: "false",
|
|
229
|
+
ref: (el) => input = el,
|
|
230
|
+
onInput: (event) => {
|
|
231
|
+
query = event.target.value;
|
|
232
|
+
search();
|
|
233
|
+
nearestToCaret();
|
|
234
|
+
scrollToCurrent = true;
|
|
235
|
+
options.render();
|
|
236
|
+
paint();
|
|
237
|
+
},
|
|
238
|
+
onKeydown: (event) => {
|
|
239
|
+
if (event.key !== "Enter") return;
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
go(event.shiftKey ? -1 : 1);
|
|
242
|
+
}
|
|
243
|
+
})), toggle("caseSensitive", words.matchCase, "Aa"), toggle("wholeWord", words.wholeWord, "ab"), toggle("regex", words.useRegex, ".*"), h("span", mergeAttrs({
|
|
244
|
+
key: "count",
|
|
245
|
+
id: `${id}-count`,
|
|
246
|
+
"aria-live": "polite"
|
|
247
|
+
}, options.part("findCount", { empty: !!query && !found.length })), count), iconButton("prev", words.previousMatch, "chevronUp", () => go(-1), !found.length), iconButton("next", words.nextMatch, "chevronDown", () => go(1), !found.length), iconButton("close", words.closeFind, "close", () => close())), canReplace && replacing ? h("div", mergeAttrs({
|
|
248
|
+
key: "replace",
|
|
249
|
+
id: `${id}-replace`
|
|
250
|
+
}, options.part("findRow", { replace: true })), h("span", {
|
|
251
|
+
key: "with",
|
|
252
|
+
class: "vt-field vt-field-sm vt-editor-find-field"
|
|
253
|
+
}, h("input", {
|
|
254
|
+
type: "text",
|
|
255
|
+
class: "vt-field-input",
|
|
256
|
+
value: replacement,
|
|
257
|
+
placeholder: words.replaceWith,
|
|
258
|
+
"aria-label": words.replaceWith,
|
|
259
|
+
spellcheck: "false",
|
|
260
|
+
onInput: (event) => replacement = event.target.value,
|
|
261
|
+
onKeydown: (event) => {
|
|
262
|
+
if (event.key !== "Enter") return;
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
if (event.ctrlKey || event.metaKey) replaceAll();
|
|
265
|
+
else replaceOne();
|
|
266
|
+
}
|
|
267
|
+
})), h("button", {
|
|
268
|
+
key: "one",
|
|
269
|
+
type: "button",
|
|
270
|
+
class: "vt-button vt-button-text vt-button-secondary vt-button-sm",
|
|
271
|
+
disabled: !found.length,
|
|
272
|
+
onClick: replaceOne
|
|
273
|
+
}, words.replace), h("button", {
|
|
274
|
+
key: "all",
|
|
275
|
+
type: "button",
|
|
276
|
+
class: "vt-button vt-button-text vt-button-secondary vt-button-sm",
|
|
277
|
+
disabled: !found.length,
|
|
278
|
+
onClick: replaceAll
|
|
279
|
+
}, words.replaceAll)) : null);
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
get isOpen() {
|
|
283
|
+
return isOpen;
|
|
284
|
+
},
|
|
285
|
+
open({ replace = false, query: next } = {}) {
|
|
286
|
+
const { anchor, head } = options.editor.state.selection;
|
|
287
|
+
if (next === void 0 && anchor.path.join() === head.path.join() && anchor.offset !== head.offset) {
|
|
288
|
+
const block = editorNodeAt(options.editor.state.doc, anchor.path);
|
|
289
|
+
const selected = editorInlineText(block?.content).slice(Math.min(anchor.offset, head.offset), Math.max(anchor.offset, head.offset));
|
|
290
|
+
if (selected && !/[\n\ufffc]/.test(selected) && selected.length <= 200) next = selected;
|
|
291
|
+
}
|
|
292
|
+
if (next !== void 0) query = next;
|
|
293
|
+
isOpen = true;
|
|
294
|
+
replacing = replace && editable() ? true : replacing && editable();
|
|
295
|
+
wantFocus = true;
|
|
296
|
+
search();
|
|
297
|
+
nearestToCaret();
|
|
298
|
+
scrollToCurrent = true;
|
|
299
|
+
options.render();
|
|
300
|
+
paint();
|
|
301
|
+
},
|
|
302
|
+
close,
|
|
303
|
+
sync() {
|
|
304
|
+
if (!isOpen) return;
|
|
305
|
+
search();
|
|
306
|
+
paint();
|
|
307
|
+
},
|
|
308
|
+
view,
|
|
309
|
+
matches: () => found,
|
|
310
|
+
destroy() {
|
|
311
|
+
painted.delete(key);
|
|
312
|
+
repaint();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
export { createFindBar };
|
|
318
|
+
|
|
319
|
+
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","names":[],"sources":["../src/find.ts"],"sourcesContent":["import { editorInlineText, editorNodeAt, en, findInEditor, formatMessage, replaceEditorMatches, type EditorFindOptions, type EditorInstance, type EditorMatch, type EditorView, type Locale } from '@vitral/core';\nimport { h, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { iconView } from './render/toolbar';\n\n/**\n * The bar that finds words in an editor and replaces them, over the text the\n * way a code editor's does. Every match is painted with the CSS Custom\n * Highlight API — nothing is added to the document, so the words stay what\n * they are for undo, for a screen reader and for the caret — and where a\n * browser has no highlights the count and the selection still work.\n */\n\nexport interface FindBarOptions {\n editor: EditorInstance;\n view: () => EditorView | null;\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Whether the words can be changed; without it the bar only finds. */\n editable?: () => boolean;\n /** The bar changed and wants drawing again. */\n render: () => void;\n id?: string;\n}\n\nexport interface FindBar {\n readonly isOpen: boolean;\n open(options?: { replace?: boolean; query?: string }): void;\n close(options?: { focusEditor?: boolean }): void;\n /** The document changed: find again and repaint. */\n sync(): void;\n view(): Child;\n matches(): readonly EditorMatch[];\n destroy(): void;\n}\n\n// Highlights are named for the whole page, so every bar adds its ranges to\n// one shared set and the set is rebuilt from all of them.\nconst painted = new Map<object, { all: Range[]; current: Range | null }>();\n\nfunction repaint() {\n const registry = typeof CSS !== 'undefined' ? (CSS as unknown as { highlights?: Map<string, unknown> }).highlights : undefined;\n const Highlight = (globalThis as { Highlight?: new (...ranges: Range[]) => unknown }).Highlight;\n if (!registry || !Highlight) return;\n const all: Range[] = [];\n const current: Range[] = [];\n for (const entry of painted.values()) {\n all.push(...entry.all);\n if (entry.current) current.push(entry.current);\n }\n if (all.length) registry.set('vt-find', new Highlight(...all));\n else registry.delete('vt-find');\n if (current.length) registry.set('vt-find-current', new Highlight(...current));\n else registry.delete('vt-find-current');\n}\n\nexport function createFindBar(options: FindBarOptions): FindBar {\n const key = {};\n const locale = () => options.locale?.() ?? en;\n const editable = () => options.editable?.() ?? true;\n const id = options.id ?? 'vt-find';\n let isOpen = false;\n let replacing = false;\n let query = '';\n let replacement = '';\n const flags: Required<EditorFindOptions> = { caseSensitive: false, wholeWord: false, regex: false };\n let found: EditorMatch[] = [];\n let current = 0;\n let input: HTMLInputElement | null = null;\n let wantFocus = false;\n let scrollToCurrent = false;\n\n function search() {\n found = isOpen ? findInEditor(options.editor.state.doc, query, flags) : [];\n if (current >= found.length) current = Math.max(0, found.length - 1);\n }\n\n /** The first match at or after the caret, so opening the bar starts where the reader is. */\n function nearestToCaret() {\n const head = options.editor.state.selection.head;\n const index = found.findIndex((m) => {\n const order = m.path.join('.').localeCompare(head.path.join('.'), undefined, { numeric: true });\n return order > 0 || (order === 0 && m.to > head.offset);\n });\n current = index === -1 ? 0 : index;\n }\n\n function rangeOf(match: EditorMatch): Range | null {\n const view = options.view();\n const start = view?.domFromPos({ path: match.path, offset: match.from });\n const end = view?.domFromPos({ path: match.path, offset: match.to });\n if (!start || !end || typeof document === 'undefined') return null;\n try {\n const range = document.createRange();\n range.setStart(start.node, start.offset);\n range.setEnd(end.node, end.offset);\n return range;\n } catch {\n return null;\n }\n }\n\n // The view draws the document after the handle hears of a change, so the\n // ranges are taken once it has.\n let queued = false;\n function paint() {\n if (queued) return;\n queued = true;\n queueMicrotask(() => {\n queued = false;\n if (wantFocus && input) {\n wantFocus = false;\n input.focus();\n input.select();\n }\n if (!isOpen || !found.length) {\n painted.delete(key);\n repaint();\n return;\n }\n const all = found.map(rangeOf).filter((r): r is Range => !!r);\n const now = found[current] ? rangeOf(found[current]!) : null;\n painted.set(key, { all, current: now });\n repaint();\n if (scrollToCurrent && now) {\n scrollToCurrent = false;\n const block = now.startContainer.nodeType === 1 ? (now.startContainer as Element) : now.startContainer.parentElement;\n block?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });\n }\n });\n }\n\n function changed() {\n search();\n options.render();\n paint();\n }\n\n function go(step: number) {\n if (!found.length) return;\n current = (current + step + found.length) % found.length;\n scrollToCurrent = true;\n options.render();\n paint();\n }\n\n /** Leaves the current match selected in the document, where Escape takes the reader. */\n function selectCurrent() {\n const match = found[current];\n if (!match) return;\n options.editor.setSelection({ anchor: { path: match.path, offset: match.from }, head: { path: match.path, offset: match.to } });\n }\n\n function replaceOne() {\n const match = found[current];\n if (!match || !editable()) return;\n options.editor.apply(replaceEditorMatches(options.editor.state, [match], replacement, flags), { origin: 'user', history: 'other' });\n search();\n scrollToCurrent = true;\n options.render();\n paint();\n }\n\n function replaceAll() {\n if (!found.length || !editable()) return;\n options.editor.apply(replaceEditorMatches(options.editor.state, found, replacement, flags), { origin: 'user', history: 'other' });\n search();\n options.render();\n paint();\n }\n\n const close: FindBar['close'] = ({ focusEditor = true } = {}) => {\n if (!isOpen) return;\n if (focusEditor) selectCurrent();\n isOpen = false;\n found = [];\n painted.delete(key);\n repaint();\n options.render();\n if (focusEditor) options.view()?.focus();\n };\n\n const toggle = (name: keyof EditorFindOptions, label: string, glyph: string): Child =>\n h(\n 'button',\n mergeAttrs({ key: name, type: 'button' }, options.part('findToggle', { active: flags[name] }), {\n 'aria-label': label,\n 'aria-pressed': flags[name] ? 'true' : 'false',\n title: label,\n onClick: () => {\n flags[name] = !flags[name];\n changed();\n }\n }),\n glyph\n );\n\n const iconButton = (name: string, label: string, icon: string, onClick: () => void, disabled = false): Child =>\n h(\n 'button',\n mergeAttrs({ key: name, type: 'button' }, options.part('button', { disabled }), { 'aria-label': label, title: label, disabled, onClick }),\n iconView(icon, options.part('buttonIcon'))\n );\n\n function view(): Child {\n if (!isOpen) return null;\n const words = locale().editor;\n const canReplace = editable();\n const count = !query ? '' : found.length ? formatMessage(words.matchCount, { current: current + 1, total: found.length }) : words.noMatches;\n const keydown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n close();\n }\n };\n return h(\n 'div',\n mergeAttrs({ key: 'find', id, role: 'search' }, options.part('find'), { 'aria-label': words.find, onKeydown: keydown }),\n h(\n 'div',\n mergeAttrs({ key: 'row' }, options.part('findRow')),\n canReplace\n ? h(\n 'button',\n mergeAttrs({ key: 'expand', type: 'button' }, options.part('button'), {\n 'aria-label': words.toggleReplace,\n title: words.toggleReplace,\n 'aria-expanded': replacing ? 'true' : 'false',\n 'aria-controls': `${id}-replace`,\n onClick: () => {\n replacing = !replacing;\n options.render();\n }\n }),\n iconView(replacing ? 'chevronDown' : 'chevronRight', options.part('buttonIcon'))\n )\n : null,\n h(\n 'span',\n { key: 'query', class: 'vt-field vt-field-sm vt-editor-find-field' },\n h('input', {\n type: 'text',\n class: 'vt-field-input',\n value: query,\n placeholder: words.find,\n 'aria-label': words.find,\n 'aria-describedby': `${id}-count`,\n spellcheck: 'false',\n ref: (el: Element | null) => (input = el as HTMLInputElement | null),\n onInput: (event: Event) => {\n query = (event.target as HTMLInputElement).value;\n search();\n nearestToCaret();\n scrollToCurrent = true;\n options.render();\n paint();\n },\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n go(event.shiftKey ? -1 : 1);\n }\n })\n ),\n toggle('caseSensitive', words.matchCase, 'Aa'),\n toggle('wholeWord', words.wholeWord, 'ab'),\n toggle('regex', words.useRegex, '.*'),\n h('span', mergeAttrs({ key: 'count', id: `${id}-count`, 'aria-live': 'polite' }, options.part('findCount', { empty: !!query && !found.length })), count),\n iconButton('prev', words.previousMatch, 'chevronUp', () => go(-1), !found.length),\n iconButton('next', words.nextMatch, 'chevronDown', () => go(1), !found.length),\n iconButton('close', words.closeFind, 'close', () => close())\n ),\n canReplace && replacing\n ? h(\n 'div',\n mergeAttrs({ key: 'replace', id: `${id}-replace` }, options.part('findRow', { replace: true })),\n h(\n 'span',\n { key: 'with', class: 'vt-field vt-field-sm vt-editor-find-field' },\n h('input', {\n type: 'text',\n class: 'vt-field-input',\n value: replacement,\n placeholder: words.replaceWith,\n 'aria-label': words.replaceWith,\n spellcheck: 'false',\n onInput: (event: Event) => (replacement = (event.target as HTMLInputElement).value),\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n if (event.ctrlKey || event.metaKey) replaceAll();\n else replaceOne();\n }\n })\n ),\n h('button', { key: 'one', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm', disabled: !found.length, onClick: replaceOne }, words.replace),\n h('button', { key: 'all', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm', disabled: !found.length, onClick: replaceAll }, words.replaceAll)\n )\n : null\n );\n }\n\n return {\n get isOpen() {\n return isOpen;\n },\n open({ replace = false, query: next } = {}) {\n // What is selected is what the reader wants to find, when it is a few words on one line.\n const { anchor, head } = options.editor.state.selection;\n if (next === undefined && anchor.path.join() === head.path.join() && anchor.offset !== head.offset) {\n const block = editorNodeAt(options.editor.state.doc, anchor.path);\n const selected = editorInlineText(block?.content).slice(Math.min(anchor.offset, head.offset), Math.max(anchor.offset, head.offset));\n if (selected && !/[\\n\\ufffc]/.test(selected) && selected.length <= 200) next = selected;\n }\n if (next !== undefined) query = next;\n isOpen = true;\n replacing = replace && editable() ? true : replacing && editable();\n wantFocus = true;\n search();\n nearestToCaret();\n scrollToCurrent = true;\n options.render();\n paint();\n },\n close,\n sync() {\n if (!isOpen) return;\n search();\n paint();\n },\n view,\n matches: () => found,\n destroy() {\n painted.delete(key);\n repaint();\n }\n };\n}\n"],"mappings":";;;;AAqCA,IAAM,0BAAU,IAAI,IAAqD;AAEzE,SA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AAS;GACjE,YAAY;GACZ,OAAO;GACP,eAAe;GACf,kBAAkB;GAClB,QAAQ,OAAO;GACf,MAAM;EACV;EACA;EACA,OAAO;GACH,IAAI,CAAC,QAAQ;GACb,OAAO;GACP,MAAM;EACV;EACA;EACA,eAAe;EACf,UAAU;GACN,QAAQ,OAAO,GAAG;GAClB,QAAQ;EACZ;CACJ;AACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
export { createTextEditor } from './editor';
|
|
8
8
|
export { createSlashMenu, defaultSlashCommands, type SlashMenu, type SlashMenuOptions } from './slash';
|
|
9
9
|
export { createChipMenu, type ChipMenu, type ChipMenuOptions } from './chips';
|
|
10
|
+
export { createFindBar, type FindBar, type FindBarOptions } from './find';
|
|
10
11
|
export { createBlockHandle, defaultBlockActions, type BlockHandle, type BlockHandleOptions } from './block';
|
|
11
12
|
export { editorButtons, editorIcons, shortcutCommands, defaultToolbar, defaultBubbleMenu, type EditorButtonSpec } from './buttons';
|
|
12
13
|
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { bubbleView, buttonView, iconView, toolbarView } from "./render/toolbar.
|
|
|
3
3
|
import { blockHandleView, blockMenuView, colorPanelView, imagePanelView, linkPanelView, slashMenuView, tablePanelView } from "./render/menus.js";
|
|
4
4
|
import { createBlockHandle, defaultBlockActions } from "./block.js";
|
|
5
5
|
import { createChipMenu } from "./chips.js";
|
|
6
|
+
import { createFindBar } from "./find.js";
|
|
6
7
|
import { createSlashMenu, defaultSlashCommands } from "./slash.js";
|
|
7
8
|
import { createTextEditor } from "./editor.js";
|
|
8
|
-
export { blockHandleView, blockMenuView, bubbleView, buttonView, colorPanelView, createBlockHandle, createChipMenu, createSlashMenu, createTextEditor, defaultBlockActions, defaultBubbleMenu, defaultSlashCommands, defaultToolbar, editorButtons, editorIcons, iconView, imagePanelView, linkPanelView, shortcutCommands, slashMenuView, tablePanelView, toolbarView };
|
|
9
|
+
export { blockHandleView, blockMenuView, bubbleView, buttonView, colorPanelView, createBlockHandle, createChipMenu, createFindBar, createSlashMenu, createTextEditor, defaultBlockActions, defaultBubbleMenu, defaultSlashCommands, defaultToolbar, editorButtons, editorIcons, iconView, imagePanelView, linkPanelView, shortcutCommands, slashMenuView, tablePanelView, toolbarView };
|
package/dist/render/toolbar.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface ToolbarActions {
|
|
|
32
32
|
tip: (element: Element | null, text: string) => void;
|
|
33
33
|
command: (name: string, args: readonly unknown[], event: MouseEvent) => void;
|
|
34
34
|
openLink: (event: MouseEvent) => void;
|
|
35
|
+
/** Opens or shuts the find bar. */
|
|
36
|
+
openFind: () => void;
|
|
35
37
|
openImage: (event: MouseEvent) => void;
|
|
36
38
|
openTable: (event: MouseEvent) => void;
|
|
37
39
|
openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;
|
package/dist/render/toolbar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { editorButtons, shortcutCommands } from "../buttons.js";
|
|
2
|
-
import "@vitral/core";
|
|
2
|
+
import { ariaEditorShortcut, formatEditorShortcut } from "@vitral/core";
|
|
3
3
|
import { h, iconNode, mergeAttrs } from "@vitral/dom";
|
|
4
4
|
import { getIcon } from "@vitral/icons";
|
|
5
5
|
//#region src/render/toolbar.ts
|
|
@@ -65,6 +65,19 @@ function openerView(context, item) {
|
|
|
65
65
|
onClick: (event) => spec.action === "openImage" ? context.on.openImage(event) : context.on.openTable(event)
|
|
66
66
|
}), iconView(spec.icon, context.part("buttonIcon")));
|
|
67
67
|
}
|
|
68
|
+
/** The button that opens the find bar. */
|
|
69
|
+
function findView(context) {
|
|
70
|
+
const name = context.locale.editor.find;
|
|
71
|
+
return h("button", mergeAttrs({
|
|
72
|
+
key: "find",
|
|
73
|
+
type: "button"
|
|
74
|
+
}, context.part("button"), {
|
|
75
|
+
"aria-label": name,
|
|
76
|
+
"aria-keyshortcuts": ariaEditorShortcut("Mod-f"),
|
|
77
|
+
ref: (element) => context.on.tip(element, `${name} (${formatEditorShortcut("Mod-f")})`),
|
|
78
|
+
onClick: () => context.on.openFind()
|
|
79
|
+
}), iconView("search", context.part("buttonIcon")));
|
|
80
|
+
}
|
|
68
81
|
/** The text and highlight pickers: a button showing the colour in hand. */
|
|
69
82
|
function colorView(context, kind) {
|
|
70
83
|
const { part, locale } = context;
|
|
@@ -102,7 +115,7 @@ function toolbarView(context, groups) {
|
|
|
102
115
|
}), groups.map((group, index) => h("div", mergeAttrs({
|
|
103
116
|
key: index,
|
|
104
117
|
role: "group"
|
|
105
|
-
}, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : buttonView(context, item)))));
|
|
118
|
+
}, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : item === "find" ? findView(context) : buttonView(context, item)))));
|
|
106
119
|
}
|
|
107
120
|
/** The floating toolbar over a selection: the same buttons, in one group. */
|
|
108
121
|
function bubbleView(context, items) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table'\n ? openerView(context, item)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AAuCA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;CAC3E,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;AAC/E;;AAGA,SAAgB,WAAW,SAAyB,MAAkC;CAClF,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,OAAO,cAAc;CAC3B,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,OAAO,KAAK,MAAM,OAAO,MAAM;CACrC,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,KAAK,SAAS,QAAQ,SAAS,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,KAAA;CACjF,M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AC1I,OAAO,KAAK,OAAO,UACf,EACI,OACA,WAAW;EAAE,KAAK;EAAO,MAAM;CAAQ,GAAG,KAAK,cAAc,CAAC,GAC9D,MAAM,KAAK,SACP,SAAS,cACH,gBAAgB,OAAO,IACvB,SAAS,WAAW,SAAS,cAC3B,UAAU,SAAS,IAAI,IACvB,SAAS,WAAW,SAAS,UAC3B,WAAW,SAAS,IAAI,IACxB,WAAW,SAAS,IAA2B,CAC7D,CACJ,CACJ,CACJ;AACJ;;AAGA,SAAgB,WAAW,SAAyB,OAAmC;CACnF,OAAO,EACH,OACA,WAAW,EAAE,MAAM,UAAU,GAAG,QAAQ,KAAK,QAAQ,GAAG,EAAE,cAAc,QAAQ,OAAO,OAAO,QAAQ,CAAC,GACvG,MAAM,KAAK,SACP,SAAS,WAAW,SAAS,cAAc,UAAU,SAAS,IAAI,IAAI,SAAS,WAAW,SAAS,UAAU,WAAW,SAAS,IAAI,IAAI,WAAW,SAAS,IAA2B,CAC5L,CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { ariaEditorShortcut, formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n /** Opens or shuts the find bar. */\n openFind: () => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The button that opens the find bar. */\nfunction findView(context: ToolbarContext): Child {\n const name = context.locale.editor.find;\n return h(\n 'button',\n mergeAttrs({ key: 'find', type: 'button' }, context.part('button'), {\n 'aria-label': name,\n 'aria-keyshortcuts': ariaEditorShortcut('Mod-f'),\n ref: (element: Element | null) => context.on.tip(element, `${name} (${formatEditorShortcut('Mod-f')})`),\n onClick: () => context.on.openFind()\n }),\n iconView('search', context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table'\n ? openerView(context, item)\n : item === 'find'\n ? findView(context)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AAyCA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;CAC3E,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;AAC/E;;AAGA,SAAgB,WAAW,SAAyB,MAAkC;CAClF,MAAM,EAAE,MAAM,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IAA2B,CAC5L,CACJ;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';
|
|
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';
|
|
11
11
|
/** The commands a plain button can run. */
|
|
12
|
-
export type EditorButtonCommand = Exclude<EditorToolbarItem, 'blockType' | 'color' | 'highlight' | 'image' | 'table'>;
|
|
12
|
+
export type EditorButtonCommand = Exclude<EditorToolbarItem, 'blockType' | 'color' | 'highlight' | 'image' | 'table' | '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 {
|
|
@@ -92,6 +92,12 @@ export interface TextEditorConfig {
|
|
|
92
92
|
* once. Chips can also be put in with `run('insertChip', { id, label, kind })`.
|
|
93
93
|
*/
|
|
94
94
|
chips?: ChipTrigger | ChipTrigger[];
|
|
95
|
+
/**
|
|
96
|
+
* Find and replace: Ctrl/⌘+F opens the bar over the text, Ctrl+H (⌘+⌥+F
|
|
97
|
+
* on a Mac) opens it with the replace row. On by default; `false` leaves
|
|
98
|
+
* those keys to the browser. The `find` toolbar item opens it too.
|
|
99
|
+
*/
|
|
100
|
+
find?: boolean;
|
|
95
101
|
/** The most characters the document may hold. */
|
|
96
102
|
maxLength?: number | null;
|
|
97
103
|
/** Milliseconds of quiet before an edit starts a new undo step. */
|
|
@@ -155,6 +161,12 @@ export interface TextEditorHandle {
|
|
|
155
161
|
can(name: string, ...args: unknown[]): boolean;
|
|
156
162
|
isActive(name: string, attrs?: Record<string, unknown>): boolean;
|
|
157
163
|
focus(): void;
|
|
164
|
+
/** Opens the find bar, with the replace row and a query when given. */
|
|
165
|
+
openFind(options?: {
|
|
166
|
+
replace?: boolean;
|
|
167
|
+
query?: string;
|
|
168
|
+
}): void;
|
|
169
|
+
closeFind(): void;
|
|
158
170
|
/** Draws again, for anything that changed underneath. */
|
|
159
171
|
refresh(): void;
|
|
160
172
|
destroy(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitral/editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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/controls": "0.2.
|
|
48
|
-
"@vitral/
|
|
49
|
-
"@vitral/
|
|
50
|
-
"@vitral/
|
|
51
|
-
"@vitral/
|
|
47
|
+
"@vitral/controls": "0.2.8",
|
|
48
|
+
"@vitral/core": "0.2.8",
|
|
49
|
+
"@vitral/dom": "0.2.8",
|
|
50
|
+
"@vitral/styles": "0.2.8",
|
|
51
|
+
"@vitral/icons": "0.2.8"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "vite build && tsc -p tsconfig.build.json"
|