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,258 @@
1
+ <script setup lang="ts">
2
+ import type { DropdownMenuItem } from '@nuxt/ui'
3
+
4
+ // Team: who can sign in, with what role. Administrators invite people, change
5
+ // roles, disable access or remove someone; the server enforces every guard
6
+ // (not yourself, never the last administrator).
7
+ definePageMeta({ layout: 'admin' })
8
+ const { t } = useCmsI18n()
9
+ const toast = useToast()
10
+ const { user: me } = useUserSession()
11
+ useHead({ title: () => t('team.title') })
12
+
13
+ const isAdmin = computed(() => me.value?.role === 'admin')
14
+ const { data, refresh, error } = await useFetch<{ users: any[] }>('/api/cms/_users', { immediate: isAdmin.value })
15
+ const users = computed(() => data.value?.users ?? [])
16
+
17
+ const ROLES = ['admin', 'editor', 'author'] as const
18
+ const roleName = (r: string) => (ROLES as readonly string[]).includes(r) ? t(`roles.${r as typeof ROLES[number]}.name`) : r
19
+
20
+ // ── invite ──
21
+ const inviteOpen = ref(false)
22
+ const invite = reactive({ email: '', name: '', role: 'editor' as typeof ROLES[number] })
23
+ const inviteErrors = reactive<Record<string, string>>({})
24
+ const inviting = ref(false)
25
+ const inviteForm = ref<HTMLElement | null>(null)
26
+ const inviteFailed = ref('')
27
+ const created = ref<{ email: string; role: string; url: string; emailed: boolean } | null>(null)
28
+
29
+ function openInvite() {
30
+ Object.assign(invite, { email: '', name: '', role: 'editor' })
31
+ Object.keys(inviteErrors).forEach((k) => delete inviteErrors[k])
32
+ created.value = null
33
+ inviteOpen.value = true
34
+ }
35
+
36
+ async function sendInvite() {
37
+ Object.keys(inviteErrors).forEach((k) => delete inviteErrors[k])
38
+ inviteFailed.value = ''
39
+ inviting.value = true
40
+ try {
41
+ const res = await $fetch<{ user: any; inviteUrl: string; emailed: boolean }>('/api/cms/_users', { method: 'POST', body: invite })
42
+ created.value = { email: res.user.email, role: res.user.role, url: res.inviteUrl, emailed: res.emailed }
43
+ refresh()
44
+ }
45
+ catch (err: any) {
46
+ const issues = err?.data?.data
47
+ if (Array.isArray(issues)) for (const i of issues) if (i.path?.[0]) inviteErrors[i.path[0]] = cmsIssueMessage(i, null, t as any)
48
+ // Said in the dialog itself (read out, and the cursor goes there), not in a toast behind it.
49
+ if (!Object.keys(inviteErrors).length) inviteFailed.value = cmsRequestError(err, t as any)
50
+ await cmsFocusInvalid(inviteForm.value)
51
+ }
52
+ finally {
53
+ inviting.value = false
54
+ }
55
+ }
56
+
57
+ const copied = ref(false)
58
+ async function copy(url: string) {
59
+ await navigator.clipboard.writeText(url)
60
+ copied.value = true
61
+ setTimeout(() => { copied.value = false }, 2000)
62
+ }
63
+
64
+ // ── row actions ──
65
+ async function act(run: () => Promise<unknown>, success: string) {
66
+ try {
67
+ await run()
68
+ toast.add({ title: success, icon: 'i-lucide-check', color: 'success' })
69
+ refresh()
70
+ }
71
+ catch (err: any) {
72
+ toast.add({ title: t('team.actionFailed'), description: cmsErrorMessage(err, ''), color: 'error', icon: 'i-lucide-x' })
73
+ }
74
+ }
75
+ const patch = (id: string, body: Record<string, string>) => cmsFetch(`/api/cms/_users/${id}`, { method: 'PATCH', body })
76
+
77
+ const resent = ref<{ email: string; role: string; url: string; emailed: boolean } | null>(null)
78
+ async function resend(u: any) {
79
+ await act(async () => {
80
+ const res = await cmsFetch<{ inviteUrl: string; emailed: boolean }>(`/api/cms/_users/${u.id}/resend`, { method: 'POST' })
81
+ resent.value = { email: u.email, role: u.role, url: res.inviteUrl, emailed: res.emailed }
82
+ }, t('team.resent'))
83
+ }
84
+
85
+ // Someone who never accepted the invitation has only an invitation to take back.
86
+ const confirm = useCmsConfirm()
87
+ async function remove(u: any) {
88
+ const name = u.name || u.email
89
+ const invited = u.status === 'invited'
90
+ const ok = await confirm({
91
+ title: t(invited ? 'team.cancelInviteTitle' : 'team.removeTitle', { name }),
92
+ description: t(invited ? 'team.cancelInviteBody' : 'team.removeBody'),
93
+ icon: invited ? 'i-lucide-mail-x' : 'i-lucide-user-minus', color: 'error',
94
+ confirmLabel: t(invited ? 'team.cancelInvite' : 'team.remove'),
95
+ cancelLabel: t(invited ? 'team.keepInvite' : 'common.cancel'),
96
+ })
97
+ if (ok) await act(() => cmsFetch(`/api/cms/_users/${u.id}`, { method: 'DELETE' }), t(invited ? 'team.inviteCancelled' : 'team.removed'))
98
+ }
99
+
100
+ // Turning someone's access off signs them out at once and takes their drafts out of reach:
101
+ // asked first (it is undone with "Enable access", but not before they have been locked out).
102
+ async function disable(u: any) {
103
+ const name = u.name || u.email
104
+ const ok = await confirm({
105
+ title: t('team.disableTitle', { name }), description: t('team.disableBody'),
106
+ icon: 'i-lucide-ban', color: 'error', confirmLabel: t('team.disable'), cancelLabel: t('common.cancel'),
107
+ })
108
+ if (ok) await act(() => patch(u.id, { status: 'disabled' }), t('team.disabled'))
109
+ }
110
+
111
+ function rowMenu(u: any): DropdownMenuItem[][] {
112
+ const groups: DropdownMenuItem[][] = [[{
113
+ label: t('team.changeRole'), icon: 'i-lucide-shield',
114
+ children: ROLES.map((r) => ({
115
+ label: roleName(r), type: 'checkbox' as const, checked: u.role === r,
116
+ onSelect: () => { if (u.role !== r) act(() => patch(u.id, { role: r }), t('team.roleChanged')) },
117
+ })),
118
+ }]]
119
+ if (u.status === 'invited') groups[0]!.push({ label: t('team.resend'), icon: 'i-lucide-send', onSelect: () => resend(u) })
120
+ if (u.status === 'active') groups[0]!.push({ label: t('team.disable'), icon: 'i-lucide-ban', onSelect: () => disable(u) })
121
+ if (u.status === 'disabled') groups[0]!.push({ label: t('team.enable'), icon: 'i-lucide-rotate-ccw', onSelect: () => act(() => patch(u.id, { status: 'active' }), t('team.enabled')) })
122
+ groups.push([u.status === 'invited'
123
+ ? { label: t('team.cancelInvite'), icon: 'i-lucide-mail-x', color: 'error' as const, onSelect: () => remove(u) }
124
+ : { label: t('team.remove'), icon: 'i-lucide-trash-2', color: 'error' as const, onSelect: () => remove(u) }])
125
+ return groups
126
+ }
127
+
128
+ const initials = (u: any) => (u.name || u.email).split(/[\s@.]+/).filter(Boolean).map((p: string) => p[0]).join('').slice(0, 2).toUpperCase()
129
+ </script>
130
+
131
+ <template>
132
+ <CmsPage :title="t('team.title')" :description="t('team.description')" :breadcrumbs="[{ label: t('nav.home'), to: '/admin' }, { label: t('team.title') }]">
133
+ <template v-if="isAdmin" #actions>
134
+ <UButton icon="i-lucide-user-plus" @click="openInvite">{{ t('team.invite') }}</UButton>
135
+ </template>
136
+
137
+ <div class="cms-card overflow-hidden">
138
+ <CmsEmptyState v-if="!isAdmin" plain icon="i-lucide-lock" :title="t('team.adminsOnly')" />
139
+ <CmsLoadError v-else-if="error" :error="error" @retry="refresh()" />
140
+ <!-- phones: each person is a small card (name, then role and status under it) -->
141
+ <div v-else class="sm:overflow-x-auto">
142
+ <table class="w-full text-sm max-sm:block">
143
+ <thead class="max-sm:hidden">
144
+ <tr class="border-b border-default text-left text-muted">
145
+ <th scope="col" class="font-medium px-4 py-2.5">{{ t('team.person') }}</th>
146
+ <th scope="col" class="font-medium px-4 py-2.5">{{ t('team.role') }}</th>
147
+ <th scope="col" class="font-medium px-4 py-2.5">{{ t('team.status') }}</th>
148
+ <th scope="col" class="font-medium px-4 py-2.5 whitespace-nowrap">{{ t('team.lastActive') }}</th>
149
+ <th class="w-12"><span class="sr-only">{{ t('common.edit') }}</span></th>
150
+ </tr>
151
+ </thead>
152
+ <tbody class="max-sm:block">
153
+ <tr v-for="u in users" :key="u.id" class="border-b border-default last:border-0 max-sm:grid max-sm:grid-cols-[minmax(0,1fr)_auto] max-sm:gap-x-2 max-sm:gap-y-1 max-sm:px-4 max-sm:py-3">
154
+ <td class="px-4 py-3 max-sm:p-0 max-sm:col-start-1 max-sm:row-start-1">
155
+ <div class="flex items-center gap-3 min-w-0">
156
+ <span class="size-8 shrink-0 rounded-full bg-(--cms-moment-strong) text-highlighted grid place-items-center text-xs font-medium">{{ initials(u) }}</span>
157
+ <span class="min-w-0">
158
+ <span class="flex items-center gap-2">
159
+ <span class="font-medium text-highlighted truncate">{{ u.name || u.email }}</span>
160
+ <UBadge v-if="u.id === me?.id" color="neutral" variant="outline" size="sm">{{ t('team.you') }}</UBadge>
161
+ </span>
162
+ <span v-if="u.name" class="block text-muted truncate">{{ u.email }}</span>
163
+ </span>
164
+ </div>
165
+ </td>
166
+ <td class="px-4 py-3 whitespace-nowrap max-sm:col-start-1 max-sm:p-0 max-sm:pl-11 max-sm:text-muted">{{ roleName(u.role) }}</td>
167
+ <td class="px-4 py-3 whitespace-nowrap max-sm:col-start-1 max-sm:p-0 max-sm:pl-11">
168
+ <!-- a dot and a word, as every status in the admin -->
169
+ <span v-if="u.status === 'active'" class="inline-flex items-center gap-2 text-default">
170
+ <span class="size-2 rounded-full bg-success" aria-hidden="true" />{{ t('team.statusActive') }}
171
+ </span>
172
+ <span v-else-if="u.status === 'invited'" class="inline-flex flex-col">
173
+ <span class="inline-flex items-center gap-2 text-default">
174
+ <span class="size-2 rounded-full bg-info" aria-hidden="true" />{{ t('team.statusInvited') }}
175
+ </span>
176
+ <span v-if="u.invite?.expiresAt" class="mt-1 text-xs text-muted">{{ t('team.inviteExpires', { time: '' }) }}<CmsTime :value="u.invite.expiresAt" relative /></span>
177
+ <span v-else class="mt-1 text-xs cms-unsaved">{{ t('team.inviteExpiredBadge') }}</span>
178
+ </span>
179
+ <span v-else class="inline-flex items-center gap-2 text-muted">
180
+ <span class="size-2 rounded-full ring-[1.5px] ring-inset ring-(--ui-text-dimmed)" aria-hidden="true" />{{ t('team.statusDisabled') }}
181
+ </span>
182
+ </td>
183
+ <td class="px-4 py-3 text-muted whitespace-nowrap max-sm:hidden">
184
+ <CmsTime v-if="u.lastLoginAt" :value="u.lastLoginAt" relative />
185
+ <span v-else>{{ t('team.never') }}</span>
186
+ </td>
187
+ <td class="px-2 py-3 text-right max-sm:p-0 max-sm:col-start-2 max-sm:row-start-1 max-sm:self-center">
188
+ <UDropdownMenu v-if="u.id !== me?.id" :items="rowMenu(u)" :content="{ align: 'end' }">
189
+ <UButton color="neutral" variant="ghost" icon="i-lucide-ellipsis" size="sm" :aria-label="t('common.edit')" />
190
+ </UDropdownMenu>
191
+ </td>
192
+ </tr>
193
+ </tbody>
194
+ </table>
195
+ </div>
196
+ </div>
197
+
198
+ <!-- Invite -->
199
+ <UModal v-model:open="inviteOpen" :title="created ? t(created.emailed ? 'team.inviteSent' : 'team.inviteCreated', { email: created.email }) : t('team.inviteTitle')">
200
+ <template #body>
201
+ <div v-if="created" class="space-y-4">
202
+ <UAlert v-if="!created.emailed" color="warning" variant="subtle" icon="i-lucide-mail-warning" :title="t('team.inviteNotEmailed')" />
203
+ <UFormField :label="t('team.inviteLink')" :description="t('team.linkNote', { role: roleName(created.role).toLowerCase() })">
204
+ <div class="flex gap-2">
205
+ <UInput :model-value="created.url" readonly class="flex-1 font-mono text-xs" />
206
+ <UButton color="neutral" variant="outline" :icon="copied ? 'i-lucide-check' : 'i-lucide-copy'" @click="copy(created.url)">{{ copied ? t('team.copied') : t('team.copyLink') }}</UButton>
207
+ </div>
208
+ </UFormField>
209
+ </div>
210
+ <form v-else id="cms-invite" ref="inviteForm" class="space-y-5" novalidate @submit.prevent="sendInvite">
211
+ <UFormField :label="t('auth.email')" name="email" :error="inviteErrors.email || undefined" required>
212
+ <UInput v-model="invite.email" type="email" autofocus class="w-full" />
213
+ <template #error="{ error }"><span v-if="error" role="alert">{{ error }}</span></template>
214
+ </UFormField>
215
+ <UFormField :label="t('team.inviteName')" name="name">
216
+ <UInput v-model="invite.name" class="w-full" />
217
+ </UFormField>
218
+ <UFormField :label="t('team.role')" name="role">
219
+ <URadioGroup
220
+ v-model="invite.role" variant="card" indicator="start" :aria-label="t('team.role')"
221
+ :ui="{ item: 'has-data-[state=checked]:bg-(--cms-moment-bg) has-data-[state=checked]:border-(--cms-moment-line)' }"
222
+ :items="ROLES.map((r: typeof ROLES[number]) => ({ value: r, label: t(`roles.${r}.name`), description: t(`roles.${r}.description`) }))"
223
+ />
224
+ </UFormField>
225
+ <UAlert v-if="inviteFailed" color="error" variant="subtle" icon="i-lucide-circle-alert" :title="inviteFailed" role="alert" data-cms-error-summary />
226
+ </form>
227
+ </template>
228
+ <template #footer>
229
+ <div class="flex justify-end gap-2 w-full">
230
+ <template v-if="created">
231
+ <UButton color="neutral" variant="ghost" icon="i-lucide-user-plus" @click="openInvite">{{ t('team.inviteAnother') }}</UButton>
232
+ <UButton @click="inviteOpen = false">{{ t('common.close') }}</UButton>
233
+ </template>
234
+ <template v-else>
235
+ <UButton color="neutral" variant="ghost" @click="inviteOpen = false">{{ t('common.cancel') }}</UButton>
236
+ <UButton type="submit" form="cms-invite" icon="i-lucide-send" :loading="inviting">{{ t('team.sendInvite') }}</UButton>
237
+ </template>
238
+ </div>
239
+ </template>
240
+ </UModal>
241
+
242
+ <!-- A resent invitation: show the new link too -->
243
+ <UModal :open="!!resent" :title="resent ? t(resent.emailed ? 'team.inviteSent' : 'team.inviteCreated', { email: resent.email }) : ''" @update:open="(v: boolean) => { if (!v) resent = null }">
244
+ <template #body>
245
+ <div v-if="resent" class="space-y-4">
246
+ <UAlert v-if="!resent.emailed" color="warning" variant="subtle" icon="i-lucide-mail-warning" :title="t('team.inviteNotEmailed')" />
247
+ <UFormField :label="t('team.inviteLink')" :description="t('team.linkNote', { role: roleName(resent.role).toLowerCase() })">
248
+ <div class="flex gap-2">
249
+ <UInput :model-value="resent.url" readonly class="flex-1 font-mono text-xs" />
250
+ <UButton color="neutral" variant="outline" :icon="copied ? 'i-lucide-check' : 'i-lucide-copy'" @click="copy(resent.url)">{{ copied ? t('team.copied') : t('team.copyLink') }}</UButton>
251
+ </div>
252
+ </UFormField>
253
+ </div>
254
+ </template>
255
+ </UModal>
256
+
257
+ </CmsPage>
258
+ </template>
@@ -0,0 +1,20 @@
1
+ // Live preview on the website. Inside the admin's preview panel (an iframe with
2
+ // ?preview), the page refetches its content whenever the editor types: the admin has
3
+ // already handed the unsaved values to the server, and the content API lays them over
4
+ // the entry for that editor's ?preview requests (server/utils/cmsPreviewDraft.ts).
5
+ // Any page that loads its content through the content API with ?preview updates
6
+ // without code of its own; scroll position and page state stay as they are.
7
+ //
8
+ // A site that renders from something else can listen too: the message is
9
+ // { type: 'cms:preview', entity, id, locale, data } with the form's values.
10
+ export default defineNuxtPlugin(() => {
11
+ if (window.parent === window) return
12
+ if (!new URLSearchParams(location.search).has('preview')) return
13
+ let timer: ReturnType<typeof setTimeout> | undefined
14
+ window.addEventListener('message', (e: MessageEvent) => {
15
+ if (e.origin !== location.origin || e.source !== window.parent) return
16
+ if (e.data?.type !== 'cms:preview') return
17
+ clearTimeout(timer)
18
+ timer = setTimeout(() => { refreshNuxtData() }, 30)
19
+ })
20
+ })
@@ -0,0 +1,31 @@
1
+ // The admin stays open while the account changes under it — disabled, removed, its role or
2
+ // password changed elsewhere, the session expired. Every list and page then fails with a 401
3
+ // ("Authentication required") and "Try again" can never help. Instead: the first read the server
4
+ // refuses sends the person to sign-in with "You were signed out", and after signing in they come
5
+ // back to the page they were on.
6
+ //
7
+ // Only reads (GET) of the admin's own API (`/api/cms/…`, not the sign-in calls) while an admin
8
+ // page is open: a save that is refused keeps the page and says so (the editor holds the unsaved
9
+ // text), and the website's own requests are never touched.
10
+ export default defineNuxtPlugin((nuxtApp) => {
11
+ const router = useRouter()
12
+ const base = globalThis.$fetch
13
+ let leaving = false
14
+ globalThis.$fetch = base.create({
15
+ onResponseError({ request, options, response }) {
16
+ if (response.status !== 401 || leaving) return
17
+ const url = typeof request === 'string' ? request : (request as Request).url
18
+ const path = url.startsWith('http') ? new URL(url).pathname : url.split('?')[0]!
19
+ const method = String(options.method ?? (request as Request).method ?? 'GET').toUpperCase()
20
+ const here = router.currentRoute.value
21
+ if (method !== 'GET' || !path.startsWith('/api/cms/') || path.startsWith('/api/cms/_auth/')) return
22
+ if (!here.path.startsWith('/admin') || /^\/admin\/(login|setup|forgot|reset|invite)/.test(here.path)) return
23
+ leaving = true
24
+ void nuxtApp.runWithContext(async () => {
25
+ const { clear } = useUserSession()
26
+ try { await clear() } catch { /* the cookie is gone or invalid anyway */ }
27
+ await navigateTo({ path: '/admin/login', query: { redirect: here.fullPath, reason: 'signedOut' } })
28
+ }).finally(() => { leaving = false })
29
+ },
30
+ }) as typeof $fetch
31
+ })
@@ -0,0 +1,11 @@
1
+ // Which block types the website may draw. A block's `type` picks a component by name
2
+ // (`hero` → BlockHero), and the name is derived from it, so odd spellings (`Hero`,
3
+ // `_hero`, `-hero`, `hero-`) would all land on the component of a known type. Only the
4
+ // spelling a definition can be written in counts: starts with a lower-case letter or a
5
+ // digit, words joined by single `_` or `-`.
6
+ const RENDERABLE = /^[a-z0-9][A-Za-z0-9]*([_-][A-Za-z0-9]+)*$/
7
+
8
+ /** Is this a block type that maps to exactly one component name? */
9
+ export function renderableBlockType(type: unknown): type is string {
10
+ return typeof type === 'string' && RENDERABLE.test(type)
11
+ }
@@ -0,0 +1,38 @@
1
+ import faviconUrl from '../assets/brand/logo/favicon.svg?url'
2
+ import mascotUrl from '../assets/brand/logo/mascot.svg?url'
3
+ import mascotReversedUrl from '../assets/brand/logo/mascot-reversed.svg?url'
4
+ import wordmarkUrl from '../assets/brand/logo/wordmark.svg?url'
5
+ import wordmarkReversedUrl from '../assets/brand/logo/wordmark-reversed.svg?url'
6
+ import logoUrl from '../assets/brand/logo/logo-primary.svg?url'
7
+ import logoReversedUrl from '../assets/brand/logo/logo-primary-reversed.svg?url'
8
+
9
+ /**
10
+ * tinyzoo's own brand inside the admin (docs/brand/brand-guide.md). The client's name
11
+ * leads; tinyzoo shows in calm places: its signature under the sidebar and on the
12
+ * sign-in, the tab icon, and one animal at each moment (welcome, sign-in, empty
13
+ * states, success, errors) — never in the chrome.
14
+ */
15
+ export const cmsBrand = { name: 'tinyzoo', faviconUrl, mascotUrl, mascotReversedUrl, wordmarkUrl, wordmarkReversedUrl, logoUrl, logoReversedUrl }
16
+
17
+ const muted = import.meta.glob('../assets/brand/characters/muted/*.svg', { eager: true, query: '?url', import: 'default' }) as Record<string, string>
18
+ const bright = import.meta.glob('../assets/brand/characters/bright/*.svg', { eager: true, query: '?url', import: 'default' }) as Record<string, string>
19
+
20
+ const list = (files: Record<string, string>) => Object.entries(files)
21
+ .map(([path, url]) => ({ name: path.split('/').pop()!.replace(/\.svg$/, ''), url }))
22
+ // One fixed order everywhere (in Czech "ch" sorts after "h": the server and a Czech browser would disagree).
23
+ .sort((a, b) => a.name.localeCompare(b.name, 'en'))
24
+
25
+ /** The animal family: 26 muted characters (the admin's) and the 6 bright ones. */
26
+ export const cmsCharacters = { muted: list(muted), bright: list(bright) }
27
+
28
+ /** The same animal for the same place every time (a collection always has its own). */
29
+ export function cmsCharacterFor(seed: string): { name: string; url: string } {
30
+ let h = 0
31
+ for (const c of seed) h = (h * 31 + c.charCodeAt(0)) >>> 0
32
+ return cmsCharacters.muted[h % cmsCharacters.muted.length]!
33
+ }
34
+
35
+ /** One animal by name ('owl', 'hedgehog'…), muted first — for the fixed moments. */
36
+ export function cmsCharacter(name: string, set: 'muted' | 'bright' = 'muted'): { name: string; url: string } {
37
+ return cmsCharacters[set].find((c) => c.name === name) ?? cmsCharacters.muted[0]!
38
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Small helpers for showing what changed between two versions of a field.
3
+ */
4
+
5
+ /**
6
+ * Plain text of a rich-text document, one line per paragraph, heading or list item
7
+ * (bullets and numbers kept, nested items indented), so a list reads as a list and
8
+ * its items never run together when two versions are compared.
9
+ */
10
+ export function richTextToPlain(doc: any): string {
11
+ if (!doc || typeof doc !== 'object') return ''
12
+ const inline = (node: any): string => {
13
+ if (!node) return ''
14
+ if (node.type === 'text') return node.text ?? ''
15
+ if (node.type === 'hardBreak') return '\n'
16
+ if (node.type === 'image') return '[image]'
17
+ return (node.content ?? []).map(inline).join('')
18
+ }
19
+ const lines: string[] = []
20
+ const block = (node: any, indent: string, first: string) => {
21
+ if (!node) return
22
+ if (node.type === 'bulletList' || node.type === 'orderedList') {
23
+ ;(node.content ?? []).forEach((item: any, i: number) => {
24
+ const bullet = node.type === 'orderedList' ? `${(Number(node.attrs?.start) || 1) + i}. ` : '• '
25
+ listItem(item, indent, bullet)
26
+ })
27
+ }
28
+ else if (node.type === 'blockquote') {
29
+ for (const child of node.content ?? []) block(child, indent, indent)
30
+ }
31
+ else lines.push(first + inline(node))
32
+ }
33
+ const listItem = (item: any, indent: string, bullet: string) => {
34
+ const pad = indent + ' '.repeat(bullet.length)
35
+ let used = false
36
+ for (const child of item?.content ?? []) {
37
+ if (child?.type === 'bulletList' || child?.type === 'orderedList') block(child, pad, pad)
38
+ else {
39
+ block(child, pad, used ? pad : indent + bullet)
40
+ used = true
41
+ }
42
+ }
43
+ if (!used) lines.push(indent + bullet.trimEnd())
44
+ }
45
+ for (const node of doc.content ?? []) block(node, '', '')
46
+ return lines.join('\n').trim()
47
+ }
48
+
49
+ export interface DiffPart { text: string; kind: 'same' | 'added' | 'removed' }
50
+
51
+ /**
52
+ * Word-level difference from `a` to `b` (longest common subsequence). Long texts
53
+ * fall back to "all removed, all added" rather than stalling the page.
54
+ */
55
+ export function wordDiff(a: string, b: string): DiffPart[] {
56
+ const x = a.split(/(\s+)/).filter(Boolean)
57
+ const y = b.split(/(\s+)/).filter(Boolean)
58
+ if (x.length * y.length > 400_000) {
59
+ return [...(a ? [{ text: a, kind: 'removed' as const }] : []), ...(b ? [{ text: b, kind: 'added' as const }] : [])]
60
+ }
61
+ const n = x.length
62
+ const m = y.length
63
+ const lcs: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0))
64
+ for (let i = n - 1; i >= 0; i--) {
65
+ for (let j = m - 1; j >= 0; j--) lcs[i]![j] = x[i] === y[j] ? lcs[i + 1]![j + 1]! + 1 : Math.max(lcs[i + 1]![j]!, lcs[i]![j + 1]!)
66
+ }
67
+ const out: DiffPart[] = []
68
+ const push = (text: string, kind: DiffPart['kind']) => {
69
+ const last = out[out.length - 1]
70
+ if (last && last.kind === kind) last.text += text
71
+ else out.push({ text, kind })
72
+ }
73
+ let i = 0
74
+ let j = 0
75
+ while (i < n && j < m) {
76
+ if (x[i] === y[j]) { push(x[i]!, 'same'); i++; j++ }
77
+ else if (lcs[i + 1]![j]! >= lcs[i]![j + 1]!) push(x[i++]!, 'removed')
78
+ else push(y[j++]!, 'added')
79
+ }
80
+ while (i < n) push(x[i++]!, 'removed')
81
+ while (j < m) push(y[j++]!, 'added')
82
+ return out
83
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `$fetch` for the admin's own API calls with a computed address. Nuxt types each
3
+ * call against every route of the host app; with a dynamic address in a large app
4
+ * that comparison exceeds TypeScript's depth limit and fails the host's typecheck.
5
+ * The admin's calls are typed by their result instead.
6
+ */
7
+ export const cmsFetch = <T = any>(url: string, options?: Record<string, any>): Promise<T> => ($fetch as any)(url, options)
@@ -0,0 +1,22 @@
1
+ /**
2
+ * After a failed submit: put the cursor on the first field that is wrong, so a keyboard or
3
+ * screen-reader user lands where the problem is (and is told it) instead of on `<body>`.
4
+ * Looks for `aria-invalid="true"` inside `root` (the form or dialog; the whole page by
5
+ * default) and, when no field is marked, on the first `[data-cms-error-summary]` / alert.
6
+ * Call it after the error state is set; it waits for the DOM to show it.
7
+ */
8
+ export async function cmsFocusInvalid(root?: ParentNode | null, fallbackId?: string): Promise<boolean> {
9
+ if (!import.meta.client) return false
10
+ await nextTick()
11
+ const scope: ParentNode = root ?? document
12
+ const field = scope.querySelector<HTMLElement>('[aria-invalid="true"]:not([disabled]):not([type="hidden"])')
13
+ // A composite field (rich text, pictures, blocks) has no single control to mark: its box is the next best place.
14
+ const summary = field ? null : (fallbackId ? document.getElementById(fallbackId) : null) ?? scope.querySelector<HTMLElement>('[data-cms-error-summary], [role="alert"]:not(:empty)')
15
+ const target = field ?? summary
16
+ if (!target) return false
17
+ if (!field && target.tabIndex < 0) target.tabIndex = -1
18
+ const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
19
+ target.focus({ preventScroll: true })
20
+ target.scrollIntoView?.({ block: 'center', behavior: reduce ? 'auto' : 'smooth' })
21
+ return true
22
+ }
@@ -0,0 +1,128 @@
1
+ // A failed save names what is wrong per field in the validator's own words ("Invalid
2
+ // input: expected string, received undefined"). Editors get a plain sentence in their
3
+ // language instead, by the kind of problem; a message the developer wrote (a custom
4
+ // rule) is kept as it is.
5
+ type T = (key: string, params?: Record<string, any>) => string
6
+
7
+ export function cmsIssueMessage(issue: any, field: any, t: T): string {
8
+ const code = issue?.code
9
+ const msg = String(issue?.message ?? '')
10
+ const empty = /received (undefined|null)\b/.test(msg)
11
+ switch (code) {
12
+ case 'invalid_type':
13
+ if (empty) return field?.type === 'datetime' || field?.type === 'date' ? t('validation.pickDate') : t('validation.required')
14
+ if (issue.expected === 'date') return t('validation.pickDate')
15
+ // A decimal in a whole-number field (a count, a position).
16
+ if (issue.expected === 'int' || issue.expected === 'integer') return t('validation.wholeNumber')
17
+ if (issue.expected === 'number') return t('validation.number')
18
+ return t('validation.invalid')
19
+ case 'too_small':
20
+ if (issue.origin === 'string') return issue.minimum <= 1 ? t('validation.required') : t('validation.minLength', { n: issue.minimum })
21
+ if (issue.origin === 'array') return issue.minimum <= 1 ? t('validation.pickOne') : t('validation.minItems', { n: issue.minimum })
22
+ return t('validation.min', { n: issue.minimum })
23
+ case 'too_big':
24
+ if (issue.origin === 'string') return t('validation.maxLength', { n: issue.maximum })
25
+ if (issue.origin === 'array') return t('validation.maxItems', { n: issue.maximum })
26
+ return t('validation.max', { n: issue.maximum })
27
+ case 'invalid_format':
28
+ if (issue.format === 'email') return t('validation.email')
29
+ if (issue.format === 'url') return t('validation.url')
30
+ if (field?.type === 'slug') return t('validation.slug')
31
+ if (field?.meta?.format === 'color') return t('fields.colorHint')
32
+ if (field?.meta?.format === 'path' || msg.startsWith('Start with /')) return t('validation.path')
33
+ return t('validation.invalid')
34
+ case 'invalid_value':
35
+ return t('validation.pickOption')
36
+ case 'unrecognized_keys':
37
+ // A block that went through `upgrade` is checked strictly: a key the definition does not know.
38
+ return t('validation.blockUnknownFields', { keys: Array.isArray(issue.keys) ? issue.keys.join(', ') : '' })
39
+ case 'unique':
40
+ // A page tree: the whole address is taken, not just the part.
41
+ if (issue.address) return t('validation.addressTaken', { address: issue.address, title: issue.otherTitle ?? '' })
42
+ return t('validation.unique')
43
+ case 'tree_cycle':
44
+ return t('validation.treeCycle', { loop: Array.isArray(issue.loop) ? issue.loop.join(' → ') : '' })
45
+ case 'tree_depth':
46
+ return t('validation.treeDepth', { max: issue.maxDepth ?? '' })
47
+ case 'tree_parent_missing':
48
+ return t('validation.treeParentMissing')
49
+ case 'redirect_loop':
50
+ return t('validation.redirectLoop')
51
+ case 'redirect_circle':
52
+ return t('validation.redirectCircle')
53
+ case 'custom':
54
+ // The developer's own words ("Use /page, https://…") — known ones translated.
55
+ if (msg.startsWith('Use /page')) return t('validation.link')
56
+ // The server's words about a block (see blocksSchema), in the editor's language.
57
+ if (msg.startsWith('This block could not be brought up to date')) return t('validation.blockStale')
58
+ if (msg.startsWith('This block is out of date')) return t('validation.blockOutOfDate')
59
+ if (msg.startsWith('This block has fields this site does not know')) return t('validation.blockUnknownFields', { keys: /\(([^)]*)\)/.exec(msg)?.[1] ?? '' })
60
+ if (msg === 'Unknown block type' || msg.startsWith('This block type does not exist')) return t('validation.blockTypeGone')
61
+ if (msg.startsWith('Saved by a newer version of this site')) return t('validation.blockNewer')
62
+ return msg
63
+ default:
64
+ if (msg === 'Wrong password') return t('validation.wrongPassword')
65
+ return t('validation.invalid')
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Toast text for a refused delete: "still in use" names where (up to five titles),
71
+ * anything else gives the server's reason.
72
+ */
73
+ export function cmsDeleteFailure(err: any, t: T, name?: (label: unknown) => string): { title: string; description?: string } {
74
+ const data = err?.data?.data
75
+ if (data?.code === 'in_use') {
76
+ const short = (s: string) => (s.length > 40 ? s.slice(0, 39).trimEnd() + '…' : s)
77
+ const used: any[] = data.usedBy ?? []
78
+ // A global (a menu, the site settings) has no title: it is named by its collection.
79
+ const named = (u: any) => (u.title ? t('common.quoted', { text: short(String(u.title)) }) : u.singleton && name ? name(u.label) : '')
80
+ const titles: string[] = used.map(named).filter(Boolean)
81
+ const shown = titles.length ? [...new Set(titles)].slice(0, 5).join(', ') + (titles.length > 5 ? '…' : '') : ''
82
+ // What this person may not read is not named, only counted.
83
+ const hidden = Number(data.hidden ?? 0)
84
+ const items = [shown, hidden > 0 ? t('list.inUseHidden', { count: hidden }) : ''].filter(Boolean).join(', ') || '—'
85
+ // Links to a page by reference (a menu, a button) have their own wording: remove the links.
86
+ const onlyLinks = used.length > 0 && used.every((u) => u.via === 'link')
87
+ return { title: t('list.inUseTitle'), description: t(onlyLinks ? 'list.inUseLinkBody' : 'list.inUseBody', { items }) }
88
+ }
89
+ // A page with pages under it: say which, so they can be moved first.
90
+ if (data?.code === 'has_children') {
91
+ const short = (s: string) => (s.length > 40 ? s.slice(0, 39).trimEnd() + '…' : s)
92
+ const titles: string[] = (data.children ?? []).map((c: any) => (c.title ? t('common.quoted', { text: short(String(c.title)) }) : '')).filter(Boolean)
93
+ const more = Number(data.count ?? titles.length) - titles.length
94
+ const items = titles.length ? titles.join(', ') + (more > 0 ? '…' : '') : '—'
95
+ return { title: t('tree.hasChildrenTitle'), description: t('tree.hasChildrenBody', { items }) }
96
+ }
97
+ return { title: t('list.deleteFailed'), description: cmsRequestError(err, t) }
98
+ }
99
+
100
+ /**
101
+ * A failed request in words an editor can act on (never "[PATCH] … Failed to fetch"):
102
+ * offline, not allowed, too large, a file type we don't take, too many tries, a server
103
+ * problem — otherwise the server's own reason.
104
+ */
105
+ export function cmsRequestError(err: any, t: T, extra: { maxMb?: number } = {}): string {
106
+ const status = err?.statusCode ?? err?.status ?? err?.response?.status
107
+ if (!status) return t('errors.offline')
108
+ // The server states the limit it applied (a picture over the pixel limit, a file over the cap).
109
+ const detail = err?.data?.data
110
+ if (detail?.code === 'image_too_many_pixels') return t('errors.imagePixels', { mp: detail.maxMegapixels })
111
+ if (status === 413 && !extra.maxMb && detail?.maxMb) extra = { ...extra, maxMb: detail.maxMb }
112
+ if (status === 400 && err?.data?.statusMessage === 'The file is empty') return t('errors.emptyFile')
113
+ if (status === 401) return t('errors.signedOut')
114
+ if (status === 403) return t('errors.forbidden')
115
+ if (status === 413) {
116
+ // "File too large (max 10MB)": the server names its limit, and so do we.
117
+ const mb = extra.maxMb ?? (Number(/(\d+)\s*MB/i.exec(String(err?.data?.statusMessage ?? err?.statusMessage ?? ''))?.[1]) || undefined)
118
+ return mb ? t('errors.tooLargeMax', { mb }) : t('errors.tooLarge')
119
+ }
120
+ if (status === 415) return t('errors.fileType')
121
+ if (status === 429) return t('errors.tooMany')
122
+ if (status >= 500) return t('errors.server')
123
+ // The server's own sentence is English: an editor gets one in their language, by the kind of refusal.
124
+ if (status === 404) return t('errors.notFound')
125
+ if (status === 409) return err?.data?.statusMessage === 'Save the default language first' ? t('errors.saveDefaultFirst') : t('errors.conflict')
126
+ if (status === 400 || status === 422) return t('errors.invalid')
127
+ return t('errors.refused')
128
+ }
@@ -0,0 +1,28 @@
1
+ import { stableJson as stable } from '../../shared/json'
2
+ import { formJson as form, withoutTrailingEmpty } from '../../shared/richtext-normalize'
3
+
4
+ /** Key-order-insensitive JSON (see shared/json.ts). */
5
+ export function stableJson(value: unknown): string {
6
+ return stable(value)
7
+ }
8
+
9
+ /** Like `stableJson`, for comparing form values: rich text without its trailing empty paragraphs. */
10
+ export function cmsFormJson(value: unknown): string {
11
+ return form(value)
12
+ }
13
+
14
+ /** Rich text with nothing in it (no nodes, or only empty paragraphs) — the same as no value. */
15
+ export function isEmptyRichText(value: any): boolean {
16
+ if (value === null || value === undefined) return true
17
+ if (value?.type !== 'doc') return false
18
+ return !(value.content ?? []).some((n: any) => n?.type !== 'paragraph' || n.content?.length)
19
+ }
20
+
21
+ /**
22
+ * Do two rich-text values say the same thing? Key order, emptiness and the empty
23
+ * paragraph the editor puts after a last heading or list do not count.
24
+ */
25
+ export function sameRichText(a: unknown, b: unknown): boolean {
26
+ if (isEmptyRichText(a) && isEmptyRichText(b)) return true
27
+ return stableJson(withoutTrailingEmpty(a)) === stableJson(withoutTrailingEmpty(b))
28
+ }