@conloca/cms-spa 0.2.1 → 0.2.3

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 (232) hide show
  1. package/README.md +26 -0
  2. package/dist/spa/main.css +240 -4
  3. package/dist/ts/.build-inputs.json +178 -0
  4. package/dist/ts/App.d.ts +10 -2
  5. package/dist/ts/App.d.ts.map +1 -1
  6. package/dist/ts/App.js +20 -8
  7. package/dist/ts/App.js.map +1 -1
  8. package/dist/ts/CmsSpaApp.d.ts.map +1 -1
  9. package/dist/ts/CmsSpaApp.js +4 -1
  10. package/dist/ts/CmsSpaApp.js.map +1 -1
  11. package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
  12. package/dist/ts/components/CMSDashboard.js +6 -2
  13. package/dist/ts/components/CMSDashboard.js.map +1 -1
  14. package/dist/ts/components/RouteErrorPage.d.ts +11 -0
  15. package/dist/ts/components/RouteErrorPage.d.ts.map +1 -0
  16. package/dist/ts/components/RouteErrorPage.js +44 -0
  17. package/dist/ts/components/RouteErrorPage.js.map +1 -0
  18. package/dist/ts/components/dashboard/RecentActivity.d.ts.map +1 -1
  19. package/dist/ts/components/dashboard/RecentActivity.js +2 -8
  20. package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
  21. package/dist/ts/components/dialogs/CreateDataDialog.js +2 -2
  22. package/dist/ts/components/dialogs/CreateDataDialog.js.map +1 -1
  23. package/dist/ts/components/dialogs/CreateFolderDialog.d.ts.map +1 -1
  24. package/dist/ts/components/dialogs/CreateFolderDialog.js +2 -1
  25. package/dist/ts/components/dialogs/CreateFolderDialog.js.map +1 -1
  26. package/dist/ts/components/dialogs/CreatePageFlow.d.ts +13 -0
  27. package/dist/ts/components/dialogs/CreatePageFlow.d.ts.map +1 -0
  28. package/dist/ts/components/dialogs/CreatePageFlow.js +100 -0
  29. package/dist/ts/components/dialogs/CreatePageFlow.js.map +1 -0
  30. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +1 -1
  31. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
  32. package/dist/ts/components/dialogs/DataPropertiesDialog.js +2 -2
  33. package/dist/ts/components/dialogs/DataPropertiesDialog.js.map +1 -1
  34. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +1 -1
  35. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
  36. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +2 -2
  37. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.map +1 -1
  38. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts +2 -12
  39. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
  40. package/dist/ts/components/dialogs/PageMetadataDialog.js +3 -21
  41. package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
  42. package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
  43. package/dist/ts/components/editor/CMSMDXEditor.js +46 -55
  44. package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
  45. package/dist/ts/components/editor/DrawerItemOverride.d.ts +2 -0
  46. package/dist/ts/components/editor/DrawerItemOverride.d.ts.map +1 -1
  47. package/dist/ts/components/editor/DrawerItemOverride.js +4 -3
  48. package/dist/ts/components/editor/DrawerItemOverride.js.map +1 -1
  49. package/dist/ts/components/editor/PageEditor.d.ts +6 -7
  50. package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
  51. package/dist/ts/components/editor/PageEditor.js +124 -34
  52. package/dist/ts/components/editor/PageEditor.js.map +1 -1
  53. package/dist/ts/components/editor/PageEditorHeaderActions.js +1 -1
  54. package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
  55. package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
  56. package/dist/ts/components/editor/PageEditorWrapper.js +48 -12
  57. package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
  58. package/dist/ts/components/editor/draft-media-config.d.ts +22 -0
  59. package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -0
  60. package/dist/ts/components/editor/draft-media-config.js +186 -0
  61. package/dist/ts/components/editor/draft-media-config.js.map +1 -0
  62. package/dist/ts/components/editor/preview-availability.d.ts +6 -5
  63. package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
  64. package/dist/ts/components/editor/preview-availability.js +6 -5
  65. package/dist/ts/components/editor/preview-availability.js.map +1 -1
  66. package/dist/ts/components/editors/DataEditor.d.ts +2 -2
  67. package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
  68. package/dist/ts/components/forms/HintForm.js +8 -5
  69. package/dist/ts/components/forms/HintForm.js.map +1 -1
  70. package/dist/ts/components/forms/SchemaForm.d.ts +17 -5
  71. package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
  72. package/dist/ts/components/forms/SchemaForm.js +16 -9
  73. package/dist/ts/components/forms/SchemaForm.js.map +1 -1
  74. package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
  75. package/dist/ts/components/media/AssetCard.js +3 -2
  76. package/dist/ts/components/media/AssetCard.js.map +1 -1
  77. package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
  78. package/dist/ts/components/media/AssetDetailSidebar.js +4 -2
  79. package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
  80. package/dist/ts/components/media/FolderTreeSidebar.d.ts.map +1 -1
  81. package/dist/ts/components/media/FolderTreeSidebar.js +4 -1
  82. package/dist/ts/components/media/FolderTreeSidebar.js.map +1 -1
  83. package/dist/ts/components/pages/PageList.d.ts.map +1 -1
  84. package/dist/ts/components/pages/PageList.js +13 -99
  85. package/dist/ts/components/pages/PageList.js.map +1 -1
  86. package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
  87. package/dist/ts/components/sandbox/ContentSandbox.js +36 -5
  88. package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
  89. package/dist/ts/content-form-fields.d.ts +41 -0
  90. package/dist/ts/content-form-fields.d.ts.map +1 -0
  91. package/dist/ts/content-form-fields.js +70 -0
  92. package/dist/ts/content-form-fields.js.map +1 -0
  93. package/dist/ts/content-wrapper.d.ts +65 -0
  94. package/dist/ts/content-wrapper.d.ts.map +1 -0
  95. package/dist/ts/content-wrapper.js +190 -0
  96. package/dist/ts/content-wrapper.js.map +1 -0
  97. package/dist/ts/data-schemas.d.ts +4 -3
  98. package/dist/ts/data-schemas.d.ts.map +1 -1
  99. package/dist/ts/data-schemas.js.map +1 -1
  100. package/dist/ts/frame/channel.d.ts +40 -0
  101. package/dist/ts/frame/channel.d.ts.map +1 -0
  102. package/dist/ts/frame/channel.js +233 -0
  103. package/dist/ts/frame/channel.js.map +1 -0
  104. package/dist/ts/frame/editor-frame.d.ts +23 -0
  105. package/dist/ts/frame/editor-frame.d.ts.map +1 -0
  106. package/dist/ts/frame/editor-frame.js +154 -0
  107. package/dist/ts/frame/editor-frame.js.map +1 -0
  108. package/dist/ts/frame/media-cache.d.ts +26 -0
  109. package/dist/ts/frame/media-cache.d.ts.map +1 -0
  110. package/dist/ts/frame/media-cache.js +123 -0
  111. package/dist/ts/frame/media-cache.js.map +1 -0
  112. package/dist/ts/frame/memory-router.d.ts +10 -0
  113. package/dist/ts/frame/memory-router.d.ts.map +1 -0
  114. package/dist/ts/frame/memory-router.js +39 -0
  115. package/dist/ts/frame/memory-router.js.map +1 -0
  116. package/dist/ts/frame/parent-hello.d.ts +11 -0
  117. package/dist/ts/frame/parent-hello.d.ts.map +1 -0
  118. package/dist/ts/frame/parent-hello.js +53 -0
  119. package/dist/ts/frame/parent-hello.js.map +1 -0
  120. package/dist/ts/frame/protocol.d.ts +201 -0
  121. package/dist/ts/frame/protocol.d.ts.map +1 -0
  122. package/dist/ts/frame/protocol.js +195 -0
  123. package/dist/ts/frame/protocol.js.map +1 -0
  124. package/dist/ts/frame/rpc-content-client.d.ts +10 -0
  125. package/dist/ts/frame/rpc-content-client.d.ts.map +1 -0
  126. package/dist/ts/frame/rpc-content-client.js +51 -0
  127. package/dist/ts/frame/rpc-content-client.js.map +1 -0
  128. package/dist/ts/frame/save-shortcut.d.ts +8 -0
  129. package/dist/ts/frame/save-shortcut.d.ts.map +1 -0
  130. package/dist/ts/frame/save-shortcut.js +26 -0
  131. package/dist/ts/frame/save-shortcut.js.map +1 -0
  132. package/dist/ts/host-schema.d.ts +73 -0
  133. package/dist/ts/host-schema.d.ts.map +1 -0
  134. package/dist/ts/host-schema.js +66 -0
  135. package/dist/ts/host-schema.js.map +1 -0
  136. package/dist/ts/host-style-probe.d.ts +32 -37
  137. package/dist/ts/host-style-probe.d.ts.map +1 -1
  138. package/dist/ts/host-style-probe.js +102 -68
  139. package/dist/ts/host-style-probe.js.map +1 -1
  140. package/dist/ts/index.d.ts +4 -2
  141. package/dist/ts/index.d.ts.map +1 -1
  142. package/dist/ts/index.js +6 -2
  143. package/dist/ts/index.js.map +1 -1
  144. package/dist/ts/main-spa.d.ts.map +1 -1
  145. package/dist/ts/main-spa.js +2 -1
  146. package/dist/ts/main-spa.js.map +1 -1
  147. package/dist/ts/page-schema-define.d.ts +14 -12
  148. package/dist/ts/page-schema-define.d.ts.map +1 -1
  149. package/dist/ts/page-schema-define.js +8 -5
  150. package/dist/ts/page-schema-define.js.map +1 -1
  151. package/dist/ts/prose-surface-css.d.ts +3 -5
  152. package/dist/ts/prose-surface-css.d.ts.map +1 -1
  153. package/dist/ts/prose-surface-css.js +3 -5
  154. package/dist/ts/prose-surface-css.js.map +1 -1
  155. package/dist/ts/site-styles.d.ts +4 -21
  156. package/dist/ts/site-styles.d.ts.map +1 -1
  157. package/dist/ts/site-styles.js.map +1 -1
  158. package/dist/ts/ui-config.d.ts +52 -1
  159. package/dist/ts/ui-config.d.ts.map +1 -1
  160. package/dist/ts/ui-config.js +4 -0
  161. package/dist/ts/ui-config.js.map +1 -1
  162. package/dist/ts/utils/asset-url.d.ts +2 -0
  163. package/dist/ts/utils/asset-url.d.ts.map +1 -1
  164. package/dist/ts/utils/asset-url.js +7 -0
  165. package/dist/ts/utils/asset-url.js.map +1 -1
  166. package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
  167. package/dist/ts/utils/pageMetadata.js +27 -10
  168. package/dist/ts/utils/pageMetadata.js.map +1 -1
  169. package/dist/ts/utils/schema-fields.d.ts +23 -0
  170. package/dist/ts/utils/schema-fields.d.ts.map +1 -0
  171. package/dist/ts/utils/schema-fields.js +82 -0
  172. package/dist/ts/utils/schema-fields.js.map +1 -0
  173. package/package.json +56 -18
  174. package/src/App.tsx +35 -14
  175. package/src/CmsSpaApp.tsx +5 -1
  176. package/src/components/CMSDashboard.tsx +12 -4
  177. package/src/components/RouteErrorPage.tsx +75 -0
  178. package/src/components/dashboard/RecentActivity.tsx +3 -7
  179. package/src/components/dialogs/CreateDataDialog.tsx +2 -2
  180. package/src/components/dialogs/CreateFolderDialog.tsx +2 -1
  181. package/src/components/dialogs/CreatePageFlow.tsx +117 -0
  182. package/src/components/dialogs/DataPropertiesDialog.tsx +3 -2
  183. package/src/components/dialogs/FragmentPropertiesDialog.tsx +3 -2
  184. package/src/components/dialogs/PageMetadataDialog.tsx +5 -28
  185. package/src/components/editor/CMSMDXEditor.tsx +49 -69
  186. package/src/components/editor/DrawerItemOverride.tsx +14 -8
  187. package/src/components/editor/PageEditor.tsx +135 -36
  188. package/src/components/editor/PageEditorHeaderActions.tsx +1 -1
  189. package/src/components/editor/PageEditorWrapper.tsx +51 -12
  190. package/src/components/editor/draft-media-config.ts +197 -0
  191. package/src/components/editor/preview-availability.ts +6 -5
  192. package/src/components/editors/DataEditor.tsx +2 -2
  193. package/src/components/forms/HintForm.tsx +7 -5
  194. package/src/components/forms/SchemaForm.tsx +41 -12
  195. package/src/components/media/AssetCard.tsx +10 -7
  196. package/src/components/media/AssetDetailSidebar.tsx +6 -6
  197. package/src/components/media/FolderTreeSidebar.tsx +3 -1
  198. package/src/components/pages/PageList.tsx +17 -119
  199. package/src/components/sandbox/ContentSandbox.tsx +34 -5
  200. package/src/content-form-fields.ts +79 -0
  201. package/src/content-wrapper.ts +284 -0
  202. package/src/data-schemas.ts +4 -3
  203. package/src/frame/channel.ts +258 -0
  204. package/src/frame/editor-frame.ts +180 -0
  205. package/src/frame/media-cache.ts +144 -0
  206. package/src/frame/memory-router.ts +39 -0
  207. package/src/frame/parent-hello.ts +62 -0
  208. package/src/frame/protocol.ts +323 -0
  209. package/src/frame/rpc-content-client.ts +58 -0
  210. package/src/frame/save-shortcut.ts +25 -0
  211. package/src/host-schema.ts +122 -0
  212. package/src/host-style-probe.ts +120 -90
  213. package/src/index.ts +7 -2
  214. package/src/main-spa.tsx +2 -0
  215. package/src/main.css +12 -8
  216. package/src/page-schema-define.ts +29 -17
  217. package/src/prose-surface-css.ts +3 -5
  218. package/src/site-styles.ts +4 -22
  219. package/src/ui-config.ts +54 -1
  220. package/src/utils/asset-url.ts +8 -0
  221. package/src/utils/pageMetadata.ts +27 -10
  222. package/src/utils/schema-fields.ts +106 -0
  223. package/dist/ts/host-discovery.d.ts +0 -40
  224. package/dist/ts/host-discovery.d.ts.map +0 -1
  225. package/dist/ts/host-discovery.js +0 -39
  226. package/dist/ts/host-discovery.js.map +0 -1
  227. package/dist/ts/utils/zodIntrospect.d.ts +0 -19
  228. package/dist/ts/utils/zodIntrospect.d.ts.map +0 -1
  229. package/dist/ts/utils/zodIntrospect.js +0 -95
  230. package/dist/ts/utils/zodIntrospect.js.map +0 -1
  231. package/src/host-discovery.ts +0 -77
  232. package/src/utils/zodIntrospect.ts +0 -136
