@conloca/cms-spa 0.2.2 → 0.2.4

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 (259) hide show
  1. package/README.md +26 -0
  2. package/dist/spa/main.css +229 -1
  3. package/dist/ts/.build-inputs.json +187 -0
  4. package/dist/ts/App.d.ts +5 -1
  5. package/dist/ts/App.d.ts.map +1 -1
  6. package/dist/ts/App.js +13 -6
  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 +2 -1
  13. package/dist/ts/components/CMSDashboard.js.map +1 -1
  14. package/dist/ts/components/cards/DataEntryCard.d.ts +1 -1
  15. package/dist/ts/components/cards/DataEntryCard.d.ts.map +1 -1
  16. package/dist/ts/components/cards/SectionCard.d.ts +1 -1
  17. package/dist/ts/components/cards/SectionCard.d.ts.map +1 -1
  18. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts +6 -1
  19. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -1
  20. package/dist/ts/components/dialogs/DeleteConfirmDialog.js +2 -2
  21. package/dist/ts/components/dialogs/DeleteConfirmDialog.js.map +1 -1
  22. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +1 -1
  23. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
  24. package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts +10 -0
  25. package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts.map +1 -0
  26. package/dist/ts/components/dialogs/MakePagesEditableDialog.js +35 -0
  27. package/dist/ts/components/dialogs/MakePagesEditableDialog.js.map +1 -0
  28. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts +6 -1
  29. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts.map +1 -1
  30. package/dist/ts/components/dialogs/MoveFolderDialog.js +3 -3
  31. package/dist/ts/components/dialogs/MoveFolderDialog.js.map +1 -1
  32. package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
  33. package/dist/ts/components/editor/CMSMDXEditor.js +53 -62
  34. package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
  35. package/dist/ts/components/editor/DocsPreviewButton.d.ts +6 -0
  36. package/dist/ts/components/editor/DocsPreviewButton.d.ts.map +1 -0
  37. package/dist/ts/components/editor/DocsPreviewButton.js +15 -0
  38. package/dist/ts/components/editor/DocsPreviewButton.js.map +1 -0
  39. package/dist/ts/components/editor/ImagePickerDialog.js +2 -2
  40. package/dist/ts/components/editor/ImagePickerDialog.js.map +1 -1
  41. package/dist/ts/components/editor/LocaleSelector.d.ts +1 -1
  42. package/dist/ts/components/editor/LocaleSelector.d.ts.map +1 -1
  43. package/dist/ts/components/editor/MdxPageEditor.d.ts.map +1 -1
  44. package/dist/ts/components/editor/MdxPageEditor.js +2 -1
  45. package/dist/ts/components/editor/MdxPageEditor.js.map +1 -1
  46. package/dist/ts/components/editor/PageEditor.d.ts +1 -1
  47. package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
  48. package/dist/ts/components/editor/PageEditor.js +47 -19
  49. package/dist/ts/components/editor/PageEditor.js.map +1 -1
  50. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts +1 -1
  51. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts.map +1 -1
  52. package/dist/ts/components/editor/PageEditorWrapper.js +31 -5
  53. package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
  54. package/dist/ts/components/editor/draft-media-config.d.ts +32 -2
  55. package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
  56. package/dist/ts/components/editor/draft-media-config.js +194 -39
  57. package/dist/ts/components/editor/draft-media-config.js.map +1 -1
  58. package/dist/ts/components/editor/page-setting-targets.d.ts +1 -1
  59. package/dist/ts/components/editor/page-setting-targets.d.ts.map +1 -1
  60. package/dist/ts/components/editor/preview-availability.d.ts +8 -5
  61. package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
  62. package/dist/ts/components/editor/preview-availability.js +8 -5
  63. package/dist/ts/components/editor/preview-availability.js.map +1 -1
  64. package/dist/ts/components/editors/DataEditor.d.ts +6 -2
  65. package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
  66. package/dist/ts/components/editors/DataEditor.js +46 -19
  67. package/dist/ts/components/editors/DataEditor.js.map +1 -1
  68. package/dist/ts/components/fields/ImageField.js +2 -2
  69. package/dist/ts/components/fields/ImageField.js.map +1 -1
  70. package/dist/ts/components/media/AssetCard.d.ts +1 -1
  71. package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
  72. package/dist/ts/components/media/AssetCard.js +3 -2
  73. package/dist/ts/components/media/AssetCard.js.map +1 -1
  74. package/dist/ts/components/media/AssetDetailSidebar.d.ts +1 -1
  75. package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
  76. package/dist/ts/components/media/AssetDetailSidebar.js +7 -2
  77. package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
  78. package/dist/ts/components/media/AssetUsageList.d.ts +13 -0
  79. package/dist/ts/components/media/AssetUsageList.d.ts.map +1 -0
  80. package/dist/ts/components/media/AssetUsageList.js +35 -0
  81. package/dist/ts/components/media/AssetUsageList.js.map +1 -0
  82. package/dist/ts/components/media/MediaLibrary.d.ts +1 -1
  83. package/dist/ts/components/media/MediaLibrary.d.ts.map +1 -1
  84. package/dist/ts/components/media/MediaLibrary.js +6 -4
  85. package/dist/ts/components/media/MediaLibrary.js.map +1 -1
  86. package/dist/ts/components/media/MediaToolbar.d.ts +1 -1
  87. package/dist/ts/components/media/MediaToolbar.d.ts.map +1 -1
  88. package/dist/ts/components/media/index.d.ts +1 -0
  89. package/dist/ts/components/media/index.d.ts.map +1 -1
  90. package/dist/ts/components/media/index.js +1 -0
  91. package/dist/ts/components/media/index.js.map +1 -1
  92. package/dist/ts/components/pages/DataList.d.ts.map +1 -1
  93. package/dist/ts/components/pages/DataList.js +48 -31
  94. package/dist/ts/components/pages/DataList.js.map +1 -1
  95. package/dist/ts/components/pages/MediaPage.d.ts.map +1 -1
  96. package/dist/ts/components/pages/MediaPage.js +7 -5
  97. package/dist/ts/components/pages/MediaPage.js.map +1 -1
  98. package/dist/ts/components/pages/NoPagesYet.d.ts +5 -0
  99. package/dist/ts/components/pages/NoPagesYet.d.ts.map +1 -0
  100. package/dist/ts/components/pages/NoPagesYet.js +16 -0
  101. package/dist/ts/components/pages/NoPagesYet.js.map +1 -0
  102. package/dist/ts/components/pages/PageList.d.ts.map +1 -1
  103. package/dist/ts/components/pages/PageList.js +19 -8
  104. package/dist/ts/components/pages/PageList.js.map +1 -1
  105. package/dist/ts/components/sandbox/ContentSandbox.d.ts +1 -1
  106. package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
  107. package/dist/ts/components/sandbox/ContentSandbox.js +36 -5
  108. package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
  109. package/dist/ts/components/ui/IconButton.d.ts +1 -1
  110. package/dist/ts/components/ui/IconButton.d.ts.map +1 -1
  111. package/dist/ts/content-wrapper.d.ts +65 -0
  112. package/dist/ts/content-wrapper.d.ts.map +1 -0
  113. package/dist/ts/content-wrapper.js +190 -0
  114. package/dist/ts/content-wrapper.js.map +1 -0
  115. package/dist/ts/convert-pages.d.ts +30 -0
  116. package/dist/ts/convert-pages.d.ts.map +1 -0
  117. package/dist/ts/convert-pages.js +85 -0
  118. package/dist/ts/convert-pages.js.map +1 -0
  119. package/dist/ts/data-schemas.d.ts.map +1 -1
  120. package/dist/ts/frame/channel.d.ts +40 -0
  121. package/dist/ts/frame/channel.d.ts.map +1 -0
  122. package/dist/ts/frame/channel.js +233 -0
  123. package/dist/ts/frame/channel.js.map +1 -0
  124. package/dist/ts/frame/editor-frame.d.ts +23 -0
  125. package/dist/ts/frame/editor-frame.d.ts.map +1 -0
  126. package/dist/ts/frame/editor-frame.js +159 -0
  127. package/dist/ts/frame/editor-frame.js.map +1 -0
  128. package/dist/ts/frame/media-cache.d.ts +37 -0
  129. package/dist/ts/frame/media-cache.d.ts.map +1 -0
  130. package/dist/ts/frame/media-cache.js +138 -0
  131. package/dist/ts/frame/media-cache.js.map +1 -0
  132. package/dist/ts/frame/memory-router.d.ts +10 -0
  133. package/dist/ts/frame/memory-router.d.ts.map +1 -0
  134. package/dist/ts/frame/memory-router.js +39 -0
  135. package/dist/ts/frame/memory-router.js.map +1 -0
  136. package/dist/ts/frame/parent-hello.d.ts +11 -0
  137. package/dist/ts/frame/parent-hello.d.ts.map +1 -0
  138. package/dist/ts/frame/parent-hello.js +53 -0
  139. package/dist/ts/frame/parent-hello.js.map +1 -0
  140. package/dist/ts/frame/protocol.d.ts +209 -0
  141. package/dist/ts/frame/protocol.d.ts.map +1 -0
  142. package/dist/ts/frame/protocol.js +200 -0
  143. package/dist/ts/frame/protocol.js.map +1 -0
  144. package/dist/ts/frame/rpc-content-client.d.ts +10 -0
  145. package/dist/ts/frame/rpc-content-client.d.ts.map +1 -0
  146. package/dist/ts/frame/rpc-content-client.js +51 -0
  147. package/dist/ts/frame/rpc-content-client.js.map +1 -0
  148. package/dist/ts/frame/save-shortcut.d.ts +8 -0
  149. package/dist/ts/frame/save-shortcut.d.ts.map +1 -0
  150. package/dist/ts/frame/save-shortcut.js +26 -0
  151. package/dist/ts/frame/save-shortcut.js.map +1 -0
  152. package/dist/ts/hooks/index.d.ts +2 -0
  153. package/dist/ts/hooks/index.d.ts.map +1 -1
  154. package/dist/ts/hooks/index.js +1 -0
  155. package/dist/ts/hooks/index.js.map +1 -1
  156. package/dist/ts/hooks/usePageConversion.d.ts +11 -0
  157. package/dist/ts/hooks/usePageConversion.d.ts.map +1 -0
  158. package/dist/ts/hooks/usePageConversion.js +47 -0
  159. package/dist/ts/hooks/usePageConversion.js.map +1 -0
  160. package/dist/ts/hooks/useUploadFlow.d.ts.map +1 -1
  161. package/dist/ts/hooks/useUploadFlow.js +41 -7
  162. package/dist/ts/hooks/useUploadFlow.js.map +1 -1
  163. package/dist/ts/host-style-probe.d.ts +32 -37
  164. package/dist/ts/host-style-probe.d.ts.map +1 -1
  165. package/dist/ts/host-style-probe.js +86 -68
  166. package/dist/ts/host-style-probe.js.map +1 -1
  167. package/dist/ts/index.d.ts +6 -2
  168. package/dist/ts/index.d.ts.map +1 -1
  169. package/dist/ts/index.js +9 -2
  170. package/dist/ts/index.js.map +1 -1
  171. package/dist/ts/main-spa.d.ts.map +1 -1
  172. package/dist/ts/main-spa.js +2 -1
  173. package/dist/ts/main-spa.js.map +1 -1
  174. package/dist/ts/media/prepare-image-upload.d.ts +19 -0
  175. package/dist/ts/media/prepare-image-upload.d.ts.map +1 -0
  176. package/dist/ts/media/prepare-image-upload.js +93 -0
  177. package/dist/ts/media/prepare-image-upload.js.map +1 -0
  178. package/dist/ts/media/use-asset-serve-src.d.ts +7 -0
  179. package/dist/ts/media/use-asset-serve-src.d.ts.map +1 -0
  180. package/dist/ts/media/use-asset-serve-src.js +17 -0
  181. package/dist/ts/media/use-asset-serve-src.js.map +1 -0
  182. package/dist/ts/page-schemas.d.ts.map +1 -1
  183. package/dist/ts/prose-surface-css.d.ts +3 -5
  184. package/dist/ts/prose-surface-css.d.ts.map +1 -1
  185. package/dist/ts/prose-surface-css.js +3 -5
  186. package/dist/ts/prose-surface-css.js.map +1 -1
  187. package/dist/ts/puck-config.d.ts.map +1 -1
  188. package/dist/ts/selected-block.d.ts.map +1 -1
  189. package/dist/ts/site-styles.d.ts +4 -21
  190. package/dist/ts/site-styles.d.ts.map +1 -1
  191. package/dist/ts/site-styles.js.map +1 -1
  192. package/dist/ts/ui-config.d.ts +62 -3
  193. package/dist/ts/ui-config.d.ts.map +1 -1
  194. package/dist/ts/ui-config.js +18 -0
  195. package/dist/ts/ui-config.js.map +1 -1
  196. package/dist/ts/utils/asset-url.d.ts +3 -0
  197. package/dist/ts/utils/asset-url.d.ts.map +1 -1
  198. package/dist/ts/utils/asset-url.js +4 -0
  199. package/dist/ts/utils/asset-url.js.map +1 -1
  200. package/dist/ts/utils/data-entry-validation.d.ts +11 -0
  201. package/dist/ts/utils/data-entry-validation.d.ts.map +1 -0
  202. package/dist/ts/utils/data-entry-validation.js +15 -0
  203. package/dist/ts/utils/data-entry-validation.js.map +1 -0
  204. package/package.json +20 -11
  205. package/src/App.tsx +22 -10
  206. package/src/CmsSpaApp.tsx +5 -1
  207. package/src/components/CMSDashboard.tsx +16 -8
  208. package/src/components/dialogs/DeleteConfirmDialog.tsx +14 -1
  209. package/src/components/dialogs/MakePagesEditableDialog.tsx +112 -0
  210. package/src/components/dialogs/MoveFolderDialog.tsx +9 -2
  211. package/src/components/editor/CMSMDXEditor.tsx +56 -76
  212. package/src/components/editor/DocsPreviewButton.tsx +25 -0
  213. package/src/components/editor/ImagePickerDialog.tsx +2 -2
  214. package/src/components/editor/MdxPageEditor.tsx +2 -0
  215. package/src/components/editor/PageEditor.tsx +46 -22
  216. package/src/components/editor/PageEditorWrapper.tsx +34 -5
  217. package/src/components/editor/draft-media-config.ts +199 -41
  218. package/src/components/editor/preview-availability.ts +9 -5
  219. package/src/components/editors/DataEditor.tsx +65 -32
  220. package/src/components/fields/ImageField.tsx +2 -2
  221. package/src/components/media/AssetCard.tsx +12 -9
  222. package/src/components/media/AssetDetailSidebar.tsx +38 -25
  223. package/src/components/media/AssetUsageList.tsx +84 -0
  224. package/src/components/media/MediaLibrary.tsx +6 -4
  225. package/src/components/media/index.ts +1 -0
  226. package/src/components/pages/DataList.tsx +53 -29
  227. package/src/components/pages/MediaPage.tsx +14 -5
  228. package/src/components/pages/NoPagesYet.tsx +41 -0
  229. package/src/components/pages/PageList.tsx +40 -27
  230. package/src/components/sandbox/ContentSandbox.tsx +34 -5
  231. package/src/content-wrapper.ts +284 -0
  232. package/src/convert-pages.ts +110 -0
  233. package/src/frame/channel.ts +258 -0
  234. package/src/frame/editor-frame.ts +184 -0
  235. package/src/frame/media-cache.ts +157 -0
  236. package/src/frame/memory-router.ts +39 -0
  237. package/src/frame/parent-hello.ts +62 -0
  238. package/src/frame/protocol.ts +332 -0
  239. package/src/frame/rpc-content-client.ts +58 -0
  240. package/src/frame/save-shortcut.ts +25 -0
  241. package/src/hooks/index.ts +2 -0
  242. package/src/hooks/usePageConversion.ts +55 -0
  243. package/src/hooks/useUploadFlow.ts +44 -7
  244. package/src/host-style-probe.ts +104 -90
  245. package/src/index.ts +10 -2
  246. package/src/main-spa.tsx +2 -0
  247. package/src/main.css +2 -1
  248. package/src/media/prepare-image-upload.ts +118 -0
  249. package/src/media/use-asset-serve-src.ts +22 -0
  250. package/src/prose-surface-css.ts +3 -5
  251. package/src/site-styles.ts +4 -22
  252. package/src/ui-config.ts +74 -3
  253. package/src/utils/asset-url.ts +6 -0
  254. package/src/utils/data-entry-validation.ts +16 -0
  255. package/dist/ts/host-discovery.d.ts +0 -40
  256. package/dist/ts/host-discovery.d.ts.map +0 -1
  257. package/dist/ts/host-discovery.js +0 -39
  258. package/dist/ts/host-discovery.js.map +0 -1
  259. package/src/host-discovery.ts +0 -77
@@ -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
@@ -463,59 +528,24 @@ function probeInlineTag(view: Window, parent: HTMLElement, tag: string): string
463
528
  }
464
529
 
465
530
  /**
466
- * Where the probe reads from. Two delivery routes, ONE mechanism:
467
- *
468
- * - `{ url }` — the site's real rendered page, for when the editor and the
469
- * site share an origin, so `contentDocument` is readable.
470
- * - `{ srcdoc }` — a same-origin reconstruction assembled from what the host
471
- * set with `setHostDiscovery` (its `routeCss` plus the discovered wrapper
472
- * class). For a site on a DIFFERENT origin, where no header on either side
473
- * can make its document readable: the same-origin
474
- * policy is not a permission, it is the boundary. An `srcdoc` frame
475
- * inherits the parent's origin, so the probe runs against it normally, and
476
- * a CSP of `frame-src 'self'` already covers `srcdoc`.
477
- *
478
- * A reconstruction sees the stylesheet but not the markup, so it cannot
479
- * observe utility-class or inline-style typography on real elements — the very
480
- * thing the probe exists for on utility-first hosts.
481
- */
482
- export type ProbeSource = { url: string } | { srcdoc: string };
483
-
484
- /**
485
- * Build the reconstruction document for `{ srcdoc }` probing: the host's route
486
- * CSS inlined, and an empty clone of its content wrapper for the probe's
487
- * sample elements to be injected into. Nothing else — no shell, no scripts.
488
- */
489
- export function buildProbeReconstruction(routeCss: string, wrapperClass: string | null): string {
490
- const wrapper = wrapperClass ? `<div class="${wrapperClass.replace(/"/g, '&quot;')}"></div>` : '<main></main>';
491
- // Neutralise a literal `</style` in the site's CSS. It is legal inside a
492
- // `content:` string, and because a srcdoc frame inherits THIS origin, an
493
- // early close would let the remainder parse as HTML in the app's own origin.
494
- // Escaping the slash keeps the bytes valid CSS while making the sequence
495
- // unable to terminate the element. Paired with the `sandbox` attribute in
496
- // `probeHostStyles`: a document built from site CSS is a different trust
497
- // boundary than this probe's original job of loading the site's own
498
- // already-trusted page, so it gets belt and braces.
499
- const inert = routeCss.replace(/<\/(style)/gi, '<\\/$1');
500
- return `<!doctype html><html><head><meta charset="utf-8"><style>${inert}</style></head><body>${wrapper}</body></html>`;
501
- }
502
-
503
- /**
504
- * Run a one-shot probe against `source`. Returns the generated stylesheet, or
505
- * 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.
506
535
  *
507
536
  * `signal` lets the caller cancel a probe (eg the user navigated to
508
537
  * a different page mid-fetch). Cleanup is best-effort.
509
538
  */
