inlaycms 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +462 -2
  3. package/assets/admin/admin.css +2 -0
  4. package/assets/admin/admin.js +1 -0
  5. package/assets/admin/editor.js +125 -0
  6. package/dist/adapters/admin/activity.d.ts +17 -0
  7. package/dist/adapters/admin/activity.js +59 -0
  8. package/dist/adapters/admin/assets.d.ts +14 -0
  9. package/dist/adapters/admin/assets.js +64 -0
  10. package/dist/adapters/admin/attention.d.ts +15 -0
  11. package/dist/adapters/admin/attention.js +34 -0
  12. package/dist/adapters/admin/context.d.ts +40 -0
  13. package/dist/adapters/admin/context.js +142 -0
  14. package/dist/adapters/admin/form/walk.d.ts +61 -0
  15. package/dist/adapters/admin/form/walk.js +565 -0
  16. package/dist/adapters/admin/pages.d.ts +38 -0
  17. package/dist/adapters/admin/pages.js +66 -0
  18. package/dist/adapters/admin/publish.d.ts +12 -0
  19. package/dist/adapters/admin/publish.js +195 -0
  20. package/dist/adapters/admin/routes.d.ts +47 -0
  21. package/dist/adapters/admin/routes.js +255 -0
  22. package/dist/adapters/admin/screens/backups.d.ts +11 -0
  23. package/dist/adapters/admin/screens/backups.js +223 -0
  24. package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
  25. package/dist/adapters/admin/screens/dashboard.js +160 -0
  26. package/dist/adapters/admin/screens/editor.d.ts +67 -0
  27. package/dist/adapters/admin/screens/editor.js +416 -0
  28. package/dist/adapters/admin/screens/history.d.ts +4 -0
  29. package/dist/adapters/admin/screens/history.js +105 -0
  30. package/dist/adapters/admin/screens/lists.d.ts +4 -0
  31. package/dist/adapters/admin/screens/lists.js +297 -0
  32. package/dist/adapters/admin/screens/media.d.ts +20 -0
  33. package/dist/adapters/admin/screens/media.js +186 -0
  34. package/dist/adapters/admin/screens/pickers.d.ts +29 -0
  35. package/dist/adapters/admin/screens/pickers.js +134 -0
  36. package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
  37. package/dist/adapters/admin/screens/preview-pane.js +74 -0
  38. package/dist/adapters/admin/screens/redirects.d.ts +4 -0
  39. package/dist/adapters/admin/screens/redirects.js +137 -0
  40. package/dist/adapters/admin/screens/releases.d.ts +7 -0
  41. package/dist/adapters/admin/screens/releases.js +287 -0
  42. package/dist/adapters/admin/screens/search.d.ts +22 -0
  43. package/dist/adapters/admin/screens/search.js +113 -0
  44. package/dist/adapters/admin/screens/security.d.ts +4 -0
  45. package/dist/adapters/admin/screens/security.js +85 -0
  46. package/dist/adapters/admin/screens/users.d.ts +4 -0
  47. package/dist/adapters/admin/screens/users.js +330 -0
  48. package/dist/adapters/admin/theme.d.ts +1 -0
  49. package/dist/adapters/admin/theme.js +1 -0
  50. package/dist/adapters/admin/translations.d.ts +16 -0
  51. package/dist/adapters/admin/translations.js +23 -0
  52. package/dist/adapters/admin/upload.d.ts +8 -0
  53. package/dist/adapters/admin/upload.js +116 -0
  54. package/dist/adapters/admin/views/data-table.d.ts +82 -0
  55. package/dist/adapters/admin/views/data-table.js +117 -0
  56. package/dist/adapters/admin/views/icons.d.ts +48 -0
  57. package/dist/adapters/admin/views/icons.js +47 -0
  58. package/dist/adapters/admin/views/layout.d.ts +51 -0
  59. package/dist/adapters/admin/views/layout.js +145 -0
  60. package/dist/adapters/admin/views/sheet.d.ts +15 -0
  61. package/dist/adapters/admin/views/sheet.js +6 -0
  62. package/dist/adapters/admin/views/status.d.ts +32 -0
  63. package/dist/adapters/admin/views/status.js +74 -0
  64. package/dist/adapters/auth/handler.d.ts +10 -0
  65. package/dist/adapters/auth/handler.js +63 -0
  66. package/dist/adapters/auth/request.d.ts +8 -0
  67. package/dist/adapters/auth/request.js +14 -0
  68. package/dist/adapters/cli/bin.d.ts +2 -0
  69. package/dist/adapters/cli/bin.js +42 -0
  70. package/dist/adapters/cli/main.d.ts +7 -0
  71. package/dist/adapters/cli/main.js +982 -0
  72. package/dist/adapters/cli/remote.d.ts +52 -0
  73. package/dist/adapters/cli/remote.js +161 -0
  74. package/dist/adapters/mcp/agent-refs.d.ts +9 -0
  75. package/dist/adapters/mcp/agent-refs.js +25 -0
  76. package/dist/adapters/mcp/documents.d.ts +15 -0
  77. package/dist/adapters/mcp/documents.js +26 -0
  78. package/dist/adapters/mcp/fetch-url.d.ts +19 -0
  79. package/dist/adapters/mcp/fetch-url.js +244 -0
  80. package/dist/adapters/mcp/request-state.d.ts +15 -0
  81. package/dist/adapters/mcp/request-state.js +38 -0
  82. package/dist/adapters/mcp/results.d.ts +20 -0
  83. package/dist/adapters/mcp/results.js +61 -0
  84. package/dist/adapters/mcp/route.d.ts +34 -0
  85. package/dist/adapters/mcp/route.js +52 -0
  86. package/dist/adapters/mcp/server.d.ts +44 -0
  87. package/dist/adapters/mcp/server.js +49 -0
  88. package/dist/adapters/mcp/tools/history.d.ts +5 -0
  89. package/dist/adapters/mcp/tools/history.js +84 -0
  90. package/dist/adapters/mcp/tools/media.d.ts +5 -0
  91. package/dist/adapters/mcp/tools/media.js +102 -0
  92. package/dist/adapters/mcp/tools/publish.d.ts +5 -0
  93. package/dist/adapters/mcp/tools/publish.js +157 -0
  94. package/dist/adapters/mcp/tools/read.d.ts +5 -0
  95. package/dist/adapters/mcp/tools/read.js +279 -0
  96. package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
  97. package/dist/adapters/mcp/tools/redirects.js +74 -0
  98. package/dist/adapters/mcp/tools/write.d.ts +5 -0
  99. package/dist/adapters/mcp/tools/write.js +304 -0
  100. package/dist/adapters/site/backup-schedule.d.ts +8 -0
  101. package/dist/adapters/site/backup-schedule.js +31 -0
  102. package/dist/adapters/site/cache.d.ts +29 -0
  103. package/dist/adapters/site/cache.js +63 -0
  104. package/dist/adapters/site/context.d.ts +29 -0
  105. package/dist/adapters/site/context.js +278 -0
  106. package/dist/adapters/site/head.d.ts +23 -0
  107. package/dist/adapters/site/head.js +44 -0
  108. package/dist/adapters/site/limiter.d.ts +17 -0
  109. package/dist/adapters/site/limiter.js +39 -0
  110. package/dist/adapters/site/lock.d.ts +30 -0
  111. package/dist/adapters/site/lock.js +143 -0
  112. package/dist/adapters/site/media-routes.d.ts +4 -0
  113. package/dist/adapters/site/media-routes.js +55 -0
  114. package/dist/adapters/site/plugin.d.ts +122 -0
  115. package/dist/adapters/site/plugin.js +436 -0
  116. package/dist/adapters/site/preview.d.ts +36 -0
  117. package/dist/adapters/site/preview.js +82 -0
  118. package/dist/adapters/site/public.d.ts +6 -0
  119. package/dist/adapters/site/public.js +87 -0
  120. package/dist/adapters/site/render.d.ts +45 -0
  121. package/dist/adapters/site/render.js +191 -0
  122. package/dist/adapters/site/routes.d.ts +17 -0
  123. package/dist/adapters/site/routes.js +125 -0
  124. package/dist/adapters/site/sitemap.d.ts +10 -0
  125. package/dist/adapters/site/sitemap.js +10 -0
  126. package/dist/adapters/web.d.ts +22 -0
  127. package/dist/adapters/web.js +75 -0
  128. package/dist/config.d.ts +21 -0
  129. package/dist/config.js +58 -0
  130. package/dist/core/agent/format.d.ts +62 -0
  131. package/dist/core/agent/format.js +211 -0
  132. package/dist/core/agent/schema.d.ts +6 -0
  133. package/dist/core/agent/schema.js +86 -0
  134. package/dist/core/archive.d.ts +12 -0
  135. package/dist/core/archive.js +72 -0
  136. package/dist/core/auth/auth.d.ts +4911 -0
  137. package/dist/core/auth/auth.js +61 -0
  138. package/dist/core/auth/roles.d.ts +10 -0
  139. package/dist/core/auth/roles.js +38 -0
  140. package/dist/core/auth/service.d.ts +118 -0
  141. package/dist/core/auth/service.js +424 -0
  142. package/dist/core/auth/upload-token.d.ts +8 -0
  143. package/dist/core/auth/upload-token.js +27 -0
  144. package/dist/core/backup/backup.d.ts +28 -0
  145. package/dist/core/backup/backup.js +126 -0
  146. package/dist/core/backup/restore.d.ts +41 -0
  147. package/dist/core/backup/restore.js +264 -0
  148. package/dist/core/backup/schedule.d.ts +12 -0
  149. package/dist/core/backup/schedule.js +29 -0
  150. package/dist/core/boot.d.ts +63 -0
  151. package/dist/core/boot.js +141 -0
  152. package/dist/core/check.d.ts +32 -0
  153. package/dist/core/check.js +111 -0
  154. package/dist/core/content/activity.d.ts +8 -0
  155. package/dist/core/content/activity.js +101 -0
  156. package/dist/core/content/delete.d.ts +5 -0
  157. package/dist/core/content/delete.js +100 -0
  158. package/dist/core/content/diff.d.ts +6 -0
  159. package/dist/core/content/diff.js +129 -0
  160. package/dist/core/content/dry-run.d.ts +24 -0
  161. package/dist/core/content/dry-run.js +69 -0
  162. package/dist/core/content/gaps.d.ts +25 -0
  163. package/dist/core/content/gaps.js +50 -0
  164. package/dist/core/content/hidden.d.ts +33 -0
  165. package/dist/core/content/hidden.js +103 -0
  166. package/dist/core/content/history.d.ts +15 -0
  167. package/dist/core/content/history.js +62 -0
  168. package/dist/core/content/patch.d.ts +40 -0
  169. package/dist/core/content/patch.js +287 -0
  170. package/dist/core/content/path.d.ts +6 -0
  171. package/dist/core/content/path.js +38 -0
  172. package/dist/core/content/publish.d.ts +26 -0
  173. package/dist/core/content/publish.js +211 -0
  174. package/dist/core/content/read.d.ts +99 -0
  175. package/dist/core/content/read.js +141 -0
  176. package/dist/core/content/reader.d.ts +37 -0
  177. package/dist/core/content/reader.js +195 -0
  178. package/dist/core/content/refs.d.ts +44 -0
  179. package/dist/core/content/refs.js +161 -0
  180. package/dist/core/content/release-migrations.d.ts +12 -0
  181. package/dist/core/content/release-migrations.js +154 -0
  182. package/dist/core/content/save.d.ts +25 -0
  183. package/dist/core/content/save.js +87 -0
  184. package/dist/core/content/schema.d.ts +22 -0
  185. package/dist/core/content/schema.js +127 -0
  186. package/dist/core/content/search.d.ts +8 -0
  187. package/dist/core/content/search.js +89 -0
  188. package/dist/core/content/shipped-input.d.ts +39 -0
  189. package/dist/core/content/shipped-input.js +221 -0
  190. package/dist/core/content/shipped.d.ts +112 -0
  191. package/dist/core/content/shipped.js +437 -0
  192. package/dist/core/content/slug.d.ts +23 -0
  193. package/dist/core/content/slug.js +182 -0
  194. package/dist/core/content/stats.d.ts +11 -0
  195. package/dist/core/content/stats.js +30 -0
  196. package/dist/core/content/translate.d.ts +3 -0
  197. package/dist/core/content/translate.js +68 -0
  198. package/dist/core/content/usages.d.ts +13 -0
  199. package/dist/core/content/usages.js +70 -0
  200. package/dist/core/content/validate.d.ts +21 -0
  201. package/dist/core/content/validate.js +124 -0
  202. package/dist/core/content/write.d.ts +10 -0
  203. package/dist/core/content/write.js +93 -0
  204. package/dist/core/core.d.ts +227 -0
  205. package/dist/core/core.js +251 -0
  206. package/dist/core/db/connection.d.ts +6 -0
  207. package/dist/core/db/connection.js +12 -0
  208. package/dist/core/db/migrate.d.ts +9 -0
  209. package/dist/core/db/migrate.js +42 -0
  210. package/dist/core/db/migrations/0001_content.d.ts +2 -0
  211. package/dist/core/db/migrations/0001_content.js +69 -0
  212. package/dist/core/db/migrations/0002_media.d.ts +2 -0
  213. package/dist/core/db/migrations/0002_media.js +26 -0
  214. package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
  215. package/dist/core/db/migrations/0003_redirects.js +19 -0
  216. package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
  217. package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
  218. package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
  219. package/dist/core/db/migrations/0005_site_lock.js +10 -0
  220. package/dist/core/db/migrations/0006_releases.d.ts +3 -0
  221. package/dist/core/db/migrations/0006_releases.js +34 -0
  222. package/dist/core/db/schema.d.ts +155 -0
  223. package/dist/core/db/schema.js +1 -0
  224. package/dist/core/errors.d.ts +27 -0
  225. package/dist/core/errors.js +15 -0
  226. package/dist/core/export/export.d.ts +17 -0
  227. package/dist/core/export/export.js +185 -0
  228. package/dist/core/export/format.d.ts +241 -0
  229. package/dist/core/export/format.js +106 -0
  230. package/dist/core/export/import.d.ts +54 -0
  231. package/dist/core/export/import.js +180 -0
  232. package/dist/core/export/read.d.ts +16 -0
  233. package/dist/core/export/read.js +234 -0
  234. package/dist/core/export/replace.d.ts +17 -0
  235. package/dist/core/export/replace.js +36 -0
  236. package/dist/core/export/report.d.ts +55 -0
  237. package/dist/core/export/report.js +50 -0
  238. package/dist/core/export/schema.d.ts +8 -0
  239. package/dist/core/export/schema.js +47 -0
  240. package/dist/core/export/stage.d.ts +25 -0
  241. package/dist/core/export/stage.js +192 -0
  242. package/dist/core/fields/builtins.d.ts +70 -0
  243. package/dist/core/fields/builtins.js +335 -0
  244. package/dist/core/fields/define.d.ts +86 -0
  245. package/dist/core/fields/define.js +34 -0
  246. package/dist/core/fields/walk.d.ts +49 -0
  247. package/dist/core/fields/walk.js +270 -0
  248. package/dist/core/fields/widgets.d.ts +27 -0
  249. package/dist/core/fields/widgets.js +330 -0
  250. package/dist/core/fields/zod-internals.d.ts +29 -0
  251. package/dist/core/fields/zod-internals.js +28 -0
  252. package/dist/core/media/detect.d.ts +5 -0
  253. package/dist/core/media/detect.js +66 -0
  254. package/dist/core/media/labels.d.ts +6 -0
  255. package/dist/core/media/labels.js +17 -0
  256. package/dist/core/media/library.d.ts +45 -0
  257. package/dist/core/media/library.js +239 -0
  258. package/dist/core/media/store.d.ts +11 -0
  259. package/dist/core/media/store.js +49 -0
  260. package/dist/core/media/variants.d.ts +10 -0
  261. package/dist/core/media/variants.js +59 -0
  262. package/dist/core/messages/en.d.ts +1278 -0
  263. package/dist/core/messages/en.js +1287 -0
  264. package/dist/core/messages/index.d.ts +7 -0
  265. package/dist/core/messages/index.js +14 -0
  266. package/dist/core/preview.d.ts +16 -0
  267. package/dist/core/preview.js +42 -0
  268. package/dist/core/redirects/collapse.d.ts +68 -0
  269. package/dist/core/redirects/collapse.js +153 -0
  270. package/dist/core/redirects/csv.d.ts +15 -0
  271. package/dist/core/redirects/csv.js +68 -0
  272. package/dist/core/redirects/redirects.d.ts +58 -0
  273. package/dist/core/redirects/redirects.js +545 -0
  274. package/dist/core/registry/content.d.ts +26 -0
  275. package/dist/core/registry/content.js +9 -0
  276. package/dist/core/registry/define.d.ts +145 -0
  277. package/dist/core/registry/define.js +41 -0
  278. package/dist/core/registry/migration.d.ts +44 -0
  279. package/dist/core/registry/migration.js +4 -0
  280. package/dist/core/registry/registry.d.ts +18 -0
  281. package/dist/core/registry/registry.js +255 -0
  282. package/dist/core/registry/render.d.ts +98 -0
  283. package/dist/core/registry/render.js +1 -0
  284. package/dist/core/registry/route.d.ts +42 -0
  285. package/dist/core/registry/route.js +3 -0
  286. package/dist/core/release/bundle.d.ts +21 -0
  287. package/dist/core/release/bundle.js +252 -0
  288. package/dist/core/release/keys.d.ts +11 -0
  289. package/dist/core/release/keys.js +60 -0
  290. package/dist/core/release/manifest.d.ts +103 -0
  291. package/dist/core/release/manifest.js +138 -0
  292. package/dist/core/release/pack.d.ts +20 -0
  293. package/dist/core/release/pack.js +97 -0
  294. package/dist/core/release/pointer.d.ts +19 -0
  295. package/dist/core/release/pointer.js +53 -0
  296. package/dist/core/release/read.d.ts +59 -0
  297. package/dist/core/release/read.js +256 -0
  298. package/dist/core/report.d.ts +31 -0
  299. package/dist/core/report.js +37 -0
  300. package/dist/core/richtext/html.d.ts +15 -0
  301. package/dist/core/richtext/html.js +81 -0
  302. package/dist/core/richtext/markdown.d.ts +19 -0
  303. package/dist/core/richtext/markdown.js +951 -0
  304. package/dist/core/richtext/schema.d.ts +98 -0
  305. package/dist/core/richtext/schema.js +275 -0
  306. package/dist/core/site/live.d.ts +56 -0
  307. package/dist/core/site/live.js +145 -0
  308. package/dist/core/site/paths.d.ts +15 -0
  309. package/dist/core/site/paths.js +64 -0
  310. package/dist/core/site/resolve.d.ts +9 -0
  311. package/dist/core/site/resolve.js +202 -0
  312. package/dist/core/site/sitemap.d.ts +11 -0
  313. package/dist/core/site/sitemap.js +24 -0
  314. package/dist/core/site-lock/site-lock.d.ts +21 -0
  315. package/dist/core/site-lock/site-lock.js +65 -0
  316. package/dist/core/site-lock/token.d.ts +7 -0
  317. package/dist/core/site-lock/token.js +24 -0
  318. package/dist/core/theme.d.ts +22 -0
  319. package/dist/core/theme.js +133 -0
  320. package/dist/core/types.d.ts +253 -0
  321. package/dist/core/types.js +1 -0
  322. package/dist/core/version.d.ts +1 -0
  323. package/dist/core/version.js +5 -0
  324. package/dist/host/activate.d.ts +53 -0
  325. package/dist/host/activate.js +162 -0
  326. package/dist/host/app.d.ts +46 -0
  327. package/dist/host/app.js +129 -0
  328. package/dist/host/bin.d.ts +5 -0
  329. package/dist/host/bin.js +8 -0
  330. package/dist/host/config.d.ts +36 -0
  331. package/dist/host/config.js +152 -0
  332. package/dist/host/dev.d.ts +10 -0
  333. package/dist/host/dev.js +293 -0
  334. package/dist/host/diff.d.ts +78 -0
  335. package/dist/host/diff.js +346 -0
  336. package/dist/host/hooks.d.ts +41 -0
  337. package/dist/host/hooks.js +49 -0
  338. package/dist/host/ipc.d.ts +123 -0
  339. package/dist/host/ipc.js +61 -0
  340. package/dist/host/preview-proxy.d.ts +24 -0
  341. package/dist/host/preview-proxy.js +154 -0
  342. package/dist/host/preview-worker.d.ts +42 -0
  343. package/dist/host/preview-worker.js +242 -0
  344. package/dist/host/primary.d.ts +38 -0
  345. package/dist/host/primary.js +357 -0
  346. package/dist/host/push.d.ts +125 -0
  347. package/dist/host/push.js +420 -0
  348. package/dist/host/serve.d.ts +16 -0
  349. package/dist/host/serve.js +150 -0
  350. package/dist/host/store.d.ts +48 -0
  351. package/dist/host/store.js +109 -0
  352. package/dist/host/worker.d.ts +67 -0
  353. package/dist/host/worker.js +310 -0
  354. package/dist/index.d.ts +47 -0
  355. package/dist/index.js +32 -0
  356. package/dist/jsx/html.d.ts +16 -0
  357. package/dist/jsx/html.js +65 -0
  358. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  359. package/dist/jsx/jsx-dev-runtime.js +5 -0
  360. package/dist/jsx/jsx-runtime.d.ts +17 -0
  361. package/dist/jsx/jsx-runtime.js +41 -0
  362. package/dist/site.d.ts +17 -0
  363. package/dist/site.js +14 -0
  364. package/package.json +111 -3
