@finema/core 1.4.90 → 1.4.91

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 (54) hide show
  1. package/README.md +63 -63
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +3 -2
  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/FlexDeck/Base.vue +90 -90
  15. package/dist/runtime/components/FlexDeck/index.vue +66 -66
  16. package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
  17. package/dist/runtime/components/Form/Fields.vue +160 -160
  18. package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
  19. package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
  20. package/dist/runtime/components/Form/InputNumber/index.vue +27 -27
  21. package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
  22. package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
  23. package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
  24. package/dist/runtime/components/Form/InputText/index.vue +67 -67
  25. package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
  26. package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
  27. package/dist/runtime/components/Form/InputUploadDropzone/index.vue +213 -158
  28. package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +349 -243
  29. package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +3 -0
  30. package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +101 -101
  31. package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +174 -174
  32. package/dist/runtime/components/Form/index.vue +6 -6
  33. package/dist/runtime/components/Icon.vue +23 -23
  34. package/dist/runtime/components/Image.vue +36 -36
  35. package/dist/runtime/components/Loader.vue +27 -27
  36. package/dist/runtime/components/Modal/index.vue +146 -146
  37. package/dist/runtime/components/SimplePagination.vue +96 -96
  38. package/dist/runtime/components/Slideover/index.vue +110 -110
  39. package/dist/runtime/components/Table/Base.vue +139 -139
  40. package/dist/runtime/components/Table/ColumnDate.vue +16 -16
  41. package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
  42. package/dist/runtime/components/Table/ColumnImage.vue +15 -15
  43. package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
  44. package/dist/runtime/components/Table/ColumnText.vue +25 -25
  45. package/dist/runtime/components/Table/Simple.vue +69 -69
  46. package/dist/runtime/components/Table/index.vue +65 -65
  47. package/dist/runtime/components/Tabs/index.vue +64 -64
  48. package/dist/runtime/helpers/componentHelper.d.ts +9 -0
  49. package/dist/runtime/helpers/componentHelper.mjs +30 -0
  50. package/dist/runtime/ui.config/uploadFileDropzone.d.ts +36 -13
  51. package/dist/runtime/ui.config/uploadFileDropzone.mjs +42 -19
  52. package/dist/runtime/utils/StringHelper.d.ts +1 -0
  53. package/dist/runtime/utils/StringHelper.mjs +6 -0
  54. package/package.json +88 -88
