@homefile/components-v2 2.14.28 → 2.14.30
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/components/forms/dynamicForm/fields/AIGridField.js +4 -2
- package/dist/components/forms/dynamicForm/fields/SingleImage.d.ts +2 -2
- package/dist/components/forms/dynamicForm/fields/SingleImage.js +1 -3
- package/dist/hooks/forms/useDynamicForm.d.ts +2 -2
- package/dist/interfaces/forms/ItemFormPanel/ItemFormTabs.interface.d.ts +1 -1
- package/dist/interfaces/forms/dynamicForm/DynamicForm.interface.d.ts +1 -1
- package/dist/interfaces/forms/dynamicForm/fields/FileField.interface.d.ts +3 -0
- package/dist/interfaces/forms/dynamicForm/fields/GridField.interface.d.ts +3 -3
- package/package.json +1 -1
- package/src/components/forms/dynamicForm/fields/AIGridField.tsx +8 -5
- package/src/components/forms/dynamicForm/fields/SingleImage.tsx +3 -5
- package/src/hooks/forms/useDynamicForm.ts +2 -2
- package/src/interfaces/forms/ItemFormPanel/ItemFormTabs.interface.ts +7 -2
- package/src/interfaces/forms/dynamicForm/DynamicForm.interface.ts +1 -1
- package/src/interfaces/forms/dynamicForm/fields/FileField.interface.ts +4 -0
- package/src/interfaces/forms/dynamicForm/fields/GridField.interface.ts +2 -2
|
@@ -6,7 +6,7 @@ import { fieldIcons } from '../../../../helpers';
|
|
|
6
6
|
import { colors } from '../../../../theme/colors';
|
|
7
7
|
import { useState } from 'react';
|
|
8
8
|
export const AIGridField = ({ children, onAISend, onRemove, onUpload, }) => {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
10
|
const [file, setFile] = useState(undefined);
|
|
11
11
|
const { watch } = useFormContext();
|
|
12
12
|
const textChild = children === null || children === void 0 ? void 0 : children.find(({ type }) => type === 'text' || type === 'string');
|
|
@@ -27,6 +27,8 @@ export const AIGridField = ({ children, onAISend, onRemove, onUpload, }) => {
|
|
|
27
27
|
? fieldIcons[imageField.icon]
|
|
28
28
|
: undefined,
|
|
29
29
|
};
|
|
30
|
+
const imageId = (_g = imageField === null || imageField === void 0 ? void 0 : imageField.id) !== null && _g !== void 0 ? _g : '';
|
|
31
|
+
const imageValue = watch(imageId);
|
|
30
32
|
const model = watch(String(textChild === null || textChild === void 0 ? void 0 : textChild.id));
|
|
31
33
|
const handleUpload = (files) => {
|
|
32
34
|
const file = files[0];
|
|
@@ -43,5 +45,5 @@ export const AIGridField = ({ children, onAISend, onRemove, onUpload, }) => {
|
|
|
43
45
|
}
|
|
44
46
|
onAISend === null || onAISend === void 0 ? void 0 : onAISend(form);
|
|
45
47
|
};
|
|
46
|
-
return (_jsxs(Flex, { align: "flex-end", gap: "base", children: [_jsxs(Flex, { align: "center", gap: "base", children: [_jsx(SingleImage, Object.assign({}, imageProps, { onUpload: handleUpload, onRemove: onRemove, value:
|
|
48
|
+
return (_jsxs(Flex, { align: "flex-end", gap: "base", children: [_jsxs(Flex, { align: "center", gap: "base", children: [_jsx(SingleImage, Object.assign({}, imageProps, { onUpload: handleUpload, onRemove: onRemove, value: String(imageValue) })), _jsx(Text, { fontFamily: "secondary", textAlign: "center", children: "OR" })] }), _jsx(TextField, Object.assign({}, textProps)), _jsx(IconButton, { "aria-label": "Add new address line", variant: "iconOutlined", icon: _jsx(Plus, { size: 28, stroke: colors.blue[3] }), onClick: handleAISend, h: "input.md", disabled: !(model === null || model === void 0 ? void 0 : model.length) && !imageValue })] }));
|
|
47
49
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const SingleImage: ({ onRemove, onUpload, uploading, value, }:
|
|
1
|
+
import { SingleImageI } from '../../../../interfaces';
|
|
2
|
+
export declare const SingleImage: ({ onRemove, onUpload, uploading, value, }: SingleImageI) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,15 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { AspectRatio, Box, Flex, IconButton, Image } from '@chakra-ui/react';
|
|
3
3
|
import { colors } from '../../../../theme/colors';
|
|
4
4
|
import { Close, MobileFileUploader } from '../../..';
|
|
5
|
-
import { handleMapFile } from '../../../../utils';
|
|
6
5
|
export const SingleImage = ({ onRemove, onUpload, uploading = false, value, }) => {
|
|
7
6
|
const handleInputChange = (event) => {
|
|
8
7
|
var _a;
|
|
9
8
|
const fileList = (_a = event.target.files) !== null && _a !== void 0 ? _a : [];
|
|
10
9
|
const files = Array.from(fileList);
|
|
11
10
|
if (files.length > 0) {
|
|
12
|
-
|
|
13
|
-
onUpload === null || onUpload === void 0 ? void 0 : onUpload(selectedFiles);
|
|
11
|
+
onUpload === null || onUpload === void 0 ? void 0 : onUpload(files);
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
14
|
return (_jsxs(Flex, { gap: "2", align: "center", h: "input.md", children: [_jsx(MobileFileUploader, { handleInputChange: handleInputChange, "aria-label": "upload image", minW: "72px" }), value && (_jsxs(Box, { position: "relative", minW: "30px", children: [_jsx(IconButton, { variant: "ghost", "aria-label": "close", maxW: "fit-content", onClick: () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(value), icon: _jsx(Close, { size: 11, stroke: colors.error['2'] }), disabled: uploading, position: "absolute", bg: "neutral.white", p: "0.5", borderRadius: "full", top: "-2", right: "-2", zIndex: "1" }), _jsx(AspectRatio, { maxW: "100%", ratio: 1, children: _jsx(Image, { src: value, objectFit: "cover", alt: "image" }) })] }))] }));
|
|
@@ -2,11 +2,11 @@ import { FieldValues } from 'react-hook-form';
|
|
|
2
2
|
import { FolderFileI, ReportI } from '../../interfaces';
|
|
3
3
|
interface FilesUploadI {
|
|
4
4
|
id: string;
|
|
5
|
-
files: FolderFileI[];
|
|
5
|
+
files: FolderFileI[] | File[];
|
|
6
6
|
}
|
|
7
7
|
interface UseDynamicFormI {
|
|
8
8
|
fields: ReportI[];
|
|
9
|
-
onUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void;
|
|
9
|
+
onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void;
|
|
10
10
|
}
|
|
11
11
|
export declare const useDynamicForm: ({ fields, onUpload }: UseDynamicFormI) => {
|
|
12
12
|
form: import("react-hook-form").UseFormReturn<FieldValues, any, undefined>;
|
|
@@ -3,5 +3,5 @@ export interface ItemFormTabsI extends ItemFormTabImageI {
|
|
|
3
3
|
form?: ReportI[];
|
|
4
4
|
onAISend?: AIGridFieldI['onAISend'];
|
|
5
5
|
searching?: boolean;
|
|
6
|
-
formUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void;
|
|
6
|
+
formUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void;
|
|
7
7
|
}
|
|
@@ -28,7 +28,7 @@ export interface DynamicFormI extends Partial<PartnerFooterI> {
|
|
|
28
28
|
menuItems?: MenuItemI[];
|
|
29
29
|
onAISend?: AIGridFieldI['onAISend'];
|
|
30
30
|
onRemoveImage?: (file: string) => void;
|
|
31
|
-
onUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void;
|
|
31
|
+
onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void;
|
|
32
32
|
searching?: boolean;
|
|
33
33
|
showTitle?: boolean;
|
|
34
34
|
title?: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReportI } from '../../..';
|
|
2
2
|
export interface GridFieldI {
|
|
3
3
|
children: ReportI['children'];
|
|
4
4
|
onRemove?: (file: string) => void;
|
|
5
|
-
onUpload?: (files:
|
|
5
|
+
onUpload?: (files: File[]) => void;
|
|
6
6
|
}
|
|
7
7
|
export interface AIGridFieldI extends GridFieldI {
|
|
8
8
|
onAISend?: (form?: AIFormI) => void;
|
|
9
9
|
}
|
|
10
10
|
export interface AIFormI {
|
|
11
11
|
model?: string;
|
|
12
|
-
file?:
|
|
12
|
+
file?: File;
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -12,9 +12,9 @@ export const AIGridField = ({
|
|
|
12
12
|
onRemove,
|
|
13
13
|
onUpload,
|
|
14
14
|
}: AIGridFieldI) => {
|
|
15
|
-
const [file, setFile] = useState<
|
|
15
|
+
const [file, setFile] = useState<File | undefined>(undefined)
|
|
16
16
|
const { watch } = useFormContext()
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
const textChild = children?.find(
|
|
19
19
|
({ type }) => type === 'text' || type === 'string'
|
|
20
20
|
)
|
|
@@ -38,9 +38,12 @@ export const AIGridField = ({
|
|
|
38
38
|
: undefined,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
const imageId = imageField?.id ?? ''
|
|
42
|
+
const imageValue = watch(imageId)
|
|
43
|
+
|
|
41
44
|
const model = watch(String(textChild?.id))
|
|
42
45
|
|
|
43
|
-
const handleUpload = (files:
|
|
46
|
+
const handleUpload = (files: File[]) => {
|
|
44
47
|
const file = files[0]
|
|
45
48
|
setFile(file)
|
|
46
49
|
onUpload?.(files)
|
|
@@ -64,7 +67,7 @@ export const AIGridField = ({
|
|
|
64
67
|
{...imageProps}
|
|
65
68
|
onUpload={handleUpload}
|
|
66
69
|
onRemove={onRemove}
|
|
67
|
-
value={
|
|
70
|
+
value={String(imageValue)}
|
|
68
71
|
/>
|
|
69
72
|
<Text fontFamily="secondary" textAlign="center">
|
|
70
73
|
OR
|
|
@@ -77,7 +80,7 @@ export const AIGridField = ({
|
|
|
77
80
|
icon={<Plus size={28} stroke={colors.blue[3]} />}
|
|
78
81
|
onClick={handleAISend}
|
|
79
82
|
h="input.md"
|
|
80
|
-
disabled={!model?.length && !
|
|
83
|
+
disabled={!model?.length && !imageValue}
|
|
81
84
|
/>
|
|
82
85
|
</Flex>
|
|
83
86
|
)
|
|
@@ -2,21 +2,19 @@ import { ChangeEvent } from 'react'
|
|
|
2
2
|
import { AspectRatio, Box, Flex, IconButton, Image } from '@chakra-ui/react'
|
|
3
3
|
import { colors } from '@/theme/colors'
|
|
4
4
|
import { Close, MobileFileUploader } from '@/components'
|
|
5
|
-
import {
|
|
6
|
-
import { handleMapFile } from '@/utils'
|
|
5
|
+
import { SingleImageI } from '@/interfaces'
|
|
7
6
|
|
|
8
7
|
export const SingleImage = ({
|
|
9
8
|
onRemove,
|
|
10
9
|
onUpload,
|
|
11
10
|
uploading = false,
|
|
12
11
|
value,
|
|
13
|
-
}:
|
|
12
|
+
}: SingleImageI) => {
|
|
14
13
|
const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
15
14
|
const fileList = event.target.files ?? []
|
|
16
15
|
const files = Array.from(fileList)
|
|
17
16
|
if (files.length > 0) {
|
|
18
|
-
|
|
19
|
-
onUpload?.(selectedFiles)
|
|
17
|
+
onUpload?.(files)
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -5,12 +5,12 @@ import { dynamicFormProxy } from '@/proxies'
|
|
|
5
5
|
|
|
6
6
|
interface FilesUploadI {
|
|
7
7
|
id: string
|
|
8
|
-
files: FolderFileI[]
|
|
8
|
+
files: FolderFileI[] | File[]
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
interface UseDynamicFormI {
|
|
12
12
|
fields: ReportI[]
|
|
13
|
-
onUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void
|
|
13
|
+
onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const useDynamicForm = ({ fields, onUpload }: UseDynamicFormI) => {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ItemFormTabImageI,
|
|
3
|
+
ReportI,
|
|
4
|
+
AIGridFieldI,
|
|
5
|
+
FolderFileI,
|
|
6
|
+
} from '@/interfaces'
|
|
2
7
|
|
|
3
8
|
export interface ItemFormTabsI extends ItemFormTabImageI {
|
|
4
9
|
form?: ReportI[]
|
|
5
10
|
onAISend?: AIGridFieldI['onAISend']
|
|
6
11
|
searching?: boolean
|
|
7
|
-
formUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void
|
|
12
|
+
formUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void
|
|
8
13
|
}
|
|
@@ -136,7 +136,7 @@ export interface DynamicFormI extends Partial<PartnerFooterI> {
|
|
|
136
136
|
menuItems?: MenuItemI[]
|
|
137
137
|
onAISend?: AIGridFieldI['onAISend']
|
|
138
138
|
onRemoveImage?: (file: string) => void
|
|
139
|
-
onUpload?: (filesByFieldId: Record<string, FolderFileI[]>) => void
|
|
139
|
+
onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void
|
|
140
140
|
searching?: boolean
|
|
141
141
|
showTitle?: boolean
|
|
142
142
|
title?: string
|
|
@@ -3,7 +3,7 @@ import { FolderFileI, ReportI } from '@/interfaces'
|
|
|
3
3
|
export interface GridFieldI {
|
|
4
4
|
children: ReportI['children']
|
|
5
5
|
onRemove?: (file: string) => void
|
|
6
|
-
onUpload?: (files:
|
|
6
|
+
onUpload?: (files: File[]) => void
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface AIGridFieldI extends GridFieldI {
|
|
@@ -12,5 +12,5 @@ export interface AIGridFieldI extends GridFieldI {
|
|
|
12
12
|
|
|
13
13
|
export interface AIFormI {
|
|
14
14
|
model?: string
|
|
15
|
-
file?:
|
|
15
|
+
file?: File
|
|
16
16
|
}
|