@@ -0,0 +1,270 @@
1
+ import { z } from 'zod';
2
+ import { t } from '../messages/index.js';
3
+ import { defineField, fieldMeta } from './define.js';
4
+ import { defOf, innerOf, isRecord } from './zod-internals.js';
5
+ const CONTAINERS = new Set(['group', 'list']);
6
+ const metaOf = (s) => fieldMeta(s);
7
+ /**
8
+ * Meta for this node itself. A wrapper whose inner schema is a field defers to
9
+ * it (fieldMeta unwraps, and lookups may return copies, so identity can't tell).
10
+ */
11
+ export function ownMeta(s) {
12
+ const inner = innerOf(s);
13
+ if (inner && metaOf(inner))
14
+ return undefined;
15
+ return metaOf(s);
16
+ }
17
+ export const isLeaf = (meta) => meta !== undefined && !CONTAINERS.has(meta.kind);
18
+ /** Copies a def keeping its accessors (e.g. function defaults), with `overrides` as plain values. */
19
+ function withDef(def, overrides) {
20
+ const next = Object.create(Object.getPrototypeOf(def), Object.getOwnPropertyDescriptors(def));
21
+ for (const [key, value] of Object.entries(overrides)) {
22
+ Object.defineProperty(next, key, { value, enumerable: true, configurable: true, writable: true });
23
+ }
24
+ return next;
25
+ }
26
+ function rebuild(s, overrides) {
27
+ return z.clone(s, withDef(defOf(s), overrides));
28
+ }
29
+ const draftCache = new WeakMap();
30
+ function draftOf(s) {
31
+ const cached = draftCache.get(s);
32
+ if (cached)
33
+ return cached;
34
+ const out = buildDraft(s);
35
+ draftCache.set(s, out);
36
+ return out;
37
+ }
38
+ function buildDraft(s) {
39
+ const meta = ownMeta(s);
40
+ if (isLeaf(meta))
41
+ return meta.draft ?? s;
42
+ const def = defOf(s);
43
+ const inner = innerOf(s);
44
+ let out = s;
45
+ if (inner) {
46
+ out = rebuild(s, def.type === 'pipe' ? { in: draftOf(inner) } : { innerType: draftOf(inner) });
47
+ }
48
+ else if (def.type === 'object' && def.shape) {
49
+ const shape = {};
50
+ for (const [key, value] of Object.entries(def.shape)) {
51
+ const drafted = draftOf(value);
52
+ shape[key] = drafted._zod.optin === undefined ? z.optional(drafted) : drafted;
53
+ }
54
+ out = rebuild(s, { shape });
55
+ }
56
+ else if (def.type === 'array' && def.element) {
57
+ const checks = def.checks?.filter((c) => c._zod.def.check !== 'min_length');
58
+ out = rebuild(s, { element: draftOf(def.element), checks });
59
+ }
60
+ if (meta && out !== s)
61
+ defineField(out, meta);
62
+ return out;
63
+ }
64
+ /**
65
+ * The draft-level version of `schema`: object and group keys become optional,
66
+ * lists drop their minimum, leaves use `meta.draft`. Per-value checks and
67
+ * defaults stay.
68
+ */
69
+ export function toDraftSchema(schema) {
70
+ return draftOf(schema);
71
+ }
72
+ const looseCache = new WeakMap();
73
+ function looseOf(s) {
74
+ const cached = looseCache.get(s);
75
+ if (cached)
76
+ return cached;
77
+ const out = buildLoose(s);
78
+ looseCache.set(s, out);
79
+ return out;
80
+ }
81
+ function buildLoose(s) {
82
+ const meta = ownMeta(s);
83
+ if (isLeaf(meta))
84
+ return s;
85
+ const def = defOf(s);
86
+ const inner = innerOf(s);
87
+ let out = s;
88
+ if (inner) {
89
+ const loose = looseOf(inner);
90
+ if (loose !== inner)
91
+ out = rebuild(s, def.type === 'pipe' ? { in: loose } : { innerType: loose });
92
+ }
93
+ else if (def.type === 'object' && def.shape) {
94
+ const shape = {};
95
+ for (const [key, value] of Object.entries(def.shape))
96
+ shape[key] = looseOf(value);
97
+ out = rebuild(s, { shape, catchall: z.unknown() });
98
+ }
99
+ else if (def.type === 'union' && def.options) {
100
+ const options = def.options.map(looseOf);
101
+ if (options.some((o, i) => o !== def.options[i]))
102
+ out = rebuild(s, { options });
103
+ }
104
+ if (meta && out !== s)
105
+ defineField(out, meta);
106
+ return out;
107
+ }
108
+ /**
109
+ * `schema` with every object it reaches (through wrappers and unions, not
110
+ * inside leaf fields or lists) keeping unknown keys instead of stripping them.
111
+ * List items keep stripping them: the admin rebuilds them on every save.
112
+ */
113
+ export function toLooseSchema(schema) {
114
+ return looseOf(schema);
115
+ }
116
+ function refsOf(meta, value, path, out) {
117
+ const next = new Map();
118
+ for (const ref of meta.refs(value)) {
119
+ let at = path;
120
+ if (Array.isArray(value)) {
121
+ const i = value.indexOf(ref.id, next.get(ref.id) ?? 0);
122
+ if (i >= 0) {
123
+ at = [...path, i];
124
+ next.set(ref.id, i + 1);
125
+ }
126
+ }
127
+ out.set(JSON.stringify([at, ref.kind, ref.id]), { path: at, meta, ref });
128
+ }
129
+ }
130
+ function collectRefs(s, value, path, out) {
131
+ if (value === undefined || value === null)
132
+ return;
133
+ const meta = ownMeta(s);
134
+ if (meta?.refs)
135
+ refsOf(meta, value, path, out);
136
+ if (isLeaf(meta))
137
+ return;
138
+ const def = defOf(s);
139
+ const inner = innerOf(s);
140
+ if (inner) {
141
+ collectRefs(inner, value, path, out);
142
+ }
143
+ else if (def.type === 'object' && def.shape) {
144
+ if (!isRecord(value))
145
+ return;
146
+ for (const [key, child] of Object.entries(def.shape))
147
+ collectRefs(child, value[key], [...path, key], out);
148
+ }
149
+ else if (def.type === 'array' && def.element) {
150
+ if (!Array.isArray(value))
151
+ return;
152
+ value.forEach((item, i) => collectRefs(def.element, item, [...path, i], out));
153
+ }
154
+ else if (def.type === 'union' && def.options) {
155
+ for (const option of unionCandidates(def, value))
156
+ collectRefs(option, value, path, out);
157
+ }
158
+ }
159
+ /** For a discriminated union, the options whose discriminator matches; otherwise all options. */
160
+ function unionCandidates(def, value) {
161
+ const options = def.options ?? [];
162
+ const disc = def.discriminator;
163
+ if (disc === undefined || !isRecord(value))
164
+ return options;
165
+ return options.filter((option) => {
166
+ const field = defOf(option).shape?.[disc];
167
+ const values = field?._zod.values;
168
+ return values === undefined || values.has(value[disc]);
169
+ });
170
+ }
171
+ /** Every document and media reference in `value`, with the field it sits in, in document order. */
172
+ export function findRefs(schema, value) {
173
+ const out = new Map();
174
+ collectRefs(schema, value, [], out);
175
+ return [...out.values()];
176
+ }
177
+ /** Every document and media reference in `value`, deduplicated by `kind:id`. */
178
+ export function extractRefs(schema, value) {
179
+ const out = new Map();
180
+ for (const { ref } of findRefs(schema, value))
181
+ out.set(`${ref.kind}:${ref.id}`, ref);
182
+ return [...out.values()];
183
+ }
184
+ function collectValues(s, value, path, kinds, out) {
185
+ if (value === undefined)
186
+ return;
187
+ const meta = ownMeta(s);
188
+ if (meta && kinds.has(meta.kind))
189
+ out.push({ path, meta, value });
190
+ if (isLeaf(meta) || value === null)
191
+ return;
192
+ const def = defOf(s);
193
+ const inner = innerOf(s);
194
+ if (inner) {
195
+ collectValues(inner, value, path, kinds, out);
196
+ }
197
+ else if (def.type === 'object' && def.shape) {
198
+ if (!isRecord(value))
199
+ return;
200
+ for (const [key, child] of Object.entries(def.shape))
201
+ collectValues(child, value[key], [...path, key], kinds, out);
202
+ }
203
+ else if (def.type === 'array' && def.element) {
204
+ if (!Array.isArray(value))
205
+ return;
206
+ value.forEach((item, i) => collectValues(def.element, item, [...path, i], kinds, out));
207
+ }
208
+ else if (def.type === 'union' && def.options) {
209
+ const [option] = unionCandidates(def, value);
210
+ if (option)
211
+ collectValues(option, value, path, kinds, out);
212
+ }
213
+ }
214
+ /**
215
+ * The values of fields of the given `kinds` in `value`, in document order,
216
+ * descending through groups and lists. Absent (`undefined`) values are skipped.
217
+ */
218
+ export function fieldValues(schema, value, kinds) {
219
+ const out = [];
220
+ collectValues(schema, value, [], kinds, out);
221
+ return out;
222
+ }
223
+ function labelsFrom(s, path, inLeaf) {
224
+ if (path.length === 0)
225
+ return [];
226
+ const meta = ownMeta(s);
227
+ const leaf = inLeaf || isLeaf(meta);
228
+ const def = defOf(s);
229
+ const inner = innerOf(s);
230
+ if (inner)
231
+ return labelsFrom(inner, path, leaf);
232
+ if (def.type === 'union' && def.options) {
233
+ for (const option of def.options) {
234
+ const found = labelsFrom(option, path, leaf);
235
+ if (found)
236
+ return found;
237
+ }
238
+ return null;
239
+ }
240
+ const [segment, ...rest] = path;
241
+ if (def.type === 'object' && def.shape) {
242
+ if (typeof segment !== 'string' || !Object.hasOwn(def.shape, segment))
243
+ return null;
244
+ const child = def.shape[segment];
245
+ const tail = labelsFrom(child, rest, leaf);
246
+ if (!tail)
247
+ return null;
248
+ return leaf ? tail : [metaOf(child)?.label ?? segment, ...tail];
249
+ }
250
+ if (def.type === 'array' && def.element) {
251
+ if (typeof segment !== 'number' || !Number.isInteger(segment) || segment < 0)
252
+ return null;
253
+ const tail = labelsFrom(def.element, rest, leaf);
254
+ if (!tail)
255
+ return null;
256
+ if (leaf)
257
+ return tail;
258
+ const n = segment + 1;
259
+ const label = meta?.itemLabel !== undefined ? `${meta.itemLabel} ${n}` : t('label.item', { n });
260
+ return [label, ...tail];
261
+ }
262
+ return null;
263
+ }
264
+ /**
265
+ * One label per field segment of `path`, or `null` if the path isn't in the
266
+ * schema. List indexes become "Item n" (or the list's `itemLabel` and n).
267
+ */
268
+ export function labelsAt(schema, path) {
269
+ return labelsFrom(schema, path, false);
270
+ }
@@ -0,0 +1,27 @@
1
+ import type { AdminWidget } from './define.js';
2
+ export declare const textWidget: AdminWidget;
3
+ export declare const textareaWidget: AdminWidget;
4
+ export declare const numberWidget: AdminWidget;
5
+ export declare const booleanWidget: AdminWidget;
6
+ export declare const selectWidget: AdminWidget;
7
+ export declare const dateWidget: AdminWidget;
8
+ export declare const datetimeWidget: AdminWidget;
9
+ /** The fallback for fields without a widget of their own: the value as JSON. */
10
+ export declare const jsonWidget: AdminWidget;
11
+ export declare const imageWidget: AdminWidget;
12
+ export declare const fileWidget: AdminWidget;
13
+ /** A reference to one entry: its title and the picker buttons. */
14
+ export declare const refWidget: AdminWidget;
15
+ /**
16
+ * References to several entries, as a list of chips. A hidden `<name>.many` marks a stored list, so a list left
17
+ * empty stays empty and an absent one stays absent.
18
+ */
19
+ export declare const refsWidget: AdminWidget;
20
+ /** A link: a page on this site (chosen with the documents picker) or a web address, plus optional link text. */
21
+ export declare const linkWidget: AdminWidget;
22
+ /**
23
+ * Formatted text. Without JavaScript only the stored JSON is kept. Parse: the stored form of a valid doc; text
24
+ * that isn't JSON, or JSON that isn't a doc the field allows, as it is, so validation reports it; a blank doc on
25
+ * an optional field → absent, unless a hidden `<name>._present` marks a stored value, which keeps it.
26
+ */
27
+ export declare const richTextWidget: AdminWidget;
@@ -0,0 +1,330 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { isRasterImage } from '../media/detect.js';
3
+ import { missingMediaLabel } from '../media/labels.js';
4
+ import { t } from '../messages/index.js';
5
+ import { DEFAULT_RICH_TEXT, parseRichText, RICH_TEXT_FEATURES, richTextIsBlank } from '../richtext/schema.js';
6
+ import { isRecord } from './zod-internals.js';
7
+ /** The attributes every control shares. */
8
+ const control = (p) => ({
9
+ id: p.id,
10
+ name: p.name,
11
+ disabled: p.readOnly,
12
+ 'aria-invalid': p.invalid ? 'true' : undefined,
13
+ 'aria-describedby': p.describedBy,
14
+ });
15
+ /** A stored value as text for a control: strings as they are, other values written out. */
16
+ function asText(value) {
17
+ if (value === undefined || value === null)
18
+ return '';
19
+ if (typeof value === 'string')
20
+ return value;
21
+ if (typeof value === 'number' || typeof value === 'boolean')
22
+ return String(value);
23
+ return JSON.stringify(value);
24
+ }
25
+ /** Browsers drop one newline right after `<textarea>`, so a value starting with one gets an extra. */
26
+ const textareaBody = (s) => (s.startsWith('\n') ? `\n${s}` : s);
27
+ /** A submitted value with its newlines as `\n`: browsers send them as CRLF. */
28
+ function submitted(form, name) {
29
+ return form.get(name)?.replace(/\r\n?/g, '\n');
30
+ }
31
+ /** `''` → absent when optional; otherwise the raw text. */
32
+ function parseText(form, name, optional) {
33
+ const raw = submitted(form, name);
34
+ if (raw === undefined)
35
+ return undefined;
36
+ return raw === '' && optional ? undefined : raw;
37
+ }
38
+ /** `''` → absent; otherwise the raw text. */
39
+ function parseNonEmpty(form, name) {
40
+ const raw = submitted(form, name);
41
+ return raw === undefined || raw === '' ? undefined : raw;
42
+ }
43
+ /** A one-line text input, which browsers would strip of newlines, as a free text box with the stored value as it is. */
44
+ const plainInput = (p, value) => _jsx("input", { type: "text", value: value, class: "input input-bordered w-full", ...control(p) });
45
+ export const textWidget = {
46
+ render(p) {
47
+ const value = asText(p.value);
48
+ // A one-line input would drop the newlines of a stored value, so it gets a text box instead.
49
+ if (!/[\r\n]/.test(value))
50
+ return plainInput(p, value);
51
+ return (_jsx("textarea", { rows: "3", class: "textarea textarea-bordered w-full", ...control(p), children: textareaBody(value) }));
52
+ },
53
+ parse: (form, name, _meta, optional) => parseText(form, name, optional),
54
+ };
55
+ export const textareaWidget = {
56
+ render: (p) => (_jsx("textarea", { rows: "4", class: "textarea textarea-bordered w-full", ...control(p), children: textareaBody(asText(p.value)) })),
57
+ parse: (form, name, _meta, optional) => parseText(form, name, optional),
58
+ };
59
+ /** HTML's valid floating-point number: what a `type=number` input keeps; it blanks anything else. */
60
+ const VALID_FLOAT = /^-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?$/;
61
+ export const numberWidget = {
62
+ render(p) {
63
+ const value = asText(p.value);
64
+ // A value the number input would blank is shown as it is, so it is seen and saving keeps it.
65
+ if (value !== '' && !VALID_FLOAT.test(value))
66
+ return plainInput(p, value);
67
+ return _jsx("input", { type: "number", step: "any", value: value, class: "input input-bordered w-full", ...control(p) });
68
+ },
69
+ parse(form, name) {
70
+ const raw = form.get(name);
71
+ if (raw === undefined || raw.trim() === '')
72
+ return undefined;
73
+ const n = Number(raw);
74
+ return Number.isFinite(n) ? n : raw;
75
+ },
76
+ };
77
+ export const booleanWidget = {
78
+ render: (p) => _jsx("input", { type: "checkbox", value: "true", checked: p.value === true, class: "checkbox", ...control(p) }),
79
+ parse: (form, name) => form.get(name) === 'true',
80
+ };
81
+ export const selectWidget = {
82
+ render(p) {
83
+ const options = p.meta.options ?? [];
84
+ const current = typeof p.value === 'string' ? p.value : undefined;
85
+ // A value that isn't one of the options is kept as its own choice, so saving doesn't change it.
86
+ const unknown = current !== undefined && current !== '' && !options.includes(current);
87
+ return (_jsxs("select", { class: "select select-bordered w-full", ...control(p), children: [(p.optional || current === undefined) && _jsx("option", { value: "", children: t('admin.form.none') }), unknown && (_jsx("option", { value: current, selected: true, children: current })), options.map((o) => (_jsx("option", { value: o, selected: o === current, children: o })))] }));
88
+ },
89
+ parse: (form, name) => parseNonEmpty(form, name),
90
+ };
91
+ /** Whether `text` is HTML's valid date string (`YYYY-MM-DD`, a real day), which a `type=date` input keeps. */
92
+ function isDateInput(text) {
93
+ const m = /^(\d{4,})-(\d{2})-(\d{2})$/.exec(text);
94
+ if (!m)
95
+ return false;
96
+ const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
97
+ if (y < 1 || mo < 1 || mo > 12 || d < 1)
98
+ return false;
99
+ const date = new Date(0);
100
+ date.setUTCFullYear(y, mo - 1, d);
101
+ return date.getUTCMonth() === mo - 1 && date.getUTCDate() === d;
102
+ }
103
+ export const dateWidget = {
104
+ render(p) {
105
+ const value = asText(p.value);
106
+ // A value the date input would blank is shown as it is, so it is seen and saving keeps it.
107
+ if (value !== '' && !isDateInput(value))
108
+ return plainInput(p, value);
109
+ return _jsx("input", { type: "date", value: value, class: "input input-bordered w-full", ...control(p) });
110
+ },
111
+ parse: (form, name) => parseNonEmpty(form, name),
112
+ };
113
+ /** A stored datetime as a `datetime-local` value in UTC (`YYYY-MM-DDTHH:MM:SS`); anything unreadable as it is. */
114
+ function utcInput(value) {
115
+ const text = asText(value);
116
+ const ms = Date.parse(text);
117
+ return Number.isNaN(ms) ? text : new Date(ms).toISOString().slice(0, 19);
118
+ }
119
+ const LOCAL_DATETIME = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/;
120
+ /** `YYYY-MM-DDTHH:MM(:SS)?` read as UTC, written `YYYY-MM-DDTHH:MM:SSZ`; `undefined` if it isn't a real time. */
121
+ function fromUtcInput(raw) {
122
+ const m = LOCAL_DATETIME.exec(raw);
123
+ if (!m)
124
+ return undefined;
125
+ const [y = 0, mo = 0, d = 0, h = 0, mi = 0, s = 0] = m.slice(1).map((part) => Number(part ?? 0));
126
+ const date = new Date(Date.UTC(y, mo - 1, d, h, mi, s));
127
+ const real = date.getUTCFullYear() === y && date.getUTCMonth() === mo - 1 && date.getUTCDate() === d &&
128
+ date.getUTCHours() === h && date.getUTCMinutes() === mi && date.getUTCSeconds() === s;
129
+ return real ? `${raw.slice(0, 16)}:${String(s).padStart(2, '0')}Z` : undefined;
130
+ }
131
+ export const datetimeWidget = {
132
+ render(p) {
133
+ const shown = utcInput(p.value);
134
+ // A value the datetime input would blank is shown as it is, so it is seen and saving keeps it.
135
+ const readable = shown === '' || fromUtcInput(shown) !== undefined;
136
+ return (_jsxs(_Fragment, { children: [readable ? (_jsx("input", { type: "datetime-local", step: "1", value: shown, class: "input input-bordered w-full", ...control(p) })) : (plainInput(p, asText(p.value))), _jsx("input", { type: "hidden", name: `${p.name}.was`, value: asText(p.value), disabled: p.readOnly })] }));
137
+ },
138
+ parse(form, name) {
139
+ const raw = form.get(name);
140
+ if (raw === undefined)
141
+ return undefined;
142
+ const was = form.get(`${name}.was`);
143
+ if (was !== undefined && was !== '') {
144
+ // Browsers drop zero seconds from a datetime input's value, so the time is compared rather than the text.
145
+ const shown = utcInput(was);
146
+ const time = fromUtcInput(raw);
147
+ if (raw === was || raw === shown || (time !== undefined && time === fromUtcInput(shown)))
148
+ return was;
149
+ }
150
+ if (raw === '')
151
+ return undefined;
152
+ return fromUtcInput(raw) ?? raw;
153
+ },
154
+ };
155
+ /** The fallback for fields without a widget of their own: the value as JSON. */
156
+ export const jsonWidget = {
157
+ render: (p) => (_jsx("textarea", { rows: "6", class: "textarea textarea-bordered w-full font-mono text-sm", ...control(p), children: textareaBody(p.value === undefined ? '' : JSON.stringify(p.value, null, 2)) })),
158
+ parse(form, name) {
159
+ const raw = submitted(form, name);
160
+ if (raw === undefined || raw.trim() === '')
161
+ return undefined;
162
+ try {
163
+ return JSON.parse(raw);
164
+ }
165
+ catch {
166
+ return raw;
167
+ }
168
+ },
169
+ };
170
+ function shownMedia(id, refs) {
171
+ const status = refs.media(id);
172
+ if (status.status === 'present') {
173
+ const { media } = status;
174
+ return { label: media.filename, ...(isRasterImage(media.mime) && { thumb: `/media/${media.id}/320.webp` }) };
175
+ }
176
+ if (status.status === 'deleted')
177
+ return { label: missingMediaLabel(status), missing: true };
178
+ return { label: t('admin.form.missingMedia'), missing: true };
179
+ }
180
+ function shownDocument(id, refs) {
181
+ const found = refs.document(id);
182
+ return found ? { label: found.title } : { label: t('admin.form.missingEntry'), missing: true };
183
+ }
184
+ /** The chosen value's name (and thumbnail), which `applyPick` and `clearField` update. */
185
+ function Preview({ id, shown, thumbs }) {
186
+ return (_jsxs("div", { class: "flex items-center gap-3", children: [thumbs && (_jsx("img", { "data-picker-thumb": true, src: shown?.thumb, alt: "", hidden: shown?.thumb === undefined, class: "h-16 w-16 rounded-box bg-base-200 object-cover" })), _jsx("span", { id: id, "data-picker-label": true, "data-empty": t('admin.form.nothingChosen'), class: shown?.missing === true
187
+ ? 'rounded-box bg-warning px-2 text-warning-content'
188
+ : shown === undefined
189
+ ? 'text-base-content/70'
190
+ : undefined, children: shown?.label ?? t('admin.form.nothingChosen') })] }));
191
+ }
192
+ /** "Choose…" and, when the field may be left empty, "Remove". */
193
+ function PickerButtons({ p, label }) {
194
+ if (p.readOnly)
195
+ return null;
196
+ const describedBy = [`${p.id}-chosen`, p.describedBy].filter((x) => x !== undefined).join(' ');
197
+ return (_jsxs("div", { class: "flex flex-wrap gap-2", children: [_jsx("button", { type: "button", id: p.id, "data-picker-open": true, class: "btn btn-sm", "aria-describedby": describedBy, "aria-invalid": p.invalid ? 'true' : undefined, children: label }), p.optional && (_jsx("button", { type: "button", "data-picker-clear": true, class: "btn btn-ghost btn-sm", children: t('admin.form.clear') }))] }));
198
+ }
199
+ const textOf = (value) => (typeof value === 'string' && value !== '' ? value : undefined);
200
+ function mediaWidget(kind) {
201
+ return {
202
+ fieldset: true,
203
+ render(p) {
204
+ const record = isRecord(p.value) ? p.value : {};
205
+ const id = textOf(record.media);
206
+ const status = id === undefined ? undefined : p.refs.media(id);
207
+ const defaultAlt = status?.status === 'present' ? status.media.defaultAlt : null;
208
+ const altId = `${p.id}-alt`;
209
+ return (_jsxs("div", { "data-picker": `/admin/pick/media?kind=${kind}`, "data-name": p.name, class: "flex flex-col gap-2", children: [_jsx("input", { type: "hidden", name: `${p.name}.media`, value: id ?? '', "data-picker-value": true, disabled: p.readOnly }), _jsx(Preview, { id: `${p.id}-chosen`, shown: id === undefined ? undefined : shownMedia(id, p.refs), thumbs: kind === 'image' }), _jsx(PickerButtons, { p: p, label: t('admin.form.choose') }), kind === 'image' && (_jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: altId, class: "text-sm font-medium", children: t('admin.form.alt') }), _jsx("input", { type: "text", id: altId, name: `${p.name}.alt`, value: typeof record.alt === 'string' ? record.alt : '', placeholder: defaultAlt ?? undefined, disabled: p.readOnly, "aria-describedby": `${altId}-default`, class: "input input-bordered w-full" }), _jsx("p", { id: `${altId}-default`, class: "text-sm text-base-content/70", children: t('admin.form.altDefault') })] }))] }));
210
+ },
211
+ parse(form, name) {
212
+ const media = parseNonEmpty(form, `${name}.media`);
213
+ if (media === undefined)
214
+ return undefined;
215
+ if (kind === 'file')
216
+ return { media };
217
+ const alt = parseNonEmpty(form, `${name}.alt`);
218
+ return alt === undefined ? { media } : { media, alt };
219
+ },
220
+ };
221
+ }
222
+ export const imageWidget = mediaWidget('image');
223
+ export const fileWidget = mediaWidget('file');
224
+ const entriesPicker = (p) => `/admin/pick/entries?${new URLSearchParams({ collection: p.meta.target ?? '', locale: p.locale }).toString()}`;
225
+ /** A reference to one entry: its title and the picker buttons. */
226
+ export const refWidget = {
227
+ render(p) {
228
+ const id = textOf(p.value);
229
+ return (_jsxs("div", { "data-picker": entriesPicker(p), "data-name": p.name, class: "flex flex-col gap-2", children: [_jsx("input", { type: "hidden", name: p.name, value: id ?? '', "data-picker-value": true, disabled: p.readOnly }), _jsx(Preview, { id: `${p.id}-chosen`, shown: id === undefined ? undefined : shownDocument(id, p.refs), thumbs: false }), _jsx(PickerButtons, { p: p, label: t('admin.form.choose') })] }));
230
+ },
231
+ parse: (form, name) => parseNonEmpty(form, name),
232
+ };
233
+ function Chip({ name, value, label, missing, readOnly }) {
234
+ return (_jsxs("li", { class: "flex items-center gap-2 rounded-box border border-base-300 px-3 py-1", children: [_jsx("input", { type: "hidden", name: name, value: value, disabled: readOnly }), _jsx("span", { "data-chip-label": true, class: missing ? 'rounded-box bg-warning px-2 text-warning-content' : undefined, children: label }), !readOnly && (_jsx("button", { type: "button", "data-picker-remove": true, class: "btn btn-ghost btn-xs", "aria-label": t('admin.form.removeItem', { item: label }), children: t('admin.form.remove') }))] }));
235
+ }
236
+ /**
237
+ * References to several entries, as a list of chips. A hidden `<name>.many` marks a stored list, so a list left
238
+ * empty stays empty and an absent one stays absent.
239
+ */
240
+ export const refsWidget = {
241
+ fieldset: true,
242
+ render(p) {
243
+ const ids = Array.isArray(p.value) ? p.value.filter((v) => typeof v === 'string') : [];
244
+ return (_jsxs("div", { "data-picker": entriesPicker(p), "data-name": p.name, "data-many": true, class: "flex flex-col gap-2", children: [Array.isArray(p.value) && _jsx("input", { type: "hidden", name: `${p.name}.many`, value: "", disabled: p.readOnly }), _jsx("ul", { "data-picker-list": true, id: `${p.id}-chosen`, class: "flex flex-wrap gap-2", children: ids.map((id) => {
245
+ const shown = shownDocument(id, p.refs);
246
+ return _jsx(Chip, { name: p.name, value: id, label: shown.label, missing: shown.missing === true, readOnly: p.readOnly });
247
+ }) }), !p.readOnly && (_jsx("template", { "data-picker-chip": true, "data-remove-label": t('admin.form.removeItem', { item: '{item}' }), children: _jsx(Chip, { name: p.name, value: "", label: "", missing: false, readOnly: false }) })), _jsx(PickerButtons, { p: { ...p, optional: false }, label: t('admin.form.add.chosen') })] }));
248
+ },
249
+ parse(form, name) {
250
+ const ids = form.all(name).filter((id) => id !== '');
251
+ if (ids.length > 0)
252
+ return ids;
253
+ return form.get(`${name}.many`) === undefined ? undefined : [];
254
+ },
255
+ };
256
+ /** A link: a page on this site (chosen with the documents picker) or a web address, plus optional link text. */
257
+ export const linkWidget = {
258
+ fieldset: true,
259
+ render(p) {
260
+ const record = isRecord(p.value) ? p.value : {};
261
+ const document = textOf(record.document);
262
+ const url = typeof record.url === 'string' ? record.url : '';
263
+ const mode = record.url !== undefined && record.document === undefined ? 'url' : 'document';
264
+ const pageName = `${p.name}.document`;
265
+ const picker = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale }).toString()}`;
266
+ const urlId = `${p.id}-url`;
267
+ const textId = `${p.id}-text`;
268
+ const radio = (value, id, label) => (_jsxs("div", { class: "flex items-center gap-2", children: [_jsx("input", { type: "radio", id: id, name: `${p.name}.mode`, value: value, checked: mode === value, disabled: p.readOnly, "data-link-mode": value, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: "radio radio-sm" }), _jsx("label", { for: id, children: label })] }));
269
+ return (_jsxs("div", { "data-link": true, class: "flex flex-col gap-3", children: [_jsxs("div", { class: "flex flex-wrap gap-4", children: [radio('document', p.id, t('admin.form.link.page')), radio('url', `${p.id}-mode-url`, t('admin.form.link.url'))] }), _jsxs("div", { "data-picker": picker, "data-name": pageName, class: "flex flex-col gap-2", children: [_jsx("input", { type: "hidden", name: pageName, value: document ?? '', "data-picker-value": true, disabled: p.readOnly }), _jsx(Preview, { id: `${p.id}-page-chosen`, shown: document === undefined ? undefined : shownDocument(document, p.refs), thumbs: false }), _jsx(PickerButtons, { p: { ...p, id: `${p.id}-page`, optional: true, describedBy: undefined }, label: t('admin.form.choose') })] }), _jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: urlId, class: "text-sm font-medium", children: t('admin.form.link.urlLabel') }), _jsx("input", { type: "text", inputmode: "url", id: urlId, name: `${p.name}.url`, value: url, disabled: p.readOnly, "data-link-url": true, class: "input input-bordered w-full" })] }), _jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: textId, class: "text-sm font-medium", children: t('admin.form.link.text') }), _jsx("input", { type: "text", id: textId, name: `${p.name}.text`, value: typeof record.text === 'string' ? record.text : '', disabled: p.readOnly, class: "input input-bordered w-full" })] })] }));
270
+ },
271
+ parse(form, name) {
272
+ const mode = form.get(`${name}.mode`);
273
+ const text = parseNonEmpty(form, `${name}.text`);
274
+ const withText = text === undefined ? {} : { text };
275
+ if (mode === 'url') {
276
+ const url = parseNonEmpty(form, `${name}.url`);
277
+ return url === undefined ? undefined : { url, ...withText };
278
+ }
279
+ const document = parseNonEmpty(form, `${name}.document`);
280
+ return document === undefined ? undefined : { document, ...withText };
281
+ },
282
+ };
283
+ // ---------------------------------------------------------------------------
284
+ // Rich text: `client/admin/editor.ts` mounts the editor and keeps the hidden JSON up to date.
285
+ /** The toolbar's labels, by command: one per feature, and one per heading level (`heading2`, …). */
286
+ function toolbarLabels(headings) {
287
+ return {
288
+ ...Object.fromEntries(headings.map((level) => [`heading${level}`, t('admin.richtext.heading', { level })])),
289
+ bold: t('admin.richtext.bold'),
290
+ italic: t('admin.richtext.italic'),
291
+ link: t('admin.richtext.link'),
292
+ bulletList: t('admin.richtext.bulletList'),
293
+ orderedList: t('admin.richtext.orderedList'),
294
+ blockquote: t('admin.richtext.blockquote'),
295
+ image: t('admin.richtext.image'),
296
+ hardBreak: t('admin.richtext.hardBreak'),
297
+ };
298
+ }
299
+ /**
300
+ * Formatted text. Without JavaScript only the stored JSON is kept. Parse: the stored form of a valid doc; text
301
+ * that isn't JSON, or JSON that isn't a doc the field allows, as it is, so validation reports it; a blank doc on
302
+ * an optional field → absent, unless a hidden `<name>._present` marks a stored value, which keeps it.
303
+ */
304
+ export const richTextWidget = {
305
+ fieldset: true,
306
+ render(p) {
307
+ const opts = p.meta.richText ?? DEFAULT_RICH_TEXT;
308
+ const features = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature));
309
+ const value = p.value === undefined ? '' : typeof p.value === 'string' ? p.value : JSON.stringify(p.value);
310
+ const links = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale, web: '1' }).toString()}`;
311
+ return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: "min-h-40 [&_.ProseMirror]:min-h-40 [&_.ProseMirror]:p-3 [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary" }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
312
+ },
313
+ parse(form, name, meta, optional) {
314
+ const raw = form.get(name);
315
+ if (raw === undefined || raw === '')
316
+ return undefined;
317
+ let value;
318
+ try {
319
+ value = JSON.parse(raw);
320
+ }
321
+ catch {
322
+ return raw;
323
+ }
324
+ const parsed = parseRichText(value, meta.richText ?? DEFAULT_RICH_TEXT);
325
+ if (!parsed.ok)
326
+ return value;
327
+ const stored = form.get(`${name}._present`) !== undefined;
328
+ return optional && !stored && richTextIsBlank(parsed.doc) ? undefined : parsed.doc;
329
+ },
330
+ };
@@ -0,0 +1,29 @@
1
+ import type { z } from 'zod';
2
+ export type Schema = z.core.$ZodType;
3
+ interface Check {
4
+ _zod: {
5
+ def: {
6
+ check: string;
7
+ };
8
+ };
9
+ }
10
+ /** The parts of a zod def that Inlay reads. */
11
+ export interface Def {
12
+ type: string;
13
+ innerType?: Schema;
14
+ in?: Schema;
15
+ shape?: Record<string, Schema>;
16
+ element?: Schema;
17
+ options?: readonly Schema[];
18
+ discriminator?: string;
19
+ checks?: Check[];
20
+ }
21
+ /** Schema types that wrap one inner schema. A pipe wraps its `in` side. */
22
+ export declare const WRAPPERS: ReadonlySet<string>;
23
+ export declare const defOf: (s: Schema) => Def;
24
+ /** The schema `s` wraps, or `undefined` if it isn't a wrapper. */
25
+ export declare function innerOf(s: Schema): Schema | undefined;
26
+ /** `s` with every wrapper removed. */
27
+ export declare function unwrap(s: Schema): Schema;
28
+ export declare function isRecord(v: unknown): v is Record<string, unknown>;
29
+ export {};