@wordpress/grid 0.10.0 → 0.11.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 (114) hide show
  1. package/README.md +35 -14
  2. package/build/dashboard-grid/grid-item.cjs +232 -295
  3. package/build/dashboard-grid/grid-item.cjs.map +1 -7
  4. package/build/dashboard-grid/index.cjs +525 -632
  5. package/build/dashboard-grid/index.cjs.map +1 -7
  6. package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
  7. package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
  8. package/build/dashboard-grid/types.cjs +4 -18
  9. package/build/dashboard-lanes/index.cjs +494 -576
  10. package/build/dashboard-lanes/index.cjs.map +1 -7
  11. package/build/dashboard-lanes/lane-placement.cjs +77 -100
  12. package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
  13. package/build/dashboard-lanes/lanes-item.cjs +222 -278
  14. package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
  15. package/build/dashboard-lanes/types.cjs +4 -18
  16. package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
  17. package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
  18. package/build/index.cjs +16 -31
  19. package/build/shared/array-move-with-pinned.cjs +29 -45
  20. package/build/shared/array-move-with-pinned.cjs.map +1 -7
  21. package/build/shared/column-policy.cjs +58 -0
  22. package/build/shared/column-policy.cjs.map +1 -0
  23. package/build/shared/drag-overlay-drop-animation.cjs +40 -66
  24. package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
  25. package/build/shared/grid-item-key.cjs +12 -29
  26. package/build/shared/grid-item-key.cjs.map +1 -7
  27. package/build/shared/grid-overlay.cjs +163 -164
  28. package/build/shared/grid-overlay.cjs.map +1 -7
  29. package/build/shared/item-exit-overlay.cjs +132 -134
  30. package/build/shared/item-exit-overlay.cjs.map +1 -7
  31. package/build/shared/resize-handle.cjs +213 -197
  32. package/build/shared/resize-handle.cjs.map +1 -7
  33. package/build/shared/resize-snap.cjs +116 -121
  34. package/build/shared/resize-snap.cjs.map +1 -7
  35. package/build/shared/types.cjs +4 -18
  36. package/build/shared/use-item-exit-animation.cjs +96 -143
  37. package/build/shared/use-item-exit-animation.cjs.map +1 -7
  38. package/build/shared/use-layout-shift-animation.cjs +121 -150
  39. package/build/shared/use-layout-shift-animation.cjs.map +1 -7
  40. package/build/shared/use-span-bounds.cjs +65 -79
  41. package/build/shared/use-span-bounds.cjs.map +1 -7
  42. package/build-module/dashboard-grid/grid-item.mjs +209 -265
  43. package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
  44. package/build-module/dashboard-grid/index.mjs +502 -623
  45. package/build-module/dashboard-grid/index.mjs.map +1 -7
  46. package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
  47. package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
  48. package/build-module/dashboard-grid/types.mjs +0 -1
  49. package/build-module/dashboard-lanes/index.mjs +470 -567
  50. package/build-module/dashboard-lanes/index.mjs.map +1 -7
  51. package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
  52. package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
  53. package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
  54. package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
  55. package/build-module/dashboard-lanes/types.mjs +0 -1
  56. package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
  57. package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
  58. package/build-module/index.mjs +1 -6
  59. package/build-module/shared/array-move-with-pinned.mjs +25 -21
  60. package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
  61. package/build-module/shared/column-policy.mjs +52 -0
  62. package/build-module/shared/column-policy.mjs.map +1 -0
  63. package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
  64. package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
  65. package/build-module/shared/grid-item-key.mjs +8 -5
  66. package/build-module/shared/grid-item-key.mjs.map +1 -7
  67. package/build-module/shared/grid-overlay.mjs +143 -136
  68. package/build-module/shared/grid-overlay.mjs.map +1 -7
  69. package/build-module/shared/item-exit-overlay.mjs +128 -110
  70. package/build-module/shared/item-exit-overlay.mjs.map +1 -7
  71. package/build-module/shared/resize-handle.mjs +191 -171
  72. package/build-module/shared/resize-handle.mjs.map +1 -7
  73. package/build-module/shared/resize-snap.mjs +108 -93
  74. package/build-module/shared/resize-snap.mjs.map +1 -7
  75. package/build-module/shared/types.mjs +0 -1
  76. package/build-module/shared/use-item-exit-animation.mjs +92 -124
  77. package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
  78. package/build-module/shared/use-layout-shift-animation.mjs +114 -123
  79. package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
  80. package/build-module/shared/use-span-bounds.mjs +60 -57
  81. package/build-module/shared/use-span-bounds.mjs.map +1 -7
  82. package/build-types/dashboard-grid/index.d.ts.map +1 -1
  83. package/build-types/dashboard-grid/types.d.ts +9 -5
  84. package/build-types/dashboard-grid/types.d.ts.map +1 -1
  85. package/build-types/dashboard-lanes/index.d.ts.map +1 -1
  86. package/build-types/dashboard-lanes/types.d.ts +9 -5
  87. package/build-types/dashboard-lanes/types.d.ts.map +1 -1
  88. package/build-types/index.d.ts +1 -0
  89. package/build-types/index.d.ts.map +1 -1
  90. package/build-types/shared/column-policy.d.ts +43 -0
  91. package/build-types/shared/column-policy.d.ts.map +1 -0
  92. package/package.json +11 -11
  93. package/src/dashboard-grid/grid-item.tsx +1 -1
  94. package/src/dashboard-grid/index.tsx +11 -12
  95. package/src/dashboard-grid/stories/index.story.tsx +129 -50
  96. package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
  97. package/src/dashboard-grid/types.ts +9 -5
  98. package/src/dashboard-lanes/index.tsx +11 -11
  99. package/src/dashboard-lanes/lanes-item.tsx +1 -1
  100. package/src/dashboard-lanes/stories/index.story.tsx +124 -28
  101. package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
  102. package/src/dashboard-lanes/types.ts +9 -5
  103. package/src/index.ts +1 -0
  104. package/src/shared/column-policy.ts +100 -0
  105. package/src/shared/test/column-policy.test.ts +215 -0
  106. package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
  107. package/build/dashboard-grid/types.cjs.map +0 -7
  108. package/build/dashboard-lanes/types.cjs.map +0 -7
  109. package/build/index.cjs.map +0 -7
  110. package/build/shared/types.cjs.map +0 -7
  111. package/build-module/dashboard-grid/types.mjs.map +0 -7
  112. package/build-module/dashboard-lanes/types.mjs.map +0 -7
  113. package/build-module/index.mjs.map +0 -7
  114. package/build-module/shared/types.mjs.map +0 -7
