chore: lint

This commit is contained in:
Braks
2022-05-27 23:36:01 +02:00
parent 9510f3dd54
commit bae5d1e26d
7 changed files with 1025 additions and 631 deletions
+1 -1
View File
@@ -24,6 +24,6 @@ export default defineConfig({
}), }),
], ],
optimizeDeps: { optimizeDeps: {
include: ['@braks/vue-flow'], exclude: ['@braks/vue-flow'],
}, },
}) })
+1
View File
@@ -2,6 +2,7 @@ module.exports = {
rules: { rules: {
'no-use-before-define': 0, 'no-use-before-define': 0,
'vue/no-setup-props-destructure': 0, 'vue/no-setup-props-destructure': 0,
'react/prop-types': 0,
}, },
extends: ['../../.eslintrc.js'], extends: ['../../.eslintrc.js'],
ignorePatterns: ['!**/*'], ignorePatterns: ['!**/*'],
@@ -1,6 +1,7 @@
import { Component, CSSProperties, FunctionalComponent, VNode } from 'vue' import type { CSSProperties, Component, FunctionalComponent, VNode } from 'vue'
import EdgeAnchor from './EdgeAnchor' import EdgeAnchor from './EdgeAnchor'
import { ConnectionMode, EdgeComponent, EdgeMarkerType, EdgeTextProps, GraphNode, Position } from '~/types' import type { EdgeComponent, EdgeMarkerType, EdgeTextProps, GraphNode } from '~/types'
import { ConnectionMode, Position } from '~/types'
import { getEdgePositions, getHandle, getMarkerId } from '~/utils' import { getEdgePositions, getHandle, getMarkerId } from '~/utils'
interface Props { interface Props {
@@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useVueFlow, useDrag } from '../../composables' import { useDrag, useVueFlow } from '../../composables'
import { NodeComponent, SnapGrid, XYZPosition } from '../../types' import type { NodeComponent, SnapGrid, XYZPosition } from '../../types'
import { NodeId } from '../../context' import { NodeId } from '../../context'
import { getConnectedEdges, getHandleBounds, getXYZPos } from '../../utils' import { getConnectedEdges, getHandleBounds, getXYZPos } from '../../utils'
@@ -15,7 +15,6 @@ const { id, type, name, draggable, selectable, connectable, snapGrid, ...props }
name: string name: string
}>() }>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
let computedPosition = $(useVModel(props, 'modelValue', emit)) let computedPosition = $(useVModel(props, 'modelValue', emit))
@@ -102,29 +101,32 @@ onMounted(() => {
updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }]) updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }])
watch( watch(
[() => node.position, () => parentNode?.computedPosition], [
([pos, parent]) => { () => node.position.x,
() => node.position.y,
() => parentNode?.computedPosition.x,
() => parentNode?.computedPosition.y,
() => parentNode?.computedPosition.z,
],
([newX, newY, parentX, parentY, parentZ]) => {
const xyzPos = { const xyzPos = {
...pos, x: newX,
y: newY,
z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0, z: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
} }
if (parent) { if (parentX && parentY) {
computedPosition = getXYZPos(parent, xyzPos) computedPosition = getXYZPos({ x: parentX, y: parentY, z: parentZ! }, xyzPos)
} else { } else {
computedPosition = xyzPos computedPosition = xyzPos
} }
node.handleBounds = getHandleBounds(nodeElement.value, viewport.zoom) node.handleBounds = getHandleBounds(nodeElement.value, viewport.zoom)
}, },
{ immediate: true, deep: true, flush: 'post' }, { immediate: true, flush: 'post' },
) )
}) })
onUnmounted(() => {
nodeElement.value = undefined
})
const onMouseEnter = (event: MouseEvent) => { const onMouseEnter = (event: MouseEvent) => {
if (!dragging) { if (!dragging) {
emits.nodeMouseEnter({ event, node, connectedEdges: getConnectedEdges([node], edges) }) emits.nodeMouseEnter({ event, node, connectedEdges: getConnectedEdges([node], edges) })
@@ -167,11 +169,11 @@ const onSelectNode = (event: MouseEvent) => {
} }
} }
const getClass = () => { const getClass = computed(() => {
return node.class instanceof Function ? node.class(node) : node.class return node.class instanceof Function ? node.class(node) : node.class
} })
const getStyle = () => { const getStyle = computed(() => {
const styles = (node.style instanceof Function ? node.style(node) : node.style) || {} const styles = (node.style instanceof Function ? node.style(node) : node.style) || {}
const width = node.width instanceof Function ? node.width(node) : node.width const width = node.width instanceof Function ? node.width(node) : node.width
const height = node.height instanceof Function ? node.height(node) : node.height const height = node.height instanceof Function ? node.height(node) : node.height
@@ -179,7 +181,7 @@ const getStyle = () => {
if (height) styles.height = typeof height === 'string' ? height : `${height}px` if (height) styles.height = typeof height === 'string' ? height : `${height}px`
return styles return styles
} })
</script> </script>
<script lang="ts"> <script lang="ts">
@@ -192,8 +194,8 @@ export default {
<template> <template>
<div <div
ref="nodeElement" ref="nodeElement"
class="vue-flow__node"
:class="[ :class="[
'vue-flow__node',
`vue-flow__node-${name}`, `vue-flow__node-${name}`,
noPanClassName, noPanClassName,
{ {
@@ -201,13 +203,13 @@ export default {
selected: node.selected, selected: node.selected,
selectable, selectable,
}, },
getClass(), getClass,
]" ]"
:style="{ :style="{
zIndex: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0, zIndex: node.computedPosition.z ? node.computedPosition.z : node.selected ? 1000 : 0,
transform: `translate(${node.computedPosition.x}px,${node.computedPosition.y}px)`, transform: `translate(${node.computedPosition.x}px,${node.computedPosition.y}px)`,
pointerEvents: selectable || draggable ? 'all' : 'none', pointerEvents: selectable || draggable ? 'all' : 'none',
...getStyle(), ...getStyle,
}" }"
:data-id="node.id" :data-id="node.id"
@mouseenter="onMouseEnter" @mouseenter="onMouseEnter"
+10 -6
View File
@@ -1,15 +1,19 @@
import { D3DragEvent, drag, SubjectPosition } from 'd3-drag' import type { D3DragEvent, SubjectPosition } from 'd3-drag'
import { drag } from 'd3-drag'
import { select } from 'd3-selection' import { select } from 'd3-selection'
import { Ref } from 'vue' import type { Ref } from 'vue'
import { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import useVueFlow from './useVueFlow' import useVueFlow from './useVueFlow'
import { pointToRendererPoint } from '~/utils' import { pointToRendererPoint } from '~/utils'
import { GraphNode, XYPosition } from '~/types' import type { GraphNode, XYPosition } from '~/types'
export type UseDragEvent = D3DragEvent<HTMLDivElement, null, SubjectPosition> export type UseDragEvent = D3DragEvent<HTMLDivElement, null, SubjectPosition>
export type UseDragData = { dx: number; dy: number } export interface UseDragData {
dx: number
dy: number
}
type UseDragParams = { interface UseDragParams {
onStart: (event: UseDragEvent) => void onStart: (event: UseDragEvent) => void
onDrag: (event: UseDragEvent, data: UseDragData) => void onDrag: (event: UseDragEvent, data: UseDragData) => void
onStop: (event: UseDragEvent) => void onStop: (event: UseDragEvent) => void
+5 -12
View File
@@ -1,15 +1,5 @@
import type { CSSProperties, ComputedRef, ToRefs } from 'vue' import type { CSSProperties, ComputedRef, ToRefs } from 'vue'
import type { import type { Dimensions, ElementData, Elements, FlowElements, FlowInstance, FlowOptions, SnapGrid, XYPosition } from './flow'
Dimensions,
ElementData,
Elements,
FlowElements,
FlowInstance,
FlowOptions,
Rect,
SnapGrid,
XYPosition,
} from './flow'
import type { DefaultEdgeTypes, DefaultNodeTypes, EdgeComponent, NodeComponent } from './components' import type { DefaultEdgeTypes, DefaultNodeTypes, EdgeComponent, NodeComponent } from './components'
import type { Connection, ConnectionLineType, ConnectionMode } from './connection' import type { Connection, ConnectionLineType, ConnectionMode } from './connection'
import type { DefaultEdgeOptions, Edge, GraphEdge } from './edge' import type { DefaultEdgeOptions, Edge, GraphEdge } from './edge'
@@ -25,7 +15,10 @@ export interface UpdateNodeDimensionsParams {
forceUpdate?: boolean forceUpdate?: boolean
} }
export type UpdateNodePositionsParams = { id?: string; diff?: XYPosition } export interface UpdateNodePositionsParams {
id?: string
diff?: XYPosition
}
export interface State extends Omit<FlowOptions, 'id' | 'modelValue'> { export interface State extends Omit<FlowOptions, 'id' | 'modelValue'> {
/** Event hooks, you can manipulate the triggers at your own peril */ /** Event hooks, you can manipulate the triggers at your own peril */
+983 -590
View File
File diff suppressed because it is too large Load Diff