@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.
Files changed (116) hide show
  1. package/README.md +35 -14
  2. package/build/dashboard-grid/grid-item.cjs +232 -295
  3. package/build/dashboard-grid/grid-item.cjs.map +1 -7
  4. package/build/dashboard-grid/index.cjs +526 -633
  5. package/build/dashboard-grid/index.cjs.map +1 -7
  6. package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
  7. package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
  8. package/build/dashboard-grid/types.cjs +4 -18
  9. package/build/dashboard-lanes/index.cjs +495 -577
  10. package/build/dashboard-lanes/index.cjs.map +1 -7
  11. package/build/dashboard-lanes/lane-placement.cjs +77 -100
  12. package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
  13. package/build/dashboard-lanes/lanes-item.cjs +222 -278
  14. package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
  15. package/build/dashboard-lanes/types.cjs +4 -18
  16. package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
  17. package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
  18. package/build/index.cjs +16 -31
  19. package/build/shared/array-move-with-pinned.cjs +29 -45
  20. package/build/shared/array-move-with-pinned.cjs.map +1 -7
  21. package/build/shared/column-policy.cjs +58 -0
  22. package/build/shared/column-policy.cjs.map +1 -0
  23. package/build/shared/drag-overlay-drop-animation.cjs +40 -66
  24. package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
  25. package/build/shared/grid-item-key.cjs +12 -29
  26. package/build/shared/grid-item-key.cjs.map +1 -7
  27. package/build/shared/grid-overlay.cjs +163 -164
  28. package/build/shared/grid-overlay.cjs.map +1 -7
  29. package/build/shared/item-exit-overlay.cjs +132 -134
  30. package/build/shared/item-exit-overlay.cjs.map +1 -7
  31. package/build/shared/resize-handle.cjs +213 -197
  32. package/build/shared/resize-handle.cjs.map +1 -7
  33. package/build/shared/resize-snap.cjs +116 -121
  34. package/build/shared/resize-snap.cjs.map +1 -7
  35. package/build/shared/types.cjs +4 -18
  36. package/build/shared/use-item-exit-animation.cjs +96 -143
  37. package/build/shared/use-item-exit-animation.cjs.map +1 -7
  38. package/build/shared/use-layout-shift-animation.cjs +121 -150
  39. package/build/shared/use-layout-shift-animation.cjs.map +1 -7
  40. package/build/shared/use-span-bounds.cjs +65 -79
  41. package/build/shared/use-span-bounds.cjs.map +1 -7
  42. package/build-module/dashboard-grid/grid-item.mjs +209 -265
  43. package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
  44. package/build-module/dashboard-grid/index.mjs +502 -623
  45. package/build-module/dashboard-grid/index.mjs.map +1 -7
  46. package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
  47. package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
  48. package/build-module/dashboard-grid/types.mjs +0 -1
  49. package/build-module/dashboard-lanes/index.mjs +470 -567
  50. package/build-module/dashboard-lanes/index.mjs.map +1 -7
  51. package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
  52. package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
  53. package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
  54. package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
  55. package/build-module/dashboard-lanes/types.mjs +0 -1
  56. package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
  57. package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
  58. package/build-module/index.mjs +1 -6
  59. package/build-module/shared/array-move-with-pinned.mjs +25 -21
  60. package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
  61. package/build-module/shared/column-policy.mjs +52 -0
  62. package/build-module/shared/column-policy.mjs.map +1 -0
  63. package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
  64. package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
  65. package/build-module/shared/grid-item-key.mjs +8 -5
  66. package/build-module/shared/grid-item-key.mjs.map +1 -7
  67. package/build-module/shared/grid-overlay.mjs +143 -136
  68. package/build-module/shared/grid-overlay.mjs.map +1 -7
  69. package/build-module/shared/item-exit-overlay.mjs +128 -110
  70. package/build-module/shared/item-exit-overlay.mjs.map +1 -7
  71. package/build-module/shared/resize-handle.mjs +191 -171
  72. package/build-module/shared/resize-handle.mjs.map +1 -7
  73. package/build-module/shared/resize-snap.mjs +108 -93
  74. package/build-module/shared/resize-snap.mjs.map +1 -7
  75. package/build-module/shared/types.mjs +0 -1
  76. package/build-module/shared/use-item-exit-animation.mjs +92 -124
  77. package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
  78. package/build-module/shared/use-layout-shift-animation.mjs +114 -123
  79. package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
  80. package/build-module/shared/use-span-bounds.mjs +60 -57
  81. package/build-module/shared/use-span-bounds.mjs.map +1 -7
  82. package/build-types/dashboard-grid/index.d.ts.map +1 -1
  83. package/build-types/dashboard-grid/types.d.ts +9 -5
  84. package/build-types/dashboard-grid/types.d.ts.map +1 -1
  85. package/build-types/dashboard-lanes/index.d.ts.map +1 -1
  86. package/build-types/dashboard-lanes/types.d.ts +9 -5
  87. package/build-types/dashboard-lanes/types.d.ts.map +1 -1
  88. package/build-types/index.d.ts +1 -0
  89. package/build-types/index.d.ts.map +1 -1
  90. package/build-types/shared/column-policy.d.ts +43 -0
  91. package/build-types/shared/column-policy.d.ts.map +1 -0
  92. package/package.json +14 -12
  93. package/src/dashboard-grid/grid-item.tsx +1 -1
  94. package/src/dashboard-grid/{grid.module.css → grid.module.scss} +10 -19
  95. package/src/dashboard-grid/index.tsx +12 -13
  96. package/src/dashboard-grid/stories/index.story.tsx +129 -50
  97. package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
  98. package/src/dashboard-grid/types.ts +9 -5
  99. package/src/dashboard-lanes/index.tsx +13 -13
  100. package/src/dashboard-lanes/lanes-item.tsx +1 -1
  101. package/src/dashboard-lanes/{lanes.module.css → lanes.module.scss} +10 -19
  102. package/src/dashboard-lanes/stories/index.story.tsx +124 -28
  103. package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
  104. package/src/dashboard-lanes/types.ts +9 -5
  105. package/src/index.ts +1 -0
  106. package/src/shared/column-policy.ts +100 -0
  107. package/src/shared/test/column-policy.test.ts +215 -0
  108. package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
  109. package/build/dashboard-grid/types.cjs.map +0 -7
  110. package/build/dashboard-lanes/types.cjs.map +0 -7
  111. package/build/index.cjs.map +0 -7
  112. package/build/shared/types.cjs.map +0 -7
  113. package/build-module/dashboard-grid/types.mjs.map +0 -7
  114. package/build-module/dashboard-lanes/types.mjs.map +0 -7
  115. package/build-module/index.mjs.map +0 -7
  116. package/build-module/shared/types.mjs.map +0 -7
