@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,4 +1,7 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
+ import { type DiscoveredWrappers, findContentWrapper } from './content-wrapper.js';
3
+ import { buildSiteUrl } from './lib/utils.js';
4
+ import type { SiteStyles } from './site-styles.js';
2
5
 
3
6
  /**
4
7
  * Host-style probe — captures the host's computed styles for prose
@@ -161,6 +164,68 @@ export function findWrapperByClass(doc: Document, className: string | null): HTM
161
164
  return (found as HTMLElement) ?? fallback();
162
165
  }
163
166
 
167
+ /** What one load of the real page yields. */
168
+ export interface HostProbe {
169
+ /** The measured prose rules, unlayered; empty when nothing was probable. */
170
+ css: string;
171
+ /** The page's own stylesheets as one text: what the dev styles endpoint answers for its route. */
172
+ styles: SiteStyles;
173
+ /** The page's content and code-block wrappers, by the dev wrapper endpoint's rule. */
174
+ wrappers: DiscoveredWrappers;
175
+ }
176
+
177
+ const EMPTY_PROBE: HostProbe = { css: '', styles: [], wrappers: { content: null, codeBlock: null } };
178
+
179
+ /**
180
+ * Read a loaded page. An editor in a parent frame has no dev endpoints, so
181
+ * with `discover` this is where it gets the route CSS and wrappers they give a
182
+ * local editor, and with no `wrapperClass` from the caller the samples go
183
+ * inside the wrapper the page's own markup names. Without `discover` only the
184
+ * measured rules are read. Exported for tests.
185
+ */
186
+ export function readProbedPage(doc: Document, wrapperClass: string | null, discover: boolean): HostProbe {
187
+ if (!discover) return { ...EMPTY_PROBE, css: buildProbeStylesheet(doc, wrapperClass) };
188
+ // Read before measuring: the samples are added under the wrapper.
189
+ const wrappers = findContentWrapper(doc.documentElement.outerHTML);
190
+ return {
191
+ css: buildProbeStylesheet(doc, wrapperClass ?? wrappers.content?.className ?? null),
192
+ styles: pageStyles(doc),
193
+ wrappers,
194
+ };
195
+ }
196
+
197
+ /**
198
+ * `next`, with `prev`'s styles and wrappers wherever their content is the same,
199
+ * so a re-probe of an unchanged page (a theme toggle) changes no identity the
200
+ * editor's injected sheet and plugins depend on. Exported for tests.
201
+ */
202
+ export function keepUnchanged(prev: HostProbe, next: HostProbe): HostProbe {
203
+ const sameStyles =
204
+ prev.styles.length === next.styles.length && prev.styles.every((text, index) => text === next.styles[index]);
205
+ return {
206
+ css: next.css,
207
+ styles: sameStyles ? prev.styles : next.styles,
208
+ wrappers: JSON.stringify(prev.wrappers) === JSON.stringify(next.wrappers) ? prev.wrappers : next.wrappers,
209
+ };
210
+ }
211
+
212
+ /** The page's stylesheets in document order, each under its own media. Another origin's sheet is unreadable and left out. */
213
+ function pageStyles(doc: Document): SiteStyles {
214
+ const sheets: string[] = [];
215
+ for (const sheet of Array.from(doc.styleSheets)) {
216
+ let rules: string;
217
+ try {
218
+ rules = Array.from(sheet.cssRules, (rule) => rule.cssText).join('\n');
219
+ } catch {
220
+ continue;
221
+ }
222
+ const media = sheet.media.mediaText;
223
+ sheets.push(media && media !== 'all' ? `@media ${media} {\n${rules}\n}` : rules);
224
+ }
225
+ const css = sheets.join('\n');
226
+ return css ? [css] : [];
227
+ }
228
+
164
229
  /**
165
230
  * Read computed styles for each PROBE_TAG inside a freshly loaded
166
231
  * iframe's document. Returns one CSS rule string per tag, scoped to
@@ -406,15 +471,31 @@ function makeProbeEl(doc: Document, tag: string): HTMLElement {
406
471
  * numbers. Filtered out for any tag other than ul/ol. */
407
472
  const LIST_STYLE_PROPS = new Set(['list-style-type', 'list-style-position']);
408
473
 
474
+ /** The properties `@conloca/mdx`'s L0 heading scale sets on `h1`..`h6`.
475
+ * Its `:where(.conloca-prose--editor) hN` rules are unlayered at (0,0,1),
476
+ * the same specificity as the rules emitted here, so the stylesheet that
477
+ * comes last in `<head>` would win the tie — and nothing orders the probe's
478
+ * `<style>` against a bundled or lazily loaded editor sheet. The probe
479
+ * therefore also publishes these values as `--conloca-host-hN-<prop>` on the
480
+ * heading itself, and the L0 rules read them through `var()`: whichever rule
481
+ * wins, the heading resolves to the host's value. */
482
+ const HEADING_SCALE_PROPS: Partial<Record<(typeof PROBE_PROPS)[number], true>> = {
483
+ 'font-size': true,
484
+ 'font-weight': true,
485
+ 'line-height': true,
486
+ };
487
+
409
488
  function generateRule(view: Window, sample: HTMLElement, tag: string): string {
410
489
  const cs = view.getComputedStyle(sample);
411
490
  const decls: string[] = [];
412
491
  const isListContainer = tag === 'ul' || tag === 'ol';
492
+ const isHeading = /^h[1-6]$/.test(tag);
413
493
  for (const prop of PROBE_PROPS) {
414
494
  if (LIST_STYLE_PROPS.has(prop) && !isListContainer) continue;
415
495
  const value = cs.getPropertyValue(prop);
416
496
  if (value && value !== 'normal' && value !== 'none') {
417
497
  decls.push(`${prop}: ${value}`);
498
+ if (isHeading && HEADING_SCALE_PROPS[prop]) decls.push(`--conloca-host-${tag}-${prop}: ${value}`);
418
499
  }
419
500
  }
420
501
  if (decls.length === 0) return '';
@@ -447,59 +528,24 @@ function probeInlineTag(view: Window, parent: HTMLElement, tag: string): string
447
528
  }
448
529
 
449
530
  /**
450
- * Where the probe reads from. Two delivery routes, ONE mechanism:
451
- *
452
- * - `{ url }` — the site's real rendered page, for when the editor and the
453
- * site share an origin, so `contentDocument` is readable.
454
- * - `{ srcdoc }` — a same-origin reconstruction assembled from what the host
455
- * set with `setHostDiscovery` (its `routeCss` plus the discovered wrapper
456
- * class). For a site on a DIFFERENT origin, where no header on either side
457
- * can make its document readable: the same-origin
458
- * policy is not a permission, it is the boundary. An `srcdoc` frame
459
- * inherits the parent's origin, so the probe runs against it normally, and
460
- * a CSP of `frame-src 'self'` already covers `srcdoc`.
461
- *
462
- * A reconstruction sees the stylesheet but not the markup, so it cannot
463
- * observe utility-class or inline-style typography on real elements — the very
464
- * thing the probe exists for on utility-first hosts.
465
- */
466
- export type ProbeSource = { url: string } | { srcdoc: string };
467
-
468
- /**
469
- * Build the reconstruction document for `{ srcdoc }` probing: the host's route
470
- * CSS inlined, and an empty clone of its content wrapper for the probe's
471
- * sample elements to be injected into. Nothing else — no shell, no scripts.
472
- */
473
- export function buildProbeReconstruction(routeCss: string, wrapperClass: string | null): string {
474
- const wrapper = wrapperClass ? `<div class="${wrapperClass.replace(/"/g, '&quot;')}"></div>` : '<main></main>';
475
- // Neutralise a literal `</style` in the site's CSS. It is legal inside a
476
- // `content:` string, and because a srcdoc frame inherits THIS origin, an
477
- // early close would let the remainder parse as HTML in the app's own origin.
478
- // Escaping the slash keeps the bytes valid CSS while making the sequence
479
- // unable to terminate the element. Paired with the `sandbox` attribute in
480
- // `probeHostStyles`: a document built from site CSS is a different trust
481
- // boundary than this probe's original job of loading the site's own
482
- // already-trusted page, so it gets belt and braces.
483
- const inert = routeCss.replace(/<\/(style)/gi, '<\\/$1');
484
- return `<!doctype html><html><head><meta charset="utf-8"><style>${inert}</style></head><body>${wrapper}</body></html>`;
485
- }
486
-
487
- /**
488
- * Run a one-shot probe against `source`. Returns the generated stylesheet, or
489
- * an empty string when the frame failed to load or there was nothing probable.
531
+ * Run a one-shot probe against the site's real rendered page at `url`, which
532
+ * shares the editor's origin so `contentDocument` is readable. Resolves to
533
+ * what the page yields (see `readProbedPage`), or an empty probe when the
534
+ * frame failed to load.
490
535
  *
491
536
  * `signal` lets the caller cancel a probe (eg the user navigated to
492
537
  * a different page mid-fetch). Cleanup is best-effort.
493
538
  */
