-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Update connection line to reuse
getCustomPath
in new …
…canvas (no-changelog) (#10175)
- Loading branch information
1 parent
0753aea
commit eb0f18f
Showing
4 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/editor-ui/src/components/canvas/elements/edges/CanvasConnectionLine.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import CanvasConnectionLine from './CanvasConnectionLine.vue'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { setActivePinia } from 'pinia'; | ||
import type { ConnectionLineProps } from '@vue-flow/core'; | ||
import { Position } from '@vue-flow/core'; | ||
|
||
const DEFAULT_PROPS = { | ||
sourceX: 0, | ||
sourceY: 0, | ||
sourcePosition: Position.Top, | ||
targetX: 100, | ||
targetY: 100, | ||
targetPosition: Position.Bottom, | ||
} satisfies Partial<ConnectionLineProps>; | ||
const renderComponent = createComponentRenderer(CanvasConnectionLine, { | ||
props: DEFAULT_PROPS, | ||
}); | ||
|
||
beforeEach(() => { | ||
const pinia = createTestingPinia(); | ||
setActivePinia(pinia); | ||
}); | ||
|
||
describe('CanvasConnectionLine', () => { | ||
it('should render a correct bezier path', () => { | ||
const { container } = renderComponent({ | ||
props: DEFAULT_PROPS, | ||
}); | ||
|
||
const edge = container.querySelector('.vue-flow__edge-path'); | ||
|
||
expect(edge).toHaveAttribute('d', 'M0,0 C0,-62.5 100,162.5 100,100'); | ||
}); | ||
|
||
it('should render a correct smooth step path when the connection is backwards', () => { | ||
const { container } = renderComponent({ | ||
props: { | ||
...DEFAULT_PROPS, | ||
sourceX: 0, | ||
sourceY: 0, | ||
sourcePosition: Position.Right, | ||
targetX: -100, | ||
targetY: -100, | ||
targetPosition: Position.Left, | ||
}, | ||
}); | ||
|
||
const edge = container.querySelector('.vue-flow__edge-path'); | ||
|
||
expect(edge).toHaveAttribute( | ||
'd', | ||
'M0 0L 32,0Q 40,0 40,8L 40,132Q 40,140 32,140L1 140L0 140M0 140L-40 140L -132,140Q -140,140 -140,132L -140,-92Q -140,-100 -132,-100L-100 -100', | ||
); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/editor-ui/src/components/canvas/elements/edges/CanvasConnectionLine.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts" setup> | ||
/* eslint-disable vue/no-multiple-template-root */ | ||
import type { ConnectionLineProps } from '@vue-flow/core'; | ||
import { BaseEdge } from '@vue-flow/core'; | ||
import { computed, useCssModule } from 'vue'; | ||
import { getCustomPath } from './utils/edgePath'; | ||
const props = defineProps<ConnectionLineProps>(); | ||
const $style = useCssModule(); | ||
const edgeStyle = computed(() => ({ | ||
strokeWidth: 2, | ||
})); | ||
const path = computed(() => getCustomPath(props)); | ||
</script> | ||
|
||
<template> | ||
<BaseEdge :class="$style.edge" :style="edgeStyle" :path="path[0]" :marker-end="markerEnd" /> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
.edge { | ||
transition: stroke 0.3s ease; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters