Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/readonly-cut-paste-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflowbuilder/sdk': patch
---

We are blocking cut and paste actions in the diagram in read-only mode; copying is still allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getStoreSelection,
resetStoreSelection,
trackFutureChange,
useStore,
} from '@workflowbuilder/sdk';
import { useReactFlow } from '@xyflow/react';
import { type ReactNode, useCallback } from 'react';
Expand All @@ -27,6 +28,7 @@ const getHandleIdForCopyPaste: GetHandleId = (params) => {
};

function CopyPasteProviderComponent({ children }: CopyPasteProviderProps) {
const isReadOnlyMode = useStore((store) => store.isReadOnlyMode);
const mousePosition = useFlowMousePosition();

const { setNodes, setEdges } = useReactFlow();
Expand All @@ -44,22 +46,30 @@ function CopyPasteProviderComponent({ children }: CopyPasteProviderProps) {
});

const handleCut = useCallback(() => {
if (isReadOnlyMode) {
return;
}

const selection = getStoreSelection();

if (selection) {
trackFutureChange('cut');
cut();
}
}, [cut]);
}, [cut, isReadOnlyMode]);

const handlePaste = useCallback(async () => {
if (isReadOnlyMode) {
return;
}

const text = await navigator.clipboard.readText();

if (text) {
trackFutureChange('paste');
paste({ mousePosition: mousePosition.flow });
}
}, [mousePosition.flow, paste]);
}, [isReadOnlyMode, mousePosition.flow, paste]);

useCopyPasteKeyboardHandler({
handleCut,
Expand Down
Loading