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