@dxos/react-ui-form 0.7.5-labs.ea4b4c2 → 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 +299 -115
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +324 -139
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +299 -115
- package/dist/lib/node-esm/index.mjs.map +3 -3
- 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/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 +59 -3
- package/src/components/Form/Form.tsx +8 -5
- package/src/components/Form/FormContent.tsx +9 -12
- 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/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/src/util/field.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { FormatEnum, TypeEnum } from '@dxos/echo-schema';
|
|
5
|
+
import { FormatEnum, GeoLocation, TypeEnum } from '@dxos/echo-schema';
|
|
6
6
|
import { type ValidationError } from '@dxos/schema';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -81,6 +81,24 @@ export const parseValue = ({ type, format, value }: ParseProps) => {
|
|
|
81
81
|
return isNaN(date.getTime()) ? null : date;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
case FormatEnum.GeoPoint: {
|
|
85
|
+
// Parse string in format "lat,long" to GeoPoint [longitude, latitude].
|
|
86
|
+
if (typeof value === 'string') {
|
|
87
|
+
// Only keep digits, decimal points, minus signs, and commas.
|
|
88
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, '');
|
|
89
|
+
const parts = cleaned.split(',');
|
|
90
|
+
if (parts.length === 2) {
|
|
91
|
+
const lat = parseFloat(parts[0]);
|
|
92
|
+
const long = parseFloat(parts[1]);
|
|
93
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
94
|
+
return GeoLocation.toGeoPoint({ latitude: lat, longitude: long });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [0, 0];
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
default: {
|
|
85
103
|
return value;
|
|
86
104
|
}
|
package/src/util/formatting.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { FormatEnum, TypeEnum } from '@dxos/echo-schema';
|
|
5
|
+
import { FormatEnum, GeoLocation, TypeEnum } from '@dxos/echo-schema';
|
|
6
6
|
|
|
7
7
|
type ValueFormatProps = {
|
|
8
8
|
type: TypeEnum;
|
|
@@ -73,6 +73,19 @@ export const formatForDisplay = ({ type, format, value, locale = undefined }: Va
|
|
|
73
73
|
return date.toLocaleTimeString(locale);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
case FormatEnum.GeoPoint: {
|
|
77
|
+
if (value === null || value === undefined) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// For GeoPoint format [longitude, latitude].
|
|
82
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
83
|
+
const { latitude, longitude } = GeoLocation.fromGeoPoint(value as [number, number]);
|
|
84
|
+
return `${latitude},${longitude}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
76
89
|
default: {
|
|
77
90
|
if (value === null || value === 'undefined') {
|
|
78
91
|
return '';
|
|
@@ -125,6 +138,21 @@ export const formatForEditing = ({ type, format, value, locale = undefined }: Va
|
|
|
125
138
|
const date = new Date(value as number);
|
|
126
139
|
return date.toISOString().split('T')[1].split('.')[0];
|
|
127
140
|
}
|
|
141
|
+
case FormatEnum.GeoPoint: {
|
|
142
|
+
// Handle null or undefined
|
|
143
|
+
if (value === null || value === undefined) {
|
|
144
|
+
return '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// For GeoPoint format [longitude, latitude].
|
|
148
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
149
|
+
const { latitude, longitude } = GeoLocation.fromGeoPoint(value as [number, number]);
|
|
150
|
+
return `${latitude},${longitude}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return String(value);
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
default: {
|
|
129
157
|
return String(value);
|
|
130
158
|
}
|