@dxos/react-ui-form 0.8.4-main.ead640a → 0.8.4-main.effb148878
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 +3252 -2315
- 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 +3252 -2315
- 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 +123 -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 +48 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +95 -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 +25 -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 +116 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.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/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 +13 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +4 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- 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 +37 -10
- 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 +17 -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 +61 -51
- package/src/components/FieldEditor/FieldEditor.stories.tsx +44 -25
- package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
- package/src/components/FieldEditor/FieldEditor.tsx +84 -84
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +134 -252
- package/src/components/Form/Form.tsx +417 -107
- package/src/components/Form/FormField.tsx +332 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +206 -0
- package/src/components/Form/FormFieldSet.tsx +173 -0
- package/src/components/Form/FormTooltipsContext.ts +25 -0
- package/src/components/Form/Layout/FormLayout.stories.tsx +339 -0
- package/src/components/Form/Layout/FormLayout.tsx +123 -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 +185 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/DateField.tsx +95 -0
- package/src/components/Form/fields/GeoPointField.tsx +124 -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 +232 -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 +16 -0
- package/src/components/Form/index.ts +5 -4
- package/src/components/ObjectForm/ObjectForm.tsx +115 -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 +122 -81
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +108 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +147 -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 +65 -73
- package/src/components/ViewEditor/ViewEditor.test.tsx +11 -11
- package/src/components/ViewEditor/ViewEditor.tsx +308 -214
- 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 +78 -0
- package/src/util/properties.ts +38 -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,332 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
import * as String from 'effect/String';
|
|
10
|
+
import React, { useMemo } from 'react';
|
|
11
|
+
|
|
12
|
+
import { Format } from '@dxos/echo';
|
|
13
|
+
import {
|
|
14
|
+
createJsonPath,
|
|
15
|
+
findNode,
|
|
16
|
+
getAnnotation,
|
|
17
|
+
getDiscriminatedType,
|
|
18
|
+
isArrayType,
|
|
19
|
+
isDiscriminatedUnion,
|
|
20
|
+
isLiteralUnion,
|
|
21
|
+
isNestedType,
|
|
22
|
+
} from '@dxos/effect';
|
|
23
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
24
|
+
import { type ProjectionModel } from '@dxos/schema';
|
|
25
|
+
|
|
26
|
+
import { translationKey } from '#translations';
|
|
27
|
+
|
|
28
|
+
import { getRefProps } from '../../util';
|
|
29
|
+
import {
|
|
30
|
+
ArrayField,
|
|
31
|
+
BooleanField,
|
|
32
|
+
DateField,
|
|
33
|
+
GeoPointField,
|
|
34
|
+
MarkdownField,
|
|
35
|
+
NumberField,
|
|
36
|
+
RefField,
|
|
37
|
+
type RefFieldProps,
|
|
38
|
+
SelectField,
|
|
39
|
+
TextAreaField,
|
|
40
|
+
TextField,
|
|
41
|
+
} from './fields';
|
|
42
|
+
import { useFormFieldState } from './Form';
|
|
43
|
+
import {
|
|
44
|
+
type FormFieldComponent,
|
|
45
|
+
type FormFieldComponentProps,
|
|
46
|
+
type FormFieldMap,
|
|
47
|
+
type FormFieldProvider,
|
|
48
|
+
} from './FormFieldComponent';
|
|
49
|
+
import { FormFieldSet } from './FormFieldSet';
|
|
50
|
+
|
|
51
|
+
export type FormFieldProps = {
|
|
52
|
+
/**
|
|
53
|
+
* AST of the property to render.
|
|
54
|
+
*/
|
|
55
|
+
type: SchemaAST.AST;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Name of the property. Used to derive a default label
|
|
59
|
+
* (`title ?? capitalize(name)`) and as the projection lookup key. Pass
|
|
60
|
+
* `null` to suppress the header label entirely -- the form still renders
|
|
61
|
+
* the field/struct, but `FormFieldSet`'s top-level `<FormFieldLabel>` is
|
|
62
|
+
* skipped. Used by `ArrayField` for object-array items, where every item
|
|
63
|
+
* would otherwise repeat the array's parent name.
|
|
64
|
+
*/
|
|
65
|
+
name: string | null;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Path to the current object from the root. Used with nested forms.
|
|
69
|
+
*/
|
|
70
|
+
path?: (string | number)[];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Optional projection for projection-based field management.
|
|
74
|
+
*/
|
|
75
|
+
projection?: ProjectionModel;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Map of custom renderers for specific properties.
|
|
79
|
+
* Prefer fieldProvider for plugin specific input surfaces.
|
|
80
|
+
*/
|
|
81
|
+
fieldMap?: FormFieldMap;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Function to lookup custom renderers for specific properties.
|
|
85
|
+
*/
|
|
86
|
+
fieldProvider?: FormFieldProvider;
|
|
87
|
+
/**
|
|
88
|
+
* Typename of the ref type that the create props apply to.
|
|
89
|
+
* When set, createOptionLabel/createOptionIcon/createInitialValuePath/createFieldMap/onCreate
|
|
90
|
+
* are only passed to ref fields whose typename matches.
|
|
91
|
+
*/
|
|
92
|
+
createTypename?: string;
|
|
93
|
+
} & Pick<FormFieldComponentProps, 'autoFocus' | 'readonly' | 'layout'> &
|
|
94
|
+
Pick<
|
|
95
|
+
RefFieldProps,
|
|
96
|
+
| 'createOptionLabel'
|
|
97
|
+
| 'createOptionIcon'
|
|
98
|
+
| 'createInitialValuePath'
|
|
99
|
+
| 'createFieldMap'
|
|
100
|
+
| 'db'
|
|
101
|
+
| 'useType'
|
|
102
|
+
| 'getOptions'
|
|
103
|
+
| 'onCreate'
|
|
104
|
+
>;
|
|
105
|
+
|
|
106
|
+
export const FormField = (props: FormFieldProps) => {
|
|
107
|
+
const {
|
|
108
|
+
type,
|
|
109
|
+
name,
|
|
110
|
+
path,
|
|
111
|
+
projection,
|
|
112
|
+
fieldMap,
|
|
113
|
+
fieldProvider,
|
|
114
|
+
readonly,
|
|
115
|
+
layout,
|
|
116
|
+
|
|
117
|
+
// RefFieldProps
|
|
118
|
+
createTypename,
|
|
119
|
+
createOptionLabel,
|
|
120
|
+
createOptionIcon,
|
|
121
|
+
createInitialValuePath,
|
|
122
|
+
createFieldMap,
|
|
123
|
+
db,
|
|
124
|
+
useType: schemaHook,
|
|
125
|
+
getOptions,
|
|
126
|
+
onCreate,
|
|
127
|
+
} = props;
|
|
128
|
+
const { t } = useTranslation(translationKey);
|
|
129
|
+
const title = getAnnotation<string>(SchemaAST.TitleAnnotationId)(type);
|
|
130
|
+
const description = getAnnotation<string>(SchemaAST.DescriptionAnnotationId)(type);
|
|
131
|
+
const examples = getAnnotation<string[]>(SchemaAST.ExamplesAnnotationId)(type);
|
|
132
|
+
|
|
133
|
+
// `name === null` means "no header" -- collapse to an empty string so
|
|
134
|
+
// downstream consumers keep their `label: string` types, and the falsy
|
|
135
|
+
// value lets `FormFieldSet`'s `label && <FormFieldLabel ...>` guard skip
|
|
136
|
+
// the header.
|
|
137
|
+
const label = useMemo(() => title ?? (name == null ? '' : String.capitalize(name)), [title, name]);
|
|
138
|
+
const placeholder = useMemo(
|
|
139
|
+
() => (examples?.length ? `${t('example.placeholder')}: ${examples[0]}` : (description ?? label)),
|
|
140
|
+
[examples, description, label],
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const fieldState = useFormFieldState(FormField.displayName, path);
|
|
144
|
+
const jsonPath = createJsonPath(path ?? []);
|
|
145
|
+
const fieldProps: FormFieldComponentProps = {
|
|
146
|
+
type,
|
|
147
|
+
format: Format.FormatAnnotation.getFromAst(type).pipe((annotation) => Option.getOrUndefined(annotation)),
|
|
148
|
+
readonly,
|
|
149
|
+
label,
|
|
150
|
+
jsonPath,
|
|
151
|
+
placeholder,
|
|
152
|
+
layout,
|
|
153
|
+
db,
|
|
154
|
+
...fieldState,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Omit empty fields entirely in read-only mode -- an empty value has nothing
|
|
158
|
+
// to display, so a labelled row with a blank input is just noise. This
|
|
159
|
+
// mirrors what `FormFieldWrapper` already does for `layout === 'static'`, but
|
|
160
|
+
// covers every field type (including those that bypass the wrapper:
|
|
161
|
+
// RefField, SelectField, MarkdownField, ...). Container fields
|
|
162
|
+
// (`ArrayField`, nested-struct -> `FormFieldSet`) keep their own
|
|
163
|
+
// empty-value checks, but those branches only apply when the value is
|
|
164
|
+
// actually a non-null array/object, so this check doesn't interfere.
|
|
165
|
+
if (readonly && fieldState.getValue() == null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Custom field.
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
const CustomField = fieldMap?.[jsonPath];
|
|
174
|
+
if (CustomField) {
|
|
175
|
+
return <CustomField {...fieldProps} />;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// TODO(burdon): Expensive to create schema each time; pass AST?
|
|
179
|
+
const component = fieldProvider?.({ schema: Schema.make(type), prop: name ?? '', fieldProps });
|
|
180
|
+
if (component) {
|
|
181
|
+
return component;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//
|
|
185
|
+
// Array field.
|
|
186
|
+
//
|
|
187
|
+
|
|
188
|
+
if (isArrayType(type)) {
|
|
189
|
+
return <ArrayField fieldProps={fieldState} label={label} {...props} />;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//
|
|
193
|
+
// Regular field.
|
|
194
|
+
//
|
|
195
|
+
|
|
196
|
+
const Field = getFormField(fieldProps);
|
|
197
|
+
if (Field) {
|
|
198
|
+
return <Field {...fieldProps} />;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//
|
|
202
|
+
// Select field.
|
|
203
|
+
//
|
|
204
|
+
|
|
205
|
+
const options = getSelectOptions(type);
|
|
206
|
+
if (options) {
|
|
207
|
+
// Resolve labels from projection metadata when available.
|
|
208
|
+
const fieldProjections = projection?.getFieldProjections();
|
|
209
|
+
const fieldProjection = fieldProjections?.find((fp) => fp.field.path === name);
|
|
210
|
+
const selectOptions = fieldProjection?.props.options;
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<SelectField
|
|
214
|
+
{...fieldProps}
|
|
215
|
+
options={options.map((option) => {
|
|
216
|
+
const selectOption = selectOptions?.find((so) => so.id === globalThis.String(option));
|
|
217
|
+
return {
|
|
218
|
+
value: option,
|
|
219
|
+
label: selectOption?.title ?? option.toString(),
|
|
220
|
+
};
|
|
221
|
+
})}
|
|
222
|
+
/>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
//
|
|
227
|
+
// Ref field.
|
|
228
|
+
//
|
|
229
|
+
|
|
230
|
+
const refProps = getRefProps(type);
|
|
231
|
+
if (refProps) {
|
|
232
|
+
const isCreateTarget = !createTypename || refProps.typename === createTypename;
|
|
233
|
+
return (
|
|
234
|
+
<RefField
|
|
235
|
+
{...fieldProps}
|
|
236
|
+
{...refProps}
|
|
237
|
+
createOptionLabel={isCreateTarget ? createOptionLabel : undefined}
|
|
238
|
+
createOptionIcon={isCreateTarget ? createOptionIcon : undefined}
|
|
239
|
+
createInitialValuePath={isCreateTarget ? createInitialValuePath : undefined}
|
|
240
|
+
createFieldMap={isCreateTarget ? createFieldMap : undefined}
|
|
241
|
+
db={db}
|
|
242
|
+
useType={schemaHook}
|
|
243
|
+
getOptions={getOptions}
|
|
244
|
+
onCreate={onCreate}
|
|
245
|
+
/>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
//
|
|
250
|
+
// Nested Object field.
|
|
251
|
+
//
|
|
252
|
+
|
|
253
|
+
if (isNestedType(type)) {
|
|
254
|
+
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
255
|
+
const typeLiteral = baseNode
|
|
256
|
+
? getDiscriminatedType(baseNode, fieldState.getValue() as any)
|
|
257
|
+
: findNode(type, SchemaAST.isTypeLiteral);
|
|
258
|
+
|
|
259
|
+
if (typeLiteral) {
|
|
260
|
+
const schema = Schema.make(typeLiteral);
|
|
261
|
+
return (
|
|
262
|
+
<FormFieldSet
|
|
263
|
+
schema={schema}
|
|
264
|
+
path={path}
|
|
265
|
+
readonly={readonly}
|
|
266
|
+
layout={layout}
|
|
267
|
+
label={label}
|
|
268
|
+
projection={projection}
|
|
269
|
+
fieldMap={fieldMap}
|
|
270
|
+
fieldProvider={fieldProvider}
|
|
271
|
+
createOptionLabel={createOptionLabel}
|
|
272
|
+
createOptionIcon={createOptionIcon}
|
|
273
|
+
createInitialValuePath={createInitialValuePath}
|
|
274
|
+
db={db}
|
|
275
|
+
useType={schemaHook}
|
|
276
|
+
getOptions={getOptions}
|
|
277
|
+
onCreate={onCreate}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return null;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
FormField.displayName = 'Form.FormField';
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Get property input component.
|
|
290
|
+
*/
|
|
291
|
+
const getFormField = ({ type, format }: FormFieldComponentProps): FormFieldComponent | undefined => {
|
|
292
|
+
//
|
|
293
|
+
// Standard formats.
|
|
294
|
+
//
|
|
295
|
+
|
|
296
|
+
const formatField = Match.value(format).pipe(
|
|
297
|
+
Match.withReturnType<FormFieldComponent | undefined>(),
|
|
298
|
+
Match.when(Format.TypeFormat.Date, () => DateField),
|
|
299
|
+
Match.when(Format.TypeFormat.DateTime, () => DateField),
|
|
300
|
+
Match.when(Format.TypeFormat.GeoPoint, () => GeoPointField),
|
|
301
|
+
Match.when(Format.TypeFormat.Markdown, () => MarkdownField),
|
|
302
|
+
Match.when(Format.TypeFormat.Text, () => TextAreaField),
|
|
303
|
+
Match.when(Format.TypeFormat.Time, () => DateField),
|
|
304
|
+
Match.orElse(() => undefined),
|
|
305
|
+
);
|
|
306
|
+
if (formatField) {
|
|
307
|
+
return formatField;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
//
|
|
311
|
+
// Standard types.
|
|
312
|
+
//
|
|
313
|
+
|
|
314
|
+
switch (type._tag) {
|
|
315
|
+
// TODO(wittjosiah): Schema.Any is currently used to represent template inputs.
|
|
316
|
+
case 'AnyKeyword':
|
|
317
|
+
case 'StringKeyword':
|
|
318
|
+
return TextField;
|
|
319
|
+
case 'NumberKeyword':
|
|
320
|
+
return NumberField;
|
|
321
|
+
case 'BooleanKeyword':
|
|
322
|
+
return BooleanField;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const getSelectOptions = (ast: SchemaAST.AST): Format.Options[] | undefined => {
|
|
327
|
+
if (isLiteralUnion(ast)) {
|
|
328
|
+
return ast.types.map((type) => type.literal).filter((v): v is string | number => v !== null);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return Format.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option.getOrUndefined(annotation));
|
|
332
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { type ChangeEvent, useCallback } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Input } from '@dxos/react-ui';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
|
|
11
|
+
import { type FormFieldComponentProps, FormFieldWrapper } from './FormFieldComponent';
|
|
12
|
+
|
|
13
|
+
const DefaultStory = ({
|
|
14
|
+
type,
|
|
15
|
+
placeholder,
|
|
16
|
+
readonly,
|
|
17
|
+
onBlur,
|
|
18
|
+
onValueChange,
|
|
19
|
+
...props
|
|
20
|
+
}: FormFieldComponentProps<string>) => {
|
|
21
|
+
const handleChange = useCallback(
|
|
22
|
+
(event: ChangeEvent<HTMLInputElement>) => onValueChange(type, event.target.value),
|
|
23
|
+
[type, onValueChange],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className='p-form-padding'>
|
|
28
|
+
<FormFieldWrapper<string> {...props}>
|
|
29
|
+
{({ value = '' }) => (
|
|
30
|
+
<Input.TextInput
|
|
31
|
+
disabled={!!readonly}
|
|
32
|
+
placeholder={placeholder}
|
|
33
|
+
noAutoFill
|
|
34
|
+
value={value}
|
|
35
|
+
onChange={handleChange}
|
|
36
|
+
onBlur={onBlur}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
</FormFieldWrapper>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const meta: Meta<typeof DefaultStory> = {
|
|
45
|
+
title: 'ui/react-ui-form/FormFieldComponent',
|
|
46
|
+
component: DefaultStory,
|
|
47
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
48
|
+
parameters: {
|
|
49
|
+
layout: 'fullscreen',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
|
|
55
|
+
type Story = StoryObj<typeof meta>;
|
|
56
|
+
|
|
57
|
+
export const Default: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
label: 'Label',
|
|
60
|
+
getStatus: () => ({ status: 'error', error: 'Required field' }),
|
|
61
|
+
getValue: () => 'DXOS',
|
|
62
|
+
onBlur: () => {},
|
|
63
|
+
onValueChange: () => {},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
import type * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
import React, {
|
|
8
|
+
Component,
|
|
9
|
+
type FC,
|
|
10
|
+
type FocusEvent,
|
|
11
|
+
type PropsWithChildren,
|
|
12
|
+
type ReactElement,
|
|
13
|
+
type ReactNode,
|
|
14
|
+
} from 'react';
|
|
15
|
+
|
|
16
|
+
import { type Database } from '@dxos/echo';
|
|
17
|
+
import { type Format } from '@dxos/echo/internal';
|
|
18
|
+
import { Icon, Input, Tooltip } from '@dxos/react-ui';
|
|
19
|
+
import { inputTextLabel } from '@dxos/react-ui';
|
|
20
|
+
import { mx } from '@dxos/ui-theme';
|
|
21
|
+
|
|
22
|
+
import { type FormFieldStatus } from '../../hooks';
|
|
23
|
+
import { useFormTooltips } from './FormTooltipsContext';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Dynamic props passed to input components.
|
|
27
|
+
*/
|
|
28
|
+
export type FormFieldStateProps<T = any> = {
|
|
29
|
+
getStatus: () => FormFieldStatus;
|
|
30
|
+
getValue: () => T | undefined;
|
|
31
|
+
onBlur: (event: FocusEvent<HTMLElement>) => void;
|
|
32
|
+
onValueChange: (type: SchemaAST.AST, value: T) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Presentation mode.
|
|
37
|
+
* - full: Show label, control, and status.
|
|
38
|
+
* - compact: Show label and control.
|
|
39
|
+
* - inline: Control only.
|
|
40
|
+
* - static: Plain DOM; omit all undefined values.
|
|
41
|
+
*/
|
|
42
|
+
// TODO(burdon): 'inline' should be orthogonal to the layout (e.g., array of inline static).
|
|
43
|
+
export type Presentation = 'full' | 'compact' | 'inline' | 'static';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Props passed to input components.
|
|
47
|
+
*/
|
|
48
|
+
export type FormFieldComponentProps<T = any> = {
|
|
49
|
+
type: SchemaAST.AST;
|
|
50
|
+
format?: Format.TypeFormat;
|
|
51
|
+
readonly?: boolean;
|
|
52
|
+
label: string;
|
|
53
|
+
/**
|
|
54
|
+
* Dotted JSON path of this field within the form values (e.g.
|
|
55
|
+
* `runtime.client.storage.persistent`). Forwarded to `FormFieldLabel` so
|
|
56
|
+
* that it can render the path as a debug hint when the enclosing
|
|
57
|
+
* `Form.Root` has `debug` enabled.
|
|
58
|
+
*/
|
|
59
|
+
jsonPath?: string;
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
autoFocus?: boolean;
|
|
62
|
+
layout?: Presentation;
|
|
63
|
+
/** Database the form is editing against; populated for fields whose value is an ECHO object/Ref. */
|
|
64
|
+
db?: Database.Database;
|
|
65
|
+
} & FormFieldStateProps<T>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Form field component.
|
|
69
|
+
*/
|
|
70
|
+
export type FormFieldComponent = FC<FormFieldComponentProps>;
|
|
71
|
+
|
|
72
|
+
export type FormFieldMap = Record<string, FormFieldComponent>;
|
|
73
|
+
|
|
74
|
+
export type FormFieldProvider = (props: {
|
|
75
|
+
prop: string; // TODO(burdon): Path?
|
|
76
|
+
schema: Schema.Schema<any>;
|
|
77
|
+
fieldProps: FormFieldComponentProps;
|
|
78
|
+
}) => ReactElement | undefined;
|
|
79
|
+
|
|
80
|
+
//
|
|
81
|
+
// FormFieldLabel
|
|
82
|
+
//
|
|
83
|
+
|
|
84
|
+
export type FormFieldLabelProps = {
|
|
85
|
+
asChild?: boolean;
|
|
86
|
+
error?: string;
|
|
87
|
+
/**
|
|
88
|
+
* JSON path of the field this label describes (e.g. `runtime.client.storage.persistent`).
|
|
89
|
+
* Surfaced as a hover tooltip on the label when the enclosing `Form.Root`
|
|
90
|
+
* has `tooltips` enabled (the default) -- useful for spotting which field
|
|
91
|
+
* maps to which path when authoring schemas or filing bugs against a form.
|
|
92
|
+
* Callers can supply the path unconditionally; the label suppresses the
|
|
93
|
+
* tooltip when `Form.Root tooltips={false}`.
|
|
94
|
+
*/
|
|
95
|
+
path?: string;
|
|
96
|
+
} & Pick<FormFieldComponentProps, 'label' | 'readonly'>;
|
|
97
|
+
|
|
98
|
+
export const FormFieldLabel = ({ label, error, readonly, asChild, path }: FormFieldLabelProps) => {
|
|
99
|
+
const tooltips = useFormTooltips();
|
|
100
|
+
const Label = readonly || asChild ? 'span' : Input.Label;
|
|
101
|
+
const labelNode = <Label className={mx(inputTextLabel, 'text-sm')}>{label}</Label>;
|
|
102
|
+
return (
|
|
103
|
+
<div className='flex items-center justify-between'>
|
|
104
|
+
{tooltips && path ? (
|
|
105
|
+
<Tooltip.Trigger asChild content={path} side='bottom'>
|
|
106
|
+
{labelNode}
|
|
107
|
+
</Tooltip.Trigger>
|
|
108
|
+
) : (
|
|
109
|
+
labelNode
|
|
110
|
+
)}
|
|
111
|
+
{error && (
|
|
112
|
+
<Tooltip.Trigger asChild content={error} side='bottom'>
|
|
113
|
+
<Icon icon='ph--warning--regular' size={4} classNames='text-error-text' />
|
|
114
|
+
</Tooltip.Trigger>
|
|
115
|
+
)}
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
FormFieldLabel.displayName = 'Form.FieldLabel';
|
|
121
|
+
|
|
122
|
+
//
|
|
123
|
+
// FormFieldWrapper
|
|
124
|
+
//
|
|
125
|
+
|
|
126
|
+
export type FormFieldWrapperProps<T = any> = Pick<
|
|
127
|
+
FormFieldComponentProps,
|
|
128
|
+
'readonly' | 'label' | 'layout' | 'getStatus' | 'getValue' | 'jsonPath'
|
|
129
|
+
> & {
|
|
130
|
+
children?: (props: { value: T }) => ReactNode;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const FormFieldWrapper = <T,>(props: FormFieldWrapperProps<T>) => {
|
|
134
|
+
const { children, readonly, layout, label, jsonPath, getStatus, getValue } = props;
|
|
135
|
+
const { status, error } = getStatus();
|
|
136
|
+
|
|
137
|
+
const value = getValue();
|
|
138
|
+
if (layout === 'static' && value == null) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const str = String(value ?? '');
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<div className='contents'>
|
|
146
|
+
<Input.Root validationValence={status}>
|
|
147
|
+
{layout !== 'inline' && <FormFieldLabel error={error} readonly={readonly} label={label} path={jsonPath} />}
|
|
148
|
+
{layout === 'static' ? (
|
|
149
|
+
<p className='truncate min-w-0' title={str}>
|
|
150
|
+
{str}
|
|
151
|
+
</p>
|
|
152
|
+
) : children ? (
|
|
153
|
+
children({ value })
|
|
154
|
+
) : null}
|
|
155
|
+
{layout === 'full' && error && (
|
|
156
|
+
<Input.DescriptionAndValidation>
|
|
157
|
+
<Input.Validation>{error}</Input.Validation>
|
|
158
|
+
</Input.DescriptionAndValidation>
|
|
159
|
+
)}
|
|
160
|
+
</Input.Root>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//
|
|
166
|
+
// FormFieldErrorBoundary
|
|
167
|
+
//
|
|
168
|
+
|
|
169
|
+
type FormFieldErrorState = {
|
|
170
|
+
error: Error | undefined;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
type FormFieldErrorBoundaryProps = PropsWithChildren<{
|
|
174
|
+
path?: (string | number)[];
|
|
175
|
+
}>;
|
|
176
|
+
|
|
177
|
+
export class FormFieldErrorBoundary extends Component<FormFieldErrorBoundaryProps, FormFieldErrorState> {
|
|
178
|
+
static getDerivedStateFromError(error: Error): { error: Error } {
|
|
179
|
+
return { error };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
override state = { error: undefined };
|
|
183
|
+
|
|
184
|
+
override componentDidUpdate(prevProps: FormFieldErrorBoundaryProps) {
|
|
185
|
+
if (prevProps.path !== this.props.path) {
|
|
186
|
+
this.resetError();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
override render() {
|
|
191
|
+
if (this.state.error) {
|
|
192
|
+
return (
|
|
193
|
+
<div className='flex gap-2 border border-rose-fill font-mono text-sm'>
|
|
194
|
+
<span className='bg-rose-fill text-base-foreground px-1 font-thin'>ERROR</span>
|
|
195
|
+
{String(this.props.path?.join('.'))}
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return this.props.children;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private resetError() {
|
|
204
|
+
this.setState({ error: undefined });
|
|
205
|
+
}
|
|
206
|
+
}
|