tinyzoo 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 (391) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +46 -2
  3. package/app/app.config.ts +35 -0
  4. package/app/assets/brand/characters/bright/bird.svg +1 -0
  5. package/app/assets/brand/characters/bright/bunny.svg +1 -0
  6. package/app/assets/brand/characters/bright/elephant.svg +1 -0
  7. package/app/assets/brand/characters/bright/fox.svg +1 -0
  8. package/app/assets/brand/characters/bright/frog.svg +1 -0
  9. package/app/assets/brand/characters/bright/octopus.svg +1 -0
  10. package/app/assets/brand/characters/muted/bee.svg +1 -0
  11. package/app/assets/brand/characters/muted/bird.svg +1 -0
  12. package/app/assets/brand/characters/muted/butterfly.svg +1 -0
  13. package/app/assets/brand/characters/muted/chick.svg +1 -0
  14. package/app/assets/brand/characters/muted/cow.svg +1 -0
  15. package/app/assets/brand/characters/muted/deer.svg +1 -0
  16. package/app/assets/brand/characters/muted/duck.svg +1 -0
  17. package/app/assets/brand/characters/muted/elephant.svg +1 -0
  18. package/app/assets/brand/characters/muted/fox.svg +1 -0
  19. package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
  20. package/app/assets/brand/characters/muted/koala.svg +1 -0
  21. package/app/assets/brand/characters/muted/ladybug.svg +1 -0
  22. package/app/assets/brand/characters/muted/lion.svg +1 -0
  23. package/app/assets/brand/characters/muted/mouse.svg +1 -0
  24. package/app/assets/brand/characters/muted/octopus.svg +1 -0
  25. package/app/assets/brand/characters/muted/owl.svg +1 -0
  26. package/app/assets/brand/characters/muted/panda.svg +1 -0
  27. package/app/assets/brand/characters/muted/penguin.svg +1 -0
  28. package/app/assets/brand/characters/muted/pig.svg +1 -0
  29. package/app/assets/brand/characters/muted/poodle.svg +1 -0
  30. package/app/assets/brand/characters/muted/raccoon.svg +1 -0
  31. package/app/assets/brand/characters/muted/seal.svg +1 -0
  32. package/app/assets/brand/characters/muted/sheep.svg +1 -0
  33. package/app/assets/brand/characters/muted/snail.svg +1 -0
  34. package/app/assets/brand/characters/muted/turtle.svg +1 -0
  35. package/app/assets/brand/characters/muted/whale.svg +1 -0
  36. package/app/assets/brand/logo/favicon.svg +1 -0
  37. package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
  38. package/app/assets/brand/logo/logo-primary.svg +1 -0
  39. package/app/assets/brand/logo/mascot-reversed.svg +1 -0
  40. package/app/assets/brand/logo/mascot.svg +1 -0
  41. package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
  42. package/app/assets/brand/logo/wordmark.svg +1 -0
  43. package/app/assets/css/cms-admin.css +607 -0
  44. package/app/components/CmsBlocks.vue +30 -0
  45. package/app/components/CmsCell.vue +16 -0
  46. package/app/components/CmsCellBadge.vue +18 -0
  47. package/app/components/CmsCellBlocks.vue +9 -0
  48. package/app/components/CmsCellBoolean.vue +12 -0
  49. package/app/components/CmsCellCode.vue +7 -0
  50. package/app/components/CmsCellColor.vue +13 -0
  51. package/app/components/CmsCellDate.vue +10 -0
  52. package/app/components/CmsCellExcerpt.vue +21 -0
  53. package/app/components/CmsCellGallery.vue +10 -0
  54. package/app/components/CmsCellGroup.vue +23 -0
  55. package/app/components/CmsCellNumber.vue +7 -0
  56. package/app/components/CmsCellRelation.vue +8 -0
  57. package/app/components/CmsCellText.vue +12 -0
  58. package/app/components/CmsCellThumb.vue +18 -0
  59. package/app/components/CmsConfirmDialog.vue +55 -0
  60. package/app/components/CmsContent.vue +103 -0
  61. package/app/components/CmsDayPicker.vue +44 -0
  62. package/app/components/CmsEmptyState.vue +35 -0
  63. package/app/components/CmsField.vue +111 -0
  64. package/app/components/CmsFieldBlocks.vue +353 -0
  65. package/app/components/CmsFieldBoolean.vue +8 -0
  66. package/app/components/CmsFieldColor.vue +42 -0
  67. package/app/components/CmsFieldDate.vue +131 -0
  68. package/app/components/CmsFieldGallery.vue +114 -0
  69. package/app/components/CmsFieldGroup.vue +53 -0
  70. package/app/components/CmsFieldMedia.vue +219 -0
  71. package/app/components/CmsFieldNumber.vue +11 -0
  72. package/app/components/CmsFieldRelationMany.vue +54 -0
  73. package/app/components/CmsFieldRelationOne.vue +47 -0
  74. package/app/components/CmsFieldRichText.vue +45 -0
  75. package/app/components/CmsFieldSelect.vue +41 -0
  76. package/app/components/CmsFieldSlug.vue +46 -0
  77. package/app/components/CmsFieldText.vue +75 -0
  78. package/app/components/CmsFormSections.vue +150 -0
  79. package/app/components/CmsHighlight.vue +22 -0
  80. package/app/components/CmsImage.vue +39 -0
  81. package/app/components/CmsLinkPicker.vue +122 -0
  82. package/app/components/CmsLinkTarget.vue +35 -0
  83. package/app/components/CmsListFilters.vue +107 -0
  84. package/app/components/CmsLiveNotice.vue +64 -0
  85. package/app/components/CmsLoadError.vue +24 -0
  86. package/app/components/CmsMascot.vue +10 -0
  87. package/app/components/CmsMediaLibrary.vue +114 -0
  88. package/app/components/CmsMediaPreview.vue +34 -0
  89. package/app/components/CmsMediaThumb.vue +22 -0
  90. package/app/components/CmsMoment.vue +42 -0
  91. package/app/components/CmsNav.vue +39 -0
  92. package/app/components/CmsPage.vue +86 -0
  93. package/app/components/CmsPasswordInput.vue +22 -0
  94. package/app/components/CmsPresence.vue +29 -0
  95. package/app/components/CmsPreviewPanel.vue +131 -0
  96. package/app/components/CmsPublishReview.vue +102 -0
  97. package/app/components/CmsRevisions.vue +195 -0
  98. package/app/components/CmsRichTextEditor.vue +290 -0
  99. package/app/components/CmsSearch.vue +99 -0
  100. package/app/components/CmsSection.vue +20 -0
  101. package/app/components/CmsSingletonForm.vue +283 -0
  102. package/app/components/CmsStatusBadge.vue +21 -0
  103. package/app/components/CmsTime.vue +16 -0
  104. package/app/components/CmsTranslationRef.vue +27 -0
  105. package/app/components/CmsTreeList.vue +453 -0
  106. package/app/components/CmsUnsavedText.vue +34 -0
  107. package/app/components/CmsWordmark.vue +10 -0
  108. package/app/composables/useCmsAdminHead.ts +18 -0
  109. package/app/composables/useCmsCollab.ts +165 -0
  110. package/app/composables/useCmsConfirm.ts +39 -0
  111. package/app/composables/useCmsEntryActions.ts +75 -0
  112. package/app/composables/useCmsFocus.ts +13 -0
  113. package/app/composables/useCmsForm.ts +273 -0
  114. package/app/composables/useCmsI18n.ts +185 -0
  115. package/app/composables/useCmsLinkTargets.ts +84 -0
  116. package/app/composables/useCmsLive.ts +199 -0
  117. package/app/composables/useCmsSearch.ts +62 -0
  118. package/app/composables/useCmsSeo.ts +99 -0
  119. package/app/composables/useCmsSignedIn.ts +24 -0
  120. package/app/composables/useCmsUiLocale.ts +24 -0
  121. package/app/i18n/cs.ts +781 -0
  122. package/app/i18n/de.ts +781 -0
  123. package/app/i18n/en.ts +782 -0
  124. package/app/i18n/types.ts +22 -0
  125. package/app/layouts/admin.vue +224 -0
  126. package/app/layouts/cms-auth.vue +37 -0
  127. package/app/middleware/cms-api-not-a-page.global.ts +10 -0
  128. package/app/middleware/cms-auth.global.ts +16 -0
  129. package/app/pages/admin/[entity]/[id].vue +1109 -0
  130. package/app/pages/admin/[entity]/index.vue +733 -0
  131. package/app/pages/admin/account.vue +117 -0
  132. package/app/pages/admin/forgot.vue +50 -0
  133. package/app/pages/admin/index.vue +184 -0
  134. package/app/pages/admin/invite/[token].vue +73 -0
  135. package/app/pages/admin/login.vue +84 -0
  136. package/app/pages/admin/media.vue +494 -0
  137. package/app/pages/admin/privacy.vue +193 -0
  138. package/app/pages/admin/reset/[token].vue +52 -0
  139. package/app/pages/admin/setup.vue +87 -0
  140. package/app/pages/admin/styleguide.vue +261 -0
  141. package/app/pages/admin/team.vue +258 -0
  142. package/app/plugins/cmsLivePreview.client.ts +20 -0
  143. package/app/plugins/cmsSignedOut.client.ts +31 -0
  144. package/app/utils/cmsBlockType.ts +11 -0
  145. package/app/utils/cmsBrand.ts +38 -0
  146. package/app/utils/cmsDiff.ts +83 -0
  147. package/app/utils/cmsFetch.ts +7 -0
  148. package/app/utils/cmsFocusInvalid.ts +22 -0
  149. package/app/utils/cmsIssues.ts +128 -0
  150. package/app/utils/cmsJson.ts +28 -0
  151. package/app/utils/cmsMedia.ts +63 -0
  152. package/app/utils/cmsSections.ts +154 -0
  153. package/app/utils/cmsTime.ts +41 -0
  154. package/cli/backup.ts +713 -0
  155. package/cli/breaking.ts +174 -0
  156. package/cli/content-migrate.ts +239 -0
  157. package/cli/db.ts +86 -0
  158. package/cli/export.ts +336 -0
  159. package/cli/generate.ts +146 -0
  160. package/cli/import.ts +643 -0
  161. package/cli/index.ts +140 -0
  162. package/cli/links-convert.ts +291 -0
  163. package/cli/seed-engine.ts +705 -0
  164. package/cli/seed.ts +339 -0
  165. package/cli/status.ts +49 -0
  166. package/cli/tar.ts +304 -0
  167. package/cli/transfer.ts +677 -0
  168. package/cli/up.ts +27 -0
  169. package/cli/upgrade.ts +60 -0
  170. package/cli/versions.ts +60 -0
  171. package/forms/components/CmsForm.vue +186 -0
  172. package/forms/index.ts +203 -0
  173. package/forms/messages.ts +104 -0
  174. package/forms/retention.ts +48 -0
  175. package/forms/server/form.get.ts +12 -0
  176. package/forms/server/form.post.ts +109 -0
  177. package/forms/server/formSettings.ts +12 -0
  178. package/forms/server/forms.ts +127 -0
  179. package/module.ts +373 -0
  180. package/nuxt.config.ts +43 -0
  181. package/package.json +99 -3
  182. package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
  183. package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
  184. package/server/api/cms/[entity]/[id].delete.ts +52 -0
  185. package/server/api/cms/[entity]/[id].get.ts +21 -0
  186. package/server/api/cms/[entity]/[id].patch.ts +116 -0
  187. package/server/api/cms/[entity]/_export.get.ts +69 -0
  188. package/server/api/cms/[entity]/_move.post.ts +81 -0
  189. package/server/api/cms/[entity]/_order.post.ts +49 -0
  190. package/server/api/cms/[entity]/_tree.get.ts +41 -0
  191. package/server/api/cms/[entity]/index.get.ts +62 -0
  192. package/server/api/cms/[entity]/index.post.ts +38 -0
  193. package/server/api/cms/[entity]/options.get.ts +55 -0
  194. package/server/api/cms/_auth/accept.post.ts +33 -0
  195. package/server/api/cms/_auth/forgot.post.ts +39 -0
  196. package/server/api/cms/_auth/invite/[token].get.ts +18 -0
  197. package/server/api/cms/_auth/login.post.ts +42 -0
  198. package/server/api/cms/_auth/logout.post.ts +7 -0
  199. package/server/api/cms/_auth/me.get.ts +5 -0
  200. package/server/api/cms/_auth/me.patch.ts +32 -0
  201. package/server/api/cms/_auth/password.post.ts +29 -0
  202. package/server/api/cms/_auth/reset.post.ts +34 -0
  203. package/server/api/cms/_auth/setup.post.ts +46 -0
  204. package/server/api/cms/_auth/status.get.ts +18 -0
  205. package/server/api/cms/_collab/session.get.ts +30 -0
  206. package/server/api/cms/_collab/socket.ts +51 -0
  207. package/server/api/cms/_collab/unsaved.delete.ts +16 -0
  208. package/server/api/cms/_graph.get.ts +20 -0
  209. package/server/api/cms/_links/resolve.post.ts +17 -0
  210. package/server/api/cms/_links.get.ts +81 -0
  211. package/server/api/cms/_live.ts +30 -0
  212. package/server/api/cms/_media/[id]/usage.get.ts +14 -0
  213. package/server/api/cms/_media/[id].delete.ts +29 -0
  214. package/server/api/cms/_media/[id].get.ts +13 -0
  215. package/server/api/cms/_media/[id].patch.ts +64 -0
  216. package/server/api/cms/_media/exists.post.ts +15 -0
  217. package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
  218. package/server/api/cms/_media/index.get.ts +44 -0
  219. package/server/api/cms/_media/index.post.ts +147 -0
  220. package/server/api/cms/_media/raw/[...key].get.ts +85 -0
  221. package/server/api/cms/_media/raw/[...key].head.ts +2 -0
  222. package/server/api/cms/_overview.get.ts +87 -0
  223. package/server/api/cms/_preview.post.ts +17 -0
  224. package/server/api/cms/_privacy/delete.post.ts +14 -0
  225. package/server/api/cms/_privacy/export.post.ts +25 -0
  226. package/server/api/cms/_privacy/lookup.post.ts +27 -0
  227. package/server/api/cms/_search.get.ts +17 -0
  228. package/server/api/cms/_singleton/[name].get.ts +19 -0
  229. package/server/api/cms/_singleton/[name].put.ts +76 -0
  230. package/server/api/cms/_users/[id]/resend.post.ts +25 -0
  231. package/server/api/cms/_users/[id].delete.ts +21 -0
  232. package/server/api/cms/_users/[id].patch.ts +45 -0
  233. package/server/api/cms/_users/index.get.ts +28 -0
  234. package/server/api/cms/_users/index.post.ts +39 -0
  235. package/server/api/content/[entity]/[slug].get.ts +74 -0
  236. package/server/api/content/[entity]/index.get.ts +100 -0
  237. package/server/api/content/_global/[name].get.ts +23 -0
  238. package/server/api/content/_search.get.ts +28 -0
  239. package/server/api/content/_sitemap.get.ts +8 -0
  240. package/server/api/content/_tree/[entity].get.ts +31 -0
  241. package/server/api/content-types.ts.get.ts +17 -0
  242. package/server/api/health/live.get.ts +10 -0
  243. package/server/api/health/ready.get.ts +21 -0
  244. package/server/api/openapi.get.ts +48 -0
  245. package/server/api/openapi.json.get.ts +32 -0
  246. package/server/db/driver.ts +8 -0
  247. package/server/mail/mailer.ts +43 -0
  248. package/server/middleware/cms-0-headers.ts +37 -0
  249. package/server/middleware/cms-0-migrate-gate.ts +14 -0
  250. package/server/middleware/cms-csrf.ts +28 -0
  251. package/server/middleware/cms-limits.ts +20 -0
  252. package/server/middleware/cms-redirects.ts +21 -0
  253. package/server/middleware/cms-session.ts +41 -0
  254. package/server/middleware/cms-z-plugin-access.ts +15 -0
  255. package/server/plugins/cms-0-config-check.ts +35 -0
  256. package/server/plugins/cms-changes.ts +53 -0
  257. package/server/plugins/cms-content-etag.ts +21 -0
  258. package/server/plugins/cms-errors.ts +45 -0
  259. package/server/plugins/cms-migrate.ts +5 -0
  260. package/server/plugins/cms-plugins.ts +17 -0
  261. package/server/plugins/cms-search.ts +12 -0
  262. package/server/plugins/cms-setup-code.ts +15 -0
  263. package/server/routes/sitemap.xml.get.ts +25 -0
  264. package/server/store/redis.ts +95 -0
  265. package/server/store/types.ts +21 -0
  266. package/server/tasks/cms/retention.ts +10 -0
  267. package/server/tasks/cms/scheduled.ts +10 -0
  268. package/server/tasks/cms/search-reindex.ts +12 -0
  269. package/server/utils/cmsAudit.ts +29 -0
  270. package/server/utils/cmsAuth.ts +143 -0
  271. package/server/utils/cmsBlocks.ts +47 -0
  272. package/server/utils/cmsChanges.ts +222 -0
  273. package/server/utils/cmsCollab.ts +286 -0
  274. package/server/utils/cmsCollabServer.ts +451 -0
  275. package/server/utils/cmsCollate.ts +27 -0
  276. package/server/utils/cmsContent.ts +376 -0
  277. package/server/utils/cmsCrud.ts +361 -0
  278. package/server/utils/cmsCsv.ts +24 -0
  279. package/server/utils/cmsDb.ts +23 -0
  280. package/server/utils/cmsDemo.ts +36 -0
  281. package/server/utils/cmsEmails.ts +125 -0
  282. package/server/utils/cmsErrors.ts +40 -0
  283. package/server/utils/cmsFold.ts +17 -0
  284. package/server/utils/cmsImageSizes.ts +51 -0
  285. package/server/utils/cmsJson.ts +6 -0
  286. package/server/utils/cmsLinkAddress.ts +50 -0
  287. package/server/utils/cmsLinks.ts +248 -0
  288. package/server/utils/cmsListQuery.ts +93 -0
  289. package/server/utils/cmsLive.ts +392 -0
  290. package/server/utils/cmsLocales.ts +96 -0
  291. package/server/utils/cmsMail.ts +28 -0
  292. package/server/utils/cmsMediaGc.ts +188 -0
  293. package/server/utils/cmsMediaKeys.ts +62 -0
  294. package/server/utils/cmsMigrate.ts +86 -0
  295. package/server/utils/cmsPreviewDraft.ts +72 -0
  296. package/server/utils/cmsPrivacy.ts +176 -0
  297. package/server/utils/cmsPublished.ts +57 -0
  298. package/server/utils/cmsRange.ts +38 -0
  299. package/server/utils/cmsRateLimit.ts +82 -0
  300. package/server/utils/cmsRedirects.ts +160 -0
  301. package/server/utils/cmsRetention.ts +61 -0
  302. package/server/utils/cmsRevisions.ts +103 -0
  303. package/server/utils/cmsScheduler.ts +45 -0
  304. package/server/utils/cmsScrub.ts +107 -0
  305. package/server/utils/cmsSearch.ts +354 -0
  306. package/server/utils/cmsSession.ts +102 -0
  307. package/server/utils/cmsSetupCode.ts +97 -0
  308. package/server/utils/cmsSitemap.ts +176 -0
  309. package/server/utils/cmsStorage.ts +580 -0
  310. package/server/utils/cmsStore.ts +109 -0
  311. package/server/utils/cmsTooMany.ts +9 -0
  312. package/server/utils/cmsTranslationWrite.ts +186 -0
  313. package/server/utils/cmsTree.ts +251 -0
  314. package/server/utils/cmsTreeAddress.ts +65 -0
  315. package/server/utils/cmsUpload.ts +197 -0
  316. package/server/utils/cmsWebhooks.ts +101 -0
  317. package/shared/json.ts +11 -0
  318. package/shared/richtext-editor.ts +56 -0
  319. package/shared/richtext-normalize.ts +33 -0
  320. package/shared/richtext-paste.ts +151 -0
  321. package/shared/storage-delivery.ts +53 -0
  322. package/src/blocks.ts +624 -0
  323. package/src/changes.ts +54 -0
  324. package/src/content-shape.ts +340 -0
  325. package/src/deprecate.ts +64 -0
  326. package/src/descriptor.ts +149 -0
  327. package/src/docs.ts +27 -0
  328. package/src/emitter.ts +94 -0
  329. package/src/entity.ts +624 -0
  330. package/src/errorReport.ts +41 -0
  331. package/src/fields.ts +465 -0
  332. package/src/i18n.ts +26 -0
  333. package/src/index.ts +54 -0
  334. package/src/linkref.ts +31 -0
  335. package/src/links.ts +179 -0
  336. package/src/locales.ts +39 -0
  337. package/src/media.ts +48 -0
  338. package/src/migrate.ts +236 -0
  339. package/src/openapi.ts +377 -0
  340. package/src/paths.ts +88 -0
  341. package/src/plugin.ts +505 -0
  342. package/src/presets.ts +230 -0
  343. package/src/richtext.ts +88 -0
  344. package/src/sdk.ts +181 -0
  345. package/src/search.ts +312 -0
  346. package/src/seed.ts +225 -0
  347. package/src/setupCode.ts +30 -0
  348. package/src/system.ts +219 -0
  349. package/src/tree.ts +421 -0
  350. package/src/upgrades.ts +137 -0
  351. package/starter/.env.example +10 -0
  352. package/starter/README.md +65 -0
  353. package/starter/app/app.config.ts +10 -0
  354. package/starter/app/app.vue +12 -0
  355. package/starter/app/assets/css/main.css +15 -0
  356. package/starter/app/components/global/BlockContact.vue +15 -0
  357. package/starter/app/components/global/BlockCta.vue +15 -0
  358. package/starter/app/components/global/BlockHero.vue +23 -0
  359. package/starter/app/components/global/BlockImage.vue +13 -0
  360. package/starter/app/components/global/BlockText.vue +12 -0
  361. package/starter/app/composables/useSite.ts +77 -0
  362. package/starter/app/error.vue +28 -0
  363. package/starter/app/layouts/default.vue +106 -0
  364. package/starter/app/lib/cms-content.ts +152 -0
  365. package/starter/app/pages/[...slug].vue +66 -0
  366. package/starter/app/pages/hledat.vue +59 -0
  367. package/starter/app/pages/index.vue +20 -0
  368. package/starter/cms.config.ts +137 -0
  369. package/starter/compose.yaml +15 -0
  370. package/starter/drizzle.config.ts +8 -0
  371. package/starter/gitignore.txt +8 -0
  372. package/starter/nuxt.config.ts +13 -0
  373. package/starter/package.json +38 -0
  374. package/starter/scripts/typecheck.mjs +38 -0
  375. package/starter/seed/index.ts +297 -0
  376. package/starter/seed/media/about.jpg +0 -0
  377. package/starter/seed/media/hero.jpg +0 -0
  378. package/starter/seed/media/logo.png +0 -0
  379. package/starter/seed/media/news-bread.jpg +0 -0
  380. package/starter/seed/media/news-morning.jpg +0 -0
  381. package/starter/server/db/migrations/0000_init.sql +269 -0
  382. package/starter/server/db/migrations/0001_page_tree.sql +5 -0
  383. package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
  384. package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
  385. package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
  386. package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
  387. package/starter/server/db/migrations/meta/_journal.json +27 -0
  388. package/starter/server/db/schema.ts +253 -0
  389. package/starter/server/plugins/sitemap.ts +11 -0
  390. package/starter/server/routes/robots.txt.get.ts +12 -0
  391. package/starter/tsconfig.json +9 -0
