BookStack/resources/js/wysiwyg/ui/toolbars.ts

103 lines
3.8 KiB
TypeScript
Raw Normal View History

2024-06-13 02:51:42 +08:00
import {EditorButton} from "./framework/buttons";
import {
blockquote, bold, bulletList, clearFormating, code, codeBlock,
dangerCallout, details, fullscreen,
2024-06-27 22:48:06 +08:00
h2, h3, h4, h5, highlightColor, horizontalRule, image,
infoCallout, italic, link, numberList, paragraph,
redo, source, strikethrough, subscript,
2024-06-21 23:18:44 +08:00
successCallout, superscript, table, taskList, textColor, underline,
undo, unlink,
warningCallout
} from "./defaults/button-definitions";
import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiContext, EditorUiElement} from "./framework/core";
import {el} from "../helpers";
2024-06-13 02:51:42 +08:00
import {EditorFormatMenu} from "./framework/blocks/format-menu";
import {FormatPreviewButton} from "./framework/blocks/format-preview-button";
import {EditorDropdownButton} from "./framework/blocks/dropdown-button";
import {EditorColorPicker} from "./framework/blocks/color-picker";
2024-06-21 23:18:44 +08:00
import {EditorTableCreator} from "./framework/blocks/table-creator";
import {EditorColorButton} from "./framework/blocks/color-button";
2024-06-27 23:28:06 +08:00
import {EditorOverflowContainer} from "./framework/blocks/overflow-container";
export function getMainEditorFullToolbar(): EditorContainerUiElement {
return new EditorSimpleClassContainer('editor-toolbar-main', [
2024-06-12 21:24:50 +08:00
// History state
new EditorButton(undo),
new EditorButton(redo),
2024-06-12 21:24:50 +08:00
// Block formats
new EditorFormatMenu([
new FormatPreviewButton(el('h2'), h2),
new FormatPreviewButton(el('h3'), h3),
new FormatPreviewButton(el('h4'), h4),
new FormatPreviewButton(el('h5'), h5),
new FormatPreviewButton(el('blockquote'), blockquote),
new FormatPreviewButton(el('p'), paragraph),
new FormatPreviewButton(el('p', {class: 'callout info'}), infoCallout),
new FormatPreviewButton(el('p', {class: 'callout success'}), successCallout),
new FormatPreviewButton(el('p', {class: 'callout warning'}), warningCallout),
new FormatPreviewButton(el('p', {class: 'callout danger'}), dangerCallout),
]),
2024-06-12 21:24:50 +08:00
// Inline formats
new EditorButton(bold),
new EditorButton(italic),
new EditorButton(underline),
new EditorDropdownButton(new EditorColorButton(textColor, 'color'), [
2024-06-13 02:51:42 +08:00
new EditorColorPicker('color'),
]),
new EditorDropdownButton(new EditorColorButton(highlightColor, 'background-color'), [
2024-06-13 02:51:42 +08:00
new EditorColorPicker('background-color'),
]),
new EditorButton(strikethrough),
new EditorButton(superscript),
new EditorButton(subscript),
new EditorButton(code),
2024-06-12 21:24:50 +08:00
new EditorButton(clearFormating),
// Lists
new EditorButton(bulletList),
new EditorButton(numberList),
new EditorButton(taskList),
2024-06-12 21:24:50 +08:00
// Insert types
2024-06-27 23:28:06 +08:00
new EditorOverflowContainer(6, [
new EditorButton(link),
new EditorDropdownButton(table, [
new EditorTableCreator(),
]),
new EditorButton(image),
new EditorButton(horizontalRule),
new EditorButton(codeBlock),
2024-06-27 23:28:06 +08:00
new EditorButton(details),
2024-06-21 23:18:44 +08:00
]),
2024-06-12 21:24:50 +08:00
// Meta elements
new EditorButton(source),
new EditorButton(fullscreen),
// Test
new EditorButton({
2024-06-27 22:48:06 +08:00
label: 'Test button',
action(context: EditorUiContext) {
context.editor.update(() => {
2024-06-27 22:48:06 +08:00
// Do stuff
});
},
isActive() {
return false;
}
})
]);
}
export function getImageToolbarContent(): EditorUiElement[] {
return [new EditorButton(image)];
}
export function getLinkToolbarContent(): EditorUiElement[] {
return [
new EditorButton(link),
new EditorButton(unlink),
];
}