uncial-cms 5.1.0 → 5.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 +216 -23
- package/dist/astro/EditorSurface.svelte +6 -2
- package/dist/astro/EditorSurface.svelte.d.ts +3 -1
- package/dist/astro/index.d.ts +2 -1
- package/dist/astro/index.js +7 -2
- package/dist/content-sources.d.ts +10 -0
- package/dist/content-sources.js +25 -1
- package/dist/dashboard/ConfirmDialog.svelte +76 -0
- package/dist/dashboard/ConfirmDialog.svelte.d.ts +10 -0
- package/dist/dashboard/Dashboard.svelte +650 -0
- package/dist/dashboard/Dashboard.svelte.d.ts +4 -0
- package/dist/dashboard/FallbackEditor.svelte +42 -0
- package/dist/dashboard/FallbackEditor.svelte.d.ts +14 -0
- package/dist/dashboard/GlobalForm.svelte +405 -0
- package/dist/dashboard/GlobalForm.svelte.d.ts +17 -0
- package/dist/dashboard/GlobalsList.svelte +62 -0
- package/dist/dashboard/GlobalsList.svelte.d.ts +7 -0
- package/dist/dashboard/MediaSection.svelte +221 -0
- package/dist/dashboard/MediaSection.svelte.d.ts +16 -0
- package/dist/dashboard/PagesSection.svelte +477 -0
- package/dist/dashboard/PagesSection.svelte.d.ts +23 -0
- package/dist/dashboard/element.d.ts +41 -0
- package/dist/dashboard/element.js +113 -0
- package/dist/dashboard/pages-list.d.ts +18 -0
- package/dist/dashboard/pages-list.js +29 -0
- package/dist/dashboard/routes.d.ts +25 -0
- package/dist/dashboard/routes.js +81 -0
- package/dist/dashboard/types.d.ts +34 -0
- package/dist/dashboard/types.js +1 -0
- package/dist/define-site.d.ts +15 -6
- package/dist/define-site.js +12 -9
- package/dist/editor-controller.d.ts +1 -0
- package/dist/editor-controller.js +1 -0
- package/dist/editor-session.d.ts +5 -0
- package/dist/editor-session.js +1 -1
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +14 -0
- package/dist/github/broker.d.ts +26 -0
- package/dist/github/broker.js +196 -0
- package/dist/github/index.d.ts +1 -0
- package/dist/github/index.js +1 -0
- package/dist/globals.d.ts +12 -0
- package/dist/globals.js +29 -0
- package/dist/image-source.d.ts +0 -10
- package/dist/image-source.js +15 -44
- package/dist/index-actions.d.ts +29 -2
- package/dist/index-actions.js +36 -4
- package/dist/index-page.d.ts +2 -0
- package/dist/index-page.js +6 -256
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -3
- package/dist/local/vite.d.ts +8 -2
- package/dist/local/vite.js +32 -15
- package/dist/media-source.d.ts +45 -0
- package/dist/media-source.js +113 -0
- package/dist/mount.d.ts +3 -0
- package/dist/mount.js +3 -0
- package/dist/nav/index.d.ts +39 -0
- package/dist/nav/index.js +52 -0
- package/dist/served-url.d.ts +6 -4
- package/dist/served-url.js +18 -7
- package/dist/server/handlers.d.ts +1 -1
- package/dist/server/handlers.js +32 -5
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +2 -1
- package/dist/server/media.d.ts +1 -10
- package/dist/server/media.js +7 -11
- package/dist/server/postgres-store.d.ts +5 -0
- package/dist/server/postgres-store.js +50 -5
- package/dist/server-forge/adapter.d.ts +1 -0
- package/dist/server-forge/adapter.js +7 -4
- package/dist/server-forge/protocol.d.ts +3 -1
- package/dist/server-forge/protocol.js +2 -1
- package/dist/svelte/EditorPage.svelte +5 -1
- package/dist/svelte/EditorPage.svelte.d.ts +3 -1
- package/dist/svelte/MediaLibrary.svelte +109 -53
- package/dist/svelte/MediaLibrary.svelte.d.ts +10 -2
- package/dist/svelte/index.d.ts +1 -4
- package/dist/svelte/index.js +1 -4
- package/dist/sveltekit/index.d.ts +11 -1
- package/dist/sveltekit/index.js +23 -9
- package/dist/types.d.ts +2 -0
- package/dist/upload-context.d.ts +1 -0
- package/dist/upload-context.js +3 -0
- package/dist/vite/index.js +18 -4
- package/package.json +16 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConflictError, NotFoundError } from '../errors.js';
|
|
1
|
+
import { ConflictError, MediaInUseError, NotFoundError, SignedOutError } from '../errors.js';
|
|
2
2
|
export async function serverRequest(apiBase, method, opts = {}) {
|
|
3
3
|
const url = new URL(apiBase, location.origin);
|
|
4
4
|
for (const [key, value] of Object.entries(opts.query ?? {}))
|
|
@@ -16,15 +16,15 @@ export async function serverRequest(apiBase, method, opts = {}) {
|
|
|
16
16
|
return undefined;
|
|
17
17
|
if (response.ok)
|
|
18
18
|
return (await response.json());
|
|
19
|
-
const { error } = (await response.json().catch(() => ({})));
|
|
19
|
+
const { error, usage } = (await response.json().catch(() => ({})));
|
|
20
20
|
if (response.status === 401)
|
|
21
|
-
throw new
|
|
21
|
+
throw new SignedOutError();
|
|
22
22
|
if (response.status === 403)
|
|
23
23
|
throw new Error(error ?? 'You do not have permission to do that.');
|
|
24
24
|
if (response.status === 404)
|
|
25
25
|
throw new NotFoundError(error);
|
|
26
26
|
if (response.status === 409)
|
|
27
|
-
throw new ConflictError(error);
|
|
27
|
+
throw usage ? new MediaInUseError(usage) : new ConflictError(error);
|
|
28
28
|
throw new Error(error ?? `Request failed (${response.status}).`);
|
|
29
29
|
}
|
|
30
30
|
class ServerAdapter {
|
|
@@ -61,6 +61,9 @@ class ServerAdapter {
|
|
|
61
61
|
move(path, to, etag) {
|
|
62
62
|
return this.#request('POST', { body: { action: 'move', path, to, etag } });
|
|
63
63
|
}
|
|
64
|
+
saveGlobal(name, document, etag) {
|
|
65
|
+
return this.#request('POST', { body: { action: 'global-edit', name, document, etag } });
|
|
66
|
+
}
|
|
64
67
|
async readFile(path) {
|
|
65
68
|
const record = await this.getRecord(path);
|
|
66
69
|
return { content: JSON.stringify(record.draft ?? record.published), sha: record.etag };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* endpoint built by `createServerContentHandlers`. Types and pure helpers only,
|
|
4
4
|
* so both sides import it without pulling in the other.
|
|
5
5
|
*/
|
|
6
|
-
export declare const ACTIONS: readonly ["read-draft", "save-draft", "create", "publish", "unpublish", "delete", "move", "restore", "media-upload", "media-delete"];
|
|
6
|
+
export declare const ACTIONS: readonly ["read-draft", "save-draft", "create", "publish", "unpublish", "delete", "move", "restore", "media-upload", "media-delete", "global-edit"];
|
|
7
7
|
export type Action = (typeof ACTIONS)[number];
|
|
8
8
|
export interface ServerUser {
|
|
9
9
|
id: string;
|
|
@@ -33,6 +33,7 @@ export type ContentStatus = 'draft' | 'published' | 'changed';
|
|
|
33
33
|
/** One row of the list endpoint. */
|
|
34
34
|
export interface ContentSummary {
|
|
35
35
|
path: string;
|
|
36
|
+
title?: string;
|
|
36
37
|
kind: string;
|
|
37
38
|
status: ContentStatus;
|
|
38
39
|
publishedAt: string | null;
|
|
@@ -59,6 +60,7 @@ export interface MediaItemView {
|
|
|
59
60
|
export interface MediaListView {
|
|
60
61
|
items: Array<MediaItemView & {
|
|
61
62
|
usage: number;
|
|
63
|
+
usagePaths: string[];
|
|
62
64
|
}>;
|
|
63
65
|
/** Of `media-upload` and `media-delete`, the actions `authorize` grants the requesting user. */
|
|
64
66
|
allowed: Action[];
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { onMount } from 'svelte';
|
|
15
15
|
import { SvelteSet } from 'svelte/reactivity';
|
|
16
|
-
import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
16
|
+
import type { AttributeInputs, BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
17
17
|
import type { ImageSource } from 'uncial/editor';
|
|
18
18
|
import type { Site } from '../define-site.js';
|
|
19
19
|
import type { EditorController, RecordState, StatusView } from '../editor-controller.js';
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
presentation?: 'card' | 'bare';
|
|
48
48
|
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
49
49
|
imageSource?: ImageSource;
|
|
50
|
+
/** Forwarded to `Editor`: Svelte components for host-defined attribute `input` kinds. */
|
|
51
|
+
attributeInputs?: AttributeInputs;
|
|
50
52
|
/** Where the host previews a Draft; the editing view links there when given. */
|
|
51
53
|
previewUrl?: (sourcePath: string) => string;
|
|
52
54
|
/** The record moved, by a save that derived a new path or by Move; reopen it at `sourcePath`. */
|
|
@@ -65,6 +67,7 @@
|
|
|
65
67
|
attributesPanel = 'overlay',
|
|
66
68
|
presentation = 'bare',
|
|
67
69
|
imageSource,
|
|
70
|
+
attributeInputs,
|
|
68
71
|
previewUrl,
|
|
69
72
|
onMoved,
|
|
70
73
|
movable = false
|
|
@@ -391,6 +394,7 @@
|
|
|
391
394
|
{attributesPanel}
|
|
392
395
|
{presentation}
|
|
393
396
|
imageSource={resolvedImageSource}
|
|
397
|
+
{attributeInputs}
|
|
394
398
|
onChange={(next) => controller?.documentChanged(next as ContentDocument)}
|
|
395
399
|
/>
|
|
396
400
|
{/if}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockRegistry, ContentSchema } from 'uncial/core';
|
|
1
|
+
import type { AttributeInputs, BlockRegistry, ContentSchema } from 'uncial/core';
|
|
2
2
|
import type { ImageSource } from 'uncial/editor';
|
|
3
3
|
import type { Site } from '../define-site.js';
|
|
4
4
|
import type { SessionProvider } from '../types.js';
|
|
@@ -20,6 +20,8 @@ interface Props {
|
|
|
20
20
|
presentation?: 'card' | 'bare';
|
|
21
21
|
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
22
22
|
imageSource?: ImageSource;
|
|
23
|
+
/** Forwarded to `Editor`: Svelte components for host-defined attribute `input` kinds. */
|
|
24
|
+
attributeInputs?: AttributeInputs;
|
|
23
25
|
/** Where the host previews a Draft; the editing view links there when given. */
|
|
24
26
|
previewUrl?: (sourcePath: string) => string;
|
|
25
27
|
/** The record moved, by a save that derived a new path or by Move; reopen it at `sourcePath`. */
|
|
@@ -1,37 +1,60 @@
|
|
|
1
|
+
<svelte:options css="injected" />
|
|
2
|
+
|
|
1
3
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { deleteMedia, listMedia, uploadMedia } from '../server-forge/media.js';
|
|
9
|
-
import type { MediaListView } from '../server-forge/protocol.js';
|
|
4
|
+
import { onMount, tick } from 'svelte';
|
|
5
|
+
import { resolveImageSrc } from 'uncial/render';
|
|
6
|
+
import { serverMediaSource, type MediaItem, type MediaSource } from '../media-source.js';
|
|
7
|
+
import type { Action } from '../server-forge/protocol.js';
|
|
8
|
+
|
|
9
|
+
type MediaAction = 'media-upload' | 'media-delete';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
source?: MediaSource;
|
|
13
|
+
/** @deprecated Pass `source`; this builds the `server` forge's source over its `mediaApiBase`. */
|
|
14
|
+
apiBase?: string;
|
|
15
|
+
can?: (action: MediaAction, item?: MediaItem) => boolean;
|
|
16
|
+
confirmDelete?: (item: MediaItem) => Promise<boolean>;
|
|
17
|
+
/** The site's base path, for previewing the base-less URLs a git forge's items carry. */
|
|
18
|
+
base?: string;
|
|
19
|
+
onerror?: (error: unknown) => void;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
let { apiBase }: Props = $props();
|
|
22
|
+
let { source, apiBase, can, confirmDelete, base = '', onerror }: Props = $props();
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
let allowed = $state<Action[]>([]);
|
|
25
|
+
const media = $derived.by(() => {
|
|
26
|
+
if (source) return source;
|
|
27
|
+
if (!apiBase) throw new Error('MediaLibrary needs a `source`.');
|
|
28
|
+
return serverMediaSource(apiBase, (next) => (allowed = next));
|
|
29
|
+
});
|
|
30
|
+
const capabilities = $derived(media.capabilities);
|
|
19
31
|
|
|
20
32
|
let search = $state('');
|
|
21
|
-
let
|
|
33
|
+
let items = $state<MediaItem[] | undefined>(undefined);
|
|
22
34
|
let error = $state('');
|
|
23
35
|
let uploading = $state(0);
|
|
24
36
|
let fileInput = $state<HTMLInputElement>();
|
|
37
|
+
let section = $state<HTMLElement>();
|
|
25
38
|
let request = 0;
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
const
|
|
40
|
+
// Under the deprecated `apiBase`, the server's own answer of what the user may do.
|
|
41
|
+
const may = (action: MediaAction, item?: MediaItem) =>
|
|
42
|
+
can ? can(action, item) : source !== undefined || allowed.includes(action);
|
|
43
|
+
const message = (reason: unknown) => {
|
|
44
|
+
onerror?.(reason);
|
|
45
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
46
|
+
};
|
|
47
|
+
const nameOf = (item: MediaItem) => (capabilities.metadata && item.title) || item.filename;
|
|
48
|
+
const ask = (item: MediaItem) =>
|
|
49
|
+
confirmDelete
|
|
50
|
+
? confirmDelete(item)
|
|
51
|
+
: Promise.resolve(confirm(`Delete “${nameOf(item)}”? This cannot be undone.`));
|
|
29
52
|
|
|
30
53
|
async function load() {
|
|
31
54
|
const current = ++request;
|
|
32
55
|
try {
|
|
33
|
-
const next = await
|
|
34
|
-
if (current === request)
|
|
56
|
+
const next = await media.list(capabilities.search ? { search: search.trim() } : {});
|
|
57
|
+
if (current === request) items = next;
|
|
35
58
|
} catch (reason) {
|
|
36
59
|
if (current === request) error = message(reason);
|
|
37
60
|
}
|
|
@@ -43,7 +66,7 @@
|
|
|
43
66
|
try {
|
|
44
67
|
for (const file of files) {
|
|
45
68
|
try {
|
|
46
|
-
await
|
|
69
|
+
await media.upload(file);
|
|
47
70
|
} catch (reason) {
|
|
48
71
|
error = `${file.name}: ${message(reason)}`;
|
|
49
72
|
} finally {
|
|
@@ -55,15 +78,20 @@
|
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
80
|
|
|
58
|
-
async function remove(item:
|
|
59
|
-
if (!confirm(`Delete “${item.title}”? This cannot be undone.`)) return;
|
|
81
|
+
async function remove(item: MediaItem) {
|
|
60
82
|
error = '';
|
|
61
83
|
try {
|
|
62
|
-
await
|
|
84
|
+
if (!(await ask(item))) return;
|
|
85
|
+
await media.delete(item);
|
|
63
86
|
} catch (reason) {
|
|
64
87
|
error = message(reason);
|
|
88
|
+
await load();
|
|
89
|
+
return;
|
|
65
90
|
}
|
|
66
91
|
await load();
|
|
92
|
+
// The deleted item's button went with it.
|
|
93
|
+
await tick();
|
|
94
|
+
section?.focus();
|
|
67
95
|
}
|
|
68
96
|
|
|
69
97
|
function size(bytes: number): string {
|
|
@@ -72,24 +100,36 @@
|
|
|
72
100
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
73
101
|
}
|
|
74
102
|
|
|
75
|
-
function
|
|
76
|
-
|
|
103
|
+
function details(item: MediaItem): string {
|
|
104
|
+
const dimensions = item.width && item.height ? `${item.width}×${item.height}` : '';
|
|
105
|
+
return [item.filename, dimensions, item.size === undefined ? '' : size(item.size)]
|
|
106
|
+
.filter(Boolean)
|
|
107
|
+
.join(' · ');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function usage(item: MediaItem): string {
|
|
111
|
+
const uses = item.usage ?? [];
|
|
112
|
+
if (uses.length === 0) return 'Not in use';
|
|
113
|
+
const paths = uses.map((use) => use.title || use.path).join(', ');
|
|
114
|
+
return `In use by ${uses.length} Content document${uses.length === 1 ? '' : 's'}: ${paths}`;
|
|
77
115
|
}
|
|
78
116
|
|
|
79
117
|
onMount(() => void load());
|
|
80
118
|
</script>
|
|
81
119
|
|
|
82
|
-
<section class="uncial-cms-media" aria-label="Media library">
|
|
120
|
+
<section bind:this={section} class="uncial-cms-media" aria-label="Media library" tabindex="-1">
|
|
83
121
|
<div class="uncial-cms-media-toolbar">
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
{#if capabilities.search}
|
|
123
|
+
<input
|
|
124
|
+
type="search"
|
|
125
|
+
class="uncial-cms-media-search"
|
|
126
|
+
placeholder="Search by title or filename"
|
|
127
|
+
aria-label="Search media"
|
|
128
|
+
bind:value={search}
|
|
129
|
+
oninput={() => void load()}
|
|
130
|
+
/>
|
|
131
|
+
{/if}
|
|
132
|
+
{#if may('media-upload')}
|
|
93
133
|
<input
|
|
94
134
|
bind:this={fileInput}
|
|
95
135
|
type="file"
|
|
@@ -102,7 +142,12 @@
|
|
|
102
142
|
if (files.length) void upload(files);
|
|
103
143
|
}}
|
|
104
144
|
/>
|
|
105
|
-
<button
|
|
145
|
+
<button
|
|
146
|
+
type="button"
|
|
147
|
+
class="uncial-cms-media-upload"
|
|
148
|
+
disabled={uploading > 0}
|
|
149
|
+
onclick={() => fileInput?.click()}
|
|
150
|
+
>
|
|
106
151
|
Upload
|
|
107
152
|
</button>
|
|
108
153
|
{/if}
|
|
@@ -115,35 +160,39 @@
|
|
|
115
160
|
<p class="uncial-cms-media-error" role="alert">{error}</p>
|
|
116
161
|
{/if}
|
|
117
162
|
|
|
118
|
-
{#if
|
|
163
|
+
{#if items === undefined}
|
|
119
164
|
{#if !error}<p role="status">Loading media…</p>{/if}
|
|
120
|
-
{:else if
|
|
165
|
+
{:else if items.length === 0}
|
|
121
166
|
<p>{search.trim() ? 'No media matches that search.' : 'No media yet.'}</p>
|
|
122
167
|
{:else}
|
|
123
168
|
<ul class="uncial-cms-media-grid">
|
|
124
|
-
{#each
|
|
169
|
+
{#each items as item (item.id)}
|
|
125
170
|
<li class="uncial-cms-media-item">
|
|
126
|
-
<a
|
|
171
|
+
<a
|
|
172
|
+
class="uncial-cms-media-preview"
|
|
173
|
+
href={resolveImageSrc(item.url, base)}
|
|
174
|
+
target="_blank"
|
|
175
|
+
rel="noopener"
|
|
176
|
+
aria-label="Open {nameOf(item)}"
|
|
177
|
+
>
|
|
127
178
|
{#if item.contentType.startsWith('image/')}
|
|
128
|
-
<img src={item.url} alt="" loading="lazy" />
|
|
179
|
+
<img src={resolveImageSrc(item.url, base)} alt="" loading="lazy" />
|
|
129
180
|
{:else}
|
|
130
|
-
<span>{item.
|
|
181
|
+
<span>{item.filename.split('.').at(-1)?.toUpperCase()}</span>
|
|
131
182
|
{/if}
|
|
132
183
|
</a>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
</p>
|
|
142
|
-
{#if can('media-delete')}
|
|
184
|
+
{#if capabilities.metadata}
|
|
185
|
+
<p class="uncial-cms-media-title">{item.title}</p>
|
|
186
|
+
{/if}
|
|
187
|
+
<p class="uncial-cms-media-meta">{details(item)}</p>
|
|
188
|
+
{#if capabilities.usage}
|
|
189
|
+
<p class="uncial-cms-media-usage">{usage(item)}</p>
|
|
190
|
+
{/if}
|
|
191
|
+
{#if capabilities.delete && may('media-delete', item)}
|
|
143
192
|
<button
|
|
144
193
|
type="button"
|
|
145
|
-
|
|
146
|
-
|
|
194
|
+
class="uncial-cms-media-delete"
|
|
195
|
+
aria-label="Delete {nameOf(item)}"
|
|
147
196
|
onclick={() => void remove(item)}
|
|
148
197
|
>
|
|
149
198
|
Delete
|
|
@@ -181,7 +230,14 @@
|
|
|
181
230
|
object-fit: cover;
|
|
182
231
|
}
|
|
183
232
|
|
|
184
|
-
.uncial-cms-media-meta
|
|
233
|
+
.uncial-cms-media-meta,
|
|
234
|
+
.uncial-cms-media-usage {
|
|
185
235
|
overflow-wrap: anywhere;
|
|
186
236
|
}
|
|
237
|
+
|
|
238
|
+
@media (max-width: 40rem) {
|
|
239
|
+
.uncial-cms-media-grid {
|
|
240
|
+
grid-template-columns: minmax(0, 1fr);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
187
243
|
</style>
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { type MediaItem, type MediaSource } from '../media-source.js';
|
|
2
|
+
type MediaAction = 'media-upload' | 'media-delete';
|
|
1
3
|
interface Props {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
source?: MediaSource;
|
|
5
|
+
/** @deprecated Pass `source`; this builds the `server` forge's source over its `mediaApiBase`. */
|
|
6
|
+
apiBase?: string;
|
|
7
|
+
can?: (action: MediaAction, item?: MediaItem) => boolean;
|
|
8
|
+
confirmDelete?: (item: MediaItem) => Promise<boolean>;
|
|
9
|
+
/** The site's base path, for previewing the base-less URLs a git forge's items carry. */
|
|
10
|
+
base?: string;
|
|
11
|
+
onerror?: (error: unknown) => void;
|
|
4
12
|
}
|
|
5
13
|
declare const MediaLibrary: import("svelte").Component<Props, {}, "">;
|
|
6
14
|
type MediaLibrary = ReturnType<typeof MediaLibrary>;
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* `uncial-cms/svelte` — the SvelteKit door. `svelte` is a peer of this subpath
|
|
3
|
-
* only; the runtime root still imports no Svelte.
|
|
4
|
-
*/
|
|
1
|
+
export { default as Dashboard } from '../dashboard/Dashboard.svelte';
|
|
5
2
|
export { default as EditorPage } from './EditorPage.svelte';
|
|
6
3
|
export { default as MediaLibrary } from './MediaLibrary.svelte';
|
package/dist/svelte/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* `uncial-cms/svelte` — the SvelteKit door. `svelte` is a peer of this subpath
|
|
3
|
-
* only; the runtime root still imports no Svelte.
|
|
4
|
-
*/
|
|
1
|
+
export { default as Dashboard } from '../dashboard/Dashboard.svelte';
|
|
5
2
|
export { default as EditorPage } from './EditorPage.svelte';
|
|
6
3
|
export { default as MediaLibrary } from './MediaLibrary.svelte';
|
|
@@ -2,6 +2,8 @@ import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core'
|
|
|
2
2
|
import type { Site } from '../define-site.js';
|
|
3
3
|
import type { UncialCmsSiteConfig } from '../types.js';
|
|
4
4
|
export { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
5
|
+
export { loadGlobal, type GlobalStore } from '../content-sources.js';
|
|
6
|
+
export type { GlobalValue } from '../globals.js';
|
|
5
7
|
/** A content file as the factories see it: site-relative path, repo-root-relative source. */
|
|
6
8
|
export interface ContentEntry {
|
|
7
9
|
path: string;
|
|
@@ -13,7 +15,6 @@ interface HandlerOptionsBase {
|
|
|
13
15
|
schema: ContentSchema | ((path: string) => ContentSchema);
|
|
14
16
|
/** Site-relative URL path → repo-root-relative JSON path. */
|
|
15
17
|
mapPathToSource?: (path: string) => string;
|
|
16
|
-
/** Keep a non-page file — site settings, a manifest — out of the routes. */
|
|
17
18
|
exclude?: (entry: ContentEntry) => boolean;
|
|
18
19
|
}
|
|
19
20
|
/** The site object from `defineSite`, or the resolved config plus its build-time FS path. */
|
|
@@ -36,8 +37,17 @@ export type IndexHandlerOptions<Config extends UncialCmsSiteConfig = UncialCmsSi
|
|
|
36
37
|
interface RouteEntry {
|
|
37
38
|
path: string;
|
|
38
39
|
}
|
|
40
|
+
/** A content document ready to render, with the paths an editor route needs. */
|
|
41
|
+
export interface ContentPage {
|
|
42
|
+
path: string;
|
|
43
|
+
/** Repo-root-relative, as the forge addresses it. */
|
|
44
|
+
sourcePath: string;
|
|
45
|
+
document: ContentDocument;
|
|
46
|
+
}
|
|
39
47
|
export declare function createContentHandlers(opts: ContentHandlerOptions): {
|
|
40
48
|
entries: () => RouteEntry[];
|
|
49
|
+
/** Every content document, normalized, in source order. */
|
|
50
|
+
list: () => ContentPage[];
|
|
41
51
|
load: (event: {
|
|
42
52
|
params: {
|
|
43
53
|
path: string;
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -9,8 +9,10 @@ import { readFileSync } from 'node:fs';
|
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { normalizeDocument } from 'uncial/core';
|
|
11
11
|
import { listContentSources } from '../content-sources.js';
|
|
12
|
+
import { isGlobalsPath } from '../globals.js';
|
|
12
13
|
import { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
13
14
|
export { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
15
|
+
export { loadGlobal } from '../content-sources.js';
|
|
14
16
|
function resolveSite(opts) {
|
|
15
17
|
const config = opts.site ? opts.site.config : opts.config;
|
|
16
18
|
if (config.forge === 'server') {
|
|
@@ -21,20 +23,25 @@ function resolveSite(opts) {
|
|
|
21
23
|
}
|
|
22
24
|
return { config, localContentDir: opts.localContentDir, localOnly: false };
|
|
23
25
|
}
|
|
24
|
-
function
|
|
25
|
-
return ()
|
|
26
|
+
function excluded(opts, entry) {
|
|
27
|
+
return isGlobalsPath(entry.path) || (opts.exclude?.(entry) ?? false);
|
|
28
|
+
}
|
|
29
|
+
function listEntries(opts, site) {
|
|
30
|
+
return listContentSources(site.localContentDir)
|
|
26
31
|
.map((rel) => {
|
|
27
32
|
const source = `${site.config.contentDir}/${rel}`;
|
|
28
33
|
return { path: defaultMapSourceToPath(source, site.config.contentDir), source };
|
|
29
34
|
})
|
|
30
|
-
.filter((entry) => !opts
|
|
31
|
-
|
|
35
|
+
.filter((entry) => !excluded(opts, entry));
|
|
36
|
+
}
|
|
37
|
+
function createEntries(opts, site) {
|
|
38
|
+
return () => listEntries(opts, site).map(({ path }) => ({ path }));
|
|
32
39
|
}
|
|
33
40
|
/** The source for a site path, refusing one the site's `exclude` rules out. */
|
|
34
41
|
function resolveSource(opts, site, sitePath) {
|
|
35
42
|
const map = opts.mapPathToSource ?? ((path) => defaultMapPathToSource(path, site.config.contentDir));
|
|
36
43
|
const source = map(sitePath);
|
|
37
|
-
if (opts
|
|
44
|
+
if (excluded(opts, { path: sitePath, source })) {
|
|
38
45
|
throw new Error(`Content path "${sitePath}" is excluded from this site's routes.`);
|
|
39
46
|
}
|
|
40
47
|
return source;
|
|
@@ -52,13 +59,20 @@ function contentDirRelative(source, contentDir) {
|
|
|
52
59
|
}
|
|
53
60
|
export function createContentHandlers(opts) {
|
|
54
61
|
const site = resolveSite(opts);
|
|
62
|
+
const read = (path, source) => {
|
|
63
|
+
const rel = contentDirRelative(source, site.config.contentDir);
|
|
64
|
+
const raw = readFileSync(join(site.localContentDir, rel), 'utf-8');
|
|
65
|
+
return normalizeDocument(JSON.parse(raw), opts.blocks, schemaFor(opts, path));
|
|
66
|
+
};
|
|
55
67
|
return {
|
|
56
68
|
entries: createEntries(opts, site),
|
|
69
|
+
list: () => listEntries(opts, site).map(({ path, source }) => ({
|
|
70
|
+
path,
|
|
71
|
+
sourcePath: source,
|
|
72
|
+
document: read(path, source)
|
|
73
|
+
})),
|
|
57
74
|
load: async ({ params }) => {
|
|
58
|
-
const
|
|
59
|
-
const rel = contentDirRelative(source, site.config.contentDir);
|
|
60
|
-
const raw = readFileSync(join(site.localContentDir, rel), 'utf-8');
|
|
61
|
-
const document = normalizeDocument(JSON.parse(raw), opts.blocks, schemaFor(opts, params.path));
|
|
75
|
+
const document = read(params.path, resolveSource(opts, site, params.path));
|
|
62
76
|
return { document, meta: document.meta ?? {}, path: params.path };
|
|
63
77
|
}
|
|
64
78
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -6,11 +6,13 @@ export interface GitHubSiteConfig {
|
|
|
6
6
|
authWorkerUrl: string;
|
|
7
7
|
appSlug: string;
|
|
8
8
|
mediaDir?: string;
|
|
9
|
+
mediaUrlPrefix?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface LocalSiteConfig {
|
|
11
12
|
forge: 'local';
|
|
12
13
|
contentDir: string;
|
|
13
14
|
mediaDir?: string;
|
|
15
|
+
mediaUrlPrefix?: string;
|
|
14
16
|
}
|
|
15
17
|
export interface ServerSiteConfig {
|
|
16
18
|
forge: 'server';
|
package/dist/upload-context.d.ts
CHANGED
|
@@ -24,3 +24,4 @@ export declare function clearActiveForge(): void;
|
|
|
24
24
|
export declare function getActiveForge(): ActiveForge | null;
|
|
25
25
|
/** The git forges commit media under `mediaDir`; the server forge has none. */
|
|
26
26
|
export declare function configMediaDir(config: UncialCmsSiteConfig): string | undefined;
|
|
27
|
+
export declare function configMediaUrlPrefix(config: UncialCmsSiteConfig): string | undefined;
|
package/dist/upload-context.js
CHANGED
|
@@ -12,3 +12,6 @@ export function getActiveForge() {
|
|
|
12
12
|
export function configMediaDir(config) {
|
|
13
13
|
return config.forge === 'server' ? undefined : config.mediaDir;
|
|
14
14
|
}
|
|
15
|
+
export function configMediaUrlPrefix(config) {
|
|
16
|
+
return config.forge === 'server' ? undefined : config.mediaUrlPrefix;
|
|
17
|
+
}
|
package/dist/vite/index.js
CHANGED
|
@@ -29,15 +29,29 @@ function repositoryRoot(options) {
|
|
|
29
29
|
function trimSlashes(path) {
|
|
30
30
|
return path.replace(/^\/+|\/+$/g, '');
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
createLocalVitePlugin({
|
|
32
|
+
function localPlugin(options) {
|
|
33
|
+
if (options.localMediaDir === undefined) {
|
|
34
|
+
return createLocalVitePlugin({
|
|
35
35
|
root: repositoryRoot(options),
|
|
36
36
|
permittedRoots: [
|
|
37
37
|
trimSlashes(options.contentDir),
|
|
38
38
|
...(options.mediaDir ? [trimSlashes(options.mediaDir)] : [])
|
|
39
39
|
]
|
|
40
|
-
})
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!options.mediaDir)
|
|
43
|
+
throw new Error('localMediaDir needs the mediaDir it is the local copy of.');
|
|
44
|
+
return createLocalVitePlugin({
|
|
45
|
+
root: resolve(options.localContentDir ?? options.contentDir),
|
|
46
|
+
permittedRoots: [
|
|
47
|
+
{ path: options.contentDir, local: options.localContentDir ?? options.contentDir },
|
|
48
|
+
{ path: options.mediaDir, local: options.localMediaDir }
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function uncialCms(options) {
|
|
53
|
+
return [
|
|
54
|
+
localPlugin(options),
|
|
41
55
|
{
|
|
42
56
|
name: 'uncial-cms:forge',
|
|
43
57
|
config(_config, env) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uncial-cms",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"!dist/**/*.spec.*"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
26
|
-
"sideEffects":
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./dist/dashboard/element.js"
|
|
28
|
+
],
|
|
27
29
|
"types": "./dist/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
@@ -35,6 +37,11 @@
|
|
|
35
37
|
"types": "./dist/editor-session.d.ts",
|
|
36
38
|
"default": "./dist/editor-session.js"
|
|
37
39
|
},
|
|
40
|
+
"./dashboard": {
|
|
41
|
+
"types": "./dist/dashboard/element.d.ts",
|
|
42
|
+
"svelte": "./dist/dashboard/element.js",
|
|
43
|
+
"default": "./dist/dashboard/element.js"
|
|
44
|
+
},
|
|
38
45
|
"./svelte": {
|
|
39
46
|
"types": "./dist/svelte/index.d.ts",
|
|
40
47
|
"svelte": "./dist/svelte/index.js",
|
|
@@ -48,6 +55,10 @@
|
|
|
48
55
|
"types": "./dist/local/index.d.ts",
|
|
49
56
|
"default": "./dist/local/index.js"
|
|
50
57
|
},
|
|
58
|
+
"./nav": {
|
|
59
|
+
"types": "./dist/nav/index.d.ts",
|
|
60
|
+
"default": "./dist/nav/index.js"
|
|
61
|
+
},
|
|
51
62
|
"./paths": {
|
|
52
63
|
"types": "./dist/paths/index.d.ts",
|
|
53
64
|
"default": "./dist/paths/index.js"
|
|
@@ -78,7 +89,7 @@
|
|
|
78
89
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
79
90
|
"postgres": "^3.4.0",
|
|
80
91
|
"svelte": "^5.0.0",
|
|
81
|
-
"uncial": "^5.
|
|
92
|
+
"uncial": "^5.2.0"
|
|
82
93
|
},
|
|
83
94
|
"peerDependenciesMeta": {
|
|
84
95
|
"@aws-sdk/client-s3": {
|
|
@@ -91,6 +102,7 @@
|
|
|
91
102
|
"devDependencies": {
|
|
92
103
|
"@astrojs/svelte": "^7.2.5",
|
|
93
104
|
"@aws-sdk/client-s3": "^3.1144.0",
|
|
105
|
+
"@axe-core/playwright": "^4.13.0",
|
|
94
106
|
"@playwright/test": "^1.58.2",
|
|
95
107
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
96
108
|
"@sveltejs/kit": "^2.50.2",
|
|
@@ -124,6 +136,7 @@
|
|
|
124
136
|
"test": "pnpm run test:unit -- --run && pnpm run test:browser -- --run && pnpm run test:e2e",
|
|
125
137
|
"test:e2e": "playwright test",
|
|
126
138
|
"test:cli": "node scripts/test-local-only-cli.mjs",
|
|
139
|
+
"test:astro": "playwright test --project astro",
|
|
127
140
|
"test:browser": "vitest --project client"
|
|
128
141
|
}
|
|
129
142
|
}
|