]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/toolbars.ts
Lexical: Created custom table node with col width handling
[bookstack] / resources / js / wysiwyg / ui / toolbars.ts
1 import {EditorButton} from "./framework/buttons";
2 import {
3     blockquote, bold, bulletList, clearFormating, code,
4     dangerCallout, details,
5     h2, h3, h4, h5, highlightColor, image,
6     infoCallout, italic, link, numberList, paragraph,
7     redo, source, strikethrough, subscript,
8     successCallout, superscript, table, taskList, textColor, underline,
9     undo,
10     warningCallout
11 } from "./defaults/button-definitions";
12 import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiContext} from "./framework/core";
13 import {el} from "../helpers";
14 import {EditorFormatMenu} from "./framework/blocks/format-menu";
15 import {FormatPreviewButton} from "./framework/blocks/format-preview-button";
16 import {EditorDropdownButton} from "./framework/blocks/dropdown-button";
17 import {EditorColorPicker} from "./framework/blocks/color-picker";
18 import {EditorTableCreator} from "./framework/blocks/table-creator";
19 import {EditorColorButton} from "./framework/blocks/color-button";
20 import {$isCustomTableNode, $setTableColumnWidth, CustomTableNode} from "../nodes/custom-table";
21 import {$getRoot} from "lexical";
22
23 export function getMainEditorFullToolbar(): EditorContainerUiElement {
24     return new EditorSimpleClassContainer('editor-toolbar-main', [
25         // History state
26         new EditorButton(undo),
27         new EditorButton(redo),
28
29         // Block formats
30         new EditorFormatMenu([
31             new FormatPreviewButton(el('h2'), h2),
32             new FormatPreviewButton(el('h3'), h3),
33             new FormatPreviewButton(el('h4'), h4),
34             new FormatPreviewButton(el('h5'), h5),
35             new FormatPreviewButton(el('blockquote'), blockquote),
36             new FormatPreviewButton(el('p'), paragraph),
37             new FormatPreviewButton(el('p', {class: 'callout info'}), infoCallout),
38             new FormatPreviewButton(el('p', {class: 'callout success'}), successCallout),
39             new FormatPreviewButton(el('p', {class: 'callout warning'}), warningCallout),
40             new FormatPreviewButton(el('p', {class: 'callout danger'}), dangerCallout),
41         ]),
42
43         // Inline formats
44         new EditorButton(bold),
45         new EditorButton(italic),
46         new EditorButton(underline),
47         new EditorDropdownButton(new EditorColorButton(textColor, 'color'), [
48             new EditorColorPicker('color'),
49         ]),
50         new EditorDropdownButton(new EditorColorButton(highlightColor, 'background-color'), [
51             new EditorColorPicker('background-color'),
52         ]),
53         new EditorButton(strikethrough),
54         new EditorButton(superscript),
55         new EditorButton(subscript),
56         new EditorButton(code),
57         new EditorButton(clearFormating),
58
59         // Lists
60         new EditorButton(bulletList),
61         new EditorButton(numberList),
62         new EditorButton(taskList),
63
64         // Insert types
65         new EditorButton(link),
66         new EditorDropdownButton(table, [
67             new EditorTableCreator(),
68         ]),
69         new EditorButton(image),
70         new EditorButton(details),
71
72         // Meta elements
73         new EditorButton(source),
74
75         // Test
76         new EditorButton({
77             label: 'Expand table col 2',
78             action(context: EditorUiContext) {
79                 context.editor.update(() => {
80                     const root = $getRoot();
81                     let table: CustomTableNode|null = null;
82                     for (const child of root.getChildren()) {
83                         if ($isCustomTableNode(child)) {
84                             table = child as CustomTableNode;
85                             break;
86                         }
87                     }
88
89                     if (table) {
90                         $setTableColumnWidth(table, 1, 500);
91                     }
92                 });
93             },
94             isActive() {
95                 return false;
96             }
97         })
98     ]);
99 }