]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/defaults/toolbars.ts
Lexical: Added a media toolbar, improved toolbars and media selection
[bookstack] / resources / js / wysiwyg / ui / defaults / toolbars.ts
1 import {EditorButton} from "../framework/buttons";
2 import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiContext, 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 "./buttons/tables";
33 import {about, fullscreen, redo, source, undo} from "./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 "./buttons/block-formats";
45 import {
46     bold, clearFormating, code,
47     highlightColor, highlightColorAction,
48     italic,
49     strikethrough, subscript,
50     superscript,
51     textColor, textColorAction,
52     underline
53 } from "./buttons/inline-formats";
54 import {
55     alignCenter,
56     alignJustify,
57     alignLeft,
58     alignRight,
59     directionLTR,
60     directionRTL
61 } from "./buttons/alignments";
62 import {
63     bulletList,
64     indentDecrease,
65     indentIncrease,
66     numberList,
67     taskList
68 } from "./buttons/lists";
69 import {
70     codeBlock,
71     details, detailsEditLabel, detailsToggle, detailsUnwrap,
72     diagram, diagramManager,
73     editCodeBlock,
74     horizontalRule,
75     image,
76     link, media,
77     unlink
78 } from "./buttons/objects";
79 import {el} from "../../utils/dom";
80 import {EditorButtonWithMenu} from "../framework/blocks/button-with-menu";
81 import {EditorSeparator} from "../framework/blocks/separator";
82
83 export function getMainEditorFullToolbar(context: EditorUiContext): EditorContainerUiElement {
84
85     const inRtlMode = context.manager.getDefaultDirection() === 'rtl';
86
87     return new EditorSimpleClassContainer('editor-toolbar-main', [
88
89         // History state
90         new EditorOverflowContainer(2, [
91             new EditorButton(undo),
92             new EditorButton(redo),
93         ]),
94
95         // Block formats
96         new EditorFormatMenu([
97             new FormatPreviewButton(el('h2'), h2),
98             new FormatPreviewButton(el('h3'), h3),
99             new FormatPreviewButton(el('h4'), h4),
100             new FormatPreviewButton(el('h5'), h5),
101             new FormatPreviewButton(el('blockquote'), blockquote),
102             new FormatPreviewButton(el('p'), paragraph),
103             new EditorDropdownButton({button: {label: 'Callouts', format: 'long'}, showOnHover: true, direction: 'vertical'}, [
104                 new FormatPreviewButton(el('p', {class: 'callout info'}), infoCallout),
105                 new FormatPreviewButton(el('p', {class: 'callout success'}), successCallout),
106                 new FormatPreviewButton(el('p', {class: 'callout warning'}), warningCallout),
107                 new FormatPreviewButton(el('p', {class: 'callout danger'}), dangerCallout),
108             ]),
109         ]),
110
111         // Inline formats
112         new EditorOverflowContainer(6, [
113             new EditorButton(bold),
114             new EditorButton(italic),
115             new EditorButton(underline),
116             new EditorDropdownButton({ button: new EditorColorButton(textColor, 'color') }, [
117                 new EditorColorPicker(textColorAction),
118             ]),
119             new EditorDropdownButton({button: new EditorColorButton(highlightColor, 'background-color')}, [
120                 new EditorColorPicker(highlightColorAction),
121             ]),
122             new EditorButton(strikethrough),
123             new EditorButton(superscript),
124             new EditorButton(subscript),
125             new EditorButton(code),
126             new EditorButton(clearFormating),
127         ]),
128
129         // Alignment
130         new EditorOverflowContainer(6, [
131             new EditorButton(alignLeft),
132             new EditorButton(alignCenter),
133             new EditorButton(alignRight),
134             new EditorButton(alignJustify),
135             inRtlMode ? new EditorButton(directionLTR) : null,
136             inRtlMode ? new EditorButton(directionRTL) : null,
137         ].filter(x => x !== null)),
138
139         // Lists
140         new EditorOverflowContainer(3, [
141             new EditorButton(bulletList),
142             new EditorButton(numberList),
143             new EditorButton(taskList),
144             new EditorButton(indentDecrease),
145             new EditorButton(indentIncrease),
146         ]),
147
148         // Insert types
149         new EditorOverflowContainer(4, [
150             new EditorButton(link),
151
152             new EditorDropdownButton({button: table, direction: 'vertical', showAside: false}, [
153                 new EditorDropdownButton({button: {label: 'Insert', format: 'long'}, showOnHover: true, showAside: true}, [
154                     new EditorTableCreator(),
155                 ]),
156                 new EditorSeparator(),
157                 new EditorDropdownButton({button: {label: 'Cell', format: 'long'}, direction: 'vertical', showOnHover: true}, [
158                     new EditorButton(cellProperties),
159                     new EditorButton(mergeCells),
160                     new EditorButton(splitCell),
161                 ]),
162                 new EditorDropdownButton({button: {label: 'Row', format: 'long'}, direction: 'vertical', showOnHover: true}, [
163                     new EditorButton({...insertRowAbove, format: 'long'}),
164                     new EditorButton({...insertRowBelow, format: 'long'}),
165                     new EditorButton({...deleteRow, format: 'long'}),
166                     new EditorButton(rowProperties),
167                     new EditorSeparator(),
168                     new EditorButton(cutRow),
169                     new EditorButton(copyRow),
170                     new EditorButton(pasteRowBefore),
171                     new EditorButton(pasteRowAfter),
172                 ]),
173                 new EditorDropdownButton({button: {label: 'Column', format: 'long'}, direction: 'vertical', showOnHover: true}, [
174                     new EditorButton({...insertColumnBefore, format: 'long'}),
175                     new EditorButton({...insertColumnAfter, format: 'long'}),
176                     new EditorButton({...deleteColumn, format: 'long'}),
177                     new EditorSeparator(),
178                     new EditorButton(cutColumn),
179                     new EditorButton(copyColumn),
180                     new EditorButton(pasteColumnBefore),
181                     new EditorButton(pasteColumnAfter),
182                 ]),
183                 new EditorSeparator(),
184                 new EditorButton({...tableProperties, format: 'long'}),
185                 new EditorButton(clearTableFormatting),
186                 new EditorButton(resizeTableToContents),
187                 new EditorButton(deleteTableMenuAction),
188             ]),
189
190             new EditorButton(image),
191             new EditorButton(horizontalRule),
192             new EditorButton(codeBlock),
193             new EditorButtonWithMenu(
194                 new EditorButton(diagram),
195                 [new EditorButton(diagramManager)],
196             ),
197             new EditorButton(media),
198             new EditorButton(details),
199         ]),
200
201         // Meta elements
202         new EditorOverflowContainer(3, [
203             new EditorButton(source),
204             new EditorButton(about),
205             new EditorButton(fullscreen),
206
207             // Test
208             // new EditorButton({
209             //     label: 'Test button',
210             //     action(context: EditorUiContext) {
211             //         context.editor.update(() => {
212             //             // Do stuff
213             //         });
214             //     },
215             //     isActive() {
216             //         return false;
217             //     }
218             // })
219         ]),
220     ]);
221 }
222
223 export function getImageToolbarContent(): EditorUiElement[] {
224     return [new EditorButton(image)];
225 }
226
227 export function getMediaToolbarContent(): EditorUiElement[] {
228     return [new EditorButton(media)];
229 }
230
231 export function getLinkToolbarContent(): EditorUiElement[] {
232     return [
233         new EditorButton(link),
234         new EditorButton(unlink),
235     ];
236 }
237
238 export function getCodeToolbarContent(): EditorUiElement[] {
239     return [
240         new EditorButton(editCodeBlock),
241     ];
242 }
243
244 export function getTableToolbarContent(): EditorUiElement[] {
245     return [
246         new EditorOverflowContainer(2, [
247             new EditorButton(tableProperties),
248             new EditorButton(deleteTable),
249         ]),
250         new EditorOverflowContainer(3, [
251             new EditorButton(insertRowAbove),
252             new EditorButton(insertRowBelow),
253             new EditorButton(deleteRow),
254         ]),
255         new EditorOverflowContainer(3, [
256             new EditorButton(insertColumnBefore),
257             new EditorButton(insertColumnAfter),
258             new EditorButton(deleteColumn),
259         ]),
260     ];
261 }
262
263 export function getDetailsToolbarContent(): EditorUiElement[] {
264     return [
265         new EditorButton(detailsEditLabel),
266         new EditorButton(detailsToggle),
267         new EditorButton(detailsUnwrap),
268     ];
269 }