@dxos/react-ui-form 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
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 +354 -306
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +354 -306
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +2 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +8 -8
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +4 -2
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +41 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +82 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +7 -5
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +2 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +4 -3
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +1 -1
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -33
- package/src/components/ControlSection/ControlSection.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +4 -3
- package/src/components/Form/Form.stories.tsx +3 -3
- package/src/components/Form/Form.tsx +13 -5
- package/src/components/Form/FormContent.tsx +5 -3
- package/src/components/Form/FormContext.tsx +2 -2
- package/src/components/Form/Input.tsx +1 -1
- package/src/components/Form/RefField.tsx +35 -115
- package/src/components/Form/custom/GeoPointInput.tsx +1 -1
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.tsx +1 -1
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +207 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +161 -0
- package/src/components/ObjectPicker/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +41 -25
- package/src/components/ViewEditor/ViewEditor.test.tsx +3 -2
- package/src/components/ViewEditor/ViewEditor.tsx +45 -94
- package/src/components/index.ts +1 -0
- package/src/components/testing.tsx +2 -2
- package/src/hooks/useForm.ts +6 -4
- package/src/hooks/useQueryRefOptions.ts +9 -6
- package/src/hooks/useRefQueryLookupHandler.ts +3 -3
- package/src/util/field.ts +1 -1
- package/src/util/formatting.ts +1 -1
- package/src/util/refs.ts +2 -2
- package/src/util/schema.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-form",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ae835ea",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -32,51 +32,50 @@
|
|
|
32
32
|
"@radix-ui/react-context": "1.1.1",
|
|
33
33
|
"date-fns": "^3.3.1",
|
|
34
34
|
"jsonpath": "^1.1.1",
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/echo-
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/log": "0.8.4-main.
|
|
46
|
-
"@dxos/react-
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/react-ui-list": "0.8.4-main.
|
|
50
|
-
"@dxos/react-ui-
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/react-ui-
|
|
54
|
-
"@dxos/react-ui-
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/util": "0.8.4-main.a4bbb77"
|
|
35
|
+
"@dxos/echo": "0.8.4-main.ae835ea",
|
|
36
|
+
"@dxos/echo-db": "0.8.4-main.ae835ea",
|
|
37
|
+
"@dxos/async": "0.8.4-main.ae835ea",
|
|
38
|
+
"@dxos/echo-query": "0.8.4-main.ae835ea",
|
|
39
|
+
"@dxos/effect": "0.8.4-main.ae835ea",
|
|
40
|
+
"@dxos/invariant": "0.8.4-main.ae835ea",
|
|
41
|
+
"@dxos/keys": "0.8.4-main.ae835ea",
|
|
42
|
+
"@dxos/lit-ui": "0.8.4-main.ae835ea",
|
|
43
|
+
"@dxos/debug": "0.8.4-main.ae835ea",
|
|
44
|
+
"@dxos/react-client": "0.8.4-main.ae835ea",
|
|
45
|
+
"@dxos/log": "0.8.4-main.ae835ea",
|
|
46
|
+
"@dxos/react-ui-components": "0.8.4-main.ae835ea",
|
|
47
|
+
"@dxos/react-ui-editor": "0.8.4-main.ae835ea",
|
|
48
|
+
"@dxos/live-object": "0.8.4-main.ae835ea",
|
|
49
|
+
"@dxos/react-ui-list": "0.8.4-main.ae835ea",
|
|
50
|
+
"@dxos/react-ui-stack": "0.8.4-main.ae835ea",
|
|
51
|
+
"@dxos/util": "0.8.4-main.ae835ea",
|
|
52
|
+
"@dxos/schema": "0.8.4-main.ae835ea",
|
|
53
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.ae835ea",
|
|
54
|
+
"@dxos/react-ui-types": "0.8.4-main.ae835ea",
|
|
55
|
+
"@dxos/react-ui-pickers": "0.8.4-main.ae835ea"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|
|
59
58
|
"@types/jsonpath": "^0.2.4",
|
|
60
|
-
"@types/react": "~19.2.
|
|
61
|
-
"@types/react-dom": "~19.2.
|
|
59
|
+
"@types/react": "~19.2.2",
|
|
60
|
+
"@types/react-dom": "~19.2.2",
|
|
62
61
|
"effect": "3.18.3",
|
|
63
62
|
"fast-check": "^3.19.0",
|
|
64
63
|
"react": "~19.2.0",
|
|
65
64
|
"react-dom": "~19.2.0",
|
|
66
65
|
"vite": "7.1.9",
|
|
67
|
-
"@dxos/echo-signals": "0.8.4-main.
|
|
68
|
-
"@dxos/random": "0.8.4-main.
|
|
69
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
70
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
71
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
72
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
66
|
+
"@dxos/echo-signals": "0.8.4-main.ae835ea",
|
|
67
|
+
"@dxos/random": "0.8.4-main.ae835ea",
|
|
68
|
+
"@dxos/react-ui": "0.8.4-main.ae835ea",
|
|
69
|
+
"@dxos/react-ui-theme": "0.8.4-main.ae835ea",
|
|
70
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.ae835ea",
|
|
71
|
+
"@dxos/storybook-utils": "0.8.4-main.ae835ea"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
74
|
"effect": "^3.13.3",
|
|
76
75
|
"react": "^19.0.0",
|
|
77
76
|
"react-dom": "^19.0.0",
|
|
78
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
79
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
77
|
+
"@dxos/react-ui": "0.8.4-main.ae835ea",
|
|
78
|
+
"@dxos/react-ui-theme": "0.8.4-main.ae835ea"
|
|
80
79
|
},
|
|
81
80
|
"publishConfig": {
|
|
82
81
|
"access": "public"
|
|
@@ -22,7 +22,7 @@ export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
|
|
|
22
22
|
|
|
23
23
|
export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
|
|
24
24
|
return (
|
|
25
|
-
<StackItem.Content classNames='
|
|
25
|
+
<StackItem.Content scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
|
|
26
26
|
<div role='none' className={mx('pli-cardSpacingInline pbe-trimLg', classNames)} {...props}>
|
|
27
27
|
{children}
|
|
28
28
|
</div>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useEffect, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import { createEchoSchema } from '@dxos/
|
|
8
|
+
import { createEchoSchema } from '@dxos/echo/testing';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
11
|
import { ProjectionModel } from '@dxos/schema';
|
|
@@ -4,8 +4,8 @@
|
|
|
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 { type EchoSchema, FormatEnum, FormatEnums, formatToType } from '@dxos/echo-schema';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { useAsyncEffect, useTranslation } from '@dxos/react-ui';
|
|
11
11
|
import {
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
10
|
import { SimpleType, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
|
|
@@ -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
|
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback, useState } from 'react';
|
|
8
8
|
|
|
9
9
|
import { ContactType } from '@dxos/client/testing';
|
|
10
10
|
import { type Type } from '@dxos/echo';
|
|
11
|
-
import { type BaseObject, Expando, Format, Ref, type TypeAnnotation, getObjectDXN } from '@dxos/echo
|
|
12
|
-
import { live } from '@dxos/
|
|
11
|
+
import { type BaseObject, Expando, Format, Ref, type TypeAnnotation, getObjectDXN } from '@dxos/echo/internal';
|
|
12
|
+
import { live } from '@dxos/echo/internal';
|
|
13
13
|
import { Tooltip } from '@dxos/react-ui';
|
|
14
14
|
import { withSurfaceVariantsLayout, withTheme } from '@dxos/react-ui/testing';
|
|
15
15
|
import { Testing } from '@dxos/schema/testing';
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { useFocusFinders } from '@fluentui/react-tabster';
|
|
6
|
-
import
|
|
7
|
-
import React, { type ReactElement,
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import React, { type ReactElement, useCallback, useEffect, useRef } from 'react';
|
|
8
8
|
|
|
9
|
-
import { type BaseObject, type PropertyKey } from '@dxos/echo
|
|
9
|
+
import { type BaseObject, type PropertyKey } from '@dxos/echo/internal';
|
|
10
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
11
11
|
import { cardDialogOverflow, cardSpacing } from '@dxos/react-ui-stack';
|
|
12
12
|
import { type ProjectionModel, type SchemaProperty } from '@dxos/schema';
|
|
13
13
|
|
|
14
|
-
import { type FormOptions } from '../../hooks';
|
|
14
|
+
import { type FormHandler, type FormOptions } from '../../hooks';
|
|
15
15
|
|
|
16
16
|
import { FormActions, type FormOuterSpacing } from './FormActions';
|
|
17
17
|
import { FormFields, type FormFieldsProps } from './FormContent';
|
|
@@ -41,6 +41,7 @@ export type FormProps<T extends BaseObject> = ThemedClassName<{
|
|
|
41
41
|
onCancel?: () => void;
|
|
42
42
|
}> &
|
|
43
43
|
Pick<FormOptions<T>, 'schema' | 'onValuesChanged' | 'onValidate' | 'onSave'> &
|
|
44
|
+
// TODO(wittjosiah): This needs to support different ref field options per field.
|
|
44
45
|
FormFieldsProps;
|
|
45
46
|
|
|
46
47
|
export const Form = <T extends BaseObject>({
|
|
@@ -72,7 +73,14 @@ export const Form = <T extends BaseObject>({
|
|
|
72
73
|
}, [autoFocus]);
|
|
73
74
|
|
|
74
75
|
// TODO(burdon): Name?
|
|
75
|
-
const handleValid =
|
|
76
|
+
const handleValid = useCallback(
|
|
77
|
+
async (values: any, meta: { changed: FormHandler<T>['changed'] }) => {
|
|
78
|
+
if (autoSave) {
|
|
79
|
+
await onSave?.(values, meta);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[autoSave, onSave],
|
|
83
|
+
);
|
|
76
84
|
|
|
77
85
|
return (
|
|
78
86
|
<FormProvider
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
import * as StringEffect from 'effect/String';
|
|
7
9
|
import React, { forwardRef, useMemo } from 'react';
|
|
8
10
|
|
|
9
11
|
import { createJsonPath, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
|
|
@@ -60,7 +62,7 @@ export const FormField = ({
|
|
|
60
62
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
61
63
|
const inputProps = useInputProps(path);
|
|
62
64
|
|
|
63
|
-
const label = useMemo(() => title ?? pipe(name, capitalize), [title, name]);
|
|
65
|
+
const label = useMemo(() => title ?? Function.pipe(name, StringEffect.capitalize), [title, name]);
|
|
64
66
|
const placeholder = useMemo(
|
|
65
67
|
() => (examples?.length ? `Example: "${examples[0]}"` : description),
|
|
66
68
|
[examples, description],
|
|
@@ -14,7 +14,7 @@ import React, {
|
|
|
14
14
|
} from 'react';
|
|
15
15
|
|
|
16
16
|
import { raise } from '@dxos/debug';
|
|
17
|
-
import { type BaseObject, getValue } from '@dxos/echo
|
|
17
|
+
import { type BaseObject, getValue } from '@dxos/echo/internal';
|
|
18
18
|
import { type SimpleType, createJsonPath } from '@dxos/effect';
|
|
19
19
|
|
|
20
20
|
import { type FormHandler, type FormOptions, useForm } from '../../hooks';
|
|
@@ -92,7 +92,7 @@ export const FormProvider = ({
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
|
-
[form, autoSave],
|
|
95
|
+
[form.canSave, form.formIsValid, form.handleSave, autoSave],
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
useEffect(() => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type FC } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type FormatEnum } from '@dxos/echo
|
|
7
|
+
import { type FormatEnum } from '@dxos/echo/internal';
|
|
8
8
|
import { type SimpleType } from '@dxos/effect';
|
|
9
9
|
import { Icon, Input, Tooltip } from '@dxos/react-ui';
|
|
10
10
|
import { labelSpacing } from '@dxos/react-ui-stack';
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import '@dxos/lit-ui/dx-tag-picker.pcss';
|
|
6
|
+
|
|
7
|
+
import type * as Schema from 'effect/Schema';
|
|
8
|
+
import type * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
import React, { useCallback, useMemo } from 'react';
|
|
7
10
|
|
|
8
11
|
import {
|
|
9
12
|
type EchoSchema,
|
|
@@ -12,21 +15,20 @@ import {
|
|
|
12
15
|
ReferenceAnnotationId,
|
|
13
16
|
type ReferenceAnnotationValue,
|
|
14
17
|
getTypeAnnotation,
|
|
15
|
-
} from '@dxos/echo
|
|
18
|
+
} from '@dxos/echo/internal';
|
|
16
19
|
import { findAnnotation } from '@dxos/effect';
|
|
17
20
|
import { DXN } from '@dxos/keys';
|
|
18
21
|
import { type DxTagPickerItemClick } from '@dxos/lit-ui';
|
|
19
22
|
import { DxAnchor, DxTagPickerItem } from '@dxos/lit-ui/react';
|
|
20
|
-
import { Button, Icon, Input,
|
|
21
|
-
import { PopoverCombobox } from '@dxos/react-ui-searchlist';
|
|
23
|
+
import { Button, Icon, Input, useTranslation } from '@dxos/react-ui';
|
|
22
24
|
import { descriptionText, mx } from '@dxos/react-ui-theme';
|
|
23
25
|
import { isNonNullable } from '@dxos/util';
|
|
24
26
|
|
|
25
27
|
import { type QueryRefOptions, useQueryRefOptions } from '../../hooks';
|
|
26
28
|
import { translationKey } from '../../translations';
|
|
29
|
+
import { ObjectPicker } from '../ObjectPicker';
|
|
27
30
|
|
|
28
31
|
import { TextInput } from './Defaults';
|
|
29
|
-
import { Form } from './Form';
|
|
30
32
|
import { InputHeader, type InputProps } from './Input';
|
|
31
33
|
|
|
32
34
|
export type RefFieldProps = InputProps & {
|
|
@@ -70,55 +72,11 @@ export const RefField = ({
|
|
|
70
72
|
() => (ast ? findAnnotation<ReferenceAnnotationValue>(ast, ReferenceAnnotationId) : undefined),
|
|
71
73
|
[ast],
|
|
72
74
|
);
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const handleFormSave = useCallback(
|
|
79
|
-
(values: any) => {
|
|
80
|
-
onCreate?.(values);
|
|
81
|
-
setShowForm(false);
|
|
82
|
-
setSearchString('');
|
|
83
|
-
},
|
|
84
|
-
[refTypeInfo, onCreate],
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const handleFormCancel = useCallback(() => {
|
|
88
|
-
setShowForm(false);
|
|
89
|
-
setSearchString('');
|
|
90
|
-
}, []);
|
|
91
|
-
|
|
92
|
-
// TODO(thure): The following workarounds are necessary because `onSelect` is called after the Popover is already
|
|
93
|
-
// closed. Augment/refactor CmdK, if possible, to facilitate stopping event default & propagation.
|
|
94
|
-
|
|
95
|
-
const handleClick = useCallback(
|
|
96
|
-
(event: MouseEvent) => {
|
|
97
|
-
if (createSchema && (event.target as HTMLElement).closest('[data-value="__create__"]')) {
|
|
98
|
-
event.stopPropagation();
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
setShowForm(true);
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
[createSchema],
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const handleKeyDown = useCallback(
|
|
107
|
-
(event: KeyboardEvent) => {
|
|
108
|
-
if (
|
|
109
|
-
event.key === 'Enter' &&
|
|
110
|
-
createSchema &&
|
|
111
|
-
(event.currentTarget as HTMLElement).querySelector(
|
|
112
|
-
'[role="option"][aria-selected="true"][data-value="__create__"]',
|
|
113
|
-
)
|
|
114
|
-
) {
|
|
115
|
-
event.stopPropagation();
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
setShowForm(true);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
[createSchema],
|
|
121
|
-
);
|
|
75
|
+
const {
|
|
76
|
+
options: availableOptions,
|
|
77
|
+
update: updateOptions,
|
|
78
|
+
loading: _loading,
|
|
79
|
+
} = useQueryRefOptions({ refTypeInfo, onQueryRefOptions });
|
|
122
80
|
|
|
123
81
|
if ((refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename) || !onQueryRefOptions) {
|
|
124
82
|
// If ref type is expando, fall back to taking a DXN in string format.
|
|
@@ -183,6 +141,14 @@ export const RefField = ({
|
|
|
183
141
|
[availableOptions, array, onValueChange],
|
|
184
142
|
);
|
|
185
143
|
|
|
144
|
+
const handleCreate = useCallback(
|
|
145
|
+
(values: any) => {
|
|
146
|
+
onCreate?.(values);
|
|
147
|
+
updateOptions();
|
|
148
|
+
},
|
|
149
|
+
[onCreate, updateOptions],
|
|
150
|
+
);
|
|
151
|
+
|
|
186
152
|
if (!refTypeInfo) {
|
|
187
153
|
return null;
|
|
188
154
|
}
|
|
@@ -191,14 +157,6 @@ export const RefField = ({
|
|
|
191
157
|
|
|
192
158
|
const items = handleGetValue();
|
|
193
159
|
const selectedIds = useMemo(() => items.map((i: any) => i.id), [items]);
|
|
194
|
-
const labelById = useMemo(
|
|
195
|
-
() =>
|
|
196
|
-
availableOptions.reduce((acc: Record<string, string>, option) => {
|
|
197
|
-
acc[option.id.toLowerCase()] = option.label.toLowerCase();
|
|
198
|
-
return acc;
|
|
199
|
-
}, {}),
|
|
200
|
-
[availableOptions],
|
|
201
|
-
);
|
|
202
160
|
const toggleSelect = useCallback(
|
|
203
161
|
(id: string) => {
|
|
204
162
|
if (array) {
|
|
@@ -231,8 +189,8 @@ export const RefField = ({
|
|
|
231
189
|
))
|
|
232
190
|
)
|
|
233
191
|
) : (
|
|
234
|
-
<
|
|
235
|
-
<
|
|
192
|
+
<ObjectPicker.Root>
|
|
193
|
+
<ObjectPicker.Trigger asChild>
|
|
236
194
|
<Button variant='ghost' classNames='is-full text-start gap-2'>
|
|
237
195
|
<div role='none' className='grow'>
|
|
238
196
|
{items?.length ? (
|
|
@@ -258,56 +216,18 @@ export const RefField = ({
|
|
|
258
216
|
</div>
|
|
259
217
|
<Icon size={3} icon='ph--caret-down--bold' />
|
|
260
218
|
</Button>
|
|
261
|
-
</
|
|
262
|
-
<
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
values={createInitialValuePath ? { [createInitialValuePath]: searchString } : {}}
|
|
274
|
-
onSave={handleFormSave}
|
|
275
|
-
onCancel={handleFormCancel}
|
|
276
|
-
testId='create-referenced-object-form'
|
|
277
|
-
/>
|
|
278
|
-
</Popover.Viewport>
|
|
279
|
-
) : (
|
|
280
|
-
<>
|
|
281
|
-
<PopoverCombobox.Input
|
|
282
|
-
placeholder={t('ref field combobox input placeholder')}
|
|
283
|
-
value={searchString}
|
|
284
|
-
onValueChange={(v) => setSearchString(v)}
|
|
285
|
-
autoFocus
|
|
286
|
-
/>
|
|
287
|
-
<PopoverCombobox.List>
|
|
288
|
-
{availableOptions.map((option) => (
|
|
289
|
-
<PopoverCombobox.Item
|
|
290
|
-
key={option.id}
|
|
291
|
-
value={option.id}
|
|
292
|
-
onSelect={() => toggleSelect(option.id)}
|
|
293
|
-
classNames='flex items-center gap-2'
|
|
294
|
-
>
|
|
295
|
-
<span className='grow'>{option.label}</span>
|
|
296
|
-
{selectedIds.includes(option.id) && <Icon icon='ph--check--regular' />}
|
|
297
|
-
</PopoverCombobox.Item>
|
|
298
|
-
))}
|
|
299
|
-
{searchString.length > 0 && createOptionLabel && createOptionIcon && createSchema && (
|
|
300
|
-
<PopoverCombobox.Item value='__create__' classNames='flex items-center gap-2'>
|
|
301
|
-
<Icon icon={createOptionIcon} />
|
|
302
|
-
{t(createOptionLabel[0], { ns: createOptionLabel[1].ns, text: searchString })}
|
|
303
|
-
</PopoverCombobox.Item>
|
|
304
|
-
)}
|
|
305
|
-
</PopoverCombobox.List>
|
|
306
|
-
</>
|
|
307
|
-
)}
|
|
308
|
-
<PopoverCombobox.Arrow />
|
|
309
|
-
</PopoverCombobox.Content>
|
|
310
|
-
</PopoverCombobox.Root>
|
|
219
|
+
</ObjectPicker.Trigger>
|
|
220
|
+
<ObjectPicker.Content
|
|
221
|
+
options={availableOptions}
|
|
222
|
+
selectedIds={selectedIds}
|
|
223
|
+
onSelect={toggleSelect}
|
|
224
|
+
createSchema={createSchema}
|
|
225
|
+
createOptionLabel={createOptionLabel}
|
|
226
|
+
createOptionIcon={createOptionIcon}
|
|
227
|
+
createInitialValuePath={createInitialValuePath}
|
|
228
|
+
onCreate={handleCreate}
|
|
229
|
+
/>
|
|
230
|
+
</ObjectPicker.Root>
|
|
311
231
|
)}
|
|
312
232
|
</div>
|
|
313
233
|
{inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { GeoLocation, type GeoPoint } from '@dxos/echo
|
|
7
|
+
import { GeoLocation, type GeoPoint } from '@dxos/echo/internal';
|
|
8
8
|
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { safeParseFloat } from '@dxos/util';
|
|
10
10
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import { type SelectOption, SelectOptionSchema } from '@dxos/echo
|
|
9
|
+
import { type SelectOption, SelectOptionSchema } from '@dxos/echo/internal';
|
|
10
10
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
11
|
|
|
12
12
|
import { translations } from '../../../translations';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type ChangeEvent, type KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type SelectOption } from '@dxos/echo
|
|
7
|
+
import { type SelectOption } from '@dxos/echo/internal';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { type ChromaticPalette, IconButton, Input, Tag, useTranslation } from '@dxos/react-ui';
|
|
10
10
|
import { List } from '@dxos/react-ui-list';
|