@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,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rich text editor: TipTap (ProseMirror) configured to the CMS document contract, which
|
|
3
|
+
* `rich-text-schema.ts` defines for the editor and the entry room alike. The `.client.ts` name
|
|
4
|
+
* keeps TipTap out of server bundles; the server receives a stub. Only the nodes and marks the
|
|
5
|
+
* host accepts are registered, so pasted content is reduced to them, and links and images are
|
|
6
|
+
* filtered by the same URL rules as on save. With `collab`, the editor takes part in the
|
|
7
|
+
* entry's room: its steps go there, and the room's steps come back.
|
|
8
|
+
*/
|
|
9
|
+
import { Editor, type NodeViewRendererProps } from '@tiptap/core';
|
|
10
|
+
import { Placeholder } from '@tiptap/extensions';
|
|
11
|
+
import { safeImageUrl, safeLinkUrl, type EmbeddedBlock, type RichTextDoc } from '@cossackframework/cms';
|
|
12
|
+
import { blockOf, cmsBlock, richTextExtensions, type BlockView } from './rich-text-schema';
|
|
13
|
+
import { CollabSession, collabPlugins, type Caret, type CollabOptions } from './collab/rich-text-collab.client';
|
|
14
|
+
import { notesPlugin, setNotes, type NoteMark, type NoteMarkInput, type NotesPluginOptions } from './collab/rich-text-notes.client';
|
|
15
|
+
|
|
16
|
+
export type { Caret, CollabOptions, CollabTransport, StepsResult } from './collab/rich-text-collab.client';
|
|
17
|
+
export type { NoteMark, NoteMarkInput } from './collab/rich-text-notes.client';
|
|
18
|
+
|
|
19
|
+
export type RichTextCommand =
|
|
20
|
+
| 'paragraph' | 'heading2' | 'heading3' | 'heading4' | 'bold' | 'italic' | 'underline' | 'strike' | 'code'
|
|
21
|
+
| 'bulletList' | 'orderedList' | 'blockquote' | 'codeBlock' | 'horizontalRule' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'undo' | 'redo' | 'unlink'
|
|
22
|
+
| 'table' | 'tableRowAfter' | 'tableColumnAfter' | 'tableDeleteRow' | 'tableDeleteColumn' | 'tableDelete' | 'tableHeaderRow';
|
|
23
|
+
|
|
24
|
+
export interface RichTextHandle {
|
|
25
|
+
run(command: RichTextCommand): void;
|
|
26
|
+
/** Link the selection, or the word at the cursor. */
|
|
27
|
+
link(href: string, newTab: boolean): void;
|
|
28
|
+
/** The link at the selection, for the link form. */
|
|
29
|
+
linkAt(): { href: string; newTab: boolean } | null;
|
|
30
|
+
insertImage(image: { src: string; alt: string; mediaId?: string }): void;
|
|
31
|
+
insertLink(text: string, href: string): void;
|
|
32
|
+
/** Plain text at the cursor, such as a `{{ $.price }}` binding. */
|
|
33
|
+
insertText(text: string): void;
|
|
34
|
+
insertBlock(block: EmbeddedBlock): void;
|
|
35
|
+
updateBlock(id: string, data: EmbeddedBlock['data']): void;
|
|
36
|
+
/** Insert a document's content after the top-level node holding the cursor, such as a pattern's copy. */
|
|
37
|
+
insertContent(doc: RichTextDoc): void;
|
|
38
|
+
/** Replace an embedded block with a document's content, such as when detaching a synced pattern. */
|
|
39
|
+
replaceBlock(id: string, doc: RichTextDoc): void;
|
|
40
|
+
/** Replace the whole document from outside (a restored autosave, a saved entry), without reporting it as a change. */
|
|
41
|
+
setContent(doc: RichTextDoc | null): void;
|
|
42
|
+
/** The current selection, as ProseMirror positions. */
|
|
43
|
+
selection(): { anchor: number; head: number };
|
|
44
|
+
/** The document's text between two positions. */
|
|
45
|
+
textBetween(from: number, to: number): string;
|
|
46
|
+
/** Place the notes on their passages (with `notes`); the plugin answers through `onMoved` with where each one sits. */
|
|
47
|
+
setNotes(inputs: readonly NoteMarkInput[], active: string | null): void;
|
|
48
|
+
/** The editor's part in the room, with `collab`. */
|
|
49
|
+
collab: CollabSession | null;
|
|
50
|
+
focus(): void;
|
|
51
|
+
destroy(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface RichTextOptions {
|
|
55
|
+
content: RichTextDoc | null;
|
|
56
|
+
label: string;
|
|
57
|
+
placeholder: string;
|
|
58
|
+
/** Classes of the editable surface. */
|
|
59
|
+
className: string;
|
|
60
|
+
blockLabel(type: string): string;
|
|
61
|
+
/** A line describing the block's content in the editor. */
|
|
62
|
+
blockSummary(block: EmbeddedBlock): string;
|
|
63
|
+
onChange(doc: RichTextDoc): void;
|
|
64
|
+
/** Names of the formats active at the selection, for the toolbar. */
|
|
65
|
+
onSelection(active: string[]): void;
|
|
66
|
+
onEditBlock(block: EmbeddedBlock): void;
|
|
67
|
+
/** The selection moved: its ProseMirror positions, for other editors' carets. */
|
|
68
|
+
onCaret?(anchor: number, head: number): void;
|
|
69
|
+
/** Take part in the entry's room: the document comes from it and steps go through it. */
|
|
70
|
+
collab?: CollabOptions;
|
|
71
|
+
/** Show notes on passages, and say when they move or are clicked. */
|
|
72
|
+
notes?: NotesPluginOptions;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The editor's card for an embedded block: the block's name and Edit and Remove buttons. */
|
|
76
|
+
function blockCard(options: RichTextOptions): BlockView {
|
|
77
|
+
return () => ({ node: initial, editor, getPos }: NodeViewRendererProps) => {
|
|
78
|
+
let node = initial;
|
|
79
|
+
const dom = document.createElement('div');
|
|
80
|
+
dom.className = 'my-4 flex items-center justify-between gap-3 rounded-lg border border-dashed border-border bg-muted/40 px-4 py-3 not-prose';
|
|
81
|
+
dom.contentEditable = 'false';
|
|
82
|
+
const text = document.createElement('div');
|
|
83
|
+
text.className = 'min-w-0';
|
|
84
|
+
const title = document.createElement('p');
|
|
85
|
+
title.className = 'text-xs font-semibold uppercase tracking-wide text-muted-foreground';
|
|
86
|
+
const summary = document.createElement('p');
|
|
87
|
+
summary.className = 'truncate text-sm text-foreground';
|
|
88
|
+
text.appendChild(title);
|
|
89
|
+
text.appendChild(summary);
|
|
90
|
+
const actions = document.createElement('div');
|
|
91
|
+
actions.className = 'flex shrink-0 gap-2';
|
|
92
|
+
const button = (label: string, run: () => void) => {
|
|
93
|
+
const element = document.createElement('button');
|
|
94
|
+
element.type = 'button';
|
|
95
|
+
element.textContent = label;
|
|
96
|
+
element.className = 'rounded-md border border-border bg-background px-2.5 py-1 text-xs text-foreground hover:bg-muted cursor-pointer';
|
|
97
|
+
element.addEventListener('click', event => { event.preventDefault(); run(); });
|
|
98
|
+
return element;
|
|
99
|
+
};
|
|
100
|
+
const edit = button(__('Edit'), () => options.onEditBlock(blockOf(node)));
|
|
101
|
+
const remove = button(__('Remove'), () => {
|
|
102
|
+
const position = getPos();
|
|
103
|
+
if (typeof position === 'number') editor.chain().focus().deleteRange({ from: position, to: position + node.nodeSize }).run();
|
|
104
|
+
});
|
|
105
|
+
actions.appendChild(edit);
|
|
106
|
+
actions.appendChild(remove);
|
|
107
|
+
dom.appendChild(text);
|
|
108
|
+
dom.appendChild(actions);
|
|
109
|
+
const paint = () => {
|
|
110
|
+
const block = blockOf(node);
|
|
111
|
+
title.textContent = options.blockLabel(block.type);
|
|
112
|
+
summary.textContent = options.blockSummary(block);
|
|
113
|
+
edit.setAttribute('aria-label', `${__('Edit')} ${title.textContent}`);
|
|
114
|
+
remove.setAttribute('aria-label', `${__('Remove')} ${title.textContent}`);
|
|
115
|
+
};
|
|
116
|
+
paint();
|
|
117
|
+
return {
|
|
118
|
+
dom,
|
|
119
|
+
update: updated => {
|
|
120
|
+
if (updated.type.name !== 'cmsBlock') return false;
|
|
121
|
+
node = updated;
|
|
122
|
+
paint();
|
|
123
|
+
return true;
|
|
124
|
+
},
|
|
125
|
+
selectNode: () => dom.classList.add('ring-2', 'ring-ring'),
|
|
126
|
+
deselectNode: () => dom.classList.remove('ring-2', 'ring-ring'),
|
|
127
|
+
stopEvent: event => event.target instanceof HTMLButtonElement,
|
|
128
|
+
ignoreMutation: () => true,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function mountRichText(element: HTMLElement, options: RichTextOptions): RichTextHandle {
|
|
134
|
+
const active = (editor: Editor) => [
|
|
135
|
+
...(['bold', 'italic', 'underline', 'strike', 'code', 'bulletList', 'orderedList', 'blockquote', 'codeBlock', 'link', 'table'] as const).filter(name => editor.isActive(name)),
|
|
136
|
+
...([2, 3, 4] as const).filter(level => editor.isActive('heading', { level })).map(level => `heading${level}`),
|
|
137
|
+
...(['center', 'right'] as const).filter(align => editor.isActive({ textAlign: align })).map(align => `align${align[0]!.toUpperCase()}${align.slice(1)}`),
|
|
138
|
+
];
|
|
139
|
+
let session: CollabSession | null = null;
|
|
140
|
+
const editor = new Editor({
|
|
141
|
+
element,
|
|
142
|
+
extensions: [
|
|
143
|
+
...richTextExtensions(cmsBlock(blockCard(options))),
|
|
144
|
+
Placeholder.configure({ placeholder: options.placeholder }),
|
|
145
|
+
],
|
|
146
|
+
content: options.content && options.content.content.length ? options.content as never : '',
|
|
147
|
+
editorProps: { attributes: { class: options.className, 'aria-label': options.label, 'aria-multiline': 'true', role: 'textbox' } },
|
|
148
|
+
onUpdate: ({ editor }) => options.onChange(editor.getJSON() as RichTextDoc),
|
|
149
|
+
onSelectionUpdate: ({ editor }) => { options.onSelection(active(editor)); options.onCaret?.(editor.state.selection.anchor, editor.state.selection.head); },
|
|
150
|
+
onTransaction: ({ editor }) => { options.onSelection(active(editor)); session?.flush(); },
|
|
151
|
+
});
|
|
152
|
+
if (options.collab) {
|
|
153
|
+
for (const plugin of collabPlugins(options.collab)) editor.registerPlugin(plugin);
|
|
154
|
+
session = new CollabSession(editor, options.collab);
|
|
155
|
+
}
|
|
156
|
+
if (options.notes) editor.registerPlugin(notesPlugin(options.notes));
|
|
157
|
+
const chain = () => editor.chain().focus();
|
|
158
|
+
const find = (id: string): { position: number; size: number } | null => {
|
|
159
|
+
let found: { position: number; size: number } | null = null;
|
|
160
|
+
editor.state.doc.descendants((node, position) => {
|
|
161
|
+
if (found) return false;
|
|
162
|
+
if (node.type.name === 'cmsBlock' && node.attrs._id === id) found = { position, size: node.nodeSize };
|
|
163
|
+
return !found;
|
|
164
|
+
});
|
|
165
|
+
return found;
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
run(command) {
|
|
169
|
+
const run: Record<RichTextCommand, () => boolean> = {
|
|
170
|
+
paragraph: () => chain().setParagraph().run(),
|
|
171
|
+
heading2: () => chain().toggleHeading({ level: 2 }).run(),
|
|
172
|
+
heading3: () => chain().toggleHeading({ level: 3 }).run(),
|
|
173
|
+
heading4: () => chain().toggleHeading({ level: 4 }).run(),
|
|
174
|
+
bold: () => chain().toggleBold().run(),
|
|
175
|
+
italic: () => chain().toggleItalic().run(),
|
|
176
|
+
underline: () => chain().toggleUnderline().run(),
|
|
177
|
+
strike: () => chain().toggleStrike().run(),
|
|
178
|
+
code: () => chain().toggleCode().run(),
|
|
179
|
+
bulletList: () => chain().toggleBulletList().run(),
|
|
180
|
+
orderedList: () => chain().toggleOrderedList().run(),
|
|
181
|
+
blockquote: () => chain().toggleBlockquote().run(),
|
|
182
|
+
codeBlock: () => chain().toggleCodeBlock().run(),
|
|
183
|
+
horizontalRule: () => chain().setHorizontalRule().run(),
|
|
184
|
+
alignLeft: () => chain().setTextAlign('left').run(),
|
|
185
|
+
alignCenter: () => chain().setTextAlign('center').run(),
|
|
186
|
+
alignRight: () => chain().setTextAlign('right').run(),
|
|
187
|
+
undo: () => chain().undo().run(),
|
|
188
|
+
redo: () => chain().redo().run(),
|
|
189
|
+
unlink: () => chain().extendMarkRange('link').unsetLink().run(),
|
|
190
|
+
table: () => chain().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
|
|
191
|
+
tableRowAfter: () => chain().addRowAfter().run(),
|
|
192
|
+
tableColumnAfter: () => chain().addColumnAfter().run(),
|
|
193
|
+
tableDeleteRow: () => chain().deleteRow().run(),
|
|
194
|
+
tableDeleteColumn: () => chain().deleteColumn().run(),
|
|
195
|
+
tableDelete: () => chain().deleteTable().run(),
|
|
196
|
+
tableHeaderRow: () => chain().toggleHeaderRow().run(),
|
|
197
|
+
};
|
|
198
|
+
run[command]();
|
|
199
|
+
},
|
|
200
|
+
link(href, newTab) {
|
|
201
|
+
if (!safeLinkUrl(href)) return;
|
|
202
|
+
const attributes = { href, target: newTab ? '_blank' : null };
|
|
203
|
+
if (editor.state.selection.empty && !editor.isActive('link')) chain().insertContent({ type: 'text', text: href, marks: [{ type: 'link', attrs: attributes }] }).run();
|
|
204
|
+
else chain().extendMarkRange('link').setLink(attributes).run();
|
|
205
|
+
},
|
|
206
|
+
linkAt() {
|
|
207
|
+
if (!editor.isActive('link')) return null;
|
|
208
|
+
const attributes = editor.getAttributes('link');
|
|
209
|
+
return { href: String(attributes.href ?? ''), newTab: attributes.target === '_blank' };
|
|
210
|
+
},
|
|
211
|
+
insertImage(image) {
|
|
212
|
+
if (!safeImageUrl(image.src)) return;
|
|
213
|
+
chain().insertContent({ type: 'image', attrs: { src: image.src, alt: image.alt, mediaId: image.mediaId ?? null } }).run();
|
|
214
|
+
},
|
|
215
|
+
insertLink(text, href) {
|
|
216
|
+
if (!safeLinkUrl(href)) return;
|
|
217
|
+
chain().insertContent({ type: 'text', text, marks: [{ type: 'link', attrs: { href } }] }).run();
|
|
218
|
+
},
|
|
219
|
+
insertText(text) {
|
|
220
|
+
chain().insertContent({ type: 'text', text }).run();
|
|
221
|
+
},
|
|
222
|
+
insertBlock(block) {
|
|
223
|
+
// Blocks sit between top-level nodes: after the one holding the cursor.
|
|
224
|
+
const { $from } = editor.state.selection;
|
|
225
|
+
const position = $from.depth ? $from.after(1) : $from.pos;
|
|
226
|
+
chain().insertContentAt(position, { type: 'cmsBlock', attrs: { _id: block._id, type: block.type, data: block.data } }).run();
|
|
227
|
+
},
|
|
228
|
+
updateBlock(id, data) {
|
|
229
|
+
const found = find(id);
|
|
230
|
+
if (!found) return;
|
|
231
|
+
editor.chain().command(({ tr }) => {
|
|
232
|
+
const node = tr.doc.nodeAt(found.position);
|
|
233
|
+
if (!node) return false;
|
|
234
|
+
tr.setNodeMarkup(found.position, undefined, { ...node.attrs, data });
|
|
235
|
+
return true;
|
|
236
|
+
}).run();
|
|
237
|
+
},
|
|
238
|
+
insertContent(doc) {
|
|
239
|
+
const { $from } = editor.state.selection;
|
|
240
|
+
const position = $from.depth ? $from.after(1) : $from.pos;
|
|
241
|
+
chain().insertContentAt(position, doc.content).run();
|
|
242
|
+
},
|
|
243
|
+
replaceBlock(id, doc) {
|
|
244
|
+
const found = find(id);
|
|
245
|
+
if (found) chain().insertContentAt({ from: found.position, to: found.position + found.size }, doc.content).run();
|
|
246
|
+
},
|
|
247
|
+
setContent(doc) { editor.commands.setContent(doc && doc.content.length ? doc as never : '', { emitUpdate: false }); },
|
|
248
|
+
selection() { const { anchor, head } = editor.state.selection; return { anchor, head }; },
|
|
249
|
+
textBetween(from, to) { return editor.state.doc.textBetween(Math.max(0, from), Math.min(editor.state.doc.content.size, to), ' '); },
|
|
250
|
+
setNotes(inputs, active) { if (options.notes) setNotes(editor.view, inputs, active); },
|
|
251
|
+
collab: session,
|
|
252
|
+
focus() { editor.commands.focus(); },
|
|
253
|
+
destroy() { session?.destroy(); editor.destroy(); },
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The search box's browser part: suggestions while someone types. Up to five entries from the
|
|
3
|
+
* site's search (`data-suggest`, `/api/cms/search`), whose last word is a prefix, in a listbox
|
|
4
|
+
* under the box. The arrow keys move through them, Enter opens the one chosen, Escape closes the
|
|
5
|
+
* list. Without this the form still submits to the search page.
|
|
6
|
+
*/
|
|
7
|
+
interface Suggestion { readonly title: string; readonly url: string }
|
|
8
|
+
|
|
9
|
+
const enhanced = new WeakSet<HTMLFormElement>();
|
|
10
|
+
let lists = 0;
|
|
11
|
+
|
|
12
|
+
export function enhanceSearch(form: HTMLFormElement): void {
|
|
13
|
+
if (enhanced.has(form)) return;
|
|
14
|
+
enhanced.add(form);
|
|
15
|
+
const input = form.querySelector<HTMLInputElement>('input[name="q"]');
|
|
16
|
+
const endpoint = form.dataset.suggest;
|
|
17
|
+
if (!input || !endpoint) return;
|
|
18
|
+
const id = `cms-search-suggestions-${++lists}`;
|
|
19
|
+
const list = document.createElement('ul');
|
|
20
|
+
list.id = id;
|
|
21
|
+
list.className = 'cms-search-suggestions';
|
|
22
|
+
list.setAttribute('role', 'listbox');
|
|
23
|
+
list.setAttribute('aria-label', form.dataset.suggestLabel || 'Suggestions');
|
|
24
|
+
list.hidden = true;
|
|
25
|
+
form.appendChild(list);
|
|
26
|
+
input.setAttribute('role', 'combobox');
|
|
27
|
+
input.setAttribute('aria-autocomplete', 'list');
|
|
28
|
+
input.setAttribute('aria-controls', id);
|
|
29
|
+
input.setAttribute('aria-expanded', 'false');
|
|
30
|
+
input.autocomplete = 'off';
|
|
31
|
+
|
|
32
|
+
let shown: readonly Suggestion[] = [];
|
|
33
|
+
let active = -1;
|
|
34
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
35
|
+
let request: AbortController | undefined;
|
|
36
|
+
|
|
37
|
+
const close = () => {
|
|
38
|
+
list.hidden = true;
|
|
39
|
+
input.setAttribute('aria-expanded', 'false');
|
|
40
|
+
input.removeAttribute('aria-activedescendant');
|
|
41
|
+
active = -1;
|
|
42
|
+
};
|
|
43
|
+
const choose = (index: number) => {
|
|
44
|
+
active = index;
|
|
45
|
+
list.querySelectorAll('[role="option"]').forEach((option, at) => option.setAttribute('aria-selected', at === index ? 'true' : 'false'));
|
|
46
|
+
if (index < 0) input.removeAttribute('aria-activedescendant');
|
|
47
|
+
else input.setAttribute('aria-activedescendant', `${id}-${index}`);
|
|
48
|
+
};
|
|
49
|
+
const show = (items: readonly Suggestion[]) => {
|
|
50
|
+
shown = items;
|
|
51
|
+
active = -1;
|
|
52
|
+
list.replaceChildren(...items.map((item, index) => {
|
|
53
|
+
const option = document.createElement('li');
|
|
54
|
+
option.id = `${id}-${index}`;
|
|
55
|
+
option.setAttribute('role', 'option');
|
|
56
|
+
option.setAttribute('aria-selected', 'false');
|
|
57
|
+
// A real link, so a middle click or a modifier opens a tab; focus stays in the box.
|
|
58
|
+
const link = document.createElement('a');
|
|
59
|
+
link.href = item.url;
|
|
60
|
+
link.tabIndex = -1;
|
|
61
|
+
link.textContent = item.title;
|
|
62
|
+
option.appendChild(link);
|
|
63
|
+
return option;
|
|
64
|
+
}));
|
|
65
|
+
if (!items.length) return close();
|
|
66
|
+
list.hidden = false;
|
|
67
|
+
input.setAttribute('aria-expanded', 'true');
|
|
68
|
+
input.removeAttribute('aria-activedescendant');
|
|
69
|
+
};
|
|
70
|
+
const suggest = async (text: string) => {
|
|
71
|
+
request?.abort();
|
|
72
|
+
if (text.length < 2) return show([]);
|
|
73
|
+
request = new AbortController();
|
|
74
|
+
try {
|
|
75
|
+
const url = `${endpoint}${endpoint.includes('?') ? '&' : '?'}q=${encodeURIComponent(text)}`;
|
|
76
|
+
const response = await fetch(url, { headers: { accept: 'application/json' }, credentials: 'same-origin', signal: request.signal });
|
|
77
|
+
if (!response.ok) return show([]);
|
|
78
|
+
const body = await response.json() as { items?: { title?: unknown; url?: unknown }[] };
|
|
79
|
+
// Only what is still typed is shown: a slower answer for older text never replaces it.
|
|
80
|
+
if (input.value.trim() !== text) return;
|
|
81
|
+
show((body.items ?? []).flatMap(item => typeof item.title === 'string' && typeof item.url === 'string' && item.url.startsWith('/') ? [{ title: item.title, url: item.url }] : []).slice(0, 5));
|
|
82
|
+
} catch {
|
|
83
|
+
/* aborted for newer text, or offline: the form still submits */
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
input.addEventListener('input', () => {
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
const text = input.value.trim();
|
|
90
|
+
timer = setTimeout(() => void suggest(text), 150);
|
|
91
|
+
});
|
|
92
|
+
input.addEventListener('keydown', event => {
|
|
93
|
+
if (event.key === 'Escape' && !list.hidden) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
close();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
99
|
+
if (list.hidden || !shown.length) return;
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
const step = event.key === 'ArrowDown' ? 1 : -1;
|
|
102
|
+
choose(active < 0 ? (step > 0 ? 0 : shown.length - 1) : (active + step + shown.length) % shown.length);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (event.key === 'Enter' && !list.hidden && active >= 0) {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
window.location.assign(shown[active]!.url);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
// Pressing an option must not blur the box first, or the list closes under the pointer.
|
|
111
|
+
list.addEventListener('mousedown', event => event.preventDefault());
|
|
112
|
+
form.addEventListener('focusout', event => {
|
|
113
|
+
if (!form.contains(event.relatedTarget as Node | null)) close();
|
|
114
|
+
});
|
|
115
|
+
input.addEventListener('focus', () => { if (shown.length && input.value.trim().length >= 2) show(shown); });
|
|
116
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Head tags of a site page from its SEO data: title, description, canonical link, robots,
|
|
3
|
+
* Open Graph and Twitter cards, language alternates and JSON-LD. Client-safe; pages compute
|
|
4
|
+
* the data on the server and keep it in state.
|
|
5
|
+
*/
|
|
6
|
+
import type { HeadValue } from '@cossackframework/core';
|
|
7
|
+
|
|
8
|
+
export interface SeoView {
|
|
9
|
+
/** The whole `<title>`, from the template. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** The title shared links carry: the page's own, without the site title. */
|
|
12
|
+
ogTitle: string;
|
|
13
|
+
/** The description shared links carry; the meta description unless a social one is set. */
|
|
14
|
+
ogDescription: string;
|
|
15
|
+
description: string;
|
|
16
|
+
/** Absolute URL. */
|
|
17
|
+
canonical: string;
|
|
18
|
+
/** Absolute image URL, or empty. */
|
|
19
|
+
image: string;
|
|
20
|
+
imageWidth: number | null;
|
|
21
|
+
imageHeight: number | null;
|
|
22
|
+
imageAlt: string;
|
|
23
|
+
/** Robots directives such as `noindex, max-image-preview:large`, or empty. */
|
|
24
|
+
robots: string;
|
|
25
|
+
type: 'website' | 'article' | 'profile';
|
|
26
|
+
siteName: string;
|
|
27
|
+
/** BCP 47 language of the page, such as `en` or `pt-br`. */
|
|
28
|
+
locale: string;
|
|
29
|
+
/** The site's X account, with `@`, or empty. */
|
|
30
|
+
twitterSite: string;
|
|
31
|
+
publishedTime: string;
|
|
32
|
+
modifiedTime: string;
|
|
33
|
+
/** The page in other languages, absolute. */
|
|
34
|
+
alternates: { hreflang: string; href: string }[];
|
|
35
|
+
/** Structured data as JSON text, or empty. */
|
|
36
|
+
jsonLd: string;
|
|
37
|
+
/** The entry as Markdown (`?format=md`), absolute, or empty. */
|
|
38
|
+
markdownUrl: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function emptySeo(): SeoView {
|
|
42
|
+
return { title: '', ogTitle: '', ogDescription: '', description: '', canonical: '', image: '', imageWidth: null, imageHeight: null, imageAlt: '', robots: '', type: 'website', siteName: '', locale: '', twitterSite: '', publishedTime: '', modifiedTime: '', alternates: [], jsonLd: '', markdownUrl: '' };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function seoHead(seo: SeoView): HeadValue {
|
|
46
|
+
const meta = (property: string, content: string) => content ? [{ tag: 'meta', attributes: { property, content } }] : [];
|
|
47
|
+
const name = (key: string, content: string) => content ? [{ tag: 'meta', attributes: { name: key, content } }] : [];
|
|
48
|
+
return {
|
|
49
|
+
...(seo.title ? { title: seo.title } : {}),
|
|
50
|
+
...(seo.image ? { image: seo.image } : {}),
|
|
51
|
+
meta: [
|
|
52
|
+
// The meta description and the shared one apart, so a social description can differ.
|
|
53
|
+
...name('description', seo.description),
|
|
54
|
+
...meta('og:description', seo.ogDescription || seo.description),
|
|
55
|
+
...name('robots', seo.robots),
|
|
56
|
+
...meta('og:type', seo.type),
|
|
57
|
+
...meta('og:title', seo.ogTitle),
|
|
58
|
+
...meta('og:url', seo.canonical),
|
|
59
|
+
...meta('og:site_name', seo.siteName),
|
|
60
|
+
...meta('og:locale', seo.locale.replace('-', '_')),
|
|
61
|
+
...meta('og:image:width', seo.image && seo.imageWidth ? String(seo.imageWidth) : ''),
|
|
62
|
+
...meta('og:image:height', seo.image && seo.imageHeight ? String(seo.imageHeight) : ''),
|
|
63
|
+
...meta('og:image:alt', seo.image ? seo.imageAlt : ''),
|
|
64
|
+
...meta('article:published_time', seo.type === 'article' ? seo.publishedTime : ''),
|
|
65
|
+
...meta('article:modified_time', seo.type === 'article' ? seo.modifiedTime : ''),
|
|
66
|
+
...name('twitter:card', seo.image ? 'summary_large_image' : 'summary'),
|
|
67
|
+
...name('twitter:site', seo.twitterSite),
|
|
68
|
+
...name('twitter:title', seo.ogTitle),
|
|
69
|
+
...name('twitter:description', seo.ogDescription || seo.description),
|
|
70
|
+
],
|
|
71
|
+
links: [
|
|
72
|
+
...(seo.canonical ? [{ tag: 'link', attributes: { rel: 'canonical', href: seo.canonical } }] : []),
|
|
73
|
+
...seo.alternates.map(alternate => ({ tag: 'link', attributes: { rel: 'alternate', hreflang: alternate.hreflang, href: alternate.href } })),
|
|
74
|
+
...(seo.markdownUrl ? [{ tag: 'link', attributes: { rel: 'alternate', type: 'text/markdown', href: seo.markdownUrl } }] : []),
|
|
75
|
+
],
|
|
76
|
+
scripts: seo.jsonLd ? [{ tag: 'script', attributes: { type: 'application/ld+json' }, children: seo.jsonLd }] : [],
|
|
77
|
+
};
|
|
78
|
+
}
|