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