refactor(store): move hooks to store dir
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
export { default as useHandle } from './useHandle'
|
export { default as useHandle } from './useHandle'
|
||||||
export { default as useHooks } from './useHooks'
|
|
||||||
export * from './useHooks'
|
|
||||||
export { default as useKeyPress } from './useKeyPress'
|
export { default as useKeyPress } from './useKeyPress'
|
||||||
export { default as useZoomPanHelper } from './useZoomPanHelper'
|
export { default as useZoomPanHelper } from './useZoomPanHelper'
|
||||||
export { default as useWindow } from './useWindow'
|
export { default as useWindow } from './useWindow'
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import useHooks from './useHooks'
|
|
||||||
import {
|
import {
|
||||||
EdgeChange,
|
EdgeChange,
|
||||||
EmitFunc,
|
EmitFunc,
|
||||||
@@ -10,8 +9,9 @@ import {
|
|||||||
FlowElement,
|
FlowElement,
|
||||||
GraphNode,
|
GraphNode,
|
||||||
GraphEdge,
|
GraphEdge,
|
||||||
|
SelectionChange,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
import { useStore } from '~/store'
|
import { useStore, useHooks } from '~/store'
|
||||||
import { isGraphNode } from '~/utils'
|
import { isGraphNode } from '~/utils'
|
||||||
|
|
||||||
const applyChanges = (changes: NodeChange[] | EdgeChange[], elements: FlowElements): FlowElements => {
|
const applyChanges = (changes: NodeChange[] | EdgeChange[], elements: FlowElements): FlowElements => {
|
||||||
@@ -64,15 +64,16 @@ export const applyNodeChanges = (changes: NodeChange[], nodes: GraphNode[]): Gra
|
|||||||
export const applyEdgeChanges = (changes: EdgeChange[], edges: GraphEdge[]): GraphEdge[] =>
|
export const applyEdgeChanges = (changes: EdgeChange[], edges: GraphEdge[]): GraphEdge[] =>
|
||||||
<GraphEdge[]>applyChanges(changes, edges)
|
<GraphEdge[]>applyChanges(changes, edges)
|
||||||
|
|
||||||
export const createSelectionChange = (id: string, selected: boolean) => ({
|
export const createSelectionChange = (id: string, selected: boolean): SelectionChange => ({
|
||||||
id,
|
id,
|
||||||
type: 'select',
|
type: 'select',
|
||||||
selected,
|
selected,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getSelectionChanges = (items: any[], selectedIds: string[]) => {
|
export const getSelectionChanges = (items: FlowElements, selectedIds: string[]) => {
|
||||||
return items.reduce((res, item) => {
|
return items.reduce((res, item) => {
|
||||||
const willBeSelected = selectedIds.includes(item.id)
|
const willBeSelected =
|
||||||
|
selectedIds.includes(item.id) || (isGraphNode(item) && item.parentNode && selectedIds.includes(item.parentNode?.id))
|
||||||
|
|
||||||
if (!item.selected && willBeSelected) {
|
if (!item.selected && willBeSelected) {
|
||||||
item.selected = true
|
item.selected = true
|
||||||
@@ -83,7 +84,7 @@ export const getSelectionChanges = (items: any[], selectedIds: string[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}, [])
|
}, [] as SelectionChange[])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initFlow = (emit: EmitFunc, id?: string): FlowStore => {
|
export const initFlow = (emit: EmitFunc, id?: string): FlowStore => {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export const createHooks = (): FlowHooks => ({
|
|||||||
move: createEventHook(),
|
move: createEventHook(),
|
||||||
moveStart: createEventHook(),
|
moveStart: createEventHook(),
|
||||||
moveEnd: createEventHook(),
|
moveEnd: createEventHook(),
|
||||||
selectionChange: createEventHook(),
|
|
||||||
selectionDragStart: createEventHook(),
|
selectionDragStart: createEventHook(),
|
||||||
selectionDrag: createEventHook(),
|
selectionDrag: createEventHook(),
|
||||||
selectionDragStop: createEventHook(),
|
selectionDragStop: createEventHook(),
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
export { default as useHooks } from './hooks'
|
||||||
export { default as useStore } from './store'
|
export { default as useStore } from './store'
|
||||||
export * from './state'
|
export * from './state'
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
|
import { createHooks } from './hooks'
|
||||||
import { ConnectionMode, FlowState, PanOnScrollMode, DefaultNodeTypes, DefaultEdgeTypes, ConnectionLineType } from '~/types'
|
import { ConnectionMode, FlowState, PanOnScrollMode, DefaultNodeTypes, DefaultEdgeTypes, ConnectionLineType } from '~/types'
|
||||||
import { DefaultNode, InputNode, OutputNode, BezierEdge, SmoothStepEdge, StepEdge, StraightEdge } from '~/components'
|
import { DefaultNode, InputNode, OutputNode, BezierEdge, SmoothStepEdge, StepEdge, StraightEdge } from '~/components'
|
||||||
import { createHooks } from '~/composables'
|
|
||||||
|
|
||||||
export const defaultNodeTypes: DefaultNodeTypes = {
|
export const defaultNodeTypes: DefaultNodeTypes = {
|
||||||
input: InputNode,
|
input: InputNode,
|
||||||
|
|||||||
Reference in New Issue
Block a user