inlaycms 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +469 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
|
|
2
|
+
import { InlayError } from '../../../core/errors.js';
|
|
3
|
+
import { t } from '../../../core/messages/index.js';
|
|
4
|
+
import { singletonPath, withLocale } from '../../../core/site/paths.js';
|
|
5
|
+
import { adminActor, forbidden, formValues, HTML, noticeOf, notFound } from '../context.js';
|
|
6
|
+
import { backOf, idsOf } from '../publish.js';
|
|
7
|
+
import { DataTable, pageOf, readTableQuery, tableHref } from '../views/data-table.js';
|
|
8
|
+
import { Icon } from '../views/icons.js';
|
|
9
|
+
import { adminPage, Alert, initials, Time } from '../views/layout.js';
|
|
10
|
+
import { Badge, badgeClass, documentStatus, StatusBadge, StatusDot } from '../views/status.js';
|
|
11
|
+
import { translationRows } from '../translations.js';
|
|
12
|
+
const TABLE_ID = 'entries-table';
|
|
13
|
+
const STATUSES = ['all', 'published', 'changed', 'new'];
|
|
14
|
+
const STATUS_ORDER = { new: 0, changed: 1, published: 2, deleted: 3 };
|
|
15
|
+
const editorLink = (doc) => `/admin/documents/${encodeURIComponent(doc.id)}`;
|
|
16
|
+
const textOf = (value) => (typeof value === 'string' ? value : '');
|
|
17
|
+
/** Marks a document whose published revision leaves a required field empty. */
|
|
18
|
+
const GapBadge = () => (_jsx(Badge, { tone: "warning", class: "ml-2", children: t('admin.gaps.badge') }));
|
|
19
|
+
function LanguageChips({ row, from }) {
|
|
20
|
+
return (_jsx("span", { class: "flex flex-wrap gap-1", children: [...row.docs].map(([locale, doc]) => {
|
|
21
|
+
const code = locale.toUpperCase();
|
|
22
|
+
if (doc) {
|
|
23
|
+
const label = t('admin.list.languageStatus', { locale: code, status: t(`admin.status.${documentStatus(doc)}`) });
|
|
24
|
+
return (_jsxs("a", { href: editorLink(doc), class: `${badgeClass('ghost')} uppercase`, "aria-label": label, title: label, children: [_jsx(StatusDot, { status: documentStatus(doc) }), locale] }));
|
|
25
|
+
}
|
|
26
|
+
if (!from)
|
|
27
|
+
return null;
|
|
28
|
+
const label = t('admin.list.translateInto', { locale: code });
|
|
29
|
+
return (_jsxs("form", { method: "post", action: `${editorLink(from)}/translations`, children: [_jsx("input", { type: "hidden", name: "locale", value: locale }), _jsxs("button", { type: "submit", class: `${badgeClass('outline')} border-dashed uppercase`, "aria-label": label, title: label, children: [_jsx(Icon, { name: "plus" }), locale] })] }));
|
|
30
|
+
}) }));
|
|
31
|
+
}
|
|
32
|
+
function Person({ name }) {
|
|
33
|
+
if (name === '')
|
|
34
|
+
return null;
|
|
35
|
+
return (_jsxs("span", { class: "flex items-center gap-2 whitespace-nowrap", children: [_jsx("span", { class: "grid size-6 shrink-0 place-items-center rounded-full bg-base-300 text-[10px] font-medium", "aria-hidden": "true", children: initials(name) }), name] }));
|
|
36
|
+
}
|
|
37
|
+
function compareBy(sort) {
|
|
38
|
+
if (sort === 'title')
|
|
39
|
+
return (a, b) => a.title.localeCompare(b.title);
|
|
40
|
+
if (sort === 'status')
|
|
41
|
+
return (a, b) => STATUS_ORDER[documentStatus(a)] - STATUS_ORDER[documentStatus(b)];
|
|
42
|
+
return (a, b) => a.updatedAt.localeCompare(b.updatedAt);
|
|
43
|
+
}
|
|
44
|
+
/** The list's address for this view, leaving out everything at its default. */
|
|
45
|
+
function listHref(base, locale, defaultLocale, query, page) {
|
|
46
|
+
return tableHref(base, {
|
|
47
|
+
locale: locale === defaultLocale ? '' : locale,
|
|
48
|
+
q: query.q,
|
|
49
|
+
status: query.status === 'all' ? '' : query.status,
|
|
50
|
+
sort: query.sort === 'updated' ? '' : query.sort,
|
|
51
|
+
dir: query.dir === 'desc' ? '' : query.dir,
|
|
52
|
+
size: query.size === 25 ? '' : String(query.size),
|
|
53
|
+
page: page > 1 ? String(page) : '',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** The pages, site-wide content and collection lists of the admin. */
|
|
57
|
+
export function registerLists(scope, ctx) {
|
|
58
|
+
const { core } = ctx;
|
|
59
|
+
const { registry } = core;
|
|
60
|
+
const localeOf = (raw) => {
|
|
61
|
+
const value = textOf(raw);
|
|
62
|
+
return registry.locales.includes(value) ? value : registry.defaultLocale;
|
|
63
|
+
};
|
|
64
|
+
for (const [path, section, kind] of [
|
|
65
|
+
['/admin/pages', 'pages', 'singleton'],
|
|
66
|
+
['/admin/globals', 'globals', 'global'],
|
|
67
|
+
]) {
|
|
68
|
+
scope.get(path, async (request, reply) => {
|
|
69
|
+
const actor = adminActor(request);
|
|
70
|
+
const query = request.query;
|
|
71
|
+
const defs = kind === 'singleton' ? registry.site.singletons : registry.site.globals;
|
|
72
|
+
const [rows, found] = await Promise.all([translationRows(ctx, defs), core.listGaps({ types: defs.map((def) => def.name) })]);
|
|
73
|
+
const gapped = new Set(found.map((g) => g.document.id));
|
|
74
|
+
const hasGap = (row) => [...row.docs.values()].some((d) => d !== null && gapped.has(d.id));
|
|
75
|
+
const { locales, defaultLocale } = registry;
|
|
76
|
+
const defaultDoc = (row) => row.docs.get(defaultLocale) ?? null;
|
|
77
|
+
const sourceOf = (row) => [...row.docs.values()].find((d) => d !== null) ?? null;
|
|
78
|
+
const columns = [
|
|
79
|
+
{
|
|
80
|
+
key: 'name',
|
|
81
|
+
label: t(kind === 'singleton' ? 'admin.list.col.page' : 'admin.list.col.item'),
|
|
82
|
+
class: 'max-w-md',
|
|
83
|
+
cell: (row) => {
|
|
84
|
+
const doc = defaultDoc(row);
|
|
85
|
+
return (_jsxs(_Fragment, { children: [doc ? (_jsx("a", { href: editorLink(doc), class: "link link-hover", children: row.def.label })) : (row.def.label), hasGap(row) && _jsx(GapBadge, {}), row.def.help !== undefined && (_jsx("div", { class: "truncate text-xs font-normal text-base-content/60", title: row.def.help, children: row.def.help }))] }));
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
if (kind === 'singleton') {
|
|
90
|
+
columns.push({
|
|
91
|
+
key: 'address',
|
|
92
|
+
label: t('admin.list.col.address'),
|
|
93
|
+
cell: (row) => {
|
|
94
|
+
const address = row.def.kind === 'singleton' ? singletonPath(row.def, defaultLocale, defaultLocale) : null;
|
|
95
|
+
return address === null ? (_jsx("span", { class: "text-base-content/60", children: t('admin.list.noPath') })) : (_jsx("code", { children: withLocale(registry, defaultLocale, address) }));
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
columns.push({
|
|
100
|
+
key: 'status',
|
|
101
|
+
label: t('admin.list.col.status'),
|
|
102
|
+
cell: (row) => {
|
|
103
|
+
const doc = defaultDoc(row);
|
|
104
|
+
return doc ? _jsx(StatusBadge, { doc: doc }) : null;
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
if (locales.length > 1) {
|
|
108
|
+
columns.push({ key: 'languages', label: t('admin.list.col.languages'), cell: (row) => _jsx(LanguageChips, { row: row, from: sourceOf(row) }) });
|
|
109
|
+
}
|
|
110
|
+
columns.push({
|
|
111
|
+
key: 'updated',
|
|
112
|
+
label: t('admin.list.col.updated'),
|
|
113
|
+
class: 'whitespace-nowrap',
|
|
114
|
+
cell: (row) => {
|
|
115
|
+
const doc = defaultDoc(row);
|
|
116
|
+
return doc ? _jsx(Time, { iso: doc.updatedAt, relative: true }) : null;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const body = (_jsx(DataTable, { id: section, caption: t(kind === 'singleton' ? 'admin.nav.pages' : 'admin.nav.globals'), base: path, rows: rows, columns: columns, rowKey: (row) => row.def.name, rowLabel: (row) => row.def.label, rowActions: (row) => {
|
|
120
|
+
const doc = defaultDoc(row) ?? sourceOf(row);
|
|
121
|
+
return doc
|
|
122
|
+
? [
|
|
123
|
+
{ label: t('admin.list.edit'), icon: 'pencil', href: editorLink(doc) },
|
|
124
|
+
{ label: t('admin.list.history'), icon: 'history', href: `${editorLink(doc)}/history` },
|
|
125
|
+
]
|
|
126
|
+
: [];
|
|
127
|
+
}, empty: t('admin.list.empty') }));
|
|
128
|
+
const notice = noticeOf(query);
|
|
129
|
+
const title = t(kind === 'singleton' ? 'admin.nav.pages' : 'admin.nav.globals');
|
|
130
|
+
const page = await adminPage(ctx, { title, actor, section, ...(notice !== undefined && { notice }) }, body);
|
|
131
|
+
return reply.code(200).type(HTML).send(page);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
scope.get('/admin/collections/:type', async (request, reply) => {
|
|
135
|
+
const actor = adminActor(request);
|
|
136
|
+
const { type } = request.params;
|
|
137
|
+
const def = registry.types.get(type);
|
|
138
|
+
if (def?.kind !== 'collection')
|
|
139
|
+
return notFound(reply, ctx, actor);
|
|
140
|
+
const query = request.query;
|
|
141
|
+
const deleted = textOf(query.deleted) === '1';
|
|
142
|
+
if (deleted && actor.role !== 'owner')
|
|
143
|
+
return forbidden(reply, ctx, actor);
|
|
144
|
+
const locale = localeOf(query.locale);
|
|
145
|
+
const asked = readTableQuery(query, {
|
|
146
|
+
sorts: ['title', 'status', 'updated'],
|
|
147
|
+
defaultSort: 'updated',
|
|
148
|
+
defaultDir: 'desc',
|
|
149
|
+
statuses: STATUSES,
|
|
150
|
+
});
|
|
151
|
+
const table = deleted ? { ...asked, q: '', status: 'all' } : asked;
|
|
152
|
+
let source;
|
|
153
|
+
if (deleted) {
|
|
154
|
+
const all = await core.listEntries(type, { locale, includeDeleted: true });
|
|
155
|
+
source = all.filter((d) => d.deletedAt !== null);
|
|
156
|
+
}
|
|
157
|
+
else if (table.q !== '') {
|
|
158
|
+
source = await core.searchEntries(type, table.q, { locale, limit: 50 });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
source = await core.listEntries(type, { locale });
|
|
162
|
+
}
|
|
163
|
+
const countOf = (status) => (status === 'all' ? source.length : source.filter((d) => documentStatus(d) === status).length);
|
|
164
|
+
const filtered = table.status === 'all' ? source : source.filter((d) => documentStatus(d) === table.status);
|
|
165
|
+
const compare = compareBy(table.sort);
|
|
166
|
+
const sorted = [...filtered].sort(table.dir === 'asc' ? compare : (a, b) => compare(b, a));
|
|
167
|
+
const shown = pageOf(sorted, table);
|
|
168
|
+
const authors = new Map();
|
|
169
|
+
await Promise.all(shown.rows.map(async (d) => {
|
|
170
|
+
const view = await core.getDocument(d.id);
|
|
171
|
+
if (view)
|
|
172
|
+
authors.set(d.id, view.revision.authorName);
|
|
173
|
+
}));
|
|
174
|
+
const gaps = deleted ? new Set() : new Set((await core.listGaps({ ids: shown.rows.map((d) => d.id) })).map((g) => g.document.id));
|
|
175
|
+
const live = deleted ? new Map() : await core.liveDocuments(shown.rows.map((d) => d.groupId), locale, { state: 'preview' });
|
|
176
|
+
const pathOf = (d) => {
|
|
177
|
+
const found = live.get(d.groupId);
|
|
178
|
+
return found && found.documentId === d.id ? found.path : null;
|
|
179
|
+
};
|
|
180
|
+
const base = `/admin/collections/${encodeURIComponent(type)}`;
|
|
181
|
+
const bulkId = `${TABLE_ID}-bulk`;
|
|
182
|
+
const back = listHref(base, locale, registry.defaultLocale, table, shown.page);
|
|
183
|
+
const keepLocale = locale === registry.defaultLocale ? '' : locale;
|
|
184
|
+
const columns = [
|
|
185
|
+
{
|
|
186
|
+
key: 'title',
|
|
187
|
+
label: t('admin.list.col.title'),
|
|
188
|
+
sortable: true,
|
|
189
|
+
class: 'max-w-md',
|
|
190
|
+
cell: (d) => {
|
|
191
|
+
const path = pathOf(d);
|
|
192
|
+
return (_jsxs(_Fragment, { children: [_jsx("a", { href: editorLink(d), class: "link link-hover", children: d.title }), gaps.has(d.id) && _jsx(GapBadge, {}), path !== null && _jsx("div", { class: "truncate text-xs font-normal text-base-content/60", children: path })] }));
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{ key: 'status', label: t('admin.list.col.status'), sortable: true, cell: (d) => _jsx(StatusBadge, { doc: d }) },
|
|
196
|
+
{
|
|
197
|
+
key: 'updated',
|
|
198
|
+
label: t('admin.list.col.updated'),
|
|
199
|
+
sortable: true,
|
|
200
|
+
class: 'whitespace-nowrap',
|
|
201
|
+
cell: (d) => _jsx(Time, { iso: d.updatedAt, relative: true }),
|
|
202
|
+
},
|
|
203
|
+
{ key: 'author', label: t('admin.list.col.author'), cell: (d) => _jsx(Person, { name: authors.get(d.id) ?? '' }) },
|
|
204
|
+
];
|
|
205
|
+
if (deleted) {
|
|
206
|
+
columns.push({
|
|
207
|
+
key: 'restore',
|
|
208
|
+
label: t('admin.editor.restore'),
|
|
209
|
+
cell: (d) => (_jsx("form", { method: "post", action: `${editorLink(d)}/restore`, children: _jsx("button", { type: "submit", class: "btn btn-xs", "aria-label": t('admin.editor.restoreItem', { title: d.title }), children: t('admin.editor.restore') }) })),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const { locales } = registry;
|
|
213
|
+
const toolbarEnd = (_jsxs(_Fragment, { children: [locales.length > 1 && (_jsxs(_Fragment, { children: [_jsx("label", { for: `${TABLE_ID}-locale`, class: "sr-only", children: t('admin.list.locale') }), _jsx("select", { id: `${TABLE_ID}-locale`, name: "locale", form: `${TABLE_ID}-filters`, class: "select select-sm w-20", children: locales.map((l) => (_jsx("option", { value: l, selected: l === locale, children: l }))) })] })), actor.role === 'owner' && (_jsxs("details", { class: "dropdown dropdown-end", children: [_jsx("summary", { class: "btn btn-ghost btn-sm btn-square", "aria-label": t('admin.list.more'), children: _jsx(Icon, { name: "more" }) }), _jsx("ul", { class: "dropdown-content menu menu-sm z-20 w-52 rounded-box border border-base-300 bg-base-100 p-1 shadow-lg", children: _jsx("li", { children: _jsxs("a", { href: tableHref(base, { locale: keepLocale, deleted: deleted ? '' : '1' }), children: [_jsx(Icon, { name: "trash" }), t(deleted ? 'admin.list.showCurrent' : 'admin.list.showDeleted')] }) }) })] }))] }));
|
|
214
|
+
const body = (_jsxs(_Fragment, { children: [_jsx(DataTable, { id: TABLE_ID, caption: def.label, base: base, keep: { locale: keepLocale, deleted: deleted ? '1' : '' }, ...(locales.length > 1 && { controls: ['locale'] }), query: table, rows: shown.rows, total: shown.total, columns: columns, rowKey: (d) => d.id, rowLabel: (d) => d.title, ...(!deleted && {
|
|
215
|
+
search: { label: t('admin.list.search') },
|
|
216
|
+
tabs: STATUSES.map((key) => ({ key, label: t(key === 'all' ? 'admin.table.all' : `admin.status.${key}`), count: countOf(key) })),
|
|
217
|
+
rowActions: (d) => [
|
|
218
|
+
{ label: t('admin.list.edit'), icon: 'pencil', href: editorLink(d) },
|
|
219
|
+
{ label: t('admin.list.history'), icon: 'history', href: `${editorLink(d)}/history` },
|
|
220
|
+
{ label: t('admin.list.delete'), icon: 'trash', href: `${editorLink(d)}/delete`, danger: true },
|
|
221
|
+
],
|
|
222
|
+
bulk: {
|
|
223
|
+
actions: (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: "back", value: back, form: bulkId }), _jsx("input", { type: "hidden", name: "ids", value: "", form: bulkId }), _jsxs("button", { type: "submit", formaction: "/admin/publish", formmethod: "get", "data-publish-dialog": true, class: "btn btn-ghost btn-xs", children: [_jsx(Icon, { name: "send" }), t('admin.bulk.publish')] }), _jsxs("button", { type: "submit", formaction: `${base}/delete`, formmethod: "get", "data-bulk-delete": true, class: "btn btn-ghost btn-xs text-error", children: [_jsx(Icon, { name: "trash" }), t('admin.bulk.delete')] })] })),
|
|
224
|
+
},
|
|
225
|
+
}), toolbarEnd: toolbarEnd, empty: t('admin.list.empty') }), !deleted && (_jsxs("dialog", { id: "bulk-delete-dialog", "aria-labelledby": "bulk-delete-title", class: "modal", children: [_jsxs("div", { class: "modal-box flex flex-col gap-4", children: [_jsxs("div", { class: "flex items-center justify-between gap-4", children: [_jsx("h2", { id: "bulk-delete-title", class: "text-lg font-semibold", children: t('admin.bulkDelete.title') }), _jsx("form", { method: "dialog", children: _jsx("button", { type: "submit", class: "btn btn-ghost btn-sm btn-square", "aria-label": t('admin.bulkDelete.close'), children: _jsx(Icon, { name: "x" }) }) })] }), _jsx("div", { id: "bulk-delete-body" })] }), _jsx("form", { method: "dialog", class: "modal-backdrop", children: _jsx("button", { type: "submit", tabindex: "-1", children: t('admin.bulkDelete.close') }) })] }))] }));
|
|
226
|
+
const notice = noticeOf(query);
|
|
227
|
+
const title = deleted ? t('admin.list.deletedTitle', { label: def.label }) : def.label;
|
|
228
|
+
const actions = deleted ? undefined : (_jsxs("a", { href: `${base}/new`, class: "btn btn-primary btn-sm", children: [_jsx(Icon, { name: "plus" }), t('admin.list.new')] }));
|
|
229
|
+
const page = await adminPage(ctx, { title, actor, section: `collection:${type}`, ...(notice !== undefined && { notice }), ...(actions !== undefined && { actions }) }, body);
|
|
230
|
+
return reply.code(200).type(HTML).send(page);
|
|
231
|
+
});
|
|
232
|
+
/** The live entries of `type` among `ids`, in the order asked, each group once. */
|
|
233
|
+
async function entriesOf(type, ids) {
|
|
234
|
+
const found = [];
|
|
235
|
+
const groups = new Set();
|
|
236
|
+
for (const id of ids) {
|
|
237
|
+
const doc = await core.getDocument(id);
|
|
238
|
+
if (!doc || doc.kind !== 'entry' || doc.type !== type || doc.deletedAt !== null || groups.has(doc.groupId))
|
|
239
|
+
continue;
|
|
240
|
+
groups.add(doc.groupId);
|
|
241
|
+
found.push(doc);
|
|
242
|
+
}
|
|
243
|
+
return found;
|
|
244
|
+
}
|
|
245
|
+
/** A return address on this list, or the list itself. */
|
|
246
|
+
const listBackOf = (base, raw) => {
|
|
247
|
+
const back = backOf(raw);
|
|
248
|
+
return back === base || back.startsWith(`${base}?`) ? back : base;
|
|
249
|
+
};
|
|
250
|
+
const bulkPage = (actor, type, label, title, body) => adminPage(ctx, { title, actor, section: `collection:${type}`, breadcrumbs: [{ label, href: `/admin/collections/${encodeURIComponent(type)}` }] }, body);
|
|
251
|
+
const noneChosen = (back) => (_jsxs("div", { id: "bulk-delete-confirm", class: "flex flex-col gap-4", children: [_jsx("p", { children: t('admin.bulkDelete.none') }), _jsx("p", { children: _jsx("a", { href: back, class: "link", children: t('admin.bulkDelete.back') }) })] }));
|
|
252
|
+
scope.get('/admin/collections/:type/delete', async (request, reply) => {
|
|
253
|
+
const actor = adminActor(request);
|
|
254
|
+
const { type } = request.params;
|
|
255
|
+
const def = registry.types.get(type);
|
|
256
|
+
if (def?.kind !== 'collection')
|
|
257
|
+
return notFound(reply, ctx, actor);
|
|
258
|
+
const query = request.query;
|
|
259
|
+
const base = `/admin/collections/${encodeURIComponent(type)}`;
|
|
260
|
+
const back = listBackOf(base, query.back);
|
|
261
|
+
const entries = await entriesOf(type, idsOf(query.ids));
|
|
262
|
+
const body = entries.length === 0 ? (noneChosen(back)) : (_jsxs("div", { id: "bulk-delete-confirm", class: "flex flex-col gap-4", children: [_jsx("p", { children: t('admin.bulkDelete.intro') }), _jsx("ul", { class: "list-disc pl-6", children: entries.map((d) => (_jsx("li", { children: d.title }))) }), _jsxs("form", { method: "post", action: `${base}/delete`, class: "flex flex-wrap items-center gap-2", children: [_jsx("input", { type: "hidden", name: "ids", value: entries.map((d) => d.id).join(',') }), _jsx("input", { type: "hidden", name: "back", value: back }), _jsx("button", { type: "submit", class: "btn btn-error", children: t('admin.bulkDelete.confirm') }), _jsx("a", { href: back, class: "btn btn-ghost", "data-dialog-cancel": true, children: t('admin.bulkDelete.cancel') })] })] }));
|
|
263
|
+
return reply.code(200).type(HTML).send(await bulkPage(actor, type, def.label, t('admin.bulkDelete.title'), body));
|
|
264
|
+
});
|
|
265
|
+
scope.post('/admin/collections/:type/delete', async (request, reply) => {
|
|
266
|
+
const actor = adminActor(request);
|
|
267
|
+
const { type } = request.params;
|
|
268
|
+
const def = registry.types.get(type);
|
|
269
|
+
if (def?.kind !== 'collection')
|
|
270
|
+
return notFound(reply, ctx, actor);
|
|
271
|
+
const form = formValues(request);
|
|
272
|
+
const base = `/admin/collections/${encodeURIComponent(type)}`;
|
|
273
|
+
const back = listBackOf(base, form.get('back'));
|
|
274
|
+
const entries = await entriesOf(type, idsOf(form.all('ids')));
|
|
275
|
+
if (entries.length === 0) {
|
|
276
|
+
return reply.code(200).type(HTML).send(await bulkPage(actor, type, def.label, t('admin.bulkDelete.title'), noneChosen(back)));
|
|
277
|
+
}
|
|
278
|
+
const run = { actor, source: 'admin' };
|
|
279
|
+
let count = 0;
|
|
280
|
+
const failed = [];
|
|
281
|
+
for (const doc of entries) {
|
|
282
|
+
try {
|
|
283
|
+
await core.deleteEntry(doc.groupId, run);
|
|
284
|
+
count += 1;
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
if (!(e instanceof InlayError))
|
|
288
|
+
throw e;
|
|
289
|
+
failed.push({ title: doc.title, reason: t(e.messageId, e.params) });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (failed.length === 0)
|
|
293
|
+
return reply.redirect(`${back}${back.includes('?') ? '&' : '?'}notice=bulkDeleted&count=${count}`, 303);
|
|
294
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-4", children: [count > 0 && (_jsx("div", { role: "status", class: "alert alert-success", children: t('admin.bulkDelete.done', { count }) })), _jsx(Alert, { kind: "error", children: _jsxs("div", { class: "flex flex-col gap-2", children: [_jsx("p", { children: t('admin.bulkDelete.failed') }), _jsx("ul", { class: "list-disc pl-6", children: failed.map((f) => (_jsx("li", { children: t('admin.bulkDelete.failedItem', { title: f.title, reason: f.reason }) }))) })] }) }), _jsx("p", { children: _jsx("a", { href: back, class: "link", children: t('admin.bulkDelete.back') }) })] }));
|
|
295
|
+
return reply.code(200).type(HTML).send(await bulkPage(actor, type, def.label, def.label, body));
|
|
296
|
+
});
|
|
297
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { Ctx, MediaInfo } from '../../../core/types.js';
|
|
3
|
+
import { type AdminContext } from '../context.js';
|
|
4
|
+
/** How many files one upload form may carry. */
|
|
5
|
+
export declare const MAX_FILES = 10;
|
|
6
|
+
export type Kind = 'image' | 'file';
|
|
7
|
+
/** What an upload form did: the files now in the library, and a plain message for each one that failed. */
|
|
8
|
+
export interface UploadOutcome {
|
|
9
|
+
stored: MediaInfo[];
|
|
10
|
+
/** True when every stored file was already in the library. */
|
|
11
|
+
allReused: boolean;
|
|
12
|
+
problems: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads the files of a multipart request and adds each to the library as `ctx`. A file that can't be stored gets a
|
|
16
|
+
* message in `problems`; the others are still stored.
|
|
17
|
+
*/
|
|
18
|
+
export declare function receiveUploads(request: FastifyRequest, ctx: AdminContext, as: Ctx): Promise<UploadOutcome>;
|
|
19
|
+
/** The media library: a grid of uploaded files with search, a kind filter, paging and an upload form. */
|
|
20
|
+
export declare function registerMedia(scope: FastifyInstance, ctx: AdminContext): void;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
|
|
2
|
+
import { InlayError } from '../../../core/errors.js';
|
|
3
|
+
import { isRasterImage, typeLabel } from '../../../core/media/detect.js';
|
|
4
|
+
import { formatSize } from '../../../core/media/labels.js';
|
|
5
|
+
import { sanitizeFilename } from '../../../core/media/library.js';
|
|
6
|
+
import { t } from '../../../core/messages/index.js';
|
|
7
|
+
import { adminActor, formOf, HTML, noticeOf, notFound } from '../context.js';
|
|
8
|
+
import { Icon } from '../views/icons.js';
|
|
9
|
+
import { Alert, adminPage, Time } from '../views/layout.js';
|
|
10
|
+
import { Sheet } from '../views/sheet.js';
|
|
11
|
+
import { mediaPicker } from './pickers.js';
|
|
12
|
+
const PAGE_SIZE = 48;
|
|
13
|
+
/** How many files one upload form may carry. */
|
|
14
|
+
export const MAX_FILES = 10;
|
|
15
|
+
const TOO_MANY_FILES = 'FST_FILES_LIMIT';
|
|
16
|
+
const textOf = (value) => (typeof value === 'string' ? value : '');
|
|
17
|
+
/**
|
|
18
|
+
* Reads the files of a multipart request and adds each to the library as `ctx`. A file that can't be stored gets a
|
|
19
|
+
* message in `problems`; the others are still stored.
|
|
20
|
+
*/
|
|
21
|
+
export async function receiveUploads(request, ctx, as) {
|
|
22
|
+
const outcome = { stored: [], allReused: true, problems: [] };
|
|
23
|
+
if (!request.isMultipart())
|
|
24
|
+
return outcome;
|
|
25
|
+
let seen = 0;
|
|
26
|
+
try {
|
|
27
|
+
for await (const part of request.files({ limits: { files: MAX_FILES, fileSize: ctx.uploads.maxBytes }, throwFileSizeLimit: false })) {
|
|
28
|
+
const data = await part.toBuffer();
|
|
29
|
+
if (part.file.truncated) {
|
|
30
|
+
const max = formatSize(ctx.uploads.maxBytes);
|
|
31
|
+
outcome.problems.push(t('error.mediaTooLarge', { filename: sanitizeFilename(part.filename), max }));
|
|
32
|
+
seen++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// A browser sends an empty, nameless part when no file was chosen.
|
|
36
|
+
if (part.filename === '' && data.length === 0)
|
|
37
|
+
continue;
|
|
38
|
+
seen++;
|
|
39
|
+
try {
|
|
40
|
+
const { media, reused } = await ctx.core.addMedia({ data, filename: part.filename }, as);
|
|
41
|
+
outcome.stored.push(media);
|
|
42
|
+
if (!reused)
|
|
43
|
+
outcome.allReused = false;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
if (!(e instanceof InlayError))
|
|
47
|
+
throw e;
|
|
48
|
+
outcome.problems.push(e.message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
if (e.code !== TOO_MANY_FILES)
|
|
54
|
+
throw e;
|
|
55
|
+
outcome.problems.push(t('admin.media.tooMany', { count: MAX_FILES }));
|
|
56
|
+
}
|
|
57
|
+
if (seen === 0 && outcome.problems.length === 0)
|
|
58
|
+
outcome.problems.push(t('admin.media.noFile'));
|
|
59
|
+
return outcome;
|
|
60
|
+
}
|
|
61
|
+
const href = (base, params) => {
|
|
62
|
+
const query = new URLSearchParams(Object.entries(params).filter(([, v]) => v !== '')).toString();
|
|
63
|
+
return query === '' ? base : `${base}?${query}`;
|
|
64
|
+
};
|
|
65
|
+
function Card({ media }) {
|
|
66
|
+
return (_jsx("li", { class: "card card-border bg-base-100", children: _jsxs("a", { href: `/admin/media/${encodeURIComponent(media.id)}`, class: "flex h-full flex-col", children: [_jsx("figure", { class: "flex aspect-square items-center justify-center bg-base-200", children: isRasterImage(media.mime) ? (_jsx("img", { src: `/media/${media.id}/320.webp`, alt: media.defaultAlt ?? '', loading: "lazy", class: "h-full w-full object-cover" })) : (_jsx("span", { class: "px-2 text-center text-sm font-medium", children: typeLabel(media.mime) })) }), _jsx("span", { class: "card-body p-3 text-sm break-words", children: media.filename })] }) }));
|
|
67
|
+
}
|
|
68
|
+
function Grid({ files }) {
|
|
69
|
+
return (_jsx("ul", { class: "grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4", children: files.map((media) => (_jsx(Card, { media: media }))) }));
|
|
70
|
+
}
|
|
71
|
+
/** The kind filter's value; anything else means all files. */
|
|
72
|
+
const kindOf = (raw) => (raw === 'image' || raw === 'file' ? raw : undefined);
|
|
73
|
+
const usageState = (u) => t(u.in === 'draft' ? 'admin.media.usage.draft' : u.in === 'published' ? 'admin.media.usage.published' : 'admin.media.usage.both');
|
|
74
|
+
function UsageList({ usages }) {
|
|
75
|
+
return (_jsx("ul", { class: "list-disc pl-6", children: usages.map((u) => (_jsxs("li", { children: [_jsx("a", { href: `/admin/documents/${encodeURIComponent(u.documentId)}`, class: "link", children: u.title }), ' ', "(", u.locale, ", ", usageState(u), ")"] }))) }));
|
|
76
|
+
}
|
|
77
|
+
/** The media library: a grid of uploaded files with search, a kind filter, paging and an upload form. */
|
|
78
|
+
export function registerMedia(scope, ctx) {
|
|
79
|
+
const { core, uploads } = ctx;
|
|
80
|
+
const asCtx = (actor) => ({ actor, source: 'admin' });
|
|
81
|
+
const send = async (reply, status, opts, body) => reply.code(status).type(HTML).send(await adminPage(ctx, { ...opts, status }, body));
|
|
82
|
+
async function library(request, reply, status, outcome) {
|
|
83
|
+
const actor = adminActor(request);
|
|
84
|
+
const query = request.query;
|
|
85
|
+
const q = textOf(query.q).trim();
|
|
86
|
+
const kind = kindOf(query.kind);
|
|
87
|
+
const asked = Number.parseInt(textOf(query.page), 10);
|
|
88
|
+
const page = Number.isSafeInteger(asked) && asked > 0 ? asked : 1;
|
|
89
|
+
const found = await core.listMedia({
|
|
90
|
+
...(kind && { kind }),
|
|
91
|
+
...(q !== '' && { search: q }),
|
|
92
|
+
limit: PAGE_SIZE + 1,
|
|
93
|
+
offset: (page - 1) * PAGE_SIZE,
|
|
94
|
+
});
|
|
95
|
+
const files = found.slice(0, PAGE_SIZE);
|
|
96
|
+
const hasNext = found.length > PAGE_SIZE;
|
|
97
|
+
const keep = { q, kind: kind ?? '' };
|
|
98
|
+
const stored = outcome?.stored ?? [];
|
|
99
|
+
const accept = uploads.types.join(',');
|
|
100
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [_jsxs("form", { method: "get", action: "/admin/media", class: "flex flex-wrap items-end gap-4", children: [_jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: "q", class: "text-sm font-medium", children: t('admin.media.search') }), _jsx("input", { id: "q", name: "q", type: "search", value: q, class: "input input-bordered" })] }), _jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: "kind", class: "text-sm font-medium", children: t('admin.media.kind') }), _jsxs("select", { id: "kind", name: "kind", class: "select select-bordered", children: [_jsx("option", { value: "", selected: kind === undefined, children: t('admin.media.kind.all') }), _jsx("option", { value: "image", selected: kind === 'image', children: t('admin.media.kind.image') }), _jsx("option", { value: "file", selected: kind === 'file', children: t('admin.media.kind.file') })] })] }), _jsx("button", { type: "submit", class: "btn", children: t('admin.media.filter') })] }), files.length === 0 ? _jsx("p", { children: t(q !== '' || kind ? 'admin.media.noMatches' : 'admin.media.empty') }) : _jsx(Grid, { files: files }), (page > 1 || hasNext) && (_jsxs("nav", { "aria-label": t('admin.list.page', { page }), class: "flex gap-4", children: [page > 1 && (_jsx("a", { href: href('/admin/media', { ...keep, page: page > 2 ? String(page - 1) : '' }), class: "btn", children: t('admin.list.prev') })), hasNext && (_jsx("a", { href: href('/admin/media', { ...keep, page: String(page + 1) }), class: "btn", children: t('admin.list.next') }))] })), _jsxs(Sheet, { id: "upload-media", title: t('admin.media.uploadHeading'), action: "/admin/media", enctype: "multipart/form-data", submit: t('admin.media.upload'), open: (outcome !== undefined && outcome.problems.length > 0) || query.sheet === 'upload', children: [outcome && outcome.problems.length > 0 && (_jsx(Alert, { kind: "error", id: "upload-problems", children: _jsxs("div", { children: [_jsx("p", { class: "font-semibold", children: t('admin.media.problems') }), _jsx("ul", { class: "list-disc pl-6", children: outcome.problems.map((problem) => (_jsx("li", { children: problem }))) })] }) })), stored.length > 0 && (_jsxs("section", { "aria-labelledby": "stored-heading", class: "flex flex-col gap-2", children: [_jsx("h3", { id: "stored-heading", class: "font-semibold", children: t('admin.media.storedHeading') }), _jsx("ul", { class: "list-disc pl-6", children: stored.map((m) => (_jsx("li", { children: t('admin.upload.uploaded', { filename: m.filename }) }))) })] })), _jsxs("div", { class: "flex flex-col gap-2", children: [_jsx("label", { for: "files", class: "text-sm font-medium", children: t('admin.media.files') }), _jsx("input", { id: "files", name: "file", type: "file", multiple: true, accept: accept, class: "file-input w-full", "aria-describedby": "files-hint" }), _jsx("p", { id: "files-hint", class: "text-sm", children: t('admin.media.uploadHint', { count: MAX_FILES, types: uploads.types.map(typeLabel).join(', '), max: formatSize(uploads.maxBytes) }) })] })] })] }));
|
|
101
|
+
const notice = noticeOf(query);
|
|
102
|
+
const actions = (_jsxs("button", { type: "button", class: "btn btn-primary btn-sm", "data-sheet-open": "upload-media", children: [_jsx(Icon, { name: "upload" }), t('admin.media.uploadHeading')] }));
|
|
103
|
+
return send(reply, status, { title: t('admin.media.title'), actions, actor, section: 'media', ...(notice !== undefined && { notice }) }, body);
|
|
104
|
+
}
|
|
105
|
+
scope.get('/admin/media', (request, reply) => library(request, reply, 200));
|
|
106
|
+
scope.post('/admin/media', async (request, reply) => {
|
|
107
|
+
const actor = adminActor(request);
|
|
108
|
+
const outcome = await receiveUploads(request, ctx, asCtx(actor));
|
|
109
|
+
// From the picker's upload form: the picker again, with the new files first and any problems above.
|
|
110
|
+
const pick = request.query.pick;
|
|
111
|
+
if (pick === 'image' || pick === 'file')
|
|
112
|
+
return reply.code(200).type(HTML).send(await mediaPicker(ctx, { kind: pick, outcome }));
|
|
113
|
+
if (outcome.problems.length > 0)
|
|
114
|
+
return library(request, reply, 400, outcome);
|
|
115
|
+
return reply.redirect(`/admin/media?notice=${outcome.allReused ? 'reused' : 'uploaded'}`, 303);
|
|
116
|
+
});
|
|
117
|
+
async function detail(reply, actor, media, opts = {}) {
|
|
118
|
+
const usages = opts.usages ?? (await core.findUsages({ kind: 'media', id: media.id }));
|
|
119
|
+
const id = encodeURIComponent(media.id);
|
|
120
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [_jsx("div", { children: isRasterImage(media.mime) ? (_jsx("img", { src: `/media/${media.id}/960.webp`, alt: media.defaultAlt ?? '', class: "max-h-96 max-w-full" })) : (_jsx("a", { href: `/media/${id}`, class: "link", children: t('admin.media.download') })) }), _jsxs("dl", { class: "grid grid-cols-[max-content_1fr] gap-x-6 gap-y-1", children: [_jsx("dt", { class: "font-medium", children: t('admin.media.type') }), _jsx("dd", { children: typeLabel(media.mime) }), _jsx("dt", { class: "font-medium", children: t('admin.media.size') }), _jsx("dd", { children: formatSize(media.size) }), media.width !== null && media.height !== null && (_jsxs(_Fragment, { children: [_jsx("dt", { class: "font-medium", children: t('admin.media.dimensions') }), _jsx("dd", { children: t('admin.media.dimensionsValue', { width: media.width, height: media.height }) })] })), _jsx("dt", { class: "font-medium", children: t('admin.media.uploadedBy') }), _jsxs("dd", { children: [media.createdBy, ", ", _jsx(Time, { iso: media.createdAt })] })] }), _jsxs("form", { method: "post", action: `/admin/media/${id}/alt`, class: "flex flex-col gap-2", children: [_jsx("label", { for: "alt", class: "text-sm font-medium", children: t('admin.media.alt') }), _jsx("input", { id: "alt", name: "alt", type: "text", value: media.defaultAlt ?? '', class: "input input-bordered w-full", "aria-describedby": "alt-hint" }), _jsx("p", { id: "alt-hint", class: "text-sm", children: t('admin.media.altHint') }), _jsx("div", { children: _jsx("button", { type: "submit", class: "btn", children: t('admin.media.altSave') }) })] }), _jsxs("section", { "aria-labelledby": "usage-heading", class: "flex flex-col gap-2", children: [_jsx("h2", { id: "usage-heading", class: "text-lg font-semibold", children: t('admin.media.usageHeading') }), usages.length === 0 ? _jsx("p", { children: t('admin.media.unused') }) : _jsx(UsageList, { usages: usages })] }), _jsx("div", { children: _jsx("a", { href: `/admin/media/${id}/delete`, class: "btn btn-error btn-outline", children: t('admin.media.delete') }) })] }));
|
|
121
|
+
return send(reply, 200, {
|
|
122
|
+
title: media.filename,
|
|
123
|
+
actor,
|
|
124
|
+
section: 'media',
|
|
125
|
+
breadcrumbs: [{ label: t('admin.media.title'), href: '/admin/media' }],
|
|
126
|
+
...(opts.notice !== undefined && { notice: opts.notice }),
|
|
127
|
+
}, body);
|
|
128
|
+
}
|
|
129
|
+
async function confirmDelete(reply, status, actor, media, error) {
|
|
130
|
+
const usages = error?.details.usages ?? [];
|
|
131
|
+
const id = encodeURIComponent(media.id);
|
|
132
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-4", children: [error && (_jsx(Alert, { kind: "error", id: "delete-error", children: error.message })), usages.length > 0 && _jsx(UsageList, { usages: usages }), _jsx("p", { children: t('admin.media.delete.confirm', { filename: media.filename }) }), _jsxs("form", { method: "post", action: `/admin/media/${id}/delete`, class: "flex gap-4", children: [_jsx("button", { type: "submit", class: "btn btn-error", children: t('admin.media.delete.submit') }), _jsx("a", { href: `/admin/media/${id}`, class: "btn", children: t('admin.media.cancel') })] })] }));
|
|
133
|
+
return send(reply, status, {
|
|
134
|
+
title: t('admin.media.delete.title', { filename: media.filename }),
|
|
135
|
+
actor,
|
|
136
|
+
section: 'media',
|
|
137
|
+
breadcrumbs: [{ label: t('admin.media.title'), href: '/admin/media' }],
|
|
138
|
+
}, body);
|
|
139
|
+
}
|
|
140
|
+
scope.get('/admin/media/:id', async (request, reply) => {
|
|
141
|
+
const actor = adminActor(request);
|
|
142
|
+
const media = await core.getMedia(request.params.id);
|
|
143
|
+
if (!media)
|
|
144
|
+
return notFound(reply, ctx, actor);
|
|
145
|
+
return detail(reply, actor, media, { ...(noticeOf(request.query) !== undefined && { notice: noticeOf(request.query) }) });
|
|
146
|
+
});
|
|
147
|
+
scope.post('/admin/media/:id/alt', async (request, reply) => {
|
|
148
|
+
const actor = adminActor(request);
|
|
149
|
+
const { id } = request.params;
|
|
150
|
+
try {
|
|
151
|
+
await core.setMediaAlt(id, formOf(request).alt ?? '', asCtx(actor));
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
if (e instanceof InlayError && e.code === 'not_found')
|
|
155
|
+
return notFound(reply, ctx, actor);
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
return reply.redirect(`/admin/media/${encodeURIComponent(id)}?notice=altSaved`, 303);
|
|
159
|
+
});
|
|
160
|
+
scope.get('/admin/media/:id/delete', async (request, reply) => {
|
|
161
|
+
const actor = adminActor(request);
|
|
162
|
+
const media = await core.getMedia(request.params.id);
|
|
163
|
+
if (!media)
|
|
164
|
+
return notFound(reply, ctx, actor);
|
|
165
|
+
return confirmDelete(reply, 200, actor, media);
|
|
166
|
+
});
|
|
167
|
+
scope.post('/admin/media/:id/delete', async (request, reply) => {
|
|
168
|
+
const actor = adminActor(request);
|
|
169
|
+
const media = await core.getMedia(request.params.id);
|
|
170
|
+
if (!media)
|
|
171
|
+
return notFound(reply, ctx, actor);
|
|
172
|
+
try {
|
|
173
|
+
await core.deleteMedia(media.id, asCtx(actor));
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
if (!(e instanceof InlayError))
|
|
177
|
+
throw e;
|
|
178
|
+
if (e.code === 'in_use')
|
|
179
|
+
return confirmDelete(reply, 409, actor, media, e);
|
|
180
|
+
if (e.code === 'not_found')
|
|
181
|
+
return notFound(reply, ctx, actor);
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
return reply.redirect('/admin/media?notice=deleted', 303);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import { type AdminContext } from '../context.js';
|
|
3
|
+
import type { Kind, UploadOutcome } from './media.js';
|
|
4
|
+
/** What choosing a result gives the field: the stored value, its name and, for images, a thumbnail. */
|
|
5
|
+
export interface Pick {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
thumb?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A web address to link to, for rich text's link picker: `client/admin/picker.ts` turns it into the pick
|
|
12
|
+
* `{ value: 'url:<address>', label: <address> }`. Not a `<form>`, since the picker may sit inside the editor's form.
|
|
13
|
+
*/
|
|
14
|
+
export declare function WebAddress(): import("../../../jsx/html.js").Html;
|
|
15
|
+
/**
|
|
16
|
+
* The media picker: an upload form, then the library's files (images only for `image`), 24 at a time. After an
|
|
17
|
+
* upload, the new files come first and any problems are shown above.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mediaPicker(ctx: AdminContext, opts: {
|
|
20
|
+
kind: Kind;
|
|
21
|
+
q?: string;
|
|
22
|
+
page?: number;
|
|
23
|
+
outcome?: UploadOutcome;
|
|
24
|
+
}): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* The fragments the editor's pickers load into the shared dialog: media, entries of a collection, and pages to link
|
|
27
|
+
* to (with `web=1`, which rich text asks for, also a web address).
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerPickers(scope: FastifyInstance, ctx: AdminContext): void;
|