uncial-cms 4.0.3 → 5.1.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 +1 -1
- package/dist/define-site.d.ts +13 -4
- package/dist/define-site.js +10 -0
- package/dist/editor-controller.d.ts +25 -0
- package/dist/editor-controller.js +174 -14
- package/dist/editor-session.d.ts +1 -1
- package/dist/editor-session.js +9 -1
- package/dist/image-source.d.ts +2 -1
- package/dist/image-source.js +19 -5
- package/dist/index-actions.js +3 -3
- package/dist/index-page.d.ts +2 -0
- package/dist/index-page.js +38 -20
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/local/vite.d.ts +2 -0
- package/dist/local/vite.js +1 -1
- package/dist/served-url.js +2 -1
- package/dist/server/handlers.d.ts +45 -0
- package/dist/server/handlers.js +237 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +4 -0
- package/dist/server/media.d.ts +69 -0
- package/dist/server/media.js +181 -0
- package/dist/server/migrations.d.ts +8 -0
- package/dist/server/migrations.js +47 -0
- package/dist/server/postgres-store.d.ts +72 -0
- package/dist/server/postgres-store.js +201 -0
- package/dist/server-forge/adapter.d.ts +17 -0
- package/dist/server-forge/adapter.js +95 -0
- package/dist/server-forge/media.d.ts +11 -0
- package/dist/server-forge/media.js +26 -0
- package/dist/server-forge/protocol.d.ts +65 -0
- package/dist/server-forge/protocol.js +27 -0
- package/dist/server-forge/session.d.ts +2 -0
- package/dist/server-forge/session.js +15 -0
- package/dist/svelte/EditorPage.svelte +217 -7
- package/dist/svelte/EditorPage.svelte.d.ts +6 -0
- package/dist/svelte/MediaLibrary.svelte +187 -0
- package/dist/svelte/MediaLibrary.svelte.d.ts +7 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/sveltekit/index.d.ts +7 -7
- package/dist/sveltekit/index.js +6 -6
- package/dist/types.d.ts +7 -1
- package/dist/upload-context.d.ts +2 -0
- package/dist/upload-context.js +4 -0
- package/package.json +18 -2
|
@@ -12,12 +12,20 @@
|
|
|
12
12
|
* that boundary, so the site has to restate every one of them.
|
|
13
13
|
*/
|
|
14
14
|
import { onMount } from 'svelte';
|
|
15
|
+
import { SvelteSet } from 'svelte/reactivity';
|
|
15
16
|
import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
|
|
16
17
|
import type { ImageSource } from 'uncial/editor';
|
|
17
18
|
import type { Site } from '../define-site.js';
|
|
18
|
-
import type { EditorController, StatusView } from '../editor-controller.js';
|
|
19
|
+
import type { EditorController, RecordState, StatusView } from '../editor-controller.js';
|
|
19
20
|
import { cmsImageSource } from '../image-source.js';
|
|
21
|
+
import { isMediaUrl, listMedia } from '../server-forge/media.js';
|
|
20
22
|
import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
|
|
23
|
+
import {
|
|
24
|
+
contentStatus,
|
|
25
|
+
describeContentStatus,
|
|
26
|
+
type Action,
|
|
27
|
+
type VersionView
|
|
28
|
+
} from '../server-forge/protocol.js';
|
|
21
29
|
import type { SessionProvider } from '../types.js';
|
|
22
30
|
import { clearActiveForge } from '../upload-context.js';
|
|
23
31
|
|
|
@@ -39,6 +47,12 @@
|
|
|
39
47
|
presentation?: 'card' | 'bare';
|
|
40
48
|
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
41
49
|
imageSource?: ImageSource;
|
|
50
|
+
/** Where the host previews a Draft; the editing view links there when given. */
|
|
51
|
+
previewUrl?: (sourcePath: string) => string;
|
|
52
|
+
/** The record moved, by a save that derived a new path or by Move; reopen it at `sourcePath`. */
|
|
53
|
+
onMoved?: (sourcePath: string) => void;
|
|
54
|
+
/** Offer Move, for records whose path an author chooses rather than one their metadata derives. */
|
|
55
|
+
movable?: boolean;
|
|
42
56
|
}
|
|
43
57
|
|
|
44
58
|
let {
|
|
@@ -50,19 +64,59 @@
|
|
|
50
64
|
sessionProvider,
|
|
51
65
|
attributesPanel = 'overlay',
|
|
52
66
|
presentation = 'bare',
|
|
53
|
-
imageSource
|
|
67
|
+
imageSource,
|
|
68
|
+
previewUrl,
|
|
69
|
+
onMoved,
|
|
70
|
+
movable = false
|
|
54
71
|
}: Props = $props();
|
|
55
72
|
|
|
56
73
|
const resolvedSchema = $derived(typeof schema === 'function' ? schema(pagePath) : schema);
|
|
57
74
|
// Autosave leaves nothing to press; a forge commit is never autosaved, so a
|
|
58
75
|
// Save button and autosave are exactly the two modes.
|
|
59
76
|
const manualSave = $derived(site.autosaveMs === undefined);
|
|
60
|
-
const
|
|
77
|
+
const mediaApiBase = $derived(site.config.forge === 'server' ? site.config.mediaApiBase : undefined);
|
|
78
|
+
// The Media library's URLs, so the editing view can flag media that is gone.
|
|
79
|
+
let library = $state<SvelteSet<string> | undefined>(undefined);
|
|
80
|
+
let libraryChecked = $state(false);
|
|
81
|
+
const isMissing = (src: string) => (library ? isMediaUrl(src) && !library.has(src) : false);
|
|
82
|
+
const resolvedImageSource = $derived.by((): ImageSource => {
|
|
83
|
+
const source = imageSource ?? cmsImageSource(site.config);
|
|
84
|
+
const { upload } = source;
|
|
85
|
+
if (!mediaApiBase) return source;
|
|
86
|
+
return {
|
|
87
|
+
...source,
|
|
88
|
+
upload:
|
|
89
|
+
upload &&
|
|
90
|
+
(async (file) => {
|
|
91
|
+
const src = await upload(file);
|
|
92
|
+
library?.add(src);
|
|
93
|
+
return src;
|
|
94
|
+
}),
|
|
95
|
+
missing: isMissing
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
const missingMedia = $derived.by(() => {
|
|
99
|
+
const found = new Set<string>();
|
|
100
|
+
const walk = (value: unknown): void => {
|
|
101
|
+
if (typeof value === 'string') {
|
|
102
|
+
if (isMissing(value)) found.add(value);
|
|
103
|
+
} else if (value && typeof value === 'object') {
|
|
104
|
+
Object.values(value).forEach(walk);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
walk(doc);
|
|
108
|
+
return [...found];
|
|
109
|
+
});
|
|
61
110
|
const branch = $derived(
|
|
62
|
-
site.config.forge === 'github'
|
|
111
|
+
site.config.forge === 'github'
|
|
112
|
+
? site.config.branch
|
|
113
|
+
: site.config.forge === 'server'
|
|
114
|
+
? 'the server'
|
|
115
|
+
: 'the local checkout'
|
|
63
116
|
);
|
|
64
117
|
|
|
65
118
|
type EditorComponent = (typeof import('uncial/editor'))['Editor'];
|
|
119
|
+
type RendererComponent = (typeof import('uncial/render'))['Renderer'];
|
|
66
120
|
|
|
67
121
|
let Editor = $state<EditorComponent | undefined>(undefined);
|
|
68
122
|
let doc = $state<ContentDocument | undefined>(undefined);
|
|
@@ -70,9 +124,50 @@
|
|
|
70
124
|
let status = $state<StatusView | undefined>(undefined);
|
|
71
125
|
let conflict = $state(false);
|
|
72
126
|
let saveEnabled = $state(false);
|
|
127
|
+
let record = $state<RecordState | undefined>(undefined);
|
|
128
|
+
let deleted = $state(false);
|
|
129
|
+
const can = (action: Action) => record?.allowed.includes(action) ?? false;
|
|
130
|
+
let moveTo = $state<string | undefined>(undefined);
|
|
131
|
+
let historyOpen = $state(false);
|
|
132
|
+
let versions = $state<VersionView[] | undefined>(undefined);
|
|
133
|
+
let selected = $state<{ id: string; doc: ContentDocument } | undefined>(undefined);
|
|
134
|
+
let Renderer = $state<RendererComponent | undefined>(undefined);
|
|
73
135
|
let controller: EditorController | undefined;
|
|
74
136
|
let root: HTMLDivElement;
|
|
75
137
|
|
|
138
|
+
const failed = (error: unknown, fallback: string) =>
|
|
139
|
+
(status = { tone: 'error', text: error instanceof Error ? error.message : fallback });
|
|
140
|
+
|
|
141
|
+
function closeHistory() {
|
|
142
|
+
historyOpen = false;
|
|
143
|
+
versions = undefined;
|
|
144
|
+
selected = undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function openHistory() {
|
|
148
|
+
if (!controller) return;
|
|
149
|
+
historyOpen = true;
|
|
150
|
+
try {
|
|
151
|
+
const [list, render] = await Promise.all([controller.history(), import('uncial/render')]);
|
|
152
|
+
versions = list;
|
|
153
|
+
Renderer = render.Renderer;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
failed(error, 'Failed to load the history.');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function select(versionId: string) {
|
|
160
|
+
try {
|
|
161
|
+
selected = { id: versionId, doc: await controller!.version(versionId) };
|
|
162
|
+
} catch (error) {
|
|
163
|
+
failed(error, 'Failed to load the Version.');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function restore(versionId: string) {
|
|
168
|
+
if (await controller?.restore(versionId)) closeHistory();
|
|
169
|
+
}
|
|
170
|
+
|
|
76
171
|
onMount(() => {
|
|
77
172
|
// The editor stack hangs off dynamic imports behind a statically decidable
|
|
78
173
|
// condition, so a local-only production build has no reachable path to it
|
|
@@ -87,6 +182,16 @@
|
|
|
87
182
|
|
|
88
183
|
let cancelled = false;
|
|
89
184
|
|
|
185
|
+
if (mediaApiBase) {
|
|
186
|
+
listMedia(mediaApiBase)
|
|
187
|
+
.then((view) => (library = new SvelteSet(view.items.map((item) => item.url))))
|
|
188
|
+
// Without the list nothing can be flagged missing; the editor still opens.
|
|
189
|
+
.catch(() => {})
|
|
190
|
+
.finally(() => (libraryChecked = true));
|
|
191
|
+
} else {
|
|
192
|
+
libraryChecked = true;
|
|
193
|
+
}
|
|
194
|
+
|
|
90
195
|
void Promise.all([
|
|
91
196
|
import('uncial/editor'),
|
|
92
197
|
// The package's own session module, not the `uncial-cms/session`
|
|
@@ -119,7 +224,9 @@
|
|
|
119
224
|
meta = next.meta ?? {};
|
|
120
225
|
},
|
|
121
226
|
saveEnabled: (enabled) => (saveEnabled = enabled),
|
|
122
|
-
conflictVisible: (visible) => (conflict = visible)
|
|
227
|
+
conflictVisible: (visible) => (conflict = visible),
|
|
228
|
+
record: (next) => (record = next),
|
|
229
|
+
moved: (path) => onMoved?.(path)
|
|
123
230
|
}
|
|
124
231
|
});
|
|
125
232
|
void controller.load().catch((error: unknown) => {
|
|
@@ -141,11 +248,56 @@
|
|
|
141
248
|
|
|
142
249
|
<div class="uncial-cms-editor-page" bind:this={root}>
|
|
143
250
|
<div class="uncial-cms-chrome">
|
|
144
|
-
{#if manualSave}
|
|
251
|
+
{#if manualSave && !deleted}
|
|
145
252
|
<button type="button" disabled={!saveEnabled} onclick={() => void controller?.save()}>
|
|
146
253
|
Save
|
|
147
254
|
</button>
|
|
148
255
|
{/if}
|
|
256
|
+
{#if record && !deleted}
|
|
257
|
+
<p class="uncial-cms-record-status">
|
|
258
|
+
{describeContentStatus(contentStatus(record.draft, record.published))}
|
|
259
|
+
</p>
|
|
260
|
+
{#if can('publish')}
|
|
261
|
+
<button type="button" disabled={!saveEnabled} onclick={() => void controller?.publish()}>
|
|
262
|
+
Publish
|
|
263
|
+
</button>
|
|
264
|
+
{/if}
|
|
265
|
+
{#if can('unpublish') && record.published}
|
|
266
|
+
<button type="button" disabled={!saveEnabled} onclick={() => void controller?.unpublish()}>
|
|
267
|
+
Unpublish
|
|
268
|
+
</button>
|
|
269
|
+
{/if}
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
aria-expanded={historyOpen}
|
|
273
|
+
onclick={() => (historyOpen ? closeHistory() : void openHistory())}
|
|
274
|
+
>
|
|
275
|
+
History
|
|
276
|
+
</button>
|
|
277
|
+
{#if movable && can('move')}
|
|
278
|
+
<button
|
|
279
|
+
type="button"
|
|
280
|
+
aria-expanded={moveTo !== undefined}
|
|
281
|
+
onclick={() => (moveTo = moveTo === undefined ? sourcePath : undefined)}
|
|
282
|
+
>
|
|
283
|
+
Move
|
|
284
|
+
</button>
|
|
285
|
+
{/if}
|
|
286
|
+
{#if can('delete')}
|
|
287
|
+
<button
|
|
288
|
+
type="button"
|
|
289
|
+
disabled={!saveEnabled}
|
|
290
|
+
onclick={async () => (deleted = (await controller?.remove()) ?? false)}
|
|
291
|
+
>
|
|
292
|
+
Delete
|
|
293
|
+
</button>
|
|
294
|
+
{/if}
|
|
295
|
+
{/if}
|
|
296
|
+
{#if previewUrl && !deleted}
|
|
297
|
+
<a class="uncial-cms-preview" href={previewUrl(sourcePath)} target="_blank" rel="noopener">
|
|
298
|
+
Preview
|
|
299
|
+
</a>
|
|
300
|
+
{/if}
|
|
149
301
|
{#if status}
|
|
150
302
|
<p class="uncial-cms-status" role="status" data-tone={status.tone}>
|
|
151
303
|
{status.text}{#if status.href} <a href={status.href} target="_blank" rel="noopener"
|
|
@@ -155,6 +307,19 @@
|
|
|
155
307
|
{/if}
|
|
156
308
|
</div>
|
|
157
309
|
|
|
310
|
+
{#if moveTo !== undefined && !deleted}
|
|
311
|
+
<form
|
|
312
|
+
class="uncial-cms-move"
|
|
313
|
+
onsubmit={(event) => {
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
void controller?.move(moveTo!);
|
|
316
|
+
}}
|
|
317
|
+
>
|
|
318
|
+
<label>New path <input type="text" bind:value={moveTo} required /></label>
|
|
319
|
+
<button type="submit" disabled={!saveEnabled || moveTo === sourcePath}>Move here</button>
|
|
320
|
+
</form>
|
|
321
|
+
{/if}
|
|
322
|
+
|
|
158
323
|
{#if conflict}
|
|
159
324
|
<div class="uncial-cms-banner" role="alert">
|
|
160
325
|
<p class="uncial-cms-banner-message">
|
|
@@ -171,7 +336,52 @@
|
|
|
171
336
|
</div>
|
|
172
337
|
{/if}
|
|
173
338
|
|
|
174
|
-
{#if
|
|
339
|
+
{#if missingMedia.length > 0 && !deleted}
|
|
340
|
+
<div class="uncial-cms-banner uncial-cms-missing-media" role="alert">
|
|
341
|
+
<p class="uncial-cms-banner-message">
|
|
342
|
+
{missingMedia.length === 1 ? 'An image' : `${missingMedia.length} images`} on this page {missingMedia.length ===
|
|
343
|
+
1
|
|
344
|
+
? 'is'
|
|
345
|
+
: 'are'} no longer in the Media library. The editing view shows a placeholder; readers see no
|
|
346
|
+
image. Choose a replacement or clear it.
|
|
347
|
+
</p>
|
|
348
|
+
</div>
|
|
349
|
+
{/if}
|
|
350
|
+
|
|
351
|
+
{#if historyOpen && !deleted}
|
|
352
|
+
<section class="uncial-cms-history" aria-label="History">
|
|
353
|
+
{#if versions === undefined}
|
|
354
|
+
<p>Loading history…</p>
|
|
355
|
+
{:else if versions.length === 0}
|
|
356
|
+
<p>No earlier Versions yet. Each publish keeps the copy it replaces.</p>
|
|
357
|
+
{:else}
|
|
358
|
+
<ol class="uncial-cms-history-list">
|
|
359
|
+
{#each versions as version (version.id)}
|
|
360
|
+
<li>
|
|
361
|
+
<button
|
|
362
|
+
type="button"
|
|
363
|
+
aria-pressed={selected?.id === version.id}
|
|
364
|
+
onclick={() => void select(version.id)}
|
|
365
|
+
>
|
|
366
|
+
{new Date(version.createdAt).toLocaleString()} · {version.createdBy}
|
|
367
|
+
</button>
|
|
368
|
+
</li>
|
|
369
|
+
{/each}
|
|
370
|
+
</ol>
|
|
371
|
+
{/if}
|
|
372
|
+
{#if selected && Renderer}
|
|
373
|
+
{@const versionId = selected.id}
|
|
374
|
+
<div class="uncial-cms-version" aria-label="Selected Version">
|
|
375
|
+
{#if can('restore')}
|
|
376
|
+
<button type="button" onclick={() => void restore(versionId)}>Restore</button>
|
|
377
|
+
{/if}
|
|
378
|
+
<Renderer content={selected.doc} {blocks} schema={resolvedSchema} />
|
|
379
|
+
</div>
|
|
380
|
+
{/if}
|
|
381
|
+
</section>
|
|
382
|
+
{/if}
|
|
383
|
+
|
|
384
|
+
{#if Editor && doc && libraryChecked && !deleted}
|
|
175
385
|
<Editor
|
|
176
386
|
{blocks}
|
|
177
387
|
schema={resolvedSchema}
|
|
@@ -20,6 +20,12 @@ interface Props {
|
|
|
20
20
|
presentation?: 'card' | 'bare';
|
|
21
21
|
/** Forwarded to `Editor`; defaults to `cmsImageSource(site.config)`. */
|
|
22
22
|
imageSource?: ImageSource;
|
|
23
|
+
/** Where the host previews a Draft; the editing view links there when given. */
|
|
24
|
+
previewUrl?: (sourcePath: string) => string;
|
|
25
|
+
/** The record moved, by a save that derived a new path or by Move; reopen it at `sourcePath`. */
|
|
26
|
+
onMoved?: (sourcePath: string) => void;
|
|
27
|
+
/** Offer Move, for records whose path an author chooses rather than one their metadata derives. */
|
|
28
|
+
movable?: boolean;
|
|
23
29
|
}
|
|
24
30
|
declare const EditorPage: import("svelte").Component<Props, {}, "">;
|
|
25
31
|
type EditorPage = ReturnType<typeof EditorPage>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The Media library for a host's Dashboard: browse, search, upload and
|
|
4
|
+
* delete the items behind `createServerMediaHandlers`. Unstyled beyond its
|
|
5
|
+
* grid, like `EditorPage`; the host styles the `uncial-cms-media-*` classes.
|
|
6
|
+
*/
|
|
7
|
+
import { onMount } from 'svelte';
|
|
8
|
+
import { deleteMedia, listMedia, uploadMedia } from '../server-forge/media.js';
|
|
9
|
+
import type { MediaListView } from '../server-forge/protocol.js';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** The host's media endpoint, the `server` forge's `mediaApiBase`. */
|
|
13
|
+
apiBase: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { apiBase }: Props = $props();
|
|
17
|
+
|
|
18
|
+
type Item = MediaListView['items'][number];
|
|
19
|
+
|
|
20
|
+
let search = $state('');
|
|
21
|
+
let view = $state<MediaListView | undefined>(undefined);
|
|
22
|
+
let error = $state('');
|
|
23
|
+
let uploading = $state(0);
|
|
24
|
+
let fileInput = $state<HTMLInputElement>();
|
|
25
|
+
let request = 0;
|
|
26
|
+
|
|
27
|
+
const can = (action: 'media-upload' | 'media-delete') => view?.allowed.includes(action) ?? false;
|
|
28
|
+
const message = (reason: unknown) => (reason instanceof Error ? reason.message : String(reason));
|
|
29
|
+
|
|
30
|
+
async function load() {
|
|
31
|
+
const current = ++request;
|
|
32
|
+
try {
|
|
33
|
+
const next = await listMedia(apiBase, { search: search.trim() });
|
|
34
|
+
if (current === request) view = next;
|
|
35
|
+
} catch (reason) {
|
|
36
|
+
if (current === request) error = message(reason);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function upload(files: File[]) {
|
|
41
|
+
error = '';
|
|
42
|
+
uploading += files.length;
|
|
43
|
+
try {
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
try {
|
|
46
|
+
await uploadMedia(apiBase, file);
|
|
47
|
+
} catch (reason) {
|
|
48
|
+
error = `${file.name}: ${message(reason)}`;
|
|
49
|
+
} finally {
|
|
50
|
+
uploading -= 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await load();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function remove(item: Item) {
|
|
59
|
+
if (!confirm(`Delete “${item.title}”? This cannot be undone.`)) return;
|
|
60
|
+
error = '';
|
|
61
|
+
try {
|
|
62
|
+
await deleteMedia(apiBase, item.id);
|
|
63
|
+
} catch (reason) {
|
|
64
|
+
error = message(reason);
|
|
65
|
+
}
|
|
66
|
+
await load();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function size(bytes: number): string {
|
|
70
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
71
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
72
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function inUse(count: number): string {
|
|
76
|
+
return `In use by ${count} Content document${count === 1 ? '' : 's'}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onMount(() => void load());
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<section class="uncial-cms-media" aria-label="Media library">
|
|
83
|
+
<div class="uncial-cms-media-toolbar">
|
|
84
|
+
<input
|
|
85
|
+
type="search"
|
|
86
|
+
class="uncial-cms-media-search"
|
|
87
|
+
placeholder="Search by title or filename"
|
|
88
|
+
aria-label="Search media"
|
|
89
|
+
bind:value={search}
|
|
90
|
+
oninput={() => void load()}
|
|
91
|
+
/>
|
|
92
|
+
{#if can('media-upload')}
|
|
93
|
+
<input
|
|
94
|
+
bind:this={fileInput}
|
|
95
|
+
type="file"
|
|
96
|
+
multiple
|
|
97
|
+
hidden
|
|
98
|
+
onchange={(event) => {
|
|
99
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
100
|
+
const files = [...(target.files ?? [])];
|
|
101
|
+
target.value = '';
|
|
102
|
+
if (files.length) void upload(files);
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
<button type="button" disabled={uploading > 0} onclick={() => fileInput?.click()}>
|
|
106
|
+
Upload
|
|
107
|
+
</button>
|
|
108
|
+
{/if}
|
|
109
|
+
{#if uploading > 0}
|
|
110
|
+
<p class="uncial-cms-media-status" role="status">Uploading {uploading}…</p>
|
|
111
|
+
{/if}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
{#if error}
|
|
115
|
+
<p class="uncial-cms-media-error" role="alert">{error}</p>
|
|
116
|
+
{/if}
|
|
117
|
+
|
|
118
|
+
{#if view === undefined}
|
|
119
|
+
{#if !error}<p role="status">Loading media…</p>{/if}
|
|
120
|
+
{:else if view.items.length === 0}
|
|
121
|
+
<p>{search.trim() ? 'No media matches that search.' : 'No media yet.'}</p>
|
|
122
|
+
{:else}
|
|
123
|
+
<ul class="uncial-cms-media-grid">
|
|
124
|
+
{#each view.items as item (item.id)}
|
|
125
|
+
<li class="uncial-cms-media-item">
|
|
126
|
+
<a class="uncial-cms-media-preview" href={item.url} target="_blank" rel="noopener">
|
|
127
|
+
{#if item.contentType.startsWith('image/')}
|
|
128
|
+
<img src={item.url} alt="" loading="lazy" />
|
|
129
|
+
{:else}
|
|
130
|
+
<span>{item.key.split('.').at(-1)?.toUpperCase()}</span>
|
|
131
|
+
{/if}
|
|
132
|
+
</a>
|
|
133
|
+
<p class="uncial-cms-media-title">{item.title}</p>
|
|
134
|
+
<p class="uncial-cms-media-meta">
|
|
135
|
+
{item.filename} · {#if item.width && item.height}{item.width}×{item.height} · {/if}{size(
|
|
136
|
+
item.size
|
|
137
|
+
)}
|
|
138
|
+
</p>
|
|
139
|
+
<p class="uncial-cms-media-usage">
|
|
140
|
+
{item.usage > 0 ? inUse(item.usage) : 'Not in use'}
|
|
141
|
+
</p>
|
|
142
|
+
{#if can('media-delete')}
|
|
143
|
+
<button
|
|
144
|
+
type="button"
|
|
145
|
+
disabled={item.usage > 0}
|
|
146
|
+
title={item.usage > 0 ? `${inUse(item.usage)}, so it cannot be deleted.` : undefined}
|
|
147
|
+
onclick={() => void remove(item)}
|
|
148
|
+
>
|
|
149
|
+
Delete
|
|
150
|
+
</button>
|
|
151
|
+
{/if}
|
|
152
|
+
</li>
|
|
153
|
+
{/each}
|
|
154
|
+
</ul>
|
|
155
|
+
{/if}
|
|
156
|
+
</section>
|
|
157
|
+
|
|
158
|
+
<style>
|
|
159
|
+
.uncial-cms-media-grid {
|
|
160
|
+
display: grid;
|
|
161
|
+
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
|
|
162
|
+
gap: 1rem;
|
|
163
|
+
padding: 0;
|
|
164
|
+
list-style: none;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.uncial-cms-media-item {
|
|
168
|
+
min-width: 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.uncial-cms-media-preview {
|
|
172
|
+
display: grid;
|
|
173
|
+
place-items: center;
|
|
174
|
+
aspect-ratio: 4 / 3;
|
|
175
|
+
overflow: hidden;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.uncial-cms-media-preview img {
|
|
179
|
+
width: 100%;
|
|
180
|
+
height: 100%;
|
|
181
|
+
object-fit: cover;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.uncial-cms-media-meta {
|
|
185
|
+
overflow-wrap: anywhere;
|
|
186
|
+
}
|
|
187
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The host's media endpoint, the `server` forge's `mediaApiBase`. */
|
|
3
|
+
apiBase: string;
|
|
4
|
+
}
|
|
5
|
+
declare const MediaLibrary: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type MediaLibrary = ReturnType<typeof MediaLibrary>;
|
|
7
|
+
export default MediaLibrary;
|
package/dist/svelte/index.d.ts
CHANGED
package/dist/svelte/index.js
CHANGED
|
@@ -17,20 +17,20 @@ interface HandlerOptionsBase {
|
|
|
17
17
|
exclude?: (entry: ContentEntry) => boolean;
|
|
18
18
|
}
|
|
19
19
|
/** The site object from `defineSite`, or the resolved config plus its build-time FS path. */
|
|
20
|
-
interface SiteSource {
|
|
21
|
-
site: Site
|
|
20
|
+
interface SiteSource<Config extends UncialCmsSiteConfig = UncialCmsSiteConfig> {
|
|
21
|
+
site: Site<Config>;
|
|
22
22
|
config?: never;
|
|
23
23
|
localContentDir?: never;
|
|
24
24
|
}
|
|
25
|
-
interface ConfigSource {
|
|
25
|
+
interface ConfigSource<Config extends UncialCmsSiteConfig = UncialCmsSiteConfig> {
|
|
26
26
|
site?: never;
|
|
27
|
-
config:
|
|
27
|
+
config: Config;
|
|
28
28
|
/** FS path of the content dir at build time (differs from config.contentDir,
|
|
29
29
|
* which is repo-root-relative for the forge API). */
|
|
30
30
|
localContentDir: string;
|
|
31
31
|
}
|
|
32
32
|
export type ContentHandlerOptions = HandlerOptionsBase & (SiteSource | ConfigSource);
|
|
33
|
-
export type IndexHandlerOptions = HandlerOptionsBase & (SiteSource | (Omit<ConfigSource
|
|
33
|
+
export type IndexHandlerOptions<Config extends UncialCmsSiteConfig = UncialCmsSiteConfig> = HandlerOptionsBase & (SiteSource<Config> | (Omit<ConfigSource<Config>, 'localContentDir'> & {
|
|
34
34
|
localContentDir?: string;
|
|
35
35
|
}));
|
|
36
36
|
interface RouteEntry {
|
|
@@ -61,8 +61,8 @@ export declare function createEditorHandlers(opts: ContentHandlerOptions & {
|
|
|
61
61
|
pagePath: string;
|
|
62
62
|
}>;
|
|
63
63
|
};
|
|
64
|
-
export declare function createIndexHandlers(opts: IndexHandlerOptions): {
|
|
64
|
+
export declare function createIndexHandlers<Config extends UncialCmsSiteConfig>(opts: IndexHandlerOptions<Config>): {
|
|
65
65
|
load: () => Promise<{
|
|
66
|
-
config:
|
|
66
|
+
config: Config;
|
|
67
67
|
}>;
|
|
68
68
|
};
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -12,14 +12,14 @@ import { listContentSources } from '../content-sources.js';
|
|
|
12
12
|
import { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
13
13
|
export { defaultMapPathToSource, defaultMapSourceToPath } from '../paths/index.js';
|
|
14
14
|
function resolveSite(opts) {
|
|
15
|
+
const config = opts.site ? opts.site.config : opts.config;
|
|
16
|
+
if (config.forge === 'server') {
|
|
17
|
+
throw new Error('These route factories read a content directory; a server site serves its content through createServerContentHandlers.');
|
|
18
|
+
}
|
|
15
19
|
if (opts.site) {
|
|
16
|
-
return {
|
|
17
|
-
config: opts.site.config,
|
|
18
|
-
localContentDir: opts.site.localContentDir,
|
|
19
|
-
localOnly: opts.site.localOnly
|
|
20
|
-
};
|
|
20
|
+
return { config, localContentDir: opts.site.localContentDir, localOnly: opts.site.localOnly };
|
|
21
21
|
}
|
|
22
|
-
return { config
|
|
22
|
+
return { config, localContentDir: opts.localContentDir, localOnly: false };
|
|
23
23
|
}
|
|
24
24
|
function createEntries(opts, site) {
|
|
25
25
|
return () => listContentSources(site.localContentDir)
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,12 @@ export interface LocalSiteConfig {
|
|
|
12
12
|
contentDir: string;
|
|
13
13
|
mediaDir?: string;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
15
|
+
export interface ServerSiteConfig {
|
|
16
|
+
forge: 'server';
|
|
17
|
+
apiBase: string;
|
|
18
|
+
mediaApiBase?: string;
|
|
19
|
+
}
|
|
20
|
+
export type UncialCmsSiteConfig = GitHubSiteConfig | LocalSiteConfig | ServerSiteConfig;
|
|
16
21
|
export interface ForgeSession {
|
|
17
22
|
token: string;
|
|
18
23
|
expiresAt: number | null;
|
|
@@ -40,6 +45,7 @@ export interface ForgeAdapter {
|
|
|
40
45
|
}): Promise<{
|
|
41
46
|
sha: string;
|
|
42
47
|
commitSha: string;
|
|
48
|
+
path?: string;
|
|
43
49
|
}>;
|
|
44
50
|
deleteFile(path: string, opts: {
|
|
45
51
|
message: string;
|
package/dist/upload-context.d.ts
CHANGED
|
@@ -22,3 +22,5 @@ export interface ActiveForge {
|
|
|
22
22
|
export declare function setActiveForge(forge: ActiveForge): void;
|
|
23
23
|
export declare function clearActiveForge(): void;
|
|
24
24
|
export declare function getActiveForge(): ActiveForge | null;
|
|
25
|
+
/** The git forges commit media under `mediaDir`; the server forge has none. */
|
|
26
|
+
export declare function configMediaDir(config: UncialCmsSiteConfig): string | undefined;
|
package/dist/upload-context.js
CHANGED
|
@@ -8,3 +8,7 @@ export function clearActiveForge() {
|
|
|
8
8
|
export function getActiveForge() {
|
|
9
9
|
return active;
|
|
10
10
|
}
|
|
11
|
+
/** The git forges commit media under `mediaDir`; the server forge has none. */
|
|
12
|
+
export function configMediaDir(config) {
|
|
13
|
+
return config.forge === 'server' ? undefined : config.mediaDir;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uncial-cms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,6 +60,10 @@
|
|
|
60
60
|
"types": "./dist/sveltekit/index.d.ts",
|
|
61
61
|
"default": "./dist/sveltekit/index.js"
|
|
62
62
|
},
|
|
63
|
+
"./server": {
|
|
64
|
+
"types": "./dist/server/index.d.ts",
|
|
65
|
+
"default": "./dist/server/index.js"
|
|
66
|
+
},
|
|
63
67
|
"./astro": {
|
|
64
68
|
"types": "./dist/astro/index.d.ts",
|
|
65
69
|
"default": "./dist/astro/index.js"
|
|
@@ -71,11 +75,22 @@
|
|
|
71
75
|
}
|
|
72
76
|
},
|
|
73
77
|
"peerDependencies": {
|
|
78
|
+
"@aws-sdk/client-s3": "^3.0.0",
|
|
79
|
+
"postgres": "^3.4.0",
|
|
74
80
|
"svelte": "^5.0.0",
|
|
75
|
-
"uncial": "^
|
|
81
|
+
"uncial": "^5.0.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@aws-sdk/client-s3": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"postgres": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
76
90
|
},
|
|
77
91
|
"devDependencies": {
|
|
78
92
|
"@astrojs/svelte": "^7.2.5",
|
|
93
|
+
"@aws-sdk/client-s3": "^3.1144.0",
|
|
79
94
|
"@playwright/test": "^1.58.2",
|
|
80
95
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
81
96
|
"@sveltejs/kit": "^2.50.2",
|
|
@@ -84,6 +99,7 @@
|
|
|
84
99
|
"@vitest/browser-playwright": "^4.0.18",
|
|
85
100
|
"astro": "^5.18.2",
|
|
86
101
|
"playwright": "^1.58.2",
|
|
102
|
+
"postgres": "^3.4.7",
|
|
87
103
|
"publint": "^0.3.17",
|
|
88
104
|
"svelte": "^5.56.10",
|
|
89
105
|
"svelte-check": "^4.4.2",
|