@wordpress/grid 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) 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/build-types/shared/drag-overlay-drop-animation.d.ts +2 -2
  93. package/build-types/shared/use-item-exit-animation.d.ts +1 -1
  94. package/build-types/shared/use-item-exit-animation.d.ts.map +1 -1
  95. package/package.json +13 -14
  96. package/src/dashboard-grid/grid-item.tsx +1 -1
  97. package/src/dashboard-grid/index.tsx +11 -12
  98. package/src/dashboard-grid/stories/index.story.tsx +129 -50
  99. package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
  100. package/src/dashboard-grid/types.ts +9 -5
  101. package/src/dashboard-lanes/index.tsx +11 -11
  102. package/src/dashboard-lanes/lanes-item.tsx +1 -1
  103. package/src/dashboard-lanes/stories/index.story.tsx +124 -28
  104. package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
  105. package/src/dashboard-lanes/types.ts +9 -5
  106. package/src/index.ts +1 -0
  107. package/src/shared/column-policy.ts +100 -0
  108. package/src/shared/drag-overlay-drop-animation.ts +2 -2
  109. package/src/shared/test/column-policy.test.ts +215 -0
  110. package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
  111. package/src/shared/use-item-exit-animation.ts +1 -3
  112. package/CHANGELOG.md +0 -93
  113. package/build/dashboard-grid/types.cjs.map +0 -7
  114. package/build/dashboard-lanes/types.cjs.map +0 -7
  115. package/build/index.cjs.map +0 -7
  116. package/build/shared/types.cjs.map +0 -7
  117. package/build-module/dashboard-grid/types.mjs.map +0 -7
  118. package/build-module/dashboard-lanes/types.mjs.map +0 -7
  119. package/build-module/index.mjs.map +0 -7
  120. package/build-module/shared/types.mjs.map +0 -7
@@ -1,323 +1,260 @@
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-grid/grid-item.tsx
31
- var grid_item_exports = {};
32
- __export(grid_item_exports, {
33
- GridItem: () => GridItem
34
- });
35
- module.exports = __toCommonJS(grid_item_exports);
36
- var import_sortable = require("@dnd-kit/sortable");
37
- var import_clsx = __toESM(require("clsx"));
38
- var import_element = require("@wordpress/element");
39
- var import_compose = require("@wordpress/compose");
40
- var import_react_inert_value = require("@wordpress/react-inert-value");
41
-
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_sortable = require("@dnd-kit/sortable");
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 _wordpress_react_inert_value = require("@wordpress/react-inert-value");
33
+ let ___shared_grid_item_key_ts = require("../shared/grid-item-key.cjs");
34
+ let ___shared_resize_handle_tsx = require("../shared/resize-handle.cjs");
35
+ ___shared_resize_handle_tsx = __toESM(___shared_resize_handle_tsx);
36
+ let ___shared_resize_snap_ts = require("../shared/resize-snap.cjs");
37
+ let react_jsx_runtime = require("react/jsx-runtime");
42
38
  // packages/style-runtime/src/index.ts
43
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
39
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
40
+ /**
41
+ * Returns the shared style runtime registry.
42
+ *
43
+ * The registry is stored on `globalThis` so separately bundled copies of this
44
+ * package can coordinate through the same document and style maps.
45
+ *
46
+ * @return The shared runtime registry.
47
+ */
44
48
  function getRuntime() {
45
- const globalScope = globalThis;
46
- if (globalScope.__wpStyleRuntime) {
47
- return globalScope.__wpStyleRuntime;
48
- }
49
- globalScope.__wpStyleRuntime = {
50
- documents: /* @__PURE__ */ new Map(),
51
- styles: /* @__PURE__ */ new Map(),
52
- injectedStyles: /* @__PURE__ */ new WeakMap()
53
- };
54
- if (typeof document !== "undefined") {
55
- registerDocument(document);
56
- }
57
- return globalScope.__wpStyleRuntime;
49
+ const globalScope = globalThis;
50
+ if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
51
+ globalScope.__wpStyleRuntime = {
52
+ documents: /* @__PURE__ */ new Map(),
53
+ styles: /* @__PURE__ */ new Map(),
54
+ injectedStyles: /* @__PURE__ */ new WeakMap()
55
+ };
56
+ if (typeof document !== "undefined") registerDocument(document);
57
+ return globalScope.__wpStyleRuntime;
58
58
  }
