Lexical: Updated toolbar & text node exporting

- Updated toolbar to match existing editor, including dynamic RTL/LTR
  controls.
- Updated text node handling to not include spans and extra classes when
  not needed. Added & update tests to cover.
This commit is contained in:
Dan Brown
2024-09-23 17:36:16 +01:00
parent 8b32e6c15a
commit a62d8381be
16 changed files with 152 additions and 51 deletions

View File

@ -1,5 +1,5 @@
import {EditorButton} from "./framework/buttons";
import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiElement} from "./framework/core";
import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiContext, EditorUiElement} from "./framework/core";
import {EditorFormatMenu} from "./framework/blocks/format-menu";
import {FormatPreviewButton} from "./framework/blocks/format-preview-button";
import {EditorDropdownButton} from "./framework/blocks/dropdown-button";
@ -80,7 +80,10 @@ import {el} from "../utils/dom";
import {EditorButtonWithMenu} from "./framework/blocks/button-with-menu";
import {EditorSeparator} from "./framework/blocks/separator";
export function getMainEditorFullToolbar(): EditorContainerUiElement {
export function getMainEditorFullToolbar(context: EditorUiContext): EditorContainerUiElement {
const inRtlMode = context.manager.getDefaultDirection() === 'rtl';
return new EditorSimpleClassContainer('editor-toolbar-main', [
// History state
@ -124,17 +127,17 @@ export function getMainEditorFullToolbar(): EditorContainerUiElement {
]),
// Alignment
new EditorOverflowContainer(6, [ // TODO - Dynamic
new EditorOverflowContainer(6, [
new EditorButton(alignLeft),
new EditorButton(alignCenter),
new EditorButton(alignRight),
new EditorButton(alignJustify),
new EditorButton(directionLTR), // TODO - Dynamic
new EditorButton(directionRTL), // TODO - Dynamic
]),
inRtlMode ? new EditorButton(directionLTR) : null,
inRtlMode ? new EditorButton(directionRTL) : null,
].filter(x => x !== null)),
// Lists
new EditorOverflowContainer(5, [
new EditorOverflowContainer(3, [
new EditorButton(bulletList),
new EditorButton(numberList),
new EditorButton(taskList),