@dxos/react-ui-form 0.8.2-main.f081794 → 0.8.2-main.f11618f

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 (33) hide show
  1. package/dist/lib/browser/index.mjs +205 -73
  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 +259 -129
  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 +205 -73
  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/Form/ArrayField.d.ts.map +1 -1
  11. package/dist/types/src/components/Form/Form.d.ts +3 -1
  12. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  13. package/dist/types/src/components/Form/Form.stories.d.ts +4 -2
  14. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/Form/FormContent.d.ts +13 -10
  16. package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
  17. package/dist/types/src/components/Form/FormContext.d.ts +2 -2
  18. package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
  19. package/dist/types/src/components/Form/RefField.d.ts +23 -0
  20. package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
  21. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
  22. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
  23. package/dist/types/src/util/formatting.d.ts.map +1 -1
  24. package/package.json +24 -24
  25. package/src/components/Form/ArrayField.tsx +3 -1
  26. package/src/components/Form/Form.stories.tsx +48 -5
  27. package/src/components/Form/Form.tsx +4 -0
  28. package/src/components/Form/FormContent.tsx +59 -15
  29. package/src/components/Form/FormContext.tsx +10 -2
  30. package/src/components/Form/RefField.tsx +151 -0
  31. package/src/components/Form/custom/GeoPointInput.tsx +2 -2
  32. package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
  33. package/src/util/formatting.ts +15 -3
@@ -181,9 +181,9 @@ var ControlFrameItem = ({ title, description, children }) => {
181
181
  };
182
182
 
183
183
  // packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
184
- import React13, { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo7, useState as useState4 } from "react";
184
+ import React14, { useCallback as useCallback6, useEffect as useEffect8, useMemo as useMemo7, useState as useState5 } from "react";
185
185
  import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
186
- import { log as log2 } from "@dxos/log";
186
+ import { log as log3 } from "@dxos/log";
187
187
  import { useTranslation as useTranslation6 } from "@dxos/react-ui";
188
188
  import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
189
189
 
@@ -606,7 +606,7 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
606
606
  };
607
607
 
608
608
  // packages/ui/react-ui-form/src/components/Form/Form.tsx
609
- import React12, { useEffect as useEffect6, useMemo as useMemo6, useRef as useRef3 } from "react";
609
+ import React13, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef3 } from "react";
610
610
  import { mx as mx8 } from "@dxos/react-ui-theme";
611
611
 
612
612
  // packages/ui/react-ui-form/src/components/Form/FormActions.tsx
@@ -922,7 +922,7 @@ var FormActions = ({ onCancel, readonly }) => {
922
922
  // packages/ui/react-ui-form/src/components/Form/FormContent.tsx
923
923
  import { pipe as pipe2 } from "effect";
924
924
  import { capitalize as capitalize2 } from "effect/String";
925
- import React11, { useMemo as useMemo5 } from "react";
925
+ import React12, { useMemo as useMemo5 } from "react";
926
926
  import { AST as AST3, S } from "@dxos/echo-schema";
927
927
  import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
928
928
  import { mx as mx7 } from "@dxos/react-ui-theme";
@@ -944,10 +944,10 @@ var padding = "px-2";
944
944
  var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
945
945
  const { t } = useTranslation5(translationKey);
946
946
  const { ast, name, type, title } = property;
947
- const values = useFormValues(path ?? []);
947
+ const values = useFormValues(path ?? []) ?? [];
948
948
  invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
949
949
  F: __dxlog_file2,
950
- L: 37,
950
+ L: 39,
951
951
  S: void 0,
952
952
  A: [
953
953
  "Array.isArray(values)",
@@ -1044,6 +1044,108 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
1044
1044
  })));
1045
1045
  };
1046
1046
 
