@logicflow/core 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.turbo/turbo-build$colon$dev.log +10 -10
  2. package/.turbo/turbo-build.log +33 -33
  3. package/CHANGELOG.md +21 -0
  4. package/__tests__/algorithm/egde.test.ts +36 -23
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/es/event/eventArgs.d.ts +23 -29
  8. package/es/model/GraphModel.d.ts +10 -0
  9. package/es/model/GraphModel.js +26 -1
  10. package/es/model/edge/BaseEdgeModel.d.ts +1 -0
  11. package/es/model/node/BaseNodeModel.js +1 -1
  12. package/es/util/drag.d.ts +1 -0
  13. package/es/util/drag.js +11 -0
  14. package/es/view/Anchor.js +6 -8
  15. package/es/view/Control.js +1 -1
  16. package/es/view/Graph.js +3 -15
  17. package/es/view/behavior/dnd.js +1 -0
  18. package/es/view/edge/BaseEdge.d.ts +3 -1
  19. package/es/view/edge/BaseEdge.js +8 -5
  20. package/es/view/overlay/BackgroundOverlay.d.ts +4 -14
  21. package/es/view/overlay/BackgroundOverlay.js +11 -1
  22. package/es/view/overlay/Grid.d.ts +4 -3
  23. package/es/view/overlay/Grid.js +8 -31
  24. package/es/view/text/BaseText.js +1 -1
  25. package/lib/event/eventArgs.d.ts +23 -29
  26. package/lib/model/GraphModel.d.ts +10 -0
  27. package/lib/model/GraphModel.js +25 -0
  28. package/lib/model/edge/BaseEdgeModel.d.ts +1 -0
  29. package/lib/model/node/BaseNodeModel.js +1 -1
  30. package/lib/util/drag.d.ts +1 -0
  31. package/lib/util/drag.js +11 -0
  32. package/lib/view/Anchor.js +6 -8
  33. package/lib/view/Control.js +1 -1
  34. package/lib/view/Graph.js +3 -15
  35. package/lib/view/behavior/dnd.js +1 -0
  36. package/lib/view/edge/BaseEdge.d.ts +3 -1
  37. package/lib/view/edge/BaseEdge.js +8 -5
  38. package/lib/view/overlay/BackgroundOverlay.d.ts +4 -14
  39. package/lib/view/overlay/BackgroundOverlay.js +11 -1
  40. package/lib/view/overlay/Grid.d.ts +4 -3
  41. package/lib/view/overlay/Grid.js +8 -31
  42. package/lib/view/text/BaseText.js +1 -1
  43. package/package.json +1 -1
  44. package/src/algorithm/edge.ts +2 -4
  45. package/src/event/eventArgs.ts +23 -29
  46. package/src/model/GraphModel.ts +12 -1
  47. package/src/model/edge/BaseEdgeModel.ts +1 -0
  48. package/src/model/node/BaseNodeModel.ts +1 -1
  49. package/src/model/node/HtmlNodeModel.ts +1 -1
  50. package/src/util/drag.ts +12 -0
  51. package/src/view/Anchor.tsx +7 -8
  52. package/src/view/Control.tsx +1 -1
  53. package/src/view/Graph.tsx +2 -3
  54. package/src/view/behavior/dnd.ts +1 -0
  55. package/src/view/edge/BaseEdge.tsx +8 -3
  56. package/src/view/overlay/Grid.tsx +13 -9
  57. package/src/view/text/BaseText.tsx +1 -1
  58. package/stats.html +1 -1
@@ -67,6 +67,7 @@ export class Dnd {
67
67
  this.lf.setNodeSnapLine(nodeData)
68
68
  this.lf.graphModel.eventCenter.emit(EventType.NODE_DND_DRAG, {
69
69
  data: nodeData,
70
+ e,
70
71
  })
71
72
  }
72
73
  return false
@@ -29,6 +29,7 @@ export abstract class BaseEdge<P extends IProps> extends Component<
29
29
  > {
30
30
  static isObserved: boolean = false
31
31
  static extendsKey?: string
32
+ mouseUpDrag?: boolean
32
33
 
33
34
  startTime?: number
34
35
  contextMenuTime?: number
@@ -385,13 +386,16 @@ export abstract class BaseEdge<P extends IProps> extends Component<
385
386
  e.stopPropagation()
386
387
  this.startTime = new Date().getTime()
387
388
  }
