@dxos/react-ui-form 0.8.1 → 0.8.2-main.2f9c567

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.
Files changed (70) hide show
  1. package/dist/lib/browser/index.mjs +338 -149
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +326 -138
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +338 -149
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/{ControlSection.d.ts → ControlSection/ControlSection.d.ts} +8 -5
  11. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -0
  12. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +8 -0
  13. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -0
  14. package/dist/types/src/components/ControlSection/index.d.ts +2 -0
  15. package/dist/types/src/components/ControlSection/index.d.ts.map +1 -0
  16. package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
  17. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
  18. package/dist/types/src/components/Form/Form.d.ts +6 -3
  19. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  20. package/dist/types/src/components/Form/Form.stories.d.ts +37 -34
  21. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/Form/FormContent.d.ts +14 -11
  23. package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
  24. package/dist/types/src/components/Form/FormContext.d.ts +2 -2
  25. package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
  26. package/dist/types/src/components/Form/RefField.d.ts +24 -0
  27. package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
  28. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
  29. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
  30. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Form/index.d.ts +1 -0
  32. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  33. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  34. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  35. package/dist/types/src/components/deprecated/Form.d.ts +2 -2
  36. package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
  37. package/dist/types/src/components/index.d.ts.map +1 -1
  38. package/dist/types/src/hooks/index.d.ts +1 -0
  39. package/dist/types/src/hooks/index.d.ts.map +1 -1
  40. package/dist/types/src/hooks/useForm.d.ts +2 -2
  41. package/dist/types/src/hooks/useForm.d.ts.map +1 -1
  42. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
  43. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
  44. package/dist/types/src/util/formatting.d.ts.map +1 -1
  45. package/package.json +25 -25
  46. package/src/components/ControlSection/ControlSection.stories.tsx +29 -0
  47. package/src/components/{ControlSection.tsx → ControlSection/ControlSection.tsx} +38 -14
  48. package/src/components/ControlSection/index.ts +5 -0
  49. package/src/components/Form/ArrayField.tsx +8 -7
  50. package/src/components/Form/Defaults.tsx +4 -1
  51. package/src/components/Form/Form.stories.tsx +90 -42
  52. package/src/components/Form/Form.tsx +7 -2
  53. package/src/components/Form/FormContent.tsx +62 -19
  54. package/src/components/Form/FormContext.tsx +10 -2
  55. package/src/components/Form/RefField.tsx +152 -0
  56. package/src/components/Form/custom/GeoPointInput.tsx +2 -2
  57. package/src/components/Form/custom/SelectOptionsInput.stories.tsx +5 -4
  58. package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
  59. package/src/components/Form/index.ts +1 -1
  60. package/src/components/ViewEditor/ViewEditor.stories.tsx +3 -2
  61. package/src/components/ViewEditor/ViewEditor.tsx +12 -10
  62. package/src/components/deprecated/Form.stories.tsx +6 -6
  63. package/src/components/deprecated/Form.tsx +6 -6
  64. package/src/components/deprecated/FormInput.tsx +1 -1
  65. package/src/components/index.ts +1 -0
  66. package/src/hooks/index.ts +1 -0
  67. package/src/hooks/useForm.ts +3 -3
  68. package/src/hooks/useRefQueryLookupHandler.ts +43 -0
  69. package/src/util/formatting.ts +15 -3
  70. package/dist/types/src/components/ControlSection.d.ts.map +0 -1
@@ -1,2 +1,3 @@
1
1
  export * from './useForm';
