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.
Files changed (86) hide show
  1. package/README.md +216 -23
  2. package/dist/astro/EditorSurface.svelte +6 -2
  3. package/dist/astro/EditorSurface.svelte.d.ts +3 -1
  4. package/dist/astro/index.d.ts +2 -1
  5. package/dist/astro/index.js +7 -2
  6. package/dist/content-sources.d.ts +10 -0
  7. package/dist/content-sources.js +25 -1
  8. package/dist/dashboard/ConfirmDialog.svelte +76 -0
  9. package/dist/dashboard/ConfirmDialog.svelte.d.ts +10 -0
  10. package/dist/dashboard/Dashboard.svelte +650 -0
  11. package/dist/dashboard/Dashboard.svelte.d.ts +4 -0
  12. package/dist/dashboard/FallbackEditor.svelte +42 -0
  13. package/dist/dashboard/FallbackEditor.svelte.d.ts +14 -0
  14. package/dist/dashboard/GlobalForm.svelte +405 -0
  15. package/dist/dashboard/GlobalForm.svelte.d.ts +17 -0
  16. package/dist/dashboard/GlobalsList.svelte +62 -0
  17. package/dist/dashboard/GlobalsList.svelte.d.ts +7 -0
  18. package/dist/dashboard/MediaSection.svelte +221 -0
  19. package/dist/dashboard/MediaSection.svelte.d.ts +16 -0
  20. package/dist/dashboard/PagesSection.svelte +477 -0
  21. package/dist/dashboard/PagesSection.svelte.d.ts +23 -0
  22. package/dist/dashboard/element.d.ts +41 -0
  23. package/dist/dashboard/element.js +113 -0
  24. package/dist/dashboard/pages-list.d.ts +18 -0
  25. package/dist/dashboard/pages-list.js +29 -0
  26. package/dist/dashboard/routes.d.ts +25 -0
  27. package/dist/dashboard/routes.js +81 -0
  28. package/dist/dashboard/types.d.ts +34 -0
  29. package/dist/dashboard/types.js +1 -0
  30. package/dist/define-site.d.ts +15 -6
  31. package/dist/define-site.js +12 -9
  32. package/dist/editor-controller.d.ts +1 -0
  33. package/dist/editor-controller.js +1 -0
  34. package/dist/editor-session.d.ts +5 -0
  35. package/dist/editor-session.js +1 -1
  36. package/dist/errors.d.ts +13 -0
  37. package/dist/errors.js +14 -0
  38. package/dist/github/broker.d.ts +26 -0
  39. package/dist/github/broker.js +196 -0
  40. package/dist/github/index.d.ts +1 -0
  41. package/dist/github/index.js +1 -0
  42. package/dist/globals.d.ts +12 -0
  43. package/dist/globals.js +29 -0
  44. package/dist/image-source.d.ts +0 -10
  45. package/dist/image-source.js +15 -44
  46. package/dist/index-actions.d.ts +29 -2
  47. package/dist/index-actions.js +36 -4
  48. package/dist/index-page.d.ts +2 -0
  49. package/dist/index-page.js +6 -256
  50. package/dist/index.d.ts +6 -3
  51. package/dist/index.js +4 -3
  52. package/dist/local/vite.d.ts +8 -2
  53. package/dist/local/vite.js +32 -15
  54. package/dist/media-source.d.ts +45 -0
  55. package/dist/media-source.js +113 -0
  56. package/dist/mount.d.ts +3 -0
  57. package/dist/mount.js +3 -0
  58. package/dist/nav/index.d.ts +39 -0
  59. package/dist/nav/index.js +52 -0
  60. package/dist/served-url.d.ts +6 -4
  61. package/dist/served-url.js +18 -7
  62. package/dist/server/handlers.d.ts +1 -1
  63. package/dist/server/handlers.js +32 -5
  64. package/dist/server/index.d.ts +2 -1
  65. package/dist/server/index.js +2 -1
  66. package/dist/server/media.d.ts +1 -10
  67. package/dist/server/media.js +7 -11
  68. package/dist/server/postgres-store.d.ts +5 -0
  69. package/dist/server/postgres-store.js +50 -5
  70. package/dist/server-forge/adapter.d.ts +1 -0
  71. package/dist/server-forge/adapter.js +7 -4
  72. package/dist/server-forge/protocol.d.ts +3 -1
  73. package/dist/server-forge/protocol.js +2 -1
  74. package/dist/svelte/EditorPage.svelte +5 -1
  75. package/dist/svelte/EditorPage.svelte.d.ts +3 -1
  76. package/dist/svelte/MediaLibrary.svelte +109 -53
  77. package/dist/svelte/MediaLibrary.svelte.d.ts +10 -2
  78. package/dist/svelte/index.d.ts +1 -4
  79. package/dist/svelte/index.js +1 -4
  80. package/dist/sveltekit/index.d.ts +11 -1
  81. package/dist/sveltekit/index.js +23 -9
  82. package/dist/types.d.ts +2 -0
  83. package/dist/upload-context.d.ts +1 -0
  84. package/dist/upload-context.js +3 -0
  85. package/dist/vite/index.js +18 -4
  86. package/package.json +16 -3
