2024-06-23 18:36:48 +08:00
|
|
|
import {EditorBasicButtonDefinition, EditorButton, EditorButtonDefinition} from "../framework/buttons";
|
2024-05-29 05:56:58 +08:00
|
|
|
import {
|
2024-06-01 23:49:47 +08:00
|
|
|
$createNodeSelection,
|
2024-07-01 02:52:09 +08:00
|
|
|
$createParagraphNode, $createTextNode, $getRoot, $getSelection,
|
2024-06-12 21:24:50 +08:00
|
|
|
$isParagraphNode, $isTextNode, $setSelection,
|
2024-06-23 18:36:48 +08:00
|
|
|
BaseSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, ElementNode, FORMAT_TEXT_COMMAND,
|
2024-05-29 05:56:58 +08:00
|
|
|
LexicalNode,
|
2024-06-19 23:14:20 +08:00
|
|
|
REDO_COMMAND, TextFormatType,
|
2024-05-29 05:56:58 +08:00
|
|
|
UNDO_COMMAND
|
|
|
|
} from "lexical";
|
2024-06-01 23:49:47 +08:00
|
|
|
import {
|
2024-06-27 22:48:06 +08:00
|
|
|
getNodeFromSelection, insertNewBlockNodeAtSelection,
|
2024-06-01 23:49:47 +08:00
|
|
|
selectionContainsNodeType,
|
|
|
|
selectionContainsTextFormat,
|
|
|
|
toggleSelectionBlockNodeType
|
|
|
|
} from "../../helpers";
|
2024-05-30 03:38:31 +08:00
|
|
|
import {$createCalloutNode, $isCalloutNodeOfCategory, CalloutCategory} from "../../nodes/callout";
|
2024-05-29 05:56:58 +08:00
|
|
|
import {
|
|
|
|
$createHeadingNode,
|
|
|
|
$createQuoteNode,
|
|
|
|
$isHeadingNode,
|
|
|
|
$isQuoteNode,
|
|
|
|
HeadingNode,
|
|
|
|
HeadingTagType
|
|
|
|
} from "@lexical/rich-text";
|
2024-06-19 23:14:20 +08:00
|
|
|
import {$isLinkNode, LinkNode} from "@lexical/link";
|
2024-05-30 23:50:55 +08:00
|
|
|
import {EditorUiContext} from "../framework/core";
|
2024-06-06 01:43:42 +08:00
|
|
|
import {$isImageNode, ImageNode} from "../../nodes/image";
|
2024-06-06 21:43:50 +08:00
|
|
|
import {$createDetailsNode, $isDetailsNode} from "../../nodes/details";
|
2024-06-12 21:01:36 +08:00
|
|
|
import {getEditorContentAsHtml} from "../../actions";
|
2024-06-19 23:14:20 +08:00
|
|
|
import {$isListNode, insertList, ListNode, ListType, removeList} from "@lexical/list";
|
2024-06-20 03:00:29 +08:00
|
|
|
import undoIcon from "@icons/editor/undo.svg"
|
|
|
|
import redoIcon from "@icons/editor/redo.svg"
|
|
|
|
import boldIcon from "@icons/editor/bold.svg"
|
|
|
|
import italicIcon from "@icons/editor/italic.svg"
|
|
|
|
import underlinedIcon from "@icons/editor/underlined.svg"
|
2024-06-23 22:50:41 +08:00
|
|
|
import textColorIcon from "@icons/editor/text-color.svg";
|
|
|
|
import highlightIcon from "@icons/editor/highlighter.svg";
|
2024-06-20 03:00:29 +08:00
|
|
|
import strikethroughIcon from "@icons/editor/strikethrough.svg"
|
|
|
|
import superscriptIcon from "@icons/editor/superscript.svg"
|
|
|
|
import subscriptIcon from "@icons/editor/subscript.svg"
|
|
|
|
import codeIcon from "@icons/editor/code.svg"
|
|
|
|
import formatClearIcon from "@icons/editor/format-clear.svg"
|
|
|
|
import listBulletIcon from "@icons/editor/list-bullet.svg"
|
|
|
|
import listNumberedIcon from "@icons/editor/list-numbered.svg"
|
|
|
|
import listCheckIcon from "@icons/editor/list-check.svg"
|
|
|
|
import linkIcon from "@icons/editor/link.svg"
|
2024-07-01 02:52:09 +08:00
|
|
|
import unlinkIcon from "@icons/editor/unlink.svg"
|
2024-06-23 22:50:41 +08:00
|
|
|
import tableIcon from "@icons/editor/table.svg"
|
2024-06-20 03:00:29 +08:00
|
|
|
import imageIcon from "@icons/editor/image.svg"
|
2024-06-27 22:48:06 +08:00
|
|
|
import horizontalRuleIcon from "@icons/editor/horizontal-rule.svg"
|
2024-06-20 03:00:29 +08:00
|
|
|
import detailsIcon from "@icons/editor/details.svg"
|
|
|
|
import sourceIcon from "@icons/editor/source-view.svg"
|
2024-07-01 17:44:23 +08:00
|
|
|
import fullscreenIcon from "@icons/editor/fullscreen.svg"
|
2024-07-01 02:52:09 +08:00
|
|
|
import {$createHorizontalRuleNode, $isHorizontalRuleNode} from "../../nodes/horizontal-rule";
|
2024-05-29 05:56:58 +08:00
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const undo: EditorButtonDefinition = {
|
2024-05-29 05:56:58 +08:00
|
|
|
label: 'Undo',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: undoIcon,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.dispatchCommand(UNDO_COMMAND, undefined);
|
2024-05-29 05:56:58 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return false;
|
2024-06-23 18:36:48 +08:00
|
|
|
},
|
|
|
|
setup(context: EditorUiContext, button: EditorButton) {
|
|
|
|
button.toggleDisabled(true);
|
|
|
|
|
|
|
|
context.editor.registerCommand(CAN_UNDO_COMMAND, (payload: boolean): boolean => {
|
|
|
|
button.toggleDisabled(!payload)
|
|
|
|
return false;
|
|
|
|
}, COMMAND_PRIORITY_LOW);
|
2024-05-29 05:56:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const redo: EditorButtonDefinition = {
|
2024-05-29 05:56:58 +08:00
|
|
|
label: 'Redo',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: redoIcon,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.dispatchCommand(REDO_COMMAND, undefined);
|
2024-05-29 05:56:58 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return false;
|
2024-06-23 18:36:48 +08:00
|
|
|
},
|
|
|
|
setup(context: EditorUiContext, button: EditorButton) {
|
|
|
|
button.toggleDisabled(true);
|
|
|
|
|
|
|
|
context.editor.registerCommand(CAN_REDO_COMMAND, (payload: boolean): boolean => {
|
|
|
|
button.toggleDisabled(!payload)
|
|
|
|
return false;
|
|
|
|
}, COMMAND_PRIORITY_LOW);
|
2024-05-29 05:56:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildCalloutButton(category: CalloutCategory, name: string): EditorButtonDefinition {
|
|
|
|
return {
|
|
|
|
label: `${name} Callout`,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
2024-05-29 05:56:58 +08:00
|
|
|
toggleSelectionBlockNodeType(
|
2024-05-30 23:50:55 +08:00
|
|
|
context.editor,
|
2024-05-29 05:56:58 +08:00
|
|
|
(node) => $isCalloutNodeOfCategory(node, category),
|
|
|
|
() => $createCalloutNode(category),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, (node) => $isCalloutNodeOfCategory(node, category));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const infoCallout: EditorButtonDefinition = buildCalloutButton('info', 'Info');
|
|
|
|
export const dangerCallout: EditorButtonDefinition = buildCalloutButton('danger', 'Danger');
|
|
|
|
export const warningCallout: EditorButtonDefinition = buildCalloutButton('warning', 'Warning');
|
|
|
|
export const successCallout: EditorButtonDefinition = buildCalloutButton('success', 'Success');
|
2024-05-29 05:56:58 +08:00
|
|
|
|
|
|
|
const isHeaderNodeOfTag = (node: LexicalNode | null | undefined, tag: HeadingTagType) => {
|
|
|
|
return $isHeadingNode(node) && (node as HeadingNode).getTag() === tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
function buildHeaderButton(tag: HeadingTagType, name: string): EditorButtonDefinition {
|
|
|
|
return {
|
|
|
|
label: name,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
2024-05-29 05:56:58 +08:00
|
|
|
toggleSelectionBlockNodeType(
|
2024-05-30 23:50:55 +08:00
|
|
|
context.editor,
|
2024-05-29 05:56:58 +08:00
|
|
|
(node) => isHeaderNodeOfTag(node, tag),
|
|
|
|
() => $createHeadingNode(tag),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, (node) => isHeaderNodeOfTag(node, tag));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const h2: EditorButtonDefinition = buildHeaderButton('h2', 'Large Header');
|
|
|
|
export const h3: EditorButtonDefinition = buildHeaderButton('h3', 'Medium Header');
|
|
|
|
export const h4: EditorButtonDefinition = buildHeaderButton('h4', 'Small Header');
|
|
|
|
export const h5: EditorButtonDefinition = buildHeaderButton('h5', 'Tiny Header');
|
2024-05-29 05:56:58 +08:00
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const blockquote: EditorButtonDefinition = {
|
2024-05-29 05:56:58 +08:00
|
|
|
label: 'Blockquote',
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
toggleSelectionBlockNodeType(context.editor, $isQuoteNode, $createQuoteNode);
|
2024-05-29 05:56:58 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isQuoteNode);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
export const paragraph: EditorButtonDefinition = {
|
2024-05-29 05:56:58 +08:00
|
|
|
label: 'Paragraph',
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
toggleSelectionBlockNodeType(context.editor, $isParagraphNode, $createParagraphNode);
|
2024-05-29 05:56:58 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isParagraphNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-20 03:00:29 +08:00
|
|
|
function buildFormatButton(label: string, format: TextFormatType, icon: string): EditorButtonDefinition {
|
2024-05-29 05:56:58 +08:00
|
|
|
return {
|
|
|
|
label: label,
|
2024-06-20 03:00:29 +08:00
|
|
|
icon,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
|
2024-05-29 05:56:58 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsTextFormat(selection, format);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-20 03:00:29 +08:00
|
|
|
export const bold: EditorButtonDefinition = buildFormatButton('Bold', 'bold', boldIcon);
|
|
|
|
export const italic: EditorButtonDefinition = buildFormatButton('Italic', 'italic', italicIcon);
|
|
|
|
export const underline: EditorButtonDefinition = buildFormatButton('Underline', 'underline', underlinedIcon);
|
2024-06-23 22:50:41 +08:00
|
|
|
export const textColor: EditorBasicButtonDefinition = {label: 'Text color', icon: textColorIcon};
|
|
|
|
export const highlightColor: EditorBasicButtonDefinition = {label: 'Highlight color', icon: highlightIcon};
|
2024-06-13 02:51:42 +08:00
|
|
|
|
2024-06-20 03:00:29 +08:00
|
|
|
export const strikethrough: EditorButtonDefinition = buildFormatButton('Strikethrough', 'strikethrough', strikethroughIcon);
|
|
|
|
export const superscript: EditorButtonDefinition = buildFormatButton('Superscript', 'superscript', superscriptIcon);
|
|
|
|
export const subscript: EditorButtonDefinition = buildFormatButton('Subscript', 'subscript', subscriptIcon);
|
|
|
|
export const code: EditorButtonDefinition = buildFormatButton('Inline Code', 'code', codeIcon);
|
2024-06-12 21:24:50 +08:00
|
|
|
export const clearFormating: EditorButtonDefinition = {
|
|
|
|
label: 'Clear formatting',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: formatClearIcon,
|
2024-06-12 21:24:50 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
for (const node of selection?.getNodes() || []) {
|
|
|
|
if ($isTextNode(node)) {
|
|
|
|
node.setFormat(0);
|
2024-06-23 22:50:41 +08:00
|
|
|
node.setStyle('');
|
2024-06-12 21:24:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2024-05-30 03:38:31 +08:00
|
|
|
|
2024-06-20 03:00:29 +08:00
|
|
|
function buildListButton(label: string, type: ListType, icon: string): EditorButtonDefinition {
|
2024-06-19 23:14:20 +08:00
|
|
|
return {
|
|
|
|
label,
|
2024-06-20 03:00:29 +08:00
|
|
|
icon,
|
2024-06-19 23:14:20 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.getEditorState().read(() => {
|
|
|
|
const selection = $getSelection();
|
2024-07-01 17:44:23 +08:00
|
|
|
if (this.isActive(selection, context)) {
|
2024-06-19 23:14:20 +08:00
|
|
|
removeList(context.editor);
|
|
|
|
} else {
|
|
|
|
insertList(context.editor, type);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, (node: LexicalNode | null | undefined): boolean => {
|
|
|
|
return $isListNode(node) && (node as ListNode).getListType() === type;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-20 03:00:29 +08:00
|
|
|
export const bulletList: EditorButtonDefinition = buildListButton('Bullet list', 'bullet', listBulletIcon);
|
|
|
|
export const numberList: EditorButtonDefinition = buildListButton('Numbered list', 'number', listNumberedIcon);
|
|
|
|
export const taskList: EditorButtonDefinition = buildListButton('Task list', 'check', listCheckIcon);
|
2024-06-19 23:14:20 +08:00
|
|
|
|
2024-05-30 03:38:31 +08:00
|
|
|
|
|
|
|
export const link: EditorButtonDefinition = {
|
|
|
|
label: 'Insert/edit link',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: linkIcon,
|
2024-05-30 23:50:55 +08:00
|
|
|
action(context: EditorUiContext) {
|
2024-06-01 23:49:47 +08:00
|
|
|
const linkModal = context.manager.createModal('link');
|
|
|
|
context.editor.getEditorState().read(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
const selectedLink = getNodeFromSelection(selection, $isLinkNode) as LinkNode|null;
|
|
|
|
|
|
|
|
let formDefaults = {};
|
|
|
|
if (selectedLink) {
|
|
|
|
formDefaults = {
|
|
|
|
url: selectedLink.getURL(),
|
|
|
|
text: selectedLink.getTextContent(),
|
|
|
|
title: selectedLink.getTitle(),
|
|
|
|
target: selectedLink.getTarget(),
|
|
|
|
}
|
|
|
|
|
|
|
|
context.editor.update(() => {
|
|
|
|
const selection = $createNodeSelection();
|
|
|
|
selection.add(selectedLink.getKey());
|
|
|
|
$setSelection(selection);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
linkModal.show(formDefaults);
|
|
|
|
});
|
2024-05-30 03:38:31 +08:00
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isLinkNode);
|
|
|
|
}
|
2024-07-01 02:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const unlink: EditorButtonDefinition = {
|
|
|
|
label: 'Remove link',
|
|
|
|
icon: unlinkIcon,
|
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.update(() => {
|
|
|
|
const selection = context.lastSelection;
|
|
|
|
const selectedLink = getNodeFromSelection(selection, $isLinkNode) as LinkNode|null;
|
|
|
|
const selectionPoints = selection?.getStartEndPoints();
|
|
|
|
|
|
|
|
if (selectedLink) {
|
|
|
|
const newNode = $createTextNode(selectedLink.getTextContent());
|
|
|
|
selectedLink.replace(newNode);
|
|
|
|
if (selectionPoints?.length === 2) {
|
|
|
|
newNode.select(selectionPoints[0].offset, selectionPoints[1].offset);
|
|
|
|
} else {
|
|
|
|
newNode.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
2024-05-30 03:38:31 +08:00
|
|
|
};
|
|
|
|
|
2024-06-21 23:18:44 +08:00
|
|
|
export const table: EditorBasicButtonDefinition = {
|
|
|
|
label: 'Table',
|
2024-06-23 22:50:41 +08:00
|
|
|
icon: tableIcon,
|
2024-06-21 23:18:44 +08:00
|
|
|
};
|
|
|
|
|
2024-06-06 01:43:42 +08:00
|
|
|
export const image: EditorButtonDefinition = {
|
|
|
|
label: 'Insert/Edit Image',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: imageIcon,
|
2024-06-06 01:43:42 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
const imageModal = context.manager.createModal('image');
|
|
|
|
const selection = context.lastSelection;
|
|
|
|
const selectedImage = getNodeFromSelection(selection, $isImageNode) as ImageNode|null;
|
|
|
|
|
|
|
|
context.editor.getEditorState().read(() => {
|
|
|
|
let formDefaults = {};
|
|
|
|
if (selectedImage) {
|
|
|
|
formDefaults = {
|
|
|
|
src: selectedImage.getSrc(),
|
|
|
|
alt: selectedImage.getAltText(),
|
|
|
|
height: selectedImage.getHeight(),
|
|
|
|
width: selectedImage.getWidth(),
|
|
|
|
}
|
|
|
|
|
|
|
|
context.editor.update(() => {
|
|
|
|
const selection = $createNodeSelection();
|
|
|
|
selection.add(selectedImage.getKey());
|
|
|
|
$setSelection(selection);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
imageModal.show(formDefaults);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isImageNode);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-06-27 22:48:06 +08:00
|
|
|
export const horizontalRule: EditorButtonDefinition = {
|
|
|
|
label: 'Insert horizontal line',
|
|
|
|
icon: horizontalRuleIcon,
|
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.update(() => {
|
|
|
|
insertNewBlockNodeAtSelection($createHorizontalRuleNode(), false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isHorizontalRuleNode);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-06-06 21:43:50 +08:00
|
|
|
export const details: EditorButtonDefinition = {
|
|
|
|
label: 'Insert collapsible block',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: detailsIcon,
|
2024-06-06 21:43:50 +08:00
|
|
|
action(context: EditorUiContext) {
|
|
|
|
context.editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
const detailsNode = $createDetailsNode();
|
|
|
|
const selectionNodes = selection?.getNodes() || [];
|
|
|
|
const topLevels = selectionNodes.map(n => n.getTopLevelElement())
|
|
|
|
.filter(n => n !== null) as ElementNode[];
|
|
|
|
const uniqueTopLevels = [...new Set(topLevels)];
|
|
|
|
|
|
|
|
if (uniqueTopLevels.length > 0) {
|
|
|
|
uniqueTopLevels[0].insertAfter(detailsNode);
|
|
|
|
} else {
|
|
|
|
$getRoot().append(detailsNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const node of uniqueTopLevels) {
|
|
|
|
detailsNode.append(node);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isActive(selection: BaseSelection|null): boolean {
|
|
|
|
return selectionContainsNodeType(selection, $isDetailsNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-12 21:01:36 +08:00
|
|
|
export const source: EditorButtonDefinition = {
|
|
|
|
label: 'Source code',
|
2024-06-20 03:00:29 +08:00
|
|
|
icon: sourceIcon,
|
2024-06-12 21:01:36 +08:00
|
|
|
async action(context: EditorUiContext) {
|
|
|
|
const modal = context.manager.createModal('source');
|
|
|
|
const source = await getEditorContentAsHtml(context.editor);
|
|
|
|
modal.show({source});
|
|
|
|
},
|
|
|
|
isActive() {
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-01 17:44:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const fullscreen: EditorButtonDefinition = {
|
|
|
|
label: 'Fullscreen',
|
|
|
|
icon: fullscreenIcon,
|
|
|
|
async action(context: EditorUiContext, button: EditorButton) {
|
|
|
|
const isFullScreen = context.containerDOM.classList.contains('fullscreen');
|
|
|
|
context.containerDOM.classList.toggle('fullscreen', !isFullScreen);
|
|
|
|
(context.containerDOM.closest('body') as HTMLElement).classList.toggle('editor-is-fullscreen', !isFullScreen);
|
|
|
|
button.setActiveState(!isFullScreen);
|
|
|
|
},
|
|
|
|
isActive(selection, context: EditorUiContext) {
|
|
|
|
return context.containerDOM.classList.contains('fullscreen');
|
|
|
|
}
|
2024-06-13 02:51:42 +08:00
|
|
|
};
|