@dxos/react-ui-form 0.8.2-main.36232bc → 0.8.2-main.5ca3450
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 +275 -117
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +258 -103
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +275 -117
- 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 -3
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +35 -32
- 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.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +24 -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.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +1 -0
- 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.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 +1 -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/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/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -25
- package/src/components/Form/ArrayField.tsx +5 -6
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +86 -38
- package/src/components/Form/Form.tsx +7 -2
- package/src/components/Form/FormContent.tsx +62 -19
- package/src/components/Form/RefField.tsx +152 -0
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +5 -4
- package/src/components/Form/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +3 -2
- package/src/components/ViewEditor/ViewEditor.tsx +12 -10
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useForm.ts +3 -3
- package/src/hooks/useRefQueryLookupHandler.ts +43 -0
|
@@ -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"}
|
|
@@ -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,CAmLhC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
2
|
+
import { type QueryRefOptions } from '../components';
|
|
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,eAAe,CAAC;AAErD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,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":"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.5ca3450",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -28,46 +28,46 @@
|
|
|
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/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/invariant": "0.8.2-main.
|
|
37
|
-
"@dxos/keys": "0.8.2-main.
|
|
38
|
-
"@dxos/live-object": "0.8.2-main.
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/react-
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/react-ui-
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/schema": "0.8.2-main.
|
|
45
|
-
"@dxos/
|
|
31
|
+
"@dxos/async": "0.8.2-main.5ca3450",
|
|
32
|
+
"@dxos/debug": "0.8.2-main.5ca3450",
|
|
33
|
+
"@dxos/echo-db": "0.8.2-main.5ca3450",
|
|
34
|
+
"@dxos/echo-schema": "0.8.2-main.5ca3450",
|
|
35
|
+
"@dxos/effect": "0.8.2-main.5ca3450",
|
|
36
|
+
"@dxos/invariant": "0.8.2-main.5ca3450",
|
|
37
|
+
"@dxos/keys": "0.8.2-main.5ca3450",
|
|
38
|
+
"@dxos/live-object": "0.8.2-main.5ca3450",
|
|
39
|
+
"@dxos/react-client": "0.8.2-main.5ca3450",
|
|
40
|
+
"@dxos/react-ui-list": "0.8.2-main.5ca3450",
|
|
41
|
+
"@dxos/log": "0.8.2-main.5ca3450",
|
|
42
|
+
"@dxos/react-ui-pickers": "0.8.2-main.5ca3450",
|
|
43
|
+
"@dxos/react-ui-types": "0.8.2-main.5ca3450",
|
|
44
|
+
"@dxos/schema": "0.8.2-main.5ca3450",
|
|
45
|
+
"@dxos/util": "0.8.2-main.5ca3450"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@phosphor-icons/react": "^2.1.5",
|
|
49
49
|
"@types/jsonpath": "^0.2.4",
|
|
50
50
|
"@types/react": "~18.2.0",
|
|
51
51
|
"@types/react-dom": "~18.2.0",
|
|
52
|
-
"effect": "3.
|
|
52
|
+
"effect": "3.14.21",
|
|
53
53
|
"fast-check": "^3.19.0",
|
|
54
54
|
"react": "~18.2.0",
|
|
55
55
|
"react-dom": "~18.2.0",
|
|
56
56
|
"vite": "5.4.7",
|
|
57
|
-
"@dxos/echo-signals": "0.8.2-main.
|
|
58
|
-
"@dxos/random": "0.8.2-main.
|
|
59
|
-
"@dxos/react-ui": "0.8.2-main.
|
|
60
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.2-main.
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
57
|
+
"@dxos/echo-signals": "0.8.2-main.5ca3450",
|
|
58
|
+
"@dxos/random": "0.8.2-main.5ca3450",
|
|
59
|
+
"@dxos/react-ui": "0.8.2-main.5ca3450",
|
|
60
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.2-main.5ca3450",
|
|
61
|
+
"@dxos/react-ui-theme": "0.8.2-main.5ca3450",
|
|
62
|
+
"@dxos/storybook-utils": "0.8.2-main.5ca3450"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@phosphor-icons/react": "^2.1.5",
|
|
66
66
|
"effect": "3.13.3",
|
|
67
67
|
"react": "~18.2.0",
|
|
68
68
|
"react-dom": "~18.2.0",
|
|
69
|
-
"@dxos/react-ui": "0.8.2-main.
|
|
70
|
-
"@dxos/react-ui-theme": "0.8.2-main.
|
|
69
|
+
"@dxos/react-ui": "0.8.2-main.5ca3450",
|
|
70
|
+
"@dxos/react-ui-theme": "0.8.2-main.5ca3450"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|
|
@@ -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
7
|
import React, { useCallback, useMemo } 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';
|
|
@@ -39,12 +38,12 @@ export const ArrayField = ({ property, readonly, path, inputProps, Custom, looku
|
|
|
39
38
|
invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
|
|
40
39
|
const label = title ?? pipe(name, capitalize);
|
|
41
40
|
|
|
42
|
-
const tupleType = findNode(ast,
|
|
43
|
-
const elementType = (tupleType as
|
|
41
|
+
const tupleType = findNode(ast, SchemaAST.isTupleType);
|
|
42
|
+
const elementType = (tupleType as SchemaAST.TupleType | undefined)?.rest[0]?.type;
|
|
44
43
|
|
|
45
|
-
const getDefaultObjectValue = (typeNode:
|
|
44
|
+
const getDefaultObjectValue = (typeNode: SchemaAST.AST): any => {
|
|
46
45
|
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
47
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode,
|
|
46
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST.isTypeLiteral);
|
|
48
47
|
if (!typeLiteral) {
|
|
49
48
|
return {};
|
|
50
49
|
}
|
|
@@ -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);
|
|
@@ -115,22 +120,24 @@ export const OrganizationAutoSave: Story<Testing.Organization> = {
|
|
|
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,44 @@ 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
|
+
unknownExpando: Schema.optional(Ref(Expando).annotations({ title: 'Optional Ref to an Expando (DXN Input)' })),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const RefStory = ({ values: initialValues }: FormProps<any>) => {
|
|
257
|
+
const [values, setValues] = useState(initialValues);
|
|
258
|
+
const handleSave = useCallback<NonNullable<FormProps<any>['onSave']>>((values) => {
|
|
259
|
+
setValues(values);
|
|
260
|
+
}, []);
|
|
261
|
+
|
|
262
|
+
const contact1 = live(ContactType, { identifiers: [] });
|
|
263
|
+
const contact2 = live(ContactType, { identifiers: [] });
|
|
264
|
+
|
|
265
|
+
const onQueryRefOptions = useCallback((typeInfo: TypeAnnotation) => {
|
|
266
|
+
switch (typeInfo.typename) {
|
|
267
|
+
case ContactType.typename:
|
|
268
|
+
return [
|
|
269
|
+
{ dxn: getDXN(contact1)!, label: 'John Coltraine' },
|
|
270
|
+
{ dxn: getDXN(contact2)!, label: 'Erykah Badu' },
|
|
271
|
+
];
|
|
272
|
+
default:
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
}, []);
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<TestLayout json={{ values, schema: RefSchema.ast.toJSON() }}>
|
|
279
|
+
<TestPanel>
|
|
280
|
+
<Form schema={RefSchema} values={values} onSave={handleSave} onQueryRefOptions={onQueryRefOptions} />
|
|
281
|
+
</TestPanel>
|
|
282
|
+
</TestLayout>
|
|
283
|
+
);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export const Refs: StoryObj<FormProps<ContactType>> = {
|
|
287
|
+
render: RefStory,
|
|
288
|
+
args: { values: {} },
|
|
289
|
+
};
|
|
@@ -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,14 @@ 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';
|
|
17
|
+
import { type QueryRefOptions } from './RefField';
|
|
16
18
|
import { type FormOptions } from '../../hooks';
|
|
17
19
|
|
|
18
20
|
export type PropsFilter<T extends BaseObject> = (props: SchemaProperty<T>[]) => SchemaProperty<T>[];
|
|
19
21
|
|
|
20
22
|
export type ComponentLookup = (args: {
|
|
21
23
|
prop: string;
|
|
22
|
-
schema:
|
|
24
|
+
schema: Schema.Schema<any>;
|
|
23
25
|
inputProps: InputProps;
|
|
24
26
|
}) => ReactElement | undefined;
|
|
25
27
|
|
|
@@ -41,6 +43,7 @@ export type FormProps<T extends BaseObject> = ThemedClassName<
|
|
|
41
43
|
autoSave?: boolean;
|
|
42
44
|
testId?: string;
|
|
43
45
|
onCancel?: () => void;
|
|
46
|
+
onQueryRefOptions?: QueryRefOptions;
|
|
44
47
|
lookupComponent?: ComponentLookup;
|
|
45
48
|
/**
|
|
46
49
|
* Map of custom renderers for specific properties.
|
|
@@ -65,6 +68,7 @@ export const Form = <T extends BaseObject>({
|
|
|
65
68
|
onValidate,
|
|
66
69
|
onSave,
|
|
67
70
|
onCancel,
|
|
71
|
+
onQueryRefOptions,
|
|
68
72
|
lookupComponent,
|
|
69
73
|
Custom,
|
|
70
74
|
}: FormProps<T>) => {
|
|
@@ -100,6 +104,7 @@ export const Form = <T extends BaseObject>({
|
|
|
100
104
|
readonly={readonly}
|
|
101
105
|
filter={filter}
|
|
102
106
|
sort={sort}
|
|
107
|
+
onQueryRefOptions={onQueryRefOptions}
|
|
103
108
|
lookupComponent={lookupComponent}
|
|
104
109
|
Custom={Custom}
|
|
105
110
|
/>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { pipe } from 'effect';
|
|
5
|
+
import { Schema, SchemaAST, pipe } from 'effect';
|
|
6
6
|
import { capitalize } from 'effect/String';
|
|
7
7
|
import React, { useMemo } from 'react';
|
|
8
8
|
|
|
9
|
-
import { AST, S } from '@dxos/echo-schema';
|
|
10
9
|
import { createJsonPath, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
|
|
11
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
12
11
|
import { getSchemaProperties, type SchemaProperty } from '@dxos/schema';
|
|
@@ -17,29 +16,29 @@ import { SelectInput } from './Defaults';
|
|
|
17
16
|
import { type ComponentLookup } from './Form';
|
|
18
17
|
import { useInputProps, useFormValues } from './FormContext';
|
|
19
18
|
import { type InputComponent } from './Input';
|
|
19
|
+
import { RefField, type QueryRefOptions } from './RefField';
|
|
20
20
|
import { getInputComponent } from './factory';
|
|
21
21
|
|
|
22
|
-
export type FormContentProps = {
|
|
23
|
-
schema: S.Schema.All;
|
|
24
|
-
path?: (string | number)[];
|
|
25
|
-
filter?: (props: SchemaProperty<any>[]) => SchemaProperty<any>[];
|
|
26
|
-
sort?: string[];
|
|
27
|
-
readonly?: boolean;
|
|
28
|
-
lookupComponent?: ComponentLookup;
|
|
29
|
-
Custom?: Partial<Record<string, InputComponent>>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
22
|
export type FormFieldProps = {
|
|
33
23
|
property: SchemaProperty<any>;
|
|
34
24
|
path?: (string | number)[];
|
|
35
25
|
readonly?: boolean;
|
|
36
26
|
/** Used to indicate if input should be presented inline (e.g. for array items). */
|
|
37
27
|
inline?: boolean;
|
|
28
|
+
onQueryRefOptions?: QueryRefOptions;
|
|
38
29
|
lookupComponent?: ComponentLookup;
|
|
39
30
|
Custom?: Partial<Record<string, InputComponent>>;
|
|
40
31
|
};
|
|
41
32
|
|
|
42
|
-
export const FormField = ({
|
|
33
|
+
export const FormField = ({
|
|
34
|
+
property,
|
|
35
|
+
path,
|
|
36
|
+
readonly,
|
|
37
|
+
inline,
|
|
38
|
+
onQueryRefOptions,
|
|
39
|
+
lookupComponent,
|
|
40
|
+
Custom,
|
|
41
|
+
}: FormFieldProps) => {
|
|
43
42
|
const inputProps = useInputProps(path);
|
|
44
43
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
45
44
|
|
|
@@ -51,7 +50,7 @@ export const FormField = ({ property, path, readonly, inline, lookupComponent, C
|
|
|
51
50
|
|
|
52
51
|
const FoundComponent = lookupComponent?.({
|
|
53
52
|
prop: name,
|
|
54
|
-
schema:
|
|
53
|
+
schema: Schema.make(ast),
|
|
55
54
|
inputProps: {
|
|
56
55
|
type,
|
|
57
56
|
format,
|
|
@@ -120,17 +119,40 @@ export const FormField = ({ property, path, readonly, inline, lookupComponent, C
|
|
|
120
119
|
);
|
|
121
120
|
}
|
|
122
121
|
|
|
122
|
+
// TODO(ZaymonFC): Extract this to it's own component.
|
|
123
|
+
if (format === 'ref') {
|
|
124
|
+
return (
|
|
125
|
+
<RefField
|
|
126
|
+
ast={ast}
|
|
127
|
+
type={type}
|
|
128
|
+
label={label}
|
|
129
|
+
readonly={readonly}
|
|
130
|
+
placeholder={placeholder}
|
|
131
|
+
inline={inline}
|
|
132
|
+
onQueryRefOptions={onQueryRefOptions}
|
|
133
|
+
inputProps={inputProps}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
if (type === 'object') {
|
|
124
139
|
const baseNode = findNode(ast, isDiscriminatedUnion);
|
|
125
140
|
const typeLiteral = baseNode
|
|
126
141
|
? getDiscriminatedType(baseNode, inputProps.getValue() as any)
|
|
127
|
-
: findNode(ast,
|
|
142
|
+
: findNode(ast, SchemaAST.isTypeLiteral);
|
|
128
143
|
|
|
129
144
|
if (typeLiteral) {
|
|
130
145
|
return (
|
|
131
146
|
<div role='none'>
|
|
132
|
-
{!inline && <
|
|
133
|
-
<FormFields
|
|
147
|
+
{!inline && <h3 className='text-lg mbs-2 mbe-1'>{label}</h3>}
|
|
148
|
+
<FormFields
|
|
149
|
+
schema={Schema.make(typeLiteral)}
|
|
150
|
+
path={path}
|
|
151
|
+
readonly={readonly}
|
|
152
|
+
onQueryRefOptions={onQueryRefOptions}
|
|
153
|
+
Custom={Custom}
|
|
154
|
+
lookupComponent={lookupComponent}
|
|
155
|
+
/>
|
|
134
156
|
</div>
|
|
135
157
|
);
|
|
136
158
|
}
|
|
@@ -139,7 +161,27 @@ export const FormField = ({ property, path, readonly, inline, lookupComponent, C
|
|
|
139
161
|
return null;
|
|
140
162
|
};
|
|
141
163
|
|
|
142
|
-
export
|
|
164
|
+
export type FormContentProps = {
|
|
165
|
+
schema: Schema.Schema.All;
|
|
166
|
+
path?: (string | number)[];
|
|
167
|
+
filter?: (props: SchemaProperty<any>[]) => SchemaProperty<any>[];
|
|
168
|
+
sort?: string[];
|
|
169
|
+
readonly?: boolean;
|
|
170
|
+
onQueryRefOptions?: QueryRefOptions;
|
|
171
|
+
lookupComponent?: ComponentLookup;
|
|
172
|
+
Custom?: Partial<Record<string, InputComponent>>;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const FormFields = ({
|
|
176
|
+
schema,
|
|
177
|
+
path,
|
|
178
|
+
filter,
|
|
179
|
+
sort,
|
|
180
|
+
readonly,
|
|
181
|
+
onQueryRefOptions,
|
|
182
|
+
lookupComponent,
|
|
183
|
+
Custom,
|
|
184
|
+
}: FormContentProps) => {
|
|
143
185
|
const values = useFormValues(path);
|
|
144
186
|
|
|
145
187
|
const properties = useMemo(() => {
|
|
@@ -159,6 +201,7 @@ export const FormFields = ({ schema, path, filter, sort, readonly, lookupCompone
|
|
|
159
201
|
property={property}
|
|
160
202
|
path={[...(path ?? []), property.name]}
|
|
161
203
|
readonly={readonly}
|
|
204
|
+
onQueryRefOptions={onQueryRefOptions}
|
|
162
205
|
lookupComponent={lookupComponent}
|
|
163
206
|
Custom={Custom}
|
|
164
207
|
/>
|