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