feat: script setup style
* Replace jsx with script setup syntax
* Simplify logic and make it more "composable"
* Move Zoom functions to useZoom composable
* Update eslint config & tsconfig
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
import useKeyPress from './useKeyPress'
|
||||
import { isNode, getConnectedEdges } from '../utils/graph'
|
||||
import { Elements, KeyCode, ElementId, FlowElement, RevueFlowStore, Edge } from '../types'
|
||||
import { computed, watch } from 'vue'
|
||||
import useKeyPress from './useKeyPress'
|
||||
import { isNode, getConnectedEdges } from '~/utils/graph'
|
||||
import { Elements, KeyCode, ElementId, FlowElement, RevueFlowStore, Edge } from '~/types'
|
||||
|
||||
interface HookParams {
|
||||
store: RevueFlowStore
|
||||
deleteKeyCode: KeyCode
|
||||
multiSelectionKeyCode: KeyCode
|
||||
onElementsRemove?: (elements: Elements) => void
|
||||
}
|
||||
|
||||
export default ({ store, deleteKeyCode, multiSelectionKeyCode, onElementsRemove }: HookParams): void => {
|
||||
export default ({ deleteKeyCode, multiSelectionKeyCode, onElementsRemove }: HookParams): void => {
|
||||
const selectedElements = ref([])
|
||||
const deleteKeyPressed = useKeyPress(deleteKeyCode)
|
||||
const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode)
|
||||
const selectedElements = computed(() => store.selectedElements || [])
|
||||
const edges = computed(() => store.edges)
|
||||
/**
|
||||
* const selectedElements = computed(() => store.selectedElements || [])
|
||||
const edges = computed(() => store.edges)
|
||||
|
||||
watch(selectedElements, () => {
|
||||
watch(selectedElements, () => {
|
||||
if (onElementsRemove && deleteKeyPressed.value && selectedElements.value.length > 0) {
|
||||
const selectedNodes = selectedElements.value.filter(isNode)
|
||||
const connectedEdges = getConnectedEdges(selectedNodes, edges.value as Edge[])
|
||||
const elementsToRemove = [...selectedElements.value, ...connectedEdges].reduce(
|
||||
(res, item) => res.set(item.id, item),
|
||||
new Map<ElementId, FlowElement>()
|
||||
new Map<ElementId, FlowElement>(),
|
||||
)
|
||||
|
||||
onElementsRemove(Array.from(elementsToRemove.values()))
|
||||
@@ -31,7 +32,8 @@ export default ({ store, deleteKeyCode, multiSelectionKeyCode, onElementsRemove
|
||||
}
|
||||
})
|
||||
|
||||
watch(multiSelectionKeyPressed, () => {
|
||||
watch(multiSelectionKeyPressed, () => {
|
||||
store.multiSelectionActive = multiSelectionKeyPressed.value
|
||||
})
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user