mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(editor): Fit view consistently after nodes are initialized on new canvas (#11457)
This commit is contained in:
@@ -41,7 +41,6 @@ import { GRID_SIZE } from '@/utils/nodeViewUtils';
|
|||||||
import { CanvasKey } from '@/constants';
|
import { CanvasKey } from '@/constants';
|
||||||
import { onKeyDown, onKeyUp, useDebounceFn } from '@vueuse/core';
|
import { onKeyDown, onKeyUp, useDebounceFn } from '@vueuse/core';
|
||||||
import CanvasArrowHeadMarker from './elements/edges/CanvasArrowHeadMarker.vue';
|
import CanvasArrowHeadMarker from './elements/edges/CanvasArrowHeadMarker.vue';
|
||||||
import { CanvasNodeRenderType } from '@/types';
|
|
||||||
import CanvasBackgroundStripedPattern from './elements/CanvasBackgroundStripedPattern.vue';
|
import CanvasBackgroundStripedPattern from './elements/CanvasBackgroundStripedPattern.vue';
|
||||||
import { isMiddleMouseButton } from '@/utils/eventUtils';
|
import { isMiddleMouseButton } from '@/utils/eventUtils';
|
||||||
|
|
||||||
@@ -123,7 +122,6 @@ const {
|
|||||||
nodes: graphNodes,
|
nodes: graphNodes,
|
||||||
onPaneReady,
|
onPaneReady,
|
||||||
findNode,
|
findNode,
|
||||||
onNodesInitialized,
|
|
||||||
viewport,
|
viewport,
|
||||||
} = useVueFlow({ id: props.id, deleteKeyCode: null });
|
} = useVueFlow({ id: props.id, deleteKeyCode: null });
|
||||||
|
|
||||||
@@ -538,11 +536,6 @@ onPaneReady(async () => {
|
|||||||
isPaneReady.value = true;
|
isPaneReady.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
onNodesInitialized((nodes) => {
|
|
||||||
if (nodes.length !== 1 || nodes[0].data?.render.type !== CanvasNodeRenderType.AddNodes) return;
|
|
||||||
void onFitView();
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(() => props.readOnly, setReadonly, {
|
watch(() => props.readOnly, setReadonly, {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Canvas from '@/components/canvas/Canvas.vue';
|
import Canvas from '@/components/canvas/Canvas.vue';
|
||||||
import { computed, toRef, useCssModule } from 'vue';
|
import { computed, ref, toRef, useCssModule } from 'vue';
|
||||||
import type { Workflow } from 'n8n-workflow';
|
import type { Workflow } from 'n8n-workflow';
|
||||||
import type { IWorkflowDb } from '@/Interface';
|
import type { IWorkflowDb } from '@/Interface';
|
||||||
import { useCanvasMapping } from '@/composables/useCanvasMapping';
|
import { useCanvasMapping } from '@/composables/useCanvasMapping';
|
||||||
import type { EventBus } from 'n8n-design-system';
|
import type { EventBus } from 'n8n-design-system';
|
||||||
import { createEventBus } from 'n8n-design-system';
|
import { createEventBus } from 'n8n-design-system';
|
||||||
import type { CanvasEventBusEvents } from '@/types';
|
import type { CanvasEventBusEvents } from '@/types';
|
||||||
|
import { useVueFlow } from '@vue-flow/core';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
@@ -34,6 +35,8 @@ const props = withDefaults(
|
|||||||
|
|
||||||
const $style = useCssModule();
|
const $style = useCssModule();
|
||||||
|
|
||||||
|
const { onNodesInitialized } = useVueFlow({ id: props.id });
|
||||||
|
|
||||||
const workflow = toRef(props, 'workflow');
|
const workflow = toRef(props, 'workflow');
|
||||||
const workflowObject = toRef(props, 'workflowObject');
|
const workflowObject = toRef(props, 'workflowObject');
|
||||||
|
|
||||||
@@ -49,6 +52,14 @@ const { nodes: mappedNodes, connections: mappedConnections } = useCanvasMapping(
|
|||||||
connections,
|
connections,
|
||||||
workflowObject,
|
workflowObject,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const initialFitViewDone = ref(false); // Workaround for https://github.com/bcakmakoglu/vue-flow/issues/1636
|
||||||
|
onNodesInitialized(() => {
|
||||||
|
if (!initialFitViewDone.value || props.showFallbackNodes) {
|
||||||
|
props.eventBus.emit('fitView');
|
||||||
|
initialFitViewDone.value = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user