@@ -1,8 +1,9 @@
1
1
  import type { DataContext, LocalizedEntry, UpdateResult } from '@conloca/content-api-client';
2
- import type { Config } from '@puckeditor/core';
2
+ import { type Config, createUsePuck } from '@puckeditor/core';
3
3
  import { Monitor, Smartphone, Tablet } from 'lucide-react';
4
4
  import React, { useCallback, useMemo, useRef, useState } from 'react';
5
5
  import { notifyEditorDirtyChanged, registerEditorFlushHandler } from '../../editor-flush.js';
6
+ import { useCanvasSaveShortcut } from '../../frame/save-shortcut.js';
6
7
  import { useSiteBaseUrl } from '../../hooks/index.js';
7
8
  import { useCanvasTheme } from '../../hooks/useCanvasTheme.js';
8
9
  import { useUnsavedChangesGuard } from '../../hooks/useUnsavedChangesGuard.js';
@@ -14,7 +15,8 @@ import { ConflictDialog } from '../dialogs/ConflictDialog.js';
14
15
  import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
15
16
  import { ImageFieldRender } from '../fields/ImageField.js';
16
17
  import { toast } from '../toast.js';
17
- import { DrawerItemOverride } from './DrawerItemOverride.js';
18
+ import { DrawerItemOverride, PUCK_ROOT_DROP_ZONE } from './DrawerItemOverride.js';
19
+ import { withDraftMediaRendering } from './draft-media-config.js';
18
20
  import { PageEditorHeaderActions } from './PageEditorHeaderActions.js';
