@dxos/react-ui-form 0.8.4-main.b97322e → 0.8.4-main.c4373fc

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 (117) hide show
  1. package/dist/lib/browser/index.mjs +810 -594
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +810 -594
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/ControlSection/ControlSection.d.ts +2 -2
  8. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
  9. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +81 -5
  10. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
  12. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  13. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +76 -5
  14. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/Form/ArrayField.d.ts +2 -2
  16. package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
  17. package/dist/types/src/components/Form/Defaults.d.ts +5 -5
  18. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
  19. package/dist/types/src/components/Form/Form.d.ts +7 -6
  20. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  21. package/dist/types/src/components/Form/Form.stories.d.ts +129 -32
  22. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  23. package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
  24. package/dist/types/src/components/Form/FormContent.d.ts +17 -11
  25. package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
  26. package/dist/types/src/components/Form/FormContext.d.ts +3 -3
  27. package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
  28. package/dist/types/src/components/Form/Input.d.ts +5 -2
  29. package/dist/types/src/components/Form/Input.d.ts.map +1 -1
  30. package/dist/types/src/components/Form/RefField.d.ts +14 -5
  31. package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
  32. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +1 -1
  33. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
  34. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +1 -1
  35. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
  36. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +76 -4
  37. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
  38. package/dist/types/src/components/Form/custom/TupleInput.d.ts +1 -1
  39. package/dist/types/src/components/Form/factory.d.ts +1 -1
  40. package/dist/types/src/components/Form/factory.d.ts.map +1 -1
  41. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +41 -0
  42. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
  43. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +81 -0
  44. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
  45. package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
  46. package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
  47. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +16 -4
  48. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  49. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +79 -7
  50. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  51. package/dist/types/src/components/index.d.ts +1 -1
  52. package/dist/types/src/components/index.d.ts.map +1 -1
  53. package/dist/types/src/components/testing.d.ts +6 -3
  54. package/dist/types/src/components/testing.d.ts.map +1 -1
  55. package/dist/types/src/hooks/useForm.d.ts +3 -3
  56. package/dist/types/src/hooks/useForm.d.ts.map +1 -1
  57. package/dist/types/src/hooks/useQueryRefOptions.d.ts +8 -3
  58. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -1
  59. package/dist/types/src/translations.d.ts +11 -5
  60. package/dist/types/src/translations.d.ts.map +1 -1
  61. package/dist/types/src/util/field.d.ts +1 -1
  62. package/dist/types/src/util/field.d.ts.map +1 -1
  63. package/dist/types/src/util/formatting.d.ts +1 -1
  64. package/dist/types/src/util/formatting.d.ts.map +1 -1
  65. package/dist/types/src/util/refs.d.ts +1 -1
  66. package/dist/types/src/util/refs.d.ts.map +1 -1
  67. package/dist/types/src/util/schema.d.ts +1 -1
  68. package/dist/types/src/util/schema.d.ts.map +1 -1
  69. package/dist/types/tsconfig.tsbuildinfo +1 -1
  70. package/package.json +41 -36
  71. package/src/components/ControlSection/ControlSection.stories.tsx +11 -14
  72. package/src/components/ControlSection/ControlSection.tsx +26 -12
  73. package/src/components/FieldEditor/FieldEditor.stories.tsx +14 -14
  74. package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
  75. package/src/components/FieldEditor/FieldEditor.tsx +26 -18
  76. package/src/components/Form/ArrayField.tsx +12 -11
  77. package/src/components/Form/Defaults.tsx +22 -20
  78. package/src/components/Form/Form.stories.tsx +135 -99
  79. package/src/components/Form/Form.tsx +26 -15
  80. package/src/components/Form/FormActions.tsx +2 -1
  81. package/src/components/Form/FormContent.tsx +121 -39
  82. package/src/components/Form/FormContext.tsx +8 -8
  83. package/src/components/Form/Input.tsx +5 -2
  84. package/src/components/Form/RefField.tsx +97 -41
  85. package/src/components/Form/custom/GeoPointInput.tsx +29 -21
  86. package/src/components/Form/custom/SelectOptionsInput.stories.tsx +11 -11
  87. package/src/components/Form/custom/SelectOptionsInput.tsx +30 -31
  88. package/src/components/Form/custom/TupleInput.tsx +2 -2
  89. package/src/components/Form/factory.tsx +2 -2
  90. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +207 -0
  91. package/src/components/ObjectPicker/ObjectPicker.tsx +161 -0
  92. package/src/components/ObjectPicker/index.ts +5 -0
  93. package/src/components/ViewEditor/ViewEditor.stories.tsx +102 -44
  94. package/src/components/ViewEditor/ViewEditor.test.tsx +9 -12
  95. package/src/components/ViewEditor/ViewEditor.tsx +328 -220
  96. package/src/components/index.ts +1 -2
  97. package/src/components/testing.tsx +15 -9
  98. package/src/hooks/useForm.ts +8 -4
  99. package/src/hooks/useQueryRefOptions.ts +9 -3
  100. package/src/hooks/useRefQueryLookupHandler.ts +1 -1
  101. package/src/translations.ts +13 -6
  102. package/src/util/field.ts +9 -19
  103. package/src/util/formatting.ts +1 -1
  104. package/src/util/refs.ts +2 -2
  105. package/src/util/schema.ts +2 -4
  106. package/dist/types/src/components/deprecated/Form.d.ts +0 -15
  107. package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
  108. package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
  109. package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
  110. package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
  111. package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
  112. package/dist/types/src/components/deprecated/index.d.ts +0 -2
  113. package/dist/types/src/components/deprecated/index.d.ts.map +0 -1
  114. package/src/components/deprecated/Form.stories.tsx +0 -62
  115. package/src/components/deprecated/Form.tsx +0 -119
  116. package/src/components/deprecated/FormInput.tsx +0 -71
  117. package/src/components/deprecated/index.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-form",
