@chobantonov/jsonforms-extended-spec 0.0.0-stage → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/conformance/authoring.json +2680 -0
- package/conformance/behavior.json +1602 -0
- package/conformance/config-consumption.json +1542 -0
- package/conformance/expected-invalid.json +20 -0
- package/docs/audit.md +150 -0
- package/docs/conditional-fields.md +122 -0
- package/docs/draft-07-visual-support.md +43 -0
- package/docs/external-resources-proposal.md +536 -0
- package/docs/implementation-guide.md +233 -0
- package/docs/implementation-pitfalls.md +968 -0
- package/docs/implementation-web-typescript.md +41 -0
- package/docs/renderer-and-demo.md +1347 -0
- package/docs/renderer-selection.md +99 -0
- package/docs/spec.md +8470 -0
- package/docs/todo.md +166 -0
- package/examples/README.md +127 -0
- package/examples/additional-errors/README.md +176 -0
- package/examples/additional-errors/config.json +3 -0
- package/examples/additional-errors/data.json +11 -0
- package/examples/additional-errors/schema.json +56 -0
- package/examples/additional-errors/translations.json +64 -0
- package/examples/additional-errors/uischema.json +158 -0
- package/examples/additional-items-pagination/README.md +8 -0
- package/examples/additional-items-pagination/config.json +10 -0
- package/examples/additional-items-pagination/data.json +22 -0
- package/examples/additional-items-pagination/schema.json +30 -0
- package/examples/additional-items-pagination/translations.json +16 -0
- package/examples/additional-items-pagination/uischema.json +39 -0
- package/examples/additional-properties/README.md +203 -0
- package/examples/additional-properties/config.json +5 -0
- package/examples/additional-properties/data.json +31 -0
- package/examples/additional-properties/schema.json +78 -0
- package/examples/additional-properties/translations.json +80 -0
- package/examples/additional-properties/uischema.json +104 -0
- package/examples/ag-grid/README.md +62 -0
- package/examples/ag-grid/config.json +14 -0
- package/examples/ag-grid/data.json +124 -0
- package/examples/ag-grid/schema.json +48 -0
- package/examples/ag-grid/translations.json +58 -0
- package/examples/ag-grid/uischema.json +671 -0
- package/examples/array-choices/README.md +150 -0
- package/examples/array-choices/config.json +4 -0
- package/examples/array-choices/data.json +10 -0
- package/examples/array-choices/schema.json +68 -0
- package/examples/array-choices/translations.json +64 -0
- package/examples/array-choices/uischema.json +97 -0
- package/examples/array-controls/README.md +237 -0
- package/examples/array-controls/config.json +4 -0
- package/examples/array-controls/data.json +147 -0
- package/examples/array-controls/schema.json +374 -0
- package/examples/array-controls/translations.json +186 -0
- package/examples/array-controls/uischema.json +685 -0
- package/examples/array-detail-modes/README.md +11 -0
- package/examples/array-detail-modes/data.json +38 -0
- package/examples/array-detail-modes/schema.json +89 -0
- package/examples/array-detail-modes/translations.json +36 -0
- package/examples/array-detail-modes/uischema.json +73 -0
- package/examples/array-detail-modes/uischemas.d.mts +2 -0
- package/examples/array-detail-modes/uischemas.json +15 -0
- package/examples/boolean-controls/README.md +109 -0
- package/examples/boolean-controls/config.json +3 -0
- package/examples/boolean-controls/data.json +27 -0
- package/examples/boolean-controls/schema.json +98 -0
- package/examples/boolean-controls/translations.json +94 -0
- package/examples/boolean-controls/uischema.json +126 -0
- package/examples/button-actions/README.md +259 -0
- package/examples/button-actions/config.json +7 -0
- package/examples/button-actions/data.json +5 -0
- package/examples/button-actions/host.mjs +14 -0
- package/examples/button-actions/schema.json +20 -0
- package/examples/button-actions/translations.json +60 -0
- package/examples/button-actions/uischema.json +179 -0
- package/examples/catalog.json +634 -0
- package/examples/categorization/README.md +132 -0
- package/examples/categorization/config.json +7 -0
- package/examples/categorization/data.json +8 -0
- package/examples/categorization/schema.json +29 -0
- package/examples/categorization/translations.json +72 -0
- package/examples/categorization/uischema.json +288 -0
- package/examples/choice-controls/README.md +136 -0
- package/examples/choice-controls/config.json +10 -0
- package/examples/choice-controls/data.json +61 -0
- package/examples/choice-controls/schema.json +406 -0
- package/examples/choice-controls/translations.json +154 -0
- package/examples/choice-controls/uischema.json +575 -0
- package/examples/choice-controls/uischemas.d.mts +2 -0
- package/examples/choice-controls/uischemas.json +16 -0
- package/examples/code-editor/README.md +74 -0
- package/examples/code-editor/data.json +8 -0
- package/examples/code-editor/schema.json +28 -0
- package/examples/code-editor/translations.json +20 -0
- package/examples/code-editor/uischema.json +77 -0
- package/examples/collection-pagination/README.md +5 -0
- package/examples/collection-pagination/config.json +1 -0
- package/examples/collection-pagination/data.json +64 -0
- package/examples/collection-pagination/schema.json +23 -0
- package/examples/collection-pagination/translations.json +14 -0
- package/examples/collection-pagination/uischema.json +14 -0
- package/examples/color-control/README.md +154 -0
- package/examples/color-control/config.json +7 -0
- package/examples/color-control/data.json +11 -0
- package/examples/color-control/schema.json +61 -0
- package/examples/color-control/translations.json +76 -0
- package/examples/color-control/uischema.json +106 -0
- package/examples/combinators/README.md +223 -0
- package/examples/combinators/config.json +9 -0
- package/examples/combinators/data.json +23 -0
- package/examples/combinators/schema.json +232 -0
- package/examples/combinators/translations.json +178 -0
- package/examples/combinators/uischema.json +158 -0
- package/examples/conditional-fields/README.md +27 -0
- package/examples/conditional-fields/config.json +5 -0
- package/examples/conditional-fields/data.json +7 -0
- package/examples/conditional-fields/schema.json +59 -0
- package/examples/conditional-fields/translations.json +32 -0
- package/examples/conditional-fields/uischema.json +131 -0
- package/examples/container-validation-indicator/README.md +187 -0
- package/examples/container-validation-indicator/config.json +9 -0
- package/examples/container-validation-indicator/data.json +68 -0
- package/examples/container-validation-indicator/schema.json +222 -0
- package/examples/container-validation-indicator/translations.json +120 -0
- package/examples/container-validation-indicator/uischema.json +98 -0
- package/examples/cron-control/README.md +155 -0
- package/examples/cron-control/data.json +15 -0
- package/examples/cron-control/schema.json +72 -0
- package/examples/cron-control/translations.json +80 -0
- package/examples/cron-control/uischema.json +91 -0
- package/examples/destructive-confirmation/README.md +210 -0
- package/examples/destructive-confirmation/config.json +17 -0
- package/examples/destructive-confirmation/data.json +86 -0
- package/examples/destructive-confirmation/schema.json +204 -0
- package/examples/destructive-confirmation/translations.json +112 -0
- package/examples/destructive-confirmation/uischema.json +105 -0
- package/examples/draft-07-metaschema/README.md +11 -0
- package/examples/draft-07-metaschema/config.json +3 -0
- package/examples/draft-07-metaschema/data.json +25 -0
- package/examples/draft-07-metaschema/schema.json +172 -0
- package/examples/draft-07-metaschema/translations.json +10 -0
- package/examples/draft-07-metaschema/uischema.json +14 -0
- package/examples/dynamic-playground/README.md +95 -0
- package/examples/dynamic-playground/config.json +8 -0
- package/examples/dynamic-playground/configuration.json +152 -0
- package/examples/dynamic-playground/data.json +15 -0
- package/examples/dynamic-playground/dynamic-uischema.json +379 -0
- package/examples/dynamic-playground/host.mjs +37 -0
- package/examples/dynamic-playground/schema.json +48 -0
- package/examples/dynamic-playground/translations.json +76 -0
- package/examples/dynamic-playground/uischema.json +36 -0
- package/examples/editor-details/README.md +10 -0
- package/examples/editor-details/data.json +18 -0
- package/examples/editor-details/schema.json +49 -0
- package/examples/editor-details/translations.json +28 -0
- package/examples/editor-details/uischema.json +53 -0
- package/examples/editor-details/uischemas.d.mts +2 -0
- package/examples/editor-details/uischemas.json +14 -0
- package/examples/file-control/README.md +108 -0
- package/examples/file-control/data.json +28 -0
- package/examples/file-control/schema.json +89 -0
- package/examples/file-control/translations.json +46 -0
- package/examples/file-control/uischema.json +152 -0
- package/examples/group-layout/README.md +149 -0
- package/examples/group-layout/config.json +10 -0
- package/examples/group-layout/data.json +9 -0
- package/examples/group-layout/schema.json +51 -0
- package/examples/group-layout/translations.json +62 -0
- package/examples/group-layout/uischema.json +249 -0
- package/examples/index.d.ts +17 -0
- package/examples/index.js +69 -0
- package/examples/input-adornments/README.md +68 -0
- package/examples/input-adornments/data.json +41 -0
- package/examples/input-adornments/schema.json +207 -0
- package/examples/input-adornments/translations.json +106 -0
- package/examples/input-adornments/uischema.json +695 -0
- package/examples/job-application/README.md +23 -0
- package/examples/job-application/config.json +10 -0
- package/examples/job-application/data.json +68 -0
- package/examples/job-application/schema.json +196 -0
- package/examples/job-application/translations.json +388 -0
- package/examples/job-application/uischema.json +218 -0
- package/examples/job-application/uischemas.json +153 -0
- package/examples/json-editor/README.md +28 -0
- package/examples/json-editor/schema.json +1 -0
- package/examples/json-editor/translations.json +10 -0
- package/examples/json-editor/uischema.json +16 -0
- package/examples/json-inference/README.md +33 -0
- package/examples/json-inference/translations.json +10 -0
- package/examples/json-inference/uischema.json +16 -0
- package/examples/kitchen-sink/README.md +86 -0
- package/examples/kitchen-sink/config.json +14 -0
- package/examples/kitchen-sink/data.json +263 -0
- package/examples/kitchen-sink/invalid-data.json +263 -0
- package/examples/kitchen-sink/schema.json +515 -0
- package/examples/kitchen-sink/translations.json +270 -0
- package/examples/kitchen-sink/uischema.json +722 -0
- package/examples/label-interpolation/README.md +241 -0
- package/examples/label-interpolation/config.json +14 -0
- package/examples/label-interpolation/data.json +13 -0
- package/examples/label-interpolation/schema.json +64 -0
- package/examples/label-interpolation/translations.json +94 -0
- package/examples/label-interpolation/uischema.json +379 -0
- package/examples/layout-sizing/README.md +162 -0
- package/examples/layout-sizing/config.json +10 -0
- package/examples/layout-sizing/data.json +14 -0
- package/examples/layout-sizing/schema.json +58 -0
- package/examples/layout-sizing/translations.json +42 -0
- package/examples/layout-sizing/uischema.json +558 -0
- package/examples/markup-label/README.md +109 -0
- package/examples/markup-label/config.json +16 -0
- package/examples/markup-label/data.json +5 -0
- package/examples/markup-label/schema.json +24 -0
- package/examples/markup-label/translations.json +40 -0
- package/examples/markup-label/uischema.json +149 -0
- package/examples/mixed-control/README.md +164 -0
- package/examples/mixed-control/config.json +11 -0
- package/examples/mixed-control/data.json +70 -0
- package/examples/mixed-control/schema.json +221 -0
- package/examples/mixed-control/translations.json +158 -0
- package/examples/mixed-control/uischema.json +211 -0
- package/examples/null-control/README.md +111 -0
- package/examples/null-control/config.json +4 -0
- package/examples/null-control/data.json +6 -0
- package/examples/null-control/schema.json +36 -0
- package/examples/null-control/translations.json +42 -0
- package/examples/null-control/uischema.json +56 -0
- package/examples/numeric-controls/README.md +94 -0
- package/examples/numeric-controls/config.json +4 -0
- package/examples/numeric-controls/data.json +8 -0
- package/examples/numeric-controls/schema.json +52 -0
- package/examples/numeric-controls/translations.json +56 -0
- package/examples/numeric-controls/uischema.json +77 -0
- package/examples/object-control/README.md +220 -0
- package/examples/object-control/config.json +4 -0
- package/examples/object-control/data.json +62 -0
- package/examples/object-control/schema.json +252 -0
- package/examples/object-control/translations.json +160 -0
- package/examples/object-control/uischema.json +275 -0
- package/examples/object-control/uischemas.d.mts +2 -0
- package/examples/object-control/uischemas.json +59 -0
- package/examples/password-control/README.md +119 -0
- package/examples/password-control/config.json +3 -0
- package/examples/password-control/data.json +18 -0
- package/examples/password-control/schema.json +65 -0
- package/examples/password-control/translations.json +64 -0
- package/examples/password-control/uischema.json +94 -0
- package/examples/pre-touch-errors/README.md +176 -0
- package/examples/pre-touch-errors/config.json +4 -0
- package/examples/pre-touch-errors/data.json +5 -0
- package/examples/pre-touch-errors/schema.json +56 -0
- package/examples/pre-touch-errors/translations.json +68 -0
- package/examples/pre-touch-errors/uischema.json +85 -0
- package/examples/presentation/README.md +148 -0
- package/examples/presentation/config.json +9 -0
- package/examples/presentation/data.json +6 -0
- package/examples/presentation/schema.json +21 -0
- package/examples/presentation/translations.json +64 -0
- package/examples/presentation/uischema.json +210 -0
- package/examples/property-pagination/README.md +5 -0
- package/examples/property-pagination/config.json +1 -0
- package/examples/property-pagination/data.json +17 -0
- package/examples/property-pagination/schema.json +14 -0
- package/examples/property-pagination/translations.json +10 -0
- package/examples/property-pagination/uischema.json +24 -0
- package/examples/recursive-tree/README.md +49 -0
- package/examples/recursive-tree/config.json +1 -0
- package/examples/recursive-tree/data.json +40 -0
- package/examples/recursive-tree/schema.json +89 -0
- package/examples/recursive-tree/translations.json +42 -0
- package/examples/recursive-tree/uischema.json +84 -0
- package/examples/recursive-tree/uischemas.d.mts +2 -0
- package/examples/recursive-tree/uischemas.json +51 -0
- package/examples/split-layout/README.md +123 -0
- package/examples/split-layout/config.json +3 -0
- package/examples/split-layout/data.json +13 -0
- package/examples/split-layout/schema.json +50 -0
- package/examples/split-layout/translations.json +50 -0
- package/examples/split-layout/uischema.json +204 -0
- package/examples/string-controls/README.md +159 -0
- package/examples/string-controls/config.json +5 -0
- package/examples/string-controls/data.json +13 -0
- package/examples/string-controls/schema.json +70 -0
- package/examples/string-controls/translations.json +76 -0
- package/examples/string-controls/uischema.json +148 -0
- package/examples/table-row-details/README.md +69 -0
- package/examples/table-row-details/config.json +7 -0
- package/examples/table-row-details/data.json +280 -0
- package/examples/table-row-details/schema.json +61 -0
- package/examples/table-row-details/translations.json +56 -0
- package/examples/table-row-details/uischema.json +1303 -0
- package/examples/template-layout/README.md +250 -0
- package/examples/template-layout/config.json +9 -0
- package/examples/template-layout/data.json +20 -0
- package/examples/template-layout/host.mjs +13 -0
- package/examples/template-layout/schema.json +48 -0
- package/examples/template-layout/translations.json +70 -0
- package/examples/template-layout/uischema.json +177 -0
- package/examples/template-slots/README.md +19 -0
- package/examples/template-slots/data.json +4 -0
- package/examples/template-slots/schema.json +11 -0
- package/examples/template-slots/translations.json +26 -0
- package/examples/template-slots/uischema.json +47 -0
- package/examples/template-slots/uischemas.d.mts +2 -0
- package/examples/template-slots/uischemas.json +56 -0
- package/examples/temporal-controls/README.md +325 -0
- package/examples/temporal-controls/data.json +44 -0
- package/examples/temporal-controls/schema.json +208 -0
- package/examples/temporal-controls/translations.json +156 -0
- package/examples/temporal-controls/uischema.json +297 -0
- package/examples/tree-max-depth/README.md +5 -0
- package/examples/tree-max-depth/config.json +3 -0
- package/examples/tree-max-depth/data.json +31 -0
- package/examples/tree-max-depth/schema.json +258 -0
- package/examples/tree-max-depth/translations.json +42 -0
- package/examples/tree-max-depth/uischema.json +16 -0
- package/examples/tree-max-depth/uischemas.d.mts +2 -0
- package/examples/tree-max-depth/uischemas.json +50 -0
- package/examples/tuple-control/README.md +335 -0
- package/examples/tuple-control/config.json +4 -0
- package/examples/tuple-control/data.json +61 -0
- package/examples/tuple-control/schema.json +218 -0
- package/examples/tuple-control/translations.json +142 -0
- package/examples/tuple-control/uischema.json +128 -0
- package/examples/tuple-control/uischemas.d.mts +2 -0
- package/examples/tuple-control/uischemas.json +125 -0
- package/examples/validator-profile/README.md +197 -0
- package/examples/validator-profile/config.json +9 -0
- package/examples/validator-profile/data.json +16 -0
- package/examples/validator-profile/schema.json +139 -0
- package/examples/validator-profile/translations.json +34 -0
- package/examples/validator-profile/uischema.json +59 -0
- package/package.json +83 -3
- package/provenance.json +140 -0
- package/schemas/README.md +82 -0
- package/schemas/example.schema.json +37 -0
- package/schemas/jsonforms-config.schema.json +427 -0
- package/schemas/jsonforms-dynamic-uischema.schema.json +220 -0
- package/schemas/jsonforms-extended-config.schema.json +332 -0
- package/schemas/jsonforms-extended-uischema.schema.json +1932 -0
- package/schemas/jsonforms-rule.schema.json +104 -0
- package/schemas/jsonforms-uischema.schema.json +1434 -0
- package/typescript/README.md +546 -0
- package/typescript/lib/authoring/cssLength.d.ts +33 -0
- package/typescript/lib/authoring/cssLength.js +25 -0
- package/typescript/lib/authoring/dynamic.d.ts +73 -0
- package/typescript/lib/authoring/dynamic.js +8 -0
- package/typescript/lib/authoring/forSchema.d.ts +385 -0
- package/typescript/lib/authoring/forSchema.js +84 -0
- package/typescript/lib/authoring/schemaTypes.d.ts +111 -0
- package/typescript/lib/authoring/schemaTypes.js +15 -0
- package/typescript/lib/index.d.ts +4 -0
- package/typescript/lib/index.js +20 -0
- package/typescript/package.json +1 -0
- package/typescript/src/authoring/cssLength.ts +79 -0
- package/typescript/src/authoring/dynamic.ts +96 -0
- package/typescript/src/authoring/forSchema.ts +428 -0
- package/typescript/src/authoring/schemaTypes.ts +143 -0
- package/typescript/src/index.ts +4 -0
- package/typescript/test/schemaContract.test.ts +638 -0
- package/typescript/test/tsconfig.json +10 -0
- package/typescript/test/typedAuthoring.test.ts +151 -0
- package/typescript/test/typedAuthoringCoverage.test.ts +178 -0
- package/typescript/test/typedAuthoringCssLength.test.ts +81 -0
- package/typescript/test/typedAuthoringNames.test.ts +90 -0
- package/typescript/test/typedDynamic.test.ts +88 -0
- package/typescript/tsconfig.json +15 -0
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
|
|
25
|
+
type AbsoluteUnit = 'px' | 'pt' | 'pc' | 'cm' | 'mm' | 'in' | 'q';
|
|
26
|
+
type FontRelativeUnit =
|
|
27
|
+
| 'em'
|
|
28
|
+
| 'rem'
|
|
29
|
+
| 'ex'
|
|
30
|
+
| 'ch'
|
|
31
|
+
| 'cap'
|
|
32
|
+
| 'ic'
|
|
33
|
+
| 'lh'
|
|
34
|
+
| 'rlh';
|
|
35
|
+
type ViewportUnit =
|
|
36
|
+
| 'vw'
|
|
37
|
+
| 'vh'
|
|
38
|
+
| 'vmin'
|
|
39
|
+
| 'vmax'
|
|
40
|
+
| 'vi'
|
|
41
|
+
| 'vb'
|
|
42
|
+
| 'svw'
|
|
43
|
+
| 'svh'
|
|
44
|
+
| 'lvw'
|
|
45
|
+
| 'lvh'
|
|
46
|
+
| 'dvw'
|
|
47
|
+
| 'dvh';
|
|
48
|
+
|
|
49
|
+
export type CssUnit = AbsoluteUnit | FontRelativeUnit | ViewportUnit | '%';
|
|
50
|
+
|
|
51
|
+
/** Sizing keywords, plus the CSS-wide ones any property accepts. */
|
|
52
|
+
export type CssKeyword =
|
|
53
|
+
| 'auto'
|
|
54
|
+
| 'none'
|
|
55
|
+
| 'min-content'
|
|
56
|
+
| 'max-content'
|
|
57
|
+
| 'fit-content'
|
|
58
|
+
| 'stretch'
|
|
59
|
+
| 'inherit'
|
|
60
|
+
| 'initial'
|
|
61
|
+
| 'revert'
|
|
62
|
+
| 'unset';
|
|
63
|
+
|
|
64
|
+
export type CssFunction =
|
|
65
|
+
| `calc(${string})`
|
|
66
|
+
| `min(${string})`
|
|
67
|
+
| `max(${string})`
|
|
68
|
+
| `clamp(${string})`
|
|
69
|
+
| `fit-content(${string})`
|
|
70
|
+
| `var(${string})`;
|
|
71
|
+
|
|
72
|
+
/** A bare number is CSS pixels, which is what `toCss` does with it. */
|
|
73
|
+
export type CssLength =
|
|
74
|
+
| number
|
|
75
|
+
| `${number}${CssUnit}`
|
|
76
|
+
/* `0` is a valid length on its own, and the only unitless one. */
|
|
77
|
+
| '0'
|
|
78
|
+
| CssKeyword
|
|
79
|
+
| CssFunction;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Portable JSON leaves. Functions belong only to the explicitly trusted profile. */
|
|
2
|
+
export type DynamicJson =
|
|
3
|
+
| null
|
|
4
|
+
| boolean
|
|
5
|
+
| number
|
|
6
|
+
| string
|
|
7
|
+
| readonly DynamicJson[]
|
|
8
|
+
| { readonly [key: string]: DynamicJson };
|
|
9
|
+
|
|
10
|
+
export type DynamicDescriptor<T = DynamicJson> =
|
|
11
|
+
| { readonly bind: string }
|
|
12
|
+
| { readonly expression: string }
|
|
13
|
+
| (string extends T ? { readonly template: string } : never)
|
|
14
|
+
| { readonly literal: T };
|
|
15
|
+
|
|
16
|
+
/** Extension values remain portable; unknown keys do not admit executable code. */
|
|
17
|
+
export type DynamicExtension =
|
|
18
|
+
| DynamicJson
|
|
19
|
+
| undefined
|
|
20
|
+
| { readonly [key: string]: DynamicExtension }
|
|
21
|
+
| readonly DynamicExtension[];
|
|
22
|
+
|
|
23
|
+
/** Array replacements contain complete entries, not partial object patches. */
|
|
24
|
+
export type DynamicArrayEntry<T> =
|
|
25
|
+
| DynamicDescriptor<T>
|
|
26
|
+
| (T extends readonly (infer Item)[]
|
|
27
|
+
? readonly DynamicArrayEntry<Item>[]
|
|
28
|
+
: T extends object
|
|
29
|
+
? { readonly [K in keyof T]: DynamicArrayEntry<T[K]> }
|
|
30
|
+
: T);
|
|
31
|
+
|
|
32
|
+
export type DynamicValue<T> =
|
|
33
|
+
| T
|
|
34
|
+
| DynamicDescriptor<T>
|
|
35
|
+
| (T extends readonly (infer Item)[]
|
|
36
|
+
? readonly DynamicArrayEntry<Item>[]
|
|
37
|
+
: T extends object
|
|
38
|
+
? { readonly [K in keyof T]?: DynamicValue<T[K]> } & { readonly [extension: string]: DynamicExtension }
|
|
39
|
+
: never);
|
|
40
|
+
|
|
41
|
+
/** Known fields retain their types; adapters may forward unknown extension fields. */
|
|
42
|
+
export type DynamicOverlay<T> = {
|
|
43
|
+
readonly [K in keyof T as K extends '$dynamic' ? never : K]?: DynamicValue<T[K]>;
|
|
44
|
+
} & { readonly $dynamic?: never; readonly [extension: string]: DynamicExtension };
|
|
45
|
+
|
|
46
|
+
export type DynamicRule<T> = {
|
|
47
|
+
readonly when?: boolean | { readonly expression: string };
|
|
48
|
+
readonly overlay: DynamicOverlay<T>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type DynamicSpec<T> = DynamicOverlay<T> | readonly DynamicRule<T>[];
|
|
52
|
+
|
|
53
|
+
/** Type and scope may select a different renderer, so overlays may change them. */
|
|
54
|
+
export type DynamicTarget<T> = Omit<T, 'type' | 'scope' | '$dynamic'> & {
|
|
55
|
+
type: string;
|
|
56
|
+
scope?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type TrustedDynamicFunction<T> = (environment: Readonly<Record<string, unknown>>) => T;
|
|
60
|
+
export type TrustedDynamicArrayEntry<T> =
|
|
61
|
+
| DynamicDescriptor<T>
|
|
62
|
+
| TrustedDynamicFunction<T>
|
|
63
|
+
| (T extends readonly (infer Item)[]
|
|
64
|
+
? readonly TrustedDynamicArrayEntry<Item>[]
|
|
65
|
+
: T extends object
|
|
66
|
+
? { readonly [K in keyof T]: TrustedDynamicArrayEntry<T[K]> }
|
|
67
|
+
: T);
|
|
68
|
+
export type TrustedDynamicValue<T> =
|
|
69
|
+
| DynamicValue<T>
|
|
70
|
+
| TrustedDynamicFunction<T>
|
|
71
|
+
| (T extends readonly (infer Item)[]
|
|
72
|
+
? readonly TrustedDynamicArrayEntry<Item>[]
|
|
73
|
+
: T extends object
|
|
74
|
+
? { readonly [K in keyof T]?: TrustedDynamicValue<T[K]> } & { readonly [extension: string]: unknown }
|
|
75
|
+
: never);
|
|
76
|
+
|
|
77
|
+
export type TrustedDynamicOverlay<T> = {
|
|
78
|
+
readonly [K in keyof T as K extends '$dynamic' ? never : K]?: TrustedDynamicValue<T[K]>;
|
|
79
|
+
} & { readonly $dynamic?: never; readonly [extension: string]: unknown };
|
|
80
|
+
|
|
81
|
+
export type TrustedDynamicRule<T> = {
|
|
82
|
+
readonly when?: boolean | { readonly expression: string } | TrustedDynamicFunction<boolean>;
|
|
83
|
+
readonly overlay: TrustedDynamicOverlay<T>;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type TrustedDynamicSpec<T> =
|
|
87
|
+
| TrustedDynamicOverlay<T>
|
|
88
|
+
| readonly TrustedDynamicRule<T>[];
|
|
89
|
+
|
|
90
|
+
/** Opt into trusted authoring explicitly without weakening portable form helpers. */
|
|
91
|
+
export function withTrustedDynamic<T extends { type: string }>(
|
|
92
|
+
element: T,
|
|
93
|
+
dynamic: TrustedDynamicSpec<DynamicTarget<T>>,
|
|
94
|
+
): Omit<T, '$dynamic'> & { $dynamic: TrustedDynamicSpec<DynamicTarget<T>> } {
|
|
95
|
+
return { ...element, $dynamic: dynamic };
|
|
96
|
+
}
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import type { JsonSchema, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
import type { CssLength } from './cssLength';
|
|
3
|
+
import type { DataPath, Scope, SchemaAtPath } from './schemaTypes';
|
|
4
|
+
import type { DynamicSpec, DynamicTarget } from './dynamic';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Authoring a UI schema against the JSON Schema it is bound to.
|
|
8
|
+
*
|
|
9
|
+
* The elements produced are ordinary portable UI-model objects - `type:
|
|
10
|
+
* 'Control'` with a `scope`, options under `options`. Nothing about the
|
|
11
|
+
* runtime changes; the types exist to make a wrong `scope` or a
|
|
12
|
+
* misapplied option a compile error instead of a control that silently
|
|
13
|
+
* renders nothing.
|
|
14
|
+
*
|
|
15
|
+
* See `typescript/README.md` for what this does and does not catch.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* DEFAULT leaves array presentation to renderer selection. GENERATE bypasses
|
|
20
|
+
* the registry. Other strings, including REGISTERED and GENERATED, consult it.
|
|
21
|
+
* Comparisons are case-insensitive, matching JSON Forms core.
|
|
22
|
+
*/
|
|
23
|
+
export type EditorDetail = string | UISchemaElement | { elements: UISchemaElement[] };
|
|
24
|
+
export type ArrayDetail = EditorDetail;
|
|
25
|
+
|
|
26
|
+
/** Options every control understands, whatever it is bound to. */
|
|
27
|
+
/** Selectable-card presentation; content is presentation-only UI schema. */
|
|
28
|
+
export type CardChoice = ({ value: unknown; branch?: never } | { branch: number; value?: never }) & {
|
|
29
|
+
label?: string;
|
|
30
|
+
i18n?: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
content?: UISchemaElement;
|
|
33
|
+
selectedContent?: UISchemaElement;
|
|
34
|
+
detail?: EditorDetail;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type InputAdornment =
|
|
38
|
+
| { kind: 'text'; text: string; i18n?: string; tooltip?: string }
|
|
39
|
+
| { kind: 'icon'; icon: string; label: string; i18n?: string; tooltip?: string; decorative?: false }
|
|
40
|
+
| { kind: 'icon'; icon: string; decorative: true; label?: never; i18n?: never; tooltip?: never };
|
|
41
|
+
export type InputAdornmentValue = string | InputAdornment | InputAdornment[];
|
|
42
|
+
|
|
43
|
+
export interface CommonControlOptions {
|
|
44
|
+
/** Host styling names; HTML layout-slot marker, optional on non-HTML platforms. */
|
|
45
|
+
part?: string;
|
|
46
|
+
/** Provisional portable input-edge content; support depends on the renderer variant. */
|
|
47
|
+
startAdornment?: InputAdornmentValue;
|
|
48
|
+
endAdornment?: InputAdornmentValue;
|
|
49
|
+
/** Opt in to conditional object field discovery; local false overrides config. */
|
|
50
|
+
conditionalFields?: boolean;
|
|
51
|
+
/** Editor layout or upstream detail-resolution mode. */
|
|
52
|
+
detail?: EditorDetail;
|
|
53
|
+
'object-detail'?: EditorDetail;
|
|
54
|
+
'array-detail'?: EditorDetail;
|
|
55
|
+
'string-detail'?: EditorDetail;
|
|
56
|
+
'number-detail'?: EditorDetail;
|
|
57
|
+
'integer-detail'?: EditorDetail;
|
|
58
|
+
'boolean-detail'?: EditorDetail;
|
|
59
|
+
'null-detail'?: EditorDetail;
|
|
60
|
+
/** Navigate recursive nodes through a tree and selected-node editor. */
|
|
61
|
+
recursiveTree?: {
|
|
62
|
+
childrenProperty: string;
|
|
63
|
+
labelProperty: string;
|
|
64
|
+
detail?: EditorDetail;
|
|
65
|
+
};
|
|
66
|
+
/** Mixed value presentation; defaults to tree. Code requires Monaco support. */
|
|
67
|
+
structuredLayout?: 'tree' | 'nested' | 'code';
|
|
68
|
+
validateActiveBranch?: boolean;
|
|
69
|
+
format?: string;
|
|
70
|
+
choices?: CardChoice[];
|
|
71
|
+
showRadio?: boolean;
|
|
72
|
+
dialog?: DetailDialogOptions;
|
|
73
|
+
readonly?: boolean;
|
|
74
|
+
focus?: boolean;
|
|
75
|
+
hideRequiredAsterisk?: boolean;
|
|
76
|
+
showUnfocusedDescription?: boolean;
|
|
77
|
+
clearable?: boolean;
|
|
78
|
+
placeholder?: string;
|
|
79
|
+
/**
|
|
80
|
+
* How this child participates in its parent layout.
|
|
81
|
+
*
|
|
82
|
+
* The names are the ones `itemSizing` actually reads - `minWidth` and
|
|
83
|
+
* friends, **not** `min`/`max`. An earlier draft of this type had the
|
|
84
|
+
* short forms, which are read by nothing: they would have type-approved a
|
|
85
|
+
* dead option while rejecting the one that works.
|
|
86
|
+
*/
|
|
87
|
+
layout?: {
|
|
88
|
+
span?: number;
|
|
89
|
+
weight?: number;
|
|
90
|
+
width?: CssLength;
|
|
91
|
+
minWidth?: CssLength;
|
|
92
|
+
maxWidth?: CssLength;
|
|
93
|
+
height?: CssLength;
|
|
94
|
+
minHeight?: CssLength;
|
|
95
|
+
maxHeight?: CssLength;
|
|
96
|
+
/** Reserved by the specification; accepted and ignored. */
|
|
97
|
+
start?: number;
|
|
98
|
+
/** Reserved by the specification; accepted and ignored. */
|
|
99
|
+
responsive?: unknown;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options admissible for the schema a control is bound to.
|
|
105
|
+
*
|
|
106
|
+
* **A curated subset, on purpose.** It covers the options these renderers
|
|
107
|
+
* read for each schema kind; it is not generated from the published JSON
|
|
108
|
+
* Schemas and will lag them. Adding one is a line here.
|
|
109
|
+
*
|
|
110
|
+
* An option this map does not know is still reachable, because excess
|
|
111
|
+
* property checking only applies to a *fresh object literal*: assign the
|
|
112
|
+
* options to a variable first and TypeScript stops checking the extra keys.
|
|
113
|
+
* That is the documented escape hatch, and it is the same rule that makes
|
|
114
|
+
* a separately-built element unchecked - see the limits in the guide.
|
|
115
|
+
*/
|
|
116
|
+
export type PaginationOptions = boolean | {
|
|
117
|
+
pageSize?: number;
|
|
118
|
+
pageSizeOptions?: number[];
|
|
119
|
+
};
|
|
120
|
+
export type DetailDialogOptions = {
|
|
121
|
+
width?: number | string;
|
|
122
|
+
height?: number | string;
|
|
123
|
+
maximizable?: boolean;
|
|
124
|
+
draggable?: boolean;
|
|
125
|
+
resizable?: boolean;
|
|
126
|
+
};
|
|
127
|
+
export type RowDetailOptions =
|
|
128
|
+
| { presentation: 'dialog'; dialog?: DetailDialogOptions; detail?: EditorDetail; placement?: never; resizable?: never; collapsed?: never }
|
|
129
|
+
| { presentation: 'panel'; detail?: EditorDetail; placement?: 'right' | 'bottom'; resizable?: boolean; collapsed?: boolean };
|
|
130
|
+
|
|
131
|
+
export type OptionsFor<Sub> = CommonControlOptions &
|
|
132
|
+
(Sub extends { type: 'number' | 'integer' }
|
|
133
|
+
? { slider?: boolean; step?: number; toggle?: never }
|
|
134
|
+
: Sub extends { type: 'string' }
|
|
135
|
+
? {
|
|
136
|
+
multi?: boolean;
|
|
137
|
+
variant?: 'otp';
|
|
138
|
+
vertical?: boolean;
|
|
139
|
+
format?: string;
|
|
140
|
+
mask?: string;
|
|
141
|
+
returnMaskedValue?: boolean;
|
|
142
|
+
language?: string;
|
|
143
|
+
propagateErrors?: boolean;
|
|
144
|
+
monaco?: Record<string, unknown>;
|
|
145
|
+
slider?: never;
|
|
146
|
+
}
|
|
147
|
+
: Sub extends { type: 'array' }
|
|
148
|
+
? {
|
|
149
|
+
collapsible?: boolean;
|
|
150
|
+
collapsed?: boolean;
|
|
151
|
+
table?: boolean;
|
|
152
|
+
columnDefs?: { field: string; scope?: '#'; headerName?: string; width?: number; minWidth?: number; maxWidth?: number }[];
|
|
153
|
+
pagination?: PaginationOptions;
|
|
154
|
+
additionalItems?: { pagination?: PaginationOptions };
|
|
155
|
+
rowDetail?: RowDetailOptions;
|
|
156
|
+
variant?: 'ag-grid' | 'tuple' | 'chips' | 'multi-select';
|
|
157
|
+
showSortButtons?: boolean;
|
|
158
|
+
restrict?: boolean;
|
|
159
|
+
detail?: ArrayDetail;
|
|
160
|
+
cells?: Record<string, unknown>;
|
|
161
|
+
}
|
|
162
|
+
: Sub extends { type: 'object' }
|
|
163
|
+
? { additionalProperties?: { pagination?: PaginationOptions } }
|
|
164
|
+
: Sub extends { type: 'boolean' }
|
|
165
|
+
? { toggle?: boolean; slider?: never }
|
|
166
|
+
: Record<string, unknown>);
|
|
167
|
+
|
|
168
|
+
export type RuleEffect = 'HIDE' | 'SHOW' | 'ENABLE' | 'DISABLE';
|
|
169
|
+
|
|
170
|
+
/** A leaf condition: one scope, one schema to test the value against. */
|
|
171
|
+
export interface TypedLeafCondition<S> {
|
|
172
|
+
scope: Scope<(DataPath<S> & string) | ''>;
|
|
173
|
+
schema: Record<string, unknown>;
|
|
174
|
+
failWhenUndefined?: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The composite forms core supports, so a rule is not limited to one test. */
|
|
178
|
+
export interface TypedComposedCondition<S> {
|
|
179
|
+
type: 'AND' | 'OR';
|
|
180
|
+
conditions: TypedCondition<S>[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type TypedCondition<S> =
|
|
184
|
+
| TypedLeafCondition<S>
|
|
185
|
+
| TypedComposedCondition<S>;
|
|
186
|
+
|
|
187
|
+
export interface TypedRule<S> {
|
|
188
|
+
effect: RuleEffect;
|
|
189
|
+
condition: TypedCondition<S>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** `label` is not only a string: core also accepts a descriptor. */
|
|
193
|
+
export type TypedLabelDescriptor = { text?: string; show?: boolean };
|
|
194
|
+
|
|
195
|
+
/** Every path a control may bind to, including `''` for the root. */
|
|
196
|
+
export type ControlPath<S> = (DataPath<S> & string) | '';
|
|
197
|
+
|
|
198
|
+
export interface TypedControl<S, P extends ControlPath<S> = ControlPath<S>> {
|
|
199
|
+
type: 'Control';
|
|
200
|
+
scope: Scope<P>;
|
|
201
|
+
label?: string | boolean | TypedLabelDescriptor;
|
|
202
|
+
/** Translation-key prefix for this element, per core's i18n precedence. */
|
|
203
|
+
i18n?: string;
|
|
204
|
+
options?: OptionsFor<SchemaAtPath<S, P>>;
|
|
205
|
+
rule?: TypedRule<S>;
|
|
206
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedControl<S, P>>>;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** An unbound label element. */
|
|
210
|
+
export interface TypedLabelElement<S> {
|
|
211
|
+
type: 'Label';
|
|
212
|
+
text?: string;
|
|
213
|
+
i18n?: string;
|
|
214
|
+
options?: Record<string, unknown> & {
|
|
215
|
+
/** Override the host default for named substitution markers; omit to inherit. */
|
|
216
|
+
textParamSpans?: boolean;
|
|
217
|
+
};
|
|
218
|
+
rule?: TypedRule<S>;
|
|
219
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedLabelElement<S>>>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** One tab or step of a `Categorization`. */
|
|
223
|
+
export interface TypedCategory<S> {
|
|
224
|
+
type: 'Category';
|
|
225
|
+
label?: string;
|
|
226
|
+
i18n?: string;
|
|
227
|
+
elements: TypedElement<S>[];
|
|
228
|
+
options?: Record<string, unknown>;
|
|
229
|
+
rule?: TypedRule<S>;
|
|
230
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedCategory<S>>>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface TypedLayout<S> {
|
|
234
|
+
type: 'VerticalLayout' | 'HorizontalLayout' | 'Group' | 'Categorization';
|
|
235
|
+
label?: string;
|
|
236
|
+
i18n?: string;
|
|
237
|
+
/** Group's prominent media, dispatched before its heading. */
|
|
238
|
+
cover?: TypedElement<S>;
|
|
239
|
+
/** Group's supplemental heading content, outside the disclosure trigger. */
|
|
240
|
+
header?: TypedElement<S>[];
|
|
241
|
+
/** Group's content after its body; may contain any supported elements. */
|
|
242
|
+
footer?: TypedElement<S>[];
|
|
243
|
+
elements: (TypedElement<S> | TypedCategory<S>)[];
|
|
244
|
+
options?: {
|
|
245
|
+
/** Own conditional object presentation for this layout subtree. */
|
|
246
|
+
conditionalFields?: boolean;
|
|
247
|
+
/** Host styling names on this element's slot in its parent layout. */
|
|
248
|
+
part?: string;
|
|
249
|
+
gap?: CssLength;
|
|
250
|
+
wrap?: boolean;
|
|
251
|
+
minItemWidth?: CssLength;
|
|
252
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
253
|
+
justify?:
|
|
254
|
+
| 'start'
|
|
255
|
+
| 'center'
|
|
256
|
+
| 'end'
|
|
257
|
+
| 'space-between'
|
|
258
|
+
| 'space-around'
|
|
259
|
+
| 'space-evenly';
|
|
260
|
+
resizable?: boolean;
|
|
261
|
+
/** Horizontal layouts only. */
|
|
262
|
+
gridColumns?: number;
|
|
263
|
+
collapsible?: boolean;
|
|
264
|
+
collapsed?: boolean;
|
|
265
|
+
showDataIndicator?: boolean;
|
|
266
|
+
showValidationIndicator?: boolean;
|
|
267
|
+
};
|
|
268
|
+
rule?: TypedRule<S>;
|
|
269
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedLayout<S>>>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Anything this module does not model, passed through unchecked.
|
|
274
|
+
*
|
|
275
|
+
* The escape hatch, and deliberately a **named** one: the alternative is a
|
|
276
|
+
* permissive member of the element union, which would silently accept a
|
|
277
|
+
* mistyped `Control` as well. Written as `f.raw({ … })` it is greppable, and
|
|
278
|
+
* the loss of checking is visible at the point where it happens rather than
|
|
279
|
+
* inferred from an element that quietly matched something else.
|
|
280
|
+
*/
|
|
281
|
+
export interface RawElement {
|
|
282
|
+
type: string;
|
|
283
|
+
[key: string]: unknown;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export type TypedElement<S> =
|
|
287
|
+
| TypedControl<S>
|
|
288
|
+
| TypedLayout<S>
|
|
289
|
+
| TypedLabelElement<S>
|
|
290
|
+
| RawElement;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* `address.city` -> `#/properties/address/properties/city`.
|
|
294
|
+
*
|
|
295
|
+
* Takes a plain `string`: with `S` still generic TypeScript cannot see that
|
|
296
|
+
* `P` is one, so the work happens here and the literal type is reapplied at
|
|
297
|
+
* the boundary. The cast is the only thing tying this expression to
|
|
298
|
+
* `Scope<P>`, which is why `typedAuthoring.test.ts` asserts that the two
|
|
299
|
+
* agree on concrete paths.
|
|
300
|
+
*/
|
|
301
|
+
const toPointer = (path: string): string =>
|
|
302
|
+
path === ''
|
|
303
|
+
? '#'
|
|
304
|
+
: `#/properties/${path
|
|
305
|
+
.split('.')
|
|
306
|
+
/*
|
|
307
|
+
RFC 6901 escaping, per segment, exactly as core's own `getPropPath`
|
|
308
|
+
does it: `/` and `~` have meaning inside a pointer, so a property
|
|
309
|
+
called `a/b` is addressed as `a~1b`. Core `decode`s them on the way
|
|
310
|
+
back, so leaving them raw produces a pointer that silently resolves
|
|
311
|
+
to nothing.
|
|
312
|
+
*/
|
|
313
|
+
.map((segment) => segment.replace(/~/g, '~0').replace(/\//g, '~1'))
|
|
314
|
+
.join('/properties/')}`;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Binds the authoring helpers to one schema.
|
|
318
|
+
*
|
|
319
|
+
* ```ts
|
|
320
|
+
* const schema = { … } as const;
|
|
321
|
+
* const f = forSchema(schema);
|
|
322
|
+
* f.control('address.city'); // '#/properties/address/properties/city'
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* The schema argument is used for **inference only** and is never read, so
|
|
326
|
+
* the helpers cost nothing at runtime beyond the string join.
|
|
327
|
+
*/
|
|
328
|
+
export const forSchema = <S>(_schema: S) => ({
|
|
329
|
+
/** The JSON Pointer for a path, as a literal type. `''` is the root. */
|
|
330
|
+
scope: <P extends ControlPath<S>>(path: P): Scope<P> =>
|
|
331
|
+
toPointer(path) as Scope<P>,
|
|
332
|
+
|
|
333
|
+
/** A `Control` bound to a path, with options checked against its schema. */
|
|
334
|
+
control: <P extends ControlPath<S>>(
|
|
335
|
+
path: P,
|
|
336
|
+
rest?: Omit<TypedControl<S, P>, 'type' | 'scope'>
|
|
337
|
+
): TypedControl<S, P> =>
|
|
338
|
+
({
|
|
339
|
+
type: 'Control',
|
|
340
|
+
scope: toPointer(path) as Scope<P>,
|
|
341
|
+
...rest,
|
|
342
|
+
} as TypedControl<S, P>),
|
|
343
|
+
|
|
344
|
+
/** Identity, for the inference: it fixes `S` for every nested element. */
|
|
345
|
+
layout: (layout: TypedLayout<S>): TypedLayout<S> => layout,
|
|
346
|
+
|
|
347
|
+
/** One tab or step of a `Categorization`. */
|
|
348
|
+
category: (category: Omit<TypedCategory<S>, 'type'>): TypedCategory<S> => ({
|
|
349
|
+
type: 'Category',
|
|
350
|
+
...category,
|
|
351
|
+
}),
|
|
352
|
+
|
|
353
|
+
/** An unbound label. */
|
|
354
|
+
label: (label: Omit<TypedLabelElement<S>, 'type'>): TypedLabelElement<S> => ({
|
|
355
|
+
type: 'Label',
|
|
356
|
+
...label,
|
|
357
|
+
}),
|
|
358
|
+
|
|
359
|
+
/** Identity, so a rule written on its own is still checked. */
|
|
360
|
+
rule: (rule: TypedRule<S>): TypedRule<S> => rule,
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Anything this module does not model - an extended element, an option it
|
|
364
|
+
* does not carry, a layout from another family. Unchecked by design; see
|
|
365
|
+
* `typescript/README.md`.
|
|
366
|
+
*/
|
|
367
|
+
raw: <T extends RawElement>(element: T): T => element,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// ------------------------------------------------------------ the boundary
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* A deeply readonly view of a type.
|
|
374
|
+
*
|
|
375
|
+
* `as const` freezes arrays into `readonly` tuples, and `JsonSchema`'s
|
|
376
|
+
* `required` is a mutable `string[]`, so `… as const satisfies JsonSchema`
|
|
377
|
+
* is rejected on any schema that has a `required` - which is most of them.
|
|
378
|
+
* The constraint has to admit readonly to be usable at all.
|
|
379
|
+
*/
|
|
380
|
+
export type ReadonlyDeep<T> = T extends (infer E)[]
|
|
381
|
+
? readonly ReadonlyDeep<E>[]
|
|
382
|
+
: T extends readonly (infer E)[]
|
|
383
|
+
? readonly ReadonlyDeep<E>[]
|
|
384
|
+
: T extends object
|
|
385
|
+
? { readonly [K in keyof T]: ReadonlyDeep<T[K]> }
|
|
386
|
+
: T;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* What to `satisfies` an authored schema against.
|
|
390
|
+
*
|
|
391
|
+
* ```ts
|
|
392
|
+
* const schema = { … } as const satisfies AuthoredSchema;
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* Keeps the literal inference the rest of this module needs, and still
|
|
396
|
+
* checks that what was written is a JSON Schema.
|
|
397
|
+
*/
|
|
398
|
+
export type AuthoredSchema = ReadonlyDeep<JsonSchema> & {
|
|
399
|
+
/*
|
|
400
|
+
JSON Schema is open: an unknown keyword is legal and ignored, which is
|
|
401
|
+
also how this project's Ajv is configured (`strictSchema: false`). The
|
|
402
|
+
index signature is what admits them - `$defs` above all, which
|
|
403
|
+
`JsonSchema7` does not declare because draft-07 spells it `definitions`.
|
|
404
|
+
Without it, `satisfies` rejects most real schemas.
|
|
405
|
+
|
|
406
|
+
The cost is that a misspelled keyword is accepted here too, exactly as
|
|
407
|
+
it would be at runtime.
|
|
408
|
+
*/
|
|
409
|
+
readonly [keyword: string]: unknown;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Hands an authored schema to `<JsonForms>`.
|
|
414
|
+
*
|
|
415
|
+
* The cast is through `unknown` because `as const` makes every array
|
|
416
|
+
* readonly and `JsonSchema` wants mutable ones - the two do not overlap in
|
|
417
|
+
* TypeScript's view, though the value is a perfectly good schema. It is
|
|
418
|
+
* widening, so it happens **after** every check in this module has run, and
|
|
419
|
+
* it is here rather than at each call site so there is one place to look.
|
|
420
|
+
*
|
|
421
|
+
* JSON Forms does not mutate the schema it is given.
|
|
422
|
+
*/
|
|
423
|
+
export const asJsonSchema = (schema: unknown): JsonSchema =>
|
|
424
|
+
schema as JsonSchema;
|
|
425
|
+
|
|
426
|
+
/** The same, for a UI schema built by {@link forSchema}. */
|
|
427
|
+
export const asUiSchema = (uischema: unknown): UISchemaElement =>
|
|
428
|
+
uischema as UISchemaElement;
|