@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,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forms for settings groups: Settings screens and Appearance → Customize render a group's
|
|
3
|
+
* fields with these. Rows and values are plain data; the server converts them back.
|
|
4
|
+
*/
|
|
5
|
+
import { Checkbox, ColorPicker, Field, Input, NativeSelect, Textarea, UI_PALETTES, type FieldControlAttributes } from '@cossackframework/ui';
|
|
6
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { CmsError, hasPermission, iconHref, isCmsError, isIconStyle, PERMISSIONS, recordTitle, type FieldMediaKind, type Principal, type SettingControl, type SettingDeclaration, type SettingsDocument, type SettingsGroup } from '@cossackframework/cms';
|
|
8
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
9
|
+
import { findMedia } from './content';
|
|
10
|
+
import { SettingsFile, type SettingsMedia } from './settings-file';
|
|
11
|
+
|
|
12
|
+
export interface SettingRow { name: string; namespace: string; label: string; description: string; kind: string; min: number | null; max: number | null; choices: { value: string; label: string }[]; required: boolean; nullable: boolean; section: string; control?: SettingControl; fileKinds?: readonly FieldMediaKind[] }
|
|
13
|
+
export type SettingValue = string | boolean | null;
|
|
14
|
+
export type SettingValues = Record<string, SettingValue>;
|
|
15
|
+
|
|
16
|
+
/** Permit repairing an incompatible override without sending unrelated settings to the browser. */
|
|
17
|
+
export async function settingsEditorSnapshot(cms: CmsHost, principal: Principal): Promise<{ document: SettingsDocument; errors: Record<string, string> }> {
|
|
18
|
+
try { return { document: await cms.settings.snapshot({ principal }), errors: {} }; }
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (!isCmsError(error, 'CMS_VALIDATION') || !error.fields) throw error;
|
|
21
|
+
cms.settings.refresh();
|
|
22
|
+
const stored = await cms.settings.all();
|
|
23
|
+
const document: SettingsDocument = {};
|
|
24
|
+
for (const group of cms.settings.catalog({ principal })) for (const [name, declaration] of Object.entries(group.fields)) {
|
|
25
|
+
const key = `${group.id}.${name}`;
|
|
26
|
+
if (Object.hasOwn(error.fields, key)) continue;
|
|
27
|
+
const value = stored[key];
|
|
28
|
+
if (value === null && !declaration.nullable && declaration.default === undefined) continue;
|
|
29
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number' && Number.isFinite(value)) (document[group.id] ??= {})[name] = value;
|
|
30
|
+
}
|
|
31
|
+
return { document, errors: { ...error.fields } };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The choices read for each source (`roles`, `pages`, …), shared by every row of a page that lists them. */
|
|
36
|
+
export type ChoiceCache = Map<string, Promise<SettingRow['choices']>>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The group's rows, with choices filled in, and the current values as control values. Pass one
|
|
40
|
+
* `cache` for every group of a page, so a source is read once however many fields list it.
|
|
41
|
+
*/
|
|
42
|
+
export async function settingRows(cms: CmsHost, group: SettingsGroup, principal: Principal, cache: ChoiceCache = new Map()): Promise<{ rows: SettingRow[]; values: SettingValues }> {
|
|
43
|
+
const stored = await cms.settings.all();
|
|
44
|
+
const rows: SettingRow[] = [];
|
|
45
|
+
const values: SettingValues = {};
|
|
46
|
+
for (const [name, declaration] of Object.entries(group.fields)) {
|
|
47
|
+
rows.push({ name, namespace: group.id, label: declaration.label ?? name, description: declaration.description ?? '', kind: declaration.kind, min: declaration.min ?? null, max: declaration.max ?? null,
|
|
48
|
+
required: declaration.required === true, nullable: declaration.nullable === true, section: declaration.section ?? '', choices: await choicesOf(cms, declaration, principal, cache),
|
|
49
|
+
...(declaration.control ? { control: declaration.control } : declaration.source === 'media' ? { control: 'file' as const } : {}),
|
|
50
|
+
...(declaration.fileKinds ? { fileKinds: [...declaration.fileKinds] } : declaration.source === 'media' ? { fileKinds: ['image'] } : {}) });
|
|
51
|
+
const value = stored[`${group.id}.${name}`];
|
|
52
|
+
values[name] = value === null && declaration.nullable ? null : typeof value === 'boolean' ? value : value === null || value === undefined ? '' : String(value);
|
|
53
|
+
}
|
|
54
|
+
return { rows, values };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function choicesOf(cms: CmsHost, declaration: SettingDeclaration, principal: Principal, cache: ChoiceCache): Promise<SettingRow['choices']> {
|
|
58
|
+
if (declaration.control && declaration.kind !== 'enum' || declaration.source === 'media') return Promise.resolve([]);
|
|
59
|
+
if (declaration.kind === 'enum') return Promise.resolve((declaration.values ?? []).map(value => ({ value, label: declaration.choices?.[value] ?? value })));
|
|
60
|
+
if (!declaration.source) return Promise.resolve([]);
|
|
61
|
+
let found = cache.get(declaration.source);
|
|
62
|
+
if (!found) { found = sourceChoices(cms, declaration, principal); cache.set(declaration.source, found); }
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The choices a source offers: the site's roles, categories, published pages or the time zones. */
|
|
67
|
+
async function sourceChoices(cms: CmsHost, declaration: SettingDeclaration, principal: Principal): Promise<SettingRow['choices']> {
|
|
68
|
+
switch (declaration.source) {
|
|
69
|
+
case 'roles': return (await cms.users.roles()).filter(role => role.id !== 'admin').map(role => ({ value: role.id, label: role.name }));
|
|
70
|
+
case 'categories': return (await cms.taxonomies.tree('categories')).map(term => ({ value: term.id, label: `${'— '.repeat(term.depth)}${term.name}` }));
|
|
71
|
+
case 'pages': return (await cms.resource('cms/pages').list({ where: { status: 'published' }, order: { field: 'title', direction: 'asc' }, limit: 100 }, { principal }))
|
|
72
|
+
.records.map(record => ({ value: record.id, label: recordTitle(record, 'title') }));
|
|
73
|
+
case 'timezones': {
|
|
74
|
+
const zones = typeof Intl.supportedValuesOf === 'function' ? Intl.supportedValuesOf('timeZone') : [];
|
|
75
|
+
return ['UTC', ...zones.filter(zone => zone !== 'UTC')].map(zone => ({ value: zone, label: zone.replaceAll('_', ' ') }));
|
|
76
|
+
}
|
|
77
|
+
default: return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Match the media endpoint's authorization before a Settings or Customize server method lists files. */
|
|
82
|
+
export async function findSettingsMedia(cms: CmsHost, principal: Principal, search: string, kind: string) {
|
|
83
|
+
if (![PERMISSIONS.upload, PERMISSIONS.manageMedia, PERMISSIONS.manageUsers].some(permission => hasPermission(principal, permission))) throw new CmsError('CMS_FORBIDDEN', __('Not allowed to see the media library.'));
|
|
84
|
+
if (!cms.files) throw new CmsError('CMS_UNAVAILABLE', __('File storage is not configured.'));
|
|
85
|
+
return findMedia(cms, typeof search === 'string' ? search : '', ['image', 'video', 'audio', 'archive', 'document'].includes(kind) ? kind : '');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Typed input from control values, or errors by field. */
|
|
89
|
+
export function settingInput(group: SettingsGroup, values: SettingValues): { input: Record<string, unknown>; errors: Record<string, string> } {
|
|
90
|
+
const input: Record<string, unknown> = {};
|
|
91
|
+
const errors: Record<string, string> = {};
|
|
92
|
+
if (!values || typeof values !== 'object' || Array.isArray(values)) return { input, errors: { _form: __('Settings values must be an object.') } };
|
|
93
|
+
for (const name of Object.keys(values)) if (!Object.hasOwn(group.fields, name)) errors[name] = __('is not a setting of this group.');
|
|
94
|
+
for (const [name, declaration] of Object.entries(group.fields)) {
|
|
95
|
+
if (!Object.hasOwn(values, name)) continue;
|
|
96
|
+
const value = values[name];
|
|
97
|
+
if (value !== null && typeof value !== 'string' && typeof value !== 'boolean') { errors[name] = __('has an invalid control value.'); continue; }
|
|
98
|
+
if (value === null) input[name] = null;
|
|
99
|
+
else if (declaration.kind === 'boolean') input[name] = value === true;
|
|
100
|
+
else if (declaration.kind === 'integer' || declaration.kind === 'number') {
|
|
101
|
+
const number = Number(value);
|
|
102
|
+
if (value === '' || !Number.isFinite(number)) errors[name] = __('must be a number.');
|
|
103
|
+
else input[name] = number;
|
|
104
|
+
} else input[name] = typeof value === 'string' ? (declaration.kind === 'text' ? value : value.trim()) : '';
|
|
105
|
+
}
|
|
106
|
+
return { input, errors };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** One setting's control with its label, hint and error. */
|
|
110
|
+
export function settingControlId(namespace: string, name: string): string { return `setting-${encodeURIComponent(namespace)}-${encodeURIComponent(name)}`; }
|
|
111
|
+
|
|
112
|
+
/** Native color inputs use opaque six-digit hex; keep the author's original text until they pick. */
|
|
113
|
+
export function settingPickerColor(value: string): string {
|
|
114
|
+
if (/^#[0-9a-f]{3,4}$/i.test(value)) return `#${[...value.slice(1, 4)].map(digit => digit + digit).join('')}`;
|
|
115
|
+
return /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i.test(value) ? value.slice(0, 7) : '#000000';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Icons the icon style control previews in the chosen style, from their sprites. */
|
|
119
|
+
const ICON_STYLE_PREVIEW = ['star', 'heart', 'bell', 'settings', 'chat-round-line', 'cart-large-2', 'user', 'calendar'];
|
|
120
|
+
|
|
121
|
+
function iconStyleControl(row: SettingRow, value: SettingValue | undefined, attributes: FieldControlAttributes, set: (value: SettingValue) => void): TemplateResult {
|
|
122
|
+
const style = isIconStyle(value) ? value : 'line';
|
|
123
|
+
return html`<div class="flex flex-wrap items-center gap-3">
|
|
124
|
+
${component(NativeSelect, { ...attributes, class: 'w-auto min-w-40', disabled: value === null, '@change': (event: Event) => set((event.target as HTMLSelectElement).value) }, html`
|
|
125
|
+
${row.choices.map(choice => html`<option value=${choice.value} ?selected=${choice.value === value}>${__(choice.label)}</option>`)}`)}
|
|
126
|
+
<div class="flex flex-wrap items-center gap-3 text-foreground" role="img" aria-label=${`${__('Preview')}: ${row.choices.find(choice => choice.value === style)?.label ?? style}`} data-icon-style=${style}>
|
|
127
|
+
${ICON_STYLE_PREVIEW.map(name => html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" class="size-6" focusable="false" aria-hidden="true"><use href=${iconHref(name, style) ?? ''}></use></svg>`)}
|
|
128
|
+
</div>
|
|
129
|
+
</div>`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The UI's palettes as swatches, like WordPress's admin color schemes: four colors of each in
|
|
134
|
+
* the current mode, and the name. A radio group; the choice applies once saved.
|
|
135
|
+
*/
|
|
136
|
+
function paletteControl(row: SettingRow, value: SettingValue | undefined, attributes: FieldControlAttributes, set: (value: SettingValue) => void): TemplateResult {
|
|
137
|
+
const kind = row.name === 'accent' ? 'accent' : 'base';
|
|
138
|
+
const strip = (colors: readonly string[], mode: string) => html`<span aria-hidden="true" class=${`${mode} h-6 overflow-hidden rounded-sm border border-border`}>${colors.map(color => html`<span class="h-full flex-1" style=${`background:${color}`}></span>`)}</span>`;
|
|
139
|
+
return html`<div id=${attributes.id} role="radiogroup" aria-label=${row.label} aria-describedby=${attributes['aria-describedby'] ?? null} class="grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-5">
|
|
140
|
+
${row.choices.map(choice => {
|
|
141
|
+
const palette = UI_PALETTES.find(entry => entry.id === choice.value && entry.kind === kind);
|
|
142
|
+
const checked = choice.value === value;
|
|
143
|
+
return html`<label data-palette-choice=${choice.value} class=${`flex cursor-pointer flex-col gap-2 rounded-md border p-2 text-sm has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring ${checked ? 'border-primary bg-primary/5 font-medium text-foreground' : 'border-border text-muted-foreground hover:border-foreground/30 hover:text-foreground'}`}>
|
|
144
|
+
${palette ? html`${strip(palette.light, 'flex dark:hidden')}${strip(palette.dark, 'hidden dark:flex')}` : null}
|
|
145
|
+
<span class="flex items-center gap-2"><input type="radio" class="sr-only" name=${`${row.namespace}-${row.name}`} value=${choice.value} .checked=${checked} ?disabled=${value === null}
|
|
146
|
+
@change=${(event: Event) => { if ((event.target as HTMLInputElement).checked) set(choice.value); }}>${__(choice.label)}</span>
|
|
147
|
+
</label>`;
|
|
148
|
+
})}
|
|
149
|
+
</div>`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function settingControl(row: SettingRow, value: SettingValue | undefined, error: string | undefined, set: (value: SettingValue) => void, media?: SettingsMedia): TemplateResult {
|
|
153
|
+
const id = settingControlId(row.namespace, row.name);
|
|
154
|
+
const select = row.choices.length || row.kind === 'enum';
|
|
155
|
+
const control = component(Field, { label: row.label, for: id, ...(row.description ? { hint: row.description } : {}), ...(error ? { error: `${row.label} ${error}` } : {}),
|
|
156
|
+
control: attributes => row.control === 'color'
|
|
157
|
+
? html`<div class="flex items-center gap-2">
|
|
158
|
+
${component(ColorPicker, { id: `${id}-picker`, label: `${__('Choose color')}: ${row.label}`, value: settingPickerColor(String(value ?? '')), disabled: value === null, onChange: set })}
|
|
159
|
+
${component(Input, { ...attributes, type: 'text', disabled: value === null, placeholder: '#000000', '.value': String(value ?? ''), '@input': (event: Event) => set((event.target as HTMLInputElement).value) })}
|
|
160
|
+
</div>`
|
|
161
|
+
: row.control === 'icon-style'
|
|
162
|
+
? iconStyleControl(row, value, attributes, set)
|
|
163
|
+
: row.control === 'palette'
|
|
164
|
+
? paletteControl(row, value, attributes, set)
|
|
165
|
+
: row.control === 'file'
|
|
166
|
+
? component(SettingsFile, { attributes, label: row.label, value: String(value ?? ''), disabled: value === null, kinds: row.fileKinds, media, onChange: set })
|
|
167
|
+
: row.kind === 'boolean'
|
|
168
|
+
? component(Checkbox, { ...attributes, disabled: value === null, checked: value === true, '@change': (event: Event) => set((event.target as HTMLInputElement).checked) })
|
|
169
|
+
: select
|
|
170
|
+
? component(NativeSelect, { ...attributes, disabled: value === null, '@change': (event: Event) => set((event.target as HTMLSelectElement).value) }, html`
|
|
171
|
+
${value === null ? html`<option value="" selected>${__('Null')}</option>` : null}
|
|
172
|
+
${row.kind === 'enum' ? null : html`<option value="" ?selected=${!value}>—</option>`}
|
|
173
|
+
${row.choices.map(choice => html`<option value=${choice.value} ?selected=${choice.value === value}>${choice.label}</option>`)}`)
|
|
174
|
+
: row.kind === 'text' ? component(Textarea, { ...attributes, disabled: value === null, rows: 5, '.value': String(value ?? ''), '@input': (event: Event) => set((event.target as HTMLTextAreaElement).value) })
|
|
175
|
+
: component(Input, { ...attributes, disabled: value === null, type: row.kind === 'integer' || row.kind === 'number' ? 'number' : 'text', ...(row.min !== null && row.kind !== 'string' && row.kind !== 'text' ? { min: row.min } : {}), ...(row.max !== null && row.kind !== 'string' && row.kind !== 'text' ? { max: row.max } : {}),
|
|
176
|
+
...(row.kind === 'integer' ? { step: 1 } : row.kind === 'number' ? { step: 'any' } : {}),
|
|
177
|
+
'.value': String(value ?? ''), '@input': (event: Event) => set((event.target as HTMLInputElement).value) }) });
|
|
178
|
+
return html`<div class="space-y-2">${control}${row.nullable ? component(Checkbox, { id: `${id}-null`, label: `${__('Set to null')}: ${row.label}`, checked: value === null,
|
|
179
|
+
'@change': (event: Event) => set((event.target as HTMLInputElement).checked ? null : row.kind === 'boolean' ? false : row.kind === 'integer' || row.kind === 'number' ? '0' : row.kind === 'enum' ? row.choices[0]?.value ?? '' : '') }) : null}</div>`;
|
|
180
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** The language form used by the unified Settings page. */
|
|
2
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
3
|
+
import { Button, Checkbox, NativeSelect, Input } from '@cossackframework/ui';
|
|
4
|
+
import { component, html } from '@cossackframework/renderer';
|
|
5
|
+
import { isCmsError, languageName, LOCALE, type Principal } from '@cossackframework/cms';
|
|
6
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
7
|
+
import type { SettingsDraft } from './settings-draft';
|
|
8
|
+
import { notice } from './ui';
|
|
9
|
+
|
|
10
|
+
const COMMON = ['ar', 'bg', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ko', 'ms', 'nb', 'nl', 'pl', 'pt', 'pt-br',
|
|
11
|
+
'ro', 'ru', 'sk', 'sv', 'sw', 'th', 'tl', 'tr', 'uk', 'ur', 'vi', 'zh-hans', 'zh-hant'];
|
|
12
|
+
|
|
13
|
+
/** Language in URLs: `hide-default` keeps the default language's pages unprefixed, `all` gives every language its code. */
|
|
14
|
+
export type LanguageUrls = 'hide-default' | 'all';
|
|
15
|
+
export interface LanguageSettingsInput { main: string; others: string[]; urls: LanguageUrls }
|
|
16
|
+
export interface LanguageSettingsData extends LanguageSettingsInput { options: { code: string; label: string }[]; origin: string }
|
|
17
|
+
export interface LanguageSettingsResult { data: LanguageSettingsData | null; error: string }
|
|
18
|
+
interface LanguageDraft extends LanguageSettingsInput { custom: string; added: string[] }
|
|
19
|
+
|
|
20
|
+
export async function loadLanguageSettings(cms: CmsHost, origin: string): Promise<LanguageSettingsData> {
|
|
21
|
+
const languages = await cms.languages();
|
|
22
|
+
return { main: languages.default, others: [...languages.others], urls: await cms.settings.get('languages.urls') === 'all' ? 'all' : 'hide-default', origin,
|
|
23
|
+
options: [...new Set([...COMMON, ...languages.all])].map(code => ({ code, label: `${languageName(code)} (${code})` })).sort((a, b) => a.label.localeCompare(b.label)) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Called by the authorized page's server method; mutation authorization stays in CmsHost. */
|
|
27
|
+
export async function saveLanguageSettings(cms: CmsHost, principal: Principal, input: LanguageSettingsInput, origin: string): Promise<LanguageSettingsResult> {
|
|
28
|
+
try {
|
|
29
|
+
if (!input || typeof input.main !== 'string' || !Array.isArray(input.others) || input.others.some(code => typeof code !== 'string')) return { data: null, error: __('Use language codes such as en, fr or pt-br.') };
|
|
30
|
+
if (input.urls !== undefined && input.urls !== 'hide-default' && input.urls !== 'all') return { data: null, error: __('Choose how URLs show the language.') };
|
|
31
|
+
await cms.saveLanguages({ default: input.main, others: input.others, ...(input.urls ? { urls: input.urls } : {}) }, principal);
|
|
32
|
+
return { data: await loadLanguageSettings(cms, origin), error: '' };
|
|
33
|
+
} catch (error) { return { data: null, error: isCmsError(error) ? error.message : __('The languages could not be saved.') }; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type LanguagesSettingsProps = {
|
|
37
|
+
draft: SettingsDraft;
|
|
38
|
+
initial: LanguageSettingsData;
|
|
39
|
+
/** Undefined shows all fields; otherwise these are the full matching setting keys. */
|
|
40
|
+
fields?: readonly string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const languageDraft = (data: LanguageSettingsData): LanguageDraft => ({ main: data.main, others: [...data.others], urls: data.urls, custom: '', added: [] });
|
|
44
|
+
|
|
45
|
+
/** What the Settings page's Save sends for the section's draft. */
|
|
46
|
+
export function languageInput(draft: SettingsDraft, initial: LanguageSettingsData): LanguageSettingsInput {
|
|
47
|
+
const current = draft.section('languages', languageDraft(initial));
|
|
48
|
+
return { main: current.main, others: current.others.filter(code => code !== current.main), urls: current.urls };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Component()
|
|
52
|
+
export class LanguagesSettings extends Cossack {
|
|
53
|
+
declare props: LanguagesSettingsProps;
|
|
54
|
+
@ClientState() private revision = 0;
|
|
55
|
+
@ClientState() private error = '';
|
|
56
|
+
private unsubscribe?: () => void;
|
|
57
|
+
|
|
58
|
+
onMount() {
|
|
59
|
+
this.props.draft.initializeSection('languages', languageDraft(this.props.initial));
|
|
60
|
+
this.unsubscribe = this.props.draft.subscribe(() => { this.revision++; });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
onCleanup() { this.unsubscribe?.(); }
|
|
64
|
+
|
|
65
|
+
@Client()
|
|
66
|
+
set(patch: Partial<LanguageDraft>) {
|
|
67
|
+
const current = this.props.draft.section('languages', languageDraft(this.props.initial));
|
|
68
|
+
this.props.draft.setSection('languages', { ...current, ...patch });
|
|
69
|
+
this.error = '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Client()
|
|
73
|
+
toggle(code: string, checked: boolean) {
|
|
74
|
+
const current = this.props.draft.section('languages', languageDraft(this.props.initial));
|
|
75
|
+
this.set({ others: checked ? [...new Set([...current.others, code])] : current.others.filter(entry => entry !== code) });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Client()
|
|
79
|
+
addCustom() {
|
|
80
|
+
const current = this.props.draft.section('languages', languageDraft(this.props.initial));
|
|
81
|
+
const code = current.custom.trim().toLowerCase();
|
|
82
|
+
if (!LOCALE.test(code)) { this.error = __('Use a code such as fr, pt-br or zh-hans.'); return; }
|
|
83
|
+
this.set({ added: [...new Set([...current.added, code])], others: [...new Set([...current.others, code])], custom: '' });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render() {
|
|
87
|
+
const form = this.props.draft.section('languages', languageDraft(this.props.initial));
|
|
88
|
+
const show = (field: string) => !this.props.fields || this.props.fields.includes(`languages.${field}`);
|
|
89
|
+
const origin = this.props.initial.origin;
|
|
90
|
+
const options = [...new Set([...this.props.initial.options.map(option => option.code), form.main, ...form.others, ...form.added])]
|
|
91
|
+
.map(code => ({ code, label: `${languageName(code)} (${code})` })).sort((a, b) => a.label.localeCompare(b.label));
|
|
92
|
+
return html`<div class="space-y-5">
|
|
93
|
+
<p class="text-sm text-muted-foreground">${__('Publish entries in several languages. Each entry has one language; the editor links its translations.')}</p>
|
|
94
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
95
|
+
<fieldset class="min-w-0 space-y-5" ?disabled=${this.props.draft.saving}>
|
|
96
|
+
${show('default') ? html`<div class="space-y-1">
|
|
97
|
+
<label for="language-default" class="block text-sm font-medium text-foreground">${__('Default language')}</label>
|
|
98
|
+
${component(NativeSelect, { id: 'language-default', '@change': (event: Event) => this.set({ main: (event.target as HTMLSelectElement).value }) }, html`
|
|
99
|
+
${options.map(option => html`<option value=${option.code} ?selected=${option.code === form.main}>${option.label}</option>`)}`)}
|
|
100
|
+
<p class="text-xs text-muted-foreground">${__('Its entries are at addresses such as')} <code>${origin}${form.urls === 'all' && form.others.some(code => code !== form.main) ? `/${form.main}` : ''}/about</code>.</p>
|
|
101
|
+
</div>` : null}
|
|
102
|
+
${show('others') ? html`<fieldset id="language-others" class="min-w-0 space-y-2">
|
|
103
|
+
<legend class="mb-1 text-sm font-medium text-foreground">${__('Other languages')}</legend>
|
|
104
|
+
<p class="text-xs text-muted-foreground">${__('Their entries live under the language code, such as')} <code>${origin}/fr/a-propos</code>.</p>
|
|
105
|
+
<div class="grid max-h-80 gap-1.5 overflow-y-auto rounded-md border border-border p-3 sm:grid-cols-2">
|
|
106
|
+
${options.filter(option => option.code !== form.main).map(option => html`<div>${component(Checkbox, { label: option.label, checked: form.others.includes(option.code), '@change': (event: Event) => this.toggle(option.code, (event.target as HTMLInputElement).checked) })}</div>`)}
|
|
107
|
+
</div>
|
|
108
|
+
<div class="flex gap-2">
|
|
109
|
+
${component(Input, { class: 'min-w-0 max-w-48', 'aria-label': __('Another language code'), placeholder: __('Another code, such as eu'), '.value': form.custom,
|
|
110
|
+
'@input': (event: Event) => this.set({ custom: (event.target as HTMLInputElement).value }) })}
|
|
111
|
+
${component(Button, { type: 'button', variant: 'outline', '@click': this.addCustom }, __('Add'))}
|
|
112
|
+
</div>
|
|
113
|
+
</fieldset>` : null}
|
|
114
|
+
${show('urls') ? html`<fieldset id="language-urls" class="min-w-0 space-y-2">
|
|
115
|
+
<legend class="mb-1 text-sm font-medium text-foreground">${__('Language in URLs')}</legend>
|
|
116
|
+
${([['hide-default', __('Hide the default language\'s code'), `${origin}/about · ${origin}/fr/a-propos`], ['all', __('Every language has its code'), `${origin}/${form.main}/about · ${origin}/fr/a-propos`]] as const).map(([value, label, example]) => html`<label class="flex cursor-pointer items-start gap-3 rounded-md border border-border p-3 has-[:checked]:border-primary">
|
|
117
|
+
<input type="radio" name="language-urls" class="mt-1" .checked=${form.urls === value} @change=${() => this.set({ urls: value })}>
|
|
118
|
+
<span><span class="block text-sm font-medium text-foreground">${label}</span><code class="break-all text-xs text-muted-foreground">${example}</code></span>
|
|
119
|
+
</label>`)}
|
|
120
|
+
<p class="text-xs text-muted-foreground">${__('Applies when the site has several languages. Addresses in the other form redirect.')}</p>
|
|
121
|
+
</fieldset>` : null}
|
|
122
|
+
</fieldset>
|
|
123
|
+
</div>`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Navigation for the scrolling Settings page and its JSON editor. */
|
|
2
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
3
|
+
import { Icon } from '@cossackframework/ui';
|
|
4
|
+
import { PERMISSIONS } from '@cossackframework/cms';
|
|
5
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
6
|
+
import { icon } from './icons';
|
|
7
|
+
import { settingsNavigation } from './settings-draft';
|
|
8
|
+
import { searchSettings, settingsSectionHref, type SettingsSearchEntry } from './settings-search';
|
|
9
|
+
|
|
10
|
+
export interface SettingsLink {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
href: string;
|
|
14
|
+
parent?: string;
|
|
15
|
+
icon?: string;
|
|
16
|
+
/** Matching settings in this group and its descendants. */
|
|
17
|
+
count?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Settings groups in page order. Plugins each get a child beneath Plugins; `network` adds the main site's Network section last. */
|
|
21
|
+
export function settingsLinks(cms: CmsHost, options: { network?: boolean } = {}): SettingsLink[] {
|
|
22
|
+
const groups = cms.settings.groups.filter(group => (group.permission ?? PERMISSIONS.manageSettings) === PERMISSIONS.manageSettings);
|
|
23
|
+
return [
|
|
24
|
+
...groups.filter(group => !group.plugin).map(group => ({ id: group.id, label: group.label, href: settingsSectionHref(group.id),
|
|
25
|
+
...(group.parent ? { parent: group.parent } : {}), ...(group.icon ? { icon: group.icon } : {}) })),
|
|
26
|
+
{ id: 'permalinks', label: 'Permalinks', href: settingsSectionHref('permalinks'), icon: 'link' },
|
|
27
|
+
{ id: 'plugins', label: 'Plugins', href: settingsSectionHref('plugins'), icon: 'widget' },
|
|
28
|
+
...groups.filter(group => group.plugin).map(group => ({ id: group.id, label: group.label, href: settingsSectionHref(group.id), parent: 'plugins', icon: 'plug-circle' })),
|
|
29
|
+
...(options.network ? [{ id: 'network', label: 'Network', href: settingsSectionHref('network'), icon: 'global' }] : []),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Keep matching groups and their ancestors, counting each matching field once per ancestor. */
|
|
34
|
+
export function filterSettingsLinks(links: readonly SettingsLink[], entries: readonly SettingsSearchEntry[], query: string): SettingsLink[] {
|
|
35
|
+
const byId = new Map(links.map(link => [link.id, link]));
|
|
36
|
+
const counts = new Map<string, number>();
|
|
37
|
+
for (const entry of searchSettings(entries, query)) {
|
|
38
|
+
let group: string | undefined = entry.groupId;
|
|
39
|
+
const visited = new Set<string>();
|
|
40
|
+
while (group && byId.has(group) && !visited.has(group)) {
|
|
41
|
+
visited.add(group);
|
|
42
|
+
counts.set(group, (counts.get(group) ?? 0) + 1);
|
|
43
|
+
group = byId.get(group)!.parent;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return links.filter(link => !query.trim() || counts.has(link.id)).map(link => ({ ...link, count: counts.get(link.id) ?? 0 }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Error links target the persistent section shell, including sections whose controls are deferred. */
|
|
50
|
+
export function settingsErrorSummary(errors: Readonly<Record<string, string>>, onNavigate: (event: MouseEvent) => void = settingsNavigation): TemplateResult | null {
|
|
51
|
+
const entries = Object.entries(errors);
|
|
52
|
+
if (!entries.length) return null;
|
|
53
|
+
return html`<ul role="alert" class="space-y-1 text-sm text-destructive">${entries.map(([path, error]) => {
|
|
54
|
+
const separator = path.lastIndexOf('.');
|
|
55
|
+
const namespace = path.slice(0, separator);
|
|
56
|
+
const destination = separator < 1 ? '/dashboard/settings/json' : settingsSectionHref(namespace);
|
|
57
|
+
return html`<li><a href=${destination} data-settings-error-group=${namespace} @click=${onNavigate} class="underline"><code>${path}</code></a>: ${error}</li>`;
|
|
58
|
+
})}</ul>`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SettingsFrameOptions {
|
|
62
|
+
entries?: readonly SettingsSearchEntry[];
|
|
63
|
+
query?: string;
|
|
64
|
+
onNavigate?: (event: MouseEvent) => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The navigation grows with the page and occupies at least a viewport on desktop. */
|
|
68
|
+
export function settingsFrame(links: readonly SettingsLink[], current: string, body: TemplateResult, options: SettingsFrameOptions = {}): TemplateResult {
|
|
69
|
+
const query = options.query ?? '';
|
|
70
|
+
const menu = options.entries ? filterSettingsLinks(links, options.entries, query) : links;
|
|
71
|
+
const onNavigate = options.onNavigate ?? settingsNavigation;
|
|
72
|
+
const ids = new Set(menu.map(link => link.id));
|
|
73
|
+
const byParent = new Map<string, SettingsLink[]>();
|
|
74
|
+
for (const link of menu) if (link.parent) {
|
|
75
|
+
const siblings = byParent.get(link.parent) ?? [];
|
|
76
|
+
siblings.push(link);
|
|
77
|
+
byParent.set(link.parent, siblings);
|
|
78
|
+
}
|
|
79
|
+
const roots = menu.filter(link => !link.parent || !ids.has(link.parent));
|
|
80
|
+
const item = (link: SettingsLink, ancestors: readonly string[] = []): TemplateResult => {
|
|
81
|
+
const children = (byParent.get(link.id) ?? []).filter(entry => !ancestors.includes(entry.id) && entry.id !== link.id);
|
|
82
|
+
return html`<li data-settings-menu-parent=${link.id} class="min-w-0">
|
|
83
|
+
<a href=${link.href} data-settings-menu-group=${link.id} data-settings-count=${link.count} @click=${onNavigate}
|
|
84
|
+
aria-current=${link.id === current ? 'location' : 'false'}
|
|
85
|
+
class=${`flex items-center gap-2 rounded-md px-3 py-2 text-sm no-underline [&_svg]:size-4 ${link.id === current ? 'bg-muted font-medium text-foreground' : 'text-muted-foreground hover:bg-muted/60 hover:text-foreground'}`}>
|
|
86
|
+
<span aria-hidden="true" class="inline-flex shrink-0">${component(Icon, { entry: icon(link.icon ?? 'settings', 'settings'), size: 16 })}</span>
|
|
87
|
+
<span class="min-w-0 flex-1 break-words">${__(link.label)}</span>
|
|
88
|
+
${query.trim() && link.count !== undefined ? html`<span aria-label=${`${link.count} ${link.count === 1 ? __('setting') : __('settings')}`} class="shrink-0 rounded bg-muted px-1.5 py-0.5 text-xs tabular-nums">${link.count}</span>` : null}
|
|
89
|
+
</a>
|
|
90
|
+
${children.length ? html`<ul class="ms-5 space-y-0.5 border-s border-border ps-1">${children.map(child => item(child, [...ancestors, link.id]))}</ul>` : null}
|
|
91
|
+
</li>`;
|
|
92
|
+
};
|
|
93
|
+
return html`<div data-subnav class="grid min-h-screen min-w-0 content-start md:grid-cols-[13rem_minmax(0,1fr)] md:content-stretch">
|
|
94
|
+
<nav aria-label=${__('Settings')} class="self-stretch border-b border-border bg-background md:min-h-screen md:border-b-0 md:border-e">
|
|
95
|
+
<div class="md:sticky md:overflow-y-auto" style="top:var(--settings-toolbar-height, 56px);max-height:calc(100dvh - var(--settings-toolbar-height, 56px))">
|
|
96
|
+
<ul class="flex gap-1 overflow-x-auto p-2 md:flex-col md:overflow-x-visible">${roots.map(link => item(link))}</ul>
|
|
97
|
+
${menu.length ? null : html`<p role="status" class="px-4 py-3 text-sm text-muted-foreground">${__('No settings match your search.')}</p>`}
|
|
98
|
+
</div>
|
|
99
|
+
</nav>
|
|
100
|
+
<div class="min-w-0 p-6 sm:p-8"><div class="max-w-3xl space-y-6">${body}</div></div>
|
|
101
|
+
</div>`;
|
|
102
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Network section of the main site's Settings page, for network admins: whether the install
|
|
3
|
+
* runs a network of sites, and what new sites start with. It saves through the network, not the
|
|
4
|
+
* site's settings document.
|
|
5
|
+
*/
|
|
6
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
7
|
+
import { Checkbox, Field, Input, NativeSelect } from '@cossackframework/ui';
|
|
8
|
+
import { html, type TemplateResult, component } from '@cossackframework/renderer';
|
|
9
|
+
import { isCmsError, type Principal } from '@cossackframework/cms';
|
|
10
|
+
import type { CmsNetwork, NetworkSettings, SiteExportPolicy } from '@cossackframework/cms/server';
|
|
11
|
+
import type { SettingsDraft } from './settings-draft';
|
|
12
|
+
import { notice } from './ui';
|
|
13
|
+
|
|
14
|
+
export interface NetworkSettingsInput {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
name: string;
|
|
17
|
+
subdomainSuffix: string;
|
|
18
|
+
defaultTheme: string;
|
|
19
|
+
defaultPlugins: string[];
|
|
20
|
+
defaultLanguage: string;
|
|
21
|
+
siteExports: SiteExportPolicy;
|
|
22
|
+
}
|
|
23
|
+
export interface NetworkSettingsData extends NetworkSettingsInput {
|
|
24
|
+
/** What new sites' addresses end with while `subdomainSuffix` is empty. */
|
|
25
|
+
fallbackSuffix: string;
|
|
26
|
+
/** Themes and plugins new sites may start with: those the network neither hides nor runs everywhere. */
|
|
27
|
+
themes: { name: string; label: string }[];
|
|
28
|
+
plugins: string[];
|
|
29
|
+
/** Whether this install opens and creates site databases. */
|
|
30
|
+
canAddSites: boolean;
|
|
31
|
+
/** Added sites that answer while the network is on: active or archived. */
|
|
32
|
+
sites: number;
|
|
33
|
+
}
|
|
34
|
+
export interface NetworkSettingsResult { data: NetworkSettingsData | null; error: string; fields: Record<string, string> }
|
|
35
|
+
|
|
36
|
+
export async function loadNetworkSettings(network: CmsNetwork): Promise<NetworkSettingsData> {
|
|
37
|
+
const [settings, enabled, policy, status, active, archived] = await Promise.all([
|
|
38
|
+
network.settings(), network.enabled(), network.policy(), network.main.status(),
|
|
39
|
+
network.sites.list({ status: 'active', limit: 1 }), network.sites.list({ status: 'archived', limit: 1 }),
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
enabled, name: settings.name, subdomainSuffix: settings.subdomainSuffix, defaultTheme: settings.defaultTheme,
|
|
43
|
+
defaultPlugins: [...settings.defaultPlugins], defaultLanguage: settings.defaultLanguage, siteExports: settings.siteExports, fallbackSuffix: network.subdomainSuffix,
|
|
44
|
+
themes: network.main.themes().filter(theme => !theme.problems.length && !policy.hiddenThemes.has(theme.name)).map(theme => ({ name: theme.name, label: theme.label })),
|
|
45
|
+
plugins: status.plugins.filter(plugin => !plugin.themeOnly && !plugin.unrestricted && plugin.network === 'available').map(plugin => plugin.name),
|
|
46
|
+
canAddSites: network.canAddSites, sites: active.total + archived.total,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Called by the authorized page; the network also checks that the principal is a network admin. */
|
|
51
|
+
export async function saveNetworkSettings(network: CmsNetwork, principal: Principal, input: NetworkSettingsInput): Promise<NetworkSettingsResult> {
|
|
52
|
+
const text = (value: unknown) => typeof value === 'string';
|
|
53
|
+
if (!input || typeof input.enabled !== 'boolean' || ![input.name, input.subdomainSuffix, input.defaultTheme, input.defaultLanguage].every(text)
|
|
54
|
+
|| !Array.isArray(input.defaultPlugins) || !input.defaultPlugins.every(text) || (input.siteExports !== 'request' && input.siteExports !== 'self')) return { data: null, error: __('The network settings are invalid.'), fields: {} };
|
|
55
|
+
try {
|
|
56
|
+
if (input.enabled !== await network.enabled()) await network.setEnabled(input.enabled, { principal });
|
|
57
|
+
const patch: Partial<NetworkSettings> = {
|
|
58
|
+
name: input.name, subdomainSuffix: input.subdomainSuffix.trim(), defaultTheme: input.defaultTheme,
|
|
59
|
+
defaultPlugins: input.defaultPlugins, defaultLanguage: input.defaultLanguage.trim().toLowerCase(), siteExports: input.siteExports,
|
|
60
|
+
};
|
|
61
|
+
const saved = await network.settings();
|
|
62
|
+
// Turning the network on or off leaves the rest alone, even when a stored value went stale.
|
|
63
|
+
if (Object.entries(patch).some(([key, value]) => JSON.stringify(value) !== JSON.stringify(saved[key as keyof NetworkSettings]))) await network.saveSettings(patch, { principal });
|
|
64
|
+
return { data: await loadNetworkSettings(network), error: '', fields: {} };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return { data: null, error: isCmsError(error) ? error.message : __('The network settings could not be saved.'), fields: isCmsError(error) ? { ...error.fields } : {} };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const networkDraft = (data: NetworkSettingsData): NetworkSettingsInput => ({
|
|
71
|
+
enabled: data.enabled, name: data.name, subdomainSuffix: data.subdomainSuffix, defaultTheme: data.defaultTheme,
|
|
72
|
+
defaultPlugins: [...data.defaultPlugins], defaultLanguage: data.defaultLanguage, siteExports: data.siteExports,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export type NetworkSettingsProps = {
|
|
76
|
+
draft: SettingsDraft;
|
|
77
|
+
initial: NetworkSettingsData;
|
|
78
|
+
/** Matching search entries, as `network.<field>`; every field when absent. */
|
|
79
|
+
fields?: readonly string[];
|
|
80
|
+
/** Field problems from the last save, by field name. */
|
|
81
|
+
errors?: Readonly<Record<string, string>>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
@Component()
|
|
85
|
+
export class NetworkSettingsForm extends Cossack {
|
|
86
|
+
declare props: NetworkSettingsProps;
|
|
87
|
+
@ClientState() private revision = 0;
|
|
88
|
+
private unsubscribe?: () => void;
|
|
89
|
+
|
|
90
|
+
onMount() {
|
|
91
|
+
this.props.draft.initializeSection('network', networkDraft(this.props.initial));
|
|
92
|
+
this.unsubscribe = this.props.draft.subscribe(() => { this.revision++; });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onCleanup() { this.unsubscribe?.(); }
|
|
96
|
+
|
|
97
|
+
@Client()
|
|
98
|
+
set(patch: Partial<NetworkSettingsInput>) {
|
|
99
|
+
this.props.draft.setSection('network', { ...this.props.draft.section('network', networkDraft(this.props.initial)), ...patch });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Client()
|
|
103
|
+
togglePlugin(name: string, checked: boolean) {
|
|
104
|
+
const current = this.props.draft.section('network', networkDraft(this.props.initial)).defaultPlugins;
|
|
105
|
+
this.set({ defaultPlugins: checked ? [...new Set([...current, name])] : current.filter(entry => entry !== name) });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
render() {
|
|
109
|
+
const initial = this.props.initial;
|
|
110
|
+
const form = this.props.draft.section('network', networkDraft(initial));
|
|
111
|
+
const show = (field: string) => !this.props.fields || this.props.fields.includes(`network.${field}`);
|
|
112
|
+
const errors = this.props.errors ?? {};
|
|
113
|
+
const error = (name: string) => errors[name] ? html`<p role="alert" class="text-xs text-destructive">${errors[name]}</p>` : null;
|
|
114
|
+
const input = (name: 'name' | 'subdomainSuffix' | 'defaultLanguage', label: string, hint: string, placeholder = ''): TemplateResult | null => show(name)
|
|
115
|
+
? component(Field, { label, for: `network-${name}`, hint, ...(errors[name] ? { error: errors[name] } : {}),
|
|
116
|
+
control: attributes => component(Input, { ...attributes, '.value': form[name], placeholder, '@input': (event: Event) => this.set({ [name]: (event.target as HTMLInputElement).value }) }) })
|
|
117
|
+
: null;
|
|
118
|
+
const suffix = form.subdomainSuffix.trim() || initial.fallbackSuffix || 'example.com';
|
|
119
|
+
return html`<fieldset class="min-w-0 space-y-5" ?disabled=${this.props.draft.saving}>
|
|
120
|
+
${show('enabled') ? component(Checkbox, { id: 'network-enabled', checked: form.enabled, '@change': (event: Event) => this.set({ enabled: (event.target as HTMLInputElement).checked }) },
|
|
121
|
+
html`<span><span class="block font-medium">${__('Run a network of sites')}</span>
|
|
122
|
+
<span class="text-xs text-muted-foreground">${__('Each added site has its own database, address and members; accounts sign in once, here, for all of them. Network admins manage the sites under Network.')}</span></span>`) : null}
|
|
123
|
+
${form.enabled && !initial.canAddSites ? notice(__('Sites need their own databases: files beside the main one on Node, or ROMEDB_SITES_URL and ROMEDB_SITES_TOKEN (a RomeDB organization). Until then the network is this site only.')) : null}
|
|
124
|
+
${!form.enabled && initial.enabled && initial.sites ? notice(`${__('Turning the network off stops serving its other sites')} (${initial.sites}). ${__('Their databases stay: turn it on again to serve them.')}`, 'warning') : null}
|
|
125
|
+
${form.enabled ? html`
|
|
126
|
+
${input('name', __('Network name'), __('Shown on the network dashboard and the sign-in page.'))}
|
|
127
|
+
${input('subdomainSuffix', __('Addresses of new sites'), `${__('New sites start at a subdomain of this domain, such as blog.')}${suffix}. ${__('Point a wildcard DNS record at the network.')}`, initial.fallbackSuffix)}
|
|
128
|
+
${show('defaultTheme') || show('defaultPlugins') || show('defaultLanguage') ? html`<fieldset class="min-w-0 space-y-4">
|
|
129
|
+
<legend class="mb-2 text-base font-semibold text-foreground">${__('New sites')}</legend>
|
|
130
|
+
${show('defaultTheme') ? component(Field, { label: __('Theme'), for: 'network-defaultTheme', ...(errors.defaultTheme ? { error: errors.defaultTheme } : {}),
|
|
131
|
+
control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.set({ defaultTheme: (event.target as HTMLSelectElement).value }) }, html`
|
|
132
|
+
<option value="" ?selected=${!form.defaultTheme}>${__('The first available theme')}</option>
|
|
133
|
+
${initial.themes.map(theme => html`<option value=${theme.name} ?selected=${theme.name === form.defaultTheme}>${theme.label}</option>`)}`) }) : null}
|
|
134
|
+
${show('defaultPlugins') && initial.plugins.length ? html`<div class="space-y-1.5">
|
|
135
|
+
<p class="text-sm font-medium text-foreground">${__('Plugins enabled on new sites')}</p>
|
|
136
|
+
${initial.plugins.map(name => html`<div>${component(Checkbox, { label: name, checked: form.defaultPlugins.includes(name), '@change': (event: Event) => this.togglePlugin(name, (event.target as HTMLInputElement).checked) })}</div>`)}
|
|
137
|
+
<p class="text-xs text-muted-foreground">${__('Network active plugins run on every site already.')}</p>${error('defaultPlugins')}
|
|
138
|
+
</div>` : null}
|
|
139
|
+
${input('defaultLanguage', __('Language'), __('A language code, such as en, fr or pt-br. Add site can choose another.'), 'en')}
|
|
140
|
+
</fieldset>` : null}
|
|
141
|
+
${show('siteExports') ? html`<fieldset class="min-w-0 space-y-2">
|
|
142
|
+
<legend class="mb-2 text-base font-semibold text-foreground">${__('Site exports')}</legend>
|
|
143
|
+
${([['request', __('Site admins request an export; a network admin approves it'), __('The site can then download it under Tools → Export for 7 days. Requests wait on the site\'s page under Network → Sites.')],
|
|
144
|
+
['self', __('Site admins export their own site'), __('Tools → Export downloads the site\'s database at once.')]] as const).map(([value, label, hint]) => html`<label class="flex cursor-pointer items-start gap-3 rounded-md border border-border p-3 has-[:checked]:border-primary">
|
|
145
|
+
<input type="radio" name="network-siteExports" class="mt-1" .checked=${form.siteExports === value} @change=${() => this.set({ siteExports: value })}>
|
|
146
|
+
<span><span class="block text-sm font-medium text-foreground">${label}</span><span class="text-xs text-muted-foreground">${hint}</span></span>
|
|
147
|
+
</label>`)}${error('siteExports')}
|
|
148
|
+
</fieldset>` : null}` : null}
|
|
149
|
+
</fieldset>`;
|
|
150
|
+
}
|
|
151
|
+
}
|