@lonli-lokli/react-mosaic-component
Version:
A React Tiling Window Manager
126 lines (123 loc) • 5.95 kB
text/typescript
import { v as MosaicKey, M as MosaicNode, d as MosaicDirection, e as MosaicPath, b as MosaicTabsNode, L as LegacyMosaicNode, a as MosaicSplitNode } from '../../types-D_JoxNST.mjs';
import 'immutability-helper';
import 'react';
declare enum Corner {
TOP_LEFT = 1,
TOP_RIGHT = 2,
BOTTOM_LEFT = 3,
BOTTOM_RIGHT = 4
}
/**
* Returns `true` if `node` is a MosaicSplitNode
* @param node
* @returns {boolean}
*/
declare function isSplitNode<T extends MosaicKey>(node: MosaicNode<T> | null): node is MosaicSplitNode<T>;
declare function isTabsNode<T extends MosaicKey>(node: MosaicNode<T> | null): node is MosaicTabsNode<T>;
declare function getParentNode<T extends MosaicKey>(root: MosaicNode<T> | null, path: MosaicPath): MosaicNode<T> | null;
declare function getParentPath(path: MosaicPath): MosaicPath;
/**
* Creates a balanced binary tree from `leaves` with the goal of making them as equal area as possible
* @param leaves
* @param startDirection
* @returns {MosaicNode<T>}
*/
declare function createBalancedTreeFromLeaves<T extends MosaicKey>(leaves: MosaicNode<T>[], startDirection?: MosaicDirection): MosaicNode<T> | null;
/**
* Creates a balanced n-ary tree from `leaves` - alternative implementation
* that creates splits with multiple children when beneficial
* @param leaves
* @param startDirection
* @returns {MosaicNode<T>}
*/
declare function createBalancedNaryTreeFromLeaves<T extends MosaicKey>(leaves: MosaicNode<T>[], startDirection?: MosaicDirection, maxChildrenPerSplit?: number): MosaicNode<T> | null;
/**
* Gets the sibling index of the given child index
* For n-ary structures, this concept is less clear, so we return adjacent indices
* @param childIndex
* @param totalChildren
* @returns {number[]} Array of sibling indices
*/
declare function getOtherChildIndices(childIndex: number, totalChildren: number): number[];
/**
* Gets the opposite of `direction`
* @param direction
* @returns {any}
*/
declare function getOtherDirection(direction: MosaicDirection): MosaicDirection;
/**
* Traverses `tree` to find the path to the specified `corner`
* @param tree
* @param corner
* @returns {MosaicPath}
*/
declare function getPathToCorner(tree: MosaicNode<any>, corner: Corner): MosaicPath;
/**
* Gets all leaves of `tree`
* @param tree
* @returns {T[]}
*/
declare function getLeaves<T extends MosaicKey>(tree: MosaicNode<T> | null): T[];
/**
* Converts a legacy binary-tree MosaicNode to the new n-ary tree format.
* - `LegacyMosaicParent` is converted to `MosaicSplitNode`.
* - `splitPercentage` is converted to a `splitPercentages` array.
*
* @param legacyNode The node from the old binary tree structure.
* @returns The equivalent node in the new n-ary tree structure.
*/
declare function convertLegacyToNary<T extends MosaicKey>(legacyNode: null): null;
declare function convertLegacyToNary<T extends MosaicKey>(legacyNode: LegacyMosaicNode<T> | MosaicNode<T>): MosaicNode<T>;
declare function convertLegacyToNary<T extends MosaicKey>(legacyNode: LegacyMosaicNode<T> | MosaicNode<T> | null): MosaicNode<T> | null;
/**
* Recursively normalizes a mosaic tree to enforce logical constraints, returning a new tree.
* - Flattens Split nodes that have only one child.
* - Flattens Tabs nodes that have only one tab.
* - Removes empty Split or Tabs nodes completely.
*
* This should be run after any operation that might change the tree structure.
*
* @param node The mosaic node to normalize.
* @returns A normalized node, or null if the node becomes empty and should be removed.
*/
declare function normalizeMosaicTree<T extends MosaicKey>(node: MosaicNode<T> | null): MosaicNode<T> | null;
/**
* Helper to retrieve a node from the tree at a given path.
* Correctly traverses both 'split' and 'tabs' nodes.
*
* @param tree The root of the tree to search.
* @param path The path to the desired node.
* @returns The node at the path, or null if the path is invalid or the node doesn't exist.
*/
declare function getNodeAtPath<T extends MosaicKey>(tree: MosaicNode<T> | null, path: MosaicPath): MosaicNode<T> | null;
/**
* Updates the split percentages for a node in the tree based on a local resize action.
* This function only affects the two panes adjacent to the dragged splitter.
*
* @param tree The root of the mosaic tree.
* @param path The path to the `MosaicSplitNode` being resized.
* @param splitterIndex The index of the splitter being dragged (0 for the splitter between child 0 and 1).
* @param deltaPercentage The percentage change to apply. Positive makes the first pane larger.
* @param minimumPaneSizePercentage The minimum allowed size for a pane.
* @returns A new, updated mosaic tree.
*/
declare function resizeSplit<T extends MosaicKey>(tree: MosaicNode<T>, path: MosaicPath, splitterIndex: number, deltaPercentage: number, minimumPaneSizePercentage?: number): MosaicNode<T>;
/**
* Gets node at `path` from `tree` and verifies that neither `tree` nor the result are null
* @param tree
* @param path
* @returns {MosaicNode<T>}
*/
declare function getAndAssertNodeAtPathExists<T extends MosaicKey>(tree: MosaicNode<T> | null, path: MosaicPath): MosaicNode<T>;
/**
* Helper function to get the parent node and child index for a given path
* Useful for operations that need to modify a child
* @param tree
* @param path
* @returns Object with parent node and child index, or null if not found
*/
declare function getParentAndChildIndex<T extends MosaicKey>(tree: MosaicNode<T> | null, path: MosaicPath): {
parent: MosaicSplitNode<T> | MosaicTabsNode<T>;
childIndex: number;
} | null;
export { Corner, convertLegacyToNary, createBalancedNaryTreeFromLeaves, createBalancedTreeFromLeaves, getAndAssertNodeAtPathExists, getLeaves, getNodeAtPath, getOtherChildIndices, getOtherDirection, getParentAndChildIndex, getParentNode, getParentPath, getPathToCorner, isSplitNode, isTabsNode, normalizeMosaicTree, resizeSplit };