@wordpress/grid 0.1.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/CHANGELOG.md +33 -0
- package/LICENSE.md +788 -0
- package/README.md +534 -0
- package/build/dashboard-grid/grid-item.cjs +308 -0
- package/build/dashboard-grid/grid-item.cjs.map +7 -0
- package/build/dashboard-grid/index.cjs +591 -0
- package/build/dashboard-grid/index.cjs.map +7 -0
- package/build/dashboard-grid/resolve-fill-widths.cjs +189 -0
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +7 -0
- package/build/dashboard-grid/types.cjs +19 -0
- package/build/dashboard-grid/types.cjs.map +7 -0
- package/build/dashboard-lanes/index.cjs +558 -0
- package/build/dashboard-lanes/index.cjs.map +7 -0
- package/build/dashboard-lanes/lane-placement.cjs +110 -0
- package/build/dashboard-lanes/lane-placement.cjs.map +7 -0
- package/build/dashboard-lanes/lanes-item.cjs +295 -0
- package/build/dashboard-lanes/lanes-item.cjs.map +7 -0
- package/build/dashboard-lanes/types.cjs +19 -0
- package/build/dashboard-lanes/types.cjs.map +7 -0
- package/build/dashboard-lanes/use-lane-placement.cjs +206 -0
- package/build/dashboard-lanes/use-lane-placement.cjs.map +7 -0
- package/build/index.cjs +34 -0
- package/build/index.cjs.map +7 -0
- package/build/shared/drag-overlay-drop-animation.cjs +70 -0
- package/build/shared/drag-overlay-drop-animation.cjs.map +7 -0
- package/build/shared/grid-item-key.cjs +31 -0
- package/build/shared/grid-item-key.cjs.map +7 -0
- package/build/shared/grid-overlay.cjs +187 -0
- package/build/shared/grid-overlay.cjs.map +7 -0
- package/build/shared/item-exit-overlay.cjs +150 -0
- package/build/shared/item-exit-overlay.cjs.map +7 -0
- package/build/shared/resize-handle.cjs +224 -0
- package/build/shared/resize-handle.cjs.map +7 -0
- package/build/shared/resize-snap.cjs +47 -0
- package/build/shared/resize-snap.cjs.map +7 -0
- package/build/shared/types.cjs +19 -0
- package/build/shared/types.cjs.map +7 -0
- package/build/shared/use-item-exit-animation.cjs +148 -0
- package/build/shared/use-item-exit-animation.cjs.map +7 -0
- package/build/shared/use-layout-shift-animation.cjs +167 -0
- package/build/shared/use-layout-shift-animation.cjs.map +7 -0
- package/build-module/dashboard-grid/grid-item.mjs +273 -0
- package/build-module/dashboard-grid/grid-item.mjs.map +7 -0
- package/build-module/dashboard-grid/index.mjs +579 -0
- package/build-module/dashboard-grid/index.mjs.map +7 -0
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +164 -0
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +7 -0
- package/build-module/dashboard-grid/types.mjs +1 -0
- package/build-module/dashboard-grid/types.mjs.map +7 -0
- package/build-module/dashboard-lanes/index.mjs +547 -0
- package/build-module/dashboard-lanes/index.mjs.map +7 -0
- package/build-module/dashboard-lanes/lane-placement.mjs +85 -0
- package/build-module/dashboard-lanes/lane-placement.mjs.map +7 -0
- package/build-module/dashboard-lanes/lanes-item.mjs +260 -0
- package/build-module/dashboard-lanes/lanes-item.mjs.map +7 -0
- package/build-module/dashboard-lanes/types.mjs +1 -0
- package/build-module/dashboard-lanes/types.mjs.map +7 -0
- package/build-module/dashboard-lanes/use-lane-placement.mjs +181 -0
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +7 -0
- package/build-module/index.mjs +8 -0
- package/build-module/index.mjs.map +7 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs +47 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs.map +7 -0
- package/build-module/shared/grid-item-key.mjs +6 -0
- package/build-module/shared/grid-item-key.mjs.map +7 -0
- package/build-module/shared/grid-overlay.mjs +152 -0
- package/build-module/shared/grid-overlay.mjs.map +7 -0
- package/build-module/shared/item-exit-overlay.mjs +125 -0
- package/build-module/shared/item-exit-overlay.mjs.map +7 -0
- package/build-module/shared/resize-handle.mjs +193 -0
- package/build-module/shared/resize-handle.mjs.map +7 -0
- package/build-module/shared/resize-snap.mjs +21 -0
- package/build-module/shared/resize-snap.mjs.map +7 -0
- package/build-module/shared/types.mjs +1 -0
- package/build-module/shared/types.mjs.map +7 -0
- package/build-module/shared/use-item-exit-animation.mjs +128 -0
- package/build-module/shared/use-item-exit-animation.mjs.map +7 -0
- package/build-module/shared/use-layout-shift-animation.mjs +140 -0
- package/build-module/shared/use-layout-shift-animation.mjs.map +7 -0
- package/build-types/dashboard-grid/grid-item.d.ts +3 -0
- package/build-types/dashboard-grid/grid-item.d.ts.map +1 -0
- package/build-types/dashboard-grid/index.d.ts +35 -0
- package/build-types/dashboard-grid/index.d.ts.map +1 -0
- package/build-types/dashboard-grid/resolve-fill-widths.d.ts +26 -0
- package/build-types/dashboard-grid/resolve-fill-widths.d.ts.map +1 -0
- package/build-types/dashboard-grid/stories/index.story.d.ts +98 -0
- package/build-types/dashboard-grid/stories/index.story.d.ts.map +1 -0
- package/build-types/dashboard-grid/types.d.ts +232 -0
- package/build-types/dashboard-grid/types.d.ts.map +1 -0
- package/build-types/dashboard-lanes/index.d.ts +40 -0
- package/build-types/dashboard-lanes/index.d.ts.map +1 -0
- package/build-types/dashboard-lanes/lane-placement.d.ts +126 -0
- package/build-types/dashboard-lanes/lane-placement.d.ts.map +1 -0
- package/build-types/dashboard-lanes/lanes-item.d.ts +52 -0
- package/build-types/dashboard-lanes/lanes-item.d.ts.map +1 -0
- package/build-types/dashboard-lanes/stories/index.story.d.ts +64 -0
- package/build-types/dashboard-lanes/stories/index.story.d.ts.map +1 -0
- package/build-types/dashboard-lanes/types.d.ts +151 -0
- package/build-types/dashboard-lanes/types.d.ts.map +1 -0
- package/build-types/dashboard-lanes/use-lane-placement.d.ts +74 -0
- package/build-types/dashboard-lanes/use-lane-placement.d.ts.map +1 -0
- package/build-types/index.d.ts +6 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/shared/drag-overlay-drop-animation.d.ts +13 -0
- package/build-types/shared/drag-overlay-drop-animation.d.ts.map +1 -0
- package/build-types/shared/grid-item-key.d.ts +6 -0
- package/build-types/shared/grid-item-key.d.ts.map +1 -0
- package/build-types/shared/grid-overlay.d.ts +19 -0
- package/build-types/shared/grid-overlay.d.ts.map +1 -0
- package/build-types/shared/item-exit-overlay.d.ts +20 -0
- package/build-types/shared/item-exit-overlay.d.ts.map +1 -0
- package/build-types/shared/resize-handle.d.ts +23 -0
- package/build-types/shared/resize-handle.d.ts.map +1 -0
- package/build-types/shared/resize-snap.d.ts +41 -0
- package/build-types/shared/resize-snap.d.ts.map +1 -0
- package/build-types/shared/types.d.ts +144 -0
- package/build-types/shared/types.d.ts.map +1 -0
- package/build-types/shared/use-item-exit-animation.d.ts +37 -0
- package/build-types/shared/use-item-exit-animation.d.ts.map +1 -0
- package/build-types/shared/use-layout-shift-animation.d.ts +77 -0
- package/build-types/shared/use-layout-shift-animation.d.ts.map +1 -0
- package/package.json +80 -0
- package/src/dashboard-grid/grid-item.module.css +94 -0
- package/src/dashboard-grid/grid-item.tsx +205 -0
- package/src/dashboard-grid/grid.module.css +134 -0
- package/src/dashboard-grid/index.tsx +713 -0
- package/src/dashboard-grid/resolve-fill-widths.ts +224 -0
- package/src/dashboard-grid/stories/index.story.tsx +930 -0
- package/src/dashboard-grid/test/keyboard-activation.test.tsx +76 -0
- package/src/dashboard-grid/test/resolve-fill-widths.test.ts +250 -0
- package/src/dashboard-grid/types.ts +271 -0
- package/src/dashboard-lanes/index.tsx +629 -0
- package/src/dashboard-lanes/lane-placement.ts +245 -0
- package/src/dashboard-lanes/lanes-item.module.css +93 -0
- package/src/dashboard-lanes/lanes-item.tsx +236 -0
- package/src/dashboard-lanes/lanes.module.css +152 -0
- package/src/dashboard-lanes/stories/index.story.tsx +518 -0
- package/src/dashboard-lanes/test/keyboard-activation.test.tsx +71 -0
- package/src/dashboard-lanes/test/lane-placement.test.ts +442 -0
- package/src/dashboard-lanes/test/use-lane-placement.test.tsx +358 -0
- package/src/dashboard-lanes/types.ts +176 -0
- package/src/dashboard-lanes/use-lane-placement.ts +313 -0
- package/src/index.ts +17 -0
- package/src/shared/actionable-area-slot.module.css +16 -0
- package/src/shared/drag-overlay-drop-animation.ts +66 -0
- package/src/shared/grid-item-key.ts +5 -0
- package/src/shared/grid-overlay.module.css +82 -0
- package/src/shared/grid-overlay.tsx +93 -0
- package/src/shared/item-exit-animation.module.css +49 -0
- package/src/shared/item-exit-overlay.tsx +57 -0
- package/src/shared/layout-shift-animation.module.css +16 -0
- package/src/shared/resize-handle.module.css +88 -0
- package/src/shared/resize-handle.tsx +163 -0
- package/src/shared/resize-snap.ts +63 -0
- package/src/shared/test/resize-snap.test.ts +35 -0
- package/src/shared/types.ts +164 -0
- package/src/shared/use-item-exit-animation.ts +199 -0
- package/src/shared/use-layout-shift-animation.ts +284 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { DashboardGrid } from './dashboard-grid';\nexport { DashboardLanes } from './dashboard-lanes';\n\nexport type {\n\tDashboardGridLayoutItem,\n\tDashboardGridProps,\n} from './dashboard-grid/types';\nexport type {\n\tDashboardLanesLayoutItem,\n\tDashboardLanesProps,\n} from './dashboard-lanes/types';\nexport type {\n\tDragPreviewRenderProps,\n\tGridOverlayRenderProps,\n\tResizeDelta,\n\tResizeHandleRenderProps,\n} from './shared/types';\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// packages/grid/src/shared/drag-overlay-drop-animation.ts
|
|
2
|
+
import {
|
|
3
|
+
defaultDropAnimation,
|
|
4
|
+
defaultDropAnimationSideEffects
|
|
5
|
+
} from "@dnd-kit/core";
|
|
6
|
+
var DROP_ANIMATION_DURATION_MS = 200;
|
|
7
|
+
var DROP_ANIMATION_EASING = "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
8
|
+
function createDashboardDragDropAnimation(dragPreviewFrameClassName, exitingFrameClassName) {
|
|
9
|
+
return {
|
|
10
|
+
...defaultDropAnimation,
|
|
11
|
+
duration: DROP_ANIMATION_DURATION_MS,
|
|
12
|
+
easing: DROP_ANIMATION_EASING,
|
|
13
|
+
sideEffects(args) {
|
|
14
|
+
const cleanupDefault = defaultDropAnimationSideEffects({
|
|
15
|
+
styles: {
|
|
16
|
+
active: {
|
|
17
|
+
opacity: "0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
})(args);
|
|
21
|
+
const frame = args.dragOverlay.node.getElementsByClassName(
|
|
22
|
+
dragPreviewFrameClassName
|
|
23
|
+
)[0];
|
|
24
|
+
if (frame) {
|
|
25
|
+
frame.getAnimations().forEach((animation) => animation.cancel());
|
|
26
|
+
const lift = frame.firstElementChild;
|
|
27
|
+
if (lift instanceof HTMLElement) {
|
|
28
|
+
lift.getAnimations().forEach(
|
|
29
|
+
(animation) => animation.cancel()
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
frame.classList.add(exitingFrameClassName);
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
cleanupDefault?.();
|
|
36
|
+
if (frame) {
|
|
37
|
+
frame.classList.remove(exitingFrameClassName);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
DROP_ANIMATION_DURATION_MS,
|
|
45
|
+
createDashboardDragDropAnimation
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=drag-overlay-drop-animation.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shared/drag-overlay-drop-animation.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tdefaultDropAnimation,\n\tdefaultDropAnimationSideEffects,\n} from '@dnd-kit/core';\nimport type { DropAnimation } from '@dnd-kit/core';\n\n/** Matches `--wpds-motion-duration-md` on the drag preview frame exit. */\nexport const DROP_ANIMATION_DURATION_MS = 200;\n\n/** Matches `--wpds-motion-easing-balanced` on the drag preview frame exit. */\nconst DROP_ANIMATION_EASING = 'cubic-bezier(0.4, 0, 0.2, 1)';\n\n/**\n * Composes @dnd-kit/core’s default overlay drop translation with preview\n * exit keyframes (via side effects). When the pointer never moves, @dnd-kit\n * skips the drop animation and these side effects do not run.\n *\n * @param dragPreviewFrameClassName Hashed class for `.drag-preview-frame`.\n * @param exitingFrameClassName Hashed class for the exit state.\n */\nexport function createDashboardDragDropAnimation(\n\tdragPreviewFrameClassName: string,\n\texitingFrameClassName: string\n): DropAnimation {\n\treturn {\n\t\t...defaultDropAnimation,\n\t\tduration: DROP_ANIMATION_DURATION_MS,\n\t\teasing: DROP_ANIMATION_EASING,\n\t\tsideEffects( args ) {\n\t\t\tconst cleanupDefault = defaultDropAnimationSideEffects( {\n\t\t\t\tstyles: {\n\t\t\t\t\tactive: {\n\t\t\t\t\t\topacity: '0',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} )( args );\n\n\t\t\tconst frame = args.dragOverlay.node.getElementsByClassName(\n\t\t\t\tdragPreviewFrameClassName\n\t\t\t)[ 0 ] as HTMLElement | undefined;\n\n\t\t\tif ( frame ) {\n\t\t\t\tframe\n\t\t\t\t\t.getAnimations()\n\t\t\t\t\t.forEach( ( animation ) => animation.cancel() );\n\t\t\t\tconst lift = frame.firstElementChild;\n\t\t\t\tif ( lift instanceof HTMLElement ) {\n\t\t\t\t\tlift.getAnimations().forEach( ( animation ) =>\n\t\t\t\t\t\tanimation.cancel()\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tframe.classList.add( exitingFrameClassName );\n\t\t\t}\n\n\t\t\treturn () => {\n\t\t\t\tcleanupDefault?.();\n\t\t\t\tif ( frame ) {\n\t\t\t\t\tframe.classList.remove( exitingFrameClassName );\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAIA,IAAM,6BAA6B;AAG1C,IAAM,wBAAwB;AAUvB,SAAS,iCACf,2BACA,uBACgB;AAChB,SAAO;AAAA,IACN,GAAG;AAAA,IACH,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAa,MAAO;AACnB,YAAM,iBAAiB,gCAAiC;AAAA,QACvD,QAAQ;AAAA,UACP,QAAQ;AAAA,YACP,SAAS;AAAA,UACV;AAAA,QACD;AAAA,MACD,CAAE,EAAG,IAAK;AAEV,YAAM,QAAQ,KAAK,YAAY,KAAK;AAAA,QACnC;AAAA,MACD,EAAG,CAAE;AAEL,UAAK,OAAQ;AACZ,cACE,cAAc,EACd,QAAS,CAAE,cAAe,UAAU,OAAO,CAAE;AAC/C,cAAM,OAAO,MAAM;AACnB,YAAK,gBAAgB,aAAc;AAClC,eAAK,cAAc,EAAE;AAAA,YAAS,CAAE,cAC/B,UAAU,OAAO;AAAA,UAClB;AAAA,QACD;AACA,cAAM,UAAU,IAAK,qBAAsB;AAAA,MAC5C;AAEA,aAAO,MAAM;AACZ,yBAAiB;AACjB,YAAK,OAAQ;AACZ,gBAAM,UAAU,OAAQ,qBAAsB;AAAA,QAC/C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shared/grid-item-key.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Data attribute grid tiles declare so layout-shift animation can map\n * measured DOM nodes back to logical item keys.\n */\nexport const GRID_ITEM_DATA_KEY = 'data-wp-grid-item-key';\n"],
|
|
5
|
+
"mappings": ";AAIO,IAAM,qBAAqB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// packages/grid/src/shared/grid-overlay.tsx
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { useEffect, useState } from "@wordpress/element";
|
|
4
|
+
|
|
5
|
+
// packages/style-runtime/src/index.ts
|
|
6
|
+
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
7
|
+
function getRuntime() {
|
|
8
|
+
const globalScope = globalThis;
|
|
9
|
+
if (globalScope.__wpStyleRuntime) {
|
|
10
|
+
return globalScope.__wpStyleRuntime;
|
|
11
|
+
}
|
|
12
|
+
globalScope.__wpStyleRuntime = {
|
|
13
|
+
documents: /* @__PURE__ */ new Map(),
|
|
14
|
+
styles: /* @__PURE__ */ new Map(),
|
|
15
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
16
|
+
};
|
|
17
|
+
if (typeof document !== "undefined") {
|
|
18
|
+
registerDocument(document);
|
|
19
|
+
}
|
|
20
|
+
return globalScope.__wpStyleRuntime;
|
|
21
|
+
}
|
|
22
|
+
function documentContainsStyleHash(targetDocument, hash) {
|
|
23
|
+
if (!targetDocument.head) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
for (const style of targetDocument.head.querySelectorAll(
|
|
27
|
+
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
28
|
+
)) {
|
|
29
|
+
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function injectStyle(targetDocument, hash, css) {
|
|
36
|
+
if (!targetDocument.head) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const runtime = getRuntime();
|
|
40
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
41
|
+
if (!injectedStyles) {
|
|
42
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
43
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
44
|
+
}
|
|
45
|
+
if (injectedStyles.has(hash)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
49
|
+
injectedStyles.add(hash);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const style = targetDocument.createElement("style");
|
|
53
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
54
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
55
|
+
targetDocument.head.appendChild(style);
|
|
56
|
+
injectedStyles.add(hash);
|
|
57
|
+
}
|
|
58
|
+
function registerDocument(targetDocument) {
|
|
59
|
+
const runtime = getRuntime();
|
|
60
|
+
runtime.documents.set(
|
|
61
|
+
targetDocument,
|
|
62
|
+
(runtime.documents.get(targetDocument) ?? 0) + 1
|
|
63
|
+
);
|
|
64
|
+
for (const [hash, css] of runtime.styles) {
|
|
65
|
+
injectStyle(targetDocument, hash, css);
|
|
66
|
+
}
|
|
67
|
+
return () => {
|
|
68
|
+
const count = runtime.documents.get(targetDocument);
|
|
69
|
+
if (count === void 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (count <= 1) {
|
|
73
|
+
runtime.documents.delete(targetDocument);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function registerStyle(hash, css) {
|
|
80
|
+
const runtime = getRuntime();
|
|
81
|
+
runtime.styles.set(hash, css);
|
|
82
|
+
for (const targetDocument of runtime.documents.keys()) {
|
|
83
|
+
injectStyle(targetDocument, hash, css);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// packages/grid/src/shared/grid-overlay.module.css
|
|
88
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
89
|
+
registerStyle("63c265b9f4", "._9d372b1b567c1c15__overlay{display:grid;gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));inset:0;opacity:0;pointer-events:none;position:absolute;visibility:hidden}._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active{opacity:1;visibility:visible}@media not (prefers-reduced-motion){._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active .d8e6ee9623aadacf__row,._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active:not(._1cee1202cb622c6b__has-rows) ._04ff499ab60b4891__column{animation:_2d68e980e4534716__grid-overlay-tile-in var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)) both;animation-delay:calc(var(--wp-grid-overlay-wave-delay-step, 28ms)*(var(--wp-grid-overlay-column-index, 0) + var(--wp-grid-overlay-row-index, 0)));opacity:0;transform:scale(.64)}@keyframes _2d68e980e4534716__grid-overlay-tile-in{to{opacity:1;transform:scale(1)}}._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active){transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear var(--wpds-motion-duration-sm,.1s)}._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active) ._04ff499ab60b4891__column,._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active) .d8e6ee9623aadacf__row{animation:none;transform:none}}@media (prefers-reduced-motion:reduce){._9d372b1b567c1c15__overlay{transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear var(--wpds-motion-duration-sm,.1s)}._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active{transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear 0s}}._04ff499ab60b4891__column{display:flex;flex-direction:column;gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));min-width:0}.d8e6ee9623aadacf__row{background-color:var(--wp-grid-overlay-tile-bg,var(--wpds-color-background-surface-neutral-weak,#f4f4f4));border-radius:var(--wpds-border-radius-lg,8px);box-sizing:border-box;flex:0 0 var(--wp-grid-overlay-row-height);height:var(--wp-grid-overlay-row-height)}");
|
|
90
|
+
}
|
|
91
|
+
var grid_overlay_default = { "overlay": "_9d372b1b567c1c15__overlay", "is-active": "acb42ab28bd5e371__is-active", "row": "d8e6ee9623aadacf__row", "has-rows": "_1cee1202cb622c6b__has-rows", "column": "_04ff499ab60b4891__column", "grid-overlay-tile-in": "_2d68e980e4534716__grid-overlay-tile-in" };
|
|
92
|
+
|
|
93
|
+
// packages/grid/src/shared/grid-overlay.tsx
|
|
94
|
+
import { jsx } from "react/jsx-runtime";
|
|
95
|
+
function GridOverlay({
|
|
96
|
+
columns,
|
|
97
|
+
rowHeight,
|
|
98
|
+
rows,
|
|
99
|
+
isActive
|
|
100
|
+
}) {
|
|
101
|
+
const showRows = typeof rowHeight === "number" && typeof rows === "number" && rows > 0;
|
|
102
|
+
const [waveKey, setWaveKey] = useState(0);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (isActive) {
|
|
105
|
+
setWaveKey((key) => key + 1);
|
|
106
|
+
}
|
|
107
|
+
}, [isActive]);
|
|
108
|
+
const style = {
|
|
109
|
+
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
|
|
110
|
+
...showRows ? {
|
|
111
|
+
"--wp-grid-overlay-row-height": `${rowHeight}px`
|
|
112
|
+
} : {}
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsx(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
"aria-hidden": true,
|
|
118
|
+
className: clsx(
|
|
119
|
+
grid_overlay_default.overlay,
|
|
120
|
+
isActive && grid_overlay_default["is-active"],
|
|
121
|
+
showRows && grid_overlay_default["has-rows"]
|
|
122
|
+
),
|
|
123
|
+
style,
|
|
124
|
+
children: Array.from({ length: columns }, (_column, columnIndex) => /* @__PURE__ */ jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
className: grid_overlay_default.column,
|
|
128
|
+
style: {
|
|
129
|
+
"--wp-grid-overlay-column-index": columnIndex,
|
|
130
|
+
"--wp-grid-overlay-row-index": 0
|
|
131
|
+
},
|
|
132
|
+
children: showRows && Array.from({ length: rows }, (_row, rowIndex) => /* @__PURE__ */ jsx(
|
|
133
|
+
"div",
|
|
134
|
+
{
|
|
135
|
+
className: grid_overlay_default.row,
|
|
136
|
+
style: {
|
|
137
|
+
"--wp-grid-overlay-row-index": rowIndex
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
rowIndex
|
|
141
|
+
))
|
|
142
|
+
},
|
|
143
|
+
columnIndex
|
|
144
|
+
))
|
|
145
|
+
},
|
|
146
|
+
waveKey
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
GridOverlay
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=grid-overlay.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shared/grid-overlay.tsx", "../../../style-runtime/src/index.ts", "../../src/shared/grid-overlay.module.css"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { GridOverlayRenderProps } from './types';\nimport styles from './grid-overlay.module.css';\n\n/**\n * Default edit-mode overlay: one column per track, each holding `rows`\n * row-marker tiles when `rowHeight` is uniform. Used by both surfaces\n * and replaceable via `renderGridOverlay`. Reveals with a diagonal\n * wave on activate and releases paint cost while inactive.\n *\n * @param props Render props supplied by the surface.\n * @param props.columns Column tracks to mirror.\n * @param props.rowHeight Uniform row height in pixels; omitted for\n * content-sized rows, which skip row markers.\n * @param props.rows Row tracks per column; omitted when unknown.\n * @param props.isActive When `false`, the overlay fades out.\n */\nexport function GridOverlay( {\n\tcolumns,\n\trowHeight,\n\trows,\n\tisActive,\n}: GridOverlayRenderProps ) {\n\tconst showRows =\n\t\ttypeof rowHeight === 'number' && typeof rows === 'number' && rows > 0;\n\t// Bump the key when edit mode activates so CSS animations restart on\n\t// each enter (the overlay stays mounted across toggles).\n\tconst [ waveKey, setWaveKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( isActive ) {\n\t\t\tsetWaveKey( ( key ) => key + 1 );\n\t\t}\n\t}, [ isActive ] );\n\tconst style: React.CSSProperties = {\n\t\tgridTemplateColumns: `repeat(${ columns }, minmax(0, 1fr))`,\n\t\t...( showRows\n\t\t\t? ( {\n\t\t\t\t\t'--wp-grid-overlay-row-height': `${ rowHeight }px`,\n\t\t\t } as React.CSSProperties )\n\t\t\t: {} ),\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tkey={ waveKey }\n\t\t\taria-hidden\n\t\t\tclassName={ clsx(\n\t\t\t\tstyles.overlay,\n\t\t\t\tisActive && styles[ 'is-active' ],\n\t\t\t\tshowRows && styles[ 'has-rows' ]\n\t\t\t) }\n\t\t\tstyle={ style }\n\t\t>\n\t\t\t{ Array.from( { length: columns }, ( _column, columnIndex ) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={ columnIndex }\n\t\t\t\t\tclassName={ styles.column }\n\t\t\t\t\tstyle={\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'--wp-grid-overlay-column-index': columnIndex,\n\t\t\t\t\t\t\t'--wp-grid-overlay-row-index': 0,\n\t\t\t\t\t\t} as React.CSSProperties\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ showRows &&\n\t\t\t\t\t\tArray.from( { length: rows }, ( _row, rowIndex ) => (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tkey={ rowIndex }\n\t\t\t\t\t\t\t\tclassName={ styles.row }\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'--wp-grid-overlay-row-index': rowIndex,\n\t\t\t\t\t\t\t\t\t} as React.CSSProperties\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"63c265b9f4\", \"._9d372b1b567c1c15__overlay{display:grid;gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));inset:0;opacity:0;pointer-events:none;position:absolute;visibility:hidden}._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active{opacity:1;visibility:visible}@media not (prefers-reduced-motion){._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active .d8e6ee9623aadacf__row,._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active:not(._1cee1202cb622c6b__has-rows) ._04ff499ab60b4891__column{animation:_2d68e980e4534716__grid-overlay-tile-in var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)) both;animation-delay:calc(var(--wp-grid-overlay-wave-delay-step, 28ms)*(var(--wp-grid-overlay-column-index, 0) + var(--wp-grid-overlay-row-index, 0)));opacity:0;transform:scale(.64)}@keyframes _2d68e980e4534716__grid-overlay-tile-in{to{opacity:1;transform:scale(1)}}._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active){transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear var(--wpds-motion-duration-sm,.1s)}._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active) ._04ff499ab60b4891__column,._9d372b1b567c1c15__overlay:not(.acb42ab28bd5e371__is-active) .d8e6ee9623aadacf__row{animation:none;transform:none}}@media (prefers-reduced-motion:reduce){._9d372b1b567c1c15__overlay{transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear var(--wpds-motion-duration-sm,.1s)}._9d372b1b567c1c15__overlay.acb42ab28bd5e371__is-active{transition:opacity var(--wpds-motion-duration-sm,.1s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)),visibility 0s linear 0s}}._04ff499ab60b4891__column{display:flex;flex-direction:column;gap:var(--wp-grid-gap,var(--wpds-dimension-gap-xl,24px));min-width:0}.d8e6ee9623aadacf__row{background-color:var(--wp-grid-overlay-tile-bg,var(--wpds-color-background-surface-neutral-weak,#f4f4f4));border-radius:var(--wpds-border-radius-lg,8px);box-sizing:border-box;flex:0 0 var(--wp-grid-overlay-row-height);height:var(--wp-grid-overlay-row-height)}\");\n}\nexport default {\"overlay\":\"_9d372b1b567c1c15__overlay\",\"is-active\":\"acb42ab28bd5e371__is-active\",\"row\":\"d8e6ee9623aadacf__row\",\"has-rows\":\"_1cee1202cb622c6b__has-rows\",\"column\":\"_04ff499ab60b4891__column\",\"grid-overlay-tile-in\":\"_2d68e980e4534716__grid-overlay-tile-in\"};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// packages/grid/src/shared/item-exit-overlay.tsx
|
|
2
|
+
import { GRID_ITEM_DATA_KEY } from "./grid-item-key.mjs";
|
|
3
|
+
|
|
4
|
+
// packages/style-runtime/src/index.ts
|
|
5
|
+
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
6
|
+
function getRuntime() {
|
|
7
|
+
const globalScope = globalThis;
|
|
8
|
+
if (globalScope.__wpStyleRuntime) {
|
|
9
|
+
return globalScope.__wpStyleRuntime;
|
|
10
|
+
}
|
|
11
|
+
globalScope.__wpStyleRuntime = {
|
|
12
|
+
documents: /* @__PURE__ */ new Map(),
|
|
13
|
+
styles: /* @__PURE__ */ new Map(),
|
|
14
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
15
|
+
};
|
|
16
|
+
if (typeof document !== "undefined") {
|
|
17
|
+
registerDocument(document);
|
|
18
|
+
}
|
|
19
|
+
return globalScope.__wpStyleRuntime;
|
|
20
|
+
}
|
|
21
|
+
function documentContainsStyleHash(targetDocument, hash) {
|
|
22
|
+
if (!targetDocument.head) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
for (const style of targetDocument.head.querySelectorAll(
|
|
26
|
+
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
27
|
+
)) {
|
|
28
|
+
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
function injectStyle(targetDocument, hash, css) {
|
|
35
|
+
if (!targetDocument.head) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const runtime = getRuntime();
|
|
39
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
40
|
+
if (!injectedStyles) {
|
|
41
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
42
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
43
|
+
}
|
|
44
|
+
if (injectedStyles.has(hash)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
48
|
+
injectedStyles.add(hash);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const style = targetDocument.createElement("style");
|
|
52
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
53
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
54
|
+
targetDocument.head.appendChild(style);
|
|
55
|
+
injectedStyles.add(hash);
|
|
56
|
+
}
|
|
57
|
+
function registerDocument(targetDocument) {
|
|
58
|
+
const runtime = getRuntime();
|
|
59
|
+
runtime.documents.set(
|
|
60
|
+
targetDocument,
|
|
61
|
+
(runtime.documents.get(targetDocument) ?? 0) + 1
|
|
62
|
+
);
|
|
63
|
+
for (const [hash, css] of runtime.styles) {
|
|
64
|
+
injectStyle(targetDocument, hash, css);
|
|
65
|
+
}
|
|
66
|
+
return () => {
|
|
67
|
+
const count = runtime.documents.get(targetDocument);
|
|
68
|
+
if (count === void 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (count <= 1) {
|
|
72
|
+
runtime.documents.delete(targetDocument);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function registerStyle(hash, css) {
|
|
79
|
+
const runtime = getRuntime();
|
|
80
|
+
runtime.styles.set(hash, css);
|
|
81
|
+
for (const targetDocument of runtime.documents.keys()) {
|
|
82
|
+
injectStyle(targetDocument, hash, css);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// packages/grid/src/shared/item-exit-animation.module.css
|
|
87
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
88
|
+
registerStyle("1e0c56b346", ".f5f31b390af63a56__exit-overlay{opacity:1;overflow:hidden;pointer-events:none;position:absolute;transform:scale(1);transform-origin:center center;z-index:2}@media not (prefers-reduced-motion:reduce){.f5f31b390af63a56__exit-overlay{animation:_5e96d3d4062490e6__wp-grid-item-exit-opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)) forwards,a74da0751a183719__wp-grid-item-exit-scale var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}}@keyframes _5e96d3d4062490e6__wp-grid-item-exit-opacity{0%{opacity:1}to{opacity:0}}@keyframes a74da0751a183719__wp-grid-item-exit-scale{0%{transform:scale(1)}to{transform:scale(.88)}}@media (prefers-reduced-motion:reduce){.f5f31b390af63a56__exit-overlay{display:none}}");
|
|
89
|
+
}
|
|
90
|
+
var item_exit_animation_default = { "exit-overlay": "f5f31b390af63a56__exit-overlay", "wp-grid-item-exit-opacity": "_5e96d3d4062490e6__wp-grid-item-exit-opacity", "wp-grid-item-exit-scale": "a74da0751a183719__wp-grid-item-exit-scale" };
|
|
91
|
+
|
|
92
|
+
// packages/grid/src/shared/item-exit-overlay.tsx
|
|
93
|
+
import { jsx } from "react/jsx-runtime";
|
|
94
|
+
function ItemExitOverlay({
|
|
95
|
+
itemKey,
|
|
96
|
+
rect,
|
|
97
|
+
children,
|
|
98
|
+
onAnimationEnd
|
|
99
|
+
}) {
|
|
100
|
+
return /* @__PURE__ */ jsx(
|
|
101
|
+
"div",
|
|
102
|
+
{
|
|
103
|
+
className: item_exit_animation_default["exit-overlay"],
|
|
104
|
+
style: {
|
|
105
|
+
left: rect.left,
|
|
106
|
+
top: rect.top,
|
|
107
|
+
width: rect.width,
|
|
108
|
+
height: rect.height
|
|
109
|
+
},
|
|
110
|
+
...{ [GRID_ITEM_DATA_KEY]: itemKey },
|
|
111
|
+
"data-wp-grid-item-exiting": "",
|
|
112
|
+
onAnimationEnd: (event) => {
|
|
113
|
+
if (event.target !== event.currentTarget) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
onAnimationEnd();
|
|
117
|
+
},
|
|
118
|
+
children
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
ItemExitOverlay
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=item-exit-overlay.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shared/item-exit-overlay.tsx", "../../../style-runtime/src/index.ts", "../../src/shared/item-exit-animation.module.css"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { GRID_ITEM_DATA_KEY } from './grid-item-key';\nimport exitStyles from './item-exit-animation.module.css';\nimport type { RectSnapshot } from './use-layout-shift-animation';\n\nexport type ItemExitOverlayRect = Pick<\n\tRectSnapshot,\n\t'left' | 'top' | 'width' | 'height'\n>;\n\nexport type ItemExitOverlayProps = {\n\titemKey: string;\n\trect: ItemExitOverlayRect;\n\tchildren: React.ReactNode;\n\tonAnimationEnd: () => void;\n};\n\n/**\n * Ghost tile shown at the removed item's last position while siblings\n * reflow. Not a sortable grid cell — only visual exit feedback.\n *\n * @param root0 Component props.\n * @param root0.itemKey Layout key of the removed tile.\n * @param root0.rect Last bounds relative to the grid surface.\n * @param root0.children Cached tile content to render in the ghost.\n * @param root0.onAnimationEnd Called when the exit animation finishes.\n */\nexport function ItemExitOverlay( {\n\titemKey,\n\trect,\n\tchildren,\n\tonAnimationEnd,\n}: ItemExitOverlayProps ) {\n\treturn (\n\t\t<div\n\t\t\tclassName={ exitStyles[ 'exit-overlay' ] }\n\t\t\tstyle={ {\n\t\t\t\tleft: rect.left,\n\t\t\t\ttop: rect.top,\n\t\t\t\twidth: rect.width,\n\t\t\t\theight: rect.height,\n\t\t\t} }\n\t\t\t{ ...{ [ GRID_ITEM_DATA_KEY ]: itemKey } }\n\t\t\tdata-wp-grid-item-exiting=\"\"\n\t\t\tonAnimationEnd={ ( event ) => {\n\t\t\t\tif ( event.target !== event.currentTarget ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonAnimationEnd();\n\t\t\t} }\n\t\t>\n\t\t\t{ children }\n\t\t</div>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"1e0c56b346\", \".f5f31b390af63a56__exit-overlay{opacity:1;overflow:hidden;pointer-events:none;position:absolute;transform:scale(1);transform-origin:center center;z-index:2}@media not (prefers-reduced-motion:reduce){.f5f31b390af63a56__exit-overlay{animation:_5e96d3d4062490e6__wp-grid-item-exit-opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1)) forwards,a74da0751a183719__wp-grid-item-exit-scale var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-balanced,cubic-bezier(.4,0,.2,1)) forwards}}@keyframes _5e96d3d4062490e6__wp-grid-item-exit-opacity{0%{opacity:1}to{opacity:0}}@keyframes a74da0751a183719__wp-grid-item-exit-scale{0%{transform:scale(1)}to{transform:scale(.88)}}@media (prefers-reduced-motion:reduce){.f5f31b390af63a56__exit-overlay{display:none}}\");\n}\nexport default {\"exit-overlay\":\"f5f31b390af63a56__exit-overlay\",\"wp-grid-item-exit-opacity\":\"_5e96d3d4062490e6__wp-grid-item-exit-opacity\",\"wp-grid-item-exit-scale\":\"a74da0751a183719__wp-grid-item-exit-scale\"};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// packages/grid/src/shared/resize-handle.tsx
|
|
2
|
+
import { DndContext, useDraggable } from "@dnd-kit/core";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useCallback, useEffect, useRef } from "@wordpress/element";
|
|
5
|
+
import { useMergeRefs, useThrottle } from "@wordpress/compose";
|
|
6
|
+
|
|
7
|
+
// packages/style-runtime/src/index.ts
|
|
8
|
+
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
9
|
+
function getRuntime() {
|
|
10
|
+
const globalScope = globalThis;
|
|
11
|
+
if (globalScope.__wpStyleRuntime) {
|
|
12
|
+
return globalScope.__wpStyleRuntime;
|
|
13
|
+
}
|
|
14
|
+
globalScope.__wpStyleRuntime = {
|
|
15
|
+
documents: /* @__PURE__ */ new Map(),
|
|
16
|
+
styles: /* @__PURE__ */ new Map(),
|
|
17
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
18
|
+
};
|
|
19
|
+
if (typeof document !== "undefined") {
|
|
20
|
+
registerDocument(document);
|
|
21
|
+
}
|
|
22
|
+
return globalScope.__wpStyleRuntime;
|
|
23
|
+
}
|
|
24
|
+
function documentContainsStyleHash(targetDocument, hash) {
|
|
25
|
+
if (!targetDocument.head) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (const style of targetDocument.head.querySelectorAll(
|
|
29
|
+
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
30
|
+
)) {
|
|
31
|
+
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
function injectStyle(targetDocument, hash, css) {
|
|
38
|
+
if (!targetDocument.head) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const runtime = getRuntime();
|
|
42
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
43
|
+
if (!injectedStyles) {
|
|
44
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
45
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
46
|
+
}
|
|
47
|
+
if (injectedStyles.has(hash)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
51
|
+
injectedStyles.add(hash);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const style = targetDocument.createElement("style");
|
|
55
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
56
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
57
|
+
targetDocument.head.appendChild(style);
|
|
58
|
+
injectedStyles.add(hash);
|
|
59
|
+
}
|
|
60
|
+
function registerDocument(targetDocument) {
|
|
61
|
+
const runtime = getRuntime();
|
|
62
|
+
runtime.documents.set(
|
|
63
|
+
targetDocument,
|
|
64
|
+
(runtime.documents.get(targetDocument) ?? 0) + 1
|
|
65
|
+
);
|
|
66
|
+
for (const [hash, css] of runtime.styles) {
|
|
67
|
+
injectStyle(targetDocument, hash, css);
|
|
68
|
+
}
|
|
69
|
+
return () => {
|
|
70
|
+
const count = runtime.documents.get(targetDocument);
|
|
71
|
+
if (count === void 0) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (count <= 1) {
|
|
75
|
+
runtime.documents.delete(targetDocument);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function registerStyle(hash, css) {
|
|
82
|
+
const runtime = getRuntime();
|
|
83
|
+
runtime.styles.set(hash, css);
|
|
84
|
+
for (const targetDocument of runtime.documents.keys()) {
|
|
85
|
+
injectStyle(targetDocument, hash, css);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// packages/grid/src/shared/resize-handle.module.css
|
|
90
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
91
|
+
registerStyle("13645360b3", '._91523dc3a37aecb8__resize-handle-slot{opacity:1}@media (prefers-reduced-motion:no-preference){._91523dc3a37aecb8__resize-handle-slot{transition:opacity var(--wpds-motion-duration-md,.2s) var(--wpds-motion-easing-subtle,cubic-bezier(.15,0,.15,1))}}[data-wp-grid-dragging] ._91523dc3a37aecb8__resize-handle-slot,[data-wp-grid-resizing] ._91523dc3a37aecb8__resize-handle-slot{opacity:0;pointer-events:none}[data-wp-grid-resizing]\n[data-wp-grid-item-resizing]\n._91523dc3a37aecb8__resize-handle-slot{opacity:1;pointer-events:auto}._4da787f72dc00d8b__resize-handle{border-block-end:12px solid var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-inline-start:12px solid transparent;bottom:0;cursor:nwse-resize;height:0;inset-inline-end:0;position:absolute;width:0;z-index:1}._885412b44a137da0__is-horizontal-only{align-items:center;background:transparent;border-style:none;bottom:auto;cursor:ew-resize;display:flex;height:40px;justify-content:center;top:50%;transform:translateY(-50%);width:16px}._885412b44a137da0__is-horizontal-only:before{background-color:var(--wpds-color-foreground-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-radius:2px;content:"";height:24px;width:4px}@media (forced-colors:active){._885412b44a137da0__is-horizontal-only:before{background-color:Highlight}}');
|
|
92
|
+
}
|
|
93
|
+
var resize_handle_default = { "resize-handle-slot": "_91523dc3a37aecb8__resize-handle-slot", "resize-handle": "_4da787f72dc00d8b__resize-handle", "is-horizontal-only": "_885412b44a137da0__is-horizontal-only" };
|
|
94
|
+
|
|
95
|
+
// packages/grid/src/shared/resize-handle.tsx
|
|
96
|
+
import { jsx } from "react/jsx-runtime";
|
|
97
|
+
function lockDocumentCursorWhileActive(getDocument, cursor) {
|
|
98
|
+
const root = getDocument().documentElement;
|
|
99
|
+
const previous = root.style.cursor;
|
|
100
|
+
root.style.cursor = cursor;
|
|
101
|
+
return () => {
|
|
102
|
+
root.style.cursor = previous;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function ResizeHandle({
|
|
106
|
+
itemId,
|
|
107
|
+
verticalResizable = true,
|
|
108
|
+
renderResizeHandle
|
|
109
|
+
}) {
|
|
110
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
111
|
+
id: "draggable",
|
|
112
|
+
data: { itemId }
|
|
113
|
+
});
|
|
114
|
+
const ownerDocumentRef = useRef(null);
|
|
115
|
+
const setOwnerDocumentRef = useCallback((node) => {
|
|
116
|
+
ownerDocumentRef.current = node?.ownerDocument ?? null;
|
|
117
|
+
}, []);
|
|
118
|
+
const mergedRef = useMergeRefs([setOwnerDocumentRef, setNodeRef]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!isDragging) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const cursor = verticalResizable ? "nwse-resize" : "ew-resize";
|
|
124
|
+
return lockDocumentCursorWhileActive(
|
|
125
|
+
() => ownerDocumentRef.current ?? document,
|
|
126
|
+
cursor
|
|
127
|
+
);
|
|
128
|
+
}, [isDragging, verticalResizable]);
|
|
129
|
+
if (renderResizeHandle) {
|
|
130
|
+
const RenderResizeHandle = renderResizeHandle;
|
|
131
|
+
return /* @__PURE__ */ jsx(
|
|
132
|
+
RenderResizeHandle,
|
|
133
|
+
{
|
|
134
|
+
ref: mergedRef,
|
|
135
|
+
listeners,
|
|
136
|
+
attributes,
|
|
137
|
+
verticalResizable,
|
|
138
|
+
isResizing: isDragging,
|
|
139
|
+
itemId
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return /* @__PURE__ */ jsx(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
ref: mergedRef,
|
|
147
|
+
className: clsx(
|
|
148
|
+
resize_handle_default["resize-handle"],
|
|
149
|
+
!verticalResizable && resize_handle_default["is-horizontal-only"]
|
|
150
|
+
),
|
|
151
|
+
...listeners,
|
|
152
|
+
...attributes
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
function ResizeHandleWrapper(props) {
|
|
157
|
+
const throttleDelay = 16;
|
|
158
|
+
const throttledResize = useThrottle((delta) => {
|
|
159
|
+
if (props.onResize) {
|
|
160
|
+
props.onResize(delta);
|
|
161
|
+
}
|
|
162
|
+
}, throttleDelay);
|
|
163
|
+
const handleDragMove = (event) => {
|
|
164
|
+
if (event.active.id !== "draggable") {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
throttledResize({
|
|
168
|
+
width: event.delta.x,
|
|
169
|
+
height: event.delta.y
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const handleDragEnd = () => {
|
|
173
|
+
if (props.onResizeEnd) {
|
|
174
|
+
props.onResizeEnd();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
return /* @__PURE__ */ jsx(
|
|
178
|
+
DndContext,
|
|
179
|
+
{
|
|
180
|
+
autoScroll: {
|
|
181
|
+
threshold: { x: 5e-3, y: 5e-3 },
|
|
182
|
+
acceleration: 1
|
|
183
|
+
},
|
|
184
|
+
onDragMove: handleDragMove,
|
|
185
|
+
onDragEnd: handleDragEnd,
|
|
186
|
+
children: /* @__PURE__ */ jsx("div", { className: resize_handle_default["resize-handle-slot"], children: /* @__PURE__ */ jsx(ResizeHandle, { ...props }) })
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
ResizeHandleWrapper as default
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=resize-handle.mjs.map
|