@wordpress/grid 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +525 -632
- 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 +494 -576
- 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/build-types/shared/drag-overlay-drop-animation.d.ts +2 -2
- package/build-types/shared/use-item-exit-animation.d.ts +1 -1
- package/build-types/shared/use-item-exit-animation.d.ts.map +1 -1
- package/package.json +13 -14
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/index.tsx +11 -12
- 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 +11 -11
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- 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/drag-overlay-drop-animation.ts +2 -2
- package/src/shared/test/column-policy.test.ts +215 -0
- package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
- package/src/shared/use-item-exit-animation.ts +1 -3
- package/CHANGELOG.md +0 -93
- 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,193 +1,213 @@
|
|
|
1
|
-
// packages/grid/src/shared/resize-handle.tsx
|
|
2
1
|
import { DndContext, useDraggable } from "@dnd-kit/core";
|
|
3
2
|
import clsx from "clsx";
|
|
4
3
|
import { useCallback, useEffect, useRef } from "@wordpress/element";
|
|
5
4
|
import { useMergeRefs, useThrottle } from "@wordpress/compose";
|
|
6
|
-
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
// packages/style-runtime/src/index.ts
|
|
8
|
-
|
|
7
|
+
const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
8
|
+
/**
|
|
9
|
+
* Returns the shared style runtime registry.
|
|
10
|
+
*
|
|
11
|
+
* The registry is stored on `globalThis` so separately bundled copies of this
|
|
12
|
+
* package can coordinate through the same document and style maps.
|
|
13
|
+
*
|
|
14
|
+
* @return The shared runtime registry.
|
|
15
|
+
*/
|
|
9
16
|
function getRuntime() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof document !== "undefined") {
|
|
20
|
-
registerDocument(document);
|
|
21
|
-
}
|
|
22
|
-
return globalScope.__wpStyleRuntime;
|
|
17
|
+
const globalScope = globalThis;
|
|
18
|
+
if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
|
|
19
|
+
globalScope.__wpStyleRuntime = {
|
|
20
|
+
documents: /* @__PURE__ */ new Map(),
|
|
21
|
+
styles: /* @__PURE__ */ new Map(),
|
|
22
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
23
|
+
};
|
|
24
|
+
if (typeof document !== "undefined") registerDocument(document);
|
|
25
|
+
return globalScope.__wpStyleRuntime;
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether a document already contains a style tag for a hash.
|
|
29
|
+
*
|
|
30
|
+
* @param targetDocument Document to inspect.
|
|
31
|
+
* @param hash Stable hash for the transformed CSS.
|
|
32
|
+
*
|
|
33
|
+
* @return Whether the style hash already exists in the document.
|
|
34
|
+
*/
|
|
24
35
|
function documentContainsStyleHash(targetDocument, hash) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const style of targetDocument.head.querySelectorAll(
|
|
29
|
-
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
30
|
-
)) {
|
|
31
|
-
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
+
if (!targetDocument.head) return false;
|
|
37
|
+
for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
|
|
38
|
+
return false;
|
|
36
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Injects a registered style into a document, unless that document already
|
|
42
|
+
* contains a style tag for the same hash.
|
|
43
|
+
*
|
|
44
|
+
* @param targetDocument Document to inject the style into.
|
|
45
|
+
* @param hash Stable hash for the transformed CSS.
|
|
46
|
+
* @param css CSS text to inject.
|
|
47
|
+
*/
|
|
37
48
|
function injectStyle(targetDocument, hash, css) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
56
|
-
style.appendChild(targetDocument.createTextNode(css));
|
|
57
|
-
targetDocument.head.appendChild(style);
|
|
58
|
-
injectedStyles.add(hash);
|
|
49
|
+
if (!targetDocument.head) return;
|
|
50
|
+
const runtime = getRuntime();
|
|
51
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
52
|
+
if (!injectedStyles) {
|
|
53
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
54
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
55
|
+
}
|
|
56
|
+
if (injectedStyles.has(hash)) return;
|
|
57
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
58
|
+
injectedStyles.add(hash);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const style = targetDocument.createElement("style");
|
|
62
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
63
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
64
|
+
targetDocument.head.appendChild(style);
|
|
65
|
+
injectedStyles.add(hash);
|
|
59
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Registers a document as a style injection target.
|
|
69
|
+
*
|
|
70
|
+
* Existing registered styles are replayed into the document immediately.
|
|
71
|
+
* Documents are reference-counted so multiple providers can safely register the
|
|
72
|
+
* same document without one cleanup removing it while another registration is
|
|
73
|
+
* still active.
|
|
74
|
+
*
|
|
75
|
+
* @param targetDocument Document to receive registered styles.
|
|
76
|
+
* @return Cleanup function that unregisters this document registration.
|
|
77
|
+
*/
|
|
60
78
|
function registerDocument(targetDocument) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (count <= 1) {
|
|
75
|
-
runtime.documents.delete(targetDocument);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
runtime.documents.set(targetDocument, count - 1);
|
|
79
|
-
};
|
|
79
|
+
const runtime = getRuntime();
|
|
80
|
+
runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
|
|
81
|
+
for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
|
|
82
|
+
return () => {
|
|
83
|
+
const count = runtime.documents.get(targetDocument);
|
|
84
|
+
if (count === void 0) return;
|
|
85
|
+
if (count <= 1) {
|
|
86
|
+
runtime.documents.delete(targetDocument);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
90
|
+
};
|
|
80
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Registers a style and injects it into all registered documents.
|
|
94
|
+
*
|
|
95
|
+
* The hash is used as the deduplication key, so calling this repeatedly with
|
|
96
|
+
* the same hash will not add duplicate style tags to a document.
|
|
97
|
+
* Registered styles are retained for the lifetime of the page so they can be
|
|
98
|
+
* replayed into documents that are registered later.
|
|
99
|
+
*
|
|
100
|
+
* @param hash Stable hash for the transformed CSS.
|
|
101
|
+
* @param css CSS text to inject.
|
|
102
|
+
*/
|
|
81
103
|
function registerStyle(hash, css) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
injectStyle(targetDocument, hash, css);
|
|
86
|
-
}
|
|
104
|
+
const runtime = getRuntime();
|
|
105
|
+
runtime.styles.set(hash, css);
|
|
106
|
+
for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
|
|
87
107
|
}
|
|
88
|
-
|
|
89
108
|
// packages/grid/src/shared/resize-handle.module.css
|
|
90
|
-
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("a268367938", ".ec44a4f547abd05b__resize-handle-slot{opacity:1}@media (prefers-reduced-motion:no-preference){.ec44a4f547abd05b__resize-handle-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-dragging] .ec44a4f547abd05b__resize-handle-slot,[data-wp-grid-resizing] .ec44a4f547abd05b__resize-handle-slot{opacity:0;pointer-events:none}[data-wp-grid-resizing]\n[data-wp-grid-item-resizing]\n.ec44a4f547abd05b__resize-handle-slot{opacity:1;pointer-events:auto}.ce3becd091879c6c__resize-handle{border-block-end:12px solid var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-inline-start:12px solid transparent;bottom:0;cursor:nwse-resize;height:0;inset-inline-end:0;position:absolute;width:0;z-index:1}.a498ea47859f08fc__is-horizontal-only{align-items:center;background:transparent;border-style:none;bottom:auto;cursor:ew-resize;display:flex;height:40px;justify-content:center;top:50%;transform:translateY(-50%);width:16px}.a498ea47859f08fc__is-horizontal-only:before{background-color:var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-radius:2px;content:\"\";height:24px;width:4px}@media (forced-colors:active){.a498ea47859f08fc__is-horizontal-only:before{background-color:Highlight}}");
|
|
110
|
+
var resize_handle_module_default = {
|
|
111
|
+
"resize-handle-slot": "ec44a4f547abd05b__resize-handle-slot",
|
|
112
|
+
"resize-handle": "ce3becd091879c6c__resize-handle",
|
|
113
|
+
"is-horizontal-only": "a498ea47859f08fc__is-horizontal-only"
|
|
114
|
+
};
|
|
95
115
|
// packages/grid/src/shared/resize-handle.tsx
|
|
96
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Sets `document.documentElement.style.cursor` for the duration of a drag
|
|
118
|
+
* and restores it on cleanup. Lives outside the component so cursor writes
|
|
119
|
+
* are not analyzed as mutating values derived from refs in the component
|
|
120
|
+
* body (react-hooks/immutability).
|
|
121
|
+
*
|
|
122
|
+
* @param getDocument Returns the document whose root element should receive
|
|
123
|
+
* the cursor (handle owner, or global `document`).
|
|
124
|
+
* @param cursor CSS cursor value while active.
|
|
125
|
+
* @return Cleanup that restores the previous cursor.
|
|
126
|
+
*/
|
|
97
127
|
function lockDocumentCursorWhileActive(getDocument, cursor) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
const root = getDocument().documentElement;
|
|
129
|
+
const previous = root.style.cursor;
|
|
130
|
+
root.style.cursor = cursor;
|
|
131
|
+
return () => {
|
|
132
|
+
root.style.cursor = previous;
|
|
133
|
+
};
|
|
104
134
|
}
|
|
105
|
-
function ResizeHandle({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
ref: mergedRef,
|
|
135
|
-
listeners,
|
|
136
|
-
attributes,
|
|
137
|
-
verticalResizable,
|
|
138
|
-
isResizing: isDragging,
|
|
139
|
-
itemId
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
return /* @__PURE__ */ jsx(
|
|
144
|
-
"div",
|
|
145
|
-
{
|
|
146
|
-
ref: mergedRef,
|
|
147
|
-
className: clsx(
|
|
148
|
-
resize_handle_default["resize-handle"],
|
|
149
|
-
!verticalResizable && resize_handle_default["is-horizontal-only"]
|
|
150
|
-
),
|
|
151
|
-
...listeners,
|
|
152
|
-
...attributes
|
|
153
|
-
}
|
|
154
|
-
);
|
|
135
|
+
function ResizeHandle({ itemId, verticalResizable = true, renderResizeHandle }) {
|
|
136
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
137
|
+
id: "draggable",
|
|
138
|
+
data: { itemId }
|
|
139
|
+
});
|
|
140
|
+
const ownerDocumentRef = useRef(null);
|
|
141
|
+
const setOwnerDocumentRef = useCallback((node) => {
|
|
142
|
+
ownerDocumentRef.current = node?.ownerDocument ?? null;
|
|
143
|
+
}, []);
|
|
144
|
+
const mergedRef = useMergeRefs([setOwnerDocumentRef, setNodeRef]);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!isDragging) return;
|
|
147
|
+
return lockDocumentCursorWhileActive(() => ownerDocumentRef.current ?? document, verticalResizable ? "nwse-resize" : "ew-resize");
|
|
148
|
+
}, [isDragging, verticalResizable]);
|
|
149
|
+
if (renderResizeHandle) return /* @__PURE__ */ jsx(renderResizeHandle, {
|
|
150
|
+
ref: mergedRef,
|
|
151
|
+
listeners,
|
|
152
|
+
attributes,
|
|
153
|
+
verticalResizable,
|
|
154
|
+
isResizing: isDragging,
|
|
155
|
+
itemId
|
|
156
|
+
});
|
|
157
|
+
return /* @__PURE__ */ jsx("div", {
|
|
158
|
+
ref: mergedRef,
|
|
159
|
+
className: clsx(resize_handle_module_default["resize-handle"], !verticalResizable && resize_handle_module_default["is-horizontal-only"]),
|
|
160
|
+
...listeners,
|
|
161
|
+
...attributes
|
|
162
|
+
});
|
|
155
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Renders a corner resize handle inside an isolated `<DndContext>`.
|
|
166
|
+
* Reports the cursor offset since the gesture started (in pixels)
|
|
167
|
+
* via `onResize`, throttled to one animation frame so the grid
|
|
168
|
+
* commit loop runs at most once per paint.
|
|
169
|
+
*
|
|
170
|
+
* Auto-scroll is enabled with a tight trigger zone and a low
|
|
171
|
+
* acceleration so a resize gesture near the viewport edge scrolls
|
|
172
|
+
* the page only when the user deliberately pushes against the very
|
|
173
|
+
* edge, and even then at a pace the user can interrupt by releasing.
|
|
174
|
+
* Default tuning would otherwise produce a runaway loop where the
|
|
175
|
+
* page scrolls fast, dnd-kit's document-coordinate `delta` inflates
|
|
176
|
+
* with the scroll, and the tile keeps growing without further user
|
|
177
|
+
* input.
|
|
178
|
+
*
|
|
179
|
+
* @param props Component props.
|
|
180
|
+
*/
|
|
156
181
|
function ResizeHandleWrapper(props) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
onDragEnd: handleDragEnd,
|
|
186
|
-
children: /* @__PURE__ */ jsx("div", { className: resize_handle_default["resize-handle-slot"], children: /* @__PURE__ */ jsx(ResizeHandle, { ...props }) })
|
|
187
|
-
}
|
|
188
|
-
);
|
|
182
|
+
const throttledResize = useThrottle((delta) => {
|
|
183
|
+
if (props.onResize) props.onResize(delta);
|
|
184
|
+
}, 16);
|
|
185
|
+
const handleDragMove = (event) => {
|
|
186
|
+
if (event.active.id !== "draggable") return;
|
|
187
|
+
throttledResize({
|
|
188
|
+
width: event.delta.x,
|
|
189
|
+
height: event.delta.y
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const handleDragEnd = () => {
|
|
193
|
+
if (props.onResizeEnd) props.onResizeEnd();
|
|
194
|
+
};
|
|
195
|
+
return /* @__PURE__ */ jsx(DndContext, {
|
|
196
|
+
autoScroll: {
|
|
197
|
+
threshold: {
|
|
198
|
+
x: .005,
|
|
199
|
+
y: .005
|
|
200
|
+
},
|
|
201
|
+
acceleration: 1
|
|
202
|
+
},
|
|
203
|
+
onDragMove: handleDragMove,
|
|
204
|
+
onDragEnd: handleDragEnd,
|
|
205
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
206
|
+
className: resize_handle_module_default["resize-handle-slot"],
|
|
207
|
+
children: /* @__PURE__ */ jsx(ResizeHandle, { ...props })
|
|
208
|
+
})
|
|
209
|
+
});
|
|
189
210
|
}
|
|
190
|
-
export {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
//# sourceMappingURL=resize-handle.mjs.map
|
|
211
|
+
export { ResizeHandleWrapper as default };
|
|
212
|
+
|
|
213
|
+
//# sourceMappingURL=resize-handle.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/shared/resize-handle.tsx", "../../../style-runtime/src/index.ts", "../../src/shared/resize-handle.module.css"],
|
|
4
|
-
"sourcesContent": ["import { DndContext, useDraggable } from '@dnd-kit/core';\nimport type { DragMoveEvent } from '@dnd-kit/core';\nimport clsx from 'clsx';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMergeRefs, useThrottle } from '@wordpress/compose';\nimport type { ResizeDelta, ResizeHandleProps } from './types';\nimport styles from './resize-handle.module.css';\n\n/**\n * Sets `document.documentElement.style.cursor` for the duration of a drag\n * and restores it on cleanup. Lives outside the component so cursor writes\n * are not analyzed as mutating values derived from refs in the component\n * body (react-hooks/immutability).\n *\n * @param getDocument Returns the document whose root element should receive\n * the cursor (handle owner, or global `document`).\n * @param cursor CSS cursor value while active.\n * @return Cleanup that restores the previous cursor.\n */\nfunction lockDocumentCursorWhileActive(\n\tgetDocument: () => Document,\n\tcursor: string\n): () => void {\n\tconst root = getDocument().documentElement;\n\tconst previous = root.style.cursor;\n\troot.style.cursor = cursor;\n\treturn () => {\n\t\troot.style.cursor = previous;\n\t};\n}\n\nfunction ResizeHandle( {\n\titemId,\n\tverticalResizable = true,\n\trenderResizeHandle,\n}: ResizeHandleProps ) {\n\tconst { attributes, listeners, setNodeRef, isDragging } = useDraggable( {\n\t\tid: 'draggable',\n\t\tdata: { itemId },\n\t} );\n\n\t// Snapshot owner document on mount/update via ref callback so the\n\t// cursor-lock effect can resolve the correct document in an iframe.\n\tconst ownerDocumentRef = useRef< Document | null >( null );\n\tconst setOwnerDocumentRef = useCallback( ( node: HTMLElement | null ) => {\n\t\townerDocumentRef.current = node?.ownerDocument ?? null;\n\t}, [] );\n\tconst mergedRef = useMergeRefs( [ setOwnerDocumentRef, setNodeRef ] );\n\n\t// Lock the document cursor while the gesture is active. Without\n\t// this, the OS pointer reverts to the default arrow as soon as it\n\t// leaves the handle's hit area, even though the resize is still\n\t// in progress.\n\tuseEffect( () => {\n\t\tif ( ! isDragging ) {\n\t\t\treturn;\n\t\t}\n\t\tconst cursor = verticalResizable ? 'nwse-resize' : 'ew-resize';\n\t\treturn lockDocumentCursorWhileActive(\n\t\t\t() => ownerDocumentRef.current ?? document,\n\t\t\tcursor\n\t\t);\n\t}, [ isDragging, verticalResizable ] );\n\n\tif ( renderResizeHandle ) {\n\t\tconst RenderResizeHandle = renderResizeHandle;\n\t\treturn (\n\t\t\t<RenderResizeHandle\n\t\t\t\tref={ mergedRef }\n\t\t\t\tlisteners={ listeners }\n\t\t\t\tattributes={ attributes }\n\t\t\t\tverticalResizable={ verticalResizable }\n\t\t\t\tisResizing={ isDragging }\n\t\t\t\titemId={ itemId }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ mergedRef }\n\t\t\tclassName={ clsx(\n\t\t\t\tstyles[ 'resize-handle' ],\n\t\t\t\t! verticalResizable && styles[ 'is-horizontal-only' ]\n\t\t\t) }\n\t\t\t{ ...listeners }\n\t\t\t{ ...attributes }\n\t\t/>\n\t);\n}\n\n/**\n * Renders a corner resize handle inside an isolated `<DndContext>`.\n * Reports the cursor offset since the gesture started (in pixels)\n * via `onResize`, throttled to one animation frame so the grid\n * commit loop runs at most once per paint.\n *\n * Auto-scroll is enabled with a tight trigger zone and a low\n * acceleration so a resize gesture near the viewport edge scrolls\n * the page only when the user deliberately pushes against the very\n * edge, and even then at a pace the user can interrupt by releasing.\n * Default tuning would otherwise produce a runaway loop where the\n * page scrolls fast, dnd-kit's document-coordinate `delta` inflates\n * with the scroll, and the tile keeps growing without further user\n * input.\n *\n * @param props Component props.\n */\nexport default function ResizeHandleWrapper( props: ResizeHandleProps ) {\n\tconst throttleDelay = 16;\n\tconst throttledResize = useThrottle( ( delta: ResizeDelta ) => {\n\t\tif ( props.onResize ) {\n\t\t\tprops.onResize( delta );\n\t\t}\n\t}, throttleDelay );\n\n\t// `event.delta` is the cursor offset from the gesture start —\n\t// not from the handle's current position — so it stays stable\n\t// even when the tile (and therefore the handle) jumps a column.\n\t// The grid's resize logic snapshots the start width and adds\n\t// `delta`, so the two must share the same frame of reference.\n\tconst handleDragMove = ( event: DragMoveEvent ) => {\n\t\tif ( event.active.id !== 'draggable' ) {\n\t\t\treturn;\n\t\t}\n\t\tthrottledResize( {\n\t\t\twidth: event.delta.x,\n\t\t\theight: event.delta.y,\n\t\t} );\n\t};\n\n\tconst handleDragEnd = () => {\n\t\tif ( props.onResizeEnd ) {\n\t\t\tprops.onResizeEnd();\n\t\t}\n\t};\n\n\treturn (\n\t\t<DndContext\n\t\t\tautoScroll={ {\n\t\t\t\tthreshold: { x: 0.005, y: 0.005 },\n\t\t\t\tacceleration: 1,\n\t\t\t} }\n\t\t\tonDragMove={ handleDragMove }\n\t\t\tonDragEnd={ handleDragEnd }\n\t\t>\n\t\t\t<div className={ styles[ 'resize-handle-slot' ] }>\n\t\t\t\t<ResizeHandle { ...props } />\n\t\t\t</div>\n\t\t</DndContext>\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(\"13645360b3\", \"._91523dc3a37aecb8__resize-handle-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._91523dc3a37aecb8__resize-handle-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-dragging] ._91523dc3a37aecb8__resize-handle-slot,[data-wp-grid-resizing] ._91523dc3a37aecb8__resize-handle-slot{opacity:0;pointer-events:none}[data-wp-grid-resizing]\\n[data-wp-grid-item-resizing]\\n._91523dc3a37aecb8__resize-handle-slot{opacity:1;pointer-events:auto}._4da787f72dc00d8b__resize-handle{border-block-end:12px solid var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-inline-start:12px solid transparent;bottom:0;cursor:nwse-resize;height:0;inset-inline-end:0;position:absolute;width:0;z-index:1}._885412b44a137da0__is-horizontal-only{align-items:center;background:transparent;border-style:none;bottom:auto;cursor:ew-resize;display:flex;height:40px;justify-content:center;top:50%;transform:translateY(-50%);width:16px}._885412b44a137da0__is-horizontal-only:before{background-color:var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-radius:2px;content:\\\"\\\";height:24px;width:4px}@media (forced-colors:active){._885412b44a137da0__is-horizontal-only:before{background-color:Highlight}}\");\n}\nexport default {\"resize-handle-slot\":\"_91523dc3a37aecb8__resize-handle-slot\",\"resize-handle\":\"_4da787f72dc00d8b__resize-handle\",\"is-horizontal-only\":\"_885412b44a137da0__is-horizontal-only\"};\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY,oBAAoB;AAEzC,OAAO,UAAU;AACjB,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,cAAc,mBAAmB;;;ACM1C,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACrB,QAAM,c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AAA,MACA,YAAa;AAAA,MACb,WAAY;AAAA,MAEZ,8BAAC,SAAI,WAAY,sBAAQ,oBAAqB,GAC7C,8BAAC,gBAAe,GAAG,OAAQ,GAC5B;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"resize-handle.mjs","names":["RenderResizeHandle","styles"],"sources":["../../../style-runtime/src/index.ts","../../src/shared/resize-handle.module.css","../../src/shared/resize-handle.tsx"],"sourcesContent":["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(\"a268367938\", \".ec44a4f547abd05b__resize-handle-slot{opacity:1}@media (prefers-reduced-motion:no-preference){.ec44a4f547abd05b__resize-handle-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-dragging] .ec44a4f547abd05b__resize-handle-slot,[data-wp-grid-resizing] .ec44a4f547abd05b__resize-handle-slot{opacity:0;pointer-events:none}[data-wp-grid-resizing]\\n[data-wp-grid-item-resizing]\\n.ec44a4f547abd05b__resize-handle-slot{opacity:1;pointer-events:auto}.ce3becd091879c6c__resize-handle{border-block-end:12px solid var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-inline-start:12px solid transparent;bottom:0;cursor:nwse-resize;height:0;inset-inline-end:0;position:absolute;width:0;z-index:1}.a498ea47859f08fc__is-horizontal-only{align-items:center;background:transparent;border-style:none;bottom:auto;cursor:ew-resize;display:flex;height:40px;justify-content:center;top:50%;transform:translateY(-50%);width:16px}.a498ea47859f08fc__is-horizontal-only:before{background-color:var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-radius:2px;content:\\\"\\\";height:24px;width:4px}@media (forced-colors:active){.a498ea47859f08fc__is-horizontal-only:before{background-color:Highlight}}\");\n}\nexport default {\"resize-handle-slot\":\"ec44a4f547abd05b__resize-handle-slot\",\"resize-handle\":\"ce3becd091879c6c__resize-handle\",\"is-horizontal-only\":\"a498ea47859f08fc__is-horizontal-only\"};\n","import { DndContext, useDraggable } from '@dnd-kit/core';\nimport type { DragMoveEvent } from '@dnd-kit/core';\nimport clsx from 'clsx';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMergeRefs, useThrottle } from '@wordpress/compose';\nimport type { ResizeDelta, ResizeHandleProps } from './types';\nimport styles from './resize-handle.module.css';\n\n/**\n * Sets `document.documentElement.style.cursor` for the duration of a drag\n * and restores it on cleanup. Lives outside the component so cursor writes\n * are not analyzed as mutating values derived from refs in the component\n * body (react-hooks/immutability).\n *\n * @param getDocument Returns the document whose root element should receive\n * the cursor (handle owner, or global `document`).\n * @param cursor CSS cursor value while active.\n * @return Cleanup that restores the previous cursor.\n */\nfunction lockDocumentCursorWhileActive(\n\tgetDocument: () => Document,\n\tcursor: string\n): () => void {\n\tconst root = getDocument().documentElement;\n\tconst previous = root.style.cursor;\n\troot.style.cursor = cursor;\n\treturn () => {\n\t\troot.style.cursor = previous;\n\t};\n}\n\nfunction ResizeHandle( {\n\titemId,\n\tverticalResizable = true,\n\trenderResizeHandle,\n}: ResizeHandleProps ) {\n\tconst { attributes, listeners, setNodeRef, isDragging } = useDraggable( {\n\t\tid: 'draggable',\n\t\tdata: { itemId },\n\t} );\n\n\t// Snapshot owner document on mount/update via ref callback so the\n\t// cursor-lock effect can resolve the correct document in an iframe.\n\tconst ownerDocumentRef = useRef< Document | null >( null );\n\tconst setOwnerDocumentRef = useCallback( ( node: HTMLElement | null ) => {\n\t\townerDocumentRef.current = node?.ownerDocument ?? null;\n\t}, [] );\n\tconst mergedRef = useMergeRefs( [ setOwnerDocumentRef, setNodeRef ] );\n\n\t// Lock the document cursor while the gesture is active. Without\n\t// this, the OS pointer reverts to the default arrow as soon as it\n\t// leaves the handle's hit area, even though the resize is still\n\t// in progress.\n\tuseEffect( () => {\n\t\tif ( ! isDragging ) {\n\t\t\treturn;\n\t\t}\n\t\tconst cursor = verticalResizable ? 'nwse-resize' : 'ew-resize';\n\t\treturn lockDocumentCursorWhileActive(\n\t\t\t() => ownerDocumentRef.current ?? document,\n\t\t\tcursor\n\t\t);\n\t}, [ isDragging, verticalResizable ] );\n\n\tif ( renderResizeHandle ) {\n\t\tconst RenderResizeHandle = renderResizeHandle;\n\t\treturn (\n\t\t\t<RenderResizeHandle\n\t\t\t\tref={ mergedRef }\n\t\t\t\tlisteners={ listeners }\n\t\t\t\tattributes={ attributes }\n\t\t\t\tverticalResizable={ verticalResizable }\n\t\t\t\tisResizing={ isDragging }\n\t\t\t\titemId={ itemId }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ mergedRef }\n\t\t\tclassName={ clsx(\n\t\t\t\tstyles[ 'resize-handle' ],\n\t\t\t\t! verticalResizable && styles[ 'is-horizontal-only' ]\n\t\t\t) }\n\t\t\t{ ...listeners }\n\t\t\t{ ...attributes }\n\t\t/>\n\t);\n}\n\n/**\n * Renders a corner resize handle inside an isolated `<DndContext>`.\n * Reports the cursor offset since the gesture started (in pixels)\n * via `onResize`, throttled to one animation frame so the grid\n * commit loop runs at most once per paint.\n *\n * Auto-scroll is enabled with a tight trigger zone and a low\n * acceleration so a resize gesture near the viewport edge scrolls\n * the page only when the user deliberately pushes against the very\n * edge, and even then at a pace the user can interrupt by releasing.\n * Default tuning would otherwise produce a runaway loop where the\n * page scrolls fast, dnd-kit's document-coordinate `delta` inflates\n * with the scroll, and the tile keeps growing without further user\n * input.\n *\n * @param props Component props.\n */\nexport default function ResizeHandleWrapper( props: ResizeHandleProps ) {\n\tconst throttleDelay = 16;\n\tconst throttledResize = useThrottle( ( delta: ResizeDelta ) => {\n\t\tif ( props.onResize ) {\n\t\t\tprops.onResize( delta );\n\t\t}\n\t}, throttleDelay );\n\n\t// `event.delta` is the cursor offset from the gesture start —\n\t// not from the handle's current position — so it stays stable\n\t// even when the tile (and therefore the handle) jumps a column.\n\t// The grid's resize logic snapshots the start width and adds\n\t// `delta`, so the two must share the same frame of reference.\n\tconst handleDragMove = ( event: DragMoveEvent ) => {\n\t\tif ( event.active.id !== 'draggable' ) {\n\t\t\treturn;\n\t\t}\n\t\tthrottledResize( {\n\t\t\twidth: event.delta.x,\n\t\t\theight: event.delta.y,\n\t\t} );\n\t};\n\n\tconst handleDragEnd = () => {\n\t\tif ( props.onResizeEnd ) {\n\t\t\tprops.onResizeEnd();\n\t\t}\n\t};\n\n\treturn (\n\t\t<DndContext\n\t\t\tautoScroll={ {\n\t\t\t\tthreshold: { x: 0.005, y: 0.005 },\n\t\t\t\tacceleration: 1,\n\t\t\t} }\n\t\t\tonDragMove={ handleDragMove }\n\t\t\tonDragEnd={ handleDragEnd }\n\t\t>\n\t\t\t<div className={ styles[ 'resize-handle-slot' ] }>\n\t\t\t\t<ResizeHandle { ...props } />\n\t\t\t</div>\n\t\t</DndContext>\n\t);\n}\n"],"mappings":";;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO,aAAa,aACxB,iBAAkB,QAAS;CAG5B,OAAO,YAAY;AACpB;;;;;;;;;AAUA,SAAS,0BACR,gBACA,MACU;CACV,IAAK,CAAE,eAAe,MACrB,OAAO;CAGR,KAAM,MAAM,SAAS,eAAe,KAAK,iBACxC,SAAU,qBAAsB,EACjC,GACC,IAAK,MAAM,aAAc,oB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