@witchcraft/ui 0.1.3 → 0.2.1-beta.1

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 (179) hide show
  1. package/README.md +3 -6
  2. package/dist/module.json +3 -3
  3. package/dist/module.mjs +15 -12
  4. package/dist/runtime/build/generateTheme.js +1 -1
  5. package/dist/runtime/components/Aria/Aria.vue +5 -9
  6. package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
  7. package/dist/runtime/components/Icon/Icon.vue +10 -30
  8. package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
  9. package/dist/runtime/components/LibButton/LibButton.vue +51 -72
  10. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
  11. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +43 -74
  12. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
  13. package/dist/runtime/components/LibColorInput/LibColorInput.vue +63 -107
  14. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
  15. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +272 -352
  16. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
  17. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +1 -1
  18. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +1 -1
  19. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +35 -69
  20. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
  21. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +17 -38
  22. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
  23. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +58 -82
  24. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
  25. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +55 -67
  26. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
  27. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +7 -8
  28. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
  29. package/dist/runtime/components/LibDebug/LibDebug.vue +43 -70
  30. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
  31. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +18 -31
  32. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
  33. package/dist/runtime/components/LibFileInput/LibFileInput.vue +116 -156
  34. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
  35. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +211 -241
  36. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
  37. package/dist/runtime/components/LibLabel/LibLabel.vue +25 -46
  38. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +26 -0
  39. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +43 -58
  40. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
  41. package/dist/runtime/components/LibNotifications/LibNotification.vue +34 -48
  42. package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
  43. package/dist/runtime/components/LibNotifications/LibNotifications.vue +63 -83
  44. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
  45. package/dist/runtime/components/LibPagination/LibPagination.vue +67 -111
  46. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
  47. package/dist/runtime/components/LibPalette/LibPalette.vue +17 -23
  48. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
  49. package/dist/runtime/components/LibPopup/LibPopup.vue +314 -351
  50. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
  51. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +65 -91
  52. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
  53. package/dist/runtime/components/LibRecorder/LibRecorder.vue +127 -177
  54. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
  55. package/dist/runtime/components/LibRoot/LibRoot.vue +75 -101
  56. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
  57. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +42 -77
  58. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
  59. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +118 -156
  60. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
  61. package/dist/runtime/components/LibTable/LibTable.vue +63 -99
  62. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
  63. package/dist/runtime/components/Template/NAME.vue +15 -36
  64. package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
  65. package/dist/runtime/components/TestControls/TestControls.vue +6 -9
  66. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
  67. package/dist/runtime/components/shared/props.d.ts +0 -29
  68. package/dist/runtime/components/shared/props.js +0 -12
  69. package/dist/runtime/composables/useAccesibilityOutline.js +1 -1
  70. package/dist/runtime/composables/useDivideAttrs.js +1 -1
  71. package/dist/runtime/composables/useSuggestions.js +4 -4
  72. package/dist/runtime/directives/vDetectFlex.js +4 -4
  73. package/dist/runtime/directives/vExtractRootEl.d.ts +1 -1
  74. package/dist/runtime/directives/vResizableCols.d.ts +1 -1
  75. package/dist/runtime/directives/vResizableCols.js +4 -4
  76. package/dist/runtime/helpers/NotificationHandler.js +6 -6
  77. package/dist/runtime/helpers/base64ToImg.js +2 -2
  78. package/dist/runtime/nuxt/plugins/vue-plugin.js +1 -1
  79. package/dist/runtime/tailwind/themeConvertionOpts.d.ts +1 -1
  80. package/dist/runtime/theme.d.ts +1 -1
  81. package/dist/runtime/theme.js +1 -1
  82. package/dist/runtime/utils/notifyIfError.js +1 -1
  83. package/dist/runtime/vue/registerComponents.js +1 -1
  84. package/dist/types.d.mts +2 -6
  85. package/package.json +68 -90
  86. package/src/module.ts +19 -12
  87. package/src/runtime/build/generateTheme.ts +1 -1
  88. package/src/runtime/components/LibButton/LibButton.stories.ts +1 -1
  89. package/src/runtime/components/LibButton/LibButton.vue +3 -3
  90. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +3 -7
  91. package/src/runtime/components/LibColorPicker/LibColorPicker.vue +6 -4
  92. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +1 -1
  93. package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +1 -1
  94. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +8 -15
  95. package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +6 -0
  96. package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +6 -0
  97. package/src/runtime/components/LibDebug/LibDebug.stories.ts +1 -1
  98. package/src/runtime/components/LibDebug/LibDebug.vue +2 -0
  99. package/src/runtime/components/LibFileInput/LibFileInput.vue +4 -0
  100. package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +7 -5
  101. package/src/runtime/components/LibLabel/LibLabel.vue +2 -3
  102. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +5 -3
  103. package/src/runtime/components/LibNotifications/LibNotification.vue +3 -0
  104. package/src/runtime/components/LibNotifications/LibNotifications.vue +1 -1
  105. package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
  106. package/src/runtime/components/LibPopup/LibPopup.vue +2 -2
  107. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +2 -2
  108. package/src/runtime/components/LibRecorder/LibRecorder.vue +3 -3
  109. package/src/runtime/components/LibRoot/LibRoot.vue +3 -2
  110. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +2 -2
  111. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +2 -2
  112. package/src/runtime/components/LibTable/LibTable.vue +1 -1
  113. package/src/runtime/components/Template/NAME.vue +2 -2
  114. package/src/runtime/components/shared/props.ts +8 -12
  115. package/src/runtime/composables/useAccesibilityOutline.ts +1 -1
  116. package/src/runtime/composables/useDivideAttrs.ts +1 -1
  117. package/src/runtime/composables/useSuggestions.ts +4 -4
  118. package/src/runtime/directives/vDetectFlex.ts +4 -4
  119. package/src/runtime/directives/vExtractRootEl.ts +1 -1
  120. package/src/runtime/directives/vResizableCols.ts +5 -5
  121. package/src/runtime/helpers/NotificationHandler.ts +6 -6
  122. package/src/runtime/nuxt/plugins/vue-plugin.ts +1 -1
  123. package/src/runtime/tailwind/themeConvertionOpts.ts +1 -1
  124. package/src/runtime/theme.ts +2 -2
  125. package/src/runtime/utils/notifyIfError.ts +1 -1
  126. package/src/runtime/vue/registerComponents.ts +1 -1
  127. package/dist/module.cjs +0 -5
  128. package/dist/module.d.ts +0 -36
  129. package/dist/runtime/components/Focus.stories.d.ts +0 -11
  130. package/dist/runtime/components/Focus.stories.js +0 -53
  131. package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
  132. package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
  133. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
  134. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
  135. package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
  136. package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
  137. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -9
  138. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -68
  139. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
  140. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
  141. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
  142. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
  143. package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
  144. package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
  145. package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
  146. package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
  147. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +0 -33
  148. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +0 -384
  149. package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
  150. package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
  151. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
  152. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -61
  153. package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
  154. package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
  155. package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
  156. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
  157. package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
  158. package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
  159. package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
  160. package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
  161. package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
  162. package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
  163. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
  164. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
  165. package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
  166. package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
  167. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
  168. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
  169. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
  170. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
  171. package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
  172. package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
  173. package/dist/runtime/components/Reset.stories.d.ts +0 -5
  174. package/dist/runtime/components/Reset.stories.js +0 -19
  175. package/dist/runtime/components/Scrolling.stories.d.ts +0 -6
  176. package/dist/runtime/components/Scrolling.stories.js +0 -44
  177. package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
  178. package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
  179. package/dist/types.d.ts +0 -7
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <!-- todo aria errors -->
3
- <div :class="twMerge(`file-input
3
+ <div :class="twMerge(
4
+ `file-input
4
5
  justify-center
5
6
  border-2
6
7
  border-dashed
@@ -8,25 +9,26 @@
8
9
  focus-outline-within
9
10
  transition-[border-color,box-shadow]
10
11
  ease-out`,
