@finema/core 3.4.0 → 3.5.2

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.4.0",
3
+ "version": "3.5.2",
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.4.0";
7
+ const version = "3.5.2";
8
8
 
9
9
  const nuxtAppOptions = {
10
10
  head: {
@@ -2,11 +2,11 @@ import type { IUploadDropzoneAutoMultipleProps } from './types.js';
2
2
  import type { IFileValue } from '#core/components/Form/types';
3
3
  declare const __VLS_export: import("vue").DefineComponent<IUploadDropzoneAutoMultipleProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
4
  success: (res: IFileValue) => any;
5
- delete: (index: number) => any;
5
+ delete: (index: number, value: IFileValue) => any;
6
6
  change: (value: File[] | undefined) => any;
7
7
  }, string, import("vue").PublicProps, Readonly<IUploadDropzoneAutoMultipleProps> & Readonly<{
8
8
  onSuccess?: ((res: IFileValue) => any) | undefined;
9
- onDelete?: ((index: number) => any) | undefined;
9
+ onDelete?: ((index: number, value: IFileValue) => any) | undefined;
10
10
  onChange?: ((value: File[] | undefined) => any) | undefined;
11
11
  }>, {
12
12
  selectFileLabel: string;
@@ -29,14 +29,34 @@
29
29
  @delete="uploadState.handleDeleteFile"
30
30
  @retry="uploadState.handleRetryUpload"
31
31
  />
32
+
33
+ <!-- Success State -->
34
+ <div
35
+ v-for="(item, index) in value"
36
+ :key="index"
37
+ :class="theme.multipleFilesWrapper()"
38
+ >
39
+ <div :class="theme.fileItemWrapper()">
40
+ <SuccessState
41
+ :theme="theme"
42
+ :value="item"
43
+ :disabled="wrapperProps.disabled"
44
+ :readonly="wrapperProps.readonly"
45
+ @preview="uploadState.handlePreview(item)"
46
+ @download="handleDownloadFile(item)"
47
+ @delete="handleDeleteFile(index, item)"
48
+ />
49
+ </div>
50
+ </div>
32
51
  </FieldWrapper>
33
52
  </template>
34
53
 
35
54
  <script setup>
36
55
  import EmptyState from "../fileState/EmptyState.vue";
37
56
  import MultipleFilesState from "../fileState/MultipleFilesState.vue";
57
+ import SuccessState from "../fileState/SuccessState.vue";
38
58
  import { useUploadStateMultiple } from "../fileState/useUploadStateMultiple";
39
- import { computed, useTemplateRef } from "#imports";
59
+ import { computed, DialogType, useDialog, useTemplateRef } from "#imports";
40
60
  import FieldWrapper from "#core/components/Form/FieldWrapper.vue";
41
61
  import { useFieldHOC } from "#core/composables/useForm";
42
62
  import { uploadFileDropzoneTheme } from "#core/theme/uploadFileDropzone";
@@ -81,6 +101,7 @@ const {
81
101
  setErrors,
82
102
  value
83
103
  } = useFieldHOC(props);
104
+ const dialog = useDialog();
84
105
  const acceptedFileTypes = computed(
85
106
  () => typeof props.accept === "string" ? props.accept : props.accept?.join(",")
86
107
  );
@@ -107,4 +128,14 @@ const handleDownloadFile = (fileValue) => {
107
128
  downloadFileFromURL(fileValue.url, fileValue.name);
108
129
  }
109
130
  };
131
+ const handleDeleteFile = (index, fileValue) => {
132
+ dialog.confirm({
133
+ type: DialogType.ERROR,
134
+ title: "\u0E25\u0E1A\u0E44\u0E1F\u0E25\u0E4C",
135
+ description: `\u0E04\u0E38\u0E13\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23\u0E25\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${fileValue.name} \u0E43\u0E0A\u0E48\u0E2B\u0E23\u0E37\u0E2D\u0E44\u0E21\u0E48`
136
+ }).then(() => {
137
+ emits("delete", index, fileValue);
138
+ value.value?.splice(index, 1);
139
+ });
140
+ };
110
141
  </script>
@@ -2,11 +2,11 @@ import type { IUploadDropzoneAutoMultipleProps } from './types.js';
2
2
  import type { IFileValue } from '#core/components/Form/types';
3
3
  declare const __VLS_export: import("vue").DefineComponent<IUploadDropzoneAutoMultipleProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
4
  success: (res: IFileValue) => any;
5
- delete: (index: number) => any;
5
+ delete: (index: number, value: IFileValue) => any;
6
6
  change: (value: File[] | undefined) => any;
7
7
  }, string, import("vue").PublicProps, Readonly<IUploadDropzoneAutoMultipleProps> & Readonly<{
8
8
  onSuccess?: ((res: IFileValue) => any) | undefined;
9
- onDelete?: ((index: number) => any) | undefined;
9
+ onDelete?: ((index: number, value: IFileValue) => any) | undefined;
10
10
  onChange?: ((value: File[] | undefined) => any) | undefined;
11
11
  }>, {
12
12
  selectFileLabel: string;
@@ -1,5 +1,5 @@
1
1
  import type { AxiosRequestConfig } from 'axios';
2
- import type { IFieldProps, IFormFieldBase, INPUT_TYPES } from '../types.js';
2
+ import type { IFieldProps, IFileValue, IFormFieldBase, INPUT_TYPES } from '../types.js';
3
3
  export interface IUploadDropzoneAutoMultipleProps extends IFieldProps {
4
4
  requestOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
5
5
  baseURL: string;
@@ -23,5 +23,5 @@ export interface IUploadDropzoneAutoMultipleProps extends IFieldProps {
23
23
  export type IUploadDropzoneAutoMultipleField = IFormFieldBase<INPUT_TYPES.UPLOAD_DROPZONE_AUTO_MULTIPLE, IUploadDropzoneAutoMultipleProps, {
24
24
  change: (value: File[] | undefined) => void;
25
25
  success: (res: any) => void;
26
- delete: (index: number) => void;
26
+ delete: (index: number, value: IFileValue) => void;
27
27
  }>;
@@ -34,76 +34,6 @@
34
34
  </div>
35
35
  </div>
36
36
 
37
- <!-- Success State -->
38
- <div
39
- v-else-if="item.state === UploadState.SUCCESS && item.value"
40
- :class="theme.successItemWrapper()"
41
- >
42
- <div
43
- v-if="isImageFromPath(item.value.path)"
44
- :class="theme.successImgWrapper()"
45
- >
46
- <img
47
- :src="item.value.url"
48
- :class="theme.successImgClass()"
49
- alt="img-preview"
50
- />
51
- </div>
52
- <div
53
- v-else
54
- :class="theme.successFileWrapper()"
55
- >
56
- <Icon
57
- :name="icons.filePreviewIcon"
58
- :class="theme.successFileClass()"
59
- />
60
- </div>
61
- <div :class="theme.successTextWrapper()">
62
- <div class="truncate">
63
- <h1 class="truncate font-bold">
64
- {{ item.value.name }}
65
- </h1>
66
- <p class="truncate text-sm font-light text-gray-400">
67
- {{ getFileSizeFromValue(item.value) }}
68
- </p>
69
- </div>
70
- <div :class="theme.actionWrapper()">
71
- <a
72
- v-if="isPDFFromPath(item.value.path)"
73
- :href="item.value.url"
74
- target="_blank"
75
- class="flex"
76
- >
77
- <Icon
78
- :name="icons.actionPreviewIcon"
79
- :class="theme.actionIconClass()"
80
- title="ดูตัวอย่าง"
81
- />
82
- </a>
83
- <Icon
84
- v-if="isImageFromPath(item.value.path) || isVideoFromPath(item.value.path)"
85
- :name="icons.actionPreviewIcon"
86
- :class="theme.actionIconClass()"
87
- title="ดูตัวอย่าง"
88
- @click="$emit('preview', item.value)"
89
- />
90
- <Icon
91
- :name="icons.actionDownloadIcon"
92
- :class="theme.actionIconClass()"
93
- title="ดาวน์โหลดไฟล์"
94
- @click="$emit('download', item.value)"
95
- />
96
- <Icon
97
- v-if="!disabled && !readonly"
98
- :name="icons.actionDeleteIcon"
99
- :class="theme.actionIconClass()"
100
- title="ลบไฟล์"
101
- @click="$emit('delete', index)"
102
- />
103
- </div>
104
- </div>
105
- </div>
106
-
107
37
  <!-- Error State -->
108
38
  <div
109
39
  v-else-if="item.state === UploadState.ERROR"
@@ -147,12 +77,6 @@
147
77
  </template>
148
78
 
149
79
  <script setup>
150
- import {
151
- isImageFromPath,
152
- isPDFFromPath,
153
- isVideoFromPath,
154
- useFileSize
155
- } from "#core/helpers/componentHelper";
156
80
  import { useUiIconConfig } from "#core/composables/useConfig";
157
81
  import { UploadState } from "./useUploadStateMultiple";
158
82
  defineEmits(["preview", "download", "delete", "retry"]);
@@ -165,8 +89,4 @@ defineProps({
165
89
  retryLabel: { type: String, required: false }
166
90
  });
167
91
  const icons = useUiIconConfig("uploadFileDropzone");
168
- const getFileSizeFromValue = (fileValue) => {
169
- const allocate = useFileSize(fileValue.size || 0);
170
- return allocate.isSelectedFileUseMb.value ? `${allocate.selectedFileSizeMb.value} MB` : `${allocate.selectedFileSizeKb.value} KB`;
171
- };
172
92
  </script>
@@ -1,6 +1,6 @@
1
1
  import { useDropZone, useFileDialog } from "@vueuse/core";
2
2
  import PreviewModal from "./PreviewModal.vue";
3
- import { computed, ref, useOverlay, watch } from "#imports";
3
+ import { ArrayHelper, computed, ref, useOverlay, watch } from "#imports";
4
4
  import { useUploadLoader } from "#core/composables/useUpload";
5
5
  import { useFileAllocate, useFileProgress } from "#core/helpers/componentHelper";
6
6
  import { StringHelper } from "#core/utils/StringHelper";
@@ -98,11 +98,8 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
98
98
  size: Number(_get(uploadLoader.data.value, props.responseSize) || fileItem.file.size),
99
99
  id: _get(uploadLoader.data.value, props.responseID)
100
100
  };
101
- updateFileItem(index, {
102
- value: fileValue,
103
- state: "success" /* SUCCESS */
104
- });
105
- updateFormValue();
101
+ fileItems.value.splice(index, 1);
102
+ onChange([fileValue, ...ArrayHelper.toArray(value.value)]);
106
103
  emits("success", fileValue);
107
104
  stopProgressWatch();
108
105
  stopSuccessWatch();
@@ -154,10 +151,6 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
154
151
  });
155
152
  emits("change", fileItems.value.map((item) => item.file));
156
153
  };
157
- const updateFormValue = () => {
158
- const successfulFiles = fileItems.value.filter((item) => item.state === "success" /* SUCCESS */ && item.value).map((item) => item.value);
159
- onChange(successfulFiles.length > 0 ? successfulFiles : void 0);
160
- };
161
154
  const handleFileDrop = (files) => {
162
155
  if (wrapperProps.value.disabled || wrapperProps.value.readonly || !files?.length) return;
163
156
  files.forEach((file) => processFile(file));
@@ -195,7 +188,6 @@ export const useUploadStateMultiple = (props, emits, onChange, setErrors, value,
195
188
  };
196
189
  const handleDeleteFile = (index) => {
197
190
  fileItems.value.splice(index, 1);
198
- updateFormValue();
199
191
  if (fileItems.value.length === 0) {
200
192
  setErrors("");
201
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "3.4.0",
3
+ "version": "3.5.2",
4
4
  "repository": "https://gitlab.finema.co/finema/ui-kit",
5
5
  "license": "MIT",
6
6
  "author": "Finema Dev Core Team",