1047
+ // packages/ui/react-ui-form/src/components/Form/RefField.tsx
1048
+ import React11, { useEffect as useEffect6, useState as useState4 } from "react";
1049
+ import { Expando, getTypeAnnotation, ReferenceAnnotationId } from "@dxos/echo-schema";
1050
+ import { findAnnotation } from "@dxos/effect";
1051
+ import { DXN } from "@dxos/keys";
1052
+ import { refFromDXN, RefImpl } from "@dxos/live-object";
1053
+ import { log as log2 } from "@dxos/log";
1054
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/RefField.tsx";
1055
+ var RefField = ({ ast, type, label, readonly, placeholder, inline, onQueryRefOptions, inputProps }) => {
1056
+ const { getValue: getValue3, onValueChange, ...restInputProps } = inputProps;
1057
+ const refTypeInfo = findAnnotation(ast, ReferenceAnnotationId);
1058
+ const [refOptions, setRefOptions] = useState4([]);
1059
+ const [loading, setLoading] = useState4(false);
1060
+ useEffect6(() => {
1061
+ if (!refTypeInfo || !onQueryRefOptions) {
1062
+ return;
1063
+ }
1064
+ const fetchOptions = async () => {
1065
+ setLoading(true);
1066
+ try {
1067
+ const options = await onQueryRefOptions(refTypeInfo);
1068
+ setRefOptions(options.map((option) => ({
1069
+ label: option.label,
1070
+ value: option.dxn.toString()
1071
+ })));
1072
+ } catch (error) {
1073
+ log2.error("Failed to fetch ref options:", error, {
1074
+ F: __dxlog_file3,
1075
+ L: 68,
1076
+ S: void 0,
1077
+ C: (f, a) => f(...a)
1078
+ });
1079
+ setRefOptions([]);
1080
+ } finally {
1081
+ setLoading(false);
1082
+ }
1083
+ };
1084
+ void fetchOptions();
1085
+ }, [
1086
+ refTypeInfo,
1087
+ onQueryRefOptions
1088
+ ]);
1089
+ if (!refTypeInfo) {
1090
+ return null;
1091
+ }
1092
+ if (refTypeInfo.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
1093
+ const handleOnValueChange = (_type, dxnString) => {
1094
+ const dxn = DXN.tryParse(dxnString);
1095
+ if (dxn) {
1096
+ onValueChange?.("object", refFromDXN(dxn));
1097
+ } else if (dxnString === "") {
1098
+ onValueChange?.("object", void 0);
1099
+ } else {
1100
+ onValueChange?.("string", dxnString);
1101
+ }
1102
+ };
1103
+ const handleGetValue2 = () => {
1104
+ const formValue = getValue3();
1105
+ if (typeof formValue === "string") {
1106
+ return formValue;
1107
+ }
1108
+ if (formValue instanceof RefImpl) {
1109
+ return formValue.dxn.toString();
1110
+ }
1111
+ return void 0;
1112
+ };
1113
+ return /* @__PURE__ */ React11.createElement(TextInput, {
1114
+ type,
1115
+ label,
1116
+ disabled: readonly,
1117
+ placeholder,
1118
+ inputOnly: inline,
1119
+ getValue: handleGetValue2,
1120
+ onValueChange: handleOnValueChange,
1121
+ ...restInputProps
1122
+ });
1123
+ }
1124
+ const handleGetValue = () => {
1125
+ const formValue = getValue3();
1126
+ if (formValue instanceof RefImpl) {
1127
+ return formValue.dxn.toString();
1128
+ }
1129
+ return void 0;
1130
+ };
1131
+ const handleValueChanged = (_type, dxnString) => {
1132
+ const dxn = DXN.parse(dxnString);
1133
+ const ref = refFromDXN(dxn);
1134
+ onValueChange("object", ref);
1135
+ };
1136
+ return /* @__PURE__ */ React11.createElement(SelectInput, {
1137
+ type,
1138
+ label,
1139
+ disabled: readonly || loading,
1140
+ placeholder: loading ? "Loading options..." : placeholder,
1141
+ inputOnly: inline,
1142
+ getValue: handleGetValue,
1143
+ onValueChange: handleValueChanged,
1144
+ options: refOptions,
1145
+ ...restInputProps
1146
+ });
1147
+ };
1148
+
1047
1149
  // packages/ui/react-ui-form/src/components/Form/factory.tsx