2
+ export * from './useRefQueryLookupHandler';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -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 as S } from 'effect';
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: S.Schema<T>;
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,EAAoB,KAAK,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAG5D,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAA4C,MA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;;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,4EAOzC,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,cAAe,sBAAsB,KAAG,eA0B5E,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,oCAAiD,gBAAgB,KAAG,MAyEhG,CAAC;AAEF,eAAO,MAAM,gBAAgB,oCAAiD,gBAAgB,KAAG,MA8DhG,CAAC"}
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,oCAAiD,gBAAgB,KAAG,MAqFhG,CAAC;AAEF,eAAO,MAAM,gBAAgB,oCAAiD,gBAAgB,KAAG,MA8DhG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-form",
3
- "version": "0.8.1",
3
+ "version": "0.8.2-main.2f9c567",
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.1",
32
- "@dxos/echo-db": "0.8.1",
33
- "@dxos/debug": "0.8.1",
34
- "@dxos/echo-schema": "0.8.1",
35
- "@dxos/effect": "0.8.1",
36
- "@dxos/invariant": "0.8.1",
37
- "@dxos/live-object": "0.8.1",
38
- "@dxos/log": "0.8.1",
39
- "@dxos/keys": "0.8.1",
40
- "@dxos/react-client": "0.8.1",
41
- "@dxos/react-ui-pickers": "0.8.1",
42
- "@dxos/react-ui-types": "0.8.1",
43
- "@dxos/schema": "0.8.1",
44
- "@dxos/react-ui-list": "0.8.1",
45
- "@dxos/util": "0.8.1"
31
+ "@dxos/debug": "0.8.2-main.2f9c567",
32
+ "@dxos/echo-schema": "0.8.2-main.2f9c567",
33
+ "@dxos/async": "0.8.2-main.2f9c567",
34
+ "@dxos/echo-db": "0.8.2-main.2f9c567",
35
+ "@dxos/effect": "0.8.2-main.2f9c567",
36
+ "@dxos/invariant": "0.8.2-main.2f9c567",
37
+ "@dxos/live-object": "0.8.2-main.2f9c567",
38
+ "@dxos/react-client": "0.8.2-main.2f9c567",
39
+ "@dxos/keys": "0.8.2-main.2f9c567",
40
+ "@dxos/react-ui-list": "0.8.2-main.2f9c567",
41
+ "@dxos/react-ui-pickers": "0.8.2-main.2f9c567",
42
+ "@dxos/log": "0.8.2-main.2f9c567",
43
+ "@dxos/react-ui-types": "0.8.2-main.2f9c567",
44
+ "@dxos/util": "0.8.2-main.2f9c567",
45
+ "@dxos/schema": "0.8.2-main.2f9c567"
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.13.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/random": "0.8.1",
58
- "@dxos/react-ui-syntax-highlighter": "0.8.1",
59
- "@dxos/echo-signals": "0.8.1",
60
- "@dxos/react-ui": "0.8.1",
61
- "@dxos/react-ui-theme": "0.8.1",
62
- "@dxos/storybook-utils": "0.8.1"
57
+ "@dxos/echo-signals": "0.8.2-main.2f9c567",
58
+ "@dxos/random": "0.8.2-main.2f9c567",
59
+ "@dxos/react-ui": "0.8.2-main.2f9c567",
60
+ "@dxos/react-ui-syntax-highlighter": "0.8.2-main.2f9c567",
61
+ "@dxos/storybook-utils": "0.8.2-main.2f9c567",
62
+ "@dxos/react-ui-theme": "0.8.2-main.2f9c567"
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.1",
70
- "@dxos/react-ui-theme": "0.8.1"
69
+ "@dxos/react-ui-theme": "0.8.2-main.2f9c567",
70
+ "@dxos/react-ui": "0.8.2-main.2f9c567"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -0,0 +1,29 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+
9
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
10
+
11
+ import { ControlSection, type ControlSectionProps } from './ControlSection';
12
+ import translations from '../../translations';
13
+
14
+ const meta: Meta<ControlSectionProps> = {
15
+ title: 'ui/react-ui-form/ControlSection',
16
+ component: ControlSection,
17
+ decorators: [withLayout({ tooltips: true }), withTheme],
18
+ parameters: {
19
+ translations,
20
+ },
21
+ };
22
+
23
+ export default meta;
24
+
25
+ type Story = StoryObj<ControlSectionProps>;
26
+
27
+ export const Default: Story = {
28
+ args: {},
29
+ };
@@ -2,19 +2,45 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { type PropsWithChildren } from 'react';
5
+ import React, { type ComponentPropsWithoutRef, type PropsWithChildren } from 'react';
6
6
 