11
- compact && `rounded-sm`,
12
- !compact && `flex w-full flex-col items-center gap-2 rounded-xl p-2 `,
13
- errors.length > 0 && errorFlashing && `border-danger-400`,
14
- ( $.wrapperAttrs as any ).class
15
- )"
16
- v-bind="{...$.wrapperAttrs, class:undefined}"
12
+ compact && `rounded-sm`,
13
+ !compact && `flex w-full flex-col items-center gap-2 rounded-xl p-2 `,
14
+ errors.length > 0 && errorFlashing && `border-danger-400`,
15
+ $.wrapperAttrs.class
16
+ )"
17
+ v-bind="{ ...$.wrapperAttrs, class: void 0 }"
17
18
  >
18
- <div :class="twMerge( `
19
+ <div :class="twMerge(
20
+ `
19
21
  file-input--wrapper
20
22
  relative justify-center`,
21
- compact && `flex gap-2`,
22
- !compact && `input-wrapper
23
+ compact && `flex gap-2`,
24
+ !compact && `input-wrapper
23
25
  flex flex-col items-center
24
26
  `
25
- )"
27
+ )"
26
28
  >
27
29
  <label
28
30
  :for="id ?? fallbackId"
29
- :class="twMerge( `
31
+ :class="twMerge(`
30
32
  file-input--label
