@cossackframework/cms 0.0.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +21 -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 +709 -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 +114 -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 +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -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 +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -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 +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -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 +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** The permalink form used by the unified Settings page. */
|
|
2
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
3
|
+
import { Checkbox, Field, Input } from '@cossackframework/ui';
|
|
4
|
+
import { html, component } from '@cossackframework/renderer';
|
|
5
|
+
import { isCmsError, type Principal } from '@cossackframework/cms';
|
|
6
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
7
|
+
import type { SettingsDraft } from './settings-draft';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
interface Base { name: string; label: string; singular: string; path: string }
|
|
11
|
+
export interface PermalinkSettingsInput { postsAtRoot: boolean; postsBase: string; withCategory: boolean; bases: { name: string; path: string }[] }
|
|
12
|
+
export interface PermalinkSettingsData extends PermalinkSettingsInput { taxonomies: Base[]; origin: string }
|
|
13
|
+
export interface PermalinkSettingsResult { data: PermalinkSettingsData | null; error: string; fields: Record<string, string> }
|
|
14
|
+
const SEGMENT = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/;
|
|
15
|
+
|
|
16
|
+
export function loadPermalinkSettings(cms: CmsHost, origin: string): PermalinkSettingsData {
|
|
17
|
+
const posts = cms.collections().find(collection => collection.name === 'posts');
|
|
18
|
+
const taxonomies = cms.taxonomies.declarations.filter(taxonomy => taxonomy.path).map(taxonomy => ({ name: taxonomy.name, label: taxonomy.label, singular: taxonomy.singular, path: taxonomy.path! }));
|
|
19
|
+
return { postsAtRoot: posts?.path === '', postsBase: posts?.path || 'posts', withCategory: posts?.permalink === 'category', taxonomies, origin,
|
|
20
|
+
bases: taxonomies.map(({ name, path }) => ({ name, path })) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Called by the authorized page; CmsHost also checks schema-edit permissions. */
|
|
24
|
+
export async function savePermalinkSettings(cms: CmsHost, principal: Principal, input: PermalinkSettingsInput, origin: string): Promise<PermalinkSettingsResult> {
|
|
25
|
+
const fields: Record<string, string> = {};
|
|
26
|
+
try {
|
|
27
|
+
if (!input || typeof input.postsAtRoot !== 'boolean' || typeof input.postsBase !== 'string' || typeof input.withCategory !== 'boolean' || !Array.isArray(input.bases)
|
|
28
|
+
|| input.bases.some(entry => !entry || typeof entry.name !== 'string' || typeof entry.path !== 'string')) return { data: null, error: __('The permalink settings are invalid.'), fields };
|
|
29
|
+
const base = input.postsBase.trim().replace(/^\/+|\/+$/g, '');
|
|
30
|
+
if (!input.postsAtRoot && !SEGMENT.test(base)) fields.posts = __('Use lowercase letters, digits, hyphens and slashes.');
|
|
31
|
+
for (const entry of input.bases) if (!SEGMENT.test(entry.path.trim()) || entry.path.includes('/')) fields[entry.name] = __('Use lowercase letters, digits and hyphens.');
|
|
32
|
+
if (Object.keys(fields).length) return { data: null, error: __('Some permalinks are invalid.'), fields };
|
|
33
|
+
const posts = cms.collection('posts');
|
|
34
|
+
const path = input.postsAtRoot ? '' : base;
|
|
35
|
+
const permalink = input.withCategory && posts.taxonomies?.length ? 'category' as const : 'slug' as const;
|
|
36
|
+
if (posts.path !== path || (posts.permalink ?? 'slug') !== permalink) await cms.saveCollection({ ...posts, path, permalink }, principal);
|
|
37
|
+
for (const entry of input.bases) {
|
|
38
|
+
const taxonomy = cms.taxonomies.declaration(entry.name);
|
|
39
|
+
if (taxonomy.path !== entry.path.trim()) await cms.saveTaxonomy({ ...taxonomy, path: entry.path.trim() }, principal);
|
|
40
|
+
}
|
|
41
|
+
return { data: loadPermalinkSettings(cms, origin), error: '', fields };
|
|
42
|
+
} catch (error) { return { data: null, error: isCmsError(error) ? error.message : __('The permalinks could not be saved.'), fields }; }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type PermalinksSettingsProps = {
|
|
46
|
+
draft: SettingsDraft;
|
|
47
|
+
initial: PermalinkSettingsData;
|
|
48
|
+
fields?: readonly string[];
|
|
49
|
+
/** Field problems from the last save, by field name. */
|
|
50
|
+
errors?: Readonly<Record<string, string>>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const permalinkDraft = (data: PermalinkSettingsData): PermalinkSettingsInput => ({ postsAtRoot: data.postsAtRoot, postsBase: data.postsBase, withCategory: data.withCategory, bases: data.bases.map(base => ({ ...base })) });
|
|
54
|
+
|
|
55
|
+
@Component()
|
|
56
|
+
export class PermalinksSettings extends Cossack {
|
|
57
|
+
declare props: PermalinksSettingsProps;
|
|
58
|
+
@ClientState() private revision = 0;
|
|
59
|
+
private unsubscribe?: () => void;
|
|
60
|
+
|
|
61
|
+
onMount() {
|
|
62
|
+
this.props.draft.initializeSection('permalinks', permalinkDraft(this.props.initial));
|
|
63
|
+
this.unsubscribe = this.props.draft.subscribe(() => { this.revision++; });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onCleanup() { this.unsubscribe?.(); }
|
|
67
|
+
|
|
68
|
+
@Client()
|
|
69
|
+
set(patch: Partial<PermalinkSettingsInput>) {
|
|
70
|
+
const current = this.props.draft.section('permalinks', permalinkDraft(this.props.initial));
|
|
71
|
+
this.props.draft.setSection('permalinks', { ...current, ...patch });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Client()
|
|
75
|
+
setBase(name: string, path: string) {
|
|
76
|
+
const current = this.props.draft.section('permalinks', permalinkDraft(this.props.initial));
|
|
77
|
+
this.set({ bases: current.bases.map(base => base.name === name ? { ...base, path } : base) });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
render() {
|
|
81
|
+
const form = this.props.draft.section('permalinks', permalinkDraft(this.props.initial));
|
|
82
|
+
const show = (field: string) => !this.props.fields || this.props.fields.includes(`permalinks.${field}`);
|
|
83
|
+
const sample = (base: string) => `${this.props.initial.origin}${base}${form.withCategory ? '/sample-category' : ''}/sample-post`;
|
|
84
|
+
const option = (atRoot: boolean, label: string, example: string) => html`<label class="flex cursor-pointer items-start gap-3 rounded-md border border-border p-3 has-[:checked]:border-primary">
|
|
85
|
+
<input type="radio" name="posts-structure" class="mt-1" .checked=${form.postsAtRoot === atRoot} @change=${() => this.set({ postsAtRoot: atRoot })}>
|
|
86
|
+
<span><span class="block text-sm font-medium text-foreground">${label}</span><code class="break-all text-xs text-muted-foreground">${example}</code></span>
|
|
87
|
+
</label>`;
|
|
88
|
+
const taxonomies = this.props.initial.taxonomies.filter(taxonomy => show(`taxonomy.${taxonomy.name}`));
|
|
89
|
+
const errors = this.props.errors ?? {};
|
|
90
|
+
return html`<div class="space-y-5">
|
|
91
|
+
<p class="text-sm text-muted-foreground">${__('Choose the addresses of posts and archives. Old addresses redirect to the new ones.')}</p>
|
|
92
|
+
<fieldset class="min-w-0 space-y-5" ?disabled=${this.props.draft.saving}>
|
|
93
|
+
${show('posts') || show('postsBase') || show('category') ? html`<fieldset id="permalink-posts" class="min-w-0 space-y-3">
|
|
94
|
+
<legend class="mb-2 text-base font-semibold text-foreground">${__('Post permalinks')}</legend>
|
|
95
|
+
${show('posts') || show('postsBase') ? html`${option(true, __('Post name'), sample(''))}${option(false, __('Under a base'), sample(`/${form.postsBase.trim() || 'posts'}`))}` : null}
|
|
96
|
+
${show('category') ? component(Checkbox, { id: 'permalink-category', checked: form.withCategory, '@change': (event: Event) => this.set({ withCategory: (event.target as HTMLInputElement).checked }) },
|
|
97
|
+
html`<span><span class="block font-medium">${__('Category before the post name')}</span>
|
|
98
|
+
<span class="text-xs text-muted-foreground">${__('Use the first category before the post name. Posts without a category keep the plain address.')}</span></span>`) : null}
|
|
99
|
+
${(show('posts') || show('postsBase')) && !form.postsAtRoot ? component(Field, { label: __('Posts base'), for: 'posts-base', ...(errors.posts ? { error: errors.posts } : {}),
|
|
100
|
+
control: attributes => component(Input, { ...attributes, '.value': form.postsBase, '@input': (event: Event) => this.set({ postsBase: (event.target as HTMLInputElement).value }) }) }) : null}
|
|
101
|
+
</fieldset>` : null}
|
|
102
|
+
${taxonomies.length ? html`<fieldset class="min-w-0 space-y-3">
|
|
103
|
+
<legend class="mb-2 text-base font-semibold text-foreground">${__('Archive bases')}</legend>
|
|
104
|
+
${taxonomies.map(taxonomy => {
|
|
105
|
+
const path = form.bases.find(base => base.name === taxonomy.name)?.path ?? taxonomy.path;
|
|
106
|
+
return component(Field, { label: `${taxonomy.singular} ${__('base')}`, for: `base-${taxonomy.name}`, hint: `${this.props.initial.origin}/${path || '…'}/sample-${taxonomy.singular.toLowerCase()}`,
|
|
107
|
+
...(errors[taxonomy.name] ? { error: errors[taxonomy.name] } : {}), class: 'min-w-0 [&_.cs-field__hint]:break-all [&_.cs-field__hint]:font-mono',
|
|
108
|
+
control: attributes => component(Input, { ...attributes, '.value': path, '@input': (event: Event) => this.setBase(taxonomy.name, (event.target as HTMLInputElement).value) }) });
|
|
109
|
+
})}
|
|
110
|
+
</fieldset>` : null}
|
|
111
|
+
</fieldset>
|
|
112
|
+
</div>`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Select the section crossing the reading line, including the last short section. */
|
|
2
|
+
export function activeSettingsSection(sections: readonly { id: string; top: number }[], readingLine: number, atEnd: boolean): string | undefined {
|
|
3
|
+
if (atEnd) return sections.at(-1)?.id;
|
|
4
|
+
let current = sections[0]?.id;
|
|
5
|
+
for (const section of sections) {
|
|
6
|
+
if (section.top > readingLine + 1) break;
|
|
7
|
+
current = section.id;
|
|
8
|
+
}
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Searchable settings declarations. Saved values never enter the search index. */
|
|
2
|
+
import { PERMISSIONS } from '@cossackframework/cms';
|
|
3
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
4
|
+
|
|
5
|
+
export interface SettingsSearchEntry {
|
|
6
|
+
id: string;
|
|
7
|
+
groupId: string;
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
group: string;
|
|
11
|
+
description: string;
|
|
12
|
+
href: string;
|
|
13
|
+
/** Lowercase labels, descriptions, and keys used for matching. */
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The section shell is present before its field controls are mounted. */
|
|
18
|
+
export function settingsSectionId(groupId: string): string { return `settings-${encodeURIComponent(groupId)}`; }
|
|
19
|
+
|
|
20
|
+
export function settingsSectionHref(groupId: string): string { return `/dashboard/settings#${encodeURIComponent(settingsSectionId(groupId))}`; }
|
|
21
|
+
|
|
22
|
+
/** The calling page requires cms:settings. Include every group served by Settings, including non-JSON groups; `network` for the Network section. */
|
|
23
|
+
export function settingsSearchEntries(cms: CmsHost, options: { network?: boolean } = {}): SettingsSearchEntry[] {
|
|
24
|
+
const groups = cms.settings.groups.filter(group => (group.permission ?? PERMISSIONS.manageSettings) === PERMISSIONS.manageSettings);
|
|
25
|
+
const entries: SettingsSearchEntry[] = [];
|
|
26
|
+
for (const group of groups) {
|
|
27
|
+
const parent = groups.find(entry => entry.id === group.parent);
|
|
28
|
+
const label = [parent?.label, group.plugin ? 'Plugins' : '', group.label].filter(Boolean).join(' / ');
|
|
29
|
+
for (const [name, field] of Object.entries(group.fields)) {
|
|
30
|
+
const section = group.sections?.find(entry => entry.id === field.section);
|
|
31
|
+
const id = `${group.id}.${name}`;
|
|
32
|
+
entries.push({ id, groupId: group.id, name, label: field.label ?? name, group: label, description: field.description ?? '',
|
|
33
|
+
href: settingsSectionHref(group.id),
|
|
34
|
+
text: [id, label, group.plugin, group.description, section?.id, section?.label, section?.description, field.label, field.description,
|
|
35
|
+
...(field.values ?? []), ...Object.entries(field.choices ?? {}).flat()].filter(Boolean).join(' ').toLowerCase() });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Permalinks change collection and taxonomy declarations through their own form.
|
|
40
|
+
const permalink = (id: string, label: string, description: string, keywords = ''): SettingsSearchEntry => ({
|
|
41
|
+
id: `permalinks.${id}`, groupId: 'permalinks', name: id, label, group: 'Permalinks', description, href: settingsSectionHref('permalinks'),
|
|
42
|
+
text: ['permalinks', id, label, description, keywords].join(' ').toLowerCase(),
|
|
43
|
+
});
|
|
44
|
+
entries.push(
|
|
45
|
+
permalink('posts', 'Post permalinks', 'Choose the address structure for posts.', 'post name under a base slug URL'),
|
|
46
|
+
permalink('postsBase', 'Posts base', 'The address prefix before a post name.', 'path URL'),
|
|
47
|
+
permalink('category', 'Category before the post name', 'Include the first category in post addresses.', 'slug URL'),
|
|
48
|
+
);
|
|
49
|
+
for (const taxonomy of cms.taxonomies.declarations.filter(entry => entry.path)) {
|
|
50
|
+
entries.push(permalink(`taxonomy.${taxonomy.name}`, `${taxonomy.singular} base`,
|
|
51
|
+
`Address prefix for ${taxonomy.label.toLowerCase()} archives.`, `${taxonomy.name} ${taxonomy.label} archive bases path URL`));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The network's settings live in the network database and save through the network.
|
|
55
|
+
if (options.network) {
|
|
56
|
+
const network = (id: string, label: string, description: string, keywords = ''): SettingsSearchEntry => ({
|
|
57
|
+
id: `network.${id}`, groupId: 'network', name: id, label, group: 'Network', description, href: settingsSectionHref('network'),
|
|
58
|
+
text: ['network', id, label, description, keywords].join(' ').toLowerCase(),
|
|
59
|
+
});
|
|
60
|
+
entries.push(
|
|
61
|
+
network('enabled', 'Run a network of sites', 'Add sites with their own databases, addresses and members.', 'multisite enable disable on off'),
|
|
62
|
+
network('name', 'Network name', 'Shown on the network dashboard and the sign-in page.', 'title'),
|
|
63
|
+
network('subdomainSuffix', 'Addresses of new sites', 'The domain new sites start under.', 'subdomain suffix domain URL'),
|
|
64
|
+
network('defaultTheme', 'Theme of new sites', 'The theme new sites start with.', 'new sites appearance'),
|
|
65
|
+
network('defaultPlugins', 'Plugins enabled on new sites', 'Plugins new sites start with.', 'new sites'),
|
|
66
|
+
network('defaultLanguage', 'Language of new sites', 'The default language new sites start with.', 'new sites locale'),
|
|
67
|
+
network('siteExports', 'Site exports', 'Whether site admins export their own site or request it from a network admin.', 'database download backup export request approve'),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return entries;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** All query words must match. A blank query includes every field. */
|
|
74
|
+
export function searchSettings(entries: readonly SettingsSearchEntry[], query: string): SettingsSearchEntry[] {
|
|
75
|
+
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
76
|
+
return words.length ? entries.filter(entry => words.every(word => entry.text.includes(word))) : [...entries];
|
|
77
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Client, Component, Cossack } from '@cossackframework/core';
|
|
2
|
+
import { html, type TemplateResult } from '@cossackframework/renderer';
|
|
3
|
+
import { settingsSectionId } from './settings-search';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One section of the Settings page: its heading and its controls, in the shell the menu scrolls
|
|
7
|
+
* to. Every section renders its controls at once, so the whole catalog is on the page: search
|
|
8
|
+
* matches show without loading anything, and the layout is final when the menu scrolls to a
|
|
9
|
+
* section. `onConnect` tells the page where the section is, for the menu's current item.
|
|
10
|
+
*/
|
|
11
|
+
@Component()
|
|
12
|
+
export class SettingsSection extends Cossack {
|
|
13
|
+
declare props: { id: string; heading: TemplateResult; content: () => TemplateResult; onConnect?: (id: string, element: Element | undefined) => void };
|
|
14
|
+
private element?: Element;
|
|
15
|
+
|
|
16
|
+
@Client()
|
|
17
|
+
connect(element: Element | undefined) {
|
|
18
|
+
if (element === this.element) return;
|
|
19
|
+
this.element = element;
|
|
20
|
+
this.props.onConnect?.(this.props.id, element);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onCleanup() {
|
|
24
|
+
// Teardown also runs on the server after rendering. The parent's `onConnect` is a client
|
|
25
|
+
// method there, which cannot be sent from an HTTP render and would only log a warning.
|
|
26
|
+
if (this.isServer) return;
|
|
27
|
+
this.element = undefined;
|
|
28
|
+
this.props.onConnect?.(this.props.id, undefined);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
return html`<section id=${settingsSectionId(this.props.id)} ref=${this.connect} data-settings-section=${this.props.id}
|
|
33
|
+
data-settings-loaded="true" class="min-w-0 space-y-4" style="scroll-margin-top:calc(var(--settings-toolbar-height, 56px) + 24px)">
|
|
34
|
+
${this.props.heading}
|
|
35
|
+
${this.props.content()}
|
|
36
|
+
</section>`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser's part of share buttons: the copy button puts the page's address on the
|
|
3
|
+
* clipboard and says so for a moment; the links open their networks in a small window.
|
|
4
|
+
*/
|
|
5
|
+
const enhanced = new WeakSet<HTMLElement>();
|
|
6
|
+
|
|
7
|
+
export function enhanceShare(root: HTMLElement): void {
|
|
8
|
+
if (enhanced.has(root)) return;
|
|
9
|
+
enhanced.add(root);
|
|
10
|
+
for (const button of root.querySelectorAll<HTMLButtonElement>('button[data-network="copy"]')) {
|
|
11
|
+
button.addEventListener('click', async () => {
|
|
12
|
+
const url = button.dataset.url || location.href;
|
|
13
|
+
try {
|
|
14
|
+
await navigator.clipboard.writeText(url);
|
|
15
|
+
button.setAttribute('data-copied', '');
|
|
16
|
+
setTimeout(() => button.removeAttribute('data-copied'), 2000);
|
|
17
|
+
} catch { /* the clipboard is unavailable: the address stays in the bar */ }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
for (const link of root.querySelectorAll<HTMLAnchorElement>('a[data-network][target="_blank"]')) {
|
|
21
|
+
link.addEventListener('click', event => {
|
|
22
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey || event.button !== 0) return;
|
|
23
|
+
const popup = window.open(link.href, 'cms-share', 'width=640,height=560,noopener,noreferrer');
|
|
24
|
+
if (popup) event.preventDefault();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server helpers for editing an entry on the public site. Every call checks again that the
|
|
3
|
+
* signed-in user may update the entry; drafts render like previews and save through the
|
|
4
|
+
* dashboard editor's save, with its revision check.
|
|
5
|
+
*/
|
|
6
|
+
import { CmsError, flattenBlocks, hasPermission, participantColor, PERMISSIONS, recordTitle, richTextBlocks, type Block, type CollectionDefinition, type EntryView, type Principal, type RecordShape, type RichTextDoc } from '@cossackframework/cms';
|
|
7
|
+
import type { FormRequest } from './site-forms';
|
|
8
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
9
|
+
import { blockOptions, editorView, entryInput, entryValues, findMedia, mediaPreviews, saveEntry, sourceChoices } from './content';
|
|
10
|
+
import { blocksInput, editorBlocks, type BlockOption, type EditorBlock, type EditorValues, type EditorView } from './editor';
|
|
11
|
+
import { closedChooser } from './media-chooser';
|
|
12
|
+
import { activePresets, entryViews } from './site';
|
|
13
|
+
import type { DraftBlock, SiteDocument, SiteDraft, SiteEditable } from './site-editor';
|
|
14
|
+
|
|
15
|
+
/** The entry when the principal may update it, read as them; otherwise null. */
|
|
16
|
+
export async function editableRecord(cms: CmsHost, collection: string, id: string, principal: Principal): Promise<{ collection: CollectionDefinition; record: RecordShape } | null> {
|
|
17
|
+
if (principal.kind !== 'user') return null;
|
|
18
|
+
try {
|
|
19
|
+
const definition = cms.collection(collection);
|
|
20
|
+
const repository = cms.resource(`cms/${definition.name}`);
|
|
21
|
+
const record = await repository.get(id, { principal });
|
|
22
|
+
return record && repository.canUpdate(record, principal) ? { collection: definition, record } : null;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error instanceof CmsError) return null;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The bar's links for an entry the principal may edit, or null. */
|
|
30
|
+
export async function siteEditable(cms: CmsHost, collection: string, id: string, principal: Principal): Promise<SiteEditable | null> {
|
|
31
|
+
const found = await editableRecord(cms, collection, id, principal);
|
|
32
|
+
return found ? { collection: found.collection.name, id, dashboard: `/dashboard/content/${found.collection.name}/${id}` } : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Who a new note could mention: the site's active users other than the viewer, by name. Their
|
|
37
|
+
* email addresses show only to a viewer who may manage users (anyone who may edit one entry
|
|
38
|
+
* opens this list); a user without a name is listed as such.
|
|
39
|
+
*/
|
|
40
|
+
export async function mentionableUsers(cms: CmsHost, principal: Principal): Promise<{ id: string; name: string }[]> {
|
|
41
|
+
if (principal.kind !== 'user') return [];
|
|
42
|
+
const emails = hasPermission(principal, PERMISSIONS.manageUsers);
|
|
43
|
+
const users = (await cms.users.list({ limit: 100 }).catch(() => ({ items: [] }))).items;
|
|
44
|
+
return users.filter(user => user.id !== principal.id && user.status === 'active')
|
|
45
|
+
.map(user => ({ id: user.id, name: user.name || (emails ? user.email : __('Unnamed user')) }));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A draft of the saved entry: its editor view and control values, blocks' data as control values too. */
|
|
49
|
+
export async function siteDraft(cms: CmsHost, collection: CollectionDefinition, record: RecordShape, principal: Principal): Promise<SiteDraft> {
|
|
50
|
+
const view = await editorView(cms, collection.name, principal);
|
|
51
|
+
const values = await entryValues(cms, view, record);
|
|
52
|
+
const blocksField = view.fields.find(field => field.kind === 'blocks')?.name ?? null;
|
|
53
|
+
const bodyField = view.fields.find(field => field.name === 'body' && field.kind === 'richtext')?.name ?? view.fields.find(field => field.kind === 'richtext')?.name ?? null;
|
|
54
|
+
if (blocksField) values[blocksField] = editorBlocks((values[blocksField] as DraftBlock[] | undefined) ?? [], view.blocks);
|
|
55
|
+
const references: SiteDraft['references'] = {};
|
|
56
|
+
for (const field of view.fields.filter(entry => entry.kind === 'reference')) {
|
|
57
|
+
const page = await cms.resource(field.target).list({ limit: 100 }, { principal }).catch(() => ({ records: [] as RecordShape[] }));
|
|
58
|
+
const target = cms.resourceById(field.target);
|
|
59
|
+
references[field.name] = page.records.filter(entry => entry.id !== record.id).map(entry => ({ id: entry.id, title: recordTitle(entry, target.titleField) }));
|
|
60
|
+
}
|
|
61
|
+
// The entry's notes, with who wrote them, and who a new note could mention.
|
|
62
|
+
const me = principal.kind === 'user' ? principal.id : '';
|
|
63
|
+
const notes = await cms.notes.forEntry(`cms/${collection.name}`, record.id).catch(() => []);
|
|
64
|
+
const users = await cms.users.getMany([...new Set([me, ...notes.map(note => note.userId)].filter(Boolean))]);
|
|
65
|
+
const mentionable = await mentionableUsers(cms, principal);
|
|
66
|
+
return {
|
|
67
|
+
collection: collection.name, id: record.id, rev: record.rev, view, values, previews: await mediaPreviews(cms, values, view), references,
|
|
68
|
+
blocksField, bodyField, documents: await pageDocuments(cms, view, values, principal), changed: false, error: '', errors: {}, conflict: false, chooser: closedChooser(),
|
|
69
|
+
notes, people: Object.fromEntries([...users.values()].map(user => [user.id, { user: user.id, name: user.name || user.email, avatar: user.avatar, color: participantColor(user.id) }])),
|
|
70
|
+
me, admin: hasPermission(principal, PERMISSIONS.manageUsers), mentionable,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A draft without an entry, for a page that is a list (the home page's latest posts, an archive,
|
|
76
|
+
* a term): the frame alone is edited, through the areas and the patterns on the page. Only for
|
|
77
|
+
* users who may change areas; null otherwise.
|
|
78
|
+
*/
|
|
79
|
+
export async function frameDraft(cms: CmsHost, principal: Principal): Promise<SiteDraft | null> {
|
|
80
|
+
if (principal.kind !== 'user' || !hasPermission(principal, PERMISSIONS.manageAppearance)) return null;
|
|
81
|
+
const view: EditorView = {
|
|
82
|
+
resource: '', route: '', label: '', singular: '', titleField: '', titleRequired: false, slug: false, publishable: false, hierarchical: false, path: null,
|
|
83
|
+
fields: [], restricted: [], taxonomies: [], blocks: await blockOptions(cms), presets: await activePresets(cms), template: [], groups: [], layout: { tabs: [], sidebar: [] }, collections: [], sources: await sourceChoices(cms),
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
collection: '', id: '', rev: 0, view, values: {}, previews: {}, references: {}, blocksField: null, bodyField: null,
|
|
87
|
+
documents: await pageDocuments(cms, view, {}, principal), changed: false, error: '', errors: {}, conflict: false, chooser: closedChooser(),
|
|
88
|
+
notes: [], people: {}, me: principal.id, admin: hasPermission(principal, PERMISSIONS.manageUsers), mentionable: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The page's documents beside the entry: the active theme's areas, then the synced patterns the
|
|
94
|
+
* page shows, in the entry's blocks and rich text, in the areas and in the menus' panels.
|
|
95
|
+
*/
|
|
96
|
+
export async function pageDocuments(cms: CmsHost, view: EditorView, values: EditorValues, principal: Principal): Promise<SiteDocument[]> {
|
|
97
|
+
const areas = await siteDocuments(cms, view.blocks, principal);
|
|
98
|
+
const ids = new Set<string>();
|
|
99
|
+
const collect = (blocks: readonly Block[]) => { for (const block of flattenBlocks(blocks)) if (block.type === 'core/pattern' && typeof block.data.pattern === 'string' && block.data.pattern) ids.add(block.data.pattern); };
|
|
100
|
+
for (const field of view.fields) {
|
|
101
|
+
const value = values[field.name];
|
|
102
|
+
if (field.kind === 'blocks' && Array.isArray(value)) collect(value as Block[]);
|
|
103
|
+
if (field.kind === 'richtext') for (const doc of Array.isArray(value) ? value : [value]) if (doc && typeof doc === 'object') collect(richTextBlocks(doc as RichTextDoc));
|
|
104
|
+
}
|
|
105
|
+
for (const area of areas) collect(area.blocks as Block[]);
|
|
106
|
+
const locations = (await cms.menuLocations()).filter(location => location.active).map(location => location.name);
|
|
107
|
+
for (const location of locations) {
|
|
108
|
+
const items = await cms.menus.forLocation(location).catch(() => null);
|
|
109
|
+
const visit = (list: readonly { panel: string | null; children: readonly unknown[] }[]) => { for (const item of list) { if (item.panel) ids.add(item.panel); visit(item.children as never); } };
|
|
110
|
+
if (items) visit(items);
|
|
111
|
+
}
|
|
112
|
+
return [...areas, ...await patternDocuments(cms, [...ids], view.blocks, principal)];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Synced patterns as documents: their blocks as control values, editable when the user may update the pattern. */
|
|
116
|
+
async function patternDocuments(cms: CmsHost, ids: readonly string[], options: readonly BlockOption[], principal: Principal): Promise<SiteDocument[]> {
|
|
117
|
+
if (!ids.length) return [];
|
|
118
|
+
const repository = cms.resource('cms/patterns');
|
|
119
|
+
let records: Map<string, RecordShape>;
|
|
120
|
+
try { records = await repository.getMany(ids.slice(0, 50), { principal }); }
|
|
121
|
+
catch (error) { if (error instanceof CmsError) return []; throw error; }
|
|
122
|
+
return ids.flatMap(id => {
|
|
123
|
+
const record = records.get(id);
|
|
124
|
+
if (!record || !Array.isArray(record.content)) return [];
|
|
125
|
+
return [{ key: `pattern:${id}`, kind: 'pattern' as const, name: id, label: recordTitle(record, 'title'), revision: record.rev, blocks: editorBlocks(record.content as EditorBlock[], options), editable: repository.canUpdate(record, principal), changed: false, error: '', conflict: false }];
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The active theme's widget areas as documents the editor edits beside the entry: the saved
|
|
131
|
+
* blocks, or the theme's defaults, as control values. Editable with `cms:appearance`.
|
|
132
|
+
*/
|
|
133
|
+
export async function siteDocuments(cms: CmsHost, options: readonly BlockOption[], principal: Principal): Promise<SiteDocument[]> {
|
|
134
|
+
const editable = principal.kind === 'user' && hasPermission(principal, PERMISSIONS.manageAppearance);
|
|
135
|
+
const saved = await cms.areas.all().catch(() => new Map<string, { readonly blocks: readonly Block[]; readonly revision: number }>());
|
|
136
|
+
return (await cms.areaLocations()).filter(area => area.active).map(area => {
|
|
137
|
+
const stored = saved.get(area.name);
|
|
138
|
+
return { key: `area:${area.name}`, kind: 'area' as const, name: area.name, label: area.label, revision: stored?.revision ?? 0, blocks: editorBlocks((stored?.blocks ?? area.defaults) as EditorBlock[], options), editable, changed: false, error: '', conflict: false };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Save the changed documents, each over the revision it started from. A conflict or an error stays on its document; the others still save. */
|
|
143
|
+
export async function saveDocuments(cms: CmsHost, documents: readonly SiteDocument[], options: readonly BlockOption[], principal: Principal): Promise<SiteDocument[]> {
|
|
144
|
+
const types = new Map(options.map(option => [option.name, option]));
|
|
145
|
+
const known = (await cms.areaLocations()).map(area => area.name);
|
|
146
|
+
const result: SiteDocument[] = [];
|
|
147
|
+
for (const document of documents) {
|
|
148
|
+
if (!document.changed || !document.editable) { result.push(document); continue; }
|
|
149
|
+
const converted = blocksInput(document.blocks, types);
|
|
150
|
+
if ('error' in converted) { result.push({ ...document, error: converted.error }); continue; }
|
|
151
|
+
try {
|
|
152
|
+
if (document.kind === 'pattern') {
|
|
153
|
+
const record = await cms.resource('cms/patterns').update(document.name, { content: converted.value }, { principal, expectedRevision: document.revision });
|
|
154
|
+
result.push({ ...document, revision: record.rev, blocks: editorBlocks((record.content ?? []) as EditorBlock[], options), changed: false, error: '', conflict: false });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const saved = await cms.areas.save(document.name, converted.value, { principal, expectedRevision: document.revision, known });
|
|
158
|
+
result.push({ ...document, revision: saved.revision, blocks: editorBlocks(saved.blocks as EditorBlock[], options), changed: false, error: '', conflict: false });
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (!(error instanceof CmsError)) throw error;
|
|
161
|
+
result.push({ ...document, error: error.message, conflict: error.code === 'CMS_CONFLICT' });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Blocks as the site previews them, converted from the editor's control values, by area name or pattern ID; a list that does not convert keeps what is saved. */
|
|
168
|
+
export function areaDraftBlocks(areas: readonly { name: string; blocks: EditorBlock[] }[], options: readonly BlockOption[]): Map<string, readonly Block[]> {
|
|
169
|
+
const types = new Map(options.map(option => [option.name, option]));
|
|
170
|
+
const drafts = new Map<string, readonly Block[]>();
|
|
171
|
+
for (const area of areas) {
|
|
172
|
+
const converted = blocksInput(area.blocks, types);
|
|
173
|
+
if (!('error' in converted)) drafts.set(area.name, converted.value as unknown as Block[]);
|
|
174
|
+
}
|
|
175
|
+
return drafts;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The editor's pattern drafts as the site previews them (`patternDrafts` of the views). */
|
|
179
|
+
export function patternDraftBlocks(patterns: readonly { id: string; blocks: EditorBlock[] }[], options: readonly BlockOption[]): Map<string, readonly Block[]> {
|
|
180
|
+
return areaDraftBlocks(patterns.map(pattern => ({ name: pattern.id, blocks: pattern.blocks })), options);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The entry as the site shows it with the draft's values, like a preview, with its forms and the
|
|
185
|
+
* draft's patterns. Callers have checked the principal may edit the entry, so nothing of it is
|
|
186
|
+
* locked: a members-only or protected entry shows its content to its editor. Invalid values throw.
|
|
187
|
+
*/
|
|
188
|
+
export async function draftEntry(cms: CmsHost, collection: CollectionDefinition, record: RecordShape, values: EditorValues, forms?: FormRequest, documents: readonly SiteDocument[] = [], options: readonly BlockOption[] = []): Promise<EntryView> {
|
|
189
|
+
const input = await entryInput(cms, collection.name, values);
|
|
190
|
+
// Typed tags are names until the save creates their terms; the preview keeps the saved ones.
|
|
191
|
+
for (const name of Object.keys(input)) if (cms.resourceById(`cms/${collection.name}`).fields[name]?.taxonomy) delete input[name];
|
|
192
|
+
const patterns = documents.filter(document => document.kind === 'pattern' && document.changed);
|
|
193
|
+
return (await entryViews(cms, collection, [{ ...record, ...input }], { full: true, editable: new Set([record.id]), ...(forms ? { forms } : {}), ...(patterns.length ? { patternDrafts: patternDraftBlocks(patterns.map(pattern => ({ id: pattern.name, blocks: pattern.blocks })), options) } : {}) }))[0]!;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The block options a draft's documents are checked and saved with, as the host has them for
|
|
198
|
+
* this principal: the draft itself is page state the client sends back, so never its copy.
|
|
199
|
+
*/
|
|
200
|
+
export async function draftBlockOptions(cms: CmsHost, draft: Pick<SiteDraft, 'collection'>, principal: Principal): Promise<BlockOption[]> {
|
|
201
|
+
if (!draft.collection) return principal.kind === 'user' && hasPermission(principal, PERMISSIONS.manageAppearance) ? blockOptions(cms) : [];
|
|
202
|
+
return (await editorView(cms, draft.collection, principal)).blocks;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Save the draft over the revision it started from. A newer save makes a CMS_CONFLICT. */
|
|
206
|
+
export function saveDraft(cms: CmsHost, draft: Pick<SiteDraft, 'collection' | 'id' | 'rev'>, values: EditorValues, principal: Principal): Promise<RecordShape> {
|
|
207
|
+
return saveEntry(cms, draft.collection, draft.id, values, 'update', draft.rev, principal);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Files for the media chooser of the draft's editor: someone who may edit the entry, or for a
|
|
212
|
+
* frame-only draft (areas and patterns), someone who may change the site's appearance. The draft
|
|
213
|
+
* comes from the page's state, which the client sends back, so it is checked here, not trusted.
|
|
214
|
+
*/
|
|
215
|
+
export async function draftMedia(cms: CmsHost, draft: Pick<SiteDraft, 'collection' | 'id'>, search: string, principal: Principal, kind = '') {
|
|
216
|
+
if (principal.kind !== 'user') return null;
|
|
217
|
+
const allowed = draft.collection ? Boolean(await editableRecord(cms, draft.collection, draft.id, principal)) : hasPermission(principal, PERMISSIONS.manageAppearance);
|
|
218
|
+
return allowed ? findMedia(cms, search, kind) : null;
|
|
219
|
+
}
|