payload-canvas 0.5.0 → 0.5.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/README.md CHANGED
@@ -668,7 +668,7 @@ It also adds these endpoints (signed-in users only):
668
668
  | Import | Use it in | Holds |
669
669
  |---|---|---|
670
670
  | `payload-canvas` | `payload.config.ts` (server) | `websiteBuilder`, `defineBlock`, `defaultBlocks`, `fromPayloadBlocks`, `migrateBlocksField`, types |
671
- | `payload-canvas/blocks` | anywhere | `defaultBlocks`, `defineBlock`, `linkField`, `fromPayloadBlocks`, `BUILDER_CSS_CLASS`, `withBuilderCssClass` |
671
+ | `payload-canvas/blocks` | anywhere | `defaultBlocks`, `defineBlock`, `linkField`, `fromPayloadBlocks`, `prepareBlocks`, `listCollectionsOf`, `BUILDER_CSS_CLASS`, `withBuilderCssClass` |
672
672
  | `payload-canvas/core` | anywhere | layout types, `normalizeLayout`, `validateLayout`, `applyOperations`, tree helpers, `convertPayloadBlocksLayout`, `toPayloadBlock` |
673
673
  | `payload-canvas/css` | server | `compileClasses`, `getStyleTokens`, `tracingIncludes` |
674
674
  | `payload-canvas/theme` | anywhere | `themeCss`, `themeVariables`, `themeOutput`, `deriveColors`, `googleFontsHref`, `themeConfigOf`, theme types |
