Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-table] Bug Fix: Change exported table column width #6243

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/lexical-table/src/LexicalTableCellNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ElementNode,
} from 'lexical';

import {PIXEL_VALUE_REG_EXP} from './constants';
import {COLUMN_WIDTH, PIXEL_VALUE_REG_EXP} from './constants';

export const TableCellHeaderStates = {
BOTH: 3,
Expand Down Expand Up @@ -152,18 +152,14 @@ export class TableCellNode extends ElementNode {

if (element) {
const element_ = element as HTMLTableCellElement;
const maxWidth = 700;
const colCount = this.getParentOrThrow().getChildrenSize();
element_.style.border = '1px solid black';
if (this.__colSpan > 1) {
element_.colSpan = this.__colSpan;
}
if (this.__rowSpan > 1) {
element_.rowSpan = this.__rowSpan;
}
element_.style.width = `${
this.getWidth() || Math.max(90, maxWidth / colCount)
}px`;
element_.style.width = `${this.getWidth() || COLUMN_WIDTH}px`;

element_.style.verticalAlign = 'top';
element_.style.textAlign = 'start';
Expand Down
4 changes: 4 additions & 0 deletions packages/lexical-table/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
*/

export const PIXEL_VALUE_REG_EXP = /^(\d+(?:\.\d+)?)px$/;

// .PlaygroundEditorTheme__tableCell width value from
// packages/lexical-playground/src/themes/PlaygroundEditorTheme.css
export const COLUMN_WIDTH = 75;
Loading