mirror of
https://github.com/OFFIS-ESC/constellation-analyzer
synced 2026-01-27 07:43:41 +00:00
fix: resolve effect dependencies
This commit is contained in:
parent
79bfd525dd
commit
75cb26a991
2 changed files with 78 additions and 76 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import ConfirmDialog, { ConfirmDialogSeverity } from '../components/Common/ConfirmDialog';
|
||||
import { useState, useCallback } from "react";
|
||||
import ConfirmDialog, {
|
||||
ConfirmDialogSeverity,
|
||||
} from "../components/Common/ConfirmDialog";
|
||||
|
||||
/**
|
||||
* useConfirm Hook
|
||||
|
|
@ -47,11 +49,11 @@ interface ConfirmState extends ConfirmOptions {
|
|||
export const useConfirm = () => {
|
||||
const [state, setState] = useState<ConfirmState>({
|
||||
isOpen: false,
|
||||
title: '',
|
||||
message: '',
|
||||
confirmLabel: 'Confirm',
|
||||
cancelLabel: 'Cancel',
|
||||
severity: 'warning',
|
||||
title: "",
|
||||
message: "",
|
||||
confirmLabel: "Confirm",
|
||||
cancelLabel: "Cancel",
|
||||
severity: "warning",
|
||||
});
|
||||
|
||||
const confirm = useCallback((options: ConfirmOptions): Promise<boolean> => {
|
||||
|
|
@ -67,12 +69,12 @@ export const useConfirm = () => {
|
|||
const handleConfirm = useCallback(() => {
|
||||
state.resolve?.(true);
|
||||
setState((prev) => ({ ...prev, isOpen: false }));
|
||||
}, [state.resolve]);
|
||||
}, [state]);
|
||||
|
||||
const handleCancel = useCallback(() => {
|
||||
state.resolve?.(false);
|
||||
setState((prev) => ({ ...prev, isOpen: false }));
|
||||
}, [state.resolve]);
|
||||
}, [state]);
|
||||
|
||||
const ConfirmDialogComponent = (
|
||||
<ConfirmDialog
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useKeyboardShortcuts } from '../contexts/KeyboardShortcutContext';
|
||||
import { useWorkspaceStore } from '../stores/workspaceStore';
|
||||
import type { KeyboardShortcut } from './useKeyboardShortcutManager';
|
||||
import { useEffect } from "react";
|
||||
import { useKeyboardShortcuts } from "../contexts/KeyboardShortcutContext";
|
||||
import { useWorkspaceStore } from "../stores/workspaceStore";
|
||||
import type { KeyboardShortcut } from "./useKeyboardShortcutManager";
|
||||
|
||||
/**
|
||||
* useGlobalShortcuts Hook
|
||||
|
|
@ -34,156 +34,161 @@ export function useGlobalShortcuts(options: UseGlobalShortcutsOptions = {}) {
|
|||
const shortcutDefinitions: KeyboardShortcut[] = [
|
||||
// Document Management
|
||||
{
|
||||
id: 'new-document',
|
||||
description: 'New Document',
|
||||
key: 'n',
|
||||
id: "new-document",
|
||||
description: "New Document",
|
||||
key: "n",
|
||||
ctrl: true,
|
||||
handler: () => createDocument(),
|
||||
category: 'Document Management',
|
||||
category: "Document Management",
|
||||
},
|
||||
{
|
||||
id: 'open-document-manager',
|
||||
description: 'Document Manager',
|
||||
key: 'o',
|
||||
id: "open-document-manager",
|
||||
description: "Document Manager",
|
||||
key: "o",
|
||||
ctrl: true,
|
||||
handler: () => options.onOpenDocumentManager?.(),
|
||||
category: 'Document Management',
|
||||
category: "Document Management",
|
||||
enabled: !!options.onOpenDocumentManager,
|
||||
},
|
||||
{
|
||||
id: 'save-document',
|
||||
description: 'Export Document',
|
||||
key: 's',
|
||||
id: "save-document",
|
||||
description: "Export Document",
|
||||
key: "s",
|
||||
ctrl: true,
|
||||
handler: () => {
|
||||
if (activeDocumentId) {
|
||||
saveDocument(activeDocumentId);
|
||||
}
|
||||
},
|
||||
category: 'Document Management',
|
||||
category: "Document Management",
|
||||
},
|
||||
{
|
||||
id: 'close-document',
|
||||
description: 'Close Current Document',
|
||||
key: 'w',
|
||||
id: "close-document",
|
||||
description: "Close Current Document",
|
||||
key: "w",
|
||||
ctrl: true,
|
||||
handler: () => {
|
||||
if (activeDocumentId && documentOrder.length > 1) {
|
||||
closeDocument(activeDocumentId);
|
||||
}
|
||||
},
|
||||
category: 'Document Management',
|
||||
category: "Document Management",
|
||||
},
|
||||
{
|
||||
id: 'next-document',
|
||||
description: 'Next Document',
|
||||
key: 'Tab',
|
||||
id: "next-document",
|
||||
description: "Next Document",
|
||||
key: "Tab",
|
||||
ctrl: true,
|
||||
handler: () => {
|
||||
const currentIndex = documentOrder.findIndex(id => id === activeDocumentId);
|
||||
const currentIndex = documentOrder.findIndex(
|
||||
(id) => id === activeDocumentId,
|
||||
);
|
||||
if (currentIndex !== -1) {
|
||||
const nextIndex = (currentIndex + 1) % documentOrder.length;
|
||||
switchToDocument(documentOrder[nextIndex]);
|
||||
}
|
||||
},
|
||||
category: 'Navigation',
|
||||
category: "Navigation",
|
||||
},
|
||||
{
|
||||
id: 'previous-document',
|
||||
description: 'Previous Document',
|
||||
key: 'Tab',
|
||||
id: "previous-document",
|
||||
description: "Previous Document",
|
||||
key: "Tab",
|
||||
ctrl: true,
|
||||
shift: true,
|
||||
handler: () => {
|
||||
const currentIndex = documentOrder.findIndex(id => id === activeDocumentId);
|
||||
const currentIndex = documentOrder.findIndex(
|
||||
(id) => id === activeDocumentId,
|
||||
);
|
||||
if (currentIndex !== -1) {
|
||||
const prevIndex = (currentIndex - 1 + documentOrder.length) % documentOrder.length;
|
||||
const prevIndex =
|
||||
(currentIndex - 1 + documentOrder.length) % documentOrder.length;
|
||||
switchToDocument(documentOrder[prevIndex]);
|
||||
}
|
||||
},
|
||||
category: 'Navigation',
|
||||
category: "Navigation",
|
||||
},
|
||||
|
||||
// Graph Editing
|
||||
{
|
||||
id: 'undo',
|
||||
description: 'Undo',
|
||||
key: 'z',
|
||||
id: "undo",
|
||||
description: "Undo",
|
||||
key: "z",
|
||||
ctrl: true,
|
||||
handler: () => options.onUndo?.(),
|
||||
category: 'Graph Editing',
|
||||
category: "Graph Editing",
|
||||
enabled: !!options.onUndo,
|
||||
},
|
||||
{
|
||||
id: 'redo',
|
||||
description: 'Redo',
|
||||
key: 'y',
|
||||
id: "redo",
|
||||
description: "Redo",
|
||||
key: "y",
|
||||
ctrl: true,
|
||||
handler: () => options.onRedo?.(),
|
||||
category: 'Graph Editing',
|
||||
category: "Graph Editing",
|
||||
enabled: !!options.onRedo,
|
||||
},
|
||||
{
|
||||
id: 'redo-alt',
|
||||
description: 'Redo',
|
||||
key: 'z',
|
||||
id: "redo-alt",
|
||||
description: "Redo",
|
||||
key: "z",
|
||||
ctrl: true,
|
||||
shift: true,
|
||||
handler: () => options.onRedo?.(),
|
||||
category: 'Graph Editing',
|
||||
category: "Graph Editing",
|
||||
enabled: !!options.onRedo,
|
||||
priority: -1, // Lower priority than Ctrl+Y
|
||||
},
|
||||
|
||||
// Selection
|
||||
{
|
||||
id: 'select-all',
|
||||
description: 'Select All',
|
||||
key: 'a',
|
||||
id: "select-all",
|
||||
description: "Select All",
|
||||
key: "a",
|
||||
ctrl: true,
|
||||
handler: () => options.onSelectAll?.(),
|
||||
category: 'Selection',
|
||||
category: "Selection",
|
||||
enabled: !!options.onSelectAll,
|
||||
},
|
||||
{
|
||||
id: 'deselect-all',
|
||||
description: 'Deselect All',
|
||||
key: 'Escape',
|
||||
id: "deselect-all",
|
||||
description: "Deselect All",
|
||||
key: "Escape",
|
||||
handler: () => {
|
||||
// This will be handled by GraphEditor
|
||||
// Just documenting it here
|
||||
},
|
||||
category: 'Selection',
|
||||
category: "Selection",
|
||||
enabled: false, // React Flow handles this internally
|
||||
},
|
||||
|
||||
// View
|
||||
{
|
||||
id: 'fit-view',
|
||||
description: 'Fit View to Content',
|
||||
key: 'f',
|
||||
id: "fit-view",
|
||||
description: "Fit View to Content",
|
||||
key: "f",
|
||||
handler: () => options.onFitView?.(),
|
||||
category: 'View',
|
||||
category: "View",
|
||||
enabled: !!options.onFitView,
|
||||
},
|
||||
{
|
||||
id: 'show-help',
|
||||
description: 'Show Keyboard Shortcuts',
|
||||
key: '?',
|
||||
id: "show-help",
|
||||
description: "Show Keyboard Shortcuts",
|
||||
key: "?",
|
||||
handler: () => options.onOpenHelp?.(),
|
||||
category: 'Navigation',
|
||||
category: "Navigation",
|
||||
enabled: !!options.onOpenHelp,
|
||||
},
|
||||
];
|
||||
|
||||
// Register all shortcuts
|
||||
shortcutDefinitions.forEach(shortcut => {
|
||||
shortcutDefinitions.forEach((shortcut) => {
|
||||
shortcuts.register(shortcut);
|
||||
});
|
||||
|
||||
// Cleanup on unmount
|
||||
return () => {
|
||||
shortcutDefinitions.forEach(shortcut => {
|
||||
shortcutDefinitions.forEach((shortcut) => {
|
||||
shortcuts.unregister(shortcut.id);
|
||||
});
|
||||
};
|
||||
|
|
@ -195,11 +200,6 @@ export function useGlobalShortcuts(options: UseGlobalShortcutsOptions = {}) {
|
|||
closeDocument,
|
||||
createDocument,
|
||||
saveDocument,
|
||||
options.onOpenDocumentManager,
|
||||
options.onUndo,
|
||||
options.onRedo,
|
||||
options.onOpenHelp,
|
||||
options.onFitView,
|
||||
options.onSelectAll,
|
||||
options,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue