@dxos/react-ui-form 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc
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 +546 -362
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +589 -401
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +546 -362
- 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 +1 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +1 -2
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +5 -5
- package/dist/types/src/components/Form/Defaults.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/FormActions.d.ts +1 -2
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +2 -3
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +4 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +2 -2
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +2 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts +1 -2
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +1 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +1 -2
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +2 -2
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +1 -0
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/package.json +25 -24
- package/src/components/Form/Defaults.tsx +61 -4
- package/src/components/Form/Form.tsx +9 -5
- package/src/components/Form/FormActions.tsx +1 -1
- package/src/components/Form/FormContent.tsx +10 -13
- package/src/components/Form/FormContext.tsx +58 -10
- package/src/components/Form/custom/GeoPointInput.tsx +42 -12
- package/src/components/Form/custom/SelectOptionsInput.tsx +7 -9
- package/src/components/Form/factory.tsx +4 -2
- package/src/components/Form/index.ts +3 -0
- package/src/components/ViewEditor/ViewEditor.tsx +2 -2
- package/src/hooks/useForm.ts +69 -40
- package/src/translations.ts +1 -1
- package/src/util/field.ts +19 -1
- package/src/util/formatting.ts +29 -1
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-form",
|
|
3
|
-
"version": "0.7.5-labs.
|
|
3
|
+
"version": "0.7.5-labs.f400bbc",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"types": "./dist/types/src/index.d.ts",
|
|
@@ -28,21 +29,21 @@
|
|
|
28
29
|
"@radix-ui/react-context": "1.1.1",
|
|
29
30
|
"date-fns": "^3.3.1",
|
|
30
31
|
"jsonpath": "^1.1.1",
|
|
31
|
-
"@dxos/async": "0.7.5-labs.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/effect": "0.7.5-labs.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/live-object": "0.7.5-labs.
|
|
39
|
-
"@dxos/log": "0.7.5-labs.
|
|
40
|
-
"@dxos/react-
|
|
41
|
-
"@dxos/react-ui-list": "0.7.5-labs.
|
|
42
|
-
"@dxos/react-
|
|
43
|
-
"@dxos/react-ui-
|
|
44
|
-
"@dxos/schema": "0.7.5-labs.
|
|
45
|
-
"@dxos/util": "0.7.5-labs.
|
|
32
|
+
"@dxos/async": "0.7.5-labs.f400bbc",
|
|
33
|
+
"@dxos/debug": "0.7.5-labs.f400bbc",
|
|
34
|
+
"@dxos/echo-db": "0.7.5-labs.f400bbc",
|
|
35
|
+
"@dxos/echo-schema": "0.7.5-labs.f400bbc",
|
|
36
|
+
"@dxos/effect": "0.7.5-labs.f400bbc",
|
|
37
|
+
"@dxos/invariant": "0.7.5-labs.f400bbc",
|
|
38
|
+
"@dxos/keys": "0.7.5-labs.f400bbc",
|
|
39
|
+
"@dxos/live-object": "0.7.5-labs.f400bbc",
|
|
40
|
+
"@dxos/log": "0.7.5-labs.f400bbc",
|
|
41
|
+
"@dxos/react-ui-pickers": "0.7.5-labs.f400bbc",
|
|
42
|
+
"@dxos/react-ui-list": "0.7.5-labs.f400bbc",
|
|
43
|
+
"@dxos/react-client": "0.7.5-labs.f400bbc",
|
|
44
|
+
"@dxos/react-ui-types": "0.7.5-labs.f400bbc",
|
|
45
|
+
"@dxos/schema": "0.7.5-labs.f400bbc",
|
|
46
|
+
"@dxos/util": "0.7.5-labs.f400bbc"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@phosphor-icons/react": "^2.1.5",
|
|
@@ -54,12 +55,12 @@
|
|
|
54
55
|
"react": "~18.2.0",
|
|
55
56
|
"react-dom": "~18.2.0",
|
|
56
57
|
"vite": "5.4.7",
|
|
57
|
-
"@dxos/echo-signals": "0.7.5-labs.
|
|
58
|
-
"@dxos/random": "0.7.5-labs.
|
|
59
|
-
"@dxos/react-ui
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/react-ui-
|
|
58
|
+
"@dxos/echo-signals": "0.7.5-labs.f400bbc",
|
|
59
|
+
"@dxos/random": "0.7.5-labs.f400bbc",
|
|
60
|
+
"@dxos/react-ui": "0.7.5-labs.f400bbc",
|
|
61
|
+
"@dxos/react-ui-syntax-highlighter": "0.7.5-labs.f400bbc",
|
|
62
|
+
"@dxos/storybook-utils": "0.7.5-labs.f400bbc",
|
|
63
|
+
"@dxos/react-ui-theme": "0.7.5-labs.f400bbc"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|
|
65
66
|
"@effect/schema": "^0.75.5",
|
|
@@ -67,8 +68,8 @@
|
|
|
67
68
|
"effect": "^3.12.3",
|
|
68
69
|
"react": "~18.2.0",
|
|
69
70
|
"react-dom": "~18.2.0",
|
|
70
|
-
"@dxos/react-ui": "0.7.5-labs.
|
|
71
|
-
"@dxos/react-ui-theme": "0.7.5-labs.
|
|
71
|
+
"@dxos/react-ui": "0.7.5-labs.f400bbc",
|
|
72
|
+
"@dxos/react-ui-theme": "0.7.5-labs.f400bbc"
|
|
72
73
|
},
|
|
73
74
|
"publishConfig": {
|
|
74
75
|
"access": "public"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Input, Select } from '@dxos/react-ui';
|
|
8
8
|
|
|
@@ -75,9 +75,8 @@ export const NumberInput = ({
|
|
|
75
75
|
|
|
76
76
|
export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onValueChange }: InputProps) => {
|
|
77
77
|
const { status, error } = getStatus();
|
|
78
|
+
const checked = Boolean(getValue());
|
|
78
79
|
|
|
79
|
-
// TODO(burdon): Runtime error:
|
|
80
|
-
// Warning: Unknown event handler property `onCheckedChange`. It will be ignored.
|
|
81
80
|
return (
|
|
82
81
|
<Input.Root validationValence={status}>
|
|
83
82
|
{!inputOnly && (
|
|
@@ -85,7 +84,7 @@ export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onVa
|
|
|
85
84
|
<Input.Label>{label}</Input.Label>
|
|
86
85
|
</InputHeader>
|
|
87
86
|
)}
|
|
88
|
-
<Input.Switch checked={
|
|
87
|
+
<Input.Switch checked={checked} onCheckedChange={(value) => onValueChange(type, value)} />
|
|
89
88
|
{inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
90
89
|
</Input.Root>
|
|
91
90
|
);
|
|
@@ -135,3 +134,61 @@ export const SelectInput = ({
|
|
|
135
134
|
</Input.Root>
|
|
136
135
|
);
|
|
137
136
|
};
|
|
137
|
+
|
|
138
|
+
export const MarkdownInput = ({
|
|
139
|
+
type,
|
|
140
|
+
label,
|
|
141
|
+
inputOnly,
|
|
142
|
+
disabled,
|
|
143
|
+
placeholder,
|
|
144
|
+
getStatus,
|
|
145
|
+
getValue,
|
|
146
|
+
onValueChange,
|
|
147
|
+
onBlur,
|
|
148
|
+
}: InputProps) => {
|
|
149
|
+
const { status, error } = getStatus();
|
|
150
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
151
|
+
|
|
152
|
+
// TODO(ZaymonFC): If we start using `Enter` for form submission, we should prevent default behavior here
|
|
153
|
+
// since we're using a textarea element and the user needs to be able to enter new lines.
|
|
154
|
+
|
|
155
|
+
const adjustHeight = useCallback(() => {
|
|
156
|
+
const textarea = textareaRef.current;
|
|
157
|
+
if (textarea) {
|
|
158
|
+
textarea.style.blockSize = 'auto'; // For measurement.
|
|
159
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
160
|
+
}
|
|
161
|
+
}, []);
|
|
162
|
+
|
|
163
|
+
// Adjust height on initial render.
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
adjustHeight();
|
|
166
|
+
}, [adjustHeight]);
|
|
167
|
+
|
|
168
|
+
// Adjust height when the content changes.
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
adjustHeight();
|
|
171
|
+
}, [getValue(), adjustHeight]);
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<Input.Root validationValence={status}>
|
|
175
|
+
{!inputOnly && (
|
|
176
|
+
<InputHeader error={error}>
|
|
177
|
+
<Input.Label>{label}</Input.Label>
|
|
178
|
+
</InputHeader>
|
|
179
|
+
)}
|
|
180
|
+
<Input.TextArea
|
|
181
|
+
ref={textareaRef}
|
|
182
|
+
disabled={disabled}
|
|
183
|
+
placeholder={placeholder}
|
|
184
|
+
value={getValue() ?? ''}
|
|
185
|
+
classNames={'min-bs-auto max-h-40 overflow-auto'}
|
|
186
|
+
onChange={(event) => onValueChange(type, event.target.value)}
|
|
187
|
+
onBlur={onBlur}
|
|
188
|
+
style={{ resize: 'none' }}
|
|
189
|
+
spellCheck={false}
|
|
190
|
+
/>
|
|
191
|
+
{inputOnly && <Input.Validation>{error}</Input.Validation>}
|
|
192
|
+
</Input.Root>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { type ReactElement, useEffect, useMemo } from 'react';
|
|
5
|
+
import React, { type ReactElement, useEffect, useMemo, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type BaseObject, type S, type PropertyKey } from '@dxos/echo-schema';
|
|
8
8
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
@@ -68,12 +68,13 @@ export const Form = <T extends BaseObject>({
|
|
|
68
68
|
lookupComponent,
|
|
69
69
|
Custom,
|
|
70
70
|
}: FormProps<T>) => {
|
|
71
|
+
const formRef = useRef<HTMLDivElement>(null);
|
|
71
72
|
const onValid = useMemo(() => (autoSave ? onSave : undefined), [autoSave, onSave]);
|
|
72
73
|
|
|
73
|
-
//
|
|
74
|
+
// Focus the first input element within this form.
|
|
74
75
|
useEffect(() => {
|
|
75
|
-
if (autoFocus) {
|
|
76
|
-
const input =
|
|
76
|
+
if (autoFocus && formRef.current) {
|
|
77
|
+
const input = formRef.current.querySelector('input');
|
|
77
78
|
if (input) {
|
|
78
79
|
input.focus();
|
|
79
80
|
}
|
|
@@ -82,14 +83,17 @@ export const Form = <T extends BaseObject>({
|
|
|
82
83
|
|
|
83
84
|
return (
|
|
84
85
|
<FormProvider
|
|
86
|
+
formRef={formRef}
|
|
85
87
|
schema={schema}
|
|
88
|
+
autoSave={autoSave}
|
|
86
89
|
initialValues={initialValues}
|
|
87
90
|
onValuesChanged={onValuesChanged}
|
|
88
91
|
onValidate={onValidate}
|
|
89
92
|
onValid={onValid}
|
|
90
93
|
onSave={onSave}
|
|
91
94
|
>
|
|
92
|
-
|
|
95
|
+
{/* TODO(burdon): Remove padding. */}
|
|
96
|
+
<div ref={formRef} role='none' className={mx('p-2', classNames)} data-testid={testId}>
|
|
93
97
|
<FormFields
|
|
94
98
|
schema={schema}
|
|
95
99
|
path={path}
|
|
@@ -20,7 +20,7 @@ export const FormActions = ({ onCancel, readonly }: FormActionsProps) => {
|
|
|
20
20
|
const { canSave, handleSave } = useFormContext();
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<div role='none' className='flex justify-center'>
|
|
23
|
+
<div role='none' className='mt-2 flex justify-center'>
|
|
24
24
|
<div role='none' className={mx(onCancel && !readonly && 'grid grid-cols-2 gap-2')}>
|
|
25
25
|
{onCancel && !readonly && (
|
|
26
26
|
<IconButton data-testid='cancel-button' icon='ph--x--regular' label={t('button cancel')} onClick={onCancel} />
|
|
@@ -70,18 +70,15 @@ export const FormField = ({ property, path, readonly, inline, lookupComponent, C
|
|
|
70
70
|
const CustomComponent = Custom?.[jsonPath];
|
|
71
71
|
if (CustomComponent) {
|
|
72
72
|
return (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{...inputProps}
|
|
83
|
-
/>
|
|
84
|
-
</div>
|
|
73
|
+
<CustomComponent
|
|
74
|
+
type={type}
|
|
75
|
+
format={format}
|
|
76
|
+
label={label}
|
|
77
|
+
inputOnly={inline}
|
|
78
|
+
placeholder={placeholder}
|
|
79
|
+
disabled={readonly}
|
|
80
|
+
{...inputProps}
|
|
81
|
+
/>
|
|
85
82
|
);
|
|
86
83
|
}
|
|
87
84
|
|
|
@@ -153,7 +150,7 @@ export const FormFields = ({ schema, path, filter, sort, readonly, lookupCompone
|
|
|
153
150
|
}, [schema, values, filter, sort]);
|
|
154
151
|
|
|
155
152
|
return (
|
|
156
|
-
<div role='form' className={mx('flex flex-col w-full gap-2
|
|
153
|
+
<div role='form' className={mx('flex flex-col w-full gap-2')}>
|
|
157
154
|
{properties
|
|
158
155
|
.map((property) => {
|
|
159
156
|
return (
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { createContext, useContext, type FocusEvent, type PropsWithChildren } from 'react';
|
|
5
|
+
import React, { createContext, useContext, useEffect, useMemo, type FocusEvent, type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
import { type BaseObject, getValue } from '@dxos/echo-schema';
|
|
@@ -34,15 +34,63 @@ export type FormInputStateProps = {
|
|
|
34
34
|
export const useInputProps = (path: (string | number)[] = []): FormInputStateProps => {
|
|
35
35
|
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const stablePath = useMemo(() => path, [Array.isArray(path) ? path.join('.') : path]);
|
|
38
|
+
return useMemo(
|
|
39
|
+
() => ({
|
|
40
|
+
getStatus: () => getStatus(stablePath),
|
|
41
|
+
getValue: () => getFormValue(stablePath),
|
|
42
|
+
onValueChange: (type: SimpleType, value: any) => onValueChange(stablePath, type, value),
|
|
43
|
+
onBlur: () => onTouched(stablePath),
|
|
44
|
+
}),
|
|
45
|
+
[getStatus, getFormValue, onValueChange, onTouched, stablePath],
|
|
46
|
+
);
|
|
43
47
|
};
|
|
44
48
|
|
|
45
|
-
export const FormProvider = ({
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
export const FormProvider = ({
|
|
50
|
+
children,
|
|
51
|
+
formRef,
|
|
52
|
+
autoSave,
|
|
53
|
+
...formOptions
|
|
54
|
+
}: PropsWithChildren<
|
|
55
|
+
FormOptions<any> & {
|
|
56
|
+
formRef?: React.RefObject<HTMLDivElement>;
|
|
57
|
+
autoSave?: boolean;
|
|
58
|
+
}
|
|
59
|
+
>) => {
|
|
60
|
+
const form = useForm(formOptions);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!formRef?.current) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
68
|
+
const keyIsEnter = event.key === 'Enter';
|
|
69
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
70
|
+
const inputIsTextarea = (event.target as HTMLElement).tagName.toLowerCase() === 'textarea';
|
|
71
|
+
const inputOptOut = (event.target as HTMLElement).hasAttribute('data-no-submit');
|
|
72
|
+
|
|
73
|
+
// Regular inputs: Submit on Enter (no modifiers).
|
|
74
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
75
|
+
|
|
76
|
+
// Textareas: Submit only on Meta+Enter.
|
|
77
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
78
|
+
|
|
79
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
80
|
+
if (!autoSave && form.canSave) {
|
|
81
|
+
form.handleSave();
|
|
82
|
+
}
|
|
83
|
+
if (autoSave && form.formIsValid) {
|
|
84
|
+
(event.target as HTMLElement).blur();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const formElement = formRef.current;
|
|
90
|
+
|
|
91
|
+
formElement.addEventListener('keydown', handleKeyDown);
|
|
92
|
+
return () => formElement.removeEventListener('keydown', handleKeyDown);
|
|
93
|
+
}, [formRef, form.canSave, form.formIsValid, form.handleSave, autoSave]);
|
|
94
|
+
|
|
95
|
+
return <FormContext.Provider value={form}>{children}</FormContext.Provider>;
|
|
48
96
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useCallback, useState, useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type GeoPoint } from '@dxos/echo-schema';
|
|
7
|
+
import { type GeoPoint, GeoLocation } from '@dxos/echo-schema';
|
|
8
8
|
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { safeParseFloat } from '@dxos/util';
|
|
10
10
|
|
|
@@ -14,28 +14,58 @@ import { InputHeader, type InputProps } from '../Input';
|
|
|
14
14
|
export const GeoPointInput = ({ type, label, disabled, getStatus, getValue, onValueChange, onBlur }: InputProps) => {
|
|
15
15
|
const { t } = useTranslation(translationKey);
|
|
16
16
|
const { status, error } = getStatus();
|
|
17
|
-
const
|
|
17
|
+
const geoPoint = useMemo<GeoPoint>(() => getValue<GeoPoint>() ?? [0, 0], [getValue]);
|
|
18
|
+
const geoLocation = useMemo(() => GeoLocation.fromGeoPoint(geoPoint), [geoPoint]);
|
|
19
|
+
|
|
20
|
+
const [longitudeText, setLongitudeText] = useState(geoLocation.longitude?.toString());
|
|
21
|
+
const [latitudeText, setLatitudeText] = useState(geoLocation.latitude?.toString());
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const location = GeoLocation.fromGeoPoint(geoPoint);
|
|
25
|
+
setLongitudeText(location.longitude.toString());
|
|
26
|
+
setLatitudeText(location.latitude.toString());
|
|
27
|
+
}, [geoPoint]);
|
|
28
|
+
|
|
29
|
+
const handleCoordinateChange = useCallback(
|
|
30
|
+
(coordinateType: keyof Pick<GeoLocation, 'longitude' | 'latitude'>, setText: (text: string) => void) =>
|
|
31
|
+
(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
32
|
+
const inputText = event.target.value;
|
|
33
|
+
setText(inputText);
|
|
34
|
+
if (inputText !== '' && inputText !== '-') {
|
|
35
|
+
const coord = safeParseFloat(inputText);
|
|
36
|
+
if (coord !== undefined && !isNaN(coord)) {
|
|
37
|
+
const currentLocation = GeoLocation.fromGeoPoint(getValue<GeoPoint>() ?? [0, 0]);
|
|
38
|
+
const newLocation = { ...currentLocation, [coordinateType]: coord };
|
|
39
|
+
const newValue = GeoLocation.toGeoPoint(newLocation);
|
|
40
|
+
onValueChange(type, newValue);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[getValue, onValueChange, type],
|
|
45
|
+
);
|
|
18
46
|
|
|
19
47
|
return (
|
|
20
48
|
<Input.Root validationValence={status}>
|
|
21
49
|
<InputHeader error={error}>
|
|
22
50
|
<Input.Label>{label}</Input.Label>
|
|
23
51
|
</InputHeader>
|
|
24
|
-
<div className='grid grid-cols-2 gap-2'>
|
|
52
|
+
<div role='none' className='grid grid-cols-2 gap-2'>
|
|
25
53
|
<Input.TextInput
|
|
26
|
-
type='
|
|
54
|
+
type='text'
|
|
55
|
+
pattern='^-?[0-9]*\.?[0-9]*$'
|
|
27
56
|
disabled={disabled}
|
|
28
|
-
placeholder={t('placeholder
|
|
29
|
-
value={
|
|
30
|
-
onChange={(
|
|
57
|
+
placeholder={t('placeholder latitude')}
|
|
58
|
+
value={latitudeText}
|
|
59
|
+
onChange={handleCoordinateChange('latitude', setLatitudeText)}
|
|
31
60
|
onBlur={onBlur}
|
|
32
61
|
/>
|
|
33
62
|
<Input.TextInput
|
|
34
|
-
type='
|
|
63
|
+
type='text'
|
|
64
|
+
pattern='^-?[0-9]*\.?[0-9]*$'
|
|
35
65
|
disabled={disabled}
|
|
36
|
-
placeholder={t('placeholder
|
|
37
|
-
value={
|
|
38
|
-
onChange={(
|
|
66
|
+
placeholder={t('placeholder longitude')}
|
|
67
|
+
value={longitudeText}
|
|
68
|
+
onChange={handleCoordinateChange('longitude', setLongitudeText)}
|
|
39
69
|
onBlur={onBlur}
|
|
40
70
|
/>
|
|
41
71
|
</div>
|
|
@@ -8,8 +8,8 @@ import { type SelectOption } from '@dxos/echo-schema';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { type ChromaticPalette, Icon, IconButton, Input, Tag, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
10
10
|
import { List } from '@dxos/react-ui-list';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { HuePicker } from '@dxos/react-ui-pickers';
|
|
12
|
+
import { hues, mx } from '@dxos/react-ui-theme';
|
|
13
13
|
|
|
14
14
|
import { translationKey } from '../../../translations';
|
|
15
15
|
import { InputHeader, type InputProps } from '../Input';
|
|
@@ -32,20 +32,17 @@ export const SelectOptionInput = ({ type, label, disabled, getStatus, getValue,
|
|
|
32
32
|
|
|
33
33
|
const randomHue = () => {
|
|
34
34
|
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
35
|
-
const hueKeys = Object.keys(hueTokenThemes) as Array<keyof typeof hueTokenThemes>;
|
|
36
|
-
|
|
37
35
|
// Pick a random unused option from hueTokenThemes.
|
|
38
|
-
const unusedHues =
|
|
36
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
39
37
|
if (unusedHues.length > 0) {
|
|
40
38
|
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
// Pick a random one that hasn't been used in the last three options
|
|
44
42
|
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
45
|
-
const availableHues =
|
|
43
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
46
44
|
return (
|
|
47
|
-
availableHues[Math.floor(Math.random() * availableHues.length)] ??
|
|
48
|
-
hueKeys[Math.floor(Math.random() * hueKeys.length)]
|
|
45
|
+
availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)]
|
|
49
46
|
);
|
|
50
47
|
};
|
|
51
48
|
|
|
@@ -154,9 +151,10 @@ export const SelectOptionInput = ({ type, label, disabled, getStatus, getValue,
|
|
|
154
151
|
onChange={handleTitleChange(item.id)}
|
|
155
152
|
onKeyDown={handleKeyDown}
|
|
156
153
|
classNames='flex-1'
|
|
154
|
+
data-no-submit
|
|
157
155
|
/>
|
|
158
156
|
<Toolbar.Root classNames='p-0 m-0 !is-auto'>
|
|
159
|
-
<
|
|
157
|
+
<HuePicker value={item.color} onChange={handleColorChange(item.id)} />
|
|
160
158
|
</Toolbar.Root>
|
|
161
159
|
<IconButton
|
|
162
160
|
icon='ph--trash--fill'
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { FormatEnum } from '@dxos/echo-schema';
|
|
6
6
|
import { type SimpleType } from '@dxos/effect';
|
|
7
7
|
|
|
8
|
-
import { BooleanInput, NumberInput, TextInput } from './Defaults';
|
|
8
|
+
import { BooleanInput, MarkdownInput, NumberInput, TextInput } from './Defaults';
|
|
9
9
|
import { type InputComponent } from './Input';
|
|
10
10
|
import { GeoPointInput } from './custom';
|
|
11
11
|
|
|
@@ -14,8 +14,10 @@ import { GeoPointInput } from './custom';
|
|
|
14
14
|
*/
|
|
15
15
|
export const getInputComponent = (type: SimpleType, format?: FormatEnum): InputComponent | undefined => {
|
|
16
16
|
switch (format) {
|
|
17
|
-
case FormatEnum.
|
|
17
|
+
case FormatEnum.GeoPoint:
|
|
18
18
|
return GeoPointInput;
|
|
19
|
+
case FormatEnum.Markdown:
|
|
20
|
+
return MarkdownInput;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
switch (type) {
|
|
@@ -21,7 +21,7 @@ const ViewMetaSchema = S.Struct({
|
|
|
21
21
|
name: S.String.annotations({
|
|
22
22
|
[AST.TitleAnnotationId]: 'View',
|
|
23
23
|
}),
|
|
24
|
-
typename: Format.
|
|
24
|
+
typename: Format.URL.annotations({
|
|
25
25
|
[AST.TitleAnnotationId]: 'Typename',
|
|
26
26
|
}),
|
|
27
27
|
}).pipe(S.mutable);
|
|
@@ -103,7 +103,7 @@ export const ViewEditor = ({
|
|
|
103
103
|
|
|
104
104
|
return (
|
|
105
105
|
<div role='none' className={mx('flex flex-col w-full divide-y divide-separator', classNames)}>
|
|
106
|
-
<Form<ViewMetaType>
|
|
106
|
+
<Form<ViewMetaType> autoSave schema={ViewMetaSchema} values={viewValues} onSave={handleViewUpdate} />
|
|
107
107
|
|
|
108
108
|
<div>
|
|
109
109
|
{/* TODO(burdon): Clean up common form ux. */}
|