uncial-cms 3.0.1 → 4.0.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 +111 -11
- package/dist/astro/EditorSurface.svelte +171 -0
- package/dist/astro/EditorSurface.svelte.d.ts +41 -0
- package/dist/astro/editor.d.ts +2 -0
- package/dist/astro/editor.js +2 -0
- package/dist/astro/index.d.ts +52 -0
- package/dist/astro/index.js +72 -0
- package/dist/astro/integration.d.ts +4 -0
- package/dist/astro/integration.js +15 -0
- package/dist/cli/assert-clean-astro-pages.d.ts +2 -0
- package/dist/cli/assert-clean-astro-pages.js +146 -0
- package/dist/cli/assert-clean-pages.d.ts +10 -0
- package/dist/cli/assert-clean-pages.js +2 -2
- package/dist/cli/run.js +15 -3
- package/dist/content-sources.d.ts +2 -0
- package/dist/content-sources.js +15 -0
- package/dist/github/adapter.js +17 -6
- package/dist/image-source.d.ts +17 -0
- package/dist/image-source.js +38 -0
- package/dist/index-actions.d.ts +2 -0
- package/dist/index-actions.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mount.d.ts +2 -0
- package/dist/mount.js +2 -0
- package/dist/served-url.d.ts +1 -1
- package/dist/svelte/EditorPage.svelte +8 -1
- package/dist/svelte/EditorPage.svelte.d.ts +3 -0
- package/dist/sveltekit/index.js +2 -12
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -62,6 +62,11 @@ The package also ships a `uncial-cms` command; see
|
|
|
62
62
|
- `uncial-cms/sveltekit` — build-time route factories for prerendered
|
|
63
63
|
SvelteKit sites (`createContentHandlers`, `createEditorHandlers`,
|
|
64
64
|
`createIndexHandlers`).
|
|
65
|
+
- `uncial-cms/astro` — the Astro integration (`uncialCms`) and build-time
|
|
66
|
+
route helpers for static Astro sites (`createContentRoutes`,
|
|
67
|
+
`createEditorRoutes`). See [Quick start: Astro](#quick-start-astro).
|
|
68
|
+
- `uncial-cms/astro/editor` — `EditorSurface`, the Svelte island for an Astro
|
|
69
|
+
site's editor routes.
|
|
65
70
|
- `uncial-cms/vite` — `uncialCms(siteOptions)`, the Vite plugins a site
|
|
66
71
|
installs: the development editing endpoint, and the build's forge literal.
|
|
67
72
|
- `uncial-cms/paths` — the pure path↔source mapping and the page-path
|
|
@@ -313,6 +318,89 @@ const handlers = createContentHandlers({
|
|
|
313
318
|
Pass the same resolver to `EditorPage` and to the Content page's renderer, and
|
|
314
319
|
one page path means one schema everywhere.
|
|
315
320
|
|
|
321
|
+
## Quick start: Astro
|
|
322
|
+
|
|
323
|
+
An Astro site renders content with `@astrojs/svelte` and Uncial's SSR renderer,
|
|
324
|
+
at build time and with no hydration. As with SvelteKit, the package registers
|
|
325
|
+
no routes: the site writes them and hands each its `getStaticPaths`.
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
// astro.config.mjs
|
|
329
|
+
import svelte from '@astrojs/svelte';
|
|
330
|
+
import { uncialCms } from 'uncial-cms/astro';
|
|
331
|
+
import { siteOptions } from './src/site-options.ts';
|
|
332
|
+
|
|
333
|
+
export default defineConfig({ integrations: [svelte(), uncialCms(siteOptions)] });
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The reader route is a rest route named `path`. The helpers take the plain site
|
|
337
|
+
options, not `defineSite`'s result: nothing a reader route imports may reach the
|
|
338
|
+
package root, whose editor stylesheet Astro would otherwise link into the page.
|
|
339
|
+
|
|
340
|
+
```astro
|
|
341
|
+
---
|
|
342
|
+
// src/pages/[...path].astro
|
|
343
|
+
import { Renderer } from 'uncial/render';
|
|
344
|
+
import { createContentRoutes, type ContentPage } from 'uncial-cms/astro';
|
|
345
|
+
import { blocks, schema } from '../site';
|
|
346
|
+
import { siteOptions } from '../site-options';
|
|
347
|
+
|
|
348
|
+
export function getStaticPaths() {
|
|
349
|
+
return createContentRoutes({ siteOptions, blocks, schema }).getStaticPaths();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const { document } = Astro.props as ContentPage;
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
<Renderer content={document} {blocks} {schema} />
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
`createContentRoutes` also returns `list()`, every normalized document (to
|
|
359
|
+
derive navigation from metadata, say), and `load(path)`, for a page that keeps a
|
|
360
|
+
fixed shell of its own and renders its document inside it. `exclude` and a
|
|
361
|
+
per-path `schema` work as they do for the SvelteKit handlers.
|
|
362
|
+
|
|
363
|
+
The editor route bakes only the source mapping. Blocks and schemas are not
|
|
364
|
+
serializable island props, so the site mounts `EditorSurface` from a small
|
|
365
|
+
component of its own:
|
|
366
|
+
|
|
367
|
+
```astro
|
|
368
|
+
---
|
|
369
|
+
// src/pages/[...path]/edit.astro
|
|
370
|
+
import { createEditorRoutes } from 'uncial-cms/astro';
|
|
371
|
+
import Editor from '../../Editor.svelte';
|
|
372
|
+
|
|
373
|
+
export function getStaticPaths() {
|
|
374
|
+
return createEditorRoutes({ siteOptions, blocks, schema }).getStaticPaths();
|
|
375
|
+
}
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
<Editor client:only="svelte" {...Astro.props} />
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
```svelte
|
|
382
|
+
<!-- src/Editor.svelte -->
|
|
383
|
+
<script lang="ts">
|
|
384
|
+
import { defineSite } from 'uncial-cms';
|
|
385
|
+
import { EditorSurface } from 'uncial-cms/astro/editor';
|
|
386
|
+
|
|
387
|
+
let { sourcePath, pagePath } = $props();
|
|
388
|
+
</script>
|
|
389
|
+
|
|
390
|
+
<EditorSurface site={defineSite(siteOptions)} {blocks} {schema} {sourcePath} {pagePath} />
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
`EditorSurface` forwards `extensions`, `toolbarFeatures` and
|
|
394
|
+
`toolbarExtensions` to `Editor`, for custom marks and their controls, and takes
|
|
395
|
+
a `sessionProvider`. Against the GitHub forge it shows a Sign in button first,
|
|
396
|
+
since a sign-in popup opened outside a click is blocked.
|
|
397
|
+
|
|
398
|
+
Astro bundles a `client:only` island for any page file that renders it, even
|
|
399
|
+
one whose `getStaticPaths` returns nothing. A site that wants no editor code in
|
|
400
|
+
its production build at all injects the editor route from an integration only
|
|
401
|
+
when `command === 'dev'` rather than writing it as a page file. Gate the build
|
|
402
|
+
with `uncial-cms assert-clean-pages dist --astro`.
|
|
403
|
+
|
|
316
404
|
## Local-only sites
|
|
317
405
|
|
|
318
406
|
Omitting the `github` half is the whole of the configuration for a site edited
|
|
@@ -453,7 +541,7 @@ uses:
|
|
|
453
541
|
The package ships a `bin` with two commands.
|
|
454
542
|
|
|
455
543
|
```sh
|
|
456
|
-
pnpm exec uncial-cms assert-clean-pages [buildDir] [--local-only]
|
|
544
|
+
pnpm exec uncial-cms assert-clean-pages [buildDir] [--local-only | --astro]
|
|
457
545
|
pnpm exec uncial-cms doctor --origin https://example.com [--repo owner/name]
|
|
458
546
|
```
|
|
459
547
|
|
|
@@ -462,7 +550,11 @@ pnpm exec uncial-cms doctor --origin https://example.com [--repo owner/name]
|
|
|
462
550
|
of its scripts, and checks the runtime sentinel: absent from every Content page,
|
|
463
551
|
present on every Editor variant, ignored on the Index page. With `--local-only`
|
|
464
552
|
it asserts a local-only site's build instead — no Editor variant exists, and no
|
|
465
|
-
page's closure carries the sentinel or the editor stack.
|
|
553
|
+
page's closure carries the sentinel or the editor stack. With `--astro` it reads
|
|
554
|
+
an Astro build (default `dist`): every `.html` file, the `_astro/` bundles and
|
|
555
|
+
island URLs, and dynamic imports as well as static ones, since an Astro page has
|
|
556
|
+
no router lazily importing other routes. A reader page there fails on the editor
|
|
557
|
+
stack as well as the sentinel.
|
|
466
558
|
|
|
467
559
|
**`doctor`** is the provisioning check, run before the first sign-in rather than
|
|
468
560
|
learned from it. Through the authenticated `gh` CLI it checks that the GitHub
|
|
@@ -540,9 +632,17 @@ Residual risks accepted for v1 (see the spec's §6.5 for the full treatment):
|
|
|
540
632
|
|
|
541
633
|
## Media
|
|
542
634
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
635
|
+
A Block gets image upload by declaring an attribute with `input: 'image'`:
|
|
636
|
+
`EditorPage` and `mountEditorPage` back its attributes-panel field with
|
|
637
|
+
`cmsImageSource(config, { base, staticDir })`, which fits an upload under the
|
|
638
|
+
forge limit, commits it under `mediaDir`, stores its served URL and lists the
|
|
639
|
+
media dir for Choose existing. Pass `list` and `thumbnail` to override the
|
|
640
|
+
listing and tile URLs for a rendition pipeline, or `imageSource` to replace the
|
|
641
|
+
source outright.
|
|
642
|
+
|
|
643
|
+
Underneath, single-image upload commits an image straight into the repo and
|
|
644
|
+
answers its served path. It is exposed as pure, adapter-injected functions in
|
|
645
|
+
the same family as `createPage`/`deletePage`:
|
|
546
646
|
|
|
547
647
|
```ts
|
|
548
648
|
import { uploadAsset, uploadImageAsset, servedUrl, MAX_CONTENT_BYTES } from 'uncial-cms';
|
|
@@ -555,10 +655,10 @@ const { path, sha, commitSha } = await uploadAsset(
|
|
|
555
655
|
);
|
|
556
656
|
```
|
|
557
657
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
`uncial-cms` never enters a reader page's static import graph:
|
|
658
|
+
For a custom flow (e.g. uploading a fetched video poster), use the editor
|
|
659
|
+
convenience: it resolves the adapter and author from the active editor session,
|
|
660
|
+
and reads `mediaDir` off the site object. Import it **dynamically**, inside the
|
|
661
|
+
handler, so `uncial-cms` never enters a reader page's static import graph:
|
|
562
662
|
|
|
563
663
|
```ts
|
|
564
664
|
const { servedUrl, uploadImageAsset } = await import('uncial-cms');
|
|
@@ -584,8 +684,8 @@ updateAttributes?.({ src: servedUrl(site, result.path, STATIC_DIR) });
|
|
|
584
684
|
no git-blobs-API fallback in v1. With `fit`, the re-encode happens first.
|
|
585
685
|
- **`mediaDir`** is repo-root-relative and comes from the site options; the
|
|
586
686
|
returned `path` is repo-root-relative too. Until the next redeploy the
|
|
587
|
-
committed copy is not served
|
|
588
|
-
`
|
|
687
|
+
committed copy is not served; an `input: 'image'` field bridges the gap with a
|
|
688
|
+
local `blob:` preview, and a custom flow has to do the same.
|
|
589
689
|
|
|
590
690
|
The `ForgeAdapter`'s `writeFile` accepts `string | Uint8Array`; binary content is
|
|
591
691
|
base64-encoded and PUT to the Contents API with the same message/branch/sha
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* An Astro editor route's island: Uncial's `Editor` in the host's own tree
|
|
4
|
+
* and cascade, driven by the headless editor session, with the status line,
|
|
5
|
+
* conflict banner and Save or autosave around it.
|
|
6
|
+
*
|
|
7
|
+
* Blocks, schemas and Tiptap extensions are not serializable island props,
|
|
8
|
+
* so the host mounts this from a small component of its own that imports
|
|
9
|
+
* them, with `client:only="svelte"`.
|
|
10
|
+
*/
|
|
11
|
+
import 'uncial/styles/chrome.css';
|
|
12
|
+
import { onMount, type ComponentProps } from 'svelte';
|
|
13
|
+
import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
14
|
+
import { Editor, type ToolbarFeature, type ToolbarFeatureSelection } from 'uncial/editor';
|
|
15
|
+
import type { Site } from '../define-site.js';
|
|
16
|
+
import type { EditorController, StatusView } from '../editor-controller.js';
|
|
17
|
+
import { createEditorSession } from '../editor-session.js';
|
|
18
|
+
import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
|
|
19
|
+
import type { SessionProvider } from '../types.js';
|
|
20
|
+
import { clearActiveForge } from '../upload-context.js';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
/** The site object from `defineSite`. */
|
|
24
|
+
site: Site;
|
|
25
|
+
/** Repo-root-relative JSON path, from the editor route's props. */
|
|
26
|
+
sourcePath: string;
|
|
27
|
+
/** Site-relative page path, from the editor route's props. */
|
|
28
|
+
pagePath: string;
|
|
29
|
+
blocks: BlockRegistry;
|
|
30
|
+
/** One schema for the site, or the schema this page path is written against. */
|
|
31
|
+
schema: ContentSchema | ((path: string) => ContentSchema);
|
|
32
|
+
/** Defaults to the provider the resolved forge implies. */
|
|
33
|
+
sessionProvider?: SessionProvider;
|
|
34
|
+
/** Forwarded to `Editor`: the Tiptap extensions behind custom marks. */
|
|
35
|
+
extensions?: ComponentProps<typeof Editor>['extensions'];
|
|
36
|
+
/** Forwarded to `Editor`. */
|
|
37
|
+
toolbarFeatures?: ToolbarFeatureSelection;
|
|
38
|
+
/** Forwarded to `Editor`. */
|
|
39
|
+
toolbarExtensions?: ToolbarFeature[];
|
|
40
|
+
/** Forwarded to `Editor`; `'overlay'` keeps the document at the host's width. */
|
|
41
|
+
attributesPanel?: 'docked' | 'overlay' | 'off';
|
|
42
|
+
/** Forwarded to `Editor`; `'bare'` draws no surface of the editor's own. */
|
|
43
|
+
presentation?: 'card' | 'bare';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
site,
|
|
48
|
+
sourcePath,
|
|
49
|
+
pagePath,
|
|
50
|
+
blocks,
|
|
51
|
+
schema,
|
|
52
|
+
sessionProvider,
|
|
53
|
+
extensions,
|
|
54
|
+
toolbarFeatures,
|
|
55
|
+
toolbarExtensions,
|
|
56
|
+
attributesPanel = 'overlay',
|
|
57
|
+
presentation = 'bare'
|
|
58
|
+
}: Props = $props();
|
|
59
|
+
|
|
60
|
+
const resolvedSchema = $derived(typeof schema === 'function' ? schema(pagePath) : schema);
|
|
61
|
+
const signIn = $derived(site.config.forge === 'github');
|
|
62
|
+
const branch = $derived(
|
|
63
|
+
site.config.forge === 'github' ? site.config.branch : 'the local checkout'
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
let doc = $state<ContentDocument | undefined>(undefined);
|
|
67
|
+
let meta = $state<Record<string, unknown>>({});
|
|
68
|
+
let status = $state<StatusView | undefined>(undefined);
|
|
69
|
+
let conflict = $state(false);
|
|
70
|
+
let saveEnabled = $state(false);
|
|
71
|
+
let started = $state(false);
|
|
72
|
+
let cancelled = false;
|
|
73
|
+
let controller: EditorController | undefined;
|
|
74
|
+
|
|
75
|
+
// A sign-in popup opens a window, which browsers block outside a click, so a
|
|
76
|
+
// forge that signs in waits for the button.
|
|
77
|
+
function start() {
|
|
78
|
+
started = true;
|
|
79
|
+
controller?.load().catch((error: unknown) => {
|
|
80
|
+
if (cancelled) return;
|
|
81
|
+
// Offer the sign-in again: most refusals are fixed outside this page.
|
|
82
|
+
if (signIn) started = false;
|
|
83
|
+
status = {
|
|
84
|
+
tone: 'error',
|
|
85
|
+
text: error instanceof Error ? error.message : 'Failed to load the document.'
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onMount(() => {
|
|
91
|
+
controller = createEditorSession({
|
|
92
|
+
config: site.config,
|
|
93
|
+
sourcePath,
|
|
94
|
+
pagePath,
|
|
95
|
+
blocks,
|
|
96
|
+
schema: resolvedSchema,
|
|
97
|
+
sessionProvider,
|
|
98
|
+
autosaveMs: site.autosaveMs,
|
|
99
|
+
timings: site.deployStatusTimings,
|
|
100
|
+
isDestroyed: () => cancelled,
|
|
101
|
+
ui: {
|
|
102
|
+
status: (view) => (status = view),
|
|
103
|
+
setDocument: (next) => {
|
|
104
|
+
doc = next;
|
|
105
|
+
// Without this the metadata panel shows schema defaults, and
|
|
106
|
+
// committing metadata would clobber the document's own.
|
|
107
|
+
meta = next.meta ?? {};
|
|
108
|
+
},
|
|
109
|
+
saveEnabled: (enabled) => (saveEnabled = enabled),
|
|
110
|
+
conflictVisible: (visible) => (conflict = visible)
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
if (!signIn) start();
|
|
114
|
+
return () => {
|
|
115
|
+
cancelled = true;
|
|
116
|
+
controller?.stop();
|
|
117
|
+
clearActiveForge();
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<div class="uncial-cms-editor-page" data-uncial-cms-runtime={UNCIAL_CMS_RUNTIME_SENTINEL}>
|
|
123
|
+
<div class="uncial-cms-chrome">
|
|
124
|
+
{#if !started}
|
|
125
|
+
<button type="button" onclick={start}>Sign in with GitHub</button>
|
|
126
|
+
{:else if site.autosaveMs === undefined && doc}
|
|
127
|
+
<button type="button" disabled={!saveEnabled} onclick={() => void controller?.save()}>
|
|
128
|
+
Save
|
|
129
|
+
</button>
|
|
130
|
+
{/if}
|
|
131
|
+
{#if status}
|
|
132
|
+
<p class="uncial-cms-status" role="status" data-tone={status.tone}>
|
|
133
|
+
{status.text}{#if status.href} <a href={status.href} target="_blank" rel="noopener"
|
|
134
|
+
>View commit</a
|
|
135
|
+
>{/if}
|
|
136
|
+
</p>
|
|
137
|
+
{/if}
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{#if conflict}
|
|
141
|
+
<div class="uncial-cms-banner" role="alert">
|
|
142
|
+
<p class="uncial-cms-banner-message">
|
|
143
|
+
This page changed on {branch} since you loaded it. Your unsaved changes are safe — choose how
|
|
144
|
+
to proceed.
|
|
145
|
+
</p>
|
|
146
|
+
<div class="uncial-cms-banner-actions">
|
|
147
|
+
<button type="button" onclick={() => controller?.downloadMyVersion()}>
|
|
148
|
+
Download my version
|
|
149
|
+
</button>
|
|
150
|
+
<button type="button" onclick={() => void controller?.reloadLatest()}>Reload latest</button>
|
|
151
|
+
<button type="button" onclick={() => controller?.dismissConflict()}>Dismiss</button>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
{/if}
|
|
155
|
+
|
|
156
|
+
{#if doc}
|
|
157
|
+
<Editor
|
|
158
|
+
{blocks}
|
|
159
|
+
schema={resolvedSchema}
|
|
160
|
+
metaFields={resolvedSchema.metaFields}
|
|
161
|
+
bind:json={doc}
|
|
162
|
+
bind:meta
|
|
163
|
+
{extensions}
|
|
164
|
+
{toolbarFeatures}
|
|
165
|
+
{toolbarExtensions}
|
|
166
|
+
{attributesPanel}
|
|
167
|
+
{presentation}
|
|
168
|
+
onChange={(next) => controller?.documentChanged(next as ContentDocument)}
|
|
169
|
+
/>
|
|
170
|
+
{/if}
|
|
171
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An Astro editor route's island: Uncial's `Editor` in the host's own tree
|
|
3
|
+
* and cascade, driven by the headless editor session, with the status line,
|
|
4
|
+
* conflict banner and Save or autosave around it.
|
|
5
|
+
*
|
|
6
|
+
* Blocks, schemas and Tiptap extensions are not serializable island props,
|
|
7
|
+
* so the host mounts this from a small component of its own that imports
|
|
8
|
+
* them, with `client:only="svelte"`.
|
|
9
|
+
*/
|
|
10
|
+
import 'uncial/styles/chrome.css';
|
|
11
|
+
import { type ComponentProps } from 'svelte';
|
|
12
|
+
import type { BlockRegistry, ContentSchema } from 'uncial/core';
|
|
13
|
+
import { Editor, type ToolbarFeature, type ToolbarFeatureSelection } from 'uncial/editor';
|
|
14
|
+
import type { Site } from '../define-site.js';
|
|
15
|
+
import type { SessionProvider } from '../types.js';
|
|
16
|
+
interface Props {
|
|
17
|
+
/** The site object from `defineSite`. */
|
|
18
|
+
site: Site;
|
|
19
|
+
/** Repo-root-relative JSON path, from the editor route's props. */
|
|
20
|
+
sourcePath: string;
|
|
21
|
+
/** Site-relative page path, from the editor route's props. */
|
|
22
|
+
pagePath: string;
|
|
23
|
+
blocks: BlockRegistry;
|
|
24
|
+
/** One schema for the site, or the schema this page path is written against. */
|
|
25
|
+
schema: ContentSchema | ((path: string) => ContentSchema);
|
|
26
|
+
/** Defaults to the provider the resolved forge implies. */
|
|
27
|
+
sessionProvider?: SessionProvider;
|
|
28
|
+
/** Forwarded to `Editor`: the Tiptap extensions behind custom marks. */
|
|
29
|
+
extensions?: ComponentProps<typeof Editor>['extensions'];
|
|
30
|
+
/** Forwarded to `Editor`. */
|
|
31
|
+
toolbarFeatures?: ToolbarFeatureSelection;
|
|
32
|
+
/** Forwarded to `Editor`. */
|
|
33
|
+
toolbarExtensions?: ToolbarFeature[];
|
|
34
|
+
/** Forwarded to `Editor`; `'overlay'` keeps the document at the host's width. */
|
|
35
|
+
attributesPanel?: 'docked' | 'overlay' | 'off';
|
|
36
|
+
/** Forwarded to `Editor`; `'bare'` draws no surface of the editor's own. */
|
|
37
|
+
presentation?: 'card' | 'bare';
|
|
38
|
+
}
|
|
39
|
+
declare const EditorSurface: import("svelte").Component<Props, {}, "">;
|
|
40
|
+
type EditorSurface = ReturnType<typeof EditorSurface>;
|
|
41
|
+
export default EditorSurface;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
2
|
+
import type { SiteOptions } from '../define-site.js';
|
|
3
|
+
export { uncialCms } from './integration.js';
|
|
4
|
+
/** A content file as the helpers see it: site-relative path, repo-root-relative source. */
|
|
5
|
+
export interface ContentEntry {
|
|
6
|
+
path: string;
|
|
7
|
+
source: string;
|
|
8
|
+
}
|
|
9
|
+
/** A content document ready to render, with the paths an editor route needs. */
|
|
10
|
+
export interface ContentPage {
|
|
11
|
+
path: string;
|
|
12
|
+
/** Repo-root-relative, as the forge addresses it. */
|
|
13
|
+
sourcePath: string;
|
|
14
|
+
document: ContentDocument;
|
|
15
|
+
}
|
|
16
|
+
export interface ContentRouteOptions {
|
|
17
|
+
/** The options the site hands `defineSite`. */
|
|
18
|
+
siteOptions: SiteOptions;
|
|
19
|
+
blocks: BlockRegistry;
|
|
20
|
+
/** One schema for the whole site, or the schema this page path is written against. */
|
|
21
|
+
schema: ContentSchema | ((path: string) => ContentSchema);
|
|
22
|
+
/** Keep a non-page file — site settings, a manifest — out of the routes. */
|
|
23
|
+
exclude?: (entry: ContentEntry) => boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A rest parameter's value: Astro spells the site root as `undefined`, which a
|
|
27
|
+
* `[...path]` route needs in order to emit `/`.
|
|
28
|
+
*/
|
|
29
|
+
type RestParams = {
|
|
30
|
+
path: string | undefined;
|
|
31
|
+
};
|
|
32
|
+
export declare function createContentRoutes(opts: ContentRouteOptions): {
|
|
33
|
+
/** Every content document, normalized, in source order. */
|
|
34
|
+
list: () => ContentPage[];
|
|
35
|
+
/** One document by site path, for a route with a fixed shell of its own. */
|
|
36
|
+
load: (path: string) => ContentPage;
|
|
37
|
+
getStaticPaths: () => Array<{
|
|
38
|
+
params: RestParams;
|
|
39
|
+
props: ContentPage;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
export declare function createEditorRoutes(opts: ContentRouteOptions & {
|
|
43
|
+
devOnly?: boolean;
|
|
44
|
+
}): {
|
|
45
|
+
getStaticPaths: () => Array<{
|
|
46
|
+
params: RestParams;
|
|
47
|
+
props: {
|
|
48
|
+
sourcePath: string;
|
|
49
|
+
pagePath: string;
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `uncial-cms/astro` — the integration and route helpers for a static Astro
|
|
3
|
+
* site. Build time only: it reads the local content directory with node:fs, so
|
|
4
|
+
* import it from `astro.config` and route frontmatter, never from an island.
|
|
5
|
+
* The editor island lives at `uncial-cms/astro/editor`.
|
|
6
|
+
*
|
|
7
|
+
* Like `uncial-cms/sveltekit`, nothing here registers a route. The host writes
|
|
8
|
+
* its reader route as `[...path].astro` and injects or writes its editor route
|
|
9
|
+
* itself, and each hands its `getStaticPaths` to the helper.
|
|
10
|
+
*
|
|
11
|
+
* The helpers take the site's plain options rather than `defineSite`'s result
|
|
12
|
+
* so that no reader route has to import the package root: the root carries the
|
|
13
|
+
* editor's stylesheet, and Astro links a module's CSS into every page whose
|
|
14
|
+
* graph reaches it.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { normalizeDocument } from 'uncial/core';
|
|
19
|
+
import { listContentSources } from '../content-sources.js';
|
|
20
|
+
import { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
21
|
+
export { uncialCms } from './integration.js';
|
|
22
|
+
function localContentDir({ siteOptions }) {
|
|
23
|
+
return siteOptions.localContentDir ?? siteOptions.contentDir;
|
|
24
|
+
}
|
|
25
|
+
function listEntries(opts) {
|
|
26
|
+
const { contentDir } = opts.siteOptions;
|
|
27
|
+
return listContentSources(localContentDir(opts))
|
|
28
|
+
.map((rel) => {
|
|
29
|
+
const source = `${contentDir}/${rel}`;
|
|
30
|
+
return { path: defaultMapSourceToPath(source, contentDir), source };
|
|
31
|
+
})
|
|
32
|
+
.filter((entry) => !opts.exclude?.(entry));
|
|
33
|
+
}
|
|
34
|
+
function readPage(opts, { path, source }) {
|
|
35
|
+
const rel = source.slice(opts.siteOptions.contentDir.length + 1);
|
|
36
|
+
const raw = JSON.parse(readFileSync(join(localContentDir(opts), rel), 'utf-8'));
|
|
37
|
+
const schema = typeof opts.schema === 'function' ? opts.schema(path) : opts.schema;
|
|
38
|
+
return {
|
|
39
|
+
path,
|
|
40
|
+
sourcePath: source,
|
|
41
|
+
document: normalizeDocument(raw, opts.blocks, schema)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function restParams(path) {
|
|
45
|
+
return { path: path === '' ? undefined : path };
|
|
46
|
+
}
|
|
47
|
+
export function createContentRoutes(opts) {
|
|
48
|
+
const list = () => listEntries(opts).map((entry) => readPage(opts, entry));
|
|
49
|
+
return {
|
|
50
|
+
list,
|
|
51
|
+
load: (path) => {
|
|
52
|
+
const source = defaultMapPathToSource(path, opts.siteOptions.contentDir);
|
|
53
|
+
if (opts.exclude?.({ path, source })) {
|
|
54
|
+
throw new Error(`Content path "${path}" is excluded from this site's routes.`);
|
|
55
|
+
}
|
|
56
|
+
return readPage(opts, { path, source });
|
|
57
|
+
},
|
|
58
|
+
getStaticPaths: () => list().map((page) => ({ params: restParams(page.path), props: page }))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function createEditorRoutes(opts) {
|
|
62
|
+
// A local-only site has no forge to commit to outside development.
|
|
63
|
+
const devOnly = opts.devOnly ?? opts.siteOptions.github === undefined;
|
|
64
|
+
return {
|
|
65
|
+
getStaticPaths: () => devOnly && !import.meta.env.DEV
|
|
66
|
+
? []
|
|
67
|
+
: listEntries(opts).map(({ path, source }) => ({
|
|
68
|
+
params: restParams(path),
|
|
69
|
+
props: { sourcePath: source, pagePath: path }
|
|
70
|
+
}))
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { uncialCms as uncialCmsVite } from '../vite/index.js';
|
|
2
|
+
/** Installs the dev server's local forge and the build's forge constant. */
|
|
3
|
+
export function uncialCms(options) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'uncial-cms',
|
|
6
|
+
hooks: {
|
|
7
|
+
'astro:config:setup': ({ updateConfig }) => {
|
|
8
|
+
// Typed against the Vite this package builds with, which need not be
|
|
9
|
+
// the one Astro bundles; the plugins use only hooks both versions share.
|
|
10
|
+
const plugins = uncialCmsVite(options);
|
|
11
|
+
updateConfig({ vite: { plugins } });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zero-CMS-JS build gate against Astro's asset layout: reader pages must
|
|
3
|
+
* ship none of the editor's JavaScript, and every editor page must ship it.
|
|
4
|
+
*
|
|
5
|
+
* It is stricter than the SvelteKit gate in two ways. Dynamic imports are
|
|
6
|
+
* followed, because an Astro page has no router lazily importing other routes:
|
|
7
|
+
* a dynamic import reachable from a page is code that page may run. And a
|
|
8
|
+
* reader page fails on the editor stack as well as the sentinel, which catches
|
|
9
|
+
* the editor imported directly, without the sentinel-bearing surface.
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { dirname, join, relative } from 'node:path';
|
|
13
|
+
import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
|
|
14
|
+
import { EDITOR_STACK_MARKERS, walk } from './assert-clean-pages.js';
|
|
15
|
+
const SENTINEL_NAME = 'uncial-cms runtime sentinel';
|
|
16
|
+
const MARKERS = [
|
|
17
|
+
[SENTINEL_NAME, new RegExp(UNCIAL_CMS_RUNTIME_SENTINEL)],
|
|
18
|
+
...EDITOR_STACK_MARKERS
|
|
19
|
+
];
|
|
20
|
+
function markersIn(source) {
|
|
21
|
+
return MARKERS.filter(([, pattern]) => pattern.test(source)).map(([name]) => name);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Map a URL from the page or a chunk to a file in the build directory. Astro
|
|
25
|
+
* emits its bundles under `_astro/`, so those resolve from that segment whatever
|
|
26
|
+
* base path prefixes them; other root-relative URLs are files from `public/`.
|
|
27
|
+
* Off-site URLs resolve to nothing.
|
|
28
|
+
*/
|
|
29
|
+
function resolveAsset(buildDir, url) {
|
|
30
|
+
const marker = url.indexOf('_astro/');
|
|
31
|
+
if (marker !== -1)
|
|
32
|
+
return join(buildDir, url.slice(marker));
|
|
33
|
+
if (url.startsWith('/') && !url.startsWith('//'))
|
|
34
|
+
return join(buildDir, url);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
function readSource(file, cache) {
|
|
38
|
+
if (!cache.has(file)) {
|
|
39
|
+
try {
|
|
40
|
+
cache.set(file, readFileSync(file, 'utf-8'));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
cache.set(file, null); // external or non-emitted reference
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return cache.get(file) ?? null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Every JS file a page can load: script and preload tags, the component and
|
|
50
|
+
* renderer URLs of Astro islands, imports in inline module scripts, and then,
|
|
51
|
+
* transitively, each chunk's static and dynamic imports.
|
|
52
|
+
*/
|
|
53
|
+
function scriptClosure(buildDir, html, cache) {
|
|
54
|
+
const queue = [];
|
|
55
|
+
const urls = [
|
|
56
|
+
...html.matchAll(/(?:src|href|component-url|renderer-url|before-hydration-url)="([^"]+\.m?js)"/g),
|
|
57
|
+
...html.matchAll(/import\s*\(?\s*["']([^"']+\.m?js)["']/g)
|
|
58
|
+
];
|
|
59
|
+
for (const [, url] of urls) {
|
|
60
|
+
const resolved = resolveAsset(buildDir, url);
|
|
61
|
+
if (resolved)
|
|
62
|
+
queue.push(resolved);
|
|
63
|
+
}
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
while (queue.length > 0) {
|
|
66
|
+
const file = queue.pop();
|
|
67
|
+
if (seen.has(file))
|
|
68
|
+
continue;
|
|
69
|
+
seen.add(file);
|
|
70
|
+
const source = readSource(file, cache);
|
|
71
|
+
if (source === null)
|
|
72
|
+
continue;
|
|
73
|
+
for (const [, spec] of source.matchAll(/(?:from|import)\s*\(?\s*["']([^"']+\.m?js)["']/g)) {
|
|
74
|
+
if (spec.startsWith('.'))
|
|
75
|
+
queue.push(join(dirname(file), spec));
|
|
76
|
+
else {
|
|
77
|
+
const resolved = resolveAsset(buildDir, spec);
|
|
78
|
+
if (resolved)
|
|
79
|
+
queue.push(resolved);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return seen;
|
|
84
|
+
}
|
|
85
|
+
/** Editor markers on a page, each named with the file that carries it. */
|
|
86
|
+
function pageFindings(buildDir, htmlPath, cache) {
|
|
87
|
+
const html = readFileSync(htmlPath, 'utf-8');
|
|
88
|
+
// The stack markers are looked for only in inline script bodies, since page
|
|
89
|
+
// prose may mention them; the sentinel counts anywhere, as an attribute too.
|
|
90
|
+
const inline = [...html.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/g)]
|
|
91
|
+
.map(([, body]) => body)
|
|
92
|
+
.join('\n');
|
|
93
|
+
const findings = markersIn(inline).map((name) => `${name} in an inline script`);
|
|
94
|
+
if (html.includes(UNCIAL_CMS_RUNTIME_SENTINEL))
|
|
95
|
+
findings.push(`${SENTINEL_NAME} in the page`);
|
|
96
|
+
for (const file of scriptClosure(buildDir, html, cache)) {
|
|
97
|
+
const source = readSource(file, cache);
|
|
98
|
+
if (source === null)
|
|
99
|
+
continue;
|
|
100
|
+
for (const name of markersIn(source))
|
|
101
|
+
findings.push(`${name} in ${relative(buildDir, file)}`);
|
|
102
|
+
}
|
|
103
|
+
return findings;
|
|
104
|
+
}
|
|
105
|
+
/** Site-relative page path of an HTML file, as the failure messages name it. */
|
|
106
|
+
function pageOf(buildDir, htmlPath) {
|
|
107
|
+
const rel = relative(buildDir, htmlPath).split('\\').join('/');
|
|
108
|
+
if (rel === 'index.html')
|
|
109
|
+
return '/';
|
|
110
|
+
return rel.endsWith('/index.html') ? `/${rel.slice(0, -'index.html'.length)}` : `/${rel}`;
|
|
111
|
+
}
|
|
112
|
+
export function assertCleanAstroPages(buildDir, io) {
|
|
113
|
+
let htmlFiles;
|
|
114
|
+
try {
|
|
115
|
+
htmlFiles = walk(buildDir).filter((path) => path.endsWith('.html'));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
htmlFiles = [];
|
|
119
|
+
}
|
|
120
|
+
if (htmlFiles.length === 0) {
|
|
121
|
+
io.err(`No pages found under "${buildDir}" — build the site first.`);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
const cache = new Map();
|
|
125
|
+
const failures = [];
|
|
126
|
+
for (const htmlPath of htmlFiles) {
|
|
127
|
+
const page = pageOf(buildDir, htmlPath);
|
|
128
|
+
const findings = pageFindings(buildDir, htmlPath, cache);
|
|
129
|
+
if (page.endsWith('/edit/')) {
|
|
130
|
+
if (!findings.some((finding) => finding.startsWith(SENTINEL_NAME))) {
|
|
131
|
+
failures.push(`${page} is an editor page but does not reference the CMS runtime.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (page !== '/uncial/' && findings.length > 0) {
|
|
135
|
+
failures.push(`${page} is a reader page but ships the editor runtime: ${findings.join('; ')}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (failures.length > 0) {
|
|
139
|
+
io.err('assert:clean-pages FAILED');
|
|
140
|
+
for (const failure of failures)
|
|
141
|
+
io.err(` - ${failure}`);
|
|
142
|
+
return 1;
|
|
143
|
+
}
|
|
144
|
+
io.out(`assert:clean-pages OK — ${htmlFiles.length} pages checked, reader pages ship no editor runtime.`);
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
@@ -7,4 +7,14 @@ export interface AssertCleanPagesOptions {
|
|
|
7
7
|
/** Assert a local-only site: no Editor variant, and no editor stack anywhere. */
|
|
8
8
|
localOnly?: boolean;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Names the editor stack cannot be bundled without, and that nothing else in a
|
|
12
|
+
* built site carries. The ProseMirror marker is its class-name prefix rather
|
|
13
|
+
* than the bare word: `ProseMirror-focused` and its siblings are string
|
|
14
|
+
* literals in prosemirror-view that survive minification, while the bare word
|
|
15
|
+
* also appears in a validation message uncial's renderer ships — prose about a
|
|
16
|
+
* document format, not a copy of the library.
|
|
17
|
+
*/
|
|
18
|
+
export declare const EDITOR_STACK_MARKERS: ReadonlyArray<readonly [string, RegExp]>;
|
|
19
|
+
export declare function walk(dir: string): string[];
|
|
10
20
|
export declare function assertCleanPages(buildDir: string, options: AssertCleanPagesOptions, io: CliOutput): number;
|
|
@@ -18,12 +18,12 @@ import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
|
|
|
18
18
|
* also appears in a validation message uncial's renderer ships — prose about a
|
|
19
19
|
* document format, not a copy of the library.
|
|
20
20
|
*/
|
|
21
|
-
const EDITOR_STACK_MARKERS = [
|
|
21
|
+
export const EDITOR_STACK_MARKERS = [
|
|
22
22
|
['tiptap', /tiptap/i],
|
|
23
23
|
['ProseMirror-', /ProseMirror-/],
|
|
24
24
|
['uncial-editor', /uncial-editor/]
|
|
25
25
|
];
|
|
26
|
-
function walk(dir) {
|
|
26
|
+
export function walk(dir) {
|
|
27
27
|
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
28
28
|
const path = join(dir, entry.name);
|
|
29
29
|
return entry.isDirectory() ? walk(path) : [path];
|
package/dist/cli/run.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/** Argument parsing and dispatch for the `uncial-cms` command. */
|
|
2
|
+
import { assertCleanAstroPages } from './assert-clean-astro-pages.js';
|
|
2
3
|
import { assertCleanPages } from './assert-clean-pages.js';
|
|
3
4
|
import { DEFAULT_APP_SLUG } from '../define-site.js';
|
|
4
5
|
import { doctor } from './doctor.js';
|
|
5
6
|
const USAGE = `uncial-cms — build gates and provisioning checks for a site that edits itself
|
|
6
7
|
|
|
7
8
|
Usage:
|
|
8
|
-
uncial-cms assert-clean-pages [buildDir] [--local-only]
|
|
9
|
+
uncial-cms assert-clean-pages [buildDir] [--local-only | --astro]
|
|
9
10
|
|
|
10
11
|
Assert that Content pages ship no uncial-cms JavaScript and that every
|
|
11
|
-
Editor variant does. buildDir defaults to "build".
|
|
12
|
+
Editor variant does. buildDir defaults to "build", or "dist" with --astro.
|
|
12
13
|
|
|
13
14
|
--local-only Assert a local-only site's production build instead: no
|
|
14
15
|
Editor variant exists, and no file in the build carries the
|
|
15
16
|
CMS runtime sentinel or the editor stack.
|
|
17
|
+
--astro Read an Astro build's asset layout, following dynamic
|
|
18
|
+
imports and island URLs, and fail a reader page on the
|
|
19
|
+
editor stack as well as the sentinel.
|
|
16
20
|
|
|
17
21
|
uncial-cms doctor --origin <https://host> [--repo owner/name]
|
|
18
22
|
[--app-slug <slug>] [--branch <ref>] [--no-pages]
|
|
@@ -95,12 +99,20 @@ export async function run(argv, io = consoleOutput, gh) {
|
|
|
95
99
|
}, io, gh);
|
|
96
100
|
}
|
|
97
101
|
const localOnly = rest.includes('--local-only');
|
|
102
|
+
const astro = rest.includes('--astro');
|
|
98
103
|
const positional = rest.filter((arg) => !arg.startsWith('-'));
|
|
99
|
-
const unknownFlag = rest.find((arg) => arg.startsWith('-') && arg !== '--local-only');
|
|
104
|
+
const unknownFlag = rest.find((arg) => arg.startsWith('-') && arg !== '--local-only' && arg !== '--astro');
|
|
100
105
|
if (unknownFlag !== undefined) {
|
|
101
106
|
io.err(`Unknown option "${unknownFlag}".`);
|
|
102
107
|
io.err(USAGE);
|
|
103
108
|
return 2;
|
|
104
109
|
}
|
|
110
|
+
if (localOnly && astro) {
|
|
111
|
+
io.err('--local-only and --astro cannot be combined.');
|
|
112
|
+
io.err(USAGE);
|
|
113
|
+
return 2;
|
|
114
|
+
}
|
|
115
|
+
if (astro)
|
|
116
|
+
return assertCleanAstroPages(positional[0] ?? 'dist', io);
|
|
105
117
|
return assertCleanPages(positional[0] ?? 'build', { localOnly }, io);
|
|
106
118
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Build-time enumeration of a content directory, shared by the framework route factories. Node only. */
|
|
2
|
+
import { readdirSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/** Every `.json` file under the local content dir, content-dir-relative and sorted. */
|
|
5
|
+
export function listContentSources(localContentDir, prefix = '') {
|
|
6
|
+
const sources = [];
|
|
7
|
+
for (const entry of readdirSync(join(localContentDir, prefix), { withFileTypes: true })) {
|
|
8
|
+
const rel = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
|
|
9
|
+
if (entry.isDirectory())
|
|
10
|
+
sources.push(...listContentSources(localContentDir, rel));
|
|
11
|
+
else if (entry.isFile() && entry.name.endsWith('.json'))
|
|
12
|
+
sources.push(rel);
|
|
13
|
+
}
|
|
14
|
+
return sources.sort();
|
|
15
|
+
}
|
package/dist/github/adapter.js
CHANGED
|
@@ -65,15 +65,26 @@ class GitHubAdapter {
|
|
|
65
65
|
await this.#assertOk(response, `delete ${path}`);
|
|
66
66
|
}
|
|
67
67
|
async listDir(path) {
|
|
68
|
-
|
|
68
|
+
// The Trees API, unlike the Contents API, has no 1,000-entry directory cap.
|
|
69
|
+
const dir = path.replace(/^\/+|\/+$/g, '');
|
|
70
|
+
const ref = `${this.#config.branch}:${encodeRepoPath(dir)}`;
|
|
71
|
+
// GitHub marks this `private, max-age=60`, so the browser would otherwise
|
|
72
|
+
// answer from its cache and omit a file committed within the last minute.
|
|
73
|
+
const response = await this.#request(`${GITHUB_API_URL}/repos/${this.#config.repo}/git/trees/${ref}`, { cache: 'no-cache' });
|
|
69
74
|
await this.#assertOk(response, `list ${path}`);
|
|
70
|
-
const
|
|
71
|
-
if (!Array.isArray(
|
|
75
|
+
const body = (await response.json());
|
|
76
|
+
if (!Array.isArray(body.tree)) {
|
|
72
77
|
throw new Error(`Expected a directory but found a file: ${path}`);
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
if (body.truncated) {
|
|
80
|
+
throw new Error(`Directory is too large to list: ${path}`);
|
|
81
|
+
}
|
|
82
|
+
// Tree entry paths are relative to the listed directory; callers expect repo-root-relative.
|
|
83
|
+
const prefix = dir ? `${dir}/` : '';
|
|
84
|
+
const kinds = { blob: 'file', tree: 'dir' };
|
|
85
|
+
return body.tree
|
|
86
|
+
.filter((entry) => entry.type in kinds)
|
|
87
|
+
.map((entry) => ({ path: prefix + entry.path, type: kinds[entry.type] }));
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
90
|
* Both of GitHub's two answers to "how did this commit fare", because a repo
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ImageSource } from 'uncial/editor';
|
|
2
|
+
import type { UncialCmsSiteConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The editor's image source for a CMS site: an upload is fitted under the
|
|
5
|
+
* forge limit, committed under the media dir through the active editor
|
|
6
|
+
* session, and stored as its base-less served URL; browse lists the media
|
|
7
|
+
* dir's images the same way. `base` and `staticDir` are the site's build-time
|
|
8
|
+
* values, which the config does not carry. A site with a rendition pipeline
|
|
9
|
+
* replaces the listing with `list` (served paths) and the tile URL with
|
|
10
|
+
* `thumbnail`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cmsImageSource(config: UncialCmsSiteConfig, options?: {
|
|
13
|
+
base?: string;
|
|
14
|
+
staticDir?: string;
|
|
15
|
+
list?: () => Promise<string[]>;
|
|
16
|
+
thumbnail?: (src: string) => string;
|
|
17
|
+
}): ImageSource;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveImageSrc } from 'uncial/render';
|
|
2
|
+
import { resolveMediaDir, uploadImageAsset } from './index-actions.js';
|
|
3
|
+
import { servedUrl } from './served-url.js';
|
|
4
|
+
import { getActiveForge } from './upload-context.js';
|
|
5
|
+
const IMAGE_EXTENSION = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
|
|
6
|
+
/**
|
|
7
|
+
* The editor's image source for a CMS site: an upload is fitted under the
|
|
8
|
+
* forge limit, committed under the media dir through the active editor
|
|
9
|
+
* session, and stored as its base-less served URL; browse lists the media
|
|
10
|
+
* dir's images the same way. `base` and `staticDir` are the site's build-time
|
|
11
|
+
* values, which the config does not carry. A site with a rendition pipeline
|
|
12
|
+
* replaces the listing with `list` (served paths) and the tile URL with
|
|
13
|
+
* `thumbnail`.
|
|
14
|
+
*/
|
|
15
|
+
export function cmsImageSource(config, options = {}) {
|
|
16
|
+
const { base = '', staticDir = 'static', list } = options;
|
|
17
|
+
return {
|
|
18
|
+
upload: async (file) => {
|
|
19
|
+
const result = await uploadImageAsset(file, { fit: true, mediaDir: config.mediaDir });
|
|
20
|
+
return servedUrl({ config }, result.path, staticDir);
|
|
21
|
+
},
|
|
22
|
+
browse: list ?? (async () => {
|
|
23
|
+
const forge = getActiveForge();
|
|
24
|
+
if (!forge) {
|
|
25
|
+
throw new Error('No active editor session — open a page in the editor and sign in before choosing an image.');
|
|
26
|
+
}
|
|
27
|
+
// The same resolution `uploadImageAsset` commits under, so browse lists what upload wrote.
|
|
28
|
+
const mediaDir = resolveMediaDir(config.mediaDir, forge.config.mediaDir);
|
|
29
|
+
const entries = await forge.adapter.listDir(mediaDir);
|
|
30
|
+
return entries
|
|
31
|
+
.filter((entry) => entry.type === 'file' && IMAGE_EXTENSION.test(entry.path))
|
|
32
|
+
.map((entry) => entry.path)
|
|
33
|
+
.sort()
|
|
34
|
+
.map((path) => servedUrl({ config }, path, staticDir));
|
|
35
|
+
}),
|
|
36
|
+
thumbnail: options.thumbnail ?? ((src) => resolveImageSrc(src, base))
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dist/index-actions.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export interface UploadAssetResult {
|
|
|
50
50
|
export declare function uploadAsset(deps: {
|
|
51
51
|
adapter: ForgeAdapter;
|
|
52
52
|
}, file: UploadAssetFile, opts: UploadAssetOptions): Promise<UploadAssetResult>;
|
|
53
|
+
/** `mediaDir` from the most specific source that supplies one. */
|
|
54
|
+
export declare function resolveMediaDir(...candidates: Array<string | undefined>): string;
|
|
53
55
|
export interface UploadImageAssetOptions {
|
|
54
56
|
mediaDir?: string;
|
|
55
57
|
site?: Site;
|
package/dist/index-actions.js
CHANGED
|
@@ -86,7 +86,7 @@ export async function uploadAsset(deps, file, opts) {
|
|
|
86
86
|
return { path, sha, commitSha };
|
|
87
87
|
}
|
|
88
88
|
/** `mediaDir` from the most specific source that supplies one. */
|
|
89
|
-
function resolveMediaDir(...candidates) {
|
|
89
|
+
export function resolveMediaDir(...candidates) {
|
|
90
90
|
const dir = candidates.find((candidate) => candidate);
|
|
91
91
|
if (!dir) {
|
|
92
92
|
throw new Error('No media directory for the upload: pass `mediaDir`, or give a `site` whose config sets it.');
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { mountIndexPage, type MountIndexPageOptions } from './index-page.js';
|
|
|
9
9
|
export { createPage, deletePage, listPages, uploadAsset, uploadImageAsset, type PageRef, type UploadAssetFile, type UploadAssetOptions, type UploadAssetResult, type UploadImageAssetOptions } from './index-actions.js';
|
|
10
10
|
export { fitImage, type FitOptions, type FittedImage, type ImageEncoder, type EncodableImage } from './fit-image.js';
|
|
11
11
|
export { servedUrl } from './served-url.js';
|
|
12
|
+
export { cmsImageSource } from './image-source.js';
|
|
12
13
|
export { MAX_CONTENT_BYTES } from './constants.js';
|
|
13
14
|
export { hashForPagePath, pagePathFromHash, validatePagePath } from './paths/index.js';
|
|
14
15
|
export { parseDocument, serializeDocument, type Blocks } from './document.js';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { mountIndexPage } from './index-page.js';
|
|
|
15
15
|
export { createPage, deletePage, listPages, uploadAsset, uploadImageAsset } from './index-actions.js';
|
|
16
16
|
export { fitImage } from './fit-image.js';
|
|
17
17
|
export { servedUrl } from './served-url.js';
|
|
18
|
+
export { cmsImageSource } from './image-source.js';
|
|
18
19
|
export { MAX_CONTENT_BYTES } from './constants.js';
|
|
19
20
|
export { hashForPagePath, pagePathFromHash, validatePagePath } from './paths/index.js';
|
|
20
21
|
export { parseDocument, serializeDocument } from './document.js';
|
package/dist/mount.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface MountEditorPageOptions {
|
|
|
36
36
|
* renders behind a shadow boundary, which page styles do not cross).
|
|
37
37
|
*/
|
|
38
38
|
editorStylesheets?: string[];
|
|
39
|
+
/** Where `input: 'image'` fields get images; defaults to `cmsImageSource(config)`. */
|
|
40
|
+
imageSource?: UncialEditorElement['imageSource'];
|
|
39
41
|
}
|
|
40
42
|
export declare function mountEditorPage(target: HTMLElement, opts: MountEditorPageOptions): {
|
|
41
43
|
destroy(): void;
|
package/dist/mount.js
CHANGED
|
@@ -8,6 +8,7 @@ import 'uncial/web-components';
|
|
|
8
8
|
import 'uncial/styles/chrome.css';
|
|
9
9
|
import {} from './editor-controller.js';
|
|
10
10
|
import { createEditorSession, defaultSessionProvider } from './editor-session.js';
|
|
11
|
+
import { cmsImageSource } from './image-source.js';
|
|
11
12
|
import { UNCIAL_CMS_RUNTIME_SENTINEL } from './sentinel.js';
|
|
12
13
|
import { clearActiveForge } from './upload-context.js';
|
|
13
14
|
function mirrorPageStylesIntoEditor(editor, explicit) {
|
|
@@ -71,6 +72,7 @@ export function mountEditorPage(target, opts) {
|
|
|
71
72
|
editor.attributesPanel = opts.attributesPanel;
|
|
72
73
|
if (opts.presentation !== undefined)
|
|
73
74
|
editor.presentation = opts.presentation;
|
|
75
|
+
editor.imageSource = opts.imageSource ?? cmsImageSource(config);
|
|
74
76
|
editor.blocks = blocks;
|
|
75
77
|
editor.schema = schema;
|
|
76
78
|
// Forward the schema's declared meta fields so the editor renders (and edits)
|
package/dist/served-url.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ import type { Site } from './define-site.js';
|
|
|
13
13
|
* `paths.base` the same content is built at, so the site prepends its base at
|
|
14
14
|
* render time.
|
|
15
15
|
*/
|
|
16
|
-
export declare function servedUrl(site: Site, repoPath: string, staticDir?: string): string;
|
|
16
|
+
export declare function servedUrl(site: Pick<Site, 'config'>, repoPath: string, staticDir?: string): string;
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { onMount } from 'svelte';
|
|
15
15
|
import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
16
|
+
import type { ImageSource } from 'uncial/editor';
|
|
16
17
|
import type { Site } from '../define-site.js';
|
|
17
18
|
import type { EditorController, StatusView } from '../editor-controller.js';
|
|
19
|
+
import { cmsImageSource } from '../image-source.js';
|
|
18
20
|
import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
|
|
19
21
|
import type { SessionProvider } from '../types.js';
|
|
20
22
|
import { clearActiveForge } from '../upload-context.js';
|
|
@@ -35,6 +37,8 @@
|
|
|
35
37
|
attributesPanel?: 'docked' | 'overlay' | 'off';
|
|
36
38
|
/** Forwarded to `Editor`; `'bare'` draws no surface of the editor's own. */
|
|
37
39
|
presentation?: 'card' | 'bare';
|
|
40
|
+
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
41
|
+
imageSource?: ImageSource;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
let {
|
|
@@ -45,13 +49,15 @@
|
|
|
45
49
|
schema,
|
|
46
50
|
sessionProvider,
|
|
47
51
|
attributesPanel = 'overlay',
|
|
48
|
-
presentation = 'bare'
|
|
52
|
+
presentation = 'bare',
|
|
53
|
+
imageSource
|
|
49
54
|
}: Props = $props();
|
|
50
55
|
|
|
51
56
|
const resolvedSchema = $derived(typeof schema === 'function' ? schema(pagePath) : schema);
|
|
52
57
|
// Autosave leaves nothing to press; a forge commit is never autosaved, so a
|
|
53
58
|
// Save button and autosave are exactly the two modes.
|
|
54
59
|
const manualSave = $derived(site.autosaveMs === undefined);
|
|
60
|
+
const resolvedImageSource = $derived(imageSource ?? cmsImageSource(site.config));
|
|
55
61
|
const branch = $derived(
|
|
56
62
|
site.config.forge === 'github' ? site.config.branch : 'the local checkout'
|
|
57
63
|
);
|
|
@@ -174,6 +180,7 @@
|
|
|
174
180
|
bind:meta
|
|
175
181
|
{attributesPanel}
|
|
176
182
|
{presentation}
|
|
183
|
+
imageSource={resolvedImageSource}
|
|
177
184
|
onChange={(next) => controller?.documentChanged(next as ContentDocument)}
|
|
178
185
|
/>
|
|
179
186
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BlockRegistry, ContentSchema } from 'uncial/core';
|
|
2
|
+
import type { ImageSource } from 'uncial/editor';
|
|
2
3
|
import type { Site } from '../define-site.js';
|
|
3
4
|
import type { SessionProvider } from '../types.js';
|
|
4
5
|
interface Props {
|
|
@@ -17,6 +18,8 @@ interface Props {
|
|
|
17
18
|
attributesPanel?: 'docked' | 'overlay' | 'off';
|
|
18
19
|
/** Forwarded to `Editor`; `'bare'` draws no surface of the editor's own. */
|
|
19
20
|
presentation?: 'card' | 'bare';
|
|
21
|
+
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
22
|
+
imageSource?: ImageSource;
|
|
20
23
|
}
|
|
21
24
|
declare const EditorPage: import("svelte").Component<Props, {}, "">;
|
|
22
25
|
type EditorPage = ReturnType<typeof EditorPage>;
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* reads the local content directory with node:fs — do not import it from
|
|
6
6
|
* client-side code (the pure mapping lives in `./mapping.js` for that).
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { normalizeDocument } from 'uncial/core';
|
|
11
|
+
import { listContentSources } from '../content-sources.js';
|
|
11
12
|
import { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
12
13
|
export { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
13
14
|
function resolveSite(opts) {
|
|
@@ -20,17 +21,6 @@ function resolveSite(opts) {
|
|
|
20
21
|
}
|
|
21
22
|
return { config: opts.config, localContentDir: opts.localContentDir, localOnly: false };
|
|
22
23
|
}
|
|
23
|
-
function listContentSources(localContentDir, prefix = '') {
|
|
24
|
-
const sources = [];
|
|
25
|
-
for (const entry of readdirSync(join(localContentDir, prefix), { withFileTypes: true })) {
|
|
26
|
-
const rel = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
|
|
27
|
-
if (entry.isDirectory())
|
|
28
|
-
sources.push(...listContentSources(localContentDir, rel));
|
|
29
|
-
else if (entry.isFile() && entry.name.endsWith('.json'))
|
|
30
|
-
sources.push(rel);
|
|
31
|
-
}
|
|
32
|
-
return sources.sort();
|
|
33
|
-
}
|
|
34
24
|
function createEntries(opts, site) {
|
|
35
25
|
return () => listContentSources(site.localContentDir)
|
|
36
26
|
.map((rel) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uncial-cms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,19 +59,30 @@
|
|
|
59
59
|
"./sveltekit": {
|
|
60
60
|
"types": "./dist/sveltekit/index.d.ts",
|
|
61
61
|
"default": "./dist/sveltekit/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./astro": {
|
|
64
|
+
"types": "./dist/astro/index.d.ts",
|
|
65
|
+
"default": "./dist/astro/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./astro/editor": {
|
|
68
|
+
"types": "./dist/astro/editor.d.ts",
|
|
69
|
+
"svelte": "./dist/astro/editor.js",
|
|
70
|
+
"default": "./dist/astro/editor.js"
|
|
62
71
|
}
|
|
63
72
|
},
|
|
64
73
|
"peerDependencies": {
|
|
65
74
|
"svelte": "^5.0.0",
|
|
66
|
-
"uncial": "^
|
|
75
|
+
"uncial": "^4.0.0"
|
|
67
76
|
},
|
|
68
77
|
"devDependencies": {
|
|
78
|
+
"@astrojs/svelte": "^7.2.5",
|
|
69
79
|
"@playwright/test": "^1.58.2",
|
|
70
80
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
71
81
|
"@sveltejs/kit": "^2.50.2",
|
|
72
82
|
"@sveltejs/package": "^2.5.7",
|
|
73
83
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
74
84
|
"@vitest/browser-playwright": "^4.0.18",
|
|
85
|
+
"astro": "^5.18.2",
|
|
75
86
|
"playwright": "^1.58.2",
|
|
76
87
|
"publint": "^0.3.17",
|
|
77
88
|
"svelte": "^5.56.10",
|