@cossackframework/cms 0.0.0-stage → 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 +147 -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 +123 -3
- 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,85 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { Button, Card, CardBody, Checkbox, Field, Input } from '@cossackframework/ui';
|
|
3
|
+
import { html, component } from '@cossackframework/renderer';
|
|
4
|
+
import { isCmsError, PERMISSIONS } from '@cossackframework/cms';
|
|
5
|
+
import { requireAny } from '#app/cms/guards';
|
|
6
|
+
import { notice, pageHeader } from '#app/cms/ui';
|
|
7
|
+
|
|
8
|
+
/** Rename a taxonomy, change its URL, or delete it with its terms. */
|
|
9
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageCollections)] })
|
|
10
|
+
export default class EditTaxonomy extends Cossack {
|
|
11
|
+
@State() draft = { name: '', label: '', singular: '', description: '', path: '', hierarchical: false, noindex: false, builtin: false };
|
|
12
|
+
@State() error = '';
|
|
13
|
+
/** What the last save did. */
|
|
14
|
+
@State() message = '';
|
|
15
|
+
|
|
16
|
+
head(): HeadValue {
|
|
17
|
+
return { title: this.draft.label || __('Taxonomy') };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async init() {
|
|
21
|
+
try {
|
|
22
|
+
const taxonomy = this.c.get('cms').taxonomies.declaration(this.c.req.param('name') ?? '');
|
|
23
|
+
this.draft = { name: taxonomy.name, label: taxonomy.label, singular: taxonomy.singular, description: taxonomy.description ?? '', path: taxonomy.path ?? '', hierarchical: taxonomy.hierarchical, noindex: taxonomy.noindex === true, builtin: taxonomy.builtin === true };
|
|
24
|
+
} catch { this.error = __('This taxonomy does not exist.'); this.c.status(404); }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Client()
|
|
28
|
+
setDraft<K extends keyof EditTaxonomy['draft']>(key: K, value: EditTaxonomy['draft'][K]) {
|
|
29
|
+
this.draft = { ...this.draft, [key]: value };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Client()
|
|
33
|
+
async submit(event: Event) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
this.message = '';
|
|
36
|
+
await this.save(this.draft);
|
|
37
|
+
if (!this.error) this.message = __('Taxonomy saved.');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Server()
|
|
41
|
+
async save(draft: EditTaxonomy['draft']) {
|
|
42
|
+
this.error = '';
|
|
43
|
+
try {
|
|
44
|
+
const cms = this.c.get('cms');
|
|
45
|
+
await cms.saveTaxonomy({ name: draft.name, label: draft.label, singular: draft.singular, hierarchical: draft.hierarchical,
|
|
46
|
+
path: draft.path.trim() || null, noindex: draft.noindex, ...(draft.description.trim() ? { description: draft.description.trim() } : {}) }, this.c.get('principal'));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
this.error = isCmsError(error) ? error.message : __('The taxonomy could not be saved.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Server()
|
|
53
|
+
async remove() {
|
|
54
|
+
this.message = '';
|
|
55
|
+
try {
|
|
56
|
+
await this.c.get('cms').deleteTaxonomy(this.draft.name, this.c.get('principal'));
|
|
57
|
+
return this.redirect('/dashboard/taxonomies');
|
|
58
|
+
} catch (error) {
|
|
59
|
+
this.error = isCmsError(error) ? error.message : __('The taxonomy could not be deleted.');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
if (!this.draft.name) return notice(this.error || __('This taxonomy does not exist.'), 'error');
|
|
65
|
+
const input = (key: 'label' | 'singular' | 'description' | 'path', label: string, hint?: string) => component(Field, { label, for: `taxonomy-${key}`, ...(hint ? { hint } : {}),
|
|
66
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft[key], '@input': (event: Event) => this.setDraft(key, (event.target as HTMLInputElement).value) }) });
|
|
67
|
+
return html`<div class="max-w-2xl space-y-6">
|
|
68
|
+
${pageHeader(this.draft.label, { description: `${__('Taxonomy')} ${this.draft.name}`, actions: html`<a href="/dashboard/taxonomies" class="text-sm text-muted-foreground hover:text-foreground">← ${__('Taxonomies')}</a>` })}
|
|
69
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
70
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
71
|
+
${component(Card, {}, component(CardBody, {}, html`<form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
|
|
72
|
+
${input('label', __('Plural name'))}
|
|
73
|
+
${input('singular', __('Singular name'))}
|
|
74
|
+
${input('description', __('Description'))}
|
|
75
|
+
${input('path', __('URL path'), __('Archives at /<path>/<term>. Empty keeps them off the site.'))}
|
|
76
|
+
${component(Checkbox, { label: __('Terms can be nested'), checked: this.draft.hierarchical, disabled: this.draft.builtin, '@change': (event: Event) => this.setDraft('hierarchical', (event.target as HTMLInputElement).checked) })}
|
|
77
|
+
${this.draft.path.trim() ? component(Checkbox, { label: __('Hide term archives from search engines'), checked: this.draft.noindex, '@change': (event: Event) => this.setDraft('noindex', (event.target as HTMLInputElement).checked) }) : null}
|
|
78
|
+
<div class="flex items-center justify-between">
|
|
79
|
+
${this.draft.builtin ? html`<span></span>` : html`<button type="button" class="text-sm text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.remove()}>${__('Delete taxonomy and its terms')}</button>`}
|
|
80
|
+
${component(Button, { type: 'submit' }, __('Save'))}
|
|
81
|
+
</div>
|
|
82
|
+
</form>`))}
|
|
83
|
+
</div>`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { Badge, Button, Card, CardBody, Checkbox, Field, Input, CardHeader } from '@cossackframework/ui';
|
|
3
|
+
import { html, component } from '@cossackframework/renderer';
|
|
4
|
+
import { isCmsError, PERMISSIONS } from '@cossackframework/cms';
|
|
5
|
+
import { fieldName } from '#app/cms/builder';
|
|
6
|
+
import { requireAny } from '#app/cms/guards';
|
|
7
|
+
import { notice, pageHeader } from '#app/cms/ui';
|
|
8
|
+
|
|
9
|
+
interface Row { name: string; label: string; hierarchical: boolean; builtin: boolean; path: string | null; collections: string[]; terms: number }
|
|
10
|
+
|
|
11
|
+
/** Taxonomies: vocabularies such as categories and tags that collections use to group entries. */
|
|
12
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageCollections)] })
|
|
13
|
+
export default class TaxonomiesPage extends Cossack {
|
|
14
|
+
@State() rows: Row[] = [];
|
|
15
|
+
@State() draft = { label: '', singular: '', hierarchical: false, path: '' };
|
|
16
|
+
@State() error = '';
|
|
17
|
+
|
|
18
|
+
head(): HeadValue {
|
|
19
|
+
return { title: 'Taxonomies' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async init() {
|
|
23
|
+
await this.load();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Server()
|
|
27
|
+
async load() {
|
|
28
|
+
const cms = this.c.get('cms');
|
|
29
|
+
const collections = cms.collections();
|
|
30
|
+
this.rows = await Promise.all(cms.taxonomies.declarations.map(async taxonomy => ({
|
|
31
|
+
name: taxonomy.name, label: taxonomy.label, hierarchical: taxonomy.hierarchical, builtin: taxonomy.builtin === true, path: taxonomy.path ?? null,
|
|
32
|
+
collections: collections.filter(collection => collection.taxonomies?.includes(taxonomy.name)).map(collection => collection.label),
|
|
33
|
+
terms: (await cms.taxonomies.list(taxonomy.name, { limit: 1 })).total,
|
|
34
|
+
})));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Client()
|
|
38
|
+
setDraft<K extends keyof TaxonomiesPage['draft']>(key: K, value: TaxonomiesPage['draft'][K]) {
|
|
39
|
+
this.draft = { ...this.draft, [key]: value };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Client()
|
|
43
|
+
async submit(event: Event) {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
await this.create(this.draft);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Server()
|
|
49
|
+
async create(draft: TaxonomiesPage['draft']) {
|
|
50
|
+
this.error = '';
|
|
51
|
+
try {
|
|
52
|
+
const name = fieldName(draft.label);
|
|
53
|
+
const cms = this.c.get('cms');
|
|
54
|
+
await cms.saveTaxonomy({ name, label: draft.label.trim(), singular: draft.singular.trim() || draft.label.trim(), hierarchical: draft.hierarchical,
|
|
55
|
+
path: draft.path.trim() || null }, this.c.get('principal'));
|
|
56
|
+
this.draft = { label: '', singular: '', hierarchical: false, path: '' };
|
|
57
|
+
await this.load();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
this.error = isCmsError(error) ? error.message : __('The taxonomy could not be created.');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
return html`<div class="space-y-6">
|
|
65
|
+
${pageHeader(__('Taxonomies'), { description: __('Group entries by terms. Choose which collections use a taxonomy on the collection.') })}
|
|
66
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
67
|
+
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_20rem]">
|
|
68
|
+
${component(Card, {}, component(CardBody, { class: 'p-0' }, html`<div class="overflow-x-auto"><table class="w-full text-sm">
|
|
69
|
+
<thead><tr class="border-b border-border text-left text-xs uppercase tracking-wide text-muted-foreground">
|
|
70
|
+
<th class="px-3 py-2 font-medium">${__('Taxonomy')}</th><th class="px-3 py-2 font-medium">${__('Used by')}</th>
|
|
71
|
+
<th class="px-3 py-2 font-medium">${__('URL')}</th><th class="px-3 py-2 text-right font-medium">${__('Terms')}</th>
|
|
72
|
+
</tr></thead>
|
|
73
|
+
<tbody>${this.rows.map(row => html`<tr class="border-b border-border last:border-0">
|
|
74
|
+
<td class="px-3 py-2">
|
|
75
|
+
<a href=${`/dashboard/taxonomies/${row.name}`} class="font-medium text-foreground hover:text-primary no-underline">${row.label}</a>
|
|
76
|
+
<span class="ml-2 inline-flex gap-1">${row.hierarchical ? component(Badge, { variant: 'outline' }, __('Nested')) : null}${row.builtin ? component(Badge, { variant: 'secondary' }, __('Built in')) : null}</span>
|
|
77
|
+
<div class="mt-1 text-xs"><a href=${`/dashboard/terms/${row.name}`} class="text-primary hover:underline">${__('Manage terms')}</a></div>
|
|
78
|
+
</td>
|
|
79
|
+
<td class="px-3 py-2 text-muted-foreground">${row.collections.join(', ') || '—'}</td>
|
|
80
|
+
<td class="px-3 py-2 font-mono text-xs text-muted-foreground">${row.path ? `/${row.path}/…` : '—'}</td>
|
|
81
|
+
<td class="px-3 py-2 text-right text-muted-foreground">${row.terms}</td>
|
|
82
|
+
</tr>`)}</tbody>
|
|
83
|
+
</table></div>`))}
|
|
84
|
+
${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Add taxonomy')}</h2>`)}
|
|
85
|
+
${component(CardBody, {}, html`<form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
|
|
86
|
+
${component(Field, { label: __('Plural name'), for: 'taxonomy-label', hint: this.draft.label ? `${__('Stored as')} ${fieldName(this.draft.label)}` : __('Such as Brands or Genres.'),
|
|
87
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.label, '@input': (event: Event) => this.setDraft('label', (event.target as HTMLInputElement).value) }) })}
|
|
88
|
+
${component(Field, { label: __('Singular name'), for: 'taxonomy-singular',
|
|
89
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.singular, '@input': (event: Event) => this.setDraft('singular', (event.target as HTMLInputElement).value) }) })}
|
|
90
|
+
${component(Field, { label: __('URL path'), for: 'taxonomy-path', hint: __('Archives at /<path>/<term>. Empty keeps them off the site.'),
|
|
91
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.path, '@input': (event: Event) => this.setDraft('path', (event.target as HTMLInputElement).value) }) })}
|
|
92
|
+
${component(Checkbox, { label: __('Terms can be nested, like categories'), checked: this.draft.hierarchical, '@change': (event: Event) => this.setDraft('hierarchical', (event.target as HTMLInputElement).checked) })}
|
|
93
|
+
${component(Button, { type: 'submit', disabled: !this.draft.label.trim() }, __('Add taxonomy'))}
|
|
94
|
+
</form>`)}`)}
|
|
95
|
+
</div>
|
|
96
|
+
</div>`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Button, Card, CardBody, Field, Input, NativeSelect, Textarea } from '@cossackframework/ui';
|
|
4
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
5
|
+
import { fieldVisibility, hasPermission, isCmsError, mediaUrl, PERMISSIONS, slugify } from '@cossackframework/cms';
|
|
6
|
+
import { findMedia, groupsView, metaInput, metaValues, type GroupsView } from '#app/cms/content';
|
|
7
|
+
import { fieldControl, type MediaHooks, type MediaPreview } from '#app/cms/field-controls';
|
|
8
|
+
import { FieldGroupView, plainBlocks, visibilityTypes, type RowPath } from '#app/cms/field-group-view';
|
|
9
|
+
import { requireAny } from '#app/cms/guards';
|
|
10
|
+
import { closedChooser, mediaChooser, uploadMedia, withFile, type MediaChooserState } from '#app/cms/media-chooser';
|
|
11
|
+
import { iconSelect } from '#app/cms/term-icons';
|
|
12
|
+
import { box, notice, pageHeader } from '#app/cms/ui';
|
|
13
|
+
import type { EditorField, EditorValues } from '#app/cms/editor';
|
|
14
|
+
|
|
15
|
+
interface Draft { name: string; slug: string; parent: string; description: string; icon: string }
|
|
16
|
+
/** Where a chosen file goes: a meta field, through the rows it sits in. */
|
|
17
|
+
interface MetaTarget { field: string; rows: RowPath; key: string; multiple: boolean }
|
|
18
|
+
|
|
19
|
+
/** Edit one term. Moving it moves the terms below it too. Field groups attached to the taxonomy show as boxes. */
|
|
20
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageTerms)] })
|
|
21
|
+
export default class EditTerm extends Cossack {
|
|
22
|
+
@State() taxonomy = { name: '', label: '', singular: '', hierarchical: false };
|
|
23
|
+
@State() draft: Draft = { name: '', slug: '', parent: '', description: '', icon: '' };
|
|
24
|
+
@State() parents: { id: string; name: string; depth: number }[] = [];
|
|
25
|
+
@State() errors: Record<string, string> = {};
|
|
26
|
+
@State() error = '';
|
|
27
|
+
/** What the last save did. */
|
|
28
|
+
@State() message = '';
|
|
29
|
+
@State() found = false;
|
|
30
|
+
/** The field groups attached to the taxonomy, and the term's values for them as control values. */
|
|
31
|
+
@State() fieldGroups: GroupsView = { groups: [], fields: [], options: [] };
|
|
32
|
+
@State() meta: EditorValues = {};
|
|
33
|
+
@State() previews: Record<string, MediaPreview> = {};
|
|
34
|
+
@State() chooser: MediaChooserState = closedChooser();
|
|
35
|
+
private target: MetaTarget | null = null;
|
|
36
|
+
|
|
37
|
+
head(): HeadValue {
|
|
38
|
+
return { title: `${__('Edit')} ${this.taxonomy.singular.toLowerCase() || __('term')}` };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async init() {
|
|
42
|
+
const cms = this.c.get('cms');
|
|
43
|
+
const term = await cms.taxonomies.get(this.c.req.param('id') ?? '');
|
|
44
|
+
if (!term || term.taxonomy !== this.c.req.param('taxonomy')) { this.error = __('This term does not exist.'); this.c.status(404); return; }
|
|
45
|
+
const declaration = cms.taxonomies.declaration(term.taxonomy);
|
|
46
|
+
this.taxonomy = { name: declaration.name, label: declaration.label, singular: declaration.singular, hierarchical: declaration.hierarchical };
|
|
47
|
+
this.draft = { name: term.name, slug: term.slug, parent: term.parent ?? '', description: term.description, icon: term.icon };
|
|
48
|
+
if (declaration.hierarchical) {
|
|
49
|
+
// A term cannot move below itself.
|
|
50
|
+
this.parents = (await cms.taxonomies.tree(term.taxonomy)).filter(entry => !entry.path.startsWith(term.path)).map(entry => ({ id: entry.id, name: entry.name, depth: entry.depth }));
|
|
51
|
+
}
|
|
52
|
+
this.fieldGroups = await groupsView(cms, { kind: 'taxonomy', name: term.taxonomy });
|
|
53
|
+
this.meta = metaValues(this.fieldGroups.fields, term.meta);
|
|
54
|
+
this.previews = await this.metaPreviews(term.meta);
|
|
55
|
+
this.found = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Previews of the files the meta names, at any depth. */
|
|
59
|
+
private async metaPreviews(meta: { readonly [field: string]: unknown }): Promise<Record<string, MediaPreview>> {
|
|
60
|
+
const cms = this.c.get('cms');
|
|
61
|
+
const ids: string[] = [];
|
|
62
|
+
const walk = (value: unknown) => {
|
|
63
|
+
if (typeof value === 'string' && /^[A-Za-z0-9_-]{1,80}$/.test(value)) ids.push(value);
|
|
64
|
+
else if (Array.isArray(value)) value.forEach(walk);
|
|
65
|
+
else if (value && typeof value === 'object') Object.values(value).forEach(walk);
|
|
66
|
+
};
|
|
67
|
+
walk(meta);
|
|
68
|
+
if (!cms.files || !ids.length) return {};
|
|
69
|
+
const files = await cms.files.getMany([...new Set(ids)].slice(0, 200));
|
|
70
|
+
return Object.fromEntries([...files.values()].map(file => [file.id, { id: file.id, url: mediaUrl(file), title: file.title, alt: file.alt, contentType: file.contentType, width: file.width, height: file.height }]));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Client()
|
|
74
|
+
setDraft(name: keyof Draft, value: string) {
|
|
75
|
+
// A slug that still matches the name keeps following it.
|
|
76
|
+
const follows = name === 'name' && this.draft.slug === slugify(this.draft.name);
|
|
77
|
+
this.draft = { ...this.draft, [name]: value, ...(follows ? { slug: slugify(value) } : {}) };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Client()
|
|
81
|
+
setMeta(name: string, value: unknown) {
|
|
82
|
+
this.meta = { ...this.meta, [name]: value };
|
|
83
|
+
if (this.errors[name]) this.errors = Object.fromEntries(Object.entries(this.errors).filter(([key]) => key !== name));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Set a row's field through the rows above it. */
|
|
87
|
+
@Client()
|
|
88
|
+
setRowValue(field: string, rows: RowPath, key: string, value: unknown) {
|
|
89
|
+
const update = (list: unknown, depth: number): unknown => {
|
|
90
|
+
const entries = Array.isArray(list) ? list as Record<string, unknown>[] : [];
|
|
91
|
+
const row = rows[depth]!;
|
|
92
|
+
return entries.map(entry => entry._id !== row.id ? entry : depth === rows.length - 1 ? { ...entry, [key]: value } : { ...entry, [rows[depth + 1]!.field]: update(entry[rows[depth + 1]!.field], depth + 1) });
|
|
93
|
+
};
|
|
94
|
+
this.setMeta(field, update(this.meta[field], 0));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private rowValue(field: string, rows: RowPath, key: string): unknown {
|
|
98
|
+
let current: unknown = this.meta[field];
|
|
99
|
+
for (const [index, row] of rows.entries()) {
|
|
100
|
+
const found = (Array.isArray(current) ? current as Record<string, unknown>[] : []).find(entry => entry._id === row.id);
|
|
101
|
+
if (!found) return undefined;
|
|
102
|
+
current = index === rows.length - 1 ? found[key] : found[rows[index + 1]!.field];
|
|
103
|
+
}
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- Media --------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
@Server({ input: input.args(input.string({ maxLength: 2000 })) })
|
|
110
|
+
async searchMedia(search: string) {
|
|
111
|
+
if (!hasPermission(this.c.get('principal'), PERMISSIONS.manageTerms)) return;
|
|
112
|
+
this.chooser = { ...this.chooser, search, items: await findMedia(this.c.get('cms'), search, this.chooser.kind) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Client()
|
|
116
|
+
async filterMedia(kind: string) {
|
|
117
|
+
this.chooser = { ...this.chooser, kind };
|
|
118
|
+
await this.searchMedia(this.chooser.search);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Client()
|
|
122
|
+
async openChooser(target: MetaTarget) {
|
|
123
|
+
this.target = target;
|
|
124
|
+
this.chooser = { ...this.chooser, open: true, error: '', field: target.key, multiple: target.multiple, kind: 'image' };
|
|
125
|
+
await this.searchMedia(this.chooser.search);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Client()
|
|
129
|
+
chooseFile(file: MediaPreview) {
|
|
130
|
+
const target = this.target;
|
|
131
|
+
if (!target) return;
|
|
132
|
+
this.previews = { ...this.previews, [file.id]: file };
|
|
133
|
+
const current = target.rows.length ? this.rowValue(target.field, target.rows, target.key) : this.meta[target.field];
|
|
134
|
+
const next = withFile(current, file.id, target.multiple);
|
|
135
|
+
if (target.rows.length) this.setRowValue(target.field, target.rows, target.key, next); else this.setMeta(target.field, next);
|
|
136
|
+
if (!target.multiple) this.chooser = { ...this.chooser, open: false };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Client()
|
|
140
|
+
async uploadFile(event: Event) {
|
|
141
|
+
const { files, error } = await uploadMedia(event.currentTarget as HTMLInputElement);
|
|
142
|
+
this.chooser = { ...this.chooser, error };
|
|
143
|
+
for (const file of files) this.chooseFile(file);
|
|
144
|
+
await this.searchMedia('');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// --- Saving -------------------------------------------------------------------
|
|
148
|
+
|
|
149
|
+
@Client()
|
|
150
|
+
async submit(event: Event) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
this.message = '';
|
|
153
|
+
await this.save(this.draft, this.meta);
|
|
154
|
+
if (!this.error) this.message = `${this.taxonomy.singular} ${__('updated.')}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Server()
|
|
158
|
+
async save(draft: Draft, meta: EditorValues) {
|
|
159
|
+
this.errors = {};
|
|
160
|
+
this.error = '';
|
|
161
|
+
// The term, its taxonomy and its fields as the host has them, not as the client's state says.
|
|
162
|
+
const cms = this.c.get('cms');
|
|
163
|
+
const current = await cms.taxonomies.get(this.c.req.param('id') ?? '');
|
|
164
|
+
if (!current || current.taxonomy !== this.c.req.param('taxonomy')) { this.error = __('This term does not exist.'); return; }
|
|
165
|
+
const declaration = cms.taxonomies.declaration(current.taxonomy);
|
|
166
|
+
this.taxonomy = { name: declaration.name, label: declaration.label, singular: declaration.singular, hierarchical: declaration.hierarchical };
|
|
167
|
+
this.fieldGroups = await groupsView(cms, { kind: 'taxonomy', name: current.taxonomy });
|
|
168
|
+
const converted = metaInput(this.fieldGroups.fields, meta);
|
|
169
|
+
if (Object.keys(converted.errors).length) { this.errors = converted.errors; this.error = __('Some fields are invalid.'); return; }
|
|
170
|
+
try {
|
|
171
|
+
const term = await this.c.get('cms').taxonomies.update(this.c.req.param('id') ?? '', {
|
|
172
|
+
name: draft.name, slug: draft.slug, description: draft.description, icon: draft.icon, meta: converted.meta, ...(this.taxonomy.hierarchical ? { parent: draft.parent || null } : {}),
|
|
173
|
+
}, { principal: this.c.get('principal') });
|
|
174
|
+
this.draft = { name: term.name, slug: term.slug, parent: term.parent ?? '', description: term.description, icon: term.icon };
|
|
175
|
+
this.meta = metaValues(this.fieldGroups.fields, term.meta);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
this.errors = isCmsError(error) && error.fields ? { ...error.fields } : {};
|
|
178
|
+
this.error = isCmsError(error) ? error.message : __('The term could not be saved.');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Server()
|
|
183
|
+
async remove() {
|
|
184
|
+
this.error = '';
|
|
185
|
+
this.message = '';
|
|
186
|
+
try {
|
|
187
|
+
await this.c.get('cms').taxonomies.delete(this.c.req.param('id') ?? '', { principal: this.c.get('principal') });
|
|
188
|
+
return this.redirect(`/dashboard/terms/${encodeURIComponent(this.c.req.param('taxonomy') ?? '')}`);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
this.error = isCmsError(error) ? error.message : __('The term could not be deleted.');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// --- Rendering ----------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
private metaControl(field: EditorField, value: unknown, change: (value: unknown) => void, rows: RowPath, id: string): TemplateResult | null {
|
|
197
|
+
const root = rows[0]?.field ?? field.name;
|
|
198
|
+
const media: MediaHooks = { previews: this.previews, choose: multiple => this.openChooser({ field: root, rows, key: field.name, multiple }) };
|
|
199
|
+
return fieldControl(field, value, change, id, { media });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private groupBoxes(): TemplateResult | null {
|
|
203
|
+
const { groups, fields, options } = this.fieldGroups;
|
|
204
|
+
if (!groups.length) return null;
|
|
205
|
+
const hidden = fieldVisibility(plainBlocks(groups.flatMap(group => group.blocks)), visibilityTypes(options), this.meta).hidden;
|
|
206
|
+
return html`${groups.map(group => box(group.title, html`
|
|
207
|
+
${group.description ? html`<p class="text-xs text-muted-foreground">${group.description}</p>` : null}
|
|
208
|
+
${component(FieldGroupView, {
|
|
209
|
+
id: `group-${group.id}`, blocks: group.blocks, options, fields, values: this.meta, hidden, errors: this.errors,
|
|
210
|
+
onChange: (name: string, value: unknown) => this.setMeta(name, value),
|
|
211
|
+
control: (field: EditorField, value: unknown, change: (value: unknown) => void, rows: RowPath, id: string) => this.metaControl(field, value, change, rows, id),
|
|
212
|
+
})}`, { id: `group-${group.id}-title` }))}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
render() {
|
|
216
|
+
if (!this.found) return notice(this.error || __('This term does not exist.'), 'error');
|
|
217
|
+
return html`<div class="max-w-2xl space-y-6">
|
|
218
|
+
${pageHeader(`${__('Edit')} ${this.taxonomy.singular.toLowerCase()}`, { actions: html`<a href=${`/dashboard/terms/${this.taxonomy.name}`} class="text-sm text-muted-foreground hover:text-foreground">← ${this.taxonomy.label}</a>` })}
|
|
219
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
220
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
221
|
+
<form class="space-y-6" @submit=${(event: Event) => this.submit(event)}>
|
|
222
|
+
${component(Card, {}, component(CardBody, {}, html`<div class="space-y-4">
|
|
223
|
+
${component(Field, { label: __('Name'), for: 'term-name', error: this.errors.name,
|
|
224
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.name, '@input': (event: Event) => this.setDraft('name', (event.target as HTMLInputElement).value) }) })}
|
|
225
|
+
${component(Field, { label: __('Slug'), for: 'term-slug', error: this.errors.slug, hint: __('Follows the name until you change it; lowercase letters, digits and hyphens.'),
|
|
226
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.slug, '@input': (event: Event) => this.setDraft('slug', (event.target as HTMLInputElement).value) }) })}
|
|
227
|
+
${this.taxonomy.hierarchical ? component(Field, { label: __('Parent'), for: 'term-parent', error: this.errors.parent,
|
|
228
|
+
control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.setDraft('parent', (event.target as HTMLSelectElement).value) }, html`
|
|
229
|
+
<option value="" ?selected=${!this.draft.parent}>${__('None')}</option>
|
|
230
|
+
${this.parents.map(entry => html`<option value=${entry.id} ?selected=${entry.id === this.draft.parent}>${'— '.repeat(entry.depth)}${entry.name}</option>`)}`) }) : null}
|
|
231
|
+
${component(Field, { label: __('Description'), for: 'term-description', error: this.errors.description,
|
|
232
|
+
control: attributes => component(Textarea, { ...attributes, rows: 4, '.value': this.draft.description, '@input': (event: Event) => this.setDraft('description', (event.target as HTMLTextAreaElement).value) }) })}
|
|
233
|
+
${iconSelect('term-icon', this.draft.icon, value => this.setDraft('icon', value), this.errors.icon)}
|
|
234
|
+
</div>`))}
|
|
235
|
+
${this.groupBoxes()}
|
|
236
|
+
<div class="flex items-center justify-between">
|
|
237
|
+
<button type="button" class="text-sm text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.remove()}>${__('Delete')}</button>
|
|
238
|
+
${component(Button, { type: 'submit' }, __('Update'))}
|
|
239
|
+
</div>
|
|
240
|
+
</form>
|
|
241
|
+
${mediaChooser(this.chooser, { search: text => this.searchMedia(text), filter: kind => this.filterMedia(kind), choose: file => this.chooseFile(file), upload: event => this.uploadFile(event), close: () => { this.chooser = { ...this.chooser, open: false }; } })}
|
|
242
|
+
</div>`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { AlertDialog, Button, Card, CardBody, Field, Icon, Input, NativeSelect, Textarea, CardHeader } from '@cossackframework/ui';
|
|
3
|
+
import { html, component } from '@cossackframework/renderer';
|
|
4
|
+
import { isCmsError, PERMISSIONS, slugify, type TermShape } from '@cossackframework/cms';
|
|
5
|
+
import { requireAny } from '#app/cms/guards';
|
|
6
|
+
import { icon } from '#app/cms/icons';
|
|
7
|
+
import { iconSelect } from '#app/cms/term-icons';
|
|
8
|
+
import { notice, pageHeader } from '#app/cms/ui';
|
|
9
|
+
|
|
10
|
+
interface Row { id: string; name: string; slug: string; description: string; icon: string; depth: number; count: number }
|
|
11
|
+
interface Draft { name: string; slug: string; parent: string; description: string; icon: string }
|
|
12
|
+
|
|
13
|
+
/** Terms of one taxonomy, WordPress style: an add form beside the table of terms with their counts. */
|
|
14
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageTerms)] })
|
|
15
|
+
export default class TermsPage extends Cossack {
|
|
16
|
+
@State() taxonomy = { name: '', label: '', singular: '', hierarchical: false, path: '' as string | null };
|
|
17
|
+
@State() rows: Row[] = [];
|
|
18
|
+
@State() search = '';
|
|
19
|
+
@State() draft: Draft = { name: '', slug: '', parent: '', description: '', icon: '' };
|
|
20
|
+
/** The slug follows the name until it is typed. */
|
|
21
|
+
@State() slugTouched = false;
|
|
22
|
+
@State() errors: Record<string, string> = {};
|
|
23
|
+
@State() error = '';
|
|
24
|
+
/** What the last addition did. */
|
|
25
|
+
@State() message = '';
|
|
26
|
+
@State() pendingDelete: Row | null = null;
|
|
27
|
+
|
|
28
|
+
head(): HeadValue {
|
|
29
|
+
return { title: this.taxonomy.label || __('Terms') };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async init() {
|
|
33
|
+
this.search = (this.c.req.query('q') ?? '').slice(0, 100);
|
|
34
|
+
await this.load();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Server()
|
|
38
|
+
async load() {
|
|
39
|
+
const cms = this.c.get('cms');
|
|
40
|
+
try {
|
|
41
|
+
const declaration = cms.taxonomies.declaration(this.c.req.param('taxonomy') ?? '');
|
|
42
|
+
this.taxonomy = { name: declaration.name, label: declaration.label, singular: declaration.singular, hierarchical: declaration.hierarchical, path: declaration.path ?? null };
|
|
43
|
+
} catch { this.error = __('This taxonomy does not exist.'); this.c.status(404); return; }
|
|
44
|
+
const terms: TermShape[] = this.search ? (await cms.taxonomies.list(this.taxonomy.name, { search: this.search, limit: 200 })).items : await cms.taxonomies.tree(this.taxonomy.name);
|
|
45
|
+
const counts = await cms.taxonomies.counts(this.taxonomy.name, terms.map(term => term.id));
|
|
46
|
+
this.rows = terms.map(term => ({ id: term.id, name: term.name, slug: term.slug, description: term.description, icon: term.icon, depth: this.search ? 0 : term.depth, count: counts.get(term.id) ?? 0 }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Client()
|
|
50
|
+
setDraft(name: keyof Draft, value: string) {
|
|
51
|
+
if (name === 'slug') this.slugTouched = value.trim() !== '';
|
|
52
|
+
// The slug is generated from the name, as WordPress does, until it is edited.
|
|
53
|
+
this.draft = { ...this.draft, [name]: value, ...(name === 'name' && !this.slugTouched ? { slug: slugify(value) } : {}) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Client()
|
|
57
|
+
async submit(event: Event) {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
this.message = '';
|
|
60
|
+
await this.create(this.draft);
|
|
61
|
+
if (!Object.keys(this.errors).length && !this.error) this.message = `${this.taxonomy.singular} ${__('added.')}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Server()
|
|
65
|
+
async create(draft: Draft) {
|
|
66
|
+
this.errors = {};
|
|
67
|
+
this.error = '';
|
|
68
|
+
try {
|
|
69
|
+
const terms = this.c.get('cms').taxonomies;
|
|
70
|
+
// The taxonomy the URL names, not the client's state.
|
|
71
|
+
await terms.create(terms.declaration(this.c.req.param('taxonomy') ?? '').name, { name: draft.name, slug: draft.slug, description: draft.description, parent: draft.parent || null, icon: draft.icon }, { principal: this.c.get('principal') });
|
|
72
|
+
this.draft = { name: '', slug: '', parent: '', description: '', icon: '' };
|
|
73
|
+
this.slugTouched = false;
|
|
74
|
+
await this.load();
|
|
75
|
+
} catch (error) {
|
|
76
|
+
this.errors = isCmsError(error) && error.fields ? { ...error.fields } : {};
|
|
77
|
+
this.error = isCmsError(error) ? error.message : __('The term could not be added.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Server()
|
|
82
|
+
async remove(id: string) {
|
|
83
|
+
this.error = '';
|
|
84
|
+
this.message = '';
|
|
85
|
+
try { await this.c.get('cms').taxonomies.delete(id, { principal: this.c.get('principal') }); }
|
|
86
|
+
catch (error) { this.error = isCmsError(error) ? error.message : __('The term could not be deleted.'); }
|
|
87
|
+
await this.load();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
render() {
|
|
91
|
+
if (!this.taxonomy.name) return notice(this.error || __('This taxonomy does not exist.'), 'error');
|
|
92
|
+
const base = `/dashboard/terms/${this.taxonomy.name}`;
|
|
93
|
+
return html`<div class="space-y-6">
|
|
94
|
+
${pageHeader(this.taxonomy.label, { description: this.taxonomy.hierarchical ? __('Nest terms to organize them; archives include the terms below.') : undefined })}
|
|
95
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
96
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
97
|
+
<div class="grid gap-6 lg:grid-cols-[22rem_minmax(0,1fr)]">
|
|
98
|
+
${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('New')} ${this.taxonomy.singular.toLowerCase()}</h2>`)}
|
|
99
|
+
${component(CardBody, {}, html`<form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
|
|
100
|
+
${component(Field, { label: __('Name'), for: 'term-name', error: this.errors.name, hint: __('The name is how it appears on your site.'),
|
|
101
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.name, '@input': (event: Event) => this.setDraft('name', (event.target as HTMLInputElement).value) }) })}
|
|
102
|
+
${component(Field, { label: __('Slug'), for: 'term-slug', error: this.errors.slug, hint: __('Generated from the name; lowercase letters, digits and hyphens.'),
|
|
103
|
+
control: attributes => component(Input, { ...attributes, '.value': this.draft.slug, '@input': (event: Event) => this.setDraft('slug', (event.target as HTMLInputElement).value) }) })}
|
|
104
|
+
${this.taxonomy.hierarchical ? component(Field, { label: __('Parent'), for: 'term-parent', error: this.errors.parent,
|
|
105
|
+
control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.setDraft('parent', (event.target as HTMLSelectElement).value) }, html`
|
|
106
|
+
<option value="" ?selected=${!this.draft.parent}>${__('None')}</option>
|
|
107
|
+
${this.rows.map(row => html`<option value=${row.id} ?selected=${row.id === this.draft.parent}>${'— '.repeat(row.depth)}${row.name}</option>`)}`) }) : null}
|
|
108
|
+
${component(Field, { label: __('Description'), for: 'term-description', error: this.errors.description,
|
|
109
|
+
control: attributes => component(Textarea, { ...attributes, rows: 3, '.value': this.draft.description, '@input': (event: Event) => this.setDraft('description', (event.target as HTMLTextAreaElement).value) }) })}
|
|
110
|
+
${iconSelect('term-icon', this.draft.icon, value => this.setDraft('icon', value), this.errors.icon)}
|
|
111
|
+
${component(Button, { type: 'submit', disabled: !this.draft.name.trim() }, `${__('New')} ${this.taxonomy.singular.toLowerCase()}`)}
|
|
112
|
+
</form>`)}`)}
|
|
113
|
+
<div class="space-y-3">
|
|
114
|
+
<form method="get" action=${base} class="flex justify-end gap-2" role="search">
|
|
115
|
+
${component(Input, { type: 'search', name: 'q', size: 'sm', value: this.search, placeholder: `${__('Search')} ${this.taxonomy.label.toLowerCase()}`, 'aria-label': __('Search') })}
|
|
116
|
+
${component(Button, { type: 'submit', size: 'sm', variant: 'outline' }, __('Search'))}
|
|
117
|
+
</form>
|
|
118
|
+
${component(Card, {}, component(CardBody, { class: 'p-0' }, html`<div class="overflow-x-auto"><table class="w-full text-sm">
|
|
119
|
+
<thead><tr class="border-b border-border text-left text-xs uppercase tracking-wide text-muted-foreground">
|
|
120
|
+
<th class="px-3 py-2 font-medium">${__('Name')}</th><th class="px-3 py-2 font-medium">${__('Description')}</th>
|
|
121
|
+
<th class="px-3 py-2 font-medium">${__('Slug')}</th><th class="px-3 py-2 text-right font-medium">${__('Count')}</th>
|
|
122
|
+
</tr></thead>
|
|
123
|
+
<tbody>${this.rows.map(row => html`<tr class="group border-b border-border last:border-0 align-top">
|
|
124
|
+
<td class="px-3 py-2">
|
|
125
|
+
<a href=${`${base}/${row.id}`} class="inline-flex items-center gap-1.5 font-medium text-foreground hover:text-primary no-underline">${'— '.repeat(row.depth)}${row.icon ? html`<span class="inline-flex text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: icon(row.icon), size: 16 })}</span>` : null}${row.name}</a>
|
|
126
|
+
<div class="mt-1 flex gap-2 text-xs opacity-80 group-hover:opacity-100">
|
|
127
|
+
<a href=${`${base}/${row.id}`} class="text-primary hover:underline">${__('Edit')}</a><span aria-hidden="true" class="text-muted-foreground">|</span>
|
|
128
|
+
<button type="button" class="text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => { this.pendingDelete = row; }}>${__('Delete')}</button>
|
|
129
|
+
${this.taxonomy.path ? html`<span aria-hidden="true" class="text-muted-foreground">|</span><a href=${`/${this.taxonomy.path}/${row.slug}`} class="text-primary hover:underline">${__('View')}</a>` : null}
|
|
130
|
+
</div>
|
|
131
|
+
</td>
|
|
132
|
+
<td class="px-3 py-2 text-muted-foreground">${row.description || '—'}</td>
|
|
133
|
+
<td class="px-3 py-2 font-mono text-xs text-muted-foreground">${row.slug}</td>
|
|
134
|
+
<td class="px-3 py-2 text-right text-muted-foreground">${row.count}</td>
|
|
135
|
+
</tr>`)}</tbody>
|
|
136
|
+
</table>${this.rows.length ? null : html`<p class="px-4 py-10 text-center text-sm text-muted-foreground">${__('No terms found.')}</p>`}</div>`))}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
${component(AlertDialog, {
|
|
140
|
+
id: 'delete-term-dialog', open: this.pendingDelete !== null, title: `${__('Delete')} ${this.taxonomy.singular.toLowerCase()}?`,
|
|
141
|
+
description: this.pendingDelete ? `“${this.pendingDelete.name}” ${__('is removed from entries. Terms below it move up a level.')}` : '',
|
|
142
|
+
cancelLabel: __('Cancel'), actionLabel: __('Delete'), actionVariant: 'destructive',
|
|
143
|
+
onAction: () => { const row = this.pendingDelete; this.pendingDelete = null; if (row) void this.remove(row.id); },
|
|
144
|
+
onOpenChange: () => { this.pendingDelete = null; },
|
|
145
|
+
})}
|
|
146
|
+
</div>`;
|
|
147
|
+
}
|
|
148
|
+
}
|