@wordpress/grid 0.6.0 → 0.7.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.
- package/CHANGELOG.md +14 -0
- package/README.md +44 -1
- package/build/dashboard-grid/grid-item.cjs +21 -7
- package/build/dashboard-grid/grid-item.cjs.map +2 -2
- package/build/dashboard-grid/index.cjs +107 -45
- package/build/dashboard-grid/index.cjs.map +2 -2
- package/build/dashboard-grid/resolve-fill-widths.cjs +68 -50
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +2 -2
- package/build/dashboard-grid/types.cjs.map +1 -1
- package/build/dashboard-lanes/index.cjs +59 -17
- package/build/dashboard-lanes/index.cjs.map +2 -2
- package/build/dashboard-lanes/lanes-item.cjs +14 -6
- package/build/dashboard-lanes/lanes-item.cjs.map +2 -2
- package/build/dashboard-lanes/types.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/shared/array-move-with-pinned.cjs +49 -0
- package/build/shared/array-move-with-pinned.cjs.map +7 -0
- package/build/shared/resize-snap.cjs +91 -5
- package/build/shared/resize-snap.cjs.map +2 -2
- package/build/shared/types.cjs.map +1 -1
- package/build/shared/use-span-bounds.cjs +85 -0
- package/build/shared/use-span-bounds.cjs.map +7 -0
- package/build-module/dashboard-grid/grid-item.mjs +21 -7
- package/build-module/dashboard-grid/grid-item.mjs.map +2 -2
- package/build-module/dashboard-grid/index.mjs +108 -47
- package/build-module/dashboard-grid/index.mjs.map +2 -2
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +68 -50
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +2 -2
- package/build-module/dashboard-lanes/index.mjs +60 -19
- package/build-module/dashboard-lanes/index.mjs.map +2 -2
- package/build-module/dashboard-lanes/lanes-item.mjs +14 -6
- package/build-module/dashboard-lanes/lanes-item.mjs.map +2 -2
- package/build-module/index.mjs.map +1 -1
- package/build-module/shared/array-move-with-pinned.mjs +24 -0
- package/build-module/shared/array-move-with-pinned.mjs.map +7 -0
- package/build-module/shared/resize-snap.mjs +87 -4
- package/build-module/shared/resize-snap.mjs.map +2 -2
- package/build-module/shared/use-span-bounds.mjs +62 -0
- package/build-module/shared/use-span-bounds.mjs.map +7 -0
- package/build-types/dashboard-grid/grid-item.d.ts +1 -1
- package/build-types/dashboard-grid/grid-item.d.ts.map +1 -1
- package/build-types/dashboard-grid/index.d.ts.map +1 -1
- package/build-types/dashboard-grid/resolve-fill-widths.d.ts +12 -1
- package/build-types/dashboard-grid/resolve-fill-widths.d.ts.map +1 -1
- package/build-types/dashboard-grid/types.d.ts +43 -1
- package/build-types/dashboard-grid/types.d.ts.map +1 -1
- package/build-types/dashboard-lanes/index.d.ts.map +1 -1
- package/build-types/dashboard-lanes/lanes-item.d.ts +18 -1
- package/build-types/dashboard-lanes/lanes-item.d.ts.map +1 -1
- package/build-types/dashboard-lanes/types.d.ts +20 -1
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/shared/array-move-with-pinned.d.ts +13 -0
- package/build-types/shared/array-move-with-pinned.d.ts.map +1 -0
- package/build-types/shared/resize-snap.d.ts +65 -2
- package/build-types/shared/resize-snap.d.ts.map +1 -1
- package/build-types/shared/types.d.ts +31 -0
- package/build-types/shared/types.d.ts.map +1 -1
- package/build-types/shared/use-span-bounds.d.ts +29 -0
- package/build-types/shared/use-span-bounds.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/dashboard-grid/grid-item.tsx +21 -7
- package/src/dashboard-grid/index.tsx +154 -57
- package/src/dashboard-grid/resolve-fill-widths.ts +85 -62
- package/src/dashboard-grid/stories/index.story.tsx +154 -0
- package/src/dashboard-grid/test/item-interactions.jsdom.test.tsx +64 -0
- package/src/dashboard-grid/test/item-limits.jsdom.test.tsx +147 -0
- package/src/dashboard-grid/test/{keyboard-activation.test.tsx → keyboard-activation.jsdom.test.tsx} +4 -3
- package/src/dashboard-grid/test/resolve-fill-widths.test.ts +159 -0
- package/src/dashboard-grid/types.ts +50 -0
- package/src/dashboard-lanes/index.tsx +86 -24
- package/src/dashboard-lanes/lanes-item.tsx +34 -6
- package/src/dashboard-lanes/stories/index.story.tsx +119 -0
- package/src/dashboard-lanes/test/item-interactions.jsdom.test.tsx +64 -0
- package/src/dashboard-lanes/test/item-limits.jsdom.test.tsx +140 -0
- package/src/dashboard-lanes/test/{keyboard-activation.test.tsx → keyboard-activation.jsdom.test.tsx} +4 -3
- package/src/dashboard-lanes/test/lane-placement.test.ts +1 -0
- package/src/dashboard-lanes/test/{use-lane-placement.test.tsx → use-lane-placement.jsdom.test.tsx} +11 -10
- package/src/dashboard-lanes/types.ts +23 -0
- package/src/index.ts +2 -0
- package/src/shared/array-move-with-pinned.ts +36 -0
- package/src/shared/resize-snap.ts +161 -5
- package/src/shared/test/array-move-with-pinned.test.ts +40 -0
- package/src/shared/test/resize-snap.test.ts +171 -2
- package/src/shared/test/use-span-bounds.jsdom.test.ts +105 -0
- package/src/shared/types.ts +35 -0
- package/src/shared/use-span-bounds.ts +99 -0
package/src/shared/types.ts
CHANGED
|
@@ -159,3 +159,38 @@ export interface ResizeHandleProps {
|
|
|
159
159
|
*/
|
|
160
160
|
renderResizeHandle?: React.ComponentType< ResizeHandleRenderProps >;
|
|
161
161
|
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Per-item width limits, in pixels. Surfaces quantize each limit to
|
|
165
|
+
* whole tracks (minimums round up, maximums round down), bound rendered
|
|
166
|
+
* spans and resize gestures at the result, and never write it into the
|
|
167
|
+
* layout. A quantized minimum wins over a smaller quantized maximum.
|
|
168
|
+
*/
|
|
169
|
+
export type GridItemWidthLimits = {
|
|
170
|
+
/**
|
|
171
|
+
* Minimum tile width in pixels.
|
|
172
|
+
*/
|
|
173
|
+
minWidth?: number;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Maximum tile width in pixels.
|
|
177
|
+
*/
|
|
178
|
+
maxWidth?: number;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Per-item size limits on both axes, in pixels, for surfaces with row
|
|
183
|
+
* tracks. Height limits quantize against the row track when `rowHeight`
|
|
184
|
+
* is numeric and stay open otherwise.
|
|
185
|
+
*/
|
|
186
|
+
export type GridItemLimits = GridItemWidthLimits & {
|
|
187
|
+
/**
|
|
188
|
+
* Minimum tile height in pixels.
|
|
189
|
+
*/
|
|
190
|
+
minHeight?: number;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Maximum tile height in pixels.
|
|
194
|
+
*/
|
|
195
|
+
maxHeight?: number;
|
|
196
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useMemo } from '@wordpress/element';
|
|
2
|
+
import {
|
|
3
|
+
pixelLimitsToSpanBounds,
|
|
4
|
+
spanBoundsToPixelLimits,
|
|
5
|
+
} from './resize-snap';
|
|
6
|
+
import type { ResizePixelLimits, SpanBounds } from './resize-snap';
|
|
7
|
+
import type { GridItemLimits } from './types';
|
|
8
|
+
|
|
9
|
+
const NO_BOUNDS: ReadonlyMap< string, SpanBounds > = new Map();
|
|
10
|
+
const NO_LIMITS: ReadonlyMap< string, ResizePixelLimits > = new Map();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Quantizes per-item pixel limits to span bounds for the current
|
|
14
|
+
* geometry. The map keeps its identity while every bound is unchanged,
|
|
15
|
+
* so container width ticks and fresh `itemLimits` objects do not
|
|
16
|
+
* invalidate the layout memos or the sortable context downstream.
|
|
17
|
+
*
|
|
18
|
+
* @param itemLimits Per-item pixel limits, keyed by layout item key.
|
|
19
|
+
* @param columnWidth Width of one column track in pixels.
|
|
20
|
+
* @param gapPx Gap between tracks in pixels.
|
|
21
|
+
* @param rowHeightPx Row track height in pixels, or `null` when rows
|
|
22
|
+
* are content-sized.
|
|
23
|
+
* @param maxColumns Number of column tracks in the surface.
|
|
24
|
+
*/
|
|
25
|
+
export function useSpanBounds(
|
|
26
|
+
itemLimits: Record< string, GridItemLimits > | undefined,
|
|
27
|
+
columnWidth: number,
|
|
28
|
+
gapPx: number,
|
|
29
|
+
rowHeightPx: number | null,
|
|
30
|
+
maxColumns: number
|
|
31
|
+
): ReadonlyMap< string, SpanBounds > {
|
|
32
|
+
const computed = useMemo( () => {
|
|
33
|
+
if ( ! itemLimits ) {
|
|
34
|
+
return NO_BOUNDS;
|
|
35
|
+
}
|
|
36
|
+
const map = new Map< string, SpanBounds >();
|
|
37
|
+
for ( const [ key, limits ] of Object.entries( itemLimits ) ) {
|
|
38
|
+
map.set(
|
|
39
|
+
key,
|
|
40
|
+
pixelLimitsToSpanBounds(
|
|
41
|
+
limits,
|
|
42
|
+
columnWidth,
|
|
43
|
+
gapPx,
|
|
44
|
+
rowHeightPx,
|
|
45
|
+
maxColumns
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return map;
|
|
50
|
+
}, [ itemLimits, columnWidth, gapPx, rowHeightPx, maxColumns ] );
|
|
51
|
+
|
|
52
|
+
const signature = useMemo( () => {
|
|
53
|
+
let value = '';
|
|
54
|
+
for ( const [ key, bounds ] of computed ) {
|
|
55
|
+
value += `${ key }:${ bounds.minWidth }:${ bounds.minHeight }:${ bounds.maxWidth }:${ bounds.maxHeight }|`;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}, [ computed ] );
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `signature` encodes every bound; `computed` changes identity on geometry ticks that leave the bounds unchanged.
|
|
61
|
+
return useMemo( () => computed, [ signature ] );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Pixel limits for the resize gesture of every bounded item. Tracks
|
|
66
|
+
* the continuous geometry, but only recomputes when it changes, not on
|
|
67
|
+
* every gesture frame.
|
|
68
|
+
*
|
|
69
|
+
* @param spanBounds Span bounds per item key.
|
|
70
|
+
* @param columnWidth Width of one column track in pixels.
|
|
71
|
+
* @param gapPx Gap between tracks in pixels.
|
|
72
|
+
* @param rowHeightPx Row track height in pixels, or `null` when rows
|
|
73
|
+
* are content-sized.
|
|
74
|
+
*/
|
|
75
|
+
export function useResizePixelLimits(
|
|
76
|
+
spanBounds: ReadonlyMap< string, SpanBounds >,
|
|
77
|
+
columnWidth: number,
|
|
78
|
+
gapPx: number,
|
|
79
|
+
rowHeightPx: number | null
|
|
80
|
+
): ReadonlyMap< string, ResizePixelLimits > {
|
|
81
|
+
return useMemo( () => {
|
|
82
|
+
if ( spanBounds.size === 0 ) {
|
|
83
|
+
return NO_LIMITS;
|
|
84
|
+
}
|
|
85
|
+
const map = new Map< string, ResizePixelLimits >();
|
|
86
|
+
for ( const [ key, bounds ] of spanBounds ) {
|
|
87
|
+
map.set(
|
|
88
|
+
key,
|
|
89
|
+
spanBoundsToPixelLimits(
|
|
90
|
+
bounds,
|
|
91
|
+
columnWidth,
|
|
92
|
+
gapPx,
|
|
93
|
+
rowHeightPx
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return map;
|
|
98
|
+
}, [ spanBounds, columnWidth, gapPx, rowHeightPx ] );
|
|
99
|
+
}
|