@cossackframework/cms 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +123 -3
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block references: blocks written inside text, as shortcodes are in WordPress. Markdown
|
|
3
|
+
* fields, widget text and theme options can hold them:
|
|
4
|
+
*
|
|
5
|
+
* {{ block core/button label="Buy {{ $.title }}" url="/cart" /}} a block without a body
|
|
6
|
+
* {{ block core/button }}Price is {{ $.price }}{{ /block }} a body fills the type's `body` field
|
|
7
|
+
* {{ block core/group }} …blocks and text… {{ /block }} a container's body is its children
|
|
8
|
+
* {{ pattern hero /}} a synced pattern by slug
|
|
9
|
+
* \{{ … }} written as is
|
|
10
|
+
*
|
|
11
|
+
* Only block types that declare `inline: true` can be referenced. The parser turns text into
|
|
12
|
+
* text runs and the same `Block` tree the editor stores, so validation and rendering are the
|
|
13
|
+
* blocks' own. Bindings (`{{ $.price }}`) are left in the text, in bodies and in quoted
|
|
14
|
+
* values alike, and resolve when the blocks render. Client-safe.
|
|
15
|
+
*/
|
|
16
|
+
import { BLOCK_LIMITS } from './block-shape';
|
|
17
|
+
import type { Block, BlockDeclaration } from './blocks';
|
|
18
|
+
|
|
19
|
+
/** A piece of text with references: a run of text, or a block. */
|
|
20
|
+
export type TextPart = { readonly kind: 'text'; readonly text: string } | { readonly kind: 'block'; readonly block: Block };
|
|
21
|
+
|
|
22
|
+
export interface ParsedText {
|
|
23
|
+
readonly parts: readonly TextPart[];
|
|
24
|
+
/** Why parts of the text are not blocks, in order; empty when it is fine. Faulty references are left out of `parts`. */
|
|
25
|
+
readonly problems: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether a text holds a block or pattern reference, so a renderer knows to parse it. */
|
|
29
|
+
export function hasBlockReference(value: unknown): value is string {
|
|
30
|
+
return typeof value === 'string' && /(?<!\\)\{\{\s*(?:block|pattern|\/block)\b/.test(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The pattern a `{{ pattern … }}` names, kept as a `core/pattern` block whose `pattern` is the slug until the site resolves it. */
|
|
34
|
+
export const PATTERN_REFERENCE = 'core/pattern';
|
|
35
|
+
|
|
36
|
+
type Tag =
|
|
37
|
+
| { kind: 'open'; type: string; attrs: Record<string, unknown>; closed: boolean }
|
|
38
|
+
| { kind: 'close'; type: string | null }
|
|
39
|
+
| { kind: 'pattern'; ref: string };
|
|
40
|
+
|
|
41
|
+
interface Frame { type: string; attrs: Record<string, unknown>; parts: TextPart[] }
|
|
42
|
+
|
|
43
|
+
const NAME = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
|
|
44
|
+
const ATTRIBUTE = /^[A-Za-z_][\w-]*$/;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parse text into runs and blocks. `types` are the available block types; `prefix` makes the
|
|
48
|
+
* blocks' IDs, which follow their position, distinct in the tree around the text.
|
|
49
|
+
*/
|
|
50
|
+
export function parseBlockText(text: string, types: ReadonlyMap<string, BlockDeclaration>, prefix = 'ref'): ParsedText {
|
|
51
|
+
const problems: string[] = [];
|
|
52
|
+
const root: Frame = { type: '', attrs: {}, parts: [] };
|
|
53
|
+
const stack: Frame[] = [root];
|
|
54
|
+
let count = 0;
|
|
55
|
+
let buffer = '';
|
|
56
|
+
const flush = () => {
|
|
57
|
+
if (buffer) stack[stack.length - 1]!.parts.push({ kind: 'text', text: buffer });
|
|
58
|
+
buffer = '';
|
|
59
|
+
};
|
|
60
|
+
let at = 0;
|
|
61
|
+
while (at < text.length) {
|
|
62
|
+
// `\{{` writes the braces as text.
|
|
63
|
+
if (text.startsWith('\\{{', at)) { buffer += '{{'; at += 3; continue; }
|
|
64
|
+
if (!text.startsWith('{{', at)) { buffer += text[at]; at++; continue; }
|
|
65
|
+
const end = tagEnd(text, at + 2);
|
|
66
|
+
const inner = end === -1 ? null : text.slice(at + 2, end).trim();
|
|
67
|
+
const tag = inner === null ? null : parseTag(inner);
|
|
68
|
+
// Bindings and anything that is not a reference stay in the text as written.
|
|
69
|
+
if (!tag || typeof tag === 'string') {
|
|
70
|
+
if (typeof tag === 'string') problems.push(tag);
|
|
71
|
+
const stop = end === -1 ? text.length : end + 2;
|
|
72
|
+
if (typeof tag !== 'string') buffer += text.slice(at, stop);
|
|
73
|
+
at = stop;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
at = end + 2;
|
|
77
|
+
flush();
|
|
78
|
+
if (tag.kind === 'close') {
|
|
79
|
+
const frame = stack.length > 1 ? stack[stack.length - 1]! : null;
|
|
80
|
+
if (!frame) { problems.push('{{ /block }} closes no block.'); continue; }
|
|
81
|
+
if (tag.type && tag.type !== frame.type) { problems.push(`{{ /block ${tag.type} }} closes ${frame.type}.`); continue; }
|
|
82
|
+
stack.pop();
|
|
83
|
+
const block = build(frame, types, `${prefix}${++count}`, problems, stack.length);
|
|
84
|
+
if (block) stack[stack.length - 1]!.parts.push({ kind: 'block', block });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (tag.kind === 'pattern') {
|
|
88
|
+
stack[stack.length - 1]!.parts.push({ kind: 'block', block: { _id: `${prefix}${++count}`, type: PATTERN_REFERENCE, data: { pattern: tag.ref } } });
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const frame: Frame = { type: tag.type, attrs: tag.attrs, parts: [] };
|
|
92
|
+
if (tag.closed) {
|
|
93
|
+
const block = build(frame, types, `${prefix}${++count}`, problems, stack.length);
|
|
94
|
+
if (block) stack[stack.length - 1]!.parts.push({ kind: 'block', block });
|
|
95
|
+
} else stack.push(frame);
|
|
96
|
+
}
|
|
97
|
+
flush();
|
|
98
|
+
// Blocks left open: their text keeps showing, and the reference is reported.
|
|
99
|
+
while (stack.length > 1) {
|
|
100
|
+
const frame = stack.pop()!;
|
|
101
|
+
problems.push(`{{ block ${frame.type} }} is not closed: end it with {{ /block }}, or write {{ block ${frame.type} … /}} for one without a body.`);
|
|
102
|
+
stack[stack.length - 1]!.parts.push(...frame.parts);
|
|
103
|
+
}
|
|
104
|
+
if (count > BLOCK_LIMITS.count) problems.push(`Text holds at most ${BLOCK_LIMITS.count} block references.`);
|
|
105
|
+
return { parts: merge(root.parts), problems };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Where the tag starting at `from` ends (the index of its `}}`), skipping quoted values, which may hold `{{ $.price }}`. -1 when it does not end. */
|
|
109
|
+
function tagEnd(text: string, from: number): number {
|
|
110
|
+
let quoted = false;
|
|
111
|
+
let depth = 0;
|
|
112
|
+
for (let index = from; index < text.length; index++) {
|
|
113
|
+
const char = text[index];
|
|
114
|
+
if (quoted) {
|
|
115
|
+
if (char === '\\') { index++; continue; }
|
|
116
|
+
if (char === '"') quoted = false;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (char === '"') { quoted = true; continue; }
|
|
120
|
+
if (text.startsWith('{{', index)) { depth++; index++; continue; }
|
|
121
|
+
if (text.startsWith('}}', index)) {
|
|
122
|
+
if (depth === 0) return index;
|
|
123
|
+
depth--; index++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return -1;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A reference tag, a problem to report (for a reference that is wrong), or null for text such as a binding. */
|
|
130
|
+
function parseTag(inner: string): Tag | string | null {
|
|
131
|
+
const closed = inner.endsWith('/');
|
|
132
|
+
const body = closed ? inner.slice(0, -1).trim() : inner;
|
|
133
|
+
const match = /^(\/?block|pattern)\b\s*([\s\S]*)$/.exec(body);
|
|
134
|
+
if (!match) return null;
|
|
135
|
+
const [, keyword, rest] = match as unknown as [string, string, string];
|
|
136
|
+
if (keyword === '/block') {
|
|
137
|
+
const type = rest.trim();
|
|
138
|
+
if (type && !NAME.test(type)) return `{{ /block ${type} }} names no block type.`;
|
|
139
|
+
return { kind: 'close', type: type || null };
|
|
140
|
+
}
|
|
141
|
+
const tokens = attributeTokens(rest);
|
|
142
|
+
if (typeof tokens === 'string') return tokens;
|
|
143
|
+
const [first, ...others] = tokens;
|
|
144
|
+
if (keyword === 'pattern') {
|
|
145
|
+
if (!first || first.value !== undefined || others.length) return '{{ pattern … /}} names one pattern by its slug.';
|
|
146
|
+
return { kind: 'pattern', ref: first.name };
|
|
147
|
+
}
|
|
148
|
+
if (!first || first.value !== undefined || !NAME.test(first.name)) return `{{ block ${rest.trim()} }} names no block type, such as core/button.`;
|
|
149
|
+
const attrs: Record<string, unknown> = {};
|
|
150
|
+
for (const token of others) {
|
|
151
|
+
if (!ATTRIBUTE.test(token.name)) return `${token.name} is not an attribute name.`;
|
|
152
|
+
attrs[token.name] = token.value === undefined ? true : token.value;
|
|
153
|
+
}
|
|
154
|
+
return { kind: 'open', type: first.name, attrs, closed };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `name`, `name="text"`, `name=12`, `name=true`: the words of a tag after its keyword. */
|
|
158
|
+
function attributeTokens(source: string): { name: string; value?: unknown }[] | string {
|
|
159
|
+
const tokens: { name: string; value?: unknown }[] = [];
|
|
160
|
+
let at = 0;
|
|
161
|
+
const space = () => { while (at < source.length && /\s/.test(source[at]!)) at++; };
|
|
162
|
+
while (true) {
|
|
163
|
+
space();
|
|
164
|
+
if (at >= source.length) return tokens;
|
|
165
|
+
const start = at;
|
|
166
|
+
while (at < source.length && !/[\s=]/.test(source[at]!)) at++;
|
|
167
|
+
const name = source.slice(start, at);
|
|
168
|
+
if (source[at] !== '=') { tokens.push({ name }); continue; }
|
|
169
|
+
at++;
|
|
170
|
+
if (source[at] === '"') {
|
|
171
|
+
at++;
|
|
172
|
+
let value = '';
|
|
173
|
+
while (at < source.length && source[at] !== '"') {
|
|
174
|
+
if (source[at] === '\\' && at + 1 < source.length) { value += source[at + 1]; at += 2; continue; }
|
|
175
|
+
value += source[at]; at++;
|
|
176
|
+
}
|
|
177
|
+
if (at >= source.length) return `The value of ${name} is missing its closing quote.`;
|
|
178
|
+
at++;
|
|
179
|
+
tokens.push({ name, value });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const startValue = at;
|
|
183
|
+
while (at < source.length && !/\s/.test(source[at]!)) at++;
|
|
184
|
+
const raw = source.slice(startValue, at);
|
|
185
|
+
if (raw === 'true' || raw === 'false') tokens.push({ name, value: raw === 'true' });
|
|
186
|
+
else if (/^-?\d+(?:\.\d+)?$/.test(raw)) tokens.push({ name, value: Number(raw) });
|
|
187
|
+
else return `The value of ${name} needs quotes: ${name}="${raw}". Bindings go inside them: ${name}="{{ $.field }}".`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The block a finished reference stands for, or null after reporting why it cannot be one. */
|
|
192
|
+
function build(frame: Frame, types: ReadonlyMap<string, BlockDeclaration>, id: string, problems: string[], depth: number): Block | null {
|
|
193
|
+
const type = types.get(frame.type);
|
|
194
|
+
if (!type) { problems.push(`${frame.type} is not an available block.`); return null; }
|
|
195
|
+
if (type.inline !== true) { problems.push(`${type.label} (${frame.type}) cannot be used in text.`); return null; }
|
|
196
|
+
if (depth > BLOCK_LIMITS.depth) { problems.push(`Block references nest at most ${BLOCK_LIMITS.depth} levels.`); return null; }
|
|
197
|
+
const data: Record<string, unknown> = {};
|
|
198
|
+
for (const [name, value] of Object.entries(frame.attrs)) {
|
|
199
|
+
if (!type.fields[name]) { problems.push(`${frame.type} has no ${name}.`); continue; }
|
|
200
|
+
data[name] = value;
|
|
201
|
+
}
|
|
202
|
+
const parts = merge(frame.parts);
|
|
203
|
+
const hasBody = parts.some(part => part.kind === 'block' || part.text.trim() !== '');
|
|
204
|
+
if (!hasBody) return { _id: id, type: frame.type, data };
|
|
205
|
+
if (type.children) {
|
|
206
|
+
// A container's body is its children; loose text becomes paragraphs, where they may go.
|
|
207
|
+
const children: Block[] = [];
|
|
208
|
+
let index = 0;
|
|
209
|
+
for (const part of parts) {
|
|
210
|
+
if (part.kind === 'block') { children.push(part.block); continue; }
|
|
211
|
+
const text = part.text.trim();
|
|
212
|
+
if (!text) continue;
|
|
213
|
+
if (type.children.allowed && !type.children.allowed.includes('core/paragraph')) { problems.push(`${frame.type} holds only ${type.children.allowed.join(', ')}: put the text in one of them.`); continue; }
|
|
214
|
+
children.push({ _id: `${id}-t${++index}`, type: 'core/paragraph', data: { text } });
|
|
215
|
+
}
|
|
216
|
+
return { _id: id, type: frame.type, data, children };
|
|
217
|
+
}
|
|
218
|
+
if (parts.some(part => part.kind === 'block')) { problems.push(`${frame.type} holds no blocks; its body is text.`); return null; }
|
|
219
|
+
if (!type.body) { problems.push(`${frame.type} takes no body: write {{ block ${frame.type} … /}}.`); return null; }
|
|
220
|
+
if (frame.attrs[type.body] !== undefined) { problems.push(`${frame.type} gets ${type.body} twice: as an attribute and as its body.`); return null; }
|
|
221
|
+
data[type.body] = parts.map(part => part.kind === 'text' ? part.text : '').join('').trim();
|
|
222
|
+
return { _id: id, type: frame.type, data };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Adjacent text runs as one. */
|
|
226
|
+
function merge(parts: readonly TextPart[]): TextPart[] {
|
|
227
|
+
const merged: TextPart[] = [];
|
|
228
|
+
for (const part of parts) {
|
|
229
|
+
const last = merged[merged.length - 1];
|
|
230
|
+
if (part.kind === 'text' && last?.kind === 'text') merged[merged.length - 1] = { kind: 'text', text: last.text + part.text };
|
|
231
|
+
else merged.push(part);
|
|
232
|
+
}
|
|
233
|
+
return merged;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The blocks a parsed text holds, in order, nested ones included through their containers. */
|
|
237
|
+
export function textBlocks(parsed: ParsedText): Block[] {
|
|
238
|
+
return parsed.parts.flatMap(part => part.kind === 'block' ? [part.block] : []);
|
|
239
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of stored blocks, shared by field validation and rich text documents, which embed
|
|
3
|
+
* blocks. No imports, so both can use it.
|
|
4
|
+
*/
|
|
5
|
+
/** A block's `_id`: 1 to 40 letters, digits, `_` or `-`; generated, or chosen under the block's Advanced settings. */
|
|
6
|
+
export const BLOCK_ID = /^[A-Za-z0-9_-]{1,40}$/;
|
|
7
|
+
const BLOCK_TYPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
8
|
+
/** A color of the block's own, beside the theme's presets: a hex color, which cannot carry anything but a color. */
|
|
9
|
+
export const CUSTOM_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
10
|
+
|
|
11
|
+
/** Why a block ID an editor typed is refused: its shape, or another block of the field that has it. Undefined when fine. */
|
|
12
|
+
export function blockIdProblem(id: string, taken?: ReadonlySet<string>): string | undefined {
|
|
13
|
+
if (!BLOCK_ID.test(id)) return 'A block ID is 1 to 40 letters, digits, _ or -.';
|
|
14
|
+
if (taken?.has(id)) return 'Another block of this field has this ID.';
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** How many blocks a field holds across its tree, and how deep they nest. */
|
|
19
|
+
export const BLOCK_LIMITS = Object.freeze({ count: 200, depth: 8 });
|
|
20
|
+
/** Container widths blocks respond to: `sm` below 640px, `md` below 1024px, `lg` from there. */
|
|
21
|
+
export const BREAKPOINTS = Object.freeze(['sm', 'md', 'lg'] as const);
|
|
22
|
+
export type Breakpoint = (typeof BREAKPOINTS)[number];
|
|
23
|
+
/**
|
|
24
|
+
* Style properties every block may carry, outside its type's data, and the support kind each
|
|
25
|
+
* belongs to. The `background` kind is the advanced background of containers: a gradient
|
|
26
|
+
* preset, an image or a video from the library, and an overlay over them.
|
|
27
|
+
*/
|
|
28
|
+
export const STYLE_PROPERTIES = Object.freeze({
|
|
29
|
+
background: 'color', text: 'color', padding: 'spacing', margin: 'spacing', fontSize: 'typography', align: 'typography',
|
|
30
|
+
gradient: 'background', image: 'background', imageSize: 'background', imageRepeat: 'background', imageFixed: 'background', overlay: 'background', overlayOpacity: 'background', video: 'background',
|
|
31
|
+
} as const);
|
|
32
|
+
export type StyleProperty = keyof typeof STYLE_PROPERTIES;
|
|
33
|
+
export const TEXT_ALIGNMENTS = Object.freeze(['left', 'center', 'right'] as const);
|
|
34
|
+
/** How a background image fills its block. */
|
|
35
|
+
export const BACKGROUND_SIZES = Object.freeze(['cover', 'contain', 'auto'] as const);
|
|
36
|
+
/** A media file's ID, as `style.image` and `style.video` hold it. */
|
|
37
|
+
export const MEDIA_ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
38
|
+
/** A preset's slug: lowercase letters, digits and hyphens. */
|
|
39
|
+
export const PRESET_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
40
|
+
const ANCHOR = /^[A-Za-z][\w-]{0,59}$/;
|
|
41
|
+
/** A form input's name: a lowercase letter, then letters and digits, as field names are. */
|
|
42
|
+
export const INPUT_NAME = /^[a-z][a-zA-Z0-9]{0,39}$/;
|
|
43
|
+
/** How a condition compares an input's value. */
|
|
44
|
+
export const CONDITION_OPERATORS = Object.freeze(['is', 'isNot', 'contains', 'empty', 'notEmpty', 'gt', 'lt', 'in'] as const);
|
|
45
|
+
export type ConditionOperator = (typeof CONDITION_OPERATORS)[number];
|
|
46
|
+
/** Rules a block's condition holds. */
|
|
47
|
+
export const CONDITION_LIMIT = 10;
|
|
48
|
+
const CLASS_NAME = /^-?[_A-Za-z][\w-]*$/;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The shape of a `blocks` value: `{ id, type, data }` items, with `layout` and `children`
|
|
52
|
+
* under a container, at most 200 across the tree and 4 deep. Each block's data is checked
|
|
53
|
+
* against its type separately.
|
|
54
|
+
*/
|
|
55
|
+
export function blocksShapeProblem(value: unknown): string | undefined {
|
|
56
|
+
if (!Array.isArray(value)) return 'must be a list of at most 200 blocks.';
|
|
57
|
+
const ids = new Set<string>();
|
|
58
|
+
const visit = (list: unknown[], depth: number): string | undefined => {
|
|
59
|
+
if (depth >= BLOCK_LIMITS.depth) return `blocks nest at most ${BLOCK_LIMITS.depth} deep.`;
|
|
60
|
+
for (const block of list) {
|
|
61
|
+
if (!block || typeof block !== 'object' || Array.isArray(block)) return 'must contain blocks.';
|
|
62
|
+
const { _id: id, type, data, layout, style, when, children } = block as { _id?: unknown; type?: unknown; data?: unknown; layout?: unknown; style?: unknown; when?: unknown; children?: unknown };
|
|
63
|
+
if (typeof id !== 'string' || !BLOCK_ID.test(id) || ids.has(id)) return 'blocks need distinct IDs.';
|
|
64
|
+
ids.add(id);
|
|
65
|
+
if (ids.size > BLOCK_LIMITS.count) return `must be a list of at most ${BLOCK_LIMITS.count} blocks.`;
|
|
66
|
+
if (typeof type !== 'string' || !BLOCK_TYPE.test(type)) return 'blocks need a type such as core/paragraph.';
|
|
67
|
+
if (!data || typeof data !== 'object' || Array.isArray(data) || Object.getPrototypeOf(data) !== Object.prototype) return 'block data must be an object.';
|
|
68
|
+
if (layout !== undefined) {
|
|
69
|
+
const problem = blockLayoutProblem(layout);
|
|
70
|
+
if (problem) return problem;
|
|
71
|
+
}
|
|
72
|
+
if (style !== undefined) {
|
|
73
|
+
const problem = blockStyleProblem(style);
|
|
74
|
+
if (problem) return problem;
|
|
75
|
+
}
|
|
76
|
+
if (when !== undefined) {
|
|
77
|
+
const problem = blockConditionProblem(when);
|
|
78
|
+
if (problem) return problem;
|
|
79
|
+
}
|
|
80
|
+
if (children !== undefined) {
|
|
81
|
+
if (!Array.isArray(children)) return 'block children must be a list of blocks.';
|
|
82
|
+
const problem = visit(children, depth + 1);
|
|
83
|
+
if (problem) return problem;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
};
|
|
88
|
+
const problem = visit(value, 0);
|
|
89
|
+
if (problem) return problem;
|
|
90
|
+
if (JSON.stringify(value).length > 512 * 1024) return 'must be at most 512 KB.';
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The shape of a block's `layout`: `hide` lists breakpoints; `anchor` is an HTML id; `className` lists class names; `nosnippet` keeps it out of snippets. */
|
|
95
|
+
export function blockLayoutProblem(value: unknown): string | undefined {
|
|
96
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) return 'block layout must be an object.';
|
|
97
|
+
const { hide, anchor, className, nosnippet } = value as { hide?: unknown; anchor?: unknown; className?: unknown; nosnippet?: unknown };
|
|
98
|
+
if (nosnippet !== undefined && typeof nosnippet !== 'boolean') return 'block layout.nosnippet is on or off.';
|
|
99
|
+
if (hide !== undefined && (!Array.isArray(hide) || !hide.every(entry => (BREAKPOINTS as readonly string[]).includes(entry as string)))) return `block layout.hide lists ${BREAKPOINTS.join(', ')}.`;
|
|
100
|
+
if (anchor !== undefined && anchor !== '' && (typeof anchor !== 'string' || !ANCHOR.test(anchor))) return 'block layout.anchor is an HTML id: a letter, then up to 59 letters, digits, _ or -.';
|
|
101
|
+
if (className !== undefined && className !== '' && (typeof className !== 'string' || className.length > 200 || !className.trim().split(/\s+/).every(name => CLASS_NAME.test(name)))) return 'block layout.className lists class names, at most 200 characters.';
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Why a value does not fit a style property; undefined when it does. Colors and the overlay
|
|
107
|
+
* are preset slugs or hex colors, the image and the video media file IDs, sizes and
|
|
108
|
+
* alignments one of their words, the image flags on or off, the overlay's opacity 0 to 100.
|
|
109
|
+
*/
|
|
110
|
+
export function styleValueProblem(property: StyleProperty, value: unknown): string | undefined {
|
|
111
|
+
const slug = typeof value === 'string' && value.length <= 40 && PRESET_SLUG.test(value);
|
|
112
|
+
switch (property) {
|
|
113
|
+
case 'align': return (TEXT_ALIGNMENTS as readonly string[]).includes(value as string) ? undefined : `block style.align is ${TEXT_ALIGNMENTS.join(', ')}.`;
|
|
114
|
+
case 'background': case 'text': case 'overlay': return slug || (typeof value === 'string' && CUSTOM_COLOR.test(value)) ? undefined : `block style.${property} is a preset slug or a hex color.`;
|
|
115
|
+
case 'image': case 'video': return typeof value === 'string' && MEDIA_ID.test(value) ? undefined : `block style.${property} is a media file ID.`;
|
|
116
|
+
case 'imageSize': return (BACKGROUND_SIZES as readonly string[]).includes(value as string) ? undefined : `block style.imageSize is ${BACKGROUND_SIZES.join(', ')}.`;
|
|
117
|
+
case 'imageRepeat': case 'imageFixed': return typeof value === 'boolean' ? undefined : `block style.${property} is on or off.`;
|
|
118
|
+
case 'overlayOpacity': return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 100 ? undefined : 'block style.overlayOpacity is a whole number from 0 to 100.';
|
|
119
|
+
default: return slug ? undefined : `block style.${property} is a preset slug.`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The shape of a block's `style`: preset slugs per property (colors may be hex colors of the block's own), an alignment, and the advanced background. */
|
|
124
|
+
export function blockStyleProblem(value: unknown): string | undefined {
|
|
125
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) return 'block style must be an object.';
|
|
126
|
+
for (const [property, entry] of Object.entries(value)) {
|
|
127
|
+
if (!Object.hasOwn(STYLE_PROPERTIES, property)) return `block style has no ${property}; it takes ${Object.keys(STYLE_PROPERTIES).join(', ')}.`;
|
|
128
|
+
if (entry === undefined || entry === '') continue;
|
|
129
|
+
const problem = styleValueProblem(property as StyleProperty, entry);
|
|
130
|
+
if (problem) return problem;
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The shape of a block's `when`: show (or hide) the block when all or any of its rules match
|
|
137
|
+
* the values of the form's inputs. `value` is text; `in` takes a comma-separated list.
|
|
138
|
+
*/
|
|
139
|
+
export function blockConditionProblem(value: unknown): string | undefined {
|
|
140
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) return 'block when must be an object.';
|
|
141
|
+
const { action, match, rules, ...rest } = value as { action?: unknown; match?: unknown; rules?: unknown };
|
|
142
|
+
if (Object.keys(rest).length) return 'block when takes action, match and rules.';
|
|
143
|
+
if (action !== undefined && action !== 'show' && action !== 'hide') return 'block when.action is show or hide.';
|
|
144
|
+
if (match !== undefined && match !== 'all' && match !== 'any') return 'block when.match is all or any.';
|
|
145
|
+
if (!Array.isArray(rules) || !rules.length || rules.length > CONDITION_LIMIT) return `block when.rules lists 1 to ${CONDITION_LIMIT} rules.`;
|
|
146
|
+
for (const rule of rules) {
|
|
147
|
+
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) return 'block when.rules holds rules.';
|
|
148
|
+
const { field, op, value: expected, ...extra } = rule as { field?: unknown; op?: unknown; value?: unknown };
|
|
149
|
+
if (Object.keys(extra).length) return 'a condition rule takes field, op and value.';
|
|
150
|
+
if (typeof field !== 'string' || !INPUT_NAME.test(field)) return 'a condition rule names a form field.';
|
|
151
|
+
if (!(CONDITION_OPERATORS as readonly string[]).includes(op as string)) return `a condition rule's op is one of ${CONDITION_OPERATORS.join(', ')}.`;
|
|
152
|
+
if (expected !== undefined && (typeof expected !== 'string' || expected.length > 500)) return 'a condition rule\'s value is text of at most 500 characters.';
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|