Skip to content

Commit

Permalink
fix(draw): fixed the problem of table-bound lines paste failure #WIK-…
Browse files Browse the repository at this point in the history
…15700 (#909)
  • Loading branch information
huanhuanwa authored Jun 5, 2024
1 parent bc57da6 commit ba2c21b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-donuts-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/draw': patch
---

fixed the problem of table-bound lines paste failure
46 changes: 25 additions & 21 deletions packages/draw/src/utils/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlaitBoard, Point, Transforms, getElementById, idCreator } from '@plait/core';
import { PlaitDrawElement, PlaitGeometry, PlaitLine } from '../interfaces';
import { PlaitDrawElement, PlaitGeometry, PlaitLine, PlaitShapeElement } from '../interfaces';
import { PlaitImage } from '../interfaces/image';
import { getConnectionPoint } from './line/line-common';
import { PlaitTable } from '../interfaces/table';
Expand Down Expand Up @@ -45,43 +45,47 @@ export const insertClipboardData = (board: PlaitBoard, elements: PlaitDrawElemen
value => (PlaitDrawElement.isGeometry(value) && !PlaitDrawElement.isGeometryByTable(value)) || PlaitDrawElement.isImage(value)
) as (PlaitImage | PlaitGeometry)[];
const tables = elements.filter(value => PlaitDrawElement.isElementByTable(value)) as PlaitTable[];

geometries.forEach(element => {
const sourceLines: PlaitLine[] = [];
const targetLines: PlaitLine[] = [];
lines.forEach(line => {
if (PlaitLine.isBoundElementOfSource(line, element)) {
sourceLines.push(line);
}
if (PlaitLine.isBoundElementOfTarget(line, element)) {
targetLines.push(line);
}
});
element.id = idCreator();

// update lines
sourceLines.forEach(sourceLine => (sourceLine.source.boundId = element.id));
targetLines.forEach(targetLine => (targetLine.target.boundId = element.id));

const newId = idCreator();
updateBoundLinesId(element, lines, newId);
element.id = newId;
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]) as [Point, Point];
Transforms.insertNode(board, element, [board.children.length]);
});
insertClipboardTableData(board, tables, startPoint, lines);
lines.forEach(element => {
element.id = idCreator();
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]) as [Point, Point];
Transforms.insertNode(board, element, [board.children.length]);
});
insertClipboardTableData(board, tables, startPoint);
Transforms.addSelectionWithTemporaryElements(board, elements);
};

export const insertClipboardTableData = (board: PlaitBoard, elements: PlaitTable[], startPoint: Point) => {
export const insertClipboardTableData = (board: PlaitBoard, elements: PlaitTable[], startPoint: Point, lines: PlaitLine[]) => {
elements.forEach(element => {
element.id = idCreator();
const newId = idCreator();
updateBoundLinesId(element, lines, newId);
element.id = newId;
updateRowOrColumnIds(element, 'row');
updateRowOrColumnIds(element, 'column');
updateCellIds(element.cells);
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]) as [Point, Point];
Transforms.insertNode(board, element, [board.children.length]);
});
};

export const updateBoundLinesId = (element: PlaitShapeElement, lines: PlaitLine[], newId: string) => {
const sourceLines: PlaitLine[] = [];
const targetLines: PlaitLine[] = [];
lines.forEach(line => {
if (PlaitLine.isBoundElementOfSource(line, element)) {
sourceLines.push(line);
}
if (PlaitLine.isBoundElementOfTarget(line, element)) {
targetLines.push(line);
}
});
// update lines
sourceLines.forEach(sourceLine => (sourceLine.source.boundId = newId));
targetLines.forEach(targetLine => (targetLine.target.boundId = newId));
};

0 comments on commit ba2c21b

Please sign in to comment.