@wordpress/grid 0.10.0 → 0.12.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/README.md +35 -14
- package/build/dashboard-grid/grid-item.cjs +232 -295
- package/build/dashboard-grid/grid-item.cjs.map +1 -7
- package/build/dashboard-grid/index.cjs +526 -633
- package/build/dashboard-grid/index.cjs.map +1 -7
- package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
- package/build/dashboard-grid/types.cjs +4 -18
- package/build/dashboard-lanes/index.cjs +495 -577
- package/build/dashboard-lanes/index.cjs.map +1 -7
- package/build/dashboard-lanes/lane-placement.cjs +77 -100
- package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
- package/build/dashboard-lanes/lanes-item.cjs +222 -278
- package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
- package/build/dashboard-lanes/types.cjs +4 -18
- package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
- package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
- package/build/index.cjs +16 -31
- package/build/shared/array-move-with-pinned.cjs +29 -45
- package/build/shared/array-move-with-pinned.cjs.map +1 -7
- package/build/shared/column-policy.cjs +58 -0
- package/build/shared/column-policy.cjs.map +1 -0
- package/build/shared/drag-overlay-drop-animation.cjs +40 -66
- package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
- package/build/shared/grid-item-key.cjs +12 -29
- package/build/shared/grid-item-key.cjs.map +1 -7
- package/build/shared/grid-overlay.cjs +163 -164
- package/build/shared/grid-overlay.cjs.map +1 -7
- package/build/shared/item-exit-overlay.cjs +132 -134
- package/build/shared/item-exit-overlay.cjs.map +1 -7
- package/build/shared/resize-handle.cjs +213 -197
- package/build/shared/resize-handle.cjs.map +1 -7
- package/build/shared/resize-snap.cjs +116 -121
- package/build/shared/resize-snap.cjs.map +1 -7
- package/build/shared/types.cjs +4 -18
- package/build/shared/use-item-exit-animation.cjs +96 -143
- package/build/shared/use-item-exit-animation.cjs.map +1 -7
- package/build/shared/use-layout-shift-animation.cjs +121 -150
- package/build/shared/use-layout-shift-animation.cjs.map +1 -7
- package/build/shared/use-span-bounds.cjs +65 -79
- package/build/shared/use-span-bounds.cjs.map +1 -7
- package/build-module/dashboard-grid/grid-item.mjs +209 -265
- package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
- package/build-module/dashboard-grid/index.mjs +502 -623
- package/build-module/dashboard-grid/index.mjs.map +1 -7
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
- package/build-module/dashboard-grid/types.mjs +0 -1
- package/build-module/dashboard-lanes/index.mjs +470 -567
- package/build-module/dashboard-lanes/index.mjs.map +1 -7
- package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
- package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
- package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
- package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
- package/build-module/dashboard-lanes/types.mjs +0 -1
- package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
- package/build-module/index.mjs +1 -6
- package/build-module/shared/array-move-with-pinned.mjs +25 -21
- package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
- package/build-module/shared/column-policy.mjs +52 -0
- package/build-module/shared/column-policy.mjs.map +1 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
- package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
- package/build-module/shared/grid-item-key.mjs +8 -5
- package/build-module/shared/grid-item-key.mjs.map +1 -7
- package/build-module/shared/grid-overlay.mjs +143 -136
- package/build-module/shared/grid-overlay.mjs.map +1 -7
- package/build-module/shared/item-exit-overlay.mjs +128 -110
- package/build-module/shared/item-exit-overlay.mjs.map +1 -7
- package/build-module/shared/resize-handle.mjs +191 -171
- package/build-module/shared/resize-handle.mjs.map +1 -7
- package/build-module/shared/resize-snap.mjs +108 -93
- package/build-module/shared/resize-snap.mjs.map +1 -7
- package/build-module/shared/types.mjs +0 -1
- package/build-module/shared/use-item-exit-animation.mjs +92 -124
- package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
- package/build-module/shared/use-layout-shift-animation.mjs +114 -123
- package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
- package/build-module/shared/use-span-bounds.mjs +60 -57
- package/build-module/shared/use-span-bounds.mjs.map +1 -7
- package/build-types/dashboard-grid/index.d.ts.map +1 -1
- package/build-types/dashboard-grid/types.d.ts +9 -5
- 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/types.d.ts +9 -5
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/shared/column-policy.d.ts +43 -0
- package/build-types/shared/column-policy.d.ts.map +1 -0
- package/package.json +14 -12
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/{grid.module.css → grid.module.scss} +10 -19
- package/src/dashboard-grid/index.tsx +12 -13
- package/src/dashboard-grid/stories/index.story.tsx +129 -50
- package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-grid/types.ts +9 -5
- package/src/dashboard-lanes/index.tsx +13 -13
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- package/src/dashboard-lanes/{lanes.module.css → lanes.module.scss} +10 -19
- package/src/dashboard-lanes/stories/index.story.tsx +124 -28
- package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-lanes/types.ts +9 -5
- package/src/index.ts +1 -0
- package/src/shared/column-policy.ts +100 -0
- package/src/shared/test/column-policy.test.ts +215 -0
- package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
- package/build/dashboard-grid/types.cjs.map +0 -7
- package/build/dashboard-lanes/types.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/shared/types.cjs.map +0 -7
- package/build-module/dashboard-grid/types.mjs.map +0 -7
- package/build-module/dashboard-lanes/types.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/shared/types.mjs.map +0 -7
|
@@ -1,588 +1,491 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
DndContext,
|
|
4
|
-
DragOverlay,
|
|
5
|
-
KeyboardSensor,
|
|
6
|
-
PointerSensor,
|
|
7
|
-
useSensor,
|
|
8
|
-
useSensors
|
|
9
|
-
} from "@dnd-kit/core";
|
|
10
|
-
import {
|
|
11
|
-
SortableContext,
|
|
12
|
-
sortableKeyboardCoordinates
|
|
13
|
-
} from "@dnd-kit/sortable";
|
|
1
|
+
import { DndContext, DragOverlay, KeyboardSensor, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
|
|
2
|
+
import { SortableContext, sortableKeyboardCoordinates } from "@dnd-kit/sortable";
|
|
14
3
|
import clsx from "clsx";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
forwardRef,
|
|
18
|
-
useMemo,
|
|
19
|
-
Children,
|
|
20
|
-
cloneElement,
|
|
21
|
-
isValidElement,
|
|
22
|
-
useLayoutEffect,
|
|
23
|
-
useRef,
|
|
24
|
-
useState
|
|
25
|
-
} from "@wordpress/element";
|
|
4
|
+
import { useEvent, useMergeRefs, useResizeObserver } from "@wordpress/compose";
|
|
5
|
+
import { Children, cloneElement, forwardRef, isValidElement, useLayoutEffect, useMemo, useRef, useState } from "@wordpress/element";
|
|
26
6
|
import { LanesItem } from "./lanes-item.mjs";
|
|
27
7
|
import { useLanePlacement } from "./use-lane-placement.mjs";
|
|
28
8
|
import { arrayMoveWithPinned } from "../shared/array-move-with-pinned.mjs";
|
|
9
|
+
import { resolveColumnCount } from "../shared/column-policy.mjs";
|
|
29
10
|
import { GridOverlay } from "../shared/grid-overlay.mjs";
|
|
30
11
|
import { clampSpan, gridSpanToPixelSize } from "../shared/resize-snap.mjs";
|
|
31
12
|
import { useResizePixelLimits, useSpanBounds } from "../shared/use-span-bounds.mjs";
|
|
32
|
-
|
|
13
|
+
import { ItemExitOverlay } from "../shared/item-exit-overlay.mjs";
|
|
14
|
+
import { getLayoutFingerprint, getPlacementFingerprint, useLayoutShiftAnimation } from "../shared/use-layout-shift-animation.mjs";
|
|
15
|
+
import { useItemExitAnimation } from "../shared/use-item-exit-animation.mjs";
|
|
16
|
+
import { createDashboardDragDropAnimation } from "../shared/drag-overlay-drop-animation.mjs";
|
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
33
18
|
// packages/style-runtime/src/index.ts
|
|
34
|
-
|
|
19
|
+
const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
20
|
+
/**
|
|
21
|
+
* Returns the shared style runtime registry.
|
|
22
|
+
*
|
|
23
|
+
* The registry is stored on `globalThis` so separately bundled copies of this
|
|
24
|
+
* package can coordinate through the same document and style maps.
|
|
25
|
+
*
|
|
26
|
+
* @return The shared runtime registry.
|
|
27
|
+
*/
|
|
35
28
|
function getRuntime() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof document !== "undefined") {
|
|
46
|
-
registerDocument(document);
|
|
47
|
-
}
|
|
48
|
-
return globalScope.__wpStyleRuntime;
|
|
29
|
+
const globalScope = globalThis;
|
|
30
|
+
if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
|
|
31
|
+
globalScope.__wpStyleRuntime = {
|
|
32
|
+
documents: /* @__PURE__ */ new Map(),
|
|
33
|
+
styles: /* @__PURE__ */ new Map(),
|
|
34
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
35
|
+
};
|
|
36
|
+
if (typeof document !== "undefined") registerDocument(document);
|
|
37
|
+
return globalScope.__wpStyleRuntime;
|
|
49
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks whether a document already contains a style tag for a hash.
|
|
41
|
+
*
|
|
42
|
+
* @param targetDocument Document to inspect.
|
|
43
|
+
* @param hash Stable hash for the transformed CSS.
|
|
44
|
+
*
|
|
45
|
+
* @return Whether the style hash already exists in the document.
|
|
46
|
+
*/
|
|
50
47
|
function documentContainsStyleHash(targetDocument, hash) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (const style of targetDocument.head.querySelectorAll(
|
|
55
|
-
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
56
|
-
)) {
|
|
57
|
-
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
48
|
+
if (!targetDocument.head) return false;
|
|
49
|
+
for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
|
|
50
|
+
return false;
|
|
62
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Injects a registered style into a document, unless that document already
|
|
54
|
+
* contains a style tag for the same hash.
|
|
55
|
+
*
|
|
56
|
+
* @param targetDocument Document to inject the style into.
|
|
57
|
+
* @param hash Stable hash for the transformed CSS.
|
|
58
|
+
* @param css CSS text to inject.
|
|
59
|
+
*/
|
|
63
60
|
function injectStyle(targetDocument, hash, css) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
82
|
-
style.appendChild(targetDocument.createTextNode(css));
|
|
83
|
-
targetDocument.head.appendChild(style);
|
|
84
|
-
injectedStyles.add(hash);
|
|
61
|
+
if (!targetDocument.head) return;
|
|
62
|
+
const runtime = getRuntime();
|
|
63
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
64
|
+
if (!injectedStyles) {
|
|
65
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
66
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
67
|
+
}
|
|
68
|
+
if (injectedStyles.has(hash)) return;
|
|
69
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
70
|
+
injectedStyles.add(hash);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const style = targetDocument.createElement("style");
|
|
74
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
75
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
76
|
+
targetDocument.head.appendChild(style);
|
|
77
|
+
injectedStyles.add(hash);
|
|
85
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Registers a document as a style injection target.
|
|
81
|
+
*
|
|
82
|
+
* Existing registered styles are replayed into the document immediately.
|
|
83
|
+
* Documents are reference-counted so multiple providers can safely register the
|
|
84
|
+
* same document without one cleanup removing it while another registration is
|
|
85
|
+
* still active.
|
|
86
|
+
*
|
|
87
|
+
* @param targetDocument Document to receive registered styles.
|
|
88
|
+
* @return Cleanup function that unregisters this document registration.
|
|
89
|
+
*/
|
|
86
90
|
function registerDocument(targetDocument) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (count <= 1) {
|
|
101
|
-
runtime.documents.delete(targetDocument);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
runtime.documents.set(targetDocument, count - 1);
|
|
105
|
-
};
|
|
91
|
+
const runtime = getRuntime();
|
|
92
|
+
runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
|
|
93
|
+
for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
|
|
94
|
+
return () => {
|
|
95
|
+
const count = runtime.documents.get(targetDocument);
|
|
96
|
+
if (count === void 0) return;
|
|
97
|
+
if (count <= 1) {
|
|
98
|
+
runtime.documents.delete(targetDocument);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
102
|
+
};
|
|
106
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Registers a style and injects it into all registered documents.
|
|
106
|
+
*
|
|
107
|
+
* The hash is used as the deduplication key, so calling this repeatedly with
|
|
108
|
+
* the same hash will not add duplicate style tags to a document.
|
|
109
|
+
* Registered styles are retained for the lifetime of the page so they can be
|
|
110
|
+
* replayed into documents that are registered later.
|
|
111
|
+
*
|
|
112
|
+
* @param hash Stable hash for the transformed CSS.
|
|
113
|
+
* @param css CSS text to inject.
|
|
114
|
+
*/
|
|
107
115
|
function registerStyle(hash, css) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
injectStyle(targetDocument, hash, css);
|
|
112
|
-
}
|
|
116
|
+
const runtime = getRuntime();
|
|
117
|
+
runtime.styles.set(hash, css);
|
|
118
|
+
for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
|
|
113
119
|
}
|
|
114
|
-
|
|
115
120
|
// packages/grid/src/shared/layout-shift-animation.module.css
|
|
116
|
-
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("5d10111ab0", ".c68bb75eb6bf717a__layout-animating [data-wp-grid-item-key]{transition:transform var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1))}@media (prefers-reduced-motion:reduce){.c68bb75eb6bf717a__layout-animating [data-wp-grid-item-key]{transition:none}}");
|
|
122
|
+
var layout_shift_animation_module_default = { "layout-animating": "c68bb75eb6bf717a__layout-animating" };
|
|
123
|
+
// packages/grid/src/dashboard-lanes/lanes.module.scss
|
|
124
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("25b095c2e7", "._23779dfdf51c5e50__lanes{column-gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));display:grid-lanes;position:relative;row-gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px))}@supports not (display:grid-lanes){._23779dfdf51c5e50__lanes{display:grid;grid-auto-flow:dense;grid-auto-rows:var(--wp-grid-lane-row-unit,4px);row-gap:0}}.d7e03cc9b910fc7e__drag-preview-frame{border-radius:var(--wp-grid-drag-preview-radius,0);box-shadow:0 2px 3px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.04),0 12px 12px rgba(0,0,0,.03),0 16px 16px rgba(0,0,0,.02);cursor:grabbing;height:100%;pointer-events:none}._4425b9a6fa30579d__drag-preview-frame__lift{height:100%;transform:scale(var(--wp-grid-drag-preview-scale,1.05));transform-origin:center}@media not (prefers-reduced-motion:reduce){.d7e03cc9b910fc7e__drag-preview-frame{animation:ff9e5dccc1f34f49__wp-grid-drag-preview-shadow-enter var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) both}._4425b9a6fa30579d__drag-preview-frame__lift{animation:_2592bed08e4f30e4__wp-grid-drag-preview-scale-enter var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) both}}@media not (prefers-reduced-motion:reduce){@keyframes ff9e5dccc1f34f49__wp-grid-drag-preview-shadow-enter{0%{box-shadow:0 1px 1px rgba(0,0,0,.03),0 1px 2px rgba(0,0,0,.02),0 3px 3px rgba(0,0,0,.02),0 4px 4px rgba(0,0,0,.01)}to{box-shadow:0 2px 3px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.04),0 12px 12px rgba(0,0,0,.03),0 16px 16px rgba(0,0,0,.02)}}@keyframes _2592bed08e4f30e4__wp-grid-drag-preview-scale-enter{0%{transform:scale(1)}to{transform:scale(var(--wp-grid-drag-preview-scale,1.05))}}}@media not (prefers-reduced-motion:reduce){.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting{animation:_4eb7799009ff2eea__wp-grid-drag-preview-shadow-exit var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting ._4425b9a6fa30579d__drag-preview-frame__lift{animation:_58b3144e745d3a6e__wp-grid-drag-preview-scale-exit var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}@keyframes _4eb7799009ff2eea__wp-grid-drag-preview-shadow-exit{0%{box-shadow:0 2px 3px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.04),0 12px 12px rgba(0,0,0,.03),0 16px 16px rgba(0,0,0,.02)}to{box-shadow:0 1px 1px rgba(0,0,0,.03),0 1px 2px rgba(0,0,0,.02),0 3px 3px rgba(0,0,0,.02),0 4px 4px rgba(0,0,0,.01)}}@keyframes _58b3144e745d3a6e__wp-grid-drag-preview-scale-exit{0%{transform:scale(var(--wp-grid-drag-preview-scale,1.05))}to{transform:scale(1)}}}.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting{box-shadow:0 1px 1px rgba(0,0,0,.03),0 1px 2px rgba(0,0,0,.02),0 3px 3px rgba(0,0,0,.02),0 4px 4px rgba(0,0,0,.01)}.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting ._4425b9a6fa30579d__drag-preview-frame__lift{transform:scale(1)}@media (prefers-reduced-motion:reduce){.d7e03cc9b910fc7e__drag-preview-frame{box-shadow:0 2px 3px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.04),0 12px 12px rgba(0,0,0,.03),0 16px 16px rgba(0,0,0,.02)}._4425b9a6fa30579d__drag-preview-frame__lift{transform:none}.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting{box-shadow:0 1px 1px rgba(0,0,0,.03),0 1px 2px rgba(0,0,0,.02),0 3px 3px rgba(0,0,0,.02),0 4px 4px rgba(0,0,0,.01);transition:none}.d7e03cc9b910fc7e__drag-preview-frame._6348e3778fd237bf__is-exiting ._4425b9a6fa30579d__drag-preview-frame__lift{transition:none}}");
|
|
125
|
+
var lanes_module_default = {
|
|
126
|
+
"lanes": "_23779dfdf51c5e50__lanes",
|
|
127
|
+
"drag-preview-frame": "d7e03cc9b910fc7e__drag-preview-frame",
|
|
128
|
+
"drag-preview-frame__lift": "_4425b9a6fa30579d__drag-preview-frame__lift",
|
|
129
|
+
"wp-grid-drag-preview-shadow-enter": "ff9e5dccc1f34f49__wp-grid-drag-preview-shadow-enter",
|
|
130
|
+
"wp-grid-drag-preview-scale-enter": "_2592bed08e4f30e4__wp-grid-drag-preview-scale-enter",
|
|
131
|
+
"is-exiting": "_6348e3778fd237bf__is-exiting",
|
|
132
|
+
"wp-grid-drag-preview-shadow-exit": "_4eb7799009ff2eea__wp-grid-drag-preview-shadow-exit",
|
|
133
|
+
"wp-grid-drag-preview-scale-exit": "_58b3144e745d3a6e__wp-grid-drag-preview-scale-exit"
|
|
134
|
+
};
|
|
121
135
|
// packages/grid/src/dashboard-lanes/index.tsx
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
136
|
+
const dashboardDragDropAnimation = createDashboardDragDropAnimation(lanes_module_default["drag-preview-frame"], lanes_module_default["is-exiting"]);
|
|
137
|
+
const FALLBACK_GAP_PX = 24;
|
|
138
|
+
const DEFAULT_COLUMNS = 6;
|
|
139
|
+
const NO_SORT_STRATEGY = () => null;
|
|
140
|
+
/**
|
|
141
|
+
* Masonry-style surface aligned with `display: grid-lanes`. Items
|
|
142
|
+
* declare a column span; heights are driven by content; placement
|
|
143
|
+
* follows the source-ordered, shortest-lane algorithm with
|
|
144
|
+
* `flow-tolerance` tiebreaking.
|
|
145
|
+
*
|
|
146
|
+
* On browsers that support `display: grid-lanes` natively, the
|
|
147
|
+
* component emits the spec's CSS and lets the engine handle layout.
|
|
148
|
+
* Otherwise, `useLanePlacement` measures item heights and assigns
|
|
149
|
+
* explicit `grid-column-start` / `grid-row-start` values that
|
|
150
|
+
* approximate the same result inside CSS Grid.
|
|
151
|
+
*
|
|
152
|
+
* Each child's `key` must match an entry in the `layout` array;
|
|
153
|
+
* children without a match render at the end of the surface without
|
|
154
|
+
* explicit placement and fall through the lanes auto-flow.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```jsx
|
|
158
|
+
* <DashboardLanes
|
|
159
|
+
* layout={ [
|
|
160
|
+
* { key: 'a' },
|
|
161
|
+
* { key: 'b', width: 2 },
|
|
162
|
+
* { key: 'c' },
|
|
163
|
+
* ] }
|
|
164
|
+
* columns={ 3 }
|
|
165
|
+
* editMode
|
|
166
|
+
* onChangeLayout={ setLayout }
|
|
167
|
+
* >
|
|
168
|
+
* <Tile key="a">A</Tile>
|
|
169
|
+
* <Tile key="b">B</Tile>
|
|
170
|
+
* <Tile key="c">C</Tile>
|
|
171
|
+
* </DashboardLanes>
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param props Component props.
|
|
175
|
+
* @param ref Forwarded to the surface's root `<div>`.
|
|
176
|
+
*/
|
|
177
|
+
const DashboardLanes = forwardRef(function UnforwardedDashboardLanes(props, ref) {
|
|
178
|
+
const { layout, columns, children, className, style, flowTolerance = 16, rowUnit = 4, minColumnWidth, itemLimits, editMode = false, onChangeLayout, onPreviewLayout, renderResizeHandle, renderDragPreview, renderGridOverlay, ...divProps } = props;
|
|
179
|
+
const [temporaryLayout, setTemporaryLayout] = useState();
|
|
180
|
+
const [activeId, setActiveId] = useState(null);
|
|
181
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
182
|
+
const [resizeSnapPreview, setResizeSnapPreview] = useState(null);
|
|
183
|
+
const latestLayoutRef = useRef(void 0);
|
|
184
|
+
const lastReorderCursorRef = useRef(null);
|
|
185
|
+
const resizeBaselineRef = useRef(null);
|
|
186
|
+
const captureLayoutSnapshotRef = useRef(() => {});
|
|
187
|
+
const childrenCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
188
|
+
const activeLayout = temporaryLayout ?? layout;
|
|
189
|
+
const [container, setContainer] = useState(null);
|
|
190
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
191
|
+
const [gapPx, setGapPx] = useState(FALLBACK_GAP_PX);
|
|
192
|
+
const resizeObserverRef = useResizeObserver(([{ contentRect }]) => {
|
|
193
|
+
setContainerWidth(contentRect.width);
|
|
194
|
+
});
|
|
195
|
+
const mergedRootRef = useMergeRefs([
|
|
196
|
+
setContainer,
|
|
197
|
+
resizeObserverRef,
|
|
198
|
+
ref
|
|
199
|
+
]);
|
|
200
|
+
useLayoutEffect(() => {
|
|
201
|
+
if (!container) return;
|
|
202
|
+
const { width } = container.getBoundingClientRect();
|
|
203
|
+
if (width > 0) setContainerWidth(width);
|
|
204
|
+
const parsed = Number.parseFloat(window.getComputedStyle(container).columnGap);
|
|
205
|
+
if (Number.isFinite(parsed) && parsed > 0) setGapPx(parsed);
|
|
206
|
+
}, [container]);
|
|
207
|
+
const effectiveColumns = useMemo(() => resolveColumnCount({
|
|
208
|
+
columns,
|
|
209
|
+
minColumnWidth
|
|
210
|
+
}, containerWidth, gapPx, DEFAULT_COLUMNS), [
|
|
211
|
+
minColumnWidth,
|
|
212
|
+
gapPx,
|
|
213
|
+
containerWidth,
|
|
214
|
+
columns
|
|
215
|
+
]);
|
|
216
|
+
const columnWidth = (containerWidth - (effectiveColumns - 1) * gapPx) / effectiveColumns;
|
|
217
|
+
const minResizeWidthPx = gridSpanToPixelSize(1, 1, columnWidth, gapPx, null).widthPx;
|
|
218
|
+
const widthBoundsByKey = useSpanBounds(itemLimits, columnWidth, gapPx, null, effectiveColumns);
|
|
219
|
+
const resizeLimitsByKey = useResizePixelLimits(widthBoundsByKey, columnWidth, gapPx, null);
|
|
220
|
+
const layoutMap = useMemo(() => {
|
|
221
|
+
const map = /* @__PURE__ */ new Map();
|
|
222
|
+
activeLayout.forEach((item) => map.set(item.key, item));
|
|
223
|
+
return map;
|
|
224
|
+
}, [activeLayout]);
|
|
225
|
+
const layoutKeys = useMemo(() => new Set(layout.map((item) => item.key)), [layout]);
|
|
226
|
+
const items = useMemo(() => activeLayout.map((item, index) => ({
|
|
227
|
+
item,
|
|
228
|
+
index
|
|
229
|
+
})).sort((a, b) => (a.item.order ?? a.index) - (b.item.order ?? b.index)).map(({ item }) => item.key), [activeLayout]);
|
|
230
|
+
const renderedSpanByKey = useMemo(() => {
|
|
231
|
+
const map = /* @__PURE__ */ new Map();
|
|
232
|
+
for (const [key, item] of layoutMap) {
|
|
233
|
+
const span = typeof item.width === "number" ? Math.max(1, Math.min(item.width, effectiveColumns)) : 1;
|
|
234
|
+
const bounds = widthBoundsByKey.get(key);
|
|
235
|
+
map.set(key, bounds ? clampSpan(span, bounds.minWidth, bounds.maxWidth) : span);
|
|
236
|
+
}
|
|
237
|
+
return map;
|
|
238
|
+
}, [
|
|
239
|
+
layoutMap,
|
|
240
|
+
effectiveColumns,
|
|
241
|
+
widthBoundsByKey
|
|
242
|
+
]);
|
|
243
|
+
const placementItems = useMemo(() => {
|
|
244
|
+
return items.map((key) => ({
|
|
245
|
+
key,
|
|
246
|
+
span: renderedSpanByKey.get(key) ?? 1,
|
|
247
|
+
lane: layoutMap.get(key)?.lane
|
|
248
|
+
}));
|
|
249
|
+
}, [
|
|
250
|
+
items,
|
|
251
|
+
layoutMap,
|
|
252
|
+
renderedSpanByKey
|
|
253
|
+
]);
|
|
254
|
+
const { itemStyles } = useLanePlacement(container, {
|
|
255
|
+
items: placementItems,
|
|
256
|
+
lanes: effectiveColumns,
|
|
257
|
+
gap: gapPx,
|
|
258
|
+
flowTolerance,
|
|
259
|
+
rowUnit
|
|
260
|
+
});
|
|
261
|
+
const [childrenMap, actionableAreaMap, remaining, renderedByKey] = useMemo(() => {
|
|
262
|
+
const childMap = /* @__PURE__ */ new Map();
|
|
263
|
+
const actionableMap = /* @__PURE__ */ new Map();
|
|
264
|
+
const rest = [];
|
|
265
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
266
|
+
Children.forEach(children, (child) => {
|
|
267
|
+
if (!isValidElement(child)) {
|
|
268
|
+
rest.push(child);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const key = child.key?.toString();
|
|
272
|
+
if (!key) {
|
|
273
|
+
rest.push(child);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const { actionableArea } = child.props;
|
|
277
|
+
const stripped = actionableArea !== void 0 ? cloneElement(child, { actionableArea: void 0 }) : child;
|
|
278
|
+
byKey.set(key, stripped);
|
|
279
|
+
if (layoutKeys.has(key)) {
|
|
280
|
+
if (actionableArea !== void 0) actionableMap.set(key, actionableArea);
|
|
281
|
+
childMap.set(key, stripped);
|
|
282
|
+
} else rest.push(child);
|
|
283
|
+
});
|
|
284
|
+
return [
|
|
285
|
+
childMap,
|
|
286
|
+
actionableMap,
|
|
287
|
+
rest,
|
|
288
|
+
byKey
|
|
289
|
+
];
|
|
290
|
+
}, [children, layoutKeys]);
|
|
291
|
+
useLayoutEffect(() => {
|
|
292
|
+
for (const [key, child] of renderedByKey) childrenCacheRef.current.set(key, child);
|
|
293
|
+
}, [renderedByKey]);
|
|
294
|
+
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
|
|
295
|
+
const handleDragStart = useEvent((event) => {
|
|
296
|
+
setActiveId(String(event.active.id));
|
|
297
|
+
lastReorderCursorRef.current = null;
|
|
298
|
+
});
|
|
299
|
+
const handleDragCancel = useEvent(() => {
|
|
300
|
+
setActiveId(null);
|
|
301
|
+
latestLayoutRef.current = void 0;
|
|
302
|
+
lastReorderCursorRef.current = null;
|
|
303
|
+
resizeBaselineRef.current = null;
|
|
304
|
+
setIsResizing(false);
|
|
305
|
+
setResizeSnapPreview(null);
|
|
306
|
+
setTemporaryLayout(void 0);
|
|
307
|
+
});
|
|
308
|
+
const handleDragMove = useEvent((event) => {
|
|
309
|
+
const { active, over } = event;
|
|
310
|
+
if (!over || active.id === over.id) return;
|
|
311
|
+
const activeRect = active.rect.current.translated;
|
|
312
|
+
if (!activeRect) return;
|
|
313
|
+
const activeCenterX = activeRect.left + activeRect.width / 2;
|
|
314
|
+
const activeCenterY = activeRect.top + activeRect.height / 2;
|
|
315
|
+
const lastCursor = lastReorderCursorRef.current;
|
|
316
|
+
if (lastCursor) {
|
|
317
|
+
const dx = activeCenterX - lastCursor.x;
|
|
318
|
+
const dy = activeCenterY - lastCursor.y;
|
|
319
|
+
if (dx * dx + dy * dy < 100) return;
|
|
320
|
+
}
|
|
321
|
+
const insertAfter = activeCenterX > over.rect.left + over.rect.width / 2;
|
|
322
|
+
const currentIndex = items.indexOf(String(active.id));
|
|
323
|
+
const overIndex = items.indexOf(String(over.id));
|
|
324
|
+
let newIndex;
|
|
325
|
+
if (insertAfter) newIndex = currentIndex > overIndex ? overIndex + 1 : overIndex;
|
|
326
|
+
else newIndex = currentIndex > overIndex ? overIndex : overIndex - 1;
|
|
327
|
+
newIndex = Math.max(0, Math.min(newIndex, items.length - 1));
|
|
328
|
+
if (newIndex === currentIndex) return;
|
|
329
|
+
const updatedItems = arrayMoveWithPinned(items, currentIndex, newIndex, (key) => layoutMap.get(key)?.draggable === false);
|
|
330
|
+
if (updatedItems.every((key, index) => key === items[index])) return;
|
|
331
|
+
const orderByKey = /* @__PURE__ */ new Map();
|
|
332
|
+
updatedItems.forEach((key, index) => {
|
|
333
|
+
orderByKey.set(key, index);
|
|
334
|
+
});
|
|
335
|
+
const updatedLayout = activeLayout.map((item) => ({
|
|
336
|
+
...item,
|
|
337
|
+
order: orderByKey.get(item.key) ?? 0
|
|
338
|
+
}));
|
|
339
|
+
lastReorderCursorRef.current = {
|
|
340
|
+
x: activeCenterX,
|
|
341
|
+
y: activeCenterY
|
|
342
|
+
};
|
|
343
|
+
latestLayoutRef.current = updatedLayout;
|
|
344
|
+
captureLayoutSnapshotRef.current();
|
|
345
|
+
setTemporaryLayout(updatedLayout);
|
|
346
|
+
onPreviewLayout?.(updatedLayout);
|
|
347
|
+
});
|
|
348
|
+
const persistTemporaryLayout = useEvent(() => {
|
|
349
|
+
const latest = latestLayoutRef.current;
|
|
350
|
+
latestLayoutRef.current = void 0;
|
|
351
|
+
resizeBaselineRef.current = null;
|
|
352
|
+
setIsResizing(false);
|
|
353
|
+
setResizeSnapPreview(null);
|
|
354
|
+
if (!onChangeLayout || !latest) {
|
|
355
|
+
setTemporaryLayout(void 0);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
onChangeLayout(latest);
|
|
359
|
+
setTemporaryLayout(void 0);
|
|
360
|
+
});
|
|
361
|
+
const handleResize = useEvent((id, delta) => {
|
|
362
|
+
if (!editMode) return;
|
|
363
|
+
if (!isResizing) setIsResizing(true);
|
|
364
|
+
const relativeDelta = Math.round(delta.width / (columnWidth + gapPx));
|
|
365
|
+
if (resizeBaselineRef.current === null) resizeBaselineRef.current = renderedSpanByKey.get(id) ?? 1;
|
|
366
|
+
const baseline = resizeBaselineRef.current;
|
|
367
|
+
const bounds = widthBoundsByKey.get(id);
|
|
368
|
+
const newWidth = clampSpan(baseline + relativeDelta, bounds?.minWidth ?? 1, bounds?.maxWidth ?? effectiveColumns);
|
|
369
|
+
setResizeSnapPreview({
|
|
370
|
+
id,
|
|
371
|
+
snap: gridSpanToPixelSize(newWidth, 1, columnWidth, gapPx, null)
|
|
372
|
+
});
|
|
373
|
+
if (((latestLayoutRef.current?.find((item) => item.key === id))?.width ?? renderedSpanByKey.get(id)) === newWidth) return;
|
|
374
|
+
const updatedLayout = activeLayout.map((item) => item.key === id ? {
|
|
375
|
+
...item,
|
|
376
|
+
width: newWidth
|
|
377
|
+
} : item);
|
|
378
|
+
latestLayoutRef.current = updatedLayout;
|
|
379
|
+
captureLayoutSnapshotRef.current();
|
|
380
|
+
setTemporaryLayout(updatedLayout);
|
|
381
|
+
onPreviewLayout?.(updatedLayout);
|
|
382
|
+
});
|
|
383
|
+
const interacting = activeId !== null || isResizing;
|
|
384
|
+
const activeClone = activeId ? childrenMap.get(activeId) : null;
|
|
385
|
+
const DragPreview = renderDragPreview;
|
|
386
|
+
const dragOverlayContent = activeId && activeClone ? /* @__PURE__ */ jsx("div", {
|
|
387
|
+
className: lanes_module_default["drag-preview-frame"],
|
|
388
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
389
|
+
className: lanes_module_default["drag-preview-frame__lift"],
|
|
390
|
+
children: DragPreview ? /* @__PURE__ */ jsx(DragPreview, {
|
|
391
|
+
itemId: activeId,
|
|
392
|
+
children: activeClone
|
|
393
|
+
}) : activeClone
|
|
394
|
+
})
|
|
395
|
+
}) : null;
|
|
396
|
+
const Overlay = renderGridOverlay ?? GridOverlay;
|
|
397
|
+
const gridOverlay = useMemo(() => /* @__PURE__ */ jsx(Overlay, {
|
|
398
|
+
columns: effectiveColumns,
|
|
399
|
+
isActive: editMode
|
|
400
|
+
}), [
|
|
401
|
+
Overlay,
|
|
402
|
+
editMode,
|
|
403
|
+
effectiveColumns
|
|
404
|
+
]);
|
|
405
|
+
const layoutFingerprint = useMemo(() => {
|
|
406
|
+
return `${getLayoutFingerprint(activeLayout)}\0${getPlacementFingerprint(itemStyles)}`;
|
|
407
|
+
}, [activeLayout, itemStyles]);
|
|
408
|
+
const excludeLayoutAnimationKey = activeId ?? (isResizing ? resizeSnapPreview?.id : null);
|
|
409
|
+
const { captureLayoutSnapshot, getPositionsBeforeLastChange } = useLayoutShiftAnimation({
|
|
410
|
+
container,
|
|
411
|
+
enabled: editMode,
|
|
412
|
+
layoutFingerprint,
|
|
413
|
+
excludeItemKey: excludeLayoutAnimationKey
|
|
414
|
+
});
|
|
415
|
+
const { exitingItems, clearExitingItem } = useItemExitAnimation({
|
|
416
|
+
container,
|
|
417
|
+
enabled: editMode,
|
|
418
|
+
layoutKeys,
|
|
419
|
+
getPositionsBeforeLastChange,
|
|
420
|
+
childrenCacheRef
|
|
421
|
+
});
|
|
422
|
+
const layoutAnimating = editMode;
|
|
423
|
+
useLayoutEffect(() => {
|
|
424
|
+
captureLayoutSnapshotRef.current = captureLayoutSnapshot;
|
|
425
|
+
}, [captureLayoutSnapshot]);
|
|
426
|
+
return /* @__PURE__ */ jsxs(DndContext, {
|
|
427
|
+
sensors,
|
|
428
|
+
onDragStart: handleDragStart,
|
|
429
|
+
onDragCancel: handleDragCancel,
|
|
430
|
+
onDragMove: handleDragMove,
|
|
431
|
+
onDragEnd: () => {
|
|
432
|
+
persistTemporaryLayout();
|
|
433
|
+
lastReorderCursorRef.current = null;
|
|
434
|
+
setActiveId(null);
|
|
435
|
+
},
|
|
436
|
+
children: [/* @__PURE__ */ jsx(SortableContext, {
|
|
437
|
+
items,
|
|
438
|
+
strategy: NO_SORT_STRATEGY,
|
|
439
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
440
|
+
...divProps,
|
|
441
|
+
ref: mergedRootRef,
|
|
442
|
+
className: clsx(lanes_module_default.lanes, layoutAnimating && layout_shift_animation_module_default["layout-animating"], className),
|
|
443
|
+
"data-wp-grid-dragging": activeId || void 0,
|
|
444
|
+
"data-wp-grid-resizing": isResizing || void 0,
|
|
445
|
+
style: {
|
|
446
|
+
...style,
|
|
447
|
+
gridTemplateColumns: `repeat(${effectiveColumns}, minmax(0, 1fr))`,
|
|
448
|
+
"--wp-grid-lane-row-unit": `${Math.max(1, rowUnit)}px`
|
|
449
|
+
},
|
|
450
|
+
children: [
|
|
451
|
+
gridOverlay,
|
|
452
|
+
items.map((id) => {
|
|
453
|
+
const child = childrenMap.get(id);
|
|
454
|
+
if (!child) return null;
|
|
455
|
+
const limitsPx = resizeLimitsByKey.get(id);
|
|
456
|
+
return /* @__PURE__ */ jsx(LanesItem, {
|
|
457
|
+
itemKey: id,
|
|
458
|
+
placementStyle: itemStyles.get(id) ?? {},
|
|
459
|
+
disabled: !editMode,
|
|
460
|
+
draggable: layoutMap.get(id)?.draggable !== false,
|
|
461
|
+
resizable: layoutMap.get(id)?.resizable !== false,
|
|
462
|
+
interacting,
|
|
463
|
+
dragging: activeId !== null,
|
|
464
|
+
onResize: handleResize,
|
|
465
|
+
onResizeEnd: persistTemporaryLayout,
|
|
466
|
+
resizeSnapPreview: resizeSnapPreview?.id === id ? resizeSnapPreview.snap : null,
|
|
467
|
+
minResizeWidthPx: limitsPx?.minWidthPx ?? minResizeWidthPx,
|
|
468
|
+
maxResizeWidthPx: limitsPx?.maxWidthPx,
|
|
469
|
+
actionableArea: actionableAreaMap.get(id),
|
|
470
|
+
renderResizeHandle,
|
|
471
|
+
children: child
|
|
472
|
+
}, id);
|
|
473
|
+
}),
|
|
474
|
+
remaining,
|
|
475
|
+
exitingItems.map(({ key, rect, child }) => /* @__PURE__ */ jsx(ItemExitOverlay, {
|
|
476
|
+
itemKey: key,
|
|
477
|
+
rect,
|
|
478
|
+
onAnimationEnd: () => clearExitingItem(key),
|
|
479
|
+
children: child
|
|
480
|
+
}, `exiting-${key}`))
|
|
481
|
+
]
|
|
482
|
+
})
|
|
483
|
+
}), /* @__PURE__ */ jsx(DragOverlay, {
|
|
484
|
+
dropAnimation: dashboardDragDropAnimation,
|
|
485
|
+
children: dragOverlayContent
|
|
486
|
+
})]
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
export { DashboardLanes };
|
|
130
490
|
|
|
131
|
-
|
|
132
|
-
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
133
|
-
registerStyle("7b851be8c0", "._8cc368bc6c2d79c6__lanes{column-gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));display:grid-lanes;position:relative;row-gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px))}@supports not (display:grid-lanes){._8cc368bc6c2d79c6__lanes{display:grid;grid-auto-flow:dense;grid-auto-rows:var(--wp-grid-lane-row-unit,4px);row-gap:0}}._1bfa908a532e32a4__drag-preview-frame{--_wp-grid-elevation-xs:0 1px 1px rgba(0,0,0,.03),0 1px 2px rgba(0,0,0,.02),0 3px 3px rgba(0,0,0,.02),0 4px 4px rgba(0,0,0,.01);--_wp-grid-elevation-md:0 2px 3px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.04),0 12px 12px rgba(0,0,0,.03),0 16px 16px rgba(0,0,0,.02);border-radius:var(--wp-grid-drag-preview-radius,0);box-shadow:var(--_wp-grid-elevation-md);cursor:grabbing;height:100%;pointer-events:none}.bd684ee9f92388ed__drag-preview-frame__lift{height:100%;transform:scale(var(--wp-grid-drag-preview-scale,1.05));transform-origin:center}@media not (prefers-reduced-motion:reduce){._1bfa908a532e32a4__drag-preview-frame{animation:_5f4a1718cb7927ee__wp-grid-drag-preview-shadow-enter var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) both}.bd684ee9f92388ed__drag-preview-frame__lift{animation:_29f7f02d4f227b1e__wp-grid-drag-preview-scale-enter var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) both}}@media not (prefers-reduced-motion:reduce){@keyframes _5f4a1718cb7927ee__wp-grid-drag-preview-shadow-enter{0%{box-shadow:var(--_wp-grid-elevation-xs)}to{box-shadow:var(--_wp-grid-elevation-md)}}@keyframes _29f7f02d4f227b1e__wp-grid-drag-preview-scale-enter{0%{transform:scale(1)}to{transform:scale(var(--wp-grid-drag-preview-scale,1.05))}}}@media not (prefers-reduced-motion:reduce){._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting{animation:_6883de14c5fb8559__wp-grid-drag-preview-shadow-exit var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting .bd684ee9f92388ed__drag-preview-frame__lift{animation:_0de4da1cd817e536__wp-grid-drag-preview-scale-exit var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}@keyframes _6883de14c5fb8559__wp-grid-drag-preview-shadow-exit{0%{box-shadow:var(--_wp-grid-elevation-md)}to{box-shadow:var(--_wp-grid-elevation-xs)}}@keyframes _0de4da1cd817e536__wp-grid-drag-preview-scale-exit{0%{transform:scale(var(--wp-grid-drag-preview-scale,1.05))}to{transform:scale(1)}}}._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting{box-shadow:var(--_wp-grid-elevation-xs)}._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting .bd684ee9f92388ed__drag-preview-frame__lift{transform:scale(1)}@media (prefers-reduced-motion:reduce){._1bfa908a532e32a4__drag-preview-frame{box-shadow:var(--_wp-grid-elevation-md)}.bd684ee9f92388ed__drag-preview-frame__lift{transform:none}._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting{box-shadow:var(--_wp-grid-elevation-xs);transition:none}._1bfa908a532e32a4__drag-preview-frame._4e3613427755609c__is-exiting .bd684ee9f92388ed__drag-preview-frame__lift{transition:none}}");
|
|
134
|
-
}
|
|
135
|
-
var lanes_default = { "lanes": "_8cc368bc6c2d79c6__lanes", "drag-preview-frame": "_1bfa908a532e32a4__drag-preview-frame", "drag-preview-frame__lift": "bd684ee9f92388ed__drag-preview-frame__lift", "wp-grid-drag-preview-shadow-enter": "_5f4a1718cb7927ee__wp-grid-drag-preview-shadow-enter", "wp-grid-drag-preview-scale-enter": "_29f7f02d4f227b1e__wp-grid-drag-preview-scale-enter", "is-exiting": "_4e3613427755609c__is-exiting", "wp-grid-drag-preview-shadow-exit": "_6883de14c5fb8559__wp-grid-drag-preview-shadow-exit", "wp-grid-drag-preview-scale-exit": "_0de4da1cd817e536__wp-grid-drag-preview-scale-exit" };
|
|
136
|
-
|
|
137
|
-
// packages/grid/src/dashboard-lanes/index.tsx
|
|
138
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
139
|
-
var dashboardDragDropAnimation = createDashboardDragDropAnimation(
|
|
140
|
-
lanes_default["drag-preview-frame"],
|
|
141
|
-
lanes_default["is-exiting"]
|
|
142
|
-
);
|
|
143
|
-
var FALLBACK_GAP_PX = 24;
|
|
144
|
-
var DEFAULT_COLUMNS = 6;
|
|
145
|
-
var NO_SORT_STRATEGY = () => null;
|
|
146
|
-
var DashboardLanes = forwardRef(
|
|
147
|
-
function UnforwardedDashboardLanes(props, ref) {
|
|
148
|
-
const {
|
|
149
|
-
layout,
|
|
150
|
-
columns,
|
|
151
|
-
children,
|
|
152
|
-
className,
|
|
153
|
-
style,
|
|
154
|
-
flowTolerance = 16,
|
|
155
|
-
rowUnit = 4,
|
|
156
|
-
minColumnWidth,
|
|
157
|
-
itemLimits,
|
|
158
|
-
editMode = false,
|
|
159
|
-
onChangeLayout,
|
|
160
|
-
onPreviewLayout,
|
|
161
|
-
renderResizeHandle,
|
|
162
|
-
renderDragPreview,
|
|
163
|
-
renderGridOverlay,
|
|
164
|
-
...divProps
|
|
165
|
-
} = props;
|
|
166
|
-
const [temporaryLayout, setTemporaryLayout] = useState();
|
|
167
|
-
const [activeId, setActiveId] = useState(null);
|
|
168
|
-
const [isResizing, setIsResizing] = useState(false);
|
|
169
|
-
const [resizeSnapPreview, setResizeSnapPreview] = useState(null);
|
|
170
|
-
const latestLayoutRef = useRef(void 0);
|
|
171
|
-
const lastReorderCursorRef = useRef(null);
|
|
172
|
-
const resizeBaselineRef = useRef(null);
|
|
173
|
-
const captureLayoutSnapshotRef = useRef(() => {
|
|
174
|
-
});
|
|
175
|
-
const childrenCacheRef = useRef(
|
|
176
|
-
/* @__PURE__ */ new Map()
|
|
177
|
-
);
|
|
178
|
-
const activeLayout = temporaryLayout ?? layout;
|
|
179
|
-
const [container, setContainer] = useState(
|
|
180
|
-
null
|
|
181
|
-
);
|
|
182
|
-
const [containerWidth, setContainerWidth] = useState(0);
|
|
183
|
-
const [gapPx, setGapPx] = useState(FALLBACK_GAP_PX);
|
|
184
|
-
const resizeObserverRef = useResizeObserver(
|
|
185
|
-
([{ contentRect }]) => {
|
|
186
|
-
setContainerWidth(contentRect.width);
|
|
187
|
-
}
|
|
188
|
-
);
|
|
189
|
-
const mergedRootRef = useMergeRefs([
|
|
190
|
-
setContainer,
|
|
191
|
-
resizeObserverRef,
|
|
192
|
-
ref
|
|
193
|
-
]);
|
|
194
|
-
useLayoutEffect(() => {
|
|
195
|
-
if (!container) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
const { width } = container.getBoundingClientRect();
|
|
199
|
-
if (width > 0) {
|
|
200
|
-
setContainerWidth(width);
|
|
201
|
-
}
|
|
202
|
-
const parsed = Number.parseFloat(
|
|
203
|
-
window.getComputedStyle(container).columnGap
|
|
204
|
-
);
|
|
205
|
-
if (Number.isFinite(parsed) && parsed > 0) {
|
|
206
|
-
setGapPx(parsed);
|
|
207
|
-
}
|
|
208
|
-
}, [container]);
|
|
209
|
-
const effectiveColumns = useMemo(() => {
|
|
210
|
-
if (!minColumnWidth) {
|
|
211
|
-
return columns ?? DEFAULT_COLUMNS;
|
|
212
|
-
}
|
|
213
|
-
const totalWidthPerColumn = minColumnWidth + gapPx;
|
|
214
|
-
const maxFit = Math.max(
|
|
215
|
-
1,
|
|
216
|
-
Math.floor((containerWidth + gapPx) / totalWidthPerColumn)
|
|
217
|
-
);
|
|
218
|
-
return columns !== void 0 ? Math.min(columns, maxFit) : maxFit;
|
|
219
|
-
}, [minColumnWidth, gapPx, containerWidth, columns]);
|
|
220
|
-
const columnWidth = (containerWidth - (effectiveColumns - 1) * gapPx) / effectiveColumns;
|
|
221
|
-
const minResizeWidthPx = gridSpanToPixelSize(
|
|
222
|
-
1,
|
|
223
|
-
1,
|
|
224
|
-
columnWidth,
|
|
225
|
-
gapPx,
|
|
226
|
-
null
|
|
227
|
-
).widthPx;
|
|
228
|
-
const widthBoundsByKey = useSpanBounds(
|
|
229
|
-
itemLimits,
|
|
230
|
-
columnWidth,
|
|
231
|
-
gapPx,
|
|
232
|
-
null,
|
|
233
|
-
effectiveColumns
|
|
234
|
-
);
|
|
235
|
-
const resizeLimitsByKey = useResizePixelLimits(
|
|
236
|
-
widthBoundsByKey,
|
|
237
|
-
columnWidth,
|
|
238
|
-
gapPx,
|
|
239
|
-
null
|
|
240
|
-
);
|
|
241
|
-
const layoutMap = useMemo(() => {
|
|
242
|
-
const map = /* @__PURE__ */ new Map();
|
|
243
|
-
activeLayout.forEach((item) => map.set(item.key, item));
|
|
244
|
-
return map;
|
|
245
|
-
}, [activeLayout]);
|
|
246
|
-
const layoutKeys = useMemo(
|
|
247
|
-
() => new Set(layout.map((item) => item.key)),
|
|
248
|
-
[layout]
|
|
249
|
-
);
|
|
250
|
-
const sortedItems = useMemo(
|
|
251
|
-
() => activeLayout.map((item, index) => ({ item, index })).sort(
|
|
252
|
-
(a, b) => (a.item.order ?? a.index) - (b.item.order ?? b.index)
|
|
253
|
-
).map(({ item }) => item.key),
|
|
254
|
-
[activeLayout]
|
|
255
|
-
);
|
|
256
|
-
const items = sortedItems;
|
|
257
|
-
const renderedSpanByKey = useMemo(() => {
|
|
258
|
-
const map = /* @__PURE__ */ new Map();
|
|
259
|
-
for (const [key, item] of layoutMap) {
|
|
260
|
-
const span = typeof item.width === "number" ? Math.max(
|
|
261
|
-
1,
|
|
262
|
-
Math.min(item.width, effectiveColumns)
|
|
263
|
-
) : 1;
|
|
264
|
-
const bounds = widthBoundsByKey.get(key);
|
|
265
|
-
map.set(
|
|
266
|
-
key,
|
|
267
|
-
bounds ? clampSpan(span, bounds.minWidth, bounds.maxWidth) : span
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
return map;
|
|
271
|
-
}, [layoutMap, effectiveColumns, widthBoundsByKey]);
|
|
272
|
-
const placementItems = useMemo(() => {
|
|
273
|
-
return items.map((key) => ({
|
|
274
|
-
key,
|
|
275
|
-
span: renderedSpanByKey.get(key) ?? 1,
|
|
276
|
-
lane: layoutMap.get(key)?.lane
|
|
277
|
-
}));
|
|
278
|
-
}, [items, layoutMap, renderedSpanByKey]);
|
|
279
|
-
const { itemStyles } = useLanePlacement(container, {
|
|
280
|
-
items: placementItems,
|
|
281
|
-
lanes: effectiveColumns,
|
|
282
|
-
gap: gapPx,
|
|
283
|
-
flowTolerance,
|
|
284
|
-
rowUnit
|
|
285
|
-
});
|
|
286
|
-
const [childrenMap, actionableAreaMap, remaining, renderedByKey] = useMemo(() => {
|
|
287
|
-
const childMap = /* @__PURE__ */ new Map();
|
|
288
|
-
const actionableMap = /* @__PURE__ */ new Map();
|
|
289
|
-
const rest = [];
|
|
290
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
291
|
-
Children.forEach(children, (child) => {
|
|
292
|
-
if (!isValidElement(child)) {
|
|
293
|
-
rest.push(child);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const key = child.key?.toString();
|
|
297
|
-
if (!key) {
|
|
298
|
-
rest.push(child);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const { actionableArea } = child.props;
|
|
302
|
-
const stripped = actionableArea !== void 0 ? cloneElement(
|
|
303
|
-
child,
|
|
304
|
-
{ actionableArea: void 0 }
|
|
305
|
-
) : child;
|
|
306
|
-
byKey.set(key, stripped);
|
|
307
|
-
if (layoutKeys.has(key)) {
|
|
308
|
-
if (actionableArea !== void 0) {
|
|
309
|
-
actionableMap.set(key, actionableArea);
|
|
310
|
-
}
|
|
311
|
-
childMap.set(key, stripped);
|
|
312
|
-
} else {
|
|
313
|
-
rest.push(child);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
return [childMap, actionableMap, rest, byKey];
|
|
317
|
-
}, [children, layoutKeys]);
|
|
318
|
-
useLayoutEffect(() => {
|
|
319
|
-
for (const [key, child] of renderedByKey) {
|
|
320
|
-
childrenCacheRef.current.set(key, child);
|
|
321
|
-
}
|
|
322
|
-
}, [renderedByKey]);
|
|
323
|
-
const sensors = useSensors(
|
|
324
|
-
useSensor(PointerSensor),
|
|
325
|
-
useSensor(KeyboardSensor, {
|
|
326
|
-
coordinateGetter: sortableKeyboardCoordinates
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
const handleDragStart = useEvent((event) => {
|
|
330
|
-
setActiveId(String(event.active.id));
|
|
331
|
-
lastReorderCursorRef.current = null;
|
|
332
|
-
});
|
|
333
|
-
const handleDragCancel = useEvent(() => {
|
|
334
|
-
setActiveId(null);
|
|
335
|
-
latestLayoutRef.current = void 0;
|
|
336
|
-
lastReorderCursorRef.current = null;
|
|
337
|
-
resizeBaselineRef.current = null;
|
|
338
|
-
setIsResizing(false);
|
|
339
|
-
setResizeSnapPreview(null);
|
|
340
|
-
setTemporaryLayout(void 0);
|
|
341
|
-
});
|
|
342
|
-
const handleDragMove = useEvent((event) => {
|
|
343
|
-
const { active, over } = event;
|
|
344
|
-
if (!over || active.id === over.id) {
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
const activeRect = active.rect.current.translated;
|
|
348
|
-
if (!activeRect) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
const activeCenterX = activeRect.left + activeRect.width / 2;
|
|
352
|
-
const activeCenterY = activeRect.top + activeRect.height / 2;
|
|
353
|
-
const lastCursor = lastReorderCursorRef.current;
|
|
354
|
-
if (lastCursor) {
|
|
355
|
-
const dx = activeCenterX - lastCursor.x;
|
|
356
|
-
const dy = activeCenterY - lastCursor.y;
|
|
357
|
-
if (dx * dx + dy * dy < 100) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
const overCenterX = over.rect.left + over.rect.width / 2;
|
|
362
|
-
const insertAfter = activeCenterX > overCenterX;
|
|
363
|
-
const currentIndex = items.indexOf(String(active.id));
|
|
364
|
-
const overIndex = items.indexOf(String(over.id));
|
|
365
|
-
let newIndex;
|
|
366
|
-
if (insertAfter) {
|
|
367
|
-
newIndex = currentIndex > overIndex ? overIndex + 1 : overIndex;
|
|
368
|
-
} else {
|
|
369
|
-
newIndex = currentIndex > overIndex ? overIndex : overIndex - 1;
|
|
370
|
-
}
|
|
371
|
-
newIndex = Math.max(0, Math.min(newIndex, items.length - 1));
|
|
372
|
-
if (newIndex === currentIndex) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const updatedItems = arrayMoveWithPinned(
|
|
376
|
-
items,
|
|
377
|
-
currentIndex,
|
|
378
|
-
newIndex,
|
|
379
|
-
(key) => layoutMap.get(key)?.draggable === false
|
|
380
|
-
);
|
|
381
|
-
if (updatedItems.every((key, index) => key === items[index])) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const orderByKey = /* @__PURE__ */ new Map();
|
|
385
|
-
updatedItems.forEach((key, index) => {
|
|
386
|
-
orderByKey.set(key, index);
|
|
387
|
-
});
|
|
388
|
-
const updatedLayout = activeLayout.map((item) => ({
|
|
389
|
-
...item,
|
|
390
|
-
order: orderByKey.get(item.key) ?? 0
|
|
391
|
-
}));
|
|
392
|
-
lastReorderCursorRef.current = {
|
|
393
|
-
x: activeCenterX,
|
|
394
|
-
y: activeCenterY
|
|
395
|
-
};
|
|
396
|
-
latestLayoutRef.current = updatedLayout;
|
|
397
|
-
captureLayoutSnapshotRef.current();
|
|
398
|
-
setTemporaryLayout(updatedLayout);
|
|
399
|
-
onPreviewLayout?.(updatedLayout);
|
|
400
|
-
});
|
|
401
|
-
const persistTemporaryLayout = useEvent(() => {
|
|
402
|
-
const latest = latestLayoutRef.current;
|
|
403
|
-
latestLayoutRef.current = void 0;
|
|
404
|
-
resizeBaselineRef.current = null;
|
|
405
|
-
setIsResizing(false);
|
|
406
|
-
setResizeSnapPreview(null);
|
|
407
|
-
if (!onChangeLayout || !latest) {
|
|
408
|
-
setTemporaryLayout(void 0);
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
onChangeLayout(latest);
|
|
412
|
-
setTemporaryLayout(void 0);
|
|
413
|
-
});
|
|
414
|
-
const handleResize = useEvent((id, delta) => {
|
|
415
|
-
if (!editMode) {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
if (!isResizing) {
|
|
419
|
-
setIsResizing(true);
|
|
420
|
-
}
|
|
421
|
-
const relativeDelta = Math.round(
|
|
422
|
-
delta.width / (columnWidth + gapPx)
|
|
423
|
-
);
|
|
424
|
-
if (resizeBaselineRef.current === null) {
|
|
425
|
-
resizeBaselineRef.current = renderedSpanByKey.get(id) ?? 1;
|
|
426
|
-
}
|
|
427
|
-
const baseline = resizeBaselineRef.current;
|
|
428
|
-
const bounds = widthBoundsByKey.get(id);
|
|
429
|
-
const newWidth = clampSpan(
|
|
430
|
-
baseline + relativeDelta,
|
|
431
|
-
bounds?.minWidth ?? 1,
|
|
432
|
-
bounds?.maxWidth ?? effectiveColumns
|
|
433
|
-
);
|
|
434
|
-
setResizeSnapPreview({
|
|
435
|
-
id,
|
|
436
|
-
snap: gridSpanToPixelSize(
|
|
437
|
-
newWidth,
|
|
438
|
-
1,
|
|
439
|
-
columnWidth,
|
|
440
|
-
gapPx,
|
|
441
|
-
null
|
|
442
|
-
)
|
|
443
|
-
});
|
|
444
|
-
const pendingItem = latestLayoutRef.current?.find(
|
|
445
|
-
(item) => item.key === id
|
|
446
|
-
);
|
|
447
|
-
const currentWidth = pendingItem?.width ?? renderedSpanByKey.get(id);
|
|
448
|
-
if (currentWidth === newWidth) {
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
const updatedLayout = activeLayout.map(
|
|
452
|
-
(item) => item.key === id ? { ...item, width: newWidth } : item
|
|
453
|
-
);
|
|
454
|
-
latestLayoutRef.current = updatedLayout;
|
|
455
|
-
captureLayoutSnapshotRef.current();
|
|
456
|
-
setTemporaryLayout(updatedLayout);
|
|
457
|
-
onPreviewLayout?.(updatedLayout);
|
|
458
|
-
});
|
|
459
|
-
const interacting = activeId !== null || isResizing;
|
|
460
|
-
const activeClone = activeId ? childrenMap.get(activeId) : null;
|
|
461
|
-
const DragPreview = renderDragPreview;
|
|
462
|
-
const dragOverlayContent = activeId && activeClone ? /* @__PURE__ */ jsx("div", { className: lanes_default["drag-preview-frame"], children: /* @__PURE__ */ jsx("div", { className: lanes_default["drag-preview-frame__lift"], children: DragPreview ? /* @__PURE__ */ jsx(DragPreview, { itemId: activeId, children: activeClone }) : activeClone }) }) : null;
|
|
463
|
-
const Overlay = renderGridOverlay ?? GridOverlay;
|
|
464
|
-
const gridOverlay = useMemo(
|
|
465
|
-
() => /* @__PURE__ */ jsx(Overlay, { columns: effectiveColumns, isActive: editMode }),
|
|
466
|
-
[Overlay, editMode, effectiveColumns]
|
|
467
|
-
);
|
|
468
|
-
const layoutFingerprint = useMemo(() => {
|
|
469
|
-
const layoutSig = getLayoutFingerprint(activeLayout);
|
|
470
|
-
const placementSig = getPlacementFingerprint(itemStyles);
|
|
471
|
-
return `${layoutSig}\0${placementSig}`;
|
|
472
|
-
}, [activeLayout, itemStyles]);
|
|
473
|
-
const excludeLayoutAnimationKey = activeId ?? (isResizing ? resizeSnapPreview?.id : null);
|
|
474
|
-
const { captureLayoutSnapshot, getPositionsBeforeLastChange } = useLayoutShiftAnimation({
|
|
475
|
-
container,
|
|
476
|
-
enabled: editMode,
|
|
477
|
-
layoutFingerprint,
|
|
478
|
-
excludeItemKey: excludeLayoutAnimationKey
|
|
479
|
-
});
|
|
480
|
-
const { exitingItems, clearExitingItem } = useItemExitAnimation({
|
|
481
|
-
container,
|
|
482
|
-
enabled: editMode,
|
|
483
|
-
layoutKeys,
|
|
484
|
-
getPositionsBeforeLastChange,
|
|
485
|
-
childrenCacheRef
|
|
486
|
-
});
|
|
487
|
-
const layoutAnimating = editMode;
|
|
488
|
-
useLayoutEffect(() => {
|
|
489
|
-
captureLayoutSnapshotRef.current = captureLayoutSnapshot;
|
|
490
|
-
}, [captureLayoutSnapshot]);
|
|
491
|
-
return /* @__PURE__ */ jsxs(
|
|
492
|
-
DndContext,
|
|
493
|
-
{
|
|
494
|
-
sensors,
|
|
495
|
-
onDragStart: handleDragStart,
|
|
496
|
-
onDragCancel: handleDragCancel,
|
|
497
|
-
onDragMove: handleDragMove,
|
|
498
|
-
onDragEnd: () => {
|
|
499
|
-
persistTemporaryLayout();
|
|
500
|
-
lastReorderCursorRef.current = null;
|
|
501
|
-
setActiveId(null);
|
|
502
|
-
},
|
|
503
|
-
children: [
|
|
504
|
-
/* @__PURE__ */ jsx(SortableContext, { items, strategy: NO_SORT_STRATEGY, children: /* @__PURE__ */ jsxs(
|
|
505
|
-
"div",
|
|
506
|
-
{
|
|
507
|
-
...divProps,
|
|
508
|
-
ref: mergedRootRef,
|
|
509
|
-
className: clsx(
|
|
510
|
-
lanes_default.lanes,
|
|
511
|
-
layoutAnimating && layout_shift_animation_default["layout-animating"],
|
|
512
|
-
className
|
|
513
|
-
),
|
|
514
|
-
"data-wp-grid-dragging": activeId || void 0,
|
|
515
|
-
"data-wp-grid-resizing": isResizing || void 0,
|
|
516
|
-
style: {
|
|
517
|
-
...style,
|
|
518
|
-
gridTemplateColumns: `repeat(${effectiveColumns}, minmax(0, 1fr))`,
|
|
519
|
-
// `column-gap` and `row-gap` are set in
|
|
520
|
-
// `lanes.module.css` from the
|
|
521
|
-
// design-system gap token, with an
|
|
522
|
-
// `@supports` block that zeroes `row-gap`
|
|
523
|
-
// in polyfill mode (the skyline already
|
|
524
|
-
// encodes vertical spacing in each tile's
|
|
525
|
-
// `top`). Driving the toggle from CSS
|
|
526
|
-
// keeps SSR and client output identical
|
|
527
|
-
// regardless of native support.
|
|
528
|
-
"--wp-grid-lane-row-unit": `${Math.max(
|
|
529
|
-
1,
|
|
530
|
-
rowUnit
|
|
531
|
-
)}px`
|
|
532
|
-
},
|
|
533
|
-
children: [
|
|
534
|
-
gridOverlay,
|
|
535
|
-
items.map((id) => {
|
|
536
|
-
const child = childrenMap.get(id);
|
|
537
|
-
if (!child) {
|
|
538
|
-
return null;
|
|
539
|
-
}
|
|
540
|
-
const limitsPx = resizeLimitsByKey.get(id);
|
|
541
|
-
return /* @__PURE__ */ jsx(
|
|
542
|
-
LanesItem,
|
|
543
|
-
{
|
|
544
|
-
itemKey: id,
|
|
545
|
-
placementStyle: itemStyles.get(id) ?? {},
|
|
546
|
-
disabled: !editMode,
|
|
547
|
-
draggable: layoutMap.get(id)?.draggable !== false,
|
|
548
|
-
resizable: layoutMap.get(id)?.resizable !== false,
|
|
549
|
-
interacting,
|
|
550
|
-
dragging: activeId !== null,
|
|
551
|
-
onResize: handleResize,
|
|
552
|
-
onResizeEnd: persistTemporaryLayout,
|
|
553
|
-
resizeSnapPreview: resizeSnapPreview?.id === id ? resizeSnapPreview.snap : null,
|
|
554
|
-
minResizeWidthPx: limitsPx?.minWidthPx ?? minResizeWidthPx,
|
|
555
|
-
maxResizeWidthPx: limitsPx?.maxWidthPx,
|
|
556
|
-
actionableArea: actionableAreaMap.get(
|
|
557
|
-
id
|
|
558
|
-
),
|
|
559
|
-
renderResizeHandle,
|
|
560
|
-
children: child
|
|
561
|
-
},
|
|
562
|
-
id
|
|
563
|
-
);
|
|
564
|
-
}),
|
|
565
|
-
remaining,
|
|
566
|
-
exitingItems.map(({ key, rect, child }) => /* @__PURE__ */ jsx(
|
|
567
|
-
ItemExitOverlay,
|
|
568
|
-
{
|
|
569
|
-
itemKey: key,
|
|
570
|
-
rect,
|
|
571
|
-
onAnimationEnd: () => clearExitingItem(key),
|
|
572
|
-
children: child
|
|
573
|
-
},
|
|
574
|
-
`exiting-${key}`
|
|
575
|
-
))
|
|
576
|
-
]
|
|
577
|
-
}
|
|
578
|
-
) }),
|
|
579
|
-
/* @__PURE__ */ jsx(DragOverlay, { dropAnimation: dashboardDragDropAnimation, children: dragOverlayContent })
|
|
580
|
-
]
|
|
581
|
-
}
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
);
|
|
585
|
-
export {
|
|
586
|
-
DashboardLanes
|
|
587
|
-
};
|
|
588
|
-
//# sourceMappingURL=index.mjs.map
|
|
491
|
+
//# sourceMappingURL=index.mjs.map
|