@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,19 +1,5 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // packages/grid/src/dashboard-lanes/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
19
- //# sourceMappingURL=types.cjs.map
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
@@ -1,206 +1,180 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/grid/src/dashboard-lanes/use-lane-placement.ts
21
- var use_lane_placement_exports = {};
22
- __export(use_lane_placement_exports, {
23
- useLanePlacement: () => useLanePlacement
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(use_lane_placement_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_lane_placement = require("./lane-placement.cjs");
28
- var import_grid_item_key = require("../shared/grid-item-key.cjs");
29
- var DEFAULT_ROW_UNIT = 4;
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let __lane_placement_ts = require("./lane-placement.cjs");
8
+ let ___shared_grid_item_key_ts = require("../shared/grid-item-key.cjs");
9
+ // packages/grid/src/dashboard-lanes/use-lane-placement.ts
10
+ const DEFAULT_ROW_UNIT = 4;
30
11
  function supportsGridLanes() {
31
- if (typeof CSS === "undefined" || !CSS.supports) {
32
- return false;
33
- }
34
- return CSS.supports("display", "grid-lanes");
12
+ if (typeof CSS === "undefined" || !CSS.supports) return false;
13
+ return CSS.supports("display", "grid-lanes");
35
14
  }
36
15
  function clampSpan(span) {
37
- if (typeof span !== "number" || !Number.isFinite(span)) {
38
- return 1;
39
- }
40
- return Math.max(1, Math.floor(span));
16
+ if (typeof span !== "number" || !Number.isFinite(span)) return 1;
17
+ return Math.max(1, Math.floor(span));
41
18
  }
19
+ /**
20
+ * Hook that measures item heights and resolves their placement when
21
+ * `display: grid-lanes` is unavailable, falling through to a no-op
22
+ * pass when the host browser supports the feature natively.
23
+ *
24
+ * Usage from the renderer:
25
+ *
26
+ * ```tsx
27
+ * const [ container, setContainer ] = useState< HTMLDivElement | null >( null );
28
+ * const { itemStyles } = useLanePlacement( container, {
29
+ * items: layout,
30
+ * lanes: columns,
31
+ * gap: gapPx,
32
+ * flowTolerance: 16,
33
+ * } );
34
+ *
35
+ * return (
36
+ * <div ref={ setContainer } style={ { display: 'grid-lanes', ... } }>
37
+ * { items.map( ( item ) => (
38
+ * <div
39
+ * key={ item.key }
40
+ * data-wp-grid-item-key={ item.key }
41
+ * style={ itemStyles.get( item.key ) }
42
+ * >
43
+ * { ... }
44
+ * </div>
45
+ * ) ) }
46
+ * </div>
47
+ * );
48
+ * ```
49
+ *
50
+ * @param container HTMLElement (or null pre-mount) hosting the items.
51
+ * @param input Logical items, lane count, gap, and tuning.
52
+ * @return Per-item styles plus the `isPolyfilled` flag.
53
+ */
42
54
  function useLanePlacement(container, input) {
43
- const [isPolyfilled] = (0, import_element.useState)(() => !supportsGridLanes());
44
- const [itemStyles, setItemStyles] = (0, import_element.useState)(() => /* @__PURE__ */ new Map());
45
- const nativeStyles = (0, import_element.useMemo)(() => {
46
- const map = /* @__PURE__ */ new Map();
47
- for (const item of input.items) {
48
- map.set(item.key, {
49
- gridColumn: `span ${clampSpan(item.span)}`
50
- });
51
- }
52
- return map;
53
- }, [input.items]);
54
- const itemsSignature = (0, import_element.useMemo)(() => {
55
- return input.items.map(
56
- (item) => `${item.key}/${item.span ?? 1}/${item.lane ?? ""}`
57
- ).join("\0");
58
- }, [input.items]);
59
- const itemsForPlacement = (0, import_element.useMemo)(() => input.items, [itemsSignature]);
60
- const { lanes, gap, flowTolerance, rowUnit } = input;
61
- (0, import_element.useLayoutEffect)(() => {
62
- if (!isPolyfilled || !container) {
63
- return;
64
- }
65
- if (typeof ResizeObserver === "undefined") {
66
- return;
67
- }
68
- const heights = /* @__PURE__ */ new Map();
69
- const observed = /* @__PURE__ */ new Set();
70
- let cancelled = false;
71
- let rafId = null;
72
- const recompute = () => {
73
- if (rafId !== null || cancelled) {
74
- return;
75
- }
76
- rafId = requestAnimationFrame(() => {
77
- rafId = null;
78
- if (cancelled) {
79
- return;
80
- }
81
- const itemsWithHeight = itemsForPlacement.map((item) => ({
82
- key: item.key,
83
- span: clampSpan(item.span),
84
- lane: item.lane,
85
- height: heights.get(item.key) ?? 0
86
- }));
87
- const result = (0, import_lane_placement.computeLanePlacements)({
88
- items: itemsWithHeight,
89
- lanes,
90
- gap,
91
- flowTolerance
92
- });
93
- const effectiveRowUnit = Math.max(
94
- 1,
95
- rowUnit ?? DEFAULT_ROW_UNIT
96
- );
97
- const next = /* @__PURE__ */ new Map();
98
- for (const item of itemsForPlacement) {
99
- const placement = result.placements.get(item.key);
100
- if (!placement) {
101
- continue;
102
- }
103
- const height = heights.get(item.key) ?? 0;
104
- const rowStart = Math.floor(placement.top / effectiveRowUnit) + 1;
105
- const rowSpan = Math.max(
106
- 1,
107
- Math.ceil(height / effectiveRowUnit)
108
- );
109
- next.set(item.key, {
110
- gridColumnStart: placement.lane + 1,
111
- gridColumnEnd: `span ${placement.span}`,
112
- gridRowStart: rowStart,
113
- gridRowEnd: `span ${rowSpan}`
114
- });
115
- }
116
- setItemStyles(next);
117
- });
118
- };
119
- const resizeObserver = new ResizeObserver((entries) => {
120
- let changed = false;
121
- for (const entry of entries) {
122
- const key = entry.target.getAttribute(
123
- import_grid_item_key.GRID_ITEM_DATA_KEY
124
- );
125
- if (!key) {
126
- continue;
127
- }
128
- const newHeight = entry.contentRect.height;
129
- if (heights.get(key) !== newHeight) {
130
- heights.set(key, newHeight);
131
- changed = true;
132
- }
133
- }
134
- if (changed) {
135
- recompute();
136
- }
137
- });
138
- const refreshObserved = () => {
139
- const current = container.querySelectorAll(
140
- `[${import_grid_item_key.GRID_ITEM_DATA_KEY}]`
141
- );
142
- for (const element of current) {
143
- if (!observed.has(element)) {
144
- observed.add(element);
145
- resizeObserver.observe(element);
146
- const key = element.getAttribute(import_grid_item_key.GRID_ITEM_DATA_KEY);
147
- if (key) {
148
- const rect = element.getBoundingClientRect();
149
- heights.set(key, rect.height);
150
- }
151
- }
152
- }
153
- for (const element of observed) {
154
- if (!container.contains(element)) {
155
- resizeObserver.unobserve(element);
156
- observed.delete(element);
157
- }
158
- }
159
- };
160
- const mutationObserver = typeof MutationObserver !== "undefined" ? new MutationObserver(() => {
161
- refreshObserved();
162
- recompute();
163
- }) : null;
164
- if (mutationObserver) {
165
- mutationObserver.observe(container, {
166
- childList: true,
167
- subtree: true,
168
- attributes: true,
169
- attributeFilter: [import_grid_item_key.GRID_ITEM_DATA_KEY]
170
- });
171
- }
172
- refreshObserved();
173
- recompute();
174
- return () => {
175
- cancelled = true;
176
- if (rafId !== null) {
177
- cancelAnimationFrame(rafId);
178
- }
179
- resizeObserver.disconnect();
180
- mutationObserver?.disconnect();
181
- };
182
- }, [
183
- container,
184
- isPolyfilled,
185
- lanes,
186
- gap,
187
- flowTolerance,
188
- rowUnit,
189
- itemsForPlacement
190
- ]);
191
- if (!isPolyfilled) {
192
- return { itemStyles: nativeStyles, isPolyfilled: false };
193
- }
194
- if (itemStyles.size === 0) {
195
- return {
196
- itemStyles: nativeStyles,
197
- isPolyfilled: true
198
- };
199
- }
200
- return { itemStyles, isPolyfilled: true };
55
+ const [isPolyfilled] = (0, _wordpress_element.useState)(() => !supportsGridLanes());
56
+ const [itemStyles, setItemStyles] = (0, _wordpress_element.useState)(() => /* @__PURE__ */ new Map());
57
+ const nativeStyles = (0, _wordpress_element.useMemo)(() => {
58
+ const map = /* @__PURE__ */ new Map();
59
+ for (const item of input.items) map.set(item.key, { gridColumn: `span ${clampSpan(item.span)}` });
60
+ return map;
61
+ }, [input.items]);
62
+ const itemsSignature = (0, _wordpress_element.useMemo)(() => {
63
+ return input.items.map((item) => `${item.key}/${item.span ?? 1}/${item.lane ?? ""}`).join("\0");
64
+ }, [input.items]);
65
+ const itemsForPlacement = (0, _wordpress_element.useMemo)(() => input.items, [itemsSignature]);
66
+ const { lanes, gap, flowTolerance, rowUnit } = input;
67
+ (0, _wordpress_element.useLayoutEffect)(() => {
68
+ if (!isPolyfilled || !container) return;
69
+ if (typeof ResizeObserver === "undefined") return;
70
+ const heights = /* @__PURE__ */ new Map();
71
+ const observed = /* @__PURE__ */ new Set();
72
+ let cancelled = false;
73
+ let rafId = null;
74
+ const recompute = () => {
75
+ if (rafId !== null || cancelled) return;
76
+ rafId = requestAnimationFrame(() => {
77
+ rafId = null;
78
+ if (cancelled) return;
79
+ const itemsWithHeight = itemsForPlacement.map((item) => ({
80
+ key: item.key,
81
+ span: clampSpan(item.span),
82
+ lane: item.lane,
83
+ height: heights.get(item.key) ?? 0
84
+ }));
85
+ const result = (0, __lane_placement_ts.computeLanePlacements)({
86
+ items: itemsWithHeight,
87
+ lanes,
88
+ gap,
89
+ flowTolerance
90
+ });
91
+ const effectiveRowUnit = Math.max(1, rowUnit ?? DEFAULT_ROW_UNIT);
92
+ const next = /* @__PURE__ */ new Map();
93
+ for (const item of itemsForPlacement) {
94
+ const placement = result.placements.get(item.key);
95
+ if (!placement) continue;
96
+ const height = heights.get(item.key) ?? 0;
97
+ const rowStart = Math.floor(placement.top / effectiveRowUnit) + 1;
98
+ const rowSpan = Math.max(1, Math.ceil(height / effectiveRowUnit));
99
+ next.set(item.key, {
100
+ gridColumnStart: placement.lane + 1,
101
+ gridColumnEnd: `span ${placement.span}`,
102
+ gridRowStart: rowStart,
103
+ gridRowEnd: `span ${rowSpan}`
104
+ });
105
+ }
106
+ setItemStyles(next);
107
+ });
108
+ };
109
+ const resizeObserver = new ResizeObserver((entries) => {
110
+ let changed = false;
111
+ for (const entry of entries) {
112
+ const key = entry.target.getAttribute(___shared_grid_item_key_ts.GRID_ITEM_DATA_KEY);
113
+ if (!key) continue;
114
+ const newHeight = entry.contentRect.height;
115
+ if (heights.get(key) !== newHeight) {
116
+ heights.set(key, newHeight);
117
+ changed = true;
118
+ }
119
+ }
120
+ if (changed) recompute();
121
+ });
122
+ const refreshObserved = () => {
123
+ const current = container.querySelectorAll(`[${___shared_grid_item_key_ts.GRID_ITEM_DATA_KEY}]`);
124
+ for (const element of current) if (!observed.has(element)) {
125
+ observed.add(element);
126
+ resizeObserver.observe(element);
127
+ const key = element.getAttribute(___shared_grid_item_key_ts.GRID_ITEM_DATA_KEY);
128
+ if (key) {
129
+ const rect = element.getBoundingClientRect();
130
+ heights.set(key, rect.height);
131
+ }
132
+ }
133
+ for (const element of observed) if (!container.contains(element)) {
134
+ resizeObserver.unobserve(element);
135
+ observed.delete(element);
136
+ }
137
+ };
138
+ const mutationObserver = typeof MutationObserver !== "undefined" ? new MutationObserver(() => {
139
+ refreshObserved();
140
+ recompute();
141
+ }) : null;
142
+ if (mutationObserver) mutationObserver.observe(container, {
143
+ childList: true,
144
+ subtree: true,
145
+ attributes: true,
146
+ attributeFilter: [___shared_grid_item_key_ts.GRID_ITEM_DATA_KEY]
147
+ });
148
+ refreshObserved();
149
+ recompute();
150
+ return () => {
151
+ cancelled = true;
152
+ if (rafId !== null) cancelAnimationFrame(rafId);
153
+ resizeObserver.disconnect();
154
+ mutationObserver?.disconnect();
155
+ };
156
+ }, [
157
+ container,
158
+ isPolyfilled,
159
+ lanes,
160
+ gap,
161
+ flowTolerance,
162
+ rowUnit,
163
+ itemsForPlacement
164
+ ]);
165
+ if (!isPolyfilled) return {
166
+ itemStyles: nativeStyles,
167
+ isPolyfilled: false
168
+ };
169
+ if (itemStyles.size === 0) return {
170
+ itemStyles: nativeStyles,
171
+ isPolyfilled: true
172
+ };
173
+ return {
174
+ itemStyles,
175
+ isPolyfilled: true
176
+ };
201
177
  }
202
- // Annotate the CommonJS export names for ESM import in node:
203
- 0 && (module.exports = {
204
- useLanePlacement
205
- });
206
- //# sourceMappingURL=use-lane-placement.cjs.map
178
+ exports.useLanePlacement = useLanePlacement;
179
+
180
+ //# sourceMappingURL=use-lane-placement.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dashboard-lanes/use-lane-placement.ts"],
4
- "sourcesContent": ["import { useState, useLayoutEffect, useMemo } from '@wordpress/element';\nimport { computeLanePlacements } from './lane-placement';\nimport { GRID_ITEM_DATA_KEY } from '../shared/grid-item-key';\n\nconst DEFAULT_ROW_UNIT = 4;\n\nfunction supportsGridLanes(): boolean {\n\tif ( typeof CSS === 'undefined' || ! CSS.supports ) {\n\t\treturn false;\n\t}\n\treturn CSS.supports( 'display', 'grid-lanes' );\n}\n\nfunction clampSpan( span: number | undefined ): number {\n\tif ( typeof span !== 'number' || ! Number.isFinite( span ) ) {\n\t\treturn 1;\n\t}\n\treturn Math.max( 1, Math.floor( span ) );\n}\n\n/**\n * Logical item passed to the hook. The renderer is responsible for\n * mounting a DOM node with `data-wp-grid-item-key={ item.key }` for each\n * entry; the hook will measure that node and produce inline styles.\n */\nexport type LaneItemInput = {\n\tkey: string;\n\tspan?: number;\n\tlane?: number;\n};\n\nexport type UseLanePlacementInput = {\n\titems: ReadonlyArray< LaneItemInput >;\n\tlanes: number;\n\tgap: number;\n\tflowTolerance: number;\n\t/**\n\t * Snap unit for `grid-row-start` / `grid-row-end: span N` math.\n\t * Smaller values produce sharper placement at the cost of more\n\t * implicit rows. Defaults to 4 (px).\n\t */\n\trowUnit?: number;\n};\n\nexport type UseLanePlacementResult = {\n\t/**\n\t * Inline styles to apply to each item, keyed by item key. On\n\t * native (`display: grid-lanes`), entries carry only\n\t * `gridColumn: span N`; the browser handles row placement. While\n\t * polyfilling, entries also carry explicit `grid-column-start` /\n\t * `grid-row-*` values.\n\t */\n\titemStyles: Map< string, React.CSSProperties >;\n\n\t/**\n\t * `false` when the host browser supports `display: grid-lanes`\n\t * natively. The hook avoids mounting any observers in that case.\n\t */\n\tisPolyfilled: boolean;\n};\n\n/**\n * Hook that measures item heights and resolves their placement when\n * `display: grid-lanes` is unavailable, falling through to a no-op\n * pass when the host browser supports the feature natively.\n *\n * Usage from the renderer:\n *\n * ```tsx\n * const [ container, setContainer ] = useState< HTMLDivElement | null >( null );\n * const { itemStyles } = useLanePlacement( container, {\n * items: layout,\n * lanes: columns,\n * gap: gapPx,\n * flowTolerance: 16,\n * } );\n *\n * return (\n * <div ref={ setContainer } style={ { display: 'grid-lanes', ... } }>\n * { items.map( ( item ) => (\n * <div\n * key={ item.key }\n * data-wp-grid-item-key={ item.key }\n * style={ itemStyles.get( item.key ) }\n * >\n * { ... }\n * </div>\n * ) ) }\n * </div>\n * );\n * ```\n *\n * @param container HTMLElement (or null pre-mount) hosting the items.\n * @param input Logical items, lane count, gap, and tuning.\n * @return Per-item styles plus the `isPolyfilled` flag.\n */\nexport function useLanePlacement(\n\tcontainer: HTMLElement | null,\n\tinput: UseLanePlacementInput\n): UseLanePlacementResult {\n\t// Detect once at mount. SSR returns `true` (CSS undefined); the\n\t// client-first render returns the real value. Either path produces\n\t// the same DOM until the polyfill effect runs (both emit\n\t// span-only styles), so there is no hydration mismatch.\n\tconst [ isPolyfilled ] = useState( () => ! supportsGridLanes() );\n\n\tconst [ itemStyles, setItemStyles ] = useState<\n\t\tMap< string, React.CSSProperties >\n\t>( () => new Map() );\n\n\t// Native pass-through: items only need their column span; the\n\t// browser handles row placement. Memoized so a stable items\n\t// array yields a stable Map identity.\n\tconst nativeStyles = useMemo( () => {\n\t\tconst map = new Map< string, React.CSSProperties >();\n\t\tfor ( const item of input.items ) {\n\t\t\tmap.set( item.key, {\n\t\t\t\tgridColumn: `span ${ clampSpan( item.span ) }`,\n\t\t\t} );\n\t\t}\n\t\treturn map;\n\t}, [ input.items ] );\n\n\t// Stable signature of items for deps. Keys, spans, and explicit\n\t// lanes are the only fields that influence observer wiring or\n\t// placement, so we hash exactly those.\n\tconst itemsSignature = useMemo( () => {\n\t\treturn input.items\n\t\t\t.map(\n\t\t\t\t( item ) =>\n\t\t\t\t\t`${ item.key }/${ item.span ?? 1 }/${ item.lane ?? '' }`\n\t\t\t)\n\t\t\t.join( '\\0' );\n\t}, [ input.items ] );\n\n\t// Stable array identity while placement-relevant fields match\n\t// `itemsSignature`, so the layout effect is not torn down on every\n\t// parent re-render that passes a fresh `items` reference.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- `itemsSignature` encodes keys/spans/lanes; `input.items` reference often changes without placement changes.\n\tconst itemsForPlacement = useMemo( () => input.items, [ itemsSignature ] );\n\n\tconst { lanes, gap, flowTolerance, rowUnit } = input;\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! isPolyfilled || ! container ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( typeof ResizeObserver === 'undefined' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst heights = new Map< string, number >();\n\t\tconst observed = new Set< Element >();\n\t\tlet cancelled = false;\n\t\tlet rafId: number | null = null;\n\n\t\tconst recompute = () => {\n\t\t\tif ( rafId !== null || cancelled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// One layout per frame even when ResizeObserver and\n\t\t\t// MutationObserver fire in the same tick.\n\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\trafId = null;\n\t\t\t\tif ( cancelled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst itemsWithHeight = itemsForPlacement.map( ( item ) => ( {\n\t\t\t\t\tkey: item.key,\n\t\t\t\t\tspan: clampSpan( item.span ),\n\t\t\t\t\tlane: item.lane,\n\t\t\t\t\theight: heights.get( item.key ) ?? 0,\n\t\t\t\t} ) );\n\t\t\t\tconst result = computeLanePlacements( {\n\t\t\t\t\titems: itemsWithHeight,\n\t\t\t\t\tlanes,\n\t\t\t\t\tgap,\n\t\t\t\t\tflowTolerance,\n\t\t\t\t} );\n\t\t\t\tconst effectiveRowUnit = Math.max(\n\t\t\t\t\t1,\n\t\t\t\t\trowUnit ?? DEFAULT_ROW_UNIT\n\t\t\t\t);\n\t\t\t\tconst next = new Map< string, React.CSSProperties >();\n\t\t\t\tfor ( const item of itemsForPlacement ) {\n\t\t\t\t\tconst placement = result.placements.get( item.key );\n\t\t\t\t\tif ( ! placement ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst height = heights.get( item.key ) ?? 0;\n\t\t\t\t\tconst rowStart =\n\t\t\t\t\t\tMath.floor( placement.top / effectiveRowUnit ) + 1;\n\t\t\t\t\tconst rowSpan = Math.max(\n\t\t\t\t\t\t1,\n\t\t\t\t\t\tMath.ceil( height / effectiveRowUnit )\n\t\t\t\t\t);\n\t\t\t\t\tnext.set( item.key, {\n\t\t\t\t\t\tgridColumnStart: placement.lane + 1,\n\t\t\t\t\t\tgridColumnEnd: `span ${ placement.span }`,\n\t\t\t\t\t\tgridRowStart: rowStart,\n\t\t\t\t\t\tgridRowEnd: `span ${ rowSpan }`,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tsetItemStyles( next );\n\t\t\t} );\n\t\t};\n\n\t\tconst resizeObserver = new ResizeObserver( ( entries ) => {\n\t\t\tlet changed = false;\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst key = ( entry.target as HTMLElement ).getAttribute(\n\t\t\t\t\tGRID_ITEM_DATA_KEY\n\t\t\t\t);\n\t\t\t\tif ( ! key ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst newHeight = entry.contentRect.height;\n\t\t\t\tif ( heights.get( key ) !== newHeight ) {\n\t\t\t\t\theights.set( key, newHeight );\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( changed ) {\n\t\t\t\trecompute();\n\t\t\t}\n\t\t} );\n\n\t\tconst refreshObserved = () => {\n\t\t\tconst current = container.querySelectorAll(\n\t\t\t\t`[${ GRID_ITEM_DATA_KEY }]`\n\t\t\t);\n\t\t\tfor ( const element of current ) {\n\t\t\t\tif ( ! observed.has( element ) ) {\n\t\t\t\t\tobserved.add( element );\n\t\t\t\t\tresizeObserver.observe( element );\n\t\t\t\t\tconst key = element.getAttribute( GRID_ITEM_DATA_KEY );\n\t\t\t\t\tif ( key ) {\n\t\t\t\t\t\tconst rect = (\n\t\t\t\t\t\t\telement as HTMLElement\n\t\t\t\t\t\t ).getBoundingClientRect();\n\t\t\t\t\t\theights.set( key, rect.height );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor ( const element of observed ) {\n\t\t\t\tif ( ! container.contains( element ) ) {\n\t\t\t\t\tresizeObserver.unobserve( element );\n\t\t\t\t\tobserved.delete( element );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Children may mount, unmount, or change `data-wp-grid-item-key`\n\t\t// after the container exists (drag reorders, additions). The\n\t\t// mutation observer keeps the observed set in sync.\n\t\tconst mutationObserver =\n\t\t\ttypeof MutationObserver !== 'undefined'\n\t\t\t\t? new MutationObserver( () => {\n\t\t\t\t\t\trefreshObserved();\n\t\t\t\t\t\trecompute();\n\t\t\t\t\t} )\n\t\t\t\t: null;\n\t\tif ( mutationObserver ) {\n\t\t\tmutationObserver.observe( container, {\n\t\t\t\tchildList: true,\n\t\t\t\tsubtree: true,\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: [ GRID_ITEM_DATA_KEY ],\n\t\t\t} );\n\t\t}\n\n\t\trefreshObserved();\n\t\trecompute();\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif ( rafId !== null ) {\n\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t}\n\t\t\tresizeObserver.disconnect();\n\t\t\tmutationObserver?.disconnect();\n\t\t};\n\t}, [\n\t\tcontainer,\n\t\tisPolyfilled,\n\t\tlanes,\n\t\tgap,\n\t\tflowTolerance,\n\t\trowUnit,\n\t\titemsForPlacement,\n\t] );\n\n\tif ( ! isPolyfilled ) {\n\t\treturn { itemStyles: nativeStyles, isPolyfilled: false };\n\t}\n\tif ( itemStyles.size === 0 ) {\n\t\t// Pre-measurement frame: emit native-shape styles so items\n\t\t// appear in their default span rather than collapsing to 1\n\t\t// column at the top-left.\n\t\treturn {\n\t\t\titemStyles: nativeStyles as Map< string, React.CSSProperties >,\n\t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,iBAAiB,CAAE,uCAAmB;AAAA,MACvC,CAAE;AAAA,IACH;AAEA,oBAAgB;AAChB,cAAU;AAEV,WAAO,MAAM;AACZ,kBAAY;AACZ,UAAK,UAAU,MAAO;AACrB,6BAAsB,KAAM;AAAA,MAC7B;AACA,qBAAe,WAAW;AAC1B,wBAAkB,WAAW;AAAA,IAC9B;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,MAAK,CAAE,cAAe;AACrB,WAAO,EAAE,YAAY,cAAc,cAAc,MAAM;AAAA,EACxD;AACA,MAAK,WAAW,SAAS,GAAI;AAI5B,WAAO;AAAA,MACN,YAAY;AAAA,MACZ,cAAc;AAAA,IACf;AAAA,EACD;AACA,SAAO,EAAE,YAAY,cAAc,KAAK;AACzC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-lane-placement.cjs","names":["useState","useMemo","computeLanePlacements","GRID_ITEM_DATA_KEY"],"sources":["../../src/dashboard-lanes/use-lane-placement.ts"],"sourcesContent":["import { useState, useLayoutEffect, useMemo } from '@wordpress/element';\nimport { computeLanePlacements } from './lane-placement';\nimport { GRID_ITEM_DATA_KEY } from '../shared/grid-item-key';\n\nconst DEFAULT_ROW_UNIT = 4;\n\nfunction supportsGridLanes(): boolean {\n\tif ( typeof CSS === 'undefined' || ! CSS.supports ) {\n\t\treturn false;\n\t}\n\treturn CSS.supports( 'display', 'grid-lanes' );\n}\n\nfunction clampSpan( span: number | undefined ): number {\n\tif ( typeof span !== 'number' || ! Number.isFinite( span ) ) {\n\t\treturn 1;\n\t}\n\treturn Math.max( 1, Math.floor( span ) );\n}\n\n/**\n * Logical item passed to the hook. The renderer is responsible for\n * mounting a DOM node with `data-wp-grid-item-key={ item.key }` for each\n * entry; the hook will measure that node and produce inline styles.\n */\nexport type LaneItemInput = {\n\tkey: string;\n\tspan?: number;\n\tlane?: number;\n};\n\nexport type UseLanePlacementInput = {\n\titems: ReadonlyArray< LaneItemInput >;\n\tlanes: number;\n\tgap: number;\n\tflowTolerance: number;\n\t/**\n\t * Snap unit for `grid-row-start` / `grid-row-end: span N` math.\n\t * Smaller values produce sharper placement at the cost of more\n\t * implicit rows. Defaults to 4 (px).\n\t */\n\trowUnit?: number;\n};\n\nexport type UseLanePlacementResult = {\n\t/**\n\t * Inline styles to apply to each item, keyed by item key. On\n\t * native (`display: grid-lanes`), entries carry only\n\t * `gridColumn: span N`; the browser handles row placement. While\n\t * polyfilling, entries also carry explicit `grid-column-start` /\n\t * `grid-row-*` values.\n\t */\n\titemStyles: Map< string, React.CSSProperties >;\n\n\t/**\n\t * `false` when the host browser supports `display: grid-lanes`\n\t * natively. The hook avoids mounting any observers in that case.\n\t */\n\tisPolyfilled: boolean;\n};\n\n/**\n * Hook that measures item heights and resolves their placement when\n * `display: grid-lanes` is unavailable, falling through to a no-op\n * pass when the host browser supports the feature natively.\n *\n * Usage from the renderer:\n *\n * ```tsx\n * const [ container, setContainer ] = useState< HTMLDivElement | null >( null );\n * const { itemStyles } = useLanePlacement( container, {\n * items: layout,\n * lanes: columns,\n * gap: gapPx,\n * flowTolerance: 16,\n * } );\n *\n * return (\n * <div ref={ setContainer } style={ { display: 'grid-lanes', ... } }>\n * { items.map( ( item ) => (\n * <div\n * key={ item.key }\n * data-wp-grid-item-key={ item.key }\n * style={ itemStyles.get( item.key ) }\n * >\n * { ... }\n * </div>\n * ) ) }\n * </div>\n * );\n * ```\n *\n * @param container HTMLElement (or null pre-mount) hosting the items.\n * @param input Logical items, lane count, gap, and tuning.\n * @return Per-item styles plus the `isPolyfilled` flag.\n */\nexport function useLanePlacement(\n\tcontainer: HTMLElement | null,\n\tinput: UseLanePlacementInput\n): UseLanePlacementResult {\n\t// Detect once at mount. SSR returns `true` (CSS undefined); the\n\t// client-first render returns the real value. Either path produces\n\t// the same DOM until the polyfill effect runs (both emit\n\t// span-only styles), so there is no hydration mismatch.\n\tconst [ isPolyfilled ] = useState( () => ! supportsGridLanes() );\n\n\tconst [ itemStyles, setItemStyles ] = useState<\n\t\tMap< string, React.CSSProperties >\n\t>( () => new Map() );\n\n\t// Native pass-through: items only need their column span; the\n\t// browser handles row placement. Memoized so a stable items\n\t// array yields a stable Map identity.\n\tconst nativeStyles = useMemo( () => {\n\t\tconst map = new Map< string, React.CSSProperties >();\n\t\tfor ( const item of input.items ) {\n\t\t\tmap.set( item.key, {\n\t\t\t\tgridColumn: `span ${ clampSpan( item.span ) }`,\n\t\t\t} );\n\t\t}\n\t\treturn map;\n\t}, [ input.items ] );\n\n\t// Stable signature of items for deps. Keys, spans, and explicit\n\t// lanes are the only fields that influence observer wiring or\n\t// placement, so we hash exactly those.\n\tconst itemsSignature = useMemo( () => {\n\t\treturn input.items\n\t\t\t.map(\n\t\t\t\t( item ) =>\n\t\t\t\t\t`${ item.key }/${ item.span ?? 1 }/${ item.lane ?? '' }`\n\t\t\t)\n\t\t\t.join( '\\0' );\n\t}, [ input.items ] );\n\n\t// Stable array identity while placement-relevant fields match\n\t// `itemsSignature`, so the layout effect is not torn down on every\n\t// parent re-render that passes a fresh `items` reference.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- `itemsSignature` encodes keys/spans/lanes; `input.items` reference often changes without placement changes.\n\tconst itemsForPlacement = useMemo( () => input.items, [ itemsSignature ] );\n\n\tconst { lanes, gap, flowTolerance, rowUnit } = input;\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! isPolyfilled || ! container ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( typeof ResizeObserver === 'undefined' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst heights = new Map< string, number >();\n\t\tconst observed = new Set< Element >();\n\t\tlet cancelled = false;\n\t\tlet rafId: number | null = null;\n\n\t\tconst recompute = () => {\n\t\t\tif ( rafId !== null || cancelled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// One layout per frame even when ResizeObserver and\n\t\t\t// MutationObserver fire in the same tick.\n\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\trafId = null;\n\t\t\t\tif ( cancelled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst itemsWithHeight = itemsForPlacement.map( ( item ) => ( {\n\t\t\t\t\tkey: item.key,\n\t\t\t\t\tspan: clampSpan( item.span ),\n\t\t\t\t\tlane: item.lane,\n\t\t\t\t\theight: heights.get( item.key ) ?? 0,\n\t\t\t\t} ) );\n\t\t\t\tconst result = computeLanePlacements( {\n\t\t\t\t\titems: itemsWithHeight,\n\t\t\t\t\tlanes,\n\t\t\t\t\tgap,\n\t\t\t\t\tflowTolerance,\n\t\t\t\t} );\n\t\t\t\tconst effectiveRowUnit = Math.max(\n\t\t\t\t\t1,\n\t\t\t\t\trowUnit ?? DEFAULT_ROW_UNIT\n\t\t\t\t);\n\t\t\t\tconst next = new Map< string, React.CSSProperties >();\n\t\t\t\tfor ( const item of itemsForPlacement ) {\n\t\t\t\t\tconst placement = result.placements.get( item.key );\n\t\t\t\t\tif ( ! placement ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst height = heights.get( item.key ) ?? 0;\n\t\t\t\t\tconst rowStart =\n\t\t\t\t\t\tMath.floor( placement.top / effectiveRowUnit ) + 1;\n\t\t\t\t\tconst rowSpan = Math.max(\n\t\t\t\t\t\t1,\n\t\t\t\t\t\tMath.ceil( height / effectiveRowUnit )\n\t\t\t\t\t);\n\t\t\t\t\tnext.set( item.key, {\n\t\t\t\t\t\tgridColumnStart: placement.lane + 1,\n\t\t\t\t\t\tgridColumnEnd: `span ${ placement.span }`,\n\t\t\t\t\t\tgridRowStart: rowStart,\n\t\t\t\t\t\tgridRowEnd: `span ${ rowSpan }`,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tsetItemStyles( next );\n\t\t\t} );\n\t\t};\n\n\t\tconst resizeObserver = new ResizeObserver( ( entries ) => {\n\t\t\tlet changed = false;\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst key = ( entry.target as HTMLElement ).getAttribute(\n\t\t\t\t\tGRID_ITEM_DATA_KEY\n\t\t\t\t);\n\t\t\t\tif ( ! key ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst newHeight = entry.contentRect.height;\n\t\t\t\tif ( heights.get( key ) !== newHeight ) {\n\t\t\t\t\theights.set( key, newHeight );\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( changed ) {\n\t\t\t\trecompute();\n\t\t\t}\n\t\t} );\n\n\t\tconst refreshObserved = () => {\n\t\t\tconst current = container.querySelectorAll(\n\t\t\t\t`[${ GRID_ITEM_DATA_KEY }]`\n\t\t\t);\n\t\t\tfor ( const element of current ) {\n\t\t\t\tif ( ! observed.has( element ) ) {\n\t\t\t\t\tobserved.add( element );\n\t\t\t\t\tresizeObserver.observe( element );\n\t\t\t\t\tconst key = element.getAttribute( GRID_ITEM_DATA_KEY );\n\t\t\t\t\tif ( key ) {\n\t\t\t\t\t\tconst rect = (\n\t\t\t\t\t\t\telement as HTMLElement\n\t\t\t\t\t\t ).getBoundingClientRect();\n\t\t\t\t\t\theights.set( key, rect.height );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor ( const element of observed ) {\n\t\t\t\tif ( ! container.contains( element ) ) {\n\t\t\t\t\tresizeObserver.unobserve( element );\n\t\t\t\t\tobserved.delete( element );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Children may mount, unmount, or change `data-wp-grid-item-key`\n\t\t// after the container exists (drag reorders, additions). The\n\t\t// mutation observer keeps the observed set in sync.\n\t\tconst mutationObserver =\n\t\t\ttypeof MutationObserver !== 'undefined'\n\t\t\t\t? new MutationObserver( () => {\n\t\t\t\t\t\trefreshObserved();\n\t\t\t\t\t\trecompute();\n\t\t\t\t\t} )\n\t\t\t\t: null;\n\t\tif ( mutationObserver ) {\n\t\t\tmutationObserver.observe( container, {\n\t\t\t\tchildList: true,\n\t\t\t\tsubtree: true,\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: [ GRID_ITEM_DATA_KEY ],\n\t\t\t} );\n\t\t}\n\n\t\trefreshObserved();\n\t\trecompute();\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif ( rafId !== null ) {\n\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t}\n\t\t\tresizeObserver.disconnect();\n\t\t\tmutationObserver?.disconnect();\n\t\t};\n\t}, [\n\t\tcontainer,\n\t\tisPolyfilled,\n\t\tlanes,\n\t\tgap,\n\t\tflowTolerance,\n\t\trowUnit,\n\t\titemsForPlacement,\n\t] );\n\n\tif ( ! isPolyfilled ) {\n\t\treturn { itemStyles: nativeStyles, isPolyfilled: false };\n\t}\n\tif ( itemStyles.size === 0 ) {\n\t\t// Pre-measurement frame: emit native-shape styles so items\n\t\t// appear in their default span rather than collapsing to 1\n\t\t// column at the top-left.\n\t\treturn {\n\t\t\titemStyles: nativeStyles as Map< string, React.CSSProperties >,\n\t\t\tisPolyfilled: true,\n\t\t};\n\t}\n\treturn { itemStyles, isPolyfilled: true };\n}\n"],"mappings":";;;;;;;;;AAIA,MAAM,mBAAmB;AAEzB,SAAS,oBAA6B;CACrC,IAAK,OAAO,QAAQ,eAAe,CAAE,IAAI,UACxC,OAAO;CAER,OAAO,IAAI,SAAU,WAAW,YAAa;AAC9C;AAEA,SAAS,UAAW,MAAmC;CACtD,IAAK,OAAO,SAAS,YAAY,CAAE,OAAO,SAAU,IAAK,GACxD,OAAO;CAER,OAAO,KAAK,IAAK,GAAG,KAAK,MAAO,IAAK,CAAE;AACxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAgB,iBACf,WACA,OACyB;CAKzB,MAAM,CAAE,iBAAA,GAAiBA,mBAAAA,SAAAA,OAAgB,CAAE,kBAAkB,CAAE;CAE/D,MAAM,CAAE,YAAY,kBAAA,GAAkBA,mBAAAA,SAAA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AAQ,OAAQ;GAC1B;EAEF;EAKA,MAAM,mBACL,OAAO,qBAAqB,cACzB,IAAI,uBAAwB;GAC5B,gBAAgB;GAChB,UAAU;EACX,CAAE,IACD;EACJ,IAAK,kBACJ,iBAAiB,QAAS,WAAW;GACpC,WAAW;GACX,SAAS;GACT,YAAY;GACZ,iBAAiB,CAAEA,2BAAAA,kBAAmB;EACvC,CAAE;EAGH,gBAAgB;EAChB,UAAU;EAEV,aAAa;GACZ,YAAY;GACZ,IAAK,UAAU,MACd,qBAAsB,KAAM;GAE7B,eAAe,WAAW;GAC1B,kBAAkB,WAAW;EAC9B;CACD,GAAG;EACF;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAE;CAEF,IAAK,CAAE,cACN,OAAO;EAAE,YAAY;EAAc,cAAc;CAAM;CAExD,IAAK,WAAW,SAAS,GAIxB,OAAO;EACN,YAAY;EACZ,cAAc;CACf;CAED,OAAO;EAAE;EAAY,cAAc;CAAK;AACzC"}
package/build/index.cjs CHANGED
@@ -1,34 +1,19 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/grid/src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- DashboardGrid: () => import_dashboard_grid.DashboardGrid,
24
- DashboardLanes: () => import_dashboard_lanes.DashboardLanes
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
25
5
  });
26
- module.exports = __toCommonJS(index_exports);
27
- var import_dashboard_grid = require("./dashboard-grid/index.cjs");
28
- var import_dashboard_lanes = require("./dashboard-lanes/index.cjs");
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- DashboardGrid,
32
- DashboardLanes
6
+ let __dashboard_grid_index_tsx = require("./dashboard-grid/index.cjs");
7
+ let __dashboard_lanes_index_tsx = require("./dashboard-lanes/index.cjs");
8
+ Object.defineProperty(exports, "DashboardGrid", {
9
+ enumerable: true,
10
+ get: function() {
11
+ return __dashboard_grid_index_tsx.DashboardGrid;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "DashboardLanes", {
15
+ enumerable: true,
16
+ get: function() {
17
+ return __dashboard_lanes_index_tsx.DashboardLanes;
18
+ }
33
19
  });
34
- //# sourceMappingURL=index.cjs.map
@@ -1,49 +1,33 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/grid/src/shared/array-move-with-pinned.ts
21
- var array_move_with_pinned_exports = {};
22
- __export(array_move_with_pinned_exports, {
23
- arrayMoveWithPinned: () => arrayMoveWithPinned
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(array_move_with_pinned_exports);
26
- var import_sortable = require("@dnd-kit/sortable");
6
+ let _dnd_kit_sortable = require("@dnd-kit/sortable");
7
+ // packages/grid/src/shared/array-move-with-pinned.ts
8
+ /**
9
+ * Moves the item at `from` to `to` while pinned items hold their index:
10
+ * the free items reorder among the remaining slots. Moving a pinned item
11
+ * is a no-op.
12
+ *
13
+ * @param items Items in display order.
14
+ * @param from Index of the moved item.
15
+ * @param to Target index.
16
+ * @param isPinned Whether an item holds its index.
17
+ * @return The reordered items.
18
+ */
27
19
  function arrayMoveWithPinned(items, from, to, isPinned) {
28
- const pinned = new Set(items.filter(isPinned));
29
- if (pinned.size === 0) {
30
- return (0, import_sortable.arrayMove)(items, from, to);
31
- }
32
- const free = (0, import_sortable.arrayMove)(items, from, to).filter(
33
- (item) => !pinned.has(item)
34
- );
35
- let nextFree = 0;
36
- return items.map((item) => {
37
- if (pinned.has(item)) {
38
- return item;
39
- }
40
- const next = free[nextFree];
41
- nextFree += 1;
42
- return next;
43
- });
20
+ const pinned = new Set(items.filter(isPinned));
21
+ if (pinned.size === 0) return (0, _dnd_kit_sortable.arrayMove)(items, from, to);
22
+ const free = (0, _dnd_kit_sortable.arrayMove)(items, from, to).filter((item) => !pinned.has(item));
23
+ let nextFree = 0;
24
+ return items.map((item) => {
25
+ if (pinned.has(item)) return item;
26
+ const next = free[nextFree];
27
+ nextFree += 1;
28
+ return next;
29
+ });
44
30
  }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- arrayMoveWithPinned
48
- });
49
- //# sourceMappingURL=array-move-with-pinned.cjs.map
31
+ exports.arrayMoveWithPinned = arrayMoveWithPinned;
32
+
33
+ //# sourceMappingURL=array-move-with-pinned.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/shared/array-move-with-pinned.ts"],
4
- "sourcesContent": ["import { arrayMove } from '@dnd-kit/sortable';\n\n/**\n * Moves the item at `from` to `to` while pinned items hold their index:\n * the free items reorder among the remaining slots. Moving a pinned item\n * is a no-op.\n *\n * @param items Items in display order.\n * @param from Index of the moved item.\n * @param to Target index.\n * @param isPinned Whether an item holds its index.\n * @return The reordered items.\n */\nexport function arrayMoveWithPinned< T >(\n\titems: T[],\n\tfrom: number,\n\tto: number,\n\tisPinned: ( item: T ) => boolean\n): T[] {\n\tconst pinned = new Set( items.filter( isPinned ) );\n\tif ( pinned.size === 0 ) {\n\t\treturn arrayMove( items, from, to );\n\t}\n\tconst free = arrayMove( items, from, to ).filter(\n\t\t( item ) => ! pinned.has( item )\n\t);\n\tlet nextFree = 0;\n\treturn items.map( ( item ) => {\n\t\tif ( pinned.has( item ) ) {\n\t\t\treturn item;\n\t\t}\n\t\tconst next = free[ nextFree ];\n\t\tnextFree += 1;\n\t\treturn next;\n\t} );\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAanB,SAAS,oBACf,OACA,MACA,IACA,UACM;AACN,QAAM,SAAS,IAAI,IAAK,MAAM,OAAQ,QAAS,CAAE;AACjD,MAAK,OAAO,SAAS,GAAI;AACxB,eAAO,2BAAW,OAAO,MAAM,EAAG;AAAA,EACnC;AACA,QAAM,WAAO,2BAAW,OAAO,MAAM,EAAG,EAAE;AAAA,IACzC,CAAE,SAAU,CAAE,OAAO,IAAK,IAAK;AAAA,EAChC;AACA,MAAI,WAAW;AACf,SAAO,MAAM,IAAK,CAAE,SAAU;AAC7B,QAAK,OAAO,IAAK,IAAK,GAAI;AACzB,aAAO;AAAA,IACR;AACA,UAAM,OAAO,KAAM,QAAS;AAC5B,gBAAY;AACZ,WAAO;AAAA,EACR,CAAE;AACH;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"array-move-with-pinned.cjs","names":["arrayMove"],"sources":["../../src/shared/array-move-with-pinned.ts"],"sourcesContent":["import { arrayMove } from '@dnd-kit/sortable';\n\n/**\n * Moves the item at `from` to `to` while pinned items hold their index:\n * the free items reorder among the remaining slots. Moving a pinned item\n * is a no-op.\n *\n * @param items Items in display order.\n * @param from Index of the moved item.\n * @param to Target index.\n * @param isPinned Whether an item holds its index.\n * @return The reordered items.\n */\nexport function arrayMoveWithPinned< T >(\n\titems: T[],\n\tfrom: number,\n\tto: number,\n\tisPinned: ( item: T ) => boolean\n): T[] {\n\tconst pinned = new Set( items.filter( isPinned ) );\n\tif ( pinned.size === 0 ) {\n\t\treturn arrayMove( items, from, to );\n\t}\n\tconst free = arrayMove( items, from, to ).filter(\n\t\t( item ) => ! pinned.has( item )\n\t);\n\tlet nextFree = 0;\n\treturn items.map( ( item ) => {\n\t\tif ( pinned.has( item ) ) {\n\t\t\treturn item;\n\t\t}\n\t\tconst next = free[ nextFree ];\n\t\tnextFree += 1;\n\t\treturn next;\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,SAAgB,oBACf,OACA,MACA,IACA,UACM;CACN,MAAM,SAAS,IAAI,IAAK,MAAM,OAAQ,QAAS,CAAE;CACjD,IAAK,OAAO,SAAS,GACpB,QAAA,GAAOA,kBAAAA,UAAAA,CAAW,OAAO,MAAM,EAAG;CAEnC,MAAM,QAAA,GAAOA,kBAAAA,UAAAA,CAAW,OAAO,MAAM,EAAG,CAAC,CAAC,QACvC,SAAU,CAAE,OAAO,IAAK,IAAK,CAChC;CACA,IAAI,WAAW;CACf,OAAO,MAAM,KAAO,SAAU;EAC7B,IAAK,OAAO,IAAK,IAAK,GACrB,OAAO;EAER,MAAM,OAAO,KAAM;EACnB,YAAY;EACZ,OAAO;CACR,CAAE;AACH"}