Skip to content

Commit 28e2fcf

Browse files
committed
feat(extension): 独占模式支持单击取消全选 & 还原dynamic-group插件demo的代码
1 parent 40fa244 commit 28e2fcf

File tree

3 files changed

+38
-36
lines changed
  • examples/feature-examples/src/pages/extensions/dynamic-group
  • packages/extension/src

3 files changed

+38
-36
lines changed

examples/feature-examples/src/pages/extensions/dynamic-group/index.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ShapeItem,
66
Group,
77
SelectionSelect,
8-
DynamicGroup,
98
} from '@logicflow/extension'
109

1110
import { Button, Card, Divider, Flex } from 'antd'
@@ -24,7 +23,7 @@ const config: Partial<LogicFlow.Options> = {
2423
keyboard: {
2524
enabled: true,
2625
},
27-
plugins: [Group, Control, DndPanel, SelectionSelect, DynamicGroup],
26+
plugins: [Group, Control, DndPanel, SelectionSelect],
2827
}
2928

3029
const customDndConfig: ShapeItem[] = [
@@ -121,23 +120,16 @@ export default function BPMNExtension() {
121120
// },
122121
{
123122
id: 'group_1',
124-
type: 'dynamic-group',
123+
type: 'sub-process',
125124
x: 300,
126125
y: 120,
127-
text: 'dynamic-group-1',
126+
// children: ["rect_3"],
127+
text: 'sub-process-1',
128+
properties: {
129+
isFolded: true,
130+
},
128131
},
129132
// {
130-
// id: 'group_1',
131-
// type: 'sub-process',
132-
// x: 300,
133-
// y: 120,
134-
// // children: ["rect_3"],
135-
// text: 'sub-process-1',
136-
// properties: {
137-
// isFolded: true,
138-
// },
139-
// },
140-
// {
141133
// id: "group_2",
142134
// type: "sub-process",
143135
// x: 800,
@@ -162,10 +154,7 @@ export default function BPMNExtension() {
162154
const rerender = () => {}
163155

164156
return (
165-
<Card
166-
title="LogicFlow Extension - DynamicGroup"
167-
className="control-container"
168-
>
157+
<Card title="LogicFlow Extension - DndPanel" className="control-container">
169158
<Flex wrap="wrap" gap="small">
170159
<Button type="primary" key="getData" onClick={getGraphData}>
171160
获取数据

packages/extension/src/components/selection-select/index.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class SelectionSelect {
6262
* 清理选区状态
6363
*/
6464
private cleanupSelectionState() {
65+
console.log('cleanupSelectionState')
6566
// 清理当前的选区状态
6667
if (this.wrapper) {
6768
this.wrapper.oncontextmenu = null
@@ -72,6 +73,7 @@ export class SelectionSelect {
7273
}
7374
this.startPoint = undefined
7475
this.endPoint = undefined
76+
this.mouseDownInfo = null
7577

7678
// 移除事件监听
7779
document.removeEventListener('mousemove', this.draw)
@@ -134,9 +136,15 @@ export class SelectionSelect {
134136
// 禁用右键框选
135137
const isRightClick = e.button === 2
136138
if (isRightClick) return
137-
138139
// 清理之前可能存在的选区状态
139140
this.cleanupSelectionState()
141+
// 记录鼠标按下时的位置和时间
142+
this.mouseDownInfo = {
143+
x: e.clientX,
144+
y: e.clientY,
145+
time: Date.now(),
146+
}
147+
console.log('handleMouseDown', this.mouseDownInfo)
140148

141149
// 记录原始设置并临时禁止画布移动
142150
this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph!
@@ -165,22 +173,6 @@ export class SelectionSelect {
165173
document.addEventListener('mouseup', this.drawOff)
166174
}
167175

168-
onToolContainerMouseUp = (e: MouseEvent) => {
169-
if (this.mouseDownInfo) {
170-
const { x, y, time } = this.mouseDownInfo
171-
const now = Date.now()
172-
// 用 mouseDown 和 mouseUp 的位置偏移及时间间隔来判断是否是点击事件
173-
const isClickEvent =
174-
Math.abs(e.clientX - x) < 10 &&
175-
Math.abs(e.clientY - y) < 10 &&
176-
now - time < 100
177-
if (isClickEvent) {
178-
this.lf.clearSelectElements()
179-
}
180-
this.mouseDownInfo = null
181-
}
182-
}
183-
184176
/**
185177
* 设置选中的灵敏度
186178
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
@@ -259,6 +251,23 @@ export class SelectionSelect {
259251
}
260252
}
261253
private drawOff = (e: MouseEvent) => {
254+
// 处理鼠标抬起事件
255+
// 首先判断是否是点击,如果是,则清空框选
256+
console.log('drawOff', e, this.mouseDownInfo)
257+
if (this.mouseDownInfo) {
258+
const { x, y, time } = this.mouseDownInfo
259+
const isClick =
260+
Math.abs(e.clientX - x) < 5 &&
261+
Math.abs(e.clientY - y) < 5 &&
262+
Date.now() - time < 200
263+
console.log('isClick', isClick)
264+
if (isClick) {
265+
this.lf.clearSelectElements()
266+
this.cleanupSelectionState()
267+
return
268+
}
269+
}
270+
262271
const curStartPoint = cloneDeep(this.startPoint)
263272
const curEndPoint = cloneDeep(this.endPoint)
264273
document.removeEventListener('mousemove', this.draw)

packages/extension/src/style/raw.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ export const content = `@import url('medium-editor/dist/css/medium-editor.min.cs
193193
background: #eaedf2;
194194
border: 1px solid #93a3b4;
195195
}
196+
.lf-mini-map .lf-graph {
197+
width: 100% !important;
198+
height: 100% !important;
199+
}
196200
.lf-mini-map-graph {
197201
position: relative;
198202
overflow: hidden;

0 commit comments

Comments
 (0)