@@ -1,158 +1,213 @@
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 v-if="isImage(selectedFile)" :class="[ui.preview.image.wrapper]">
32
- <img :src="generateURL(selectedFile)" :class="[ui.preview.image.img]" alt="file" />
33
- </div>
34
- <Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
35
- <div :class="[ui.preview.filename]">
36
- <p class="truncate">{{ selectedFile.name }}</p>
37
- </div>
38
- <Badge size="xs" variant="outline" class="mt-1">
39
- {{ isSelectedFileUseMb ? `${selectedFileSizeMb} Mb` : `${selectedFileSizeKb} Kb` }}
40
- </Badge>
41
- </div>
42
- <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
43
- <Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
44
- <div :class="[ui.labelWrapper]">
45
- <p class="text-primary cursor-pointer" @click="handleOpenFile">
46
- {{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
47
- </p>
48
- <p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
49
- </div>
50
- <p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
51
- </div>
52
- </div>
53
- </div>
54
- </FieldWrapper>
55
- </template>
56
-
57
- <script lang="ts" setup>
58
- import { useDropZone } from '@vueuse/core'
59
- import { type IUploadDropzoneProps } from './types'
60
- import { isImage, generateURL, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
61
- import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
62
- import { useFieldHOC } from '#core/composables/useForm'
63
- import { computed, ref, toRef, useUI, useUiConfig } from '#imports'
64
- import { uploadFileDropzone } from '#core/ui.config'
65
- import i18next from 'i18next'
66
-
67
- const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
68
-
69
- const props = withDefaults(defineProps<IUploadDropzoneProps>(), {})
70
- const emit = defineEmits(['change', 'delete'])
71
-
72
- const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
73
-
74
- const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
75
-
76
- const fileInputRef = ref<HTMLInputElement>()
77
- const dropzoneRef = ref<HTMLDivElement>()
78
-
79
- const acceptFile = computed(() =>
80
- typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
81
- )
82
-
83
- const acceptFileSizeKb = computed(() => props.maxSize)
84
- const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
85
- const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
86
-
87
- const selectedFileSizeKb = computed(() => ((value?.value.size || 0) / 1000).toFixed(2))
88
- const selectedFileSizeMb = computed(() => ((value?.value.size || 0) / 1000 / 1000).toFixed(2))
89
- const isSelectedFileUseMb = computed(() => (value?.value.size || 0) / 1000 > 1024)
90
- const selectedFile = computed(() => value?.value)
91
-
92
- const onDrop = (files: File[] | null) => {
93
- if (props.isDisabled || files?.length === 0 || !files) return
94
-
95
- const file = files[0]
96
- const result = handleCheckFileCondition(file)
97
-
98
- if (result) {
99
- onChange(file)
100
- emit('change', file)
101
- }
102
- }
103
-
104
- const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
105
- onDrop,
106
- })
107
-
108
- const handleChange = (e: Event) => {
109
- if (props.isDisabled) return
110
-
111
- const file = (e.target as HTMLInputElement).files?.[0]
112
- const result = handleCheckFileCondition(file)
113
-
114
- if (result && file) {
115
- onChange(file)
116
- value.value = file
117
- emit('change', file)
118
- }
119
- }
120
-
121
- const handleOpenFile = () => {
122
- fileInputRef.value?.click()
123
- }
124
-
125
- const handleDeleteFile = () => {
126
- fileInputRef.value?.value && (fileInputRef.value.value = '')
127
- onChange(undefined)
128
- emit('delete')
129
- }
130
-
131
- const handleCheckFileCondition = (file: File | undefined): boolean => {
132
- if (!file) return false
133
-
134
- const fileType = checkFileType(file, acceptFile.value ?? '')
135
-
136
- if (!fileType) {
137
- setErrors(i18next.t('custom:invalid_file_type'))
138
-
139
- return false
140
- }
141
-
142
- const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
143
-
144
- if (!maxSize) {
145
- if (isAcceptFileUseMb.value) {
146
- setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
147
- } else {
148
- setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
149
- }
150
-
151
- return false
152
- }
153
-
154
- setErrors('')
155
-
156
- return true
157
- }
158
- </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
+ <input
15
+ ref="fileInputRef"
16
+ type="file"
17
+ class="hidden"
18
+ :name="name"
19
+ :accept="acceptFile"
20
+ :disabled="isDisabled"
21
+ @change="handleChange"
22
+ />
23
+ <div :class="[ui.wrapper]">
24
+ <div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
25
+ <Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
26
+ <div :class="[ui.labelWrapper]">
27
+ <p class="text-primary cursor-pointer" @click="handleOpenFile">
28
+ {{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
29
+ </p>
30
+ <p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
31
+ </div>
32
+ <p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
33
+ </div>
34
+
35
+ <!-- Selected State -->
36
+ <div v-if="selectedFile" :class="[ui.onPreview.wrapper]">
37
+ <div :class="[ui.onPreview.previewImgWrapper]">
38
+ <div v-if="isImage(selectedFile)" class="size-full overflow-hidden">
39
+ <img
40
+ :src="generateURL(selectedFile)"
41
+ :class="[ui.onPreview.previewImgClass]"
42
+ alt="image-preview"
43
+ />
44
+ </div>
45
+ <div v-else>
46
+ <Icon
47
+ :name="ui.onPreview.previewFileIcon || ui.default.filePreviewIcon"
48
+ :class="[ui.onPreview.previewFileClass]"
49
+ />
50
+ </div>
51
+ </div>
52
+ <div :class="[ui.onPreview.textWrapper]">
53
+ <div class="truncate">
54
+ <h1 class="truncate font-bold">{{ selectedFile?.name }}</h1>
55
+ <p class="truncate font-light text-gray-400">
56
+ {{
57
+ fileAllocate.isSelectedFileUseMb
58
+ ? `${fileAllocate.selectedFileSizeMb} MB`
59
+ : `${fileAllocate.selectedFileSizeKb} KB`
60
+ }}
61
+ </p>
62
+ </div>
63
+ <div :class="[ui.action.wrapper]">
64
+ <PImage
65
+ v-if="isImage(selectedFile)"
66
+ alt="image-popup-preview"
67
+ preview
68
+ :pt="{ button: 'absolute opacity-0 inset-0' }"
69
+ >
70
+ <template #image>
71
+ <Icon :name="ui.action.previewIcon" :class="[ui.action.iconClass]" />
72
+ </template>
73
+ <template #preview="slotProps">
74
+ <img
75
+ :src="generateURL(selectedFile)"
76
+ alt="preview"
77
+ :style="slotProps.style"
78
+ @click="slotProps.previewCallback"
79
+ />
80
+ </template>
81
+ </PImage>
82
+ <Icon
83
+ :name="ui.action.downloadIcon"
84
+ :class="[ui.action.iconClass]"
85
+ @click="handleDownloadFile"
86
+ />
87
+ <Icon
88
+ :name="ui.action.deleteIcon"
89
+ :class="[ui.action.iconClass]"
90
+ @click="handleDeleteFile"
91
+ />
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ </FieldWrapper>
98
+ </template>
99
+
100
+ <script lang="ts" setup>
101
+ import { useDropZone } from '@vueuse/core'
102
+ import { type IUploadDropzoneProps } from './types'
103
+ import {
104
+ isImage,
105
+ generateURL,
106
+ checkMaxSize,
107
+ checkFileType,
108
+ getFileAllocate,
109
+ downloadFileFromURL,
110
+ } from '#core/helpers/componentHelper'
111
+ import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
112
+ import { useFieldHOC } from '#core/composables/useForm'
113
+ import { computed, ref, toRef, useUI, useUiConfig } from '#imports'
114
+ import { uploadFileDropzone } from '#core/ui.config'
115
+ import i18next from 'i18next'
116
+
117
+ const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
118
+
119
+ const props = withDefaults(defineProps<IUploadDropzoneProps>(), {})
120
+ const emit = defineEmits(['change', 'delete'])
121
+
122
+ const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
123
+
124
+ const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
125
+
126
+ const fileInputRef = ref<HTMLInputElement>()
127
+ const dropzoneRef = ref<HTMLDivElement>()
128
+
129
+ const acceptFile = computed(() =>
130
+ typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
131
+ )
132
+
133
+ const fileAllocate = computed(() =>
134
+ getFileAllocate(props.maxSize ?? 0, selectedFile.value?.size ?? 0)
135
+ )
136
+
137
+ const selectedFile = computed(() => value?.value)
138
+
139
+ const onDrop = (files: File[] | null) => {
140
+ if (props.isDisabled || files?.length === 0 || !files) return
141
+
142
+ const file = files[0]
143
+ const result = handleCheckFileCondition(file)
144
+
145
+ if (result) {
146
+ onChange(file)
147
+ emit('change', file)
148
+ }
149
+ }
150
+
151
+ const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
152
+ onDrop,
153
+ })
154
+
155
+ const handleChange = (e: Event) => {
156
+ if (props.isDisabled) return
157
+
158
+ const file = (e.target as HTMLInputElement).files?.[0]
159
+ const result = handleCheckFileCondition(file)
160
+
161
+ if (result && file) {
162
+ onChange(file)
163
+ value.value = file
164
+ emit('change', file)
165
+ }
166
+ }
167
+
168
+ const handleOpenFile = () => {
169
+ fileInputRef.value?.click()
170
+ }
171
+
172
+ const handleDeleteFile = () => {
173
+ fileInputRef.value?.value && (fileInputRef.value.value = '')
174
+ onChange(undefined)
175
+ emit('delete')
176
+ }
177
+
178
+ const handleDownloadFile = () => {
179
+ downloadFileFromURL(generateURL(selectedFile.value), selectedFile.value?.name)
180
+ }
181
+
182
+ const handleCheckFileCondition = (file: File | undefined): boolean => {
183
+ if (!file) return false
184
+
185
+ const fileType = checkFileType(file, acceptFile.value ?? '')
186
+
187
+ if (!fileType) {
188
+ setErrors(i18next.t('custom:invalid_file_type'))
189
+
190
+ return false
191
+ }
192
+
193
+ const maxSize = checkMaxSize(file, fileAllocate.value.acceptFileSizeKb ?? 0)
194
+
195
+ if (!maxSize) {
196
+ if (fileAllocate.value.isAcceptFileUseMb) {
197
+ setErrors(
198
+ i18next.t('custom:invalid_file_size_mb', { size: fileAllocate.value.acceptFileSizeMb })
199
+ )
200
+ } else {
201
+ setErrors(
202
+ i18next.t('custom:invalid_file_size_kb', { size: fileAllocate.value.acceptFileSizeKb })
203
+ )
204
+ }
205
+
206
+ return false
207
+ }
208
+
209
+ setErrors('')
210
+
211
+ return true
212
+ }
213
+ </script>