@bison-lab/payload-core 4.15.1 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +41 -31
  2. package/dist/admin.mjs +54 -17
  3. package/dist/admin.mjs.map +1 -1
  4. package/dist/block-library.d.mts +1 -1
  5. package/dist/block-thumbnails--AJzSdzJ.mjs +130 -0
  6. package/dist/block-thumbnails--AJzSdzJ.mjs.map +1 -0
  7. package/dist/block-thumbnails-cli.d.mts +1 -0
  8. package/dist/block-thumbnails-cli.mjs +121 -0
  9. package/dist/block-thumbnails-cli.mjs.map +1 -0
  10. package/dist/block-thumbnails.d.mts +74 -0
  11. package/dist/block-thumbnails.d.mts.map +1 -0
  12. package/dist/block-thumbnails.mjs +2 -0
  13. package/dist/{catalogue-CFXM1yAZ.d.mts → catalogue-DMoDgScN.d.mts} +6 -5
  14. package/dist/catalogue-DMoDgScN.d.mts.map +1 -0
  15. package/dist/{facet-field-_8bYI1i0.d.mts → facet-field-DKzRCYrh.d.mts} +1 -1
  16. package/dist/{facet-field-_8bYI1i0.d.mts.map → facet-field-DKzRCYrh.d.mts.map} +1 -1
  17. package/dist/index.d.mts +27 -11
  18. package/dist/index.d.mts.map +1 -1
  19. package/dist/index.mjs +80 -21
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/metadata.d.mts +1 -1
  22. package/dist/navigation.d.mts +1 -1
  23. package/dist/{preview-Vaa1KXJP.d.mts → preview-T5VFcS32.d.mts} +1 -1
  24. package/dist/{preview-Vaa1KXJP.d.mts.map → preview-T5VFcS32.d.mts.map} +1 -1
  25. package/dist/published-BjmUCpdY.mjs.map +1 -1
  26. package/dist/{published-FUgC5Mc8.d.mts → published-IX1-6JEa.d.mts} +1 -1
  27. package/dist/{published-FUgC5Mc8.d.mts.map → published-IX1-6JEa.d.mts.map} +1 -1
  28. package/dist/taxonomy.d.mts +1 -1
  29. package/dist/theme.d.mts +1 -1
  30. package/dist/{title-ImlifZ_6.d.mts → title-BvjHeRo5.d.mts} +1 -1
  31. package/dist/{title-ImlifZ_6.d.mts.map → title-BvjHeRo5.d.mts.map} +1 -1
  32. package/dist/{wireframe-BTocmmyY.mjs → wireframe-ApjwNWAN.mjs} +6 -1
  33. package/dist/{wireframe-BTocmmyY.mjs.map → wireframe-ApjwNWAN.mjs.map} +1 -1
  34. package/dist/wireframe-cli.mjs +5 -1
  35. package/dist/wireframe-cli.mjs.map +1 -1
  36. package/dist/wireframe.d.mts +5 -0
  37. package/dist/wireframe.d.mts.map +1 -1
  38. package/dist/wireframe.mjs +1 -1
  39. package/package.json +6 -1
  40. package/dist/catalogue-CFXM1yAZ.d.mts.map +0 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@ Media list with `next/navigation`, which Payload's admin already loads); `@bison
19
19
  Pin the plugin to the same version as `payload`; Payload releases them in
20
20
  lockstep.
21
21
 
22
- ## Nine entry points, and why
22
+ ## Ten entry points, and why
23
23
 
24
24
  | Import | Contents | Runs where |
25
25
  | ---------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
@@ -29,7 +29,8 @@ lockstep.
29
29
  | `@bison-lab/payload-core/navigation` | `getNavigation`, the Header and Footer slugs | Server. What a site header imports; it does not load the plugin or React. |
30
30
  | `@bison-lab/payload-core/block-library` | `getSectionControls`, `sectionControlsFromLibrary`, `SectionControls`, the catalogue readers, the island height message | Server. What a page route and the Block Settings fold import; it does not load the plugin or React. |