7
- import { type Label, toLocalizedString, useTranslation, Input } from '@dxos/react-ui';
7
+ import {
8
+ Button,
9
+ type ButtonProps,
10
+ type Label,
11
+ Input,
12
+ type ThemedClassName,
13
+ toLocalizedString,
14
+ useTranslation,
15
+ } from '@dxos/react-ui';
16
+ import { mx } from '@dxos/react-ui-theme';
8
17
 
9
- import { translationKey } from '../translations';
18
+ import { translationKey } from '../../translations';
10
19
 
11
- // TODO(wittjosiah): Copied from @dxos/plugin-client. Reconcile/factor out.
20
+ export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
21
+
22
+ export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
23
+ return (
24
+ <div role='none' className={mx('pli-2', classNames)} {...props}>
25
+ {children}
26
+ </div>
27
+ );
28
+ };
12
29
 
13
30
  export type ControlSectionProps = PropsWithChildren<{
14
31
  title: Label;
15
32
  description?: Label;
16
33
  }>;
17
34
 
35
+ export const ControlSection = ({ title, description, children }: ControlSectionProps) => {
36
+ return (
37
+ <>
38
+ <ControlSectionHeading title={title} description={description} />
39
+ {children}
40
+ </>
41
+ );
42
+ };
43
+
18
44
  export const ControlSectionHeading = ({ title, description }: Omit<ControlSectionProps, 'children'>) => {
19
45
  const { t } = useTranslation(translationKey);
20
46
  return (
@@ -27,19 +53,17 @@ export const ControlSectionHeading = ({ title, description }: Omit<ControlSectio
27
53
  );
28
54
  };
29
55
 
30
- export const ControlSection = ({ title, description, children }: ControlSectionProps) => {
31
- return (
32
- <>
33
- <ControlSectionHeading title={title} description={description} />
34
- {children}
35
- </>
36
- );
56
+ export const ControlGroupButton = ({ classNames, ...props }: ButtonProps) => {
57
+ return <Button {...props} classNames={['md:col-span-2', classNames]} />;
37
58
  };
38
59
 
39
- export type ControlGroupProps = PropsWithChildren<{}>;
60
+ export type ControlGroupProps = ThemedClassName<PropsWithChildren<{}>>;
40
61
 
41
- export const ControlGroup = ({ children }: ControlGroupProps) => (
42
- <div role='none' className='group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4'>
62
+ export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
63
+ <div
64
+ role='none'
65
+ className={mx('group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4', classNames)}
66
+ >
43
67
  {children}
44
68
  </div>
45
69
  );
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './ControlSection';
@@ -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';
@@ -33,16 +32,18 @@ type ArrayFieldProps = {
33
32
  export const ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }: ArrayFieldProps) => {
34
33
  const { t } = useTranslation(translationKey);
35
34
  const { ast, name, type, title } = property;
36
- const values = useFormValues(path ?? []) as any[];
35
+ // TODO(wittjosiah): The fallback to an empty array stops the form from crashing but isn't immediately live.
36
+ // It doesn't become live until another field is touched, but that's better than the whole form crashing.
37
+ const values = (useFormValues(path ?? []) ?? []) as any[];
37
38
  invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
38
39
  const label = title ?? pipe(name, capitalize);
39
40
 
40
- const tupleType = findNode(ast, AST.isTupleType);
41
- const elementType = (tupleType as AST.TupleType | undefined)?.rest[0]?.type;
41
+ const tupleType = findNode(ast, SchemaAST.isTupleType);
42
+ const elementType = (tupleType as SchemaAST.TupleType | undefined)?.rest[0]?.type;
42
43
 
43
- const getDefaultObjectValue = (typeNode: AST.AST): any => {
44
+ const getDefaultObjectValue = (typeNode: SchemaAST.AST): any => {
44
45
  const baseNode = findNode(typeNode, isDiscriminatedUnion);
45
- const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, AST.isTypeLiteral);
46
+ const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST.isTypeLiteral);
46
47
  if (!typeLiteral) {
47
48
  return {};
48
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={getValue()} onValueChange={(value) => onValueChange(type, 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 { AST, type BaseObject, Format, S } from '@dxos/echo-schema';
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 = S.Struct({
20
- street: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Street' })),
21
- city: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'City' })),
22
- zip: S.optional(S.String.pipe(S.pattern(/^\d{5}(-\d{4})?$/)).annotations({ [AST.TitleAnnotationId]: 'ZIP' })),
23
- location: S.optional(Format.GeoPoint.annotations({ [AST.TitleAnnotationId]: 'Location' })),
24
- }).annotations({ [AST.TitleAnnotationId]: 'Address' });
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 = S.Struct({
28
- name: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Name' })),
29
- active: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Active' })),
30
- rank: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Rank' })),
31
- website: S.optional(Format.URL.annotations({ [AST.TitleAnnotationId]: 'Website' })),
32
- address: S.optional(AddressSchema),
33
- }).pipe(S.mutable);
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 = S.Schema.Type<typeof TestSchema>;
40
+ type TestType = Schema.Schema.Type<typeof TestSchema>;
36
41
 
37
- type StoryProps<T extends BaseObject> = { schema: S.Schema<T> } & FormProps<T>;
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);
@@ -78,9 +83,9 @@ export const Default: Story<TestType> = {
78
83
  },
79
84
  };