59
+ /**
60
+ * Checks whether a document already contains a style tag for a hash.
61
+ *
62
+ * @param targetDocument Document to inspect.
63
+ * @param hash Stable hash for the transformed CSS.
64
+ *
65
+ * @return Whether the style hash already exists in the document.
66
+ */
59
67
  function documentContainsStyleHash(targetDocument, hash) {
60
- if (!targetDocument.head) {
61
- return false;
62
- }
63
- for (const style of targetDocument.head.querySelectorAll(
64
- `style[${STYLE_HASH_ATTRIBUTE}]`
65
- )) {
66
- if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
67
- return true;
68
- }
69
- }
70
- return false;
68
+ if (!targetDocument.head) return false;
69
+ for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
70
+ return false;
71
71
  }
72
+ /**
73
+ * Injects a registered style into a document, unless that document already
74
+ * contains a style tag for the same hash.
75
+ *
76
+ * @param targetDocument Document to inject the style into.
77
+ * @param hash Stable hash for the transformed CSS.
78
+ * @param css CSS text to inject.
79
+ */
72
80
  function injectStyle(targetDocument, hash, css) {
73
- if (!targetDocument.head) {
74
- return;
75
- }
76
- const runtime = getRuntime();
77
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
78
- if (!injectedStyles) {
79
- injectedStyles = /* @__PURE__ */ new Set();
80
- runtime.injectedStyles.set(targetDocument, injectedStyles);
81
- }
82
- if (injectedStyles.has(hash)) {
83
- return;
84
- }
85
- if (documentContainsStyleHash(targetDocument, hash)) {
86
- injectedStyles.add(hash);
87
- return;
88
- }
89
- const style = targetDocument.createElement("style");
90
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
91
- style.appendChild(targetDocument.createTextNode(css));
92
- targetDocument.head.appendChild(style);
93
- injectedStyles.add(hash);
81
+ if (!targetDocument.head) return;
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)) return;
89
+ if (documentContainsStyleHash(targetDocument, hash)) {
90
+ injectedStyles.add(hash);
91
+ return;
92
+ }
93
+ const style = targetDocument.createElement("style");
94
+ style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
95
+ style.appendChild(targetDocument.createTextNode(css));
96
+ targetDocument.head.appendChild(style);
97
+ injectedStyles.add(hash);
94
98
  }
99
+ /**
100
+ * Registers a document as a style injection target.
101
+ *
102
+ * Existing registered styles are replayed into the document immediately.
103
+ * Documents are reference-counted so multiple providers can safely register the
104
+ * same document without one cleanup removing it while another registration is
105
+ * still active.
106
+ *
107
+ * @param targetDocument Document to receive registered styles.
108
+ * @return Cleanup function that unregisters this document registration.
109
+ */
95
110
  function registerDocument(targetDocument) {
96
- const runtime = getRuntime();
97
- runtime.documents.set(
98
- targetDocument,
99
- (runtime.documents.get(targetDocument) ?? 0) + 1
100
- );
101
- for (const [hash, css] of runtime.styles) {
102
- injectStyle(targetDocument, hash, css);
103
- }
104
- return () => {
105
- const count = runtime.documents.get(targetDocument);
106
- if (count === void 0) {
107
- return;
108
- }
109
- if (count <= 1) {
110
- runtime.documents.delete(targetDocument);
111
- return;
112
- }
113
- runtime.documents.set(targetDocument, count - 1);
114
- };
111
+ const runtime = getRuntime();
112
+ runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
113
+ for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
114
+ return () => {
115
+ const count = runtime.documents.get(targetDocument);
116
+ if (count === void 0) return;
117
+ if (count <= 1) {
118
+ runtime.documents.delete(targetDocument);
119
+ return;
120
+ }
121
+ runtime.documents.set(targetDocument, count - 1);
122
+ };
115
123
  }
124
+ /**
125
+ * Registers a style and injects it into all registered documents.
126
+ *
127
+ * The hash is used as the deduplication key, so calling this repeatedly with
128
+ * the same hash will not add duplicate style tags to a document.
129
+ * Registered styles are retained for the lifetime of the page so they can be
130
+ * replayed into documents that are registered later.
131
+ *
132
+ * @param hash Stable hash for the transformed CSS.
133
+ * @param css CSS text to inject.
134
+ */
116
135
  function registerStyle(hash, css) {
117
- const runtime = getRuntime();
118
- runtime.styles.set(hash, css);
119
- for (const targetDocument of runtime.documents.keys()) {
120
- injectStyle(targetDocument, hash, css);
121
- }
136
+ const runtime = getRuntime();
137
+ runtime.styles.set(hash, css);
138
+ for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
122
139
  }
