Skip to content

Commit 74d4855

Browse files
committed
feat(): 拓扑图支持快捷键shift快速选择和取消选择多个元素,原框选功能需要支持选中边
Closes CMDB_VIEW-314
1 parent 3c328cf commit 74d4855

File tree

13 files changed

+145
-53
lines changed

13 files changed

+145
-53
lines changed

bricks/diagram/src/draw-canvas/CellComponent.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
NodeBrickConf,
1414
NodeCell,
1515
EditableLine,
16+
BaseEdgeCell,
1617
} from "./interfaces";
1718
import {
1819
isContainerDecoratorCell,
@@ -51,6 +52,9 @@ export interface CellComponentProps {
5152
unrelatedCells: Cell[];
5253
dragNodeToContainerActive?: boolean;
5354
allowEdgeToArea?: boolean;
55+
updateCurActiveEditableEdge?: (
56+
activeEditableEdge: BaseEdgeCell | null
57+
) => void;
5458
onCellsMoving?(info: MoveCellPayload[]): void;
5559
onCellsMoved?(info: MoveCellPayload[]): void;
5660
onCellResizing?(info: ResizeCellPayload): void;
@@ -82,6 +86,7 @@ export function CellComponent({
8286
hoverCell,
8387
unrelatedCells,
8488
allowEdgeToArea,
89+
updateCurActiveEditableEdge,
8590
onCellsMoving,
8691
onCellsMoved,
8792
onCellResizing,
@@ -96,7 +101,7 @@ export function CellComponent({
96101
onCellMouseLeave,
97102
}: CellComponentProps): JSX.Element | null {
98103
const {
99-
activeEditableEdge,
104+
activeEditableEdges,
100105
lineEditorState,
101106
smartConnectLineState,
102107
setSmartConnectLineState,
@@ -109,6 +114,15 @@ export function CellComponent({
109114
() => unrelatedCells.some((item) => sameTarget(item, cell)),
110115
[cell, unrelatedCells]
111116
);
117+
const activeEditableEdge = useMemo(
118+
() =>
119+
cell.type === "edge"
120+
? activeEditableEdges.find(
121+
(edge) => edge.source === cell.source && edge.target === cell.target
122+
)
123+
: null,
124+
[cell, activeEditableEdges]
125+
);
112126
// `containerRect` is undefined when it's an edge cell.
113127
const containerRect = useMemo((): DecoratorView | undefined => {
114128
if (isContainerDecoratorCell(cell) && isNoManualLayout(layout)) {
@@ -196,7 +210,9 @@ export function CellComponent({
196210
);
197211
}
198212
setSmartConnectLineState(null);
199-
} else if (activeEditableEdge && lineEditorState) {
213+
} else if (!activeEditableEdge) {
214+
updateCurActiveEditableEdge?.(null);
215+
} else if (lineEditorState) {
200216
const { type } = lineEditorState;
201217
const { source, target } = editableLineMap.get(activeEditableEdge)!;
202218
const { view } = activeEditableEdge;
@@ -276,7 +292,6 @@ export function CellComponent({
276292
}, [cell, onCellMouseLeave]);
277293

278294
const active = targetIsActive(cell, activeTarget);
279-
280295
return (
281296
<g
282297
className={classNames("cell", {

bricks/diagram/src/draw-canvas/EdgeComponent.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,18 @@ export function EdgeComponent({
139139
if (element) {
140140
// Jest does not support `SVGPathElement::getTotalLength`
141141
setPathLength(element.getTotalLength?.() ?? 100);
142+
const rect = element.getBBox?.();
143+
edge.view = {
144+
...edge.view,
145+
x: rect?.x,
146+
y: rect?.y,
147+
width: rect?.width,
148+
height: rect?.height,
149+
};
142150
}
143151
updateLabelPosition();
144152
},
145-
[updateLabelPosition]
153+
[updateLabelPosition, edge]
146154
);
147155

148156
const [labelElement, setLabelElement] = useState<HTMLElement | null>(null);

bricks/diagram/src/draw-canvas/EditingLineComponent.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,21 @@ export interface EditingLineComponentProps {
2626
editableLineMap: WeakMap<EdgeCell, EditableLine>;
2727
transform: TransformLiteral;
2828
options: ComputedLineConnecterConf;
29+
activeEditableEdge: EdgeCell | null;
2930
}
3031

3132
export function EditingLineComponent({
3233
cells,
3334
editableLineMap,
3435
transform,
3536
options,
37+
activeEditableEdge,
3638
}: EditingLineComponentProps): JSX.Element {
3739
const [connectLineTo, setConnectLineTo] = useState<PositionTuple | null>(
3840
null
3941
);
40-
const {
41-
activeEditableEdge,
42-
hoverState,
43-
lineEditorState,
44-
setLineEditorState,
45-
onChangeEdgeView,
46-
} = useHoverStateContext();
42+
const { hoverState, lineEditorState, setLineEditorState, onChangeEdgeView } =
43+
useHoverStateContext();
4744
const movedRef = useRef(false);
4845

4946
useEffect(() => {

bricks/diagram/src/draw-canvas/HoverStateContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const HoverStateContext = React.createContext<{
2323
smartConnectLineState: SmartConnectLineState | null;
2424
unsetHoverStateTimeoutRef: React.MutableRefObject<number | null>;
2525
hoverState: HoverState | null;
26-
activeEditableEdge: EdgeCell | null;
26+
activeEditableEdges: EdgeCell[];
2727
lineEditorState: LineEditorState | null;
2828
setLineEditorState: React.Dispatch<
2929
React.SetStateAction<LineEditorState | null>
@@ -48,7 +48,7 @@ export const HoverStateContext = React.createContext<{
4848
smartConnectLineState: null,
4949
unsetHoverStateTimeoutRef: { current: null },
5050
hoverState: null,
51-
activeEditableEdge: null,
51+
activeEditableEdges: [],
5252
lineEditorState: null,
5353
setLineEditorState: () => {},
5454
setHoverState: () => {},

bricks/diagram/src/draw-canvas/LineConnectorComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@ export interface LineConnectorComponentProps {
2222
activeTarget: ActiveTarget | null;
2323
editableLineMap: WeakMap<EdgeCell, EditableLine>;
2424
scale: number;
25+
activeEditableEdge: EdgeCell | null;
2526
disabled?: boolean;
2627
}
2728

2829
export function LineConnectorComponent({
2930
activeTarget,
3031
editableLineMap,
3132
scale,
33+
activeEditableEdge,
3234
disabled,
3335
}: LineConnectorComponentProps): JSX.Element | null {
3436
const {
3537
unsetHoverStateTimeoutRef,
3638
hoverState,
3739
setHoverState,
3840
smartConnectLineState,
39-
activeEditableEdge,
4041
lineEditorState,
4142
} = useHoverStateContext();
4243

@@ -112,6 +113,7 @@ export function LineConnectorComponent({
112113
index={index}
113114
point={point}
114115
scale={scale}
116+
activeEditableEdge={activeEditableEdge}
115117
unsetActivePointIndex={unsetActivePointIndex}
116118
unsetTimeout={unsetTimeout}
117119
/>
@@ -127,6 +129,7 @@ interface ConnectPointComponentProps {
127129
index: number;
128130
point: NodePosition;
129131
scale: number;
132+
activeEditableEdge: EdgeCell | null;
130133
unsetTimeout: () => void;
131134
unsetActivePointIndex: () => void;
132135
}
@@ -136,6 +139,7 @@ function ConnectPointComponent({
136139
index,
137140
point,
138141
scale,
142+
activeEditableEdge,
139143
unsetTimeout,
140144
unsetActivePointIndex,
141145
}: ConnectPointComponentProps): JSX.Element {
@@ -146,7 +150,6 @@ function ConnectPointComponent({
146150
setHoverState,
147151
setSmartConnectLineState,
148152
onConnect,
149-
activeEditableEdge,
150153
lineEditorState,
151154
setLineEditorState,
152155
onChangeEdgeView,

bricks/diagram/src/draw-canvas/LineEditorComponent.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
import React, { useEffect, useMemo, useRef } from "react";
33
import type { NodePosition } from "../diagram/interfaces";
44
import { useHoverStateContext } from "./HoverStateContext";
5-
import type { ControlPoint, EdgeCell, EditableLine } from "./interfaces";
5+
import type {
6+
BaseEdgeCell,
7+
ControlPoint,
8+
EdgeCell,
9+
EditableLine,
10+
} from "./interfaces";
611
import { isStraightType } from "./processors/asserts";
712

813
const POINT_HELPER_IMAGE =
@@ -16,18 +21,22 @@ const POINT_HELPER_BG_SIZE = 22;
1621
export interface LineEditorComponentProps {
1722
scale: number;
1823
editableLineMap: WeakMap<EdgeCell, EditableLine>;
24+
activeEditableEdge: EdgeCell;
25+
updateCurActiveEditableEdge?: (
26+
activeEditableEdge: BaseEdgeCell | null
27+
) => void;
1928
}
2029

2130
export function LineEditorComponent({
2231
scale,
2332
editableLineMap,
33+
activeEditableEdge,
34+
updateCurActiveEditableEdge,
2435
}: LineEditorComponentProps): JSX.Element | null {
25-
const { rootRef, activeEditableEdge, setLineEditorState } =
26-
useHoverStateContext();
36+
const { rootRef, setLineEditorState } = useHoverStateContext();
2737
const exitRef = useRef<SVGImageElement>(null);
2838
const entryRef = useRef<SVGImageElement>(null);
2939
const controlPointsRef = useRef<(SVGImageElement | null)[]>([]);
30-
3140
useEffect(() => {
3241
const exit = exitRef.current;
3342
const entry = entryRef.current;
@@ -44,6 +53,7 @@ export function LineEditorComponent({
4453
from: [e.clientX, e.clientY],
4554
type,
4655
});
56+
updateCurActiveEditableEdge?.(activeEditableEdge);
4757
};
4858
};
4959
const handleStartMouseDown = handleMouseDownFactory("exit");
@@ -61,7 +71,6 @@ export function LineEditorComponent({
6171
? getControlPoints(editableLineMap.get(activeEditableEdge)!.points!)
6272
: [];
6373
}, [activeEditableEdge, editableLineMap]);
64-
6574
useEffect(() => {
6675
if (!activeEditableEdge) {
6776
return;

0 commit comments

Comments
 (0)