@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.
Files changed (65) hide show
  1. package/dist/lib/browser/index.mjs +546 -362
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +589 -401
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +546 -362
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +1 -2
  11. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  12. package/dist/types/src/components/Form/ArrayField.d.ts +1 -2
  13. package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
  14. package/dist/types/src/components/Form/Defaults.d.ts +5 -5
  15. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
  16. package/dist/types/src/components/Form/Form.d.ts +2 -2
  17. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  18. package/dist/types/src/components/Form/FormActions.d.ts +1 -2
  19. package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
  20. package/dist/types/src/components/Form/FormContent.d.ts +2 -3
  21. package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
  22. package/dist/types/src/components/Form/FormContext.d.ts +4 -1
  23. package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
  24. package/dist/types/src/components/Form/Input.d.ts +2 -2
  25. package/dist/types/src/components/Form/Input.d.ts.map +1 -1
  26. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +1 -2
  27. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
  28. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +1 -2
  29. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
  30. package/dist/types/src/components/Form/custom/TupleInput.d.ts +1 -2
  31. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
  32. package/dist/types/src/components/Form/factory.d.ts.map +1 -1
  33. package/dist/types/src/components/Form/index.d.ts +2 -0
  34. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  35. package/dist/types/src/components/ViewEditor/Test.stories.d.ts +1 -2
  36. package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -2
  38. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  39. package/dist/types/src/components/deprecated/Form.d.ts +1 -2
  40. package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
  41. package/dist/types/src/components/deprecated/Form.stories.d.ts +1 -2
  42. package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
  43. package/dist/types/src/components/deprecated/FormInput.d.ts +2 -2
  44. package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
  45. package/dist/types/src/components/testing.d.ts +3 -3
  46. package/dist/types/src/components/testing.d.ts.map +1 -1
  47. package/dist/types/src/hooks/useForm.d.ts +1 -0
  48. package/dist/types/src/hooks/useForm.d.ts.map +1 -1
  49. package/dist/types/src/util/field.d.ts.map +1 -1
  50. package/dist/types/src/util/formatting.d.ts.map +1 -1
  51. package/package.json +25 -24
  52. package/src/components/Form/Defaults.tsx +61 -4
  53. package/src/components/Form/Form.tsx +9 -5
  54. package/src/components/Form/FormActions.tsx +1 -1
  55. package/src/components/Form/FormContent.tsx +10 -13
  56. package/src/components/Form/FormContext.tsx +58 -10
  57. package/src/components/Form/custom/GeoPointInput.tsx +42 -12
  58. package/src/components/Form/custom/SelectOptionsInput.tsx +7 -9
  59. package/src/components/Form/factory.tsx +4 -2
  60. package/src/components/Form/index.ts +3 -0
  61. package/src/components/ViewEditor/ViewEditor.tsx +2 -2
  62. package/src/hooks/useForm.ts +69 -40
  63. package/src/translations.ts +1 -1
  64. package/src/util/field.ts +19 -1
  65. 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.e27f9b9",
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.e27f9b9",
32
- "@dxos/echo-db": "0.7.5-labs.e27f9b9",
33
- "@dxos/debug": "0.7.5-labs.e27f9b9",
34
- "@dxos/invariant": "0.7.5-labs.e27f9b9",
35
- "@dxos/effect": "0.7.5-labs.e27f9b9",
36
- "@dxos/keys": "0.7.5-labs.e27f9b9",
37
- "@dxos/echo-schema": "0.7.5-labs.e27f9b9",
38
- "@dxos/live-object": "0.7.5-labs.e27f9b9",
39
- "@dxos/log": "0.7.5-labs.e27f9b9",
40
- "@dxos/react-client": "0.7.5-labs.e27f9b9",
41
- "@dxos/react-ui-list": "0.7.5-labs.e27f9b9",
42
- "@dxos/react-ui-types": "0.7.5-labs.e27f9b9",
43
- "@dxos/react-ui-pickers": "0.7.5-labs.e27f9b9",
44
- "@dxos/schema": "0.7.5-labs.e27f9b9",
45
- "@dxos/util": "0.7.5-labs.e27f9b9"
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.e27f9b9",
58
- "@dxos/random": "0.7.5-labs.e27f9b9",
59
- "@dxos/react-ui-theme": "0.7.5-labs.e27f9b9",
60
- "@dxos/storybook-utils": "0.7.5-labs.e27f9b9",
61
- "@dxos/react-ui": "0.7.5-labs.e27f9b9",
62
- "@dxos/react-ui-syntax-highlighter": "0.7.5-labs.e27f9b9"
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.e27f9b9",
71
- "@dxos/react-ui-theme": "0.7.5-labs.e27f9b9"
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={getValue()} onCheckedChange={(value) => onValueChange(type, value)} />
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
- // TODO(burdon): Hack to select first input.
74
+ // Focus the first input element within this form.
74
75
  useEffect(() => {
75
- if (autoFocus) {
76
- const input = document.querySelector('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
- <div role='none' className={mx('p-2', classNames)} data-testid={testId}>
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
- // TODO(ZaymonFC): We should try to remove this div wrapper.
74
- <div role='none'>
75
- <CustomComponent
76
- type={type}
77
- format={format}
78
- label={label}
79
- inputOnly={inline}
80
- placeholder={placeholder}
81
- disabled={readonly}
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 py-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
- return {
38
- getStatus: () => getStatus(path),
39
- getValue: () => getFormValue(path),
40
- onValueChange: (type: SimpleType, value: any) => onValueChange(path, type, value),
41
- onBlur: () => onTouched(path),
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 = ({ children, ...formOptions }: PropsWithChildren<FormOptions<any>>) => {
46
- const formHandler = useForm(formOptions);
47
- return <FormContext.Provider value={formHandler}>{children}</FormContext.Provider>;
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 [lng = 0, lat = 0] = getValue<GeoPoint>() ?? [];
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='number'
54
+ type='text'
55
+ pattern='^-?[0-9]*\.?[0-9]*$'
27
56
  disabled={disabled}
28
- placeholder={t('placeholder longitude')}
29
- value={lng}
30
- onChange={(event) => onValueChange(type, [lat, safeParseFloat(event.target.value, 0)])}
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='number'
63
+ type='text'
64
+ pattern='^-?[0-9]*\.?[0-9]*$'
35
65
  disabled={disabled}
36
- placeholder={t('placeholder latitude')}
37
- value={lat}
38
- onChange={(event) => onValueChange(type, [safeParseFloat(event.target.value, 0), lng])}
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 { HuePickerToolbarButton } from '@dxos/react-ui-pickers';
12
- import { hueTokenThemes, mx } from '@dxos/react-ui-theme';
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 = hueKeys.filter((hue) => !usedHues.has(hue));
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 = hueKeys.filter((hue) => !lastThree.has(hue));
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
- <HuePickerToolbarButton hue={item.color} onChangeHue={handleColorChange(item.id)} />
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.LatLng:
17
+ case FormatEnum.GeoPoint:
18
18
  return GeoPointInput;
19
+ case FormatEnum.Markdown:
20
+ return MarkdownInput;
19
21
  }
20
22
 
21
23
  switch (type) {
@@ -2,8 +2,11 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { useFormValues } from './FormContext';
6
+
5
7
  export * from './custom';
6
8
 
7
9
  export * from './Defaults';
8
10
  export * from './Form';
9
11
  export * from './Input';
12
+ export { useFormValues };
@@ -21,7 +21,7 @@ const ViewMetaSchema = S.Struct({
21
21
  name: S.String.annotations({
22
22
  [AST.TitleAnnotationId]: 'View',
23
23
  }),
24
- typename: Format.DXN.annotations({
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> autoFocus autoSave schema={ViewMetaSchema} values={viewValues} onSave={handleViewUpdate} />
106
+ <Form<ViewMetaType> autoSave schema={ViewMetaSchema} values={viewValues} onSave={handleViewUpdate} />
107
107
 
108
108
  <div>
109
109
  {/* TODO(burdon): Clean up common form ux. */}