@dxos/react-ui-form 0.7.5-main.b19bfc8 → 0.7.5-main.d9d2d4e
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 +65 -35
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +48 -18
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +65 -35
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/Form/FormContext.tsx +11 -7
- package/src/components/ViewEditor/ViewEditor.stories.tsx +3 -3
- package/src/components/ViewEditor/ViewEditor.tsx +2 -2
- package/src/hooks/useForm.ts +64 -41
|
@@ -99,14 +99,14 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
102
|
-
import React12, { useCallback as useCallback6, useEffect as useEffect7, useMemo as
|
|
102
|
+
import React12, { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo7, useState as useState4 } from "react";
|
|
103
103
|
import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
104
104
|
import { log as log2 } from "@dxos/log";
|
|
105
105
|
import { useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
106
106
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
|
|
107
107
|
|
|
108
108
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
109
|
-
import React2, { createContext, useContext, useEffect as useEffect2 } from "react";
|
|
109
|
+
import React2, { createContext, useContext, useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
110
110
|
import { raise } from "@dxos/debug";
|
|
111
111
|
import { getValue as getValue2 } from "@dxos/echo-schema";
|
|
112
112
|
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
@@ -170,7 +170,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
170
170
|
}, [
|
|
171
171
|
errors
|
|
172
172
|
]);
|
|
173
|
-
const canSave = useMemo(() => !saving && // Check if any error paths that are touched have errors
|
|
173
|
+
const canSave = useMemo(() => !saving && // Check if any error paths that are touched have errors.
|
|
174
174
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
175
175
|
touched,
|
|
176
176
|
errors,
|
|
@@ -203,10 +203,12 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
203
203
|
}, [
|
|
204
204
|
errors
|
|
205
205
|
]);
|
|
206
|
-
const getFormValue = (path) => {
|
|
206
|
+
const getFormValue = useCallback((path) => {
|
|
207
207
|
return getValue(values, createJsonPath(path));
|
|
208
|
-
}
|
|
209
|
-
|
|
208
|
+
}, [
|
|
209
|
+
values
|
|
210
|
+
]);
|
|
211
|
+
const onValueChange = useCallback((path, type, value) => {
|
|
210
212
|
const jsonPath = createJsonPath(path);
|
|
211
213
|
let parsedValue = value;
|
|
212
214
|
try {
|
|
@@ -216,7 +218,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
216
218
|
} catch (err) {
|
|
217
219
|
log.catch(err, void 0, {
|
|
218
220
|
F: __dxlog_file,
|
|
219
|
-
L:
|
|
221
|
+
L: 202,
|
|
220
222
|
S: void 0,
|
|
221
223
|
C: (f, a) => f(...a)
|
|
222
224
|
});
|
|
@@ -237,7 +239,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
237
239
|
changed
|
|
238
240
|
});
|
|
239
241
|
}
|
|
240
|
-
}
|
|
242
|
+
}, [
|
|
243
|
+
values,
|
|
244
|
+
onValuesChanged,
|
|
245
|
+
validate,
|
|
246
|
+
onValid,
|
|
247
|
+
changed
|
|
248
|
+
]);
|
|
241
249
|
const onTouched = useCallback((path) => {
|
|
242
250
|
const jsonPath = createJsonPath(path);
|
|
243
251
|
setTouched((touched2) => ({
|
|
@@ -249,26 +257,39 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
249
257
|
validate,
|
|
250
258
|
values
|
|
251
259
|
]);
|
|
252
|
-
return {
|
|
260
|
+
return useMemo(() => ({
|
|
253
261
|
// State.
|
|
254
262
|
values,
|
|
255
263
|
errors,
|
|
256
264
|
touched,
|
|
257
265
|
changed,
|
|
258
266
|
canSave,
|
|
259
|
-
handleSave,
|
|
260
267
|
formIsValid,
|
|
268
|
+
// Actions.
|
|
269
|
+
handleSave,
|
|
261
270
|
// Field utils.
|
|
262
271
|
getStatus,
|
|
263
272
|
getValue: getFormValue,
|
|
264
273
|
onValueChange,
|
|
265
274
|
onTouched
|
|
266
|
-
}
|
|
275
|
+
}), [
|
|
276
|
+
values,
|
|
277
|
+
errors,
|
|
278
|
+
touched,
|
|
279
|
+
changed,
|
|
280
|
+
canSave,
|
|
281
|
+
formIsValid,
|
|
282
|
+
handleSave,
|
|
283
|
+
getStatus,
|
|
284
|
+
getFormValue,
|
|
285
|
+
onValueChange,
|
|
286
|
+
onTouched
|
|
287
|
+
]);
|
|
267
288
|
};
|
|
268
289
|
var createKeySet = (obj, value) => {
|
|
269
290
|
invariant(obj, void 0, {
|
|
270
291
|
F: __dxlog_file,
|
|
271
|
-
L:
|
|
292
|
+
L: 264,
|
|
272
293
|
S: void 0,
|
|
273
294
|
A: [
|
|
274
295
|
"obj",
|
|
@@ -302,12 +323,21 @@ var useFormValues = (path = []) => {
|
|
|
302
323
|
};
|
|
303
324
|
var useInputProps = (path = []) => {
|
|
304
325
|
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
const stablePath = useMemo2(() => path, [
|
|
327
|
+
Array.isArray(path) ? path.join(".") : path
|
|
328
|
+
]);
|
|
329
|
+
return useMemo2(() => ({
|
|
330
|
+
getStatus: () => getStatus(stablePath),
|
|
331
|
+
getValue: () => getFormValue(stablePath),
|
|
332
|
+
onValueChange: (type, value) => onValueChange(stablePath, type, value),
|
|
333
|
+
onBlur: () => onTouched(stablePath)
|
|
334
|
+
}), [
|
|
335
|
+
getStatus,
|
|
336
|
+
getFormValue,
|
|
337
|
+
onValueChange,
|
|
338
|
+
onTouched,
|
|
339
|
+
stablePath
|
|
340
|
+
]);
|
|
311
341
|
};
|
|
312
342
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
313
343
|
const form = useForm(formOptions);
|
|
@@ -347,7 +377,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
347
377
|
};
|
|
348
378
|
|
|
349
379
|
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
350
|
-
import React4, { useCallback as useCallback2, useState as useState2, useEffect as useEffect3, useMemo as
|
|
380
|
+
import React4, { useCallback as useCallback2, useState as useState2, useEffect as useEffect3, useMemo as useMemo3 } from "react";
|
|
351
381
|
import { GeoLocation } from "@dxos/echo-schema";
|
|
352
382
|
import { Input as Input2, useTranslation } from "@dxos/react-ui";
|
|
353
383
|
import { safeParseFloat } from "@dxos/util";
|
|
@@ -375,13 +405,13 @@ var InputHeader = ({ children, error }) => {
|
|
|
375
405
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
376
406
|
const { t } = useTranslation(translationKey);
|
|
377
407
|
const { status, error } = getStatus();
|
|
378
|
-
const geoPoint =
|
|
408
|
+
const geoPoint = useMemo3(() => getValue3() ?? [
|
|
379
409
|
0,
|
|
380
410
|
0
|
|
381
411
|
], [
|
|
382
412
|
getValue3
|
|
383
413
|
]);
|
|
384
|
-
const geoLocation =
|
|
414
|
+
const geoLocation = useMemo3(() => GeoLocation.fromGeoPoint(geoPoint), [
|
|
385
415
|
geoPoint
|
|
386
416
|
]);
|
|
387
417
|
const [longitudeText, setLongitudeText] = useState2(geoLocation.longitude?.toString());
|
|
@@ -764,7 +794,7 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
|
|
|
764
794
|
};
|
|
765
795
|
|
|
766
796
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
767
|
-
import React11, { useEffect as useEffect6, useMemo as
|
|
797
|
+
import React11, { useEffect as useEffect6, useMemo as useMemo6, useRef as useRef3 } from "react";
|
|
768
798
|
import { mx as mx7 } from "@dxos/react-ui-theme";
|
|
769
799
|
|
|
770
800
|
// packages/ui/react-ui-form/src/components/Form/FormActions.tsx
|
|
@@ -798,7 +828,7 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
798
828
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
799
829
|
import { pipe as pipe2 } from "effect";
|
|
800
830
|
import { capitalize as capitalize2 } from "effect/String";
|
|
801
|
-
import React10, { useMemo as
|
|
831
|
+
import React10, { useMemo as useMemo5 } from "react";
|
|
802
832
|
import { AST as AST3, S } from "@dxos/echo-schema";
|
|
803
833
|
import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
804
834
|
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
@@ -808,7 +838,7 @@ import { isNotFalsy } from "@dxos/util";
|
|
|
808
838
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
809
839
|
import { pipe } from "effect";
|
|
810
840
|
import { capitalize } from "effect/String";
|
|
811
|
-
import React9, { useCallback as useCallback5, useMemo as
|
|
841
|
+
import React9, { useCallback as useCallback5, useMemo as useMemo4 } from "react";
|
|
812
842
|
import { AST as AST2 } from "@dxos/echo-schema";
|
|
813
843
|
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
814
844
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
@@ -844,7 +874,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
844
874
|
prop.defaultValue
|
|
845
875
|
]));
|
|
846
876
|
};
|
|
847
|
-
const newValue =
|
|
877
|
+
const newValue = useMemo4(() => {
|
|
848
878
|
if (type === "object" && elementType) {
|
|
849
879
|
return getDefaultObjectValue(elementType);
|
|
850
880
|
} else {
|
|
@@ -943,11 +973,11 @@ var getInputComponent = (type, format) => {
|
|
|
943
973
|
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
944
974
|
const inputProps = useInputProps(path);
|
|
945
975
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
946
|
-
const label =
|
|
976
|
+
const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
|
|
947
977
|
title,
|
|
948
978
|
name
|
|
949
979
|
]);
|
|
950
|
-
const placeholder =
|
|
980
|
+
const placeholder = useMemo5(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
951
981
|
examples,
|
|
952
982
|
description
|
|
953
983
|
]);
|
|
@@ -1039,7 +1069,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1039
1069
|
};
|
|
1040
1070
|
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1041
1071
|
const values = useFormValues(path);
|
|
1042
|
-
const properties =
|
|
1072
|
+
const properties = useMemo5(() => {
|
|
1043
1073
|
const props = getSchemaProperties2(schema.ast, values);
|
|
1044
1074
|
const filtered = filter ? filter(props) : props;
|
|
1045
1075
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1070,7 +1100,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1070
1100
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
1071
1101
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1072
1102
|
const formRef = useRef3(null);
|
|
1073
|
-
const onValid =
|
|
1103
|
+
const onValid = useMemo6(() => autoSave ? onSave : void 0, [
|
|
1074
1104
|
autoSave,
|
|
1075
1105
|
onSave
|
|
1076
1106
|
]);
|
|
@@ -1215,7 +1245,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1215
1245
|
}, [
|
|
1216
1246
|
onSave
|
|
1217
1247
|
]);
|
|
1218
|
-
const Custom =
|
|
1248
|
+
const Custom = useMemo7(() => ({
|
|
1219
1249
|
["format"]: (props2) => /* @__PURE__ */ React12.createElement(SelectInput, {
|
|
1220
1250
|
...props2,
|
|
1221
1251
|
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
@@ -1272,7 +1302,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1272
1302
|
};
|
|
1273
1303
|
|
|
1274
1304
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
1275
|
-
import React13, { useCallback as useCallback7, useMemo as
|
|
1305
|
+
import React13, { useCallback as useCallback7, useMemo as useMemo8, useState as useState5 } from "react";
|
|
1276
1306
|
import { AST as AST4, Format, S as S2 } from "@dxos/echo-schema";
|
|
1277
1307
|
import { IconButton as IconButton4, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1278
1308
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
@@ -1289,17 +1319,17 @@ var ViewMetaSchema = S2.Struct({
|
|
|
1289
1319
|
}).pipe(S2.mutable);
|
|
1290
1320
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1291
1321
|
const { t } = useTranslation6(translationKey);
|
|
1292
|
-
const projection =
|
|
1322
|
+
const projection = useMemo8(() => new ViewProjection(schema, view), [
|
|
1293
1323
|
schema,
|
|
1294
1324
|
view
|
|
1295
1325
|
]);
|
|
1296
1326
|
const [field, setField] = useState5();
|
|
1297
|
-
const viewValues =
|
|
1327
|
+
const viewValues = useMemo8(() => {
|
|
1298
1328
|
return {
|
|
1299
1329
|
name: view.name,
|
|
1300
1330
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
1301
1331
|
// TODO(burdon): Settings should have domain name owned by user.
|
|
1302
|
-
typename: view.query.
|
|
1332
|
+
typename: view.query.typename
|
|
1303
1333
|
};
|
|
1304
1334
|
}, [
|
|
1305
1335
|
view
|
|
@@ -1309,7 +1339,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1309
1339
|
if (view.name !== name) {
|
|
1310
1340
|
view.name = name;
|
|
1311
1341
|
}
|
|
1312
|
-
if (view.query.
|
|
1342
|
+
if (view.query.typename !== typename) {
|
|
1313
1343
|
onTypenameChanged(typename);
|
|
1314
1344
|
}
|
|
1315
1345
|
});
|