]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/toolbars.ts
Lexical: Integrated diagram manager, added menu split button
[bookstack] / resources / js / wysiwyg / ui / toolbars.ts
1 import {EditorButton} from "./framework/buttons";
2 import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiElement} from "./framework/core";
3 import {EditorFormatMenu} from "./framework/blocks/format-menu";
4 import {FormatPreviewButton} from "./framework/blocks/format-preview-button";
5 import {EditorDropdownButton} from "./framework/blocks/dropdown-button";
6 import {EditorColorPicker} from "./framework/blocks/color-picker";
7 import {EditorTableCreator} from "./framework/blocks/table-creator";
8 import {EditorColorButton} from "./framework/blocks/color-button";
9 import {EditorOverflowContainer} from "./framework/blocks/overflow-container";
10 import {
11     cellProperties, clearTableFormatting,
12     copyColumn,
13     copyRow,
14     cutColumn,
15     cutRow,
16     deleteColumn,
17     deleteRow,
18     deleteTable,
19     deleteTableMenuAction,
20     insertColumnAfter,
21     insertColumnBefore,
22     insertRowAbove,
23     insertRowBelow,
24     mergeCells,
25     pasteColumnAfter,
26     pasteColumnBefore,
27     pasteRowAfter,
28     pasteRowBefore, resizeTableToContents,
29     rowProperties,
30     splitCell,
31     table, tableProperties
32 } from "./defaults/buttons/tables";
33 import {fullscreen, redo, source, undo} from "./defaults/buttons/controls";
34 import {
35     blockquote, dangerCallout,
36     h2,
37     h3,
38     h4,
39     h5,
40     infoCallout,
41     paragraph,
42     successCallout,
43     warningCallout
44 } from "./defaults/buttons/block-formats";
45 import {
46     bold, clearFormating, code,
47     highlightColor,
48     italic,
49     strikethrough, subscript,
50     superscript,
51     textColor,
52     underline
53 } from "./defaults/buttons/inline-formats";
54 import {alignCenter, alignJustify, alignLeft, alignRight} from "./defaults/buttons/alignments";
55 import {bulletList, numberList, taskList} from "./defaults/buttons/lists";
56 import {
57     codeBlock,
58     details,
59     diagram, diagramManager,
60     editCodeBlock,
61     horizontalRule,
62     image,
63     link, media,
64     unlink
65 } from "./defaults/buttons/objects";
66 import {el} from "../utils/dom";
67 import {EditorButtonWithMenu} from "./framework/blocks/button-with-menu";
68
69 export function getMainEditorFullToolbar(): EditorContainerUiElement {
70     return new EditorSimpleClassContainer('editor-toolbar-main', [
71
72         // History state
73         new EditorOverflowContainer(2, [
74             new EditorButton(undo),
75             new EditorButton(redo),
76         ]),
77
78         // Block formats
79         new EditorFormatMenu([
80             new FormatPreviewButton(el('h2'), h2),
81             new FormatPreviewButton(el('h3'), h3),
82             new FormatPreviewButton(el('h4'), h4),
83             new FormatPreviewButton(el('h5'), h5),
84             new FormatPreviewButton(el('blockquote'), blockquote),
85             new FormatPreviewButton(el('p'), paragraph),
86             new EditorDropdownButton({button: {label: 'Callouts'}, showOnHover: true, direction: 'vertical'}, [
87                 new FormatPreviewButton(el('p', {class: 'callout info'}), infoCallout),
88                 new FormatPreviewButton(el('p', {class: 'callout success'}), successCallout),
89                 new FormatPreviewButton(el('p', {class: 'callout warning'}), warningCallout),
90                 new FormatPreviewButton(el('p', {class: 'callout danger'}), dangerCallout),
91             ]),
92         ]),
93
94         // Inline formats
95         new EditorOverflowContainer(6, [
96             new EditorButton(bold),
97             new EditorButton(italic),
98             new EditorButton(underline),
99             new EditorDropdownButton({ button: new EditorColorButton(textColor, 'color') }, [
100                 new EditorColorPicker('color'),
101             ]),
102             new EditorDropdownButton({button: new EditorColorButton(highlightColor, 'background-color')}, [
103                 new EditorColorPicker('background-color'),
104             ]),
105             new EditorButton(strikethrough),
106             new EditorButton(superscript),
107             new EditorButton(subscript),
108             new EditorButton(code),
109             new EditorButton(clearFormating),
110         ]),
111
112         // Alignment
113         new EditorOverflowContainer(4, [
114             new EditorButton(alignLeft),
115             new EditorButton(alignCenter),
116             new EditorButton(alignRight),
117             new EditorButton(alignJustify),
118         ]),
119
120         // Lists
121         new EditorOverflowContainer(3, [
122             new EditorButton(bulletList),
123             new EditorButton(numberList),
124             new EditorButton(taskList),
125         ]),
126
127         // Insert types
128         new EditorOverflowContainer(8, [
129             new EditorButton(link),
130
131             new EditorDropdownButton({button: table, direction: 'vertical'}, [
132                 new EditorDropdownButton({button: {...table, format: 'long'}, showOnHover: true}, [
133                     new EditorTableCreator(),
134                 ]),
135                 new EditorDropdownButton({button: {label: 'Cell'}, direction: 'vertical', showOnHover: true}, [
136                     new EditorButton(cellProperties),
137                     new EditorButton(mergeCells),
138                     new EditorButton(splitCell),
139                 ]),
140                 new EditorDropdownButton({button: {label: 'Row'}, direction: 'vertical', showOnHover: true}, [
141                     new EditorButton({...insertRowAbove, format: 'long'}),
142                     new EditorButton({...insertRowBelow, format: 'long'}),
143                     new EditorButton({...deleteRow, format: 'long'}),
144                     new EditorButton(rowProperties),
145                     new EditorButton(cutRow),
146                     new EditorButton(copyRow),
147                     new EditorButton(pasteRowBefore),
148                     new EditorButton(pasteRowAfter),
149                 ]),
150                 new EditorDropdownButton({button: {label: 'Column'}, direction: 'vertical', showOnHover: true}, [
151                     new EditorButton({...insertColumnBefore, format: 'long'}),
152                     new EditorButton({...insertColumnAfter, format: 'long'}),
153                     new EditorButton({...deleteColumn, format: 'long'}),
154                     new EditorButton(cutColumn),
155                     new EditorButton(copyColumn),
156                     new EditorButton(pasteColumnBefore),
157                     new EditorButton(pasteColumnAfter),
158                 ]),
159                 new EditorButton({...tableProperties, format: 'long'}),
160                 new EditorButton(clearTableFormatting),
161                 new EditorButton(resizeTableToContents),
162                 new EditorButton(deleteTableMenuAction),
163             ]),
164
165             new EditorButton(image),
166             new EditorButton(horizontalRule),
167             new EditorButton(codeBlock),
168             new EditorButtonWithMenu(
169                 new EditorButton(diagram),
170                 [new EditorButton(diagramManager)],
171             ),
172             new EditorButton(media),
173             new EditorButton(details),
174         ]),
175
176         // Meta elements
177         new EditorOverflowContainer(3, [
178             new EditorButton(source),
179             new EditorButton(fullscreen),
180
181             // Test
182             // new EditorButton({
183             //     label: 'Test button',
184             //     action(context: EditorUiContext) {
185             //         context.editor.update(() => {
186             //             // Do stuff
187             //         });
188             //     },
189             //     isActive() {
190             //         return false;
191             //     }
192             // })
193         ]),
194     ]);
195 }
196
197 export function getImageToolbarContent(): EditorUiElement[] {
198     return [new EditorButton(image)];
199 }
200
201 export function getLinkToolbarContent(): EditorUiElement[] {
202     return [
203         new EditorButton(link),
204         new EditorButton(unlink),
205     ];
206 }
207
208 export function getCodeToolbarContent(): EditorUiElement[] {
209     return [
210         new EditorButton(editCodeBlock),
211     ];
212 }
213
214 export function getTableToolbarContent(): EditorUiElement[] {
215     return [
216         new EditorOverflowContainer(2, [
217             new EditorButton(tableProperties),
218             new EditorButton(deleteTable),
219         ]),
220         new EditorOverflowContainer(3, [
221             new EditorButton(insertRowAbove),
222             new EditorButton(insertRowBelow),
223             new EditorButton(deleteRow),
224         ]),
225         new EditorOverflowContainer(3, [
226             new EditorButton(insertColumnBefore),
227             new EditorButton(insertColumnAfter),
228             new EditorButton(deleteColumn),
229         ]),
230     ];
231 }