@chobantonov/jsonforms-extended-spec 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -2
  3. package/conformance/authoring.json +2169 -0
  4. package/conformance/behavior.json +731 -0
  5. package/conformance/config-consumption.json +1531 -0
  6. package/conformance/expected-invalid.json +20 -0
  7. package/docs/audit.md +150 -0
  8. package/docs/conditional-fields.md +80 -0
  9. package/docs/draft-07-visual-support.md +43 -0
  10. package/docs/external-resources-proposal.md +536 -0
  11. package/docs/implementation-guide.md +180 -0
  12. package/docs/implementation-pitfalls.md +802 -0
  13. package/docs/implementation-web-typescript.md +41 -0
  14. package/docs/renderer-and-demo.md +1347 -0
  15. package/docs/renderer-selection.md +99 -0
  16. package/docs/spec.md +8321 -0
  17. package/docs/todo.md +149 -0
  18. package/examples/README.md +121 -0
  19. package/examples/additional-errors/README.md +169 -0
  20. package/examples/additional-errors/config.json +3 -0
  21. package/examples/additional-errors/data.json +11 -0
  22. package/examples/additional-errors/schema.json +56 -0
  23. package/examples/additional-errors/translations.json +64 -0
  24. package/examples/additional-errors/uischema.json +158 -0
  25. package/examples/additional-items-pagination/README.md +8 -0
  26. package/examples/additional-items-pagination/config.json +10 -0
  27. package/examples/additional-items-pagination/data.json +22 -0
  28. package/examples/additional-items-pagination/schema.json +30 -0
  29. package/examples/additional-items-pagination/translations.json +16 -0
  30. package/examples/additional-items-pagination/uischema.json +39 -0
  31. package/examples/additional-properties/README.md +188 -0
  32. package/examples/additional-properties/config.json +5 -0
  33. package/examples/additional-properties/data.json +31 -0
  34. package/examples/additional-properties/schema.json +78 -0
  35. package/examples/additional-properties/translations.json +80 -0
  36. package/examples/additional-properties/uischema.json +104 -0
  37. package/examples/ag-grid/README.md +62 -0
  38. package/examples/ag-grid/config.json +14 -0
  39. package/examples/ag-grid/data.json +124 -0
  40. package/examples/ag-grid/schema.json +48 -0
  41. package/examples/ag-grid/translations.json +58 -0
  42. package/examples/ag-grid/uischema.json +671 -0
  43. package/examples/array-choices/README.md +150 -0
  44. package/examples/array-choices/config.json +4 -0
  45. package/examples/array-choices/data.json +10 -0
  46. package/examples/array-choices/schema.json +68 -0
  47. package/examples/array-choices/translations.json +64 -0
  48. package/examples/array-choices/uischema.json +97 -0
  49. package/examples/array-controls/README.md +237 -0
  50. package/examples/array-controls/config.json +4 -0
  51. package/examples/array-controls/data.json +147 -0
  52. package/examples/array-controls/schema.json +374 -0
  53. package/examples/array-controls/translations.json +186 -0
  54. package/examples/array-controls/uischema.json +685 -0
  55. package/examples/array-detail-modes/README.md +11 -0
  56. package/examples/array-detail-modes/data.json +38 -0
  57. package/examples/array-detail-modes/schema.json +89 -0
  58. package/examples/array-detail-modes/translations.json +36 -0
  59. package/examples/array-detail-modes/uischema.json +73 -0
  60. package/examples/array-detail-modes/uischemas.d.mts +2 -0
  61. package/examples/array-detail-modes/uischemas.json +15 -0
  62. package/examples/boolean-controls/README.md +109 -0
  63. package/examples/boolean-controls/config.json +3 -0
  64. package/examples/boolean-controls/data.json +27 -0
  65. package/examples/boolean-controls/schema.json +98 -0
  66. package/examples/boolean-controls/translations.json +94 -0
  67. package/examples/boolean-controls/uischema.json +126 -0
  68. package/examples/button-actions/README.md +259 -0
  69. package/examples/button-actions/config.json +7 -0
  70. package/examples/button-actions/data.json +5 -0
  71. package/examples/button-actions/host.mjs +14 -0
  72. package/examples/button-actions/schema.json +20 -0
  73. package/examples/button-actions/translations.json +60 -0
  74. package/examples/button-actions/uischema.json +179 -0
  75. package/examples/catalog.json +634 -0
  76. package/examples/categorization/README.md +132 -0
  77. package/examples/categorization/config.json +7 -0
  78. package/examples/categorization/data.json +8 -0
  79. package/examples/categorization/schema.json +29 -0
  80. package/examples/categorization/translations.json +72 -0
  81. package/examples/categorization/uischema.json +288 -0
  82. package/examples/choice-controls/README.md +136 -0
  83. package/examples/choice-controls/config.json +10 -0
  84. package/examples/choice-controls/data.json +61 -0
  85. package/examples/choice-controls/schema.json +406 -0
  86. package/examples/choice-controls/translations.json +154 -0
  87. package/examples/choice-controls/uischema.json +575 -0
  88. package/examples/choice-controls/uischemas.d.mts +2 -0
  89. package/examples/choice-controls/uischemas.json +16 -0
  90. package/examples/code-editor/README.md +74 -0
  91. package/examples/code-editor/data.json +8 -0
  92. package/examples/code-editor/schema.json +28 -0
  93. package/examples/code-editor/translations.json +20 -0
  94. package/examples/code-editor/uischema.json +77 -0
  95. package/examples/collection-pagination/README.md +5 -0
  96. package/examples/collection-pagination/config.json +1 -0
  97. package/examples/collection-pagination/data.json +64 -0
  98. package/examples/collection-pagination/schema.json +23 -0
  99. package/examples/collection-pagination/translations.json +14 -0
  100. package/examples/collection-pagination/uischema.json +14 -0
  101. package/examples/color-control/README.md +151 -0
  102. package/examples/color-control/config.json +7 -0
  103. package/examples/color-control/data.json +11 -0
  104. package/examples/color-control/schema.json +61 -0
  105. package/examples/color-control/translations.json +76 -0
  106. package/examples/color-control/uischema.json +106 -0
  107. package/examples/combinators/README.md +223 -0
  108. package/examples/combinators/config.json +9 -0
  109. package/examples/combinators/data.json +23 -0
  110. package/examples/combinators/schema.json +232 -0
  111. package/examples/combinators/translations.json +178 -0
  112. package/examples/combinators/uischema.json +158 -0
  113. package/examples/conditional-fields/README.md +19 -0
  114. package/examples/conditional-fields/config.json +5 -0
  115. package/examples/conditional-fields/data.json +7 -0
  116. package/examples/conditional-fields/schema.json +59 -0
  117. package/examples/conditional-fields/translations.json +30 -0
  118. package/examples/conditional-fields/uischema.json +71 -0
  119. package/examples/container-validation-indicator/README.md +187 -0
  120. package/examples/container-validation-indicator/config.json +9 -0
  121. package/examples/container-validation-indicator/data.json +68 -0
  122. package/examples/container-validation-indicator/schema.json +222 -0
  123. package/examples/container-validation-indicator/translations.json +120 -0
  124. package/examples/container-validation-indicator/uischema.json +98 -0
  125. package/examples/cron-control/README.md +155 -0
  126. package/examples/cron-control/data.json +15 -0
  127. package/examples/cron-control/schema.json +72 -0
  128. package/examples/cron-control/translations.json +80 -0
  129. package/examples/cron-control/uischema.json +91 -0
  130. package/examples/destructive-confirmation/README.md +210 -0
  131. package/examples/destructive-confirmation/config.json +17 -0
  132. package/examples/destructive-confirmation/data.json +86 -0
  133. package/examples/destructive-confirmation/schema.json +204 -0
  134. package/examples/destructive-confirmation/translations.json +112 -0
  135. package/examples/destructive-confirmation/uischema.json +105 -0
  136. package/examples/draft-07-metaschema/README.md +11 -0
  137. package/examples/draft-07-metaschema/config.json +3 -0
  138. package/examples/draft-07-metaschema/data.json +25 -0
  139. package/examples/draft-07-metaschema/schema.json +172 -0
  140. package/examples/draft-07-metaschema/translations.json +10 -0
  141. package/examples/draft-07-metaschema/uischema.json +14 -0
  142. package/examples/dynamic-playground/README.md +95 -0
  143. package/examples/dynamic-playground/config.json +8 -0
  144. package/examples/dynamic-playground/configuration.json +152 -0
  145. package/examples/dynamic-playground/data.json +15 -0
  146. package/examples/dynamic-playground/dynamic-uischema.json +379 -0
  147. package/examples/dynamic-playground/host.mjs +37 -0
  148. package/examples/dynamic-playground/schema.json +48 -0
  149. package/examples/dynamic-playground/translations.json +76 -0
  150. package/examples/dynamic-playground/uischema.json +36 -0
  151. package/examples/editor-details/README.md +10 -0
  152. package/examples/editor-details/data.json +18 -0
  153. package/examples/editor-details/schema.json +49 -0
  154. package/examples/editor-details/translations.json +28 -0
  155. package/examples/editor-details/uischema.json +53 -0
  156. package/examples/editor-details/uischemas.d.mts +2 -0
  157. package/examples/editor-details/uischemas.json +14 -0
  158. package/examples/file-control/README.md +108 -0
  159. package/examples/file-control/data.json +28 -0
  160. package/examples/file-control/schema.json +89 -0
  161. package/examples/file-control/translations.json +46 -0
  162. package/examples/file-control/uischema.json +152 -0
  163. package/examples/group-layout/README.md +149 -0
  164. package/examples/group-layout/config.json +10 -0
  165. package/examples/group-layout/data.json +9 -0
  166. package/examples/group-layout/schema.json +51 -0
  167. package/examples/group-layout/translations.json +62 -0
  168. package/examples/group-layout/uischema.json +249 -0
  169. package/examples/index.d.ts +17 -0
  170. package/examples/index.js +69 -0
  171. package/examples/input-adornments/README.md +68 -0
  172. package/examples/input-adornments/data.json +41 -0
  173. package/examples/input-adornments/schema.json +207 -0
  174. package/examples/input-adornments/translations.json +106 -0
  175. package/examples/input-adornments/uischema.json +695 -0
  176. package/examples/job-application/README.md +23 -0
  177. package/examples/job-application/config.json +10 -0
  178. package/examples/job-application/data.json +68 -0
  179. package/examples/job-application/schema.json +196 -0
  180. package/examples/job-application/translations.json +388 -0
  181. package/examples/job-application/uischema.json +218 -0
  182. package/examples/job-application/uischemas.json +153 -0
  183. package/examples/json-editor/README.md +28 -0
  184. package/examples/json-editor/schema.json +1 -0
  185. package/examples/json-editor/translations.json +10 -0
  186. package/examples/json-editor/uischema.json +16 -0
  187. package/examples/json-inference/README.md +33 -0
  188. package/examples/json-inference/translations.json +10 -0
  189. package/examples/json-inference/uischema.json +16 -0
  190. package/examples/kitchen-sink/README.md +86 -0
  191. package/examples/kitchen-sink/config.json +14 -0
  192. package/examples/kitchen-sink/data.json +263 -0
  193. package/examples/kitchen-sink/invalid-data.json +263 -0
  194. package/examples/kitchen-sink/schema.json +515 -0
  195. package/examples/kitchen-sink/translations.json +270 -0
  196. package/examples/kitchen-sink/uischema.json +722 -0
  197. package/examples/label-interpolation/README.md +200 -0
  198. package/examples/label-interpolation/config.json +8 -0
  199. package/examples/label-interpolation/data.json +13 -0
  200. package/examples/label-interpolation/schema.json +64 -0
  201. package/examples/label-interpolation/translations.json +94 -0
  202. package/examples/label-interpolation/uischema.json +375 -0
  203. package/examples/layout-sizing/README.md +162 -0
  204. package/examples/layout-sizing/config.json +10 -0
  205. package/examples/layout-sizing/data.json +14 -0
  206. package/examples/layout-sizing/schema.json +58 -0
  207. package/examples/layout-sizing/translations.json +42 -0
  208. package/examples/layout-sizing/uischema.json +558 -0
  209. package/examples/markup-label/README.md +109 -0
  210. package/examples/markup-label/config.json +16 -0
  211. package/examples/markup-label/data.json +5 -0
  212. package/examples/markup-label/schema.json +24 -0
  213. package/examples/markup-label/translations.json +40 -0
  214. package/examples/markup-label/uischema.json +149 -0
  215. package/examples/mixed-control/README.md +164 -0
  216. package/examples/mixed-control/config.json +11 -0
  217. package/examples/mixed-control/data.json +70 -0
  218. package/examples/mixed-control/schema.json +221 -0
  219. package/examples/mixed-control/translations.json +158 -0
  220. package/examples/mixed-control/uischema.json +211 -0
  221. package/examples/null-control/README.md +111 -0
  222. package/examples/null-control/config.json +4 -0
  223. package/examples/null-control/data.json +6 -0
  224. package/examples/null-control/schema.json +36 -0
  225. package/examples/null-control/translations.json +42 -0
  226. package/examples/null-control/uischema.json +56 -0
  227. package/examples/numeric-controls/README.md +94 -0
  228. package/examples/numeric-controls/config.json +4 -0
  229. package/examples/numeric-controls/data.json +8 -0
  230. package/examples/numeric-controls/schema.json +52 -0
  231. package/examples/numeric-controls/translations.json +56 -0
  232. package/examples/numeric-controls/uischema.json +77 -0
  233. package/examples/object-control/README.md +220 -0
  234. package/examples/object-control/config.json +4 -0
  235. package/examples/object-control/data.json +62 -0
  236. package/examples/object-control/schema.json +252 -0
  237. package/examples/object-control/translations.json +160 -0
  238. package/examples/object-control/uischema.json +275 -0
  239. package/examples/object-control/uischemas.d.mts +2 -0
  240. package/examples/object-control/uischemas.json +59 -0
  241. package/examples/password-control/README.md +119 -0
  242. package/examples/password-control/config.json +3 -0
  243. package/examples/password-control/data.json +18 -0
  244. package/examples/password-control/schema.json +65 -0
  245. package/examples/password-control/translations.json +64 -0
  246. package/examples/password-control/uischema.json +94 -0
  247. package/examples/pre-touch-errors/README.md +176 -0
  248. package/examples/pre-touch-errors/config.json +4 -0
  249. package/examples/pre-touch-errors/data.json +5 -0
  250. package/examples/pre-touch-errors/schema.json +56 -0
  251. package/examples/pre-touch-errors/translations.json +68 -0
  252. package/examples/pre-touch-errors/uischema.json +85 -0
  253. package/examples/presentation/README.md +148 -0
  254. package/examples/presentation/config.json +9 -0
  255. package/examples/presentation/data.json +6 -0
  256. package/examples/presentation/schema.json +21 -0
  257. package/examples/presentation/translations.json +64 -0
  258. package/examples/presentation/uischema.json +210 -0
  259. package/examples/property-pagination/README.md +5 -0
  260. package/examples/property-pagination/config.json +1 -0
  261. package/examples/property-pagination/data.json +17 -0
  262. package/examples/property-pagination/schema.json +14 -0
  263. package/examples/property-pagination/translations.json +10 -0
  264. package/examples/property-pagination/uischema.json +24 -0
  265. package/examples/recursive-tree/README.md +49 -0
  266. package/examples/recursive-tree/config.json +1 -0
  267. package/examples/recursive-tree/data.json +40 -0
  268. package/examples/recursive-tree/schema.json +89 -0
  269. package/examples/recursive-tree/translations.json +42 -0
  270. package/examples/recursive-tree/uischema.json +84 -0
  271. package/examples/recursive-tree/uischemas.d.mts +2 -0
  272. package/examples/recursive-tree/uischemas.json +51 -0
  273. package/examples/split-layout/README.md +123 -0
  274. package/examples/split-layout/config.json +3 -0
  275. package/examples/split-layout/data.json +13 -0
  276. package/examples/split-layout/schema.json +50 -0
  277. package/examples/split-layout/translations.json +50 -0
  278. package/examples/split-layout/uischema.json +204 -0
  279. package/examples/string-controls/README.md +159 -0
  280. package/examples/string-controls/config.json +5 -0
  281. package/examples/string-controls/data.json +13 -0
  282. package/examples/string-controls/schema.json +70 -0
  283. package/examples/string-controls/translations.json +76 -0
  284. package/examples/string-controls/uischema.json +148 -0
  285. package/examples/table-row-details/README.md +69 -0
  286. package/examples/table-row-details/config.json +7 -0
  287. package/examples/table-row-details/data.json +280 -0
  288. package/examples/table-row-details/schema.json +61 -0
  289. package/examples/table-row-details/translations.json +56 -0
  290. package/examples/table-row-details/uischema.json +1303 -0
  291. package/examples/template-layout/README.md +250 -0
  292. package/examples/template-layout/config.json +9 -0
  293. package/examples/template-layout/data.json +20 -0
  294. package/examples/template-layout/host.mjs +13 -0
  295. package/examples/template-layout/schema.json +48 -0
  296. package/examples/template-layout/translations.json +70 -0
  297. package/examples/template-layout/uischema.json +177 -0
  298. package/examples/template-slots/README.md +19 -0
  299. package/examples/template-slots/data.json +4 -0
  300. package/examples/template-slots/schema.json +11 -0
  301. package/examples/template-slots/translations.json +26 -0
  302. package/examples/template-slots/uischema.json +47 -0
  303. package/examples/template-slots/uischemas.d.mts +2 -0
  304. package/examples/template-slots/uischemas.json +56 -0
  305. package/examples/temporal-controls/README.md +325 -0
  306. package/examples/temporal-controls/data.json +44 -0
  307. package/examples/temporal-controls/schema.json +208 -0
  308. package/examples/temporal-controls/translations.json +156 -0
  309. package/examples/temporal-controls/uischema.json +297 -0
  310. package/examples/tree-max-depth/README.md +5 -0
  311. package/examples/tree-max-depth/config.json +3 -0
  312. package/examples/tree-max-depth/data.json +31 -0
  313. package/examples/tree-max-depth/schema.json +258 -0
  314. package/examples/tree-max-depth/translations.json +42 -0
  315. package/examples/tree-max-depth/uischema.json +16 -0
  316. package/examples/tree-max-depth/uischemas.d.mts +2 -0
  317. package/examples/tree-max-depth/uischemas.json +50 -0
  318. package/examples/tuple-control/README.md +335 -0
  319. package/examples/tuple-control/config.json +4 -0
  320. package/examples/tuple-control/data.json +61 -0
  321. package/examples/tuple-control/schema.json +218 -0
  322. package/examples/tuple-control/translations.json +142 -0
  323. package/examples/tuple-control/uischema.json +128 -0
  324. package/examples/tuple-control/uischemas.d.mts +2 -0
  325. package/examples/tuple-control/uischemas.json +125 -0
  326. package/examples/validator-profile/README.md +197 -0
  327. package/examples/validator-profile/config.json +9 -0
  328. package/examples/validator-profile/data.json +16 -0
  329. package/examples/validator-profile/schema.json +139 -0
  330. package/examples/validator-profile/translations.json +34 -0
  331. package/examples/validator-profile/uischema.json +59 -0
  332. package/package.json +83 -3
  333. package/provenance.json +140 -0
  334. package/schemas/README.md +77 -0
  335. package/schemas/example.schema.json +37 -0
  336. package/schemas/jsonforms-config.schema.json +427 -0
  337. package/schemas/jsonforms-dynamic-uischema.schema.json +220 -0
  338. package/schemas/jsonforms-extended-config.schema.json +327 -0
  339. package/schemas/jsonforms-extended-uischema.schema.json +1923 -0
  340. package/schemas/jsonforms-rule.schema.json +104 -0
  341. package/schemas/jsonforms-uischema.schema.json +1421 -0
  342. package/typescript/README.md +540 -0
  343. package/typescript/lib/authoring/cssLength.d.ts +33 -0
  344. package/typescript/lib/authoring/cssLength.js +25 -0
  345. package/typescript/lib/authoring/dynamic.d.ts +73 -0
  346. package/typescript/lib/authoring/dynamic.js +8 -0
  347. package/typescript/lib/authoring/forSchema.d.ts +376 -0
  348. package/typescript/lib/authoring/forSchema.js +84 -0
  349. package/typescript/lib/authoring/schemaTypes.d.ts +111 -0
  350. package/typescript/lib/authoring/schemaTypes.js +15 -0
  351. package/typescript/lib/index.d.ts +4 -0
  352. package/typescript/lib/index.js +20 -0
  353. package/typescript/package.json +1 -0
  354. package/typescript/src/authoring/cssLength.ts +79 -0
  355. package/typescript/src/authoring/dynamic.ts +96 -0
  356. package/typescript/src/authoring/forSchema.ts +419 -0
  357. package/typescript/src/authoring/schemaTypes.ts +143 -0
  358. package/typescript/src/index.ts +4 -0
  359. package/typescript/test/schemaContract.test.ts +626 -0
  360. package/typescript/test/tsconfig.json +10 -0
  361. package/typescript/test/typedAuthoring.test.ts +140 -0
  362. package/typescript/test/typedAuthoringCoverage.test.ts +145 -0
  363. package/typescript/test/typedAuthoringCssLength.test.ts +81 -0
  364. package/typescript/test/typedAuthoringNames.test.ts +90 -0
  365. package/typescript/test/typedDynamic.test.ts +88 -0
  366. package/typescript/tsconfig.json +15 -0