123
-
124
140
  // packages/grid/src/shared/actionable-area-slot.module.css
125
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
126
- registerStyle("ac1094954c", "._1c54fe8165d3023e__actionable-area-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._1c54fe8165d3023e__actionable-area-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-resizing] ._1c54fe8165d3023e__actionable-area-slot{opacity:0;pointer-events:none}");
127
- }
128
- var actionable_area_slot_default = { "actionable-area-slot": "_1c54fe8165d3023e__actionable-area-slot" };
129
-
130
- // packages/grid/src/dashboard-grid/grid-item.tsx
131
- var import_grid_item_key = require("../shared/grid-item-key.cjs");
132
- var import_resize_handle = __toESM(require("../shared/resize-handle.cjs"));
133
- var import_resize_snap = require("../shared/resize-snap.cjs");
134
-
141
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("36a7a084ce", "._0a2b470abcf47e5b__actionable-area-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._0a2b470abcf47e5b__actionable-area-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-resizing] ._0a2b470abcf47e5b__actionable-area-slot{opacity:0;pointer-events:none}");
142
+ var actionable_area_slot_module_default = { "actionable-area-slot": "_0a2b470abcf47e5b__actionable-area-slot" };
135
143
  // packages/grid/src/dashboard-grid/grid-item.module.css
136
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
137
- registerStyle("62860ded21", "._5d1abcb332a18701__item{position:relative}._54de57c12d3ce67e__item-content{height:100%;position:relative}._3e086aa073b9bbd9__is-resizing{overflow:visible;z-index:1}._3e086aa073b9bbd9__is-resizing ._54de57c12d3ce67e__item-content{overflow:visible;position:relative;z-index:2}._81d4e1a6c979f1e4__is-dragging{pointer-events:none}[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{border-radius:var(--wp-grid-placeholder-radius,0)}@media not (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{animation:_0447be8a7068a873__wp-grid-item-placeholder-in 0ms linear var(--wpds-motion-duration-sm,.1s) forwards;opacity:1;outline-color:transparent;outline-style:var(--wp-grid-placeholder-outline-style,dashed);outline-width:0}@keyframes _0447be8a7068a873__wp-grid-item-placeholder-in{to{opacity:var(--wp-grid-placeholder-opacity,.4);outline-color:var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));outline-width:var(--wpds-border-width-sm,2px)}}}@media (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{opacity:var(--wp-grid-placeholder-opacity,.4);outline:var(--wpds-border-width-sm,2px) var(--wp-grid-placeholder-outline-style,dashed) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)))}}@media (forced-colors:active){[data-wp-grid-dragging] ._81d4e1a6c979f1e4__is-dragging{--wp-grid-placeholder-outline-color:Highlight}}._2028fc095dbc5cb2__preview-overlay{background:transparent;border:var(--wpds-border-width-sm,2px) var(--wp-grid-resize-preview-outline-style,solid) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));border-radius:var(--wp-grid-placeholder-radius,0);box-sizing:border-box;inset-inline-start:0;pointer-events:none;position:absolute;top:0;z-index:0}@media (forced-colors:active){._2028fc095dbc5cb2__preview-overlay{border-color:Highlight}}");
138
- }
139
- var grid_item_default = { "item": "_5d1abcb332a18701__item", "item-content": "_54de57c12d3ce67e__item-content", "is-resizing": "_3e086aa073b9bbd9__is-resizing", "is-dragging": "_81d4e1a6c979f1e4__is-dragging", "wp-grid-item-placeholder-in": "_0447be8a7068a873__wp-grid-item-placeholder-in", "preview-overlay": "_2028fc095dbc5cb2__preview-overlay" };
140
-
144
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("33e05f5e81", ".d8e79c99afd8bca5__item{position:relative}._88155a7e5db75630__item-content{height:100%;position:relative}._09df60d54139626b__is-resizing{overflow:visible;z-index:1}._09df60d54139626b__is-resizing ._88155a7e5db75630__item-content{overflow:visible;position:relative;z-index:2}._5e7dab4e781593a1__is-dragging{pointer-events:none}[data-wp-grid-dragging] ._5e7dab4e781593a1__is-dragging{border-radius:var(--wp-grid-placeholder-radius,0)}@media not (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._5e7dab4e781593a1__is-dragging{animation:_41089f4f79a6ecfb__wp-grid-item-placeholder-in 0ms linear var(--wpds-motion-duration-sm,.1s) forwards;opacity:1;outline-color:transparent;outline-style:var(--wp-grid-placeholder-outline-style,dashed);outline-width:0}@keyframes _41089f4f79a6ecfb__wp-grid-item-placeholder-in{to{opacity:var(--wp-grid-placeholder-opacity,.4);outline-color:var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));outline-width:var(--wpds-border-width-sm,2px)}}}@media (prefers-reduced-motion:reduce){[data-wp-grid-dragging] ._5e7dab4e781593a1__is-dragging{opacity:var(--wp-grid-placeholder-opacity,.4);outline:var(--wpds-border-width-sm,2px) var(--wp-grid-placeholder-outline-style,dashed) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)))}}@media (forced-colors:active){[data-wp-grid-dragging] ._5e7dab4e781593a1__is-dragging{--wp-grid-placeholder-outline-color:Highlight}}.c99f267fd053e634__preview-overlay{background:transparent;border:var(--wpds-border-width-sm,2px) var(--wp-grid-resize-preview-outline-style,solid) var(--wp-grid-placeholder-outline-color,var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9)));border-radius:var(--wp-grid-placeholder-radius,0);box-sizing:border-box;inset-inline-start:0;pointer-events:none;position:absolute;top:0;z-index:0}@media (forced-colors:active){.c99f267fd053e634__preview-overlay{border-color:Highlight}}");
145
+ var grid_item_module_default = {
146
+ "item": "d8e79c99afd8bca5__item",
147
+ "item-content": "_88155a7e5db75630__item-content",
148
+ "is-resizing": "_09df60d54139626b__is-resizing",
149
+ "is-dragging": "_5e7dab4e781593a1__is-dragging",
150
+ "wp-grid-item-placeholder-in": "_41089f4f79a6ecfb__wp-grid-item-placeholder-in",
151
+ "preview-overlay": "c99f267fd053e634__preview-overlay"
152
+ };
141
153
  // packages/grid/src/dashboard-grid/grid-item.tsx
