From b387faf2e356507f9027a20eae35e5cbb488d9c8 Mon Sep 17 00:00:00 2001 From: huanhuanwa <2323666215@qq.com> Date: Wed, 26 Jun 2024 11:37:50 +0800 Subject: [PATCH] fix(table): fix set text property error when select table --- .changeset/clean-bears-enjoy.md | 5 +++++ packages/draw/src/table.component.ts | 4 ++-- packages/draw/src/transforms/table-text.ts | 17 +++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 .changeset/clean-bears-enjoy.md diff --git a/.changeset/clean-bears-enjoy.md b/.changeset/clean-bears-enjoy.md new file mode 100644 index 000000000..56c71fdd7 --- /dev/null +++ b/.changeset/clean-bears-enjoy.md @@ -0,0 +1,5 @@ +--- +'@plait/draw': patch +--- + +fix set text property error when select table diff --git a/packages/draw/src/table.component.ts b/packages/draw/src/table.component.ts index f2c4323bc..e57101c40 100644 --- a/packages/draw/src/table.component.ts +++ b/packages/draw/src/table.component.ts @@ -117,9 +117,9 @@ export class TableComponent extends CommonElementFlavour { const height = data.height / this.board.viewport.zoom; - const width = data.width / this.board.viewport.zoom; + const path = PlaitBoard.findPath(this.board, value); if (data.newText) { - DrawTransforms.setTableText(this.board, value, text.key, data.newText, width, height); + DrawTransforms.setTableText(this.board, path, text.key, data.newText, height); } data.operations && memorizeLatestText(value, data.operations); }, diff --git a/packages/draw/src/transforms/table-text.ts b/packages/draw/src/transforms/table-text.ts index 57cc88974..7e906c41e 100644 --- a/packages/draw/src/transforms/table-text.ts +++ b/packages/draw/src/transforms/table-text.ts @@ -1,17 +1,11 @@ -import { PlaitBoard, RectangleClient, Transforms } from '@plait/core'; +import { Path, PlaitBoard, PlaitNode, RectangleClient, Transforms } from '@plait/core'; import { ShapeDefaultSpace } from '../constants'; import { Element } from 'slate'; -import { PlaitTable, PlaitTableCell, PlaitTableElement } from '../interfaces/table'; +import { PlaitBaseTable, PlaitTableCell, PlaitTableElement } from '../interfaces/table'; import { getCellWithPoints, updateColumns, updateRows } from '../utils/table'; -export const setTableText = ( - board: PlaitBoard, - table: PlaitTable, - cellId: string, - text: Element, - textWidth: number, - textHeight: number -) => { +export const setTableText = (board: PlaitBoard, path: Path, cellId: string, text: Element, textHeight: number) => { + const table = PlaitNode.get(board, path) as PlaitBaseTable; const cell = getCellWithPoints(board, table, cellId); const cellIndex = table.cells.findIndex(item => item.id === cell.id); let rows = [...table.rows]; @@ -47,6 +41,5 @@ export const setTableText = ( text }; - const path = board.children.findIndex(child => child.id === table.id); - Transforms.setNode(board, { rows, columns, cells, points }, [path]); + Transforms.setNode(board, { rows, columns, cells, points }, path); };