mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-27 06:01:54 +03:00
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.
This commit is contained in:
@ -353,10 +353,17 @@ export function $convertTableCellNodeElement(
|
|||||||
const hasUnderlineTextDecoration = textDecoration.includes('underline');
|
const hasUnderlineTextDecoration = textDecoration.includes('underline');
|
||||||
|
|
||||||
if (domNode instanceof HTMLElement) {
|
if (domNode instanceof HTMLElement) {
|
||||||
tableCellNode.setStyles(extractStyleMapFromElement(domNode));
|
const styleMap = extractStyleMapFromElement(domNode);
|
||||||
|
styleMap.delete('background-color');
|
||||||
|
tableCellNode.setStyles(styleMap);
|
||||||
tableCellNode.setAlignment(extractAlignmentFromElement(domNode));
|
tableCellNode.setAlignment(extractAlignmentFromElement(domNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const background = style.backgroundColor || null;
|
||||||
|
if (background) {
|
||||||
|
tableCellNode.setBackgroundColor(background);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
after: (childLexicalNodes) => {
|
after: (childLexicalNodes) => {
|
||||||
if (childLexicalNodes.length === 0) {
|
if (childLexicalNodes.length === 0) {
|
||||||
|
@ -13,14 +13,16 @@ import {$showLinkForm} from "../ui/defaults/forms/objects";
|
|||||||
import {showLinkSelector} from "../utils/links";
|
import {showLinkSelector} from "../utils/links";
|
||||||
import {HeadingTagType} from "@lexical/rich-text/LexicalHeadingNode";
|
import {HeadingTagType} from "@lexical/rich-text/LexicalHeadingNode";
|
||||||
|
|
||||||
function headerHandler(editor: LexicalEditor, tag: HeadingTagType): boolean {
|
function headerHandler(context: EditorUiContext, tag: HeadingTagType): boolean {
|
||||||
toggleSelectionAsHeading(editor, tag);
|
toggleSelectionAsHeading(context.editor, tag);
|
||||||
|
context.manager.triggerFutureStateRefresh();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapFormatAction(formatAction: (editor: LexicalEditor) => any): ShortcutAction {
|
function wrapFormatAction(formatAction: (editor: LexicalEditor) => any): ShortcutAction {
|
||||||
return (editor: LexicalEditor) => {
|
return (editor: LexicalEditor, context: EditorUiContext) => {
|
||||||
formatAction(editor);
|
formatAction(editor);
|
||||||
|
context.manager.triggerFutureStateRefresh();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -45,10 +47,10 @@ const actionsByKeys: Record<string, ShortcutAction> = {
|
|||||||
window.$events.emit('editor-save-page');
|
window.$events.emit('editor-save-page');
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'meta+1': (editor) => headerHandler(editor, 'h1'),
|
'meta+1': (editor, context) => headerHandler(context, 'h2'),
|
||||||
'meta+2': (editor) => headerHandler(editor, 'h2'),
|
'meta+2': (editor, context) => headerHandler(context, 'h3'),
|
||||||
'meta+3': (editor) => headerHandler(editor, 'h3'),
|
'meta+3': (editor, context) => headerHandler(context, 'h4'),
|
||||||
'meta+4': (editor) => headerHandler(editor, 'h4'),
|
'meta+4': (editor, context) => headerHandler(context, 'h5'),
|
||||||
'meta+5': wrapFormatAction(toggleSelectionAsParagraph),
|
'meta+5': wrapFormatAction(toggleSelectionAsParagraph),
|
||||||
'meta+d': wrapFormatAction(toggleSelectionAsParagraph),
|
'meta+d': wrapFormatAction(toggleSelectionAsParagraph),
|
||||||
'meta+6': wrapFormatAction(toggleSelectionAsBlockquote),
|
'meta+6': wrapFormatAction(toggleSelectionAsBlockquote),
|
||||||
|
@ -13,7 +13,6 @@ import codeIcon from "@icons/editor/code.svg";
|
|||||||
import formatClearIcon from "@icons/editor/format-clear.svg";
|
import formatClearIcon from "@icons/editor/format-clear.svg";
|
||||||
import {$selectionContainsTextFormat} from "../../../utils/selection";
|
import {$selectionContainsTextFormat} from "../../../utils/selection";
|
||||||
import {$patchStyleText} from "@lexical/selection";
|
import {$patchStyleText} from "@lexical/selection";
|
||||||
import {context} from "esbuild";
|
|
||||||
|
|
||||||
function buildFormatButton(label: string, format: TextFormatType, icon: string): EditorButtonDefinition {
|
function buildFormatButton(label: string, format: TextFormatType, icon: string): EditorButtonDefinition {
|
||||||
return {
|
return {
|
||||||
|
@ -75,7 +75,7 @@ export function $showCellPropertiesForm(cell: TableCellNode, context: EditorUiCo
|
|||||||
border_width: styles.get('border-width') || '',
|
border_width: styles.get('border-width') || '',
|
||||||
border_style: styles.get('border-style') || '',
|
border_style: styles.get('border-style') || '',
|
||||||
border_color: styles.get('border-color') || '',
|
border_color: styles.get('border-color') || '',
|
||||||
background_color: styles.get('background-color') || '',
|
background_color: cell.getBackgroundColor() || styles.get('background-color') || '',
|
||||||
});
|
});
|
||||||
return modalForm;
|
return modalForm;
|
||||||
}
|
}
|
||||||
@ -91,6 +91,7 @@ export const cellProperties: EditorFormDefinition = {
|
|||||||
$setTableCellColumnWidth(cell, width);
|
$setTableCellColumnWidth(cell, width);
|
||||||
cell.updateTag(formData.get('type')?.toString() || '');
|
cell.updateTag(formData.get('type')?.toString() || '');
|
||||||
cell.setAlignment((formData.get('h_align')?.toString() || '') as CommonBlockAlignment);
|
cell.setAlignment((formData.get('h_align')?.toString() || '') as CommonBlockAlignment);
|
||||||
|
cell.setBackgroundColor(formData.get('background_color')?.toString() || '');
|
||||||
|
|
||||||
const styles = cell.getStyles();
|
const styles = cell.getStyles();
|
||||||
styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
|
styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
|
||||||
@ -98,7 +99,6 @@ export const cellProperties: EditorFormDefinition = {
|
|||||||
styles.set('border-width', formatSizeValue(formData.get('border_width')?.toString() || ''));
|
styles.set('border-width', formatSizeValue(formData.get('border_width')?.toString() || ''));
|
||||||
styles.set('border-style', formData.get('border_style')?.toString() || '');
|
styles.set('border-style', formData.get('border_style')?.toString() || '');
|
||||||
styles.set('border-color', formData.get('border_color')?.toString() || '');
|
styles.set('border-color', formData.get('border_color')?.toString() || '');
|
||||||
styles.set('background-color', formData.get('background_color')?.toString() || '');
|
|
||||||
|
|
||||||
cell.setStyles(styles);
|
cell.setStyles(styles);
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,7 @@ export function $clearTableFormatting(table: TableNode): void {
|
|||||||
const cells = row.getChildren().filter(c => $isTableCellNode(c));
|
const cells = row.getChildren().filter(c => $isTableCellNode(c));
|
||||||
for (const cell of cells) {
|
for (const cell of cells) {
|
||||||
cell.setStyles(new Map);
|
cell.setStyles(new Map);
|
||||||
|
cell.setBackgroundColor(null);
|
||||||
cell.clearWidth();
|
cell.clearWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user