@cossackframework/cms 0.0.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +21 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +709 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +114 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form controls for entry and block fields, shared by the entry editor, Appearance → Widgets
|
|
3
|
+
* and the editor on the public site. Client-safe. Media fields show their files with Choose and
|
|
4
|
+
* Remove buttons; the screen opens its own media chooser.
|
|
5
|
+
*/
|
|
6
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { Button, Checkbox, CodeEditor, Combobox, DropdownMenu, Icon, IconPicker, Input, NativeSelect, Textarea } from '@cossackframework/ui';
|
|
8
|
+
import { hasBinding, ITEM_LIMITS, mediaKind, withBinding } from '@cossackframework/cms';
|
|
9
|
+
import type { BlockOption, EditorField, SourceChoices } from './editor';
|
|
10
|
+
import { icon, ICON_CATALOG } from './icons';
|
|
11
|
+
import { iconButton } from './ui';
|
|
12
|
+
|
|
13
|
+
/** A file as media controls preview it. */
|
|
14
|
+
export interface MediaPreview { id: string; url: string; title: string; alt: string; contentType: string; width: number | null; height: number | null }
|
|
15
|
+
|
|
16
|
+
/** How a media control shows and changes its files. */
|
|
17
|
+
export interface MediaHooks {
|
|
18
|
+
previews: Record<string, MediaPreview>;
|
|
19
|
+
/** Open the screen's media chooser for this field. */
|
|
20
|
+
choose(multiple: boolean): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A field of the entry a block's text may show: `{{ $.name }}` on the site becomes the entry's value. */
|
|
24
|
+
export interface BindingChoice { name: string; label: string }
|
|
25
|
+
|
|
26
|
+
/** A list of binding choices from editor fields: the kinds whose values read as text. */
|
|
27
|
+
export function bindingChoices(fields: readonly Pick<EditorField, 'name' | 'label' | 'kind' | 'media'>[]): BindingChoice[] {
|
|
28
|
+
return fields.filter(field => !field.media && ['string', 'text', 'integer', 'number', 'boolean', 'enum', 'datetime', 'reference'].includes(field.kind))
|
|
29
|
+
.map(field => ({ name: field.name, label: field.label }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The control for one field, or null for kinds a screen renders itself (blocks, rich text).
|
|
34
|
+
* `options` lists a reference field's choices.
|
|
35
|
+
*/
|
|
36
|
+
export function fieldControl(field: EditorField, value: unknown, change: (value: unknown) => void, id: string,
|
|
37
|
+
extra: { media?: MediaHooks; options?: readonly { id: string; title: string }[]; /** Entry fields the text may bind to; a picker button offers them. */ bindings?: readonly BindingChoice[]; /** The language of a code field, from the block's `language` field. */ language?: string;
|
|
38
|
+
/** What fields with `choicesFrom` choose from; without it they are text. */ sources?: SourceChoices } = {}): TemplateResult | null {
|
|
39
|
+
const input = (type: 'text' | 'number' | 'datetime-local') => component(Input, { id, type, '.value': String(value ?? ''), step: field.kind === 'integer' ? 1 : 'any',
|
|
40
|
+
...(field.kind === 'string' && field.max ? { maxlength: field.max } : {}), '@input': (event: Event) => change((event.target as HTMLInputElement).value) });
|
|
41
|
+
const textarea = (rows: number, className = '') => component(Textarea, { id, rows, ...(className ? { class: className } : {}), '.value': String(value ?? ''),
|
|
42
|
+
'@input': (event: Event) => change((event.target as HTMLTextAreaElement).value) });
|
|
43
|
+
// Text may show an entry field instead: the picker beside the control writes the binding.
|
|
44
|
+
const bindable = (control: TemplateResult) => extra.bindings !== undefined ? bindingControl(control, value, change, id, extra.bindings) : control;
|
|
45
|
+
if (field.multiple && !field.media) {
|
|
46
|
+
if (field.kind === 'enum') return choicesControl(field, value, change, id);
|
|
47
|
+
// A few choices from a source, such as the site's roles, are a checklist; more are a searchable list per item.
|
|
48
|
+
const listed = field.choicesFrom && extra.sources ? extra.sources[field.choicesFrom] : undefined;
|
|
49
|
+
if (field.kind === 'string' && listed && listed.length <= 12) return choicesControl({ ...field, choices: withMissing(listed, value) }, value, change, id);
|
|
50
|
+
return multipleControl(field, value, change, id, (item, itemChange, itemId) => fieldControl({ ...field, multiple: false }, item, itemChange, itemId, extra) ?? html``);
|
|
51
|
+
}
|
|
52
|
+
if (field.choicesFrom && extra.sources && field.kind === 'string') return sourceControl(field, value, change, id, extra.sources);
|
|
53
|
+
// A site icon: the closed set the public site ships, in a searchable grid.
|
|
54
|
+
if (field.icon && field.kind === 'string') return component(IconPicker, { id, value: typeof value === 'string' ? value : '', icons: ICON_CATALOG, label: field.label, allowEmpty: !field.required, onChange: (name: string) => change(name) });
|
|
55
|
+
switch (field.kind) {
|
|
56
|
+
case 'boolean': return component(Checkbox, { id, label: field.label, checked: value === true, '@change': (event: Event) => change((event.target as HTMLInputElement).checked) });
|
|
57
|
+
case 'enum': return component(NativeSelect, { id, '@change': (event: Event) => change((event.target as HTMLSelectElement).value) }, html`
|
|
58
|
+
${field.required ? null : html`<option value="" ?selected=${!value}>—</option>`}
|
|
59
|
+
${field.choices.map(choice => html`<option value=${choice.value} ?selected=${choice.value === value}>${choice.label}</option>`)}`);
|
|
60
|
+
case 'integer': case 'number': return input('number');
|
|
61
|
+
case 'datetime': return input('datetime-local');
|
|
62
|
+
// A reference: a searchable list of the target's entries by title; the stored value is the entry ID.
|
|
63
|
+
case 'reference': {
|
|
64
|
+
const options = (extra.options ?? []).map(option => ({ value: option.id, label: option.title }));
|
|
65
|
+
const current = typeof value === 'string' ? value : '';
|
|
66
|
+
if (current && !options.some(option => option.value === current)) options.unshift({ value: current, label: `${current} (${__('not in the list')})` });
|
|
67
|
+
return component(Combobox, { id, options, value: current, placeholder: __('Type to search…'), emptyLabel: __('No entry matches.'), required: field.required, onValueChange: (next: string) => change(next) });
|
|
68
|
+
}
|
|
69
|
+
case 'json': return field.fields.length
|
|
70
|
+
? groupFields(field, value, change, id, (sub, subValue, subChange, subId) => fieldControl(sub, subValue, subChange, subId, extra) ?? html``)
|
|
71
|
+
: textarea(6, 'font-mono text-xs');
|
|
72
|
+
// Markdown in a block is a short passage: a compact box that grows with its text, no tabs or toolbar.
|
|
73
|
+
case 'text': return field.format === 'markdown'
|
|
74
|
+
? html`<div class="space-y-1">${bindable(textarea(3, 'field-sizing-content min-h-[4.5rem] max-h-[40vh]'))}<p class="text-xs text-muted-foreground">${__('Markdown: **bold**, _italic_, [link](https://…). Blocks: {{ block core/button label="Buy" url="/cart" /}}.')}</p></div>`
|
|
75
|
+
: field.format === 'code' ? component(CodeEditor, { id, value: String(value ?? ''), language: extra.language || field.language, label: field.label, onChange: (next: string) => change(next) })
|
|
76
|
+
: bindable(textarea(4));
|
|
77
|
+
case 'blocks': case 'richtext': case 'vector': case 'bigint': return null;
|
|
78
|
+
default: return field.media && extra.media ? mediaControl(value, change, field.label, field.multiple, extra.media) : bindable(input('text'));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A field that names one of the site's forms, collections or terms: a searchable list. A value
|
|
84
|
+
* that is no longer there stays, marked, so saving does not drop it unseen; Clear empties an optional one.
|
|
85
|
+
*/
|
|
86
|
+
export function sourceControl(field: EditorField, value: unknown, change: (value: unknown) => void, id: string, sources: SourceChoices): TemplateResult {
|
|
87
|
+
const current = typeof value === 'string' ? value : '';
|
|
88
|
+
const choices = sources[field.choicesFrom as keyof SourceChoices] ?? [];
|
|
89
|
+
const options = current && !choices.some(choice => choice.value === current) ? [{ value: current, label: `${current} (${__('not found')})` }, ...choices] : choices;
|
|
90
|
+
const placeholder = field.choicesFrom === 'forms' ? __('Search forms…') : field.choicesFrom === 'collections' ? __('Search collections…') : field.choicesFrom === 'locations' ? __('Search menu locations…') : __('Search terms…');
|
|
91
|
+
return html`<div class="flex items-start gap-1.5">
|
|
92
|
+
<div class="min-w-0 flex-1">${component(Combobox, { id, options, value: current, placeholder, emptyLabel: __('Nothing matches.'), required: field.required,
|
|
93
|
+
onValueChange: (next: string) => change(next) })}</div>
|
|
94
|
+
${!field.required && current ? iconButton(`${id}-clear`, 'close-circle', `${__('Clear')} ${field.label}`, () => change('')) : null}
|
|
95
|
+
</div>`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A source's choices, and any chosen value no longer among them, marked, so saving does not drop it unseen. */
|
|
99
|
+
function withMissing(choices: readonly { value: string; label: string }[], value: unknown): { value: string; label: string }[] {
|
|
100
|
+
const missing = (Array.isArray(value) ? value.map(String) : []).filter(entry => !choices.some(choice => choice.value === entry));
|
|
101
|
+
return [...choices, ...missing.map(entry => ({ value: entry, label: `${entry} (${__('not found')})` }))];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A multiple choice: one checkbox per choice, the ticked values kept in the choices' order. */
|
|
105
|
+
export function choicesControl(field: EditorField, value: unknown, change: (value: unknown) => void, id: string): TemplateResult {
|
|
106
|
+
const chosen = Array.isArray(value) ? value.map(String) : [];
|
|
107
|
+
const toggle = (entry: string, on: boolean) => change(field.choices.map(choice => choice.value).filter(candidate => candidate === entry ? on : chosen.includes(candidate)));
|
|
108
|
+
return html`<div id=${id} class="space-y-1.5">${field.choices.map(choice => html`<div>${component(Checkbox, { label: choice.label, checked: chosen.includes(choice.value), '@change': (event: Event) => toggle(choice.value, (event.target as HTMLInputElement).checked) })}</div>`)}</div>`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The value a new item of a multiple field starts with: nothing of its kind. */
|
|
112
|
+
function emptyItem(field: EditorField): unknown {
|
|
113
|
+
return field.kind === 'richtext' ? null : '';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A multiple field: the kind's control once per item, each with Move up, Move down and
|
|
118
|
+
* Remove, and the Add button below, within the field's fewest and most items. `item`
|
|
119
|
+
* renders one value's control with its own id.
|
|
120
|
+
*/
|
|
121
|
+
export function multipleControl(field: EditorField, value: unknown, change: (value: unknown) => void, id: string,
|
|
122
|
+
item: (value: unknown, change: (value: unknown) => void, id: string, index: number) => TemplateResult): TemplateResult {
|
|
123
|
+
const items = Array.isArray(value) ? value : [];
|
|
124
|
+
const fewest = field.minItems ?? 0;
|
|
125
|
+
const most = field.maxItems ?? (field.kind === 'reference' ? ITEM_LIMITS.media : ITEM_LIMITS.max);
|
|
126
|
+
const set = (next: unknown[]) => change(next);
|
|
127
|
+
const label = (index: number) => `${field.label} ${index + 1}`;
|
|
128
|
+
return html`<div id=${id} class="space-y-2" data-cms-multiple=${field.name}>
|
|
129
|
+
${items.map((entry, index) => html`<div class="flex items-start gap-1" data-cms-item>
|
|
130
|
+
<div class="min-w-0 flex-1">${item(entry, next => set(items.map((current, at) => at === index ? next : current)), `${id}-${index}`, index)}</div>
|
|
131
|
+
${iconButton(`${id}-${index}-up`, 'arrow-up', `${__('Move up')} ${label(index)}`, () => set(moveItem(items, index, -1)), { disabled: index === 0 })}
|
|
132
|
+
${iconButton(`${id}-${index}-down`, 'arrow-down', `${__('Move down')} ${label(index)}`, () => set(moveItem(items, index, 1)), { disabled: index === items.length - 1 })}
|
|
133
|
+
${iconButton(`${id}-${index}-remove`, 'trash-bin-trash', `${__('Remove')} ${label(index)}`, () => set(items.filter((_, at) => at !== index)), { danger: true, disabled: items.length <= fewest })}
|
|
134
|
+
</div>`)}
|
|
135
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', disabled: items.length >= most, '@click': () => set([...items, emptyItem(field)]) }, field.addLabel || __('Add new'))}
|
|
136
|
+
</div>`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A text control with a picker of the entry's fields beside it. Picking one appends `{{ $.name }}`
|
|
141
|
+
* to its text; the site shows the entry's value there, with the words around it.
|
|
142
|
+
*/
|
|
143
|
+
export function bindingControl(control: TemplateResult, value: unknown, change: (value: unknown) => void, id: string, choices: readonly BindingChoice[]): TemplateResult {
|
|
144
|
+
const bound = hasBinding(value);
|
|
145
|
+
// The button is always there, so people learn that text can show a field; without fields it says why it is off.
|
|
146
|
+
const none = __('This entry has no fields a block can show. Add fields to the collection or a field group.');
|
|
147
|
+
return html`<div class="space-y-1">
|
|
148
|
+
<div class="flex items-start gap-1.5">
|
|
149
|
+
<div class="min-w-0 flex-1">${control}</div>
|
|
150
|
+
${!choices.length ? html`<button type="button" id=${`${id}-bind`} disabled title=${none} aria-label=${__('Show a field of the entry')}
|
|
151
|
+
class="inline-flex h-9 w-9 shrink-0 cursor-not-allowed items-center justify-center rounded-md border border-input bg-background text-muted-foreground opacity-50 [&_svg]:size-4">${component(Icon, { entry: icon('database'), size: 16 })}</button>`
|
|
152
|
+
: component(DropdownMenu, { id: `${id}-bind`, side: 'bottom', align: 'end', 'aria-label': __('Show a field of the entry'), title: __('Show a field of the entry'),
|
|
153
|
+
class: `inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md border bg-background [&_svg]:size-4 ${bound ? 'border-primary text-primary' : 'border-input text-muted-foreground hover:bg-muted hover:text-foreground'}`,
|
|
154
|
+
trigger: component(Icon, { entry: icon('database'), size: 16 }) }, html`
|
|
155
|
+
<p class="px-2 py-1.5 text-xs text-muted-foreground">${__('Show the value of')}</p>
|
|
156
|
+
${choices.map(choice => html`<button type="button" role="menuitem" tabindex="-1" class="flex w-full items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-left text-sm text-foreground hover:bg-muted cursor-pointer border-none bg-transparent"
|
|
157
|
+
@click=${() => change(withBinding(value, choice.name))}><span class="truncate">${choice.label}</span><code class="shrink-0 text-xs text-muted-foreground">{{ $.${choice.name} }}</code></button>`)}`)}
|
|
158
|
+
</div>
|
|
159
|
+
${bound ? html`<p class="text-xs text-muted-foreground">${__('On the site, each {{ $.name }} is replaced by that field of the entry.')}</p>` : null}
|
|
160
|
+
</div>`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** A media field: its files, with Remove buttons, and a button that opens the chooser. */
|
|
164
|
+
export function mediaControl(value: unknown, change: (value: unknown) => void, label: string, multiple: boolean, media: MediaHooks): TemplateResult {
|
|
165
|
+
const ids = Array.isArray(value) ? value as string[] : typeof value === 'string' && value ? [value] : [];
|
|
166
|
+
const remove = (id: string) => change(multiple ? ids.filter(entry => entry !== id) : null);
|
|
167
|
+
return html`<div class="space-y-2">
|
|
168
|
+
${ids.length ? html`<div class=${multiple ? 'grid grid-cols-3 gap-2' : ''}>${ids.map(id => {
|
|
169
|
+
const file = media.previews[id];
|
|
170
|
+
return html`<figure class="group relative overflow-hidden rounded-md border border-border bg-muted">
|
|
171
|
+
${file && mediaKind(file.contentType) === 'image'
|
|
172
|
+
? html`<img src=${file.url} alt=${file.alt} class="aspect-video w-full object-cover" loading="lazy">`
|
|
173
|
+
: html`<p class="p-3 text-xs text-muted-foreground">${file?.title ?? id}</p>`}
|
|
174
|
+
<div class="absolute right-1 top-1 rounded bg-background">${iconButton(`media-${label.toLowerCase().replace(/[^a-z0-9]+/g, '-')}-${id}-remove`, 'trash-bin-trash', __('Remove'), () => remove(id), { danger: true, class: 'shadow-sm' })}</div>
|
|
175
|
+
</figure>`;
|
|
176
|
+
})}</div>` : null}
|
|
177
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => media.choose(multiple) },
|
|
178
|
+
ids.length && !multiple ? `${__('Replace')} ${label.toLowerCase()}` : `${__('Choose')} ${label.toLowerCase()}`)}
|
|
179
|
+
</div>`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A group field (`field.group`, such as a form's settings) as a box of its subfields, one
|
|
184
|
+
* labelled control each. `render` draws a subfield's control; its change writes the subfield
|
|
185
|
+
* into the group's object.
|
|
186
|
+
*/
|
|
187
|
+
export function groupFields(field: EditorField, value: unknown, change: (value: unknown) => void, id: string,
|
|
188
|
+
render: (sub: EditorField, value: unknown, change: (value: unknown) => void, id: string) => TemplateResult): TemplateResult {
|
|
189
|
+
const object = value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
|
190
|
+
return html`<div id=${id} class="space-y-4 rounded-md border border-border p-3">${field.fields.map(sub => {
|
|
191
|
+
const subId = `${id}-${sub.name}`;
|
|
192
|
+
return html`<div class="space-y-1.5">
|
|
193
|
+
${sub.kind === 'boolean' ? null : html`<label for=${subId} class="block text-sm font-medium text-foreground">${sub.label}${sub.required ? html`<span class="text-destructive"> *</span>` : null}</label>`}
|
|
194
|
+
${render(sub, object[sub.name], next => change({ ...object, [sub.name]: next }), subId)}
|
|
195
|
+
${sub.description ? html`<p class="text-xs text-muted-foreground">${sub.description}</p>` : null}
|
|
196
|
+
</div>`;
|
|
197
|
+
})}</div>`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** A block's fields as a form: one labelled control each, spaced like a form. `errors` are keyed by field name. */
|
|
201
|
+
export function blockFields(option: BlockOption, values: Record<string, unknown>, change: (name: string, value: unknown) => void, idPrefix: string,
|
|
202
|
+
media: (name: string) => MediaHooks, errors: Record<string, string> = {}, bindings: readonly BindingChoice[] = [], sources?: SourceChoices): TemplateResult {
|
|
203
|
+
return html`<div class="space-y-4">${option.fields.map(entry => {
|
|
204
|
+
const id = `${idPrefix}-${entry.name}`;
|
|
205
|
+
return html`<div class="space-y-1.5">
|
|
206
|
+
${entry.kind === 'boolean' ? null : html`<label for=${id} class="block text-sm font-medium text-foreground">${entry.label}${entry.required ? ' *' : ''}</label>`}
|
|
207
|
+
${fieldControl(entry, values[entry.name], value => change(entry.name, value), id, { media: media(entry.name), bindings, language: String(values.language ?? ''), ...(sources ? { sources } : {}) })}
|
|
208
|
+
${entry.description ? html`<p class="text-xs text-muted-foreground">${entry.description}</p>` : null}
|
|
209
|
+
${errors[entry.name] ? html`<p role="alert" class="text-xs text-destructive">${entry.label} ${errors[entry.name]}</p>` : null}
|
|
210
|
+
</div>`;
|
|
211
|
+
})}</div>`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Move one item of a list by `delta` places; the list unchanged when it would leave the ends. */
|
|
215
|
+
export function moveItem<T>(items: readonly T[], index: number, delta: number): T[] {
|
|
216
|
+
const target = index + delta;
|
|
217
|
+
if (index < 0 || index >= items.length || target < 0 || target >= items.length) return [...items];
|
|
218
|
+
const moved = [...items];
|
|
219
|
+
const [item] = moved.splice(index, 1);
|
|
220
|
+
moved.splice(target, 0, item!);
|
|
221
|
+
return moved;
|
|
222
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field group editor: the block tree in field group mode (field blocks and layout blocks)
|
|
3
|
+
* with the side panel for a block's settings and its condition, applied as they change. Shared by the collection
|
|
4
|
+
* builder and the field group screen. Client-safe: the blocks are control values, and the
|
|
5
|
+
* screen saves them.
|
|
6
|
+
*/
|
|
7
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
8
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
9
|
+
import { findBlock, updateBlock, type BlockCondition } from '@cossackframework/cms';
|
|
10
|
+
import { blockPanel } from './block-panel';
|
|
11
|
+
import { BlockTree } from './block-tree';
|
|
12
|
+
import { fieldName } from './builder';
|
|
13
|
+
import { conditionControl, conditionFields, type ConditionField } from './condition-control';
|
|
14
|
+
import { editorInput, type BlockOption, type EditorBlock } from './editor';
|
|
15
|
+
import { blockFields } from './field-controls';
|
|
16
|
+
import { styleValues } from './style-controls';
|
|
17
|
+
|
|
18
|
+
export type FieldGroupEditorProps = {
|
|
19
|
+
/** Page-unique prefix for control IDs. */
|
|
20
|
+
id: string;
|
|
21
|
+
blocks: EditorBlock[];
|
|
22
|
+
/** Every block type; the tree offers the field and layout blocks among them. */
|
|
23
|
+
options: BlockOption[];
|
|
24
|
+
/** The target's own fields a condition may test, such as an entry's status. */
|
|
25
|
+
scope?: ConditionField[];
|
|
26
|
+
/** The screen's validation message, for the tree to open and flash the block it names. */
|
|
27
|
+
error?: string;
|
|
28
|
+
onChange(blocks: EditorBlock[]): void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** The block open in the panel. */
|
|
32
|
+
interface Dialog { id: string; values: Record<string, unknown>; errors: Record<string, string>; when?: BlockCondition }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@Component()
|
|
36
|
+
export class FieldGroupEditor extends Cossack {
|
|
37
|
+
declare props: FieldGroupEditorProps;
|
|
38
|
+
@ClientState() private dialog: Dialog | null = null;
|
|
39
|
+
|
|
40
|
+
@Client()
|
|
41
|
+
private open(id: string) {
|
|
42
|
+
const block = findBlock(this.props.blocks, id);
|
|
43
|
+
const option = this.props.options.find(entry => entry.name === block?.type);
|
|
44
|
+
if (!block || !option) return;
|
|
45
|
+
this.dialog = { id, errors: {}, values: Object.fromEntries(option.fields.map(field => [field.name, block.data[field.name] ?? ''])), ...(block.when ? { when: block.when } : {}) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Client()
|
|
49
|
+
private setValue(name: string, value: unknown) {
|
|
50
|
+
if (!this.dialog) return;
|
|
51
|
+
const values = { ...this.dialog.values, [name]: value };
|
|
52
|
+
// An unnamed field follows its label, as form inputs do.
|
|
53
|
+
if (name === 'label' && !String(this.dialog.values.name ?? '').trim()) values.name = '';
|
|
54
|
+
this.commit({ ...this.dialog, values, errors: { ...this.dialog.errors, [name]: '' } });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Client()
|
|
58
|
+
private setCondition(when: BlockCondition | null) {
|
|
59
|
+
if (!this.dialog) return;
|
|
60
|
+
const { when: _previous, ...rest } = this.dialog;
|
|
61
|
+
this.commit(when ? { ...rest, when } : rest);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The panel's values go into the block at once. A value its field cannot take stays in the
|
|
66
|
+
* panel with its message; a missing name follows the label, as saving derives it.
|
|
67
|
+
*/
|
|
68
|
+
@Client()
|
|
69
|
+
private commit(dialog: Dialog) {
|
|
70
|
+
const block = findBlock(this.props.blocks, dialog.id);
|
|
71
|
+
const option = this.props.options.find(entry => entry.name === block?.type);
|
|
72
|
+
if (!block || !option) return;
|
|
73
|
+
const { input, errors } = editorInput(option.fields, dialog.values);
|
|
74
|
+
if (option.field && !String(input.name ?? '').trim() && String(input.label ?? '').trim()) input.name = fieldName(String(input.label ?? ''));
|
|
75
|
+
this.dialog = { ...dialog, errors: { ...dialog.errors, ...errors } };
|
|
76
|
+
this.props.onChange(updateBlock(this.props.blocks, dialog.id, entry => {
|
|
77
|
+
const { when: _previous, ...rest } = entry;
|
|
78
|
+
return { ...rest, ...(dialog.when ? { when: dialog.when } : {}), data: { ...entry.data, ...input } };
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
render(): TemplateResult {
|
|
83
|
+
const dialog = this.dialog;
|
|
84
|
+
const block = dialog ? findBlock(this.props.blocks, dialog.id) : undefined;
|
|
85
|
+
const option = this.props.options.find(entry => entry.name === block?.type) ?? null;
|
|
86
|
+
const prefix = `${this.props.id}-block`;
|
|
87
|
+
return html`<div class="space-y-3">
|
|
88
|
+
${component(BlockTree, {
|
|
89
|
+
id: this.props.id, blocks: this.props.blocks, options: this.props.options, allowed: [], fieldGroup: true, error: this.props.error ?? '',
|
|
90
|
+
onChange: (blocks: EditorBlock[]) => this.props.onChange(blocks), onEdit: (id: string) => this.open(id),
|
|
91
|
+
control: () => null,
|
|
92
|
+
})}
|
|
93
|
+
${blockPanel({
|
|
94
|
+
id: prefix, open: Boolean(dialog && option), option, tab: 'general', style: styleValues({}), presets: { colors: [], gradients: [], fontSizes: [], spacing: [] }, styleTab: false,
|
|
95
|
+
onTab: () => undefined, onStyle: () => undefined, onClose: () => { this.dialog = null; },
|
|
96
|
+
general: dialog && option ? html`
|
|
97
|
+
${option.fields.length ? blockFields(option, dialog.values, (name, value) => this.setValue(name, value), `${prefix}-${dialog.id}`, () => ({ previews: {}, choose: () => undefined }), dialog.errors)
|
|
98
|
+
: html`<p class="text-sm text-muted-foreground">${__('This block has no settings.')}</p>`}
|
|
99
|
+
${conditionControl(dialog.when, [...(this.props.scope ?? []), ...conditionFields(this.props.blocks, this.props.options, dialog.id)], `${prefix}-${dialog.id}`,
|
|
100
|
+
when => this.setCondition(when ?? null),
|
|
101
|
+
{ toggle: __('Conditional logic'), subject: __('this'), show: __('Show'), hide: __('Hide') })}` : html``,
|
|
102
|
+
})}
|
|
103
|
+
</div>`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A field group as an editor shows it: the group's layout blocks as dashboard UI (sections,
|
|
3
|
+
* columns, grids, tabs, headings, notes, rules) and its field blocks as controls, which the
|
|
4
|
+
* screen renders since it owns media choosing. A repeater's rows are collapsible sections
|
|
5
|
+
* with their own fields, reordered with buttons; rows nest. Client-safe.
|
|
6
|
+
*/
|
|
7
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
8
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
9
|
+
import { Badge, Button, Icon, Tabs } from '@cossackframework/ui';
|
|
10
|
+
import { blockId, hiddenKey, type Block, type BlockDeclaration } from '@cossackframework/cms';
|
|
11
|
+
import { presenceChip, presenceOutline, type Someone } from './collab/presence';
|
|
12
|
+
import { controlValue, type BlockOption, type EditorBlock, type EditorField } from './editor';
|
|
13
|
+
import { icon } from './icons';
|
|
14
|
+
import { iconButton } from './ui';
|
|
15
|
+
|
|
16
|
+
/** Where a value sits: the rows fields above it, with the row IDs, from the top down. */
|
|
17
|
+
export type RowPath = { field: string; id: string }[];
|
|
18
|
+
|
|
19
|
+
export type FieldGroupViewProps = {
|
|
20
|
+
/** Page-unique prefix for control IDs. */
|
|
21
|
+
id: string;
|
|
22
|
+
blocks: EditorBlock[];
|
|
23
|
+
options: BlockOption[];
|
|
24
|
+
/** The fields the blocks declare, as the editor holds them, at this level. */
|
|
25
|
+
fields: EditorField[];
|
|
26
|
+
values: Record<string, unknown>;
|
|
27
|
+
onChange(name: string, value: unknown): void;
|
|
28
|
+
/** Keys of the blocks the conditions hide; see `hiddenKey`. */
|
|
29
|
+
hidden: ReadonlySet<string>;
|
|
30
|
+
/** Messages by field name at this level. */
|
|
31
|
+
errors?: Record<string, string>;
|
|
32
|
+
/** A field's control, given where it sits. Null renders the generic control's place empty. */
|
|
33
|
+
control(field: EditorField, value: unknown, change: (value: unknown) => void, rows: RowPath, id: string): TemplateResult | null;
|
|
34
|
+
/** The rows above this view, for nested views. */
|
|
35
|
+
rows?: RowPath;
|
|
36
|
+
/** Who else is in a field, by its presence anchor (`data-field`): the field is outlined in their color with a chip. */
|
|
37
|
+
presence?(anchor: string): readonly Someone[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** The block types as declarations, enough for `fieldVisibility`: which blocks are field blocks and of what kind. */
|
|
41
|
+
export function visibilityTypes(options: readonly BlockOption[]): ReadonlyMap<string, BlockDeclaration> {
|
|
42
|
+
return new Map(options.map(option => [option.name, { name: option.name, label: option.label, fields: {}, ...(option.field ? { field: { kind: option.field as never } } : {}), ...(option.children ? { children: {} } : {}) }]));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The widths of a field block in the six-column grid. */
|
|
46
|
+
const WIDTHS: Record<string, string> = { full: 'col-span-6', half: 'col-span-6 sm:col-span-3', third: 'col-span-6 sm:col-span-2' };
|
|
47
|
+
|
|
48
|
+
@Component()
|
|
49
|
+
export class FieldGroupView extends Cossack {
|
|
50
|
+
declare props: FieldGroupViewProps;
|
|
51
|
+
@ClientState() private tabs: Record<string, number> = {};
|
|
52
|
+
@ClientState() private collapsed: Record<string, boolean> = {};
|
|
53
|
+
|
|
54
|
+
private option(type: string): BlockOption | undefined {
|
|
55
|
+
return this.props.options.find(entry => entry.name === type);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private rowKey(name: string, id: string): string {
|
|
59
|
+
return `${this.props.id}:${name}:${id}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A field's presence anchor here: its name under the rows above it (`items:<rowId>.title`). */
|
|
63
|
+
private anchor(name: string): string {
|
|
64
|
+
return [...(this.props.rows ?? []).map(row => `${row.field}:${row.id}`), name].join('.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Client()
|
|
68
|
+
private showTab(id: string, index: number) {
|
|
69
|
+
this.tabs = { ...this.tabs, [id]: index };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Client()
|
|
73
|
+
private toggleRow(key: string, collapsed: boolean) {
|
|
74
|
+
this.collapsed = { ...this.collapsed, [key]: collapsed };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A new row: an ID and each field's default. */
|
|
78
|
+
private newRow(field: EditorField): Record<string, unknown> {
|
|
79
|
+
return { _id: blockId(), ...Object.fromEntries(field.fields.map(sub => [sub.name, controlValue(sub, sub.defaultValue)])) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private rowsOf(name: string): Record<string, unknown>[] {
|
|
83
|
+
const value = this.props.values[name];
|
|
84
|
+
return Array.isArray(value) ? value as Record<string, unknown>[] : [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private list(blocks: readonly EditorBlock[]): TemplateResult {
|
|
88
|
+
return html`<div class="grid grid-cols-6 gap-4">${blocks.map(block => {
|
|
89
|
+
const option = this.option(block.type);
|
|
90
|
+
if (this.props.hidden.has(hiddenKey((this.props.rows ?? []).map(row => ({ name: row.field, id: row.id })), block._id))) return null;
|
|
91
|
+
const width = option?.field ? WIDTHS[String(block.data.width ?? 'full')] ?? WIDTHS.full : 'col-span-6';
|
|
92
|
+
return html`<div class=${width}>${option?.field ? this.fieldBlock(block, option) : this.layoutBlock(block, option)}</div>`;
|
|
93
|
+
})}</div>`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private layoutBlock(block: EditorBlock, option: BlockOption | undefined): TemplateResult | null {
|
|
97
|
+
const children = block.children ?? [];
|
|
98
|
+
switch (block.type) {
|
|
99
|
+
case 'core/heading': return html`<h3 class="text-base font-semibold text-foreground">${String(block.data.text ?? '')}</h3>`;
|
|
100
|
+
case 'core/paragraph': return html`<p class="whitespace-pre-line text-sm text-muted-foreground">${String(block.data.text ?? '')}</p>`;
|
|
101
|
+
case 'core/divider': return html`<hr class="border-border">`;
|
|
102
|
+
case 'core/columns': return html`<div class=${`grid gap-4 ${children.length > 1 ? `sm:grid-cols-${Math.min(children.length, 6)}` : ''}`}>${children.map(column => this.list(column.children ?? []))}</div>`;
|
|
103
|
+
case 'core/grid': {
|
|
104
|
+
const columns = Math.min(Math.max(Number(block.data.columns) || 2, 1), 6);
|
|
105
|
+
return html`<div class=${`grid gap-4 sm:grid-cols-${columns}`}>${children.map(child => html`<div>${this.list([child])}</div>`)}</div>`;
|
|
106
|
+
}
|
|
107
|
+
case 'core/tabs': {
|
|
108
|
+
const active = Math.min(this.tabs[block._id] ?? 0, Math.max(children.length - 1, 0));
|
|
109
|
+
const prefix = `${this.props.id}-${block._id}`;
|
|
110
|
+
return component(Tabs, {
|
|
111
|
+
id: prefix, label: __('Field group tabs'), value: String(active), variant: 'underline',
|
|
112
|
+
listProps: { class: 'flex flex-wrap' },
|
|
113
|
+
onValueChange: (value: string) => this.showTab(block._id, Number(value)),
|
|
114
|
+
items: children.map((tab, index) => ({
|
|
115
|
+
value: String(index), label: String(tab.data.label ?? '').trim() || __('Tab'),
|
|
116
|
+
icon: typeof tab.data.icon === 'string' && tab.data.icon ? component(Icon, { entry: icon(tab.data.icon), size: 16 }) : undefined,
|
|
117
|
+
content: this.list(tab.children ?? []),
|
|
118
|
+
})),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
default: return option?.children ? html`<div class="space-y-4">${this.list(children)}</div>` : null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private fieldBlock(block: EditorBlock, option: BlockOption): TemplateResult | null {
|
|
126
|
+
const name = typeof block.data.name === 'string' ? block.data.name : '';
|
|
127
|
+
const field = this.props.fields.find(entry => entry.name === name);
|
|
128
|
+
if (!field) return null;
|
|
129
|
+
const anchor = this.anchor(name);
|
|
130
|
+
const here = this.props.presence?.(anchor) ?? [];
|
|
131
|
+
const chip = here.length ? presenceChip(here, __('is here')) : null;
|
|
132
|
+
if (option.field === 'repeater') return html`<div class="space-y-1.5" data-field=${anchor} style=${presenceOutline(here)}>${chip}${this.repeater(block, field)}</div>`;
|
|
133
|
+
const id = [this.props.id, ...(this.props.rows ?? []).map(row => `${row.field}-${row.id}`), name].join('-');
|
|
134
|
+
const error = this.props.errors?.[name];
|
|
135
|
+
return html`<div class="space-y-1.5" data-field=${anchor} style=${presenceOutline(here)}>
|
|
136
|
+
${field.kind === 'boolean' ? null : html`<label for=${id} class="block text-sm font-medium text-foreground">${field.label}${field.required ? html`<span class="text-destructive"> *</span>` : null}</label>`}
|
|
137
|
+
${chip}
|
|
138
|
+
${this.props.control(field, this.props.values[name], value => this.props.onChange(name, value), this.props.rows ?? [], id)}
|
|
139
|
+
${field.description ? html`<p class="text-xs text-muted-foreground">${field.description}</p>` : null}
|
|
140
|
+
${error ? html`<p role="alert" class="text-xs text-destructive">${field.label} ${error}</p>` : null}
|
|
141
|
+
</div>`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** A row's title: its summary field, or its first text, or its number. */
|
|
145
|
+
private rowTitle(block: EditorBlock, field: EditorField, row: Record<string, unknown>, index: number): string {
|
|
146
|
+
const summary = typeof block.data.summary === 'string' && block.data.summary ? block.data.summary : field.fields.find(sub => sub.kind === 'string' && !sub.media)?.name;
|
|
147
|
+
const value = summary ? row[summary] : undefined;
|
|
148
|
+
return typeof value === 'string' && value.trim() ? value.trim().slice(0, 80) : `${field.label} ${index + 1}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private repeater(block: EditorBlock, field: EditorField): TemplateResult {
|
|
152
|
+
const name = field.name;
|
|
153
|
+
const rows = this.rowsOf(name);
|
|
154
|
+
const max = field.max ?? 200;
|
|
155
|
+
const set = (next: Record<string, unknown>[]) => this.props.onChange(name, next);
|
|
156
|
+
const move = (index: number, delta: number) => {
|
|
157
|
+
const to = index + delta;
|
|
158
|
+
if (to < 0 || to >= rows.length) return;
|
|
159
|
+
const next = [...rows];
|
|
160
|
+
[next[index], next[to]] = [next[to]!, next[index]!];
|
|
161
|
+
set(next);
|
|
162
|
+
};
|
|
163
|
+
const prefix = `${this.props.id}-${block._id}`;
|
|
164
|
+
return html`<fieldset class="space-y-2 rounded-lg border border-border p-3" aria-describedby=${`${prefix}-count`}>
|
|
165
|
+
<legend class="px-1 text-sm font-medium text-foreground">${field.label}${field.required ? html`<span class="text-destructive"> *</span>` : null}</legend>
|
|
166
|
+
${field.description ? html`<p class="text-xs text-muted-foreground">${field.description}</p>` : null}
|
|
167
|
+
<p id=${`${prefix}-count`} class="sr-only">${rows.length} ${rows.length === 1 ? __('row') : __('rows')}</p>
|
|
168
|
+
${rows.map((row, index) => {
|
|
169
|
+
const id = typeof row._id === 'string' ? row._id : String(index);
|
|
170
|
+
const key = this.rowKey(name, id);
|
|
171
|
+
// Rows start open at the top level and closed inside another repeater.
|
|
172
|
+
const collapsed = this.collapsed[key] ?? (this.props.rows?.length ?? 0) > 0;
|
|
173
|
+
const title = this.rowTitle(block, field, row, index);
|
|
174
|
+
const rowPath: RowPath = [...(this.props.rows ?? []), { field: name, id }];
|
|
175
|
+
return html`<section class="rounded-md border border-border bg-card" aria-label=${`${field.label} ${index + 1}`}>
|
|
176
|
+
<header class="flex flex-wrap items-center gap-1.5 px-2 py-1.5">
|
|
177
|
+
<button type="button" class="inline-flex h-7 w-6 shrink-0 items-center justify-center rounded border-none bg-transparent text-muted-foreground hover:bg-muted cursor-pointer [&_svg]:size-4"
|
|
178
|
+
aria-expanded=${collapsed ? 'false' : 'true'} aria-label=${`${collapsed ? __('Expand') : __('Collapse')} ${title}`} @click=${() => this.toggleRow(key, !collapsed)}>
|
|
179
|
+
${component(Icon, { entry: icon(collapsed ? 'alt-arrow-right' : 'alt-arrow-down'), size: 16 })}</button>
|
|
180
|
+
<span class="min-w-0 flex-1 truncate text-sm text-foreground">${title}</span>
|
|
181
|
+
${collapsed ? component(Badge, { variant: 'outline' }, String(index + 1)) : null}
|
|
182
|
+
<span class="flex items-center gap-1">
|
|
183
|
+
${iconButton(`${prefix}-${id}-up`, 'arrow-up', `${__('Move up')} ${title}`, () => move(index, -1), { disabled: index === 0 })}
|
|
184
|
+
${iconButton(`${prefix}-${id}-down`, 'arrow-down', `${__('Move down')} ${title}`, () => move(index, 1), { disabled: index === rows.length - 1 })}
|
|
185
|
+
${iconButton(`${prefix}-${id}-remove`, 'trash-bin-trash', `${__('Remove')} ${title}`, () => set(rows.filter((_, at) => at !== index)), { danger: true })}
|
|
186
|
+
</span>
|
|
187
|
+
</header>
|
|
188
|
+
${collapsed ? null : html`<div class="border-t border-border p-3">${component(FieldGroupView, {
|
|
189
|
+
id: `${prefix}-${id}`, blocks: block.children ?? [], options: this.props.options, fields: field.fields, values: row, hidden: this.props.hidden, rows: rowPath,
|
|
190
|
+
onChange: (sub: string, value: unknown) => set(rows.map((entry, at) => at === index ? { ...entry, [sub]: value } : entry)),
|
|
191
|
+
control: this.props.control, ...(this.props.presence ? { presence: this.props.presence } : {}),
|
|
192
|
+
})}</div>`}
|
|
193
|
+
</section>`;
|
|
194
|
+
})}
|
|
195
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
196
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', disabled: rows.length >= max, '@click': () => set([...rows, this.newRow(field)]) }, `${__('Add')} ${field.label.toLowerCase()}`)}
|
|
197
|
+
${rows.length >= max ? html`<span class="text-xs text-muted-foreground">${__('At most')} ${max} ${__('rows')}.</span>` : null}
|
|
198
|
+
</div>
|
|
199
|
+
${this.props.errors?.[name] ? html`<p role="alert" class="text-xs text-destructive">${field.label} ${this.props.errors[name]}</p>` : null}
|
|
200
|
+
</fieldset>`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
render(): TemplateResult {
|
|
204
|
+
return this.list(this.props.blocks);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The blocks of a group as plain blocks, for `fieldVisibility`. */
|
|
209
|
+
export function plainBlocks(blocks: readonly EditorBlock[]): Block[] {
|
|
210
|
+
return blocks as unknown as Block[];
|
|
211
|
+
}
|