@finema/core 1.4.65 → 1.4.67

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