31
33
  pointer-events-none
32
34
  flex
@@ -40,14 +42,7 @@
40
42
  </slot>
41
43
  <slot name="label">
42
44
  {{
43
- (compact
44
- ? multiple
45
- ? t("file-input.compact-choose-file-plural")
46
- : t("file-input.compact-choose-file")
47
- : multiple
48
- ? t("file-input.non-compact-choose-file-plural")
49
- : t("file-input.non-compact-choose-file")
50
- )
45
+ compact ? multiple ? t("file-input.compact-choose-file-plural") : t("file-input.compact-choose-file") : multiple ? t("file-input.non-compact-choose-file-plural") : t("file-input.non-compact-choose-file")
51
46
  }}
52
47
  </slot>
53
48
  <span
@@ -65,7 +60,8 @@
65
60
  </label>
66
61
  <input
67
62
  :id="id ?? fallbackId"
68
- :class="twMerge(`
63
+ :class="twMerge(
64
+ `
69
65
  file-input--input
70
66
  absolute
71
67
  inset-0
@@ -74,27 +70,28 @@
74
70
  text-[0]
75
71
  opacity-0
76
72
  `,
77
- ($.inputAttrs as any)?.class
78
- )"
73
+ $.inputAttrs?.class
74
+ )"
79
75
  type="file"
80
76
  :accept="formats.join(', ')"
81
77
  :multiple="multiple"
82
78
  ref="el"
83
- v-bind="{...$.inputAttrs, class:undefined}"
84
- @input="(inputFile as any)"
85
- @click="($event.target! as any).value = null"
79
+ v-bind="{ ...$.inputAttrs, class: void 0 }"
80
+ @input="inputFile"
81
+ @click="$event.target.value = null"
86
82
  >
87
83
  <!-- click event allows event to fire even if the user picks the same file -->
88
84
  </div>
89
85
  <div v-if="!compact && files.length > 0"
90
- :class="twMerge(`file-input--previews
86
+ :class="twMerge(
87
+ `file-input--previews
91
88
  flex items-stretch justify-center gap-2 flex-wrap
92
89
  `,
93
- multiple && `
90
+ multiple && `
94
91
  w-full
