@finema/core 1.4.51 → 1.4.53

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": "1.4.51",
3
+ "version": "1.4.53",
4
4
  "configKey": "core",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.7.4"
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { defineNuxtModule, createResolver, installModule, addPlugin, addComponen
2
2
  import 'lodash-es';
3
3
 
4
4
  const name = "@finema/core";
5
- const version = "1.4.51";
5
+ const version = "1.4.53";
6
6
 
7
7
  const colors = {
8
8
  black: "#20243E",
@@ -56,7 +56,7 @@
56
56
  <script lang="ts" setup>
57
57
  import { useDropZone } from '@vueuse/core'
58
58
  import { type IUploadDropzoneProps } from './types'
59
- import { isImage, generateURL, checkMaxSize } from '#core/helpers/componentHelper'
59
+ import { isImage, generateURL, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
60
60
  import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
61
61
  import { useFieldHOC } from '#core/composables/useForm'
62
62
  import { computed, ref, toRef, useUI, useUiConfig } from '#imports'
@@ -100,7 +100,7 @@ const onDrop = (files: File[] | null) => {
100
100
  }
101
101
  }
102
102
 
103
- const { isOverDropZone } = useDropZone(dropzoneRef, {
103
+ const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
104
104
  onDrop,
105
105
  })
106
106
 
@@ -130,6 +130,14 @@ const handleDeleteFile = () => {
130
130
  const handleCheckFileCondition = (file: File | undefined): boolean => {
131
131
  if (!file) return false
132
132
 
133
+ const fileType = checkFileType(file, acceptFile.value ?? '')
134
+
135
+ if (!fileType) {
136
+ setErrors(i18next.t('custom:invalid_file_type'))
137
+
138
+ return false
139
+ }
140
+
133
141
  const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
134
142
 
135
143
  if (!maxSize) {
@@ -28,26 +28,22 @@
28
28
  <div :class="[ui.wrapper]">
29
29
  <div v-if="selectedFile" :class="[ui.preview.wrapper]">
30
30
  <div
31
- v-if="isImage(selectedFile) && upload.status.value.isSuccess"
31
+ v-if="isImage(selectedFile) && upload.status.value.isLoaded"
32
32
  :class="[ui.preview.image.wrapper]"
33
33
  >
34
34
  <img
35
- :src="upload.data.value[props.responseKey || 'url']"
35
+ :src="upload.data.value[responseKey || 'url']"
36
36
  :class="[ui.preview.image.img]"
37
37
  alt="file"
38
38
  />
39
39
  </div>
40
- <Icon
41
- v-else-if="!isImage(selectedFile) && upload.status.value.isSuccess"
42
- :name="ui.default.filePreviewIcon"
43
- :class="[ui.preview.icon]"
44
- />
40
+ <Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
45
41
  <div :class="[ui.preview.filename]">
46
42
  <p class="truncate">{{ selectedFile.name }}</p>
47
43
  </div>
48
44
  <div class="flex items-center space-x-1">
49
45
  <Badge size="xs" variant="outline" class="mt-1">
50
- {{ isSelectedFileUseMb ? `${selectedFileSizeMb} Mb` : `${selectedFileSizeKb} Kb` }}
46
+ {{ isSelectedFileUseMb ? `${selectedFileSizeMb} MB` : `${selectedFileSizeKb} KB` }}
51
47
  </Badge>
52
48
  <div>
53
49
  <Icon
@@ -63,7 +59,7 @@
63
59
  </div>
64
60
  </div>
65
61
  </div>
66
- <div v-if="selectedFile" :class="[ui.uploadStatus.wrapper]">
62
+ <div v-if="upload.status.value.isLoading" :class="[ui.uploadStatus.wrapper]">
67
63
  <UProgress :class="[ui.uploadStatus.progressBar]" :value="100" />
68
64
  </div>
69
65
  <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
@@ -84,7 +80,7 @@
84
80
  <script lang="ts" setup>
85
81
  import { useDropZone } from '@vueuse/core'
86
82
  import { type IUploadDropzoneAutoProps } from './types'
87
- import { isImage, checkMaxSize } from '#core/helpers/componentHelper'
83
+ import { isImage, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
88
84
  import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
89
85
  import { useFieldHOC } from '#core/composables/useForm'
90
86
  import {
@@ -119,7 +115,6 @@ const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
119
115
 
120
116
  const fileInputRef = ref<HTMLInputElement>()
121
117
  const dropzoneRef = ref<HTMLDivElement>()
122
-
123
118
  const selectedFile = ref<File | undefined>()
124
119
  const percent = ref<number>(0)
125
120
 
@@ -155,7 +150,7 @@ const onDrop = (files: File[] | null) => {
155
150
  }
156
151
  }
157
152
 
158
- const { isOverDropZone } = useDropZone(dropzoneRef, {
153
+ const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
159
154
  onDrop,
160
155
  })
161
156
 
@@ -190,6 +185,14 @@ const handleDeleteFile = () => {
190
185
  const handleCheckFileCondition = (file: File | undefined): boolean => {
191
186
  if (!file) return false
192
187
 
188
+ const fileType = checkFileType(file, acceptFile.value ?? '')
189
+
190
+ if (!fileType) {
191
+ setErrors(i18next.t('custom:invalid_file_type'))
192
+
193
+ return false
194
+ }
195
+
193
196
  const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
194
197
 
195
198
  if (!maxSize) {
@@ -1,3 +1,4 @@
1
1
  export declare const checkMaxSize: (file: File, acceptFileSize: number) => boolean;
2
+ export declare const checkFileType: (file: File, acceptFileType: string | string[]) => boolean;
2
3
  export declare const generateURL: (file: File) => string;
3
4
  export declare const isImage: (file: File) => boolean;
@@ -4,6 +4,29 @@ export const checkMaxSize = (file, acceptFileSize) => {
4
4
  }
5
5
  return true;
6
6
  };
7
+ export const checkFileType = (file, acceptFileType) => {
8
+ if (!acceptFileType || Array.isArray(acceptFileType) && acceptFileType.length === 0)
9
+ return true;
10
+ const result = [];
11
+ const acceptedTypes = Array.isArray(acceptFileType) ? acceptFileType : acceptFileType.split(",");
12
+ for (const acceptedType of acceptedTypes) {
13
+ if (acceptedType.startsWith(".")) {
14
+ const fileExtension = `.${file.name.split(".").pop()}`;
15
+ if (fileExtension.toLowerCase() === acceptedType.toLowerCase())
16
+ result.push(true);
17
+ } else {
18
+ const fileType = acceptedType.split("/");
19
+ const fileExtension = file.type.split("/");
20
+ if (fileType.length === 2 && fileExtension.length === 2) {
21
+ if (fileType[1] === "*") {
22
+ result.push(fileType[0].toLowerCase() === fileExtension[0].toLowerCase());
23
+ }
24
+ result.push(acceptedType.toLowerCase() === file.type.toLowerCase());
25
+ }
26
+ }
27
+ }
28
+ return result.includes(true);
29
+ };
7
30
  export const generateURL = (file) => {
8
31
  const fileSrc = URL.createObjectURL(file);
9
32
  setTimeout(() => {
@@ -26,9 +26,9 @@ export class StringHelper {
26
26
  return newStr;
27
27
  };
28
28
  static getError = (errorData, defaultErrorMessage = "\u0E21\u0E35\u0E1A\u0E32\u0E07\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14") => {
29
- let msg = errorData?.message;
29
+ let msg = errorData?.message || defaultErrorMessage;
30
30
  if (!errorData.code || !msg) {
31
- return defaultErrorMessage;
31
+ return msg;
32
32
  }
33
33
  if (errorData.code !== "INVALID_PARAMS" && !errorData.fields) {
34
34
  return msg;
@@ -106,6 +106,15 @@ export declare const _fromPairs: {
106
106
  (pairs: import("lodash").List<any[]> | null | undefined): import("lodash").Dictionary<any>;
107
107
  };
108
108
  export declare const _xor: <T>(...arrays: (import("lodash").List<T> | null | undefined)[]) => T[];
109
+ export declare const _omit: {
110
+ <T extends object, K extends import("lodash").PropertyName[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>;
111
+ <T_1 extends object, K_1 extends keyof T_1>(object: T_1 | null | undefined, ...paths: import("lodash").Many<K_1>[]): import("lodash").Omit<T_1, K_1>;
112
+ <T_2 extends object>(object: T_2 | null | undefined, ...paths: import("lodash").Many<import("lodash").PropertyName>[]): Partial<T_2>;
113
+ };
114
+ export declare const _pick: {
115
+ <T extends object, U extends keyof T>(object: T, ...props: import("lodash").Many<U>[]): Pick<T, U>;
116
+ <T_1>(object: T_1 | null | undefined, ...props: import("lodash").Many<import("lodash").PropertyPath>[]): Partial<T_1>;
117
+ };
109
118
  export declare const _clone: (object: any) => any;
110
119
  export declare const _debounce: <T extends (...args: any[]) => any>(func: T, wait?: number) => import("lodash").DebouncedFunc<T>;
111
120
  export declare const _deepMerge: (target: any, ...sources: any[]) => any;
@@ -27,7 +27,9 @@ import {
27
27
  xor,
28
28
  debounce,
29
29
  intersection,
30
- get
30
+ get,
31
+ omit,
32
+ pick
31
33
  } from "lodash-es";
32
34
  export const _get = get;
33
35
  export const _range = range;
@@ -57,6 +59,8 @@ export const _toPairs = toPairs;
57
59
  export const _orderBy = orderBy;
58
60
  export const _fromPairs = fromPairs;
59
61
  export const _xor = xor;
62
+ export const _omit = omit;
63
+ export const _pick = pick;
60
64
  export const _clone = (object) => {
61
65
  try {
62
66
  return JSON.parse(JSON.stringify(object || {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "1.4.51",
3
+ "version": "1.4.53",
4
4
  "repository": "https://gitlab.finema.co/finema/ui-kit",
5
5
  "license": "MIT",
6
6
  "author": "Finema Dev Core Team",
@@ -66,7 +66,7 @@
66
66
  "happy-dom": "^13.0.0",
67
67
  "husky": "^8.0.3",
68
68
  "lint-staged": "^15.2.0",
69
- "nuxt": "^3.10.0",
69
+ "nuxt": "^3.10.1",
70
70
  "playwright-core": "^1.40.1",
71
71
  "prettier": "^3.1.1",
72
72
  "release-it": "^17.0.1",
@@ -76,9 +76,6 @@
76
76
  "stylelint-config-standard-scss": "^13.0.0",
77
77
  "vitest": "^1.2.2"
78
78
  },
79
- "resolutions": {
80
- "vue": "3.3.13"
81
- },
82
79
  "lint-staged": {
83
80
  "*.{ts,vue,tsx,js}": "eslint --fix --cache",
84
81
  "*.{html,json}": "prettier --write"