@cossackframework/cms 0.0.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { EditorLayout } from '@cossackframework/cms';
|
|
2
|
+
/**
|
|
3
|
+
* The collection builder's model: field types as the picker offers them, names from labels,
|
|
4
|
+
* and the definition a draft describes. Client-safe.
|
|
5
|
+
*/
|
|
6
|
+
import type { Block, CollectionDefinition, FieldDeclaration, SchemaType } from '@cossackframework/cms';
|
|
7
|
+
|
|
8
|
+
export const FIELD_TYPES = [
|
|
9
|
+
{ type: 'text', label: 'Single line', description: 'One line of text, such as a subtitle or SKU.' },
|
|
10
|
+
{ type: 'textarea', label: 'Long text', description: 'Plain paragraphs.' },
|
|
11
|
+
{ type: 'markdown', label: 'Rich text', description: 'Markdown with a toolbar and preview.' },
|
|
12
|
+
{ type: 'number', label: 'Number', description: 'Prices, ratings and measurements.' },
|
|
13
|
+
{ type: 'integer', label: 'Whole number', description: 'Counts and positions.' },
|
|
14
|
+
{ type: 'boolean', label: 'Yes / no', description: 'A checkbox.' },
|
|
15
|
+
{ type: 'date', label: 'Date and time', description: 'Stored in UTC.' },
|
|
16
|
+
{ type: 'choice', label: 'Choice', description: 'One of a fixed list.' },
|
|
17
|
+
{ type: 'media', label: 'Image or file', description: 'A file from the media library; a gallery with Multiple on.' },
|
|
18
|
+
{ type: 'reference', label: 'Reference', description: 'An entry of another collection.' },
|
|
19
|
+
{ type: 'blocks', label: 'Blocks', description: 'Content built from blocks, such as headings, images and buttons.' },
|
|
20
|
+
{ type: 'json', label: 'JSON', description: 'Structured data for developers.' },
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
export type FieldType = (typeof FIELD_TYPES)[number]['type'];
|
|
24
|
+
|
|
25
|
+
/** `Release date` → `releaseDate`. */
|
|
26
|
+
export function fieldName(label: string): string {
|
|
27
|
+
const words = label.normalize('NFKD').replace(/[̀-ͯ]/g, '').replace(/[^A-Za-z0-9]+/g, ' ').trim().split(' ').filter(Boolean);
|
|
28
|
+
const name = words.map((word, index) => index ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word.toLowerCase()).join('');
|
|
29
|
+
return /^[a-z]/.test(name) ? name.slice(0, 40) : `field${name}`.slice(0, 40);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** `Product Reviews` → `product_reviews`, a collection name. */
|
|
33
|
+
export function collectionName(label: string): string {
|
|
34
|
+
return label.normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '').replace(/^(\d)/, 'c$1').slice(0, 40);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function typeOf(declaration: FieldDeclaration): FieldType {
|
|
38
|
+
switch (declaration.kind) {
|
|
39
|
+
case 'string': return declaration.media ? 'media' : 'text';
|
|
40
|
+
case 'text': return declaration.format === 'markdown' ? 'markdown' : 'textarea';
|
|
41
|
+
case 'number': return 'number';
|
|
42
|
+
case 'integer': return 'integer';
|
|
43
|
+
case 'boolean': return 'boolean';
|
|
44
|
+
case 'datetime': return 'date';
|
|
45
|
+
case 'enum': return 'choice';
|
|
46
|
+
case 'reference': return 'reference';
|
|
47
|
+
case 'blocks': return 'blocks';
|
|
48
|
+
default: return 'json';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The settings of a collection the builder edits, without its fields. */
|
|
53
|
+
export interface CollectionDraft {
|
|
54
|
+
name: string;
|
|
55
|
+
label: string;
|
|
56
|
+
singular: string;
|
|
57
|
+
description: string;
|
|
58
|
+
icon: string;
|
|
59
|
+
path: string;
|
|
60
|
+
/** Entries are on the site. */
|
|
61
|
+
public: boolean;
|
|
62
|
+
slug: boolean;
|
|
63
|
+
publishable: boolean;
|
|
64
|
+
hierarchical: boolean;
|
|
65
|
+
visibility: 'public' | 'private';
|
|
66
|
+
/** Visitors can comment on entries. */
|
|
67
|
+
comments: boolean;
|
|
68
|
+
/** Entries are listed in the XML sitemap. */
|
|
69
|
+
sitemap: boolean;
|
|
70
|
+
taxonomies: string[];
|
|
71
|
+
builtin: boolean;
|
|
72
|
+
/** The standard fields: blocks content, an excerpt and a featured image. */
|
|
73
|
+
content: boolean;
|
|
74
|
+
excerpt: boolean;
|
|
75
|
+
featuredImage: boolean;
|
|
76
|
+
/** A password visitors type to read an entry. */
|
|
77
|
+
password: boolean;
|
|
78
|
+
/** Entries only signed-in users read. */
|
|
79
|
+
members: boolean;
|
|
80
|
+
/** A revision of every write. */
|
|
81
|
+
revisions: boolean;
|
|
82
|
+
/** How far entries may change the content template: free, keep its blocks, or keep their order too. */
|
|
83
|
+
templateLock: '' | 'insert' | 'all';
|
|
84
|
+
/** Structured data: the schema.org type of entries and which fields fill its properties. */
|
|
85
|
+
schemaType: SchemaType;
|
|
86
|
+
schemaMap: Record<string, string>;
|
|
87
|
+
/** Robots: entries and the archive kept out of search engines, links on entries not followed. */
|
|
88
|
+
noindex: boolean;
|
|
89
|
+
nofollow: boolean;
|
|
90
|
+
archiveNoindex: boolean;
|
|
91
|
+
/** Title and description templates; empty uses Settings → SEO. */
|
|
92
|
+
seoTitle: string;
|
|
93
|
+
seoDescription: string;
|
|
94
|
+
archiveTitle: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function collectionDraft(definition: CollectionDefinition): CollectionDraft {
|
|
98
|
+
return {
|
|
99
|
+
name: definition.name, label: definition.label, singular: definition.singular, description: definition.description ?? '', icon: definition.icon ?? 'document-text',
|
|
100
|
+
path: definition.path ?? '', public: definition.path !== null && definition.path !== undefined, slug: definition.slug !== false, publishable: definition.publishable !== false,
|
|
101
|
+
hierarchical: definition.hierarchical === true, visibility: definition.visibility ?? 'private', comments: definition.comments === true, sitemap: definition.sitemap !== false, taxonomies: [...(definition.taxonomies ?? [])], builtin: definition.builtin === true,
|
|
102
|
+
content: Boolean(definition.features?.content), excerpt: definition.features?.excerpt === true, featuredImage: definition.features?.featuredImage === true, password: definition.features?.password === true, members: definition.features?.members === true, revisions: definition.features?.revisions !== false,
|
|
103
|
+
templateLock: definition.templateLock ?? '',
|
|
104
|
+
schemaType: definition.schema?.type ?? 'WebPage', schemaMap: { ...(definition.schema?.map ?? {}) },
|
|
105
|
+
noindex: definition.robots?.noindex === true, nofollow: definition.robots?.nofollow === true, archiveNoindex: definition.robots?.archiveNoindex === true,
|
|
106
|
+
seoTitle: definition.seoTemplates?.title ?? '', seoDescription: definition.seoTemplates?.description ?? '', archiveTitle: definition.seoTemplates?.archiveTitle ?? '',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The definition a draft and its content template describe. Fields live in the groups attached to the collection. */
|
|
111
|
+
export function definitionOf(draft: CollectionDraft, template: readonly Block[] = [], editor?: EditorLayout): CollectionDefinition {
|
|
112
|
+
const map = Object.fromEntries(Object.entries(draft.schemaMap).filter(([, name]) => name));
|
|
113
|
+
return {
|
|
114
|
+
name: draft.name, label: draft.label.trim(), singular: draft.singular.trim(), ...(draft.description.trim() ? { description: draft.description.trim() } : {}),
|
|
115
|
+
icon: draft.icon, path: draft.public ? draft.path.trim().replace(/^\/+|\/+$/g, '') : null,
|
|
116
|
+
slug: draft.slug, publishable: draft.publishable, hierarchical: draft.hierarchical, ...(draft.publishable ? {} : { visibility: draft.visibility }), comments: draft.comments, sitemap: draft.sitemap,
|
|
117
|
+
taxonomies: [...draft.taxonomies],
|
|
118
|
+
features: { content: draft.content, excerpt: draft.excerpt, featuredImage: draft.featuredImage, password: draft.password === true, members: draft.members === true, revisions: draft.revisions },
|
|
119
|
+
fields: {},
|
|
120
|
+
template: draft.content ? [...template] : [], ...(draft.content && draft.templateLock && template.length ? { templateLock: draft.templateLock } : {}),
|
|
121
|
+
schema: { type: draft.schemaType, ...(Object.keys(map).length ? { map } : {}) },
|
|
122
|
+
robots: { noindex: draft.noindex, nofollow: draft.nofollow, archiveNoindex: draft.archiveNoindex },
|
|
123
|
+
seoTemplates: { title: draft.seoTitle.trim(), description: draft.seoDescription.trim(), archiveTitle: draft.archiveTitle.trim() },
|
|
124
|
+
...(editor ? { editor } : {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cache headers of the site's anonymous responses: how long the caches in front of the site
|
|
3
|
+
* may hold them (Settings → Cache → Hold pages, a day once a purger is configured) and the tags
|
|
4
|
+
* a change purges (`Cache-Tag`). A response that said `private, no-store` first keeps it; a
|
|
5
|
+
* signed-in user's page is made private by the framework after the page. Server-only.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from 'hono';
|
|
8
|
+
import { cacheControl, cacheTagHeader, type RenderedBlock } from '@cossackframework/cms';
|
|
9
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
10
|
+
|
|
11
|
+
export interface CacheHeaders { 'cache-control': string; 'cache-tag': string }
|
|
12
|
+
|
|
13
|
+
/** The headers of an anonymous response showing what `tags` name; `max` caps the hold (a not-found page is held a minute). */
|
|
14
|
+
export async function cacheHeaders(cms: CmsHost, tags: Iterable<string>, options: { max?: number } = {}): Promise<CacheHeaders> {
|
|
15
|
+
const hold = await cms.settings.get('cache.hold');
|
|
16
|
+
return {
|
|
17
|
+
'cache-control': cacheControl(hold, { purging: cms.purge.configured, ...(options.max !== undefined ? { max: options.max } : {}) }),
|
|
18
|
+
'cache-tag': cacheTagHeader([cms.purge.tag.site(), ...tags]),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Set the headers on a page's response, unless the page already made it private. */
|
|
23
|
+
export async function applyCacheHeaders(c: Context, cms: CmsHost, tags: Iterable<string>, options: { max?: number } = {}): Promise<void> {
|
|
24
|
+
if (c.res.headers.has('cache-control')) return;
|
|
25
|
+
const headers = await cacheHeaders(cms, tags, options);
|
|
26
|
+
c.header('cache-control', headers['cache-control']);
|
|
27
|
+
c.header('cache-tag', headers['cache-tag']);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Blocks that list a collection's entries, so a page showing one changes when the collection does. */
|
|
31
|
+
const LISTING_BLOCKS = new Set(['core/latest-entries']);
|
|
32
|
+
|
|
33
|
+
/** The collections listed by blocks (Latest entries) anywhere in these trees. */
|
|
34
|
+
export function listedCollections(blocks: Iterable<RenderedBlock>): Set<string> {
|
|
35
|
+
const found = new Set<string>();
|
|
36
|
+
const walk = (list: Iterable<RenderedBlock>) => {
|
|
37
|
+
for (const block of list) {
|
|
38
|
+
if (LISTING_BLOCKS.has(block.type) && typeof block.data.collection === 'string' && block.data.collection) found.add(block.data.collection);
|
|
39
|
+
if (block.children) walk(block.children);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
walk(blocks);
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser's part of a carousel block: arrows and dots (or thumbnails) move the
|
|
3
|
+
* scroll-snapping track, the arrow keys do the same when it has focus, and autoplay advances it
|
|
4
|
+
* until it is hovered, focused or hidden. Several slides may show at once; the track then moves
|
|
5
|
+
* one slide at a time and stops at the last full view. Without this the track still scrolls and swipes.
|
|
6
|
+
*/
|
|
7
|
+
const enhanced = new WeakSet<HTMLElement>();
|
|
8
|
+
|
|
9
|
+
export function enhanceCarousel(root: HTMLElement): void {
|
|
10
|
+
if (enhanced.has(root)) return;
|
|
11
|
+
enhanced.add(root);
|
|
12
|
+
const track = root.querySelector<HTMLElement>('.cms-carousel-track');
|
|
13
|
+
const slides = [...root.querySelectorAll<HTMLElement>('.cms-carousel-slide')];
|
|
14
|
+
const dots = [...root.querySelectorAll<HTMLButtonElement>('.cms-carousel-dots [role="tab"], .cms-carousel-thumbs [role="tab"]')];
|
|
15
|
+
if (!track || slides.length < 2) return;
|
|
16
|
+
root.setAttribute('data-enhanced', '');
|
|
17
|
+
let current = 0;
|
|
18
|
+
// The first slide of the last full view: with three showing of five, the track stops at the third.
|
|
19
|
+
const step = () => (slides[1]!.offsetLeft - slides[0]!.offsetLeft) || track.clientWidth || 1;
|
|
20
|
+
const last = () => Math.max(slides.length - Math.max(Math.round(track.clientWidth / step()), 1), 0);
|
|
21
|
+
const show = (index: number) => {
|
|
22
|
+
const end = last();
|
|
23
|
+
current = index > end ? 0 : index < 0 ? end : index;
|
|
24
|
+
track.scrollTo({ left: slides[current]!.offsetLeft - slides[0]!.offsetLeft, behavior: matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' });
|
|
25
|
+
};
|
|
26
|
+
const mark = () => {
|
|
27
|
+
current = Math.min(Math.round(track.scrollLeft / step()), slides.length - 1);
|
|
28
|
+
dots.forEach((dot, index) => {
|
|
29
|
+
dot.setAttribute('aria-selected', index === current ? 'true' : 'false');
|
|
30
|
+
// A thumbnail strip follows the slide shown.
|
|
31
|
+
if (index === current && dot.classList.contains('cms-carousel-thumb')) dot.parentElement?.scrollTo({ left: dot.offsetLeft - dot.parentElement.clientWidth / 2 + dot.clientWidth / 2, behavior: 'smooth' });
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
track.addEventListener('scroll', mark, { passive: true });
|
|
35
|
+
for (const arrow of root.querySelectorAll<HTMLButtonElement>('.cms-carousel-arrow')) arrow.addEventListener('click', () => show(current + Number(arrow.dataset.direction || 1)));
|
|
36
|
+
dots.forEach((dot, index) => dot.addEventListener('click', () => show(index)));
|
|
37
|
+
track.addEventListener('keydown', event => {
|
|
38
|
+
if (event.key === 'ArrowRight') { event.preventDefault(); show(current + 1); }
|
|
39
|
+
if (event.key === 'ArrowLeft') { event.preventDefault(); show(current - 1); }
|
|
40
|
+
});
|
|
41
|
+
// Autoplay: every interval, unless the pointer or the focus is on the carousel, or the page is hidden.
|
|
42
|
+
if (root.dataset.autoplay !== 'true') return;
|
|
43
|
+
const interval = Math.min(Math.max(Number(root.dataset.interval) || 5, 2), 30) * 1000;
|
|
44
|
+
let paused = false;
|
|
45
|
+
root.addEventListener('pointerenter', () => { paused = true; });
|
|
46
|
+
root.addEventListener('pointerleave', () => { paused = false; });
|
|
47
|
+
root.addEventListener('focusin', () => { paused = true; });
|
|
48
|
+
root.addEventListener('focusout', () => { paused = false; });
|
|
49
|
+
const timer = setInterval(() => { if (!paused && !document.hidden && root.isConnected) show(current + 1); }, interval);
|
|
50
|
+
const observer = new MutationObserver(() => { if (!root.isConnected) { clearInterval(timer); observer.disconnect(); } });
|
|
51
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
52
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presence as the dashboard draws it: avatars ringed in each editor's color, stacked with a
|
|
3
|
+
* count past `max`, and a chip naming who is in a field or a block. Client-safe.
|
|
4
|
+
*/
|
|
5
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
6
|
+
import { Avatar } from '@cossackframework/ui';
|
|
7
|
+
import type { Participant } from '@cossackframework/cms';
|
|
8
|
+
|
|
9
|
+
/** Someone to draw: a participant, or a peer. */
|
|
10
|
+
export interface Someone {
|
|
11
|
+
readonly user: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly avatar: string | null;
|
|
14
|
+
readonly color: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The same user once, by user ID. */
|
|
18
|
+
export function distinct<T extends Someone>(people: Iterable<T>): T[] {
|
|
19
|
+
const seen = new Map<string, T>();
|
|
20
|
+
for (const person of people) if (!seen.has(person.user)) seen.set(person.user, person);
|
|
21
|
+
return [...seen.values()];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The tooltip and accessible name of a group. */
|
|
25
|
+
export function namesOf(people: readonly Someone[]): string {
|
|
26
|
+
return people.map(person => person.name).join(', ');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** One person's avatar: their picture, or their initials on their color. */
|
|
30
|
+
export function avatar(person: Someone, size: number): TemplateResult {
|
|
31
|
+
return component(Avatar, { src: person.avatar ?? undefined, alt: person.name, size, style: `background: ${person.color}; color: #fff` });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Up to `max` avatars with their colors as rings, then "+N"; names on hover and for assistive technology; `self` is the viewer, named "(you)". */
|
|
35
|
+
export function avatarStack(people: readonly Someone[], options: { size?: number; max?: number; label: string; self?: string }): TemplateResult | null {
|
|
36
|
+
const list = distinct(people);
|
|
37
|
+
if (!list.length) return null;
|
|
38
|
+
const size = options.size ?? 24;
|
|
39
|
+
const max = options.max ?? 3;
|
|
40
|
+
const shown = list.slice(0, max);
|
|
41
|
+
const rest = list.length - shown.length;
|
|
42
|
+
const names = list.map(person => person.user === options.self ? `${person.name} (${__('you')})` : person.name).join(', ');
|
|
43
|
+
return html`<span class="inline-flex items-center" role="img" aria-label=${`${options.label}: ${names}`} title=${names} data-presence=${list.length}>
|
|
44
|
+
${shown.map((person, index) => html`<span class=${`inline-flex rounded-full bg-background ${index ? '-ml-1.5' : ''}`} style=${`box-shadow: 0 0 0 2px ${person.color}; z-index: ${shown.length - index}`} data-presence-user=${person.user}>
|
|
45
|
+
${avatar(person, size)}</span>`)}
|
|
46
|
+
${rest > 0 ? html`<span class="-ml-1.5 inline-flex items-center justify-center rounded-full border border-border bg-muted px-1 text-[10px] font-medium text-foreground" style=${`min-width: ${size}px; height: ${size}px`}>+${rest}</span>` : null}
|
|
47
|
+
</span>`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A small chip bordered in the editor's color, naming who is in a field or block; the avatar carries the color, the text stays readable. */
|
|
51
|
+
export function presenceChip(people: readonly Someone[], what: string): TemplateResult | null {
|
|
52
|
+
const list = distinct(people);
|
|
53
|
+
if (!list.length) return null;
|
|
54
|
+
const first = list[0]!;
|
|
55
|
+
const label = list.length === 1 ? `${first.name} ${what}` : `${first.name} +${list.length - 1} ${what}`;
|
|
56
|
+
return html`<span class="inline-flex items-center gap-1 rounded-full border bg-background py-0.5 pl-0.5 pr-1.5 text-[10px] font-medium leading-none text-foreground" style=${`border-color: ${first.color}`} data-presence-chip=${list.map(person => person.user).join(' ')}>
|
|
57
|
+
${avatar(first, 14)}${label}</span>`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The outline style of a control or block someone else is in. */
|
|
61
|
+
export function presenceOutline(people: readonly Someone[]): string {
|
|
62
|
+
const first = distinct(people)[0];
|
|
63
|
+
return first ? `box-shadow: 0 0 0 2px ${first.color}; border-radius: 0.5rem;` : '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Participants on a layout tab: the tab's stack leaves the viewer out. */
|
|
67
|
+
export function onTab(participants: readonly Participant[], tab: string, self: string): Participant[] {
|
|
68
|
+
return participants.filter(participant => participant.user !== self && participant.tabs.includes(tab));
|
|
69
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Co-editing of one rich text document with `prosemirror-collab`: the entry's room is the
|
|
3
|
+
* central authority. Unconfirmed steps go to the room one batch at a time; a batch made against
|
|
4
|
+
* an old version comes back with the steps this editor lacked, which rebase the unconfirmed
|
|
5
|
+
* ones; a document the room no longer has steps for is loaded again. Other editors' carets and
|
|
6
|
+
* selections are decorations, mapped along as the document changes. The `.client.ts` name keeps
|
|
7
|
+
* ProseMirror out of server bundles.
|
|
8
|
+
*/
|
|
9
|
+
import type { Editor } from '@tiptap/core';
|
|
10
|
+
import { collab, getVersion, receiveTransaction, sendableSteps } from 'prosemirror-collab';
|
|
11
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
12
|
+
import type { Node } from '@tiptap/pm/model';
|
|
13
|
+
import { Step } from '@tiptap/pm/transform';
|
|
14
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
15
|
+
import type { RichTextDoc } from '@cossackframework/cms';
|
|
16
|
+
|
|
17
|
+
/** Another editor's selection in this document. */
|
|
18
|
+
export interface Caret {
|
|
19
|
+
readonly peer: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly color: string;
|
|
22
|
+
readonly anchor: number;
|
|
23
|
+
readonly head: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The room's answer to a batch of steps. */
|
|
27
|
+
export type StepsResult =
|
|
28
|
+
| { readonly status: 'accepted'; readonly version: number }
|
|
29
|
+
| { readonly status: 'behind'; readonly version: number; readonly steps: readonly unknown[]; readonly clientIDs: readonly (string | number)[] }
|
|
30
|
+
| { readonly status: 'reload' };
|
|
31
|
+
|
|
32
|
+
export interface CollabTransport {
|
|
33
|
+
/** Send steps made against `version`; an empty batch asks for the steps after `version`. */
|
|
34
|
+
steps(version: number, steps: readonly unknown[], clientID: string): Promise<StepsResult>;
|
|
35
|
+
/** The whole document, to start over. */
|
|
36
|
+
document(): Promise<{ doc: RichTextDoc | null; version: number }>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CollabOptions {
|
|
40
|
+
readonly transport: CollabTransport;
|
|
41
|
+
readonly clientID: string;
|
|
42
|
+
readonly version: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const caretsKey = new PluginKey<{ carets: readonly Caret[]; set: DecorationSet }>('cmsCarets');
|
|
46
|
+
|
|
47
|
+
/** The caret's name is drawn by CSS, so it is neither in the document's text nor copied with it. */
|
|
48
|
+
const CARET_STYLE = `.cms-caret { position: relative; display: inline; border-left: 2px solid var(--caret-color); margin-left: -1px; pointer-events: none; }
|
|
49
|
+
.cms-caret::after { content: attr(data-name); position: absolute; left: -2px; bottom: 100%; white-space: nowrap; border-radius: 3px 3px 3px 0; background: var(--caret-color); color: #fff; font-size: 10px; line-height: 1.4; padding: 0 4px; font-weight: 500; font-family: system-ui, sans-serif; user-select: none; }`;
|
|
50
|
+
|
|
51
|
+
function caretWidget(caret: Caret): HTMLElement {
|
|
52
|
+
if (!document.getElementById('cms-caret-style')) {
|
|
53
|
+
const style = document.createElement('style');
|
|
54
|
+
style.id = 'cms-caret-style';
|
|
55
|
+
style.textContent = CARET_STYLE;
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
}
|
|
58
|
+
const span = document.createElement('span');
|
|
59
|
+
span.className = 'cms-caret';
|
|
60
|
+
span.setAttribute('aria-hidden', 'true');
|
|
61
|
+
span.dataset.name = caret.name;
|
|
62
|
+
span.style.setProperty('--caret-color', caret.color);
|
|
63
|
+
return span;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function caretDecorations(doc: Node, carets: readonly Caret[]): DecorationSet {
|
|
67
|
+
const size = doc.content.size;
|
|
68
|
+
const clamp = (position: number) => Math.max(0, Math.min(size, position));
|
|
69
|
+
const decorations: Decoration[] = [];
|
|
70
|
+
for (const caret of carets) {
|
|
71
|
+
const anchor = clamp(caret.anchor);
|
|
72
|
+
const head = clamp(caret.head);
|
|
73
|
+
if (anchor !== head) decorations.push(Decoration.inline(Math.min(anchor, head), Math.max(anchor, head), { style: `background-color: ${caret.color}33` }));
|
|
74
|
+
decorations.push(Decoration.widget(head, () => caretWidget(caret), { side: -1, key: `caret-${caret.peer}` }));
|
|
75
|
+
}
|
|
76
|
+
return DecorationSet.create(doc, decorations);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Other editors' carets: set through a transaction's meta, mapped as the document changes. */
|
|
80
|
+
export function caretsPlugin(): Plugin {
|
|
81
|
+
return new Plugin<{ carets: readonly Caret[]; set: DecorationSet }>({
|
|
82
|
+
key: caretsKey,
|
|
83
|
+
state: {
|
|
84
|
+
init: () => ({ carets: [] as readonly Caret[], set: DecorationSet.empty }),
|
|
85
|
+
apply(transaction, value) {
|
|
86
|
+
const carets = transaction.getMeta(caretsKey) as readonly Caret[] | undefined;
|
|
87
|
+
if (carets) return { carets, set: caretDecorations(transaction.doc, carets) };
|
|
88
|
+
return transaction.docChanged ? { carets: value.carets, set: value.set.map(transaction.mapping, transaction.doc) } : value;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
props: { decorations: state => caretsKey.getState(state)?.set },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The plugins an editor starts with to take part: the collab plugin at the room's version, and the carets. */
|
|
96
|
+
export function collabPlugins(options: Pick<CollabOptions, 'clientID' | 'version'>): Plugin[] {
|
|
97
|
+
return [collab({ version: options.version, clientID: options.clientID }), caretsPlugin()];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** One editor's part in the room for its document. */
|
|
101
|
+
export class CollabSession {
|
|
102
|
+
readonly #editor: Editor;
|
|
103
|
+
readonly #transport: CollabTransport;
|
|
104
|
+
readonly #clientID: string;
|
|
105
|
+
#sending = false;
|
|
106
|
+
#reloading = false;
|
|
107
|
+
#destroyed = false;
|
|
108
|
+
|
|
109
|
+
constructor(editor: Editor, options: CollabOptions) {
|
|
110
|
+
this.#editor = editor;
|
|
111
|
+
this.#transport = options.transport;
|
|
112
|
+
this.#clientID = options.clientID;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The version this editor has synced to. */
|
|
116
|
+
get version(): number {
|
|
117
|
+
return getVersion(this.#editor.state);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** After a local transaction: send what is unconfirmed, one batch at a time. */
|
|
121
|
+
flush(): void {
|
|
122
|
+
if (this.#destroyed || this.#sending || this.#reloading) return;
|
|
123
|
+
const sendable = sendableSteps(this.#editor.state);
|
|
124
|
+
if (!sendable) return;
|
|
125
|
+
this.#sending = true;
|
|
126
|
+
const steps = sendable.steps.map(step => step.toJSON() as unknown);
|
|
127
|
+
this.#transport.steps(sendable.version, steps, this.#clientID).then(result => {
|
|
128
|
+
if (this.#destroyed) return;
|
|
129
|
+
// The room confirms the batch here as well as in its broadcast, whichever comes first.
|
|
130
|
+
if (result.status === 'accepted') this.receive(result.version, steps, steps.map(() => this.#clientID));
|
|
131
|
+
else if (result.status === 'behind') this.receive(result.version, result.steps, result.clientIDs);
|
|
132
|
+
else void this.reload();
|
|
133
|
+
}).catch(() => { /* The socket closed: the next connection joins the room again. */ })
|
|
134
|
+
.finally(() => { this.#sending = false; if (!this.#destroyed) this.flush(); });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Steps from the room, ending at `version`: others' changes and this editor's confirmations.
|
|
139
|
+
* Steps already applied are skipped; a gap is filled by asking the room for what is missing.
|
|
140
|
+
*/
|
|
141
|
+
receive(version: number, steps: readonly unknown[], clientIDs: readonly (string | number)[]): void {
|
|
142
|
+
if (this.#destroyed || this.#reloading) return;
|
|
143
|
+
const mine = this.version;
|
|
144
|
+
if (version <= mine) return;
|
|
145
|
+
const start = version - steps.length;
|
|
146
|
+
if (start > mine) { void this.catchUp(); return; }
|
|
147
|
+
const skip = mine - start;
|
|
148
|
+
try {
|
|
149
|
+
const schema = this.#editor.state.schema;
|
|
150
|
+
const parsed = steps.slice(skip).map(step => Step.fromJSON(schema, step));
|
|
151
|
+
this.#editor.view.dispatch(receiveTransaction(this.#editor.state, parsed, clientIDs.slice(skip), { mapSelectionBackward: true }));
|
|
152
|
+
} catch { void this.reload(); return; }
|
|
153
|
+
this.flush();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Ask the room for the steps after this editor's version. */
|
|
157
|
+
async catchUp(): Promise<void> {
|
|
158
|
+
if (this.#sending || this.#reloading) return;
|
|
159
|
+
this.#sending = true;
|
|
160
|
+
try {
|
|
161
|
+
const result = await this.#transport.steps(this.version, [], this.#clientID);
|
|
162
|
+
if (this.#destroyed) return;
|
|
163
|
+
if (result.status === 'behind') this.receive(result.version, result.steps, result.clientIDs);
|
|
164
|
+
else if (result.status === 'reload') void this.reload();
|
|
165
|
+
} catch { /* The next connection joins again. */ }
|
|
166
|
+
finally { this.#sending = false; if (!this.#destroyed) this.flush(); }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Load the document again from the room and start from its version; unconfirmed steps are lost. */
|
|
170
|
+
async reload(): Promise<void> {
|
|
171
|
+
if (this.#reloading || this.#destroyed) return;
|
|
172
|
+
this.#reloading = true;
|
|
173
|
+
try {
|
|
174
|
+
const { doc, version } = await this.#transport.document();
|
|
175
|
+
if (!this.#destroyed) this.reset(doc, version);
|
|
176
|
+
} catch { /* The next connection joins again. */ }
|
|
177
|
+
finally { this.#reloading = false; }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Replace the document with the room's and track from `version`, without sending the replacement as steps. */
|
|
181
|
+
reset(doc: RichTextDoc | null, version: number): void {
|
|
182
|
+
if (this.#destroyed) return;
|
|
183
|
+
const editor = this.#editor;
|
|
184
|
+
editor.unregisterPlugin('collab');
|
|
185
|
+
editor.commands.setContent(doc && doc.content.length ? doc as never : '', { emitUpdate: false });
|
|
186
|
+
editor.registerPlugin(collab({ version, clientID: this.#clientID }));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
setCarets(carets: readonly Caret[]): void {
|
|
190
|
+
if (this.#destroyed) return;
|
|
191
|
+
this.#editor.view.dispatch(this.#editor.state.tr.setMeta(caretsKey, carets).setMeta('addToHistory', false));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
destroy(): void {
|
|
195
|
+
this.#destroyed = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notes on passages of rich text, drawn as decorations: an amber underline on each noted
|
|
3
|
+
* passage, stronger on the thread open in the rail, mapped along as the document changes so
|
|
4
|
+
* a note stays on its words while people type around it. A stored range that no longer holds
|
|
5
|
+
* its quote is put back on the nearest occurrence of the quote; a quote that is gone detaches
|
|
6
|
+
* the note, and the rail shows it on the block instead. The `.client.ts` name keeps ProseMirror
|
|
7
|
+
* out of server bundles.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
10
|
+
import type { Node } from '@tiptap/pm/model';
|
|
11
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
12
|
+
import { findQuote, type NoteRange } from '@cossackframework/cms';
|
|
13
|
+
|
|
14
|
+
/** A text note as the page knows it: its last range, and the words it was left on. */
|
|
15
|
+
export interface NoteMarkInput {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly range: NoteRange | null;
|
|
18
|
+
readonly quote: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A text note as it sits in the document now. */
|
|
22
|
+
export interface NoteMark {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly from: number;
|
|
25
|
+
readonly to: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface NotesState {
|
|
29
|
+
marks: readonly NoteMark[];
|
|
30
|
+
active: string | null;
|
|
31
|
+
set: DecorationSet;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface NotesPluginOptions {
|
|
35
|
+
/** A noted passage was clicked. */
|
|
36
|
+
onClick(id: string): void;
|
|
37
|
+
/** The passages moved, or the notes were placed: where every note that could be placed sits now. */
|
|
38
|
+
onMoved(marks: readonly NoteMark[]): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const notesKey = new PluginKey<NotesState>('cmsNotes');
|
|
42
|
+
|
|
43
|
+
const NOTE_STYLE = `.cms-note { background: rgba(245, 158, 11, 0.16); border-bottom: 2px solid rgb(245 158 11); cursor: pointer; }
|
|
44
|
+
.cms-note-active { background: rgba(245, 158, 11, 0.38); }`;
|
|
45
|
+
|
|
46
|
+
function ensureStyle(): void {
|
|
47
|
+
if (document.getElementById('cms-note-style')) return;
|
|
48
|
+
const style = document.createElement('style');
|
|
49
|
+
style.id = 'cms-note-style';
|
|
50
|
+
style.textContent = NOTE_STYLE;
|
|
51
|
+
document.head.appendChild(style);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The document's text with, for each character, the position it sits at. */
|
|
55
|
+
function flatten(doc: Node): { text: string; positions: number[] } {
|
|
56
|
+
let text = '';
|
|
57
|
+
const positions: number[] = [];
|
|
58
|
+
doc.descendants((node, position) => {
|
|
59
|
+
if (node.isText && node.text) {
|
|
60
|
+
for (let index = 0; index < node.text.length; index++) positions.push(position + index);
|
|
61
|
+
text += node.text;
|
|
62
|
+
} else if (node.isBlock && text && !text.endsWith('\n')) {
|
|
63
|
+
// Blocks are separated so a quote never spans two of them.
|
|
64
|
+
positions.push(position);
|
|
65
|
+
text += '\n';
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
return { text, positions };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Where a note's words are now: its range when it still holds the quote, else the nearest
|
|
74
|
+
* occurrence of the quote, else nothing. Without a quote the range stands as it is.
|
|
75
|
+
*/
|
|
76
|
+
export function anchorNote(doc: Node, input: NoteMarkInput): NoteRange | null {
|
|
77
|
+
const size = doc.content.size;
|
|
78
|
+
const range = input.range && input.range.to <= size ? input.range : null;
|
|
79
|
+
const quote = input.quote.replace(/\s+/g, ' ').trim();
|
|
80
|
+
if (!quote) return range;
|
|
81
|
+
if (range && doc.textBetween(range.from, range.to, ' ').replace(/\s+/g, ' ').trim() === quote) return range;
|
|
82
|
+
const flat = flatten(doc);
|
|
83
|
+
const at = findQuote(flat.text, quote, range ? flat.positions.findIndex(position => position >= range.from) : 0);
|
|
84
|
+
if (at === -1 || at + quote.length > flat.positions.length) return null;
|
|
85
|
+
return { from: flat.positions[at]!, to: flat.positions[at + quote.length - 1]! + 1 };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function decorate(doc: Node, marks: readonly NoteMark[], active: string | null): DecorationSet {
|
|
89
|
+
const size = doc.content.size;
|
|
90
|
+
return DecorationSet.create(doc, marks.filter(mark => mark.from < mark.to && mark.to <= size)
|
|
91
|
+
.map(mark => Decoration.inline(mark.from, mark.to, { class: mark.id === active ? 'cms-note cms-note-active' : 'cms-note', 'data-note': mark.id })));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The notes plugin: notes are set through a transaction's meta; the document's changes move them. */
|
|
95
|
+
export function notesPlugin(options: NotesPluginOptions): Plugin<NotesState> {
|
|
96
|
+
return new Plugin<NotesState>({
|
|
97
|
+
key: notesKey,
|
|
98
|
+
state: {
|
|
99
|
+
init: () => ({ marks: [], active: null, set: DecorationSet.empty }),
|
|
100
|
+
apply(transaction, value) {
|
|
101
|
+
const meta = transaction.getMeta(notesKey) as { inputs: readonly NoteMarkInput[]; active: string | null } | undefined;
|
|
102
|
+
if (meta) {
|
|
103
|
+
// A note already placed keeps the place the document's changes carried it to; a new one is put on its words; one no longer listed goes.
|
|
104
|
+
const placed = new Map(value.marks.map(mark => [mark.id, mark]));
|
|
105
|
+
const marks = meta.inputs.flatMap(input => {
|
|
106
|
+
const known = placed.get(input.id);
|
|
107
|
+
if (known) return [known];
|
|
108
|
+
const range = anchorNote(transaction.doc, input);
|
|
109
|
+
return range ? [{ id: input.id, from: range.from, to: range.to }] : [];
|
|
110
|
+
});
|
|
111
|
+
const same = marks.length === value.marks.length && marks.every((mark, index) => mark === value.marks[index]);
|
|
112
|
+
if (!same) queueMicrotask(() => options.onMoved(marks));
|
|
113
|
+
return { marks, active: meta.active, set: decorate(transaction.doc, marks, meta.active) };
|
|
114
|
+
}
|
|
115
|
+
if (!transaction.docChanged) return value;
|
|
116
|
+
const marks = value.marks.map(mark => ({ id: mark.id, from: transaction.mapping.map(mark.from, 1), to: transaction.mapping.map(mark.to, -1) })).filter(mark => mark.from < mark.to);
|
|
117
|
+
if (marks.length !== value.marks.length || marks.some((mark, index) => mark.from !== value.marks[index]!.from || mark.to !== value.marks[index]!.to)) queueMicrotask(() => options.onMoved(marks));
|
|
118
|
+
return { marks, active: value.active, set: decorate(transaction.doc, marks, value.active) };
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
props: {
|
|
122
|
+
decorations: state => notesKey.getState(state)?.set,
|
|
123
|
+
handleClick(_view, _position, event) {
|
|
124
|
+
const target = event.target instanceof Element ? event.target.closest('[data-note]') : null;
|
|
125
|
+
const id = target?.getAttribute('data-note');
|
|
126
|
+
if (!id) return false;
|
|
127
|
+
options.onClick(id);
|
|
128
|
+
return false;
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
view: () => { ensureStyle(); return {}; },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Place the notes in an editor's document; the plugin answers through `onMoved` with where each one sits. */
|
|
136
|
+
export function setNotes(view: { state: import('@tiptap/pm/state').EditorState; dispatch(tr: import('@tiptap/pm/state').Transaction): void }, inputs: readonly NoteMarkInput[], active: string | null): void {
|
|
137
|
+
view.dispatch(view.state.tr.setMeta(notesKey, { inputs, active }).setMeta('addToHistory', false));
|
|
138
|
+
}
|