@reactflow/node-toolbar
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -23,2 +23,5 @@ import { jsx } from 'react/jsx-runtime'; | ||
a?.[internalsSymbol]?.z === b?.[internalsSymbol]?.z; | ||
const nodesEqualityFn = (a, b) => { | ||
return a.length === b.length && a.every((node, i) => nodeEqualityFn(node, b[i])); | ||
}; | ||
const storeSelector = (state) => ({ | ||
@@ -56,14 +59,24 @@ transform: state.transform, | ||
function NodeToolbar({ nodeId, children, className, style, isVisible, position = Position.Top, offset = 10, ...rest }) { | ||
const nodeSelector = useCallback((state) => state.nodeInternals.get(nodeId), [nodeId]); | ||
const node = useStore(nodeSelector, nodeEqualityFn); | ||
const nodesSelector = useCallback((state) => { | ||
const nodeIds = typeof nodeId === 'string' ? [nodeId] : nodeId; | ||
return nodeIds.reduce((acc, id) => { | ||
const node = state.nodeInternals.get(id); | ||
if (node) { | ||
acc.push(node); | ||
} | ||
return acc; | ||
}, []); | ||
}, [nodeId]); | ||
const nodes = useStore(nodesSelector, nodesEqualityFn); | ||
const { transform, nodeOrigin, selectedNodesCount } = useStore(storeSelector, shallow); | ||
const isActive = typeof isVisible === 'boolean' ? isVisible : node?.selected && selectedNodesCount === 1; | ||
if (!isActive || !node) { | ||
const isActive = typeof isVisible === 'boolean' ? isVisible : nodes.length === 1 && nodes[0].selected && selectedNodesCount === 1; | ||
if (!isActive || !nodes.length) { | ||
return null; | ||
} | ||
const nodeRect = getRectOfNodes([node], nodeOrigin); | ||
const nodeRect = getRectOfNodes(nodes, nodeOrigin); | ||
const zIndex = Math.max(...nodes.map((node) => (node[internalsSymbol]?.z || 1) + 1)); | ||
const wrapperStyle = { | ||
position: 'absolute', | ||
transform: getTransform(nodeRect, transform, position, offset), | ||
zIndex: (node[internalsSymbol]?.z || 1) + 1, | ||
zIndex, | ||
...style, | ||
@@ -70,0 +83,0 @@ }; |
import { Position } from '@reactflow/core'; | ||
import type { HTMLAttributes } from 'react'; | ||
export declare type NodeToolbarProps = HTMLAttributes<HTMLDivElement> & { | ||
nodeId: string; | ||
nodeId: string | string[]; | ||
isVisible?: boolean; | ||
@@ -6,0 +6,0 @@ position?: Position; |
import { Position } from '@reactflow/core'; | ||
import type { HTMLAttributes } from 'react'; | ||
export declare type NodeToolbarProps = HTMLAttributes<HTMLDivElement> & { | ||
nodeId: string; | ||
nodeId: string | string[]; | ||
isVisible?: boolean; | ||
@@ -6,0 +6,0 @@ position?: Position; |
{ | ||
"name": "@reactflow/node-toolbar", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A toolbar component for React Flow that can be attached to a node.", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"@babel/runtime": "^7.18.9", | ||
"@reactflow/core": "11.3.0", | ||
"@reactflow/core": "11.3.1", | ||
"classcat": "^5.0.3", | ||
@@ -37,0 +37,0 @@ "zustand": "^4.1.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139610
624
21
+ Added@reactflow/core@11.3.1(transitive)
- Removed@reactflow/core@11.3.0(transitive)
Updated@reactflow/core@11.3.1