MCPcopy
hub / github.com/wavetermdev/waveterm / getNodeModel

Method getNodeModel

frontend/layout/lib/layoutModel.ts:1042–1098  ·  view source on GitHub ↗

* Gets the node model for the given node. * @param node The node for which to retrieve the node model. * @returns The node model for the given node.

(node: LayoutNode)

Source from the content-addressed store, hash-verified

1040 * @returns The node model for the given node.
1041 */
1042 getNodeModel(node: LayoutNode): NodeModel {
1043 const nodeid = node.id;
1044 const blockId = node.data.blockId;
1045 const addlPropsAtom = this.getNodeAdditionalPropertiesAtom(nodeid);
1046 if (!this.nodeModels.has(nodeid)) {
1047 this.nodeModels.set(nodeid, {
1048 additionalProps: addlPropsAtom,
1049 innerRect: atom((get) => {
1050 const addlProps = get(addlPropsAtom);
1051 const numLeafs = get(this.numLeafs);
1052 const gapSizePx = get(this.gapSizePx);
1053 if (numLeafs > 1 && addlProps?.rect) {
1054 return {
1055 width: `${addlProps.transform.width} - ${gapSizePx}px`,
1056 height: `${addlProps.transform.height} - ${gapSizePx}px`,
1057 } as CSSProperties;
1058 } else {
1059 return null;
1060 }
1061 }),
1062 nodeId: nodeid,
1063 blockId,
1064 blockNum: atom((get) => get(this.leafOrder).findIndex((leafEntry) => leafEntry.nodeid === nodeid) + 1),
1065 isFocused: atom((get) => {
1066 const treeState = get(this.localTreeStateAtom);
1067 const isFocused = treeState.focusedNodeId === nodeid;
1068 const focusType = get(FocusManager.getInstance().focusType);
1069 return isFocused && focusType === "node";
1070 }),
1071 numLeafs: this.numLeafs,
1072 isResizing: this.isResizing,
1073 isMagnified: atom((get) => {
1074 const treeState = get(this.localTreeStateAtom);
1075 return treeState.magnifiedNodeId === nodeid;
1076 }),
1077 anyMagnified: atom((get) => {
1078 const treeState = get(this.localTreeStateAtom);
1079 return treeState.magnifiedNodeId != null;
1080 }),
1081 isEphemeral: atom((get) => {
1082 const ephemeralNode = get(this.ephemeralNode);
1083 return ephemeralNode?.id === nodeid;
1084 }),
1085 addEphemeralNodeToLayout: () => this.addEphemeralNodeToLayout(),
1086 animationTimeS: this.animationTimeS,
1087 ready: this.ready,
1088 disablePointerEvents: this.activeDrag,
1089 onClose: () => fireAndForget(() => this.closeNode(nodeid)), // no longer used (instead we use keymodel uxCloseBlock)
1090 toggleMagnify: () => this.magnifyNodeToggle(nodeid),
1091 focusNode: () => this.focusNode(nodeid),
1092 dragHandleRef: createRef(),
1093 displayContainerRef: this.displayContainerRef,
1094 });
1095 }
1096 const nodeModel = this.nodeModels.get(nodeid);
1097 return nodeModel;
1098 }
1099

Callers 1

useNodeModelFunction · 0.80

Calls 9

closeNodeMethod · 0.95
magnifyNodeToggleMethod · 0.95
focusNodeMethod · 0.95
fireAndForgetFunction · 0.90
setMethod · 0.80
getMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected