update(types): Rename FlowStore to Store and ReactiveFlowStore to FlowStore
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import useStore from './useStore'
|
import useStore from './useStore'
|
||||||
import { getHostForElement } from '~/utils'
|
import { getHostForElement } from '~/utils'
|
||||||
import { Connection, ConnectionMode, ElementId, HandleType, ReactiveFlowStore, ValidConnectionFunc } from '~/types'
|
import { Connection, ConnectionMode, ElementId, HandleType, FlowStore, ValidConnectionFunc } from '~/types'
|
||||||
|
|
||||||
type Result = {
|
type Result = {
|
||||||
elementBelow: Element | null
|
elementBelow: Element | null
|
||||||
@@ -67,7 +67,7 @@ const resetRecentHandle = (hoveredHandle: Element): void => {
|
|||||||
hoveredHandle?.classList.remove('vue-flow__handle-connecting')
|
hoveredHandle?.classList.remove('vue-flow__handle-connecting')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (store: ReactiveFlowStore = useStore()) =>
|
export default (store: FlowStore = useStore()) =>
|
||||||
(
|
(
|
||||||
event: MouseEvent,
|
event: MouseEvent,
|
||||||
handleId: ElementId,
|
handleId: ElementId,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EmitFunc, FlowHooks, FlowEvents, FlowStore, ReactiveFlowStore } from '~/types'
|
import { EmitFunc, FlowHooks, FlowEvents, FlowStore } from '~/types'
|
||||||
|
|
||||||
// flow event hooks
|
// flow event hooks
|
||||||
export const createHooks = (): FlowHooks => ({
|
export const createHooks = (): FlowHooks => ({
|
||||||
@@ -49,4 +49,4 @@ const bind = (emit: EmitFunc, hooks: FlowHooks) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (store: ReactiveFlowStore, emit: EmitFunc) => bind(emit, store.hooks)
|
export default (store: FlowStore, emit: EmitFunc) => bind(emit, store.hooks)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FlowExportObject, FlowOptions, FlowState, ReactiveFlowStore } from '~/types'
|
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
|
||||||
import { useNewStore } from '~/store'
|
import { useNewStore } from '~/store'
|
||||||
import { Store } from '~/context'
|
import { StoreSymbol } from '~/context'
|
||||||
import { onLoadToObject, initialState } from '~/utils'
|
import { onLoadToObject, initialState } from '~/utils'
|
||||||
|
|
||||||
let id = 0
|
let id = 0
|
||||||
@@ -35,12 +35,12 @@ export const createStore = (options?: FlowOptions) => {
|
|||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (options?: FlowOptions): ReactiveFlowStore => {
|
export default (options?: FlowOptions): FlowStore => {
|
||||||
let store = options?.id ? createStore(options) : inject(Store, undefined)
|
let store = options?.id ? createStore(options) : inject(StoreSymbol, undefined)
|
||||||
if (!store) {
|
if (!store) {
|
||||||
store = createStore(options)
|
store = createStore(options)
|
||||||
}
|
}
|
||||||
provide(Store, store)
|
provide(StoreSymbol, store)
|
||||||
|
|
||||||
return reactive(store)
|
return reactive(store)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import useStore from './useStore'
|
import useStore from './useStore'
|
||||||
import useHooks from './useHooks'
|
import useHooks from './useHooks'
|
||||||
import { EmitFunc, ReactiveFlowStore } from '~/types'
|
import { EmitFunc, FlowStore } from '~/types'
|
||||||
|
|
||||||
let key = 0
|
let key = 0
|
||||||
export const initFlow = (emit: EmitFunc, id = `vue-flow-${key++}`): ReactiveFlowStore => {
|
export const initFlow = (emit: EmitFunc, id = `vue-flow-${key++}`): FlowStore => {
|
||||||
const store = useStore({ id })
|
const store = useStore({ id })
|
||||||
useHooks(store, emit)
|
useHooks(store, emit)
|
||||||
return store
|
return store
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { zoomIdentity } from 'd3-zoom'
|
import { zoomIdentity } from 'd3-zoom'
|
||||||
import useStore from './useStore'
|
import useStore from './useStore'
|
||||||
import { getRectOfNodes, pointToRendererPoint, getTransformForBounds, isGraphNode } from '~/utils'
|
import { getRectOfNodes, pointToRendererPoint, getTransformForBounds, isGraphNode } from '~/utils'
|
||||||
import { FitViewParams, FlowTransform, GraphNode, ReactiveFlowStore, Rect, UseZoomPanHelper, XYPosition } from '~/types'
|
import { FitViewParams, FlowTransform, GraphNode, FlowStore, Rect, UseZoomPanHelper, XYPosition } from '~/types'
|
||||||
|
|
||||||
const DEFAULT_PADDING = 0.1
|
const DEFAULT_PADDING = 0.1
|
||||||
|
|
||||||
export default (store: ReactiveFlowStore = useStore()): UseZoomPanHelper => {
|
export default (store: FlowStore = useStore()): UseZoomPanHelper => {
|
||||||
return {
|
return {
|
||||||
zoomIn: () => store.d3Selection && store.d3Zoom?.scaleBy(store.d3Selection, 1.2),
|
zoomIn: () => store.d3Selection && store.d3Zoom?.scaleBy(store.d3Selection, 1.2),
|
||||||
zoomOut: () => store.d3Selection && store.d3Zoom?.scaleBy(store.d3Selection, 1 / 1.2),
|
zoomOut: () => store.d3Selection && store.d3Zoom?.scaleBy(store.d3Selection, 1 / 1.2),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { InjectionKey } from 'vue'
|
import { InjectionKey } from 'vue'
|
||||||
import { ElementId, FlowStore } from '~/types'
|
import { ElementId, Store as TStore } from '~/types'
|
||||||
|
|
||||||
export const Store: InjectionKey<FlowStore> = Symbol('store')
|
export const StoreSymbol: InjectionKey<TStore> = Symbol('store')
|
||||||
export const NodeId: InjectionKey<ElementId> = Symbol('nodeId')
|
export const NodeId: InjectionKey<ElementId> = Symbol('nodeId')
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
import useState from './state'
|
import useState from './state'
|
||||||
import useActions from './actions'
|
import useActions from './actions'
|
||||||
import useGetters from './getters'
|
import useGetters from './getters'
|
||||||
import { FlowState, FlowStore } from '~/types'
|
import { FlowState, Store } from '~/types'
|
||||||
|
|
||||||
export default (id: string, preloadedState: FlowState): FlowStore => {
|
export default (id: string, preloadedState: FlowState): Store => {
|
||||||
const state = reactive(useState(preloadedState))
|
const state = reactive(useState(preloadedState))
|
||||||
const getters = useGetters(state)
|
const getters = useGetters(state)
|
||||||
const actions = useActions(state, getters)
|
const actions = useActions(state, getters)
|
||||||
|
|||||||
+2
-2
@@ -89,5 +89,5 @@ export interface FlowGetters {
|
|||||||
getSelectedNodes: ComputedRef<GraphNode[]>
|
getSelectedNodes: ComputedRef<GraphNode[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FlowStore = { state: FlowState } & ToRefs<FlowState> & FlowActions & FlowGetters
|
export type Store = { state: FlowState } & ToRefs<FlowState> & FlowActions & FlowGetters
|
||||||
export type ReactiveFlowStore = UnwrapNestedRefs<FlowStore>
|
export type FlowStore = UnwrapNestedRefs<Store>
|
||||||
|
|||||||
+3
-4
@@ -11,12 +11,11 @@ import {
|
|||||||
FlowExportObject,
|
FlowExportObject,
|
||||||
NodeExtent,
|
NodeExtent,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
FlowStore,
|
|
||||||
GraphNode,
|
GraphNode,
|
||||||
FlowElements,
|
FlowElements,
|
||||||
GraphEdge,
|
GraphEdge,
|
||||||
NextElements,
|
NextElements,
|
||||||
ReactiveFlowStore,
|
FlowStore,
|
||||||
FlowState,
|
FlowState,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
import { useWindow } from '~/composables'
|
import { useWindow } from '~/composables'
|
||||||
@@ -163,7 +162,7 @@ export const pointToRendererPoint = (
|
|||||||
return position
|
return position
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onLoadProject = (currentStore: ReactiveFlowStore) => (position: XYPosition) =>
|
export const onLoadProject = (currentStore: FlowStore) => (position: XYPosition) =>
|
||||||
pointToRendererPoint(position, currentStore.transform, currentStore.snapToGrid, currentStore.snapGrid)
|
pointToRendererPoint(position, currentStore.transform, currentStore.snapToGrid, currentStore.snapGrid)
|
||||||
|
|
||||||
export const parseNode = (node: Node, nodeExtent: NodeExtent): GraphNode => ({
|
export const parseNode = (node: Node, nodeExtent: NodeExtent): GraphNode => ({
|
||||||
@@ -278,7 +277,7 @@ export const getConnectedEdges = (nodes: GraphNode[], edges: GraphEdge[]) => {
|
|||||||
return edges.filter((edge) => nodeIds.includes(edge.source) || nodeIds.includes(edge.target))
|
return edges.filter((edge) => nodeIds.includes(edge.source) || nodeIds.includes(edge.target))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onLoadGetElements = (currentStore: ReactiveFlowStore) => (): FlowElements => currentStore.elements
|
export const onLoadGetElements = (currentStore: FlowStore) => (): FlowElements => currentStore.elements
|
||||||
|
|
||||||
export const onLoadToObject = (currentStore: FlowState) => (): FlowExportObject => {
|
export const onLoadToObject = (currentStore: FlowState) => (): FlowExportObject => {
|
||||||
// we have to stringify/parse so objects containing refs (like nodes and edges) can potentially be saved in a storage
|
// we have to stringify/parse so objects containing refs (like nodes and edges) can potentially be saved in a storage
|
||||||
|
|||||||
Reference in New Issue
Block a user