Skip to content

Commit a4aeab7

Browse files
authored
feat: fix lint errors (#1140)
1 parent faf8875 commit a4aeab7

147 files changed

Lines changed: 1173 additions & 1158 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/common/src/algorithms/a-star.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class AStar {
3030
if (currentPoint[0] === end[0] && currentPoint[1] === end[1]) {
3131
break;
3232
}
33-
current.node.adjacentNodes.forEach(next => {
33+
current.node.adjacentNodes.forEach((next) => {
3434
let newCost = costSoFar.get(current!.node)! + this.heuristic(next.data, current!.node.data);
3535
const previousNode = this.cameFrom.get(current!.node);
3636
// Inflection point weight, if an inflection point occurs, cost + 1 to avoid the inflection point path

packages/common/src/plugins/with-group.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ describe('with group plugin', () => {
149149
it('should remove the group if there is only one element left within after deletion', () => {
150150
addSelectedElement(board, [board.children[0]]);
151151
deleteFragment(board);
152-
const group = board.children.find(item => item.id === board.children[0].groupId);
152+
const group = board.children.find((item) => item.id === board.children[0].groupId);
153153
expect(group).toBe(undefined);
154154
});
155155

156156
it('should update element groupId if there is only one element left within after deletion', () => {
157157
addSelectedElement(board, [board.children[4]]);
158158
deleteFragment(board);
159-
const group = board.children.find(item => item.id === board.children[4].groupId);
159+
const group = board.children.find((item) => item.id === board.children[4].groupId);
160160
expect(group).toBe(undefined);
161161
expect(board.children[3].groupId).toBe(group2[group2.length - 1].id);
162162

packages/common/src/plugins/with-resize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const withResize = <T extends PlaitElementOrArray = PlaitElementOrArray,
5252
}
5353
startPoint = [event.x, event.y];
5454
const path = Array.isArray(resizeHitTestRef.element)
55-
? resizeHitTestRef.element.map(el => PlaitBoard.findPath(board, el))
55+
? resizeHitTestRef.element.map((el) => PlaitBoard.findPath(board, el))
5656
: PlaitBoard.findPath(board, resizeHitTestRef.element);
5757
resizeRef = {
5858
path,

packages/common/src/text/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { BaseElement } from 'slate';
22

3-
export type ElementSize = {
3+
export type ElementSize = {
44
width: number;
55
height: number;
6-
}
6+
};
77

88
export enum Alignment {
99
left = 'left',

packages/common/src/transforms/align.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const alignRight = (board: PlaitBoard) => {
6060
function setOffset(board: PlaitBoard, getOffset: (outerRectangle: RectangleClient, rectangle: RectangleClient) => Point) {
6161
const elements = getHighestSelectedElements(board);
6262
const outerRectangle = getRectangleByElements(board, elements, false);
63-
elements.forEach(element => {
63+
elements.forEach((element) => {
6464
if (!element.points && !PlaitGroupElement.isGroup(element)) return;
6565
const rectangle = board.getRectangle(element)!;
6666
const offset = getOffset(outerRectangle, rectangle);
@@ -70,8 +70,8 @@ function setOffset(board: PlaitBoard, getOffset: (outerRectangle: RectangleClien
7070
} else if (element.points) {
7171
updateElements = [element];
7272
}
73-
updateElements.forEach(item => {
74-
const newPoints = item.points!.map(p => [p[0] + offset[0], p[1] + offset[1]]) as Point[];
73+
updateElements.forEach((item) => {
74+
const newPoints = item.points!.map((p) => [p[0] + offset[0], p[1] + offset[1]]) as Point[];
7575
const path = PlaitBoard.findPath(board, item);
7676
Transforms.setNode(
7777
board,
@@ -98,14 +98,14 @@ const distribute = (board: PlaitBoard, isHorizontal: boolean) => {
9898
const axis = isHorizontal ? 'x' : 'y';
9999
const side = isHorizontal ? 'width' : 'height';
100100
const highestSelectedElements = getHighestSelectedElements(board);
101-
const refs = highestSelectedElements.map(element => {
101+
const refs = highestSelectedElements.map((element) => {
102102
return { element, rectangle: board.getRectangle(element)! };
103103
});
104104
const outerRectangle = getRectangleByElements(board, highestSelectedElements, false);
105105
const minRectangleRef = refs.sort((a, b) => a.rectangle[axis] - b.rectangle[axis])[0];
106106
const maxRectangleRef = refs.sort((a, b) => b.rectangle[axis] + b.rectangle[side] - (a.rectangle[axis] + a.rectangle[side]))[0];
107-
const minIndex = refs.findIndex(ref => ref === minRectangleRef);
108-
const maxIndex = refs.findIndex(ref => ref === maxRectangleRef);
107+
const minIndex = refs.findIndex((ref) => ref === minRectangleRef);
108+
const maxIndex = refs.findIndex((ref) => ref === maxRectangleRef);
109109
let distributeRefs = refs.filter((element, index) => index !== minIndex && index !== maxIndex);
110110
const sum = distributeRefs.reduce((accumulator, current) => current.rectangle[side] + accumulator, 0);
111111
const offset =
@@ -118,7 +118,7 @@ const distribute = (board: PlaitBoard, isHorizontal: boolean) => {
118118
const moveAxis = isHorizontal ? 0 : 1;
119119
moveOffset[moveAxis] = position - rectangle[axis];
120120
const path = PlaitBoard.findPath(board, distributeRefs[i].element);
121-
const newPoints = distributeRefs[i].element.points!.map(p => [p[0] + moveOffset[0], p[1] + moveOffset[1]]) as Point[];
121+
const newPoints = distributeRefs[i].element.points!.map((p) => [p[0] + moveOffset[0], p[1] + moveOffset[1]]) as Point[];
122122
Transforms.setNode(
123123
board,
124124
{

packages/common/src/transforms/property.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface SetOptions<T extends PlaitElement = PlaitElement> {
99

1010
export const setProperty = <T extends PlaitElement = PlaitElement>(board: PlaitBoard, properties: Partial<T>, options?: SetOptions<T>) => {
1111
const selectedElements = getSelectedElements(board) as T[];
12-
selectedElements.forEach(element => {
12+
selectedElements.forEach((element) => {
1313
if (options?.match && !options?.match(element)) return;
1414
const path = PlaitBoard.findPath(board, element);
1515
const memorizeKey = options?.getMemorizeKey ? options?.getMemorizeKey(element) : '';

packages/common/src/utils/clipboard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export const buildClipboardData = (
66
startPoint: Point,
77
elementBuilder?: (element: PlaitElement) => PlaitElement | undefined
88
) => {
9-
return elements.map(element => {
9+
return elements.map((element) => {
1010
const newElement = elementBuilder && elementBuilder(element);
1111
if (newElement) {
1212
return newElement;
1313
}
1414
if (element.points) {
15-
const points = element.points.map(point => [point[0] - startPoint[0], point[1] - startPoint[1]]);
15+
const points = element.points.map((point) => [point[0] - startPoint[0], point[1] - startPoint[1]]);
1616
return { ...element, points };
1717
}
1818
return element;
@@ -26,14 +26,14 @@ export const insertClipboardData = (
2626
elementHandler?: (element: PlaitElement, idsMap: Record<string, string>) => void
2727
) => {
2828
const idsMap: Record<string, string> = {};
29-
elements.forEach(element => {
29+
elements.forEach((element) => {
3030
idsMap[element.id] = idCreator();
3131
});
32-
elements.forEach(element => {
32+
elements.forEach((element) => {
3333
element.id = idsMap[element.id];
3434
elementHandler && elementHandler(element, idsMap);
3535
if (element.points) {
36-
element.points = element.points.map(point => [startPoint[0] + point[0], startPoint[1] + point[1]]) as [Point, Point];
36+
element.points = element.points.map((point) => [startPoint[0] + point[0], startPoint[1] + point[1]]) as [Point, Point];
3737
}
3838
Transforms.insertNode(board, element, [board.children.length]);
3939
});

packages/common/src/utils/default-orthogonal-routing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Credits to xyflow
22
// https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/edges/smoothstep-edge.ts
33

4-
import { Direction, Point } from "@plait/core";
5-
import { getDirectionFactor } from "./direction";
4+
import { Direction, Point } from '@plait/core';
5+
import { getDirectionFactor } from './direction';
66

77
export const getPoints = (source: Point, sourcePosition: Direction, target: Point, targetPosition: Direction, offset: number) => {
88
const sourceDirectionFactors = getDirectionFactor(sourcePosition);
@@ -99,4 +99,4 @@ function getEdgeCenter({
9999
const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset;
100100

101101
return [centerX, centerY, xOffset, yOffset];
102-
}
102+
}

packages/common/src/utils/elbow-line-route.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export const generateElbowLineRoute = (options: ElbowLineRouteOptions, board?: P
4848
const isHitY = RectangleClient.isHitY(options.sourceOuterRectangle, options.targetOuterRectangle);
4949
const centerX = isHitX ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, true);
5050
const centerY = isHitY ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, false);
51-
route = routeAdjust(route, { centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle }, board);
51+
route = routeAdjust(
52+
route,
53+
{ centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle },
54+
board
55+
);
5256
return route;
5357
};
5458

@@ -61,7 +65,11 @@ export const routeAdjust = (path: Point[], options: RouteAdjustOptions, board?:
6165
const optionsX = getAdjustOptions(path, centerX, true);
6266
const resultX =
6367
optionsX.pointOfHit &&
64-
adjust(path, { parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle }, board);
68+
adjust(
69+
path,
70+
{ parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle },
71+
board
72+
);
6573
if (resultX) {
6674
path = resultX;
6775
}
@@ -70,7 +78,11 @@ export const routeAdjust = (path: Point[], options: RouteAdjustOptions, board?:
7078
const optionsY = getAdjustOptions(path, centerY, false);
7179
const resultY =
7280
optionsY.pointOfHit &&
73-
adjust(path, { parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle }, board);
81+
adjust(
82+
path,
83+
{ parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle },
84+
board
85+
);
7486
if (resultY) {
7587
path = resultY;
7688
}
@@ -81,7 +93,7 @@ export const routeAdjust = (path: Point[], options: RouteAdjustOptions, board?:
8193
const adjust = (route: Point[], options: AdjustOptions, board?: PlaitBoard): null | Point[] => {
8294
const { parallelPaths, pointOfHit, sourceRectangle, targetRectangle } = options;
8395
let result = null;
84-
parallelPaths.forEach(parallelPath => {
96+
parallelPaths.forEach((parallelPath) => {
8597
// Construct a rectangle
8698
const tempRectPoints = [pointOfHit, parallelPath[0], parallelPath[1]];
8799
// directly use getCornerPoints will bring the precision issue (eg: 263.6923375175286 - 57.130859375)
@@ -94,7 +106,7 @@ const adjust = (route: Point[], options: AdjustOptions, board?: PlaitBoard): nul
94106
const indexRangeInPath: number[] = [];
95107
const indexRangeInCorner: number[] = [];
96108
route.forEach((point, index) => {
97-
const cornerResult = tempCorners.findIndex(corner => Point.isEquals(point, corner));
109+
const cornerResult = tempCorners.findIndex((corner) => Point.isEquals(point, corner));
98110
if (cornerResult !== -1) {
99111
indexRangeInPath.push(index);
100112
indexRangeInCorner.push(cornerResult);
@@ -153,7 +165,7 @@ export const getGraphPoints = (options: ElbowLineRouteOptions) => {
153165
const y: number[] = [];
154166
let result: Point[] = [];
155167

156-
[sourceOuterRectangle, targetOuterRectangle].forEach(rectangle => {
168+
[sourceOuterRectangle, targetOuterRectangle].forEach((rectangle) => {
157169
x.push(rectangle.x, rectangle.x + rectangle.width / 2, rectangle.x + rectangle.width);
158170
y.push(rectangle.y, rectangle.y + rectangle.height / 2, rectangle.y + rectangle.height);
159171
});
@@ -181,7 +193,7 @@ export const getGraphPoints = (options: ElbowLineRouteOptions) => {
181193
}
182194
}
183195
}
184-
result = removeDuplicatePoints(result).filter(point => {
196+
result = removeDuplicatePoints(result).filter((point) => {
185197
const isInSource = RectangleClient.isPointInRectangle(sourceOuterRectangle, point);
186198
const isInTarget = RectangleClient.isPointInRectangle(targetOuterRectangle, point);
187199
return !isInSource && !isInTarget;
@@ -193,7 +205,7 @@ export const createGraph = (points: Point[]) => {
193205
const graph = new PointGraph();
194206
const Xs: number[] = [];
195207
const Ys: number[] = [];
196-
points.forEach(p => {
208+
points.forEach((p) => {
197209
const x = p[0],
198210
y = p[1];
199211
if (Xs.indexOf(x) < 0) Xs.push(x);

packages/common/src/utils/image.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function getImageSize(file: File, defaultImageWidth: number): Promise<{ width: n
5353
const image = new Image();
5454
image.src = URL.createObjectURL(file);
5555

56-
image.onload = function() {
56+
image.onload = function () {
5757
const width = defaultImageWidth;
5858
const height = (defaultImageWidth * image.naturalHeight) / image.naturalWidth;
5959
resolve(

0 commit comments

Comments
 (0)