@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.
- package/README.md +3 -6
- package/dist/module.json +3 -3
- package/dist/module.mjs +15 -12
- package/dist/runtime/build/generateTheme.js +1 -1
- package/dist/runtime/components/Aria/Aria.vue +5 -9
- package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
- package/dist/runtime/components/Icon/Icon.vue +10 -30
- package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
- package/dist/runtime/components/LibButton/LibButton.vue +51 -72
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +43 -74
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +63 -107
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +272 -352
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +1 -1
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +1 -1
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +35 -69
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +17 -38
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +58 -82
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +55 -67
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +7 -8
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +43 -70
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +18 -31
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +116 -156
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +211 -241
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +25 -46
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +26 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +43 -58
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +34 -48
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +63 -83
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +67 -111
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +17 -23
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +314 -351
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +65 -91
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +127 -177
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
- package/dist/runtime/components/LibRoot/LibRoot.vue +75 -101
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +42 -77
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +118 -156
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
- package/dist/runtime/components/LibTable/LibTable.vue +63 -99
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
- package/dist/runtime/components/Template/NAME.vue +15 -36
- package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
- package/dist/runtime/components/TestControls/TestControls.vue +6 -9
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
- package/dist/runtime/components/shared/props.d.ts +0 -29
- package/dist/runtime/components/shared/props.js +0 -12
- package/dist/runtime/composables/useAccesibilityOutline.js +1 -1
- package/dist/runtime/composables/useDivideAttrs.js +1 -1
- package/dist/runtime/composables/useSuggestions.js +4 -4
- package/dist/runtime/directives/vDetectFlex.js +4 -4
- package/dist/runtime/directives/vExtractRootEl.d.ts +1 -1
- package/dist/runtime/directives/vResizableCols.d.ts +1 -1
- package/dist/runtime/directives/vResizableCols.js +4 -4
- package/dist/runtime/helpers/NotificationHandler.js +6 -6
- package/dist/runtime/helpers/base64ToImg.js +2 -2
- package/dist/runtime/nuxt/plugins/vue-plugin.js +1 -1
- package/dist/runtime/tailwind/themeConvertionOpts.d.ts +1 -1
- package/dist/runtime/theme.d.ts +1 -1
- package/dist/runtime/theme.js +1 -1
- package/dist/runtime/utils/notifyIfError.js +1 -1
- package/dist/runtime/vue/registerComponents.js +1 -1
- package/dist/types.d.mts +2 -6
- package/package.json +68 -90
- package/src/module.ts +19 -12
- package/src/runtime/build/generateTheme.ts +1 -1
- package/src/runtime/components/LibButton/LibButton.stories.ts +1 -1
- package/src/runtime/components/LibButton/LibButton.vue +3 -3
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +3 -7
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +6 -4
- package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +1 -1
- package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +1 -1
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +8 -15
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +6 -0
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +6 -0
- package/src/runtime/components/LibDebug/LibDebug.stories.ts +1 -1
- package/src/runtime/components/LibDebug/LibDebug.vue +2 -0
- package/src/runtime/components/LibFileInput/LibFileInput.vue +4 -0
- package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +7 -5
- package/src/runtime/components/LibLabel/LibLabel.vue +2 -3
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +5 -3
- package/src/runtime/components/LibNotifications/LibNotification.vue +3 -0
- package/src/runtime/components/LibNotifications/LibNotifications.vue +1 -1
- package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
- package/src/runtime/components/LibPopup/LibPopup.vue +2 -2
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +2 -2
- package/src/runtime/components/LibRecorder/LibRecorder.vue +3 -3
- package/src/runtime/components/LibRoot/LibRoot.vue +3 -2
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +2 -2
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +2 -2
- package/src/runtime/components/LibTable/LibTable.vue +1 -1
- package/src/runtime/components/Template/NAME.vue +2 -2
- package/src/runtime/components/shared/props.ts +8 -12
- package/src/runtime/composables/useAccesibilityOutline.ts +1 -1
- package/src/runtime/composables/useDivideAttrs.ts +1 -1
- package/src/runtime/composables/useSuggestions.ts +4 -4
- package/src/runtime/directives/vDetectFlex.ts +4 -4
- package/src/runtime/directives/vExtractRootEl.ts +1 -1
- package/src/runtime/directives/vResizableCols.ts +5 -5
- package/src/runtime/helpers/NotificationHandler.ts +6 -6
- package/src/runtime/nuxt/plugins/vue-plugin.ts +1 -1
- package/src/runtime/tailwind/themeConvertionOpts.ts +1 -1
- package/src/runtime/theme.ts +2 -2
- package/src/runtime/utils/notifyIfError.ts +1 -1
- package/src/runtime/vue/registerComponents.ts +1 -1
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -36
- package/dist/runtime/components/Focus.stories.d.ts +0 -11
- package/dist/runtime/components/Focus.stories.js +0 -53
- package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
- package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -9
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -68
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
- package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
- package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +0 -33
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +0 -384
- package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
- package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -61
- package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
- package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
- package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
- package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
- package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
- package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
- package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
- package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
- package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
- package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
- package/dist/runtime/components/Reset.stories.d.ts +0 -5
- package/dist/runtime/components/Reset.stories.js +0 -19
- package/dist/runtime/components/Scrolling.stories.d.ts +0 -6
- package/dist/runtime/components/Scrolling.stories.js +0 -44
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
- package/dist/types.d.ts +0 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<!-- todo aria errors -->
|
|
3
|
-
<div :class="twMerge(
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
v-bind="{...$.wrapperAttrs, class:
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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:
|
|
84
|
-
@input="
|
|
85
|
-
@click="
|
|
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(
|
|
86
|
+
:class="twMerge(
|
|
87
|
+
`file-input--previews
|
|
91
88
|
flex items-stretch justify-center gap-2 flex-wrap
|
|
92
89
|
`,
|
|
93
|
-
|
|
90
|
+
multiple && `
|
|
94
91
|
w-full
|
|
95
92
|
`,
|
|
96
|
-
|
|
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
|
-
|
|
187
|
-
})
|
|
182
|
+
emits("input", files.map((entry) => entry.file));
|
|
183
|
+
});
|
|
188
184
|
watch(errors, () => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
})
|
|
202
|
-
const $ = useDivideAttrs(["wrapper", "input", "previews"]
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
292
|
-
|
|
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
|
+
};
|