@overmap-ai/forms 1.0.32-react-flow-david-fixes.1 → 1.0.32-react-flow-david-fixes.2
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/form/index.d.ts +1 -1
- package/dist/form/utils.d.ts +9 -1
- package/dist/forms.js +50 -2
- package/dist/forms.umd.cjs +48 -0
- package/package.json +1 -1
package/dist/form/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export * from './constants';
|
|
|
3
3
|
export * from './fields';
|
|
4
4
|
export * from './renderer';
|
|
5
5
|
export type * from './typings';
|
|
6
|
-
export { initializeFieldValues, validateFields } from './utils';
|
|
6
|
+
export { initializeFieldValues, separateFilesFromFields, separateFilesFromFieldValues, validateFields } from './utils';
|
package/dist/form/utils.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { FormikErrors } from 'formik';
|
|
2
2
|
import { FormBuilderValues } from './builder';
|
|
3
|
-
import { AnyFormElement } from './fields';
|
|
3
|
+
import { AnyFormElement, SerializedField } from './fields';
|
|
4
4
|
import { FieldValues } from './typings';
|
|
5
5
|
export declare const hasKeys: (errors: object) => boolean;
|
|
6
6
|
export declare const validateFields: (fields: AnyFormElement[], values: FieldValues | FormBuilderValues) => FormikErrors<FieldValues | FormBuilderValues> | undefined;
|
|
7
7
|
export declare const initializeFieldValues: (fields: AnyFormElement[], values: FieldValues) => FieldValues;
|
|
8
8
|
export declare const changedFieldValues: (fields: AnyFormElement[], values1: FieldValues, values2: FieldValues) => FieldValues;
|
|
9
|
+
export declare const separateFilesFromFieldValues: (values: FieldValues) => {
|
|
10
|
+
values: FieldValues;
|
|
11
|
+
files: Record<string, File[]>;
|
|
12
|
+
};
|
|
13
|
+
export declare const separateFilesFromFields: (fields: SerializedField[]) => Promise<{
|
|
14
|
+
fields: SerializedField[];
|
|
15
|
+
images: Record<string, File>;
|
|
16
|
+
}>;
|
package/dist/forms.js
CHANGED
|
@@ -13,7 +13,7 @@ import { DirectedGraph } from "graphology";
|
|
|
13
13
|
import { willCreateCycle } from "graphology-dag";
|
|
14
14
|
import { v4 } from "uuid";
|
|
15
15
|
import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd";
|
|
16
|
-
import { Copy, Download, X, Plus, Check, ChevronDown, Minus, Circle, Maximize, FileWarning, File, Upload, Trash2, Settings } from "lucide-react";
|
|
16
|
+
import { Copy, Download, X, Plus, Check, ChevronDown, Minus, Circle, Maximize, FileWarning, File as File$1, Upload, Trash2, Settings } from "lucide-react";
|
|
17
17
|
import * as ReactDOM from "react-dom";
|
|
18
18
|
import ReactDOM__default from "react-dom";
|
|
19
19
|
import { saveAs } from "file-saver";
|
|
@@ -31947,7 +31947,7 @@ const ImageCard = memo(
|
|
|
31947
31947
|
"bg-transparent": !file
|
|
31948
31948
|
}),
|
|
31949
31949
|
children: [
|
|
31950
|
-
error ? /* @__PURE__ */ jsx(FileWarning, { className: "h-4 w-4" }) : file && /* @__PURE__ */ jsx(File, { className: "h-4 w-4", style: { color: "var(--base-a11)" } }),
|
|
31950
|
+
error ? /* @__PURE__ */ jsx(FileWarning, { className: "h-4 w-4" }) : file && /* @__PURE__ */ jsx(File$1, { className: "h-4 w-4", style: { color: "var(--base-a11)" } }),
|
|
31951
31951
|
/* @__PURE__ */ jsx(Text, { className: "truncate", size: "sm", children: error ?? (file == null ? void 0 : file.name) }),
|
|
31952
31952
|
rightSlot
|
|
31953
31953
|
]
|
|
@@ -34529,6 +34529,52 @@ const changedFieldValues = (fields, values1, values2) => {
|
|
|
34529
34529
|
return acc;
|
|
34530
34530
|
}, {});
|
|
34531
34531
|
};
|
|
34532
|
+
const isArrayOfFiles = (value) => {
|
|
34533
|
+
return Array.isArray(value) && value[0] instanceof File;
|
|
34534
|
+
};
|
|
34535
|
+
const separateFilesFromFieldValues = (values) => {
|
|
34536
|
+
const files = {};
|
|
34537
|
+
const newValues = {};
|
|
34538
|
+
for (const key in values) {
|
|
34539
|
+
const value = values[key];
|
|
34540
|
+
if (value instanceof File) {
|
|
34541
|
+
files[key] = [value];
|
|
34542
|
+
} else if (isArrayOfFiles(value)) {
|
|
34543
|
+
files[key] = value;
|
|
34544
|
+
} else if (value !== void 0) {
|
|
34545
|
+
newValues[key] = value;
|
|
34546
|
+
}
|
|
34547
|
+
}
|
|
34548
|
+
return { values: newValues, files };
|
|
34549
|
+
};
|
|
34550
|
+
const separateFilesFromFields = async (fields) => {
|
|
34551
|
+
const images = {};
|
|
34552
|
+
const newFields = [];
|
|
34553
|
+
for (const section of fields) {
|
|
34554
|
+
if (section.type !== "section") {
|
|
34555
|
+
throw new Error(`Expected ISerializedField type to be a section. Got ${section.type} instead.`);
|
|
34556
|
+
}
|
|
34557
|
+
const { fields: sectionFields } = section;
|
|
34558
|
+
const newSectionFields = [];
|
|
34559
|
+
for (const field of sectionFields) {
|
|
34560
|
+
if (field.image) {
|
|
34561
|
+
if (field.image instanceof Promise) {
|
|
34562
|
+
try {
|
|
34563
|
+
images[field.identifier] = await field.image;
|
|
34564
|
+
} catch (e) {
|
|
34565
|
+
console.error("Failed to get image from promise", e);
|
|
34566
|
+
}
|
|
34567
|
+
} else {
|
|
34568
|
+
images[field.identifier] = field.image;
|
|
34569
|
+
}
|
|
34570
|
+
delete field.image;
|
|
34571
|
+
}
|
|
34572
|
+
newSectionFields.push(field);
|
|
34573
|
+
}
|
|
34574
|
+
newFields.push({ ...section, fields: newSectionFields });
|
|
34575
|
+
}
|
|
34576
|
+
return { fields: newFields, images };
|
|
34577
|
+
};
|
|
34532
34578
|
const FieldSettingsPopover = memo((props) => {
|
|
34533
34579
|
const { popoverInputs, hasError, ...rest } = props;
|
|
34534
34580
|
return /* @__PURE__ */ jsxs(Popover.Root, { children: [
|
|
@@ -35984,6 +36030,8 @@ export {
|
|
|
35984
36030
|
maxFileSizeB,
|
|
35985
36031
|
maxFileSizeKB,
|
|
35986
36032
|
maxFileSizeMB,
|
|
36033
|
+
separateFilesFromFieldValues,
|
|
36034
|
+
separateFilesFromFields,
|
|
35987
36035
|
serializeFieldValues,
|
|
35988
36036
|
useFieldInput,
|
|
35989
36037
|
useFieldInputs,
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -34531,6 +34531,52 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
34531
34531
|
return acc;
|
|
34532
34532
|
}, {});
|
|
34533
34533
|
};
|
|
34534
|
+
const isArrayOfFiles = (value) => {
|
|
34535
|
+
return Array.isArray(value) && value[0] instanceof File;
|
|
34536
|
+
};
|
|
34537
|
+
const separateFilesFromFieldValues = (values) => {
|
|
34538
|
+
const files = {};
|
|
34539
|
+
const newValues = {};
|
|
34540
|
+
for (const key in values) {
|
|
34541
|
+
const value = values[key];
|
|
34542
|
+
if (value instanceof File) {
|
|
34543
|
+
files[key] = [value];
|
|
34544
|
+
} else if (isArrayOfFiles(value)) {
|
|
34545
|
+
files[key] = value;
|
|
34546
|
+
} else if (value !== void 0) {
|
|
34547
|
+
newValues[key] = value;
|
|
34548
|
+
}
|
|
34549
|
+
}
|
|
34550
|
+
return { values: newValues, files };
|
|
34551
|
+
};
|
|
34552
|
+
const separateFilesFromFields = async (fields) => {
|
|
34553
|
+
const images = {};
|
|
34554
|
+
const newFields = [];
|
|
34555
|
+
for (const section of fields) {
|
|
34556
|
+
if (section.type !== "section") {
|
|
34557
|
+
throw new Error(`Expected ISerializedField type to be a section. Got ${section.type} instead.`);
|
|
34558
|
+
}
|
|
34559
|
+
const { fields: sectionFields } = section;
|
|
34560
|
+
const newSectionFields = [];
|
|
34561
|
+
for (const field of sectionFields) {
|
|
34562
|
+
if (field.image) {
|
|
34563
|
+
if (field.image instanceof Promise) {
|
|
34564
|
+
try {
|
|
34565
|
+
images[field.identifier] = await field.image;
|
|
34566
|
+
} catch (e) {
|
|
34567
|
+
console.error("Failed to get image from promise", e);
|
|
34568
|
+
}
|
|
34569
|
+
} else {
|
|
34570
|
+
images[field.identifier] = field.image;
|
|
34571
|
+
}
|
|
34572
|
+
delete field.image;
|
|
34573
|
+
}
|
|
34574
|
+
newSectionFields.push(field);
|
|
34575
|
+
}
|
|
34576
|
+
newFields.push({ ...section, fields: newSectionFields });
|
|
34577
|
+
}
|
|
34578
|
+
return { fields: newFields, images };
|
|
34579
|
+
};
|
|
34534
34580
|
const FieldSettingsPopover = React.memo((props) => {
|
|
34535
34581
|
const { popoverInputs, hasError, ...rest } = props;
|
|
34536
34582
|
return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Popover.Root, { children: [
|
|
@@ -35985,6 +36031,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
35985
36031
|
exports2.maxFileSizeB = maxFileSizeB;
|
|
35986
36032
|
exports2.maxFileSizeKB = maxFileSizeKB;
|
|
35987
36033
|
exports2.maxFileSizeMB = maxFileSizeMB;
|
|
36034
|
+
exports2.separateFilesFromFieldValues = separateFilesFromFieldValues;
|
|
36035
|
+
exports2.separateFilesFromFields = separateFilesFromFields;
|
|
35988
36036
|
exports2.serializeFieldValues = serializeFieldValues;
|
|
35989
36037
|
exports2.useFieldInput = useFieldInput;
|
|
35990
36038
|
exports2.useFieldInputs = useFieldInputs;
|