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