@finema/core 1.4.72 → 1.4.74

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.
Files changed (47) hide show
  1. package/README.md +63 -63
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1 -1
  4. package/dist/runtime/components/Alert.vue +48 -48
  5. package/dist/runtime/components/Avatar.vue +27 -27
  6. package/dist/runtime/components/Badge.vue +53 -53
  7. package/dist/runtime/components/Breadcrumb.vue +44 -44
  8. package/dist/runtime/components/Button/Group.vue +37 -37
  9. package/dist/runtime/components/Button/index.vue +76 -76
  10. package/dist/runtime/components/Card.vue +38 -38
  11. package/dist/runtime/components/Core.vue +13 -13
  12. package/dist/runtime/components/Dialog/index.vue +108 -108
  13. package/dist/runtime/components/Dropdown/index.vue +70 -70
  14. package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
  15. package/dist/runtime/components/Form/Fields.vue +153 -153
  16. package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
  17. package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
  18. package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
  19. package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
  20. package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
  21. package/dist/runtime/components/Form/InputText/index.vue +54 -54
  22. package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
  23. package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
  24. package/dist/runtime/components/Form/InputUploadDropzone/index.vue +158 -158
  25. package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +242 -242
  26. package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +1 -1
  27. package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +102 -102
  28. package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +166 -166
  29. package/dist/runtime/components/Form/index.vue +6 -6
  30. package/dist/runtime/components/Icon.vue +23 -23
  31. package/dist/runtime/components/Image.vue +36 -36
  32. package/dist/runtime/components/Loader.vue +14 -14
  33. package/dist/runtime/components/Modal/index.vue +146 -146
  34. package/dist/runtime/components/SimplePagination.vue +96 -96
  35. package/dist/runtime/components/Slideover/index.vue +110 -110
  36. package/dist/runtime/components/Table/Base.vue +139 -139
  37. package/dist/runtime/components/Table/ColumnDate.vue +16 -16
  38. package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
  39. package/dist/runtime/components/Table/ColumnImage.vue +15 -15
  40. package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
  41. package/dist/runtime/components/Table/ColumnText.vue +25 -25
  42. package/dist/runtime/components/Table/Simple.vue +64 -64
  43. package/dist/runtime/components/Table/index.vue +60 -60
  44. package/dist/runtime/components/Tabs/index.vue +64 -64
  45. package/dist/runtime/helpers/apiPageHelper.mjs +2 -2
  46. package/dist/runtime/ui.css +32 -32
  47. package/package.json +88 -88
