diff --git a/.changeset/readonly-cut-paste-block.md b/.changeset/readonly-cut-paste-block.md new file mode 100644 index 000000000..9187c7b1d --- /dev/null +++ b/.changeset/readonly-cut-paste-block.md @@ -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. diff --git a/apps/demo/src/app/plugins/copy-paste/providers/copy-paste-provider.ts b/apps/demo/src/app/plugins/copy-paste/providers/copy-paste-provider.ts index b7d145f60..20b8680c6 100644 --- a/apps/demo/src/app/plugins/copy-paste/providers/copy-paste-provider.ts +++ b/apps/demo/src/app/plugins/copy-paste/providers/copy-paste-provider.ts @@ -4,6 +4,7 @@ import { getStoreSelection, resetStoreSelection, trackFutureChange, + useStore, } from '@workflowbuilder/sdk'; import { useReactFlow } from '@xyflow/react'; import { type ReactNode, useCallback } from 'react'; @@ -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(); @@ -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,