@@ -1,224 +1,240 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
13
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
19
22
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // packages/grid/src/shared/resize-handle.tsx
31
- var resize_handle_exports = {};
32
- __export(resize_handle_exports, {
33
- default: () => ResizeHandleWrapper
34
- });
35
- module.exports = __toCommonJS(resize_handle_exports);
36
- var import_core = require("@dnd-kit/core");
37
- var import_clsx = __toESM(require("clsx"));
38
- var import_element = require("@wordpress/element");
39
- var import_compose = require("@wordpress/compose");
40
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _dnd_kit_core = require("@dnd-kit/core");
28
+ let clsx = require("clsx");
29
+ clsx = __toESM(clsx);
30
+ let _wordpress_element = require("@wordpress/element");
31
+ let _wordpress_compose = require("@wordpress/compose");
32
+ let react_jsx_runtime = require("react/jsx-runtime");
41
33
  // packages/style-runtime/src/index.ts
42
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
34
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
35
+ /**
36
+ * Returns the shared style runtime registry.
37
+ *
38
+ * The registry is stored on `globalThis` so separately bundled copies of this
39
+ * package can coordinate through the same document and style maps.
40
+ *
41
+ * @return The shared runtime registry.
42
+ */
43
43
  function getRuntime() {
44
- const globalScope = globalThis;
45
- if (globalScope.__wpStyleRuntime) {
46
- return globalScope.__wpStyleRuntime;
47
- }
48
- globalScope.__wpStyleRuntime = {
49
- documents: /* @__PURE__ */ new Map(),
50
- styles: /* @__PURE__ */ new Map(),
51
- injectedStyles: /* @__PURE__ */ new WeakMap()
52
- };
53
- if (typeof document !== "undefined") {
54
- registerDocument(document);
55
- }
56
- return globalScope.__wpStyleRuntime;
44
+ const globalScope = globalThis;
45
+ if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
46
+ globalScope.__wpStyleRuntime = {
47
+ documents: /* @__PURE__ */ new Map(),
48
+ styles: /* @__PURE__ */ new Map(),
49
+ injectedStyles: /* @__PURE__ */ new WeakMap()
50
+ };
51
+ if (typeof document !== "undefined") registerDocument(document);
52
+ return globalScope.__wpStyleRuntime;
57
53
  }
54
+ /**
55
+ * Checks whether a document already contains a style tag for a hash.
56
+ *
57
+ * @param targetDocument Document to inspect.
58
+ * @param hash Stable hash for the transformed CSS.
59
+ *
60
+ * @return Whether the style hash already exists in the document.
61
+ */
58
62
  function documentContainsStyleHash(targetDocument, hash) {
59
- if (!targetDocument.head) {
60
- return false;
61
- }
62
- for (const style of targetDocument.head.querySelectorAll(
63
- `style[${STYLE_HASH_ATTRIBUTE}]`
64
- )) {
65
- if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
66
- return true;
67
- }
68
- }
69
- return false;
63
+ if (!targetDocument.head) return false;
64
+ for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
65
+ return false;
70
66
  }
67
+ /**
68
+ * Injects a registered style into a document, unless that document already
69
+ * contains a style tag for the same hash.
70
+ *
71
+ * @param targetDocument Document to inject the style into.
72
+ * @param hash Stable hash for the transformed CSS.
73
+ * @param css CSS text to inject.
74
+ */
71
75
  function injectStyle(targetDocument, hash, css) {
72
- if (!targetDocument.head) {
73
- return;
74
- }
75
- const runtime = getRuntime();
76
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
77
- if (!injectedStyles) {
78
- injectedStyles = /* @__PURE__ */ new Set();
79
- runtime.injectedStyles.set(targetDocument, injectedStyles);
80
- }
81
- if (injectedStyles.has(hash)) {
82
- return;
83
- }
84
- if (documentContainsStyleHash(targetDocument, hash)) {
85
- injectedStyles.add(hash);
86
- return;
87
- }
88
- const style = targetDocument.createElement("style");
89
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
90
- style.appendChild(targetDocument.createTextNode(css));
91
- targetDocument.head.appendChild(style);
92
- injectedStyles.add(hash);
76
+ if (!targetDocument.head) return;
77
+ const runtime = getRuntime();
78
+ let injectedStyles = runtime.injectedStyles.get(targetDocument);
79
+ if (!injectedStyles) {
80
+ injectedStyles = /* @__PURE__ */ new Set();
81
+ runtime.injectedStyles.set(targetDocument, injectedStyles);
82
+ }
83
+ if (injectedStyles.has(hash)) return;
84
+ if (documentContainsStyleHash(targetDocument, hash)) {
85
+ injectedStyles.add(hash);
86
+ return;
87
+ }
88
+ const style = targetDocument.createElement("style");
89
+ style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
90
+ style.appendChild(targetDocument.createTextNode(css));
91
+ targetDocument.head.appendChild(style);
92
+ injectedStyles.add(hash);
93
93
  }
94
+ /**
95
+ * Registers a document as a style injection target.
96
+ *
97
+ * Existing registered styles are replayed into the document immediately.
98
+ * Documents are reference-counted so multiple providers can safely register the
99
+ * same document without one cleanup removing it while another registration is
100
+ * still active.
101
+ *
102
+ * @param targetDocument Document to receive registered styles.
103
+ * @return Cleanup function that unregisters this document registration.
104
+ */
94
105
  function registerDocument(targetDocument) {
95
- const runtime = getRuntime();
96
- runtime.documents.set(
97
- targetDocument,
98
- (runtime.documents.get(targetDocument) ?? 0) + 1
99
- );
100
- for (const [hash, css] of runtime.styles) {
101
- injectStyle(targetDocument, hash, css);
102
- }
103
- return () => {
104
- const count = runtime.documents.get(targetDocument);
105
- if (count === void 0) {
106
- return;
107
- }
108
- if (count <= 1) {
109
- runtime.documents.delete(targetDocument);
110
- return;
111
- }
112
- runtime.documents.set(targetDocument, count - 1);
113
- };
106
+ const runtime = getRuntime();
107
+ runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
108
+ for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
109
+ return () => {
110
+ const count = runtime.documents.get(targetDocument);
111
+ if (count === void 0) return;
112
+ if (count <= 1) {
113
+ runtime.documents.delete(targetDocument);
114
+ return;
115
+ }
116
+ runtime.documents.set(targetDocument, count - 1);
117
+ };
114
118
  }
119
+ /**
120
+ * Registers a style and injects it into all registered documents.
121
+ *
122
+ * The hash is used as the deduplication key, so calling this repeatedly with
123
+ * the same hash will not add duplicate style tags to a document.
124
+ * Registered styles are retained for the lifetime of the page so they can be
125
+ * replayed into documents that are registered later.
126
+ *
127
+ * @param hash Stable hash for the transformed CSS.
128
+ * @param css CSS text to inject.
129
+ */
115
130
  function registerStyle(hash, css) {
116
- const runtime = getRuntime();
117
- runtime.styles.set(hash, css);
118
- for (const targetDocument of runtime.documents.keys()) {
119
- injectStyle(targetDocument, hash, css);
120
- }
131
+ const runtime = getRuntime();
132
+ runtime.styles.set(hash, css);
133
+ for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
121
134
  }
122
-
123
135
  // packages/grid/src/shared/resize-handle.module.css
124
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
125
- registerStyle("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}}');
126
- }
127
- var resize_handle_default = { "resize-handle-slot": "_91523dc3a37aecb8__resize-handle-slot", "resize-handle": "_4da787f72dc00d8b__resize-handle", "is-horizontal-only": "_885412b44a137da0__is-horizontal-only" };
128
-
136
+ 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}}");
137
+ var resize_handle_module_default = {
138
+ "resize-handle-slot": "ec44a4f547abd05b__resize-handle-slot",
139
+ "resize-handle": "ce3becd091879c6c__resize-handle",
140
+ "is-horizontal-only": "a498ea47859f08fc__is-horizontal-only"
141
+ };
129
142
  // packages/grid/src/shared/resize-handle.tsx
130
- var import_jsx_runtime = require("react/jsx-runtime");
143
+ /**
144
+ * Sets `document.documentElement.style.cursor` for the duration of a drag
145
+ * and restores it on cleanup. Lives outside the component so cursor writes
146
+ * are not analyzed as mutating values derived from refs in the component
147
+ * body (react-hooks/immutability).
148
+ *
149
+ * @param getDocument Returns the document whose root element should receive
150
+ * the cursor (handle owner, or global `document`).
151
+ * @param cursor CSS cursor value while active.
152
+ * @return Cleanup that restores the previous cursor.
153
+ */
131
154
  function lockDocumentCursorWhileActive(getDocument, cursor) {
132
- const root = getDocument().documentElement;
133
- const previous = root.style.cursor;
134
- root.style.cursor = cursor;
135
- return () => {
136
- root.style.cursor = previous;
137
- };
155
+ const root = getDocument().documentElement;
156
+ const previous = root.style.cursor;
157
+ root.style.cursor = cursor;
158
+ return () => {
159
+ root.style.cursor = previous;
160
+ };
138
161
  }
139
- function ResizeHandle({
140
- itemId,
141
- verticalResizable = true,
142
- renderResizeHandle
143
- }) {
144
- const { attributes, listeners, setNodeRef, isDragging } = (0, import_core.useDraggable)({
145
- id: "draggable",
146
- data: { itemId }
147
- });
148
- const ownerDocumentRef = (0, import_element.useRef)(null);
149
- const setOwnerDocumentRef = (0, import_element.useCallback)((node) => {
150
- ownerDocumentRef.current = node?.ownerDocument ?? null;
151
- }, []);
152
- const mergedRef = (0, import_compose.useMergeRefs)([setOwnerDocumentRef, setNodeRef]);
153
- (0, import_element.useEffect)(() => {
154
- if (!isDragging) {
155
- return;
156
- }
157
- const cursor = verticalResizable ? "nwse-resize" : "ew-resize";
158
- return lockDocumentCursorWhileActive(
159
- () => ownerDocumentRef.current ?? document,
160
- cursor
161
- );
162
- }, [isDragging, verticalResizable]);
163
- if (renderResizeHandle) {
164
- const RenderResizeHandle = renderResizeHandle;
165
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
166
- RenderResizeHandle,
167
- {
168
- ref: mergedRef,
169
- listeners,
170
- attributes,
171
- verticalResizable,
172
- isResizing: isDragging,
173
- itemId
174
- }
175
- );
176
- }
177
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
178
- "div",
179
- {
180
- ref: mergedRef,
181
- className: (0, import_clsx.default)(
182
- resize_handle_default["resize-handle"],
183
- !verticalResizable && resize_handle_default["is-horizontal-only"]
184
- ),
185
- ...listeners,
186
- ...attributes
187
- }
188
- );
162
+ function ResizeHandle({ itemId, verticalResizable = true, renderResizeHandle }) {
163
+ const { attributes, listeners, setNodeRef, isDragging } = (0, _dnd_kit_core.useDraggable)({
164
+ id: "draggable",
165
+ data: { itemId }
166
+ });
167
+ const ownerDocumentRef = (0, _wordpress_element.useRef)(null);
168
+ const setOwnerDocumentRef = (0, _wordpress_element.useCallback)((node) => {
169
+ ownerDocumentRef.current = node?.ownerDocument ?? null;
170
+ }, []);
171
+ const mergedRef = (0, _wordpress_compose.useMergeRefs)([setOwnerDocumentRef, setNodeRef]);
172
+ (0, _wordpress_element.useEffect)(() => {
173
+ if (!isDragging) return;
174
+ return lockDocumentCursorWhileActive(() => ownerDocumentRef.current ?? document, verticalResizable ? "nwse-resize" : "ew-resize");
175
+ }, [isDragging, verticalResizable]);
176
+ if (renderResizeHandle) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(renderResizeHandle, {
177
+ ref: mergedRef,
178
+ listeners,
179
+ attributes,
180
+ verticalResizable,
181
+ isResizing: isDragging,
182
+ itemId
183
+ });
184
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
185
+ ref: mergedRef,
186
+ className: (0, clsx.default)(resize_handle_module_default["resize-handle"], !verticalResizable && resize_handle_module_default["is-horizontal-only"]),
187
+ ...listeners,
188
+ ...attributes
189
+ });
189
190
  }
