@cossackframework/cms 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +123 -3
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rich text field of the entry editor: a WordPress-style toolbar over a TipTap surface.
|
|
3
|
+
* The editor loads in the browser only; the field stores the document as JSON.
|
|
4
|
+
*/
|
|
5
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
6
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { DropdownMenu, Icon } from '@cossackframework/ui';
|
|
8
|
+
import type { EmbeddedBlock, NoteRange, RichTextDoc } from '@cossackframework/cms';
|
|
9
|
+
import type { CollabTransport, NoteMark, NoteMarkInput, RichTextCommand, RichTextHandle } from './rich-text.client';
|
|
10
|
+
import { BlockInserter, type BlockInserterProps } from './block-inserter';
|
|
11
|
+
import type { BindingChoice } from './field-controls';
|
|
12
|
+
import { icon } from './icons';
|
|
13
|
+
import { PROSE } from './site-view';
|
|
14
|
+
|
|
15
|
+
export type RichTextFieldProps = {
|
|
16
|
+
/** The field's element ID; the page reaches the editor by it in `richTextEditors`. */
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
value: RichTextDoc | null;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Block types that can be embedded. */
|
|
22
|
+
blocks: BlockInserterProps['blocks'];
|
|
23
|
+
onChange(doc: RichTextDoc): void;
|
|
24
|
+
/** Open the media library to insert an image or file. */
|
|
25
|
+
onMedia(): void;
|
|
26
|
+
/** Insert a new block of this type, then edit it. */
|
|
27
|
+
onInsertBlock(type: string): void;
|
|
28
|
+
onEditBlock(block: EmbeddedBlock): void;
|
|
29
|
+
/** Open the patterns, to insert one. */
|
|
30
|
+
onPatterns?(): void;
|
|
31
|
+
/** Titles of synced patterns by ID, shown on their blocks. */
|
|
32
|
+
patternTitles?: Record<string, string>;
|
|
33
|
+
/** Entry fields the text may show (`{{ $.price }}`); a toolbar menu inserts one at the cursor. */
|
|
34
|
+
bindings?: readonly BindingChoice[];
|
|
35
|
+
/** Edit the document together in the entry's room: it comes from there, and every change goes through it. */
|
|
36
|
+
collab?: RichTextCollabProps;
|
|
37
|
+
/** Notes on passages of this document: drawn as underlines, following the text as it changes. */
|
|
38
|
+
notes?: RichTextNotesProps;
|
|
39
|
+
/** Start a note: on the selected passage with its words, or without a range when nothing is selected. A toolbar button offers it. */
|
|
40
|
+
onNote?(range: NoteRange | null, quote: string): void;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface RichTextNotesProps {
|
|
44
|
+
/** The notes on this document, with their last known ranges and the words they quote. */
|
|
45
|
+
marks: readonly NoteMarkInput[];
|
|
46
|
+
/** The note open in the rail, drawn stronger. */
|
|
47
|
+
active: string | null;
|
|
48
|
+
/** A noted passage was clicked. */
|
|
49
|
+
onClick(id: string): void;
|
|
50
|
+
/** Where the notes sit now, after they were placed or the text moved; notes missing here could not be placed. */
|
|
51
|
+
onMoved(marks: readonly NoteMark[]): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface RichTextCollabProps {
|
|
55
|
+
/** The document's path in the room (`richTextPath`). */
|
|
56
|
+
path: string;
|
|
57
|
+
/** This browser tab's ID in the room. */
|
|
58
|
+
clientID: string;
|
|
59
|
+
transport: CollabTransport;
|
|
60
|
+
/** The selection moved, for other editors' carets. */
|
|
61
|
+
onSelection(anchor: number, head: number): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Mounted editors by field ID, for the page's media picker and block forms. */
|
|
65
|
+
export const richTextEditors = new Map<string, RichTextHandle>();
|
|
66
|
+
/** Mounted editors by their document's path in the room, for the room's steps and carets. */
|
|
67
|
+
export const collabEditors = new Map<string, RichTextHandle>();
|
|
68
|
+
|
|
69
|
+
const SURFACE = `${PROSE} min-h-[22rem] px-4 py-3 focus:outline-none [&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:float-left [&_p.is-editor-empty:first-child]:before:h-0 [&_p.is-editor-empty:first-child]:before:text-muted-foreground [&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)] [&_img.ProseMirror-selectednode]:ring-2 [&_img.ProseMirror-selectednode]:ring-ring`;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A document's identity, for telling the editor's own value from one set from outside: keys sorted, and null attributes left out, since the saved value and the
|
|
73
|
+
* room's copy write the same document differently (the saved one without `textAlign: null`).
|
|
74
|
+
*/
|
|
75
|
+
export function docKey(value: RichTextDoc | null | undefined): string {
|
|
76
|
+
try { return JSON.stringify(canonicalDoc(value ?? null)); } catch { return ''; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function canonicalDoc(value: unknown): unknown {
|
|
80
|
+
if (Array.isArray(value)) return value.map(canonicalDoc);
|
|
81
|
+
if (!value || typeof value !== 'object') return value;
|
|
82
|
+
const out: Record<string, unknown> = {};
|
|
83
|
+
for (const key of Object.keys(value).sort()) {
|
|
84
|
+
const item = canonicalDoc((value as Record<string, unknown>)[key]);
|
|
85
|
+
if (item === null || item === undefined) continue;
|
|
86
|
+
if (key === 'attrs' && typeof item === 'object' && !Object.keys(item).length) continue;
|
|
87
|
+
out[key] = item;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Component()
|
|
93
|
+
export class RichTextField extends Cossack {
|
|
94
|
+
declare props: RichTextFieldProps;
|
|
95
|
+
@ClientState() private ready = false;
|
|
96
|
+
@ClientState() private failed = '';
|
|
97
|
+
@ClientState() private active: string[] = [];
|
|
98
|
+
@ClientState() private linkOpen = false;
|
|
99
|
+
@ClientState() private linkUrl = '';
|
|
100
|
+
@ClientState() private linkNewTab = false;
|
|
101
|
+
/** Whether the editor takes part in the room, for the surface's `data-collab`. */
|
|
102
|
+
@ClientState() private shared = false;
|
|
103
|
+
/** Typing done before the room came up could not go to it: someone else changed the document first. */
|
|
104
|
+
@ClientState() private lostEarly = false;
|
|
105
|
+
private handle?: RichTextHandle;
|
|
106
|
+
private surface?: HTMLElement;
|
|
107
|
+
/** The document the editor holds, as JSON: what it last emitted or was given. */
|
|
108
|
+
private held = '';
|
|
109
|
+
/** The value last compared with `held`: the page renders the same object again on every unrelated keystroke. */
|
|
110
|
+
private heldValue: RichTextDoc | null | undefined;
|
|
111
|
+
/** When the room's document could not be fetched: the editor runs alone until this time, then tries again. */
|
|
112
|
+
private collabRetryAt = 0;
|
|
113
|
+
/** The document a lone editor (no room yet) started from, as JSON; what it holds differs once someone typed. */
|
|
114
|
+
private aloneFrom: string | undefined;
|
|
115
|
+
/** A mount is under way (the editor loads, the room answers): no second one starts meanwhile. */
|
|
116
|
+
private busy = false;
|
|
117
|
+
/** The notes last placed, as JSON, so unchanged notes are not placed again on every render. */
|
|
118
|
+
private notesPlaced = '';
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A value that changed outside the editor (a restored autosave, the entry as saved, a pattern
|
|
122
|
+
* put in by the page) replaces the document; the editor's own edits come back as the same
|
|
123
|
+
* value and leave it alone.
|
|
124
|
+
*/
|
|
125
|
+
@Client()
|
|
126
|
+
updated(changed: Map<string | number | symbol, unknown>) {
|
|
127
|
+
super.updated(changed);
|
|
128
|
+
// The room came up after the editor mounted: mount again, on the room's document.
|
|
129
|
+
if (this.props.collab && this.handle && !this.handle.collab && this.surface && this.ready && !this.busy && Date.now() >= this.collabRetryAt) {
|
|
130
|
+
const element = this.surface;
|
|
131
|
+
this.surface = undefined;
|
|
132
|
+
void this.connect(element);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (this.handle && this.ready) this.placeNotes();
|
|
136
|
+
// In a room the document is the room's: it changes through steps alone.
|
|
137
|
+
if (this.props.collab || !this.handle || !this.ready || this.props.value === this.heldValue) return;
|
|
138
|
+
this.heldValue = this.props.value;
|
|
139
|
+
const next = docKey(this.props.value);
|
|
140
|
+
if (next === this.held) return;
|
|
141
|
+
this.held = next;
|
|
142
|
+
this.handle.setContent(this.props.value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@Client()
|
|
146
|
+
private async connect(element: Element | undefined) {
|
|
147
|
+
if (!element || this.surface === element || this.busy) return;
|
|
148
|
+
this.surface = element as HTMLElement;
|
|
149
|
+
this.busy = true;
|
|
150
|
+
try {
|
|
151
|
+
const { mountRichText } = await import('./rich-text.client');
|
|
152
|
+
// A lone editor that is mounted again on the room's document: what was typed before the room came up.
|
|
153
|
+
const early = this.handle && !this.handle.collab && this.aloneFrom !== undefined && this.held !== this.aloneFrom
|
|
154
|
+
? { from: this.aloneFrom, doc: this.heldValue ?? null } : null;
|
|
155
|
+
this.handle?.destroy();
|
|
156
|
+
const labels = new Map(this.props.blocks.map(block => [block.name, block.label]));
|
|
157
|
+
// In a room the document starts as the room holds it, at the room's version; when the room cannot be
|
|
158
|
+
// reached, the editor runs alone for a while and joins when it comes up.
|
|
159
|
+
const shared = this.props.collab ? await this.sharedDocument(this.props.collab) : null;
|
|
160
|
+
const collab = shared ? this.props.collab : undefined;
|
|
161
|
+
if (this.surface !== element) return;
|
|
162
|
+
this.handle = mountRichText(this.surface, {
|
|
163
|
+
content: shared ? shared.doc : this.props.value, label: this.props.label, placeholder: this.props.placeholder ?? __('Start writing…'), className: SURFACE,
|
|
164
|
+
...(collab && shared ? { collab: { transport: collab.transport, clientID: collab.clientID, version: shared.version }, onCaret: (anchor: number, head: number) => collab.onSelection(anchor, head) } : {}),
|
|
165
|
+
...(this.props.notes ? { notes: { onClick: (id: string) => this.props.notes?.onClick(id), onMoved: (marks: readonly NoteMark[]) => this.props.notes?.onMoved(marks) } } : {}),
|
|
166
|
+
blockLabel: type => type === 'core/pattern' ? __('Synced pattern') : labels.get(type) ?? type,
|
|
167
|
+
blockSummary: block => block.type === 'core/pattern' ? this.props.patternTitles?.[String(block.data.pattern)] ?? __('Pattern')
|
|
168
|
+
: Object.values(block.data).find((value): value is string => typeof value === 'string' && value.trim() !== '') ?? '',
|
|
169
|
+
onChange: doc => { this.held = docKey(doc); this.heldValue = doc; this.props.onChange(doc); },
|
|
170
|
+
onSelection: active => { if (active.join() !== this.active.join()) this.active = active; },
|
|
171
|
+
onEditBlock: block => this.props.onEditBlock(block),
|
|
172
|
+
});
|
|
173
|
+
richTextEditors.set(this.props.id, this.handle);
|
|
174
|
+
if (collab) collabEditors.set(collab.path, this.handle);
|
|
175
|
+
this.held = docKey(shared ? shared.doc : this.props.value);
|
|
176
|
+
this.heldValue = shared ? shared.doc : this.props.value;
|
|
177
|
+
this.aloneFrom = collab ? undefined : this.held;
|
|
178
|
+
this.shared = Boolean(collab);
|
|
179
|
+
this.ready = true;
|
|
180
|
+
this.notesPlaced = '';
|
|
181
|
+
this.placeNotes();
|
|
182
|
+
if (shared && early) {
|
|
183
|
+
// Typing done while the editor ran alone goes to the room as steps, unless someone
|
|
184
|
+
// changed the room's document meanwhile: then the room's stays, and the editor says so.
|
|
185
|
+
if (docKey(shared.doc) === early.from) {
|
|
186
|
+
this.handle.setContent(early.doc);
|
|
187
|
+
this.held = docKey(early.doc);
|
|
188
|
+
this.heldValue = early.doc;
|
|
189
|
+
this.props.onChange(early.doc ?? { type: 'doc', content: [] });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.lostEarly = true;
|
|
193
|
+
}
|
|
194
|
+
// The page's values follow the room's document.
|
|
195
|
+
if (shared && docKey(shared.doc) !== docKey(this.props.value)) this.props.onChange(shared.doc ?? { type: 'doc', content: [] });
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error('[cms] the rich text editor could not load', error);
|
|
198
|
+
this.failed = __('The editor could not load. Reload the page to try again.');
|
|
199
|
+
} finally { this.busy = false; }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The room's document, asked for a few times while the connection settles; null when the room stays out of reach. */
|
|
203
|
+
@Client()
|
|
204
|
+
private async sharedDocument(collab: RichTextCollabProps): Promise<{ doc: RichTextDoc | null; version: number } | null> {
|
|
205
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
206
|
+
try { return await collab.transport.document(); }
|
|
207
|
+
catch { await new Promise(resolve => setTimeout(resolve, 300 * (attempt + 1))); }
|
|
208
|
+
}
|
|
209
|
+
this.collabRetryAt = Date.now() + 5000;
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
onCleanup() {
|
|
214
|
+
this.handle?.destroy();
|
|
215
|
+
if (richTextEditors.get(this.props.id) === this.handle) richTextEditors.delete(this.props.id);
|
|
216
|
+
if (this.props.collab && collabEditors.get(this.props.collab.path) === this.handle) collabEditors.delete(this.props.collab.path);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@Client()
|
|
220
|
+
private run(command: RichTextCommand) {
|
|
221
|
+
this.handle?.run(command);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Put the notes on their passages when they changed since last time. */
|
|
225
|
+
@Client()
|
|
226
|
+
private placeNotes() {
|
|
227
|
+
const notes = this.props.notes;
|
|
228
|
+
if (!notes || !this.handle) return;
|
|
229
|
+
const key = JSON.stringify([notes.marks, notes.active]);
|
|
230
|
+
if (key === this.notesPlaced) return;
|
|
231
|
+
this.notesPlaced = key;
|
|
232
|
+
this.handle.setNotes(notes.marks, notes.active);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** A note on the selection: its range and words; without a selection, one on the document as a whole. */
|
|
236
|
+
@Client()
|
|
237
|
+
private note() {
|
|
238
|
+
if (!this.handle || !this.props.onNote) return;
|
|
239
|
+
const { anchor, head } = this.handle.selection();
|
|
240
|
+
const from = Math.min(anchor, head);
|
|
241
|
+
const to = Math.max(anchor, head);
|
|
242
|
+
if (from === to) this.props.onNote(null, '');
|
|
243
|
+
else this.props.onNote({ from, to }, this.handle.textBetween(from, to));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@Client()
|
|
247
|
+
private bind(name: string) {
|
|
248
|
+
this.handle?.insertText(`{{ $.${name} }}`);
|
|
249
|
+
this.handle?.focus();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@Client()
|
|
253
|
+
private openLink() {
|
|
254
|
+
const current = this.handle?.linkAt();
|
|
255
|
+
this.linkUrl = current?.href ?? '';
|
|
256
|
+
this.linkNewTab = current?.newTab ?? false;
|
|
257
|
+
this.linkOpen = true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@Client()
|
|
261
|
+
private applyLink(event: Event) {
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
const url = this.linkUrl.trim();
|
|
264
|
+
if (url) this.handle?.link(/^[a-z][a-z0-9+.-]*:|^[/#]/i.test(url) ? url : `https://${url}`, this.linkNewTab);
|
|
265
|
+
else this.handle?.run('unlink');
|
|
266
|
+
this.linkOpen = false;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private tool(label: string, title: string, command: RichTextCommand | (() => void), name = typeof command === 'string' ? command : ''): TemplateResult {
|
|
270
|
+
const on = name !== '' && this.active.includes(name);
|
|
271
|
+
return html`<button type="button" title=${title} aria-label=${title} aria-pressed=${name ? (on ? 'true' : 'false') : ''} ?disabled=${!this.ready}
|
|
272
|
+
class=${`min-w-8 rounded px-2 py-1 text-xs font-medium border-none cursor-pointer disabled:cursor-default disabled:opacity-40 ${on ? 'bg-muted text-foreground' : 'bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground'}`}
|
|
273
|
+
@click=${() => typeof command === 'string' ? this.run(command) : command()}>${label}</button>`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
render() {
|
|
277
|
+
const format = (['heading2', 'heading3', 'heading4'] as const).find(name => this.active.includes(name)) ?? 'paragraph';
|
|
278
|
+
const separator = html`<span aria-hidden="true" class="mx-1 h-5 w-px bg-border"></span>`;
|
|
279
|
+
return html`<div class="rounded-lg border border-border bg-card">
|
|
280
|
+
<div role="toolbar" aria-label=${`${this.props.label} ${__('formatting')}`} class="sticky top-0 z-10 flex flex-wrap items-center gap-0.5 rounded-t-lg border-b border-border bg-card px-2 py-1.5">
|
|
281
|
+
<select aria-label=${__('Text style')} ?disabled=${!this.ready} class="h-7 rounded border border-input bg-background px-1.5 text-xs text-foreground"
|
|
282
|
+
@change=${(event: Event) => this.run((event.target as HTMLSelectElement).value as RichTextCommand)}>
|
|
283
|
+
${([['paragraph', __('Paragraph')], ['heading2', __('Heading 2')], ['heading3', __('Heading 3')], ['heading4', __('Heading 4')]] as const)
|
|
284
|
+
.map(([value, label]) => html`<option value=${value} ?selected=${format === value}>${label}</option>`)}
|
|
285
|
+
</select>
|
|
286
|
+
${separator}
|
|
287
|
+
${this.tool('B', __('Bold'), 'bold')}${this.tool('I', __('Italic'), 'italic')}${this.tool('U', __('Underline'), 'underline')}${this.tool('S', __('Strikethrough'), 'strike')}${this.tool('</>', __('Code'), 'code')}
|
|
288
|
+
${separator}
|
|
289
|
+
${this.tool('•', __('Bulleted list'), 'bulletList')}${this.tool('1.', __('Numbered list'), 'orderedList')}${this.tool('“', __('Quote'), 'blockquote')}${this.tool('{ }', __('Code block'), 'codeBlock')}
|
|
290
|
+
${separator}
|
|
291
|
+
${this.tool('⇤', __('Align left'), 'alignLeft', '')}${this.tool('↔', __('Align center'), 'alignCenter')}${this.tool('⇥', __('Align right'), 'alignRight')}
|
|
292
|
+
${separator}
|
|
293
|
+
${this.tool(__('Link'), __('Insert or edit link'), () => this.openLink(), 'link')}${this.tool('—', __('Horizontal line'), 'horizontalRule', '')}
|
|
294
|
+
${this.tool('⊞', __('Insert a table'), 'table')}
|
|
295
|
+
${this.active.includes('table') ? html`${this.tool('+⇣', __('Add a row below'), 'tableRowAfter', '')}${this.tool('+⇢', __('Add a column to the right'), 'tableColumnAfter', '')}${this.tool('−⇣', __('Delete the row'), 'tableDeleteRow', '')}${this.tool('−⇢', __('Delete the column'), 'tableDeleteColumn', '')}${this.tool('H', __('Toggle the header row'), 'tableHeaderRow', '')}${this.tool('⌫⊞', __('Delete the table'), 'tableDelete', '')}` : null}
|
|
296
|
+
${this.tool('↶', __('Undo'), 'undo', '')}${this.tool('↷', __('Redo'), 'redo', '')}
|
|
297
|
+
${separator}
|
|
298
|
+
${this.tool(__('Add media'), __('Add media'), () => this.props.onMedia())}
|
|
299
|
+
${this.props.onPatterns ? this.tool(__('Patterns'), __('Insert a pattern'), () => this.props.onPatterns?.()) : null}
|
|
300
|
+
${this.props.onNote ? this.tool(__('Note'), __('Add a note on the selection'), () => this.note()) : null}
|
|
301
|
+
${this.props.bindings?.length ? component(DropdownMenu, { id: `${this.props.id}-bind`, side: 'bottom', align: 'end', 'aria-label': __('Show a field of the entry'), title: __('Show a field of the entry'),
|
|
302
|
+
disabled: !this.ready, class: 'inline-flex h-7 w-8 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground [&_svg]:size-4',
|
|
303
|
+
trigger: component(Icon, { entry: icon('database'), size: 16 }) }, html`
|
|
304
|
+
<p class="px-2 py-1.5 text-xs text-muted-foreground">${__('Show the value of')}</p>
|
|
305
|
+
${this.props.bindings.map(choice => html`<button type="button" role="menuitem" tabindex="-1" class="flex w-full items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-left text-sm text-foreground hover:bg-muted cursor-pointer border-none bg-transparent"
|
|
306
|
+
@click=${() => this.bind(choice.name)}><span class="truncate">${choice.label}</span><code class="shrink-0 text-xs text-muted-foreground">{{ $.${choice.name} }}</code></button>`)}`) : null}
|
|
307
|
+
${this.props.blocks.length ? component(BlockInserter, { id: `${this.props.id}-blocks`, blocks: this.props.blocks, disabled: !this.ready, compact: true, plain: true,
|
|
308
|
+
onPick: (name: string) => this.props.onInsertBlock(name) }) : null}
|
|
309
|
+
</div>
|
|
310
|
+
${this.linkOpen ? html`<form class="flex flex-wrap items-center gap-2 border-b border-border px-3 py-2" @submit=${(event: Event) => this.applyLink(event)}>
|
|
311
|
+
<input type="text" inputmode="url" aria-label=${__('Link URL')} placeholder="https://" .value=${this.linkUrl} autofocus
|
|
312
|
+
class="min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
313
|
+
@input=${(event: Event) => { this.linkUrl = (event.target as HTMLInputElement).value; }}>
|
|
314
|
+
<label class="flex items-center gap-1.5 text-xs text-foreground"><input type="checkbox" .checked=${this.linkNewTab}
|
|
315
|
+
@change=${(event: Event) => { this.linkNewTab = (event.target as HTMLInputElement).checked; }}> ${__('Open in a new tab')}</label>
|
|
316
|
+
<button type="submit" class="rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground border-none cursor-pointer">${this.linkUrl.trim() ? __('Apply') : __('Remove link')}</button>
|
|
317
|
+
<button type="button" class="rounded-md border border-border bg-background px-3 py-1 text-xs text-foreground cursor-pointer" @click=${() => { this.linkOpen = false; }}>${__('Cancel')}</button>
|
|
318
|
+
</form>` : null}
|
|
319
|
+
${this.failed ? html`<p role="alert" class="px-4 py-3 text-sm text-destructive">${this.failed}</p>`
|
|
320
|
+
: this.ready ? null : html`<p class="px-4 py-3 text-sm text-muted-foreground">${__('Loading the editor…')}</p>`}
|
|
321
|
+
${this.lostEarly ? html`<p role="status" class="px-4 py-2 text-xs text-muted-foreground">${__('Someone changed this text while the editor was connecting, so what you typed meanwhile was not kept.')}</p>` : null}
|
|
322
|
+
<div id=${this.props.id} class="rich-text-surface" data-collab=${this.shared ? 'on' : 'off'} ref=${(element: Element) => this.connect(element)}></div>
|
|
323
|
+
</div>`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rich text document contract as TipTap extensions, shared by the editor in the browser
|
|
3
|
+
* and the entry room on the server, which applies editors' steps to the same schema. Only the
|
|
4
|
+
* nodes and marks the host accepts are registered, so pasted content is reduced to them, and
|
|
5
|
+
* links and images are filtered by the same URL rules as on save. Node views, which need a
|
|
6
|
+
* document, are added by the editor alone (`rich-text.client.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { getSchema, Node, type Extensions, type NodeConfig } from '@tiptap/core';
|
|
9
|
+
import type { Schema } from '@tiptap/pm/model';
|
|
10
|
+
import { Document } from '@tiptap/extension-document';
|
|
11
|
+
import { Image } from '@tiptap/extension-image';
|
|
12
|
+
import { TextAlign } from '@tiptap/extension-text-align';
|
|
13
|
+
import { TableKit } from '@tiptap/extension-table';
|
|
14
|
+
import { StarterKit } from '@tiptap/starter-kit';
|
|
15
|
+
import { safeImageUrl, safeLinkUrl, type EmbeddedBlock } from '@cossackframework/cms';
|
|
16
|
+
|
|
17
|
+
/** The block a `cmsBlock` node stands for. */
|
|
18
|
+
export function blockOf(node: { attrs: Record<string, unknown> }): EmbeddedBlock {
|
|
19
|
+
return { _id: String(node.attrs._id), type: String(node.attrs.type), data: (node.attrs.data ?? {}) as EmbeddedBlock['data'] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** How the editor draws an embedded block: TipTap's node view factory. */
|
|
23
|
+
export type BlockView = NonNullable<NodeConfig['addNodeView']>;
|
|
24
|
+
|
|
25
|
+
/** Blocks as atoms between paragraphs. `view` adds the editor's card for one; without it the node renders its markup alone. */
|
|
26
|
+
export function cmsBlock(view?: BlockView) {
|
|
27
|
+
return Node.create({
|
|
28
|
+
name: 'cmsBlock',
|
|
29
|
+
group: 'cmsBlock',
|
|
30
|
+
atom: true,
|
|
31
|
+
selectable: true,
|
|
32
|
+
draggable: true,
|
|
33
|
+
addAttributes() {
|
|
34
|
+
return { _id: { default: null }, type: { default: null }, data: { default: {} } };
|
|
35
|
+
},
|
|
36
|
+
parseHTML() {
|
|
37
|
+
return [{
|
|
38
|
+
tag: 'div[data-cms-block]',
|
|
39
|
+
getAttrs: element => {
|
|
40
|
+
try { return { _id: element.getAttribute('data-id'), type: element.getAttribute('data-type'), data: JSON.parse(element.getAttribute('data-data') ?? '{}') }; }
|
|
41
|
+
catch { return false; }
|
|
42
|
+
},
|
|
43
|
+
}];
|
|
44
|
+
},
|
|
45
|
+
renderHTML({ node }) {
|
|
46
|
+
return ['div', { 'data-cms-block': '', 'data-id': node.attrs._id, 'data-type': node.attrs.type, 'data-data': JSON.stringify(node.attrs.data ?? {}) }];
|
|
47
|
+
},
|
|
48
|
+
...(view ? { addNodeView: view } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Images keep their media ID; pasted images from other sites are dropped unless they are https. */
|
|
53
|
+
export const MediaImage = Image.extend({
|
|
54
|
+
addAttributes() {
|
|
55
|
+
return {
|
|
56
|
+
...this.parent?.(),
|
|
57
|
+
mediaId: {
|
|
58
|
+
default: null,
|
|
59
|
+
parseHTML: element => element.getAttribute('data-media-id'),
|
|
60
|
+
renderHTML: attributes => attributes.mediaId ? { 'data-media-id': attributes.mediaId } : {},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
parseHTML() {
|
|
65
|
+
return [{ tag: 'img[src]', getAttrs: element => safeImageUrl(element.getAttribute('src')) ? null : false }];
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/** The extensions that define the document: the same list on both sides, so steps apply alike. */
|
|
70
|
+
export function richTextExtensions(block = cmsBlock()): Extensions {
|
|
71
|
+
return [
|
|
72
|
+
Document.extend({ content: '(block | cmsBlock)+' }),
|
|
73
|
+
StarterKit.configure({
|
|
74
|
+
document: false,
|
|
75
|
+
heading: { levels: [2, 3, 4] },
|
|
76
|
+
link: { openOnClick: false, autolink: true, defaultProtocol: 'https', isAllowedUri: url => safeLinkUrl(url), shouldAutoLink: url => safeLinkUrl(url) },
|
|
77
|
+
}),
|
|
78
|
+
TextAlign.configure({ types: ['heading', 'paragraph'], alignments: ['left', 'center', 'right'] }),
|
|
79
|
+
MediaImage.configure({ inline: false, allowBase64: false }),
|
|
80
|
+
// Tables: rows of header and body cells, each holding blocks; the site renders them with `richTextHtml`.
|
|
81
|
+
TableKit.configure({ table: { resizable: false, HTMLAttributes: { class: 'cms-table' } } }),
|
|
82
|
+
block,
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let schema: Schema | undefined;
|
|
87
|
+
|
|
88
|
+
/** The document schema, built once; the room applies steps to documents of this schema. */
|
|
89
|
+
export function richTextSchema(): Schema {
|
|
90
|
+
return schema ??= getSchema(richTextExtensions());
|
|
91
|
+
}
|