Skip to content

Commit ae4d1d8

Browse files
committed
Lexical: Table cell bg and format setting fixes
- Updated table cell background color setting to be stable by specifically using the background property over the general styles. - Updated format shorcuts to be correct header levels as per old editor and format menu. - Updated format changes to properly update UI afterwards.
1 parent 5fc19b0 commit ae4d1d8

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

resources/js/wysiwyg/lexical/table/LexicalTableCellNode.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,17 @@ export function $convertTableCellNodeElement(
353353
const hasUnderlineTextDecoration = textDecoration.includes('underline');
354354

355355
if (domNode instanceof HTMLElement) {
356-
tableCellNode.setStyles(extractStyleMapFromElement(domNode));
356+
const styleMap = extractStyleMapFromElement(domNode);
357+
styleMap.delete('background-color');
358+
tableCellNode.setStyles(styleMap);
357359
tableCellNode.setAlignment(extractAlignmentFromElement(domNode));
358360
}
359361

362+
const background = style.backgroundColor || null;
363+
if (background) {
364+
tableCellNode.setBackgroundColor(background);
365+
}
366+
360367
return {
361368
after: (childLexicalNodes) => {
362369
if (childLexicalNodes.length === 0) {

resources/js/wysiwyg/services/shortcuts.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import {$showLinkForm} from "../ui/defaults/forms/objects";
1313
import {showLinkSelector} from "../utils/links";
1414
import {HeadingTagType} from "@lexical/rich-text/LexicalHeadingNode";
1515

16-
function headerHandler(editor: LexicalEditor, tag: HeadingTagType): boolean {
17-
toggleSelectionAsHeading(editor, tag);
16+
function headerHandler(context: EditorUiContext, tag: HeadingTagType): boolean {
17+
toggleSelectionAsHeading(context.editor, tag);
18+
context.manager.triggerFutureStateRefresh();
1819
return true;
1920
}
2021

2122
function wrapFormatAction(formatAction: (editor: LexicalEditor) => any): ShortcutAction {
22-
return (editor: LexicalEditor) => {
23+
return (editor: LexicalEditor, context: EditorUiContext) => {
2324
formatAction(editor);
25+
context.manager.triggerFutureStateRefresh();
2426
return true;
2527
};
2628
}
@@ -45,10 +47,10 @@ const actionsByKeys: Record<string, ShortcutAction> = {
4547
window.$events.emit('editor-save-page');
4648
return true;
4749
},
48-
'meta+1': (editor) => headerHandler(editor, 'h1'),
49-
'meta+2': (editor) => headerHandler(editor, 'h2'),
50-
'meta+3': (editor) => headerHandler(editor, 'h3'),
51-
'meta+4': (editor) => headerHandler(editor, 'h4'),
50+
'meta+1': (editor, context) => headerHandler(context, 'h2'),
51+
'meta+2': (editor, context) => headerHandler(context, 'h3'),
52+
'meta+3': (editor, context) => headerHandler(context, 'h4'),
53+
'meta+4': (editor, context) => headerHandler(context, 'h5'),
5254
'meta+5': wrapFormatAction(toggleSelectionAsParagraph),
5355
'meta+d': wrapFormatAction(toggleSelectionAsParagraph),
5456
'meta+6': wrapFormatAction(toggleSelectionAsBlockquote),

resources/js/wysiwyg/ui/defaults/buttons/inline-formats.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import codeIcon from "@icons/editor/code.svg";
1313
import formatClearIcon from "@icons/editor/format-clear.svg";
1414
import {$selectionContainsTextFormat} from "../../../utils/selection";
1515
import {$patchStyleText} from "@lexical/selection";
16-
import {context} from "esbuild";
1716

1817
function buildFormatButton(label: string, format: TextFormatType, icon: string): EditorButtonDefinition {
1918
return {

resources/js/wysiwyg/ui/defaults/forms/tables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function $showCellPropertiesForm(cell: TableCellNode, context: EditorUiCo
7575
border_width: styles.get('border-width') || '',
7676
border_style: styles.get('border-style') || '',
7777
border_color: styles.get('border-color') || '',
78-
background_color: styles.get('background-color') || '',
78+
background_color: cell.getBackgroundColor() || styles.get('background-color') || '',
7979
});
8080
return modalForm;
8181
}
@@ -91,14 +91,14 @@ export const cellProperties: EditorFormDefinition = {
9191
$setTableCellColumnWidth(cell, width);
9292
cell.updateTag(formData.get('type')?.toString() || '');
9393
cell.setAlignment((formData.get('h_align')?.toString() || '') as CommonBlockAlignment);
94+
cell.setBackgroundColor(formData.get('background_color')?.toString() || '');
9495

9596
const styles = cell.getStyles();
9697
styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
9798
styles.set('vertical-align', formData.get('v_align')?.toString() || '');
9899
styles.set('border-width', formatSizeValue(formData.get('border_width')?.toString() || ''));
99100
styles.set('border-style', formData.get('border_style')?.toString() || '');
100101
styles.set('border-color', formData.get('border_color')?.toString() || '');
101-
styles.set('background-color', formData.get('background_color')?.toString() || '');
102102

103103
cell.setStyles(styles);
104104
}

resources/js/wysiwyg/utils/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export function $clearTableFormatting(table: TableNode): void {
282282
const cells = row.getChildren().filter(c => $isTableCellNode(c));
283283
for (const cell of cells) {
284284
cell.setStyles(new Map);
285+
cell.setBackgroundColor(null);
285286
cell.clearWidth();
286287
}
287288
}

0 commit comments

Comments
 (0)