@@ -0,0 +1,1109 @@
1
+ <script setup lang="ts">
2
+ // Entry editor. The title is the page heading; content fields fill the main column;
3
+ // properties (status, URL, dates, relations…) sit in a side panel; grouped fields
4
+ // (e.g. "Search & sharing") collapse at the bottom of the panel. Status is shown once
5
+ // and changed through the header's single primary action.
6
+ //
7
+ // Remount per record so state/dirty/guard fully reset when switching records
8
+ // (and after a create→redirect), rather than reusing a stale component instance.
9
+ import type { LiveChange } from '../../../composables/useCmsLive'
10
+
11
+ definePageMeta({ layout: 'admin', key: (route) => route.fullPath })
12
+ const route = useRoute()
13
+ const router = useRouter()
14
+ const toast = useToast()
15
+ const { t, tl, languageName, entityLabel, entitySingular, fieldLabel, formatDate, fieldHelp } = useCmsI18n()
16
+ const entity = computed(() => route.params.entity as string)
17
+ const id = computed(() => route.params.id as string)
18
+ const isNew = computed(() => id.value === 'new')
19
+
20
+ const { data: graph } = await useFetch<any[]>('/api/cms/_graph', { key: 'cms-graph' })
21
+ const meta = computed(() => (graph.value ?? []).find((e: any) => e.name === entity.value))
22
+ // The manual-order position is set by arranging the list, never by this form (a stale
23
+ // position saved from here would undo someone's reordering).
24
+ const form = useCmsForm(computed(() => (meta.value?.fields ?? []).filter((f: any) => f.key !== meta.value?.orderField)), isNew)
25
+ const { state, fieldErrors, editable, dirty, saving, conflict } = form
26
+
27
+ // ── content languages ──
28
+ // The default language is the entry itself; others are translations of the
29
+ // `.localized()` fields (?locale=en). The page remounts when the language changes.
30
+ const locales = computed(() => meta.value?.locales as { default: string; all: string[]; labels: Record<string, any> } | null)
31
+ const currentLocale = computed(() => {
32
+ const q = route.query.locale
33
+ return typeof q === 'string' && locales.value?.all.includes(q) ? q : (locales.value?.default ?? null)
34
+ })
35
+ const isTranslation = computed(() => !!locales.value && !isNew.value && currentLocale.value !== locales.value.default)
36
+ // "The other fields are shared" only when there are other fields.
37
+ const hasSharedFields = computed(() => (meta.value?.fields ?? []).some((f: any) => !f.localized && f.relation?.kind !== 'one-to-many' && f.key !== meta.value?.orderField))
38
+ const localeLabel = (code?: string | null) => (code ? tl(locales.value?.labels?.[code], code.toUpperCase()) : '')
39
+ // In a sentence a language is named in the admin's own language ("angličtina"), not spelled its own way.
40
+ const localeName = (code?: string | null) => languageName(code, code ? locales.value?.labels?.[code] : null)
41
+ const defaultLabel = computed(() => localeName(locales.value?.default))
42
+ const available = ref<string[]>([])
43
+ const defaults = ref<Record<string, any>>({})
44
+ const translated = ref(false)
45
+
46
+ // May this person save here? Told by the server with the entry (the same rules a save
47
+ // applies); when not, the form opens read-only with the reason, not a save that fails.
48
+ const can = ref<{ update: boolean; why?: 'role' | 'owner' | 'published' }>({ update: true })
49
+ const cannotCreate = computed(() => isNew.value && meta.value?.can?.create === false)
50
+ const readOnly = computed(() => cannotCreate.value || (!isNew.value && can.value.update === false))
51
+ provide('cmsReadOnly', readOnly)
52
+
53
+ const savedAt = ref<string | null>(null)
54
+ const createdAt = ref<string | null>(null)
55
+ // The version this tab edits (the entry's updatedAt): sent with every save, so saving
56
+ // over someone else's newer version is refused unless the editor chooses to.
57
+ const version = ref<string | null>(null)
58
+ const rowUrl = (): string => `/api/cms/${entity.value}/${id.value}${isTranslation.value ? `?locale=${currentLocale.value}` : ''}`
59
+ function adopt(row: Record<string, any> | null | undefined) {
60
+ savedAt.value = row?.updatedAt ?? null
61
+ createdAt.value = row?.createdAt ?? null
62
+ // A translation has its own version.
63
+ version.value = (isTranslation.value ? row?.__version : row?.updatedAt) ?? null
64
+ available.value = row?.__locales ?? []
65
+ defaults.value = row?.__defaults ?? {}
66
+ translated.value = !!row?.__translated
67
+ }
68
+ // An address of an entry that does not exist (deleted, mistyped): say so, never a blank editor.
69
+ const missing = ref(false)
70
+ if (!isNew.value) {
71
+ const { data, error: rowError } = await useFetch<{ row: Record<string, any>; can?: typeof can.value }>(rowUrl)
72
+ missing.value = rowError.value?.statusCode === 404 || rowError.value?.statusCode === 400
73
+ if (data.value?.can) can.value = data.value.can
74
+ form.load(data.value?.row)
75
+ adopt(data.value?.row)
76
+ }
77
+ else {
78
+ // "Add a subpage" opens a new page with its parent chosen.
79
+ const parent = meta.value?.tree && typeof route.query.parent === 'string' ? route.query.parent : null
80
+ form.load(parent ? { [meta.value.tree.parent]: parent } : {})
81
+ }
82
+
83
+ const fetchRow = async () => {
84
+ const res = await cmsFetch<{ row: Record<string, any>; can?: typeof can.value }>(rowUrl())
85
+ if (res.can) can.value = res.can
86
+ return res.row
87
+ }
88
+
89
+ /** Replace the form with the newest saved version (discarding unsaved edits here). */
90
+ async function loadNewest() {
91
+ const row = await fetchRow()
92
+ await form.replace(row)
93
+ adopt(row)
94
+ // Shared text follows only when someone asks for the saved version: for everyone.
95
+ for (const key of sharedFields.value) collab?.set(key, row[key])
96
+ if (live) live.incoming.value = null
97
+ }
98
+
99
+ /**
100
+ * Someone else saved, or the connection came back (we may have missed something).
101
+ * Fetch first, then decide: nothing new → nothing; unsaved edits here (also ones
102
+ * typed while fetching) → offer the newer version; otherwise show it.
103
+ */
104
+ // This tab has just removed the translation itself: its own change coming back is no news.
105
+ let removedHere = false
106
+ async function onRemoteChange(c: LiveChange) {
107
+ if (removedHere && c.type === 'translation.deleted') return
108
+ const row = await fetchRow().catch(() => null)
109
+ if (!row) return
110
+ const newest = (isTranslation.value ? row.__version : row.updatedAt) ?? null
111
+ if (newest === version.value) return
112
+ // Their changes come in field by field; only the same field changed differently on
113
+ // both sides needs a decision. Shared text merges by itself.
114
+ if (!saving.value && await form.merge(row, sharedFields.value)) {
115
+ adopt(row)
116
+ toast.add({ title: c.byName ? t('live.reloaded', { name: c.byName }) : t('live.reloadedSomeone'), icon: 'i-lucide-refresh-cw', color: 'info' })
117
+ return
118
+ }
119
+ if (live) live.incoming.value = c
120
+ }
121
+
122
+ /**
123
+ * "Save my changes on top": the newest version, with only the fields changed in
124
+ * this tab put back on it — everything else (a publish, other people's edits) stays
125
+ * as they saved it.
126
+ */
127
+ async function saveOnTop() {
128
+ const mine = form.changedFields()
129
+ const row = await fetchRow()
130
+ await form.replace(row)
131
+ adopt(row)
132
+ Object.assign(state, mine)
133
+ await save()
134
+ }
135
+
136
+ // ── realtime: who else is here, and what they saved ──
137
+ const live = isNew.value
138
+ ? null
139
+ : useCmsEntryLive({
140
+ entity: entity.value,
141
+ id: id.value,
142
+ version,
143
+ dirty,
144
+ saving,
145
+ locale: computed(() => (isTranslation.value ? currentLocale.value : null)),
146
+ onChange: onRemoteChange,
147
+ })
148
+ const others = computed(() => live?.others.value ?? [])
149
+
150
+ // ── shared editing of the rich-text fields (this entry, in this language) ──
151
+ // Only when there is text to write together (a rich-text field).
152
+ const hasRichText = (meta.value?.fields ?? []).some((f: any) => f.type === 'richtext')
153
+ const collab = isNew.value || !hasRichText ? null : useCmsCollab({ entity: entity.value, id: id.value, locale: isTranslation.value ? currentLocale.value : null })
154
+ // Shared on this page right now: a shared editor is mounted for it (not, say, a
155
+ // field in a collapsed group, which then merges like any other field).
156
+ const sharedFields = computed(() => (collab?.status.value === 'ready' ? collab.mounted.value : new Set<string>()))
157
+ form.setSharedText({ fields: () => sharedFields.value, othersHere: () => others.value.length > 0, reset: (key, value) => { collab?.set(key, value) } })
158
+ /**
159
+ * Saves made from the shared document say so (it then matches the saved version) —
160
+ * only when every shared field is on the page, so the save really holds the shared text.
161
+ */
162
+ const collabHeaders = (): Record<string, string> => {
163
+ if (!collab || collab.status.value !== 'ready' || !collab.epoch.value) return {}
164
+ for (const k of collab.fields.value) if (!collab.mounted.value.has(k)) return {}
165
+ return { 'x-cms-collab': collab.epoch.value }
166
+ }
167
+
168
+ // ── the "…" menu: whatever applies here ──
169
+ // A draft's top bar on a phone: "Save" while there is something to save (publishing moves into the menu).
170
+ const phoneSave = computed(() => narrow.value && dirty.value && !!publish.value && canPublish.value && !isPublished.value && !isTranslation.value && !readOnly.value)
171
+ const draftActions = computed(() => !!publish.value && canPublish.value && !isPublished.value && !isTranslation.value)
172
+ const menuGroups = computed(() => {
173
+ const groups: any[][] = []
174
+ if (narrow.value) {
175
+ const g: any[] = []
176
+ if (phoneSave.value) g.push({ label: t('editor.publishEllipsis'), icon: 'i-lucide-send', onSelect: () => { reviewOpen.value = true } })
177
+ else if (draftActions.value && !readOnly.value) g.push({ label: t('editor.saveDraft'), icon: 'i-lucide-save', onSelect: () => save() })
178
+ if (previewUrl.value) g.push({ label: t('editor.preview'), icon: 'i-lucide-eye', onSelect: togglePreview })
179
+ if (!isNew.value) g.push({ label: t('revisions.open'), icon: 'i-lucide-history', onSelect: () => { historyOpen.value = true } })
180
+ if (locales.value && !isNew.value) g.push({ label: t('translation.language'), icon: 'i-lucide-languages', children: localeItems.value })
181
+ if (g.length) groups.push(g)
182
+ }
183
+ if (moreItems.value.length) groups.push(moreItems.value)
184
+ if (entryItems.value.length) groups.push(entryItems.value)
185
+ return groups
186
+ })
187
+ const moreItems = computed(() => {
188
+ const items: any[] = []
189
+ if (readOnly.value) return items
190
+ if (!isNew.value && dirty.value) items.push({ label: t('editor.discard'), icon: 'i-lucide-undo-2', onSelect: discardChanges })
191
+ if (!isNew.value && !isTranslation.value && publish.value && canPublish.value && isPublished.value) {
192
+ items.push({ label: t('editor.unpublish'), icon: 'i-lucide-eye-off', onSelect: confirmUnpublish })
193
+ }
194
+ if (isTranslation.value && translated.value) items.push({ label: t('translation.remove'), icon: 'i-lucide-trash-2', color: 'error' as const, onSelect: removeTranslation })
195
+ return items
196
+ })
197
+ // The entry itself: see it live, copy it, delete it (never from a translation).
198
+ const entryItems = computed(() => {
199
+ const items: any[] = []
200
+ if (isNew.value || isTranslation.value) return items
201
+ if (isPublished.value && publicPath.value) items.push({ label: t('editor.viewOnSite'), icon: 'i-lucide-arrow-up-right', to: publicPath.value, target: '_blank' })
202
+ if (meta.value?.can?.create !== false) items.push({ label: t('editor.duplicate'), icon: 'i-lucide-copy', onSelect: duplicateEntry })
203
+ if (meta.value?.can?.delete !== false && !(readOnly.value && can.value.why !== 'published')) items.push({ label: t('editor.delete'), icon: 'i-lucide-trash-2', color: 'error' as const, onSelect: deleteEntry })
204
+ return items
205
+ })
206
+ const entryActions = useCmsEntryActions()
207
+ async function duplicateEntry() {
208
+ if (dirty.value && !await confirm({ title: t('editor.duplicateDirtyTitle'), description: t('editor.duplicateDirtyBody'), icon: 'i-lucide-copy', confirmLabel: t('editor.duplicateAnyway'), cancelLabel: t('common.cancel'), color: 'warning' })) return
209
+ const copy = await entryActions.duplicate(entity.value, meta.value, id.value)
210
+ if (copy) {
211
+ dirty.value = false
212
+ await router.push(`/admin/${entity.value}/${copy}`)
213
+ }
214
+ }
215
+ async function deleteEntry() {
216
+ if (await entryActions.remove(entity.value, meta.value, id.value, titleField.value ? state[titleField.value.key] : null)) {
217
+ dirty.value = false
218
+ await router.push(`/admin/${entity.value}`)
219
+ }
220
+ }
221
+
222
+ const confirm = useCmsConfirm()
223
+ /** Taking it off the website is one click away from "Discard changes": ask first. */
224
+ async function confirmUnpublish() {
225
+ // A page tree: the pages under this one go off the website with it.
226
+ const below = subpagesOnSite.value
227
+ const ok = await confirm({
228
+ title: t('editor.unpublishTitle'), description: below ? t('tree.unpublishBranchCount', { count: below }) : t('editor.unpublishBody'), icon: 'i-lucide-eye-off',
229
+ confirmLabel: t('editor.unpublish'),
230
+ })
231
+ if (ok) await setPublished(false)
232
+ }
233
+ /** Back to the saved version. Shared text goes back for everyone editing it, so ask first. */
234
+ async function discardChanges() {
235
+ const others = (live?.others.value ?? []).length > 0 && sharedFields.value.size > 0
236
+ const ok = await confirm({
237
+ title: t('editor.discardTitle'), description: others ? t('editor.discardSharedConfirm') : t('editor.discardConfirm'),
238
+ icon: 'i-lucide-undo-2', cancelLabel: t('editor.keepEditing'), confirmLabel: t('editor.discard'), color: 'warning',
239
+ })
240
+ if (!ok) return
241
+ await loadNewest()
242
+ }
243
+
244
+ // Text typed while offline that the shared document could not take back (it was
245
+ // restarted meanwhile): offered back, never dropped silently.
246
+ const lostText = ref<Record<string, any> | null>(null)
247
+ if (collab) watch(collab.lost, (v) => { if (v) lostText.value = v })
248
+ /** "Keep" on text a closed tab left behind: into the form (shared text: for everyone), as an unsaved change. */
249
+ function keepUnsaved(values: Record<string, any>) {
250
+ for (const [key, value] of Object.entries(values)) {
251
+ if (!collab?.set(key, structuredClone(toRaw(value)))) state[key] = structuredClone(toRaw(value))
252
+ }
253
+ }
254
+ function restoreLost() {
255
+ for (const [key, value] of Object.entries(lostText.value ?? {})) {
256
+ if (!collab?.set(key, value)) state[key] = value
257
+ }
258
+ lostText.value = null
259
+ if (collab) collab.lost.value = null
260
+ }
261
+
262
+ // ── history ──
263
+ const historyOpen = ref(false)
264
+ /** Put an older version into the form (shared text: for everyone). Saving makes it current. */
265
+ // Restoring brings back content, not the workflow: status, publish date (and the
266
+ // list position, which is not in this form) stay as they are now.
267
+ const workflowFields = computed(() => new Set([publish.value?.field, publish.value?.dateField].filter(Boolean) as string[]))
268
+ async function restoreRevision(data: Record<string, any>) {
269
+ // Files deleted since that version are left out (an empty field, no broken image).
270
+ const gone = await missingMedia(data)
271
+ data = withoutMedia(data, gone)
272
+ for (const f of editable.value) {
273
+ if (!(f.key in data) || workflowFields.value.has(f.key)) continue
274
+ if (sharedFields.value.has(f.key) && collab?.set(f.key, data[f.key])) continue
275
+ state[f.key] = structuredClone(toRaw(data[f.key]))
276
+ }
277
+ toast.add({
278
+ title: t('revisions.restored'), icon: 'i-lucide-history', color: 'info',
279
+ description: gone.size ? t('revisions.filesGone', { count: gone.size }) : undefined,
280
+ })
281
+ }
282
+
283
+ /** Media ids a snapshot uses (media fields, images in rich text and blocks). */
284
+ function mediaIdsIn(data: Record<string, any>): string[] {
285
+ const ids: string[] = []
286
+ const walk = (v: any) => {
287
+ if (!v || typeof v !== 'object') return
288
+ if (Array.isArray(v)) return v.forEach(walk)
289
+ if (typeof v.attrs?.mediaId === 'string') ids.push(v.attrs.mediaId)
290
+ for (const x of Object.values(v)) walk(x)
291
+ }
292
+ // A group's media fields (and, inside it, rich text, lists and more groups).
293
+ const groupMedia = (g: any, v: any) => {
294
+ if (!v || typeof v !== 'object') return
295
+ for (const gf of g.meta?.fields ?? []) {
296
+ const x = v[gf.key]
297
+ if (gf.type === 'media' && typeof x === 'string') ids.push(x)
298
+ else if (gf.type === 'group') groupMedia(gf, x)
299
+ else walk(x)
300
+ }
301
+ }
302
+ for (const f of editable.value) {
303
+ const v = data[f.key]
304
+ if (f.type === 'media' && typeof v === 'string') ids.push(v)
305
+ else if (f.type === 'gallery' && Array.isArray(v)) ids.push(...v.map((x: any) => x?.mediaId).filter(Boolean))
306
+ else if (f.type === 'richtext') walk(v)
307
+ else if (f.type === 'blocks' && Array.isArray(v)) {
308
+ for (const b of v) for (const [k, x] of Object.entries(b ?? {})) {
309
+ const bf = f.meta?.blocks?.[b?.type]?.fields?.find((y: any) => y.key === k)
310
+ if (bf?.type === 'media' && typeof x === 'string') ids.push(x)
311
+ else if (bf?.type === 'group') groupMedia(bf, x)
312
+ else walk(x)
313
+ }
314
+ }
315
+ else if (f.type === 'group') groupMedia(f, v)
316
+ }
317
+ return [...new Set(ids.filter((id) => /^[0-9a-f-]{36}$/i.test(id)))]
318
+ }
319
+ async function missingMedia(data: Record<string, any>): Promise<Set<string>> {
320
+ const ids = mediaIdsIn(data)
321
+ if (!ids.length) return new Set()
322
+ const res = await $fetch<{ ids: string[] }>('/api/cms/_media/exists', { method: 'POST', body: { ids } }).catch(() => ({ ids }))
323
+ const have = new Set(res.ids)
324
+ return new Set(ids.filter((id) => !have.has(id)))
325
+ }
326
+ /** A copy of the snapshot without the given files: fields emptied, images removed. */
327
+ function withoutMedia(data: Record<string, any>, gone: Set<string>): Record<string, any> {
328
+ if (!gone.size) return data
329
+ const strip = (v: any): any => {
330
+ if (Array.isArray(v)) return v.filter((x) => !(x?.type === 'image' && gone.has(x?.attrs?.mediaId)) && !gone.has(x?.mediaId)).map(strip)
331
+ if (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, typeof x === 'string' && gone.has(x) ? null : strip(x)]))
332
+ return v
333
+ }
334
+ const out: Record<string, any> = {}
335
+ for (const [k, v] of Object.entries(data)) out[k] = typeof v === 'string' && gone.has(v) ? null : strip(v)
336
+ return out
337
+ }
338
+
339
+ /** Copy the default language's value into this translation's field (shared text: for everyone). */
340
+ function copyDefault(key: string) {
341
+ const value = structuredClone(toRaw(defaults.value[key]))
342
+ if (sharedFields.value.has(key) && collab?.set(key, value)) return
343
+ state[key] = value
344
+ }
345
+
346
+ // ── layout: which field goes where ──
347
+ const publish = computed(() => meta.value?.publish)
348
+ const titleKey = computed(() => meta.value?.titleField as string | undefined)
349
+ const titleField = computed(() => editable.value.find((f: any) => f.key === titleKey.value))
350
+ // A title that is an address (redirects): labelled, "/…" as the hint, set in mono.
351
+ const titleIsAddress = computed(() => ['path', 'url', 'link'].includes(titleField.value?.meta?.format))
352
+ const titlePlaceholder = computed(() => (titleIsAddress.value ? '/…' : t('editor.titlePlaceholder')))
353
+ const MAIN_TYPES = new Set(['text', 'richtext', 'media', 'blocks', 'gallery', 'group'])
354
+ const placementOf = (f: any): 'main' | 'sidebar' => f.meta?.position ?? (MAIN_TYPES.has(f.type) ? 'main' : 'sidebar')
355
+ // The publish field is changed by the Publish action, not edited as a field. In a
356
+ // translation only the translatable fields are shown.
357
+ const formFields = computed(() => editable.value.filter((f: any) =>
358
+ f.key !== titleKey.value && f.key !== publish.value?.field && f.key !== meta.value?.orderField && (!isTranslation.value || f.localized)))
359
+ const mainFields = computed(() => formFields.value.filter((f: any) => !f.meta?.group && placementOf(f) === 'main'))
360
+ // ── arrangement: chosen from the content (graph `editor`, see editorLayout) ──
361
+ // write: one calm, centred writing column, details on demand · form: fields and a
362
+ // properties panel · preview: the form beside the live page. Same parts, same top bar.
363
+ const arrangement = computed<'write' | 'form' | 'preview'>(() => meta.value?.editor ?? 'form')
364
+ const wide = ref(false) // ≥ 1024px: panels side by side
365
+ const roomy = ref(false) // ≥ 1280px: the Write arrangement shows details by default
366
+ const narrow = ref(false) // < 768px: secondary actions move into "…"
367
+ const previewOpen = ref(arrangement.value === 'preview')
368
+ const previewSheet = ref(false)
369
+ const detailsOpen = ref(true)
370
+ const previewKey = computed(() => `cms-preview:${entity.value}`)
371
+ onMounted(() => {
372
+ const mq = (q: string, set: (v: boolean) => void) => {
373
+ const m = window.matchMedia(q)
374
+ set(m.matches)
375
+ m.addEventListener('change', (e) => set(e.matches))
376
+ }
377
+ mq('(min-width: 1024px)', (v) => { wide.value = v })
378
+ mq('(min-width: 1280px)', (v) => { roomy.value = v })
379
+ mq('(max-width: 767px)', (v) => { narrow.value = v })
380
+ detailsOpen.value = arrangement.value !== 'write' || roomy.value
381
+ try {
382
+ const pref = localStorage.getItem(previewKey.value)
383
+ if (pref) previewOpen.value = pref === '1'
384
+ }
385
+ catch { /* storage blocked: the arrangement's default */ }
386
+ })
387
+ // The live page loads the site with whatever the entry contains: beside the form on
388
+ // wide screens (remembered per collection), as a full-screen sheet on small ones.
389
+ function togglePreview() {
390
+ if (!wide.value) {
391
+ previewSheet.value = true
392
+ return
393
+ }
394
+ previewOpen.value = !previewOpen.value
395
+ try {
396
+ localStorage.setItem(previewKey.value, previewOpen.value ? '1' : '0')
397
+ }
398
+ catch { /* storage blocked: for this visit only */ }
399
+ }
400
+ const split = computed(() => wide.value && previewOpen.value && !!previewUrl.value)
401
+ // Form and preview show every field in titled sections (admin.sections; tabs read as
402
+ // sections there) with a details column; write keeps the text apart from the details.
403
+ const sectioned = computed(() => arrangement.value !== 'write')
404
+ const formSectionConfig = computed(() => {
405
+ if (meta.value?.sections?.length) return meta.value.sections
406
+ const tabs = (meta.value?.tabs ?? []) as { label: any; fields: string[] }[]
407
+ return tabs.length ? tabs.map((tab) => ({ label: tab.label, fields: tab.fields })) : null
408
+ })
409
+ const showAside = computed(() => !wide.value || arrangement.value !== 'write' || detailsOpen.value || split.value)
410
+ // The sidebar folds to icons while writing or looking at the page.
411
+ useCmsFocus(computed(() => wide.value && (arrangement.value !== 'form' || split.value)))
412
+ const groups = computed(() => {
413
+ const out = new Map<string, { label: string; fields: any[] }>()
414
+ for (const f of formFields.value) {
415
+ if (!f.meta?.group) continue
416
+ const label = tl(f.meta.group)
417
+ if (!out.has(label)) out.set(label, { label, fields: [] })
418
+ out.get(label)!.fields.push(f)
419
+ }
420
+ return [...out.values()]
421
+ })
422
+
423
+ // ── write: the column holds the cover photo, the title, the summary and the text, as
424
+ // the reader meets them; everything else is in the details beside it ──
425
+ const isImageMedia = (f: any) => f.type === 'media' && (!f.meta?.accept || String(f.meta.accept).startsWith('image'))
426
+ const writeCover = computed(() => mainFields.value.find(isImageMedia))
427
+ const writeLead = computed(() => mainFields.value.find((f: any) => f.type === 'text' && f.meta?.multiline))
428
+ const writeBody = computed(() => mainFields.value.find((f: any) => f.type === 'richtext'))
429
+ const inColumn = computed(() => new Set([writeCover.value?.key, writeLead.value?.key, writeBody.value?.key].filter(Boolean) as string[]))
430
+ // Further text bodies and lists of blocks stay in the column, under their labels.
431
+ const writeMore = computed(() => mainFields.value.filter((f: any) => !inColumn.value.has(f.key) && (f.type === 'richtext' || f.type === 'blocks')))
432
+ // admin.tabs after the first become folded groups in the details ("Photos & video"),
433
+ // as do .group() fields; the rest are rows.
434
+ const writeGroups = computed(() => {
435
+ const tabs = (meta.value?.tabs ?? []) as { label: any; fields: string[] }[]
436
+ const taken = new Set([...inColumn.value, ...writeMore.value.map((f: any) => f.key as string)])
437
+ const out: { id: string; label: string; fields: any[] }[] = []
438
+ tabs.forEach((tab, i) => {
439
+ if (i === 0) return
440
+ const fields = formFields.value.filter((f: any) => !f.meta?.group && tab.fields.includes(f.key) && !taken.has(f.key))
441
+ fields.forEach((f: any) => taken.add(f.key))
442
+ if (fields.length) out.push({ id: `tab-${i}`, label: tl(tab.label), fields })
443
+ })
444
+ for (const g of groups.value) out.push({ id: `group-${g.label}`, label: g.label, fields: g.fields })
445
+ return out
446
+ })
447
+ const writeRows = computed(() => {
448
+ const elsewhere = new Set([...inColumn.value, ...writeMore.value.map((f: any) => f.key as string), ...writeGroups.value.flatMap((g) => g.fields.map((f: any) => f.key as string))])
449
+ const rows = formFields.value.filter((f: any) => !f.meta?.group && !elsewhere.has(f.key))
450
+ // The address last: it follows from the title.
451
+ return [...rows.filter((f: any) => f.type !== 'slug'), ...rows.filter((f: any) => f.type === 'slug')]
452
+ })
453
+ const groupSummary = (g: { fields: any[] }) => {
454
+ const filled = g.fields.filter((f: any) => !cmsIsEmpty(state[f.key]) && !(f.type === 'boolean' && !state[f.key])).length
455
+ return filled ? t('sections.filled', { n: filled, total: g.fields.length }) : t('sections.empty')
456
+ }
457
+ const openGroups = reactive<Record<string, boolean>>({})
458
+ // A group with an error inside opens itself.
459
+ watch(() => ({ ...fieldErrors }), (errs) => {
460
+ for (const g of writeGroups.value) if (g.fields.some((f: any) => errs[f.key])) openGroups[g.id] = true
461
+ })
462
+
463
+ // ── a redirect from the address of a page that is on the website would hide that page ──
464
+ const shadowed = ref<{ title: string } | null>(null)
465
+ if (meta.value?.preset === 'redirects') {
466
+ let seq = 0
467
+ let timer: ReturnType<typeof setTimeout> | undefined
468
+ const check = async (from: unknown) => {
469
+ const my = ++seq
470
+ const path = typeof from === 'string' ? from.trim().split(/[?#]/)[0]!.replace(/(.)\/+$/, '$1') : ''
471
+ if (!path.startsWith('/') || path === '/') {
472
+ shadowed.value = null
473
+ return
474
+ }
475
+ // The page's address may be nested (/about/team): its last part is what the picker can search by.
476
+ const last = path.split('/').filter(Boolean).pop() ?? ''
477
+ const codes = locales.value?.all ?? [undefined]
478
+ const found = await Promise.all(codes.map((locale) => cmsFetch<{ items: { title: string; path: string; published: boolean }[] }>('/api/cms/_links', { query: { q: last, locale } }).catch(() => ({ items: [] }))))
479
+ if (my !== seq) return
480
+ const hit = found.flatMap((r) => r.items).find((i) => i.published && i.path === path)
481
+ shadowed.value = hit ? { title: hit.title } : null
482
+ }
483
+ onMounted(() => {
484
+ watch(() => state[titleKey.value ?? 'from'], (v) => {
485
+ clearTimeout(timer)
486
+ timer = setTimeout(() => check(v), 350)
487
+ }, { immediate: true })
488
+ })
489
+ onBeforeUnmount(() => clearTimeout(timer))
490
+ }
491
+
492
+ // ── titles ──
493
+ const listLabel = computed(() => entityLabel(meta.value) || entity.value)
494
+ const heading = computed(() => {
495
+ const v = titleKey.value ? state[titleKey.value] : ''
496
+ if (v) return String(v)
497
+ return isNew.value ? t('editor.newTitle', { label: entitySingular(meta.value).toLowerCase() }) : t('common.untitled')
498
+ })
499
+ useHead({ title: heading })
500
+
501
+ // ── publishing ──
502
+ const canPublish = computed(() => meta.value?.can?.publish !== false)
503
+ const isPublished = computed(() => !!publish.value && state[publish.value.field] === publish.value.publishedValue)
504
+ const publishedOn = computed(() => (publish.value?.dateField ? state[publish.value.dateField] : null))
505
+ // A publish date ahead: publishing schedules it (live from that moment).
506
+ const futureDate = computed(() => !!publishedOn.value && new Date(publishedOn.value).getTime() > Date.now())
507
+ const isScheduled = computed(() => isPublished.value && futureDate.value)
508
+
509
+ // A changed address leaves redirects behind: the "Saved" says so.
510
+ let redirectsMade = 0
511
+ const redirectNote = () => (redirectsMade ? { successTitle: t('editor.savedRedirect', { count: redirectsMade }) } : undefined)
512
+ async function save(successTitle?: string | null) {
513
+ if (isTranslation.value) return saveTranslation()
514
+ redirectsMade = 0
515
+ return form.submit(async () => {
516
+ if (isNew.value) {
517
+ const url: string = `/api/cms/${entity.value}`
518
+ const res: any = await $fetch(url, { method: 'POST', body: form.body() })
519
+ dirty.value = false // before the redirect, so the leave-guard does not fire
520
+ handedOver.value = momentAfterCreate.value
521
+ // Replace: Back then goes to where they came from, not to a blank "new" form.
522
+ await router.replace(`/admin/${entity.value}/${res.row.id}`)
523
+ }
524
+ else {
525
+ const url: string = `/api/cms/${entity.value}/${id.value}`
526
+ const headers: Record<string, string> = { ...(version.value ? { 'x-cms-version': version.value } : {}), ...collabHeaders() }
527
+ const res: any = await $fetch(url, { method: 'PATCH', body: form.body(), headers })
528
+ redirectsMade = Number(res?.redirects) || 0
529
+ savedAt.value = res?.row?.updatedAt ?? new Date().toISOString()
530
+ version.value = res?.row?.updatedAt ?? null
531
+ // The publish date may have been stamped by the server: show what was stored —
532
+ // quietly, it is the saved value, not an edit made during the save.
533
+ const dateKey = publish.value?.dateField
534
+ if (dateKey && res?.row && dateKey in res.row) form.quiet(() => { state[dateKey] = res.row[dateKey] })
535
+ if (live) live.incoming.value = null
536
+ if (successTitle === undefined) return redirectNote()
537
+ }
538
+ }, successTitle === undefined ? (isNew.value ? t('editor.created') : t('editor.saved')) : successTitle)
539
+ }
540
+
541
+ async function saveTranslation() {
542
+ redirectsMade = 0
543
+ return form.submit(async () => {
544
+ const body = Object.fromEntries(editable.value.filter((f: any) => f.localized).map((f: any) => [f.key, state[f.key] ?? null]))
545
+ const url: string = `/api/cms/${entity.value}/${id.value}?locale=${currentLocale.value}`
546
+ const headers: Record<string, string> = { ...(version.value ? { 'x-cms-version': version.value } : {}), ...collabHeaders() }
547
+ const res: any = await $fetch(url, { method: 'PATCH', body, headers })
548
+ redirectsMade = Number(res?.row?.__redirects) || 0
549
+ savedAt.value = res?.row?.updatedAt ?? new Date().toISOString()
550
+ version.value = res?.row?.__version ?? null
551
+ if (live) live.incoming.value = null
552
+ // Saved with nothing in it, the language is not translated (the server kept no row).
553
+ translated.value = !!res?.row?.__translated
554
+ const code = currentLocale.value
555
+ if (code) available.value = translated.value ? [...new Set([...available.value, code])] : available.value.filter((l) => l !== code)
556
+ return redirectNote()
557
+ }, t('editor.saved'))
558
+ }
559
+
560
+ async function removeTranslation() {
561
+ const lang = localeName(currentLocale.value)
562
+ if (!await confirm({ title: t('translation.removeTitle', { lang }), description: t('translation.removeBody', { lang }), icon: 'i-lucide-languages', confirmLabel: t('translation.remove'), cancelLabel: t('common.cancel'), color: 'error' })) return
563
+ try {
564
+ const url: string = `/api/cms/${entity.value}/${id.value}?locale=${currentLocale.value}`
565
+ removedHere = true
566
+ await $fetch(url, { method: 'DELETE' })
567
+ toast.add({ title: t('translation.removed'), icon: 'i-lucide-check', color: 'success' })
568
+ dirty.value = false
569
+ await router.push({ query: {} })
570
+ }
571
+ catch (e: any) {
572
+ removedHere = false
573
+ toast.add({ title: t('team.actionFailed'), description: cmsRequestError(e, t as any), icon: 'i-lucide-x', color: 'error' })
574
+ }
575
+ }
576
+
577
+ const localeItems = computed(() => (locales.value?.all ?? []).map((code) => ({
578
+ label: code === locales.value?.default ? `${localeLabel(code)} (${t('translation.default')})` : localeLabel(code),
579
+ description: code === locales.value?.default ? undefined : (available.value.includes(code) ? t('translation.translated') : t('translation.notTranslated')),
580
+ icon: code === currentLocale.value ? 'i-lucide-check' : undefined,
581
+ to: { query: code === locales.value?.default ? {} : { locale: code } },
582
+ })))
583
+
584
+ async function setPublished(next: boolean, quiet = false): Promise<boolean> {
585
+ const p = publish.value
586
+ if (!p) return false
587
+ const before = { status: state[p.field], date: p.dateField ? state[p.dateField] : undefined }
588
+ state[p.field] = next ? p.publishedValue : p.draftValue
589
+ // The server stamps the publish date when there is none (its clock, not ours).
590
+ const ok = await save(quiet ? null : next ? (futureDate.value ? t('editor.scheduledToast', { date: formatDate(publishedOn.value) }) : t('editor.publishedToast')) : t('editor.unpublishedToast'))
591
+ if (!ok) {
592
+ // Never show "Published" for something the server did not accept.
593
+ state[p.field] = before.status
594
+ if (p.dateField) state[p.dateField] = before.date
595
+ }
596
+ return !!ok
597
+ }
598
+
599
+ // ── the review step before going live, and the moment after ──
600
+ const reviewOpen = ref(false)
601
+ const publicPath = computed(() => previewUrl.value?.split('?')[0] ?? null)
602
+ const dateFieldDesc = computed(() => (publish.value?.dateField ? editable.value.find((f: any) => f.key === publish.value.dateField) : undefined))
603
+ const hasContent = (f: any, v: any) => {
604
+ if (v === null || v === undefined || v === '') return false
605
+ if (Array.isArray(v)) return v.length > 0
606
+ if (f.type === 'richtext') return /"text":"[^"]|"type":"image"/.test(JSON.stringify(v))
607
+ return true
608
+ }
609
+ function toDetails() {
610
+ document.querySelector('.cms-editor__aside')?.scrollIntoView({ behavior: 'smooth', block: 'start' })
611
+ }
612
+ /** Close the review and bring the field into view (its tab first). */
613
+ async function goToField(key: string) {
614
+ reviewOpen.value = false
615
+ const group = writeGroups.value.find((g) => g.fields.some((f: any) => f.key === key))
616
+ if (group) {
617
+ detailsOpen.value = true
618
+ openGroups[group.id] = true
619
+ }
620
+ await nextTick()
621
+ const el = document.getElementById(`cms-field-${key}`)
622
+ if (!el) return
623
+ el.scrollIntoView({ behavior: 'smooth', block: 'center' })
624
+ // Show where: focus it and flash a ring around it for a moment.
625
+ setTimeout(() => (el as HTMLElement).focus?.({ preventScroll: true }), 350)
626
+ el.classList.remove('cms-flash')
627
+ void el.offsetWidth
628
+ el.classList.add('cms-flash')
629
+ setTimeout(() => el.classList.remove('cms-flash'), 2000)
630
+ }
631
+ const reviewChecks = computed(() => {
632
+ const out: { ok: boolean; blocking?: boolean; title: string; description?: string; action?: { label: string; onClick: () => void } }[] = []
633
+ const tf = titleField.value
634
+ if (tf) {
635
+ const v = state[tf.key]
636
+ out.push(v
637
+ ? { ok: true, title: fieldLabel(tf), description: String(v) }
638
+ // A required title blocks like any other required field, in the same words.
639
+ : { ok: false, blocking: !tf.optional, title: t('review.missing', { field: fieldLabel(tf) }), description: tf.optional ? t('review.titleMissingBody') : t('review.requiredBody'), action: { label: t('review.fix'), onClick: () => goToField(tf.key) } })
640
+ }
641
+ // Required fields left empty: the save would be refused, so these come first and
642
+ // block publishing. A translation only checks what it translates.
643
+ for (const f of (meta.value?.fields ?? []) as any[]) {
644
+ if (f === tf || f.key === meta.value?.orderField) continue
645
+ if (!(f.required || f.relation?.required)) continue
646
+ if (isTranslation.value && !f.localized) continue
647
+ if (hasContent(f, state[f.key])) continue
648
+ out.unshift({ ok: false, blocking: true, title: t('review.missing', { field: fieldLabel(f) }), description: t('review.requiredBody'), action: { label: t('review.fix'), onClick: () => goToField(f.key) } })
649
+ }
650
+ // The content itself: the text body and the main picture. Galleries, files and
651
+ // other extras are optional by nature and are not worth a warning.
652
+ const mainPicture = mainFields.value.find((f: any) => f.type === 'media' && (!f.meta?.accept || String(f.meta.accept).startsWith('image')))
653
+ for (const f of mainFields.value) {
654
+ if (f.type !== 'richtext' && f !== mainPicture) continue
655
+ out.push(hasContent(f, state[f.key])
656
+ ? { ok: true, title: fieldLabel(f) }
657
+ : { ok: false, title: t('review.missing', { field: fieldLabel(f) }), description: t('review.missingBody'), action: { label: t('review.add'), onClick: () => goToField(f.key) } })
658
+ }
659
+ if (publicPath.value) out.push({ ok: true, title: t('review.address'), description: publicPath.value })
660
+ // Translations not written yet (the page then shows the default language).
661
+ if (locales.value && !isNew.value && !isTranslation.value) {
662
+ for (const code of locales.value.all) {
663
+ if (code === locales.value.default || available.value.includes(code)) continue
664
+ out.push({
665
+ ok: false, title: t('review.translationMissing', { lang: localeName(code) }), description: t('review.translationMissingBody', { lang: defaultLabel.value }),
666
+ action: { label: t('review.translate'), onClick: () => { reviewOpen.value = false; router.push({ query: { locale: code } }) } },
667
+ })
668
+ }
669
+ }
670
+ // Text nobody has saved. What is in the form goes live with this publish (it is saved
671
+ // first) — also what others are typing right now; text a closed tab left behind waits aside, not in it.
672
+ if (collab && !isNew.value) {
673
+ const typing = others.value.filter((p) => p.editing).map((p) => p.name)
674
+ const unsavedShared = (editable.value as any[]).filter((f) => sharedFields.value.has(f.key) && f.key in form.changedFields())
675
+ if (others.value.length && unsavedShared.length) {
676
+ out.push({
677
+ ok: false, title: t('review.sharedUnsaved', { names: (typing.length ? typing : others.value.map((p) => p.name)).join(', ') }),
678
+ description: t('review.sharedUnsavedBody', { fields: unsavedShared.map((f) => fieldLabel(f)).join(', ') }),
679
+ })
680
+ }
681
+ if (collab.unsaved.value) {
682
+ out.push({
683
+ ok: false, title: t('review.unsavedLeft'), description: t('review.unsavedLeftBody'),
684
+ action: { label: t('review.look'), onClick: () => { reviewOpen.value = false; nextTick(() => window.scrollTo({ top: 0, behavior: 'smooth' })) } },
685
+ })
686
+ }
687
+ }
688
+ return out
689
+ })
690
+ const moment = ref<null | 'published' | 'scheduled'>(null)
691
+ const momentOpen = computed({ get: () => !!moment.value, set: (v: boolean) => { if (!v) moment.value = null } })
692
+ // A new entry published from the review is saved first, then opened at its own
693
+ // address (a new page): the moment is handed over in app state and shown there.
694
+ const momentAfterCreate = ref<null | 'published' | 'scheduled'>(null)
695
+ const handedOver = useState<null | 'published' | 'scheduled'>('cms-moment', () => null)
696
+ onMounted(() => {
697
+ if (handedOver.value) {
698
+ moment.value = handedOver.value
699
+ handedOver.value = null
700
+ }
701
+ })
702
+ async function publishFromReview(when: 'now' | 'schedule') {
703
+ const dk = publish.value?.dateField
704
+ if (when === 'now' && dk && futureDate.value) state[dk] = null
705
+ const kind = when === 'schedule' ? 'scheduled' : 'published'
706
+ momentAfterCreate.value = kind
707
+ const ok = await setPublished(true, true)
708
+ momentAfterCreate.value = null
709
+ if (!ok) {
710
+ reviewOpen.value = false
711
+ return
712
+ }
713
+ reviewOpen.value = false
714
+ moment.value = kind
715
+ }
716
+
717
+ // A page tree: the address runs through the ancestors, so it comes from the server (the saved
718
+ // parent and address parts), refreshed after each save.
719
+ const treeRows = meta.value?.tree && !isNew.value
720
+ ? await useFetch<{ rows: { id: string; parentId: string | null; onSite: boolean; paths: Record<string, string> }[] }>(() => `/api/cms/${entity.value}/_tree`, { key: `cms-tree-address:${entity.value}:${id.value}` })
721
+ : null
722
+ watch(savedAt, () => treeRows?.refresh())
723
+ /** How many pages under this one are on the website now (they go with it when it is taken down). */
724
+ const subpagesOnSite = computed(() => {
725
+ const rows = treeRows?.data.value?.rows ?? []
726
+ const byParent = new Map<string | null, typeof rows>()
727
+ for (const r of rows) byParent.set(r.parentId, [...(byParent.get(r.parentId) ?? []), r])
728
+ let count = 0
729
+ const seen = new Set<string>()
730
+ const walk = (parent: string) => {
731
+ for (const r of byParent.get(parent) ?? []) {
732
+ if (seen.has(r.id)) continue
733
+ seen.add(r.id)
734
+ if (r.onSite) count++
735
+ walk(r.id)
736
+ }
737
+ }
738
+ walk(id.value)
739
+ return count
740
+ })
741
+ const treeAddress = computed(() => treeRows?.data.value?.rows.find((r) => r.id === id.value)?.paths?.[currentLocale.value ?? ''] ?? null)
742
+
743
+ const previewUrl = computed(() => {
744
+ if (meta.value?.tree) {
745
+ if (isNew.value || !treeAddress.value) return null
746
+ return `${treeAddress.value}?preview${isTranslation.value ? `&locale=${currentLocale.value}` : ''}`
747
+ }
748
+ // The address in the language being edited (prefix included), from the graph.
749
+ const paths: Record<string, string> | null = meta.value?.previewPaths ?? null
750
+ // A language left out of a per-language map has no page: no preview then. An entry
751
+ // without languages of its own uses the default language's address.
752
+ const template = !paths ? null : currentLocale.value ? (paths[currentLocale.value] ?? null) : (paths[''] ?? Object.values(paths)[0] ?? null)
753
+ if (!template || isNew.value) return null
754
+ let ok = true
755
+ const url = template.replace(/:(\w+)/g, (_m: string, k: string) => {
756
+ const v = state[k]
757
+ if (v === undefined || v === null || v === '') ok = false
758
+ return encodeURIComponent(v ?? '')
759
+ })
760
+ return ok ? `${url}?preview${isTranslation.value ? `&locale=${currentLocale.value}` : ''}` : null
761
+ })
762
+
763
+ defineShortcuts({ meta_s: { usingInput: true, handler: () => { if (!saving.value) save() } } })
764
+ </script>
765
+
766
+ <template>
767
+ <CmsPage v-if="graph && (!meta || missing)" :title="t('nav.notFoundTitle')">
768
+ <CmsEmptyState variant="no-results" icon="i-lucide-map-pin-off" :title="t('nav.notFoundTitle')" :description="missing && meta ? t('nav.missingEntryBody') : t('nav.notFoundBody')">
769
+ <template #actions>
770
+ <UButton to="/admin" color="neutral" variant="outline" icon="i-lucide-house">{{ t('nav.home') }}</UButton>
771
+ </template>
772
+ </CmsEmptyState>
773
+ </CmsPage>
774
+ <!-- a person who may not add this kind of entry: said, never an editable form that cannot save -->
775
+ <CmsPage v-else-if="cannotCreate" :back="{ label: listLabel, to: `/admin/${entity}` }" :title="listLabel">
776
+ <CmsEmptyState variant="no-results" icon="i-lucide-lock" :title="t('readOnly.cannotCreateTitle')" :description="t('readOnly.cannotCreate')">
777
+ <template #actions>
778
+ <UButton :to="`/admin/${entity}`" color="neutral" variant="outline" icon="i-lucide-chevron-left">{{ t('moment.backTo', { list: listLabel }) }}</UButton>
779
+ </template>
780
+ </CmsEmptyState>
781
+ </CmsPage>
782
+ <CmsPage v-else :back="{ label: listLabel, to: `/admin/${entity}` }" :heading="heading" flush>
783
+ <!-- one top bar for every arrangement: ‹ back · status · saved | language, history, details, preview, the primary action, … -->
784
+ <template #status>
785
+ <!-- phones: one thing — unsaved changes while there are any, else the status -->
786
+ <CmsStatusBadge v-if="publish && !isNew" :published="isPublished" :scheduled-for="publishedOn" class="shrink-0" :class="saving || dirty ? 'max-md:hidden' : ''" />
787
+ <span v-else-if="isNew" class="shrink-0" :class="saving || dirty ? 'max-md:hidden' : ''">{{ t('editor.newEntry') }}</span>
788
+ <span v-if="readOnly" class="inline-flex items-center gap-1 text-muted"><UIcon name="i-lucide-lock" class="size-3.5" />{{ t('readOnly.badge') }}</span>
789
+ <span v-if="!readOnly && ((publish && !isNew) || isNew) && (saving || dirty || savedAt)" class="text-dimmed max-md:hidden" aria-hidden="true">·</span>
790
+ <span v-if="!readOnly" class="truncate" :class="[dirty ? 'cms-unsaved' : '', saving || dirty ? '' : 'max-md:hidden']">
791
+ <template v-if="saving">{{ t('editor.saving') }}</template>
792
+ <template v-else-if="dirty"><span class="md:hidden">{{ t('editor.unsavedShort') }}</span><span class="max-md:hidden">{{ t('editor.unsaved') }}</span></template>
793
+ <CmsTime v-else-if="savedAt" v-slot="{ text }" :value="savedAt" relative>{{ t('editor.savedAgo', { time: text }) }}</CmsTime>
794
+ </span>
795
+ </template>
796
+ <template #actions>
797
+ <CmsPresence :people="others" />
798
+ <UDropdownMenu v-if="locales && !isNew" :items="localeItems" :content="{ align: 'end' }">
799
+ <UButton color="neutral" variant="ghost" icon="i-lucide-languages" trailing-icon="i-lucide-chevron-down" :aria-label="t('translation.language')" class="max-md:hidden">
800
+ {{ (currentLocale ?? '').toUpperCase() }}
801
+ </UButton>
802
+ </UDropdownMenu>
803
+ <UTooltip v-if="!isNew" :text="t('revisions.open')">
804
+ <UButton variant="ghost" color="neutral" icon="i-lucide-history" :aria-label="t('revisions.open')" class="max-md:hidden" @click="historyOpen = true" />
805
+ </UTooltip>
806
+ <UButton
807
+ v-if="arrangement === 'write' && wide && !split" color="neutral" variant="outline" icon="i-lucide-sliders-horizontal"
808
+ :class="detailsOpen ? 'bg-(--cms-nav-active)' : ''" :aria-pressed="detailsOpen" @click="detailsOpen = !detailsOpen"
809
+ >{{ t('editor.details') }}</UButton>
810
+ <!-- phones: the details sit under the text; this says they exist and goes there -->
811
+ <UButton
812
+ v-if="!wide && showAside" color="neutral" variant="ghost" icon="i-lucide-sliders-horizontal"
813
+ :aria-label="t('editor.details')" @click="toDetails"
814
+ />
815
+ <UButton
816
+ v-if="previewUrl" color="neutral" variant="outline" icon="i-lucide-eye" class="max-md:hidden"
817
+ :class="split ? 'bg-(--cms-nav-active)' : ''" :aria-pressed="split" @click="togglePreview"
818
+ >{{ t('editor.preview') }}</UButton>
819
+
820
+ <!-- one primary action (none for someone who cannot save here) -->
821
+ <template v-if="readOnly" />
822
+ <UButton v-else-if="isTranslation" :loading="saving" @click="save()">{{ t('translation.save') }}</UButton>
823
+ <template v-else-if="publish && canPublish">
824
+ <UButton v-if="isPublished && !isNew" :loading="saving" @click="save()">{{ futureDate ? t('editor.saveChanges') : t('editor.update') }}</UButton>
825
+ <template v-else>
826
+ <UButton color="neutral" variant="outline" :loading="saving" class="max-md:hidden" @click="save()">{{ t('editor.saveDraft') }}</UButton>
827
+ <!-- phones: with unsaved changes the bar offers Save (Publish waits in the menu), otherwise Publish -->
828
+ <UButton v-if="phoneSave" class="md:hidden" :loading="saving" @click="save()">{{ t('common.save') }}</UButton>
829
+ <UButton :disabled="saving" :class="phoneSave ? 'max-md:hidden' : ''" @click="reviewOpen = true">{{ t('editor.publishEllipsis') }}</UButton>
830
+ </template>
831
+ </template>
832
+ <UButton v-else-if="isNew" :loading="saving" @click="save()">{{ publish ? t('editor.saveDraft') : t('common.create') }}</UButton>
833
+ <UButton v-else :loading="saving" @click="save()">{{ publish ? t('editor.saveDraft') : t('common.save') }}</UButton>
834
+ <UDropdownMenu v-if="menuGroups.length" :items="menuGroups" :content="{ align: 'end' }">
835
+ <UButton color="neutral" variant="ghost" icon="i-lucide-ellipsis" :aria-label="t('editor.moreActions')" />
836
+ </UDropdownMenu>
837
+ </template>
838
+
839
+ <CmsRevisions
840
+ v-if="!isNew" v-model:open="historyOpen" :entity="entity" :id="id"
841
+ :locale="isTranslation ? currentLocale : null" :fields="editable.filter((f: any) => !workflowFields.has(f.key))" :current="state" @restore="restoreRevision"
842
+ />
843
+
844
+ <div
845
+ class="cms-editor"
846
+ :class="[arrangement === 'write' && !split ? 'cms-editor--write' : '', split ? 'cms-editor--split' : '', !showAside ? 'cms-editor--no-aside' : '']"
847
+ >
848
+ <!-- someone who cannot save here can read everything and change nothing -->
849
+ <fieldset class="cms-fieldset contents" :disabled="readOnly">
850
+ <div class="cms-editor__main">
851
+ <div class="cms-editor__column">
852
+ <UAlert
853
+ v-if="lostText" color="warning" variant="subtle" icon="i-lucide-cloud-off" class="mb-6" role="alert"
854
+ :title="t('live.offlineLost')" :description="t('live.offlineLostBody')"
855
+ :actions="[{ label: t('live.restoreMine'), color: 'neutral', variant: 'outline', onClick: restoreLost }]"
856
+ close @update:open="(open: boolean) => { if (!open) lostText = null }"
857
+ />
858
+ <UAlert
859
+ v-if="readOnly" color="neutral" variant="subtle" icon="i-lucide-lock" class="mb-6" role="status"
860
+ :title="t(`readOnly.${can.why ?? 'role'}`)" :description="t('readOnly.body')"
861
+ />
862
+ <UAlert
863
+ v-if="shadowed" color="warning" variant="subtle" icon="i-lucide-triangle-alert" class="mb-6" role="status"
864
+ :title="t('redirects.shadowsTitle', { title: shadowed.title })" :description="t('redirects.shadowsBody')"
865
+ />
866
+ <CmsUnsavedText :collab="collab" @keep="keepUnsaved" />
867
+ <CmsLiveNotice
868
+ :deleted="live?.deleted.value" :conflict="conflict" :incoming="live?.incoming.value"
869
+ :list-to="`/admin/${entity}`"
870
+ @load="loadNewest" @save-anyway="saveOnTop" @dismiss="live && (live.incoming.value = null)"
871
+ />
872
+
873
+ <!-- form and preview: every field in titled sections -->
874
+ <CmsFormSections
875
+ v-if="sectioned" :fields="formFields" :sections="formSectionConfig" :state="state" :errors="fieldErrors"
876
+ :disclose="!isTranslation" :menu="!split"
877
+ >
878
+ <template #top>
879
+ <!-- the title is the page heading; the address it will have sits under it -->
880
+ <div v-if="titleField">
881
+ <label v-if="titleIsAddress" :for="`cms-field-${titleField.key}`" class="block mb-1 text-sm font-medium text-highlighted">{{ fieldLabel(titleField) }}</label>
882
+ <textarea
883
+ :id="`cms-field-${titleField.key}`" v-model="state[titleField.key]" rows="1" class="cms-title-input resize-none field-sizing-content" :class="titleIsAddress ? 'cms-title-input--address' : ''"
884
+ :placeholder="titlePlaceholder"
885
+ :disabled="isTranslation && !titleField.localized"
886
+ :aria-label="fieldLabel(titleField)" :aria-invalid="!!fieldErrors[titleField.key]" :aria-describedby="fieldErrors[titleField.key] ? `cms-field-${titleField.key}-error` : undefined" autocomplete="off"
887
+ @keydown.enter.prevent
888
+ />
889
+ <p v-if="fieldErrors[titleField.key]" :id="`cms-field-${titleField.key}-error`" role="alert" class="mt-1 text-sm text-error">{{ fieldErrors[titleField.key] }}</p>
890
+ <p v-else-if="titleIsAddress && fieldHelp(titleField)" class="mt-1.5 text-sm text-muted">{{ fieldHelp(titleField) }}</p>
891
+ <p v-else-if="publicPath" class="mt-1.5 font-mono text-xs text-muted truncate">
892
+ <a v-if="isPublished" :href="publicPath" target="_blank" rel="noopener" class="hover:text-highlighted">{{ publicPath }} <UIcon name="i-lucide-arrow-up-right" class="size-3 align-[-1px]" /></a>
893
+ <template v-else>{{ publicPath }}</template>
894
+ </p>
895
+ <CmsTranslationRef
896
+ v-if="isTranslation && titleField.localized" :field="titleField" :value="defaults[titleField.key]"
897
+ :lang="defaultLabel" :empty="!state[titleField.key]" @copy="state[titleField.key] = defaults[titleField.key]"
898
+ />
899
+ </div>
900
+ </template>
901
+ <template #field="{ field: f }">
902
+ <CmsField v-model="state[f.key]" :field="f" :entity="entity" :error="fieldErrors[f.key]" placement="main" hide-optional />
903
+ <CmsTranslationRef
904
+ v-if="isTranslation" :field="f" :value="defaults[f.key]" :lang="defaultLabel"
905
+ :empty="state[f.key] == null || (Array.isArray(state[f.key]) && !state[f.key].length)"
906
+ @copy="copyDefault(f.key)"
907
+ />
908
+ </template>
909
+ </CmsFormSections>
910
+
911
+ <!-- write: the cover photo, the title, the summary, the text — as the reader meets them -->
912
+ <div v-else class="space-y-6">
913
+ <CmsFieldMedia
914
+ v-if="writeCover" :id="`cms-field-${writeCover.key}`" v-model="state[writeCover.key]" :field="writeCover" :entity="entity"
915
+ variant="cover" class="mb-2"
916
+ />
917
+ <!-- the title is the page heading; the address it will have sits under it -->
918
+ <div v-if="titleField">
919
+ <label v-if="titleIsAddress" :for="`cms-field-${titleField.key}`" class="block mb-1 text-sm font-medium text-highlighted">{{ fieldLabel(titleField) }}</label>
920
+ <textarea
921
+ :id="`cms-field-${titleField.key}`" v-model="state[titleField.key]" rows="1" class="cms-title-input resize-none field-sizing-content" :class="titleIsAddress ? 'cms-title-input--address' : ''"
922
+ :placeholder="titlePlaceholder"
923
+ :disabled="isTranslation && !titleField.localized"
924
+ :aria-label="fieldLabel(titleField)" :aria-invalid="!!fieldErrors[titleField.key]" :aria-describedby="fieldErrors[titleField.key] ? `cms-field-${titleField.key}-error` : undefined" autocomplete="off"
925
+ @keydown.enter.prevent
926
+ />
927
+ <p v-if="fieldErrors[titleField.key]" :id="`cms-field-${titleField.key}-error`" role="alert" class="mt-1 text-sm text-error">{{ fieldErrors[titleField.key] }}</p>
928
+ <p v-else-if="titleIsAddress && fieldHelp(titleField)" class="mt-1.5 text-sm text-muted">{{ fieldHelp(titleField) }}</p>
929
+ <p v-else-if="publicPath" class="mt-1.5 font-mono text-xs text-muted truncate">
930
+ <a v-if="isPublished" :href="publicPath" target="_blank" rel="noopener" class="hover:text-highlighted">{{ publicPath }} <UIcon name="i-lucide-arrow-up-right" class="size-3 align-[-1px]" /></a>
931
+ <template v-else>{{ publicPath }}</template>
932
+ </p>
933
+ <CmsTranslationRef
934
+ v-if="isTranslation && titleField.localized" :field="titleField" :value="defaults[titleField.key]"
935
+ :lang="defaultLabel" :empty="!state[titleField.key]" @copy="state[titleField.key] = defaults[titleField.key]"
936
+ />
937
+ </div>
938
+ <!-- the summary: large, unboxed, right under the title -->
939
+ <div v-if="writeLead">
940
+ <textarea
941
+ :id="`cms-field-${writeLead.key}`" v-model="state[writeLead.key]" rows="2"
942
+ class="cms-lead-input resize-none field-sizing-content" :maxlength="writeLead.meta?.max"
943
+ :placeholder="fieldHelp(writeLead) || fieldLabel(writeLead)"
944
+ :aria-label="fieldLabel(writeLead)" :aria-invalid="!!fieldErrors[writeLead.key]" :aria-describedby="fieldErrors[writeLead.key] ? `cms-field-${writeLead.key}-error` : undefined"
945
+ />
946
+ <p v-if="fieldErrors[writeLead.key]" :id="`cms-field-${writeLead.key}-error`" role="alert" class="mt-1 text-sm text-error">{{ fieldErrors[writeLead.key] }}</p>
947
+ <p v-else-if="writeLead.meta?.max && (state[writeLead.key]?.length ?? 0) > writeLead.meta.max * 0.8" class="mt-1 text-xs text-muted tabular-nums">
948
+ {{ state[writeLead.key]?.length ?? 0 }} / {{ writeLead.meta.max }}
949
+ </p>
950
+ <CmsTranslationRef
951
+ v-if="isTranslation" :field="writeLead" :value="defaults[writeLead.key]" :lang="defaultLabel"
952
+ :empty="!state[writeLead.key]" @copy="copyDefault(writeLead.key)"
953
+ />
954
+ </div>
955
+ <!-- the text: no box, the toolbar a quiet line above it -->
956
+ <div v-if="writeBody" :id="`cms-field-${writeBody.key}`" class="cms-write-body" :aria-label="fieldLabel(writeBody)" role="group">
957
+ <CmsFieldRichText v-model="state[writeBody.key]" :field="writeBody" />
958
+ <p v-if="fieldErrors[writeBody.key]" :id="`cms-field-${writeBody.key}-error`" role="alert" class="mt-1 text-sm text-error">{{ fieldErrors[writeBody.key] }}</p>
959
+ <CmsTranslationRef
960
+ v-if="isTranslation" :field="writeBody" :value="defaults[writeBody.key]" :lang="defaultLabel"
961
+ :empty="state[writeBody.key] == null" @copy="copyDefault(writeBody.key)"
962
+ />
963
+ </div>
964
+ <div v-for="f in writeMore" :key="f.key">
965
+ <CmsField v-model="state[f.key]" :field="f" :entity="entity" :error="fieldErrors[f.key]" placement="main" />
966
+ <CmsTranslationRef
967
+ v-if="isTranslation" :field="f" :value="defaults[f.key]" :lang="defaultLabel"
968
+ :empty="state[f.key] == null || (Array.isArray(state[f.key]) && !state[f.key].length)"
969
+ @copy="copyDefault(f.key)"
970
+ />
971
+ </div>
972
+ </div>
973
+ </div>
974
+ </div>
975
+
976
+ <aside v-if="showAside" class="cms-editor__aside" :aria-label="t('editor.details')">
977
+ <div class="cms-editor__aside-inner space-y-5">
978
+ <!-- the status itself is in the top bar; here only what it does not say -->
979
+ <div v-if="publish && !isNew && (isScheduled || !isPublished || publishedOn)" class="flex items-start gap-2 text-sm text-muted">
980
+ <UIcon :name="isScheduled ? 'i-lucide-clock' : isPublished ? 'i-lucide-globe' : 'i-lucide-pencil-line'" class="size-4 shrink-0 mt-0.5" />
981
+ <div>
982
+ <p>
983
+ <template v-if="isScheduled">{{ t('editor.goesLive', { date: formatDate(publishedOn) }) }}</template>
984
+ <template v-else-if="isPublished && publishedOn">{{ t('editor.publishedSince', { date: formatDate(publishedOn, { time: false }) }) }}</template>
985
+ <template v-else-if="!isPublished">{{ canPublish ? t('editor.notPublished') : t('editor.cannotPublish') }}</template>
986
+ </p>
987
+ <p v-if="isTranslation" class="text-xs">{{ t('translation.publishingShared') }}</p>
988
+ </div>
989
+ </div>
990
+
991
+ <!-- form and preview: what the fields do not say — where it is, when it was saved -->
992
+ <dl v-if="sectioned" class="space-y-3 text-sm">
993
+ <div v-if="isNew" class="flex items-start gap-2 text-muted">
994
+ <dt class="sr-only">{{ t('editor.newEntry') }}</dt>
995
+ <UIcon name="i-lucide-sparkles" class="size-4 shrink-0 mt-0.5" />
996
+ <dd>{{ t('editor.newEntryHint') }}</dd>
997
+ </div>
998
+ <div v-if="publicPath && isPublished" class="flex items-start gap-2 min-w-0">
999
+ <dt class="sr-only">{{ t('editor.onWebsite') }}</dt>
1000
+ <UIcon name="i-lucide-link" class="size-4 shrink-0 mt-0.5 text-muted" />
1001
+ <dd class="min-w-0"><a :href="publicPath" target="_blank" rel="noopener" class="text-highlighted hover:underline underline-offset-2 break-all">{{ publicPath }}</a></dd>
1002
+ </div>
1003
+ <div v-if="createdAt && !isNew" class="flex items-start gap-2 text-muted">
1004
+ <dt class="sr-only">{{ t('editor.created') }}</dt>
1005
+ <UIcon name="i-lucide-calendar-plus" class="size-4 shrink-0 mt-0.5" />
1006
+ <dd>{{ t('editor.createdOn', { date: formatDate(createdAt, { time: false }) }) }}</dd>
1007
+ </div>
1008
+ <div v-if="locales && !isNew" class="flex items-start gap-2">
1009
+ <dt class="sr-only">{{ t('translation.languages') }}</dt>
1010
+ <UIcon name="i-lucide-languages" class="size-4 shrink-0 mt-0.5 text-muted" />
1011
+ <dd class="min-w-0 flex-1">
1012
+ <ul class="space-y-1.5">
1013
+ <li v-for="code in locales.all" :key="code" class="flex items-center justify-between gap-2">
1014
+ <NuxtLink
1015
+ :to="{ query: code === locales.default ? {} : { locale: code } }"
1016
+ class="hover:underline underline-offset-2" :class="code === currentLocale ? 'font-medium text-highlighted' : 'text-default'"
1017
+ >{{ localeLabel(code) }}</NuxtLink>
1018
+ <span class="text-xs" :class="code === locales.default || available.includes(code) ? 'text-muted' : 'cms-unsaved'">
1019
+ {{ code === locales.default ? t('translation.default') : available.includes(code) ? t('translation.translated') : t('translation.notTranslated') }}
1020
+ </span>
1021
+ </li>
1022
+ </ul>
1023
+ </dd>
1024
+ </div>
1025
+ </dl>
1026
+
1027
+ <!-- write: the details beside the text, as quiet rows -->
1028
+ <div v-else class="space-y-1">
1029
+ <div v-for="f in writeRows" :key="f.key">
1030
+ <CmsField v-model="state[f.key]" :field="f" :entity="entity" :error="fieldErrors[f.key]" placement="sidebar" row />
1031
+ <CmsTranslationRef
1032
+ v-if="isTranslation" :field="f" :value="defaults[f.key]" :lang="defaultLabel" :empty="!state[f.key]"
1033
+ @copy="state[f.key] = defaults[f.key]"
1034
+ />
1035
+ </div>
1036
+ </div>
1037
+ <p v-if="isTranslation && hasSharedFields" class="text-xs text-muted border-t border-default pt-4">
1038
+ {{ t('translation.shared') }}
1039
+ <NuxtLink :to="{ query: {} }" class="underline underline-offset-2 hover:text-highlighted">{{ t('translation.editShared', { lang: defaultLabel }) }}</NuxtLink>
1040
+ </p>
1041
+
1042
+ <!-- write: photos, race facts, search… folded, each saying what is filled in -->
1043
+ <div v-if="!sectioned" class="border-t border-default">
1044
+ <UCollapsible v-for="g in writeGroups" :key="g.id" v-model:open="openGroups[g.id]" class="border-b border-default">
1045
+ <button type="button" class="group w-full flex items-center justify-between gap-3 py-3.5 text-left">
1046
+ <span class="text-sm font-medium text-highlighted">{{ g.label }}</span>
1047
+ <span class="flex items-center gap-2 text-xs text-muted">
1048
+ {{ groupSummary(g) }}
1049
+ <UIcon name="i-lucide-chevron-down" class="size-4 text-dimmed transition-transform group-data-[state=open]:rotate-180" />
1050
+ </span>
1051
+ </button>
1052
+ <template #content>
1053
+ <div class="space-y-5 pb-5">
1054
+ <div v-for="f in g.fields" :key="f.key">
1055
+ <CmsField v-model="state[f.key]" :field="f" :entity="entity" :error="fieldErrors[f.key]" placement="sidebar" hide-optional />
1056
+ <CmsTranslationRef
1057
+ v-if="isTranslation" :field="f" :value="defaults[f.key]" :lang="defaultLabel"
1058
+ :empty="state[f.key] == null || (Array.isArray(state[f.key]) && !state[f.key].length)"
1059
+ @copy="copyDefault(f.key)"
1060
+ />
1061
+ </div>
1062
+ </div>
1063
+ </template>
1064
+ </UCollapsible>
1065
+ </div>
1066
+ </div>
1067
+ </aside>
1068
+ </fieldset>
1069
+ <div v-if="split && previewUrl" class="cms-editor__preview">
1070
+ <CmsPreviewPanel
1071
+ :url="previewUrl" :entity="entity" :id="id"
1072
+ :locale="isTranslation ? currentLocale : null" :data="form.body()" :version="version" @close="togglePreview"
1073
+ />
1074
+ </div>
1075
+ </div>
1076
+
1077
+ <!-- small screens: the page as a full-screen sheet -->
1078
+ <UModal v-if="previewUrl" v-model:open="previewSheet" fullscreen :title="t('editor.preview')" :ui="{ header: 'hidden', body: 'p-3 sm:p-4 flex flex-col' }">
1079
+ <template #body>
1080
+ <CmsPreviewPanel
1081
+ :url="previewUrl" :entity="entity" :id="id" sheet
1082
+ :locale="isTranslation ? currentLocale : null" :data="form.body()" :version="version" @close="previewSheet = false"
1083
+ />
1084
+ </template>
1085
+ </UModal>
1086
+
1087
+ <CmsPublishReview
1088
+ v-if="publish && canPublish" v-model:open="reviewOpen"
1089
+ :checks="reviewChecks" :entity="entity" :busy="saving"
1090
+ :date-field="dateFieldDesc" :date="publish.dateField ? state[publish.dateField] : undefined"
1091
+ @update:date="(v: any) => { if (publish?.dateField) state[publish.dateField] = v }"
1092
+ @publish="publishFromReview"
1093
+ />
1094
+ <CmsMoment
1095
+ v-model:open="momentOpen" :animal="moment === 'scheduled' ? 'turtle' : 'whale'"
1096
+ :title="moment === 'scheduled' ? t('moment.scheduledTitle') : t('moment.liveTitle')"
1097
+ :description="moment === 'scheduled' ? t('moment.scheduledBody', { date: formatDate(publishedOn) }) : t('moment.liveBody')"
1098
+ >
1099
+ <UButton v-if="moment === 'published' && publicPath" :to="publicPath" target="_blank" size="sm" color="neutral" variant="outline" icon="i-lucide-arrow-up-right">{{ t('moment.view') }}</UButton>
1100
+ <UButton :to="`/admin/${entity}`" size="sm" color="neutral" variant="ghost">{{ t('moment.backTo', { list: listLabel }) }}</UButton>
1101
+ </CmsMoment>
1102
+ </CmsPage>
1103
+ </template>
1104
+
1105
+ <style scoped>
1106
+ /* Read-only: still easy to read (the browser dims disabled controls a lot). */
1107
+ .cms-fieldset:disabled :is(input, textarea, select, button):disabled { opacity: 0.85; cursor: default; }
1108
+ .cms-fieldset:disabled :deep(.cms-rte__toolbar) { display: none; }
1109
+ </style>