@@ -1046,7 +1046,7 @@ export const blocks = [...defaultBlocks({ linkCollections: ['pages'] }), pricing
1046
1046
 
1047
1047
  - `description` is one short plain sentence for editors. The block library shows it as the tooltip. Without it, the tooltip shows only the label. The library search also reads `ai.description`. Keep code and syntax out of it: those go in `ai.description`.
1048
1048
  - `slots` declares where child blocks go. `allow` lists the accepted block types, or `['*']`. `max` caps the number of direct children: a full slot refuses insert, move, paste and duplicate (also from MCP and the assistant), and the canvas offers no drop target or "+" there. `min` is the fewest children: fewer block **Publish** but not draft saves.
1049
- - `inline: true` says the block renders no link, button or other control of its own (an icon, a badge, a rating). Such a block may go directly inside a `link` block, whose content slot sets `allowInline: true`. A slot of your own can set `allowInline: true` too. `websiteBuilder` and `builderMcpTools` add the inline types to those slots' `allow` lists (`withInlineBlocks`); a slot's `disallow` still wins. Blocks without `inline` stay out of links. `validateLayout` applies the same rule itself, so a seed or a test can check a layout against your own block list. To check a collection list's picked `ids` as a relationship, give that list `defaultBlocks({ listCollections })`, as the plugin does with the collections that have a `url`.
1049
+ - `inline: true` says the block renders no link, button or other control of its own (an icon, a badge, a rating). Such a block may go directly inside a `link` block, whose content slot sets `allowInline: true`. A slot of your own can set `allowInline: true` too. `websiteBuilder` and `builderMcpTools` add the inline types to those slots' `allow` lists (`withInlineBlocks`); a slot's `disallow` still wins. Blocks without `inline` stay out of links. `validateLayout` applies the same rule itself, so a seed or a test can check a layout against your own block list. To check a collection list's picked `ids` as a relationship, give that list `defaultBlocks({ listCollections })`, as the plugin does with the collections that have a `url`. A list you do not build with `defaultBlocks` (for example from `fromPayloadBlocks`) can get the same preparation as `websiteBuilder` with `prepareBlocks(blocks, listCollections)` from `payload-canvas/blocks`. `listCollectionsOf(blocks, listCollections)` does only the collection list part.
1050
1050
  - `parents` limits where a block may go: only directly inside the listed block types (never in the root list). The `listItem` block uses `parents: ['list']`. A new block whose slot accepts exactly one such type starts with children of it: the slot's `min`, or one. So a new list starts with one item, and new tabs start with two tabs.
1051
1051
  - `classes`: classes your component uses itself that your site's CSS does not have. Components in your app need no list: Tailwind finds their classes in your files, and the site's CSS has them on the site and on the canvas. List classes only for a component in a package that your CSS entry does not scan (no `@source` for it). The generated CSS styles only elements with the class `builder-css` (`BUILDER_CSS_CLASS` from `payload-canvas/blocks`), so add that class to each element that uses the listed classes. The built-in Menu block does this for its toggle, panel and links.
1052
1052
  - Block fields keep Payload's `validate`, `hooks` and `access`. See [Validation, hooks and access on block fields](#validation-hooks-and-access-on-block-fields).
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { DefaultEditView, useConfig, useDocumentDrawerContext, useDocumentInfo } from '@payloadcms/ui';
4
4
  import { useRouter, useSearchParams } from 'next/navigation';
5
5
  import { useEffect } from 'react';
6
- import { builderViewPath, FORM_PARAM, opensInBuilder } from '../plugin/links.js';
6
+ import { builderOpening, builderViewPath, FORM_PARAM, opensInBuilder } from '../plugin/links.js';
7
7
  import { formChosen, rememberForm } from './formChoice.js';
8
8
  import './layoutField.scss';
9
9
  /**
@@ -35,7 +35,14 @@ export function DocumentEditView(props) {
35
35
  rememberForm(collectionSlug, id);
36
36
  }, [asked, hasId, collectionSlug, id, drawerSlug]);
37
37
  useEffect(() => {
38
- if (target)
38
+ if (!target)
39
+ return;
40
+ // A client navigation right after a full page load can lock React in a render loop in
41
+ // development: see `builderOpening`.
42
+ const loaded = performance.getEntriesByType('navigation')[0]?.name;
43
+ if (builderOpening(loaded, window.location.href) === 'page')
44
+ window.location.replace(target);
45
+ else
39
46
  router.replace(target);
40
47
  }, [target, router]);
41
48
  if (target) {
@@ -4,4 +4,5 @@ export { isLinkField, linkField, type BuilderCondition, type LinkFieldOptions }
4
4
  export { fromPayloadBlocks, type FromPayloadBlocksOptions, type PayloadBlockOverride } from './payload.js';
5
5
  export { defineBlock, defineSection, type SectionBlockInput, type SectionInput, sectionsWithVariants, withDefaultClassNames, withInlineBlocks } from '../core/blocks.js';
6
6
  export { BUILDER_CSS_CLASS, withBuilderCssClass } from '../css/marker.js';
7
+ export { listCollectionsOf, prepareBlocks } from '../plugin/listCollections.js';
7
8
  export type { Block, BlockDefinition, BlockProps, Layout, SectionDefinition, SectionVariant, SlotDefinition, } from '../core/types.js';
@@ -7,3 +7,5 @@ export { isLinkField, linkField } from './link.js';
7
7
  export { fromPayloadBlocks } from './payload.js';
8
8
  export { defineBlock, defineSection, sectionsWithVariants, withDefaultClassNames, withInlineBlocks } from '../core/blocks.js';
9
9
  export { BUILDER_CSS_CLASS, withBuilderCssClass } from '../css/marker.js';
10
+ // Public since 0.4.0. 0.5.0 dropped this line by mistake; `exports.test.ts` keeps it.
11
+ export { listCollectionsOf, prepareBlocks } from '../plugin/listCollections.js';
@@ -25,6 +25,20 @@ export declare function opensInBuilder(state: {
25
25
  inDrawer: boolean;
26
26
  formParam: string | null;
27
27
  }): boolean;
28
+ /**
29
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
30
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
31
+ * navigation, for an edit view that Next's router opened (a link in the admin).
32
+ *
33
+ * A client navigation right after a full load can lock React in a render loop in development
34
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
35
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
36
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
37
+ * From then on every render applies that close again and makes a new `modalState` object, and the
38
+ * effects that read it set state again, so the idle close never runs. A full page load gives
39
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
40
+ */
41
+ export declare function builderOpening(loadedUrl: string | null | undefined, currentUrl: string): 'page' | 'router';
28
42
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
29
43
  export declare function documentPath(url: ((doc: Record<string, unknown>) => string) | undefined, doc: Record<string, unknown>): string | null;
30
44
  /** The draft preview path from the collection's `admin.livePreview.url` or `admin.preview`. */
@@ -29,6 +29,29 @@ export function opensInBuilder(state) {
29
29
  return false;
30
30
  return formParam === null;
31
31
  }
32
+ /**
33
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
34
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
35
+ * navigation, for an edit view that Next's router opened (a link in the admin).
36
+ *
37
+ * A client navigation right after a full load can lock React in a render loop in development
38
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
39
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
40
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
41
+ * From then on every render applies that close again and makes a new `modalState` object, and the
42
+ * effects that read it set state again, so the idle close never runs. A full page load gives
43
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
44
+ */
45
+ export function builderOpening(loadedUrl, currentUrl) {
46
+ if (!loadedUrl)
47
+ return 'router';
48
+ try {
49
+ return new URL(loadedUrl).pathname === new URL(currentUrl).pathname ? 'page' : 'router';
50
+ }
51
+ catch {
52
+ return 'router';
53
+ }
54
+ }
32
55
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
33
56
  export function documentPath(url, doc) {
34
57
  if (!url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-canvas",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Payload Canvas: a visual drag-and-drop website builder for Payload CMS 3. Nested layout blocks, Tailwind styling, sections, templates, live AI editing over MCP, and the React renderer for your site.",
5
5
  "keywords": [
6
6
  "payload",