fixed undefined option values
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { createWithEqualityFn } from 'zustand/traditional';
|
import { createWithEqualityFn } from 'zustand/traditional';
|
||||||
import {
|
import {
|
||||||
clampPosition,
|
|
||||||
getFitViewNodes,
|
getFitViewNodes,
|
||||||
fitView as fitViewSystem,
|
fitView as fitViewSystem,
|
||||||
adoptUserNodes,
|
adoptUserNodes,
|
||||||
|
|||||||
@@ -41,12 +41,23 @@ const adoptUserNodesDefaultOptions = {
|
|||||||
checkEquality: true,
|
checkEquality: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function mergeObjects<T extends Record<string, any>>(base: T, incoming?: Partial<T>): T {
|
||||||
|
const result = { ...base };
|
||||||
|
for (const key in incoming) {
|
||||||
|
if (incoming[key] !== undefined) {
|
||||||
|
result[key] = incoming[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
export function updateAbsolutePositions<NodeType extends NodeBase>(
|
export function updateAbsolutePositions<NodeType extends NodeBase>(
|
||||||
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
nodeLookup: NodeLookup<InternalNodeBase<NodeType>>,
|
||||||
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
||||||
options?: UpdateNodesOptions<NodeType>
|
options?: UpdateNodesOptions<NodeType>
|
||||||
) {
|
) {
|
||||||
const _options = { ...defaultOptions, ...options };
|
const _options = mergeObjects(defaultOptions, options);
|
||||||
for (const node of nodeLookup.values()) {
|
for (const node of nodeLookup.values()) {
|
||||||
if (!node.parentId) {
|
if (!node.parentId) {
|
||||||
continue;
|
continue;
|
||||||
@@ -70,7 +81,7 @@ export function adoptUserNodes<NodeType extends NodeBase>(
|
|||||||
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
||||||
options?: UpdateNodesOptions<NodeType>
|
options?: UpdateNodesOptions<NodeType>
|
||||||
) {
|
) {
|
||||||
const _options = { ...adoptUserNodesDefaultOptions, ...options };
|
const _options = mergeObjects(adoptUserNodesDefaultOptions, options);
|
||||||
|
|
||||||
const tmpLookup = new Map(nodeLookup);
|
const tmpLookup = new Map(nodeLookup);
|
||||||
nodeLookup.clear();
|
nodeLookup.clear();
|
||||||
@@ -117,7 +128,7 @@ function updateChildPosition<NodeType extends NodeBase>(
|
|||||||
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
parentLookup: ParentLookup<InternalNodeBase<NodeType>>,
|
||||||
options?: UpdateNodesOptions<NodeType>
|
options?: UpdateNodesOptions<NodeType>
|
||||||
) {
|
) {
|
||||||
const _options = { ...defaultOptions, ...options };
|
const _options = mergeObjects(defaultOptions, options);
|
||||||
|
|
||||||
const parentId = node.parentId!;
|
const parentId = node.parentId!;
|
||||||
const parentNode = nodeLookup.get(parentId);
|
const parentNode = nodeLookup.get(parentId);
|
||||||
|
|||||||
Reference in New Issue
Block a user