@mitcsutt/kiln-dnd
Version:
Kiln drag and drop: sortable lists, boards, drop zones and grid layouts with one keyboard model and one announcer, rendered through kiln-ui
66 lines (65 loc) • 3.17 kB
TypeScript
/*! @license
* Vendored from react-grid-layout 2.3.0 (src/core/layout.ts), MIT licence.
* Copyright (c) 2016 Samuel Reed. See ./LICENSE.
* https://github.com/react-grid-layout/react-grid-layout/tree/2.3.0/src/core
*/
import type { CompactType, Layout, LayoutItem, Mutable } from './types.js';
/**
* Get the bottom-most Y coordinate of the layout.
*
* This is the Y position plus height of the lowest item.
*/
export declare function bottom(layout: Layout): number;
/** Get a layout item by its ID. */
export declare function getLayoutItem(layout: Layout, id: string): LayoutItem | undefined;
/**
* Get all static items from the layout.
*
* Static items cannot be moved or resized by the user.
*/
export declare function getStatics(layout: Layout): LayoutItem[];
/** Clone a layout item (a shallow copy with every property preserved). */
export declare function cloneLayoutItem(layoutItem: LayoutItem): LayoutItem;
/** Clone an entire layout. */
export declare function cloneLayout(layout: Layout): LayoutItem[];
/**
* Ensure all layout items fit within the grid bounds.
*
* - Items overflowing right are moved left
* - Items overflowing left are moved to x=0 and clamped to grid width
* - Static items that collide with other statics are moved down
*
* **IMPORTANT**: This function mutates the layout items in place for performance.
* Clone the layout first (e.g., with `cloneLayout()`) if you need immutability.
*/
export declare function correctBounds(layout: Mutable<LayoutItem>[], bounds: {
cols: number;
}): LayoutItem[];
/**
* Move a layout element to a new position.
*
* Handles collision detection and cascading movements.
* Does not compact the layout - call `compact()` separately.
*
* **Note**: This function mutates the `l` parameter directly for performance.
* The item's x, y, and moved properties will be modified. Callers should
* pass a cloned item if they need to preserve the original.
*
* @param layout - Full layout
* @param l - Item to move (will be mutated)
* @param x - New X position (or undefined to keep current)
* @param y - New Y position (or undefined to keep current)
* @param isUserAction - True if this is a direct user action (affects collision resolution)
* @param preventCollision - True to block movement into occupied space (item snaps back). No effect if allowOverlap is true.
* @param compactType - Compaction type for collision resolution
* @param cols - Number of columns in the grid
* @param allowOverlap - True to allow items to stack on top of each other
*/
export declare function moveElement(layout: Layout, l: LayoutItem, x: number | undefined, y: number | undefined, isUserAction: boolean | undefined, preventCollision: boolean | undefined, compactType: CompactType, cols: number, allowOverlap?: boolean): LayoutItem[];
/**
* Move an item away from a collision.
*
* Attempts to move the item up/left first if there's room,
* otherwise moves it down/right.
*/
export declare function moveElementAwayFromCollision(layout: Layout, collidesWith: LayoutItem, itemToMove: LayoutItem, isUserAction: boolean | undefined, compactType: CompactType, cols: number): LayoutItem[];