@conloca/astro-cms 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -22
- package/dist/internal/PageRoot.astro +10 -0
- package/dist/internal/page-handler.astro +46 -13
- package/dist/internal/preview-page-handler.astro +359 -0
- package/dist/ts/.build-inputs.json +20 -15
- package/dist/ts/src/build/check-fragment-components.d.ts +18 -0
- package/dist/ts/src/build/check-fragment-components.d.ts.map +1 -0
- package/dist/ts/src/build/check-fragment-components.js +70 -0
- package/dist/ts/src/build/check-fragment-components.js.map +1 -0
- package/dist/ts/src/build/fragment-manifest.d.ts +35 -0
- package/dist/ts/src/build/fragment-manifest.d.ts.map +1 -0
- package/dist/ts/src/build/fragment-manifest.js +138 -0
- package/dist/ts/src/build/fragment-manifest.js.map +1 -0
- package/dist/ts/src/build/fragment-render-load.d.ts +17 -0
- package/dist/ts/src/build/fragment-render-load.d.ts.map +1 -0
- package/dist/ts/src/build/fragment-render-load.js +51 -0
- package/dist/ts/src/build/fragment-render-load.js.map +1 -0
- package/dist/ts/src/cms-handler.d.ts +6 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -1
- package/dist/ts/src/cms-handler.js +3 -5
- package/dist/ts/src/cms-handler.js.map +1 -1
- package/dist/ts/src/components/FragmentIsland.d.ts +17 -0
- package/dist/ts/src/components/FragmentIsland.d.ts.map +1 -0
- package/dist/ts/src/components/FragmentIsland.js +78 -0
- package/dist/ts/src/components/FragmentIsland.js.map +1 -0
- package/dist/ts/src/components/IslandSlot.d.ts +14 -0
- package/dist/ts/src/components/IslandSlot.d.ts.map +1 -0
- package/dist/ts/src/components/IslandSlot.js +19 -0
- package/dist/ts/src/components/IslandSlot.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +3 -1
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -1
- package/dist/ts/src/components/RenderWithFragments.js +1 -1
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -1
- package/dist/ts/src/discovery/merge-registry.js +6 -2
- package/dist/ts/src/discovery/merge-registry.js.map +1 -1
- package/dist/ts/src/editor-descriptors.d.ts +4 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -1
- package/dist/ts/src/editor-descriptors.js +11 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -1
- package/dist/ts/src/handlers/collection-content-api.d.ts +3 -1
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -1
- package/dist/ts/src/handlers/collection-content-api.js +13 -2
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -1
- package/dist/ts/src/handlers/page-render-core.d.ts +36 -7
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -1
- package/dist/ts/src/handlers/page-render-core.js +97 -18
- package/dist/ts/src/handlers/page-render-core.js.map +1 -1
- package/dist/ts/src/lib/hydration-scanner.d.ts +21 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -1
- package/dist/ts/src/lib/hydration-scanner.js +50 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -1
- package/dist/ts/src/lib/hydration-script.d.ts +13 -5
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -1
- package/dist/ts/src/lib/hydration-script.js +74 -36
- package/dist/ts/src/lib/hydration-script.js.map +1 -1
- package/dist/ts/src/lib/routing-config.d.ts +1 -1
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -1
- package/dist/ts/src/lib/routing-config.js +5 -2
- package/dist/ts/src/lib/routing-config.js.map +1 -1
- package/dist/ts/src/lib/unknown-components.d.ts +1 -2
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -1
- package/dist/ts/src/lib/virtual-module-generators.d.ts +37 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -1
- package/dist/ts/src/lib/virtual-module-generators.js +86 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -1
- package/dist/ts/src/plugin-spa.d.ts +24 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -1
- package/dist/ts/src/plugin-spa.js +136 -69
- package/dist/ts/src/plugin-spa.js.map +1 -1
- package/dist/ts/src/puck-manifest/types.d.ts +4 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -1
- package/dist/ts/src/types.d.ts +14 -2
- package/dist/ts/src/types.d.ts.map +1 -1
- package/dist/virtual-modules.d.ts +26 -0
- package/package.json +10 -4
- package/src/build/check-fragment-components.ts +82 -0
- package/src/build/fragment-manifest.ts +163 -0
- package/src/build/fragment-render-load.ts +64 -0
- package/src/cms-handler.ts +3 -6
- package/src/components/FragmentIsland.tsx +97 -0
- package/src/components/IslandSlot.tsx +28 -0
- package/src/components/PageRoot.astro +10 -0
- package/src/components/RenderWithFragments.tsx +4 -1
- package/src/discovery/merge-registry.ts +8 -3
- package/src/editor-descriptors.ts +17 -0
- package/src/handlers/collection-content-api.ts +15 -2
- package/src/handlers/page-handler.astro +46 -13
- package/src/handlers/page-render-core.ts +132 -21
- package/src/lib/hydration-scanner.ts +65 -0
- package/src/lib/hydration-script.ts +83 -40
- package/src/lib/routing-config.ts +7 -3
- package/src/lib/unknown-components.ts +1 -1
- package/src/lib/virtual-module-generators.ts +106 -0
- package/src/plugin-spa.ts +182 -76
- package/src/puck-manifest/types.ts +8 -0
- package/src/types.ts +15 -1
- package/src/virtual-modules.d.ts +26 -0
package/README.md
CHANGED
|
@@ -178,31 +178,42 @@ const { title, description } = Astro.props;
|
|
|
178
178
|
Supplying `layout` and nothing else turns on a catch-all `/[...slug]` route over the `pages` collection with a `404`
|
|
179
179
|
fallback. Sites that need more than one route drop `layout` and use `routing.routes.<name>.layout` instead.
|
|
180
180
|
|
|
181
|
+
A route may also name an `editorFrame`: a module whose default export is a React component
|
|
182
|
+
`({ pathname, children }) => ReactNode` that renders the markup the route's layout puts around page content, for example
|
|
183
|
+
`<div className="page-shell">{children}</div>`. The editor canvas shows each page of that route inside it, so blocks
|
|
184
|
+
look as they do on the site. Publish ignores the frame apart from one thing: every published page of that route wraps
|
|
185
|
+
its content in `<div data-conloca-page-root="">`, which marks where page content starts. Routes without a frame are
|
|
186
|
+
unchanged, byte for byte. Selectors in the layout's CSS that target page content as a direct child (`main > section`)
|
|
187
|
+
may need adjusting on framed routes. Fragments render inline inside the frame with the site's own components, so prose
|
|
188
|
+
in the canvas sits in the same wrappers as on the page; `conloca doctor --live` (CC30) warns when a published page's
|
|
189
|
+
wrappers drift from its frame.
|
|
190
|
+
|
|
181
191
|
With those four files in place, run the Astro dev server and open `/__cms`.
|
|
182
192
|
|
|
183
193
|
### Options
|
|
184
194
|
|
|
185
195
|
Passed to `conlocaCMS({ ... })`. Only two are required.
|
|
186
196
|
|
|
187
|
-
| Option
|
|
188
|
-
|
|
|
189
|
-
| `contentRoot`
|
|
190
|
-
| `puckConfigPath`
|
|
191
|
-
| `canvasDir`
|
|
192
|
-
| `route`
|
|
193
|
-
| `layout`
|
|
194
|
-
| `routing`
|
|
195
|
-
| `templates`
|
|
196
|
-
| `schemasPath`
|
|
197
|
-
| `contentSchemasPath`
|
|
198
|
-
| `componentPaths`
|
|
199
|
-
| `mdxComponentFolders`
|
|
200
|
-
| `assetsPath`
|
|
201
|
-
| `siteStyles`
|
|
202
|
-
| `editorStyles`
|
|
203
|
-
| `editorCSS`
|
|
204
|
-
| `fragmentPreviewRoute`
|
|
205
|
-
| `
|
|
197
|
+
| Option | Required | What it does |
|
|
198
|
+
| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
199
|
+
| `contentRoot` | yes | Directory holding `sites.json` and the content files. Also handed to the collection factories, so the content config needs no copy of it. |
|
|
200
|
+
| `puckConfigPath` | yes | Module whose default export is the Puck `Config`. Supplies the visual editor's component palette and seeds component auto-discovery. |
|
|
201
|
+
| `canvasDir` | no | Directory for canvas documents. |
|
|
202
|
+
| `route` | no | Where the CMS mounts. Defaults to `/__cms`. |
|
|
203
|
+
| `layout` | no | Default layout for content pages. On its own it enables routing with a catch-all pattern. |
|
|
204
|
+
| `routing` | no | Full routing configuration, for sites with more than one content route. |
|
|
205
|
+
| `templates` | no | Page templates offered in the create-page dialog. |
|
|
206
|
+
| `schemasPath` | no | Module exporting `dataSchemas`, `pageSchemas` and `mdxComponents`. Drives the page-settings form and the MDX component registry. |
|
|
207
|
+
| `contentSchemasPath` | no | Schema-only module exporting the `pageSchemas` / `dataSchemas` your content config passes to `conlocaPages()` / `conlocaData()`. Draft previews parse entries with the entry parsers built from it, as the build does. |
|
|
208
|
+
| `componentPaths` | no | Extra folders to scan for components wrapped in `withHydration()`. |
|
|
209
|
+
| `mdxComponentFolders` | no | Folders scanned for locally authored MDX components, whose `interface Props` becomes the editor's prop panel. Defaults to `['src/components/mdx']`. |
|
|
210
|
+
| `assetsPath` | no | Upload directory; enables the Media Library. The site must serve it from `publicDir`, directly or through a link there, or dev and build fail. |
|
|
211
|
+
| `siteStyles` | no | CSS injected into the Puck preview iframe so components render with site styling. |
|
|
212
|
+
| `editorStyles` | no | CSS injected into the MDX editor's admin document. Host-component selectors only — see the file's own notes on what does not belong. |
|
|
213
|
+
| `editorCSS` | no | Raw CSS applied after auto-discovered host styles in the editor's host-preview layer. |
|
|
214
|
+
| `fragmentPreviewRoute` | no | Route whose styles and content wrapper frame the standalone fragment editor, and the `pathname` the fragment live preview's editor frame receives, in dev and in the built editor. Defaults to `/`. |
|
|
215
|
+
| `fragmentComponentsPath` | no | Module exporting `fragmentComponents = defineFragmentComponents(...)`: the components and element overrides fragments may use. See [Fragment components](#fragment-components). |
|
|
216
|
+
| `locales` | no | The site's locales and default locale. Without it: the site's `locales` and `defaultLocale` in `sites.json`, else `globalLocales`. |
|
|
206
217
|
|
|
207
218
|
`ConlocaCMSOptions` also extends the editor's `UIConfig` (minus `basename`), so fields such as `apiBaseUrl`,
|
|
208
219
|
`siteBaseUrl`, `enableDevtools`, `queryClientOptions`, `projectRoot` and `hosted` are accepted as well. Those exist for
|
|
@@ -282,6 +293,141 @@ editing a page never moves it; `'date-asc'` and `'title'` are the others; pages
|
|
|
282
293
|
and `locale` to read another language. It reads the pages of the content routes `conlocaCMS()` serves, so it needs
|
|
283
294
|
`layout` or `routing` set there and throws when neither is.
|
|
284
295
|
|
|
296
|
+
## Fragment components
|
|
297
|
+
|
|
298
|
+
Fragments can use the site's own React components and restyle the HTML their Markdown produces. The site declares both
|
|
299
|
+
in a render module and names it with `fragmentComponentsPath`:
|
|
300
|
+
|
|
301
|
+
```tsx
|
|
302
|
+
// src/fragment-components.tsx
|
|
303
|
+
import { defineFragmentComponents } from '@conloca/mdx/render';
|
|
304
|
+
import { Callout } from './components/Callout';
|
|
305
|
+
import { SectionHeading } from './components/SectionHeading';
|
|
306
|
+
|
|
307
|
+
export const fragmentComponents = defineFragmentComponents({
|
|
308
|
+
components: { Callout },
|
|
309
|
+
elements: { h2: SectionHeading },
|
|
310
|
+
});
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
// astro.config.mjs
|
|
315
|
+
conlocaCMS({
|
|
316
|
+
contentRoot: './content',
|
|
317
|
+
puckConfigPath: './src/puck.config.tsx',
|
|
318
|
+
fragmentComponentsPath: './src/fragment-components.tsx',
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Published pages, draft previews, the editor canvas and the fragment editor's live preview all render fragments from this
|
|
323
|
+
module, with `evaluateMDXToComponent` from `@conloca/mdx/render`. That is why it is its own module and not part of
|
|
324
|
+
`schemasPath`: it loads in the server runtime that renders pages, which may forbid code generation from strings, so it
|
|
325
|
+
must import no editor code. `schemasPath` holds the editor's descriptors and may import editor code. The rules for
|
|
326
|
+
components, element overrides and JSON props are in the `@conloca/mdx` README.
|
|
327
|
+
|
|
328
|
+
In the fragment editor:
|
|
329
|
+
|
|
330
|
+
- **Descriptors join by name.** The editor offers the vocabulary's components only, and uses the `mdxComponents`
|
|
331
|
+
descriptor of the same name (from `schemasPath`, see below) for its label, insert hint and props. A descriptor with no
|
|
332
|
+
vocabulary component stays available on MDX pages only. A vocabulary component without a descriptor is still offered,
|
|
333
|
+
with no settings fields, and is inserted without a body; declare a descriptor with `hasChildren: true` to give it an
|
|
334
|
+
editable body.
|
|
335
|
+
- **No custom editors.** A descriptor's custom `Editor` is not used in fragments: the editor renders the site's
|
|
336
|
+
component itself, with the settings panel for props.
|
|
337
|
+
- **List and object props.** A descriptor prop may be `{ type: 'list', of: … }` or `{ type: 'object', fields: … }`.
|
|
338
|
+
Authors edit them in the settings panel, never as JSON, and the editor writes them as JSON attribute values.
|
|
339
|
+
`defineMdxComponents` warns when a string, number or boolean default does not match its type, and throws for a list or
|
|
340
|
+
object prop with no `of` or `fields`, or a default of the wrong shape.
|
|
341
|
+
- **Block types.** A descriptor with `blockType: true` (it needs `kind: 'flow'` and `hasChildren: true`) is a text
|
|
342
|
+
style, such as an eyebrow: its body is one line of text. The toolbar's Block type dropdown lists it after Paragraph,
|
|
343
|
+
Quote and the headings, and shows it while the caret is inside one. Choosing it turns the selected lines into the
|
|
344
|
+
component, each holding its line; choosing Paragraph, Quote or a heading turns the component's lines back. Every
|
|
345
|
+
component, block type or not, stays in the `/` menu and Insert component.
|
|
346
|
+
- **Hidden props.** A top-level prop with `hidden: true` is kept out of the settings panel; its value is kept as
|
|
347
|
+
written.
|
|
348
|
+
- **Outline anchors.** For a component the render module declares as an `outline` entry (see Component outline below),
|
|
349
|
+
the editor fills in the anchor prop from the contents text when the author sets the text and the component has no
|
|
350
|
+
anchor yet. It never changes an anchor that exists, so links to it keep working when the text changes. Pair it with
|
|
351
|
+
`hidden: true` on the anchor prop so authors only write the contents text.
|
|
352
|
+
- **The save check.** The editor refuses to save a fragment the renderer would refuse or change: a parse failure,
|
|
353
|
+
`import`/`export` lines, `{…}` expressions, a component the vocabulary lacks, a prop value that is not valid JSON, a
|
|
354
|
+
`{...spread}` or code in an attribute, or a declared prop of the wrong type. The message names the component or line;
|
|
355
|
+
for a component the vocabulary lacks, it also lists the vocabulary. The text stays in the editor, unsaved. An editor
|
|
356
|
+
that syncs as you type holds such an edit unsent, shows `Not saved:` with the message, and asks before leaving; it
|
|
357
|
+
syncs once fixed or undone. A body that already failed the check when it arrived is not held, so it can still be
|
|
358
|
+
fixed. A component prop value that is not valid JSON is never published.
|
|
359
|
+
- **The live preview** renders the fragment in the editor frame of the first routing entry, in declaration order, that
|
|
360
|
+
declares an `editorFrame`, with `fragmentPreviewRoute` as its `pathname`. With no framed route there is no frame. To
|
|
361
|
+
use another frame, reorder the routes or point `fragmentPreviewRoute` at a path the frame recognizes.
|
|
362
|
+
- **Outline.** The page outline comes from the fragment's Markdown headings, including those written between a
|
|
363
|
+
component's tags; a heading the component itself renders is not in the outline.
|
|
364
|
+
- **Component outline.** Components the render module declares as contents entries, with
|
|
365
|
+
`defineFragmentComponents({ components: { Section }, outline: { Section: { id: 'id', text: 'label' } } })`, reach your
|
|
366
|
+
`ContentFragmentSection` block as `fragmentComponentOutline` (`{ component, id, text }` in document order), next to
|
|
367
|
+
the heading list in `fragmentOutline`. The published page, draft previews and the editor canvas hand the block the
|
|
368
|
+
same lists, so a contents column built from either matches on every surface.
|
|
369
|
+
|
|
370
|
+
The build fails when a live fragment (published, or scheduled and not expired) fails to parse or uses a component the
|
|
371
|
+
render module does not declare, naming the fragment, its file and line, and the component. When the module cannot be
|
|
372
|
+
loaded outside Astro's pipeline, the build only warns and skips the name check.
|
|
373
|
+
|
|
374
|
+
Author-written `style` is dropped from every element and component in fragments, raw HTML included; the column alignment
|
|
375
|
+
the renderer gives Markdown tables is kept. Props and attributes whose names start with `on`, in any case, are never
|
|
376
|
+
passed; rename them.
|
|
377
|
+
|
|
378
|
+
A component that renders a prop as HTML (`dangerouslySetInnerHTML`) turns author text into markup, in the editor page
|
|
379
|
+
and on the published site. That is the site's code choice; render props as text unless the markup is trusted.
|
|
380
|
+
|
|
381
|
+
Inside an object or list prop, a key starting with `on`, in any case, is dropped at any depth when its value is text, so
|
|
382
|
+
a component that spreads the object onto an element never publishes an author's handler; `{"online": true}` is kept. The
|
|
383
|
+
save check refuses such a key, naming its path.
|
|
384
|
+
|
|
385
|
+
Discovered components can be adjusted with `src/cms-overrides`, but an override cannot declare list or object props;
|
|
386
|
+
declare those in `mdxComponents`.
|
|
387
|
+
|
|
388
|
+
### Interactive fragment components
|
|
389
|
+
|
|
390
|
+
Fragment components are static HTML by default. To make one interactive on published pages, wrap it with `withHydration`
|
|
391
|
+
from `@conloca/astro-cms/hydration` and pick a strategy: `'load'` (on page load), `'visible'` (when it scrolls into
|
|
392
|
+
view) or `'idle'` (when the browser is idle).
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
// src/fragments/Disclosure.tsx
|
|
396
|
+
import { withHydration } from '@conloca/astro-cms/hydration';
|
|
397
|
+
|
|
398
|
+
export const Disclosure = withHydration(DisclosureView, 'load');
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
```tsx
|
|
402
|
+
// the render module
|
|
403
|
+
import { defineFragmentComponents } from '@conloca/mdx/render';
|
|
404
|
+
import { Disclosure } from './fragments/Disclosure';
|
|
405
|
+
|
|
406
|
+
export const fragmentComponents = defineFragmentComponents({ components: { Disclosure } });
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
- **One file per hydrated component.** Put each hydrated component in its own file that calls `withHydration`, and
|
|
410
|
+
import it into the render module by name. A page then downloads only the chunks of the islands it uses; two hydrated
|
|
411
|
+
components in one file share a chunk. One defined in the render module, or re-exported through another file, has no
|
|
412
|
+
module the build can map. `astro build` then fails, whatever the output mode, with
|
|
413
|
+
`Fragment component <Name> is wrapped in withHydration(), but the build found no module for it. Import it into the render module by name from the file that calls withHydration().`
|
|
414
|
+
That build check needs to load the render module outside Astro's pipeline; when it cannot, the build only warns that
|
|
415
|
+
the mapping was not checked. Prerendering, `astro dev` and draft previews throw the same error when they render
|
|
416
|
+
fragments; a live on-demand page logs it once and renders that component without hydration, with every other fragment
|
|
417
|
+
and island intact.
|
|
418
|
+
- **Props are JSON.** The component receives the props the server render passed, after the rules above (JSON, or the
|
|
419
|
+
object-literal form `staticDataValue` also accepts).
|
|
420
|
+
- **Children are the page's server HTML.** The browser re-uses the HTML the page already contains for the component's
|
|
421
|
+
children; state inside them is not React state. An island nested in them hydrates on its own; after the outer island
|
|
422
|
+
remounts its children, the nested one stays static.
|
|
423
|
+
- **Element overrides cannot hydrate.** Wrapping one throws
|
|
424
|
+
`Element override <a> is wrapped in withHydration(); only fragment components can hydrate.`
|
|
425
|
+
- **Outline.** A hydrated component can be an `outline` entry; it still appears in the contents.
|
|
426
|
+
- **No island, no script.** A page with no island ships no hydration script.
|
|
427
|
+
- **Wrappers.** The `conloca-island` and `conloca-island-slot` wrappers are `display:contents`, so direct-child
|
|
428
|
+
selectors across them stop matching.
|
|
429
|
+
- **In the editor** the component is live immediately and its strategy is ignored.
|
|
430
|
+
|
|
285
431
|
## MDX component registry
|
|
286
432
|
|
|
287
433
|
Hosts can register JSX components (their own, or third-party ones like Starlight's `<Steps>`, `<Tabs>`, `<Card>`) with
|
|
@@ -319,9 +465,10 @@ In the editor, registered components appear in two places:
|
|
|
319
465
|
|
|
320
466
|
### Auto-import injection (and its pruning caveat)
|
|
321
467
|
|
|
322
|
-
Setting `import: { from: '<module>' }` on a descriptor opts the component into automatic import injection
|
|
323
|
-
component appears in the document, the CMS save serializer emits the matching
|
|
324
|
-
the top of the file (after frontmatter).
|
|
468
|
+
Setting `import: { from: '<module>' }` on a descriptor opts the component into automatic import injection on MDX pages:
|
|
469
|
+
whenever the component appears in the document, the CMS save serializer emits the matching
|
|
470
|
+
`import { Name } from '<module>'` line at the top of the file (after frontmatter). Fragments never get an `import` line:
|
|
471
|
+
their components come from the render module, and the editor refuses to save a fragment with one.
|
|
325
472
|
|
|
326
473
|
**Important: the editor rebuilds the import block on every save from components actually referenced in the tree.**
|
|
327
474
|
Imports for unused components are dropped. So are non-JSX imports — type imports, side-effect imports
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** Wraps page content in the marker the editor frame's drift check stops at, on routes that declare an `editorFrame`. */
|
|
3
|
+
interface Props {
|
|
4
|
+
framed: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const { framed } = Astro.props;
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
{framed ? <div data-conloca-page-root=""><slot /></div> : <slot />}
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
import { getCollection } from 'astro:content';
|
|
13
13
|
import { loadContentSchemas } from 'virtual:conloca-content-schemas';
|
|
14
|
+
import {
|
|
15
|
+
fragmentComponentsPath,
|
|
16
|
+
fragmentIslandLoaders,
|
|
17
|
+
loadFragmentComponents,
|
|
18
|
+
} from 'virtual:conloca-fragment-components';
|
|
14
19
|
import Layout from 'virtual:conloca-layout';
|
|
15
20
|
import puckConfig from 'virtual:conloca-puck-config';
|
|
16
21
|
import routingConfig from 'virtual:conloca-routing-config';
|
|
@@ -30,15 +35,19 @@ import {
|
|
|
30
35
|
createReaderContentSource,
|
|
31
36
|
findUnknownComponentTypes,
|
|
32
37
|
getPageEntries,
|
|
38
|
+
loadFragmentVocabulary,
|
|
33
39
|
loadMdxComponents,
|
|
40
|
+
type MdxFragmentComponent,
|
|
34
41
|
normalizePathname,
|
|
35
42
|
type PageContentSource,
|
|
36
43
|
type PageEntryData,
|
|
37
44
|
type PageEntryRecord,
|
|
45
|
+
pageHasFragmentIslands,
|
|
38
46
|
pageNotFoundResponse,
|
|
39
47
|
resolvePuckData,
|
|
40
48
|
} from '../ts/src/handlers/page-render-core.js';
|
|
41
49
|
import { previewEntryParsers } from '../ts/src/internal/collection-parsers.js';
|
|
50
|
+
import PageRoot from './PageRoot.astro';
|
|
42
51
|
|
|
43
52
|
// prerender is controlled by injectRoute({ prerender }) in plugin-spa.ts
|
|
44
53
|
// Do not hardcode here — it overrides the route-level config
|
|
@@ -210,6 +219,9 @@ try {
|
|
|
210
219
|
throw error;
|
|
211
220
|
}
|
|
212
221
|
|
|
222
|
+
// A route with an editor frame marks where page content starts, which the canvas drift check stops at.
|
|
223
|
+
const framed = page !== undefined && config.routes[routeName]?.editorFrame !== undefined;
|
|
224
|
+
|
|
213
225
|
const dataContext = await buildDataContext(source, config.routes[routeName], config, matchedPage);
|
|
214
226
|
|
|
215
227
|
const hasPuckData = !!page?.puckData && Object.keys(page.puckData).length > 0;
|
|
@@ -230,28 +242,46 @@ if (hasPuckData && resolvedPuckData) {
|
|
|
230
242
|
}
|
|
231
243
|
}
|
|
232
244
|
|
|
233
|
-
const needsHydration = hasPuckData && resolvedPuckData && hasHydratableComponents(resolvedPuckData, puckConfig);
|
|
234
|
-
|
|
235
245
|
let PageRenderer: ComponentType | undefined;
|
|
246
|
+
let mdxComponents: MdxFragmentComponent[] = [];
|
|
236
247
|
|
|
237
248
|
if (hasPuckData && page && resolvedPuckData) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
+
const showErrors = import.meta.env.DEV || previewContentApi !== undefined;
|
|
250
|
+
// A broken render module fails the static build and shows in previews, but must not take down a live SSR site.
|
|
251
|
+
const fragmentVocabulary = await loadFragmentVocabulary(
|
|
252
|
+
loadFragmentComponents,
|
|
253
|
+
Astro.isPrerendered || showErrors,
|
|
254
|
+
fragmentComponentsPath,
|
|
255
|
+
fragmentIslandLoaders,
|
|
256
|
+
);
|
|
257
|
+
if (fragmentVocabulary) {
|
|
258
|
+
try {
|
|
259
|
+
mdxComponents = await loadMdxComponents(
|
|
260
|
+
source,
|
|
261
|
+
config.locale,
|
|
262
|
+
await loadEvaluateMDXToComponent(),
|
|
263
|
+
import.meta.env.DEV,
|
|
264
|
+
fragmentVocabulary,
|
|
265
|
+
showErrors,
|
|
266
|
+
);
|
|
267
|
+
PageRenderer = createPageRendererWithFragments(puckConfig, resolvedPuckData, mdxComponents, dataContext);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.error('[Conloca] MDX evaluation failed, falling back to plain render:', error);
|
|
270
|
+
PageRenderer = undefined;
|
|
271
|
+
}
|
|
249
272
|
}
|
|
250
273
|
}
|
|
274
|
+
|
|
275
|
+
const needsHydration =
|
|
276
|
+
hasPuckData &&
|
|
277
|
+
resolvedPuckData &&
|
|
278
|
+
(hasHydratableComponents(resolvedPuckData, puckConfig) ||
|
|
279
|
+
(PageRenderer !== undefined && pageHasFragmentIslands(resolvedPuckData, mdxComponents)));
|
|
251
280
|
---
|
|
252
281
|
|
|
253
282
|
{Layout && page ? (
|
|
254
283
|
<Layout title={page.title ?? 'Page'} description={page.description} page={dataContext.page}>
|
|
284
|
+
<PageRoot framed={framed}>
|
|
255
285
|
{hasPuckData && PageRenderer ? (
|
|
256
286
|
<PageRenderer />
|
|
257
287
|
) : hasPuckData && resolvedPuckData ? (
|
|
@@ -265,6 +295,7 @@ if (hasPuckData && page && resolvedPuckData) {
|
|
|
265
295
|
<p>This page has no content yet.</p>
|
|
266
296
|
</div>
|
|
267
297
|
)}
|
|
298
|
+
</PageRoot>
|
|
268
299
|
</Layout>
|
|
269
300
|
) : page ? (
|
|
270
301
|
<html lang={config.locale || 'en'}>
|
|
@@ -276,6 +307,7 @@ if (hasPuckData && page && resolvedPuckData) {
|
|
|
276
307
|
{needsHydration && <script>import 'virtual:conloca-hydration-entry'</script>}
|
|
277
308
|
</head>
|
|
278
309
|
<body>
|
|
310
|
+
<PageRoot framed={framed}>
|
|
279
311
|
{hasPuckData && PageRenderer ? (
|
|
280
312
|
<PageRenderer />
|
|
281
313
|
) : hasPuckData && resolvedPuckData ? (
|
|
@@ -289,6 +321,7 @@ if (hasPuckData && page && resolvedPuckData) {
|
|
|
289
321
|
<p>This page has no content yet.</p>
|
|
290
322
|
</div>
|
|
291
323
|
)}
|
|
324
|
+
</PageRoot>
|
|
292
325
|
</body>
|
|
293
326
|
</html>
|
|
294
327
|
) : (
|