MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / updateTreeHelper

Method updateTreeHelper

frontend/layout/lib/layoutModel.ts:785–886  ·  view source on GitHub ↗

* Per-node callback that is invoked recursively to find leaf nodes, update the resize handles, and compute additional properties associated with the given node. * @param node The node for which to update the resize handles and additional properties. * @param additionalPropsMap The new map

(
        node: LayoutNode,
        additionalPropsMap: Record<string, LayoutNodeAdditionalProps>,
        leafs: LayoutNode[],
        resizeHandleSizePx: number,
        magnifiedNodeSizePct: number,
        boundingRect: Dimensions,
        resizeAction?: LayoutTreeResizeNodeAction
    )

Source from the content-addressed store, hash-verified

783 * @param resizeAction The pending resize action, if any. Used to set temporary size values on nodes that are being resized.
784 */
785 private updateTreeHelper(
786 node: LayoutNode,
787 additionalPropsMap: Record<string, LayoutNodeAdditionalProps>,
788 leafs: LayoutNode[],
789 resizeHandleSizePx: number,
790 magnifiedNodeSizePct: number,
791 boundingRect: Dimensions,
792 resizeAction?: LayoutTreeResizeNodeAction
793 ) {
794 if (!node.children?.length) {
795 leafs.push(node);
796 const addlProps = additionalPropsMap[node.id];
797 if (addlProps) {
798 if (this.magnifiedNodeId === node.id) {
799 const magnifiedNodeMarginPct = (1 - magnifiedNodeSizePct) / 2;
800 const transform = setTransform(
801 {
802 top: boundingRect.height * magnifiedNodeMarginPct,
803 left: boundingRect.width * magnifiedNodeMarginPct,
804 width: boundingRect.width * magnifiedNodeSizePct,
805 height: boundingRect.height * magnifiedNodeSizePct,
806 },
807 true,
808 true,
809 "var(--zindex-layout-magnified-node)"
810 );
811 addlProps.transform = transform;
812 }
813 if (this.lastMagnifiedNodeId === node.id) {
814 addlProps.transform.zIndex = "var(--zindex-layout-last-magnified-node)";
815 } else if (this.lastEphemeralNodeId === node.id) {
816 addlProps.transform.zIndex = "var(--zindex-layout-last-ephemeral-node)";
817 }
818 }
819 return;
820 }
821
822 function getNodeSize(node: LayoutNode) {
823 return resizeAction?.resizeOperations.find((op) => op.nodeId === node.id)?.size ?? node.size;
824 }
825
826 const additionalProps: LayoutNodeAdditionalProps = node.id in additionalPropsMap
827 ? additionalPropsMap[node.id]
828 : { treeKey: "0" };
829
830 const nodeRect: Dimensions = node.id === this.treeState.rootNode.id ? boundingRect : additionalProps.rect;
831 const nodeIsRow = node.flexDirection === FlexDirection.Row;
832 const nodePixels = nodeIsRow ? nodeRect.width : nodeRect.height;
833 const totalChildrenSize = node.children.reduce((acc, child) => acc + getNodeSize(child), 0);
834 const pixelToSizeRatio = totalChildrenSize / nodePixels;
835
836 let lastChildRect: Dimensions;
837 const resizeHandles: ResizeHandleProps[] = [];
838 node.children.forEach((child, i) => {
839 const childSize = getNodeSize(child);
840 const rect: Dimensions = {
841 top: !nodeIsRow && lastChildRect ? lastChildRect.top + lastChildRect.height : nodeRect.top,
842 left: nodeIsRow && lastChildRect ? lastChildRect.left + lastChildRect.width : nodeRect.left,

Callers 1

callbackMethod · 0.95

Calls 2

setTransformFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected