@wordpress/grid 0.10.0 → 0.11.0

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