@overmap-ai/forms 1.0.10 → 1.0.11-fix-dropdown-buttons.0
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/fields/UploadField/utils.d.ts +1 -1
- package/dist/forms.js +19 -11
- package/dist/forms.js.map +1 -1
- package/dist/forms.umd.cjs +19 -11
- package/dist/forms.umd.cjs.map +1 -1
- package/dist/typings.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const convertKilobytesToLargestUnit: (kilobytes: number) => string;
|
package/dist/forms.js
CHANGED
|
@@ -1145,15 +1145,20 @@ const previewImage = "_previewImage_1ig84_1";
|
|
|
1145
1145
|
const styles$2 = {
|
|
1146
1146
|
previewImage
|
|
1147
1147
|
};
|
|
1148
|
-
const
|
|
1149
|
-
const units = ["
|
|
1150
|
-
let sizeInUnit =
|
|
1148
|
+
const convertKilobytesToLargestUnit = (kilobytes) => {
|
|
1149
|
+
const units = ["kilobyte", "megabyte"];
|
|
1150
|
+
let sizeInUnit = kilobytes;
|
|
1151
1151
|
let unitIndex = 0;
|
|
1152
1152
|
while (sizeInUnit > 1024 && unitIndex < units.length - 1) {
|
|
1153
1153
|
sizeInUnit /= 1024;
|
|
1154
1154
|
unitIndex++;
|
|
1155
1155
|
}
|
|
1156
|
-
const formatter = new Intl.NumberFormat([], {
|
|
1156
|
+
const formatter = new Intl.NumberFormat([], {
|
|
1157
|
+
// 0 for kilobytes, 1 for megabytes
|
|
1158
|
+
maximumFractionDigits: unitIndex,
|
|
1159
|
+
style: "unit",
|
|
1160
|
+
unit: units[unitIndex]
|
|
1161
|
+
});
|
|
1157
1162
|
return formatter.format(sizeInUnit);
|
|
1158
1163
|
};
|
|
1159
1164
|
const NumberInput = memo(function NumberInput22(props) {
|
|
@@ -1167,7 +1172,7 @@ const NumberInput = memo(function NumberInput22(props) {
|
|
|
1167
1172
|
if (helpText)
|
|
1168
1173
|
return helpText;
|
|
1169
1174
|
if (field.maxFileSize) {
|
|
1170
|
-
const size =
|
|
1175
|
+
const size = convertKilobytesToLargestUnit(field.maxFileSize);
|
|
1171
1176
|
return `Maximum file size: ${size}`;
|
|
1172
1177
|
}
|
|
1173
1178
|
return null;
|
|
@@ -1235,7 +1240,7 @@ const DisplayFile = memo(function DisplayFile2({ file, field, onRemove, disabled
|
|
|
1235
1240
|
}
|
|
1236
1241
|
if (resolvedFile) {
|
|
1237
1242
|
name2 = resolvedFile.name;
|
|
1238
|
-
size2 =
|
|
1243
|
+
size2 = convertKilobytesToLargestUnit(resolvedFile.size);
|
|
1239
1244
|
} else {
|
|
1240
1245
|
name2 = "Downloading...";
|
|
1241
1246
|
size2 = "...";
|
|
@@ -1271,7 +1276,7 @@ const DisplayFile = memo(function DisplayFile2({ file, field, onRemove, disabled
|
|
|
1271
1276
|
url && /* @__PURE__ */ jsx("img", { className: styles$2.previewImage, src: url, alt: name })
|
|
1272
1277
|
] }) });
|
|
1273
1278
|
});
|
|
1274
|
-
const largestSupportedSize = 50 * 1024
|
|
1279
|
+
const largestSupportedSize = 50 * 1024;
|
|
1275
1280
|
const _UploadField = class _UploadField extends BaseField {
|
|
1276
1281
|
constructor(options) {
|
|
1277
1282
|
const { extensions, maximum_files, maximum_size, ...base } = options;
|
|
@@ -1298,11 +1303,13 @@ const _UploadField = class _UploadField extends BaseField {
|
|
|
1298
1303
|
required: false,
|
|
1299
1304
|
minimum: 1,
|
|
1300
1305
|
maximum: 10,
|
|
1301
|
-
identifier: "maximum_files"
|
|
1306
|
+
identifier: "maximum_files",
|
|
1307
|
+
integers: true
|
|
1302
1308
|
}),
|
|
1303
1309
|
new NumberField({
|
|
1310
|
+
// TODO: Default value
|
|
1304
1311
|
label: "What is the maximum size of each file?",
|
|
1305
|
-
description: "Maximum file size in
|
|
1312
|
+
description: "Maximum file size in kilobytes.",
|
|
1306
1313
|
required: false,
|
|
1307
1314
|
identifier: "maximum_size",
|
|
1308
1315
|
minimum: 1,
|
|
@@ -1345,7 +1352,7 @@ const _UploadField = class _UploadField extends BaseField {
|
|
|
1345
1352
|
const maxFiles = this.maxFiles ?? 1;
|
|
1346
1353
|
validators.push((value) => {
|
|
1347
1354
|
if (value && value.some((file) => file.size > maxFileSize)) {
|
|
1348
|
-
return `Files must be at most ${
|
|
1355
|
+
return `Files must be at most ${convertKilobytesToLargestUnit(maxFileSize)}.`;
|
|
1349
1356
|
}
|
|
1350
1357
|
});
|
|
1351
1358
|
validators.push((value) => {
|
|
@@ -2125,13 +2132,14 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2125
2132
|
trigger: /* @__PURE__ */ jsx(IconButton, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ jsx(DotsVerticalIcon, {}) }),
|
|
2126
2133
|
closeOnSelect: false,
|
|
2127
2134
|
items: actions.map((Action) => {
|
|
2128
|
-
var _a;
|
|
2135
|
+
var _a, _b;
|
|
2129
2136
|
if (Action.disableOnMobile)
|
|
2130
2137
|
return null;
|
|
2131
2138
|
const Wrapper = Action.Wrapper ?? DefaultWrapper;
|
|
2132
2139
|
return {
|
|
2133
2140
|
...Action.buttonProps,
|
|
2134
2141
|
onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
|
|
2142
|
+
onClick: (_b = Action.buttonProps) == null ? void 0 : _b.onClick,
|
|
2135
2143
|
content: /* @__PURE__ */ jsx(Wrapper, { ...Action.wrapperProps, children: /* @__PURE__ */ jsxs(Flex, { gap: "2", align: "center", children: [
|
|
2136
2144
|
/* @__PURE__ */ jsx(Action.Icon, {}),
|
|
2137
2145
|
Action.text
|