Skip to content

refactor(core): implement @xyflow/system #1546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: release/2.0.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-rockets-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/minimap": patch
---

Update import of `getBoundsOfRects`
26 changes: 26 additions & 0 deletions .changeset/fluffy-tables-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
"@vue-flow/core": minor
---

Replace existing graph utils exports with those already provided by `@xyflow/system`:

- Replace utils
- `clamp`
- `clampPosition`
- `getDimensions`
- `getHostForElement`
- `getOverlappingArea`
- `rectToBox`
- `boxToRect`
- `getBoundsofRects`
- `getBoundsOfBoxes`
- `rendererPointToPoint`
- `getMarkerId`
- `isRect`
- `isNumeric`
- `calcAutoPan`
- `isMouseEvent`
- `getEventPosition`

-Remove utils
- `isMacOS`
5 changes: 5 additions & 0 deletions .changeset/seven-ads-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/minimap": minor
---

Replace d3 with xyflow minimap instance
5 changes: 5 additions & 0 deletions .changeset/six-spiders-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": major
---

Rename transformationpane to viewport and viewport to zoompane. Also update corresponding css class names and styles.
5 changes: 5 additions & 0 deletions .changeset/tame-books-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": major
---

Replace d3 zoom and pan with panzoom instance
5 changes: 5 additions & 0 deletions .changeset/ten-snails-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": minor
---

