@overmap-ai/core 1.0.34 → 1.0.35-add-image-to-forms.1
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.
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { ChangeEvent } from "react";
|
|
2
|
+
import { FieldTypeIdentifier } from "../typings.ts";
|
|
2
3
|
interface FieldActionsProps {
|
|
3
4
|
index: number;
|
|
5
|
+
type: FieldTypeIdentifier;
|
|
4
6
|
sectionIndex?: number;
|
|
5
7
|
remove: () => void;
|
|
6
8
|
duplicate: () => void;
|
|
7
9
|
move: (direction: "up" | "down") => void;
|
|
10
|
+
upload?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
8
11
|
}
|
|
9
12
|
export declare const FieldActions: import("react").MemoExoticComponent<(props: FieldActionsProps) => import("react/jsx-runtime").JSX.Element>;
|
|
10
13
|
export {};
|
package/dist/overmap-core.js
CHANGED
|
@@ -6567,6 +6567,24 @@ var GearIcon = /* @__PURE__ */ forwardRef(function(_ref, forwardedRef) {
|
|
|
6567
6567
|
clipRule: "evenodd"
|
|
6568
6568
|
}));
|
|
6569
6569
|
});
|
|
6570
|
+
var _excluded$2C = ["color"];
|
|
6571
|
+
var ImageIcon = /* @__PURE__ */ forwardRef(function(_ref, forwardedRef) {
|
|
6572
|
+
var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, props = _objectWithoutPropertiesLoose(_ref, _excluded$2C);
|
|
6573
|
+
return createElement("svg", Object.assign({
|
|
6574
|
+
width: "15",
|
|
6575
|
+
height: "15",
|
|
6576
|
+
viewBox: "0 0 15 15",
|
|
6577
|
+
fill: "none",
|
|
6578
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
6579
|
+
}, props, {
|
|
6580
|
+
ref: forwardedRef
|
|
6581
|
+
}), createElement("path", {
|
|
6582
|
+
d: "M2.5 1H12.5C13.3284 1 14 1.67157 14 2.5V12.5C14 13.3284 13.3284 14 12.5 14H2.5C1.67157 14 1 13.3284 1 12.5V2.5C1 1.67157 1.67157 1 2.5 1ZM2.5 2C2.22386 2 2 2.22386 2 2.5V8.3636L3.6818 6.6818C3.76809 6.59551 3.88572 6.54797 4.00774 6.55007C4.12975 6.55216 4.24568 6.60372 4.32895 6.69293L7.87355 10.4901L10.6818 7.6818C10.8575 7.50607 11.1425 7.50607 11.3182 7.6818L13 9.3636V2.5C13 2.22386 12.7761 2 12.5 2H2.5ZM2 12.5V9.6364L3.98887 7.64753L7.5311 11.4421L8.94113 13H2.5C2.22386 13 2 12.7761 2 12.5ZM12.5 13H10.155L8.48336 11.153L11 8.6364L13 10.6364V12.5C13 12.7761 12.7761 13 12.5 13ZM6.64922 5.5C6.64922 5.03013 7.03013 4.64922 7.5 4.64922C7.96987 4.64922 8.35078 5.03013 8.35078 5.5C8.35078 5.96987 7.96987 6.35078 7.5 6.35078C7.03013 6.35078 6.64922 5.96987 6.64922 5.5ZM7.5 3.74922C6.53307 3.74922 5.74922 4.53307 5.74922 5.5C5.74922 6.46693 6.53307 7.25078 7.5 7.25078C8.46693 7.25078 9.25078 6.46693 9.25078 5.5C9.25078 4.53307 8.46693 3.74922 7.5 3.74922Z",
|
|
6583
|
+
fill: color,
|
|
6584
|
+
fillRule: "evenodd",
|
|
6585
|
+
clipRule: "evenodd"
|
|
6586
|
+
}));
|
|
6587
|
+
});
|
|
6570
6588
|
var _excluded$2E = ["color"];
|
|
6571
6589
|
var InputIcon = /* @__PURE__ */ forwardRef(function(_ref, forwardedRef) {
|
|
6572
6590
|
var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, props = _objectWithoutPropertiesLoose(_ref, _excluded$2E);
|
|
@@ -9442,7 +9460,6 @@ const emptyUploadField = {
|
|
|
9442
9460
|
maximum_size: void 0,
|
|
9443
9461
|
maximum_files: 1
|
|
9444
9462
|
};
|
|
9445
|
-
const largestSupportedSize = 50;
|
|
9446
9463
|
const _UploadField = class _UploadField extends BaseField {
|
|
9447
9464
|
constructor(options) {
|
|
9448
9465
|
const { extensions, maximum_files, maximum_size, ...base } = options;
|
|
@@ -9480,11 +9497,11 @@ const _UploadField = class _UploadField extends BaseField {
|
|
|
9480
9497
|
field: new NumberField({
|
|
9481
9498
|
// TODO: Default value
|
|
9482
9499
|
label: "What is the maximum size of each file?",
|
|
9483
|
-
description: `Maximum file size in megabytes (between 1MB–${
|
|
9500
|
+
description: `Maximum file size in megabytes (between 1MB–${maxFileSizeMB}MB).`,
|
|
9484
9501
|
required: false,
|
|
9485
9502
|
identifier: `${path}maximum_size`,
|
|
9486
9503
|
minimum: 1,
|
|
9487
|
-
maximum:
|
|
9504
|
+
maximum: maxFileSizeMB,
|
|
9488
9505
|
integers: true
|
|
9489
9506
|
}),
|
|
9490
9507
|
showDirectly: false
|
|
@@ -9524,7 +9541,7 @@ const _UploadField = class _UploadField extends BaseField {
|
|
|
9524
9541
|
}
|
|
9525
9542
|
getFieldValidators() {
|
|
9526
9543
|
const validators = super.getFieldValidators();
|
|
9527
|
-
const maxFileSizeInMB = this.maxFileSize ??
|
|
9544
|
+
const maxFileSizeInMB = this.maxFileSize ?? maxFileSizeMB;
|
|
9528
9545
|
const maxFileSizeInB = maxFileSizeInMB * 1e3 * 1e3;
|
|
9529
9546
|
const maxFiles = this.maxFiles || 1;
|
|
9530
9547
|
validators.push((value) => {
|
|
@@ -9586,6 +9603,9 @@ const FieldTypeToEmptyFieldMapping = {
|
|
|
9586
9603
|
"multi-string": emptyMultiStringField,
|
|
9587
9604
|
"multi-select": emptyMultiSelectField
|
|
9588
9605
|
};
|
|
9606
|
+
const maxFileSizeMB = 50;
|
|
9607
|
+
const maxFileSizeKB = maxFileSizeMB * 1e3;
|
|
9608
|
+
const maxFileSizeB = maxFileSizeKB * 1e3;
|
|
9589
9609
|
const deserializeField = (serializedField) => {
|
|
9590
9610
|
const fieldType = serializedField.type;
|
|
9591
9611
|
const fieldCls = FieldTypeToClsMapping[fieldType];
|
|
@@ -10263,8 +10283,12 @@ const forMobile = (mobile, display) => ({
|
|
|
10263
10283
|
sm: mobile ? "none" : display
|
|
10264
10284
|
});
|
|
10265
10285
|
const FieldActions = memo((props) => {
|
|
10266
|
-
const { index: index2, sectionIndex, remove: remove2, duplicate, move } = props;
|
|
10286
|
+
const { index: index2, type, sectionIndex, remove: remove2, duplicate, move, upload } = props;
|
|
10287
|
+
if (type !== "section" && !upload) {
|
|
10288
|
+
throw new Error("Upload function prop must be defined for non-section fields.");
|
|
10289
|
+
}
|
|
10267
10290
|
const { values } = useFormikContext();
|
|
10291
|
+
const fileInputRef = useRef(null);
|
|
10268
10292
|
const actions = useMemo(() => {
|
|
10269
10293
|
const actions2 = [
|
|
10270
10294
|
{
|
|
@@ -10275,11 +10299,24 @@ const FieldActions = memo((props) => {
|
|
|
10275
10299
|
},
|
|
10276
10300
|
{
|
|
10277
10301
|
Icon: TrashIcon,
|
|
10278
|
-
buttonProps: { onClick: remove2 },
|
|
10279
10302
|
key: "delete",
|
|
10280
|
-
text: "Delete"
|
|
10303
|
+
text: "Delete",
|
|
10304
|
+
buttonProps: { onClick: remove2 }
|
|
10281
10305
|
}
|
|
10282
10306
|
];
|
|
10307
|
+
if (type !== "section") {
|
|
10308
|
+
actions2.unshift({
|
|
10309
|
+
Icon: ImageIcon,
|
|
10310
|
+
key: "upload",
|
|
10311
|
+
text: "Upload image",
|
|
10312
|
+
buttonProps: {
|
|
10313
|
+
onClick: () => {
|
|
10314
|
+
var _a2;
|
|
10315
|
+
(_a2 = fileInputRef.current) == null ? void 0 : _a2.click();
|
|
10316
|
+
}
|
|
10317
|
+
}
|
|
10318
|
+
});
|
|
10319
|
+
}
|
|
10283
10320
|
if (sectionIndex === void 0 && index2 !== values.fields.length - 1 || sectionIndex !== void 0 && (sectionIndex < values.fields.length - 1 || index2 !== values.fields[sectionIndex].fields.length - 1)) {
|
|
10284
10321
|
actions2.unshift({
|
|
10285
10322
|
Icon: ArrowDownIcon,
|
|
@@ -10305,7 +10342,7 @@ const FieldActions = memo((props) => {
|
|
|
10305
10342
|
});
|
|
10306
10343
|
}
|
|
10307
10344
|
return actions2;
|
|
10308
|
-
}, [duplicate, index2, move, remove2, sectionIndex, values.fields]);
|
|
10345
|
+
}, [duplicate, index2, move, remove2, sectionIndex, type, values.fields]);
|
|
10309
10346
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
10310
10347
|
/* @__PURE__ */ jsx(Flex, { display: forMobile(false, "flex"), direction: "column", gap: "5", mx: "2", children: actions.map((Action) => /* @__PURE__ */ jsx(
|
|
10311
10348
|
IconButton,
|
|
@@ -10334,7 +10371,8 @@ const FieldActions = memo((props) => {
|
|
|
10334
10371
|
};
|
|
10335
10372
|
})
|
|
10336
10373
|
}
|
|
10337
|
-
) })
|
|
10374
|
+
) }),
|
|
10375
|
+
type !== "section" && /* @__PURE__ */ jsx("input", { style: { display: "none" }, ref: fileInputRef, type: "file", accept: "image/*", onChange: upload })
|
|
10338
10376
|
] });
|
|
10339
10377
|
});
|
|
10340
10378
|
FieldActions.displayName = "FieldActions";
|
|
@@ -10605,6 +10643,7 @@ const FieldWithActions = memo((props) => {
|
|
|
10605
10643
|
const { field, index: index2, sectionIndex, takenLabels, remove: remove2 } = props;
|
|
10606
10644
|
const { setFieldValue, values } = useFormikContext();
|
|
10607
10645
|
const { reorderField } = useFieldReordering();
|
|
10646
|
+
const { showError } = useToast();
|
|
10608
10647
|
const parentPath = `fields.${sectionIndex}.fields`;
|
|
10609
10648
|
const editFieldProps = useMemo(
|
|
10610
10649
|
() => ({
|
|
@@ -10648,6 +10687,25 @@ const FieldWithActions = memo((props) => {
|
|
|
10648
10687
|
},
|
|
10649
10688
|
[sectionIndex, values.fields, index2, reorderField, setFieldValue]
|
|
10650
10689
|
);
|
|
10690
|
+
const uploadImage = useCallback(
|
|
10691
|
+
(event) => {
|
|
10692
|
+
const { files } = event.target;
|
|
10693
|
+
console.log(files);
|
|
10694
|
+
if (files && files.length === 1) {
|
|
10695
|
+
const file = files.item(0);
|
|
10696
|
+
if (!file)
|
|
10697
|
+
return;
|
|
10698
|
+
if (file.size > maxFileSizeB) {
|
|
10699
|
+
showError({
|
|
10700
|
+
title: "File upload error",
|
|
10701
|
+
description: `The file ${file.name} exceeded the maximum file size`
|
|
10702
|
+
});
|
|
10703
|
+
return;
|
|
10704
|
+
}
|
|
10705
|
+
}
|
|
10706
|
+
},
|
|
10707
|
+
[showError]
|
|
10708
|
+
);
|
|
10651
10709
|
return /* @__PURE__ */ jsx(Draggable, { draggableId: field.identifier, index: index2, children: (draggableProvided) => /* @__PURE__ */ jsx(
|
|
10652
10710
|
Card,
|
|
10653
10711
|
{
|
|
@@ -10666,10 +10724,12 @@ const FieldWithActions = memo((props) => {
|
|
|
10666
10724
|
FieldActions,
|
|
10667
10725
|
{
|
|
10668
10726
|
index: index2,
|
|
10727
|
+
type: field.type,
|
|
10669
10728
|
sectionIndex,
|
|
10670
10729
|
remove: remove2,
|
|
10671
10730
|
duplicate: duplicateField,
|
|
10672
|
-
move: moveField
|
|
10731
|
+
move: moveField,
|
|
10732
|
+
upload: uploadImage
|
|
10673
10733
|
}
|
|
10674
10734
|
)
|
|
10675
10735
|
] })
|
|
@@ -10871,6 +10931,7 @@ const FieldSectionWithActions = memo((props) => {
|
|
|
10871
10931
|
FieldActions,
|
|
10872
10932
|
{
|
|
10873
10933
|
index: sectionIndex,
|
|
10934
|
+
type: field.type,
|
|
10874
10935
|
remove: removeSection,
|
|
10875
10936
|
duplicate: duplicateSection,
|
|
10876
10937
|
move: moveSection
|