@bison-lab/payload-core 4.15.1 → 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 CHANGED
@@ -4281,8 +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 landingRef = useRef(null);
4285
- landingRef.current = landing;
4284
+ const [pinned, setPinned] = useState(null);
4285
+ const pinnedRef = useRef(null);
4286
+ pinnedRef.current = pinned;
4286
4287
  const gallery = useRef(null);
4287
4288
  const openCategory = useCallback((id) => {
4288
4289
  setOpen(id);
@@ -4299,6 +4300,7 @@ const BlockLibraryField = (props) => {
4299
4300
  setQuery("");
4300
4301
  openCategory(category);
4301
4302
  setActive(slug);
4303
+ setPinned(slug);
4302
4304
  setLanding(slug);
4303
4305
  };
4304
4306
  land();
@@ -4312,25 +4314,16 @@ const BlockLibraryField = (props) => {
4312
4314
  const root = gallery.current;
4313
4315
  const resize = root && typeof ResizeObserver !== "undefined" ? new ResizeObserver(land) : null;
4314
4316
  if (root) resize?.observe(root);
4315
- const release = () => {
4316
- landingRef.current = null;
4317
- setLanding(null);
4318
- };
4317
+ const release = () => setLanding(null);
4319
4318
  const timer = window.setTimeout(release, LANDING_HOLD_MS);
4320
- const events = [
4321
- "wheel",
4322
- "touchstart",
4323
- "keydown",
4324
- "pointerdown"
4325
- ];
4326
- for (const name of events) window.addEventListener(name, release, {
4319
+ for (const name of EDITOR_MOVES) window.addEventListener(name, release, {
4327
4320
  once: true,
4328
4321
  passive: true
4329
4322
  });
4330
4323
  return () => {
4331
4324
  resize?.disconnect();
4332
4325
  window.clearTimeout(timer);
4333
- for (const name of events) window.removeEventListener(name, release);
4326
+ for (const name of EDITOR_MOVES) window.removeEventListener(name, release);
4334
4327
  };
4335
4328
  }, [landing]);
4336
4329
  const searching = query.trim().length > 0;
@@ -4349,13 +4342,48 @@ const BlockLibraryField = (props) => {
4349
4342
  const visibleKeyRef = useRef("");
4350
4343
  visibleKeyRef.current = visibleKey;
4351
4344
  const pickInView = useCallback(() => {
4352
- if (landingRef.current) return;
4345
+ if (pinnedRef.current) return;
4353
4346
  const first = visibleKeyRef.current.split(",").find((slug) => inViewRef.current.has(slug));
4354
4347
  if (first) setActive(first);
4355
4348
  }, []);
4356
4349
  useEffect(() => {
4357
- if (!landing) pickInView();
4358
- }, [landing, pickInView]);
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
+ ]);
4359
4387
  useEffect(() => {
4360
4388
  const root = gallery.current;
4361
4389
  if (!root || typeof IntersectionObserver === "undefined") return;
@@ -4423,6 +4451,15 @@ const BlockLibraryField = (props) => {
4423
4451
  * `#slug` landing scrolls the next card to the top (BIS-149).
4424
4452
  */
4425
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
+ ];
4426
4463
  /** How long a `#slug` landing holds its card in place while islands above it resize. */
4427
4464
  const LANDING_HOLD_MS = 4e3;
4428
4465
  /** The rail's categories in catalogue order, each listing its cards. */