tinyzoo 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) 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 +98 -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 +393 -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/cmsTiming.ts +14 -0
  312. package/server/utils/cmsTooMany.ts +9 -0
  313. package/server/utils/cmsTranslationWrite.ts +186 -0
  314. package/server/utils/cmsTree.ts +251 -0
  315. package/server/utils/cmsTreeAddress.ts +65 -0
  316. package/server/utils/cmsUpload.ts +228 -0
  317. package/server/utils/cmsWebhooks.ts +104 -0
  318. package/shared/json.ts +11 -0
  319. package/shared/richtext-editor.ts +56 -0
  320. package/shared/richtext-normalize.ts +33 -0
  321. package/shared/richtext-paste.ts +151 -0
  322. package/shared/storage-delivery.ts +53 -0
  323. package/src/blocks.ts +624 -0
  324. package/src/changes.ts +54 -0
  325. package/src/content-shape.ts +340 -0
  326. package/src/deprecate.ts +64 -0
  327. package/src/descriptor.ts +149 -0
  328. package/src/docs.ts +27 -0
  329. package/src/emitter.ts +94 -0
  330. package/src/entity.ts +624 -0
  331. package/src/errorReport.ts +41 -0
  332. package/src/fields.ts +465 -0
  333. package/src/i18n.ts +26 -0
  334. package/src/index.ts +54 -0
  335. package/src/linkref.ts +31 -0
  336. package/src/links.ts +179 -0
  337. package/src/locales.ts +39 -0
  338. package/src/media.ts +48 -0
  339. package/src/migrate.ts +236 -0
  340. package/src/openapi.ts +377 -0
  341. package/src/paths.ts +88 -0
  342. package/src/plugin.ts +505 -0
  343. package/src/presets.ts +230 -0
  344. package/src/richtext.ts +88 -0
  345. package/src/sdk.ts +181 -0
  346. package/src/search.ts +312 -0
  347. package/src/seed.ts +225 -0
  348. package/src/setupCode.ts +30 -0
  349. package/src/system.ts +219 -0
  350. package/src/tree.ts +421 -0
  351. package/src/upgrades.ts +137 -0
  352. package/starter/.env.example +10 -0
  353. package/starter/README.md +65 -0
  354. package/starter/app/app.config.ts +10 -0
  355. package/starter/app/app.vue +12 -0
  356. package/starter/app/assets/css/main.css +15 -0
  357. package/starter/app/components/global/BlockContact.vue +15 -0
  358. package/starter/app/components/global/BlockCta.vue +15 -0
  359. package/starter/app/components/global/BlockHero.vue +23 -0
  360. package/starter/app/components/global/BlockImage.vue +13 -0
  361. package/starter/app/components/global/BlockText.vue +12 -0
  362. package/starter/app/composables/useSite.ts +77 -0
  363. package/starter/app/error.vue +28 -0
  364. package/starter/app/layouts/default.vue +106 -0
  365. package/starter/app/lib/cms-content.ts +152 -0
  366. package/starter/app/pages/[...slug].vue +66 -0
  367. package/starter/app/pages/hledat.vue +59 -0
  368. package/starter/app/pages/index.vue +20 -0
  369. package/starter/cms.config.ts +137 -0
  370. package/starter/compose.yaml +15 -0
  371. package/starter/drizzle.config.ts +8 -0
  372. package/starter/gitignore.txt +8 -0
  373. package/starter/nuxt.config.ts +13 -0
  374. package/starter/package.json +38 -0
  375. package/starter/scripts/typecheck.mjs +38 -0
  376. package/starter/seed/index.ts +297 -0
  377. package/starter/seed/media/about.jpg +0 -0
  378. package/starter/seed/media/hero.jpg +0 -0
  379. package/starter/seed/media/logo.png +0 -0
  380. package/starter/seed/media/news-bread.jpg +0 -0
  381. package/starter/seed/media/news-morning.jpg +0 -0
  382. package/starter/server/db/migrations/0000_init.sql +269 -0
  383. package/starter/server/db/migrations/0001_page_tree.sql +5 -0
  384. package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
  385. package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
  386. package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
  387. package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
  388. package/starter/server/db/migrations/meta/_journal.json +27 -0
  389. package/starter/server/db/schema.ts +253 -0
  390. package/starter/server/plugins/sitemap.ts +11 -0
  391. package/starter/server/routes/robots.txt.get.ts +12 -0
  392. package/starter/tsconfig.json +9 -0
