2024-06-13 02:51:42 +08:00
|
|
|
import {EditorButton} from "./framework/buttons";
|
2024-09-24 00:36:16 +08:00
|
|
|
import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiContext, EditorUiElement} from "./framework/core";
|
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";
|
2024-06-23 22:50:41 +08:00
|
|
|
import {EditorColorButton} from "./framework/blocks/color-button";
|
2024-06-27 23:28:06 +08:00
|
|
|
import {EditorOverflowContainer} from "./framework/blocks/overflow-container";
|
2024-07-21 22:11:24 +08:00
|
|
|
import {
|
2024-08-04 01:01:54 +08:00
|
|
|
cellProperties, clearTableFormatting,
|
|
|
|
copyColumn,
|
|
|
|
copyRow,
|
|
|
|
cutColumn,
|
|
|
|
cutRow,
|
2024-07-21 22:11:24 +08:00
|
|
|
deleteColumn,
|
|
|
|
deleteRow,
|
2024-08-04 01:01:54 +08:00
|
|
|
deleteTable,
|
|
|
|
deleteTableMenuAction,
|
|
|
|
insertColumnAfter,
|
2024-07-21 22:11:24 +08:00
|
|
|
insertColumnBefore,
|
|
|
|
insertRowAbove,
|
2024-08-04 01:01:54 +08:00
|
|
|
insertRowBelow,
|
|
|
|
mergeCells,
|
|
|
|
pasteColumnAfter,
|
|
|
|
pasteColumnBefore,
|
|
|
|
pasteRowAfter,
|
|
|
|
pasteRowBefore, resizeTableToContents,
|
|
|
|
rowProperties,
|
|
|
|
splitCell,
|
|
|
|
table, tableProperties
|
2024-07-21 22:11:24 +08:00
|
|
|
} from "./defaults/buttons/tables";
|
|
|
|
import {fullscreen, redo, source, undo} from "./defaults/buttons/controls";
|
|
|
|
import {
|
|
|
|
blockquote, dangerCallout,
|
|
|
|
h2,
|
|
|
|
h3,
|
|
|
|
h4,
|
|
|
|
h5,
|
|
|
|
infoCallout,
|
|
|
|
paragraph,
|
|
|
|
successCallout,
|
|
|
|
warningCallout
|
|
|
|
} from "./defaults/buttons/block-formats";
|
|
|
|
import {
|
|
|
|
bold, clearFormating, code,
|
|
|
|
highlightColor,
|
|
|
|
italic,
|
|
|
|
strikethrough, subscript,
|
|
|
|
superscript,
|
|
|
|
textColor,
|
|
|
|
underline
|
|
|
|
} from "./defaults/buttons/inline-formats";
|
2024-09-16 19:29:46 +08:00
|
|
|
import {
|
|
|
|
alignCenter,
|
|
|
|
alignJustify,
|
|
|
|
alignLeft,
|
|
|
|
alignRight,
|
|
|
|
directionLTR,
|
|
|
|
directionRTL
|
|
|
|
} from "./defaults/buttons/alignments";
|
2024-09-10 22:55:46 +08:00
|
|
|
import {
|
|
|
|
bulletList,
|
|
|
|
indentDecrease,
|
|
|
|
indentIncrease,
|
|
|
|
numberList,
|
|
|
|
taskList
|
|
|
|
} from "./defaults/buttons/lists";
|
2024-07-21 22:11:24 +08:00
|
|
|
import {
|
|
|
|
codeBlock,
|
|
|
|
details,
|
2024-08-17 17:48:34 +08:00
|
|
|
diagram, diagramManager,
|
2024-07-21 22:11:24 +08:00
|
|
|
editCodeBlock,
|
|
|
|
horizontalRule,
|
|
|
|
image,
|
2024-07-25 23:25:08 +08:00
|
|
|
link, media,
|
2024-07-21 22:11:24 +08:00
|
|
|
unlink
|
|
|
|
} from "./defaults/buttons/objects";
|
2024-08-04 01:14:01 +08:00
|
|
|
import {el} from "../utils/dom";
|
2024-08-17 17:48:34 +08:00
|
|
|
import {EditorButtonWithMenu} from "./framework/blocks/button-with-menu";
|
2024-09-09 21:06:41 +08:00
|
|
|
import {EditorSeparator} from "./framework/blocks/separator";
|
2024-05-30 03:38:31 +08:00
|
|
|
|
2024-09-24 00:36:16 +08:00
|
|
|
export function getMainEditorFullToolbar(context: EditorUiContext): EditorContainerUiElement {
|
|
|
|
|
|
|
|
const inRtlMode = context.manager.getDefaultDirection() === 'rtl';
|
|
|
|
|
2024-05-30 19:25:25 +08:00
|
|
|
return new EditorSimpleClassContainer('editor-toolbar-main', [
|
2024-07-04 23:16:16 +08:00
|
|
|
|
2024-06-12 21:24:50 +08:00
|
|
|
// History state
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorOverflowContainer(2, [
|
|
|
|
new EditorButton(undo),
|
|
|
|
new EditorButton(redo),
|
|
|
|
]),
|
2024-05-30 03:38:31 +08:00
|
|
|
|
2024-06-12 21:24:50 +08:00
|
|
|
// Block formats
|
2024-05-30 03:38:31 +08:00
|
|
|
new EditorFormatMenu([
|
2024-05-30 19:25:25 +08:00
|
|
|
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),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorDropdownButton({button: {label: 'Callouts', format: 'long'}, showOnHover: true, direction: 'vertical'}, [
|
2024-07-04 23:16:16 +08:00
|
|
|
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-05-30 03:38:31 +08:00
|
|
|
]),
|
|
|
|
|
2024-06-12 21:24:50 +08:00
|
|
|
// Inline formats
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorOverflowContainer(6, [
|
|
|
|
new EditorButton(bold),
|
|
|
|
new EditorButton(italic),
|
|
|
|
new EditorButton(underline),
|
2024-08-02 18:16:54 +08:00
|
|
|
new EditorDropdownButton({ button: new EditorColorButton(textColor, 'color') }, [
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorColorPicker('color'),
|
|
|
|
]),
|
2024-08-02 18:16:54 +08:00
|
|
|
new EditorDropdownButton({button: new EditorColorButton(highlightColor, 'background-color')}, [
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorColorPicker('background-color'),
|
|
|
|
]),
|
|
|
|
new EditorButton(strikethrough),
|
|
|
|
new EditorButton(superscript),
|
|
|
|
new EditorButton(subscript),
|
|
|
|
new EditorButton(code),
|
|
|
|
new EditorButton(clearFormating),
|
2024-06-13 02:51:42 +08:00
|
|
|
]),
|
2024-05-30 03:38:31 +08:00
|
|
|
|
2024-07-17 23:38:20 +08:00
|
|
|
// Alignment
|
2024-09-24 00:36:16 +08:00
|
|
|
new EditorOverflowContainer(6, [
|
2024-07-17 23:38:20 +08:00
|
|
|
new EditorButton(alignLeft),
|
|
|
|
new EditorButton(alignCenter),
|
|
|
|
new EditorButton(alignRight),
|
|
|
|
new EditorButton(alignJustify),
|
2024-09-24 00:36:16 +08:00
|
|
|
inRtlMode ? new EditorButton(directionLTR) : null,
|
|
|
|
inRtlMode ? new EditorButton(directionRTL) : null,
|
|
|
|
].filter(x => x !== null)),
|
2024-07-17 23:38:20 +08:00
|
|
|
|
2024-06-19 23:14:20 +08:00
|
|
|
// Lists
|
2024-09-24 00:36:16 +08:00
|
|
|
new EditorOverflowContainer(3, [
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorButton(bulletList),
|
|
|
|
new EditorButton(numberList),
|
|
|
|
new EditorButton(taskList),
|
2024-09-10 22:55:46 +08:00
|
|
|
new EditorButton(indentDecrease),
|
|
|
|
new EditorButton(indentIncrease),
|
2024-07-04 23:16:16 +08:00
|
|
|
]),
|
2024-06-19 23:14:20 +08:00
|
|
|
|
2024-06-12 21:24:50 +08:00
|
|
|
// Insert types
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorOverflowContainer(4, [
|
2024-06-27 23:28:06 +08:00
|
|
|
new EditorButton(link),
|
2024-08-02 18:16:54 +08:00
|
|
|
|
|
|
|
new EditorDropdownButton({button: table, direction: 'vertical'}, [
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorDropdownButton({button: {label: 'Insert', format: 'long'}, showOnHover: true}, [
|
2024-08-02 18:16:54 +08:00
|
|
|
new EditorTableCreator(),
|
|
|
|
]),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorSeparator(),
|
|
|
|
new EditorDropdownButton({button: {label: 'Cell', format: 'long'}, direction: 'vertical', showOnHover: true}, [
|
2024-08-02 22:28:54 +08:00
|
|
|
new EditorButton(cellProperties),
|
|
|
|
new EditorButton(mergeCells),
|
|
|
|
new EditorButton(splitCell),
|
|
|
|
]),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorDropdownButton({button: {label: 'Row', format: 'long'}, direction: 'vertical', showOnHover: true}, [
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton({...insertRowAbove, format: 'long'}),
|
|
|
|
new EditorButton({...insertRowBelow, format: 'long'}),
|
|
|
|
new EditorButton({...deleteRow, format: 'long'}),
|
|
|
|
new EditorButton(rowProperties),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorSeparator(),
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton(cutRow),
|
|
|
|
new EditorButton(copyRow),
|
|
|
|
new EditorButton(pasteRowBefore),
|
|
|
|
new EditorButton(pasteRowAfter),
|
|
|
|
]),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorDropdownButton({button: {label: 'Column', format: 'long'}, direction: 'vertical', showOnHover: true}, [
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton({...insertColumnBefore, format: 'long'}),
|
|
|
|
new EditorButton({...insertColumnAfter, format: 'long'}),
|
|
|
|
new EditorButton({...deleteColumn, format: 'long'}),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorSeparator(),
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton(cutColumn),
|
|
|
|
new EditorButton(copyColumn),
|
|
|
|
new EditorButton(pasteColumnBefore),
|
|
|
|
new EditorButton(pasteColumnAfter),
|
|
|
|
]),
|
2024-09-09 21:06:41 +08:00
|
|
|
new EditorSeparator(),
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton({...tableProperties, format: 'long'}),
|
|
|
|
new EditorButton(clearTableFormatting),
|
|
|
|
new EditorButton(resizeTableToContents),
|
2024-08-02 18:16:54 +08:00
|
|
|
new EditorButton(deleteTableMenuAction),
|
2024-06-27 23:28:06 +08:00
|
|
|
]),
|
2024-08-02 18:16:54 +08:00
|
|
|
|
2024-06-27 23:28:06 +08:00
|
|
|
new EditorButton(image),
|
|
|
|
new EditorButton(horizontalRule),
|
2024-07-03 00:34:03 +08:00
|
|
|
new EditorButton(codeBlock),
|
2024-08-17 17:48:34 +08:00
|
|
|
new EditorButtonWithMenu(
|
|
|
|
new EditorButton(diagram),
|
|
|
|
[new EditorButton(diagramManager)],
|
|
|
|
),
|
2024-07-25 23:25:08 +08:00
|
|
|
new EditorButton(media),
|
2024-06-27 23:28:06 +08:00
|
|
|
new EditorButton(details),
|
2024-06-21 23:18:44 +08:00
|
|
|
]),
|
2024-06-12 21:01:36 +08:00
|
|
|
|
2024-06-12 21:24:50 +08:00
|
|
|
// Meta elements
|
2024-07-04 23:16:16 +08:00
|
|
|
new EditorOverflowContainer(3, [
|
|
|
|
new EditorButton(source),
|
|
|
|
new EditorButton(fullscreen),
|
2024-06-25 03:50:17 +08:00
|
|
|
|
2024-07-04 23:16:16 +08:00
|
|
|
// Test
|
2024-07-10 03:49:47 +08:00
|
|
|
// new EditorButton({
|
|
|
|
// label: 'Test button',
|
|
|
|
// action(context: EditorUiContext) {
|
|
|
|
// context.editor.update(() => {
|
|
|
|
// // Do stuff
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// isActive() {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// })
|
2024-07-04 23:16:16 +08:00
|
|
|
]),
|
2024-05-30 03:38:31 +08:00
|
|
|
]);
|
2024-06-30 19:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getImageToolbarContent(): EditorUiElement[] {
|
|
|
|
return [new EditorButton(image)];
|
2024-07-01 02:52:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getLinkToolbarContent(): EditorUiElement[] {
|
|
|
|
return [
|
|
|
|
new EditorButton(link),
|
|
|
|
new EditorButton(unlink),
|
|
|
|
];
|
2024-07-16 23:36:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getCodeToolbarContent(): EditorUiElement[] {
|
|
|
|
return [
|
|
|
|
new EditorButton(editCodeBlock),
|
|
|
|
];
|
2024-07-21 22:11:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getTableToolbarContent(): EditorUiElement[] {
|
|
|
|
return [
|
|
|
|
new EditorOverflowContainer(2, [
|
2024-08-04 01:01:54 +08:00
|
|
|
new EditorButton(tableProperties),
|
2024-07-21 22:11:24 +08:00
|
|
|
new EditorButton(deleteTable),
|
|
|
|
]),
|
|
|
|
new EditorOverflowContainer(3, [
|
|
|
|
new EditorButton(insertRowAbove),
|
|
|
|
new EditorButton(insertRowBelow),
|
|
|
|
new EditorButton(deleteRow),
|
|
|
|
]),
|
|
|
|
new EditorOverflowContainer(3, [
|
|
|
|
new EditorButton(insertColumnBefore),
|
|
|
|
new EditorButton(insertColumnAfter),
|
|
|
|
new EditorButton(deleteColumn),
|
|
|
|
]),
|
|
|
|
];
|
2024-05-30 03:38:31 +08:00
|
|
|
}
|