refactor(store): Rename isReady to paneReady
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -187,7 +187,7 @@ onMounted(() => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
nextTick(async () => {
|
nextTick(async () => {
|
||||||
store.isReady = true
|
store.paneReady = true
|
||||||
|
|
||||||
// if ssr we can't wait for dimensions, they'll never really exist
|
// if ssr we can't wait for dimensions, they'll never really exist
|
||||||
const window = useWindow()
|
const window = useWindow()
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export default (state: FlowState, getters: FlowGetters): FlowActions => {
|
|||||||
if (typeof opts.snapToGrid !== 'undefined') state.snapToGrid = opts.snapToGrid
|
if (typeof opts.snapToGrid !== 'undefined') state.snapToGrid = opts.snapToGrid
|
||||||
if (typeof opts.snapGrid !== 'undefined') state.snapGrid = opts.snapGrid
|
if (typeof opts.snapGrid !== 'undefined') state.snapGrid = opts.snapGrid
|
||||||
if (typeof opts.nodeExtent !== 'undefined') state.nodeExtent = opts.nodeExtent
|
if (typeof opts.nodeExtent !== 'undefined') state.nodeExtent = opts.nodeExtent
|
||||||
if (!state.isReady)
|
if (!state.paneReady)
|
||||||
until(() => state.d3Zoom)
|
until(() => state.d3Zoom)
|
||||||
.not.toBeUndefined()
|
.not.toBeUndefined()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default (state: FlowState): FlowGetters => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getNodes = computed<GraphNode[]>(() => {
|
const getNodes = computed<GraphNode[]>(() => {
|
||||||
if (state.isReady && state.dimensions.width && state.dimensions.height) {
|
if (state.paneReady && state.dimensions.width && state.dimensions.height) {
|
||||||
const nodes = state.nodes.filter((n) => !n.hidden)
|
const nodes = state.nodes.filter((n) => !n.hidden)
|
||||||
return state.onlyRenderVisibleElements
|
return state.onlyRenderVisibleElements
|
||||||
? nodes &&
|
? nodes &&
|
||||||
@@ -43,8 +43,8 @@ export default (state: FlowState): FlowGetters => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getEdges = computed<GraphEdge[]>(() => {
|
const getEdges = computed<GraphEdge[]>(() => {
|
||||||
if (state.isReady && state.dimensions.width && state.dimensions.height) {
|
if (state.paneReady && state.dimensions.width && state.dimensions.height) {
|
||||||
if (!state.onlyRenderVisibleElements) return state.edges
|
if (!state.onlyRenderVisibleElements) return state.edges.filter((e) => !e.hidden)
|
||||||
else
|
else
|
||||||
return state.edges.filter(
|
return state.edges.filter(
|
||||||
(e) =>
|
(e) =>
|
||||||
|
|||||||
+1
-2
@@ -16,11 +16,10 @@ export const defaultEdgeTypes: DefaultEdgeTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default (): FlowState => ({
|
export default (): FlowState => ({
|
||||||
elements: [],
|
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
|
|
||||||
isReady: false,
|
paneReady: false,
|
||||||
instance: undefined,
|
instance: undefined,
|
||||||
|
|
||||||
dimensions: {
|
dimensions: {
|
||||||
|
|||||||
+3
-6
@@ -1,7 +1,7 @@
|
|||||||
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 { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, Store } from '~/types'
|
import { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, GraphEdge, GraphNode, Store } from '~/types'
|
||||||
import { onLoadToObject } from '~/utils'
|
import { onLoadToObject } from '~/utils'
|
||||||
|
|
||||||
const useFlowStore = (id: string, preloadedState: FlowState): Store => {
|
const useFlowStore = (id: string, preloadedState: FlowState): Store => {
|
||||||
@@ -30,7 +30,6 @@ export default (options?: FlowOptions) => {
|
|||||||
let storedState = ref<FlowExportObject>()
|
let storedState = ref<FlowExportObject>()
|
||||||
const initial = useState()
|
const initial = useState()
|
||||||
const storageKey = options?.id ?? `vue-flow-${id++}`
|
const storageKey = options?.id ?? `vue-flow-${id++}`
|
||||||
delete options?.id
|
|
||||||
const preloadedState = {
|
const preloadedState = {
|
||||||
...initial,
|
...initial,
|
||||||
...(options as FlowState),
|
...(options as FlowState),
|
||||||
@@ -38,10 +37,8 @@ export default (options?: FlowOptions) => {
|
|||||||
if (withStorage) {
|
if (withStorage) {
|
||||||
storedState = useStorage<FlowExportObject>(storageKey, { edges: [], nodes: [], position: [0, 0], zoom: 0 })
|
storedState = useStorage<FlowExportObject>(storageKey, { edges: [], nodes: [], position: [0, 0], zoom: 0 })
|
||||||
if (storedState.value) {
|
if (storedState.value) {
|
||||||
preloadedState.elements =
|
preloadedState.nodes = (storedState.value.nodes ? storedState.value.nodes : options?.nodes ?? []) as GraphNode[]
|
||||||
storedState.value.nodes || storedState.value.edges
|
preloadedState.edges = (storedState.value.edges ? storedState.value.edges : options?.edges ?? []) as GraphEdge[]
|
||||||
? [...storedState.value.nodes, ...storedState.value.edges]
|
|
||||||
: options?.elements ?? []
|
|
||||||
if (storedState.value.position && storedState.value.zoom)
|
if (storedState.value.position && storedState.value.zoom)
|
||||||
preloadedState.transform = [storedState.value.position[0], storedState.value.position[1], storedState.value.zoom]
|
preloadedState.transform = [storedState.value.position[0], storedState.value.position[1], storedState.value.zoom]
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -8,11 +8,10 @@ import { GraphNode, CoordinateExtent, Node } from './node'
|
|||||||
import { D3Selection, D3Zoom, D3ZoomHandler, KeyCode, PanOnScrollMode } from './zoom'
|
import { D3Selection, D3Zoom, D3ZoomHandler, KeyCode, PanOnScrollMode } from './zoom'
|
||||||
import { FlowHooks, FlowHooksOn } from './hooks'
|
import { FlowHooks, FlowHooksOn } from './hooks'
|
||||||
|
|
||||||
export interface FlowState<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id'> {
|
export interface FlowState<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id' | 'elements'> {
|
||||||
hooks: FlowHooks
|
hooks: FlowHooks
|
||||||
instance?: FlowInstance
|
instance?: FlowInstance
|
||||||
|
|
||||||
elements: Elements
|
|
||||||
nodes: GraphNode<N>[]
|
nodes: GraphNode<N>[]
|
||||||
edges: GraphEdge<E>[]
|
edges: GraphEdge<E>[]
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ export interface FlowState<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id'>
|
|||||||
zoomOnDoubleClick: boolean
|
zoomOnDoubleClick: boolean
|
||||||
preventScrolling: boolean
|
preventScrolling: boolean
|
||||||
|
|
||||||
isReady: boolean
|
paneReady: boolean
|
||||||
|
|
||||||
vueFlowVersion: string
|
vueFlowVersion: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user