waveterm/frontend/util/layoututil.ts
Evan Simkowitz e85b0d205e
New layout model (#210)
This PR is a large refactoring of the layout code to move as much of the
layout state logic as possible into a unified model class, with atoms
and derived atoms to notify the display logic of changes. It also fixes
some latent bugs in the node resize code, significantly speeds up
response times for resizing and dragging, and sets us up to fully
replace the React-DnD library in the future.
2024-08-14 18:40:41 -07:00

31 lines
866 B
TypeScript

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { LayoutModel } from "@/layout/index";
function findLeafIdFromBlockId(layoutModel: LayoutModel, blockId: string): string {
if (layoutModel?.leafs == null) {
return null;
}
for (const leaf of layoutModel.leafs) {
if (leaf.data.blockId == blockId) {
return leaf.id;
}
}
return null;
}
function isBlockMagnified(layoutModel: LayoutModel, blockId: string): boolean {
if (layoutModel?.leafs == null || layoutModel.treeState.magnifiedNodeId == null) {
return false;
}
for (const leaf of layoutModel.leafs) {
if (leaf.data.blockId == blockId) {
return layoutModel.treeState.magnifiedNodeId == leaf.id;
}
}
return false;
}
export { findLeafIdFromBlockId, isBlockMagnified };