@dxos/react-ui-form 0.7.1 → 0.7.2-main.f1adc9f
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 +137 -111
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +130 -104
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +137 -111
- 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 +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/Custom.d.ts +2 -1
- package/dist/types/src/components/Form/Custom.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +11 -4
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +6 -5
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +1 -4
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +3 -8
- package/dist/types/src/components/Form/Input.d.ts.map +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/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +8 -7
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/package.json +22 -24
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.tsx +8 -8
- package/src/components/Form/Custom.tsx +9 -9
- package/src/components/Form/Defaults.tsx +10 -5
- package/src/components/Form/Form.stories.tsx +6 -6
- package/src/components/Form/Form.tsx +52 -28
- package/src/components/Form/Input.tsx +3 -7
- package/src/components/Form/factory.tsx +4 -4
- package/src/components/ViewEditor/ViewEditor.stories.tsx +1 -2
- package/src/components/ViewEditor/ViewEditor.tsx +8 -7
- package/src/hooks/useForm.ts +18 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Form.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Form.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAElD,OAAO,EAAO,KAAK,UAAU,EAAK,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG9E,OAAO,EAAc,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAIxE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,aAAa,CAAC;AAOxD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;AAEvG,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,IAAI,eAAe,CAC9D;IACE,MAAM,EAAE,CAAC,CAAC;IACV,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAEtB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACrD,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAG,iBAAiB,GAAG,YAAY,GAAG,QAAQ,CAAC,CACjF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,iJAczC,SAAS,CAAC,CAAC,CAAC,sBAoId,CAAC"}
|
|
@@ -11,10 +11,7 @@ declare const TestSchema: S.mutable<S.Struct<{
|
|
|
11
11
|
street: S.optional<S.SchemaClass<string, string, never>>;
|
|
12
12
|
city: S.optional<S.SchemaClass<string, string, never>>;
|
|
13
13
|
zip: S.optional<S.refine<string, S.Schema<string, string, never>>>;
|
|
14
|
-
location: S.optional<S.
|
|
15
|
-
lat: S.filter<S.Schema<number, number, never>>;
|
|
16
|
-
lng: S.filter<S.Schema<number, number, never>>;
|
|
17
|
-
}>>;
|
|
14
|
+
location: S.optional<S.Tuple<[S.refine<number, S.Schema<number, number, never>>, S.refine<number, S.Schema<number, number, never>>, S.Element<typeof S.Number, "?">]>>;
|
|
18
15
|
}>>;
|
|
19
16
|
}>>;
|
|
20
17
|
type TestType = S.Schema.Type<typeof TestSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Form.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAe,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAK9C,QAAA,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"Form.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Form.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAe,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAK9C,QAAA,MAAM,UAAU;;;;;;;;;;;GAaE,CAAC;AAEnB,KAAK,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAEjD,KAAK,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAiBtC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAAU,CAQ1B,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAElC,eAAO,MAAM,OAAO,EAAE,KAUrB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;GAaC,CAAC;AAEnB,KAAK,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,CAAC;AACnD,KAAK,4BAA4B,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;AAgCzD,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,4BAA4B,CAUrE,CAAC"}
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import React, { type FC, type PropsWithChildren } from 'react';
|
|
2
|
-
import { type FormatEnum } from '@dxos/echo-schema';
|
|
2
|
+
import { type BaseObject, type FormatEnum, type PropertyKey } from '@dxos/echo-schema';
|
|
3
3
|
import { type SimpleType } from '@dxos/effect';
|
|
4
|
-
import { type PropertyKey } from '@dxos/schema';
|
|
5
4
|
import { type FormHandler } from '../../hooks';
|
|
6
5
|
/**
|
|
7
6
|
* Props passed to input components.
|
|
8
7
|
*/
|
|
9
|
-
export type InputProps<T extends
|
|
8
|
+
export type InputProps<T extends BaseObject<T>> = {
|
|
10
9
|
property: PropertyKey<T>;
|
|
11
10
|
type: SimpleType;
|
|
12
11
|
format?: FormatEnum;
|
|
13
12
|
label: string;
|
|
14
13
|
disabled?: boolean;
|
|
15
14
|
placeholder?: string;
|
|
16
|
-
options?: Array<{
|
|
17
|
-
value: string | number;
|
|
18
|
-
label?: string;
|
|
19
|
-
}>;
|
|
20
15
|
} & Pick<FormHandler<T>, 'getStatus' | 'getValue' | 'onValueChange' | 'onBlur'>;
|
|
21
16
|
/**
|
|
22
17
|
* Form input component.
|
|
23
18
|
*/
|
|
24
|
-
export type InputComponent<T extends
|
|
19
|
+
export type InputComponent<T extends BaseObject<T>> = FC<InputProps<T>>;
|
|
25
20
|
export type InputHeaderProps = PropsWithChildren<{
|
|
26
21
|
error?: string;
|
|
27
22
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Input.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAE,KAAK,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/Input.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,IAAI;IAChD,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,eAAe,GAAG,QAAQ,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,eAAO,MAAM,WAAW,wBAAyB,gBAAgB,sBAiBhE,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FormatEnum } from '@dxos/echo-schema';
|
|
1
|
+
import { type BaseObject, FormatEnum } from '@dxos/echo-schema';
|
|
2
2
|
import { type SimpleType } from '@dxos/effect';
|
|
3
3
|
import { type InputComponent } from './Input';
|
|
4
4
|
/**
|
|
5
5
|
* Get property input component.
|
|
6
6
|
*/
|
|
7
|
-
export declare const getInputComponent: <T extends
|
|
7
|
+
export declare const getInputComponent: <T extends BaseObject<T>>(type: SimpleType, format?: FormatEnum) => InputComponent<T> | undefined;
|
|
8
8
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/factory.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/components/Form/factory.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChE,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,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,QACjD,UAAU,WACP,UAAU,KAClB,cAAc,CAAC,CAAC,CAAC,GAAG,SActB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewEditor.d.ts","sourceRoot":"","sources":["../../../../../src/components/ViewEditor/ViewEditor.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAe,KAAK,aAAa,EAAK,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAc,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAGlF,OAAO,EAA+B,KAAK,QAAQ,EAAoC,MAAM,cAAc,CAAC;AAoB5G,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;IAC5C,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,6EAQpB,eAAe,
|
|
1
|
+
{"version":3,"file":"ViewEditor.d.ts","sourceRoot":"","sources":["../../../../../src/components/ViewEditor/ViewEditor.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAe,KAAK,aAAa,EAAK,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAc,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAGlF,OAAO,EAA+B,KAAK,QAAQ,EAAoC,MAAM,cAAc,CAAC;AAoB5G,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;IAC5C,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,6EAQpB,eAAe,sBA2GjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewEditor.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/ViewEditor/ViewEditor.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ViewEditor.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/ViewEditor/ViewEditor.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAS5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA0C1C,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,UAAU,CAQjC,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC;AAEtB,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { type FocusEvent } from 'react';
|
|
2
|
+
import { type BaseObject, type PropertyKey } from '@dxos/echo-schema';
|
|
2
3
|
import { type SimpleType, type S } from '@dxos/effect';
|
|
3
|
-
import { type
|
|
4
|
+
import { type ValidationError } from '@dxos/schema';
|
|
4
5
|
/**
|
|
5
6
|
* Return type from `useForm` hook.
|
|
6
7
|
*/
|
|
7
|
-
export type FormHandler<T extends
|
|
8
|
+
export type FormHandler<T extends BaseObject<T>> = {
|
|
8
9
|
values: T;
|
|
9
10
|
errors: Record<PropertyKey<T>, string>;
|
|
10
11
|
touched: Record<PropertyKey<T>, boolean>;
|
|
11
12
|
changed: Record<PropertyKey<T>, boolean>;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
canSave: boolean;
|
|
14
|
+
handleSave: () => void;
|
|
14
15
|
getStatus: (property: PropertyKey<T>) => {
|
|
15
16
|
status?: 'error';
|
|
16
17
|
error?: string;
|
|
@@ -22,7 +23,7 @@ export type FormHandler<T extends object = {}> = {
|
|
|
22
23
|
/**
|
|
23
24
|
* Hook options.
|
|
24
25
|
*/
|
|
25
|
-
export interface FormOptions<T extends
|
|
26
|
+
export interface FormOptions<T extends BaseObject<T>> {
|
|
26
27
|
schema: S.Schema<T>;
|
|
27
28
|
initialValues: T;
|
|
28
29
|
/**
|
|
@@ -46,7 +47,7 @@ export interface FormOptions<T extends object> {
|
|
|
46
47
|
/**
|
|
47
48
|
* Called when the form is submitted and passes validation.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
+
onSave?: (values: T, meta: {
|
|
50
51
|
changed: FormHandler<T>['changed'];
|
|
51
52
|
}) => void;
|
|
52
53
|
}
|
|
@@ -54,5 +55,5 @@ export interface FormOptions<T extends object> {
|
|
|
54
55
|
* Creates a hook for managing form state, including values, validation, and submission.
|
|
55
56
|
* Deeply integrated with `@dxos/schema` for schema-based validation.
|
|
56
57
|
*/
|
|
57
|
-
export declare const useForm: <T extends
|
|
58
|
+
export declare const useForm: <T extends BaseObject<T>>({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave, }: FormOptions<T>) => FormHandler<T>;
|
|
58
59
|
//# sourceMappingURL=useForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAA6C,MAAM,OAAO,CAAC;AAEnF,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAA6C,MAAM,OAAO,CAAC;AAEnF,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,IAAI;IAKjD,MAAM,EAAE,CAAC,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,IAAI,CAAC;IAMvB,SAAS,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9E,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7C,aAAa,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACjF,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,IAAI,CAAC;CAC7E,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC;IAClD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAGpB,aAAa,EAAE,CAAC,CAAC;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAEtC;;;;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,IAAI,CAAC;CAC5E;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,4EAO5C,WAAW,CAAC,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,CAiIhC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-form",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-main.f1adc9f",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -23,27 +23,25 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
|
|
26
|
-
"@atlaskit/pragmatic-drag-and-drop-flourish": "^1.1.2",
|
|
27
26
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
|
|
28
|
-
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.3",
|
|
29
27
|
"@effect/schema": "^0.75.5",
|
|
30
28
|
"@radix-ui/react-context": "^1.0.0",
|
|
31
29
|
"date-fns": "^3.3.1",
|
|
32
30
|
"effect": "^3.9.2",
|
|
33
31
|
"jsonpath": "^1.1.1",
|
|
34
|
-
"@dxos/async": "0.7.
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/react-ui-
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/util": "0.7.
|
|
46
|
-
"@dxos/
|
|
32
|
+
"@dxos/async": "0.7.2-main.f1adc9f",
|
|
33
|
+
"@dxos/echo-schema": "0.7.2-main.f1adc9f",
|
|
34
|
+
"@dxos/effect": "0.7.2-main.f1adc9f",
|
|
35
|
+
"@dxos/debug": "0.7.2-main.f1adc9f",
|
|
36
|
+
"@dxos/echo-db": "0.7.2-main.f1adc9f",
|
|
37
|
+
"@dxos/invariant": "0.7.2-main.f1adc9f",
|
|
38
|
+
"@dxos/keys": "0.7.2-main.f1adc9f",
|
|
39
|
+
"@dxos/log": "0.7.2-main.f1adc9f",
|
|
40
|
+
"@dxos/react-client": "0.7.2-main.f1adc9f",
|
|
41
|
+
"@dxos/react-ui-list": "0.7.2-main.f1adc9f",
|
|
42
|
+
"@dxos/schema": "0.7.2-main.f1adc9f",
|
|
43
|
+
"@dxos/util": "0.7.2-main.f1adc9f",
|
|
44
|
+
"@dxos/react-ui-types": "0.7.2-main.f1adc9f"
|
|
47
45
|
},
|
|
48
46
|
"devDependencies": {
|
|
49
47
|
"@phosphor-icons/react": "^2.1.5",
|
|
@@ -54,12 +52,12 @@
|
|
|
54
52
|
"react": "~18.2.0",
|
|
55
53
|
"react-dom": "~18.2.0",
|
|
56
54
|
"vite": "5.4.7",
|
|
57
|
-
"@dxos/echo-signals": "0.7.
|
|
58
|
-
"@dxos/random": "0.7.
|
|
59
|
-
"@dxos/react-ui": "0.7.
|
|
60
|
-
"@dxos/react-ui-
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
55
|
+
"@dxos/echo-signals": "0.7.2-main.f1adc9f",
|
|
56
|
+
"@dxos/random": "0.7.2-main.f1adc9f",
|
|
57
|
+
"@dxos/react-ui-syntax-highlighter": "0.7.2-main.f1adc9f",
|
|
58
|
+
"@dxos/react-ui-theme": "0.7.2-main.f1adc9f",
|
|
59
|
+
"@dxos/react-ui": "0.7.2-main.f1adc9f",
|
|
60
|
+
"@dxos/storybook-utils": "0.7.2-main.f1adc9f"
|
|
63
61
|
},
|
|
64
62
|
"peerDependencies": {
|
|
65
63
|
"@effect/schema": "^0.75.5",
|
|
@@ -67,8 +65,8 @@
|
|
|
67
65
|
"effect": "^3.9.2",
|
|
68
66
|
"react": "~18.2.0",
|
|
69
67
|
"react-dom": "~18.2.0",
|
|
70
|
-
"@dxos/react-ui": "0.7.
|
|
71
|
-
"@dxos/react-ui-theme": "0.7.
|
|
68
|
+
"@dxos/react-ui": "0.7.2-main.f1adc9f",
|
|
69
|
+
"@dxos/react-ui-theme": "0.7.2-main.f1adc9f"
|
|
72
70
|
},
|
|
73
71
|
"publishConfig": {
|
|
74
72
|
"access": "public"
|
|
@@ -20,14 +20,14 @@ import { TestLayout, TestPanel } from '../testing';
|
|
|
20
20
|
type StoryProps = FieldEditorProps;
|
|
21
21
|
|
|
22
22
|
const DefaultStory = (props: FieldEditorProps) => {
|
|
23
|
-
const handleComplete: FieldEditorProps['
|
|
23
|
+
const handleComplete: FieldEditorProps['onSave'] = () => {
|
|
24
24
|
log.info('onClose', { props });
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
return (
|
|
28
28
|
<TestLayout json={{ props }}>
|
|
29
29
|
<TestPanel>
|
|
30
|
-
<FieldEditor {...props}
|
|
30
|
+
<FieldEditor {...props} onSave={handleComplete} />
|
|
31
31
|
</TestPanel>
|
|
32
32
|
</TestLayout>
|
|
33
33
|
);
|
|
@@ -26,14 +26,14 @@ export type FieldEditorProps = {
|
|
|
26
26
|
projection: ViewProjection;
|
|
27
27
|
field: FieldType;
|
|
28
28
|
registry?: SchemaResolver;
|
|
29
|
-
|
|
29
|
+
onSave: () => void;
|
|
30
30
|
onCancel?: () => void;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Displays a Form representing the metadata for a given `Field` and `View`.
|
|
35
35
|
*/
|
|
36
|
-
export const FieldEditor = ({ view, projection, field, registry,
|
|
36
|
+
export const FieldEditor = ({ view, projection, field, registry, onSave, onCancel }: FieldEditorProps) => {
|
|
37
37
|
const { t } = useTranslation(translationKey);
|
|
38
38
|
const [props, setProps] = useState<PropertyType>(projection.getFieldProjection(field.id).props);
|
|
39
39
|
useEffect(() => setProps(projection.getFieldProjection(field.id).props), [field, projection]);
|
|
@@ -100,19 +100,19 @@ export const FieldEditor = ({ view, projection, field, registry, onClose, onCanc
|
|
|
100
100
|
[view.fields, field],
|
|
101
101
|
);
|
|
102
102
|
|
|
103
|
-
const
|
|
103
|
+
const handleSave = useCallback<NonNullable<FormProps<PropertyType>['onSave']>>(
|
|
104
104
|
(props) => {
|
|
105
105
|
projection.setFieldProjection({ field, props });
|
|
106
|
-
|
|
106
|
+
onSave();
|
|
107
107
|
},
|
|
108
|
-
[projection, field,
|
|
108
|
+
[projection, field, onSave],
|
|
109
109
|
);
|
|
110
110
|
|
|
111
111
|
const handleCancel = useCallback<NonNullable<FormProps<PropertyType>['onCancel']>>(() => {
|
|
112
112
|
// Need to defer to allow form to close.
|
|
113
113
|
requestAnimationFrame(() => onCancel?.());
|
|
114
|
-
|
|
115
|
-
}, [
|
|
114
|
+
onSave();
|
|
115
|
+
}, [onSave]);
|
|
116
116
|
|
|
117
117
|
if (!fieldSchema) {
|
|
118
118
|
log.warn('invalid format', { props });
|
|
@@ -129,7 +129,7 @@ export const FieldEditor = ({ view, projection, field, registry, onClose, onCanc
|
|
|
129
129
|
sort={['property', 'format']}
|
|
130
130
|
onValuesChanged={handleValuesChanged}
|
|
131
131
|
onValidate={handleValidate}
|
|
132
|
-
|
|
132
|
+
onSave={handleSave}
|
|
133
133
|
onCancel={handleCancel}
|
|
134
134
|
Custom={{
|
|
135
135
|
['format' satisfies keyof PropertyType]: (props) => (
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type BaseObject, type GeoPoint } from '@dxos/echo-schema';
|
|
8
8
|
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
|
|
10
10
|
import { InputHeader, type InputProps } from './Input';
|
|
@@ -14,7 +14,7 @@ import { translationKey } from '../../translations';
|
|
|
14
14
|
// Custom format components.
|
|
15
15
|
//
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const GeiPointInput = <T extends BaseObject<T>>({
|
|
18
18
|
property,
|
|
19
19
|
type,
|
|
20
20
|
label,
|
|
@@ -26,7 +26,7 @@ export const LatLngInput = <T extends object>({
|
|
|
26
26
|
}: InputProps<T>) => {
|
|
27
27
|
const { t } = useTranslation(translationKey);
|
|
28
28
|
const { status, error } = getStatus?.(property);
|
|
29
|
-
const
|
|
29
|
+
const [lng = 0, lat = 0] = getValue<GeoPoint>(property) ?? [];
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<Input.Root validationValence={status}>
|
|
@@ -37,17 +37,17 @@ export const LatLngInput = <T extends object>({
|
|
|
37
37
|
<Input.TextInput
|
|
38
38
|
type='number'
|
|
39
39
|
disabled={disabled}
|
|
40
|
-
placeholder={t('placeholder
|
|
41
|
-
value={
|
|
42
|
-
onChange={(event) => onValueChange(property, type,
|
|
40
|
+
placeholder={t('placeholder longitude')}
|
|
41
|
+
value={lng}
|
|
42
|
+
onChange={(event) => onValueChange(property, type, [lat, safeParseFloat(event.target.value, 0)])}
|
|
43
43
|
onBlur={onBlur}
|
|
44
44
|
/>
|
|
45
45
|
<Input.TextInput
|
|
46
46
|
type='number'
|
|
47
47
|
disabled={disabled}
|
|
48
|
-
placeholder={t('placeholder
|
|
49
|
-
value={
|
|
50
|
-
onChange={(event) => onValueChange(property, type,
|
|
48
|
+
placeholder={t('placeholder latitude')}
|
|
49
|
+
value={lat}
|
|
50
|
+
onChange={(event) => onValueChange(property, type, [safeParseFloat(event.target.value, 0), lng])}
|
|
51
51
|
onBlur={onBlur}
|
|
52
52
|
/>
|
|
53
53
|
</div>
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
+
import { type BaseObject } from '@dxos/echo-schema';
|
|
7
8
|
import { Input, Select } from '@dxos/react-ui';
|
|
8
9
|
|
|
9
10
|
import { type InputProps, InputHeader } from './Input';
|
|
10
11
|
|
|
11
|
-
export const TextInput = <T extends
|
|
12
|
+
export const TextInput = <T extends BaseObject<T>>({
|
|
12
13
|
property,
|
|
13
14
|
type,
|
|
14
15
|
label,
|
|
@@ -37,7 +38,7 @@ export const TextInput = <T extends object>({
|
|
|
37
38
|
);
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
export const NumberInput = <T extends
|
|
41
|
+
export const NumberInput = <T extends BaseObject<T>>({
|
|
41
42
|
property,
|
|
42
43
|
type,
|
|
43
44
|
label,
|
|
@@ -68,7 +69,7 @@ export const NumberInput = <T extends object>({
|
|
|
68
69
|
);
|
|
69
70
|
};
|
|
70
71
|
|
|
71
|
-
export const BooleanInput = <T extends
|
|
72
|
+
export const BooleanInput = <T extends BaseObject<T>>({
|
|
72
73
|
property,
|
|
73
74
|
type,
|
|
74
75
|
label,
|
|
@@ -91,7 +92,11 @@ export const BooleanInput = <T extends object>({
|
|
|
91
92
|
);
|
|
92
93
|
};
|
|
93
94
|
|
|
94
|
-
export
|
|
95
|
+
export type SelectInputOptions<T extends BaseObject<T>> = InputProps<T> & {
|
|
96
|
+
options?: Array<{ value: string | number; label?: string }>;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const SelectInput = <T extends BaseObject<T>>({
|
|
95
100
|
property,
|
|
96
101
|
type,
|
|
97
102
|
label,
|
|
@@ -101,7 +106,7 @@ export const SelectInput = <T extends object>({
|
|
|
101
106
|
getStatus,
|
|
102
107
|
getValue,
|
|
103
108
|
onValueChange,
|
|
104
|
-
}:
|
|
109
|
+
}: SelectInputOptions<T>) => {
|
|
105
110
|
const { status, error } = getStatus?.(property);
|
|
106
111
|
|
|
107
112
|
return (
|
|
@@ -26,7 +26,7 @@ const TestSchema = S.Struct({
|
|
|
26
26
|
street: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Street' })),
|
|
27
27
|
city: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'City' })),
|
|
28
28
|
zip: S.optional(S.String.pipe(S.pattern(/^\d{5}(-\d{4})?$/)).annotations({ [AST.TitleAnnotationId]: 'ZIP' })),
|
|
29
|
-
location: S.optional(Format.
|
|
29
|
+
location: S.optional(Format.GeoPoint.annotations({ [AST.TitleAnnotationId]: 'Location' })),
|
|
30
30
|
}).annotations({ [AST.TitleAnnotationId]: 'Address' }),
|
|
31
31
|
),
|
|
32
32
|
}).pipe(S.mutable);
|
|
@@ -37,21 +37,21 @@ type StoryProps = FormProps<TestType>;
|
|
|
37
37
|
|
|
38
38
|
const DefaultStory = ({ values: initialValues }: StoryProps) => {
|
|
39
39
|
const [values, setValues] = useState(initialValues);
|
|
40
|
-
const
|
|
40
|
+
const handleSave = useCallback<NonNullable<FormProps<TestType>['onSave']>>((values) => {
|
|
41
41
|
setValues(values);
|
|
42
42
|
}, []);
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
45
|
<TestLayout json={{ values, schema: TestSchema.ast.toJSON() }}>
|
|
46
46
|
<TestPanel>
|
|
47
|
-
<Form<TestType> schema={TestSchema} values={values}
|
|
47
|
+
<Form<TestType> schema={TestSchema} values={values} onSave={handleSave} />
|
|
48
48
|
</TestPanel>
|
|
49
49
|
</TestLayout>
|
|
50
50
|
);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const meta: Meta<StoryProps> = {
|
|
54
|
-
title: 'ui/react-ui-
|
|
54
|
+
title: 'ui/react-ui-form/Form',
|
|
55
55
|
component: Form,
|
|
56
56
|
render: DefaultStory,
|
|
57
57
|
decorators: [withLayout({ fullscreen: true, tooltips: true }), withTheme],
|
|
@@ -96,7 +96,7 @@ type DiscriminatedUnionStoryProps = FormProps<ShapeType>;
|
|
|
96
96
|
|
|
97
97
|
const DiscriminatedUnionStory = ({ values: initialValues }: DiscriminatedUnionStoryProps) => {
|
|
98
98
|
const [values, setValues] = useState(initialValues);
|
|
99
|
-
const
|
|
99
|
+
const handleSave = useCallback<NonNullable<FormProps<ShapeType>['onSave']>>((values) => {
|
|
100
100
|
setValues(values);
|
|
101
101
|
}, []);
|
|
102
102
|
|
|
@@ -106,7 +106,7 @@ const DiscriminatedUnionStory = ({ values: initialValues }: DiscriminatedUnionSt
|
|
|
106
106
|
<Form<ShapeType>
|
|
107
107
|
schema={ShapeSchema}
|
|
108
108
|
values={values}
|
|
109
|
-
|
|
109
|
+
onSave={handleSave}
|
|
110
110
|
Custom={{
|
|
111
111
|
['shape.type' as const]: (props) => (
|
|
112
112
|
<SelectInput<ShapeType>
|