Fixed not being able to copy anywhere

This commit is contained in:
Lucas Oliveira 2024-06-13 18:18:15 -03:00 • committed by ogabrielluiz
commit 6322827ad6
3 changed files with 42 additions and 46 deletions

View file

@ -13,7 +13,7 @@ export default function SingleAlert({
return ( return (
<Transition <Transition
className="relative" className="nocopy nowheel nopan nodelete nodrag noundo relative"
show={show} show={show}
appear={true} appear={true}
enter="transition-transform duration-500 ease-out" enter="transition-transform duration-500 ease-out"

View file

@ -58,7 +58,6 @@ export default function Page({
flow: FlowType; flow: FlowType;
view?: boolean; view?: boolean;
}): JSX.Element { }): JSX.Element {
const preventDefault = true;
const uploadFlow = useFlowsManagerStore((state) => state.uploadFlow); const uploadFlow = useFlowsManagerStore((state) => state.uploadFlow);
const autoSaveCurrentFlow = useFlowsManagerStore( const autoSaveCurrentFlow = useFlowsManagerStore(
(state) => state.autoSaveCurrentFlow (state) => state.autoSaveCurrentFlow
@ -178,17 +177,17 @@ export default function Page({
}, []); }, []);
function handleUndo(e: KeyboardEvent) { function handleUndo(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "noundo")) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if (!isWrappedWithClass(e, "noundo")) {
undo(); undo();
} }
} }
function handleRedo(e: KeyboardEvent) { function handleRedo(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "noundo")) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if (!isWrappedWithClass(e, "noundo")) {
redo(); redo();
} }
} }
@ -218,34 +217,30 @@ export default function Page({
} }
function handleCopy(e: KeyboardEvent) { function handleCopy(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "nocopy")) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if ( if (window.getSelection()?.toString().length === 0 && lastSelection) {
!isWrappedWithClass(e, "nocopy") &&
window.getSelection()?.toString().length === 0 &&
lastSelection
) {
setLastCopiedSelection(_.cloneDeep(lastSelection)); setLastCopiedSelection(_.cloneDeep(lastSelection));
} }
} }
}
function handleCut(e: KeyboardEvent) { function handleCut(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "nocopy")) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if ( if (window.getSelection()?.toString().length === 0 && lastSelection) {
!isWrappedWithClass(e, "nocopy") &&
window.getSelection()?.toString().length === 0 &&
lastSelection
) {
setLastCopiedSelection(_.cloneDeep(lastSelection), true); setLastCopiedSelection(_.cloneDeep(lastSelection), true);
} }
} }
}
function handlePaste(e: KeyboardEvent) { function handlePaste(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "nocopy")) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if ( if (
!isWrappedWithClass(e, "nocopy") &&
window.getSelection()?.toString().length === 0 && window.getSelection()?.toString().length === 0 &&
lastCopiedSelection lastCopiedSelection
) { ) {
@ -256,11 +251,12 @@ export default function Page({
}); });
} }
} }
}
function handleDelete(e: KeyboardEvent) { function handleDelete(e: KeyboardEvent) {
if (!isWrappedWithClass(e, "nodelete") && lastSelection) {
e.preventDefault(); e.preventDefault();
(e as unknown as Event).stopImmediatePropagation(); (e as unknown as Event).stopImmediatePropagation();
if (!isWrappedWithClass(e, "nodelete") && lastSelection) {
takeSnapshot(); takeSnapshot();
deleteNode(lastSelection.nodes.map((node) => node.id)); deleteNode(lastSelection.nodes.map((node) => node.id));
deleteEdge(lastSelection.edges.map((edge) => edge.id)); deleteEdge(lastSelection.edges.map((edge) => edge.id));
@ -276,23 +272,23 @@ export default function Page({
const cutAction = useShortcutsStore((state) => state.cut); const cutAction = useShortcutsStore((state) => state.cut);
const pasteAction = useShortcutsStore((state) => state.paste); const pasteAction = useShortcutsStore((state) => state.paste);
//@ts-ignore //@ts-ignore
useHotkeys(undoAction, handleUndo, { preventDefault }); useHotkeys(undoAction, handleUndo);
//@ts-ignore //@ts-ignore
useHotkeys(redoAction, handleRedo, { preventDefault }); useHotkeys(redoAction, handleRedo);
//@ts-ignore //@ts-ignore
useHotkeys(groupAction, handleGroup, { preventDefault }); useHotkeys(groupAction, handleGroup);
//@ts-ignore //@ts-ignore
useHotkeys(duplicate, handleDuplicate, { preventDefault }); useHotkeys(duplicate, handleDuplicate);
//@ts-ignore //@ts-ignore
useHotkeys(copyAction, handleCopy, { preventDefault }); useHotkeys(copyAction, handleCopy);
//@ts-ignore //@ts-ignore
useHotkeys(cutAction, handleCut, { preventDefault }); useHotkeys(cutAction, handleCut);
//@ts-ignore //@ts-ignore
useHotkeys(pasteAction, handlePaste, { preventDefault }); useHotkeys(pasteAction, handlePaste);
//@ts-ignore //@ts-ignore
useHotkeys(deleteAction, handleDelete, { preventDefault }); useHotkeys(deleteAction, handleDelete);
//@ts-ignore //@ts-ignore
useHotkeys("delete", handleDelete, { preventDefault }); useHotkeys("delete", handleDelete);
useEffect(() => { useEffect(() => {
setSHowCanvas( setSHowCanvas(

View file

@ -411,7 +411,7 @@
} }
.error-build-message { .error-build-message {
@apply mt-6 w-96 cursor-pointer rounded-md bg-error-background p-4 shadow-xl; @apply mt-6 w-96 rounded-md bg-error-background p-4 shadow-xl;
} }
.error-build-message-circle { .error-build-message-circle {
@apply alert-icon text-status-red; @apply alert-icon text-status-red;