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
@@ -0,0 +1,405 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import { onMount } from 'svelte';
5
+ import type { ContentSchema } from 'uncial/core';
6
+ import { AttributeFieldControl, createDocumentMetaController } from 'uncial/editor';
7
+ import {
8
+ describeDeployPhase,
9
+ githubCommitUrl,
10
+ startDeployPolling,
11
+ type DeployPollHandle
12
+ } from '../deploy-status.js';
13
+ import { serializeDocument } from '../document.js';
14
+ import type { StatusView } from '../editor-controller.js';
15
+ import { triggerDownload } from '../editor-session.js';
16
+ import { ConflictError, SignedOutError } from '../errors.js';
17
+ import { globalDocument } from '../globals.js';
18
+ import { readStoredGlobal, saveGlobal } from '../index-actions.js';
19
+ import type { ForgeAdapter, ForgeSession, UncialCmsSiteConfig } from '../types.js';
20
+ import ConfirmDialog from './ConfirmDialog.svelte';
21
+ import type { DashboardAction } from './types.js';
22
+
23
+ interface Props {
24
+ config: UncialCmsSiteConfig;
25
+ adapter: ForgeAdapter;
26
+ session: ForgeSession;
27
+ name: string;
28
+ schema: ContentSchema;
29
+ branchLabel: string;
30
+ can: (action: DashboardAction, subject?: unknown) => boolean;
31
+ onfocusheading: () => void;
32
+ onsignedout: (reason: string) => void;
33
+ }
34
+
35
+ let {
36
+ config,
37
+ adapter,
38
+ session,
39
+ name,
40
+ schema,
41
+ branchLabel,
42
+ can,
43
+ onfocusheading,
44
+ onsignedout
45
+ }: Props = $props();
46
+
47
+ const uid = $props.id();
48
+ const form = $derived(createDocumentMetaController(schema.metaFields));
49
+ const fields = $derived(Array.from(schema.metaFields));
50
+ const editable = $derived(can('global-edit', name));
51
+
52
+ let sha: string | undefined;
53
+ let poll: DeployPollHandle | undefined;
54
+ let loaded = $state(false);
55
+ let loadError = $state('');
56
+ let saving = $state(false);
57
+ let status = $state<StatusView>();
58
+ let conflict = $state(false);
59
+ let confirmingReload = $state(false);
60
+
61
+ function message(error: unknown, fallback: string): string {
62
+ if (error instanceof SignedOutError) onsignedout(error.message);
63
+ return error instanceof Error ? error.message : fallback;
64
+ }
65
+
66
+ async function load() {
67
+ try {
68
+ const stored = await readStoredGlobal({ adapter, config }, { name, schema });
69
+ sha = stored.sha;
70
+ form.reset(stored.value);
71
+ loaded = true;
72
+ loadError = '';
73
+ } catch (error) {
74
+ loadError = message(error, `Failed to load ${name}.`);
75
+ }
76
+ }
77
+
78
+ function validated(outcome: string): Record<string, unknown> | undefined {
79
+ const { meta, validation } = form.commit();
80
+ if (validation.ok) return meta;
81
+ const count = validation.issues.filter((issue) => issue.severity === 'error').length;
82
+ status = {
83
+ tone: 'error',
84
+ text: `Not ${outcome}: ${count === 1 ? '1 field needs' : `${count} fields need`} fixing.`
85
+ };
86
+ }
87
+
88
+ function showDeploy(commitSha: string) {
89
+ const commitUrl = config.forge === 'github' ? githubCommitUrl(config.repo, commitSha) : '';
90
+ poll = startDeployPolling({
91
+ check: () => adapter.commitStatus(commitSha),
92
+ onPhase: (phase) => {
93
+ const view = describeDeployPhase(phase, { branch: branchLabel, commitSha, commitUrl });
94
+ status = { text: view.text, href: view.commitUrl, tone: view.tone };
95
+ }
96
+ });
97
+ }
98
+
99
+ async function save(event: SubmitEvent) {
100
+ event.preventDefault();
101
+ if (!editable || saving) return;
102
+ const value = validated('saved');
103
+ if (!value) return;
104
+ poll?.cancel();
105
+ conflict = false;
106
+ saving = true;
107
+ status = { tone: 'progress', text: 'Saving…' };
108
+ try {
109
+ const saved = await saveGlobal(
110
+ { adapter, config, author: { name: session.user.name, email: session.user.email } },
111
+ { name, schema, value, sha }
112
+ );
113
+ sha = saved.sha;
114
+ if (config.forge === 'server') status = { tone: 'success', text: 'Published · live now' };
115
+ else showDeploy(saved.commitSha);
116
+ } catch (error) {
117
+ if (error instanceof ConflictError) {
118
+ conflict = true;
119
+ status = {
120
+ tone: 'error',
121
+ text: `Save conflicted — ${name} changed on ${branchLabel} since you loaded it.`
122
+ };
123
+ } else {
124
+ status = { tone: 'error', text: message(error, 'Save failed.') };
125
+ }
126
+ } finally {
127
+ saving = false;
128
+ }
129
+ }
130
+
131
+ function downloadMine() {
132
+ const value = validated('downloaded');
133
+ if (!value) return;
134
+ triggerDownload({
135
+ filename: `${name}.json`,
136
+ content: serializeDocument(globalDocument(value), [], schema),
137
+ mimeType: 'application/json'
138
+ });
139
+ }
140
+
141
+ async function reload(confirmed: boolean) {
142
+ confirmingReload = false;
143
+ if (!confirmed) return;
144
+ poll?.cancel();
145
+ await load();
146
+ if (loadError) return;
147
+ conflict = false;
148
+ status = { tone: 'success', text: `Loaded the latest ${name} from ${branchLabel}.` };
149
+ onfocusheading();
150
+ }
151
+
152
+ onMount(() => {
153
+ void load();
154
+ return () => poll?.cancel();
155
+ });
156
+ </script>
157
+
158
+ {#if loadError}
159
+ <p class="error" role="alert">{loadError}</p>
160
+ {/if}
161
+
162
+ {#if conflict}
163
+ <div class="uncial-cms-banner" role="alert">
164
+ <p class="uncial-cms-banner-message">
165
+ {name} changed on {branchLabel} since you loaded it. Your unsaved changes are safe — choose how
166
+ to proceed.
167
+ </p>
168
+ <div class="uncial-cms-banner-actions">
169
+ <button type="button" class="btn" onclick={downloadMine}>Download my version</button>
170
+ <button type="button" class="btn" onclick={() => (confirmingReload = true)}>
171
+ Reload latest
172
+ </button>
173
+ <button type="button" class="btn" onclick={() => (conflict = false)}>Dismiss</button>
174
+ </div>
175
+ </div>
176
+ {/if}
177
+
178
+ {#if loaded}
179
+ <form class="global-form" onsubmit={save} novalidate>
180
+ {#if !editable}
181
+ <p id="{uid}-readonly" class="note">
182
+ You don’t have permission to edit {name}, so it is read-only.
183
+ </p>
184
+ {/if}
185
+ <fieldset disabled={!editable} aria-describedby={editable ? undefined : `${uid}-readonly`}>
186
+ {#each fields as [field, spec] (field)}
187
+ <AttributeFieldControl
188
+ name={field}
189
+ {spec}
190
+ value={$form.draft[field]}
191
+ error={$form.errors[field]}
192
+ errors={$form.errors}
193
+ onChange={(value) => form.setDraft(field, value)}
194
+ />
195
+ {:else}
196
+ <p class="note">This Global declares no fields.</p>
197
+ {/each}
198
+ </fieldset>
199
+ <div class="actions">
200
+ {#if editable}
201
+ <button type="submit" class="btn btn-primary" disabled={saving}>Save</button>
202
+ {/if}
203
+ <p class="status" role="status" data-tone={status?.tone}>
204
+ {#if status}
205
+ {status.text}{#if status.href}&nbsp;<a href={status.href} target="_blank" rel="noopener"
206
+ >View commit</a
207
+ >{/if}
208
+ {/if}
209
+ </p>
210
+ </div>
211
+ </form>
212
+ {:else if !loadError}
213
+ <p class="note">Loading…</p>
214
+ {/if}
215
+
216
+ {#if confirmingReload}
217
+ <ConfirmDialog title="Reload the latest version?" confirmLabel="Reload latest" onclose={reload}>
218
+ Reload {name} from {branchLabel}? This discards your unsaved changes unless you have downloaded
219
+ them.
220
+ </ConfirmDialog>
221
+ {/if}
222
+
223
+ <style>
224
+ p {
225
+ margin: 0;
226
+ }
227
+
228
+ .note {
229
+ color: var(--uncial-dashboard-muted);
230
+ }
231
+
232
+ .error,
233
+ .status[data-tone='error'] {
234
+ color: var(--uncial-color-danger);
235
+ font-weight: 600;
236
+ }
237
+
238
+ .uncial-cms-banner {
239
+ display: grid;
240
+ gap: var(--uncial-space-3);
241
+ margin-bottom: var(--uncial-space-5);
242
+ padding: var(--uncial-space-3) var(--uncial-space-4);
243
+ border: 1px solid var(--uncial-color-danger);
244
+ border-left-width: 4px;
245
+ border-radius: var(--uncial-radius-md);
246
+ background: var(--uncial-color-surface-elevated);
247
+ }
248
+
249
+ .uncial-cms-banner-actions,
250
+ .actions {
251
+ display: flex;
252
+ flex-wrap: wrap;
253
+ align-items: center;
254
+ gap: var(--uncial-space-2) var(--uncial-space-3);
255
+ }
256
+
257
+ .global-form {
258
+ display: grid;
259
+ gap: var(--uncial-space-4);
260
+ max-width: 44rem;
261
+ }
262
+
263
+ fieldset {
264
+ min-width: 0;
265
+ margin: 0;
266
+ padding: 0;
267
+ border: 0;
268
+ }
269
+
270
+ .global-form :global(.uncial-field) {
271
+ display: grid;
272
+ gap: var(--uncial-space-1);
273
+ margin-bottom: var(--uncial-space-4);
274
+ }
275
+
276
+ .global-form :global(.uncial-field__label) {
277
+ font-weight: 600;
278
+ }
279
+
280
+ .global-form :global(:is(.uncial-input, .uncial-select, .uncial-textarea)) {
281
+ box-sizing: border-box;
282
+ width: 100%;
283
+ min-height: 2.5rem;
284
+ padding: var(--uncial-space-2) var(--uncial-space-3);
285
+ border: 1px solid var(--uncial-color-border-strong);
286
+ border-radius: var(--uncial-radius-md);
287
+ background: var(--uncial-color-surface);
288
+ color: var(--uncial-color-text);
289
+ font: inherit;
290
+ }
291
+
292
+ .global-form :global(.uncial-textarea) {
293
+ min-height: 8rem;
294
+ resize: vertical;
295
+ }
296
+
297
+ .global-form :global(:is(select, textarea):focus-visible) {
298
+ outline: 2px solid var(--uncial-color-focus-ring);
299
+ outline-offset: 2px;
300
+ }
301
+
302
+ .global-form :global(:is(input, select, textarea, button):disabled) {
303
+ cursor: not-allowed;
304
+ opacity: 0.6;
305
+ }
306
+
307
+ .global-form :global(.uncial-field__error) {
308
+ color: var(--uncial-color-danger);
309
+ font-size: 0.875rem;
310
+ font-weight: 600;
311
+ }
312
+
313
+ .global-form :global(:is(.uncial-field__warning, .uncial-help-text)) {
314
+ margin: 0;
315
+ color: var(--uncial-dashboard-muted);
316
+ font-size: 0.875rem;
317
+ }
318
+
319
+ .global-form :global(.uncial-list-field) {
320
+ display: grid;
321
+ gap: var(--uncial-space-3);
322
+ }
323
+
324
+ .global-form :global(.uncial-list-item) {
325
+ padding: var(--uncial-space-3);
326
+ border: 1px solid var(--uncial-color-border);
327
+ border-radius: var(--uncial-radius-lg);
328
+ background: var(--uncial-color-surface-elevated);
329
+ }
330
+
331
+ .global-form :global(.uncial-list-item .uncial-list-item) {
332
+ background: var(--uncial-color-surface);
333
+ }
334
+
335
+ .global-form :global(.uncial-list-item__head) {
336
+ display: flex;
337
+ align-items: center;
338
+ justify-content: space-between;
339
+ gap: var(--uncial-space-2);
340
+ margin-bottom: var(--uncial-space-2);
341
+ }
342
+
343
+ .global-form :global(.uncial-list-item > .uncial-field:last-child) {
344
+ margin-bottom: 0;
345
+ }
346
+
347
+ .global-form :global(.uncial-section-label) {
348
+ color: var(--uncial-dashboard-muted);
349
+ font-size: 0.75rem;
350
+ font-weight: 700;
351
+ letter-spacing: 0.06em;
352
+ text-transform: uppercase;
353
+ }
354
+
355
+ .global-form :global(.uncial-child-item__actions) {
356
+ display: flex;
357
+ gap: var(--uncial-space-1);
358
+ }
359
+
360
+ .global-form :global(.uncial-btn) {
361
+ display: inline-flex;
362
+ align-items: center;
363
+ justify-content: center;
364
+ gap: 0.375rem;
365
+ min-height: 2rem;
366
+ padding: 0 var(--uncial-space-3);
367
+ border: 1px solid var(--uncial-color-border-strong);
368
+ border-radius: var(--uncial-radius-md);
369
+ background: var(--uncial-color-surface);
370
+ color: var(--uncial-color-text);
371
+ font: inherit;
372
+ font-size: 0.875rem;
373
+ font-weight: 600;
374
+ line-height: 1;
375
+ cursor: pointer;
376
+ }
377
+
378
+ .global-form :global(.uncial-btn:not(.uncial-btn--primary):hover:not(:disabled)) {
379
+ background: var(--uncial-color-surface-elevated);
380
+ }
381
+
382
+ .global-form :global(.uncial-btn--start) {
383
+ justify-self: start;
384
+ }
385
+
386
+ .global-form :global(.uncial-btn--square) {
387
+ width: 2rem;
388
+ padding: 0;
389
+ }
390
+
391
+ .global-form :global(.uncial-btn--ghost) {
392
+ border-color: transparent;
393
+ background: transparent;
394
+ }
395
+
396
+ .global-form :global(.uncial-btn--danger) {
397
+ color: var(--uncial-color-danger);
398
+ }
399
+
400
+ .global-form :global(.uncial-btn--primary) {
401
+ border-color: var(--uncial-color-primary);
402
+ background: var(--uncial-color-primary);
403
+ color: var(--uncial-color-primary-contrast);
404
+ }
405
+ </style>
@@ -0,0 +1,17 @@
1
+ import type { ContentSchema } from 'uncial/core';
2
+ import type { ForgeAdapter, ForgeSession, UncialCmsSiteConfig } from '../types.js';
3
+ import type { DashboardAction } from './types.js';
4
+ interface Props {
5
+ config: UncialCmsSiteConfig;
6
+ adapter: ForgeAdapter;
7
+ session: ForgeSession;
8
+ name: string;
9
+ schema: ContentSchema;
10
+ branchLabel: string;
11
+ can: (action: DashboardAction, subject?: unknown) => boolean;
12
+ onfocusheading: () => void;
13
+ onsignedout: (reason: string) => void;
14
+ }
15
+ declare const GlobalForm: import("svelte").Component<Props, {}, "">;
16
+ type GlobalForm = ReturnType<typeof GlobalForm>;
17
+ export default GlobalForm;
@@ -0,0 +1,62 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import type { ContentSchema } from 'uncial/core';
5
+ import { globalTitle } from '../globals.js';
6
+ import { hashForRoute } from './routes.js';
7
+
8
+ let { globals }: { globals: Record<string, ContentSchema> } = $props();
9
+
10
+ const entries = $derived(Object.entries(globals));
11
+ </script>
12
+
13
+ {#if entries.length === 0}
14
+ <p class="note">This site declares no Globals.</p>
15
+ {:else}
16
+ <ul class="globals">
17
+ {#each entries as [name, schema] (name)}
18
+ {@const title = globalTitle(schema)}
19
+ <li class="global">
20
+ <a class="global-name" href={hashForRoute({ section: 'globals', name })}>{name}</a>
21
+ {#if title}<span class="global-title">{title}</span>{/if}
22
+ </li>
23
+ {/each}
24
+ </ul>
25
+ {/if}
26
+
27
+ <style>
28
+ .note {
29
+ color: var(--uncial-dashboard-muted);
30
+ }
31
+
32
+ .globals {
33
+ margin: 0;
34
+ padding: 0;
35
+ list-style: none;
36
+ border: 1px solid var(--uncial-color-border);
37
+ border-radius: var(--uncial-radius-lg);
38
+ }
39
+
40
+ .global {
41
+ display: flex;
42
+ flex-wrap: wrap;
43
+ align-items: baseline;
44
+ gap: var(--uncial-space-1) var(--uncial-space-3);
45
+ padding: var(--uncial-space-3) var(--uncial-space-4);
46
+ }
47
+
48
+ .global + .global {
49
+ border-top: 1px solid var(--uncial-color-border);
50
+ }
51
+
52
+ .global-name {
53
+ color: var(--uncial-color-primary);
54
+ font-family: var(--uncial-font-mono);
55
+ font-weight: 600;
56
+ overflow-wrap: anywhere;
57
+ }
58
+
59
+ .global-title {
60
+ color: var(--uncial-dashboard-muted);
61
+ }
62
+ </style>
@@ -0,0 +1,7 @@
1
+ import type { ContentSchema } from 'uncial/core';
2
+ type $$ComponentProps = {
3
+ globals: Record<string, ContentSchema>;
4
+ };
5
+ declare const GlobalsList: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type GlobalsList = ReturnType<typeof GlobalsList>;
7
+ export default GlobalsList;
@@ -0,0 +1,221 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import { listPages } from '../index-actions.js';
5
+ import { SignedOutError } from '../errors.js';
6
+ import { mediaSourceFor, type MediaItem, type MediaSource } from '../media-source.js';
7
+ import MediaLibrary from '../svelte/MediaLibrary.svelte';
8
+ import type { ForgeAdapter, ForgeSession, UncialCmsSiteConfig } from '../types.js';
9
+ import ConfirmDialog from './ConfirmDialog.svelte';
10
+ import type { DashboardAction } from './types.js';
11
+
12
+ interface Props {
13
+ config: UncialCmsSiteConfig;
14
+ adapter: ForgeAdapter;
15
+ session: ForgeSession;
16
+ staticDir?: string;
17
+ basePath: string;
18
+ mapSourceToPath?: (source: string) => string;
19
+ branchLabel: string;
20
+ can: (action: DashboardAction, subject?: unknown) => boolean;
21
+ onsignedout: (reason: string) => void;
22
+ }
23
+
24
+ let {
25
+ config,
26
+ adapter,
27
+ session,
28
+ staticDir,
29
+ basePath,
30
+ mapSourceToPath,
31
+ branchLabel,
32
+ can,
33
+ onsignedout
34
+ }: Props = $props();
35
+
36
+ const media = $derived.by((): { source: MediaSource } | { error: string } => {
37
+ try {
38
+ return { source: mediaSourceFor(config, { adapter, author: session.user }, { staticDir }) };
39
+ } catch (error) {
40
+ return { error: error instanceof Error ? error.message : String(error) };
41
+ }
42
+ });
43
+
44
+ let documents: Promise<Array<{ label: string; content: string }>> | undefined;
45
+ let checking = $state(false);
46
+ let pending = $state<{
47
+ item: MediaItem;
48
+ usedBy: string[];
49
+ resolve: (confirmed: boolean) => void;
50
+ }>();
51
+
52
+ const labelFor = (pagePath: string) => (pagePath === '' ? '(site root)' : `/${pagePath}/`);
53
+
54
+ function loadDocuments(contentDir: string) {
55
+ documents ??= listPages(adapter, contentDir, mapSourceToPath)
56
+ .then((pages) =>
57
+ Promise.all(
58
+ pages.map(async (page) => ({
59
+ label: labelFor(page.pagePath),
60
+ content: (await adapter.readFile(page.sourcePath)).content
61
+ }))
62
+ )
63
+ )
64
+ .catch((error: unknown) => {
65
+ documents = undefined;
66
+ throw error;
67
+ });
68
+ return documents;
69
+ }
70
+
71
+ async function confirmDelete(item: MediaItem): Promise<boolean> {
72
+ let usedBy: string[] = item.usage?.map((use) => use.title || use.path) ?? [];
73
+ if (config.forge !== 'server') {
74
+ checking = true;
75
+ try {
76
+ usedBy = (await loadDocuments(config.contentDir))
77
+ .filter((document) => document.content.includes(item.url))
78
+ .map((document) => document.label);
79
+ } finally {
80
+ checking = false;
81
+ }
82
+ }
83
+ pending?.resolve(false);
84
+ return new Promise((resolve) => (pending = { item, usedBy, resolve }));
85
+ }
86
+
87
+ function close(confirmed: boolean) {
88
+ pending?.resolve(confirmed);
89
+ pending = undefined;
90
+ }
91
+ </script>
92
+
93
+ <div class="media">
94
+ {#if 'error' in media}
95
+ <p class="note">{media.error}</p>
96
+ {:else}
97
+ <MediaLibrary
98
+ source={media.source}
99
+ base={basePath}
100
+ {can}
101
+ {confirmDelete}
102
+ onerror={(error) => {
103
+ if (error instanceof SignedOutError) onsignedout(error.message);
104
+ }}
105
+ />
106
+ {/if}
107
+ {#if checking}
108
+ <p class="note" role="status">Checking which pages use it…</p>
109
+ {/if}
110
+ </div>
111
+
112
+ {#if pending}
113
+ {@const current = pending}
114
+ {@const name = current.item.title || current.item.filename}
115
+ {@const inUse = current.usedBy.length > 0}
116
+ {#key current}
117
+ <ConfirmDialog
118
+ title={inUse ? 'This file is in use' : 'Delete this file?'}
119
+ confirmLabel={inUse && config.forge !== 'server' ? 'Delete anyway' : 'Delete'}
120
+ onclose={close}
121
+ >
122
+ {#if inUse}
123
+ <p><code>{name}</code> is still used by:</p>
124
+ <ul>
125
+ {#each current.usedBy as label (label)}<li>{label}</li>{/each}
126
+ </ul>
127
+ {#if config.forge === 'server'}
128
+ <p>Remove these uses before deleting this file.</p>
129
+ {:else}
130
+ <p>
131
+ Deleting it breaks {current.usedBy.length === 1 ? 'that page' : 'those pages'}. This
132
+ commits the deletion immediately.
133
+ </p>
134
+ {/if}
135
+ {:else if config.forge === 'server'}
136
+ <p>Delete <code>{name}</code>? This cannot be undone.</p>
137
+ {:else}
138
+ <p>Delete <code>{name}</code> from {branchLabel}? This commits the deletion immediately.</p>
139
+ {/if}
140
+ </ConfirmDialog>
141
+ {/key}
142
+ {/if}
143
+
144
+ <style>
145
+ p,
146
+ ul {
147
+ margin: 0 0 var(--uncial-space-2);
148
+ }
149
+
150
+ .note {
151
+ color: var(--uncial-dashboard-muted);
152
+ }
153
+
154
+ .media :global(.uncial-cms-media-toolbar) {
155
+ display: flex;
156
+ flex-wrap: wrap;
157
+ align-items: center;
158
+ gap: var(--uncial-space-3);
159
+ margin-bottom: var(--uncial-space-4);
160
+ }
161
+
162
+ .media :global(.uncial-cms-media-search) {
163
+ flex: 1 1 14rem;
164
+ min-width: 0;
165
+ min-height: 2.5rem;
166
+ padding: 0 var(--uncial-space-3);
167
+ border: 1px solid var(--uncial-color-border-strong);
168
+ border-radius: var(--uncial-radius-md);
169
+ background: var(--uncial-color-surface);
170
+ color: var(--uncial-color-text);
171
+ font: inherit;
172
+ }
173
+
174
+ .media :global(.uncial-cms-media-toolbar p),
175
+ .media :global(.uncial-cms-media-item p) {
176
+ margin: 0;
177
+ }
178
+
179
+ .media :global(.uncial-cms-media-error) {
180
+ color: var(--uncial-color-danger);
181
+ font-weight: 600;
182
+ }
183
+
184
+ .media :global(.uncial-cms-media-grid) {
185
+ margin: 0;
186
+ }
187
+
188
+ .media :global(.uncial-cms-media-item) {
189
+ display: grid;
190
+ align-content: start;
191
+ gap: var(--uncial-space-2);
192
+ padding: var(--uncial-space-3);
193
+ border: 1px solid var(--uncial-color-border);
194
+ border-radius: var(--uncial-radius-lg);
195
+ background: var(--uncial-color-surface-elevated);
196
+ box-shadow: var(--uncial-shadow-sm);
197
+ font-size: 0.875rem;
198
+ }
199
+
200
+ .media :global(.uncial-cms-media-preview) {
201
+ border-radius: var(--uncial-radius-md);
202
+ background: var(--uncial-color-surface);
203
+ color: var(--uncial-dashboard-muted);
204
+ font-weight: 700;
205
+ text-decoration: none;
206
+ }
207
+
208
+ .media :global(.uncial-cms-media-title) {
209
+ font-weight: 600;
210
+ }
211
+
212
+ .media :global(.uncial-cms-media-meta) {
213
+ color: var(--uncial-dashboard-muted);
214
+ font-family: var(--uncial-font-mono);
215
+ font-size: 0.75rem;
216
+ }
217
+
218
+ .media :global(.uncial-cms-media-delete) {
219
+ justify-self: start;
220
+ }
221
+ </style>