@cossackframework/cms 0.0.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +21 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +709 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +114 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The block tree editor shared by the entry editor and Appearance → Widgets: blocks as nested,
|
|
3
|
+
* collapsible sections with their type's icon, dragged by a handle (the tree previews the drop
|
|
4
|
+
* with a ghost of the block in its new place, opening the container it would land in; sideways
|
|
5
|
+
* changes the container; the page scrolls near the window's edges), moved with the arrow keys
|
|
6
|
+
* or buttons, hidden per device, with an inserter at every level offering what fits there.
|
|
7
|
+
* Client-safe. The screen renders each field's control, since it owns media choosing.
|
|
8
|
+
*/
|
|
9
|
+
import { Client, ClientState, Component, Cossack, getTabbable } from '@cossackframework/core';
|
|
10
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
11
|
+
import { AlertDialog, Badge, DropdownMenu, Icon } from '@cossackframework/ui';
|
|
12
|
+
import { blockId, BLOCK_LIMITS, BREAKPOINTS, cloneBlocks, FIELD_GROUP_LAYOUT, insertBlock, placeBlocks, removeBlock, shiftBlock, updateBlock, type BlockDeclaration, type BlockMove, type Breakpoint } from '@cossackframework/cms';
|
|
13
|
+
import { fieldName } from './builder';
|
|
14
|
+
import { BlockInserter } from './block-inserter';
|
|
15
|
+
import { reorderBlocks } from './block-rows';
|
|
16
|
+
import { blockErrorPath, blockErrorTarget, describeBlockError } from './block-errors';
|
|
17
|
+
import { newBlock, type BlockOption, type EditorBlock, type EditorField } from './editor';
|
|
18
|
+
import type { MediaPreview } from './field-controls';
|
|
19
|
+
import { blockIcon, blockIconColor, icon } from './icons';
|
|
20
|
+
import { iconButton } from './ui';
|
|
21
|
+
import { presenceChip, presenceOutline, type Someone } from './collab/presence';
|
|
22
|
+
import { noteMarker } from './notes-rail';
|
|
23
|
+
|
|
24
|
+
export type BlockTreeProps = {
|
|
25
|
+
/** Page-unique prefix for control IDs. */
|
|
26
|
+
id: string;
|
|
27
|
+
blocks: EditorBlock[];
|
|
28
|
+
/** Every block type, for labels and nesting rules. */
|
|
29
|
+
options: BlockOption[];
|
|
30
|
+
/** Types the field allows at the top level; empty for all. */
|
|
31
|
+
allowed: string[];
|
|
32
|
+
/** The field holds a form: input blocks are offered. */
|
|
33
|
+
form?: boolean;
|
|
34
|
+
/** The blocks are a field group: field blocks and layout blocks are offered, and every block opens in the panel. */
|
|
35
|
+
fieldGroup?: boolean;
|
|
36
|
+
onChange(blocks: EditorBlock[]): void;
|
|
37
|
+
/** A field's control; the screen's own, so media choosing lands in the right block. */
|
|
38
|
+
control(field: EditorField, value: unknown, change: (value: unknown) => void, block: EditorBlock, id: string): TemplateResult | null;
|
|
39
|
+
/**
|
|
40
|
+
* Opens a block in the screen's panel from its Edit button; the tree shows a summary. Rich
|
|
41
|
+
* text fields are edited in place. In a form every block has the button, for its condition.
|
|
42
|
+
*/
|
|
43
|
+
onEdit?(id: string): void;
|
|
44
|
+
/** A collection template's lock: `insert` keeps the blocks (no adding or removing), `all` keeps their order too. */
|
|
45
|
+
lock?: 'all' | 'insert';
|
|
46
|
+
/** Offer saved patterns beside the top-level inserter. */
|
|
47
|
+
onPatterns?(): void;
|
|
48
|
+
previews?: Record<string, MediaPreview>;
|
|
49
|
+
/**
|
|
50
|
+
* The field's validation message. The tree opens to the block it names (`block <id>.<field> …`),
|
|
51
|
+
* flashes it, scrolls it into view and shows the message under it with the block's name.
|
|
52
|
+
*/
|
|
53
|
+
error?: string;
|
|
54
|
+
/** Blocks that stay where they are: no dragging, moving or removing, and no move puts another block in their place. An editor layout's Edit tab, say. */
|
|
55
|
+
pinned?: string[];
|
|
56
|
+
/** Containers start open rather than collapsed, for a tree that is read as a whole, such as an editor layout. */
|
|
57
|
+
expanded?: boolean;
|
|
58
|
+
/** Offer the per-device hide toggles. Default true; an editor layout has no devices to hide on. */
|
|
59
|
+
devices?: boolean;
|
|
60
|
+
/** The summary beside a block's name, in place of its first text; undefined falls back to it. */
|
|
61
|
+
summary?(block: EditorBlock, option: BlockOption | undefined): string | undefined;
|
|
62
|
+
/** Who else is in each block, by block ID: the block is outlined in their color and named after its title. */
|
|
63
|
+
editing?: Record<string, readonly Someone[]>;
|
|
64
|
+
/** A drag started (the block's ID) or ended (null), for the others' presence. */
|
|
65
|
+
onDrag?(id: string | null): void;
|
|
66
|
+
/** Open notes on each block, by block ID, shown as a marker in its header that opens them. */
|
|
67
|
+
notes?: Record<string, number>;
|
|
68
|
+
/** Start a note on a block, from its header's button. */
|
|
69
|
+
onNote?(id: string): void;
|
|
70
|
+
/** Show a block's notes, from its marker. */
|
|
71
|
+
onNotes?(id: string): void;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** Devices the hide toggles stand for, with their icons. */
|
|
75
|
+
export const BREAKPOINT_DEVICES: { readonly [key in Breakpoint]: { label: string; icon: string } } = {
|
|
76
|
+
sm: { label: 'phones', icon: 'smartphone' }, md: { label: 'tablets', icon: 'tablet' }, lg: { label: 'desktops', icon: 'monitor' },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Types the inserter offers inside `parent` (null at the top level), by the types' nesting rules. A repeater (an input that holds blocks) goes one level deep. */
|
|
80
|
+
export function offeredIn(options: readonly BlockOption[], parent: BlockOption | null, allowed: readonly string[] = [], form = false, fieldGroup = false): BlockOption[] {
|
|
81
|
+
return options.filter(option => option.name !== 'core/pattern' && (form || !option.input) && !(parent?.input && option.input && option.children) && (fieldGroup ? !!option.field || option.common || FIELD_GROUP_LAYOUT.has(option.name) : !option.field) && (parent
|
|
82
|
+
? !!parent.children && (!parent.children.allowed.length || parent.children.allowed.includes(option.name)) && (!option.parent.length || option.parent.includes(parent.name))
|
|
83
|
+
: !option.parent.length && (!allowed.length || allowed.includes(option.name))));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The options as declarations, for the CMS's tree moves. */
|
|
87
|
+
export function declarationsOf(options: readonly BlockOption[]): Map<string, BlockDeclaration> {
|
|
88
|
+
return new Map(options.map(option => [option.name, {
|
|
89
|
+
name: option.name, label: option.label, fields: {},
|
|
90
|
+
...(option.children ? { children: { ...(option.children.allowed.length ? { allowed: option.children.allowed } : {}), ...(option.children.max !== null ? { max: option.children.max } : {}) } } : {}),
|
|
91
|
+
...(option.parent.length ? { parent: option.parent } : {}),
|
|
92
|
+
}]));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A block's first text, for summaries. */
|
|
96
|
+
export function blockSummary(block: EditorBlock, previews: Record<string, MediaPreview> = {}, option?: BlockOption): string {
|
|
97
|
+
const shown = (value: unknown): value is string => typeof value === 'string' && value.trim() !== '' && !previews[value];
|
|
98
|
+
// The block's body field first, then its fields in their declared order: a patch from the room may reorder the data's keys.
|
|
99
|
+
const names = [...(option?.body ? [option.body] : []), ...(option?.fields.map(field => field.name) ?? []), ...Object.keys(block.data)];
|
|
100
|
+
const text = names.map(name => block.data[name]).find(shown);
|
|
101
|
+
return text ? text.replace(/[*_#>`]/g, '').slice(0, 120) : '';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The border color of a nested list: deeper levels are stronger. */
|
|
105
|
+
export function levelBorder(depth: number): string {
|
|
106
|
+
return `border-color: color-mix(in oklab, var(--primary) ${Math.min(15 + depth * 20, 95)}%, var(--border))`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Field kinds short enough to share a row. */
|
|
110
|
+
const SHORT_KINDS = new Set(['enum', 'integer', 'number', 'boolean', 'datetime']);
|
|
111
|
+
|
|
112
|
+
const GRIP = html`<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>`;
|
|
113
|
+
|
|
114
|
+
/** A drag in progress: the block and the tree as it would be if dropped now. */
|
|
115
|
+
interface Drag { id: string; blocks: EditorBlock[]; depth: number; moved: boolean }
|
|
116
|
+
|
|
117
|
+
/** A tree's arrangement, for telling whether a move changed anything. */
|
|
118
|
+
function treeShape(blocks: readonly EditorBlock[]): string {
|
|
119
|
+
return placeBlocks(blocks).map(place => `${place.block._id}:${place.depth}`).join(' ');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** How near the window's top or bottom edge a drag scrolls, in pixels; the nearer, the faster. */
|
|
123
|
+
const SCROLL_EDGE = 56;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* What a drag may scroll, nearest first: the ancestors that may scroll their content, then the
|
|
127
|
+
* page. An ancestor that only hides sideways overflow computes as scrolling vertically too
|
|
128
|
+
* without ever doing it, so the drag tries each in turn.
|
|
129
|
+
*/
|
|
130
|
+
function scrollersOf(element: HTMLElement): Element[] {
|
|
131
|
+
const scrollers: Element[] = [];
|
|
132
|
+
for (let parent = element.parentElement; parent; parent = parent.parentElement) {
|
|
133
|
+
const overflow = getComputedStyle(parent).overflowY;
|
|
134
|
+
if ((overflow === 'auto' || overflow === 'scroll') && parent.scrollHeight > parent.clientHeight) scrollers.push(parent);
|
|
135
|
+
}
|
|
136
|
+
const page = document.scrollingElement ?? document.documentElement;
|
|
137
|
+
return scrollers.includes(page) ? scrollers : [...scrollers, page];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@Component()
|
|
141
|
+
export class BlockTree extends Cossack {
|
|
142
|
+
declare props: BlockTreeProps;
|
|
143
|
+
@ClientState() private collapsed: Record<string, boolean> = {};
|
|
144
|
+
/** The block whose removal waits for confirmation. */
|
|
145
|
+
@ClientState() private pendingRemove: string | null = null;
|
|
146
|
+
@ClientState() private drag: Drag | null = null;
|
|
147
|
+
private pointer: { id: number; x: number; y: number; depth: number } | null = null;
|
|
148
|
+
/** The window's listeners while a drag is on. Lists render by position, so the handle that started a drag may show another block, or leave the page, as the preview moves. */
|
|
149
|
+
private listeners: { move(event: PointerEvent): void; up(event: PointerEvent): void; cancel(): void; key(event: KeyboardEvent): void } | null = null;
|
|
150
|
+
/** Where the pointer last was during a drag, and what the drag scrolls near the window's edges. */
|
|
151
|
+
private last: { x: number; y: number } | null = null;
|
|
152
|
+
private scrollers: Element[] = [];
|
|
153
|
+
private scrollFrame = 0;
|
|
154
|
+
/** Each block's header, measured while dragging. */
|
|
155
|
+
private headers = new Map<string, HTMLElement>();
|
|
156
|
+
private handles = new Map<string, HTMLElement>();
|
|
157
|
+
|
|
158
|
+
private option(type: string): BlockOption | undefined {
|
|
159
|
+
return this.props.options.find(option => option.name === type);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The tree shown: the drop preview while dragging. */
|
|
163
|
+
private get tree(): EditorBlock[] {
|
|
164
|
+
return this.drag?.blocks ?? this.props.blocks;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Whether a container nobody toggled starts collapsed. */
|
|
168
|
+
private get startCollapsed(): boolean {
|
|
169
|
+
return this.props.expanded !== true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Containers are collapsed until opened (unless the tree starts `expanded`); a new one, one a
|
|
174
|
+
* block just went into, one holding the block an error names, or one a dragged block would
|
|
175
|
+
* land in, is open.
|
|
176
|
+
*/
|
|
177
|
+
private isCollapsed(block: EditorBlock, option: BlockOption | undefined): boolean {
|
|
178
|
+
return !!option?.children && (this.collapsed[block._id] ?? this.startCollapsed) && !this.errorPath.has(block._id) && !this.dropPath.has(block._id);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The containers of the dragged block in the drop preview; computed per render. */
|
|
182
|
+
private dropPath = new Set<string>();
|
|
183
|
+
|
|
184
|
+
/** The containers of a block, outermost first. */
|
|
185
|
+
private ancestors(blocks: readonly EditorBlock[], id: string): string[] {
|
|
186
|
+
const places = placeBlocks(blocks);
|
|
187
|
+
const path: string[] = [];
|
|
188
|
+
for (let parent = places.find(place => place.block._id === id)?.parent ?? null; parent; parent = places.find(place => place.block._id === parent)?.parent ?? null) path.unshift(parent);
|
|
189
|
+
return path;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Whether a moved tree keeps to what the tree allows beyond the types' nesting rules: a block
|
|
194
|
+
* that comes to the top level is one of the `allowed` types, and the pinned blocks keep their
|
|
195
|
+
* place, so nothing moves above an Edit tab or below a sidebar that stays last.
|
|
196
|
+
*/
|
|
197
|
+
private fits(next: readonly EditorBlock[]): boolean {
|
|
198
|
+
const pinned = this.props.pinned ?? [];
|
|
199
|
+
const allowed = this.props.allowed;
|
|
200
|
+
if (allowed.length && next.some(block => !allowed.includes(block.type) && !pinned.includes(block._id) && !this.props.blocks.some(entry => entry._id === block._id))) return false;
|
|
201
|
+
if (!pinned.length) return true;
|
|
202
|
+
const where = (blocks: readonly EditorBlock[]) => new Map(placeBlocks(blocks).filter(place => pinned.includes(place.block._id)).map(place => [place.block._id, `${place.parent}:${place.index}`]));
|
|
203
|
+
const after = where(next);
|
|
204
|
+
return [...where(this.props.blocks)].every(([id, place]) => after.get(id) === place);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The block the error names and its containers; computed per render. */
|
|
208
|
+
private errorPath = new Set<string>();
|
|
209
|
+
/** The error the tree last scrolled to, so it scrolls once per message. */
|
|
210
|
+
private scrolledTo = '';
|
|
211
|
+
|
|
212
|
+
/** Scroll to the block a new error names, once the render that opened its containers has committed. */
|
|
213
|
+
@Client()
|
|
214
|
+
private revealError() {
|
|
215
|
+
const error = this.props.error;
|
|
216
|
+
const target = blockErrorTarget(error);
|
|
217
|
+
if (!target || !error || this.scrolledTo === error) return;
|
|
218
|
+
this.scrolledTo = error;
|
|
219
|
+
requestAnimationFrame(() => this.headers.get(target.id)?.scrollIntoView({ block: 'center', behavior: 'smooth' }));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@Client()
|
|
223
|
+
private add(parent: string | null, type: string, variation?: string) {
|
|
224
|
+
const block = newBlock(type, this.props.options, blockId, variation);
|
|
225
|
+
if (!block) return;
|
|
226
|
+
this.collapsed = { ...this.collapsed, [block._id]: false };
|
|
227
|
+
this.props.onChange(insertBlock(this.props.blocks, parent, block));
|
|
228
|
+
// A new block opens in the panel at once when it has settings there, as its Edit button would.
|
|
229
|
+
const option = this.props.options.find(entry => entry.name === type);
|
|
230
|
+
if (option && this.props.onEdit && (option.fields.some(field => field.kind !== 'richtext') || this.props.form || this.props.fieldGroup)) {
|
|
231
|
+
const edit = this.props.onEdit;
|
|
232
|
+
requestAnimationFrame(() => {
|
|
233
|
+
edit(block._id);
|
|
234
|
+
// Once the sheet is open, the cursor goes to the block's first field.
|
|
235
|
+
setTimeout(() => {
|
|
236
|
+
const dialog = document.querySelector<HTMLElement>('dialog[open]');
|
|
237
|
+
if (dialog) getTabbable(dialog).find(element => element.matches('input:not([type="checkbox"]), textarea, select, [contenteditable="true"]'))?.focus();
|
|
238
|
+
}, 150);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@Client()
|
|
244
|
+
private shift(id: string, move: BlockMove, into?: string) {
|
|
245
|
+
const next = shiftBlock(this.props.blocks, id, move, declarationsOf(this.props.options));
|
|
246
|
+
if (next !== this.props.blocks && this.fits(next)) {
|
|
247
|
+
if (into) this.collapsed = { ...this.collapsed, [into]: false };
|
|
248
|
+
this.props.onChange([...next]);
|
|
249
|
+
requestAnimationFrame(() => this.handles.get(id)?.focus());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@Client()
|
|
254
|
+
private remove(id: string) {
|
|
255
|
+
this.pendingRemove = null;
|
|
256
|
+
this.props.onChange(removeBlock(this.props.blocks, id));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** A copy of the block (nested blocks included, every ID fresh) right after it. */
|
|
260
|
+
@Client()
|
|
261
|
+
private duplicate(id: string, parent: string | null, index: number) {
|
|
262
|
+
const block = placeBlocks(this.props.blocks).find(place => place.block._id === id)?.block;
|
|
263
|
+
if (!block) return;
|
|
264
|
+
const copy = cloneBlocks([block])[0]!;
|
|
265
|
+
const next = insertBlock(this.props.blocks, parent, copy, index + 1);
|
|
266
|
+
if (this.fits(next)) {
|
|
267
|
+
this.props.onChange(next);
|
|
268
|
+
requestAnimationFrame(() => this.handles.get(copy._id)?.focus());
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The block's secondary actions behind one ⋮ button: where it shows (per device), where it
|
|
274
|
+
* sits (the four moves) and Duplicate. Edit, Note and Remove stay as buttons of their own.
|
|
275
|
+
*/
|
|
276
|
+
private moreMenu(block: EditorBlock, label: string, prefix: string, can: { devices: boolean; hide: readonly Breakpoint[]; up: boolean; down: boolean; out: boolean; into: string | undefined; duplicate: boolean; parent: string | null; index: number }): TemplateResult {
|
|
277
|
+
const item = (name: string, text: string, run: () => void, enabled: boolean, options: { checked?: boolean } = {}) => html`<button type="button" role="menuitem" tabindex="-1" ?disabled=${!enabled} aria-label=${`${text} ${label}`}
|
|
278
|
+
aria-pressed=${options.checked === undefined ? undefined : options.checked ? 'true' : 'false'}
|
|
279
|
+
class=${`flex w-full items-center gap-2 rounded-sm border-none bg-transparent px-2 py-1.5 text-left text-sm cursor-pointer hover:bg-muted disabled:cursor-default disabled:opacity-40 [&_svg]:size-4 ${options.checked ? 'text-destructive' : 'text-foreground'}`}
|
|
280
|
+
@click=${run}>${component(Icon, { entry: icon(name), size: 16 })}<span class="flex-1">${text}</span>${options.checked ? html`<span aria-hidden="true" class="text-xs">${__('Hidden')}</span>` : null}</button>`;
|
|
281
|
+
const separator = html`<hr role="separator" class="-mx-1 my-1 border-t border-border">`;
|
|
282
|
+
return component(DropdownMenu, { id: `${prefix}-more`, side: 'bottom', align: 'end', 'aria-label': `${__('More actions for')} ${label}`, title: __('More'),
|
|
283
|
+
class: 'inline-flex h-7 shrink-0 items-center justify-center px-1.5 rounded border border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground [&_svg]:size-4',
|
|
284
|
+
trigger: component(Icon, { entry: icon('menu-dots'), size: 16 }) }, html`
|
|
285
|
+
${can.devices ? html`${BREAKPOINTS.map(breakpoint => {
|
|
286
|
+
const hidden = can.hide.includes(breakpoint);
|
|
287
|
+
const device = __(BREAKPOINT_DEVICES[breakpoint].label);
|
|
288
|
+
return item(BREAKPOINT_DEVICES[breakpoint].icon, hidden ? `${__('Show on')} ${device}` : `${__('Hide on')} ${device}`, () => this.toggleHide(block._id, breakpoint), true, { checked: hidden });
|
|
289
|
+
})}${separator}` : null}
|
|
290
|
+
${item('arrow-up', __('Move up'), () => this.shift(block._id, 'up'), can.up)}
|
|
291
|
+
${item('arrow-down', __('Move down'), () => this.shift(block._id, 'down'), can.down)}
|
|
292
|
+
${item('arrow-left', __('Move out'), () => this.shift(block._id, 'out'), can.out)}
|
|
293
|
+
${item('arrow-right', __('Move in'), () => this.shift(block._id, 'in', can.into), !!can.into)}
|
|
294
|
+
${can.duplicate ? html`${separator}${item('copy', __('Duplicate'), () => this.duplicate(block._id, can.parent, can.index), true)}` : null}`);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
@Client()
|
|
298
|
+
private setValue(id: string, key: string, value: unknown) {
|
|
299
|
+
this.props.onChange(updateBlock(this.props.blocks, id, block => ({ ...block, data: { ...block.data, [key]: value } })));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
@Client()
|
|
303
|
+
private toggleHide(id: string, breakpoint: Breakpoint) {
|
|
304
|
+
this.props.onChange(updateBlock(this.props.blocks, id, block => {
|
|
305
|
+
const hide = block.layout?.hide ?? [];
|
|
306
|
+
const next = hide.includes(breakpoint) ? hide.filter(entry => entry !== breakpoint) : [...BREAKPOINTS].filter(entry => entry === breakpoint || hide.includes(entry));
|
|
307
|
+
return { ...block, layout: { ...block.layout, hide: next } };
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@Client()
|
|
312
|
+
private toggleCollapsed(id: string) {
|
|
313
|
+
// An untoggled container is as the tree starts it, so the first click turns that over.
|
|
314
|
+
this.collapsed = { ...this.collapsed, [id]: !(this.collapsed[id] ?? this.startCollapsed) };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
@Client()
|
|
318
|
+
private collapseAll(collapsed: boolean) {
|
|
319
|
+
this.collapsed = Object.fromEntries(this.containers().map(block => [block._id, collapsed]));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The blocks that can hold others, so can collapse. */
|
|
323
|
+
private containers(): EditorBlock[] {
|
|
324
|
+
return placeBlocks(this.props.blocks).map(place => place.block).filter(block => !!this.option(block.type)?.children);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// --- Dragging: the tree previews the drop; the block is a ghost in its new place ---------
|
|
328
|
+
|
|
329
|
+
@Client()
|
|
330
|
+
private startDrag(event: PointerEvent, id: string) {
|
|
331
|
+
if (event.button !== 0 || this.props.lock === 'all' || this.props.pinned?.includes(id)) return;
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
334
|
+
const depth = placeBlocks(this.props.blocks).find(place => place.block._id === id)?.depth ?? 0;
|
|
335
|
+
this.pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, depth };
|
|
336
|
+
this.drag = { id, blocks: this.props.blocks, depth, moved: false };
|
|
337
|
+
this.props.onDrag?.(id);
|
|
338
|
+
this.listen();
|
|
339
|
+
// After `listen`, which clears what an earlier drag left.
|
|
340
|
+
this.last = { x: event.clientX, y: event.clientY };
|
|
341
|
+
this.scrollers = scrollersOf(event.currentTarget as HTMLElement);
|
|
342
|
+
this.autoScroll();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Follow the drag from the window, whichever element is under the pointer; Escape cancels it wherever the focus is. */
|
|
346
|
+
@Client()
|
|
347
|
+
private listen() {
|
|
348
|
+
this.unlisten();
|
|
349
|
+
const listeners = {
|
|
350
|
+
move: (event: PointerEvent) => this.moveDrag(event), up: (event: PointerEvent) => this.endDrag(event), cancel: () => this.cancelDrag(),
|
|
351
|
+
key: (event: KeyboardEvent) => { if (event.key === 'Escape') { event.preventDefault(); this.cancelDrag(); } },
|
|
352
|
+
};
|
|
353
|
+
window.addEventListener('pointermove', listeners.move);
|
|
354
|
+
window.addEventListener('pointerup', listeners.up);
|
|
355
|
+
window.addEventListener('pointercancel', listeners.cancel);
|
|
356
|
+
window.addEventListener('keydown', listeners.key);
|
|
357
|
+
this.listeners = listeners;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@Client()
|
|
361
|
+
private unlisten() {
|
|
362
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
363
|
+
this.last = null;
|
|
364
|
+
const listeners = this.listeners;
|
|
365
|
+
if (!listeners) return;
|
|
366
|
+
window.removeEventListener('pointermove', listeners.move);
|
|
367
|
+
window.removeEventListener('pointerup', listeners.up);
|
|
368
|
+
window.removeEventListener('pointercancel', listeners.cancel);
|
|
369
|
+
window.removeEventListener('keydown', listeners.key);
|
|
370
|
+
this.listeners = null;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** While a drag is on, a pointer near the window's top or bottom scrolls the page, and the preview follows what comes under it. */
|
|
374
|
+
@Client()
|
|
375
|
+
private autoScroll() {
|
|
376
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
377
|
+
const step = () => {
|
|
378
|
+
const last = this.last;
|
|
379
|
+
if (!this.drag || !last) return;
|
|
380
|
+
const bottom = window.innerHeight - SCROLL_EDGE;
|
|
381
|
+
const speed = Math.round(last.y < SCROLL_EDGE ? -(SCROLL_EDGE - last.y) / 3 : last.y > bottom ? (last.y - bottom) / 3 : 0);
|
|
382
|
+
// The nearest that moves scrolls; the preview follows what comes under the pointer.
|
|
383
|
+
const scrolled = speed !== 0 && this.scrollers.some(scroller => {
|
|
384
|
+
const before = scroller.scrollTop;
|
|
385
|
+
scroller.scrollTop = before + speed;
|
|
386
|
+
return scroller.scrollTop !== before;
|
|
387
|
+
});
|
|
388
|
+
if (scrolled && this.drag.moved) this.dragTo(last.x, last.y);
|
|
389
|
+
this.scrollFrame = requestAnimationFrame(step);
|
|
390
|
+
};
|
|
391
|
+
this.scrollFrame = requestAnimationFrame(step);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
@Client()
|
|
395
|
+
private moveDrag(event: PointerEvent) {
|
|
396
|
+
if (!this.pointer || event.pointerId !== this.pointer.id) return;
|
|
397
|
+
this.last = { x: event.clientX, y: event.clientY };
|
|
398
|
+
this.dragTo(event.clientX, event.clientY);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** The preview for the pointer at (x, y): the row under it decides the drop. */
|
|
402
|
+
@Client()
|
|
403
|
+
private dragTo(x: number, y: number) {
|
|
404
|
+
const pointer = this.pointer;
|
|
405
|
+
const drag = this.drag;
|
|
406
|
+
if (!pointer || !drag) return;
|
|
407
|
+
if (!drag.moved && Math.abs(y - pointer.y) < 4 && Math.abs(x - pointer.x) < 12) return;
|
|
408
|
+
const original = placeBlocks(this.props.blocks);
|
|
409
|
+
const from = original.findIndex(place => place.block._id === drag.id);
|
|
410
|
+
const moving = new Set(placeBlocks([original[from]!.block]).map(place => place.block._id));
|
|
411
|
+
// The rows that stay, in the order they show now; the one under the pointer decides the drop.
|
|
412
|
+
const rest = placeBlocks(drag.blocks).filter(place => !moving.has(place.block._id));
|
|
413
|
+
const depth = Math.min(Math.max(pointer.depth + Math.round((x - pointer.x) / 24), 0), BLOCK_LIMITS.depth - 1);
|
|
414
|
+
let to: number | null = null;
|
|
415
|
+
for (const [index, place] of rest.entries()) {
|
|
416
|
+
const rect = this.headers.get(place.block._id)?.getBoundingClientRect();
|
|
417
|
+
if (!rect || y < rect.top || y > rect.bottom) continue;
|
|
418
|
+
to = y < rect.top + rect.height / 2 ? index : index + 1;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
if (to === null) { if (!drag.moved) this.drag = { ...drag, moved: true }; return; }
|
|
422
|
+
const reordered = reorderBlocks(this.props.blocks, from, to, depth, declarationsOf(this.props.options));
|
|
423
|
+
// A drop the tree does not allow previews as the block where it started.
|
|
424
|
+
const next = this.fits(reordered) ? reordered : [...this.props.blocks];
|
|
425
|
+
if (treeShape(next) !== treeShape(drag.blocks) || !drag.moved) this.drag = { ...drag, blocks: next, depth, moved: true };
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
@Client()
|
|
429
|
+
private endDrag(event: PointerEvent) {
|
|
430
|
+
const drag = this.drag;
|
|
431
|
+
if (!this.pointer || event.pointerId !== this.pointer.id) return;
|
|
432
|
+
this.unlisten();
|
|
433
|
+
this.pointer = null;
|
|
434
|
+
this.drag = null;
|
|
435
|
+
this.props.onDrag?.(null);
|
|
436
|
+
if (drag?.moved && treeShape(drag.blocks) !== treeShape(this.props.blocks)) {
|
|
437
|
+
// The container the block landed in stays open.
|
|
438
|
+
const opened = this.ancestors(drag.blocks, drag.id);
|
|
439
|
+
if (opened.length) this.collapsed = { ...this.collapsed, ...Object.fromEntries(opened.map(id => [id, false])) };
|
|
440
|
+
this.props.onChange(drag.blocks);
|
|
441
|
+
requestAnimationFrame(() => this.handles.get(drag.id)?.focus());
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
@Client()
|
|
446
|
+
private cancelDrag() {
|
|
447
|
+
this.unlisten();
|
|
448
|
+
this.pointer = null;
|
|
449
|
+
this.drag = null;
|
|
450
|
+
this.props.onDrag?.(null);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
@Client()
|
|
454
|
+
private handleKey(event: KeyboardEvent, id: string) {
|
|
455
|
+
if (event.key === 'Escape' && this.drag) { this.cancelDrag(); return; }
|
|
456
|
+
if (this.props.lock === 'all' || this.props.pinned?.includes(id)) return;
|
|
457
|
+
const move = ({ ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'out', ArrowRight: 'in' } as const)[event.key as 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight'];
|
|
458
|
+
if (!move) return;
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
this.shift(id, move);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// --- Rendering ----------------------------------------------------------------------------
|
|
464
|
+
|
|
465
|
+
/** The block's fields: short ones share a row, long ones take the width. */
|
|
466
|
+
private fields(block: EditorBlock, option: BlockOption, only?: readonly EditorField[]): TemplateResult {
|
|
467
|
+
const runs: EditorField[][] = [];
|
|
468
|
+
for (const field of only ?? option.fields) {
|
|
469
|
+
const last = runs.at(-1);
|
|
470
|
+
if (SHORT_KINDS.has(field.kind) && last && SHORT_KINDS.has(last[0]!.kind)) last.push(field); else runs.push([field]);
|
|
471
|
+
}
|
|
472
|
+
const control = (field: EditorField) => {
|
|
473
|
+
const id = `${this.props.id}-${block._id}-${field.name}`;
|
|
474
|
+
const fieldError = this.props.error?.includes(`${block._id}.${field.name}`) ? this.props.error : '';
|
|
475
|
+
return html`<div class="min-w-0 space-y-1">
|
|
476
|
+
${field.kind === 'boolean' || field.kind === 'richtext' ? null : html`<label for=${id} class="block text-xs font-medium text-foreground">${field.label}${field.required ? ' *' : ''}</label>`}
|
|
477
|
+
${this.props.control(field, block.data[field.name], value => this.setValue(block._id, field.name, value), block, id)}
|
|
478
|
+
${field.description ? html`<p class="text-xs text-muted-foreground">${field.description}</p>` : null}
|
|
479
|
+
${fieldError ? html`<p role="alert" class="text-xs text-destructive">${fieldError}</p>` : null}
|
|
480
|
+
</div>`;
|
|
481
|
+
};
|
|
482
|
+
return html`${runs.map(run => run.length > 1 || SHORT_KINDS.has(run[0]!.kind)
|
|
483
|
+
? html`<div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">${run.map(control)}</div>` : control(run[0]!))}`;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
private section(block: EditorBlock, index: number, siblings: readonly EditorBlock[], parent: EditorBlock | null, depth: number): TemplateResult {
|
|
487
|
+
const option = this.option(block.type);
|
|
488
|
+
const label = option?.label ?? block.type;
|
|
489
|
+
const hide = block.layout?.hide ?? [];
|
|
490
|
+
const ghost = this.drag?.moved && this.drag.id === block._id;
|
|
491
|
+
const collapsed = this.isCollapsed(block, option);
|
|
492
|
+
const held = collapsed ? placeBlocks(block.children ?? []).length : 0;
|
|
493
|
+
const above = siblings[index - 1];
|
|
494
|
+
const pinned = this.props.pinned?.includes(block._id) === true;
|
|
495
|
+
const locked = this.props.lock === 'all' || pinned;
|
|
496
|
+
const canGoIn = !ghost && !locked && !!above && !!this.option(above.type)?.children && shiftBlock(this.props.blocks, block._id, 'in', declarationsOf(this.props.options)) !== this.props.blocks;
|
|
497
|
+
// The message names this block (or one of its fields): shown here in words, and the block flashes.
|
|
498
|
+
const target = blockErrorTarget(this.props.error);
|
|
499
|
+
const error = target?.id === block._id ? describeBlockError(this.props.error!, this.props.blocks, this.props.options) : '';
|
|
500
|
+
const summary = this.props.summary?.(block, option) ?? (option?.field ? (typeof block.data.description === 'string' ? block.data.description : '') : blockSummary(block, this.props.previews, option));
|
|
501
|
+
const prefix = `${this.props.id}-${block._id}`;
|
|
502
|
+
// Rich text is written in place, whichever way the block's other settings are edited; its
|
|
503
|
+
// toolbar names it, so it has no label of its own above the block's header.
|
|
504
|
+
const inlineFields = option?.fields.filter(field => field.kind === 'richtext') ?? [];
|
|
505
|
+
const data = option?.category === 'data';
|
|
506
|
+
const here = this.props.editing?.[block._id] ?? [];
|
|
507
|
+
return html`<section class=${`rounded-lg border bg-card ${ghost ? 'border-dashed border-primary bg-primary/5 opacity-50' : error ? 'cms-block-error border-destructive' : data ? 'border-dashed border-border' : 'border-border'}`} aria-label=${`${label} ${index + 1}`} data-block-tree-item=${block._id} style=${presenceOutline(here)}>
|
|
508
|
+
<header class="flex flex-wrap items-center gap-1.5 border-b border-border px-2 py-1.5" ref=${(element: Element) => { if (element) this.headers.set(block._id, element as HTMLElement); else this.headers.delete(block._id); }}>
|
|
509
|
+
<button type="button" class=${`flex h-7 w-5 shrink-0 touch-none items-center justify-center rounded border-none bg-transparent text-muted-foreground ${locked ? 'cursor-default opacity-40' : 'cursor-grab hover:bg-muted active:cursor-grabbing'}`} data-handle
|
|
510
|
+
aria-label=${pinned ? `${label}. ${__('This block stays where it is.')}` : locked ? `${label}. ${__('The template keeps this order.')}` : `${__('Move')} ${label}. ${__('Drag, or use the arrow keys.')}`} ?disabled=${locked}
|
|
511
|
+
ref=${(element: Element) => { if (element) this.handles.set(block._id, element as HTMLElement); else this.handles.delete(block._id); }}
|
|
512
|
+
@pointerdown=${(event: PointerEvent) => this.startDrag(event, block._id)}
|
|
513
|
+
@keydown=${(event: KeyboardEvent) => this.handleKey(event, block._id)}>${GRIP}</button>
|
|
514
|
+
${option?.children ? html`<button type="button" class="inline-flex h-7 w-6 shrink-0 items-center justify-center rounded border-none bg-transparent text-muted-foreground hover:bg-muted cursor-pointer [&_svg]:size-4"
|
|
515
|
+
aria-expanded=${collapsed ? 'false' : 'true'} aria-label=${`${collapsed ? __('Expand') : __('Collapse')} ${label}`} @click=${() => this.toggleCollapsed(block._id)}>
|
|
516
|
+
${component(Icon, { entry: icon(collapsed ? 'alt-arrow-right' : 'alt-arrow-down'), size: 16 })}</button>` : null}
|
|
517
|
+
<span class=${`inline-flex shrink-0 [&_svg]:size-4 ${blockIconColor(option?.category)}`}>${component(Icon, { entry: blockIcon(option?.icon), size: 16 })}</span>
|
|
518
|
+
<span class="min-w-28 flex-1 truncate text-sm">
|
|
519
|
+
<span class="font-medium text-foreground">${option?.field && typeof block.data.label === 'string' && block.data.label ? block.data.label : label}</span>
|
|
520
|
+
${option?.field ? html` <code class="text-xs text-muted-foreground">${typeof block.data.name === 'string' && block.data.name ? block.data.name : fieldName(String(block.data.label ?? ''))}</code> ${component(Badge, { variant: 'outline' }, label)}` : null}
|
|
521
|
+
${data ? html` ${component(Badge, { variant: 'outline' }, __('Data only'))}` : null}
|
|
522
|
+
${here.length ? html` ${presenceChip(here, __('is here'))}` : null}
|
|
523
|
+
${this.props.notes?.[block._id] ? html` ${noteMarker(this.props.notes[block._id]!, label, () => this.props.onNotes?.(block._id))}` : null}
|
|
524
|
+
${block.when ? html` ${component(Badge, { variant: 'outline' }, block.when.action === 'hide' ? __('Hidden if…') : __('Shown if…'))}` : null}
|
|
525
|
+
${summary ? html`<span class="ml-2 text-muted-foreground">${summary}</span>` : null}
|
|
526
|
+
${collapsed ? html`<span class="ml-2 text-muted-foreground">${held} ${held === 1 ? __('block') : __('blocks')}</span>` : null}
|
|
527
|
+
</span>
|
|
528
|
+
<span class="flex flex-wrap items-center gap-1">
|
|
529
|
+
${hide.length && !data && this.props.devices !== false ? html`<span class="inline-flex items-center gap-0.5 text-destructive [&_svg]:size-3.5" title=${`${__('Hidden on')} ${hide.map(breakpoint => __(BREAKPOINT_DEVICES[breakpoint].label)).join(', ')}`}>
|
|
530
|
+
${hide.map(breakpoint => component(Icon, { entry: icon(BREAKPOINT_DEVICES[breakpoint].icon), size: 14 }))}</span>` : null}
|
|
531
|
+
${this.moreMenu(block, label, prefix, {
|
|
532
|
+
devices: !data && this.props.devices !== false, hide, up: !locked && index > 0, down: !locked && index < siblings.length - 1, out: !locked && !!parent, into: canGoIn ? above?._id : undefined,
|
|
533
|
+
duplicate: !locked && !option?.field && !!option, parent: parent?._id ?? null, index,
|
|
534
|
+
})}
|
|
535
|
+
${option && this.props.onEdit && (option.fields.length > inlineFields.length || this.props.form || this.props.fieldGroup) ? iconButton(`${prefix}-edit`, 'pen', `${__('Edit')} ${label}`, () => this.props.onEdit!(block._id)) : null}
|
|
536
|
+
${this.props.onNote ? iconButton(`${prefix}-note`, 'chat-round-line', `${__('Add a note on')} ${label}`, () => this.props.onNote!(block._id)) : null}
|
|
537
|
+
${this.props.lock || pinned ? null : iconButton(`${prefix}-remove`, 'trash-bin-trash', `${__('Remove')} ${label}`, () => { this.pendingRemove = block._id; }, { danger: true })}
|
|
538
|
+
</span>
|
|
539
|
+
</header>
|
|
540
|
+
${collapsed || (option && !inlineFields.length && !option.children && !error) ? null : html`<div class="space-y-3 p-3">
|
|
541
|
+
${!option ? html`<p class="text-sm text-muted-foreground">${__('This block type is no longer available. Its content stays until you remove it.')}</p>`
|
|
542
|
+
: inlineFields.length ? this.fields(block, option, inlineFields) : null}
|
|
543
|
+
${option?.children ? this.list(block.children ?? [], block, depth + 1) : null}
|
|
544
|
+
${error ? html`<p role="alert" class="text-xs text-destructive">${error}</p>` : null}
|
|
545
|
+
</div>`}
|
|
546
|
+
</section>`;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
private list(blocks: readonly EditorBlock[], parent: EditorBlock | null, depth: number): TemplateResult {
|
|
550
|
+
const container = parent ? this.option(parent.type) ?? null : null;
|
|
551
|
+
const offered = offeredIn(this.props.options, container, this.props.allowed, this.props.form === true, this.props.fieldGroup === true);
|
|
552
|
+
const full = container?.children?.max !== null && container?.children?.max !== undefined && blocks.length >= container.children.max;
|
|
553
|
+
return html`<div class=${depth ? 'space-y-3 border-l-2 pl-3' : 'space-y-3'} style=${depth ? levelBorder(depth) : ''} data-block-tree-list=${parent?._id ?? ''}>
|
|
554
|
+
${blocks.length ? blocks.map((block, index) => this.section(block, index, blocks, parent, depth))
|
|
555
|
+
: html`<p class="rounded-md border border-dashed border-border p-3 text-center text-sm text-muted-foreground">${parent ? __('Empty. Add a block below.') : __('No blocks yet. Add the first one below.')}</p>`}
|
|
556
|
+
${offered.length && !full && !this.props.lock ? html`<div class="flex flex-wrap items-center gap-2">
|
|
557
|
+
${component(BlockInserter, { id: `${this.props.id}-add-${parent?._id ?? 'top'}`, blocks: offered, compact: depth > 0, onPick: (type: string, variation?: string) => this.add(parent?._id ?? null, type, variation) })}
|
|
558
|
+
${!parent && this.props.onPatterns ? html`<button type="button" class="inline-flex h-8 items-center gap-1.5 rounded-md border border-border bg-background px-3 text-sm font-medium text-foreground hover:bg-muted cursor-pointer [&_svg]:size-4"
|
|
559
|
+
@click=${() => this.props.onPatterns!()}>${component(Icon, { entry: icon('widget-add'), size: 16 })}${__('Patterns')}</button>` : null}
|
|
560
|
+
</div>` : null}
|
|
561
|
+
</div>`;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
render() {
|
|
565
|
+
this.errorPath = blockErrorPath(this.props.error, this.props.blocks);
|
|
566
|
+
this.dropPath = new Set(this.drag?.moved ? this.ancestors(this.drag.blocks, this.drag.id) : []);
|
|
567
|
+
if (typeof window !== 'undefined') this.revealError();
|
|
568
|
+
const places = placeBlocks(this.props.blocks);
|
|
569
|
+
const containers = this.containers();
|
|
570
|
+
const allCollapsed = containers.every(block => this.collapsed[block._id] ?? this.startCollapsed);
|
|
571
|
+
const pending = this.pendingRemove ? places.find(place => place.block._id === this.pendingRemove) : undefined;
|
|
572
|
+
const pendingLabel = pending ? this.option(pending.block.type)?.label ?? pending.block.type : '';
|
|
573
|
+
const held = pending ? placeBlocks([pending.block]).length - 1 : 0;
|
|
574
|
+
return html`<div class="space-y-2">
|
|
575
|
+
${containers.length ? html`<p class="flex justify-end text-xs"><button type="button" class="border-none bg-transparent text-muted-foreground hover:text-foreground cursor-pointer" @click=${() => this.collapseAll(!allCollapsed)}>${allCollapsed ? __('Expand all') : __('Collapse all')}</button></p>` : null}
|
|
576
|
+
${this.list(this.tree, null, 0)}
|
|
577
|
+
${component(AlertDialog, {
|
|
578
|
+
id: `${this.props.id}-remove-dialog`, open: pending !== undefined, title: `${__('Remove')} ${pendingLabel}?`,
|
|
579
|
+
description: held ? `${__('The block and the')} ${held} ${held === 1 ? __('block inside it are removed.') : __('blocks inside it are removed.')}` : __('The block and what it holds are removed from this entry.'),
|
|
580
|
+
cancelLabel: __('Cancel'), actionLabel: __('Remove'), actionVariant: 'destructive',
|
|
581
|
+
onAction: () => { if (this.pendingRemove) this.remove(this.pendingRemove); }, onOpenChange: () => { this.pendingRemove = null; },
|
|
582
|
+
})}
|
|
583
|
+
</div>`;
|
|
584
|
+
}
|
|
585
|
+
}
|