MCPcopy
hub / github.com/udecode/plate / normalizeNode

Function normalizeNode

packages/core/src/lib/plugins/node-id/NodeIdPlugin.ts:243–280  ·  view source on GitHub ↗
(node: Descendant, path: number[])

Source from the content-addressed store, hash-verified

241 }
242
243 const normalizeNode = (node: Descendant, path: number[]): Descendant => {
244 let nextNode = node;
245 let childrenChanged = false;
246
247 if (shouldAssignNodeId([node, path], options)) {
248 nextNode = {
249 ...node,
250 [idKey]: idCreator(),
251 };
252 }
253
254 if (ElementApi.isElement(node)) {
255 const nextChildren = node.children.map((child, index) => {
256 const nextChild = normalizeNode(child as Descendant, [...path, index]);
257
258 if (nextChild !== child) {
259 childrenChanged = true;
260 }
261
262 return nextChild;
263 });
264
265 if (childrenChanged) {
266 nextNode =
267 nextNode === node
268 ? {
269 ...node,
270 children: nextChildren,
271 }
272 : {
273 ...nextNode,
274 children: nextChildren,
275 };
276 }
277 }
278
279 return nextNode;
280 };
281
282 let valueChanged = false;
283

Callers 2

normalizeNodeIdRuntimeFunction · 0.70
withSlateFunction · 0.50

Calls 1

shouldAssignNodeIdFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…