inlaycms 0.0.0-stage → 0.2.0

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 (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +469 -2
  3. package/assets/admin/admin.css +2 -0
  4. package/assets/admin/admin.js +1 -0
  5. package/assets/admin/editor.js +125 -0
  6. package/dist/adapters/admin/activity.d.ts +17 -0
  7. package/dist/adapters/admin/activity.js +59 -0
  8. package/dist/adapters/admin/assets.d.ts +14 -0
  9. package/dist/adapters/admin/assets.js +64 -0
  10. package/dist/adapters/admin/attention.d.ts +15 -0
  11. package/dist/adapters/admin/attention.js +34 -0
  12. package/dist/adapters/admin/context.d.ts +40 -0
  13. package/dist/adapters/admin/context.js +142 -0
  14. package/dist/adapters/admin/form/walk.d.ts +61 -0
  15. package/dist/adapters/admin/form/walk.js +565 -0
  16. package/dist/adapters/admin/pages.d.ts +38 -0
  17. package/dist/adapters/admin/pages.js +66 -0
  18. package/dist/adapters/admin/publish.d.ts +12 -0
  19. package/dist/adapters/admin/publish.js +195 -0
  20. package/dist/adapters/admin/routes.d.ts +47 -0
  21. package/dist/adapters/admin/routes.js +255 -0
  22. package/dist/adapters/admin/screens/backups.d.ts +11 -0
  23. package/dist/adapters/admin/screens/backups.js +223 -0
  24. package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
  25. package/dist/adapters/admin/screens/dashboard.js +160 -0
  26. package/dist/adapters/admin/screens/editor.d.ts +67 -0
  27. package/dist/adapters/admin/screens/editor.js +416 -0
  28. package/dist/adapters/admin/screens/history.d.ts +4 -0
  29. package/dist/adapters/admin/screens/history.js +105 -0
  30. package/dist/adapters/admin/screens/lists.d.ts +4 -0
  31. package/dist/adapters/admin/screens/lists.js +297 -0
  32. package/dist/adapters/admin/screens/media.d.ts +20 -0
  33. package/dist/adapters/admin/screens/media.js +186 -0
  34. package/dist/adapters/admin/screens/pickers.d.ts +29 -0
  35. package/dist/adapters/admin/screens/pickers.js +134 -0
  36. package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
  37. package/dist/adapters/admin/screens/preview-pane.js +74 -0
  38. package/dist/adapters/admin/screens/redirects.d.ts +4 -0
  39. package/dist/adapters/admin/screens/redirects.js +137 -0
  40. package/dist/adapters/admin/screens/releases.d.ts +7 -0
  41. package/dist/adapters/admin/screens/releases.js +287 -0
  42. package/dist/adapters/admin/screens/search.d.ts +22 -0
  43. package/dist/adapters/admin/screens/search.js +113 -0
  44. package/dist/adapters/admin/screens/security.d.ts +4 -0
  45. package/dist/adapters/admin/screens/security.js +85 -0
  46. package/dist/adapters/admin/screens/users.d.ts +4 -0
  47. package/dist/adapters/admin/screens/users.js +330 -0
  48. package/dist/adapters/admin/theme.d.ts +1 -0
  49. package/dist/adapters/admin/theme.js +1 -0
  50. package/dist/adapters/admin/translations.d.ts +16 -0
  51. package/dist/adapters/admin/translations.js +23 -0
  52. package/dist/adapters/admin/upload.d.ts +8 -0
  53. package/dist/adapters/admin/upload.js +116 -0
  54. package/dist/adapters/admin/views/data-table.d.ts +82 -0
  55. package/dist/adapters/admin/views/data-table.js +117 -0
  56. package/dist/adapters/admin/views/icons.d.ts +48 -0
  57. package/dist/adapters/admin/views/icons.js +47 -0
  58. package/dist/adapters/admin/views/layout.d.ts +51 -0
  59. package/dist/adapters/admin/views/layout.js +145 -0
  60. package/dist/adapters/admin/views/sheet.d.ts +15 -0
  61. package/dist/adapters/admin/views/sheet.js +6 -0
  62. package/dist/adapters/admin/views/status.d.ts +32 -0
  63. package/dist/adapters/admin/views/status.js +74 -0
  64. package/dist/adapters/auth/handler.d.ts +10 -0
  65. package/dist/adapters/auth/handler.js +63 -0
  66. package/dist/adapters/auth/request.d.ts +8 -0
  67. package/dist/adapters/auth/request.js +14 -0
  68. package/dist/adapters/cli/bin.d.ts +2 -0
  69. package/dist/adapters/cli/bin.js +42 -0
  70. package/dist/adapters/cli/main.d.ts +7 -0
  71. package/dist/adapters/cli/main.js +982 -0
  72. package/dist/adapters/cli/remote.d.ts +52 -0
  73. package/dist/adapters/cli/remote.js +161 -0
  74. package/dist/adapters/mcp/agent-refs.d.ts +9 -0
  75. package/dist/adapters/mcp/agent-refs.js +25 -0
  76. package/dist/adapters/mcp/documents.d.ts +15 -0
  77. package/dist/adapters/mcp/documents.js +26 -0
  78. package/dist/adapters/mcp/fetch-url.d.ts +19 -0
  79. package/dist/adapters/mcp/fetch-url.js +244 -0
  80. package/dist/adapters/mcp/request-state.d.ts +15 -0
  81. package/dist/adapters/mcp/request-state.js +38 -0
  82. package/dist/adapters/mcp/results.d.ts +20 -0
  83. package/dist/adapters/mcp/results.js +61 -0
  84. package/dist/adapters/mcp/route.d.ts +34 -0
  85. package/dist/adapters/mcp/route.js +52 -0
  86. package/dist/adapters/mcp/server.d.ts +44 -0
  87. package/dist/adapters/mcp/server.js +49 -0
  88. package/dist/adapters/mcp/tools/history.d.ts +5 -0
  89. package/dist/adapters/mcp/tools/history.js +84 -0
  90. package/dist/adapters/mcp/tools/media.d.ts +5 -0
  91. package/dist/adapters/mcp/tools/media.js +102 -0
  92. package/dist/adapters/mcp/tools/publish.d.ts +5 -0
  93. package/dist/adapters/mcp/tools/publish.js +157 -0
  94. package/dist/adapters/mcp/tools/read.d.ts +5 -0
  95. package/dist/adapters/mcp/tools/read.js +279 -0
  96. package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
  97. package/dist/adapters/mcp/tools/redirects.js +74 -0
  98. package/dist/adapters/mcp/tools/write.d.ts +5 -0
  99. package/dist/adapters/mcp/tools/write.js +304 -0
  100. package/dist/adapters/site/backup-schedule.d.ts +8 -0
  101. package/dist/adapters/site/backup-schedule.js +31 -0
  102. package/dist/adapters/site/cache.d.ts +29 -0
  103. package/dist/adapters/site/cache.js +63 -0
  104. package/dist/adapters/site/context.d.ts +29 -0
  105. package/dist/adapters/site/context.js +278 -0
  106. package/dist/adapters/site/head.d.ts +23 -0
  107. package/dist/adapters/site/head.js +44 -0
  108. package/dist/adapters/site/limiter.d.ts +17 -0
  109. package/dist/adapters/site/limiter.js +39 -0
  110. package/dist/adapters/site/lock.d.ts +30 -0
  111. package/dist/adapters/site/lock.js +143 -0
  112. package/dist/adapters/site/media-routes.d.ts +4 -0
  113. package/dist/adapters/site/media-routes.js +55 -0
  114. package/dist/adapters/site/plugin.d.ts +122 -0
  115. package/dist/adapters/site/plugin.js +436 -0
  116. package/dist/adapters/site/preview.d.ts +36 -0
  117. package/dist/adapters/site/preview.js +82 -0
  118. package/dist/adapters/site/public.d.ts +6 -0
  119. package/dist/adapters/site/public.js +87 -0
  120. package/dist/adapters/site/render.d.ts +45 -0
  121. package/dist/adapters/site/render.js +191 -0
  122. package/dist/adapters/site/routes.d.ts +17 -0
  123. package/dist/adapters/site/routes.js +125 -0
  124. package/dist/adapters/site/sitemap.d.ts +10 -0
  125. package/dist/adapters/site/sitemap.js +10 -0
  126. package/dist/adapters/web.d.ts +22 -0
  127. package/dist/adapters/web.js +75 -0
  128. package/dist/config.d.ts +21 -0
  129. package/dist/config.js +58 -0
  130. package/dist/core/agent/format.d.ts +62 -0
  131. package/dist/core/agent/format.js +211 -0
  132. package/dist/core/agent/schema.d.ts +6 -0
  133. package/dist/core/agent/schema.js +86 -0
  134. package/dist/core/archive.d.ts +12 -0
  135. package/dist/core/archive.js +72 -0
  136. package/dist/core/auth/auth.d.ts +4911 -0
  137. package/dist/core/auth/auth.js +61 -0
  138. package/dist/core/auth/roles.d.ts +10 -0
  139. package/dist/core/auth/roles.js +38 -0
  140. package/dist/core/auth/service.d.ts +118 -0
  141. package/dist/core/auth/service.js +424 -0
  142. package/dist/core/auth/upload-token.d.ts +8 -0
  143. package/dist/core/auth/upload-token.js +27 -0
  144. package/dist/core/backup/backup.d.ts +28 -0
  145. package/dist/core/backup/backup.js +126 -0
  146. package/dist/core/backup/restore.d.ts +41 -0
  147. package/dist/core/backup/restore.js +264 -0
  148. package/dist/core/backup/schedule.d.ts +12 -0
  149. package/dist/core/backup/schedule.js +29 -0
  150. package/dist/core/boot.d.ts +63 -0
  151. package/dist/core/boot.js +141 -0
  152. package/dist/core/check.d.ts +32 -0
  153. package/dist/core/check.js +111 -0
  154. package/dist/core/content/activity.d.ts +8 -0
  155. package/dist/core/content/activity.js +101 -0
  156. package/dist/core/content/delete.d.ts +5 -0
  157. package/dist/core/content/delete.js +100 -0
  158. package/dist/core/content/diff.d.ts +6 -0
  159. package/dist/core/content/diff.js +129 -0
  160. package/dist/core/content/dry-run.d.ts +24 -0
  161. package/dist/core/content/dry-run.js +69 -0
  162. package/dist/core/content/gaps.d.ts +25 -0
  163. package/dist/core/content/gaps.js +50 -0
  164. package/dist/core/content/hidden.d.ts +33 -0
  165. package/dist/core/content/hidden.js +103 -0
  166. package/dist/core/content/history.d.ts +15 -0
  167. package/dist/core/content/history.js +62 -0
  168. package/dist/core/content/patch.d.ts +40 -0
  169. package/dist/core/content/patch.js +287 -0
  170. package/dist/core/content/path.d.ts +6 -0
  171. package/dist/core/content/path.js +38 -0
  172. package/dist/core/content/publish.d.ts +26 -0
  173. package/dist/core/content/publish.js +211 -0
  174. package/dist/core/content/read.d.ts +99 -0
  175. package/dist/core/content/read.js +141 -0
  176. package/dist/core/content/reader.d.ts +37 -0
  177. package/dist/core/content/reader.js +195 -0
  178. package/dist/core/content/refs.d.ts +44 -0
  179. package/dist/core/content/refs.js +161 -0
  180. package/dist/core/content/release-migrations.d.ts +12 -0
  181. package/dist/core/content/release-migrations.js +154 -0
  182. package/dist/core/content/save.d.ts +25 -0
  183. package/dist/core/content/save.js +87 -0
  184. package/dist/core/content/schema.d.ts +22 -0
  185. package/dist/core/content/schema.js +127 -0
  186. package/dist/core/content/search.d.ts +8 -0
  187. package/dist/core/content/search.js +89 -0
  188. package/dist/core/content/shipped-input.d.ts +39 -0
  189. package/dist/core/content/shipped-input.js +221 -0
  190. package/dist/core/content/shipped.d.ts +112 -0
  191. package/dist/core/content/shipped.js +437 -0
  192. package/dist/core/content/slug.d.ts +23 -0
  193. package/dist/core/content/slug.js +182 -0
  194. package/dist/core/content/stats.d.ts +11 -0
  195. package/dist/core/content/stats.js +30 -0
  196. package/dist/core/content/translate.d.ts +3 -0
  197. package/dist/core/content/translate.js +68 -0
  198. package/dist/core/content/usages.d.ts +13 -0
  199. package/dist/core/content/usages.js +70 -0
  200. package/dist/core/content/validate.d.ts +21 -0
  201. package/dist/core/content/validate.js +124 -0
  202. package/dist/core/content/write.d.ts +10 -0
  203. package/dist/core/content/write.js +93 -0
  204. package/dist/core/core.d.ts +227 -0
  205. package/dist/core/core.js +251 -0
  206. package/dist/core/db/connection.d.ts +6 -0
  207. package/dist/core/db/connection.js +12 -0
  208. package/dist/core/db/migrate.d.ts +9 -0
  209. package/dist/core/db/migrate.js +42 -0
  210. package/dist/core/db/migrations/0001_content.d.ts +2 -0
  211. package/dist/core/db/migrations/0001_content.js +69 -0
  212. package/dist/core/db/migrations/0002_media.d.ts +2 -0
  213. package/dist/core/db/migrations/0002_media.js +26 -0
  214. package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
  215. package/dist/core/db/migrations/0003_redirects.js +19 -0
  216. package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
  217. package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
  218. package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
  219. package/dist/core/db/migrations/0005_site_lock.js +10 -0
  220. package/dist/core/db/migrations/0006_releases.d.ts +3 -0
  221. package/dist/core/db/migrations/0006_releases.js +34 -0
  222. package/dist/core/db/schema.d.ts +155 -0
  223. package/dist/core/db/schema.js +1 -0
  224. package/dist/core/errors.d.ts +27 -0
  225. package/dist/core/errors.js +15 -0
  226. package/dist/core/export/export.d.ts +17 -0
  227. package/dist/core/export/export.js +185 -0
  228. package/dist/core/export/format.d.ts +241 -0
  229. package/dist/core/export/format.js +106 -0
  230. package/dist/core/export/import.d.ts +54 -0
  231. package/dist/core/export/import.js +180 -0
  232. package/dist/core/export/read.d.ts +16 -0
  233. package/dist/core/export/read.js +234 -0
  234. package/dist/core/export/replace.d.ts +17 -0
  235. package/dist/core/export/replace.js +36 -0
  236. package/dist/core/export/report.d.ts +55 -0
  237. package/dist/core/export/report.js +50 -0
  238. package/dist/core/export/schema.d.ts +8 -0
  239. package/dist/core/export/schema.js +47 -0
  240. package/dist/core/export/stage.d.ts +25 -0
  241. package/dist/core/export/stage.js +192 -0
  242. package/dist/core/fields/builtins.d.ts +70 -0
  243. package/dist/core/fields/builtins.js +335 -0
  244. package/dist/core/fields/define.d.ts +86 -0
  245. package/dist/core/fields/define.js +34 -0
  246. package/dist/core/fields/walk.d.ts +49 -0
  247. package/dist/core/fields/walk.js +270 -0
  248. package/dist/core/fields/widgets.d.ts +27 -0
  249. package/dist/core/fields/widgets.js +330 -0
  250. package/dist/core/fields/zod-internals.d.ts +29 -0
  251. package/dist/core/fields/zod-internals.js +28 -0
  252. package/dist/core/media/detect.d.ts +5 -0
  253. package/dist/core/media/detect.js +66 -0
  254. package/dist/core/media/labels.d.ts +6 -0
  255. package/dist/core/media/labels.js +17 -0
  256. package/dist/core/media/library.d.ts +45 -0
  257. package/dist/core/media/library.js +239 -0
  258. package/dist/core/media/store.d.ts +11 -0
  259. package/dist/core/media/store.js +49 -0
  260. package/dist/core/media/variants.d.ts +10 -0
  261. package/dist/core/media/variants.js +59 -0
  262. package/dist/core/messages/en.d.ts +1278 -0
  263. package/dist/core/messages/en.js +1287 -0
  264. package/dist/core/messages/index.d.ts +7 -0
  265. package/dist/core/messages/index.js +14 -0
  266. package/dist/core/preview.d.ts +16 -0
  267. package/dist/core/preview.js +42 -0
  268. package/dist/core/redirects/collapse.d.ts +68 -0
  269. package/dist/core/redirects/collapse.js +153 -0
  270. package/dist/core/redirects/csv.d.ts +15 -0
  271. package/dist/core/redirects/csv.js +68 -0
  272. package/dist/core/redirects/redirects.d.ts +58 -0
  273. package/dist/core/redirects/redirects.js +545 -0
  274. package/dist/core/registry/content.d.ts +26 -0
  275. package/dist/core/registry/content.js +9 -0
  276. package/dist/core/registry/define.d.ts +145 -0
  277. package/dist/core/registry/define.js +41 -0
  278. package/dist/core/registry/migration.d.ts +44 -0
  279. package/dist/core/registry/migration.js +4 -0
  280. package/dist/core/registry/registry.d.ts +18 -0
  281. package/dist/core/registry/registry.js +255 -0
  282. package/dist/core/registry/render.d.ts +98 -0
  283. package/dist/core/registry/render.js +1 -0
  284. package/dist/core/registry/route.d.ts +42 -0
  285. package/dist/core/registry/route.js +3 -0
  286. package/dist/core/release/bundle.d.ts +21 -0
  287. package/dist/core/release/bundle.js +252 -0
  288. package/dist/core/release/keys.d.ts +11 -0
  289. package/dist/core/release/keys.js +60 -0
  290. package/dist/core/release/manifest.d.ts +103 -0
  291. package/dist/core/release/manifest.js +138 -0
  292. package/dist/core/release/pack.d.ts +20 -0
  293. package/dist/core/release/pack.js +97 -0
  294. package/dist/core/release/pointer.d.ts +19 -0
  295. package/dist/core/release/pointer.js +53 -0
  296. package/dist/core/release/read.d.ts +59 -0
  297. package/dist/core/release/read.js +256 -0
  298. package/dist/core/report.d.ts +31 -0
  299. package/dist/core/report.js +37 -0
  300. package/dist/core/richtext/html.d.ts +15 -0
  301. package/dist/core/richtext/html.js +81 -0
  302. package/dist/core/richtext/markdown.d.ts +19 -0
  303. package/dist/core/richtext/markdown.js +951 -0
  304. package/dist/core/richtext/schema.d.ts +98 -0
  305. package/dist/core/richtext/schema.js +275 -0
  306. package/dist/core/site/live.d.ts +56 -0
  307. package/dist/core/site/live.js +145 -0
  308. package/dist/core/site/paths.d.ts +15 -0
  309. package/dist/core/site/paths.js +64 -0
  310. package/dist/core/site/resolve.d.ts +9 -0
  311. package/dist/core/site/resolve.js +202 -0
  312. package/dist/core/site/sitemap.d.ts +11 -0
  313. package/dist/core/site/sitemap.js +24 -0
  314. package/dist/core/site-lock/site-lock.d.ts +21 -0
  315. package/dist/core/site-lock/site-lock.js +65 -0
  316. package/dist/core/site-lock/token.d.ts +7 -0
  317. package/dist/core/site-lock/token.js +24 -0
  318. package/dist/core/theme.d.ts +22 -0
  319. package/dist/core/theme.js +133 -0
  320. package/dist/core/types.d.ts +253 -0
  321. package/dist/core/types.js +1 -0
  322. package/dist/core/version.d.ts +1 -0
  323. package/dist/core/version.js +5 -0
  324. package/dist/host/activate.d.ts +53 -0
  325. package/dist/host/activate.js +162 -0
  326. package/dist/host/app.d.ts +46 -0
  327. package/dist/host/app.js +129 -0
  328. package/dist/host/bin.d.ts +5 -0
  329. package/dist/host/bin.js +8 -0
  330. package/dist/host/config.d.ts +36 -0
  331. package/dist/host/config.js +152 -0
  332. package/dist/host/dev.d.ts +10 -0
  333. package/dist/host/dev.js +293 -0
  334. package/dist/host/diff.d.ts +78 -0
  335. package/dist/host/diff.js +346 -0
  336. package/dist/host/hooks.d.ts +41 -0
  337. package/dist/host/hooks.js +49 -0
  338. package/dist/host/ipc.d.ts +123 -0
  339. package/dist/host/ipc.js +61 -0
  340. package/dist/host/preview-proxy.d.ts +24 -0
  341. package/dist/host/preview-proxy.js +154 -0
  342. package/dist/host/preview-worker.d.ts +42 -0
  343. package/dist/host/preview-worker.js +242 -0
  344. package/dist/host/primary.d.ts +38 -0
  345. package/dist/host/primary.js +357 -0
  346. package/dist/host/push.d.ts +125 -0
  347. package/dist/host/push.js +420 -0
  348. package/dist/host/serve.d.ts +16 -0
  349. package/dist/host/serve.js +150 -0
  350. package/dist/host/store.d.ts +48 -0
  351. package/dist/host/store.js +109 -0
  352. package/dist/host/worker.d.ts +67 -0
  353. package/dist/host/worker.js +310 -0
  354. package/dist/index.d.ts +47 -0
  355. package/dist/index.js +32 -0
  356. package/dist/jsx/html.d.ts +16 -0
  357. package/dist/jsx/html.js +65 -0
  358. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  359. package/dist/jsx/jsx-dev-runtime.js +5 -0
  360. package/dist/jsx/jsx-runtime.d.ts +17 -0
  361. package/dist/jsx/jsx-runtime.js +41 -0
  362. package/dist/site.d.ts +17 -0
  363. package/dist/site.js +14 -0
  364. package/package.json +111 -3
@@ -0,0 +1,416 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { normalizeContent } from '../../../core/content/schema.js';
3
+ import { validateContent } from '../../../core/content/validate.js';
4
+ import { InlayError } from '../../../core/errors.js';
5
+ import { t } from '../../../core/messages/index.js';
6
+ import { loadAgentRefs } from '../../mcp/agent-refs.js';
7
+ import { previewLink } from '../../site/preview.js';
8
+ import { adminActor, forbidden, formValues, HTML, noticeOf, notFound } from '../context.js';
9
+ import { blankPath, panePath, paneDocument } from './preview-pane.js';
10
+ import { applyFormOp, DocumentFields, parseDocumentForm, placeIssues, readOpenState, remapOpen } from '../form/walk.js';
11
+ import { Icon } from '../views/icons.js';
12
+ import { adminPage, Alert, Time } from '../views/layout.js';
13
+ import { sourceLabel, StatusBadge } from '../views/status.js';
14
+ /** The address of a document's editor. */
15
+ export const editorLink = (id) => `/admin/documents/${encodeURIComponent(id)}`;
16
+ /** The publish (or unpublish) review of one document, which comes back to its editor. */
17
+ const publishLink = (id, action) => `/admin/publish?${new URLSearchParams({ ids: id, action, back: editorLink(id) }).toString()}`;
18
+ const REVISION = /^\d{1,15}$/;
19
+ const LANGUAGES = new Intl.DisplayNames(['en'], { type: 'language' });
20
+ /** A locale's name in English ("Spanish"), or the code itself when it has none. */
21
+ export function localeName(locale) {
22
+ try {
23
+ return LANGUAGES.of(locale) ?? locale;
24
+ }
25
+ catch {
26
+ return locale;
27
+ }
28
+ }
29
+ /** Where a document sits in the navigation: its section and the breadcrumb back to its list. */
30
+ export function placement(ctx, doc) {
31
+ const { registry } = ctx.core;
32
+ const query = doc.locale === registry.defaultLocale ? '' : `?${new URLSearchParams({ locale: doc.locale }).toString()}`;
33
+ if (doc.kind === 'singleton')
34
+ return { section: 'pages', breadcrumbs: [{ label: t('admin.nav.pages'), href: `/admin/pages${query}` }] };
35
+ if (doc.kind === 'global')
36
+ return { section: 'globals', breadcrumbs: [{ label: t('admin.nav.globals'), href: `/admin/globals${query}` }] };
37
+ const label = registry.types.get(doc.type)?.label ?? doc.type;
38
+ return {
39
+ section: `collection:${doc.type}`,
40
+ breadcrumbs: [{ label, href: `/admin/collections/${encodeURIComponent(doc.type)}${query}` }],
41
+ };
42
+ }
43
+ /** Every locale of the site with its version of `doc`'s group. */
44
+ export async function translationsOf(ctx, doc) {
45
+ return Promise.all(ctx.core.registry.locales.map(async (locale) => ({
46
+ locale,
47
+ document: locale === doc.locale ? doc : await ctx.core.findTranslation(doc.groupId, locale),
48
+ })));
49
+ }
50
+ /**
51
+ * Links to each language of the document as a compact button group, the current one marked. A locale without a document shows `missing`
52
+ * when given (the "Add <language>" button), otherwise a note that it isn't translated yet.
53
+ */
54
+ export function LocaleSwitcher({ doc, translations, missing }) {
55
+ if (translations.length < 2)
56
+ return null;
57
+ return (_jsx("nav", { "aria-label": t('admin.editor.languages'), children: _jsx("ul", { class: "join", children: translations.map(({ locale, document }) => (_jsx("li", { children: document ? (_jsx("a", { href: editorLink(document.id), lang: locale, "aria-current": document.id === doc.id ? 'page' : undefined, class: document.id === doc.id ? 'btn btn-xs join-item btn-active' : 'btn btn-xs join-item', children: localeName(locale) })) : missing ? (missing(locale)) : (_jsx("span", { class: "btn btn-xs join-item btn-disabled", children: t('admin.editor.missingLocale', { name: localeName(locale) }) })) }))) }) }));
58
+ }
59
+ /** A button that creates the `locale` translation of the document group `id` belongs to. */
60
+ export function TranslateButton({ id, locale }) {
61
+ return (_jsxs("form", { method: "post", action: `${editorLink(id)}/translations`, children: [_jsx("input", { type: "hidden", name: "locale", value: locale }), _jsx("button", { type: "submit", class: "btn btn-xs btn-outline join-item", children: t('admin.editor.addLanguage', { name: localeName(locale) }) })] }));
62
+ }
63
+ /** "Needed before publishing" hints for `data`, by form name, and those no field shows. */
64
+ function publishHints(ctx, type, data) {
65
+ const { registry } = ctx.core;
66
+ const strict = validateContent(registry, type, data, 'strict');
67
+ if (strict.ok)
68
+ return { byName: new Map(), unplaced: [] };
69
+ const placed = placeIssues(registry, type, data, strict.issues);
70
+ const byName = new Map([...placed.byName].map(([name, messages]) => [name, messages.map((problem) => t('admin.editor.needed', { problem }))]));
71
+ return { byName, unplaced: placed.unplaced };
72
+ }
73
+ /** The editor header's right side: when it was last saved, the Edit/Preview tabs (with a pane), Save, Publish and More. */
74
+ function HeaderActions({ doc, conflictHead, pane }) {
75
+ return (_jsxs("div", { class: "ml-auto flex flex-wrap items-center gap-2", children: [_jsxs("span", { id: "save-state", "data-text-unsaved": t('admin.editor.unsavedShort'), class: "hidden text-xs text-base-content/70 md:inline", children: [t('admin.editor.lastSaved'), " ", _jsx(Time, { iso: doc.revision.createdAt }), ' ', t('admin.editor.savedBy', { name: doc.revision.authorName, source: sourceLabel(doc.revision.source) })] }), pane && (_jsxs("div", { role: "group", "aria-label": t('admin.preview.views'), class: "join lg:hidden", children: [_jsx("button", { type: "button", "aria-pressed": "true", "data-view-btn": "edit", class: "btn btn-sm join-item btn-active", children: t('admin.preview.editTab') }), _jsx("button", { type: "button", "aria-pressed": "false", "data-view-btn": "preview", class: "btn btn-sm join-item", children: t('admin.preview.previewTab') })] })), _jsxs("div", { role: "group", "aria-label": t('admin.editor.actions'), class: "flex items-center gap-2", children: [_jsx("button", { type: "submit", form: "editor-form", name: "_action", value: "save", class: "btn btn-sm", children: t('admin.editor.save') }), conflictHead !== undefined && (_jsx("button", { type: "submit", form: "editor-form", name: "overwrite", value: String(conflictHead), class: "btn btn-sm btn-warning", children: t('admin.editor.overwrite') })), _jsxs("button", { type: "submit", form: "editor-form", name: "_action", value: "publish", "data-publish-dialog": true, class: "btn btn-sm btn-primary", children: [_jsx(Icon, { name: "send" }), t('admin.editor.publish')] }), _jsxs("details", { id: "editor-more", "data-refresh": true, class: "dropdown dropdown-end", children: [_jsx("summary", { class: "btn btn-ghost btn-sm btn-square", "aria-label": t('admin.editor.more'), children: _jsx(Icon, { name: "more" }) }), _jsxs("ul", { class: "dropdown-content menu menu-sm z-20 mt-1 w-56 rounded-box border border-base-300 bg-base-100 p-1 shadow-lg", children: [_jsx("li", { children: _jsxs("button", { type: "submit", form: "editor-form", name: "_action", value: "preview", children: [_jsx(Icon, { name: "external" }), t('admin.editor.preview')] }) }), _jsx("li", { children: _jsxs("a", { href: `${editorLink(doc.id)}/history`, children: [_jsx(Icon, { name: "history" }), t('admin.editor.history')] }) }), doc.kind === 'entry' && doc.publishedRev !== null && (_jsx("li", { children: _jsxs("a", { href: publishLink(doc.id, 'unpublish'), "data-publish-dialog": true, children: [_jsx(Icon, { name: "x" }), t('admin.editor.unpublish')] }) })), doc.kind === 'entry' && (_jsx("li", { children: _jsxs("a", { href: `${editorLink(doc.id)}/delete`, class: "text-error", children: [_jsx(Icon, { name: "trash" }), t('admin.editor.delete')] }) }))] })] })] })] }));
76
+ }
77
+ /** A preview size button; `client/admin` resizes the page to that device's width. */
78
+ function DeviceButton({ device, icon, pressed }) {
79
+ const label = t(`admin.preview.${device}`);
80
+ return (_jsx("button", { type: "button", "data-device": device, "aria-pressed": pressed ? 'true' : 'false', "aria-label": label, title: label, class: pressed ? 'btn btn-xs join-item btn-active' : 'btn btn-xs join-item', children: _jsx(Icon, { name: icon }) }));
81
+ }
82
+ /** The live preview: a toolbar over the page itself, which loads the saved draft and is then rewritten as the form changes. */
83
+ function PreviewPane({ id, live }) {
84
+ const src = panePath(id);
85
+ return (_jsxs("div", { id: "preview-pane", class: "flex min-h-0 flex-col overflow-y-auto border-l border-base-300 bg-base-100", children: [_jsxs("div", { class: "flex h-11 shrink-0 items-center gap-2 border-b border-base-300 px-3", children: [_jsxs("div", { role: "group", "aria-label": t('admin.preview.size'), class: "join", children: [_jsx(DeviceButton, { device: "desktop", icon: "monitor", pressed: true }), _jsx(DeviceButton, { device: "tablet", icon: "tablet", pressed: false }), _jsx(DeviceButton, { device: "phone", icon: "smartphone", pressed: false })] }), _jsx("span", { id: "preview-scale", class: "text-xs tabular-nums text-base-content/70" }), _jsxs("div", { class: "mx-auto flex min-w-0 items-center gap-1.5 rounded-field bg-base-200 px-2.5 py-1 text-xs text-base-content/70", children: [_jsx(Icon, { name: "globe", class: "opacity-60" }), _jsx("span", { class: "truncate", children: live.path })] }), _jsx("span", { id: "preview-status", "data-text-updating": t('admin.preview.updating'), "data-text-ready": t('admin.preview.ready'), "data-text-signed-out": t('admin.preview.signedOut'), "data-text-failed": t('admin.preview.failed'), class: "flex min-w-0 items-center gap-1.5 truncate text-xs text-base-content/70" }), _jsx("span", { id: "preview-announce", role: "status", class: "sr-only" }), _jsx("button", { type: "button", id: "preview-hide", "aria-label": t('admin.preview.hide'), title: t('admin.preview.hide'), class: "btn btn-ghost btn-xs btn-square hidden lg:inline-flex", children: _jsx(Icon, { name: "panel-right" }) })] }), _jsx("div", { id: "preview-stage", class: "relative flex min-h-0 flex-1 justify-center overflow-hidden bg-base-200 p-3", children: _jsx("div", { id: "preview-device", class: "relative w-full overflow-hidden rounded-lg bg-white shadow-sm ring-1 ring-base-300", children: _jsx("iframe", { id: "preview-frame", title: t('admin.preview.title'), src: src, "data-preview-url": src, "data-blank-url": blankPath(id), "data-page-path": live.path, class: "absolute left-0 top-0 h-full w-full origin-top-left border-0 bg-white" }) }) })] }));
86
+ }
87
+ /** The editor page of `doc` (the current head, for the header) showing `state`. */
88
+ export async function editorPage(ctx, actor, doc, state) {
89
+ const { core } = ctx;
90
+ const { registry } = core;
91
+ const def = registry.getType(doc.type);
92
+ const action = editorLink(doc.id);
93
+ const [refs, translations, live, gap] = await Promise.all([
94
+ loadAgentRefs({ core, baseUrl: ctx.baseUrl }, doc.type, doc.locale, state.data),
95
+ translationsOf(ctx, doc),
96
+ paneDocument(ctx, doc),
97
+ doc.publishedRev === null ? undefined : core.listGaps({ ids: [doc.id] }).then((gaps) => gaps[0]),
98
+ ]);
99
+ const pane = live !== null && live.path !== null ? { ...live, path: live.path } : null;
100
+ const hints = publishHints(ctx, doc.type, state.data);
101
+ const formCtx = {
102
+ registry,
103
+ type: doc.type,
104
+ locale: doc.locale,
105
+ refs,
106
+ action,
107
+ ...(ctx.readOnly && { readOnly: true }),
108
+ hints: hints.byName,
109
+ ...(state.problems && { problems: state.problems }),
110
+ ...(state.open && { open: state.open }),
111
+ ...(state.closed && { closed: state.closed }),
112
+ };
113
+ const unplaced = state.unplaced ?? [];
114
+ const actions = (_jsxs(_Fragment, { children: [_jsx("span", { id: "editor-status", "data-refresh": true, children: _jsx(StatusBadge, { doc: doc }) }), _jsx(LocaleSwitcher, { doc: doc, translations: translations, missing: (locale) => _jsx(TranslateButton, { id: doc.id, locale: locale }) }), _jsx(HeaderActions, { doc: doc, pane: pane !== null, ...(state.conflict && { conflictHead: state.conflict.head }) })] }));
115
+ const body = (_jsxs(_Fragment, { children: [_jsxs("div", { id: "workspace", "data-view": "edit", class: pane ? 'grid min-h-0 flex-1 grid-cols-1 lg:grid-cols-[minmax(24rem,5fr)_7fr]' : 'grid min-h-0 flex-1 grid-cols-1', children: [_jsx("div", { id: "form-pane", class: "min-h-0 overflow-y-auto", children: _jsxs("form", { id: "editor-form", method: "post", action: action, "data-save-errors": (state.status ?? 200) >= 400, class: "mx-auto flex max-w-3xl flex-col gap-4 p-4 pb-24", children: [_jsx("button", { type: "submit", name: "_action", value: "save", class: "hidden", tabindex: "-1", "aria-hidden": "true" }), _jsx("input", { type: "hidden", name: "base", value: state.base }), state.review !== undefined && _jsx("div", { hidden: true, "data-publish-open": state.review }), state.unsaved === true && (_jsx("div", { role: "status", class: "alert alert-info", children: t('admin.editor.unsaved') })), state.conflict && (_jsx(Alert, { kind: "error", children: t('admin.editor.conflict', { name: state.conflict.name, source: sourceLabel(state.conflict.source) }) })), (state.error !== undefined || unplaced.length > 0) && (_jsx(Alert, { kind: "error", children: _jsxs("div", { children: [state.error !== undefined && _jsx("p", { children: state.error }), unplaced.length > 0 && (_jsx("ul", { class: "list-disc pl-6", children: unplaced.map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), gap && (_jsx(Alert, { kind: "warning", children: t('admin.gaps.editor', { count: gap.issues.length, labels: gap.issues.map((issue) => issue.labels.join(' → ')).join(', ') }) })), hints.unplaced.length > 0 && (_jsx(Alert, { kind: "warning", children: _jsxs("div", { children: [_jsx("p", { children: t('admin.editor.neededIntro') }), _jsx("ul", { class: "list-disc pl-6", children: hints.unplaced.map((issue) => (_jsx("li", { children: issue.message }))) })] }) })), _jsx(DocumentFields, { ctx: formCtx, data: state.data, ...(def.kind === 'collection' && { entry: { customPaths: def.customPaths } }) })] }) }), pane && _jsx(PreviewPane, { id: doc.id, live: pane })] }), pane && (_jsxs("button", { type: "button", id: "preview-show", hidden: true, class: "btn btn-sm fixed bottom-4 right-4 z-30 shadow-lg", children: [_jsx(Icon, { name: "eye" }), t('admin.preview.show')] }))] }));
116
+ const { section, breadcrumbs } = placement(ctx, doc);
117
+ return adminPage(ctx, {
118
+ title: doc.title,
119
+ actor,
120
+ section,
121
+ breadcrumbs,
122
+ actions,
123
+ layout: 'workspace',
124
+ scripts: ['editor.js'],
125
+ ...(state.status !== undefined && { status: state.status }),
126
+ ...(state.notice !== undefined && { notice: state.notice }),
127
+ }, body);
128
+ }
129
+ /** The form for a new entry of collection `type` in `locale`. */
130
+ async function newEntryPage(ctx, actor, type, locale, state) {
131
+ const { core } = ctx;
132
+ const { registry } = core;
133
+ const def = registry.getType(type);
134
+ const action = `/admin/collections/${encodeURIComponent(type)}`;
135
+ const refs = await loadAgentRefs({ core, baseUrl: ctx.baseUrl }, type, locale, state.data);
136
+ const formCtx = {
137
+ registry,
138
+ type,
139
+ locale,
140
+ refs,
141
+ action,
142
+ ...(ctx.readOnly && { readOnly: true }),
143
+ ...(state.problems && { problems: state.problems }),
144
+ ...(state.open && { open: state.open }),
145
+ ...(state.closed && { closed: state.closed }),
146
+ };
147
+ const unplaced = state.unplaced ?? [];
148
+ const body = (_jsxs("form", { id: "editor-form", method: "post", action: action, class: "flex flex-col gap-4", children: [_jsx("button", { type: "submit", name: "_action", value: "save", class: "hidden", tabindex: "-1", "aria-hidden": "true" }), _jsx("input", { type: "hidden", name: "locale", value: locale }), state.unsaved === true && (_jsx("div", { role: "status", class: "alert alert-info", children: t('admin.editor.unsaved') })), (state.error !== undefined || unplaced.length > 0) && (_jsx(Alert, { kind: "error", children: _jsxs("div", { children: [state.error !== undefined && _jsx("p", { children: state.error }), unplaced.length > 0 && (_jsx("ul", { class: "list-disc pl-6", children: unplaced.map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), _jsx(DocumentFields, { ctx: formCtx, data: state.data, ...(def.kind === 'collection' && { entry: { customPaths: def.customPaths } }) }), _jsxs("div", { role: "group", "aria-label": t('admin.editor.actions'), class: "flex flex-wrap items-center gap-2 border-t border-base-300 pt-4", children: [_jsx("button", { type: "submit", name: "_action", value: "save", class: "btn btn-primary", children: t('admin.editor.create') }), _jsx("button", { type: "submit", name: "_action", value: "preview", class: "btn", children: t('admin.editor.createPreview') })] })] }));
149
+ return adminPage(ctx, {
150
+ title: t('admin.editor.newTitle', { label: def.label }),
151
+ actor,
152
+ section: `collection:${type}`,
153
+ breadcrumbs: [{ label: def.label, href: action }],
154
+ scripts: ['editor.js'],
155
+ ...(state.status !== undefined && { status: state.status }),
156
+ }, body);
157
+ }
158
+ /** A page with one message, for a request the core refused. */
159
+ async function messagePage(reply, ctx, actor, status, title, message, section) {
160
+ const body = (_jsxs(_Fragment, { children: [_jsx(Alert, { kind: "error", children: message }), _jsx("p", { children: _jsx("a", { href: "/admin", class: "link", children: t('admin.backToDashboard') }) })] }));
161
+ const page = await adminPage(ctx, { title, actor, status, ...(section && { section }) }, body);
162
+ return reply.code(status).type(HTML).send(page);
163
+ }
164
+ /** The 404 page of a deleted entry, linking to its list. */
165
+ async function deletedPage(reply, ctx, actor, doc) {
166
+ const { section, breadcrumbs } = placement(ctx, doc);
167
+ const list = breadcrumbs[0];
168
+ const body = (_jsxs(_Fragment, { children: [_jsx("p", { children: t('error.editDeleted', { title: doc.title }) }), _jsx("p", { children: _jsx("a", { href: list.href, class: "link", children: t('admin.editor.backToList', { list: list.label }) }) })] }));
169
+ const page = await adminPage(ctx, { title: t('admin.editor.deleted.title'), actor, section, breadcrumbs, status: 404 }, body);
170
+ return reply.code(404).type(HTML).send(page);
171
+ }
172
+ /** The editor: `GET` shows a document's form, `POST` saves it (or applies a list button without saving). */
173
+ export function registerEditor(scope, ctx) {
174
+ const { core } = ctx;
175
+ const { registry } = core;
176
+ const send = (reply, status, body) => reply.code(status).type(HTML).send(body);
177
+ /** The document, or the reply already sent when it is unknown or deleted. */
178
+ async function load(reply, actor, id) {
179
+ const doc = await core.getDocument(id);
180
+ if (!doc)
181
+ return notFound(reply, ctx, actor);
182
+ if (doc.deletedAt !== null)
183
+ return deletedPage(reply, ctx, actor, doc);
184
+ return doc;
185
+ }
186
+ scope.get('/admin/documents/:id', async (request, reply) => {
187
+ const actor = adminActor(request);
188
+ const { id } = request.params;
189
+ const doc = await load(reply, actor, id);
190
+ if (!('revision' in doc))
191
+ return doc;
192
+ const notice = noticeOf(request.query);
193
+ const review = request.query.review === 'publish' ? publishLink(doc.id, 'publish') : undefined;
194
+ const page = await editorPage(ctx, actor, doc, {
195
+ data: doc.data,
196
+ base: String(doc.headRev),
197
+ ...(notice !== undefined && { notice }),
198
+ ...(review !== undefined && { review }),
199
+ });
200
+ return send(reply, 200, page);
201
+ });
202
+ scope.post('/admin/documents/:id', async (request, reply) => {
203
+ const actor = adminActor(request);
204
+ const { id } = request.params;
205
+ const doc = await load(reply, actor, id);
206
+ if (!('revision' in doc))
207
+ return doc;
208
+ const form = formValues(request);
209
+ const data = parseDocumentForm(registry, doc.type, form);
210
+ const submittedBase = form.get('base') ?? '';
211
+ const op = form.get('_op');
212
+ if (op !== undefined) {
213
+ const next = applyFormOp(registry, doc.type, data, op);
214
+ const { open, closed } = readOpenState(form);
215
+ const shown = { open: new Set(remapOpen(registry, doc.type, data, op, open)), closed: new Set(closed) };
216
+ return send(reply, 200, await editorPage(ctx, actor, doc, { data: next, base: submittedBase, unsaved: true, ...shown }));
217
+ }
218
+ const rawBase = form.get('overwrite') ?? form.get('base');
219
+ if (rawBase === undefined || !REVISION.test(rawBase)) {
220
+ return send(reply, 400, await editorPage(ctx, actor, doc, { data, base: submittedBase, status: 400, error: t('admin.editor.badBase') }));
221
+ }
222
+ let result;
223
+ try {
224
+ result = await core.saveDraft(doc.id, { baseRevisionId: Number(rawBase), data }, { actor, source: 'admin' });
225
+ }
226
+ catch (e) {
227
+ if (!(e instanceof InlayError))
228
+ throw e;
229
+ if (e.code === 'not_found')
230
+ return notFound(reply, ctx, actor);
231
+ if (e.code === 'validation') {
232
+ const { byName, unplaced } = placeIssues(registry, doc.type, data, e.details.issues ?? []);
233
+ const page = await editorPage(ctx, actor, doc, {
234
+ data,
235
+ base: submittedBase,
236
+ status: 400,
237
+ error: t('admin.editor.problems'),
238
+ problems: byName,
239
+ unplaced,
240
+ });
241
+ return send(reply, 400, page);
242
+ }
243
+ if (e.code === 'conflict') {
244
+ const current = await core.getDocument(doc.id);
245
+ if (!current || current.deletedAt !== null)
246
+ return notFound(reply, ctx, actor);
247
+ const conflict = { head: current.headRev, name: current.revision.authorName, source: current.revision.source };
248
+ return send(reply, 409, await editorPage(ctx, actor, current, { data, base: submittedBase, status: 409, conflict }));
249
+ }
250
+ if (e.code === 'invalid_operation') {
251
+ return send(reply, 400, await editorPage(ctx, actor, doc, { data, base: submittedBase, status: 400, error: e.message }));
252
+ }
253
+ throw e;
254
+ }
255
+ const next = form.get('_action');
256
+ if (next === 'preview') {
257
+ const live = await core.liveDocuments([doc.groupId], doc.locale, { state: 'preview' });
258
+ const path = live.get(doc.groupId)?.path ?? '/';
259
+ return reply.redirect(previewLink(ctx, path), 303);
260
+ }
261
+ if (next === 'publish') {
262
+ // With JS (`_dialog`), back to the editor, which opens the publish dialog; without, to the publish page.
263
+ const to = form.get('_dialog') === '1' ? `${editorLink(doc.id)}?review=publish` : publishLink(doc.id, 'publish');
264
+ return reply.redirect(to, 303);
265
+ }
266
+ return reply.redirect(`${editorLink(doc.id)}?notice=${result.changed ? 'saved' : 'unchanged'}`, 303);
267
+ });
268
+ scope.get('/admin/collections/:type/new', async (request, reply) => {
269
+ const actor = adminActor(request);
270
+ const { type } = request.params;
271
+ if (registry.types.get(type)?.kind !== 'collection')
272
+ return notFound(reply, ctx, actor);
273
+ // Entries start in the default language; other languages are added as translations.
274
+ const data = normalizeContent(registry, type, {});
275
+ return send(reply, 200, await newEntryPage(ctx, actor, type, registry.defaultLocale, { data }));
276
+ });
277
+ scope.post('/admin/collections/:type', async (request, reply) => {
278
+ const actor = adminActor(request);
279
+ const { type } = request.params;
280
+ if (registry.types.get(type)?.kind !== 'collection')
281
+ return notFound(reply, ctx, actor);
282
+ const form = formValues(request);
283
+ const asked = form.get('locale');
284
+ const locale = asked !== undefined && registry.locales.includes(asked) ? asked : registry.defaultLocale;
285
+ const data = parseDocumentForm(registry, type, form);
286
+ const op = form.get('_op');
287
+ if (op !== undefined) {
288
+ const next = applyFormOp(registry, type, data, op);
289
+ const { open, closed } = readOpenState(form);
290
+ const shown = { open: new Set(remapOpen(registry, type, data, op, open)), closed: new Set(closed) };
291
+ return send(reply, 200, await newEntryPage(ctx, actor, type, locale, { data: next, unsaved: true, ...shown }));
292
+ }
293
+ const input = {
294
+ ...(data.slug !== undefined && { slug: data.slug }),
295
+ ...(data.path !== undefined && { path: data.path }),
296
+ fields: data.fields,
297
+ slots: Object.fromEntries(Object.entries(data.slots).map(([key, slot]) => [key, slot.enabled ? slot.data : false])),
298
+ };
299
+ let created;
300
+ try {
301
+ created = await core.createEntry(type, { ...input, locale }, { actor, source: 'admin' });
302
+ }
303
+ catch (e) {
304
+ if (!(e instanceof InlayError))
305
+ throw e;
306
+ if (e.code === 'forbidden')
307
+ return forbidden(reply, ctx, actor);
308
+ if (e.code === 'validation') {
309
+ const { byName, unplaced } = placeIssues(registry, type, data, e.details.issues ?? []);
310
+ const page = await newEntryPage(ctx, actor, type, locale, {
311
+ data,
312
+ status: 400,
313
+ error: t('admin.editor.problems'),
314
+ problems: byName,
315
+ unplaced,
316
+ });
317
+ return send(reply, 400, page);
318
+ }
319
+ if (e.code === 'invalid_operation') {
320
+ return send(reply, 400, await newEntryPage(ctx, actor, type, locale, { data, status: 400, error: e.message }));
321
+ }
322
+ throw e;
323
+ }
324
+ if (form.get('_action') === 'preview') {
325
+ const live = await core.liveDocuments([created.groupId], created.locale, { state: 'preview' });
326
+ return reply.redirect(previewLink(ctx, live.get(created.groupId)?.path ?? '/'), 303);
327
+ }
328
+ return reply.redirect(`${editorLink(created.id)}?notice=created`, 303);
329
+ });
330
+ scope.post('/admin/documents/:id/translations', async (request, reply) => {
331
+ const actor = adminActor(request);
332
+ const { id } = request.params;
333
+ const doc = await core.getDocument(id);
334
+ if (!doc)
335
+ return notFound(reply, ctx, actor);
336
+ const locale = formValues(request).get('locale') ?? '';
337
+ try {
338
+ const created = await core.createTranslation(doc.groupId, locale, { actor, source: 'admin' });
339
+ return reply.redirect(`${editorLink(created.id)}?notice=translated`, 303);
340
+ }
341
+ catch (e) {
342
+ if (!(e instanceof InlayError))
343
+ throw e;
344
+ if (e.code === 'forbidden')
345
+ return forbidden(reply, ctx, actor);
346
+ if (e.code === 'not_found')
347
+ return notFound(reply, ctx, actor);
348
+ if (e.code === 'invalid_operation') {
349
+ return messagePage(reply, ctx, actor, 400, doc.title, e.message, placement(ctx, doc).section);
350
+ }
351
+ throw e;
352
+ }
353
+ });
354
+ scope.get('/admin/documents/:id/delete', async (request, reply) => {
355
+ const actor = adminActor(request);
356
+ const { id } = request.params;
357
+ const doc = await load(reply, actor, id);
358
+ if (!('revision' in doc))
359
+ return doc;
360
+ if (doc.kind !== 'entry')
361
+ return notFound(reply, ctx, actor);
362
+ const { section, breadcrumbs } = placement(ctx, doc);
363
+ const body = (_jsxs("form", { method: "post", action: `${editorLink(doc.id)}/delete`, class: "flex flex-col gap-4", children: [_jsx("p", { children: t('admin.delete.intro', { title: doc.title }) }), _jsxs("div", { class: "flex gap-2", children: [_jsx("button", { type: "submit", class: "btn btn-error", children: t('admin.delete.confirm') }), _jsx("a", { href: editorLink(doc.id), class: "btn btn-ghost", children: t('admin.delete.cancel') })] })] }));
364
+ const page = await adminPage(ctx, { title: t('admin.delete.title', { title: doc.title }), actor, section, breadcrumbs }, body);
365
+ return send(reply, 200, page);
366
+ });
367
+ scope.post('/admin/documents/:id/delete', async (request, reply) => {
368
+ const actor = adminActor(request);
369
+ const { id } = request.params;
370
+ const doc = await load(reply, actor, id);
371
+ if (!('revision' in doc))
372
+ return doc;
373
+ if (doc.kind !== 'entry')
374
+ return notFound(reply, ctx, actor);
375
+ const { section, breadcrumbs } = placement(ctx, doc);
376
+ try {
377
+ await core.deleteEntry(doc.groupId, { actor, source: 'admin' });
378
+ }
379
+ catch (e) {
380
+ if (!(e instanceof InlayError))
381
+ throw e;
382
+ if (e.code === 'forbidden')
383
+ return forbidden(reply, ctx, actor);
384
+ if (e.code === 'not_found')
385
+ return notFound(reply, ctx, actor);
386
+ if (e.code === 'in_use') {
387
+ const usages = e.details.usages ?? [];
388
+ const body = (_jsxs(_Fragment, { children: [_jsx(Alert, { kind: "error", children: e.message }), _jsx("p", { children: t('admin.delete.usedBy') }), _jsx("ul", { class: "list-disc pl-6", children: usages.map((u) => (_jsx("li", { children: _jsx("a", { href: editorLink(u.documentId), class: "link", children: u.title }) }))) }), _jsx("p", { children: _jsx("a", { href: editorLink(doc.id), class: "link", children: t('admin.editor.backToList', { list: doc.title }) }) })] }));
389
+ const page = await adminPage(ctx, { title: t('admin.delete.title', { title: doc.title }), actor, section, breadcrumbs, status: 409 }, body);
390
+ return send(reply, 409, page);
391
+ }
392
+ throw e;
393
+ }
394
+ return reply.redirect(`${breadcrumbs[0].href}${breadcrumbs[0].href.includes('?') ? '&' : '?'}notice=deleted`, 303);
395
+ });
396
+ scope.post('/admin/documents/:id/restore', async (request, reply) => {
397
+ const actor = adminActor(request);
398
+ const { id } = request.params;
399
+ const doc = await core.getDocument(id);
400
+ if (!doc)
401
+ return notFound(reply, ctx, actor);
402
+ try {
403
+ await core.restoreEntry(doc.groupId, { actor, source: 'admin' });
404
+ }
405
+ catch (e) {
406
+ if (!(e instanceof InlayError))
407
+ throw e;
408
+ if (e.code === 'forbidden')
409
+ return forbidden(reply, ctx, actor);
410
+ if (e.code === 'not_found')
411
+ return notFound(reply, ctx, actor);
412
+ throw e;
413
+ }
414
+ return reply.redirect(`${editorLink(doc.id)}?notice=restored`, 303);
415
+ });
416
+ }
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import { type AdminContext } from '../context.js';
3
+ /** The history of a document: its saved versions, and any one of them with the option to restore it. */
4
+ export declare function registerHistory(scope: FastifyInstance, ctx: AdminContext): void;
@@ -0,0 +1,105 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { formatDiff } from '../../../core/content/diff.js';
3
+ import { InlayError } from '../../../core/errors.js';
4
+ import { t } from '../../../core/messages/index.js';
5
+ import { loadAgentRefs } from '../../mcp/agent-refs.js';
6
+ import { adminActor, HTML, notFound } from '../context.js';
7
+ import { DocumentFields } from '../form/walk.js';
8
+ import { DataTable } from '../views/data-table.js';
9
+ import { adminPage, Time } from '../views/layout.js';
10
+ import { Badge, sourceLabel } from '../views/status.js';
11
+ import { editorLink, placement } from './editor.js';
12
+ const REVISION = /^\d{1,15}$/;
13
+ const historyLink = (id) => `${editorLink(id)}/history`;
14
+ function ChangeList({ lines }) {
15
+ if (lines.length === 0)
16
+ return _jsx("p", { children: t('admin.history.noChanges') });
17
+ return (_jsx("ul", { class: "list-disc pl-6", children: lines.map((line) => (_jsx("li", { children: line }))) }));
18
+ }
19
+ /** The history of a document: its saved versions, and any one of them with the option to restore it. */
20
+ export function registerHistory(scope, ctx) {
21
+ const { core } = ctx;
22
+ const { registry } = core;
23
+ const send = (reply, status, body) => reply.code(status).type(HTML).send(body);
24
+ /** The live document, or `undefined` when it is unknown or deleted. */
25
+ async function load(id) {
26
+ const doc = await core.getDocument(id);
27
+ return doc && doc.deletedAt === null ? doc : undefined;
28
+ }
29
+ scope.get('/admin/documents/:id/history', async (request, reply) => {
30
+ const actor = adminActor(request);
31
+ const { id } = request.params;
32
+ const doc = await load(id);
33
+ if (!doc)
34
+ return notFound(reply, ctx, actor);
35
+ const revisions = await core.listRevisions(doc.id);
36
+ const { section, breadcrumbs } = placement(ctx, doc);
37
+ const body = (_jsxs(_Fragment, { children: [_jsx("p", { class: "mb-4", children: t('admin.history.intro') }), _jsx(DataTable, { id: "history", caption: t('admin.history.title', { title: doc.title }), base: `${historyLink(doc.id)}`, rows: revisions, rowKey: (rev) => String(rev.id), rowLabel: (rev) => rev.createdAt, empty: t('admin.history.noChanges'), columns: [
38
+ {
39
+ key: 'when',
40
+ label: t('admin.history.when'),
41
+ cell: (rev) => (_jsx("a", { href: `${historyLink(doc.id)}/${rev.id}`, class: "link", children: _jsx(Time, { iso: rev.createdAt, relative: true }) })),
42
+ },
43
+ { key: 'author', label: t('admin.history.author'), cell: (rev) => rev.authorName },
44
+ { key: 'how', label: t('admin.history.how'), cell: (rev) => sourceLabel(rev.source) },
45
+ { key: 'message', label: t('admin.history.message'), cell: (rev) => rev.message ?? '' },
46
+ {
47
+ key: 'state',
48
+ label: t('admin.history.state'),
49
+ cell: (rev) => (_jsxs("div", { class: "flex flex-wrap gap-1", children: [rev.id === doc.publishedRev && _jsx(Badge, { tone: "success", children: t('admin.history.published') }), rev.id === doc.headRev && _jsx(Badge, { tone: "warning", children: t('admin.history.current') })] })),
50
+ },
51
+ ] })] }));
52
+ const page = await adminPage(ctx, {
53
+ title: t('admin.history.title', { title: doc.title }),
54
+ actor,
55
+ section,
56
+ breadcrumbs: [...breadcrumbs, { label: doc.title, href: editorLink(doc.id) }],
57
+ }, body);
58
+ return send(reply, 200, page);
59
+ });
60
+ scope.get('/admin/documents/:id/history/:rev', async (request, reply) => {
61
+ const actor = adminActor(request);
62
+ const { id, rev: rawRev } = request.params;
63
+ const doc = await load(id);
64
+ if (!doc || !REVISION.test(rawRev))
65
+ return notFound(reply, ctx, actor);
66
+ const revisionId = Number(rawRev);
67
+ const [revision, revisions] = await Promise.all([core.getRevision(revisionId), core.listRevisions(doc.id)]);
68
+ if (!revision || revision.documentId !== doc.id)
69
+ return notFound(reply, ctx, actor);
70
+ const index = revisions.findIndex((r) => r.id === revisionId);
71
+ const previous = revisions[index + 1];
72
+ const [changes, sinceThen, refs] = await Promise.all([
73
+ core.diffRevisions(previous?.id ?? null, revisionId),
74
+ revisionId === doc.headRev ? Promise.resolve(null) : core.diffRevisions(revisionId, doc.headRev),
75
+ loadAgentRefs({ core, baseUrl: ctx.baseUrl }, doc.type, doc.locale, revision.data),
76
+ ]);
77
+ const { section, breadcrumbs } = placement(ctx, doc);
78
+ const meta = revision.meta;
79
+ const body = (_jsxs(_Fragment, { children: [_jsxs("p", { class: "mb-6", children: [_jsx(Time, { iso: meta.createdAt }), " ", t('admin.editor.savedBy', { name: meta.authorName, source: sourceLabel(meta.source) })] }), _jsxs("section", { "aria-labelledby": "h-changes", class: "mb-6", children: [_jsx("h2", { id: "h-changes", class: "mb-2 text-xl font-semibold", children: t('admin.history.changes') }), _jsx(ChangeList, { lines: formatDiff(changes) })] }), sinceThen && (_jsxs("section", { "aria-labelledby": "h-now", class: "mb-6", children: [_jsx("h2", { id: "h-now", class: "mb-2 text-xl font-semibold", children: t('admin.history.changesNow') }), _jsx(ChangeList, { lines: formatDiff(sinceThen) })] })), _jsxs("section", { "aria-labelledby": "h-restore", class: "mb-6", children: [_jsx("h2", { id: "h-restore", class: "sr-only", children: t('admin.history.restore') }), _jsxs("form", { method: "post", action: `${historyLink(doc.id)}/${revisionId}/restore`, class: "flex flex-col items-start gap-2", children: [_jsx("button", { type: "submit", class: "btn btn-primary", "aria-describedby": "restore-hint", children: t('admin.history.restore') }), _jsx("p", { id: "restore-hint", class: "text-sm", children: t('admin.history.restoreHint') })] })] }), _jsxs("section", { id: "version", "aria-labelledby": "h-version", class: "mb-6", children: [_jsx("h2", { id: "h-version", class: "mb-2 text-xl font-semibold", children: t('admin.history.thisVersion') }), _jsx("div", { class: "flex flex-col gap-4", children: _jsx(DocumentFields, { ctx: { registry, type: doc.type, locale: doc.locale, refs, readOnly: true }, data: revision.data }) })] }), _jsx("p", { children: _jsx("a", { href: historyLink(doc.id), class: "link", children: t('admin.history.backToList') }) })] }));
80
+ const page = await adminPage(ctx, {
81
+ title: t('admin.history.title', { title: doc.title }),
82
+ actor,
83
+ section,
84
+ breadcrumbs: [...breadcrumbs, { label: doc.title, href: editorLink(doc.id) }, { label: t('admin.editor.history'), href: historyLink(doc.id) }],
85
+ scripts: ['editor.js'],
86
+ }, body);
87
+ return send(reply, 200, page);
88
+ });
89
+ scope.post('/admin/documents/:id/history/:rev/restore', async (request, reply) => {
90
+ const actor = adminActor(request);
91
+ const { id, rev: rawRev } = request.params;
92
+ const doc = await load(id);
93
+ if (!doc || !REVISION.test(rawRev))
94
+ return notFound(reply, ctx, actor);
95
+ try {
96
+ await core.restoreRevision(doc.id, Number(rawRev), { actor, source: 'admin' });
97
+ }
98
+ catch (e) {
99
+ if (e instanceof InlayError && (e.code === 'not_found' || e.code === 'invalid_operation'))
100
+ return notFound(reply, ctx, actor);
101
+ throw e;
102
+ }
103
+ return reply.redirect(`${editorLink(doc.id)}?notice=restored`, 303);
104
+ });
105
+ }
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import { type AdminContext } from '../context.js';
3
+ /** The pages, site-wide content and collection lists of the admin. */
4
+ export declare function registerLists(scope: FastifyInstance, ctx: AdminContext): void;