diff --git a/examples/router.ts b/examples/router.ts index bd1c81c3..f539b24b 100644 --- a/examples/router.ts +++ b/examples/router.ts @@ -13,6 +13,10 @@ export const routes: RouterOptions['routes'] = [ path: '/basic', component: () => import('./Basic/Basic.vue'), }, + { + path: '/basic-options-api', + component: () => import('./Basic/BasicOptionsAPI.vue'), + }, { path: '/custom-connectionline', component: () => import('./CustomConnectionLine/CustomConnectionLine.vue'), diff --git a/src/components/Edges/BezierEdge.vue b/src/components/Edges/BezierEdge.vue index cf8f551f..2bb762ba 100644 --- a/src/components/Edges/BezierEdge.vue +++ b/src/components/Edges/BezierEdge.vue @@ -9,6 +9,7 @@ const props = withDefaults(defineProps(), { sourcePosition: 'bottom' as Position, targetPosition: 'top' as Position, labelStyle: () => ({}), + label: () => '', labelShowBg: true, labelBgStyle: () => ({}), }) diff --git a/src/components/Edges/SmoothStepEdge.vue b/src/components/Edges/SmoothStepEdge.vue index 0ad70c7f..433cf58d 100644 --- a/src/components/Edges/SmoothStepEdge.vue +++ b/src/components/Edges/SmoothStepEdge.vue @@ -8,7 +8,7 @@ const props = withDefaults(defineProps(), { selected: false, sourcePosition: 'bottom' as Position, targetPosition: 'top' as Position, - label: '', + label: () => '', labelStyle: () => ({}), labelShowBg: true, labelBgStyle: () => ({}), diff --git a/src/components/Edges/StepEdge.vue b/src/components/Edges/StepEdge.vue index 452b3973..945dc21e 100644 --- a/src/components/Edges/StepEdge.vue +++ b/src/components/Edges/StepEdge.vue @@ -7,7 +7,7 @@ const props = withDefaults(defineProps(), { selected: false, sourcePosition: 'bottom' as Position, targetPosition: 'top' as Position, - label: '', + label: () => '', labelStyle: () => ({}), labelShowBg: true, labelBgStyle: () => ({}), diff --git a/src/components/Edges/StraightEdge.vue b/src/components/Edges/StraightEdge.vue index eb6eeae2..655a28db 100644 --- a/src/components/Edges/StraightEdge.vue +++ b/src/components/Edges/StraightEdge.vue @@ -8,7 +8,7 @@ const props = withDefaults(defineProps(), { selected: false, sourcePosition: 'bottom' as Position, targetPosition: 'top' as Position, - label: '', + label: () => '', labelStyle: () => ({}), labelShowBg: true, labelBgStyle: () => ({}), diff --git a/src/composables/useVueFlow.ts b/src/composables/useVueFlow.ts index b7e55d8a..989e1b81 100644 --- a/src/composables/useVueFlow.ts +++ b/src/composables/useVueFlow.ts @@ -19,7 +19,7 @@ export default (options?: Partial>): UseVueFlo ...store.getters, ...store.actions, ...store.hooksOn, - } as unknown as UseVueFlow + } as unknown as UseVueFlow } if (currentInstance) { provide(VueFlow, vueFlow) diff --git a/src/store/actions.ts b/src/store/actions.ts index 81383781..092b43c2 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -2,7 +2,7 @@ import { CoordinateExtent, EdgeChange, Actions, - Getters, + ComputedGetters, State, GraphNode, Node, @@ -101,7 +101,7 @@ export const parseChildren = ( } } -export default (state: State, getters: Getters): Actions => { +export default (state: State, getters: ComputedGetters): Actions => { const updateNodePosition: Actions['updateNodePosition'] = ({ id, diff = { x: 0, y: 0 }, dragging }) => { const changes: NodeDimensionChange[] = [] diff --git a/src/store/getters.ts b/src/store/getters.ts index bee2d6cd..6327fe1b 100644 --- a/src/store/getters.ts +++ b/src/store/getters.ts @@ -1,8 +1,8 @@ import { defaultEdgeTypes, defaultNodeTypes } from './state' -import { Getters, State, GraphEdge, GraphNode } from '~/types' +import { ComputedGetters, State, GraphEdge, GraphNode } from '~/types' import { getNodesInside, isEdgeVisible } from '~/utils' -export default (state: State): Getters => { +export default (state: State): ComputedGetters => { const getEdgeTypes = computed(() => { const edgeTypes: Record = { ...defaultEdgeTypes, @@ -69,17 +69,17 @@ export default (state: State): Getters => { return [] }) - const getSelectedNodes: Getters['getSelectedNodes'] = computed(() => state.nodes.filter((n) => n.selected)) - const getSelectedEdges: Getters['getSelectedEdges'] = computed(() => state.edges.filter((e) => e.selected)) - const getSelectedElements: Getters['getSelectedElements'] = computed(() => [ + const getSelectedNodes: ComputedGetters['getSelectedNodes'] = computed(() => state.nodes.filter((n) => n.selected)) + const getSelectedEdges: ComputedGetters['getSelectedEdges'] = computed(() => state.edges.filter((e) => e.selected)) + const getSelectedElements: ComputedGetters['getSelectedElements'] = computed(() => [ ...(getSelectedNodes.value ?? []), ...(getSelectedEdges.value ?? []), ]) const nodeIds = computed(() => state.nodes.map((n) => n.id)) const edgeIds = computed(() => state.edges.map((e) => e.id)) - const getNode: Getters['getNode'] = computed(() => (id: string) => state.nodes[nodeIds.value.indexOf(id)]) - const getEdge: Getters['getEdge'] = computed(() => (id: string) => state.edges[edgeIds.value.indexOf(id)]) + const getNode: ComputedGetters['getNode'] = computed(() => (id: string) => state.nodes[nodeIds.value.indexOf(id)]) + const getEdge: ComputedGetters['getEdge'] = computed(() => (id: string) => state.edges[edgeIds.value.indexOf(id)]) return { getNode, diff --git a/src/store/store.ts b/src/store/store.ts index 5d604d20..3ed329a5 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -27,5 +27,5 @@ export default (preloadedState?: FlowOptions): Store => { ...toRefs(state), ...getters, ...actions, - } + } as unknown as Store } diff --git a/src/types/flow.ts b/src/types/flow.ts index dd267dc1..a75c5c00 100644 --- a/src/types/flow.ts +++ b/src/types/flow.ts @@ -4,7 +4,7 @@ import { GraphEdge, Edge } from './edge' import { GraphNode, CoordinateExtent, Node } from './node' import { ConnectionLineType, ConnectionMode } from './connection' import { KeyCode, PanOnScrollMode, UseZoomPanHelper } from './zoom' -import { Actions, Getters, State, FlowStore } from './store' +import { Actions, ComputedGetters, State, FlowStore } from './store' import { FlowHooksOn } from './hooks' export type FlowElement = GraphNode | GraphEdge @@ -129,5 +129,5 @@ export type UseVueFlow = { store: FlowStore } & FlowHooksOn & ToRefs> & - Getters & + ComputedGetters & Actions diff --git a/src/types/store.ts b/src/types/store.ts index 02e27d55..ccaa8fb5 100644 --- a/src/types/store.ts +++ b/src/types/store.ts @@ -1,5 +1,5 @@ import { ComputedRef } from 'vue' -import { UnwrapNestedRefs, ToRefs } from '@vue/reactivity' +import { ToRefs } from '@vue/reactivity' import { Dimensions, Elements, FlowElements, FlowInstance, FlowOptions, Rect, SnapGrid, Transform, XYPosition } from './flow' import { HandleType, EdgeComponent, NodeComponent } from './components' import { Connection, ConnectionLineType, ConnectionMode, SetConnectionId } from './connection' @@ -93,22 +93,25 @@ export interface Actions { } export interface Getters { - getEdgeTypes: ComputedRef> - getNodeTypes: ComputedRef> - getNodes: ComputedRef[]> - getEdges: ComputedRef[]> - getNode: ComputedRef<(id: string) => GraphNode | undefined> - getEdge: ComputedRef<(id: string) => GraphEdge | undefined> - getSelectedElements: ComputedRef> - getSelectedNodes: ComputedRef[]> - getSelectedEdges: ComputedRef[]> + getEdgeTypes: Record + getNodeTypes: Record + getNodes: GraphNode[] + getEdges: GraphEdge[] + getNode: (id: string) => GraphNode | undefined + getEdge: (id: string) => GraphEdge | undefined + getSelectedElements: FlowElements + getSelectedNodes: GraphNode[] + getSelectedEdges: GraphEdge[] } +export type ComputedGetters = { [key in keyof Getters]: ComputedRef[key]> } + interface StoreBase { state: State actions: Actions - getters: Getters + getters: ComputedGetters hooksOn: FlowHooksOn } -export type Store = StoreBase & ToRefs> & Actions & Getters -export type FlowStore = UnwrapNestedRefs> + +export type Store = StoreBase & ToRefs> & Actions & ComputedGetters +export type FlowStore = StoreBase & State & Actions & Getters diff --git a/tsconfig.json b/tsconfig.json index a237676f..831acd5d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,8 +33,9 @@ { "transform": "typescript-transform-paths", "afterDeclarations": true } ] }, - "include": ["src", "examples"], + "include": ["src"], "exclude": [ + "examples", "node_modules", "build", "dist",