@cossackframework/cms 0.0.0 → 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 +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 +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 +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,697 @@
|
|
|
1
|
+
import { Cossack, Page, State, ClientState, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { AlertDialog, Button, Card, CardBody, Checkbox, Icon, Input, Sheet, Tabs } from '@cossackframework/ui';
|
|
3
|
+
import { html, component, repeat, type TemplateResult } from '@cossackframework/renderer';
|
|
4
|
+
import {
|
|
5
|
+
allowedMoves, buildMenu, dropDepths, flattenMenu, isCmsError, MENU_ATTRIBUTE, MENU_LIMITS, menuItemId, moveRows, PERMISSIONS, recordTitle, safeLinkUrl, shiftRows, subtreeEnd,
|
|
6
|
+
type MenuMove, type MenuRow, type Principal,
|
|
7
|
+
} from '@cossackframework/cms';
|
|
8
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
9
|
+
import { requireAny } from '#app/cms/guards';
|
|
10
|
+
import { groupsView, listUpTo, metaInput, metaValues, type GroupsView } from '#app/cms/content';
|
|
11
|
+
import { fieldControl } from '#app/cms/field-controls';
|
|
12
|
+
import { FieldGroupView, plainBlocks, visibilityTypes, type RowPath } from '#app/cms/field-group-view';
|
|
13
|
+
import { fieldVisibility } from '@cossackframework/cms';
|
|
14
|
+
import type { EditorField } from '#app/cms/editor';
|
|
15
|
+
import { icon } from '#app/cms/icons';
|
|
16
|
+
import { box, CONTROL, iconButton, linkButton, notice, pageHeader } from '#app/cms/ui';
|
|
17
|
+
import { openMatches } from '#app/cms/site';
|
|
18
|
+
|
|
19
|
+
interface SourceEntry { id: string; title: string; depth: number }
|
|
20
|
+
interface Source { kind: 'collection' | 'taxonomy'; name: string; label: string; singular: string; icon: string; archive: boolean; entries: SourceEntry[] }
|
|
21
|
+
/** What an item points at, for its row: the entry's or term's current title, its kind's icon and where to edit it. */
|
|
22
|
+
interface Target { title: string; type: string; icon: string; draft: boolean; missing: boolean; edit: string | null }
|
|
23
|
+
/** A custom attribute being edited: a key and a value, in rows the editor keeps while they are typed. */
|
|
24
|
+
interface Attribute { name: string; value: string }
|
|
25
|
+
type ItemTab = 'general' | 'fields' | 'advanced';
|
|
26
|
+
interface LocationChoice { name: string; label: string; theme: string; active: boolean; checked: boolean }
|
|
27
|
+
interface Drag { from: number; to: number; depth: number; valid: boolean; y: number; moved: boolean }
|
|
28
|
+
|
|
29
|
+
/** Pixels of horizontal drag per nesting level, and the indent of each level in the list. */
|
|
30
|
+
const INDENT = 32;
|
|
31
|
+
const MOVE_LABELS: Record<MenuMove, string> = { up: 'Move up', down: 'Move down', in: 'Move under the item above', out: 'Move out one level' };
|
|
32
|
+
const MOVE_ICONS: Record<MenuMove, string> = { up: 'arrow-up', down: 'arrow-down', in: 'arrow-right', out: 'arrow-left' };
|
|
33
|
+
|
|
34
|
+
/** Item titles and types, read as the editor so drafts show too. */
|
|
35
|
+
async function describe(cms: CmsHost, rows: readonly MenuRow[], principal: Principal): Promise<Record<string, Target>> {
|
|
36
|
+
const targets: Record<string, Target> = {};
|
|
37
|
+
const entries = new Map<string, string[]>();
|
|
38
|
+
for (const row of rows) if (row.kind === 'entry' && row.collection && row.entry) entries.set(row.collection, [...(entries.get(row.collection) ?? []), row.entry]);
|
|
39
|
+
const found = new Map<string, { title: string; draft: boolean }>();
|
|
40
|
+
for (const [name, ids] of entries) {
|
|
41
|
+
try {
|
|
42
|
+
const collection = cms.collection(name);
|
|
43
|
+
for (const record of (await cms.resource(`cms/${name}`).getMany(ids, { principal })).values()) {
|
|
44
|
+
found.set(`${name}:${record.id}`, { title: recordTitle(record, 'title'), draft: collection.publishable !== false && record.status !== 'published' });
|
|
45
|
+
}
|
|
46
|
+
} catch (error) { if (!isCmsError(error)) throw error; }
|
|
47
|
+
}
|
|
48
|
+
const terms = await cms.taxonomies.getMany(rows.filter(row => row.kind === 'term' && row.term).map(row => row.term!));
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
if (row.kind === 'link') { targets[row.id] = { title: row.url ?? '', type: __('Custom link'), icon: 'link-round', draft: false, missing: false, edit: null }; continue; }
|
|
51
|
+
if (row.kind === 'heading') { targets[row.id] = { title: '', type: __('Heading'), icon: 'text-field', draft: false, missing: false, edit: null }; continue; }
|
|
52
|
+
if (row.kind === 'archive') {
|
|
53
|
+
const collection = cms.collections().find(entry => entry.name === row.collection);
|
|
54
|
+
targets[row.id] = { title: collection?.label ?? row.collection ?? '', type: __('Archive'), icon: 'folder-with-files', draft: false, missing: !collection?.path, edit: null };
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (row.kind === 'entry') {
|
|
58
|
+
const entry = found.get(`${row.collection}:${row.entry}`);
|
|
59
|
+
const collection = cms.collections().find(item => item.name === row.collection);
|
|
60
|
+
targets[row.id] = { title: entry?.title ?? __('Deleted entry'), type: collection?.singular ?? row.collection ?? '', icon: collection?.icon ?? 'document-text', draft: entry?.draft ?? false, missing: !entry, edit: entry ? `/dashboard/content/${row.collection}/${row.entry}` : null };
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const term = terms.get(row.term ?? '');
|
|
64
|
+
const taxonomy = cms.taxonomies.declarations.find(item => item.name === row.taxonomy);
|
|
65
|
+
targets[row.id] = { title: term?.name ?? __('Deleted term'), type: taxonomy?.singular ?? row.taxonomy ?? '', icon: term?.icon || (taxonomy?.hierarchical ? 'folder' : 'tag'), draft: false, missing: !term, edit: term ? `/dashboard/terms/${term.taxonomy}/${term.id}` : null };
|
|
66
|
+
}
|
|
67
|
+
return targets;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Synced patterns an item can show as its mega menu panel, by title. */
|
|
71
|
+
async function syncedPatterns(cms: CmsHost, principal: Principal): Promise<{ id: string; title: string }[]> {
|
|
72
|
+
try {
|
|
73
|
+
const records = await listUpTo(cms, 'cms/patterns', { where: { synced: true }, order: { field: 'title', direction: 'asc' } }, principal, 200);
|
|
74
|
+
return records.map(record => ({ id: record.id, title: recordTitle(record, 'title') }));
|
|
75
|
+
} catch (error) { if (isCmsError(error)) return []; throw error; }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Collections and taxonomies with public URLs, each with recent entries or its terms. */
|
|
79
|
+
async function sources(cms: CmsHost, principal: Principal): Promise<Source[]> {
|
|
80
|
+
const list: Source[] = [];
|
|
81
|
+
for (const collection of cms.collections()) {
|
|
82
|
+
if (collection.path === null || collection.path === undefined || collection.slug === false) continue;
|
|
83
|
+
const publishable = collection.publishable !== false;
|
|
84
|
+
const page = await cms.resource(`cms/${collection.name}`).list({
|
|
85
|
+
...(publishable ? { where: { status: 'published' } } : {}), limit: 30,
|
|
86
|
+
order: collection.hierarchical || !publishable ? { field: 'title', direction: 'asc' } : { field: 'publishedAt', direction: 'desc' },
|
|
87
|
+
}, { principal }).catch(() => ({ records: [] }));
|
|
88
|
+
list.push({ kind: 'collection', name: collection.name, label: collection.label, singular: collection.singular, icon: collection.icon ?? 'document-text', archive: collection.path !== '',
|
|
89
|
+
entries: page.records.map(record => ({ id: record.id, title: recordTitle(record, 'title'), depth: 0 })) });
|
|
90
|
+
}
|
|
91
|
+
for (const taxonomy of cms.taxonomies.declarations) {
|
|
92
|
+
if (!taxonomy.path) continue;
|
|
93
|
+
const terms = (await cms.taxonomies.tree(taxonomy.name)).slice(0, 100);
|
|
94
|
+
list.push({ kind: 'taxonomy', name: taxonomy.name, label: taxonomy.label, singular: taxonomy.singular, icon: taxonomy.hierarchical ? 'folder' : 'tag', archive: false, entries: terms.map(term => ({ id: term.id, title: term.name, depth: term.depth })) });
|
|
95
|
+
}
|
|
96
|
+
return list;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The menu editor, laid out like WordPress: item sources on the left (entries, terms, custom
|
|
101
|
+
* links and headings), the menu's structure on the right. Drag an item by its handle (mouse,
|
|
102
|
+
* touch or pen); dragging sideways nests it. The arrow keys on a handle and the buttons in each
|
|
103
|
+
* item move it too. An item's General tab takes its label, URL, description and mega menu
|
|
104
|
+
* panel; Fields holds the field groups attached to menu items; Advanced its class names and
|
|
105
|
+
* attributes.
|
|
106
|
+
*/
|
|
107
|
+
@Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageAppearance)] })
|
|
108
|
+
export default class MenuEditor extends Cossack {
|
|
109
|
+
@State() id = '';
|
|
110
|
+
@State() name = '';
|
|
111
|
+
@State() revision = 0;
|
|
112
|
+
@State() rows: MenuRow[] = [];
|
|
113
|
+
@State() targets: Record<string, Target> = {};
|
|
114
|
+
@State() sources: Source[] = [];
|
|
115
|
+
/** Synced patterns, for an item's Mega menu panel select. */
|
|
116
|
+
@State() patterns: { id: string; title: string }[] = [];
|
|
117
|
+
@State() locations: LocationChoice[] = [];
|
|
118
|
+
/** Field groups attached to menu items; each row's `meta` holds their control values. */
|
|
119
|
+
@State() fieldGroups: GroupsView = { groups: [], fields: [], options: [] };
|
|
120
|
+
@State() error = '';
|
|
121
|
+
/** What the last save did. */
|
|
122
|
+
@State() message = '';
|
|
123
|
+
@State() conflict = false;
|
|
124
|
+
@ClientState() selected: Record<string, string[]> = {};
|
|
125
|
+
@ClientState() link = { url: '', label: '' };
|
|
126
|
+
@ClientState() linkError = '';
|
|
127
|
+
@ClientState() heading = '';
|
|
128
|
+
@ClientState() headingError = '';
|
|
129
|
+
/** The item open in the side sheet, one at a time, as blocks are edited. */
|
|
130
|
+
@ClientState() editing: string | null = null;
|
|
131
|
+
/** The tab shown under each open item. */
|
|
132
|
+
@ClientState() tabs: Record<string, ItemTab> = {};
|
|
133
|
+
/** Attributes as typed, by item; saved into the row when complete. */
|
|
134
|
+
@ClientState() attributes: Record<string, Attribute[]> = {};
|
|
135
|
+
@ClientState() drag: Drag | null = null;
|
|
136
|
+
@ClientState() announcement = '';
|
|
137
|
+
@ClientState() dirty = false;
|
|
138
|
+
@ClientState() saving = false;
|
|
139
|
+
@ClientState() confirmDelete = false;
|
|
140
|
+
private rowElements = new Map<string, HTMLElement>();
|
|
141
|
+
private handles = new Map<string, HTMLElement>();
|
|
142
|
+
private list?: HTMLElement;
|
|
143
|
+
private pointer: { id: number; x: number; y: number; depth: number; tops: number[]; bottoms: number[] } | null = null;
|
|
144
|
+
|
|
145
|
+
head(): HeadValue {
|
|
146
|
+
return { title: this.name ? `${__('Edit menu')}: ${this.name}` : __('Edit menu') };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async init() {
|
|
150
|
+
const cms = this.c.get('cms');
|
|
151
|
+
const principal = this.c.get('principal');
|
|
152
|
+
const menu = await cms.menus.get(this.c.req.param('id') ?? '');
|
|
153
|
+
if (!menu) { this.error = __('This menu does not exist.'); this.c.status(404); return; }
|
|
154
|
+
this.id = menu.id;
|
|
155
|
+
this.name = menu.name;
|
|
156
|
+
this.revision = menu.revision;
|
|
157
|
+
this.fieldGroups = await groupsView(cms, { kind: 'menus' });
|
|
158
|
+
this.rows = this.withMetaValues(flattenMenu(menu.items));
|
|
159
|
+
this.targets = await describe(cms, this.rows, principal);
|
|
160
|
+
this.sources = await sources(cms, principal);
|
|
161
|
+
this.patterns = await syncedPatterns(cms, principal);
|
|
162
|
+
const assigned = await cms.menus.locations();
|
|
163
|
+
this.locations = (await cms.menuLocations()).map(location => ({ ...location, checked: assigned.get(location.name) === menu.id }));
|
|
164
|
+
this.message = this.c.req.query('saved') === '1' ? __('Menu saved.') : '';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// --- Adding items ------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
@Client()
|
|
170
|
+
toggleSelected(source: string, id: string, checked: boolean) {
|
|
171
|
+
const current = this.selected[source] ?? [];
|
|
172
|
+
this.selected = { ...this.selected, [source]: checked ? [...current, id] : current.filter(entry => entry !== id) };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Client()
|
|
176
|
+
addSelected(source: Source) {
|
|
177
|
+
const chosen = this.selected[source.name] ?? [];
|
|
178
|
+
if (!chosen.length) return;
|
|
179
|
+
const added: MenuRow[] = [];
|
|
180
|
+
const targets = { ...this.targets };
|
|
181
|
+
for (const value of chosen) {
|
|
182
|
+
const id = menuItemId();
|
|
183
|
+
if (value === '__archive') {
|
|
184
|
+
added.push({ id, kind: 'archive', label: '', collection: source.name, depth: 0 });
|
|
185
|
+
targets[id] = { title: source.label, type: __('Archive'), icon: 'folder-with-files', draft: false, missing: false, edit: null };
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const entry = source.entries.find(item => item.id === value);
|
|
189
|
+
if (!entry) continue;
|
|
190
|
+
added.push(source.kind === 'collection' ? { id, kind: 'entry', label: '', collection: source.name, entry: entry.id, depth: 0 } : { id, kind: 'term', label: '', taxonomy: source.name, term: entry.id, depth: 0 });
|
|
191
|
+
targets[id] = { title: entry.title, type: source.singular, icon: source.icon, draft: false, missing: false, edit: source.kind === 'collection' ? `/dashboard/content/${source.name}/${entry.id}` : `/dashboard/terms/${source.name}/${entry.id}` };
|
|
192
|
+
}
|
|
193
|
+
if (this.rows.length + added.length > MENU_LIMITS.items) { this.message = ''; this.conflict = false; this.error = `${__('A menu holds at most')} ${MENU_LIMITS.items} ${__('items.')}`; return; }
|
|
194
|
+
this.targets = targets;
|
|
195
|
+
this.rows = [...this.rows, ...added];
|
|
196
|
+
this.selected = { ...this.selected, [source.name]: [] };
|
|
197
|
+
this.changed(`${added.length} ${added.length === 1 ? __('item added to the menu.') : __('items added to the menu.')}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@Client()
|
|
201
|
+
addLink(event: Event) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
const raw = this.link.url.trim();
|
|
204
|
+
const url = /^[a-z][a-z0-9+.-]*:|^[/#]/i.test(raw) ? raw : `https://${raw}`;
|
|
205
|
+
if (!raw || !safeLinkUrl(url)) { this.linkError = __('Enter a URL such as https://example.com, /about or #contact.'); return; }
|
|
206
|
+
if (!this.link.label.trim()) { this.linkError = __('Enter the link text.'); return; }
|
|
207
|
+
const id = menuItemId();
|
|
208
|
+
this.targets = { ...this.targets, [id]: { title: url, type: __('Custom link'), icon: 'link-round', draft: false, missing: false, edit: null } };
|
|
209
|
+
this.rows = [...this.rows, { id, kind: 'link', label: this.link.label.trim(), url, depth: 0 }];
|
|
210
|
+
this.link = { url: '', label: '' };
|
|
211
|
+
this.linkError = '';
|
|
212
|
+
this.changed(__('Link added to the menu.'));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** A heading: a label without a URL that names a column of links in a mega menu. */
|
|
216
|
+
@Client()
|
|
217
|
+
addHeading(event: Event) {
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
const label = this.heading.trim();
|
|
220
|
+
if (!label) { this.headingError = __('Enter the heading text.'); return; }
|
|
221
|
+
const id = menuItemId();
|
|
222
|
+
this.targets = { ...this.targets, [id]: { title: '', type: __('Heading'), icon: 'text-field', draft: false, missing: false, edit: null } };
|
|
223
|
+
this.rows = [...this.rows, { id, kind: 'heading', label, depth: 0 }];
|
|
224
|
+
this.heading = '';
|
|
225
|
+
this.headingError = '';
|
|
226
|
+
this.changed(__('Heading added to the menu.'));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@Server()
|
|
230
|
+
async findEntries(source: string, query: string) {
|
|
231
|
+
const cms = this.c.get('cms');
|
|
232
|
+
const principal = this.c.get('principal');
|
|
233
|
+
const entry = this.sources.find(item => item.name === source);
|
|
234
|
+
if (!entry) return;
|
|
235
|
+
let entries: SourceEntry[];
|
|
236
|
+
if (entry.kind === 'taxonomy') {
|
|
237
|
+
entries = query.trim() ? (await cms.taxonomies.list(source, { search: query, limit: 50 })).items.map(term => ({ id: term.id, title: term.name, depth: 0 }))
|
|
238
|
+
: (await cms.taxonomies.tree(source)).slice(0, 100).map(term => ({ id: term.id, title: term.name, depth: term.depth }));
|
|
239
|
+
} else {
|
|
240
|
+
const collection = cms.collection(source);
|
|
241
|
+
const where = collection.publishable === false ? {} : { where: { status: 'published' } };
|
|
242
|
+
const records = query.trim() ? openMatches(cms, `cms/${source}`, await cms.resource(`cms/${source}`).search(query.slice(0, 100), { limit: 30, ...where }, { principal }).catch(() => []), principal)
|
|
243
|
+
: (await cms.resource(`cms/${source}`).list({ ...where, limit: 30 }, { principal })).records;
|
|
244
|
+
entries = records.map(record => ({ id: record.id, title: recordTitle(record, 'title'), depth: 0 }));
|
|
245
|
+
}
|
|
246
|
+
this.sources = this.sources.map(item => item.name === source ? { ...item, entries } : item);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// --- Editing items -----------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
@Client()
|
|
252
|
+
changed(announcement: string) {
|
|
253
|
+
this.dirty = true;
|
|
254
|
+
this.announcement = announcement;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@Client()
|
|
258
|
+
toggle(id: string) {
|
|
259
|
+
this.editing = this.editing === id ? null : id;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@Client()
|
|
263
|
+
showTab(id: string, tab: ItemTab) {
|
|
264
|
+
this.tabs = { ...this.tabs, [id]: tab };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The attribute rows of an item: those typed, else the saved ones. */
|
|
268
|
+
private attributesOf(row: MenuRow): Attribute[] {
|
|
269
|
+
return this.attributes[row.id] ?? Object.entries(row.attributes ?? {}).map(([name, value]) => ({ name, value }));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Keep the typed rows and save the complete, valid ones into the item. */
|
|
273
|
+
@Client()
|
|
274
|
+
setAttributes(index: number, list: Attribute[]) {
|
|
275
|
+
const row = this.rows[index]!;
|
|
276
|
+
this.attributes = { ...this.attributes, [row.id]: list };
|
|
277
|
+
const attributes = Object.fromEntries(list.filter(entry => MENU_ATTRIBUTE.test(entry.name.trim())).map(entry => [entry.name.trim(), entry.value]));
|
|
278
|
+
this.setRow(index, Object.keys(attributes).length ? { attributes } : { attributes: undefined });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@Client()
|
|
282
|
+
setRow(index: number, patch: Partial<MenuRow>) {
|
|
283
|
+
this.rows = this.rows.map((row, position) => position === index ? { ...row, ...patch } : row);
|
|
284
|
+
this.dirty = true;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Remove an item; its children move up a level, as in WordPress. */
|
|
288
|
+
@Client()
|
|
289
|
+
removeRow(index: number) {
|
|
290
|
+
const row = this.rows[index];
|
|
291
|
+
if (!row) return;
|
|
292
|
+
const end = subtreeEnd(this.rows, index);
|
|
293
|
+
this.rows = [...this.rows.slice(0, index), ...this.rows.slice(index + 1, end).map(entry => ({ ...entry, depth: entry.depth - 1 })), ...this.rows.slice(end)];
|
|
294
|
+
if (this.editing === row.id) this.editing = null;
|
|
295
|
+
this.changed(`${this.labelOf(row)} ${__('removed.')}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
@Client()
|
|
299
|
+
shift(index: number, move: MenuMove) {
|
|
300
|
+
const row = this.rows[index];
|
|
301
|
+
const next = shiftRows(this.rows, index, move);
|
|
302
|
+
if (!row || next === this.rows) return;
|
|
303
|
+
this.rows = [...next];
|
|
304
|
+
this.changed(`${this.labelOf(row)}: ${this.position(row.id)}`);
|
|
305
|
+
requestAnimationFrame(() => this.handles.get(row.id)?.focus());
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
labelOf(row: MenuRow): string {
|
|
309
|
+
return row.label || this.targets[row.id]?.title || __('Item');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Where an item now sits, for screen readers: its parent and its place among siblings. */
|
|
313
|
+
position(id: string): string {
|
|
314
|
+
const index = this.rows.findIndex(row => row.id === id);
|
|
315
|
+
const row = this.rows[index]!;
|
|
316
|
+
let parent = index - 1;
|
|
317
|
+
while (parent >= 0 && this.rows[parent]!.depth >= row.depth) parent--;
|
|
318
|
+
const siblings = this.rows.filter((entry, position) => entry.depth === row.depth && position > parent && (parent < 0 || position < subtreeEnd(this.rows, parent)));
|
|
319
|
+
const place = `${__('item')} ${siblings.findIndex(entry => entry.id === id) + 1} ${__('of')} ${siblings.length}`;
|
|
320
|
+
return parent >= 0 ? `${place} ${__('under')} ${this.labelOf(this.rows[parent]!)}` : `${place} ${__('at the top level')}`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// --- Dragging ----------------------------------------------------------------
|
|
324
|
+
|
|
325
|
+
@Client()
|
|
326
|
+
rowRef(id: string, element: Element | undefined) {
|
|
327
|
+
if (element) this.rowElements.set(id, element as HTMLElement); else this.rowElements.delete(id);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
@Client()
|
|
331
|
+
handleRef(id: string, element: Element | undefined) {
|
|
332
|
+
if (element) this.handles.set(id, element as HTMLElement); else this.handles.delete(id);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
@Client()
|
|
336
|
+
listRef(element: Element | undefined) {
|
|
337
|
+
this.list = element as HTMLElement | undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
@Client()
|
|
341
|
+
startDrag(event: PointerEvent, index: number) {
|
|
342
|
+
if (event.button !== 0 || !this.list) return;
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
345
|
+
const top = this.list.getBoundingClientRect().top;
|
|
346
|
+
const rects = this.rows.map(row => this.rowElements.get(row.id)?.getBoundingClientRect());
|
|
347
|
+
this.pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, depth: this.rows[index]!.depth,
|
|
348
|
+
tops: rects.map(rect => (rect?.top ?? 0) - top), bottoms: rects.map(rect => (rect?.bottom ?? 0) - top) };
|
|
349
|
+
this.drag = { from: index, to: index, depth: this.rows[index]!.depth, valid: false, y: 0, moved: false };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@Client()
|
|
353
|
+
moveDrag(event: PointerEvent) {
|
|
354
|
+
const pointer = this.pointer;
|
|
355
|
+
const drag = this.drag;
|
|
356
|
+
if (!pointer || !drag || event.pointerId !== pointer.id || !this.list) return;
|
|
357
|
+
if (!drag.moved && Math.abs(event.clientY - pointer.y) < 4 && Math.abs(event.clientX - pointer.x) < 4) return;
|
|
358
|
+
const y = event.clientY - this.list.getBoundingClientRect().top;
|
|
359
|
+
const end = subtreeEnd(this.rows, drag.from);
|
|
360
|
+
const rest = this.rows.map((_, index) => index).filter(index => index < drag.from || index >= end);
|
|
361
|
+
let to = 0;
|
|
362
|
+
while (to < rest.length && (pointer.tops[rest[to]!]! + pointer.bottoms[rest[to]!]!) / 2 < y) to++;
|
|
363
|
+
const { min, max } = dropDepths(this.rows, drag.from, to);
|
|
364
|
+
const depth = Math.min(Math.max(pointer.depth + Math.round((event.clientX - pointer.x) / INDENT), min), Math.max(max, min));
|
|
365
|
+
const line = to < rest.length ? pointer.tops[rest[to]!]! : pointer.bottoms[rest.at(-1) ?? 0] ?? 0;
|
|
366
|
+
if (drag.to !== to || drag.depth !== depth || !drag.moved) this.drag = { ...drag, to, depth, valid: max >= min, y: line - 2, moved: true };
|
|
367
|
+
// Scroll while dragging near the window's edges.
|
|
368
|
+
if (event.clientY < 60) window.scrollBy(0, -12);
|
|
369
|
+
else if (event.clientY > window.innerHeight - 60) window.scrollBy(0, 12);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@Client()
|
|
373
|
+
endDrag(event: PointerEvent) {
|
|
374
|
+
const drag = this.drag;
|
|
375
|
+
if (!this.pointer || event.pointerId !== this.pointer.id) return;
|
|
376
|
+
this.pointer = null;
|
|
377
|
+
this.drag = null;
|
|
378
|
+
if (!drag?.moved || !drag.valid) return;
|
|
379
|
+
const row = this.rows[drag.from]!;
|
|
380
|
+
const next = moveRows(this.rows, drag.from, drag.to, drag.depth);
|
|
381
|
+
if (next.every((entry, index) => entry.id === this.rows[index]?.id && entry.depth === this.rows[index]?.depth)) return;
|
|
382
|
+
this.rows = next;
|
|
383
|
+
this.changed(`${this.labelOf(row)}: ${this.position(row.id)}`);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
@Client()
|
|
387
|
+
cancelDrag() {
|
|
388
|
+
this.pointer = null;
|
|
389
|
+
this.drag = null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@Client()
|
|
393
|
+
handleKey(event: KeyboardEvent, index: number) {
|
|
394
|
+
const moves: Record<string, MenuMove> = { ArrowUp: 'up', ArrowDown: 'down', ArrowRight: 'in', ArrowLeft: 'out' };
|
|
395
|
+
if (event.key === 'Escape' && this.drag) { this.cancelDrag(); return; }
|
|
396
|
+
const move = moves[event.key];
|
|
397
|
+
if (!move) return;
|
|
398
|
+
event.preventDefault();
|
|
399
|
+
this.shift(index, move);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// --- Saving ------------------------------------------------------------------
|
|
403
|
+
|
|
404
|
+
@Client()
|
|
405
|
+
async submit(event: Event) {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
this.saving = true;
|
|
408
|
+
this.message = '';
|
|
409
|
+
try { await this.save(this.name, this.rows, this.revision, this.locations.filter(location => location.checked).map(location => location.name)); }
|
|
410
|
+
finally { this.saving = false; }
|
|
411
|
+
if (!this.error) { this.dirty = false; this.message = __('Menu saved.'); }
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
@Server()
|
|
415
|
+
async save(name: string, rows: MenuRow[], revision: number, locations: string[]) {
|
|
416
|
+
const cms = this.c.get('cms');
|
|
417
|
+
const principal = this.c.get('principal');
|
|
418
|
+
this.error = '';
|
|
419
|
+
this.conflict = false;
|
|
420
|
+
try {
|
|
421
|
+
// Menu item fields as the host has them, not as the client's state lists them.
|
|
422
|
+
this.fieldGroups = await groupsView(cms, { kind: 'menus' });
|
|
423
|
+
const typed: MenuRow[] = [];
|
|
424
|
+
for (const row of rows) {
|
|
425
|
+
const { meta, errors } = metaInput(this.fieldGroups.fields, (row.meta ?? {}) as Record<string, unknown>);
|
|
426
|
+
const first = Object.entries(errors)[0];
|
|
427
|
+
if (first) { this.error = `${row.label || row.kind}: ${first[0]} ${first[1]}`; return; }
|
|
428
|
+
typed.push({ ...row, ...(Object.keys(meta).length ? { meta } : { meta: undefined }) });
|
|
429
|
+
}
|
|
430
|
+
const menu = await cms.menus.update(this.c.req.param('id') ?? '', { name, items: buildMenu(typed) }, { principal, expectedRevision: revision });
|
|
431
|
+
await cms.menus.place(menu.id, locations, { principal, known: (await cms.menuLocations()).map(location => location.name) });
|
|
432
|
+
this.name = menu.name;
|
|
433
|
+
this.revision = menu.revision;
|
|
434
|
+
this.rows = this.withMetaValues(flattenMenu(menu.items));
|
|
435
|
+
this.targets = await describe(cms, this.rows, principal);
|
|
436
|
+
} catch (error) {
|
|
437
|
+
this.conflict = isCmsError(error, 'CMS_CONFLICT') && !(isCmsError(error) && error.fields?.name);
|
|
438
|
+
this.error = isCmsError(error) ? error.message : __('The menu could not be saved.');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
@Server()
|
|
443
|
+
async deleteMenu() {
|
|
444
|
+
this.error = '';
|
|
445
|
+
this.message = '';
|
|
446
|
+
try {
|
|
447
|
+
await this.c.get('cms').menus.delete(this.c.req.param('id') ?? '', { principal: this.c.get('principal') });
|
|
448
|
+
return this.redirect('/dashboard/appearance/menus');
|
|
449
|
+
} catch (error) { this.error = isCmsError(error) ? error.message : __('The menu could not be deleted.'); }
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// --- Rendering ---------------------------------------------------------------
|
|
453
|
+
|
|
454
|
+
private sourceBox(source: Source): TemplateResult {
|
|
455
|
+
const selected = this.selected[source.name] ?? [];
|
|
456
|
+
const option = (value: string, label: string, depth = 0) => html`<div class="py-0.5" style=${`padding-left: ${depth * 1.25}rem`}>
|
|
457
|
+
${component(Checkbox, { label, checked: selected.includes(value), '@change': (event: Event) => this.toggleSelected(source.name, value, (event.target as HTMLInputElement).checked) })}</div>`;
|
|
458
|
+
return html`<details class="rounded-lg border border-border bg-card" ?open=${source.name === this.sources[0]?.name}>
|
|
459
|
+
<summary class="flex cursor-pointer select-none items-center gap-2 px-4 py-2.5 text-sm font-semibold text-foreground"><span class="inline-flex text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: icon(source.icon), size: 16 })}</span>${source.label}</summary>
|
|
460
|
+
<div class="space-y-3 border-t border-border p-4">
|
|
461
|
+
<input type="search" class=${CONTROL} placeholder=${`${__('Search')} ${source.label.toLowerCase()}`} aria-label=${`${__('Search')} ${source.label.toLowerCase()}`}
|
|
462
|
+
@change=${(event: Event) => this.findEntries(source.name, (event.target as HTMLInputElement).value)}>
|
|
463
|
+
<div class="max-h-56 overflow-y-auto">
|
|
464
|
+
${source.archive ? option('__archive', `${__('All')} ${source.label.toLowerCase()} (${__('archive')})`) : null}
|
|
465
|
+
${source.entries.length ? source.entries.map(entry => option(entry.id, entry.title, entry.depth)) : html`<p class="text-xs text-muted-foreground">${__('Nothing found.')}</p>`}
|
|
466
|
+
</div>
|
|
467
|
+
${component(Button, { type: 'button', size: 'sm', variant: 'outline', disabled: !selected.length, '@click': () => this.addSelected(source) }, __('Add to menu'))}
|
|
468
|
+
</div>
|
|
469
|
+
</details>`;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private linkBox(): TemplateResult {
|
|
473
|
+
return html`<details class="rounded-lg border border-border bg-card">
|
|
474
|
+
<summary class="flex cursor-pointer select-none items-center gap-2 px-4 py-2.5 text-sm font-semibold text-foreground"><span class="inline-flex text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: icon('link-round'), size: 16 })}</span>${__('Custom links')}</summary>
|
|
475
|
+
<form class="space-y-3 border-t border-border p-4" @submit=${(event: Event) => this.addLink(event)}>
|
|
476
|
+
<div class="space-y-1"><label for="link-url" class="block text-xs font-medium text-foreground">${__('URL')}</label>
|
|
477
|
+
<input id="link-url" type="text" inputmode="url" class=${CONTROL} placeholder="https://" .value=${this.link.url} @input=${(event: Event) => { this.link = { ...this.link, url: (event.target as HTMLInputElement).value }; }}></div>
|
|
478
|
+
<div class="space-y-1"><label for="link-label" class="block text-xs font-medium text-foreground">${__('Link text')}</label>
|
|
479
|
+
<input id="link-label" type="text" class=${CONTROL} .value=${this.link.label} @input=${(event: Event) => { this.link = { ...this.link, label: (event.target as HTMLInputElement).value }; }}></div>
|
|
480
|
+
${this.linkError ? html`<p role="alert" class="text-xs text-destructive">${this.linkError}</p>` : null}
|
|
481
|
+
${component(Button, { type: 'submit', size: 'sm', variant: 'outline' }, __('Add to menu'))}
|
|
482
|
+
</form>
|
|
483
|
+
</details>`;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
private headingBox(): TemplateResult {
|
|
487
|
+
return html`<details class="rounded-lg border border-border bg-card">
|
|
488
|
+
<summary class="flex cursor-pointer select-none items-center gap-2 px-4 py-2.5 text-sm font-semibold text-foreground"><span class="inline-flex text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: icon('text-field'), size: 16 })}</span>${__('Headings')}</summary>
|
|
489
|
+
<form class="space-y-3 border-t border-border p-4" @submit=${(event: Event) => this.addHeading(event)}>
|
|
490
|
+
<div class="space-y-1"><label for="heading-text" class="block text-xs font-medium text-foreground">${__('Heading text')}</label>
|
|
491
|
+
<input id="heading-text" type="text" class=${CONTROL} maxlength=${MENU_LIMITS.label} .value=${this.heading} @input=${(event: Event) => { this.heading = (event.target as HTMLInputElement).value; }}></div>
|
|
492
|
+
<p class="text-xs text-muted-foreground">${__('Not a link: it names a column of links in a mega menu. Nest the links under it.')}</p>
|
|
493
|
+
${this.headingError ? html`<p role="alert" class="text-xs text-destructive">${this.headingError}</p>` : null}
|
|
494
|
+
${component(Button, { type: 'submit', size: 'sm', variant: 'outline' }, __('Add to menu'))}
|
|
495
|
+
</form>
|
|
496
|
+
</details>`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The General tab's panel select: a synced pattern shown beside the item's links, which makes the item a mega menu. */
|
|
500
|
+
private panelControl(row: MenuRow, index: number): TemplateResult {
|
|
501
|
+
const missing = Boolean(row.panel) && !this.patterns.some(pattern => pattern.id === row.panel);
|
|
502
|
+
return html`<div class="space-y-1"><label for=${`panel-${row.id}`} class="block text-xs font-medium text-foreground">${__('Mega menu panel')}</label>
|
|
503
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
504
|
+
<select id=${`panel-${row.id}`} class=${`${CONTROL} max-w-xs`} @change=${(event: Event) => this.setRow(index, { panel: (event.target as HTMLSelectElement).value || undefined })}>
|
|
505
|
+
<option value="" ?selected=${!row.panel}>${__('None')}</option>
|
|
506
|
+
${this.patterns.map(pattern => html`<option value=${pattern.id} ?selected=${pattern.id === row.panel}>${pattern.title}</option>`)}
|
|
507
|
+
${missing ? html`<option value=${row.panel ?? ''} selected>${__('Missing pattern')}</option>` : null}
|
|
508
|
+
</select>
|
|
509
|
+
${row.panel && !missing ? html`<a href=${`/dashboard/content/patterns/${row.panel}`} class="text-xs text-primary hover:underline" target="_blank" rel="noopener">${__('Edit pattern')}</a>`
|
|
510
|
+
: html`<a href="/dashboard/content/patterns/new" class="text-xs text-primary hover:underline" target="_blank" rel="noopener">${__('New pattern')}</a>`}
|
|
511
|
+
</div>
|
|
512
|
+
<p class="text-xs text-muted-foreground">${__('A synced pattern shown beside this item’s links: a card, a call to action, latest posts. An item with a panel or a heading under it opens as a mega menu.')}</p>
|
|
513
|
+
</div>`;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** The Advanced tab: class names for the theme's stylesheet and extra attributes on the link. */
|
|
517
|
+
/** Rows with their meta as control values, for the Fields tab. */
|
|
518
|
+
private withMetaValues(rows: readonly MenuRow[]): MenuRow[] {
|
|
519
|
+
return rows.map(row => ({ ...row, meta: metaValues(this.fieldGroups.fields, row.meta) }));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** The Fields tab: the field groups attached to menu items, with this item's values. */
|
|
523
|
+
private fieldsTab(row: MenuRow, index: number): TemplateResult {
|
|
524
|
+
const { groups, fields, options } = this.fieldGroups;
|
|
525
|
+
const values = (row.meta ?? {}) as Record<string, unknown>;
|
|
526
|
+
const blocks = groups.flatMap(group => group.blocks);
|
|
527
|
+
const hidden = fieldVisibility(plainBlocks(blocks), visibilityTypes(options), values).hidden;
|
|
528
|
+
return html`<div class="space-y-4">${groups.map(group => html`<section class="space-y-3" aria-label=${group.title}>
|
|
529
|
+
<h3 class="text-xs font-medium text-foreground">${group.title}</h3>
|
|
530
|
+
${group.description ? html`<p class="text-xs text-muted-foreground">${group.description}</p>` : null}
|
|
531
|
+
${component(FieldGroupView, {
|
|
532
|
+
id: `item-${row.id}-${group.id}`, blocks: group.blocks, options, fields, values, hidden,
|
|
533
|
+
onChange: (name: string, value: unknown) => this.setRow(index, { meta: { ...values, [name]: value } }),
|
|
534
|
+
control: (field: EditorField, value: unknown, change: (value: unknown) => void, _rows: RowPath, id: string) => fieldControl(field, value, change, id),
|
|
535
|
+
})}
|
|
536
|
+
</section>`)}</div>`;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
private advanced(row: MenuRow, index: number): TemplateResult {
|
|
540
|
+
const attributes = this.attributesOf(row);
|
|
541
|
+
const set = (position: number, patch: Partial<Attribute>) => this.setAttributes(index, attributes.map((entry, at) => at === position ? { ...entry, ...patch } : entry));
|
|
542
|
+
return html`<div class="space-y-3">
|
|
543
|
+
<div class="space-y-1"><label for=${`class-${row.id}`} class="block text-xs font-medium text-foreground">${__('CSS classes')}</label>
|
|
544
|
+
<input id=${`class-${row.id}`} class=${CONTROL} maxlength=${MENU_LIMITS.className} .value=${row.className ?? ''} placeholder="featured highlight"
|
|
545
|
+
@input=${(event: Event) => this.setRow(index, { className: (event.target as HTMLInputElement).value })}>
|
|
546
|
+
<p class="text-xs text-muted-foreground">${__("Added to the link, for the theme's stylesheet.")}</p></div>
|
|
547
|
+
<fieldset class="space-y-2">
|
|
548
|
+
<legend class="text-xs font-medium text-foreground">${__('Custom attributes')}</legend>
|
|
549
|
+
${attributes.map((entry, position) => html`<div class="flex items-center gap-2">
|
|
550
|
+
<input class=${`${CONTROL} font-mono text-xs`} aria-label=${__('Attribute name')} placeholder="data-track" .value=${entry.name} aria-invalid=${entry.name.trim() !== '' && !MENU_ATTRIBUTE.test(entry.name.trim()) ? 'true' : 'false'}
|
|
551
|
+
@input=${(event: Event) => set(position, { name: (event.target as HTMLInputElement).value })}>
|
|
552
|
+
<input class=${`${CONTROL} text-xs`} aria-label=${__('Attribute value')} placeholder=${__('value')} maxlength=${MENU_LIMITS.attributeValue} .value=${entry.value}
|
|
553
|
+
@input=${(event: Event) => set(position, { value: (event.target as HTMLInputElement).value })}>
|
|
554
|
+
${iconButton(`attr-${row.id}-${position}`, 'trash-bin-trash', __('Remove attribute'), () => this.setAttributes(index, attributes.filter((_, at) => at !== position)), { danger: true })}
|
|
555
|
+
</div>`)}
|
|
556
|
+
${attributes.length < MENU_LIMITS.attributes ? component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.setAttributes(index, [...attributes, { name: '', value: '' }]) }, __('Add attribute')) : null}
|
|
557
|
+
<p class="text-xs text-muted-foreground">${__('Lowercase names such as data-track or rel; href, class, target and event handlers cannot be set.')}</p>
|
|
558
|
+
</fieldset>
|
|
559
|
+
</div>`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
private row(row: MenuRow, index: number): TemplateResult {
|
|
563
|
+
const target = this.targets[row.id];
|
|
564
|
+
const open = this.editing === row.id;
|
|
565
|
+
const drag = this.drag;
|
|
566
|
+
const dragging = drag?.moved && index >= drag.from && index < subtreeEnd(this.rows, drag.from);
|
|
567
|
+
const label = this.labelOf(row);
|
|
568
|
+
return html`<li class=${`transition-opacity ${dragging ? 'opacity-40' : ''}`} style=${`margin-left: ${row.depth * INDENT}px`} data-menu-item=${row.id} data-depth=${row.depth}
|
|
569
|
+
ref=${(element: Element) => this.rowRef(row.id, element)}>
|
|
570
|
+
<div class=${`flex items-center gap-2 rounded-md border bg-card px-2 py-2 ${target?.missing ? 'border-destructive/60' : 'border-border'}`}>
|
|
571
|
+
<button type="button" class="flex h-8 w-6 shrink-0 cursor-grab touch-none items-center justify-center rounded text-muted-foreground hover:bg-muted active:cursor-grabbing border-none bg-transparent"
|
|
572
|
+
aria-label=${`${__('Move')} ${label}. ${__('Drag, or use the arrow keys.')}`} aria-describedby="menu-help" data-handle
|
|
573
|
+
ref=${(element: Element) => this.handleRef(row.id, element)}
|
|
574
|
+
@pointerdown=${(event: PointerEvent) => this.startDrag(event, index)} @pointermove=${(event: PointerEvent) => this.moveDrag(event)}
|
|
575
|
+
@pointerup=${(event: PointerEvent) => this.endDrag(event)} @pointercancel=${() => this.cancelDrag()} @lostpointercapture=${() => this.cancelDrag()}
|
|
576
|
+
@keydown=${(event: KeyboardEvent) => this.handleKey(event, index)}>
|
|
577
|
+
<svg aria-hidden="true" viewBox="0 0 10 16" class="h-4 w-2.5 fill-current"><circle cx="2" cy="2" r="1.5"/><circle cx="8" cy="2" r="1.5"/><circle cx="2" cy="8" r="1.5"/><circle cx="8" cy="8" r="1.5"/><circle cx="2" cy="14" r="1.5"/><circle cx="8" cy="14" r="1.5"/></svg>
|
|
578
|
+
</button>
|
|
579
|
+
<span class="inline-flex shrink-0 text-muted-foreground [&_svg]:size-4" title=${target?.type ?? ''}>${component(Icon, { entry: icon(target?.icon, 'document-text'), size: 16 })}</span>
|
|
580
|
+
<span class="min-w-0 flex-1 truncate text-sm font-medium text-foreground">${label}</span>
|
|
581
|
+
<span class="hidden shrink-0 text-xs text-muted-foreground sm:inline">${target?.type ?? ''}${target?.draft ? ` · ${__('Draft')}` : ''}${target?.missing ? ` · ${__('Missing')}` : ''}</span>
|
|
582
|
+
${iconButton(`item-${row.id}-toggle`, 'pen', `${__('Edit')} ${label}`, () => this.toggle(row.id), { class: 'shrink-0 border-transparent bg-transparent', pressed: open })}
|
|
583
|
+
</div>
|
|
584
|
+
</li>`;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The item being edited, in a sheet at the side of the screen as a block is: its tabs, then
|
|
589
|
+
* its moves and Remove. Changes apply to the menu at once; Save menu keeps them.
|
|
590
|
+
*/
|
|
591
|
+
private itemSheet(): TemplateResult {
|
|
592
|
+
const index = this.editing ? this.rows.findIndex(entry => entry.id === this.editing) : -1;
|
|
593
|
+
const row = index >= 0 ? this.rows[index]! : null;
|
|
594
|
+
const close = () => { this.editing = null; };
|
|
595
|
+
if (!row) return component(Sheet, { id: 'menu-item-sheet', open: false, side: 'right', size: '30rem', 'aria-label': __('Menu item'), onOpenChange: () => close() }, html``);
|
|
596
|
+
const target = this.targets[row.id];
|
|
597
|
+
const tab = this.tabs[row.id] ?? 'general';
|
|
598
|
+
const moves = allowedMoves(this.rows, index);
|
|
599
|
+
const label = this.labelOf(row);
|
|
600
|
+
return component(Sheet, { id: 'menu-item-sheet', open: true, side: 'right', size: '30rem', 'aria-label': `${__('Edit')} ${label.trim() || __('Menu item')}`, onOpenChange: (open: boolean) => { if (!open) close(); } },
|
|
601
|
+
html`<form id=${`item-${row.id}`} class="flex h-full flex-col" @submit=${(event: Event) => { event.preventDefault(); close(); }}>
|
|
602
|
+
<header class="flex items-start gap-3 border-b border-border px-5 py-4">
|
|
603
|
+
<span class="mt-0.5 inline-flex shrink-0 text-muted-foreground [&_svg]:size-5">${component(Icon, { entry: icon(target?.icon, 'document-text'), size: 20 })}</span>
|
|
604
|
+
<div class="min-w-0 flex-1">
|
|
605
|
+
<h2 class="truncate text-base font-semibold text-foreground">${label.trim() || __('Menu item')}</h2>
|
|
606
|
+
<p class="text-xs text-muted-foreground">${target?.type ?? ''}${target?.draft ? ` · ${__('Draft')}` : ''}${target?.missing ? ` · ${__('Missing')}` : ''}</p>
|
|
607
|
+
</div>
|
|
608
|
+
<button type="button" class="inline-flex size-8 shrink-0 items-center justify-center rounded-md border-none bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground cursor-pointer" aria-label=${__('Close')} @click=${close}>✕</button>
|
|
609
|
+
</header>
|
|
610
|
+
<div class="min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4">
|
|
611
|
+
${component(Tabs, {
|
|
612
|
+
id: `menu-item-${row.id}`, label: label.trim() || __('Menu item'), value: tab, variant: 'underline',
|
|
613
|
+
onValueChange: (value: string) => this.showTab(row.id, value as ItemTab),
|
|
614
|
+
items: [
|
|
615
|
+
{ value: 'general', label: __('Navigation label'), content: html`<div class="space-y-3">
|
|
616
|
+
<div class="grid gap-3">
|
|
617
|
+
<div class="space-y-1"><label for=${`label-${row.id}`} class="block text-xs font-medium text-foreground">${__('Navigation label')}</label>
|
|
618
|
+
<input id=${`label-${row.id}`} class=${CONTROL} maxlength=${MENU_LIMITS.label} .value=${row.label} placeholder=${target?.title ?? ''}
|
|
619
|
+
@input=${(event: Event) => this.setRow(index, { label: (event.target as HTMLInputElement).value })}></div>
|
|
620
|
+
${row.kind === 'link' ? html`<div class="space-y-1"><label for=${`url-${row.id}`} class="block text-xs font-medium text-foreground">${__('URL')}</label>
|
|
621
|
+
<input id=${`url-${row.id}`} class=${CONTROL} .value=${row.url ?? ''} @input=${(event: Event) => this.setRow(index, { url: (event.target as HTMLInputElement).value.trim() })}></div>` : null}
|
|
622
|
+
</div>
|
|
623
|
+
<div class="space-y-1"><label for=${`description-${row.id}`} class="block text-xs font-medium text-foreground">${__('Description')}</label>
|
|
624
|
+
<input id=${`description-${row.id}`} class=${CONTROL} maxlength=${MENU_LIMITS.description} .value=${row.description ?? ''} placeholder=${__('Shown under the link in a mega menu')}
|
|
625
|
+
@input=${(event: Event) => this.setRow(index, { description: (event.target as HTMLInputElement).value })}></div>
|
|
626
|
+
${row.kind === 'heading' ? null : html`<div>${component(Checkbox, { label: __('Open link in a new tab'), checked: row.newTab === true, '@change': (event: Event) => this.setRow(index, { newTab: (event.target as HTMLInputElement).checked })})}</div>`}
|
|
627
|
+
${row.kind !== 'link' && row.kind !== 'heading' && target ? html`<p class="text-xs text-muted-foreground">${__('Original')}: ${target.edit ? html`<a href=${target.edit} class="text-primary hover:underline">${target.title}</a>` : target.title}</p>` : null}
|
|
628
|
+
${this.panelControl(row, index)}
|
|
629
|
+
</div>` },
|
|
630
|
+
...(this.fieldGroups.groups.length ? [{ value: 'fields', label: __('Fields'), content: this.fieldsTab(row, index) }] : []),
|
|
631
|
+
{ value: 'advanced', label: __('Advanced'), content: this.advanced(row, index) },
|
|
632
|
+
],
|
|
633
|
+
})}
|
|
634
|
+
</div>
|
|
635
|
+
<footer class="flex flex-wrap items-center gap-1 border-t border-border px-5 py-3">
|
|
636
|
+
${(['up', 'down', 'out', 'in'] as const).map(move => iconButton(`item-${row.id}-move-${move}`, MOVE_ICONS[move], __(MOVE_LABELS[move]), () => this.shift(index, move), { disabled: !moves.has(move) }))}
|
|
637
|
+
${iconButton(`item-${row.id}-remove`, 'trash-bin-trash', `${__('Remove')} ${label}`, () => this.removeRow(index), { danger: true, class: 'ml-1' })}
|
|
638
|
+
<span class="ml-auto">${component(Button, { type: 'submit' }, __('Done'))}</span>
|
|
639
|
+
</footer>
|
|
640
|
+
</form>`);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
render() {
|
|
644
|
+
if (!this.id) return html`<div class="space-y-4">${notice(this.error || __('This menu does not exist.'), 'error')}${linkButton(__('All menus'), '/dashboard/appearance/menus', 'outline')}</div>`;
|
|
645
|
+
const drag = this.drag;
|
|
646
|
+
return html`<div class="space-y-6">
|
|
647
|
+
${pageHeader(__('Edit menu'), { actions: html`<a href="/dashboard/appearance/menus" class="text-sm text-muted-foreground hover:text-foreground">← ${__('All menus')}</a>` })}
|
|
648
|
+
${this.message ? notice(this.message, 'success') : null}
|
|
649
|
+
${this.error ? html`<div class="space-y-2">${notice(this.error, 'error')}${this.conflict ? html`<a href=${`/dashboard/appearance/menus/${this.id}`} class="text-sm text-primary hover:underline">${__('Reload the menu')}</a>` : null}</div>` : null}
|
|
650
|
+
<div class="grid gap-6 lg:grid-cols-[20rem_minmax(0,1fr)]">
|
|
651
|
+
<aside class="space-y-3" aria-label=${__('Add menu items')}>
|
|
652
|
+
<h2 class="text-sm font-semibold text-foreground">${__('Add menu items')}</h2>
|
|
653
|
+
${this.sources.map(source => this.sourceBox(source))}
|
|
654
|
+
${this.linkBox()}
|
|
655
|
+
${this.headingBox()}
|
|
656
|
+
</aside>
|
|
657
|
+
<form class="min-w-0" @submit=${(event: Event) => this.submit(event)}>
|
|
658
|
+
${component(Card, {}, component(CardBody, { class: 'space-y-5' }, html`
|
|
659
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
660
|
+
<div class="min-w-48 flex-1 space-y-1"><label for="menu-name" class="block text-sm font-medium text-foreground">${__('Menu name')}</label>
|
|
661
|
+
${component(Input, { id: 'menu-name', '.value': this.name, maxlength: MENU_LIMITS.name, '@input': (event: Event) => { this.name = (event.target as HTMLInputElement).value; this.dirty = true; } })}</div>
|
|
662
|
+
${component(Button, { type: 'submit', disabled: this.saving || !this.name.trim() }, this.saving ? __('Saving…') : __('Save menu'))}
|
|
663
|
+
</div>
|
|
664
|
+
<div class="space-y-2">
|
|
665
|
+
<h2 class="text-sm font-semibold text-foreground">${__('Menu structure')}</h2>
|
|
666
|
+
<p id="menu-help" class="text-xs text-muted-foreground">${__('Drag the handles to reorder; drag right to nest an item under the one above. On a handle, the arrow keys move the item.')}</p>
|
|
667
|
+
${this.rows.length ? html`<div class="relative" ref=${(element: Element) => this.listRef(element)}>
|
|
668
|
+
<ol class="space-y-1.5" aria-label=${__('Menu structure')}>${repeat(this.rows, row => row.id, (row, index) => this.row(row, index))}</ol>
|
|
669
|
+
${drag?.moved ? html`<div aria-hidden="true" class=${`pointer-events-none absolute right-0 h-1 rounded-full ${drag.valid ? 'bg-primary' : 'bg-destructive'}`}
|
|
670
|
+
style=${`top: ${drag.y}px; left: ${drag.depth * INDENT}px`}></div>` : null}
|
|
671
|
+
</div>` : html`<p class="rounded-md border border-dashed border-border p-6 text-center text-sm text-muted-foreground">${__('Add items from the column on the left.')}</p>`}
|
|
672
|
+
<p class="sr-only" aria-live="polite">${this.announcement}</p>
|
|
673
|
+
</div>
|
|
674
|
+
${box(__('Display location'), this.locations.length ? html`<div class="space-y-1.5">${this.locations.map((location, index) => html`<label class="flex items-center gap-2 text-sm text-foreground cursor-pointer">
|
|
675
|
+
${component(Checkbox, { checked: location.checked, '@change': (event: Event) => { this.locations = this.locations.map((entry, position) => position === index ? { ...entry, checked: (event.target as HTMLInputElement).checked } : entry); this.dirty = true; } })}
|
|
676
|
+
${location.label}${location.active ? null : html`<span class="text-xs text-muted-foreground">(${location.theme})</span>`}</label>`)}</div>`
|
|
677
|
+
: html`<p class="text-sm text-muted-foreground">${__('The active theme has no menu locations.')}</p>`)}
|
|
678
|
+
<div class="flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
|
|
679
|
+
<button type="button" class="text-sm text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => { this.confirmDelete = true; }}>${__('Delete menu')}</button>
|
|
680
|
+
<span class="flex items-center gap-3">
|
|
681
|
+
${this.dirty ? html`<span class="text-xs text-muted-foreground">${__('Unsaved changes')}</span>` : null}
|
|
682
|
+
${component(Button, { type: 'submit', disabled: this.saving || !this.name.trim() }, this.saving ? __('Saving…') : __('Save menu'))}
|
|
683
|
+
</span>
|
|
684
|
+
</div>`))}
|
|
685
|
+
</form>
|
|
686
|
+
</div>
|
|
687
|
+
${component(AlertDialog, {
|
|
688
|
+
id: 'delete-menu-dialog', open: this.confirmDelete, title: __('Delete menu?'),
|
|
689
|
+
description: `“${this.name}” ${__('and its items are deleted. Locations that showed it fall back to the theme default.')}`,
|
|
690
|
+
cancelLabel: __('Cancel'), actionLabel: __('Delete'), actionVariant: 'destructive',
|
|
691
|
+
onAction: () => { this.confirmDelete = false; void this.deleteMenu(); },
|
|
692
|
+
onOpenChange: () => { this.confirmDelete = false; },
|
|
693
|
+
})}
|
|
694
|
+
${this.itemSheet()}
|
|
695
|
+
</div>`;
|
|
696
|
+
}
|
|
697
|
+
}
|