From 4947f683b7530f8e6684865ab53ea38633de0f4d Mon Sep 17 00:00:00 2001 From: peterkogo Date: Wed, 8 Jan 2025 16:09:20 +0100 Subject: [PATCH] Move areSetsEqual to system --- ...ct-fans-grow.md => twelve-bottles-turn.md} | 1 + packages/react/src/container/Pane/index.tsx | 23 +++++++------------ packages/system/src/utils/general.ts | 14 +++++++++++ 3 files changed, 23 insertions(+), 15 deletions(-) rename .changeset/{perfect-fans-grow.md => twelve-bottles-turn.md} (85%) diff --git a/.changeset/perfect-fans-grow.md b/.changeset/twelve-bottles-turn.md similarity index 85% rename from .changeset/perfect-fans-grow.md rename to .changeset/twelve-bottles-turn.md index 2d4c738e..89b28a52 100644 --- a/.changeset/perfect-fans-grow.md +++ b/.changeset/twelve-bottles-turn.md @@ -1,5 +1,6 @@ --- '@xyflow/react': patch +'@xyflow/system': patch --- Optimize selections and take into account if edges connected to selected nodes are actually selectable. diff --git a/packages/react/src/container/Pane/index.tsx b/packages/react/src/container/Pane/index.tsx index 99d81da3..3b7c94bb 100644 --- a/packages/react/src/container/Pane/index.tsx +++ b/packages/react/src/container/Pane/index.tsx @@ -10,7 +10,14 @@ import { } from 'react'; import { shallow } from 'zustand/shallow'; import cc from 'classcat'; -import { getNodesInside, getEventPosition, SelectionMode, type NodeChange, type EdgeChange } from '@xyflow/system'; +import { + getNodesInside, + getEventPosition, + SelectionMode, + areSetsEqual, + type NodeChange, + type EdgeChange, +} from '@xyflow/system'; import { UserSelection } from '../../components/UserSelection'; import { containerStyle } from '../../styles/utils'; @@ -39,20 +46,6 @@ type PaneProps = { > >; -function areSetsEqual(a: Set, b: Set) { - if (a.size !== b.size) { - return false; - } - - for (const item of a) { - if (!b.has(item)) { - return false; - } - } - - return true; -} - const wrapHandler = ( handler: React.MouseEventHandler | undefined, containerRef: React.MutableRefObject diff --git a/packages/system/src/utils/general.ts b/packages/system/src/utils/general.ts index 088209a3..7f631a59 100644 --- a/packages/system/src/utils/general.ts +++ b/packages/system/src/utils/general.ts @@ -263,3 +263,17 @@ export function evaluateAbsolutePosition( return positionAbsolute; } + +export function areSetsEqual(a: Set, b: Set) { + if (a.size !== b.size) { + return false; + } + + for (const item of a) { + if (!b.has(item)) { + return false; + } + } + + return true; +}