Skip to content

Commit ebe778f

Browse files
authored
Merge pull request #9 from yhlchao/master
feat(core): support open text edit by double click anchor
2 parents 5c28e43 + 7a30f23 commit ebe778f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

packages/core/src/constant/constant.ts

-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ export enum EventType {
6161
HISTORY_CHANGE = 'history:change',
6262
}
6363

64-
export enum InnerEventType {
65-
HISTORY_CHANGE = 'inner:history:change'
66-
}
67-
6864
export enum SegmentDirection {
6965
HORIZONTAL = 'horizontal',
7066
VERTICAL = 'vertical',

packages/core/src/view/Anchor.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface IState {
3232
endX: number,
3333
endY: number,
3434
hover: boolean,
35+
draging: boolean,
3536
}
3637

3738
class Anchor extends Component<IProps, IState> {
@@ -50,6 +51,7 @@ class Anchor extends Component<IProps, IState> {
5051
endX: 0,
5152
endY: 0,
5253
hover: false,
54+
draging: false,
5355
};
5456

5557
this.dragHandler = createDrag({
@@ -59,8 +61,6 @@ class Anchor extends Component<IProps, IState> {
5961
});
6062
}
6163
onDragStart = () => {
62-
console.log('onDragStart');
63-
6464
const {
6565
x, y, nodeModel, graphModel,
6666
} = this.props;
@@ -75,8 +75,6 @@ class Anchor extends Component<IProps, IState> {
7575
});
7676
};
7777
onDraging = ({ deltaX, deltaY }) => {
78-
console.log('onDraging');
79-
8078
const { endX, endY } = this.state;
8179
const { graphModel, nodeModel } = this.props;
8280
const { transformMatrix, nodes } = graphModel;
@@ -88,6 +86,7 @@ class Anchor extends Component<IProps, IState> {
8886
this.setState({
8987
endX: x,
9088
endY: y,
89+
draging: true,
9190
});
9291
const info = targetNodeInfo({ x: endX, y: endY }, nodes);
9392
if (info) {
@@ -117,15 +116,19 @@ class Anchor extends Component<IProps, IState> {
117116
}
118117
};
119118
onDragEnd = () => {
120-
console.log('onDragEnd');
121119
this.checkEnd();
122120
this.setState({
123121
startX: 0,
124122
startY: 0,
125123
endX: 0,
126124
endY: 0,
125+
draging: false,
127126
});
128127
};
128+
onDblClick = () => {
129+
const { graphModel, nodeModel } = this.props;
130+
graphModel.setElementStateById(nodeModel.id, ElementState.TEXT_EDIT);
131+
};
129132

130133
setHover(isHover: boolean, ev: MouseEvent): void {
131134
const { nodeDraging, setHoverOFF } = this.props;
@@ -147,13 +150,15 @@ class Anchor extends Component<IProps, IState> {
147150
// nodeModel.setSelected(false);
148151
/* 创建连线 */
149152
const { nodes, edgeType } = graphModel;
150-
const { endX, endY } = this.state;
153+
const { endX, endY, draging } = this.state;
151154
const info = targetNodeInfo({ x: endX, y: endY }, nodes);
152155
// 为了保证鼠标离开的时候,将上一个节点状态重置为正常状态。
153156
if (this.preTargetNode && this.preTargetNode.state !== ElementState.DEFAULT) {
154157
this.preTargetNode.setElementState(ElementState.DEFAULT);
155158
this.preTargetNode.setAnchorActive(-1);
156159
}
160+
// 没有draging就结束连线
161+
if (!draging) return;
157162
if (info) {
158163
const targetNode = info.node;
159164
const {
@@ -208,7 +213,7 @@ class Anchor extends Component<IProps, IState> {
208213
} = this.props;
209214
return (
210215
// className="lf-anchor" 作为下载时,需要将锚点删除的依据,不要修改,svg结构也不要做修改否则会引起下载bug
211-
<g className="lf-anchor">
216+
<g className="lf-anchor" onDblClick={this.onDblClick}>
212217
{hover || activeAnchor === anchorIndex ? (
213218
<Circle
214219
className="lf-node-anchor-hover"

packages/site/src/app.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Setting from './component/Setting';
66
import Links from './component/Links';
77
import './index.less';
88
import CustomNode from './lib/utils/registerNode';
9+
import CustomListener from './lib/utils/addListener';
910

1011
LogicFlow.use(Snapshot);
1112
LogicFlow.use(Dnd);
@@ -36,7 +37,9 @@ export default class App extends Component<IProps, IState> {
3637
});
3738

3839
const customNode = new CustomNode(this.lf);
40+
const customListener = new CustomListener(this.lf);
3941
customNode.registerAll();
42+
customListener.addAll();
4043
this.lf.render({});
4144
}
4245

0 commit comments

Comments
 (0)