@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,359 @@
|
|
|
1
|
+
import { Client, ClientState, Cossack, Inject, OnDocument, OnWindow, Page, PreventNavigation, Server, Shared, server$, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Badge, Card, CardBody } from '@cossackframework/ui';
|
|
4
|
+
import { component, html, repeat, type TemplateResult } from '@cossackframework/renderer';
|
|
5
|
+
import { hasPermission, isCmsError, isNetworkAdmin, MAIN_SITE, PERMISSIONS, type SettingsDocument, type SettingsSection as SectionDeclaration } from '@cossackframework/cms';
|
|
6
|
+
import { requireAny } from '#app/cms/guards';
|
|
7
|
+
import { SettingsDraft, settingsNavigation } from '#app/cms/settings-draft';
|
|
8
|
+
import { findSettingsMedia, settingControl, settingInput, settingRows, settingsEditorSnapshot, type ChoiceCache, type SettingRow, type SettingValue, type SettingValues } from '#app/cms/settings-form';
|
|
9
|
+
import { filterSettingsLinks, settingsErrorSummary, settingsFrame, settingsLinks, type SettingsLink } from '#app/cms/settings-nav';
|
|
10
|
+
import { searchSettings, settingsSearchEntries, settingsSectionId, type SettingsSearchEntry } from '#app/cms/settings-search';
|
|
11
|
+
import { SettingsSection } from '#app/cms/settings-section';
|
|
12
|
+
import { activeSettingsSection } from '#app/cms/settings-scroll';
|
|
13
|
+
import { languageDraft, languageInput, LanguagesSettings, loadLanguageSettings, saveLanguageSettings, type LanguageSettingsData, type LanguageSettingsInput } from '#app/cms/settings-languages';
|
|
14
|
+
import { PermalinksSettings, loadPermalinkSettings, permalinkDraft, savePermalinkSettings, type PermalinkSettingsData, type PermalinkSettingsInput } from '#app/cms/settings-permalinks';
|
|
15
|
+
import { NetworkSettingsForm, loadNetworkSettings, networkDraft, saveNetworkSettings, type NetworkSettingsData, type NetworkSettingsInput } from '#app/cms/settings-network';
|
|
16
|
+
import { notice } from '#app/cms/ui';
|
|
17
|
+
|
|
18
|
+
interface GroupView {
|
|
19
|
+
id: string; label: string; description: string; plugin: string; active: boolean; theme: boolean; portable: boolean;
|
|
20
|
+
sections: readonly SectionDeclaration[]; rows: SettingRow[]; values: SettingValues;
|
|
21
|
+
}
|
|
22
|
+
/** Everything the toolbar's Save sends: the portable document and the sections saved by their own operations. */
|
|
23
|
+
interface SaveInput {
|
|
24
|
+
document: SettingsDocument | null;
|
|
25
|
+
languages: LanguageSettingsInput | null;
|
|
26
|
+
permalinks: PermalinkSettingsInput | null;
|
|
27
|
+
network: NetworkSettingsInput | null;
|
|
28
|
+
groups: Record<string, SettingValues>;
|
|
29
|
+
}
|
|
30
|
+
/** What was saved, in order; the first part that fails stops the rest and names its section. */
|
|
31
|
+
interface SaveResult {
|
|
32
|
+
document: SettingsDocument | null; languages: LanguageSettingsData | null; permalinks: PermalinkSettingsData | null; network: NetworkSettingsData | null; groups: string[];
|
|
33
|
+
error: string; fields: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
interface SettingsView {
|
|
36
|
+
links: SettingsLink[]; entries: SettingsSearchEntry[]; groups: GroupView[];
|
|
37
|
+
canUpload: boolean; canBrowse: boolean;
|
|
38
|
+
snapshot: SettingsDocument; invalid: Record<string, string>; languages: LanguageSettingsData | null; permalinks: PermalinkSettingsData | null;
|
|
39
|
+
/** The Network section: for network admins, on the main site. */
|
|
40
|
+
network: NetworkSettingsData | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One document of settings. The menu and visible fields use the same search matches. */
|
|
44
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
|
|
45
|
+
export default class SettingsPage extends Cossack {
|
|
46
|
+
@Inject(SettingsDraft) private draft!: SettingsDraft;
|
|
47
|
+
view: SettingsView = server$(async (): Promise<SettingsView> => {
|
|
48
|
+
const cms = this.c.get('cms'), principal = this.c.get('principal');
|
|
49
|
+
const origin = new URL(this.c.req.url).origin;
|
|
50
|
+
const portable = new Set(cms.settings.catalog({ principal }).map(group => group.id));
|
|
51
|
+
const network = this.managesNetwork();
|
|
52
|
+
// The whole page in one round of reads: the groups share each choice source (roles, pages,
|
|
53
|
+
// categories are read once), and the plugin status, the snapshot and the other sections load alongside.
|
|
54
|
+
const choices: ChoiceCache = new Map();
|
|
55
|
+
const [status, snapshot, languages, networkData, rows] = await Promise.all([
|
|
56
|
+
cms.status(), settingsEditorSnapshot(cms, principal), loadLanguageSettings(cms, origin), network ? loadNetworkSettings(this.c.get('network')) : Promise.resolve(null),
|
|
57
|
+
Promise.all(cms.settings.groups.filter(group => group.id !== 'languages' && (group.permission ?? PERMISSIONS.manageSettings) === PERMISSIONS.manageSettings).map(async group => ({
|
|
58
|
+
id: group.id, label: group.label, description: group.description ?? '', plugin: group.plugin ?? '',
|
|
59
|
+
theme: cms.themes().some(theme => theme.name === group.plugin), portable: portable.has(group.id),
|
|
60
|
+
sections: group.sections ?? [], ...await settingRows(cms, group, principal, choices),
|
|
61
|
+
}))),
|
|
62
|
+
]);
|
|
63
|
+
const groups: GroupView[] = rows.map(group => ({ ...group, active: status.plugins.find(plugin => plugin.name === group.plugin)?.active ?? false }));
|
|
64
|
+
return { links: settingsLinks(cms, { network }), entries: settingsSearchEntries(cms, { network }), groups, snapshot: snapshot.document, invalid: snapshot.errors,
|
|
65
|
+
canUpload: !!cms.files && hasPermission(principal, PERMISSIONS.upload),
|
|
66
|
+
canBrowse: !!cms.files && [PERMISSIONS.upload, PERMISSIONS.manageMedia, PERMISSIONS.manageUsers].some(permission => hasPermission(principal, permission)),
|
|
67
|
+
languages, permalinks: loadPermalinkSettings(cms, origin), network: networkData };
|
|
68
|
+
}, { initial: { links: [], entries: [], groups: [], canUpload: false, canBrowse: false, snapshot: {}, invalid: {}, languages: null, permalinks: null, network: null } });
|
|
69
|
+
@ClientState() message = '';
|
|
70
|
+
@ClientState() error = '';
|
|
71
|
+
@ClientState() errors: Record<string, string> = {};
|
|
72
|
+
@ClientState() revision = 0;
|
|
73
|
+
@ClientState() target = 'general';
|
|
74
|
+
@ClientState() active = 'general';
|
|
75
|
+
private unsubscribe?: () => void;
|
|
76
|
+
private discards = 0;
|
|
77
|
+
private sectionElements = new Map<string, Element>();
|
|
78
|
+
private scrollFrame?: number;
|
|
79
|
+
/** The section being scrolled to: kept under the toolbar until the page above it stops changing size, then let go. */
|
|
80
|
+
private pendingTarget?: string;
|
|
81
|
+
private settleDeadline = 0;
|
|
82
|
+
private settleQuiet?: ReturnType<typeof setTimeout>;
|
|
83
|
+
private settle?: ResizeObserver;
|
|
84
|
+
private sectionsContainer?: Element;
|
|
85
|
+
|
|
86
|
+
head(): HeadValue { return { title: __('Settings') }; }
|
|
87
|
+
|
|
88
|
+
/** The network's settings belong to network admins, on its main site. Server only. */
|
|
89
|
+
private managesNetwork(): boolean {
|
|
90
|
+
return isNetworkAdmin(this.c.get('principal')) && this.c.get('site')?.id === MAIN_SITE;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onMount() {
|
|
94
|
+
this.draft.initialize(this.view.snapshot, this.view.invalid);
|
|
95
|
+
this.draft.navigated(window.location.pathname);
|
|
96
|
+
for (const group of this.view.groups.filter(group => !group.portable)) this.draft.initializeSection(group.id, group.values);
|
|
97
|
+
this.discards = this.draft.discards;
|
|
98
|
+
this.unsubscribe = this.draft.subscribe(() => {
|
|
99
|
+
// The toolbar's Discard also clears what the last save reported.
|
|
100
|
+
if (this.draft.discards !== this.discards) { this.discards = this.draft.discards; this.error = ''; this.message = ''; this.errors = {}; }
|
|
101
|
+
this.revision++; this.updateActiveSection();
|
|
102
|
+
});
|
|
103
|
+
this.revealHash();
|
|
104
|
+
this.updateActiveSection();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
onCleanup() { this.pendingTarget = undefined; clearTimeout(this.settleQuiet); this.settle?.disconnect(); this.unsubscribe?.(); if (this.scrollFrame !== undefined) cancelAnimationFrame(this.scrollFrame); }
|
|
108
|
+
|
|
109
|
+
/** The user took over the scrolling: the section being scrolled to is let go. */
|
|
110
|
+
@OnWindow('wheel')
|
|
111
|
+
@OnWindow('touchstart')
|
|
112
|
+
@OnWindow('pointerdown')
|
|
113
|
+
@OnWindow('keydown')
|
|
114
|
+
@Client()
|
|
115
|
+
cancelSectionJump() {
|
|
116
|
+
if (!this.pendingTarget) return;
|
|
117
|
+
this.pendingTarget = undefined;
|
|
118
|
+
clearTimeout(this.settleQuiet);
|
|
119
|
+
this.updateActiveSection();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Scroll a section under the toolbar. Every section is on the page at once, but the controls
|
|
124
|
+
* inside them render after their section connects (nested components), so the page above the
|
|
125
|
+
* section grows for a moment: the section is kept in place while the sections' container
|
|
126
|
+
* changes size, until it has been quiet for a moment, at most two seconds. A section that has
|
|
127
|
+
* not connected yet (the hash's, as the page arrives after a client navigation) is scrolled to
|
|
128
|
+
* when it does.
|
|
129
|
+
*/
|
|
130
|
+
@Client()
|
|
131
|
+
async scrollToSection(id: string) {
|
|
132
|
+
this.pendingTarget = id;
|
|
133
|
+
this.settleDeadline = performance.now() + 2000;
|
|
134
|
+
await this.requestUpdate();
|
|
135
|
+
this.realign();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Put the pending section under the toolbar (again). */
|
|
139
|
+
@Client()
|
|
140
|
+
private realign() {
|
|
141
|
+
const element = this.pendingTarget ? this.sectionElements.get(this.pendingTarget) : undefined;
|
|
142
|
+
if (!element) return;
|
|
143
|
+
element.scrollIntoView({ block: 'start', behavior: 'instant' });
|
|
144
|
+
clearTimeout(this.settleQuiet);
|
|
145
|
+
this.settleQuiet = setTimeout(() => { this.pendingTarget = undefined; this.updateActiveSection(); }, Math.max(0, Math.min(150, this.settleDeadline - performance.now())));
|
|
146
|
+
this.updateActiveSection();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The sections' container: its size changes while the page settles after a scroll. */
|
|
150
|
+
@Client()
|
|
151
|
+
trackContainer(element: Element | undefined) {
|
|
152
|
+
if (element === this.sectionsContainer) return;
|
|
153
|
+
this.settle?.disconnect();
|
|
154
|
+
this.sectionsContainer = element;
|
|
155
|
+
if (element && typeof ResizeObserver !== 'undefined') {
|
|
156
|
+
this.settle = new ResizeObserver(() => this.realign());
|
|
157
|
+
this.settle.observe(element);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@Client()
|
|
162
|
+
trackSection(id: string, element: Element | undefined) {
|
|
163
|
+
const previous = this.sectionElements.get(id);
|
|
164
|
+
if (previous === element) return;
|
|
165
|
+
if (element) this.sectionElements.set(id, element);
|
|
166
|
+
else this.sectionElements.delete(id);
|
|
167
|
+
if (element && this.pendingTarget === id) this.realign();
|
|
168
|
+
this.updateActiveSection();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@OnWindow('scroll')
|
|
172
|
+
@OnWindow('resize')
|
|
173
|
+
@Client()
|
|
174
|
+
updateActiveSection() {
|
|
175
|
+
if (this.scrollFrame !== undefined) return;
|
|
176
|
+
this.scrollFrame = requestAnimationFrame(() => {
|
|
177
|
+
this.scrollFrame = undefined;
|
|
178
|
+
const sections = this.view.links
|
|
179
|
+
.flatMap(link => {
|
|
180
|
+
const element = this.sectionElements.get(link.id);
|
|
181
|
+
return element?.isConnected ? [{ id: link.id, top: element.getBoundingClientRect().top }] : [];
|
|
182
|
+
});
|
|
183
|
+
const atEnd = window.scrollY > 0 && window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 2;
|
|
184
|
+
const active = activeSettingsSection(sections, this.draft.toolbarHeight + 24, atEnd) ?? '';
|
|
185
|
+
if (active !== this.active) this.active = active;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Scroll to the section the address names (`#settings-<group>`): on mount, when the address
|
|
191
|
+
* changes, and when a client navigation completes (`cossack:ready`): at mount the router has
|
|
192
|
+
* not committed the address yet, and its own scroll to the fragment lands before the sections'
|
|
193
|
+
* controls have rendered. The section is scrolled to when it connects (`trackSection`) and
|
|
194
|
+
* kept in place while the page settles.
|
|
195
|
+
*/
|
|
196
|
+
@OnWindow('hashchange')
|
|
197
|
+
@OnDocument('cossack:ready')
|
|
198
|
+
@Client()
|
|
199
|
+
async revealHash() {
|
|
200
|
+
let anchor = window.location.hash.slice(1);
|
|
201
|
+
try { anchor = decodeURIComponent(anchor); } catch { return; }
|
|
202
|
+
if (!anchor.startsWith('settings-')) return;
|
|
203
|
+
let id = '';
|
|
204
|
+
try { id = decodeURIComponent(anchor.slice('settings-'.length)); } catch { return; }
|
|
205
|
+
if (!id) return;
|
|
206
|
+
this.target = id;
|
|
207
|
+
await this.scrollToSection(id);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@PreventNavigation()
|
|
211
|
+
@Client()
|
|
212
|
+
confirmLeave(): boolean { return this.draft.preventNavigation(); }
|
|
213
|
+
|
|
214
|
+
@Client()
|
|
215
|
+
async openSection(event: MouseEvent) {
|
|
216
|
+
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
217
|
+
const url = new URL((event.currentTarget as HTMLAnchorElement).href, window.location.href);
|
|
218
|
+
if (url.pathname !== '/dashboard/settings') { settingsNavigation(event); return; }
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
const anchor = decodeURIComponent(url.hash.slice(1));
|
|
221
|
+
const link = this.view.links.find(link => settingsSectionId(link.id) === anchor);
|
|
222
|
+
if (!link) return;
|
|
223
|
+
this.target = link.id;
|
|
224
|
+
this.active = link.id;
|
|
225
|
+
if ((event.currentTarget as HTMLElement).hasAttribute('data-settings-error-group') || !filterSettingsLinks(this.view.links, this.view.entries, this.draft.search).some(entry => entry.id === link.id)) this.draft.setSearch('');
|
|
226
|
+
if (window.location.hash !== url.hash) history.pushState(history.state, '', url.hash);
|
|
227
|
+
await this.scrollToSection(link.id);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@Client()
|
|
231
|
+
set(group: GroupView, row: SettingRow, value: SettingValue) {
|
|
232
|
+
if (this.draft.saving) return;
|
|
233
|
+
if (group.portable) this.draft.set(row, value);
|
|
234
|
+
else this.draft.setSection(group.id, { ...this.draft.section(group.id, group.values), [row.name]: value });
|
|
235
|
+
this.message = '';
|
|
236
|
+
const errors = { ...this.errors }; delete errors[`${group.id}.${row.name}`]; this.errors = errors;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@Client()
|
|
240
|
+
async submit(event: Event) {
|
|
241
|
+
event.preventDefault(); this.error = ''; this.message = '';
|
|
242
|
+
if (this.draft.saving || this.draft.jsonError || Object.keys(this.draft.errors).length || this.draft.preview?.imported || !this.draft.dirty()) return;
|
|
243
|
+
const changes = this.draft.changes();
|
|
244
|
+
const languages = this.view.languages && this.draft.sectionDirty('languages') ? languageInput(this.draft, this.view.languages) : null;
|
|
245
|
+
const permalinks = this.view.permalinks && this.draft.sectionDirty('permalinks') ? this.draft.section('permalinks', permalinkDraft(this.view.permalinks)) : null;
|
|
246
|
+
const network = this.view.network && this.draft.sectionDirty('network') ? this.draft.section('network', networkDraft(this.view.network)) : null;
|
|
247
|
+
const groups = Object.fromEntries(this.view.groups.filter(group => !group.portable && this.draft.sectionDirty(group.id)).map(group => [group.id, this.draft.section(group.id, group.values)]));
|
|
248
|
+
this.draft.setSaving(true);
|
|
249
|
+
try {
|
|
250
|
+
const result = await this.saveAll({ document: Object.keys(changes).length ? changes : null, languages, permalinks, network, groups });
|
|
251
|
+
if (result.document) this.draft.accept(result.document);
|
|
252
|
+
if (result.languages) this.draft.acceptSection('languages', languageDraft(result.languages));
|
|
253
|
+
if (result.permalinks) this.draft.acceptSection('permalinks', permalinkDraft(result.permalinks));
|
|
254
|
+
if (result.network) this.draft.acceptSection('network', networkDraft(result.network));
|
|
255
|
+
// Network appears in, or leaves, the dashboard menu.
|
|
256
|
+
if (result.network && result.network.enabled !== this.view.network?.enabled && !result.error) { window.location.reload(); return; }
|
|
257
|
+
// Interface settings restyle the dashboard itself (palettes, icon sprites): show them at once.
|
|
258
|
+
if (changes.interface && result.document && !result.error) { window.location.reload(); return; }
|
|
259
|
+
for (const id of result.groups) this.draft.acceptSection(id, groups[id]);
|
|
260
|
+
this.error = result.error; this.errors = result.fields;
|
|
261
|
+
if (!result.error) this.message = __('Settings saved.');
|
|
262
|
+
} catch { this.error = __('The settings could not be saved. Your draft is kept.'); }
|
|
263
|
+
finally { this.draft.setSaving(false); }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@Server()
|
|
267
|
+
async findMedia(search: string, kind: string) { return findSettingsMedia(this.c.get('cms'), this.c.get('principal'), search, kind); }
|
|
268
|
+
|
|
269
|
+
/** One save for the whole page: the document first, then Languages, Permalinks, Network and the groups outside the document. */
|
|
270
|
+
@Server({ input: input.args(input.record<SaveInput>()) })
|
|
271
|
+
async saveAll(input: SaveInput): Promise<SaveResult> {
|
|
272
|
+
const cms = this.c.get('cms'), principal = this.c.get('principal'), origin = new URL(this.c.req.url).origin;
|
|
273
|
+
const result: SaveResult = { document: null, languages: null, permalinks: null, network: null, groups: [], error: '', fields: {} };
|
|
274
|
+
const failed = (section: string, error: string, fields: Record<string, string> = {}) => ({ ...result, error: `${section}: ${error}`, fields });
|
|
275
|
+
if (input.document) {
|
|
276
|
+
try { result.document = await cms.settings.applyDocument(input.document, { principal }); }
|
|
277
|
+
catch (error) { return { ...result, error: isCmsError(error) ? error.message : __('The settings could not be saved.'), fields: isCmsError(error) ? { ...error.fields } : {} }; }
|
|
278
|
+
}
|
|
279
|
+
if (input.languages) {
|
|
280
|
+
const saved = await saveLanguageSettings(cms, principal, input.languages, origin);
|
|
281
|
+
if (!saved.data) return failed(__('Languages'), saved.error);
|
|
282
|
+
result.languages = saved.data;
|
|
283
|
+
}
|
|
284
|
+
if (input.permalinks) {
|
|
285
|
+
const saved = await savePermalinkSettings(cms, principal, input.permalinks, origin);
|
|
286
|
+
if (!saved.data) return failed(__('Permalinks'), saved.error, Object.fromEntries(Object.entries(saved.fields).map(([name, error]) => [`permalinks.${name}`, error])));
|
|
287
|
+
result.permalinks = saved.data;
|
|
288
|
+
}
|
|
289
|
+
if (input.network) {
|
|
290
|
+
if (!this.managesNetwork()) return failed(__('Network'), __('Only network admins change the network, on its main site.'));
|
|
291
|
+
const saved = await saveNetworkSettings(this.c.get('network'), principal, input.network);
|
|
292
|
+
if (!saved.data) return failed(__('Network'), saved.error, Object.fromEntries(Object.entries(saved.fields).map(([name, error]) => [`network.${name}`, error])));
|
|
293
|
+
result.network = saved.data;
|
|
294
|
+
}
|
|
295
|
+
for (const [id, values] of Object.entries(input.groups ?? {})) {
|
|
296
|
+
const group = cms.settings.groups.find(group => group.id === id && !group.plugin && group.id !== 'languages' && (group.permission ?? PERMISSIONS.manageSettings) === PERMISSIONS.manageSettings);
|
|
297
|
+
if (!group) return failed(id, __('These settings do not exist.'));
|
|
298
|
+
const { input: valid, errors } = settingInput(group, values);
|
|
299
|
+
if (Object.keys(errors).length) return failed(group.label, __('Some settings are invalid.'), Object.fromEntries(Object.entries(errors).map(([name, value]) => [`${id}.${name}`, value])));
|
|
300
|
+
try { await cms.settings.update(id, valid, { principal }); }
|
|
301
|
+
catch (error) { return failed(group.label, isCmsError(error) ? error.message : __('The settings could not be saved.'), isCmsError(error) ? Object.fromEntries(Object.entries(error.fields ?? {}).map(([name, value]) => [`${id}.${name}`, value])) : {}); }
|
|
302
|
+
result.groups.push(id);
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@Shared()
|
|
308
|
+
groupContent(group: GroupView, fields: Set<string>, blocked: boolean): TemplateResult {
|
|
309
|
+
const controls = html`<fieldset class="min-w-0 space-y-5" ?disabled=${this.draft.saving || (group.portable && blocked)}>
|
|
310
|
+
${[{ id: '', label: '', description: '' }, ...group.sections].map(section => {
|
|
311
|
+
const rows = group.rows.filter(row => row.section === section.id && fields.has(`${group.id}.${row.name}`));
|
|
312
|
+
return rows.length ? html`<fieldset class="min-w-0 space-y-4">
|
|
313
|
+
${section.label ? html`<legend class="mb-3 text-sm font-semibold">${section.label}</legend>` : null}
|
|
314
|
+
${section.description ? html`<p class="text-sm text-muted-foreground">${section.description}</p>` : null}
|
|
315
|
+
${repeat(rows, row => row.name, row => settingControl(row, group.portable ? this.draft.control(row, group.values[row.name]) : this.draft.section(group.id, group.values)[row.name],
|
|
316
|
+
this.draft.errors[`${group.id}.${row.name}`] ?? this.errors[`${group.id}.${row.name}`], value => this.set(group, row, value),
|
|
317
|
+
this.view.canBrowse ? { find: this.findMedia, canUpload: this.view.canUpload, epoch: () => this.draft.epoch } : undefined))}
|
|
318
|
+
</fieldset>` : null;
|
|
319
|
+
})}
|
|
320
|
+
</fieldset>`;
|
|
321
|
+
return component(Card, group.plugin ? { 'data-plugin-settings': group.plugin } : {}, component(CardBody, {}, controls));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
render() {
|
|
325
|
+
const matches = searchSettings(this.view.entries, this.draft.search);
|
|
326
|
+
const fields = new Set(matches.map(entry => entry.id));
|
|
327
|
+
const blocked = !!this.draft.jsonError || !!this.draft.preview?.imported;
|
|
328
|
+
const ordered = filterSettingsLinks(this.view.links, this.view.entries, this.draft.search);
|
|
329
|
+
const permalinkErrors = Object.fromEntries(Object.entries(this.errors).filter(([key]) => key.startsWith('permalinks.')).map(([key, error]) => [key.slice(11), error]));
|
|
330
|
+
const networkErrors = Object.fromEntries(Object.entries(this.errors).filter(([key]) => key.startsWith('network.')).map(([key, error]) => [key.slice(8), error]));
|
|
331
|
+
return settingsFrame(this.view.links, this.active, html`<div class="min-w-0 space-y-8" ref=${this.trackContainer}>
|
|
332
|
+
<form id="settings-actions" hidden @submit=${this.submit}></form>
|
|
333
|
+
<div class="space-y-4">
|
|
334
|
+
${this.draft.search.trim() ? html`<p role="status" data-settings-results class="text-sm text-muted-foreground">${matches.length ? matches.length === 1 ? __('1 setting found') : `${matches.length} ${__('settings found')}` : __('No settings match your search.')}</p>` : null}
|
|
335
|
+
${this.message ? notice(this.message, 'success') : null}${this.error ? notice(this.error, 'error') : null}
|
|
336
|
+
${settingsErrorSummary({ ...this.errors, ...this.draft.errors }, this.openSection)}
|
|
337
|
+
${Object.keys(this.draft.initialized ? this.draft.baselineErrors : this.view.invalid).length ? notice(__('Some saved values no longer match their declarations. Set a valid value for each affected field before saving.'), 'error') : null}
|
|
338
|
+
${blocked ? html`<div role="alert">${notice(__('Fix the JSON draft, or resolve its import preview, before editing fields.'), 'error')}<a href="/dashboard/settings/json" @click=${settingsNavigation} class="text-sm text-primary underline">${__('Open JSON draft')}</a></div>` : null}
|
|
339
|
+
${this.draft.dirty() ? html`<p role="status" class="text-xs text-muted-foreground">${__('Unsaved changes, including settings hidden by search.')}</p>` : null}
|
|
340
|
+
</div>
|
|
341
|
+
${repeat(ordered, link => link.id, link => {
|
|
342
|
+
if (link.id === 'plugins') return html`<div id=${settingsSectionId('plugins')} ref=${(element: Element | undefined) => this.trackSection('plugins', element)} class="space-y-2" style="scroll-margin-top:calc(var(--settings-toolbar-height, 56px) + 24px)"><h2 class="text-xl font-semibold">${__('Plugins')}</h2><a href="/dashboard/plugins" class="text-sm text-primary hover:underline">${__('Manage plugins')}</a>
|
|
343
|
+
${this.view.groups.some(group => group.plugin) ? null : html`<p class="text-sm text-muted-foreground">${__('No installed plugins declare settings.')}</p>`}</div>`;
|
|
344
|
+
const group = this.view.groups.find(group => group.id === link.id);
|
|
345
|
+
const keys = matches.filter(entry => entry.groupId === link.id).map(entry => entry.id);
|
|
346
|
+
const heading = html`<div class="space-y-2"><div class="flex flex-wrap items-center gap-2"><h2 class="text-lg font-semibold">${link.label}</h2>
|
|
347
|
+
${group?.plugin ? component(Badge, { variant: group.active ? 'success' : 'secondary' }, group.active ? __('Enabled') : __('Disabled')) : null}</div>
|
|
348
|
+
${group?.description ? html`<p class="text-sm text-muted-foreground">${group.description}</p>` : null}
|
|
349
|
+
${group?.plugin ? html`<p class="text-xs text-muted-foreground">${group.plugin}</p>` : null}
|
|
350
|
+
${group?.theme ? html`<a href="/dashboard/appearance/customize" class="text-sm text-primary hover:underline">${__('Theme customization')}</a>` : null}</div>`;
|
|
351
|
+
return component(SettingsSection, { id: link.id, heading, onConnect: this.trackSection,
|
|
352
|
+
content: () => link.id === 'languages' && this.view.languages ? component(LanguagesSettings, { draft: this.draft, initial: this.view.languages, fields: keys })
|
|
353
|
+
: link.id === 'permalinks' && this.view.permalinks ? component(PermalinksSettings, { draft: this.draft, initial: this.view.permalinks, fields: keys, errors: permalinkErrors })
|
|
354
|
+
: link.id === 'network' && this.view.network ? component(NetworkSettingsForm, { draft: this.draft, initial: this.view.network, fields: keys, errors: networkErrors })
|
|
355
|
+
: group && keys.length ? this.groupContent(group, fields, blocked) : html`` });
|
|
356
|
+
})}
|
|
357
|
+
</div>`, { entries: this.view.entries, query: this.draft.search, onNavigate: this.openSection });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Client, ClientState, Cossack, Inject, Page, PreventNavigation, Server, server$, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { Button, Card, CardBody, CodeEditor } from '@cossackframework/ui';
|
|
3
|
+
import { component, html, key } from '@cossackframework/renderer';
|
|
4
|
+
import { isCmsError, isNetworkAdmin, MAIN_SITE, parseSettingsDocument, PERMISSIONS, SETTINGS_DOCUMENT_MAX_BYTES, SETTINGS_DOCUMENT_MAX_FIELDS, settingsJsonSchema, stringifySettingsDocument, type SettingsDocument } from '@cossackframework/cms';
|
|
5
|
+
import { requireAny } from '#app/cms/guards';
|
|
6
|
+
import { formatSettingsDraft, mergeSettings, settingsChanges, SettingsDraft, settingsNavigation } from '#app/cms/settings-draft';
|
|
7
|
+
import { settingsEditorSnapshot } from '#app/cms/settings-form';
|
|
8
|
+
import { settingsErrorSummary, settingsFrame, settingsLinks, type SettingsLink } from '#app/cms/settings-nav';
|
|
9
|
+
import { notice, pageHeader } from '#app/cms/ui';
|
|
10
|
+
import { settingsSearchEntries, type SettingsSearchEntry } from '#app/cms/settings-search';
|
|
11
|
+
|
|
12
|
+
interface JsonSettingsView { links: SettingsLink[]; entries: SettingsSearchEntry[]; snapshot: SettingsDocument; invalid: Record<string, string>; schema: object; references: string[] }
|
|
13
|
+
interface PreviewResult { before: SettingsDocument; after: SettingsDocument; patch: SettingsDocument; error: string; fields: Record<string, string> }
|
|
14
|
+
const EDITOR_CLASS = 'rounded-md border border-input bg-background [&_.cm-editor]:h-[60vh] [&_.cm-editor]:max-h-[36rem] [&_.cm-scroller]:overflow-auto [&_pre]:max-h-[60vh] [&_pre]:overflow-auto';
|
|
15
|
+
|
|
16
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
|
|
17
|
+
export default class JsonSettingsPage extends Cossack {
|
|
18
|
+
@Inject(SettingsDraft) private draft!: SettingsDraft;
|
|
19
|
+
view: JsonSettingsView = server$(async () => {
|
|
20
|
+
const cms = this.c.get('cms');
|
|
21
|
+
const principal = this.c.get('principal');
|
|
22
|
+
const groups = cms.settings.catalog({ principal });
|
|
23
|
+
const snapshot = await settingsEditorSnapshot(cms, principal);
|
|
24
|
+
// The Network section's link, as on Settings.
|
|
25
|
+
const network = isNetworkAdmin(principal) && this.c.get('site')?.id === MAIN_SITE;
|
|
26
|
+
return { links: settingsLinks(cms, { network }), entries: settingsSearchEntries(cms, { network }), snapshot: snapshot.document, invalid: snapshot.errors, schema: settingsJsonSchema(groups),
|
|
27
|
+
references: groups.flatMap(group => Object.entries(group.fields).filter(([, field]) => field.control === 'file' || field.source && ['roles', 'pages', 'categories', 'media'].includes(field.source)).map(([name]) => `${group.id}.${name}`)) };
|
|
28
|
+
}, { initial: { links: [], entries: [], snapshot: {}, invalid: {}, schema: {}, references: [] } });
|
|
29
|
+
@ClientState() error = '';
|
|
30
|
+
@ClientState() errors: Record<string, string> = {};
|
|
31
|
+
@ClientState() message = '';
|
|
32
|
+
@ClientState() draftRevision = 0;
|
|
33
|
+
private unsubscribeDraft?: () => void;
|
|
34
|
+
|
|
35
|
+
head(): HeadValue { return { title: __('Settings JSON') }; }
|
|
36
|
+
|
|
37
|
+
onMount() {
|
|
38
|
+
this.draft.navigated(window.location.pathname);
|
|
39
|
+
this.draft.initialize(this.view.snapshot, this.view.invalid);
|
|
40
|
+
this.unsubscribeDraft = this.draft.subscribe(() => { this.draftRevision++; });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onCleanup() { this.unsubscribeDraft?.(); }
|
|
44
|
+
|
|
45
|
+
@PreventNavigation()
|
|
46
|
+
@Client()
|
|
47
|
+
confirmLeave(): boolean { return this.draft.preventNavigation(); }
|
|
48
|
+
|
|
49
|
+
@Client()
|
|
50
|
+
edit(text: string) {
|
|
51
|
+
this.draft.editJson(text);
|
|
52
|
+
this.error = '';
|
|
53
|
+
this.errors = {};
|
|
54
|
+
this.message = '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Client()
|
|
58
|
+
async submit(event: Event) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
if (this.draft.saving) return;
|
|
61
|
+
if (this.draft.preview) await this.applyChanges();
|
|
62
|
+
else await this.previewChanges();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Client()
|
|
66
|
+
async previewChanges() {
|
|
67
|
+
if (this.draft.jsonError || Object.keys(this.draft.errors).length) return;
|
|
68
|
+
try { await this.showPreview(stringifySettingsDocument(this.draft.changes()), false); }
|
|
69
|
+
catch (error) { this.error = error instanceof Error ? error.message : __('The settings could not be checked.'); }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Client()
|
|
73
|
+
async importFile(event: Event) {
|
|
74
|
+
const input = event.target as HTMLInputElement;
|
|
75
|
+
const file = input.files?.[0];
|
|
76
|
+
input.value = '';
|
|
77
|
+
if (!file) return;
|
|
78
|
+
this.message = '';
|
|
79
|
+
this.error = '';
|
|
80
|
+
if (this.draft.dirty()) { this.error = __('Save the current draft before importing a file.'); return; }
|
|
81
|
+
if (file.size > SETTINGS_DOCUMENT_MAX_BYTES) { this.error = __('The settings file exceeds the supported size limit.'); return; }
|
|
82
|
+
try { await this.showPreview(await file.text(), true); }
|
|
83
|
+
catch { this.error = __('The settings file could not be read.'); }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Client()
|
|
87
|
+
async showPreview(text: string, imported: boolean) {
|
|
88
|
+
if (this.draft.saving) return;
|
|
89
|
+
this.draft.setSaving(true);
|
|
90
|
+
this.error = '';
|
|
91
|
+
this.errors = {};
|
|
92
|
+
this.message = '';
|
|
93
|
+
const source = this.draft.rawJson;
|
|
94
|
+
try {
|
|
95
|
+
// Parse on both sides: immediate local size/syntax feedback and an authoritative server check.
|
|
96
|
+
parseSettingsDocument(text);
|
|
97
|
+
const result = await this.preview(text, imported);
|
|
98
|
+
if (source !== this.draft.rawJson) { this.error = __('The draft changed while it was checked. Preview the current changes again.'); return; }
|
|
99
|
+
this.error = result.error;
|
|
100
|
+
this.errors = result.fields;
|
|
101
|
+
this.draft.setPreview(result.error ? null : { before: result.before, after: result.after, patch: result.patch, imported });
|
|
102
|
+
} catch (error) { this.error = error instanceof Error ? error.message : __('The settings could not be checked.'); }
|
|
103
|
+
finally { this.draft.setSaving(false); }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Client()
|
|
107
|
+
cancelPreview() { this.draft.setPreview(null); this.error = ''; this.errors = {}; }
|
|
108
|
+
|
|
109
|
+
@Client()
|
|
110
|
+
openError(event: MouseEvent) {
|
|
111
|
+
settingsNavigation(event);
|
|
112
|
+
// Keep the link's DOM intact until the document router consumes the click.
|
|
113
|
+
if (!event.defaultPrevented && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) setTimeout(() => this.draft.setSearch(''), 0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Client()
|
|
117
|
+
async applyChanges() {
|
|
118
|
+
const preview = this.draft.preview;
|
|
119
|
+
if (!preview || this.draft.saving) return;
|
|
120
|
+
this.draft.setSaving(true);
|
|
121
|
+
this.error = '';
|
|
122
|
+
this.message = '';
|
|
123
|
+
try {
|
|
124
|
+
const result = await this.apply(preview.patch);
|
|
125
|
+
this.error = result.error;
|
|
126
|
+
this.errors = result.fields;
|
|
127
|
+
if (result.document) { this.draft.accept(result.document); this.message = __('Settings saved.'); }
|
|
128
|
+
} catch { this.error = __('The settings could not be saved. Your draft is kept.'); }
|
|
129
|
+
finally { this.draft.setSaving(false); }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Client()
|
|
133
|
+
async exportSaved() {
|
|
134
|
+
this.error = '';
|
|
135
|
+
try {
|
|
136
|
+
const text = await this.download();
|
|
137
|
+
const url = URL.createObjectURL(new Blob([text], { type: 'application/json' }));
|
|
138
|
+
const link = document.createElement('a');
|
|
139
|
+
link.href = url;
|
|
140
|
+
link.download = 'settings.json';
|
|
141
|
+
link.click();
|
|
142
|
+
URL.revokeObjectURL(url);
|
|
143
|
+
} catch (error) { this.error = error instanceof Error ? error.message : __('The saved settings could not be exported.'); }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@Server()
|
|
147
|
+
async preview(text: string, imported = false): Promise<PreviewResult> {
|
|
148
|
+
try {
|
|
149
|
+
const settings = this.c.get('cms').settings;
|
|
150
|
+
const context = { principal: this.c.get('principal') };
|
|
151
|
+
const proposed = settings.validateDocument(parseSettingsDocument(text), context);
|
|
152
|
+
settings.refresh();
|
|
153
|
+
const before = (await settingsEditorSnapshot(this.c.get('cms'), context.principal)).document;
|
|
154
|
+
const patch = imported ? proposed : settingsChanges(before, proposed);
|
|
155
|
+
return { before, after: mergeSettings(before, patch), patch, error: '', fields: {} };
|
|
156
|
+
} catch (error) { return { before: {}, after: {}, patch: {}, error: isCmsError(error) ? error.message : __('The settings could not be checked.'), fields: isCmsError(error) ? { ...error.fields } : {} }; }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@Server()
|
|
160
|
+
async apply(document: SettingsDocument): Promise<{ document: SettingsDocument | null; error: string; fields: Record<string, string> }> {
|
|
161
|
+
try { return { document: await this.c.get('cms').settings.applyDocument(document, { principal: this.c.get('principal') }), error: '', fields: {} }; }
|
|
162
|
+
catch (error) { return { document: null, error: isCmsError(error) ? error.message : __('The settings could not be saved.'), fields: isCmsError(error) ? { ...error.fields } : {} }; }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Server()
|
|
166
|
+
async download(): Promise<string> { return this.c.get('cms').settings.exportDocument({ principal: this.c.get('principal') }); }
|
|
167
|
+
|
|
168
|
+
render() {
|
|
169
|
+
const preview = this.draft.preview;
|
|
170
|
+
const busy = this.draft.saving;
|
|
171
|
+
const text = this.draft.initialized ? this.draft.rawJson : formatSettingsDraft(this.view.snapshot);
|
|
172
|
+
const invalid = this.draft.initialized ? this.draft.baselineErrors : this.view.invalid;
|
|
173
|
+
const references = preview ? this.view.references.filter(path => Object.entries(preview.patch).some(([group, fields]) => Object.keys(fields).some(name => `${group}.${name}` === path))) : [];
|
|
174
|
+
return settingsFrame(this.view.links, 'json', html`<div class="space-y-5">
|
|
175
|
+
<form id="settings-actions" hidden @submit=${this.submit}></form>
|
|
176
|
+
${pageHeader(__('Settings JSON'), { description: __('Edit settings as namespace and field pairs. Missing fields keep their saved values.') })}
|
|
177
|
+
<p class="text-sm text-muted-foreground">${__('Appearance, theme options, Languages, Permalinks, and server credentials use their own save operations and are excluded. This file is not a full site backup.')}</p>
|
|
178
|
+
<p class="text-xs text-muted-foreground">${__('Maximum JSON file size')}: ${Math.floor(SETTINGS_DOCUMENT_MAX_BYTES / 1024)} KiB; ${SETTINGS_DOCUMENT_MAX_FIELDS} ${__('fields')}. ${__('Only strings, numbers, booleans, and declared null values are supported.')}</p>
|
|
179
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
180
|
+
${component(Button, { type: 'button', variant: 'outline', disabled: !!this.loading.download, '@click': this.exportSaved }, __('Export saved settings'))}
|
|
181
|
+
<label class="text-sm font-medium">${__('Import settings JSON')}<input type="file" accept=".json,application/json" aria-label=${__('Import settings JSON')} class="mt-1 block max-w-full text-sm" ?disabled=${busy} @change=${this.importFile}></label>
|
|
182
|
+
</div>
|
|
183
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
184
|
+
${this.error || this.draft.jsonError ? notice(this.error || this.draft.jsonError, 'error') : null}
|
|
185
|
+
${Object.keys(invalid).length ? html`<div role="alert">${notice(__('Some saved values no longer match their declarations. Add corrected values for these omitted fields before saving.'), 'error')}<ul class="mt-2 text-sm">${Object.keys(invalid).map(path => html`<li><code>${path}</code></li>`)}</ul></div>` : null}
|
|
186
|
+
${settingsErrorSummary(this.errors, this.openError)}
|
|
187
|
+
${this.draft.hasInvalidControls() ? html`<div role="alert">${notice(__('Fix the invalid form values before editing JSON.'), 'error')}<a href="/dashboard/settings" @click=${settingsNavigation} class="text-sm text-primary underline">${__('Open settings')}</a></div>` : null}
|
|
188
|
+
${preview ? component(Card, {}, component(CardBody, { class: 'space-y-4' }, html`
|
|
189
|
+
<h2 class="font-semibold">${__('Review changes')}</h2>
|
|
190
|
+
<p class="text-sm text-muted-foreground">${__('Nothing is saved until you apply these changes.')}</p>
|
|
191
|
+
${preview.imported ? html`<p class="text-sm text-muted-foreground">${__('Every supplied value is saved explicitly, including unchanged defaults.')}</p>` : null}
|
|
192
|
+
${references.length ? html`<p role="status" class="text-sm text-muted-foreground">${__('These references are copied as stored and are not remapped to this site')}: ${references.join(', ')}.</p>` : null}
|
|
193
|
+
${key(formatSettingsDraft(preview.patch), component(CodeEditor, { id: 'settings-json-diff', language: 'json', label: __('Settings changes'), class: EDITOR_CLASS, original: formatSettingsDraft(preview.before), value: formatSettingsDraft(preview.after) }))}
|
|
194
|
+
${component(Button, { type: 'button', variant: 'outline', disabled: busy, '@click': this.cancelPreview }, __('Cancel preview'))}
|
|
195
|
+
${Object.keys(preview.patch).length ? null : html`<p role="status" class="text-sm text-muted-foreground">${__('No settings would change.')}</p>`}
|
|
196
|
+
`)) : html`
|
|
197
|
+
${key(busy || this.draft.hasInvalidControls(), component(CodeEditor, { id: 'settings-json-editor', language: 'json', label: __('Settings JSON'), value: text, schema: this.view.schema,
|
|
198
|
+
readOnly: busy || this.draft.hasInvalidControls(), class: EDITOR_CLASS, onChange: this.edit }))}
|
|
199
|
+
`}
|
|
200
|
+
</div>`, { entries: this.view.entries, query: this.draft.search });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Client, ClientState, Cossack, Inject, Page } from '@cossackframework/core';
|
|
2
|
+
import { Button, Icon, Input } from '@cossackframework/ui';
|
|
3
|
+
import { component, html } from '@cossackframework/renderer';
|
|
4
|
+
import { PERMISSIONS } from '@cossackframework/cms';
|
|
5
|
+
import { requireAny } from '#app/cms/guards';
|
|
6
|
+
import { icon } from '#app/cms/icons';
|
|
7
|
+
import { SettingsDraft, settingsNavigation } from '#app/cms/settings-draft';
|
|
8
|
+
|
|
9
|
+
/** This scope survives Settings navigation and disposes its client draft on exit. */
|
|
10
|
+
@Page({ transport: 'http', services: [SettingsDraft], middlewares: [requireAny(PERMISSIONS.manageSettings)] })
|
|
11
|
+
export default class SettingsLayout extends Cossack {
|
|
12
|
+
@Inject(SettingsDraft) private draft!: SettingsDraft;
|
|
13
|
+
@ClientState() revision = 0;
|
|
14
|
+
private unsubscribe?: () => void;
|
|
15
|
+
private toolbar?: HTMLElement;
|
|
16
|
+
private resize?: ResizeObserver;
|
|
17
|
+
|
|
18
|
+
onMount() { this.draft.navigated(window.location.pathname); this.unsubscribe = this.draft.subscribe(() => { this.revision++; }); }
|
|
19
|
+
onCleanup() { this.unsubscribe?.(); this.resize?.disconnect(); }
|
|
20
|
+
|
|
21
|
+
@Client()
|
|
22
|
+
connectToolbar(element: HTMLElement | undefined) {
|
|
23
|
+
if (element === this.toolbar) return;
|
|
24
|
+
this.resize?.disconnect();
|
|
25
|
+
this.toolbar = element;
|
|
26
|
+
if (!element) return;
|
|
27
|
+
const measure = () => this.draft.setToolbarHeight(Math.ceil(element.getBoundingClientRect().height));
|
|
28
|
+
measure();
|
|
29
|
+
if (typeof ResizeObserver !== 'undefined') { this.resize = new ResizeObserver(measure); this.resize.observe(element); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Client()
|
|
33
|
+
discard() { if (!this.draft.saving) this.draft.discard(); }
|
|
34
|
+
|
|
35
|
+
@Client()
|
|
36
|
+
searchKey(event: KeyboardEvent) {
|
|
37
|
+
if (event.key === 'Escape') { this.draft.setSearch(''); event.preventDefault(); }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
render() {
|
|
41
|
+
const json = this.isActive('/dashboard/settings/json');
|
|
42
|
+
const preview = json ? this.draft.preview : null;
|
|
43
|
+
const blocked = !!this.draft.jsonError || Object.keys(this.draft.errors).length > 0 || (!json && !!this.draft.preview?.imported);
|
|
44
|
+
return html`<div data-subnav class="flex min-h-screen min-w-0 flex-col" style=${`--settings-toolbar-height:${this.draft.toolbarHeight}px`}>
|
|
45
|
+
<header ref=${this.connectToolbar} data-settings-toolbar class="sticky top-0 z-20 flex min-h-14 flex-wrap items-center gap-3 border-b border-border bg-background px-4 py-3 md:flex-nowrap md:gap-0 md:px-0 md:py-0">
|
|
46
|
+
<h1 class="w-full shrink-0 text-sm font-semibold md:w-52 md:px-4">${__('Settings')}</h1>
|
|
47
|
+
<div class="flex min-w-0 basis-full flex-wrap items-center gap-2 py-1 md:flex-1 md:basis-auto md:px-6">
|
|
48
|
+
<div class="min-w-36 flex-1" @keydown=${this.searchKey}>
|
|
49
|
+
${component(Input, { type: 'search', 'aria-label': __('Search settings'), placeholder: __('Search settings'),
|
|
50
|
+
'.value': this.draft.search, '@input': (event: Event) => this.draft.setSearch((event.target as HTMLInputElement).value) })}
|
|
51
|
+
</div>
|
|
52
|
+
<a href="/dashboard/settings/json" @click=${settingsNavigation} aria-label=${__('Edit settings JSON')} title=${__('Edit settings JSON')}
|
|
53
|
+
aria-current=${json ? 'page' : 'false'}
|
|
54
|
+
class=${`inline-flex size-9 shrink-0 items-center justify-center rounded-md border border-border no-underline hover:bg-muted focus-visible:outline-2 focus-visible:outline-ring ${json ? 'bg-muted text-foreground' : 'text-muted-foreground'}`}>
|
|
55
|
+
<span aria-hidden="true">${component(Icon, { entry: icon('code-square'), size: 18 })}</span>
|
|
56
|
+
</a>
|
|
57
|
+
<div class="ms-auto flex shrink-0 items-center gap-2" data-settings-actions>
|
|
58
|
+
${this.draft.dirty() ? component(Button, { type: 'button', variant: 'outline', disabled: this.draft.saving, '@click': this.discard }, __('Discard changes')) : null}
|
|
59
|
+
${component(Button, { type: 'submit', form: 'settings-actions', disabled: this.draft.saving || blocked || (preview ? !Object.keys(preview.patch).length : json ? !this.draft.documentDirty() : !this.draft.dirty()) },
|
|
60
|
+
this.draft.saving ? __('Working…') : json ? preview ? __('Apply changes') : __('Preview changes') : __('Save changes'))}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</header>
|
|
64
|
+
${this.children}
|
|
65
|
+
</div>`;
|
|
66
|
+
}
|
|
67
|
+
}
|