Skip to content

Commit

Permalink
Move areSetsEqual to system
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkogo committed Jan 8, 2025
1 parent a893cdd commit 4947f68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 8 additions & 15 deletions packages/react/src/container/Pane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,20 +46,6 @@ type PaneProps = {
>
>;

function areSetsEqual(a: Set<string>, b: Set<string>) {
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<HTMLDivElement | null>
Expand Down
14 changes: 14 additions & 0 deletions packages/system/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,17 @@ export function evaluateAbsolutePosition(

return positionAbsolute;
}

export function areSetsEqual(a: Set<string>, b: Set<string>) {
if (a.size !== b.size) {
return false;
}

for (const item of a) {
if (!b.has(item)) {
return false;
}
}

return true;
}

0 comments on commit 4947f68

Please sign in to comment.