( node: T, parent: ParentNode | null, )
| 106 | sceneNode.map(convertNodeToAltNode(parent)).filter(isNotEmpty); |
| 107 | |
| 108 | export const cloneNode = <T extends BaseNode>( |
| 109 | node: T, |
| 110 | parent: ParentNode | null, |
| 111 | ): T => { |
| 112 | // Create the cloned object with the correct prototype |
| 113 | const cloned = {} as T; |
| 114 | // Create a new object with only the desired descriptors (excluding 'parent' and 'children') |
| 115 | for (const prop in node) { |
| 116 | if ( |
| 117 | prop !== "parent" && |
| 118 | prop !== "children" && |
| 119 | prop !== "horizontalPadding" && |
| 120 | prop !== "verticalPadding" && |
| 121 | prop !== "mainComponent" && |
| 122 | prop !== "masterComponent" && |
| 123 | prop !== "variantProperties" && |
| 124 | prop !== "get_annotations" && |
| 125 | prop !== "componentPropertyDefinitions" && |
| 126 | prop !== "exposedInstances" && |
| 127 | prop !== "instances" && |
| 128 | prop !== "componentProperties" && |
| 129 | prop !== "componenPropertyReferences" && |
| 130 | prop !== "constrainProportions" |
| 131 | ) { |
| 132 | cloned[prop as keyof T] = node[prop as keyof T]; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Set parent explicitly in addition to using assignParent |
| 137 | assignParent(parent, cloned); |
| 138 | // if (parent) { |
| 139 | // (cloned as any).parent = parent; |
| 140 | // } |
| 141 | |
| 142 | const altNode = { |
| 143 | ...cloned, |
| 144 | parent: cloned.parent, |
| 145 | originalNode: node, |
| 146 | canBeFlattened: canBeFlattened(node), |
| 147 | } as AltNode<T>; |
| 148 | |
| 149 | if (globalTextStyleSegments[node.id]) { |
| 150 | altNode.styledTextSegments = globalTextStyleSegments[node.id]; |
| 151 | } |
| 152 | |
| 153 | return altNode; |
| 154 | }; |
| 155 | |
| 156 | // auto convert Frame to Rectangle when Frame has no Children |
| 157 | const cloneAsRectangleNode = <T extends BaseNode>( |
no outgoing calls
no test coverage detected