@bison-lab/payload-core 4.15.0 → 4.15.2
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/dist/admin.mjs +76 -12
- package/dist/admin.mjs.map +1 -1
- package/package.json +3 -3
package/dist/admin.mjs
CHANGED
|
@@ -4281,6 +4281,9 @@ const BlockLibraryField = (props) => {
|
|
|
4281
4281
|
const [shown, setShown] = useState("hero");
|
|
4282
4282
|
const [active, setActive] = useState(null);
|
|
4283
4283
|
const [landing, setLanding] = useState(null);
|
|
4284
|
+
const [pinned, setPinned] = useState(null);
|
|
4285
|
+
const pinnedRef = useRef(null);
|
|
4286
|
+
pinnedRef.current = pinned;
|
|
4284
4287
|
const gallery = useRef(null);
|
|
4285
4288
|
const openCategory = useCallback((id) => {
|
|
4286
4289
|
setOpen(id);
|
|
@@ -4297,6 +4300,7 @@ const BlockLibraryField = (props) => {
|
|
|
4297
4300
|
setQuery("");
|
|
4298
4301
|
openCategory(category);
|
|
4299
4302
|
setActive(slug);
|
|
4303
|
+
setPinned(slug);
|
|
4300
4304
|
setLanding(slug);
|
|
4301
4305
|
};
|
|
4302
4306
|
land();
|
|
@@ -4312,20 +4316,14 @@ const BlockLibraryField = (props) => {
|
|
|
4312
4316
|
if (root) resize?.observe(root);
|
|
4313
4317
|
const release = () => setLanding(null);
|
|
4314
4318
|
const timer = window.setTimeout(release, LANDING_HOLD_MS);
|
|
4315
|
-
const
|
|
4316
|
-
"wheel",
|
|
4317
|
-
"touchstart",
|
|
4318
|
-
"keydown",
|
|
4319
|
-
"pointerdown"
|
|
4320
|
-
];
|
|
4321
|
-
for (const name of events) window.addEventListener(name, release, {
|
|
4319
|
+
for (const name of EDITOR_MOVES) window.addEventListener(name, release, {
|
|
4322
4320
|
once: true,
|
|
4323
4321
|
passive: true
|
|
4324
4322
|
});
|
|
4325
4323
|
return () => {
|
|
4326
4324
|
resize?.disconnect();
|
|
4327
4325
|
window.clearTimeout(timer);
|
|
4328
|
-
for (const name of
|
|
4326
|
+
for (const name of EDITOR_MOVES) window.removeEventListener(name, release);
|
|
4329
4327
|
};
|
|
4330
4328
|
}, [landing]);
|
|
4331
4329
|
const searching = query.trim().length > 0;
|
|
@@ -4340,10 +4338,57 @@ const BlockLibraryField = (props) => {
|
|
|
4340
4338
|
}];
|
|
4341
4339
|
const visible = groups.flatMap((group) => group.rows);
|
|
4342
4340
|
const visibleKey = visible.map((row) => row.slug).join(",");
|
|
4341
|
+
const inViewRef = useRef(/* @__PURE__ */ new Set());
|
|
4342
|
+
const visibleKeyRef = useRef("");
|
|
4343
|
+
visibleKeyRef.current = visibleKey;
|
|
4344
|
+
const pickInView = useCallback(() => {
|
|
4345
|
+
if (pinnedRef.current) return;
|
|
4346
|
+
const first = visibleKeyRef.current.split(",").find((slug) => inViewRef.current.has(slug));
|
|
4347
|
+
if (first) setActive(first);
|
|
4348
|
+
}, []);
|
|
4349
|
+
useEffect(() => {
|
|
4350
|
+
if (!pinned) return;
|
|
4351
|
+
const unpin = () => {
|
|
4352
|
+
pinnedRef.current = null;
|
|
4353
|
+
setPinned(null);
|
|
4354
|
+
pickInView();
|
|
4355
|
+
};
|
|
4356
|
+
const inside = (element, target) => Boolean(element && target instanceof Node && element.contains(target));
|
|
4357
|
+
const onMove = (event) => {
|
|
4358
|
+
if ((event.type === "pointerdown" || event.type === "touchstart") && inside(document.getElementById(pinned), event.target)) return;
|
|
4359
|
+
unpin();
|
|
4360
|
+
};
|
|
4361
|
+
for (const name of EDITOR_MOVES) window.addEventListener(name, onMove, { passive: true });
|
|
4362
|
+
let resizedAt = Number.NEGATIVE_INFINITY;
|
|
4363
|
+
const root = gallery.current;
|
|
4364
|
+
const resize = !landing && root && typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => {
|
|
4365
|
+
resizedAt = performance.now();
|
|
4366
|
+
}) : null;
|
|
4367
|
+
if (root) resize?.observe(root);
|
|
4368
|
+
const onScroll = (event) => {
|
|
4369
|
+
if (performance.now() - resizedAt < RESIZE_SCROLL_MS) return;
|
|
4370
|
+
if (event.target instanceof Element && event.target.closest(".bl-block-library__rail")) return;
|
|
4371
|
+
unpin();
|
|
4372
|
+
};
|
|
4373
|
+
if (!landing) document.addEventListener("scroll", onScroll, {
|
|
4374
|
+
capture: true,
|
|
4375
|
+
passive: true
|
|
4376
|
+
});
|
|
4377
|
+
return () => {
|
|
4378
|
+
for (const name of EDITOR_MOVES) window.removeEventListener(name, onMove);
|
|
4379
|
+
resize?.disconnect();
|
|
4380
|
+
if (!landing) document.removeEventListener("scroll", onScroll, { capture: true });
|
|
4381
|
+
};
|
|
4382
|
+
}, [
|
|
4383
|
+
pinned,
|
|
4384
|
+
landing,
|
|
4385
|
+
pickInView
|
|
4386
|
+
]);
|
|
4343
4387
|
useEffect(() => {
|
|
4344
4388
|
const root = gallery.current;
|
|
4345
4389
|
if (!root || typeof IntersectionObserver === "undefined") return;
|
|
4346
4390
|
const inView = /* @__PURE__ */ new Set();
|
|
4391
|
+
inViewRef.current = inView;
|
|
4347
4392
|
const observer = new IntersectionObserver((entries) => {
|
|
4348
4393
|
for (const entry of entries) {
|
|
4349
4394
|
const slug = entry.target.dataset.blockCard;
|
|
@@ -4351,12 +4396,15 @@ const BlockLibraryField = (props) => {
|
|
|
4351
4396
|
if (entry.isIntersecting) inView.add(slug);
|
|
4352
4397
|
else inView.delete(slug);
|
|
4353
4398
|
}
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
}, { rootMargin: "0px 0px -55% 0px" });
|
|
4399
|
+
pickInView();
|
|
4400
|
+
}, { rootMargin: SCROLL_SPY_ROOT_MARGIN });
|
|
4357
4401
|
root.querySelectorAll("[data-block-card]").forEach((card) => observer.observe(card));
|
|
4358
4402
|
return () => observer.disconnect();
|
|
4359
|
-
}, [
|
|
4403
|
+
}, [
|
|
4404
|
+
visibleKey,
|
|
4405
|
+
searching,
|
|
4406
|
+
pickInView
|
|
4407
|
+
]);
|
|
4360
4408
|
const card = (row) => /* @__PURE__ */ jsx(LibraryCard, {
|
|
4361
4409
|
row,
|
|
4362
4410
|
write: loaded.some((entry) => entry.slug === row.slug) ? writeRow(row.slug) : null,
|
|
@@ -4396,6 +4444,22 @@ const BlockLibraryField = (props) => {
|
|
|
4396
4444
|
]
|
|
4397
4445
|
}) });
|
|
4398
4446
|
};
|
|
4447
|
+
/**
|
|
4448
|
+
* The scroll-spy's reading band: from 20% down the viewport to 45%. The top
|
|
4449
|
+
* margin keeps out a card whose last strip sits under Payload's sticky
|
|
4450
|
+
* document header, which otherwise wins as "first in view" after a
|
|
4451
|
+
* `#slug` landing scrolls the next card to the top (BIS-149).
|
|
4452
|
+
*/
|
|
4453
|
+
const SCROLL_SPY_ROOT_MARGIN = "-20% 0px -55% 0px";
|
|
4454
|
+
/** A scroll this soon after the gallery resized is the browser's, not the editor's. */
|
|
4455
|
+
const RESIZE_SCROLL_MS = 250;
|
|
4456
|
+
/** What counts as the editor taking over from a `#slug` landing. */
|
|
4457
|
+
const EDITOR_MOVES = [
|
|
4458
|
+
"wheel",
|
|
4459
|
+
"touchstart",
|
|
4460
|
+
"keydown",
|
|
4461
|
+
"pointerdown"
|
|
4462
|
+
];
|
|
4399
4463
|
/** How long a `#slug` landing holds its card in place while islands above it resize. */
|
|
4400
4464
|
const LANDING_HOLD_MS = 4e3;
|
|
4401
4465
|
/** The rail's categories in catalogue order, each listing its cards. */
|