@dxos/react-ui-form 0.7.5-feature-compute.4d9d99a → 0.7.5-labs.401163d
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 +881 -556
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +910 -596
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +881 -556
- 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 +16 -0
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/Defaults.d.ts +6 -6
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +12 -21
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +2 -1
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts +7 -0
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormContent.d.ts +26 -0
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormContext.d.ts +23 -0
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Input.d.ts +5 -6
- 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 +4 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +7 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -0
- 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/custom/index.d.ts +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +2 -2
- 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/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +5 -0
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +10 -10
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -24
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.tsx +7 -6
- package/src/components/Form/ArrayField.tsx +111 -0
- package/src/components/Form/Defaults.tsx +78 -36
- package/src/components/Form/Form.stories.tsx +15 -5
- package/src/components/Form/Form.tsx +50 -355
- package/src/components/Form/FormActions.tsx +41 -0
- package/src/components/Form/FormContent.tsx +170 -0
- package/src/components/Form/FormContext.tsx +92 -0
- package/src/components/Form/Input.tsx +5 -6
- package/src/components/Form/custom/GeoPointInput.tsx +6 -15
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +58 -0
- package/src/components/Form/custom/SelectOptionsInput.tsx +190 -0
- package/src/components/Form/custom/TupleInput.tsx +5 -9
- package/src/components/Form/custom/index.ts +1 -0
- package/src/components/Form/factory.tsx +5 -6
- package/src/components/Form/index.ts +3 -0
- package/src/components/ViewEditor/ViewEditor.tsx +7 -4
- package/src/components/deprecated/FormInput.tsx +20 -7
- package/src/hooks/useForm.ts +60 -47
- package/src/translations.ts +8 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { createContext, useContext, useEffect, type FocusEvent, type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
import { type BaseObject, getValue } from '@dxos/echo-schema';
|
|
9
|
+
import { createJsonPath, type SimpleType } from '@dxos/effect';
|
|
10
|
+
|
|
11
|
+
import { type FormHandler, type FormOptions, useForm } from '../../hooks';
|
|
12
|
+
|
|
13
|
+
type FormContextValue<T extends BaseObject> = FormHandler<T>;
|
|
14
|
+
|
|
15
|
+
const FormContext = createContext<FormContextValue<any> | undefined>(undefined);
|
|
16
|
+
|
|
17
|
+
export const useFormContext = <T extends BaseObject>(): FormContextValue<T> => {
|
|
18
|
+
return useContext(FormContext) ?? raise(new Error('Missing FormContext'));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useFormValues = (path: (string | number)[] = []): any => {
|
|
22
|
+
const { values: formValues } = useFormContext();
|
|
23
|
+
const jsonPath = createJsonPath(path);
|
|
24
|
+
return getValue(formValues, jsonPath) as BaseObject;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type FormInputStateProps = {
|
|
28
|
+
getStatus: () => { status?: 'error'; error?: string };
|
|
29
|
+
getValue: <V>() => V | undefined;
|
|
30
|
+
onValueChange: (type: SimpleType, value: any) => void;
|
|
31
|
+
onBlur: (event: FocusEvent<HTMLElement>) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const useInputProps = (path: (string | number)[] = []): FormInputStateProps => {
|
|
35
|
+
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
getStatus: () => getStatus(path),
|
|
39
|
+
getValue: () => getFormValue(path),
|
|
40
|
+
onValueChange: (type: SimpleType, value: any) => onValueChange(path, type, value),
|
|
41
|
+
onBlur: () => onTouched(path),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const FormProvider = ({
|
|
46
|
+
children,
|
|
47
|
+
formRef,
|
|
48
|
+
autoSave,
|
|
49
|
+
...formOptions
|
|
50
|
+
}: PropsWithChildren<
|
|
51
|
+
FormOptions<any> & {
|
|
52
|
+
formRef?: React.RefObject<HTMLDivElement>;
|
|
53
|
+
autoSave?: boolean;
|
|
54
|
+
}
|
|
55
|
+
>) => {
|
|
56
|
+
const form = useForm(formOptions);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!formRef?.current) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
64
|
+
const keyIsEnter = event.key === 'Enter';
|
|
65
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
66
|
+
const inputIsTextarea = (event.target as HTMLElement).tagName.toLowerCase() === 'textarea';
|
|
67
|
+
const inputOptOut = (event.target as HTMLElement).hasAttribute('data-no-submit');
|
|
68
|
+
|
|
69
|
+
// Regular inputs: Submit on Enter (no modifiers).
|
|
70
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
71
|
+
|
|
72
|
+
// Textareas: Submit only on Meta+Enter.
|
|
73
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
74
|
+
|
|
75
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
76
|
+
if (!autoSave && form.canSave) {
|
|
77
|
+
form.handleSave();
|
|
78
|
+
}
|
|
79
|
+
if (autoSave && form.formIsValid) {
|
|
80
|
+
(event.target as HTMLElement).blur();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const formElement = formRef.current;
|
|
86
|
+
|
|
87
|
+
formElement.addEventListener('keydown', handleKeyDown);
|
|
88
|
+
return () => formElement.removeEventListener('keydown', handleKeyDown);
|
|
89
|
+
}, [formRef, form.canSave, form.formIsValid, form.handleSave, autoSave]);
|
|
90
|
+
|
|
91
|
+
return <FormContext.Provider value={form}>{children}</FormContext.Provider>;
|
|
92
|
+
};
|
|
@@ -4,30 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type FC, type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type FormatEnum } from '@dxos/echo-schema';
|
|
8
8
|
import { type SimpleType } from '@dxos/effect';
|
|
9
9
|
import { Icon, Tooltip } from '@dxos/react-ui';
|
|
10
10
|
import { errorText } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import { type
|
|
12
|
+
import { type FormInputStateProps } from './FormContext';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Props passed to input components.
|
|
16
16
|
*/
|
|
17
|
-
export type InputProps
|
|
18
|
-
property: PropertyKey<T>;
|
|
17
|
+
export type InputProps = {
|
|
19
18
|
type: SimpleType;
|
|
20
19
|
format?: FormatEnum;
|
|
21
20
|
label?: string;
|
|
22
21
|
disabled?: boolean;
|
|
23
22
|
placeholder?: string;
|
|
24
23
|
inputOnly?: boolean;
|
|
25
|
-
} &
|
|
24
|
+
} & FormInputStateProps;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Form input component.
|
|
29
28
|
*/
|
|
30
|
-
export type InputComponent
|
|
29
|
+
export type InputComponent = FC<InputProps>;
|
|
31
30
|
|
|
32
31
|
export type InputHeaderProps = PropsWithChildren<{
|
|
33
32
|
error?: string;
|
|
@@ -4,26 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type GeoPoint } from '@dxos/echo-schema';
|
|
8
8
|
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { safeParseFloat } from '@dxos/util';
|
|
10
10
|
|
|
11
11
|
import { translationKey } from '../../../translations';
|
|
12
12
|
import { InputHeader, type InputProps } from '../Input';
|
|
13
13
|
|
|
14
|
-
export const GeoPointInput =
|
|
15
|
-
property,
|
|
16
|
-
type,
|
|
17
|
-
label,
|
|
18
|
-
disabled,
|
|
19
|
-
getStatus,
|
|
20
|
-
getValue,
|
|
21
|
-
onValueChange,
|
|
22
|
-
onBlur,
|
|
23
|
-
}: InputProps<T>) => {
|
|
14
|
+
export const GeoPointInput = ({ type, label, disabled, getStatus, getValue, onValueChange, onBlur }: InputProps) => {
|
|
24
15
|
const { t } = useTranslation(translationKey);
|
|
25
|
-
const { status, error } = getStatus
|
|
26
|
-
const [lng = 0, lat = 0] = getValue<GeoPoint>(
|
|
16
|
+
const { status, error } = getStatus();
|
|
17
|
+
const [lng = 0, lat = 0] = getValue<GeoPoint>() ?? [];
|
|
27
18
|
|
|
28
19
|
return (
|
|
29
20
|
<Input.Root validationValence={status}>
|
|
@@ -36,7 +27,7 @@ export const GeoPointInput = <T extends BaseObject>({
|
|
|
36
27
|
disabled={disabled}
|
|
37
28
|
placeholder={t('placeholder longitude')}
|
|
38
29
|
value={lng}
|
|
39
|
-
onChange={(event) => onValueChange(
|
|
30
|
+
onChange={(event) => onValueChange(type, [lat, safeParseFloat(event.target.value, 0)])}
|
|
40
31
|
onBlur={onBlur}
|
|
41
32
|
/>
|
|
42
33
|
<Input.TextInput
|
|
@@ -44,7 +35,7 @@ export const GeoPointInput = <T extends BaseObject>({
|
|
|
44
35
|
disabled={disabled}
|
|
45
36
|
placeholder={t('placeholder latitude')}
|
|
46
37
|
value={lat}
|
|
47
|
-
onChange={(event) => onValueChange(
|
|
38
|
+
onChange={(event) => onValueChange(type, [safeParseFloat(event.target.value, 0), lng])}
|
|
48
39
|
onBlur={onBlur}
|
|
49
40
|
/>
|
|
50
41
|
</div>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react';
|
|
8
|
+
import React, { useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { S, SelectOptionSchema, type SelectOption } from '@dxos/echo-schema';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import { SelectOptionInput } from './SelectOptionsInput';
|
|
14
|
+
import translations from '../../../translations';
|
|
15
|
+
import { TestLayout, TestPanel } from '../../testing';
|
|
16
|
+
import { Form } from '../Form';
|
|
17
|
+
|
|
18
|
+
const schema = S.Struct({
|
|
19
|
+
options: S.Array(SelectOptionSchema).pipe(S.mutable),
|
|
20
|
+
}).pipe(S.mutable);
|
|
21
|
+
|
|
22
|
+
const DefaultStory = () => {
|
|
23
|
+
const [values, setValues] = useState<{ options: SelectOption[] }>({
|
|
24
|
+
// TODO(Zaymon): Pick colors from our limited set.
|
|
25
|
+
options: [
|
|
26
|
+
{ id: 'opt_1', title: 'First option', color: 'amber' },
|
|
27
|
+
{ id: 'opt_2', title: 'Second option', color: 'emerald' },
|
|
28
|
+
{ id: 'opt_3', title: 'Third option', color: 'rose' },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<TestLayout>
|
|
34
|
+
<TestPanel>
|
|
35
|
+
<Form
|
|
36
|
+
schema={schema}
|
|
37
|
+
values={values}
|
|
38
|
+
onSave={(vals) => setValues(vals)}
|
|
39
|
+
Custom={{ options: SelectOptionInput }}
|
|
40
|
+
/>
|
|
41
|
+
</TestPanel>
|
|
42
|
+
</TestLayout>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const meta: Meta = {
|
|
47
|
+
title: 'ui/react-ui-form/SelectOptionsInput',
|
|
48
|
+
component: SelectOptionInput,
|
|
49
|
+
decorators: [withTheme, withLayout({ tooltips: true })],
|
|
50
|
+
parameters: { translations },
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
type Story = StoryObj;
|
|
55
|
+
|
|
56
|
+
export const Default: Story = {
|
|
57
|
+
render: DefaultStory,
|
|
58
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useEffect, useState, type ChangeEvent, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type SelectOption } from '@dxos/echo-schema';
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import { type ChromaticPalette, Icon, IconButton, Input, Tag, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { List } from '@dxos/react-ui-list';
|
|
11
|
+
import { HuePickerToolbarButton } from '@dxos/react-ui-pickers';
|
|
12
|
+
import { hues, mx } from '@dxos/react-ui-theme';
|
|
13
|
+
|
|
14
|
+
import { translationKey } from '../../../translations';
|
|
15
|
+
import { InputHeader, type InputProps } from '../Input';
|
|
16
|
+
|
|
17
|
+
// TODO(ZaymonFC): Handle disabled.
|
|
18
|
+
export const SelectOptionInput = ({ type, label, disabled, getStatus, getValue, onValueChange }: InputProps) => {
|
|
19
|
+
const [selected, setSelectedId] = useState<string | null>(null);
|
|
20
|
+
const [isNewOption, setIsNewOption] = useState(false);
|
|
21
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
22
|
+
const { t } = useTranslation(translationKey);
|
|
23
|
+
const { status, error } = getStatus();
|
|
24
|
+
const options = getValue<SelectOption[] | undefined>();
|
|
25
|
+
|
|
26
|
+
// Initialization.
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (options === undefined) {
|
|
29
|
+
onValueChange(type, []);
|
|
30
|
+
}
|
|
31
|
+
}, [options, onValueChange, type]);
|
|
32
|
+
|
|
33
|
+
const randomHue = () => {
|
|
34
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
35
|
+
// Pick a random unused option from hueTokenThemes.
|
|
36
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
37
|
+
if (unusedHues.length > 0) {
|
|
38
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Pick a random one that hasn't been used in the last three options
|
|
42
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
43
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
44
|
+
return (
|
|
45
|
+
availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)]
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleAdd = useCallback(() => {
|
|
50
|
+
const newId = PublicKey.random().truncate();
|
|
51
|
+
const newOption = { id: newId, title: '', color: randomHue() };
|
|
52
|
+
onValueChange(type, [...(options ?? []), newOption]);
|
|
53
|
+
setSelectedId(newId);
|
|
54
|
+
setIsNewOption(true);
|
|
55
|
+
}, [options, type, onValueChange]);
|
|
56
|
+
|
|
57
|
+
const handleDelete = useCallback(
|
|
58
|
+
(id: string) => {
|
|
59
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
60
|
+
onValueChange(type, newOptions);
|
|
61
|
+
setSelectedId(null);
|
|
62
|
+
},
|
|
63
|
+
[options, type, onValueChange],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const handleMove = useCallback(
|
|
67
|
+
(from: number, to: number) => {
|
|
68
|
+
if (!options) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const newOptions = [...options];
|
|
73
|
+
const [removed] = newOptions.splice(from, 1);
|
|
74
|
+
newOptions.splice(to, 0, removed);
|
|
75
|
+
onValueChange(type, newOptions);
|
|
76
|
+
},
|
|
77
|
+
[options, type, onValueChange],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const handleClick = useCallback((id: string) => {
|
|
81
|
+
setSelectedId((current) => (current === id ? null : id));
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
const handleTitleChange = useCallback(
|
|
85
|
+
(id: string) => (e: ChangeEvent<HTMLInputElement>) => {
|
|
86
|
+
const newOptions = options?.map((o) => (o.id === id ? { ...o, title: e.target.value } : o));
|
|
87
|
+
onValueChange(type, newOptions ?? []);
|
|
88
|
+
},
|
|
89
|
+
[options, type, onValueChange],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
93
|
+
if (e.key === 'Enter') {
|
|
94
|
+
setSelectedId(null);
|
|
95
|
+
}
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const handleColorChange = useCallback(
|
|
99
|
+
(id: string) => (hue: string) => {
|
|
100
|
+
const newOptions = options?.map((o) => (o.id === id ? { ...o, color: hue } : o));
|
|
101
|
+
onValueChange(type, newOptions ?? []);
|
|
102
|
+
},
|
|
103
|
+
[options, type, onValueChange],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (selected && isNewOption && inputRef.current) {
|
|
108
|
+
inputRef.current.focus();
|
|
109
|
+
setIsNewOption(false);
|
|
110
|
+
}
|
|
111
|
+
}, [selected, isNewOption]);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Input.Root validationValence={status}>
|
|
115
|
+
<InputHeader error={error}>
|
|
116
|
+
<Input.Label>{label}</Input.Label>
|
|
117
|
+
</InputHeader>
|
|
118
|
+
<div role='none'>
|
|
119
|
+
{options && (
|
|
120
|
+
<List.Root items={options} isItem={(item) => true} onMove={handleMove}>
|
|
121
|
+
{({ items }) => (
|
|
122
|
+
<div role='list' className='w-full overflow-auto'>
|
|
123
|
+
{items?.map((item) => (
|
|
124
|
+
<div key={item.id}>
|
|
125
|
+
<List.Item
|
|
126
|
+
role='button'
|
|
127
|
+
item={item}
|
|
128
|
+
classNames={mx('p-1 plb-2', 'flex flex-col', 'cursor-pointer', 'hover:bg-hoverOverlay')}
|
|
129
|
+
aria-expanded={selected === item.id}
|
|
130
|
+
>
|
|
131
|
+
<div className='flex items-center'>
|
|
132
|
+
<List.ItemDragHandle />
|
|
133
|
+
<List.ItemTitle onClick={() => handleClick(item.id)} classNames='flex-1'>
|
|
134
|
+
{/* TODO(ZaymonFC): Move spacer into Tag component. */}
|
|
135
|
+
<Tag palette={item.color as ChromaticPalette}>{item.title || '\u200b'}</Tag>
|
|
136
|
+
</List.ItemTitle>
|
|
137
|
+
<Icon
|
|
138
|
+
icon={selected === item.id ? 'ph--caret-down--regular' : 'ph--caret-right--regular'}
|
|
139
|
+
onClick={() => handleClick(item.id)}
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
{selected === item.id && (
|
|
143
|
+
<div className='mis-4 mbs-2 flex flex-col gap-1'>
|
|
144
|
+
{/* 16px to match drag handle width. */}
|
|
145
|
+
<Input.Label classNames='text-xs'>{t('select option label')}</Input.Label>
|
|
146
|
+
<div className='flex flex-row items-center gap-1'>
|
|
147
|
+
<Input.TextInput
|
|
148
|
+
placeholder={t('select option label placeholder')}
|
|
149
|
+
ref={selected === item.id ? inputRef : undefined}
|
|
150
|
+
value={item.title}
|
|
151
|
+
onChange={handleTitleChange(item.id)}
|
|
152
|
+
onKeyDown={handleKeyDown}
|
|
153
|
+
classNames='flex-1'
|
|
154
|
+
data-no-submit
|
|
155
|
+
/>
|
|
156
|
+
<Toolbar.Root classNames='p-0 m-0 !is-auto'>
|
|
157
|
+
<HuePickerToolbarButton hue={item.color} onChangeHue={handleColorChange(item.id)} />
|
|
158
|
+
</Toolbar.Root>
|
|
159
|
+
<IconButton
|
|
160
|
+
icon='ph--trash--fill'
|
|
161
|
+
iconOnly
|
|
162
|
+
label={t('select option delete')}
|
|
163
|
+
onClick={() => handleDelete(item.id)}
|
|
164
|
+
/>
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
</List.Item>
|
|
169
|
+
</div>
|
|
170
|
+
))}
|
|
171
|
+
<div role='listitem'>
|
|
172
|
+
<div
|
|
173
|
+
role='button'
|
|
174
|
+
className={mx('p-1 plb-2', 'flex flex-col', 'cursor-pointer', 'hover:bg-hoverOverlay')}
|
|
175
|
+
onClick={handleAdd}
|
|
176
|
+
>
|
|
177
|
+
<div className='flex items-center gap-1'>
|
|
178
|
+
<Icon icon='ph--plus--regular' />
|
|
179
|
+
<span className='text-sm'>{t('select option add')}</span>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
)}
|
|
185
|
+
</List.Root>
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
</Input.Root>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type BaseObject } from '@dxos/echo-schema';
|
|
8
7
|
import { Input } from '@dxos/react-ui';
|
|
9
8
|
import { mx } from '@dxos/react-ui-theme';
|
|
10
9
|
import { safeParseFloat } from '@dxos/util';
|
|
@@ -13,9 +12,8 @@ import { InputHeader, type InputProps } from '../Input';
|
|
|
13
12
|
|
|
14
13
|
const gridCols = ['grid-cols-1', 'grid-cols-2', 'grid-cols-3', 'grid-cols-4'];
|
|
15
14
|
|
|
16
|
-
export const TupleInput =
|
|
15
|
+
export const TupleInput = ({
|
|
17
16
|
binding,
|
|
18
|
-
property,
|
|
19
17
|
type,
|
|
20
18
|
label,
|
|
21
19
|
disabled,
|
|
@@ -23,11 +21,11 @@ export const TupleInput = <T extends BaseObject>({
|
|
|
23
21
|
getValue,
|
|
24
22
|
onValueChange,
|
|
25
23
|
onBlur,
|
|
26
|
-
}: InputProps
|
|
27
|
-
const { status, error } = getStatus
|
|
24
|
+
}: InputProps & { binding: string[] }) => {
|
|
25
|
+
const { status, error } = getStatus();
|
|
28
26
|
|
|
29
27
|
// TODO(burdon): Generalize number/float/string, etc.
|
|
30
|
-
const values: Record<string, number> = getValue<Record<string, number>>(
|
|
28
|
+
const values: Record<string, number> = getValue<Record<string, number>>() ?? {};
|
|
31
29
|
|
|
32
30
|
return (
|
|
33
31
|
<Input.Root validationValence={status}>
|
|
@@ -41,9 +39,7 @@ export const TupleInput = <T extends BaseObject>({
|
|
|
41
39
|
type='number'
|
|
42
40
|
disabled={disabled}
|
|
43
41
|
value={values[prop]}
|
|
44
|
-
onChange={(event) =>
|
|
45
|
-
onValueChange(property, type, { ...values, [prop]: safeParseFloat(event.target.value, 0) })
|
|
46
|
-
}
|
|
42
|
+
onChange={(event) => onValueChange(type, { ...values, [prop]: safeParseFloat(event.target.value, 0) })}
|
|
47
43
|
onBlur={onBlur}
|
|
48
44
|
/>
|
|
49
45
|
))}
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
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
|
|
|
12
12
|
/**
|
|
13
13
|
* Get property input component.
|
|
14
14
|
*/
|
|
15
|
-
export const getInputComponent =
|
|
16
|
-
type: SimpleType,
|
|
17
|
-
format?: FormatEnum,
|
|
18
|
-
): InputComponent<T> | undefined => {
|
|
15
|
+
export const getInputComponent = (type: SimpleType, format?: FormatEnum): InputComponent | undefined => {
|
|
19
16
|
switch (format) {
|
|
20
17
|
case FormatEnum.LatLng:
|
|
21
18
|
return GeoPointInput;
|
|
19
|
+
case FormatEnum.Markdown:
|
|
20
|
+
return MarkdownInput;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
switch (type) {
|
|
@@ -10,7 +10,6 @@ import { IconButton, type ThemedClassName, useTranslation } from '@dxos/react-ui
|
|
|
10
10
|
import { List } from '@dxos/react-ui-list';
|
|
11
11
|
import { ghostHover, inputTextLabel, mx } from '@dxos/react-ui-theme';
|
|
12
12
|
import { FieldSchema, type FieldType, type ViewType, ViewProjection, VIEW_FIELD_LIMIT } from '@dxos/schema';
|
|
13
|
-
import { arrayMove } from '@dxos/util';
|
|
14
13
|
|
|
15
14
|
import { translationKey } from '../../translations';
|
|
16
15
|
import { FieldEditor } from '../FieldEditor';
|
|
@@ -22,7 +21,7 @@ const ViewMetaSchema = S.Struct({
|
|
|
22
21
|
name: S.String.annotations({
|
|
23
22
|
[AST.TitleAnnotationId]: 'View',
|
|
24
23
|
}),
|
|
25
|
-
typename: Format.
|
|
24
|
+
typename: Format.URL.annotations({
|
|
26
25
|
[AST.TitleAnnotationId]: 'Typename',
|
|
27
26
|
}),
|
|
28
27
|
}).pipe(S.mutable);
|
|
@@ -91,7 +90,11 @@ export const ViewEditor = ({
|
|
|
91
90
|
|
|
92
91
|
const handleMove = useCallback(
|
|
93
92
|
(fromIndex: number, toIndex: number) => {
|
|
94
|
-
|
|
93
|
+
// NOTE(ZaymonFC): Using arrayMove here causes a race condition with the kanban model.
|
|
94
|
+
const fields = [...view.fields];
|
|
95
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
96
|
+
fields.splice(toIndex, 0, moved);
|
|
97
|
+
view.fields = fields;
|
|
95
98
|
},
|
|
96
99
|
[view.fields],
|
|
97
100
|
);
|
|
@@ -100,7 +103,7 @@ export const ViewEditor = ({
|
|
|
100
103
|
|
|
101
104
|
return (
|
|
102
105
|
<div role='none' className={mx('flex flex-col w-full divide-y divide-separator', classNames)}>
|
|
103
|
-
<Form<ViewMetaType>
|
|
106
|
+
<Form<ViewMetaType> autoSave schema={ViewMetaSchema} values={viewValues} onSave={handleViewUpdate} />
|
|
104
107
|
|
|
105
108
|
<div>
|
|
106
109
|
{/* TODO(burdon): Clean up common form ux. */}
|
|
@@ -4,7 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type JSX, type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
|
-
import { Input } from '@dxos/react-ui';
|
|
7
|
+
import { Input, type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
+
import { mx, textBlockWidth } from '@dxos/react-ui-theme';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
export const DeprecatedFormContainer = ({ children, classNames }: ThemedClassName<PropsWithChildren>) => {
|
|
14
|
+
return (
|
|
15
|
+
<div role='none' className='w-full p-4 justify-center overflow-x-hidden overflow-y-auto'>
|
|
16
|
+
<div role='form' className={mx('flex flex-col', textBlockWidth, classNames)}>
|
|
17
|
+
{children}
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
8
22
|
|
|
9
23
|
export type DeprecatedFormInputProps = {
|
|
10
24
|
label: string;
|
|
@@ -15,7 +29,6 @@ export type DeprecatedFormInputProps = {
|
|
|
15
29
|
/**
|
|
16
30
|
* @deprecated
|
|
17
31
|
*/
|
|
18
|
-
// TODO(burdon): Still used in ObservabilitySettings and all settings.
|
|
19
32
|
export const DeprecatedFormInput = ({
|
|
20
33
|
label,
|
|
21
34
|
description,
|
|
@@ -26,8 +39,9 @@ export const DeprecatedFormInput = ({
|
|
|
26
39
|
<div role='none' className='flex w-full gap-4 py-1'>
|
|
27
40
|
<Input.Root>
|
|
28
41
|
<div role='none' className='flex flex-col w-full'>
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
<Input.Label classNames='flex min-bs-[--rail-action] items-center' style={{ fontSize: 'unset' }}>
|
|
43
|
+
{label}
|
|
44
|
+
</Input.Label>
|
|
31
45
|
{description && (
|
|
32
46
|
<Input.DescriptionAndValidation classNames='mbs-0.5'>
|
|
33
47
|
<Input.Description>{description}</Input.Description>
|
|
@@ -36,7 +50,7 @@ export const DeprecatedFormInput = ({
|
|
|
36
50
|
</div>
|
|
37
51
|
|
|
38
52
|
<div role='none'>
|
|
39
|
-
<div role='none' className='flex min-
|
|
53
|
+
<div role='none' className='flex min-bs-[--rail-action] items-center'>
|
|
40
54
|
{children}
|
|
41
55
|
</div>
|
|
42
56
|
</div>
|
|
@@ -45,9 +59,8 @@ export const DeprecatedFormInput = ({
|
|
|
45
59
|
);
|
|
46
60
|
|
|
47
61
|
if (secondary) {
|
|
48
|
-
// console.log(secondary);
|
|
49
62
|
return (
|
|
50
|
-
<div role='none'
|
|
63
|
+
<div role='none'>
|
|
51
64
|
{primary}
|
|
52
65
|
{secondary}
|
|
53
66
|
</div>
|