Merge commit 'ca6f73e91922c8faed1f495e7ecac2ad1101f65d' into block-notes

This commit is contained in:
Oliver Walters
2026-06-09 06:44:55 +00:00
19 changed files with 225 additions and 27 deletions
+31
View File
@@ -1,6 +1,37 @@
import { useHotkeys } from '@mantine/hooks';
import type { HotkeyItemOptions } from '@mantine/hooks';
import { useEffect } from 'react';
import { useLocalLibState } from '..';
// Helper function to cancel event propagation
export function cancelEvent(event: any) {
event?.preventDefault();
event?.stopPropagation();
event?.nativeEvent?.stopImmediatePropagation();
}
export type InvenTreeHotkeyItem = [
string,
string,
(event: KeyboardEvent) => void,
HotkeyItemOptions?
];
export function useInvenTreeHotkeys(hotkeys: InvenTreeHotkeyItem[]) {
// Register the hotkeys using the Mantine hook
useHotkeys(
hotkeys.map(([key, _, handler, options]) => [key, handler, options])
);
// register to helper state to store hotkeys
// This allows us to display the hotkeys in the UI
const keyelems: [string, string][] = hotkeys.map(([key, description]) => [
key,
description
]);
useEffect(() => {
useLocalLibState.getState().addHotkeys(keyelems);
return () =>
useLocalLibState.getState().removeHotkeys(keyelems.map(([key]) => key));
}, []);
}
+2
View File
@@ -139,6 +139,8 @@ export {
type TableStateExtraProps
} from './hooks/UseTable';
export { useInvenTreeHotkeys } from './functions/Events';
export {
type DrawerProps,
DetailDrawer,
+19
View File
@@ -10,8 +10,24 @@ export const useLocalLibState = create<LocalLibStateProps>()(
detailDrawerStack:
value === false ? 0 : get().detailDrawerStack + value
});
},
hotkeys: {},
addHotkeys: (hotkeys) => {
const newHotkeys = { ...get().hotkeys };
for (const [ref, details] of hotkeys) {
newHotkeys[ref] = details;
}
set({ hotkeys: newHotkeys });
},
removeHotkeys: (hotkeys) => {
const newHotkeys = { ...get().hotkeys };
for (const ref of hotkeys) {
delete newHotkeys[ref];
}
set({ hotkeys: newHotkeys });
}
}),
{
name: 'session-settings-inventreedb_lib'
}
@@ -20,4 +36,7 @@ export const useLocalLibState = create<LocalLibStateProps>()(
export interface LocalLibStateProps {
detailDrawerStack: number;
addDetailDrawer: (value: number | false) => void;
hotkeys: Record<string, string>;
addHotkeys: (hotkeys: [string, string][]) => void;
removeHotkeys: (hotkeys: string[]) => void;
}