80
85
 
81
- export const Org: Story<Testing.Org> = {
86
+ export const Organization: Story<Testing.Organization> = {
82
87
  args: {
83
- schema: Testing.OrgSchema,
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 OrgAutoSave: Story<Testing.Org> = {
96
+ export const OrganizationAutoSave: Story<Testing.Organization> = {
92
97
  args: {
93
- schema: Testing.OrgSchema,
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 = S.Struct({
119
- shape: S.optional(
120
- S.Union(
121
- S.Struct({
122
- type: S.Literal('circle').annotations({ [AST.TitleAnnotationId]: 'Type' }),
123
- radius: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: '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
- S.Struct({
126
- type: S.Literal('square').annotations({ [AST.TitleAnnotationId]: 'Type' }),
127
- size: S.optional(S.Number.pipe(S.nonNegative()).annotations({ [AST.TitleAnnotationId]: '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({ [AST.TitleAnnotationId]: 'Shape' }),
136
+ ).annotations({ [SchemaAST.TitleAnnotationId]: 'Shape' }),
130
137
  ),
131
- }).pipe(S.mutable);
138
+ }).pipe(Schema.mutable);
132
139
 
133
- type ShapeType = S.Schema.Type<typeof ShapeSchema>;
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 = S.Struct({
180
- names: S.Array(S.String.pipe(S.nonEmptyString())),
181
- addresses: S.Array(AddressSchema),
182
- }).pipe(S.mutable);
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 = S.Schema.Type<typeof ArraysSchema>;
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 = S.Struct({
212
- color: S.Union(S.Literal('red'), S.Literal('green'), S.Literal('blue')).annotations({
213
- [AST.TitleAnnotationId]: 'Color',
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(S.mutable);
222
+ }).pipe(Schema.mutable);
216
223
 
217
- type ColorType = S.Schema.Type<typeof ColorSchema>;
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 S, type PropertyKey } from '@dxos/echo-schema';
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: S.Schema<any>;
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
  />