@dxos/react-ui-form 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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 +2289 -2269
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2289 -2269
- 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 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +13 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +81 -26
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +59 -84
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +37 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +78 -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 +19 -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 +14 -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/{ControlSection/ControlSection.stories.d.ts → Form/fields/SelectOptionField.stories.d.ts} +12 -14
- 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/ObjectPicker/ObjectPicker.d.ts +15 -10
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +10 -6
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.d.ts +56 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/{Form/custom/SelectOptionsInput.stories.d.ts → Settings/Settings.stories.d.ts} +10 -8
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +16 -16
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +13 -9
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +0 -2
- 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 +6 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +10 -7
- package/dist/types/src/translations.d.ts.map +1 -1
- 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 +1 -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 +1 -2
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +50 -46
- package/src/components/FieldEditor/FieldEditor.stories.tsx +43 -24
- package/src/components/FieldEditor/FieldEditor.tsx +74 -78
- package/src/components/Form/Form.stories.tsx +149 -248
- package/src/components/Form/Form.tsx +347 -107
- package/src/components/Form/FormField.tsx +294 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +172 -0
- package/src/components/Form/FormFieldSet.tsx +123 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +149 -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 +189 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +19 -16
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +23 -17
- 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} +15 -8
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +40 -37
- package/src/components/ObjectPicker/ObjectPicker.tsx +84 -70
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +230 -0
- package/src/components/{ControlSection → Settings}/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +69 -49
- package/src/components/ViewEditor/ViewEditor.test.tsx +8 -6
- package/src/components/ViewEditor/ViewEditor.tsx +302 -271
- package/src/components/index.ts +1 -1
- package/src/components/testing.tsx +12 -7
- 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 +12 -10
- package/src/util/field.ts +25 -25
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +1 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +11 -17
- 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.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 -21
- 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.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 -28
- 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 -269
- 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 -295
- package/src/hooks/useQueryRefOptions.ts +0 -59
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -12
|
@@ -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,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAI9C,eAAO,MAAM,oBAAoB,GAAI,KAAK,SAAS,CAAC,GAAG,8BAGtD,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
-
|
|
10
|
-
import { translations } from '../../translations';
|
|
11
|
-
|
|
12
|
-
import { ControlPage, ControlSection } from './ControlSection';
|
|
13
|
-
|
|
14
|
-
const meta = {
|
|
15
|
-
title: 'ui/react-ui-form/ControlSection',
|
|
16
|
-
component: ControlSection,
|
|
17
|
-
render: (args) => (
|
|
18
|
-
<ControlPage classNames='w-[40rem]'>
|
|
19
|
-
<ControlSection {...args} />
|
|
20
|
-
</ControlPage>
|
|
21
|
-
),
|
|
22
|
-
decorators: [withTheme],
|
|
23
|
-
parameters: {
|
|
24
|
-
layout: 'centered',
|
|
25
|
-
translations,
|
|
26
|
-
},
|
|
27
|
-
} satisfies Meta<typeof ControlSection>;
|
|
28
|
-
|
|
29
|
-
export default meta;
|
|
30
|
-
|
|
31
|
-
type Story = StoryObj<typeof meta>;
|
|
32
|
-
|
|
33
|
-
export const Default: Story = {
|
|
34
|
-
args: {
|
|
35
|
-
title: 'Control Section',
|
|
36
|
-
description: 'This is a control section',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
@@ -1,153 +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 { StackItem } from '@dxos/react-ui-stack';
|
|
17
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
18
|
-
|
|
19
|
-
import { translationKey } from '../../translations';
|
|
20
|
-
|
|
21
|
-
export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
|
|
22
|
-
|
|
23
|
-
export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
|
|
24
|
-
return (
|
|
25
|
-
<StackItem.Content scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
|
|
26
|
-
<div role='none' className={mx('pli-cardSpacingInline pbe-trimLg', classNames)} {...props}>
|
|
27
|
-
{children}
|
|
28
|
-
</div>
|
|
29
|
-
</StackItem.Content>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type ControlSectionProps = PropsWithChildren<{
|
|
34
|
-
title: Label;
|
|
35
|
-
description?: Label;
|
|
36
|
-
}>;
|
|
37
|
-
|
|
38
|
-
export const ControlSection = ({ title, description, children }: ControlSectionProps) => {
|
|
39
|
-
return (
|
|
40
|
-
<>
|
|
41
|
-
<ControlSectionHeading title={title} description={description} />
|
|
42
|
-
{children}
|
|
43
|
-
</>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const ControlSectionHeading = ({ title, description }: Omit<ControlSectionProps, 'children'>) => {
|
|
48
|
-
const { t } = useTranslation(translationKey);
|
|
49
|
-
return (
|
|
50
|
-
<>
|
|
51
|
-
<h2 className='pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd'>{toLocalizedString(title, t)}</h2>
|
|
52
|
-
{description && (
|
|
53
|
-
<p className='pli-trimMd mlb-trimMd container-max-width text-description'>
|
|
54
|
-
{toLocalizedString(description, t)}
|
|
55
|
-
</p>
|
|
56
|
-
)}
|
|
57
|
-
</>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const ControlGroupButton = ({ classNames, ...props }: ButtonProps) => {
|
|
62
|
-
return <Button {...props} classNames={['md:col-span-2', classNames]} />;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export type ControlGroupProps = ThemedClassName<PropsWithChildren>;
|
|
66
|
-
|
|
67
|
-
export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
|
|
68
|
-
<div
|
|
69
|
-
role='none'
|
|
70
|
-
className={mx(
|
|
71
|
-
'group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd',
|
|
72
|
-
'[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end',
|
|
73
|
-
classNames,
|
|
74
|
-
)}
|
|
75
|
-
>
|
|
76
|
-
{children}
|
|
77
|
-
</div>
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
export const ControlFrame = ({ children }: ControlGroupProps) => (
|
|
81
|
-
<div
|
|
82
|
-
role='none'
|
|
83
|
-
className={mx(
|
|
84
|
-
'container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd',
|
|
85
|
-
'border border-separator rounded-md',
|
|
86
|
-
)}
|
|
87
|
-
>
|
|
88
|
-
{children}
|
|
89
|
-
</div>
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
export const controlItemClasses = mx([
|
|
93
|
-
'container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center',
|
|
94
|
-
// TODO(burdon): Use grid gap consistently or apply margins consistently?
|
|
95
|
-
'mlb-[--control-spacing] *:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd',
|
|
96
|
-
'border border-separator rounded-md',
|
|
97
|
-
]);
|
|
98
|
-
|
|
99
|
-
const controlItemTitleClasses = 'mbe-0 text-lg text-baseText font-normal';
|
|
100
|
-
const controlItemDescriptionClasses = 'mlb-trimSm md:mbe-0 text-base text-description';
|
|
101
|
-
|
|
102
|
-
export type ControlItemProps = PropsWithChildren<{
|
|
103
|
-
title: Label;
|
|
104
|
-
description?: Label;
|
|
105
|
-
}>;
|
|
106
|
-
|
|
107
|
-
export const ControlItem = ({ title, description, children }: ControlItemProps) => {
|
|
108
|
-
const { t } = useTranslation(translationKey);
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<div className={controlItemClasses}>
|
|
112
|
-
<div role='none'>
|
|
113
|
-
<h3 className={controlItemTitleClasses}>{toLocalizedString(title, t)}</h3>
|
|
114
|
-
{description && <p className={controlItemDescriptionClasses}>{toLocalizedString(description, t)}</p>}
|
|
115
|
-
</div>
|
|
116
|
-
{children}
|
|
117
|
-
</div>
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const ControlItemInput = ({ title, description, children }: ControlItemProps) => {
|
|
122
|
-
const { t } = useTranslation(translationKey);
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<Input.Root>
|
|
126
|
-
<div className={controlItemClasses}>
|
|
127
|
-
<div role='none'>
|
|
128
|
-
<Input.Label classNames={controlItemTitleClasses}>{toLocalizedString(title, t)}</Input.Label>
|
|
129
|
-
{description && (
|
|
130
|
-
<Input.DescriptionAndValidation>
|
|
131
|
-
<Input.Description classNames={controlItemDescriptionClasses}>
|
|
132
|
-
{toLocalizedString(description, t)}
|
|
133
|
-
</Input.Description>
|
|
134
|
-
</Input.DescriptionAndValidation>
|
|
135
|
-
)}
|
|
136
|
-
</div>
|
|
137
|
-
{children}
|
|
138
|
-
</div>
|
|
139
|
-
</Input.Root>
|
|
140
|
-
);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export const ControlFrameItem = ({ title, description, children }: ControlItemProps) => {
|
|
144
|
-
const { t } = useTranslation(translationKey);
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<div role='group' className='min-is-0'>
|
|
148
|
-
<h3 className='text-lg mbe-2'>{toLocalizedString(title, t)}</h3>
|
|
149
|
-
{description && <p className='mlb-trimSm md:mbe-0 text-description'>{toLocalizedString(description, t)}</p>}
|
|
150
|
-
{children}
|
|
151
|
-
</div>
|
|
152
|
-
);
|
|
153
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Function from 'effect/Function';
|
|
6
|
-
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
-
import * as String from 'effect/String';
|
|
8
|
-
import React, { Fragment, useCallback } from 'react';
|
|
9
|
-
|
|
10
|
-
import { SimpleType, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
|
|
11
|
-
import { invariant } from '@dxos/invariant';
|
|
12
|
-
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
13
|
-
import { type SchemaProperty, getSchemaProperties } from '@dxos/schema';
|
|
14
|
-
|
|
15
|
-
import { translationKey } from '../../translations';
|
|
16
|
-
import { findArrayElementType } from '../../util';
|
|
17
|
-
|
|
18
|
-
import { type ComponentLookup } from './Form';
|
|
19
|
-
import { FormField, type FormFieldProps } from './FormContent';
|
|
20
|
-
import { type FormInputStateProps, useFormValues } from './FormContext';
|
|
21
|
-
import { type InputComponent, InputHeader } from './Input';
|
|
22
|
-
|
|
23
|
-
type ArrayFieldProps = {
|
|
24
|
-
property: SchemaProperty<any>;
|
|
25
|
-
inputProps: FormInputStateProps;
|
|
26
|
-
path?: (string | number)[];
|
|
27
|
-
Custom?: Partial<Record<string, InputComponent>>;
|
|
28
|
-
lookupComponent?: ComponentLookup;
|
|
29
|
-
} & Pick<FormFieldProps, 'readonly'>;
|
|
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 ?? Function.pipe(name, String.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
|
-
};
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Input, Select, useTranslation } from '@dxos/react-ui';
|
|
8
|
-
|
|
9
|
-
import { translationKey } from '../../translations';
|
|
10
|
-
|
|
11
|
-
import { InputHeader, type InputProps } from './Input';
|
|
12
|
-
|
|
13
|
-
export const TextInput = ({
|
|
14
|
-
type,
|
|
15
|
-
label,
|
|
16
|
-
inputOnly,
|
|
17
|
-
readonly,
|
|
18
|
-
placeholder,
|
|
19
|
-
getStatus,
|
|
20
|
-
getValue,
|
|
21
|
-
onValueChange,
|
|
22
|
-
onBlur,
|
|
23
|
-
}: InputProps) => {
|
|
24
|
-
const { status, error } = getStatus();
|
|
25
|
-
|
|
26
|
-
return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
|
|
27
|
-
<p>{getValue() ?? ''}</p>
|
|
28
|
-
) : (
|
|
29
|
-
<Input.Root validationValence={status}>
|
|
30
|
-
{!inputOnly && <InputHeader error={error} label={label} />}
|
|
31
|
-
{readonly === 'static' ? (
|
|
32
|
-
<p>{getValue() ?? ''}</p>
|
|
33
|
-
) : (
|
|
34
|
-
<Input.TextInput
|
|
35
|
-
disabled={!!readonly}
|
|
36
|
-
placeholder={placeholder}
|
|
37
|
-
value={getValue() ?? ''}
|
|
38
|
-
onChange={(event) => onValueChange(type, event.target.value)}
|
|
39
|
-
onBlur={onBlur}
|
|
40
|
-
/>
|
|
41
|
-
)}
|
|
42
|
-
{inputOnly && <Input.Validation>{error}</Input.Validation>}
|
|
43
|
-
</Input.Root>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const NumberInput = ({
|
|
48
|
-
type,
|
|
49
|
-
label,
|
|
50
|
-
inputOnly,
|
|
51
|
-
readonly,
|
|
52
|
-
placeholder,
|
|
53
|
-
getStatus,
|
|
54
|
-
getValue,
|
|
55
|
-
onValueChange,
|
|
56
|
-
onBlur,
|
|
57
|
-
}: InputProps) => {
|
|
58
|
-
const { status, error } = getStatus();
|
|
59
|
-
|
|
60
|
-
return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
|
|
61
|
-
<p>{getValue() ?? ''}</p>
|
|
62
|
-
) : (
|
|
63
|
-
<Input.Root validationValence={status}>
|
|
64
|
-
{!inputOnly && <InputHeader error={error} label={label} />}
|
|
65
|
-
{readonly === 'static' ? (
|
|
66
|
-
<p>{getValue() ?? ''}</p>
|
|
67
|
-
) : (
|
|
68
|
-
<Input.TextInput
|
|
69
|
-
type='number'
|
|
70
|
-
disabled={!!readonly}
|
|
71
|
-
placeholder={placeholder}
|
|
72
|
-
value={getValue()}
|
|
73
|
-
onChange={(event) => onValueChange(type, event.target.value)}
|
|
74
|
-
onBlur={onBlur}
|
|
75
|
-
/>
|
|
76
|
-
)}
|
|
77
|
-
{inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
78
|
-
</Input.Root>
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onValueChange, readonly }: InputProps) => {
|
|
83
|
-
const { status, error } = getStatus();
|
|
84
|
-
const checked = Boolean(getValue());
|
|
85
|
-
const { t } = useTranslation(translationKey);
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<Input.Root validationValence={status}>
|
|
89
|
-
{!inputOnly && <InputHeader error={error} label={label} />}
|
|
90
|
-
{readonly === 'static' ? (
|
|
91
|
-
<p>{t(checked ? 'boolean input true value' : 'boolean input false value')}</p>
|
|
92
|
-
) : (
|
|
93
|
-
<Input.Switch disabled={!!readonly} checked={checked} onCheckedChange={(value) => onValueChange(type, value)} />
|
|
94
|
-
)}
|
|
95
|
-
{inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
96
|
-
</Input.Root>
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type SelectInputOptions = InputProps & {
|
|
101
|
-
options?: Array<{ value: string | number; label?: string }>;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const SelectInput = ({
|
|
105
|
-
type,
|
|
106
|
-
label,
|
|
107
|
-
inputOnly,
|
|
108
|
-
readonly,
|
|
109
|
-
placeholder,
|
|
110
|
-
options,
|
|
111
|
-
getStatus,
|
|
112
|
-
getValue,
|
|
113
|
-
onValueChange,
|
|
114
|
-
}: SelectInputOptions) => {
|
|
115
|
-
const { status, error } = getStatus();
|
|
116
|
-
|
|
117
|
-
const value = getValue() as string | undefined;
|
|
118
|
-
const handleValueChange = useCallback((value: string | number) => onValueChange(type, value), [type, onValueChange]);
|
|
119
|
-
|
|
120
|
-
return readonly && !value ? null : (
|
|
121
|
-
<Input.Root validationValence={status}>
|
|
122
|
-
{!inputOnly && <InputHeader error={error} label={label} />}
|
|
123
|
-
{readonly === 'static' ? (
|
|
124
|
-
<p>{options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)}</p>
|
|
125
|
-
) : (
|
|
126
|
-
<Select.Root value={value} onValueChange={handleValueChange}>
|
|
127
|
-
{/* TODO(burdon): Placeholder not working? */}
|
|
128
|
-
<Select.TriggerButton classNames='is-full' disabled={!!readonly} placeholder={placeholder} />
|
|
129
|
-
<Select.Portal>
|
|
130
|
-
<Select.Content>
|
|
131
|
-
<Select.Viewport>
|
|
132
|
-
{options?.map(({ value, label }) => (
|
|
133
|
-
// NOTE: Numeric values are converted to and from strings.
|
|
134
|
-
<Select.Option key={String(value)} value={String(value)}>
|
|
135
|
-
{label ?? String(value)}
|
|
136
|
-
</Select.Option>
|
|
137
|
-
))}
|
|
138
|
-
</Select.Viewport>
|
|
139
|
-
<Select.Arrow />
|
|
140
|
-
</Select.Content>
|
|
141
|
-
</Select.Portal>
|
|
142
|
-
</Select.Root>
|
|
143
|
-
)}
|
|
144
|
-
{inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
145
|
-
</Input.Root>
|
|
146
|
-
);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export const MarkdownInput = ({
|
|
150
|
-
type,
|
|
151
|
-
label,
|
|
152
|
-
inputOnly,
|
|
153
|
-
readonly,
|
|
154
|
-
placeholder,
|
|
155
|
-
getStatus,
|
|
156
|
-
getValue,
|
|
157
|
-
onValueChange,
|
|
158
|
-
onBlur,
|
|
159
|
-
}: InputProps) => {
|
|
160
|
-
const { status, error } = getStatus();
|
|
161
|
-
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
162
|
-
|
|
163
|
-
// TODO(ZaymonFC): If we start using `Enter` for form submission, we should prevent default behavior here
|
|
164
|
-
// since we're using a textarea element and the user needs to be able to enter new lines.
|
|
165
|
-
|
|
166
|
-
const adjustHeight = useCallback(() => {
|
|
167
|
-
const textarea = textareaRef.current;
|
|
168
|
-
if (textarea) {
|
|
169
|
-
textarea.style.blockSize = 'auto'; // For measurement.
|
|
170
|
-
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
171
|
-
}
|
|
172
|
-
}, []);
|
|
173
|
-
|
|
174
|
-
// Adjust height on initial render.
|
|
175
|
-
useEffect(() => {
|
|
176
|
-
adjustHeight();
|
|
177
|
-
}, [adjustHeight]);
|
|
178
|
-
|
|
179
|
-
// Adjust height when the content changes.
|
|
180
|
-
useEffect(() => {
|
|
181
|
-
adjustHeight();
|
|
182
|
-
}, [getValue(), adjustHeight]);
|
|
183
|
-
|
|
184
|
-
return (
|
|
185
|
-
<Input.Root validationValence={status}>
|
|
186
|
-
{!inputOnly && <InputHeader error={error} label={label} />}
|
|
187
|
-
{readonly === 'static' ? (
|
|
188
|
-
<p>{getValue() ?? ''}</p>
|
|
189
|
-
) : (
|
|
190
|
-
<Input.TextArea
|
|
191
|
-
ref={textareaRef}
|
|
192
|
-
disabled={!!readonly}
|
|
193
|
-
placeholder={placeholder}
|
|
194
|
-
value={getValue() ?? ''}
|
|
195
|
-
classNames={'min-bs-auto max-h-40 overflow-auto'}
|
|
196
|
-
onChange={(event) => onValueChange(type, event.target.value)}
|
|
197
|
-
onBlur={onBlur}
|
|
198
|
-
style={{ resize: 'none' }}
|
|
199
|
-
spellCheck={false}
|
|
200
|
-
/>
|
|
201
|
-
)}
|
|
202
|
-
{inputOnly && <Input.Validation>{error}</Input.Validation>}
|
|
203
|
-
</Input.Root>
|
|
204
|
-
);
|
|
205
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
8
|
-
import { cardSpacing } from '@dxos/react-ui-stack';
|
|
9
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
-
|
|
11
|
-
import { translationKey } from '../../translations';
|
|
12
|
-
|
|
13
|
-
import { useFormContext } from './FormContext';
|
|
14
|
-
|
|
15
|
-
export type FormOuterSpacing = boolean | 'blockStart-0' | 'scroll-fields';
|
|
16
|
-
|
|
17
|
-
export type FormActionsProps = {
|
|
18
|
-
readonly?: boolean;
|
|
19
|
-
onCancel?: () => void;
|
|
20
|
-
outerSpacing?: FormOuterSpacing;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const FormActions = ({ readonly, onCancel, outerSpacing = true }: FormActionsProps) => {
|
|
24
|
-
const { t } = useTranslation(translationKey);
|
|
25
|
-
const { canSave, handleSave } = useFormContext();
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<div
|
|
29
|
-
role='none'
|
|
30
|
-
className={mx(
|
|
31
|
-
outerSpacing === 'scroll-fields'
|
|
32
|
-
? 'pli-cardSpacingInline mbe-cardSpacingBlock'
|
|
33
|
-
: outerSpacing
|
|
34
|
-
? cardSpacing
|
|
35
|
-
: 'mbs-cardSpacingBlock',
|
|
36
|
-
'flex [&_button]:grow gap-1 first:mbs-0',
|
|
37
|
-
)}
|
|
38
|
-
>
|
|
39
|
-
{onCancel && !readonly && (
|
|
40
|
-
<IconButton data-testid='cancel-button' icon='ph--x--regular' label={t('button cancel')} onClick={onCancel} />
|
|
41
|
-
)}
|
|
42
|
-
{handleSave && (
|
|
43
|
-
<IconButton
|
|
44
|
-
type='submit'
|
|
45
|
-
data-testid='save-button'
|
|
46
|
-
disabled={!canSave}
|
|
47
|
-
icon='ph--check--regular'
|
|
48
|
-
label={t('button save')}
|
|
49
|
-
onClick={handleSave}
|
|
50
|
-
/>
|
|
51
|
-
)}
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
};
|