@finema/core 3.14.3 → 3.14.5

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.14.3",
3
+ "version": "3.14.5",
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.14.3";
7
+ const version = "3.14.5";
8
8
 
9
9
  const nuxtAppOptions = {
10
10
  head: {
@@ -1,7 +1,6 @@
1
- import type { Ref, TemplateRef } from 'vue';
1
+ import type { TemplateRef } from 'vue';
2
2
  import type { IUploadDropzoneAutoMultipleProps } from '../InputUploadDropzoneAutoMultiple/types.js';
3
3
  import type { IFileValue } from '#core/components/Form/types';
4
- import { useUploadLoader } from '#core/composables/useUpload';
5
4
  export declare enum UploadState {
6
5
  EMPTY = "empty",
7
6
  UPLOADING = "uploading",
@@ -14,11 +13,12 @@ export interface FileUploadItem {
14
13
  progress: number;
15
14
  value?: IFileValue;
16
15
  error?: string;
17
- uploadLoader?: ReturnType<typeof useUploadLoader>;
18
- percentRef?: Ref<number>;
16
+ uploadLoader?: any;
17
+ percentRef?: any;
18
+ cleanupWatchers?: (() => void)[];
19
19
  }
20
20
  export declare const useUploadStateMultiple: (props: IUploadDropzoneAutoMultipleProps, emits: any, onChange: (value: IFileValue[] | undefined) => void, setErrors: (error: string) => void, value: any, acceptedFileTypes: any, wrapperProps: any, dropzoneRef: TemplateRef<HTMLDivElement | undefined>) => {
21
- fileItems: Ref<{
21
+ fileItems: import("vue").Ref<{
22
22
  file: {
23
23
  readonly lastModified: number;
24
24
  readonly name: string;
@@ -56,16 +56,9 @@ export declare const useUploadStateMultiple: (props: IUploadDropzoneAutoMultiple
56
56
  id?: string | undefined;
57
57
  } | undefined;
58
58
  error?: string | undefined;
59
- uploadLoader?: {
60
- status: import("#imports").IStatus;
61
- data: any;
62
- options: import("#imports").IAPIOptions;
63
- run: (payload?: import("../../../helpers/apiObjectHelper.js").IObjectRunLoaderOptions<any, any> | undefined) => Promise<void>;
64
- clear: () => void;
65
- setLoading: () => void;
66
- setData: (data: any) => void;
67
- } | undefined;
68
- percentRef?: number | undefined;
59
+ uploadLoader?: any;
60
+ percentRef?: any;
61
+ cleanupWatchers?: (() => void)[] | undefined;
69
62
  }[], FileUploadItem[] | {
70
63
  file: {
71
64
  readonly lastModified: number;
@@ -104,16 +97,9 @@ export declare const useUploadStateMultiple: (props: IUploadDropzoneAutoMultiple
104
97
  id?: string | undefined;
105
98
  } | undefined;
106
99
  error?: string | undefined;
107
- uploadLoader?: {
108
- status: import("#imports").IStatus;
109
- data: any;
110
- options: import("#imports").IAPIOptions;
111
- run: (payload?: import("../../../helpers/apiObjectHelper.js").IObjectRunLoaderOptions<any, any> | undefined) => Promise<void>;
112
- clear: () => void;
113
- setLoading: () => void;
114
- setData: (data: any) => void;
115
- } | undefined;
116
- percentRef?: number | undefined;
100
+ uploadLoader?: any;
101
+ percentRef?: any;
102
+ cleanupWatchers?: (() => void)[] | undefined;
117
103
  }[]>;
118
104
  isEmpty: import("vue").ComputedRef<boolean>;
119
105
  hasUploading: import("vue").ComputedRef<boolean>;
@@ -121,6 +107,6 @@ export declare const useUploadStateMultiple: (props: IUploadDropzoneAutoMultiple
121
107
  dropzone: import("@vueuse/core").UseDropZoneReturn;
122
108
  handleOpenFile: () => void;
123
109
  handleDeleteFile: (index: number) => void;
124
- handleRetryUpload: (index: number) => void;
110
+ handleRetryUpload: (index: number) => Promise<void>;
125
111
  handlePreview: (fileValue: IFileValue) => void;
126
112
  };
@@ -87,45 +87,17 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
87
87
  progress: newProgress
88
88
  });
89
89
  });
90
- const stopSuccessWatch = watch(
91
- () => uploadLoader.status.value.isSuccess,
92
- (isSuccess) => {
93
- if (isSuccess && uploadLoader.data.value) {
94
- const fileValue = {
95
- url: _get(uploadLoader.data.value, props.responseURL),
96
- path: _get(uploadLoader.data.value, props.responsePath),
97
- name: _get(uploadLoader.data.value, props.responseName) || fileItem.file.name,
98
- size: Number(_get(uploadLoader.data.value, props.responseSize) || fileItem.file.size),
99
- id: _get(uploadLoader.data.value, props.responseID)
100
- };
101
- fileItems.value.splice(index, 1);
102
- onChange([fileValue, ...ArrayHelper.toArray(value.value)]);
103
- emits("success", fileValue);
104
- stopProgressWatch();
105
- stopSuccessWatch();
106
- stopErrorWatch();
107
- }
108
- }
109
- );
110
- const stopErrorWatch = watch(
111
- () => uploadLoader.status.value.isError,
112
- (isError) => {
113
- if (isError) {
114
- updateFileItem(index, {
115
- state: "error" /* ERROR */,
116
- error: "\u0E1E\u0E1A\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14: " + StringHelper.getError(
117
- uploadLoader.status.value.errorData
118
- )
119
- });
120
- stopProgressWatch();
121
- stopSuccessWatch();
122
- stopErrorWatch();
123
- }
124
- }
125
- );
90
+ updateFileItem(index, {
91
+ cleanupWatchers: [stopProgressWatch]
92
+ });
126
93
  return uploadLoader;
127
94
  };
128
95
  const processFile = (file) => {
96
+ processFileAsync(file).catch((error) => {
97
+ console.error("Error processing file:", error);
98
+ });
99
+ };
100
+ const processFileAsync = async (file) => {
129
101
  const validation = validateFile(file);
130
102
  if (!validation.valid) {
131
103
  setErrors(validation.error || "Invalid file");
@@ -146,14 +118,54 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
146
118
  const uploadLoader = setupUpload(fileItem, newIndex);
147
119
  const formData = new FormData();
148
120
  formData.append(props.bodyKey, file);
149
- uploadLoader.run({
150
- data: formData
121
+ await new Promise((resolve, reject) => {
122
+ const stopSuccessWatch = watch(
123
+ () => uploadLoader.status.value.isSuccess,
124
+ (isSuccess) => {
125
+ if (isSuccess && uploadLoader.data.value) {
126
+ const fileValue = {
127
+ url: _get(uploadLoader.data.value, props.responseURL),
128
+ path: _get(uploadLoader.data.value, props.responsePath),
129
+ name: _get(uploadLoader.data.value, props.responseName) || fileItem.file.name,
130
+ size: Number(_get(uploadLoader.data.value, props.responseSize) || fileItem.file.size),
131
+ id: _get(uploadLoader.data.value, props.responseID)
132
+ };
133
+ fileItems.value = fileItems.value.filter((_, i) => i !== newIndex);
134
+ onChange([fileValue, ...ArrayHelper.toArray(value.value)]);
135
+ emits("success", fileValue);
136
+ stopSuccessWatch();
137
+ stopErrorWatch();
138
+ resolve();
139
+ }
140
+ }
141
+ );
142
+ const stopErrorWatch = watch(
143
+ () => uploadLoader.status.value.isError,
144
+ (isError) => {
145
+ if (isError) {
146
+ updateFileItem(newIndex, {
147
+ state: "error" /* ERROR */,
148
+ error: "\u0E1E\u0E1A\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14: " + StringHelper.getError(
149
+ uploadLoader.status.value.errorData
150
+ )
151
+ });
152
+ stopSuccessWatch();
153
+ stopErrorWatch();
154
+ reject(new Error("Upload failed"));
155
+ }
156
+ }
157
+ );
158
+ uploadLoader.run({
159
+ data: formData
160
+ });
151
161
  });
152
162
  emits("change", fileItems.value.map((item) => item.file));
153
163
  };
154
- const handleFileDrop = (files) => {
164
+ const handleFileDrop = async (files) => {
155
165
  if (wrapperProps.value.disabled || wrapperProps.value.readonly || !files?.length) return;
156
- files.forEach((file) => processFile(file));
166
+ for (const file of files) {
167
+ await processFileAsync(file);
168
+ }
157
169
  };
158
170
  const fileDialog = useFileDialog({
159
171
  accept: acceptedFileTypes.value || "",
@@ -172,9 +184,11 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
172
184
  const allSuccess = computed(
173
185
  () => fileItems.value.length > 0 && fileItems.value.every((item) => item.state === "success" /* SUCCESS */)
174
186
  );
175
- fileDialog.onChange((files) => {
187
+ fileDialog.onChange(async (files) => {
176
188
  if (files?.length) {
177
- Array.from(files).forEach((file) => processFile(file));
189
+ for (const file of Array.from(files)) {
190
+ await processFileAsync(file);
191
+ }
178
192
  fileDialog.reset();
179
193
  }
180
194
  });
@@ -187,13 +201,17 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
187
201
  fileDialog.open();
188
202
  };
189
203
  const handleDeleteFile = (index) => {
204
+ const fileItem = fileItems.value[index];
205
+ if (fileItem?.cleanupWatchers) {
206
+ fileItem.cleanupWatchers.forEach((cleanup) => cleanup());
207
+ }
190
208
  fileItems.value.splice(index, 1);
191
209
  if (fileItems.value.length === 0) {
192
210
  setErrors("");
193
211
  }
194
212
  emits("delete", index);
195
213
  };
196
- const handleRetryUpload = (index) => {
214
+ const handleRetryUpload = async (index) => {
197
215
  const fileItem = fileItems.value[index];
198
216
  if (!fileItem) return;
199
217
  updateFileItem(index, {
@@ -204,8 +222,46 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
204
222
  const uploadLoader = setupUpload(fileItem, index);
205
223
  const formData = new FormData();
206
224
  formData.append(props.bodyKey, fileItem.file);
207
- uploadLoader.run({
208
- data: formData
225
+ await new Promise((resolve, reject) => {
226
+ const stopSuccessWatch = watch(
227
+ () => uploadLoader.status.value.isSuccess,
228
+ (isSuccess) => {
229
+ if (isSuccess && uploadLoader.data.value) {
230
+ const fileValue = {
231
+ url: _get(uploadLoader.data.value, props.responseURL),
232
+ path: _get(uploadLoader.data.value, props.responsePath),
233
+ name: _get(uploadLoader.data.value, props.responseName) || fileItem.file.name,
234
+ size: Number(_get(uploadLoader.data.value, props.responseSize) || fileItem.file.size),
235
+ id: _get(uploadLoader.data.value, props.responseID)
236
+ };
237
+ fileItems.value = fileItems.value.filter((_, i) => i !== index);
238
+ onChange([fileValue, ...ArrayHelper.toArray(value.value)]);
239
+ emits("success", fileValue);
240
+ stopSuccessWatch();
241
+ stopErrorWatch();
242
+ resolve();
243
+ }
244
+ }
245
+ );
246
+ const stopErrorWatch = watch(
247
+ () => uploadLoader.status.value.isError,
248
+ (isError) => {
249
+ if (isError) {
250
+ updateFileItem(index, {
251
+ state: "error" /* ERROR */,
252
+ error: "\u0E1E\u0E1A\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14: " + StringHelper.getError(
253
+ uploadLoader.status.value.errorData
254
+ )
255
+ });
256
+ stopSuccessWatch();
257
+ stopErrorWatch();
258
+ reject(new Error("Upload failed"));
259
+ }
260
+ }
261
+ );
262
+ uploadLoader.run({
263
+ data: formData
264
+ });
209
265
  });
210
266
  };
211
267
  const handlePreview = (fileValue) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "3.14.3",
3
+ "version": "3.14.5",
4
4
  "repository": "https://gitlab.finema.co/finema/ui-kit",
5
5
  "license": "MIT",
6
6
  "author": "Finema Dev Core Team",