@@ -0,0 +1,540 @@
1
+ # Authoring forms in TypeScript, type-safely
2
+
3
+ A JSON Schema and a UI schema are two documents that have to agree about one
4
+ thing — **paths** — and nothing in JSON checks that they do. A `scope` with a
5
+ typo is valid JSON, valid against the UI-model schema, and renders a control
6
+ that is bound to nothing. It fails at runtime by showing an empty field, which
7
+ is the hardest kind of failure to notice.
8
+
9
+ If both documents are written in TypeScript instead, the compiler can check
10
+ that agreement. This is what that looks like, what it catches, and — the part
11
+ that matters more — what it does not.
12
+
13
+ Helpers: `@chobantonov/jsonforms-extended-spec/typescript`
14
+ ([`src/authoring/`](src/authoring)).
15
+ Everything below is compiled and asserted in
16
+ [`test/typedAuthoring.test.ts`](test/typedAuthoring.test.ts).
17
+
18
+ The experimental `$dynamic` profile is also typed for Control, Label,
19
+ Category and layout helpers. Descriptor leaves retain the declared type of
20
+ known options while arbitrary extension keys remain available:
21
+
22
+ ```ts
23
+ f.control('email', {
24
+ $dynamic: [
25
+ { overlay: { label: { bind: 'external.settings.label' } } },
26
+ {
27
+ when: { expression: "external.settings.presentation == 'radio'" },
28
+ overlay: { options: { format: 'radio' } },
29
+ },
30
+ ],
31
+ });
32
+ ```
33
+
34
+ `DynamicSpec<T>` describes portable JSON descriptors;
35
+ `TrustedDynamicSpec<T>` separately admits synchronous function leaves for
36
+ in-process authoring. A host must explicitly enable that trusted runtime
37
+ profile. Neither TypeScript nor the schema can prove an expression's result
38
+ type, so the runtime still validates resolved values. See
39
+ [`typedDynamic.test.ts`](test/typedDynamic.test.ts) for positive and negative
40
+ compile-time cases.
41
+
42
+ ## The shape of it
43
+
44
+ ```ts
45
+ import { forSchema, type DataOf } from '@chobantonov/jsonforms-extended-spec/typescript';
46
+
47
+ // 1. The schema, `as const` — see "Why `as const`" below.
48
+ export const schema = {
49
+ type: 'object',
50
+ required: ['email'],
51
+ properties: {
52
+ email: { type: 'string', format: 'email' },
53
+ age: { type: 'integer', minimum: 0 },
54
+ subscribed: { type: 'boolean' },
55
+ address: {
56
+ type: 'object',
57
+ properties: {
58
+ city: { type: 'string' },
59
+ postcode: { type: 'string' },
60
+ },
61
+ },
62
+ orders: {
63
+ type: 'array',
64
+ items: { type: 'object', properties: { reference: { type: 'string' } } },
65
+ },
66
+ },
67
+ } as const;
68
+
69
+ // 2. Bind the helpers to it. The argument is used for inference only.
70
+ const f = forSchema(schema);
71
+
72
+ // 3. The UI schema, written against it.
73
+ export const uischema = f.layout({
74
+ type: 'VerticalLayout',
75
+ options: { gap: 16 },
76
+ elements: [
77
+ f.control('email'),
78
+ f.control('age', { options: { slider: true } }),
79
+ f.control('address.city', { label: 'Town' }),
80
+ f.control('orders', { options: { table: true, variant: 'ag-grid' } }),
81
+ f.control('subscribed', {
82
+ rule: {
83
+ effect: 'HIDE',
84
+ condition: { scope: f.scope('age'), schema: { maximum: 17 } },
85
+ },
86
+ }),
87
+ ],
88
+ });
89
+
90
+ // 4. The data type falls out of the schema.
91
+ export type Data = DataOf<typeof schema>;
92
+ // { email: string; age?: number; subscribed?: boolean;
93
+ // address?: { city?: string; postcode?: string };
94
+ // orders?: { reference?: string }[] }
95
+ ```
96
+
97
+ `f.control('address.city')` produces exactly
98
+ `{ type: 'Control', scope: '#/properties/address/properties/city' }` — an
99
+ ordinary portable element. Nothing about the runtime changes, and the output
100
+ is still plain JSON you could have written by hand. The helpers exist so that
101
+ writing it by hand wrongly stops compiling.
102
+
103
+ Paths are **dotted data paths**, not pointers: you write `address.city`, not
104
+ `properties/address/properties/city`. The `properties` segments are noise that
105
+ comes from the schema's own shape, and making an author repeat them is making
106
+ them repeat something the compiler already knows.
107
+
108
+ ## What it catches
109
+
110
+ Every line below is a compile error. Each is asserted with `@ts-expect-error`
111
+ in the test, so if any of them ever starts compiling, the build fails.
112
+
113
+ ```ts
114
+ f.control('emial'); // a misspelled property
115
+ f.control('address.postcod'); // misspelled, nested
116
+ f.control('address.city.suburb'); // a path past a leaf
117
+ f.control('orders.reference'); // an array is terminal
118
+ f.control('email', { options: { slider: true } }); // numeric option on a string
119
+ f.control('age', { options: { multi: true } }); // string option on a number
120
+ f.control('age', { options: { slider: 'yes' } }); // right option, wrong value
121
+ f.control('email', { labl: 'typo' }); // a misspelled element key
122
+
123
+ f.control('email', {
124
+ rule: {
125
+ effect: 'HIDE',
126
+ condition: { scope: f.scope('nope'), schema: {} }, // a rule's scope, too
127
+ },
128
+ });
129
+
130
+ const wrong: Data = { email: 'a@b.c', age: 'old' }; // wrong data type
131
+ const missing: Data = { age: 3 }; // `email` is required
132
+ ```
133
+
134
+ The scope also comes back as a **literal type**, not `string`:
135
+
136
+ ```ts
137
+ const s: '#/properties/address/properties/city' = f.scope('address.city');
138
+ ```
139
+
140
+ which means an editor shows you the pointer on hover, and a wrong annotation
141
+ is an error rather than a comment that drifts.
142
+
143
+ ### Why arrays are terminal
144
+
145
+ `orders.reference` is rejected on purpose. A control inside an array's
146
+ `detail` is scoped **relative to the item** — `#/properties/reference` — so
147
+ the through-path would be a pointer that resolves to nothing. The array itself
148
+ is addressable; its items are addressed from the detail's own uischema:
149
+
150
+ ```ts
151
+ const item = forSchema(schema.properties.orders.items);
152
+ f.control('orders', {
153
+ options: {
154
+ detail: item.layout({
155
+ type: 'VerticalLayout',
156
+ elements: [item.control('reference')],
157
+ }),
158
+ },
159
+ });
160
+ ```
161
+
162
+ The same trick applies anywhere the scope resets: bind a second `forSchema` to
163
+ the sub-schema and carry on.
164
+
165
+ ## Property names that collide with the addressing scheme
166
+
167
+ Paths are dotted, so a property name can collide with the syntax that
168
+ addresses it. Three cases, three different answers — all pinned in
169
+ [`typedAuthoringNames.test.ts`](test/typedAuthoringNames.test.ts),
170
+ which resolves each pointer against the schema rather than only comparing
171
+ strings.
172
+
173
+ ### A property named `properties` — fine
174
+
175
+ ```ts
176
+ f.scope('properties') // '#/properties/properties'
177
+ f.scope('properties.city') // '#/properties/properties/properties/city'
178
+ ```
179
+
180
+ Nothing is ambiguous: the first `properties` is the keyword, the second is
181
+ the property. The same holds for names that look like other keywords —
182
+ `items`, `type`, `required` — because they are only ever read as names under
183
+ `properties`.
184
+
185
+ ### `/` and `~` — addressable, and escaped for you
186
+
187
+ JSON Pointer reserves both, so a property called `a/b` is addressed as
188
+ `a~1b`:
189
+
190
+ ```ts
191
+ f.scope('a/b') // '#/properties/a~1b'
192
+ f.scope('c~d') // '#/properties/c~0d'
193
+ ```
194
+
195
+ This is the same escaping core's own `getPropPath` applies, and core
196
+ `decode`s on the way back. Left raw, `#/properties/a/b` would walk into a
197
+ property called `a` and resolve to nothing.
198
+
199
+ ### A dot in a name — **not addressable**, and refused
200
+
201
+ ```ts
202
+ f.scope('first.name'); // compile error
203
+ ```
204
+
205
+ JSON Forms addresses data with dotted paths and **the grammar has no
206
+ escape**, so a property literally called `first.name` has no scope at all:
207
+ it splits into two segments and yields `#/properties/first/properties/name`,
208
+ which is well-formed, points at nothing, and reports no error anywhere. Core
209
+ has the same limitation — `getPropPath` splits on `.` too — so it is not
210
+ something these helpers could route around.
211
+
212
+ So such a name is left out of the offered paths. A compile error is the
213
+ honest answer; a pointer that silently resolves to nothing is not.
214
+
215
+ The name itself is perfectly legal, and the data validates — this is an
216
+ addressing limit, not a restriction on JSON.
217
+ [portable contract](../docs/spec.md) covers the
218
+ runtime half: such properties are not refused, and are edited through a
219
+ control that uses no path at all.
220
+
221
+ ## Sizing options are the one narrow type
222
+
223
+ `width`, `height`, `minWidth`, `maxWidth`, `gap` and `minItemWidth` take a
224
+ `CssLength` rather than `number | string`, so `width: '100'` and
225
+ `width: 'pixels'` are compile errors.
226
+
227
+ This is the only place where the types are **narrower than the runtime**:
228
+ `toCss` passes any string through as authored, so `CssLength` can only ever
229
+ be a subset of what works. That inverts the usual risk — a false rejection
230
+ turns correct CSS into a build failure — which is why the shape of it is
231
+ pinned in
232
+ [`typedAuthoringCssLength.test.ts`](test/typedAuthoringCssLength.test.ts)
233
+ rather than left to whoever next edits the unit list.
234
+
235
+ Three calibration decisions worth knowing:
236
+
237
+ - **The functional notations are all admitted**, not only `calc()`.
238
+ `clamp()`, `min()`, `max()`, `var()` and `fit-content()` are ordinary in
239
+ responsive layouts; a type that allows only `calc()` rejects correct CSS.
240
+ - **The unit list is long on purpose.** `vmin`, `dvh`, `pt`, `lh`, `ch` and
241
+ the rest are all accepted. A short, tidy list turns each of them into an
242
+ error on a value that works.
243
+ - **`fr` is deliberately excluded.** These layout containers are
244
+ `display: flex`, and item sizing sets `flex-basis` and `width`. `fr` is a
245
+ grid unit and means nothing in either, so admitting it would type-approve a
246
+ value the browser silently ignores — which is worse than rejecting it.
247
+
248
+ `'0'` is accepted as the one unitless length. TypeScript's `${number}` is
249
+ lenient enough that `'100 px'` also gets through; narrowing that is not worth
250
+ the type it would take.
251
+
252
+ ### The option names are the ones the renderer reads
253
+
254
+ `layout` takes `minWidth` / `maxWidth` / `minHeight` / `maxHeight`, not
255
+ `min` / `max`. An earlier draft of this module had the short forms, which
256
+ `itemSizing` reads nowhere: it would have type-approved a dead option while
257
+ rejecting the one that works. If you are adding an option here, check it
258
+ against `LayoutItemOptions` in `layoutSizing.ts` rather than against the
259
+ specification prose.
260
+
261
+ ## Why `as const`
262
+
263
+ This is the one thing that decides how much of the above works, and it fails
264
+ quietly if you forget it.
265
+
266
+ | Schema declared as | Paths checked | Options checked | `DataOf` |
267
+ | --- | --- | --- | --- |
268
+ | `{ … }` | **yes** | no | `unknown` |
269
+ | `{ … } as const` | yes | yes | yes |
270
+ | `{ … } as const satisfies AuthoredSchema` | yes | yes | yes, **and the schema itself is checked** |
271
+
272
+ Property *names* are keys, and keys survive widening — so paths keep being
273
+ checked even without `as const`. Property *values* do not: `type: 'integer'`
274
+ widens to `type: string`, every kind test stops matching, and both the option
275
+ map and the data type fall back to "anything". You get an authoring experience
276
+ that looks identical and checks half as much.
277
+
278
+ Prefer the third form. `as const satisfies` keeps the literal inference **and**
279
+ makes TypeScript check that what you wrote is a schema at all, which the first
280
+ two do not.
281
+
282
+ **`satisfies JsonSchema` does not work**, which is worth stating because it is
283
+ the obvious thing to reach for. `as const` freezes `required: ['email']` into
284
+ a `readonly` tuple, and `JsonSchema` declares `required` as a mutable
285
+ `string[]`; the two do not overlap, so every schema with a `required` is
286
+ rejected. `AuthoredSchema` is the same type made deeply readonly, and exists
287
+ only to be `satisfies`-ed against.
288
+
289
+ ## Can it express everything the JSON way can?
290
+
291
+ **Yes — nothing is unauthorable.** But the checking is not uniform, and it is
292
+ worth knowing which of three buckets a thing falls into before you commit.
293
+
294
+ Every element kind and awkward schema shape below is built in
295
+ [`typedAuthoringCoverage.test.ts`](test/typedAuthoringCoverage.test.ts),
296
+ which is what keeps this section from drifting.
297
+
298
+ ### 1. Modelled, and checked
299
+
300
+ Controls, the four layouts, `Category`, `Label`, rules — including `AND`/`OR`
301
+ composition and `failWhenUndefined` — `i18n` prefixes, `label` as a string, a
302
+ boolean or a `{ text, show }` descriptor, and the root scope (`f.control('')`
303
+ → `#`).
304
+
305
+ ```ts
306
+ f.layout({
307
+ type: 'Categorization',
308
+ elements: [
309
+ f.category({
310
+ label: 'Contact',
311
+ elements: [
312
+ f.label({ text: 'Tell us how to reach you' }),
313
+ f.control('email', { i18n: 'email' }),
314
+ f.control('kind', {
315
+ rule: {
316
+ effect: 'HIDE',
317
+ condition: {
318
+ type: 'AND',
319
+ conditions: [{ scope: f.scope('email'), schema: { minLength: 1 } }],
320
+ },
321
+ },
322
+ }),
323
+ ],
324
+ }),
325
+ ],
326
+ });
327
+ ```
328
+
329
+ ### 2. Expressible through `raw`, unchecked
330
+
331
+ Anything this module does not model — an extended element (`Button`,
332
+ `SplitLayout`, `TemplateLayout`, `ImageView`, `Separator`), a layout from
333
+ another family, or an option the curated map does not carry:
334
+
335
+ ```ts
336
+ f.raw({ type: 'Button', label: 'Go', action: 'submit' })
337
+ ```
338
+
339
+ For an **unmodelled option**, use `raw` for the element but keep the typed
340
+ scope — you lose the option checking and keep the path checking, which is the
341
+ half that actually catches mistakes:
342
+
343
+ ```ts
344
+ f.raw({
345
+ type: 'Control',
346
+ scope: f.scope('email'), // still checked
347
+ options: { autocomplete: true }, // not checked
348
+ })
349
+ ```
350
+
351
+ `raw` is deliberately a **named** escape rather than a permissive member of
352
+ the element union. A permissive member would also swallow a mistyped
353
+ `Control`; `f.raw(` is greppable, and the loss of checking is visible where it
354
+ happens.
355
+
356
+ ### 3. Addressable as a whole, not traversable
357
+
358
+ A combinator (`oneOf`/`anyOf`/`allOf`), a tuple array, an
359
+ `additionalProperties` map and a `$ref` are all bindable — `f.control('choice')`,
360
+ `f.control('home')` — but the types do not see inside them. Their `DataOf`
361
+ degrades to `unknown` rather than guessing.
362
+
363
+ For `$ref` and array items there is a good answer: point a second `forSchema`
364
+ at the sub-schema, which restores full checking from there down. That is the
365
+ same move the array `detail` example uses.
366
+
367
+ ```ts
368
+ const addr = forSchema(schema.$defs.addr);
369
+ f.control('home', { options: { detail: addr.layout({ … }) } });
370
+ ```
371
+
372
+ **Two things are impossible, not merely unimplemented**, and no amount of type
373
+ machinery will change them:
374
+
375
+ - **A dynamic property name.** `extras.anything` under `additionalProperties`
376
+ has no name until runtime. The map is addressable; its members are not.
377
+ - **A schema that does not exist at compile time** — fetched over the network,
378
+ assembled at runtime, or narrowed by `if`/`then`/`else`. There is nothing to
379
+ infer from.
380
+
381
+ Both fall back to plain objects, which still work, because the output was
382
+ always ordinary JSON.
383
+
384
+ ### The practical answer
385
+
386
+ Adopt it per form. A typed uischema is an ordinary uischema, so a form that
387
+ turns out to be awkward can stay JSON, and a form can be half-and-half without
388
+ anything special. You are never choosing between the two for the whole
389
+ project.
390
+
391
+ ## What it does not catch
392
+
393
+ Worth reading in full before relying on any of this.
394
+
395
+ **1. Which renderer will be chosen.** Selection is done by testers at runtime,
396
+ from the schema and the options together. The types know the option is
397
+ *admissible*; they cannot know that `{ slider: true }` will actually reach the
398
+ slider rather than losing a rank contest. Nothing at the type level models
399
+ tester ranks.
400
+
401
+ **2. Options this map does not know.** `OptionsFor` is a curated subset — the
402
+ options these renderers read for each schema kind — not something generated
403
+ from the published JSON Schemas in [`schemas/`](../schemas). It will lag them.
404
+ Adding one is a line in `forSchema.ts`.
405
+
406
+ **3. Anything built as a variable first.** TypeScript's excess property
407
+ checking applies only to a *fresh object literal*:
408
+
409
+ ```ts
410
+ const opts = { slider: true, notAnOption: 1 };
411
+ f.control('age', { options: opts }); // compiles. No error.
412
+ ```
413
+
414
+ A real hole, and an unreliable escape hatch: it only works while the object
415
+ shares **at least one** property with the expected type. An options object
416
+ with nothing in common is still rejected, with
417
+ `has no properties in common with type 'OptionsFor<…>'`. Use `f.raw` for that
418
+ case — it is the escape that always works, and it says so at the call site.
419
+
420
+ **4. `$ref`.** Nothing resolves one. A property whose schema is
421
+ `{ $ref: '#/$defs/address' }` has no `properties` at the type level, so it is
422
+ terminal — `home` is offered, `home.city` is not. Point a second `forSchema`
423
+ at the definition, as with array items.
424
+
425
+ **5. The runtime schema, if it is not the same object.** All of this checks
426
+ the schema *as a TypeScript type*. A schema fetched over the network, built at
427
+ runtime, or narrowed by an `if/then/else` is outside it entirely.
428
+
429
+ **6. That the pointer is correct.** `Scope<P>` and the string the builder
430
+ returns are tied together by a cast, which is precisely where a type and a
431
+ value drift apart unnoticed. The test asserts they agree on concrete paths;
432
+ that assertion is the only thing holding them together.
433
+
434
+ ## How this differs from typing the element itself
435
+
436
+ Another approach — used by the `workflowbuilder` project, which is where this
437
+ one started — gives every control its own element `type`:
438
+ `{ type: 'Text', scope, placeholder }`, with options flat on the element and
439
+ a discriminated union over `type`. Renderers are then selected by
440
+ `uiTypeIs('Text')` at a fixed rank.
441
+
442
+ It buys sharper option checking, because the element names its own renderer.
443
+ It costs portability: those uischemas are not JSON Forms uischemas any more,
444
+ schema-driven selection is gone (nothing picks a date control because
445
+ `format: 'date'`), and the same document cannot be handed to another renderer
446
+ family.
447
+
448
+ The approach here keeps `type: 'Control'` and tester-based selection, so a
449
+ uischema written this way is still an ordinary portable one — it can be
450
+ serialised, stored, sent to a server, and rendered by a family that has never
451
+ heard of these helpers. The type checking is a **development-time** aid over
452
+ an unchanged document, which is also why it can be adopted one form at a time.
453
+
454
+ ## Using it with `<JsonForms>`
455
+
456
+ The output is an ordinary UI schema, so nothing special is needed:
457
+
458
+ ```tsx
459
+ import { asJsonSchema, asUiSchema } from '@chobantonov/jsonforms-extended-spec/typescript';
460
+
461
+ <JsonForms
462
+ schema={asJsonSchema(schema)}
463
+ uischema={asUiSchema(uischema)}
464
+ data={data}
465
+ renderers={renderers}
466
+ cells={cells}
467
+ onChange={({ data }) => setData(data as Data)}
468
+ />
469
+ ```
470
+
471
+ Those two helpers are widening casts, and they are helpers rather than inline
472
+ casts for a reason: `schema as JsonSchema` **does not compile**. `as const`
473
+ makes every array readonly, `JsonSchema` wants mutable ones, and TypeScript
474
+ refuses a direct cast between types that "do not sufficiently overlap" — so
475
+ the inline version has to be `as unknown as JsonSchema`, which is the kind of
476
+ thing that gets copied into places it should not be. Doing it once, in a named
477
+ function, keeps it to one place.
478
+
479
+ The widening is safe in the direction that matters: the value really is a
480
+ schema and really is a UI schema, JSON Forms does not mutate either, and what
481
+ is lost at the boundary is only the extra precision — lost *after* every check
482
+ above has already run.
483
+
484
+ ### Array detail modes
485
+
486
+ Array control options accept the exported ArrayDetail type: an inline UI schema,
487
+ an elements container, or a string mode. Use detail: 'GENERATE' to bypass
488
+ registered layouts and detail: 'REGISTERED' to prefer a registered layout.
489
+ DEFAULT keeps normal renderer selection. Values are case-insensitive; other
490
+ strings (including GENERATED) use registry lookup, matching upstream core.
491
+ See examples/array-detail-modes for executable layouts and trusted registrations.
492
+
493
+ ## Editor detail modes and mixed type overrides
494
+
495
+ The detail resolver is also used for object and mixed editors. Explicit editor
496
+ details in composite cells, tuple-field editors, recursiveTree.detail, and row
497
+ editors accept the same string modes or inline layout. GENERATE bypasses registry
498
+ lookup and preserves that intent through a fallback Control. REGISTERED and other
499
+ strings use the registry before the context-specific fallback. DEFAULT preserves
500
+ normal presentation; it does not mean table outside array selection. An omitted
501
+ option retains the editor's existing default, which may already be a registered
502
+ layout. Scopes in inline layouts are relative to the edited value's schema.
503
+
504
+ Tuple container detail remains a position layout scoped to the whole tuple.
505
+ Do not apply an array-item editor layout to each tuple position.
506
+
507
+ Mixed controls accept object-detail, array-detail, string-detail, number-detail,
508
+ integer-detail, boolean-detail, and null-detail. For the current mixed value,
509
+ the selected type's option takes precedence over detail, including string modes.
510
+ This is a project extension, not a new upstream detail mode. It does not change
511
+ structuredLayout (tree/nested/code). Tree mode uses it for that mixed value's root
512
+ detail pane; it does not impose a root-specific layout on every descendant.
513
+ Code presentation edits the whole value and does not use these field layouts.
514
+ Null retains the existing no-value-control presentation.
515
+
516
+ See the editor-details example. Renderer projects document their own support.
517
+
518
+ ## Authoring named templates and slots
519
+
520
+ Template and Slot are extended elements; use the explicit `f.raw(...)` escape
521
+ hatch in the schema-bound authoring API. Their `name` is a top-level UI-model
522
+ property, not an option or a data path:
523
+
524
+ ```ts
525
+ f.raw({ type: 'Template', name: 'contact-card', elements: [
526
+ { type: 'Control', name: 'body', scope: '#/properties/name' }
527
+ ] });
528
+ ```
529
+
530
+ Register a layout with `uischema.name: 'contact-card'` containing
531
+ `{ type: 'Slot', name: 'body' }`. Its registry tester can return -1: named lookup
532
+ ignores rankings. The raw escape hatch does not type-check the slot contract;
533
+ validate authored models against the extended UI-schema JSON Schema. See the
534
+ [complete example](../examples/template-slots/README.md).
535
+
536
+ ## Conditional fields
537
+
538
+ See [conditional field presentation and graphical authoring](../docs/conditional-fields.md).
539
+ Use `options.conditionalFields: true` on an object Control or the default
540
+ `config.jsonformsExtended.conditionalFields`. Local false opts out.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A CSS length, as far as a type can usefully describe one.
3
+ *
4
+ * The runtime accepts `number | string` and passes a string through as
5
+ * authored by the form author, so this type is
6
+ * deliberately a **subset** of what will work - its job is to catch `width:
7
+ * '100'` and `width: 'pixels'`, not to be the authority on CSS.
8
+ *
9
+ * Three calibration decisions, each of which costs something if got wrong:
10
+ *
11
+ * - **No `fr`.** The layout containers are `display: flex` and item sizing
12
+ * sets `flex-basis` and `width`. `fr` is a grid unit and means nothing in
13
+ * either, so admitting it would type-approve a value that silently does
14
+ * nothing - the worst kind of permissiveness.
15
+ * - **The functional notations are all here**, not only `calc()`. `clamp()`,
16
+ * `min()`, `max()` and `var()` are ordinary in responsive layouts, and a
17
+ * type that rejects them produces false errors on correct CSS.
18
+ * - **The unit list is long on purpose.** A short list looks tidy and turns
19
+ * every `vmin`, `dvh` or `pt` into a compile error on a value that works.
20
+ *
21
+ * Known looseness: TypeScript's `${number}` is lenient, so `'100 px'` is
22
+ * accepted. Narrowing that is not worth the type it would take.
23
+ */
24
+ type AbsoluteUnit = 'px' | 'pt' | 'pc' | 'cm' | 'mm' | 'in' | 'q';
25
+ type FontRelativeUnit = 'em' | 'rem' | 'ex' | 'ch' | 'cap' | 'ic' | 'lh' | 'rlh';
26
+ type ViewportUnit = 'vw' | 'vh' | 'vmin' | 'vmax' | 'vi' | 'vb' | 'svw' | 'svh' | 'lvw' | 'lvh' | 'dvw' | 'dvh';
27
+ export type CssUnit = AbsoluteUnit | FontRelativeUnit | ViewportUnit | '%';
28
+ /** Sizing keywords, plus the CSS-wide ones any property accepts. */
29
+ export type CssKeyword = 'auto' | 'none' | 'min-content' | 'max-content' | 'fit-content' | 'stretch' | 'inherit' | 'initial' | 'revert' | 'unset';
30
+ export type CssFunction = `calc(${string})` | `min(${string})` | `max(${string})` | `clamp(${string})` | `fit-content(${string})` | `var(${string})`;
31
+ /** A bare number is CSS pixels, which is what `toCss` does with it. */
32
+ export type CssLength = number | `${number}${CssUnit}` | '0' | CssKeyword | CssFunction;
33
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * A CSS length, as far as a type can usefully describe one.
4
+ *
5
+ * The runtime accepts `number | string` and passes a string through as
6
+ * authored by the form author, so this type is
7
+ * deliberately a **subset** of what will work - its job is to catch `width:
8
+ * '100'` and `width: 'pixels'`, not to be the authority on CSS.
9
+ *
10
+ * Three calibration decisions, each of which costs something if got wrong:
11
+ *
12
+ * - **No `fr`.** The layout containers are `display: flex` and item sizing
13
+ * sets `flex-basis` and `width`. `fr` is a grid unit and means nothing in
14
+ * either, so admitting it would type-approve a value that silently does
15
+ * nothing - the worst kind of permissiveness.
16
+ * - **The functional notations are all here**, not only `calc()`. `clamp()`,
17
+ * `min()`, `max()` and `var()` are ordinary in responsive layouts, and a
18
+ * type that rejects them produces false errors on correct CSS.
19
+ * - **The unit list is long on purpose.** A short list looks tidy and turns
20
+ * every `vmin`, `dvh` or `pt` into a compile error on a value that works.
21
+ *
22
+ * Known looseness: TypeScript's `${number}` is lenient, so `'100 px'` is
23
+ * accepted. Narrowing that is not worth the type it would take.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,73 @@
1
+ /** Portable JSON leaves. Functions belong only to the explicitly trusted profile. */
2
+ export type DynamicJson = null | boolean | number | string | readonly DynamicJson[] | {
3
+ readonly [key: string]: DynamicJson;
4
+ };
5
+ export type DynamicDescriptor<T = DynamicJson> = {
6
+ readonly bind: string;
7
+ } | {
8
+ readonly expression: string;
9
+ } | (string extends T ? {
10
+ readonly template: string;
11
+ } : never) | {
12
+ readonly literal: T;
13
+ };
14
+ /** Extension values remain portable; unknown keys do not admit executable code. */
15
+ export type DynamicExtension = DynamicJson | undefined | {
16
+ readonly [key: string]: DynamicExtension;
17
+ } | readonly DynamicExtension[];
18
+ /** Array replacements contain complete entries, not partial object patches. */
19
+ export type DynamicArrayEntry<T> = DynamicDescriptor<T> | (T extends readonly (infer Item)[] ? readonly DynamicArrayEntry<Item>[] : T extends object ? {
20
+ readonly [K in keyof T]: DynamicArrayEntry<T[K]>;
21
+ } : T);
22
+ export type DynamicValue<T> = T | DynamicDescriptor<T> | (T extends readonly (infer Item)[] ? readonly DynamicArrayEntry<Item>[] : T extends object ? {
23
+ readonly [K in keyof T]?: DynamicValue<T[K]>;
24
+ } & {
25
+ readonly [extension: string]: DynamicExtension;
26
+ } : never);
27
+ /** Known fields retain their types; adapters may forward unknown extension fields. */
28
+ export type DynamicOverlay<T> = {
29
+ readonly [K in keyof T as K extends '$dynamic' ? never : K]?: DynamicValue<T[K]>;
30
+ } & {
31
+ readonly $dynamic?: never;
32
+ readonly [extension: string]: DynamicExtension;
33
+ };
34
+ export type DynamicRule<T> = {
35
+ readonly when?: boolean | {
36
+ readonly expression: string;
37
+ };
38
+ readonly overlay: DynamicOverlay<T>;
39
+ };
40
+ export type DynamicSpec<T> = DynamicOverlay<T> | readonly DynamicRule<T>[];
41
+ /** Type and scope may select a different renderer, so overlays may change them. */
42
+ export type DynamicTarget<T> = Omit<T, 'type' | 'scope' | '$dynamic'> & {
43
+ type: string;
44
+ scope?: string;
45
+ };
46
+ export type TrustedDynamicFunction<T> = (environment: Readonly<Record<string, unknown>>) => T;
47
+ export type TrustedDynamicArrayEntry<T> = DynamicDescriptor<T> | TrustedDynamicFunction<T> | (T extends readonly (infer Item)[] ? readonly TrustedDynamicArrayEntry<Item>[] : T extends object ? {
48
+ readonly [K in keyof T]: TrustedDynamicArrayEntry<T[K]>;
49
+ } : T);
50
+ export type TrustedDynamicValue<T> = DynamicValue<T> | TrustedDynamicFunction<T> | (T extends readonly (infer Item)[] ? readonly TrustedDynamicArrayEntry<Item>[] : T extends object ? {
51
+ readonly [K in keyof T]?: TrustedDynamicValue<T[K]>;
52
+ } & {
53
+ readonly [extension: string]: unknown;
54
+ } : never);
55
+ export type TrustedDynamicOverlay<T> = {
56
+ readonly [K in keyof T as K extends '$dynamic' ? never : K]?: TrustedDynamicValue<T[K]>;
57
+ } & {
58
+ readonly $dynamic?: never;
59
+ readonly [extension: string]: unknown;
60
+ };
61
+ export type TrustedDynamicRule<T> = {
62
+ readonly when?: boolean | {
63
+ readonly expression: string;
64
+ } | TrustedDynamicFunction<boolean>;
65
+ readonly overlay: TrustedDynamicOverlay<T>;
66
+ };
67
+ export type TrustedDynamicSpec<T> = TrustedDynamicOverlay<T> | readonly TrustedDynamicRule<T>[];
68
+ /** Opt into trusted authoring explicitly without weakening portable form helpers. */
69
+ export declare function withTrustedDynamic<T extends {
70
+ type: string;
71
+ }>(element: T, dynamic: TrustedDynamicSpec<DynamicTarget<T>>): Omit<T, '$dynamic'> & {
72
+ $dynamic: TrustedDynamicSpec<DynamicTarget<T>>;
73
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withTrustedDynamic = void 0;
4
+ /** Opt into trusted authoring explicitly without weakening portable form helpers. */
5
+ function withTrustedDynamic(element, dynamic) {
6
+ return { ...element, $dynamic: dynamic };
7
+ }
8
+ exports.withTrustedDynamic = withTrustedDynamic;