@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
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @vitral/editor
|
|
2
|
+
|
|
3
|
+
A rich text editor with no framework in it: the toolbar, the panels and the
|
|
4
|
+
content area over `@vitral/core`'s editor engine, which the Vitral components
|
|
5
|
+
wrap.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createTextEditor } from '@vitral/editor';
|
|
9
|
+
|
|
10
|
+
const editor = createTextEditor(element, {
|
|
11
|
+
content: '<p>Hello</p>',
|
|
12
|
+
placeholder: 'Write something…',
|
|
13
|
+
showCount: true,
|
|
14
|
+
on: { change: ({ html }) => save(html) }
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
editor.getMarkdown();
|
|
18
|
+
editor.destroy();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The document, the commands, the undo history, the input rules and the bridge to
|
|
22
|
+
the `contenteditable` element are the core's; this package is the interface
|
|
23
|
+
around them: the toolbar and its buttons, the block type, the colour swatches,
|
|
24
|
+
the link, image and table panels, the floating toolbar over a selection, the
|
|
25
|
+
menu a `/` opens in an empty block, and the handle beside a block.
|
|
26
|
+
|
|
27
|
+
A slash menu entry is `{ id, label, description, icon, command }` or carries a
|
|
28
|
+
`run` of its own, so an application can offer whatever it likes; the same goes
|
|
29
|
+
for the block handle's actions. What a framework component draws better — a
|
|
30
|
+
select, a colour picker — it hands over instead.
|
|
31
|
+
|
|
32
|
+
**[Documentation](https://vitralui.github.io/vitral/#/components/editor)**
|
|
33
|
+
|
|
34
|
+
LGPL-3.0-or-later. Part of the [Vitral](https://github.com/vitralui/vitral) monorepo.
|
package/dist/block.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type EditorInstance, type Locale } from '@vitral/core';
|
|
2
|
+
import { type OverlayTarget } from '@vitral/controls';
|
|
3
|
+
import { type Props } from '@vitral/dom';
|
|
4
|
+
import type { BlockAction } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* The handle beside the block the caret is in, and the menu it opens: a piece
|
|
7
|
+
* that attaches to any editor, so the framework-free editor and a framework
|
|
8
|
+
* component that draws its own toolbar both get it from here.
|
|
9
|
+
*/
|
|
10
|
+
export interface BlockHandleOptions {
|
|
11
|
+
editor: EditorInstance;
|
|
12
|
+
/** Where the handle is put: the editor's own box, which it is positioned against. */
|
|
13
|
+
host: () => HTMLElement | null;
|
|
14
|
+
/** The rectangle of the caret, from the editor's view. */
|
|
15
|
+
caretRect: () => {
|
|
16
|
+
top: number;
|
|
17
|
+
left: number;
|
|
18
|
+
height: number;
|
|
19
|
+
} | null;
|
|
20
|
+
actions: () => BlockAction[];
|
|
21
|
+
part: (name: string, state?: unknown) => Props;
|
|
22
|
+
locale?: () => Locale;
|
|
23
|
+
enabled?: () => boolean;
|
|
24
|
+
ids?: {
|
|
25
|
+
slash: string;
|
|
26
|
+
block: string;
|
|
27
|
+
};
|
|
28
|
+
overlayTarget?: OverlayTarget;
|
|
29
|
+
zIndex?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface BlockHandle {
|
|
32
|
+
/** Reads the document and the caret again: called on every change. */
|
|
33
|
+
sync(): void;
|
|
34
|
+
close(): void;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare function createBlockHandle(options: BlockHandleOptions): BlockHandle;
|
|
38
|
+
/** What the handle offers when an application names nothing. */
|
|
39
|
+
export declare function defaultBlockActions(locale: Locale): BlockAction[];
|
package/dist/block.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { iconView } from "./render/toolbar.js";
|
|
2
|
+
import { blockMenuView } from "./render/menus.js";
|
|
3
|
+
import { editorSelectionRange, en } from "@vitral/core";
|
|
4
|
+
import { createOverlay } from "@vitral/controls";
|
|
5
|
+
import { createRoot } from "@vitral/dom";
|
|
6
|
+
//#region src/block.ts
|
|
7
|
+
function createBlockHandle(options) {
|
|
8
|
+
let button = null;
|
|
9
|
+
let root = null;
|
|
10
|
+
let host = null;
|
|
11
|
+
const locale = () => options.locale?.() ?? en;
|
|
12
|
+
const ids = options.ids ?? {
|
|
13
|
+
slash: "vt-slash",
|
|
14
|
+
block: "vt-block"
|
|
15
|
+
};
|
|
16
|
+
const enabled = () => options.enabled?.() ?? true;
|
|
17
|
+
/** The top-level block the caret is in. */
|
|
18
|
+
function block() {
|
|
19
|
+
const state = options.editor.state;
|
|
20
|
+
const index = editorSelectionRange(state.selection).from.path[0];
|
|
21
|
+
const node = index === void 0 ? void 0 : state.doc.content?.[index];
|
|
22
|
+
return node ? {
|
|
23
|
+
node,
|
|
24
|
+
index
|
|
25
|
+
} : null;
|
|
26
|
+
}
|
|
27
|
+
const overlay = createOverlay({
|
|
28
|
+
anchor: () => button,
|
|
29
|
+
render: () => {
|
|
30
|
+
const current = block();
|
|
31
|
+
return current ? blockMenuView({
|
|
32
|
+
locale: locale(),
|
|
33
|
+
part: options.part,
|
|
34
|
+
ids
|
|
35
|
+
}, current.node, options.actions(), { choose: run }) : null;
|
|
36
|
+
},
|
|
37
|
+
placement: "bottom-start",
|
|
38
|
+
target: () => options.overlayTarget,
|
|
39
|
+
zIndex: options.zIndex
|
|
40
|
+
});
|
|
41
|
+
function run(id) {
|
|
42
|
+
const current = block();
|
|
43
|
+
const action = options.actions().find((entry) => entry.id === id);
|
|
44
|
+
overlay.close();
|
|
45
|
+
if (!current || !action) return;
|
|
46
|
+
action.run(options.editor, current.node, current.index);
|
|
47
|
+
}
|
|
48
|
+
/** The handle is the editor's own element, not the document's: it is never edited. */
|
|
49
|
+
function ensure() {
|
|
50
|
+
const next = options.host();
|
|
51
|
+
if (!next) return null;
|
|
52
|
+
if (host !== next) {
|
|
53
|
+
remove();
|
|
54
|
+
host = next;
|
|
55
|
+
}
|
|
56
|
+
if (button) return button;
|
|
57
|
+
button = host.ownerDocument.createElement("button");
|
|
58
|
+
host.appendChild(button);
|
|
59
|
+
root = createRoot(button);
|
|
60
|
+
return button;
|
|
61
|
+
}
|
|
62
|
+
function remove() {
|
|
63
|
+
root = null;
|
|
64
|
+
button?.remove();
|
|
65
|
+
button = null;
|
|
66
|
+
}
|
|
67
|
+
function sync() {
|
|
68
|
+
if (!enabled()) {
|
|
69
|
+
remove();
|
|
70
|
+
overlay.close();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const handle = ensure();
|
|
74
|
+
const rect = options.caretRect();
|
|
75
|
+
const box = options.host()?.getBoundingClientRect();
|
|
76
|
+
if (!handle || !root) return;
|
|
77
|
+
root.attrs({
|
|
78
|
+
...options.part("blockHandle"),
|
|
79
|
+
type: "button",
|
|
80
|
+
contenteditable: "false",
|
|
81
|
+
"aria-label": locale().editor.blockMenu,
|
|
82
|
+
"aria-haspopup": "menu",
|
|
83
|
+
"aria-expanded": overlay.isOpen ? "true" : "false",
|
|
84
|
+
style: rect && box ? { top: `${rect.top - box.top}px` } : void 0,
|
|
85
|
+
onMousedown: (event) => event.preventDefault(),
|
|
86
|
+
onClick: () => {
|
|
87
|
+
if (overlay.isOpen) overlay.close();
|
|
88
|
+
else {
|
|
89
|
+
overlay.open();
|
|
90
|
+
overlay.update();
|
|
91
|
+
}
|
|
92
|
+
sync();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
root.render([iconView("grip", options.part("blockHandleIcon"))]);
|
|
96
|
+
}
|
|
97
|
+
const stop = options.editor.subscribe(sync);
|
|
98
|
+
sync();
|
|
99
|
+
return {
|
|
100
|
+
sync,
|
|
101
|
+
close: () => overlay.close(),
|
|
102
|
+
destroy() {
|
|
103
|
+
stop();
|
|
104
|
+
overlay.destroy();
|
|
105
|
+
remove();
|
|
106
|
+
host = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** What the handle offers when an application names nothing. */
|
|
111
|
+
function defaultBlockActions(locale) {
|
|
112
|
+
const words = locale.editor.blockActions;
|
|
113
|
+
const command = (name) => (editor) => void editor.run(name);
|
|
114
|
+
return [
|
|
115
|
+
{
|
|
116
|
+
id: "duplicate",
|
|
117
|
+
label: words.duplicate ?? "Duplicate",
|
|
118
|
+
icon: "copy",
|
|
119
|
+
run: command("duplicateBlock")
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "moveUp",
|
|
123
|
+
label: words.moveUp ?? "Move up",
|
|
124
|
+
icon: "arrowUp",
|
|
125
|
+
run: command("moveBlockUp")
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "moveDown",
|
|
129
|
+
label: words.moveDown ?? "Move down",
|
|
130
|
+
icon: "arrowDown",
|
|
131
|
+
run: command("moveBlockDown")
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "turnIntoParagraph",
|
|
135
|
+
label: words.turnIntoParagraph ?? "Turn into text",
|
|
136
|
+
icon: "pilcrow",
|
|
137
|
+
run: command("setParagraph")
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "delete",
|
|
141
|
+
label: words.delete ?? "Delete",
|
|
142
|
+
icon: "trash",
|
|
143
|
+
run: command("deleteBlock")
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { createBlockHandle, defaultBlockActions };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","names":[],"sources":["../src/block.ts"],"sourcesContent":["import { editorSelectionRange, en, type EditorInstance, type EditorNode, type Locale } from '@vitral/core';\nimport { createOverlay, type OverlayTarget } from '@vitral/controls';\nimport { createRoot, type Props } from '@vitral/dom';\nimport { blockMenuView } from './render/menus';\nimport { iconView } from './render/toolbar';\nimport type { BlockAction } from './types';\n\n/**\n * The handle beside the block the caret is in, and the menu it opens: a piece\n * that attaches to any editor, so the framework-free editor and a framework\n * component that draws its own toolbar both get it from here.\n */\n\nexport interface BlockHandleOptions {\n editor: EditorInstance;\n /** Where the handle is put: the editor's own box, which it is positioned against. */\n host: () => HTMLElement | null;\n /** The rectangle of the caret, from the editor's view. */\n caretRect: () => { top: number; left: number; height: number } | null;\n actions: () => BlockAction[];\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n enabled?: () => boolean;\n ids?: { slash: string; block: string };\n overlayTarget?: OverlayTarget;\n zIndex?: number;\n}\n\nexport interface BlockHandle {\n /** Reads the document and the caret again: called on every change. */\n sync(): void;\n close(): void;\n destroy(): void;\n}\n\nexport function createBlockHandle(options: BlockHandleOptions): BlockHandle {\n let button: HTMLButtonElement | null = null;\n let root: ReturnType<typeof createRoot> | null = null;\n let host: 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 /** The top-level block the caret is in. */\n function block(): { node: EditorNode; index: number } | null {\n const state = options.editor.state;\n const index = editorSelectionRange(state.selection).from.path[0];\n const node = index === undefined ? undefined : (state.doc.content?.[index] as EditorNode | undefined);\n return node ? { node, index } : null;\n }\n\n const overlay = createOverlay({\n anchor: () => button,\n render: () => {\n const current = block();\n return current ? (blockMenuView({ locale: locale(), part: options.part, ids }, current.node, options.actions(), { choose: run }) as never) : null;\n },\n placement: 'bottom-start',\n target: () => options.overlayTarget,\n zIndex: options.zIndex\n });\n\n function run(id: string) {\n const current = block();\n const action = options.actions().find((entry) => entry.id === id);\n overlay.close();\n if (!current || !action) return;\n action.run(options.editor, current.node, current.index);\n }\n\n /** The handle is the editor's own element, not the document's: it is never edited. */\n function ensure(): HTMLButtonElement | null {\n const next = options.host();\n if (!next) return null;\n if (host !== next) {\n remove();\n host = next;\n }\n if (button) return button;\n button = host.ownerDocument.createElement('button');\n host.appendChild(button);\n root = createRoot(button);\n return button;\n }\n\n function remove() {\n root = null;\n button?.remove();\n button = null;\n }\n\n function sync() {\n if (!enabled()) {\n remove();\n overlay.close();\n return;\n }\n const handle = ensure();\n const rect = options.caretRect();\n const box = options.host()?.getBoundingClientRect();\n if (!handle || !root) return;\n root.attrs({\n ...options.part('blockHandle'),\n type: 'button',\n contenteditable: 'false',\n 'aria-label': locale().editor.blockMenu,\n 'aria-haspopup': 'menu',\n 'aria-expanded': overlay.isOpen ? 'true' : 'false',\n style: rect && box ? { top: `${rect.top - box.top}px` } : undefined,\n // A press on the handle must not take the caret out of the text.\n onMousedown: (event: MouseEvent) => event.preventDefault(),\n onClick: () => {\n if (overlay.isOpen) overlay.close();\n else {\n overlay.open();\n overlay.update();\n }\n sync();\n }\n });\n root.render([iconView('grip', options.part('blockHandleIcon'))]);\n }\n\n const stop = options.editor.subscribe(sync);\n sync();\n\n return {\n sync,\n close: () => overlay.close(),\n destroy() {\n stop();\n overlay.destroy();\n remove();\n host = null;\n }\n };\n}\n\n/** What the handle offers when an application names nothing. */\nexport function defaultBlockActions(locale: Locale): BlockAction[] {\n const words = locale.editor.blockActions;\n const command = (name: string) => (editor: { run: (name: string, ...args: unknown[]) => boolean }) => void editor.run(name);\n return [\n { id: 'duplicate', label: words.duplicate ?? 'Duplicate', icon: 'copy', run: command('duplicateBlock') },\n { id: 'moveUp', label: words.moveUp ?? 'Move up', icon: 'arrowUp', run: command('moveBlockUp') },\n { id: 'moveDown', label: words.moveDown ?? 'Move down', icon: 'arrowDown', run: command('moveBlockDown') },\n { id: 'turnIntoParagraph', label: words.turnIntoParagraph ?? 'Turn into text', icon: 'pilcrow', run: command('setParagraph') },\n { id: 'delete', label: words.delete ?? 'Delete', icon: 'trash', run: command('deleteBlock') }\n ];\n}\n"],"mappings":";;;;;;AAmCA,SAAgB,kBAAkB,SAA0C;CACxE,IAAI,SAAmC;CACvC,IAAI,OAA6C;CACjD,IAAI,OAA2B;CAE/B,MAAM,eAAe,QAAQ,SAAS,KAAK;CAC3C,MAAM,MAAM,QAAQ,OAAO;EAAE,OAAO;EAAY,OAAO;CAAW;CAClE,MAAM,gBAAgB,QAAQ,UAAU,KAAK;;CAG7C,SAAS,QAAoD;EACzD,MAAM,QAAQ,QAAQ,OAAO;EAC7B,MAAM,QAAQ,qBAAqB,MAAM,SAAS,CAAC,CAAC,KAAK,KAAK;EAC9D,MAAM,OAAO,UAAU,KAAA,IAAY,KAAA,IAAa,MAAM,IAAI,UAAU;EACpE,OAAO,OAAO;GAAE;GAAM;EAAM,IAAI;CACpC;CAEA,MAAM,UAAU,cAAc;EAC1B,cAAc;EACd,cAAc;GACV,MAAM,UAAU,MAAM;GACtB,OAAO,UAAW,cAAc;IAAE,QAAQ,OAAO;IAAG,MAAM,QAAQ;IAAM;GAAI,GAAG,QAAQ,MAAM,QAAQ,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC,IAAc;EACjJ;EACA,WAAW;EACX,cAAc,QAAQ;EACtB,QAAQ,QAAQ;CACpB,CAAC;CAED,SAAS,IAAI,IAAY;EACrB,MAAM,UAAU,MAAM;EACtB,MAAM,SAAS,QAAQ,QAAQ,CAAC,CAAC,MAAM,UAAU,MAAM,OAAO,EAAE;EAChE,QAAQ,MAAM;EACd,IAAI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M;EAC3B,UAAU;GACN,KAAK;GACL,QAAQ,QAAQ;GAChB,OAAO;GACP,OAAO;EACX;CACJ;AACJ;;AAGA,SAAgB,oBAAoB,QAA+B;CAC/D,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,WAAW,UAAkB,WAAmE,KAAK,OAAO,IAAI,IAAI;CAC1H,OAAO;EACH;GAAE,IAAI;GAAa,OAAO,MAAM,aAAa;GAAa,MAAM;GAAQ,KAAK,QAAQ,gBAAgB;EAAE;EACvG;GAAE,IAAI;GAAU,OAAO,MAAM,UAAU;GAAW,MAAM;GAAW,KAAK,QAAQ,aAAa;EAAE;EAC/F;GAAE,IAAI;GAAY,OAAO,MAAM,YAAY;GAAa,MAAM;GAAa,KAAK,QAAQ,eAAe;EAAE;EACzG;GAAE,IAAI;GAAqB,OAAO,MAAM,qBAAqB;GAAkB,MAAM;GAAW,KAAK,QAAQ,cAAc;EAAE;EAC7H;GAAE,IAAI;GAAU,OAAO,MAAM,UAAU;GAAU,MAAM;GAAS,KAAK,QAAQ,aAAa;EAAE;CAChG;AACJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Locale } from '@vitral/core';
|
|
2
|
+
import { type IconDef } from '@vitral/icons';
|
|
3
|
+
import type { EditorButtonCommand, EditorToolbarItem } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* What every toolbar button is — icon, name, command, pressed state — as plain
|
|
6
|
+
* data, so the Vue toolbar, the framework-free one and anything else draw the
|
|
7
|
+
* same buttons from the same list.
|
|
8
|
+
*/
|
|
9
|
+
export interface EditorButtonSpec {
|
|
10
|
+
icon: IconDef;
|
|
11
|
+
label: (text: Locale['editor']) => string;
|
|
12
|
+
/** The command the button runs, with its arguments; `link` opens the link editor. */
|
|
13
|
+
command: readonly [string, ...unknown[]];
|
|
14
|
+
/** What the button's pressed state reflects. */
|
|
15
|
+
active?: readonly [string, Record<string, unknown>?];
|
|
16
|
+
}
|
|
17
|
+
/** What each plain toolbar button is: icon, name, command and pressed state. */
|
|
18
|
+
export declare const editorButtons: Record<EditorButtonCommand, EditorButtonSpec>;
|
|
19
|
+
/** Where a button's shortcut is looked up, when it is not its own command's. */
|
|
20
|
+
export declare const shortcutCommands: Partial<Record<EditorButtonCommand, readonly [string, ...unknown[]]>>;
|
|
21
|
+
/** The toolbar `<Editor>` shows unless told otherwise. */
|
|
22
|
+
export declare const defaultToolbar: EditorToolbarItem[][];
|
|
23
|
+
/** The floating toolbar's buttons. */
|
|
24
|
+
export declare const defaultBubbleMenu: EditorToolbarItem[];
|
|
25
|
+
/**
|
|
26
|
+
* The icons the editor ships with, by name. The toolbar holds its own
|
|
27
|
+
* definitions, but the slash menu, the block handle and anything an
|
|
28
|
+
* application names in a command of its own are looked up by name — so the
|
|
29
|
+
* editor puts its own set in the registry rather than going blank in an
|
|
30
|
+
* application that never registered them.
|
|
31
|
+
*/
|
|
32
|
+
export declare const editorIcons: IconDef[];
|
package/dist/buttons.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { arrowDown, arrowUp, bold, clearFormatting, code, codeBlock, copy, grip, heading1, heading2, heading3, highlighter, horizontalRule, image, indent, italic, link, list, listChecks, listOrdered, outdent, pilcrow, quote, redo, strikethrough, table, textColor, trash, underline, undo } from "@vitral/icons";
|
|
2
|
+
//#region src/buttons.ts
|
|
3
|
+
/** What each plain toolbar button is: icon, name, command and pressed state. */
|
|
4
|
+
var editorButtons = {
|
|
5
|
+
paragraph: {
|
|
6
|
+
icon: pilcrow,
|
|
7
|
+
label: (t) => t.paragraph,
|
|
8
|
+
command: ["setParagraph"],
|
|
9
|
+
active: ["paragraph"]
|
|
10
|
+
},
|
|
11
|
+
heading1: {
|
|
12
|
+
icon: heading1,
|
|
13
|
+
label: (t) => t.heading1,
|
|
14
|
+
command: ["toggleHeading", 1],
|
|
15
|
+
active: ["heading", { level: 1 }]
|
|
16
|
+
},
|
|
17
|
+
heading2: {
|
|
18
|
+
icon: heading2,
|
|
19
|
+
label: (t) => t.heading2,
|
|
20
|
+
command: ["toggleHeading", 2],
|
|
21
|
+
active: ["heading", { level: 2 }]
|
|
22
|
+
},
|
|
23
|
+
heading3: {
|
|
24
|
+
icon: heading3,
|
|
25
|
+
label: (t) => t.heading3,
|
|
26
|
+
command: ["toggleHeading", 3],
|
|
27
|
+
active: ["heading", { level: 3 }]
|
|
28
|
+
},
|
|
29
|
+
bold: {
|
|
30
|
+
icon: bold,
|
|
31
|
+
label: (t) => t.bold,
|
|
32
|
+
command: ["toggleBold"],
|
|
33
|
+
active: ["bold"]
|
|
34
|
+
},
|
|
35
|
+
italic: {
|
|
36
|
+
icon: italic,
|
|
37
|
+
label: (t) => t.italic,
|
|
38
|
+
command: ["toggleItalic"],
|
|
39
|
+
active: ["italic"]
|
|
40
|
+
},
|
|
41
|
+
underline: {
|
|
42
|
+
icon: underline,
|
|
43
|
+
label: (t) => t.underline,
|
|
44
|
+
command: ["toggleUnderline"],
|
|
45
|
+
active: ["underline"]
|
|
46
|
+
},
|
|
47
|
+
strike: {
|
|
48
|
+
icon: strikethrough,
|
|
49
|
+
label: (t) => t.strike,
|
|
50
|
+
command: ["toggleStrike"],
|
|
51
|
+
active: ["strike"]
|
|
52
|
+
},
|
|
53
|
+
code: {
|
|
54
|
+
icon: code,
|
|
55
|
+
label: (t) => t.code,
|
|
56
|
+
command: ["toggleCode"],
|
|
57
|
+
active: ["code"]
|
|
58
|
+
},
|
|
59
|
+
bulletList: {
|
|
60
|
+
icon: list,
|
|
61
|
+
label: (t) => t.bulletList,
|
|
62
|
+
command: ["toggleBulletList"],
|
|
63
|
+
active: ["bulletList"]
|
|
64
|
+
},
|
|
65
|
+
orderedList: {
|
|
66
|
+
icon: listOrdered,
|
|
67
|
+
label: (t) => t.orderedList,
|
|
68
|
+
command: ["toggleOrderedList"],
|
|
69
|
+
active: ["orderedList"]
|
|
70
|
+
},
|
|
71
|
+
taskList: {
|
|
72
|
+
icon: listChecks,
|
|
73
|
+
label: (t) => t.taskList,
|
|
74
|
+
command: ["toggleTaskList"],
|
|
75
|
+
active: ["taskList"]
|
|
76
|
+
},
|
|
77
|
+
indent: {
|
|
78
|
+
icon: indent,
|
|
79
|
+
label: (t) => t.indent,
|
|
80
|
+
command: ["sinkListItem"]
|
|
81
|
+
},
|
|
82
|
+
outdent: {
|
|
83
|
+
icon: outdent,
|
|
84
|
+
label: (t) => t.outdent,
|
|
85
|
+
command: ["liftListItem"]
|
|
86
|
+
},
|
|
87
|
+
blockquote: {
|
|
88
|
+
icon: quote,
|
|
89
|
+
label: (t) => t.blockquote,
|
|
90
|
+
command: ["toggleBlockquote"],
|
|
91
|
+
active: ["blockquote"]
|
|
92
|
+
},
|
|
93
|
+
codeBlock: {
|
|
94
|
+
icon: codeBlock,
|
|
95
|
+
label: (t) => t.codeBlock,
|
|
96
|
+
command: ["toggleCodeBlock"],
|
|
97
|
+
active: ["codeBlock"]
|
|
98
|
+
},
|
|
99
|
+
horizontalRule: {
|
|
100
|
+
icon: horizontalRule,
|
|
101
|
+
label: (t) => t.horizontalRule,
|
|
102
|
+
command: ["insertHorizontalRule"]
|
|
103
|
+
},
|
|
104
|
+
link: {
|
|
105
|
+
icon: link,
|
|
106
|
+
label: (t) => t.link,
|
|
107
|
+
command: ["link"],
|
|
108
|
+
active: ["link"]
|
|
109
|
+
},
|
|
110
|
+
undo: {
|
|
111
|
+
icon: undo,
|
|
112
|
+
label: (t) => t.undo,
|
|
113
|
+
command: ["undo"]
|
|
114
|
+
},
|
|
115
|
+
redo: {
|
|
116
|
+
icon: redo,
|
|
117
|
+
label: (t) => t.redo,
|
|
118
|
+
command: ["redo"]
|
|
119
|
+
},
|
|
120
|
+
clear: {
|
|
121
|
+
icon: clearFormatting,
|
|
122
|
+
label: (t) => t.clearFormatting,
|
|
123
|
+
command: ["clearFormatting"]
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/** Where a button's shortcut is looked up, when it is not its own command's. */
|
|
127
|
+
var shortcutCommands = {
|
|
128
|
+
indent: ["indent"],
|
|
129
|
+
outdent: ["outdent"]
|
|
130
|
+
};
|
|
131
|
+
/** The toolbar `<Editor>` shows unless told otherwise. */
|
|
132
|
+
var defaultToolbar = [
|
|
133
|
+
["blockType"],
|
|
134
|
+
[
|
|
135
|
+
"bold",
|
|
136
|
+
"italic",
|
|
137
|
+
"underline",
|
|
138
|
+
"strike",
|
|
139
|
+
"code"
|
|
140
|
+
],
|
|
141
|
+
["color", "highlight"],
|
|
142
|
+
[
|
|
143
|
+
"bulletList",
|
|
144
|
+
"orderedList",
|
|
145
|
+
"taskList"
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
"blockquote",
|
|
149
|
+
"codeBlock",
|
|
150
|
+
"link",
|
|
151
|
+
"image",
|
|
152
|
+
"table",
|
|
153
|
+
"horizontalRule"
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"undo",
|
|
157
|
+
"redo",
|
|
158
|
+
"clear"
|
|
159
|
+
]
|
|
160
|
+
];
|
|
161
|
+
/** The floating toolbar's buttons. */
|
|
162
|
+
var defaultBubbleMenu = [
|
|
163
|
+
"bold",
|
|
164
|
+
"italic",
|
|
165
|
+
"underline",
|
|
166
|
+
"strike",
|
|
167
|
+
"code",
|
|
168
|
+
"link",
|
|
169
|
+
"color"
|
|
170
|
+
];
|
|
171
|
+
/**
|
|
172
|
+
* The icons the editor ships with, by name. The toolbar holds its own
|
|
173
|
+
* definitions, but the slash menu, the block handle and anything an
|
|
174
|
+
* application names in a command of its own are looked up by name — so the
|
|
175
|
+
* editor puts its own set in the registry rather than going blank in an
|
|
176
|
+
* application that never registered them.
|
|
177
|
+
*/
|
|
178
|
+
var editorIcons = [
|
|
179
|
+
...Object.values(editorButtons).map((spec) => spec.icon),
|
|
180
|
+
arrowDown,
|
|
181
|
+
arrowUp,
|
|
182
|
+
copy,
|
|
183
|
+
grip,
|
|
184
|
+
highlighter,
|
|
185
|
+
image,
|
|
186
|
+
table,
|
|
187
|
+
textColor,
|
|
188
|
+
trash
|
|
189
|
+
];
|
|
190
|
+
//#endregion
|
|
191
|
+
export { defaultBubbleMenu, defaultToolbar, editorButtons, editorIcons, shortcutCommands };
|
|
192
|
+
|
|
193
|
+
//# sourceMappingURL=buttons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buttons.js","names":[],"sources":["../src/buttons.ts"],"sourcesContent":["import type { Locale } from '@vitral/core';\nimport {\n arrowDown,\n arrowUp,\n bold,\n clearFormatting,\n code,\n codeBlock,\n copy,\n grip,\n heading1,\n heading2,\n heading3,\n highlighter,\n horizontalRule,\n image,\n indent,\n italic,\n link,\n list,\n listChecks,\n listOrdered,\n outdent,\n pilcrow,\n quote,\n redo,\n strikethrough,\n table,\n textColor,\n trash,\n underline,\n undo,\n type IconDef\n} from '@vitral/icons';\nimport type { EditorButtonCommand, EditorToolbarItem } from './types';\n\n/**\n * What every toolbar button is — icon, name, command, pressed state — as plain\n * data, so the Vue toolbar, the framework-free one and anything else draw the\n * same buttons from the same list.\n */\n\nexport interface EditorButtonSpec {\n icon: IconDef;\n label: (text: Locale['editor']) => string;\n /** The command the button runs, with its arguments; `link` opens the link editor. */\n command: readonly [string, ...unknown[]];\n /** What the button's pressed state reflects. */\n active?: readonly [string, Record<string, unknown>?];\n}\n\n/** What each plain toolbar button is: icon, name, command and pressed state. */\nexport const editorButtons: Record<EditorButtonCommand, EditorButtonSpec> = {\n paragraph: { icon: pilcrow, label: (t) => t.paragraph, command: ['setParagraph'], active: ['paragraph'] },\n heading1: { icon: heading1, label: (t) => t.heading1, command: ['toggleHeading', 1], active: ['heading', { level: 1 }] },\n heading2: { icon: heading2, label: (t) => t.heading2, command: ['toggleHeading', 2], active: ['heading', { level: 2 }] },\n heading3: { icon: heading3, label: (t) => t.heading3, command: ['toggleHeading', 3], active: ['heading', { level: 3 }] },\n bold: { icon: bold, label: (t) => t.bold, command: ['toggleBold'], active: ['bold'] },\n italic: { icon: italic, label: (t) => t.italic, command: ['toggleItalic'], active: ['italic'] },\n underline: { icon: underline, label: (t) => t.underline, command: ['toggleUnderline'], active: ['underline'] },\n strike: { icon: strikethrough, label: (t) => t.strike, command: ['toggleStrike'], active: ['strike'] },\n code: { icon: code, label: (t) => t.code, command: ['toggleCode'], active: ['code'] },\n bulletList: { icon: list, label: (t) => t.bulletList, command: ['toggleBulletList'], active: ['bulletList'] },\n orderedList: { icon: listOrdered, label: (t) => t.orderedList, command: ['toggleOrderedList'], active: ['orderedList'] },\n taskList: { icon: listChecks, label: (t) => t.taskList, command: ['toggleTaskList'], active: ['taskList'] },\n indent: { icon: indent, label: (t) => t.indent, command: ['sinkListItem'] },\n outdent: { icon: outdent, label: (t) => t.outdent, command: ['liftListItem'] },\n blockquote: { icon: quote, label: (t) => t.blockquote, command: ['toggleBlockquote'], active: ['blockquote'] },\n codeBlock: { icon: codeBlock, label: (t) => t.codeBlock, command: ['toggleCodeBlock'], active: ['codeBlock'] },\n horizontalRule: { icon: horizontalRule, label: (t) => t.horizontalRule, command: ['insertHorizontalRule'] },\n link: { icon: link, label: (t) => t.link, command: ['link'], active: ['link'] },\n undo: { icon: undo, label: (t) => t.undo, command: ['undo'] },\n redo: { icon: redo, label: (t) => t.redo, command: ['redo'] },\n clear: { icon: clearFormatting, label: (t) => t.clearFormatting, command: ['clearFormatting'] }\n};\n\n/** Where a button's shortcut is looked up, when it is not its own command's. */\nexport const shortcutCommands: Partial<Record<EditorButtonCommand, readonly [string, ...unknown[]]>> = {\n indent: ['indent'],\n outdent: ['outdent']\n};\n\n/** The toolbar `<Editor>` shows unless told otherwise. */\nexport const defaultToolbar: EditorToolbarItem[][] = [\n ['blockType'],\n ['bold', 'italic', 'underline', 'strike', 'code'],\n ['color', 'highlight'],\n ['bulletList', 'orderedList', 'taskList'],\n ['blockquote', 'codeBlock', 'link', 'image', 'table', 'horizontalRule'],\n ['undo', 'redo', 'clear']\n];\n\n/** The floating toolbar's buttons. */\nexport const defaultBubbleMenu: EditorToolbarItem[] = ['bold', 'italic', 'underline', 'strike', 'code', 'link', 'color'];\n\n/**\n * The icons the editor ships with, by name. The toolbar holds its own\n * definitions, but the slash menu, the block handle and anything an\n * application names in a command of its own are looked up by name — so the\n * editor puts its own set in the registry rather than going blank in an\n * application that never registered them.\n */\nexport const editorIcons: IconDef[] = [\n ...Object.values(editorButtons).map((spec) => spec.icon),\n arrowDown,\n arrowUp,\n copy,\n grip,\n highlighter,\n image,\n table,\n textColor,\n trash\n];\n"],"mappings":";;;AAoDA,IAAa,gBAA+D;CACxE,WAAW;EAAE,MAAM;EAAS,QAAQ,MAAM,EAAE;EAAW,SAAS,CAAC,cAAc;EAAG,QAAQ,CAAC,WAAW;CAAE;CACxG,UAAU;EAAE,MAAM;EAAU,QAAQ,MAAM,EAAE;EAAU,SAAS,CAAC,iBAAiB,CAAC;EAAG,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;CAAE;CACvH,UAAU;EAAE,MAAM;EAAU,QAAQ,MAAM,EAAE;EAAU,SAAS,CAAC,iBAAiB,CAAC;EAAG,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;CAAE;CACvH,UAAU;EAAE,MAAM;EAAU,QAAQ,MAAM,EAAE;EAAU,SAAS,CAAC,iBAAiB,CAAC;EAAG,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;CAAE;CACvH,MAAM;EAAE,MAAM;EAAM,QAAQ,MAAM,EAAE;EAAM,SAAS,CAAC,YAAY;EAAG,QAAQ,CAAC,MAAM;CAAE;CACpF,QAAQ;EAAE,MAAM;EAAQ,QAAQ,MAAM,EAAE;EAAQ,SAAS,CAAC,cAAc;EAAG,QAAQ,CAAC,QAAQ;CAAE;CAC9F,WAAW;EAAE,MAAM;EAAW,QAAQ,MAAM,EAAE;EAAW,SAAS,CAAC,iBAAiB;EAAG,QAAQ,CAAC,WAAW;CAAE;CAC7G,QAAQ;EAAE,MAAM;EAAe,QAAQ,MAAM,EAAE;EAAQ,SAAS,CAAC,cAAc;EAA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