@overmap-ai/forms 1.0.32-react-flow-david-fixes.1 → 1.0.32-react-flow-david-fixes.3
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 +10 -1
- package/dist/forms.js +62 -2
- package/dist/forms.umd.cjs +60 -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 { awaitPromisesFromFieldValues, initializeFieldValues, separateFilesFromFields, separateFilesFromFieldValues, validateFields, } from './utils';
|
package/dist/form/utils.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { FormikErrors } from 'formik';
|
|
2
2
|
import { FormBuilderValues } from './builder';
|
|
3
|
-
import { AnyFormElement } from './fields';
|
|
3
|
+
import { AnyFormElement, FieldValue, 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
|
+
}>;
|
|
17
|
+
export declare function awaitPromisesFromFieldValues(values: FieldValues): Promise<Record<string, FieldValue | undefined>>;
|
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,63 @@ 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
|
+
};
|
|
34578
|
+
async function awaitPromisesFromFieldValues(values) {
|
|
34579
|
+
const valuesWithoutFiles = {};
|
|
34580
|
+
for (const [key, value] of Object.entries(values)) {
|
|
34581
|
+
if (Array.isArray(value) && value.every((item) => item instanceof Promise)) {
|
|
34582
|
+
valuesWithoutFiles[key] = await Promise.all(value);
|
|
34583
|
+
} else {
|
|
34584
|
+
valuesWithoutFiles[key] = value;
|
|
34585
|
+
}
|
|
34586
|
+
}
|
|
34587
|
+
return valuesWithoutFiles;
|
|
34588
|
+
}
|
|
34532
34589
|
const FieldSettingsPopover = memo((props) => {
|
|
34533
34590
|
const { popoverInputs, hasError, ...rest } = props;
|
|
34534
34591
|
return /* @__PURE__ */ jsxs(Popover.Root, { children: [
|
|
@@ -35970,6 +36027,7 @@ export {
|
|
|
35970
36027
|
TextInput,
|
|
35971
36028
|
UploadField,
|
|
35972
36029
|
UploadInput,
|
|
36030
|
+
awaitPromisesFromFieldValues,
|
|
35973
36031
|
createCondition,
|
|
35974
36032
|
createField,
|
|
35975
36033
|
deserialize,
|
|
@@ -35984,6 +36042,8 @@ export {
|
|
|
35984
36042
|
maxFileSizeB,
|
|
35985
36043
|
maxFileSizeKB,
|
|
35986
36044
|
maxFileSizeMB,
|
|
36045
|
+
separateFilesFromFieldValues,
|
|
36046
|
+
separateFilesFromFields,
|
|
35987
36047
|
serializeFieldValues,
|
|
35988
36048
|
useFieldInput,
|
|
35989
36049
|
useFieldInputs,
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -34531,6 +34531,63 @@ 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
|
+
};
|
|
34580
|
+
async function awaitPromisesFromFieldValues(values) {
|
|
34581
|
+
const valuesWithoutFiles = {};
|
|
34582
|
+
for (const [key, value] of Object.entries(values)) {
|
|
34583
|
+
if (Array.isArray(value) && value.every((item) => item instanceof Promise)) {
|
|
34584
|
+
valuesWithoutFiles[key] = await Promise.all(value);
|
|
34585
|
+
} else {
|
|
34586
|
+
valuesWithoutFiles[key] = value;
|
|
34587
|
+
}
|
|
34588
|
+
}
|
|
34589
|
+
return valuesWithoutFiles;
|
|
34590
|
+
}
|
|
34534
34591
|
const FieldSettingsPopover = React.memo((props) => {
|
|
34535
34592
|
const { popoverInputs, hasError, ...rest } = props;
|
|
34536
34593
|
return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Popover.Root, { children: [
|
|
@@ -35971,6 +36028,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
35971
36028
|
exports2.TextInput = TextInput;
|
|
35972
36029
|
exports2.UploadField = UploadField;
|
|
35973
36030
|
exports2.UploadInput = UploadInput;
|
|
36031
|
+
exports2.awaitPromisesFromFieldValues = awaitPromisesFromFieldValues;
|
|
35974
36032
|
exports2.createCondition = createCondition;
|
|
35975
36033
|
exports2.createField = createField;
|
|
35976
36034
|
exports2.deserialize = deserialize;
|
|
@@ -35985,6 +36043,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
35985
36043
|
exports2.maxFileSizeB = maxFileSizeB;
|
|
35986
36044
|
exports2.maxFileSizeKB = maxFileSizeKB;
|
|
35987
36045
|
exports2.maxFileSizeMB = maxFileSizeMB;
|
|
36046
|
+
exports2.separateFilesFromFieldValues = separateFilesFromFieldValues;
|
|
36047
|
+
exports2.separateFilesFromFields = separateFilesFromFields;
|
|
35988
36048
|
exports2.serializeFieldValues = serializeFieldValues;
|
|
35989
36049
|
exports2.useFieldInput = useFieldInput;
|
|
35990
36050
|
exports2.useFieldInputs = useFieldInputs;
|