Skip to content

Commit 82c6847

Browse files
feat: keyboard zoom + watermark layering fix (#53)
* feat: keyboard zoom + watermark layering fix * feat: keyboard zoom + watermark layering fix - add missing files
1 parent dc73279 commit 82c6847

6 files changed

Lines changed: 40 additions & 2 deletions

File tree

.changeset/keyboard-zoom.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@workflowbuilder/sdk': minor
3+
---
4+
5+
The editor now supports keyboard zoom: `Ctrl/Cmd` with `+`/`=` zooms in and `Ctrl/Cmd` with `-` zooms out while the canvas is focused.

apps/demo/src/app/plugins/help/components/watermark/watermark.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
opacity: 1;
1414
}
1515

16-
z-index: 5;
16+
z-index: 0;
1717

1818
:global(html[data-theme='dark']) & {
1919
path {

apps/demo/src/app/plugins/help/plugin-exports.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ import { Watermark } from './components/watermark/watermark';
66
export function plugin(): void {
77
registerComponentDecorator<DiagramContainerProps>('DiagramContainer', {
88
content: Watermark,
9+
// Render after the canvas so the watermark paints above nodes/edges,
10+
// while `z-index: 0` keeps it below the side panels (z-index: 1).
11+
place: 'after',
912
});
1013
}

apps/docs/src/content/docs/overview/features/diagram-state-management.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Workflow Builder automatically persists workflow changes in the background witho
5858
| Paste | `Ctrl+V` | `Cmd+V` |
5959
| Cut | `Ctrl+X` | `Cmd+X` |
6060
| Select all | `Ctrl+A` | `Cmd+A` |
61+
| Zoom in | `Ctrl++` | `Cmd++` |
62+
| Zoom out | `Ctrl+-` | `Cmd+-` |
6163
| Undo | `Ctrl+Z` | `Cmd+Z` |
6264
| Redo | `Ctrl+Shift+Z` | `Cmd+Shift+Z` |
6365

packages/sdk/src/hooks/use-command-handler-keyboard.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@ import { useKeyPress } from './use-key-press';
66

77
export function useCommandHandlerKeyboard(commandHandler: CommandHandler) {
88
const a = useKeyPress('a', { withControlOrMeta: true });
9+
const plus = useKeyPress('+', { withControlOrMeta: true });
10+
const equal = useKeyPress('=', { withControlOrMeta: true });
11+
const minus = useKeyPress('-', { withControlOrMeta: true });
912

1013
useEffect(() => {
1114
if (a) {
1215
commandHandler.selectAll();
1316
}
1417
}, [a]);
18+
19+
useEffect(() => {
20+
if (plus || equal) {
21+
commandHandler.zoomIn();
22+
}
23+
}, [plus, equal]);
24+
25+
useEffect(() => {
26+
if (minus) {
27+
commandHandler.zoomOut();
28+
}
29+
}, [minus]);
1530
}

packages/sdk/src/hooks/use-command-handler.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import { useOnSelectionChange, useStoreApi } from '@xyflow/react';
1+
import { useOnSelectionChange, useReactFlow, useStoreApi } from '@xyflow/react';
22
import { useCallback, useState } from 'react';
33

44
import type { WorkflowBuilderOnSelectionChangeParams } from '../node/common';
55

66
export type CommandHandler = {
77
selectAll: () => void;
8+
zoomIn: () => void;
9+
zoomOut: () => void;
810
};
911

1012
export function useCommandHandler(): CommandHandler {
1113
const [_, setSelection] = useState<WorkflowBuilderOnSelectionChangeParams>();
1214
const reactFlowStore = useStoreApi();
15+
const { zoomIn, zoomOut } = useReactFlow();
1316

1417
useOnSelectionChange({
1518
onChange: (change) => setSelection(change as WorkflowBuilderOnSelectionChangeParams),
@@ -21,7 +24,17 @@ export function useCommandHandler(): CommandHandler {
2124
state.addSelectedEdges(state.edges.map((edge) => edge.id));
2225
}, [reactFlowStore]);
2326

27+
const zoomInCommand = useCallback(() => {
28+
zoomIn();
29+
}, [zoomIn]);
30+
31+
const zoomOutCommand = useCallback(() => {
32+
zoomOut();
33+
}, [zoomOut]);
34+
2435
return {
2536
selectAll,
37+
zoomIn: zoomInCommand,
38+
zoomOut: zoomOutCommand,
2639
};
2740
}

0 commit comments

Comments
 (0)