95
92
  `,
96
- ($.previewsAttrs as any)?.class
97
- )"
93
+ $.previewsAttrs?.class
94
+ )"
98
95
  >
99
96
  <div class="file-input--preview-spacer flex-1"/>
100
97
  <div class="file-input--preview-wrapper
@@ -163,136 +160,99 @@
163
160
  </div>
164
161
  </div>
165
162
  </template>
166
- <script setup lang="ts">
167
- import { computed, type HTMLAttributes, type InputHTMLAttributes,ref, shallowReactive, watch } from "vue"
168
-
169
- import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
170
- import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
171
- import { type FileInputError } from "../../types/index.js"
172
- import { twMerge } from "../../utils/twMerge.js"
173
- import Icon from "../Icon/Icon.vue"
174
- import LibButton from "../LibButton/LibButton.vue"
175
- import { getFallbackId,type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
176
-
177
- const t = useInjectedI18n()
178
- const el = ref<null | HTMLInputElement>(null)
179
- type Entry = { file: File, isImg: boolean }
180
-
181
- const files = shallowReactive<(Entry)[]>([])
182
- const errors = shallowReactive<(FileInputError)[]>([])
183
- const errorFlashing = ref(false)
184
163
 
164
+ <script setup>
165
+ import { computed, ref, shallowReactive, watch } from "vue";
166
+ import IFa6RegularFile from "~icons/fa6-regular/file";
167
+ import IFa6SolidArrowUpFromBracket from "~icons/fa6-solid/arrow-up-from-bracket";
168
+ import IFa6SolidXmark from "~icons/fa6-solid/xmark";
169
+ import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
170
+ import { useInjectedI18n } from "../../composables/useInjectedI18n.js";
171
+ import {} from "../../types/index.js";
172
+ import { twMerge } from "../../utils/twMerge.js";
173
+ import Icon from "../Icon/Icon.vue";
174
+ import LibButton from "../LibButton/LibButton.vue";
175
+ import { getFallbackId } from "../shared/props.js";
176
+ const t = useInjectedI18n();
177
+ const el = ref(null);
178
+ const files = shallowReactive([]);
179
+ const errors = shallowReactive([]);
180
+ const errorFlashing = ref(false);
185
181
  watch(files, () => {
186
- emits("input", files.map(entry => entry.file))
187
- })
182
+ emits("input", files.map((entry) => entry.file));
183
+ });
188
184
  watch(errors, () => {
189
- if (errors.length > 0) {
190
- errorFlashing.value = true
191
- setTimeout(() => {
192
- errorFlashing.value = false
193
- }, 500)
194
- emits("errors", errors)
195
- }
196
- })
197
-
185
+ if (errors.length > 0) {
186
+ errorFlashing.value = true;
187
+ setTimeout(() => {
188
+ errorFlashing.value = false;
189
+ }, 500);
190
+ emits("errors", errors);
191
+ }
192
+ });
198
193
  defineOptions({
199
- name: "lib-file-input",
200
- inheritAttrs: false,
201
- })
202
- const $ = useDivideAttrs(["wrapper", "input", "previews"] as const)
203
-
204
- const emits = defineEmits<{
205
- (e: "input", val: File[]): void
206
- (e: "errors", val: FileInputError[]): void
207
- }>()
208
-
209
- const fallbackId = getFallbackId()
210
- const props = withDefaults(defineProps<Props>(), {
211
- multiple: false,
212
- formats: () => ["image/*", ".jpeg", ".jpg", ".png"],
213
- compact: false,
214
- })
215
-
216
- const mimeTypes = computed(() => props.formats?.filter(_ => !_.startsWith(".")) ?? [])
217
- const extensions = computed(() => props.formats?.filter(_ => _.startsWith(".")) ?? [])
218
-
219
- const getSrc = (file: File) => {
220
- const src = URL.createObjectURL(file)
221
- return src
222
- }
223
-
224
- const removeFile = (entry: Entry) => {
225
- const index = files.indexOf(entry)
226
- files.splice(index, 1)
227
- }
228
- const extensionsList = computed(() => extensions.value.join(", "))
229
- const inputFile = async (e: InputEvent): Promise<void | boolean> => {
230
- e.preventDefault()
231
- if (el.value!.files) {
232
- const errs = []
233
- for (const file of el.value!.files) {
234
- const isImg = file.type.startsWith("image")
235
-
236
- const byPassValidation = props.formats.length === 0
237
- const isValidMimeType = mimeTypes.value.find(_ => _.endsWith("/*") ? file.type.startsWith(_.slice(0, -2)) : _ === file.type) !== undefined
238
- const isValidExtension = extensions.value.find(_ => file.name.endsWith(_)) !== undefined
239
- if (!byPassValidation && (!isValidMimeType || !isValidExtension)) {
240
- const extension = file.name.match(/.*(\..*)/)?.[1] ?? "Unknown"
241
- const type = file.type === "" ? "" : ` (${file.type})`
242
- const message = `File type ${extension}${type} is not allowed. Allowed file types are: ${extensionsList.value}.`
243
- const err = new Error(message) as FileInputError
244
- err.file = file
245
- err.isValidExtension = isValidExtension
246
- err.isValidMimeType = isValidMimeType
247
- errs.push(err)
248
- continue
249
- }
250
- if (errs.length > 0) continue
251
- if (!files.find(_ => _.file === file)) {
252
- if ((props.multiple || files.length < 1)
253
- ) {
254
- files.push({ file, isImg })
255
- } else {
256
- files.splice(0, files.length, { file, isImg })
257
- }
258
- }
259
- }
260
- if (errs.length > 0) {
261
- errors.splice(0, errors.length, ...errs)
262
- return false
263
- } else if (errors.length > 0) {
264
- errors.splice(0, errors.length)
265
- }
266
- }
267
- }
268
-
194
+ name: "lib-file-input",
195
+ inheritAttrs: false
196
+ });
197
+ const $ = useDivideAttrs(["wrapper", "input", "previews"]);
198
+ const emits = defineEmits(["input", "errors"]);
199
+ const fallbackId = getFallbackId();
200
+ const props = defineProps({
201
+ id: { type: String, required: false },
202
+ multiple: { type: Boolean, required: false, default: false },
203
+ formats: { type: Array, required: false, default: () => ["image/*", ".jpeg", ".jpg", ".png"] },
204
+ compact: { type: Boolean, required: false, default: false }
205
+ });
206
+ const mimeTypes = computed(() => props.formats?.filter((_) => !_.startsWith(".")) ?? []);
207
+ const extensions = computed(() => props.formats?.filter((_) => _.startsWith(".")) ?? []);
208
+ const getSrc = (file) => {
209
+ const src = URL.createObjectURL(file);
210
+ return src;
211
+ };
212
+ const removeFile = (entry) => {
213
+ const index = files.indexOf(entry);
214
+ files.splice(index, 1);
215
+ };
216
+ const extensionsList = computed(() => extensions.value.join(", "));
217
+ const inputFile = async (e) => {
218
+ e.preventDefault();
219
+ if (el.value.files) {
220
+ const errs = [];
221
+ for (const file of el.value.files) {
222
+ const isImg = file.type.startsWith("image");
223
+ const byPassValidation = props.formats.length === 0;
224
+ const isValidMimeType = mimeTypes.value.find((_) => _.endsWith("/*") ? file.type.startsWith(_.slice(0, -2)) : _ === file.type) !== void 0;
225
+ const isValidExtension = extensions.value.find((_) => file.name.endsWith(_)) !== void 0;
226
+ if (!byPassValidation && (!isValidMimeType || !isValidExtension)) {
227
+ const extension = file.name.match(/.*(\..*)/)?.[1] ?? "Unknown";
228
+ const type = file.type === "" ? "" : ` (${file.type})`;
229
+ const message = `File type ${extension}${type} is not allowed. Allowed file types are: ${extensionsList.value}.`;
230
+ const err = new Error(message);
231
+ err.file = file;
232
+ err.isValidExtension = isValidExtension;
233
+ err.isValidMimeType = isValidMimeType;
234
+ errs.push(err);
235
+ continue;
236
+ }
237
+ if (errs.length > 0) continue;
238
+ if (!files.find((_) => _.file === file)) {
239
+ if (props.multiple || files.length < 1) {
240
+ files.push({ file, isImg });
241
+ } else {
242
+ files.splice(0, files.length, { file, isImg });
243
+ }
244
+ }
245
+ }
246
+ if (errs.length > 0) {
247
+ errors.splice(0, errors.length, ...errs);
248
+ return false;
249
+ } else if (errors.length > 0) {
250
+ errors.splice(0, errors.length);
251
+ }
252
+ }
253
+ };
269
254
  </script>
270
- <script lang="ts">
271
- export default { name: "lib-file-input" }
272
-
273
- type WrapperTypes =
274
- & WrapperProps<"input", InputHTMLAttributes >
275
- & WrapperProps<"wrapper", HTMLAttributes >
276
- & WrapperProps<"previews",HTMLAttributes >
277
-
278
- type RealProps =
279
- & LinkableByIdProps
280
- & {
281
- multiple?: boolean
282
- /**
283
- * A list of extensions or mime types to add to the input's accept. Basic validations are done so that files match an extension and mimeType, but note that a file could still be lying, all files should be validated server side.
284
- *
285
- * Pass an empty array to allow any filetype.
286
- */
287
- formats?: string[]
288
- compact?: boolean
289
- }
290
255
 
291
- interface Props
292
- extends
293
- /** @vue-ignore */
294
- Partial<Omit<InputHTMLAttributes,"class" | "multiple" | "formats" | "compact"> & TailwindClassProp>,
295
- /** @vue-ignore */
296
- Partial<WrapperTypes>,
297
- RealProps { }
256
+ <script>
257
+ export default { name: "lib-file-input" };
298
258
  </script>
@@ -0,0 +1,43 @@
1
+ import { type HTMLAttributes, type InputHTMLAttributes } from "vue";
2
+ import { type FileInputError } from "../../types/index.js.js";
3
+ import { type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js.js";
4
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
5
+ input: (val: File[]) => any;
6
+ errors: (val: FileInputError[]) => any;
7
+ }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
8
+ onInput?: ((val: File[]) => any) | undefined;
9
+ onErrors?: ((val: FileInputError[]) => any) | undefined;
10
+ }>, {
11
+ multiple: boolean;
12
+ formats: string[];
13
+ compact: boolean;
14
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
15
+ icon?: (props: {}) => any;
16
+ } & {
17
+ label?: (props: {}) => any;
18
+ } & {
19
+ formats?: (props: {}) => any;
20
+ }>;
21
+ export default _default;
22
+ type WrapperTypes = WrapperProps<"input", InputHTMLAttributes> & WrapperProps<"wrapper", HTMLAttributes> & WrapperProps<"previews", HTMLAttributes>;
23
+ type RealProps = LinkableByIdProps & {
24
+ multiple?: boolean;
25
+ /**
26
+ * A list of extensions or mime types to add to the input's accept. Basic validations are done so that files match an extension and mimeType, but note that a file could still be lying, all files should be validated server side.
27
+ *
28
+ * Pass an empty array to allow any filetype.
29
+ */
30
+ formats?: string[];
31
+ compact?: boolean;
32
+ };
33
+ interface Props extends
34
+ /** @vue-ignore */
35
+ Partial<Omit<InputHTMLAttributes, "class" | "multiple" | "formats" | "compact"> & TailwindClassProp>,
36
+ /** @vue-ignore */
37
+ Partial<WrapperTypes>, RealProps {
38
+ }
39
+ type __VLS_WithSlots<T, S> = T & {
40
+ new (): {
41
+ $slots: S;
42
+ };
43
+ };