uncial-cms 5.0.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.
- package/README.md +62 -17
- 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 +639 -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 +39 -0
- package/dist/dashboard/element.js +107 -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 +32 -0
- package/dist/dashboard/types.js +1 -0
- package/dist/define-site.d.ts +11 -6
- package/dist/define-site.js +4 -7
- 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/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 +5 -2
- package/dist/index.js +3 -2
- package/dist/local/vite.d.ts +2 -0
- package/dist/local/vite.js +1 -1
- package/dist/media-source.d.ts +45 -0
- package/dist/media-source.js +113 -0
- package/dist/mount.d.ts +1 -0
- package/dist/mount.js +2 -0
- 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/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 +2 -1
- package/dist/sveltekit/index.js +7 -2
- package/package.json +12 -3
package/dist/server/media.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { NotFoundError } from '../errors.js';
|
|
3
|
-
|
|
4
|
-
usage;
|
|
5
|
-
constructor(usage) {
|
|
6
|
-
super(`This Media item is used by ${usage.count} Content document${usage.count === 1 ? '' : 's'}: ${usage.paths.join(', ')}.`);
|
|
7
|
-
this.usage = usage;
|
|
8
|
-
this.name = 'MediaInUseError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
2
|
+
import { MediaInUseError, NotFoundError } from '../errors.js';
|
|
3
|
+
import { GLOBAL_KIND } from '../globals.js';
|
|
11
4
|
const EXTENSIONS = {
|
|
12
5
|
'image/webp': 'webp',
|
|
13
6
|
'image/png': 'png',
|
|
@@ -100,7 +93,7 @@ export function createMediaLibrary(opts) {
|
|
|
100
93
|
})
|
|
101
94
|
})));
|
|
102
95
|
async function referencing(urls) {
|
|
103
|
-
const records = await store.list();
|
|
96
|
+
const records = (await Promise.all([store.list(), store.list({ kind: GLOBAL_KIND })])).flat();
|
|
104
97
|
const paths = new Map(urls.map((url) => [url, []]));
|
|
105
98
|
for (const record of records) {
|
|
106
99
|
const docs = [record.draft, record.published]
|
|
@@ -136,7 +129,10 @@ export function createMediaLibrary(opts) {
|
|
|
136
129
|
`;
|
|
137
130
|
const items = rows.map((row) => toItem(row, publicBaseUrl));
|
|
138
131
|
const paths = await referencing(items.map((item) => item.url));
|
|
139
|
-
return items.map((item) =>
|
|
132
|
+
return items.map((item) => {
|
|
133
|
+
const usagePaths = paths.get(item.url);
|
|
134
|
+
return { ...item, usage: usagePaths.length, usagePaths };
|
|
135
|
+
});
|
|
140
136
|
},
|
|
141
137
|
async upload(bytes, { filename, title, contentType, uploadedBy }) {
|
|
142
138
|
const id = createHash('sha256').update(bytes).digest('hex');
|
|
@@ -22,6 +22,7 @@ export interface VersionSummary {
|
|
|
22
22
|
}
|
|
23
23
|
export interface ContentStore {
|
|
24
24
|
get(path: string): Promise<ContentRecord | null>;
|
|
25
|
+
/** Globals are listed only when asked for by their kind, `global`. */
|
|
25
26
|
list(query?: {
|
|
26
27
|
kind?: string;
|
|
27
28
|
status?: 'draft' | 'published' | 'any';
|
|
@@ -55,6 +56,10 @@ export interface ContentStore {
|
|
|
55
56
|
etag: string;
|
|
56
57
|
author: string;
|
|
57
58
|
}): Promise<ContentRecord>;
|
|
59
|
+
publishGlobal(name: string, doc: unknown, opts: {
|
|
60
|
+
etag?: string;
|
|
61
|
+
author: string;
|
|
62
|
+
}): Promise<ContentRecord>;
|
|
58
63
|
}
|
|
59
64
|
/**
|
|
60
65
|
* Runs inside a move's transaction, after the record has moved, so a host can
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConflictError, NotFoundError } from '../errors.js';
|
|
2
|
+
import { assertPagePath, GLOBAL_KIND, globalRecordPath, GLOBALS_DIR } from '../globals.js';
|
|
2
3
|
const UNIQUE_VIOLATION = '23505';
|
|
3
4
|
function toRecord(row) {
|
|
4
5
|
return {
|
|
@@ -26,6 +27,14 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
26
27
|
throw new ConflictError();
|
|
27
28
|
return row;
|
|
28
29
|
}
|
|
30
|
+
async function keepPublished(tx, current, author) {
|
|
31
|
+
if (current.published === null)
|
|
32
|
+
return;
|
|
33
|
+
await tx `
|
|
34
|
+
insert into uncial_content_versions (content_id, doc, created_by)
|
|
35
|
+
values (${current.id}, ${json(current.published)}, ${author})
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
29
38
|
async function prune(tx, contentId) {
|
|
30
39
|
const { retention } = opts;
|
|
31
40
|
if ('keep' in retention) {
|
|
@@ -60,11 +69,15 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
60
69
|
${kind === undefined ? sql `` : sql `and kind = ${kind}`}
|
|
61
70
|
${status === 'draft' ? sql `and draft is not null` : sql ``}
|
|
62
71
|
${status === 'published' ? sql `and published is not null` : sql ``}
|
|
72
|
+
${kind === GLOBAL_KIND ? sql `` : sql `and not starts_with(path, ${`/${GLOBALS_DIR}/`})`}
|
|
63
73
|
order by path
|
|
64
74
|
`;
|
|
65
75
|
return rows.map(toRecord);
|
|
66
76
|
},
|
|
67
77
|
async create(path, kind, draft, { author }) {
|
|
78
|
+
assertPagePath(path);
|
|
79
|
+
if (kind === GLOBAL_KIND)
|
|
80
|
+
throw new Error('Globals are saved with publishGlobal.');
|
|
68
81
|
try {
|
|
69
82
|
const [row] = await sql `
|
|
70
83
|
insert into uncial_content (kind, path, draft, updated_by)
|
|
@@ -80,6 +93,7 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
80
93
|
}
|
|
81
94
|
},
|
|
82
95
|
async saveDraft(path, draft, { etag, author }) {
|
|
96
|
+
assertPagePath(path);
|
|
83
97
|
return sql.begin(async (tx) => {
|
|
84
98
|
await lock(tx, path, etag);
|
|
85
99
|
const [row] = await tx `
|
|
@@ -93,19 +107,46 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
93
107
|
});
|
|
94
108
|
},
|
|
95
109
|
async publish(path, { etag, author }) {
|
|
110
|
+
assertPagePath(path);
|
|
96
111
|
return sql.begin(async (tx) => {
|
|
97
112
|
const current = await lock(tx, path, etag);
|
|
98
113
|
if (current.draft === null)
|
|
99
114
|
throw new Error(`Nothing to publish: ${path} has no Draft.`);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
await keepPublished(tx, current, author);
|
|
116
|
+
const [row] = await tx `
|
|
117
|
+
update uncial_content
|
|
118
|
+
set published = draft, draft = null, published_at = now(),
|
|
119
|
+
etag = gen_random_uuid()::text, updated_at = now(), updated_by = ${author}
|
|
120
|
+
where id = ${current.id}
|
|
121
|
+
returning *
|
|
122
|
+
`;
|
|
123
|
+
await prune(tx, current.id);
|
|
124
|
+
return toRecord(row);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
async publishGlobal(name, doc, { etag, author }) {
|
|
128
|
+
const path = globalRecordPath(name);
|
|
129
|
+
if (etag === undefined) {
|
|
130
|
+
try {
|
|
131
|
+
const [row] = await sql `
|
|
132
|
+
insert into uncial_content (kind, path, published, published_at, updated_by)
|
|
133
|
+
values (${GLOBAL_KIND}, ${path}, ${json(doc)}, now(), ${author})
|
|
134
|
+
returning *
|
|
104
135
|
`;
|
|
136
|
+
return toRecord(row);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (isUniqueViolation(error))
|
|
140
|
+
throw new ConflictError();
|
|
141
|
+
throw error;
|
|
105
142
|
}
|
|
143
|
+
}
|
|
144
|
+
return sql.begin(async (tx) => {
|
|
145
|
+
const current = await lock(tx, path, etag);
|
|
146
|
+
await keepPublished(tx, current, author);
|
|
106
147
|
const [row] = await tx `
|
|
107
148
|
update uncial_content
|
|
108
|
-
set published =
|
|
149
|
+
set published = ${json(doc)}, draft = null, published_at = now(),
|
|
109
150
|
etag = gen_random_uuid()::text, updated_at = now(), updated_by = ${author}
|
|
110
151
|
where id = ${current.id}
|
|
111
152
|
returning *
|
|
@@ -115,6 +156,7 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
115
156
|
});
|
|
116
157
|
},
|
|
117
158
|
async unpublish(path, { etag, author }) {
|
|
159
|
+
assertPagePath(path);
|
|
118
160
|
return sql.begin(async (tx) => {
|
|
119
161
|
await lock(tx, path, etag);
|
|
120
162
|
const [row] = await tx `
|
|
@@ -134,6 +176,8 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
134
176
|
});
|
|
135
177
|
},
|
|
136
178
|
async move(from, to, { etag, author }) {
|
|
179
|
+
assertPagePath(from);
|
|
180
|
+
assertPagePath(to);
|
|
137
181
|
try {
|
|
138
182
|
return await sql.begin(async (tx) => {
|
|
139
183
|
await lock(tx, from, etag);
|
|
@@ -179,6 +223,7 @@ export function createPostgresContentStore(sql, opts) {
|
|
|
179
223
|
return version.doc;
|
|
180
224
|
},
|
|
181
225
|
async restore(path, versionId, { etag, author }) {
|
|
226
|
+
assertPagePath(path);
|
|
182
227
|
return sql.begin(async (tx) => {
|
|
183
228
|
const current = await lock(tx, path, etag);
|
|
184
229
|
const [version] = await tx `
|
|
@@ -9,6 +9,7 @@ export interface ServerForgeAdapter extends ForgeAdapter {
|
|
|
9
9
|
getVersion(path: string, versionId: string): Promise<unknown>;
|
|
10
10
|
restore(path: string, versionId: string, etag: string): Promise<ContentView>;
|
|
11
11
|
move(path: string, to: string, etag: string): Promise<ContentView>;
|
|
12
|
+
saveGlobal(name: string, document: unknown, etag?: string): Promise<ContentView>;
|
|
12
13
|
}
|
|
13
14
|
export declare function serverRequest<T>(apiBase: string, method: string, opts?: {
|
|
14
15
|
query?: Record<string, string>;
|
|
@@ -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[];
|
|
@@ -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. */
|
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,23 @@ function resolveSite(opts) {
|
|
|
21
23
|
}
|
|
22
24
|
return { config, localContentDir: opts.localContentDir, localOnly: false };
|
|
23
25
|
}
|
|
26
|
+
function excluded(opts, entry) {
|
|
27
|
+
return isGlobalsPath(entry.path) || (opts.exclude?.(entry) ?? false);
|
|
28
|
+
}
|
|
24
29
|
function createEntries(opts, site) {
|
|
25
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
|
|
35
|
+
.filter((entry) => !excluded(opts, entry))
|
|
31
36
|
.map(({ path }) => ({ path }));
|
|
32
37
|
}
|
|
33
38
|
/** The source for a site path, refusing one the site's `exclude` rules out. */
|
|
34
39
|
function resolveSource(opts, site, sitePath) {
|
|
35
40
|
const map = opts.mapPathToSource ?? ((path) => defaultMapPathToSource(path, site.config.contentDir));
|
|
36
41
|
const source = map(sitePath);
|
|
37
|
-
if (opts
|
|
42
|
+
if (excluded(opts, { path: sitePath, source })) {
|
|
38
43
|
throw new Error(`Content path "${sitePath}" is excluded from this site's routes.`);
|
|
39
44
|
}
|
|
40
45
|
return source;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uncial-cms",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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",
|
|
@@ -78,7 +85,7 @@
|
|
|
78
85
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
79
86
|
"postgres": "^3.4.0",
|
|
80
87
|
"svelte": "^5.0.0",
|
|
81
|
-
"uncial": "^5.
|
|
88
|
+
"uncial": "^5.1.0"
|
|
82
89
|
},
|
|
83
90
|
"peerDependenciesMeta": {
|
|
84
91
|
"@aws-sdk/client-s3": {
|
|
@@ -91,6 +98,7 @@
|
|
|
91
98
|
"devDependencies": {
|
|
92
99
|
"@astrojs/svelte": "^7.2.5",
|
|
93
100
|
"@aws-sdk/client-s3": "^3.1144.0",
|
|
101
|
+
"@axe-core/playwright": "^4.13.0",
|
|
94
102
|
"@playwright/test": "^1.58.2",
|
|
95
103
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
96
104
|
"@sveltejs/kit": "^2.50.2",
|
|
@@ -124,6 +132,7 @@
|
|
|
124
132
|
"test": "pnpm run test:unit -- --run && pnpm run test:browser -- --run && pnpm run test:e2e",
|
|
125
133
|
"test:e2e": "playwright test",
|
|
126
134
|
"test:cli": "node scripts/test-local-only-cli.mjs",
|
|
135
|
+
"test:astro": "playwright test --project astro",
|
|
127
136
|
"test:browser": "vitest --project client"
|
|
128
137
|
}
|
|
129
138
|
}
|