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
@@ -3,12 +3,14 @@
3
3
  // (`imageHover`), a double-click (`imageEdit`) and a dropped file (`imageDrop`). Every change of
4
4
  // the layout is one `update` operation through the store, so it is one undo step and syncs to
5
5
  // collaborators like any edit. Alt text of a media document is the one change outside the layout:
6
- // it is saved on the document over REST.
6
+ // it is saved on the document over REST. An image of a page region shows a document field: its
7
+ // change is saved to the document (`runtime.regions`), also one undo step.
7
8
  import { dataFields, findBlock, getBlockDefinition } from '../../../core/index.js';
8
9
  import { textOf } from '../../../core/fields.js';
9
10
  import { lockedMessage } from '../fields/accessRules.js';
11
+ import { ownerKey } from '../regions/select.js';
10
12
  import { createValueStore } from '../valueStore.js';
11
- import { altFromFileName, removeOp, uploadFieldAt, uploadValue } from './model.js';
13
+ import { altFromFileName, removeChange, removeOp, uploadFieldAt, uploadValue } from './model.js';
12
14
  import { inlineUpdate } from '../inline.js';
13
15
  const stores = new WeakMap();
14
16
  /** The image editing state of this editor. */
@@ -26,14 +28,25 @@ export function updateImageEditor(runtime, change) {
26
28
  }
27
29
  const humanize = (name) => name.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, (c) => c.toUpperCase());
28
30
  const labelOf = (field) => textOf(field.label) ?? humanize(field.name ?? '');
