feat(nodes-edges): add zIndexMode
This commit is contained in:
@@ -4,7 +4,7 @@ import { Provider } from '../../contexts/StoreContext';
|
|||||||
import { createStore } from '../../store';
|
import { createStore } from '../../store';
|
||||||
import { BatchProvider } from '../BatchProvider';
|
import { BatchProvider } from '../BatchProvider';
|
||||||
import type { Node, Edge, FitViewOptions } from '../../types';
|
import type { Node, Edge, FitViewOptions } from '../../types';
|
||||||
import { CoordinateExtent, NodeOrigin } from '@xyflow/system';
|
import { CoordinateExtent, NodeOrigin, ZIndexMode } from '@xyflow/system';
|
||||||
|
|
||||||
export type ReactFlowProviderProps = {
|
export type ReactFlowProviderProps = {
|
||||||
/** These nodes are used to initialize the flow. They are not dynamic. */
|
/** These nodes are used to initialize the flow. They are not dynamic. */
|
||||||
@@ -48,6 +48,7 @@ export type ReactFlowProviderProps = {
|
|||||||
*/
|
*/
|
||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,6 +98,7 @@ export function ReactFlowProvider({
|
|||||||
fitView,
|
fitView,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
|
zIndexMode,
|
||||||
children,
|
children,
|
||||||
}: ReactFlowProviderProps) {
|
}: ReactFlowProviderProps) {
|
||||||
const [store] = useState(() =>
|
const [store] = useState(() =>
|
||||||
@@ -113,6 +115,7 @@ export function ReactFlowProvider({
|
|||||||
fitViewOptions,
|
fitViewOptions,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
|
zIndexMode,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ const reactFlowFieldsToTrack = [
|
|||||||
'debug',
|
'debug',
|
||||||
'autoPanSpeed',
|
'autoPanSpeed',
|
||||||
'ariaLabelConfig',
|
'ariaLabelConfig',
|
||||||
|
'zIndexMode',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
type ReactFlowFieldsToTrack = (typeof reactFlowFieldsToTrack)[number];
|
type ReactFlowFieldsToTrack = (typeof reactFlowFieldsToTrack)[number];
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useContext, type ReactNode } from 'react';
|
|||||||
import StoreContext from '../../contexts/StoreContext';
|
import StoreContext from '../../contexts/StoreContext';
|
||||||
import { ReactFlowProvider } from '../../components/ReactFlowProvider';
|
import { ReactFlowProvider } from '../../components/ReactFlowProvider';
|
||||||
import type { Node, Edge, FitViewOptions } from '../../types';
|
import type { Node, Edge, FitViewOptions } from '../../types';
|
||||||
import { CoordinateExtent, NodeOrigin } from '@xyflow/system';
|
import { CoordinateExtent, NodeOrigin, ZIndexMode } from '@xyflow/system';
|
||||||
|
|
||||||
export function Wrapper({
|
export function Wrapper({
|
||||||
children,
|
children,
|
||||||
@@ -19,6 +19,7 @@ export function Wrapper({
|
|||||||
maxZoom,
|
maxZoom,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
|
zIndexMode,
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
nodes?: Node[];
|
nodes?: Node[];
|
||||||
@@ -33,6 +34,7 @@ export function Wrapper({
|
|||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
}) {
|
}) {
|
||||||
const isWrapped = useContext(StoreContext);
|
const isWrapped = useContext(StoreContext);
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ export function Wrapper({
|
|||||||
initialMaxZoom={maxZoom}
|
initialMaxZoom={maxZoom}
|
||||||
nodeOrigin={nodeOrigin}
|
nodeOrigin={nodeOrigin}
|
||||||
nodeExtent={nodeExtent}
|
nodeExtent={nodeExtent}
|
||||||
|
zIndexMode={zIndexMode}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</ReactFlowProvider>
|
</ReactFlowProvider>
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
|
|||||||
debug,
|
debug,
|
||||||
onScroll,
|
onScroll,
|
||||||
ariaLabelConfig,
|
ariaLabelConfig,
|
||||||
|
zIndexMode,
|
||||||
...rest
|
...rest
|
||||||
}: ReactFlowProps<NodeType, EdgeType>,
|
}: ReactFlowProps<NodeType, EdgeType>,
|
||||||
ref: ForwardedRef<HTMLDivElement>
|
ref: ForwardedRef<HTMLDivElement>
|
||||||
@@ -186,6 +187,7 @@ function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
|
|||||||
maxZoom={maxZoom}
|
maxZoom={maxZoom}
|
||||||
nodeOrigin={nodeOrigin}
|
nodeOrigin={nodeOrigin}
|
||||||
nodeExtent={nodeExtent}
|
nodeExtent={nodeExtent}
|
||||||
|
zIndexMode={zIndexMode}
|
||||||
>
|
>
|
||||||
<GraphView<NodeType, EdgeType>
|
<GraphView<NodeType, EdgeType>
|
||||||
onInit={onInit}
|
onInit={onInit}
|
||||||
@@ -311,6 +313,7 @@ function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
|
|||||||
onBeforeDelete={onBeforeDelete}
|
onBeforeDelete={onBeforeDelete}
|
||||||
debug={debug}
|
debug={debug}
|
||||||
ariaLabelConfig={ariaLabelConfig}
|
ariaLabelConfig={ariaLabelConfig}
|
||||||
|
zIndexMode={zIndexMode}
|
||||||
/>
|
/>
|
||||||
<SelectionListener<NodeType, EdgeType> onSelectionChange={onSelectionChange} />
|
<SelectionListener<NodeType, EdgeType> onSelectionChange={onSelectionChange} />
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
NodeOrigin,
|
NodeOrigin,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
fitViewport,
|
fitViewport,
|
||||||
|
ZIndexMode,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import { applyEdgeChanges, applyNodeChanges, createSelectionChange, getSelectionChanges } from '../utils/changes';
|
import { applyEdgeChanges, applyNodeChanges, createSelectionChange, getSelectionChanges } from '../utils/changes';
|
||||||
@@ -33,6 +34,7 @@ const createStore = ({
|
|||||||
maxZoom,
|
maxZoom,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
|
zIndexMode,
|
||||||
}: {
|
}: {
|
||||||
nodes?: Node[];
|
nodes?: Node[];
|
||||||
edges?: Edge[];
|
edges?: Edge[];
|
||||||
@@ -46,6 +48,7 @@ const createStore = ({
|
|||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
}) =>
|
}) =>
|
||||||
createWithEqualityFn<ReactFlowState>((set, get) => {
|
createWithEqualityFn<ReactFlowState>((set, get) => {
|
||||||
async function resolveFitView() {
|
async function resolveFitView() {
|
||||||
@@ -89,9 +92,10 @@ const createStore = ({
|
|||||||
nodeExtent,
|
nodeExtent,
|
||||||
defaultNodes,
|
defaultNodes,
|
||||||
defaultEdges,
|
defaultEdges,
|
||||||
|
zIndexMode,
|
||||||
}),
|
}),
|
||||||
setNodes: (nodes: Node[]) => {
|
setNodes: (nodes: Node[]) => {
|
||||||
const { nodeLookup, parentLookup, nodeOrigin, elevateNodesOnSelect, fitViewQueued } = get();
|
const { nodeLookup, parentLookup, nodeOrigin, elevateNodesOnSelect, fitViewQueued, zIndexMode } = get();
|
||||||
/*
|
/*
|
||||||
* setNodes() is called exclusively in response to user actions:
|
* setNodes() is called exclusively in response to user actions:
|
||||||
* - either when the `<ReactFlow nodes>` prop is updated in the controlled ReactFlow setup,
|
* - either when the `<ReactFlow nodes>` prop is updated in the controlled ReactFlow setup,
|
||||||
@@ -106,6 +110,7 @@ const createStore = ({
|
|||||||
nodeExtent,
|
nodeExtent,
|
||||||
elevateNodesOnSelect,
|
elevateNodesOnSelect,
|
||||||
checkEquality: true,
|
checkEquality: true,
|
||||||
|
zIndexMode,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fitViewQueued && nodesInitialized) {
|
if (fitViewQueued && nodesInitialized) {
|
||||||
@@ -140,8 +145,17 @@ const createStore = ({
|
|||||||
* new dimensions and update the nodes.
|
* new dimensions and update the nodes.
|
||||||
*/
|
*/
|
||||||
updateNodeInternals: (updates) => {
|
updateNodeInternals: (updates) => {
|
||||||
const { triggerNodeChanges, nodeLookup, parentLookup, domNode, nodeOrigin, nodeExtent, debug, fitViewQueued } =
|
const {
|
||||||
get();
|
triggerNodeChanges,
|
||||||
|
nodeLookup,
|
||||||
|
parentLookup,
|
||||||
|
domNode,
|
||||||
|
nodeOrigin,
|
||||||
|
nodeExtent,
|
||||||
|
debug,
|
||||||
|
fitViewQueued,
|
||||||
|
zIndexMode,
|
||||||
|
} = get();
|
||||||
|
|
||||||
const { changes, updatedInternals } = updateNodeInternalsSystem(
|
const { changes, updatedInternals } = updateNodeInternalsSystem(
|
||||||
updates,
|
updates,
|
||||||
@@ -149,14 +163,15 @@ const createStore = ({
|
|||||||
parentLookup,
|
parentLookup,
|
||||||
domNode,
|
domNode,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent
|
nodeExtent,
|
||||||
|
zIndexMode
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!updatedInternals) {
|
if (!updatedInternals) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAbsolutePositions(nodeLookup, parentLookup, { nodeOrigin, nodeExtent });
|
updateAbsolutePositions(nodeLookup, parentLookup, { nodeOrigin, nodeExtent, zIndexMode });
|
||||||
|
|
||||||
if (fitViewQueued) {
|
if (fitViewQueued) {
|
||||||
resolveFitView();
|
resolveFitView();
|
||||||
@@ -332,7 +347,7 @@ const createStore = ({
|
|||||||
triggerEdgeChanges(edgeChanges);
|
triggerEdgeChanges(edgeChanges);
|
||||||
},
|
},
|
||||||
setNodeExtent: (nextNodeExtent) => {
|
setNodeExtent: (nextNodeExtent) => {
|
||||||
const { nodes, nodeLookup, parentLookup, nodeOrigin, elevateNodesOnSelect, nodeExtent } = get();
|
const { nodes, nodeLookup, parentLookup, nodeOrigin, elevateNodesOnSelect, nodeExtent, zIndexMode } = get();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
nextNodeExtent[0][0] === nodeExtent[0][0] &&
|
nextNodeExtent[0][0] === nodeExtent[0][0] &&
|
||||||
@@ -348,6 +363,7 @@ const createStore = ({
|
|||||||
nodeExtent: nextNodeExtent,
|
nodeExtent: nextNodeExtent,
|
||||||
elevateNodesOnSelect,
|
elevateNodesOnSelect,
|
||||||
checkEquality: false,
|
checkEquality: false,
|
||||||
|
zIndexMode,
|
||||||
});
|
});
|
||||||
|
|
||||||
set({ nodeExtent: nextNodeExtent });
|
set({ nodeExtent: nextNodeExtent });
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
initialConnection,
|
initialConnection,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
defaultAriaLabelConfig,
|
defaultAriaLabelConfig,
|
||||||
|
ZIndexMode,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type { Edge, FitViewOptions, InternalNode, Node, ReactFlowStore } from '../types';
|
import type { Edge, FitViewOptions, InternalNode, Node, ReactFlowStore } from '../types';
|
||||||
@@ -28,6 +29,7 @@ const getInitialState = ({
|
|||||||
maxZoom = 2,
|
maxZoom = 2,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
|
zIndexMode = 'auto',
|
||||||
}: {
|
}: {
|
||||||
nodes?: Node[];
|
nodes?: Node[];
|
||||||
edges?: Edge[];
|
edges?: Edge[];
|
||||||
@@ -41,6 +43,7 @@ const getInitialState = ({
|
|||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
} = {}): ReactFlowStore => {
|
} = {}): ReactFlowStore => {
|
||||||
const nodeLookup = new Map<string, InternalNode>();
|
const nodeLookup = new Map<string, InternalNode>();
|
||||||
const parentLookup = new Map();
|
const parentLookup = new Map();
|
||||||
@@ -146,6 +149,7 @@ const getInitialState = ({
|
|||||||
lib: 'react',
|
lib: 'react',
|
||||||
debug: false,
|
debug: false,
|
||||||
ariaLabelConfig: defaultAriaLabelConfig,
|
ariaLabelConfig: defaultAriaLabelConfig,
|
||||||
|
zIndexMode,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import type {
|
|||||||
OnReconnect,
|
OnReconnect,
|
||||||
AriaLabelConfig,
|
AriaLabelConfig,
|
||||||
FinalConnectionState,
|
FinalConnectionState,
|
||||||
|
ZIndexMode,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -691,4 +692,5 @@ export interface ReactFlowProps<NodeType extends Node = Node, EdgeType extends E
|
|||||||
* Allows localization, customization of ARIA descriptions, control labels, minimap labels, and other UI strings.
|
* Allows localization, customization of ARIA descriptions, control labels, minimap labels, and other UI strings.
|
||||||
*/
|
*/
|
||||||
ariaLabelConfig?: Partial<AriaLabelConfig>;
|
ariaLabelConfig?: Partial<AriaLabelConfig>;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
type ParentLookup,
|
type ParentLookup,
|
||||||
type AriaLabelConfig,
|
type AriaLabelConfig,
|
||||||
SetCenter,
|
SetCenter,
|
||||||
|
ZIndexMode,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -152,6 +153,8 @@ export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge =
|
|||||||
lib: string;
|
lib: string;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
ariaLabelConfig: AriaLabelConfig;
|
ariaLabelConfig: AriaLabelConfig;
|
||||||
|
|
||||||
|
zIndexMode: ZIndexMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ReactFlowActions<NodeType extends Node, EdgeType extends Edge> = {
|
export type ReactFlowActions<NodeType extends Node, EdgeType extends Edge> = {
|
||||||
|
|||||||
@@ -367,3 +367,5 @@ export type OnBeforeDeleteBase<NodeType extends NodeBase = NodeBase, EdgeType ex
|
|||||||
nodes: NodeType[];
|
nodes: NodeType[];
|
||||||
edges: EdgeType[];
|
edges: EdgeType[];
|
||||||
}) => Promise<boolean | { nodes: NodeType[]; edges: EdgeType[] }>;
|
}) => Promise<boolean | { nodes: NodeType[]; edges: EdgeType[] }>;
|
||||||
|
|
||||||
|
export type ZIndexMode = 'auto' | 'manual';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Handle, HandleConnection, infiniteExtent, NodeHandle, NodeHandleBounds } from '..';
|
import { Handle, HandleConnection, infiniteExtent, NodeHandleBounds, ZIndexMode } from '..';
|
||||||
import {
|
import {
|
||||||
NodeBase,
|
NodeBase,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
@@ -37,6 +37,7 @@ const defaultOptions = {
|
|||||||
nodeOrigin: [0, 0] as NodeOrigin,
|
nodeOrigin: [0, 0] as NodeOrigin,
|
||||||
nodeExtent: infiniteExtent,
|
nodeExtent: infiniteExtent,
|
||||||
elevateNodesOnSelect: true,
|
elevateNodesOnSelect: true,
|
||||||
|
zIndexMode: 'auto' as ZIndexMode,
|
||||||
defaults: {},
|
defaults: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,21 +113,27 @@ type UpdateNodesOptions<NodeType extends NodeBase> = {
|
|||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
elevateNodesOnSelect?: boolean;
|
elevateNodesOnSelect?: boolean;
|
||||||
defaults?: Partial<NodeType>;
|
defaults?: Partial<NodeType>;
|
||||||
|
zIndexMode?: ZIndexMode;
|
||||||
checkEquality?: boolean;
|
checkEquality?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isManualZIndexMode(zIndexMode?: ZIndexMode): boolean {
|
||||||
|
return zIndexMode === 'manual';
|
||||||
|
}
|
||||||
|
|
||||||
export function adoptUserNodes<NodeType extends NodeBase>(
|
export function adoptUserNodes<NodeType extends NodeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
||||||
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
||||||
options?: UpdateNodesOptions<NodeType>
|
options: UpdateNodesOptions<NodeType> = {}
|
||||||
): boolean {
|
): boolean {
|
||||||
const _options = mergeObjects(adoptUserNodesDefaultOptions, options);
|
const _options = mergeObjects(adoptUserNodesDefaultOptions, options);
|
||||||
|
|
||||||
let rootParentIndex = { i: -1 };
|
let rootParentIndex = { i: -1 };
|
||||||
let nodesInitialized = nodes.length > 0;
|
let nodesInitialized = nodes.length > 0;
|
||||||
const tmpLookup = new Map(nodeLookup);
|
const tmpLookup = new Map(nodeLookup);
|
||||||
const selectedNodeZ: number = _options?.elevateNodesOnSelect ? SELECTED_NODE_Z : 0;
|
const selectedNodeZ: number =
|
||||||
|
_options?.elevateNodesOnSelect && !isManualZIndexMode(_options.zIndexMode) ? SELECTED_NODE_Z : 0;
|
||||||
|
|
||||||
nodeLookup.clear();
|
nodeLookup.clear();
|
||||||
parentLookup.clear();
|
parentLookup.clear();
|
||||||
@@ -152,7 +159,7 @@ export function adoptUserNodes<NodeType extends NodeBase>(
|
|||||||
positionAbsolute: clampedPosition,
|
positionAbsolute: clampedPosition,
|
||||||
// if user re-initializes the node or removes `measured` for whatever reason, we reset the handleBounds so that the node gets re-measured
|
// if user re-initializes the node or removes `measured` for whatever reason, we reset the handleBounds so that the node gets re-measured
|
||||||
handleBounds: parseHandles(userNode, internalNode),
|
handleBounds: parseHandles(userNode, internalNode),
|
||||||
z: calculateZ(userNode, selectedNodeZ),
|
z: calculateZ(userNode, selectedNodeZ, _options.zIndexMode),
|
||||||
userNode,
|
userNode,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -201,10 +208,10 @@ function updateChildNode<NodeType extends NodeBase>(
|
|||||||
node: InternalNodeBase<NodeType>,
|
node: InternalNodeBase<NodeType>,
|
||||||
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
||||||
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
||||||
options?: UpdateNodesOptions<NodeType>,
|
options: UpdateNodesOptions<NodeType>,
|
||||||
rootParentIndex?: { i: number }
|
rootParentIndex?: { i: number }
|
||||||
) {
|
) {
|
||||||
const { elevateNodesOnSelect, nodeOrigin, nodeExtent } = mergeObjects(defaultOptions, options);
|
const { elevateNodesOnSelect, nodeOrigin, nodeExtent, zIndexMode } = mergeObjects(defaultOptions, options);
|
||||||
const parentId = node.parentId!;
|
const parentId = node.parentId!;
|
||||||
const parentNode = nodeLookup.get(parentId);
|
const parentNode = nodeLookup.get(parentId);
|
||||||
|
|
||||||
@@ -218,7 +225,12 @@ function updateChildNode<NodeType extends NodeBase>(
|
|||||||
updateParentLookup(node, parentLookup);
|
updateParentLookup(node, parentLookup);
|
||||||
|
|
||||||
// We just want to set the rootParentIndex for the first child
|
// We just want to set the rootParentIndex for the first child
|
||||||
if (rootParentIndex && !parentNode.parentId && parentNode.internals.rootParentIndex === undefined) {
|
if (
|
||||||
|
rootParentIndex &&
|
||||||
|
!parentNode.parentId &&
|
||||||
|
parentNode.internals.rootParentIndex === undefined &&
|
||||||
|
!isManualZIndexMode(zIndexMode)
|
||||||
|
) {
|
||||||
parentNode.internals.rootParentIndex = ++rootParentIndex.i;
|
parentNode.internals.rootParentIndex = ++rootParentIndex.i;
|
||||||
parentNode.internals.z = parentNode.internals.z + rootParentIndex.i * ROOT_PARENT_Z_INCREMENT;
|
parentNode.internals.z = parentNode.internals.z + rootParentIndex.i * ROOT_PARENT_Z_INCREMENT;
|
||||||
}
|
}
|
||||||
@@ -228,8 +240,8 @@ function updateChildNode<NodeType extends NodeBase>(
|
|||||||
rootParentIndex.i = parentNode.internals.rootParentIndex;
|
rootParentIndex.i = parentNode.internals.rootParentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedNodeZ = elevateNodesOnSelect ? SELECTED_NODE_Z : 0;
|
const selectedNodeZ = elevateNodesOnSelect && !isManualZIndexMode(zIndexMode) ? SELECTED_NODE_Z : 0;
|
||||||
const { x, y, z } = calculateChildXYZ(node, parentNode, nodeOrigin, nodeExtent, selectedNodeZ);
|
const { x, y, z } = calculateChildXYZ(node, parentNode, nodeOrigin, nodeExtent, selectedNodeZ, zIndexMode);
|
||||||
const { positionAbsolute } = node.internals;
|
const { positionAbsolute } = node.internals;
|
||||||
const positionChanged = x !== positionAbsolute.x || y !== positionAbsolute.y;
|
const positionChanged = x !== positionAbsolute.x || y !== positionAbsolute.y;
|
||||||
|
|
||||||
@@ -246,8 +258,14 @@ function updateChildNode<NodeType extends NodeBase>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateZ(node: NodeBase, selectedNodeZ: number) {
|
function calculateZ(node: NodeBase, selectedNodeZ: number, zIndexMode: ZIndexMode): number {
|
||||||
return (isNumeric(node.zIndex) ? node.zIndex : 0) + (node.selected ? selectedNodeZ : 0);
|
const zIndex = isNumeric(node.zIndex) ? node.zIndex : 0;
|
||||||
|
|
||||||
|
if (isManualZIndexMode(zIndexMode)) {
|
||||||
|
return zIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return zIndex + (node.selected ? selectedNodeZ : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateChildXYZ<NodeType extends NodeBase>(
|
function calculateChildXYZ<NodeType extends NodeBase>(
|
||||||
@@ -255,7 +273,8 @@ function calculateChildXYZ<NodeType extends NodeBase>(
|
|||||||
parentNode: InternalNodeBase<NodeType>,
|
parentNode: InternalNodeBase<NodeType>,
|
||||||
nodeOrigin: NodeOrigin,
|
nodeOrigin: NodeOrigin,
|
||||||
nodeExtent: CoordinateExtent,
|
nodeExtent: CoordinateExtent,
|
||||||
selectedNodeZ: number
|
selectedNodeZ: number,
|
||||||
|
zIndexMode: ZIndexMode
|
||||||
) {
|
) {
|
||||||
const { x: parentX, y: parentY } = parentNode.internals.positionAbsolute;
|
const { x: parentX, y: parentY } = parentNode.internals.positionAbsolute;
|
||||||
const childDimensions = getNodeDimensions(childNode);
|
const childDimensions = getNodeDimensions(childNode);
|
||||||
@@ -274,7 +293,7 @@ function calculateChildXYZ<NodeType extends NodeBase>(
|
|||||||
absolutePosition = clampPositionToParent(absolutePosition, childDimensions, parentNode);
|
absolutePosition = clampPositionToParent(absolutePosition, childDimensions, parentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
const childZ = calculateZ(childNode, selectedNodeZ);
|
const childZ = calculateZ(childNode, selectedNodeZ, zIndexMode);
|
||||||
const parentZ = parentNode.internals.z ?? 0;
|
const parentZ = parentNode.internals.z ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -378,7 +397,8 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
|
|||||||
parentLookup: ParentLookup<NodeType>,
|
parentLookup: ParentLookup<NodeType>,
|
||||||
domNode: HTMLElement | null,
|
domNode: HTMLElement | null,
|
||||||
nodeOrigin?: NodeOrigin,
|
nodeOrigin?: NodeOrigin,
|
||||||
nodeExtent?: CoordinateExtent
|
nodeExtent?: CoordinateExtent,
|
||||||
|
zIndexMode?: ZIndexMode
|
||||||
): { changes: (NodeDimensionChange | NodePositionChange)[]; updatedInternals: boolean } {
|
): { changes: (NodeDimensionChange | NodePositionChange)[]; updatedInternals: boolean } {
|
||||||
const viewportNode = domNode?.querySelector('.xyflow__viewport');
|
const viewportNode = domNode?.querySelector('.xyflow__viewport');
|
||||||
let updatedInternals = false;
|
let updatedInternals = false;
|
||||||
@@ -446,7 +466,7 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
|
|||||||
nodeLookup.set(node.id, newNode);
|
nodeLookup.set(node.id, newNode);
|
||||||
|
|
||||||
if (node.parentId) {
|
if (node.parentId) {
|
||||||
updateChildNode(newNode, nodeLookup, parentLookup, { nodeOrigin });
|
updateChildNode(newNode, nodeLookup, parentLookup, { nodeOrigin, zIndexMode });
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedInternals = true;
|
updatedInternals = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user