@sguisse/react-grid-layout 2.2.3-sguisse.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/css/styles.css +120 -0
  4. package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
  5. package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
  6. package/dist/calculate-CoBSgofg.d.mts +196 -0
  7. package/dist/calculate-K0IBpu53.d.ts +196 -0
  8. package/dist/chunk-7BT7XXIT.js +74 -0
  9. package/dist/chunk-G3PAJYGP.mjs +72 -0
  10. package/dist/chunk-ITLZ7N2R.mjs +456 -0
  11. package/dist/chunk-J4LTYI7L.js +485 -0
  12. package/dist/chunk-KKV4ZCG4.mjs +583 -0
  13. package/dist/chunk-LQOPWRJR.js +623 -0
  14. package/dist/chunk-O3KX3VYW.mjs +1 -0
  15. package/dist/chunk-STBCV65G.js +3159 -0
  16. package/dist/chunk-UZL6BMXQ.mjs +3146 -0
  17. package/dist/chunk-ZJHF4QM5.js +2 -0
  18. package/dist/core.d.mts +160 -0
  19. package/dist/core.d.ts +160 -0
  20. package/dist/core.js +268 -0
  21. package/dist/core.mjs +3 -0
  22. package/dist/extras.d.mts +208 -0
  23. package/dist/extras.d.ts +208 -0
  24. package/dist/extras.js +388 -0
  25. package/dist/extras.mjs +380 -0
  26. package/dist/index.d.mts +7 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.js +152 -0
  29. package/dist/index.mjs +5 -0
  30. package/dist/legacy.d.mts +163 -0
  31. package/dist/legacy.d.ts +163 -0
  32. package/dist/legacy.js +331 -0
  33. package/dist/legacy.mjs +319 -0
  34. package/dist/position-BeP60S5h.d.ts +316 -0
  35. package/dist/position-CeG3Nr4z.d.mts +316 -0
  36. package/dist/react.d.mts +214 -0
  37. package/dist/react.d.ts +214 -0
  38. package/dist/react.js +94 -0
  39. package/dist/react.mjs +5 -0
  40. package/dist/responsive-D4zBXLkH.d.ts +145 -0
  41. package/dist/responsive-DQi_9rBi.d.mts +145 -0
  42. package/dist/types-Dbg8jAWj.d.mts +458 -0
  43. package/dist/types-Dbg8jAWj.d.ts +458 -0
  44. package/index-dev.js +23 -0
  45. package/index.js +8 -0
  46. package/package.json +238 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Samuel Reed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ <p align="center">
