Skip to content

Commit

Permalink
fix(mind): Identify mind elements by the type of root node rather tha…
Browse files Browse the repository at this point in the history
…n the node properties

Handle the waring of drawing on element can not been identified
  • Loading branch information
pubuzhixing8 committed Jul 31, 2024
1 parent 9fb1a80 commit ed2f090
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/green-ladybugs-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@plait/core': patch
'@plait/mind': patch
---

Identify mind elements by the type of root node rather than the node properties

Handle the waring of drawing on element can not been identified
7 changes: 6 additions & 1 deletion packages/core/src/plugins/create-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { ThemeColorMode } from '../interfaces/theme';
import { CoreTransforms } from '../transforms/element';
import { ClipboardData, WritableClipboardContext, WritableClipboardOperationType, drawEntireActiveRectangleG } from '../utils';
import { Point, RectangleClient } from '../interfaces';
import { isDebug } from '../utils/debug';
import { ElementFlavour } from '../core/element/element-flavour';

export function createBoard(children: PlaitElement[], options?: PlaitBoardOptions): PlaitBoard {
const board: PlaitBoard = {
Expand Down Expand Up @@ -109,7 +111,10 @@ export function createBoard(children: PlaitElement[], options?: PlaitBoardOption
getDeletedFragment: (data: PlaitElement[]) => data,
getRelatedFragment: (data: PlaitElement[], originData?: PlaitElement[]) => data,
drawElement: (context: PlaitPluginElementContext) => {
throw new Error(`can not resolve plugin element component type: ${context.element.type}`);
if (isDebug()) {
console.error(`can not resolve plugin element: ${JSON.stringify(context.element)}`);
}
return ElementFlavour;
},
isWithinSelection: element => false,
isRectangleHit: element => false,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/utils/element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Ancestor, PlaitBoard, PlaitElement, Point, RectangleClient } from '../interfaces';
import { getSelectionAngle, hasSameAngle, getRotatedBoundingRectangle, rotatePointsByElement, getRectangleByAngle } from './angle';
import { isDebug } from './debug';
import { depthFirstRecursion, getIsRecursionFunc } from './tree';

export function getRectangleByElements(board: PlaitBoard, elements: PlaitElement[], recursion: boolean): RectangleClient {
Expand All @@ -11,7 +12,9 @@ export function getRectangleByElements(board: PlaitBoard, elements: PlaitElement
const rotatedCornerPoints = rotatePointsByElement(cornerPoints, node) || cornerPoints;
rectanglesCornerPoints.push(rotatedCornerPoints);
} else {
console.error(`can not get rectangle of element:`, node);
if (isDebug()) {
console.error(`can not get rectangle of element:`, node);
}
}
};
elements.forEach(element => {
Expand Down
3 changes: 2 additions & 1 deletion packages/mind/src/interfaces/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const MindElement = {
return isIndentedLayout(_layout);
},
isMindElement(board: PlaitBoard, element: PlaitElement): element is MindElement {
if (element.data && element.data.topic && element.width && element.height) {
const root = MindElement.getRoot(board, element as MindElement);
if (root && PlaitMind.isMind(root)) {
return true;
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/mind/src/plugins/with-mind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const withMind = (baseBoard: PlaitBoard) => {
board.getRectangle = element => {
if (MindElement.isMindElement(board, element)) {
if (!PlaitElement.hasMounted(element)) {
console.error('mind element has not been mounted');
console.error(`mind element has not been mounted: ${JSON.stringify(element)}`);
}
return getRectangleByNode(MindElement.getNode(element));
}
Expand Down

0 comments on commit ed2f090

Please sign in to comment.