package/README.md CHANGED
@@ -148,8 +148,8 @@ interface DashboardGridLayoutItem {
148
148
  | -------------------- | ------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
149
149
  | `layout` | `DashboardGridLayoutItem[]` | — | Required. Positions and sizes keyed by child `key`. |
150
150
  | `children` | `ReactNode` | — | Required. Each child needs a `key` matching a layout entry. |
151
- | `columns` | `number` | `6` | Total columns (fixed mode). |
152
- | `minColumnWidth` | `number` | — | If set, enables responsive mode: columns derived from container width. Mutually exclusive with `columns`. |
151
+ | `columns` | `number \| ColumnSteps` | `6` | Column count, or a count per container width (`{ 0: 1, 600: 2, 960: 4 }`; a step can be `'auto'`). Caps the count when `minColumnWidth` is set. See [Columns](#columns). |
152
+ | `minColumnWidth` | `number` | — | Per-column floor in pixels: the count drops on narrow containers so no column is narrower, down to one. Alone, as many columns as fit. |
153
153
  | `rowHeight` | `number \| 'auto'` | `'auto'` | Row height in pixels, or `'auto'` to let content size rows. |
154
154
  | `itemLimits` | `Record< string, GridItemLimits >` | — | Per-item minimum and maximum tile sizes in pixels, keyed by layout item key. See [Size limits](#size-limits). |
155
155
  | `editMode` | `boolean` | `false` | Enables drag-to-reorder and resize handles. |
@@ -179,9 +179,11 @@ while edit mode is on:
179
179
  | ---------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
180
180
  | `actionableArea` | `ReactNode` | Content rendered above the draggable surface of the grid item. Useful for close buttons, menus, or links that must stay clickable in edit mode. |
181
181
 
182
- ### Modes
182
+ ### Columns
183
183
 
184
- #### Fixed columns
184
+ `columns` and `minColumnWidth` compose. Both surfaces measure their own width with a `ResizeObserver` and resolve the count from it.
185
+
186
+ A number renders that many columns at every width:
185
187
 
186
188
  ```jsx
187
189
  <DashboardGrid layout={ layout } columns={ 12 }>
@@ -189,20 +191,39 @@ while edit mode is on:
189
191
  </DashboardGrid>
190
192
  ```
191
193
 
192
- #### Responsive
194
+ A `ColumnSteps` map renders a count from each container width up: one column from 0px, two from 600px, four from 960px.
193
195
 
194
- Columns are computed from container width using `minColumnWidth` as
195
- the lower bound per column. A `ResizeObserver` recomputes on
196
- container resize.
196
+ ```jsx
197
+ <DashboardGrid layout={ layout } columns={ { 0: 1, 600: 2, 960: 4 } }>
198
+ { children }
199
+ </DashboardGrid>
200
+ ```
201
+
202
+ Below the smallest key, that step's count applies, so a map that starts at `0` states every width.
203
+
204
+ `minColumnWidth` is a per-column floor in pixels. Alone, the surface fits as many columns of at least that width as the container allows. With `columns`, the count is capped by the number or the step, and lowered whenever a column would end up narrower than the floor.
197
205
 
198
206
  ```jsx
199
- <DashboardGrid layout={ layout } minColumnWidth={ 240 }>
207
+ <DashboardGrid layout={ layout } columns={ 4 } minColumnWidth={ 240 }>
200
208
  { children }
201
209
  </DashboardGrid>
202
210
  ```
203
211
 
204
- In responsive mode, layout items can provide an `order` to control
205
- display order independently of array position.
212
+ A step can be `'auto'`: from that width up there is no cap, and the floor alone decides the count. Below it the steps still fix the count. Without a floor, an `'auto'` step is skipped and the count below it holds.
213
+
214
+ ```jsx
215
+ <DashboardGrid
216
+ layout={ layout }
217
+ columns={ { 0: 1, 600: 2, 960: 'auto' } }
218
+ minColumnWidth={ 240 }
219
+ >
220
+ { children }
221
+ </DashboardGrid>
222
+ ```
223
+
224
+ A count is rounded down and never below one. A count that is not a finite number, or a step that is neither a count nor `'auto'`, is ignored.
225
+
226
+ Layout items can provide an `order` to control display order independently of array position.
206
227
 
207
228
  #### Edit mode
208
229
 
@@ -311,8 +332,8 @@ items flow around them; out-of-range values (negative, or beyond
311
332
  | -------------------- | ------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
312
333
  | `layout` | `DashboardLanesLayoutItem[]` | — | Required. Span and order keyed by child `key`. |
313
334
  | `children` | `ReactNode` | — | Required. Each child needs a `key` matching a layout entry. |
314
- | `columns` | `number` | `6` | Total lanes (fixed mode). |
315
- | `minColumnWidth` | `number` | — | If set, enables responsive mode: lane count derived from container width. Mutually exclusive with `columns`. |
335
+ | `columns` | `number \| ColumnSteps` | `6` | Lane count, or a count per container width (`{ 0: 1, 600: 2, 960: 4 }`; a step can be `'auto'`). Caps the count when `minColumnWidth` is set. See [Columns](#columns). |
336
+ | `minColumnWidth` | `number` | — | Per-lane floor in pixels: the count drops on narrow containers so no lane is narrower, down to one. Alone, as many lanes as fit. |
316
337
  | `flowTolerance` | `number` | `16` | Pixel tolerance for source-order tiebreaking when two candidate lanes have similar baselines. Larger values keep tiles closer to reading order at the cost of bigger empty regions. |
317
338
  | `rowUnit` | `number` | `4` | Snap unit for the polyfill's `grid-row-start` math. Smaller values produce sharper placement at the cost of a larger implicit row count. Ignored on browsers with native `display: grid-lanes` support. |
318
339
  | `itemLimits` | `Record< string, GridItemWidthLimits >` | — | Per-item minimum and maximum tile widths in pixels, keyed by layout item key. See [Size limits](#size-limits). |
@@ -423,7 +444,7 @@ heights are content-driven.
423
444
  Drag-to-reorder is operable from the keyboard via `@dnd-kit`'s
424
445
  keyboard sensor:
425
446
 
426
- - `Tab` to focus a tile.
447
+ - In edit mode, `Tab` to focus a draggable tile.
427
448
  - `Space` to pick it up.
428
449
  - Arrow keys to move it between positions.
429
450
  - `Space` to drop, or `Escape` to cancel.