react-grid-layout 1.5.3 → 2.0.0

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 (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
package/css/styles.css CHANGED
@@ -5,6 +5,7 @@
5
5
  .react-grid-item {
6
6
  transition: all 200ms ease;
7
7
  transition-property: left, top, width, height;
8
+ user-select: none;
8
9
  }
9
10
  .react-grid-item img {
10
11
  pointer-events: none;
@@ -34,10 +35,6 @@
34
35
  opacity: 0.2;
35
36
  transition-duration: 100ms;
36
37
  z-index: 2;
37
- -webkit-user-select: none;
38
- -moz-user-select: none;
39
- -ms-user-select: none;
40
- -o-user-select: none;
41
38
  user-select: none;
42
39
  }
43
40
 
@@ -49,6 +46,11 @@
49
46
  position: absolute;
50
47
  width: 20px;
51
48
  height: 20px;
49
+ opacity: 0;
50
+ }
51
+
52
+ .react-grid-item:hover > .react-resizable-handle {
53
+ opacity: 1;
52
54
  }
53
55
 
54
56
  .react-grid-item > .react-resizable-handle::after {
@@ -0,0 +1,124 @@
1
+ import React__default, { CSSProperties, DragEvent, ReactElement } from 'react';
2
+ import { j as GridConfig, k as DragConfig, l as ResizeConfig, m as DropConfig, i as PositionStrategy, c as Compactor, L as Layout, a as LayoutItem, B as Breakpoint, b as Breakpoints, R as ResponsiveLayouts } from './types-Cxf4nHNr.js';
3
+
4
+ /**
5
+ * GridLayout component
6
+ *
7
+ * A reactive, fluid grid layout with draggable, resizable components.
8
+ */
9
+
10
+ type EventCallback = (layout: Layout, oldItem: LayoutItem | null, newItem: LayoutItem | null, placeholder: LayoutItem | null, event: Event, element?: HTMLElement) => void;
11
+ interface GridLayoutProps {
12
+ /** Child elements to render in the grid */
13
+ children: React__default.ReactNode;
14
+ /** Width of the container in pixels */
15
+ width: number;
16
+ /**
17
+ * Grid measurement configuration.
18
+ * @see GridConfig
19
+ */
20
+ gridConfig?: Partial<GridConfig>;
21
+ /**
22
+ * Drag behavior configuration.
23
+ * @see DragConfig
24
+ */
25
+ dragConfig?: Partial<DragConfig>;
26
+ /**
27
+ * Resize behavior configuration.
28
+ * @see ResizeConfig
29
+ */
30
+ resizeConfig?: Partial<ResizeConfig>;
31
+ /**
32
+ * External drop configuration.
33
+ * @see DropConfig
34
+ */
35
+ dropConfig?: Partial<DropConfig>;
36
+ /**
37
+ * CSS positioning strategy.
38
+ * Use transformStrategy (default), absoluteStrategy, or createScaledStrategy(scale).
39
+ * @see PositionStrategy
40
+ */
41
+ positionStrategy?: PositionStrategy;
42
+ /**
43
+ * Layout compaction strategy.
44
+ * Use verticalCompactor (default), horizontalCompactor, or noCompactor.
45
+ * @see Compactor
46
+ */
47
+ compactor?: Compactor;
48
+ /** Layout definition */
49
+ layout?: Layout;
50
+ /** Item to use when dropping from outside */
51
+ droppingItem?: LayoutItem;
52
+ /** Whether to auto-size the container height */
53
+ autoSize?: boolean;
54
+ /** Additional class name */
55
+ className?: string;
56
+ /** Additional styles */
57
+ style?: CSSProperties;
58
+ /** Ref to the container element */
59
+ innerRef?: React__default.Ref<HTMLDivElement>;
60
+ /** Called when layout changes */
61
+ onLayoutChange?: (layout: Layout) => void;
62
+ /** Called when drag starts */
63
+ onDragStart?: EventCallback;
64
+ /** Called during drag */
65
+ onDrag?: EventCallback;
66
+ /** Called when drag stops */
67
+ onDragStop?: EventCallback;
68
+ /** Called when resize starts */
69
+ onResizeStart?: EventCallback;
70
+ /** Called during resize */
71
+ onResize?: EventCallback;
72
+ /** Called when resize stops */
73
+ onResizeStop?: EventCallback;
74
+ /** Called when an item is dropped from outside */
75
+ onDrop?: (layout: Layout, item: LayoutItem | undefined, e: Event) => void;
76
+ /** Called when dragging over the grid */
77
+ onDropDragOver?: (e: DragEvent) => {
78
+ w?: number;
79
+ h?: number;
80
+ } | false | void;
81
+ }
82
+ /**
83
+ * GridLayout - A reactive, fluid grid layout with draggable, resizable components.
84
+ */
85
+ declare function GridLayout(props: GridLayoutProps): ReactElement;
86
+
87
+ /**
88
+ * ResponsiveGridLayout component
89
+ *
90
+ * A responsive grid layout that automatically adjusts to container width.
91
+ */
92
+
93
+ interface ResponsiveGridLayoutProps<B extends Breakpoint = string> extends Omit<GridLayoutProps, "gridConfig" | "layout" | "onLayoutChange"> {
94
+ /** Current breakpoint (optional, auto-detected from width) */
95
+ breakpoint?: B;
96
+ /** Breakpoint definitions (name → min-width) */
97
+ breakpoints?: Breakpoints<B>;
98
+ /** Column counts per breakpoint */
99
+ cols?: Breakpoints<B>;
100
+ /** Layouts for each breakpoint */
101
+ layouts?: ResponsiveLayouts<B>;
102
+ /** Row height (default: 150) */
103
+ rowHeight?: number;
104
+ /** Maximum rows (default: Infinity) */
105
+ maxRows?: number;
106
+ /** Margin between items - can be fixed or per-breakpoint */
107
+ margin?: readonly [number, number] | Partial<Record<B, readonly [number, number]>>;
108
+ /** Container padding - can be fixed or per-breakpoint */
109
+ containerPadding?: readonly [number, number] | Partial<Record<B, readonly [number, number] | null>> | null;
110
+ /** Compactor for layout compaction */
111
+ compactor?: Compactor;
112
+ /** Called when breakpoint changes */
113
+ onBreakpointChange?: (newBreakpoint: B, cols: number) => void;
114
+ /** Called when layout changes */
115
+ onLayoutChange?: (layout: Layout, layouts: ResponsiveLayouts<B>) => void;
116
+ /** Called when width changes */
117
+ onWidthChange?: (containerWidth: number, margin: readonly [number, number], cols: number, containerPadding: readonly [number, number] | null) => void;
118
+ }
119
+ /**
120
+ * ResponsiveGridLayout - A responsive grid layout that adjusts to container width.
121
+ */
122
+ declare function ResponsiveGridLayout<B extends Breakpoint = string>(props: ResponsiveGridLayoutProps<B>): ReactElement;
123
+
124
+ export { type EventCallback as E, GridLayout as G, ResponsiveGridLayout as R, type GridLayoutProps as a, type ResponsiveGridLayoutProps as b };
@@ -0,0 +1,124 @@
1
+ import React__default, { CSSProperties, DragEvent, ReactElement } from 'react';
2
+ import { j as GridConfig, k as DragConfig, l as ResizeConfig, m as DropConfig, i as PositionStrategy, c as Compactor, L as Layout, a as LayoutItem, B as Breakpoint, b as Breakpoints, R as ResponsiveLayouts } from './types-Cxf4nHNr.mjs';
3
+
4
+ /**
5
+ * GridLayout component
6
+ *
7
+ * A reactive, fluid grid layout with draggable, resizable components.
8
+ */
9
+
10
+ type EventCallback = (layout: Layout, oldItem: LayoutItem | null, newItem: LayoutItem | null, placeholder: LayoutItem | null, event: Event, element?: HTMLElement) => void;
11
+ interface GridLayoutProps {
12
+ /** Child elements to render in the grid */
13
+ children: React__default.ReactNode;
14
+ /** Width of the container in pixels */
15
+ width: number;
16
+ /**
17
+ * Grid measurement configuration.
18
+ * @see GridConfig
19
+ */
20
+ gridConfig?: Partial<GridConfig>;
21
+ /**
22
+ * Drag behavior configuration.
23
+ * @see DragConfig
24
+ */
25
+ dragConfig?: Partial<DragConfig>;
26
+ /**
27
+ * Resize behavior configuration.
28
+ * @see ResizeConfig
29
+ */
30
+ resizeConfig?: Partial<ResizeConfig>;
31
+ /**
32
+ * External drop configuration.
33
+ * @see DropConfig
34
+ */
35
+ dropConfig?: Partial<DropConfig>;
36
+ /**
37
+ * CSS positioning strategy.
38
+ * Use transformStrategy (default), absoluteStrategy, or createScaledStrategy(scale).
39
+ * @see PositionStrategy
40
+ */
41
+ positionStrategy?: PositionStrategy;
42
+ /**
43
+ * Layout compaction strategy.
44
+ * Use verticalCompactor (default), horizontalCompactor, or noCompactor.
45
+ * @see Compactor
46
+ */
47
+ compactor?: Compactor;
48
+ /** Layout definition */
49
+ layout?: Layout;
50
+ /** Item to use when dropping from outside */
51
+ droppingItem?: LayoutItem;
52
+ /** Whether to auto-size the container height */
53
+ autoSize?: boolean;
54
+ /** Additional class name */
55
+ className?: string;
56
+ /** Additional styles */
57
+ style?: CSSProperties;
58
+ /** Ref to the container element */
59
+ innerRef?: React__default.Ref<HTMLDivElement>;
60
+ /** Called when layout changes */
61
+ onLayoutChange?: (layout: Layout) => void;
62
+ /** Called when drag starts */
63
+ onDragStart?: EventCallback;
64
+ /** Called during drag */
65
+ onDrag?: EventCallback;
66
+ /** Called when drag stops */
67
+ onDragStop?: EventCallback;
68
+ /** Called when resize starts */
69
+ onResizeStart?: EventCallback;
70
+ /** Called during resize */
71
+ onResize?: EventCallback;
72
+ /** Called when resize stops */
73
+ onResizeStop?: EventCallback;
74
+ /** Called when an item is dropped from outside */
75
+ onDrop?: (layout: Layout, item: LayoutItem | undefined, e: Event) => void;
76
+ /** Called when dragging over the grid */
77
+ onDropDragOver?: (e: DragEvent) => {
78
+ w?: number;
79
+ h?: number;
80
+ } | false | void;
81
+ }
82
+ /**
83
+ * GridLayout - A reactive, fluid grid layout with draggable, resizable components.
84
+ */
85
+ declare function GridLayout(props: GridLayoutProps): ReactElement;
86
+
87
+ /**
88
+ * ResponsiveGridLayout component
89
+ *
90
+ * A responsive grid layout that automatically adjusts to container width.
91
+ */
92
+
93
+ interface ResponsiveGridLayoutProps<B extends Breakpoint = string> extends Omit<GridLayoutProps, "gridConfig" | "layout" | "onLayoutChange"> {
94
+ /** Current breakpoint (optional, auto-detected from width) */
95
+ breakpoint?: B;
96
+ /** Breakpoint definitions (name → min-width) */
97
+ breakpoints?: Breakpoints<B>;
98
+ /** Column counts per breakpoint */
99
+ cols?: Breakpoints<B>;
100
+ /** Layouts for each breakpoint */
101
+ layouts?: ResponsiveLayouts<B>;
102
+ /** Row height (default: 150) */
103
+ rowHeight?: number;
104
+ /** Maximum rows (default: Infinity) */
105
+ maxRows?: number;
106
+ /** Margin between items - can be fixed or per-breakpoint */
107
+ margin?: readonly [number, number] | Partial<Record<B, readonly [number, number]>>;
108
+ /** Container padding - can be fixed or per-breakpoint */
109
+ containerPadding?: readonly [number, number] | Partial<Record<B, readonly [number, number] | null>> | null;
110
+ /** Compactor for layout compaction */
111
+ compactor?: Compactor;
112
+ /** Called when breakpoint changes */
113
+ onBreakpointChange?: (newBreakpoint: B, cols: number) => void;
114
+ /** Called when layout changes */
115
+ onLayoutChange?: (layout: Layout, layouts: ResponsiveLayouts<B>) => void;
116
+ /** Called when width changes */
117
+ onWidthChange?: (containerWidth: number, margin: readonly [number, number], cols: number, containerPadding: readonly [number, number] | null) => void;
118
+ }
119
+ /**
120
+ * ResponsiveGridLayout - A responsive grid layout that adjusts to container width.
121
+ */
122
+ declare function ResponsiveGridLayout<B extends Breakpoint = string>(props: ResponsiveGridLayoutProps<B>): ReactElement;
123
+
124
+ export { type EventCallback as E, GridLayout as G, ResponsiveGridLayout as R, type GridLayoutProps as a, type ResponsiveGridLayoutProps as b };
@@ -0,0 +1,168 @@
1
+ import { P as Position, d as ResizeHandleAxis } from './types-Cxf4nHNr.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
+ * Calculate grid units from pixel dimensions.
79
+ *
80
+ * @param positionParams - Grid parameters
81
+ * @param width - Width in pixels
82
+ * @param height - Height in pixels
83
+ * @param x - X coordinate in grid units (for clamping)
84
+ * @param y - Y coordinate in grid units (for clamping)
85
+ * @param handle - Resize handle being used
86
+ * @returns w, h in grid units
87
+ */
88
+ declare function calcWH(positionParams: PositionParams, width: number, height: number, x: number, y: number, handle: ResizeHandleAxis): {
89
+ w: number;
90
+ h: number;
91
+ };
92
+ /**
93
+ * Clamp a number between bounds.
94
+ *
95
+ * @param num - Number to clamp
96
+ * @param lowerBound - Minimum value
97
+ * @param upperBound - Maximum value
98
+ * @returns Clamped value
99
+ */
100
+ declare function clamp(num: number, lowerBound: number, upperBound: number): number;
101
+ /**
102
+ * Grid cell dimension information for rendering backgrounds or overlays.
103
+ */
104
+ interface GridCellDimensions {
105
+ /** Width of a single cell in pixels */
106
+ readonly cellWidth: number;
107
+ /** Height of a single cell in pixels */
108
+ readonly cellHeight: number;
109
+ /** Horizontal offset from container edge to first cell */
110
+ readonly offsetX: number;
111
+ /** Vertical offset from container edge to first cell */
112
+ readonly offsetY: number;
113
+ /** Horizontal gap between cells */
114
+ readonly gapX: number;
115
+ /** Vertical gap between cells */
116
+ readonly gapY: number;
117
+ /** Number of columns */
118
+ readonly cols: number;
119
+ /** Total container width */
120
+ readonly containerWidth: number;
121
+ }
122
+ /**
123
+ * Configuration for grid cell dimension calculation.
124
+ */
125
+ interface GridCellConfig {
126
+ /** Container width in pixels */
127
+ width: number;
128
+ /** Number of columns */
129
+ cols: number;
130
+ /** Row height in pixels */
131
+ rowHeight: number;
132
+ /** Margin between items [x, y] */
133
+ margin?: readonly [number, number];
134
+ /** Container padding [x, y], defaults to margin if not specified */
135
+ containerPadding?: readonly [number, number] | null;
136
+ }
137
+ /**
138
+ * Calculate grid cell dimensions for rendering backgrounds or overlays.
139
+ *
140
+ * This function provides all the measurements needed to render a visual
141
+ * grid background that aligns with the actual grid cells.
142
+ *
143
+ * @param config - Grid configuration
144
+ * @returns Cell dimensions and offsets
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * import { calcGridCellDimensions } from 'react-grid-layout/core';
149
+ *
150
+ * const dims = calcGridCellDimensions({
151
+ * width: 1200,
152
+ * cols: 12,
153
+ * rowHeight: 30,
154
+ * margin: [10, 10],
155
+ * containerPadding: [10, 10]
156
+ * });
157
+ *
158
+ * // dims.cellWidth = 88.33...
159
+ * // dims.cellHeight = 30
160
+ * // dims.offsetX = 10 (containerPadding[0])
161
+ * // dims.offsetY = 10 (containerPadding[1])
162
+ * // dims.gapX = 10 (margin[0])
163
+ * // dims.gapY = 10 (margin[1])
164
+ * ```
165
+ */
166
+ declare function calcGridCellDimensions(config: GridCellConfig): GridCellDimensions;
167
+
168
+ export { type GridCellDimensions as G, type PositionParams as P, calcXY as a, calcWH as b, calcGridItemPosition as c, type GridCellConfig as d, calcGridColWidth as e, calcGridItemWHPx as f, clamp as g, calcGridCellDimensions as h };
@@ -0,0 +1,168 @@
1
+ import { P as Position, d as ResizeHandleAxis } from './types-Cxf4nHNr.js';
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
+ * Calculate grid units from pixel dimensions.
79
+ *
80
+ * @param positionParams - Grid parameters
81
+ * @param width - Width in pixels
82
+ * @param height - Height in pixels
83
+ * @param x - X coordinate in grid units (for clamping)
84
+ * @param y - Y coordinate in grid units (for clamping)
85
+ * @param handle - Resize handle being used
86
+ * @returns w, h in grid units
87
+ */
88
+ declare function calcWH(positionParams: PositionParams, width: number, height: number, x: number, y: number, handle: ResizeHandleAxis): {
89
+ w: number;
90
+ h: number;
91
+ };
92
+ /**
93
+ * Clamp a number between bounds.
94
+ *
95
+ * @param num - Number to clamp
96
+ * @param lowerBound - Minimum value
97
+ * @param upperBound - Maximum value
98
+ * @returns Clamped value
99
+ */
100
+ declare function clamp(num: number, lowerBound: number, upperBound: number): number;
101
+ /**
102
+ * Grid cell dimension information for rendering backgrounds or overlays.
103
+ */
104
+ interface GridCellDimensions {
105
+ /** Width of a single cell in pixels */
106
+ readonly cellWidth: number;
107
+ /** Height of a single cell in pixels */
108
+ readonly cellHeight: number;
109
+ /** Horizontal offset from container edge to first cell */
110
+ readonly offsetX: number;
111
+ /** Vertical offset from container edge to first cell */
112
+ readonly offsetY: number;
113
+ /** Horizontal gap between cells */
114
+ readonly gapX: number;
115
+ /** Vertical gap between cells */
116
+ readonly gapY: number;
117
+ /** Number of columns */
118
+ readonly cols: number;
119
+ /** Total container width */
120
+ readonly containerWidth: number;
121
+ }
122
+ /**
123
+ * Configuration for grid cell dimension calculation.
124
+ */
125
+ interface GridCellConfig {
126
+ /** Container width in pixels */
127
+ width: number;
128
+ /** Number of columns */
129
+ cols: number;
130
+ /** Row height in pixels */
131
+ rowHeight: number;
132
+ /** Margin between items [x, y] */
133
+ margin?: readonly [number, number];
134
+ /** Container padding [x, y], defaults to margin if not specified */
135
+ containerPadding?: readonly [number, number] | null;
136
+ }
137
+ /**
138
+ * Calculate grid cell dimensions for rendering backgrounds or overlays.
139
+ *
140
+ * This function provides all the measurements needed to render a visual
141
+ * grid background that aligns with the actual grid cells.
142
+ *
143
+ * @param config - Grid configuration
144
+ * @returns Cell dimensions and offsets
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * import { calcGridCellDimensions } from 'react-grid-layout/core';
149
+ *
150
+ * const dims = calcGridCellDimensions({
151
+ * width: 1200,
152
+ * cols: 12,
153
+ * rowHeight: 30,
154
+ * margin: [10, 10],
155
+ * containerPadding: [10, 10]
156
+ * });
157
+ *
158
+ * // dims.cellWidth = 88.33...
159
+ * // dims.cellHeight = 30
160
+ * // dims.offsetX = 10 (containerPadding[0])
161
+ * // dims.offsetY = 10 (containerPadding[1])
162
+ * // dims.gapX = 10 (margin[0])
163
+ * // dims.gapY = 10 (margin[1])
164
+ * ```
165
+ */
166
+ declare function calcGridCellDimensions(config: GridCellConfig): GridCellDimensions;
167
+
168
+ export { type GridCellDimensions as G, type PositionParams as P, calcXY as a, calcWH as b, calcGridItemPosition as c, type GridCellConfig as d, calcGridColWidth as e, calcGridItemWHPx as f, clamp as g, calcGridCellDimensions as h };