From a493168daf88e7488e668a9b5fedfdeaee37d4ab Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 18 Nov 2021 18:04:50 +0100 Subject: [PATCH] feat: Add useVueFlow composable * Allows for use of the vue flow instance without having to listen to the onLoad event * fix usekeypress export * Add types for controls events Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../Controls/Controls.vue | 13 +++++++---- src/composables/index.ts | 1 + src/composables/useVueFlow.ts | 22 +++++++++++++++++++ src/index.ts | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/composables/useVueFlow.ts diff --git a/src/additional-components/Controls/Controls.vue b/src/additional-components/Controls/Controls.vue index de9e5531..b9264c6d 100644 --- a/src/additional-components/Controls/Controls.vue +++ b/src/additional-components/Controls/Controls.vue @@ -16,19 +16,24 @@ export interface ControlProps extends HTMLAttributes { fitViewParams?: FitViewParams } +interface ControlEvents { + (event: 'zoom-in'): void + (event: 'zoom-out'): void + (event: 'fit-view'): void + (event: 'interaction-change', active: boolean): void +} + const props = withDefaults(defineProps(), { showZoom: true, showFitView: true, showInteractive: true, }) -// todo define types for events -const emit = defineEmits(['zoom-in', 'zoom-out', 'fit-view', 'interaction-change']) +const emit = defineEmits() const store = useStore() const { zoomIn, zoomOut, fitView } = useZoomPanHelper() const isInteractive = computed(() => store.nodesDraggable && store.nodesConnectable && store.elementsSelectable) -const mapClasses = ['vue-flow__controls'] const onZoomInHandler = () => { zoomIn() @@ -51,7 +56,7 @@ const onInteractiveChangeHandler = () => { }