@cossackframework/cms 0.0.0-stage → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +18 -0
  10. package/app/src/auth-providers.ts +16 -0
  11. package/app/src/auth.ts +1082 -0
  12. package/app/src/brand.ts +68 -0
  13. package/app/src/cms/ai.ts +54 -0
  14. package/app/src/cms/analytics.ts +33 -0
  15. package/app/src/cms/block-errors.ts +55 -0
  16. package/app/src/cms/block-inserter.ts +111 -0
  17. package/app/src/cms/block-panel.ts +68 -0
  18. package/app/src/cms/block-rows.ts +44 -0
  19. package/app/src/cms/block-tree.ts +585 -0
  20. package/app/src/cms/blocks.css +708 -0
  21. package/app/src/cms/builder.ts +126 -0
  22. package/app/src/cms/cache.ts +44 -0
  23. package/app/src/cms/carousel.client.ts +52 -0
  24. package/app/src/cms/collab/presence.ts +69 -0
  25. package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
  26. package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
  27. package/app/src/cms/collab/room.ts +881 -0
  28. package/app/src/cms/compare.client.ts +47 -0
  29. package/app/src/cms/condition-control.ts +109 -0
  30. package/app/src/cms/content-api.ts +143 -0
  31. package/app/src/cms/content.ts +524 -0
  32. package/app/src/cms/countdown.client.ts +37 -0
  33. package/app/src/cms/editor-layout-editor.ts +260 -0
  34. package/app/src/cms/editor-layout-view.ts +37 -0
  35. package/app/src/cms/editor.ts +381 -0
  36. package/app/src/cms/entry.ts +26 -0
  37. package/app/src/cms/feeds.ts +145 -0
  38. package/app/src/cms/field-controls.ts +222 -0
  39. package/app/src/cms/field-group-editor.ts +105 -0
  40. package/app/src/cms/field-group-view.ts +211 -0
  41. package/app/src/cms/form-view.ts +203 -0
  42. package/app/src/cms/form.client.ts +203 -0
  43. package/app/src/cms/guards.ts +27 -0
  44. package/app/src/cms/handoff.ts +202 -0
  45. package/app/src/cms/headings.ts +51 -0
  46. package/app/src/cms/icons.ts +80 -0
  47. package/app/src/cms/import.client.ts +16 -0
  48. package/app/src/cms/index.ts +191 -0
  49. package/app/src/cms/lightbox.client.ts +109 -0
  50. package/app/src/cms/machine.ts +118 -0
  51. package/app/src/cms/maintenance.ts +97 -0
  52. package/app/src/cms/manage.ts +1236 -0
  53. package/app/src/cms/mcp-tools.ts +388 -0
  54. package/app/src/cms/mcp.ts +242 -0
  55. package/app/src/cms/media-chooser.ts +123 -0
  56. package/app/src/cms/media-usage.ts +57 -0
  57. package/app/src/cms/middleware.ts +199 -0
  58. package/app/src/cms/middlewares.ts +13 -0
  59. package/app/src/cms/network-ui.ts +36 -0
  60. package/app/src/cms/network-view.ts +38 -0
  61. package/app/src/cms/notes-announce.ts +65 -0
  62. package/app/src/cms/notes-rail.ts +207 -0
  63. package/app/src/cms/notification-rules.ts +66 -0
  64. package/app/src/cms/recovery.ts +82 -0
  65. package/app/src/cms/replace.ts +63 -0
  66. package/app/src/cms/reserved-paths.ts +19 -0
  67. package/app/src/cms/rich-text-field.ts +325 -0
  68. package/app/src/cms/rich-text-schema.ts +91 -0
  69. package/app/src/cms/rich-text.client.ts +255 -0
  70. package/app/src/cms/search.client.ts +116 -0
  71. package/app/src/cms/seo-head.ts +78 -0
  72. package/app/src/cms/seo.ts +241 -0
  73. package/app/src/cms/settings-draft.ts +218 -0
  74. package/app/src/cms/settings-file.ts +127 -0
  75. package/app/src/cms/settings-form.ts +180 -0
  76. package/app/src/cms/settings-languages.ts +125 -0
  77. package/app/src/cms/settings-nav.ts +102 -0
  78. package/app/src/cms/settings-network.ts +151 -0
  79. package/app/src/cms/settings-permalinks.ts +114 -0
  80. package/app/src/cms/settings-scroll.ts +10 -0
  81. package/app/src/cms/settings-search.ts +77 -0
  82. package/app/src/cms/settings-section.ts +38 -0
  83. package/app/src/cms/share.client.ts +27 -0
  84. package/app/src/cms/site-editing.ts +219 -0
  85. package/app/src/cms/site-editor.client.ts +1008 -0
  86. package/app/src/cms/site-editor.ts +99 -0
  87. package/app/src/cms/site-export.ts +60 -0
  88. package/app/src/cms/site-forms.ts +143 -0
  89. package/app/src/cms/site-import.ts +28 -0
  90. package/app/src/cms/site-session.ts +36 -0
  91. package/app/src/cms/site-taskbar.ts +77 -0
  92. package/app/src/cms/site-view.ts +1014 -0
  93. package/app/src/cms/site.ts +1322 -0
  94. package/app/src/cms/sitemaps.ts +131 -0
  95. package/app/src/cms/stat.client.ts +56 -0
  96. package/app/src/cms/style-controls.ts +252 -0
  97. package/app/src/cms/tabs.client.ts +36 -0
  98. package/app/src/cms/taskbar.ts +134 -0
  99. package/app/src/cms/term-icons.ts +10 -0
  100. package/app/src/cms/traffic.ts +26 -0
  101. package/app/src/cms/ui.ts +170 -0
  102. package/app/src/cms/updates.ts +124 -0
  103. package/app/src/cms/uploads.ts +26 -0
  104. package/app/src/cms/worker.ts +13 -0
  105. package/app/src/config/auth.ts +30 -0
  106. package/app/src/config/cms.ts +18 -0
  107. package/app/src/dashboard/access.ts +344 -0
  108. package/app/src/dashboard/agent-icons.ts +44 -0
  109. package/app/src/dashboard/app-passwords.ts +74 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +53 -0
  112. package/app/src/dashboard/head.ts +29 -0
  113. package/app/src/dashboard/icons.ts +15 -0
  114. package/app/src/dashboard/list-table.ts +120 -0
  115. package/app/src/dashboard/modules/roles.ts +15 -0
  116. package/app/src/dashboard/modules/sessions.ts +15 -0
  117. package/app/src/dashboard/modules/settings.ts +15 -0
  118. package/app/src/dashboard/modules/users.ts +18 -0
  119. package/app/src/dashboard/page.ts +67 -0
  120. package/app/src/dashboard/registry.ts +13 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +26 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +40 -0
  125. package/app/src/dashboard/user-sections.ts +172 -0
  126. package/app/src/lib/permissions.ts +84 -0
  127. package/app/src/middlewares/auth.ts +117 -0
  128. package/app/src/pages/(site)/[...path]/index.ts +609 -0
  129. package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
  130. package/app/src/pages/(site)/feed/index.ts +12 -0
  131. package/app/src/pages/(site)/index.ts +11 -0
  132. package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
  133. package/app/src/pages/(site)/layout.ts +219 -0
  134. package/app/src/pages/(site)/llms.txt/index.ts +23 -0
  135. package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
  136. package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
  137. package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
  138. package/app/src/pages/(site)/robots.txt/index.ts +29 -0
  139. package/app/src/pages/(site)/search/index.ts +36 -0
  140. package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
  141. package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
  142. package/app/src/pages/api/auth/session.ts +48 -0
  143. package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
  144. package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
  145. package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
  146. package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
  147. package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
  148. package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
  149. package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
  150. package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
  151. package/app/src/pages/api/cms/cache/purge.ts +6 -0
  152. package/app/src/pages/api/cms/collections/index.ts +6 -0
  153. package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
  154. package/app/src/pages/api/cms/comments/[id].ts +9 -0
  155. package/app/src/pages/api/cms/comments/index.ts +126 -0
  156. package/app/src/pages/api/cms/comments/queue.ts +6 -0
  157. package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
  158. package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
  159. package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
  160. package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
  161. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
  162. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
  163. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
  164. package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
  165. package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
  166. package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
  167. package/app/src/pages/api/cms/export/[collection].ts +37 -0
  168. package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
  169. package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
  170. package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
  171. package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
  172. package/app/src/pages/api/cms/import/[collection].ts +23 -0
  173. package/app/src/pages/api/cms/mcp.ts +29 -0
  174. package/app/src/pages/api/cms/me/index.ts +6 -0
  175. package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
  176. package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
  177. package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
  178. package/app/src/pages/api/cms/media/[id].ts +6 -0
  179. package/app/src/pages/api/cms/media.ts +26 -0
  180. package/app/src/pages/api/cms/menus/[location].ts +14 -0
  181. package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
  182. package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
  183. package/app/src/pages/api/cms/network/sites/index.ts +14 -0
  184. package/app/src/pages/api/cms/notes/[id].ts +13 -0
  185. package/app/src/pages/api/cms/notes/index.ts +6 -0
  186. package/app/src/pages/api/cms/payments/webhook.ts +28 -0
  187. package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
  188. package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
  189. package/app/src/pages/api/cms/plugins/index.ts +6 -0
  190. package/app/src/pages/api/cms/recovery.ts +29 -0
  191. package/app/src/pages/api/cms/redirects/index.ts +9 -0
  192. package/app/src/pages/api/cms/roles/index.ts +6 -0
  193. package/app/src/pages/api/cms/schema/[collection].ts +13 -0
  194. package/app/src/pages/api/cms/search.ts +16 -0
  195. package/app/src/pages/api/cms/settings/[group].ts +9 -0
  196. package/app/src/pages/api/cms/settings/index.ts +9 -0
  197. package/app/src/pages/api/cms/site-export.ts +34 -0
  198. package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
  199. package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
  200. package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
  201. package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
  202. package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
  203. package/app/src/pages/api/cms/uploads/index.ts +26 -0
  204. package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
  205. package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
  206. package/app/src/pages/api/cms/users/index.ts +12 -0
  207. package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
  208. package/app/src/pages/api/cms/webhooks/index.ts +9 -0
  209. package/app/src/pages/auth/[provider]/callback.ts +11 -0
  210. package/app/src/pages/auth/[provider]/redirect.ts +9 -0
  211. package/app/src/pages/auth/forgot-password/index.ts +75 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +198 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +117 -0
  216. package/app/src/pages/auth/reset-password/index.ts +65 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +67 -0
  219. package/app/src/pages/auth/verify/index.ts +62 -0
  220. package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
  221. package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
  222. package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
  223. package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
  224. package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
  225. package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
  226. package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
  227. package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
  228. package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
  229. package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
  230. package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
  231. package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
  232. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
  233. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
  234. package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
  235. package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
  236. package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
  237. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
  238. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
  239. package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
  240. package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
  241. package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
  242. package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
  243. package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
  244. package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
  245. package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
  246. package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
  247. package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
  248. package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
  249. package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
  250. package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
  251. package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
  252. package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
  253. package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
  254. package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
  255. package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
  256. package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
  257. package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
  258. package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
  259. package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
  260. package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
  261. package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
  262. package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
  263. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
  264. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
  265. package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
  266. package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
  267. package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
  268. package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
  269. package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
  270. package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
  271. package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
  272. package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
  273. package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
  274. package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
  275. package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
  276. package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
  277. package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +320 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +255 -0
  282. package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
  283. package/app/src/pages/dashboard/roles/index.ts +134 -0
  284. package/app/src/pages/dashboard/roles/new/index.ts +95 -0
  285. package/app/src/pages/dashboard/sessions/index.ts +105 -0
  286. package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
  287. package/app/src/pages/dashboard/users/index.ts +299 -0
  288. package/app/src/pages/dashboard/users/new/index.ts +123 -0
  289. package/app/src/passkeys.client.ts +18 -0
  290. package/app/src/plugins/default-theme/assets/cover.svg +31 -0
  291. package/app/src/plugins/default-theme/assets/logo.svg +8 -0
  292. package/app/src/plugins/default-theme/parts/comments.ts +66 -0
  293. package/app/src/plugins/default-theme/parts/list.ts +38 -0
  294. package/app/src/plugins/default-theme/parts/media.ts +15 -0
  295. package/app/src/plugins/default-theme/parts/options.ts +45 -0
  296. package/app/src/plugins/default-theme/plugin.json +275 -0
  297. package/app/src/plugins/default-theme/templates/archive.ts +14 -0
  298. package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
  299. package/app/src/plugins/default-theme/templates/entry.ts +27 -0
  300. package/app/src/plugins/default-theme/templates/home.ts +8 -0
  301. package/app/src/plugins/default-theme/templates/layout.ts +40 -0
  302. package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
  303. package/app/src/plugins/default-theme/templates/search.ts +32 -0
  304. package/app/src/services/rbac.ts +65 -0
  305. package/app/src/services/roles.ts +89 -0
  306. package/app/src/services/users.ts +173 -0
  307. package/package.json +123 -3
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
@@ -0,0 +1,344 @@
1
+ import type { Context } from 'hono';
2
+ import { ANONYMOUS, applyDashboardMenu, dashboardLinkModuleId, dashboardMenuOf, dashboardNotices as noticesPoint, dashboardNoticesOf, dashboardTaskbar, EMPTY_DASHBOARD_MENU, evaluateRule, hasPermission, isCmsError, isNetworkAdmin, PERMISSIONS, recordTitle, taskbarItemsOf, type DashboardNotice, type Principal, type WriteActor } from '@cossackframework/cms';
3
+ import { MAIN_SITE, type CmsHost } from '@cossackframework/cms/server';
4
+ import { icon } from '../cms/icons';
5
+ import { currentCms, networkFor, siteUrl, updateSettings, type CmsBindings } from '../cms/index';
6
+ import { updateAvailable } from '../cms/updates';
7
+ import { recoveryCode } from '../cms/recovery';
8
+ import { openMatches } from '../cms/site';
9
+ import { dashboardModules } from './registry';
10
+ import type { DashboardModule, DashboardModuleLink, DashboardStatus } from './types';
11
+
12
+ /**
13
+ * The same data within one request, asked for once: the layout, the command palette and the
14
+ * taskbar all build the navigation and the counts, so each computes on the first ask and the
15
+ * others wait for that promise. A request-scoped memo, never shared between requests.
16
+ */
17
+ export function remember<T>(c: Context, key: string, compute: () => Promise<T>): Promise<T> {
18
+ let memo = c.get('cms.memo');
19
+ if (!memo) { memo = new Map(); c.set('cms.memo', memo); }
20
+ let value = memo.get(key) as Promise<T> | undefined;
21
+ if (!value) {
22
+ value = compute();
23
+ memo.set(key, value);
24
+ value.catch(() => memo!.delete(key));
25
+ }
26
+ return value;
27
+ }
28
+
29
+ /** Comments waiting for moderation, for moderators of a site with comments; 0 otherwise. */
30
+ export function pendingComments(c: Context): Promise<number> {
31
+ return remember(c, 'counts.comments', async () => {
32
+ const cms = c.get('cms') as CmsHost;
33
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
34
+ if (!hasPermission(principal, PERMISSIONS.moderateComments) || !cms.collections().some(collection => collection.comments)) return 0;
35
+ return cms.comments.counts().then(counts => counts.pending).catch(() => 0);
36
+ });
37
+ }
38
+
39
+ /** New form submissions across the forms the user manages; 0 without that permission. */
40
+ export function freshSubmissions(c: Context): Promise<number> {
41
+ return remember(c, 'counts.submissions', async () => {
42
+ const cms = c.get('cms') as CmsHost;
43
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
44
+ if (!hasPermission(principal, PERMISSIONS.manageSubmissions) || !cms.collections().some(collection => collection.name === 'forms')) return 0;
45
+ return cms.forms.all().then(forms => cms.forms.inboxCounts(forms, principal)).then(counts => [...counts.values()].reduce((sum, count) => sum + count.fresh, 0)).catch(() => 0);
46
+ });
47
+ }
48
+
49
+ /** Accounts waiting for approval, for user managers; 0 otherwise. */
50
+ export function waitingRegistrations(c: Context): Promise<number> {
51
+ return remember(c, 'counts.registrations', async () => {
52
+ const cms = c.get('cms') as CmsHost;
53
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
54
+ return hasPermission(principal, PERMISSIONS.manageUsers) ? cms.users.registrationCount().catch(() => 0) : 0;
55
+ });
56
+ }
57
+
58
+ const EMPTY_STATUS = { resources: [], plugins: [] } as Awaited<ReturnType<CmsHost['status']>>;
59
+
60
+ /** The host's activation status (resources and plugins), once per request. */
61
+ export function activationStatus(c: Context): Promise<Awaited<ReturnType<CmsHost['status']>>> {
62
+ return remember(c, 'status', () => (c.get('cms') as CmsHost).status().catch(() => EMPTY_STATUS));
63
+ }
64
+
65
+ /** The account modules' icons by module id: the scaffold draws them in line, the CMS in the site's style. */
66
+ const REGISTRY_ICONS: Readonly<Record<string, string>> = { users: 'users-group-rounded', roles: 'shield-keyhole', sessions: 'monitor-smartphone', settings: 'user-circle' };
67
+
68
+ /**
69
+ * Navigation for the signed-in user as the site's administrators arranged it (Appearance →
70
+ * Dashboard menu): the default navigation with modules hidden, reordered and links added.
71
+ */
72
+ export function navigation(c: Context): Promise<DashboardModule[]> {
73
+ return remember(c, 'navigation', async () => {
74
+ const cms = c.get('cms') as CmsHost;
75
+ const [modules, stored] = await Promise.all([defaultNavigation(c), cms.settings.get('dashboard.menu').catch(() => null)]);
76
+ const menu = dashboardMenuOf(stored);
77
+ if (menu === EMPTY_DASHBOARD_MENU) return modules;
78
+ const account = modules.filter(module => module.placement === 'account');
79
+ const arranged = applyDashboardMenu(modules.filter(module => module.placement !== 'account'), menu,
80
+ link => ({ id: dashboardLinkModuleId(link), label: link.label, href: link.href, icon: icon(link.icon, 'link'), authorization: 'authenticated' as const }));
81
+ return [...arranged, ...account];
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Who sees Tools → Updates: holders of the permission, on the main site. In a network the
87
+ * software is shared by every site, so only the network's administrators do.
88
+ */
89
+ export async function managesUpdates(c: Context, principal: Principal): Promise<boolean> {
90
+ if (!hasPermission(principal, PERMISSIONS.manageUpdates) || c.get('site')?.id !== MAIN_SITE) return false;
91
+ return isNetworkAdmin(principal) || !(await networkFor(c.env as CmsBindings).enabled().catch(() => false));
92
+ }
93
+
94
+ /**
95
+ * The default navigation for the signed-in user, in WordPress order: content first (posts,
96
+ * media, pages, other collections, plugin resources and links), then administration. Each item
97
+ * shows only with the permission its screens require. What it needs from the database loads in
98
+ * one round, and once per request.
99
+ */
100
+ export function defaultNavigation(c: Context): Promise<DashboardModule[]> {
101
+ return remember(c, 'navigation.default', () => buildNavigation(c));
102
+ }
103
+
104
+ async function buildNavigation(c: Context): Promise<DashboardModule[]> {
105
+ const cms = c.get('cms') as CmsHost;
106
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
107
+ const env = c.env as CmsBindings;
108
+ const can = (permission: string) => hasPermission(principal, permission);
109
+ const hasForms = cms.collections().some(collection => collection.name === 'forms');
110
+ const formsCreate = hasForms && evaluateRule(cms.resourceById('cms/forms').access.create, principal) !== 'deny';
111
+ const showsForms = hasForms && (formsCreate || can('cms/forms:read') || can('cms/forms:update') || can(PERMISSIONS.manageSubmissions));
112
+ const [status, pendingCommentCount, fresh, slotLinks, approveRegistrations, registrations, network, sites, updates] = await Promise.all([
113
+ activationStatus(c),
114
+ pendingComments(c),
115
+ showsForms ? freshSubmissions(c) : 0,
116
+ cms.slotLinks('dashboard.nav', principal).catch(() => []),
117
+ can(PERMISSIONS.manageUsers) ? cms.settings.get('general.approveRegistrations').catch(() => false) : false,
118
+ waitingRegistrations(c),
119
+ showsNetwork(c, principal),
120
+ principal.kind === 'user' ? remember(c, 'member-sites', () => networkFor(env).memberSites(principal.id).catch(() => [])) : [],
121
+ managesUpdates(c, principal).then(async shown => ({ shown, available: shown && await updateAvailable(networkFor(env), updateSettings(env)).catch(() => false) })),
122
+ ]);
123
+ const content: DashboardModule[] = [];
124
+ const ordered = [...cms.collections()].sort((a, b) => (a.name === 'posts' ? -1 : b.name === 'posts' ? 1 : 0));
125
+ for (const collection of ordered) {
126
+ // Forms have their own section, after Comments.
127
+ if (collection.name === 'forms') continue;
128
+ const resource = cms.resourceById(`cms/${collection.name}`);
129
+ const create = evaluateRule(resource.access.create, principal) !== 'deny';
130
+ if (!create && !can(`cms/${collection.name}:update`) && !can(`cms/${collection.name}:read`)) continue;
131
+ const base = `/dashboard/content/${collection.name}`;
132
+ const children: DashboardModuleLink[] = [{ label: `All ${collection.label.toLowerCase()}`, href: base }];
133
+ if (create) children.push({ label: 'New', href: `${base}/new` });
134
+ if (can(PERMISSIONS.manageTerms)) {
135
+ for (const name of collection.taxonomies ?? []) {
136
+ const taxonomy = cms.taxonomies.declarations.find(entry => entry.name === name);
137
+ if (taxonomy) children.push({ label: taxonomy.label, href: `/dashboard/terms/${name}` });
138
+ }
139
+ }
140
+ content.push({ id: `collection-${collection.name}`, label: collection.label, href: base, icon: icon(collection.icon), authorization: 'authenticated', children });
141
+ }
142
+ // The month's published and scheduled entries of every collection the user may see.
143
+ if (content.length) content.push({ id: 'calendar', label: 'Calendar', href: '/dashboard/calendar', icon: icon('calendar'), authorization: 'authenticated' });
144
+ if (can(PERMISSIONS.upload) || can(PERMISSIONS.manageMedia)) {
145
+ // Media follows posts, as in WordPress.
146
+ content.splice(Math.min(1, content.length), 0, { id: 'media', label: 'Files', href: '/dashboard/media', icon: icon('folder-with-files'), authorization: 'authenticated',
147
+ children: [{ label: 'Library', href: '/dashboard/media' }, { label: 'New', href: '/dashboard/media/new' }, { label: 'Summary', href: '/dashboard/media/summary' }] });
148
+ }
149
+ // A plugin's records show once it is active; until then its screens answer that it is not.
150
+ const inactivePlugins = new Set(status.plugins.filter(plugin => !plugin.active).map(plugin => plugin.name));
151
+ for (const resource of cms.readable(principal)) {
152
+ if (resource.owner === 'cms' || inactivePlugins.has(resource.owner)) continue;
153
+ const create = evaluateRule(resource.access.create, principal) !== 'deny';
154
+ const base = `/dashboard/content/${resource.owner}.${resource.name}`;
155
+ content.push({ id: `resource-${resource.owner}-${resource.name}`, label: resource.label ?? resource.id, href: base, icon: icon('widget-4'), authorization: 'authenticated',
156
+ children: [{ label: 'All entries', href: base }, ...(create ? [{ label: 'New', href: `${base}/new` }] : [])] });
157
+ }
158
+ // Comments follow the content they belong to; the label shows how many wait for moderation.
159
+ if (can(PERMISSIONS.moderateComments) && cms.collections().some(collection => collection.comments)) {
160
+ content.push({ id: 'comments', label: pendingCommentCount ? `Comments (${pendingCommentCount})` : 'Comments', href: '/dashboard/comments', icon: icon('chat-round-dots'), authorization: { permission: PERMISSIONS.moderateComments } });
161
+ }
162
+ // Forms follow comments; the label counts new submissions.
163
+ if (showsForms) {
164
+ content.push({ id: 'forms', label: fresh ? `Forms (${fresh})` : 'Forms', href: '/dashboard/forms', icon: icon('checklist-minimalistic'), authorization: 'authenticated',
165
+ children: [{ label: 'All forms', href: '/dashboard/forms' }, ...(formsCreate ? [{ label: 'New', href: '/dashboard/content/forms/new' }] : [])] });
166
+ }
167
+ // Host slot: active plugins add navigation links, with an icon of the dashboard's set when they name one.
168
+ for (const link of slotLinks) {
169
+ content.push({ id: `plugin-${link.plugin}-${link.href}`, label: link.label, href: link.href, icon: icon(link.icon, 'plug-circle'), authorization: 'authenticated' });
170
+ }
171
+
172
+ const admin: DashboardModule[] = [];
173
+ if (can(PERMISSIONS.manageAppearance)) {
174
+ admin.push({ id: 'appearance', label: 'Appearance', href: '/dashboard/appearance', icon: icon('palette-2'), authorization: { permission: PERMISSIONS.manageAppearance },
175
+ children: [{ label: 'Themes', href: '/dashboard/appearance' }, { label: 'Customize', href: '/dashboard/appearance/customize' }, { label: 'Menus', href: '/dashboard/appearance/menus' }, { label: 'Widgets', href: '/dashboard/appearance/widgets' }, { label: 'Dashboard menu', href: '/dashboard/appearance/dashboard-menu' }] });
176
+ }
177
+ if (can(PERMISSIONS.manageCollections)) {
178
+ admin.push({ id: 'collections', label: 'Collections', href: '/dashboard/collections', icon: icon('structure'), authorization: { permission: PERMISSIONS.manageCollections },
179
+ children: [{ label: 'All collections', href: '/dashboard/collections' }, { label: 'Field groups', href: '/dashboard/field-groups' }, { label: 'Taxonomies', href: '/dashboard/taxonomies' }, { label: 'Blocks', href: '/dashboard/blocks' }] });
180
+ }
181
+ if (can(PERMISSIONS.managePlugins)) admin.push({ id: 'plugins', label: 'Plugins', href: '/dashboard/plugins', icon: icon('plug-circle'), authorization: { permission: PERMISSIONS.managePlugins } });
182
+ // Roles belong to role managers; the other administration modules to user managers.
183
+ const registry = dashboardModules.filter(module => module.authorization === 'authenticated'
184
+ || (module.authorization === 'admin' ? can(module.id === 'roles' ? PERMISSIONS.manageRoles : PERMISSIONS.manageUsers) : can(module.authorization.permission)))
185
+ .map(module => REGISTRY_ICONS[module.id] ? { ...module, icon: icon(REGISTRY_ICONS[module.id]) } : module);
186
+ // Users gains Registrations while the site approves new accounts, or while one still waits.
187
+ const approving = can(PERMISSIONS.manageUsers) && (approveRegistrations || registrations > 0);
188
+ admin.push(...registry.filter(module => module.placement !== 'account')
189
+ .map(module => module.id === 'users' && approving ? { ...module, children: [...(module.children ?? []), { label: 'Registrations', href: '/dashboard/registrations' }] } : module));
190
+ const tools: DashboardModuleLink[] = [
191
+ ...(can(PERMISSIONS.manageRedirects) ? [{ label: 'Redirects', href: '/dashboard/tools/redirects' }] : []),
192
+ ...(can(PERMISSIONS.manageRedirects) || can(PERMISSIONS.manageCollections) ? [{ label: 'Links', href: '/dashboard/tools/links' }] : []),
193
+ ...(can(PERMISSIONS.manageSettings) || can(PERMISSIONS.manageRedirects) ? [{ label: 'Health', href: '/dashboard/tools/health' }] : []),
194
+ ...(can(PERMISSIONS.manageSettings) ? [{ label: 'SEO editor', href: '/dashboard/tools/seo' }] : []),
195
+ ...(can(PERMISSIONS.manageWebhooks) ? [{ label: 'Webhooks', href: '/dashboard/tools/webhooks' }] : []),
196
+ ...(can(PERMISSIONS.manageSchema) ? [{ label: 'Schema', href: '/dashboard/tools/schema' }] : []),
197
+ ...(can(PERMISSIONS.manageSettings) ? [{ label: 'Export', href: '/dashboard/tools/export' }] : []),
198
+ ...(can(PERMISSIONS.manageSettings) ? [{ label: 'Cache', href: '/dashboard/tools/cache' }] : []),
199
+ // In a network the software is the network's: its administrators update it, on the network host.
200
+ ...(updates.shown ? [{ label: updates.available ? 'Updates (1)' : 'Updates', href: '/dashboard/tools/updates' }] : []),
201
+ ...(can(PERMISSIONS.manageSettings) ? [{ label: 'Jobs', href: '/dashboard/tools/jobs' }, { label: 'Activity', href: '/dashboard/tools/activity' }, { label: 'Find and replace', href: '/dashboard/tools/replace' }, { label: 'Automations', href: '/dashboard/tools/automations' }] : []),
202
+ ];
203
+ if (tools.length) admin.push({ id: 'tools', label: 'Tools', href: tools[0]!.href, icon: icon('tuning-2'), authorization: 'authenticated', children: tools });
204
+ // Settings has its own navigation beside its pages, so the sidebar holds one link.
205
+ if (can(PERMISSIONS.manageSettings)) admin.push({ id: 'site-settings', label: 'Settings', href: '/dashboard/settings', icon: icon('settings'), authorization: { permission: PERMISSIONS.manageSettings },
206
+ activeFor: '/dashboard/settings' });
207
+ // Network admins run the network from the network host; its settings are under Settings there.
208
+ if (network) admin.push({ id: 'network', label: 'Network', href: '/dashboard/network', icon: icon('global'), authorization: 'authenticated', activeFor: '/dashboard/network',
209
+ children: [['Home', ''], ['Sites', '/sites'], ['Users', '/users'], ['Plugins', '/plugins'], ['Themes', '/themes'], ['Updates', '/updates']].map(([label, path]) => ({ label: label!, href: `/dashboard/network${path}` })) });
210
+ // Sites: My sites (every site the account belongs to) and each site's dashboard, when there is more than one.
211
+ if (sites.length > 1) content.unshift({ id: 'my-sites', label: 'Sites', href: '/dashboard/my-sites', icon: icon('home-2'), authorization: 'authenticated',
212
+ children: [{ label: 'My sites', href: '/dashboard/my-sites' }, ...sites.map(site => ({ label: site.name ?? 'Main site', href: `${(siteUrl(env, site) ?? '').replace(/\/$/, '')}/dashboard` }))] });
213
+ const account = registry.filter(module => module.placement === 'account');
214
+ // The author profile follows the profile settings in the account menu.
215
+ account.splice(Math.min(1, account.length), 0, { id: 'public-profile', label: 'Public profile', href: '/dashboard/profile/public', icon: icon('user-id'), authorization: 'authenticated', placement: 'account' });
216
+ return [...content, ...admin, ...account];
217
+ }
218
+
219
+ /** Whether the dashboard links the network's: for network admins, on the main site, while the network is on. Other sites reach it through My sites. */
220
+ function showsNetwork(c: Context, principal: Principal): Promise<boolean> {
221
+ return remember(c, 'shows-network', async () => isNetworkAdmin(principal) && c.get('site')?.id === MAIN_SITE && await networkFor(c.env as CmsBindings).enabled().catch(() => false));
222
+ }
223
+
224
+ /**
225
+ * What waits for the signed-in user, for the dashboard's taskbar: comments to moderate, entries
226
+ * pending review, new form submissions, schema migrations, plugins waiting for a grant and
227
+ * deliveries, each with a count and where to go; then the links active plugins add to the
228
+ * `dashboard.taskbar` slot.
229
+ */
230
+ export async function dashboardStatus(c: Context): Promise<DashboardStatus[]> {
231
+ const cms = c.get('cms') as CmsHost;
232
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
233
+ const can = (permission: string) => hasPermission(principal, permission);
234
+ const context = { principal };
235
+ const items: DashboardStatus[] = [];
236
+ const reviewed = cms.collections().filter(collection => collection.publishable !== false && can(`cms/${collection.name}:update`));
237
+ const technical = can(PERMISSIONS.manageSchema) || can(PERMISSIONS.managePlugins);
238
+ // Everything the bar counts, in one round.
239
+ const [network, exportRequests, pendingCommentCount, pendingByCollection, unseen, fresh, status, outbox, unconfirmed, slotLinks] = await Promise.all([
240
+ showsNetwork(c, principal),
241
+ showsNetwork(c, principal).then(shows => shows ? networkFor(c.env as CmsBindings).exportRequests().catch(() => new Map()) : new Map()),
242
+ pendingComments(c),
243
+ Promise.all(reviewed.map(collection => cms.resource(`cms/${collection.name}`).count({ where: { status: 'pending' } }, context).catch(() => 0))),
244
+ principal.kind === 'user' ? cms.notes.unseen(principal.id).catch(() => 0) : 0,
245
+ freshSubmissions(c),
246
+ technical ? activationStatus(c) : EMPTY_STATUS,
247
+ can(PERMISSIONS.manageSchema) ? cms.outbox.pending({ limit: 100 }).catch(() => []) : [],
248
+ can(PERMISSIONS.manageSchema) ? cms.db.pending.list({ limit: 100 }).catch(() => []) : [],
249
+ cms.slotLinks('dashboard.taskbar', principal).catch(() => []),
250
+ ]);
251
+ // Network admins reach the network dashboard from the main site's taskbar, with sites' export requests.
252
+ if (network) {
253
+ items.push({ id: 'network', label: 'Network', href: '/dashboard/network' });
254
+ const waiting = [...exportRequests.values()].filter(request => request.approvedAt === null);
255
+ if (waiting.length) items.push({ id: 'export-requests', label: 'Export requests', href: `/dashboard/network/sites/${waiting[0]!.site}`, count: waiting.length, tone: 'warning' });
256
+ }
257
+ if (pendingCommentCount) items.push({ id: 'comments', label: 'Comments to moderate', href: '/dashboard/comments?status=pending', count: pendingCommentCount, tone: 'warning' });
258
+ const pending = pendingByCollection.reduce((sum, count) => sum + count, 0);
259
+ const first = reviewed[pendingByCollection.findIndex(count => count > 0)]?.name ?? '';
260
+ if (pending) items.push({ id: 'pending-review', label: 'Pending review', href: `/dashboard/content/${first}?status=pending`, count: pending, tone: 'warning' });
261
+ // Notes that name the user, in entries they have not opened since.
262
+ if (unseen) items.push({ id: 'notes', label: 'Notes for you', href: '/dashboard#notes-for-you', count: unseen });
263
+ if (fresh) items.push({ id: 'submissions', label: 'New submissions', href: '/dashboard/forms', count: fresh });
264
+ if (technical) {
265
+ const migrations = status.resources.filter(resource => !resource.active).length;
266
+ if (migrations && can(PERMISSIONS.manageSchema)) items.push({ id: 'schema', label: 'Schema migrations waiting', href: '/dashboard/tools/schema', count: migrations, tone: 'error' });
267
+ // A network-active plugin waits for the network admin, not the site's.
268
+ const grants = status.plugins.filter(plugin => !plugin.active && plugin.missing.length && plugin.network === 'available').length;
269
+ if (grants && can(PERMISSIONS.managePlugins)) items.push({ id: 'plugins', label: 'Plugins waiting for a grant', href: '/dashboard/plugins', count: grants, tone: 'warning' });
270
+ }
271
+ if (outbox.length) items.push({ id: 'outbox', label: 'Events waiting for delivery', href: '/dashboard', count: outbox.length });
272
+ if (unconfirmed.length) items.push({ id: 'unconfirmed', label: 'Writes waiting for confirmation', href: '/dashboard', count: unconfirmed.length, tone: 'warning' });
273
+ for (const link of slotLinks) items.push({ id: `plugin-${link.plugin}-${link.href}`, label: link.label, href: link.href });
274
+ // Plugins add items with counts, or change the built-in ones, through `cms.dashboard.taskbar`; a failing handler leaves the list as it was.
275
+ const filtered = await cms.hooks.applyFilters(dashboardTaskbar, items, { actor: actorOf(principal) }).catch(() => items);
276
+ return taskbarItemsOf(filtered);
277
+ }
278
+
279
+ /** Notices above every dashboard screen: what active plugins return from `cms.dashboard.notices`. */
280
+ export async function dashboardNotices(c: Context): Promise<DashboardNotice[]> {
281
+ const cms = c.get('cms') as CmsHost | undefined;
282
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
283
+ if (!cms || principal.kind !== 'user') return [];
284
+ // User managers hear of accounts waiting for their approval on every screen, until none waits.
285
+ const waiting = await waitingRegistrations(c);
286
+ const core: DashboardNotice[] = waiting ? [{ id: 'cms-registrations', tone: 'info', message: waiting === 1 ? __('1 new account waits for your approval.') : `${waiting} ${__('new accounts wait for your approval.')}`, href: '/dashboard/registrations' }] : [];
287
+ // Recovery mode lets anyone with the code reset any account: administrators are reminded to turn it off.
288
+ if (recoveryCode(c.env) && hasPermission(principal, PERMISSIONS.manageSettings))
289
+ core.unshift({ id: 'cms-recovery-mode', tone: 'warning', message: __('Recovery mode is on: anyone with CMS_RECOVERY_CODE can reset an account\'s password. Remove it from the environment once you are back in.'), href: '/dashboard/tools/activity?resource=cms/users' });
290
+ return dashboardNoticesOf(await cms.hooks.applyFilters(noticesPoint, core, { actor: actorOf(principal) }).catch(() => core));
291
+ }
292
+
293
+ function actorOf(principal: Principal): WriteActor {
294
+ return principal.kind === 'user' ? { kind: 'user', id: principal.id } : principal.kind === 'system' ? { kind: 'system', id: principal.reason } : { kind: 'anonymous', id: 'anonymous' };
295
+ }
296
+
297
+ export { siteName } from '../brand';
298
+
299
+ /**
300
+ * Where the command palette (Ctrl/Cmd+K) can go: every module and child link of the navigation,
301
+ * grouped by module. The CMS adds its screens the same way through its own navigation.
302
+ */
303
+ export async function dashboardSearch(c: Context): Promise<{ id: string; label: string; group: string; href: string }[]> {
304
+ const modules = await navigation(c);
305
+ const seen = new Set<string>();
306
+ const commands: { id: string; label: string; group: string; href: string }[] = [];
307
+ const add = (label: string, group: string, href: string) => {
308
+ if (seen.has(href)) return;
309
+ seen.add(href);
310
+ commands.push({ id: href, label, group, href });
311
+ };
312
+ add('Dashboard', 'Dashboard', '/dashboard');
313
+ for (const module of modules) {
314
+ add(module.label, module.placement === 'account' ? 'Account' : module.label, module.href);
315
+ for (const child of module.children ?? []) add(`${module.label}: ${child.label}`, module.label, child.href);
316
+ }
317
+ return commands;
318
+ }
319
+
320
+ /**
321
+ * What the command palette finds for typed text besides its screens: entries of each collection
322
+ * the user may read, drafts included, up to five a collection, opening in the editor. The last
323
+ * word typed is a prefix, so entries show while someone types.
324
+ */
325
+ export async function dashboardFind(c: Context, text: string): Promise<{ id: string; label: string; group: string; href: string }[]> {
326
+ const cms = c.get('cms') as CmsHost;
327
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
328
+ const searched = cms.collections().filter(collection => Object.values(cms.resourceById(`cms/${collection.name}`).fields).some(field => field.search));
329
+ const found = await Promise.all(searched.map(async collection => {
330
+ const resource = cms.resourceById(`cms/${collection.name}`);
331
+ try {
332
+ const records = openMatches(cms, resource.id, await cms.resource(resource.id).search(text, { limit: 5 }, { principal }), principal);
333
+ return records.map(record => {
334
+ const href = `/dashboard/content/${collection.name}/${record.id}`;
335
+ return { id: href, label: recordTitle(record, resource.titleField), group: collection.label, href };
336
+ });
337
+ } catch (error) {
338
+ // A collection the user may not read, or a search RomeDB refused: nothing from it.
339
+ if (isCmsError(error)) return [];
340
+ throw error;
341
+ }
342
+ }));
343
+ return found.flat();
344
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Browser and operating system glyphs for sign-in lists, drawn from a parsed user agent. The
3
+ * brand marks of Chrome, Firefox, Opera, Apple, Android and Linux are from Simple Icons (CC0);
4
+ * Safari, Edge and Windows are plain drawings, since their marks are not freely licensed.
5
+ * Unknown agents get a globe or a monitor. Client-safe.
6
+ */
7
+ import { html, type TemplateResult } from '@cossackframework/renderer';
8
+
9
+ const PATHS: Record<string, string> = {
10
+ chrome: 'M12 0C8.21 0 4.831 1.757 2.632 4.501l3.953 6.848A5.454 5.454 0 0 1 12 6.545h10.691A12 12 0 0 0 12 0zM1.931 5.47A11.943 11.943 0 0 0 0 12c0 6.012 4.42 10.991 10.189 11.864l3.953-6.847a5.45 5.45 0 0 1-6.865-2.29zm13.342 2.166a5.446 5.446 0 0 1 1.45 7.09l.002.001h-.002l-5.344 9.257c.206.01.413.016.621.016 6.627 0 12-5.373 12-12 0-1.54-.29-3.011-.818-4.364zM12 16.364a4.364 4.364 0 1 1 0-8.728 4.364 4.364 0 0 1 0 8.728Z',
11
+ firefox: 'M8.824 7.287c.008 0 .004 0 0 0zm-2.8-1.4c.006 0 .003 0 0 0zm16.754 2.161c-.505-1.215-1.53-2.528-2.333-2.943.654 1.283 1.033 2.57 1.177 3.53l.002.02c-1.314-3.278-3.544-4.6-5.366-7.477-.091-.147-.184-.292-.273-.446a3.545 3.545 0 01-.13-.24 2.118 2.118 0 01-.172-.46.03.03 0 00-.027-.03.038.038 0 00-.021 0l-.006.001a.037.037 0 00-.01.005L15.624 0c-2.585 1.515-3.657 4.168-3.932 5.856a6.197 6.197 0 00-2.305.587.297.297 0 00-.147.37c.057.162.24.24.396.17a5.622 5.622 0 012.008-.523l.067-.005a5.847 5.847 0 011.957.222l.095.03a5.816 5.816 0 01.616.228c.08.036.16.073.238.112l.107.055a5.835 5.835 0 01.368.211 5.953 5.953 0 012.034 2.104c-.62-.437-1.733-.868-2.803-.681 4.183 2.09 3.06 9.292-2.737 9.02a5.164 5.164 0 01-1.513-.292 4.42 4.42 0 01-.538-.232c-1.42-.735-2.593-2.121-2.74-3.806 0 0 .537-2 3.845-2 .357 0 1.38-.998 1.398-1.287-.005-.095-2.029-.9-2.817-1.677-.422-.416-.622-.616-.8-.767a3.47 3.47 0 00-.301-.227 5.388 5.388 0 01-.032-2.842c-1.195.544-2.124 1.403-2.8 2.163h-.006c-.46-.584-.428-2.51-.402-2.913-.006-.025-.343.176-.389.206-.406.29-.787.616-1.136.974-.397.403-.76.839-1.085 1.303a9.816 9.816 0 00-1.562 3.52c-.003.013-.11.487-.19 1.073-.013.09-.026.181-.037.272a7.8 7.8 0 00-.069.667l-.002.034-.023.387-.001.06C.386 18.795 5.593 24 12.016 24c5.752 0 10.527-4.176 11.463-9.661.02-.149.035-.298.052-.448.232-1.994-.025-4.09-.753-5.844z',
12
+ opera: 'M8.051 5.238c-1.328 1.566-2.186 3.883-2.246 6.48v.564c.061 2.598.918 4.912 2.246 6.479 1.721 2.236 4.279 3.654 7.139 3.654 1.756 0 3.4-.537 4.807-1.471C17.879 22.846 15.074 24 12 24c-.192 0-.383-.004-.57-.014C5.064 23.689 0 18.436 0 12 0 5.371 5.373 0 12 0h.045c3.055.012 5.84 1.166 7.953 3.055-1.408-.93-3.051-1.471-4.81-1.471-2.858 0-5.417 1.42-7.14 3.654h.003zM24 12c0 3.556-1.545 6.748-4.002 8.945-3.078 1.5-5.946.451-6.896-.205 3.023-.664 5.307-4.32 5.307-8.74 0-4.422-2.283-8.075-5.307-8.74.949-.654 3.818-1.703 6.896-.205C22.455 5.25 24 8.445 24 12z',
13
+ apple: 'M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701',
14
+ android: 'M18.4395 5.5586c-.675 1.1664-1.352 2.3318-2.0274 3.498-.0366-.0155-.0742-.0286-.1113-.043-1.8249-.6957-3.484-.8-4.42-.787-1.8551.0185-3.3544.4643-4.2597.8203-.084-.1494-1.7526-3.021-2.0215-3.4864a1.1451 1.1451 0 0 0-.1406-.1914c-.3312-.364-.9054-.4859-1.379-.203-.475.282-.7136.9361-.3886 1.5019 1.9466 3.3696-.0966-.2158 1.9473 3.3593.0172.031-.4946.2642-1.3926 1.0177C2.8987 12.176.452 14.772 0 18.9902h24c-.119-1.1108-.3686-2.099-.7461-3.0683-.7438-1.9118-1.8435-3.2928-2.7402-4.1836a12.1048 12.1048 0 0 0-2.1309-1.6875c.6594-1.122 1.312-2.2559 1.9649-3.3848.2077-.3615.1886-.7956-.0079-1.1191a1.1001 1.1001 0 0 0-.8515-.5332c-.5225-.0536-.9392.3128-1.0488.5449zm-.0391 8.461c.3944.5926.324 1.3306-.1563 1.6503-.4799.3197-1.188.0985-1.582-.4941-.3944-.5927-.324-1.3307.1563-1.6504.4727-.315 1.1812-.1086 1.582.4941zM7.207 13.5273c.4803.3197.5506 1.0577.1563 1.6504-.394.5926-1.1038.8138-1.584.4941-.48-.3197-.5503-1.0577-.1563-1.6504.4008-.6021 1.1087-.8106 1.584-.4941z',
15
+ linux: 'M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.11.135c-.26.268-.45.6-.663.839-.199.199-.485.267-.797.4-.313.136-.658.269-.864.68-.09.189-.136.394-.132.602 0 .199.027.4.055.536.058.399.116.728.04.97-.249.68-.28 1.145-.106 1.484.174.334.535.47.94.601.81.2 1.91.135 2.774.6.926.466 1.866.67 2.616.47.526-.116.97-.464 1.208-.946.587-.003 1.23-.269 2.26-.334.699-.058 1.574.267 2.577.2.025.134.063.198.114.333l.003.003c.391.778 1.113 1.132 1.884 1.071.771-.06 1.592-.536 2.257-1.306.631-.765 1.683-1.084 2.378-1.503.348-.199.629-.469.649-.853.023-.4-.2-.811-.714-1.376v-.097l-.003-.003c-.17-.2-.25-.535-.338-.926-.085-.401-.182-.786-.492-1.046h-.003c-.059-.054-.123-.067-.188-.135a.357.357 0 00-.19-.064c.431-1.278.264-2.55-.173-3.694-.533-1.41-1.465-2.638-2.175-3.483-.796-1.005-1.576-1.957-1.56-3.368.026-2.152.236-6.133-3.544-6.139zm.529 3.405h.013c.213 0 .396.062.584.198.19.135.33.332.438.533.105.259.158.459.166.724 0-.02.006-.04.006-.06v.105a.086.086 0 01-.004-.021l-.004-.024a1.807 1.807 0 01-.15.706.953.953 0 01-.213.335.71.71 0 00-.088-.042c-.104-.045-.198-.064-.284-.133a1.312 1.312 0 00-.22-.066c.05-.06.146-.133.183-.198.053-.128.082-.264.088-.402v-.02a1.21 1.21 0 00-.061-.4c-.045-.134-.101-.2-.183-.333-.084-.066-.167-.132-.267-.132h-.016c-.093 0-.176.03-.262.132a.8.8 0 00-.205.334 1.18 1.18 0 00-.09.4v.019c.002.089.008.179.02.267-.193-.067-.438-.135-.607-.202a1.635 1.635 0 01-.018-.2v-.02a1.772 1.772 0 01.15-.768c.082-.22.232-.406.43-.533a.985.985 0 01.594-.2zm-2.962.059h.036c.142 0 .27.048.399.135.146.129.264.288.344.465.09.199.14.4.153.667v.004c.007.134.006.2-.002.266v.08c-.03.007-.056.018-.083.024-.152.055-.274.135-.393.2.012-.09.013-.18.003-.267v-.015c-.012-.133-.04-.2-.082-.333a.613.613 0 00-.166-.267.248.248 0 00-.183-.064h-.021c-.071.006-.13.04-.186.132a.552.552 0 00-.12.27.944.944 0 00-.023.33v.015c.012.135.037.2.08.334.046.134.098.2.166.268.01.009.02.018.034.024-.07.057-.117.07-.176.136a.304.304 0 01-.131.068 2.62 2.62 0 01-.275-.402 1.772 1.772 0 01-.155-.667 1.759 1.759 0 01.08-.668 1.43 1.43 0 01.283-.535c.128-.133.26-.2.418-.2zm1.37 1.706c.332 0 .733.065 1.216.399.293.2.523.269 1.052.468h.003c.255.136.405.266.478.399v-.131a.571.571 0 01.016.47c-.123.31-.516.643-1.063.842v.002c-.268.135-.501.333-.775.465-.276.135-.588.292-1.012.267a1.139 1.139 0 01-.448-.067 3.566 3.566 0 01-.322-.198c-.195-.135-.363-.332-.612-.465v-.005h-.005c-.4-.246-.616-.512-.686-.71-.07-.268-.005-.47.193-.6.224-.135.38-.271.483-.336.104-.074.143-.102.176-.131h.002v-.003c.169-.202.436-.47.839-.601.139-.036.294-.065.466-.065zm2.8 2.142c.358 1.417 1.196 3.475 1.735 4.473.286.534.855 1.659 1.102 3.024.156-.005.33.018.513.064.646-1.671-.546-3.467-1.089-3.966-.22-.2-.232-.335-.123-.335.59.534 1.365 1.572 1.646 2.757.13.535.16 1.104.021 1.67.067.028.135.06.205.067 1.032.534 1.413.938 1.23 1.537v-.043c-.06-.003-.12 0-.18 0h-.016c.151-.467-.182-.825-1.065-1.224-.915-.4-1.646-.336-1.77.465-.008.043-.013.066-.018.135-.068.023-.139.053-.209.064-.43.268-.662.669-.793 1.187-.13.533-.17 1.156-.205 1.869v.003c-.02.334-.17.838-.319 1.35-1.5 1.072-3.58 1.538-5.348.334a2.645 2.645 0 00-.402-.533 1.45 1.45 0 00-.275-.333c.182 0 .338-.03.465-.067a.615.615 0 00.314-.334c.108-.267 0-.697-.345-1.163-.345-.467-.931-.995-1.788-1.521-.63-.4-.986-.87-1.15-1.396-.165-.534-.143-1.085-.015-1.645.245-1.07.873-2.11 1.274-2.763.107-.065.037.135-.408.974-.396.751-1.14 2.497-.122 3.854a8.123 8.123 0 01.647-2.876c.564-1.278 1.743-3.504 1.836-5.268.048.036.217.135.289.202.218.133.38.333.59.465.21.201.477.335.876.335.039.003.075.006.11.006.412 0 .73-.134.997-.268.29-.134.52-.334.74-.4h.005c.467-.135.835-.402 1.044-.7zm2.185 8.958c.037.6.343 1.245.882 1.377.588.134 1.434-.333 1.791-.765l.211-.01c.315-.007.577.01.847.268l.003.003c.208.199.305.53.391.876.085.4.154.78.409 1.066.486.527.645.906.636 1.14l.003-.007v.018l-.003-.012c-.015.262-.185.396-.498.595-.63.401-1.746.712-2.457 1.57-.618.737-1.37 1.14-2.036 1.191-.664.053-1.237-.2-1.574-.898l-.005-.003c-.21-.4-.12-1.025.056-1.69.176-.668.428-1.344.463-1.897.037-.714.076-1.335.195-1.814.12-.465.308-.797.641-.984l.045-.022zm-10.814.049h.01c.053 0 .105.005.157.014.376.055.706.333 1.023.752l.91 1.664.003.003c.243.533.754 1.064 1.189 1.637.434.598.77 1.131.729 1.57v.006c-.057.744-.48 1.148-1.125 1.294-.645.135-1.52.002-2.395-.464-.968-.536-2.118-.469-2.857-.602-.369-.066-.61-.2-.723-.4-.11-.2-.113-.602.123-1.23v-.004l.002-.003c.117-.334.03-.752-.027-1.118-.055-.401-.083-.71.043-.94.16-.334.396-.4.69-.533.294-.135.64-.202.915-.47h.002v-.002c.256-.268.445-.601.668-.838.19-.201.38-.336.663-.336zm7.159-9.074c-.435.201-.945.535-1.488.535-.542 0-.97-.267-1.28-.466-.154-.134-.28-.268-.373-.335-.164-.134-.144-.333-.074-.333.109.016.129.134.199.2.096.066.215.2.36.333.292.2.68.467 1.167.467.485 0 1.053-.267 1.398-.466.195-.135.445-.334.648-.467.156-.136.149-.267.279-.267.128.016.034.134-.147.332a8.097 8.097 0 01-.69.468zm-1.082-1.583V5.64c-.006-.02.013-.042.029-.05.074-.043.18-.027.26.004.063 0 .16.067.15.135-.006.049-.085.066-.135.066-.055 0-.092-.043-.141-.068-.052-.018-.146-.008-.163-.065zm-.551 0c-.02.058-.113.049-.166.066-.047.025-.086.068-.14.068-.05 0-.13-.02-.136-.068-.01-.066.088-.133.15-.133.08-.031.184-.047.259-.005.019.009.036.03.03.05v.02h.003z',
16
+ // A compass: Safari.
17
+ safari: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm0 1.5a8.5 8.5 0 1 1 0 17 8.5 8.5 0 0 1 0-17zm5.3 3.2-6.7 4.1-4.1 6.7 6.7-4.1 4.1-6.7zm-6.1 5.5a1 1 0 1 1 1.6 1.6 1 1 0 0 1-1.6-1.6z',
18
+ // A swept "e": Edge.
19
+ edge: 'M21.5 12.7c0-5.4-4.1-9.3-9.5-9.3C6.5 3.4 2.6 7.1 2.5 12.2c.4-3.7 3.5-6 7.4-6 3.2 0 5.6 1.6 5.6 4.1 0 1.4-.8 2.3-2.1 3-.9.5-1.4 1.1-1.4 1.8 0 1.4 1.5 2.3 3.6 2.3 1.8 0 3.5-.5 4.9-1.4-.6 3-3.6 5.3-7.4 5.3-5.1 0-8.9-3.5-9.2-8.4.2 5.6 4.6 9.7 10.2 9.7 3.1 0 5.8-1.2 7.3-3.4-1.1.5-2.4.7-3.6.7-2.8 0-4.6-1.3-4.6-3.1 0-1.1.6-1.8 1.7-2.4 1.6-.9 2.6-1.9 2.6-3.6 0-3.2-3-5.3-7-5.3-1.1 0-2.2.2-3.2.5 1.7-1.3 3.9-2 6.4-2 5 0 8.7 3.3 8.7 8.1z',
20
+ // Four panes: Windows.
21
+ windows: 'M3 5.5 11 4.4v7.1H3V5.5zm9-1.3L21 3v8.5h-9V4.2zM3 12.5h8v7.1L3 18.5v-6zm9 0h9V21l-9-1.2v-7.3z',
22
+ // A globe: a browser we do not know.
23
+ globe: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm6.9 9.2h-3.4a15.6 15.6 0 0 0-1.3-6 8.5 8.5 0 0 1 4.7 6zM12 3.6c1 1.2 2.1 3.4 2.3 7.6H9.7c.2-4.2 1.3-6.4 2.3-7.6zM9.8 5.2a15.6 15.6 0 0 0-1.3 6H5.1a8.5 8.5 0 0 1 4.7-6zM5.1 12.8h3.4c.1 2.3.6 4.4 1.3 6a8.5 8.5 0 0 1-4.7-6zm6.9 7.6c-1-1.2-2.1-3.4-2.3-7.6h4.6c-.2 4.2-1.3 6.4-2.3 7.6zm2.2-1.6c.7-1.6 1.2-3.7 1.3-6h3.4a8.5 8.5 0 0 1-4.7 6z',
24
+ // A monitor: a system we do not know.
25
+ monitor: 'M3 4.5h18a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1h-7v1.5h3v1.5H7V19h3v-1.5H3a1 1 0 0 1-1-1v-11a1 1 0 0 1 1-1zm.5 1.5v10h17V6h-17z',
26
+ };
27
+
28
+ /** The icon's key for a browser name from `parseUserAgent`. */
29
+ export function browserIcon(browser: string): string {
30
+ const key = browser.toLowerCase();
31
+ return key in PATHS && ['chrome', 'firefox', 'safari', 'edge', 'opera'].includes(key) ? key : 'globe';
32
+ }
33
+
34
+ /** The icon's key for an operating system name from `parseUserAgent`. */
35
+ export function osIcon(os: string): string {
36
+ const key = os.toLowerCase();
37
+ if (key === 'macos' || key === 'ios') return 'apple';
38
+ return ['windows', 'android', 'linux'].includes(key) ? key : 'monitor';
39
+ }
40
+
41
+ /** One glyph with the name as its accessible label and tooltip. */
42
+ export function agentIcon(key: string, label: string, size = 16): TemplateResult {
43
+ return html`<span class="inline-flex shrink-0 items-center justify-center text-muted-foreground" role="img" aria-label=${label} title=${label}><svg viewBox="0 0 24 24" width=${size} height=${size} fill="currentColor" aria-hidden="true"><path d=${PATHS[key] ?? PATHS.globe!}></path></svg></span>`;
44
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Application passwords: tokens that apps and scripts send to the content API as
3
+ * `Authorization: Bearer`, acting as their user with the user's roles. Shared by Profile →
4
+ * Security and the user screen; the page owns the list and the new password, shown once.
5
+ */
6
+ import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
7
+ import { Badge, Button, Field, Input, NativeSelect } from '@cossackframework/ui';
8
+ import { html, component } from '@cossackframework/renderer';
9
+ import type { ApiToken } from '../auth';
10
+
11
+ export type AppPasswordsProps = {
12
+ tokens: ApiToken[];
13
+ /** The password just created; it is shown once. */
14
+ newToken: string;
15
+ /** Resolves to false when the password was not created, keeping the form. */
16
+ /** `expiresInDays` is 0 for a password that never expires. */
17
+ onAdd(name: string, scope: 'read' | 'write', expiresInDays: number): unknown;
18
+ onRevoke(id: string): unknown;
19
+ };
20
+
21
+ const date = (value: number | null) => value ? new Date(value).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : '—';
22
+
23
+ @Component()
24
+ export class AppPasswords extends Cossack {
25
+ declare props: AppPasswordsProps;
26
+ @ClientState() private name = '';
27
+ @ClientState() private scope: 'read' | 'write' = 'write';
28
+ /** Days until the password expires, as the select's value; '0' is never. */
29
+ @ClientState() private expires = '0';
30
+ /** Whether Copy worked: the button says so, or the box asks to copy by hand. */
31
+ @ClientState() private copied: 'yes' | 'no' | '' = '';
32
+
33
+ @Client()
34
+ private async submit(event: Event) {
35
+ event.preventDefault();
36
+ const name = this.name.trim();
37
+ if (!name) return;
38
+ if ((await this.props.onAdd(name, this.scope, Number(this.expires))) === false) return;
39
+ this.name = '';
40
+ this.scope = 'write';
41
+ this.expires = '0';
42
+ }
43
+
44
+ @Client()
45
+ private async copy() {
46
+ try { await navigator.clipboard.writeText(this.props.newToken); this.copied = 'yes'; }
47
+ catch { this.copied = 'no'; }
48
+ }
49
+
50
+ render() {
51
+ return html`<div class="space-y-4">
52
+ ${this.props.newToken ? html`<div class="space-y-2 rounded-md border border-emerald-500/40 bg-emerald-500/5 p-3">
53
+ <p class="text-sm font-medium text-foreground">${__('Copy the new application password now. You will not see it again.')}</p>
54
+ <div class="flex gap-2"><input readonly class="w-full rounded-md border border-input bg-background px-3 py-1.5 font-mono text-xs" aria-label=${__('New application password')} .value=${this.props.newToken} data-new-token>
55
+ ${component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.copy() }, this.copied === 'yes' ? __('Copied.') : __('Copy'))}</div>
56
+ ${this.copied === 'no' ? html`<p role="alert" class="text-xs text-destructive">${__('Copy it from the box.')}</p>` : null}
57
+ </div>` : null}
58
+ <form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => this.submit(event)}>
59
+ ${component(Field, { label: __('Name'), for: 'token-name', control: attributes => component(Input, { ...attributes, required: true, maxlength: 80, placeholder: __('Such as Mobile app'),
60
+ '.value': this.name, '@input': (event: Event) => { this.name = (event.target as HTMLInputElement).value; } }) })}
61
+ ${component(Field, { label: __('Access'), for: 'token-scope', control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => { this.scope = (event.target as HTMLSelectElement).value === 'read' ? 'read' : 'write'; } }, html`
62
+ <option value="write" ?selected=${this.scope === 'write'}>${__('Read and write')}</option><option value="read" ?selected=${this.scope === 'read'}>${__('Read only')}</option>`) })}
63
+ ${component(Field, { label: __('Expires'), for: 'token-expires', control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => { this.expires = (event.target as HTMLSelectElement).value; } }, html`
64
+ ${[['0', __('Never')], ['30', __('In 30 days')], ['90', __('In 90 days')], ['365', __('In a year')]].map(([value, label]) => html`<option value=${value} ?selected=${this.expires === value}>${label}</option>`)}`) })}
65
+ ${component(Button, { type: 'submit', disabled: !this.name.trim() }, __('Add application password'))}
66
+ </form>
67
+ ${this.props.tokens.length ? html`<ul class="divide-y divide-border rounded-md border border-border">${this.props.tokens.map(token => html`<li class="flex flex-wrap items-center justify-between gap-2 px-3 py-2 text-sm" data-token=${token.name}>
68
+ <span><span class="font-medium text-foreground">${token.name}</span> ${component(Badge, { variant: 'secondary' }, token.scope === 'read' ? __('Read only') : __('Read and write'))}
69
+ <span class="block text-xs text-muted-foreground">${__('created')} ${date(token.createdAt)} · ${__('last used')} ${date(token.lastUsedAt)}${token.expiresAt ? ` · ${__('expires')} ${date(token.expiresAt)}` : ''}</span></span>
70
+ <button type="button" class="text-xs text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.props.onRevoke(token.id)}>${__('Revoke')}</button>
71
+ </li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('No application passwords yet.')}</p>`}
72
+ </div>`;
73
+ }
74
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The avatar control of the profile and user screens: a preview with Upload and Remove when
3
+ * the auth store keeps files (the CMS keeps them in its media library), otherwise an image URL
4
+ * with a live preview. Clicking the picture opens the file dialog too.
5
+ */
6
+ import { html, component, type TemplateResult } from '@cossackframework/renderer';
7
+ import { Avatar, Button, Field, Input } from '@cossackframework/ui';
8
+
9
+ /** Still and animated images: animated GIF, APNG, WebP and AVIF play in the preview too. */
10
+ export const AVATAR_ACCEPT = 'image/png,image/jpeg,image/gif,image/webp,image/avif';
11
+
12
+ export interface AvatarFieldOptions {
13
+ id: string;
14
+ value: string;
15
+ /** Alternative text: the user's name. */
16
+ name: string;
17
+ uploads: boolean;
18
+ uploading: boolean;
19
+ error?: string;
20
+ onFile(file: File): void;
21
+ onUrl(url: string): void;
22
+ onRemove(): void;
23
+ }
24
+
25
+ export function avatarField(options: AvatarFieldOptions): TemplateResult {
26
+ const preview = component(Avatar, { src: options.value || undefined, alt: options.name, size: 72 });
27
+ if (!options.uploads) {
28
+ return html`<div class="flex items-start gap-4">${preview}<div class="flex-1">
29
+ ${component(Field, { label: __('Avatar URL'), for: options.id, hint: __('A link to a picture.'), ...(options.error ? { error: options.error } : {}),
30
+ control: attributes => component(Input, { ...attributes, type: 'url', placeholder: 'https://...', '.value': options.value,
31
+ '@input': (event: Event) => options.onUrl((event.target as HTMLInputElement).value) }) })}
32
+ </div></div>`;
33
+ }
34
+ return html`<div class="space-y-2">
35
+ <span class="block text-sm font-medium text-foreground">${__('Avatar')}</span>
36
+ <div class="flex items-center gap-4">
37
+ <label for=${options.id} title=${options.value ? __('Change picture') : __('Upload picture')}
38
+ class=${`shrink-0 rounded-full transition-opacity hover:opacity-80 ${options.uploading ? 'pointer-events-none opacity-60' : 'cursor-pointer'}`}>${preview}</label>
39
+ <div class="space-y-2">
40
+ <div class="flex flex-wrap items-center gap-2">
41
+ <label class=${`inline-flex cursor-pointer items-center rounded-md border border-border px-3 py-1.5 text-sm font-medium text-foreground hover:bg-muted focus-within:ring-2 focus-within:ring-ring ${options.uploading ? 'pointer-events-none opacity-60' : ''}`}>
42
+ ${options.uploading ? __('Uploading…') : options.value ? __('Change picture') : __('Upload picture')}
43
+ <input id=${options.id} type="file" accept=${AVATAR_ACCEPT} class="sr-only" ?disabled=${options.uploading}
44
+ @change=${(event: Event) => {
45
+ const input = event.currentTarget as HTMLInputElement;
46
+ const file = input.files?.[0];
47
+ input.value = '';
48
+ if (file) options.onFile(file);
49
+ }}>
50
+ </label>
51
+ ${options.value && !options.uploading ? component(Button, { type: 'button', variant: 'ghost', size: 'sm', '@click': () => options.onRemove() }, __('Remove')) : null}
52
+ </div>
53
+ <p class="text-xs text-muted-foreground">${__('PNG, JPEG, GIF, WebP or AVIF, still or animated, up to 5 MB.')}</p>
54
+ ${options.error ? html`<p role="alert" class="text-xs text-destructive">${options.error}</p>` : null}
55
+ </div>
56
+ </div>
57
+ </div>`;
58
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Selection and bulk actions shared by the dashboard's lists (entries, users, forms): row and
3
+ * "select all" checkboxes, and the Bulk actions select with its Apply button.
4
+ */
5
+ import { component, html, type TemplateResult } from '@cossackframework/renderer';
6
+ import { Button, Checkbox, NativeSelect } from '@cossackframework/ui';
7
+
8
+ /** A bulk action of a list; `confirm` asks first with that text. */
9
+ export interface BulkChoice {
10
+ key: string;
11
+ label: string;
12
+ confirm?: string;
13
+ }
14
+
15
+ /** The selection after a row's checkbox changes. */
16
+ export function toggleSelected(selected: readonly string[], id: string, checked: boolean): string[] {
17
+ return checked ? [...new Set([...selected, id])] : selected.filter(entry => entry !== id);
18
+ }
19
+
20
+ /** The "select all" checkbox of a table's header, over the rows that can be selected. */
21
+ export function selectAllBox(ids: readonly string[], selected: readonly string[], change: (ids: string[]) => void): TemplateResult {
22
+ const all = ids.length > 0 && ids.every(id => selected.includes(id));
23
+ return component(Checkbox, { checked: all, indeterminate: !all && ids.some(id => selected.includes(id)), disabled: ids.length === 0, 'aria-label': __('Select all'),
24
+ '@change': (event: Event) => change((event.target as HTMLInputElement).checked ? [...ids] : []) });
25
+ }
26
+
27
+ /** A row's checkbox; `label` names the row for assistive technology. */
28
+ export function selectBox(id: string, label: string, selected: readonly string[], change: (ids: string[]) => void): TemplateResult {
29
+ return component(Checkbox, { checked: selected.includes(id), 'aria-label': `${__('Select')} ${label}`,
30
+ '@change': (event: Event) => change(toggleSelected(selected, id, (event.target as HTMLInputElement).checked)) });
31
+ }
32
+
33
+ export interface BulkBarOptions {
34
+ /** Distinct per bar, such as `bulk-top` and `bulk-bottom`. */
35
+ id: string;
36
+ choices: readonly BulkChoice[];
37
+ /** The chosen action's key; empty for none. */
38
+ value: string;
39
+ count: number;
40
+ choose(key: string): void;
41
+ apply(): void;
42
+ }
43
+
44
+ /** The Bulk actions select, its Apply button and how many rows are selected. */
45
+ export function bulkBar(options: BulkBarOptions): TemplateResult {
46
+ return html`<div class="flex flex-wrap items-center gap-2" data-bulk-bar>
47
+ <div class="w-44">${component(NativeSelect, { id: options.id, size: 'sm', 'aria-label': __('Bulk actions'), '@change': (event: Event) => options.choose((event.target as HTMLSelectElement).value) }, html`
48
+ <option value="" ?selected=${!options.value}>${__('Bulk actions')}</option>
49
+ ${options.choices.map(choice => html`<option value=${choice.key} ?selected=${options.value === choice.key}>${choice.label}</option>`)}`)}</div>
50
+ ${component(Button, { type: 'button', size: 'sm', variant: 'outline', disabled: !options.value || !options.count, '@click': () => options.apply() }, __('Apply'))}
51
+ ${options.count ? html`<span class="text-xs text-muted-foreground">${options.count} ${__('selected')}</span>` : null}
52
+ </div>`;
53
+ }