31
31
  | `@bison-lab/payload-core/taxonomy` | `facetField`, `FacetEntry` | Anywhere. What a block config imports to tag content from a taxonomy; no plugin, no React, so a browser bundle can take it (`@bison-lab/payload-blocks` main entry reaches the docs island and Storybook). |
32
- | `@bison-lab/payload-core/wireframe` | `captureWireframes`, `extractWireframe`, `wireframeSvg`, `svgDataUri`; the `bison-wireframes` bin | Node, beside Playwright. What a site's thumbnail script imports; no Payload, no React. |
32
+ | `@bison-lab/payload-core/block-thumbnails` | `captureThumbnails`, `thumbnailCss`, `NEUTRAL_THEME`, `thumbnailVersion`; the `bison-block-thumbnails` bin | Node, beside Playwright. What a site's thumbnail script imports; no Payload, no React. |
33
+ | `@bison-lab/payload-core/wireframe` | Deprecated: the 4.15 wireframe generator and the `bison-wireframes` bin | Node. Kept for one release so a site's script keeps working; use `./block-thumbnails`. Goes in the next major. |
33
34
  | `@bison-lab/payload-core/admin` | Theme fields, the Roles and Features matrices, the Block library field, Admin nav, the Users Roles checklist, and the FAQ Library list | Admin. Referenced by import-map string; `generate:importmap` writes it. |
34
35
  | `@bison-lab/payload-core/react` | `BlockLibraryIsland`; `ThemePreview` (legacy; Theme has no preview pane) | Client. What a Block library preview route wraps its sample in. |
35
36
 
@@ -428,12 +429,18 @@ every catalogue block, in every collection and global, so all three agree:
428
429
  Feature, Process, … like the Block library. Blocks outside the catalogue
429
430
  (a Header's `megaMenu` and `navLink`) are left alone and go last, which
430
431
  is also where Payload draws ungrouped blocks.
431
- - **`admin.images.thumbnail`**: a black-and-white wireframe of the block.
432
- The package ships one for each of its page blocks
433
- (`block-library/wireframes.generated.ts`, `resources` included). A site
434
- extra passes its own as `thumbnail` on its `createBlockLibrary` entry; it
435
- is kept in the Global's server-only `custom`, not in the client config.
436
- A block config that already sets a thumbnail or `imageURL` keeps it.
432
+ - **`admin.images.thumbnail`**: a screenshot of the block's sample (generic
433
+ copy and photos from `@bison-lab/payload-blocks`) under a neutral slate
434
+ theme (BIS-151). The package ships one for each of its page blocks
435
+ (`block-library/thumbnails.generated.ts`, `resources` included) and
436
+ serves it from `GET /api/block-library/thumbnail/:slug`, a root endpoint
437
+ the plugin registers: signed-in users only, `image/jpeg`, cached for a
438
+ year behind a `?v=` that changes with the picture. The admin's client
439
+ config carries only that URL. A site extra passes its own `thumbnail`
440
+ URL on its `createBlockLibrary` entry (a file it serves, such as
441
+ `/block-thumbnails/ctaBand.jpg` from `public/`); it is kept in the
442
+ Global's server-only `custom`. A block config that already sets a
443
+ thumbnail or `imageURL` keeps it.
437
444
  - **Larger cards**: one admin stylesheet (`BLOCK_DRAWER_CSS`, mounted as the
438
445
  `BLOCK_DRAWER_STYLES` provider) lays the drawer out three across, two at
439
446
  Payload's 1024px break, one at 768px, instead of Payload's six.
