MCPcopy Index your code
hub / github.com/angular/components / deepCloneNode

Function deepCloneNode

src/cdk/drag-drop/dom/clone-node.ts:10–31  ·  view source on GitHub ↗
(node: HTMLElement)

Source from the content-addressed store, hash-verified

8
9/** Creates a deep clone of an element. */
10export function deepCloneNode(node: HTMLElement): HTMLElement {
11 const clone = node.cloneNode(true) as HTMLElement;
12 const descendantsWithId = clone.querySelectorAll('[id]');
13 const nodeName = node.nodeName.toLowerCase();
14
15 // Remove the `id` to avoid having multiple elements with the same id on the page.
16 clone.removeAttribute('id');
17
18 for (let i = 0; i < descendantsWithId.length; i++) {
19 descendantsWithId[i].removeAttribute('id');
20 }
21
22 if (nodeName === 'canvas') {
23 transferCanvasData(node as HTMLCanvasElement, clone as HTMLCanvasElement);
24 } else if (nodeName === 'input' || nodeName === 'select' || nodeName === 'textarea') {
25 transferInputData(node as HTMLInputElement, clone as HTMLInputElement);
26 }
27
28 transferData('canvas', node, clone, transferCanvasData);
29 transferData('input, textarea, select', node, clone, transferInputData);
30 return clone;
31}
32
33/** Matches elements between an element and its clone and allows for their data to be cloned. */
34function transferData<T extends Element>(

Callers 3

_createPreviewMethod · 0.90

Calls 3

transferCanvasDataFunction · 0.85
transferInputDataFunction · 0.85
transferDataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…