payload-canvas 0.1.1 → 0.2.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 (124) hide show
  1. package/README.md +187 -26
  2. package/dist/admin/editor/Canvas.js +30 -8
  3. package/dist/admin/editor/Editor.js +2 -0
  4. package/dist/admin/editor/Inspector.js +14 -7
  5. package/dist/admin/editor/Outline.js +15 -9
  6. package/dist/admin/editor/Overlay.js +2 -1
  7. package/dist/admin/editor/actions.d.ts +5 -0
  8. package/dist/admin/editor/actions.js +23 -1
  9. package/dist/admin/editor/counts.d.ts +6 -0
  10. package/dist/admin/editor/counts.js +10 -0
  11. package/dist/admin/editor/dnd/displace.js +3 -1
  12. package/dist/admin/editor/editor.scss +53 -0
  13. package/dist/admin/editor/inline.d.ts +12 -0
  14. package/dist/admin/editor/inline.js +48 -3
  15. package/dist/admin/editor/insert/spots.js +4 -2
  16. package/dist/admin/editor/live/useMultiplayer.js +8 -2
  17. package/dist/admin/editor/media/ImageEditor.js +21 -15
  18. package/dist/admin/editor/media/actions.d.ts +13 -9
  19. package/dist/admin/editor/media/actions.js +67 -28
  20. package/dist/admin/editor/media/model.d.ts +8 -0
  21. package/dist/admin/editor/media/model.js +14 -6
  22. package/dist/admin/editor/menu/blockMenu.js +13 -8
  23. package/dist/admin/editor/regions/RegionOverlay.d.ts +18 -0
  24. package/dist/admin/editor/regions/RegionOverlay.js +44 -0
  25. package/dist/admin/editor/regions/RegionPane.d.ts +5 -0
  26. package/dist/admin/editor/regions/RegionPane.js +26 -0
  27. package/dist/admin/editor/regions/RegionRows.d.ts +1 -0
  28. package/dist/admin/editor/regions/RegionRows.js +23 -0
  29. package/dist/admin/editor/regions/controller.d.ts +73 -0
  30. package/dist/admin/editor/regions/controller.js +231 -0
  31. package/dist/admin/editor/regions/select.d.ts +17 -0
  32. package/dist/admin/editor/regions/select.js +31 -0
  33. package/dist/admin/editor/runtime.d.ts +6 -0
  34. package/dist/admin/editor/runtime.js +49 -4
  35. package/dist/admin/editor/sections/controller.d.ts +6 -2
  36. package/dist/admin/editor/sections/controller.js +9 -3
  37. package/dist/admin/editor/shortcuts.js +11 -4
  38. package/dist/admin/editor/storage.d.ts +7 -0
  39. package/dist/admin/editor/storage.js +15 -0
  40. package/dist/admin/editor/store.d.ts +39 -0
  41. package/dist/admin/editor/store.js +106 -2
  42. package/dist/admin/editor/templates/Bindable.js +1 -1
  43. package/dist/admin/editor/templates/SamplePicker.js +1 -1
  44. package/dist/admin/editor/topbar/DocumentActions.js +38 -5
  45. package/dist/admin/editor/topbar/closeSave.d.ts +50 -0
  46. package/dist/admin/editor/topbar/closeSave.js +90 -0
  47. package/dist/admin/editor/topbar/document.d.ts +10 -2
  48. package/dist/admin/editor/topbar/document.js +9 -1
  49. package/dist/admin/editor/topbar/drawerLabels.d.ts +22 -0
  50. package/dist/admin/editor/topbar/drawerLabels.js +69 -0
  51. package/dist/admin/editor/topbar/problems.d.ts +9 -0
  52. package/dist/admin/editor/topbar/problems.js +15 -1
  53. package/dist/admin/editor/topbar/settingsDrawer.js +88 -4
  54. package/dist/admin/editor/topbar/settingsFocus.d.ts +11 -0
  55. package/dist/admin/editor/topbar/settingsFocus.js +46 -0
  56. package/dist/admin/editor/ui/payloadA11y.d.ts +17 -0
  57. package/dist/admin/editor/ui/payloadA11y.js +12 -5
  58. package/dist/admin/editor/valueStore.d.ts +2 -0
  59. package/dist/admin/editor/valueStore.js +6 -0
  60. package/dist/core/dropTarget.js +3 -1
  61. package/dist/core/index.d.ts +2 -0
  62. package/dist/core/index.js +2 -0
  63. package/dist/core/payloadBlocks.d.ts +53 -0
  64. package/dist/core/payloadBlocks.js +391 -0
  65. package/dist/core/regions.d.ts +63 -0
  66. package/dist/core/regions.js +239 -0
  67. package/dist/core/types.d.ts +53 -0
  68. package/dist/index.d.ts +1 -0
  69. package/dist/index.js +1 -0
  70. package/dist/live/document.d.ts +9 -1
  71. package/dist/live/document.js +57 -17
  72. package/dist/live/draftAccess.d.ts +36 -0
  73. package/dist/live/draftAccess.js +146 -0
  74. package/dist/live/endpoints.d.ts +11 -2
  75. package/dist/live/endpoints.js +120 -10
  76. package/dist/live/fieldChecks.d.ts +3 -3
  77. package/dist/live/fieldsGuard.d.ts +56 -2
  78. package/dist/live/fieldsGuard.js +107 -11
  79. package/dist/live/index.d.ts +2 -0
  80. package/dist/live/index.js +2 -0
  81. package/dist/live/regions.d.ts +89 -0
  82. package/dist/live/regions.js +401 -0
  83. package/dist/live/runtime.d.ts +1 -1
  84. package/dist/live/runtime.js +5 -2
  85. package/dist/live/session.d.ts +74 -9
  86. package/dist/live/session.js +655 -123
  87. package/dist/live/storage.d.ts +97 -0
  88. package/dist/live/storage.js +269 -0
  89. package/dist/live/types.d.ts +64 -0
  90. package/dist/live/writeGate.d.ts +72 -0
  91. package/dist/live/writeGate.js +478 -0
  92. package/dist/mcp/index.js +56 -12
  93. package/dist/plugin/hook.d.ts +44 -6
  94. package/dist/plugin/hook.js +176 -20
  95. package/dist/plugin/index.d.ts +23 -1
  96. package/dist/plugin/index.js +172 -10
  97. package/dist/plugin/references.d.ts +4 -2
  98. package/dist/plugin/references.js +2 -0
  99. package/dist/plugin/sectionsBuilder.js +3 -3
  100. package/dist/protocol/index.d.ts +28 -2
  101. package/dist/react/canvas/BuilderCanvas.js +198 -8
  102. package/dist/react/canvas/frame.d.ts +70 -0
  103. package/dist/react/canvas/frame.js +66 -0
  104. package/dist/react/canvas/inline/dom.d.ts +7 -1
  105. package/dist/react/canvas/inline/dom.js +19 -9
  106. package/dist/react/canvas/inline/mapper.d.ts +26 -0
  107. package/dist/react/canvas/inline/mapper.js +59 -32
  108. package/dist/react/canvas/inline/session.d.ts +7 -1
  109. package/dist/react/canvas/inline/session.js +6 -2
  110. package/dist/react/canvas/measure.js +26 -1
  111. package/dist/react/index.d.ts +2 -0
  112. package/dist/react/index.js +2 -0
  113. package/dist/react/render/LayoutOutlet.d.ts +11 -0
  114. package/dist/react/render/LayoutOutlet.js +16 -0
  115. package/dist/react/render/canvasFrame.d.ts +46 -0
  116. package/dist/react/render/canvasFrame.js +59 -0
  117. package/dist/react/render/canvasServer.d.ts +13 -0
  118. package/dist/react/render/canvasServer.js +3 -0
  119. package/dist/react/render/canvasServerTypes.d.ts +17 -0
  120. package/dist/react/render/regions.d.ts +13 -0
  121. package/dist/react/render/regions.js +8 -0
  122. package/dist/react/server.d.ts +2 -1
  123. package/dist/react/server.js +1 -0
  124. package/package.json +1 -1
