@dxos/react-ui-form 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb
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 +672 -543
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +564 -442
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +672 -543
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +1 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +6 -18
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +0 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +23 -0
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +1 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +9 -0
- package/dist/types/src/util/refs.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +3 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -24
- package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +2 -2
- package/src/components/Form/Form.stories.tsx +2 -1
- package/src/components/Form/Form.tsx +1 -2
- package/src/components/Form/FormContent.tsx +44 -16
- package/src/components/Form/FormContext.tsx +3 -1
- package/src/components/Form/Input.tsx +3 -9
- package/src/components/Form/RefField.tsx +144 -99
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +1 -1
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +0 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +1 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useQueryRefOptions.ts +53 -0
- package/src/hooks/useRefQueryLookupHandler.ts +2 -4
- package/src/util/index.ts +3 -1
- package/src/util/refs.ts +38 -0
- package/src/util/schema.ts +14 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -54,8 +54,10 @@ __export(node_exports, {
|
|
|
54
54
|
ViewEditor: () => ViewEditor,
|
|
55
55
|
cellClassesForFieldType: () => cellClassesForFieldType,
|
|
56
56
|
controlItemClasses: () => controlItemClasses,
|
|
57
|
+
findArrayElementType: () => findArrayElementType,
|
|
57
58
|
formatForDisplay: () => formatForDisplay,
|
|
58
59
|
formatForEditing: () => formatForEditing,
|
|
60
|
+
getRefProps: () => getRefProps,
|
|
59
61
|
parseValue: () => parseValue,
|
|
60
62
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
61
63
|
translations: () => translations_default,
|
|
@@ -63,6 +65,7 @@ __export(node_exports, {
|
|
|
63
65
|
useFormContext: () => useFormContext,
|
|
64
66
|
useFormValues: () => useFormValues,
|
|
65
67
|
useInputProps: () => useInputProps,
|
|
68
|
+
useQueryRefOptions: () => useQueryRefOptions,
|
|
66
69
|
useRefQueryLookupHandler: () => useRefQueryLookupHandler
|
|
67
70
|
});
|
|
68
71
|
module.exports = __toCommonJS(node_exports);
|
|
@@ -116,39 +119,46 @@ var import_react13 = require("react");
|
|
|
116
119
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
117
120
|
var import_echo = require("@dxos/react-client/echo");
|
|
118
121
|
var import_util3 = require("@dxos/util");
|
|
122
|
+
var import_react14 = require("react");
|
|
123
|
+
var import_log3 = require("@dxos/log");
|
|
119
124
|
var import_effect4 = require("effect");
|
|
120
125
|
var import_String = require("effect/String");
|
|
121
|
-
var
|
|
126
|
+
var import_react15 = __toESM(require("react"));
|
|
122
127
|
var import_effect5 = require("@dxos/effect");
|
|
123
128
|
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
124
129
|
var import_schema3 = require("@dxos/schema");
|
|
125
130
|
var import_util4 = require("@dxos/util");
|
|
126
131
|
var import_effect6 = require("effect");
|
|
127
132
|
var import_String2 = require("effect/String");
|
|
128
|
-
var
|
|
133
|
+
var import_react16 = __toESM(require("react"));
|
|
129
134
|
var import_effect7 = require("@dxos/effect");
|
|
130
135
|
var import_invariant2 = require("@dxos/invariant");
|
|
131
136
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
132
137
|
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
133
138
|
var import_schema4 = require("@dxos/schema");
|
|
134
|
-
var import_react16 = __toESM(require("react"));
|
|
135
139
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
136
|
-
var
|
|
137
|
-
var import_keys2 = require("@dxos/keys");
|
|
138
|
-
var import_live_object = require("@dxos/live-object");
|
|
139
|
-
var import_log3 = require("@dxos/log");
|
|
140
|
+
var import_format = require("date-fns/format");
|
|
140
141
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
142
|
+
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
143
|
+
var import_effect8 = require("@dxos/effect");
|
|
141
144
|
var import_effect9 = require("effect");
|
|
145
|
+
var import_effect10 = require("@dxos/effect");
|
|
142
146
|
var import_react17 = __toESM(require("react"));
|
|
143
|
-
var
|
|
144
|
-
var
|
|
147
|
+
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
148
|
+
var import_effect11 = require("@dxos/effect");
|
|
149
|
+
var import_keys2 = require("@dxos/keys");
|
|
145
150
|
var import_react_ui11 = require("@dxos/react-ui");
|
|
151
|
+
var import_react_ui_tag_picker = require("@dxos/react-ui-tag-picker");
|
|
152
|
+
var import_util5 = require("@dxos/util");
|
|
153
|
+
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
154
|
+
var import_effect12 = require("effect");
|
|
155
|
+
var import_react18 = __toESM(require("react"));
|
|
156
|
+
var import_echo_schema11 = require("@dxos/echo-schema");
|
|
157
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
158
|
+
var import_react_ui12 = require("@dxos/react-ui");
|
|
146
159
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
147
160
|
var import_react_ui_theme10 = require("@dxos/react-ui-theme");
|
|
148
161
|
var import_schema5 = require("@dxos/schema");
|
|
149
|
-
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
150
|
-
var import_format = require("date-fns/format");
|
|
151
|
-
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
152
162
|
var translationKey = "react-ui-form";
|
|
153
163
|
var translations_default = [
|
|
154
164
|
{
|
|
@@ -323,15 +333,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
323
333
|
return /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
324
334
|
role: "none",
|
|
325
335
|
className: "flex justify-between items-center mb-1"
|
|
326
|
-
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.
|
|
327
|
-
asChild: true
|
|
336
|
+
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Trigger, {
|
|
337
|
+
asChild: true,
|
|
338
|
+
content: error,
|
|
339
|
+
side: "bottom"
|
|
328
340
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
329
341
|
icon: "ph--warning--regular",
|
|
330
342
|
size: 4,
|
|
331
343
|
classNames: import_react_ui_theme3.errorText
|
|
332
|
-
}))
|
|
333
|
-
side: "bottom"
|
|
334
|
-
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
|
|
344
|
+
})));
|
|
335
345
|
};
|
|
336
346
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
337
347
|
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
@@ -934,6 +944,48 @@ var useRefQueryLookupHandler = ({ space }) => {
|
|
|
934
944
|
]);
|
|
935
945
|
return handleRefQueryLookup;
|
|
936
946
|
};
|
|
947
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
948
|
+
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
949
|
+
const [options, setOptions] = (0, import_react14.useState)([]);
|
|
950
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
951
|
+
(0, import_react14.useEffect)(() => {
|
|
952
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const fetchOptions = async () => {
|
|
956
|
+
setLoading(true);
|
|
957
|
+
try {
|
|
958
|
+
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
959
|
+
setOptions(fetchedOptions.map((option) => {
|
|
960
|
+
const dxn = option.dxn.toString();
|
|
961
|
+
return {
|
|
962
|
+
id: dxn,
|
|
963
|
+
label: option.label ?? dxn,
|
|
964
|
+
hue: "neutral"
|
|
965
|
+
};
|
|
966
|
+
}));
|
|
967
|
+
} catch (error) {
|
|
968
|
+
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
969
|
+
F: __dxlog_file2,
|
|
970
|
+
L: 42,
|
|
971
|
+
S: void 0,
|
|
972
|
+
C: (f, a) => f(...a)
|
|
973
|
+
});
|
|
974
|
+
setOptions([]);
|
|
975
|
+
} finally {
|
|
976
|
+
setLoading(false);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
void fetchOptions();
|
|
980
|
+
}, [
|
|
981
|
+
refTypeInfo,
|
|
982
|
+
onQueryRefOptions
|
|
983
|
+
]);
|
|
984
|
+
return {
|
|
985
|
+
options,
|
|
986
|
+
loading
|
|
987
|
+
};
|
|
988
|
+
};
|
|
937
989
|
var FormContext = /* @__PURE__ */ (0, import_react11.createContext)(void 0);
|
|
938
990
|
var useFormContext = () => {
|
|
939
991
|
return (0, import_react11.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
@@ -971,7 +1023,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
971
1023
|
const keyIsEnter = event.key === "Enter";
|
|
972
1024
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
973
1025
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
974
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
1026
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
975
1027
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
976
1028
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
977
1029
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -1020,15 +1072,305 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
1020
1072
|
onClick: handleSave
|
|
1021
1073
|
})));
|
|
1022
1074
|
};
|
|
1023
|
-
var
|
|
1075
|
+
var parseValue = ({ type, format, value }) => {
|
|
1076
|
+
if (value === void 0 || value === null || value === "") {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
}
|
|
1079
|
+
const parseScalar = (type2) => {
|
|
1080
|
+
switch (type2) {
|
|
1081
|
+
case import_echo_schema6.TypeEnum.Boolean: {
|
|
1082
|
+
if (typeof value === "string") {
|
|
1083
|
+
const lowercaseValue = value.toLowerCase();
|
|
1084
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1085
|
+
return false;
|
|
1086
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return Boolean(value);
|
|
1091
|
+
}
|
|
1092
|
+
case import_echo_schema6.TypeEnum.Number: {
|
|
1093
|
+
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1094
|
+
const num = Number(cleaned);
|
|
1095
|
+
return Number.isNaN(num) ? null : num;
|
|
1096
|
+
}
|
|
1097
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1098
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1099
|
+
return String(value);
|
|
1100
|
+
default: {
|
|
1101
|
+
return value;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
if (!format) {
|
|
1106
|
+
return parseScalar(type);
|
|
1107
|
+
}
|
|
1108
|
+
switch (format) {
|
|
1109
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1110
|
+
return parseScalar(import_echo_schema6.TypeEnum.Boolean);
|
|
1111
|
+
case import_echo_schema6.FormatEnum.Number:
|
|
1112
|
+
case import_echo_schema6.FormatEnum.Percent:
|
|
1113
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1114
|
+
return parseScalar(import_echo_schema6.TypeEnum.Number);
|
|
1115
|
+
case import_echo_schema6.FormatEnum.String:
|
|
1116
|
+
case import_echo_schema6.FormatEnum.Markdown: {
|
|
1117
|
+
return parseScalar(import_echo_schema6.TypeEnum.String);
|
|
1118
|
+
}
|
|
1119
|
+
case import_echo_schema6.FormatEnum.Ref:
|
|
1120
|
+
throw new Error(`unexpected format: ${import_echo_schema6.FormatEnum.Ref}`);
|
|
1121
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1122
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1123
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1124
|
+
case import_echo_schema6.FormatEnum.Timestamp: {
|
|
1125
|
+
const date = new Date(value);
|
|
1126
|
+
return isNaN(date.getTime()) ? null : date;
|
|
1127
|
+
}
|
|
1128
|
+
case import_echo_schema6.FormatEnum.GeoPoint: {
|
|
1129
|
+
if (typeof value === "string") {
|
|
1130
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1131
|
+
const parts = cleaned.split(",");
|
|
1132
|
+
if (parts.length === 2) {
|
|
1133
|
+
const lat = parseFloat(parts[0]);
|
|
1134
|
+
const long = parseFloat(parts[1]);
|
|
1135
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1136
|
+
return import_echo_schema6.GeoLocation.toGeoPoint({
|
|
1137
|
+
latitude: lat,
|
|
1138
|
+
longitude: long
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return [
|
|
1144
|
+
0,
|
|
1145
|
+
0
|
|
1146
|
+
];
|
|
1147
|
+
}
|
|
1148
|
+
default: {
|
|
1149
|
+
return value;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
1154
|
+
if (!format) {
|
|
1155
|
+
switch (type) {
|
|
1156
|
+
case import_echo_schema6.TypeEnum.Number:
|
|
1157
|
+
return [
|
|
1158
|
+
"text-right",
|
|
1159
|
+
"font-mono"
|
|
1160
|
+
];
|
|
1161
|
+
case import_echo_schema6.TypeEnum.Boolean:
|
|
1162
|
+
return [
|
|
1163
|
+
"text-right",
|
|
1164
|
+
"font-mono"
|
|
1165
|
+
];
|
|
1166
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1167
|
+
return void 0;
|
|
1168
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1169
|
+
return void 0;
|
|
1170
|
+
default: {
|
|
1171
|
+
return void 0;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
switch (format) {
|
|
1176
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
1177
|
+
return void 0;
|
|
1178
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1179
|
+
case import_echo_schema6.FormatEnum.Timestamp:
|
|
1180
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1181
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1182
|
+
case import_echo_schema6.FormatEnum.Duration:
|
|
1183
|
+
return [
|
|
1184
|
+
"font-mono",
|
|
1185
|
+
"text-right"
|
|
1186
|
+
];
|
|
1187
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1188
|
+
return [
|
|
1189
|
+
"text-right"
|
|
1190
|
+
];
|
|
1191
|
+
case import_echo_schema6.FormatEnum.JSON:
|
|
1192
|
+
case import_echo_schema6.FormatEnum.DID:
|
|
1193
|
+
return [
|
|
1194
|
+
"font-mono"
|
|
1195
|
+
];
|
|
1196
|
+
default:
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
var pathNotUniqueError = (path) => ({
|
|
1201
|
+
path: "path",
|
|
1202
|
+
message: `'${path}' is already present`
|
|
1203
|
+
});
|
|
1204
|
+
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1205
|
+
const formatScalar = (type2) => {
|
|
1206
|
+
switch (type2) {
|
|
1207
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1208
|
+
return value.toLocaleString().toUpperCase();
|
|
1209
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1210
|
+
return value.toLocaleString(locale);
|
|
1211
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1212
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1213
|
+
return String(value);
|
|
1214
|
+
default: {
|
|
1215
|
+
return String(value);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
if (!format) {
|
|
1220
|
+
return formatScalar(type);
|
|
1221
|
+
}
|
|
1222
|
+
switch (format) {
|
|
1223
|
+
case import_echo_schema7.FormatEnum.Boolean: {
|
|
1224
|
+
return formatScalar(import_echo_schema7.TypeEnum.Boolean);
|
|
1225
|
+
}
|
|
1226
|
+
case import_echo_schema7.FormatEnum.Number: {
|
|
1227
|
+
return formatScalar(import_echo_schema7.TypeEnum.Number);
|
|
1228
|
+
}
|
|
1229
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1230
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1231
|
+
return formatScalar(import_echo_schema7.TypeEnum.String);
|
|
1232
|
+
}
|
|
1233
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1234
|
+
return `${value * 100}%`;
|
|
1235
|
+
}
|
|
1236
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1237
|
+
return value.toLocaleString(locale, {
|
|
1238
|
+
style: "currency",
|
|
1239
|
+
currency: "USD",
|
|
1240
|
+
minimumFractionDigits: 2,
|
|
1241
|
+
maximumFractionDigits: 2
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1245
|
+
try {
|
|
1246
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
return "Invalid Date";
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1252
|
+
try {
|
|
1253
|
+
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1254
|
+
} catch (error) {
|
|
1255
|
+
return "Invalid Time";
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1259
|
+
try {
|
|
1260
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
return "Invalid DateTime";
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1266
|
+
if (value === null || value === void 0) {
|
|
1267
|
+
return "";
|
|
1268
|
+
}
|
|
1269
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1270
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1271
|
+
return `${latitude},${longitude}`;
|
|
1272
|
+
}
|
|
1273
|
+
return String(value);
|
|
1274
|
+
}
|
|
1275
|
+
default: {
|
|
1276
|
+
if (value === null || value === "undefined") {
|
|
1277
|
+
return "";
|
|
1278
|
+
}
|
|
1279
|
+
return String(value);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1284
|
+
const formatScalar = (type2) => {
|
|
1285
|
+
switch (type2) {
|
|
1286
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1287
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1288
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1289
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1290
|
+
return String(value);
|
|
1291
|
+
default:
|
|
1292
|
+
return String(value);
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
if (!format) {
|
|
1296
|
+
return formatScalar(type);
|
|
1297
|
+
}
|
|
1298
|
+
switch (format) {
|
|
1299
|
+
case import_echo_schema7.FormatEnum.Boolean:
|
|
1300
|
+
case import_echo_schema7.FormatEnum.Number:
|
|
1301
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1302
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1303
|
+
return formatScalar(type);
|
|
1304
|
+
}
|
|
1305
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1306
|
+
return String(value * 100);
|
|
1307
|
+
}
|
|
1308
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1309
|
+
return String(value);
|
|
1310
|
+
}
|
|
1311
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1312
|
+
const date = new Date(value);
|
|
1313
|
+
return date.toISOString();
|
|
1314
|
+
}
|
|
1315
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1316
|
+
const date = new Date(value);
|
|
1317
|
+
return date.toISOString().split("T")[0];
|
|
1318
|
+
}
|
|
1319
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1320
|
+
const date = new Date(value);
|
|
1321
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
1322
|
+
}
|
|
1323
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1324
|
+
if (value === null || value === void 0) {
|
|
1325
|
+
return "";
|
|
1326
|
+
}
|
|
1327
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1328
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1329
|
+
return `${latitude},${longitude}`;
|
|
1330
|
+
}
|
|
1331
|
+
return String(value);
|
|
1332
|
+
}
|
|
1333
|
+
default: {
|
|
1334
|
+
return String(value);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
var findArrayElementType = (ast) => {
|
|
1339
|
+
const tupleType = (0, import_effect10.findNode)(ast, import_effect9.SchemaAST.isTupleType);
|
|
1340
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
1341
|
+
return elementType;
|
|
1342
|
+
};
|
|
1343
|
+
var getRefProps = (property) => {
|
|
1344
|
+
const { ast, format, array } = property;
|
|
1345
|
+
if (format === import_echo_schema8.FormatEnum.Ref) {
|
|
1346
|
+
return {
|
|
1347
|
+
ast,
|
|
1348
|
+
isArray: false
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
if (array) {
|
|
1352
|
+
const elementType = findArrayElementType(ast);
|
|
1353
|
+
if (elementType) {
|
|
1354
|
+
const annotation = (0, import_effect8.findAnnotation)(elementType, import_echo_schema8.ReferenceAnnotationId);
|
|
1355
|
+
if (annotation) {
|
|
1356
|
+
return {
|
|
1357
|
+
ast: elementType,
|
|
1358
|
+
isArray: true
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
return void 0;
|
|
1364
|
+
};
|
|
1365
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1024
1366
|
var padding = "px-2";
|
|
1025
1367
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1026
1368
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1027
1369
|
const { ast, name, type, title } = property;
|
|
1028
1370
|
const values = useFormValues(path ?? []) ?? [];
|
|
1029
1371
|
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1030
|
-
F:
|
|
1031
|
-
L:
|
|
1372
|
+
F: __dxlog_file3,
|
|
1373
|
+
L: 39,
|
|
1032
1374
|
S: void 0,
|
|
1033
1375
|
A: [
|
|
1034
1376
|
"Array.isArray(values)",
|
|
@@ -1036,8 +1378,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1036
1378
|
]
|
|
1037
1379
|
});
|
|
1038
1380
|
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
1039
|
-
const
|
|
1040
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
1381
|
+
const elementType = findArrayElementType(ast);
|
|
1041
1382
|
const getDefaultObjectValue = (typeNode) => {
|
|
1042
1383
|
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
1043
1384
|
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_effect6.SchemaAST.isTypeLiteral);
|
|
@@ -1049,7 +1390,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1049
1390
|
prop.defaultValue
|
|
1050
1391
|
]));
|
|
1051
1392
|
};
|
|
1052
|
-
const newValue = (0,
|
|
1393
|
+
const newValue = (0, import_react16.useMemo)(() => {
|
|
1053
1394
|
if (type === "object" && elementType) {
|
|
1054
1395
|
return getDefaultObjectValue(elementType);
|
|
1055
1396
|
} else {
|
|
@@ -1059,7 +1400,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1059
1400
|
type,
|
|
1060
1401
|
elementType
|
|
1061
1402
|
]);
|
|
1062
|
-
const handleAdd = (0,
|
|
1403
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1063
1404
|
inputProps.onValueChange(type, [
|
|
1064
1405
|
...values,
|
|
1065
1406
|
newValue
|
|
@@ -1071,7 +1412,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1071
1412
|
newValue,
|
|
1072
1413
|
values
|
|
1073
1414
|
]);
|
|
1074
|
-
const handleRemove = (0,
|
|
1415
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1075
1416
|
const newValues = values.filter((_, i) => i !== index);
|
|
1076
1417
|
inputProps.onValueChange(type, newValues);
|
|
1077
1418
|
}, [
|
|
@@ -1082,20 +1423,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1082
1423
|
if (!elementType) {
|
|
1083
1424
|
return null;
|
|
1084
1425
|
}
|
|
1085
|
-
return /* @__PURE__ */
|
|
1426
|
+
return /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1086
1427
|
role: "none",
|
|
1087
1428
|
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1088
|
-
}, /* @__PURE__ */
|
|
1429
|
+
}, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1089
1430
|
role: "none",
|
|
1090
1431
|
className: "flex flex-col gap-1"
|
|
1091
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
1432
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1092
1433
|
key: index,
|
|
1093
1434
|
role: "none",
|
|
1094
1435
|
className: "flex items-center gap-1"
|
|
1095
|
-
}, /* @__PURE__ */
|
|
1436
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1096
1437
|
role: "none",
|
|
1097
1438
|
className: "flex-1"
|
|
1098
|
-
}, /* @__PURE__ */
|
|
1439
|
+
}, /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1099
1440
|
property: {
|
|
1100
1441
|
...property,
|
|
1101
1442
|
array: false,
|
|
@@ -1109,120 +1450,158 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1109
1450
|
inline: true,
|
|
1110
1451
|
Custom,
|
|
1111
1452
|
lookupComponent
|
|
1112
|
-
})), /* @__PURE__ */
|
|
1453
|
+
})), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1113
1454
|
icon: "ph--trash--regular",
|
|
1114
1455
|
iconOnly: true,
|
|
1115
1456
|
label: t("button remove"),
|
|
1116
1457
|
onClick: () => handleRemove(index)
|
|
1117
|
-
})))), /* @__PURE__ */
|
|
1458
|
+
})))), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1118
1459
|
role: "none",
|
|
1119
1460
|
className: "flex justify-between items-center plb-1"
|
|
1120
|
-
}, /* @__PURE__ */
|
|
1461
|
+
}, /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1121
1462
|
icon: "ph--plus--regular",
|
|
1122
1463
|
iconOnly: true,
|
|
1123
1464
|
label: t("button add"),
|
|
1124
1465
|
onClick: handleAdd
|
|
1125
1466
|
})));
|
|
1126
1467
|
};
|
|
1127
|
-
var
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
const
|
|
1132
|
-
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
1133
|
-
(0, import_react16.useEffect)(() => {
|
|
1134
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1135
|
-
return;
|
|
1136
|
-
}
|
|
1137
|
-
const fetchOptions = async () => {
|
|
1138
|
-
setLoading(true);
|
|
1139
|
-
try {
|
|
1140
|
-
const options = await onQueryRefOptions(refTypeInfo);
|
|
1141
|
-
setRefOptions(options.map((option) => ({
|
|
1142
|
-
label: option.label,
|
|
1143
|
-
value: option.dxn.toString()
|
|
1144
|
-
})));
|
|
1145
|
-
} catch (error) {
|
|
1146
|
-
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
1147
|
-
F: __dxlog_file3,
|
|
1148
|
-
L: 69,
|
|
1149
|
-
S: void 0,
|
|
1150
|
-
C: (f, a) => f(...a)
|
|
1151
|
-
});
|
|
1152
|
-
setRefOptions([]);
|
|
1153
|
-
} finally {
|
|
1154
|
-
setLoading(false);
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
void fetchOptions();
|
|
1158
|
-
}, [
|
|
1468
|
+
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1469
|
+
const refTypeInfo = (0, import_react17.useMemo)(() => ast ? (0, import_effect11.findAnnotation)(ast, import_echo_schema9.ReferenceAnnotationId) : void 0, [
|
|
1470
|
+
ast
|
|
1471
|
+
]);
|
|
1472
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1159
1473
|
refTypeInfo,
|
|
1160
1474
|
onQueryRefOptions
|
|
1161
|
-
|
|
1162
|
-
if (
|
|
1163
|
-
return
|
|
1164
|
-
}
|
|
1165
|
-
if (refTypeInfo.typename === (0, import_echo_schema6.getTypeAnnotation)(import_echo_schema6.Expando)?.typename || !onQueryRefOptions) {
|
|
1166
|
-
const handleOnValueChange = (_type, dxnString) => {
|
|
1167
|
-
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1168
|
-
if (dxn) {
|
|
1169
|
-
onValueChange?.("object", (0, import_live_object.refFromDXN)(dxn));
|
|
1170
|
-
} else if (dxnString === "") {
|
|
1171
|
-
onValueChange?.("object", void 0);
|
|
1172
|
-
} else {
|
|
1173
|
-
onValueChange?.("string", dxnString);
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
const handleGetValue2 = () => {
|
|
1177
|
-
const formValue = getValue3();
|
|
1178
|
-
if (typeof formValue === "string") {
|
|
1179
|
-
return formValue;
|
|
1180
|
-
}
|
|
1181
|
-
if (import_echo_schema6.Ref.isRef(formValue)) {
|
|
1182
|
-
return formValue.dxn.toString();
|
|
1183
|
-
}
|
|
1184
|
-
return void 0;
|
|
1185
|
-
};
|
|
1186
|
-
return /* @__PURE__ */ import_react16.default.createElement(TextInput, {
|
|
1475
|
+
});
|
|
1476
|
+
if (refTypeInfo && refTypeInfo?.typename === (0, import_echo_schema9.getTypeAnnotation)(import_echo_schema9.Expando)?.typename || !onQueryRefOptions) {
|
|
1477
|
+
return /* @__PURE__ */ import_react17.default.createElement(RefFieldFallback, {
|
|
1187
1478
|
type,
|
|
1188
1479
|
label,
|
|
1189
|
-
disabled: readonly,
|
|
1190
1480
|
placeholder,
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1481
|
+
disabled,
|
|
1482
|
+
inputOnly,
|
|
1483
|
+
getValue: getValue3,
|
|
1484
|
+
onBlur,
|
|
1485
|
+
onValueChange,
|
|
1194
1486
|
...restInputProps
|
|
1195
1487
|
});
|
|
1196
1488
|
}
|
|
1489
|
+
const handleGetValue = (0, import_react17.useCallback)(() => {
|
|
1490
|
+
const formValue = getValue3();
|
|
1491
|
+
const unknownToRefOption = (val) => {
|
|
1492
|
+
if (import_echo_schema9.Ref.isRef(val)) {
|
|
1493
|
+
const dxnString = val.dxn.toString();
|
|
1494
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1495
|
+
if (matchingOption) {
|
|
1496
|
+
return matchingOption;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return void 0;
|
|
1500
|
+
};
|
|
1501
|
+
if (array && Array.isArray(formValue)) {
|
|
1502
|
+
return formValue.map(unknownToRefOption).filter(import_util5.isNonNullable) ?? [];
|
|
1503
|
+
}
|
|
1504
|
+
const option = unknownToRefOption(formValue);
|
|
1505
|
+
if (option) {
|
|
1506
|
+
return [
|
|
1507
|
+
option
|
|
1508
|
+
];
|
|
1509
|
+
}
|
|
1510
|
+
return [];
|
|
1511
|
+
}, [
|
|
1512
|
+
getValue3,
|
|
1513
|
+
availableOptions,
|
|
1514
|
+
array
|
|
1515
|
+
]);
|
|
1516
|
+
const handleSearch = (0, import_react17.useCallback)((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1517
|
+
id: option.id,
|
|
1518
|
+
label: option.label,
|
|
1519
|
+
hue: option.hue
|
|
1520
|
+
})), [
|
|
1521
|
+
availableOptions
|
|
1522
|
+
]);
|
|
1523
|
+
const handleUpdate = (0, import_react17.useCallback)((ids) => {
|
|
1524
|
+
if (ids.length === 0) {
|
|
1525
|
+
onValueChange("object", void 0);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
const refs = ids.map((id) => {
|
|
1529
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1530
|
+
if (item) {
|
|
1531
|
+
const dxn = import_keys2.DXN.parse(item.id);
|
|
1532
|
+
return import_echo_schema9.Ref.fromDXN(dxn);
|
|
1533
|
+
}
|
|
1534
|
+
return null;
|
|
1535
|
+
}).filter(import_util5.isNonNullable);
|
|
1536
|
+
if (array) {
|
|
1537
|
+
onValueChange("object", refs);
|
|
1538
|
+
} else {
|
|
1539
|
+
onValueChange("object", refs[0]);
|
|
1540
|
+
}
|
|
1541
|
+
}, [
|
|
1542
|
+
availableOptions,
|
|
1543
|
+
array,
|
|
1544
|
+
onValueChange
|
|
1545
|
+
]);
|
|
1546
|
+
const tagPickerMode = (0, import_react17.useMemo)(() => array ? "multi-select" : "single-select", [
|
|
1547
|
+
array
|
|
1548
|
+
]);
|
|
1549
|
+
if (!refTypeInfo) {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
const { status, error } = restInputProps.getStatus();
|
|
1553
|
+
return /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Root, {
|
|
1554
|
+
validationValence: status
|
|
1555
|
+
}, !inputOnly && /* @__PURE__ */ import_react17.default.createElement(InputHeader, {
|
|
1556
|
+
error
|
|
1557
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Label, null, label)), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1558
|
+
"data-no-submit": true
|
|
1559
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui_tag_picker.TagPicker, {
|
|
1560
|
+
items: handleGetValue(),
|
|
1561
|
+
mode: tagPickerMode,
|
|
1562
|
+
onBlur: (event) => onBlur(event),
|
|
1563
|
+
onUpdate: handleUpdate,
|
|
1564
|
+
onSearch: handleSearch,
|
|
1565
|
+
classNames: "rounded-sm bg-input p-1.5"
|
|
1566
|
+
})), inputOnly && /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.DescriptionAndValidation, null, error));
|
|
1567
|
+
};
|
|
1568
|
+
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1569
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1570
|
+
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1571
|
+
if (dxn) {
|
|
1572
|
+
onValueChange?.("object", import_echo_schema9.Ref.fromDXN(dxn));
|
|
1573
|
+
} else if (dxnString === "") {
|
|
1574
|
+
onValueChange?.("object", void 0);
|
|
1575
|
+
} else {
|
|
1576
|
+
onValueChange?.("string", dxnString);
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1197
1579
|
const handleGetValue = () => {
|
|
1198
1580
|
const formValue = getValue3();
|
|
1199
|
-
if (
|
|
1581
|
+
if (typeof formValue === "string") {
|
|
1582
|
+
return formValue;
|
|
1583
|
+
}
|
|
1584
|
+
if (import_echo_schema9.Ref.isRef(formValue)) {
|
|
1200
1585
|
return formValue.dxn.toString();
|
|
1201
1586
|
}
|
|
1202
1587
|
return void 0;
|
|
1203
1588
|
};
|
|
1204
|
-
|
|
1205
|
-
const dxn = import_keys2.DXN.parse(dxnString);
|
|
1206
|
-
const ref = (0, import_live_object.refFromDXN)(dxn);
|
|
1207
|
-
onValueChange("object", ref);
|
|
1208
|
-
};
|
|
1209
|
-
return /* @__PURE__ */ import_react16.default.createElement(SelectInput, {
|
|
1589
|
+
return /* @__PURE__ */ import_react17.default.createElement(TextInput, {
|
|
1210
1590
|
type,
|
|
1211
1591
|
label,
|
|
1212
|
-
disabled
|
|
1213
|
-
placeholder
|
|
1214
|
-
inputOnly
|
|
1592
|
+
disabled,
|
|
1593
|
+
placeholder,
|
|
1594
|
+
inputOnly,
|
|
1215
1595
|
getValue: handleGetValue,
|
|
1216
|
-
onValueChange:
|
|
1217
|
-
options: refOptions,
|
|
1596
|
+
onValueChange: handleOnValueChange,
|
|
1218
1597
|
...restInputProps
|
|
1219
1598
|
});
|
|
1220
1599
|
};
|
|
1221
1600
|
var getInputComponent = (type, format) => {
|
|
1222
1601
|
switch (format) {
|
|
1223
|
-
case
|
|
1602
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1224
1603
|
return GeoPointInput;
|
|
1225
|
-
case
|
|
1604
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1226
1605
|
return MarkdownInput;
|
|
1227
1606
|
}
|
|
1228
1607
|
switch (type) {
|
|
@@ -1237,11 +1616,11 @@ var getInputComponent = (type, format) => {
|
|
|
1237
1616
|
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1238
1617
|
const inputProps = useInputProps(path);
|
|
1239
1618
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1240
|
-
const label = (0,
|
|
1619
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1241
1620
|
title,
|
|
1242
1621
|
name
|
|
1243
1622
|
]);
|
|
1244
|
-
const placeholder = (0,
|
|
1623
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1245
1624
|
examples,
|
|
1246
1625
|
description
|
|
1247
1626
|
]);
|
|
@@ -1258,14 +1637,14 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1258
1637
|
}
|
|
1259
1638
|
});
|
|
1260
1639
|
if (FoundComponent) {
|
|
1261
|
-
return /* @__PURE__ */
|
|
1640
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1262
1641
|
role: "none"
|
|
1263
1642
|
}, FoundComponent);
|
|
1264
1643
|
}
|
|
1265
1644
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1266
1645
|
const CustomComponent = Custom?.[jsonPath];
|
|
1267
1646
|
if (CustomComponent) {
|
|
1268
|
-
return /* @__PURE__ */
|
|
1647
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1269
1648
|
type,
|
|
1270
1649
|
format,
|
|
1271
1650
|
label,
|
|
@@ -1275,8 +1654,23 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1275
1654
|
...inputProps
|
|
1276
1655
|
});
|
|
1277
1656
|
}
|
|
1657
|
+
const refProps = getRefProps(property);
|
|
1658
|
+
if (refProps) {
|
|
1659
|
+
return /* @__PURE__ */ import_react15.default.createElement(RefField, {
|
|
1660
|
+
ast: refProps.ast,
|
|
1661
|
+
array: refProps.isArray,
|
|
1662
|
+
type,
|
|
1663
|
+
format,
|
|
1664
|
+
label,
|
|
1665
|
+
placeholder,
|
|
1666
|
+
disabled: readonly,
|
|
1667
|
+
inputOnly: inline,
|
|
1668
|
+
onQueryRefOptions,
|
|
1669
|
+
...inputProps
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1278
1672
|
if (array) {
|
|
1279
|
-
return /* @__PURE__ */
|
|
1673
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1280
1674
|
property,
|
|
1281
1675
|
path,
|
|
1282
1676
|
inputProps,
|
|
@@ -1286,9 +1680,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1286
1680
|
}
|
|
1287
1681
|
const InputComponent = getInputComponent(type, format);
|
|
1288
1682
|
if (InputComponent) {
|
|
1289
|
-
return /* @__PURE__ */
|
|
1683
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1290
1684
|
role: "none"
|
|
1291
|
-
}, /* @__PURE__ */
|
|
1685
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1292
1686
|
type,
|
|
1293
1687
|
format,
|
|
1294
1688
|
label,
|
|
@@ -1299,9 +1693,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1299
1693
|
}));
|
|
1300
1694
|
}
|
|
1301
1695
|
if (options) {
|
|
1302
|
-
return /* @__PURE__ */
|
|
1696
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1303
1697
|
role: "none"
|
|
1304
|
-
}, /* @__PURE__ */
|
|
1698
|
+
}, /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1305
1699
|
type,
|
|
1306
1700
|
format,
|
|
1307
1701
|
disabled: readonly,
|
|
@@ -1315,27 +1709,15 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1315
1709
|
...inputProps
|
|
1316
1710
|
}));
|
|
1317
1711
|
}
|
|
1318
|
-
if (format === "ref") {
|
|
1319
|
-
return /* @__PURE__ */ import_react14.default.createElement(RefField, {
|
|
1320
|
-
ast,
|
|
1321
|
-
type,
|
|
1322
|
-
label,
|
|
1323
|
-
readonly,
|
|
1324
|
-
placeholder,
|
|
1325
|
-
inline,
|
|
1326
|
-
onQueryRefOptions,
|
|
1327
|
-
inputProps
|
|
1328
|
-
});
|
|
1329
|
-
}
|
|
1330
1712
|
if (type === "object") {
|
|
1331
1713
|
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1332
1714
|
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1333
1715
|
if (typeLiteral) {
|
|
1334
|
-
return /* @__PURE__ */
|
|
1716
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1335
1717
|
role: "none"
|
|
1336
|
-
}, !inline && /* @__PURE__ */
|
|
1718
|
+
}, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1337
1719
|
className: "text-lg mbs-2 mbe-1"
|
|
1338
|
-
}, label), /* @__PURE__ */
|
|
1720
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1339
1721
|
schema: import_effect4.Schema.make(typeLiteral),
|
|
1340
1722
|
path,
|
|
1341
1723
|
readonly,
|
|
@@ -1349,7 +1731,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1349
1731
|
};
|
|
1350
1732
|
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1351
1733
|
const values = useFormValues(path);
|
|
1352
|
-
const properties = (0,
|
|
1734
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1353
1735
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1354
1736
|
const filtered = filter ? filter(props) : props;
|
|
1355
1737
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1359,11 +1741,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1359
1741
|
filter,
|
|
1360
1742
|
sort
|
|
1361
1743
|
]);
|
|
1362
|
-
return /* @__PURE__ */
|
|
1744
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1363
1745
|
role: "form",
|
|
1364
1746
|
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1365
1747
|
}, properties.map((property) => {
|
|
1366
|
-
return /* @__PURE__ */
|
|
1748
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1367
1749
|
key: property.name,
|
|
1368
1750
|
property,
|
|
1369
1751
|
path: [
|
|
@@ -1580,22 +1962,22 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1580
1962
|
};
|
|
1581
1963
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1582
1964
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1583
|
-
var ViewMetaSchema =
|
|
1584
|
-
name:
|
|
1585
|
-
[
|
|
1965
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
1966
|
+
name: import_effect12.Schema.String.annotations({
|
|
1967
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "View"
|
|
1586
1968
|
}),
|
|
1587
|
-
typename:
|
|
1588
|
-
[
|
|
1969
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
1970
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1589
1971
|
})
|
|
1590
|
-
}).pipe(
|
|
1972
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
1591
1973
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1592
|
-
const { t } = (0,
|
|
1593
|
-
const projection = (0,
|
|
1974
|
+
const { t } = (0, import_react_ui12.useTranslation)(translationKey);
|
|
1975
|
+
const projection = (0, import_react18.useMemo)(() => new import_schema5.ViewProjection(schema.jsonSchema, view), [
|
|
1594
1976
|
schema,
|
|
1595
1977
|
view
|
|
1596
1978
|
]);
|
|
1597
|
-
const [field, setField] = (0,
|
|
1598
|
-
const viewValues = (0,
|
|
1979
|
+
const [field, setField] = (0, import_react18.useState)();
|
|
1980
|
+
const viewValues = (0, import_react18.useMemo)(() => {
|
|
1599
1981
|
return {
|
|
1600
1982
|
name: view.name,
|
|
1601
1983
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1605,10 +1987,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1605
1987
|
}, [
|
|
1606
1988
|
view
|
|
1607
1989
|
]);
|
|
1608
|
-
const handleSelect = (0,
|
|
1990
|
+
const handleSelect = (0, import_react18.useCallback)((field2) => {
|
|
1609
1991
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1610
1992
|
}, []);
|
|
1611
|
-
const handleAdd = (0,
|
|
1993
|
+
const handleAdd = (0, import_react18.useCallback)(() => {
|
|
1612
1994
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1613
1995
|
F: __dxlog_file5,
|
|
1614
1996
|
L: 77,
|
|
@@ -1624,7 +2006,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1624
2006
|
schema,
|
|
1625
2007
|
view
|
|
1626
2008
|
]);
|
|
1627
|
-
const handleUpdate = (0,
|
|
2009
|
+
const handleUpdate = (0, import_react18.useCallback)(({ name, typename }) => {
|
|
1628
2010
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1629
2011
|
F: __dxlog_file5,
|
|
1630
2012
|
L: 84,
|
|
@@ -1647,7 +2029,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1647
2029
|
view,
|
|
1648
2030
|
onTypenameChanged
|
|
1649
2031
|
]);
|
|
1650
|
-
const handleDelete = (0,
|
|
2032
|
+
const handleDelete = (0, import_react18.useCallback)((fieldId) => {
|
|
1651
2033
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1652
2034
|
F: __dxlog_file5,
|
|
1653
2035
|
L: 100,
|
|
@@ -1666,7 +2048,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1666
2048
|
field,
|
|
1667
2049
|
onDelete
|
|
1668
2050
|
]);
|
|
1669
|
-
const handleMove = (0,
|
|
2051
|
+
const handleMove = (0, import_react18.useCallback)((fromIndex, toIndex) => {
|
|
1670
2052
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1671
2053
|
F: __dxlog_file5,
|
|
1672
2054
|
L: 112,
|
|
@@ -1686,95 +2068,95 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1686
2068
|
schema,
|
|
1687
2069
|
view.fields
|
|
1688
2070
|
]);
|
|
1689
|
-
const handleClose = (0,
|
|
2071
|
+
const handleClose = (0, import_react18.useCallback)(() => setField(void 0), []);
|
|
1690
2072
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1691
|
-
const handleHide = (0,
|
|
2073
|
+
const handleHide = (0, import_react18.useCallback)((fieldId) => {
|
|
1692
2074
|
setField(void 0);
|
|
1693
2075
|
projection.hideFieldProjection(fieldId);
|
|
1694
2076
|
}, [
|
|
1695
2077
|
projection
|
|
1696
2078
|
]);
|
|
1697
|
-
const handleShow = (0,
|
|
2079
|
+
const handleShow = (0, import_react18.useCallback)((property) => {
|
|
1698
2080
|
setField(void 0);
|
|
1699
2081
|
projection.showFieldProjection(property);
|
|
1700
2082
|
}, [
|
|
1701
2083
|
projection
|
|
1702
2084
|
]);
|
|
1703
|
-
return /* @__PURE__ */
|
|
2085
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1704
2086
|
role: "none",
|
|
1705
2087
|
className: (0, import_react_ui_theme10.mx)("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1706
|
-
}, /* @__PURE__ */
|
|
2088
|
+
}, /* @__PURE__ */ import_react18.default.createElement(Form, {
|
|
1707
2089
|
autoSave: true,
|
|
1708
2090
|
schema: ViewMetaSchema,
|
|
1709
2091
|
values: viewValues,
|
|
1710
2092
|
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1711
2093
|
classNames: "min-bs-0 overflow-y-auto"
|
|
1712
|
-
}), /* @__PURE__ */
|
|
2094
|
+
}), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1713
2095
|
role: "none",
|
|
1714
2096
|
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1715
|
-
}, /* @__PURE__ */
|
|
2097
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1716
2098
|
role: "none",
|
|
1717
2099
|
className: "p-2"
|
|
1718
|
-
}, /* @__PURE__ */
|
|
2100
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1719
2101
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1720
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
2102
|
+
}, t("fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1721
2103
|
items: view.fields,
|
|
1722
|
-
isItem:
|
|
2104
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
1723
2105
|
getId: (field2) => field2.id,
|
|
1724
2106
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1725
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
2107
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, showHeading && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1726
2108
|
role: "heading",
|
|
1727
2109
|
className: grid
|
|
1728
|
-
}, /* @__PURE__ */
|
|
2110
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1729
2111
|
className: "flex items-center text-sm"
|
|
1730
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
2112
|
+
}, t("field path label"))), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1731
2113
|
role: "list",
|
|
1732
2114
|
className: "flex flex-col w-full"
|
|
1733
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
2115
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1734
2116
|
key: field2.id,
|
|
1735
2117
|
item: field2,
|
|
1736
2118
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1737
|
-
}, /* @__PURE__ */
|
|
2119
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1738
2120
|
onClick: () => handleSelect(field2)
|
|
1739
|
-
}, field2.path), /* @__PURE__ */
|
|
2121
|
+
}, field2.path), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1740
2122
|
className: "flex items-center gap-2 -ml-4"
|
|
1741
|
-
}, /* @__PURE__ */
|
|
2123
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1742
2124
|
icon: "ph--eye-slash--regular",
|
|
1743
2125
|
disabled: view.fields.length <= 1,
|
|
1744
2126
|
onClick: () => handleHide(field2.id)
|
|
1745
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
2127
|
+
}), !schema.readonly && /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1746
2128
|
icon: "ph--trash--regular",
|
|
1747
2129
|
disabled: view.fields.length <= 1,
|
|
1748
2130
|
onClick: () => handleDelete(field2.id)
|
|
1749
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
2131
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react18.default.createElement("div", null, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1750
2132
|
role: "none",
|
|
1751
2133
|
className: "p-2"
|
|
1752
|
-
}, /* @__PURE__ */
|
|
2134
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1753
2135
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1754
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
2136
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1755
2137
|
items: hiddenProperties,
|
|
1756
2138
|
isItem: (item) => typeof item === "string",
|
|
1757
2139
|
getId: (property) => property
|
|
1758
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
2140
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1759
2141
|
role: "list",
|
|
1760
2142
|
className: "flex flex-col w-full"
|
|
1761
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
2143
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1762
2144
|
key: property,
|
|
1763
2145
|
item: property,
|
|
1764
2146
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1765
|
-
}, /* @__PURE__ */
|
|
2147
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1766
2148
|
icon: "ph--eye--regular",
|
|
1767
2149
|
onClick: () => handleShow(property)
|
|
1768
|
-
}))))))), field && /* @__PURE__ */
|
|
2150
|
+
}))))))), field && /* @__PURE__ */ import_react18.default.createElement(FieldEditor, {
|
|
1769
2151
|
key: field.id,
|
|
1770
2152
|
view,
|
|
1771
2153
|
projection,
|
|
1772
2154
|
field,
|
|
1773
2155
|
registry,
|
|
1774
2156
|
onSave: handleClose
|
|
1775
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
2157
|
+
}), !readonly && !field && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1776
2158
|
className: "flex p-2 justify-center"
|
|
1777
|
-
}, /* @__PURE__ */
|
|
2159
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui12.IconButton, {
|
|
1778
2160
|
icon: "ph--plus--regular",
|
|
1779
2161
|
label: t("button add property"),
|
|
1780
2162
|
onClick: schema.readonly ? void 0 : handleAdd,
|
|
@@ -1782,269 +2164,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1782
2164
|
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1783
2165
|
})));
|
|
1784
2166
|
};
|
|
1785
|
-
var parseValue = ({ type, format, value }) => {
|
|
1786
|
-
if (value === void 0 || value === null || value === "") {
|
|
1787
|
-
return void 0;
|
|
1788
|
-
}
|
|
1789
|
-
const parseScalar = (type2) => {
|
|
1790
|
-
switch (type2) {
|
|
1791
|
-
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1792
|
-
if (typeof value === "string") {
|
|
1793
|
-
const lowercaseValue = value.toLowerCase();
|
|
1794
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1795
|
-
return false;
|
|
1796
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1797
|
-
return true;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
return Boolean(value);
|
|
1801
|
-
}
|
|
1802
|
-
case import_echo_schema9.TypeEnum.Number: {
|
|
1803
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1804
|
-
const num = Number(cleaned);
|
|
1805
|
-
return Number.isNaN(num) ? null : num;
|
|
1806
|
-
}
|
|
1807
|
-
case import_echo_schema9.TypeEnum.String:
|
|
1808
|
-
case import_echo_schema9.TypeEnum.Ref:
|
|
1809
|
-
return String(value);
|
|
1810
|
-
default: {
|
|
1811
|
-
return value;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
};
|
|
1815
|
-
if (!format) {
|
|
1816
|
-
return parseScalar(type);
|
|
1817
|
-
}
|
|
1818
|
-
switch (format) {
|
|
1819
|
-
case import_echo_schema9.FormatEnum.Boolean:
|
|
1820
|
-
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1821
|
-
case import_echo_schema9.FormatEnum.Number:
|
|
1822
|
-
case import_echo_schema9.FormatEnum.Percent:
|
|
1823
|
-
case import_echo_schema9.FormatEnum.Currency:
|
|
1824
|
-
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1825
|
-
case import_echo_schema9.FormatEnum.String:
|
|
1826
|
-
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1827
|
-
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1828
|
-
}
|
|
1829
|
-
case import_echo_schema9.FormatEnum.Ref:
|
|
1830
|
-
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1831
|
-
case import_echo_schema9.FormatEnum.DateTime:
|
|
1832
|
-
case import_echo_schema9.FormatEnum.Date:
|
|
1833
|
-
case import_echo_schema9.FormatEnum.Time:
|
|
1834
|
-
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1835
|
-
const date = new Date(value);
|
|
1836
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1837
|
-
}
|
|
1838
|
-
case import_echo_schema9.FormatEnum.GeoPoint: {
|
|
1839
|
-
if (typeof value === "string") {
|
|
1840
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1841
|
-
const parts = cleaned.split(",");
|
|
1842
|
-
if (parts.length === 2) {
|
|
1843
|
-
const lat = parseFloat(parts[0]);
|
|
1844
|
-
const long = parseFloat(parts[1]);
|
|
1845
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1846
|
-
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1847
|
-
latitude: lat,
|
|
1848
|
-
longitude: long
|
|
1849
|
-
});
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
return [
|
|
1854
|
-
0,
|
|
1855
|
-
0
|
|
1856
|
-
];
|
|
1857
|
-
}
|
|
1858
|
-
default: {
|
|
1859
|
-
return value;
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
};
|
|
1863
|
-
var cellClassesForFieldType = ({ type, format }) => {
|
|
1864
|
-
if (!format) {
|
|
1865
|
-
switch (type) {
|
|
1866
|
-
case import_echo_schema9.TypeEnum.Number:
|
|
1867
|
-
return [
|
|
1868
|
-
"text-right",
|
|
1869
|
-
"font-mono"
|
|
1870
|
-
];
|
|
1871
|
-
case import_echo_schema9.TypeEnum.Boolean:
|
|
1872
|
-
return [
|
|
1873
|
-
"text-right",
|
|
1874
|
-
"font-mono"
|
|
1875
|
-
];
|
|
1876
|
-
case import_echo_schema9.TypeEnum.String:
|
|
1877
|
-
return void 0;
|
|
1878
|
-
case import_echo_schema9.TypeEnum.Ref:
|
|
1879
|
-
return void 0;
|
|
1880
|
-
default: {
|
|
1881
|
-
return void 0;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
switch (format) {
|
|
1886
|
-
case import_echo_schema9.FormatEnum.Markdown:
|
|
1887
|
-
return void 0;
|
|
1888
|
-
case import_echo_schema9.FormatEnum.Time:
|
|
1889
|
-
case import_echo_schema9.FormatEnum.Timestamp:
|
|
1890
|
-
case import_echo_schema9.FormatEnum.DateTime:
|
|
1891
|
-
case import_echo_schema9.FormatEnum.Date:
|
|
1892
|
-
case import_echo_schema9.FormatEnum.Duration:
|
|
1893
|
-
return [
|
|
1894
|
-
"font-mono",
|
|
1895
|
-
"text-right"
|
|
1896
|
-
];
|
|
1897
|
-
case import_echo_schema9.FormatEnum.Currency:
|
|
1898
|
-
return [
|
|
1899
|
-
"text-right"
|
|
1900
|
-
];
|
|
1901
|
-
case import_echo_schema9.FormatEnum.JSON:
|
|
1902
|
-
case import_echo_schema9.FormatEnum.DID:
|
|
1903
|
-
return [
|
|
1904
|
-
"font-mono"
|
|
1905
|
-
];
|
|
1906
|
-
default:
|
|
1907
|
-
return void 0;
|
|
1908
|
-
}
|
|
1909
|
-
};
|
|
1910
|
-
var pathNotUniqueError = (path) => ({
|
|
1911
|
-
path: "path",
|
|
1912
|
-
message: `'${path}' is already present`
|
|
1913
|
-
});
|
|
1914
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1915
|
-
const formatScalar = (type2) => {
|
|
1916
|
-
switch (type2) {
|
|
1917
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1918
|
-
return value.toLocaleString().toUpperCase();
|
|
1919
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1920
|
-
return value.toLocaleString(locale);
|
|
1921
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1922
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1923
|
-
return String(value);
|
|
1924
|
-
default: {
|
|
1925
|
-
return String(value);
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
if (!format) {
|
|
1930
|
-
return formatScalar(type);
|
|
1931
|
-
}
|
|
1932
|
-
switch (format) {
|
|
1933
|
-
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1934
|
-
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1935
|
-
}
|
|
1936
|
-
case import_echo_schema10.FormatEnum.Number: {
|
|
1937
|
-
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1938
|
-
}
|
|
1939
|
-
case import_echo_schema10.FormatEnum.String:
|
|
1940
|
-
case import_echo_schema10.FormatEnum.Ref: {
|
|
1941
|
-
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1942
|
-
}
|
|
1943
|
-
case import_echo_schema10.FormatEnum.Percent: {
|
|
1944
|
-
return `${value * 100}%`;
|
|
1945
|
-
}
|
|
1946
|
-
case import_echo_schema10.FormatEnum.Currency: {
|
|
1947
|
-
return value.toLocaleString(locale, {
|
|
1948
|
-
style: "currency",
|
|
1949
|
-
currency: "USD",
|
|
1950
|
-
minimumFractionDigits: 2,
|
|
1951
|
-
maximumFractionDigits: 2
|
|
1952
|
-
});
|
|
1953
|
-
}
|
|
1954
|
-
case import_echo_schema10.FormatEnum.Date: {
|
|
1955
|
-
try {
|
|
1956
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1957
|
-
} catch (error) {
|
|
1958
|
-
return "Invalid Date";
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
case import_echo_schema10.FormatEnum.Time: {
|
|
1962
|
-
try {
|
|
1963
|
-
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1964
|
-
} catch (error) {
|
|
1965
|
-
return "Invalid Time";
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1969
|
-
try {
|
|
1970
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1971
|
-
} catch (error) {
|
|
1972
|
-
return "Invalid DateTime";
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1976
|
-
if (value === null || value === void 0) {
|
|
1977
|
-
return "";
|
|
1978
|
-
}
|
|
1979
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1980
|
-
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1981
|
-
return `${latitude},${longitude}`;
|
|
1982
|
-
}
|
|
1983
|
-
return String(value);
|
|
1984
|
-
}
|
|
1985
|
-
default: {
|
|
1986
|
-
if (value === null || value === "undefined") {
|
|
1987
|
-
return "";
|
|
1988
|
-
}
|
|
1989
|
-
return String(value);
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
};
|
|
1993
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1994
|
-
const formatScalar = (type2) => {
|
|
1995
|
-
switch (type2) {
|
|
1996
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1997
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1998
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1999
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
2000
|
-
return String(value);
|
|
2001
|
-
default:
|
|
2002
|
-
return String(value);
|
|
2003
|
-
}
|
|
2004
|
-
};
|
|
2005
|
-
if (!format) {
|
|
2006
|
-
return formatScalar(type);
|
|
2007
|
-
}
|
|
2008
|
-
switch (format) {
|
|
2009
|
-
case import_echo_schema10.FormatEnum.Boolean:
|
|
2010
|
-
case import_echo_schema10.FormatEnum.Number:
|
|
2011
|
-
case import_echo_schema10.FormatEnum.String:
|
|
2012
|
-
case import_echo_schema10.FormatEnum.Ref: {
|
|
2013
|
-
return formatScalar(type);
|
|
2014
|
-
}
|
|
2015
|
-
case import_echo_schema10.FormatEnum.Percent: {
|
|
2016
|
-
return String(value * 100);
|
|
2017
|
-
}
|
|
2018
|
-
case import_echo_schema10.FormatEnum.Currency: {
|
|
2019
|
-
return String(value);
|
|
2020
|
-
}
|
|
2021
|
-
case import_echo_schema10.FormatEnum.DateTime: {
|
|
2022
|
-
const date = new Date(value);
|
|
2023
|
-
return date.toISOString();
|
|
2024
|
-
}
|
|
2025
|
-
case import_echo_schema10.FormatEnum.Date: {
|
|
2026
|
-
const date = new Date(value);
|
|
2027
|
-
return date.toISOString().split("T")[0];
|
|
2028
|
-
}
|
|
2029
|
-
case import_echo_schema10.FormatEnum.Time: {
|
|
2030
|
-
const date = new Date(value);
|
|
2031
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
2032
|
-
}
|
|
2033
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
2034
|
-
if (value === null || value === void 0) {
|
|
2035
|
-
return "";
|
|
2036
|
-
}
|
|
2037
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
2038
|
-
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
2039
|
-
return `${latitude},${longitude}`;
|
|
2040
|
-
}
|
|
2041
|
-
return String(value);
|
|
2042
|
-
}
|
|
2043
|
-
default: {
|
|
2044
|
-
return String(value);
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
};
|
|
2048
2167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2049
2168
|
0 && (module.exports = {
|
|
2050
2169
|
BooleanInput,
|
|
@@ -2073,8 +2192,10 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
2073
2192
|
ViewEditor,
|
|
2074
2193
|
cellClassesForFieldType,
|
|
2075
2194
|
controlItemClasses,
|
|
2195
|
+
findArrayElementType,
|
|
2076
2196
|
formatForDisplay,
|
|
2077
2197
|
formatForEditing,
|
|
2198
|
+
getRefProps,
|
|
2078
2199
|
parseValue,
|
|
2079
2200
|
pathNotUniqueError,
|
|
2080
2201
|
translations,
|
|
@@ -2082,6 +2203,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
2082
2203
|
useFormContext,
|
|
2083
2204
|
useFormValues,
|
|
2084
2205
|
useInputProps,
|
|
2206
|
+
useQueryRefOptions,
|
|
2085
2207
|
useRefQueryLookupHandler
|
|
2086
2208
|
});
|
|
2087
2209
|
//# sourceMappingURL=index.cjs.map
|