3
- "version": "0.8.4-main.b97322e",
3
+ "version": "0.8.4-main.c4373fc",
4
4
  "description": "Data components.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -9,6 +9,7 @@
9
9
  "type": "module",
10
10
  "exports": {
11
11
  ".": {
12
+ "source": "./src/index.ts",
12
13
  "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": "./dist/lib/node-esm/index.mjs"
@@ -25,52 +26,56 @@
25
26
  "dependencies": {
26
27
  "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
27
28
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
29
+ "@fluentui/react-tabster": "^9.24.2",
28
30
  "@preact-signals/safe-react": "^0.9.0",
31
+ "@preact/signals-react": "^3.2.0",
29
32
  "@radix-ui/react-context": "1.1.1",
30
33
  "date-fns": "^3.3.1",
31
34
  "jsonpath": "^1.1.1",
32
- "@dxos/async": "0.8.4-main.b97322e",
33
- "@dxos/debug": "0.8.4-main.b97322e",
34
- "@dxos/echo-schema": "0.8.4-main.b97322e",
35
- "@dxos/echo": "0.8.4-main.b97322e",
36
- "@dxos/echo-db": "0.8.4-main.b97322e",
37
- "@dxos/effect": "0.8.4-main.b97322e",
38
- "@dxos/invariant": "0.8.4-main.b97322e",
39
- "@dxos/keys": "0.8.4-main.b97322e",
40
- "@dxos/lit-ui": "0.8.4-main.b97322e",
41
- "@dxos/log": "0.8.4-main.b97322e",
42
- "@dxos/react-client": "0.8.4-main.b97322e",
43
- "@dxos/live-object": "0.8.4-main.b97322e",
44
- "@dxos/react-ui-list": "0.8.4-main.b97322e",
45
- "@dxos/react-ui-stack": "0.8.4-main.b97322e",
46
- "@dxos/react-ui-pickers": "0.8.4-main.b97322e",
47
- "@dxos/react-ui-types": "0.8.4-main.b97322e",
48
- "@dxos/react-ui-tag-picker": "0.8.4-main.b97322e",
49
- "@dxos/schema": "0.8.4-main.b97322e",
50
- "@dxos/util": "0.8.4-main.b97322e"
35
+ "@dxos/async": "0.8.4-main.c4373fc",
36
+ "@dxos/debug": "0.8.4-main.c4373fc",
37
+ "@dxos/echo": "0.8.4-main.c4373fc",
38
+ "@dxos/echo-db": "0.8.4-main.c4373fc",
39
+ "@dxos/echo-query": "0.8.4-main.c4373fc",
40
+ "@dxos/effect": "0.8.4-main.c4373fc",
41
+ "@dxos/invariant": "0.8.4-main.c4373fc",
42
+ "@dxos/keys": "0.8.4-main.c4373fc",
43
+ "@dxos/lit-ui": "0.8.4-main.c4373fc",
44
+ "@dxos/live-object": "0.8.4-main.c4373fc",
45
+ "@dxos/log": "0.8.4-main.c4373fc",
46
+ "@dxos/react-ui-editor": "0.8.4-main.c4373fc",
47
+ "@dxos/react-ui-components": "0.8.4-main.c4373fc",
48
+ "@dxos/react-ui-list": "0.8.4-main.c4373fc",
49
+ "@dxos/react-ui-pickers": "0.8.4-main.c4373fc",
50
+ "@dxos/react-client": "0.8.4-main.c4373fc",
51
+ "@dxos/react-ui-stack": "0.8.4-main.c4373fc",
52
+ "@dxos/react-ui-searchlist": "0.8.4-main.c4373fc",
53
+ "@dxos/schema": "0.8.4-main.c4373fc",
54
+ "@dxos/react-ui-types": "0.8.4-main.c4373fc",
55
+ "@dxos/util": "0.8.4-main.c4373fc"
51
56
  },
52
57
  "devDependencies": {
53
58
  "@types/jsonpath": "^0.2.4",
54
- "@types/react": "~18.2.0",
55
- "@types/react-dom": "~18.2.0",
56
- "effect": "3.17.0",
59
+ "@types/react": "~19.2.2",
60
+ "@types/react-dom": "~19.2.1",
61
+ "effect": "3.18.3",
57
62
  "fast-check": "^3.19.0",
58
- "react": "~18.2.0",
59
- "react-dom": "~18.2.0",
60
- "vite": "5.4.7",
61
- "@dxos/echo-signals": "0.8.4-main.b97322e",
62
- "@dxos/random": "0.8.4-main.b97322e",
63
- "@dxos/react-ui": "0.8.4-main.b97322e",
64
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.b97322e",
65
- "@dxos/storybook-utils": "0.8.4-main.b97322e",
66
- "@dxos/react-ui-theme": "0.8.4-main.b97322e"
63
+ "react": "~19.2.0",
64
+ "react-dom": "~19.2.0",
65
+ "vite": "7.1.9",
66
+ "@dxos/random": "0.8.4-main.c4373fc",
67
+ "@dxos/react-ui": "0.8.4-main.c4373fc",
68
+ "@dxos/echo-signals": "0.8.4-main.c4373fc",
69
+ "@dxos/storybook-utils": "0.8.4-main.c4373fc",
70
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.c4373fc",
71
+ "@dxos/react-ui-theme": "0.8.4-main.c4373fc"
67
72
  },
68
73
  "peerDependencies": {
69
74
  "effect": "^3.13.3",
70
- "react": "~18.2.0",
71
- "react-dom": "~18.2.0",
72
- "@dxos/react-ui": "0.8.4-main.b97322e",
73
- "@dxos/react-ui-theme": "0.8.4-main.b97322e"
75
+ "react": "^19.0.0",
76
+ "react-dom": "^19.0.0",
77
+ "@dxos/react-ui": "0.8.4-main.c4373fc",
78
+ "@dxos/react-ui-theme": "0.8.4-main.c4373fc"
74
79
  },
75
80
  "publishConfig": {
76
81
  "access": "public"
@@ -2,36 +2,33 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React from 'react';
9
7
 
10
- import { StackItem } from '@dxos/react-ui-stack';
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
8
+ import { withTheme } from '@dxos/react-ui/testing';
12
9
 
13
- import { ControlPage, ControlSection, type ControlSectionProps } from './ControlSection';
14
10
  import { translations } from '../../translations';
15
11
 
16
- const meta: Meta<ControlSectionProps> = {
12
+ import { ControlPage, ControlSection } from './ControlSection';
13
+
14
+ const meta = {
17
15
  title: 'ui/react-ui-form/ControlSection',
18
16
  component: ControlSection,
19
17
  render: (args) => (
20
- <StackItem.Content classNames='w-[40rem]'>
21
- <ControlPage>
22
- <ControlSection {...args} />
23
- </ControlPage>
24
- </StackItem.Content>
18
+ <ControlPage classNames='w-[40rem]'>
19
+ <ControlSection {...args} />
20
+ </ControlPage>
25
21
  ),
26
- decorators: [withLayout({ fullscreen: true, classNames: 'justify-center' }), withTheme],
22
+ decorators: [withTheme],
27
23
  parameters: {
24
+ layout: 'centered',
28
25
  translations,
29
26
  },
30
- };
27
+ } satisfies Meta<typeof ControlSection>;
31
28
 
32
29
  export default meta;
33
30
 
34
- type Story = StoryObj<ControlSectionProps>;
31
+ type Story = StoryObj<typeof meta>;
35
32
 
36
33
  export const Default: Story = {
37
34
  args: {
@@ -13,6 +13,7 @@ import {
13
13
  toLocalizedString,
14
14
  useTranslation,
15
15
  } from '@dxos/react-ui';
16
+ import { StackItem } from '@dxos/react-ui-stack';
16
17
  import { mx } from '@dxos/react-ui-theme';
17
18
 
18
19
  import { translationKey } from '../../translations';
@@ -21,9 +22,11 @@ export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
21
22
 
22
23
  export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
23
24
  return (
24
- <div role='none' className={mx('pli-cardSpacingInline', classNames)} {...props}>
25
- {children}
26
- </div>
25
+ <StackItem.Content scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
26
+ <div role='none' className={mx('pli-cardSpacingInline pbe-trimLg', classNames)} {...props}>
27
+ {children}
28
+ </div>
29
+ </StackItem.Content>
27
30
  );
28
31
  };
29
32
 
@@ -59,12 +62,16 @@ export const ControlGroupButton = ({ classNames, ...props }: ButtonProps) => {
59
62
  return <Button {...props} classNames={['md:col-span-2', classNames]} />;
60
63
  };
61
64
 
62
- export type ControlGroupProps = ThemedClassName<PropsWithChildren<{}>>;
65
+ export type ControlGroupProps = ThemedClassName<PropsWithChildren>;
63
66
 
64
67
  export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
65
68
  <div
66
69
  role='none'
67
- className={mx('group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd', classNames)}
70
+ className={mx(
71
+ 'group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd',
72
+ '[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end',
73
+ classNames,
74
+ )}
68
75
  >
69
76
  {children}
70
77
  </div>
@@ -73,23 +80,30 @@ export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
73
80
  export const ControlFrame = ({ children }: ControlGroupProps) => (
74
81
  <div
75
82
  role='none'
76
- className='p-trimMd container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd border border-separator rounded-md'
83
+ className={mx(
84
+ 'container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd',
85
+ 'border border-separator rounded-md',
86
+ )}
77
87
  >
78
88
  {children}
79
89
  </div>
80
90
  );
81
91
 
92
+ export const controlItemClasses = mx([
93
+ 'container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center',
94
+ // TODO(burdon): Use grid gap consistently or apply margins consistently?
95
+ 'mlb-[--control-spacing] *:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd',
96
+ 'border border-separator rounded-md',
97
+ ]);
98
+
99
+ const controlItemTitleClasses = 'mbe-0 text-lg text-baseText font-normal';
100
+ const controlItemDescriptionClasses = 'mlb-trimSm md:mbe-0 text-base text-description';
101
+
82
102
  export type ControlItemProps = PropsWithChildren<{
83
103
  title: Label;
84
104
  description?: Label;
85
105
  }>;
86
106
 
87
- export const controlItemClasses =
88
- 'pli-trimMd plb-trimMd container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-trimSm border border-separator rounded-md *:first:!mbs-0 *:last:!mbe-0';
89
-
90
- const controlItemTitleClasses = 'text-lg font-normal';
91
- const controlItemDescriptionClasses = 'text-base mlb-trimSm md:mbe-0 text-description';
92
-
93
107
  export const ControlItem = ({ title, description, children }: ControlItemProps) => {
94
108
  const { t } = useTranslation(translationKey);
95
109
 
@@ -2,20 +2,19 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
- import React, { useMemo, useEffect } from 'react';
6
+ import React, { useEffect, useMemo } from 'react';
9
7
 
10
- import { createEchoSchema } from '@dxos/live-object/testing';
8
+ import { createEchoSchema } from '@dxos/echo/testing';
11
9
  import { log } from '@dxos/log';
10
+ import { withTheme } from '@dxos/react-ui/testing';
12
11
  import { ProjectionModel } from '@dxos/schema';
13
12
  import { TestSchema, testView } from '@dxos/schema/testing';
14
- import { withLayout, withTheme } from '@dxos/storybook-utils';
15
13
 
16
- import { FieldEditor, type FieldEditorProps } from './FieldEditor';
17
14
  import { translations } from '../../translations';
18
- import { TestLayout, TestPanel, FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
15
+ import { FIELD_EDITOR_DEBUG_SYMBOL, TestLayout, TestPanel } from '../testing';
16
+
17
+ import { FieldEditor, type FieldEditorProps } from './FieldEditor';
19
18
 
20
19
  // Type definition for debug objects exposed to tests.
21
20
  export type FieldEditorDebugObjects = {
@@ -23,8 +22,6 @@ export type FieldEditorDebugObjects = {
23
22
  projection: ProjectionModel;
24
23
  };
25
24
 
26
- type StoryProps = FieldEditorProps;
27
-
28
25
  const DefaultStory = (props: FieldEditorProps) => {
29
26
  const handleComplete: FieldEditorProps['onSave'] = () => {
30
27
  log.info('onClose', { props });
@@ -32,6 +29,8 @@ const DefaultStory = (props: FieldEditorProps) => {
32
29
 
33
30
  // Expose objects on window for test access.
34
31
  useEffect(() => {
32
+ props.projection.normalizeView();
33
+
35
34
  if (typeof window !== 'undefined') {
36
35
  (window as any)[FIELD_EDITOR_DEBUG_SYMBOL] = {
37
36
  props,
@@ -55,19 +54,20 @@ const DefaultStory = (props: FieldEditorProps) => {
55
54
  );
56
55
  };
57
56
 
58
- const meta: Meta<StoryProps> = {
57
+ const meta = {
59
58
  title: 'ui/react-ui-form/FieldEditor',
60
- component: FieldEditor,
59
+ component: FieldEditor as any,
61
60
  render: DefaultStory,
62
- decorators: [withLayout({ fullscreen: true }), withTheme],
61
+ decorators: [withTheme],
63
62
  parameters: {
63
+ layout: 'fullscreen',
64
64
  translations,
65
65
  },
66
- };
66
+ } satisfies Meta<typeof DefaultStory>;
67
67
 
68
68
  export default meta;
69
69
 
70
- type Story = StoryObj<StoryProps>;
70
+ type Story = StoryObj<typeof meta>;
71
71
 
72
72
  export const Default: Story = {
73
73
  args: {
@@ -3,14 +3,15 @@
3
3
  //
4
4
 
5
5
  import { composeStories } from '@storybook/react';
6
- import { screen, cleanup, fireEvent, act } from '@testing-library/react';
6
+ import { act, cleanup, fireEvent, screen } from '@testing-library/react';
7
7
  import { afterEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { ProjectionModel } from '@dxos/schema';
10
10
 
11
+ import { FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
12
+
11
13
  import * as stories from './FieldEditor.stories';
12
14
  import { type FieldEditorDebugObjects } from './FieldEditor.stories';
13
- import { FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
14
15
 
15
16
  const { Default } = composeStories(stories);
16
17
 
@@ -4,18 +4,19 @@
4
4
 
5
5
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
6
6
 
7
+ import { type EchoSchema, FormatEnum, FormatEnums, formatToType } from '@dxos/echo/internal';
7
8
  import { type SchemaRegistry } from '@dxos/echo-db';
8
- import { FormatEnum, FormatEnums, formatToType, type EchoSchema } from '@dxos/echo-schema';
9
9
  import { log } from '@dxos/log';
10
- import { useTranslation } from '@dxos/react-ui';
10
+ import { useAsyncEffect, useTranslation } from '@dxos/react-ui';
11
11
  import {
12
- getFormatSchema,
13
- getSchemaProperties,
14
- sortProperties,
15
12
  type FieldType,
16
- type PropertyType,
17
13
  type ProjectionModel,
14
+ type PropertyType,
18
15
  type SchemaProperty,
16
+ formatToAdditionalPropertyAttributes,
17
+ getFormatSchema,
18
+ getSchemaProperties,
19
+ sortProperties,
19
20
  } from '@dxos/schema';
20
21
 
21
22
  import { translationKey } from '../../translations';
@@ -27,18 +28,26 @@ export type FieldEditorProps = {
27
28
  registry?: SchemaRegistry;
28
29
  onSave: () => void;
29
30
  onCancel?: () => void;
30
- } & Pick<FormProps<any>, 'outerSpacing'>;
31
+ } & Pick<FormProps<any>, 'outerSpacing' | 'readonly'>;
31
32
 
32
33
  /**
33
34
  * Displays a Form representing the metadata for a given `Field` and `View`.
34
35
  */
35
- export const FieldEditor = ({ projection, field, registry, onSave, onCancel, outerSpacing }: FieldEditorProps) => {
36
+ export const FieldEditor = ({
37
+ readonly,
38
+ projection,
39
+ field,
40
+ registry,
41
+ onSave,
42
+ onCancel,
43
+ outerSpacing,
44
+ }: FieldEditorProps) => {
36
45
  const { t } = useTranslation(translationKey);
37
46
  const [props, setProps] = useState<PropertyType>(projection.getFieldProjection(field.id).props);
38
47
  useEffect(() => setProps(projection.getFieldProjection(field.id).props), [field, projection]);
39
48
 
40
49
  const [schemas, setSchemas] = useState<EchoSchema[]>([]);
41
- useEffect(() => {
50
+ useAsyncEffect(async () => {
42
51
  if (!registry) {
43
52
  return;
44
53
  }
@@ -46,14 +55,10 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
46
55
  const subscription = registry.query().subscribe((query) => setSchemas(query.results), { fire: true });
47
56
 
48
57
  // TODO(dmaretskyi): This shouldn't be needed.
49
- const t = setTimeout(async () => {
50
- const schemas = await registry.query().run();
51
- setSchemas(schemas);
52
- });
53
- return () => {
54
- clearTimeout(t);
55
- subscription?.();
56
- };
58
+ const schemas = await registry.query().run();
59
+ setSchemas(schemas);
60
+
61
+ return () => subscription?.();
57
62
  }, [registry]);
58
63
 
59
64
  const [referenceSchema, setReferenceSchema] = useState<EchoSchema>();
@@ -90,8 +95,10 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
90
95
 
91
96
  setProps((props) => {
92
97
  const type = formatToType[_props.format as keyof typeof formatToType];
98
+ const additionalProps =
99
+ formatToAdditionalPropertyAttributes[_props.format as keyof typeof formatToAdditionalPropertyAttributes];
93
100
  if (props.type !== type) {
94
- return { ...props, ..._props, type };
101
+ return { ...props, ..._props, ...additionalProps, type } as PropertyType;
95
102
  }
96
103
 
97
104
  return _props as PropertyType;
@@ -178,6 +185,7 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
178
185
  <Form<PropertyType>
179
186
  key={field.id}
180
187
  autoFocus
188
+ readonly={readonly}
181
189
  values={props}
182
190
  schema={fieldSchema}
183
191
  filter={propIsNotType}
@@ -2,30 +2,31 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { SchemaAST, pipe } from 'effect';
6
- import { capitalize } from 'effect/String';
5
+ import * as Function from 'effect/Function';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+ import * as String from 'effect/String';
7
8
  import React, { Fragment, useCallback } from 'react';
8
9
 
9
- import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from '@dxos/effect';
10
+ import { SimpleType, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
10
11
  import { invariant } from '@dxos/invariant';
11
12
  import { IconButton, useTranslation } from '@dxos/react-ui';
12
- import { getSchemaProperties, type SchemaProperty } from '@dxos/schema';
13
+ import { type SchemaProperty, getSchemaProperties } from '@dxos/schema';
13
14
 
14
- import { type ComponentLookup } from './Form';
15
- import { FormField } from './FormContent';
16
- import { useFormValues, type FormInputStateProps } from './FormContext';
17
- import { InputHeader, type InputComponent } from './Input';
18
15
  import { translationKey } from '../../translations';
19
16
  import { findArrayElementType } from '../../util';
20
17
 
18
+ import { type ComponentLookup } from './Form';
19
+ import { FormField, type FormFieldProps } from './FormContent';
20
+ import { type FormInputStateProps, useFormValues } from './FormContext';
21
+ import { type InputComponent, InputHeader } from './Input';
22
+
21
23
  type ArrayFieldProps = {
22
24
  property: SchemaProperty<any>;
23
- readonly?: boolean;
24
25
  inputProps: FormInputStateProps;
25
26
  path?: (string | number)[];
26
27
  Custom?: Partial<Record<string, InputComponent>>;
27
28
  lookupComponent?: ComponentLookup;
28
- };
29
+ } & Pick<FormFieldProps, 'readonly'>;
29
30
 
30
31
  export const ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }: ArrayFieldProps) => {
31
32
  const { t } = useTranslation(translationKey);
@@ -34,7 +35,7 @@ export const ArrayField = ({ property, readonly, path, inputProps, Custom, looku
34
35
  // It doesn't become live until another field is touched, but that's better than the whole form crashing.
35
36
  const values = (useFormValues(path ?? []) ?? []) as any[];
36
37
  invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
37
- const label = title ?? pipe(name, capitalize);
38
+ const label = title ?? Function.pipe(name, String.capitalize);
38
39
 
39
40
  const elementType = findArrayElementType(ast);
40
41
 
@@ -6,14 +6,15 @@ import React, { useCallback, useEffect, useRef } from 'react';
6
6
 
7
7
  import { Input, Select, useTranslation } from '@dxos/react-ui';
8
8
 
9
- import { type InputProps, InputHeader } from './Input';
10
9
  import { translationKey } from '../../translations';
11
10
 
11
+ import { InputHeader, type InputProps } from './Input';
12
+
12
13
  export const TextInput = ({
13
14
  type,
14
15
  label,
15
16
  inputOnly,
16
- disabled,
17
+ readonly,
17
18
  placeholder,
18
19
  getStatus,
19
20
  getValue,
@@ -22,16 +23,16 @@ export const TextInput = ({
22
23
  }: InputProps) => {
23
24
  const { status, error } = getStatus();
24
25
 
25
- return disabled && !getValue() ? null : disabled && inputOnly ? (
26
+ return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
26
27
  <p>{getValue() ?? ''}</p>
27
28
  ) : (
28
29
  <Input.Root validationValence={status}>
29
30
  {!inputOnly && <InputHeader error={error} label={label} />}
30
- {disabled ? (
31
+ {readonly === 'static' ? (
31
32
  <p>{getValue() ?? ''}</p>
32
33
  ) : (
33
34
  <Input.TextInput
34
- disabled={disabled}
35
+ disabled={!!readonly}
35
36
  placeholder={placeholder}
36
37
  value={getValue() ?? ''}
37
38
  onChange={(event) => onValueChange(type, event.target.value)}
@@ -47,7 +48,7 @@ export const NumberInput = ({
47
48
  type,
48
49
  label,
49
50
  inputOnly,
50
- disabled,
51
+ readonly,
51
52
  placeholder,
52
53
  getStatus,
53
54
  getValue,
@@ -56,19 +57,19 @@ export const NumberInput = ({
56
57
  }: InputProps) => {
57
58
  const { status, error } = getStatus();
58
59
 
59
- return disabled && !getValue() ? null : disabled && inputOnly ? (
60
+ return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
60
61
  <p>{getValue() ?? ''}</p>
61
62
  ) : (
62
63
  <Input.Root validationValence={status}>
63
64
  {!inputOnly && <InputHeader error={error} label={label} />}
64
- {disabled ? (
65
+ {readonly === 'static' ? (
65
66
  <p>{getValue() ?? ''}</p>
66
67
  ) : (
67
68
  <Input.TextInput
68
69
  type='number'
69
- disabled={disabled}
70
+ disabled={!!readonly}
70
71
  placeholder={placeholder}
71
- value={getValue() ?? 0}
72
+ value={getValue()}
72
73
  onChange={(event) => onValueChange(type, event.target.value)}
73
74
  onBlur={onBlur}
74
75
  />
@@ -78,7 +79,7 @@ export const NumberInput = ({
78
79
  );
79
80
  };
80
81
 
81
- export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onValueChange, disabled }: InputProps) => {
82
+ export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onValueChange, readonly }: InputProps) => {
82
83
  const { status, error } = getStatus();
83
84
  const checked = Boolean(getValue());
84
85
  const { t } = useTranslation(translationKey);
@@ -86,10 +87,10 @@ export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onVa
86
87
  return (
87
88
  <Input.Root validationValence={status}>
88
89
  {!inputOnly && <InputHeader error={error} label={label} />}
89
- {disabled ? (
90
+ {readonly === 'static' ? (
90
91
  <p>{t(checked ? 'boolean input true value' : 'boolean input false value')}</p>
91
92
  ) : (
92
- <Input.Switch checked={checked} onCheckedChange={(value) => onValueChange(type, value)} />
93
+ <Input.Switch disabled={!!readonly} checked={checked} onCheckedChange={(value) => onValueChange(type, value)} />
93
94
  )}
94
95
  {inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
95
96
  </Input.Root>
@@ -104,7 +105,7 @@ export const SelectInput = ({
104
105
  type,
105
106
  label,
106
107
  inputOnly,
107
- disabled,
108
+ readonly,
108
109
  placeholder,
109
110
  options,
110
111
  getStatus,
@@ -116,15 +117,15 @@ export const SelectInput = ({
116
117
  const value = getValue() as string | undefined;
117
118
  const handleValueChange = useCallback((value: string | number) => onValueChange(type, value), [type, onValueChange]);
118
119
 
119
- return disabled && !value ? null : (
120
+ return readonly && !value ? null : (
120
121
  <Input.Root validationValence={status}>
121
122
  {!inputOnly && <InputHeader error={error} label={label} />}
122
- {disabled ? (
123
+ {readonly === 'static' ? (
123
124
  <p>{options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)}</p>
124
125
  ) : (
125
126
  <Select.Root value={value} onValueChange={handleValueChange}>
126
127
  {/* TODO(burdon): Placeholder not working? */}
127
- <Select.TriggerButton classNames='is-full' disabled={disabled} placeholder={placeholder} />
128
+ <Select.TriggerButton classNames='is-full' disabled={!!readonly} placeholder={placeholder} />
128
129
  <Select.Portal>
129
130
  <Select.Content>
130
131
  <Select.Viewport>
@@ -135,6 +136,7 @@ export const SelectInput = ({
135
136
  </Select.Option>
136
137
  ))}
137
138
  </Select.Viewport>
139
+ <Select.Arrow />
138
140
  </Select.Content>
139
141
  </Select.Portal>
140
142
  </Select.Root>
@@ -148,7 +150,7 @@ export const MarkdownInput = ({
148
150
  type,
149
151
  label,
150
152
  inputOnly,
151
- disabled,
153
+ readonly,
152
154
  placeholder,
153
155
  getStatus,
154
156
  getValue,
@@ -182,12 +184,12 @@ export const MarkdownInput = ({
182
184
  return (
183
185
  <Input.Root validationValence={status}>
184
186
  {!inputOnly && <InputHeader error={error} label={label} />}
185
- {disabled ? (
187
+ {readonly === 'static' ? (
186
188
  <p>{getValue() ?? ''}</p>
187
189
  ) : (
188
190
  <Input.TextArea
189
191
  ref={textareaRef}
190
- disabled={disabled}
192
+ disabled={!!readonly}
191
193
  placeholder={placeholder}
192
194
  value={getValue() ?? ''}
193
195
  classNames={'min-bs-auto max-h-40 overflow-auto'}