@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,320 @@
|
|
|
1
|
+
import { Cossack, Page, Server, State, Client, Image, server$, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { Sidebar, DropdownMenu, Avatar, Icon, type SidebarItem } from '@cossackframework/ui';
|
|
3
|
+
import { CommandPalette, type CommandItem } from '@cossackframework/ui/blocks';
|
|
4
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
5
|
+
import { getCookie } from 'hono/cookie';
|
|
6
|
+
import { dashboardFind, dashboardNotices, dashboardSearch, dashboardStatus, navigation } from '#app/dashboard/access';
|
|
7
|
+
import { shellIcons } from '#app/dashboard/icons';
|
|
8
|
+
import { dashboardHead } from '#app/dashboard/head';
|
|
9
|
+
import { notice } from '@cossackframework/ui/blocks';
|
|
10
|
+
import { siteHasLogo, siteLogo, siteName } from '#app/brand';
|
|
11
|
+
import type { DashboardModule, DashboardNotice, DashboardStatus } from '#app/dashboard/types';
|
|
12
|
+
import { logout } from '#app/auth';
|
|
13
|
+
import { requireDashboardUser } from '#app/middlewares/auth';
|
|
14
|
+
import { themeStore } from '@/stores.client';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dashboard layout: sidebar nav + user menu + theme toggle, shared by every
|
|
18
|
+
* /dashboard/* page. src/dashboard/access.ts decides which modules the user
|
|
19
|
+
* sees; each describes its icon, destination, submenu links, and whether it
|
|
20
|
+
* belongs in navigation or the account menu.
|
|
21
|
+
*
|
|
22
|
+
* A page with navigation of its own (a secondary sidebar) marks its root
|
|
23
|
+
* `data-subnav`: the main area then drops its padding, so the page's
|
|
24
|
+
* navigation sits against the sidebar and runs to the footer.
|
|
25
|
+
*
|
|
26
|
+
* The theme toggle writes the same `cs-theme` cookie and themeStore the App
|
|
27
|
+
* component applies to `<html>.dark`, and draws itself from that class.
|
|
28
|
+
*
|
|
29
|
+
* The taskbar along the bottom (desktop and tablet) opens the site, shows what
|
|
30
|
+
* waits for the user (`dashboardStatus` in src/dashboard/access.ts, a `server$`
|
|
31
|
+
* resource so it is fresh on every navigation) and holds the Screen options and
|
|
32
|
+
* Help buttons, which open the `#screen-options` and `#screen-help` popovers a
|
|
33
|
+
* screen renders with `screenOptions()` and `screenHelp()` from src/dashboard/page.ts.
|
|
34
|
+
*/
|
|
35
|
+
@Page({ transport: 'http', middlewares: [requireDashboardUser] })
|
|
36
|
+
export default class DashboardLayout extends Cossack {
|
|
37
|
+
appName = server$(() => siteName(), { initial: 'Cossack' });
|
|
38
|
+
appLogo = server$(() => siteLogo(), { initial: '/logo.svg' });
|
|
39
|
+
/** The site set its own logo: it shows without the name beside it. */
|
|
40
|
+
appLogoOnly = server$(() => siteHasLogo(), { initial: false });
|
|
41
|
+
/** What waits for the user, with counts, for the taskbar. */
|
|
42
|
+
statuses: DashboardStatus[] = server$(() => dashboardStatus(this.c), { initial: [] });
|
|
43
|
+
/** Messages above every screen, such as the ones CMS plugins return; fresh on every navigation, like the statuses. */
|
|
44
|
+
notices: DashboardNotice[] = server$(() => dashboardNotices(this.c), { initial: [] });
|
|
45
|
+
/** Sidebar collapsed state. Seeded from the cookie at SSR (via this.c) and
|
|
46
|
+
* re-read client-side in onMount; persists across client navigations. */
|
|
47
|
+
@State() sidebarCollapsed = false;
|
|
48
|
+
/** Navigation the signed-in user may open, resolved on the server. */
|
|
49
|
+
@State() modules: DashboardModule[] = [];
|
|
50
|
+
/** Where Ctrl/Cmd+K can go: every screen of the navigation, resolved with it. */
|
|
51
|
+
@State() commands: { id: string; label: string; group: string; href: string }[] = [];
|
|
52
|
+
/** What the palette found for its text besides the screens (`dashboardFind`): the CMS's entries. */
|
|
53
|
+
@State() found: { id: string; label: string; group: string; href: string }[] = [];
|
|
54
|
+
/** The palette's text the next find is for; one find runs at a time, so an older answer never replaces a newer one. */
|
|
55
|
+
private wanted = '';
|
|
56
|
+
private finding = false;
|
|
57
|
+
private findTimer: ReturnType<typeof setTimeout> | undefined;
|
|
58
|
+
@State() logoutError = '';
|
|
59
|
+
@State() account: { name: string; email: string; avatar: string | null } = {
|
|
60
|
+
name: '',
|
|
61
|
+
email: '',
|
|
62
|
+
avatar: null,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
@Client()
|
|
66
|
+
toggleTheme() {
|
|
67
|
+
const theme = themeStore.get() === 'dark' ? 'light' : 'dark';
|
|
68
|
+
document.cookie = `cs-theme=${theme}; Path=/; Max-Age=31536000; SameSite=Lax`;
|
|
69
|
+
themeStore.set(theme);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Flip the sidebar collapsed state and persist to a cookie so the next
|
|
73
|
+
* SSR render paints the correct state (no flash). The @State update drives
|
|
74
|
+
* the Sidebar re-render (controlled component). */
|
|
75
|
+
/** Open the screen or entry a palette entry names; the palette's ids are the hrefs. */
|
|
76
|
+
@Client()
|
|
77
|
+
go(id: string) {
|
|
78
|
+
const found = [...this.commands, ...this.found].find((entry) => entry.id === id);
|
|
79
|
+
if (found) window.location.assign(found.href);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The palette's text changed: find for it a moment after the typing stops, from two characters. */
|
|
83
|
+
@Client()
|
|
84
|
+
onPaletteSearch(text: string) {
|
|
85
|
+
this.wanted = text.trim();
|
|
86
|
+
clearTimeout(this.findTimer);
|
|
87
|
+
if (this.wanted.length < 2) {
|
|
88
|
+
if (this.found.length) this.found = [];
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.findTimer = setTimeout(() => void this.findWanted(), 150);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Find for the text wanted, again while it changed during a find. */
|
|
95
|
+
@Client()
|
|
96
|
+
async findWanted() {
|
|
97
|
+
if (this.finding) return;
|
|
98
|
+
this.finding = true;
|
|
99
|
+
try {
|
|
100
|
+
let text: string;
|
|
101
|
+
do {
|
|
102
|
+
text = this.wanted;
|
|
103
|
+
if (text.length >= 2) await this.find(text);
|
|
104
|
+
} while (text !== this.wanted);
|
|
105
|
+
if (this.wanted.length < 2 && this.found.length) this.found = [];
|
|
106
|
+
} catch {
|
|
107
|
+
/* the screens still show; the next text finds again */
|
|
108
|
+
} finally {
|
|
109
|
+
this.finding = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@Server()
|
|
114
|
+
async find(text: string) {
|
|
115
|
+
const seen = new Set(this.commands.map((entry) => entry.id));
|
|
116
|
+
this.found = typeof text === 'string' ? (await dashboardFind(this.c, text.slice(0, 200))).filter((entry) => !seen.has(entry.id)) : [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Client()
|
|
120
|
+
onToggleSidebar() {
|
|
121
|
+
this.sidebarCollapsed = !this.sidebarCollapsed;
|
|
122
|
+
try {
|
|
123
|
+
document.cookie = `cs-sidebar-collapsed=${this.sidebarCollapsed}; Path=/; Max-Age=31536000; SameSite=Lax`;
|
|
124
|
+
} catch { /* document.cookie unavailable */ }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Server()
|
|
128
|
+
async doLogout() {
|
|
129
|
+
this.logoutError = '';
|
|
130
|
+
try {
|
|
131
|
+
const { headers } = await logout(this.c);
|
|
132
|
+
headers.forEach((value, key) => this.c.header(key, value));
|
|
133
|
+
this.redirect(config('auth.redirectAfterLogout'));
|
|
134
|
+
} catch {
|
|
135
|
+
this.logoutError = 'Could not sign out. Try again.';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async init() {
|
|
140
|
+
const user = this.user;
|
|
141
|
+
if (this.c) {
|
|
142
|
+
this.modules = await navigation(this.c);
|
|
143
|
+
this.commands = await dashboardSearch(this.c);
|
|
144
|
+
}
|
|
145
|
+
this.account = {
|
|
146
|
+
name: user?.name ?? '',
|
|
147
|
+
email: user?.email ?? '',
|
|
148
|
+
avatar: user?.avatar ?? null,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
this.sidebarCollapsed = this.c
|
|
152
|
+
? getCookie(this.c, 'cs-sidebar-collapsed') === 'true'
|
|
153
|
+
: this.sidebarCollapsed;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
head(): HeadValue {
|
|
157
|
+
return { meta: dashboardHead() };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
render(): TemplateResult {
|
|
161
|
+
const icons = shellIcons();
|
|
162
|
+
const iconClass = 'inline-flex items-center justify-center [&_svg]:size-4';
|
|
163
|
+
// The theme icons: only one shows, so `hidden` must not share the element with `inline-flex`.
|
|
164
|
+
const themeIcon = 'items-center justify-center [&_svg]:size-4';
|
|
165
|
+
const availableModules = this.modules;
|
|
166
|
+
// A module with a parent the user also sees is listed inside the parent's menu.
|
|
167
|
+
const nested = (module: DashboardModule) => !!module.parent && availableModules.some((other) => other.id === module.parent);
|
|
168
|
+
const navigationModules = availableModules.filter(
|
|
169
|
+
(module) => module.placement !== 'account' && !nested(module),
|
|
170
|
+
);
|
|
171
|
+
const accountModules = availableModules.filter(
|
|
172
|
+
(module) => module.placement === 'account',
|
|
173
|
+
);
|
|
174
|
+
const items: SidebarItem[] = [
|
|
175
|
+
{
|
|
176
|
+
value: 'dashboard',
|
|
177
|
+
label: __('Dashboard'),
|
|
178
|
+
href: '/dashboard',
|
|
179
|
+
icon: icons.home,
|
|
180
|
+
active: this.isActive('/dashboard'),
|
|
181
|
+
},
|
|
182
|
+
...navigationModules.map((module): SidebarItem => {
|
|
183
|
+
const item = {
|
|
184
|
+
value: `module:${module.id}`,
|
|
185
|
+
label: __(module.label), href: module.href, icon: module.icon,
|
|
186
|
+
active: module.activeFor ? this.isActive(module.activeFor, false) : this.isActive(module.href),
|
|
187
|
+
};
|
|
188
|
+
const children = [
|
|
189
|
+
...(module.children ?? []),
|
|
190
|
+
...availableModules.filter((other) => other.parent === module.id && nested(other))
|
|
191
|
+
.flatMap((other) => other.children?.length ? other.children : [{ label: other.label, href: other.href }]),
|
|
192
|
+
];
|
|
193
|
+
if (!children.length) return item;
|
|
194
|
+
// A group lists its own page as a link too; leave it out when a child already opens it.
|
|
195
|
+
const { href: _href, active: _active, ...group } = item;
|
|
196
|
+
return {
|
|
197
|
+
...(children.some((child) => child.href === module.href) ? group : item),
|
|
198
|
+
children: children.map((child) => ({
|
|
199
|
+
value: `module:${module.id}:${child.href}`,
|
|
200
|
+
label: __(child.label), href: child.href,
|
|
201
|
+
active: this.isActive(child.href),
|
|
202
|
+
})),
|
|
203
|
+
};
|
|
204
|
+
}),
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
const statusTone = (tone: DashboardStatus['tone']) => tone === 'error' ? 'text-destructive' : tone === 'warning' ? 'text-warning-text' : 'text-muted-foreground';
|
|
208
|
+
const taskbarButton = 'hidden h-7 cursor-pointer items-center gap-1 rounded-md border-none bg-transparent px-2 text-xs text-muted-foreground hover:bg-muted hover:text-foreground';
|
|
209
|
+
return html`
|
|
210
|
+
<div class="group/dashboard flex min-h-screen bg-background">
|
|
211
|
+
${component(Sidebar, {
|
|
212
|
+
id: 'dashboard-navigation', label: __('Dashboard navigation'),
|
|
213
|
+
expandLabel: __('Expand navigation'), collapseLabel: __('Collapse navigation'),
|
|
214
|
+
title: this.appName,
|
|
215
|
+
// The brand opens the site itself, as WordPress's admin bar does; Dashboard is the first navigation item.
|
|
216
|
+
brand: html`<a href="/" class="flex items-center gap-2 no-underline group-[.is-collapsed]:hidden" aria-label=${__('View site')} title=${__('View site')}>
|
|
217
|
+
${this.appLogoOnly
|
|
218
|
+
? Image({ src: this.appLogo, alt: this.appName, width: 32, height: 32, loading: 'eager', class: 'h-8 w-auto max-w-40 shrink-0 object-contain' })
|
|
219
|
+
: html`${Image({ src: this.appLogo, alt: '', width: 24, height: 24, loading: 'eager', class: 'h-6 w-auto max-w-24 shrink-0 object-contain' })}
|
|
220
|
+
<span class="text-sm font-semibold text-foreground truncate">${this.appName}</span>`}
|
|
221
|
+
</a>
|
|
222
|
+
<a href="/" class="hidden group-[.is-collapsed]:flex items-center justify-center" aria-label=${__('View site')} title=${__('View site')}>
|
|
223
|
+
${Image({ src: this.appLogo, alt: '', width: 24, height: 24, loading: 'eager', class: 'size-6 object-contain' })}
|
|
224
|
+
</a>`,
|
|
225
|
+
width: '248px',
|
|
226
|
+
collapsible: 'icon',
|
|
227
|
+
collapsed: this.sidebarCollapsed,
|
|
228
|
+
onCollapsedChange: () => this.onToggleSidebar(),
|
|
229
|
+
items: items,
|
|
230
|
+
// The toggle renders both modes and the .dark class on <html> shows the current
|
|
231
|
+
// one (sun in light mode, moon in dark mode), so the server's markup matches
|
|
232
|
+
// before the cookie or system theme is known. A click switches to the other.
|
|
233
|
+
footer: html`
|
|
234
|
+
<div class="flex items-center gap-1">
|
|
235
|
+
<button
|
|
236
|
+
type="button"
|
|
237
|
+
@click=${() => this.toggleTheme()}
|
|
238
|
+
class="flex-1 flex items-center justify-center gap-2 px-2 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer border-none bg-transparent group-[.is-collapsed]:px-0"
|
|
239
|
+
title=${__('Switch between light and dark mode')}
|
|
240
|
+
aria-label=${__('Switch between light and dark mode')}
|
|
241
|
+
>
|
|
242
|
+
<span class=${`${themeIcon} inline-flex dark:hidden`}>${component(Icon, { entry: icons.light, size: 16 })}</span>
|
|
243
|
+
<span class=${`${themeIcon} hidden dark:inline-flex`}>${component(Icon, { entry: icons.dark, size: 16 })}</span>
|
|
244
|
+
<span class="group-[.is-collapsed]:hidden dark:hidden">${__('Light mode')}</span>
|
|
245
|
+
<span class="hidden group-[.is-collapsed]:hidden dark:inline">${__('Dark mode')}</span>
|
|
246
|
+
</button>
|
|
247
|
+
</div>
|
|
248
|
+
<div class="h-px bg-border my-1 group-[.is-collapsed]:hidden"></div>
|
|
249
|
+
${component(DropdownMenu, {
|
|
250
|
+
id: 'dashboard-account-menu',
|
|
251
|
+
block: true,
|
|
252
|
+
side: 'right',
|
|
253
|
+
align: 'end',
|
|
254
|
+
trigger: html`
|
|
255
|
+
<span class="flex items-center gap-2.5 w-full px-1.5 py-1 rounded-md text-left group-[.is-collapsed]:justify-center">
|
|
256
|
+
${component(Avatar, { src: this.account.avatar ?? '', alt: this.account.name, size: 32 })}
|
|
257
|
+
<span class="flex-1 min-w-0 group-[.is-collapsed]:hidden">
|
|
258
|
+
<span class="block text-sm font-medium text-foreground truncate">${this.account.name}</span>
|
|
259
|
+
<span class="block text-xs text-muted-foreground truncate">${this.account.email}</span>
|
|
260
|
+
</span>
|
|
261
|
+
<span class="text-muted-foreground group-[.is-collapsed]:hidden ${iconClass}">
|
|
262
|
+
${component(Icon, { entry: icons.expand, size: 16 })}
|
|
263
|
+
</span>
|
|
264
|
+
</span>
|
|
265
|
+
`,
|
|
266
|
+
}, html`
|
|
267
|
+
<div class="px-3 py-2">
|
|
268
|
+
<div class="text-sm font-medium">${this.account.name}</div>
|
|
269
|
+
<div class="text-xs text-muted-foreground">${this.account.email}</div>
|
|
270
|
+
</div>
|
|
271
|
+
${accountModules.length ? html`<div class="h-px bg-border my-1"></div>` : null}
|
|
272
|
+
${accountModules.map((module) => html`
|
|
273
|
+
<a role="menuitem" tabindex="-1" href=${module.href} class="w-full flex items-center gap-2 px-3 py-2 text-sm rounded-sm hover:bg-muted text-foreground no-underline">
|
|
274
|
+
<span class=${iconClass}>${component(Icon, { entry: module.icon, size: 16 })}</span>
|
|
275
|
+
${__(module.label)}
|
|
276
|
+
</a>
|
|
277
|
+
`)}
|
|
278
|
+
<div class="h-px bg-border my-1"></div>
|
|
279
|
+
<button
|
|
280
|
+
type="button" role="menuitem" tabindex="-1"
|
|
281
|
+
@click=${() => this.doLogout()}
|
|
282
|
+
class="w-full flex items-center gap-2 px-3 py-2 text-sm rounded-sm hover:bg-muted cursor-pointer border-none bg-transparent text-left text-destructive">
|
|
283
|
+
<span class=${iconClass}>${component(Icon, { entry: icons.logout, size: 16 })}</span>
|
|
284
|
+
${__('Log out')}
|
|
285
|
+
</button>
|
|
286
|
+
`)}
|
|
287
|
+
`,
|
|
288
|
+
})}
|
|
289
|
+
<div class="flex-1 min-w-0 flex flex-col">
|
|
290
|
+
${component(CommandPalette, { id: 'dashboard-commands', label: __('Go to'), placeholder: __('Type a screen name or search…'), shortcut: true,
|
|
291
|
+
commands: [...this.commands.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group })),
|
|
292
|
+
...this.found.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group, matched: true }))],
|
|
293
|
+
onSelect: (id: string) => this.go(id), onSearchChange: (text: string) => this.onPaletteSearch(text) })}
|
|
294
|
+
<main class="flex-1 p-6 sm:p-8 overflow-x-hidden has-[[data-settings-toolbar]]:overflow-visible has-[[data-subnav]]:grid has-[[data-subnav]]:grid-cols-1 has-[[data-subnav]]:p-0">
|
|
295
|
+
${this.logoutError ? html`<p role="alert" class="mb-4 text-sm text-destructive">${this.logoutError}</p>` : null}
|
|
296
|
+
${this.notices.length ? html`<div data-dashboard-notices class="mb-6 space-y-2 group-has-[[data-subnav]]/dashboard:m-4">${this.notices.map((item) => item.href
|
|
297
|
+
? html`<a href=${item.href} data-notice-id=${item.id} class="block no-underline">${notice(item.message, item.tone)}</a>`
|
|
298
|
+
: html`<div data-notice-id=${item.id}>${notice(item.message, item.tone)}</div>`)}</div>` : null}
|
|
299
|
+
${this.children}
|
|
300
|
+
</main>
|
|
301
|
+
<footer data-dashboard-taskbar aria-label=${__('Dashboard taskbar')} class="sticky bottom-0 z-30 hidden h-10 items-center gap-1 border-t border-border bg-background/95 px-3 text-xs text-muted-foreground backdrop-blur md:flex">
|
|
302
|
+
<a href="/" class="inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-foreground no-underline hover:bg-muted" title=${__('View site')}>
|
|
303
|
+
${this.appLogoOnly
|
|
304
|
+
? Image({ src: this.appLogo, alt: this.appName, width: 24, height: 24, loading: 'eager', class: 'h-6 w-auto max-w-28 shrink-0 object-contain' })
|
|
305
|
+
: html`${Image({ src: this.appLogo, alt: '', width: 16, height: 16, loading: 'eager', class: 'h-4 w-auto max-w-16 shrink-0 object-contain' })}
|
|
306
|
+
<span class="max-w-40 truncate">${this.appName}</span>`}
|
|
307
|
+
</a>
|
|
308
|
+
<span aria-hidden="true" class="mx-1 h-4 w-px bg-border"></span>
|
|
309
|
+
${this.statuses.map((item) => html`<a href=${item.href} data-status=${item.id} class=${`inline-flex h-7 items-center gap-1.5 rounded-md px-2 no-underline hover:bg-muted hover:text-foreground ${statusTone(item.tone)}`}>
|
|
310
|
+
${__(item.label)}${item.count !== undefined ? html`<span class="rounded-full bg-muted px-1.5 py-px text-[0.7rem] font-semibold tabular-nums text-foreground">${item.count}</span>` : null}</a>`)}
|
|
311
|
+
<span class="flex-1"></span>
|
|
312
|
+
<button type="button" popovertarget="screen-options" class=${`${taskbarButton} group-has-[#screen-options]/dashboard:inline-flex`}>${__('Screen options')}</button>
|
|
313
|
+
<button type="button" popovertarget="screen-help" class=${`${taskbarButton} group-has-[#screen-help]/dashboard:inline-flex`}>${__('Help')}</button>
|
|
314
|
+
<span class="px-2">© ${new Date().getFullYear()} ${this.appName}</span>
|
|
315
|
+
</footer>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
`;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Cossack, Page, State, ClientState, Store, Validate, Client, Server, storeRules, getLocale, getSupportedLocales, setLocale } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Card, CardBody, CardHeader, Field, Input, Button, Avatar, Form, NativeSelect } from '@cossackframework/ui';
|
|
4
|
+
import { notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
5
|
+
import { html, component, bind } from '@cossackframework/renderer';
|
|
6
|
+
import { avatarUploads, deleteOwnAccount, updateUserProfile, uploadAvatar } from '#app/auth';
|
|
7
|
+
import { avatarField } from '#app/dashboard/avatar-field';
|
|
8
|
+
|
|
9
|
+
/** A language's name in itself, such as Français or Tiếng Việt. */
|
|
10
|
+
function languageLabel(code: string): string {
|
|
11
|
+
try { return new Intl.DisplayNames([code], { type: 'language' }).of(code) ?? code; } catch { return code; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ProfileForm {
|
|
15
|
+
name: string;
|
|
16
|
+
avatar: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Page({ transport: 'http' })
|
|
20
|
+
export default class ProfilePage extends Cossack {
|
|
21
|
+
@Store()
|
|
22
|
+
@Validate({
|
|
23
|
+
rules: storeRules<ProfileForm>({
|
|
24
|
+
name: { required: true, message: 'Name is required' },
|
|
25
|
+
}),
|
|
26
|
+
config: { trigger: 'all', runOn: 'both' }
|
|
27
|
+
})
|
|
28
|
+
form: ProfileForm = { name: '', avatar: '' };
|
|
29
|
+
|
|
30
|
+
@State() saved = false;
|
|
31
|
+
@State() error = '';
|
|
32
|
+
/** What the last action did, shown under the heading. */
|
|
33
|
+
@State() message = '';
|
|
34
|
+
/** Email shown in the profile card (read-only; seeded server-side). */
|
|
35
|
+
@State() userEmail = '';
|
|
36
|
+
/** Whether the auth store accepts picture uploads; otherwise the avatar is a URL. */
|
|
37
|
+
@State() avatarUploads = false;
|
|
38
|
+
@ClientState() uploading = false;
|
|
39
|
+
@ClientState() avatarError = '';
|
|
40
|
+
/** The chosen picture while it uploads; browser-only, so server state never echoes it back. */
|
|
41
|
+
@ClientState() avatarPreview = '';
|
|
42
|
+
/** Languages the interface has catalogs for, from the application and language packs. */
|
|
43
|
+
@State() languages: { code: string; label: string }[] = [];
|
|
44
|
+
@State() language = '';
|
|
45
|
+
|
|
46
|
+
async init() {
|
|
47
|
+
// Seed the form server-side (serializes via @Store) so it's populated
|
|
48
|
+
// at SSR — not empty until onMount runs client-side.
|
|
49
|
+
const user = this.user;
|
|
50
|
+
if (user) {
|
|
51
|
+
this.form.name = user.name;
|
|
52
|
+
this.form.avatar = user.avatar ?? '';
|
|
53
|
+
this.userEmail = user.email;
|
|
54
|
+
}
|
|
55
|
+
this.avatarUploads = avatarUploads;
|
|
56
|
+
this.languages = getSupportedLocales().map(code => ({ code, label: languageLabel(code) }));
|
|
57
|
+
this.language = getLocale();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Keep the dashboard's language in this browser (the `cossack_locale` cookie), then draw it again. */
|
|
61
|
+
@Client()
|
|
62
|
+
async chooseLanguage(event: Event) {
|
|
63
|
+
this.error = '';
|
|
64
|
+
try {
|
|
65
|
+
await setLocale((event.target as HTMLSelectElement).value);
|
|
66
|
+
window.location.reload();
|
|
67
|
+
} catch {
|
|
68
|
+
this.error = __('That language could not be loaded.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Upload a picture: it shows at once and is saved when the upload finishes. */
|
|
73
|
+
@Client()
|
|
74
|
+
async chooseAvatar(file: File) {
|
|
75
|
+
this.avatarError = '';
|
|
76
|
+
this.message = '';
|
|
77
|
+
this.uploading = true;
|
|
78
|
+
const preview = URL.createObjectURL(file);
|
|
79
|
+
this.avatarPreview = preview;
|
|
80
|
+
try {
|
|
81
|
+
await this.storeAvatar(file);
|
|
82
|
+
this.message = __('Picture updated.');
|
|
83
|
+
} catch (e: any) {
|
|
84
|
+
this.avatarError = e?.message || __('The picture could not be uploaded.');
|
|
85
|
+
} finally {
|
|
86
|
+
this.uploading = false;
|
|
87
|
+
this.avatarPreview = '';
|
|
88
|
+
URL.revokeObjectURL(preview);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The stored picture's URL comes back as state. */
|
|
93
|
+
@Server({ input: input.args(input.file()) })
|
|
94
|
+
async storeAvatar(file: File) {
|
|
95
|
+
this.form.avatar = await uploadAvatar(this.user!.id, file);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Client()
|
|
99
|
+
async removeAvatar() {
|
|
100
|
+
this.form.avatar = '';
|
|
101
|
+
this.message = '';
|
|
102
|
+
await this.clearAvatar();
|
|
103
|
+
this.message = __('Picture removed.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Server()
|
|
107
|
+
async clearAvatar() {
|
|
108
|
+
await updateUserProfile(this.user!.id, { avatar: null });
|
|
109
|
+
this.form.avatar = '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@Client()
|
|
113
|
+
async handleSubmit(event: Event) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
this.error = '';
|
|
116
|
+
this.message = '';
|
|
117
|
+
this.saved = false;
|
|
118
|
+
const ok = await this.validateAll();
|
|
119
|
+
if (!ok) return;
|
|
120
|
+
try {
|
|
121
|
+
await this.save(this.form.name, this.form.avatar);
|
|
122
|
+
this.saved = true;
|
|
123
|
+
this.message = __('Profile updated.');
|
|
124
|
+
} catch (e: any) {
|
|
125
|
+
this.error = e?.message || 'Could not save profile';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Server()
|
|
130
|
+
async save(name: string, avatar: string) {
|
|
131
|
+
await updateUserProfile(this.user!.id, { name, avatar: avatar || null });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@ClientState() deletePassword = '';
|
|
135
|
+
@State() deleteError = '';
|
|
136
|
+
|
|
137
|
+
@Client()
|
|
138
|
+
async confirmDelete(event: Event) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
if (!this.deletePassword || !window.confirm(__('Delete your account for good? This cannot be undone.'))) return;
|
|
141
|
+
await this.deleteAccount(this.deletePassword);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Ends every session and deletes the account; the browser lands on the home page signed out. */
|
|
145
|
+
@Server()
|
|
146
|
+
async deleteAccount(password: string) {
|
|
147
|
+
this.deleteError = '';
|
|
148
|
+
try {
|
|
149
|
+
const { headers } = await deleteOwnAccount(this.c, this.user!.id, password);
|
|
150
|
+
headers.forEach((value, key) => this.c.header(key, value));
|
|
151
|
+
this.redirect('/');
|
|
152
|
+
} catch (error) {
|
|
153
|
+
this.deleteError = (error as Error).message || __('The account could not be deleted.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
render() {
|
|
158
|
+
return html`
|
|
159
|
+
<div class="max-w-2xl space-y-6">
|
|
160
|
+
${pageHeader(__('Profile'), { description: __('Update your display name and avatar.'),
|
|
161
|
+
actions: html`<a href="/dashboard/profile/security" class="text-sm text-primary hover:underline">${__('Security and application passwords')} →</a>` })}
|
|
162
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
163
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
164
|
+
|
|
165
|
+
${component(Card, {}, component(CardBody, {}, html`
|
|
166
|
+
<div class="flex items-center gap-4">
|
|
167
|
+
${component(Avatar, { src: this.form.avatar || undefined, alt: this.form.name, size: 56 })}
|
|
168
|
+
<div>
|
|
169
|
+
<div class="text-sm text-muted-foreground">${__('Email')}</div>
|
|
170
|
+
<div class="text-foreground font-medium">${this.userEmail}</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
`))}
|
|
174
|
+
|
|
175
|
+
${component(Card, {}, html`
|
|
176
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Edit profile')}</h2>`)}
|
|
177
|
+
${component(CardBody, {}, html`
|
|
178
|
+
${component(Form, {
|
|
179
|
+
submit: (e: Event) => this.handleSubmit(e),
|
|
180
|
+
}, html`
|
|
181
|
+
<div class="flex flex-col space-y-4">
|
|
182
|
+
${component(Field, { label: __('Name'), for: 'name', error: this.getError('form.name'),
|
|
183
|
+
control: attributes => component(Input, { ...attributes, type: 'text', '.value': bind(this.form, 'name') }) })}
|
|
184
|
+
${avatarField({ id: 'avatar', value: this.avatarPreview || this.form.avatar, name: this.form.name, uploads: this.avatarUploads, uploading: this.uploading, error: this.avatarError,
|
|
185
|
+
onFile: file => this.chooseAvatar(file), onUrl: url => { this.form.avatar = url; }, onRemove: () => this.removeAvatar() })}
|
|
186
|
+
<div>${component(Button, { type: 'submit' }, __('Save changes'))}</div>
|
|
187
|
+
</div>
|
|
188
|
+
`)}
|
|
189
|
+
`)}
|
|
190
|
+
`)}
|
|
191
|
+
|
|
192
|
+
${this.languages.length > 1 ? component(Card, {}, html`
|
|
193
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Dashboard language')}</h2>`)}
|
|
194
|
+
${component(CardBody, {}, component(Field, { label: __('Language'), for: 'dashboard-language', hint: __('Kept in this browser.'),
|
|
195
|
+
control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.chooseLanguage(event) }, html`
|
|
196
|
+
${this.languages.map(language => html`<option value=${language.code} ?selected=${language.code === this.language}>${language.label}</option>`)}`) }))}
|
|
197
|
+
`) : null}
|
|
198
|
+
${component(Card, {}, html`
|
|
199
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-destructive">${__('Delete your account')}</h2>
|
|
200
|
+
<p class="text-sm text-muted-foreground">${__('Your account and its sessions go for good. What you published stays, without you as its author.')}</p>`)}
|
|
201
|
+
${component(CardBody, {}, html`<form class="flex flex-wrap items-end gap-3" @submit=${(event: Event) => this.confirmDelete(event)}>
|
|
202
|
+
${component(Field, { label: __('Your password'), for: 'delete-password', control: attributes => component(Input, { ...attributes, type: 'password', autocomplete: 'current-password', required: true,
|
|
203
|
+
'.value': this.deletePassword, '@input': (event: Event) => { this.deletePassword = (event.target as HTMLInputElement).value; } }) })}
|
|
204
|
+
${component(Button, { type: 'submit', variant: 'destructive' }, __('Delete my account'))}
|
|
205
|
+
${this.deleteError ? html`<p role="alert" class="w-full text-sm text-destructive">${this.deleteError}</p>` : null}
|
|
206
|
+
</form>`)}
|
|
207
|
+
`)}
|
|
208
|
+
</div>
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
}
|