@@ -0,0 +1,53 @@
1
+ <script setup lang="ts">
2
+ // A group: a named object of fields (an address, a contact) kept together. Shown as a
3
+ // fieldset — the group's own label sits above it (CmsField), its fields inside, each
4
+ // with its own label, help and error. An optional group left untouched stays empty
5
+ // (null), so a form with an unused address does not store one.
6
+ // `id` is the control id CmsField makes for the field (its label is `${id}-label`).
7
+ const props = defineProps<{ field: any; entity: string; id?: string }>()
8
+ // Text inside a group is edited on its own (not shared), even on a shared entry.
9
+ provide('cmsCollab', null)
10
+ const model = defineModel<Record<string, any> | null>()
11
+ const form = inject<{ issues?: Record<string, string> } | null>('cmsForm', null)
12
+
13
+ const inner = computed<any[]>(() => props.field.meta?.fields ?? [])
14
+ const value = computed<Record<string, any>>(() => (model.value && typeof model.value === 'object' ? model.value : {}))
15
+
16
+ /** A group inside this one (or a list) is addressed by its full path, so errors and ids find it. */
17
+ const nested = (f: any) => (f.type === 'blocks' || f.type === 'group' ? { ...f, key: `${props.field.key}.${f.key}` } : f)
18
+
19
+ /** Nothing typed in a value: empty text, an empty list, a rich-text document with no content, a switch that is off. */
20
+ function blank(v: unknown): boolean {
21
+ if (v === null || v === undefined || v === '' || v === false) return true
22
+ if (Array.isArray(v)) return v.length === 0
23
+ if (typeof v === 'object') {
24
+ const o = v as Record<string, any>
25
+ if (o.type === 'doc') return !JSON.stringify(o.content ?? []).includes('"text"') && !JSON.stringify(o.content ?? []).includes('"image"')
26
+ return Object.values(o).every(blank)
27
+ }
28
+ return false
29
+ }
30
+
31
+ /** Inner controls get ids under the group's own, so two groups never share one. */
32
+ const innerPrefix = computed(() => `${(props.id ?? `cms-field-${props.field.key}`).replace(/^cms-field-/, '')}-`)
33
+
34
+ function set(key: string, v: unknown) {
35
+ const next = { ...value.value, [key]: v }
36
+ model.value = props.field.optional && Object.values(next).every(blank) ? null : next
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <fieldset
42
+ class="min-w-0 space-y-5 rounded-(--ui-radius) border border-default px-4 py-4"
43
+ :aria-labelledby="id ? `${id}-label` : undefined"
44
+ data-cms-group
45
+ >
46
+ <CmsField
47
+ v-for="f in inner" :key="f.key"
48
+ :model-value="value[f.key]" :field="nested(f)" :entity="entity" :id-prefix="innerPrefix"
49
+ :error="form?.issues?.[`${field.key}.${f.key}`]"
50
+ @update:model-value="(v: unknown) => set(f.key, v)"
51
+ />
52
+ </fieldset>
53
+ </template>
@@ -0,0 +1,219 @@
1
+ <script setup lang="ts">
2
+ import type { Ref } from 'vue'
3
+ // Media upload widget. `model` is the cms_media id (the FK value the form saves).
4
+ // `variant="cover"`: the entry's main picture at the top of the writing column, wide,
5
+ // with "Change photo" on it.
6
+ const props = defineProps<{ field: any; entity?: string; variant?: 'cover' }>()
7
+ const model = defineModel<string | null>()
8
+ const toast = useToast()
9
+ const { t } = useCmsI18n()
10
+
11
+ const media = ref<any>(null)
12
+ const triedId = ref<string | null>(null)
13
+ const uploading = ref(false)
14
+ const errorMsg = ref('')
15
+ const input = ref<HTMLInputElement | null>(null)
16
+ const libraryOpen = ref(false)
17
+
18
+ // Resolve the current id -> media record (so the preview survives a page load).
19
+ async function resolveMedia(id: string | null | undefined) {
20
+ if (!id) {
21
+ media.value = null
22
+ return
23
+ }
24
+ if (media.value?.id === id) return
25
+ try {
26
+ media.value = await cmsFetch(`/api/cms/_media/${id}`)
27
+ } catch {
28
+ media.value = null
29
+ } finally {
30
+ triedId.value = id
31
+ }
32
+ }
33
+ watch(model, resolveMedia, { immediate: true })
34
+ // A chosen file whose details have not arrived yet: a placeholder, not "add a photo".
35
+ const resolving = computed(() => !!model.value && media.value?.id !== model.value && triedId.value !== model.value && !uploading.value)
36
+
37
+ const isImage = computed(() => cmsMediaKind(media.value) === 'image')
38
+ const isPlayable = computed(() => ['video', 'audio'].includes(cmsMediaKind(media.value)))
39
+ // A document (f.file): its kind and size, the way people talk about files.
40
+ const fileKind = computed(() => {
41
+ const m = String(media.value?.mime ?? '')
42
+ return m === 'application/pdf' ? 'PDF' : (m.split('/')[1] ?? m).toUpperCase()
43
+ })
44
+ const fileSize = computed(() => {
45
+ const n = Number(media.value?.size ?? 0)
46
+ return n >= 1024 * 1024 ? `${(n / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} kB`
47
+ })
48
+ const isFileField = computed(() => !!props.field?.meta?.file)
49
+ // Large preview in the content column, compact in the properties panel.
50
+ const placement = inject<Ref<'main' | 'sidebar'>>('cmsFieldPlacement', ref('main'))
51
+ const compact = computed(() => placement.value === 'sidebar')
52
+
53
+ // Alt text — edit + persist on the media record (accessibility / SEO).
54
+ const alt = ref('')
55
+ watch(media, (m) => { alt.value = m?.alt ?? '' })
56
+ async function saveAlt() {
57
+ if (!media.value) return
58
+ const next = alt.value.trim()
59
+ if (next === (media.value.alt ?? '')) return
60
+ try {
61
+ const url: string = `/api/cms/_media/${media.value.id}`
62
+ const rec: any = await $fetch(url, { method: 'PATCH', body: { alt: next } })
63
+ media.value = rec
64
+ } catch (err: any) {
65
+ toast.add({ title: t('media.altSaveFailed'), description: cmsRequestError(err, t as any), color: 'error', icon: 'i-lucide-x' })
66
+ }
67
+ }
68
+
69
+ function pick() {
70
+ input.value?.click()
71
+ }
72
+
73
+ async function onChange(e: Event) {
74
+ const file = (e.target as HTMLInputElement).files?.[0]
75
+ if (!file) return
76
+ uploading.value = true
77
+ errorMsg.value = ''
78
+ try {
79
+ const fd = new FormData()
80
+ fd.append('file', file)
81
+ const rec: any = await $fetch('/api/cms/_media', { method: 'POST', body: fd })
82
+ media.value = rec
83
+ model.value = rec.id
84
+ } catch (err: any) {
85
+ errorMsg.value = cmsRequestError(err, t as any)
86
+ } finally {
87
+ uploading.value = false
88
+ if (input.value) input.value.value = ''
89
+ }
90
+ }
91
+
92
+ function onLibrarySelect(rec: any) {
93
+ media.value = rec
94
+ model.value = rec.id
95
+ }
96
+
97
+ function clear() {
98
+ model.value = null
99
+ media.value = null
100
+ }
101
+ </script>
102
+
103
+ <template>
104
+ <div v-if="variant === 'cover'" class="w-full">
105
+ <input ref="input" type="file" class="hidden" :accept="field.meta?.accept" @change="onChange">
106
+ <CmsMediaLibrary v-model:open="libraryOpen" :accept="field.meta?.accept" @select="onLibrarySelect" />
107
+ <template v-if="media">
108
+ <div class="relative overflow-hidden rounded-xl bg-muted aspect-[2.4/1]">
109
+ <img
110
+ v-if="isImage" :src="media.url" :alt="media.alt ?? ''"
111
+ :width="media.width || undefined" :height="media.height || undefined"
112
+ decoding="async" class="block size-full object-cover"
113
+ >
114
+ <UDropdownMenu
115
+ :items="[[
116
+ { label: t('media.replace'), icon: 'i-lucide-upload', onSelect: pick },
117
+ { label: t('media.browse'), icon: 'i-lucide-images', onSelect: () => { libraryOpen = true } },
118
+ ], [
119
+ { label: t('media.remove'), icon: 'i-lucide-x', color: 'error' as const, onSelect: clear },
120
+ ]]"
121
+ :content="{ align: 'end' }"
122
+ >
123
+ <UButton
124
+ size="sm" color="neutral" variant="outline" icon="i-lucide-image" :loading="uploading"
125
+ class="absolute right-3 bottom-3 bg-default/95 shadow-sm"
126
+ >{{ t('media.changeCover') }}</UButton>
127
+ </UDropdownMenu>
128
+ </div>
129
+ <UInput
130
+ v-if="isImage" v-model="alt" variant="ghost" size="sm" class="mt-1 w-full" :aria-label="t('media.altLabel')"
131
+ :placeholder="t('media.altPlaceholder')" :ui="{ base: 'px-0 text-muted' }" @blur="saveAlt" @keydown.enter.prevent="saveAlt"
132
+ />
133
+ </template>
134
+ <USkeleton v-else-if="resolving" class="w-full aspect-[2.4/1] rounded-xl" />
135
+ <div v-else class="flex flex-col items-start gap-1.5">
136
+ <button
137
+ type="button"
138
+ class="w-full aspect-[4/1] rounded-xl border border-dashed border-accented flex items-center justify-center gap-2 text-sm text-muted transition-colors hover:border-(--ui-text-dimmed) hover:text-default disabled:opacity-60"
139
+ :disabled="uploading" @click="pick"
140
+ >
141
+ <UIcon :name="uploading ? 'i-lucide-loader-circle' : 'i-lucide-image-plus'" :class="['size-4', uploading && 'animate-spin']" />
142
+ {{ uploading ? t('media.uploading') : t('media.addCover') }}
143
+ </button>
144
+ <button type="button" class="text-xs text-muted hover:text-highlighted underline-offset-2 hover:underline" @click="libraryOpen = true">
145
+ {{ t('media.browse') }}
146
+ </button>
147
+ </div>
148
+ <p v-if="errorMsg" class="mt-1 text-sm text-error">{{ errorMsg }}</p>
149
+ </div>
150
+
151
+ <div v-else class="w-full">
152
+ <input ref="input" type="file" class="hidden" :accept="field.meta?.accept" @change="onChange">
153
+ <CmsMediaLibrary v-model:open="libraryOpen" :accept="field.meta?.accept" @select="onLibrarySelect" />
154
+
155
+ <!-- has media → the picture itself, its description, and two quiet actions -->
156
+ <div v-if="media" class="space-y-2">
157
+ <div
158
+ class="group relative overflow-hidden rounded-(--ui-radius) border border-default bg-muted"
159
+ :class="!isImage ? '' : compact ? 'aspect-[1.91/1]' : 'max-h-56'"
160
+ >
161
+ <img
162
+ v-if="isImage" :src="media.url" :alt="media.alt ?? ''"
163
+ :width="media.width || undefined" :height="media.height || undefined"
164
+ loading="lazy" decoding="async" class="block size-full object-cover"
165
+ :class="compact ? '' : 'max-h-56 object-contain mx-auto'"
166
+ >
167
+ <!-- a video or a sound plays right here -->
168
+ <CmsMediaPreview v-else-if="isPlayable" :media="media" />
169
+ <a v-else :href="media.url" target="_blank" rel="noopener" class="flex items-center gap-3 p-3 hover:bg-elevated/60">
170
+ <span class="grid size-9 shrink-0 place-items-center rounded-md bg-default border border-default">
171
+ <UIcon :name="cmsMediaIcon(media)" class="size-5 text-muted" />
172
+ </span>
173
+ <span class="min-w-0">
174
+ <span class="block truncate text-sm font-medium text-highlighted">{{ media.name || media.key?.split('/').pop() }}</span>
175
+ <span class="block text-xs text-muted">{{ fileKind }} · {{ fileSize }}</span>
176
+ </span>
177
+ <UIcon name="i-lucide-arrow-up-right" class="ml-auto size-4 shrink-0 text-dimmed" />
178
+ </a>
179
+ </div>
180
+ <div class="flex items-center gap-1">
181
+ <UInput
182
+ v-if="isImage" v-model="alt" size="sm" class="flex-1 min-w-0" :aria-label="t('media.altLabel')"
183
+ :placeholder="t('media.altPlaceholder')" @blur="saveAlt" @keydown.enter.prevent="saveAlt"
184
+ />
185
+ <span v-else class="flex-1" />
186
+ <UDropdownMenu
187
+ :items="[[
188
+ { label: t('media.replace'), icon: 'i-lucide-upload', onSelect: pick },
189
+ { label: t('media.browse'), icon: 'i-lucide-images', onSelect: () => { libraryOpen = true } },
190
+ ], [
191
+ { label: t('media.remove'), icon: 'i-lucide-x', color: 'error' as const, onSelect: clear },
192
+ ]]"
193
+ :content="{ align: 'end' }"
194
+ >
195
+ <UButton size="sm" variant="ghost" color="neutral" icon="i-lucide-ellipsis" :loading="uploading" :aria-label="t('media.actions')" />
196
+ </UDropdownMenu>
197
+ </div>
198
+ </div>
199
+
200
+ <!-- empty → one quiet drop target; the library is a link -->
201
+ <USkeleton v-else-if="resolving" class="w-full rounded-(--ui-radius)" :class="compact ? 'aspect-[1.91/1]' : 'h-40'" />
202
+ <div v-else class="space-y-1.5">
203
+ <button
204
+ type="button"
205
+ class="w-full rounded-(--ui-radius) border border-dashed border-accented flex items-center justify-center gap-2 text-sm text-muted transition-colors hover:border-(--ui-text-dimmed) hover:text-default disabled:opacity-60"
206
+ :class="compact ? 'py-4' : 'py-8'"
207
+ :disabled="uploading" @click="pick"
208
+ >
209
+ <UIcon :name="uploading ? 'i-lucide-loader-circle' : isFileField ? 'i-lucide-file-up' : 'i-lucide-image-plus'" :class="['size-4', uploading && 'animate-spin']" />
210
+ {{ uploading ? t('media.uploading') : isFileField ? t('media.uploadFile') : t('media.clickToUpload') }}
211
+ </button>
212
+ <button type="button" class="text-xs text-muted hover:text-highlighted underline-offset-2 hover:underline" @click="libraryOpen = true">
213
+ {{ t('media.browse') }}
214
+ </button>
215
+ </div>
216
+
217
+ <p v-if="errorMsg" class="mt-1 text-sm text-error">{{ errorMsg }}</p>
218
+ </div>
219
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ const props = defineProps<{ field: any; entity?: string }>()
3
+ const model = defineModel<any>()
4
+ const icon = computed(() => cmsFieldIcon(props.field))
5
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
6
+ const variant = computed(() => injected?.value ?? 'outline')
7
+ </script>
8
+
9
+ <template>
10
+ <UInput v-model.number="model" type="number" :icon="icon" :variant="variant" class="w-full" />
11
+ </template>
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts">
2
+ // Several related items (tags, authors): the chosen ones as chips that wrap, so all
3
+ // of them stay readable in a narrow panel, and a menu to add more.
4
+ const { t, fieldLabel } = useCmsI18n()
5
+ const props = defineProps<{ field: any; entity?: string; id?: string }>()
6
+ const model = defineModel<any>()
7
+
8
+ const options = ref<{ id: string; label: string }[]>([])
9
+ const loading = ref(false)
10
+ const ready = ref(false)
11
+ const known = reactive(new Map<string, string>())
12
+ async function load(q = '') {
13
+ loading.value = true
14
+ try {
15
+ options.value = await cmsFetch<{ id: string; label: string }[]>(`/api/cms/${props.field.relation.to}/options`, {
16
+ query: { q, selected: Array.isArray(model.value) ? model.value.join(',') : '' },
17
+ })
18
+ for (const o of options.value) known.set(o.id, o.label)
19
+ } finally {
20
+ loading.value = false
21
+ ready.value = true
22
+ }
23
+ }
24
+ onMounted(() => load())
25
+ const ids = computed<string[]>(() => (Array.isArray(model.value) ? model.value : []))
26
+ watch(ids, (v) => { if (v.some((id) => !known.has(id))) load() })
27
+ function remove(id: string) {
28
+ model.value = ids.value.filter((x) => x !== id)
29
+ }
30
+ const icon = computed(() => cmsFieldIcon(props.field))
31
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
32
+ const variant = computed(() => injected?.value ?? 'outline')
33
+ </script>
34
+
35
+ <template>
36
+ <div class="w-full space-y-1.5">
37
+ <USkeleton v-if="ids.length && !ready" class="h-6 w-2/3 rounded-md" />
38
+ <ul v-else-if="ids.length" class="flex flex-wrap gap-1.5" :aria-label="t('fields.chosen')">
39
+ <li v-for="cid in ids" :key="cid" class="inline-flex max-w-full items-center gap-1 rounded-md bg-elevated py-0.5 pl-2 pr-0.5 text-sm text-highlighted">
40
+ <span class="truncate">{{ known.get(cid) ?? '…' }}</span>
41
+ <UButton
42
+ size="xs" color="neutral" variant="link" icon="i-lucide-x" class="p-0.5"
43
+ :aria-label="t('fields.removeItem', { name: known.get(cid) ?? '' })" @click="remove(cid)"
44
+ />
45
+ </li>
46
+ </ul>
47
+ <USelectMenu
48
+ :id="id" v-model="model" multiple :items="options" value-key="id" :loading="loading" :icon="icon ?? 'i-lucide-plus'"
49
+ :variant="variant" :aria-label="fieldLabel(field)" class="w-full" @update:open="(o: boolean) => o && load()"
50
+ >
51
+ <span class="truncate text-muted">{{ ids.length ? t('fields.addMore') : t('common.select') }}</span>
52
+ </USelectMenu>
53
+ </div>
54
+ </template>
@@ -0,0 +1,47 @@
1
+ <script setup lang="ts">
2
+ const { t, fieldLabel } = useCmsI18n()
3
+ const props = defineProps<{ field: any; entity?: string; id?: string }>()
4
+ const model = defineModel<any>()
5
+
6
+ // A page's parent picker (a relation to its own collection) leaves out the page itself and
7
+ // everything below it (choosing one of those would make a loop), and pages with no room
8
+ // left under them (the server knows how deep pages may go).
9
+ const route = useRoute()
10
+ const ownCollection = computed(() => !!props.entity && props.entity === props.field.relation.to && route.params.entity === props.entity)
11
+ const selfId = computed(() => (ownCollection.value && typeof route.params.id === 'string' && route.params.id !== 'new' ? route.params.id : ''))
12
+ const options = ref<{ id: string; label: string }[]>([])
13
+ const loading = ref(false)
14
+ // Until the names arrive, a chosen item shows as a placeholder bar, never its raw id.
15
+ const ready = ref(false)
16
+ async function load(q = '') {
17
+ loading.value = true
18
+ try {
19
+ options.value = await cmsFetch(`/api/cms/${props.field.relation.to}/options`, {
20
+ query: { q, selected: model.value ?? '', exclude: selfId.value || undefined, placing: ownCollection.value && !selfId.value ? '1' : undefined },
21
+ })
22
+ } finally {
23
+ loading.value = false
24
+ ready.value = true
25
+ }
26
+ }
27
+ onMounted(() => load())
28
+ // A value loaded later (a newer version, a restored one) needs its name too.
29
+ watch(model, (v) => { if (v && !options.value.some((o) => o.id === v)) load() })
30
+ const icon = computed(() => cmsFieldIcon(props.field))
31
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
32
+ const variant = computed(() => injected?.value ?? 'outline')
33
+ </script>
34
+
35
+ <template>
36
+ <div class="flex items-center gap-2">
37
+ <USkeleton v-if="model && !ready" class="h-8 w-full rounded-md" />
38
+ <USelectMenu v-else
39
+ :id="id" v-model="model" :variant="variant" :items="options" value-key="id" :loading="loading" :icon="icon"
40
+ :placeholder="variant === 'ghost' ? t('fields.notSet') : t('common.select')" :aria-label="fieldLabel(field)" class="w-full min-w-0" @update:open="(o: boolean) => o && load()"
41
+ />
42
+ <UButton
43
+ v-if="model && field.optional" color="neutral" variant="ghost" icon="i-lucide-x" :aria-label="t('fields.clear')"
44
+ @click="model = null"
45
+ />
46
+ </div>
47
+ </template>
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import type { CmsCollab } from '../composables/useCmsCollab'
3
+
4
+ // Built-in rich-text field. Swap it out per host by registering
5
+ // `cms.fields.richtext.edit` in app.config.
6
+ //
7
+ // When the page shares this entry (useCmsCollab) and this is one of the shared
8
+ // fields, the text is edited together, with everyone's cursors; otherwise — inside
9
+ // blocks, on a new entry, or when the shared document cannot be reached — the field
10
+ // edits on its own, as always.
11
+ defineOptions({ inheritAttrs: false })
12
+ const props = defineProps<{ field?: any }>()
13
+ const model = defineModel<any>()
14
+ const { t, fieldLabel } = useCmsI18n()
15
+ const label = computed(() => (props.field ? fieldLabel(props.field) : undefined))
16
+ // The label the field shows (CmsField), when there is one; else the field's name.
17
+ const attrs = useAttrs()
18
+ const labelledby = computed(() => (attrs['aria-labelledby'] as string | undefined))
19
+ // Everything else (the id) stays on the box; the label belongs to the textbox inside, not to the wrapper.
20
+ const rest = computed(() => { const { 'aria-labelledby': _l, ...r } = attrs; return r })
21
+ const collab = inject<CmsCollab | null>('cmsCollab', null)
22
+
23
+ const shared = computed(() => !!collab && !!props.field?.key && collab.status.value !== 'off'
24
+ && (collab.status.value === 'connecting' || collab.fields.value.has(props.field.key)))
25
+ const ready = computed(() => shared.value && collab!.status.value === 'ready')
26
+ const current = computed(() => {
27
+ if (!ready.value) return null
28
+ void collab!.generation.value // a restarted document is a new one
29
+ const live = collab!.current()
30
+ return live ? { doc: live.doc, provider: live.provider, field: props.field.key, user: collab!.user, readOnly: collab!.readOnly.value } : null
31
+ })
32
+ </script>
33
+
34
+ <template>
35
+ <CmsRichTextEditor v-if="ready && current" :key="`shared-${collab!.generation.value}`" v-model="model" :collab="current" :label="label" :labelledby="labelledby" v-bind="rest" />
36
+ <!-- while the shared text connects: the saved text, dimmed and not yet editable -->
37
+ <div v-else-if="shared" v-bind="rest" class="w-full rounded-lg border border-default bg-default" aria-busy="true">
38
+ <div class="flex h-9 items-center gap-2 border-b border-default bg-elevated/30 px-3 text-xs text-muted">
39
+ <UIcon name="i-lucide-loader-circle" class="size-3.5 animate-spin" />{{ t('live.connecting') }}
40
+ </div>
41
+ <CmsContent v-if="model" :doc="model" class="cms-prose min-h-32 px-4 py-3 opacity-60" />
42
+ <div v-else class="min-h-32" />
43
+ </div>
44
+ <CmsRichTextEditor v-else key="alone" v-model="model" :label="label" :labelledby="labelledby" v-bind="rest" />
45
+ </template>
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ // A choice. A few options in the content column are buttons (with the developer's
3
+ // icons, see `f.select({ icons })`), so every option is visible at once; elsewhere
4
+ // and for longer lists, a dropdown.
5
+ const props = defineProps<{ field: any; entity?: string; id?: string }>()
6
+ const model = defineModel<any>()
7
+ const { t, tl } = useCmsI18n()
8
+ const placement = inject<Ref<'main' | 'sidebar'> | null>('cmsFieldPlacement', null)
9
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
10
+ const variant = computed(() => injected?.value ?? 'outline')
11
+ const asButtons = computed(() => cmsSelectAsButtons(props.field, placement?.value ?? 'main'))
12
+ const items = computed(() => (props.field.meta.options as string[]).map((value) => ({
13
+ value,
14
+ label: tl(props.field.meta.labels?.[value], value),
15
+ symbol: props.field.meta.icons?.[value] as string | undefined,
16
+ })))
17
+ // An optional choice can be left empty again ("None" stands for no value).
18
+ const NONE = '\u0000none'
19
+ const choices = computed(() => (props.field.optional ? [...items.value, { value: NONE, label: t('fields.noChoice'), symbol: undefined }] : items.value))
20
+ const choice = computed({
21
+ get: () => model.value ?? NONE,
22
+ set: (v: string) => { model.value = v === NONE ? null : v },
23
+ })
24
+ const menuItems = computed(() => items.value.map((i) => ({ ...i, icon: i.symbol })))
25
+ const current = computed(() => items.value.find((i) => i.value === model.value))
26
+ </script>
27
+
28
+ <template>
29
+ <URadioGroup
30
+ v-if="asButtons" :id="id" v-model="choice" :items="choices" orientation="horizontal" variant="card" indicator="hidden"
31
+ :ui="{ fieldset: 'flex-wrap gap-2', item: 'py-2 px-3 rounded-(--ui-radius) has-data-[state=checked]:ring-1 has-data-[state=checked]:ring-inset has-data-[state=checked]:ring-(--ui-primary)', label: 'flex items-center gap-2 font-normal has-data-[state=checked]:font-medium' }"
32
+ >
33
+ <template #label="{ item }">
34
+ <span class="inline-flex items-center gap-2 text-sm">
35
+ <UIcon v-if="(item as any).symbol" :name="(item as any).symbol" class="size-4 shrink-0 text-muted" />
36
+ {{ (item as any).label }}
37
+ </span>
38
+ </template>
39
+ </URadioGroup>
40
+ <USelect v-else :id="id" v-model="model" :items="menuItems" :variant="variant" :icon="current?.symbol" class="w-full" />
41
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup lang="ts">
2
+ const { t } = useCmsI18n()
3
+ // Slug field. Auto-derives from its source field (`from`, set in cms.config) until
4
+ // the editor types in it manually — and never clobbers a slug that already exists
5
+ // on a record being edited.
6
+ const props = defineProps<{ field: any; entity?: string }>()
7
+ const model = defineModel<any>()
8
+
9
+ const form = inject<{ state: Record<string, any>, isNew: { value: boolean } } | null>('cmsForm', null)
10
+ const from = props.field.meta?.from as string | undefined
11
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
12
+ const variant = computed(() => injected?.value ?? 'outline')
13
+
14
+ function slugify(s: unknown): string {
15
+ return String(s ?? '')
16
+ .normalize('NFKD').replace(/[̀-ͯ]/g, '') // strip diacritics
17
+ .toLowerCase().trim()
18
+ .replace(/[^a-z0-9]+/g, '-')
19
+ .replace(/^-+|-+$/g, '')
20
+ }
21
+
22
+ const touched = ref(false)
23
+ let lastAuto: string | undefined
24
+
25
+ if (form && from) {
26
+ watch(() => form.state[from], (val) => {
27
+ if (touched.value) return
28
+ // Fill only an empty slug or one we filled ourselves: a saved slug (an existing
29
+ // entry, a saved translation) is kept. A new translation of an existing entry
30
+ // starts empty, so it auto-fills like a new entry does.
31
+ if (model.value && model.value !== lastAuto) return
32
+ lastAuto = slugify(val)
33
+ model.value = lastAuto
34
+ })
35
+ // Any value the user (not our auto-fill) puts in disables further auto-generation.
36
+ watch(model, (val) => { if (val && val !== lastAuto) touched.value = true })
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <!-- an address can be long: it wraps instead of being cut off -->
42
+ <UTextarea
43
+ v-model="model" :variant="variant" :placeholder="t('fields.slugPlaceholder')" class="w-full" :rows="1" autoresize :maxrows="5"
44
+ :ui="{ base: 'font-mono text-[0.8125rem] resize-none [overflow-wrap:anywhere]' }" @keydown.enter.prevent
45
+ />
46
+ </template>
@@ -0,0 +1,75 @@
1
+ <script setup lang="ts">
2
+ import { isLinkRef } from '../../src/linkref'
3
+ // A line (or box) of text. Links, e-mails and the developer's `.icon()` show an
4
+ // icon inside the box; a filled-in link can be opened from the box. A link picked
5
+ // from the site's pages is stored as a reference to the page (it follows the page when
6
+ // its address changes): the box then names the page and its address, and warns when
7
+ // visitors will not get there.
8
+ const props = defineProps<{ field: any; entity?: string; id?: string }>()
9
+ const model = defineModel<any>()
10
+ const { t } = useCmsI18n()
11
+ const multiline = computed(() => !!props.field?.meta?.multiline)
12
+ const max = computed<number | undefined>(() => props.field?.meta?.max)
13
+ const icon = computed(() => cmsFieldIcon(props.field))
14
+ const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
15
+ const variant = computed(() => injected?.value ?? 'outline')
16
+ const href = computed(() => {
17
+ const v = typeof model.value === 'string' ? model.value.trim() : ''
18
+ const format = props.field?.meta?.format
19
+ if (!v || (format !== 'url' && format !== 'link')) return null
20
+ return /^(https?:\/\/|\/)/.test(v) ? v : null
21
+ })
22
+ // Link and path fields pick a page of the site instead of typing its address.
23
+ const pickable = computed(() => props.field?.meta?.format === 'link' || props.field?.meta?.format === 'path')
24
+ const pickerOpen = ref(false)
25
+ function onPick(h: string) {
26
+ model.value = h
27
+ pickerOpen.value = false
28
+ }
29
+ // Pages are picked as references in link fields; an address field (`format: 'path'`) keeps the address.
30
+ const asRefs = computed(() => props.field?.meta?.format === 'link')
31
+ const pickedRef = computed(() => (asRefs.value && typeof model.value === 'string' && isLinkRef(model.value) ? model.value : null))
32
+ </script>
33
+
34
+ <template>
35
+ <div class="w-full">
36
+ <UTextarea v-if="multiline" :id="id" v-model="model" :variant="variant" class="w-full" autoresize :rows="3" :maxrows="12" :maxlength="max" />
37
+ <!-- a link to one of the site's pages: named by the page, not by its reference -->
38
+ <div
39
+ v-else-if="pickedRef" :id="id"
40
+ class="flex min-h-9 w-full items-center gap-1.5 rounded-(--ui-radius) py-1 pl-2.5 pr-1.5"
41
+ :class="variant === 'ghost' ? '' : 'border border-accented bg-default'"
42
+ :title="t('link.follows')"
43
+ >
44
+ <CmsLinkTarget :value="pickedRef" class="flex-1" />
45
+ <UPopover v-model:open="pickerOpen" :content="{ align: 'end' }">
46
+ <UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-file-search" :aria-label="t('link.edit')">
47
+ <span class="max-sm:hidden">{{ t('link.edit') }}</span>
48
+ </UButton>
49
+ <template #content>
50
+ <CmsLinkPicker :initial="null" refs @pick="onPick" />
51
+ </template>
52
+ </UPopover>
53
+ <UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-x" :aria-label="t('link.remove')" @click="model = ''" />
54
+ </div>
55
+ <UInput v-else :id="id" v-model="model" :variant="variant" :placeholder="variant === 'ghost' ? t('fields.notSet') : undefined" class="w-full" :maxlength="max" :icon="icon" :ui="href || pickable ? { trailing: 'pe-1.5' } : undefined">
56
+ <template v-if="href || pickable" #trailing>
57
+ <UPopover v-if="pickable" v-model:open="pickerOpen" :content="{ align: 'end' }">
58
+ <UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-file-search" :aria-label="t('link.choose')">
59
+ <span class="max-sm:hidden">{{ t('link.choose') }}</span>
60
+ </UButton>
61
+ <template #content>
62
+ <CmsLinkPicker :initial="null" :refs="asRefs" @pick="onPick" />
63
+ </template>
64
+ </UPopover>
65
+ <UButton
66
+ v-if="href" :to="href" target="_blank" rel="noopener" size="xs" color="neutral" variant="ghost"
67
+ trailing-icon="i-lucide-arrow-up-right" :aria-label="t('fields.openLink')"
68
+ ><span class="max-sm:hidden">{{ pickable ? '' : t('fields.open') }}</span></UButton>
69
+ </template>
70
+ </UInput>
71
+ <p v-if="max && (model?.length ?? 0) > max * 0.8" class="mt-1 text-xs text-muted tabular-nums text-right">
72
+ {{ model?.length ?? 0 }} / {{ max }}
73
+ </p>
74
+ </div>
75
+ </template>