389
+ handleMouseUp = () => {
390
+ const { model } = this.props
391
+ this.mouseUpDrag = model.isDragging
392
+ }
388
393
  /**
389
394
  * 不支持重写
390
395
  */
391
- handleMouseUp = (e: MouseEvent) => {
396
+ handleClick = (e: MouseEvent) => {
392
397
  if (!this.startTime) return
393
- const time = new Date().getTime() - this.startTime
394
- if (time > 200) return // 事件大于200ms,认为是拖拽。
398
+ if (this.mouseUpDrag) return // 如果是拖拽,不触发click事件。
395
399
  const isRightClick = e.button === 2
396
400
  if (isRightClick) return
397
401
  // 这里 IE 11不能正确显示
@@ -490,6 +494,7 @@ export abstract class BaseEdge<P extends IProps> extends Component<
490
494
  .join(' ')}
491
495
  onMouseDown={this.handleMouseDown}
492
496
  onMouseUp={this.handleMouseUp}
497
+ onClick={this.handleClick}
493
498
  onContextMenu={this.handleContextMenu}
494
499
  onMouseOver={this.setHoverOn}
495
500
  onMouseEnter={this.setHoverOn}
@@ -5,19 +5,24 @@ import { createUuid } from '../../util'
5
5
  import { GraphModel } from '../../model'
6
6
  import { DEFAULT_GRID_SIZE } from '../../constant'
7
7
 
8
- import GridOptions = Grid.GridOptions
9
-
10
- type IProps = GridOptions & {
8
+ type IProps = {
11
9
  graphModel: GraphModel
12
10
  }
13
11
 
14
12
  @observer
15
13
  export class Grid extends Component<IProps> {
14
+ gridOptions: Grid.GridOptions
15
+
16
16
  readonly id = createUuid()
17
17
 
18
+ constructor(props: IProps) {
19
+ super(props)
20
+ this.gridOptions = this.props.graphModel.grid
21
+ }
22
+
18
23
  // 网格类型为点状
19
24
  renderDot() {
20
- const { config, size = 1, visible } = this.props
25
+ const { config, size = 1, visible } = this.gridOptions
21
26
 
22
27
  const { color, thickness = 2 } = config ?? {}
23
28
 
@@ -37,7 +42,7 @@ export class Grid extends Component<IProps> {
37
42
  // 网格类型为交叉线
38
43
  // todo: 采用背景缩放的方式,实现更好的体验
39
44
  renderMesh() {
40
- const { config, size = 1, visible } = this.props
45
+ const { config, size = 1, visible } = this.gridOptions
41
46
  const { color, thickness = 1 } = config ?? {}
42
47
 
43
48
  // 对于交叉线网格,线的宽度不能大于网格大小的一半
@@ -48,7 +53,7 @@ export class Grid extends Component<IProps> {
48
53
  <path
49
54
  d={d}
50
55
  stroke={color}
51
- strokeWidth={strokeWidth}
56
+ strokeWidth={strokeWidth / 2}
52
57
  opacity={opacity}
53
58
  fill="transparent"
54
59
  />
@@ -57,10 +62,9 @@ export class Grid extends Component<IProps> {
57
62
 
58
63
  render() {
59
64
  const {
60
- type,
61
- size = 1,
62
65
  graphModel: { transformModel },
63
66
  } = this.props
67
+ const { type, size = 1 } = this.gridOptions
64
68
  const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
65
69
  transformModel
66
70
  const matrixString = [
@@ -124,7 +128,7 @@ export namespace Grid {
124
128
  /**
125
129
  * 网格的颜色
126
130
  */
127
- color: string
131
+ color?: string
128
132
  /**
129
133
  * 网格的宽度
130
134
  * - 对于 `dot` 点状网格,表示点的大小
@@ -91,7 +91,7 @@ export class BaseText<
91
91
  graphModel: { transformModel },
92
92
  } = this.props
93
93
 
94
- if (deltaX && deltaY) {
94
+ if (deltaX || deltaY) {
95
95
  const [curDeltaX, curDeltaY] = transformModel.fixDeltaXY(deltaX, deltaY)
96
96
  model.moveText(curDeltaX, curDeltaY)
97
97
  }