@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,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;
|
|
@@ -0,0 +1,385 @@
|
|
|
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
|
+
* Authoring a UI schema against the JSON Schema it is bound to.
|
|
7
|
+
*
|
|
8
|
+
* The elements produced are ordinary portable UI-model objects - `type:
|
|
9
|
+
* 'Control'` with a `scope`, options under `options`. Nothing about the
|
|
10
|
+
* runtime changes; the types exist to make a wrong `scope` or a
|
|
11
|
+
* misapplied option a compile error instead of a control that silently
|
|
12
|
+
* renders nothing.
|
|
13
|
+
*
|
|
14
|
+
* See `typescript/README.md` for what this does and does not catch.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* DEFAULT leaves array presentation to renderer selection. GENERATE bypasses
|
|
18
|
+
* the registry. Other strings, including REGISTERED and GENERATED, consult it.
|
|
19
|
+
* Comparisons are case-insensitive, matching JSON Forms core.
|
|
20
|
+
*/
|
|
21
|
+
export type EditorDetail = string | UISchemaElement | {
|
|
22
|
+
elements: UISchemaElement[];
|
|
23
|
+
};
|
|
24
|
+
export type ArrayDetail = EditorDetail;
|
|
25
|
+
/** Options every control understands, whatever it is bound to. */
|
|
26
|
+
/** Selectable-card presentation; content is presentation-only UI schema. */
|
|
27
|
+
export type CardChoice = ({
|
|
28
|
+
value: unknown;
|
|
29
|
+
branch?: never;
|
|
30
|
+
} | {
|
|
31
|
+
branch: number;
|
|
32
|
+
value?: never;
|
|
33
|
+
}) & {
|
|
34
|
+
label?: string;
|
|
35
|
+
i18n?: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
content?: UISchemaElement;
|
|
38
|
+
selectedContent?: UISchemaElement;
|
|
39
|
+
detail?: EditorDetail;
|
|
40
|
+
};
|
|
41
|
+
export type InputAdornment = {
|
|
42
|
+
kind: 'text';
|
|
43
|
+
text: string;
|
|
44
|
+
i18n?: string;
|
|
45
|
+
tooltip?: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'icon';
|
|
48
|
+
icon: string;
|
|
49
|
+
label: string;
|
|
50
|
+
i18n?: string;
|
|
51
|
+
tooltip?: string;
|
|
52
|
+
decorative?: false;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'icon';
|
|
55
|
+
icon: string;
|
|
56
|
+
decorative: true;
|
|
57
|
+
label?: never;
|
|
58
|
+
i18n?: never;
|
|
59
|
+
tooltip?: never;
|
|
60
|
+
};
|
|
61
|
+
export type InputAdornmentValue = string | InputAdornment | InputAdornment[];
|
|
62
|
+
export interface CommonControlOptions {
|
|
63
|
+
/** Host styling names; HTML layout-slot marker, optional on non-HTML platforms. */
|
|
64
|
+
part?: string;
|
|
65
|
+
/** Provisional portable input-edge content; support depends on the renderer variant. */
|
|
66
|
+
startAdornment?: InputAdornmentValue;
|
|
67
|
+
endAdornment?: InputAdornmentValue;
|
|
68
|
+
/** Opt in to conditional object field discovery; local false overrides config. */
|
|
69
|
+
conditionalFields?: boolean;
|
|
70
|
+
/** Editor layout or upstream detail-resolution mode. */
|
|
71
|
+
detail?: EditorDetail;
|
|
72
|
+
'object-detail'?: EditorDetail;
|
|
73
|
+
'array-detail'?: EditorDetail;
|
|
74
|
+
'string-detail'?: EditorDetail;
|
|
75
|
+
'number-detail'?: EditorDetail;
|
|
76
|
+
'integer-detail'?: EditorDetail;
|
|
77
|
+
'boolean-detail'?: EditorDetail;
|
|
78
|
+
'null-detail'?: EditorDetail;
|
|
79
|
+
/** Navigate recursive nodes through a tree and selected-node editor. */
|
|
80
|
+
recursiveTree?: {
|
|
81
|
+
childrenProperty: string;
|
|
82
|
+
labelProperty: string;
|
|
83
|
+
detail?: EditorDetail;
|
|
84
|
+
};
|
|
85
|
+
/** Mixed value presentation; defaults to tree. Code requires Monaco support. */
|
|
86
|
+
structuredLayout?: 'tree' | 'nested' | 'code';
|
|
87
|
+
validateActiveBranch?: boolean;
|
|
88
|
+
format?: string;
|
|
89
|
+
choices?: CardChoice[];
|
|
90
|
+
showRadio?: boolean;
|
|
91
|
+
dialog?: DetailDialogOptions;
|
|
92
|
+
readonly?: boolean;
|
|
93
|
+
focus?: boolean;
|
|
94
|
+
hideRequiredAsterisk?: boolean;
|
|
95
|
+
showUnfocusedDescription?: boolean;
|
|
96
|
+
clearable?: boolean;
|
|
97
|
+
placeholder?: string;
|
|
98
|
+
/**
|
|
99
|
+
* How this child participates in its parent layout.
|
|
100
|
+
*
|
|
101
|
+
* The names are the ones `itemSizing` actually reads - `minWidth` and
|
|
102
|
+
* friends, **not** `min`/`max`. An earlier draft of this type had the
|
|
103
|
+
* short forms, which are read by nothing: they would have type-approved a
|
|
104
|
+
* dead option while rejecting the one that works.
|
|
105
|
+
*/
|
|
106
|
+
layout?: {
|
|
107
|
+
span?: number;
|
|
108
|
+
weight?: number;
|
|
109
|
+
width?: CssLength;
|
|
110
|
+
minWidth?: CssLength;
|
|
111
|
+
maxWidth?: CssLength;
|
|
112
|
+
height?: CssLength;
|
|
113
|
+
minHeight?: CssLength;
|
|
114
|
+
maxHeight?: CssLength;
|
|
115
|
+
/** Reserved by the specification; accepted and ignored. */
|
|
116
|
+
start?: number;
|
|
117
|
+
/** Reserved by the specification; accepted and ignored. */
|
|
118
|
+
responsive?: unknown;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options admissible for the schema a control is bound to.
|
|
123
|
+
*
|
|
124
|
+
* **A curated subset, on purpose.** It covers the options these renderers
|
|
125
|
+
* read for each schema kind; it is not generated from the published JSON
|
|
126
|
+
* Schemas and will lag them. Adding one is a line here.
|
|
127
|
+
*
|
|
128
|
+
* An option this map does not know is still reachable, because excess
|
|
129
|
+
* property checking only applies to a *fresh object literal*: assign the
|
|
130
|
+
* options to a variable first and TypeScript stops checking the extra keys.
|
|
131
|
+
* That is the documented escape hatch, and it is the same rule that makes
|
|
132
|
+
* a separately-built element unchecked - see the limits in the guide.
|
|
133
|
+
*/
|
|
134
|
+
export type PaginationOptions = boolean | {
|
|
135
|
+
pageSize?: number;
|
|
136
|
+
pageSizeOptions?: number[];
|
|
137
|
+
};
|
|
138
|
+
export type DetailDialogOptions = {
|
|
139
|
+
width?: number | string;
|
|
140
|
+
height?: number | string;
|
|
141
|
+
maximizable?: boolean;
|
|
142
|
+
draggable?: boolean;
|
|
143
|
+
resizable?: boolean;
|
|
144
|
+
};
|
|
145
|
+
export type RowDetailOptions = {
|
|
146
|
+
presentation: 'dialog';
|
|
147
|
+
dialog?: DetailDialogOptions;
|
|
148
|
+
detail?: EditorDetail;
|
|
149
|
+
placement?: never;
|
|
150
|
+
resizable?: never;
|
|
151
|
+
collapsed?: never;
|
|
152
|
+
} | {
|
|
153
|
+
presentation: 'panel';
|
|
154
|
+
detail?: EditorDetail;
|
|
155
|
+
placement?: 'right' | 'bottom';
|
|
156
|
+
resizable?: boolean;
|
|
157
|
+
collapsed?: boolean;
|
|
158
|
+
};
|
|
159
|
+
export type OptionsFor<Sub> = CommonControlOptions & (Sub extends {
|
|
160
|
+
type: 'number' | 'integer';
|
|
161
|
+
} ? {
|
|
162
|
+
slider?: boolean;
|
|
163
|
+
step?: number;
|
|
164
|
+
toggle?: never;
|
|
165
|
+
} : Sub extends {
|
|
166
|
+
type: 'string';
|
|
167
|
+
} ? {
|
|
168
|
+
multi?: boolean;
|
|
169
|
+
variant?: 'otp';
|
|
170
|
+
vertical?: boolean;
|
|
171
|
+
format?: string;
|
|
172
|
+
mask?: string;
|
|
173
|
+
returnMaskedValue?: boolean;
|
|
174
|
+
language?: string;
|
|
175
|
+
propagateErrors?: boolean;
|
|
176
|
+
monaco?: Record<string, unknown>;
|
|
177
|
+
slider?: never;
|
|
178
|
+
} : Sub extends {
|
|
179
|
+
type: 'array';
|
|
180
|
+
} ? {
|
|
181
|
+
collapsible?: boolean;
|
|
182
|
+
collapsed?: boolean;
|
|
183
|
+
table?: boolean;
|
|
184
|
+
columnDefs?: {
|
|
185
|
+
field: string;
|
|
186
|
+
scope?: '#';
|
|
187
|
+
headerName?: string;
|
|
188
|
+
width?: number;
|
|
189
|
+
minWidth?: number;
|
|
190
|
+
maxWidth?: number;
|
|
191
|
+
}[];
|
|
192
|
+
pagination?: PaginationOptions;
|
|
193
|
+
additionalItems?: {
|
|
194
|
+
pagination?: PaginationOptions;
|
|
195
|
+
};
|
|
196
|
+
rowDetail?: RowDetailOptions;
|
|
197
|
+
variant?: 'ag-grid' | 'tuple' | 'chips' | 'multi-select';
|
|
198
|
+
showSortButtons?: boolean;
|
|
199
|
+
restrict?: boolean;
|
|
200
|
+
detail?: ArrayDetail;
|
|
201
|
+
cells?: Record<string, unknown>;
|
|
202
|
+
} : Sub extends {
|
|
203
|
+
type: 'object';
|
|
204
|
+
} ? {
|
|
205
|
+
additionalProperties?: {
|
|
206
|
+
pagination?: PaginationOptions;
|
|
207
|
+
};
|
|
208
|
+
} : Sub extends {
|
|
209
|
+
type: 'boolean';
|
|
210
|
+
} ? {
|
|
211
|
+
toggle?: boolean;
|
|
212
|
+
slider?: never;
|
|
213
|
+
} : Record<string, unknown>);
|
|
214
|
+
export type RuleEffect = 'HIDE' | 'SHOW' | 'ENABLE' | 'DISABLE';
|
|
215
|
+
/** A leaf condition: one scope, one schema to test the value against. */
|
|
216
|
+
export interface TypedLeafCondition<S> {
|
|
217
|
+
scope: Scope<(DataPath<S> & string) | ''>;
|
|
218
|
+
schema: Record<string, unknown>;
|
|
219
|
+
failWhenUndefined?: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** The composite forms core supports, so a rule is not limited to one test. */
|
|
222
|
+
export interface TypedComposedCondition<S> {
|
|
223
|
+
type: 'AND' | 'OR';
|
|
224
|
+
conditions: TypedCondition<S>[];
|
|
225
|
+
}
|
|
226
|
+
export type TypedCondition<S> = TypedLeafCondition<S> | TypedComposedCondition<S>;
|
|
227
|
+
export interface TypedRule<S> {
|
|
228
|
+
effect: RuleEffect;
|
|
229
|
+
condition: TypedCondition<S>;
|
|
230
|
+
}
|
|
231
|
+
/** `label` is not only a string: core also accepts a descriptor. */
|
|
232
|
+
export type TypedLabelDescriptor = {
|
|
233
|
+
text?: string;
|
|
234
|
+
show?: boolean;
|
|
235
|
+
};
|
|
236
|
+
/** Every path a control may bind to, including `''` for the root. */
|
|
237
|
+
export type ControlPath<S> = (DataPath<S> & string) | '';
|
|
238
|
+
export interface TypedControl<S, P extends ControlPath<S> = ControlPath<S>> {
|
|
239
|
+
type: 'Control';
|
|
240
|
+
scope: Scope<P>;
|
|
241
|
+
label?: string | boolean | TypedLabelDescriptor;
|
|
242
|
+
/** Translation-key prefix for this element, per core's i18n precedence. */
|
|
243
|
+
i18n?: string;
|
|
244
|
+
options?: OptionsFor<SchemaAtPath<S, P>>;
|
|
245
|
+
rule?: TypedRule<S>;
|
|
246
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedControl<S, P>>>;
|
|
247
|
+
}
|
|
248
|
+
/** An unbound label element. */
|
|
249
|
+
export interface TypedLabelElement<S> {
|
|
250
|
+
type: 'Label';
|
|
251
|
+
text?: string;
|
|
252
|
+
i18n?: string;
|
|
253
|
+
options?: Record<string, unknown> & {
|
|
254
|
+
/** Override the host default for named substitution markers; omit to inherit. */
|
|
255
|
+
textParamSpans?: boolean;
|
|
256
|
+
};
|
|
257
|
+
rule?: TypedRule<S>;
|
|
258
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedLabelElement<S>>>;
|
|
259
|
+
}
|
|
260
|
+
/** One tab or step of a `Categorization`. */
|
|
261
|
+
export interface TypedCategory<S> {
|
|
262
|
+
type: 'Category';
|
|
263
|
+
label?: string;
|
|
264
|
+
i18n?: string;
|
|
265
|
+
elements: TypedElement<S>[];
|
|
266
|
+
options?: Record<string, unknown>;
|
|
267
|
+
rule?: TypedRule<S>;
|
|
268
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedCategory<S>>>;
|
|
269
|
+
}
|
|
270
|
+
export interface TypedLayout<S> {
|
|
271
|
+
type: 'VerticalLayout' | 'HorizontalLayout' | 'Group' | 'Categorization';
|
|
272
|
+
label?: string;
|
|
273
|
+
i18n?: string;
|
|
274
|
+
/** Group's prominent media, dispatched before its heading. */
|
|
275
|
+
cover?: TypedElement<S>;
|
|
276
|
+
/** Group's supplemental heading content, outside the disclosure trigger. */
|
|
277
|
+
header?: TypedElement<S>[];
|
|
278
|
+
/** Group's content after its body; may contain any supported elements. */
|
|
279
|
+
footer?: TypedElement<S>[];
|
|
280
|
+
elements: (TypedElement<S> | TypedCategory<S>)[];
|
|
281
|
+
options?: {
|
|
282
|
+
/** Own conditional object presentation for this layout subtree. */
|
|
283
|
+
conditionalFields?: boolean;
|
|
284
|
+
/** Host styling names on this element's slot in its parent layout. */
|
|
285
|
+
part?: string;
|
|
286
|
+
gap?: CssLength;
|
|
287
|
+
wrap?: boolean;
|
|
288
|
+
minItemWidth?: CssLength;
|
|
289
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
290
|
+
justify?: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly';
|
|
291
|
+
resizable?: boolean;
|
|
292
|
+
/** Horizontal layouts only. */
|
|
293
|
+
gridColumns?: number;
|
|
294
|
+
collapsible?: boolean;
|
|
295
|
+
collapsed?: boolean;
|
|
296
|
+
showDataIndicator?: boolean;
|
|
297
|
+
showValidationIndicator?: boolean;
|
|
298
|
+
};
|
|
299
|
+
rule?: TypedRule<S>;
|
|
300
|
+
$dynamic?: DynamicSpec<DynamicTarget<TypedLayout<S>>>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Anything this module does not model, passed through unchecked.
|
|
304
|
+
*
|
|
305
|
+
* The escape hatch, and deliberately a **named** one: the alternative is a
|
|
306
|
+
* permissive member of the element union, which would silently accept a
|
|
307
|
+
* mistyped `Control` as well. Written as `f.raw({ … })` it is greppable, and
|
|
308
|
+
* the loss of checking is visible at the point where it happens rather than
|
|
309
|
+
* inferred from an element that quietly matched something else.
|
|
310
|
+
*/
|
|
311
|
+
export interface RawElement {
|
|
312
|
+
type: string;
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
export type TypedElement<S> = TypedControl<S> | TypedLayout<S> | TypedLabelElement<S> | RawElement;
|
|
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 declare 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
|
+
/** A `Control` bound to a path, with options checked against its schema. */
|
|
332
|
+
control: <P_1 extends ControlPath<S>>(path: P_1, rest?: Omit<TypedControl<S, P_1>, "type" | "scope"> | undefined) => TypedControl<S, P_1>;
|
|
333
|
+
/** Identity, for the inference: it fixes `S` for every nested element. */
|
|
334
|
+
layout: (layout: TypedLayout<S>) => TypedLayout<S>;
|
|
335
|
+
/** One tab or step of a `Categorization`. */
|
|
336
|
+
category: (category: Omit<TypedCategory<S>, "type">) => TypedCategory<S>;
|
|
337
|
+
/** An unbound label. */
|
|
338
|
+
label: (label: Omit<TypedLabelElement<S>, "type">) => TypedLabelElement<S>;
|
|
339
|
+
/** Identity, so a rule written on its own is still checked. */
|
|
340
|
+
rule: (rule: TypedRule<S>) => TypedRule<S>;
|
|
341
|
+
/**
|
|
342
|
+
* Anything this module does not model - an extended element, an option it
|
|
343
|
+
* does not carry, a layout from another family. Unchecked by design; see
|
|
344
|
+
* `typescript/README.md`.
|
|
345
|
+
*/
|
|
346
|
+
raw: <T extends RawElement>(element: T) => T;
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* A deeply readonly view of a type.
|
|
350
|
+
*
|
|
351
|
+
* `as const` freezes arrays into `readonly` tuples, and `JsonSchema`'s
|
|
352
|
+
* `required` is a mutable `string[]`, so `… as const satisfies JsonSchema`
|
|
353
|
+
* is rejected on any schema that has a `required` - which is most of them.
|
|
354
|
+
* The constraint has to admit readonly to be usable at all.
|
|
355
|
+
*/
|
|
356
|
+
export type ReadonlyDeep<T> = T extends (infer E)[] ? readonly ReadonlyDeep<E>[] : T extends readonly (infer E)[] ? readonly ReadonlyDeep<E>[] : T extends object ? {
|
|
357
|
+
readonly [K in keyof T]: ReadonlyDeep<T[K]>;
|
|
358
|
+
} : T;
|
|
359
|
+
/**
|
|
360
|
+
* What to `satisfies` an authored schema against.
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* const schema = { … } as const satisfies AuthoredSchema;
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* Keeps the literal inference the rest of this module needs, and still
|
|
367
|
+
* checks that what was written is a JSON Schema.
|
|
368
|
+
*/
|
|
369
|
+
export type AuthoredSchema = ReadonlyDeep<JsonSchema> & {
|
|
370
|
+
readonly [keyword: string]: unknown;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Hands an authored schema to `<JsonForms>`.
|
|
374
|
+
*
|
|
375
|
+
* The cast is through `unknown` because `as const` makes every array
|
|
376
|
+
* readonly and `JsonSchema` wants mutable ones - the two do not overlap in
|
|
377
|
+
* TypeScript's view, though the value is a perfectly good schema. It is
|
|
378
|
+
* widening, so it happens **after** every check in this module has run, and
|
|
379
|
+
* it is here rather than at each call site so there is one place to look.
|
|
380
|
+
*
|
|
381
|
+
* JSON Forms does not mutate the schema it is given.
|
|
382
|
+
*/
|
|
383
|
+
export declare const asJsonSchema: (schema: unknown) => JsonSchema;
|
|
384
|
+
/** The same, for a UI schema built by {@link forSchema}. */
|
|
385
|
+
export declare const asUiSchema: (uischema: unknown) => UISchemaElement;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asUiSchema = exports.asJsonSchema = exports.forSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `address.city` -> `#/properties/address/properties/city`.
|
|
6
|
+
*
|
|
7
|
+
* Takes a plain `string`: with `S` still generic TypeScript cannot see that
|
|
8
|
+
* `P` is one, so the work happens here and the literal type is reapplied at
|
|
9
|
+
* the boundary. The cast is the only thing tying this expression to
|
|
10
|
+
* `Scope<P>`, which is why `typedAuthoring.test.ts` asserts that the two
|
|
11
|
+
* agree on concrete paths.
|
|
12
|
+
*/
|
|
13
|
+
const toPointer = (path) => path === ''
|
|
14
|
+
? '#'
|
|
15
|
+
: `#/properties/${path
|
|
16
|
+
.split('.')
|
|
17
|
+
/*
|
|
18
|
+
RFC 6901 escaping, per segment, exactly as core's own `getPropPath`
|
|
19
|
+
does it: `/` and `~` have meaning inside a pointer, so a property
|
|
20
|
+
called `a/b` is addressed as `a~1b`. Core `decode`s them on the way
|
|
21
|
+
back, so leaving them raw produces a pointer that silently resolves
|
|
22
|
+
to nothing.
|
|
23
|
+
*/
|
|
24
|
+
.map((segment) => segment.replace(/~/g, '~0').replace(/\//g, '~1'))
|
|
25
|
+
.join('/properties/')}`;
|
|
26
|
+
/**
|
|
27
|
+
* Binds the authoring helpers to one schema.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const schema = { … } as const;
|
|
31
|
+
* const f = forSchema(schema);
|
|
32
|
+
* f.control('address.city'); // '#/properties/address/properties/city'
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* The schema argument is used for **inference only** and is never read, so
|
|
36
|
+
* the helpers cost nothing at runtime beyond the string join.
|
|
37
|
+
*/
|
|
38
|
+
const forSchema = (_schema) => ({
|
|
39
|
+
/** The JSON Pointer for a path, as a literal type. `''` is the root. */
|
|
40
|
+
scope: (path) => toPointer(path),
|
|
41
|
+
/** A `Control` bound to a path, with options checked against its schema. */
|
|
42
|
+
control: (path, rest) => ({
|
|
43
|
+
type: 'Control',
|
|
44
|
+
scope: toPointer(path),
|
|
45
|
+
...rest,
|
|
46
|
+
}),
|
|
47
|
+
/** Identity, for the inference: it fixes `S` for every nested element. */
|
|
48
|
+
layout: (layout) => layout,
|
|
49
|
+
/** One tab or step of a `Categorization`. */
|
|
50
|
+
category: (category) => ({
|
|
51
|
+
type: 'Category',
|
|
52
|
+
...category,
|
|
53
|
+
}),
|
|
54
|
+
/** An unbound label. */
|
|
55
|
+
label: (label) => ({
|
|
56
|
+
type: 'Label',
|
|
57
|
+
...label,
|
|
58
|
+
}),
|
|
59
|
+
/** Identity, so a rule written on its own is still checked. */
|
|
60
|
+
rule: (rule) => rule,
|
|
61
|
+
/**
|
|
62
|
+
* Anything this module does not model - an extended element, an option it
|
|
63
|
+
* does not carry, a layout from another family. Unchecked by design; see
|
|
64
|
+
* `typescript/README.md`.
|
|
65
|
+
*/
|
|
66
|
+
raw: (element) => element,
|
|
67
|
+
});
|
|
68
|
+
exports.forSchema = forSchema;
|
|
69
|
+
/**
|
|
70
|
+
* Hands an authored schema to `<JsonForms>`.
|
|
71
|
+
*
|
|
72
|
+
* The cast is through `unknown` because `as const` makes every array
|
|
73
|
+
* readonly and `JsonSchema` wants mutable ones - the two do not overlap in
|
|
74
|
+
* TypeScript's view, though the value is a perfectly good schema. It is
|
|
75
|
+
* widening, so it happens **after** every check in this module has run, and
|
|
76
|
+
* it is here rather than at each call site so there is one place to look.
|
|
77
|
+
*
|
|
78
|
+
* JSON Forms does not mutate the schema it is given.
|
|
79
|
+
*/
|
|
80
|
+
const asJsonSchema = (schema) => schema;
|
|
81
|
+
exports.asJsonSchema = asJsonSchema;
|
|
82
|
+
/** The same, for a UI schema built by {@link forSchema}. */
|
|
83
|
+
const asUiSchema = (uischema) => uischema;
|
|
84
|
+
exports.asUiSchema = asUiSchema;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a JSON Schema at the **type** level.
|
|
3
|
+
*
|
|
4
|
+
* Everything here operates on the schema as a TypeScript type, so it only
|
|
5
|
+
* works on a schema whose literal types survive - `as const`, or
|
|
6
|
+
* `as const satisfies …`. A schema declared as a plain object widens
|
|
7
|
+
* `type: 'integer'` to `type: string`, and the two of these that read the
|
|
8
|
+
* `type` keyword quietly stop discriminating. Property **names** survive
|
|
9
|
+
* either way, because they are keys rather than values, so {@link DataPath}
|
|
10
|
+
* keeps working where {@link DataOf} does not. That asymmetry is worth
|
|
11
|
+
* knowing: paths keep being checked while the data type silently becomes
|
|
12
|
+
* `unknown`.
|
|
13
|
+
*/
|
|
14
|
+
type Primitives = {
|
|
15
|
+
string: string;
|
|
16
|
+
number: number;
|
|
17
|
+
integer: number;
|
|
18
|
+
boolean: boolean;
|
|
19
|
+
null: null;
|
|
20
|
+
};
|
|
21
|
+
type RequiredKeyOf<S> = S extends {
|
|
22
|
+
required: readonly (infer R)[];
|
|
23
|
+
} ? R & string : never;
|
|
24
|
+
type PropsOf<S> = S extends {
|
|
25
|
+
properties: infer P;
|
|
26
|
+
} ? P : never;
|
|
27
|
+
/** `required` names stay non-optional; everything else is optional. */
|
|
28
|
+
type ObjectData<S> = {
|
|
29
|
+
[K in keyof PropsOf<S> as K extends RequiredKeyOf<S> ? K : never]: DataOf<PropsOf<S>[K]>;
|
|
30
|
+
} & {
|
|
31
|
+
[K in keyof PropsOf<S> as K extends RequiredKeyOf<S> ? never : K]?: DataOf<PropsOf<S>[K]>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The data a schema describes.
|
|
35
|
+
*
|
|
36
|
+
* `const` and `enum` come first, so a constant narrows to its value rather
|
|
37
|
+
* than to its type - which is what makes a discriminated union of branches
|
|
38
|
+
* usable from TypeScript.
|
|
39
|
+
*/
|
|
40
|
+
export type DataOf<S> = S extends {
|
|
41
|
+
const: infer C;
|
|
42
|
+
} ? C : S extends {
|
|
43
|
+
enum: readonly (infer E)[];
|
|
44
|
+
} ? E : S extends {
|
|
45
|
+
type: 'array';
|
|
46
|
+
items: infer I;
|
|
47
|
+
} ? DataOf<I>[] : S extends {
|
|
48
|
+
properties: unknown;
|
|
49
|
+
} ? ObjectData<S> : S extends {
|
|
50
|
+
type: infer T;
|
|
51
|
+
} ? T extends keyof Primitives ? Primitives[T] : unknown : unknown;
|
|
52
|
+
/** Bounded recursion, so a schema that points at itself cannot hang `tsc`. */
|
|
53
|
+
type Decrement = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
54
|
+
/**
|
|
55
|
+
* Every addressable path in a schema, dotted.
|
|
56
|
+
*
|
|
57
|
+
* **Arrays are terminal.** A control inside an array's `detail` is scoped
|
|
58
|
+
* relative to the item, not through the parent, so `orders.reference` is not
|
|
59
|
+
* a scope this form could use - `orders` is, and the detail's own uischema
|
|
60
|
+
* addresses `reference` from there. Offering the through-path would be
|
|
61
|
+
* offering a pointer that resolves to nothing.
|
|
62
|
+
*
|
|
63
|
+
* `$ref` is not followed. A property whose schema is `{ $ref: … }` has no
|
|
64
|
+
* `properties` of its own at the type level, so it is terminal too.
|
|
65
|
+
*/
|
|
66
|
+
export type DataPath<S, D extends number = 6> = D extends 0 ? never : S extends {
|
|
67
|
+
type: 'array';
|
|
68
|
+
} ? never : S extends {
|
|
69
|
+
properties: infer P;
|
|
70
|
+
} ? {
|
|
71
|
+
[K in keyof P & string]: K extends `${string}.${string}` ? never : K | (P[K] extends {
|
|
72
|
+
properties: unknown;
|
|
73
|
+
} ? `${K}.${DataPath<P[K], Decrement[D]> & string}` : never);
|
|
74
|
+
}[keyof P & string] : never;
|
|
75
|
+
/**
|
|
76
|
+
* A property whose name contains a dot is **not addressable**, and is left
|
|
77
|
+
* out of {@link DataPath} rather than mis-addressed.
|
|
78
|
+
*
|
|
79
|
+
* JSON Forms addresses data with dotted paths and the grammar has no escape,
|
|
80
|
+
* so a property literally called `first.name` has no scope: it splits into
|
|
81
|
+
* two segments and produces `#/properties/first/properties/name`, which
|
|
82
|
+
* points at a property that does not exist. Core has the same limitation -
|
|
83
|
+
* its own `getPropPath` splits on `.` too - so this is not something these
|
|
84
|
+
* helpers could route around.
|
|
85
|
+
*
|
|
86
|
+
* Adjustment 14 states the runtime half: such names are legal, are not
|
|
87
|
+
* refused, and are edited through a control that uses no path at all. What
|
|
88
|
+
* this type can do is refuse to hand out a pointer that would be wrong.
|
|
89
|
+
*
|
|
90
|
+
* `/` and `~` are a different matter. They are legal in a pointer once
|
|
91
|
+
* escaped, so they stay addressable and the escaping is done for you.
|
|
92
|
+
*/
|
|
93
|
+
export type UnaddressableName<S> = S extends {
|
|
94
|
+
properties: infer P;
|
|
95
|
+
} ? {
|
|
96
|
+
[K in keyof P & string]: K extends `${string}.${string}` ? K : never;
|
|
97
|
+
}[keyof P & string] : never;
|
|
98
|
+
type PointerBody<P extends string> = P extends `${infer H}.${infer R}` ? `properties/${H}/${PointerBody<R>}` : `properties/${P}`;
|
|
99
|
+
/**
|
|
100
|
+
* `address.city` -> `#/properties/address/properties/city`, and `''` -> `#`.
|
|
101
|
+
*
|
|
102
|
+
* The empty path is the root scope, which an object control binds to.
|
|
103
|
+
*/
|
|
104
|
+
export type Scope<P extends string> = P extends '' ? '#' : `#/${PointerBody<P>}`;
|
|
105
|
+
/** The sub-schema a dotted path lands on. */
|
|
106
|
+
export type SchemaAtPath<S, P extends string> = P extends `${infer H}.${infer R}` ? S extends {
|
|
107
|
+
properties: infer Props;
|
|
108
|
+
} ? H extends keyof Props ? SchemaAtPath<Props[H], R> : never : never : S extends {
|
|
109
|
+
properties: infer Props;
|
|
110
|
+
} ? P extends keyof Props ? Props[P] : never : never;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reading a JSON Schema at the **type** level.
|
|
4
|
+
*
|
|
5
|
+
* Everything here operates on the schema as a TypeScript type, so it only
|
|
6
|
+
* works on a schema whose literal types survive - `as const`, or
|
|
7
|
+
* `as const satisfies …`. A schema declared as a plain object widens
|
|
8
|
+
* `type: 'integer'` to `type: string`, and the two of these that read the
|
|
9
|
+
* `type` keyword quietly stop discriminating. Property **names** survive
|
|
10
|
+
* either way, because they are keys rather than values, so {@link DataPath}
|
|
11
|
+
* keeps working where {@link DataOf} does not. That asymmetry is worth
|
|
12
|
+
* knowing: paths keep being checked while the data type silently becomes
|
|
13
|
+
* `unknown`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./authoring/cssLength"), exports);
|
|
18
|
+
__exportStar(require("./authoring/schemaTypes"), exports);
|
|
19
|
+
__exportStar(require("./authoring/forSchema"), exports);
|
|
20
|
+
__exportStar(require("./authoring/dynamic"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs","main":"lib/index.js","types":"lib/index.d.ts"}
|