@dxos/react-ui-form 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731
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 +102 -5
- package/dist/lib/browser/index.mjs +2008 -840
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +83 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2008 -840
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +85 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +64 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +71 -17
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +148 -86
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +24 -8
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +26 -13
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +11 -9
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
- package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +4 -4
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/DateField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +8 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +85 -0
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +12 -6
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts +4 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +64 -61
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/index.d.ts +2 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +3 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
- package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +8 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
- package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +28 -6
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +64 -61
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +128 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts +9 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
- package/dist/types/src/components/ObjectTree/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +28 -33
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts +65 -61
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +9 -11
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +68 -66
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +13 -4
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +64 -61
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field-type.d.ts +19 -0
- package/dist/types/src/util/field-type.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +18 -1
- package/dist/types/src/util/properties.d.ts.map +1 -1
- package/dist/types/src/util/properties.test.d.ts +2 -0
- package/dist/types/src/util/properties.test.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +1 -0
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +48 -41
- package/src/components/FieldEditor/FieldEditor.stories.tsx +4 -4
- package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
- package/src/components/FieldEditor/FieldEditor.tsx +23 -17
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +46 -65
- package/src/components/Form/Form.tsx +176 -60
- package/src/components/Form/FormField.tsx +107 -38
- package/src/components/Form/FormFieldComponent.tsx +77 -20
- package/src/components/Form/FormFieldSet.tsx +128 -78
- package/src/components/Form/FormTooltipsContext.ts +25 -0
- package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
- package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
- package/src/components/Form/Layout/FormLayout.test.ts +59 -0
- package/src/components/Form/Layout/FormLayout.tsx +251 -0
- package/src/components/Form/Layout/annotation.ts +38 -0
- package/src/components/Form/Layout/index.ts +7 -0
- package/src/components/Form/Layout/parser.test.ts +120 -0
- package/src/components/Form/Layout/parser.ts +167 -0
- package/src/components/Form/fields/ArrayField.tsx +64 -35
- package/src/components/Form/fields/DateField.tsx +101 -0
- package/src/components/Form/fields/GeoPointField.tsx +12 -8
- package/src/components/Form/fields/InlineRefField.tsx +146 -0
- package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
- package/src/components/Form/fields/MarkdownField.tsx +135 -45
- package/src/components/Form/fields/RefField.tsx +83 -42
- package/src/components/Form/fields/SelectField.tsx +17 -5
- package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
- package/src/components/Form/fields/SelectOptionField.tsx +14 -13
- package/src/components/Form/fields/TextAreaField.tsx +1 -1
- package/src/components/Form/fields/TextField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +3 -2
- package/src/components/Form/fields/index.ts +2 -0
- package/src/components/Form/index.ts +3 -0
- package/src/components/Form/meta-tags.test.ts +47 -0
- package/src/components/Form/meta-tags.ts +33 -0
- package/src/components/ObjectForm/ObjectForm.tsx +109 -0
- package/src/components/ObjectForm/index.ts +5 -0
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +13 -11
- package/src/components/ObjectPicker/ObjectPicker.tsx +93 -66
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +111 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +144 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
- package/src/components/ObjectTree/ObjectTree.tsx +190 -0
- package/src/components/ObjectTree/index.ts +5 -0
- package/src/components/Settings/AUDIT.md +51 -0
- package/src/components/Settings/Settings.stories.tsx +69 -21
- package/src/components/Settings/Settings.tsx +32 -181
- package/src/components/Settings/SettingsFieldSet.tsx +257 -0
- package/src/components/Settings/SettingsItem.tsx +58 -0
- package/src/components/Settings/SettingsSelectField.tsx +59 -0
- package/src/components/Settings/index.ts +2 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +45 -51
- package/src/components/ViewEditor/ViewEditor.test.tsx +11 -9
- package/src/components/ViewEditor/ViewEditor.tsx +45 -55
- package/src/components/index.ts +3 -0
- package/src/components/testing.tsx +19 -11
- package/src/hooks/useKeyHandler.tsx +7 -7
- package/src/index.ts +0 -4
- package/src/translations.ts +67 -63
- package/src/util/field-type.ts +60 -0
- package/src/util/index.ts +1 -0
- package/src/util/properties.test.ts +121 -0
- package/src/util/properties.ts +47 -4
- package/src/util/refs.ts +7 -3
- package/src/vite-env.d.ts +10 -0
package/src/translations.ts
CHANGED
|
@@ -10,79 +10,83 @@ export const translations = [
|
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'fields
|
|
14
|
-
'hidden
|
|
15
|
-
'empty
|
|
13
|
+
'fields.label': 'Fields',
|
|
14
|
+
'hidden-fields.label': 'Hidden Fields',
|
|
15
|
+
'empty-readonly-ref-field.label': '(none)',
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
'field
|
|
20
|
-
'field
|
|
21
|
-
'field format label': 'Type',
|
|
22
|
-
'field path label': 'Field path',
|
|
23
|
-
'add field': 'Add field',
|
|
24
|
-
'delete field': 'Delete field',
|
|
25
|
-
'field limit reached': 'Maximum number of fields reached',
|
|
26
|
-
'boolean input true value': 'Yes',
|
|
27
|
-
'boolean input false value': 'No',
|
|
28
|
-
'show field label': 'Show field',
|
|
29
|
-
'hide field label': 'Hide field',
|
|
30
|
-
'delete field label': 'Delete field',
|
|
31
|
-
'ref field combobox input placeholder': 'Search…',
|
|
32
|
-
'ref field placeholder_one': 'Select…',
|
|
33
|
-
'ref field placeholder_other': 'Select items…',
|
|
17
|
+
'field-property.label': 'Property',
|
|
18
|
+
'field-property.placeholder': 'Property name',
|
|
19
|
+
'field-format.label': 'Type',
|
|
20
|
+
'field-path.label': 'Field path',
|
|
34
21
|
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
22
|
+
'remove-item.button': 'Delete item',
|
|
23
|
+
'add-item.button': 'Add item',
|
|
24
|
+
'add-property-button.label': 'Add property',
|
|
25
|
+
'boolean-input-true.value': 'Yes',
|
|
26
|
+
'boolean-input-false.value': 'No',
|
|
27
|
+
'show-field.label': 'Show field',
|
|
28
|
+
'hide-field.label': 'Hide field',
|
|
29
|
+
'delete-field.label': 'Delete field',
|
|
30
|
+
'create-option.label': 'Create',
|
|
31
|
+
'add-tag.label': 'Add tag',
|
|
38
32
|
|
|
39
|
-
'
|
|
40
|
-
'
|
|
33
|
+
'ref-field-combobox-input.placeholder': 'Search…',
|
|
34
|
+
'ref-field.placeholder': 'Select…',
|
|
35
|
+
'ref-field.placeholder_one': 'Select…',
|
|
36
|
+
'ref-field.placeholder_other': 'Select items…',
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'format
|
|
52
|
-
'format
|
|
53
|
-
'format
|
|
54
|
-
'format
|
|
55
|
-
'format
|
|
56
|
-
'format
|
|
57
|
-
'format
|
|
58
|
-
'format
|
|
59
|
-
'format
|
|
60
|
-
'format
|
|
61
|
-
'format
|
|
62
|
-
'format
|
|
63
|
-
'format
|
|
64
|
-
'format
|
|
65
|
-
'format
|
|
66
|
-
'format
|
|
67
|
-
'format
|
|
68
|
-
'format
|
|
69
|
-
'format
|
|
70
|
-
'format
|
|
38
|
+
'example.placeholder': 'Example',
|
|
39
|
+
'latitude.placeholder': 'Latitude (e.g., 40.7128)',
|
|
40
|
+
'longitude.placeholder': 'Longitude (e.g., -74.0060)',
|
|
41
|
+
|
|
42
|
+
'cancel-button.label': 'Cancel',
|
|
43
|
+
'save-button.label': 'Save',
|
|
44
|
+
'create-text.label': 'Create text',
|
|
45
|
+
|
|
46
|
+
// TypeFormat
|
|
47
|
+
'format.boolean.label': 'Boolean',
|
|
48
|
+
'format.currency.label': 'Currency',
|
|
49
|
+
'format.date.label': 'Date',
|
|
50
|
+
'format.date-time.label': 'DateTime',
|
|
51
|
+
'format.did.label': 'DID',
|
|
52
|
+
'format.duration.label': 'Duration',
|
|
53
|
+
'format.dxn.label': 'DXN',
|
|
54
|
+
'format.email.label': 'Email',
|
|
55
|
+
'format.formula.label': 'Formula',
|
|
56
|
+
'format.hostname.label': 'Hostname',
|
|
57
|
+
'format.integer.label': 'Integer',
|
|
58
|
+
'format.json.label': 'JSON',
|
|
59
|
+
'format.lnglat.label': 'Geopoint',
|
|
60
|
+
'format.markdown.label': 'Markdown',
|
|
61
|
+
'format.percent.label': 'Percent',
|
|
62
|
+
'format.ref.label': 'Reference',
|
|
63
|
+
'format.regex.label': 'RegExp',
|
|
64
|
+
'format.string.label': 'String',
|
|
65
|
+
'format.single-select.label': 'Select',
|
|
66
|
+
'format.multi-select.label': 'Multi-select',
|
|
67
|
+
'format.text.label': 'Long text',
|
|
68
|
+
'format.time.label': 'Time',
|
|
69
|
+
'format.timestamp.label': 'Timestamp',
|
|
70
|
+
'format.user.label': 'User',
|
|
71
|
+
'format.number.label': 'Number',
|
|
72
|
+
'format.uri.label': 'URI',
|
|
73
|
+
'format.url.label': 'URL',
|
|
74
|
+
'format.uuid.label': 'UUID',
|
|
71
75
|
|
|
72
76
|
// GeoPointField.
|
|
73
|
-
'latitude
|
|
74
|
-
'longitude
|
|
77
|
+
'latitude.label': 'Latitude',
|
|
78
|
+
'longitude.label': 'Longitude',
|
|
75
79
|
|
|
76
80
|
// SelectOptionsField.
|
|
77
|
-
'select
|
|
78
|
-
'select
|
|
79
|
-
'select
|
|
80
|
-
'select
|
|
81
|
-
'select option add': 'Add option',
|
|
81
|
+
'select-option.label': 'Label',
|
|
82
|
+
'select-option-label.placeholder': 'Option label',
|
|
83
|
+
'select-option-delete.button': 'Delete',
|
|
84
|
+
'select-option-add.button': 'Add option',
|
|
82
85
|
|
|
83
86
|
// System schema message.
|
|
84
|
-
'system
|
|
85
|
-
'system
|
|
87
|
+
'system-schema.title': 'System type',
|
|
88
|
+
'system-schema.description': 'System type: cannot add or remove fields.',
|
|
89
|
+
'remove.button': 'Delete',
|
|
86
90
|
},
|
|
87
91
|
},
|
|
88
92
|
},
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
|
+
|
|
7
|
+
import { getAnnotation, isLiteralUnion } from '@dxos/effect';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Detected field type for a schema property.
|
|
11
|
+
*/
|
|
12
|
+
export type SettingsFieldType = 'boolean' | 'string' | 'number' | 'select' | 'struct';
|
|
13
|
+
|
|
14
|
+
export type SelectOption = {
|
|
15
|
+
value: string | number;
|
|
16
|
+
label?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Detect the field type from an Effect Schema AST node.
|
|
21
|
+
*/
|
|
22
|
+
export const detectFieldType = (ast: SchemaAST.AST): SettingsFieldType | undefined => {
|
|
23
|
+
if (isLiteralUnion(ast)) {
|
|
24
|
+
return 'select';
|
|
25
|
+
}
|
|
26
|
+
if (SchemaAST.isTypeLiteral(ast)) {
|
|
27
|
+
return 'struct';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
switch (ast._tag) {
|
|
31
|
+
case 'BooleanKeyword':
|
|
32
|
+
return 'boolean';
|
|
33
|
+
case 'StringKeyword':
|
|
34
|
+
return 'string';
|
|
35
|
+
case 'NumberKeyword':
|
|
36
|
+
return 'number';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Extract select options from a literal union AST node.
|
|
44
|
+
* Reads title annotations from individual literals for labels.
|
|
45
|
+
*/
|
|
46
|
+
export const getSelectOptionsFromAst = (ast: SchemaAST.AST): SelectOption[] | undefined => {
|
|
47
|
+
if (!isLiteralUnion(ast)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (ast as SchemaAST.Union<SchemaAST.Literal>).types.flatMap((literalNode) => {
|
|
52
|
+
const value = literalNode.literal;
|
|
53
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const title = getAnnotation<string>(SchemaAST.TitleAnnotationId, false)(literalNode);
|
|
57
|
+
const label = title ?? (typeof value === 'string' ? value.charAt(0).toUpperCase() + value.slice(1) : String(value));
|
|
58
|
+
return [{ value, label }];
|
|
59
|
+
});
|
|
60
|
+
};
|
package/src/util/index.ts
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
import { describe, test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { DXN, Annotation, JsonSchema, Type } from '@dxos/echo';
|
|
10
|
+
import { Format } from '@dxos/echo/internal';
|
|
11
|
+
import { findNode, getArrayElementType } from '@dxos/effect';
|
|
12
|
+
|
|
13
|
+
import { getFormProperties } from './properties';
|
|
14
|
+
|
|
15
|
+
describe('getFormProperties', () => {
|
|
16
|
+
test('filters out keyword fields annotated FormInputAnnotation.set(false)', ({ expect }) => {
|
|
17
|
+
const TestSchema = Schema.Struct({
|
|
18
|
+
name: Schema.optional(Schema.String),
|
|
19
|
+
hidden: Schema.String.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
20
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.keywordHidden', '0.1.0')));
|
|
21
|
+
|
|
22
|
+
const names = getFormProperties(Type.getSchema(TestSchema).ast).map((prop) => prop.name);
|
|
23
|
+
expect(names).toContain('name');
|
|
24
|
+
expect(names).not.toContain('hidden');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('filters out struct fields annotated FormInputAnnotation.set(false)', ({ expect }) => {
|
|
28
|
+
// Regression: JsonSchema fields are a Schema.Struct; encodedBoundAST strips
|
|
29
|
+
// annotations from non-keyword inner types, which previously bypassed the
|
|
30
|
+
// form-input filter (e.g., Routine.input).
|
|
31
|
+
const TestSchema = Schema.Struct({
|
|
32
|
+
name: Schema.optional(Schema.String),
|
|
33
|
+
schema: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
34
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.structHidden', '0.1.0')));
|
|
35
|
+
|
|
36
|
+
const names = getFormProperties(Type.getSchema(TestSchema).ast).map((prop) => prop.name);
|
|
37
|
+
expect(names).toContain('name');
|
|
38
|
+
expect(names).not.toContain('schema');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('filters out array fields annotated FormInputAnnotation.set(false)', ({ expect }) => {
|
|
42
|
+
const TestSchema = Schema.Struct({
|
|
43
|
+
name: Schema.optional(Schema.String),
|
|
44
|
+
context: Schema.Array(Schema.Any).pipe(Annotation.FormInputAnnotation.set(false)),
|
|
45
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.arrayHidden', '0.1.0')));
|
|
46
|
+
|
|
47
|
+
const names = getFormProperties(Type.getSchema(TestSchema).ast).map((prop) => prop.name);
|
|
48
|
+
expect(names).toContain('name');
|
|
49
|
+
expect(names).not.toContain('context');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('filters out optional fields annotated FormInputAnnotation.set(false)', ({ expect }) => {
|
|
53
|
+
// Regression: optional fields' `prop.type` is the union `T | undefined`; the
|
|
54
|
+
// annotation lives on the inner `T`. Without unwrapping, the filter would
|
|
55
|
+
// miss the annotation and the hidden field would render. Covers the
|
|
56
|
+
// conventional pattern `Schema.X.pipe(FormInputAnnotation.set(false), Schema.optional)`.
|
|
57
|
+
const TestSchema = Schema.Struct({
|
|
58
|
+
name: Schema.optional(Schema.String),
|
|
59
|
+
userId: Schema.String.pipe(Annotation.FormInputAnnotation.set(false), Schema.optional),
|
|
60
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.optionalHidden', '0.1.0')));
|
|
61
|
+
|
|
62
|
+
const names = getFormProperties(Type.getSchema(TestSchema).ast).map((prop) => prop.name);
|
|
63
|
+
expect(names).toContain('name');
|
|
64
|
+
expect(names).not.toContain('userId');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('preserves a deeply-nested FormInputAnnotation through unions and arrays', ({ expect }) => {
|
|
68
|
+
// Regression: a hidden field nested below a discriminated union and arrays of structs (e.g.
|
|
69
|
+
// Segment.details(road).routes[].legs[].geometry). `encodedBoundAST` strips annotations from
|
|
70
|
+
// non-keyword inner types, so without keeping container types raw the annotation is lost by
|
|
71
|
+
// the time the form recurses to the leaf field. The transformation element (GeoPoint) is the
|
|
72
|
+
// trigger that forces the encode rebuild.
|
|
73
|
+
const Leg = Schema.Struct({
|
|
74
|
+
distance: Schema.Number,
|
|
75
|
+
geometry: Schema.Array(Format.GeoPoint).pipe(Annotation.FormInputAnnotation.set(false)),
|
|
76
|
+
});
|
|
77
|
+
const Route = Schema.Struct({ legs: Schema.Array(Leg) });
|
|
78
|
+
const TestSchema = Schema.Struct({
|
|
79
|
+
details: Schema.Union(
|
|
80
|
+
Schema.TaggedStruct('road', { routes: Schema.optional(Schema.Array(Route)) }),
|
|
81
|
+
Schema.TaggedStruct('other', { note: Schema.optional(Schema.String) }),
|
|
82
|
+
),
|
|
83
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.nestedHidden', '0.1.0')));
|
|
84
|
+
|
|
85
|
+
// Drill as the form does: getFormProperties at each level, descending via the property type
|
|
86
|
+
// (array element / type literal) returned by the previous level.
|
|
87
|
+
const findTypeLiteralWith = (ast: SchemaAST.AST, prop: string) =>
|
|
88
|
+
findNode(
|
|
89
|
+
ast,
|
|
90
|
+
(node) => SchemaAST.isTypeLiteral(node) && SchemaAST.getPropertySignatures(node).some((p) => p.name === prop),
|
|
91
|
+
)!;
|
|
92
|
+
const propType = (ast: SchemaAST.AST, name: string) => getFormProperties(ast).find((p) => p.name === name)!.type;
|
|
93
|
+
|
|
94
|
+
const detailsType = propType(Type.getSchema(TestSchema).ast, 'details');
|
|
95
|
+
const roadTypeLiteral = findTypeLiteralWith(detailsType, 'routes');
|
|
96
|
+
const routeTypeLiteral = findNode(
|
|
97
|
+
getArrayElementType(propType(roadTypeLiteral, 'routes'))!,
|
|
98
|
+
SchemaAST.isTypeLiteral,
|
|
99
|
+
)!;
|
|
100
|
+
const legTypeLiteral = findNode(getArrayElementType(propType(routeTypeLiteral, 'legs'))!, SchemaAST.isTypeLiteral)!;
|
|
101
|
+
|
|
102
|
+
const names = getFormProperties(legTypeLiteral).map((prop) => prop.name);
|
|
103
|
+
expect(names).toContain('distance');
|
|
104
|
+
expect(names).not.toContain('geometry');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('preserves annotation when chained with .annotations()', ({ expect }) => {
|
|
108
|
+
// Regression: `.pipe(FormInputAnnotation.set(false)).annotations({...})` must
|
|
109
|
+
// not lose the form-input annotation.
|
|
110
|
+
const TestSchema = Schema.Struct({
|
|
111
|
+
name: Schema.optional(Schema.String),
|
|
112
|
+
hidden: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)).annotations({
|
|
113
|
+
description: 'Hidden field',
|
|
114
|
+
}),
|
|
115
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.chainedHidden', '0.1.0')));
|
|
116
|
+
|
|
117
|
+
const names = getFormProperties(Type.getSchema(TestSchema).ast).map((prop) => prop.name);
|
|
118
|
+
expect(names).toContain('name');
|
|
119
|
+
expect(names).not.toContain('hidden');
|
|
120
|
+
});
|
|
121
|
+
});
|
package/src/util/properties.ts
CHANGED
|
@@ -3,16 +3,59 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import * as Option from 'effect/Option';
|
|
6
|
-
import
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
8
|
import { Annotation } from '@dxos/echo';
|
|
9
|
-
import { type SchemaProperty, getProperties } from '@dxos/effect';
|
|
9
|
+
import { type SchemaProperty, getProperties, isArrayType, isNestedType } from '@dxos/effect';
|
|
10
|
+
|
|
11
|
+
/** The property's type with an optional `T | undefined` union unwrapped to its inner `T`. */
|
|
12
|
+
const unwrapOptional = (prop: SchemaAST.PropertySignature): SchemaAST.AST => {
|
|
13
|
+
if (!prop.isOptional || !SchemaAST.isUnion(prop.type)) {
|
|
14
|
+
return prop.type;
|
|
15
|
+
}
|
|
16
|
+
// Drop the `undefined` member, preserving the remaining union (don't collapse `A | B | undefined` to `A`).
|
|
17
|
+
const defined = prop.type.types.filter((type) => type._tag !== 'UndefinedKeyword');
|
|
18
|
+
if (defined.length === 0) {
|
|
19
|
+
return prop.type;
|
|
20
|
+
}
|
|
21
|
+
return defined.length === 1 ? defined[0] : SchemaAST.Union.make(defined, prop.type.annotations);
|
|
22
|
+
};
|
|
10
23
|
|
|
11
24
|
/**
|
|
12
25
|
* Get the property types of an AST and filter out properties that are not form inputs.
|
|
26
|
+
*
|
|
27
|
+
* The `FormInputAnnotation` is read from the raw property signature's AST (before
|
|
28
|
+
* `encodedBoundAST` is applied by `getProperties`), because `encodedBoundAST` strips
|
|
29
|
+
* annotations from non-keyword inner types (e.g., `Schema.Struct`, `Schema.Array`).
|
|
30
|
+
* Without this, fields like `Routine.input` (a JsonSchema struct) annotated
|
|
31
|
+
* `FormInputAnnotation.set(false)` would still render in the form.
|
|
32
|
+
*
|
|
33
|
+
* For optional fields, `prop.type` is the union `T | undefined` — the annotation
|
|
34
|
+
* lives on the inner `T`. Unwrap before reading so that the conventional pattern
|
|
35
|
+
* `Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional)` works.
|
|
36
|
+
*
|
|
37
|
+
* Container properties (nested structs, unions, arrays) keep their *raw* AST rather than
|
|
38
|
+
* the `encodedBoundAST` produced by `getProperties`. `encodedBoundAST` strips annotations
|
|
39
|
+
* from non-keyword inner types, so a `FormInputAnnotation` nested beneath an encoded container
|
|
40
|
+
* (e.g. `RouteLeg.geometry`, reached via `Segment → details → routes → Route → legs`) would
|
|
41
|
+
* otherwise be lost by the time recursion reaches it. Leaf/transformation fields stay encoded
|
|
42
|
+
* (e.g. a `DateTime` still renders as its encoded string input).
|
|
13
43
|
*/
|
|
14
44
|
export const getFormProperties = (ast: SchemaAST.AST): SchemaProperty[] => {
|
|
15
|
-
|
|
16
|
-
|
|
45
|
+
const signatures = SchemaAST.getPropertySignatures(ast);
|
|
46
|
+
const rawByName = new Map<PropertyKey, SchemaAST.AST>(signatures.map((prop) => [prop.name, unwrapOptional(prop)]));
|
|
47
|
+
const hidden = new Set(
|
|
48
|
+
signatures
|
|
49
|
+
.filter(
|
|
50
|
+
(prop) =>
|
|
51
|
+
Annotation.FormInputAnnotation.getFromAst(unwrapOptional(prop)).pipe(Option.getOrElse(() => true)) === false,
|
|
52
|
+
)
|
|
53
|
+
.map((prop) => prop.name),
|
|
17
54
|
);
|
|
55
|
+
return getProperties(ast)
|
|
56
|
+
.filter((prop) => !hidden.has(prop.name))
|
|
57
|
+
.map((prop) => {
|
|
58
|
+
const raw = rawByName.get(prop.name);
|
|
59
|
+
return raw && (isNestedType(raw) || isArrayType(raw)) ? { ...prop, type: raw } : prop;
|
|
60
|
+
});
|
|
18
61
|
};
|
package/src/util/refs.ts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
import type * as SchemaAST from 'effect/SchemaAST';
|
|
6
6
|
|
|
7
7
|
import { Ref } from '@dxos/echo';
|
|
8
|
-
import {
|
|
8
|
+
import { type ReferenceAnnotationValue, ReferenceAnnotationId } from '@dxos/echo/internal';
|
|
9
|
+
import { findAnnotation, getArrayElementType, isArrayType } from '@dxos/effect';
|
|
9
10
|
|
|
10
11
|
type RefProps = {
|
|
11
12
|
ast: SchemaAST.AST;
|
|
12
13
|
isArray: boolean;
|
|
14
|
+
typename?: string;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export const getRefProps = (ast: SchemaAST.AST): RefProps | undefined => {
|
|
@@ -18,14 +20,16 @@ export const getRefProps = (ast: SchemaAST.AST): RefProps | undefined => {
|
|
|
18
20
|
const elementType = getArrayElementType(ast);
|
|
19
21
|
if (elementType) {
|
|
20
22
|
if (Ref.isRefType(elementType)) {
|
|
21
|
-
|
|
23
|
+
const typename = findAnnotation<ReferenceAnnotationValue>(elementType, ReferenceAnnotationId)?.typename;
|
|
24
|
+
return { ast: elementType, isArray: true, typename };
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
// Direct reference.
|
|
27
30
|
if (Ref.isRefType(ast)) {
|
|
28
|
-
|
|
31
|
+
const typename = findAnnotation<ReferenceAnnotationValue>(ast, ReferenceAnnotationId)?.typename;
|
|
32
|
+
return { ast, isArray: false, typename };
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
return undefined;
|