494
539
  export function probeHostStyles(
495
- source: ProbeSource,
540
+ url: string,
496
541
  wrapperClass: string | null,
497
542
  theme: 'light' | 'dark' | null,
543
+ discover: boolean,
498
544
  signal?: AbortSignal,
499
- ): Promise<string> {
545
+ ): Promise<HostProbe> {
500
546
  return new Promise((resolve) => {
501
547
  if (typeof document === 'undefined') {
502
- resolve('');
548
+ resolve(EMPTY_PROBE);
503
549
  return;
504
550
  }
505
551
 
@@ -514,24 +560,14 @@ export function probeHostStyles(
514
560
  iframe.setAttribute('aria-hidden', 'true');
515
561
  iframe.setAttribute('tabindex', '-1');
516
562
  iframe.setAttribute('data-conloca-probe-iframe', '');
517
- if ('srcdoc' in source) {
518
- // `allow-same-origin` ONLY: `contentDocument` stays readable, which the
519
- // probe needs, while no script in the reconstruction can execute. Applied
520
- // to the srcdoc route alone — sandboxing the real-page route would stop
521
- // the site's own scripts running and silently change what the
522
- // same-origin probe measures, which is the path that already works.
523
- iframe.setAttribute('sandbox', 'allow-same-origin');
524
- iframe.srcdoc = source.srcdoc;
525
- } else {
526
- iframe.src = source.url;
527
- }
563
+ iframe.src = url;
528
564
 
529
565
  let settled = false;
530
566
  let timeout: number | undefined;
531
567
  const cleanup = () => {
532
568
  if (iframe.parentElement) iframe.parentElement.removeChild(iframe);
533
569
  };
534
- const settle = (css: string) => {
570
+ const settle = (result: HostProbe = EMPTY_PROBE) => {
535
571
  if (settled) return;
536
572
  settled = true;
537
573
  // Cancel the deadline as well. A superseded probe (re-render, theme or
@@ -540,15 +576,15 @@ export function probeHostStyles(
540
576
  // resolved and is no longer in flight.
541
577
  if (timeout !== undefined) window.clearTimeout(timeout);
542
578
  cleanup();
543
- resolve(css);
579
+ resolve(result);
544
580
  };
545
581
 
546
- const abortHandler = () => settle('');
582
+ const abortHandler = () => settle();
547
583
  signal?.addEventListener('abort', abortHandler);
548
584
 
549
585
  timeout = window.setTimeout(() => {
550
- console.warn('[Conloca] Host style probe timed out for', 'srcdoc' in source ? '<reconstruction>' : source.url);
551
- settle('');
586
+ console.warn('[Conloca] Host style probe timed out for', url);
587
+ settle();
552
588
  }, IFRAME_TIMEOUT_MS);
553
589
 
554
590
  iframe.addEventListener('load', () => {
@@ -586,20 +622,19 @@ export function probeHostStyles(
586
622
  requestAnimationFrame(() => {
587
623
  requestAnimationFrame(() => {
588
624
  if (signal?.aborted) {
589
- settle('');
625
+ settle();
590
626
  return;
591
627
  }
592
628
  try {
593
629
  const doc = iframe.contentDocument;
594
630
  if (!doc) {
595
- settle('');
631
+ settle();
596
632
  return;
597
633
  }
598
- const css = buildProbeStylesheet(doc, wrapperClass);
599
- settle(css);
634
+ settle(readProbedPage(doc, wrapperClass, discover));
600
635
  } catch (err) {
601
636
  console.warn('[Conloca] Host style probe failed:', err);
602
- settle('');
637
+ settle();
603
638
  }
604
639
  });
605
640
  });
@@ -607,7 +642,7 @@ export function probeHostStyles(
607
642
 
608
643
  iframe.addEventListener('error', () => {
609
644
  window.clearTimeout(timeout);
610
- settle('');
645
+ settle();
611
646
  });
612
647
 
613
648
  document.body.appendChild(iframe);
@@ -618,44 +653,39 @@ export function probeHostStyles(
618
653
  * React hook wrapper. Re-probes whenever its inputs change (so dark/light
619
654
  * swaps refresh the captured styles).
620
655
  *
621
- * `routeCss` selects the delivery route. When the registered route CSS is
622
- * present — the site is on another origin, so its page cannot be read — the
623
- * probe measures a same-origin reconstruction of it. Otherwise it measures the
624
- * real page at `routeUrl`, which is the same-origin path and strictly better:
625
- * real markup means utility classes and inline styles are observed.
656
+ * Probes the real page at `routeUrl`: real markup means utility classes and
657
+ * inline styles are observed.
626
658
  *
627
- * Returns both the stylesheet and whether the current inputs have settled
659
+ * Returns what the page yielded and whether the current inputs have settled
628
660
  * once. Callers must gate fallback tiers on `settled`, not on `css === ''`:
629
661
  * the empty string is the initial state AND the definitive "nothing probable"
630
662
  * outcome, and treating them the same paints the derived tier then restyles
631
663
  * when the probe lands.
632
664
  *
633
- * During a re-probe (theme toggle, route change) prior `css` stays visible
665
+ * During a re-probe (theme toggle, route change) the prior result stays visible
634
666
  * and `settled` stays true until the new result arrives, so fallback tiers
635
667
  * do not flash back in.
636
668
  */
637
669
  export function useProbedHostStyles(
638
670
  routeUrl: string | undefined,
639
671
  wrapperClass: string | null,
640
- options: { theme?: 'light' | 'dark' | null; routeCss?: string } = {},
641
- ): { css: string; settled: boolean } {
642
- const [css, setCss] = useState<string>('');
672
+ options: { theme?: 'light' | 'dark' | null; discover?: boolean } = {},
673
+ ): HostProbe & { settled: boolean } {
674
+ const [probe, setProbe] = useState<HostProbe>(EMPTY_PROBE);
643
675
  const [settled, setSettled] = useState(false);
644
- // Mirror of `css` for the effect body — reading state inside the effect
676
+ // Mirror of `probe.css` for the effect body — reading state inside the effect
645
677
  // would stale-close over the mount value and mis-handle re-probes.
646
- const cssRef = useRef(css);
678
+ const cssRef = useRef(probe.css);
647
679
  const theme = options.theme ?? null;
648
- const routeCss = options.routeCss ?? '';
680
+ // Only an editor without the dev endpoints needs the page's styles and wrappers.
681
+ const discover = options.discover ?? false;
682
+ // The route is a site path; the page lives under the site's base, which need not be this document's origin root.
683
+ const pageUrl = routeUrl ? buildSiteUrl(routeUrl) : undefined;
649
684
 
650
685
  useEffect(() => {
651
- const source: ProbeSource | null = routeCss
652
- ? { srcdoc: buildProbeReconstruction(routeCss, wrapperClass) }
653
- : routeUrl
654
- ? { url: routeUrl }
655
- : null;
656
- if (!source) {
686
+ if (!pageUrl) {
657
687
  cssRef.current = '';
658
- setCss('');
688
+ setProbe(EMPTY_PROBE);
659
689
  setSettled(true);
660
690
  return;
661
691
  }
@@ -668,17 +698,17 @@ export function useProbedHostStyles(
668
698
  }
669
699
 
670
700
  const controller = new AbortController();
671
- probeHostStyles(source, wrapperClass, theme, controller.signal).then((result) => {
701
+ void probeHostStyles(pageUrl, wrapperClass, theme, discover, controller.signal).then((result) => {
672
702
  if (controller.signal.aborted) return;
673
- cssRef.current = result;
674
- setCss(result);
703
+ cssRef.current = result.css;
704
+ setProbe((prev) => keepUnchanged(prev, result));
675
705
  setSettled(true);
676
706
  });
677
707
 
678
708
  return () => {
679
709
  controller.abort();
680
710
  };
681
- }, [routeUrl, routeCss, wrapperClass, theme]);
711
+ }, [pageUrl, wrapperClass, theme, discover]);
682
712
 
683
- return { css, settled };
713
+ return { ...probe, settled };
684
714
  }
package/src/index.ts CHANGED
@@ -21,6 +21,9 @@ export {
21
21
  notifyEditorDirtyChanged,
22
22
  registerEditorFlushHandler,
23
23
  } from './editor-flush.js';
24
+ // The editor page's side of a parent frame
25
+ export { connectEditorFrame, type EditorFrame } from './frame/editor-frame.js';
26
+ export { awaitParentHello } from './frame/parent-hello.js';
24
27
  // Export types from hooks (AssetEntry, etc.)
25
28
  export type { AssetEntry, AssetUsage, FolderListing, FolderTreeNode } from './hooks/index.js';
26
29
  // Export configuration function
@@ -28,6 +31,7 @@ export {
28
31
  configureUI,
29
32
  type EditorWriteAccess,
30
33
  type EditorWriteRefusal,
34
+ type MemoryRouterConfig,
31
35
  type OpenPreviewResult,
32
36
  type PreviewCapability,
33
37
  setDataBindings,
@@ -38,5 +42,6 @@ export {
38
42
  type TemplateConfig,
39
43
  type UIConfig,
40
44
  } from './ui-config.js';
41
- // Export the read-only enforcement a host installs through `setEditorReadOnly`
42
- export { ContentWriteRefusedError, editorWriteAccess } from './write-access.js';
45
+ // Export the read-only enforcement a host installs through `setEditorReadOnly`, and the guard a parent frame wraps
46
+ // its own content client in
47
+ export { ContentWriteRefusedError, editorWriteAccess, guardContentWrites } from './write-access.js';
package/src/main-spa.tsx CHANGED
@@ -3,6 +3,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
3
  import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
4
4
  import { createRoot } from 'react-dom/client';
5
5
  import App from './App.js';
6
+ import { Toaster } from './components/toast.js';
6
7
  import { CanvasThemeProvider } from './hooks/useCanvasTheme.js';
7
8
  import { ThemeProvider } from './hooks/useTheme.js';
8
9
  import { installDiscoveredMdxComponents, type MdxComponents } from './mdx-components.js';
@@ -62,6 +63,7 @@ export function mountSpa(): void {
62
63
  <App basename={config.basename} />
63
64
  </CanvasThemeProvider>
64
65
  </ThemeProvider>
66
+ <Toaster />
65
67
  {config.enableDevtools && <ReactQueryDevtools initialIsOpen={false} />}
66
68
  </QueryClientProvider>,
67
69
  );
package/src/main.css CHANGED
@@ -80,7 +80,8 @@
80
80
  host's CSS doesn't reach. */
81
81
  @layer base, theme, components, utilities, cms-admin, conloca-host-defaults, conloca-host-preview;
82
82
 
83
- @import "@puckeditor/core/puck.css" layer(cms-admin);
83
+ /* Puck's styles without their remote Inter @import: the editor sets its own font stack (--puck-font-family). */
84
+ @import "@puckeditor/core/no-external.css" layer(cms-admin);
84
85
  /* Granular Tailwind v4 imports (see the preflight note in the header):
85
86
  * theme + utilities keep their exact pre-split homes — the
86
87
  * `cms-admin.theme` / `cms-admin.utilities` sublayers the monolithic
@@ -425,11 +426,14 @@ body {
425
426
  padding: 0.375rem !important;
426
427
  }
427
428
 
428
- /* Disable undo/redo buttons when there's no history */
429
- [class*="MenuBar"] button[disabled],
430
- [class*="MenuBar"] button:disabled,
431
- [class*="MenuBar"] button[aria-disabled="true"],
432
- [class*="MenuBar"] button[aria-disabled="true"]:hover {
429
+ /* Disable undo/redo buttons when there's no history. Scoped to Puck's history
430
+ * group: the editor's own header actions also mount inside the MenuBar, and
431
+ * the unavailable Preview must still receive its click and hover to explain
432
+ * itself. */
433
+ [class*="MenuBar-history"] button[disabled],
434
+ [class*="MenuBar-history"] button:disabled,
435
+ [class*="MenuBar-history"] button[aria-disabled="true"],
436
+ [class*="MenuBar-history"] button[aria-disabled="true"]:hover {
433
437
  opacity: 0.4 !important;
434
438
  cursor: not-allowed !important;
435
439
  pointer-events: none !important;
@@ -438,13 +442,13 @@ body {
438
442
  }
439
443
 
440
444
  /* Style for enabled undo/redo buttons */
441
- [class*="MenuBar"] button:not([disabled]):not(:disabled):not([aria-disabled="true"]) {
445
+ [class*="MenuBar-history"] button:not([disabled]):not(:disabled):not([aria-disabled="true"]) {
442
446
  opacity: 1 !important;
443
447
  cursor: pointer !important;
444
448
  }
445
449
 
446
450
  /* Also target buttons that might use data attributes for disabled state */
447
- [class*="MenuBar"] button[data-disabled="true"] {
451
+ [class*="MenuBar-history"] button[data-disabled="true"] {
448
452
  opacity: 0.4 !important;
449
453
  cursor: not-allowed !important;
450
454
  pointer-events: none !important;
@@ -1,11 +1,12 @@
1
- import type { z } from 'zod';
1
+ import { type HostSchema, hostSchemaFieldNames } from './host-schema.js';
2
2
 
3
3
  /**
4
4
  * Form-UI hint vocabulary for page metadata fields.
5
5
  *
6
6
  * Hosts attach a hint to each field they want surfaced in the page-settings
7
7
  * dialog. The hint drives form rendering — control type, grouping, helper
8
- * text, etc. — independently of the Zod schema, which still owns validation.
8
+ * text, etc. — independently of the host schema, whose generated validator
9
+ * still owns validation.
9
10
  *
10
11
  * Dotted keys ('sidebar.label') are supported in the hint record; on save
11
12
  * they materialize into nested objects in YAML frontmatter, and on load
@@ -62,10 +63,10 @@ export type PageSchemaGroup = {
62
63
  */
63
64
  export type CoreFieldsMode = 'full' | 'minimal' | 'none';
64
65
 
65
- export interface PageSchemaDescriptor<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
66
+ export interface PageSchemaDescriptor<S extends HostSchema = HostSchema> {
66
67
  /** Human-readable label shown in the dialog header. */
67
68
  label?: string;
68
- /** Zod schema used for validation and field-shape introspection. */
69
+ /** Host schema: its generated validator checks entries, its generated metadata shapes the form. */
69
70
  schema: S;
70
71
  /** Form-UI hints keyed by field name (dotted keys allowed for nested fields). */
71
72
  ui?: FieldHints;
@@ -80,15 +81,13 @@ export interface PageSchemaDescriptor<S extends z.ZodObject<z.ZodRawShape> = z.Z
80
81
  *
81
82
  * Mirrors Astro's `defineConfig` — purely for editor inference. The schema's
82
83
  * concrete type is carried through the descriptor (not widened), so a host
83
- * can recover its metadata type from `z.infer<typeof descriptor.schema>`.
84
+ * can recover its metadata type from `HostSchemaType<typeof descriptor.schema>`.
84
85
  *
85
86
  * Import this from `@conloca/astro-cms/page-schemas` in a content config so
86
87
  * the MDX editor / React registry is not pulled into Astro's content layer.
87
88
  */
88
- export function definePageSchema<S extends z.ZodObject<z.ZodRawShape>>(
89
- descriptor: PageSchemaDescriptor<S>,
90
- ): PageSchemaDescriptor<S> {
91
- if (descriptor.coreFields?.mode === 'none' && !('title' in descriptor.schema.shape)) {
89
+ export function definePageSchema<S extends HostSchema>(descriptor: PageSchemaDescriptor<S>): PageSchemaDescriptor<S> {
90
+ if (descriptor.coreFields?.mode === 'none' && !hostSchemaFieldNames(descriptor.schema).includes('title')) {
92
91
  throw new Error(
93
92
  "definePageSchema: coreFields.mode 'none' requires the schema to declare a `title` field " +
94
93
  '(ContentMeta.title is required by the content-api).',
@@ -98,10 +97,10 @@ export function definePageSchema<S extends z.ZodObject<z.ZodRawShape>>(
98
97
  }
99
98
 
100
99
  /**
101
- * Registry entry value: either a bare Zod object (legacy — wrapped as a
100
+ * Registry entry value: either a bare {@link HostSchema} (wrapped as a
102
101
  * descriptor with `coreFields.mode: 'full'`) or an explicit descriptor.
103
102
  */
104
- export type PageSchemaEntry = z.ZodObject<z.ZodRawShape> | PageSchemaDescriptor;
103
+ export type PageSchemaEntry<S extends HostSchema = HostSchema> = S | PageSchemaDescriptor<S>;
105
104
 
106
105
  /**
107
106
  * Page-schema registry keyed by match expression.
@@ -111,20 +110,22 @@ export type PageSchemaEntry = z.ZodObject<z.ZodRawShape> | PageSchemaDescriptor;
111
110
  * - `type:<puck|mdx>` — matches all pages of the given content type.
112
111
  * - pathname prefix (must start with `/`) — longest-prefix-match against the page's pathname.
113
112
  */
114
- export type PageSchemas = Record<string, PageSchemaEntry>;
113
+ export type PageSchemas<S extends HostSchema = HostSchema> = Record<string, PageSchemaEntry<S>>;
115
114
 
116
115
  /**
117
- * Normalize an entry to a descriptor. Bare Zod objects (legacy) get wrapped
118
- * with default `coreFields.mode: 'full'` so the dialog can render today's
116
+ * Normalize an entry to a descriptor. Bare host schemas get wrapped with
117
+ * default `coreFields.mode: 'full'` so the dialog can render today's
119
118
  * three-section layout unchanged.
120
119
  */
121
- export function toPageSchemaDescriptor(entry: PageSchemaEntry): PageSchemaDescriptor {
120
+ export function toPageSchemaDescriptor<S extends HostSchema = HostSchema>(
121
+ entry: PageSchemaEntry<S>,
122
+ ): PageSchemaDescriptor<S> {
122
123
  if (isPageSchemaDescriptor(entry)) return entry;
123
124
  return { schema: entry, coreFields: { mode: 'full' } };
124
125
  }
125
126
 
126
- function isPageSchemaDescriptor(value: PageSchemaEntry): value is PageSchemaDescriptor {
127
- return typeof value === 'object' && value !== null && 'schema' in value && !('shape' in value);
127
+ function isPageSchemaDescriptor<S extends HostSchema>(value: PageSchemaEntry<S>): value is PageSchemaDescriptor<S> {
128
+ return typeof value === 'object' && value !== null && 'schema' in value && !('validate' in value);
128
129
  }
129
130
 
130
131
  /**
@@ -174,3 +175,14 @@ export function resolvePageSchemaEntry(
174
175
  // The data-collection registry type, re-exported so content configs can
175
176
  // reference it without touching the runtime data-schemas module.
176
177
  export type { DataSchemas } from './data-schemas.js';
178
+ // The generated-schema contract both registries are keyed on.
179
+ export {
180
+ defineHostSchema,
181
+ type HostSchema,
182
+ type HostSchemaMetadata,
183
+ type HostSchemaType,
184
+ hostSchemaFieldNames,
185
+ isHostSchema,
186
+ resolveHostJsonSchema,
187
+ rootObjectOf,
188
+ } from './host-schema.js';
@@ -2,11 +2,9 @@ import type { SiteStyles } from './site-styles.js';
2
2
 
3
3
  /**
4
4
  * The fallback styles tier for the MDX typing surface, used when no dev-server
5
- * discovery endpoint answers (a host app on another origin, or a production
6
- * build). Derived from the siteStyles registry: the route CSS a host app set
7
- * with `setHostDiscovery`, or the `siteStyles` option's CSS, reduced to
8
- * prose-safe rules, plus a paper base sheet. Lives in cms-spa so every setup
9
- * runs one derivation.
5
+ * discovery endpoint answers (a production build). Derived from the siteStyles
6
+ * registry (the `siteStyles` option's CSS), reduced to prose-safe rules, plus
7
+ * a paper base sheet. Lives in cms-spa so every setup runs one derivation.
10
8
  *
11
9
  * CMSMDXEditor consumes it as the fallback below endpoint discovery: when the
12
10
  * `/api/styles` fetch delivers (dev server), this tier stays out of the
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
+ import type { ContentWrapperInfo, DiscoveredWrappers } from './content-wrapper.js';
2
3
  import { IMPORT_RE } from './site-css-layer.js';
3
4
  import { getCmsRoute } from './ui-config.js';
4
5
 
@@ -217,28 +218,9 @@ export function useFetchedSiteStyles(routeUrl: string | undefined, options: { cm
217
218
  return styles;
218
219
  }
219
220
 
220
- /**
221
- * Shape returned by the `/api/content-wrapper?url=…` endpoint — the
222
- * tag name and class list of the host page's content-root element.
223
- * Kept in lock-step with `ContentWrapperInfo` in
224
- * `packages/astro-cms/src/site-styles/content-wrapper-endpoint.ts`.
225
- */
226
- export interface HostContentWrapper {
227
- tagName: string;
228
- className: string;
229
- }
230
-
231
- /**
232
- * Discovered host wrappers for a given route. `content` is the
233
- * prose-content wrapper (eg `.sl-markdown-content`). `codeBlock` is
234
- * the ordered chain of classed wrappers between the content wrapper
235
- * and `<pre>`, outermost first (eg `[.expressive-code, .frame ...]`).
236
- * Either may be null when not present on the page.
237
- */
238
- export interface HostWrappers {
239
- content: HostContentWrapper | null;
240
- codeBlock: HostContentWrapper[] | null;
241
- }
221
+ /** The shape `/api/content-wrapper?url=…` answers: see `content-wrapper.ts`. */
222
+ export type HostContentWrapper = ContentWrapperInfo;
223
+ export type HostWrappers = DiscoveredWrappers;
242
224
 
243
225
  /**
244
226
  * Fetches the host page's wrappers for the given route URL. The