refactor(core): remove primtive typeguards
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, useAttrs } from 'vue'
|
||||
import type { BaseEdgeProps } from '../../types'
|
||||
import { isNumber } from '../../utils'
|
||||
import EdgeText from './EdgeText.vue'
|
||||
|
||||
const { interactionWidth = 20, labelShowBg = true, ...props } = defineProps<BaseEdgeProps>()
|
||||
@@ -52,7 +51,7 @@ export default {
|
||||
/>
|
||||
|
||||
<EdgeText
|
||||
v-if="label && isNumber(labelX) && isNumber(labelY)"
|
||||
v-if="label && labelX && labelY"
|
||||
ref="labelEl"
|
||||
:x="labelX"
|
||||
:y="labelY"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import type { EdgeTextProps } from '../../types/components'
|
||||
import type { Rect as RectType } from '../../types'
|
||||
import { isString } from '../../utils'
|
||||
|
||||
const {
|
||||
x,
|
||||
@@ -61,7 +60,7 @@ export default {
|
||||
|
||||
<text v-bind="$attrs" ref="el" class="vue-flow__edge-text" :y="box.height / 2" dy="0.3em" :style="labelStyle">
|
||||
<slot>
|
||||
<component :is="label as any" v-if="!isString(label)" />
|
||||
<component :is="label" v-if="typeof label !== 'string'" />
|
||||
<template v-else>
|
||||
{{ label }}
|
||||
</template>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { computed, onUnmounted, ref } from 'vue'
|
||||
import type { HandleProps } from '../../types/handle'
|
||||
import { Position } from '../../types'
|
||||
import { useHandle, useNode, useVueFlow } from '../../composables'
|
||||
import { getDimensions, isDef, isFunction, isMouseEvent, isNumber, isString } from '../../utils'
|
||||
import { getDimensions, isDef, isMouseEvent } from '../../utils'
|
||||
|
||||
const {
|
||||
position = Position.Top,
|
||||
@@ -47,7 +47,7 @@ const { handlePointerDown, handleClick } = useHandle({
|
||||
})
|
||||
|
||||
const isConnectable = computed(() => {
|
||||
if (isString(connectable) && connectable === 'single') {
|
||||
if (typeof connectable === 'string' && connectable === 'single') {
|
||||
return !connectedEdges.value.some((edge) => {
|
||||
const id = edge[`${type.value}Handle`]
|
||||
|
||||
@@ -59,7 +59,7 @@ const isConnectable = computed(() => {
|
||||
})
|
||||
}
|
||||
|
||||
if (isNumber(connectable)) {
|
||||
if (typeof connectable === 'number') {
|
||||
return (
|
||||
connectedEdges.value.filter((edge) => {
|
||||
const id = edge[`${type.value}Handle`]
|
||||
@@ -73,14 +73,14 @@ const isConnectable = computed(() => {
|
||||
)
|
||||
}
|
||||
|
||||
if (isFunction(connectable)) {
|
||||
if (typeof connectable === 'function') {
|
||||
return connectable(node, connectedEdges.value)
|
||||
}
|
||||
|
||||
return isDef(connectable) ? connectable : nodesConnectable.value
|
||||
})
|
||||
|
||||
const isConnecting = computed(
|
||||
const isConnecting = toRef(
|
||||
() =>
|
||||
(connectionStartHandle.value?.nodeId === nodeId &&
|
||||
connectionStartHandle.value?.handleId === handleId.value &&
|
||||
@@ -90,7 +90,7 @@ const isConnecting = computed(
|
||||
connectionEndHandle.value?.type === type.value),
|
||||
)
|
||||
|
||||
const isClickConnecting = computed(
|
||||
const isClickConnecting = toRef(
|
||||
() =>
|
||||
connectionClickStartHandle.value?.nodeId === nodeId &&
|
||||
connectionClickStartHandle.value?.handleId === handleId.value &&
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
getConnectedEdges,
|
||||
getXYZPos,
|
||||
handleNodeClick,
|
||||
isNumber,
|
||||
} from '~/utils'
|
||||
|
||||
interface Props {
|
||||
@@ -153,7 +152,7 @@ const NodeWrapper = defineComponent({
|
||||
z: nodeZIndex + (elevateNodesOnSelect.value ? (node.value.selected ? 1000 : 0) : 0),
|
||||
}
|
||||
|
||||
if (isNumber(parentX) && isNumber(parentY)) {
|
||||
if (typeof parentX !== 'undefined' && typeof parentY !== 'undefined') {
|
||||
node.value.computedPosition = getXYZPos({ x: parentX, y: parentY, z: parentZ! }, xyzPos)
|
||||
} else {
|
||||
node.value.computedPosition = xyzPos
|
||||
|
||||
Reference in New Issue
Block a user