1048
1150
  import { FormatEnum } from "@dxos/echo-schema";
1049
1151
  var getInputComponent = (type, format) => {
@@ -1064,7 +1166,7 @@ var getInputComponent = (type, format) => {
1064
1166
  };
1065
1167
 
1066
1168
  // packages/ui/react-ui-form/src/components/Form/FormContent.tsx
1067
- var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
1169
+ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
1068
1170
  const inputProps = useInputProps(path);
1069
1171
  const { ast, name, type, format, title, description, options, examples, array } = property;
1070
1172
  const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
@@ -1088,14 +1190,14 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
1088
1190
  }
1089
1191
  });
1090
1192
  if (FoundComponent) {
1091
- return /* @__PURE__ */ React11.createElement("div", {
1193
+ return /* @__PURE__ */ React12.createElement("div", {
1092
1194
  role: "none"
1093
1195
  }, FoundComponent);
1094
1196
  }
1095
1197
  const jsonPath = createJsonPath3(path ?? []);
1096
1198
  const CustomComponent = Custom?.[jsonPath];
1097
1199
  if (CustomComponent) {
1098
- return /* @__PURE__ */ React11.createElement(CustomComponent, {
1200
+ return /* @__PURE__ */ React12.createElement(CustomComponent, {
1099
1201
  type,
1100
1202
  format,
1101
1203
  label,
@@ -1106,7 +1208,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
1106
1208
  });
1107
1209
  }
1108
1210
  if (array) {
1109
- return /* @__PURE__ */ React11.createElement(ArrayField, {
1211
+ return /* @__PURE__ */ React12.createElement(ArrayField, {
1110
1212
  property,
1111
1213
  path,
1112
1214
  inputProps,
@@ -1116,9 +1218,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
1116
1218
  }
1117
1219
  const InputComponent = getInputComponent(type, format);
1118
1220
  if (InputComponent) {
1119
- return /* @__PURE__ */ React11.createElement("div", {
1221
+ return /* @__PURE__ */ React12.createElement("div", {
1120
1222
  role: "none"
1121
- }, /* @__PURE__ */ React11.createElement(InputComponent, {
1223
+ }, /* @__PURE__ */ React12.createElement(InputComponent, {
1122
1224
  type,
1123
1225
  format,
1124
1226
  label,
@@ -1129,9 +1231,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
1129
1231
  }));
1130
1232
  }
1131
1233
  if (options) {
1132
- return /* @__PURE__ */ React11.createElement("div", {
1234
+ return /* @__PURE__ */ React12.createElement("div", {
1133
1235
  role: "none"
1134
- }, /* @__PURE__ */ React11.createElement(SelectInput, {
1236
+ }, /* @__PURE__ */ React12.createElement(SelectInput, {
1135
1237
  type,
1136
1238
  format,
1137
1239
  disabled: readonly,
@@ -1145,23 +1247,39 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
1145
1247
  ...inputProps
1146
1248
  }));
1147
1249
  }
1250
+ if (format === "ref") {
1251
+ return /* @__PURE__ */ React12.createElement(RefField, {
1252
+ ast,
1253
+ type,
1254
+ label,
1255
+ readonly,
1256
+ placeholder,
1257
+ inline,
1258
+ onQueryRefOptions,
1259
+ inputProps
1260
+ });
1261
+ }
1148
1262
  if (type === "object") {
1149
1263
  const baseNode = findNode2(ast, isDiscriminatedUnion2);
1150
1264
  const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode2(ast, AST3.isTypeLiteral);
1151
1265
  if (typeLiteral) {
1152
- return /* @__PURE__ */ React11.createElement("div", {
1266
+ return /* @__PURE__ */ React12.createElement("div", {
1153
1267
  role: "none"
1154
- }, !inline && /* @__PURE__ */ React11.createElement("div", null, label), /* @__PURE__ */ React11.createElement(FormFields, {
1268
+ }, !inline && /* @__PURE__ */ React12.createElement("h3", {
1269
+ className: "text-lg mbs-2 mbe-1"
1270
+ }, label), /* @__PURE__ */ React12.createElement(FormFields, {
1155
1271
  schema: S.make(typeLiteral),
1156
1272
  path,
1157
1273
  readonly,
1158
- Custom
1274
+ onQueryRefOptions,
1275
+ Custom,
1276
+ lookupComponent
1159
1277
  }));
1160
1278
  }
1161
1279
  }
1162
1280
  return null;
1163
1281
  };
1164
- var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
1282
+ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
1165
1283
  const values = useFormValues(path);
1166
1284
  const properties = useMemo5(() => {
1167
1285
  const props = getSchemaProperties2(schema.ast, values);
@@ -1173,11 +1291,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
1173
1291
  filter,
1174
1292
  sort
1175
1293
  ]);
1176
- return /* @__PURE__ */ React11.createElement("div", {
1294
+ return /* @__PURE__ */ React12.createElement("div", {
1177
1295
  role: "form",
1178
1296
  className: mx7("flex flex-col w-full gap-2")
1179
1297
  }, properties.map((property) => {
1180
- return /* @__PURE__ */ React11.createElement(FormField, {
1298
+ return /* @__PURE__ */ React12.createElement(FormField, {
1181
1299
  key: property.name,
1182
1300
  property,
1183
1301
  path: [
@@ -1185,6 +1303,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
1185
1303
  property.name
1186
1304
  ],
1187
1305
  readonly,
1306
+ onQueryRefOptions,
1188
1307
  lookupComponent,
1189
1308
  Custom
1190
1309
  });
@@ -1192,13 +1311,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
1192
1311
  };
1193
1312
 
1194
1313
  // packages/ui/react-ui-form/src/components/Form/Form.tsx
1195
- var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
1314
+ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
1196
1315
  const formRef = useRef3(null);
1197
1316
  const onValid = useMemo6(() => autoSave ? onSave : void 0, [
1198
1317
  autoSave,
1199
1318
  onSave
1200
1319
  ]);
1201
- useEffect6(() => {
1320
+ useEffect7(() => {
1202
1321
  if (autoFocus && formRef.current) {
1203
1322
  const input = formRef.current.querySelector("input");
1204
1323
  if (input) {
@@ -1208,7 +1327,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
1208
1327
  }, [
1209
1328
  autoFocus
1210
1329
  ]);
1211
- return /* @__PURE__ */ React12.createElement(FormProvider, {
1330
+ return /* @__PURE__ */ React13.createElement(FormProvider, {
1212
1331
  formRef,
1213
1332
  schema,
1214
1333
  autoSave,
@@ -1217,36 +1336,37 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
1217
1336
  onValidate,
1218
1337
  onValid,
1219
1338
  onSave
1220
- }, /* @__PURE__ */ React12.createElement("div", {
1339
+ }, /* @__PURE__ */ React13.createElement("div", {
1221
1340
  ref: formRef,
1222
1341
  role: "none",
1223
1342
  className: mx8("p-2", classNames),
1224
1343
  "data-testid": testId
1225
- }, /* @__PURE__ */ React12.createElement(FormFields, {
1344
+ }, /* @__PURE__ */ React13.createElement(FormFields, {
1226
1345
  schema,
1227
1346
  path,
1228
1347
  readonly,
1229
1348
  filter,
1230
1349
  sort,
1350
+ onQueryRefOptions,
1231
1351
  lookupComponent,
1232
1352
  Custom
1233
- }), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React12.createElement(FormActions, {
1353
+ }), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React13.createElement(FormActions, {
1234
1354
  onCancel,
1235
1355
  readonly
1236
1356
  })));
1237
1357
  };
1238
1358
 
1239
1359
  // packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
1240
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
1360
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
1241
1361
  var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1242
1362
  const { t } = useTranslation6(translationKey);
1243
- const [props, setProps] = useState4(projection.getFieldProjection(field.id).props);
1244
- useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
1363
+ const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
1364
+ useEffect8(() => setProps(projection.getFieldProjection(field.id).props), [
1245
1365
  field,
1246
1366
  projection
1247
1367
  ]);
1248
- const [schemas, setSchemas] = useState4([]);
1249
- useEffect7(() => {
1368
+ const [schemas, setSchemas] = useState5([]);
1369
+ useEffect8(() => {
1250
1370
  if (!registry) {
1251
1371
  return;
1252
1372
  }
@@ -1264,14 +1384,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1264
1384
  }, [
1265
1385
  registry
1266
1386
  ]);
1267
- const [referenceSchema, setReferenceSchema] = useState4();
1268
- useEffect7(() => {
1387
+ const [referenceSchema, setReferenceSchema] = useState5();
1388
+ useEffect8(() => {
1269
1389
  setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
1270
1390
  }, [
1271
1391
  schemas,
1272
1392
  props?.referenceSchema
1273
1393
  ]);
1274
- const [{ fieldSchema }, setFieldSchema] = useState4({
1394
+ const [{ fieldSchema }, setFieldSchema] = useState5({
1275
1395
  fieldSchema: getFormatSchema(props?.format)
1276
1396
  });
1277
1397
  const handleValuesChanged = useCallback6((_props) => {
@@ -1340,26 +1460,26 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1340
1460
  onSave
1341
1461
  ]);
1342
1462
  const Custom = useMemo7(() => ({
1343
- ["format"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1463
+ ["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1344
1464
  ...props2,
1345
1465
  options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
1346
1466
  value,
1347
1467
  label: t(`format ${value}`)
1348
1468
  }))
1349
1469
  }),
1350
- ["referenceSchema"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1470
+ ["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1351
1471
  ...props2,
1352
1472
  options: schemas.map((schema) => ({
1353
1473
  value: schema.typename
1354
1474
  }))
1355
1475
  }),
1356
- ["referencePath"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1476
+ ["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1357
1477
  ...props2,
1358
1478
  options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
1359
1479
  value: p.name
1360
1480
  })) : []
1361
1481
  }),
1362
- ["options"]: (props2) => /* @__PURE__ */ React13.createElement(SelectOptionInput, props2)
1482
+ ["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
1363
1483
  }), [
1364
1484
  t,
1365
1485
  schemas,
@@ -1367,17 +1487,17 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1367
1487
  ]);
1368
1488
  const propIsNotType = useCallback6((props2) => props2.filter((p) => p.name !== "type"), []);
1369
1489
  if (!fieldSchema) {
1370
- log2.warn("invalid format", {
1490
+ log3.warn("invalid format", {
1371
1491
  props
1372
1492
  }, {
1373
- F: __dxlog_file3,
1493
+ F: __dxlog_file4,
1374
1494
  L: 174,
1375
1495
  S: void 0,
1376
1496
  C: (f, a) => f(...a)
1377
1497
  });
1378
1498
  return null;
1379
1499
  }
1380
- return /* @__PURE__ */ React13.createElement(Form, {
1500
+ return /* @__PURE__ */ React14.createElement(Form, {
1381
1501
  key: field.id,
1382
1502
  autoFocus: true,
1383
1503
  values: props,
@@ -1396,14 +1516,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1396
1516
  };
1397
1517
 
1398
1518
  // packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
1399
- import React14, { useCallback as useCallback7, useMemo as useMemo8, useState as useState5 } from "react";
1519
+ import React15, { useCallback as useCallback7, useMemo as useMemo8, useState as useState6 } from "react";
1400
1520
  import { AST as AST4, Format, S as S2 } from "@dxos/echo-schema";
1401
1521
  import { invariant as invariant3 } from "@dxos/invariant";
1402
1522
  import { IconButton as IconButton4, useTranslation as useTranslation7 } from "@dxos/react-ui";
1403
1523
  import { List as List2 } from "@dxos/react-ui-list";
1404
1524
  import { ghostHover, inputTextLabel, mx as mx9 } from "@dxos/react-ui-theme";
1405
1525
  import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
1406
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
1526
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
1407
1527
  var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
1408
1528
  var ViewMetaSchema = S2.Struct({
1409
1529
  name: S2.String.annotations({
@@ -1419,7 +1539,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1419
1539
  schema,
1420
1540
  view
1421
1541
  ]);
1422
- const [field, setField] = useState5();
1542
+ const [field, setField] = useState6();
1423
1543
  const viewValues = useMemo8(() => {
1424
1544
  return {
1425
1545
  name: view.name,
@@ -1435,7 +1555,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1435
1555
  }, []);
1436
1556
  const handleAdd = useCallback7(() => {
1437
1557
  invariant3(!schema.readonly, void 0, {
1438
- F: __dxlog_file4,
1558
+ F: __dxlog_file5,
1439
1559
  L: 76,
1440
1560
  S: void 0,
1441
1561
  A: [
@@ -1451,7 +1571,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1451
1571
  ]);
1452
1572
  const handleUpdate = useCallback7(({ name, typename }) => {
1453
1573
  invariant3(!schema.readonly, void 0, {
1454
- F: __dxlog_file4,
1574
+ F: __dxlog_file5,
1455
1575
  L: 83,
1456
1576
  S: void 0,
1457
1577
  A: [
@@ -1474,7 +1594,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1474
1594
  ]);
1475
1595
  const handleDelete = useCallback7((fieldId) => {
1476
1596
  invariant3(!schema.readonly, void 0, {
1477
- F: __dxlog_file4,
1597
+ F: __dxlog_file5,
1478
1598
  L: 99,
1479
1599
  S: void 0,
1480
1600
  A: [
@@ -1493,7 +1613,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1493
1613
  ]);
1494
1614
  const handleMove = useCallback7((fromIndex, toIndex) => {
1495
1615
  invariant3(!schema.readonly, void 0, {
1496
- F: __dxlog_file4,
1616
+ F: __dxlog_file5,
1497
1617
  L: 111,
1498
1618
  S: void 0,
1499
1619
  A: [
@@ -1525,77 +1645,77 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1525
1645
  }, [
1526
1646
  projection
1527
1647
  ]);
1528
- return /* @__PURE__ */ React14.createElement("div", {
1648
+ return /* @__PURE__ */ React15.createElement("div", {
1529
1649
  role: "none",
1530
1650
  className: mx9("flex flex-col w-full divide-y divide-separator", classNames)
1531
- }, /* @__PURE__ */ React14.createElement(Form, {
1651
+ }, /* @__PURE__ */ React15.createElement(Form, {
1532
1652
  autoSave: true,
1533
1653
  schema: ViewMetaSchema,
1534
1654
  values: viewValues,
1535
1655
  onSave: schema.readonly ? void 0 : handleUpdate
1536
- }), /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
1656
+ }), /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
1537
1657
  role: "none",
1538
1658
  className: "p-2"
1539
- }, /* @__PURE__ */ React14.createElement("label", {
1659
+ }, /* @__PURE__ */ React15.createElement("label", {
1540
1660
  className: mx9(inputTextLabel)
1541
- }, t("fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
1661
+ }, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
1542
1662
  items: view.fields,
1543
1663
  isItem: S2.is(FieldSchema),
1544
1664
  getId: (field2) => field2.id,
1545
1665
  onMove: schema.readonly ? void 0 : handleMove
1546
- }, ({ items: fields }) => /* @__PURE__ */ React14.createElement(React14.Fragment, null, showHeading && /* @__PURE__ */ React14.createElement("div", {
1666
+ }, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
1547
1667
  role: "heading",
1548
1668
  className: grid
1549
- }, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement("div", {
1669
+ }, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
1550
1670
  className: "flex items-center text-sm"
1551
- }, t("field path label"))), /* @__PURE__ */ React14.createElement("div", {
1671
+ }, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
1552
1672
  role: "list",
1553
1673
  className: "flex flex-col w-full"
1554
- }, fields?.map((field2) => /* @__PURE__ */ React14.createElement(List2.Item, {
1674
+ }, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
1555
1675
  key: field2.id,
1556
1676
  item: field2,
1557
1677
  classNames: mx9(grid, ghostHover, "cursor-pointer")
1558
- }, /* @__PURE__ */ React14.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, {
1678
+ }, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
1559
1679
  onClick: () => handleSelect(field2)
1560
- }, field2.path), /* @__PURE__ */ React14.createElement("div", {
1680
+ }, field2.path), /* @__PURE__ */ React15.createElement("div", {
1561
1681
  className: "flex items-center gap-2 -ml-4"
1562
- }, /* @__PURE__ */ React14.createElement(List2.ItemButton, {
1682
+ }, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
1563
1683
  icon: "ph--eye-slash--regular",
1564
1684
  disabled: view.fields.length <= 1,
1565
1685
  onClick: () => handleHide(field2.id)
1566
- }), !schema.readonly && /* @__PURE__ */ React14.createElement(List2.ItemDeleteButton, {
1686
+ }), !schema.readonly && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
1567
1687
  icon: "ph--trash--regular",
1568
1688
  disabled: view.fields.length <= 1,
1569
1689
  onClick: () => handleDelete(field2.id)
1570
- }))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
1690
+ }))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
1571
1691
  role: "none",
1572
1692
  className: "p-2"
1573
- }, /* @__PURE__ */ React14.createElement("label", {
1693
+ }, /* @__PURE__ */ React15.createElement("label", {
1574
1694
  className: mx9(inputTextLabel)
1575
- }, t("hidden fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
1695
+ }, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
1576
1696
  items: hiddenProperties,
1577
1697
  isItem: (item) => typeof item === "string",
1578
1698
  getId: (property) => property
1579
- }, ({ items: properties }) => /* @__PURE__ */ React14.createElement("div", {
1699
+ }, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
1580
1700
  role: "list",
1581
1701
  className: "flex flex-col w-full"
1582
- }, properties?.map((property) => /* @__PURE__ */ React14.createElement(List2.Item, {
1702
+ }, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
1583
1703
  key: property,
1584
1704
  item: property,
1585
1705
  classNames: mx9(grid, ghostHover, "cursor-pointer")
1586
- }, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React14.createElement(List2.ItemButton, {
1706
+ }, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
1587
1707
  icon: "ph--eye--regular",
1588
1708
  onClick: () => handleShow(property)
1589
- }))))))), field && /* @__PURE__ */ React14.createElement(FieldEditor, {
1709
+ }))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
1590
1710
  key: field.id,
1591
1711
  view,
1592
1712
  projection,
1593
1713
  field,
1594
1714
  registry,
1595
1715
  onSave: handleClose
1596
- }), !readonly && !field && /* @__PURE__ */ React14.createElement("div", {
1716
+ }), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
1597
1717
  className: "flex p-2 justify-center"
1598
- }, /* @__PURE__ */ React14.createElement(IconButton4, {
1718
+ }, /* @__PURE__ */ React15.createElement(IconButton4, {
1599
1719
  icon: "ph--plus--regular",
1600
1720
  label: t("button add property"),
1601
1721
  onClick: schema.readonly ? void 0 : handleAdd,
@@ -1780,13 +1900,25 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
1780
1900
  });
1781
1901
  }
1782
1902
  case FormatEnum4.Date: {
1783
- return formatDate(new Date(value), "yyyy-MM-dd");
1903
+ try {
1904
+ return formatDate(new Date(value), "yyyy-MM-dd");
1905
+ } catch (error) {
1906
+ return "Invalid Date";
1907
+ }
1784
1908
  }
1785
1909
  case FormatEnum4.Time: {
1786
- return formatDate(new Date(value), "HH:mm:ss");
1910
+ try {
1911
+ return formatDate(new Date(value), "HH:mm:ss");
1912
+ } catch (error) {
1913
+ return "Invalid Time";
1914
+ }
1787
1915
  }
1788
1916
  case FormatEnum4.DateTime: {
1789
- return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
1917
+ try {
1918
+ return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
1919
+ } catch (error) {
1920
+ return "Invalid DateTime";
1921
+ }
1790
1922
  }
1791
1923
  case FormatEnum4.GeoPoint: {
1792
1924
  if (value === null || value === void 0) {