@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
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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";
|
|
@@ -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, Ref, ReferenceAnnotationId } from "@dxos/echo-schema";
|
|
1052
|
+
import { findAnnotation } from "@dxos/effect";
|
|
1053
|
+
import { DXN } from "@dxos/keys";
|
|
1054
|
+
import { refFromDXN } 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: 69,
|
|
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 (Ref.isRef(formValue)) {
|
|
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 (Ref.isRef(formValue)) {
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
1223
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1122
1224
|
role: "none"
|
|
1123
|
-
}, /* @__PURE__ */
|
|
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__ */
|
|
1236
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1135
1237
|
role: "none"
|
|
1136
|
-
}, /* @__PURE__ */
|
|
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__ */
|
|
1268
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1155
1269
|
role: "none"
|
|
1156
|
-
}, !inline && /* @__PURE__ */
|
|
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
|
-
|
|
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__ */
|
|
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__ */
|
|
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
|
-
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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
|
|
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] =
|
|
1246
|
-
|
|
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] =
|
|
1251
|
-
|
|
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] =
|
|
1270
|
-
|
|
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] =
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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
|
-
|
|
1492
|
+
log3.warn("invalid format", {
|
|
1373
1493
|
props
|
|
1374
1494
|
}, {
|
|
1375
|
-
F:
|
|
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__ */
|
|
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
|
|
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
|
|
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] =
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
1618
|
+
F: __dxlog_file5,
|
|
1499
1619
|
L: 111,
|
|
1500
1620
|
S: void 0,
|
|
1501
1621
|
A: [
|
|
@@ -1527,77 +1647,81 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1527
1647
|
}, [
|
|
1528
1648
|
projection
|
|
1529
1649
|
]);
|
|
1530
|
-
return /* @__PURE__ */
|
|
1650
|
+
return /* @__PURE__ */ React15.createElement("div", {
|
|
1531
1651
|
role: "none",
|
|
1532
|
-
className: mx9("
|
|
1533
|
-
}, /* @__PURE__ */
|
|
1652
|
+
className: mx9("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1653
|
+
}, /* @__PURE__ */ React15.createElement(Form, {
|
|
1534
1654
|
autoSave: true,
|
|
1535
1655
|
schema: ViewMetaSchema,
|
|
1536
1656
|
values: viewValues,
|
|
1537
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1538
|
-
|
|
1657
|
+
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1658
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
1659
|
+
}), /* @__PURE__ */ React15.createElement("div", {
|
|
1660
|
+
role: "none",
|
|
1661
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1662
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
1539
1663
|
role: "none",
|
|
1540
1664
|
className: "p-2"
|
|
1541
|
-
}, /* @__PURE__ */
|
|
1665
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1542
1666
|
className: mx9(inputTextLabel)
|
|
1543
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1667
|
+
}, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1544
1668
|
items: view.fields,
|
|
1545
1669
|
isItem: S2.is(FieldSchema),
|
|
1546
1670
|
getId: (field2) => field2.id,
|
|
1547
1671
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1548
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1672
|
+
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
1549
1673
|
role: "heading",
|
|
1550
1674
|
className: grid
|
|
1551
|
-
}, /* @__PURE__ */
|
|
1675
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
|
|
1552
1676
|
className: "flex items-center text-sm"
|
|
1553
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1677
|
+
}, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
|
|
1554
1678
|
role: "list",
|
|
1555
1679
|
className: "flex flex-col w-full"
|
|
1556
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1680
|
+
}, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1557
1681
|
key: field2.id,
|
|
1558
1682
|
item: field2,
|
|
1559
1683
|
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1560
|
-
}, /* @__PURE__ */
|
|
1684
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
|
|
1561
1685
|
onClick: () => handleSelect(field2)
|
|
1562
|
-
}, field2.path), /* @__PURE__ */
|
|
1686
|
+
}, field2.path), /* @__PURE__ */ React15.createElement("div", {
|
|
1563
1687
|
className: "flex items-center gap-2 -ml-4"
|
|
1564
|
-
}, /* @__PURE__ */
|
|
1688
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1565
1689
|
icon: "ph--eye-slash--regular",
|
|
1566
1690
|
disabled: view.fields.length <= 1,
|
|
1567
1691
|
onClick: () => handleHide(field2.id)
|
|
1568
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
1692
|
+
}), !schema.readonly && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
1569
1693
|
icon: "ph--trash--regular",
|
|
1570
1694
|
disabled: view.fields.length <= 1,
|
|
1571
1695
|
onClick: () => handleDelete(field2.id)
|
|
1572
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
1696
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
|
|
1573
1697
|
role: "none",
|
|
1574
1698
|
className: "p-2"
|
|
1575
|
-
}, /* @__PURE__ */
|
|
1699
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1576
1700
|
className: mx9(inputTextLabel)
|
|
1577
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
1701
|
+
}, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1578
1702
|
items: hiddenProperties,
|
|
1579
1703
|
isItem: (item) => typeof item === "string",
|
|
1580
1704
|
getId: (property) => property
|
|
1581
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
1705
|
+
}, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
|
|
1582
1706
|
role: "list",
|
|
1583
1707
|
className: "flex flex-col w-full"
|
|
1584
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
1708
|
+
}, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1585
1709
|
key: property,
|
|
1586
1710
|
item: property,
|
|
1587
1711
|
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1588
|
-
}, /* @__PURE__ */
|
|
1712
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1589
1713
|
icon: "ph--eye--regular",
|
|
1590
1714
|
onClick: () => handleShow(property)
|
|
1591
|
-
}))))))), field && /* @__PURE__ */
|
|
1715
|
+
}))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
1592
1716
|
key: field.id,
|
|
1593
1717
|
view,
|
|
1594
1718
|
projection,
|
|
1595
1719
|
field,
|
|
1596
1720
|
registry,
|
|
1597
1721
|
onSave: handleClose
|
|
1598
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1722
|
+
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
1599
1723
|
className: "flex p-2 justify-center"
|
|
1600
|
-
}, /* @__PURE__ */
|
|
1724
|
+
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
1601
1725
|
icon: "ph--plus--regular",
|
|
1602
1726
|
label: t("button add property"),
|
|
1603
1727
|
onClick: schema.readonly ? void 0 : handleAdd,
|