@dxos/react-ui-form 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +2753 -2121
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2753 -2121
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +8 -8
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +83 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +86 -25
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +129 -56
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +43 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -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 +18 -0
- package/dist/types/src/components/Form/FormFieldSet.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/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 +4 -0
- package/dist/types/src/components/Form/fields/MarkdownField.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 +16 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -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 +83 -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 +12 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +2 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +9 -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 +54 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +86 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
- 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 +83 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.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/Settings/Settings.d.ts +43 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +83 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +38 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts +17 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +3 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +22 -10
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +85 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -4
- 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/translations.d.ts +64 -55
- 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 +7 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +3 -3
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -43
- package/src/components/FieldEditor/FieldEditor.stories.tsx +48 -31
- package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
- package/src/components/FieldEditor/FieldEditor.tsx +84 -90
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +144 -222
- package/src/components/Form/Form.tsx +359 -96
- package/src/components/Form/FormField.tsx +304 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +171 -0
- package/src/components/Form/FormFieldSet.tsx +144 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +154 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/GeoPointField.tsx +120 -0
- package/src/components/Form/fields/MarkdownField.tsx +78 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +198 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/fields/SelectOptionField.stories.tsx +65 -0
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +36 -31
- 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 -10
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectForm/ObjectForm.tsx +113 -0
- package/src/components/{ControlSection → ObjectForm}/index.ts +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +209 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +186 -0
- package/src/components/ObjectPicker/index.ts +5 -0
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +63 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +129 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/Settings/Settings.stories.tsx +103 -0
- package/src/components/Settings/Settings.tsx +81 -0
- package/src/components/Settings/SettingsFieldSet.tsx +211 -0
- package/src/components/Settings/SettingsItem.tsx +62 -0
- package/src/components/Settings/index.ts +6 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +139 -63
- package/src/components/ViewEditor/ViewEditor.test.tsx +12 -15
- package/src/components/ViewEditor/ViewEditor.tsx +346 -211
- package/src/components/index.ts +4 -3
- package/src/components/testing.tsx +28 -12
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +380 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/translations.ts +67 -59
- package/src/util/field-type.ts +57 -0
- package/src/util/field.ts +33 -43
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +2 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +17 -19
- 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 -8
- 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 -57
- 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 -26
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -12
- 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 -7
- 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/components/deprecated/Form.d.ts +0 -15
- package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/index.d.ts +0 -2
- package/dist/types/src/components/deprecated/index.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 -23
- 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 -42
- package/src/components/ControlSection/ControlSection.tsx +0 -139
- package/src/components/Form/ArrayField.tsx +0 -125
- package/src/components/Form/Defaults.tsx +0 -204
- package/src/components/Form/FormActions.tsx +0 -54
- package/src/components/Form/FormContent.tsx +0 -241
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -51
- package/src/components/Form/RefField.tsx +0 -214
- package/src/components/Form/custom/GeoPointInput.tsx +0 -72
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +0 -62
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -31
- package/src/components/deprecated/Form.stories.tsx +0 -63
- package/src/components/deprecated/Form.tsx +0 -119
- package/src/components/deprecated/FormInput.tsx +0 -71
- package/src/components/deprecated/index.ts +0 -5
- package/src/hooks/useForm.ts +0 -293
- package/src/hooks/useQueryRefOptions.ts +0 -53
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -14
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/factory.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,UAAU,EAAE,SAAS,UAAU,GAAG,MAAM,KAAG,cAAc,GAAG,SAgBnG,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Schema } from 'effect';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
4
|
-
import { type Projection } from '@dxos/schema';
|
|
5
|
-
export type DeprecatedFormProps<T extends {} = {}> = ThemedClassName<{
|
|
6
|
-
projection: Projection;
|
|
7
|
-
object: T;
|
|
8
|
-
schema?: Schema.Schema<T>;
|
|
9
|
-
readonly?: boolean;
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Schema-based object form.
|
|
13
|
-
*/
|
|
14
|
-
export declare const DeprecatedForm: <T extends {} = {}>({ classNames, projection, object, schema, readonly, }: DeprecatedFormProps<T>) => React.JSX.Element;
|
|
15
|
-
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/Form.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,MAAM,EAAmB,MAAM,QAAQ,CAAC;AAC9D,OAAO,KAAmB,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAsD,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE1G,OAAO,EAAE,KAAK,UAAU,EAAgC,MAAM,cAAc,CAAC;AAE7E,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,eAAe,CAAC;IACnE,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,CAAC,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,uDAM/C,mBAAmB,CAAC,CAAC,CAAC,sBA0DxB,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import '@dxos-theme';
|
|
2
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { type TestType } from '@dxos/schema/testing';
|
|
5
|
-
import { type DeprecatedFormProps } from './Form';
|
|
6
|
-
declare const DefaultStory: (props: DeprecatedFormProps) => React.JSX.Element;
|
|
7
|
-
declare const meta: Meta<typeof DefaultStory>;
|
|
8
|
-
export default meta;
|
|
9
|
-
type Story = StoryObj<DeprecatedFormProps<TestType>>;
|
|
10
|
-
export declare const Default: Story;
|
|
11
|
-
export declare const Empty: Story;
|
|
12
|
-
export declare const Readonly: Story;
|
|
13
|
-
//# sourceMappingURL=Form.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Form.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/Form.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAc,KAAK,QAAQ,EAAsB,MAAM,sBAAsB,CAAC;AAMrF,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAElE,QAAA,MAAM,YAAY,GAAI,OAAO,mBAAmB,sBAM/C,CAAC;AAEF,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAQnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAErD,eAAO,MAAM,OAAO,EAAE,KAMrB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,KAKnB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAOtB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type JSX, type PropsWithChildren } from 'react';
|
|
2
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated
|
|
5
|
-
*/
|
|
6
|
-
export declare const DeprecatedFormContainer: ({ children, classNames }: ThemedClassName<PropsWithChildren>) => JSX.Element;
|
|
7
|
-
export type DeprecatedFormInputProps = {
|
|
8
|
-
label: string;
|
|
9
|
-
description?: JSX.Element;
|
|
10
|
-
secondary?: JSX.Element;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated
|
|
14
|
-
*/
|
|
15
|
-
export declare const DeprecatedFormInput: ({ label, description, secondary, children, }: PropsWithChildren<DeprecatedFormInputProps>) => JSX.Element;
|
|
16
|
-
//# sourceMappingURL=FormInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormInput.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/FormInput.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAE,KAAK,GAAG,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAG7D;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,0BAA0B,eAAe,CAAC,iBAAiB,CAAC,gBAQnG,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,8CAKjC,iBAAiB,CAAC,wBAAwB,CAAC,gBAkC7C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { type Schema } from 'effect';
|
|
2
|
-
import { type BaseObject } from '@dxos/echo-schema';
|
|
3
|
-
import { type JsonPath, type SimpleType } from '@dxos/effect';
|
|
4
|
-
import { type ValidationError } from '@dxos/schema';
|
|
5
|
-
import { type MaybePromise } from '@dxos/util';
|
|
6
|
-
/**
|
|
7
|
-
* Return type from `useForm` hook.
|
|
8
|
-
*/
|
|
9
|
-
export type FormHandler<T extends BaseObject> = {
|
|
10
|
-
values: Partial<T>;
|
|
11
|
-
errors: Record<JsonPath, string>;
|
|
12
|
-
touched: Record<JsonPath, boolean>;
|
|
13
|
-
changed: Record<JsonPath, boolean>;
|
|
14
|
-
canSave: boolean;
|
|
15
|
-
formIsValid: boolean;
|
|
16
|
-
handleSave: () => void;
|
|
17
|
-
getStatus: (path: string | (string | number)[]) => {
|
|
18
|
-
status?: 'error';
|
|
19
|
-
error?: string;
|
|
20
|
-
};
|
|
21
|
-
getValue: <V>(path: (string | number)[]) => V | undefined;
|
|
22
|
-
onValueChange: <V>(path: (string | number)[], type: SimpleType, value: V) => void;
|
|
23
|
-
onTouched: (path: (string | number)[]) => void;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Hook options.
|
|
27
|
-
*/
|
|
28
|
-
export interface FormOptions<T extends BaseObject> {
|
|
29
|
-
/**
|
|
30
|
-
* Effect schema (Type literal).
|
|
31
|
-
*/
|
|
32
|
-
schema: Schema.Schema<T, any>;
|
|
33
|
-
/**
|
|
34
|
-
* Initial values (which may not pass validation).
|
|
35
|
-
*/
|
|
36
|
-
initialValues: Partial<T>;
|
|
37
|
-
/**
|
|
38
|
-
* Callback for value changes. Note: This is called even when values are invalid.
|
|
39
|
-
* Sometimes the parent component may want to know about changes even if the form is
|
|
40
|
-
* in an invalid state.
|
|
41
|
-
*/
|
|
42
|
-
onValuesChanged?: (values: Partial<T>) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Custom validation function that runs only after schema validation passes.
|
|
45
|
-
* Use this for complex validation logic that can't be expressed in the schema.
|
|
46
|
-
* @returns Array of validation errors, or undefined if validation passes
|
|
47
|
-
*/
|
|
48
|
-
onValidate?: (values: T) => ValidationError[] | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Called when the form is valid.
|
|
51
|
-
*/
|
|
52
|
-
onValid?: (values: T, meta: {
|
|
53
|
-
changed: FormHandler<T>['changed'];
|
|
54
|
-
}) => void;
|
|
55
|
-
/**
|
|
56
|
-
* Called when the form is submitted and passes validation.
|
|
57
|
-
*/
|
|
58
|
-
onSave?: (values: T, meta: {
|
|
59
|
-
changed: FormHandler<T>['changed'];
|
|
60
|
-
}) => MaybePromise<void>;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Creates a hook for managing form state, including values, validation, and submission.
|
|
64
|
-
* Deeply integrated with `@dxos/schema` for schema-based validation.
|
|
65
|
-
*/
|
|
66
|
-
export declare const useForm: <T extends BaseObject>({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave, }: FormOptions<T>) => FormHandler<T>;
|
|
67
|
-
//# sourceMappingURL=useForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,QAAQ,CAAC;AAGhD,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAA4C,MAAM,cAAc,CAAC;AAGxG,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,IAAI;IAK9C,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IAGrB,UAAU,EAAE,MAAM,IAAI,CAAC;IAMvB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxF,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;IAC1D,aAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAClF,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,UAAU;IAC/C;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE9B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAE1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAE/C;;;;OAIG;IAEH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,eAAe,EAAE,GAAG,SAAS,CAAC;IAE1D;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;KAAE,KAAK,IAAI,CAAC;IAE5E;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;KAAE,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CAC1F;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,UAAU,EAAE,0EAO3C,WAAW,CAAC,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,CAoLhC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type TypeAnnotation } from '@dxos/echo-schema';
|
|
2
|
-
import { type DXN } from '@dxos/keys';
|
|
3
|
-
import { type TagPickerItemData } from '@dxos/react-ui-tag-picker';
|
|
4
|
-
import { type MaybePromise } from '@dxos/util';
|
|
5
|
-
export type RefOption = {
|
|
6
|
-
dxn: DXN;
|
|
7
|
-
label?: string;
|
|
8
|
-
};
|
|
9
|
-
export type QueryRefOptions = (type: TypeAnnotation) => MaybePromise<RefOption[]>;
|
|
10
|
-
type UseQueryRefOptionsProps = {
|
|
11
|
-
refTypeInfo: TypeAnnotation | undefined;
|
|
12
|
-
onQueryRefOptions?: QueryRefOptions;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Hook to query reference options based on type information.
|
|
16
|
-
* Used internally within forms to fetch and format reference options for reference fields.
|
|
17
|
-
*/
|
|
18
|
-
export declare const useQueryRefOptions: ({ refTypeInfo, onQueryRefOptions }: UseQueryRefOptionsProps) => {
|
|
19
|
-
options: TagPickerItemData[];
|
|
20
|
-
loading: boolean;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=useQueryRefOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryRefOptions.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useQueryRefOptions.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;AAElF,KAAK,uBAAuB,GAAG;IAAE,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC;IAAC,iBAAiB,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC;AAEhH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,oCAAoC,uBAAuB;;;CA+B7F,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
2
|
-
import { type QueryRefOptions } from './useQueryRefOptions';
|
|
3
|
-
type UseRefQueryLookupProps = {
|
|
4
|
-
space?: Space;
|
|
5
|
-
};
|
|
6
|
-
export declare const useRefQueryLookupHandler: ({ space }: UseRefQueryLookupProps) => QueryRefOptions;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=useRefQueryLookupHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRefQueryLookupHandler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useRefQueryLookupHandler.ts"],"names":[],"mappings":"AAOA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,KAAK,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhD,eAAO,MAAM,wBAAwB,GAAI,WAAW,sBAAsB,KAAG,eAwB5E,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/util/schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC,eAAO,MAAM,oBAAoB,GAAI,KAAK,SAAS,CAAC,GAAG,8BAKtD,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React from 'react';
|
|
9
|
-
|
|
10
|
-
import { StackItem } from '@dxos/react-ui-stack';
|
|
11
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
|
-
|
|
13
|
-
import { translations } from '../../translations';
|
|
14
|
-
|
|
15
|
-
import { ControlPage, ControlSection, type ControlSectionProps } from './ControlSection';
|
|
16
|
-
|
|
17
|
-
const meta: Meta<ControlSectionProps> = {
|
|
18
|
-
title: 'ui/react-ui-form/ControlSection',
|
|
19
|
-
component: ControlSection,
|
|
20
|
-
render: (args) => (
|
|
21
|
-
<StackItem.Content classNames='w-[40rem]'>
|
|
22
|
-
<ControlPage>
|
|
23
|
-
<ControlSection {...args} />
|
|
24
|
-
</ControlPage>
|
|
25
|
-
</StackItem.Content>
|
|
26
|
-
),
|
|
27
|
-
decorators: [withLayout({ fullscreen: true, classNames: 'justify-center' }), withTheme],
|
|
28
|
-
parameters: {
|
|
29
|
-
translations,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default meta;
|
|
34
|
-
|
|
35
|
-
type Story = StoryObj<ControlSectionProps>;
|
|
36
|
-
|
|
37
|
-
export const Default: Story = {
|
|
38
|
-
args: {
|
|
39
|
-
title: 'Control Section',
|
|
40
|
-
description: 'This is a control section',
|
|
41
|
-
},
|
|
42
|
-
};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type ComponentPropsWithoutRef, type PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
Button,
|
|
9
|
-
type ButtonProps,
|
|
10
|
-
Input,
|
|
11
|
-
type Label,
|
|
12
|
-
type ThemedClassName,
|
|
13
|
-
toLocalizedString,
|
|
14
|
-
useTranslation,
|
|
15
|
-
} from '@dxos/react-ui';
|
|
16
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
17
|
-
|
|
18
|
-
import { translationKey } from '../../translations';
|
|
19
|
-
|
|
20
|
-
export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
|
|
21
|
-
|
|
22
|
-
export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
|
|
23
|
-
return (
|
|
24
|
-
<div role='none' className={mx('pli-cardSpacingInline', classNames)} {...props}>
|
|
25
|
-
{children}
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type ControlSectionProps = PropsWithChildren<{
|
|
31
|
-
title: Label;
|
|
32
|
-
description?: Label;
|
|
33
|
-
}>;
|
|
34
|
-
|
|
35
|
-
export const ControlSection = ({ title, description, children }: ControlSectionProps) => {
|
|
36
|
-
return (
|
|
37
|
-
<>
|
|
38
|
-
<ControlSectionHeading title={title} description={description} />
|
|
39
|
-
{children}
|
|
40
|
-
</>
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const ControlSectionHeading = ({ title, description }: Omit<ControlSectionProps, 'children'>) => {
|
|
45
|
-
const { t } = useTranslation(translationKey);
|
|
46
|
-
return (
|
|
47
|
-
<>
|
|
48
|
-
<h2 className='pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd'>{toLocalizedString(title, t)}</h2>
|
|
49
|
-
{description && (
|
|
50
|
-
<p className='pli-trimMd mlb-trimMd container-max-width text-description'>
|
|
51
|
-
{toLocalizedString(description, t)}
|
|
52
|
-
</p>
|
|
53
|
-
)}
|
|
54
|
-
</>
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const ControlGroupButton = ({ classNames, ...props }: ButtonProps) => {
|
|
59
|
-
return <Button {...props} classNames={['md:col-span-2', classNames]} />;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export type ControlGroupProps = ThemedClassName<PropsWithChildren<{}>>;
|
|
63
|
-
|
|
64
|
-
export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
|
|
65
|
-
<div
|
|
66
|
-
role='none'
|
|
67
|
-
className={mx('group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd', classNames)}
|
|
68
|
-
>
|
|
69
|
-
{children}
|
|
70
|
-
</div>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
export const ControlFrame = ({ children }: ControlGroupProps) => (
|
|
74
|
-
<div
|
|
75
|
-
role='none'
|
|
76
|
-
className='p-trimMd container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd border border-separator rounded-md'
|
|
77
|
-
>
|
|
78
|
-
{children}
|
|
79
|
-
</div>
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
export type ControlItemProps = PropsWithChildren<{
|
|
83
|
-
title: Label;
|
|
84
|
-
description?: Label;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
export const controlItemClasses =
|
|
88
|
-
'pli-trimMd plb-trimMd container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-trimSm border border-separator rounded-md *:first:!mbs-0 *:last:!mbe-0';
|
|
89
|
-
|
|
90
|
-
const controlItemTitleClasses = 'text-lg font-normal';
|
|
91
|
-
const controlItemDescriptionClasses = 'text-base mlb-trimSm md:mbe-0 text-description';
|
|
92
|
-
|
|
93
|
-
export const ControlItem = ({ title, description, children }: ControlItemProps) => {
|
|
94
|
-
const { t } = useTranslation(translationKey);
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<div className={controlItemClasses}>
|
|
98
|
-
<div role='none'>
|
|
99
|
-
<h3 className={controlItemTitleClasses}>{toLocalizedString(title, t)}</h3>
|
|
100
|
-
{description && <p className={controlItemDescriptionClasses}>{toLocalizedString(description, t)}</p>}
|
|
101
|
-
</div>
|
|
102
|
-
{children}
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const ControlItemInput = ({ title, description, children }: ControlItemProps) => {
|
|
108
|
-
const { t } = useTranslation(translationKey);
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<Input.Root>
|
|
112
|
-
<div className={controlItemClasses}>
|
|
113
|
-
<div role='none'>
|
|
114
|
-
<Input.Label classNames={controlItemTitleClasses}>{toLocalizedString(title, t)}</Input.Label>
|
|
115
|
-
{description && (
|
|
116
|
-
<Input.DescriptionAndValidation>
|
|
117
|
-
<Input.Description classNames={controlItemDescriptionClasses}>
|
|
118
|
-
{toLocalizedString(description, t)}
|
|
119
|
-
</Input.Description>
|
|
120
|
-
</Input.DescriptionAndValidation>
|
|
121
|
-
)}
|
|
122
|
-
</div>
|
|
123
|
-
{children}
|
|
124
|
-
</div>
|
|
125
|
-
</Input.Root>
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const ControlFrameItem = ({ title, description, children }: ControlItemProps) => {
|
|
130
|
-
const { t } = useTranslation(translationKey);
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<div role='group' className='min-is-0'>
|
|
134
|
-
<h3 className='text-lg mbe-2'>{toLocalizedString(title, t)}</h3>
|
|
135
|
-
{description && <p className='mlb-trimSm md:mbe-0 text-description'>{toLocalizedString(description, t)}</p>}
|
|
136
|
-
{children}
|
|
137
|
-
</div>
|
|
138
|
-
);
|
|
139
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { SchemaAST, pipe } from 'effect';
|
|
6
|
-
import { capitalize } from 'effect/String';
|
|
7
|
-
import React, { Fragment, useCallback } from 'react';
|
|
8
|
-
|
|
9
|
-
import { SimpleType, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
|
|
10
|
-
import { invariant } from '@dxos/invariant';
|
|
11
|
-
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
12
|
-
import { type SchemaProperty, getSchemaProperties } from '@dxos/schema';
|
|
13
|
-
|
|
14
|
-
import { translationKey } from '../../translations';
|
|
15
|
-
import { findArrayElementType } from '../../util';
|
|
16
|
-
|
|
17
|
-
import { type ComponentLookup } from './Form';
|
|
18
|
-
import { FormField } from './FormContent';
|
|
19
|
-
import { type FormInputStateProps, useFormValues } from './FormContext';
|
|
20
|
-
import { type InputComponent, InputHeader } from './Input';
|
|
21
|
-
|
|
22
|
-
type ArrayFieldProps = {
|
|
23
|
-
property: SchemaProperty<any>;
|
|
24
|
-
readonly?: boolean;
|
|
25
|
-
inputProps: FormInputStateProps;
|
|
26
|
-
path?: (string | number)[];
|
|
27
|
-
Custom?: Partial<Record<string, InputComponent>>;
|
|
28
|
-
lookupComponent?: ComponentLookup;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }: ArrayFieldProps) => {
|
|
32
|
-
const { t } = useTranslation(translationKey);
|
|
33
|
-
const { ast, name, type, title } = property;
|
|
34
|
-
// TODO(wittjosiah): The fallback to an empty array stops the form from crashing but isn't immediately live.
|
|
35
|
-
// It doesn't become live until another field is touched, but that's better than the whole form crashing.
|
|
36
|
-
const values = (useFormValues(path ?? []) ?? []) as any[];
|
|
37
|
-
invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
|
|
38
|
-
const label = title ?? pipe(name, capitalize);
|
|
39
|
-
|
|
40
|
-
const elementType = findArrayElementType(ast);
|
|
41
|
-
|
|
42
|
-
const getDefaultObjectValue = (typeNode: SchemaAST.AST): any => {
|
|
43
|
-
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
44
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST.isTypeLiteral);
|
|
45
|
-
if (!typeLiteral) {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [prop.name, prop.defaultValue]));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const getDefaultValue = () =>
|
|
53
|
-
type === 'object' && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
54
|
-
|
|
55
|
-
const handleAdd = useCallback(() => {
|
|
56
|
-
inputProps.onValueChange(type, [...values, getDefaultValue()]);
|
|
57
|
-
}, [type, elementType, inputProps, values]);
|
|
58
|
-
|
|
59
|
-
const handleRemove = useCallback(
|
|
60
|
-
(index: number) => {
|
|
61
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
62
|
-
inputProps.onValueChange(type, newValues);
|
|
63
|
-
},
|
|
64
|
-
[type, inputProps, values],
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
if (!elementType) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return readonly && values.length < 1 ? null : (
|
|
72
|
-
<>
|
|
73
|
-
<InputHeader readonly label={label} />
|
|
74
|
-
<div
|
|
75
|
-
role='none'
|
|
76
|
-
className={
|
|
77
|
-
readonly
|
|
78
|
-
? 'flex flex-wrap gap-1 mlb-1'
|
|
79
|
-
: values.length > 0
|
|
80
|
-
? 'grid gap-1 grid-cols-[1fr_min-content] mlb-1'
|
|
81
|
-
: 'hidden'
|
|
82
|
-
}
|
|
83
|
-
>
|
|
84
|
-
{values.map((_value, index) => {
|
|
85
|
-
const field = (
|
|
86
|
-
<FormField
|
|
87
|
-
property={{
|
|
88
|
-
...property,
|
|
89
|
-
array: false, // NOTE(ZaymonFC): This breaks arrays of arrays but ¯\_(ツ)_/¯. Ping me if you need that.
|
|
90
|
-
ast: elementType,
|
|
91
|
-
}}
|
|
92
|
-
path={[...(path ?? []), index]}
|
|
93
|
-
readonly={readonly}
|
|
94
|
-
inline
|
|
95
|
-
Custom={Custom}
|
|
96
|
-
lookupComponent={lookupComponent}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
return readonly ? (
|
|
100
|
-
field
|
|
101
|
-
) : (
|
|
102
|
-
<Fragment key={index}>
|
|
103
|
-
<div role='none'>{field}</div>
|
|
104
|
-
<IconButton
|
|
105
|
-
icon='ph--trash--regular'
|
|
106
|
-
iconOnly
|
|
107
|
-
label={t('button remove')}
|
|
108
|
-
onClick={() => handleRemove(index)}
|
|
109
|
-
classNames='self-center'
|
|
110
|
-
/>
|
|
111
|
-
</Fragment>
|
|
112
|
-
);
|
|
113
|
-
})}
|
|
114
|
-
</div>
|
|
115
|
-
{!readonly && (
|
|
116
|
-
<IconButton
|
|
117
|
-
classNames='is-full mlb-cardSpacingBlock flex'
|
|
118
|
-
icon='ph--plus--regular'
|
|
119
|
-
label={t('add field')}
|
|
120
|
-
onClick={handleAdd}
|
|
121
|
-
/>
|
|
122
|
-
)}
|
|
123
|
-
</>
|
|
124
|
-
);
|
|
125
|
-
};
|