@@ -89,7 +89,7 @@ export function publishProblems(layout, failure) {
89
89
  return [];
90
90
  if (block)
91
91
  return [{ blockId: block.id, field: null, message }];
92
- return [{ blockId: null, field, message }];
92
+ return [{ blockId: null, field, ...(field && path ? { path } : {}), message }];
93
93
  });
94
94
  if (listed.length > 0)
95
95
  return unique(listed);
@@ -101,6 +101,20 @@ export function publishProblems(layout, failure) {
101
101
  return message ? [{ blockId: null, field: null, message }] : [];
102
102
  }
103
103
  /** "2 blocks need attention" / "1 setting needs attention". */
104
+ /**
105
+ * The problems left after a save changed the top-level document fields `fields`: a problem of
106
+ * such a field is gone (its value changed, so the old message no longer says anything about it;
107
+ * the next publish checks it again). Problems of blocks and of other fields stay. Returns `list`
108
+ * itself when nothing goes.
109
+ */
110
+ export function withoutSavedFields(list, fields) {
111
+ if (list.length === 0 || fields.length === 0)
112
+ return list;
113
+ const saved = new Set(fields);
114
+ const topOf = (problem) => (problem.path ?? problem.field ?? '').split('.')[0];
115
+ const next = list.filter((problem) => problem.blockId !== null || !saved.has(topOf(problem)));
116
+ return next.length === list.length ? list : next;
117
+ }
104
118
  export function problemSummary(problems) {
105
119
  const blocks = new Set(problems.flatMap((p) => (p.blockId ? [p.blockId] : []))).size;
106
120
  const other = problems.filter((p) => !p.blockId).length;
@@ -14,9 +14,10 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
14
14
  // A stale save (someone else changed a field after this form loaded; live/fieldsGuard.ts) comes
15
15
  // back as a 409 with an error on each such field. Payload's form keeps what the user typed and
16
16
  // shows the field errors. The banner says who changed what and offers to load their version.
17
- import { Button, PublishButton as PayloadPublishButton, useAllFormFields, useDocumentDrawerContext, useDocumentInfo } from '@payloadcms/ui';
18
- import { createContext, use, useLayoutEffect, useRef, useState } from 'react';
17
+ import { Button, PublishButton as PayloadPublishButton, useAllFormFields, useConfig, useDocumentDrawerContext, useDocumentInfo, useForm, useFormModified, useLocale, useModal, } from '@payloadcms/ui';
18
+ import { createContext, use, useEffect, useLayoutEffect, useRef, useState } from 'react';
19
19
  import { createPortal } from 'react-dom';
20
+ import { autosaveAction, closeMustSave, closesDrawerAtOnce, escapeRoute, keepEscapeInPopup, trackDrawerPopups } from './closeSave.js';
20
21
  import { staleFieldAuthor, topFieldLabel } from '../../../live/staleMessages.js';
21
22
  import './settingsDrawer.scss';
22
23
  /** Slug of the builder's settings drawer. Null outside the builder view. */
@@ -27,10 +28,93 @@ export function PublishButton(props) {
27
28
  const settingsSlug = use(SettingsDrawerSlug);
28
29
  const { drawerSlug } = useDocumentDrawerContext();
29
30
  // In the settings drawer: no button, only the banner after a rejected save.
30
- if (settingsSlug !== null && drawerSlug === settingsSlug)
31
- return _jsx(StaleSaveBanner, {});
31
+ if (settingsSlug !== null && drawerSlug === settingsSlug) {
32
+ return (_jsxs(_Fragment, { children: [_jsx(SaveBeforeClose, {}), _jsx(StaleSaveBanner, {})] }));
33
+ }
32
34
  return _jsx(PayloadPublishButton, { ...props });
33
35
  }
36
+ /**
37
+ * Holds a close of the drawer while autosave has an edit to save (see closeSave.ts). Renders
38
+ * nothing: it listens, in the capture phase, for the clicks and keys that close the drawer at once.
39
+ */
40
+ function SaveBeforeClose() {
41
+ const { submit } = useForm();
42
+ const modified = useFormModified();
43
+ const { id, collectionSlug, docConfig } = useDocumentInfo();
44
+ const { drawerSlug } = useDocumentDrawerContext();
45
+ const { closeModal } = useModal();
46
+ const { config: { routes }, } = useConfig();
47
+ const { code: locale } = useLocale();
48
+ const drafts = docConfig?.versions?.drafts;
49
+ const autosave = typeof drafts === 'object' && Boolean(drafts.autosave);
50
+ const validate = typeof drafts === 'object' && Boolean(drafts.validate);
51
+ const saving = useRef(false);
52
+ const latest = useRef({ modified, submit, id, collectionSlug, locale, api: routes.api, validate, closeModal });
53
+ // After every render: the listener reads the form as it is shown.
54
+ useLayoutEffect(() => {
55
+ latest.current = { modified, submit, id, collectionSlug, locale, api: routes.api, validate, closeModal };
56
+ });
57
+ useEffect(() => {
58
+ if (!drawerSlug)
59
+ return;
60
+ const drawer = document.getElementById(`close-drawer__${drawerSlug}`)?.closest('.drawer');
61
+ if (!drawer)
62
+ return;
63
+ const trackPopups = trackDrawerPopups(drawer);
64
+ const hold = (event) => {
65
+ const state = latest.current;
66
+ const modals = document.querySelectorAll('.payload__modal-item');
67
+ const topmost = modals.length === 0 || modals[modals.length - 1] === drawer;
68
+ const target = event.target instanceof Element ? event.target : null;
69
+ const key = event.key;
70
+ const popupOpen = trackPopups({ type: event.type, key, target });
71
+ // Escape in an open menu, listbox or popup closes that popup only, never the drawer.
72
+ if (escapeRoute({ type: event.type, key, target }, topmost, drawer, popupOpen) === 'popup') {
73
+ keepEscapeInPopup(event);
74
+ return;
75
+ }
76
+ if (!autosave || state.id === undefined || state.id === null || !state.collectionSlug)
77
+ return;
78
+ if (!closesDrawerAtOnce({ type: event.type, key, target }, drawerSlug, topmost, drawer))
79
+ return;
80
+ if (!closeMustSave({ modified: state.modified, autosave, saving: saving.current }))
81
+ return;
82
+ // The form keeps the edit until its save worked.
83
+ event.preventDefault();
84
+ event.stopImmediatePropagation();
85
+ if (saving.current)
86
+ return;
87
+ saving.current = true;
88
+ void (async () => {
89
+ try {
90
+ const result = (await state.submit({
91
+ action: autosaveAction({ api: state.api, collection: state.collectionSlug, id: state.id, locale: state.locale }),
92
+ method: 'PATCH',
93
+ overrides: { _status: 'draft' },
94
+ skipValidation: !state.validate,
95
+ disableSuccessStatus: true,
96
+ acceptValues: { overrideLocalChanges: false },
97
+ }));
98
+ // Saved: close as asked. Not saved: the drawer stays open with the input and Payload's errors.
99
+ if (result?.res?.ok)
100
+ state.closeModal(drawerSlug);
101
+ }
102
+ finally {
103
+ saving.current = false;
104
+ }
105
+ })();
106
+ };
107
+ window.addEventListener('click', hold, true);
108
+ window.addEventListener('keydown', hold, true);
109
+ window.addEventListener('mouseover', hold, true);
110
+ return () => {
111
+ window.removeEventListener('click', hold, true);
112
+ window.removeEventListener('keydown', hold, true);
113
+ window.removeEventListener('mouseover', hold, true);
114
+ };
115
+ }, [autosave, drawerSlug]);
116
+ return null;
117
+ }
34
118
  function listText(items) {
35
119
  if (items.length <= 1)
36
120
  return items[0] ?? '';
@@ -0,0 +1,11 @@
1
+ /** The field the settings drawer opens at. `tabs`: the labels of the tabs that hold it, outermost first. */
2
+ export type SettingsFocus = {
3
+ path: string;
4
+ tabs: readonly string[];
5
+ };
6
+ /** The id Payload gives a field's element: dots become "__". */
7
+ export declare const fieldElementId: (path: string) => string;
8
+ /** True for Payload's id of the field: `field-title`, or `field-title-2` in a drawer. */
9
+ export declare function isFieldElementId(id: string, path: string): boolean;
10
+ /** Finds the field in the drawer `slug` and focuses it. Gives up quietly after a few seconds. */
11
+ export declare function focusDrawerField(slug: string, focus: SettingsFocus): void;
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ const TIMEOUT_MS = 5000;
3
+ const RETRY_MS = 100;
4
+ /** The id Payload gives a field's element: dots become "__". */
5
+ export const fieldElementId = (path) => `field-${path.replace(/\./g, '__')}`;
6
+ /** True for Payload's id of the field: `field-title`, or `field-title-2` in a drawer. */
7
+ export function isFieldElementId(id, path) {
8
+ const base = fieldElementId(path);
9
+ return id === base || (id.startsWith(base) && /^-\d+$/.test(id.slice(base.length)));
10
+ }
11
+ /** Finds the field in the drawer `slug` and focuses it. Gives up quietly after a few seconds. */
12
+ export function focusDrawerField(slug, focus) {
13
+ const started = Date.now();
14
+ const opened = new Set();
15
+ const step = () => {
16
+ if (Date.now() - started > TIMEOUT_MS)
17
+ return;
18
+ const drawer = document.getElementById(`close-drawer__${slug}`)?.closest('.drawer');
19
+ if (!drawer) {
20
+ window.setTimeout(step, RETRY_MS);
21
+ return;
22
+ }
23
+ for (const label of focus.tabs) {
24
+ if (opened.has(label))
25
+ continue;
26
+ const tab = [...drawer.querySelectorAll('.tabs-field__tab-button')].find((button) => button.textContent?.trim().startsWith(label));
27
+ if (!tab)
28
+ break;
29
+ opened.add(label);
30
+ if (!tab.classList.contains('tabs-field__tab-button--active')) {
31
+ tab.click();
32
+ window.setTimeout(step, RETRY_MS);
33
+ return;
34
+ }
35
+ }
36
+ const field = [...drawer.querySelectorAll('[id^="field-"]')].find((el) => isFieldElementId(el.id, focus.path));
37
+ if (!field) {
38
+ window.setTimeout(step, RETRY_MS);
39
+ return;
40
+ }
41
+ field.scrollIntoView({ block: 'center' });
42
+ const input = field.matches('input, textarea, select, button') ? field : field.querySelector('input, textarea, [contenteditable="true"], button');
43
+ input?.focus({ preventScroll: true });
44
+ };
45
+ step();
46
+ }
@@ -1,3 +1,20 @@
1
1
  import { type RefObject } from 'react';
2
+ /** The part of the DOM `nameComboboxes` reads and writes (tests pass small fakes). */
3
+ export type ComboboxScope = {
4
+ querySelectorAll(selector: string): Iterable<ComboboxInput>;
5
+ };
6
+ export type ComboboxInput = {
7
+ closest(selector: string): {
8
+ querySelector(selector: string): {
9
+ textContent: string | null;
10
+ } | null;
11
+ } | null;
12
+ setAttribute(name: string, value: string): void;
13
+ };
14
+ /**
15
+ * Names Payload's react-select inputs (selects, relationships) that have no name, by their field's
16
+ * label. Payload's label points at an id the react-select input does not have.
17
+ */
18
+ export declare function nameComboboxes(root: ComboboxScope): void;
2
19
  /** Names Payload's unnamed controls inside `ref`, also those that mount later. */
3
20
  export declare function usePayloadControlNames(ref: RefObject<HTMLElement | null>): void;
@@ -18,6 +18,17 @@ function fieldLabel(el) {
18
18
  const label = field?.querySelector('.field-label, label')?.textContent?.replace(/\*$/, '').trim();
19
19
  return label || null;
20
20
  }
21
+ /**
22
+ * Names Payload's react-select inputs (selects, relationships) that have no name, by their field's
23
+ * label. Payload's label points at an id the react-select input does not have.
24
+ */
25
+ export function nameComboboxes(root) {
26
+ for (const input of root.querySelectorAll('input.rs__input:not([aria-label]):not([aria-labelledby])')) {
27
+ const label = fieldLabel(input);
28
+ if (label)
29
+ input.setAttribute('aria-label', label);
30
+ }
31
+ }
21
32
  function nameControls(root) {
22
33
  for (const [selector, name] of BUTTON_NAMES) {
23
34
  for (const el of root.querySelectorAll(selector)) {
@@ -34,11 +45,7 @@ function nameControls(root) {
34
45
  wrapper.removeAttribute('tabindex');
35
46
  }
36
47
  // react-select inputs: named by their field label.
37
- for (const input of root.querySelectorAll('input.rs__input:not([aria-label]):not([aria-labelledby])')) {
38
- const label = fieldLabel(input);
39
- if (label)
40
- input.setAttribute('aria-label', label);
41
- }
48
+ nameComboboxes(root);
42
49
  // react-select marks its chevron and clear buttons aria-hidden but leaves them focusable.
43
50
  for (const el of root.querySelectorAll('[aria-hidden="true"]:is(button, [tabindex="0"])')) {
44
51
  el.setAttribute('tabindex', '-1');
@@ -28,3 +28,5 @@ export declare function useSelector<S, T>(subscribe: (listener: () => void) => (
28
28
  export declare function useValueSelector<S, T>(store: ValueStore<S>, selector: (value: S) => T, isEqual?: Equality<T>): T;
29
29
  /** Equal when both arrays hold the same items (by `Object.is`) in the same order. */
30
30
  export declare function sameItems<T>(a: readonly T[], b: readonly T[]): boolean;
31
+ /** The value of a store that may not exist (an optional feature): null without one. */
32
+ export declare function useOptionalValue<T>(store: ValueStore<T> | null): T | null;
@@ -57,3 +57,9 @@ export function useValueSelector(store, selector, isEqual) {
57
57
  export function sameItems(a, b) {
58
58
  return a === b || (a.length === b.length && a.every((item, i) => Object.is(item, b[i])));
59
59
  }
60
+ const noSubscription = () => () => { };
61
+ const nothing = () => null;
62
+ /** The value of a store that may not exist (an optional feature): null without one. */
63
+ export function useOptionalValue(store) {
64
+ return useSyncExternalStore(store?.subscribe ?? noSubscription, store?.get ?? nothing, store?.get ?? nothing);
65
+ }
@@ -176,9 +176,11 @@ export function canvasDropTarget(layout, blocks, measurement, p, source) {
176
176
  if (!accepts(null, DEFAULT_SLOT))
177
177
  return null;
178
178
  if (layout.blocks.length === 0) {
179
+ // In a page frame the empty layout is its outlet, between the fixed regions.
180
+ const root = measurement.root;
179
181
  return finalize(index, source, null, DEFAULT_SLOT, 0, {
180
182
  kind: 'box',
181
- rect: { x: 0, y: 0, width: measurement.viewport.width, height: 80 },
183
+ rect: root ? { ...root, height: Math.max(root.height, 80) } : { x: 0, y: 0, width: measurement.viewport.width, height: 80 },
182
184
  });
183
185
  }
184
186
  return betweenChildren(null, DEFAULT_SLOT);
@@ -16,5 +16,7 @@ export { FORMATS, formatProblem, isPlayableVideoUrl, parseVideoUrl, videoUrlProb
16
16
  export { describeLayoutErrors, summarizeProblems, type LayoutIssue } from './issues.js';
17
17
  export { conditionFromFunction, conditionMet, readCondition, type BuilderCondition } from './conditions.js';
18
18
  export { convertPayloadBlocksLayout, definitionForBlockType, isPayloadBlocksValue, payloadSlugOf, toPayloadBlock, withFieldDefaults, withLayoutDefaults, hasStaticDefault, type ConvertPayloadOptions, type PayloadBlockData, type PayloadConversion, type PayloadConversionReport, } from './convertPayload.js';
19
+ export { decodePayloadBlocks, encodePayloadBlocks, payloadBlocksProblems, payloadBlocksStorage, type PayloadBlocksDecode, type PayloadBlocksStorage, } from './payloadBlocks.js';
19
20
  export { dataFields, fieldAtPropPath, type DataField } from './fields.js';
21
+ export { pathWithoutIndexes, regionAccessAt, regionDefinition, regionFieldOf, regionSelect, regionsTouched, regionType, regionValues, resolveRegions, setDocPath, valueAtDocPath, type RegionOption, } from './regions.js';
20
22
  export { collectReferences, readReferences, referenceKey, referenceTargets, sameReferences, type Reference, type ReferenceTargets } from './references.js';
@@ -18,5 +18,7 @@ export { FORMATS, formatProblem, isPlayableVideoUrl, parseVideoUrl, videoUrlProb
18
18
  export { describeLayoutErrors, summarizeProblems } from './issues.js';
19
19
  export { conditionFromFunction, conditionMet, readCondition } from './conditions.js';
20
20
  export { convertPayloadBlocksLayout, definitionForBlockType, isPayloadBlocksValue, payloadSlugOf, toPayloadBlock, withFieldDefaults, withLayoutDefaults, hasStaticDefault, } from './convertPayload.js';
21
+ export { decodePayloadBlocks, encodePayloadBlocks, payloadBlocksProblems, payloadBlocksStorage, } from './payloadBlocks.js';
21
22
  export { dataFields, fieldAtPropPath } from './fields.js';
23
+ export { pathWithoutIndexes, regionAccessAt, regionDefinition, regionFieldOf, regionSelect, regionsTouched, regionType, regionValues, resolveRegions, setDocPath, valueAtDocPath, } from './regions.js';
22
24
  export { collectReferences, readReferences, referenceKey, referenceTargets, sameReferences } from './references.js';
@@ -0,0 +1,53 @@
1
+ import type { BlockDefinition, Layout, Operation } from './types.js';
2
+ /** The block types a Payload blocks field holds, as the builder sees them. */
3
+ export type PayloadBlocksStorage = {
4
+ /** The definitions of every block type the field holds, at any depth (from `fromPayloadBlocks`). */
5
+ blocks: readonly BlockDefinition[];
6
+ /** The block types the field allows at its top level. */
7
+ rootTypes: readonly string[];
8
+ };
9
+ export type PayloadBlocksDecode = {
10
+ ok: true;
11
+ layout: Layout;
12
+ } | {
13
+ ok: false;
14
+ error: string;
15
+ };
16
+ /**
17
+ * Reads a stored Payload blocks value (`[{ id, blockType, blockName?, ...fields }]`) into a layout.
18
+ * `null` or a missing value is an empty layout. Refuses data it cannot keep exactly.
19
+ */
20
+ export declare function decodePayloadBlocks(value: unknown, storage: PayloadBlocksStorage): PayloadBlocksDecode;
21
+ /**
22
+ * What in a layout a Payload blocks field cannot hold. Empty when the layout can be stored as it is.
23
+ * The builder refuses such a change instead of saving part of it.
24
+ */
25
+ export declare function payloadBlocksProblems(layout: Layout, storage: PayloadBlocksStorage): string[];
26
+ /**
27
+ * Writes a layout back as the Payload blocks value: `[{ id, blockType, blockName?, ...props,
28
+ * ...slots }]`. Every prop goes back as it is (no defaults). Check `payloadBlocksProblems` first:
29
+ * data the field cannot hold is not written.
30
+ *
31
+ * `previous`: the value stored now. Payload keeps a row's stored value for a key the saved row
32
+ * leaves out, so a value the layout removed (a cleared prop, a cleared block name) is written as
33
+ * `null` when the stored row (same id) has it. Keys the stored row does not have stay out.
34
+ */
35
+ export declare function encodePayloadBlocks(layout: Layout, storage: PayloadBlocksStorage, previous?: unknown): Record<string, unknown>[];
36
+ /**
37
+ * The storage of a Payload blocks field: the definitions of its block types at every depth, found
38
+ * by their Payload slug among `definitions`, and the types it allows at the top level. Throws when
39
+ * a block type of the field has no definition.
40
+ */
41
+ export declare function payloadBlocksStorage(topSlugs: readonly string[], definitions: readonly BlockDefinition[], where: string): PayloadBlocksStorage;
42
+ /** The row ids of a stored blocks value (array rows and nested Payload blocks, at every depth). */
43
+ export declare function payloadRowIds(value: unknown, storage: PayloadBlocksStorage): Set<string>;
44
+ /**
45
+ * Payload stores the rows of array fields and nested blocks fields by their id, in one table per
46
+ * field for every document, and its own editor gives every pasted or copied row a new id. A block
47
+ * inserted by the builder (a duplicate, a paste from another page, a section) carries the rows of
48
+ * what it was copied from. This gives each inserted row a new id unless the id is this
49
+ * document's own: in `owned` (rows its stored value has held: undoing a removal puts the same rows
50
+ * back) and not in the layout or earlier in the same operations. Without `owned`, only ids already
51
+ * in the layout get new ones. Returns `ops` itself when nothing changed.
52
+ */
53
+ export declare function withUniqueRowIds(layout: Layout, ops: readonly Operation[], storage: PayloadBlocksStorage, owned?: ReadonlySet<string>): Operation[];