@vitral/editor 0.2.0
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/LICENSE +165 -0
- package/LICENSE.GPL +674 -0
- package/README.md +34 -0
- package/dist/block.d.ts +39 -0
- package/dist/block.js +150 -0
- package/dist/block.js.map +1 -0
- package/dist/buttons.d.ts +32 -0
- package/dist/buttons.js +193 -0
- package/dist/buttons.js.map +1 -0
- package/dist/editor.d.ts +2 -0
- package/dist/editor.js +483 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/render/menus.d.ts +67 -0
- package/dist/render/menus.js +172 -0
- package/dist/render/menus.js.map +1 -0
- package/dist/render/toolbar.d.ts +48 -0
- package/dist/render/toolbar.js +114 -0
- package/dist/render/toolbar.js.map +1 -0
- package/dist/slash.d.ts +44 -0
- package/dist/slash.js +196 -0
- package/dist/slash.js.map +1 -0
- package/dist/types.d.ts +128 -0
- package/package.json +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash.js","names":[],"sources":["../src/slash.ts"],"sourcesContent":["import { editorSelectionRange, editorTextblocks, en, type EditorInstance, type EditorNode, type Locale } from '@vitral/core';\nimport { createOverlay, type OverlayTarget } from '@vitral/controls';\nimport type { Props } from '@vitral/dom';\nimport { slashMenuView } from './render/menus';\nimport type { CommandRunner, SlashCommand } from './types';\n\n/**\n * The menu a `/` opens, as a piece that attaches to any editor: the\n * framework-free one uses it, and so does a framework component that draws its\n * own toolbar. It watches the document, opens when a slash starts a word,\n * filters as it is typed, and takes the keys it needs while it is open.\n */\n\nexport interface SlashMenuOptions {\n editor: EditorInstance;\n /** The `contenteditable` element, where the keys are heard. */\n content: () => HTMLElement | null;\n /** What the menu hangs from: an element over the caret. */\n anchor: () => HTMLElement | null;\n /** The commands on offer; a function is read every time it opens. */\n commands: () => SlashCommand[];\n /** The classes and pass-through of the menu's parts. */\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Off while the editor is read-only. */\n enabled?: () => boolean;\n /** Puts the anchor where the caret is, before the menu opens. */\n place?: () => void;\n ids?: { slash: string; block: string };\n overlayTarget?: OverlayTarget;\n zIndex?: number;\n /** What to do with the command the reader chose; it runs itself by default. */\n onRun?: (command: SlashCommand) => void;\n}\n\nexport interface SlashMenu {\n readonly isOpen: boolean;\n /** Reads the document again: called on every change. */\n sync(): void;\n close(): void;\n destroy(): void;\n}\n\nexport function createSlashMenu(options: SlashMenuOptions): SlashMenu {\n let open: { query: string; active: number } | null = null;\n let element: HTMLElement | null = null;\n\n const locale = () => options.locale?.() ?? en;\n const ids = options.ids ?? { slash: 'vt-slash', block: 'vt-block' };\n const enabled = () => options.enabled?.() ?? true;\n\n /** What the query after the slash matches, by label, id and keyword. */\n function matches(query: string): SlashCommand[] {\n const needle = query.trim().toLocaleLowerCase(locale().code);\n const all = options.commands();\n if (!needle) return all;\n return all.filter((item) => [item.label, item.id, ...(item.keywords ?? [])].some((word) => word.toLocaleLowerCase(locale().code).includes(needle)));\n }\n\n const overlay = createOverlay({\n anchor: options.anchor,\n render: () =>\n open\n ? (slashMenuView({ locale: locale(), part: options.part, ids }, { query: open.query, items: matches(open.query), active: open.active }, { choose: run }) as never)\n : null,\n placement: 'bottom-start',\n target: () => options.overlayTarget,\n zIndex: options.zIndex,\n restoreFocus: false,\n onClose: () => (open = null)\n });\n\n /** The text of the block the caret is in, and where the caret is in it. */\n function caretText(): { text: string; offset: number } | null {\n const state = options.editor.state;\n if (!editorSelectionRange(state.selection).empty) return null;\n const blocks = editorTextblocks(state.doc);\n const path = state.selection.head.path;\n const block = blocks.find((entry) => entry.path.join('.') === path.join('.'))?.node ?? (path[0] === undefined ? undefined : (state.doc.content?.[path[0]] as EditorNode | undefined));\n if (!block) return null;\n const text = (block.content ?? []).map((child) => (typeof child === 'string' ? child : (child.text ?? ''))).join('');\n return { text, offset: state.selection.head.offset };\n }\n\n function sync() {\n if (!enabled()) return close();\n const caret = caretText();\n if (!caret) return close();\n const before = caret.text.slice(0, caret.offset);\n const at = before.lastIndexOf('/');\n const starts = at === 0 || (at > 0 && /\\s/.test(before[at - 1] ?? ''));\n if (at < 0 || !starts) return close();\n const query = before.slice(at + 1);\n if (/\\s/.test(query)) return close();\n open = { query, active: open && open.query === query ? open.active : 0 };\n options.place?.();\n overlay.open();\n overlay.update();\n }\n\n function close() {\n if (!overlay.isOpen) {\n open = null;\n return;\n }\n overlay.close();\n }\n\n /** Runs what the menu was pointing at, after taking the slash and its query out. */\n function run(index: number) {\n const items = matches(open?.query ?? '');\n const item = items[index];\n if (!item || !open) return;\n const remove = open.query.length + 1;\n close();\n for (let n = 0; n < remove; n++) options.editor.backspace('char');\n if (options.onRun) options.onRun(item);\n // An entry's own `run` is what an application writes a command of its\n // own with: without this it was only ever called by a host that passed\n // `onRun`, so a slash command with a `run` did nothing in Vue.\n else if (item.run) item.run(options.editor as unknown as CommandRunner);\n else if (item.command) (options.editor.run as (name: string, ...args: unknown[]) => boolean)(item.command[0], ...item.command.slice(1));\n }\n\n /**\n * While the menu is open those keys are the menu's. The listener is a\n * capturing one: the editor's own view listens on the same element, and an\n * Enter it heard would split the block the command is about to change.\n */\n function onKeydown(event: KeyboardEvent) {\n if (!open) return;\n const items = matches(open.query);\n const take = () => {\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n take();\n const step = event.key === 'ArrowDown' ? 1 : -1;\n open = { ...open, active: (open.active + step + items.length) % Math.max(1, items.length) };\n overlay.update();\n return;\n }\n if (event.key === 'Home' || event.key === 'End') {\n take();\n open = { ...open, active: event.key === 'Home' ? 0 : Math.max(0, items.length - 1) };\n overlay.update();\n return;\n }\n if (event.key === 'Enter' || event.key === 'Tab') {\n if (!items.length) return;\n take();\n run(open.active);\n return;\n }\n if (event.key === 'Escape') {\n take();\n close();\n }\n }\n\n function listen() {\n const next = options.content();\n if (next === element) return;\n element?.removeEventListener('keydown', onKeydown, true);\n element = next;\n element?.addEventListener('keydown', onKeydown, true);\n }\n\n const stop = options.editor.subscribe(() => {\n listen();\n sync();\n });\n listen();\n // The document may already be mid-word: a menu attached after a slash was\n // typed (a re-attach, a component that mounted late) opens straight away.\n sync();\n\n return {\n get isOpen() {\n return overlay.isOpen;\n },\n sync() {\n listen();\n sync();\n },\n close,\n destroy() {\n stop();\n element?.removeEventListener('keydown', onKeydown, true);\n element = null;\n overlay.destroy();\n }\n };\n}\n\n/** The blocks a slash offers when an application names none. */\nexport function defaultSlashCommands(locale: Locale): SlashCommand[] {\n const words = locale.editor;\n const entry = (id: string, icon: string, command: readonly [string, ...unknown[]]): SlashCommand => ({\n id,\n icon,\n label: words.slashCommands[id] ?? id,\n description: words.slashHints[id],\n command\n });\n return [\n entry('paragraph', 'pilcrow', ['setParagraph']),\n entry('heading1', 'heading1', ['toggleHeading', 1]),\n entry('heading2', 'heading2', ['toggleHeading', 2]),\n entry('heading3', 'heading3', ['toggleHeading', 3]),\n entry('bulletList', 'list', ['toggleBulletList']),\n entry('orderedList', 'listOrdered', ['toggleOrderedList']),\n entry('taskList', 'listChecks', ['toggleTaskList']),\n entry('blockquote', 'quote', ['toggleBlockquote']),\n entry('codeBlock', 'codeBlock', ['toggleCodeBlock']),\n entry('horizontalRule', 'horizontalRule', ['insertHorizontalRule']),\n entry('table', 'table', ['insertTable', 3, 3, true]),\n entry('image', 'image', ['insertImage', { src: '' }])\n ];\n}\n"],"mappings":";;;;AA2CA,SAAgB,gBAAgB,SAAsC;CAClE,IAAI,OAAiD;CACrD,IAAI,UAA8B;CAElC,MAAM,eAAe,QAAQ,SAAS,KAAK;CAC3C,MAAM,MAAM,QAAQ,OAAO;EAAE,OAAO;EAAY,OAAO;CAAW;CAClE,MAAM,gBAAgB,QAAQ,UAAU,KAAK;;CAG7C,SAAS,QAAQ,OAA+B;EAC5C,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,kBAAkB,OAAO,CAAC,CA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;CACJ;CACA,OAAO;EACH,MAAM,aAAa,WAAW,CAAC,cAAc,CAAC;EAC9C,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,YAAY,YAAY,CAAC,iBAAiB,CAAC,CAAC;EAClD,MAAM,cAAc,QAAQ,CAAC,kBAAkB,CAAC;EAChD,MAAM,eAAe,eAAe,CAAC,mBAAmB,CAAC;EACzD,MAAM,YAAY,cAAc,CAAC,gBAAgB,CAAC;EAClD,MAAM,cAAc,SAAS,CAAC,kBAAkB,CAAC;EACjD,MAAM,aAAa,aAAa,CAAC,iBAAiB,CAAC;EACnD,MAAM,kBAAkB,kBAAkB,CAAC,sBAAsB,CAAC;EAClE,MAAM,SAAS,SAAS;GAAC;GAAe;GAAG;GAAG;EAAI,CAAC;EACnD,MAAM,SAAS,SAAS,CAAC,eAAe,EAAE,KAAK,GAAG,CAAC,CAAC;CACxD;AACJ"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { ClassEntry, EditorColor, EditorContent, EditorNode, Locale } from '@vitral/core';
|
|
2
|
+
import type { OverlayTarget } from '@vitral/controls';
|
|
3
|
+
import type { PassThrough } from '@vitral/dom';
|
|
4
|
+
/**
|
|
5
|
+
* What an editor is told, as plain data. The document, the commands and the
|
|
6
|
+
* history are `@vitral/core`'s; this is the interface around them — which
|
|
7
|
+
* toolbar, which panels, what a host draws itself.
|
|
8
|
+
*/
|
|
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';
|
|
11
|
+
/** The commands a plain button can run. */
|
|
12
|
+
export type EditorButtonCommand = Exclude<EditorToolbarItem, 'blockType' | 'color' | 'highlight' | 'image' | 'table'>;
|
|
13
|
+
/** One entry of the menu a slash opens. */
|
|
14
|
+
export interface SlashCommand {
|
|
15
|
+
/** Identifies it, and is what a host matches on. */
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
/** A line under the label. */
|
|
19
|
+
description?: string;
|
|
20
|
+
icon?: string;
|
|
21
|
+
/** Words that find it besides its label. */
|
|
22
|
+
keywords?: string[];
|
|
23
|
+
/** A heading the entry sits under. */
|
|
24
|
+
group?: string;
|
|
25
|
+
/** What it does. Without it, `command` is run. */
|
|
26
|
+
run?: (editor: CommandRunner) => void;
|
|
27
|
+
/** A command name and its arguments, run against the editor. */
|
|
28
|
+
command?: readonly [string, ...unknown[]];
|
|
29
|
+
}
|
|
30
|
+
/** Enough of an editor for an action to act on: the handle, or the engine itself. */
|
|
31
|
+
export interface CommandRunner {
|
|
32
|
+
run(name: string, ...args: unknown[]): boolean;
|
|
33
|
+
}
|
|
34
|
+
/** What the handle around a block offers. */
|
|
35
|
+
export interface BlockAction {
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
icon?: string;
|
|
39
|
+
/** Hidden where it does not apply to the block in hand. */
|
|
40
|
+
when?: (block: EditorNode) => boolean;
|
|
41
|
+
run: (editor: CommandRunner, block: EditorNode, index: number) => void;
|
|
42
|
+
}
|
|
43
|
+
/** Content a host draws itself: a string, a node it made, or nothing. */
|
|
44
|
+
export type Content = string | number | Node | null | undefined;
|
|
45
|
+
/** The parts a host draws itself, instead of what the editor would draw. */
|
|
46
|
+
export interface EditorContentHooks {
|
|
47
|
+
/** The whole toolbar. */
|
|
48
|
+
toolbar?: () => Content;
|
|
49
|
+
/** The bar under the content, where the count sits. */
|
|
50
|
+
footer?: () => Content;
|
|
51
|
+
}
|
|
52
|
+
export interface TextEditorConfig {
|
|
53
|
+
/** The document: HTML, or the JSON a previous editor produced. */
|
|
54
|
+
content?: EditorContent;
|
|
55
|
+
/** The toolbar: `false` for none, or groups of item names. */
|
|
56
|
+
toolbar?: boolean | EditorToolbarItem[][];
|
|
57
|
+
/** A floating toolbar over selected text: `true` for the usual buttons, or the items to show. */
|
|
58
|
+
bubbleMenu?: boolean | EditorToolbarItem[];
|
|
59
|
+
/** The menu a `/` opens at the start of an empty block: `false` for none, or the commands to offer. */
|
|
60
|
+
slashMenu?: boolean | SlashCommand[];
|
|
61
|
+
/** The handle beside the block the caret is in, and what it offers. */
|
|
62
|
+
blockMenu?: boolean | BlockAction[];
|
|
63
|
+
placeholder?: string;
|
|
64
|
+
/** The most characters the document may hold. */
|
|
65
|
+
maxLength?: number | null;
|
|
66
|
+
/** Milliseconds of quiet before an edit starts a new undo step. */
|
|
67
|
+
historyDelay?: number;
|
|
68
|
+
/** Shows the character count (and the limit, where there is one). */
|
|
69
|
+
showCount?: boolean;
|
|
70
|
+
readonly?: boolean;
|
|
71
|
+
disabled?: boolean;
|
|
72
|
+
invalid?: boolean;
|
|
73
|
+
/** Takes the keyboard as soon as it is drawn. */
|
|
74
|
+
autofocus?: boolean;
|
|
75
|
+
/** The colours the text and highlight pickers offer. */
|
|
76
|
+
palette?: readonly EditorColor[];
|
|
77
|
+
/** Names the text area, where no label points at it. */
|
|
78
|
+
ariaLabel?: string;
|
|
79
|
+
ariaLabelledby?: string;
|
|
80
|
+
locale?: Locale;
|
|
81
|
+
unstyled?: boolean;
|
|
82
|
+
classes?: Partial<Record<string, ClassEntry>>;
|
|
83
|
+
pt?: PassThrough;
|
|
84
|
+
/** What the host draws itself. */
|
|
85
|
+
hooks?: EditorContentHooks;
|
|
86
|
+
id?: string;
|
|
87
|
+
nonce?: string;
|
|
88
|
+
cssLayer?: string | false;
|
|
89
|
+
overlayTarget?: OverlayTarget;
|
|
90
|
+
zIndex?: number;
|
|
91
|
+
on?: TextEditorEvents;
|
|
92
|
+
}
|
|
93
|
+
export interface TextEditorEvents {
|
|
94
|
+
/** The document changed: the HTML, the JSON and the plain text of it. */
|
|
95
|
+
change?: (value: {
|
|
96
|
+
html: string;
|
|
97
|
+
json: EditorNode;
|
|
98
|
+
text: string;
|
|
99
|
+
}) => void;
|
|
100
|
+
/** The selection moved. */
|
|
101
|
+
'selection-change'?: (event: {
|
|
102
|
+
empty: boolean;
|
|
103
|
+
source: 'user' | 'api' | 'history';
|
|
104
|
+
}) => void;
|
|
105
|
+
focus?: (event: FocusEvent) => void;
|
|
106
|
+
blur?: (event: FocusEvent) => void;
|
|
107
|
+
}
|
|
108
|
+
/** The editor, as the outside sees it. */
|
|
109
|
+
export interface TextEditorHandle {
|
|
110
|
+
update(config: Partial<TextEditorConfig>): void;
|
|
111
|
+
/** The document as HTML. */
|
|
112
|
+
getHTML(): string;
|
|
113
|
+
getJSON(): EditorNode;
|
|
114
|
+
getText(): string;
|
|
115
|
+
getMarkdown(): string;
|
|
116
|
+
setContent(content: EditorContent): void;
|
|
117
|
+
/** Types text where the caret is, Markdown shortcuts and all. */
|
|
118
|
+
typeText(text: string): boolean;
|
|
119
|
+
/** Runs one of the editor's commands by name. */
|
|
120
|
+
run(name: string, ...args: unknown[]): boolean;
|
|
121
|
+
can(name: string, ...args: unknown[]): boolean;
|
|
122
|
+
isActive(name: string, attrs?: Record<string, unknown>): boolean;
|
|
123
|
+
focus(): void;
|
|
124
|
+
/** Draws again, for anything that changed underneath. */
|
|
125
|
+
refresh(): void;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
readonly element: HTMLElement;
|
|
128
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitral/editor",
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"vitral",
|
|
7
|
+
"editor",
|
|
8
|
+
"rich text",
|
|
9
|
+
"wysiwyg",
|
|
10
|
+
"contenteditable"
|
|
11
|
+
],
|
|
12
|
+
"license": "LGPL-3.0-or-later",
|
|
13
|
+
"author": "Gustavo Will",
|
|
14
|
+
"homepage": "https://vitralui.github.io/vitral/",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/vitralui/vitral.git",
|
|
18
|
+
"directory": "packages/editor"
|
|
19
|
+
},
|
|
20
|
+
"bugs": "https://github.com/vitralui/vitral/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"*.css"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./buttons": {
|
|
34
|
+
"types": "./dist/buttons.d.ts",
|
|
35
|
+
"import": "./dist/buttons.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"LICENSE.GPL"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@vitral/core": "0.2.0",
|
|
48
|
+
"@vitral/controls": "0.2.0",
|
|
49
|
+
"@vitral/icons": "0.2.0",
|
|
50
|
+
"@vitral/styles": "0.2.0",
|
|
51
|
+
"@vitral/dom": "0.2.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "vite build && tsc -p tsconfig.build.json"
|
|
55
|
+
}
|
|
56
|
+
}
|