@dxos/react-ui-form 0.8.4-main.406dc2a → 0.8.4-main.4668b7de9b
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +3504 -2302
- 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 +3504 -2302
- 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 +8 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +69 -60
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +135 -26
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +175 -138
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +53 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +91 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts +21 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
- 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 +18 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
- 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 +5 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
- 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 +11 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
- 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 +4 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts +22 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +13 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +85 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/index.d.ts +14 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +5 -4
- 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 +39 -12
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +65 -59
- 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 +51 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +85 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- 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 +4 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +16 -20
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +72 -66
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +13 -6
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -3
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts +7 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- 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 +66 -60
- 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 +3 -3
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts +2 -2
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +24 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- 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 +2 -2
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +62 -51
- package/src/components/FieldEditor/FieldEditor.stories.tsx +44 -25
- package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
- package/src/components/FieldEditor/FieldEditor.tsx +88 -86
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +134 -252
- package/src/components/Form/Form.tsx +461 -106
- package/src/components/Form/FormField.tsx +363 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +229 -0
- package/src/components/Form/FormFieldSet.tsx +173 -0
- 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/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +178 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/DateField.tsx +101 -0
- package/src/components/Form/fields/GeoPointField.tsx +124 -0
- 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 +168 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +235 -0
- package/src/components/Form/fields/SelectField.tsx +77 -0
- package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +23 -18
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +31 -24
- package/src/components/Form/fields/TextAreaField.tsx +38 -0
- package/src/components/Form/fields/TextField.tsx +38 -0
- package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +17 -9
- package/src/components/Form/fields/index.ts +17 -0
- package/src/components/Form/index.ts +6 -4
- 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/{ControlSection → ObjectForm}/index.ts +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +30 -25
- package/src/components/ObjectPicker/ObjectPicker.tsx +123 -82
- 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 +104 -0
- package/src/components/Settings/Settings.tsx +81 -0
- 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 +7 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +75 -77
- package/src/components/ViewEditor/ViewEditor.test.tsx +16 -13
- package/src/components/ViewEditor/ViewEditor.tsx +295 -215
- package/src/components/index.ts +4 -1
- package/src/components/testing.tsx +24 -11
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +380 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/index.ts +0 -4
- package/src/translations.ts +71 -65
- package/src/util/field-type.ts +60 -0
- package/src/util/field.ts +25 -25
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +2 -1
- package/src/util/properties.test.ts +121 -0
- package/src/util/properties.ts +61 -0
- package/src/util/refs.ts +16 -18
- package/src/vite-env.d.ts +10 -0
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -84
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/Defaults.d.ts +0 -14
- package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -9
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -63
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -23
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/Input.d.ts +0 -29
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -22
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -79
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -4
- package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/factory.d.ts +0 -8
- package/dist/types/src/components/Form/factory.d.ts.map +0 -1
- package/dist/types/src/hooks/useForm.d.ts +0 -67
- package/dist/types/src/hooks/useForm.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
- package/src/components/ControlSection/ControlSection.tsx +0 -153
- package/src/components/Form/ArrayField.tsx +0 -125
- package/src/components/Form/Defaults.tsx +0 -205
- package/src/components/Form/FormActions.tsx +0 -54
- package/src/components/Form/FormContent.tsx +0 -322
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -54
- package/src/components/Form/RefField.tsx +0 -283
- package/src/components/Form/custom/GeoPointInput.tsx +0 -80
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -31
- package/src/hooks/useForm.ts +0 -296
- package/src/hooks/useQueryRefOptions.ts +0 -62
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -12
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type AnyProperties } from '@dxos/echo/internal';
|
|
9
|
+
import { createJsonPath, type SchemaProperty } from '@dxos/effect';
|
|
10
|
+
|
|
11
|
+
import { type FormHandlerProps } from '../../hooks';
|
|
12
|
+
import { getFormProperties } from '../../util';
|
|
13
|
+
import { useFormValues } from './Form';
|
|
14
|
+
import { FormField, type FormFieldProps } from './FormField';
|
|
15
|
+
import { FormFieldErrorBoundary, FormFieldLabel } from './FormFieldComponent';
|
|
16
|
+
import { DEFAULT_LAYOUT_NAME, FormLayout, FormLayoutAnnotation } from './Layout';
|
|
17
|
+
|
|
18
|
+
const FORM_FIELDSET_NAME = 'Form.FieldSet';
|
|
19
|
+
|
|
20
|
+
export type FormFieldSetProps<T extends AnyProperties> = {
|
|
21
|
+
label?: string;
|
|
22
|
+
sort?: string[];
|
|
23
|
+
exclude?: (props: SchemaProperty[]) => SchemaProperty[];
|
|
24
|
+
/**
|
|
25
|
+
* Picks a named layout out of `FormLayoutAnnotation` when present.
|
|
26
|
+
* Falls back to `'default'`. Ignored when the schema has no annotation
|
|
27
|
+
* (linear rendering then takes over).
|
|
28
|
+
*/
|
|
29
|
+
layoutName?: string;
|
|
30
|
+
} & Pick<FormHandlerProps<T>, 'schema'> &
|
|
31
|
+
Pick<
|
|
32
|
+
FormFieldProps,
|
|
33
|
+
| 'path'
|
|
34
|
+
| 'autoFocus'
|
|
35
|
+
| 'readonly'
|
|
36
|
+
| 'layout'
|
|
37
|
+
| 'projection'
|
|
38
|
+
| 'fieldMap'
|
|
39
|
+
| 'fieldProvider'
|
|
40
|
+
| 'createTypename'
|
|
41
|
+
| 'createOptionLabel'
|
|
42
|
+
| 'createOptionIcon'
|
|
43
|
+
| 'createInitialValuePath'
|
|
44
|
+
| 'createFieldMap'
|
|
45
|
+
| 'db'
|
|
46
|
+
| 'useType'
|
|
47
|
+
| 'getOptions'
|
|
48
|
+
| 'onCreate'
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Renders a set of form fields derived from a schema object.
|
|
53
|
+
*/
|
|
54
|
+
export const FormFieldSet = ({
|
|
55
|
+
label,
|
|
56
|
+
schema,
|
|
57
|
+
readonly,
|
|
58
|
+
path,
|
|
59
|
+
sort,
|
|
60
|
+
exclude,
|
|
61
|
+
projection,
|
|
62
|
+
layout,
|
|
63
|
+
layoutName = DEFAULT_LAYOUT_NAME,
|
|
64
|
+
...props
|
|
65
|
+
}: FormFieldSetProps<any>) => {
|
|
66
|
+
const values = useFormValues(FORM_FIELDSET_NAME, path);
|
|
67
|
+
const properties = useFormFieldSetProperties({ schema, values, exclude, sort, projection });
|
|
68
|
+
if ((readonly || layout === 'static') && values == null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// If the schema carries a layout template, hand off to <Form.Layout/> which renders the DSL.
|
|
73
|
+
// Linear rendering still runs when no annotation is present, so existing call sites are unchanged.
|
|
74
|
+
const layouts = schema ? Option.getOrUndefined(FormLayoutAnnotation.get(schema)) : undefined;
|
|
75
|
+
if (layouts?.[layoutName] !== undefined && schema) {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{layout !== 'inline' && label && <FormFieldLabel label={label} path={createJsonPath(path ?? [])} asChild />}
|
|
79
|
+
<FormLayout
|
|
80
|
+
schema={schema}
|
|
81
|
+
name={layoutName}
|
|
82
|
+
path={path}
|
|
83
|
+
readonly={readonly}
|
|
84
|
+
layout={layout}
|
|
85
|
+
projection={projection}
|
|
86
|
+
{...props}
|
|
87
|
+
/>
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<>
|
|
94
|
+
{layout !== 'inline' && label && <FormFieldLabel label={label} path={createJsonPath(path ?? [])} asChild />}
|
|
95
|
+
{properties.map((property) => {
|
|
96
|
+
const name = property.name.toString();
|
|
97
|
+
return (
|
|
98
|
+
<FormFieldErrorBoundary key={name} path={[...(path ?? []), name]}>
|
|
99
|
+
<FormField
|
|
100
|
+
type={property.type}
|
|
101
|
+
name={name}
|
|
102
|
+
path={[...(path ?? []), name]}
|
|
103
|
+
readonly={readonly}
|
|
104
|
+
layout={layout}
|
|
105
|
+
projection={projection}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
</FormFieldErrorBoundary>
|
|
109
|
+
);
|
|
110
|
+
})}
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
FormFieldSet.displayName = FORM_FIELDSET_NAME;
|
|
116
|
+
|
|
117
|
+
type UseFormFieldSetPropertiesParams = Pick<FormFieldSetProps<any>, 'schema' | 'exclude' | 'projection' | 'sort'> & {
|
|
118
|
+
values: AnyProperties | undefined;
|
|
119
|
+
sort?: string[];
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolves ordered schema properties for a field set (projection order, exclude, or sort).
|
|
124
|
+
*/
|
|
125
|
+
const useFormFieldSetProperties = ({
|
|
126
|
+
schema,
|
|
127
|
+
exclude,
|
|
128
|
+
projection,
|
|
129
|
+
values,
|
|
130
|
+
sort,
|
|
131
|
+
}: UseFormFieldSetPropertiesParams): SchemaProperty[] => {
|
|
132
|
+
// TODO(burdon): Updates on every value change.
|
|
133
|
+
// Remove values dep if can remove from getSchemaProperties.
|
|
134
|
+
return useMemo(() => {
|
|
135
|
+
if (!schema) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// TODO(wittjosiah): Reconcile FormInputAnnotation with projection hidden properties & exclude function.
|
|
140
|
+
const schemaProps = getFormProperties(schema.ast);
|
|
141
|
+
const filteredProps = exclude ? exclude(schemaProps) : schemaProps;
|
|
142
|
+
|
|
143
|
+
// Use projection-based field management when view and projection are available.
|
|
144
|
+
if (projection) {
|
|
145
|
+
const fieldProjections = projection.getFieldProjections();
|
|
146
|
+
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
147
|
+
|
|
148
|
+
// Filter properties to only include visible ones and order by projection.
|
|
149
|
+
const visibleProps = filteredProps.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
150
|
+
const orderedProps: SchemaProperty[] = [];
|
|
151
|
+
|
|
152
|
+
// Add properties in projection field order.
|
|
153
|
+
for (const fieldProjection of fieldProjections) {
|
|
154
|
+
const fieldPath = String(fieldProjection.field.path);
|
|
155
|
+
const prop = visibleProps.find((prop) => prop.name === fieldPath);
|
|
156
|
+
if (prop) {
|
|
157
|
+
orderedProps.push(prop);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Add any remaining properties not in projection.
|
|
162
|
+
const projectionPaths = new Set(fieldProjections.map((projection) => String(projection.field.path)));
|
|
163
|
+
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
164
|
+
orderedProps.push(...remainingProps);
|
|
165
|
+
return orderedProps;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Fallback to legacy filter/sort behavior.
|
|
169
|
+
return sort
|
|
170
|
+
? [...filteredProps].sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString()))
|
|
171
|
+
: filteredProps;
|
|
172
|
+
}, [schema, values, exclude, sort, projection]);
|
|
173
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createContext, useContext } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A standalone context for the `tooltips` flag (Form.Root's only label
|
|
9
|
+
* decoration today: a JSON-path hover tooltip rendered by
|
|
10
|
+
* `FormFieldLabel`).
|
|
11
|
+
*
|
|
12
|
+
* Lives in its own module so that `FormFieldComponent.tsx` -- imported at
|
|
13
|
+
* the top of `Form.tsx` -- can read the flag without re-importing from
|
|
14
|
+
* `Form.tsx`. That round-trip used to create a circular module-eval
|
|
15
|
+
* dependency that intermittently hit a TDZ ("Cannot access 'FormFieldLabel'
|
|
16
|
+
* before initialization") in browser-mode storybook tests.
|
|
17
|
+
*
|
|
18
|
+
* Defaults to `true` both when `Form.Root` doesn't pass an explicit value
|
|
19
|
+
* AND when there is no enclosing `Form.Root` (e.g. `FormFieldWrapper`
|
|
20
|
+
* stories that render an input without a Form provider).
|
|
21
|
+
*/
|
|
22
|
+
export const FormTooltipsContext = createContext<boolean>(true);
|
|
23
|
+
|
|
24
|
+
/** Returns whether the enclosing `Form.Root` has field tooltips enabled. */
|
|
25
|
+
export const useFormTooltips = (): boolean => useContext(FormTooltipsContext);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { composeStories } from '@storybook/react';
|
|
6
|
+
import { act, cleanup, screen, within } from '@testing-library/react';
|
|
7
|
+
import { afterEach, describe, expect, test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import * as stories from './FormLayout.stories';
|
|
10
|
+
|
|
11
|
+
const { NestedLabel, NestedLabelStatic } = composeStories(stories);
|
|
12
|
+
|
|
13
|
+
describe('FormLayout — nested fields', () => {
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
// Flush pending React scheduler work before teardown to prevent
|
|
16
|
+
// "window is not defined" errors from setImmediate callbacks firing after happy-dom cleanup.
|
|
17
|
+
await act(async () => {});
|
|
18
|
+
cleanup();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('renders nested struct labels and dotted sub-fields', { timeout: 30_000 }, async () => {
|
|
22
|
+
await NestedLabel.run();
|
|
23
|
+
|
|
24
|
+
// `<field name="origin"/>` / `<field name="destination"/>` auto-convert to the
|
|
25
|
+
// place's `LabelAnnotation` label (the `name` field), rendered as read-only text.
|
|
26
|
+
// `findByText` retries while the async client provider initializes.
|
|
27
|
+
expect(await screen.findByText('John F. Kennedy Intl')).toBeInTheDocument();
|
|
28
|
+
expect(await screen.findByText('Charles de Gaulle')).toBeInTheDocument();
|
|
29
|
+
|
|
30
|
+
// `<field name="origin.code"/>` / `<field name="destination.code"/>` drill into the
|
|
31
|
+
// leaf sub-field, rendered as editable inputs holding the code.
|
|
32
|
+
expect(await screen.findByDisplayValue('JFK')).toBeInTheDocument();
|
|
33
|
+
expect(await screen.findByDisplayValue('CDG')).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('static layout formats dates and renders labels as read-only text', { timeout: 30_000 }, async () => {
|
|
37
|
+
await NestedLabelStatic.run();
|
|
38
|
+
|
|
39
|
+
// Scope assertions to the form: the debug panel echoes the raw values JSON.
|
|
40
|
+
const form = await screen.findByRole('form');
|
|
41
|
+
|
|
42
|
+
// The depart date renders human-readable (contains the year) rather than the raw ISO
|
|
43
|
+
// string. Match `2026` and assert no ISO time fragment leaks through — timezone-robust.
|
|
44
|
+
expect(within(form).getByText(/2026/)).toBeInTheDocument();
|
|
45
|
+
expect(within(form).queryByText(/T\d\d:\d\d/)).toBeNull();
|
|
46
|
+
|
|
47
|
+
// Nested struct labels and dotted sub-fields render as static text (not inputs).
|
|
48
|
+
expect(within(form).getByText('John F. Kennedy Intl')).toBeInTheDocument();
|
|
49
|
+
expect(within(form).getByText('JFK')).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { xml } from '@codemirror/lang-xml';
|
|
6
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { Annotation, DXN, Format, Type } from '@dxos/echo';
|
|
11
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
|
+
import { Card, Tooltip, useThemeContext } from '@dxos/react-ui';
|
|
13
|
+
import { Editor } from '@dxos/react-ui-editor';
|
|
14
|
+
import { Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { createBasicExtensions, createThemeExtensions } from '@dxos/ui-editor';
|
|
17
|
+
import { mx } from '@dxos/ui-theme';
|
|
18
|
+
import { trim } from '@dxos/util';
|
|
19
|
+
|
|
20
|
+
import { translations } from '#translations';
|
|
21
|
+
|
|
22
|
+
import { TestLayout, TestPanel } from '../../testing';
|
|
23
|
+
import { Form, type FormRootProps, omitId } from '../Form';
|
|
24
|
+
import { FormLayoutAnnotation } from './annotation';
|
|
25
|
+
import { parseLayout } from './parser';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sample schema: a Flight booking carries airline, flight number, route, dates,
|
|
29
|
+
* cabin class. Without an annotation `<Form.FieldSet/>` renders one field per
|
|
30
|
+
* row (see the `Linear` story). The `FormLayoutAnnotation` on this schema
|
|
31
|
+
* arranges the same fields in a 2-column grid with selective spans.
|
|
32
|
+
*/
|
|
33
|
+
const Flight = Schema.Struct({
|
|
34
|
+
airline: Schema.optional(Schema.String.annotations({ title: 'Airline' })),
|
|
35
|
+
flightNumber: Schema.optional(Schema.String.annotations({ title: 'Flight #' })),
|
|
36
|
+
origin: Schema.optional(Schema.String.annotations({ title: 'From' })),
|
|
37
|
+
destination: Schema.optional(Schema.String.annotations({ title: 'To' })),
|
|
38
|
+
departAt: Schema.optional(Format.DateTime.annotations({ title: 'Depart' })),
|
|
39
|
+
arriveAt: Schema.optional(Format.DateTime.annotations({ title: 'Arrive' })),
|
|
40
|
+
cabin: Schema.optional(Schema.Literal('economy', 'premium', 'business', 'first').annotations({ title: 'Cabin' })),
|
|
41
|
+
notes: Schema.optional(Format.Text.annotations({ title: 'Notes' })),
|
|
42
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.flight', '0.1.0')));
|
|
43
|
+
|
|
44
|
+
export type Flight = Type.InstanceType<typeof Flight>;
|
|
45
|
+
|
|
46
|
+
type FlightValues = Omit<Type.InstanceType<typeof Flight>, 'id'>;
|
|
47
|
+
|
|
48
|
+
const flight = {
|
|
49
|
+
airline: 'Air France',
|
|
50
|
+
flightNumber: 'AF-1',
|
|
51
|
+
origin: 'JFK',
|
|
52
|
+
destination: 'CDG',
|
|
53
|
+
departAt: '2026-06-01T15:30:00.000Z',
|
|
54
|
+
arriveAt: '2026-06-02T09:30:00.000Z',
|
|
55
|
+
cabin: 'economy',
|
|
56
|
+
} satisfies Partial<FlightValues>;
|
|
57
|
+
|
|
58
|
+
const FLIGHT_LAYOUT = trim`
|
|
59
|
+
<grid cols="2">
|
|
60
|
+
<field name="airline"/>
|
|
61
|
+
<field name="flightNumber"/>
|
|
62
|
+
<field name="origin"/>
|
|
63
|
+
<field name="destination"/>
|
|
64
|
+
<field name="departAt"/>
|
|
65
|
+
<field name="arriveAt"/>
|
|
66
|
+
<field name="cabin" span="2"/>
|
|
67
|
+
<field name="notes" span="2"/>
|
|
68
|
+
</grid>
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
/** Compact variant — single column, only the headline fields. */
|
|
72
|
+
const FLIGHT_LAYOUT_COMPACT = trim`
|
|
73
|
+
<grid cols="1">
|
|
74
|
+
<field name="airline"/>
|
|
75
|
+
<field name="flightNumber"/>
|
|
76
|
+
<field name="departAt"/>
|
|
77
|
+
</grid>
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Same schema annotated with two named layouts. `Form.Layout name="…"`
|
|
82
|
+
* (or `Form.FieldSet layoutName="…"`) picks the variant; without a name
|
|
83
|
+
* the `'default'` entry is used.
|
|
84
|
+
*/
|
|
85
|
+
const AnnotatedFlight = Type.getSchema(Flight)
|
|
86
|
+
.annotations({})
|
|
87
|
+
.pipe(FormLayoutAnnotation.set({ default: FLIGHT_LAYOUT, compact: FLIGHT_LAYOUT_COMPACT }));
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sample schema with nested `Place` structs carrying a `LabelAnnotation`.
|
|
91
|
+
* Demonstrates the two nested-field DSL behaviors: `<field name="origin"/>`
|
|
92
|
+
* auto-converts to the place's computed label, while `<field name="origin.code"/>`
|
|
93
|
+
* drills into a leaf sub-field.
|
|
94
|
+
*/
|
|
95
|
+
const Place = Schema.Struct({
|
|
96
|
+
name: Schema.optional(Schema.String.annotations({ title: 'Name' })),
|
|
97
|
+
code: Schema.optional(Schema.String.annotations({ title: 'Code' })),
|
|
98
|
+
city: Schema.optional(Schema.String.annotations({ title: 'City' })),
|
|
99
|
+
}).pipe(Annotation.LabelAnnotation.set(['name']));
|
|
100
|
+
|
|
101
|
+
const Journey = Schema.Struct({
|
|
102
|
+
flightNumber: Schema.optional(Schema.String.annotations({ title: 'Flight #' })),
|
|
103
|
+
departAt: Schema.optional(Format.DateTime.annotations({ title: 'Depart' })),
|
|
104
|
+
origin: Schema.optional(Place),
|
|
105
|
+
destination: Schema.optional(Place),
|
|
106
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.journey', '0.1.0')));
|
|
107
|
+
|
|
108
|
+
type JourneyValues = Omit<Type.InstanceType<typeof Journey>, 'id'>;
|
|
109
|
+
|
|
110
|
+
const journey = {
|
|
111
|
+
flightNumber: 'AF-1',
|
|
112
|
+
departAt: '2026-06-01T15:30:00.000Z',
|
|
113
|
+
origin: { name: 'John F. Kennedy Intl', code: 'JFK', city: 'New York' },
|
|
114
|
+
destination: { name: 'Charles de Gaulle', code: 'CDG', city: 'Paris' },
|
|
115
|
+
} satisfies Partial<JourneyValues>;
|
|
116
|
+
|
|
117
|
+
const JOURNEY_LAYOUT = trim`
|
|
118
|
+
<grid cols="2">
|
|
119
|
+
<field name="flightNumber" span="2"/>
|
|
120
|
+
<field name="departAt" span="2"/>
|
|
121
|
+
<field name="origin"/>
|
|
122
|
+
<field name="destination"/>
|
|
123
|
+
<field name="origin.code"/>
|
|
124
|
+
<field name="destination.code"/>
|
|
125
|
+
</grid>
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
type StoryProps = {
|
|
129
|
+
schema: Schema.Schema<any>;
|
|
130
|
+
template?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const DefaultStory = ({ schema, template }: StoryProps) => {
|
|
134
|
+
const [values, setValues] = useState<Partial<FlightValues>>(flight);
|
|
135
|
+
|
|
136
|
+
const handleSave = useCallback<NonNullable<FormRootProps<any>['onSave']>>((next) => {
|
|
137
|
+
setValues(next as Partial<FlightValues>);
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<Tooltip.Provider>
|
|
142
|
+
<TestLayout json={{ values }}>
|
|
143
|
+
<Form.Root schema={schema} defaultValues={values} onSave={handleSave} autoSave>
|
|
144
|
+
<Form.Viewport>
|
|
145
|
+
<Form.Content>
|
|
146
|
+
{template !== undefined ? <Form.Layout schema={schema} template={template} /> : <Form.FieldSet />}
|
|
147
|
+
</Form.Content>
|
|
148
|
+
</Form.Viewport>
|
|
149
|
+
</Form.Root>
|
|
150
|
+
</TestLayout>
|
|
151
|
+
</Tooltip.Provider>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const meta = {
|
|
156
|
+
title: 'ui/react-ui-form/FormLayout',
|
|
157
|
+
render: DefaultStory,
|
|
158
|
+
decorators: [
|
|
159
|
+
withTheme(),
|
|
160
|
+
withLayout({ layout: 'fullscreen' }),
|
|
161
|
+
withClientProvider({ createIdentity: true, createSpace: true }),
|
|
162
|
+
],
|
|
163
|
+
parameters: {
|
|
164
|
+
layout: 'fullscreen',
|
|
165
|
+
translations,
|
|
166
|
+
},
|
|
167
|
+
} satisfies Meta<StoryProps>;
|
|
168
|
+
|
|
169
|
+
export default meta;
|
|
170
|
+
|
|
171
|
+
type Story = StoryObj<StoryProps>;
|
|
172
|
+
|
|
173
|
+
/** Baseline: no annotation, no override — `Form.FieldSet` renders linearly (one field per row). */
|
|
174
|
+
export const Linear: Story = {
|
|
175
|
+
args: {
|
|
176
|
+
schema: omitId(Type.getSchema(Flight)),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** `Form.Layout` invoked directly with a `template` prop, bypassing any annotation. */
|
|
181
|
+
export const TemplateProp: Story = {
|
|
182
|
+
args: {
|
|
183
|
+
schema: omitId(Type.getSchema(Flight)),
|
|
184
|
+
template: FLIGHT_LAYOUT,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/** Schema carries `FormLayoutAnnotation`; `Form.FieldSet` auto-detects and delegates. */
|
|
189
|
+
export const SchemaAnnotation: Story = {
|
|
190
|
+
args: {
|
|
191
|
+
schema: omitId(AnnotatedFlight),
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Same annotated schema, but the story switches between the two named
|
|
197
|
+
* layouts (`default` and `compact`) via a radio above the form.
|
|
198
|
+
*/
|
|
199
|
+
const NamedAnnotationStory = () => {
|
|
200
|
+
const schema = useMemo(() => omitId(AnnotatedFlight) as unknown as Schema.Schema<any>, []);
|
|
201
|
+
const [layoutName, setLayoutName] = useState<'default' | 'compact'>('default');
|
|
202
|
+
const [values, setValues] = useState<Partial<FlightValues>>(flight);
|
|
203
|
+
|
|
204
|
+
const handleSave = useCallback<NonNullable<FormRootProps<any>['onSave']>>((next) => {
|
|
205
|
+
setValues(next as Flight);
|
|
206
|
+
}, []);
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<Tooltip.Provider>
|
|
210
|
+
<TestLayout json={{ layoutName, values }}>
|
|
211
|
+
<div className='flex flex-col gap-2'>
|
|
212
|
+
<div className='flex gap-2 text-sm'>
|
|
213
|
+
{(['default', 'compact'] as const).map((name) => (
|
|
214
|
+
<label key={name} className='flex items-center gap-1'>
|
|
215
|
+
<input type='radio' name='layout' checked={layoutName === name} onChange={() => setLayoutName(name)} />
|
|
216
|
+
{name}
|
|
217
|
+
</label>
|
|
218
|
+
))}
|
|
219
|
+
</div>
|
|
220
|
+
<Form.Root schema={schema} defaultValues={values} onSave={handleSave} autoSave>
|
|
221
|
+
<Form.Viewport>
|
|
222
|
+
<Form.Content>
|
|
223
|
+
<Form.FieldSet layoutName={layoutName} />
|
|
224
|
+
</Form.Content>
|
|
225
|
+
</Form.Viewport>
|
|
226
|
+
</Form.Root>
|
|
227
|
+
</div>
|
|
228
|
+
</TestLayout>
|
|
229
|
+
</Tooltip.Provider>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const NamedAnnotation: Story = {
|
|
234
|
+
render: () => <NamedAnnotationStory />,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Nested struct fields. `origin`/`destination` are `Place` structs with a
|
|
239
|
+
* `LabelAnnotation` — referenced bare they collapse to the place's name, while
|
|
240
|
+
* `origin.code`/`destination.code` drill into the leaf sub-field.
|
|
241
|
+
*/
|
|
242
|
+
const NestedLabelStory = ({ readonly = false }: { readonly?: boolean }) => {
|
|
243
|
+
const schema = useMemo(() => omitId(Type.getSchema(Journey)) as unknown as Schema.Schema<any>, []);
|
|
244
|
+
const [values, setValues] = useState<Partial<JourneyValues>>(journey);
|
|
245
|
+
|
|
246
|
+
const handleSave = useCallback<NonNullable<FormRootProps<any>['onSave']>>((next) => {
|
|
247
|
+
setValues(next as Partial<JourneyValues>);
|
|
248
|
+
}, []);
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<Tooltip.Provider>
|
|
252
|
+
<TestLayout json={{ values }}>
|
|
253
|
+
<Form.Root
|
|
254
|
+
schema={schema}
|
|
255
|
+
defaultValues={values}
|
|
256
|
+
layout={readonly ? 'static' : 'full'}
|
|
257
|
+
readonly={readonly}
|
|
258
|
+
onSave={handleSave}
|
|
259
|
+
autoSave
|
|
260
|
+
>
|
|
261
|
+
<Form.Viewport>
|
|
262
|
+
<Form.Content>
|
|
263
|
+
<Form.Layout schema={schema} template={JOURNEY_LAYOUT} />
|
|
264
|
+
</Form.Content>
|
|
265
|
+
</Form.Viewport>
|
|
266
|
+
</Form.Root>
|
|
267
|
+
</TestLayout>
|
|
268
|
+
</Tooltip.Provider>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const NestedLabel: Story = {
|
|
273
|
+
render: () => <NestedLabelStory />,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/** Read-only static presentation: dates render human-readable; nested structs as labels. */
|
|
277
|
+
export const NestedLabelStatic: Story = {
|
|
278
|
+
render: () => <NestedLabelStory readonly />,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Live playground: the layout template lives in a code editor on the right.
|
|
283
|
+
* The form on the left re-renders as you type. If the template fails to
|
|
284
|
+
* parse, the previous valid layout stays on screen and an error banner
|
|
285
|
+
* surfaces under the editor.
|
|
286
|
+
*/
|
|
287
|
+
type PlaygroundStoryProps = {
|
|
288
|
+
/** Wrap the rendered form in `Card.Root` / `Card.Body` chrome. */
|
|
289
|
+
card?: boolean;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const PlaygroundStory = ({ card = false }: PlaygroundStoryProps) => {
|
|
293
|
+
const schema = useMemo(() => omitId(Type.getSchema(Flight)) as unknown as Schema.Schema<any>, []);
|
|
294
|
+
const [template, setTemplate] = useState(FLIGHT_LAYOUT);
|
|
295
|
+
const [lastValid, setLastValid] = useState(FLIGHT_LAYOUT);
|
|
296
|
+
const [error, setError] = useState<string | undefined>();
|
|
297
|
+
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
try {
|
|
300
|
+
parseLayout(template);
|
|
301
|
+
setLastValid(template);
|
|
302
|
+
setError(undefined);
|
|
303
|
+
} catch (err) {
|
|
304
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
305
|
+
}
|
|
306
|
+
}, [template]);
|
|
307
|
+
|
|
308
|
+
const [values, setValues] = useState<Partial<FlightValues>>(flight);
|
|
309
|
+
|
|
310
|
+
const handleSave = useCallback<NonNullable<FormRootProps<any>['onSave']>>((next) => {
|
|
311
|
+
setValues(next as Partial<FlightValues>);
|
|
312
|
+
}, []);
|
|
313
|
+
|
|
314
|
+
const { themeMode } = useThemeContext();
|
|
315
|
+
const extensions = useMemo(
|
|
316
|
+
() => [
|
|
317
|
+
xml(),
|
|
318
|
+
createBasicExtensions({ placeholder: 'Edit layout DSL…' }),
|
|
319
|
+
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
320
|
+
],
|
|
321
|
+
[themeMode],
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const renderForm = (readonly = false) => (
|
|
325
|
+
<Form.Root
|
|
326
|
+
schema={schema}
|
|
327
|
+
defaultValues={values}
|
|
328
|
+
layout={readonly ? 'static' : 'full'}
|
|
329
|
+
readonly={readonly}
|
|
330
|
+
autoSave
|
|
331
|
+
onSave={handleSave}
|
|
332
|
+
>
|
|
333
|
+
<Form.Viewport>
|
|
334
|
+
<Form.Content>
|
|
335
|
+
<Form.Layout schema={schema} template={lastValid} />
|
|
336
|
+
</Form.Content>
|
|
337
|
+
</Form.Viewport>
|
|
338
|
+
</Form.Root>
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<Tooltip.Provider>
|
|
343
|
+
<div
|
|
344
|
+
className={mx(
|
|
345
|
+
'dx-container grid grid-rows-1 p-4 gap-4 overflow-hidden',
|
|
346
|
+
card ? 'grid-cols-[var(--spacing-card-min-width)_var(--spacing-card-min-width)_1fr]' : 'grid-cols-2',
|
|
347
|
+
)}
|
|
348
|
+
>
|
|
349
|
+
{card ? (
|
|
350
|
+
<>
|
|
351
|
+
<div>
|
|
352
|
+
<Card.Root fullWidth>
|
|
353
|
+
<Card.Header>
|
|
354
|
+
<Card.DragHandle />
|
|
355
|
+
<Card.Title>Read-only</Card.Title>
|
|
356
|
+
<Card.ActionIconButton action='close' onClick={() => console.log('close')} />
|
|
357
|
+
</Card.Header>
|
|
358
|
+
<Card.Body>{renderForm(true)}</Card.Body>
|
|
359
|
+
</Card.Root>
|
|
360
|
+
</div>
|
|
361
|
+
<div>
|
|
362
|
+
<Card.Root fullWidth>
|
|
363
|
+
<Card.Header>
|
|
364
|
+
<Card.DragHandle />
|
|
365
|
+
<Card.Title>Editable</Card.Title>
|
|
366
|
+
<Card.ActionIconButton action='close' onClick={() => console.log('close')} />
|
|
367
|
+
</Card.Header>
|
|
368
|
+
<Card.Body>{renderForm(false)}</Card.Body>
|
|
369
|
+
</Card.Root>
|
|
370
|
+
</div>
|
|
371
|
+
</>
|
|
372
|
+
) : (
|
|
373
|
+
<TestPanel>{renderForm(false)}</TestPanel>
|
|
374
|
+
)}
|
|
375
|
+
<div className='grid grid-rows-3 gap-4 overflow-hidden'>
|
|
376
|
+
<TestPanel>
|
|
377
|
+
<div className='flex flex-col h-full overflow-hidden'>
|
|
378
|
+
<Editor.Root>
|
|
379
|
+
<Editor.View
|
|
380
|
+
classNames='flex-1 overflow-auto font-mono text-sm p-2'
|
|
381
|
+
extensions={extensions}
|
|
382
|
+
value={template}
|
|
383
|
+
onChange={setTemplate}
|
|
384
|
+
/>
|
|
385
|
+
</Editor.Root>
|
|
386
|
+
{error && <div className='border-t border-separator p-2 text-sm text-error-text font-mono'>{error}</div>}
|
|
387
|
+
</div>
|
|
388
|
+
</TestPanel>
|
|
389
|
+
<TestPanel>
|
|
390
|
+
<Syntax.Root data={schema.ast}>
|
|
391
|
+
<Syntax.Content>
|
|
392
|
+
<Syntax.Filter />
|
|
393
|
+
<Syntax.Viewport>
|
|
394
|
+
<Syntax.Code testId='schema' classNames='text-sm' />
|
|
395
|
+
</Syntax.Viewport>
|
|
396
|
+
</Syntax.Content>
|
|
397
|
+
</Syntax.Root>
|
|
398
|
+
</TestPanel>
|
|
399
|
+
<TestPanel>
|
|
400
|
+
<Syntax.Root data={values}>
|
|
401
|
+
<Syntax.Content>
|
|
402
|
+
<Syntax.Filter />
|
|
403
|
+
<Syntax.Viewport>
|
|
404
|
+
<Syntax.Code testId='data' classNames='text-sm' />
|
|
405
|
+
</Syntax.Viewport>
|
|
406
|
+
</Syntax.Content>
|
|
407
|
+
</Syntax.Root>
|
|
408
|
+
</TestPanel>
|
|
409
|
+
</div>
|
|
410
|
+
</div>
|
|
411
|
+
</Tooltip.Provider>
|
|
412
|
+
);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export const FormPlayground: Story = {
|
|
416
|
+
render: () => <PlaygroundStory />,
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
/** Same playground, but the form is rendered inside a `Card.Root` / `Card.Body`. */
|
|
420
|
+
export const CardPlayground: Story = {
|
|
421
|
+
render: () => <PlaygroundStory card />,
|
|
422
|
+
};
|