@wordpress/grid 0.6.0 → 0.7.1-next.v.202609031004.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 +9 -9
- 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 +63 -0
- package/src/dashboard-grid/test/item-limits.jsdom.test.tsx +147 -0
- 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 +63 -0
- package/src/dashboard-lanes/test/item-limits.jsdom.test.tsx +140 -0
- package/src/dashboard-lanes/test/lane-placement.test.ts +1 -0
- 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 +104 -0
- package/src/shared/types.ts +35 -0
- package/src/shared/use-span-bounds.ts +99 -0
- /package/src/dashboard-grid/test/{keyboard-activation.test.tsx → keyboard-activation.jsdom.test.tsx} +0 -0
- /package/src/dashboard-lanes/test/{keyboard-activation.test.tsx → keyboard-activation.jsdom.test.tsx} +0 -0
- /package/src/dashboard-lanes/test/{use-lane-placement.test.tsx → use-lane-placement.jsdom.test.tsx} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.7.0-next.0 (2026-09-03)
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- Layout items accept `draggable` and `resizable` flags. A non-draggable
|
|
10
|
+
item is pinned: it cannot be dragged and holds its index while the
|
|
11
|
+
other items reorder; a non-resizable item keeps its size
|
|
12
|
+
([#81967](https://github.com/WordPress/gutenberg/pull/81967)).
|
|
13
|
+
- `DashboardGrid` and `DashboardLanes` accept `itemLimits`: per-item minimum and maximum tile sizes in pixels (`GridItemLimits`; width-only `GridItemWidthLimits` on lanes), enforced on rendered spans and resize gestures without being written into the layout ([#81899](https://github.com/WordPress/gutenberg/pull/81899)).
|
|
14
|
+
|
|
15
|
+
### Internal
|
|
16
|
+
|
|
17
|
+
- Remove unused dependency `@dnd-kit/utilities` ([#82103](https://github.com/WordPress/gutenberg/pull/82103)).
|
|
18
|
+
|
|
5
19
|
## 0.6.0 (2026-08-26)
|
|
6
20
|
|
|
7
21
|
### Internal
|
package/README.md
CHANGED
|
@@ -129,6 +129,8 @@ interface DashboardGridLayoutItem {
|
|
|
129
129
|
width?: number | 'fill' | 'full'; // column span (see below)
|
|
130
130
|
height?: number; // rows to span
|
|
131
131
|
order?: number; // lower values render first (responsive mode)
|
|
132
|
+
draggable?: boolean; // default true; false pins it: no drag, holds its index
|
|
133
|
+
resizable?: boolean; // default true: can be resized in edit mode
|
|
132
134
|
}
|
|
133
135
|
```
|
|
134
136
|
|
|
@@ -136,7 +138,7 @@ interface DashboardGridLayoutItem {
|
|
|
136
138
|
|
|
137
139
|
- `number`: span that many columns (clamped to the grid's column count).
|
|
138
140
|
- `'fill'`: fill the remaining columns in the current row.
|
|
139
|
-
- `'full'`: span every column
|
|
141
|
+
- `'full'`: span every column and force a row break; an `itemLimits` maximum caps the span.
|
|
140
142
|
|
|
141
143
|
`'fill'` is resolved per-row against the remaining free space.
|
|
142
144
|
|
|
@@ -149,6 +151,7 @@ interface DashboardGridLayoutItem {
|
|
|
149
151
|
| `columns` | `number` | `6` | Total columns (fixed mode). |
|
|
150
152
|
| `minColumnWidth` | `number` | — | If set, enables responsive mode: columns derived from container width. Mutually exclusive with `columns`. |
|
|
151
153
|
| `rowHeight` | `number \| 'auto'` | `'auto'` | Row height in pixels, or `'auto'` to let content size rows. |
|
|
154
|
+
| `itemLimits` | `Record< string, GridItemLimits >` | — | Per-item minimum and maximum tile sizes in pixels, keyed by layout item key. See [Size limits](#size-limits). |
|
|
152
155
|
| `editMode` | `boolean` | `false` | Enables drag-to-reorder and resize handles. |
|
|
153
156
|
| `onChangeLayout` | `( layout ) => void` | — | Fired when the user commits a drag or resize. |
|
|
154
157
|
| `onPreviewLayout` | `( layout ) => void` | — | Fired continuously during a drag or resize with the in-progress layout. Use for live feedback; `onChangeLayout` still emits the committed result. |
|
|
@@ -283,6 +286,8 @@ interface DashboardLanesLayoutItem {
|
|
|
283
286
|
width?: number; // lanes to span (default 1)
|
|
284
287
|
lane?: number; // 0-indexed: pin to a specific lane
|
|
285
288
|
order?: number; // lower values render first
|
|
289
|
+
draggable?: boolean; // default true; false pins it: no drag, holds its index
|
|
290
|
+
resizable?: boolean; // default true: can be resized in edit mode
|
|
286
291
|
}
|
|
287
292
|
```
|
|
288
293
|
|
|
@@ -310,6 +315,7 @@ items flow around them; out-of-range values (negative, or beyond
|
|
|
310
315
|
| `minColumnWidth` | `number` | — | If set, enables responsive mode: lane count derived from container width. Mutually exclusive with `columns`. |
|
|
311
316
|
| `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. |
|
|
312
317
|
| `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
|
+
| `itemLimits` | `Record< string, GridItemWidthLimits >` | — | Per-item minimum and maximum tile widths in pixels, keyed by layout item key. See [Size limits](#size-limits). |
|
|
313
319
|
| `editMode` | `boolean` | `false` | Enables drag-to-reorder and horizontal resize. |
|
|
314
320
|
| `onChangeLayout` | `( layout ) => void` | — | Fired when the user commits a drag or resize. |
|
|
315
321
|
| `onPreviewLayout` | `( layout ) => void` | — | Fired continuously during a drag or resize. |
|
|
@@ -375,6 +381,43 @@ preview update; the overhead is minor up to ~50 tiles and grows
|
|
|
375
381
|
from there. For `DashboardLanes`, placement runs in a
|
|
376
382
|
`useLayoutEffect` throttled to one frame per measurement burst.
|
|
377
383
|
|
|
384
|
+
### Size limits
|
|
385
|
+
|
|
386
|
+
`itemLimits` declares per-item floors and ceilings in pixels, keyed by
|
|
387
|
+
layout item key:
|
|
388
|
+
|
|
389
|
+
```jsx
|
|
390
|
+
<DashboardGrid
|
|
391
|
+
layout={ layout }
|
|
392
|
+
rowHeight={ 80 }
|
|
393
|
+
itemLimits={ {
|
|
394
|
+
chart: { minWidth: 320, minHeight: 200 },
|
|
395
|
+
note: { maxWidth: 500 },
|
|
396
|
+
} }
|
|
397
|
+
>
|
|
398
|
+
{ tiles }
|
|
399
|
+
</DashboardGrid>
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Each surface quantizes a limit to whole tracks of its current
|
|
403
|
+
geometry: minimums round up, maximums round down, and a quantized
|
|
404
|
+
minimum wins over a smaller quantized maximum. The result bounds the
|
|
405
|
+
rendered span and the resize gesture, so a resize never commits a
|
|
406
|
+
span outside it.
|
|
407
|
+
|
|
408
|
+
Limits are not written into the layout. A stored span outside the
|
|
409
|
+
limits renders bounded while the stored data stays untouched, so a
|
|
410
|
+
limit change applies to every existing layout. A resize commits the
|
|
411
|
+
resized tile at its new span and a reorder commits only the order;
|
|
412
|
+
every other tile keeps its stored span, even while it renders bounded.
|
|
413
|
+
|
|
414
|
+
`'full'` and `'fill'` widths respect a maximum: `'full'` renders at the
|
|
415
|
+
capped span and places like a fixed item of that width, and `'fill'`
|
|
416
|
+
reserves at least its minimum and never exceeds its maximum.
|
|
417
|
+
Height limits apply when `rowHeight` is numeric and stay open with
|
|
418
|
+
`'auto'` rows. `DashboardLanes` takes `GridItemWidthLimits`: lane
|
|
419
|
+
heights are content-driven.
|
|
420
|
+
|
|
378
421
|
### Accessibility
|
|
379
422
|
|
|
380
423
|
Drag-to-reorder is operable from the keyboard via `@dnd-kit`'s
|
|
@@ -152,6 +152,8 @@ function GridItem({
|
|
|
152
152
|
item,
|
|
153
153
|
maxColumns,
|
|
154
154
|
disabled = false,
|
|
155
|
+
draggable = true,
|
|
156
|
+
resizable = true,
|
|
155
157
|
verticalResizable = true,
|
|
156
158
|
interacting = false,
|
|
157
159
|
dragging = false,
|
|
@@ -162,6 +164,8 @@ function GridItem({
|
|
|
162
164
|
resizeSnapPreview = null,
|
|
163
165
|
minResizeWidthPx,
|
|
164
166
|
minResizeHeightPx,
|
|
167
|
+
maxResizeWidthPx,
|
|
168
|
+
maxResizeHeightPx,
|
|
165
169
|
renderResizeHandle
|
|
166
170
|
}) {
|
|
167
171
|
const [resizeDelta, setResizeDelta] = (0, import_element.useState)(
|
|
@@ -170,6 +174,8 @@ function GridItem({
|
|
|
170
174
|
const [initialContentSize, setInitialContentSize] = (0, import_element.useState)(null);
|
|
171
175
|
const itemRef = (0, import_element.useRef)(null);
|
|
172
176
|
const contentRef = (0, import_element.useRef)(null);
|
|
177
|
+
const dragDisabled = disabled || !draggable;
|
|
178
|
+
const resizeDisabled = disabled || !resizable;
|
|
173
179
|
const {
|
|
174
180
|
attributes,
|
|
175
181
|
listeners,
|
|
@@ -178,7 +184,7 @@ function GridItem({
|
|
|
178
184
|
isDragging
|
|
179
185
|
} = (0, import_sortable.useSortable)({
|
|
180
186
|
id: item.key,
|
|
181
|
-
disabled
|
|
187
|
+
disabled: dragDisabled
|
|
182
188
|
});
|
|
183
189
|
const mergedRef = (0, import_compose.useMergeRefs)([itemRef, setNodeRef]);
|
|
184
190
|
const contentMergedRef = (0, import_compose.useMergeRefs)([contentRef]);
|
|
@@ -208,10 +214,18 @@ function GridItem({
|
|
|
208
214
|
height: verticalResizable ? delta.height : 0
|
|
209
215
|
};
|
|
210
216
|
if (baselineSize) {
|
|
211
|
-
clamped = (0, import_resize_snap.clampResizeDelta)(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
clamped = (0, import_resize_snap.clampResizeDelta)(
|
|
218
|
+
clamped,
|
|
219
|
+
baselineSize,
|
|
220
|
+
{
|
|
221
|
+
width: minResizeWidthPx,
|
|
222
|
+
height: verticalResizable ? minResizeHeightPx : void 0
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
width: maxResizeWidthPx,
|
|
226
|
+
height: verticalResizable ? maxResizeHeightPx : void 0
|
|
227
|
+
}
|
|
228
|
+
);
|
|
215
229
|
}
|
|
216
230
|
setResizeDelta(clamped);
|
|
217
231
|
onResize(item.key, clamped);
|
|
@@ -257,7 +271,7 @@ function GridItem({
|
|
|
257
271
|
...listeners,
|
|
258
272
|
style: {
|
|
259
273
|
height: "100%",
|
|
260
|
-
cursor: getItemCursor(
|
|
274
|
+
cursor: getItemCursor(dragDisabled, interacting)
|
|
261
275
|
},
|
|
262
276
|
children: [
|
|
263
277
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
@@ -268,7 +282,7 @@ function GridItem({
|
|
|
268
282
|
style: continuousContentStyle,
|
|
269
283
|
children: [
|
|
270
284
|
children,
|
|
271
|
-
!
|
|
285
|
+
!resizeDisabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
272
286
|
import_resize_handle.default,
|
|
273
287
|
{
|
|
274
288
|
itemId: item.key,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dashboard-grid/grid-item.tsx", "../../../style-runtime/src/index.ts", "../../src/shared/actionable-area-slot.module.css", "../../src/dashboard-grid/grid-item.module.css"],
|
|
4
|
-
"sourcesContent": ["import { useSortable } from '@dnd-kit/sortable';\nimport clsx from 'clsx';\nimport { useState, useRef } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport actionableAreaStyles from '../shared/actionable-area-slot.module.css';\nimport { GRID_ITEM_DATA_KEY } from '../shared/grid-item-key';\nimport ResizeHandle from '../shared/resize-handle';\nimport { clampResizeDelta, type ResizeSnapSize } from '../shared/resize-snap';\nimport type { ResizeDelta } from '../shared/types';\nimport type { GridItemProps } from './types';\nimport styles from './grid-item.module.css';\n\nfunction getItemCursor(\n\tdisabled: boolean,\n\tinteracting: boolean\n): React.CSSProperties[ 'cursor' ] {\n\tif ( disabled ) {\n\t\treturn 'default';\n\t}\n\n\tif ( interacting ) {\n\t\treturn undefined;\n\t}\n\n\treturn 'grab';\n}\n\nexport function GridItem( {\n\titem,\n\tmaxColumns,\n\tdisabled = false,\n\tverticalResizable = true,\n\tinteracting = false,\n\tdragging = false,\n\tchildren,\n\tactionableArea = null,\n\tonResize,\n\tonResizeEnd,\n\tresizeSnapPreview = null,\n\tminResizeWidthPx,\n\tminResizeHeightPx,\n\trenderResizeHandle,\n}: GridItemProps ) {\n\tconst [ resizeDelta, setResizeDelta ] = useState< ResizeDelta | null >(\n\t\tnull\n\t);\n\tconst [ initialContentSize, setInitialContentSize ] = useState< {\n\t\twidth: number;\n\t\theight: number;\n\t} | null >( null );\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst contentRef = useRef< HTMLDivElement >( null );\n\tconst {\n\t\tattributes,\n\t\tlisteners,\n\t\tsetNodeRef,\n\t\tsetActivatorNodeRef,\n\t\tisDragging,\n\t} = useSortable( {\n\t\tid: item.key,\n\t\tdisabled,\n\t} );\n\tconst mergedRef = useMergeRefs( [ itemRef, setNodeRef ] );\n\tconst contentMergedRef = useMergeRefs( [ contentRef ] );\n\t/*\n\t * With `<DragOverlay>` handling the cursor-following clone, the\n\t * sortable item stays put in its grid cell and acts as a\n\t * placeholder. No `transform` is applied here — applying one\n\t * would double-move the placeholder alongside the overlay.\n\t */\n\tconst style = {\n\t\tgridColumnEnd: `span ${\n\t\t\titem.width === 'full'\n\t\t\t\t? maxColumns\n\t\t\t\t: Math.min(\n\t\t\t\t\t\ttypeof item.width === 'number' ? item.width : 1,\n\t\t\t\t\t\tmaxColumns\n\t\t\t\t )\n\t\t}`,\n\t\tgridRowEnd: `span ${ item.height || 1 }`,\n\t};\n\n\tconst isResizing = resizeDelta !== null;\n\tconst itemClassName = clsx(\n\t\tstyles.item,\n\t\tisDragging && styles[ 'is-dragging' ],\n\t\tisResizing && styles[ 'is-resizing' ]\n\t);\n\n\tconst handleResize = ( delta: ResizeDelta ) => {\n\t\tconst contentNode = contentRef.current;\n\t\tlet baselineSize = initialContentSize;\n\t\tif ( contentNode && ! baselineSize ) {\n\t\t\tconst { width, height } = contentNode.getBoundingClientRect();\n\t\t\tbaselineSize = { width, height };\n\t\t\tsetInitialContentSize( baselineSize );\n\t\t}\n\t\tlet clamped: ResizeDelta = {\n\t\t\twidth: delta.width,\n\t\t\theight: verticalResizable ? delta.height : 0,\n\t\t};\n\t\tif ( baselineSize ) {\n\t\t\tclamped = clampResizeDelta( clamped, baselineSize, {\n\t\t\t\twidth: minResizeWidthPx,\n\t\t\t\theight: verticalResizable ? minResizeHeightPx : undefined,\n\t\t\t} );\n\t\t}\n\t\tsetResizeDelta( clamped );\n\t\tonResize( item.key, clamped );\n\t};\n\n\tconst handleResizeEnd = () => {\n\t\tsetResizeDelta( null );\n\t\tsetInitialContentSize( null );\n\t\tonResizeEnd();\n\t};\n\n\tconst continuousContentStyle: React.CSSProperties | undefined =\n\t\tresizeDelta && initialContentSize\n\t\t\t? {\n\t\t\t\t\twidth: initialContentSize.width + resizeDelta.width,\n\t\t\t\t\theight: verticalResizable\n\t\t\t\t\t\t? initialContentSize.height + resizeDelta.height\n\t\t\t\t\t\t: undefined,\n\t\t\t }\n\t\t\t: undefined;\n\n\tconst previewOverlay = resizeSnapPreview ? (\n\t\t<SnapPreviewOverlay snap={ resizeSnapPreview } />\n\t) : null;\n\n\treturn (\n\t\t<div\n\t\t\tref={ mergedRef }\n\t\t\tclassName={ itemClassName }\n\t\t\tstyle={ style }\n\t\t\t{ ...{ [ GRID_ITEM_DATA_KEY ]: item.key } }\n\t\t\tdata-wp-grid-item-resizing={ isResizing || undefined }\n\t\t>\n\t\t\t{ actionableArea ? (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ actionableAreaStyles[ 'actionable-area-slot' ] }\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tstyle={ { display: 'contents' } }\n\t\t\t\t\t\t{ ...( dragging ? { inert: '' } : {} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ actionableArea }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null }\n\n\t\t\t<div\n\t\t\t\tref={ setActivatorNodeRef }\n\t\t\t\t{ ...attributes }\n\t\t\t\t{ ...listeners }\n\t\t\t\tstyle={ {\n\t\t\t\t\theight: '100%',\n\t\t\t\t\tcursor: getItemCursor( disabled, interacting ),\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={ contentMergedRef }\n\t\t\t\t\tclassName={ styles[ 'item-content' ] }\n\t\t\t\t\tstyle={ continuousContentStyle }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t\t{ ! disabled && (\n\t\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\t\titemId={ item.key }\n\t\t\t\t\t\t\tverticalResizable={ verticalResizable }\n\t\t\t\t\t\t\tonResize={ handleResize }\n\t\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\t\trenderResizeHandle={ renderResizeHandle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ previewOverlay }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction SnapPreviewOverlay( { snap }: { snap: ResizeSnapSize } ) {\n\treturn (\n\t\t<div\n\t\t\tclassName={ styles[ 'preview-overlay' ] }\n\t\t\tstyle={ {\n\t\t\t\twidth: snap.widthPx,\n\t\t\t\theight: snap.heightPx ?? '100%',\n\t\t\t} }\n\t\t/>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"ac1094954c\", \"._1c54fe8165d3023e__actionable-area-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._1c54fe8165d3023e__actionable-area-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-resizing] ._1c54fe8165d3023e__actionable-area-slot{opacity:0;pointer-events:none}\");\n}\nexport default {\"actionable-area-slot\":\"_1c54fe8165d3023e__actionable-area-slot\"};\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"62860ded21\", \"._5d1abcb332a18701__item{position:relative}._54de57c12d3ce67e__item-content{height:100%;position:relative}._3e086aa073b9bbd9__is-resizing{overflow:visible;z-index:1}._3e086aa073b9bbd9__is-resizing ._54de57c12d3ce67e__item-content{overflow:visible;position:relative;z-index:2}._81d4e1a6c979f1e4__is-dragging{pointer-events:none}[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{border-radius:var(--wp-grid-placeholder-radius,0)}@media not (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{animation:_0447be8a7068a873__wp-grid-item-placeholder-in 0ms linear var(--wpds-motion-duration-sm,.1s) forwards;opacity:1;outline-color:transparent;outline-style:var(--wp-grid-placeholder-outline-style,dashed);outline-width:0}@keyframes _0447be8a7068a873__wp-grid-item-placeholder-in{to{opacity:var(--wp-grid-placeholder-opacity,.4);outline-color:var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));outline-width:var(--wpds-border-width-sm,2px)}}}@media (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{opacity:var(--wp-grid-placeholder-opacity,.4);outline:var(--wpds-border-width-sm,2px) var(--wp-grid-placeholder-outline-style,dashed) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)))}}@media (forced-colors:active){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{--wp-grid-placeholder-outline-color:Highlight}}._2028fc095dbc5cb2__preview-overlay{background:transparent;border:var(--wpds-border-width-sm,2px) var(--wp-grid-resize-preview-outline-style,solid) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));border-radius:var(--wp-grid-placeholder-radius,0);box-sizing:border-box;inset-inline-start:0;pointer-events:none;position:absolute;top:0;z-index:0}@media (forced-colors:active){._2028fc095dbc5cb2__preview-overlay{border-color:Highlight}}\");\n}\nexport default {\"item\":\"_5d1abcb332a18701__item\",\"item-content\":\"_54de57c12d3ce67e__item-content\",\"is-resizing\":\"_3e086aa073b9bbd9__is-resizing\",\"is-dragging\":\"_81d4e1a6c979f1e4__is-dragging\",\"wp-grid-item-placeholder-in\":\"_0447be8a7068a873__wp-grid-item-placeholder-in\",\"preview-overlay\":\"_2028fc095dbc5cb2__preview-overlay\"};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAC5B,kBAAiB;AACjB,qBAAiC;AACjC,qBAA6B;;;ACO7B,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACrB,QAAM,cAAc;AAEpB,MAAK,YAAY,kBAAmB;AACnC,WAAO,YAAY;AAAA,EACpB;AAEA,cAAY,mBAAmB;AAAA,IAC9B,WAAW,oBAAI,IAAI;AAAA,IACnB,QAAQ,oBAAI,IAAI;AAAA,IAChB,gBAAgB,oBAAI,QAAQ;AAAA,EAC7B;AAEA,MAAK,OAAO,aAAa,aAAc;AACtC,qBAAkB,QAAS;AAAA,EAC5B;AAEA,SAAO,YAAY;AACpB;AAUA,SAAS,0BACR,gBACA,MACU;AACV,MAAK,CAAE,eAAe,MAAO;AAC5B,WAAO;AAAA,EACR;AAEA,aAAY,SAAS,eAAe,KAAK;AAAA,IACxC,SAAU,oBAAqB;AAAA,EAChC,GAAI;AACH,QAAK,MAAM,aAAc,oBAAqB,MAAM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Y,kBAAkB,QAAQ,UAAU,KAAK,GAAI;AACxD,gBAAa,gBAAgB,MAAM,GAAI;AAAA,EACxC;AACD;;;ACpKA,IAAI,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa,QAAQ;AACtE,gBAAc,cAAc,6VAA6V;AAC1X;AACA,IAAO,+BAAQ,EAAC,wBAAuB,0CAAyC;;;AFChF,2BAAmC;AACnC,2BAAyB;AACzB,yBAAsD;;;AGNtD,IAAI,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa,QAAQ;AACtE,gBAAc,cAAc,q/DAAq/D;AAClhE;AACA,IAAO,oBAAQ,EAAC,QAAO,2BAA0B,gBAAe,mCAAkC,eAAc,kCAAiC,eAAc,kCAAiC,+BAA8B,kDAAiD,mBAAkB,qCAAoC;;;
|
|
4
|
+
"sourcesContent": ["import { useSortable } from '@dnd-kit/sortable';\nimport clsx from 'clsx';\nimport { useState, useRef } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport actionableAreaStyles from '../shared/actionable-area-slot.module.css';\nimport { GRID_ITEM_DATA_KEY } from '../shared/grid-item-key';\nimport ResizeHandle from '../shared/resize-handle';\nimport { clampResizeDelta, type ResizeSnapSize } from '../shared/resize-snap';\nimport type { ResizeDelta } from '../shared/types';\nimport type { GridItemProps } from './types';\nimport styles from './grid-item.module.css';\n\nfunction getItemCursor(\n\tdisabled: boolean,\n\tinteracting: boolean\n): React.CSSProperties[ 'cursor' ] {\n\tif ( disabled ) {\n\t\treturn 'default';\n\t}\n\n\tif ( interacting ) {\n\t\treturn undefined;\n\t}\n\n\treturn 'grab';\n}\n\nexport function GridItem( {\n\titem,\n\tmaxColumns,\n\tdisabled = false,\n\tdraggable = true,\n\tresizable = true,\n\tverticalResizable = true,\n\tinteracting = false,\n\tdragging = false,\n\tchildren,\n\tactionableArea = null,\n\tonResize,\n\tonResizeEnd,\n\tresizeSnapPreview = null,\n\tminResizeWidthPx,\n\tminResizeHeightPx,\n\tmaxResizeWidthPx,\n\tmaxResizeHeightPx,\n\trenderResizeHandle,\n}: GridItemProps ) {\n\tconst [ resizeDelta, setResizeDelta ] = useState< ResizeDelta | null >(\n\t\tnull\n\t);\n\tconst [ initialContentSize, setInitialContentSize ] = useState< {\n\t\twidth: number;\n\t\theight: number;\n\t} | null >( null );\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst contentRef = useRef< HTMLDivElement >( null );\n\tconst dragDisabled = disabled || ! draggable;\n\tconst resizeDisabled = disabled || ! resizable;\n\tconst {\n\t\tattributes,\n\t\tlisteners,\n\t\tsetNodeRef,\n\t\tsetActivatorNodeRef,\n\t\tisDragging,\n\t} = useSortable( {\n\t\tid: item.key,\n\t\tdisabled: dragDisabled,\n\t} );\n\tconst mergedRef = useMergeRefs( [ itemRef, setNodeRef ] );\n\tconst contentMergedRef = useMergeRefs( [ contentRef ] );\n\t/*\n\t * With `<DragOverlay>` handling the cursor-following clone, the\n\t * sortable item stays put in its grid cell and acts as a\n\t * placeholder. No `transform` is applied here — applying one\n\t * would double-move the placeholder alongside the overlay.\n\t */\n\tconst style = {\n\t\tgridColumnEnd: `span ${\n\t\t\titem.width === 'full'\n\t\t\t\t? maxColumns\n\t\t\t\t: Math.min(\n\t\t\t\t\t\ttypeof item.width === 'number' ? item.width : 1,\n\t\t\t\t\t\tmaxColumns\n\t\t\t\t )\n\t\t}`,\n\t\tgridRowEnd: `span ${ item.height || 1 }`,\n\t};\n\n\tconst isResizing = resizeDelta !== null;\n\tconst itemClassName = clsx(\n\t\tstyles.item,\n\t\tisDragging && styles[ 'is-dragging' ],\n\t\tisResizing && styles[ 'is-resizing' ]\n\t);\n\n\tconst handleResize = ( delta: ResizeDelta ) => {\n\t\tconst contentNode = contentRef.current;\n\t\tlet baselineSize = initialContentSize;\n\t\tif ( contentNode && ! baselineSize ) {\n\t\t\tconst { width, height } = contentNode.getBoundingClientRect();\n\t\t\tbaselineSize = { width, height };\n\t\t\tsetInitialContentSize( baselineSize );\n\t\t}\n\t\tlet clamped: ResizeDelta = {\n\t\t\twidth: delta.width,\n\t\t\theight: verticalResizable ? delta.height : 0,\n\t\t};\n\t\tif ( baselineSize ) {\n\t\t\tclamped = clampResizeDelta(\n\t\t\t\tclamped,\n\t\t\t\tbaselineSize,\n\t\t\t\t{\n\t\t\t\t\twidth: minResizeWidthPx,\n\t\t\t\t\theight: verticalResizable ? minResizeHeightPx : undefined,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\twidth: maxResizeWidthPx,\n\t\t\t\t\theight: verticalResizable ? maxResizeHeightPx : undefined,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\tsetResizeDelta( clamped );\n\t\tonResize( item.key, clamped );\n\t};\n\n\tconst handleResizeEnd = () => {\n\t\tsetResizeDelta( null );\n\t\tsetInitialContentSize( null );\n\t\tonResizeEnd();\n\t};\n\n\tconst continuousContentStyle: React.CSSProperties | undefined =\n\t\tresizeDelta && initialContentSize\n\t\t\t? {\n\t\t\t\t\twidth: initialContentSize.width + resizeDelta.width,\n\t\t\t\t\theight: verticalResizable\n\t\t\t\t\t\t? initialContentSize.height + resizeDelta.height\n\t\t\t\t\t\t: undefined,\n\t\t\t }\n\t\t\t: undefined;\n\n\tconst previewOverlay = resizeSnapPreview ? (\n\t\t<SnapPreviewOverlay snap={ resizeSnapPreview } />\n\t) : null;\n\n\treturn (\n\t\t<div\n\t\t\tref={ mergedRef }\n\t\t\tclassName={ itemClassName }\n\t\t\tstyle={ style }\n\t\t\t{ ...{ [ GRID_ITEM_DATA_KEY ]: item.key } }\n\t\t\tdata-wp-grid-item-resizing={ isResizing || undefined }\n\t\t>\n\t\t\t{ actionableArea ? (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ actionableAreaStyles[ 'actionable-area-slot' ] }\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tstyle={ { display: 'contents' } }\n\t\t\t\t\t\t{ ...( dragging ? { inert: '' } : {} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ actionableArea }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null }\n\n\t\t\t<div\n\t\t\t\tref={ setActivatorNodeRef }\n\t\t\t\t{ ...attributes }\n\t\t\t\t{ ...listeners }\n\t\t\t\tstyle={ {\n\t\t\t\t\theight: '100%',\n\t\t\t\t\tcursor: getItemCursor( dragDisabled, interacting ),\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={ contentMergedRef }\n\t\t\t\t\tclassName={ styles[ 'item-content' ] }\n\t\t\t\t\tstyle={ continuousContentStyle }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t\t{ ! resizeDisabled && (\n\t\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\t\titemId={ item.key }\n\t\t\t\t\t\t\tverticalResizable={ verticalResizable }\n\t\t\t\t\t\t\tonResize={ handleResize }\n\t\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\t\trenderResizeHandle={ renderResizeHandle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ previewOverlay }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction SnapPreviewOverlay( { snap }: { snap: ResizeSnapSize } ) {\n\treturn (\n\t\t<div\n\t\t\tclassName={ styles[ 'preview-overlay' ] }\n\t\t\tstyle={ {\n\t\t\t\twidth: snap.widthPx,\n\t\t\t\theight: snap.heightPx ?? '100%',\n\t\t\t} }\n\t\t/>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"ac1094954c\", \"._1c54fe8165d3023e__actionable-area-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._1c54fe8165d3023e__actionable-area-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-resizing] ._1c54fe8165d3023e__actionable-area-slot{opacity:0;pointer-events:none}\");\n}\nexport default {\"actionable-area-slot\":\"_1c54fe8165d3023e__actionable-area-slot\"};\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"62860ded21\", \"._5d1abcb332a18701__item{position:relative}._54de57c12d3ce67e__item-content{height:100%;position:relative}._3e086aa073b9bbd9__is-resizing{overflow:visible;z-index:1}._3e086aa073b9bbd9__is-resizing ._54de57c12d3ce67e__item-content{overflow:visible;position:relative;z-index:2}._81d4e1a6c979f1e4__is-dragging{pointer-events:none}[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{border-radius:var(--wp-grid-placeholder-radius,0)}@media not (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{animation:_0447be8a7068a873__wp-grid-item-placeholder-in 0ms linear var(--wpds-motion-duration-sm,.1s) forwards;opacity:1;outline-color:transparent;outline-style:var(--wp-grid-placeholder-outline-style,dashed);outline-width:0}@keyframes _0447be8a7068a873__wp-grid-item-placeholder-in{to{opacity:var(--wp-grid-placeholder-opacity,.4);outline-color:var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));outline-width:var(--wpds-border-width-sm,2px)}}}@media (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{opacity:var(--wp-grid-placeholder-opacity,.4);outline:var(--wpds-border-width-sm,2px) var(--wp-grid-placeholder-outline-style,dashed) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)))}}@media (forced-colors:active){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{--wp-grid-placeholder-outline-color:Highlight}}._2028fc095dbc5cb2__preview-overlay{background:transparent;border:var(--wpds-border-width-sm,2px) var(--wp-grid-resize-preview-outline-style,solid) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));border-radius:var(--wp-grid-placeholder-radius,0);box-sizing:border-box;inset-inline-start:0;pointer-events:none;position:absolute;top:0;z-index:0}@media (forced-colors:active){._2028fc095dbc5cb2__preview-overlay{border-color:Highlight}}\");\n}\nexport default {\"item\":\"_5d1abcb332a18701__item\",\"item-content\":\"_54de57c12d3ce67e__item-content\",\"is-resizing\":\"_3e086aa073b9bbd9__is-resizing\",\"is-dragging\":\"_81d4e1a6c979f1e4__is-dragging\",\"wp-grid-item-placeholder-in\":\"_0447be8a7068a873__wp-grid-item-placeholder-in\",\"preview-overlay\":\"_2028fc095dbc5cb2__preview-overlay\"};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAC5B,kBAAiB;AACjB,qBAAiC;AACjC,qBAA6B;;;ACO7B,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACrB,QAAM,cAAc;AAEpB,MAAK,YAAY,kBAAmB;AACnC,WAAO,YAAY;AAAA,EACpB;AAEA,cAAY,mBAAmB;AAAA,IAC9B,WAAW,oBAAI,IAAI;AAAA,IACnB,QAAQ,oBAAI,IAAI;AAAA,IAChB,gBAAgB,oBAAI,QAAQ;AAAA,EAC7B;AAEA,MAAK,OAAO,aAAa,aAAc;AACtC,qBAAkB,QAAS;AAAA,EAC5B;AAEA,SAAO,YAAY;AACpB;AAUA,SAAS,0BACR,gBACA,MACU;AACV,MAAK,CAAE,eAAe,MAAO;AAC5B,WAAO;AAAA,EACR;AAEA,aAAY,SAAS,eAAe,KAAK;AAAA,IACxC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AAE,KAAK,GAA8B;AACjE,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAY,kBAAQ,iBAAkB;AAAA,MACtC,OAAQ;AAAA,QACP,OAAO,KAAK;AAAA,QACZ,QAAQ,KAAK,YAAY;AAAA,MAC1B;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["clsx", "ResizeHandle"]
|
|
7
7
|
}
|
|
@@ -39,8 +39,10 @@ var import_clsx = __toESM(require("clsx"));
|
|
|
39
39
|
var import_compose = require("@wordpress/compose");
|
|
40
40
|
var import_element = require("@wordpress/element");
|
|
41
41
|
var import_grid_item = require("./grid-item.cjs");
|
|
42
|
+
var import_array_move_with_pinned = require("../shared/array-move-with-pinned.cjs");
|
|
42
43
|
var import_grid_overlay = require("../shared/grid-overlay.cjs");
|
|
43
44
|
var import_resize_snap = require("../shared/resize-snap.cjs");
|
|
45
|
+
var import_use_span_bounds = require("../shared/use-span-bounds.cjs");
|
|
44
46
|
|
|
45
47
|
// packages/style-runtime/src/index.ts
|
|
46
48
|
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
@@ -162,6 +164,7 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
162
164
|
style,
|
|
163
165
|
rowHeight = "auto",
|
|
164
166
|
minColumnWidth,
|
|
167
|
+
itemLimits,
|
|
165
168
|
editMode = false,
|
|
166
169
|
onChangeLayout,
|
|
167
170
|
onPreviewLayout,
|
|
@@ -182,7 +185,6 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
182
185
|
const childrenCacheRef = (0, import_element.useRef)(
|
|
183
186
|
/* @__PURE__ */ new Map()
|
|
184
187
|
);
|
|
185
|
-
const activeLayout = temporaryLayout ?? layout;
|
|
186
188
|
const [gridRoot, setGridRoot] = (0, import_element.useState)(
|
|
187
189
|
null
|
|
188
190
|
);
|
|
@@ -239,6 +241,48 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
239
241
|
).widthPx;
|
|
240
242
|
const rowHeightPx = typeof rowHeight === "number" ? rowHeight : null;
|
|
241
243
|
const minResizeHeightPx = rowHeightPx === null ? void 0 : (0, import_resize_snap.gridSpanToPixelSize)(1, 1, columnWidth, gapPx, rowHeightPx).heightPx ?? void 0;
|
|
244
|
+
const spanBoundsByKey = (0, import_use_span_bounds.useSpanBounds)(
|
|
245
|
+
itemLimits,
|
|
246
|
+
columnWidth,
|
|
247
|
+
gapPx,
|
|
248
|
+
rowHeightPx,
|
|
249
|
+
effectiveColumns
|
|
250
|
+
);
|
|
251
|
+
const resizeLimitsByKey = (0, import_use_span_bounds.useResizePixelLimits)(
|
|
252
|
+
spanBoundsByKey,
|
|
253
|
+
columnWidth,
|
|
254
|
+
gapPx,
|
|
255
|
+
rowHeightPx
|
|
256
|
+
);
|
|
257
|
+
const sourceLayout = temporaryLayout ?? layout;
|
|
258
|
+
const activeLayout = (0, import_element.useMemo)(() => {
|
|
259
|
+
if (spanBoundsByKey.size === 0) {
|
|
260
|
+
return sourceLayout;
|
|
261
|
+
}
|
|
262
|
+
let changed = false;
|
|
263
|
+
const bounded = sourceLayout.map((item) => {
|
|
264
|
+
const bounds = spanBoundsByKey.get(item.key);
|
|
265
|
+
if (!bounds) {
|
|
266
|
+
return item;
|
|
267
|
+
}
|
|
268
|
+
const width = typeof item.width === "number" ? (0, import_resize_snap.clampSpan)(
|
|
269
|
+
item.width,
|
|
270
|
+
bounds.minWidth,
|
|
271
|
+
bounds.maxWidth
|
|
272
|
+
) : item.width;
|
|
273
|
+
const height = (0, import_resize_snap.clampSpan)(
|
|
274
|
+
item.height ?? 1,
|
|
275
|
+
bounds.minHeight,
|
|
276
|
+
bounds.maxHeight
|
|
277
|
+
);
|
|
278
|
+
if (width === item.width && height === (item.height ?? 1)) {
|
|
279
|
+
return item;
|
|
280
|
+
}
|
|
281
|
+
changed = true;
|
|
282
|
+
return { ...item, width, height };
|
|
283
|
+
});
|
|
284
|
+
return changed ? bounded : sourceLayout;
|
|
285
|
+
}, [sourceLayout, spanBoundsByKey]);
|
|
242
286
|
const layoutMap = (0, import_element.useMemo)(() => {
|
|
243
287
|
const map = /* @__PURE__ */ new Map();
|
|
244
288
|
activeLayout.forEach((item) => map.set(item.key, item));
|
|
@@ -259,7 +303,8 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
259
303
|
const fillWidths = (0, import_resolve_fill_widths.resolveFillWidths)(
|
|
260
304
|
items,
|
|
261
305
|
layoutMap,
|
|
262
|
-
effectiveColumns
|
|
306
|
+
effectiveColumns,
|
|
307
|
+
spanBoundsByKey
|
|
263
308
|
);
|
|
264
309
|
if (fillWidths.size === 0) {
|
|
265
310
|
return layoutMap;
|
|
@@ -273,7 +318,7 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
273
318
|
);
|
|
274
319
|
}
|
|
275
320
|
return map;
|
|
276
|
-
}, [items, layoutMap, effectiveColumns]);
|
|
321
|
+
}, [items, layoutMap, effectiveColumns, spanBoundsByKey]);
|
|
277
322
|
const [childrenMap, actionableAreaMap, remaining, renderedByKey] = (0, import_element.useMemo)(() => {
|
|
278
323
|
const childMap = /* @__PURE__ */ new Map();
|
|
279
324
|
const actionableMap = /* @__PURE__ */ new Map();
|
|
@@ -362,11 +407,21 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
362
407
|
if (newIndex === currentIndex) {
|
|
363
408
|
return;
|
|
364
409
|
}
|
|
365
|
-
const updatedItems = (0,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
410
|
+
const updatedItems = (0, import_array_move_with_pinned.arrayMoveWithPinned)(
|
|
411
|
+
items,
|
|
412
|
+
currentIndex,
|
|
413
|
+
newIndex,
|
|
414
|
+
(key) => layoutMap.get(key)?.draggable === false
|
|
415
|
+
);
|
|
416
|
+
if (updatedItems.every((key, index) => key === items[index])) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const updatedLayout = (latestLayoutRef.current ?? layout).map(
|
|
420
|
+
(item) => ({
|
|
421
|
+
...item,
|
|
422
|
+
order: updatedItems.indexOf(item.key)
|
|
423
|
+
})
|
|
424
|
+
);
|
|
370
425
|
lastReorderCursorRef.current = {
|
|
371
426
|
x: activeCenterX,
|
|
372
427
|
y: activeCenterY
|
|
@@ -400,14 +455,13 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
400
455
|
width: Math.round(delta.width / (columnWidth + gapPx)),
|
|
401
456
|
height: rowHeight === "auto" ? 0 : Math.round(delta.height / (rowHeight + gapPx))
|
|
402
457
|
};
|
|
458
|
+
const bounds = spanBoundsByKey.get(id);
|
|
403
459
|
if (!resizeBaselineRef.current) {
|
|
404
|
-
const baseItem =
|
|
405
|
-
(item) => item.key === id
|
|
406
|
-
);
|
|
460
|
+
const baseItem = layoutMap.get(id);
|
|
407
461
|
const resolvedItem = resolvedItemMap.get(id);
|
|
408
462
|
let baseWidth;
|
|
409
463
|
if (baseItem?.width === "full") {
|
|
410
|
-
baseWidth = effectiveColumns;
|
|
464
|
+
baseWidth = bounds?.maxWidth ?? effectiveColumns;
|
|
411
465
|
} else if (baseItem?.width === "fill") {
|
|
412
466
|
baseWidth = typeof resolvedItem?.width === "number" ? resolvedItem.width : 1;
|
|
413
467
|
} else {
|
|
@@ -419,16 +473,15 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
419
473
|
};
|
|
420
474
|
}
|
|
421
475
|
const baseline = resizeBaselineRef.current;
|
|
422
|
-
const newWidth =
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
effectiveColumns
|
|
427
|
-
)
|
|
476
|
+
const newWidth = (0, import_resize_snap.clampSpan)(
|
|
477
|
+
baseline.width + relativeDelta.width,
|
|
478
|
+
bounds?.minWidth ?? 1,
|
|
479
|
+
bounds?.maxWidth ?? effectiveColumns
|
|
428
480
|
);
|
|
429
|
-
const newHeight =
|
|
430
|
-
|
|
431
|
-
|
|
481
|
+
const newHeight = (0, import_resize_snap.clampSpan)(
|
|
482
|
+
baseline.height + relativeDelta.height,
|
|
483
|
+
bounds?.minHeight ?? 1,
|
|
484
|
+
bounds?.maxHeight ?? Infinity
|
|
432
485
|
);
|
|
433
486
|
setResizeSnapPreview({
|
|
434
487
|
id,
|
|
@@ -443,11 +496,11 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
443
496
|
const pendingItem = latestLayoutRef.current?.find(
|
|
444
497
|
(item) => item.key === id
|
|
445
498
|
);
|
|
446
|
-
const currentItem = pendingItem ??
|
|
499
|
+
const currentItem = pendingItem ?? layoutMap.get(id);
|
|
447
500
|
if (currentItem && currentItem.width === newWidth && (currentItem.height ?? 1) === newHeight) {
|
|
448
501
|
return;
|
|
449
502
|
}
|
|
450
|
-
const updatedLayout =
|
|
503
|
+
const updatedLayout = (latestLayoutRef.current ?? layout).map(
|
|
451
504
|
(item) => item.key === id ? { ...item, width: newWidth, height: newHeight } : item
|
|
452
505
|
);
|
|
453
506
|
latestLayoutRef.current = updatedLayout;
|
|
@@ -542,28 +595,37 @@ var DashboardGrid = (0, import_element.forwardRef)(
|
|
|
542
595
|
},
|
|
543
596
|
children: [
|
|
544
597
|
gridOverlay,
|
|
545
|
-
items.map((id) =>
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
598
|
+
items.map((id) => {
|
|
599
|
+
const limitsPx = resizeLimitsByKey.get(id);
|
|
600
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
601
|
+
import_grid_item.GridItem,
|
|
602
|
+
{
|
|
603
|
+
item: resolvedItemMap.get(
|
|
604
|
+
id
|
|
605
|
+
),
|
|
606
|
+
maxColumns: spanBoundsByKey.get(id)?.maxWidth ?? effectiveColumns,
|
|
607
|
+
disabled: !editMode,
|
|
608
|
+
draggable: layoutMap.get(id)?.draggable !== false,
|
|
609
|
+
resizable: layoutMap.get(id)?.resizable !== false,
|
|
610
|
+
verticalResizable: rowHeight !== "auto",
|
|
611
|
+
interacting: activeId !== null || isResizing,
|
|
612
|
+
dragging: activeId !== null,
|
|
613
|
+
onResize: handleResize,
|
|
614
|
+
onResizeEnd: persistTemporaryLayout,
|
|
615
|
+
resizeSnapPreview: resizeSnapPreview?.id === id ? resizeSnapPreview.snap : null,
|
|
616
|
+
minResizeWidthPx: limitsPx?.minWidthPx ?? minResizeWidthPx,
|
|
617
|
+
minResizeHeightPx: limitsPx?.minHeightPx ?? minResizeHeightPx,
|
|
618
|
+
maxResizeWidthPx: limitsPx?.maxWidthPx,
|
|
619
|
+
maxResizeHeightPx: limitsPx?.maxHeightPx ?? void 0,
|
|
620
|
+
actionableArea: actionableAreaMap.get(
|
|
621
|
+
id
|
|
622
|
+
),
|
|
623
|
+
renderResizeHandle,
|
|
624
|
+
children: childrenMap.get(id)
|
|
625
|
+
},
|
|
626
|
+
id
|
|
627
|
+
);
|
|
628
|
+
}),
|
|
567
629
|
remaining,
|
|
568
630
|
exitingItems.map(({ key, rect, child }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
569
631
|
import_item_exit_overlay.ItemExitOverlay,
|