@@ -448,7 +455,7 @@ export default buildConfig({
448
455
  globals: [
449
456
  createBlockLibrary({
450
457
  previewPath: (slug) => `/block-library/${slug}`,
451
- blocks: [{ slug: "ctaBand", label: "CTA band", category: "cta", thumbnail: SITE_WIREFRAMES.ctaBand }],
458
+ blocks: [{ slug: "ctaBand", label: "CTA band", category: "cta", thumbnail: "/block-thumbnails/ctaBand.jpg" }],
452
459
  }),
453
460
  ],
454
461
  plugins: [blockDrawer()],
@@ -457,33 +464,36 @@ export default buildConfig({
457
464
 
458
465
  Run `payload generate:importmap` once for the stylesheet provider.
459
466
 
460
- **Wireframes** come from `bison-wireframes`, a bin on this package that
461
- opens each block's Block library preview in a headless browser at 1280px,
462
- reads where headings, text lines, images, buttons, fields and painted
463
- surfaces sit (`extractWireframe`, from the `./wireframe` entry), and draws
464
- them as 480 × 320 greyscale shapes (`wireframeSvg`): bars for text, a
465
- crossed box for an image, pills for buttons, a dark fill for a dark band.
466
- No copy and no brand color, so a Theme change does not stale it; rerun it
467
- when a layout changes. Run it from the site, which supplies Playwright:
467
+ **Screenshots** come from `bison-block-thumbnails`, a bin on this package
468
+ that opens each block's Block library preview in a headless browser at
469
+ 1280px, lays the neutral theme over the site's (`thumbnailCss`: the
470
+ `NEUTRAL_THEME` tokens from `buildThemeCss`, a system font stack, no
471
+ motion, dev-server chrome hidden), centers the block in a 3:2 box, and
472
+ saves a 960 × 640 JPEG (`captureThumbnails`, from the `./block-thumbnails`
473
+ entry). Run it from the site, which supplies Playwright:
468
474
 
469
475
  ```sh
470
- WIREFRAME_EMAIL=… WIREFRAME_PASSWORD=… pnpm exec bison-wireframes \
476
+ THUMBNAIL_EMAIL=… THUMBNAIL_PASSWORD=… pnpm exec bison-block-thumbnails \
471
477
  --base http://localhost:3039 --slugs ctaBand,productMap \
472
- --out src/blocks/wireframes.generated.ts --svg-dir /tmp/wireframes
478
+ --out-dir public/block-thumbnails
473
479
  ```
474
480
 
475
- The login (any user the preview route accepts) comes from the environment.
476
- `--preview` changes the route pattern (`/block-library/{slug}` by default),
477
- `--selector` the element that holds the sample (`BlockLibraryIsland`'s by
478
- default), and `--export` the constant's name. The login is required unless
479
- `--no-login` names a public route. A preview that answers an error status,
480
- or renders nothing the selector matches, fails the run and writes nothing,
481
- so a sign-in wall or a mistyped slug never becomes a block's picture. A sample that reads data
482
- (Product Map reads Products and Anatomy) needs that data in the database
483
- the site is serving. To refresh the package's own map, run it against a
484
- site's preview route for the package slugs, and against the docs site's
485
- `/preview/{slug}/` page (`--selector "main[data-block]" --no-login`) for
486
- `hero`, which no site installs.
481
+ The login (any user the preview route accepts) comes from the environment
482
+ and is required unless `--no-login` names a public route. `--preview`
483
+ changes the route pattern (`/block-library/{slug}` by default; a site can
484
+ add a query, such as `?thumbnail=1`, to swap in generic stand-ins for data
485
+ its sample reads), and `--selector` the element that holds the sample
486
+ (`BlockLibraryIsland`'s by default). `--out-dir` writes `<slug>.jpg` files;
487
+ `--module` writes a TypeScript module of base64 JPEGs (`--export` names
488
+ the constant), which is how this package ships its own. A preview that
489
+ answers an error status, or renders nothing the selector matches, fails
490
+ the run and writes nothing, so a sign-in wall or a mistyped slug never
491
+ becomes a block's picture. Rerun it when a block's layout or sample
492
+ changes. To refresh the package's own, run it with `--module
493
+ src/block-library/thumbnails.generated.ts --export PACKAGE_THUMBNAILS`
494
+ against a site's preview route with this release's payload-blocks
495
+ installed; the `hero` alias reuses the sweep hero's picture, since no site
496
+ installs it.
487
497
 
488
498
  ### Section controls
489
499
 
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. */