510
539
  export function probeHostStyles(
511
- source: ProbeSource,
540
+ url: string,
512
541
  wrapperClass: string | null,
513
542
  theme: 'light' | 'dark' | null,
543
+ discover: boolean,
514
544
  signal?: AbortSignal,
515
- ): Promise<string> {
545
+ ): Promise<HostProbe> {
516
546
  return new Promise((resolve) => {
517
547
  if (typeof document === 'undefined') {
518
- resolve('');
548
+ resolve(EMPTY_PROBE);
519
549
  return;
520
550
  }
521
551
 
@@ -530,24 +560,14 @@ export function probeHostStyles(
530
560
  iframe.setAttribute('aria-hidden', 'true');
531
561
  iframe.setAttribute('tabindex', '-1');
532
562
  iframe.setAttribute('data-conloca-probe-iframe', '');
533
- if ('srcdoc' in source) {
534
- // `allow-same-origin` ONLY: `contentDocument` stays readable, which the
535
- // probe needs, while no script in the reconstruction can execute. Applied
536
- // to the srcdoc route alone — sandboxing the real-page route would stop
537
- // the site's own scripts running and silently change what the
538
- // same-origin probe measures, which is the path that already works.
539
- iframe.setAttribute('sandbox', 'allow-same-origin');
540
- iframe.srcdoc = source.srcdoc;
541
- } else {
542
- iframe.src = source.url;
543
- }
563
+ iframe.src = url;
544
564
 
545
565
  let settled = false;
546
566
  let timeout: number | undefined;
547
567
  const cleanup = () => {
548
568
  if (iframe.parentElement) iframe.parentElement.removeChild(iframe);
549
569
  };
550
- const settle = (css: string) => {
570
+ const settle = (result: HostProbe = EMPTY_PROBE) => {
551
571
  if (settled) return;
552
572
  settled = true;
553
573
  // Cancel the deadline as well. A superseded probe (re-render, theme or
@@ -556,15 +576,15 @@ export function probeHostStyles(
556
576
  // resolved and is no longer in flight.
557
577
  if (timeout !== undefined) window.clearTimeout(timeout);
558
578
  cleanup();
559
- resolve(css);
579
+ resolve(result);
560
580
  };
561
581
 
562
- const abortHandler = () => settle('');
582
+ const abortHandler = () => settle();
563
583
  signal?.addEventListener('abort', abortHandler);
564
584
 
565
585
  timeout = window.setTimeout(() => {
566
- console.warn('[Conloca] Host style probe timed out for', 'srcdoc' in source ? '<reconstruction>' : source.url);
567
- settle('');
586
+ console.warn('[Conloca] Host style probe timed out for', url);
587
+ settle();
568
588
  }, IFRAME_TIMEOUT_MS);
569
589
 
570
590
  iframe.addEventListener('load', () => {
@@ -602,20 +622,19 @@ export function probeHostStyles(
602
622
  requestAnimationFrame(() => {
603
623
  requestAnimationFrame(() => {
604
624
  if (signal?.aborted) {
605
- settle('');
625
+ settle();
606
626
  return;
607
627
  }
608
628
  try {
609
629
  const doc = iframe.contentDocument;
610
630
  if (!doc) {
611
- settle('');
631
+ settle();
612
632
  return;
613
633
  }
614
- const css = buildProbeStylesheet(doc, wrapperClass);
615
- settle(css);
634
+ settle(readProbedPage(doc, wrapperClass, discover));
616
635
  } catch (err) {
617
636
  console.warn('[Conloca] Host style probe failed:', err);
618
- settle('');
637
+ settle();
619
638
  }
620
639
  });
621
640
  });
@@ -623,7 +642,7 @@ export function probeHostStyles(
623
642
 
624
643
  iframe.addEventListener('error', () => {
625
644
  window.clearTimeout(timeout);
626
- settle('');
645
+ settle();
627
646
  });
628
647
 
629
648
  document.body.appendChild(iframe);
@@ -634,44 +653,39 @@ export function probeHostStyles(
634
653
  * React hook wrapper. Re-probes whenever its inputs change (so dark/light
635
654
  * swaps refresh the captured styles).
636
655
  *
637
- * `routeCss` selects the delivery route. When the registered route CSS is
638
- * present — the site is on another origin, so its page cannot be read — the
639
- * probe measures a same-origin reconstruction of it. Otherwise it measures the
640
- * real page at `routeUrl`, which is the same-origin path and strictly better:
641
- * 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.
642
658
  *
643
- * Returns both the stylesheet and whether the current inputs have settled
659
+ * Returns what the page yielded and whether the current inputs have settled
644
660
  * once. Callers must gate fallback tiers on `settled`, not on `css === ''`:
645
661
  * the empty string is the initial state AND the definitive "nothing probable"
646
662
  * outcome, and treating them the same paints the derived tier then restyles
647
663
  * when the probe lands.
648
664
  *
649
- * 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
650
666
  * and `settled` stays true until the new result arrives, so fallback tiers
651
667
  * do not flash back in.
652
668
  */
653
669
  export function useProbedHostStyles(
654
670
  routeUrl: string | undefined,
655
671
  wrapperClass: string | null,
656
- options: { theme?: 'light' | 'dark' | null; routeCss?: string } = {},
657
- ): { css: string; settled: boolean } {
658
- 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);
659
675
  const [settled, setSettled] = useState(false);
660
- // 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
661
677
  // would stale-close over the mount value and mis-handle re-probes.
662
- const cssRef = useRef(css);
678
+ const cssRef = useRef(probe.css);
663
679
  const theme = options.theme ?? null;
664
- 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;
665
684
 
666
685
  useEffect(() => {
667
- const source: ProbeSource | null = routeCss
668
- ? { srcdoc: buildProbeReconstruction(routeCss, wrapperClass) }
669
- : routeUrl
670
- ? { url: routeUrl }
671
- : null;
672
- if (!source) {
686
+ if (!pageUrl) {
673
687
  cssRef.current = '';
674
- setCss('');
688
+ setProbe(EMPTY_PROBE);
675
689
  setSettled(true);
676
690
  return;
677
691
  }
@@ -684,17 +698,17 @@ export function useProbedHostStyles(
684
698
  }
685
699
 
686
700
  const controller = new AbortController();
687
- probeHostStyles(source, wrapperClass, theme, controller.signal).then((result) => {
701
+ void probeHostStyles(pageUrl, wrapperClass, theme, discover, controller.signal).then((result) => {
688
702
  if (controller.signal.aborted) return;
689
- cssRef.current = result;
690
- setCss(result);
703
+ cssRef.current = result.css;
704
+ setProbe((prev) => keepUnchanged(prev, result));
691
705
  setSettled(true);
692
706
  });
693
707
 
694
708
  return () => {
695
709
  controller.abort();
696
710
  };
697
- }, [routeUrl, routeCss, wrapperClass, theme]);
711
+ }, [pageUrl, wrapperClass, theme, discover]);
698
712
 
699
- return { css, settled };
713
+ return { ...probe, settled };
700
714
  }
package/src/index.ts CHANGED
@@ -21,13 +21,20 @@ 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';
29
+ export { buildUploadFormData } from './hooks/useUpload.js';
30
+ // Shrinks and checks an image before upload; the editor's parent page runs it on every upload it forwards
31
+ export { prepareImageUpload, prepareUploadForm } from './media/prepare-image-upload.js';
26
32
  // Export configuration function
27
33
  export {
28
34
  configureUI,
29
35
  type EditorWriteAccess,
30
36
  type EditorWriteRefusal,
37
+ type MemoryRouterConfig,
31
38
  type OpenPreviewResult,
32
39
  type PreviewCapability,
33
40
  setDataBindings,
@@ -38,5 +45,6 @@ export {
38
45
  type TemplateConfig,
39
46
  type UIConfig,
40
47
  } from './ui-config.js';
41
- // Export the read-only enforcement a host installs through `setEditorReadOnly`
42
- export { ContentWriteRefusedError, editorWriteAccess } from './write-access.js';
48
+ // Export the read-only enforcement a host installs through `setEditorReadOnly`, and the guard a parent frame wraps
49
+ // its own content client in
50
+ 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
@@ -0,0 +1,118 @@
1
+ import {
2
+ DEFAULT_ACCEPTED_FORMATS,
3
+ IMAGE_EXTENSION_MIME,
4
+ JPEG_FALLBACK_QUALITY,
5
+ MAX_IMAGE_EDGE,
6
+ tooLargeRefusal,
7
+ unreadableImageRefusal,
8
+ unsupportedTypeRefusal,
9
+ VIDEO_EXTENSIONS,
10
+ videoRefusal,
11
+ WEBP_QUALITY,
12
+ } from '@conloca/content-api-client';
13
+
14
+ /**
15
+ * The browser's half of the upload rules: a photo over 2560 px is shrunk, upright, and a file the site will not
16
+ * store is refused before any byte is sent. The editor runs it, and the editor's parent page runs it again for
17
+ * editor bundles built before it existed.
18
+ */
19
+
20
+ type OutputType = 'image/webp' | 'image/jpeg' | 'image/png';
21
+
22
+ const OUTPUT_EXTENSION = { 'image/webp': 'webp', 'image/jpeg': 'jpg', 'image/png': 'png' } satisfies Record<
23
+ OutputType,
24
+ string
25
+ >;
26
+
27
+ /** Formats a canvas decodes and re-encodes; GIF, SVG and ICO are sent as they are. */
28
+ const SHRINKABLE: ReadonlySet<string> = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/avif']);
29
+
30
+ /** The size that fits `width`×`height` within `maxEdge` on its long edge, or `null` when it already fits. */
31
+ export function fitWithin(width: number, height: number, maxEdge: number): { width: number; height: number } | null {
32
+ const longEdge = Math.max(width, height);
33
+ if (longEdge <= maxEdge) return null;
34
+ const scale = maxEdge / longEdge;
35
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
36
+ }
37
+
38
+ /** `name` with its extension replaced by the one `outputType` is stored under. */
39
+ export function processedName(name: string, outputType: OutputType): string {
40
+ const dot = name.lastIndexOf('.');
41
+ return `${dot > 0 ? name.slice(0, dot) : name}.${OUTPUT_EXTENSION[outputType]}`;
42
+ }
43
+
44
+ function extensionOf(name: string): string {
45
+ const dot = name.lastIndexOf('.');
46
+ return dot < 0 ? '' : name.slice(dot + 1).toLowerCase();
47
+ }
48
+
49
+ /** The file to upload in place of `file`, shrunk when it is a photo over the edge; throws the refusal sentence. */
50
+ export async function prepareImageUpload(file: File, maxBytes: number): Promise<File> {
51
+ const extension = extensionOf(file.name);
52
+ if (VIDEO_EXTENSIONS.has(extension) || file.type.startsWith('video/')) throw new Error(videoRefusal(file.name));
53
+ const type = IMAGE_EXTENSION_MIME[extension];
54
+ if (type === undefined) throw new Error(unsupportedTypeRefusal(file.name, DEFAULT_ACCEPTED_FORMATS));
55
+ const prepared = SHRINKABLE.has(type) ? await shrink(file, type) : file;
56
+ if (prepared.size > maxBytes) throw new Error(tooLargeRefusal(file.name, prepared.size, maxBytes));
57
+ return prepared;
58
+ }
59
+
60
+ /** `form` with its `file` prepared by {@link prepareImageUpload}; `alt` and `folder` are kept. */
61
+ export async function prepareUploadForm(form: FormData, maxBytes: number): Promise<FormData> {
62
+ const file = form.get('file');
63
+ // The server refuses a form without a file in its own words.
64
+ if (!(file instanceof File)) return form;
65
+ const prepared = await prepareImageUpload(file, maxBytes);
66
+ const next = new FormData();
67
+ for (const [key, value] of form) next.append(key, key === 'file' ? prepared : value);
68
+ return next;
69
+ }
70
+
71
+ async function shrink(file: File, type: string): Promise<File> {
72
+ const bitmap = await decode(file);
73
+ if (!bitmap) throw new Error(unreadableImageRefusal(file.name));
74
+ try {
75
+ const size = fitWithin(bitmap.width, bitmap.height, MAX_IMAGE_EDGE);
76
+ if (!size) return file;
77
+ // Never larger than 2560×2560: inside the canvas area iOS allows.
78
+ const canvas = document.createElement('canvas');
79
+ canvas.width = size.width;
80
+ canvas.height = size.height;
81
+ const context = canvas.getContext('2d');
82
+ if (!context) throw new Error(unreadableImageRefusal(file.name));
83
+ context.imageSmoothingQuality = 'high';
84
+ context.drawImage(bitmap, 0, 0, size.width, size.height);
85
+ const encoded = await encode(canvas, type === 'image/png', file.name);
86
+ return new File([encoded.blob], processedName(file.name, encoded.type), { type: encoded.type });
87
+ } finally {
88
+ bitmap.close();
89
+ }
90
+ }
91
+
92
+ /** The decoded image, upright, or `null` when the bytes are not one the browser can read. */
93
+ async function decode(file: File): Promise<ImageBitmap | null> {
94
+ try {
95
+ return await createImageBitmap(file, { imageOrientation: 'from-image' });
96
+ } catch (error) {
97
+ // Older engines reject the options with a TypeError; they apply the EXIF orientation by default.
98
+ return error instanceof TypeError ? createImageBitmap(file).catch(() => null) : null;
99
+ }
100
+ }
101
+
102
+ async function encode(
103
+ canvas: HTMLCanvasElement,
104
+ png: boolean,
105
+ name: string,
106
+ ): Promise<{ blob: Blob; type: OutputType }> {
107
+ if (png) return { blob: await toBlob(canvas, 'image/png', undefined, name), type: 'image/png' };
108
+ const webp = await toBlob(canvas, 'image/webp', WEBP_QUALITY, name);
109
+ if (webp.type === 'image/webp') return { blob: webp, type: 'image/webp' };
110
+ // Safari cannot encode WebP and answers PNG instead.
111
+ return { blob: await toBlob(canvas, 'image/jpeg', JPEG_FALLBACK_QUALITY, name), type: 'image/jpeg' };
112
+ }
113
+
114
+ function toBlob(canvas: HTMLCanvasElement, type: OutputType, quality: number | undefined, name: string): Promise<Blob> {
115
+ return new Promise((resolve, reject) =>
116
+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error(unreadableImageRefusal(name)))), type, quality),
117
+ );
118
+ }
@@ -0,0 +1,22 @@
1
+ import type { AssetEntry } from '@conloca/content-api-client';
2
+ import { mediaSourceOf } from '../components/editor/draft-media-config.js';
3
+ import { useMediaObjectUrl } from '../frame/media-cache.js';
4
+ import type { MediaLoadInput } from '../frame/protocol.js';
5
+ import { getUIConfig } from '../ui-config.js';
6
+ import { assetPath, buildAssetServeUrl } from '../utils/asset-url.js';
7
+
8
+ /**
9
+ * The `src` of an asset thumbnail: with a loader, an object URL of the bytes its link names (an image in the site's
10
+ * folder loads from there, anything else from its upload address); without one, the serve URL.
11
+ */
12
+ export function useAssetServeSrc(
13
+ assetsBasePath: string,
14
+ asset: Pick<AssetEntry, 'folder' | 'filename' | 'ref'>,
15
+ ): string | undefined {
16
+ const source: MediaLoadInput = (asset.ref === undefined ? undefined : mediaSourceOf(asset.ref)) ?? {
17
+ route: 'serve',
18
+ path: assetPath(asset.folder, asset.filename),
19
+ };
20
+ const loaded = useMediaObjectUrl(source.route, source.path);
21
+ return getUIConfig().loadMedia ? loaded : buildAssetServeUrl(assetsBasePath, asset.folder, asset.filename);
22
+ }
@@ -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