@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,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forms on the site: `core/form` and the input blocks, as plain HTML that posts without
|
|
3
|
+
* JavaScript. The server checks every post; in the browser `form.client.ts` applies the
|
|
4
|
+
* form's conditions as values change and shows the same errors before sending. Client-safe.
|
|
5
|
+
* A theme overrides any of these through its `blocks`, and can call them to wrap them.
|
|
6
|
+
*/
|
|
7
|
+
import { component, html, ifDefined, unsafeHTML, type TemplateResult } from '@cossackframework/renderer';
|
|
8
|
+
import { Turnstile } from '@cossackframework/ui';
|
|
9
|
+
import { acceptList, FORM_FILE_LIMIT, FORM_FILE_MAX_MB, type Block, type FormView, type InputView, type RenderedBlock, type ThemeHelpers } from '@cossackframework/cms';
|
|
10
|
+
|
|
11
|
+
export const FORM_INPUT = 'w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring aria-[invalid=true]:border-destructive';
|
|
12
|
+
const LABEL = 'block text-sm font-medium text-foreground';
|
|
13
|
+
const HELP = 'text-xs text-muted-foreground';
|
|
14
|
+
const ERROR = 'text-xs text-destructive empty:hidden';
|
|
15
|
+
|
|
16
|
+
/** What the browser's checks need: the blocks without their rendered parts. */
|
|
17
|
+
function plainBlocks(blocks: readonly RenderedBlock[]): Block[] {
|
|
18
|
+
return blocks.map(block => ({ _id: block._id, type: block.type, data: block.data, ...(block.when ? { when: block.when } : {}), ...(block.children ? { children: plainBlocks(block.children) } : {}) }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Load the browser's part once a form is on the page. Server rendering skips it. */
|
|
22
|
+
function enhance(element: Element | undefined): void {
|
|
23
|
+
if (!element || typeof window === 'undefined') return;
|
|
24
|
+
void import('./form.client').then(module => module.enhanceForm(element as HTMLFormElement)).catch(() => undefined);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A `core/form` block: the form, or its confirmation after a post, or why it takes nothing.
|
|
29
|
+
* The trap field catches bots; `_started` lets the server spot posts faster than people type.
|
|
30
|
+
*/
|
|
31
|
+
export function formBlock(block: RenderedBlock, helpers: ThemeHelpers): TemplateResult | null {
|
|
32
|
+
const form: FormView | undefined = block.form;
|
|
33
|
+
if (!form) return null;
|
|
34
|
+
const anchor = `form-${form.slug}`;
|
|
35
|
+
if (form.notice?.kind === 'success') return html`<div id=${anchor} role="status" class="cms-form cms-form-done rounded-md border border-border bg-muted px-4 py-3 text-sm text-foreground [&_p]:my-1">${unsafeHTML(form.notice.html)}</div>`;
|
|
36
|
+
if (form.closed !== null) return html`<div id=${anchor} class="cms-form rounded-md border border-border px-4 py-3 text-sm text-muted-foreground [&_p]:my-1">${unsafeHTML(form.closed)}</div>`;
|
|
37
|
+
if (form.signInUrl) return html`<p id=${anchor} class="cms-form text-sm text-muted-foreground"><a href=${form.signInUrl} class="text-primary hover:underline">${__('Log in')}</a> ${__('to send this form.')}</p>`;
|
|
38
|
+
// A form with a file upload posts multipart, so the files go along.
|
|
39
|
+
const enctype = Object.values(form.kinds).includes('file') ? 'multipart/form-data' : undefined;
|
|
40
|
+
return html`<form id=${anchor} method="post" action=${form.action} enctype=${ifDefined(enctype)} novalidate class="cms-form space-y-4" aria-label=${form.title}
|
|
41
|
+
data-cms-form=${form.slug} data-blocks=${JSON.stringify(plainBlocks(form.blocks))} data-kinds=${JSON.stringify(form.kinds)} ref=${enhance}>
|
|
42
|
+
<input type="hidden" name="_page" value=${form.page}>
|
|
43
|
+
<input type="hidden" name="_started" value=${String(form.startedAt)}>
|
|
44
|
+
<div aria-hidden="true" class="cms-form-trap"><label>${__('Leave this empty')} <input type="text" name="_website" tabindex="-1" autocomplete="off"></label></div>
|
|
45
|
+
<div data-cms-form-done role="status" hidden class="rounded-md border border-border bg-muted px-4 py-3 text-sm text-foreground [&_p]:my-1"></div>
|
|
46
|
+
<div data-cms-form-fields class="cms-form-fields">
|
|
47
|
+
${form.notice?.kind === 'error' ? html`<div role="alert" data-cms-server-error class="rounded-md border border-destructive/50 px-3 py-2 text-sm text-destructive [&_p]:my-0">${unsafeHTML(form.notice.html)}</div>` : null}
|
|
48
|
+
<p role="alert" data-cms-form-error class="rounded-md border border-destructive/50 px-3 py-2 text-sm text-destructive empty:hidden"></p>
|
|
49
|
+
${form.blocks.map(child => helpers.block(child))}
|
|
50
|
+
${form.turnstileSiteKey ? component(Turnstile, { id: `${anchor}-verify`, siteKey: form.turnstileSiteKey, action: 'form', label: __('Bot protection') }) : null}
|
|
51
|
+
<button type="submit" data-cms-form-submit class="rounded-md border-none bg-primary px-4 py-2 text-sm font-medium text-primary-foreground cursor-pointer disabled:opacity-60">${form.submitLabel}</button>
|
|
52
|
+
</div>
|
|
53
|
+
</form>`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** An input's width when it shares its row (`data-width`); none for a full-width input. */
|
|
57
|
+
const inputWidth = (block: RenderedBlock): 'half' | 'third' | undefined => block.data.width === 'half' || block.data.width === 'third' ? block.data.width : undefined;
|
|
58
|
+
const text = (block: RenderedBlock, name: string): string => typeof block.data[name] === 'string' ? block.data[name] as string : '';
|
|
59
|
+
const number = (block: RenderedBlock, name: string): number | undefined => typeof block.data[name] === 'number' ? block.data[name] as number : undefined;
|
|
60
|
+
|
|
61
|
+
const BUTTON = 'rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium text-foreground cursor-pointer hover:bg-muted disabled:cursor-default disabled:opacity-50';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A repeater: its rows, each a bordered group of the row's blocks with a Remove button, an
|
|
65
|
+
* Add button, and a hidden template row with its inputs disabled, which the page's script
|
|
66
|
+
* copies. Without the script, Add and Remove post the form back and it returns with the
|
|
67
|
+
* rows changed; the server validates nothing for those posts.
|
|
68
|
+
*/
|
|
69
|
+
function repeaterBlock(block: RenderedBlock, helpers: ThemeHelpers | undefined, parts: { label: TemplateResult; help: TemplateResult | null; errors: TemplateResult; width: string | undefined }): TemplateResult {
|
|
70
|
+
const input = block.input!;
|
|
71
|
+
const view = block.repeater!;
|
|
72
|
+
const name = input.name;
|
|
73
|
+
const renderRow = (child: RenderedBlock) => helpers ? helpers.block(child) : inputBlock(child);
|
|
74
|
+
const row = (entry: { readonly id: string; readonly blocks: readonly RenderedBlock[] }, index: number, template = false) => html`<div data-cms-row=${entry.id} class="cms-repeater-row space-y-3 rounded-md border border-border p-3" ?hidden=${template} ?data-cms-row-template=${template}>
|
|
75
|
+
<div class="flex items-center justify-between gap-2">
|
|
76
|
+
<p class="text-sm font-medium text-foreground">${view.rowLabel || text(block, 'label') || name} <span data-cms-row-index>${index}</span></p>
|
|
77
|
+
<button type="submit" name="_remove" value=${`${name}.${entry.id}`} formnovalidate data-cms-row-remove ?disabled=${template} class=${BUTTON}>${__('Remove')}</button>
|
|
78
|
+
</div>
|
|
79
|
+
${template ? html`<fieldset disabled class="contents">${entry.blocks.map(renderRow)}</fieldset>` : entry.blocks.map(renderRow)}
|
|
80
|
+
</div>`;
|
|
81
|
+
return html`<fieldset class="cms-field cms-repeater space-y-3" data-input=${input.key} data-width=${ifDefined(parts.width)} data-cms-repeater=${name} data-min=${String(view.min)} data-max=${String(view.max)}>
|
|
82
|
+
<legend class=${LABEL}>${parts.label}</legend>${parts.help}
|
|
83
|
+
<div data-cms-rows class="space-y-3">${view.rows.map((entry, index) => row(entry, index + 1))}</div>
|
|
84
|
+
${row({ id: '__row__', blocks: view.template }, 0, true)}
|
|
85
|
+
<div><button type="submit" name="_add" value=${name} formnovalidate data-cms-row-add ?disabled=${view.rows.length >= view.max} class=${BUTTON}>${view.addLabel}</button></div>
|
|
86
|
+
${parts.errors}
|
|
87
|
+
</fieldset>`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The control of a text-like kind: a textarea for paragraph text, an input typed by the kind otherwise. */
|
|
91
|
+
function textControl(block: RenderedBlock, input: InputView, state: { readonly id: string; readonly value: string; readonly invalid: string | undefined; readonly described: string; readonly label?: string; readonly required: boolean }): TemplateResult {
|
|
92
|
+
if (block.type === 'form/textarea') return html`<textarea id=${state.id} name=${input.name} rows=${number(block, 'rows') ?? 5} placeholder=${ifDefined(text(block, 'placeholder') || undefined)}
|
|
93
|
+
minlength=${ifDefined(number(block, 'minLength'))} maxlength=${ifDefined(number(block, 'maxLength'))} ?required=${state.required} aria-label=${ifDefined(state.label)}
|
|
94
|
+
aria-describedby=${state.described} aria-invalid=${ifDefined(state.invalid)} class=${FORM_INPUT} .value=${state.value}></textarea>`;
|
|
95
|
+
const type = input.kind === 'email' ? 'email' : input.kind === 'url' ? 'url' : input.kind === 'phone' ? 'tel' : input.kind === 'number' ? 'number' : input.kind === 'date' ? 'date' : 'text';
|
|
96
|
+
const autocomplete = input.kind === 'email' ? 'email' : input.kind === 'phone' ? 'tel' : input.kind === 'url' ? 'url' : undefined;
|
|
97
|
+
return html`<input id=${state.id} name=${input.name} type=${type} value=${state.value} placeholder=${ifDefined(text(block, 'placeholder') || undefined)}
|
|
98
|
+
minlength=${ifDefined(number(block, 'minLength'))} maxlength=${ifDefined(number(block, 'maxLength'))} pattern=${ifDefined(text(block, 'pattern') || undefined)}
|
|
99
|
+
min=${ifDefined(number(block, 'min') ?? (text(block, 'min') || undefined))} max=${ifDefined(number(block, 'max') ?? (text(block, 'max') || undefined))}
|
|
100
|
+
step=${ifDefined(number(block, 'step') ?? (input.kind === 'number' ? 'any' : undefined))}
|
|
101
|
+
autocomplete=${ifDefined(autocomplete)} ?required=${state.required} aria-label=${ifDefined(state.label)} aria-describedby=${state.described} aria-invalid=${ifDefined(state.invalid)} class=${FORM_INPUT}>`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A multiple input: one control per item, each with a Remove button and its own error, an
|
|
106
|
+
* Add button, and a hidden template item with its control disabled, which the page's script
|
|
107
|
+
* copies. Items are numbered by position; the script renumbers them after a change. Without
|
|
108
|
+
* the script, Add and Remove post the form back and it returns with the items changed.
|
|
109
|
+
*/
|
|
110
|
+
function multipleField(block: RenderedBlock, input: InputView, parts: { label: TemplateResult; help: TemplateResult | null; errors: TemplateResult; width: string | undefined }): TemplateResult {
|
|
111
|
+
const items = input.items!;
|
|
112
|
+
const label = text(block, 'label') || input.name;
|
|
113
|
+
const item = (value: string, index: number, error: string, template = false) => {
|
|
114
|
+
const key = `${input.key}.${index}`;
|
|
115
|
+
const id = `${input.id}-${index}`;
|
|
116
|
+
const control = textControl(block, input, { id, value, invalid: error ? 'true' : undefined, described: `${id}-error`, label: `${label} ${index}`, required: false });
|
|
117
|
+
return html`<div data-cms-item class="cms-item flex items-start gap-2" ?hidden=${template} ?data-cms-item-template=${template}>
|
|
118
|
+
<div class="min-w-0 flex-1 space-y-1">
|
|
119
|
+
${template ? html`<fieldset disabled class="contents">${control}</fieldset>` : control}
|
|
120
|
+
${error ? html`<p class=${ERROR} data-cms-server-error=${key}>${error}</p>` : null}<p id=${`${id}-error`} class=${ERROR} data-cms-error=${key}></p>
|
|
121
|
+
</div>
|
|
122
|
+
<button type="submit" name="_remove" value=${key} formnovalidate data-cms-item-remove ?disabled=${template || items.values.length <= items.min} aria-label=${`${__('Remove')} ${label} ${index}`} class=${BUTTON}>${__('Remove')}</button>
|
|
123
|
+
</div>`;
|
|
124
|
+
};
|
|
125
|
+
return html`<fieldset class="cms-field cms-multiple space-y-2" data-input=${input.key} data-width=${ifDefined(parts.width)} data-cms-multiple=${input.key} data-id=${input.id} data-min=${String(items.min)} data-max=${String(items.max)}>
|
|
126
|
+
<legend class=${LABEL}>${parts.label}</legend>${parts.help}
|
|
127
|
+
<div data-cms-items class="space-y-2">${items.values.map((value, index) => item(value, index + 1, items.errors[index] ?? ''))}</div>
|
|
128
|
+
${item('', 0, '', true)}
|
|
129
|
+
<div><button type="submit" name="_add" value=${input.key} formnovalidate data-cms-item-add ?disabled=${items.values.length >= items.max} class=${BUTTON}>${items.addLabel}</button></div>
|
|
130
|
+
${parts.errors}
|
|
131
|
+
</fieldset>`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A file upload: one file control, taking several files when the block allows them, with
|
|
136
|
+
* its allowed types and limits under it. A page cannot fill it in again, so after a post
|
|
137
|
+
* that came back with errors the visitor chooses the files again.
|
|
138
|
+
*/
|
|
139
|
+
function fileField(block: RenderedBlock, input: InputView, parts: { label: TemplateResult; help: TemplateResult | null; errors: TemplateResult; described: string; invalid: string | undefined; required: boolean; width: string | undefined }): TemplateResult {
|
|
140
|
+
const accept = acceptList(block.data.accept);
|
|
141
|
+
const several = block.data.multipleFiles === true;
|
|
142
|
+
const most = Math.min(number(block, 'maxFiles') ?? FORM_FILE_LIMIT, FORM_FILE_LIMIT);
|
|
143
|
+
const largest = Math.min(number(block, 'maxSize') ?? FORM_FILE_MAX_MB, FORM_FILE_MAX_MB);
|
|
144
|
+
const limits = [accept.join(', '), `${__('up to')} ${largest} MB${several ? ` ${__('each')}` : ''}`, several ? `${__('at most')} ${most} ${__('files')}` : ''].filter(Boolean).join(' · ');
|
|
145
|
+
return html`<div class="cms-field space-y-1" data-input=${input.key} data-width=${ifDefined(parts.width)}>
|
|
146
|
+
<label for=${input.id} class=${LABEL}>${parts.label}</label>
|
|
147
|
+
<input type="file" id=${input.id} name=${input.name} accept=${ifDefined(accept.length ? accept.join(',') : undefined)} ?multiple=${several} ?required=${parts.required}
|
|
148
|
+
aria-describedby=${`${input.id}-limits ${parts.described}`} aria-invalid=${ifDefined(parts.invalid)}
|
|
149
|
+
class="block w-full text-sm text-foreground file:mr-3 file:rounded-md file:border file:border-solid file:border-input file:bg-background file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-foreground file:cursor-pointer hover:file:bg-muted aria-[invalid=true]:text-destructive">
|
|
150
|
+
<p id=${`${input.id}-limits`} class=${HELP}>${limits}</p>${parts.help}${parts.errors}</div>`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* An input block in a form: its label, control, help and error. The server's error shows in
|
|
155
|
+
* `data-cms-server-error`; the browser's checks write theirs into the empty `data-cms-error`.
|
|
156
|
+
* Both carry the input's key: its name, or `repeater.<row id>.<name>` in a row. A repeater's
|
|
157
|
+
* rows render through `helpers.block`, so a theme's input renderers apply inside them.
|
|
158
|
+
*/
|
|
159
|
+
export function inputBlock(block: RenderedBlock, helpers?: ThemeHelpers): TemplateResult | null {
|
|
160
|
+
const input = block.input;
|
|
161
|
+
if (!input) return null;
|
|
162
|
+
const width = inputWidth(block);
|
|
163
|
+
const required = block.data.required === true;
|
|
164
|
+
const label = text(block, 'label') || input.name;
|
|
165
|
+
const help = text(block, 'description');
|
|
166
|
+
const described = [help ? `${input.id}-help` : '', `${input.id}-error`].filter(Boolean).join(' ');
|
|
167
|
+
const invalid = input.error ? 'true' : undefined;
|
|
168
|
+
const value = input.value;
|
|
169
|
+
const current = typeof value === 'string' ? value : typeof value === 'number' ? String(value) : '';
|
|
170
|
+
const chosen = Array.isArray(value) ? value as readonly string[] : typeof value === 'string' ? [value] : [];
|
|
171
|
+
const mark = required ? html`<span aria-hidden="true" class="text-destructive"> *</span>` : null;
|
|
172
|
+
const helpText = help ? html`<p id=${`${input.id}-help`} class=${HELP}>${help}</p>` : null;
|
|
173
|
+
const errors = html`${input.error ? html`<p class=${ERROR} data-cms-server-error=${input.key}>${input.error}</p>` : null}<p id=${`${input.id}-error`} class=${ERROR} data-cms-error=${input.key}></p>`;
|
|
174
|
+
if (block.repeater) return repeaterBlock(block, helpers, { label: html`${label}${mark}`, help: helpText, errors, width });
|
|
175
|
+
if (input.kind === 'file') return fileField(block, input, { label: html`${label}${mark}`, help: helpText, errors, described, invalid, required, width });
|
|
176
|
+
if (input.items) return multipleField(block, input, { label: html`${label}${mark}`, help: helpText, errors, width });
|
|
177
|
+
const field = (control: TemplateResult) => html`<div class="cms-field space-y-1" data-input=${input.key} data-width=${ifDefined(width)}>
|
|
178
|
+
<label for=${input.id} class=${LABEL}>${label}${mark}</label>${control}${helpText}${errors}</div>`;
|
|
179
|
+
const group = (controls: TemplateResult, inline: boolean) => html`<fieldset class="cms-field space-y-1" data-input=${input.key} data-width=${ifDefined(width)} aria-describedby=${described}>
|
|
180
|
+
<legend class=${LABEL}>${label}${mark}</legend>
|
|
181
|
+
<div class=${inline ? 'flex flex-wrap gap-x-4 gap-y-1' : 'space-y-1'}>${controls}</div>${helpText}${errors}</fieldset>`;
|
|
182
|
+
const choice = (type: 'radio' | 'checkbox', inline: boolean) => group(html`${input.options.map((option, index) => html`<label class="flex items-center gap-2 text-sm text-foreground">
|
|
183
|
+
<input type=${type} id=${index ? `${input.id}-${index}` : input.id} name=${input.name} value=${option.value} ?checked=${chosen.includes(option.value)} aria-invalid=${ifDefined(invalid)} class="size-4 accent-primary">
|
|
184
|
+
${option.label}</label>`)}`, inline);
|
|
185
|
+
switch (block.type) {
|
|
186
|
+
case 'form/hidden': return html`<input type="hidden" name=${input.name} value=${current}>`;
|
|
187
|
+
case 'form/textarea': return field(textControl(block, input, { id: input.id, value: current, invalid, described, required }));
|
|
188
|
+
case 'form/select': return field(html`<select id=${input.id} name=${input.name} ?required=${required} aria-describedby=${described} aria-invalid=${ifDefined(invalid)} class=${FORM_INPUT}>
|
|
189
|
+
<option value="" ?selected=${!current}>${text(block, 'placeholder') || __('Choose…')}</option>
|
|
190
|
+
${input.options.map(option => html`<option value=${option.value} ?selected=${option.value === current}>${option.label}</option>`)}</select>`);
|
|
191
|
+
case 'form/radio': return choice('radio', block.data.inline === true);
|
|
192
|
+
case 'form/checkboxes': return choice('checkbox', block.data.inline === true);
|
|
193
|
+
case 'form/checkbox': case 'form/consent': {
|
|
194
|
+
const caption = block.type === 'form/consent' ? html`<span class="[&_p]:my-0 [&_a]:text-primary [&_a]:underline">${unsafeHTML(block.html.text ?? '')}</span>` : html`<span>${text(block, 'text') || label}</span>`;
|
|
195
|
+
return html`<div class="cms-field space-y-1" data-input=${input.key} data-width=${ifDefined(width)}>
|
|
196
|
+
${block.type === 'form/checkbox' && text(block, 'text') ? html`<p class=${LABEL}>${label}${mark}</p>` : null}
|
|
197
|
+
<label for=${input.id} class="flex items-start gap-2 text-sm text-foreground">
|
|
198
|
+
<input type="checkbox" id=${input.id} name=${input.name} value="on" ?checked=${value === true} ?required=${required} aria-describedby=${described} aria-invalid=${ifDefined(invalid)} class="mt-0.5 size-4 accent-primary">
|
|
199
|
+
${caption}${block.type === 'form/consent' || !text(block, 'text') ? mark : null}</label>${helpText}${errors}</div>`;
|
|
200
|
+
}
|
|
201
|
+
default: return field(textControl(block, input, { id: input.id, value: current, invalid, described, required }));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser's part of a site form, loaded once a form is on the page. It applies the form's
|
|
3
|
+
* conditions as values change, shows the checks the server will make as fields are left and
|
|
4
|
+
* on sending, and sends the form in the background: the confirmation shows in place, or the
|
|
5
|
+
* browser goes to the form's page. The form works the same without it.
|
|
6
|
+
*
|
|
7
|
+
* It writes only into elements the page renders empty (`data-cms-error`, `data-cms-form-error`,
|
|
8
|
+
* `data-cms-form-done`) and toggles attributes, so the page's own rendering stays intact.
|
|
9
|
+
*/
|
|
10
|
+
import { formDataValues, formInputs, inputHtmlName, inputKey, TEMPLATE_ROW, validateSubmission, type Block, type BlockDeclaration, type InputKind } from '@cossackframework/cms';
|
|
11
|
+
|
|
12
|
+
const enhanced = new WeakSet<HTMLFormElement>();
|
|
13
|
+
|
|
14
|
+
export function enhanceForm(form: HTMLFormElement): void {
|
|
15
|
+
if (enhanced.has(form)) return;
|
|
16
|
+
enhanced.add(form);
|
|
17
|
+
let blocks: Block[];
|
|
18
|
+
let kinds: Record<string, InputKind>;
|
|
19
|
+
try {
|
|
20
|
+
blocks = JSON.parse(form.dataset.blocks ?? '[]') as Block[];
|
|
21
|
+
kinds = JSON.parse(form.dataset.kinds ?? '{}') as Record<string, InputKind>;
|
|
22
|
+
} catch { return; }
|
|
23
|
+
const types = new Map<string, BlockDeclaration>(Object.entries(kinds).map(([name, kind]) => [name, { name, label: name, fields: {}, input: { kind } }]));
|
|
24
|
+
const inputs = formInputs(blocks, types);
|
|
25
|
+
const touched = new Set<string>();
|
|
26
|
+
let sent = false;
|
|
27
|
+
let busy = false;
|
|
28
|
+
const formError = form.querySelector<HTMLElement>('[data-cms-form-error]');
|
|
29
|
+
const done = form.querySelector<HTMLElement>('[data-cms-form-done]');
|
|
30
|
+
const fields = form.querySelector<HTMLElement>('[data-cms-form-fields]');
|
|
31
|
+
const submit = form.querySelector<HTMLButtonElement>('[data-cms-form-submit]');
|
|
32
|
+
// A repeater's template row and a multiple input's template item are not part of the form: their boxes and controls stay out of every check.
|
|
33
|
+
const live = <T extends Element>(selector: string) => [...form.querySelectorAll<T>(selector)].filter(element => !element.closest('[data-cms-row-template], [data-cms-item-template]'));
|
|
34
|
+
/** The item an error key names: `tags.2` is the second control named tags. Input names never end in a number. */
|
|
35
|
+
const itemOf = (key: string) => /^(.*)\.(\d+)$/.exec(key);
|
|
36
|
+
const controls = (key: string) => {
|
|
37
|
+
const item = itemOf(key);
|
|
38
|
+
const name = inputHtmlName(item ? item[1]! : key);
|
|
39
|
+
const all = live<HTMLInputElement>('input, select, textarea').filter(control => control.name === name);
|
|
40
|
+
return item ? all.slice(Number(item[2]) - 1, Number(item[2])) : all;
|
|
41
|
+
};
|
|
42
|
+
/** The keys of every input on the page now, rows included, in page order. */
|
|
43
|
+
const keys = () => live<HTMLElement>('[data-cms-error]').map(element => element.dataset.cmsError ?? '').filter(Boolean);
|
|
44
|
+
|
|
45
|
+
const show = (errors: { readonly [name: string]: string }, server = false) => {
|
|
46
|
+
for (const key of keys()) {
|
|
47
|
+
const message = sent || server || touched.has(key) || touched.has(itemOf(key)?.[1] ?? key) ? errors[key] ?? '' : '';
|
|
48
|
+
const box = live<HTMLElement>('[data-cms-error]').find(element => element.dataset.cmsError === key);
|
|
49
|
+
if (box) box.textContent = message;
|
|
50
|
+
const fromServer = live<HTMLElement>('[data-cms-server-error]').some(element => element.dataset.cmsServerError === key && !element.hidden);
|
|
51
|
+
for (const control of controls(key)) {
|
|
52
|
+
if (message || fromServer) control.setAttribute('aria-invalid', 'true');
|
|
53
|
+
else control.removeAttribute('aria-invalid');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const apply = () => {
|
|
58
|
+
const check = validateSubmission(blocks, types, formDataValues(new FormData(form), inputs));
|
|
59
|
+
for (const wrapper of live<HTMLElement>('[data-cms-when]')) wrapper.toggleAttribute('data-hidden', check.hidden.has(wrapper.dataset.cmsWhen ?? ''));
|
|
60
|
+
show(check.errors);
|
|
61
|
+
return check;
|
|
62
|
+
};
|
|
63
|
+
const focusFirst = (errors: { readonly [name: string]: string }) => {
|
|
64
|
+
const first = keys().find(key => errors[key]);
|
|
65
|
+
if (first) controls(first)[0]?.focus();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// The server's message about a field, from a post that came back, gives way once the field changes.
|
|
69
|
+
const changed = (event: Event) => {
|
|
70
|
+
const name = (event.target as HTMLInputElement | null)?.name;
|
|
71
|
+
const key = name ? inputKey(name) : '';
|
|
72
|
+
for (const element of live<HTMLElement>('[data-cms-server-error]')) if (key && element.dataset.cmsServerError === key) element.hidden = true;
|
|
73
|
+
apply();
|
|
74
|
+
};
|
|
75
|
+
form.addEventListener('input', changed);
|
|
76
|
+
form.addEventListener('change', changed);
|
|
77
|
+
form.addEventListener('focusout', event => {
|
|
78
|
+
const name = (event.target as HTMLInputElement | null)?.name;
|
|
79
|
+
if (name && !name.startsWith('_')) { touched.add(inputKey(name)); apply(); }
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Repeaters: Add copies the template row under a fresh id; Remove drops a row. Rows are numbered and the buttons follow the limits.
|
|
83
|
+
const settle = (repeater: HTMLElement) => {
|
|
84
|
+
const rows = [...repeater.querySelectorAll<HTMLElement>('[data-cms-rows] > [data-cms-row]')];
|
|
85
|
+
const min = Number(repeater.dataset.min) || 0;
|
|
86
|
+
const max = Number(repeater.dataset.max) || 50;
|
|
87
|
+
rows.forEach((row, index) => {
|
|
88
|
+
const number = row.querySelector<HTMLElement>('[data-cms-row-index]');
|
|
89
|
+
if (number) number.textContent = String(index + 1);
|
|
90
|
+
const remove = row.querySelector<HTMLButtonElement>('[data-cms-row-remove]');
|
|
91
|
+
if (remove) remove.disabled = rows.length <= min;
|
|
92
|
+
});
|
|
93
|
+
const add = repeater.querySelector<HTMLButtonElement>('[data-cms-row-add]');
|
|
94
|
+
if (add) add.disabled = rows.length >= max;
|
|
95
|
+
};
|
|
96
|
+
// Multiple inputs: items are numbered by position, so ids, error keys and Remove values follow every add or remove.
|
|
97
|
+
const settleItems = (group: HTMLElement) => {
|
|
98
|
+
const items = [...group.querySelectorAll<HTMLElement>('[data-cms-items] > [data-cms-item]')];
|
|
99
|
+
const key = group.dataset.cmsMultiple ?? '';
|
|
100
|
+
const base = group.dataset.id ?? '';
|
|
101
|
+
const min = Number(group.dataset.min) || 0;
|
|
102
|
+
const max = Number(group.dataset.max) || 50;
|
|
103
|
+
const renumber = (element: Element | null, attribute: string, index: number) => {
|
|
104
|
+
const value = element?.getAttribute(attribute);
|
|
105
|
+
if (value) element!.setAttribute(attribute, value.replace(/\d+$/, String(index)));
|
|
106
|
+
};
|
|
107
|
+
items.forEach((item, position) => {
|
|
108
|
+
const index = position + 1;
|
|
109
|
+
const control = item.querySelector<HTMLElement>('input, select, textarea');
|
|
110
|
+
if (control) { control.id = `${base}-${index}`; renumber(control, 'aria-label', index); control.setAttribute('aria-describedby', `${base}-${index}-error`); }
|
|
111
|
+
const box = item.querySelector<HTMLElement>('[data-cms-error]');
|
|
112
|
+
if (box) { box.dataset.cmsError = `${key}.${index}`; box.id = `${base}-${index}-error`; }
|
|
113
|
+
const server = item.querySelector<HTMLElement>('[data-cms-server-error]');
|
|
114
|
+
if (server) server.dataset.cmsServerError = `${key}.${index}`;
|
|
115
|
+
const remove = item.querySelector<HTMLButtonElement>('[data-cms-item-remove]');
|
|
116
|
+
if (remove) { remove.value = `${key}.${index}`; remove.disabled = items.length <= min; renumber(remove, 'aria-label', index); }
|
|
117
|
+
});
|
|
118
|
+
const add = group.querySelector<HTMLButtonElement>('[data-cms-item-add]');
|
|
119
|
+
if (add) add.disabled = items.length >= max;
|
|
120
|
+
};
|
|
121
|
+
form.addEventListener('click', event => {
|
|
122
|
+
const target = event.target as Element | null;
|
|
123
|
+
const add = target?.closest<HTMLButtonElement>('[data-cms-row-add], [data-cms-item-add]');
|
|
124
|
+
const remove = target?.closest<HTMLButtonElement>('[data-cms-row-remove], [data-cms-item-remove]');
|
|
125
|
+
if (!add && !remove) return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
const group = (add ?? remove)!.closest<HTMLElement>('[data-cms-multiple]');
|
|
128
|
+
if (group && (add ?? remove)!.hasAttribute(add ? 'data-cms-item-add' : 'data-cms-item-remove')) {
|
|
129
|
+
if (remove) remove.closest('[data-cms-item]')?.remove();
|
|
130
|
+
else {
|
|
131
|
+
const template = group.querySelector<HTMLElement>(':scope > [data-cms-item-template]');
|
|
132
|
+
const list = group.querySelector<HTMLElement>('[data-cms-items]');
|
|
133
|
+
if (!template || !list || list.querySelectorAll(':scope > [data-cms-item]').length >= (Number(group.dataset.max) || 50)) return;
|
|
134
|
+
const holder = document.createElement('div');
|
|
135
|
+
holder.innerHTML = template.outerHTML;
|
|
136
|
+
const item = holder.firstElementChild as HTMLElement | null;
|
|
137
|
+
if (!item) return;
|
|
138
|
+
item.removeAttribute('hidden');
|
|
139
|
+
item.removeAttribute('data-cms-item-template');
|
|
140
|
+
for (const element of item.querySelectorAll('[disabled]')) element.removeAttribute('disabled');
|
|
141
|
+
list.appendChild(item);
|
|
142
|
+
item.querySelector<HTMLElement>('input, select, textarea')?.focus();
|
|
143
|
+
}
|
|
144
|
+
settleItems(group);
|
|
145
|
+
apply();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const repeater = (add ?? remove)!.closest<HTMLElement>('[data-cms-repeater]');
|
|
149
|
+
if (!repeater) return;
|
|
150
|
+
if (remove) {
|
|
151
|
+
remove.closest('[data-cms-row]')?.remove();
|
|
152
|
+
} else {
|
|
153
|
+
const template = repeater.querySelector<HTMLElement>('[data-cms-row-template]');
|
|
154
|
+
const list = repeater.querySelector<HTMLElement>('[data-cms-rows]');
|
|
155
|
+
if (!template || !list || list.querySelectorAll(':scope > [data-cms-row]').length >= (Number(repeater.dataset.max) || 50)) return;
|
|
156
|
+
const id = `r${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
157
|
+
const holder = document.createElement('div');
|
|
158
|
+
holder.innerHTML = template.outerHTML.replaceAll(TEMPLATE_ROW, id);
|
|
159
|
+
const row = holder.firstElementChild as HTMLElement | null;
|
|
160
|
+
if (!row) return;
|
|
161
|
+
row.removeAttribute('hidden');
|
|
162
|
+
row.removeAttribute('data-cms-row-template');
|
|
163
|
+
for (const element of row.querySelectorAll('[disabled]')) element.removeAttribute('disabled');
|
|
164
|
+
list.appendChild(row);
|
|
165
|
+
for (const group of row.querySelectorAll<HTMLElement>('[data-cms-multiple]')) settleItems(group);
|
|
166
|
+
row.querySelector<HTMLElement>('input:not([type=hidden]), select, textarea')?.focus();
|
|
167
|
+
}
|
|
168
|
+
settle(repeater);
|
|
169
|
+
apply();
|
|
170
|
+
});
|
|
171
|
+
for (const repeater of form.querySelectorAll<HTMLElement>('[data-cms-repeater]')) settle(repeater);
|
|
172
|
+
for (const group of form.querySelectorAll<HTMLElement>('[data-cms-multiple]')) settleItems(group);
|
|
173
|
+
form.addEventListener('submit', event => {
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
if (busy) return;
|
|
176
|
+
sent = true;
|
|
177
|
+
const check = apply();
|
|
178
|
+
if (formError) formError.textContent = '';
|
|
179
|
+
if (Object.keys(check.errors).length) { focusFirst(check.errors); return; }
|
|
180
|
+
busy = true;
|
|
181
|
+
if (submit) submit.disabled = true;
|
|
182
|
+
void (async () => {
|
|
183
|
+
try {
|
|
184
|
+
const response = await fetch(form.action, { method: 'POST', body: new FormData(form), headers: { accept: 'application/json' }, credentials: 'same-origin' });
|
|
185
|
+
const body = await response.json().catch(() => ({})) as { confirmation?: { kind: 'message'; html: string } | { kind: 'redirect'; url: string }; error?: string; fields?: Record<string, string> };
|
|
186
|
+
if (response.ok && body.confirmation?.kind === 'redirect') { location.assign(body.confirmation.url); return; }
|
|
187
|
+
if (response.ok && body.confirmation?.kind === 'message') {
|
|
188
|
+
if (done) { done.innerHTML = body.confirmation.html; done.hidden = false; done.focus?.(); }
|
|
189
|
+
if (fields) fields.hidden = true;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (body.fields && Object.keys(body.fields).length) { show(body.fields, true); focusFirst(body.fields); }
|
|
193
|
+
if (formError) formError.textContent = body.error ?? 'The form could not be sent. Try again.';
|
|
194
|
+
} catch {
|
|
195
|
+
if (formError) formError.textContent = 'The form could not be sent. Check your connection and try again.';
|
|
196
|
+
} finally {
|
|
197
|
+
busy = false;
|
|
198
|
+
if (submit) submit.disabled = false;
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
});
|
|
202
|
+
apply();
|
|
203
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineServerMiddleware } from '@cossackframework/core';
|
|
2
|
+
import { isTransportPath } from '@cossackframework/core/transport-routes';
|
|
3
|
+
import { ANONYMOUS, hasPermission, isNetworkAdmin, MAIN_SITE, type Principal } from '@cossackframework/cms';
|
|
4
|
+
import type { Context } from 'hono';
|
|
5
|
+
|
|
6
|
+
const principal = (c: Context): Principal => c.get('principal') ?? ANONYMOUS;
|
|
7
|
+
|
|
8
|
+
/** Screens for holders of any of these permissions. Visitors sign in; others get the dashboard. */
|
|
9
|
+
export function requireAny(...permissions: string[]) {
|
|
10
|
+
return defineServerMiddleware(async (c, next) => {
|
|
11
|
+
const current = principal(c);
|
|
12
|
+
if (permissions.some(permission => hasPermission(current, permission))) { await next(); return; }
|
|
13
|
+
if (isTransportPath(c.req.path, 'rpc', 'upload', 'websocket')) {
|
|
14
|
+
return c.json(current.kind === 'user' ? { error: 'Forbidden', code: 'COSSACK_RPC_FORBIDDEN' } : { error: 'Authentication required', code: 'COSSACK_RPC_UNAUTHENTICATED' }, current.kind === 'user' ? 403 : 401);
|
|
15
|
+
}
|
|
16
|
+
return c.redirect(current.kind === 'user' ? '/dashboard' : config('auth.redirectAfterLogout'));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The network dashboard: network admins, on the network host, while the network is on. Others go to their dashboard. */
|
|
21
|
+
export function requireNetworkAdmin() {
|
|
22
|
+
return defineServerMiddleware(async (c, next) => {
|
|
23
|
+
if (isNetworkAdmin(principal(c)) && c.get('site')?.id === MAIN_SITE && await c.get('network')?.enabled()) { await next(); return; }
|
|
24
|
+
if (isTransportPath(c.req.path, 'rpc', 'upload', 'websocket')) return c.json({ error: 'Forbidden', code: 'COSSACK_RPC_FORBIDDEN' }, 403);
|
|
25
|
+
return c.redirect('/dashboard');
|
|
26
|
+
});
|
|
27
|
+
}
|