uncial-cms 5.1.0 → 5.2.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.
Files changed (68) hide show
  1. package/README.md +61 -16
  2. package/dist/astro/index.d.ts +2 -1
  3. package/dist/astro/index.js +7 -2
  4. package/dist/content-sources.d.ts +10 -0
  5. package/dist/content-sources.js +25 -1
  6. package/dist/dashboard/ConfirmDialog.svelte +76 -0
  7. package/dist/dashboard/ConfirmDialog.svelte.d.ts +10 -0
  8. package/dist/dashboard/Dashboard.svelte +639 -0
  9. package/dist/dashboard/Dashboard.svelte.d.ts +4 -0
  10. package/dist/dashboard/FallbackEditor.svelte +42 -0
  11. package/dist/dashboard/FallbackEditor.svelte.d.ts +14 -0
  12. package/dist/dashboard/GlobalForm.svelte +405 -0
  13. package/dist/dashboard/GlobalForm.svelte.d.ts +17 -0
  14. package/dist/dashboard/GlobalsList.svelte +62 -0
  15. package/dist/dashboard/GlobalsList.svelte.d.ts +7 -0
  16. package/dist/dashboard/MediaSection.svelte +221 -0
  17. package/dist/dashboard/MediaSection.svelte.d.ts +16 -0
  18. package/dist/dashboard/PagesSection.svelte +477 -0
  19. package/dist/dashboard/PagesSection.svelte.d.ts +23 -0
  20. package/dist/dashboard/element.d.ts +39 -0
  21. package/dist/dashboard/element.js +107 -0
  22. package/dist/dashboard/pages-list.d.ts +18 -0
  23. package/dist/dashboard/pages-list.js +29 -0
  24. package/dist/dashboard/routes.d.ts +25 -0
  25. package/dist/dashboard/routes.js +81 -0
  26. package/dist/dashboard/types.d.ts +32 -0
  27. package/dist/dashboard/types.js +1 -0
  28. package/dist/define-site.d.ts +11 -6
  29. package/dist/define-site.js +4 -7
  30. package/dist/editor-controller.d.ts +1 -0
  31. package/dist/editor-controller.js +1 -0
  32. package/dist/editor-session.d.ts +5 -0
  33. package/dist/editor-session.js +1 -1
  34. package/dist/errors.d.ts +13 -0
  35. package/dist/errors.js +14 -0
  36. package/dist/globals.d.ts +12 -0
  37. package/dist/globals.js +29 -0
  38. package/dist/image-source.d.ts +0 -10
  39. package/dist/image-source.js +15 -44
  40. package/dist/index-actions.d.ts +29 -2
  41. package/dist/index-actions.js +36 -4
  42. package/dist/index-page.d.ts +2 -0
  43. package/dist/index-page.js +6 -256
  44. package/dist/index.d.ts +5 -2
  45. package/dist/index.js +3 -2
  46. package/dist/media-source.d.ts +45 -0
  47. package/dist/media-source.js +113 -0
  48. package/dist/mount.d.ts +1 -0
  49. package/dist/mount.js +2 -0
  50. package/dist/server/handlers.d.ts +1 -1
  51. package/dist/server/handlers.js +32 -5
  52. package/dist/server/index.d.ts +2 -1
  53. package/dist/server/index.js +2 -1
  54. package/dist/server/media.d.ts +1 -10
  55. package/dist/server/media.js +7 -11
  56. package/dist/server/postgres-store.d.ts +5 -0
  57. package/dist/server/postgres-store.js +50 -5
  58. package/dist/server-forge/adapter.d.ts +1 -0
  59. package/dist/server-forge/adapter.js +7 -4
  60. package/dist/server-forge/protocol.d.ts +3 -1
  61. package/dist/server-forge/protocol.js +2 -1
  62. package/dist/svelte/MediaLibrary.svelte +109 -53
  63. package/dist/svelte/MediaLibrary.svelte.d.ts +10 -2
  64. package/dist/svelte/index.d.ts +1 -4
  65. package/dist/svelte/index.js +1 -4
  66. package/dist/sveltekit/index.d.ts +2 -1
  67. package/dist/sveltekit/index.js +7 -2
  68. package/package.json +12 -3
