MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / addSiblingRecursive

Function addSiblingRecursive

frontend-workflow/src/utils/mindmapTree.ts:129–153  ·  view source on GitHub ↗
(
  node: MindMapTreeNode,
  nodeId: string,
)

Source from the content-addressed store, hash-verified

127 }));
128
129const addSiblingRecursive = (
130 node: MindMapTreeNode,
131 nodeId: string,
132): { changed: boolean; node: MindMapTreeNode } => {
133 const childIndex = node.children.findIndex((child) => child.id === nodeId);
134 if (childIndex >= 0) {
135 const nextChildren = [...node.children];
136 nextChildren.splice(childIndex + 1, 0, {
137 id: nextId(node.id),
138 label: '新分支',
139 summary: '',
140 children: [],
141 });
142 return { changed: true, node: { ...node, children: nextChildren } };
143 }
144
145 let changed = false;
146 const nextChildren = node.children.map((child) => {
147 const result = addSiblingRecursive(child, nodeId);
148 if (result.changed) changed = true;
149 return result.node;
150 });
151
152 return { changed, node: changed ? { ...node, children: nextChildren } : node };
153};
154
155export const addSiblingToNode = (root: MindMapTreeNode, nodeId: string): MindMapTreeNode => {
156 if (root.id === nodeId) return root;

Callers 1

addSiblingToNodeFunction · 0.85

Calls 2

nextIdFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected