@cossackframework/cms 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +123 -3
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,1014 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public site's rendering: the active theme's templates, the helpers they receive, and
|
|
3
|
+
* the core block renderers themes can replace. Client-safe; views arrive from the server with
|
|
4
|
+
* Markdown and rich text already rendered to escaped HTML.
|
|
5
|
+
*/
|
|
6
|
+
import { component, html, ifDefined, unsafeHTML, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import type { HeadValue } from '@cossackframework/core';
|
|
8
|
+
import { plugins } from '@cossackframework/framework/plugins';
|
|
9
|
+
import { formBlock, inputBlock } from './form-view';
|
|
10
|
+
import { iconHref, safeLinkUrl } from '@cossackframework/cms';
|
|
11
|
+
import { iconStyle } from './icons';
|
|
12
|
+
import { archiveTemplate, assembleSiteTheme, blockStyleAttributes, entryTemplate, withContentFields, MAP_EMBED_URL, SHARE_NETWORKS, type BreadcrumbView, type PluginHead, type SiteBasics, type ThemeContext, type ShareNetwork, type SiteView, placeholderStyle, presetStyle, resolvePresets, siteThemeProblems, type ArchiveView, type EntryView, type LanguageLink, type LanguageSwitcherOptions, type MediaView, type MenuItemView, type MenuOptions, type RenderedBlock, type SearchOptions, type SiteTheme, type ThemeData, type ThemeHelpers, type ThemePresets, highlightCode, formatBytes } from '@cossackframework/cms';
|
|
13
|
+
|
|
14
|
+
export { archiveTemplate, entryTemplate, withContentFields };
|
|
15
|
+
export type { ArchiveView, EntryView, MediaView, Paging, RenderedBlock, SiteView } from '@cossackframework/cms';
|
|
16
|
+
|
|
17
|
+
/** Prose styles for rendered bodies. */
|
|
18
|
+
export const PROSE = 'cms-prose max-w-none leading-7 [&_a]:text-primary [&_a]:underline [&_h1]:mt-8 [&_h1]:text-3xl [&_h1]:font-bold [&_h2]:mt-8 [&_h2]:text-2xl [&_h2]:font-semibold [&_h3]:mt-6 [&_h3]:text-xl [&_h3]:font-semibold [&_h4]:mt-4 [&_h4]:font-semibold [&_p]:my-4 [&_ul]:my-4 [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:my-4 [&_ol]:list-decimal [&_ol]:pl-6 [&_li_p]:my-1 [&_blockquote]:my-6 [&_blockquote]:border-l-4 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:italic [&_pre]:my-4 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-muted [&_pre]:p-4 [&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_img]:my-6 [&_img]:h-auto [&_img]:max-w-full [&_img]:rounded-lg [&_hr]:my-8 [&_table]:my-4 [&_th]:border [&_th]:border-border [&_th]:px-2 [&_td]:border [&_td]:border-border [&_td]:px-2';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A plugin's theme (its `templates/` files and `ui.ts` `theme` export), layered over its
|
|
22
|
+
* parent's for a child theme, or the built-in fallback when it is missing or invalid.
|
|
23
|
+
*/
|
|
24
|
+
export function siteTheme(state: { readonly name: string | null; readonly parent?: string | null }): SiteTheme {
|
|
25
|
+
const plugin = state.name ? plugins.find(entry => entry.name === state.name) : undefined;
|
|
26
|
+
const parent = state.parent ? plugins.find(entry => entry.name === state.parent) : undefined;
|
|
27
|
+
const theme = plugin ? assembleSiteTheme(plugin, parent) : undefined;
|
|
28
|
+
return theme && !siteThemeProblems(theme).length ? theme as SiteTheme : fallbackTheme;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a site page renders its theme with: the theme, its option values and its loaders' data. */
|
|
32
|
+
export interface ThemeRenderState {
|
|
33
|
+
readonly name: string | null;
|
|
34
|
+
/** The theme a child theme extends, whose assets it falls back to. */
|
|
35
|
+
readonly parent?: string | null;
|
|
36
|
+
readonly options: Record<string, unknown>;
|
|
37
|
+
/** The presets blocks pick from; the defaults when absent. */
|
|
38
|
+
readonly presets?: Required<ThemePresets>;
|
|
39
|
+
readonly data?: { readonly layout?: ThemeData; readonly page?: ThemeData };
|
|
40
|
+
/**
|
|
41
|
+
* The page is in edit mode: blocks are wrapped in `display: contents` markers carrying their
|
|
42
|
+
* IDs (a field's rich text, the field's name), which the site editor finds. Themes never see
|
|
43
|
+
* it; visitors never get it.
|
|
44
|
+
*/
|
|
45
|
+
readonly editing?: boolean;
|
|
46
|
+
/** The page in each of the site's languages, for `helpers.languages()`; empty on a site with one language. */
|
|
47
|
+
readonly languages?: readonly LanguageLink[];
|
|
48
|
+
/** The menus of the theme's locations, for `helpers.menu()` and the Navigation block. */
|
|
49
|
+
readonly menus?: { readonly [location: string]: readonly MenuItemView[] };
|
|
50
|
+
/** Active plugins apart from the theme chain, whose `ui.ts` `head` adds tags to every site page (`pluginHeads`). */
|
|
51
|
+
readonly plugins?: readonly string[];
|
|
52
|
+
/** The site's title, tagline, logo and URLs, and the page's language, for `helpers.search()` and the site logo block. */
|
|
53
|
+
readonly site?: { readonly title: string; readonly tagline: string; readonly logo: string | null; readonly homeUrl: string; readonly searchUrl: string; readonly locale?: string; readonly url?: string; readonly breadcrumbs?: readonly BreadcrumbView[] };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A search form posting to the site's search page: a box, or a button that opens one. As
|
|
58
|
+
* `helpers.search()` and the `core/search` block render it. While someone types, entries of the
|
|
59
|
+
* page's language show under the box (`search.client.ts`), unless `suggest` is false.
|
|
60
|
+
*/
|
|
61
|
+
export function searchForm(action: string, options: SearchOptions = {}, locale?: string): TemplateResult {
|
|
62
|
+
const placeholder = options.placeholder || __('Search');
|
|
63
|
+
const suggest = options.suggest === false ? undefined : `/api/cms/search?perPage=5${locale ? `&locale=${encodeURIComponent(locale)}` : ''}`;
|
|
64
|
+
const form = html`<form action=${action} method="get" role="search" class=${`cms-search${options.class ? ` ${options.class}` : ''}`}
|
|
65
|
+
data-suggest=${ifDefined(suggest)} data-suggest-label=${ifDefined(suggest ? __('Suggestions') : undefined)} ref=${enhanceSearch}>
|
|
66
|
+
<input type="search" name="q" placeholder=${placeholder} aria-label=${placeholder} class="cms-search-input">
|
|
67
|
+
</form>`;
|
|
68
|
+
if (options.style !== 'icon') return form;
|
|
69
|
+
return html`<details class="cms-search-toggle"><summary class="cms-search-button" aria-label=${placeholder} title=${placeholder}>
|
|
70
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg></summary>${form}</details>`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The page's other languages as a `nav` of links: by name, flag, both or code, in a row or a
|
|
75
|
+
* column. Null on a site with one language. Themes render it through `helpers.languages()`, and
|
|
76
|
+
* the `core/languages` block places it in widget areas and content.
|
|
77
|
+
*/
|
|
78
|
+
export function languageSwitcher(languages: readonly LanguageLink[], options: LanguageSwitcherOptions = {}): TemplateResult | null {
|
|
79
|
+
if (languages.length < 2) return null;
|
|
80
|
+
const style = options.style === 'flags' || options.style === 'flags-names' || options.style === 'codes' ? options.style : 'names';
|
|
81
|
+
const list = options.layout === 'list';
|
|
82
|
+
const name = (language: LanguageLink) => {
|
|
83
|
+
const flag = language.flag ? html`<span aria-hidden="true">${language.flag}</span>` : null;
|
|
84
|
+
switch (style) {
|
|
85
|
+
case 'flags': return html`${flag ?? language.code.toUpperCase()}<span class="sr-only">${language.label}</span>`;
|
|
86
|
+
case 'flags-names': return html`${flag}${flag ? ' ' : ''}${language.label}`;
|
|
87
|
+
case 'codes': return html`<span aria-hidden="true">${language.code.toUpperCase()}</span><span class="sr-only">${language.label}</span>`;
|
|
88
|
+
default: return html`${language.label}`;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return html`<nav aria-label=${__('Language')} data-languages=${style} class=${options.class ?? ''}><ul class=${list ? 'flex flex-col gap-1 text-sm' : 'flex flex-wrap items-center gap-1 text-sm'}>${languages.map(language => html`<li>
|
|
92
|
+
<a href=${language.url} hreflang=${language.code} lang=${language.code} aria-current=${language.current ? 'true' : 'false'} title=${language.label}
|
|
93
|
+
class=${`inline-flex items-center gap-1 rounded px-2 py-1 no-underline ${language.current ? 'bg-muted font-medium text-foreground' : 'text-muted-foreground hover:text-foreground'}`}>${name(language)}</a></li>`)}</ul></nav>`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A media field's view among typed fields, or null for anything else. */
|
|
97
|
+
function mediaOf(value: unknown): MediaView | null {
|
|
98
|
+
return value && typeof value === 'object' && !Array.isArray(value) && 'contentType' in value && typeof (value as MediaView).url === 'string' ? value as MediaView : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A location's name as an accessible name, when the theme gives none: `primary` is “Primary”. */
|
|
102
|
+
function locationLabel(location: string): string {
|
|
103
|
+
const words = location.replaceAll('-', ' ');
|
|
104
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A menu as a `nav`, as `helpers.menu()` and the `core/navigation` block render it. `dropdowns`
|
|
109
|
+
* is a header menu: one row, a dropdown under an item with children, a mega panel under an item
|
|
110
|
+
* with a panel or heading children (one column per heading, links with their icon, description
|
|
111
|
+
* and badge from the field groups attached to menu items, the panel's blocks beside them), and
|
|
112
|
+
* below the `collapse` width (768px, or 1024px for `lg`) a hamburger button opening a drawer
|
|
113
|
+
* with a tree whose groups fold: the `mobile` items when given (another location's menu), else
|
|
114
|
+
* this menu's own. `inline` is one row with children flattened, for
|
|
115
|
+
* footers; `list` the whole tree as nested lists, for sidebars. Panels and dropdowns open on
|
|
116
|
+
* hover, keyboard focus and while a block inside is selected in Live Edit, with the motion the
|
|
117
|
+
* `nav`'s `data-motion` names (`cms/blocks.css`: `rise` by default, `fade`, `scale`, `none`, or
|
|
118
|
+
* a theme's own). Null without items. Themes restyle the `cms-nav-*` and `cms-mega-*` classes
|
|
119
|
+
* or draw their own.
|
|
120
|
+
*/
|
|
121
|
+
export function menuNav(items: readonly MenuItemView[], options: MenuOptions, helpers: Pick<ThemeHelpers, 'block' | 'isActive'>): TemplateResult | null {
|
|
122
|
+
if (!items.length) return null;
|
|
123
|
+
const style = options.style === 'inline' || options.style === 'list' ? options.style : 'dropdowns';
|
|
124
|
+
const motion = typeof options.motion === 'string' && options.motion.trim() ? options.motion.trim() : 'rise';
|
|
125
|
+
const collapse = options.collapse === 'lg' ? 'lg' : 'md';
|
|
126
|
+
// `helpers.menu` resolves a location name to items; a name reaching here, or no items, means this menu's own tree.
|
|
127
|
+
const mobileItems = Array.isArray(options.mobile) && options.mobile.length ? options.mobile : items;
|
|
128
|
+
const label = options.label ?? __('Menu');
|
|
129
|
+
const className = `cms-nav cms-nav-${style}${options.class ? ` ${options.class}` : ''}`;
|
|
130
|
+
const badge = (item: MenuItemView) => typeof item.fields.badge === 'string' && item.fields.badge ? html` <span class="cms-nav-badge">${item.fields.badge}</span>` : null;
|
|
131
|
+
/** A heading is text; a link carries its class names, attributes and whether it is the current page. */
|
|
132
|
+
const link = (item: MenuItemView, kind: string): TemplateResult => {
|
|
133
|
+
if (item.url === null) return html`<span class=${`${kind} cms-nav-heading${item.className ? ` ${item.className}` : ''}`} ...=${item.attributes}>${item.label}${badge(item)}</span>`;
|
|
134
|
+
const active = helpers.isActive(item.url);
|
|
135
|
+
return html`<a href=${item.url} class=${`${kind}${item.className ? ` ${item.className}` : ''}`} aria-current=${ifDefined(active ? 'page' : undefined)}
|
|
136
|
+
target=${ifDefined(item.newTab ? '_blank' : undefined)} rel=${ifDefined(item.newTab ? 'noopener noreferrer' : undefined)} ...=${item.attributes}>${item.label}${badge(item)}</a>`;
|
|
137
|
+
};
|
|
138
|
+
const tree = (item: MenuItemView): TemplateResult => html`<li class="cms-nav-item">${link(item, 'cms-nav-treelink')}${item.children.length ? html`<ul>${item.children.map(tree)}</ul>` : null}</li>`;
|
|
139
|
+
if (style === 'list') return html`<nav class=${className} aria-label=${label}><ul class="cms-nav-tree">${items.map(tree)}</ul></nav>`;
|
|
140
|
+
if (style === 'inline') {
|
|
141
|
+
// One level flattened; a heading shows the links under it.
|
|
142
|
+
const flat = items.flatMap(item => item.url === null ? item.children.filter(child => child.url !== null) : [item, ...item.children.filter(child => child.url !== null)]);
|
|
143
|
+
return html`<nav class=${className} aria-label=${label}><ul class="cms-nav-list">${flat.map(item => html`<li class="cms-nav-item">${link(item, 'cms-nav-link')}</li>`)}</ul></nav>`;
|
|
144
|
+
}
|
|
145
|
+
const dropdown = (children: readonly MenuItemView[]): TemplateResult => html`<div class="cms-nav-sub"><ul class="cms-nav-sublist">
|
|
146
|
+
${children.map(child => html`<li class="cms-nav-item">${link(child, 'cms-nav-sublink')}${child.children.length ? dropdown(child.children) : null}</li>`)}</ul></div>`;
|
|
147
|
+
const megaLink = (item: MenuItemView): TemplateResult => {
|
|
148
|
+
const icon = mediaOf(item.fields.icon);
|
|
149
|
+
return html`<a href=${item.url ?? '#'} class=${`cms-mega-link${item.className ? ` ${item.className}` : ''}`} aria-current=${ifDefined(item.url && helpers.isActive(item.url) ? 'page' : undefined)}
|
|
150
|
+
target=${ifDefined(item.newTab ? '_blank' : undefined)} rel=${ifDefined(item.newTab ? 'noopener noreferrer' : undefined)} ...=${item.attributes}>
|
|
151
|
+
${icon ? html`<img class="cms-nav-icon" src=${icon.url} alt="" width="20" height="20" loading="lazy" decoding="async">` : null}
|
|
152
|
+
<span class="cms-mega-text"><span class="cms-nav-label">${item.label}${badge(item)}</span>${item.description ? html`<span class="cms-nav-description">${item.description}</span>` : null}</span></a>`;
|
|
153
|
+
};
|
|
154
|
+
/** Columns of a mega panel: the links before any heading in one, then one per heading. */
|
|
155
|
+
const megaColumns = (children: readonly MenuItemView[]): { heading: MenuItemView | null; links: MenuItemView[] }[] => {
|
|
156
|
+
const columns: { heading: MenuItemView | null; links: MenuItemView[] }[] = [];
|
|
157
|
+
for (const child of children) {
|
|
158
|
+
if (child.url === null) columns.push({ heading: child, links: child.children.filter(link => link.url !== null) });
|
|
159
|
+
else {
|
|
160
|
+
let loose = columns.find(column => column.heading === null);
|
|
161
|
+
if (!loose) columns.unshift(loose = { heading: null, links: [] });
|
|
162
|
+
loose.links.push(child);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return columns.filter(column => column.links.length || column.heading);
|
|
166
|
+
};
|
|
167
|
+
const mega = (item: MenuItemView): TemplateResult => {
|
|
168
|
+
const columns = megaColumns(item.children);
|
|
169
|
+
const panel = item.panel?.length ? item.panel : null;
|
|
170
|
+
return html`<div class="cms-mega" data-panel=${ifDefined(panel ? '' : undefined)}><div class="cms-mega-box">
|
|
171
|
+
${columns.length ? html`<div class="cms-mega-columns">${columns.map(column => html`<div class="cms-mega-column">
|
|
172
|
+
${column.heading ? html`<p class="cms-mega-heading">${column.heading.label}</p>` : null}
|
|
173
|
+
<ul class="cms-mega-links">${column.links.map(entry => html`<li>${megaLink(entry)}</li>`)}</ul></div>`)}</div>` : null}
|
|
174
|
+
${panel ? html`<div class="cms-mega-panel cms-content">${helpers.block(panel)}</div>` : null}
|
|
175
|
+
</div></div>`;
|
|
176
|
+
};
|
|
177
|
+
const top = (item: MenuItemView): TemplateResult => {
|
|
178
|
+
const isMega = Boolean(item.panel?.length) || item.children.some(child => child.url === null);
|
|
179
|
+
const sub = isMega ? mega(item) : item.children.length ? dropdown(item.children) : null;
|
|
180
|
+
return html`<li class=${`cms-nav-item${sub ? ' cms-nav-has-sub' : ''}`} data-mega=${ifDefined(isMega ? '' : undefined)}>${link(item, 'cms-nav-link')}${sub}</li>`;
|
|
181
|
+
};
|
|
182
|
+
/** The drawer's tree: a link with children folds (its link in the summary stays a link), a heading labels the group under it. */
|
|
183
|
+
const fold = (item: MenuItemView): TemplateResult => {
|
|
184
|
+
if (item.url === null) return html`<li class="cms-nav-group"><span class="cms-nav-group-label">${item.label}${badge(item)}</span><ul>${item.children.map(fold)}</ul></li>`;
|
|
185
|
+
if (!item.children.length) return html`<li>${link(item, 'cms-nav-treelink')}</li>`;
|
|
186
|
+
return html`<li class="cms-nav-group"><details class="cms-nav-fold"><summary class="cms-nav-fold-row">${link(item, 'cms-nav-treelink')}<span class="cms-nav-caret" aria-hidden="true"></span></summary><ul>${item.children.map(fold)}</ul></details></li>`;
|
|
187
|
+
};
|
|
188
|
+
return html`<nav class=${className} aria-label=${label} data-motion=${motion} data-collapse=${collapse}>
|
|
189
|
+
<ul class="cms-nav-list">${items.map(top)}</ul>
|
|
190
|
+
<details class="cms-nav-mobile"><summary class="cms-nav-toggle"><span class="cms-nav-burger" aria-hidden="true"></span><span class="cms-nav-toggle-label">${__('Menu')}</span></summary>
|
|
191
|
+
<div class="cms-nav-drawer"><ul class="cms-nav-tree">${mobileItems.map(fold)}</ul></div></details>
|
|
192
|
+
</nav>`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Keeps a header menu closed once a link in it is followed. Client-side navigation keeps the
|
|
197
|
+
* layout, so the followed link would keep its focus and the pointer stay over the panel, and
|
|
198
|
+
* either holds a CSS-only menu open; the drawer is a `<details>` nothing closes. On a plain
|
|
199
|
+
* click of a link in a `cms-nav` (not a modifier click, not a new tab), the drawer and its folds
|
|
200
|
+
* close, the link loses focus, and the nav is marked `data-closed`, which the stylesheet reads
|
|
201
|
+
* to keep dropdowns and panels hidden until the pointer leaves the item or focus returns. A
|
|
202
|
+
* click in Live Edit, where it selects a block, is left alone. Returns the function that stops
|
|
203
|
+
* listening.
|
|
204
|
+
*/
|
|
205
|
+
export function closeMenusOnFollow(root: Document = document): () => void {
|
|
206
|
+
const onClick = (event: MouseEvent) => {
|
|
207
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
208
|
+
const link = (event.target as Element | null)?.closest?.('a[href]');
|
|
209
|
+
const nav = link?.closest('nav.cms-nav');
|
|
210
|
+
if (!link || !nav || link.getAttribute('target') === '_blank' || link.closest('[data-cms-doc]')) return;
|
|
211
|
+
for (const details of nav.querySelectorAll<HTMLDetailsElement>('details[open]')) details.open = false;
|
|
212
|
+
(link as HTMLElement).blur();
|
|
213
|
+
nav.setAttribute('data-closed', '');
|
|
214
|
+
};
|
|
215
|
+
const onFocus = (event: FocusEvent) => { (event.target as Element | null)?.closest?.('nav.cms-nav[data-closed]')?.removeAttribute('data-closed'); };
|
|
216
|
+
const onPointerOut = (event: PointerEvent) => {
|
|
217
|
+
const item = (event.target as Element | null)?.closest?.('nav.cms-nav[data-closed] .cms-nav-list > .cms-nav-item');
|
|
218
|
+
if (item && !(event.relatedTarget instanceof Node && item.contains(event.relatedTarget))) item.closest('nav')?.removeAttribute('data-closed');
|
|
219
|
+
};
|
|
220
|
+
root.addEventListener('click', onClick);
|
|
221
|
+
root.addEventListener('focusin', onFocus);
|
|
222
|
+
root.addEventListener('pointerout', onPointerOut);
|
|
223
|
+
return () => {
|
|
224
|
+
root.removeEventListener('click', onClick);
|
|
225
|
+
root.removeEventListener('focusin', onFocus);
|
|
226
|
+
root.removeEventListener('pointerout', onPointerOut);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* What active plugins add to the document head: each `ui.ts` `head` export, called with the site,
|
|
232
|
+
* the helpers and the plugin's own `asset()`. A hook that throws adds nothing.
|
|
233
|
+
*/
|
|
234
|
+
export function pluginHeads(state: Pick<ThemeRenderState, 'plugins'>, site: SiteView, helpers: ThemeHelpers): HeadValue[] {
|
|
235
|
+
const heads: HeadValue[] = [];
|
|
236
|
+
for (const name of state.plugins ?? []) {
|
|
237
|
+
const plugin = plugins.find(entry => entry.name === name);
|
|
238
|
+
const head = (plugin?.ui as { head?: unknown } | null | undefined)?.head;
|
|
239
|
+
if (typeof head !== 'function') continue;
|
|
240
|
+
try { heads.push((head as PluginHead)({ site, helpers, plugin: { asset: path => plugin!.assets[path] ?? '' } })); } catch { /* a broken hook adds nothing */ }
|
|
241
|
+
}
|
|
242
|
+
return heads;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** What a page's templates know of the site, from the render state; blanks before setup. */
|
|
246
|
+
export function siteBasics(state: Pick<ThemeRenderState, 'site' | 'menus' | 'languages'>): SiteBasics {
|
|
247
|
+
const site = state.site;
|
|
248
|
+
return { title: site?.title ?? '', tagline: site?.tagline ?? '', logo: site?.logo ?? null, locale: site?.locale ?? 'en', homeUrl: site?.homeUrl ?? '/', searchUrl: site?.searchUrl ?? '/search',
|
|
249
|
+
url: site?.url ?? '', breadcrumbs: site?.breadcrumbs ?? [], menus: state.menus ?? {}, languages: state.languages ?? [] };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The context a page's templates receive: the site as far as the page knows it, and the helpers. */
|
|
253
|
+
export function themeContext(theme: SiteTheme, state: ThemeRenderState, isActive: (path: string, exact: boolean) => boolean): ThemeContext {
|
|
254
|
+
return { site: siteBasics(state), helpers: themeHelpers(theme, state, isActive) };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The helpers every template receives. `isActive` is the component's own: an exact path, or a prefix. */
|
|
258
|
+
export function themeHelpers(theme: SiteTheme, state: ThemeRenderState, isActive: (path: string, exact: boolean) => boolean): ThemeHelpers {
|
|
259
|
+
const assetsOf = (name: string | null | undefined) => name ? plugins.find(plugin => plugin.name === name)?.assets ?? {} : {};
|
|
260
|
+
// A child theme's files win over its parent's.
|
|
261
|
+
const assets: Readonly<Record<string, string>> = { ...assetsOf(state.parent), ...assetsOf(state.name) };
|
|
262
|
+
const helpers: ThemeHelpers = {
|
|
263
|
+
options: state.options,
|
|
264
|
+
presets: state.presets ?? resolvePresets(undefined),
|
|
265
|
+
data: { layout: state.data?.layout ?? {}, page: state.data?.page ?? {} },
|
|
266
|
+
asset: path => assets[path] ?? '',
|
|
267
|
+
icon: (name, options = {}) => siteIcon(name, options),
|
|
268
|
+
breadcrumbs: (options = {}) => breadcrumbTrail(state.site?.breadcrumbs, options),
|
|
269
|
+
logo: (options = {}) => state.site?.logo ? html`<img src=${state.site.logo} alt=${state.site.title} class=${`cms-site-logo object-contain ${options.class ?? 'h-10 w-auto'}`}>` : null,
|
|
270
|
+
languages: options => languageSwitcher(state.languages ?? [], options),
|
|
271
|
+
menu: (source, options = {}) => menuNav(typeof source === 'string' ? state.menus?.[source] ?? [] : source,
|
|
272
|
+
{ ...(typeof source === 'string' ? { label: locationLabel(source) } : {}), ...options, ...(typeof options.mobile === 'string' ? { mobile: state.menus?.[options.mobile] ?? [] } : {}) }, helpers),
|
|
273
|
+
search: options => searchForm(state.site?.searchUrl ?? '/search', options, state.site?.locale),
|
|
274
|
+
isActive: url => {
|
|
275
|
+
const path = url.replace(/[?#].*$/, '').replace(/(.)\/$/, '$1');
|
|
276
|
+
if (!path.startsWith('/')) return false;
|
|
277
|
+
return path === '/' ? isActive('/', true) : isActive(path, true) || isActive(`${path}/`, false);
|
|
278
|
+
},
|
|
279
|
+
block: input => {
|
|
280
|
+
const list: readonly RenderedBlock[] = Array.isArray(input) ? input as readonly RenderedBlock[] : [input as RenderedBlock];
|
|
281
|
+
return html`${list.map(block => state.editing ? marked(block) : render(block))}`;
|
|
282
|
+
},
|
|
283
|
+
layout: (blocks, options = {}) => html`<div class=${`cms-layout${options.class ? ` ${options.class}` : ''}`}>${blocks.map(block => layoutItem(block, helpers))}</div>`,
|
|
284
|
+
content: parts => html`${parts.map(part => part.kind === 'html' ? html`<div class=${PROSE}>${unsafeHTML(part.html)}</div>` : render(part.block))}`,
|
|
285
|
+
};
|
|
286
|
+
let basics: SiteBasics | undefined;
|
|
287
|
+
// In edit mode a block carries its ID; a field's rich text is one document, edited as a whole in the field's panel.
|
|
288
|
+
const marked = (block: RenderedBlock) => block.field
|
|
289
|
+
? html`<div data-cms-edit="body" data-field=${block.field} style="display: contents">${render(block)}</div>`
|
|
290
|
+
: html`<div data-cms-edit="block" data-block-id=${block.sourceId ?? block._id} data-cms-doc=${block.document ?? (block.pattern ? `pattern:${block.pattern}` : 'entry')} data-cms-locked=${ifDefined(block.locked ? '' : undefined)} style="display: contents">${render(block)}</div>`;
|
|
291
|
+
const render = (block: RenderedBlock) => {
|
|
292
|
+
// Data blocks hold values for themes and the API; nothing shows for them.
|
|
293
|
+
if (block.dataOnly) return null;
|
|
294
|
+
const renderer = theme.blocks?.[block.type];
|
|
295
|
+
const rendered = (renderer ? renderer({ block, site: basics ??= siteBasics(state), helpers }) : null) ?? coreBlock(block, helpers, state);
|
|
296
|
+
// A styled block gets one wrapper: classes per property and the presets' variables inline.
|
|
297
|
+
// A column's wrapper takes its grid placement, as cms/blocks.css places `.cms-column-box`.
|
|
298
|
+
// A group's wrapper carries its alignment too, so a narrow group's background is as narrow as the group.
|
|
299
|
+
// A video plays behind the content, muted and looping, with the background image as its poster; the overlay paints over both (cms/blocks.css).
|
|
300
|
+
// An image that covers the block is an <img> behind it: a variant for the screen's width, loaded as it nears the screen, or at once when it is the page's first image.
|
|
301
|
+
const attributes = blockStyleAttributes(block);
|
|
302
|
+
const column = block.type === 'core/column';
|
|
303
|
+
const video = attributes?.video;
|
|
304
|
+
const backdrop = attributes?.image;
|
|
305
|
+
const poster = typeof block.style?.image === 'string' ? block.media[block.style.image]?.url : undefined;
|
|
306
|
+
const styled = attributes ? html`<div class=${column ? `${attributes.className} cms-column-box` : attributes.className} id=${ifDefined(attributes.id || undefined)} data-nosnippet=${ifDefined(attributes.nosnippet ? '' : undefined)}
|
|
307
|
+
data-align=${ifDefined(block.type === 'core/group' ? alignOf(block) : undefined)}
|
|
308
|
+
style=${ifDefined([attributes.style, column ? `--cms-span: ${columnSpan(block)}` : ''].filter(Boolean).join('; ') || undefined)}>${backdrop
|
|
309
|
+
? html`<img class="cms-bg-image" src=${backdrop.media.url} srcset=${backdrop.media.srcset} sizes=${block.type === 'core/group' && alignOf(block) === 'full' ? '100vw' : '(min-width: 1280px) 1280px, 100vw'} alt="" aria-hidden="true"
|
|
310
|
+
width=${backdrop.media.width ?? ''} height=${backdrop.media.height ?? ''} loading=${backdrop.media.priority ? 'eager' : 'lazy'} fetchpriority=${ifDefined(backdrop.media.priority ? 'high' : undefined)} decoding="async"
|
|
311
|
+
style=${`object-position: ${backdrop.position}`}>` : null}${video
|
|
312
|
+
? html`<video class="cms-bg-video" src=${video.url} poster=${ifDefined(poster)} autoplay muted loop playsinline disablepictureinpicture preload="auto" aria-hidden="true" tabindex="-1"></video>` : null}${rendered}</div>` : rendered;
|
|
313
|
+
// A hidden block stays in the HTML; the stylesheet drops it at those container widths.
|
|
314
|
+
const hide = block.layout?.hide ?? [];
|
|
315
|
+
const sized = hide.length ? html`<div data-hide=${hide.join(' ')} style="display: contents">${styled}</div>` : styled;
|
|
316
|
+
// In a form, a block with a condition shows or hides as the form's values change.
|
|
317
|
+
return block.when ? html`<div data-cms-when=${block._id} ?data-hidden=${block.shown === false} style="display: contents">${sized}</div>` : sized;
|
|
318
|
+
};
|
|
319
|
+
return helpers;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Rendered blocks, and the blocks inside them, as part of a Live Edit document: the markers name
|
|
324
|
+
* it, and a locked one selects nothing. A block expanded from a synced pattern belongs to the
|
|
325
|
+
* pattern's document instead, locked unless `patterns` says the user may change that pattern.
|
|
326
|
+
*/
|
|
327
|
+
export function tagDocument(blocks: readonly RenderedBlock[], document: string, locked: boolean, patterns?: ReadonlyMap<string, boolean>): RenderedBlock[] {
|
|
328
|
+
return blocks.map(block => {
|
|
329
|
+
const own = block.pattern ? { document: `pattern:${block.pattern}`, locked: patterns?.get(block.pattern) ?? true } : { document, locked };
|
|
330
|
+
return { ...block, document: own.document, ...(own.locked ? { locked: true } : {}), ...(block.children ? { children: tagDocument(block.children, document, locked, patterns) } : {}) };
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const ALIGNMENTS: ReadonlySet<string> = new Set(['content', 'wide', 'full', 'center', 'left', 'right']);
|
|
335
|
+
|
|
336
|
+
/** A block's width where the layout constrains blocks: its Width field (`align`), `content` without one. */
|
|
337
|
+
export function alignOf(block: Pick<RenderedBlock, 'data'>): string {
|
|
338
|
+
const align = block.data.align;
|
|
339
|
+
return typeof align === 'string' && ALIGNMENTS.has(align) ? align : 'content';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* A block as an item of a constrained layout: a box at the content measure, or the wide, full
|
|
344
|
+
* or narrow one its Width field asks for (`cms-item` in cms/blocks.css), which is also the
|
|
345
|
+
* query container the block responds to. `helpers.layout` wraps a template's blocks root in
|
|
346
|
+
* them; a full-width group wraps its children.
|
|
347
|
+
*/
|
|
348
|
+
export function layoutItem(block: RenderedBlock, helpers: Pick<ThemeHelpers, 'block'>): TemplateResult {
|
|
349
|
+
return html`<div class="cms-item" data-align=${alignOf(block)}>${helpers.block(block)}</div>`;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The root the layout blocks respond to: columns stack and hidden blocks hide by its width,
|
|
354
|
+
* not the viewport's, so the editor's device toggle only narrows it. Site pages wrap the
|
|
355
|
+
* theme's page in it; a theme wraps widget areas it renders.
|
|
356
|
+
*/
|
|
357
|
+
export function siteContent(page: TemplateResult, theme?: Pick<ThemeRenderState, 'presets'>): TemplateResult {
|
|
358
|
+
return html`<div class="cms-content" style=${ifDefined(presetStyle(theme?.presets) || undefined)}>${page}</div>`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** A column's width out of 12, from the span the columns block computed for it. */
|
|
362
|
+
function columnSpan(block: RenderedBlock): number {
|
|
363
|
+
return Math.min(Math.max(Number(block.data.span) || 12, 1), 12);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* An image with its resized variants, for blocks; `sizes` is how wide it shows. Its width and
|
|
368
|
+
* height keep the page from shifting as it loads, and its blurred placeholder shows until then.
|
|
369
|
+
*/
|
|
370
|
+
export function image(media: MediaView | undefined, className = '', sizes = media?.sizes): TemplateResult | null {
|
|
371
|
+
if (!media) return null;
|
|
372
|
+
return html`<img src=${media.url} srcset=${ifDefined(media.srcset || undefined)} sizes=${ifDefined(media.srcset ? sizes : undefined)} alt=${media.alt}
|
|
373
|
+
width=${media.width ?? ''} height=${media.height ?? ''} loading=${media.priority ? 'eager' : 'lazy'} fetchpriority=${ifDefined(media.priority ? 'high' : undefined)} decoding="async" class=${className}
|
|
374
|
+
style=${ifDefined(placeholderStyle(media.placeholder, media.width, media.height) || undefined)}>`;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** A media element's `preload`, from the block's choice. */
|
|
378
|
+
function preloadOf(value: string): 'metadata' | 'auto' | 'none' {
|
|
379
|
+
return value === 'auto' || value === 'none' ? value : 'metadata';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** YouTube and Vimeo URLs as their privacy-respecting embed URLs. */
|
|
383
|
+
export interface Embed { readonly src: string; readonly title: string; readonly aspect: 'video' | 'tall' | 'wide' | 'short' }
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The provider's player or card for a page address, with the shape it is shown in: 16:9 for
|
|
387
|
+
* videos, pens and designs; tall for posts; wide for playlists and albums; short for one track.
|
|
388
|
+
* Each is a fixed URL on the provider's own embed host, so a page never loads what the address
|
|
389
|
+
* said and no request is made to find out.
|
|
390
|
+
*/
|
|
391
|
+
export function embedUrl(url: string): Embed | null {
|
|
392
|
+
const match = (pattern: RegExp) => pattern.exec(url);
|
|
393
|
+
let found = match(/^https:\/\/(?:www\.|m\.)?(?:youtube\.com\/(?:watch\?(?:.*&)?v=|shorts\/|live\/|embed\/)|youtu\.be\/)([A-Za-z0-9_-]{6,20})/);
|
|
394
|
+
if (found) return { src: `https://www.youtube-nocookie.com/embed/${found[1]}`, title: 'YouTube video', aspect: 'video' };
|
|
395
|
+
found = match(/^https:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?(\d{1,15})/);
|
|
396
|
+
if (found) return { src: `https://player.vimeo.com/video/${found[1]}`, title: 'Vimeo video', aspect: 'video' };
|
|
397
|
+
found = match(/^https:\/\/(?:www\.|mobile\.)?(?:x|twitter)\.com\/[A-Za-z0-9_]{1,30}\/status\/(\d{1,30})/);
|
|
398
|
+
if (found) return { src: `https://platform.twitter.com/embed/Tweet.html?id=${found[1]}&dnt=true`, title: 'Post on X', aspect: 'tall' };
|
|
399
|
+
found = match(/^https:\/\/(?:www\.)?instagram\.com\/(?:p|reel|reels)\/([A-Za-z0-9_-]{5,40})/);
|
|
400
|
+
if (found) return { src: `https://www.instagram.com/p/${found[1]}/embed/`, title: 'Instagram post', aspect: 'tall' };
|
|
401
|
+
found = match(/^https:\/\/(?:www\.|m\.)?tiktok\.com\/@[\w.-]{1,40}\/video\/(\d{5,30})/);
|
|
402
|
+
if (found) return { src: `https://www.tiktok.com/embed/v2/${found[1]}`, title: 'TikTok video', aspect: 'tall' };
|
|
403
|
+
found = match(/^https:\/\/open\.spotify\.com\/(?:intl-[a-z]{2}\/)?(track|album|playlist|episode|show|artist)\/([A-Za-z0-9]{10,40})/);
|
|
404
|
+
if (found) return { src: `https://open.spotify.com/embed/${found[1]}/${found[2]}`, title: `Spotify ${found[1]}`, aspect: found[1] === 'track' || found[1] === 'episode' ? 'short' : 'wide' };
|
|
405
|
+
found = match(/^https:\/\/(?:www\.|m\.)?soundcloud\.com\/[\w-]{1,60}\/[\w-]{1,120}/);
|
|
406
|
+
if (found) return { src: `https://w.soundcloud.com/player/?url=${encodeURIComponent(found[0])}&visual=false&show_comments=false`, title: 'SoundCloud track', aspect: 'short' };
|
|
407
|
+
found = match(/^https:\/\/codepen\.io\/([\w-]{1,60})\/(?:pen|full|details)\/([A-Za-z]{5,20})/);
|
|
408
|
+
if (found) return { src: `https://codepen.io/${found[1]}/embed/${found[2]}?default-tab=result`, title: 'CodePen', aspect: 'video' };
|
|
409
|
+
found = match(/^https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[A-Za-z0-9]{5,60}[^\s]*/);
|
|
410
|
+
if (found) return { src: `https://www.figma.com/embed?embed_host=cossack&url=${encodeURIComponent(found[0])}`, title: 'Figma design', aspect: 'video' };
|
|
411
|
+
found = match(/^https:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([a-f0-9]{20,40})/);
|
|
412
|
+
if (found) return { src: `https://www.loom.com/embed/${found[1]}`, title: 'Loom video', aspect: 'video' };
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** A link a block gives: a site path, an http(s), mail or phone address, or `#`; anything else is `#`. */
|
|
417
|
+
export function safeLink(url: unknown): string {
|
|
418
|
+
return safeLinkUrl(url) ? url : '#';
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* A divider's color: a palette slug as its variable, else a hex, rgb()/hsl()/oklch() or named
|
|
423
|
+
* CSS color, else the border color. Anything else could add declarations to the style.
|
|
424
|
+
*/
|
|
425
|
+
export function dividerColor(value: string): string {
|
|
426
|
+
if (!value) return 'var(--border)';
|
|
427
|
+
if (/^[a-z][a-z0-9-]*$/.test(value)) return /^(?:red|blue|green|black|white|gray|grey|transparent|currentcolor)$/.test(value) ? value : `var(--cms-color-${value}, ${value})`;
|
|
428
|
+
if (/^#[0-9a-f]{3,8}$/i.test(value) || /^(?:rgba?|hsla?|oklch|oklab|lab|lch)\([\d\s.,%/+-]{1,60}\)$/i.test(value)) return value;
|
|
429
|
+
return 'var(--border)';
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** The carousel's browser part: arrows, dots and autoplay over a scroll-snapping track. Swiping works without it. */
|
|
433
|
+
function enhanceCarousel(element: Element | undefined): void {
|
|
434
|
+
if (!element || typeof window === 'undefined') return;
|
|
435
|
+
void import('./carousel.client').then(module => module.enhanceCarousel(element as HTMLElement)).catch(() => undefined);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** The lightbox's browser part: a click on an image or a video poster opens it large over the page. The links open the files without it. */
|
|
439
|
+
function enhanceLightbox(element: Element | undefined): void {
|
|
440
|
+
if (!element || typeof window === 'undefined') return;
|
|
441
|
+
void import('./lightbox.client').then(module => module.enhanceLightbox(element as HTMLElement)).catch(() => undefined);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** The before-and-after block's browser part: the handle follows the pointer and the keyboard, thumbnails pick the pair. */
|
|
445
|
+
function enhanceCompare(element: Element | undefined): void {
|
|
446
|
+
if (!element || typeof window === 'undefined') return;
|
|
447
|
+
void import('./compare.client').then(module => module.enhanceCompare(element as HTMLElement)).catch(() => undefined);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** A `ref` for an element no script touches. */
|
|
451
|
+
function unenhanced(): void { /* nothing to add */ }
|
|
452
|
+
|
|
453
|
+
/** A heading's text, the words between *asterisks* in the accent color (`cms-accent`). */
|
|
454
|
+
export function accented(text: string): (string | TemplateResult)[] {
|
|
455
|
+
return text.split(/\*([^*\n]+)\*/).map((part, index) => index % 2 ? html`<span class="cms-accent">${part}</span>` : part).filter(part => part !== '');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** The tabs' browser part: the buttons switch panels, the arrow keys move between them. Every panel shows without it. */
|
|
459
|
+
function enhanceTabs(element: Element | undefined): void {
|
|
460
|
+
if (!element || typeof window === 'undefined') return;
|
|
461
|
+
void import('./tabs.client').then(module => module.enhanceTabs(element as HTMLElement)).catch(() => undefined);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** The stat's browser part: the number counts up as it scrolls into view. */
|
|
465
|
+
function enhanceStat(element: Element | undefined): void {
|
|
466
|
+
if (!element || typeof window === 'undefined') return;
|
|
467
|
+
void import('./stat.client').then(module => module.enhanceStat(element as HTMLElement)).catch(() => undefined);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** The countdown's browser part: the units tick every second. */
|
|
471
|
+
function enhanceCountdown(element: Element | undefined): void {
|
|
472
|
+
if (!element || typeof window === 'undefined') return;
|
|
473
|
+
void import('./countdown.client').then(module => module.enhanceCountdown(element as HTMLElement)).catch(() => undefined);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** The search box's browser part: suggestions while someone types. The form submits without it. */
|
|
477
|
+
function enhanceSearch(element: Element | undefined): void {
|
|
478
|
+
if (!element || typeof window === 'undefined' || !(element as HTMLElement).dataset.suggest) return;
|
|
479
|
+
void import('./search.client').then(module => module.enhanceSearch(element as HTMLFormElement)).catch(() => undefined);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** The share buttons' browser part: copying the address, opening networks in a small window. */
|
|
483
|
+
function enhanceShare(element: Element | undefined): void {
|
|
484
|
+
if (!element || typeof window === 'undefined') return;
|
|
485
|
+
void import('./share.client').then(module => module.enhanceShare(element as HTMLElement)).catch(() => undefined);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const SEPARATORS: Readonly<Record<string, string>> = { chevron: '›', slash: '/', arrow: '→' };
|
|
489
|
+
|
|
490
|
+
/** A page's breadcrumbs as a `nav`: links, then the page itself; null for a trail of one. `helpers.breadcrumbs` and the block render this. */
|
|
491
|
+
export function breadcrumbTrail(crumbs: readonly BreadcrumbView[] | undefined, options: { readonly class?: string; readonly separator?: string; readonly home?: boolean } = {}): TemplateResult | null {
|
|
492
|
+
const shown = options.home === false ? (crumbs ?? []).slice(1) : crumbs ?? [];
|
|
493
|
+
if (shown.length < (options.home === false ? 1 : 2)) return null;
|
|
494
|
+
const separator = SEPARATORS[options.separator ?? ''] ? options.separator! : 'chevron';
|
|
495
|
+
return html`<nav class=${`cms-breadcrumbs${options.class ? ` ${options.class}` : ''}`} aria-label=${__('Breadcrumb')} data-separator=${separator}><ol class="cms-breadcrumbs-list">${shown.map(crumb => html`<li class="cms-breadcrumb">${crumb.url
|
|
496
|
+
? html`<a href=${crumb.url}>${crumb.label}</a>` : html`<span aria-current="page">${crumb.label}</span>`}</li>`)}</ol></nav>`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const SHARE_NAMES: Readonly<Record<ShareNetwork, string>> = { facebook: 'Facebook', x: 'X', linkedin: 'LinkedIn', whatsapp: 'WhatsApp', telegram: 'Telegram', reddit: 'Reddit', pinterest: 'Pinterest', bluesky: 'Bluesky', threads: 'Threads', email: 'Email', copy: 'Copy link' };
|
|
500
|
+
|
|
501
|
+
/** Where a network's share intent takes a page, with its title; null for the copy button. */
|
|
502
|
+
export function shareUrl(network: ShareNetwork, url: string, title: string): string | null {
|
|
503
|
+
const u = encodeURIComponent(url);
|
|
504
|
+
const t = encodeURIComponent(title);
|
|
505
|
+
switch (network) {
|
|
506
|
+
case 'facebook': return `https://www.facebook.com/sharer/sharer.php?u=${u}`;
|
|
507
|
+
case 'x': return `https://x.com/intent/post?url=${u}&text=${t}`;
|
|
508
|
+
case 'linkedin': return `https://www.linkedin.com/sharing/share-offsite/?url=${u}`;
|
|
509
|
+
case 'whatsapp': return `https://wa.me/?text=${encodeURIComponent(`${title} ${url}`.trim())}`;
|
|
510
|
+
case 'telegram': return `https://t.me/share/url?url=${u}&text=${t}`;
|
|
511
|
+
case 'reddit': return `https://www.reddit.com/submit?url=${u}&title=${t}`;
|
|
512
|
+
case 'pinterest': return `https://pinterest.com/pin/create/button/?url=${u}&description=${t}`;
|
|
513
|
+
case 'bluesky': return `https://bsky.app/intent/compose?text=${encodeURIComponent(`${title} ${url}`.trim())}`;
|
|
514
|
+
case 'threads': return `https://www.threads.net/intent/post?text=${encodeURIComponent(`${title} ${url}`.trim())}`;
|
|
515
|
+
case 'email': return `mailto:?subject=${t}&body=${u}`;
|
|
516
|
+
case 'copy': return null;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** An accordion that opens one section at a time: its sections share a `name`, which the browser keeps exclusive. */
|
|
521
|
+
function enhanceAccordion(element: Element | undefined): void {
|
|
522
|
+
if (!(element instanceof HTMLElement) || element.dataset.single !== 'true') return;
|
|
523
|
+
for (const details of element.querySelectorAll<HTMLDetailsElement>('details.cms-accordion-item')) details.name = `${element.id || 'cms-accordion'}-${element.dataset.group ?? ''}`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* An icon of the catalog, in the site's style: `class` sizes it (default `size-5`), and it is
|
|
528
|
+
* decorative unless `label` names it. Drawn as `<use>` into the icon sprites (cms/icons.ts), so
|
|
529
|
+
* the HTML carries a reference, not the artwork. Null for a name outside the catalog, so a theme
|
|
530
|
+
* can fall back. `helpers.icon` is this.
|
|
531
|
+
*/
|
|
532
|
+
export function siteIcon(name: string, options: { readonly class?: string; readonly label?: string } = {}): TemplateResult | null {
|
|
533
|
+
const href = iconHref(name, iconStyle());
|
|
534
|
+
if (!href) return null;
|
|
535
|
+
const label = options.label?.trim();
|
|
536
|
+
return html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" class=${`cms-icon ${options.class ?? 'size-5'}`} focusable="false"
|
|
537
|
+
role=${ifDefined(label ? 'img' : undefined)} aria-label=${ifDefined(label || undefined)} aria-hidden=${ifDefined(label ? undefined : 'true')}><use href=${href}></use></svg>`;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** What a social link is called when no network is known: Email, Phone, or the site's host. */
|
|
541
|
+
function socialTitle(url: string): string {
|
|
542
|
+
if (url.startsWith('mailto:')) return __('Email');
|
|
543
|
+
if (url.startsWith('tel:')) return __('Phone');
|
|
544
|
+
try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url; }
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** `core/latest-entries`: the entries as a list with excerpts, a grid of cards or titles alone. */
|
|
548
|
+
function latestEntries(block: RenderedBlock): TemplateResult {
|
|
549
|
+
const entries = block.entries ?? [];
|
|
550
|
+
const layout = typeof block.data.layout === 'string' ? block.data.layout : 'list';
|
|
551
|
+
const showImage = block.data.showImage !== false;
|
|
552
|
+
const showDate = block.data.showDate !== false;
|
|
553
|
+
if (!entries.length) return html`<p class="my-4 text-sm text-muted-foreground">${__('Nothing published yet.')}</p>`;
|
|
554
|
+
if (layout === 'titles') return html`<ul class="my-4 space-y-1.5">${entries.map(entry => html`<li class="flex items-baseline justify-between gap-3">
|
|
555
|
+
<a href=${entry.url ?? '#'} class="text-primary hover:underline">${entry.title}</a>${showDate && entry.date ? html`<time class="shrink-0 text-xs text-muted-foreground">${entry.date}</time>` : null}</li>`)}</ul>`;
|
|
556
|
+
if (layout === 'grid') {
|
|
557
|
+
const columns = Math.min(Math.max(Number(block.data.columns) || 3, 1), 4);
|
|
558
|
+
return html`<div class="cms-grid my-6" data-gap="medium" style=${`--cms-cols-lg: ${columns}; --cms-cols-md: ${Math.min(columns, 2)}; --cms-cols-sm: 1`}>
|
|
559
|
+
${entries.map(entry => html`<article class="flex min-w-0 flex-col overflow-hidden rounded-lg border border-border bg-card">
|
|
560
|
+
${showImage && entry.image ? html`<a href=${entry.url ?? '#'} class="block">${image(entry.image, 'aspect-[4/3] w-full object-cover', `(min-width: 1024px) ${Math.round(1024 / columns)}px, 100vw`)}</a>` : null}
|
|
561
|
+
<div class="space-y-1.5 p-4">
|
|
562
|
+
<h3 class="text-base font-semibold"><a href=${entry.url ?? '#'} class="no-underline hover:text-primary">${entry.title}</a></h3>
|
|
563
|
+
${showDate && entry.date ? html`<time class="block text-xs text-muted-foreground">${entry.date}</time>` : null}
|
|
564
|
+
${entry.excerpt ? html`<p class="text-sm text-muted-foreground">${entry.excerpt}</p>` : null}
|
|
565
|
+
</div>
|
|
566
|
+
</article>`)}</div>`;
|
|
567
|
+
}
|
|
568
|
+
return html`<div class="my-6 space-y-6">${entries.map(entry => html`<article class="grid gap-4 sm:grid-cols-[8rem_minmax(0,1fr)]">
|
|
569
|
+
${showImage && entry.image ? html`<a href=${entry.url ?? '#'} class="block overflow-hidden rounded-md">${image(entry.image, 'aspect-[4/3] w-full object-cover', '(min-width: 640px) 8rem, 100vw')}</a>` : showImage ? html`<span class="hidden sm:block"></span>` : null}
|
|
570
|
+
<div class=${showImage ? 'space-y-1' : 'space-y-1 sm:col-span-2'}>
|
|
571
|
+
<h3 class="text-lg font-semibold"><a href=${entry.url ?? '#'} class="no-underline hover:text-primary">${entry.title}</a></h3>
|
|
572
|
+
${showDate && entry.date ? html`<time class="block text-xs text-muted-foreground">${entry.date}${entry.authors.length ? ` · ${entry.authors.map(author => author.name).join(', ')}` : ''}</time>` : null}
|
|
573
|
+
${entry.excerpt ? html`<p class="text-sm leading-6 text-muted-foreground">${entry.excerpt}</p>` : null}
|
|
574
|
+
</div>
|
|
575
|
+
</article>`)}</div>`;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/** Columns' track spans out of twelve: a declared `span`, the rest shared equally. */
|
|
579
|
+
export function columnSpans(columns: readonly RenderedBlock[]): number[] {
|
|
580
|
+
const declared = columns.map(column => Number.isInteger(column.data.span) ? Math.min(Math.max(column.data.span as number, 1), 12) : 0);
|
|
581
|
+
const auto = declared.filter(span => !span).length;
|
|
582
|
+
const share = auto ? Math.max(Math.floor((12 - declared.reduce((sum, span) => sum + span, 0)) / auto), 1) : 0;
|
|
583
|
+
return declared.map(span => span || share);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** A block of a core type, or of a plugin type through its `ui.ts` component. Unknown types render nothing. */
|
|
587
|
+
export function coreBlock(block: RenderedBlock, helpers: ThemeHelpers, state?: Pick<ThemeRenderState, 'site'>): TemplateResult | null {
|
|
588
|
+
const text = (name: string) => typeof block.data[name] === 'string' ? block.data[name] as string : '';
|
|
589
|
+
const children = block.children ?? [];
|
|
590
|
+
switch (block.type) {
|
|
591
|
+
// The site's logo (the block's own image, else Settings → General's) or its title, linked home.
|
|
592
|
+
case 'core/site-logo': {
|
|
593
|
+
const site = state?.site;
|
|
594
|
+
if (!site) return null;
|
|
595
|
+
const own = block.media[text('image')];
|
|
596
|
+
const showTitle = block.data.showTitle === true || (!own && !site.logo);
|
|
597
|
+
const picture = own ? image(own, 'cms-site-logo-image', '12rem') : site.logo ? html`<img src=${site.logo} alt=${showTitle ? '' : site.title} class="cms-site-logo-image">` : null;
|
|
598
|
+
return html`<a href=${site.homeUrl} class="cms-site-logo" data-size=${text('size') || 'medium'} rel="home">${picture}
|
|
599
|
+
${showTitle || (block.data.showTagline === true && site.tagline) ? html`<span class="cms-site-logo-text">${showTitle ? html`<span class="cms-site-logo-title">${site.title}</span>` : null}
|
|
600
|
+
${block.data.showTagline === true && site.tagline ? html`<span class="cms-site-logo-tagline">${site.tagline}</span>` : null}</span>` : null}</a>`;
|
|
601
|
+
}
|
|
602
|
+
case 'core/search': return helpers.search({ placeholder: text('placeholder'), style: text('style'), suggest: block.data.suggest !== false });
|
|
603
|
+
// Text with block references renders its runs and blocks; the HTML alone otherwise.
|
|
604
|
+
case 'core/paragraph': return block.content?.text ? helpers.content(block.content.text) : html`<div class=${PROSE}>${unsafeHTML(block.html.text ?? '')}</div>`;
|
|
605
|
+
case 'core/heading': {
|
|
606
|
+
const level = text('level') || 'h2';
|
|
607
|
+
const words = accented(text('text'));
|
|
608
|
+
return level === 'h3' ? html`<h3 class="mt-6 text-xl font-semibold">${words}</h3>`
|
|
609
|
+
: level === 'h4' ? html`<h4 class="mt-4 text-lg font-semibold">${words}</h4>`
|
|
610
|
+
: level === 'h1' ? html`<h1 class="mt-8 text-4xl font-bold tracking-tight">${words}</h1>`
|
|
611
|
+
: html`<h2 class="mt-8 text-2xl font-semibold">${words}</h2>`;
|
|
612
|
+
}
|
|
613
|
+
case 'core/image': {
|
|
614
|
+
const media = block.media[text('image')];
|
|
615
|
+
const img = image(media, 'w-full rounded-lg');
|
|
616
|
+
return html`<figure class="my-6">${text('link') ? html`<a href=${safeLink(text('link'))}>${img}</a>` : img}
|
|
617
|
+
${text('caption') || media?.caption ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption') || media?.caption}</figcaption>` : null}</figure>`;
|
|
618
|
+
}
|
|
619
|
+
case 'core/gallery': {
|
|
620
|
+
const ids = Array.isArray(block.data.images) ? block.data.images as string[] : [];
|
|
621
|
+
const columns = Math.min(Math.max(Number(block.data.columns) || 3, 1), 6);
|
|
622
|
+
// Logos: whole images at one height, grey until hovered, as a wall of clients or partners.
|
|
623
|
+
if (text('layout') === 'logos') return html`<div class="cms-logos my-6" style=${`--cms-logo-columns: ${columns}`}>${ids.map(id => block.media[id] ? html`<div class="cms-logo">${image(block.media[id], 'cms-logo-image', `${Math.round(100 / columns)}vw`)}</div>` : null)}</div>`;
|
|
624
|
+
// A lightbox makes each image a link to the file, which the script opens large; the link works without it.
|
|
625
|
+
const lightbox = block.data.lightbox === true;
|
|
626
|
+
const sizes = `(min-width: 768px) ${Math.round(768 / columns)}px, ${Math.round(100 / columns)}vw`;
|
|
627
|
+
const tile = (id: string, className: string) => {
|
|
628
|
+
const media = block.media[id];
|
|
629
|
+
if (!media) return null;
|
|
630
|
+
return lightbox ? html`<a href=${media.url} class="cms-gallery-link" data-cms-lightbox="image" data-caption=${ifDefined(media.caption || undefined)}>${image(media, className, sizes)}</a>` : image(media, className, sizes);
|
|
631
|
+
};
|
|
632
|
+
// Masonry: whole images in columns, each at its own height.
|
|
633
|
+
if (text('layout') === 'masonry') return html`<div class="cms-masonry my-6" style=${`--cms-masonry-columns: ${columns}`} ref=${lightbox ? enhanceLightbox : unenhanced}>${ids.map(id => tile(id, 'cms-masonry-image'))}</div>`;
|
|
634
|
+
return html`<div class="my-6 grid gap-3" style=${`grid-template-columns: repeat(${columns}, minmax(0, 1fr))`} ref=${lightbox ? enhanceLightbox : unenhanced}>
|
|
635
|
+
${ids.map(id => tile(id, 'aspect-square w-full rounded-md object-cover'))}</div>`;
|
|
636
|
+
}
|
|
637
|
+
case 'core/quote': return html`<blockquote class="my-6 border-l-4 border-primary pl-4">
|
|
638
|
+
<p class="text-lg italic">${text('text')}</p>${text('citation') ? html`<cite class="mt-2 block text-sm not-italic text-muted-foreground">— ${text('citation')}</cite>` : null}</blockquote>`;
|
|
639
|
+
case 'core/list': {
|
|
640
|
+
const items = Array.isArray(block.data.items) ? block.data.items as string[] : [];
|
|
641
|
+
return block.data.ordered === true ? html`<ol class="my-4 list-decimal space-y-1 pl-6">${items.map(item => html`<li>${item}</li>`)}</ol>`
|
|
642
|
+
: html`<ul class="my-4 list-disc space-y-1 pl-6">${items.map(item => html`<li>${item}</li>`)}</ul>`;
|
|
643
|
+
}
|
|
644
|
+
// Saved only by people allowed to post HTML (`cms:html`), so it renders as written.
|
|
645
|
+
case 'core/html': return html`${unsafeHTML(text('html'))}`;
|
|
646
|
+
case 'core/code': return html`<pre class="cms-code my-4 overflow-x-auto rounded-md bg-muted p-4 text-sm"><code data-language=${text('language')}>${unsafeHTML(highlightCode(text('code'), text('language')))}</code></pre>`;
|
|
647
|
+
case 'core/table': {
|
|
648
|
+
const rows = text('rows').split('\n').map(line => line.trim()).filter(Boolean).map(line => line.replace(/^\||\|$/g, '').split('|').map(cell => cell.trim()));
|
|
649
|
+
if (!rows.length) return null;
|
|
650
|
+
const width = Math.max(...rows.map(row => row.length));
|
|
651
|
+
const header = block.data.header !== false;
|
|
652
|
+
const cells = (row: string[], tag: 'th' | 'td') => Array.from({ length: width }, (_, index) => tag === 'th' ? html`<th scope="col">${row[index] ?? ''}</th>` : html`<td>${row[index] ?? ''}</td>`);
|
|
653
|
+
return html`<figure class="cms-table my-6"><table>
|
|
654
|
+
${header ? html`<thead><tr>${cells(rows[0]!, 'th')}</tr></thead>` : null}
|
|
655
|
+
<tbody>${(header ? rows.slice(1) : rows).map(row => html`<tr>${cells(row, 'td')}</tr>`)}</tbody></table>
|
|
656
|
+
${text('caption') ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption')}</figcaption>` : null}</figure>`;
|
|
657
|
+
}
|
|
658
|
+
case 'core/file': {
|
|
659
|
+
const media = block.media[text('file')];
|
|
660
|
+
if (!media) return null;
|
|
661
|
+
const label = text('label') || media.name;
|
|
662
|
+
const kind = media.contentType.split('/').pop()?.toUpperCase().replace(/^VND\..*?\./, '').slice(0, 12) ?? '';
|
|
663
|
+
return html`<p class="cms-file my-4"><a href=${media.url} ?download=${block.data.download !== false} class="inline-flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm font-medium no-underline hover:bg-muted">
|
|
664
|
+
<span aria-hidden="true">⬇</span><span>${label}</span>${block.data.showSize !== false ? html`<span class="text-xs text-muted-foreground">${kind} · ${formatBytes(media.size)}</span>` : null}</a></p>`;
|
|
665
|
+
}
|
|
666
|
+
case 'core/button': {
|
|
667
|
+
const style = text('style');
|
|
668
|
+
const large = text('size') === 'large';
|
|
669
|
+
const glyph = siteIcon(text('icon'), { class: large ? 'size-5' : 'size-4' });
|
|
670
|
+
// A text link has no box; the others are buttons of one shape.
|
|
671
|
+
const look = style === 'link' ? `${large ? 'text-base' : 'text-sm'} text-primary hover:underline`
|
|
672
|
+
: `${large ? 'px-7 py-3.5 text-base' : 'px-5 py-2.5 text-sm'} ${style === 'outline' ? 'border border-border text-foreground hover:bg-muted'
|
|
673
|
+
: style === 'light' ? 'bg-white text-neutral-900 hover:bg-neutral-100' : 'bg-primary text-primary-foreground hover:opacity-90'}`;
|
|
674
|
+
return html`<div class="cms-button my-6" data-style=${style || 'primary'} data-size=${large ? 'large' : 'medium'}><a href=${safeLink(text('url'))} class=${`inline-flex items-center rounded-md font-medium no-underline ${look}${glyph ? ' gap-2' : ''}`}>${text('label')}${glyph}</a></div>`;
|
|
675
|
+
}
|
|
676
|
+
case 'core/embed': {
|
|
677
|
+
const embed = embedUrl(text('url'));
|
|
678
|
+
if (!embed) return null;
|
|
679
|
+
const shape = embed.aspect === 'video' ? 'aspect-video' : embed.aspect === 'wide' ? 'h-[352px]' : embed.aspect === 'short' ? 'h-[166px]' : 'h-[650px] max-w-[550px] mx-auto';
|
|
680
|
+
return html`<figure class="my-6"><div class=${`${shape} overflow-hidden rounded-lg bg-muted`}>
|
|
681
|
+
<iframe src=${embed.src} title=${text('caption') || embed.title} class="h-full w-full" loading="lazy" allow="encrypted-media; picture-in-picture; clipboard-write" allowfullscreen referrerpolicy="strict-origin-when-cross-origin" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-presentation"></iframe></div>
|
|
682
|
+
${text('caption') ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption')}</figcaption>` : null}</figure>`;
|
|
683
|
+
}
|
|
684
|
+
case 'core/video': {
|
|
685
|
+
// A file of the library, or one on another server by its address.
|
|
686
|
+
const file = block.media[text('video')];
|
|
687
|
+
const address = /^https:\/\/\S+$/.test(text('url')) ? text('url') : '';
|
|
688
|
+
const media = file ?? (address ? { url: address, width: null, height: null, caption: '' } : undefined);
|
|
689
|
+
if (!media) return null;
|
|
690
|
+
const poster = block.media[text('poster')];
|
|
691
|
+
const captions = block.media[text('captions')];
|
|
692
|
+
const autoplay = block.data.autoplay === true;
|
|
693
|
+
// In a lightbox the page shows the poster with a play button; the link plays the file without the script.
|
|
694
|
+
if (block.data.lightbox === true) return html`<figure class="cms-video-lightbox my-6" ref=${enhanceLightbox}>
|
|
695
|
+
<a href=${media.url} class="cms-video-poster" data-cms-lightbox="video" aria-label=${text('caption') || media.caption || __('Play the video')}>
|
|
696
|
+
${poster ? image(poster, 'cms-video-poster-image') : html`<span class="cms-video-poster-image"></span>`}
|
|
697
|
+
<span class="cms-video-play" aria-hidden="true"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"></path></svg></span></a>
|
|
698
|
+
${text('caption') || media.caption ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption') || media.caption}</figcaption>` : null}</figure>`;
|
|
699
|
+
return html`<figure class="my-6"><video src=${media.url} class="w-full rounded-lg bg-black" poster=${ifDefined(poster?.url)} preload=${preloadOf(text('preload'))}
|
|
700
|
+
?controls=${block.data.controls !== false} ?autoplay=${autoplay} ?loop=${block.data.loop === true} ?muted=${autoplay || block.data.muted === true} ?playsinline=${autoplay}
|
|
701
|
+
width=${ifDefined(media.width ?? undefined)} height=${ifDefined(media.height ?? undefined)}>
|
|
702
|
+
${captions ? html`<track kind="captions" src=${captions.url} default>` : null}
|
|
703
|
+
<a href=${media.url}>${text('caption') || media.caption || 'Download the video'}</a></video>
|
|
704
|
+
${text('caption') || media.caption ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption') || media.caption}</figcaption>` : null}</figure>`;
|
|
705
|
+
}
|
|
706
|
+
case 'core/audio': {
|
|
707
|
+
const media = block.media[text('audio')];
|
|
708
|
+
if (!media) return null;
|
|
709
|
+
return html`<figure class="my-6"><audio src=${media.url} class="w-full" controls preload=${preloadOf(text('preload'))} ?autoplay=${block.data.autoplay === true} ?loop=${block.data.loop === true}>
|
|
710
|
+
<a href=${media.url}>${text('caption') || media.caption || 'Download the audio'}</a></audio>
|
|
711
|
+
${text('caption') || media.caption ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption') || media.caption}</figcaption>` : null}</figure>`;
|
|
712
|
+
}
|
|
713
|
+
case 'core/richtext': return helpers.content(block.content?.text ?? []);
|
|
714
|
+
case 'core/divider': {
|
|
715
|
+
const vertical = text('orientation') === 'vertical';
|
|
716
|
+
const style = `--cms-divider-color: ${dividerColor(text('color'))}`;
|
|
717
|
+
if (vertical) return html`<div class="cms-divider cms-divider-vertical" data-thickness=${text('thickness') || 'thin'} data-width=${text('width') || 'full'} style=${style} role="separator" aria-orientation="vertical"></div>`;
|
|
718
|
+
return text('text')
|
|
719
|
+
? html`<div class="cms-divider cms-divider-text" data-thickness=${text('thickness') || 'thin'} data-width=${text('width') || 'full'} style=${style} role="separator"><span>${text('text')}</span></div>`
|
|
720
|
+
: html`<hr class="cms-divider" data-thickness=${text('thickness') || 'thin'} data-width=${text('width') || 'full'} style=${style}>`;
|
|
721
|
+
}
|
|
722
|
+
case 'core/card': {
|
|
723
|
+
const media = block.media[text('image')];
|
|
724
|
+
const url = text('url');
|
|
725
|
+
const title = text('title');
|
|
726
|
+
const picture = media ? image(media, 'h-full w-full object-cover') : null;
|
|
727
|
+
// Behind the text, the image is the card's ground: the title's link covers the whole tile (cms/blocks.css).
|
|
728
|
+
const overlay = !!media && text('layout') === 'overlay';
|
|
729
|
+
const framed = picture ? html`<div class="cms-card-media">${url && !text('linkLabel') && !overlay ? html`<a href=${safeLink(url)}>${picture}</a>` : picture}</div>` : null;
|
|
730
|
+
// An icon stands in for the image: the icon box and the feature of page builders. Over an image it is a badge.
|
|
731
|
+
const glyph = (!media || overlay) && text('icon') ? siteIcon(text('icon'), { class: 'size-8' }) : null;
|
|
732
|
+
// Without an image, the position is the icon's: beside the text, it makes a contact line or a feature row.
|
|
733
|
+
const beside = !media && glyph && (text('layout') === 'left' || text('layout') === 'right') ? text('layout') : undefined;
|
|
734
|
+
return html`<div class="cms-card" data-layout=${media ? text('layout') || 'top' : 'none'} data-icon=${ifDefined(beside)} data-style=${text('style') === 'plain' ? 'plain' : 'boxed'}>
|
|
735
|
+
${framed}
|
|
736
|
+
<div class="cms-card-body">
|
|
737
|
+
${glyph ? html`<div class="cms-card-icon">${glyph}</div>` : null}
|
|
738
|
+
${title ? html`<h3 class="text-lg font-semibold">${url && !text('linkLabel') ? html`<a href=${safeLink(url)} class="no-underline hover:text-primary">${title}</a>` : title}</h3>` : null}
|
|
739
|
+
${block.html.text ? html`<div class=${`${PROSE} text-sm [&_p]:my-2`}>${unsafeHTML(block.html.text)}</div>` : null}
|
|
740
|
+
${url && text('linkLabel') ? html`<p class="mt-3"><a href=${safeLink(url)} class="text-sm font-medium text-primary hover:underline">${text('linkLabel')} →</a></p>` : null}
|
|
741
|
+
</div>
|
|
742
|
+
</div>`;
|
|
743
|
+
}
|
|
744
|
+
case 'core/carousel': {
|
|
745
|
+
// Slides of blocks when the carousel holds any, else its images.
|
|
746
|
+
const slides = children.filter(child => child.type === 'core/slide');
|
|
747
|
+
const ids = slides.length ? [] : Array.isArray(block.data.images) ? (block.data.images as string[]).filter(id => block.media[id]) : [];
|
|
748
|
+
const count = slides.length || ids.length;
|
|
749
|
+
if (!count) return null;
|
|
750
|
+
const captions = block.data.captions !== false;
|
|
751
|
+
const perView = Math.min(Math.max(Math.round(Number(block.data.perView) || 1), 1), 4);
|
|
752
|
+
// Thumbnails stand in for the dots of an image carousel.
|
|
753
|
+
const thumbnails = block.data.thumbnails === true && ids.length > 1;
|
|
754
|
+
const items = slides.length
|
|
755
|
+
? slides.map((slide, index) => html`<div class="cms-carousel-slide cms-carousel-blockslide" id=${`${block._id}-slide-${index + 1}`} aria-roledescription="slide" aria-label=${`${index + 1} / ${count}`}>${helpers.block(slide)}</div>`)
|
|
756
|
+
: ids.map((id, index) => html`<figure class="cms-carousel-slide" id=${`${block._id}-slide-${index + 1}`} aria-roledescription="slide" aria-label=${`${index + 1} / ${count}`}>
|
|
757
|
+
${image(block.media[id], 'cms-carousel-image', '(min-width: 1024px) 1024px, 100vw')}
|
|
758
|
+
${captions && block.media[id]?.caption ? html`<figcaption class="cms-carousel-caption">${block.media[id]!.caption}</figcaption>` : null}
|
|
759
|
+
</figure>`);
|
|
760
|
+
return html`<div class="cms-carousel my-6" data-aspect=${text('aspect') || 'video'} data-per-view=${ifDefined(perView > 1 ? String(perView) : undefined)} style=${ifDefined(perView > 1 ? `--cms-per-view: ${perView}` : undefined)} data-autoplay=${block.data.autoplay === true ? 'true' : 'false'} data-interval=${String(Math.min(Math.max(Number(block.data.interval) || 5, 2), 30))}
|
|
761
|
+
role="region" aria-roledescription="carousel" aria-label=${slides.length ? __('Slides') : __('Image carousel')} ref=${enhanceCarousel}>
|
|
762
|
+
<div class="cms-carousel-track" tabindex="0">${items}</div>
|
|
763
|
+
${count > 1 ? html`<button type="button" class="cms-carousel-arrow cms-carousel-prev" data-direction="-1" aria-label=${__('Previous')}>‹</button>
|
|
764
|
+
<button type="button" class="cms-carousel-arrow cms-carousel-next" data-direction="1" aria-label=${__('Next')}>›</button>
|
|
765
|
+
${thumbnails
|
|
766
|
+
? html`<div class="cms-carousel-thumbs" role="tablist">${ids.map((id, index) => html`<button type="button" role="tab" class="cms-carousel-thumb" aria-label=${`${__('Slide')} ${index + 1}`} aria-selected=${index === 0 ? 'true' : 'false'} data-index=${String(index)}>${image({ ...block.media[id]!, priority: false, placeholder: null }, '', '10rem')}</button>`)}</div>`
|
|
767
|
+
: html`<div class="cms-carousel-dots" role="tablist">${Array.from({ length: count }, (_, index) => html`<button type="button" role="tab" aria-label=${`${__('Slide')} ${index + 1}`} aria-selected=${index === 0 ? 'true' : 'false'} data-index=${String(index)}></button>`)}</div>`}` : null}
|
|
768
|
+
</div>`;
|
|
769
|
+
}
|
|
770
|
+
case 'core/slide': return html`<div class="cms-slide" data-valign=${text('valign') || 'center'}>${children.map(child => helpers.block(child))}</div>`;
|
|
771
|
+
case 'core/answer': return html`<aside class="cms-answer my-6 rounded-lg border border-border bg-muted/40 p-4" aria-label=${text('label') || __('Quick answer')}>
|
|
772
|
+
${text('label') ? html`<p class="mb-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">${text('label')}</p>` : null}
|
|
773
|
+
<div class=${`${PROSE} text-lg [&_p]:my-2`}>${block.content?.text ? helpers.content(block.content.text) : unsafeHTML(block.html.text ?? '')}</div></aside>`;
|
|
774
|
+
case 'core/faq': return html`<section class="cms-faq my-8 divide-y divide-border border-y border-border">${children.map(child => helpers.block(block.data.open === false ? { ...child, data: { ...child.data, open: false } } : child))}</section>`;
|
|
775
|
+
case 'core/faq-item': return html`<details class="cms-faq-item group py-3" ?open=${block.data.open !== false}>
|
|
776
|
+
<summary class="cursor-pointer list-none text-lg font-semibold"><h3 class="inline">${text('question')}</h3></summary>
|
|
777
|
+
<div class=${`${PROSE} mt-2 [&_p]:my-2`}>${unsafeHTML(block.html.answer ?? '')}</div></details>`;
|
|
778
|
+
// Side by side, each step is a column under its number; they stack on phones (cms/blocks.css).
|
|
779
|
+
case 'core/steps': if (text('layout') === 'row') return html`<ol class="cms-steps cms-steps-row my-8" style=${`--cms-step-count: ${Math.min(Math.max(children.length, 1), 6)}`}>${children.map((child, index) => html`<li data-step=${String(index + 1)}>
|
|
780
|
+
<span class="cms-step-number" aria-hidden="true">${index + 1}</span>${helpers.block(child)}</li>`)}</ol>`;
|
|
781
|
+
else return html`<ol class="cms-steps my-8 space-y-6 border-l-2 border-border pl-6">${children.map((child, index) => html`<li class="relative" data-step=${String(index + 1)}>
|
|
782
|
+
<span class="absolute -left-[2.1rem] flex size-7 items-center justify-center rounded-full bg-primary text-xs font-semibold text-primary-foreground" aria-hidden="true">${index + 1}</span>${helpers.block(child)}</li>`)}</ol>`;
|
|
783
|
+
case 'core/step': return html`<div class="cms-step"><h3 class="text-lg font-semibold">${text('title')}</h3>${block.html.text ? html`<div class=${`${PROSE} [&_p]:my-2`}>${unsafeHTML(block.html.text)}</div>` : null}</div>`;
|
|
784
|
+
case 'core/claim': {
|
|
785
|
+
const source = text('sourceUrl') ? html`<a href=${safeLink(text('sourceUrl'))} rel="noopener" class="text-primary hover:underline">${text('sourceName')}</a>` : text('sourceName');
|
|
786
|
+
return html`<figure class="cms-claim my-6 rounded-lg border-l-4 border-primary bg-muted/40 p-4">
|
|
787
|
+
<blockquote class=${text('kind') === 'quote' ? 'text-lg italic' : 'text-2xl font-semibold'}>${text('text')}</blockquote>
|
|
788
|
+
<figcaption class="mt-2 text-sm text-muted-foreground">${__('Source')}: <cite class="not-italic">${source}</cite>${text('date') ? html`, ${text('date')}` : null}</figcaption></figure>`;
|
|
789
|
+
}
|
|
790
|
+
case 'core/definition': return html`<dl class="cms-definition my-6 rounded-lg border border-border p-4"><dt class="text-lg font-semibold">${text('term')}</dt><dd class=${`${PROSE} mt-1 [&_p]:my-1`}>${unsafeHTML(block.html.definition ?? '')}</dd></dl>`;
|
|
791
|
+
case 'core/compare': {
|
|
792
|
+
// Each pair is a child, drawn with the block's shape, labels and starting point; thumbnails pick among several.
|
|
793
|
+
const pairs = children.filter(child => child.type === 'core/compare-item' && child.media[String(child.data.before ?? '')] && child.media[String(child.data.after ?? '')]);
|
|
794
|
+
if (!pairs.length) return null;
|
|
795
|
+
const start = Math.min(Math.max(Math.round(Number(block.data.start ?? 50)), 0), 100);
|
|
796
|
+
const shared = { beforeLabel: block.data.beforeLabel ?? __('Before'), afterLabel: block.data.afterLabel ?? __('After'), start: Number.isFinite(start) ? start : 50 };
|
|
797
|
+
return html`<div class="cms-compare my-6" data-aspect=${text('aspect') || 'video'} ref=${enhanceCompare}>
|
|
798
|
+
${pairs.map((pair, index) => html`<div class="cms-compare-pair" data-active=${ifDefined(index === 0 ? '' : undefined)}>${helpers.block({ ...pair, data: { ...pair.data, ...shared } })}</div>`)}
|
|
799
|
+
${pairs.length > 1 ? html`<div class="cms-compare-thumbs" role="tablist" aria-label=${__('Pairs')}>${pairs.map((pair, index) => html`<button type="button" role="tab" class="cms-compare-thumb" aria-label=${String(pair.data.caption || `${index + 1} / ${pairs.length}`)} aria-selected=${index === 0 ? 'true' : 'false'} data-index=${String(index)}>${image({ ...pair.media[String(pair.data.before)]!, priority: false, placeholder: null }, '', '10rem')}</button>`)}</div>` : null}
|
|
800
|
+
</div>`;
|
|
801
|
+
}
|
|
802
|
+
case 'core/compare-item': {
|
|
803
|
+
const before = block.media[text('before')];
|
|
804
|
+
const after = block.media[text('after')];
|
|
805
|
+
if (!before || !after) return null;
|
|
806
|
+
const start = Math.min(Math.max(Number(block.data.start ?? 50) || 0, 0), 100);
|
|
807
|
+
// The image after lies under the image before, which is clipped at the handle. The range input is the control: it takes the pointer and the keyboard.
|
|
808
|
+
return html`<figure class="cms-compare-figure"><div class="cms-compare-stage" style=${`--cms-compare: ${start}%`}>
|
|
809
|
+
${image(after, 'cms-compare-image', '(min-width: 1024px) 1024px, 100vw')}
|
|
810
|
+
${image({ ...before, placeholder: null }, 'cms-compare-image cms-compare-before', '(min-width: 1024px) 1024px, 100vw')}
|
|
811
|
+
${text('beforeLabel') ? html`<span class="cms-compare-label" data-side="before">${text('beforeLabel')}</span>` : null}
|
|
812
|
+
${text('afterLabel') ? html`<span class="cms-compare-label" data-side="after">${text('afterLabel')}</span>` : null}
|
|
813
|
+
<span class="cms-compare-handle" aria-hidden="true"><span class="cms-compare-knob"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5l-7 7 7 7M15 5l7 7-7 7"></path></svg></span></span>
|
|
814
|
+
<input type="range" class="cms-compare-range" min="0" max="100" value=${String(start)} aria-label=${__('How much of the image before shows')}>
|
|
815
|
+
</div>${text('caption') ? html`<figcaption class="mt-2 text-center text-sm text-muted-foreground">${text('caption')}</figcaption>` : null}</figure>`;
|
|
816
|
+
}
|
|
817
|
+
case 'core/latest-entries': return latestEntries(block);
|
|
818
|
+
case 'core/languages': return helpers.languages({ style: text('style'), layout: text('layout') });
|
|
819
|
+
case 'core/navigation': return helpers.menu(text('location') || 'primary', { style: text('style'), motion: text('motion'), mobile: text('mobile') || undefined, collapse: text('collapse') });
|
|
820
|
+
case 'core/meta': return null;
|
|
821
|
+
// Section blocks: the leaf widgets of page builders, placed in columns and grids.
|
|
822
|
+
case 'core/spacer': return html`<div class="cms-spacer" data-size=${text('size') || 'medium'} aria-hidden="true"></div>`;
|
|
823
|
+
case 'core/tabs': {
|
|
824
|
+
const tabs = children.filter(child => child.type === 'core/tab');
|
|
825
|
+
if (!tabs.length) return null;
|
|
826
|
+
// The first panel is active before any script runs; without scripting every panel shows under its title (cms/blocks.css).
|
|
827
|
+
return html`<div class="cms-tabs my-6" ref=${enhanceTabs}>
|
|
828
|
+
<div class="cms-tablist" role="tablist">${tabs.map((tab, index) => html`<button type="button" role="tab" class="cms-tab" id=${`${block._id}-tab-${index + 1}`} aria-controls=${`${block._id}-panel-${index + 1}`} aria-selected=${index === 0 ? 'true' : 'false'} tabindex=${index === 0 ? 0 : -1}>${siteIcon(typeof tab.data.icon === 'string' ? tab.data.icon : '', { class: 'size-4' })}<span>${typeof tab.data.label === 'string' ? tab.data.label : ''}</span></button>`)}</div>
|
|
829
|
+
${tabs.map((tab, index) => html`<section class="cms-tabpanel" role="tabpanel" id=${`${block._id}-panel-${index + 1}`} aria-labelledby=${`${block._id}-tab-${index + 1}`} data-active=${ifDefined(index === 0 ? '' : undefined)} tabindex="0">
|
|
830
|
+
<h3 class="cms-tabpanel-title">${typeof tab.data.label === 'string' ? tab.data.label : ''}</h3>${helpers.block(tab)}</section>`)}
|
|
831
|
+
</div>`;
|
|
832
|
+
}
|
|
833
|
+
case 'core/tab': return html`<div class="cms-tab-content">${children.map(child => helpers.block(child))}</div>`;
|
|
834
|
+
case 'core/accordion': return html`<div class="cms-accordion my-6" id=${`${block._id}-accordion`} data-single=${block.data.single === true ? 'true' : 'false'} ref=${enhanceAccordion}>${children.map(child => helpers.block(child))}</div>`;
|
|
835
|
+
case 'core/accordion-item': return html`<details class="cms-accordion-item" ?open=${block.data.open === true}>
|
|
836
|
+
<summary class="cms-accordion-summary">${text('label')}<span class="cms-accordion-caret" aria-hidden="true"></span></summary>
|
|
837
|
+
<div class="cms-accordion-body">${children.map(child => helpers.block(child))}</div></details>`;
|
|
838
|
+
case 'core/icon-list': return html`<ul class="cms-icon-list my-4" data-size=${text('size') || 'medium'} style=${`--cms-icon-columns: ${Math.min(Math.max(Number(block.data.columns) || 1, 1), 3)}`}>${children.map(child => helpers.block(child))}</ul>`;
|
|
839
|
+
case 'core/icon-item': {
|
|
840
|
+
const url = text('url');
|
|
841
|
+
return html`<li class="cms-icon-item">${siteIcon(text('icon') || 'check-circle', { class: 'cms-icon-item-icon' }) ?? siteIcon('check-circle', { class: 'cms-icon-item-icon' })}${url ? html`<a href=${safeLink(url)}>${text('text')}</a>` : html`<span>${text('text')}</span>`}</li>`;
|
|
842
|
+
}
|
|
843
|
+
case 'core/testimonial': {
|
|
844
|
+
const avatar = block.media[text('avatar')];
|
|
845
|
+
const rating = Math.min(Math.max(Math.round(Number(block.data.rating) || 0), 0), 5);
|
|
846
|
+
const url = text('url');
|
|
847
|
+
return html`<figure class="cms-testimonial my-6">
|
|
848
|
+
${rating ? html`<div class="cms-rating" role="img" aria-label=${`${rating} / 5`}>${[1, 2, 3, 4, 5].map(star => html`<span class="cms-rating-star" data-filled=${star <= rating ? 'true' : 'false'}>★</span>`)}</div>` : null}
|
|
849
|
+
<blockquote class="cms-testimonial-quote">${block.html.text ? html`<div class=${`${PROSE} [&_p]:my-1`}>${unsafeHTML(block.html.text)}</div>` : text('text')}</blockquote>
|
|
850
|
+
<figcaption class="cms-testimonial-author">${avatar ? image(avatar, 'cms-testimonial-avatar', '48px') : null}
|
|
851
|
+
<div><div class="cms-testimonial-name">${url ? html`<a href=${safeLink(url)} rel="noopener">${text('name')}</a>` : text('name')}</div>${text('role') ? html`<div class="cms-testimonial-role">${text('role')}</div>` : null}</div></figcaption>
|
|
852
|
+
</figure>`;
|
|
853
|
+
}
|
|
854
|
+
case 'core/stat': return html`<div class="cms-stat my-6" data-animate=${block.data.animate === false ? 'false' : 'true'} ref=${enhanceStat}>
|
|
855
|
+
<p class="cms-stat-value">${text('prefix') ? html`<span class="cms-stat-prefix">${text('prefix')}</span>` : null}<span class="cms-stat-number" data-value=${text('value')}>${text('value')}</span>${text('suffix') ? html`<span class="cms-stat-suffix">${text('suffix')}</span>` : null}</p>
|
|
856
|
+
${text('label') ? html`<p class="cms-stat-label">${text('label')}</p>` : null}</div>`;
|
|
857
|
+
case 'core/pricing': {
|
|
858
|
+
const features = Array.isArray(block.data.features) ? (block.data.features as unknown[]).filter((entry): entry is string => typeof entry === 'string' && entry.trim() !== '') : [];
|
|
859
|
+
const url = text('buttonUrl');
|
|
860
|
+
const label = text('buttonLabel');
|
|
861
|
+
return html`<div class="cms-pricing my-6" data-highlighted=${block.data.highlighted === true ? 'true' : 'false'}>
|
|
862
|
+
${text('badge') ? html`<span class="cms-pricing-badge">${text('badge')}</span>` : null}
|
|
863
|
+
<h3 class="cms-pricing-name">${text('name')}</h3>
|
|
864
|
+
<p class="cms-pricing-price"><span class="cms-pricing-amount">${text('price')}</span>${text('period') ? html` <span class="cms-pricing-period">${text('period')}</span>` : null}</p>
|
|
865
|
+
${text('description') ? html`<p class="cms-pricing-description">${text('description')}</p>` : null}
|
|
866
|
+
${features.length ? html`<ul class="cms-pricing-features">${features.map(feature => html`<li>${siteIcon('check-circle', { class: 'size-4' })}<span>${feature}</span></li>`)}</ul>` : null}
|
|
867
|
+
${url && label ? html`<p class="cms-pricing-action"><a href=${safeLink(url)} class=${`inline-flex items-center justify-center rounded-md px-5 py-2.5 text-sm font-medium no-underline ${block.data.highlighted === true ? 'bg-primary text-primary-foreground hover:opacity-90' : 'border border-border text-foreground hover:bg-muted'}`}>${label}</a></p>` : null}
|
|
868
|
+
</div>`;
|
|
869
|
+
}
|
|
870
|
+
case 'core/social-links': {
|
|
871
|
+
const links = Array.isArray(block.data.links) ? (block.data.links as unknown[]).filter((entry): entry is string => typeof entry === 'string' && entry.trim() !== '') : [];
|
|
872
|
+
if (!links.length) return null;
|
|
873
|
+
const labels = block.data.labels === true;
|
|
874
|
+
return html`<ul class="cms-social my-4" data-size=${text('size') || 'medium'} data-shape=${text('shape') || 'round'} data-labels=${labels ? 'true' : 'false'}>${links.map(url => {
|
|
875
|
+
const brand = block.icons?.[url];
|
|
876
|
+
const title = brand?.title ?? socialTitle(url);
|
|
877
|
+
const glyph = brand ? html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="cms-social-icon" aria-hidden="true" focusable="false"><path d=${brand.path}></path></svg>`
|
|
878
|
+
: siteIcon(url.startsWith('mailto:') ? 'letter' : url.startsWith('tel:') ? 'phone' : 'link', { class: 'cms-social-icon' });
|
|
879
|
+
const external = /^https?:/.test(url);
|
|
880
|
+
return html`<li><a class="cms-social-link" href=${safeLink(url)} style=${ifDefined(brand ? `--cms-brand: #${brand.hex}` : undefined)} title=${title} aria-label=${ifDefined(labels ? undefined : title)}
|
|
881
|
+
rel=${ifDefined(external ? 'me noopener' : undefined)} target=${ifDefined(external ? '_blank' : undefined)}>${glyph}${labels ? html`<span class="cms-social-label">${title}</span>` : null}</a></li>`;
|
|
882
|
+
})}</ul>`;
|
|
883
|
+
}
|
|
884
|
+
case 'core/map': {
|
|
885
|
+
// An address is looked up by Google Maps; an embed URL is shown as given, checked again here before it reaches an iframe.
|
|
886
|
+
const address = text('address').trim();
|
|
887
|
+
const given = text('url').trim();
|
|
888
|
+
const zoom = Math.min(Math.max(Math.round(Number(block.data.zoom) || 14), 1), 20);
|
|
889
|
+
const src = address ? `https://maps.google.com/maps?q=${encodeURIComponent(address)}&z=${zoom}&output=embed` : MAP_EMBED_URL.test(given) ? given : '';
|
|
890
|
+
if (!src) return null;
|
|
891
|
+
const caption = text('caption');
|
|
892
|
+
return html`<figure class="cms-map my-6" data-height=${text('height') || 'medium'}>
|
|
893
|
+
<iframe class="cms-map-frame" src=${src} title=${caption || address || __('Map')} loading="lazy" referrerpolicy="no-referrer" allowfullscreen></iframe>
|
|
894
|
+
${caption ? html`<figcaption class="cms-map-caption">${caption}</figcaption>` : null}
|
|
895
|
+
</figure>`;
|
|
896
|
+
}
|
|
897
|
+
// Layout blocks: CSS grid from cms/blocks.css, responding to the content root's width.
|
|
898
|
+
case 'core/notice': {
|
|
899
|
+
const kind = ['success', 'warning', 'danger'].includes(text('kind')) ? text('kind') : 'info';
|
|
900
|
+
const glyph = block.data.showIcon === false ? null : siteIcon(({ info: 'info-circle', success: 'check-circle', warning: 'danger-triangle', danger: 'close-circle' } as Record<string, string>)[kind]!, { class: 'cms-notice-icon' });
|
|
901
|
+
return html`<aside class="cms-notice my-6" data-kind=${kind} role="note">${glyph}<div class="cms-notice-body">${text('title') ? html`<p class="cms-notice-title">${text('title')}</p>` : null}${block.html.text ? html`<div class=${`${PROSE} text-sm [&_p]:my-1`}>${unsafeHTML(block.html.text)}</div>` : text('text')}</div></aside>`;
|
|
902
|
+
}
|
|
903
|
+
case 'core/countdown': {
|
|
904
|
+
// The server writes the first values; countdown.client.ts keeps them ticking and shows the end.
|
|
905
|
+
const until = Number(block.data.until);
|
|
906
|
+
if (!Number.isFinite(until) || until <= 0) return null;
|
|
907
|
+
const left = Math.max(0, Math.floor((until - Date.now()) / 1000));
|
|
908
|
+
const seconds = block.data.seconds !== false;
|
|
909
|
+
const units: [string, number, string][] = [['days', Math.floor(left / 86_400), __('Days')], ['hours', Math.floor((left % 86_400) / 3600), __('Hours')], ['minutes', Math.floor((left % 3600) / 60), __('Minutes')], ...(seconds ? [['seconds', left % 60, __('Seconds')] as [string, number, string]] : [])];
|
|
910
|
+
const over = left <= 0;
|
|
911
|
+
return html`<div class="cms-countdown my-6" data-until=${String(until)} ref=${enhanceCountdown}>
|
|
912
|
+
${text('label') ? html`<p class="cms-countdown-label">${text('label')}</p>` : null}
|
|
913
|
+
<div class="cms-countdown-units" ?hidden=${over}>${units.map(([unit, value, name]) => html`<div class="cms-countdown-unit"><span class="cms-countdown-value" data-unit=${unit}>${unit === 'days' ? String(value) : String(value).padStart(2, '0')}</span><span class="cms-countdown-name">${name}</span></div>`)}</div>
|
|
914
|
+
<p class="cms-countdown-done" ?hidden=${!over}>${text('done')}</p>
|
|
915
|
+
</div>`;
|
|
916
|
+
}
|
|
917
|
+
case 'core/toc': {
|
|
918
|
+
const deepest = ({ h2: 2, h3: 3, h4: 4 } as Record<string, number>)[text('depth')] ?? 3;
|
|
919
|
+
const headings = (block.headings ?? []).filter(heading => heading.level <= deepest);
|
|
920
|
+
if (!headings.length) return null;
|
|
921
|
+
const title = text('title');
|
|
922
|
+
const items = headings.map(heading => html`<li class="cms-toc-item" data-level=${String(heading.level)}><a href=${`#${heading.id}`}>${heading.text}</a></li>`);
|
|
923
|
+
return html`<nav class="cms-toc my-6" aria-labelledby=${ifDefined(title ? `${block._id}-title` : undefined)} aria-label=${ifDefined(title ? undefined : __('Table of contents'))}>
|
|
924
|
+
${title ? html`<p class="cms-toc-title" id=${`${block._id}-title`}>${title}</p>` : null}
|
|
925
|
+
${block.data.numbered === true ? html`<ol class="cms-toc-list">${items}</ol>` : html`<ul class="cms-toc-list">${items}</ul>`}</nav>`;
|
|
926
|
+
}
|
|
927
|
+
case 'core/share': {
|
|
928
|
+
const chosen = (Array.isArray(block.data.networks) ? block.data.networks as unknown[] : []).filter((entry): entry is ShareNetwork => (SHARE_NETWORKS as readonly string[]).includes(entry as string));
|
|
929
|
+
const url = state?.site?.url ?? '';
|
|
930
|
+
if (!chosen.length) return null;
|
|
931
|
+
const crumbs = state?.site?.breadcrumbs ?? [];
|
|
932
|
+
const title = crumbs.at(-1)?.label || state?.site?.title || '';
|
|
933
|
+
const labels = text('style') === 'labels';
|
|
934
|
+
const glyph = (network: ShareNetwork) => {
|
|
935
|
+
const brand = block.icons?.[network];
|
|
936
|
+
if (brand) return html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="cms-share-icon" aria-hidden="true" focusable="false"><path d=${brand.path}></path></svg>`;
|
|
937
|
+
return siteIcon(network === 'email' ? 'letter' : network === 'copy' ? 'link' : 'share', { class: 'cms-share-icon' });
|
|
938
|
+
};
|
|
939
|
+
return html`<div class="cms-share my-6" data-style=${labels ? 'labels' : 'icons'} ref=${enhanceShare}>
|
|
940
|
+
${text('label') ? html`<span class="cms-share-label">${text('label')}</span>` : null}
|
|
941
|
+
<ul class="cms-share-list">${chosen.map(network => {
|
|
942
|
+
const name = block.icons?.[network]?.title ?? (network === 'email' ? __('Email') : network === 'copy' ? __('Copy link') : SHARE_NAMES[network]);
|
|
943
|
+
const target = shareUrl(network, url, title);
|
|
944
|
+
const brand = block.icons?.[network];
|
|
945
|
+
const inner = html`${glyph(network)}${labels ? html`<span class="cms-share-name">${name}</span>` : null}`;
|
|
946
|
+
return html`<li>${target === null
|
|
947
|
+
? html`<button type="button" class="cms-share-link" data-network="copy" data-url=${url} title=${name} aria-label=${ifDefined(labels ? undefined : name)}>${inner}<span class="cms-share-copied" aria-live="polite">${__('Copied')}</span></button>`
|
|
948
|
+
: html`<a class="cms-share-link" href=${target} data-network=${network} style=${ifDefined(brand ? `--cms-brand: #${brand.hex}` : undefined)} title=${name} aria-label=${ifDefined(labels ? undefined : name)}
|
|
949
|
+
rel=${ifDefined(network === 'email' ? undefined : 'noopener')} target=${ifDefined(network === 'email' ? undefined : '_blank')}>${inner}</a>`}</li>`;
|
|
950
|
+
})}</ul>
|
|
951
|
+
</div>`;
|
|
952
|
+
}
|
|
953
|
+
case 'core/breadcrumbs': return breadcrumbTrail(state?.site?.breadcrumbs, { separator: text('separator'), home: block.data.home !== false });
|
|
954
|
+
case 'core/group': {
|
|
955
|
+
// A full-width stack keeps its children at the content measure, as the page's layout does; a full row lays its row within it (cms/blocks.css).
|
|
956
|
+
const align = alignOf(block);
|
|
957
|
+
const direction = text('direction') || 'column';
|
|
958
|
+
const height = text('height');
|
|
959
|
+
const valign = text('valign');
|
|
960
|
+
const inner = align === 'full' && direction !== 'row' ? children.map(child => layoutItem(child, helpers)) : children.map(child => helpers.block(child));
|
|
961
|
+
return html`<div class="cms-group" data-align=${align} data-direction=${direction} data-justify=${text('justify') || 'start'}
|
|
962
|
+
data-height=${ifDefined(height && height !== 'auto' ? height : undefined)} data-valign=${ifDefined(valign && valign !== 'top' ? valign : undefined)}>${inner}</div>`;
|
|
963
|
+
}
|
|
964
|
+
case 'core/columns': {
|
|
965
|
+
const spans = columnSpans(children);
|
|
966
|
+
return html`<div class="cms-columns" data-gap=${text('gap') || 'medium'} data-stack=${text('stack') || 'mobile'}>${children.map((column, index) => helpers.block({ ...column, data: { ...column.data, span: spans[index] } }))}</div>`;
|
|
967
|
+
}
|
|
968
|
+
case 'core/column': return html`<div class="cms-column" data-valign=${text('verticalAlign') || 'top'} style=${`--cms-span: ${columnSpan(block)}`}>${children.map(child => helpers.block(child))}</div>`;
|
|
969
|
+
case 'core/grid': {
|
|
970
|
+
const count = (name: string, fallback: number) => Math.min(Math.max(Number(block.data[name]) || fallback, 1), 6);
|
|
971
|
+
return html`<div class="cms-grid" data-gap=${text('gap') || 'medium'} style=${`--cms-cols-lg: ${count('columns', 3)}; --cms-cols-md: ${count('columnsMd', 2)}; --cms-cols-sm: ${count('columnsSm', 1)}`}>
|
|
972
|
+
${children.map(child => html`<div class="min-w-0">${helpers.block(child)}</div>`)}</div>`;
|
|
973
|
+
}
|
|
974
|
+
case 'core/form': return formBlock(block, helpers);
|
|
975
|
+
default: {
|
|
976
|
+
if (block.type.startsWith('form/')) return inputBlock(block, helpers);
|
|
977
|
+
const plugin = plugins.find(entry => block.type.startsWith(`${entry.name}/`));
|
|
978
|
+
const blocks = (plugin?.ui as { blocks?: Record<string, unknown> } | null | undefined)?.blocks;
|
|
979
|
+
const view = blocks?.[block.type.slice(block.type.indexOf('/') + 1)] ?? blocks?.[block.type];
|
|
980
|
+
return view ? component(view as never, { block, helpers }) : null;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
/** Shown in the theme's layout before setup and while content migrates. */
|
|
986
|
+
export function unavailable(): TemplateResult {
|
|
987
|
+
return html`<section class="space-y-2 py-16 text-center">
|
|
988
|
+
<h1 class="text-2xl font-bold text-foreground">${__('This site is being set up')}</h1>
|
|
989
|
+
<p class="text-muted-foreground">${__('Please come back soon.')}</p>
|
|
990
|
+
</section>`;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const list = ({ view }: { view: ArchiveView }) => html`<section>
|
|
994
|
+
<h1>${view.title}</h1>
|
|
995
|
+
${view.entries.length ? html`<ul>${view.entries.map(entry => html`<li><a href=${entry.url ?? '#'}>${entry.title}</a> ${entry.date}</li>`)}</ul>` : html`<p>${__('Nothing here yet.')}</p>`}
|
|
996
|
+
${view.paging.page < view.paging.pages ? html`<a href=${`${view.paging.base}?page=${view.paging.page + 1}`}>${__('Older')}</a>` : null}
|
|
997
|
+
</section>`;
|
|
998
|
+
|
|
999
|
+
/** Plain templates for a site without a usable theme. Activate a theme under Appearance. */
|
|
1000
|
+
export const fallbackTheme: SiteTheme = {
|
|
1001
|
+
layout: ({ site, content, helpers }) => html`<div class="mx-auto max-w-3xl px-6 py-8 text-foreground">
|
|
1002
|
+
<header><a href=${site.homeUrl}><strong>${site.title}</strong></a> ${site.tagline}${helpers.menu('primary', { style: 'list', label: __('Site') })}
|
|
1003
|
+
${site.languages.length > 1 ? html`<nav aria-label=${__('Language')}>${site.languages.map(language => html`<a href=${language.url} hreflang=${language.code}>${language.label}</a> `)}</nav>` : null}</header>
|
|
1004
|
+
<main>${content}</main>
|
|
1005
|
+
</div>`,
|
|
1006
|
+
entry: ({ entry, helpers }) => html`<article><h1>${entry.title}</h1><p>${entry.date}</p>${helpers.block(entry.content)}
|
|
1007
|
+
${entry.comments ? html`<section id="comments"><h2>${__('Comments')}</h2>${entry.comments.items.map(item => html`<div id=${`comment-${item.id}`}><strong>${item.author}</strong> ${item.date}${unsafeHTML(item.html)}</div>`)}
|
|
1008
|
+
${entry.comments.form && !entry.comments.form.requireSignIn ? html`<form method="post" action=${entry.comments.form.action}><input type="hidden" name="collection" value=${entry.comments.form.collection}>
|
|
1009
|
+
<input type="hidden" name="entry" value=${entry.comments.form.entry}><textarea name="content" required aria-label=${__('Comment')}></textarea>
|
|
1010
|
+
${entry.comments.form.userName ? null : html`<input name="authorName" aria-label=${__('Name')} placeholder=${__('Name')}><input name="authorEmail" type="email" aria-label=${__('Email')} placeholder=${__('Email')}>`}
|
|
1011
|
+
<button type="submit">${__('Post comment')}</button></form>` : null}</section>` : null}</article>`,
|
|
1012
|
+
archive: list,
|
|
1013
|
+
notFound: () => html`<section><h1>${__('Page not found')}</h1><a href="/">${__('Go to the home page')}</a></section>`,
|
|
1014
|
+
};
|