@dxos/react-ui-form 0.8.2-main.36232bc → 0.8.2-main.5885341
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 +194 -70
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +248 -126
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +194 -70
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Form/Form.d.ts +3 -1
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +2 -0
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +13 -10
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +23 -0
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/components/Form/Form.stories.tsx +44 -1
- package/src/components/Form/Form.tsx +4 -0
- package/src/components/Form/FormContent.tsx +59 -15
- package/src/components/Form/RefField.tsx +152 -0
- package/src/components/ViewEditor/ViewEditor.tsx +3 -2
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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";
|
|
@@ -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, Ref, ReferenceAnnotationId } from "@dxos/echo-schema";
|
|
1050
|
+
import { findAnnotation } from "@dxos/effect";
|
|
1051
|
+
import { DXN } from "@dxos/keys";
|
|
1052
|
+
import { refFromDXN } 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: 69,
|
|
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 (Ref.isRef(formValue)) {
|
|
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 (Ref.isRef(formValue)) {
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
1221
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1120
1222
|
role: "none"
|
|
1121
|
-
}, /* @__PURE__ */
|
|
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__ */
|
|
1234
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1133
1235
|
role: "none"
|
|
1134
|
-
}, /* @__PURE__ */
|
|
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__ */
|
|
1266
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1153
1267
|
role: "none"
|
|
1154
|
-
}, !inline && /* @__PURE__ */
|
|
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
|
-
|
|
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__ */
|
|
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__ */
|
|
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
|
-
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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
|
|
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] =
|
|
1244
|
-
|
|
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] =
|
|
1249
|
-
|
|
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] =
|
|
1268
|
-
|
|
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] =
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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
|
-
|
|
1490
|
+
log3.warn("invalid format", {
|
|
1371
1491
|
props
|
|
1372
1492
|
}, {
|
|
1373
|
-
F:
|
|
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__ */
|
|
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
|
|
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
|
|
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] =
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
1616
|
+
F: __dxlog_file5,
|
|
1497
1617
|
L: 111,
|
|
1498
1618
|
S: void 0,
|
|
1499
1619
|
A: [
|
|
@@ -1525,77 +1645,81 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1525
1645
|
}, [
|
|
1526
1646
|
projection
|
|
1527
1647
|
]);
|
|
1528
|
-
return /* @__PURE__ */
|
|
1648
|
+
return /* @__PURE__ */ React15.createElement("div", {
|
|
1529
1649
|
role: "none",
|
|
1530
|
-
className: mx9("
|
|
1531
|
-
}, /* @__PURE__ */
|
|
1650
|
+
className: mx9("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1651
|
+
}, /* @__PURE__ */ React15.createElement(Form, {
|
|
1532
1652
|
autoSave: true,
|
|
1533
1653
|
schema: ViewMetaSchema,
|
|
1534
1654
|
values: viewValues,
|
|
1535
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1536
|
-
|
|
1655
|
+
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1656
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
1657
|
+
}), /* @__PURE__ */ React15.createElement("div", {
|
|
1658
|
+
role: "none",
|
|
1659
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1660
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
1537
1661
|
role: "none",
|
|
1538
1662
|
className: "p-2"
|
|
1539
|
-
}, /* @__PURE__ */
|
|
1663
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1540
1664
|
className: mx9(inputTextLabel)
|
|
1541
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1665
|
+
}, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1542
1666
|
items: view.fields,
|
|
1543
1667
|
isItem: S2.is(FieldSchema),
|
|
1544
1668
|
getId: (field2) => field2.id,
|
|
1545
1669
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1546
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1670
|
+
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
1547
1671
|
role: "heading",
|
|
1548
1672
|
className: grid
|
|
1549
|
-
}, /* @__PURE__ */
|
|
1673
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
|
|
1550
1674
|
className: "flex items-center text-sm"
|
|
1551
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1675
|
+
}, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
|
|
1552
1676
|
role: "list",
|
|
1553
1677
|
className: "flex flex-col w-full"
|
|
1554
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1678
|
+
}, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1555
1679
|
key: field2.id,
|
|
1556
1680
|
item: field2,
|
|
1557
1681
|
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1558
|
-
}, /* @__PURE__ */
|
|
1682
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
|
|
1559
1683
|
onClick: () => handleSelect(field2)
|
|
1560
|
-
}, field2.path), /* @__PURE__ */
|
|
1684
|
+
}, field2.path), /* @__PURE__ */ React15.createElement("div", {
|
|
1561
1685
|
className: "flex items-center gap-2 -ml-4"
|
|
1562
|
-
}, /* @__PURE__ */
|
|
1686
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1563
1687
|
icon: "ph--eye-slash--regular",
|
|
1564
1688
|
disabled: view.fields.length <= 1,
|
|
1565
1689
|
onClick: () => handleHide(field2.id)
|
|
1566
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
1690
|
+
}), !schema.readonly && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
1567
1691
|
icon: "ph--trash--regular",
|
|
1568
1692
|
disabled: view.fields.length <= 1,
|
|
1569
1693
|
onClick: () => handleDelete(field2.id)
|
|
1570
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
1694
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
|
|
1571
1695
|
role: "none",
|
|
1572
1696
|
className: "p-2"
|
|
1573
|
-
}, /* @__PURE__ */
|
|
1697
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1574
1698
|
className: mx9(inputTextLabel)
|
|
1575
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
1699
|
+
}, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1576
1700
|
items: hiddenProperties,
|
|
1577
1701
|
isItem: (item) => typeof item === "string",
|
|
1578
1702
|
getId: (property) => property
|
|
1579
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
1703
|
+
}, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
|
|
1580
1704
|
role: "list",
|
|
1581
1705
|
className: "flex flex-col w-full"
|
|
1582
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
1706
|
+
}, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1583
1707
|
key: property,
|
|
1584
1708
|
item: property,
|
|
1585
1709
|
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1586
|
-
}, /* @__PURE__ */
|
|
1710
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1587
1711
|
icon: "ph--eye--regular",
|
|
1588
1712
|
onClick: () => handleShow(property)
|
|
1589
|
-
}))))))), field && /* @__PURE__ */
|
|
1713
|
+
}))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
1590
1714
|
key: field.id,
|
|
1591
1715
|
view,
|
|
1592
1716
|
projection,
|
|
1593
1717
|
field,
|
|
1594
1718
|
registry,
|
|
1595
1719
|
onSave: handleClose
|
|
1596
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1720
|
+
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
1597
1721
|
className: "flex p-2 justify-center"
|
|
1598
|
-
}, /* @__PURE__ */
|
|
1722
|
+
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
1599
1723
|
icon: "ph--plus--regular",
|
|
1600
1724
|
label: t("button add property"),
|
|
1601
1725
|
onClick: schema.readonly ? void 0 : handleAdd,
|