@finema/core 3.2.1 → 3.3.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/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "configKey": "core",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import * as lodash from 'lodash-es';
4
4
  import * as theme from '../dist/runtime/theme/index.js';
5
5
 
6
6
  const name = "@finema/core";
7
- const version = "3.2.1";
7
+ const version = "3.3.0";
8
8
 
9
9
  const nuxtAppOptions = {
10
10
  head: {
@@ -39,6 +39,7 @@ import FormInputDateTimeRange from "./InputDateTimeRange/index.vue";
39
39
  import FormInputUploadDropzoneAuto from "./InputUploadDropzoneAuto/index.vue";
40
40
  import FormInputUploadDropzoneAutoMultiple from "./InputUploadDropzoneAutoMultiple/index.vue";
41
41
  import FormInputUploadDropzone from "./InputUploadDropzone/index.vue";
42
+ import FormInputUploadImageAuto from "./InputUploadImageAuto/index.vue";
42
43
  import FormInputTag from "./InputTags/index.vue";
43
44
  import FormInputWYSIWYG from "./InputWYSIWYG/index.vue";
44
45
  import { INPUT_TYPES } from "#core/components/Form/types";
@@ -142,7 +143,10 @@ const componentMap = {
142
143
  },
143
144
  [INPUT_TYPES.UPLOAD_FILE_CLASSIC]: void 0,
144
145
  [INPUT_TYPES.UPLOAD_FILE_CLASSIC_AUTO]: void 0,
145
- [INPUT_TYPES.UPLOAD_IMAGE_AUTO]: void 0,
146
+ [INPUT_TYPES.UPLOAD_IMAGE_AUTO]: {
147
+ component: FormInputUploadImageAuto,
148
+ props: {}
149
+ },
146
150
  [INPUT_TYPES.UPLOAD_DROPZONE]: {
147
151
  component: FormInputUploadDropzone,
148
152
  props: {}
@@ -0,0 +1,26 @@
1
+ import type { IUploadImageAutoProps } from './types.js';
2
+ import type { IFileValue } from '#core/components/Form/types';
3
+ declare const __VLS_export: import("vue").DefineComponent<IUploadImageAutoProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
+ success: (res: IFileValue) => any;
5
+ delete: () => any;
6
+ change: (value: File | undefined) => any;
7
+ }, string, import("vue").PublicProps, Readonly<IUploadImageAutoProps> & Readonly<{
8
+ onSuccess?: ((res: IFileValue) => any) | undefined;
9
+ onDelete?: (() => any) | undefined;
10
+ onChange?: ((value: File | undefined) => any) | undefined;
11
+ }>, {
12
+ selectFileLabel: string;
13
+ selectFileSubLabel: string;
14
+ uploadingLabel: string;
15
+ uploadFailedLabel: string;
16
+ retryLabel: string;
17
+ bodyKey: string;
18
+ responseURL: string;
19
+ responsePath: string;
20
+ responseName: string;
21
+ responseSize: string;
22
+ responseID: string;
23
+ accept: string[] | string;
24
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
25
+ declare const _default: typeof __VLS_export;
26
+ export default _default;
@@ -0,0 +1,131 @@
1
+ <template>
2
+ <FieldWrapper v-bind="wrapperProps">
3
+ <div
4
+ ref="dropzoneRef"
5
+ :class="theme.base()"
6
+ >
7
+ <div :class="theme.wrapper()">
8
+ <!-- Empty State -->
9
+ <EmptyState
10
+ v-if="uploadState.isEmpty.value"
11
+ :theme="theme"
12
+ :select-file-label="selectFileLabel"
13
+ :select-file-sub-label="selectFileSubLabel"
14
+ :placeholder="placeholder"
15
+ @open-file="uploadState.handleOpenFile"
16
+ />
17
+
18
+ <!-- Loading State -->
19
+ <LoadingState
20
+ v-if="uploadState.isUploading.value"
21
+ :theme="theme"
22
+ :selected-file="uploadState.selectedFile.value"
23
+ :percent="uploadState.percent.value"
24
+ :uploading-label="uploadingLabel"
25
+ />
26
+
27
+ <!-- Success State -->
28
+ <SuccessState
29
+ v-if="uploadState.isSuccess.value"
30
+ :theme="theme"
31
+ :value="value"
32
+ :disabled="wrapperProps.disabled"
33
+ :readonly="wrapperProps.readonly"
34
+ @preview="uploadState.handlePreview"
35
+ @download="handleDownloadFile"
36
+ @delete="uploadState.handleDeleteFile"
37
+ />
38
+
39
+ <!-- Failed State -->
40
+ <FailedState
41
+ v-if="uploadState.isError.value"
42
+ :theme="theme"
43
+ :selected-file="uploadState.selectedFile.value"
44
+ :upload-failed-label="uploadFailedLabel"
45
+ :retry-label="retryLabel"
46
+ @retry="uploadState.handleRetryUpload"
47
+ @delete="uploadState.handleDeleteFile"
48
+ />
49
+ </div>
50
+ </div>
51
+ </FieldWrapper>
52
+ </template>
53
+
54
+ <script setup>
55
+ import EmptyState from "../fileState/EmptyState.vue";
56
+ import SuccessState from "../fileState/SuccessState.vue";
57
+ import LoadingState from "../fileState/LoadingState.vue";
58
+ import FailedState from "../fileState/FailedState.vue";
59
+ import { useUploadImageState } from "../fileState/useUploadImageState";
60
+ import { computed, useTemplateRef } from "#imports";
61
+ import FieldWrapper from "#core/components/Form/FieldWrapper.vue";
62
+ import { useFieldHOC } from "#core/composables/useForm";
63
+ import { uploadFileDropzoneTheme } from "#core/theme/uploadFileDropzone";
64
+ import { useUiConfig } from "#core/composables/useConfig";
65
+ import { downloadFileFromURL } from "#core/helpers/componentHelper";
66
+ const emits = defineEmits(["change", "success", "delete"]);
67
+ const props = defineProps({
68
+ requestOptions: { type: Object, required: true },
69
+ uploadPathURL: { type: String, required: false },
70
+ bodyKey: { type: String, required: false, default: "file" },
71
+ responseURL: { type: String, required: false, default: "url" },
72
+ responsePath: { type: String, required: false, default: "path" },
73
+ responseName: { type: String, required: false, default: "name" },
74
+ responseSize: { type: String, required: false, default: "size" },
75
+ responseID: { type: String, required: false, default: "id" },
76
+ accept: { type: [Array, String], required: false, default: () => ["image/*"] },
77
+ maxSize: { type: Number, required: false },
78
+ dimensions: { type: Object, required: false },
79
+ selectFileLabel: { type: String, required: false, default: "\u0E04\u0E25\u0E34\u0E01\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E" },
80
+ selectFileSubLabel: { type: String, required: false, default: "\u0E2B\u0E23\u0E37\u0E2D \u0E25\u0E32\u0E01\u0E41\u0E25\u0E30\u0E27\u0E32\u0E07\u0E17\u0E35\u0E48\u0E19\u0E35\u0E48" },
81
+ uploadingLabel: { type: String, required: false, default: "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2D\u0E31\u0E1E\u0E42\u0E2B\u0E25\u0E14..." },
82
+ uploadFailedLabel: { type: String, required: false, default: "\u0E2D\u0E31\u0E1E\u0E42\u0E2B\u0E25\u0E14\u0E25\u0E49\u0E21\u0E40\u0E2B\u0E25\u0E27, \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" },
83
+ retryLabel: { type: String, required: false, default: "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" },
84
+ form: { type: Object, required: false },
85
+ name: { type: String, required: true },
86
+ errorMessage: { type: String, required: false },
87
+ label: { type: null, required: false },
88
+ description: { type: String, required: false },
89
+ hint: { type: String, required: false },
90
+ rules: { type: null, required: false },
91
+ autoFocus: { type: Boolean, required: false },
92
+ placeholder: { type: String, required: false },
93
+ disabled: { type: Boolean, required: false },
94
+ readonly: { type: Boolean, required: false },
95
+ required: { type: Boolean, required: false },
96
+ help: { type: String, required: false },
97
+ ui: { type: null, required: false }
98
+ });
99
+ const {
100
+ wrapperProps,
101
+ handleChange: onChange,
102
+ setErrors,
103
+ value
104
+ } = useFieldHOC(props);
105
+ const acceptedFileTypes = computed(
106
+ () => typeof props.accept === "string" ? props.accept : props.accept?.join(",")
107
+ );
108
+ const dropzoneRef = useTemplateRef("dropzoneRef");
109
+ const uploadState = useUploadImageState(
110
+ props,
111
+ emits,
112
+ onChange,
113
+ setErrors,
114
+ value,
115
+ acceptedFileTypes,
116
+ wrapperProps,
117
+ dropzoneRef
118
+ );
119
+ const theme = computed(
120
+ () => useUiConfig(uploadFileDropzoneTheme, "uploadFileDropzone")({
121
+ dragover: uploadState.dropzone.isOverDropZone.value && uploadState.isEmpty.value,
122
+ disabled: wrapperProps.value.disabled,
123
+ failed: uploadState.upload.status.value.isError
124
+ })
125
+ );
126
+ const handleDownloadFile = () => {
127
+ if (value.value?.url && value.value?.name) {
128
+ downloadFileFromURL(value.value.url, value.value.name);
129
+ }
130
+ };
131
+ </script>
@@ -0,0 +1,26 @@
1
+ import type { IUploadImageAutoProps } from './types.js';
2
+ import type { IFileValue } from '#core/components/Form/types';
3
+ declare const __VLS_export: import("vue").DefineComponent<IUploadImageAutoProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
+ success: (res: IFileValue) => any;
5
+ delete: () => any;
6
+ change: (value: File | undefined) => any;
7
+ }, string, import("vue").PublicProps, Readonly<IUploadImageAutoProps> & Readonly<{
8
+ onSuccess?: ((res: IFileValue) => any) | undefined;
9
+ onDelete?: (() => any) | undefined;
10
+ onChange?: ((value: File | undefined) => any) | undefined;
11
+ }>, {
12
+ selectFileLabel: string;
13
+ selectFileSubLabel: string;
14
+ uploadingLabel: string;
15
+ uploadFailedLabel: string;
16
+ retryLabel: string;
17
+ bodyKey: string;
18
+ responseURL: string;
19
+ responsePath: string;
20
+ responseName: string;
21
+ responseSize: string;
22
+ responseID: string;
23
+ accept: string[] | string;
24
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
25
+ declare const _default: typeof __VLS_export;
26
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { IFieldProps, IFormFieldBase, INPUT_TYPES } from '../types.js';
3
+ export interface IDimensionValidation {
4
+ width?: number;
5
+ height?: number;
6
+ minWidth?: number;
7
+ minHeight?: number;
8
+ maxWidth?: number;
9
+ maxHeight?: number;
10
+ aspectRatio?: number;
11
+ aspectRatioTolerance?: number;
12
+ }
13
+ export interface IUploadImageAutoProps extends IFieldProps {
14
+ requestOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
15
+ baseURL: string;
16
+ };
17
+ uploadPathURL?: string;
18
+ bodyKey?: string;
19
+ responseURL?: string;
20
+ responsePath?: string;
21
+ responseName?: string;
22
+ responseSize?: string;
23
+ responseID?: string;
24
+ accept?: string[] | string;
25
+ maxSize?: number;
26
+ dimensions?: IDimensionValidation;
27
+ selectFileLabel?: string;
28
+ selectFileSubLabel?: string;
29
+ uploadingLabel?: string;
30
+ uploadFailedLabel?: string;
31
+ retryLabel?: string;
32
+ }
33
+ export type IUploadImageAutoField = IFormFieldBase<INPUT_TYPES.UPLOAD_IMAGE_AUTO, IUploadImageAutoProps, {
34
+ change: (value: File | undefined) => void;
35
+ success: (res: any) => void;
36
+ delete: () => void;
37
+ }>;
@@ -1,5 +1,6 @@
1
1
  import type { Editor } from '@tiptap/vue-3';
2
2
  import type { IFieldProps, IFormFieldBase, INPUT_TYPES } from '#core/components/Form/types';
3
+ import type { AxiosRequestConfig } from 'axios';
3
4
  export interface IWYSIWYGFieldProps extends IFieldProps {
4
5
  editable?: boolean;
5
6
  autofocus?: boolean;
@@ -18,7 +19,20 @@ export interface IWYSIWYGFieldProps extends IFieldProps {
18
19
  codeBlock?: boolean;
19
20
  horizontalRule?: boolean;
20
21
  link?: boolean;
21
- image?: boolean;
22
+ image?: {
23
+ requestOptions?: Omit<AxiosRequestConfig, 'baseURL'> & {
24
+ baseURL: string;
25
+ };
26
+ uploadPathURL?: string;
27
+ bodyKey?: string;
28
+ responseURL?: string;
29
+ responsePath?: string;
30
+ responseName?: string;
31
+ responseSize?: string;
32
+ responseID?: string;
33
+ accept?: string[] | string;
34
+ maxSize?: number;
35
+ } | boolean;
22
36
  youtube?: boolean;
23
37
  textAlign?: boolean;
24
38
  undo?: boolean;
@@ -0,0 +1,25 @@
1
+ import type { TemplateRef } from 'vue';
2
+ import type { IUploadImageAutoProps } from '../InputUploadImageAuto/types.js';
3
+ import type { IFileValue } from '#core/components/Form/types';
4
+ export declare enum UploadState {
5
+ EMPTY = "empty",
6
+ UPLOADING = "uploading",
7
+ SUCCESS = "success",
8
+ ERROR = "error"
9
+ }
10
+ export declare const useUploadImageState: (props: IUploadImageAutoProps, emits: any, onChange: (value: IFileValue | undefined) => void, setErrors: (error: string) => void, value: any, acceptedFileTypes: any, wrapperProps: any, dropzoneRef: TemplateRef<HTMLDivElement | undefined>) => {
11
+ currentState: import("vue").ComputedRef<UploadState>;
12
+ isEmpty: import("vue").ComputedRef<boolean>;
13
+ isUploading: import("vue").ComputedRef<boolean>;
14
+ isSuccess: import("vue").ComputedRef<boolean>;
15
+ isError: import("vue").ComputedRef<boolean>;
16
+ selectedFile: import("vue").Ref<File | undefined, File | undefined>;
17
+ upload: import("../../../helpers/apiObjectHelper.js").IUseObjectLoader<any, any, Record<string, any>>;
18
+ dropzone: import("@vueuse/core").UseDropZoneReturn;
19
+ percent: import("vue").Ref<number, number>;
20
+ handleInputChange: (event: Event) => void;
21
+ handleOpenFile: () => void;
22
+ handleDeleteFile: () => void;
23
+ handleRetryUpload: () => void;
24
+ handlePreview: () => void;
25
+ };
@@ -0,0 +1,257 @@
1
+ import { useDropZone, useFileDialog } from "@vueuse/core";
2
+ import { useWatchTrue } from "#core/composables/useWatch";
3
+ import PreviewModal from "./PreviewModal.vue";
4
+ import { computed, ref, useOverlay } from "#imports";
5
+ import { useUploadLoader } from "#core/composables/useUpload";
6
+ import { useFileAllocate, useFileProgress } from "#core/helpers/componentHelper";
7
+ import { StringHelper } from "#core/utils/StringHelper";
8
+ import { _get } from "#core/utils/lodash";
9
+ export var UploadState = /* @__PURE__ */ ((UploadState2) => {
10
+ UploadState2["EMPTY"] = "empty";
11
+ UploadState2["UPLOADING"] = "uploading";
12
+ UploadState2["SUCCESS"] = "success";
13
+ UploadState2["ERROR"] = "error";
14
+ return UploadState2;
15
+ })(UploadState || {});
16
+ export const useUploadImageState = (props, emits, onChange, setErrors, value, acceptedFileTypes, wrapperProps, dropzoneRef) => {
17
+ const overlay = useOverlay();
18
+ const previewModal = overlay.create(PreviewModal);
19
+ const selectedFile = ref();
20
+ const fileAllocate = useFileAllocate(selectedFile, props);
21
+ const {
22
+ percent,
23
+ onDownloadProgress,
24
+ onUploadProgress
25
+ } = useFileProgress();
26
+ const request = {
27
+ requestOptions: {
28
+ ...props.requestOptions,
29
+ onDownloadProgress,
30
+ onUploadProgress
31
+ },
32
+ pathURL: props.uploadPathURL
33
+ };
34
+ const upload = useUploadLoader(request);
35
+ const validateImageDimensions = (file) => {
36
+ return new Promise((resolve) => {
37
+ if (!props.dimensions) {
38
+ resolve(true);
39
+ return;
40
+ }
41
+ const img = new Image();
42
+ const url = URL.createObjectURL(file);
43
+ img.onload = () => {
44
+ URL.revokeObjectURL(url);
45
+ const {
46
+ width,
47
+ height
48
+ } = img;
49
+ const dimensions = props.dimensions;
50
+ if (dimensions.width !== void 0 && width !== dimensions.width) {
51
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E01\u0E27\u0E49\u0E32\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19 ${dimensions.width}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${width}px)`);
52
+ resolve(false);
53
+ return;
54
+ }
55
+ if (dimensions.height !== void 0 && height !== dimensions.height) {
56
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E2A\u0E39\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19 ${dimensions.height}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${height}px)`);
57
+ resolve(false);
58
+ return;
59
+ }
60
+ if (dimensions.minWidth !== void 0 && width < dimensions.minWidth) {
61
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E01\u0E27\u0E49\u0E32\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32 ${dimensions.minWidth}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${width}px)`);
62
+ resolve(false);
63
+ return;
64
+ }
65
+ if (dimensions.minHeight !== void 0 && height < dimensions.minHeight) {
66
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E2A\u0E39\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32 ${dimensions.minHeight}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${height}px)`);
67
+ resolve(false);
68
+ return;
69
+ }
70
+ if (dimensions.maxWidth !== void 0 && width > dimensions.maxWidth) {
71
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E01\u0E27\u0E49\u0E32\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 ${dimensions.maxWidth}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${width}px)`);
72
+ resolve(false);
73
+ return;
74
+ }
75
+ if (dimensions.maxHeight !== void 0 && height > dimensions.maxHeight) {
76
+ setErrors(`\u0E04\u0E27\u0E32\u0E21\u0E2A\u0E39\u0E07\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 ${dimensions.maxHeight}px (\u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${height}px)`);
77
+ resolve(false);
78
+ return;
79
+ }
80
+ if (dimensions.aspectRatio !== void 0) {
81
+ const actualRatio = width / height;
82
+ const tolerance = dimensions.aspectRatioTolerance ?? 0.01;
83
+ const expectedRatio = dimensions.aspectRatio;
84
+ if (Math.abs(actualRatio - expectedRatio) > tolerance) {
85
+ setErrors(`\u0E2D\u0E31\u0E15\u0E23\u0E32\u0E2A\u0E48\u0E27\u0E19\u0E02\u0E2D\u0E07\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23: ${expectedRatio.toFixed(2)}, \u0E1B\u0E31\u0E08\u0E08\u0E38\u0E1A\u0E31\u0E19: ${actualRatio.toFixed(2)})`);
86
+ resolve(false);
87
+ return;
88
+ }
89
+ }
90
+ setErrors("");
91
+ resolve(true);
92
+ };
93
+ img.onerror = () => {
94
+ URL.revokeObjectURL(url);
95
+ setErrors("\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E42\u0E2B\u0E25\u0E14\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E\u0E44\u0E14\u0E49");
96
+ resolve(false);
97
+ };
98
+ img.src = url;
99
+ });
100
+ };
101
+ const validateFile = async (file) => {
102
+ if (props.accept && fileAllocate.acceptFile.value) {
103
+ const acceptedTypes = fileAllocate.acceptFile.value;
104
+ const acceptedTypesList = acceptedTypes.split(",").map((type) => type.trim());
105
+ const fileExtension = file.name.toLowerCase().split(".").pop();
106
+ const isValidFileType = acceptedTypesList.some((acceptedType) => {
107
+ if (acceptedType.startsWith(".")) {
108
+ const extension = acceptedType.slice(1).toLowerCase();
109
+ return fileExtension === extension;
110
+ } else if (!acceptedType.includes("/") && !acceptedType.includes("*")) {
111
+ return fileExtension === acceptedType.toLowerCase();
112
+ }
113
+ if (acceptedType.endsWith("/*")) {
114
+ const baseType = acceptedType.slice(0, -2);
115
+ return file.type.startsWith(baseType + "/");
116
+ }
117
+ return file.type === acceptedType;
118
+ });
119
+ if (!isValidFileType) {
120
+ setErrors("\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17\u0E44\u0E1F\u0E25\u0E4C\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A\u0E40\u0E09\u0E1E\u0E32\u0E30 " + acceptedTypesList.join(", ") + ")");
121
+ return false;
122
+ }
123
+ }
124
+ if (props.maxSize) {
125
+ const maxSizeBytes = (fileAllocate.acceptFileSizeKb.value || 0) * 1024;
126
+ if (file.size > maxSizeBytes) {
127
+ if (fileAllocate.isAcceptFileUseMb.value) {
128
+ setErrors(`\u0E02\u0E19\u0E32\u0E14\u0E44\u0E1F\u0E25\u0E4C\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 ${fileAllocate.acceptFileSizeMb.value} MB`);
129
+ } else {
130
+ setErrors(`\u0E02\u0E19\u0E32\u0E14\u0E44\u0E1F\u0E25\u0E4C\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 ${fileAllocate.acceptFileSizeKb.value} KB`);
131
+ }
132
+ return false;
133
+ }
134
+ }
135
+ const isDimensionsValid = await validateImageDimensions(file);
136
+ if (!isDimensionsValid) {
137
+ return false;
138
+ }
139
+ setErrors("");
140
+ return true;
141
+ };
142
+ const processFile = async (file) => {
143
+ const isValid = await validateFile(file);
144
+ if (!isValid) return;
145
+ selectedFile.value = file;
146
+ emits("change", file);
147
+ const formData = new FormData();
148
+ formData.append(props.bodyKey, file);
149
+ upload.run({
150
+ data: formData
151
+ });
152
+ };
153
+ const handleFileDrop = (files) => {
154
+ if (wrapperProps.value.disabled || wrapperProps.value.readonly || !files?.length || !isEmpty.value) return;
155
+ const file = files[0];
156
+ if (file) {
157
+ processFile(file);
158
+ }
159
+ };
160
+ const fileDialog = useFileDialog({
161
+ accept: acceptedFileTypes.value || "image/*",
162
+ directory: false,
163
+ multiple: false
164
+ });
165
+ const dropzone = useDropZone(dropzoneRef, {
166
+ onDrop: handleFileDrop,
167
+ multiple: false,
168
+ preventDefaultForUnhandled: false
169
+ });
170
+ const currentState = computed(() => {
171
+ if (value.value) return "success" /* SUCCESS */;
172
+ if (selectedFile.value && upload.status.value.isLoading) return "uploading" /* UPLOADING */;
173
+ if (selectedFile.value && upload.status.value.isError) return "error" /* ERROR */;
174
+ return "empty" /* EMPTY */;
175
+ });
176
+ const isEmpty = computed(() => currentState.value === "empty" /* EMPTY */);
177
+ const isUploading = computed(() => currentState.value === "uploading" /* UPLOADING */);
178
+ const isSuccess = computed(() => currentState.value === "success" /* SUCCESS */);
179
+ const isError = computed(() => currentState.value === "error" /* ERROR */);
180
+ const handleInputChange = (event) => {
181
+ if (wrapperProps.value.disabled || wrapperProps.value.readonly) return;
182
+ const file = event.target.files?.[0];
183
+ if (file) {
184
+ processFile(file);
185
+ }
186
+ };
187
+ fileDialog.onChange((files) => {
188
+ const file = files?.[0];
189
+ if (file) {
190
+ processFile(file);
191
+ }
192
+ });
193
+ const handleOpenFile = () => {
194
+ if (wrapperProps.value.disabled || wrapperProps.value.readonly) return;
195
+ fileDialog.open();
196
+ };
197
+ const handleDeleteFile = () => {
198
+ fileDialog.reset();
199
+ upload.clear();
200
+ selectedFile.value = void 0;
201
+ onChange(void 0);
202
+ emits("delete");
203
+ };
204
+ const handleRetryUpload = () => {
205
+ if (selectedFile.value) {
206
+ const formData = new FormData();
207
+ formData.append(props.bodyKey, selectedFile.value);
208
+ upload.run(formData);
209
+ }
210
+ };
211
+ const handlePreview = () => {
212
+ previewModal.open({
213
+ value: value.value
214
+ });
215
+ };
216
+ useWatchTrue(
217
+ () => upload.status.value.isSuccess,
218
+ () => {
219
+ if (upload.data.value) {
220
+ const fileValue = {
221
+ url: _get(upload.data.value, props.responseURL),
222
+ path: _get(upload.data.value, props.responsePath),
223
+ name: _get(upload.data.value, props.responseName) || selectedFile.value?.name,
224
+ size: Number(_get(upload.data.value, props.responseSize) || selectedFile.value?.size),
225
+ id: _get(upload.data.value, props.responseID)
226
+ };
227
+ value.value = fileValue;
228
+ emits("success", fileValue);
229
+ }
230
+ }
231
+ );
232
+ useWatchTrue(
233
+ () => upload.status.value.isError,
234
+ () => {
235
+ setErrors("\u0E1E\u0E1A\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14: " + StringHelper.getError(upload.status.value.errorData));
236
+ }
237
+ );
238
+ return {
239
+ // State
240
+ currentState,
241
+ isEmpty,
242
+ isUploading,
243
+ isSuccess,
244
+ isError,
245
+ selectedFile,
246
+ // Upload utilities
247
+ upload,
248
+ dropzone,
249
+ percent,
250
+ // Handlers
251
+ handleInputChange,
252
+ handleOpenFile,
253
+ handleDeleteFile,
254
+ handleRetryUpload,
255
+ handlePreview
256
+ };
257
+ };
@@ -3,6 +3,7 @@ import type { FormContext } from 'vee-validate';
3
3
  import type { IUploadDropzoneField } from './InputUploadDropzone/types.js';
4
4
  import type { IUploadDropzoneAutoField } from './InputUploadDropzoneAuto/types.js';
5
5
  import type { IUploadDropzoneAutoMultipleField } from './InputUploadDropzoneAutoMultiple/types.js';
6
+ import type { IUploadImageAutoField } from './InputUploadImageAuto/types.js';
6
7
  import type { IDateTimeRangeField } from './InputDateTimeRange/date_range_time_field.types.js';
7
8
  import type { ITextField } from '#core/components/Form/InputText/types';
8
9
  import type { ISearchField } from '#core/components/Form/InputSearch/types';
@@ -76,7 +77,7 @@ export interface IFormFieldBase<I extends INPUT_TYPES, P extends IFieldProps, O>
76
77
  props: P;
77
78
  on?: O;
78
79
  }
79
- export type IFormField = ITextField | ISearchField | INumberField | ICurrencyField | ITextareaField | IToggleField | ISelectField | ICheckboxField | ISelectMultipleField | IRadioField | IDateTimeField | ITimeField | IMonthField | IDateTimeRangeField | IUploadDropzoneField | IUploadDropzoneAutoField | IUploadDropzoneAutoMultipleField | IWYSIWYGField | IComponentField | ITagsField | IFormFieldBase<INPUT_TYPES.COMPONENT, any, any>;
80
+ export type IFormField = ITextField | ISearchField | INumberField | ICurrencyField | ITextareaField | IToggleField | ISelectField | ICheckboxField | ISelectMultipleField | IRadioField | IDateTimeField | ITimeField | IMonthField | IDateTimeRangeField | IUploadDropzoneField | IUploadDropzoneAutoField | IUploadDropzoneAutoMultipleField | IUploadImageAutoField | IWYSIWYGField | IComponentField | ITagsField | IFormFieldBase<INPUT_TYPES.COMPONENT, any, any>;
80
81
  export interface IFileValue {
81
82
  url: string;
82
83
  path?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "repository": "https://gitlab.finema.co/finema/ui-kit",
5
5
  "license": "MIT",
6
6
  "author": "Finema Dev Core Team",