Replace existing edge utils with ones that are already provided by `@xyflow/system` and re-export them
2 changes: 1 addition & 1 deletion docs/src/guide/vue-flow/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ const edges = ref([

### default-viewport (optional)

- Type: [`ViewportTransform`](/typedocs/interfaces/ViewportTransform)
- Type: `Viewport`

- Default: `{ zoom: 1, position: { x: 0, y: 0 } }`

Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@
"@vueuse/core": "^10.5.0",
"d3-drag": "^3.0.0",
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0"
"@xyflow/system": "^0.0.39"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.3",
"@tooling/eslint-config": "workspace:*",
"@tooling/tsconfig": "workspace:*",
"@types/d3-drag": "^3.0.4",
"@types/d3-selection": "^3.0.7",
"@types/d3-zoom": "^3.0.5",
"@vitejs/plugin-vue": "^4.4.0",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.31",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/ConnectionLine/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { computed, defineComponent, h, inject } from 'vue'
import { getBezierPath, getMarkerId, getSmoothStepPath } from '@xyflow/system'
import type { HandleElement } from '../../types'
import { ConnectionLineType, ConnectionMode, Position } from '../../types'
import { getHandlePosition, getMarkerId, oppositePosition } from '../../utils'
import { getHandlePosition, oppositePosition } from '../../utils'
import { useVueFlow } from '../../composables'
import { Slots } from '../../context'
import { getBezierPath, getSimpleBezierPath, getSmoothStepPath } from '../Edges/utils'
import { getSimpleBezierPath } from '../Edges/SimpleBezierEdge'

const ConnectionLine = defineComponent({
name: 'ConnectionLine',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Edges/BezierEdge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineComponent, h } from 'vue'
import { getBezierPath } from '@xyflow/system'
import type { BezierEdgeProps } from '../../types'
import { Position } from '../../types'
import BaseEdge from './BaseEdge.vue'
import { getBezierPath } from './utils'

const BezierEdge = defineComponent<BezierEdgeProps>({
name: 'BezierEdge',
Expand Down
11 changes: 2 additions & 9 deletions packages/core/src/components/Edges/EdgeWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { computed, defineComponent, getCurrentInstance, h, inject, provide, ref, resolveComponent, toRef } from 'vue'
import { getMarkerId } from '@xyflow/system'
import type { Connection, EdgeComponent, HandleType, MouseTouchEvent } from '../../types'
import { ConnectionMode, Position } from '../../types'
import { useEdgeHooks, useHandle, useVueFlow } from '../../composables'
import { EdgeId, EdgeRef, Slots } from '../../context'
import {
ARIA_EDGE_DESC_KEY,
ErrorCode,
VueFlowError,
elementSelectionKeys,
getEdgeHandle,
getHandlePosition,
getMarkerId,
} from '../../utils'
import { ARIA_EDGE_DESC_KEY, ErrorCode, VueFlowError, elementSelectionKeys, getEdgeHandle, getHandlePosition } from '../../utils'
import EdgeAnchor from './EdgeAnchor'

interface Props {
Expand Down
93 changes: 92 additions & 1 deletion packages/core/src/components/Edges/SimpleBezierEdge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,99 @@
import { defineComponent, h } from 'vue'
import { getBezierEdgeCenter } from '@xyflow/system'
import type { SimpleBezierEdgeProps } from '../../types'
import { Position } from '../../types'
import BaseEdge from './BaseEdge.vue'
import { getSimpleBezierPath } from './utils'

export interface GetSimpleBezierPathParams {
sourceX: number
sourceY: number
sourcePosition?: Position
targetX: number
targetY: number
targetPosition?: Position
}

interface GetControlParams {
pos: Position
x1: number
y1: number
x2: number
y2: number
}

function getControl({ pos, x1, y1, x2, y2 }: GetControlParams): [number, number] {
let ctX: number, ctY: number
switch (pos) {
case Position.Left:
case Position.Right:
ctX = 0.5 * (x1 + x2)
ctY = y1
break
case Position.Top:
case Position.Bottom:
ctX = x1
ctY = 0.5 * (y1 + y2)
break
}
return [ctX, ctY]
}

/**
* Get a simple bezier path from source to target handle (no curvature)
* @public
*
* @param simpleBezierPathParams
* @param simpleBezierPathParams.sourceX - The x position of the source handle
* @param simpleBezierPathParams.sourceY - The y position of the source handle
* @param simpleBezierPathParams.sourcePosition - The position of the source handle (default: Position.Bottom)
* @param simpleBezierPathParams.targetX - The x position of the target handle
* @param simpleBezierPathParams.targetY - The y position of the target handle
* @param simpleBezierPathParams.targetPosition - The position of the target handle (default: Position.Top)
* @returns A path string you can use in an SVG, the labelX and labelY position (center of path) and offsetX, offsetY between source handle and label
*/
export function getSimpleBezierPath({
sourceX,
sourceY,
sourcePosition = Position.Bottom,
targetX,
targetY,
targetPosition = Position.Top,
}: GetSimpleBezierPathParams): [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number] {
const [sourceControlX, sourceControlY] = getControl({
pos: sourcePosition,
x1: sourceX,
y1: sourceY,
x2: targetX,
y2: targetY,
})

const [targetControlX, targetControlY] = getControl({
pos: targetPosition,
x1: targetX,
y1: targetY,
x2: sourceX,
y2: sourceY,
})

const [labelX, labelY, offsetX, offsetY] = getBezierEdgeCenter({
sourceX,
sourceY,
targetX,
targetY,
sourceControlX,
sourceControlY,
targetControlX,
targetControlY,
})

return [
`M${sourceX},${sourceY} C${sourceControlX},${sourceControlY} ${targetControlX},${targetControlY} ${targetX},${targetY}`,
labelX,
labelY,
offsetX,
offsetY,
]
}

const SimpleBezierEdge = defineComponent<SimpleBezierEdgeProps>({
name: 'SimpleBezierEdge',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Edges/SmoothStepEdge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineComponent, h } from 'vue'
import { getSmoothStepPath } from '@xyflow/system'
import type { SmoothStepEdgeProps } from '../../types'
import { Position } from '../../types'
import BaseEdge from './BaseEdge.vue'
import { getSmoothStepPath } from './utils'

const SmoothStepEdge = defineComponent<SmoothStepEdgeProps>({
name: 'SmoothStepEdge',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Edges/StraightEdge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent, h } from 'vue'
import { getStraightPath } from '@xyflow/system'
import type { StraightEdgeProps } from '../../types'
import BaseEdge from './BaseEdge.vue'
import { getStraightPath } from './utils'

const StraightEdge = defineComponent<StraightEdgeProps>({
name: 'StraightEdge',
Expand Down
114 changes: 0 additions & 114 deletions packages/core/src/components/Edges/utils/bezier.ts

This file was deleted.

Loading
Loading