Skip to content

Commit

Permalink
refactor(draw): rename method name for closed element (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 authored Dec 12, 2024
1 parent d377424 commit 9ce99ca
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/gorgeous-seas-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@plait/draw': patch
---

rename isDrawElementClosed to isClosedDrawElement and add isDrawElement condition
rename isCustomGeometryClosed to isClosedCustomGeometry
29 changes: 15 additions & 14 deletions packages/draw/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,23 @@ export const isDrawElementsIncludeText = (elements: PlaitDrawElement[]) => {
});
};

export const isDrawElementClosed = (element: PlaitDrawElement) => {
if (PlaitDrawElement.isText(element) || PlaitDrawElement.isArrowLine(element) || PlaitDrawElement.isImage(element)) {
return false;
}

if (PlaitDrawElement.isVectorLine(element)) {
return isClosedPoints(element.points);
}

if (PlaitDrawElement.isGeometry(element)) {
return isGeometryClosed(element);
export const isClosedDrawElement = (element: PlaitElement) => {
if (PlaitDrawElement.isDrawElement(element)) {
if (PlaitDrawElement.isText(element) || PlaitDrawElement.isArrowLine(element) || PlaitDrawElement.isImage(element)) {
return false;
}
if (PlaitDrawElement.isVectorLine(element)) {
return isClosedPoints(element.points);
}
if (PlaitDrawElement.isGeometry(element)) {
return isGeometryClosed(element);
}
return true;
}
return true;
return false;
};

export const isCustomGeometryClosed = (board: PlaitBoard, value: PlaitElement): value is PlaitCustomGeometry => {
export const isClosedCustomGeometry = (board: PlaitBoard, value: PlaitElement): value is PlaitCustomGeometry => {
return PlaitDrawElement.isCustomGeometryElement(board, value) && isClosedPoints(value.points);
};

Expand Down Expand Up @@ -203,7 +204,7 @@ export const drawBoundReaction = (
{
stroke: SELECTION_BORDER_COLOR,
strokeWidth: 0,
fill: isDrawElementClosed(element) ? SELECTION_FILL_COLOR : DefaultDrawStyle.fill,
fill: isClosedDrawElement(element) ? SELECTION_FILL_COLOR : DefaultDrawStyle.fill,
fillStyle: 'solid'
},
drawOptions
Expand Down
4 changes: 2 additions & 2 deletions packages/draw/src/utils/hit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getFillByElement } from './style/stroke';
import { getEngine } from '../engines';
import { getElementShape } from './shape';
import { getHitArrowLineTextIndex } from './position/arrow-line';
import { getTextRectangle, isClosedPoints, isCustomGeometryClosed, isDrawElementClosed } from './common';
import { getTextRectangle, isClosedCustomGeometry, isClosedDrawElement, isClosedPoints } from './common';
import { isMultipleTextGeometry } from './multi-text-geometry';
import { isFilled, sortElementsByArea } from '@plait/common';
import { getVectorLinePoints } from './vector-line';
Expand Down Expand Up @@ -153,7 +153,7 @@ export const getFirstFilledDrawElement = (board: PlaitBoard, elements: (PlaitDra
let filledElement: PlaitGeometry | PlaitCustomGeometry | null = null;
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
if (isCustomGeometryClosed(board, element) || isDrawElementClosed(element)) {
if (isClosedCustomGeometry(board, element) || isClosedDrawElement(element)) {
const fill = getFillByElement(board, element);
if (isFilled(fill)) {
filledElement = element as PlaitGeometry;
Expand Down
4 changes: 2 additions & 2 deletions packages/draw/src/utils/style/stroke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlaitDrawElement } from '../../interfaces';
import { DefaultDrawStyle } from '../../constants';
import { PlaitBoard, PlaitElement } from '@plait/core';
import { getDrawDefaultStrokeColor, getFlowchartDefaultFill } from '../geometry';
import { isCustomGeometryClosed, isDrawElementClosed } from '../common';
import { isClosedDrawElement } from '../common';
import { StrokeStyle } from '@plait/common';

export const getStrokeColorByElement = (board: PlaitBoard, element: PlaitElement) => {
Expand All @@ -13,7 +13,7 @@ export const getStrokeColorByElement = (board: PlaitBoard, element: PlaitElement

export const getFillByElement = (board: PlaitBoard, element: PlaitElement) => {
const defaultFill =
PlaitDrawElement.isFlowchart(element) && isDrawElementClosed(element as PlaitDrawElement)
PlaitDrawElement.isFlowchart(element) && isClosedDrawElement(element as PlaitDrawElement)
? getFlowchartDefaultFill(board.theme.themeColorMode)
: DefaultDrawStyle.fill;
const fill = element.fill || defaultFill;
Expand Down
9 changes: 3 additions & 6 deletions src/app/components/setting-panel/setting-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Path,
DEFAULT_COLOR
} from '@plait/core';

import {
MindElement,
MindPointerType,
Expand Down Expand Up @@ -55,11 +54,9 @@ import {
getGeometryAlign,
PlaitDrawElement,
getSwimlaneCount,
PlaitTableCell,
getSelectedTableCellsEditor,
isSingleSelectElementByTable,
VectorLineShape,
isDrawElementClosed
isClosedDrawElement
} from '@plait/draw';
import { MindLayoutType } from '@plait/layouts';
import { FontSizes, LinkEditor, MarkTypes, PlaitMarkEditor, TextTransforms } from '@plait/text-plugins';
Expand Down Expand Up @@ -154,7 +151,7 @@ export class AppSettingPanelComponent extends PlaitIslandBaseComponent implement
this.isSelectedLine = !!selectedArrowLineElements.length || !!selectedVectorLineElements.length;
this.isSelectedVectorLine = !!selectedVectorLineElements.length;
this.isSelectSwimlane = isSingleSelectSwimlane(this.board);
this.enableSetFillColor = selectedDrawElements.some(item => isDrawElementClosed(item));
this.enableSetFillColor = selectedDrawElements.some(item => isClosedDrawElement(item));
if (this.isSelectSwimlane) {
this.swimlaneCount = getSwimlaneCount(getSelectedElements(this.board)[0] as PlaitSwimlane);
}
Expand Down Expand Up @@ -257,7 +254,7 @@ export class AppSettingPanelComponent extends PlaitIslandBaseComponent implement
if (tableElement) {
DrawTransforms.setTableFill(this.board, element, property, path);
} else {
if (isDrawElementClosed(element as PlaitDrawElement)) {
if (isClosedDrawElement(element as PlaitDrawElement)) {
Transforms.setNode(this.board, { fill: property }, path);
}
}
Expand Down

0 comments on commit 9ce99ca

Please sign in to comment.