@dxos/react-ui-form 0.8.2-main.2f9c567 → 0.8.2-main.36232bc
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 +117 -275
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +103 -258
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +117 -275
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +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 +3 -6
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +32 -35
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +11 -14
- package/dist/types/src/components/Form/FormContent.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/index.d.ts +0 -1
- package/dist/types/src/components/Form/index.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/hooks/index.d.ts +0 -1
- 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/package.json +25 -25
- package/src/components/Form/ArrayField.tsx +6 -5
- package/src/components/Form/Defaults.tsx +1 -4
- package/src/components/Form/Form.stories.tsx +38 -86
- package/src/components/Form/Form.tsx +2 -7
- package/src/components/Form/FormContent.tsx +19 -62
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +4 -5
- package/src/components/Form/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +2 -3
- package/src/components/ViewEditor/ViewEditor.tsx +10 -12
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useForm.ts +3 -3
- package/dist/types/src/components/Form/RefField.d.ts +0 -24
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/src/components/Form/RefField.tsx +0 -152
- package/src/hooks/useRefQueryLookupHandler.ts +0 -43
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type SchemaAST } from 'effect';
|
|
6
|
-
import React, { useEffect, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
Expando,
|
|
10
|
-
getTypeAnnotation,
|
|
11
|
-
Ref,
|
|
12
|
-
ReferenceAnnotationId,
|
|
13
|
-
type ReferenceAnnotationValue,
|
|
14
|
-
type TypeAnnotation,
|
|
15
|
-
} from '@dxos/echo-schema';
|
|
16
|
-
import { findAnnotation, type SimpleType } from '@dxos/effect';
|
|
17
|
-
import { DXN } from '@dxos/keys';
|
|
18
|
-
import { refFromDXN } from '@dxos/live-object';
|
|
19
|
-
import { log } from '@dxos/log';
|
|
20
|
-
import { type MaybePromise } from '@dxos/util';
|
|
21
|
-
|
|
22
|
-
import { SelectInput, TextInput } from './Defaults';
|
|
23
|
-
import { type FormInputStateProps } from './FormContext';
|
|
24
|
-
|
|
25
|
-
export type QueryRefOptions = (type: TypeAnnotation) => MaybePromise<{ dxn: DXN; label?: string }[]>;
|
|
26
|
-
|
|
27
|
-
type RefFieldProps = {
|
|
28
|
-
ast: SchemaAST.AST;
|
|
29
|
-
type: SimpleType;
|
|
30
|
-
label: string;
|
|
31
|
-
readonly?: boolean;
|
|
32
|
-
placeholder?: string;
|
|
33
|
-
inline?: boolean;
|
|
34
|
-
onQueryRefOptions?: QueryRefOptions;
|
|
35
|
-
inputProps: FormInputStateProps;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const RefField = ({
|
|
39
|
-
ast,
|
|
40
|
-
type,
|
|
41
|
-
label,
|
|
42
|
-
readonly,
|
|
43
|
-
placeholder,
|
|
44
|
-
inline,
|
|
45
|
-
onQueryRefOptions,
|
|
46
|
-
inputProps,
|
|
47
|
-
}: RefFieldProps) => {
|
|
48
|
-
const { getValue, onValueChange, ...restInputProps } = inputProps;
|
|
49
|
-
const refTypeInfo = findAnnotation<ReferenceAnnotationValue>(ast, ReferenceAnnotationId);
|
|
50
|
-
const [refOptions, setRefOptions] = useState<Array<{ value: string; label?: string }>>([]);
|
|
51
|
-
const [loading, setLoading] = useState(false);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const fetchOptions = async () => {
|
|
59
|
-
setLoading(true);
|
|
60
|
-
try {
|
|
61
|
-
const options = await onQueryRefOptions(refTypeInfo);
|
|
62
|
-
setRefOptions(
|
|
63
|
-
options.map((option) => ({
|
|
64
|
-
label: option.label,
|
|
65
|
-
value: option.dxn.toString(),
|
|
66
|
-
})),
|
|
67
|
-
);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
log.error('Failed to fetch ref options:', error);
|
|
70
|
-
setRefOptions([]);
|
|
71
|
-
} finally {
|
|
72
|
-
setLoading(false);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
void fetchOptions();
|
|
77
|
-
}, [refTypeInfo, onQueryRefOptions]);
|
|
78
|
-
|
|
79
|
-
if (!refTypeInfo) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// If ref type is expando, fall back to taking a DXN in string format.
|
|
84
|
-
if (refTypeInfo.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
|
|
85
|
-
const handleOnValueChange = (_type: any, dxnString: string) => {
|
|
86
|
-
const dxn = DXN.tryParse(dxnString);
|
|
87
|
-
if (dxn) {
|
|
88
|
-
onValueChange?.('object', refFromDXN(dxn));
|
|
89
|
-
} else if (dxnString === '') {
|
|
90
|
-
onValueChange?.('object', undefined);
|
|
91
|
-
} else {
|
|
92
|
-
onValueChange?.('string', dxnString);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const handleGetValue = () => {
|
|
97
|
-
const formValue = getValue();
|
|
98
|
-
if (typeof formValue === 'string') {
|
|
99
|
-
return formValue;
|
|
100
|
-
}
|
|
101
|
-
if (Ref.isRef(formValue)) {
|
|
102
|
-
return formValue.dxn.toString();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return undefined;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<TextInput
|
|
110
|
-
type={type}
|
|
111
|
-
label={label}
|
|
112
|
-
disabled={readonly}
|
|
113
|
-
placeholder={placeholder}
|
|
114
|
-
inputOnly={inline}
|
|
115
|
-
getValue={handleGetValue as <V>() => V | undefined}
|
|
116
|
-
onValueChange={handleOnValueChange}
|
|
117
|
-
{...restInputProps}
|
|
118
|
-
/>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const handleGetValue = () => {
|
|
123
|
-
const formValue = getValue();
|
|
124
|
-
|
|
125
|
-
if (Ref.isRef(formValue)) {
|
|
126
|
-
return formValue.dxn.toString();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return undefined;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const handleValueChanged = (_type: any, dxnString: string) => {
|
|
133
|
-
const dxn = DXN.parse(dxnString);
|
|
134
|
-
const ref = refFromDXN(dxn);
|
|
135
|
-
|
|
136
|
-
onValueChange('object', ref);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<SelectInput
|
|
141
|
-
type={type}
|
|
142
|
-
label={label}
|
|
143
|
-
disabled={readonly || loading}
|
|
144
|
-
placeholder={loading ? 'Loading options...' : placeholder}
|
|
145
|
-
inputOnly={inline}
|
|
146
|
-
getValue={handleGetValue as <V>() => V | undefined}
|
|
147
|
-
onValueChange={handleValueChanged}
|
|
148
|
-
options={refOptions}
|
|
149
|
-
{...restInputProps}
|
|
150
|
-
/>
|
|
151
|
-
);
|
|
152
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useCallback } from 'react';
|
|
6
|
-
|
|
7
|
-
import { getDXN, type TypeAnnotation } from '@dxos/echo-schema';
|
|
8
|
-
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
9
|
-
import { isNonNullable } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
import { type QueryRefOptions } from '../components';
|
|
12
|
-
|
|
13
|
-
type UseRefQueryLookupProps = {
|
|
14
|
-
space?: Space;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const useRefQueryLookupHandler = ({ space }: UseRefQueryLookupProps): QueryRefOptions => {
|
|
18
|
-
const handleRefQueryLookup = useCallback(
|
|
19
|
-
async (typeInfo: TypeAnnotation) => {
|
|
20
|
-
if (!space) {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
const query = space.db.query(Filter.typename(typeInfo.typename));
|
|
24
|
-
const { objects } = await query.run();
|
|
25
|
-
|
|
26
|
-
return objects
|
|
27
|
-
.map((object) => {
|
|
28
|
-
const dxn = getDXN(object);
|
|
29
|
-
if (!dxn) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// TODO(Zaymon): Better fallback object names?
|
|
34
|
-
const item = { dxn, label: object?.name ?? object?.id ?? '' };
|
|
35
|
-
return item;
|
|
36
|
-
})
|
|
37
|
-
.filter(isNonNullable);
|
|
38
|
-
},
|
|
39
|
-
[space],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return handleRefQueryLookup;
|
|
43
|
-
};
|