-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update(script-setup): Refactor remaining files to script setup style
- Loading branch information
1 parent
9b2f4b7
commit 560bdc2
Showing
62 changed files
with
1,677 additions
and
1,419 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import Flowy from '~/container/Flow.vue' | ||
import { Elements } from '~/types' | ||
const elements = ref<Elements>([ | ||
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } }, | ||
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } }, | ||
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } }, | ||
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } }, | ||
{ id: 'e1-2', source: '1', target: '2', animated: true }, | ||
{ id: 'e1-3', source: '1', target: '3' }, | ||
] as Elements) | ||
</script> | ||
|
||
<template> | ||
<Flowy :elements="elements"> | ||
<div>Foobar!</div> | ||
</Flowy> | ||
</template> |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,102 @@ | ||
<script lang="ts" setup> | ||
import { CSSProperties } from 'vue' | ||
import { ConnectionLineType, CustomConnectionLine, HandleElement, Position, RevueFlowStore, Node } from '~/types' | ||
import { RevueFlowHooks } from '~/hooks/RevueFlowHooks' | ||
import { getBezierPath, getSmoothStepPath } from '~/components/Edges/utils' | ||
interface ConnectionLineProps { | ||
sourceNode: Node | ||
connectionLineType?: ConnectionLineType | ||
connectionLineStyle?: CSSProperties | ||
customConnectionLine?: CustomConnectionLine | ||
} | ||
const props = withDefaults(defineProps<ConnectionLineProps>(), { | ||
connectionLineType: ConnectionLineType.Bezier, | ||
connectionLineStyle: () => ({}), | ||
}) | ||
const store = inject<RevueFlowStore>('store')! | ||
const hooks = inject<RevueFlowHooks>('hooks')! | ||
const sourceHandle = computed(() => | ||
store.connectionHandleId && store.connectionHandleType | ||
? props.sourceNode.__rf.handleBounds[store.connectionHandleType].find((d: HandleElement) => d.id === store.connectionHandleId) | ||
: store.connectionHandleType && props.sourceNode.__rf.handleBounds[store.connectionHandleType][0], | ||
) | ||
const sourceHandleX = computed(() => | ||
sourceHandle.value ? sourceHandle.value.x + sourceHandle.value.width / 2 : (props.sourceNode.__rf.width as number) / 2, | ||
) | ||
const sourceHandleY = computed(() => | ||
sourceHandle.value ? sourceHandle.value.y + sourceHandle.value.height / 2 : props.sourceNode.__rf.height, | ||
) | ||
const sourceX = computed(() => props.sourceNode.__rf.position.x + sourceHandleX.value) | ||
const sourceY = computed(() => props.sourceNode.__rf.position.y + sourceHandleY.value) | ||
const targetX = computed(() => (store.connectionPosition?.x - store.transform[0]) / store.transform[2]) | ||
const targetY = computed(() => (store.connectionPosition?.y - store.transform[1]) / store.transform[2]) | ||
const isRightOrLeft = computed( | ||
() => sourceHandle.value?.position === Position.Left || sourceHandle.value?.position === Position.Right, | ||
) | ||
const targetPosition = computed(() => (isRightOrLeft.value ? Position.Left : Position.Top)) | ||
let dAttr = computed(() => `M${sourceX.value},${sourceY.value} ${targetX.value},${targetY.value}`) | ||
if (props.connectionLineType === ConnectionLineType.Bezier) { | ||
dAttr = computed(() => | ||
getBezierPath({ | ||
sourceX: sourceX.value, | ||
sourceY: sourceY.value, | ||
sourcePosition: sourceHandle.value?.position, | ||
targetX: targetX.value, | ||
targetY: targetY.value, | ||
targetPosition: targetPosition.value, | ||
}), | ||
) | ||
} else if (props.connectionLineType === ConnectionLineType.Step) { | ||
dAttr = computed(() => | ||
getSmoothStepPath({ | ||
sourceX: sourceX.value, | ||
sourceY: sourceY.value, | ||
sourcePosition: sourceHandle.value?.position, | ||
targetX: targetX.value, | ||
targetY: targetY.value, | ||
targetPosition: targetPosition.value, | ||
borderRadius: 0, | ||
}), | ||
) | ||
} else if (props.connectionLineType === ConnectionLineType.SmoothStep) { | ||
dAttr = computed(() => | ||
getSmoothStepPath({ | ||
sourceX: sourceX.value, | ||
sourceY: sourceY.value, | ||
sourcePosition: sourceHandle.value?.position, | ||
targetX: targetX.value, | ||
targetY: targetY.value, | ||
targetPosition: targetPosition.value, | ||
}), | ||
) | ||
} | ||
watch(dAttr, () => console.log(dAttr.value)) | ||
</script> | ||
<template> | ||
<g> | ||
<component | ||
:is="props.customConnectionLine" | ||
v-if="props.customConnectionLine" | ||
class="revue-flow__connection" | ||
v-bind="{ | ||
sourceX: sourceX, | ||
sourceY: sourceY, | ||
sourcePosition: sourceHandle.position, | ||
targetX: targetX, | ||
targetY: targetY, | ||
targetPosition: targetPosition, | ||
connectionLineType: props.connectionLineType, | ||
connectionLineStyle: props.connectionLineStyle, | ||
}" | ||
/> | ||
<path v-else :d="dAttr" class="revue-flow__connection-path" :style="props.connectionLineStyle" /> | ||
</g> | ||
</template> |
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
Oops, something went wrong.