@cossackframework/cms 0.0.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +21 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +709 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +114 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
package/src/blocks.ts
ADDED
|
@@ -0,0 +1,1157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blocks: ordered, typed content sections stored in a `blocks` field as `{ id, type, data }`,
|
|
3
|
+
* with `children` under a container and `layout` for how a block shows. A block type declares
|
|
4
|
+
* its fields like a collection does, and which blocks it holds. The host validates every
|
|
5
|
+
* block's data on write; the site renders each type with its own component. Layouts are
|
|
6
|
+
* blocks: a group, columns and a grid hold other blocks, so one tree is stored, edited,
|
|
7
|
+
* diffed and shared as a pattern.
|
|
8
|
+
*/
|
|
9
|
+
import { field, fieldProblems, slugify, validateValue, type FieldDeclaration } from './fields';
|
|
10
|
+
import { normalizeRichText, richTextBlocks, richTextMedia, withRichTextBlocks, type RichTextDoc } from './richtext';
|
|
11
|
+
|
|
12
|
+
export { blocksShapeProblem, blockLayoutProblem, blockStyleProblem, styleValueProblem, blockConditionProblem, blockIdProblem, BLOCK_ID, BLOCK_LIMITS, BREAKPOINTS, CUSTOM_COLOR, MEDIA_ID, BACKGROUND_SIZES, STYLE_PROPERTIES, TEXT_ALIGNMENTS, PRESET_SLUG, INPUT_NAME, CONDITION_OPERATORS, CONDITION_LIMIT,
|
|
13
|
+
type Breakpoint, type StyleProperty, type ConditionOperator } from './block-shape';
|
|
14
|
+
import { bindingProblem } from './bindings';
|
|
15
|
+
import { hasBlockReference, parseBlockText, textBlocks } from './block-references';
|
|
16
|
+
import { ICON_NAME } from './icons';
|
|
17
|
+
import { BLOCK_LIMITS, BREAKPOINTS, INPUT_NAME, STYLE_PROPERTIES, TEXT_ALIGNMENTS, styleValueProblem, type Breakpoint, type ConditionOperator, type StyleProperty } from './block-shape';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* What a form input collects, which decides how its value is checked and stored: text of a
|
|
21
|
+
* kind, a number, a yes or no, a `YYYY-MM-DD` date, one of the block's options or several.
|
|
22
|
+
*/
|
|
23
|
+
/** Providers an Embed block takes a page address from; `embedUrl` in the application turns each into the provider's player or card. */
|
|
24
|
+
export const EMBED_URL = /^https:\/\/(?:(?:www\.|m\.|mobile\.)?(?:youtube\.com|youtu\.be|vimeo\.com|x\.com|twitter\.com|instagram\.com|tiktok\.com|codepen\.io|loom\.com|figma\.com|soundcloud\.com)|open\.spotify\.com|player\.vimeo\.com)\/\S+$/;
|
|
25
|
+
|
|
26
|
+
export const INPUT_KINDS = Object.freeze(['string', 'text', 'email', 'url', 'phone', 'number', 'boolean', 'date', 'choice', 'choices', 'rows', 'file'] as const);
|
|
27
|
+
export type InputKind = (typeof INPUT_KINDS)[number];
|
|
28
|
+
|
|
29
|
+
/** A form holds at most this many inputs. */
|
|
30
|
+
export const FORM_INPUT_LIMIT = 48;
|
|
31
|
+
/** Input names a submission keeps for itself. */
|
|
32
|
+
export const RESERVED_INPUT_NAMES: ReadonlySet<string> = new Set(['id', 'rev', 'owner', 'createdAt', 'updatedAt', 'status', 'note', 'meta', 'form']);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Which style properties a block type offers, as Gutenberg's block supports: `true` for all
|
|
36
|
+
* of a kind, a list for some, `false` for none. Absent kinds follow the category's defaults.
|
|
37
|
+
*/
|
|
38
|
+
export interface BlockSupports {
|
|
39
|
+
readonly color?: boolean | readonly ('background' | 'text')[];
|
|
40
|
+
readonly spacing?: boolean | readonly ('padding' | 'margin')[];
|
|
41
|
+
readonly typography?: boolean | readonly ('fontSize' | 'align')[];
|
|
42
|
+
/** The advanced background (gradient, image, overlay, video); off unless a type says so, as the core containers do. */
|
|
43
|
+
readonly background?: boolean | readonly ('gradient' | 'image' | 'imageSize' | 'imageRepeat' | 'imageFixed' | 'overlay' | 'overlayOpacity' | 'video')[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface BlockDeclaration {
|
|
47
|
+
/** `<owner>/<name>`, such as `core/paragraph` or `support-desk/ticket-form`. */
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly label: string;
|
|
50
|
+
readonly description?: string;
|
|
51
|
+
/** Solar icon name for the block picker, such as `text-field`. Unknown names show a generic icon. */
|
|
52
|
+
readonly icon?: string;
|
|
53
|
+
/** The block picker's group. Default `widgets`. */
|
|
54
|
+
readonly category?: BlockCategory;
|
|
55
|
+
/** Other words the picker's search finds the block by, such as `wysiwyg` for Rich text. */
|
|
56
|
+
readonly keywords?: readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
* Offered everywhere blocks go, forms and field groups included, whatever its category: a
|
|
59
|
+
* heading or a paragraph is as useful beside a form's inputs as in a page. Input and field
|
|
60
|
+
* blocks keep to their own places regardless.
|
|
61
|
+
*/
|
|
62
|
+
readonly common?: boolean;
|
|
63
|
+
readonly fields: { readonly [name: string]: FieldDeclaration };
|
|
64
|
+
/** The block holds other blocks: those named, or any, up to `max`. Absent for a leaf block. */
|
|
65
|
+
readonly children?: { readonly allowed?: readonly string[]; readonly max?: number };
|
|
66
|
+
/** The block goes only inside these types, as a column goes inside columns. Pickers offer it there alone. */
|
|
67
|
+
readonly parent?: readonly string[];
|
|
68
|
+
/** The Style tab's controls; the category decides when absent. See `blockSupports`. */
|
|
69
|
+
readonly supports?: BlockSupports;
|
|
70
|
+
/**
|
|
71
|
+
* Shapes of the block the inserter offers as entries of their own, each starting with its
|
|
72
|
+
* `data` over the defaults: a Hero is a Group set full width, tall and centered. At most 12.
|
|
73
|
+
*/
|
|
74
|
+
readonly variations?: readonly BlockVariation[];
|
|
75
|
+
/** The block can be referenced inside text: `{{ block <name> … }}` (see `parseBlockText`). */
|
|
76
|
+
readonly inline?: boolean;
|
|
77
|
+
/** The text field a reference's body fills, such as `label` for a button: `{{ block core/button }}Buy{{ /block }}`. Containers take their body as children instead. */
|
|
78
|
+
readonly body?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The block is a form input: it collects one value under its `name` data field, labelled by
|
|
81
|
+
* its `label`. Input blocks go only in a form's blocks field.
|
|
82
|
+
*/
|
|
83
|
+
readonly input?: { readonly kind: InputKind };
|
|
84
|
+
/**
|
|
85
|
+
* The block is a field of a field group: it declares one field of the group's target under
|
|
86
|
+
* its `name` data field, labelled by its `label`. Field blocks go only in a field group.
|
|
87
|
+
*/
|
|
88
|
+
readonly field?: { readonly kind: FieldBlockKind };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A preset shape of a block type, offered in the inserter under its own name and icon. */
|
|
92
|
+
export interface BlockVariation {
|
|
93
|
+
/** Lowercase letters, digits and hyphens; distinct within the type. */
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly label: string;
|
|
96
|
+
readonly description?: string;
|
|
97
|
+
/** A Solar icon name for the picker; the type's when absent. */
|
|
98
|
+
readonly icon?: string;
|
|
99
|
+
readonly keywords?: readonly string[];
|
|
100
|
+
/** Field values the new block starts with, over the type's defaults. */
|
|
101
|
+
readonly data: { readonly [field: string]: unknown };
|
|
102
|
+
}
|
|
103
|
+
const VARIATION_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
104
|
+
|
|
105
|
+
/** The builder's field types, one field block each. */
|
|
106
|
+
export const FIELD_BLOCK_KINDS = Object.freeze(['text', 'textarea', 'markdown', 'number', 'integer', 'boolean', 'date', 'choice', 'media', 'reference', 'blocks', 'json', 'repeater'] as const);
|
|
107
|
+
export type FieldBlockKind = (typeof FIELD_BLOCK_KINDS)[number];
|
|
108
|
+
|
|
109
|
+
/** One test of a condition: an input's value against `value`. */
|
|
110
|
+
export interface ConditionRule {
|
|
111
|
+
/** The input's name. */
|
|
112
|
+
readonly field: string;
|
|
113
|
+
readonly op: ConditionOperator;
|
|
114
|
+
readonly value?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** When a block in a form shows: if `all` (the default) or `any` rule matches; `hide` turns it around. */
|
|
118
|
+
export interface BlockCondition {
|
|
119
|
+
readonly action?: 'show' | 'hide';
|
|
120
|
+
readonly match?: 'all' | 'any';
|
|
121
|
+
readonly rules: readonly ConditionRule[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** How a block shows, apart from its type's data. Checked by core for every block. */
|
|
125
|
+
export interface BlockLayout {
|
|
126
|
+
/** Container widths the block is hidden at: `sm` below 640px, `md` below 1024px, `lg` from there. */
|
|
127
|
+
readonly hide?: readonly Breakpoint[];
|
|
128
|
+
/** The block's HTML id, for in-page links. */
|
|
129
|
+
readonly anchor?: string;
|
|
130
|
+
/** Extra class names on the block's wrapper, for the theme's stylesheet. */
|
|
131
|
+
readonly className?: string;
|
|
132
|
+
/** Search and answer engines may not quote the block (`data-nosnippet` on its wrapper). */
|
|
133
|
+
readonly nosnippet?: boolean;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A block's style: slugs of the theme's presets (colors may be hex colors of the block's own),
|
|
138
|
+
* a text alignment, and for containers an advanced background: a gradient preset, an image
|
|
139
|
+
* from the library with how it fills, repeats and scrolls, an overlay color at an opacity, and
|
|
140
|
+
* a video from the library. Rendered as classes and custom properties by `blockStyleAttributes`.
|
|
141
|
+
*/
|
|
142
|
+
export interface BlockStyle {
|
|
143
|
+
readonly background?: string;
|
|
144
|
+
readonly text?: string;
|
|
145
|
+
readonly padding?: string;
|
|
146
|
+
readonly margin?: string;
|
|
147
|
+
readonly fontSize?: string;
|
|
148
|
+
readonly align?: (typeof TEXT_ALIGNMENTS)[number];
|
|
149
|
+
readonly gradient?: string;
|
|
150
|
+
/** A media file ID. */
|
|
151
|
+
readonly image?: string;
|
|
152
|
+
readonly imageSize?: 'cover' | 'contain' | 'auto';
|
|
153
|
+
readonly imageRepeat?: boolean;
|
|
154
|
+
/** The image stays put while the page scrolls (`background-attachment: fixed`), a parallax-like effect. */
|
|
155
|
+
readonly imageFixed?: boolean;
|
|
156
|
+
readonly overlay?: string;
|
|
157
|
+
/** 0 to 100; 50 when an overlay names none. */
|
|
158
|
+
readonly overlayOpacity?: number;
|
|
159
|
+
/** A media file ID of a video, played muted in a loop behind the block. */
|
|
160
|
+
readonly video?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface Block {
|
|
164
|
+
/** Stable within its field: 1-40 letters, digits, `_` or `-`; distinct across the whole tree. A system field, so `_id`. */
|
|
165
|
+
readonly _id: string;
|
|
166
|
+
readonly type: string;
|
|
167
|
+
readonly data: { readonly [field: string]: unknown };
|
|
168
|
+
readonly layout?: BlockLayout;
|
|
169
|
+
readonly style?: BlockStyle;
|
|
170
|
+
/** In a form: when the block shows, from the values of the form's inputs. */
|
|
171
|
+
readonly when?: BlockCondition;
|
|
172
|
+
/** The blocks inside a container. */
|
|
173
|
+
readonly children?: readonly Block[];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Groups of the block picker, in its order, as in WordPress. A `description` says where a family's blocks go and where their values live. */
|
|
177
|
+
export const BLOCK_CATEGORIES: readonly { readonly id: 'text' | 'media' | 'design' | 'widgets' | 'embeds' | 'form' | 'field' | 'data'; readonly label: string; readonly description?: string }[] = Object.freeze([
|
|
178
|
+
{ id: 'text', label: 'Text' },
|
|
179
|
+
{ id: 'media', label: 'Media' },
|
|
180
|
+
{ id: 'design', label: 'Design' },
|
|
181
|
+
{ id: 'widgets', label: 'Widgets' },
|
|
182
|
+
{ id: 'embeds', label: 'Embeds' },
|
|
183
|
+
// Two families that look alike: input blocks collect a form's values from visitors; field blocks declare the
|
|
184
|
+
// fields of a field group, stored on entries and edited in the dashboard. Each is offered in its own builder alone.
|
|
185
|
+
{ id: 'form', label: 'Form inputs', description: 'Controls a visitor fills in on a form. Each value is stored with the form\'s submissions.' },
|
|
186
|
+
{ id: 'field', label: 'Entry fields', description: 'Fields a field group adds to entries, terms, users or menu items. Editors fill them in the dashboard; values are stored on the entry.' },
|
|
187
|
+
// Data blocks store values with the entry and draw nothing: metadata, custom fields, settings a theme reads.
|
|
188
|
+
{ id: 'data', label: 'Data', description: 'Values stored with the entry for themes and the API. Nothing shows on the page.' },
|
|
189
|
+
]);
|
|
190
|
+
export type BlockCategory = (typeof BLOCK_CATEGORIES)[number]['id'];
|
|
191
|
+
|
|
192
|
+
/** A block's category, `widgets` when it names none. */
|
|
193
|
+
export function blockCategory(declaration: Pick<BlockDeclaration, 'category'>): BlockCategory {
|
|
194
|
+
return declaration.category ?? 'widgets';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** A data-only block: it stores values and the site renders nothing for it. */
|
|
198
|
+
export function blockIsData(declaration: Pick<BlockDeclaration, 'category'>): boolean {
|
|
199
|
+
return blockCategory(declaration) === 'data';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const SUPPORT_KINDS = Object.freeze({ color: ['background', 'text'], spacing: ['padding', 'margin'], typography: ['fontSize', 'align'], background: ['gradient', 'image', 'imageSize', 'imageRepeat', 'imageFixed', 'overlay', 'overlayOpacity', 'video'] } as const);
|
|
203
|
+
type SupportKind = keyof typeof SUPPORT_KINDS;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The style properties a block type offers: its `supports` over the category's defaults.
|
|
207
|
+
* Text blocks get color, spacing and typography; media blocks spacing alone; the rest
|
|
208
|
+
* color and spacing. The advanced background is off unless the type asks for it.
|
|
209
|
+
*/
|
|
210
|
+
export function blockSupports(declaration: Pick<BlockDeclaration, 'category' | 'supports'>): readonly StyleProperty[] {
|
|
211
|
+
const category = blockCategory(declaration);
|
|
212
|
+
if (category === 'data' || category === 'field') return [];
|
|
213
|
+
const defaults: Record<SupportKind, boolean> = { color: category !== 'media', spacing: true, typography: category === 'text', background: false };
|
|
214
|
+
const properties: StyleProperty[] = [];
|
|
215
|
+
for (const kind of Object.keys(SUPPORT_KINDS) as SupportKind[]) {
|
|
216
|
+
const support = declaration.supports?.[kind] ?? defaults[kind];
|
|
217
|
+
if (support === false) continue;
|
|
218
|
+
for (const property of SUPPORT_KINDS[kind]) if (support === true || (Array.isArray(support) && (support as readonly string[]).includes(property))) properties.push(property);
|
|
219
|
+
}
|
|
220
|
+
return properties;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export const BLOCK_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
224
|
+
/** Where `core/share` can send a page, in the order the block offers them. */
|
|
225
|
+
export const SHARE_NETWORKS = Object.freeze(['facebook', 'x', 'linkedin', 'whatsapp', 'telegram', 'reddit', 'pinterest', 'bluesky', 'threads', 'email', 'copy'] as const);
|
|
226
|
+
export type ShareNetwork = (typeof SHARE_NETWORKS)[number];
|
|
227
|
+
/** A URL of each network's own, which the server resolves into its brand icon for the share block. */
|
|
228
|
+
export const SHARE_BRAND_URLS: Readonly<Partial<Record<ShareNetwork, string>>> = Object.freeze({
|
|
229
|
+
facebook: 'https://facebook.com', x: 'https://x.com', linkedin: 'https://linkedin.com', whatsapp: 'https://whatsapp.com', telegram: 'https://t.me', reddit: 'https://reddit.com', pinterest: 'https://pinterest.com', bluesky: 'https://bsky.app', threads: 'https://threads.net',
|
|
230
|
+
});
|
|
231
|
+
/** An embed URL a map block may show: Google Maps or OpenStreetMap, as their Share → Embed dialogs give it. */
|
|
232
|
+
export const MAP_EMBED_URL = /^https:\/\/(?:(?:www\.)?google\.[a-z]{2,3}(?:\.[a-z]{2})?\/maps\/embed\?|maps\.google\.[a-z]{2,3}(?:\.[a-z]{2})?\/maps\?|(?:www\.)?openstreetmap\.org\/export\/embed\.html\?)\S*$/;
|
|
233
|
+
/** Field kinds a block can hold. Nesting is through `children`, not fields. */
|
|
234
|
+
const BLOCK_FIELD_KINDS = new Set(['string', 'text', 'enum', 'integer', 'number', 'boolean', 'datetime', 'json', 'richtext']);
|
|
235
|
+
const LINK = '(?:https?://|/|mailto:|tel:|#)\\S*';
|
|
236
|
+
|
|
237
|
+
const GAP = field.enum(['none', 'small', 'medium', 'large'], { default: 'medium', label: 'Gap' });
|
|
238
|
+
/** How wide a block is where the theme constrains blocks (the content, a full-width group): see `cms-item` in `cms/blocks.css`. */
|
|
239
|
+
const WIDTH = field.enum(['content', 'wide', 'full'], { default: 'content', label: 'Width', choices: { content: 'Content width', wide: 'Wide', full: 'Full width' } });
|
|
240
|
+
|
|
241
|
+
/** Built-in block types. */
|
|
242
|
+
const core: BlockDeclaration[] = [
|
|
243
|
+
// The word processor block: formatted text with headings, lists, links and images, as the body of a WordPress post.
|
|
244
|
+
{ name: 'core/richtext', keywords: ['wysiwyg', 'editor', 'word processor', 'text'], common: true, label: 'Rich text', icon: 'text-selection', category: 'text', description: 'Formatted text with headings, lists, links and images.', fields: { text: field.richText({ label: 'Text' }) } },
|
|
245
|
+
{ name: 'core/paragraph', inline: true, body: 'text', keywords: ['text', 'markdown'], common: true, label: 'Paragraph', icon: 'paragraph-spacing', category: 'text', fields: { text: field.text({ required: true, max: 20_000, format: 'markdown', label: 'Text' }) } },
|
|
246
|
+
{ name: 'core/heading', inline: true, body: 'text', keywords: ['title', 'h2', 'h3', 'subtitle'], common: true, label: 'Heading', icon: 'text-bold', category: 'text', fields: {
|
|
247
|
+
text: field.string({ required: true, max: 200, label: 'Text', description: 'Words between *asterisks* show in the accent color.' }),
|
|
248
|
+
level: field.enum(['h1', 'h2', 'h3', 'h4'], { default: 'h2', label: 'Level', choices: { h1: 'H1: the page title, once a page', h2: 'H2', h3: 'H3', h4: 'H4' } }),
|
|
249
|
+
} },
|
|
250
|
+
{ name: 'core/image', inline: true, keywords: ['picture', 'photo', 'figure'], common: true, label: 'Image', icon: 'gallery', category: 'media', fields: {
|
|
251
|
+
image: field.media({ required: true, nullable: false, label: 'Image' }),
|
|
252
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
253
|
+
link: field.string({ max: 2048, pattern: '(?:https?://|/)\\S*', label: 'Link' }),
|
|
254
|
+
align: WIDTH,
|
|
255
|
+
} },
|
|
256
|
+
{ name: 'core/gallery', inline: true, keywords: ['images', 'photos', 'logos', 'clients', 'partners'], label: 'Gallery', icon: 'gallery-wide', category: 'media', fields: {
|
|
257
|
+
images: field.gallery({ label: 'Images' }),
|
|
258
|
+
columns: field.integer({ default: 3, min: 1, max: 6, label: 'Columns' }),
|
|
259
|
+
layout: field.enum(['grid', 'masonry', 'logos'], { default: 'grid', label: 'Layout', choices: { grid: 'Square tiles', masonry: 'Masonry: whole images in columns', logos: 'Logos: whole images at one height' } }),
|
|
260
|
+
lightbox: field.boolean({ default: false, label: 'Open images in a lightbox', description: 'A click shows the image large, with arrows to the others.' }),
|
|
261
|
+
align: WIDTH,
|
|
262
|
+
}, variations: [
|
|
263
|
+
{ name: 'masonry', label: 'Masonry gallery', description: 'Whole images in columns, opening large when clicked: a portfolio.', icon: 'gallery-wide', keywords: ['portfolio', 'lightbox', 'photos'], data: { layout: 'masonry', lightbox: true } },
|
|
264
|
+
{ name: 'logos', label: 'Logo wall', description: 'Whole images at one height, grey until hovered: clients, partners, press.', icon: 'buildings', keywords: ['clients', 'partners', 'brands'], data: { layout: 'logos', columns: 4 } },
|
|
265
|
+
] },
|
|
266
|
+
{ name: 'core/quote', inline: true, body: 'text', keywords: ['blockquote', 'citation'], label: 'Quote', icon: 'chat-round-line', category: 'text', fields: {
|
|
267
|
+
text: field.text({ required: true, max: 2000, label: 'Quote' }),
|
|
268
|
+
citation: field.string({ max: 200, label: 'Citation' }),
|
|
269
|
+
} },
|
|
270
|
+
{ name: 'core/list', keywords: ['bullets', 'numbered', 'ul', 'ol'], label: 'List', icon: 'list', category: 'text', fields: {
|
|
271
|
+
items: field.list('string', { label: 'Items' }),
|
|
272
|
+
ordered: field.boolean({ default: false, label: 'Numbered' }),
|
|
273
|
+
} },
|
|
274
|
+
{ name: 'core/code', keywords: ['snippet', 'pre', 'source'], label: 'Code', icon: 'code-square', category: 'text', fields: {
|
|
275
|
+
code: field.text({ required: true, max: 20_000, format: 'code', label: 'Code' }),
|
|
276
|
+
language: field.string({ max: 40, pattern: '[a-z0-9+#-]*', label: 'Language', description: 'Such as html, css, js, ts, json, python or bash.' }),
|
|
277
|
+
} },
|
|
278
|
+
{ name: 'core/table', keywords: ['grid', 'rows', 'columns', 'data', 'comparison'], label: 'Table', icon: 'widget-2', category: 'text', description: 'Rows of cells: one row per line, cells separated by |. The first row can be the header.', fields: {
|
|
279
|
+
rows: field.text({ required: true, max: 20_000, label: 'Rows', description: 'One row per line; separate cells with |. Markdown inline formatting is kept as text.' }),
|
|
280
|
+
header: field.boolean({ default: true, label: 'First row is the header' }),
|
|
281
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
282
|
+
align: WIDTH,
|
|
283
|
+
} },
|
|
284
|
+
{ name: 'core/file', inline: true, keywords: ['download', 'pdf', 'attachment', 'document'], label: 'File', icon: 'file-text', category: 'media', description: 'A file from the library as a download link, with its type and size.', fields: {
|
|
285
|
+
file: field.media({ required: true, nullable: false, label: 'File' }),
|
|
286
|
+
label: field.string({ max: 200, label: 'Label', description: 'Empty shows the file\'s name.' }),
|
|
287
|
+
showSize: field.boolean({ default: true, label: 'Show the type and size' }),
|
|
288
|
+
download: field.boolean({ default: true, label: 'Download rather than open' }),
|
|
289
|
+
} },
|
|
290
|
+
{ name: 'core/html', keywords: ['code', 'embed', 'iframe', 'script', 'widget'], label: 'Custom HTML', icon: 'code-square', category: 'embeds', description: 'HTML of your own, shown on the page as it is. Only people allowed to post HTML can add or change it.', fields: {
|
|
291
|
+
html: field.text({ required: true, max: 100_000, format: 'code', language: 'html', label: 'HTML' }),
|
|
292
|
+
} },
|
|
293
|
+
{ name: 'core/button', inline: true, body: 'label', keywords: ['link', 'cta', 'call to action'], label: 'Button', icon: 'cursor-square', category: 'design', fields: {
|
|
294
|
+
label: field.string({ required: true, max: 80, label: 'Label' }),
|
|
295
|
+
url: field.string({ required: true, max: 2048, pattern: LINK, label: 'URL', description: 'A page, an address, a mailto: or tel: link, or #section on this page.' }),
|
|
296
|
+
style: field.enum(['primary', 'outline', 'light', 'link'], { default: 'primary', label: 'Style', choices: { primary: 'Primary', outline: 'Outline', light: 'Light, for dark backgrounds', link: 'Text link' } }),
|
|
297
|
+
size: field.enum(['medium', 'large'], { default: 'medium', label: 'Size' }),
|
|
298
|
+
icon: field.icon({ label: 'Icon', description: 'Shown after the label, such as an arrow.' }),
|
|
299
|
+
} },
|
|
300
|
+
{ name: 'core/embed', inline: true, keywords: ['youtube', 'vimeo', 'video', 'tweet', 'x', 'instagram', 'tiktok', 'spotify', 'soundcloud', 'codepen', 'figma', 'loom'], label: 'Embed', icon: 'play-circle', category: 'embeds',
|
|
301
|
+
description: 'A post, video, track, pen or design from YouTube, Vimeo, X, Instagram, TikTok, Spotify, SoundCloud, CodePen, Figma or Loom, from its address; it loads from their servers.', fields: {
|
|
302
|
+
url: field.string({ required: true, max: 2048, pattern: EMBED_URL.source, label: 'URL', description: 'The page\'s address on the provider, such as https://www.youtube.com/watch?v=… or https://x.com/…/status/….' }),
|
|
303
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
304
|
+
align: WIDTH,
|
|
305
|
+
} },
|
|
306
|
+
{ name: 'core/video', inline: true, keywords: ['movie', 'film', 'mp4', 'player', 'lightbox'], label: 'Video', icon: 'video-frame', category: 'media', description: 'A video file from the library or another server, with the browser\'s player.', fields: {
|
|
307
|
+
video: field.media({ kinds: ['video'], label: 'Video', description: 'An MP4 or WebM file from the library.' }),
|
|
308
|
+
url: field.string({ max: 2048, pattern: '(?:https://\\S*)?', label: 'Video address', description: 'An MP4 or WebM file on another server, when there is none in the library.' }),
|
|
309
|
+
lightbox: field.boolean({ default: false, label: 'Play in a lightbox', description: 'Shows the poster with a play button; the video opens large over the page.' }),
|
|
310
|
+
poster: field.media({ label: 'Poster', description: 'The image shown before the video plays.' }),
|
|
311
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
312
|
+
captions: field.media({ kinds: ['document'], label: 'Captions', description: 'A WebVTT (.vtt) file of subtitles.' }),
|
|
313
|
+
align: WIDTH,
|
|
314
|
+
autoplay: field.boolean({ default: false, label: 'Autoplay', description: 'Starts muted, as browsers require.' }),
|
|
315
|
+
loop: field.boolean({ default: false, label: 'Loop' }),
|
|
316
|
+
muted: field.boolean({ default: false, label: 'Muted' }),
|
|
317
|
+
controls: field.boolean({ default: true, label: 'Show controls' }),
|
|
318
|
+
preload: field.enum(['metadata', 'auto', 'none'], { default: 'metadata', label: 'Preload', choices: { metadata: 'Only the first frame', auto: 'The whole video', none: 'Nothing until played' } }),
|
|
319
|
+
} },
|
|
320
|
+
{ name: 'core/audio', inline: true, keywords: ['sound', 'music', 'podcast', 'mp3', 'player'], label: 'Audio', icon: 'music-note', category: 'media', description: 'An audio file from the library, with the browser\'s player.', fields: {
|
|
321
|
+
audio: field.media({ required: true, nullable: false, kinds: ['audio'], label: 'Audio', description: 'An MP3, OGG or WAV file from the library.' }),
|
|
322
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
323
|
+
autoplay: field.boolean({ default: false, label: 'Autoplay' }),
|
|
324
|
+
loop: field.boolean({ default: false, label: 'Loop' }),
|
|
325
|
+
preload: field.enum(['metadata', 'auto', 'none'], { default: 'metadata', label: 'Preload', choices: { metadata: 'The length only', auto: 'The whole file', none: 'Nothing until played' } }),
|
|
326
|
+
} },
|
|
327
|
+
{ name: 'core/divider', inline: true, keywords: ['separator', 'hr', 'line', 'rule'], common: true, label: 'Divider', icon: 'minus-square', category: 'design', description: 'A line between sections, with text in the middle if you like.', fields: {
|
|
328
|
+
orientation: field.enum(['horizontal', 'vertical'], { default: 'horizontal', label: 'Orientation', choices: { horizontal: 'Horizontal', vertical: 'Vertical' } }),
|
|
329
|
+
thickness: field.enum(['thin', 'medium', 'thick'], { default: 'thin', label: 'Thickness' }),
|
|
330
|
+
width: field.enum(['full', 'wide', 'narrow'], { default: 'full', label: 'Length', choices: { full: 'Full width', wide: 'Three quarters', narrow: 'A quarter' } }),
|
|
331
|
+
color: field.string({ max: 60, pattern: '(?:#[0-9a-fA-F]{3,8}|[a-z][a-z0-9-]*(?:\\([^)]*\\))?)?', label: 'Color', description: 'A palette slug or a CSS color; empty uses the border color.' }),
|
|
332
|
+
text: field.string({ max: 80, label: 'Text', description: 'Shown in the middle of the line.' }),
|
|
333
|
+
} },
|
|
334
|
+
// Answer-shaped content: what search and answer engines quote. Plain HTML; no retired rich-result schema.
|
|
335
|
+
{ name: 'core/answer', inline: true, body: 'text', keywords: ['tldr', 'key takeaway', 'summary', 'answer', 'aeo'], label: 'Quick answer', icon: 'lightbulb-bolt', category: 'text', description: 'The direct answer, set apart at the top: two or three sentences engines can quote.', fields: {
|
|
336
|
+
text: field.text({ required: true, max: 2000, format: 'markdown', label: 'Answer' }),
|
|
337
|
+
label: field.string({ max: 60, label: 'Label', description: 'Such as Quick answer or Key takeaways. Empty for none.' }),
|
|
338
|
+
} },
|
|
339
|
+
{ name: 'core/faq', keywords: ['questions', 'answers', 'q&a', 'accordion'], label: 'Questions and answers', icon: 'question-circle', category: 'text', description: 'Questions readers ask, each with its answer. Optionally as FAQPage structured data.', fields: {
|
|
340
|
+
schema: field.boolean({ default: false, label: 'Add FAQPage structured data', description: 'Valid schema.org markup. Google no longer shows FAQ rich results for it.' }),
|
|
341
|
+
open: field.boolean({ default: true, label: 'Show the answers at first', description: 'Off folds every answer under its question until it is opened.' }),
|
|
342
|
+
}, children: { allowed: ['core/faq-item'], max: 50 } },
|
|
343
|
+
{ name: 'core/faq-item', label: 'Question', icon: 'question-circle', category: 'text', parent: ['core/faq'], fields: {
|
|
344
|
+
question: field.string({ required: true, max: 300, label: 'Question' }),
|
|
345
|
+
answer: field.text({ required: true, max: 5000, format: 'markdown', label: 'Answer' }),
|
|
346
|
+
} },
|
|
347
|
+
{ name: 'core/steps', keywords: ['how to', 'instructions', 'procedure', 'tutorial'], label: 'Steps', icon: 'list-check', category: 'text', description: 'Numbered steps with a title and text each.', fields: {
|
|
348
|
+
layout: field.enum(['list', 'row'], { default: 'list', label: 'Layout', choices: { list: 'A list, one under the other', row: 'Side by side, stacked on phones' } }),
|
|
349
|
+
}, children: { allowed: ['core/step'], max: 50 } },
|
|
350
|
+
{ name: 'core/step', label: 'Step', icon: 'list-check', category: 'text', parent: ['core/steps'], fields: {
|
|
351
|
+
title: field.string({ required: true, max: 200, label: 'Title' }),
|
|
352
|
+
text: field.text({ max: 5000, format: 'markdown', label: 'Text' }),
|
|
353
|
+
} },
|
|
354
|
+
{ name: 'core/claim', keywords: ['statistic', 'fact', 'source', 'citation', 'quote', 'geo'], label: 'Claim with source', icon: 'chart-square', category: 'text', description: 'A statistic or quotation with a linked source: the content generative answers cite.', fields: {
|
|
355
|
+
text: field.text({ required: true, max: 1000, label: 'Statistic or quote' }),
|
|
356
|
+
kind: field.enum(['statistic', 'quote'], { default: 'statistic', label: 'Kind', choices: { statistic: 'Statistic', quote: 'Quotation' } }),
|
|
357
|
+
sourceName: field.string({ required: true, max: 200, label: 'Source', description: 'Who published it: a study, an organization, a person.' }),
|
|
358
|
+
sourceUrl: field.string({ max: 2048, pattern: '(?:https?://\\S*)?', label: 'Source URL' }),
|
|
359
|
+
date: field.string({ max: 40, label: 'Date', description: 'When it was published, such as 2026 or March 2026.' }),
|
|
360
|
+
} },
|
|
361
|
+
{ name: 'core/definition', keywords: ['glossary', 'term', 'meaning', 'what is'], label: 'Definition', icon: 'book-bookmark', category: 'text', description: 'A term and what it means, in one or two sentences.', fields: {
|
|
362
|
+
term: field.string({ required: true, max: 200, label: 'Term' }),
|
|
363
|
+
definition: field.text({ required: true, max: 2000, format: 'markdown', label: 'Definition' }),
|
|
364
|
+
} },
|
|
365
|
+
{ name: 'core/card', inline: true, keywords: ['box', 'tile', 'icon box', 'image box', 'feature', 'service', 'team member'], label: 'Card', icon: 'card', category: 'design', description: 'An image or an icon with a title, text and a link, in a box or plain.', fields: {
|
|
366
|
+
image: field.media({ label: 'Image' }),
|
|
367
|
+
icon: field.icon({ label: 'Icon', description: 'Shown above the title when there is no image.' }),
|
|
368
|
+
style: field.enum(['boxed', 'plain'], { default: 'boxed', label: 'Style', choices: { boxed: 'In a box', plain: 'Plain' } }),
|
|
369
|
+
title: field.string({ max: 200, label: 'Title' }),
|
|
370
|
+
text: field.text({ max: 5000, format: 'markdown', label: 'Text' }),
|
|
371
|
+
url: field.string({ max: 2048, pattern: LINK, label: 'Link' }),
|
|
372
|
+
linkLabel: field.string({ max: 80, label: 'Link text', description: 'Empty links the title and the image.' }),
|
|
373
|
+
layout: field.enum(['top', 'left', 'right', 'overlay'], { default: 'top', label: 'Image position', description: 'Without an image, left and right place the icon beside the text.', choices: { top: 'Above the text', left: 'Left of the text', right: 'Right of the text', overlay: 'Behind the text' } }),
|
|
374
|
+
}, variations: [
|
|
375
|
+
{ name: 'image-tile', label: 'Image tile', description: 'A picture filling the card, its title and text over it; the whole tile is the link.', icon: 'gallery', keywords: ['service', 'category', 'cover'], data: { layout: 'overlay' } },
|
|
376
|
+
{ name: 'icon-box', label: 'Icon box', description: 'An icon, a title and text, without a box.', icon: 'star', keywords: ['feature', 'service', 'benefit'], data: { style: 'plain', icon: 'star' } },
|
|
377
|
+
] },
|
|
378
|
+
// A carousel shows its images, or slides of blocks when it holds any: the hero slider of page builders.
|
|
379
|
+
{ name: 'core/carousel', keywords: ['slider', 'slideshow', 'slides', 'hero slider'], label: 'Carousel', icon: 'posts-carousel-horizontal', category: 'media', description: 'Images, or slides of blocks, one at a time, with arrows and dots; swipe on touch screens.', fields: {
|
|
380
|
+
images: field.gallery({ label: 'Images' }),
|
|
381
|
+
aspect: field.enum(['video', 'wide', 'photo', 'square', 'auto'], { default: 'video', label: 'Shape', choices: { video: '16:9', wide: '21:9', photo: '4:3', square: 'Square', auto: 'As uploaded' } }),
|
|
382
|
+
autoplay: field.boolean({ default: false, label: 'Play automatically' }),
|
|
383
|
+
interval: field.integer({ default: 5, min: 2, max: 30, label: 'Seconds per image' }),
|
|
384
|
+
captions: field.boolean({ default: true, label: 'Show captions' }),
|
|
385
|
+
thumbnails: field.boolean({ default: false, label: 'Thumbnails', description: 'Small images under the carousel, in place of the dots. For images.' }),
|
|
386
|
+
perView: field.integer({ default: 1, min: 1, max: 4, label: 'Shown at once', description: 'On wide screens; fewer show on tablets, one on phones.' }),
|
|
387
|
+
align: WIDTH,
|
|
388
|
+
}, children: { allowed: ['core/slide'], max: 12 } },
|
|
389
|
+
{ name: 'core/slide', label: 'Slide', icon: 'gallery-wide', category: 'media', parent: ['core/carousel'], description: 'One slide of a carousel: any blocks over a background from its Style tab.', fields: {
|
|
390
|
+
valign: field.enum(['top', 'center', 'bottom'], { default: 'center', label: 'Vertical alignment' }),
|
|
391
|
+
}, children: {}, supports: { background: true, typography: ['align'] } },
|
|
392
|
+
// Before and after: two images of one scene under a handle. Several pairs get thumbnails to pick from.
|
|
393
|
+
{ name: 'core/compare', keywords: ['before', 'after', 'slider', 'comparison', 'retouch', 'staging', 'renovation'], label: 'Before and after', icon: 'slider-vertical', category: 'media', description: 'Two images of one scene; a handle slides between them. Several pairs get thumbnails.', fields: {
|
|
394
|
+
aspect: field.enum(['video', 'wide', 'photo', 'square'], { default: 'video', label: 'Shape', choices: { video: '16:9', wide: '16:10', photo: '4:3', square: 'Square' } }),
|
|
395
|
+
beforeLabel: field.string({ max: 40, default: 'Before', label: 'Label of the first image', description: 'Empty shows none.' }),
|
|
396
|
+
afterLabel: field.string({ max: 40, default: 'After', label: 'Label of the second image' }),
|
|
397
|
+
start: field.integer({ default: 50, min: 0, max: 100, label: 'Handle starts at', description: 'Percent from the left.' }),
|
|
398
|
+
align: WIDTH,
|
|
399
|
+
}, children: { allowed: ['core/compare-item'], max: 24 } },
|
|
400
|
+
{ name: 'core/compare-item', label: 'Pair', icon: 'gallery', category: 'media', parent: ['core/compare'], description: 'One scene: the image before and the image after.', fields: {
|
|
401
|
+
before: field.media({ required: true, nullable: false, label: 'Before' }),
|
|
402
|
+
after: field.media({ required: true, nullable: false, label: 'After' }),
|
|
403
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
404
|
+
} },
|
|
405
|
+
{ name: 'core/latest-entries', inline: true, keywords: ['posts', 'recent', 'query', 'loop'], label: 'Latest entries', icon: 'list-arrow-down', category: 'widgets', description: 'The newest published entries of a collection, kept up to date.', fields: {
|
|
406
|
+
collection: field.string({ required: true, max: 40, pattern: '[a-z][a-z0-9_]*', default: 'posts', choicesFrom: 'collections', label: 'Collection' }),
|
|
407
|
+
count: field.integer({ default: 5, min: 1, max: 24, label: 'How many' }),
|
|
408
|
+
term: field.string({ max: 80, pattern: '[A-Za-z0-9_-]*', choicesFrom: 'terms', label: 'Only with the term', description: 'A category, tag or other term; empty shows every entry.' }),
|
|
409
|
+
order: field.enum(['newest', 'oldest', 'title'], { default: 'newest', label: 'Order', choices: { newest: 'Newest first', oldest: 'Oldest first', title: 'By title' } }),
|
|
410
|
+
layout: field.enum(['list', 'grid', 'titles'], { default: 'list', label: 'Layout', choices: { list: 'List with excerpts', grid: 'Grid of cards', titles: 'Titles only' } }),
|
|
411
|
+
columns: field.integer({ default: 3, min: 1, max: 4, label: 'Columns', description: 'For the grid.' }),
|
|
412
|
+
showImage: field.boolean({ default: true, label: 'Show the featured image' }),
|
|
413
|
+
showDate: field.boolean({ default: true, label: 'Show the date' }),
|
|
414
|
+
author: field.string({ max: 80, pattern: '[A-Za-z0-9_-]*', choicesFrom: 'authors', label: 'Only by the author', description: 'Entries that name this author; empty shows every author\'s.' }),
|
|
415
|
+
offset: field.integer({ default: 0, min: 0, max: 100, label: 'Skip the first', description: 'Leaves out this many entries, for a second list that continues the first.' }),
|
|
416
|
+
excludeCurrent: field.boolean({ default: true, label: 'Leave out the entry being shown' }),
|
|
417
|
+
stickyFirst: field.boolean({ default: false, label: 'Sticky entries first' }),
|
|
418
|
+
}, variations: [
|
|
419
|
+
{ name: 'cards', label: 'Entry cards', description: 'The newest entries as a grid of cards with their images.', icon: 'card', keywords: ['posts', 'grid'], data: { layout: 'grid', columns: 3, count: 6 } },
|
|
420
|
+
] },
|
|
421
|
+
// Site blocks, the twins of helpers: a header or footer is built from them in a widget area.
|
|
422
|
+
{ name: 'core/site-logo', inline: true, keywords: ['logo', 'brand', 'site title', 'home', 'header'], label: 'Site logo', icon: 'home-2', category: 'widgets', description: 'The site\'s logo, or its title, linked to the home page.', fields: {
|
|
423
|
+
image: field.media({ label: 'Image', description: 'Empty uses the logo from Settings → General.' }),
|
|
424
|
+
showTitle: field.boolean({ default: false, label: 'Show the site title', description: 'Beside the logo; the title shows on its own when there is no logo.' }),
|
|
425
|
+
showTagline: field.boolean({ default: false, label: 'Show the tagline' }),
|
|
426
|
+
size: field.enum(['small', 'medium', 'large'], { default: 'medium', label: 'Size' }),
|
|
427
|
+
}, supports: { color: false, typography: false } },
|
|
428
|
+
{ name: 'core/search', inline: true, keywords: ['search', 'find', 'form', 'header'], label: 'Search', icon: 'magnifer', category: 'widgets', description: 'A search box that opens the site\'s search results.', fields: {
|
|
429
|
+
placeholder: field.string({ max: 80, label: 'Placeholder', description: 'Empty shows “Search”.' }),
|
|
430
|
+
style: field.enum(['box', 'icon'], { default: 'box', label: 'Style', choices: { box: 'A box', icon: 'A button that opens the box' } }),
|
|
431
|
+
suggest: field.boolean({ default: true, label: 'Suggestions', description: 'Entries show under the box while someone types.' }),
|
|
432
|
+
}, supports: { color: false, typography: ['align'] } },
|
|
433
|
+
// A menu of the theme's locations, as `helpers.menu()` renders it: dropdowns and mega panels for a header, a row for a footer, a tree for a sidebar.
|
|
434
|
+
{ name: 'core/navigation', inline: true, keywords: ['menu', 'nav', 'links', 'header', 'mega menu'], label: 'Navigation', icon: 'hamburger-menu', category: 'widgets', description: 'The menu assigned to one of the theme\'s locations.', fields: {
|
|
435
|
+
location: field.string({ required: true, max: 32, pattern: '[a-z][a-z0-9-]{0,31}', default: 'primary', choicesFrom: 'locations', label: 'Menu location', description: 'Appearance → Menus assigns a menu to each location.' }),
|
|
436
|
+
style: field.enum(['dropdowns', 'inline', 'list'], { default: 'dropdowns', label: 'Style', choices: { dropdowns: 'Header: dropdowns and mega panels', inline: 'One row of links', list: 'A list, for sidebars' } }),
|
|
437
|
+
motion: field.enum(['rise', 'fade', 'scale', 'none'], { default: 'rise', label: 'Animation', description: 'How dropdowns and mega panels open.', choices: { rise: 'Rise: fade in and lift', fade: 'Fade', scale: 'Scale from the top', none: 'None' } }),
|
|
438
|
+
mobile: field.string({ max: 32, pattern: '[a-z][a-z0-9-]{0,31}', choicesFrom: 'locations', label: 'Small screens', description: 'The location whose menu the hamburger menu shows; empty shows this menu. Header style only.' }),
|
|
439
|
+
collapse: field.enum(['md', 'lg'], { default: 'md', label: 'Collapse below', description: 'The width under which the row becomes a hamburger menu.', choices: { md: '768px: phones and small tablets', lg: '1024px: tablets too' } }),
|
|
440
|
+
}, supports: { color: false, typography: ['align'] } },
|
|
441
|
+
{ name: 'core/languages', inline: true, keywords: ['language', 'switcher', 'translations', 'locale', 'flags'], label: 'Language switcher', icon: 'global', category: 'widgets', description: 'The page in each of the site\'s languages, by name, flag or code. Shows nothing on a site with one language.', fields: {
|
|
442
|
+
style: field.enum(['names', 'flags', 'flags-names', 'codes'], { default: 'names', label: 'Show languages as', choices: { names: 'Names', flags: 'Flags', 'flags-names': 'Flags and names', codes: 'Codes' } }),
|
|
443
|
+
layout: field.enum(['inline', 'list'], { default: 'inline', label: 'Layout', choices: { inline: 'In a row', list: 'In a column' } }),
|
|
444
|
+
}, supports: { color: false, typography: ['align'] } },
|
|
445
|
+
// Data: stored with the entry, shown nowhere. Themes read `entry.content` and the API returns them.
|
|
446
|
+
{ name: 'core/meta', keywords: ['metadata', 'data', 'key value'], label: 'Custom fields', icon: 'database', category: 'data', description: 'Named values stored with the entry for themes and integrations; nothing shows on the page.', fields: {
|
|
447
|
+
fields: field.list('string', { label: 'Fields', description: 'Each as name: value.' }),
|
|
448
|
+
} },
|
|
449
|
+
// Section blocks: what page builders ship as widgets, as leaf blocks placed in columns and grids.
|
|
450
|
+
{ name: 'core/spacer', keywords: ['space', 'gap', 'whitespace', 'margin', 'empty'], label: 'Spacer', icon: 'sort-vertical', category: 'design', description: 'Empty space between blocks.', fields: {
|
|
451
|
+
size: field.enum(['small', 'medium', 'large', 'huge'], { default: 'medium', label: 'Height', choices: { small: 'Small', medium: 'Medium', large: 'Large', huge: 'Huge' } }),
|
|
452
|
+
}, supports: { color: false, spacing: false, typography: false } },
|
|
453
|
+
{ name: 'core/accordion', keywords: ['toggle', 'collapse', 'expand', 'details', 'faq'], label: 'Accordion', icon: 'list-down', category: 'design', description: 'Sections that open and close, each holding any blocks.', fields: {
|
|
454
|
+
single: field.boolean({ default: false, label: 'Open one at a time', description: 'Opening a section closes the others.' }),
|
|
455
|
+
}, children: { allowed: ['core/accordion-item'], max: 30 } },
|
|
456
|
+
{ name: 'core/accordion-item', label: 'Section', icon: 'list-down', category: 'design', parent: ['core/accordion'], fields: {
|
|
457
|
+
label: field.string({ required: true, max: 200, label: 'Title' }),
|
|
458
|
+
open: field.boolean({ default: false, label: 'Open at first' }),
|
|
459
|
+
}, children: {} },
|
|
460
|
+
{ name: 'core/icon-list', keywords: ['features', 'checklist', 'bullets', 'icons', 'benefits'], label: 'Icon list', icon: 'checklist', category: 'text', description: 'A list with an icon before each item.', fields: {
|
|
461
|
+
size: field.enum(['small', 'medium', 'large'], { default: 'medium', label: 'Size' }),
|
|
462
|
+
columns: field.integer({ default: 1, min: 1, max: 3, label: 'Columns' }),
|
|
463
|
+
}, children: { allowed: ['core/icon-item'], max: 50 } },
|
|
464
|
+
{ name: 'core/icon-item', inline: true, body: 'text', label: 'Item', icon: 'check-circle', category: 'text', parent: ['core/icon-list'], fields: {
|
|
465
|
+
icon: field.icon({ default: 'check-circle', label: 'Icon' }),
|
|
466
|
+
text: field.string({ required: true, max: 300, label: 'Text' }),
|
|
467
|
+
url: field.string({ max: 2048, pattern: LINK, label: 'Link' }),
|
|
468
|
+
} },
|
|
469
|
+
{ name: 'core/testimonial', inline: true, body: 'text', keywords: ['review', 'quote', 'customer', 'rating', 'stars'], label: 'Testimonial', icon: 'chat-round-dots', category: 'widgets', description: 'What someone said, with their name, role, photo and a star rating.', fields: {
|
|
470
|
+
text: field.text({ required: true, max: 2000, format: 'markdown', label: 'Quote' }),
|
|
471
|
+
name: field.string({ required: true, max: 120, label: 'Name' }),
|
|
472
|
+
role: field.string({ max: 160, label: 'Role', description: 'Such as a job title and a company.' }),
|
|
473
|
+
avatar: field.media({ label: 'Photo' }),
|
|
474
|
+
rating: field.integer({ default: 0, min: 0, max: 5, label: 'Stars', description: '0 shows no rating.' }),
|
|
475
|
+
url: field.string({ max: 2048, pattern: '(?:https?://\\S*)?', label: 'Source URL', description: 'Where the words were published, if anywhere.' }),
|
|
476
|
+
} },
|
|
477
|
+
{ name: 'core/stat', inline: true, body: 'label', keywords: ['counter', 'number', 'statistic', 'figure', 'count up', 'metric'], label: 'Stat', icon: 'graph', category: 'widgets', description: 'A big number with a label; it counts up as it scrolls into view.', fields: {
|
|
478
|
+
value: field.string({ required: true, max: 24, pattern: '[0-9][0-9., ]*', label: 'Number', description: 'Digits, with . , or spaces between them.' }),
|
|
479
|
+
prefix: field.string({ max: 12, label: 'Before', description: 'Such as $ or +.' }),
|
|
480
|
+
suffix: field.string({ max: 12, label: 'After', description: 'Such as % or k.' }),
|
|
481
|
+
label: field.string({ max: 120, label: 'Label' }),
|
|
482
|
+
animate: field.boolean({ default: true, label: 'Count up', description: 'Counts from zero when the block scrolls into view.' }),
|
|
483
|
+
} },
|
|
484
|
+
{ name: 'core/pricing', inline: true, body: 'name', keywords: ['price', 'plan', 'tier', 'subscription', 'pricing table'], label: 'Pricing plan', icon: 'tag', category: 'widgets', description: 'One plan of a pricing table: its price, features and button. Put plans side by side in Columns.', fields: {
|
|
485
|
+
name: field.string({ required: true, max: 80, label: 'Plan' }),
|
|
486
|
+
price: field.string({ required: true, max: 24, label: 'Price', description: 'Such as $29 or Free.' }),
|
|
487
|
+
period: field.string({ max: 40, label: 'Period', description: 'Such as per month.' }),
|
|
488
|
+
description: field.string({ max: 300, label: 'Description' }),
|
|
489
|
+
features: field.list('string', { max: 200, label: 'Features', description: 'What the plan includes.' }),
|
|
490
|
+
buttonLabel: field.string({ max: 80, label: 'Button text' }),
|
|
491
|
+
buttonUrl: field.string({ max: 2048, pattern: LINK, label: 'Button link' }),
|
|
492
|
+
highlighted: field.boolean({ default: false, label: 'Highlight', description: 'The recommended plan stands out.' }),
|
|
493
|
+
badge: field.string({ max: 40, label: 'Badge', description: 'Such as Most popular.' }),
|
|
494
|
+
} },
|
|
495
|
+
{ name: 'core/social-links', keywords: ['social', 'follow', 'facebook', 'instagram', 'x', 'linkedin', 'youtube', 'tiktok', 'icons'], label: 'Social links', icon: 'share', category: 'widgets', description: 'Links to your profiles, shown as the networks\' icons.', fields: {
|
|
496
|
+
links: field.list('string', { max: 2048, pattern: '(?:https?://|mailto:|tel:)\\S*', brand: true, label: 'Links', description: 'A profile URL per item; the icon comes from the address. mailto: and tel: links work too.' }),
|
|
497
|
+
size: field.enum(['small', 'medium', 'large'], { default: 'medium', label: 'Size' }),
|
|
498
|
+
shape: field.enum(['round', 'square', 'plain'], { default: 'round', label: 'Shape', choices: { round: 'Round buttons', square: 'Square buttons', plain: 'Icons only' } }),
|
|
499
|
+
labels: field.boolean({ default: false, label: 'Show names' }),
|
|
500
|
+
}, supports: { typography: ['align'] } },
|
|
501
|
+
{ name: 'core/map', inline: true, keywords: ['google maps', 'openstreetmap', 'location', 'address', 'directions'], label: 'Map', icon: 'map', category: 'embeds', description: 'A map of an address from Google Maps, or an embed from Google Maps or OpenStreetMap. It loads from their servers.', fields: {
|
|
502
|
+
address: field.string({ max: 300, label: 'Address', description: 'A place or an address Google Maps finds; empty shows the embed URL.' }),
|
|
503
|
+
url: field.string({ max: 4096, pattern: `(?:${MAP_EMBED_URL.source.slice(1, -1)})?`, label: 'Embed URL', description: 'The src of the iframe Google Maps or OpenStreetMap give under Share → Embed a map.' }),
|
|
504
|
+
zoom: field.integer({ default: 14, min: 1, max: 20, label: 'Zoom', description: 'For an address: 1 shows the world, 20 a building.' }),
|
|
505
|
+
height: field.enum(['short', 'medium', 'tall'], { default: 'medium', label: 'Height' }),
|
|
506
|
+
caption: field.string({ max: 300, label: 'Caption' }),
|
|
507
|
+
align: WIDTH,
|
|
508
|
+
}, supports: { color: false } },
|
|
509
|
+
{ name: 'core/notice', inline: true, body: 'text', keywords: ['alert', 'callout', 'message box', 'warning', 'info', 'tip', 'note'], label: 'Notice', icon: 'info-circle', category: 'text', description: 'A short message set apart: a tip, a success, a warning or an error.', fields: {
|
|
510
|
+
kind: field.enum(['info', 'success', 'warning', 'danger'], { default: 'info', label: 'Kind', choices: { info: 'Information', success: 'Success', warning: 'Warning', danger: 'Error' } }),
|
|
511
|
+
title: field.string({ max: 120, label: 'Title' }),
|
|
512
|
+
text: field.text({ required: true, max: 2000, format: 'markdown', label: 'Text' }),
|
|
513
|
+
showIcon: field.boolean({ default: true, label: 'Show the icon' }),
|
|
514
|
+
} },
|
|
515
|
+
{ name: 'core/countdown', keywords: ['timer', 'launch', 'sale', 'event', 'deadline'], label: 'Countdown', icon: 'hourglass', category: 'widgets', description: 'Days, hours, minutes and seconds left until a moment.', fields: {
|
|
516
|
+
until: field.datetime({ required: true, label: 'Counts down to' }),
|
|
517
|
+
label: field.string({ max: 160, label: 'Label', description: 'Shown above the numbers.' }),
|
|
518
|
+
done: field.string({ max: 200, label: 'When it ends', description: 'Shown in place of the numbers once the moment has passed.' }),
|
|
519
|
+
seconds: field.boolean({ default: true, label: 'Show seconds' }),
|
|
520
|
+
} },
|
|
521
|
+
{ name: 'core/toc', keywords: ['table of contents', 'contents', 'outline', 'jump links', 'anchors'], label: 'Table of contents', icon: 'list-arrow-down', category: 'text', description: 'Links to the headings of this entry, kept up to date.', fields: {
|
|
522
|
+
title: field.string({ max: 80, default: 'Contents', label: 'Title' }),
|
|
523
|
+
depth: field.enum(['h2', 'h3', 'h4'], { default: 'h3', label: 'Down to', choices: { h2: 'Main headings', h3: 'Sub-headings too', h4: 'Every heading' } }),
|
|
524
|
+
numbered: field.boolean({ default: false, label: 'Numbered' }),
|
|
525
|
+
} },
|
|
526
|
+
{ name: 'core/share', keywords: ['share', 'social', 'facebook', 'x', 'linkedin', 'whatsapp', 'email', 'copy link'], label: 'Share buttons', icon: 'share', category: 'widgets', description: 'Buttons that share this page on social networks, by email, or copy its address.', fields: {
|
|
527
|
+
networks: field.enum([...SHARE_NETWORKS], { multiple: true, default: ['facebook', 'x', 'linkedin', 'email', 'copy'], label: 'Networks', choices: { facebook: 'Facebook', x: 'X', linkedin: 'LinkedIn', whatsapp: 'WhatsApp', telegram: 'Telegram', reddit: 'Reddit', pinterest: 'Pinterest', bluesky: 'Bluesky', threads: 'Threads', email: 'Email', copy: 'Copy link' } }),
|
|
528
|
+
label: field.string({ max: 60, default: 'Share', label: 'Label', description: 'Shown before the buttons; empty for none.' }),
|
|
529
|
+
style: field.enum(['icons', 'labels'], { default: 'icons', label: 'Style', choices: { icons: 'Icons', labels: 'Icons with names' } }),
|
|
530
|
+
}, supports: { typography: ['align'] } },
|
|
531
|
+
{ name: 'core/breadcrumbs', inline: true, keywords: ['trail', 'path', 'navigation', 'where am i'], label: 'Breadcrumbs', icon: 'structure', category: 'widgets', description: 'The way to this page: home, the section, the parents.', fields: {
|
|
532
|
+
home: field.boolean({ default: true, label: 'Show Home' }),
|
|
533
|
+
separator: field.enum(['chevron', 'slash', 'arrow'], { default: 'chevron', label: 'Separator', choices: { chevron: '›', slash: '/', arrow: '→' } }),
|
|
534
|
+
}, supports: { color: false, typography: ['align'] } },
|
|
535
|
+
// Layout: containers that hold other blocks, and may align the text of what they hold. They render as CSS grid and respond to the
|
|
536
|
+
// width of the content they are in, so columns inside a column stack on their own.
|
|
537
|
+
// A group is also the section and the hero: a full-width band with a background from its Style
|
|
538
|
+
// tab keeps its children at the content width, and a height with a vertical alignment centers them.
|
|
539
|
+
{ name: 'core/group', inline: true, keywords: ['container', 'section', 'stack', 'row', 'hero', 'banner'], label: 'Group', icon: 'layers', category: 'design', description: 'A stack of blocks with one width, or a row of them. Full width makes a band across the page.', fields: {
|
|
540
|
+
align: field.enum(['content', 'wide', 'full', 'center', 'left', 'right'], { default: 'content', label: 'Width', description: 'Full width spans the page; the blocks inside keep the content width.', choices: { content: 'Content width', wide: 'Wide', full: 'Full width', center: 'Narrow, centered', left: 'Narrow, left', right: 'Narrow, right' } }),
|
|
541
|
+
direction: field.enum(['column', 'row'], { default: 'column', label: 'Direction', choices: { column: 'Stacked', row: 'In a row' } }),
|
|
542
|
+
justify: field.enum(['start', 'center', 'end', 'between'], { default: 'start', label: 'Justify', description: 'Where the blocks of a row sit.', choices: { start: 'Start', center: 'Center', end: 'End', between: 'Spread out' } }),
|
|
543
|
+
height: field.enum(['auto', 'short', 'medium', 'tall', 'screen'], { default: 'auto', label: 'Height', description: 'At least this tall, for banners and heroes.', choices: { auto: 'Fits the blocks', short: 'Short', medium: 'Medium', tall: 'Tall', screen: 'The whole screen' } }),
|
|
544
|
+
valign: field.enum(['top', 'center', 'bottom'], { default: 'top', label: 'Vertical alignment', description: 'Where the blocks sit when the group is taller than them.' }),
|
|
545
|
+
}, children: {}, supports: { background: true, typography: ['align'] }, variations: [
|
|
546
|
+
{ name: 'hero', label: 'Hero', description: 'A band across the page, at least medium tall, its blocks centered. Give it a background under Style.', icon: 'gallery-wide', keywords: ['cover', 'banner', 'jumbotron', 'call to action'], data: { align: 'full', height: 'medium', valign: 'center' } },
|
|
547
|
+
{ name: 'row', label: 'Row', description: 'Blocks side by side in one line, spread out.', icon: 'widget-2', keywords: ['inline', 'toolbar', 'buttons'], data: { direction: 'row', justify: 'between' } },
|
|
548
|
+
] },
|
|
549
|
+
{ name: 'core/columns', inline: true, keywords: ['row', 'side by side', 'layout'], label: 'Columns', icon: 'widget-2', category: 'design', description: 'Blocks side by side; they stack on small screens.', fields: {
|
|
550
|
+
gap: GAP,
|
|
551
|
+
stack: field.enum(['mobile', 'tablet', 'never'], { default: 'mobile', label: 'Stack', choices: { mobile: 'On phones', tablet: 'On phones and tablets', never: 'Never' } }),
|
|
552
|
+
align: WIDTH,
|
|
553
|
+
}, children: { allowed: ['core/column'], max: 6 }, supports: { background: true, typography: ['align'] } },
|
|
554
|
+
{ name: 'core/column', inline: true, label: 'Column', icon: 'widget', category: 'design', parent: ['core/columns'], fields: {
|
|
555
|
+
span: field.integer({ min: 1, max: 12, label: 'Width', description: 'Out of 12; empty shares the space equally.' }),
|
|
556
|
+
verticalAlign: field.enum(['top', 'center', 'bottom'], { default: 'top', label: 'Vertical alignment' }),
|
|
557
|
+
}, children: {}, supports: { background: true, typography: ['align'] } },
|
|
558
|
+
{ name: 'core/grid', inline: true, keywords: ['cells', 'layout'], label: 'Grid', icon: 'widget-3', category: 'design', description: 'Blocks in equal cells.', fields: {
|
|
559
|
+
columns: field.integer({ default: 3, min: 1, max: 6, label: 'Columns' }),
|
|
560
|
+
columnsMd: field.integer({ default: 2, min: 1, max: 6, label: 'Columns on tablets' }),
|
|
561
|
+
columnsSm: field.integer({ default: 1, min: 1, max: 6, label: 'Columns on phones' }),
|
|
562
|
+
gap: GAP,
|
|
563
|
+
align: WIDTH,
|
|
564
|
+
}, children: { max: 24 }, supports: { background: true, typography: ['align'] } },
|
|
565
|
+
// Tabs: one panel shown at a time. In a field group they are the dashboard's tabs.
|
|
566
|
+
{ name: 'core/tabs', keywords: ['panels'], label: 'Tabs', icon: 'window-frame', category: 'design', description: 'Panels shown one at a time.', fields: {}, children: { allowed: ['core/tab'], max: 12 } },
|
|
567
|
+
{ name: 'core/tab', label: 'Tab', icon: 'tuning-square', category: 'design', parent: ['core/tabs'], fields: {
|
|
568
|
+
label: field.string({ required: true, max: 80, label: 'Label' }),
|
|
569
|
+
icon: field.icon({ label: 'Icon' }),
|
|
570
|
+
}, children: {} },
|
|
571
|
+
// A synced pattern: the site renders the pattern's current content in its place.
|
|
572
|
+
{ name: 'core/pattern', label: 'Pattern', icon: 'widget-add', category: 'design', description: 'A synced pattern.', fields: {
|
|
573
|
+
pattern: field.string({ required: true, max: 80, pattern: '[A-Za-z0-9_-]{1,80}', label: 'Pattern' }),
|
|
574
|
+
} },
|
|
575
|
+
];
|
|
576
|
+
export const CORE_BLOCKS: readonly BlockDeclaration[] = Object.freeze(core);
|
|
577
|
+
|
|
578
|
+
/** Problems in a block type declaration; empty when valid. */
|
|
579
|
+
export function blockProblems(declaration: BlockDeclaration, owner?: string): string[] {
|
|
580
|
+
const problems: string[] = [];
|
|
581
|
+
const at = `block ${String(declaration?.name)}`;
|
|
582
|
+
if (typeof declaration?.name !== 'string' || !BLOCK_NAME.test(declaration.name)) problems.push(`${at}: names are <owner>/<name> in lowercase with hyphens.`);
|
|
583
|
+
else if (owner && !declaration.name.startsWith(`${owner}/`)) problems.push(`${at}: must be named ${owner}/<name>.`);
|
|
584
|
+
if (typeof declaration?.label !== 'string' || !declaration.label.trim() || declaration.label.length > 80) problems.push(`${at}: needs a label of at most 80 characters.`);
|
|
585
|
+
if (declaration?.icon !== undefined && (typeof declaration.icon !== 'string' || declaration.icon.length > 60 || !ICON_NAME.test(declaration.icon))) problems.push(`${at}: icons are Solar icon names, such as text-field.`);
|
|
586
|
+
if (declaration?.keywords !== undefined && (!Array.isArray(declaration.keywords) || declaration.keywords.length > 12 || declaration.keywords.some(word => typeof word !== 'string' || !word.trim() || word.length > 40))) problems.push(`${at}: keywords are at most 12 words of at most 40 characters.`);
|
|
587
|
+
if (declaration?.common !== undefined && typeof declaration.common !== 'boolean') problems.push(`${at}: common is on or off.`);
|
|
588
|
+
if (declaration?.common && (declaration.input || declaration.field)) problems.push(`${at}: an input or field block cannot be common.`);
|
|
589
|
+
if (declaration?.category !== undefined && !BLOCK_CATEGORIES.some(category => category.id === declaration.category)) {
|
|
590
|
+
problems.push(`${at}: the category is one of ${BLOCK_CATEGORIES.map(category => category.id).join(', ')}.`);
|
|
591
|
+
}
|
|
592
|
+
const fields = Object.entries(declaration?.fields ?? {});
|
|
593
|
+
if (fields.length > 16) problems.push(`${at}: declare at most 16 fields.`);
|
|
594
|
+
for (const [name, entry] of fields) {
|
|
595
|
+
if (!entry || typeof entry !== 'object') { problems.push(`${at}: field ${name} must be a field declaration.`); continue; }
|
|
596
|
+
if (!BLOCK_FIELD_KINDS.has(entry.kind)) problems.push(`${at}: field ${name} cannot be ${entry.kind}.`);
|
|
597
|
+
if (entry.unique || entry.index || entry.search || entry.slugFrom || entry.taxonomy) problems.push(`${at}: field ${name} cannot be indexed, searched or derived.`);
|
|
598
|
+
// As a resource's fields are checked: a bad pattern or an enum without values would otherwise fail every write of the block.
|
|
599
|
+
else problems.push(...fieldProblems(name, entry).map(problem => `${at}: ${problem}`));
|
|
600
|
+
}
|
|
601
|
+
if (declaration?.inline !== undefined && typeof declaration.inline !== 'boolean') problems.push(`${at}: inline is true or false.`);
|
|
602
|
+
if (declaration?.body !== undefined) {
|
|
603
|
+
const target = typeof declaration.body === 'string' ? declaration.fields?.[declaration.body] : undefined;
|
|
604
|
+
if (!target || (target.kind !== 'string' && target.kind !== 'text') || target.media) problems.push(`${at}: body names one of its string or text fields.`);
|
|
605
|
+
if (declaration.children !== undefined) problems.push(`${at}: a container takes its body as children; it declares no body field.`);
|
|
606
|
+
}
|
|
607
|
+
const children = declaration?.children;
|
|
608
|
+
if (children !== undefined) {
|
|
609
|
+
if (!children || typeof children !== 'object' || Array.isArray(children)) problems.push(`${at}: children is an object.`);
|
|
610
|
+
else {
|
|
611
|
+
if (children.allowed !== undefined && (!Array.isArray(children.allowed) || !children.allowed.every(name => typeof name === 'string' && BLOCK_NAME.test(name)))) problems.push(`${at}: children.allowed lists block names.`);
|
|
612
|
+
if (children.max !== undefined && (!Number.isInteger(children.max) || children.max < 1 || children.max > BLOCK_LIMITS.count)) problems.push(`${at}: children.max is 1 to ${BLOCK_LIMITS.count}.`);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
const input = declaration?.input;
|
|
616
|
+
if (input !== undefined) {
|
|
617
|
+
if (!input || typeof input !== 'object' || !(INPUT_KINDS as readonly string[]).includes(input.kind)) problems.push(`${at}: input.kind is one of ${INPUT_KINDS.join(', ')}.`);
|
|
618
|
+
if (declaration.fields?.name?.kind !== 'string' || declaration.fields?.label?.kind !== 'string') problems.push(`${at}: an input block declares string fields name and label.`);
|
|
619
|
+
if (declaration.children !== undefined && input.kind !== 'rows') problems.push(`${at}: an input block cannot hold blocks.`);
|
|
620
|
+
if (input.kind === 'rows' && declaration.children === undefined) problems.push(`${at}: a rows input holds the inputs of a row; declare children.`);
|
|
621
|
+
}
|
|
622
|
+
if (declaration?.parent !== undefined && (!Array.isArray(declaration.parent) || !declaration.parent.length || !declaration.parent.every(name => typeof name === 'string' && BLOCK_NAME.test(name)))) {
|
|
623
|
+
problems.push(`${at}: parent lists block names.`);
|
|
624
|
+
}
|
|
625
|
+
const variations = declaration?.variations;
|
|
626
|
+
if (variations !== undefined) {
|
|
627
|
+
if (!Array.isArray(variations) || variations.length > 12) problems.push(`${at}: variations lists at most 12 variations.`);
|
|
628
|
+
else {
|
|
629
|
+
const names = new Set<string>();
|
|
630
|
+
for (const variation of variations) {
|
|
631
|
+
const label = `${at}: variation ${String(variation?.name)}`;
|
|
632
|
+
if (!variation || typeof variation !== 'object' || typeof variation.name !== 'string' || !VARIATION_NAME.test(variation.name) || variation.name.length > 40) { problems.push(`${at}: variations are named in lowercase with hyphens.`); continue; }
|
|
633
|
+
if (names.has(variation.name)) problems.push(`${label} is declared twice.`);
|
|
634
|
+
names.add(variation.name);
|
|
635
|
+
if (typeof variation.label !== 'string' || !variation.label.trim() || variation.label.length > 80) problems.push(`${label}: needs a label of at most 80 characters.`);
|
|
636
|
+
if (variation.description !== undefined && (typeof variation.description !== 'string' || variation.description.length > 300)) problems.push(`${label}: the description is at most 300 characters.`);
|
|
637
|
+
if (variation.icon !== undefined && (typeof variation.icon !== 'string' || !ICON_NAME.test(variation.icon) || variation.icon.length > 60)) problems.push(`${label}: icons are Solar icon names.`);
|
|
638
|
+
if (variation.keywords !== undefined && (!Array.isArray(variation.keywords) || variation.keywords.length > 12 || variation.keywords.some((word: unknown) => typeof word !== 'string' || !word.trim() || word.length > 40))) problems.push(`${label}: keywords are at most 12 words of at most 40 characters.`);
|
|
639
|
+
if (!variation.data || typeof variation.data !== 'object' || Array.isArray(variation.data)) problems.push(`${label}: data is an object of field values.`);
|
|
640
|
+
else for (const field of Object.keys(variation.data)) if (!declaration.fields || !Object.hasOwn(declaration.fields, field)) problems.push(`${label}: data names ${field}, which is not a field of the block.`);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const supports = declaration?.supports;
|
|
645
|
+
if (supports !== undefined) {
|
|
646
|
+
if (!supports || typeof supports !== 'object' || Array.isArray(supports)) problems.push(`${at}: supports is an object.`);
|
|
647
|
+
else for (const [kind, support] of Object.entries(supports)) {
|
|
648
|
+
const known = (SUPPORT_KINDS as Record<string, readonly string[] | undefined>)[kind];
|
|
649
|
+
if (!known) problems.push(`${at}: supports has no ${kind}; it takes ${Object.keys(SUPPORT_KINDS).join(', ')}.`);
|
|
650
|
+
else if (typeof support !== 'boolean' && (!Array.isArray(support) || !support.every(property => known.includes(property as string)))) problems.push(`${at}: supports.${kind} is true, false or some of ${known.join(', ')}.`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return problems;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Whether `type` may go directly inside a block of `parent` (null for the top level), by their declarations. */
|
|
657
|
+
export function blockAllowedIn(types: ReadonlyMap<string, BlockDeclaration>, type: string, parent: string | null): boolean {
|
|
658
|
+
const declaration = types.get(type);
|
|
659
|
+
if (!declaration) return false;
|
|
660
|
+
if (declaration.parent && (!parent || !declaration.parent.includes(parent))) return false;
|
|
661
|
+
if (parent === null) return true;
|
|
662
|
+
const container = types.get(parent)?.children;
|
|
663
|
+
return !!container && (!container.allowed || container.allowed.includes(type));
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export interface ValidateBlocksOptions {
|
|
667
|
+
/** Block types allowed at the top level; all when empty. */
|
|
668
|
+
readonly allowed?: readonly string[];
|
|
669
|
+
/** The field holds a form: input blocks and conditions are allowed, and checked as a whole. */
|
|
670
|
+
readonly form?: boolean;
|
|
671
|
+
/**
|
|
672
|
+
* The blocks are a field group: field blocks and layout blocks alone, conditions allowed,
|
|
673
|
+
* names from labels and distinct across the group, rows included. `scope` names fields of
|
|
674
|
+
* the target a condition may test besides the group's own.
|
|
675
|
+
*/
|
|
676
|
+
readonly fieldGroup?: boolean | { readonly scope?: readonly string[] };
|
|
677
|
+
/** The blocks were written inside text as references: references inside them are not parsed again. */
|
|
678
|
+
readonly inText?: boolean;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Validate blocks against their types. Returns the blocks with defaults applied and unknown
|
|
683
|
+
* data removed, or errors keyed by `<block id>.<field>`, or `<block id>` for a block that is
|
|
684
|
+
* not available or does not fit where it is. In a form, an input without a name takes one
|
|
685
|
+
* from its label; names must be distinct and conditions must name the form's inputs.
|
|
686
|
+
*/
|
|
687
|
+
export function validateBlocks(value: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>, options: ValidateBlocksOptions = {}): { blocks: Block[]; errors: { [path: string]: string } } {
|
|
688
|
+
const errors: { [path: string]: string } = {};
|
|
689
|
+
const { allowed, form = false } = options;
|
|
690
|
+
const fieldGroup = options.fieldGroup !== undefined && options.fieldGroup !== false;
|
|
691
|
+
const conditional = form || fieldGroup;
|
|
692
|
+
// Names given in the tree, so a name taken from a label does not take one of them.
|
|
693
|
+
const named = (block: Block) => form ? !!types.get(block.type)?.input : fieldGroup ? !!types.get(block.type)?.field : false;
|
|
694
|
+
const taken = new Set(conditional ? flattenBlocks(value).filter(named).map(block => block.data.name).filter((name): name is string => typeof name === 'string' && name.trim() !== '') : []);
|
|
695
|
+
const visit = (list: readonly Block[], parent: string | null): Block[] => {
|
|
696
|
+
const blocks: Block[] = [];
|
|
697
|
+
for (const block of list) {
|
|
698
|
+
const type = types.get(block.type);
|
|
699
|
+
if (!type || (parent === null && allowed && allowed.length && !allowed.includes(block.type))) { errors[block._id] = `${block.type} is not an available block.`; continue; }
|
|
700
|
+
if (!blockAllowedIn(types, block.type, parent)) { errors[block._id] = parent ? `${block.type} cannot go inside ${parent}.` : `${block.type} goes inside ${type.parent?.join(' or ')}.`; continue; }
|
|
701
|
+
if (type.input && !form) { errors[block._id] = `${block.type} goes only in a form.`; continue; }
|
|
702
|
+
if (type.field && !fieldGroup) { errors[block._id] = `${block.type} goes only in a field group.`; continue; }
|
|
703
|
+
if (fieldGroup && !type.field && !type.common && !FIELD_GROUP_LAYOUT.has(block.type)) { errors[block._id] = `${block.type} does not go in a field group.`; continue; }
|
|
704
|
+
if (block.when !== undefined && !conditional) { errors[block._id] = 'conditions apply only in forms and field groups.'; continue; }
|
|
705
|
+
let source = block.data;
|
|
706
|
+
if (named(block) && (typeof source.name !== 'string' || !source.name.trim())) {
|
|
707
|
+
const name = uniqueInputName(inputName(typeof source.label === 'string' ? source.label : ''), taken);
|
|
708
|
+
taken.add(name);
|
|
709
|
+
source = { ...source, name };
|
|
710
|
+
}
|
|
711
|
+
const data: { [field: string]: unknown } = {};
|
|
712
|
+
for (const [name, declaration] of Object.entries(type.fields)) {
|
|
713
|
+
const entry = source[name];
|
|
714
|
+
if (entry === undefined || entry === '' || entry === null) {
|
|
715
|
+
if (declaration.default !== undefined) data[name] = declaration.default;
|
|
716
|
+
else if (declaration.required) errors[`${block._id}.${name}`] = 'is required.';
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
const error = validateValue(name, declaration, entry) ?? textProblem(declaration, entry, types, `${block._id}-`, options.inText === true);
|
|
720
|
+
if (error) { errors[`${block._id}.${name}`] = error; continue; }
|
|
721
|
+
if (declaration.kind === 'richtext') {
|
|
722
|
+
// Blocks a rich-text value embeds are checked like any others.
|
|
723
|
+
const doc = normalizeRichText(entry);
|
|
724
|
+
const checked = validateBlocks(richTextBlocks(doc), types, { inText: options.inText === true });
|
|
725
|
+
const [path, message] = Object.entries(checked.errors)[0] ?? [];
|
|
726
|
+
if (path) errors[`${block._id}.${name}`] = `a block is invalid: ${path} ${message}`;
|
|
727
|
+
else data[name] = withRichTextBlocks(doc, checked.blocks);
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
data[name] = entry;
|
|
731
|
+
}
|
|
732
|
+
const children = block.children ?? [];
|
|
733
|
+
if (children.length && !type.children) { errors[block._id] = `${block.type} does not hold blocks.`; continue; }
|
|
734
|
+
if (type.children?.max !== undefined && children.length > type.children.max) { errors[block._id] = `holds at most ${type.children.max} blocks.`; continue; }
|
|
735
|
+
const layout = blockLayoutOf(block);
|
|
736
|
+
const style = blockStyleOf(block, blockSupports(type));
|
|
737
|
+
const when = block.when ? blockConditionOf(block.when) : undefined;
|
|
738
|
+
blocks.push(Object.freeze({
|
|
739
|
+
_id: block._id, type: block.type, data: Object.freeze(data),
|
|
740
|
+
...(layout ? { layout } : {}),
|
|
741
|
+
...(style ? { style } : {}),
|
|
742
|
+
...(when ? { when } : {}),
|
|
743
|
+
...(type.children ? { children: Object.freeze(visit(children, block.type)) } : {}),
|
|
744
|
+
}));
|
|
745
|
+
}
|
|
746
|
+
return blocks;
|
|
747
|
+
};
|
|
748
|
+
const blocks = visit(value, null);
|
|
749
|
+
if (form) Object.assign(errors, formTreeErrors(blocks, types));
|
|
750
|
+
if (fieldGroup) Object.assign(errors, fieldGroupTreeErrors(blocks, types, typeof options.fieldGroup === 'object' ? options.fieldGroup.scope ?? [] : []));
|
|
751
|
+
return { blocks, errors };
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Why a record's Markdown field is refused: a block reference that is not a valid block, as
|
|
756
|
+
* in a block's own Markdown. The site renders references in both alike.
|
|
757
|
+
*/
|
|
758
|
+
export function textFieldProblem(declaration: FieldDeclaration, value: unknown, types: ReadonlyMap<string, BlockDeclaration>): string | undefined {
|
|
759
|
+
if (typeof value !== 'string' || declaration.kind !== 'text' || declaration.format !== 'markdown' || declaration.media || !hasBlockReference(value)) return undefined;
|
|
760
|
+
return markdownBlocksProblem(value, types, '');
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Why a text value is refused although its declaration takes it: a binding to an unknown scope,
|
|
765
|
+
* or, in Markdown, a block reference that is not a valid block (see `parseBlockText`).
|
|
766
|
+
*/
|
|
767
|
+
function textProblem(declaration: FieldDeclaration, value: unknown, types: ReadonlyMap<string, BlockDeclaration>, prefix: string, inText: boolean): string | undefined {
|
|
768
|
+
if (typeof value !== 'string' || (declaration.kind !== 'string' && declaration.kind !== 'text') || declaration.media) return undefined;
|
|
769
|
+
const binding = bindingProblem(value);
|
|
770
|
+
if (binding) return binding;
|
|
771
|
+
if (inText || declaration.kind !== 'text' || declaration.format !== 'markdown' || !hasBlockReference(value)) return undefined;
|
|
772
|
+
return markdownBlocksProblem(value, types, prefix);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function markdownBlocksProblem(value: string, types: ReadonlyMap<string, BlockDeclaration>, prefix: string): string | undefined {
|
|
776
|
+
const parsed = parseBlockText(value, types, prefix);
|
|
777
|
+
if (parsed.problems.length) return parsed.problems[0];
|
|
778
|
+
const { errors } = validateBlocks(textBlocks(parsed), types, { inText: true });
|
|
779
|
+
const [path, message] = Object.entries(errors)[0] ?? [];
|
|
780
|
+
return path ? `a block reference is invalid: ${path.split('.').slice(1).join('.') || 'block'} ${message}` : undefined;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Core blocks a field group lays its fields out with. They render as dashboard UI there. */
|
|
784
|
+
export const FIELD_GROUP_LAYOUT: ReadonlySet<string> = new Set(['core/group', 'core/columns', 'core/column', 'core/grid', 'core/tabs', 'core/tab', 'core/heading', 'core/paragraph', 'core/divider']);
|
|
785
|
+
/** Fields a group holds at most, rows included. */
|
|
786
|
+
export const FIELD_GROUP_LIMIT = 96;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* A field group's own rules: at most 96 fields, names distinct across the group (rows
|
|
790
|
+
* included) and not a target's own, conditions naming fields in reach: the group's at the
|
|
791
|
+
* same or an outer row level, and `scope`'s.
|
|
792
|
+
*/
|
|
793
|
+
function fieldGroupTreeErrors(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>, scope: readonly string[]): { [path: string]: string } {
|
|
794
|
+
const errors: { [path: string]: string } = {};
|
|
795
|
+
const fields = flattenBlocks(blocks).filter(block => types.get(block.type)?.field);
|
|
796
|
+
if (fields.length > FIELD_GROUP_LIMIT) errors[fields[FIELD_GROUP_LIMIT]!._id] = `A field group holds at most ${FIELD_GROUP_LIMIT} fields.`;
|
|
797
|
+
// A row's field sits inside its row, so only a top-level field can take a name the target has.
|
|
798
|
+
const inRows = new Set(fields.filter(block => types.get(block.type)?.field?.kind === 'repeater').flatMap(block => flattenBlocks(block.children ?? []).map(child => child._id)));
|
|
799
|
+
const named = new Map<string, Block>();
|
|
800
|
+
for (const block of fields) {
|
|
801
|
+
const name = block.data.name as string;
|
|
802
|
+
if (RESERVED_FIELD_NAMES.has(name) || (scope.includes(name) && !inRows.has(block._id))) errors[`${block._id}.name`] = 'is used by the target itself.';
|
|
803
|
+
else if (named.has(name)) errors[`${block._id}.name`] = 'is used by another field.';
|
|
804
|
+
else named.set(name, block);
|
|
805
|
+
}
|
|
806
|
+
// The names in reach of a row level: the outer levels' and its own, whatever the order.
|
|
807
|
+
const visit = (list: readonly Block[], visible: ReadonlySet<string>) => {
|
|
808
|
+
const here = new Set(visible);
|
|
809
|
+
const collect = (items: readonly Block[]) => {
|
|
810
|
+
for (const block of items) {
|
|
811
|
+
const type = types.get(block.type);
|
|
812
|
+
if (type?.field) here.add(block.data.name as string);
|
|
813
|
+
if (block.children && !type?.field) collect(block.children);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
collect(list);
|
|
817
|
+
const check = (items: readonly Block[]) => {
|
|
818
|
+
for (const block of items) {
|
|
819
|
+
const type = types.get(block.type);
|
|
820
|
+
for (const rule of block.when?.rules ?? []) {
|
|
821
|
+
if (!here.has(rule.field)) errors[block._id] = `shows on ${rule.field}, which is not a field in reach.`;
|
|
822
|
+
else if (named.get(rule.field) === block) errors[block._id] = 'cannot show on its own value.';
|
|
823
|
+
}
|
|
824
|
+
if (!block.children) continue;
|
|
825
|
+
if (type?.field) visit(block.children, here);
|
|
826
|
+
else check(block.children);
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
check(list);
|
|
830
|
+
};
|
|
831
|
+
visit(blocks, new Set(scope));
|
|
832
|
+
return errors;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/** Field names every record keeps for itself; a target's own fields come through `scope`. */
|
|
836
|
+
export const RESERVED_FIELD_NAMES: ReadonlySet<string> = new Set(['id', 'rev', 'owner', 'createdAt', 'updatedAt', 'meta', '_id']);
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* A form's own rules: at most 48 inputs, names distinct within their scope (the form, or one
|
|
840
|
+
* repeater's rows) and not reserved, repeaters one level deep, conditions on inputs in reach:
|
|
841
|
+
* the form's for a block of the form, a row's own and then the form's for a block in a repeater.
|
|
842
|
+
*/
|
|
843
|
+
function formTreeErrors(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>): { [path: string]: string } {
|
|
844
|
+
const errors: { [path: string]: string } = {};
|
|
845
|
+
const all = flattenBlocks(blocks);
|
|
846
|
+
const inputs = all.filter(block => types.get(block.type)?.input);
|
|
847
|
+
if (inputs.length > FORM_INPUT_LIMIT) errors[inputs[FORM_INPUT_LIMIT]!._id] = `A form holds at most ${FORM_INPUT_LIMIT} fields.`;
|
|
848
|
+
const repeater = (block: Block) => types.get(block.type)?.input?.kind === 'rows';
|
|
849
|
+
const scopes = new Map<string, Map<string, Block>>();
|
|
850
|
+
const names = (list: readonly Block[], into: Map<string, Block>, inside: boolean) => {
|
|
851
|
+
for (const block of list) {
|
|
852
|
+
if (types.get(block.type)?.input) {
|
|
853
|
+
const name = block.data.name as string;
|
|
854
|
+
if (RESERVED_INPUT_NAMES.has(name)) errors[`${block._id}.name`] = 'is reserved for the submission.';
|
|
855
|
+
else if (into.has(name)) errors[`${block._id}.name`] = 'is used by another field.';
|
|
856
|
+
else into.set(name, block);
|
|
857
|
+
// Uploads are kept per submission, at its top level.
|
|
858
|
+
if (inside && types.get(block.type)?.input?.kind === 'file') errors[block._id] = 'A file upload cannot go in a repeater.';
|
|
859
|
+
}
|
|
860
|
+
if (repeater(block)) {
|
|
861
|
+
if (inside) { errors[block._id] = 'A repeater cannot hold another repeater.'; continue; }
|
|
862
|
+
const own = new Map<string, Block>();
|
|
863
|
+
names(block.children ?? [], own, true);
|
|
864
|
+
scopes.set(block._id, own);
|
|
865
|
+
} else if (block.children) names(block.children, into, inside);
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
const top = new Map<string, Block>();
|
|
869
|
+
names(blocks, top, false);
|
|
870
|
+
const check = (list: readonly Block[], own: ReadonlyMap<string, Block> | null) => {
|
|
871
|
+
for (const block of list) {
|
|
872
|
+
for (const rule of block.when?.rules ?? []) {
|
|
873
|
+
const target = own?.get(rule.field) ?? top.get(rule.field);
|
|
874
|
+
if (!target) errors[block._id] = `shows on ${rule.field}, which is not a field ${own ? 'in reach' : 'of this form'}.`;
|
|
875
|
+
else if (target === block) errors[block._id] = 'cannot show on its own value.';
|
|
876
|
+
}
|
|
877
|
+
if (repeater(block)) check(block.children ?? [], scopes.get(block._id) ?? new Map());
|
|
878
|
+
else if (block.children) check(block.children, own);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
check(blocks, null);
|
|
882
|
+
return errors;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/** An input name from a label: camel case, starting with a letter, at most 40 characters. */
|
|
886
|
+
export function inputName(label: string): string {
|
|
887
|
+
const words = slugify(label, 80).split('-').filter(Boolean);
|
|
888
|
+
let name = words.map((word, index) => index ? word.charAt(0).toUpperCase() + word.slice(1) : word).join('');
|
|
889
|
+
if (!/^[a-z]/.test(name)) name = `field${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
890
|
+
name = name.slice(0, 40);
|
|
891
|
+
return RESERVED_INPUT_NAMES.has(name) ? `${name}Field` : name;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/** `name`, or `name2`, `name3`, … when it is taken. */
|
|
895
|
+
function uniqueInputName(name: string, taken: ReadonlySet<string>): string {
|
|
896
|
+
if (!taken.has(name)) return name;
|
|
897
|
+
for (let suffix = 2; ; suffix++) {
|
|
898
|
+
const candidate = `${name.slice(0, 40 - String(suffix).length)}${suffix}`;
|
|
899
|
+
if (!taken.has(candidate)) return candidate;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** A condition with its defaults left out and values dropped where the operator takes none. */
|
|
904
|
+
function blockConditionOf(when: BlockCondition): BlockCondition {
|
|
905
|
+
return Object.freeze({
|
|
906
|
+
...(when.action === 'hide' ? { action: 'hide' as const } : {}),
|
|
907
|
+
...(when.match === 'any' ? { match: 'any' as const } : {}),
|
|
908
|
+
rules: Object.freeze(when.rules.map(rule => Object.freeze({
|
|
909
|
+
field: rule.field, op: rule.op,
|
|
910
|
+
...(rule.op !== 'empty' && rule.op !== 'notEmpty' && rule.value !== undefined ? { value: rule.value } : {}),
|
|
911
|
+
}))),
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** A block's `layout` with `hide` in breakpoint order and empty extras dropped; undefined when it has none. */
|
|
916
|
+
function blockLayoutOf(block: Block): BlockLayout | undefined {
|
|
917
|
+
const hide = block.layout?.hide?.filter((entry, index, all) => all.indexOf(entry) === index);
|
|
918
|
+
const anchor = block.layout?.anchor?.trim();
|
|
919
|
+
const className = block.layout?.className?.trim().split(/\s+/).filter(Boolean).join(' ');
|
|
920
|
+
const layout = {
|
|
921
|
+
...(hide?.length ? { hide: Object.freeze([...BREAKPOINTS].filter(breakpoint => hide.includes(breakpoint))) } : {}),
|
|
922
|
+
...(anchor ? { anchor } : {}), ...(className ? { className } : {}), ...(block.layout?.nosnippet === true ? { nosnippet: true } : {}),
|
|
923
|
+
};
|
|
924
|
+
return Object.keys(layout).length ? Object.freeze(layout) : undefined;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** A block's `style` with the properties its type supports and values that fit them; an off flag or an empty value is left out. Undefined when none is set. */
|
|
928
|
+
function blockStyleOf(block: Block, supports: readonly StyleProperty[]): BlockStyle | undefined {
|
|
929
|
+
const style: Record<string, unknown> = {};
|
|
930
|
+
for (const property of supports) {
|
|
931
|
+
const value = block.style?.[property];
|
|
932
|
+
if (value === undefined || value === null || value === '' || value === false) continue;
|
|
933
|
+
if (!styleValueProblem(property, value)) style[property] = value;
|
|
934
|
+
}
|
|
935
|
+
return Object.keys(style).length ? Object.freeze(style) as BlockStyle : undefined;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** Media file IDs referenced by blocks, nested ones and rich text inside them included, and the files their style shows, for existence checks. */
|
|
939
|
+
export function blockMedia(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>): string[] {
|
|
940
|
+
const ids: string[] = [];
|
|
941
|
+
for (const block of flattenBlocks(blocks)) {
|
|
942
|
+
for (const id of [block.style?.image, block.style?.video]) if (typeof id === 'string' && id) ids.push(id);
|
|
943
|
+
for (const [name, declaration] of Object.entries(types.get(block.type)?.fields ?? {})) {
|
|
944
|
+
const value = block.data[name];
|
|
945
|
+
if (declaration.kind === 'richtext') {
|
|
946
|
+
const doc = value as RichTextDoc | null | undefined;
|
|
947
|
+
ids.push(...richTextMedia(doc), ...blockMedia(richTextBlocks(doc), types));
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
if (!declaration.media) continue;
|
|
951
|
+
if (typeof value === 'string') ids.push(value);
|
|
952
|
+
else if (Array.isArray(value)) ids.push(...value.filter((item): item is string => typeof item === 'string'));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return [...new Set(ids)];
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/** The rich text documents inside blocks, nested ones included, for patterns and media. */
|
|
959
|
+
export function blockDocuments(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>): RichTextDoc[] {
|
|
960
|
+
const docs: RichTextDoc[] = [];
|
|
961
|
+
for (const block of flattenBlocks(blocks)) {
|
|
962
|
+
for (const [name, declaration] of Object.entries(types.get(block.type)?.fields ?? {})) {
|
|
963
|
+
const value = block.data[name];
|
|
964
|
+
if (declaration.kind === 'richtext' && value && typeof value === 'object') docs.push(value as RichTextDoc);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return docs;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* The plain text of blocks, for search and excerpts: their string and text fields and the
|
|
972
|
+
* text of their rich text, in document order. Data blocks are left out.
|
|
973
|
+
*/
|
|
974
|
+
export function blocksPlain(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>, plain: (doc: RichTextDoc) => string, max = 100_000): string {
|
|
975
|
+
const parts: string[] = [];
|
|
976
|
+
let length = 0;
|
|
977
|
+
for (const block of flattenBlocks(blocks)) {
|
|
978
|
+
const type = types.get(block.type);
|
|
979
|
+
if (!type || blockIsData(type)) continue;
|
|
980
|
+
for (const [name, declaration] of Object.entries(type.fields)) {
|
|
981
|
+
const value = block.data[name];
|
|
982
|
+
const text = declaration.kind === 'richtext' ? (value && typeof value === 'object' ? plain(value as RichTextDoc) : '')
|
|
983
|
+
: (declaration.kind === 'string' || declaration.kind === 'text') && typeof value === 'string' && !declaration.media && !declaration.pattern ? value
|
|
984
|
+
: declaration.kind === 'string' && declaration.multiple && !declaration.media && Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string').join('\n') : '';
|
|
985
|
+
if (!text.trim()) continue;
|
|
986
|
+
parts.push(text.trim());
|
|
987
|
+
length += text.length;
|
|
988
|
+
if (length >= max) return parts.join('\n\n').slice(0, max);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return parts.join('\n\n');
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/** Blocks with fresh IDs, for copies of a template or a pattern: inserting a pattern twice must not repeat an ID. */
|
|
995
|
+
export function cloneBlocks<T extends Block>(blocks: readonly T[], id: () => string = blockId): T[] {
|
|
996
|
+
return blocks.map(block => ({ ...block, _id: id(), ...(block.children ? { children: cloneBlocks(block.children as readonly T[], id) } : {}) }));
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/** A new block ID. */
|
|
1000
|
+
export function blockId(): string {
|
|
1001
|
+
return crypto.randomUUID().replaceAll('-', '').slice(0, 12);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// --- The tree, for editors ---------------------------------------------------------
|
|
1005
|
+
|
|
1006
|
+
/** Every block of a tree in document order, with where it sits. */
|
|
1007
|
+
export interface BlockPlace<T extends Block = Block> {
|
|
1008
|
+
readonly block: T;
|
|
1009
|
+
readonly depth: number;
|
|
1010
|
+
/** The container's ID, or null at the top level. */
|
|
1011
|
+
readonly parent: string | null;
|
|
1012
|
+
/** Its position among its siblings. */
|
|
1013
|
+
readonly index: number;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** The blocks of a tree in document order. */
|
|
1017
|
+
export function flattenBlocks<T extends Block>(blocks: readonly T[]): T[] {
|
|
1018
|
+
return placeBlocks(blocks).map(place => place.block);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/** The blocks of a tree in document order, with their depth, parent and index. */
|
|
1022
|
+
export function placeBlocks<T extends Block>(blocks: readonly T[], parent: string | null = null, depth = 0): BlockPlace<T>[] {
|
|
1023
|
+
return blocks.flatMap((block, index) => [{ block, depth, parent, index }, ...placeBlocks((block.children ?? []) as readonly T[], block._id, depth + 1)]);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** The block with an ID anywhere in the tree. */
|
|
1027
|
+
export function findBlock<T extends Block>(blocks: readonly T[], id: string): T | undefined {
|
|
1028
|
+
return flattenBlocks(blocks).find(block => block._id === id);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/** The tree with one block replaced by what `change` returns for it. */
|
|
1032
|
+
export function updateBlock<T extends Block>(blocks: readonly T[], id: string, change: (block: T) => T): T[] {
|
|
1033
|
+
return blocks.map(block => block._id === id ? change(block) : block.children ? { ...block, children: updateBlock(block.children as readonly T[], id, change) } : block);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/** The tree without one block and what it held. */
|
|
1037
|
+
export function removeBlock<T extends Block>(blocks: readonly T[], id: string): T[] {
|
|
1038
|
+
return blocks.filter(block => block._id !== id).map(block => block.children ? { ...block, children: removeBlock(block.children as readonly T[], id) } : block);
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/** The tree with a block inserted under `parent` (null for the top level) at `index`, or last. */
|
|
1042
|
+
export function insertBlock<T extends Block>(blocks: readonly T[], parent: string | null, block: T, index?: number): T[] {
|
|
1043
|
+
const at = (list: readonly T[]): T[] => {
|
|
1044
|
+
const position = index === undefined ? list.length : Math.min(Math.max(index, 0), list.length);
|
|
1045
|
+
return [...list.slice(0, position), block, ...list.slice(position)];
|
|
1046
|
+
};
|
|
1047
|
+
if (parent === null) return at(blocks);
|
|
1048
|
+
return blocks.map(entry => entry._id === parent ? { ...entry, children: at((entry.children ?? []) as readonly T[]) }
|
|
1049
|
+
: entry.children ? { ...entry, children: insertBlock(entry.children as readonly T[], parent, block, index) } : entry);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* The tree with a block moved under `parent` at `index`, counted among the siblings without
|
|
1054
|
+
* it. Unchanged when the target is the block itself or inside it.
|
|
1055
|
+
*/
|
|
1056
|
+
export function moveBlock<T extends Block>(blocks: readonly T[], id: string, parent: string | null, index: number): T[] {
|
|
1057
|
+
const block = findBlock(blocks, id);
|
|
1058
|
+
if (!block || parent === id || (parent && findBlock(block.children ?? [], parent))) return [...blocks];
|
|
1059
|
+
return insertBlock(removeBlock(blocks, id), parent, block, index);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
export type BlockMove = 'up' | 'down' | 'in' | 'out';
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* WordPress's moves: up or down past a sibling, in as the last child of the sibling above,
|
|
1066
|
+
* or out to follow its container. Returns the same array when the move is not possible or
|
|
1067
|
+
* the types do not allow it there.
|
|
1068
|
+
*/
|
|
1069
|
+
export function shiftBlock<T extends Block>(blocks: readonly T[], id: string, move: BlockMove, types: ReadonlyMap<string, BlockDeclaration>): readonly T[] {
|
|
1070
|
+
const places = placeBlocks(blocks);
|
|
1071
|
+
const place = places.find(entry => entry.block._id === id);
|
|
1072
|
+
if (!place) return blocks;
|
|
1073
|
+
const siblings = place.parent === null ? blocks : (findBlock(blocks, place.parent)?.children ?? []) as readonly T[];
|
|
1074
|
+
let next: T[] | undefined;
|
|
1075
|
+
switch (move) {
|
|
1076
|
+
case 'up': if (place.index > 0) next = moveBlock(blocks, id, place.parent, place.index - 1); break;
|
|
1077
|
+
case 'down': if (place.index < siblings.length - 1) next = moveBlock(blocks, id, place.parent, place.index + 1); break;
|
|
1078
|
+
case 'in': {
|
|
1079
|
+
const above = siblings[place.index - 1];
|
|
1080
|
+
if (above && types.get(above.type)?.children) next = moveBlock(blocks, id, above._id, (above.children ?? []).length);
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
case 'out': {
|
|
1084
|
+
if (place.parent === null) break;
|
|
1085
|
+
const container = places.find(entry => entry.block._id === place.parent)!;
|
|
1086
|
+
next = moveBlock(blocks, id, container.parent, container.index + 1);
|
|
1087
|
+
break;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return next && !blockTreeProblem(next, types) ? next : blocks;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/** Why a tree breaks the types' nesting rules or the limits; undefined when it is fine. */
|
|
1094
|
+
export function blockTreeProblem(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>): string | undefined {
|
|
1095
|
+
const places = placeBlocks(blocks);
|
|
1096
|
+
if (places.length > BLOCK_LIMITS.count) return `At most ${BLOCK_LIMITS.count} blocks.`;
|
|
1097
|
+
const typeOf = new Map(places.map(place => [place.block._id, place.block.type]));
|
|
1098
|
+
for (const { block, parent: parentId, depth } of places) {
|
|
1099
|
+
if (depth >= BLOCK_LIMITS.depth) return `Blocks nest at most ${BLOCK_LIMITS.depth} deep.`;
|
|
1100
|
+
const type = types.get(block.type);
|
|
1101
|
+
if (!type) continue;
|
|
1102
|
+
const parent = parentId ? typeOf.get(parentId) ?? null : null;
|
|
1103
|
+
if (!blockAllowedIn(types, block.type, parent)) return parent ? `${type.label} cannot go inside ${types.get(parent)?.label ?? parent}.` : `${type.label} goes inside ${type.parent?.map(name => types.get(name)?.label ?? name).join(' or ')}.`;
|
|
1104
|
+
const children = block.children ?? [];
|
|
1105
|
+
if (children.length && !type.children) return `${type.label} does not hold blocks.`;
|
|
1106
|
+
if (type.children?.max !== undefined && children.length > type.children.max) return `${type.label} holds at most ${type.children.max} blocks.`;
|
|
1107
|
+
}
|
|
1108
|
+
return undefined;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/** The block whose HTML renders as it is; adding or changing one needs `PERMISSIONS.unfilteredHtml`. */
|
|
1112
|
+
export const HTML_BLOCK = 'core/html';
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* The HTML of each Custom HTML block in a value, by block ID: blocks and their children, rich
|
|
1116
|
+
* text's embedded blocks, and rich text inside blocks. The walk is shape-blind, so every place
|
|
1117
|
+
* a block can sit is covered.
|
|
1118
|
+
*/
|
|
1119
|
+
export function htmlBlocks(value: unknown): Map<string, string> {
|
|
1120
|
+
return new Map(htmlBlockList(value));
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/** Every Custom HTML block in a value as `[id, html]`, repeated IDs included. */
|
|
1124
|
+
function htmlBlockList(value: unknown): [string, string][] {
|
|
1125
|
+
const found: [string, string][] = [];
|
|
1126
|
+
const walk = (node: unknown, depth: number): void => {
|
|
1127
|
+
if (!node || typeof node !== 'object' || depth > 64) return;
|
|
1128
|
+
if (Array.isArray(node)) { for (const item of node) walk(item, depth + 1); return; }
|
|
1129
|
+
const object = node as Record<string, unknown>;
|
|
1130
|
+
if (object.type === HTML_BLOCK && object.data && typeof object.data === 'object') {
|
|
1131
|
+
const data = object.data as Record<string, unknown>;
|
|
1132
|
+
const html = typeof data.html === 'string' ? data.html : '';
|
|
1133
|
+
found.push([typeof object._id === 'string' ? object._id : `#${html}`, html]);
|
|
1134
|
+
}
|
|
1135
|
+
for (const child of Object.values(object)) walk(child, depth + 1);
|
|
1136
|
+
};
|
|
1137
|
+
walk(value, 0);
|
|
1138
|
+
return found;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Whether a new value adds a Custom HTML block or changes one's HTML; removing one is no change.
|
|
1143
|
+
* Every occurrence is compared, so a block that repeats a stored block's ID with other HTML
|
|
1144
|
+
* (in a nested rich-text embed, say) counts as a change; so does a deeper walk than the limit.
|
|
1145
|
+
*/
|
|
1146
|
+
export function htmlBlocksChanged(next: unknown, previous: unknown): boolean {
|
|
1147
|
+
const before = new Map<string, Set<string>>();
|
|
1148
|
+
for (const [id, html] of htmlBlockList(previous)) before.set(id, (before.get(id) ?? new Set()).add(html));
|
|
1149
|
+
for (const [id, html] of htmlBlockList(next)) if (!before.get(id)?.has(html)) return true;
|
|
1150
|
+
return tooDeep(next, 0);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function tooDeep(node: unknown, depth: number): boolean {
|
|
1154
|
+
if (!node || typeof node !== 'object') return false;
|
|
1155
|
+
if (depth > 64) return true;
|
|
1156
|
+
return (Array.isArray(node) ? node : Object.values(node as Record<string, unknown>)).some(child => tooDeep(child, depth + 1));
|
|
1157
|
+
}
|