package/README.md CHANGED
@@ -18,8 +18,8 @@ itself. The docs are the live demo.
18
18
  Uncial document). Nested paths map naturally: `/blog/hello/` ↔
19
19
  `content/blog/hello.json`.
20
20
  - Production (non-editor) pages ship **zero** uncial-cms JavaScript. The editing
21
- surface exists only on generated editor variants (`/about/edit/`) and the site
22
- index (`/uncial/`).
21
+ surface exists only on generated editor variants (`/about/edit/`) and the
22
+ Dashboard (`/uncial/`).
23
23
  - **Load:** the runtime fetches the JSON + its blob sha live from the forge
24
24
  (never the baked build output), normalizes it, and mounts `<uncial-editor>`.
25
25
  - **Save:** validate → serialize → commit with the recorded sha (optimistic
@@ -54,6 +54,8 @@ The package also ships a `uncial-cms` command; see
54
54
  `ConflictError`, `NotFoundError`, and the shared types (`Site`,
55
55
  `SiteOptions`, `UncialCmsSiteConfig`, `ForgeSession`, `SessionProvider`,
56
56
  `ForgeAdapter`).
57
+ - `uncial-cms/dashboard` — registers `<uncial-dashboard>`, the `/uncial/`
58
+ Dashboard.
57
59
  - `uncial-cms/svelte` — `EditorPage`, the Svelte component that is the
58
60
  recommended door onto an Editor variant in a SvelteKit site.
59
61
  - `uncial-cms/session` — `createEditorSession`: the same editing session
@@ -264,9 +266,10 @@ wants editing in development only; a local-only site gets that behaviour without
264
266
  saying so. Kit reports a prerenderable route it never crawled, so a build strict
265
267
  about that also names the route in `prerender.handleUnseenRoutes`.
266
268
 
267
- **3. Site index** — `src/routes/uncial/+page.server.ts` + `+page.svelte` (OAuth
268
- landing, create/delete, hash-routed fallback editor). The Index page keeps the
269
- plain-DOM mount:
269
+ **3. Dashboard** — `src/routes/uncial/+page.server.ts` + `+page.svelte`. One
270
+ custom element, `<uncial-dashboard>`, is the whole signed-in area: Pages (list,
271
+ search, create, delete, and the hash-routed Fallback editor), Media, Globals and
272
+ the host's own App sections.
270
273
 
271
274
  ```ts
272
275
  import { createIndexHandlers } from 'uncial-cms/sveltekit';
@@ -281,23 +284,28 @@ export const load = handlers.load;
281
284
  <script lang="ts">
282
285
  import { onMount } from 'svelte';
283
286
  import { base } from '$app/paths';
284
- import { mountIndexPage } from 'uncial-cms';
287
+ import 'uncial-cms/dashboard';
285
288
  import { blocks, schema, site } from '../site.js';
286
289
 
287
- let target: HTMLElement;
288
- onMount(() => {
289
- const handle = mountIndexPage(target, { config: site.config, blocks, schema, basePath: base });
290
- return () => handle.destroy();
291
- });
290
+ let mounted = $state(false);
291
+ onMount(() => (mounted = true));
292
292
  </script>
293
293
 
294
- <div bind:this={target}></div>
294
+ {#if mounted}
295
+ <uncial-dashboard config={site} {blocks} {schema} basePath={base}></uncial-dashboard>
296
+ {/if}
295
297
  ```
296
298
 
297
- When the site is served under a base path (e.g. GitHub Pages project sites at
298
- `/owner/repo/`), pass the framework's base path to `mountIndexPage`
299
- (`basePath`) so live-page links resolve; the default mapping always operates on
300
- **site-relative** paths with the base stripped.
299
+ The element's options are objects and functions, which a prerendered attribute
300
+ cannot carry, so it renders after mount and Svelte sets them as properties.
301
+ `config` takes the whole site object, Globals included. When the site is served
302
+ under a base path (e.g. GitHub Pages project sites at `/owner/repo/`), pass the
303
+ framework's base path as `basePath` so live-page links resolve; the default
304
+ mapping always operates on **site-relative** paths with the base stripped. The
305
+ other options (`editorHref`, `can`, `appSections`, `staticDir`, `theme` and
306
+ more) are in the [Dashboard docs](https://d-flood.github.io/uncial/docs/dashboard/).
307
+ `mountIndexPage` still works, as a deprecated wrapper that renders the Dashboard
308
+ showing only Pages.
301
309
 
302
310
  ### Excluding non-page files, and a schema per path
303
311
 
@@ -395,6 +403,34 @@ export function getStaticPaths() {
395
403
  a `sessionProvider` and an `imageSource` (see [Media](#media)). Against the GitHub forge it shows a Sign in button first,
396
404
  since a sign-in popup opened outside a click is blocked.
397
405
 
406
+ The Dashboard is one page that renders `<uncial-dashboard>` and sets its
407
+ options from a script, which Astro bundles for that page alone:
408
+
409
+ ```astro
410
+ ---
411
+ // src/pages/uncial.astro
412
+ ---
413
+
414
+ <html lang="en">
415
+ <head><title>Dashboard</title></head>
416
+ <body>
417
+ <uncial-dashboard></uncial-dashboard>
418
+ <script>
419
+ import 'uncial-cms/dashboard';
420
+ import { defineSite } from 'uncial-cms';
421
+ import { blocks, schema } from '../site';
422
+ import { siteOptions } from '../site-options';
423
+
424
+ Object.assign(document.querySelector('uncial-dashboard')!, {
425
+ config: defineSite(siteOptions),
426
+ blocks,
427
+ schema
428
+ });
429
+ </script>
430
+ </body>
431
+ </html>
432
+ ```
433
+
398
434
  Astro bundles a `client:only` island for any page file that renders it, even
399
435
  one whose `getStaticPaths` returns nothing. A site that wants no editor code in
400
436
  its production build at all injects the editor route from an integration only
@@ -641,6 +677,15 @@ media dir for Choose existing. Pass `list` and `thumbnail` to override the
641
677
  listing and tile URLs for a rendition pipeline, or `imageSource` to replace the
642
678
  source outright.
643
679
 
680
+ The picker and `MediaLibrary` from `uncial-cms/svelte` both read media through a
681
+ **Media source**. `mediaSourceFor(config, session, { staticDir })` picks the
682
+ server forge's Media library, or the git forge's `mediaDir` through an editing
683
+ session's adapter and author. A source's `capabilities` say whether it has
684
+ titles and dimensions (`metadata`), `usage`, `delete` and `search`, and
685
+ `<MediaLibrary {source} />` shows only those; a git source keeps no metadata.
686
+ Deleting a server item that Content documents still use rejects with
687
+ `MediaInUseError`. `MediaLibrary`'s `apiBase` prop is deprecated.
688
+
644
689
  Underneath, single-image upload commits an image straight into the repo and
645
690
  answers its served path. It is exposed as pure, adapter-injected functions in
646
691
  the same family as `createPage`/`deletePage`:
@@ -1,6 +1,8 @@
1
1
  import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
2
2
  import type { SiteOptions } from '../define-site.js';
3
3
  export { uncialCms } from './integration.js';
4
+ export { loadGlobal, type GlobalStore } from '../content-sources.js';
5
+ export type { GlobalValue } from '../globals.js';
4
6
  /** A content file as the helpers see it: site-relative path, repo-root-relative source. */
5
7
  export interface ContentEntry {
6
8
  path: string;
@@ -19,7 +21,6 @@ export interface ContentRouteOptions {
19
21
  blocks: BlockRegistry;
20
22
  /** One schema for the whole site, or the schema this page path is written against. */
21
23
  schema: ContentSchema | ((path: string) => ContentSchema);
22
- /** Keep a non-page file — site settings, a manifest — out of the routes. */
23
24
  exclude?: (entry: ContentEntry) => boolean;
24
25
  }
25
26
  /**
@@ -17,11 +17,16 @@ import { readFileSync } from 'node:fs';
17
17
  import { join } from 'node:path';
18
18
  import { normalizeDocument } from 'uncial/core';
19
19
  import { listContentSources } from '../content-sources.js';
20
+ import { isGlobalsPath } from '../globals.js';
20
21
  import { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
21
22
  export { uncialCms } from './integration.js';
23
+ export { loadGlobal } from '../content-sources.js';
22
24
  function localContentDir({ siteOptions }) {
23
25
  return siteOptions.localContentDir ?? siteOptions.contentDir;
24
26
  }
27
+ function excluded(opts, entry) {
28
+ return isGlobalsPath(entry.path) || (opts.exclude?.(entry) ?? false);
29
+ }
25
30
  function listEntries(opts) {
26
31
  const { contentDir } = opts.siteOptions;
27
32
  return listContentSources(localContentDir(opts))
@@ -29,7 +34,7 @@ function listEntries(opts) {
29
34
  const source = `${contentDir}/${rel}`;
30
35
  return { path: defaultMapSourceToPath(source, contentDir), source };
31
36
  })
32
- .filter((entry) => !opts.exclude?.(entry));
37
+ .filter((entry) => !excluded(opts, entry));
33
38
  }
34
39
  function readPage(opts, { path, source }) {
35
40
  const rel = source.slice(opts.siteOptions.contentDir.length + 1);
@@ -50,7 +55,7 @@ export function createContentRoutes(opts) {
50
55
  list,
51
56
  load: (path) => {
52
57
  const source = defaultMapPathToSource(path, opts.siteOptions.contentDir);
53
- if (opts.exclude?.({ path, source })) {
58
+ if (excluded(opts, { path, source })) {
54
59
  throw new Error(`Content path "${path}" is excluded from this site's routes.`);
55
60
  }
56
61
  return readPage(opts, { path, source });
@@ -1,2 +1,12 @@
1
+ import type { Site } from './define-site.js';
2
+ import { type GlobalValue } from './globals.js';
1
3
  /** Every `.json` file under the local content dir, content-dir-relative and sorted. */
2
4
  export declare function listContentSources(localContentDir: string, prefix?: string): string[];
5
+ export interface GlobalStore {
6
+ get(path: string): Promise<{
7
+ published: unknown;
8
+ } | null>;
9
+ }
10
+ export declare function loadGlobal<S extends Site, N extends keyof S['globals'] & string>(site: S, name: N, opts?: {
11
+ store?: GlobalStore;
12
+ }): Promise<GlobalValue<S, N>>;
@@ -1,6 +1,8 @@
1
- /** Build-time enumeration of a content directory, shared by the framework route factories. Node only. */
2
1
  import { readdirSync } from 'node:fs';
2
+ import { readFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
+ import { normalizeDocument } from 'uncial/core';
5
+ import { globalRecordPath, globalSourcePath } from './globals.js';
4
6
  /** Every `.json` file under the local content dir, content-dir-relative and sorted. */
5
7
  export function listContentSources(localContentDir, prefix = '') {
6
8
  const sources = [];
@@ -13,3 +15,25 @@ export function listContentSources(localContentDir, prefix = '') {
13
15
  }
14
16
  return sources.sort();
15
17
  }
18
+ async function readGlobal(site, name, store) {
19
+ if (site.config.forge === 'server') {
20
+ if (!store)
21
+ throw new Error('A server site reads its Globals from its content store: pass { store }.');
22
+ return (await store.get(globalRecordPath(name)))?.published ?? null;
23
+ }
24
+ try {
25
+ return JSON.parse(await readFile(globalSourcePath(site.localContentDir, name), 'utf-8'));
26
+ }
27
+ catch (error) {
28
+ if (error.code === 'ENOENT')
29
+ return null;
30
+ throw error;
31
+ }
32
+ }
33
+ export async function loadGlobal(site, name, opts = {}) {
34
+ const schema = site.globals[name];
35
+ if (!schema)
36
+ throw new Error(`The site declares no Global named "${name}".`);
37
+ const stored = (await readGlobal(site, name, opts.store));
38
+ return (normalizeDocument(stored, [], schema).meta ?? {});
39
+ }
@@ -0,0 +1,76 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import { onMount, type Snippet } from 'svelte';
5
+
6
+ interface Props {
7
+ title: string;
8
+ confirmLabel: string;
9
+ onclose: (confirmed: boolean) => void;
10
+ children: Snippet;
11
+ }
12
+
13
+ let { title, confirmLabel, onclose, children }: Props = $props();
14
+
15
+ const uid = $props.id();
16
+ let dialog = $state<HTMLDialogElement>();
17
+ let cancel = $state<HTMLButtonElement>();
18
+ // The close event lands a task after Escape, by when the parent may have opened another dialog.
19
+ let mounted = true;
20
+
21
+ onMount(() => {
22
+ dialog?.showModal();
23
+ cancel?.focus();
24
+ return () => (mounted = false);
25
+ });
26
+ </script>
27
+
28
+ <dialog
29
+ bind:this={dialog}
30
+ class="dialog"
31
+ aria-labelledby="{uid}-title"
32
+ aria-describedby="{uid}-body"
33
+ onclose={() => mounted && onclose(dialog?.returnValue === 'confirm')}
34
+ >
35
+ <form method="dialog">
36
+ <h2 id="{uid}-title">{title}</h2>
37
+ <div id="{uid}-body" class="body">{@render children()}</div>
38
+ <div class="actions">
39
+ <button bind:this={cancel} value="cancel" class="btn">Cancel</button>
40
+ <button value="confirm" class="btn btn-danger">{confirmLabel}</button>
41
+ </div>
42
+ </form>
43
+ </dialog>
44
+
45
+ <style>
46
+ .dialog {
47
+ width: min(28rem, calc(100vw - 2rem));
48
+ padding: var(--uncial-space-5);
49
+ border: 1px solid var(--uncial-color-border);
50
+ border-radius: var(--uncial-radius-lg);
51
+ background: var(--uncial-color-surface);
52
+ color: var(--uncial-color-text);
53
+ box-shadow: var(--uncial-shadow-md);
54
+ }
55
+
56
+ .dialog::backdrop {
57
+ background: rgb(0 0 0 / 0.45);
58
+ }
59
+
60
+ h2 {
61
+ margin: 0 0 var(--uncial-space-3);
62
+ font-size: 1.125rem;
63
+ }
64
+
65
+ .body {
66
+ margin: 0 0 var(--uncial-space-5);
67
+ overflow-wrap: anywhere;
68
+ }
69
+
70
+ .actions {
71
+ display: flex;
72
+ flex-wrap: wrap;
73
+ justify-content: flex-end;
74
+ gap: var(--uncial-space-2);
75
+ }
76
+ </style>
@@ -0,0 +1,10 @@
1
+ import { type Snippet } from 'svelte';
2
+ interface Props {
3
+ title: string;
4
+ confirmLabel: string;
5
+ onclose: (confirmed: boolean) => void;
6
+ children: Snippet;
7
+ }
8
+ declare const ConfirmDialog: import("svelte").Component<Props, {}, "">;
9
+ type ConfirmDialog = ReturnType<typeof ConfirmDialog>;
10
+ export default ConfirmDialog;