@@ -0,0 +1,650 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import { onMount, tick, untrack } from 'svelte';
5
+ import { defaultSessionProvider, forgeAdapter } from '../editor-session.js';
6
+ import { SignedOutError } from '../errors.js';
7
+ import { forgetBrokerGrant, relayBrokerCallback } from '../github/broker.js';
8
+ import { globalTitle } from '../globals.js';
9
+ import { defaultMapPathToSource } from '../paths/index.js';
10
+ import { UNCIAL_CMS_RUNTIME_SENTINEL } from '../sentinel.js';
11
+ import { clearCachedSession } from '../session.js';
12
+ import type {
13
+ ForgeAdapter,
14
+ ForgeSession,
15
+ SessionProvider,
16
+ UncialCmsSiteConfig
17
+ } from '../types.js';
18
+ import FallbackEditor from './FallbackEditor.svelte';
19
+ import GlobalForm from './GlobalForm.svelte';
20
+ import GlobalsList from './GlobalsList.svelte';
21
+ import MediaSection from './MediaSection.svelte';
22
+ import PagesSection from './PagesSection.svelte';
23
+ import {
24
+ hashForRoute,
25
+ routeFromHash,
26
+ type DashboardRoute,
27
+ type DashboardSection,
28
+ type PagesQuery
29
+ } from './routes.js';
30
+ import type { DashboardProps } from './types.js';
31
+
32
+ let {
33
+ config,
34
+ blocks,
35
+ schema,
36
+ globals,
37
+ editorHref,
38
+ can = () => true,
39
+ appSections = [],
40
+ signOutHref,
41
+ basePath = '',
42
+ theme = 'system',
43
+ sessionProvider,
44
+ mapPathToSource,
45
+ mapSourceToPath,
46
+ editorStylesheets,
47
+ staticDir,
48
+ attributeInputs,
49
+ sections = ['pages', 'media', 'globals']
50
+ }: DashboardProps = $props();
51
+
52
+ const uid = $props.id();
53
+ const relaying = relayBrokerCallback();
54
+
55
+ const LABELS: Record<DashboardSection, string> = {
56
+ pages: 'Pages',
57
+ media: 'Media',
58
+ globals: 'Globals'
59
+ };
60
+
61
+ const site = $derived<UncialCmsSiteConfig | undefined>(
62
+ config && ('forge' in config ? config : config.config)
63
+ );
64
+ const globalSchemas = $derived(globals ?? (config && 'globals' in config ? config.globals : {}));
65
+ const branchLabel = $derived(
66
+ site?.forge === 'github'
67
+ ? site.branch
68
+ : site?.forge === 'server'
69
+ ? 'the server'
70
+ : 'the local checkout'
71
+ );
72
+ const locationLabel = $derived(
73
+ site?.forge === 'github' ? `${site.repo}@${site.branch}` : site ? branchLabel : ''
74
+ );
75
+ const sourceFor = $derived.by(() => {
76
+ if (mapPathToSource) return mapPathToSource;
77
+ if (site?.forge === 'server') return (path: string) => (path === '' ? '/' : `/${path}/`);
78
+ const contentDir = site?.contentDir ?? '';
79
+ return (path: string) => defaultMapPathToSource(path, contentDir);
80
+ });
81
+ const schemaFor = (pagePath: string) =>
82
+ typeof schema === 'function' ? (schema as (path: string) => unknown)(pagePath) : schema;
83
+
84
+ let connection = $state.raw<{ adapter: ForgeAdapter; session: ForgeSession }>();
85
+ let signedOut = $state<string>();
86
+ const user = $derived(connection?.session.user);
87
+
88
+ let route = $state<DashboardRoute>({ section: 'pages' });
89
+ let pagesQuery = $state<PagesQuery>({});
90
+ const pagesHref = $derived(hashForRoute({ section: 'pages', query: pagesQuery }));
91
+ const openGlobal = $derived(
92
+ route.section === 'globals' && route.name && Object.hasOwn(globalSchemas, route.name)
93
+ ? { name: route.name, schema: globalSchemas[route.name]! }
94
+ : undefined
95
+ );
96
+ let hash = '';
97
+ let heading = $state<HTMLElement>();
98
+ let editor = $state<{ isDirty(): boolean }>();
99
+ let menuOpen = $state(false);
100
+ let menuButton = $state<HTMLButtonElement>();
101
+
102
+ const navItems = $derived([
103
+ ...sections.map((id) => ({
104
+ id,
105
+ label: LABELS[id],
106
+ href: id === 'pages' ? pagesHref : `#/${id}`
107
+ })),
108
+ ...appSections.map((app) => ({
109
+ id: `app/${app.id}`,
110
+ label: app.label,
111
+ href: app.href ?? hashForRoute({ section: 'app', id: app.id })
112
+ }))
113
+ ]);
114
+ const showNav = $derived(navItems.length > 1 && signedOut === undefined && !relaying);
115
+ const activeId = $derived(
116
+ route.section === 'edit' ? 'pages' : route.section === 'app' ? `app/${route.id}` : route.section
117
+ );
118
+ const title = $derived(
119
+ relaying
120
+ ? 'Signing in'
121
+ : signedOut !== undefined
122
+ ? 'Signed out'
123
+ : route.section === 'edit'
124
+ ? route.pagePath === ''
125
+ ? 'Editing site root'
126
+ : `Editing /${route.pagePath}/`
127
+ : openGlobal
128
+ ? (globalTitle(openGlobal.schema) ?? openGlobal.name)
129
+ : (navItems.find((item) => item.id === activeId)?.label ?? LABELS.pages)
130
+ );
131
+
132
+ const reason = (error: unknown) =>
133
+ error instanceof Error ? error.message : 'Failed to sign in.';
134
+ const provideSession: SessionProvider = async (current) => {
135
+ try {
136
+ const session = await (sessionProvider ?? defaultSessionProvider(current))(current);
137
+ if (current === site && connection) connection = { ...connection, session };
138
+ return session;
139
+ } catch (error) {
140
+ throw new SignedOutError(reason(error));
141
+ }
142
+ };
143
+
144
+ async function signIn(current: UncialCmsSiteConfig) {
145
+ const adapter = forgeAdapter(current);
146
+ try {
147
+ const session = await adapter.authenticate(current, provideSession);
148
+ if (current !== site) return;
149
+ connection = { adapter, session };
150
+ signedOut = undefined;
151
+ } catch (error) {
152
+ if (current !== site) return;
153
+ signedOut = reason(error);
154
+ }
155
+ }
156
+
157
+ async function retrySignIn() {
158
+ if (!site) return;
159
+ await signIn(site);
160
+ await tick();
161
+ if (connection) heading?.focus();
162
+ }
163
+
164
+ async function endSession(why: string) {
165
+ connection = undefined;
166
+ signedOut = why;
167
+ menuOpen = false;
168
+ await tick();
169
+ heading?.focus();
170
+ }
171
+
172
+ function signOut() {
173
+ if (site?.forge === 'github') {
174
+ clearCachedSession(site.repo);
175
+ forgetBrokerGrant(site.repo);
176
+ }
177
+ void endSession('You signed out.');
178
+ }
179
+
180
+ $effect(() => {
181
+ const current = site;
182
+ if (current && !relaying) untrack(() => void signIn(current));
183
+ });
184
+
185
+ function resolve(next: string): DashboardRoute {
186
+ const parsed = routeFromHash(next);
187
+ if (parsed.section === 'edit') return parsed;
188
+ if (parsed.section === 'app') {
189
+ return appSections.some((app) => app.id === parsed.id && !app.href)
190
+ ? parsed
191
+ : { section: 'pages' };
192
+ }
193
+ if (!sections.includes(parsed.section)) return { section: 'pages' };
194
+ if (parsed.section === 'globals' && parsed.name && !Object.hasOwn(globalSchemas, parsed.name)) {
195
+ return { section: 'globals' };
196
+ }
197
+ return parsed;
198
+ }
199
+
200
+ function apply(next: string) {
201
+ const resolved = resolve(next);
202
+ const canonical = hashForRoute(resolved);
203
+ if (next !== '' && next !== canonical) history.replaceState(history.state, '', canonical);
204
+ hash = next === '' ? '' : canonical;
205
+ route = resolved;
206
+ if (resolved.section === 'pages') pagesQuery = resolved.query ?? {};
207
+ }
208
+
209
+ // A query change keeps focus where it is, so it replaces the hash without a hashchange.
210
+ function setPagesQuery(query: PagesQuery) {
211
+ pagesQuery = query;
212
+ route = { section: 'pages', query };
213
+ hash = hashForRoute(route);
214
+ history.replaceState(history.state, '', hash);
215
+ }
216
+
217
+ function onHashChange() {
218
+ if (location.hash === hash) return;
219
+ if (route.section === 'edit' && editor?.isDirty() && !confirm('Discard unsaved changes?')) {
220
+ history.replaceState(history.state, '', hash);
221
+ return;
222
+ }
223
+ apply(location.hash);
224
+ menuOpen = false;
225
+ void tick().then(() => heading?.focus());
226
+ }
227
+
228
+ function onBeforeUnload(event: BeforeUnloadEvent) {
229
+ if (route.section === 'edit' && editor?.isDirty()) event.preventDefault();
230
+ }
231
+
232
+ function onKeydown(event: KeyboardEvent) {
233
+ if (event.key !== 'Escape' || !menuOpen) return;
234
+ menuOpen = false;
235
+ menuButton?.focus();
236
+ }
237
+
238
+ onMount(() => {
239
+ apply(location.hash);
240
+ });
241
+ </script>
242
+
243
+ <svelte:window onhashchange={onHashChange} onbeforeunload={onBeforeUnload} onkeydown={onKeydown} />
244
+
245
+ <div
246
+ class="dashboard uncial-dashboard"
247
+ data-theme={theme}
248
+ data-uncial-cms-runtime={UNCIAL_CMS_RUNTIME_SENTINEL}
249
+ >
250
+ <div class="topbar">
251
+ {#if showNav}
252
+ <button
253
+ bind:this={menuButton}
254
+ type="button"
255
+ class="btn menu-button"
256
+ aria-expanded={menuOpen}
257
+ aria-controls="{uid}-nav"
258
+ onclick={() => (menuOpen = !menuOpen)}
259
+ >
260
+ <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
261
+ <path d="M2 4h12M2 8h12M2 12h12" stroke="currentColor" stroke-width="1.5" />
262
+ </svg>
263
+ Menu
264
+ </button>
265
+ {/if}
266
+ <div class="identity">
267
+ <p class="name">Dashboard</p>
268
+ {#if locationLabel}<p class="location">{locationLabel}</p>{/if}
269
+ </div>
270
+ <div class="session">
271
+ {#if signedOut === undefined}
272
+ <p class="status" role="status">
273
+ {#if user}Signed in as <strong>{user.name || user.login}</strong>{:else}Signing in…{/if}
274
+ </p>
275
+ {/if}
276
+ {#if user && site?.forge === 'github'}
277
+ <button type="button" class="btn" onclick={signOut}>Sign out</button>
278
+ {:else if user && site?.forge === 'server' && signOutHref}
279
+ <a class="btn" href={signOutHref}>Sign out</a>
280
+ {/if}
281
+ </div>
282
+ </div>
283
+
284
+ <div class="body">
285
+ {#if showNav}
286
+ <nav id="{uid}-nav" class="nav" class:open={menuOpen} aria-label="Dashboard">
287
+ <ul>
288
+ {#each navItems as item (item.id)}
289
+ <li>
290
+ <a
291
+ href={item.href}
292
+ aria-current={activeId === item.id ? 'page' : undefined}
293
+ onclick={() => (menuOpen = false)}>{item.label}</a
294
+ >
295
+ </li>
296
+ {/each}
297
+ </ul>
298
+ </nav>
299
+ {/if}
300
+
301
+ <div class="content">
302
+ {#if route.section === 'edit' && signedOut === undefined}
303
+ <a class="back" href={pagesHref}><span aria-hidden="true">←</span> Back to pages</a>
304
+ {:else if openGlobal && signedOut === undefined}
305
+ <a class="back" href="#/globals"><span aria-hidden="true">←</span> Back to globals</a>
306
+ {/if}
307
+ <h1 bind:this={heading} tabindex="-1">{title}</h1>
308
+
309
+ {#if relaying}
310
+ <p class="reason" role="status">Finishing sign-in. You can close this window.</p>
311
+ {:else if signedOut !== undefined}
312
+ <p class="reason" role="status">{signedOut}</p>
313
+ <!-- The first attempt runs outside a click, where browsers block the sign-in popup. -->
314
+ <button type="button" class="btn btn-primary" onclick={retrySignIn}>Sign in</button>
315
+ {:else if route.section === 'edit'}
316
+ {#if connection && site}
317
+ {#if can('save-draft', route.pagePath)}
318
+ {#key route.pagePath}
319
+ <FallbackEditor
320
+ bind:this={editor}
321
+ options={{
322
+ config: site,
323
+ sourcePath: sourceFor(route.pagePath),
324
+ pagePath: route.pagePath,
325
+ blocks,
326
+ schema: schemaFor(route.pagePath),
327
+ sessionProvider: provideSession,
328
+ editorStylesheets,
329
+ attributeInputs
330
+ }}
331
+ {basePath}
332
+ {staticDir}
333
+ {can}
334
+ onsignedout={endSession}
335
+ />
336
+ {/key}
337
+ {:else}
338
+ <p>You don’t have permission to edit this page.</p>
339
+ {/if}
340
+ {/if}
341
+ {:else if route.section === 'app'}
342
+ {#if connection}
343
+ <svelte:element this={'slot'} name={route.id} />
344
+ {/if}
345
+ {:else if route.section === 'pages'}
346
+ {#if connection && site}
347
+ <PagesSection
348
+ config={site}
349
+ adapter={connection.adapter}
350
+ session={connection.session}
351
+ {blocks}
352
+ {schemaFor}
353
+ {sourceFor}
354
+ {mapSourceToPath}
355
+ {basePath}
356
+ {editorHref}
357
+ {branchLabel}
358
+ {can}
359
+ query={(route.section === 'pages' && route.query) || {}}
360
+ onquery={setPagesQuery}
361
+ onfocusheading={() => heading?.focus()}
362
+ onsignedout={endSession}
363
+ />
364
+ {/if}
365
+ {:else if route.section === 'media'}
366
+ {#if connection && site}
367
+ <MediaSection
368
+ config={site}
369
+ adapter={connection.adapter}
370
+ session={connection.session}
371
+ {staticDir}
372
+ {basePath}
373
+ {mapSourceToPath}
374
+ {branchLabel}
375
+ {can}
376
+ onsignedout={endSession}
377
+ />
378
+ {/if}
379
+ {:else if route.section === 'globals'}
380
+ {#if connection && site}
381
+ {#if openGlobal}
382
+ {#key openGlobal}
383
+ <GlobalForm
384
+ config={site}
385
+ adapter={connection.adapter}
386
+ session={connection.session}
387
+ name={openGlobal.name}
388
+ schema={openGlobal.schema}
389
+ {branchLabel}
390
+ {can}
391
+ onfocusheading={() => heading?.focus()}
392
+ onsignedout={endSession}
393
+ />
394
+ {/key}
395
+ {:else}
396
+ <GlobalsList globals={globalSchemas} />
397
+ {/if}
398
+ {/if}
399
+ {/if}
400
+ </div>
401
+ </div>
402
+ </div>
403
+
404
+ <style>
405
+ @layer uncial-tokens {
406
+ :global(:host),
407
+ :global(:root) .dashboard {
408
+ --uncial-color-bg: light-dark(oklch(99% 0.006 85), oklch(18% 0.015 60));
409
+ --uncial-color-surface: light-dark(oklch(99% 0.006 85), oklch(18% 0.015 60));
410
+ --uncial-color-surface-elevated: light-dark(oklch(96% 0.022 85), oklch(22% 0.02 60));
411
+ --uncial-color-border: light-dark(oklch(91% 0.032 82), oklch(27% 0.025 60));
412
+ --uncial-color-border-strong: color-mix(
413
+ in srgb,
414
+ var(--uncial-color-text) 22%,
415
+ var(--uncial-color-border)
416
+ );
417
+ --uncial-color-text: light-dark(oklch(22% 0.04 45), oklch(92% 0.015 85));
418
+ --uncial-color-primary: light-dark(oklch(46% 0.14 260), oklch(72% 0.13 260));
419
+ --uncial-color-primary-contrast: light-dark(oklch(98% 0.015 85), oklch(16% 0.03 260));
420
+ --uncial-color-danger: light-dark(oklch(48% 0.18 25), oklch(72% 0.16 25));
421
+ --uncial-color-focus-ring: var(--uncial-color-primary);
422
+ --uncial-font-body: ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif;
423
+ --uncial-font-mono:
424
+ ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
425
+ monospace;
426
+ --uncial-font-size-base: 1rem;
427
+ --uncial-radius-md: 0.375rem;
428
+ --uncial-radius-lg: 0.5rem;
429
+ --uncial-space-1: 0.25rem;
430
+ --uncial-space-2: 0.5rem;
431
+ --uncial-space-3: 0.75rem;
432
+ --uncial-space-4: 1rem;
433
+ --uncial-space-5: 1.25rem;
434
+ --uncial-space-6: 1.5rem;
435
+ --uncial-shadow-sm: 0 1px 2px color-mix(in srgb, black 8%, transparent);
436
+ --uncial-shadow-md: 0 10px 25px color-mix(in srgb, black 14%, transparent);
437
+ --uncial-transition: 140ms ease;
438
+ }
439
+ }
440
+
441
+ .dashboard {
442
+ --uncial-dashboard-muted: color-mix(
443
+ in srgb,
444
+ var(--uncial-color-text) 78%,
445
+ var(--uncial-color-bg)
446
+ );
447
+ color-scheme: light dark;
448
+ border: 1px solid var(--uncial-color-border);
449
+ border-radius: var(--uncial-radius-lg);
450
+ background: var(--uncial-color-bg);
451
+ color: var(--uncial-color-text);
452
+ font-family: var(--uncial-font-body);
453
+ font-size: var(--uncial-font-size-base);
454
+ line-height: 1.5;
455
+ }
456
+
457
+ .dashboard[data-theme='light'] {
458
+ color-scheme: light;
459
+ }
460
+
461
+ .dashboard[data-theme='dark'] {
462
+ color-scheme: dark;
463
+ }
464
+
465
+ .topbar {
466
+ display: flex;
467
+ flex-wrap: wrap;
468
+ align-items: center;
469
+ gap: var(--uncial-space-3);
470
+ padding: var(--uncial-space-3) var(--uncial-space-4);
471
+ border-bottom: 1px solid var(--uncial-color-border);
472
+ border-radius: var(--uncial-radius-lg) var(--uncial-radius-lg) 0 0;
473
+ background: var(--uncial-color-surface-elevated);
474
+ }
475
+
476
+ .identity {
477
+ flex: 1 1 10rem;
478
+ min-width: 0;
479
+ }
480
+
481
+ .identity p,
482
+ .status {
483
+ margin: 0;
484
+ }
485
+
486
+ .name {
487
+ font-weight: 700;
488
+ }
489
+
490
+ .location {
491
+ color: var(--uncial-dashboard-muted);
492
+ font-family: var(--uncial-font-mono);
493
+ font-size: 0.8125rem;
494
+ overflow-wrap: anywhere;
495
+ }
496
+
497
+ .session {
498
+ display: flex;
499
+ flex-wrap: wrap;
500
+ align-items: center;
501
+ gap: var(--uncial-space-2);
502
+ font-size: 0.875rem;
503
+ }
504
+
505
+ .body {
506
+ display: grid;
507
+ grid-template-columns: 11rem minmax(0, 1fr);
508
+ }
509
+
510
+ .nav {
511
+ padding: var(--uncial-space-3);
512
+ border-right: 1px solid var(--uncial-color-border);
513
+ }
514
+
515
+ .nav ul {
516
+ display: grid;
517
+ gap: var(--uncial-space-1);
518
+ margin: 0;
519
+ padding: 0;
520
+ list-style: none;
521
+ }
522
+
523
+ .nav a {
524
+ display: block;
525
+ padding: var(--uncial-space-2) var(--uncial-space-3);
526
+ border-radius: var(--uncial-radius-md);
527
+ color: var(--uncial-color-text);
528
+ font-weight: 600;
529
+ text-decoration: none;
530
+ }
531
+
532
+ .nav a:hover {
533
+ background: var(--uncial-color-surface-elevated);
534
+ }
535
+
536
+ .nav a[aria-current='page'] {
537
+ background: var(--uncial-color-primary);
538
+ color: var(--uncial-color-primary-contrast);
539
+ }
540
+
541
+ .content {
542
+ min-width: 0;
543
+ padding: var(--uncial-space-6);
544
+ }
545
+
546
+ .content:only-child {
547
+ grid-column: 1 / -1;
548
+ }
549
+
550
+ h1 {
551
+ margin: 0 0 var(--uncial-space-5);
552
+ font-size: 1.5rem;
553
+ line-height: 1.25;
554
+ overflow-wrap: anywhere;
555
+ }
556
+
557
+ .back {
558
+ display: inline-block;
559
+ margin-bottom: var(--uncial-space-3);
560
+ color: var(--uncial-color-primary);
561
+ }
562
+
563
+ .reason {
564
+ margin: 0 0 var(--uncial-space-4);
565
+ }
566
+
567
+ .dashboard .topbar .menu-button {
568
+ display: none;
569
+ }
570
+
571
+ .dashboard :global(:is(a, button, input, h1, [tabindex]):focus-visible) {
572
+ outline: 2px solid var(--uncial-color-focus-ring);
573
+ outline-offset: 2px;
574
+ }
575
+
576
+ .dashboard :global(:is(.btn, .uncial-cms-media-upload, .uncial-cms-media-delete)) {
577
+ display: inline-flex;
578
+ align-items: center;
579
+ justify-content: center;
580
+ gap: 0.375rem;
581
+ min-height: 2.25rem;
582
+ padding: 0 var(--uncial-space-3);
583
+ border: 1px solid var(--uncial-color-border-strong);
584
+ border-radius: var(--uncial-radius-md);
585
+ background: var(--uncial-color-surface);
586
+ color: var(--uncial-color-text);
587
+ font: inherit;
588
+ font-size: 0.875rem;
589
+ font-weight: 600;
590
+ line-height: 1;
591
+ text-decoration: none;
592
+ cursor: pointer;
593
+ transition: background var(--uncial-transition);
594
+ }
595
+
596
+ .dashboard
597
+ :global(:is(.btn, .uncial-cms-media-upload, .uncial-cms-media-delete):hover:not(:disabled)) {
598
+ background: var(--uncial-color-surface-elevated);
599
+ }
600
+
601
+ .dashboard :global(:is(.btn, .uncial-cms-media-upload):disabled) {
602
+ cursor: not-allowed;
603
+ opacity: 0.6;
604
+ }
605
+
606
+ .dashboard :global(:is(.btn-primary, .uncial-cms-media-upload)),
607
+ .dashboard :global(:is(.btn-primary, .uncial-cms-media-upload):hover:not(:disabled)) {
608
+ border-color: var(--uncial-color-primary);
609
+ background: var(--uncial-color-primary);
610
+ color: var(--uncial-color-primary-contrast);
611
+ }
612
+
613
+ .dashboard :global(:is(.btn-danger, .uncial-cms-media-delete)) {
614
+ border-color: color-mix(in srgb, var(--uncial-color-danger) 70%, var(--uncial-color-border));
615
+ color: var(--uncial-color-danger);
616
+ }
617
+
618
+ .dashboard :global(.visually-hidden) {
619
+ position: absolute;
620
+ width: 1px;
621
+ height: 1px;
622
+ overflow: hidden;
623
+ clip-path: inset(50%);
624
+ white-space: nowrap;
625
+ }
626
+
627
+ @media (max-width: 40rem) {
628
+ .dashboard .topbar .menu-button {
629
+ display: inline-flex;
630
+ }
631
+
632
+ .body {
633
+ grid-template-columns: minmax(0, 1fr);
634
+ }
635
+
636
+ .nav {
637
+ display: none;
638
+ border-right: 0;
639
+ border-bottom: 1px solid var(--uncial-color-border);
640
+ }
641
+
642
+ .nav.open {
643
+ display: block;
644
+ }
645
+
646
+ .content {
647
+ padding: var(--uncial-space-4);
648
+ }
649
+ }
650
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { DashboardProps } from './types.js';
2
+ declare const Dashboard: import("svelte").Component<DashboardProps, {}, "">;
3
+ type Dashboard = ReturnType<typeof Dashboard>;
4
+ export default Dashboard;
@@ -0,0 +1,42 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { mountEditorPage, type MountEditorPageOptions } from '../mount.js';
4
+ import { cmsImageSource } from '../image-source.js';
5
+ import { SignedOutError } from '../errors.js';
6
+ import type { DashboardAction } from './types.js';
7
+
8
+ let {
9
+ options,
10
+ basePath,
11
+ staticDir,
12
+ can,
13
+ onsignedout
14
+ }: {
15
+ options: MountEditorPageOptions;
16
+ basePath: string;
17
+ staticDir?: string;
18
+ can: (action: DashboardAction, subject?: unknown) => boolean;
19
+ onsignedout: (reason: string) => void;
20
+ } = $props();
21
+
22
+ let target: HTMLDivElement;
23
+ let handle: ReturnType<typeof mountEditorPage> | undefined;
24
+
25
+ onMount(() => {
26
+ const source = cmsImageSource(options.config, { base: basePath, staticDir });
27
+ handle = mountEditorPage(target, {
28
+ ...options,
29
+ imageSource: { ...source, upload: can('media-upload') ? source.upload : undefined },
30
+ onerror: (error) => {
31
+ if (error instanceof SignedOutError) onsignedout(error.message);
32
+ }
33
+ });
34
+ return () => handle?.destroy();
35
+ });
36
+
37
+ export function isDirty(): boolean {
38
+ return handle?.isDirty() ?? false;
39
+ }
40
+ </script>
41
+
42
+ <div bind:this={target}></div>
@@ -0,0 +1,14 @@
1
+ import { type MountEditorPageOptions } from '../mount.js';
2
+ import type { DashboardAction } from './types.js';
3
+ type $$ComponentProps = {
4
+ options: MountEditorPageOptions;
5
+ basePath: string;
6
+ staticDir?: string;
7
+ can: (action: DashboardAction, subject?: unknown) => boolean;
8
+ onsignedout: (reason: string) => void;
9
+ };
10
+ declare const FallbackEditor: import("svelte").Component<$$ComponentProps, {
11
+ isDirty: () => boolean;
12
+ }, "">;
13
+ type FallbackEditor = ReturnType<typeof FallbackEditor>;
14
+ export default FallbackEditor;