@finema/core 3.14.4 → 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.4",
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.4";
7
+ const version = "3.14.5";
8
8
 
9
9
  const nuxtAppOptions = {
10
10
  head: {
@@ -6,9 +6,6 @@ interface FileUploadItem {
6
6
  progress: number;
7
7
  value?: IFileValue;
8
8
  error?: string;
9
- uploadLoader?: any;
10
- percentRef?: any;
11
- cleanupWatchers?: (() => void)[];
12
9
  }
13
10
  interface Props {
14
11
  theme: any;
@@ -6,9 +6,6 @@ interface FileUploadItem {
6
6
  progress: number;
7
7
  value?: IFileValue;
8
8
  error?: string;
9
- uploadLoader?: any;
10
- percentRef?: any;
11
- cleanupWatchers?: (() => void)[];
12
9
  }
13
10
  interface Props {
14
11
  theme: any;
@@ -107,6 +107,6 @@ export declare const useUploadStateMultiple: (props: IUploadDropzoneAutoMultiple
107
107
  dropzone: import("@vueuse/core").UseDropZoneReturn;
108
108
  handleOpenFile: () => void;
109
109
  handleDeleteFile: (index: number) => void;
110
- handleRetryUpload: (index: number) => void;
110
+ handleRetryUpload: (index: number) => Promise<void>;
111
111
  handlePreview: (fileValue: IFileValue) => void;
112
112
  };
@@ -87,48 +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 = fileItems.value.filter((_, i) => i !== index);
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
- );
126
90
  updateFileItem(index, {
127
- cleanupWatchers: [stopProgressWatch, stopSuccessWatch, stopErrorWatch]
91
+ cleanupWatchers: [stopProgressWatch]
128
92
  });
129
93
  return uploadLoader;
130
94
  };
131
95
  const processFile = (file) => {
96
+ processFileAsync(file).catch((error) => {
97
+ console.error("Error processing file:", error);
98
+ });
99
+ };
100
+ const processFileAsync = async (file) => {
132
101
  const validation = validateFile(file);
133
102
  if (!validation.valid) {
134
103
  setErrors(validation.error || "Invalid file");
@@ -149,14 +118,54 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
149
118
  const uploadLoader = setupUpload(fileItem, newIndex);
150
119
  const formData = new FormData();
151
120
  formData.append(props.bodyKey, file);
152
- uploadLoader.run({
153
- 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
+ });
154
161
  });
155
162
  emits("change", fileItems.value.map((item) => item.file));
156
163
  };
157
- const handleFileDrop = (files) => {
164
+ const handleFileDrop = async (files) => {
158
165
  if (wrapperProps.value.disabled || wrapperProps.value.readonly || !files?.length) return;
159
- files.forEach((file) => processFile(file));
166
+ for (const file of files) {
167
+ await processFileAsync(file);
168
+ }
160
169
  };
161
170
  const fileDialog = useFileDialog({
162
171
  accept: acceptedFileTypes.value || "",
@@ -175,9 +184,11 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
175
184
  const allSuccess = computed(
176
185
  () => fileItems.value.length > 0 && fileItems.value.every((item) => item.state === "success" /* SUCCESS */)
177
186
  );
178
- fileDialog.onChange((files) => {
187
+ fileDialog.onChange(async (files) => {
179
188
  if (files?.length) {
180
- Array.from(files).forEach((file) => processFile(file));
189
+ for (const file of Array.from(files)) {
190
+ await processFileAsync(file);
191
+ }
181
192
  fileDialog.reset();
182
193
  }
183
194
  });
@@ -200,7 +211,7 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
200
211
  }
201
212
  emits("delete", index);
202
213
  };
203
- const handleRetryUpload = (index) => {
214
+ const handleRetryUpload = async (index) => {
204
215
  const fileItem = fileItems.value[index];
205
216
  if (!fileItem) return;
206
217
  updateFileItem(index, {
@@ -211,8 +222,46 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
211
222
  const uploadLoader = setupUpload(fileItem, index);
212
223
  const formData = new FormData();
213
224
  formData.append(props.bodyKey, fileItem.file);
214
- uploadLoader.run({
215
- 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
+ });
216
265
  });
217
266
  };
218
267
  const handlePreview = (fileValue) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "3.14.4",
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",