29
- /** The block, its definition and the upload field behind a canvas image, or null when one is gone. */
30
- export function imageSpotContext(runtime, blockId, path) {
31
+ /** The block (or the region's values) and the definition behind a canvas image owner. */
32
+ function ownerData(runtime, owner) {
33
+ if (owner.region) {
34
+ const definition = runtime.regions?.definition(owner.region);
35
+ const values = runtime.regions?.state.get().values;
36
+ return definition && values ? { block: { id: '', type: definition.type, props: values }, definition } : null;
37
+ }
31
38
  // The block as the canvas shows it (the editor's locale): the store writes that locale.
32
- const block = findBlock(runtime.store.getState().view, blockId);
39
+ const block = findBlock(runtime.store.getState().view, owner.id);
33
40
  const definition = block ? getBlockDefinition(runtime.config.blocks, block.type) : undefined;
34
- const spot = definition ? uploadFieldAt(definition, path) : null;
35
- if (!block || !definition || !spot)
41
+ return block && definition ? { block, definition } : null;
42
+ }
43
+ /** The block, its definition and the upload field behind a canvas image, or null when one is gone. */
44
+ export function imageSpotContext(runtime, owner, path) {
45
+ const data = ownerData(runtime, owner);
46
+ const spot = data ? uploadFieldAt(data.definition, path) : null;
47
+ if (!data || !spot)
36
48
  return null;
49
+ const { block, definition } = data;
37
50
  // The deepest array row on the path names the item ("Gallery Items 4").
38
51
  const segments = path.split('.');
39
52
  let row = '';
@@ -50,53 +63,79 @@ export function imageSpotContext(runtime, blockId, path) {
50
63
  fields = field.fields ?? [];
51
64
  }
52
65
  const own = labelOf(spot.field);
53
- return { block, definition, spot, label: row ? `${own} · ${row}` : own };
66
+ return { block, definition, spot, label: row ? `${own} · ${row}` : own, ...(owner.region ? { region: owner.region } : {}) };
67
+ }
68
+ /** Why the user may not change `path` of the owner now, or null. */
69
+ function lockedFor(runtime, context, path) {
70
+ // `null` from `lockedMessage` means allowed: only a missing regions controller is a refusal.
71
+ if (context.region)
72
+ return runtime.regions ? runtime.regions.lockedMessage(path) : 'This page has no regions.';
73
+ return lockedMessage(runtime, context.block, path);
54
74
  }
55
75
  /** Refuses a change the user may not make (field access) and says why. True when it refused. */
56
76
  function refused(runtime, context, path) {
57
- const text = lockedMessage(runtime, context.block, path);
77
+ const text = lockedFor(runtime, context, path);
58
78
  if (text)
59
79
  runtime.warn(text);
60
80
  return Boolean(text);
61
81
  }
82
+ /** Writes one value: an `update` operation for a block, a document field save for a region. One undo step. */
83
+ function writeValue(runtime, context, path, value) {
84
+ if (context.region) {
85
+ if (!runtime.regions)
86
+ return false;
87
+ void runtime.regions.write([{ path, value }]);
88
+ return true;
89
+ }
90
+ const op = inlineUpdate(context.block, path, value);
91
+ return op ? runtime.store.apply(op) : true;
92
+ }
62
93
  /** Sets the stored value of the upload at `path` (an id, or `{ relationTo, value }`): one undo step. */
63
- export function setImageValue(runtime, blockId, path, value) {
64
- const context = imageSpotContext(runtime, blockId, path);
94
+ export function setImageValue(runtime, owner, path, value) {
95
+ const context = imageSpotContext(runtime, owner, path);
65
96
  if (!context) {
66
97
  runtime.warn('That image is gone: someone changed the page. Try again.');
67
98
  return false;
68
99
  }
69
100
  if (refused(runtime, context, path))
70
101
  return false;
71
- const op = inlineUpdate(context.block, path, value);
72
- return op ? runtime.store.apply(op) : true;
102
+ return writeValue(runtime, context, path, value);
73
103
  }
74
104
  /** Sets a media document on the upload at `path`: one undo step. */
75
- export function setImage(runtime, blockId, path, collection, id) {
76
- const context = imageSpotContext(runtime, blockId, path);
77
- return context ? setImageValue(runtime, blockId, path, uploadValue(context.spot, collection, id)) : false;
105
+ export function setImage(runtime, owner, path, collection, id) {
106
+ const context = imageSpotContext(runtime, owner, path);
107
+ return context ? setImageValue(runtime, owner, path, uploadValue(context.spot, collection, id)) : false;
78
108
  }
79
109
  /** Empties the upload at `path` (removes the item of a hasMany upload): one undo step. */
80
- export function removeImage(runtime, blockId, path) {
81
- const context = imageSpotContext(runtime, blockId, path);
110
+ export function removeImage(runtime, owner, path) {
111
+ const context = imageSpotContext(runtime, owner, path);
82
112
  if (!context || refused(runtime, context, path))
83
113
  return false;
114
+ if (context.region) {
115
+ const change = removeChange(context.block.props, path, context.spot);
116
+ return change ? writeValue(runtime, context, change.path, change.value) : false;
117
+ }
84
118
  const op = removeOp(context.block, path, context.spot);
85
119
  return op ? runtime.store.apply(op) : false;
86
120
  }
87
121
  /** Sets a text prop (alt text next to the upload). Typing in one field merges into one undo step. */
88
- export function setAltProp(runtime, blockId, path, value) {
89
- const block = findBlock(runtime.store.getState().view, blockId);
90
- if (!block)
122
+ export function setAltProp(runtime, owner, path, value) {
123
+ const data = ownerData(runtime, owner);
124
+ if (!data)
91
125
  return;
92
- const text = lockedMessage(runtime, block, path);
126
+ const text = lockedFor(runtime, { block: data.block, region: owner.region }, path);
93
127
  if (text) {
94
128
  runtime.warn(text);
95
129
  return;
96
130
  }
97
- const op = inlineUpdate(block, path, value);
131
+ // A region's alt text is a document field: saved when the input is done (blur or Enter).
132
+ if (owner.region) {
133
+ void runtime.regions?.write([{ path, value }]);
134
+ return;
135
+ }
136
+ const op = inlineUpdate(data.block, path, value);
98
137
  if (op)
99
- runtime.store.apply(op, { mergeKey: `alt:${blockId}:${path}` });
138
+ runtime.store.apply(op, { mergeKey: `alt:${owner.id}:${path}` });
100
139
  }
101
140
  const errorOf = (body, status, action) => {
102
141
  const errors = body?.errors;
@@ -115,17 +154,17 @@ export async function uploadMedia(runtime, collection, file) {
115
154
  return body.doc;
116
155
  }
117
156
  /** Uploads `file` and sets it on the upload at `path`. Shows progress on the image and the result. */
118
- export async function uploadImage(runtime, blockId, path, file) {
119
- const context = imageSpotContext(runtime, blockId, path);
157
+ export async function uploadImage(runtime, owner, path, file) {
158
+ const context = imageSpotContext(runtime, owner, path);
120
159
  if (!context || refused(runtime, context, path))
121
160
  return false;
122
161
  const collection = context.spot.collections[0];
123
162
  if (!collection)
124
163
  return false;
125
- updateImageEditor(runtime, { busy: { id: blockId, path } });
164
+ updateImageEditor(runtime, { busy: { key: ownerKey(owner), path } });
126
165
  try {
127
166
  const doc = await uploadMedia(runtime, collection, file);
128
- if (!setImage(runtime, blockId, path, collection, doc.id))
167
+ if (!setImage(runtime, owner, path, collection, doc.id))
129
168
  return false;
130
169
  runtime.notify(`Uploaded ${file.name}`);
131
170
  return true;
@@ -19,6 +19,14 @@ export declare function mediaRef(spot: UploadSpotField, value: unknown): {
19
19
  collection: string;
20
20
  id: string | number;
21
21
  } | null;
22
+ /**
23
+ * The change that empties the upload at `path`: null at the path for a single upload, the list
24
+ * without the item for one value of a hasMany upload. Null when the item is gone.
25
+ */
26
+ export declare function removeChange(props: Record<string, unknown> | undefined, path: string, spot: UploadSpotField): {
27
+ path: string;
28
+ value: unknown;
29
+ } | null;
22
30
  /**
23
31
  * The operation that empties the upload at `path`: null for a single upload, the list without the
24
32
  * item for one value of a hasMany upload.
@@ -38,21 +38,29 @@ export function mediaRef(spot, value) {
38
38
  return id === null ? null : { collection: spot.collections[0] ?? '', id };
39
39
  }
40
40
  /**
41
- * The operation that empties the upload at `path`: null for a single upload, the list without the
42
- * item for one value of a hasMany upload.
41
+ * The change that empties the upload at `path`: null at the path for a single upload, the list
42
+ * without the item for one value of a hasMany upload. Null when the item is gone.
43
43
  */
44
- export function removeOp(block, path, spot) {
44
+ export function removeChange(props, path, spot) {
45
45
  if (!spot.item)
46
- return inlineUpdate(block, path, null);
46
+ return { path, value: null };
47
47
  const cut = path.lastIndexOf('.');
48
48
  const listPath = path.slice(0, cut);
49
49
  const index = Number(path.slice(cut + 1));
50
- let list = block.props;
50
+ let list = props;
51
51
  for (const segment of listPath.split('.'))
52
52
  list = Array.isArray(list) ? list[Number(segment)] : isRecord(list) ? list[segment] : undefined;
53
53
  if (!Array.isArray(list) || index >= list.length)
54
54
  return null;
55
- return inlineUpdate(block, listPath, list.filter((_, i) => i !== index));
55
+ return { path: listPath, value: list.filter((_, i) => i !== index) };
56
+ }
57
+ /**
58
+ * The operation that empties the upload at `path`: null for a single upload, the list without the
59
+ * item for one value of a hasMany upload.
60
+ */
61
+ export function removeOp(block, path, spot) {
62
+ const change = removeChange(block.props, path, spot);
63
+ return change ? inlineUpdate(block, change.path, change.value) : null;
56
64
  }
57
65
  /**
58
66
  * A text prop next to the upload that holds its alt text (`alt`, `altText`, `<name>Alt`), or null.
@@ -4,7 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  // the right-click menu on the canvas and in the outline, so they never drift apart.
5
5
  import { memo, useCallback } from 'react';
6
6
  import { findBlock, findLocation } from '../../../core/index.js';
7
- import { copyBlock, copyStyles, duplicateBlock, inRow, moveBy, parseClipboard, pasteStoredBlocks, pasteStyles, removeBlock, resetStyles, siblingCount, storedClipboard, storedStyles, toggleHidden, } from '../actions.js';
7
+ import { copyBlock, copyStyles, duplicateBlock, inRow, moveBy, parseClipboard, pasteStoredBlocks, pasteStyles, removeBlock, resetStyles, siblingCount, storedClipboard, storedStyles, storesBuilderData, toggleHidden, } from '../actions.js';
8
8
  import { useRuntime } from '../runtime.js';
9
9
  import { requestSaveSection } from '../sections/SectionDialog.js';
10
10
  import { useEditor } from '../store.js';
@@ -36,7 +36,8 @@ export function blockMenuEntries(runtime, id, origin) {
36
36
  const parentId = location?.parentId ?? null;
37
37
  const siblings = location ? siblingCount(layout, location.parentId, location.slot) : 0;
38
38
  const row = inRow(layout, runtime.measurement.get(), id);
39
- const styled = hasStyles(runtime.config.blocks, block.type);
39
+ // A Payload blocks field stores no styles (storesBuilderData), whatever the definition says.
40
+ const styled = storesBuilderData(runtime) && hasStyles(runtime.config.blocks, block.type);
40
41
  return [
41
42
  { icon: 'parent', label: 'Select parent', keys: keys('parent'), disabled: !parentId, run: () => parentId && runtime.store.select(parentId) },
42
43
  { icon: 'rename', label: 'Rename', keys: keys('rename'), ownFocus: true, run: () => requestRename(runtime, id, origin === 'outline' ? 'outline' : 'inspector') },
@@ -77,12 +78,16 @@ export function blockMenuEntries(runtime, id, origin) {
77
78
  },
78
79
  { icon: ERASER, label: 'Reset styles', disabled: !styled || normalizeClasses(block.className) === '', run: () => resetStyles(runtime, [id]) },
79
80
  'separator',
80
- {
81
- icon: block.hidden ? 'eye' : 'eyeOff',
82
- label: block.hidden ? 'Show on the site' : 'Hide on the site',
83
- keys: keys('hide'),
84
- run: () => toggleHidden(runtime, id),
85
- },
81
+ ...(storesBuilderData(runtime)
82
+ ? [
83
+ {
84
+ icon: (block.hidden ? 'eye' : 'eyeOff'),
85
+ label: block.hidden ? 'Show on the site' : 'Hide on the site',
86
+ keys: keys('hide'),
87
+ run: () => toggleHidden(runtime, id),
88
+ },
89
+ ]
90
+ : []),
86
91
  ...(runtime.sections.enabled
87
92
  ? [{ icon: 'section', label: 'Save as section…', ownFocus: true, run: () => requestSaveSection(runtime, block) }]
88
93
  : []),
@@ -0,0 +1,18 @@
1
+ import type { CSSProperties } from 'react';
2
+ import type { Rect } from '../../../core/types.js';
3
+ import { type Runtime } from '../runtime.js';
4
+ import type { RegionsController } from './controller.js';
5
+ type TagProps = {
6
+ className: string;
7
+ style?: CSSProperties;
8
+ };
9
+ /** Opens the settings drawer at the region's first field (or at its top for a region without fields). */
10
+ export declare function editRegionFields(runtime: Runtime, regions: RegionsController, name: string): void;
11
+ export declare function RegionOverlay({ tagProps, editedRect, zoom, }: {
12
+ /** The overlay's name tag placement. */
13
+ tagProps: (rect: Rect, modifier?: string) => TagProps;
14
+ /** The element edited inline now, or null. */
15
+ editedRect: Rect | null;
16
+ zoom: number;
17
+ }): import("react").JSX.Element | null;
18
+ export {};
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Icon } from '../icons.js';
4
+ import { inlineEditing } from '../inline.js';
5
+ import { InlineToolbar } from '../InlineToolbar.js';
6
+ import { useRuntime } from '../runtime.js';
7
+ import { useOptionalValue, useValue } from '../valueStore.js';
8
+ const box = (rect) => ({ left: rect.x, top: rect.y, width: rect.width, height: rect.height });
9
+ /** The box of a region on the canvas: the largest of its visible elements. */
10
+ function regionRect(rects, name) {
11
+ if (!name)
12
+ return null;
13
+ let best = null;
14
+ for (const entry of rects ?? []) {
15
+ if (entry.name !== name)
16
+ continue;
17
+ if (!best || entry.rect.width * entry.rect.height > best.width * best.height)
18
+ best = entry.rect;
19
+ }
20
+ return best;
21
+ }
22
+ /** Opens the settings drawer at the region's first field (or at its top for a region without fields). */
23
+ export function editRegionFields(runtime, regions, name) {
24
+ const first = regions.region(name)?.fields[0];
25
+ runtime.doc.openSettings(first ? { path: first.path, tabs: first.tabs } : undefined);
26
+ }
27
+ export function RegionOverlay({ tagProps, editedRect, zoom, }) {
28
+ const runtime = useRuntime();
29
+ const regions = runtime.regions;
30
+ const selected = useOptionalValue(regions?.selected ?? null);
31
+ const hovered = useOptionalValue(regions?.hovered ?? null);
32
+ const measurement = useValue(runtime.measurement);
33
+ const drag = useValue(runtime.drag);
34
+ const inline = useValue(inlineEditing(runtime));
35
+ if (!regions)
36
+ return null;
37
+ const hoverRect = !drag && hovered !== selected ? regionRect(measurement?.regions, hovered) : null;
38
+ const selectedRect = regionRect(measurement?.regions, selected);
39
+ const hoverRegion = regions.region(hovered);
40
+ const region = regions.region(selected);
41
+ const editing = Boolean(inline?.region && inline.region === selected);
42
+ const editRect = editing ? (editedRect ?? selectedRect) : selectedRect;
43
+ return (_jsxs(_Fragment, { children: [hoverRect && hoverRegion && (_jsx("div", { className: "builder-editor__hover builder-editor__hover--region", style: box(hoverRect), children: _jsxs("span", { ...tagProps(hoverRect, 'hover'), children: [_jsx(Icon, { name: "lock", size: 12 }), hoverRegion.label] }) })), region && selectedRect && editRect && (_jsxs(_Fragment, { children: [_jsxs("div", { className: `builder-editor__selection builder-editor__selection--region${editing ? ' builder-editor__selection--editing' : ''}`, style: box(editRect), children: [editing && inline?.kind !== 'rich' && (_jsxs("span", { ...tagProps(editRect, 'editing'), children: [_jsx(Icon, { name: "rename", size: 12 }), "Editing text \u00B7 Esc to finish"] })), !editing && !drag && (_jsxs("span", { ...tagProps(selectedRect), "data-tooltip": "A fixed part of the page. Edit its text and images here, or its fields in the settings.", children: [_jsx(Icon, { name: "lock", size: 12 }), region.label, _jsx("span", { className: "builder-editor__tag-note", children: "Fixed" })] }))] }), !editing && !drag && (_jsx("div", { className: `builder-editor__actions builder-editor__actions--${selectedRect.y * zoom >= 26 ? 'above' : 'inside'}`, style: { left: selectedRect.x + selectedRect.width, top: selectedRect.y }, children: _jsxs("button", { type: "button", className: "builder-editor__action builder-editor__action--text", "aria-label": `Edit the fields of ${region.label}`, "data-tooltip": "Edit all fields in the settings", onClick: () => editRegionFields(runtime, regions, region.name), children: [_jsx(Icon, { name: "settings", size: 14 }), "Edit fields"] }) })), editing && editRect && inline?.kind === 'rich' && _jsx(InlineToolbar, { inline: inline, rect: editRect, zoom: zoom })] }))] }));
44
+ }
@@ -0,0 +1,5 @@
1
+ import type { RegionsController } from './controller.js';
2
+ export declare function RegionPane({ regions, name }: {
3
+ regions: RegionsController;
4
+ name: string;
5
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The inspector for a selected page region: what it is, its fields, and the way to edit them.
4
+ // The fields are edited with Payload's own form in the settings drawer (every field type, with
5
+ // Payload's validation and access) and, for text and images, on the canvas.
6
+ import { Button } from '@payloadcms/ui';
7
+ import { regionAccessAt, regionFieldOf } from '../../../core/regions.js';
8
+ import { Icon } from '../icons.js';
9
+ import { useRuntime } from '../runtime.js';
10
+ import { useValue } from '../valueStore.js';
11
+ import { editRegionFields } from './RegionOverlay.js';
12
+ export function RegionPane({ regions, name }) {
13
+ const runtime = useRuntime();
14
+ const state = useValue(regions.state);
15
+ const allProblems = useValue(runtime.problems);
16
+ const region = regions.region(name);
17
+ if (!region)
18
+ return null;
19
+ const problems = allProblems.filter((p) => p.path && regionFieldOf([region], p.path));
20
+ const drafts = runtime.doc.meta.get().drafts;
21
+ return (_jsxs("div", { className: "builder-editor__block-pane", children: [_jsxs("div", { className: "builder-editor__block-head", children: [_jsx("span", { className: "builder-editor__block-icon", children: _jsx(Icon, { name: "lock", size: 16 }) }), _jsxs("span", { className: "builder-editor__block-name", children: [_jsx("span", { className: "builder-editor__block-title", children: region.label }), _jsx("span", { className: "builder-editor__block-sub", children: "Fixed part of the page" })] })] }), problems.length > 0 && (_jsxs("div", { className: "builder-editor__block-problems", role: "alert", children: [_jsx(Icon, { name: "warning", size: 14 }), _jsxs("div", { children: [_jsx("p", { className: "builder-editor__block-problems-title", children: "Fix this to publish" }), _jsx("ul", { children: problems.map((p) => (_jsx("li", { children: p.message }, p.message))) })] })] })), _jsxs("div", { className: "builder-editor__fields", children: [_jsxs("p", { className: "builder-editor__hint", children: ["It shows fields of this document, outside the layout. Double-click its text or images on the canvas to edit them. Changes save to the document", drafts ? ' as a draft, and go live when you publish' : '', "."] }), state.status === 'error' && (_jsx("p", { className: "builder-editor__hint", role: "alert", children: state.error })), region.fields.length > 0 ? (_jsx("ul", { className: "builder-region__fields", children: region.fields.map((field) => {
22
+ const right = state.access ? regionAccessAt(state.access, field.path) : null;
23
+ const locked = right !== null && !right.update;
24
+ return (_jsx("li", { children: _jsxs("button", { type: "button", className: "builder-editor__menu-item", onClick: () => runtime.doc.openSettings({ path: field.path, tabs: field.tabs }), "data-tooltip": locked ? 'You may not change this field' : 'Edit in the settings', children: [_jsx(Icon, { name: locked ? 'lock' : 'rename', size: 14 }), field.label] }) }, field.path));
25
+ }) })) : (_jsx("p", { className: "builder-editor__hint", children: "It has no fields to edit." })), _jsx(Button, { buttonStyle: "secondary", size: "small", margin: false, onClick: () => editRegionFields(runtime, regions, region.name), children: "Edit fields in the settings" })] })] }));
26
+ }
@@ -0,0 +1 @@
1
+ export declare function RegionRows(): import("react").JSX.Element | null;
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The page's fixed regions in the Layers panel, above the layout's tree. They select the region;
4
+ // they are not part of the tree, so nothing drags onto or out of them.
5
+ import { Icon } from '../icons.js';
6
+ import { useRuntime } from '../runtime.js';
7
+ import { useOptionalValue } from '../valueStore.js';
8
+ export function RegionRows() {
9
+ const runtime = useRuntime();
10
+ const regions = runtime.regions;
11
+ const selected = useOptionalValue(regions?.selected ?? null);
12
+ const hovered = useOptionalValue(regions?.hovered ?? null);
13
+ if (!regions || regions.config.length === 0)
14
+ return null;
15
+ return (_jsx("section", { className: "builder-region__rows", "aria-label": "Fixed parts of the page", children: regions.config.map((region) => (_jsxs("button", { type: "button", className: [
16
+ 'builder-editor__row',
17
+ 'builder-region__row',
18
+ selected === region.name && 'builder-editor__row--selected',
19
+ hovered === region.name && selected !== region.name && 'builder-editor__row--hovered',
20
+ ]
21
+ .filter(Boolean)
22
+ .join(' '), "aria-pressed": selected === region.name, "data-tooltip": "A fixed part of the page: its fields, not blocks", "data-tooltip-side": "right", onClick: () => regions.selected.set(region.name), onPointerEnter: () => regions.hovered.set(region.name), onPointerLeave: () => regions.hovered.set(null), children: [_jsx("span", { className: "builder-editor__row-icon", children: _jsx(Icon, { name: "lock", size: 14 }) }), _jsx("span", { className: "builder-editor__row-type", children: region.label }), _jsx("span", { className: "builder-editor__row-text", children: "Fixed" })] }, region.name))) }));
23
+ }
@@ -0,0 +1,73 @@
1
+ import type { BlockDefinition, RegionConfig, RegionField } from '../../../core/types.js';
2
+ import type { LiveFieldChange, LivePublishedEvent, LiveSavedEvent, RegionAccess } from '../../../live/types.js';
3
+ import type { FieldEdit, FieldWriteResult } from '../store.js';
4
+ import { type ValueStore } from '../valueStore.js';
5
+ export type RegionsState = {
6
+ /** The regions' values in the editor's locale (ids, not documents). Null until loaded. */
7
+ values: Record<string, unknown> | null;
8
+ /** Own locale values, without fallback, for exact undo. */
9
+ storedValues: Record<string, unknown> | null;
10
+ /** What the user may read and change. Null until loaded. */
11
+ access: RegionAccess | null;
12
+ status: 'loading' | 'ready' | 'error';
13
+ error: string | null;
14
+ };
15
+ /**
16
+ * One change. `base`: the value the change replaces, as the editor showed it when the edit began
17
+ * (an inline session keeps it from its start). Left out: the value before this queued save starts.
18
+ */
19
+ export type RegionWrite = {
20
+ path: string;
21
+ value: unknown;
22
+ base?: unknown;
23
+ };
24
+ export type RegionsController = {
25
+ config: readonly RegionConfig[];
26
+ state: ValueStore<RegionsState>;
27
+ /** The selected region. A selected block and a selected region exclude each other. */
28
+ selected: ValueStore<string | null>;
29
+ hovered: ValueStore<string | null>;
30
+ /** Loads the values and the access again. */
31
+ load(): Promise<void>;
32
+ /** Loads the values again and shows the page frame again (the settings drawer saved). */
33
+ reload(): void;
34
+ /**
35
+ * Saves field changes as the user (a draft with drafts), in `locale` (default: the locale the
36
+ * editor shows). Records one undo step with the values the server stored (after field hooks)
37
+ * unless `history: false`. Resolves false when the server refused (the editor says why).
38
+ */
39
+ write(changes: RegionWrite[], options?: {
40
+ history?: boolean;
41
+ locale?: string | null;
42
+ }): Promise<boolean>;
43
+ /** Saves changes for undo or redo in the step's `locale`: `base` is the value the step expects to find. */
44
+ writeEdits(changes: LiveFieldChange[], locale: string | null): Promise<FieldWriteResult>;
45
+ region(name: string | null): RegionConfig | null;
46
+ /** The region and its field that hold a document path. */
47
+ fieldOf(path: string): {
48
+ region: RegionConfig;
49
+ field: RegionField;
50
+ } | null;
51
+ /** The region's fields as a block definition (inline editing, the image editor). */
52
+ definition(name: string): BlockDefinition | null;
53
+ /** Why the user may not change this path now, or null. */
54
+ lockedMessage(path: string): string | null;
55
+ /** A `saved` or `published` event: other fields may have changed. */
56
+ handleEvent(event: LiveSavedEvent | LivePublishedEvent): void;
57
+ /** The canvas shows the page frame again. */
58
+ refreshFrame(): void;
59
+ };
60
+ export type RegionsContext = {
61
+ regions: readonly RegionConfig[];
62
+ /** `${liveEndpoint}/${collection}/${id}` */
63
+ endpoint: string;
64
+ locale: () => string | null;
65
+ /** The settings drawer is open: its form holds its own copy of the fields. */
66
+ settingsOpen: () => boolean;
67
+ /** Asks the canvas for the page frame again. */
68
+ refreshFrame: () => void;
69
+ /** Records one undo step of field changes, made in `locale`. */
70
+ record: (edits: FieldEdit[], locale: string | null, saved: Promise<FieldEdit[] | null>) => void;
71
+ warn: (text: string) => void;
72
+ };
73
+ export declare function createRegionsController(context: RegionsContext): RegionsController;