From 1c699f889a1e30cfeb1cab869b1f4273a98f9f74 Mon Sep 17 00:00:00 2001 From: moklick Date: Sat, 2 Apr 2022 12:12:37 +0200 Subject: [PATCH 1/5] refactor(useKeyPress): return early if target is input #2000 --- src/hooks/useKeyPress.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/hooks/useKeyPress.ts b/src/hooks/useKeyPress.ts index 719c5dac..2e6c65c1 100644 --- a/src/hooks/useKeyPress.ts +++ b/src/hooks/useKeyPress.ts @@ -42,19 +42,25 @@ export default (keyCode: KeyCode | null = null, options: UseKeyPressOptions = { useEffect(() => { if (keyCode !== null) { const downHandler = (event: KeyboardEvent) => { + if (isInputDOMNode(event)) { + return false; + } const keyOrCode = useKeyOrCode(event.code, keysToWatch); pressedKeys.current.add(event[keyOrCode]); - if (isMatchingKey(event, keyCodes, pressedKeys.current, false)) { + if (isMatchingKey(keyCodes, pressedKeys.current, false)) { event.preventDefault(); setKeyPressed(true); } }; const upHandler = (event: KeyboardEvent) => { + if (isInputDOMNode(event)) { + return false; + } const keyOrCode = useKeyOrCode(event.code, keysToWatch); - if (isMatchingKey(event, keyCodes, pressedKeys.current, true)) { + if (isMatchingKey(keyCodes, pressedKeys.current, true)) { setKeyPressed(false); pressedKeys.current.clear(); } else { @@ -84,11 +90,7 @@ export default (keyCode: KeyCode | null = null, options: UseKeyPressOptions = { // utils -function isMatchingKey(event: KeyboardEvent, keyCodes: Array, pressedKeys: PressedKeys, isUp: boolean): boolean { - if (isInputDOMNode(event)) { - return false; - } - +function isMatchingKey(keyCodes: Array, pressedKeys: PressedKeys, isUp: boolean): boolean { return ( keyCodes // we only want to compare same sizes of keyCode definitions @@ -105,8 +107,8 @@ function useKeyOrCode(eventCode: string, keysToWatch: KeyCode): KeyOrCode { return keysToWatch.includes(eventCode) ? 'code' : 'key'; } -function isInputDOMNode(e: KeyboardEvent): boolean { - const target = e?.target as HTMLElement; +function isInputDOMNode(event: KeyboardEvent): boolean { + const target = event.target as HTMLElement; return ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || target?.hasAttribute('contenteditable'); } From d464ccda77ad887917a0a0011b9d19587c8d1959 Mon Sep 17 00:00:00 2001 From: moklick Date: Sat, 2 Apr 2022 12:32:07 +0200 Subject: [PATCH 2/5] refactor(change-events): cleanup delete events #2036 --- example/src/Stress/index.tsx | 17 +++++++++++++++-- src/hooks/useGlobalKeyHandler.ts | 12 +++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/example/src/Stress/index.tsx b/example/src/Stress/index.tsx index d1804051..b076db27 100644 --- a/example/src/Stress/index.tsx +++ b/example/src/Stress/index.tsx @@ -10,6 +10,8 @@ import ReactFlow, { applyNodeChanges, Connection, addEdge, + applyEdgeChanges, + EdgeChange, } from 'react-flow-renderer'; import { getNodesAndEdges } from './utils'; @@ -21,7 +23,7 @@ const onInit = (reactFlowInstance: ReactFlowInstance) => { console.log(reactFlowInstance.getNodes()); }; -const { nodes: initialNodes, edges: initialEdges } = getNodesAndEdges(30, 30); +const { nodes: initialNodes, edges: initialEdges } = getNodesAndEdges(5, 5); const StressFlow = () => { const [nodes, setNodes] = useState(initialNodes); @@ -54,8 +56,19 @@ const StressFlow = () => { setNodes((ns) => applyNodeChanges(changes, ns)); }, []); + const onEdgeChange = useCallback((changes: EdgeChange[]) => { + setEdges((es) => applyEdgeChanges(changes, es)); + }, []); + return ( - + diff --git a/src/hooks/useGlobalKeyHandler.ts b/src/hooks/useGlobalKeyHandler.ts index e6e88057..8c9cb89d 100644 --- a/src/hooks/useGlobalKeyHandler.ts +++ b/src/hooks/useGlobalKeyHandler.ts @@ -12,14 +12,13 @@ interface HookParams { } const selector = (s: ReactFlowState) => ({ - resetSelectedElements: s.resetSelectedElements, onNodesChange: s.onNodesChange, onEdgesChange: s.onEdgesChange, }); export default ({ deleteKeyCode, multiSelectionKeyCode }: HookParams): void => { const store = useStoreApi(); - const { resetSelectedElements, onNodesChange, onEdgesChange } = useStore(selector, shallow); + const { onNodesChange, onEdgesChange } = useStore(selector, shallow); const deleteKeyPressed = useKeyPress(deleteKeyCode); const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode); @@ -41,7 +40,12 @@ export default ({ deleteKeyCode, multiSelectionKeyCode }: HookParams): void => { if (deleteKeyPressed && (nodesToRemove || selectedEdges)) { const connectedEdges = getConnectedEdges(nodesToRemove, edges); const edgesToRemove = [...selectedEdges, ...connectedEdges]; - const edgeIdsToRemove = edgesToRemove.map((e) => e.id); + const edgeIdsToRemove = edgesToRemove.reduce((res, edge) => { + if (!res.includes(edge.id)) { + res.push(edge.id); + } + return res; + }, []); if (hasDefaultEdges || hasDefaultNodes) { if (hasDefaultEdges) { @@ -83,8 +87,6 @@ export default ({ deleteKeyCode, multiSelectionKeyCode }: HookParams): void => { } store.setState({ nodesSelectionActive: false }); - - resetSelectedElements(); } }, [deleteKeyPressed, onNodesChange, onEdgesChange]); From fd2ff9497c9b979da0954691ee0b65a0b09f6c83 Mon Sep 17 00:00:00 2001 From: moklick Date: Sat, 2 Apr 2022 12:47:12 +0200 Subject: [PATCH 3/5] chore: release v10.0.8 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b3731fd6..2c437a7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-flow-renderer", - "version": "10.0.7", + "version": "10.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "react-flow-renderer", - "version": "10.0.7", + "version": "10.0.8", "license": "MIT", "dependencies": { "@babel/runtime": "^7.17.8", diff --git a/package.json b/package.json index 4ff9a45f..38185bcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-flow-renderer", - "version": "10.0.7", + "version": "10.0.8", "engines": { "node": ">=12" }, From 55cfb0b8800d3adff0cb58136624a5d791861135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20M=C3=B6ller?= Date: Thu, 7 Apr 2022 11:47:22 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39a02fb4..065acc94 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,12 @@ npm run test ## Maintainers -React Flow is developed and maintained by [webkid](https://webkid.io), a web development agency with the focus on data driven applications from Berlin. If you need help or want to talk to us about a collaboration, feel free to contact us: +React Flow is developed and maintained by [webkid](https://webkid.io), a web development agency with focus on data driven applications from Berlin. If you need help or want to talk to us about a collaboration, feel free to contact us: * Moritz Klack • [Twitter](https://twitter.com/moklick) • [Github](https://github.com/moklick) * Christopher Möller • [Twitter](https://twitter.com/chrtze) • [Github](https://github.com/chrtze) -You can also use our [contact form](https://webkid.io/contact/) or join the [React Flow Discord Server](https://discord.gg/Bqt6xrs). +You can also use our [contact form](https://pro.reactflow.dev/contact) or join the [React Flow Discord Server](https://discord.gg/Bqt6xrs). ## Community Packages From 0b871e396aa8faad22442375c7ecbc80e3e6a679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20M=C3=B6ller?= Date: Thu, 7 Apr 2022 12:17:09 +0200 Subject: [PATCH 5/5] format LICENSE --- LICENSE | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index dce0cbd2..e378bc48 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,21 @@ -Copyright 2022 webkid GmbH +MIT License -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Copyright (c) 2019-2022 webkid GmbH -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.