19
21
  import { PuckWithUntouchedMetadata } from './PuckWithUntouchedMetadata.js';
20
22
  import {
@@ -44,6 +46,20 @@ const viewports = [
44
46
  { width: 1280, height: 'auto' as const, label: 'Desktop', icon: <Monitor size={16} /> },
45
47
  ];
46
48
 
49
+ /**
50
+ * The canvas options, a module constant on purpose. `<Puck>` re-runs its canvas viewport effect whenever `iframe`
51
+ * changes identity (https://github.com/puckeditor/puck/pull/1864, open against 0.23), and while the undo history
52
+ * still holds only its first entry that effect overwrites the entry with the page as it is by then. This editor
53
+ * re-renders on every edit, so an inline object would replace the loaded page in the history with the result of the
54
+ * first edit before Puck records that edit: Undo would then flip the history buttons and leave the edit on the canvas.
55
+ *
56
+ * The canvas shows the SITE, so it gets the site's stylesheets and nothing else. Puck's default mirrors this admin
57
+ * document's head into the iframe, which for a consumer whose editor and site are separate apps means the CMS
58
+ * chrome's own CSS lands on top of the page being edited — Tailwind's preflight there flattens headings the site
59
+ * styles by element rather than by utility class.
60
+ */
61
+ const CANVAS_IFRAME = { syncHostStyles: false };
62
+
47
63
  /**
48
64
  * Stable field type overrides for Puck.
49
65
  * Defined at module level to maintain referential stability across renders.
@@ -77,6 +93,29 @@ const drawerItemOverride = ({ children, name }: { children: React.ReactNode; nam
77
93
  <DrawerItemOverride name={name}>{children}</DrawerItemOverride>
78
94
  );
79
95
 
96
+ /** On the canvas's scaled-down view (about half size) this still reads at a normal text size. */
97
+ const EMPTY_PAGE_HINT_FONT_SIZE = '24px';
98
+
99
+ const EMPTY_PAGE_HINT = 'Drag a block here, or double-click one in the list';
100
+
101
+ const EMPTY_PAGE_HINT_DECLARATIONS = [
102
+ `content: ${JSON.stringify(EMPTY_PAGE_HINT)}`,
103
+ 'display: flex',
104
+ 'align-items: center',
105
+ 'justify-content: center',
106
+ 'box-sizing: border-box',
107
+ 'height: 100%',
108
+ 'min-height: inherit',
109
+ 'padding: 16px',
110
+ 'text-align: center',
111
+ 'font-family: var(--puck-font-family)',
112
+ `font-size: ${EMPTY_PAGE_HINT_FONT_SIZE}`,
113
+ 'color: var(--puck-color-grey-05)',
114
+ ].join('; ');
115
+
116
+ const CAN_INSERT_ATTRIBUTE = 'data-conloca-can-insert';
117
+ const CAN_INSERT_SELECTOR = `html[${CAN_INSERT_ATTRIBUTE}]`;
118
+
80
119
  /**
81
120
  * An editing rule the preview canvas gets from the CMS. The <Puck> below
82
121
  * opts out of Puck's host-style mirror, so main.css never reaches the canvas;
@@ -91,9 +130,27 @@ const drawerItemOverride = ({ children, name }: { children: React.ReactNode; nam
91
130
  * a child), keeps Puck's highlight. `[data-puck-dropzone]` is the attribute
92
131
  * Puck puts on every drop area; matching class names would also catch Puck's
93
132
  * drop-position line and hide it.
133
+ *
134
+ * A page with no blocks also says how to add one: the empty root area is the
135
+ * whole canvas, so a line of text centred in it is where an author looks first.
136
+ * It is the area's `::before`, so it goes as soon as the area holds a block or
137
+ * a drop preview, and it never becomes content that can be saved. It is sized
138
+ * for the canvas's scaled-down view, where it must stay readable. It shows in
139
+ * edit mode only (the interactive preview renders the published page) and only
140
+ * while the editor marks the canvas as one that can take a block, because both
141
+ * ways the hint names do nothing when no block may be inserted.
94
142
  */
95
- const EMPTY_DROP_AREA_CSS =
96
- '[data-puck-dropzone]:empty { --puck-slot-color-bg: transparent; --puck-slot-color-border: var(--puck-color-grey-07); }';
143
+ const EMPTY_DROP_AREA_CSS = [
144
+ '[data-puck-dropzone]:empty { --puck-slot-color-bg: transparent; --puck-slot-color-border: var(--puck-color-grey-07); }',
145
+ `${CAN_INSERT_SELECTOR} [data-puck-entry][data-puck-preview-mode="edit"] [data-puck-dropzone="${PUCK_ROOT_DROP_ZONE}"]:empty::before { ${EMPTY_PAGE_HINT_DECLARATIONS} }`,
146
+ ].join('\n');
147
+
148
+ const usePuck = createUsePuck();
149
+
150
+ /** Whether any block may be added to the page: the hint's two ways of adding one both need it. */
151
+ function usePageCanTakeAnInsert(): boolean {
152
+ return usePuck((state) => Object.keys(state.config.components).some((type) => state.getPermissions({ type }).insert));
153
+ }
97
154
 
98
155
  /**
99
156
  * Bridges CMS editor state into Puck's preview iframe.
@@ -108,12 +165,11 @@ const EMPTY_DROP_AREA_CSS =
108
165
  * rules (e.g. `body { color: var(...) }`) cannot cascade into Puck's
109
166
  * chrome — the iframe is the only intended consumer.
110
167
  *
111
- * The `<Puck>` below turns off Puck's host-style mirror
112
- * (`iframe={{ syncHostStyles: false }}`), so the iframe head holds only
113
- * Puck's own interaction CSS, the empty-drop-area rule (point 3), the
114
- * page-setting cursor rule (point 4) and these tags. Nothing else touches
115
- * them, so they are appended on every `siteStyles` change and removed on
116
- * cleanup.
168
+ * The `<Puck>` below turns off Puck's host-style mirror (`CANVAS_IFRAME`),
169
+ * so the iframe head holds only Puck's own interaction CSS, the
170
+ * empty-drop-area rule (point 3), the page-setting cursor rule (point 4)
171
+ * and these tags. Nothing else touches them, so they are appended on
172
+ * every `siteStyles` change and removed on cleanup.
117
173
  *
118
174
  * 3. Injects `EMPTY_DROP_AREA_CSS` once per iframe document.
119
175
  *
@@ -130,6 +186,7 @@ export function IframeBridge({ children, document: iframeDoc }: { children: Reac
130
186
  const { canvasTheme } = useCanvasTheme();
131
187
  const siteStyles = useSiteStyles();
132
188
  usePageSettingTargets(iframeDoc);
189
+ useCanvasSaveShortcut(iframeDoc);
133
190
 
134
191
  React.useEffect(() => {
135
192
  if (!iframeDoc?.documentElement) return;
@@ -188,6 +245,34 @@ export function IframeBridge({ children, document: iframeDoc }: { children: Reac
188
245
  return <>{children}</>;
189
246
  }
190
247
 
248
+ /**
249
+ * `IframeBridge` for the canvas inside <Puck>: also marks the canvas document while the page can take a block, which
250
+ * the empty-page hint in `EMPTY_DROP_AREA_CSS` waits for. Separate because the marker reads Puck's state, so it only
251
+ * works inside <Puck>, while the bridge also renders on its own.
252
+ */
253
+ function IframeWithInsertMarker({ children, document: iframeDoc }: { children: React.ReactNode; document?: Document }) {
254
+ const canTakeAnInsert = usePageCanTakeAnInsert();
255
+ React.useEffect(() => {
256
+ const html = iframeDoc?.documentElement;
257
+ if (!html) return undefined;
258
+ html.toggleAttribute(CAN_INSERT_ATTRIBUTE, canTakeAnInsert);
259
+ return () => html.removeAttribute(CAN_INSERT_ATTRIBUTE);
260
+ }, [iframeDoc, canTakeAnInsert]);
261
+
262
+ return <IframeBridge document={iframeDoc}>{children}</IframeBridge>;
263
+ }
264
+
265
+ /**
266
+ * A genuine preview failure, which is a DIFFERENT situation and must not read as though the site is misconfigured.
267
+ * Not latched: a transient fault must not disable a working button.
268
+ */
269
+ function reportPreviewFailure(error: unknown) {
270
+ toast.error('Could not open preview', {
271
+ description: 'Something went wrong creating the preview link. Please try again.',
272
+ });
273
+ console.error('[PageEditor] openPreview failed:', error);
274
+ }
275
+
191
276
  export function PageEditor({
192
277
  entry,
193
278
  config,
@@ -200,6 +285,11 @@ export function PageEditor({
200
285
  onReload,
201
286
  onPublish,
202
287
  }: PageEditorProps) {
288
+ const draftAssetsBasePath = getUIConfig().draftAssetsBasePath;
289
+ const renderConfig = useMemo(
290
+ () => withDraftMediaRendering(config, draftAssetsBasePath),
291
+ [config, draftAssetsBasePath],
292
+ );
203
293
  const [data, setData] = useState(entry.localized.content.puckData);
204
294
  const [saveState, setSaveState] = useState<SaveState>('idle');
205
295
  const [isDirty, setIsDirty] = useState(false);
@@ -327,7 +417,7 @@ export function PageEditor({
327
417
 
328
418
  const handlePreview = useCallback(() => {
329
419
  const pathname = entry.localized.pathname || '/';
330
- const openPreview = getUIConfig().openPreview;
420
+ const { openPreview, openSiteUrl, previewTab: previewTabOwner } = getUIConfig();
331
421
  if (openPreview) {
332
422
  // Already known to be impossible: explain it without flashing a blank
333
423
  // tab open and shut, which reads as a bug even when it is correct.
@@ -335,6 +425,26 @@ export function PageEditor({
335
425
  toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: previewBlockedReason, duration: 10_000 });
336
426
  return;
337
427
  }
428
+ // The site does not serve draft preview, so no URL exists that could
429
+ // work. Say so where the user is looking instead of navigating a tab to
430
+ // a 404 on their own domain, and remember it so the control goes
431
+ // disabled rather than staying a trap.
432
+ const markPreviewUnavailable = (message: string) => {
433
+ const detail = message !== '' ? message : PREVIEW_UNAVAILABLE_DETAIL;
434
+ setPreviewBlockedReason(detail);
435
+ setPreviewCapability('unavailable');
436
+ toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: detail, duration: 10_000 });
437
+ };
438
+ // The parent frame opens the tab during the click itself; a blocked
439
+ // popup is the parent's to explain, so the editor shows nothing for it.
440
+ if (previewTabOwner === 'parent') {
441
+ void openPreview({ path: pathname })
442
+ .then((result) => {
443
+ if (!result.ok && result.reason === 'not-deployed') markPreviewUnavailable(result.message);
444
+ })
445
+ .catch(reportPreviewFailure);
446
+ return;
447
+ }
338
448
  // Popup blockers only allow window creation during the click itself.
339
449
  // `openPreview` answers asynchronously, so reserve a blank tab now and
340
450
  // navigate it once the preview URL arrives.
@@ -347,31 +457,26 @@ export function PageEditor({
347
457
  void openPreview({ path: pathname })
348
458
  .then((result) => {
349
459
  if (result.ok) {
350
- previewTab.location.href = result.url;
460
+ if ('url' in result) previewTab.location.href = result.url;
461
+ else previewTab.close();
351
462
  return;
352
463
  }
353
- // The site does not serve draft preview, so no URL exists that could
354
- // work. Say so where the user is looking instead of navigating the
355
- // tab to a 404 on their own domain, and remember it so the control
356
- // goes disabled rather than staying a trap.
357
464
  previewTab.close();
358
- const detail = result.message !== '' ? result.message : PREVIEW_UNAVAILABLE_DETAIL;
359
- setPreviewBlockedReason(detail);
360
- setPreviewCapability('unavailable');
361
- toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: detail, duration: 10_000 });
465
+ // `popup-blocked` cannot happen here, the editor holds the tab.
466
+ if (result.reason === 'not-deployed') markPreviewUnavailable(result.message);
362
467
  })
363
468
  .catch((error: unknown) => {
364
- // A genuine failure, which is a DIFFERENT situation and must not
365
- // read as though the site is misconfigured. Not latched:
366
- // a transient fault must not disable a working button.
367
469
  previewTab.close();
368
- toast.error('Could not open preview', {
369
- description: 'Something went wrong creating the preview link. Please try again.',
370
- });
371
- console.error('[PageEditor] openPreview failed:', error);
470
+ reportPreviewFailure(error);
372
471
  });
373
472
  return;
374
473
  }
474
+ if (openSiteUrl) {
475
+ void openSiteUrl({ path: pathname }).catch((error: unknown) =>
476
+ console.error('[PageEditor] openSiteUrl failed:', error),
477
+ );
478
+ return;
479
+ }
375
480
  const previewUrl = buildUrl(pathname);
376
481
  const cacheBustedUrl = `${previewUrl}${previewUrl.includes('?') ? '&' : '?'}_t=${Date.now()}`;
377
482
  window.open(cacheBustedUrl, '_blank');
@@ -436,7 +541,7 @@ export function PageEditor({
436
541
  },
437
542
  drawerItem: drawerItemOverride,
438
543
  fields: FieldsWithPageSettingsHint,
439
- iframe: IframeBridge,
544
+ iframe: IframeWithInsertMarker,
440
545
  }),
441
546
  [],
442
547
  );
@@ -465,20 +570,14 @@ export function PageEditor({
465
570
  <PageSettingTargetsProvider onOpen={onOpenMetadata}>
466
571
  {/* Not <Puck> itself: on the canvas Puck rewrites the page data it hands blocks; see PuckWithUntouchedMetadata.tsx. */}
467
572
  <PuckWithUntouchedMetadata
468
- config={config}
573
+ config={renderConfig}
469
574
  data={data}
470
575
  metadata={metadata}
471
576
  onChange={handleDataChange}
472
577
  headerTitle={entry.localized.meta.title || 'Untitled Page'}
473
578
  viewports={viewports}
474
579
  overrides={overrides}
475
- // The canvas shows the SITE, so it gets the site's stylesheets and
476
- // nothing else. Puck's default mirrors this admin document's head
477
- // into the iframe, which for a consumer whose editor and site are
478
- // separate apps means the CMS chrome's own CSS lands on top of the
479
- // page being edited — Tailwind's preflight there flattens headings
480
- // the site styles by element rather than by utility class.
481
- iframe={{ syncHostStyles: false }}
580
+ iframe={CANVAS_IFRAME}
482
581
  />
483
582
  </PageSettingTargetsProvider>
484
583
  </div>
@@ -109,7 +109,7 @@ export function PageEditorHeaderActions({
109
109
  onClick={onSave}
110
110
  disabled={!isDirty && saveState !== 'error' && saveState !== 'conflict'}
111
111
  className={cn(
112
- 'w-[100px] px-4 py-2 rounded-md text-sm transition-all duration-150 flex items-center justify-center gap-1 whitespace-nowrap font-medium',
112
+ 'w-[100px] px-4 py-2 rounded-md text-sm transition-all duration-150 flex items-center justify-center gap-1 whitespace-nowrap font-medium disabled:cursor-not-allowed',
113
113
  saveState === 'saved' && 'bg-green-10 text-green-06 cursor-pointer',
114
114
  saveState === 'error' && 'bg-red-10 text-red-06 hover:bg-red-09 cursor-pointer',
115
115
  saveState === 'conflict' && 'bg-yellow-10 text-yellow-06 hover:bg-yellow-09 cursor-pointer',
@@ -259,20 +259,30 @@ export function PageEditorWrapper({ puckConfig }: PageEditorWrapperProps) {
259
259
  return <MdxPageEditor />;
260
260
  }
261
261
 
262
- return <PuckPageEditorInner puckConfig={puckConfig} />;
262
+ // Keyed by page: the route element survives navigation between pages, and
263
+ // the locale state must restart from the newly opened page's locales.
264
+ return <PuckPageEditorInner key={id} puckConfig={puckConfig} initialLocale={initialPageLocale(content.locales)} />;
263
265
  }
264
266
 
265
- function PuckPageEditorInner({ puckConfig }: PageEditorWrapperProps) {
267
+ /**
268
+ * The locale the editor opens a page in: English when the page has it, as
269
+ * before, otherwise a locale the page actually has — opening on a locale with
270
+ * no variant fails the load with no way to reach the switcher.
271
+ */
272
+ function initialPageLocale(locales: Record<string, unknown>): string {
273
+ if (locales.en) return 'en';
274
+ return Object.keys(locales).find((locale) => locales[locale]) ?? 'en';
275
+ }
276
+
277
+ function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperProps & { initialLocale: string }) {
266
278
  const { id } = useParams();
267
279
  const navigate = useNavigate();
268
280
  const updateContent = useUpdateLocalized();
269
281
 
270
282
  // Mirrors FragmentEditor / MdxPageEditor: derive the locale list from the
271
- // host's sites config and let the editor switch between them. Initial
272
- // value is `'en'` for parity with the sibling editors; on a site whose
273
- // globalLocales don't include 'en', the user picks an available locale
274
- // from the switcher PageEditor renders when availableLocales.length > 1.
275
- const [currentLocale, setCurrentLocale] = useState<string>('en');
283
+ // host's sites config and let the editor switch between them. It opens on
284
+ // a locale the page has (see initialPageLocale).
285
+ const [currentLocale, setCurrentLocale] = useState<string>(initialLocale);
276
286
  const { data: sitesConfig } = useSitesConfig();
277
287
  const availableLocales = sitesConfig?.globalLocales || ['en'];
278
288
 
@@ -320,9 +330,28 @@ function PuckPageEditorInner({ puckConfig }: PageEditorWrapperProps) {
320
330
  const puckData = content?.localized?.content?.puckData;
321
331
 
322
332
  // Resolving again replaces the editor, unsaved block edits included, so it
323
- // runs when the blocks or the data their route binds change, and reads the
324
- // page when it runs: a Page settings save changes only the page, which the
325
- // canvas takes from `metadata` without remounting.
333
+ // runs when the blocks change other than by the editor's own save, or the
334
+ // data their route binds changes, and reads the page when it runs: a Page
335
+ // settings save changes only the page, which the canvas takes from
336
+ // `metadata` without remounting.
337
+ //
338
+ // The editor's own save puts the page it read back into the cache, but the
339
+ // editor already holds that page, and anything typed while the save was
340
+ // out, which a new editor would drop. So a change to the blocks counts only
341
+ // when it is not that page: another etag, or another locale than the one the
342
+ // editor holds.
343
+ const ownSaveRef = useRef<{ locale: string; etag: string } | null>(null);
344
+ const blocksRef = useRef({ puckData, locale: currentLocale, changes: 0 });
345
+ if (puckData !== blocksRef.current.puckData) {
346
+ const own = ownSaveRef.current;
347
+ const ownSave =
348
+ own !== null &&
349
+ own.locale === currentLocale &&
350
+ blocksRef.current.locale === currentLocale &&
351
+ own.etag === content?.localized?.etag;
352
+ blocksRef.current = { puckData, locale: currentLocale, changes: blocksRef.current.changes + (ownSave ? 0 : 1) };
353
+ }
354
+ const blockChanges = blocksRef.current.changes;
326
355
  const dataContextRef = useRef(dataContext);
327
356
  dataContextRef.current = dataContext;
328
357
  const routeCollections = dataContext?.collections;
@@ -331,7 +360,7 @@ function PuckPageEditorInner({ puckConfig }: PageEditorWrapperProps) {
331
360
  // Pre-resolve component data using resolveAllData.
332
361
  // This runs each component's resolveData with the data context as its
333
362
  // metadata, ensuring data-bound components have their data BEFORE Puck mounts.
334
- // biome-ignore lint/correctness/useExhaustiveDependencies: the route's bound data is the event; the page is read through the ref.
363
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the blocks' changes and the route's bound data are the events; the page and its data context are read when it runs.
335
364
  useEffect(() => {
336
365
  let cancelled = false;
337
366
 
@@ -365,7 +394,7 @@ function PuckPageEditorInner({ puckConfig }: PageEditorWrapperProps) {
365
394
  return () => {
366
395
  cancelled = true;
367
396
  };
368
- }, [puckData, enhancedConfig, routeCollections, routePages]);
397
+ }, [blockChanges, enhancedConfig, routeCollections, routePages]);
369
398
 
370
399
  const pageMetadata = useMemo(() => (content?.localized ? extractPageMetadata(content) : null), [content]);
371
400
 
@@ -429,6 +458,16 @@ function PuckPageEditorInner({ puckConfig }: PageEditorWrapperProps) {
429
458
  if (result.success && result.etag) {
430
459
  setCurrentEtag(result.etag);
431
460
  }
461
+ // Recorded before this component renders the page the save read back: the cache tells its readers
462
+ // on a later task, and `mutateAsync` settles first. Only a read-back of exactly this write is the
463
+ // editor's own; one someone else saved since must open, or the next save would write over it.
464
+ if (
465
+ 'updatedContent' in result &&
466
+ result.updatedContent &&
467
+ result.updatedContent.localized.etag === result.etag
468
+ ) {
469
+ ownSaveRef.current = { locale: currentLocale, etag: result.updatedContent.localized.etag };
470
+ }
432
471
 
433
472
  return result;
434
473
  } catch (error) {
@@ -0,0 +1,197 @@
1
+ /** Resolve unpublished draft images for site renderers without changing Puck's persisted data. */
2
+ /* oxlint-disable anti-slop/no-unsafe-dictionary-type, anti-slop/no-unknown-returns -- block props are whatever the site's components take; this walk only swaps image strings and passes every other value through as it came. */
3
+ import { IMAGE_EXTENSION_MIME } from '@conloca/content-api-client';
4
+ import type { Config, Field, Fields } from '@puckeditor/core';
5
+ import { type ComponentType, createElement, isValidElement } from 'react';
6
+ import { loadedMedia, mediaObjectUrl, useMediaCacheVersion } from '../../frame/media-cache.js';
7
+ import { getUIConfig } from '../../ui-config.js';
8
+ import { appendAssetUrlPath } from '../../utils/asset-url.js';
9
+
10
+ /** What a validated draft image path renders as; `undefined` keeps the canonical value. */
11
+ type DraftImageResolver = (path: string) => string | undefined;
12
+
13
+ /** The raw media path of a canonical `/assets/<path>` image reference, or `undefined` when it is not a safe image path. */
14
+ function draftImagePath(value: string): string | undefined {
15
+ if (!value.startsWith('/assets/')) return undefined;
16
+ const path = value.slice('/assets/'.length);
17
+ if (/[\\?#]/.test(path)) return undefined;
18
+ const segments = path.split('/');
19
+ for (const part of segments) {
20
+ if (
21
+ part === '' ||
22
+ part === '.' ||
23
+ part === '..' ||
24
+ [...part].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)
25
+ ) {
26
+ return undefined;
27
+ }
28
+ }
29
+ const filename = segments[segments.length - 1] ?? '';
30
+ const dot = filename.lastIndexOf('.');
31
+ if (dot <= 0) return undefined;
32
+ const extension = filename.slice(dot + 1).toLowerCase();
33
+ if (!Object.prototype.hasOwnProperty.call(IMAGE_EXTENSION_MIME, extension)) return undefined;
34
+ return path;
35
+ }
36
+
37
+ function draftImageUrl(path: string, base: string): string {
38
+ const encoded = path
39
+ .split('/')
40
+ .map((part) =>
41
+ encodeURIComponent(part).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`),
42
+ );
43
+ return appendAssetUrlPath(base, encoded.join('/'));
44
+ }
45
+
46
+ /**
47
+ * What the MDX editor canvas shows for an image `src`: the loaded bytes of a draft image, else `src` itself.
48
+ * The URL is the media cache's own, which a media write or eviction revokes; mdxeditor resolves an image again only
49
+ * when its `src` changes or it remounts, so a mounted image keeps painting its decoded bytes from a revoked URL.
50
+ */
51
+ export async function draftImagePreview(src: string): Promise<string> {
52
+ const path = draftImagePath(src);
53
+ return (path === undefined ? undefined : (await loadedMedia('draft', path))?.url) ?? src;
54
+ }
55
+
56
+ function dataUrl(blob: Blob): Promise<string> {
57
+ // The package's lib target predates Promise.withResolvers.
58
+ return new Promise((resolve, reject) => {
59
+ const reader = new FileReader();
60
+ reader.addEventListener('load', () => {
61
+ if (typeof reader.result === 'string') resolve(reader.result);
62
+ else reject(new Error('The image could not be read as a data URL.'));
63
+ });
64
+ reader.addEventListener('error', () => {
65
+ reject(reader.error ?? new Error('The image could not be read.'));
66
+ });
67
+ reader.readAsDataURL(blob);
68
+ });
69
+ }
70
+
71
+ // Keyed by the cached Blob, so a cleared or evicted cache entry frees its string too.
72
+ const dataUrls = new WeakMap<Blob, Promise<string>>();
73
+
74
+ async function draftImageDataUrl(src: string): Promise<string | undefined> {
75
+ const path = draftImagePath(src);
76
+ const media = path === undefined ? undefined : await loadedMedia('draft', path);
77
+ if (!media) return undefined;
78
+ let url = dataUrls.get(media.blob);
79
+ if (!url) {
80
+ url = dataUrl(media.blob);
81
+ dataUrls.set(media.blob, url);
82
+ }
83
+ return url;
84
+ }
85
+
86
+ /** How long a preview update waits for its draft images before it goes without the ones still loading. */
87
+ export const DRAFT_IMAGE_WAIT_MS = 5000;
88
+
89
+ /**
90
+ * Data URLs of the draft images a compiled MDX body names, keyed by their canonical `src`, for the
91
+ * opaque-origin preview frame, which cannot read this page's blob URLs. Images that fail to load, or are
92
+ * still loading after `DRAFT_IMAGE_WAIT_MS`, are left out.
93
+ */
94
+ export async function draftImageData(code: string): Promise<Record<string, string>> {
95
+ // shortcut: finds srcs only as plain double-quoted literals, the form the MDX compiler emits for these paths; widen if an escaped path must preview.
96
+ const srcs = new Set(code.match(/"\/assets\/[^"\\]*"/g)?.map((literal) => literal.slice(1, -1)));
97
+ const images: Record<string, string> = {};
98
+ let timer: number | undefined;
99
+ const expired = new Promise<undefined>((resolve) => {
100
+ timer = window.setTimeout(resolve, DRAFT_IMAGE_WAIT_MS, undefined);
101
+ });
102
+ await Promise.all(
103
+ [...srcs].map(async (src) => {
104
+ const url = await Promise.race([draftImageDataUrl(src).catch(() => undefined), expired]);
105
+ if (url !== undefined) images[src] = url;
106
+ }),
107
+ );
108
+ window.clearTimeout(timer);
109
+ return images;
110
+ }
111
+
112
+ function isRecord(value: unknown): value is Record<string, unknown> {
113
+ if (value === null || typeof value !== 'object' || isValidElement(value)) return false;
114
+ const prototype: unknown = Object.getPrototypeOf(value);
115
+ return prototype === Object.prototype || prototype === null;
116
+ }
117
+
118
+ function fieldValue(value: unknown, field: Field, resolve: DraftImageResolver): unknown {
119
+ if (field.type === 'slot') return value;
120
+ if (typeof value === 'string') {
121
+ const path = draftImagePath(value);
122
+ return path === undefined ? value : (resolve(path) ?? value);
123
+ }
124
+ if (field.type === 'object' && isRecord(value)) return fieldProps(value, field.objectFields, resolve);
125
+ if (field.type === 'array' && Array.isArray(value)) {
126
+ const next = value.map((item: unknown) => (isRecord(item) ? fieldProps(item, field.arrayFields, resolve) : item));
127
+ return next.some((item, index) => item !== value[index]) ? next : value;
128
+ }
129
+ return value;
130
+ }
131
+
132
+ function fieldProps(
133
+ props: Record<string, unknown>,
134
+ fields: Fields | undefined,
135
+ resolve: DraftImageResolver,
136
+ ): Record<string, unknown> {
137
+ let next = props;
138
+ for (const [name, field] of Object.entries(fields ?? {})) {
139
+ if (name === 'puck' || name === 'children' || name === 'editMode') continue;
140
+ if (field === undefined || !Object.prototype.hasOwnProperty.call(props, name)) continue;
141
+ const value = fieldValue(props[name], field, resolve);
142
+ if (value === props[name]) continue;
143
+ if (next === props) next = { ...props };
144
+ next[name] = value;
145
+ }
146
+ return next;
147
+ }
148
+
149
+ /**
150
+ * Static declared fields bound traversal; dynamic field resolvers and runtime contexts remain untouched.
151
+ * With `UIConfig.loadMedia` set, `base` is ignored: draft images show object URLs of the loaded bytes,
152
+ * the canonical value until they arrive.
153
+ */
154
+ export function withDraftMediaRendering(config: Config, base: string | undefined): Config {
155
+ const resolve: DraftImageResolver | undefined = getUIConfig().loadMedia
156
+ ? (path) => mediaObjectUrl('draft', path)
157
+ : base === undefined
158
+ ? undefined
159
+ : (path) => draftImageUrl(path, base);
160
+ if (resolve === undefined) return config;
161
+ const root = config.root;
162
+ const rootRender = root?.render;
163
+ return {
164
+ ...config,
165
+ ...(root && rootRender
166
+ ? {
167
+ root: {
168
+ ...root,
169
+ // Rendered as an element so memo/forwardRef roots keep working. Root props are a
170
+ // children/no-children union, so name the component's own prop type for createElement.
171
+ render: (props: Parameters<typeof rootRender>[0]) => {
172
+ // Re-render when a loaded image arrives.
173
+ useMediaCacheVersion();
174
+ // SAFETY: `props` is typed from `rootRender` itself; the cast only picks one member of Puck's root union.
175
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see the SAFETY note.
176
+ return createElement(rootRender as ComponentType<typeof props>, {
177
+ ...props,
178
+ ...fieldProps(props, root.fields, resolve),
179
+ });
180
+ },
181
+ },
182
+ }
183
+ : {}),
184
+ components: Object.fromEntries(
185
+ Object.entries(config.components).map(([name, component]) => [
186
+ name,
187
+ {
188
+ ...component,
189
+ render: (props: Parameters<typeof component.render>[0]) => {
190
+ useMediaCacheVersion();
191
+ return createElement(component.render, { ...props, ...fieldProps(props, component.fields, resolve) });
192
+ },
193
+ },
194
+ ]),
195
+ ),
196
+ };
197
+ }
@@ -8,13 +8,14 @@
8
8
  * `@lexical`.
9
9
  */
10
10
 
11
- /** Toast heading when the site cannot show a preview. */
12
- export const PREVIEW_UNAVAILABLE_TITLE = 'Preview is not available for this site';
11
+ /** Toast heading when the branch cannot show a preview. */
12
+ export const PREVIEW_UNAVAILABLE_TITLE = 'Preview is not available for this branch';
13
13
 
14
14
  /**
15
15
  * The explanation, used both as the toast body and as the disabled control's
16
- * reason. States the fact about the site, reassures that nothing they
17
- * did is broken, and never implies user error.
16
+ * reason. Preview support is checked per branch (one origin can serve one
17
+ * branch's drafts and not another's), so it names the branch, never the whole
18
+ * site; it reassures that nothing they did is broken.
18
19
  */
19
20
  export const PREVIEW_UNAVAILABLE_DETAIL =
20
- 'This site does not serve draft previews, so there is no preview page to open. Your draft is still saved, and publishing and the live site are unaffected.';
21
+ 'This branch has no preview server, so there is no preview page to open. Your draft is still saved, and publishing and the live site are unaffected.';
@@ -1,7 +1,7 @@
1
1
  import { getContentAPIClient, useLocalizedContent, useUpdateLocalized } from '@conloca/content-api-client';
2
2
  import { AlertCircle, Code2, Loader2, Save } from 'lucide-react';
3
3
  import { useEffect, useRef, useState } from 'react';
4
- import type { z } from 'zod';
4
+ import type { HostSchema } from '../../host-schema.js';
5
5
  import { contentFailureMessage } from '../../utils/content-failure.js';
6
6
  import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
7
7
  import { LocaleSelector } from '../editor/LocaleSelector.js';
@@ -12,7 +12,7 @@ interface DataEditorProps {
12
12
  collection: string;
13
13
  initialLocale: string;
14
14
  existingLocales: string[];
15
- schema: z.ZodObject<z.ZodRawShape> | null;
15
+ schema: HostSchema | null;
16
16
  onSave?: () => void;
17
17
  onCancel?: () => void;
18
18
  }
@@ -138,7 +138,9 @@ function HintField({ name, hint, value, onChange }: HintFieldProps) {
138
138
  id={inputId}
139
139
  type="datetime-local"
140
140
  value={formatDateValue(value)}
141
- onChange={(e) => onChange(e.target.value || undefined)}
141
+ // The picker's digits carry no zone or seconds; a host's `Format<'date-time'>`
142
+ // validator needs a full timestamp, so they are saved as the UTC instant they mean.
143
+ onChange={(e) => onChange(e.target.value ? `${e.target.value}:00.000Z` : undefined)}
142
144
  />
143
145
  </Wrapper>
144
146
  );
@@ -417,10 +419,10 @@ function formatLabel(name: string): string {
417
419
  }
418
420
 
419
421
  /**
420
- * Host date hints store the picker's zone-less digits, which readers take as
421
- * UTC. Slicing UTC hours off a Date or ISO string keeps the picker on that
422
- * convention; local hours would shift the stored day across midnight for
423
- * authors west of UTC.
422
+ * Host date hints save the picker's digits as a UTC instant, and older pages
423
+ * may hold the bare zone-less digits, which readers also take as UTC. Slicing
424
+ * UTC hours off a Date or ISO string keeps the picker on that convention; local
425
+ * hours would shift the stored day across midnight for authors west of UTC.
424
426
  */
425
427
  function formatDateValue(value: unknown): string {
426
428
  if (!value) return '';