feat(svelte): add Provider
This commit is contained in:
@@ -31,16 +31,14 @@ import type { SvelteFlowStore } from './types';
|
||||
|
||||
export const key = Symbol();
|
||||
|
||||
type CreateStoreParams = Pick<SvelteFlowStore, 'nodes' | 'edges'> & { fitView?: boolean };
|
||||
type CreateStoreParams = Pick<SvelteFlowStore, 'nodes' | 'edges'>;
|
||||
|
||||
export function createStore(params?: CreateStoreParams): SvelteFlowStore {
|
||||
export function createStore(params: CreateStoreParams): SvelteFlowStore {
|
||||
const store = {
|
||||
...initialStoreState,
|
||||
...(params !== undefined ? params : {})
|
||||
...params
|
||||
};
|
||||
|
||||
let fitViewOnInitDone = false;
|
||||
|
||||
function setNodeTypes(nodeTypes: NodeTypes) {
|
||||
store.nodeTypes.set({
|
||||
...initialNodeTypes,
|
||||
@@ -120,9 +118,11 @@ export function createStore(params?: CreateStoreParams): SvelteFlowStore {
|
||||
|
||||
const { zoom: d3Zoom, selection: d3Selection } = get(store.d3);
|
||||
|
||||
fitViewOnInitDone =
|
||||
fitViewOnInitDone || (!!params?.fitView && !!d3Zoom && !!d3Selection && fitView());
|
||||
const fitViewOnInitDone =
|
||||
get(store.fitViewOnInitDone) ||
|
||||
(get(store.fitViewOnInit) && !!d3Zoom && !!d3Selection && fitView());
|
||||
|
||||
store.fitViewOnInitDone.set(fitViewOnInitDone);
|
||||
store.nodes.set(nextNodes);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ export const initialStoreState = {
|
||||
width: writable<number>(500),
|
||||
minZoom: writable<number>(0.5),
|
||||
maxZoom: writable<number>(2),
|
||||
fitViewOnInit: false,
|
||||
fitViewOnInit: writable<boolean>(false),
|
||||
fitViewOnInitDone: writable<boolean>(false),
|
||||
nodeOrigin: writable<NodeOrigin>([0, 0]),
|
||||
d3: writable<{ zoom: D3ZoomInstance | null; selection: D3SelectionInstance | null }>({
|
||||
zoom: null,
|
||||
|
||||
Reference in New Issue
Block a user