@dxos/react-ui-form 0.8.4-main.67995b8 → 0.8.4-main.70d3990
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/dist/lib/browser/index.mjs +909 -675
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +909 -675
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +2 -2
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +81 -5
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +76 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +2 -2
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +5 -5
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +10 -8
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +144 -33
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +17 -11
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +5 -5
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +6 -3
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +15 -5
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +76 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts +2 -2
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +41 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +82 -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/ViewEditor/ViewEditor.d.ts +20 -6
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +80 -8
- 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 +6 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +6 -6
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +9 -3
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +14 -8
- 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/refs.d.ts +1 -1
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -38
- package/src/components/ControlSection/ControlSection.stories.tsx +11 -14
- package/src/components/ControlSection/ControlSection.tsx +26 -12
- package/src/components/FieldEditor/FieldEditor.stories.tsx +16 -16
- package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
- package/src/components/FieldEditor/FieldEditor.tsx +28 -20
- package/src/components/Form/ArrayField.tsx +15 -12
- package/src/components/Form/Defaults.tsx +23 -21
- package/src/components/Form/Form.stories.tsx +144 -108
- package/src/components/Form/Form.tsx +33 -19
- package/src/components/Form/FormActions.tsx +9 -3
- package/src/components/Form/FormContent.tsx +172 -50
- package/src/components/Form/FormContext.tsx +11 -11
- package/src/components/Form/Input.tsx +6 -3
- package/src/components/Form/RefField.tsx +111 -41
- package/src/components/Form/custom/GeoPointInput.tsx +29 -21
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +11 -11
- package/src/components/Form/custom/SelectOptionsInput.tsx +31 -32
- package/src/components/Form/custom/TupleInput.tsx +2 -2
- package/src/components/Form/factory.tsx +8 -5
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +207 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +161 -0
- package/src/components/ObjectPicker/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +123 -51
- package/src/components/ViewEditor/ViewEditor.test.tsx +13 -15
- package/src/components/ViewEditor/ViewEditor.tsx +271 -219
- package/src/components/index.ts +1 -2
- package/src/components/testing.tsx +15 -9
- package/src/hooks/useForm.ts +15 -10
- package/src/hooks/useQueryRefOptions.ts +15 -6
- package/src/hooks/useRefQueryLookupHandler.ts +5 -5
- package/src/translations.ts +16 -9
- package/src/util/field.ts +33 -43
- package/src/util/formatting.ts +22 -22
- package/src/util/refs.ts +7 -7
- package/src/util/schema.ts +2 -4
- 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/src/components/deprecated/Form.stories.tsx +0 -62
- package/src/components/deprecated/Form.tsx +0 -119
- package/src/components/deprecated/FormInput.tsx +0 -71
- package/src/components/deprecated/index.ts +0 -5
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { SchemaAST, type Schema, Option, pipe } from 'effect';
|
|
6
|
-
import React, { useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { findProperty } from '@dxos/effect';
|
|
9
|
-
import { Input, type ThemedClassName, type TextInputProps as NativeTextInputProps } from '@dxos/react-ui';
|
|
10
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
11
|
-
import { getFieldValue, setFieldValue, type Projection } from '@dxos/schema';
|
|
12
|
-
|
|
13
|
-
export type DeprecatedFormProps<T extends {} = {}> = ThemedClassName<{
|
|
14
|
-
projection: Projection;
|
|
15
|
-
object: T;
|
|
16
|
-
schema?: Schema.Schema<T>;
|
|
17
|
-
readonly?: boolean;
|
|
18
|
-
}>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Schema-based object form.
|
|
22
|
-
*/
|
|
23
|
-
export const DeprecatedForm = <T extends {} = {}>({
|
|
24
|
-
classNames,
|
|
25
|
-
projection,
|
|
26
|
-
object,
|
|
27
|
-
schema,
|
|
28
|
-
readonly,
|
|
29
|
-
}: DeprecatedFormProps<T>) => {
|
|
30
|
-
return (
|
|
31
|
-
<div role='none' className={mx('flex flex-col w-full gap-2 p-2', classNames)}>
|
|
32
|
-
{projection.fields.map((field) => {
|
|
33
|
-
const prop = schema && findProperty(schema, field.path);
|
|
34
|
-
const title = (prop && pipe(SchemaAST.getTitleAnnotation(prop), Option.getOrUndefined)) ?? '';
|
|
35
|
-
const description = (prop && pipe(SchemaAST.getDescriptionAnnotation(prop), Option.getOrUndefined)) ?? title;
|
|
36
|
-
// const format =
|
|
37
|
-
// (prop && (getPatternAnnotation(prop) ?? (SchemaAST.isNumberKeyword(prop) && RealNumberFormat))) || undefined;
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
// Boolean
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
if (prop && SchemaAST.isBooleanKeyword(prop)) {
|
|
44
|
-
const value = object && getFieldValue(object, field);
|
|
45
|
-
const onChange = (checked: boolean) => {
|
|
46
|
-
setFieldValue(object, field, checked);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div key={field.path} className='flex flex-col w-full gap-1'>
|
|
51
|
-
<Input.Root>
|
|
52
|
-
<Input.Label classNames='px-1'>{title}</Input.Label>
|
|
53
|
-
<Input.Switch disabled={readonly} checked={!!value} onCheckedChange={(checked) => onChange(checked)} />
|
|
54
|
-
</Input.Root>
|
|
55
|
-
</div>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
// Strings
|
|
61
|
-
// TODO(burdon): Other types:
|
|
62
|
-
// - RichText editor
|
|
63
|
-
// - Numbers (with formatting: commas, currency, etc.)
|
|
64
|
-
// - Date (https://ark-ui.com/react/docs/components/date-picker)
|
|
65
|
-
// - Enum (single/multi-select)
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
const value = object ? getFieldValue(object, field) : undefined;
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<div key={field.path} className='flex flex-col w-full gap-1'>
|
|
72
|
-
<Input.Root>
|
|
73
|
-
<Input.Label classNames='px-1'>{title}</Input.Label>
|
|
74
|
-
<TextInput
|
|
75
|
-
disabled={readonly}
|
|
76
|
-
placeholder={description}
|
|
77
|
-
// format={format}
|
|
78
|
-
value={value ? String(value) : ''}
|
|
79
|
-
onChange={(event) => setFieldValue(object, field, event.target.value)}
|
|
80
|
-
/>
|
|
81
|
-
</Input.Root>
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
})}
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
type TextInputProps = {
|
|
90
|
-
// format?: PatternAnnotation;
|
|
91
|
-
} & Omit<NativeTextInputProps, 'style'>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @deprecated
|
|
95
|
-
*/
|
|
96
|
-
// TODO(burdon): Remove.
|
|
97
|
-
// TODO(burdon): Use schema validation directly.
|
|
98
|
-
const TextInput = ({ onChange, ...props }: TextInputProps) => {
|
|
99
|
-
const [valid, _setValid] = useState(true);
|
|
100
|
-
|
|
101
|
-
const handleChange: NativeTextInputProps['onChange'] = (ev) => {
|
|
102
|
-
// const text = ev.target.value;
|
|
103
|
-
// if (!format?.filter || text.match(format.filter)) {
|
|
104
|
-
onChange?.(ev);
|
|
105
|
-
// if (format?.valid) {
|
|
106
|
-
// setValid(format.valid.test(text));
|
|
107
|
-
// }
|
|
108
|
-
// }
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<Input.TextInput
|
|
113
|
-
{...props}
|
|
114
|
-
// TODO(burdon): validationValence on Input.
|
|
115
|
-
style={valid ? {} : ({ '--tw-ring-color': 'red' } as any)}
|
|
116
|
-
onChange={handleChange}
|
|
117
|
-
/>
|
|
118
|
-
);
|
|
119
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type JSX, type PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Input, type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
-
import { mx, textBlockWidth } from '@dxos/react-ui-theme';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
export const DeprecatedFormContainer = ({ children, classNames }: ThemedClassName<PropsWithChildren>) => {
|
|
14
|
-
return (
|
|
15
|
-
<div role='none' className='container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto'>
|
|
16
|
-
<div role='form' className={mx('flex flex-col', textBlockWidth, classNames)}>
|
|
17
|
-
{children}
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type DeprecatedFormInputProps = {
|
|
24
|
-
label: string;
|
|
25
|
-
description?: JSX.Element;
|
|
26
|
-
secondary?: JSX.Element;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated
|
|
31
|
-
*/
|
|
32
|
-
export const DeprecatedFormInput = ({
|
|
33
|
-
label,
|
|
34
|
-
description,
|
|
35
|
-
secondary,
|
|
36
|
-
children,
|
|
37
|
-
}: PropsWithChildren<DeprecatedFormInputProps>) => {
|
|
38
|
-
const primary = (
|
|
39
|
-
<div role='none' className='flex w-full gap-4 py-1'>
|
|
40
|
-
<Input.Root>
|
|
41
|
-
<div role='none' className='flex flex-col w-full'>
|
|
42
|
-
<Input.Label classNames='flex min-bs-[--rail-action] items-center' style={{ fontSize: 'unset' }}>
|
|
43
|
-
{label}
|
|
44
|
-
</Input.Label>
|
|
45
|
-
{description && (
|
|
46
|
-
<Input.DescriptionAndValidation classNames='mbs-0.5'>
|
|
47
|
-
<Input.Description>{description}</Input.Description>
|
|
48
|
-
</Input.DescriptionAndValidation>
|
|
49
|
-
)}
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
<div role='none'>
|
|
53
|
-
<div role='none' className='flex min-bs-[--rail-action] items-center'>
|
|
54
|
-
{children}
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</Input.Root>
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
if (secondary) {
|
|
62
|
-
return (
|
|
63
|
-
<div role='none'>
|
|
64
|
-
{primary}
|
|
65
|
-
{secondary}
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return primary;
|
|
71
|
-
};
|