@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.
Files changed (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -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 +114 -2
  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,193 @@
1
+ import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
+ import { input } from '@cossackframework/core/input';
3
+ import { AlertDialog, Button, Card, CardBody, CardHeader, Checkbox, Field, Input, NativeSelect, Textarea } from '@cossackframework/ui';
4
+ import { html, component, type TemplateResult } from '@cossackframework/renderer';
5
+ import { CORE_FIELDS, isCmsError, PERMISSIONS, type Block, type FieldGroup, type FieldGroupTarget } from '@cossackframework/cms';
6
+ import { collectionName } from '#app/cms/builder';
7
+ import { blockOptions } from '#app/cms/content';
8
+ import { blocksInput, editorBlocks, type BlockOption, type EditorBlock } from '#app/cms/editor';
9
+ import { FieldGroupEditor } from '#app/cms/field-group-editor';
10
+ import { describeBlockError } from '#app/cms/block-errors';
11
+ import { requireAny } from '#app/cms/guards';
12
+ import { notice, pageHeader } from '#app/cms/ui';
13
+
14
+ interface Draft { id: string; title: string; description: string; placement: 'main' | 'sidebar'; order: string }
15
+ interface TargetChoice { kind: FieldGroupTarget['kind']; name: string; label: string }
16
+
17
+ /**
18
+ * Edit a field group, or make one at `/new`: its title, where its box shows, the targets it
19
+ * is attached to, and its fields laid out in the block tree, all in one step. Saving plans
20
+ * the targets' indexes; entries keep values of fields that are removed.
21
+ */
22
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageCollections)] })
23
+ export default class FieldGroupPage extends Cossack {
24
+ @State() draft: Draft | null = null;
25
+ @State() targets: FieldGroupTarget[] = [];
26
+ @State() choices: TargetChoice[] = [];
27
+ @State() blocks: EditorBlock[] = [];
28
+ @State() options: BlockOption[] = [];
29
+ @State() message = '';
30
+ @State() error = '';
31
+ @State() confirmDelete = false;
32
+
33
+ /** True until the group is saved for the first time. */
34
+ @State() fresh = false;
35
+ /** The plugin the group comes from; such a group is read-only here. */
36
+ @State() plugin = '';
37
+
38
+ head(): HeadValue {
39
+ return { title: this.fresh ? __('New field group') : this.draft ? `${this.draft.title} — ${__('Field group')}` : __('Field group') };
40
+ }
41
+
42
+ async init() {
43
+ await this.load(this.c.req.param('id') ?? 'new');
44
+ if (this.c.req.query('created') === '1') this.message = __('Field group created.');
45
+ }
46
+
47
+ @Server()
48
+ async load(id: string) {
49
+ const cms = this.c.get('cms');
50
+ this.fresh = id === 'new';
51
+ // A new group starts empty, attached to the collection the collection manager came from.
52
+ const collection = this.fresh ? this.c.req.query('collection') ?? '' : '';
53
+ const group = this.fresh
54
+ ? { id: '', title: '', description: '', placement: 'main' as const, order: undefined, blocks: [] as Block[],
55
+ targets: collection && cms.collections().some(entry => entry.name === collection && !entry.managed) ? [{ kind: 'collection' as const, name: collection }] : [] }
56
+ : await cms.fieldGroups.get(id);
57
+ if (!group) { this.error = __('This field group does not exist.'); this.c.status(404); return; }
58
+ this.draft = { id: group.id, title: group.title, description: group.description ?? '', placement: group.placement ?? 'main', order: group.order === undefined ? '' : String(group.order) };
59
+ this.plugin = group.plugin ?? '';
60
+ this.targets = [...group.targets];
61
+ this.choices = [
62
+ ...cms.collections().filter(collection => !collection.managed).map(collection => ({ kind: 'collection' as const, name: collection.name, label: collection.label })),
63
+ ...cms.taxonomies.declarations.map(taxonomy => ({ kind: 'taxonomy' as const, name: taxonomy.name, label: taxonomy.label })),
64
+ { kind: 'users', name: '', label: __('Users') }, { kind: 'menus', name: '', label: __('Menu items') },
65
+ ];
66
+ this.options = await blockOptions(cms);
67
+ this.blocks = editorBlocks(group.blocks as EditorBlock[], this.options);
68
+ }
69
+
70
+ @Client()
71
+ setDraft<K extends keyof Draft>(key: K, value: Draft[K]) {
72
+ if (this.draft) this.draft = { ...this.draft, [key]: value };
73
+ }
74
+
75
+ @Client()
76
+ toggleTarget(choice: TargetChoice, checked: boolean) {
77
+ const target: FieldGroupTarget = choice.kind === 'collection' || choice.kind === 'taxonomy' ? { kind: choice.kind, name: choice.name } : { kind: choice.kind };
78
+ const same = (entry: FieldGroupTarget) => entry.kind === target.kind && ('name' in entry ? entry.name : '') === choice.name;
79
+ // A target already there keeps its place among the target's boxes.
80
+ if (checked && this.targets.some(same)) return;
81
+ this.targets = checked ? [...this.targets, target] : this.targets.filter(entry => !same(entry));
82
+ }
83
+
84
+ @Client()
85
+ private changeBlocks(blocks: EditorBlock[]) {
86
+ this.blocks = blocks;
87
+ }
88
+
89
+ @Client()
90
+ async submit() {
91
+ if (!this.draft) return;
92
+ await this.save(this.draft, this.targets, this.blocks);
93
+ }
94
+
95
+ @Server({ input: input.args(input.object({
96
+ id: input.string({ maxLength: 200 }), title: input.string({ maxLength: 500 }), description: input.string({ maxLength: 5000 }),
97
+ placement: input.enum(['main', 'sidebar']), order: input.string({ maxLength: 20 }),
98
+ }), input.array(input.record<FieldGroupTarget>(), { maxItems: 1000 }), input.array(input.record<EditorBlock>(), { maxItems: 1000 })) })
99
+ async save(draft: Draft, targets: FieldGroupTarget[], blocks: EditorBlock[]) {
100
+ this.error = '';
101
+ this.message = '';
102
+ const options = await blockOptions(this.c.get('cms'));
103
+ const converted = blocksInput(blocks, new Map(options.map(option => [option.name, option])));
104
+ if ('error' in converted) { this.error = `${__('Fields')}: ${converted.error}`; return; }
105
+ const order = draft.order.trim() === '' ? undefined : Number(draft.order);
106
+ // The group the URL names; a new group's ID comes from its title.
107
+ const route = this.c.req.param('id') ?? '';
108
+ const fresh = route === 'new';
109
+ const id = fresh ? collectionName(draft.title).replaceAll('_', '-') : route;
110
+ if (!id) { this.error = __('Give the field group a title.'); return; }
111
+ const group: FieldGroup = {
112
+ id, title: draft.title.trim(), description: draft.description.trim(), placement: draft.placement,
113
+ ...(order !== undefined && Number.isSafeInteger(order) ? { order } : {}), targets, blocks: converted.value as Block[],
114
+ };
115
+ try {
116
+ const saved = await this.c.get('cms').saveFieldGroup(group, this.c.get('principal'));
117
+ if (fresh) return this.redirect(`/dashboard/field-groups/${saved.id}?created=1`);
118
+ await this.load(saved.id);
119
+ this.message = __('Field group saved.');
120
+ } catch (error) {
121
+ this.error = isCmsError(error) ? error.message : __('The field group could not be saved.');
122
+ }
123
+ }
124
+
125
+ @Server()
126
+ async remove() {
127
+ try {
128
+ await this.c.get('cms').deleteFieldGroup(this.c.req.param('id') ?? '', this.c.get('principal'));
129
+ return this.redirect('/dashboard/field-groups');
130
+ } catch (error) {
131
+ this.error = isCmsError(error) ? error.message : __('The field group could not be deleted.');
132
+ }
133
+ }
134
+
135
+ private check(choice: TargetChoice): TemplateResult {
136
+ const checked = this.targets.some(entry => entry.kind === choice.kind && ('name' in entry ? entry.name : '') === choice.name);
137
+ return html`<div>${component(Checkbox, { label: choice.label, checked, '@change': (event: Event) => this.toggleTarget(choice, (event.target as HTMLInputElement).checked) })}</div>`;
138
+ }
139
+
140
+ render() {
141
+ const draft = this.draft;
142
+ if (!draft) return notice(this.error || __('This field group does not exist.'), 'error');
143
+ // Conditions may test what every target has: an entry's core fields are the common ground.
144
+ const scope = CORE_FIELDS.map(name => ({ name, label: name }));
145
+ return html`<div class="space-y-6">
146
+ ${pageHeader(this.fresh ? __('New field group') : draft.title, {
147
+ description: this.fresh ? __('A box of fields for editors. Lay its fields out and choose where it shows.') : `${__('Field group')} ${draft.id}`,
148
+ actions: html`<a href="/dashboard/field-groups" class="text-sm text-muted-foreground hover:text-foreground">← ${__('Field groups')}</a>
149
+ ${component(Button, { type: 'button', disabled: Boolean(this.plugin) || (this.fresh && !collectionName(draft.title)), '@click': () => this.submit() }, this.fresh ? __('Create field group') : __('Save field group'))}`,
150
+ })}
151
+ ${this.message ? notice(this.message, 'success') : null}
152
+ ${this.plugin ? notice(`${__('This group comes from the plugin')} ${this.plugin}. ${__('It is changed in the plugin\'s manifest and goes with the plugin.')}`, 'info') : null}
153
+ ${this.error ? notice(describeBlockError(this.error, this.blocks, this.options), 'error') : null}
154
+ <div class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]">
155
+ ${component(Card, {}, html`
156
+ ${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Fields')}</h2>
157
+ <p class="text-sm text-muted-foreground">${__('Field blocks between columns, tabs, headings and notes, as the box should show them. A repeater holds rows of fields. Conditional logic shows a field on the values of the others.')}</p>`)}
158
+ ${component(CardBody, {}, component(FieldGroupEditor, { id: 'group', blocks: this.blocks, options: this.options, scope, error: this.error, onChange: (blocks: EditorBlock[]) => this.changeBlocks(blocks) }))}
159
+ `)}
160
+ <aside class="space-y-6">
161
+ ${component(Card, {}, component(CardBody, { class: 'space-y-4' }, html`
162
+ <h2 class="text-base font-semibold text-foreground">${__('Settings')}</h2>
163
+ ${component(Field, { label: __('Title'), for: 'group-title', ...(this.fresh ? { hint: draft.title ? `${__('Stored as')} ${collectionName(draft.title).replaceAll('_', '-') || '…'}` : __('Such as Product details.') } : {}),
164
+ control: attributes => component(Input, { ...attributes, '.value': draft.title, '@input': (event: Event) => this.setDraft('title', (event.target as HTMLInputElement).value) }) })}
165
+ ${component(Field, { label: __('Description'), for: 'group-description', hint: __('Shown under the box\'s title.'),
166
+ control: attributes => component(Textarea, { ...attributes, rows: 2, '.value': draft.description, '@input': (event: Event) => this.setDraft('description', (event.target as HTMLTextAreaElement).value) }) })}
167
+ ${component(Field, { label: __('Default placement'), for: 'group-placement', hint: __('Where the box starts in an entry editor; the collection manager\'s Editor tab moves it. Terms, users and menu items have one column.'),
168
+ control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.setDraft('placement', (event.target as HTMLSelectElement).value as Draft['placement']) }, html`
169
+ <option value="main" ?selected=${draft.placement === 'main'}>${__('Main column')}</option>
170
+ <option value="sidebar" ?selected=${draft.placement === 'sidebar'}>${__('Sidebar')}</option>`) })}
171
+ ${component(Field, { label: __('Order'), for: 'group-order', hint: __('Boxes of one place show in ascending order.'),
172
+ control: attributes => component(Input, { ...attributes, type: 'number', '.value': draft.order, '@input': (event: Event) => this.setDraft('order', (event.target as HTMLInputElement).value) }) })}
173
+ `))}
174
+ ${component(Card, {}, component(CardBody, { class: 'space-y-3' }, html`
175
+ <h2 class="text-base font-semibold text-foreground">${__('Shown on')}</h2>
176
+ ${this.choices.map(choice => this.check(choice))}
177
+ `))}
178
+ ${this.fresh ? null : component(Card, {}, component(CardBody, { class: 'space-y-3' }, html`
179
+ <h2 class="text-base font-semibold text-destructive">${__('Delete field group')}</h2>
180
+ <p class="text-sm text-muted-foreground">${__('The box disappears from its editors. Values already stored stay in their entries until those are saved without them.')}</p>
181
+ ${component(Button, { type: 'button', variant: 'destructive', size: 'sm', '@click': () => { this.confirmDelete = true; } }, __('Delete field group'))}
182
+ `))}
183
+ </aside>
184
+ </div>
185
+ ${component(AlertDialog, {
186
+ id: 'delete-group-dialog', open: this.confirmDelete, title: `${__('Delete')} ${draft.title}?`,
187
+ description: __('The field group is removed from every editor it shows in. This cannot be undone.'),
188
+ cancelLabel: __('Cancel'), actionLabel: __('Delete'), actionVariant: 'destructive',
189
+ onAction: () => { this.confirmDelete = false; void this.remove(); }, onOpenChange: () => { this.confirmDelete = false; },
190
+ })}
191
+ </div>`;
192
+ }
193
+ }
@@ -0,0 +1,65 @@
1
+ import { Cossack, Page, State, type HeadValue } from '@cossackframework/core';
2
+ import { Badge, Card, CardBody } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { flattenGroupFields, PERMISSIONS, type FieldGroupTarget } from '@cossackframework/cms';
5
+ import { requireAny } from '#app/cms/guards';
6
+ import { linkButton, pageHeader } from '#app/cms/ui';
7
+
8
+ interface Row { id: string; title: string; description: string; placement: string; fields: number; targets: string[] }
9
+
10
+ /** Field groups: meta boxes of typed fields, laid out with blocks and attached to collections, taxonomies, users and menu items. */
11
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageCollections)] })
12
+ export default class FieldGroupsPage extends Cossack {
13
+ @State() rows: Row[] = [];
14
+
15
+ head(): HeadValue {
16
+ return { title: __('Field groups') };
17
+ }
18
+
19
+ async init() {
20
+ const cms = this.c.get('cms');
21
+ const labels = new Map<string, string>([
22
+ ...cms.collections().map(collection => [`collection:${collection.name}`, collection.label] as const),
23
+ ...cms.taxonomies.declarations.map(taxonomy => [`taxonomy:${taxonomy.name}`, taxonomy.label] as const),
24
+ ]);
25
+ const label = (target: FieldGroupTarget) => target.kind === 'users' ? __('Users') : target.kind === 'menus' ? __('Menu items') : 'name' in target ? labels.get(`${target.kind}:${target.name}`) ?? target.name : target.kind;
26
+ this.rows = (await cms.fieldGroups.all()).map(group => ({
27
+ id: group.id, title: group.title, description: group.description ?? '', placement: group.placement ?? 'main',
28
+ fields: flattenGroupFields(group.blocks).length, targets: group.targets.map(label),
29
+ }));
30
+ }
31
+
32
+ render() {
33
+ const th = 'px-3 py-2 font-medium';
34
+ const td = 'px-3 py-2';
35
+ return html`<div class="space-y-6">
36
+ ${pageHeader(__('Field groups'), {
37
+ description: __('Boxes of fields shown in editors: lay typed fields out with columns, tabs and headings, then attach the box to collections, taxonomies, users or menu items.'),
38
+ titleActions: linkButton(__('New field group'), '/dashboard/field-groups/new', 'primary', { size: 'sm' }),
39
+ })}
40
+ ${component(Card, {}, component(CardBody, { class: 'p-0' }, html`
41
+ <div class="overflow-x-auto">
42
+ <table class="w-full text-sm">
43
+ <thead><tr class="border-b border-border text-left text-xs uppercase tracking-wide text-muted-foreground">
44
+ <th class=${th}>${__('Title')}</th><th class=${th}>${__('Shown on')}</th><th class=${th}>${__('Placement')}</th><th class=${`${th} text-right`}>${__('Fields')}</th>
45
+ </tr></thead>
46
+ <tbody>${this.rows.map(row => html`<tr class="group border-b border-border last:border-0 align-top" data-field-group=${row.id}>
47
+ <td class=${td}>
48
+ <a href=${`/dashboard/field-groups/${row.id}`} class="font-medium text-foreground hover:text-primary no-underline">${row.title}</a>
49
+ ${row.description ? html`<p class="text-xs text-muted-foreground">${row.description}</p>` : null}
50
+ <div class="mt-1 flex flex-wrap items-center gap-2 text-xs opacity-80 group-hover:opacity-100">
51
+ <a href=${`/dashboard/field-groups/${row.id}`} class="text-primary hover:underline">${__('Edit')}</a>
52
+ <span aria-hidden="true" class="text-muted-foreground">|</span>
53
+ <code class="text-muted-foreground">${row.id}</code>
54
+ </div>
55
+ </td>
56
+ <td class=${`${td} text-muted-foreground`}>${row.targets.join(', ') || __('nothing yet')}</td>
57
+ <td class=${td}>${component(Badge, { variant: 'outline' }, row.placement === 'sidebar' ? __('Sidebar') : __('Main column'))}</td>
58
+ <td class=${`${td} text-right text-muted-foreground`}>${row.fields}</td>
59
+ </tr>`)}</tbody>
60
+ </table>
61
+ ${this.rows.length ? null : html`<p class="px-3 py-8 text-center text-sm text-muted-foreground">${__('No field groups yet. A field group holds a collection\'s fields as a box in its editor, and can show in several places at once.')}</p>`}
62
+ </div>`))}
63
+ </div>`;
64
+ }
65
+ }
@@ -0,0 +1,279 @@
1
+ import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
+ import { Badge, Button, Card, CardBody, Checkbox, Input, NativeSelect, Textarea } from '@cossackframework/ui';
3
+ import { html, component, type TemplateResult } from '@cossackframework/renderer';
4
+ import { displayValue, formatBytes, formatSiteDate, formFiles, isCmsError, isRows, PERMISSIONS, type FormField, type SubmissionShape, type SubmissionStatus } from '@cossackframework/cms';
5
+ import type { LoadedForm } from '@cossackframework/cms/server';
6
+ import { requireAny } from '#app/cms/guards';
7
+ import { notice, pageHeader } from '#app/cms/ui';
8
+
9
+ /** An answer; a repeater's rows as a table, one column per input of a row; a file upload's files as downloads. */
10
+ interface Answer { label: string; value: string; rows?: { columns: string[]; cells: string[][] }; files?: { name: string; size: string; url: string }[] }
11
+ interface View {
12
+ id: string;
13
+ status: SubmissionStatus;
14
+ answers: Answer[];
15
+ details: Answer[];
16
+ note: string;
17
+ /** The form's inputs and the answers as stored, for editing. */
18
+ inputs: FormField[];
19
+ values: Record<string, unknown>;
20
+ }
21
+
22
+ /**
23
+ * One submission: every answer, when and from where it came, who sent it, and a note for
24
+ * whoever handles it, and editing of the answers. Opening a new submission marks it read.
25
+ * Needs `cms:submissions`.
26
+ */
27
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSubmissions)] })
28
+ export default class SubmissionPage extends Cossack {
29
+ @State() form: { id: string; title: string } | null = null;
30
+ @State() view: View | null = null;
31
+ @State() note = '';
32
+ @State() error = '';
33
+ /** What the last save did. */
34
+ @State() message = '';
35
+ @State() editing = false;
36
+ /** The answers being edited, as the form would post them. */
37
+ @State() draft: Record<string, unknown> = {};
38
+ @State() errors: Record<string, string> = {};
39
+
40
+ head(): HeadValue {
41
+ return { title: this.form ? `${__('Submission')}: ${this.form.title}` : __('Submission') };
42
+ }
43
+
44
+ async init() {
45
+ await this.load(true);
46
+ if (!this.view) this.c.status(404);
47
+ }
48
+
49
+ private async loaded(): Promise<LoadedForm | null> {
50
+ return this.c.get('cms').forms.get(this.c.req.param('id') ?? '');
51
+ }
52
+
53
+ @Server()
54
+ private async load(open = false) {
55
+ const cms = this.c.get('cms');
56
+ const principal = this.c.get('principal');
57
+ const form = await this.loaded();
58
+ this.form = form ? { id: form.ref.id, title: form.ref.title } : null;
59
+ let submission = form ? await cms.forms.submission(form, this.c.req.param('submission') ?? '', principal) : null;
60
+ if (!form || !submission) { this.view = null; return; }
61
+ if (open && submission.status === 'new') {
62
+ await cms.forms.setStatus(form, [submission.id], 'read', principal);
63
+ submission = { ...submission, status: 'read' };
64
+ }
65
+ this.view = await this.describe(form, submission);
66
+ this.note = submission.note;
67
+ }
68
+
69
+ private async describe(form: LoadedForm, submission: SubmissionShape): Promise<View> {
70
+ const cms = this.c.get('cms');
71
+ const settings = await cms.settings.all();
72
+ const user = submission.user ? await cms.users.get(submission.user) : null;
73
+ const meta = submission.meta;
74
+ const details: Answer[] = [
75
+ { label: __('Submitted'), value: formatSiteDate(submission.createdAt, settings, { time: settings['general.timeFormat'] }) },
76
+ ...(user ? [{ label: __('User'), value: `${user.name} <${user.email}>` }] : []),
77
+ ...(meta.page ? [{ label: __('Page'), value: meta.page }] : []),
78
+ ...(meta.referrer ? [{ label: __('Referrer'), value: meta.referrer }] : []),
79
+ ...(meta.ip ? [{ label: __('IP address'), value: meta.ip }] : []),
80
+ ...(meta.userAgent ? [{ label: __('Browser'), value: meta.userAgent }] : []),
81
+ ...(meta.locale ? [{ label: __('Language'), value: meta.locale }] : []),
82
+ { label: __('ID'), value: submission.id },
83
+ ];
84
+ return {
85
+ id: submission.id, status: submission.status, note: submission.note, details, inputs: [...form.ref.inputs], values: { ...submission.values },
86
+ answers: form.ref.inputs.map(input => {
87
+ const value = submission.values[input.name];
88
+ // A multiple input's values read one per line.
89
+ const answer: Answer = { label: input.label, value: input.multiple && Array.isArray(value) ? (value as readonly (string | number)[]).map(String).join('\n') : displayValue(input, value) };
90
+ if (input.kind === 'rows' && isRows(value)) answer.rows = { columns: input.inputs.map(child => child.label), cells: value.map(row => input.inputs.map(child => displayValue(child, row[child.name]))) };
91
+ // Files are private: they download through the submissions API, which checks the same permission as this screen.
92
+ if (input.kind === 'file') answer.files = formFiles(value).filter(file => file.id).map(file => ({
93
+ name: file.name, size: formatBytes(file.size), url: `/api/cms/forms/${form.ref.id}/submissions/${submission.id}/files/${file.id}`,
94
+ }));
95
+ return answer;
96
+ }),
97
+ };
98
+ }
99
+
100
+ @Server()
101
+ async setStatus(status: SubmissionStatus | 'delete') {
102
+ const cms = this.c.get('cms');
103
+ const form = await this.loaded();
104
+ // The submission the URL names, not the one the client's state shows.
105
+ const id = this.c.req.param('submission');
106
+ if (!form || !id) return;
107
+ this.error = '';
108
+ this.message = '';
109
+ try {
110
+ if (status === 'delete') {
111
+ await cms.forms.delete(form, [id], this.c.get('principal'));
112
+ return this.redirect(`/dashboard/forms/${form.ref.id}/submissions`);
113
+ }
114
+ await cms.forms.setStatus(form, [id], status, this.c.get('principal'));
115
+ } catch (error) { if (!isCmsError(error)) throw error; this.error = error.message; return; }
116
+ await this.load();
117
+ }
118
+
119
+ @Server()
120
+ async saveNote(note: string) {
121
+ const cms = this.c.get('cms');
122
+ const form = await this.loaded();
123
+ // The submission the URL names, not the one the client's state shows.
124
+ const id = this.c.req.param('submission');
125
+ if (!form || !id) return;
126
+ this.error = '';
127
+ try {
128
+ const saved = await cms.forms.setNote(form, id, note, this.c.get('principal'));
129
+ this.view = await this.describe(form, saved);
130
+ this.note = saved.note;
131
+ } catch (error) { if (!isCmsError(error)) throw error; this.error = error.message; }
132
+ }
133
+
134
+ @Server()
135
+ async saveValues(draft: Record<string, unknown>) {
136
+ const cms = this.c.get('cms');
137
+ const form = await this.loaded();
138
+ // The submission the URL names, not the one the client's state shows.
139
+ const id = this.c.req.param('submission');
140
+ if (!form || !id) return;
141
+ this.error = '';
142
+ this.errors = {};
143
+ try {
144
+ const saved = await cms.forms.setValues(form, id, draft, this.c.get('principal'));
145
+ this.view = await this.describe(form, saved);
146
+ this.editing = false;
147
+ } catch (error) {
148
+ if (!isCmsError(error)) throw error;
149
+ this.error = error.message;
150
+ this.errors = error.fields ? { ...error.fields } : {};
151
+ }
152
+ }
153
+
154
+ @Client()
155
+ startEditing() {
156
+ this.draft = { ...(this.view?.values ?? {}) };
157
+ this.errors = {};
158
+ this.editing = true;
159
+ }
160
+
161
+ @Client()
162
+ async submitValues(event: Event) {
163
+ event.preventDefault();
164
+ this.message = '';
165
+ await this.saveValues(this.draft);
166
+ if (!this.error) this.message = __('Answers saved.');
167
+ }
168
+
169
+ @Client()
170
+ private setAnswer(name: string, value: unknown) {
171
+ this.draft = { ...this.draft, [name]: value };
172
+ }
173
+
174
+ /** A control for one input, by its kind; a repeater's rows and a multiple input's items are edited as text. */
175
+ private control(input: FormField): TemplateResult {
176
+ const id = `answer-${input.name}`;
177
+ const value = this.draft[input.name];
178
+ const set = (next: unknown) => this.setAnswer(input.name, next);
179
+ const text = (event: Event) => set((event.target as HTMLInputElement | HTMLTextAreaElement).value);
180
+ if (input.kind === 'rows') {
181
+ // Rows as JSON: a list of objects, one per row, with the row inputs' values.
182
+ const json = typeof value === 'string' ? value : JSON.stringify(Array.isArray(value) ? value : [], null, 2);
183
+ return component(Textarea, { id, rows: 6, class: 'font-mono text-xs', '.value': json, '@input': (event: Event) => {
184
+ const raw = (event.target as HTMLTextAreaElement).value;
185
+ try { set(JSON.parse(raw)); } catch { set(raw); }
186
+ } });
187
+ }
188
+ if (input.kind === 'file') {
189
+ const files = formFiles(value);
190
+ return html`<p id=${id} class="text-sm text-muted-foreground">${files.length ? files.map(file => file.name).join(', ') : '—'} · ${__('Files stay as they were sent.')}</p>`;
191
+ }
192
+ if (input.multiple) {
193
+ const lines = Array.isArray(value) ? (value as unknown[]).map(String).join('\n') : typeof value === 'string' ? value : '';
194
+ return component(Textarea, { id, rows: 3, '.value': lines, '@input': (event: Event) => set((event.target as HTMLTextAreaElement).value.split('\n').map(line => line.trim()).filter(Boolean)) });
195
+ }
196
+ switch (input.kind) {
197
+ case 'boolean': return component(Checkbox, { id, label: input.label, checked: value === true, '@change': (event: Event) => set((event.target as HTMLInputElement).checked) });
198
+ case 'choice': return component(NativeSelect, { id, '@change': text }, html`<option value="" ?selected=${!value}>—</option>${input.options.map(option => html`<option value=${option.value} ?selected=${option.value === value}>${option.label}</option>`)}`);
199
+ case 'choices': {
200
+ const chosen = new Set(Array.isArray(value) ? (value as unknown[]).map(String) : []);
201
+ return html`<div class="space-y-1">${input.options.map(option => html`<label class="flex items-center gap-2 text-sm text-foreground cursor-pointer">
202
+ ${component(Checkbox, { checked: chosen.has(option.value), '@change': (event: Event) => { const next = new Set(chosen); if ((event.target as HTMLInputElement).checked) next.add(option.value); else next.delete(option.value); set([...next]); } })} ${option.label}</label>`)}</div>`;
203
+ }
204
+ case 'text': return component(Textarea, { id, rows: 4, '.value': String(value ?? ''), '@input': text });
205
+ case 'number': return component(Input, { id, type: 'number', '.value': value === undefined || value === null ? '' : String(value), '@input': text });
206
+ case 'date': return component(Input, { id, type: 'date', '.value': String(value ?? ''), '@input': text });
207
+ default: return component(Input, { id, type: input.kind === 'email' ? 'email' : input.kind === 'url' ? 'url' : input.kind === 'phone' ? 'tel' : 'text', '.value': String(value ?? ''), '@input': text });
208
+ }
209
+ }
210
+
211
+ private editor(view: View): TemplateResult {
212
+ return html`<form class="space-y-4 p-4" @submit=${(event: Event) => this.submitValues(event)}>
213
+ ${view.inputs.map(input => html`<div class="space-y-1.5">
214
+ ${input.kind === 'boolean' ? null : html`<label for=${`answer-${input.name}`} class="block text-sm font-medium text-foreground">${input.label}${input.required ? html`<span class="text-destructive"> *</span>` : null}</label>`}
215
+ ${this.control(input)}
216
+ ${this.errors[input.name] ? html`<p role="alert" class="text-xs text-destructive">${this.errors[input.name]}</p>` : null}
217
+ </div>`)}
218
+ ${Object.keys(this.errors).some(key => !view.inputs.some(input => input.name === key)) ? html`<ul role="alert" class="space-y-1 text-xs text-destructive">
219
+ ${Object.entries(this.errors).filter(([key]) => !view.inputs.some(input => input.name === key)).map(([key, message]) => html`<li><code>${key}</code> ${message}</li>`)}</ul>` : null}
220
+ <div class="flex flex-wrap gap-2">
221
+ ${component(Button, { type: 'submit', size: 'sm' }, __('Save answers'))}
222
+ ${component(Button, { type: 'button', size: 'sm', variant: 'ghost', '@click': () => { this.editing = false; this.errors = {}; } }, __('Cancel'))}
223
+ </div>
224
+ </form>`;
225
+ }
226
+
227
+ @Client()
228
+ async submitNote(event: Event) {
229
+ event.preventDefault();
230
+ this.message = '';
231
+ await this.saveNote(this.note);
232
+ if (!this.error) this.message = __('Note saved.');
233
+ }
234
+
235
+ private list(entries: readonly Answer[]): TemplateResult {
236
+ return html`<dl class="divide-y divide-border">${entries.map(entry => html`<div class="grid gap-1 px-4 py-3 sm:grid-cols-3">
237
+ <dt class="text-sm font-medium text-muted-foreground">${entry.label}</dt>
238
+ <dd class="whitespace-pre-wrap break-words text-sm text-foreground sm:col-span-2">${entry.files ? (entry.files.length ? html`<ul class="space-y-1 whitespace-normal">${entry.files.map(file => html`<li>
239
+ <a href=${file.url} download=${file.name} class="text-primary hover:underline">${file.name}</a> <span class="text-xs text-muted-foreground">${file.size}</span></li>`)}</ul>` : html`<span class="text-muted-foreground">—</span>`)
240
+ : entry.rows ? html`<span>${entry.value}</span>
241
+ <div class="mt-2 overflow-x-auto"><table class="w-full text-left text-xs"><thead><tr>${entry.rows.columns.map(column => html`<th class="border-b border-border px-2 py-1 font-medium text-muted-foreground">${column}</th>`)}</tr></thead>
242
+ <tbody>${entry.rows.cells.map(cells => html`<tr>${cells.map(cell => html`<td class="border-b border-border px-2 py-1 align-top">${cell || html`<span class="text-muted-foreground">—</span>`}</td>`)}</tr>`)}</tbody></table></div>`
243
+ : entry.value || html`<span class="text-muted-foreground">—</span>`}</dd>
244
+ </div>`)}</dl>`;
245
+ }
246
+
247
+ render() {
248
+ const back = `/dashboard/forms/${this.form?.id ?? ''}/submissions`;
249
+ if (!this.view || !this.form) return html`<div class="space-y-4">${pageHeader(__('Submission'))}${notice(__('This submission does not exist.'), 'error')}
250
+ <a href=${this.form ? back : '/dashboard/forms'} class="text-sm text-primary hover:underline">${__('Back to submissions')}</a></div>`;
251
+ const view = this.view;
252
+ const action = (label: string, status: SubmissionStatus | 'delete', variant: 'outline' | 'destructive' = 'outline') =>
253
+ component(Button, { type: 'button', size: 'sm', variant, '@click': () => this.setStatus(status) }, label);
254
+ const actions = view.status === 'spam' ? [action(__('Not spam'), 'read'), action(__('Delete permanently'), 'delete', 'destructive')]
255
+ : view.status === 'trash' ? [action(__('Restore'), 'read'), action(__('Delete permanently'), 'delete', 'destructive')]
256
+ : [action(__('Mark as unread'), 'new'), action(__('Mark as spam'), 'spam'), action(__('Move to trash'), 'trash', 'destructive')];
257
+ return html`<div class="space-y-6">
258
+ <a href=${back} class="text-sm text-primary hover:underline">← ${__('All submissions')}</a>
259
+ ${pageHeader(`${__('Submission')}: ${this.form.title}`, { actions: html`${view.status === 'spam' ? component(Badge, { variant: 'destructive' }, __('Spam')) : view.status === 'trash' ? component(Badge, { variant: 'secondary' }, __('Trash')) : null}${actions}` })}
260
+ ${this.message ? notice(this.message, 'success') : null}
261
+ ${this.error ? notice(this.error, 'error') : null}
262
+ <div class="grid gap-6 lg:grid-cols-3">
263
+ <div class="lg:col-span-2">${component(Card, {}, component(CardBody, { class: 'p-0' }, html`<div class="flex min-h-12 items-center justify-between gap-2 border-b border-border px-4 py-2">
264
+ <h2 class="text-sm font-semibold text-foreground">${__('Answers')}</h2>
265
+ ${this.editing ? null : component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.startEditing() }, __('Edit'))}</div>
266
+ ${this.editing ? this.editor(view) : this.list(view.answers)}`))}</div>
267
+ <div class="space-y-6">
268
+ ${component(Card, {}, component(CardBody, { class: 'p-0' }, html`<h2 class="flex min-h-12 items-center border-b border-border px-4 py-2 text-sm font-semibold text-foreground">${__('Details')}</h2>${this.list(view.details)}`))}
269
+ ${component(Card, {}, component(CardBody, {}, html`<form class="space-y-2" @submit=${(event: Event) => this.submitNote(event)}>
270
+ <label for="submission-note" class="block text-sm font-semibold text-foreground">${__('Note')}</label>
271
+ ${component(Textarea, { id: 'submission-note', rows: 4, '.value': this.note, '@input': (event: Event) => { this.note = (event.target as HTMLTextAreaElement).value; } })}
272
+ <p class="text-xs text-muted-foreground">${__('Only people who handle submissions see it.')}</p>
273
+ ${component(Button, { type: 'submit', size: 'sm' }, __('Save note'))}
274
+ </form>`))}
275
+ </div>
276
+ </div>
277
+ </div>`;
278
+ }
279
+ }