Skip to content

Commit

Permalink
fix(table): fix set text property error when select table (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Jun 26, 2024
1 parent ec4e29e commit 2d8b964
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-bears-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/draw': patch
---

fix set text property error when select table
4 changes: 2 additions & 2 deletions packages/draw/src/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export class TableComponent<T extends PlaitTable> extends CommonElementFlavour<T
this.textGenerator = new TextGenerator(this.board, this.element, texts, {
onChange: (value: PlaitTable, data: TextManageChangeData, text: PlaitDrawShapeText) => {
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);
},
Expand Down
17 changes: 5 additions & 12 deletions packages/draw/src/transforms/table-text.ts
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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);
};

0 comments on commit 2d8b964

Please sign in to comment.