2022-11-07 00:53:27 -08:00
|
|
|
<template>
|
2022-12-01 00:26:38 -08:00
|
|
|
<div
|
|
|
|
:class="{
|
|
|
|
[$style.zoomMenu]: true,
|
|
|
|
[$style.regularZoomMenu]: !isDemo,
|
|
|
|
[$style.demoZoomMenu]: isDemo,
|
|
|
|
}"
|
|
|
|
>
|
2023-12-28 00:49:58 -08:00
|
|
|
<KeyboardShortcutTooltip
|
2023-11-20 05:37:12 -08:00
|
|
|
:label="$locale.baseText('nodeView.zoomToFit')"
|
|
|
|
:shortcut="{ keys: ['1'] }"
|
|
|
|
>
|
|
|
|
<n8n-icon-button
|
|
|
|
type="tertiary"
|
|
|
|
size="large"
|
|
|
|
icon="expand"
|
|
|
|
data-test-id="zoom-to-fit"
|
2023-12-28 00:49:58 -08:00
|
|
|
@click="zoomToFit"
|
2023-11-20 05:37:12 -08:00
|
|
|
/>
|
2023-12-28 00:49:58 -08:00
|
|
|
</KeyboardShortcutTooltip>
|
|
|
|
<KeyboardShortcutTooltip
|
2023-11-20 05:37:12 -08:00
|
|
|
:label="$locale.baseText('nodeView.zoomIn')"
|
|
|
|
:shortcut="{ keys: ['+'] }"
|
|
|
|
>
|
|
|
|
<n8n-icon-button
|
|
|
|
type="tertiary"
|
|
|
|
size="large"
|
|
|
|
icon="search-plus"
|
|
|
|
data-test-id="zoom-in-button"
|
2023-12-28 00:49:58 -08:00
|
|
|
@click="zoomIn"
|
2023-11-20 05:37:12 -08:00
|
|
|
/>
|
2023-12-28 00:49:58 -08:00
|
|
|
</KeyboardShortcutTooltip>
|
|
|
|
<KeyboardShortcutTooltip
|
2023-11-20 05:37:12 -08:00
|
|
|
:label="$locale.baseText('nodeView.zoomOut')"
|
|
|
|
:shortcut="{ keys: ['-'] }"
|
|
|
|
>
|
|
|
|
<n8n-icon-button
|
|
|
|
type="tertiary"
|
|
|
|
size="large"
|
|
|
|
icon="search-minus"
|
|
|
|
data-test-id="zoom-out-button"
|
2023-12-28 00:49:58 -08:00
|
|
|
@click="zoomOut"
|
2023-11-20 05:37:12 -08:00
|
|
|
/>
|
2023-12-28 00:49:58 -08:00
|
|
|
</KeyboardShortcutTooltip>
|
|
|
|
<KeyboardShortcutTooltip
|
2023-11-20 05:37:12 -08:00
|
|
|
:label="$locale.baseText('nodeView.resetZoom')"
|
|
|
|
:shortcut="{ keys: ['0'] }"
|
|
|
|
>
|
|
|
|
<n8n-icon-button
|
|
|
|
v-if="nodeViewScale !== 1 && !isDemo"
|
|
|
|
type="tertiary"
|
|
|
|
size="large"
|
|
|
|
icon="undo"
|
|
|
|
data-test-id="reset-zoom-button"
|
2023-12-28 00:49:58 -08:00
|
|
|
@click="resetZoom"
|
2023-11-20 05:37:12 -08:00
|
|
|
/>
|
2023-12-28 00:49:58 -08:00
|
|
|
</KeyboardShortcutTooltip>
|
2022-11-07 00:53:27 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onBeforeMount, onBeforeUnmount } from 'vue';
|
|
|
|
import { storeToRefs } from 'pinia';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useCanvasStore } from '@/stores/canvas.store';
|
2023-11-20 05:37:12 -08:00
|
|
|
import KeyboardShortcutTooltip from '@/components/KeyboardShortcutTooltip.vue';
|
2024-01-10 06:42:01 -08:00
|
|
|
import { useDeviceSupport } from 'n8n-design-system';
|
2022-11-07 00:53:27 -08:00
|
|
|
|
|
|
|
const canvasStore = useCanvasStore();
|
|
|
|
const { zoomToFit, zoomIn, zoomOut, resetZoom } = canvasStore;
|
|
|
|
const { nodeViewScale, isDemo } = storeToRefs(canvasStore);
|
2024-01-10 06:42:01 -08:00
|
|
|
const deviceSupport = useDeviceSupport();
|
2022-11-07 00:53:27 -08:00
|
|
|
|
|
|
|
const keyDown = (e: KeyboardEvent) => {
|
2024-01-10 06:42:01 -08:00
|
|
|
const isCtrlKeyPressed = deviceSupport.isCtrlKeyPressed(e);
|
2022-11-07 00:53:27 -08:00
|
|
|
if ((e.key === '=' || e.key === '+') && !isCtrlKeyPressed) {
|
|
|
|
zoomIn();
|
|
|
|
} else if ((e.key === '_' || e.key === '-') && !isCtrlKeyPressed) {
|
|
|
|
zoomOut();
|
|
|
|
} else if (e.key === '0' && !isCtrlKeyPressed) {
|
|
|
|
resetZoom();
|
|
|
|
} else if (e.key === '1' && !isCtrlKeyPressed) {
|
|
|
|
zoomToFit();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
document.addEventListener('keydown', keyDown);
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
document.removeEventListener('keydown', keyDown);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.zoomMenu {
|
|
|
|
position: absolute;
|
|
|
|
width: 210px;
|
2024-01-08 04:44:56 -08:00
|
|
|
bottom: var(--spacing-l);
|
|
|
|
left: var(--spacing-l);
|
2022-11-07 00:53:27 -08:00
|
|
|
line-height: 25px;
|
|
|
|
color: #444;
|
|
|
|
padding-right: 5px;
|
|
|
|
|
|
|
|
button {
|
|
|
|
border: var(--border-base);
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
+ * {
|
|
|
|
margin-left: var(--spacing-3xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
transform: scale(1.1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.regularZoomMenu {
|
|
|
|
@media (max-width: $breakpoint-2xs) {
|
|
|
|
bottom: 90px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.demoZoomMenu {
|
|
|
|
left: 10px;
|
|
|
|
bottom: 10px;
|
|
|
|
}
|
|
|
|
</style>
|