142
- var import_jsx_runtime = require("react/jsx-runtime");
143
154
  function getItemCursor(disabled, interacting) {
144
- if (disabled) {
145
- return "default";
146
- }
147
- if (interacting) {
148
- return void 0;
149
- }
150
- return "grab";
155
+ if (disabled) return "default";
156
+ if (interacting) return;
157
+ return "grab";
151
158
  }
152
- function GridItem({
153
- item,
154
- maxColumns,
155
- disabled = false,
156
- draggable = true,
157
- resizable = true,
158
- verticalResizable = true,
159
- interacting = false,
160
- dragging = false,
161
- children,
162
- actionableArea = null,
163
- onResize,
164
- onResizeEnd,
165
- resizeSnapPreview = null,
166
- minResizeWidthPx,
167
- minResizeHeightPx,
168
- maxResizeWidthPx,
169
- maxResizeHeightPx,
170
- renderResizeHandle
171
- }) {
172
- const [resizeDelta, setResizeDelta] = (0, import_element.useState)(
173
- null
174
- );
175
- const [initialContentSize, setInitialContentSize] = (0, import_element.useState)(null);
176
- const itemRef = (0, import_element.useRef)(null);
177
- const contentRef = (0, import_element.useRef)(null);
178
- const dragDisabled = disabled || !draggable;
179
- const resizeDisabled = disabled || !resizable;
180
- const {
181
- attributes,
182
- listeners,
183
- setNodeRef,
184
- setActivatorNodeRef,
185
- isDragging
186
- } = (0, import_sortable.useSortable)({
187
- id: item.key,
188
- disabled: dragDisabled
189
- });
190
- const mergedRef = (0, import_compose.useMergeRefs)([itemRef, setNodeRef]);
191
- const contentMergedRef = (0, import_compose.useMergeRefs)([contentRef]);
192
- const style = {
193
- gridColumnEnd: `span ${item.width === "full" ? maxColumns : Math.min(
194
- typeof item.width === "number" ? item.width : 1,
195
- maxColumns
196
- )}`,
197
- gridRowEnd: `span ${item.height || 1}`
198
- };
199
- const isResizing = resizeDelta !== null;
200
- const itemClassName = (0, import_clsx.default)(
201
- grid_item_default.item,
202
- isDragging && grid_item_default["is-dragging"],
203
- isResizing && grid_item_default["is-resizing"]
204
- );
205
- const handleResize = (delta) => {
206
- const contentNode = contentRef.current;
207
- let baselineSize = initialContentSize;
208
- if (contentNode && !baselineSize) {
209
- const { width, height } = contentNode.getBoundingClientRect();
210
- baselineSize = { width, height };
211
- setInitialContentSize(baselineSize);
212
- }
213
- let clamped = {
214
- width: delta.width,
215
- height: verticalResizable ? delta.height : 0
216
- };
217
- if (baselineSize) {
218
- clamped = (0, import_resize_snap.clampResizeDelta)(
219
- clamped,
220
- baselineSize,
221
- {
222
- width: minResizeWidthPx,
223
- height: verticalResizable ? minResizeHeightPx : void 0
224
- },
225
- {
226
- width: maxResizeWidthPx,
227
- height: verticalResizable ? maxResizeHeightPx : void 0
228
- }
229
- );
230
- }
231
- setResizeDelta(clamped);
232
- onResize(item.key, clamped);
233
- };
234
- const handleResizeEnd = () => {
235
- setResizeDelta(null);
236
- setInitialContentSize(null);
237
- onResizeEnd();
238
- };
239
- const continuousContentStyle = resizeDelta && initialContentSize ? {
240
- width: initialContentSize.width + resizeDelta.width,
241
- height: verticalResizable ? initialContentSize.height + resizeDelta.height : void 0
242
- } : void 0;
243
- const previewOverlay = resizeSnapPreview ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SnapPreviewOverlay, { snap: resizeSnapPreview }) : null;
244
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
245
- "div",
246
- {
247
- ref: mergedRef,
248
- className: itemClassName,
249
- style,
250
- ...{ [import_grid_item_key.GRID_ITEM_DATA_KEY]: item.key },
251
- "data-wp-grid-item-resizing": isResizing || void 0,
252
- children: [
253
- actionableArea ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
- "div",
255
- {
256
- className: actionable_area_slot_default["actionable-area-slot"],
257
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
258
- "div",
259
- {
260
- style: { display: "contents" },
261
- inert: (0, import_react_inert_value.inertValue)(dragging),
262
- children: actionableArea
263
- }
264
- )
265
- }
266
- ) : null,
267
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
268
- "div",
269
- {
270
- ref: setActivatorNodeRef,
271
- ...attributes,
272
- ...listeners,
273
- style: {
274
- height: "100%",
275
- cursor: getItemCursor(dragDisabled, interacting)
276
- },
277
- children: [
278
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
279
- "div",
280
- {
281
- ref: contentMergedRef,
282
- className: grid_item_default["item-content"],
283
- style: continuousContentStyle,
284
- children: [
285
- children,
286
- !resizeDisabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
287
- import_resize_handle.default,
288
- {
289
- itemId: item.key,
290
- verticalResizable,
291
- onResize: handleResize,
292
- onResizeEnd: handleResizeEnd,
293
- renderResizeHandle
294
- }
295
- )
296
- ]
297
- }
298
- ),
299
- previewOverlay
300
- ]
301
- }
302
- )
303
- ]
304
- }
305
- );
159
+ function GridItem({ item, maxColumns, disabled = false, draggable = true, resizable = true, verticalResizable = true, interacting = false, dragging = false, children, actionableArea = null, onResize, onResizeEnd, resizeSnapPreview = null, minResizeWidthPx, minResizeHeightPx, maxResizeWidthPx, maxResizeHeightPx, renderResizeHandle }) {
160
+ const [resizeDelta, setResizeDelta] = (0, _wordpress_element.useState)(null);
161
+ const [initialContentSize, setInitialContentSize] = (0, _wordpress_element.useState)(null);
162
+ const itemRef = (0, _wordpress_element.useRef)(null);
163
+ const contentRef = (0, _wordpress_element.useRef)(null);
164
+ const dragDisabled = disabled || !draggable;
165
+ const resizeDisabled = disabled || !resizable;
166
+ const { attributes, listeners, setNodeRef, setActivatorNodeRef, isDragging } = (0, _dnd_kit_sortable.useSortable)({
167
+ id: item.key,
168
+ disabled: dragDisabled
169
+ });
170
+ const mergedRef = (0, _wordpress_compose.useMergeRefs)([itemRef, setNodeRef]);
171
+ const contentMergedRef = (0, _wordpress_compose.useMergeRefs)([contentRef]);
172
+ const style = {
173
+ gridColumnEnd: `span ${item.width === "full" ? maxColumns : Math.min(typeof item.width === "number" ? item.width : 1, maxColumns)}`,
174
+ gridRowEnd: `span ${item.height || 1}`
175
+ };
176
+ const isResizing = resizeDelta !== null;
177
+ const itemClassName = (0, clsx.default)(grid_item_module_default.item, isDragging && grid_item_module_default["is-dragging"], isResizing && grid_item_module_default["is-resizing"]);
178
+ const handleResize = (delta) => {
179
+ const contentNode = contentRef.current;
180
+ let baselineSize = initialContentSize;
181
+ if (contentNode && !baselineSize) {
182
+ const { width, height } = contentNode.getBoundingClientRect();
183
+ baselineSize = {
184
+ width,
185
+ height
186
+ };
187
+ setInitialContentSize(baselineSize);
188
+ }
189
+ let clamped = {
190
+ width: delta.width,
191
+ height: verticalResizable ? delta.height : 0
192
+ };
193
+ if (baselineSize) clamped = (0, ___shared_resize_snap_ts.clampResizeDelta)(clamped, baselineSize, {
194
+ width: minResizeWidthPx,
195
+ height: verticalResizable ? minResizeHeightPx : void 0
196
+ }, {
197
+ width: maxResizeWidthPx,
198
+ height: verticalResizable ? maxResizeHeightPx : void 0
199
+ });
200
+ setResizeDelta(clamped);
201
+ onResize(item.key, clamped);
202
+ };
203
+ const handleResizeEnd = () => {
204
+ setResizeDelta(null);
205
+ setInitialContentSize(null);
206
+ onResizeEnd();
207
+ };
208
+ const continuousContentStyle = resizeDelta && initialContentSize ? {
209
+ width: initialContentSize.width + resizeDelta.width,
210
+ height: verticalResizable ? initialContentSize.height + resizeDelta.height : void 0
211
+ } : void 0;
212
+ const previewOverlay = resizeSnapPreview ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnapPreviewOverlay, { snap: resizeSnapPreview }) : null;
213
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
214
+ ref: mergedRef,
215
+ className: itemClassName,
216
+ style,
217
+ [___shared_grid_item_key_ts.GRID_ITEM_DATA_KEY]: item.key,
218
+ "data-wp-grid-item-resizing": isResizing || void 0,
219
+ children: [actionableArea ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
220
+ className: actionable_area_slot_module_default["actionable-area-slot"],
221
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
222
+ style: { display: "contents" },
223
+ inert: (0, _wordpress_react_inert_value.inertValue)(dragging),
224
+ children: actionableArea
225
+ })
226
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
227
+ ref: setActivatorNodeRef,
228
+ ...dragDisabled ? {} : attributes,
229
+ ...listeners,
230
+ style: {
231
+ height: "100%",
232
+ cursor: getItemCursor(dragDisabled, interacting)
233
+ },
234
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
235
+ ref: contentMergedRef,
236
+ className: grid_item_module_default["item-content"],
237
+ style: continuousContentStyle,
238
+ children: [children, !resizeDisabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___shared_resize_handle_tsx.default, {
239
+ itemId: item.key,
240
+ verticalResizable,
241
+ onResize: handleResize,
242
+ onResizeEnd: handleResizeEnd,
243
+ renderResizeHandle
244
+ })]
245
+ }), previewOverlay]
246
+ })]
247
+ });
306
248
  }
307
249
  function SnapPreviewOverlay({ snap }) {
308
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
309
- "div",
310
- {
311
- className: grid_item_default["preview-overlay"],
312
- style: {
313
- width: snap.widthPx,
314
- height: snap.heightPx ?? "100%"
315
- }
316
- }
317
- );
250
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
251
+ className: grid_item_module_default["preview-overlay"],
252
+ style: {
253
+ width: snap.widthPx,
254
+ height: snap.heightPx ?? "100%"
255
+ }
256
+ });
318
257
  }
319
- // Annotate the CommonJS export names for ESM import in node:
320
- 0 && (module.exports = {
321
- GridItem
322
- });
323
- //# sourceMappingURL=grid-item.cjs.map
258
+ exports.GridItem = GridItem;
259
+
260
+ //# sourceMappingURL=grid-item.cjs.map