@dxos/react-ui-form 0.8.2-main.f081794 → 0.8.2-main.fbd8ed0
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 +827 -537
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +675 -395
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +827 -537
- 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.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +6 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +37 -34
- 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 +14 -11
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +2 -2
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +12 -0
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +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.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- 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/components/deprecated/Form.d.ts +2 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +23 -0
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +9 -0
- package/dist/types/src/util/refs.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +3 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -25
- package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +13 -17
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +92 -43
- package/src/components/Form/Form.tsx +7 -3
- package/src/components/Form/FormContent.tsx +90 -19
- package/src/components/Form/FormContext.tsx +13 -3
- package/src/components/Form/Input.tsx +3 -9
- package/src/components/Form/RefField.tsx +197 -0
- package/src/components/Form/custom/GeoPointInput.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +6 -5
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +0 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +5 -4
- package/src/components/ViewEditor/ViewEditor.tsx +23 -20
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useForm.ts +4 -3
- package/src/hooks/useQueryRefOptions.ts +53 -0
- package/src/hooks/useRefQueryLookupHandler.ts +41 -0
- package/src/util/formatting.ts +15 -3
- package/src/util/index.ts +3 -1
- package/src/util/refs.ts +38 -0
- package/src/util/schema.ts +14 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Schema
|
|
1
|
+
import { type Schema } from 'effect';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
4
4
|
import { type ViewType } from '@dxos/schema';
|
|
5
5
|
export type DeprecatedFormProps<T extends {} = {}> = ThemedClassName<{
|
|
6
6
|
view: ViewType;
|
|
7
7
|
object: T;
|
|
8
|
-
schema?:
|
|
8
|
+
schema?: Schema.Schema<T>;
|
|
9
9
|
readonly?: boolean;
|
|
10
10
|
}>;
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/Form.tsx"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../src/components/deprecated/Form.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9D,OAAO,KAAmB,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAS,KAAK,eAAe,EAA+C,MAAM,gBAAgB,CAAC;AAE1G,OAAO,EAAE,KAAK,QAAQ,EAAgC,MAAM,cAAc,CAAC;AAE3E,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,eAAe,CAAC;IACnE,IAAI,EAAE,QAAQ,CAAC;IACf,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,iDAM/C,mBAAmB,CAAC,CAAC,CAAC,sBA0DxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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,kBAAkB,CAAC;AAC5D,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAkC,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAIlE,QAAA,MAAM,YAAY,
|
|
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,kBAAkB,CAAC;AAC5D,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAkC,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAIlE,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 +1 @@
|
|
|
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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/components/testing.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/components/testing.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,eAAO,MAAM,SAAS,GAAI,0BAA0B,eAAe,CAAC,iBAAiB,CAAC,sBAIrF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,gCAAgC,eAAe,CAAC,iBAAiB,CAAC;IAAE,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC,sBAO5G,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Schema
|
|
1
|
+
import { type Schema } from 'effect';
|
|
2
2
|
import { type BaseObject } from '@dxos/echo-schema';
|
|
3
3
|
import { type SimpleType, type JsonPath } from '@dxos/effect';
|
|
4
4
|
import { type ValidationError } from '@dxos/schema';
|
|
@@ -29,7 +29,7 @@ export interface FormOptions<T extends BaseObject> {
|
|
|
29
29
|
/**
|
|
30
30
|
* Effect schema (Type literal).
|
|
31
31
|
*/
|
|
32
|
-
schema:
|
|
32
|
+
schema: Schema.Schema<T, any>;
|
|
33
33
|
/**
|
|
34
34
|
* Initial values (which may not pass validation).
|
|
35
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useForm.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhD,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAA4C,MAAM,cAAc,CAAC;AAGxG,OAAO,EAAkB,KAAK,eAAe,EAAE,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;IACrB,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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,eA0B5E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/util/field.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAe,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/util/field.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAe,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,yBAAyB,UAAU,QAsF7D,CAAC;AAGF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,kBAAkB,4BAA4B,KAAG,MAAM,EAAE,GAAG,SAmCnG,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,eAGhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../../src/util/formatting.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAe,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEtE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AAGH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../../src/util/formatting.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAe,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEtE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AAGH,eAAO,MAAM,gBAAgB,GAAI,iCAA6C,gBAAgB,KAAG,MAqFhG,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,iCAA6C,gBAAgB,KAAG,MA8DhG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type SchemaAST } from 'effect';
|
|
2
|
+
import { type SchemaProperty } from '@dxos/schema';
|
|
3
|
+
type RefProps = {
|
|
4
|
+
ast: SchemaAST.AST;
|
|
5
|
+
isArray: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const getRefProps: (property: SchemaProperty<any>) => RefProps | undefined;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../src/util/refs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD,KAAK,QAAQ,GAAG;IACd,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,UAAU,cAAc,CAAC,GAAG,CAAC,KAAG,QAAQ,GAAG,SAoBtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
{"version":"5.
|
|
1
|
+
{"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-form",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.fbd8ed0",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -28,46 +28,47 @@
|
|
|
28
28
|
"@radix-ui/react-context": "1.1.1",
|
|
29
29
|
"date-fns": "^3.3.1",
|
|
30
30
|
"jsonpath": "^1.1.1",
|
|
31
|
-
"@dxos/async": "0.8.2-main.
|
|
32
|
-
"@dxos/debug": "0.8.2-main.
|
|
33
|
-
"@dxos/echo-db": "0.8.2-main.
|
|
34
|
-
"@dxos/echo-schema": "0.8.2-main.
|
|
35
|
-
"@dxos/effect": "0.8.2-main.
|
|
36
|
-
"@dxos/invariant": "0.8.2-main.
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/log": "0.8.2-main.
|
|
40
|
-
"@dxos/react-
|
|
41
|
-
"@dxos/react-ui-
|
|
42
|
-
"@dxos/react-ui-
|
|
43
|
-
"@dxos/react-
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/schema": "0.8.2-main.
|
|
31
|
+
"@dxos/async": "0.8.2-main.fbd8ed0",
|
|
32
|
+
"@dxos/debug": "0.8.2-main.fbd8ed0",
|
|
33
|
+
"@dxos/echo-db": "0.8.2-main.fbd8ed0",
|
|
34
|
+
"@dxos/echo-schema": "0.8.2-main.fbd8ed0",
|
|
35
|
+
"@dxos/effect": "0.8.2-main.fbd8ed0",
|
|
36
|
+
"@dxos/invariant": "0.8.2-main.fbd8ed0",
|
|
37
|
+
"@dxos/keys": "0.8.2-main.fbd8ed0",
|
|
38
|
+
"@dxos/live-object": "0.8.2-main.fbd8ed0",
|
|
39
|
+
"@dxos/log": "0.8.2-main.fbd8ed0",
|
|
40
|
+
"@dxos/react-client": "0.8.2-main.fbd8ed0",
|
|
41
|
+
"@dxos/react-ui-list": "0.8.2-main.fbd8ed0",
|
|
42
|
+
"@dxos/react-ui-pickers": "0.8.2-main.fbd8ed0",
|
|
43
|
+
"@dxos/react-ui-tag-picker": "0.8.2-main.fbd8ed0",
|
|
44
|
+
"@dxos/react-ui-types": "0.8.2-main.fbd8ed0",
|
|
45
|
+
"@dxos/schema": "0.8.2-main.fbd8ed0",
|
|
46
|
+
"@dxos/util": "0.8.2-main.fbd8ed0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@phosphor-icons/react": "^2.1.5",
|
|
49
50
|
"@types/jsonpath": "^0.2.4",
|
|
50
51
|
"@types/react": "~18.2.0",
|
|
51
52
|
"@types/react-dom": "~18.2.0",
|
|
52
|
-
"effect": "3.
|
|
53
|
+
"effect": "3.14.21",
|
|
53
54
|
"fast-check": "^3.19.0",
|
|
54
55
|
"react": "~18.2.0",
|
|
55
56
|
"react-dom": "~18.2.0",
|
|
56
57
|
"vite": "5.4.7",
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/react-ui
|
|
60
|
-
"@dxos/react-ui-
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/storybook-utils": "0.8.2-main.
|
|
58
|
+
"@dxos/echo-signals": "0.8.2-main.fbd8ed0",
|
|
59
|
+
"@dxos/random": "0.8.2-main.fbd8ed0",
|
|
60
|
+
"@dxos/react-ui": "0.8.2-main.fbd8ed0",
|
|
61
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.2-main.fbd8ed0",
|
|
62
|
+
"@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
|
|
63
|
+
"@dxos/storybook-utils": "0.8.2-main.fbd8ed0"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|
|
65
66
|
"@phosphor-icons/react": "^2.1.5",
|
|
66
67
|
"effect": "3.13.3",
|
|
67
68
|
"react": "~18.2.0",
|
|
68
69
|
"react-dom": "~18.2.0",
|
|
69
|
-
"@dxos/react-ui": "0.8.2-main.
|
|
70
|
-
"@dxos/react-ui
|
|
70
|
+
"@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
|
|
71
|
+
"@dxos/react-ui": "0.8.2-main.fbd8ed0"
|
|
71
72
|
},
|
|
72
73
|
"publishConfig": {
|
|
73
74
|
"access": "public"
|
|
@@ -14,7 +14,7 @@ import translations from '../../translations';
|
|
|
14
14
|
const meta: Meta<ControlSectionProps> = {
|
|
15
15
|
title: 'ui/react-ui-form/ControlSection',
|
|
16
16
|
component: ControlSection,
|
|
17
|
-
decorators: [withLayout(
|
|
17
|
+
decorators: [withLayout(), withTheme],
|
|
18
18
|
parameters: {
|
|
19
19
|
translations,
|
|
20
20
|
},
|
|
@@ -37,7 +37,7 @@ const meta: Meta<StoryProps> = {
|
|
|
37
37
|
title: 'ui/react-ui-form/FieldEditor',
|
|
38
38
|
component: FieldEditor,
|
|
39
39
|
render: DefaultStory,
|
|
40
|
-
decorators: [withLayout({ fullscreen: true
|
|
40
|
+
decorators: [withLayout({ fullscreen: true }), withTheme],
|
|
41
41
|
parameters: {
|
|
42
42
|
translations,
|
|
43
43
|
},
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { pipe } from 'effect';
|
|
5
|
+
import { SchemaAST, pipe } from 'effect';
|
|
6
6
|
import { capitalize } from 'effect/String';
|
|
7
|
-
import React, { useCallback
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
8
8
|
|
|
9
|
-
import { AST } from '@dxos/echo-schema';
|
|
10
9
|
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from '@dxos/effect';
|
|
11
10
|
import { invariant } from '@dxos/invariant';
|
|
12
11
|
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
@@ -18,6 +17,7 @@ import { FormField } from './FormContent';
|
|
|
18
17
|
import { useFormValues, type FormInputStateProps } from './FormContext';
|
|
19
18
|
import { InputHeader, type InputComponent } from './Input';
|
|
20
19
|
import { translationKey } from '../../translations';
|
|
20
|
+
import { findArrayElementType } from '../../util';
|
|
21
21
|
|
|
22
22
|
const padding = 'px-2';
|
|
23
23
|
|
|
@@ -33,16 +33,17 @@ type ArrayFieldProps = {
|
|
|
33
33
|
export const ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }: ArrayFieldProps) => {
|
|
34
34
|
const { t } = useTranslation(translationKey);
|
|
35
35
|
const { ast, name, type, title } = property;
|
|
36
|
-
|
|
36
|
+
// TODO(wittjosiah): The fallback to an empty array stops the form from crashing but isn't immediately live.
|
|
37
|
+
// It doesn't become live until another field is touched, but that's better than the whole form crashing.
|
|
38
|
+
const values = (useFormValues(path ?? []) ?? []) as any[];
|
|
37
39
|
invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
|
|
38
40
|
const label = title ?? pipe(name, capitalize);
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
const elementType = (tupleType as AST.TupleType | undefined)?.rest[0]?.type;
|
|
42
|
+
const elementType = findArrayElementType(ast);
|
|
42
43
|
|
|
43
|
-
const getDefaultObjectValue = (typeNode:
|
|
44
|
+
const getDefaultObjectValue = (typeNode: SchemaAST.AST): any => {
|
|
44
45
|
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
45
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode,
|
|
46
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST.isTypeLiteral);
|
|
46
47
|
if (!typeLiteral) {
|
|
47
48
|
return {};
|
|
48
49
|
}
|
|
@@ -50,17 +51,12 @@ export const ArrayField = ({ property, readonly, path, inputProps, Custom, looku
|
|
|
50
51
|
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [prop.name, prop.defaultValue]));
|
|
51
52
|
};
|
|
52
53
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
return getDefaultObjectValue(elementType);
|
|
56
|
-
} else {
|
|
57
|
-
return SimpleType.getDefaultValue(type);
|
|
58
|
-
}
|
|
59
|
-
}, [type, elementType]);
|
|
54
|
+
const getDefaultValue = () =>
|
|
55
|
+
type === 'object' && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
60
56
|
|
|
61
57
|
const handleAdd = useCallback(() => {
|
|
62
|
-
inputProps.onValueChange(type, [...values,
|
|
63
|
-
}, [type, elementType, inputProps,
|
|
58
|
+
inputProps.onValueChange(type, [...values, getDefaultValue()]);
|
|
59
|
+
}, [type, elementType, inputProps, values]);
|
|
64
60
|
|
|
65
61
|
const handleRemove = useCallback(
|
|
66
62
|
(index: number) => {
|
|
@@ -107,6 +107,9 @@ export const SelectInput = ({
|
|
|
107
107
|
}: SelectInputOptions) => {
|
|
108
108
|
const { status, error } = getStatus();
|
|
109
109
|
|
|
110
|
+
const value = getValue() as string | undefined;
|
|
111
|
+
const handleValueChange = useCallback((value: string | number) => onValueChange(type, value), [type, onValueChange]);
|
|
112
|
+
|
|
110
113
|
return (
|
|
111
114
|
<Input.Root validationValence={status}>
|
|
112
115
|
{!inputOnly && (
|
|
@@ -114,7 +117,7 @@ export const SelectInput = ({
|
|
|
114
117
|
<Input.Label>{label}</Input.Label>
|
|
115
118
|
</InputHeader>
|
|
116
119
|
)}
|
|
117
|
-
<Select.Root value={
|
|
120
|
+
<Select.Root value={value} onValueChange={handleValueChange}>
|
|
118
121
|
{/* TODO(burdon): Placeholder not working? */}
|
|
119
122
|
<Select.TriggerButton classNames='is-full' disabled={disabled} placeholder={placeholder} />
|
|
120
123
|
<Select.Portal>
|
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
7
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
8
|
+
import { Schema, SchemaAST } from 'effect';
|
|
8
9
|
import React, { useCallback, useState } from 'react';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
+
import { ContactType } from '@dxos/client/testing';
|
|
12
|
+
import { type BaseObject, Expando, Format, getDXN, Ref, type TypeAnnotation } from '@dxos/echo-schema';
|
|
13
|
+
import { live } from '@dxos/live-object';
|
|
11
14
|
import { Testing } from '@dxos/schema/testing';
|
|
12
15
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
13
16
|
|
|
@@ -16,25 +19,27 @@ import { Form, type FormProps } from './Form';
|
|
|
16
19
|
import translations from '../../translations';
|
|
17
20
|
import { TestLayout, TestPanel } from '../testing';
|
|
18
21
|
|
|
19
|
-
const AddressSchema =
|
|
20
|
-
street:
|
|
21
|
-
city:
|
|
22
|
-
zip:
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const AddressSchema = Schema.Struct({
|
|
23
|
+
street: Schema.optional(Schema.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Street' })),
|
|
24
|
+
city: Schema.optional(Schema.String.annotations({ [SchemaAST.TitleAnnotationId]: 'City' })),
|
|
25
|
+
zip: Schema.optional(
|
|
26
|
+
Schema.String.pipe(Schema.pattern(/^\d{5}(-\d{4})?$/)).annotations({ [SchemaAST.TitleAnnotationId]: 'ZIP' }),
|
|
27
|
+
),
|
|
28
|
+
location: Schema.optional(Format.GeoPoint.annotations({ [SchemaAST.TitleAnnotationId]: 'Location' })),
|
|
29
|
+
}).annotations({ [SchemaAST.TitleAnnotationId]: 'Address' });
|
|
25
30
|
|
|
26
31
|
// TODO(burdon): Translations?
|
|
27
|
-
const TestSchema =
|
|
28
|
-
name:
|
|
29
|
-
active:
|
|
30
|
-
rank:
|
|
31
|
-
website:
|
|
32
|
-
address:
|
|
33
|
-
}).pipe(
|
|
32
|
+
const TestSchema = Schema.Struct({
|
|
33
|
+
name: Schema.optional(Schema.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Name' })),
|
|
34
|
+
active: Schema.optional(Schema.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Active' })),
|
|
35
|
+
rank: Schema.optional(Schema.Number.annotations({ [SchemaAST.TitleAnnotationId]: 'Rank' })),
|
|
36
|
+
website: Schema.optional(Format.URL.annotations({ [SchemaAST.TitleAnnotationId]: 'Website' })),
|
|
37
|
+
address: Schema.optional(AddressSchema),
|
|
38
|
+
}).pipe(Schema.mutable);
|
|
34
39
|
|
|
35
|
-
type TestType =
|
|
40
|
+
type TestType = Schema.Schema.Type<typeof TestSchema>;
|
|
36
41
|
|
|
37
|
-
type StoryProps<T extends BaseObject> = { schema:
|
|
42
|
+
type StoryProps<T extends BaseObject> = { schema: Schema.Schema<T> } & FormProps<T>;
|
|
38
43
|
|
|
39
44
|
const DefaultStory = <T extends BaseObject>({ schema, values: initialValues, ...props }: StoryProps<T>) => {
|
|
40
45
|
const [values, setValues] = useState(initialValues);
|
|
@@ -55,7 +60,7 @@ const meta: Meta<StoryProps<any>> = {
|
|
|
55
60
|
title: 'ui/react-ui-form/Form',
|
|
56
61
|
component: Form,
|
|
57
62
|
render: DefaultStory,
|
|
58
|
-
decorators: [withLayout({ fullscreen: true
|
|
63
|
+
decorators: [withLayout({ fullscreen: true }), withTheme],
|
|
59
64
|
parameters: {
|
|
60
65
|
translations,
|
|
61
66
|
},
|
|
@@ -78,9 +83,9 @@ export const Default: Story<TestType> = {
|
|
|
78
83
|
},
|
|
79
84
|
};
|
|
80
85
|
|
|
81
|
-
export const
|
|
86
|
+
export const Organization: Story<Testing.Organization> = {
|
|
82
87
|
args: {
|
|
83
|
-
schema: Testing.
|
|
88
|
+
schema: Testing.OrganizationSchema,
|
|
84
89
|
values: {
|
|
85
90
|
name: 'DXOS',
|
|
86
91
|
// website: 'https://dxos.org',
|
|
@@ -88,9 +93,9 @@ export const Org: Story<Testing.Org> = {
|
|
|
88
93
|
},
|
|
89
94
|
};
|
|
90
95
|
|
|
91
|
-
export const
|
|
96
|
+
export const OrganizationAutoSave: Story<Testing.Organization> = {
|
|
92
97
|
args: {
|
|
93
|
-
schema: Testing.
|
|
98
|
+
schema: Testing.OrganizationSchema,
|
|
94
99
|
values: {
|
|
95
100
|
name: 'DXOS',
|
|
96
101
|
// website: 'https://dxos.org',
|
|
@@ -115,22 +120,24 @@ export const OrgAutoSave: Story<Testing.Org> = {
|
|
|
115
120
|
// TODO(burdon): Move into separate storybook and use test types.
|
|
116
121
|
//
|
|
117
122
|
|
|
118
|
-
const ShapeSchema =
|
|
119
|
-
shape:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
type:
|
|
123
|
-
radius:
|
|
123
|
+
const ShapeSchema = Schema.Struct({
|
|
124
|
+
shape: Schema.optional(
|
|
125
|
+
Schema.Union(
|
|
126
|
+
Schema.Struct({
|
|
127
|
+
type: Schema.Literal('circle').annotations({ [SchemaAST.TitleAnnotationId]: 'Type' }),
|
|
128
|
+
radius: Schema.optional(Schema.Number.annotations({ [SchemaAST.TitleAnnotationId]: 'Radius' })),
|
|
124
129
|
}),
|
|
125
|
-
|
|
126
|
-
type:
|
|
127
|
-
size:
|
|
130
|
+
Schema.Struct({
|
|
131
|
+
type: Schema.Literal('square').annotations({ [SchemaAST.TitleAnnotationId]: 'Type' }),
|
|
132
|
+
size: Schema.optional(
|
|
133
|
+
Schema.Number.pipe(Schema.nonNegative()).annotations({ [SchemaAST.TitleAnnotationId]: 'Size' }),
|
|
134
|
+
),
|
|
128
135
|
}),
|
|
129
|
-
).annotations({ [
|
|
136
|
+
).annotations({ [SchemaAST.TitleAnnotationId]: 'Shape' }),
|
|
130
137
|
),
|
|
131
|
-
}).pipe(
|
|
138
|
+
}).pipe(Schema.mutable);
|
|
132
139
|
|
|
133
|
-
type ShapeType =
|
|
140
|
+
type ShapeType = Schema.Schema.Type<typeof ShapeSchema>;
|
|
134
141
|
|
|
135
142
|
type DiscriminatedUnionStoryProps = FormProps<ShapeType>;
|
|
136
143
|
|
|
@@ -176,12 +183,12 @@ export const DiscriminatedShape: StoryObj<DiscriminatedUnionStoryProps> = {
|
|
|
176
183
|
},
|
|
177
184
|
};
|
|
178
185
|
|
|
179
|
-
const ArraysSchema =
|
|
180
|
-
names:
|
|
181
|
-
addresses:
|
|
182
|
-
}).pipe(
|
|
186
|
+
const ArraysSchema = Schema.Struct({
|
|
187
|
+
names: Schema.Array(Schema.String.pipe(Schema.nonEmptyString())),
|
|
188
|
+
addresses: Schema.Array(AddressSchema),
|
|
189
|
+
}).pipe(Schema.mutable);
|
|
183
190
|
|
|
184
|
-
type ArraysType =
|
|
191
|
+
type ArraysType = Schema.Schema.Type<typeof ArraysSchema>;
|
|
185
192
|
|
|
186
193
|
const ArraysStory = ({ values: initialValues }: FormProps<ArraysType>) => {
|
|
187
194
|
const [values, setValues] = useState(initialValues);
|
|
@@ -208,13 +215,13 @@ export const Arrays: StoryObj<FormProps<ArraysType>> = {
|
|
|
208
215
|
},
|
|
209
216
|
};
|
|
210
217
|
|
|
211
|
-
const ColorSchema =
|
|
212
|
-
color:
|
|
213
|
-
[
|
|
218
|
+
const ColorSchema = Schema.Struct({
|
|
219
|
+
color: Schema.Union(Schema.Literal('red'), Schema.Literal('green'), Schema.Literal('blue')).annotations({
|
|
220
|
+
[SchemaAST.TitleAnnotationId]: 'Color',
|
|
214
221
|
}),
|
|
215
|
-
}).pipe(
|
|
222
|
+
}).pipe(Schema.mutable);
|
|
216
223
|
|
|
217
|
-
type ColorType =
|
|
224
|
+
type ColorType = Schema.Schema.Type<typeof ColorSchema>;
|
|
218
225
|
|
|
219
226
|
const EnumStory = ({ values: initialValues }: FormProps<ColorType>) => {
|
|
220
227
|
const [values, setValues] = useState(initialValues);
|
|
@@ -239,3 +246,45 @@ export const Enum: StoryObj<FormProps<ColorType>> = {
|
|
|
239
246
|
},
|
|
240
247
|
},
|
|
241
248
|
};
|
|
249
|
+
|
|
250
|
+
const RefSchema = Schema.Struct({
|
|
251
|
+
contact: Ref(ContactType).annotations({ title: 'Contact Reference' }),
|
|
252
|
+
optionalContact: Schema.optional(Ref(ContactType).annotations({ title: 'Optional Contact Reference' })),
|
|
253
|
+
refArray: Schema.optional(Schema.Array(Ref(ContactType))),
|
|
254
|
+
unknownExpando: Schema.optional(Ref(Expando).annotations({ title: 'Optional Ref to an Expando (DXN Input)' })),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const RefStory = ({ values: initialValues }: FormProps<any>) => {
|
|
258
|
+
const [values, setValues] = useState(initialValues);
|
|
259
|
+
const handleSave = useCallback<NonNullable<FormProps<any>['onSave']>>((values) => {
|
|
260
|
+
setValues(values);
|
|
261
|
+
}, []);
|
|
262
|
+
|
|
263
|
+
const contact1 = live(ContactType, { identifiers: [] });
|
|
264
|
+
const contact2 = live(ContactType, { identifiers: [] });
|
|
265
|
+
|
|
266
|
+
const onQueryRefOptions = useCallback((typeInfo: TypeAnnotation) => {
|
|
267
|
+
switch (typeInfo.typename) {
|
|
268
|
+
case ContactType.typename:
|
|
269
|
+
return [
|
|
270
|
+
{ dxn: getDXN(contact1)!, label: 'John Coltraine' },
|
|
271
|
+
{ dxn: getDXN(contact2)!, label: 'Erykah Badu' },
|
|
272
|
+
];
|
|
273
|
+
default:
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
}, []);
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<TestLayout json={{ values, schema: RefSchema.ast.toJSON() }}>
|
|
280
|
+
<TestPanel>
|
|
281
|
+
<Form schema={RefSchema} values={values} onSave={handleSave} onQueryRefOptions={onQueryRefOptions} />
|
|
282
|
+
</TestPanel>
|
|
283
|
+
</TestLayout>
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export const Refs: StoryObj<FormProps<ContactType>> = {
|
|
288
|
+
render: RefStory,
|
|
289
|
+
args: { values: {} },
|
|
290
|
+
};
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Schema } from 'effect';
|
|
5
6
|
import React, { type ReactElement, useEffect, useMemo, useRef } from 'react';
|
|
6
7
|
|
|
7
|
-
import { type BaseObject, type
|
|
8
|
+
import { type BaseObject, type PropertyKey } from '@dxos/echo-schema';
|
|
8
9
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
9
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
10
11
|
import { type SchemaProperty } from '@dxos/schema';
|
|
@@ -13,13 +14,13 @@ import { FormActions } from './FormActions';
|
|
|
13
14
|
import { FormFields } from './FormContent';
|
|
14
15
|
import { FormProvider } from './FormContext';
|
|
15
16
|
import { type InputProps, type InputComponent } from './Input';
|
|
16
|
-
import { type FormOptions } from '../../hooks';
|
|
17
|
+
import { type FormOptions, type QueryRefOptions } from '../../hooks';
|
|
17
18
|
|
|
18
19
|
export type PropsFilter<T extends BaseObject> = (props: SchemaProperty<T>[]) => SchemaProperty<T>[];
|
|
19
20
|
|
|
20
21
|
export type ComponentLookup = (args: {
|
|
21
22
|
prop: string;
|
|
22
|
-
schema:
|
|
23
|
+
schema: Schema.Schema<any>;
|
|
23
24
|
inputProps: InputProps;
|
|
24
25
|
}) => ReactElement | undefined;
|
|
25
26
|
|
|
@@ -41,6 +42,7 @@ export type FormProps<T extends BaseObject> = ThemedClassName<
|
|
|
41
42
|
autoSave?: boolean;
|
|
42
43
|
testId?: string;
|
|
43
44
|
onCancel?: () => void;
|
|
45
|
+
onQueryRefOptions?: QueryRefOptions;
|
|
44
46
|
lookupComponent?: ComponentLookup;
|
|
45
47
|
/**
|
|
46
48
|
* Map of custom renderers for specific properties.
|
|
@@ -65,6 +67,7 @@ export const Form = <T extends BaseObject>({
|
|
|
65
67
|
onValidate,
|
|
66
68
|
onSave,
|
|
67
69
|
onCancel,
|
|
70
|
+
onQueryRefOptions,
|
|
68
71
|
lookupComponent,
|
|
69
72
|
Custom,
|
|
70
73
|
}: FormProps<T>) => {
|
|
@@ -100,6 +103,7 @@ export const Form = <T extends BaseObject>({
|
|
|
100
103
|
readonly={readonly}
|
|
101
104
|
filter={filter}
|
|
102
105
|
sort={sort}
|
|
106
|
+
onQueryRefOptions={onQueryRefOptions}
|
|
103
107
|
lookupComponent={lookupComponent}
|
|
104
108
|
Custom={Custom}
|
|
105
109
|
/>
|