@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,1008 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor on the public site, loaded only in edit mode. Click a block to edit its fields
|
|
3
|
+
* in a sheet at the side, as the dashboard's editor does, with Apply and Cancel; click the body
|
|
4
|
+
* to edit it as one document in the rich text editor. The Blocks panel shows the page's
|
|
5
|
+
* documents (the header, the entry's content, the footer areas), each a tree: drag a block, or
|
|
6
|
+
* use the arrow keys, to move it among its siblings or into and out of containers; a locked
|
|
7
|
+
* document (areas, for users without `cms:appearance`) is shown but selects nothing. The Entry
|
|
8
|
+
* panel edits the title, slug, terms and other fields. The device toggle narrows the
|
|
9
|
+
* content root. The editor's controls sit in the middle of the site taskbar, between its start
|
|
10
|
+
* menu and its user menu. Changes stay in the page's draft until saved.
|
|
11
|
+
*/
|
|
12
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
13
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
14
|
+
import { Button, Checkbox, Icon, MultiSelect, Sheet } from '@cossackframework/ui';
|
|
15
|
+
import { blockId, BLOCK_LIMITS, BREAKPOINTS, findBlock, formatNoteTarget, insertBlock, noteBlock, noteThreads, parseNoteTarget, parseRichTextPath, placeBlocks, removeBlock, richTextPath, shiftBlock, updateBlock, type BlockMove, type BlockPlace, type Breakpoint, type EmbeddedBlock, type Note, type NoteRange, type NoteStatus, type RichTextDoc } from '@cossackframework/cms';
|
|
16
|
+
import { blockDefaults, controlValue, editorInput, newBlock, type BlockOption, type EditorValues } from './editor';
|
|
17
|
+
import { BREAKPOINT_DEVICES, blockSummary, declarationsOf, offeredIn } from './block-tree';
|
|
18
|
+
import { icon } from './icons';
|
|
19
|
+
import { blockFields, fieldControl, type MediaHooks, type MediaPreview } from './field-controls';
|
|
20
|
+
import { blockTabs, styleControls, styleValues, withStyle, type BlockTab, type StyleValues } from './style-controls';
|
|
21
|
+
import { chooserKind, mediaChooser, uploadMedia, withFile } from './media-chooser';
|
|
22
|
+
import { RichTextField, richTextEditors, type RichTextFieldProps } from './rich-text-field';
|
|
23
|
+
import type { NoteMark } from './rich-text.client';
|
|
24
|
+
import { noteButton, noteMarker, notesRail, type NoteAnchorView, type NoteComposer } from './notes-rail';
|
|
25
|
+
import { BlockInserter } from './block-inserter';
|
|
26
|
+
import { reorderBlocks, type DraftBlock, type SiteDocument, type SiteEditorProps } from './site-editor';
|
|
27
|
+
import { CONTROL } from './ui';
|
|
28
|
+
|
|
29
|
+
const BODY_EDITOR = 'site-editor-body';
|
|
30
|
+
/** The removal buttons' icon; a fresh template each time, as the renderer keys templates by instance. */
|
|
31
|
+
const trash = () => html`<span class="inline-flex [&_svg]:size-3.5">${component(Icon, { entry: icon('trash-bin-trash'), size: 14 })}</span>`;
|
|
32
|
+
const PANEL = 'fixed z-50 flex flex-col overflow-hidden border border-border bg-background text-foreground shadow-2xl';
|
|
33
|
+
const STYLE = `
|
|
34
|
+
[data-cms-edit] > * { cursor: pointer; }
|
|
35
|
+
[data-cms-edit]:hover > * { outline: 2px dashed color-mix(in oklab, var(--ring, #3b82f6) 70%, transparent); outline-offset: 4px; }
|
|
36
|
+
[data-cms-edit][data-cms-selected] > * { outline: 2px solid var(--ring, #3b82f6); outline-offset: 4px; }
|
|
37
|
+
[data-cms-edit][data-cms-locked] > * { cursor: not-allowed; }
|
|
38
|
+
[data-cms-edit][data-cms-locked]:hover > * { outline-style: dotted; outline-color: color-mix(in oklab, var(--muted-foreground, #64748b) 70%, transparent); }
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
/** A block's form, in the sheet at the side of the page. */
|
|
42
|
+
interface BlockForm { id: string; /** The document the block is in. */ doc: string; values: Record<string, unknown>; style: StyleValues; tab: BlockTab; errors: Record<string, string> }
|
|
43
|
+
/** A block embedded in the body, edited from the rich text editor. */
|
|
44
|
+
interface EmbeddedForm { id: string; type: string; values: Record<string, unknown>; errors: Record<string, string> }
|
|
45
|
+
type ChooserTarget = { kind: 'block' | 'embedded' | 'entry'; field: string } | { kind: 'richtext'; /** The editor to insert into; the body's by default. */ editor?: string }
|
|
46
|
+
| { kind: 'style'; /** The block form's background image or video. */ property: 'image' | 'video' };
|
|
47
|
+
interface Drag { /** The document whose list is dragged. */ doc: string; from: number; to: number; y: number; depth: number; moved: boolean }
|
|
48
|
+
type Device = 'desktop' | 'tablet' | 'phone';
|
|
49
|
+
/** A row of the Blocks panel, by document and block. */
|
|
50
|
+
const rowKey = (doc: string, id: string) => `${doc}\u0000${id}`;
|
|
51
|
+
const DEVICE_LABELS: { readonly [key in Device]: string } = { desktop: 'Desktop', tablet: 'Tablet', phone: 'Phone' };
|
|
52
|
+
|
|
53
|
+
@Component()
|
|
54
|
+
export class SiteEditor extends Cossack {
|
|
55
|
+
declare props: SiteEditorProps;
|
|
56
|
+
@ClientState() private form: BlockForm | null = null;
|
|
57
|
+
@ClientState() private embedded: EmbeddedForm | null = null;
|
|
58
|
+
@ClientState() private panel: 'entry' | 'blocks' | 'body' | null = null;
|
|
59
|
+
@ClientState() private drag: Drag | null = null;
|
|
60
|
+
@ClientState() private announcement = '';
|
|
61
|
+
@ClientState() private device: Device = 'desktop';
|
|
62
|
+
/** The document the block operations work on: `entry`, or an area's key. */
|
|
63
|
+
@ClientState() private doc = 'entry';
|
|
64
|
+
// Notes: the rail and its state; the notes themselves live in the draft, written through the content API.
|
|
65
|
+
@ClientState() private notesOpen = false;
|
|
66
|
+
@ClientState() private notesFilter: NoteStatus = 'open';
|
|
67
|
+
@ClientState() private composer: NoteComposer | null = null;
|
|
68
|
+
@ClientState() private editingNote: { id: string; body: string } | null = null;
|
|
69
|
+
@ClientState() private activeNote: string | null = null;
|
|
70
|
+
@ClientState() private notesBusy = false;
|
|
71
|
+
@ClientState() private notesError = '';
|
|
72
|
+
@ClientState() private detachedNotes: string[] = [];
|
|
73
|
+
private chooserTarget: ChooserTarget | null = null;
|
|
74
|
+
private root?: HTMLElement;
|
|
75
|
+
/** The Blocks panel's list of each document. */
|
|
76
|
+
private lists = new Map<string, HTMLElement>();
|
|
77
|
+
private rows = new Map<string, HTMLElement>();
|
|
78
|
+
private handles = new Map<string, HTMLElement>();
|
|
79
|
+
private pointer: { id: number; x: number; y: number; tops: number[]; bottoms: number[] } | null = null;
|
|
80
|
+
private style?: HTMLStyleElement;
|
|
81
|
+
private observer?: MutationObserver;
|
|
82
|
+
|
|
83
|
+
private readonly onDocumentClick = (event: MouseEvent) => {
|
|
84
|
+
const target = event.target as Element | null;
|
|
85
|
+
if (!target || this.root?.contains(target) || target.closest('dialog, [role="dialog"]')) return;
|
|
86
|
+
// The nearest block of this page: blocks rendered from elsewhere, such as a form's inputs, are
|
|
87
|
+
// marked too, so clicking one selects the block that shows them (the Form block). Each marker
|
|
88
|
+
// names its document: the entry, or a widget area.
|
|
89
|
+
const docOf = (node: Element) => node.getAttribute('data-cms-doc') ?? 'entry';
|
|
90
|
+
let marker = target.closest('[data-cms-edit]');
|
|
91
|
+
while (marker && marker.getAttribute('data-cms-edit') === 'block' && !findBlock(this.blocksOf(docOf(marker)), marker.getAttribute('data-block-id') ?? '')) marker = marker.parentElement?.closest('[data-cms-edit]') ?? null;
|
|
92
|
+
if (!marker) return;
|
|
93
|
+
// Links and buttons inside blocks do not navigate while editing.
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
if (marker.getAttribute('data-cms-edit') === 'body') { this.openPanel('body'); return; }
|
|
97
|
+
const key = docOf(marker);
|
|
98
|
+
if (!this.editableDoc(key)) { this.announcement = __('Only administrators edit this part of the site.'); return; }
|
|
99
|
+
this.doc = key;
|
|
100
|
+
this.select(marker.getAttribute('data-block-id') ?? '', marker);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
private readonly onKey = (event: KeyboardEvent) => {
|
|
104
|
+
if (event.key !== 'Escape' || event.defaultPrevented) return;
|
|
105
|
+
// A block's form is a dialog: its own cancel closes it (`closeForm`).
|
|
106
|
+
if (this.form) return;
|
|
107
|
+
if (this.embedded) this.embedded = null;
|
|
108
|
+
else if (this.panel) this.panel = null;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
private readonly onLeave = (event: BeforeUnloadEvent) => {
|
|
112
|
+
if (this.changed()) event.preventDefault();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
private readonly onResize = () => this.placeBar();
|
|
116
|
+
|
|
117
|
+
onMount() {
|
|
118
|
+
// The frame alone has no entry: its documents are the whole editor, so the Blocks panel opens at once.
|
|
119
|
+
if (!this.props.draft.collection) this.panel = 'blocks';
|
|
120
|
+
this.style = document.createElement('style');
|
|
121
|
+
this.style.textContent = STYLE;
|
|
122
|
+
document.head.appendChild(this.style);
|
|
123
|
+
document.addEventListener('click', this.onDocumentClick, true);
|
|
124
|
+
document.addEventListener('keydown', this.onKey);
|
|
125
|
+
window.addEventListener('beforeunload', this.onLeave);
|
|
126
|
+
window.addEventListener('resize', this.onResize);
|
|
127
|
+
this.observer = new MutationObserver(() => { this.syncSelection(); this.placeBar(); });
|
|
128
|
+
this.observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['data-block-id'] });
|
|
129
|
+
this.placeBar();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onCleanup() {
|
|
133
|
+
this.observer?.disconnect();
|
|
134
|
+
this.style?.remove();
|
|
135
|
+
document.removeEventListener('click', this.onDocumentClick, true);
|
|
136
|
+
document.removeEventListener('keydown', this.onKey);
|
|
137
|
+
window.removeEventListener('beforeunload', this.onLeave);
|
|
138
|
+
window.removeEventListener('resize', this.onResize);
|
|
139
|
+
for (const marker of document.querySelectorAll('[data-cms-selected]')) marker.removeAttribute('data-cms-selected');
|
|
140
|
+
delete document.documentElement.dataset.cmsDevice;
|
|
141
|
+
document.documentElement.style.removeProperty('--cms-taskbar-start');
|
|
142
|
+
document.documentElement.style.removeProperty('--cms-taskbar-end');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Place the editing controls in the middle of the site taskbar: between its start menu and its
|
|
147
|
+
* user menu, which the bar keeps while editing (`taskbar.ts`). Without a taskbar (narrow
|
|
148
|
+
* screens show none) the controls span the bottom of the page.
|
|
149
|
+
*/
|
|
150
|
+
@Client()
|
|
151
|
+
private placeBar() {
|
|
152
|
+
const bar = document.querySelector('[data-cms-taskbar]');
|
|
153
|
+
const start = bar?.querySelector('[data-taskbar-start]')?.getBoundingClientRect();
|
|
154
|
+
const end = bar?.querySelector('[data-taskbar-end]')?.getBoundingClientRect();
|
|
155
|
+
const shown = !!bar && getComputedStyle(bar).display !== 'none';
|
|
156
|
+
const left = shown && start?.width ? `${Math.round(start.right)}px` : '0px';
|
|
157
|
+
const right = shown && end?.width ? `${Math.max(0, Math.round(window.innerWidth - end.left))}px` : '0px';
|
|
158
|
+
const root = document.documentElement.style;
|
|
159
|
+
if (root.getPropertyValue('--cms-taskbar-start') !== left) root.setProperty('--cms-taskbar-start', left);
|
|
160
|
+
if (root.getPropertyValue('--cms-taskbar-end') !== right) root.setProperty('--cms-taskbar-end', right);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Mark the selected block on the page. The page re-renders blocks after each change, so
|
|
165
|
+
* a mutation observer (set up in onMount) marks it again; `updated` is not a lifecycle the
|
|
166
|
+
* client bundle keeps.
|
|
167
|
+
*/
|
|
168
|
+
@Client()
|
|
169
|
+
private syncSelection() {
|
|
170
|
+
for (const marker of document.querySelectorAll('[data-cms-selected]')) if (marker.getAttribute('data-block-id') !== this.form?.id || (marker.getAttribute('data-cms-doc') ?? 'entry') !== this.form?.doc) marker.removeAttribute('data-cms-selected');
|
|
171
|
+
if (this.form) this.markerFor(this.form.id, this.form.doc)?.setAttribute('data-cms-selected', '');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A block's marker on the page, in its document. */
|
|
175
|
+
@Client()
|
|
176
|
+
private markerFor(id: string, doc = this.doc): Element | null {
|
|
177
|
+
return document.querySelector(`[data-cms-edit="block"][data-cms-doc="${CSS.escape(doc)}"][data-block-id="${CSS.escape(id)}"]`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Select a block added in the panel once the draft holds it and the page shows it: the
|
|
182
|
+
* draft's new values and the page's preview of them arrive after this component rendered.
|
|
183
|
+
*/
|
|
184
|
+
private selectWhenShown(id: string, tries = 40) {
|
|
185
|
+
const doc = this.doc;
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
const marker = this.markerFor(id, doc);
|
|
188
|
+
if ((!findBlock(this.blocksOf(doc), id) || !marker) && tries > 0) { this.selectWhenShown(id, tries - 1); return; }
|
|
189
|
+
if (findBlock(this.blocksOf(doc), id)) { this.doc = doc; this.select(id, marker); }
|
|
190
|
+
}, 50);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// --- Draft ---------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
private get values(): EditorValues { return this.props.draft.values; }
|
|
196
|
+
|
|
197
|
+
/** Unsaved changes anywhere: the entry or a document. */
|
|
198
|
+
@Client()
|
|
199
|
+
private changed(): boolean {
|
|
200
|
+
return this.props.draft.changed || this.props.draft.documents.some(document => document.changed);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Client()
|
|
204
|
+
private documentOf(key: string): SiteDocument | undefined {
|
|
205
|
+
return this.props.draft.documents.find(document => document.key === key);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Whether the user may change a document: the entry always (they opened the editor), an area with `cms:appearance`. Reached from the page's click handler, so client-safe by decorator. */
|
|
209
|
+
@Client()
|
|
210
|
+
private editableDoc(key: string): boolean {
|
|
211
|
+
return key === 'entry' ? true : this.documentOf(key)?.editable === true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** A document's blocks: the entry's blocks field, or an area's. */
|
|
215
|
+
@Client()
|
|
216
|
+
private blocksOf(key: string): DraftBlock[] {
|
|
217
|
+
if (key === 'entry') {
|
|
218
|
+
const field = this.props.draft.blocksField;
|
|
219
|
+
return field ? (this.values[field] as DraftBlock[] | undefined) ?? [] : [];
|
|
220
|
+
}
|
|
221
|
+
return this.documentOf(key)?.blocks ?? [];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private blocks(): DraftBlock[] { return this.blocksOf(this.doc); }
|
|
225
|
+
|
|
226
|
+
/** Every block of a document's tree in order, with its depth, container and position. */
|
|
227
|
+
private placesOf(key: string): BlockPlace<DraftBlock>[] {
|
|
228
|
+
return placeBlocks(this.blocksOf(key));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private places(): BlockPlace<DraftBlock>[] { return this.placesOf(this.doc); }
|
|
232
|
+
|
|
233
|
+
/** The document holding a block; the current one when none does. */
|
|
234
|
+
@Client()
|
|
235
|
+
private docWith(id: string): string {
|
|
236
|
+
if (findBlock(this.blocksOf(this.doc), id)) return this.doc;
|
|
237
|
+
if (findBlock(this.blocksOf('entry'), id)) return 'entry';
|
|
238
|
+
return this.props.draft.documents.find(document => findBlock(document.blocks, id))?.key ?? this.doc;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private option(type: string): BlockOption | undefined {
|
|
242
|
+
return this.props.draft.view.blocks.find(block => block.name === type);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** The block types a document offers: the entry's field may limit them; areas take anything but synced patterns, as Widgets does. */
|
|
246
|
+
private optionsFor(key: string): BlockOption[] {
|
|
247
|
+
return key === 'entry' ? this.props.draft.view.blocks : this.props.draft.view.blocks.filter(block => block.name !== 'core/pattern');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The block types the document allows at the top level; empty for all. */
|
|
251
|
+
private allowedIn(key: string): string[] {
|
|
252
|
+
if (key !== 'entry') return [];
|
|
253
|
+
const field = this.props.draft.view.fields.find(entry => entry.name === this.props.draft.blocksField);
|
|
254
|
+
return field?.blocks ?? [];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private allowed(): string[] { return this.allowedIn(this.doc); }
|
|
258
|
+
|
|
259
|
+
@Client()
|
|
260
|
+
private setBlocksOf(key: string, blocks: DraftBlock[], message = '') {
|
|
261
|
+
if (key === 'entry') {
|
|
262
|
+
const field = this.props.draft.blocksField;
|
|
263
|
+
if (!field) return;
|
|
264
|
+
this.props.onChange({ ...this.values, [field]: blocks }, true);
|
|
265
|
+
} else this.props.onDocumentChange(key, blocks);
|
|
266
|
+
if (message) this.announcement = message;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@Client()
|
|
270
|
+
private setBlocks(blocks: DraftBlock[], message = '') {
|
|
271
|
+
this.setBlocksOf(this.doc, blocks, message);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@Client()
|
|
275
|
+
private setValue(name: string, value: unknown, preview = false) {
|
|
276
|
+
this.props.onChange({ ...this.values, [name]: value }, preview);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private label(block: DraftBlock): string {
|
|
280
|
+
return this.option(block.type)?.label ?? block.type;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private summary(block: DraftBlock): string {
|
|
284
|
+
const text = Object.values(block.data).find((value): value is string => typeof value === 'string' && value.trim() !== '' && !this.props.draft.previews[value]);
|
|
285
|
+
return text ? text.replace(/[*_#>`]/g, '').slice(0, 80) : '';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// --- Blocks ----------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
/** Open a block's form in the sheet. */
|
|
291
|
+
@Client()
|
|
292
|
+
private select(id: string, _marker: Element | null = null) {
|
|
293
|
+
this.doc = this.docWith(id);
|
|
294
|
+
const block = findBlock(this.blocks(), id);
|
|
295
|
+
const option = block ? this.option(block.type) : undefined;
|
|
296
|
+
if (!block || !option) return;
|
|
297
|
+
this.form = {
|
|
298
|
+
id, doc: this.doc, errors: {}, tab: this.form?.tab ?? 'general', style: styleValues(block),
|
|
299
|
+
values: Object.fromEntries(option.fields.map(field => [field.name, block.data[field.name] ?? controlValue(field, field.defaultValue)])),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Close the form; from a nested block's form, Escape selects its container instead. */
|
|
304
|
+
@Client()
|
|
305
|
+
private closeForm(toParent = false) {
|
|
306
|
+
const parent = toParent && this.form ? this.places().find(place => place.block._id === this.form!.id)?.parent ?? null : null;
|
|
307
|
+
if (parent) this.edit(parent); else this.form = null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
@Client()
|
|
311
|
+
private setFormValue(name: string, value: unknown) {
|
|
312
|
+
if (this.form) this.form = { ...this.form, values: { ...this.form.values, [name]: value }, errors: { ...this.form.errors, [name]: '' } };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
@Client()
|
|
316
|
+
private setFormStyle(style: StyleValues) {
|
|
317
|
+
if (this.form) this.form = { ...this.form, style };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@Client()
|
|
321
|
+
private showFormTab(tab: BlockTab) {
|
|
322
|
+
if (this.form) this.form = { ...this.form, tab };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@Client()
|
|
326
|
+
private apply(event: Event) {
|
|
327
|
+
event.preventDefault();
|
|
328
|
+
const form = this.form;
|
|
329
|
+
const block = form ? findBlock(this.blocksOf(form.doc), form.id) : undefined;
|
|
330
|
+
const option = block ? this.option(block.type) : undefined;
|
|
331
|
+
if (!form || !block || !option) return;
|
|
332
|
+
const errors = this.check(option, form.values);
|
|
333
|
+
if (Object.keys(errors).length) { this.form = { ...form, errors }; return; }
|
|
334
|
+
// Blocks keep control values, as the dashboard editor does; saving converts them.
|
|
335
|
+
this.setBlocksOf(form.doc, updateBlock(this.blocksOf(form.doc), form.id, entry => withStyle({ ...entry, data: { ...form.values } }, form.style, this.otherIds(form.id))));
|
|
336
|
+
this.form = null;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Field errors of a block form, required fields included. */
|
|
340
|
+
private check(option: BlockOption, values: Record<string, unknown>): Record<string, string> {
|
|
341
|
+
const { input, errors } = editorInput(option.fields, values);
|
|
342
|
+
for (const field of option.fields) if (field.required && (input[field.name] === undefined || input[field.name] === '' || input[field.name] === null)) errors[field.name] ??= __('is required.');
|
|
343
|
+
return errors;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Add a block at the end of a document, or inside a container. */
|
|
347
|
+
@Client()
|
|
348
|
+
private add(type: string, parent: string | null = null, key?: string, variation?: string) {
|
|
349
|
+
this.doc = parent ? this.docWith(parent) : key ?? this.doc;
|
|
350
|
+
const option = this.option(type);
|
|
351
|
+
const block = newBlock(type, this.props.draft.view.blocks, blockId, variation);
|
|
352
|
+
if (!option || !block) return;
|
|
353
|
+
this.setBlocks(insertBlock(this.blocks(), parent, block), `${option.label} ${__('added.')}`);
|
|
354
|
+
this.selectWhenShown(block._id);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Where a block sits after a move, for the announcement. */
|
|
358
|
+
private position(blocks: readonly DraftBlock[], id: string): string {
|
|
359
|
+
const place = placeBlocks(blocks).find(entry => entry.block._id === id);
|
|
360
|
+
if (!place) return '';
|
|
361
|
+
const siblings = place.parent ? findBlock(blocks, place.parent)?.children ?? [] : blocks;
|
|
362
|
+
const container = place.parent ? findBlock(blocks, place.parent) : undefined;
|
|
363
|
+
return `${__('block')} ${place.index + 1} ${__('of')} ${siblings.length}${container ? ` ${__('in')} ${this.label(container)}` : ''}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@Client()
|
|
367
|
+
private shift(id: string, move: BlockMove) {
|
|
368
|
+
this.doc = this.docWith(id);
|
|
369
|
+
const blocks = this.blocks();
|
|
370
|
+
const block = findBlock(blocks, id);
|
|
371
|
+
const next = shiftBlock(blocks, id, move, declarationsOf(this.props.draft.view.blocks));
|
|
372
|
+
if (!block || next === blocks) return;
|
|
373
|
+
this.setBlocks([...next], `${this.label(block)}: ${this.position(next, id)}`);
|
|
374
|
+
requestAnimationFrame(() => this.handles.get(rowKey(this.doc, block._id))?.focus());
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@Client()
|
|
378
|
+
private toggleHide(id: string, breakpoint: Breakpoint) {
|
|
379
|
+
this.doc = this.docWith(id);
|
|
380
|
+
const block = findBlock(this.blocks(), id);
|
|
381
|
+
if (!block) return;
|
|
382
|
+
const hide = block.layout?.hide ?? [];
|
|
383
|
+
const next = hide.includes(breakpoint) ? hide.filter(entry => entry !== breakpoint) : [...BREAKPOINTS].filter(entry => entry === breakpoint || hide.includes(entry));
|
|
384
|
+
this.setBlocks(updateBlock(this.blocks(), id, entry => ({ ...entry, layout: { ...entry.layout, hide: next } })),
|
|
385
|
+
`${this.label(block)}: ${next.length ? `${__('hidden on')} ${next.map(entry => __(BREAKPOINT_DEVICES[entry].label)).join(', ')}` : __('shown everywhere')}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
@Client()
|
|
389
|
+
private remove(id: string) {
|
|
390
|
+
this.doc = this.docWith(id);
|
|
391
|
+
const block = findBlock(this.blocks(), id);
|
|
392
|
+
if (!block) return;
|
|
393
|
+
if (this.form?.id === id && this.form.doc === this.doc) this.form = null;
|
|
394
|
+
this.setBlocks(removeBlock(this.blocks(), id), `${this.label(block)} ${__('removed.')}`);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** Narrow the content root to a device's width; the layout blocks respond to it. */
|
|
398
|
+
@Client()
|
|
399
|
+
private setDevice(device: Device) {
|
|
400
|
+
this.device = device;
|
|
401
|
+
if (device === 'desktop') delete document.documentElement.dataset.cmsDevice;
|
|
402
|
+
else document.documentElement.dataset.cmsDevice = device;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
@Client()
|
|
406
|
+
private edit(id: string) {
|
|
407
|
+
this.doc = this.docWith(id);
|
|
408
|
+
const marker = this.markerFor(id);
|
|
409
|
+
if (marker) marker.firstElementChild?.scrollIntoView({ block: 'center' });
|
|
410
|
+
requestAnimationFrame(() => this.select(id, marker));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// --- Dragging, as the menu editor does: rows with depths; sideways changes the depth ---
|
|
414
|
+
|
|
415
|
+
@Client()
|
|
416
|
+
private startDrag(event: PointerEvent, doc: string, index: number) {
|
|
417
|
+
const list = this.lists.get(doc);
|
|
418
|
+
if (event.button !== 0 || !list) return;
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
421
|
+
this.doc = doc;
|
|
422
|
+
const top = list.getBoundingClientRect().top;
|
|
423
|
+
const places = this.placesOf(doc);
|
|
424
|
+
const rects = places.map(place => this.rows.get(rowKey(doc, place.block._id))?.getBoundingClientRect());
|
|
425
|
+
this.pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, tops: rects.map(rect => (rect?.top ?? 0) - top), bottoms: rects.map(rect => (rect?.bottom ?? 0) - top) };
|
|
426
|
+
this.drag = { doc, from: index, to: index, y: 0, depth: places[index]?.depth ?? 0, moved: false };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
@Client()
|
|
430
|
+
private moveDrag(event: PointerEvent) {
|
|
431
|
+
const pointer = this.pointer;
|
|
432
|
+
const drag = this.drag;
|
|
433
|
+
const list = drag ? this.lists.get(drag.doc) : undefined;
|
|
434
|
+
if (!pointer || !drag || event.pointerId !== pointer.id || !list) return;
|
|
435
|
+
if (!drag.moved && Math.abs(event.clientY - pointer.y) < 4 && Math.abs(event.clientX - pointer.x) < 12) return;
|
|
436
|
+
const y = event.clientY - list.getBoundingClientRect().top;
|
|
437
|
+
const places = this.placesOf(drag.doc);
|
|
438
|
+
// The subtree moves with its root: rows inside it are not drop targets.
|
|
439
|
+
const size = placeBlocks([places[drag.from]!.block]).length;
|
|
440
|
+
const rest = places.map((_, index) => index).filter(index => index < drag.from || index >= drag.from + size);
|
|
441
|
+
let to = 0;
|
|
442
|
+
while (to < rest.length && (pointer.tops[rest[to]!]! + pointer.bottoms[rest[to]!]!) / 2 < y) to++;
|
|
443
|
+
const line = to < rest.length ? pointer.tops[rest[to]!]! : pointer.bottoms[rest.at(-1) ?? 0] ?? 0;
|
|
444
|
+
const depth = Math.min(Math.max((places[drag.from]?.depth ?? 0) + Math.round((event.clientX - pointer.x) / 24), 0), BLOCK_LIMITS.depth - 1);
|
|
445
|
+
if (drag.to !== to || drag.depth !== depth || !drag.moved) this.drag = { ...drag, to, depth, y: line - 2, moved: true };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
@Client()
|
|
449
|
+
private endDrag(event: PointerEvent) {
|
|
450
|
+
const drag = this.drag;
|
|
451
|
+
if (!this.pointer || event.pointerId !== this.pointer.id) return;
|
|
452
|
+
this.pointer = null;
|
|
453
|
+
this.drag = null;
|
|
454
|
+
if (!drag?.moved) return;
|
|
455
|
+
const blocks = this.blocksOf(drag.doc);
|
|
456
|
+
const places = this.placesOf(drag.doc);
|
|
457
|
+
const block = places[drag.from]?.block;
|
|
458
|
+
if (!block) return;
|
|
459
|
+
const next = reorderBlocks(blocks, drag.from, drag.to, drag.depth, declarationsOf(this.props.draft.view.blocks));
|
|
460
|
+
if (placeBlocks(next).every((place, position) => place.block._id === blocks[position]?._id && place.depth === places[position]?.depth)) return;
|
|
461
|
+
this.setBlocksOf(drag.doc, next, `${this.label(block)}: ${this.position(next, block._id)}`);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
@Client()
|
|
465
|
+
private cancelDrag() {
|
|
466
|
+
this.pointer = null;
|
|
467
|
+
this.drag = null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
@Client()
|
|
471
|
+
private handleKey(event: KeyboardEvent, id: string) {
|
|
472
|
+
if (event.key === 'Escape' && this.drag) { this.cancelDrag(); return; }
|
|
473
|
+
const move = ({ ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'out', ArrowRight: 'in' } as const)[event.key as 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight'];
|
|
474
|
+
if (!move) return;
|
|
475
|
+
event.preventDefault();
|
|
476
|
+
this.shift(id, move);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// --- Body ------------------------------------------------------------------------------
|
|
480
|
+
|
|
481
|
+
@Client()
|
|
482
|
+
private openPanel(panel: 'entry' | 'blocks' | 'body') {
|
|
483
|
+
this.form = null;
|
|
484
|
+
this.panel = this.panel === panel ? null : panel;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
@Client()
|
|
488
|
+
private closeBody() {
|
|
489
|
+
this.panel = null;
|
|
490
|
+
this.embedded = null;
|
|
491
|
+
// Render the page from the edited body.
|
|
492
|
+
this.props.onChange(this.values, true);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
@Client()
|
|
496
|
+
private insertEmbedded(type: string) {
|
|
497
|
+
const option = this.option(type);
|
|
498
|
+
const editor = richTextEditors.get(BODY_EDITOR);
|
|
499
|
+
if (!option || !editor) return;
|
|
500
|
+
const values = blockDefaults(option);
|
|
501
|
+
const block: EmbeddedBlock = { _id: blockId(), type, data: editorInput(option.fields, values).input };
|
|
502
|
+
editor.insertBlock(block);
|
|
503
|
+
if (option.fields.length) this.embedded = { id: block._id, type, values, errors: {} };
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
@Client()
|
|
507
|
+
private editEmbedded(block: EmbeddedBlock) {
|
|
508
|
+
const option = this.option(block.type);
|
|
509
|
+
if (!option) return;
|
|
510
|
+
this.embedded = { id: block._id, type: block.type, errors: {}, values: Object.fromEntries(option.fields.map(field => [field.name, controlValue(field, block.data[field.name] ?? field.defaultValue)])) };
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
@Client()
|
|
514
|
+
private setEmbeddedValue(name: string, value: unknown) {
|
|
515
|
+
if (this.embedded) this.embedded = { ...this.embedded, values: { ...this.embedded.values, [name]: value }, errors: { ...this.embedded.errors, [name]: '' } };
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
@Client()
|
|
519
|
+
private applyEmbedded(event: Event) {
|
|
520
|
+
event.preventDefault();
|
|
521
|
+
const form = this.embedded;
|
|
522
|
+
const option = form ? this.option(form.type) : undefined;
|
|
523
|
+
if (!form || !option) return;
|
|
524
|
+
const errors = this.check(option, form.values);
|
|
525
|
+
if (Object.keys(errors).length) { this.embedded = { ...form, errors }; return; }
|
|
526
|
+
richTextEditors.get(BODY_EDITOR)?.updateBlock(form.id, editorInput(option.fields, form.values).input);
|
|
527
|
+
this.embedded = null;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// --- Notes: review threads, through the content API (the site has no room) -------------
|
|
531
|
+
|
|
532
|
+
private openRoots(): Note[] {
|
|
533
|
+
return this.props.draft.notes.filter(note => !note.parentId && note.status === 'open');
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Open threads on a block, counting the passages inside it. */
|
|
537
|
+
private blockNoteCount(id: string): number {
|
|
538
|
+
return this.openRoots().filter(note => { const target = parseNoteTarget(note.target); return !!target && noteBlock(target)?.block === id; }).length;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
private fieldLabel(name: string): string {
|
|
542
|
+
const { view } = this.props.draft;
|
|
543
|
+
return view.fields.find(field => field.name === name)?.label ?? view.taxonomies.find(taxonomy => taxonomy.name === name)?.label ?? name;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** The notes of a rich text document, for its editor, and the toolbar's Note. */
|
|
547
|
+
private notesFor(path: string): Partial<Pick<RichTextFieldProps, 'notes' | 'onNote'>> {
|
|
548
|
+
const marks = this.props.draft.notes.filter(note => !note.parentId && note.status === 'open' && note.target === `text:${path}`).map(note => ({ id: note.id, range: note.range, quote: note.quote }));
|
|
549
|
+
return {
|
|
550
|
+
notes: { marks, active: this.activeNote, onClick: (id: string) => this.selectNote(id), onMoved: (placed: readonly NoteMark[]) => this.onNotesPlaced(path, placed) },
|
|
551
|
+
onNote: (range: NoteRange | null, quote: string) => {
|
|
552
|
+
const parsed = parseRichTextPath(path);
|
|
553
|
+
const whole = parsed?.block ? formatNoteTarget({ kind: 'block', field: parsed.field, block: parsed.block.id }) : formatNoteTarget({ kind: 'field', field: parsed?.field ?? path });
|
|
554
|
+
this.startNote(range ? `text:${path}` : whole, range, quote);
|
|
555
|
+
},
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
@Client()
|
|
560
|
+
private onNotesPlaced(path: string, placed: readonly NoteMark[]) {
|
|
561
|
+
const found = new Set(placed.map(mark => mark.id));
|
|
562
|
+
const here = (id: string) => this.props.draft.notes.find(note => note.id === id)?.target === `text:${path}`;
|
|
563
|
+
const detached = this.props.draft.notes.filter(note => !note.parentId && note.status === 'open' && here(note.id) && !found.has(note.id)).map(note => note.id);
|
|
564
|
+
const next = [...this.detachedNotes.filter(id => !here(id)), ...detached].sort();
|
|
565
|
+
if (next.join() !== [...this.detachedNotes].sort().join()) this.detachedNotes = next;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
private noteAnchor(root: Note): NoteAnchorView {
|
|
569
|
+
const target = parseNoteTarget(root.target);
|
|
570
|
+
if (!target || target.kind === 'entry') return { label: __('This entry'), quote: '', detached: false };
|
|
571
|
+
if (target.kind === 'field') return { label: this.fieldLabel(target.field), quote: '', detached: false };
|
|
572
|
+
const at = noteBlock(target);
|
|
573
|
+
if (!at) return { label: this.fieldLabel(target.kind === 'text' ? target.path : ''), quote: root.quote, detached: this.detachedNotes.includes(root.id) };
|
|
574
|
+
const block = findBlock(this.blocks(), at.block);
|
|
575
|
+
const option = block ? this.option(block.type) : undefined;
|
|
576
|
+
const label = block ? option?.label ?? block.type : __('A removed block');
|
|
577
|
+
const summary = block ? blockSummary(block, this.props.draft.previews, option) : '';
|
|
578
|
+
if (target.kind === 'block') return { label: summary ? `${label}: ${summary}` : label, quote: '', detached: !block };
|
|
579
|
+
return { label, quote: root.quote, detached: !block || this.detachedNotes.includes(root.id) };
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
@Client()
|
|
583
|
+
private startNote(target: string, range: NoteRange | null = null, quote = '') {
|
|
584
|
+
this.composer = { target, range, quote, parentId: null, body: '' };
|
|
585
|
+
this.editingNote = null;
|
|
586
|
+
this.activeNote = null;
|
|
587
|
+
this.notesFilter = 'open';
|
|
588
|
+
this.notesError = '';
|
|
589
|
+
this.notesOpen = true;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
@Client()
|
|
593
|
+
private selectNote(id: string) {
|
|
594
|
+
const root = this.props.draft.notes.find(note => note.id === id);
|
|
595
|
+
this.activeNote = id;
|
|
596
|
+
if (root) this.notesFilter = root.status;
|
|
597
|
+
this.notesOpen = true;
|
|
598
|
+
const target = root ? parseNoteTarget(root.target) : null;
|
|
599
|
+
const block = target ? noteBlock(target) : null;
|
|
600
|
+
if (block) document.querySelector(`[data-cms-edit="block"][data-block-id="${CSS.escape(block.block)}"]`)?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** Open the rail on a block's notes, the first open thread there chosen. */
|
|
604
|
+
@Client()
|
|
605
|
+
private showBlockNotes(id: string) {
|
|
606
|
+
const first = this.openRoots().find(note => { const target = parseNoteTarget(note.target); return !!target && noteBlock(target)?.block === id; });
|
|
607
|
+
this.notesFilter = 'open';
|
|
608
|
+
this.notesOpen = true;
|
|
609
|
+
if (first) this.activeNote = first.id;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
private notesPath(): string {
|
|
613
|
+
return `/api/cms/content/${this.props.draft.collection}/${this.props.draft.id}/notes`;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** A call to the content API as the signed-in editor; the answer's JSON, or its error as a message. */
|
|
617
|
+
private async noteRequest<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
618
|
+
const response = await fetch(path, { method, credentials: 'same-origin', headers: { 'content-type': 'application/json' }, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
|
|
619
|
+
if (response.status === 204) return undefined as T;
|
|
620
|
+
const data = await response.json().catch(() => ({})) as T & { error?: string };
|
|
621
|
+
if (!response.ok) throw new Error(data.error || __('The note could not be saved.'));
|
|
622
|
+
return data;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
@Client()
|
|
626
|
+
private async postNote() {
|
|
627
|
+
const composer = this.composer;
|
|
628
|
+
if (!composer || !composer.body.trim()) return;
|
|
629
|
+
this.notesBusy = true;
|
|
630
|
+
this.notesError = '';
|
|
631
|
+
try {
|
|
632
|
+
const { note } = await this.noteRequest<{ note: Note }>('POST', this.notesPath(), composer.parentId
|
|
633
|
+
? { parentId: composer.parentId, body: composer.body } : { target: composer.target, range: composer.range, quote: composer.quote, body: composer.body });
|
|
634
|
+
this.composer = null;
|
|
635
|
+
this.props.onNotes([...this.props.draft.notes.map(entry => entry.id === note.parentId ? { ...entry, updatedAt: note.createdAt } : entry), note]);
|
|
636
|
+
this.activeNote = note.parentId ?? note.id;
|
|
637
|
+
} catch (error) { this.notesError = (error as Error).message; }
|
|
638
|
+
finally { this.notesBusy = false; }
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** Change a note's text or a thread's status; the answer replaces the note. */
|
|
642
|
+
@Client()
|
|
643
|
+
private async patchNote(id: string, body: { body?: string; status?: NoteStatus }) {
|
|
644
|
+
this.notesBusy = true;
|
|
645
|
+
this.notesError = '';
|
|
646
|
+
try {
|
|
647
|
+
const { note } = await this.noteRequest<{ note: Note }>('PATCH', `/api/cms/notes/${id}`, body);
|
|
648
|
+
this.props.onNotes(this.props.draft.notes.map(entry => entry.id === note.id ? note : entry));
|
|
649
|
+
if (this.editingNote?.id === id) this.editingNote = null;
|
|
650
|
+
} catch (error) { this.notesError = (error as Error).message; }
|
|
651
|
+
finally { this.notesBusy = false; }
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
@Client()
|
|
655
|
+
private async removeNote(id: string) {
|
|
656
|
+
const note = this.props.draft.notes.find(entry => entry.id === id);
|
|
657
|
+
if (!note || !window.confirm(note.parentId ? __('Remove this reply?') : __('Remove this thread and its replies?'))) return;
|
|
658
|
+
this.notesBusy = true;
|
|
659
|
+
this.notesError = '';
|
|
660
|
+
try {
|
|
661
|
+
await this.noteRequest<undefined>('DELETE', `/api/cms/notes/${id}`);
|
|
662
|
+
this.props.onNotes(this.props.draft.notes.filter(entry => entry.id !== id && entry.parentId !== id));
|
|
663
|
+
if (this.activeNote === id) this.activeNote = null;
|
|
664
|
+
} catch (error) { this.notesError = (error as Error).message; }
|
|
665
|
+
finally { this.notesBusy = false; }
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
private notesRailView(): TemplateResult | null {
|
|
669
|
+
const { draft } = this.props;
|
|
670
|
+
return notesRail({
|
|
671
|
+
id: 'site-notes', open: this.notesOpen, threads: noteThreads(draft.notes), filter: this.notesFilter, people: draft.people, me: draft.me, admin: draft.admin,
|
|
672
|
+
active: this.activeNote, composer: this.composer, editing: this.editingNote, mentionable: draft.mentionable, busy: this.notesBusy, error: this.notesError,
|
|
673
|
+
anchor: root => this.noteAnchor(root),
|
|
674
|
+
onClose: () => { this.notesOpen = false; }, onFilter: filter => { this.notesFilter = filter; }, onSelect: id => this.selectNote(id),
|
|
675
|
+
onCompose: composer => { this.composer = composer; }, onSubmit: () => { void this.postNote(); },
|
|
676
|
+
onEdit: editing => { this.editingNote = editing; }, onSaveEdit: () => { if (this.editingNote?.body.trim()) void this.patchNote(this.editingNote.id, { body: this.editingNote.body }); },
|
|
677
|
+
onResolve: id => { void this.patchNote(id, { status: 'resolved' }); }, onReopen: id => { void this.patchNote(id, { status: 'open' }); }, onRemove: id => { void this.removeNote(id); },
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// --- Media -----------------------------------------------------------------------------
|
|
682
|
+
|
|
683
|
+
@Client()
|
|
684
|
+
private openChooser(target: ChooserTarget, multiple: boolean) {
|
|
685
|
+
this.chooserTarget = target;
|
|
686
|
+
this.props.onChooser({ ...this.props.draft.chooser, open: true, error: '', field: 'field' in target ? target.field : '', multiple, kind: this.fileKind(target) });
|
|
687
|
+
this.props.onSearchMedia(this.props.draft.chooser.search);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/** The kind of file a target's field asks for first: its declared kinds, images otherwise. */
|
|
691
|
+
private fileKind(target: ChooserTarget): string {
|
|
692
|
+
if (target.kind === 'richtext') return 'image';
|
|
693
|
+
if (target.kind === 'style') return target.property;
|
|
694
|
+
const type = target.kind === 'entry' ? null : target.kind === 'embedded' ? this.embedded?.type : this.form ? findBlock(this.blocks(), this.form.id)?.type : undefined;
|
|
695
|
+
const fields = target.kind === 'entry' ? this.props.draft.view.fields : type ? this.option(type)?.fields ?? [] : [];
|
|
696
|
+
return chooserKind(fields.find(field => field.name === target.field));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
@Client()
|
|
700
|
+
private filterMedia(kind: string) {
|
|
701
|
+
this.props.onChooser({ ...this.props.draft.chooser, kind });
|
|
702
|
+
this.props.onSearchMedia(this.props.draft.chooser.search);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
private media(target: ChooserTarget): MediaHooks {
|
|
706
|
+
return { previews: this.props.draft.previews, choose: multiple => this.openChooser(target, multiple) };
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
@Client()
|
|
710
|
+
private choose(file: MediaPreview) {
|
|
711
|
+
const target = this.chooserTarget;
|
|
712
|
+
const chooser = this.props.draft.chooser;
|
|
713
|
+
if (!target) return;
|
|
714
|
+
this.props.onPreviews({ ...this.props.draft.previews, [file.id]: file });
|
|
715
|
+
if (target.kind === 'richtext') richTextEditors.get(target.editor ?? BODY_EDITOR)?.insertImage({ src: file.url, alt: file.alt || file.title, mediaId: file.id });
|
|
716
|
+
else if (target.kind === 'block' && this.form) this.setFormValue(target.field, withFile(this.form.values[target.field], file.id, chooser.multiple));
|
|
717
|
+
else if (target.kind === 'style' && this.form) this.setFormStyle({ ...this.form.style, style: { ...this.form.style.style, [target.property]: file.id } });
|
|
718
|
+
else if (target.kind === 'embedded' && this.embedded) this.setEmbeddedValue(target.field, withFile(this.embedded.values[target.field], file.id, chooser.multiple));
|
|
719
|
+
else if (target.kind === 'entry') this.setValue(target.field, withFile(this.values[target.field], file.id, chooser.multiple));
|
|
720
|
+
if (!chooser.multiple) this.props.onChooser({ ...chooser, open: false });
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
@Client()
|
|
724
|
+
private async upload(event: Event) {
|
|
725
|
+
const { files, error } = await uploadMedia(event.currentTarget as HTMLInputElement);
|
|
726
|
+
this.props.onChooser({ ...this.props.draft.chooser, error });
|
|
727
|
+
for (const file of files) this.choose(file);
|
|
728
|
+
this.props.onSearchMedia('');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// --- Rendering -------------------------------------------------------------------------
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* The block's form in a sheet at the side, as the dashboard's block panel: a header with the
|
|
735
|
+
* block's name, its move buttons and a close button, the settings scrolling between, and
|
|
736
|
+
* Remove at the left, Cancel and Apply at the right of the fixed bottom. Escape in a nested block's form selects its container.
|
|
737
|
+
*/
|
|
738
|
+
private formSheet(): TemplateResult {
|
|
739
|
+
const form = this.form;
|
|
740
|
+
const block = form ? findBlock(this.blocks(), form.id) : undefined;
|
|
741
|
+
const option = block ? this.option(block.type) : undefined;
|
|
742
|
+
const open = !!form && !!block && !!option;
|
|
743
|
+
return component(Sheet, { id: 'site-editor-block', open, side: 'right', size: '30rem', 'aria-label': option ? `${__('Edit')} ${option.label}` : __('Block'),
|
|
744
|
+
onOpenChange: (next: boolean) => { if (!next) this.closeForm(true); } },
|
|
745
|
+
open ? this.formBody(form, block, option) : html``);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
private formBody(form: BlockForm, block: DraftBlock, option: BlockOption): TemplateResult {
|
|
749
|
+
const place = this.places().find(entry => entry.block._id === block._id)!;
|
|
750
|
+
const siblings = place.parent ? findBlock(this.blocks(), place.parent)?.children ?? [] : this.blocks();
|
|
751
|
+
const hide = block.layout?.hide ?? [];
|
|
752
|
+
return html`<form data-site-editor-form class="flex h-full flex-col" @submit=${(event: Event) => this.apply(event)}>
|
|
753
|
+
<header class="flex items-center justify-between gap-2 border-b border-border px-5 py-4">
|
|
754
|
+
<div role="heading" aria-level="2" class="min-w-0 truncate text-base font-semibold text-foreground">${option.label}</div>
|
|
755
|
+
<span class="flex flex-wrap gap-1">
|
|
756
|
+
${this.iconButton('↑', __('Move up'), () => this.shift(block._id, 'up'), place.index === 0)}
|
|
757
|
+
${this.iconButton('↓', __('Move down'), () => this.shift(block._id, 'down'), place.index === siblings.length - 1)}
|
|
758
|
+
${this.iconButton('←', __('Move out of the container'), () => this.shift(block._id, 'out'), !place.parent)}
|
|
759
|
+
${this.iconButton('→', __('Move into the block above'), () => this.shift(block._id, 'in'), !this.canGoIn(block._id))}
|
|
760
|
+
</span>
|
|
761
|
+
<button type="button" class="inline-flex size-8 shrink-0 items-center justify-center rounded-md border-none bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground cursor-pointer" aria-label=${__('Close')} @click=${() => this.closeForm(true)}>✕</button>
|
|
762
|
+
</header>
|
|
763
|
+
<div class="min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4">
|
|
764
|
+
<div class="flex flex-wrap items-center gap-1 text-xs text-muted-foreground" role="group" aria-label=${__('Hide on')}>
|
|
765
|
+
<span>${__('Hide on')}</span>
|
|
766
|
+
${BREAKPOINTS.map(breakpoint => {
|
|
767
|
+
const hidden = hide.includes(breakpoint);
|
|
768
|
+
const device = __(BREAKPOINT_DEVICES[breakpoint].label);
|
|
769
|
+
return html`<button type="button" aria-pressed=${hidden ? 'true' : 'false'} data-hide-toggle=${breakpoint} aria-label=${`${__('Hide on')} ${device}`} title=${hidden ? `${__('Hidden on')} ${device}` : `${__('Hide on')} ${device}`}
|
|
770
|
+
class=${`inline-flex h-7 w-7 items-center justify-center rounded border cursor-pointer [&_svg]:size-4 ${hidden ? 'border-destructive/40 bg-destructive/10 text-destructive' : 'border-border bg-background hover:bg-muted'}`}
|
|
771
|
+
@click=${() => this.toggleHide(block._id, breakpoint)}>${component(Icon, { entry: icon(BREAKPOINT_DEVICES[breakpoint].icon), size: 16 })}</button>`;
|
|
772
|
+
})}
|
|
773
|
+
</div>
|
|
774
|
+
${blockTabs(form.tab, tab => this.showFormTab(tab), `site-block-${block._id}`, {
|
|
775
|
+
style: styleControls(form.style, option.supports, this.props.draft.view.presets, `site-block-${block._id}-style`, style => this.setFormStyle(style),
|
|
776
|
+
{ taken: this.otherIds(block._id), media: { previews: this.props.draft.previews, choose: property => this.openChooser({ kind: 'style', property }, false) } }),
|
|
777
|
+
general: option.fields.length ? html`
|
|
778
|
+
${option.fields.filter(field => field.kind === 'richtext').map(field => html`<div class="space-y-1"><label class="block text-sm font-medium text-foreground" for=${`site-block-${block._id}-${field.name}`}>${field.label}</label>
|
|
779
|
+
${component(RichTextField, { id: `site-block-${block._id}-${field.name}`, label: field.label, value: (form.values[field.name] as RichTextDoc | null) ?? null, blocks: [],
|
|
780
|
+
onChange: (doc: RichTextDoc) => this.setFormValue(field.name, doc), onMedia: () => this.openChooser({ kind: 'richtext', editor: `site-block-${block._id}-${field.name}` }, false),
|
|
781
|
+
onInsertBlock: () => undefined, onEditBlock: () => undefined,
|
|
782
|
+
...(this.props.draft.blocksField ? this.notesFor(richTextPath(this.props.draft.blocksField, { id: block._id, key: field.name })) : {}) })}</div>`)}
|
|
783
|
+
${blockFields({ ...option, fields: option.fields.filter(field => field.kind !== 'richtext') }, form.values, (name, value) => this.setFormValue(name, value), `site-block-${block._id}`, name => this.media({ kind: 'block', field: name }), form.errors, [], this.props.draft.view.sources)}`
|
|
784
|
+
: html`<p class="text-sm text-muted-foreground">${__('This block has no settings.')}</p>`,
|
|
785
|
+
})}
|
|
786
|
+
</div>
|
|
787
|
+
<footer class="flex items-center justify-between gap-2 border-t border-border px-5 py-3">
|
|
788
|
+
<button type="button" aria-label=${`${__('Remove')} ${option.label}`} title=${`${__('Remove')} ${option.label}`}
|
|
789
|
+
class="inline-flex h-8 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-sm text-muted-foreground cursor-pointer hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive"
|
|
790
|
+
@click=${() => this.remove(block._id)}>${trash()}${__('Remove')}</button>
|
|
791
|
+
<span class="flex items-center gap-2">
|
|
792
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => this.closeForm() }, __('Cancel'))}
|
|
793
|
+
${component(Button, { type: 'submit', size: 'sm' }, __('Apply'))}
|
|
794
|
+
</span>
|
|
795
|
+
</footer>
|
|
796
|
+
</form>`;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/** The IDs of every other block in the block's document, which a custom block ID may not repeat. */
|
|
800
|
+
private otherIds(id: string): ReadonlySet<string> {
|
|
801
|
+
return new Set(this.placesOf(this.docWith(id)).map(place => place.block._id).filter(entry => entry !== id));
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** Whether the block can move into the sibling above it. */
|
|
805
|
+
private canGoIn(id: string): boolean {
|
|
806
|
+
const blocks = this.blocksOf(this.docWith(id));
|
|
807
|
+
return shiftBlock(blocks, id, 'in', declarationsOf(this.props.draft.view.blocks)) !== blocks;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
private iconButton(label: string | TemplateResult, title: string, run: () => void, disabled = false): TemplateResult {
|
|
811
|
+
return html`<button type="button" title=${title} aria-label=${title} ?disabled=${disabled}
|
|
812
|
+
class="rounded border border-border bg-background px-2 py-0.5 text-xs text-muted-foreground hover:bg-muted hover:text-foreground cursor-pointer disabled:cursor-default disabled:opacity-40" @click=${run}>${label}</button>`;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** The page's documents in page order: the header, the entry's content, the patterns the page shows, then the other areas. */
|
|
816
|
+
private documents(): { key: string; label: string; editable: boolean; document: SiteDocument | null }[] {
|
|
817
|
+
const all = this.props.draft.documents;
|
|
818
|
+
const of = (document: SiteDocument) => ({ key: document.key, label: document.label, editable: document.editable, document });
|
|
819
|
+
const entry = this.props.draft.blocksField ? [{ key: 'entry', label: __('Content'), editable: true, document: null }] : [];
|
|
820
|
+
return [...all.filter(document => document.kind === 'area' && document.name === 'header').map(of), ...entry, ...all.filter(document => document.kind === 'pattern').map(of), ...all.filter(document => document.kind === 'area' && document.name !== 'header').map(of)];
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
private blocksPanel(): TemplateResult {
|
|
824
|
+
const documents = this.documents();
|
|
825
|
+
return html`<div class="space-y-5">
|
|
826
|
+
<p id="site-blocks-help" class="text-xs text-muted-foreground">${__('Drag a block by its handle, sideways to change its container, or focus the handle and use the arrow keys: up and down among its siblings, right into the block above, left out of its container. Click a block on the page to edit it.')}</p>
|
|
827
|
+
${documents.map(entry => this.documentSection(entry, documents.length > 1))}
|
|
828
|
+
</div>`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/** One document's tree, its inserter and, for an area, its save state. */
|
|
832
|
+
private documentSection({ key, label, editable, document: doc }: { key: string; label: string; editable: boolean; document: SiteDocument | null }, titled: boolean): TemplateResult {
|
|
833
|
+
const places = this.placesOf(key);
|
|
834
|
+
const drag = this.drag?.doc === key ? this.drag : null;
|
|
835
|
+
const options = this.optionsFor(key);
|
|
836
|
+
return html`<section class="space-y-3" data-site-doc=${key} aria-label=${label}>
|
|
837
|
+
${titled ? html`<div role="heading" aria-level="3" class="flex flex-wrap items-center gap-x-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">${label}
|
|
838
|
+
${doc?.kind === 'pattern' ? html`<span class="font-normal normal-case tracking-normal">· ${__('Pattern: changes apply everywhere it is used')}</span>` : null}
|
|
839
|
+
${editable ? null : html`<span class="font-normal normal-case tracking-normal" data-locked>· ${doc?.kind === 'pattern' ? __('You cannot change this pattern') : __('Administrators edit this')}</span>`}
|
|
840
|
+
${doc?.changed ? html`<span class="font-normal normal-case tracking-normal">· ${__('Unsaved changes')}</span>` : null}</div>` : null}
|
|
841
|
+
${doc?.error ? html`<p role="alert" class="flex flex-wrap items-center gap-2 text-xs text-destructive">${doc.error}
|
|
842
|
+
${doc.conflict ? component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.props.onReload() }, __('Reload')) : null}</p>` : null}
|
|
843
|
+
${places.length ? html`<ol class="relative space-y-1.5" aria-label=${label} ref=${(element: Element) => { if (element) this.lists.set(key, element as HTMLElement); else this.lists.delete(key); }}>
|
|
844
|
+
${drag?.moved ? html`<li aria-hidden="true" class="pointer-events-none absolute right-0 h-0.5 rounded bg-primary" style=${`top: ${drag.y}px; left: ${drag.depth * 1.25}rem`}></li>` : null}
|
|
845
|
+
${places.map((place, index) => this.blockRow(key, place, index, places, drag, editable, options))}
|
|
846
|
+
</ol>` : html`<p class="rounded-md border border-dashed border-border p-4 text-center text-sm text-muted-foreground">${__('No blocks yet.')}</p>`}
|
|
847
|
+
${editable ? component(BlockInserter, { id: `site-editor-blocks-${key.replace(':', '-')}`, blocks: offeredIn(options, null, this.allowedIn(key)), onPick: (type: string, variation?: string) => this.add(type, null, key, variation) }) : null}
|
|
848
|
+
</section>`;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
private blockRow(key: string, place: BlockPlace<DraftBlock>, index: number, places: readonly BlockPlace<DraftBlock>[], drag: Drag | null, editable: boolean, options: readonly BlockOption[]): TemplateResult {
|
|
852
|
+
const block = place.block;
|
|
853
|
+
const option = this.option(block.type);
|
|
854
|
+
const hide = block.layout?.hide ?? [];
|
|
855
|
+
const offered = option?.children ? offeredIn(options, option) : [];
|
|
856
|
+
const entry = key === 'entry';
|
|
857
|
+
const dragged = drag?.moved && index >= drag.from && index < drag.from + placeBlocks([places[drag.from]!.block]).length;
|
|
858
|
+
return html`<li class=${`transition-opacity ${dragged ? 'opacity-40' : ''}`} data-site-block=${block._id} data-depth=${place.depth}
|
|
859
|
+
style=${`padding-left: ${place.depth * 1.25}rem`} ref=${(element: Element) => { if (element) this.rows.set(rowKey(key, block._id), element as HTMLElement); else this.rows.delete(rowKey(key, block._id)); }}>
|
|
860
|
+
<div class="flex items-center gap-2 rounded-md border border-border bg-card px-2 py-1.5">
|
|
861
|
+
<button type="button" class="flex h-8 w-6 shrink-0 cursor-grab touch-none items-center justify-center rounded border-none bg-transparent text-muted-foreground hover:bg-muted active:cursor-grabbing disabled:cursor-default disabled:opacity-40"
|
|
862
|
+
aria-label=${`${__('Move')} ${this.label(block)}. ${__('Drag, or use the arrow keys.')}`} aria-describedby="site-blocks-help" data-handle ?disabled=${!editable}
|
|
863
|
+
ref=${(element: Element) => { if (element) this.handles.set(rowKey(key, block._id), element as HTMLElement); else this.handles.delete(rowKey(key, block._id)); }}
|
|
864
|
+
@pointerdown=${(event: PointerEvent) => this.startDrag(event, key, index)} @pointermove=${(event: PointerEvent) => this.moveDrag(event)}
|
|
865
|
+
@pointerup=${(event: PointerEvent) => this.endDrag(event)} @pointercancel=${() => this.cancelDrag()} @lostpointercapture=${() => this.cancelDrag()}
|
|
866
|
+
@keydown=${(event: KeyboardEvent) => this.handleKey(event, block._id)}>
|
|
867
|
+
<svg aria-hidden="true" viewBox="0 0 10 16" class="h-4 w-2.5 fill-current"><circle cx="2" cy="2" r="1.5"/><circle cx="8" cy="2" r="1.5"/><circle cx="2" cy="8" r="1.5"/><circle cx="8" cy="8" r="1.5"/><circle cx="2" cy="14" r="1.5"/><circle cx="8" cy="14" r="1.5"/></svg>
|
|
868
|
+
</button>
|
|
869
|
+
<span class="min-w-0 flex-1">
|
|
870
|
+
<span class="block text-xs font-semibold uppercase tracking-wide text-muted-foreground">${this.label(block)}${hide.length ? html` <span class="normal-case tracking-normal" data-hidden-on=${hide.join(' ')}>· ${__('hidden on')} ${hide.map(entry => __(BREAKPOINT_DEVICES[entry].label)).join(', ')}</span>` : null}</span>
|
|
871
|
+
<span class="block truncate text-sm">${this.summary(block)}</span>
|
|
872
|
+
</span>
|
|
873
|
+
${editable && offered.length && (option?.children?.max === null || (block.children ?? []).length < (option?.children?.max ?? 0))
|
|
874
|
+
? component(BlockInserter, { id: `site-editor-add-${key.replace(':', '-')}-${block._id}`, blocks: offered, compact: true, onPick: (type: string, variation?: string) => this.add(type, block._id, undefined, variation) }) : null}
|
|
875
|
+
${entry ? noteMarker(this.blockNoteCount(block._id), this.label(block), () => this.showBlockNotes(block._id)) : null}
|
|
876
|
+
${entry && this.props.draft.blocksField ? noteButton(`site-note-${block._id}`, this.label(block), () => this.startNote(formatNoteTarget({ kind: 'block', field: this.props.draft.blocksField!, block: block._id })), { always: true }) : null}
|
|
877
|
+
${editable && option?.fields.length ? this.iconButton(__('Edit'), `${__('Edit')} ${this.label(block)}`, () => this.edit(block._id)) : null}
|
|
878
|
+
${editable ? this.iconButton(trash(), `${__('Remove')} ${this.label(block)}`, () => this.remove(block._id)) : null}
|
|
879
|
+
</div>
|
|
880
|
+
</li>`;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
private entryPanel(): TemplateResult {
|
|
884
|
+
const { view, references, errors } = this.props.draft;
|
|
885
|
+
const skip = new Set([this.props.draft.blocksField, this.props.draft.bodyField]);
|
|
886
|
+
const fields = view.fields.filter(field => !skip.has(field.name) && field.kind !== 'richtext' && field.kind !== 'blocks' && !field.fields.length);
|
|
887
|
+
const row = (id: string, label: string, control: TemplateResult | null, name: string, bare = false) => html`<div class="space-y-1">
|
|
888
|
+
${bare ? null : html`<label for=${id} class="block text-sm font-medium">${label}</label>`}${control}
|
|
889
|
+
${errors[name] ? html`<p role="alert" class="text-xs text-destructive">${errors[name]}</p>` : null}</div>`;
|
|
890
|
+
return html`<div class="space-y-4">
|
|
891
|
+
${view.titleField ? row('site-entry-title', __('Title'), html`<input id="site-entry-title" class=${CONTROL} .value=${String(this.values[view.titleField] ?? '')}
|
|
892
|
+
@input=${(event: Event) => this.setValue(view.titleField, (event.target as HTMLInputElement).value)}>`, view.titleField) : null}
|
|
893
|
+
${view.slug ? row('site-entry-slug', __('Slug'), html`<input id="site-entry-slug" class=${CONTROL} .value=${String(this.values.slug ?? '')}
|
|
894
|
+
@input=${(event: Event) => this.setValue('slug', (event.target as HTMLInputElement).value)}>`, 'slug') : null}
|
|
895
|
+
${view.taxonomies.map(taxonomy => {
|
|
896
|
+
const value = this.values[taxonomy.name];
|
|
897
|
+
if (taxonomy.hierarchical) {
|
|
898
|
+
const chosen = Array.isArray(value) ? value as string[] : [];
|
|
899
|
+
return html`<fieldset class="space-y-1.5"><legend class="text-sm font-medium">${taxonomy.label}</legend>
|
|
900
|
+
${taxonomy.terms.map(term => html`<div style=${`padding-left: ${term.depth}rem`}>
|
|
901
|
+
${component(Checkbox, { label: term.name, checked: chosen.includes(term.id), '@change': (event: Event) => this.setValue(taxonomy.name,
|
|
902
|
+
(event.target as HTMLInputElement).checked ? [...chosen, term.id] : chosen.filter(id => id !== term.id)) })}</div>`)}</fieldset>`;
|
|
903
|
+
}
|
|
904
|
+
return row(`site-entry-${taxonomy.name}`, taxonomy.label, component(MultiSelect, {
|
|
905
|
+
id: `site-entry-${taxonomy.name}`, value: Array.isArray(value) ? value as string[] : [],
|
|
906
|
+
options: [...new Set(taxonomy.terms.map(term => term.name))], allowCreate: true,
|
|
907
|
+
placeholder: __('Search or add…'), emptyLabel: __('No matching terms.'),
|
|
908
|
+
createLabel: (name: string) => `${__('Create')} "${name}"`, removeLabel: (name: string) => `${__('Remove')} ${name}`,
|
|
909
|
+
onValueChange: (names: string[]) => this.setValue(taxonomy.name, names),
|
|
910
|
+
}), taxonomy.name);
|
|
911
|
+
})}
|
|
912
|
+
${fields.map(field => row(`site-entry-${field.name}`, field.label, fieldControl(field, this.values[field.name], value => this.setValue(field.name, value), `site-entry-${field.name}`,
|
|
913
|
+
{ media: this.media({ kind: 'entry', field: field.name }), options: references[field.name] ?? [], sources: this.props.draft.view.sources }), field.name, field.kind === 'boolean'))}
|
|
914
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => this.props.onChange(this.values, true) }, __('Show changes'))}
|
|
915
|
+
</div>`;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
private bodyPanel(): TemplateResult | null {
|
|
919
|
+
const field = this.props.draft.view.fields.find(entry => entry.name === this.props.draft.bodyField);
|
|
920
|
+
if (!field) return null;
|
|
921
|
+
const blocks = this.props.draft.view.blocks.filter(block => block.name !== 'core/pattern' && !block.input && (!field.blocks.length || field.blocks.includes(block.name)));
|
|
922
|
+
const form = this.embedded;
|
|
923
|
+
const option = form ? this.option(form.type) : undefined;
|
|
924
|
+
return html`<div class="space-y-3">
|
|
925
|
+
${component(RichTextField, {
|
|
926
|
+
id: BODY_EDITOR, label: field.label, value: (this.values[field.name] as RichTextDoc | null) ?? null, blocks,
|
|
927
|
+
onChange: (doc: RichTextDoc) => this.setValue(field.name, doc),
|
|
928
|
+
onMedia: () => this.openChooser({ kind: 'richtext' }, false),
|
|
929
|
+
onInsertBlock: (type: string) => this.insertEmbedded(type),
|
|
930
|
+
onEditBlock: (block: EmbeddedBlock) => this.editEmbedded(block),
|
|
931
|
+
...this.notesFor(richTextPath(field.name)),
|
|
932
|
+
})}
|
|
933
|
+
${form && option ? html`<form class="space-y-3 rounded-md border border-border bg-card p-3" @submit=${(event: Event) => this.applyEmbedded(event)}>
|
|
934
|
+
<div role="heading" aria-level="3" class="text-sm font-semibold">${option.label}</div>
|
|
935
|
+
${blockFields(option, form.values, (name, value) => this.setEmbeddedValue(name, value), `site-embedded-${form.id}`, name => this.media({ kind: 'embedded', field: name }), form.errors, [], this.props.draft.view.sources)}
|
|
936
|
+
<div class="flex justify-end gap-2">
|
|
937
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => { this.embedded = null; } }, __('Cancel'))}
|
|
938
|
+
${component(Button, { type: 'submit', size: 'sm' }, __('Apply'))}
|
|
939
|
+
</div>
|
|
940
|
+
</form>` : null}
|
|
941
|
+
</div>`;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
private sidePanel(): TemplateResult | null {
|
|
945
|
+
if (!this.panel) return null;
|
|
946
|
+
const titles = { entry: __('Entry'), blocks: __('Blocks'), body: __('Text') };
|
|
947
|
+
const body = this.panel === 'entry' ? this.entryPanel() : this.panel === 'blocks' ? this.blocksPanel() : this.bodyPanel();
|
|
948
|
+
// The open Notes rail takes the right edge: the panel sits beside it.
|
|
949
|
+
return html`<aside role="dialog" aria-label=${titles[this.panel]} class=${`${PANEL} bottom-12 right-4 top-4 w-[min(30rem,calc(100vw-2rem))] rounded-lg`} style=${this.notesOpen ? 'right: 27rem' : ''}>
|
|
950
|
+
<header class="flex items-center justify-between gap-2 border-b border-border px-4 py-3">
|
|
951
|
+
<div role="heading" aria-level="2" class="text-base font-semibold">${titles[this.panel]}</div>
|
|
952
|
+
${this.panel === 'body' ? component(Button, { type: 'button', size: 'sm', '@click': () => this.closeBody() }, __('Done'))
|
|
953
|
+
: component(Button, { type: 'button', variant: 'ghost', size: 'sm', '@click': () => { this.panel = null; } }, __('Close'))}
|
|
954
|
+
</header>
|
|
955
|
+
<div class="flex-1 overflow-y-auto p-4">${body}</div>
|
|
956
|
+
</aside>`;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
private bar(): TemplateResult {
|
|
960
|
+
const { draft, saving } = this.props;
|
|
961
|
+
const tab = (panel: 'entry' | 'blocks' | 'body', label: string) => html`<button type="button" aria-pressed=${this.panel === panel ? 'true' : 'false'}
|
|
962
|
+
class=${`rounded-full px-3 py-1.5 text-sm border-none cursor-pointer ${this.panel === panel ? 'bg-muted text-foreground' : 'bg-transparent text-muted-foreground hover:text-foreground'}`}
|
|
963
|
+
@click=${() => this.openPanel(panel)}>${label}</button>`;
|
|
964
|
+
const changed = this.changed();
|
|
965
|
+
const areaConflict = draft.documents.some(document => document.conflict);
|
|
966
|
+
const status = saving ? __('Saving…') : draft.conflict ? '' : draft.error ? draft.error : changed ? __('Unsaved changes') : __('No unsaved changes');
|
|
967
|
+
const device = (name: Device) => html`<button type="button" aria-pressed=${this.device === name ? 'true' : 'false'} data-device=${name} title=${__(DEVICE_LABELS[name])}
|
|
968
|
+
class=${`rounded-full px-2 py-1 text-xs border-none cursor-pointer ${this.device === name ? 'bg-muted text-foreground' : 'bg-transparent text-muted-foreground hover:text-foreground'}`}
|
|
969
|
+
@click=${() => this.setDevice(name)}>${__(DEVICE_LABELS[name])}</button>`;
|
|
970
|
+
// In the taskbar's middle, between its start menu and its user menu (`placeBar`); the whole bottom edge without a taskbar.
|
|
971
|
+
return html`<div role="region" aria-label=${__('Editing')} data-site-editor-bar class="fixed bottom-0 z-50 flex h-10 items-center gap-1 overflow-x-auto border-t border-border bg-background/95 px-2 text-foreground backdrop-blur md:border-t-0 md:bg-transparent md:backdrop-blur-none"
|
|
972
|
+
style="left: var(--cms-taskbar-start, 0px); right: var(--cms-taskbar-end, 0px)">
|
|
973
|
+
${draft.collection ? tab('entry', __('Entry')) : null}
|
|
974
|
+
${draft.blocksField || draft.documents.length ? tab('blocks', __('Blocks')) : null}
|
|
975
|
+
${draft.bodyField ? tab('body', __('Text')) : null}
|
|
976
|
+
${draft.collection ? html`<button type="button" aria-pressed=${this.notesOpen ? 'true' : 'false'} data-notes-toggle=${this.openRoots().length}
|
|
977
|
+
class=${`rounded-full px-3 py-1.5 text-sm border-none cursor-pointer ${this.notesOpen ? 'bg-muted text-foreground' : 'bg-transparent text-muted-foreground hover:text-foreground'}`}
|
|
978
|
+
@click=${() => { this.notesOpen = !this.notesOpen; }}>${__('Notes')}${this.openRoots().length ? html` <span class="rounded-full bg-amber-500/15 px-1.5 text-xs font-medium text-amber-700 dark:text-amber-300">${this.openRoots().length}</span>` : null}</button>` : null}
|
|
979
|
+
<span class="flex items-center gap-0.5 border-l border-border pl-1" role="group" aria-label=${__('Preview width')}>${device('desktop')}${device('tablet')}${device('phone')}</span>
|
|
980
|
+
<span role="status" class=${`px-2 text-xs ${draft.error && !draft.conflict ? 'text-destructive' : 'text-muted-foreground'}`}>${status}</span>
|
|
981
|
+
${draft.conflict ? html`<span role="alert" class="flex items-center gap-2 px-2 text-xs text-destructive">${__('Someone saved this entry since you started.')}
|
|
982
|
+
${component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.props.onReload() }, __('Reload'))}</span>` : null}
|
|
983
|
+
${!draft.conflict && areaConflict ? html`<span role="alert" class="px-2 text-xs text-destructive">${__('An area changed since you started: see the Blocks panel.')}</span>` : null}
|
|
984
|
+
${component(Button, { type: 'button', size: 'sm', variant: 'ghost', '@click': () => this.exit() }, __('Exit'))}
|
|
985
|
+
${component(Button, { type: 'button', size: 'sm', disabled: saving || !changed || draft.conflict, '@click': () => this.props.onSave() }, __('Save'))}
|
|
986
|
+
</div>`;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
@Client()
|
|
990
|
+
private exit() {
|
|
991
|
+
if (this.changed() && !window.confirm(__('Leave edit mode? Unsaved changes will be lost.'))) return;
|
|
992
|
+
this.props.onExit();
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
render() {
|
|
996
|
+
return html`<div data-site-editor ref=${(element: Element) => { this.root = element as HTMLElement; }}>
|
|
997
|
+
<p class="sr-only" aria-live="polite">${this.announcement}</p>
|
|
998
|
+
${this.formSheet()}
|
|
999
|
+
${this.sidePanel()}
|
|
1000
|
+
${this.notesRailView()}
|
|
1001
|
+
${this.bar()}
|
|
1002
|
+
${mediaChooser(this.props.draft.chooser, {
|
|
1003
|
+
search: text => this.props.onSearchMedia(text), filter: kind => this.filterMedia(kind), choose: file => this.choose(file), upload: event => this.upload(event),
|
|
1004
|
+
close: () => this.props.onChooser({ ...this.props.draft.chooser, open: false }),
|
|
1005
|
+
})}
|
|
1006
|
+
</div>`;
|
|
1007
|
+
}
|
|
1008
|
+
}
|