fix(react): check if window exists
This commit is contained in:
@@ -28,6 +28,8 @@ export type FlowRendererProps<NodeType extends Node = Node> = Omit<
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
const win = typeof window === 'undefined' ? window : undefined;
|
||||
|
||||
const selector = (s: ReactFlowState) => {
|
||||
return { nodesSelectionActive: s.nodesSelectionActive, userSelectionActive: s.userSelectionActive };
|
||||
};
|
||||
@@ -70,8 +72,8 @@ function FlowRendererComponent<NodeType extends Node = Node>({
|
||||
isControlledViewport,
|
||||
}: FlowRendererProps<NodeType>) {
|
||||
const { nodesSelectionActive, userSelectionActive } = useStore(selector);
|
||||
const selectionKeyPressed = useKeyPress(selectionKeyCode, { target: window });
|
||||
const panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: window });
|
||||
const selectionKeyPressed = useKeyPress(selectionKeyCode, { target: win });
|
||||
const panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: win });
|
||||
|
||||
const panOnDrag = panActivationKeyPressed || _panOnDrag;
|
||||
const panOnScroll = panActivationKeyPressed || _panOnScroll;
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Edge, Node } from '../types';
|
||||
const selected = (item: Node | Edge) => item.selected;
|
||||
|
||||
const deleteKeyOptions: UseKeyPressOptions = { actInsideInputWithModifier: false };
|
||||
const win = typeof window === 'undefined' ? window : undefined;
|
||||
|
||||
/**
|
||||
* Hook for handling global key events.
|
||||
@@ -26,7 +27,7 @@ export function useGlobalKeyHandler({
|
||||
const { deleteElements } = useReactFlow();
|
||||
|
||||
const deleteKeyPressed = useKeyPress(deleteKeyCode, deleteKeyOptions);
|
||||
const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode, { target: window });
|
||||
const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode, { target: win });
|
||||
|
||||
useEffect(() => {
|
||||
if (deleteKeyPressed) {
|
||||
|
||||
Reference in New Issue
Block a user