@cossackframework/cms 0.0.0 → 0.9.1
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 +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, Ref, type RefObject, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { getCookie } from 'hono/cookie';
|
|
4
|
+
import { bulkBar } from '#app/dashboard/bulk';
|
|
5
|
+
import { listFilters, listFooter, listTable } from '#app/dashboard/list-table';
|
|
6
|
+
import { Avatar, AvatarGroup, HoverCard, Icon, NativeSelect, AlertDialog, Tooltip, Button, Input } from '@cossackframework/ui';
|
|
7
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
8
|
+
import { ENTRY_ACTION_IDS, entryAuthors, evaluateRule, isCmsError, languageName, mediaUrl, participantColor, recordTitle, translationGroupOf, type BuiltinEntryAction, type EntryAction, type EntryColumn, type FieldFilter, type ListFilter, type RecordShape } from '@cossackframework/cms';
|
|
9
|
+
import { duplicateEntry, importEntries, importItems, listExtras, routeResource, runEntryCommand, termOptions, type ImportReport } from '#app/cms/content';
|
|
10
|
+
import type { TermOption } from '#app/cms/editor';
|
|
11
|
+
import { avatarStack, type Someone } from '#app/cms/collab/presence';
|
|
12
|
+
import { icon } from '#app/cms/icons';
|
|
13
|
+
import { clampPerPage, iconButton, linkButton, notice, pageHeader, saveScreenPreferences, screenCookie, screenHelp, screenOptions, screenPreferences, shortDate, statusBadge } from '#app/cms/ui';
|
|
14
|
+
import { openMatches } from '#app/cms/site';
|
|
15
|
+
|
|
16
|
+
const PAGE_SIZE = 20;
|
|
17
|
+
|
|
18
|
+
/** The list's own quick actions for an entry, before plugins change them: links for Edit and View, the rest run by the list. */
|
|
19
|
+
function builtinActions(record: RecordShape, options: { base: string; url: string | null; canCreate: boolean; publishable: boolean }): EntryAction[] {
|
|
20
|
+
const action = (id: BuiltinEntryAction, label: string, extra: Partial<EntryAction> = {}): EntryAction => ({ id, label, ...extra });
|
|
21
|
+
if (record.status === 'trash') return [action('restore', __('Restore')), action('delete-permanently', __('Delete permanently'), { danger: true })];
|
|
22
|
+
return [
|
|
23
|
+
action('edit', __('Edit'), { href: `${options.base}/${record.id}` }),
|
|
24
|
+
...(options.canCreate ? [action('duplicate', __('Duplicate'))] : []),
|
|
25
|
+
options.publishable ? action('trash', __('Trash'), { danger: true }) : action('delete', __('Delete'), { danger: true }),
|
|
26
|
+
...(options.url ? [action('view', __('View'), { href: options.url })] : []),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Row {
|
|
31
|
+
id: string;
|
|
32
|
+
rev: number;
|
|
33
|
+
title: string;
|
|
34
|
+
slug: string;
|
|
35
|
+
status: string;
|
|
36
|
+
url: string | null;
|
|
37
|
+
/** Who wrote the entry, the main author first. */
|
|
38
|
+
authors: { id: string; name: string; avatar: string | null }[];
|
|
39
|
+
/** Who has the entry open in its room right now. */
|
|
40
|
+
editing: Someone[];
|
|
41
|
+
/** Open review notes on the entry. */
|
|
42
|
+
notes: number;
|
|
43
|
+
locale: string;
|
|
44
|
+
/** Every site language: this entry, its translation, or none yet. */
|
|
45
|
+
languages: { code: string; label: string; id: string | null; status: string }[];
|
|
46
|
+
terms: string[];
|
|
47
|
+
date: string;
|
|
48
|
+
dateLabel: string;
|
|
49
|
+
/** The entry's featured image, when the collection has one. */
|
|
50
|
+
image: { url: string; alt: string; caption: string } | null;
|
|
51
|
+
/** The quick actions under the row: the built-in ones as plugins left them, and theirs. */
|
|
52
|
+
actions: EntryAction[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type Sort = '' | 'title' | 'date';
|
|
56
|
+
/** A bulk action: a built-in status change, or a plugin's. */
|
|
57
|
+
type BulkKey = 'trash' | 'restore' | 'delete' | 'publish' | 'draft' | `plugin:${number}`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Entries of one collection or resource, WordPress style: status tabs, a filter row, sortable
|
|
61
|
+
* columns, checkboxes with bulk actions, and quick actions under each title. Plugins add
|
|
62
|
+
* actions, bulk actions and columns through the `cms.dashboard.*` filters. Screen options,
|
|
63
|
+
* opened from the taskbar, hide columns and set the entries a page lists, kept per collection
|
|
64
|
+
* in the browser's `cs-screen-entries-<collection>` cookie.
|
|
65
|
+
*/
|
|
66
|
+
@Page({ transport: 'http' })
|
|
67
|
+
export default class EntriesPage extends Cossack {
|
|
68
|
+
@Ref() declare importFile: RefObject<HTMLInputElement>;
|
|
69
|
+
@State() route = '';
|
|
70
|
+
@State() label = '';
|
|
71
|
+
@State() singular = '';
|
|
72
|
+
@State() publishable = false;
|
|
73
|
+
@State() canCreate = false;
|
|
74
|
+
/** The last import's outcome, until the next load. */
|
|
75
|
+
@State() imported: ImportReport | null = null;
|
|
76
|
+
@State() importing = false;
|
|
77
|
+
@State() status = 'all';
|
|
78
|
+
@State() search = '';
|
|
79
|
+
@State() term = '';
|
|
80
|
+
@State() taxonomy: { name: string; label: string; terms: TermOption[] } | null = null;
|
|
81
|
+
@State() page = 1;
|
|
82
|
+
/** A search found more entries than this page shows. */
|
|
83
|
+
@State() more = false;
|
|
84
|
+
@State() total = 0;
|
|
85
|
+
@State() counts: { key: string; label: string; count: number }[] = [];
|
|
86
|
+
@State() rows: Row[] = [];
|
|
87
|
+
@State() message = '';
|
|
88
|
+
@State() error = '';
|
|
89
|
+
@State() pendingDelete: Row | null = null;
|
|
90
|
+
@State() hasSlug = false;
|
|
91
|
+
@State() hasImage = false;
|
|
92
|
+
/** Languages to filter by, on a site with several. */
|
|
93
|
+
@State() languages: { code: string; label: string }[] = [];
|
|
94
|
+
/** The language listed: one at a time on a site with several, the default first; `all` lists every entry. */
|
|
95
|
+
@State() locale = '';
|
|
96
|
+
@State() defaultLocale = '';
|
|
97
|
+
@State() sort: Sort = '';
|
|
98
|
+
@State() dir: 'asc' | 'desc' = 'desc';
|
|
99
|
+
@State() selected: string[] = [];
|
|
100
|
+
@State() bulk = '';
|
|
101
|
+
@State() pluginBulk: EntryAction[] = [];
|
|
102
|
+
@State() columns: EntryColumn[] = [];
|
|
103
|
+
/** A bulk action waiting for confirmation. */
|
|
104
|
+
@State() pendingBulk: { key: BulkKey; label: string; text: string } | null = null;
|
|
105
|
+
/** A plugin action with a question, waiting for confirmation. */
|
|
106
|
+
@State() pendingAction: { row: Row; action: EntryAction } | null = null;
|
|
107
|
+
/** Screen options: entries a page lists, and the optional columns hidden, by ID. */
|
|
108
|
+
@State() perPage = PAGE_SIZE;
|
|
109
|
+
@State() hidden: string[] = [];
|
|
110
|
+
|
|
111
|
+
head(): HeadValue {
|
|
112
|
+
return { title: this.label || 'Content' };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Server methods act on the collection the URL names, never on the client's state. */
|
|
116
|
+
private fromRoute(): void {
|
|
117
|
+
this.route = this.c.req.param('collection') ?? '';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async init() {
|
|
121
|
+
this.route = this.c.req.param('collection') ?? '';
|
|
122
|
+
this.status = this.c.req.query('status') ?? 'all';
|
|
123
|
+
this.search = (this.c.req.query('q') ?? '').trim().slice(0, 200);
|
|
124
|
+
this.term = this.c.req.query('term') ?? '';
|
|
125
|
+
this.locale = this.c.req.query('lang') ?? '';
|
|
126
|
+
const sort = this.c.req.query('sort');
|
|
127
|
+
this.sort = sort === 'title' || sort === 'date' ? sort : '';
|
|
128
|
+
this.dir = this.c.req.query('dir') === 'asc' ? 'asc' : 'desc';
|
|
129
|
+
const page = Number(this.c.req.query('page'));
|
|
130
|
+
this.page = Number.isSafeInteger(page) && page > 0 ? page : 1;
|
|
131
|
+
const screen = screenPreferences(getCookie(this.c, screenCookie(`entries-${this.route}`)), { hidden: [], perPage: PAGE_SIZE });
|
|
132
|
+
this.perPage = screen.perPage;
|
|
133
|
+
this.hidden = screen.hidden;
|
|
134
|
+
await this.load();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Server()
|
|
138
|
+
private async load() {
|
|
139
|
+
this.fromRoute();
|
|
140
|
+
const cms = this.c.get('cms');
|
|
141
|
+
const principal = this.c.get('principal');
|
|
142
|
+
let resource;
|
|
143
|
+
try { ({ resource } = routeResource(cms, this.route)); }
|
|
144
|
+
catch { this.error = __('This content type does not exist.'); this.c.status(404); return; }
|
|
145
|
+
const collection = resource.owner === 'cms' ? cms.collection(resource.name) : null;
|
|
146
|
+
this.label = resource.label ?? resource.id;
|
|
147
|
+
this.singular = collection?.singular ?? __('entry');
|
|
148
|
+
this.publishable = Boolean(collection && collection.publishable !== false);
|
|
149
|
+
this.hasSlug = Boolean(collection && collection.slug !== false);
|
|
150
|
+
// Screen options arrive with the client's state over RPC: keep them in bounds.
|
|
151
|
+
this.perPage = clampPerPage(this.perPage, PAGE_SIZE);
|
|
152
|
+
this.hidden = Array.isArray(this.hidden) ? this.hidden.filter(id => typeof id === 'string').slice(0, 50) : [];
|
|
153
|
+
const languages = await cms.languages();
|
|
154
|
+
this.languages = collection && languages.multilingual ? languages.all.map(code => ({ code, label: languageName(code) })) : [];
|
|
155
|
+
this.defaultLocale = this.languages.length ? languages.default : '';
|
|
156
|
+
if (!this.languages.length) this.locale = '';
|
|
157
|
+
else if (this.locale !== 'all' && !this.languages.some(language => language.code === this.locale)) this.locale = languages.default;
|
|
158
|
+
this.canCreate = evaluateRule(resource.access.create, principal) !== 'deny';
|
|
159
|
+
const taxonomyName = Object.values(resource.fields).find(field => field.taxonomy && cms.taxonomies.declaration(field.taxonomy).hierarchical)?.taxonomy
|
|
160
|
+
?? Object.values(resource.fields).find(field => field.taxonomy)?.taxonomy;
|
|
161
|
+
if (taxonomyName) {
|
|
162
|
+
const declaration = cms.taxonomies.declaration(taxonomyName);
|
|
163
|
+
this.taxonomy = { name: taxonomyName, label: declaration.label, terms: await termOptions(cms, taxonomyName) };
|
|
164
|
+
}
|
|
165
|
+
// The featured image: the collection's own, or the first single media field.
|
|
166
|
+
const imageField = resource.fields.featuredImage?.media ? 'featuredImage' : Object.entries(resource.fields).find(([, field]) => field.kind === 'string' && field.media)?.[0];
|
|
167
|
+
this.hasImage = Boolean(imageField && cms.files);
|
|
168
|
+
const repository = cms.resource(resource.id);
|
|
169
|
+
const context = { principal };
|
|
170
|
+
const me = principal.kind === 'user' ? principal.id : '';
|
|
171
|
+
const tabs: { key: string; label: string; filter: ListFilter }[] = this.publishable ? [
|
|
172
|
+
{ key: 'all', label: __('All'), filter: { where: { status: { ne: 'trash' } } } },
|
|
173
|
+
...(this.canCreate && me && resource.ownership ? [{ key: 'mine', label: __('Mine'), filter: { where: { status: { ne: 'trash' } }, owner: me } }] : []),
|
|
174
|
+
{ key: 'published', label: __('Published'), filter: { where: { status: 'published' } } },
|
|
175
|
+
{ key: 'scheduled', label: __('Scheduled'), filter: { where: { status: 'scheduled' } } },
|
|
176
|
+
{ key: 'pending', label: __('Pending'), filter: { where: { status: 'pending' } } },
|
|
177
|
+
{ key: 'draft', label: __('Drafts'), filter: { where: { status: 'draft' } } },
|
|
178
|
+
{ key: 'trash', label: __('Trash'), filter: { where: { status: 'trash' } } },
|
|
179
|
+
] : [{ key: 'all', label: __('All'), filter: {} }];
|
|
180
|
+
try {
|
|
181
|
+
const language: { [field: string]: FieldFilter } = this.locale && this.locale !== 'all' ? { locale: this.locale } : {};
|
|
182
|
+
const counts = await repository.countMany(tabs.map(tab => ({ ...tab.filter, where: { ...(tab.filter.where ?? {}), ...language } })), context);
|
|
183
|
+
// Empty tabs other than All and Published stay out of the way, as in WordPress.
|
|
184
|
+
this.counts = tabs.map((tab, index) => ({ key: tab.key, label: tab.label, count: counts[index]! }))
|
|
185
|
+
.filter(tab => tab.count > 0 || ['all', 'published'].includes(tab.key) || tab.key === this.status);
|
|
186
|
+
const tab = tabs.find(entry => entry.key === this.status) ?? tabs[0]!;
|
|
187
|
+
this.status = tab.key;
|
|
188
|
+
const where: { [field: string]: FieldFilter } = { ...(tab.filter.where ?? {}), ...language };
|
|
189
|
+
if (this.term && this.taxonomy) where[this.taxonomy.name] = { containsAny: (await cms.taxonomies.subtree(this.term)).slice(0, 50) };
|
|
190
|
+
const filter: ListFilter = { where, ...(tab.filter.owner ? { owner: tab.filter.owner } : {}) };
|
|
191
|
+
let records: readonly RecordShape[];
|
|
192
|
+
this.more = false;
|
|
193
|
+
if (this.search && Object.values(resource.fields).some(field => field.search)) {
|
|
194
|
+
// Search knows no total: a page asks for one more entry to tell whether another follows.
|
|
195
|
+
const offset = Math.min((this.page - 1) * this.perPage, 10_000 - this.perPage - 1);
|
|
196
|
+
const found = await repository.search(this.search, { ...filter, limit: this.perPage + 1, offset }, context);
|
|
197
|
+
this.more = found.length > this.perPage;
|
|
198
|
+
records = openMatches(cms, resource.id, found.slice(0, this.perPage), context.principal);
|
|
199
|
+
this.total = offset + records.length;
|
|
200
|
+
} else {
|
|
201
|
+
// The Date column sorts by the publication time on the Published and Scheduled tabs, by the last change elsewhere.
|
|
202
|
+
const dateField = this.publishable && ['published', 'scheduled'].includes(this.status) ? 'publishedAt' : 'updatedAt';
|
|
203
|
+
const order = this.sort === 'title' ? { field: resource.titleField ?? 'title', direction: this.dir } : { field: this.sort === 'date' ? dateField : 'updatedAt', direction: this.sort ? this.dir : 'desc' as const };
|
|
204
|
+
const [page, total] = await Promise.all([
|
|
205
|
+
repository.list({ ...filter, limit: this.perPage, offset: (this.page - 1) * this.perPage, order }, context),
|
|
206
|
+
repository.count(filter, context),
|
|
207
|
+
]);
|
|
208
|
+
records = page.records;
|
|
209
|
+
this.total = total;
|
|
210
|
+
}
|
|
211
|
+
const owners = await cms.users.getMany([...new Set(records.flatMap(record => entryAuthors(record)))]);
|
|
212
|
+
// Who is editing each entry now, from its room's draft row.
|
|
213
|
+
const editing = await cms.drafts.editors(resource.id, records.map(record => record.id)).catch(() => new Map<string, string[]>());
|
|
214
|
+
const editors = await cms.users.getMany([...new Set([...editing.values()].flat())]);
|
|
215
|
+
const noteCounts = await cms.notes.counts(resource.id, records.map(record => record.id)).catch(() => new Map<string, number>());
|
|
216
|
+
const termIds = this.taxonomy ? records.flatMap(record => (record[this.taxonomy!.name] as string[] | undefined) ?? []) : [];
|
|
217
|
+
const terms = await cms.taxonomies.getMany(termIds);
|
|
218
|
+
const urls = collection ? await cms.entryUrls(collection, records) : new Map<string, string | null>();
|
|
219
|
+
const translations = collection && this.languages.length ? await cms.translationsOf(collection, records, context) : new Map<string, Map<string, RecordShape>>();
|
|
220
|
+
const images = imageField && cms.files ? await cms.files.getMany(records.map(record => record[imageField]).filter((id): id is string => typeof id === 'string' && !!id)) : new Map();
|
|
221
|
+
const visible = (record: RecordShape) => (record.status === 'published' && typeof record.publishedAt === 'number') || !this.publishable ? urls.get(record.id) ?? null : null;
|
|
222
|
+
const base = `/dashboard/content/${this.route}`;
|
|
223
|
+
const extras = await listExtras(cms, resource.id, records, principal, record => builtinActions(record, { base, url: visible(record), canCreate: this.canCreate, publishable: this.publishable }));
|
|
224
|
+
this.columns = extras.columns;
|
|
225
|
+
this.pluginBulk = extras.bulk;
|
|
226
|
+
this.rows = records.map(record => {
|
|
227
|
+
const published = record.status === 'published' && typeof record.publishedAt === 'number';
|
|
228
|
+
const scheduled = record.status === 'scheduled' && typeof record.publishedAt === 'number';
|
|
229
|
+
const image = imageField ? images.get(record[imageField] as string) : undefined;
|
|
230
|
+
return {
|
|
231
|
+
id: record.id, rev: record.rev, title: recordTitle(record, resource.titleField), slug: typeof record.slug === 'string' ? record.slug : '', status: String(record.status ?? ''),
|
|
232
|
+
url: visible(record),
|
|
233
|
+
authors: entryAuthors(record).map(id => owners.get(id)).filter(user => user !== undefined).map(user => ({ id: user.id, name: user.name || user.email, avatar: user.avatar })), locale: typeof record.locale === 'string' ? record.locale : '',
|
|
234
|
+
editing: (editing.get(record.id) ?? []).map(id => editors.get(id)).filter(user => user !== undefined).map(user => ({ user: user.id, name: user.name || user.email, avatar: user.avatar, color: participantColor(user.id) })),
|
|
235
|
+
notes: noteCounts.get(record.id) ?? 0,
|
|
236
|
+
languages: this.languages.map(({ code, label }) => {
|
|
237
|
+
const entry = translations.get(translationGroupOf(record))?.get(code);
|
|
238
|
+
return { code, label, id: entry?.id ?? null, status: entry ? String(entry.status ?? '') : '' };
|
|
239
|
+
}),
|
|
240
|
+
terms: this.taxonomy ? ((record[this.taxonomy.name] as string[] | undefined) ?? []).map(id => terms.get(id)?.name).filter((name): name is string => !!name) : [],
|
|
241
|
+
date: shortDate(published || scheduled ? record.publishedAt : record.updatedAt),
|
|
242
|
+
dateLabel: published ? __('Published') : scheduled ? __('Scheduled for') : __('Last modified'),
|
|
243
|
+
image: image ? { url: mediaUrl(image), alt: image.alt, caption: image.caption } : null,
|
|
244
|
+
actions: extras.actions[record.id] ?? [],
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
this.selected = this.selected.filter(id => this.rows.some(row => row.id === id));
|
|
248
|
+
} catch (error) {
|
|
249
|
+
this.error = isCmsError(error) ? error.message : __('The entries could not be loaded.');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Import a JSON export or list of entries chosen in the file input. */
|
|
254
|
+
@Client()
|
|
255
|
+
async pickImport(event: Event) {
|
|
256
|
+
const input = event.target as HTMLInputElement;
|
|
257
|
+
const file = input.files?.[0];
|
|
258
|
+
input.value = '';
|
|
259
|
+
if (!file) return;
|
|
260
|
+
this.importing = true;
|
|
261
|
+
try { await this.importJson(await file.text()); }
|
|
262
|
+
finally { this.importing = false; }
|
|
263
|
+
// What the import did; the entries it could not take are listed below the message.
|
|
264
|
+
if (!this.error && this.imported) this.message = `${this.imported.created} ${__('created')}, ${this.imported.updated} ${__('updated')}${this.imported.failed.length ? `, ${this.imported.failed.length} ${__('failed')}` : ''}.`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@Server()
|
|
268
|
+
async importJson(text: string) {
|
|
269
|
+
this.fromRoute();
|
|
270
|
+
this.message = '';
|
|
271
|
+
this.error = '';
|
|
272
|
+
this.imported = null;
|
|
273
|
+
let parsed: unknown;
|
|
274
|
+
try { parsed = JSON.parse(text); } catch { this.error = __('The file is not valid JSON.'); return; }
|
|
275
|
+
const items = importItems(parsed);
|
|
276
|
+
if (typeof items === 'string') { this.error = __(items); return; }
|
|
277
|
+
try {
|
|
278
|
+
this.imported = await importEntries(this.c.get('cms'), this.route, items, this.c.get('principal'));
|
|
279
|
+
this.message = `${__('Imported')}: ${this.imported.created} ${__('created')}, ${this.imported.updated} ${__('updated')}.`;
|
|
280
|
+
} catch (error) { this.error = isCmsError(error) ? error.message : __('The entries could not be imported.'); return; }
|
|
281
|
+
await this.load();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@Server()
|
|
285
|
+
async moveTo(id: string, rev: number, status: 'trash' | 'draft') {
|
|
286
|
+
this.fromRoute();
|
|
287
|
+
this.message = '';
|
|
288
|
+
this.error = '';
|
|
289
|
+
try {
|
|
290
|
+
const { resource } = routeResource(this.c.get('cms'), this.route);
|
|
291
|
+
await this.c.get('cms').resource(resource.id).update(id, { status }, { principal: this.c.get('principal'), expectedRevision: rev });
|
|
292
|
+
this.message = status === 'trash' ? __('Moved to the trash.') : __('Restored as a draft.');
|
|
293
|
+
} catch (error) {
|
|
294
|
+
this.error = isCmsError(error) ? error.message : __('The entry could not be changed.');
|
|
295
|
+
}
|
|
296
|
+
await this.load();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@Server()
|
|
300
|
+
async deleteEntry(id: string, rev: number) {
|
|
301
|
+
this.fromRoute();
|
|
302
|
+
this.message = '';
|
|
303
|
+
this.error = '';
|
|
304
|
+
try {
|
|
305
|
+
const { resource } = routeResource(this.c.get('cms'), this.route);
|
|
306
|
+
await this.c.get('cms').resource(resource.id).delete(id, { principal: this.c.get('principal'), expectedRevision: rev });
|
|
307
|
+
this.message = __('Deleted permanently.');
|
|
308
|
+
} catch (error) {
|
|
309
|
+
this.error = isCmsError(error) ? error.message : __('The entry could not be deleted.');
|
|
310
|
+
}
|
|
311
|
+
await this.load();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** A draft copy of the entry, kept in this list with a link to edit it. */
|
|
315
|
+
@Server()
|
|
316
|
+
async duplicate(id: string) {
|
|
317
|
+
this.fromRoute();
|
|
318
|
+
this.message = '';
|
|
319
|
+
this.error = '';
|
|
320
|
+
try {
|
|
321
|
+
const copy = await duplicateEntry(this.c.get('cms'), this.route, id, this.c.get('principal'));
|
|
322
|
+
this.message = `${__('Copied as')} “${recordTitle(copy, routeResource(this.c.get('cms'), this.route).resource.titleField)}”.`;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
this.error = isCmsError(error) ? error.message : __('The entry could not be copied.');
|
|
325
|
+
}
|
|
326
|
+
await this.load();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Run a plugin's action for one entry. */
|
|
330
|
+
@Server()
|
|
331
|
+
async runAction(id: string, index: number) {
|
|
332
|
+
this.fromRoute();
|
|
333
|
+
this.message = '';
|
|
334
|
+
this.error = '';
|
|
335
|
+
const cms = this.c.get('cms');
|
|
336
|
+
const principal = this.c.get('principal');
|
|
337
|
+
try {
|
|
338
|
+
const { resource } = routeResource(cms, this.route);
|
|
339
|
+
const record = await cms.resource(resource.id).get(id, { principal });
|
|
340
|
+
if (!record) throw new Error('missing');
|
|
341
|
+
// The action is read again from the plugins, so the client cannot name a command of its own.
|
|
342
|
+
const action = (await listExtras(cms, resource.id, [record], principal)).actions[id]?.filter(entry => entry.command)[index];
|
|
343
|
+
if (!action?.command) throw new Error('missing');
|
|
344
|
+
await runEntryCommand(cms, action, { resource: resource.id, id }, principal, this.c.req.raw.signal);
|
|
345
|
+
this.message = `${action.label}: ${__('done.')}`;
|
|
346
|
+
} catch (error) {
|
|
347
|
+
this.error = isCmsError(error) ? error.message : __('The action could not be run.');
|
|
348
|
+
}
|
|
349
|
+
await this.load();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Apply a bulk action to the selected entries, one by one, and report what went wrong. */
|
|
353
|
+
@Server({ input: input.args(input.array(input.object({ id: input.string({ minLength: 1, maxLength: 200 }), rev: input.number({ integer: true, min: 0 }) }), { maxItems: 1000 }), input.string({ maxLength: 2000 })) })
|
|
354
|
+
async applyBulk(entries: { id: string; rev: number }[], key: string) {
|
|
355
|
+
this.fromRoute();
|
|
356
|
+
this.message = '';
|
|
357
|
+
this.error = '';
|
|
358
|
+
const cms = this.c.get('cms');
|
|
359
|
+
const principal = this.c.get('principal');
|
|
360
|
+
const { resource } = routeResource(cms, this.route);
|
|
361
|
+
const repository = cms.resource(resource.id);
|
|
362
|
+
const failures: string[] = [];
|
|
363
|
+
let done = 0;
|
|
364
|
+
if (key.startsWith('plugin:')) {
|
|
365
|
+
const action = (await listExtras(cms, resource.id, [], principal)).bulk[Number(key.slice('plugin:'.length))];
|
|
366
|
+
if (!action?.command) { this.error = __('This action is not available.'); await this.load(); return; }
|
|
367
|
+
try { await runEntryCommand(cms, action, { resource: resource.id, ids: entries.map(entry => entry.id) }, principal, this.c.req.raw.signal); done = entries.length; }
|
|
368
|
+
catch (error) { failures.push(isCmsError(error) ? error.message : __('The action could not be run.')); }
|
|
369
|
+
} else if (!['trash', 'restore', 'delete', 'publish', 'draft'].includes(key)) {
|
|
370
|
+
this.error = __('This action is not available.');
|
|
371
|
+
await this.load();
|
|
372
|
+
return;
|
|
373
|
+
} else {
|
|
374
|
+
const status = ({ trash: 'trash', restore: 'draft', publish: 'published', draft: 'draft' } as Record<string, string>)[key];
|
|
375
|
+
for (const entry of entries) {
|
|
376
|
+
try {
|
|
377
|
+
if (key === 'delete') await repository.delete(entry.id, { principal, expectedRevision: entry.rev });
|
|
378
|
+
else await repository.update(entry.id, { status }, { principal, expectedRevision: entry.rev });
|
|
379
|
+
done++;
|
|
380
|
+
} catch (error) { failures.push(isCmsError(error) ? error.message : __('An entry could not be changed.')); }
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const labels: Record<string, string> = { trash: __('moved to the trash.'), restore: __('restored as drafts.'), delete: __('deleted permanently.'), publish: __('published.'), draft: __('set back to draft.') };
|
|
384
|
+
if (done) this.message = `${done} ${done === 1 ? this.singular.toLowerCase() : this.label.toLowerCase()} ${labels[key] ?? __('done.')}`;
|
|
385
|
+
if (failures.length) this.error = [...new Set(failures)].slice(0, 3).join(' ');
|
|
386
|
+
this.selected = [];
|
|
387
|
+
this.bulk = '';
|
|
388
|
+
await this.load();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
@Client()
|
|
392
|
+
async confirmDelete() {
|
|
393
|
+
const row = this.pendingDelete;
|
|
394
|
+
this.pendingDelete = null;
|
|
395
|
+
if (row) await this.deleteEntry(row.id, row.rev);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
@Client()
|
|
399
|
+
select(ids: string[]) {
|
|
400
|
+
this.selected = ids;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** The bulk actions the current tab offers. */
|
|
404
|
+
private bulkChoices(): { key: BulkKey; label: string; confirm?: string }[] {
|
|
405
|
+
const trashed = this.status === 'trash';
|
|
406
|
+
const builtin: { key: BulkKey; label: string; confirm?: string }[] = !this.publishable ? [{ key: 'delete', label: __('Delete'), confirm: __('The selected entries and their revisions will be deleted. This cannot be undone.') }]
|
|
407
|
+
: trashed ? [{ key: 'restore', label: __('Restore') }, { key: 'delete', label: __('Delete permanently'), confirm: __('The selected entries and their revisions will be deleted. This cannot be undone.') }]
|
|
408
|
+
: [{ key: 'publish', label: __('Publish') }, { key: 'draft', label: __('Unpublish') }, { key: 'trash', label: __('Move to trash') }];
|
|
409
|
+
return [...builtin, ...this.pluginBulk.map((action, index) => ({ key: `plugin:${index}` as const, label: action.label, ...(action.confirm ? { confirm: action.confirm } : {}) }))];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
@Client()
|
|
413
|
+
async submitBulk() {
|
|
414
|
+
const choice = this.bulkChoices().find(entry => entry.key === this.bulk);
|
|
415
|
+
if (!choice || !this.selected.length) return;
|
|
416
|
+
if (choice.confirm) { this.pendingBulk = { key: choice.key, label: choice.label, text: choice.confirm }; return; }
|
|
417
|
+
await this.runBulk(choice.key);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
@Client()
|
|
421
|
+
async runBulk(key: BulkKey) {
|
|
422
|
+
this.pendingBulk = null;
|
|
423
|
+
const entries = this.rows.filter(row => this.selected.includes(row.id)).map(row => ({ id: row.id, rev: row.rev }));
|
|
424
|
+
await this.applyBulk(entries, key);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Open an entry's translation in a language, starting it as a draft copy. */
|
|
428
|
+
@Server()
|
|
429
|
+
async translate(id: string, locale: string) {
|
|
430
|
+
this.fromRoute();
|
|
431
|
+
this.error = '';
|
|
432
|
+
try {
|
|
433
|
+
const translation = await this.c.get('cms').translateEntry(this.route, id, locale, this.c.get('principal'));
|
|
434
|
+
return this.redirect(`/dashboard/content/${this.route}/${translation.id}`);
|
|
435
|
+
} catch (error) { this.error = isCmsError(error) ? error.message : __('The translation could not be started.'); }
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** The entry's language and its translations: a link to each, a button to start a missing one. */
|
|
439
|
+
private languagesCell(row: Row): TemplateResult {
|
|
440
|
+
const chip = 'inline-flex h-6 min-w-8 items-center justify-center rounded border px-1.5 text-[11px] font-medium no-underline';
|
|
441
|
+
return html`<div class="flex flex-wrap gap-1" data-translations>${row.languages.map(language => {
|
|
442
|
+
const code = language.code.toUpperCase();
|
|
443
|
+
if (language.id === row.id) return html`<span class=${`${chip} border-primary bg-primary text-primary-foreground`} title=${`${language.label}: ${__('this entry')}`}>${code}</span>`;
|
|
444
|
+
if (language.id) {
|
|
445
|
+
const done = !this.publishable || language.status === 'published';
|
|
446
|
+
return html`<a href=${`/dashboard/content/${this.route}/${language.id}`} data-translation=${language.code} class=${`${chip} ${done ? 'border-border text-foreground' : 'border-dashed border-border text-muted-foreground'} hover:bg-muted`}
|
|
447
|
+
title=${`${language.label}: ${language.status || __('translated')}`} aria-label=${`${__('Edit translation')}: ${language.label}`}>${code}</a>`;
|
|
448
|
+
}
|
|
449
|
+
return this.canCreate
|
|
450
|
+
? html`<button type="button" data-translate=${language.code} class=${`${chip} cursor-pointer border-dashed border-border bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground`}
|
|
451
|
+
title=${`${__('Translate into')} ${language.label}`} aria-label=${`${__('Translate into')} ${language.label}`} @click=${() => this.translate(row.id, language.code)}>+${code}</button>`
|
|
452
|
+
: html`<span class=${`${chip} border-transparent text-muted-foreground/60`} title=${`${language.label}: ${__('not translated')}`}>${code}</span>`;
|
|
453
|
+
})}</div>`;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
@Client()
|
|
457
|
+
async pickAction(row: Row, action: EntryAction) {
|
|
458
|
+
if (action.confirm) { this.pendingAction = { row, action }; return; }
|
|
459
|
+
await this.runAction(row.id, row.actions.filter(entry => entry.command).indexOf(action));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
private href(changes: Record<string, string | number>) {
|
|
463
|
+
const params = new URLSearchParams();
|
|
464
|
+
const next = { status: this.status, q: this.search, term: this.term, lang: this.locale, sort: this.sort, dir: this.dir, page: this.page, ...changes };
|
|
465
|
+
if (next.status && next.status !== 'all') params.set('status', String(next.status));
|
|
466
|
+
if (next.q) params.set('q', String(next.q));
|
|
467
|
+
if (next.term) params.set('term', String(next.term));
|
|
468
|
+
if (next.lang && next.lang !== this.defaultLocale) params.set('lang', String(next.lang));
|
|
469
|
+
if (next.sort) { params.set('sort', String(next.sort)); params.set('dir', String(next.dir)); }
|
|
470
|
+
if (Number(next.page) > 1) params.set('page', String(next.page));
|
|
471
|
+
const query = params.toString();
|
|
472
|
+
return `/dashboard/content/${this.route}${query ? `?${query}` : ''}`;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** A column heading that sorts the list: a click sorts ascending, another turns it around. */
|
|
476
|
+
private sortable(label: string, key: Sort): TemplateResult {
|
|
477
|
+
const active = this.sort === key;
|
|
478
|
+
const next = active && this.dir === 'asc' ? 'desc' : 'asc';
|
|
479
|
+
return html`<a href=${this.href({ sort: key, dir: next, page: 1 })} class=${`inline-flex items-center gap-1 no-underline hover:text-foreground ${active ? 'text-foreground' : ''}`}
|
|
480
|
+
aria-label=${`${__('Sort by')} ${label.toLowerCase()}`}>${label}
|
|
481
|
+
<span class="inline-flex [&_svg]:size-3.5" aria-hidden="true">${component(Icon, { entry: icon(active ? (this.dir === 'asc' ? 'alt-arrow-up' : 'alt-arrow-down') : 'sort-vertical'), size: 14 })}</span></a>`;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** The featured image as a small thumbnail; hovering or focusing it shows the picture large, with its alt text and caption. */
|
|
485
|
+
private thumbnail(row: Row): TemplateResult {
|
|
486
|
+
if (!row.image) return html`<span class="flex size-10 shrink-0 items-center justify-center rounded-md border border-dashed border-border text-muted-foreground [&_svg]:size-4" aria-hidden="true">${component(Icon, { entry: icon('gallery'), size: 16 })}</span>`;
|
|
487
|
+
const image = row.image;
|
|
488
|
+
return component(HoverCard, { id: `thumb-${row.id}`, label: row.title, side: 'right', contentProps: { class: 'w-[36rem] max-w-[calc(100vw-4rem)] p-2' },
|
|
489
|
+
content: html`<figure class="space-y-2">
|
|
490
|
+
<img src=${image.url} alt=${image.alt} class="max-h-[36rem] w-full rounded-md bg-muted object-contain" loading="lazy">
|
|
491
|
+
${image.alt || image.caption ? html`<figcaption class="space-y-1 px-1 pb-1 text-xs">
|
|
492
|
+
${image.caption ? html`<p class="text-foreground">${image.caption}</p>` : null}
|
|
493
|
+
${image.alt ? html`<p class="text-muted-foreground"><span class="font-medium">${__('Alt text')}:</span> ${image.alt}</p>` : null}
|
|
494
|
+
</figcaption>` : null}
|
|
495
|
+
</figure>` },
|
|
496
|
+
html`<a href=${`/dashboard/content/${this.route}/${row.id}`} class="block shrink-0" tabindex="0" aria-label=${`${__('Edit')} ${row.title}`}>
|
|
497
|
+
<img src=${image.url} alt="" class="size-10 rounded-md border border-border bg-muted object-cover" loading="lazy"></a>`);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** One author's picture, or the authors' as a group, with their names as the tooltip. */
|
|
501
|
+
private authorCell(row: Row): TemplateResult {
|
|
502
|
+
if (!row.authors.length) return html`<span class="text-muted-foreground">—</span>`;
|
|
503
|
+
const names = row.authors.map(author => author.name).join(', ');
|
|
504
|
+
const tip = `author-${row.id}-tip`;
|
|
505
|
+
const pictures = row.authors.length === 1
|
|
506
|
+
? component(Avatar, { src: row.authors[0]!.avatar ?? undefined, alt: names, size: 28 })
|
|
507
|
+
: component(AvatarGroup, { label: names, size: 28, max: 3, items: row.authors.map(author => ({ value: author.id, ...(author.avatar ? { src: author.avatar } : {}), alt: author.name })) });
|
|
508
|
+
return component(Tooltip, { id: tip, label: names }, html`<span tabindex="0" aria-describedby=${tip} aria-label=${names} class="inline-flex rounded-full">${pictures}</span>`);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** The bulk action select and its Apply button, above and below the table. */
|
|
512
|
+
private bulkBar(position: 'top' | 'bottom'): TemplateResult {
|
|
513
|
+
return bulkBar({ id: `bulk-${position}`, choices: this.bulkChoices(), value: this.bulk, count: this.selected.length, choose: key => { this.bulk = key as BulkKey; }, apply: () => this.submitBulk() });
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Runs a built-in quick action; Edit and View are links. */
|
|
517
|
+
@Client()
|
|
518
|
+
runBuiltin(row: Row, id: string) {
|
|
519
|
+
if (id === 'duplicate') void this.duplicate(row.id);
|
|
520
|
+
else if (id === 'trash') void this.moveTo(row.id, row.rev, 'trash');
|
|
521
|
+
else if (id === 'restore') void this.moveTo(row.id, row.rev, 'draft');
|
|
522
|
+
else if (id === 'delete' || id === 'delete-permanently') this.pendingDelete = row;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** The row's quick actions as words between bars; plugins change them through `cms.dashboard.entry-actions`. */
|
|
526
|
+
private quickActions(row: Row): TemplateResult {
|
|
527
|
+
const separator = html`<span aria-hidden="true" class="text-muted-foreground">|</span>`;
|
|
528
|
+
const items = row.actions.map(entry => {
|
|
529
|
+
const tone = entry.danger ? 'text-destructive' : 'text-primary';
|
|
530
|
+
if (entry.href) return html`<a href=${entry.href} data-action=${entry.id ?? ''} class=${`${tone} no-underline hover:underline`}>${entry.label}</a>`;
|
|
531
|
+
const builtin = !entry.command && (ENTRY_ACTION_IDS as readonly string[]).includes(entry.id ?? '');
|
|
532
|
+
if (!builtin && !entry.command) return null;
|
|
533
|
+
return html`<button type="button" data-action=${entry.id ?? ''} class=${`${tone} cursor-pointer border-none bg-transparent p-0 text-xs hover:underline`}
|
|
534
|
+
@click=${() => builtin ? this.runBuiltin(row, entry.id!) : this.pickAction(row, entry)}>${entry.label}</button>`;
|
|
535
|
+
}).filter(item => item !== null);
|
|
536
|
+
return html`<div class="mt-1 flex flex-wrap items-center gap-2 text-xs opacity-80 group-hover:opacity-100 focus-within:opacity-100" data-quick-actions>${items.flatMap((item, index) => index ? [separator, item] : [item])}</div>`;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/** The columns Screen options can hide; the title always shows. */
|
|
540
|
+
private optionalColumns(): { id: string; label: string }[] {
|
|
541
|
+
return [
|
|
542
|
+
...(this.hasSlug ? [{ id: 'slug', label: __('Slug') }] : []),
|
|
543
|
+
{ id: 'authors', label: __('Authors') },
|
|
544
|
+
...(this.languages.length ? [{ id: 'language', label: __('Languages') }] : []),
|
|
545
|
+
...(this.taxonomy ? [{ id: 'terms', label: this.taxonomy.label }] : []),
|
|
546
|
+
...this.columns.map(column => ({ id: `plugin:${column.id}`, label: column.label })),
|
|
547
|
+
{ id: 'date', label: __('Date') },
|
|
548
|
+
];
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Screen options: the columns to show and the entries a page lists, applied together. */
|
|
552
|
+
private screenPanel() {
|
|
553
|
+
return screenOptions(html`<form data-screen-options class="space-y-3" @submit=${(event: Event) => this.applyScreen(event)}>
|
|
554
|
+
<fieldset class="space-y-1.5">
|
|
555
|
+
<legend class="mb-1 font-medium text-foreground">${__('Columns')}</legend>
|
|
556
|
+
<div class="grid grid-cols-2 gap-x-4 gap-y-1.5">${this.optionalColumns().map(column => html`<label class="flex items-center gap-2 text-foreground">
|
|
557
|
+
<input type="checkbox" name="column" value=${column.id} ?checked=${!this.hidden.includes(column.id)} class="size-4 accent-primary">${column.label}</label>`)}</div>
|
|
558
|
+
</fieldset>
|
|
559
|
+
<label class="flex items-center justify-between gap-3 text-foreground">${__('Number of items per page')}
|
|
560
|
+
${component(Input, { type: 'number', name: 'perPage', min: 1, max: 100, step: 1, value: String(this.perPage), required: true, size: 'sm', class: 'w-20' })}</label>
|
|
561
|
+
<div class="flex justify-end">${component(Button, { type: 'submit', size: 'sm' }, __('Apply'))}</div>
|
|
562
|
+
</form>`);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** Keep the chosen Screen options in their cookie; a new page size lists the first page again. */
|
|
566
|
+
@Client()
|
|
567
|
+
async applyScreen(event: Event) {
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
// A submit event's target is the form, wherever the listener sits.
|
|
570
|
+
const form = new FormData(event.target as HTMLFormElement);
|
|
571
|
+
const checked = new Set(form.getAll('column').map(String));
|
|
572
|
+
// Columns this list does not offer now (another language setup, a plugin turned off) keep their choice.
|
|
573
|
+
const offered = this.optionalColumns().map(column => column.id);
|
|
574
|
+
const hidden = [...this.hidden.filter(id => !offered.includes(id)), ...offered.filter(id => !checked.has(id))];
|
|
575
|
+
const perPage = clampPerPage(form.get('perPage'), this.perPage);
|
|
576
|
+
saveScreenPreferences(`entries-${this.route}`, { hidden, perPage });
|
|
577
|
+
document.getElementById('screen-options')?.hidePopover?.();
|
|
578
|
+
this.hidden = hidden;
|
|
579
|
+
if (perPage === this.perPage) return;
|
|
580
|
+
this.perPage = perPage;
|
|
581
|
+
this.page = 1;
|
|
582
|
+
const url = new URL(window.location.href);
|
|
583
|
+
if (url.searchParams.has('page')) { url.searchParams.delete('page'); window.history.replaceState(window.history.state, '', url); }
|
|
584
|
+
await this.load();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
render() {
|
|
588
|
+
if (!this.label) return notice(this.error || __('This content type does not exist.'), 'error');
|
|
589
|
+
const base = `/dashboard/content/${this.route}`;
|
|
590
|
+
const totalPages = this.more ? this.page + 1 : Math.max(1, Math.ceil(this.total / this.perPage));
|
|
591
|
+
const shown = (id: string) => !this.hidden.includes(id);
|
|
592
|
+
const sortState = (key: Sort) => this.sort === key ? (this.dir === 'asc' ? 'ascending' as const : 'descending' as const) : 'none' as const;
|
|
593
|
+
return html`<div class="space-y-6">
|
|
594
|
+
${screenHelp(html`<p>${__('The tabs above the list filter by status; the search looks through titles and content, and the filters narrow by term and language.')}</p>
|
|
595
|
+
${this.languages.length ? html`<p>${__('The list shows one language at a time. In the Languages column, the filled code is the entry; the others open its translations, and a plus starts a missing one.')}</p>` : null}
|
|
596
|
+
<p>${__('Hover a row for its quick actions: edit, duplicate, view on the site, trash. Select rows to act on them together with the bulk actions.')}</p>
|
|
597
|
+
<p>${__('Export JSON downloads the entries shown; Import JSON creates or updates entries from such a file.')}</p>
|
|
598
|
+
<p>${__('Screen options, beside Help in the taskbar, choose the columns and how many entries a page lists.')}</p>`)}
|
|
599
|
+
${this.screenPanel()}
|
|
600
|
+
${pageHeader(this.label, {
|
|
601
|
+
titleActions: this.canCreate ? linkButton(`${__('New')} ${this.singular.toLowerCase()}`, `${base}/new`, 'primary', { size: 'sm' }) : null,
|
|
602
|
+
actions: html`${component(Tooltip, { id: 'export-json-tip', label: __('Export JSON') }, html`<a href=${`/api/cms/export/${this.route}`} download
|
|
603
|
+
aria-label=${__('Export JSON')} aria-describedby="export-json-tip"
|
|
604
|
+
class="inline-flex h-8 w-8 items-center justify-center rounded border border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground [&_svg]:size-4">
|
|
605
|
+
${component(Icon, { entry: icon('download-minimalistic'), size: 16 })}</a>`)}
|
|
606
|
+
${this.canCreate ? html`${iconButton('import-json', 'upload-minimalistic', this.importing ? __('Importing…') : __('Import JSON'), () => this.importFile.value?.click(), { size: 'md', disabled: this.importing })}
|
|
607
|
+
<input ref=${this.importFile} type="file" accept="application/json,.json" hidden ?disabled=${this.importing} @change=${(event: Event) => this.pickImport(event)}>
|
|
608
|
+
<span class="sr-only" role="status">${this.importing ? __('Importing…') : ''}</span>` : null}`,
|
|
609
|
+
})}
|
|
610
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
611
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
612
|
+
${this.imported?.failed.length ? html`<div role="alert" class="rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive">
|
|
613
|
+
<p class="font-medium">${this.imported.failed.length} ${this.imported.failed.length === 1 ? __('entry was not imported.') : __('entries were not imported.')}</p>
|
|
614
|
+
<ul class="mt-1 space-y-0.5 text-xs">${this.imported.failed.slice(0, 50).map(row => html`<li>#${row.index + 1}${row.id ? html` <code>${row.id}</code>` : null}: ${row.error}${row.fields ? ` ${Object.entries(row.fields).map(([name, message]) => `${name} ${message}`).join('; ')}` : ''}</li>`)}</ul>
|
|
615
|
+
</div>` : null}
|
|
616
|
+
<div class="space-y-3">
|
|
617
|
+
<nav aria-label=${__('Filter by status')} class="flex flex-wrap gap-x-3 gap-y-1 text-sm">
|
|
618
|
+
${this.counts.map((tab, index) => html`${index ? html`<span class="text-muted-foreground" aria-hidden="true">|</span>` : null}
|
|
619
|
+
<a href=${this.href({ status: tab.key, page: 1 })} class=${tab.key === this.status ? 'font-semibold text-foreground no-underline' : 'text-primary no-underline hover:underline'}
|
|
620
|
+
aria-current=${tab.key === this.status ? 'page' : 'false'}>${tab.label} <span class="text-muted-foreground">(${tab.count})</span></a>`)}
|
|
621
|
+
</nav>
|
|
622
|
+
${listFilters({ action: base, hidden: { status: this.status !== 'all' ? this.status : '', sort: this.sort ?? '', dir: this.sort ? this.dir : '' },
|
|
623
|
+
search: { name: 'q', value: this.search, placeholder: `${__('Search')} ${this.label.toLowerCase()}` },
|
|
624
|
+
filters: html`${this.languages.length ? html`<div class="w-44">${component(NativeSelect, { name: 'lang', size: 'sm', 'aria-label': __('Filter by language') }, html`
|
|
625
|
+
<option value="all" ?selected=${this.locale === 'all'}>${__('All languages')}</option>
|
|
626
|
+
${this.languages.map(language => html`<option value=${language.code} ?selected=${language.code === this.locale}>${language.label}</option>`)}`)}</div>` : null}
|
|
627
|
+
${this.taxonomy ? html`<div class="w-48">${component(NativeSelect, { name: 'term', size: 'sm', 'aria-label': `${__('Filter by')} ${this.taxonomy.label}` }, html`
|
|
628
|
+
<option value="" ?selected=${!this.term}>${__('All')} ${this.taxonomy.label.toLowerCase()}</option>
|
|
629
|
+
${this.taxonomy.terms.map(term => html`<option value=${term.id} ?selected=${term.id === this.term}>${'— '.repeat(term.depth)}${term.name}</option>`)}`)}</div>` : null}` })}
|
|
630
|
+
${this.bulkBar('top')}
|
|
631
|
+
</div>
|
|
632
|
+
${listTable<Row>({
|
|
633
|
+
rows: this.rows, key: row => row.id, rowAttribute: 'data-entry',
|
|
634
|
+
selection: { selected: this.selected, label: row => row.title, change: ids => this.select(ids) },
|
|
635
|
+
columns: [
|
|
636
|
+
{ label: this.sortable(__('Title'), 'title'), sort: sortState('title'), cell: row => html`<div class="flex items-start gap-3">
|
|
637
|
+
${this.hasImage ? this.thumbnail(row) : null}
|
|
638
|
+
<div class="min-w-0">
|
|
639
|
+
<a href=${`${base}/${row.id}`} class="font-medium text-foreground hover:text-primary no-underline">${row.title}</a>
|
|
640
|
+
${row.status && row.status !== 'published' && ['all', 'mine'].includes(this.status) ? html` <span class="text-muted-foreground">— ${statusBadge(row.status)}</span>` : null}
|
|
641
|
+
${row.editing.length ? html` <span class="ml-1 inline-flex align-middle">${avatarStack(row.editing, { size: 16, max: 3, label: __('Editing now') })}</span>` : null}
|
|
642
|
+
${row.notes ? html` <a href=${`${base}/${row.id}?notes=open`} class="ml-1 inline-flex items-center gap-1 rounded-full border border-amber-500/60 bg-amber-500/10 px-1.5 py-0.5 align-middle text-[10px] font-medium leading-none text-amber-700 no-underline hover:bg-amber-500/20 dark:text-amber-300"
|
|
643
|
+
data-notes=${row.notes} title=${`${row.notes} ${row.notes === 1 ? __('open note') : __('open notes')}`} aria-label=${`${row.notes} ${row.notes === 1 ? __('open note on') : __('open notes on')} ${row.title}`}>${component(Icon, { entry: icon('notes'), size: 12 })}${row.notes}</a>` : null}
|
|
644
|
+
${this.quickActions(row)}
|
|
645
|
+
</div>
|
|
646
|
+
</div>` },
|
|
647
|
+
this.hasSlug && shown('slug') && { label: __('Slug'), cell: row => html`<code class="break-all text-xs text-muted-foreground">${row.slug}</code>` },
|
|
648
|
+
shown('authors') && { label: __('Authors'), class: 'w-20', cell: row => this.authorCell(row) },
|
|
649
|
+
this.languages.length > 0 && shown('language') && { label: __('Languages'), cell: row => this.languagesCell(row) },
|
|
650
|
+
this.taxonomy && shown('terms') && { label: this.taxonomy.label, class: 'text-muted-foreground', cell: row => row.terms.join(', ') || '—' },
|
|
651
|
+
...this.columns.filter(column => shown(`plugin:${column.id}`)).map(column => ({ label: column.label, class: 'text-muted-foreground', cell: (row: Row) => column.values[row.id] ?? '—' })),
|
|
652
|
+
shown('date') && { label: this.sortable(__('Date'), 'date'), sort: sortState('date'), class: 'text-muted-foreground', cell: row => html`<span class="block">${row.dateLabel}</span><span class="block text-xs">${row.date}</span>` },
|
|
653
|
+
],
|
|
654
|
+
})}
|
|
655
|
+
${this.rows.length ? this.bulkBar('bottom') : null}
|
|
656
|
+
${listFooter({ total: this.total, page: this.page, totalPages, more: this.more, href: page => this.href({ page }) })}
|
|
657
|
+
${component(AlertDialog, {
|
|
658
|
+
id: 'delete-entry-dialog',
|
|
659
|
+
open: this.pendingDelete !== null,
|
|
660
|
+
title: __('Delete permanently?'),
|
|
661
|
+
description: this.pendingDelete ? `“${this.pendingDelete.title}” ${__('and its revisions will be deleted. This cannot be undone.')}` : '',
|
|
662
|
+
cancelLabel: __('Cancel'),
|
|
663
|
+
actionLabel: __('Delete'),
|
|
664
|
+
actionVariant: 'destructive',
|
|
665
|
+
onAction: () => this.confirmDelete(),
|
|
666
|
+
onOpenChange: () => { this.pendingDelete = null; },
|
|
667
|
+
})}
|
|
668
|
+
${component(AlertDialog, {
|
|
669
|
+
id: 'bulk-action-dialog',
|
|
670
|
+
open: this.pendingBulk !== null,
|
|
671
|
+
// Closed dialogs still need their labels.
|
|
672
|
+
title: this.pendingBulk ? `${this.pendingBulk.label} ${this.selected.length} ${this.selected.length === 1 ? this.singular.toLowerCase() : this.label.toLowerCase()}?` : __('Apply'),
|
|
673
|
+
description: this.pendingBulk?.text ?? '',
|
|
674
|
+
cancelLabel: __('Cancel'),
|
|
675
|
+
actionLabel: this.pendingBulk?.label || __('Apply'),
|
|
676
|
+
actionVariant: this.pendingBulk?.key === 'delete' ? 'destructive' : 'primary',
|
|
677
|
+
onAction: () => { if (this.pendingBulk) void this.runBulk(this.pendingBulk.key); },
|
|
678
|
+
onOpenChange: () => { this.pendingBulk = null; },
|
|
679
|
+
})}
|
|
680
|
+
${component(AlertDialog, {
|
|
681
|
+
id: 'entry-action-dialog',
|
|
682
|
+
open: this.pendingAction !== null,
|
|
683
|
+
title: this.pendingAction ? `${this.pendingAction.action.label} “${this.pendingAction.row.title}”?` : __('Confirm'),
|
|
684
|
+
description: this.pendingAction?.action.confirm ?? '',
|
|
685
|
+
cancelLabel: __('Cancel'),
|
|
686
|
+
actionLabel: this.pendingAction?.action.label || __('Confirm'),
|
|
687
|
+
actionVariant: this.pendingAction?.action.danger ? 'destructive' : 'primary',
|
|
688
|
+
onAction: () => { const pending = this.pendingAction; this.pendingAction = null; if (pending) void this.runAction(pending.row.id, pending.row.actions.indexOf(pending.action)); },
|
|
689
|
+
onOpenChange: () => { this.pendingAction = null; },
|
|
690
|
+
})}
|
|
691
|
+
</div>`;
|
|
692
|
+
}
|
|
693
|
+
}
|