@wordpress/grid 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -14
- package/build/dashboard-grid/grid-item.cjs +232 -295
- package/build/dashboard-grid/grid-item.cjs.map +1 -7
- package/build/dashboard-grid/index.cjs +526 -633
- package/build/dashboard-grid/index.cjs.map +1 -7
- package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
- package/build/dashboard-grid/types.cjs +4 -18
- package/build/dashboard-lanes/index.cjs +495 -577
- package/build/dashboard-lanes/index.cjs.map +1 -7
- package/build/dashboard-lanes/lane-placement.cjs +77 -100
- package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
- package/build/dashboard-lanes/lanes-item.cjs +222 -278
- package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
- package/build/dashboard-lanes/types.cjs +4 -18
- package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
- package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
- package/build/index.cjs +16 -31
- package/build/shared/array-move-with-pinned.cjs +29 -45
- package/build/shared/array-move-with-pinned.cjs.map +1 -7
- package/build/shared/column-policy.cjs +58 -0
- package/build/shared/column-policy.cjs.map +1 -0
- package/build/shared/drag-overlay-drop-animation.cjs +40 -66
- package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
- package/build/shared/grid-item-key.cjs +12 -29
- package/build/shared/grid-item-key.cjs.map +1 -7
- package/build/shared/grid-overlay.cjs +163 -164
- package/build/shared/grid-overlay.cjs.map +1 -7
- package/build/shared/item-exit-overlay.cjs +132 -134
- package/build/shared/item-exit-overlay.cjs.map +1 -7
- package/build/shared/resize-handle.cjs +213 -197
- package/build/shared/resize-handle.cjs.map +1 -7
- package/build/shared/resize-snap.cjs +116 -121
- package/build/shared/resize-snap.cjs.map +1 -7
- package/build/shared/types.cjs +4 -18
- package/build/shared/use-item-exit-animation.cjs +96 -143
- package/build/shared/use-item-exit-animation.cjs.map +1 -7
- package/build/shared/use-layout-shift-animation.cjs +121 -150
- package/build/shared/use-layout-shift-animation.cjs.map +1 -7
- package/build/shared/use-span-bounds.cjs +65 -79
- package/build/shared/use-span-bounds.cjs.map +1 -7
- package/build-module/dashboard-grid/grid-item.mjs +209 -265
- package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
- package/build-module/dashboard-grid/index.mjs +502 -623
- package/build-module/dashboard-grid/index.mjs.map +1 -7
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
- package/build-module/dashboard-grid/types.mjs +0 -1
- package/build-module/dashboard-lanes/index.mjs +470 -567
- package/build-module/dashboard-lanes/index.mjs.map +1 -7
- package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
- package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
- package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
- package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
- package/build-module/dashboard-lanes/types.mjs +0 -1
- package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
- package/build-module/index.mjs +1 -6
- package/build-module/shared/array-move-with-pinned.mjs +25 -21
- package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
- package/build-module/shared/column-policy.mjs +52 -0
- package/build-module/shared/column-policy.mjs.map +1 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
- package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
- package/build-module/shared/grid-item-key.mjs +8 -5
- package/build-module/shared/grid-item-key.mjs.map +1 -7
- package/build-module/shared/grid-overlay.mjs +143 -136
- package/build-module/shared/grid-overlay.mjs.map +1 -7
- package/build-module/shared/item-exit-overlay.mjs +128 -110
- package/build-module/shared/item-exit-overlay.mjs.map +1 -7
- package/build-module/shared/resize-handle.mjs +191 -171
- package/build-module/shared/resize-handle.mjs.map +1 -7
- package/build-module/shared/resize-snap.mjs +108 -93
- package/build-module/shared/resize-snap.mjs.map +1 -7
- package/build-module/shared/types.mjs +0 -1
- package/build-module/shared/use-item-exit-animation.mjs +92 -124
- package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
- package/build-module/shared/use-layout-shift-animation.mjs +114 -123
- package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
- package/build-module/shared/use-span-bounds.mjs +60 -57
- package/build-module/shared/use-span-bounds.mjs.map +1 -7
- package/build-types/dashboard-grid/index.d.ts.map +1 -1
- package/build-types/dashboard-grid/types.d.ts +9 -5
- package/build-types/dashboard-grid/types.d.ts.map +1 -1
- package/build-types/dashboard-lanes/index.d.ts.map +1 -1
- package/build-types/dashboard-lanes/types.d.ts +9 -5
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/shared/column-policy.d.ts +43 -0
- package/build-types/shared/column-policy.d.ts.map +1 -0
- package/package.json +14 -12
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/{grid.module.css → grid.module.scss} +10 -19
- package/src/dashboard-grid/index.tsx +12 -13
- package/src/dashboard-grid/stories/index.story.tsx +129 -50
- package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-grid/types.ts +9 -5
- package/src/dashboard-lanes/index.tsx +13 -13
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- package/src/dashboard-lanes/{lanes.module.css → lanes.module.scss} +10 -19
- package/src/dashboard-lanes/stories/index.story.tsx +124 -28
- package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-lanes/types.ts +9 -5
- package/src/index.ts +1 -0
- package/src/shared/column-policy.ts +100 -0
- package/src/shared/test/column-policy.test.ts +215 -0
- package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
- package/build/dashboard-grid/types.cjs.map +0 -7
- package/build/dashboard-lanes/types.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/shared/types.cjs.map +0 -7
- package/build-module/dashboard-grid/types.mjs.map +0 -7
- package/build-module/dashboard-lanes/types.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/shared/types.mjs.map +0 -7
|
@@ -1,140 +1,131 @@
|
|
|
1
|
-
// packages/grid/src/shared/use-layout-shift-animation.ts
|
|
2
1
|
import { useCallback, useLayoutEffect, useRef } from "@wordpress/element";
|
|
3
2
|
import { GRID_ITEM_DATA_KEY } from "./grid-item-key.mjs";
|
|
3
|
+
// packages/grid/src/shared/use-layout-shift-animation.ts
|
|
4
4
|
function queryGridItems(container) {
|
|
5
|
-
|
|
6
|
-
container.querySelectorAll(
|
|
7
|
-
`[${GRID_ITEM_DATA_KEY}]:not([data-wp-grid-item-exiting])`
|
|
8
|
-
)
|
|
9
|
-
);
|
|
5
|
+
return Array.from(container.querySelectorAll(`[${GRID_ITEM_DATA_KEY}]:not([data-wp-grid-item-exiting])`));
|
|
10
6
|
}
|
|
11
7
|
function readItemKey(element) {
|
|
12
|
-
|
|
8
|
+
return element.getAttribute(GRID_ITEM_DATA_KEY);
|
|
13
9
|
}
|
|
14
10
|
function snapshotPositions(container) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return positions;
|
|
11
|
+
const base = container.getBoundingClientRect();
|
|
12
|
+
const positions = /* @__PURE__ */ new Map();
|
|
13
|
+
for (const element of queryGridItems(container)) {
|
|
14
|
+
const key = readItemKey(element);
|
|
15
|
+
if (!key) continue;
|
|
16
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
17
|
+
positions.set(key, {
|
|
18
|
+
left: left - base.left,
|
|
19
|
+
top: top - base.top,
|
|
20
|
+
width,
|
|
21
|
+
height
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return positions;
|
|
31
25
|
}
|
|
32
26
|
function clearLayoutShiftStyles(element) {
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
element.style.removeProperty("transform");
|
|
28
|
+
element.style.removeProperty("transition");
|
|
35
29
|
}
|
|
36
30
|
function playLayoutShift(element, deltaX, deltaY) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
clearLayoutShiftStyles(element);
|
|
52
|
-
};
|
|
53
|
-
element.addEventListener("transitionend", onTransitionEnd);
|
|
54
|
-
});
|
|
31
|
+
if (deltaX === 0 && deltaY === 0) return;
|
|
32
|
+
element.style.transition = "none";
|
|
33
|
+
element.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
|
|
34
|
+
element.offsetHeight;
|
|
35
|
+
requestAnimationFrame(() => {
|
|
36
|
+
element.style.removeProperty("transition");
|
|
37
|
+
element.style.transform = "";
|
|
38
|
+
const onTransitionEnd = (event) => {
|
|
39
|
+
if (event.propertyName !== "transform") return;
|
|
40
|
+
element.removeEventListener("transitionend", onTransitionEnd);
|
|
41
|
+
clearLayoutShiftStyles(element);
|
|
42
|
+
};
|
|
43
|
+
element.addEventListener("transitionend", onTransitionEnd);
|
|
44
|
+
});
|
|
55
45
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
captureLayoutSnapshot,
|
|
115
|
-
getLastPositions,
|
|
116
|
-
getPositionsBeforeLastChange
|
|
117
|
-
};
|
|
46
|
+
/**
|
|
47
|
+
* Animates sibling tiles when grid layout reflows during drag or resize
|
|
48
|
+
* using a FLIP transform (see `layout-shift-animation.module.css`).
|
|
49
|
+
*
|
|
50
|
+
* @param root0 Hook options.
|
|
51
|
+
* @param root0.container Surface root that contains grid tiles.
|
|
52
|
+
* @param root0.enabled When false, snapshots are cleared and no transforms run.
|
|
53
|
+
* @param root0.layoutFingerprint Serialized layout/placement state.
|
|
54
|
+
* @param root0.excludeItemKey Item key to skip (the tile being dragged or resized).
|
|
55
|
+
* @return Snapshot capture callback for use before layout updates.
|
|
56
|
+
*/
|
|
57
|
+
function useLayoutShiftAnimation({ container, enabled, layoutFingerprint, excludeItemKey = null }) {
|
|
58
|
+
const snapshotBeforeChangeRef = useRef(null);
|
|
59
|
+
const lastRenderedPositionsRef = useRef(null);
|
|
60
|
+
const positionsBeforeLastChangeRef = useRef(null);
|
|
61
|
+
const captureLayoutSnapshot = useCallback(() => {
|
|
62
|
+
if (container) snapshotBeforeChangeRef.current = snapshotPositions(container);
|
|
63
|
+
}, [container]);
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
if (!container || !enabled) {
|
|
66
|
+
snapshotBeforeChangeRef.current = null;
|
|
67
|
+
lastRenderedPositionsRef.current = null;
|
|
68
|
+
positionsBeforeLastChangeRef.current = null;
|
|
69
|
+
if (container) for (const element of queryGridItems(container)) clearLayoutShiftStyles(element);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const element of queryGridItems(container)) clearLayoutShiftStyles(element);
|
|
73
|
+
const previous = snapshotBeforeChangeRef.current ?? lastRenderedPositionsRef.current;
|
|
74
|
+
snapshotBeforeChangeRef.current = null;
|
|
75
|
+
positionsBeforeLastChangeRef.current = previous ? new Map(previous) : null;
|
|
76
|
+
lastRenderedPositionsRef.current = snapshotPositions(container);
|
|
77
|
+
if (previous) {
|
|
78
|
+
const base = container.getBoundingClientRect();
|
|
79
|
+
for (const element of queryGridItems(container)) {
|
|
80
|
+
const key = readItemKey(element);
|
|
81
|
+
if (!key || key === excludeItemKey) continue;
|
|
82
|
+
const old = previous.get(key);
|
|
83
|
+
if (!old) continue;
|
|
84
|
+
const { left, top } = element.getBoundingClientRect();
|
|
85
|
+
playLayoutShift(element, old.left - (left - base.left), old.top - (top - base.top));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, [
|
|
89
|
+
container,
|
|
90
|
+
enabled,
|
|
91
|
+
layoutFingerprint,
|
|
92
|
+
excludeItemKey
|
|
93
|
+
]);
|
|
94
|
+
return {
|
|
95
|
+
captureLayoutSnapshot,
|
|
96
|
+
getLastPositions: useCallback(() => {
|
|
97
|
+
return lastRenderedPositionsRef.current;
|
|
98
|
+
}, []),
|
|
99
|
+
getPositionsBeforeLastChange: useCallback(() => {
|
|
100
|
+
return positionsBeforeLastChangeRef.current;
|
|
101
|
+
}, [])
|
|
102
|
+
};
|
|
118
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Stable fingerprint for {@link useLayoutShiftAnimation}. Width/height
|
|
106
|
+
* values may be numbers or layout keywords (`'fill'`, `'full'`).
|
|
107
|
+
*
|
|
108
|
+
* @param layout Layout items to serialize.
|
|
109
|
+
* @return Fingerprint string.
|
|
110
|
+
*/
|
|
119
111
|
function getLayoutFingerprint(layout) {
|
|
120
|
-
|
|
121
|
-
(item) => `${item.key}:${String(item.width ?? "")}:${item.height ?? 1}:${item.order ?? ""}:${item.lane ?? ""}`
|
|
122
|
-
).join("|");
|
|
112
|
+
return layout.map((item) => `${item.key}:${String(item.width ?? "")}:${item.height ?? 1}:${item.order ?? ""}:${item.lane ?? ""}`).join("|");
|
|
123
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Placement fingerprint for lanes polyfill / explicit grid positions.
|
|
116
|
+
*
|
|
117
|
+
* @param itemStyles Per-item inline placement styles.
|
|
118
|
+
* @return Fingerprint string.
|
|
119
|
+
*/
|
|
124
120
|
function getPlacementFingerprint(itemStyles) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)}:${String(rowStart)}:${String(rowEnd)}`;
|
|
133
|
-
}).join("|");
|
|
121
|
+
return [...itemStyles.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([key, style]) => {
|
|
122
|
+
const column = style.gridColumn ?? "";
|
|
123
|
+
const columnStart = style.gridColumnStart ?? "";
|
|
124
|
+
const rowStart = style.gridRowStart ?? "";
|
|
125
|
+
const rowEnd = style.gridRowEnd ?? "";
|
|
126
|
+
return `${key}:${String(column)}:${String(columnStart)}:${String(rowStart)}:${String(rowEnd)}`;
|
|
127
|
+
}).join("|");
|
|
134
128
|
}
|
|
135
|
-
export {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
useLayoutShiftAnimation
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=use-layout-shift-animation.mjs.map
|
|
129
|
+
export { getLayoutFingerprint, getPlacementFingerprint, useLayoutShiftAnimation };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=use-layout-shift-animation.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/shared/use-layout-shift-animation.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useLayoutEffect, useRef } from '@wordpress/element';\nimport { GRID_ITEM_DATA_KEY } from './grid-item-key';\n\n/* `left`/`top` are relative to the grid container, not the viewport. */\nexport type RectSnapshot = {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n};\n\ntype UseLayoutShiftAnimationOptions = {\n\t/**\n\t * Surface root that contains grid tiles.\n\t */\n\tcontainer: HTMLElement | null;\n\n\t/**\n\t * When false, snapshots are cleared and no transforms run.\n\t */\n\tenabled: boolean;\n\n\t/**\n\t * Serialized layout/placement state. The hook runs FLIP when this\n\t * value changes while `enabled` is true.\n\t */\n\tlayoutFingerprint: string;\n\n\t/**\n\t * Item key to skip (the tile being dragged or resized).\n\t */\n\texcludeItemKey?: string | null;\n};\n\ntype UseLayoutShiftAnimationResult = {\n\t/**\n\t * Capture tile positions synchronously **before** a layout update\n\t * (call immediately before `setTemporaryLayout` / similar).\n\t */\n\tcaptureLayoutSnapshot: () => void;\n\n\t/**\n\t * Container-relative rects from the last committed paint (settled, no\n\t * FLIP invert transforms).\n\t */\n\tgetLastPositions: () => ReadonlyMap< string, RectSnapshot > | null;\n\n\t/**\n\t * Tile positions immediately before the latest layout commit. Used\n\t * by item-exit animation when keys drop out of `layout`.\n\t */\n\tgetPositionsBeforeLastChange: () => ReadonlyMap<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null;\n};\n\nfunction queryGridItems( container: HTMLElement ): HTMLElement[] {\n\treturn Array.from(\n\t\tcontainer.querySelectorAll< HTMLElement >(\n\t\t\t`[${ GRID_ITEM_DATA_KEY }]:not([data-wp-grid-item-exiting])`\n\t\t)\n\t);\n}\n\nfunction readItemKey( element: HTMLElement ): string | null {\n\treturn element.getAttribute( GRID_ITEM_DATA_KEY );\n}\n\nfunction snapshotPositions(\n\tcontainer: HTMLElement\n): Map< string, RectSnapshot > {\n\t// Measure relative to the container so positions stay valid even if the\n\t// page scroll shifts between capture and use (e.g. the document reflowing\n\t// shorter after a tile is removed).\n\tconst base = container.getBoundingClientRect();\n\tconst positions = new Map< string, RectSnapshot >();\n\tfor ( const element of queryGridItems( container ) ) {\n\t\tconst key = readItemKey( element );\n\t\tif ( ! key ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst { left, top, width, height } = element.getBoundingClientRect();\n\t\tpositions.set( key, {\n\t\t\tleft: left - base.left,\n\t\t\ttop: top - base.top,\n\t\t\twidth,\n\t\t\theight,\n\t\t} );\n\t}\n\treturn positions;\n}\n\nfunction clearLayoutShiftStyles( element: HTMLElement ): void {\n\telement.style.removeProperty( 'transform' );\n\telement.style.removeProperty( 'transition' );\n}\n\nfunction playLayoutShift(\n\telement: HTMLElement,\n\tdeltaX: number,\n\tdeltaY: number\n): void {\n\tif ( deltaX === 0 && deltaY === 0 ) {\n\t\treturn;\n\t}\n\n\t// Invert: show the tile where it was before the layout change.\n\telement.style.transition = 'none';\n\telement.style.transform = `translate(${ deltaX }px, ${ deltaY }px)`;\n\tvoid element.offsetHeight;\n\n\t// Play on the next frame so the inverted transform paints before\n\t// the transition back to the committed grid position.\n\trequestAnimationFrame( () => {\n\t\telement.style.removeProperty( 'transition' );\n\t\telement.style.transform = '';\n\n\t\tconst onTransitionEnd = ( event: TransitionEvent ) => {\n\t\t\tif ( event.propertyName !== 'transform' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telement.removeEventListener( 'transitionend', onTransitionEnd );\n\t\t\tclearLayoutShiftStyles( element );\n\t\t};\n\t\telement.addEventListener( 'transitionend', onTransitionEnd );\n\t} );\n}\n\n/**\n * Animates sibling tiles when grid layout reflows during drag or resize\n * using a FLIP transform (see `layout-shift-animation.module.css`).\n *\n * @param root0 Hook options.\n * @param root0.container Surface root that contains grid tiles.\n * @param root0.enabled When false, snapshots are cleared and no transforms run.\n * @param root0.layoutFingerprint Serialized layout/placement state.\n * @param root0.excludeItemKey Item key to skip (the tile being dragged or resized).\n * @return Snapshot capture callback for use before layout updates.\n */\nexport function useLayoutShiftAnimation( {\n\tcontainer,\n\tenabled,\n\tlayoutFingerprint,\n\texcludeItemKey = null,\n}: UseLayoutShiftAnimationOptions ): UseLayoutShiftAnimationResult {\n\tconst snapshotBeforeChangeRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\tconst lastRenderedPositionsRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\tconst positionsBeforeLastChangeRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\n\tconst captureLayoutSnapshot = useCallback( () => {\n\t\tif ( container ) {\n\t\t\tsnapshotBeforeChangeRef.current = snapshotPositions( container );\n\t\t}\n\t}, [ container ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! container || ! enabled ) {\n\t\t\tsnapshotBeforeChangeRef.current = null;\n\t\t\tlastRenderedPositionsRef.current = null;\n\t\t\tpositionsBeforeLastChangeRef.current = null;\n\t\t\tif ( container ) {\n\t\t\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\t\t\tclearLayoutShiftStyles( element );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\tclearLayoutShiftStyles( element );\n\t\t}\n\n\t\tconst previous =\n\t\t\tsnapshotBeforeChangeRef.current ?? lastRenderedPositionsRef.current;\n\t\tsnapshotBeforeChangeRef.current = null;\n\n\t\tpositionsBeforeLastChangeRef.current = previous\n\t\t\t? new Map( previous )\n\t\t\t: null;\n\n\t\t// Record settled grid positions for the next FLIP. Must run before\n\t\t// invert transforms — measuring after `playLayoutShift` would bake\n\t\t// translate offsets into the baseline and skew the next animation.\n\t\tlastRenderedPositionsRef.current = snapshotPositions( container );\n\n\t\tif ( previous ) {\n\t\t\tconst base = container.getBoundingClientRect();\n\t\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\t\tconst key = readItemKey( element );\n\t\t\t\tif ( ! key || key === excludeItemKey ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst old = previous.get( key );\n\t\t\t\tif ( ! old ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst { left, top } = element.getBoundingClientRect();\n\t\t\t\tconst deltaX = old.left - ( left - base.left );\n\t\t\t\tconst deltaY = old.top - ( top - base.top );\n\t\t\t\tplayLayoutShift( element, deltaX, deltaY );\n\t\t\t}\n\t\t}\n\t}, [ container, enabled, layoutFingerprint, excludeItemKey ] );\n\n\tconst getLastPositions = useCallback( () => {\n\t\treturn lastRenderedPositionsRef.current;\n\t}, [] );\n\n\tconst getPositionsBeforeLastChange = useCallback( () => {\n\t\treturn positionsBeforeLastChangeRef.current;\n\t}, [] );\n\n\treturn {\n\t\tcaptureLayoutSnapshot,\n\t\tgetLastPositions,\n\t\tgetPositionsBeforeLastChange,\n\t};\n}\n\n/**\n * Stable fingerprint for {@link useLayoutShiftAnimation}. Width/height\n * values may be numbers or layout keywords (`'fill'`, `'full'`).\n *\n * @param layout Layout items to serialize.\n * @return Fingerprint string.\n */\nexport function getLayoutFingerprint(\n\tlayout: ReadonlyArray< {\n\t\tkey: string;\n\t\twidth?: number | string;\n\t\theight?: number;\n\t\torder?: number;\n\t\tlane?: number;\n\t} >\n): string {\n\treturn layout\n\t\t.map(\n\t\t\t( item ) =>\n\t\t\t\t`${ item.key }:${ String( item.width ?? '' ) }:${\n\t\t\t\t\titem.height ?? 1\n\t\t\t\t}:${ item.order ?? '' }:${ item.lane ?? '' }`\n\t\t)\n\t\t.join( '|' );\n}\n\n/**\n * Placement fingerprint for lanes polyfill / explicit grid positions.\n *\n * @param itemStyles Per-item inline placement styles.\n * @return Fingerprint string.\n */\nexport function getPlacementFingerprint(\n\titemStyles: Map< string, React.CSSProperties >\n): string {\n\treturn [ ...itemStyles.entries() ]\n\t\t.sort( ( [ a ], [ b ] ) => a.localeCompare( b ) )\n\t\t.map( ( [ key, style ] ) => {\n\t\t\tconst column = style.gridColumn ?? '';\n\t\t\tconst columnStart = style.gridColumnStart ?? '';\n\t\t\tconst rowStart = style.gridRowStart ?? '';\n\t\t\tconst rowEnd = style.gridRowEnd ?? '';\n\t\t\treturn `${ key }:${ String( column ) }:${ String(\n\t\t\t\tcolumnStart\n\t\t\t) }:${ String( rowStart ) }:${ String( rowEnd ) }`;\n\t\t} )\n\t\t.join( '|' );\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,aAAa,iBAAiB,cAAc;AACrD,SAAS,0BAA0B;AAwDnC,SAAS,eAAgB,WAAwC;AAChE,SAAO,MAAM;AAAA,IACZ,UAAU;AAAA,MACT,IAAK,kBAAmB;AAAA,IACzB;AAAA,EACD;AACD;AAEA,SAAS,YAAa,SAAsC;AAC3D,SAAO,QAAQ,aAAc,kBAAmB;AACjD;AAEA,SAAS,kBACR,WAC8B;AAI9B,QAAM,OAAO,UAAU,sBAAsB;AAC7C,QAAM,YAAY,oBAAI,IAA4B;AAClD,aAAY,WAAW,eAAgB,SAAU,GAAI;AACpD,UAAM,MAAM,YAAa,OAAQ;AACjC,QAAK,CAAE,KAAM;AACZ;AAAA,IACD;AACA,UAAM,EAAE,MAAM,KAAK,OAAO,OAAO,IAAI,QAAQ,sBAAsB;AACnE,cAAU,IAAK,KAAK;AAAA,MACnB,MAAM,OAAO,KAAK;AAAA,MAClB,KAAK,MAAM,KAAK;AAAA,MAChB;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACA,SAAO;AACR;AAEA,SAAS,uBAAwB,SAA6B;AAC7D,UAAQ,MAAM,eAAgB,WAAY;AAC1C,UAAQ,MAAM,eAAgB,YAAa;AAC5C;AAEA,SAAS,gBACR,SACA,QACA,QACO;AACP,MAAK,WAAW,KAAK,WAAW,GAAI;AACnC;AAAA,EACD;AAGA,UAAQ,M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,MAAO,CAAE,IAAK;AAAA,MACzC;AAAA,IACD,CAAE,IAAK,OAAQ,QAAS,CAAE,IAAK,OAAQ,MAAO,CAAE;AAAA,EACjD,CAAE,EACD,KAAM,GAAI;AACb;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-layout-shift-animation.mjs","names":[],"sources":["../../src/shared/use-layout-shift-animation.ts"],"sourcesContent":["import { useCallback, useLayoutEffect, useRef } from '@wordpress/element';\nimport { GRID_ITEM_DATA_KEY } from './grid-item-key';\n\n/* `left`/`top` are relative to the grid container, not the viewport. */\nexport type RectSnapshot = {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n};\n\ntype UseLayoutShiftAnimationOptions = {\n\t/**\n\t * Surface root that contains grid tiles.\n\t */\n\tcontainer: HTMLElement | null;\n\n\t/**\n\t * When false, snapshots are cleared and no transforms run.\n\t */\n\tenabled: boolean;\n\n\t/**\n\t * Serialized layout/placement state. The hook runs FLIP when this\n\t * value changes while `enabled` is true.\n\t */\n\tlayoutFingerprint: string;\n\n\t/**\n\t * Item key to skip (the tile being dragged or resized).\n\t */\n\texcludeItemKey?: string | null;\n};\n\ntype UseLayoutShiftAnimationResult = {\n\t/**\n\t * Capture tile positions synchronously **before** a layout update\n\t * (call immediately before `setTemporaryLayout` / similar).\n\t */\n\tcaptureLayoutSnapshot: () => void;\n\n\t/**\n\t * Container-relative rects from the last committed paint (settled, no\n\t * FLIP invert transforms).\n\t */\n\tgetLastPositions: () => ReadonlyMap< string, RectSnapshot > | null;\n\n\t/**\n\t * Tile positions immediately before the latest layout commit. Used\n\t * by item-exit animation when keys drop out of `layout`.\n\t */\n\tgetPositionsBeforeLastChange: () => ReadonlyMap<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null;\n};\n\nfunction queryGridItems( container: HTMLElement ): HTMLElement[] {\n\treturn Array.from(\n\t\tcontainer.querySelectorAll< HTMLElement >(\n\t\t\t`[${ GRID_ITEM_DATA_KEY }]:not([data-wp-grid-item-exiting])`\n\t\t)\n\t);\n}\n\nfunction readItemKey( element: HTMLElement ): string | null {\n\treturn element.getAttribute( GRID_ITEM_DATA_KEY );\n}\n\nfunction snapshotPositions(\n\tcontainer: HTMLElement\n): Map< string, RectSnapshot > {\n\t// Measure relative to the container so positions stay valid even if the\n\t// page scroll shifts between capture and use (e.g. the document reflowing\n\t// shorter after a tile is removed).\n\tconst base = container.getBoundingClientRect();\n\tconst positions = new Map< string, RectSnapshot >();\n\tfor ( const element of queryGridItems( container ) ) {\n\t\tconst key = readItemKey( element );\n\t\tif ( ! key ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst { left, top, width, height } = element.getBoundingClientRect();\n\t\tpositions.set( key, {\n\t\t\tleft: left - base.left,\n\t\t\ttop: top - base.top,\n\t\t\twidth,\n\t\t\theight,\n\t\t} );\n\t}\n\treturn positions;\n}\n\nfunction clearLayoutShiftStyles( element: HTMLElement ): void {\n\telement.style.removeProperty( 'transform' );\n\telement.style.removeProperty( 'transition' );\n}\n\nfunction playLayoutShift(\n\telement: HTMLElement,\n\tdeltaX: number,\n\tdeltaY: number\n): void {\n\tif ( deltaX === 0 && deltaY === 0 ) {\n\t\treturn;\n\t}\n\n\t// Invert: show the tile where it was before the layout change.\n\telement.style.transition = 'none';\n\telement.style.transform = `translate(${ deltaX }px, ${ deltaY }px)`;\n\tvoid element.offsetHeight;\n\n\t// Play on the next frame so the inverted transform paints before\n\t// the transition back to the committed grid position.\n\trequestAnimationFrame( () => {\n\t\telement.style.removeProperty( 'transition' );\n\t\telement.style.transform = '';\n\n\t\tconst onTransitionEnd = ( event: TransitionEvent ) => {\n\t\t\tif ( event.propertyName !== 'transform' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telement.removeEventListener( 'transitionend', onTransitionEnd );\n\t\t\tclearLayoutShiftStyles( element );\n\t\t};\n\t\telement.addEventListener( 'transitionend', onTransitionEnd );\n\t} );\n}\n\n/**\n * Animates sibling tiles when grid layout reflows during drag or resize\n * using a FLIP transform (see `layout-shift-animation.module.css`).\n *\n * @param root0 Hook options.\n * @param root0.container Surface root that contains grid tiles.\n * @param root0.enabled When false, snapshots are cleared and no transforms run.\n * @param root0.layoutFingerprint Serialized layout/placement state.\n * @param root0.excludeItemKey Item key to skip (the tile being dragged or resized).\n * @return Snapshot capture callback for use before layout updates.\n */\nexport function useLayoutShiftAnimation( {\n\tcontainer,\n\tenabled,\n\tlayoutFingerprint,\n\texcludeItemKey = null,\n}: UseLayoutShiftAnimationOptions ): UseLayoutShiftAnimationResult {\n\tconst snapshotBeforeChangeRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\tconst lastRenderedPositionsRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\tconst positionsBeforeLastChangeRef = useRef< Map<\n\t\tstring,\n\t\tRectSnapshot\n\t> | null >( null );\n\n\tconst captureLayoutSnapshot = useCallback( () => {\n\t\tif ( container ) {\n\t\t\tsnapshotBeforeChangeRef.current = snapshotPositions( container );\n\t\t}\n\t}, [ container ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! container || ! enabled ) {\n\t\t\tsnapshotBeforeChangeRef.current = null;\n\t\t\tlastRenderedPositionsRef.current = null;\n\t\t\tpositionsBeforeLastChangeRef.current = null;\n\t\t\tif ( container ) {\n\t\t\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\t\t\tclearLayoutShiftStyles( element );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\tclearLayoutShiftStyles( element );\n\t\t}\n\n\t\tconst previous =\n\t\t\tsnapshotBeforeChangeRef.current ?? lastRenderedPositionsRef.current;\n\t\tsnapshotBeforeChangeRef.current = null;\n\n\t\tpositionsBeforeLastChangeRef.current = previous\n\t\t\t? new Map( previous )\n\t\t\t: null;\n\n\t\t// Record settled grid positions for the next FLIP. Must run before\n\t\t// invert transforms — measuring after `playLayoutShift` would bake\n\t\t// translate offsets into the baseline and skew the next animation.\n\t\tlastRenderedPositionsRef.current = snapshotPositions( container );\n\n\t\tif ( previous ) {\n\t\t\tconst base = container.getBoundingClientRect();\n\t\t\tfor ( const element of queryGridItems( container ) ) {\n\t\t\t\tconst key = readItemKey( element );\n\t\t\t\tif ( ! key || key === excludeItemKey ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst old = previous.get( key );\n\t\t\t\tif ( ! old ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst { left, top } = element.getBoundingClientRect();\n\t\t\t\tconst deltaX = old.left - ( left - base.left );\n\t\t\t\tconst deltaY = old.top - ( top - base.top );\n\t\t\t\tplayLayoutShift( element, deltaX, deltaY );\n\t\t\t}\n\t\t}\n\t}, [ container, enabled, layoutFingerprint, excludeItemKey ] );\n\n\tconst getLastPositions = useCallback( () => {\n\t\treturn lastRenderedPositionsRef.current;\n\t}, [] );\n\n\tconst getPositionsBeforeLastChange = useCallback( () => {\n\t\treturn positionsBeforeLastChangeRef.current;\n\t}, [] );\n\n\treturn {\n\t\tcaptureLayoutSnapshot,\n\t\tgetLastPositions,\n\t\tgetPositionsBeforeLastChange,\n\t};\n}\n\n/**\n * Stable fingerprint for {@link useLayoutShiftAnimation}. Width/height\n * values may be numbers or layout keywords (`'fill'`, `'full'`).\n *\n * @param layout Layout items to serialize.\n * @return Fingerprint string.\n */\nexport function getLayoutFingerprint(\n\tlayout: ReadonlyArray< {\n\t\tkey: string;\n\t\twidth?: number | string;\n\t\theight?: number;\n\t\torder?: number;\n\t\tlane?: number;\n\t} >\n): string {\n\treturn layout\n\t\t.map(\n\t\t\t( item ) =>\n\t\t\t\t`${ item.key }:${ String( item.width ?? '' ) }:${\n\t\t\t\t\titem.height ?? 1\n\t\t\t\t}:${ item.order ?? '' }:${ item.lane ?? '' }`\n\t\t)\n\t\t.join( '|' );\n}\n\n/**\n * Placement fingerprint for lanes polyfill / explicit grid positions.\n *\n * @param itemStyles Per-item inline placement styles.\n * @return Fingerprint string.\n */\nexport function getPlacementFingerprint(\n\titemStyles: Map< string, React.CSSProperties >\n): string {\n\treturn [ ...itemStyles.entries() ]\n\t\t.sort( ( [ a ], [ b ] ) => a.localeCompare( b ) )\n\t\t.map( ( [ key, style ] ) => {\n\t\t\tconst column = style.gridColumn ?? '';\n\t\t\tconst columnStart = style.gridColumnStart ?? '';\n\t\t\tconst rowStart = style.gridRowStart ?? '';\n\t\t\tconst rowEnd = style.gridRowEnd ?? '';\n\t\t\treturn `${ key }:${ String( column ) }:${ String(\n\t\t\t\tcolumnStart\n\t\t\t) }:${ String( rowStart ) }:${ String( rowEnd ) }`;\n\t\t} )\n\t\t.join( '|' );\n}\n"],"mappings":";;;AAyDA,SAAS,eAAgB,WAAwC;CAChE,OAAO,MAAM,KACZ,UAAU,iBACT,IAAK,mBAAoB,mCAC1B,CACD;AACD;AAEA,SAAS,YAAa,SAAsC;CAC3D,OAAO,QAAQ,aAAc,kBAAmB;AACjD;AAEA,SAAS,kBACR,WAC8B;CAI9B,MAAM,OAAO,UAAU,sBAAsB;CAC7C,MAAM,4BAAY,IAAI,IAA4B;CAClD,KAAM,MAAM,WAAW,eAAgB,SAAU,GAAI;EACpD,MAAM,MAAM,YAAa,OAAQ;EACjC,IAAK,CAAE,KACN;EAED,MAAM,EAAE,MAAM,KAAK,OAAO,WAAW,QAAQ,sBAAsB;EACnE,UAAU,IAAK,KAAK;GACnB,MAAM,OAAO,KAAK;GAClB,KAAK,MAAM,KAAK;GAChB;GACA;EACD,CAAE;CACH;CACA,OAAO;AACR;AAEA,SAAS,uBAAwB,SAA6B;CAC7D,QAAQ,MAAM,eAAgB,WAAY;CAC1C,QAAQ,MAAM,eAAgB,YAAa;AAC5C;AAEA,SAAS,gBACR,SACA,QACA,QACO;CACP,IAAK,WAAW,KAAK,WAAW,GAC/B;CAID,QAAQ,MAAM,aAAa;CAC3B,QAAQ,MAAM,YA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AAQ,QAAQ,sBAAsB;IAGpD,gBAAiB,SAFF,IAAI,QAAS,OAAO,KAAK,OACzB,IAAI,OAAQ,MAAM,KAAK,IACG;GAC1C;EACD;CACD,GAAG;EAAE;EAAW;EAAS;EAAmB;CAAe,CAAE;CAU7D,OAAO;EACN;EACA,kBAVwB,kBAAmB;GAC3C,OAAO,yBAAyB;EACjC,GAAG,CAAC,CAQY;EACf,8BAPoC,kBAAmB;GACvD,OAAO,6BAA6B;EACrC,GAAG,CAAC,CAKwB;CAC5B;AACD;;;;;;;;AASA,SAAgB,qBACf,QAOS;CACT,OAAO,OACL,KACE,SACD,GAAI,KAAK,IAAK,GAAI,OAAQ,KAAK,SAAS,EAAG,EAAG,GAC7C,KAAK,UAAU,EACf,GAAI,KAAK,SAAS,GAAI,GAAI,KAAK,QAAQ,IAC1C,CAAC,CACA,KAAM,GAAI;AACb;;;;;;;AAQA,SAAgB,wBACf,YACS;CACT,OAAO,CAAE,GAAG,WAAW,QAAQ,CAAE,CAAC,CAChC,MAAQ,CAAE,IAAK,CAAE,OAAS,EAAE,cAAe,CAAE,CAAE,CAAC,CAChD,KAAO,CAAE,KAAK,WAAa;EAC3B,MAAM,SAAS,MAAM,cAAc;EACnC,MAAM,cAAc,MAAM,mBAAmB;EAC7C,MAAM,WAAW,MAAM,gBAAgB;EACvC,MAAM,SAAS,MAAM,cAAc;EACnC,OAAO,GAAI,IAAK,GAAI,OAAQ,MAAO,EAAG,GAAI,OACzC,WACD,EAAG,GAAI,OAAQ,QAAS,EAAG,GAAI,OAAQ,MAAO;CAC/C,CAAE,CAAC,CACF,KAAM,GAAI;AACb"}
|
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
// packages/grid/src/shared/use-span-bounds.ts
|
|
2
1
|
import { useMemo } from "@wordpress/element";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { pixelLimitsToSpanBounds, spanBoundsToPixelLimits } from "./resize-snap.mjs";
|
|
3
|
+
// packages/grid/src/shared/use-span-bounds.ts
|
|
4
|
+
const NO_BOUNDS = /* @__PURE__ */ new Map();
|
|
5
|
+
const NO_LIMITS = /* @__PURE__ */ new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Quantizes per-item pixel limits to span bounds for the current
|
|
8
|
+
* geometry. The map keeps its identity while every bound is unchanged,
|
|
9
|
+
* so container width ticks and fresh `itemLimits` objects do not
|
|
10
|
+
* invalidate the layout memos or the sortable context downstream.
|
|
11
|
+
*
|
|
12
|
+
* @param itemLimits Per-item pixel limits, keyed by layout item key.
|
|
13
|
+
* @param columnWidth Width of one column track in pixels.
|
|
14
|
+
* @param gapPx Gap between tracks in pixels.
|
|
15
|
+
* @param rowHeightPx Row track height in pixels, or `null` when rows
|
|
16
|
+
* are content-sized.
|
|
17
|
+
* @param maxColumns Number of column tracks in the surface.
|
|
18
|
+
*/
|
|
9
19
|
function useSpanBounds(itemLimits, columnWidth, gapPx, rowHeightPx, maxColumns) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, [itemLimits, columnWidth, gapPx, rowHeightPx, maxColumns]);
|
|
29
|
-
const signature = useMemo(() => {
|
|
30
|
-
let value = "";
|
|
31
|
-
for (const [key, bounds] of computed) {
|
|
32
|
-
value += `${key}:${bounds.minWidth}:${bounds.minHeight}:${bounds.maxWidth}:${bounds.maxHeight}|`;
|
|
33
|
-
}
|
|
34
|
-
return value;
|
|
35
|
-
}, [computed]);
|
|
36
|
-
return useMemo(() => computed, [signature]);
|
|
20
|
+
const computed = useMemo(() => {
|
|
21
|
+
if (!itemLimits) return NO_BOUNDS;
|
|
22
|
+
const map = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const [key, limits] of Object.entries(itemLimits)) map.set(key, pixelLimitsToSpanBounds(limits, columnWidth, gapPx, rowHeightPx, maxColumns));
|
|
24
|
+
return map;
|
|
25
|
+
}, [
|
|
26
|
+
itemLimits,
|
|
27
|
+
columnWidth,
|
|
28
|
+
gapPx,
|
|
29
|
+
rowHeightPx,
|
|
30
|
+
maxColumns
|
|
31
|
+
]);
|
|
32
|
+
const signature = useMemo(() => {
|
|
33
|
+
let value = "";
|
|
34
|
+
for (const [key, bounds] of computed) value += `${key}:${bounds.minWidth}:${bounds.minHeight}:${bounds.maxWidth}:${bounds.maxHeight}|`;
|
|
35
|
+
return value;
|
|
36
|
+
}, [computed]);
|
|
37
|
+
return useMemo(() => computed, [signature]);
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Pixel limits for the resize gesture of every bounded item. Tracks
|
|
41
|
+
* the continuous geometry, but only recomputes when it changes, not on
|
|
42
|
+
* every gesture frame.
|
|
43
|
+
*
|
|
44
|
+
* @param spanBounds Span bounds per item key.
|
|
45
|
+
* @param columnWidth Width of one column track in pixels.
|
|
46
|
+
* @param gapPx Gap between tracks in pixels.
|
|
47
|
+
* @param rowHeightPx Row track height in pixels, or `null` when rows
|
|
48
|
+
* are content-sized.
|
|
49
|
+
*/
|
|
38
50
|
function useResizePixelLimits(spanBounds, columnWidth, gapPx, rowHeightPx) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
gapPx,
|
|
51
|
-
rowHeightPx
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return map;
|
|
56
|
-
}, [spanBounds, columnWidth, gapPx, rowHeightPx]);
|
|
51
|
+
return useMemo(() => {
|
|
52
|
+
if (spanBounds.size === 0) return NO_LIMITS;
|
|
53
|
+
const map = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const [key, bounds] of spanBounds) map.set(key, spanBoundsToPixelLimits(bounds, columnWidth, gapPx, rowHeightPx));
|
|
55
|
+
return map;
|
|
56
|
+
}, [
|
|
57
|
+
spanBounds,
|
|
58
|
+
columnWidth,
|
|
59
|
+
gapPx,
|
|
60
|
+
rowHeightPx
|
|
61
|
+
]);
|
|
57
62
|
}
|
|
58
|
-
export {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=use-span-bounds.mjs.map
|
|
63
|
+
export { useResizePixelLimits, useSpanBounds };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=use-span-bounds.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/shared/use-span-bounds.ts"],
|
|
4
|
-
"sourcesContent": ["import { useMemo } from '@wordpress/element';\nimport {\n\tpixelLimitsToSpanBounds,\n\tspanBoundsToPixelLimits,\n} from './resize-snap';\nimport type { ResizePixelLimits, SpanBounds } from './resize-snap';\nimport type { GridItemLimits } from './types';\n\nconst NO_BOUNDS: ReadonlyMap< string, SpanBounds > = new Map();\nconst NO_LIMITS: ReadonlyMap< string, ResizePixelLimits > = new Map();\n\n/**\n * Quantizes per-item pixel limits to span bounds for the current\n * geometry. The map keeps its identity while every bound is unchanged,\n * so container width ticks and fresh `itemLimits` objects do not\n * invalidate the layout memos or the sortable context downstream.\n *\n * @param itemLimits Per-item pixel limits, keyed by layout item key.\n * @param columnWidth Width of one column track in pixels.\n * @param gapPx Gap between tracks in pixels.\n * @param rowHeightPx Row track height in pixels, or `null` when rows\n * are content-sized.\n * @param maxColumns Number of column tracks in the surface.\n */\nexport function useSpanBounds(\n\titemLimits: Record< string, GridItemLimits > | undefined,\n\tcolumnWidth: number,\n\tgapPx: number,\n\trowHeightPx: number | null,\n\tmaxColumns: number\n): ReadonlyMap< string, SpanBounds > {\n\tconst computed = useMemo( () => {\n\t\tif ( ! itemLimits ) {\n\t\t\treturn NO_BOUNDS;\n\t\t}\n\t\tconst map = new Map< string, SpanBounds >();\n\t\tfor ( const [ key, limits ] of Object.entries( itemLimits ) ) {\n\t\t\tmap.set(\n\t\t\t\tkey,\n\t\t\t\tpixelLimitsToSpanBounds(\n\t\t\t\t\tlimits,\n\t\t\t\t\tcolumnWidth,\n\t\t\t\t\tgapPx,\n\t\t\t\t\trowHeightPx,\n\t\t\t\t\tmaxColumns\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn map;\n\t}, [ itemLimits, columnWidth, gapPx, rowHeightPx, maxColumns ] );\n\n\tconst signature = useMemo( () => {\n\t\tlet value = '';\n\t\tfor ( const [ key, bounds ] of computed ) {\n\t\t\tvalue += `${ key }:${ bounds.minWidth }:${ bounds.minHeight }:${ bounds.maxWidth }:${ bounds.maxHeight }|`;\n\t\t}\n\t\treturn value;\n\t}, [ computed ] );\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- `signature` encodes every bound; `computed` changes identity on geometry ticks that leave the bounds unchanged.\n\treturn useMemo( () => computed, [ signature ] );\n}\n\n/**\n * Pixel limits for the resize gesture of every bounded item. Tracks\n * the continuous geometry, but only recomputes when it changes, not on\n * every gesture frame.\n *\n * @param spanBounds Span bounds per item key.\n * @param columnWidth Width of one column track in pixels.\n * @param gapPx Gap between tracks in pixels.\n * @param rowHeightPx Row track height in pixels, or `null` when rows\n * are content-sized.\n */\nexport function useResizePixelLimits(\n\tspanBounds: ReadonlyMap< string, SpanBounds >,\n\tcolumnWidth: number,\n\tgapPx: number,\n\trowHeightPx: number | null\n): ReadonlyMap< string, ResizePixelLimits > {\n\treturn useMemo( () => {\n\t\tif ( spanBounds.size === 0 ) {\n\t\t\treturn NO_LIMITS;\n\t\t}\n\t\tconst map = new Map< string, ResizePixelLimits >();\n\t\tfor ( const [ key, bounds ] of spanBounds ) {\n\t\t\tmap.set(\n\t\t\t\tkey,\n\t\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AAO,KAAK,YAAa;AAC3C,UAAI;AAAA,QACH;AAAA,QACA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACA,WAAO;AAAA,EACR,GAAG,CAAE,YAAY,aAAa,OAAO,WAAY,CAAE;AACpD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-span-bounds.mjs","names":[],"sources":["../../src/shared/use-span-bounds.ts"],"sourcesContent":["import { useMemo } from '@wordpress/element';\nimport {\n\tpixelLimitsToSpanBounds,\n\tspanBoundsToPixelLimits,\n} from './resize-snap';\nimport type { ResizePixelLimits, SpanBounds } from './resize-snap';\nimport type { GridItemLimits } from './types';\n\nconst NO_BOUNDS: ReadonlyMap< string, SpanBounds > = new Map();\nconst NO_LIMITS: ReadonlyMap< string, ResizePixelLimits > = new Map();\n\n/**\n * Quantizes per-item pixel limits to span bounds for the current\n * geometry. The map keeps its identity while every bound is unchanged,\n * so container width ticks and fresh `itemLimits` objects do not\n * invalidate the layout memos or the sortable context downstream.\n *\n * @param itemLimits Per-item pixel limits, keyed by layout item key.\n * @param columnWidth Width of one column track in pixels.\n * @param gapPx Gap between tracks in pixels.\n * @param rowHeightPx Row track height in pixels, or `null` when rows\n * are content-sized.\n * @param maxColumns Number of column tracks in the surface.\n */\nexport function useSpanBounds(\n\titemLimits: Record< string, GridItemLimits > | undefined,\n\tcolumnWidth: number,\n\tgapPx: number,\n\trowHeightPx: number | null,\n\tmaxColumns: number\n): ReadonlyMap< string, SpanBounds > {\n\tconst computed = useMemo( () => {\n\t\tif ( ! itemLimits ) {\n\t\t\treturn NO_BOUNDS;\n\t\t}\n\t\tconst map = new Map< string, SpanBounds >();\n\t\tfor ( const [ key, limits ] of Object.entries( itemLimits ) ) {\n\t\t\tmap.set(\n\t\t\t\tkey,\n\t\t\t\tpixelLimitsToSpanBounds(\n\t\t\t\t\tlimits,\n\t\t\t\t\tcolumnWidth,\n\t\t\t\t\tgapPx,\n\t\t\t\t\trowHeightPx,\n\t\t\t\t\tmaxColumns\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn map;\n\t}, [ itemLimits, columnWidth, gapPx, rowHeightPx, maxColumns ] );\n\n\tconst signature = useMemo( () => {\n\t\tlet value = '';\n\t\tfor ( const [ key, bounds ] of computed ) {\n\t\t\tvalue += `${ key }:${ bounds.minWidth }:${ bounds.minHeight }:${ bounds.maxWidth }:${ bounds.maxHeight }|`;\n\t\t}\n\t\treturn value;\n\t}, [ computed ] );\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- `signature` encodes every bound; `computed` changes identity on geometry ticks that leave the bounds unchanged.\n\treturn useMemo( () => computed, [ signature ] );\n}\n\n/**\n * Pixel limits for the resize gesture of every bounded item. Tracks\n * the continuous geometry, but only recomputes when it changes, not on\n * every gesture frame.\n *\n * @param spanBounds Span bounds per item key.\n * @param columnWidth Width of one column track in pixels.\n * @param gapPx Gap between tracks in pixels.\n * @param rowHeightPx Row track height in pixels, or `null` when rows\n * are content-sized.\n */\nexport function useResizePixelLimits(\n\tspanBounds: ReadonlyMap< string, SpanBounds >,\n\tcolumnWidth: number,\n\tgapPx: number,\n\trowHeightPx: number | null\n): ReadonlyMap< string, ResizePixelLimits > {\n\treturn useMemo( () => {\n\t\tif ( spanBounds.size === 0 ) {\n\t\t\treturn NO_LIMITS;\n\t\t}\n\t\tconst map = new Map< string, ResizePixelLimits >();\n\t\tfor ( const [ key, bounds ] of spanBounds ) {\n\t\t\tmap.set(\n\t\t\t\tkey,\n\t\t\t\tspanBoundsToPixelLimits(\n\t\t\t\t\tbounds,\n\t\t\t\t\tcolumnWidth,\n\t\t\t\t\tgapPx,\n\t\t\t\t\trowHeightPx\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn map;\n\t}, [ spanBounds, columnWidth, gapPx, rowHeightPx ] );\n}\n"],"mappings":";;;AAQA,MAAM,4BAA+C,IAAI,IAAI;AAC7D,MAAM,4BAAsD,IAAI,IAAI;;;;;;;;;;;;;;AAepE,SAAgB,cACf,YACA,aACA,OACA,aACA,YACoC;CACpC,MAAM,WAAW,cAAe;EAC/B,IAAK,CAAE,YACN,OAAO;EAER,MAAM,sBAAM,IAAI,IAA0B;EAC1C,KAAM,MAAM,CAAE,KAAK,WAAY,OAAO,QAAS,UAAW,GACzD,IAAI,IACH,KACA,wBACC,QACA,aACA,OACA,aACA,UACD,CACD;EAED,OAAO;CACR,GAAG;EAAE;EAAY;EAAa;EAAO;EAAa;CAAW,CAAE;CAE/D,MAAM,YAAY,cAAe;EAChC,IAAI,QAAQ;EACZ,KAAM,MAAM,CAAE,KAAK,WAAY,UAC9B,SAAS,GAAI,IAAK,GAAI,OAAO,SAAU,GAAI,OAAO,UAAW,GAAI,OAAO,SAAU,GAAI,OAAO,UAAW;EAEzG,OAAO;CACR,GAAG,CAAE,QAAS,CAAE;CAGhB,OAAO,cAAe,UAAU,CAAE,SAAU,CAAE;AAC/C;;;;;;;;;;;;AAaA,SAAgB,qBACf,YACA,aACA,OACA,aAC2C;CAC3C,OAAO,cAAe;EACrB,IAAK,WAAW,SAAS,GACxB,OAAO;EAER,MAAM,sBAAM,IAAI,IAAiC;EACjD,KAAM,MAAM,CAAE,KAAK,WAAY,YAC9B,IAAI,IACH,KACA,wBACC,QACA,aACA,OACA,WACD,CACD;EAED,OAAO;CACR,GAAG;EAAE;EAAY;EAAa;EAAO;CAAY,CAAE;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard-grid/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard-grid/index.tsx"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAA2B,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA8B3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,aAAa,+GA2rBzB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DragPreviewRenderProps, GridItemLimits, GridOverlayRenderProps, ResizeDelta, ResizeHandleRenderProps } from '../shared/types';
|
|
2
|
+
import type { ColumnSteps } from '../shared/column-policy';
|
|
2
3
|
import type { ResizeSnapSize } from '../shared/resize-snap';
|
|
3
4
|
/**
|
|
4
5
|
* Dashboard grid layout item definition.
|
|
@@ -157,7 +158,8 @@ export type GridItemProps = {
|
|
|
157
158
|
* the grid root.
|
|
158
159
|
*
|
|
159
160
|
* `columns` and `minColumnWidth` compose as a layered model:
|
|
160
|
-
* - `columns` alone:
|
|
161
|
+
* - `columns` alone: the count at every width, or a count per container
|
|
162
|
+
* width when given as `ColumnSteps`; each tile scales with the container.
|
|
161
163
|
* - `minColumnWidth` alone: column count derives from container width,
|
|
162
164
|
* floored by the per-tile minimum, down to 1 column.
|
|
163
165
|
* - Both together: `columns` caps the count, `minColumnWidth` enforces a
|
|
@@ -250,11 +252,13 @@ export interface DashboardGridProps extends Omit<React.ComponentPropsWithoutRef<
|
|
|
250
252
|
*/
|
|
251
253
|
renderGridOverlay?: React.ComponentType<GridOverlayRenderProps>;
|
|
252
254
|
/**
|
|
253
|
-
*
|
|
254
|
-
* `
|
|
255
|
-
*
|
|
255
|
+
* Column count, used as a cap. A number applies at every width; a
|
|
256
|
+
* `ColumnSteps` map applies a count from each container width up, and
|
|
257
|
+
* an `'auto'` step lifts the cap from its width up.
|
|
258
|
+
* Defaults to six when neither `columns` nor `minColumnWidth` is set;
|
|
259
|
+
* with `minColumnWidth` set it can resolve lower on narrow containers.
|
|
256
260
|
*/
|
|
257
|
-
columns?: number;
|
|
261
|
+
columns?: number | ColumnSteps;
|
|
258
262
|
/**
|
|
259
263
|
* Per-tile minimum width in pixels. Enables responsive mode: the
|
|
260
264
|
* column count derives from container width, floored by this value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","s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H,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAE,SAAS,EAAE,uBAAuB,EAAE,KAAM,IAAI,CAAC;IAElE;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAE,aAAa,EAAE,uBAAuB,EAAE,KAAM,IAAI,CAAC;IAEvE;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,uBAAuB,CAAE,CAAC;IAEpE;;;;;;;;;;;;;;OAcG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,sBAAsB,CAAE,CAAC;IAElE;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,sBAAsB,CAAE,CAAC;IAElE;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAE/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,cAAc,CAAE,CAAC;CAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard-lanes/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard-lanes/index.tsx"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAA4B,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAyB7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,cAAc,gHAikB1B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ColumnSteps } from '../shared/column-policy';
|
|
1
2
|
import type { DragPreviewRenderProps, GridItemWidthLimits, GridOverlayRenderProps, ResizeHandleRenderProps } from '../shared/types';
|
|
2
3
|
/**
|
|
3
4
|
* Lanes layout item definition.
|
|
@@ -51,7 +52,8 @@ export type DashboardLanesLayoutItem = {
|
|
|
51
52
|
* Props for `DashboardLanes`.
|
|
52
53
|
*
|
|
53
54
|
* `columns` and `minColumnWidth` compose as a layered model:
|
|
54
|
-
* - `columns` alone:
|
|
55
|
+
* - `columns` alone: the count at every width, or a count per container
|
|
56
|
+
* width when given as `ColumnSteps`; tiles scale with the container.
|
|
55
57
|
* - `minColumnWidth` alone: lane count derives from container width,
|
|
56
58
|
* floored by the per-tile minimum, down to 1.
|
|
57
59
|
* - Both together: `columns` caps the count, `minColumnWidth` enforces
|
|
@@ -147,11 +149,13 @@ export interface DashboardLanesProps extends Omit<React.ComponentPropsWithoutRef
|
|
|
147
149
|
*/
|
|
148
150
|
renderGridOverlay?: React.ComponentType<GridOverlayRenderProps>;
|
|
149
151
|
/**
|
|
150
|
-
*
|
|
151
|
-
* `
|
|
152
|
-
*
|
|
152
|
+
* Lane count, used as a cap. A number applies at every width; a
|
|
153
|
+
* `ColumnSteps` map applies a count from each container width up, and
|
|
154
|
+
* an `'auto'` step lifts the cap from its width up.
|
|
155
|
+
* Defaults to six when neither `columns` nor `minColumnWidth` is set;
|
|
156
|
+
* with `minColumnWidth` set it can resolve lower on narrow containers.
|
|
153
157
|
*/
|
|
154
|
-
columns?: number;
|
|
158
|
+
columns?: number | ColumnSteps;
|
|
155
159
|
/**
|
|
156
160
|
* Per-tile minimum width in pixels. Enables responsive mode: the
|
|
157
161
|
* lane count derives from container width, floored by this value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dashboard-lanes/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACtC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dashboard-lanes/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACX,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACtC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAChD,KAAK,CAAC,wBAAwB,CAAE,KAAK,CAAE,EACvC,UAAU,GAAG,WAAW,GAAG,OAAO,CAClC;IACA;;OAEG;IACH,MAAM,EAAE,wBAAwB,EAAE,CAAC;IAEnC;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,CAAE,SAAS,EAAE,wBAAwB,EAAE,KAAM,IAAI,CAAC;IAEnE;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAE,aAAa,EAAE,wBAAwB,EAAE,KAAM,IAAI,CAAC;IAExE;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,uBAAuB,CAAE,CAAC;IAEpE;;;;;;;;;;;;;;OAcG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,sBAAsB,CAAE,CAAC;IAElE;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAE,sBAAsB,CAAE,CAAC;IAElE;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAE/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,mBAAmB,CAAE,CAAC;CACnD"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { DashboardGrid } from './dashboard-grid';
|
|
|
2
2
|
export { DashboardLanes } from './dashboard-lanes';
|
|
3
3
|
export type { DashboardGridLayoutItem, DashboardGridProps, } from './dashboard-grid/types';
|
|
4
4
|
export type { DashboardLanesLayoutItem, DashboardLanesProps, } from './dashboard-lanes/types';
|
|
5
|
+
export type { ColumnSteps } from './shared/column-policy';
|
|
5
6
|
export type { DragPreviewRenderProps, GridItemLimits, GridItemWidthLimits, GridOverlayRenderProps, ResizeDelta, ResizeHandleRenderProps, } from './shared/types';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,YAAY,EACX,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACX,wBAAwB,EACxB,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,WAAW,EACX,uBAAuB,GACvB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,YAAY,EACX,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACX,wBAAwB,EACxB,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EACX,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,WAAW,EACX,uBAAuB,GACvB,MAAM,gBAAgB,CAAC"}
|