@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
@@ -0,0 +1,196 @@
1
+ import { P as Position, R as ResizeHandleAxis } from './types-Dbg8jAWj.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
+ * 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 };
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ // src/react/hooks/useContainerWidth.ts
6
+ function useContainerWidth(options = {}) {
7
+ function readContainerWidth(node, fallback) {
8
+ return node ? node.offsetWidth : fallback;
9
+ }
10
+ function createContainerWidthSnapshot(width2, mounted2) {
11
+ return { width: width2, mounted: mounted2, measured: mounted2 };
12
+ }
13
+ const { measureBeforeMount = false, initialWidth = 1280 } = options;
14
+ const [width, setWidth] = react.useState(initialWidth);
15
+ const [mounted, setMounted] = react.useState(!measureBeforeMount);
16
+ const containerRef = react.useRef(null);
17
+ const observerRef = react.useRef(null);
18
+ const measureWidth = react.useCallback(() => {
19
+ const node = containerRef.current;
20
+ if (node) {
21
+ const newWidth = readContainerWidth(node, initialWidth);
22
+ setWidth(newWidth);
23
+ if (!mounted) {
24
+ setMounted(true);
25
+ }
26
+ }
27
+ }, [mounted, initialWidth]);
28
+ react.useEffect(() => {
29
+ const node = containerRef.current;
30
+ if (!node) return;
31
+ measureWidth();
32
+ if (typeof ResizeObserver !== "undefined") {
33
+ let rafId = null;
34
+ observerRef.current = new ResizeObserver((entries) => {
35
+ const entry = entries[0];
36
+ if (entry) {
37
+ const newWidth = entry.contentRect.width;
38
+ if (rafId !== null) {
39
+ cancelAnimationFrame(rafId);
40
+ }
41
+ rafId = requestAnimationFrame(() => {
42
+ setWidth(newWidth);
43
+ rafId = null;
44
+ });
45
+ }
46
+ });
47
+ observerRef.current.observe(node);
48
+ return () => {
49
+ if (rafId !== null) {
50
+ cancelAnimationFrame(rafId);
51
+ }
52
+ if (observerRef.current) {
53
+ observerRef.current.disconnect();
54
+ observerRef.current = null;
55
+ }
56
+ };
57
+ }
58
+ return () => {
59
+ if (observerRef.current) {
60
+ observerRef.current.disconnect();
61
+ observerRef.current = null;
62
+ }
63
+ };
64
+ }, [measureWidth]);
65
+ const containerWidthSnapshot = createContainerWidthSnapshot(width, mounted);
66
+ return {
67
+ width: containerWidthSnapshot.width,
68
+ mounted: containerWidthSnapshot.mounted,
69
+ containerRef,
70
+ measureWidth
71
+ };
72
+ }
73
+
74
+ exports.useContainerWidth = useContainerWidth;
@@ -0,0 +1,72 @@
1
+ import { useState, useRef, useCallback, useEffect } from 'react';
2
+
3
+ // src/react/hooks/useContainerWidth.ts
4
+ function useContainerWidth(options = {}) {
5
+ function readContainerWidth(node, fallback) {
6
+ return node ? node.offsetWidth : fallback;
7
+ }
8
+ function createContainerWidthSnapshot(width2, mounted2) {
9
+ return { width: width2, mounted: mounted2, measured: mounted2 };
10
+ }
11
+ const { measureBeforeMount = false, initialWidth = 1280 } = options;
12
+ const [width, setWidth] = useState(initialWidth);
13
+ const [mounted, setMounted] = useState(!measureBeforeMount);
14
+ const containerRef = useRef(null);
15
+ const observerRef = useRef(null);
16
+ const measureWidth = useCallback(() => {
17
+ const node = containerRef.current;
18
+ if (node) {
19
+ const newWidth = readContainerWidth(node, initialWidth);
20
+ setWidth(newWidth);
21
+ if (!mounted) {
22
+ setMounted(true);
23
+ }
24
+ }
25
+ }, [mounted, initialWidth]);
26
+ useEffect(() => {
27
+ const node = containerRef.current;
28
+ if (!node) return;
29
+ measureWidth();
30
+ if (typeof ResizeObserver !== "undefined") {
31
+ let rafId = null;
32
+ observerRef.current = new ResizeObserver((entries) => {
33
+ const entry = entries[0];
34
+ if (entry) {
35
+ const newWidth = entry.contentRect.width;
36
+ if (rafId !== null) {
37
+ cancelAnimationFrame(rafId);
38
+ }
39
+ rafId = requestAnimationFrame(() => {
40
+ setWidth(newWidth);
41
+ rafId = null;
42
+ });
43
+ }
44
+ });
45
+ observerRef.current.observe(node);
46
+ return () => {
47
+ if (rafId !== null) {
48
+ cancelAnimationFrame(rafId);
49
+ }
50
+ if (observerRef.current) {
51
+ observerRef.current.disconnect();
52
+ observerRef.current = null;
53
+ }
54
+ };
55
+ }
56
+ return () => {
57
+ if (observerRef.current) {
58
+ observerRef.current.disconnect();
59
+ observerRef.current = null;
60
+ }
61
+ };
62
+ }, [measureWidth]);
63
+ const containerWidthSnapshot = createContainerWidthSnapshot(width, mounted);
64
+ return {
65
+ width: containerWidthSnapshot.width,
66
+ mounted: containerWidthSnapshot.mounted,
67
+ containerRef,
68
+ measureWidth
69
+ };
70
+ }
71
+
72
+ export { useContainerWidth };