@@ -1,242 +1,242 @@
1
- <template>
2
- <FieldWrapper v-bind="wrapperProps">
3
- <div
4
- ref="dropzoneRef"
5
- :class="[
6
- ui.base,
7
- {
8
- [ui.disabled]: isDisabled,
9
- [ui.background.default]: !isOverDropZone && !isDisabled,
10
- [ui.background.dragover]: isOverDropZone && !isDisabled,
11
- },
12
- ]"
13
- >
14
- <Icon
15
- v-if="selectedFile"
16
- :name="ui.default.closeIcon"
17
- :class="[ui.button.delete]"
18
- @click="handleDeleteFile"
19
- />
20
- <input
21
- ref="fileInputRef"
22
- type="file"
23
- class="hidden"
24
- :name="name"
25
- :accept="acceptFile"
26
- :disabled="isDisabled"
27
- @change="handleChange"
28
- />
29
- <div :class="[ui.wrapper]">
30
- <div v-if="selectedFile" :class="[ui.preview.wrapper]">
31
- <div
32
- v-if="isImage(selectedFile) && upload.status.value.isLoaded"
33
- :class="[ui.preview.image.wrapper]"
34
- >
35
- <img
36
- :src="upload.data.value[responseKey || 'url']"
37
- :class="[ui.preview.image.img]"
38
- alt="file"
39
- />
40
- </div>
41
- <Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
42
- <div :class="[ui.preview.filename]">
43
- <p class="truncate">{{ selectedFile.name }}</p>
44
- </div>
45
- <div class="flex items-center space-x-1">
46
- <Badge size="xs" variant="outline" class="mt-1">
47
- {{ isSelectedFileUseMb ? `${selectedFileSizeMb} MB` : `${selectedFileSizeKb} KB` }}
48
- </Badge>
49
- <div>
50
- <Icon
51
- v-if="upload.status.value.isSuccess"
52
- name="heroicons:check-circle-20-solid"
53
- class="text-success"
54
- />
55
- <Icon
56
- v-if="upload.status.value.isError"
57
- name="heroicons:x-circle-20-solid"
58
- class="text-danger"
59
- />
60
- </div>
61
- </div>
62
- </div>
63
- <div v-if="upload.status.value.isLoading" :class="[ui.uploadStatus.wrapper]">
64
- <UProgress :class="[ui.uploadStatus.progressBar]" :value="100" />
65
- </div>
66
- <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
67
- <Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
68
- <div :class="[ui.labelWrapper]">
69
- <p class="text-primary cursor-pointer" @click="handleOpenFile">
70
- {{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
71
- </p>
72
- <p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
73
- </div>
74
- <p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
75
- </div>
76
- </div>
77
- </div>
78
- </FieldWrapper>
79
- </template>
80
-
81
- <script lang="ts" setup>
82
- import { useDropZone } from '@vueuse/core'
83
- import { type IUploadDropzoneAutoProps } from './types'
84
- import { isImage, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
85
- import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
86
- import { useFieldHOC } from '#core/composables/useForm'
87
- import {
88
- type IUploadRequest,
89
- computed,
90
- ref,
91
- toRef,
92
- useUI,
93
- useUiConfig,
94
- useUploadLoader,
95
- useWatchTrue,
96
- StringHelper,
97
- } from '#imports'
98
- import { uploadFileDropzone } from '#core/ui.config'
99
- import i18next from 'i18next'
100
-
101
- const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
102
-
103
- const props = withDefaults(defineProps<IUploadDropzoneAutoProps>(), {})
104
- const emits = defineEmits(['change', 'success', 'delete'])
105
-
106
- const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
107
-
108
- const request: IUploadRequest = {
109
- pathURL: props.uploadPathURL,
110
- requestOptions: props.requestOptions,
111
- }
112
-
113
- const upload = useUploadLoader(request)
114
-
115
- const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
116
-
117
- const fileInputRef = ref<HTMLInputElement>()
118
- const dropzoneRef = ref<HTMLDivElement>()
119
- const selectedFile = ref<File | undefined>()
120
- const percent = ref<number>(0)
121
-
122
- const acceptFile = computed(() =>
123
- typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
124
- )
125
-
126
- const acceptFileSizeKb = computed(() => props.maxSize)
127
- const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
128
- const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
129
-
130
- const selectedFileSizeKb = computed(() => ((selectedFile.value?.size || 0) / 1000).toFixed(2))
131
- const selectedFileSizeMb = computed(() =>
132
- ((selectedFile.value?.size || 0) / 1000 / 1000).toFixed(2)
133
- )
134
-
135
- const isSelectedFileUseMb = computed(() => (selectedFile.value?.size || 0) / 1000 > 1024)
136
-
137
- const onDrop = (files: File[] | null) => {
138
- if (props.isDisabled || files?.length === 0 || !files) return
139
-
140
- const file = files[0]
141
- const result = handleCheckFileCondition(file)
142
-
143
- if (result && file) {
144
- selectedFile.value = file
145
- const formData = new FormData()
146
-
147
- emits('change', file)
148
-
149
- formData.append(props.bodyKey || 'file', file)
150
- upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
151
- }
152
- }
153
-
154
- const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
155
- onDrop,
156
- })
157
-
158
- const handleChange = (e: Event) => {
159
- if (props.isDisabled) return
160
-
161
- const file = (e.target as HTMLInputElement).files?.[0]
162
- const result = handleCheckFileCondition(file)
163
-
164
- if (result && file) {
165
- selectedFile.value = file
166
- const formData = new FormData()
167
-
168
- emits('change', file)
169
-
170
- formData.append(props.bodyKey || 'file', file)
171
- upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
172
- }
173
- }
174
-
175
- const handleOpenFile = () => {
176
- fileInputRef.value?.click()
177
- }
178
-
179
- const handleDeleteFile = () => {
180
- fileInputRef.value?.value && (fileInputRef.value.value = '')
181
- selectedFile.value = undefined
182
- onChange(undefined)
183
- emits('delete')
184
- }
185
-
186
- const handleCheckFileCondition = (file: File | undefined): boolean => {
187
- if (!file) return false
188
-
189
- const fileType = checkFileType(file, acceptFile.value ?? '')
190
-
191
- if (!fileType) {
192
- setErrors(i18next.t('custom:invalid_file_type'))
193
-
194
- return false
195
- }
196
-
197
- const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
198
-
199
- if (!maxSize) {
200
- if (isAcceptFileUseMb.value) {
201
- setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
202
- } else {
203
- setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
204
- }
205
-
206
- return false
207
- }
208
-
209
- setErrors('')
210
-
211
- return true
212
- }
213
-
214
- const onUploadProgress = (progressEvent: ProgressEvent) => {
215
- percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.8
216
- }
217
-
218
- const onDownloadProgress = (progressEvent: ProgressEvent) => {
219
- if (progressEvent.total === 0) {
220
- percent.value = 100
221
-
222
- return
223
- }
224
-
225
- percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.2 + 80
226
- }
227
-
228
- useWatchTrue(
229
- () => upload.status.value.isSuccess,
230
- () => {
231
- value.value = upload.data.value[props.responseKey || 'url']
232
- emits('success', upload.data.value)
233
- }
234
- )
235
-
236
- useWatchTrue(
237
- () => upload.status.value.isError,
238
- () => {
239
- setErrors(StringHelper.getError(upload.status.value.errorData))
240
- }
241
- )
242
- </script>
1
+ <template>
2
+ <FieldWrapper v-bind="wrapperProps">
3
+ <div
4
+ ref="dropzoneRef"
5
+ :class="[
6
+ ui.base,
7
+ {
8
+ [ui.disabled]: isDisabled,
9
+ [ui.background.default]: !isOverDropZone && !isDisabled,
10
+ [ui.background.dragover]: isOverDropZone && !isDisabled,
11
+ },
12
+ ]"
13
+ >
14
+ <Icon
15
+ v-if="selectedFile"
16
+ :name="ui.default.closeIcon"
17
+ :class="[ui.button.delete]"
18
+ @click="handleDeleteFile"
19
+ />
20
+ <input
21
+ ref="fileInputRef"
22
+ type="file"
23
+ class="hidden"
24
+ :name="name"
25
+ :accept="acceptFile"
26
+ :disabled="isDisabled"
27
+ @change="handleChange"
28
+ />
29
+ <div :class="[ui.wrapper]">
30
+ <div v-if="selectedFile" :class="[ui.preview.wrapper]">
31
+ <div
32
+ v-if="isImage(selectedFile) && upload.status.value.isLoaded"
33
+ :class="[ui.preview.image.wrapper]"
34
+ >
35
+ <img
36
+ :src="upload.data.value[responseKey || 'url']"
37
+ :class="[ui.preview.image.img]"
38
+ alt="file"
39
+ />
40
+ </div>
41
+ <Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
42
+ <div :class="[ui.preview.filename]">
43
+ <p class="truncate">{{ selectedFile.name }}</p>
44
+ </div>
45
+ <div class="flex items-center space-x-1">
46
+ <Badge size="xs" variant="outline" class="mt-1">
47
+ {{ isSelectedFileUseMb ? `${selectedFileSizeMb} MB` : `${selectedFileSizeKb} KB` }}
48
+ </Badge>
49
+ <div>
50
+ <Icon
51
+ v-if="upload.status.value.isSuccess"
52
+ name="heroicons:check-circle-20-solid"
53
+ class="text-success"
54
+ />
55
+ <Icon
56
+ v-if="upload.status.value.isError"
57
+ name="heroicons:x-circle-20-solid"
58
+ class="text-danger"
59
+ />
60
+ </div>
61
+ </div>
62
+ </div>
63
+ <div v-if="upload.status.value.isLoading" :class="[ui.uploadStatus.wrapper]">
64
+ <UProgress :class="[ui.uploadStatus.progressBar]" :value="100" />
65
+ </div>
66
+ <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
67
+ <Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
68
+ <div :class="[ui.labelWrapper]">
69
+ <p class="text-primary cursor-pointer" @click="handleOpenFile">
70
+ {{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
71
+ </p>
72
+ <p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
73
+ </div>
74
+ <p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </FieldWrapper>
79
+ </template>
80
+
81
+ <script lang="ts" setup>
82
+ import { useDropZone } from '@vueuse/core'
83
+ import { type IUploadDropzoneAutoProps } from './types'
84
+ import { isImage, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
85
+ import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
86
+ import { useFieldHOC } from '#core/composables/useForm'
87
+ import {
88
+ type IUploadRequest,
89
+ computed,
90
+ ref,
91
+ toRef,
92
+ useUI,
93
+ useUiConfig,
94
+ useUploadLoader,
95
+ useWatchTrue,
96
+ StringHelper,
97
+ } from '#imports'
98
+ import { uploadFileDropzone } from '#core/ui.config'
99
+ import i18next from 'i18next'
100
+
101
+ const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
102
+
103
+ const props = withDefaults(defineProps<IUploadDropzoneAutoProps>(), {})
104
+ const emits = defineEmits(['change', 'success', 'delete'])
105
+
106
+ const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
107
+
108
+ const request: IUploadRequest = {
109
+ pathURL: props.uploadPathURL,
110
+ requestOptions: props.requestOptions,
111
+ }
112
+
113
+ const upload = useUploadLoader(request)
114
+
115
+ const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
116
+
117
+ const fileInputRef = ref<HTMLInputElement>()
118
+ const dropzoneRef = ref<HTMLDivElement>()
119
+ const selectedFile = ref<File | undefined>()
120
+ const percent = ref<number>(0)
121
+
122
+ const acceptFile = computed(() =>
123
+ typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
124
+ )
125
+
126
+ const acceptFileSizeKb = computed(() => props.maxSize)
127
+ const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
128
+ const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
129
+
130
+ const selectedFileSizeKb = computed(() => ((selectedFile.value?.size || 0) / 1000).toFixed(2))
131
+ const selectedFileSizeMb = computed(() =>
132
+ ((selectedFile.value?.size || 0) / 1000 / 1000).toFixed(2)
133
+ )
134
+
135
+ const isSelectedFileUseMb = computed(() => (selectedFile.value?.size || 0) / 1000 > 1024)
136
+
137
+ const onDrop = (files: File[] | null) => {
138
+ if (props.isDisabled || files?.length === 0 || !files) return
139
+
140
+ const file = files[0]
141
+ const result = handleCheckFileCondition(file)
142
+
143
+ if (result && file) {
144
+ selectedFile.value = file
145
+ const formData = new FormData()
146
+
147
+ emits('change', file)
148
+
149
+ formData.append(props.bodyKey || 'file', file)
150
+ upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
151
+ }
152
+ }
153
+
154
+ const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
155
+ onDrop,
156
+ })
157
+
158
+ const handleChange = (e: Event) => {
159
+ if (props.isDisabled) return
160
+
161
+ const file = (e.target as HTMLInputElement).files?.[0]
162
+ const result = handleCheckFileCondition(file)
163
+
164
+ if (result && file) {
165
+ selectedFile.value = file
166
+ const formData = new FormData()
167
+
168
+ emits('change', file)
169
+
170
+ formData.append(props.bodyKey || 'file', file)
171
+ upload.run(formData, { data: { onUploadProgress, onDownloadProgress } })
172
+ }
173
+ }
174
+
175
+ const handleOpenFile = () => {
176
+ fileInputRef.value?.click()
177
+ }
178
+
179
+ const handleDeleteFile = () => {
180
+ fileInputRef.value?.value && (fileInputRef.value.value = '')
181
+ selectedFile.value = undefined
182
+ onChange(undefined)
183
+ emits('delete')
184
+ }
185
+
186
+ const handleCheckFileCondition = (file: File | undefined): boolean => {
187
+ if (!file) return false
188
+
189
+ const fileType = checkFileType(file, acceptFile.value ?? '')
190
+
191
+ if (!fileType) {
192
+ setErrors(i18next.t('custom:invalid_file_type'))
193
+
194
+ return false
195
+ }
196
+
197
+ const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
198
+
199
+ if (!maxSize) {
200
+ if (isAcceptFileUseMb.value) {
201
+ setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
202
+ } else {
203
+ setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
204
+ }
205
+
206
+ return false
207
+ }
208
+
209
+ setErrors('')
210
+
211
+ return true
212
+ }
213
+
214
+ const onUploadProgress = (progressEvent: ProgressEvent) => {
215
+ percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.8
216
+ }
217
+
218
+ const onDownloadProgress = (progressEvent: ProgressEvent) => {
219
+ if (progressEvent.total === 0) {
220
+ percent.value = 100
221
+
222
+ return
223
+ }
224
+
225
+ percent.value = (Math.floor((progressEvent.loaded * 100) / progressEvent.total) || 0) * 0.2 + 80
226
+ }
227
+
228
+ useWatchTrue(
229
+ () => upload.status.value.isSuccess,
230
+ () => {
231
+ value.value = upload.data.value[props.responseKey || 'url']
232
+ emits('success', upload.data.value)
233
+ }
234
+ )
235
+
236
+ useWatchTrue(
237
+ () => upload.status.value.isError,
238
+ () => {
239
+ setErrors(StringHelper.getError(upload.status.value.errorData))
240
+ }
241
+ )
242
+ </script>
@@ -14,6 +14,6 @@ export interface IUploadDropzoneAutoProps extends IFieldProps {
14
14
  }
15
15
  export type IUploadDropzoneAutoField = IFormFieldBase<INPUT_TYPES.UPLOAD_DROPZONE_AUTO, IUploadDropzoneAutoProps, {
16
16
  change: (value: File | undefined) => void;
17
- success: (value: string) => void;
17
+ success: (res: any) => void;
18
18
  delete: () => void;
19
19
  }>;