2
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/test.yml">
3
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/test.yml/badge.svg?branch=release-sguisse" alt="CI Test">
4
+ </a>
5
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/lint.yml">
6
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/lint.yml/badge.svg?branch=release-sguisse" alt="Lint">
7
+ </a>
8
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/audit.yml">
9
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/audit.yml/badge.svg?branch=release-sguisse" alt="Dependency Audit">
10
+ </a>
11
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/release.yml">
12
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/release.yml/badge.svg?branch=release-sguisse" alt="Release">
13
+ </a>
14
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/gh-pages.yml">
15
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/gh-pages.yml/badge.svg?branch=release-sguisse" alt="Deployment">
16
+ </a>
17
+ <a href="https://github.com/sguisse/react-grid-layout/actions/workflows/stale.yml">
18
+ <img src="https://github.com/sguisse/react-grid-layout/actions/workflows/stale.yml/badge.svg" alt="Stale Management">
19
+ </a>
20
+ </p>
21
+
22
+ ---
23
+
24
+ # React-Grid-Layout ==> Forked
25
+
26
+ - See original [README-origin.md](README-origin.md)
27
+ - [Forked repo
28
+ ](https://github.com/sguisse/react-grid-layout)
29
+ - [DnD-kit samples](https://sguisse.github.io/react-grid-layout/examples/00-showcase.html)
30
+
31
+ ## DND-kit migration & cross-grid drag-and-drop
32
+
33
+ This fork replaces the previous drag/resize implementation (react-draggable + react-resizable) with the @dnd-kit suite (v0.3.2) to enable native drag-and-drop transfers between different Grid instances (cross-grid DnD).
34
+
35
+ Fork based from :
36
+
37
+ ```json
38
+ "name": "react-grid-layout",
39
+ "version": "2.2.3",
40
+ ```
41
+
42
+ ## Why we want to add cross-grid DnD support
43
+
44
+ **React-Grid-Layout** remains the premier choice for building responsive grids in React. Its robust architecture is the perfect foundation for complex layouts, though users have often sought a way to move items between separate grid instances—a feature known as **cross-grid drag-and-drop**.
45
+
46
+ Recognizing this as a key requirement for multi-section dashboards and a long-standing request within the community, I have extended the library to include native support for cross-grid interactions. This fork aims to provide that missing piece while staying true to the original's excellent design:
47
+
48
+ - https://github.com/react-grid-layout/react-grid-layout/pull/1462
49
+ - https://github.com/react-grid-layout/react-grid-layout/discussions/2078#discussioncomment-15990728
50
+
51
+ ## Why use Dnd-Kit
52
+
53
+ - @dnd-kit provides composable primitives for drag/drop and collision detection that make it possible to move items between separate droppable containers.
54
+ - Enables cross-grid transfers (drag item from Grid A and drop into Grid B) which was not feasible with the old libraries.
55
+ - Modern, actively maintained, and flexible for custom behaviors.
56
+
57
+ ## What changed
58
+
59
+ - Internal drag and resize handling now uses the following packages (already added as dependencies in this fork):
60
+ - `@dnd-kit/react` (v0.3.2)
61
+ - `@dnd-kit/dom` (v0.3.2)
62
+ - `@dnd-kit/collision` (v0.3.2)
63
+ - `@dnd-kit/abstract` (v0.3.2)
64
+ - The older `react-draggable` / `react-resizable` primitives were removed from the grid internals in favor of DND-kit primitives and custom positioning/collision strategies.
65
+ - A little bit of source code, ...
66
+
67
+ ## How I have done the migration
68
+
69
+ - After trying several different approaches, I finally achieved a successful migration by building a dedicated team of AI agents and custom skills to handle the heavy lifting.
70
+ - The most challenging part was engineering the specific instructions needed to structure the team effectively.
71
+ - I’ve left the implementation details in the `tools` folder if you’d like to explore them
72
+ - Just keep in mind that the current version isn't quite 'plug-and-play' for repeated runs yet!
73
+
74
+ ## Demo / sample
75
+
76
+ A new example demonstrates cross-grid transfers and is included under:
77
+
78
+ - `test/examples/22-cross-grid-transfer.jsx`
79
+
80
+ This example shows two independent grids where items can be dragged from one grid and dropped into the other. Use it to verify cross-grid behavior and to experiment with interactions.
81
+
82
+ ## How to run the sample (recommended: yarn)
83
+
84
+ 1. Install dependencies:
85
+
86
+ ```bash
87
+ cd /Users/mac-SGUISS21/01-work/01-projects/02-web/fork/react-grid-layout
88
+ yarn
89
+ ```
90
+
91
+ 2. Generate the static example pages and view them:
92
+
93
+ ```bash
94
+ yarn view-example # runs the example generator and serves the examples
95
+ # or
96
+ make build-example # build + generate example HTML
97
+ ```
98
+
99
+ 3. Open the example in your browser:
100
+
101
+ ```
102
+ http://localhost:4002/react-grid-layout/examples/22-cross-grid-transfer.html
103
+ ```
104
+
105
+ ## What to look for
106
+
107
+ - Drag an item from the left grid and drop it onto the right grid (and vice-versa).
108
+ - The example preserves item size and updates layouts on drop.
109
+ - Resize behavior is managed via the DND-kit integration.
110
+
111
+ ## Notes for contributors
112
+
113
+ - The public Grid API remains mostly compatible, but internals and event flows changed — if you implement custom grid children, ensure they forward refs and standard event props (`style`, `className`, `onMouseDown`, `onMouseUp`, `onTouchEnd`).
114
+ - The repository recommends using `yarn` to avoid npm peer-dependency resolution differences.
115
+
116
+ ## Sample
117
+
118
+ [DnD-kit samples](https://sguisse.github.io/react-grid-layout/examples/00-showcase.html)
119
+
120
+ ![22-cross-grid-transfer.png](22-cross-grid-transfer.png)
121
+
122
+ ## Migration Status
123
+
124
+ - 🚧 Non Regression Testing still in progress ... 🚧
125
+ - Continue to Review AI generated Code. I have push this version **seems** to be already "usable"
package/css/styles.css ADDED
@@ -0,0 +1,120 @@
1
+ .react-grid-layout {
2
+ position: relative;
3
+ transition: height 200ms ease;
4
+ }
5
+ .react-grid-item {
6
+ transition: all 200ms ease;
7
+ transition-property: left, top, width, height;
8
+ }
9
+ .react-grid-item img {
10
+ pointer-events: none;
11
+ user-select: none;
12
+ }
13
+ .react-grid-item.cssTransforms {
14
+ transition-property: transform, width, height;
15
+ }
16
+ .react-grid-item.resizing {
17
+ transition: none;
18
+ z-index: 1;
19
+ will-change: width, height;
20
+ }
21
+
22
+ .react-grid-item.react-draggable-dragging {
23
+ transition: none;
24
+ z-index: 3;
25
+ will-change: transform;
26
+ }
27
+
28
+ .react-grid-item.dropping {
29
+ visibility: hidden;
30
+ }
31
+
32
+ .react-grid-item.react-grid-placeholder {
33
+ background: red;
34
+ opacity: 0.2;
35
+ transition-duration: 100ms;
36
+ z-index: 2;
37
+ user-select: none;
38
+ }
39
+
40
+ .react-grid-item.react-grid-placeholder.placeholder-resizing {
41
+ transition: none;
42
+ }
43
+
44
+ .react-grid-item > .react-resizable-handle {
45
+ position: absolute;
46
+ width: 20px;
47
+ height: 20px;
48
+ opacity: 0;
49
+ }
50
+
51
+ .react-grid-item:hover > .react-resizable-handle {
52
+ opacity: 1;
53
+ }
54
+
55
+ .react-grid-item > .react-resizable-handle::after {
56
+ content: "";
57
+ position: absolute;
58
+ right: 3px;
59
+ bottom: 3px;
60
+ width: 5px;
61
+ height: 5px;
62
+ border-right: 2px solid rgba(0, 0, 0, 0.4);
63
+ border-bottom: 2px solid rgba(0, 0, 0, 0.4);
64
+ }
65
+
66
+ .react-resizable-hide > .react-resizable-handle {
67
+ display: none;
68
+ }
69
+
70
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-sw {
71
+ bottom: 0;
72
+ left: 0;
73
+ cursor: sw-resize;
74
+ transform: rotate(90deg);
75
+ }
76
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-se {
77
+ bottom: 0;
78
+ right: 0;
79
+ cursor: se-resize;
80
+ }
81
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-nw {
82
+ top: 0;
83
+ left: 0;
84
+ cursor: nw-resize;
85
+ transform: rotate(180deg);
86
+ }
87
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-ne {
88
+ top: 0;
89
+ right: 0;
90
+ cursor: ne-resize;
91
+ transform: rotate(270deg);
92
+ }
93
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-w,
94
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-e {
95
+ top: 50%;
96
+ margin-top: -10px;
97
+ cursor: ew-resize;
98
+ }
99
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-w {
100
+ left: 0;
101
+ transform: rotate(135deg);
102
+ }
103
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-e {
104
+ right: 0;
105
+ transform: rotate(315deg);
106
+ }
107
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-n,
108
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-s {
109
+ left: 50%;
110
+ margin-left: -10px;
111
+ cursor: ns-resize;
112
+ }
113
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-n {
114
+ top: 0;
115
+ transform: rotate(225deg);
116
+ }
117
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-s {
118
+ bottom: 0;
119
+ transform: rotate(45deg);
120
+ }
@@ -0,0 +1,80 @@
1
+ import React__default, { CSSProperties, DragEvent, ReactElement } from 'react';
2
+ import { m as GridConfig, j as DragConfig, r as ResizeConfig, l as DropConfig, p as PositionStrategy, b as Compactor, f as LayoutConstraint, L as Layout, d as LayoutItem, E as EventCallback, B as Breakpoint, a as Breakpoints, e as ResponsiveLayouts } from './types-Dbg8jAWj.js';
3
+
4
+ /**
5
+ * GridLayout component
6
+ *
7
+ * A reactive, fluid grid layout with draggable, resizable components.
8
+ */
9
+
10
+ interface GridLayoutProps {
11
+ children: React__default.ReactNode;
12
+ width: number;
13
+ gridConfig?: Partial<GridConfig>;
14
+ dragConfig?: Partial<DragConfig>;
15
+ resizeConfig?: Partial<ResizeConfig>;
16
+ dropConfig?: Partial<DropConfig>;
17
+ positionStrategy?: PositionStrategy;
18
+ compactor?: Compactor;
19
+ constraints?: LayoutConstraint[];
20
+ layout?: Layout;
21
+ droppingItem?: LayoutItem;
22
+ autoSize?: boolean;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ innerRef?: React__default.Ref<HTMLDivElement>;
26
+ onLayoutChange?: (layout: Layout) => void;
27
+ onDragStart?: EventCallback;
28
+ onDrag?: EventCallback;
29
+ onDragStop?: EventCallback;
30
+ onResizeStart?: EventCallback;
31
+ onResize?: EventCallback;
32
+ onResizeStop?: EventCallback;
33
+ onDrop?: (layout: Layout, item: LayoutItem | undefined, e: Event) => void;
34
+ onDropDragOver?: (e: DragEvent) => {
35
+ w?: number;
36
+ h?: number;
37
+ dragOffsetX?: number;
38
+ dragOffsetY?: number;
39
+ } | false | void;
40
+ }
41
+ declare function GridLayout(props: GridLayoutProps): ReactElement;
42
+
43
+ /**
44
+ * ResponsiveGridLayout component
45
+ *
46
+ * A responsive grid layout that automatically adjusts to container width.
47
+ */
48
+
49
+ interface ResponsiveGridLayoutProps<B extends Breakpoint = string> extends Omit<GridLayoutProps, "gridConfig" | "layout" | "onLayoutChange"> {
50
+ /** Current breakpoint (optional, auto-detected from width) */
51
+ breakpoint?: B;
52
+ /** Breakpoint definitions (name → min-width) */
53
+ breakpoints?: Breakpoints<B>;
54
+ /** Column counts per breakpoint */
55
+ cols?: Breakpoints<B>;
56
+ /** Layouts for each breakpoint */
57
+ layouts?: ResponsiveLayouts<B>;
58
+ /** Row height (default: 150) */
59
+ rowHeight?: number;
60
+ /** Maximum rows (default: Infinity) */
61
+ maxRows?: number;
62
+ /** Margin between items - can be fixed or per-breakpoint */
63
+ margin?: readonly [number, number] | Partial<Record<B, readonly [number, number]>>;
64
+ /** Container padding - can be fixed or per-breakpoint */
65
+ containerPadding?: readonly [number, number] | Partial<Record<B, readonly [number, number] | null>> | null;
66
+ /** Compactor for layout compaction */
67
+ compactor?: Compactor;
68
+ /** Called when breakpoint changes */
69
+ onBreakpointChange?: (newBreakpoint: B, cols: number) => void;
70
+ /** Called when layout changes */
71
+ onLayoutChange?: (layout: Layout, layouts: ResponsiveLayouts<B>) => void;
72
+ /** Called when width changes */
73
+ onWidthChange?: (containerWidth: number, margin: readonly [number, number], cols: number, containerPadding: readonly [number, number] | null) => void;
74
+ }
75
+ /**
76
+ * ResponsiveGridLayout - A responsive grid layout that adjusts to container width.
77
+ */
78
+ declare function ResponsiveGridLayout<B extends Breakpoint = string>(props: ResponsiveGridLayoutProps<B>): ReactElement;
79
+
80
+ export { GridLayout as G, ResponsiveGridLayout as R, type GridLayoutProps as a, type ResponsiveGridLayoutProps as b };
@@ -0,0 +1,80 @@
1
+ import React__default, { CSSProperties, DragEvent, ReactElement } from 'react';
2
+ import { m as GridConfig, j as DragConfig, r as ResizeConfig, l as DropConfig, p as PositionStrategy, b as Compactor, f as LayoutConstraint, L as Layout, d as LayoutItem, E as EventCallback, B as Breakpoint, a as Breakpoints, e as ResponsiveLayouts } from './types-Dbg8jAWj.mjs';
3
+
4
+ /**
5
+ * GridLayout component
6
+ *
7
+ * A reactive, fluid grid layout with draggable, resizable components.
8
+ */
9
+
10
+ interface GridLayoutProps {
11
+ children: React__default.ReactNode;
12
+ width: number;
13
+ gridConfig?: Partial<GridConfig>;
14
+ dragConfig?: Partial<DragConfig>;
15
+ resizeConfig?: Partial<ResizeConfig>;
16
+ dropConfig?: Partial<DropConfig>;
17
+ positionStrategy?: PositionStrategy;
18
+ compactor?: Compactor;
19
+ constraints?: LayoutConstraint[];
20
+ layout?: Layout;
21
+ droppingItem?: LayoutItem;
22
+ autoSize?: boolean;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ innerRef?: React__default.Ref<HTMLDivElement>;
26
+ onLayoutChange?: (layout: Layout) => void;
27
+ onDragStart?: EventCallback;
28
+ onDrag?: EventCallback;
29
+ onDragStop?: EventCallback;
30
+ onResizeStart?: EventCallback;
31
+ onResize?: EventCallback;
32
+ onResizeStop?: EventCallback;
33
+ onDrop?: (layout: Layout, item: LayoutItem | undefined, e: Event) => void;
34
+ onDropDragOver?: (e: DragEvent) => {
35
+ w?: number;
36
+ h?: number;
37
+ dragOffsetX?: number;
38
+ dragOffsetY?: number;
39
+ } | false | void;
40
+ }
41
+ declare function GridLayout(props: GridLayoutProps): ReactElement;
42
+
43
+ /**
44
+ * ResponsiveGridLayout component
45
+ *
46
+ * A responsive grid layout that automatically adjusts to container width.
47
+ */
48
+
49
+ interface ResponsiveGridLayoutProps<B extends Breakpoint = string> extends Omit<GridLayoutProps, "gridConfig" | "layout" | "onLayoutChange"> {
50
+ /** Current breakpoint (optional, auto-detected from width) */
51
+ breakpoint?: B;
52
+ /** Breakpoint definitions (name → min-width) */
53
+ breakpoints?: Breakpoints<B>;
54
+ /** Column counts per breakpoint */
55
+ cols?: Breakpoints<B>;
56
+ /** Layouts for each breakpoint */
57
+ layouts?: ResponsiveLayouts<B>;
58
+ /** Row height (default: 150) */
59
+ rowHeight?: number;
60
+ /** Maximum rows (default: Infinity) */
61
+ maxRows?: number;
62
+ /** Margin between items - can be fixed or per-breakpoint */
63
+ margin?: readonly [number, number] | Partial<Record<B, readonly [number, number]>>;
64
+ /** Container padding - can be fixed or per-breakpoint */
65
+ containerPadding?: readonly [number, number] | Partial<Record<B, readonly [number, number] | null>> | null;
66
+ /** Compactor for layout compaction */
67
+ compactor?: Compactor;
68
+ /** Called when breakpoint changes */
69
+ onBreakpointChange?: (newBreakpoint: B, cols: number) => void;
70
+ /** Called when layout changes */
71
+ onLayoutChange?: (layout: Layout, layouts: ResponsiveLayouts<B>) => void;
72
+ /** Called when width changes */
73
+ onWidthChange?: (containerWidth: number, margin: readonly [number, number], cols: number, containerPadding: readonly [number, number] | null) => void;
74
+ }
75
+ /**
76
+ * ResponsiveGridLayout - A responsive grid layout that adjusts to container width.
77
+ */
78
+ declare function ResponsiveGridLayout<B extends Breakpoint = string>(props: ResponsiveGridLayoutProps<B>): ReactElement;
79
+
80
+ export { GridLayout as G, ResponsiveGridLayout as R, type GridLayoutProps as a, type ResponsiveGridLayoutProps as b };
@@ -0,0 +1,196 @@
1
+ import { P as Position, R as ResizeHandleAxis } from './types-Dbg8jAWj.mjs';
2
+
3
+ /**
4
+ * Grid calculation utilities.
5
+ *
6
+ * These functions convert between grid units and pixel positions.
7
+ */
8
+
9
+ /**
10
+ * Parameters needed for position calculations.
11
+ */
12
+ interface PositionParams {
13
+ readonly margin: readonly [number, number];
14
+ readonly containerPadding: readonly [number, number];
15
+ readonly containerWidth: number;
16
+ readonly cols: number;
17
+ readonly rowHeight: number;
18
+ readonly maxRows: number;
19
+ }
20
+ /**
21
+ * Calculate the width of a single grid column in pixels.
22
+ *
23
+ * @param positionParams - Grid parameters
24
+ * @returns Column width in pixels
25
+ */
26
+ declare function calcGridColWidth(positionParams: PositionParams): number;
27
+ /**
28
+ * Calculate the pixel size for a grid unit dimension (width or height).
29
+ *
30
+ * Can be called as:
31
+ * - calcGridItemWHPx(w, colWidth, margin[0]) for width
32
+ * - calcGridItemWHPx(h, rowHeight, margin[1]) for height
33
+ *
34
+ * @param gridUnits - Size in grid units
35
+ * @param colOrRowSize - Column width or row height in pixels
36
+ * @param marginPx - Margin between items in pixels
37
+ * @returns Size in pixels
38
+ */
39
+ declare function calcGridItemWHPx(gridUnits: number, colOrRowSize: number, marginPx: number): number;
40
+ /**
41
+ * Calculate pixel position for a grid item.
42
+ *
43
+ * Returns left, top, width, height in pixels.
44
+ *
45
+ * @param positionParams - Grid parameters
46
+ * @param x - X coordinate in grid units
47
+ * @param y - Y coordinate in grid units
48
+ * @param w - Width in grid units
49
+ * @param h - Height in grid units
50
+ * @param dragPosition - If present, use exact left/top from drag callbacks
51
+ * @param resizePosition - If present, use exact dimensions from resize callbacks
52
+ * @returns Position in pixels
53
+ */
54
+ declare function calcGridItemPosition(positionParams: PositionParams, x: number, y: number, w: number, h: number, dragPosition?: {
55
+ top: number;
56
+ left: number;
57
+ } | null, resizePosition?: {
58
+ top: number;
59
+ left: number;
60
+ height: number;
61
+ width: number;
62
+ } | null): Position;
63
+ /**
64
+ * Translate pixel coordinates to grid units.
65
+ *
66
+ * @param positionParams - Grid parameters
67
+ * @param top - Top position in pixels (relative to parent)
68
+ * @param left - Left position in pixels (relative to parent)
69
+ * @param w - Width in grid units (for clamping)
70
+ * @param h - Height in grid units (for clamping)
71
+ * @returns x and y in grid units
72
+ */
73
+ declare function calcXY(positionParams: PositionParams, top: number, left: number, w: number, h: number): {
74
+ x: number;
75
+ y: number;
76
+ };
77
+ /**
78
+ * Translate pixel coordinates to grid units without clamping.
79
+ *
80
+ * Use this with the constraint system for custom boundary control.
81
+ *
82
+ * @param positionParams - Grid parameters
83
+ * @param top - Top position in pixels (relative to parent)
84
+ * @param left - Left position in pixels (relative to parent)
85
+ * @returns x and y in grid units (unclamped)
86
+ */
87
+ declare function calcXYRaw(positionParams: PositionParams, top: number, left: number): {
88
+ x: number;
89
+ y: number;
90
+ };
91
+ /**
92
+ * Calculate grid units from pixel dimensions.
93
+ *
94
+ * @param positionParams - Grid parameters
95
+ * @param width - Width in pixels
96
+ * @param height - Height in pixels
97
+ * @param x - X coordinate in grid units (for clamping)
98
+ * @param y - Y coordinate in grid units (for clamping)
99
+ * @param handle - Resize handle being used
100
+ * @returns w, h in grid units
101
+ */
102
+ declare function calcWH(positionParams: PositionParams, width: number, height: number, x: number, y: number, handle: ResizeHandleAxis): {
103
+ w: number;
104
+ h: number;
105
+ };
106
+ /**
107
+ * Calculate grid units from pixel dimensions without clamping.
108
+ *
109
+ * Use this with the constraint system for custom size control.
110
+ *
111
+ * @param positionParams - Grid parameters
112
+ * @param width - Width in pixels
113
+ * @param height - Height in pixels
114
+ * @returns w, h in grid units (unclamped, minimum 1)
115
+ */
116
+ declare function calcWHRaw(positionParams: PositionParams, width: number, height: number): {
117
+ w: number;
118
+ h: number;
119
+ };
120
+ /**
121
+ * Clamp a number between bounds.
122
+ *
123
+ * @param num - Number to clamp
124
+ * @param lowerBound - Minimum value
125
+ * @param upperBound - Maximum value
126
+ * @returns Clamped value
127
+ */
128
+ declare function clamp(num: number, lowerBound: number, upperBound: number): number;
129
+ /**
130
+ * Grid cell dimension information for rendering backgrounds or overlays.
131
+ */
132
+ interface GridCellDimensions {
133
+ /** Width of a single cell in pixels */
134
+ readonly cellWidth: number;
135
+ /** Height of a single cell in pixels */
136
+ readonly cellHeight: number;
137
+ /** Horizontal offset from container edge to first cell */
138
+ readonly offsetX: number;
139
+ /** Vertical offset from container edge to first cell */
140
+ readonly offsetY: number;
141
+ /** Horizontal gap between cells */
142
+ readonly gapX: number;
143
+ /** Vertical gap between cells */
144
+ readonly gapY: number;
145
+ /** Number of columns */
146
+ readonly cols: number;
147
+ /** Total container width */
148
+ readonly containerWidth: number;
149
+ }
150
+ /**
151
+ * Configuration for grid cell dimension calculation.
152
+ */
153
+ interface GridCellConfig {
154
+ /** Container width in pixels */
155
+ width: number;
156
+ /** Number of columns */
157
+ cols: number;
158
+ /** Row height in pixels */
159
+ rowHeight: number;
160
+ /** Margin between items [x, y] */
161
+ margin?: readonly [number, number];
162
+ /** Container padding [x, y], defaults to margin if not specified */
163
+ containerPadding?: readonly [number, number] | null;
164
+ }
165
+ /**
166
+ * Calculate grid cell dimensions for rendering backgrounds or overlays.
167
+ *
168
+ * This function provides all the measurements needed to render a visual
169
+ * grid background that aligns with the actual grid cells.
170
+ *
171
+ * @param config - Grid configuration
172
+ * @returns Cell dimensions and offsets
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * import { calcGridCellDimensions } from 'react-grid-layout/core';
177
+ *
178
+ * const dims = calcGridCellDimensions({
179
+ * width: 1200,
180
+ * cols: 12,
181
+ * rowHeight: 30,
182
+ * margin: [10, 10],
183
+ * containerPadding: [10, 10]
184
+ * });
185
+ *
186
+ * // dims.cellWidth = 88.33...
187
+ * // dims.cellHeight = 30
188
+ * // dims.offsetX = 10 (containerPadding[0])
189
+ * // dims.offsetY = 10 (containerPadding[1])
190
+ * // dims.gapX = 10 (margin[0])
191
+ * // dims.gapY = 10 (margin[1])
192
+ * ```
193
+ */
194
+ declare function calcGridCellDimensions(config: GridCellConfig): GridCellDimensions;
195
+
196
+ export { type GridCellConfig as G, type PositionParams as P, calcWH as a, calcXY as b, calcGridItemPosition as c, type GridCellDimensions as d, calcGridCellDimensions as e, calcGridColWidth as f, calcGridItemWHPx as g, calcWHRaw as h, calcXYRaw as i, clamp as j };