191
+ /**
192
+ * Renders a corner resize handle inside an isolated `<DndContext>`.
193
+ * Reports the cursor offset since the gesture started (in pixels)
194
+ * via `onResize`, throttled to one animation frame so the grid
195
+ * commit loop runs at most once per paint.
196
+ *
197
+ * Auto-scroll is enabled with a tight trigger zone and a low
198
+ * acceleration so a resize gesture near the viewport edge scrolls
199
+ * the page only when the user deliberately pushes against the very
200
+ * edge, and even then at a pace the user can interrupt by releasing.
201
+ * Default tuning would otherwise produce a runaway loop where the
202
+ * page scrolls fast, dnd-kit's document-coordinate `delta` inflates
203
+ * with the scroll, and the tile keeps growing without further user
204
+ * input.
205
+ *
206
+ * @param props Component props.
207
+ */
190
208
  function ResizeHandleWrapper(props) {
191
- const throttleDelay = 16;
192
- const throttledResize = (0, import_compose.useThrottle)((delta) => {
193
- if (props.onResize) {
194
- props.onResize(delta);
195
- }
196
- }, throttleDelay);
197
- const handleDragMove = (event) => {
198
- if (event.active.id !== "draggable") {
199
- return;
200
- }
201
- throttledResize({
202
- width: event.delta.x,
203
- height: event.delta.y
204
- });
205
- };
206
- const handleDragEnd = () => {
207
- if (props.onResizeEnd) {
208
- props.onResizeEnd();
209
- }
210
- };
211
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
212
- import_core.DndContext,
213
- {
214
- autoScroll: {
215
- threshold: { x: 5e-3, y: 5e-3 },
216
- acceleration: 1
217
- },
218
- onDragMove: handleDragMove,
219
- onDragEnd: handleDragEnd,
220
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: resize_handle_default["resize-handle-slot"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResizeHandle, { ...props }) })
221
- }
222
- );
209
+ const throttledResize = (0, _wordpress_compose.useThrottle)((delta) => {
210
+ if (props.onResize) props.onResize(delta);
211
+ }, 16);
212
+ const handleDragMove = (event) => {
213
+ if (event.active.id !== "draggable") return;
214
+ throttledResize({
215
+ width: event.delta.x,
216
+ height: event.delta.y
217
+ });
218
+ };
219
+ const handleDragEnd = () => {
220
+ if (props.onResizeEnd) props.onResizeEnd();
221
+ };
222
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_dnd_kit_core.DndContext, {
223
+ autoScroll: {
224
+ threshold: {
225
+ x: .005,
226
+ y: .005
227
+ },
228
+ acceleration: 1
229
+ },
230
+ onDragMove: handleDragMove,
231
+ onDragEnd: handleDragEnd,
232
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
233
+ className: resize_handle_module_default["resize-handle-slot"],
234
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResizeHandle, { ...props })
235
+ })
236
+ });
223
237
  }
224
- //# sourceMappingURL=resize-handle.cjs.map
238
+ exports.default = ResizeHandleWrapper;
239
+
240
+ //# sourceMappingURL=resize-handle.cjs.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\":\"_4da787f72dc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,MACnB,QAAQ,MAAM,MAAM;AAAA,IACrB,CAAE;AAAA,EACH;AAEA,QAAM,gBAAgB,MAAM;AAC3B,QAAK,MAAM,aAAc;AACxB,YAAM,YAAY;AAAA,IACnB;AAAA,EACD;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,YAAa;AAAA,QACZ,WAAW,EAAE,GAAG,MAAO,GAAG,KAAM;AAAA,QAChC,cAAc;AAAA,MACf;AAAA,MACA,YAAa;AAAA,MACb,WAAY;AAAA,MAEZ,sDAAC,SAAI,WAAY,sBAAQ,oBAAqB,GAC7C,sDAAC,gBAAe,GAAG,OAAQ,GAC5B;AAAA;AAAA,EACD;AAEF;",
6
- "names": ["clsx"]
7
- }
1
+ {"version":3,"file":"resize-handle.cjs","names":["useDraggable","useRef","useCallback","useMergeRefs","RenderResizeHandle","styles","useThrottle","DndContext"],"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,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