@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.
- package/README.md +18 -28
- package/dist/module.d.mts +3 -1
- package/dist/module.json +3 -3
- package/dist/module.mjs +21 -12
- package/dist/runtime/assets/base.css +1 -1
- package/dist/runtime/assets/locales/en.json +2 -2
- package/dist/runtime/assets/tailwind.css +1 -1
- package/dist/runtime/assets/utils.css +1 -0
- package/dist/runtime/build/WitchcraftUiResolver.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 +12 -28
- package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
- package/dist/runtime/components/LibButton/LibButton.vue +93 -117
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +53 -76
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +131 -101
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +326 -296
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +18 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +17 -0
- package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.js +8 -0
- package/dist/runtime/components/LibColorPicker/utils/truncate.d.ts +1 -0
- package/dist/runtime/components/LibColorPicker/utils/truncate.js +5 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +42 -64
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +20 -54
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +205 -173
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +215 -164
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +9 -10
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +47 -65
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +19 -34
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +155 -173
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +352 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +30 -46
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +27 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +50 -66
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -56
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +71 -83
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +86 -131
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +23 -26
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +326 -400
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +73 -93
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +134 -179
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
- package/dist/runtime/components/LibRoot/LibRoot.vue +75 -89
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +51 -82
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +147 -164
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
- package/dist/runtime/components/LibTable/LibTable.vue +69 -106
- 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 +7 -10
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
- package/dist/runtime/components/index.d.ts +12 -11
- package/dist/runtime/components/index.js +12 -11
- package/dist/runtime/components/shared/props.d.ts +81 -16
- package/dist/runtime/components/shared/storyHelpers/playInput.js +5 -5
- package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +15 -11
- package/dist/runtime/composables/index.d.ts +5 -0
- package/dist/runtime/composables/index.js +5 -0
- package/dist/runtime/composables/useDivideAttrs.js +1 -0
- package/dist/runtime/composables/useDragWithThreshold.d.ts +71 -0
- package/dist/runtime/composables/useDragWithThreshold.js +40 -0
- package/dist/runtime/composables/usePreHydrationValue.d.ts +12 -0
- package/dist/runtime/composables/usePreHydrationValue.js +15 -0
- package/dist/runtime/composables/useSetupI18n.d.ts +2 -0
- package/dist/runtime/composables/useSetupI18n.js +5 -1
- package/dist/runtime/composables/useSuggestions.d.ts +7 -5
- package/dist/runtime/composables/useSuggestions.js +94 -57
- package/dist/runtime/directives/vResizableCols.js +92 -84
- package/dist/runtime/helpers/NotificationHandler.d.ts +5 -0
- package/dist/runtime/helpers/index.d.ts +3 -1
- package/dist/runtime/helpers/index.js +3 -1
- package/dist/runtime/types/index.d.ts +6 -0
- package/dist/runtime/utils/notifyIfError.d.ts +14 -0
- package/dist/runtime/utils/notifyIfError.js +29 -0
- package/dist/types.d.mts +2 -6
- package/package.json +27 -29
- package/src/module.ts +31 -12
- package/src/runtime/assets/base.css +10 -1
- package/src/runtime/assets/locales/en.json +2 -2
- package/src/runtime/assets/tailwind.css +1 -1
- package/src/runtime/assets/{style.css → utils.css} +86 -4
- package/src/runtime/build/WitchcraftUiResolver.ts +1 -1
- package/src/runtime/components/Focus.stories.ts +3 -2
- package/src/runtime/components/Icon/Icon.vue +10 -6
- package/src/runtime/components/LibButton/LibButton.vue +41 -47
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +7 -4
- package/src/runtime/components/LibColorInput/LibColorInput.vue +111 -37
- package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +25 -4
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
- package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +24 -0
- package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +23 -0
- package/src/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.ts +13 -0
- package/src/runtime/components/LibColorPicker/utils/truncate.ts +6 -0
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +1 -1
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
- package/src/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
- package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
- package/src/runtime/components/LibDebug/LibDebug.vue +15 -5
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
- package/src/runtime/components/LibFileInput/LibFileInput.vue +54 -29
- package/src/runtime/components/{LibInput/LibInput.stories.ts → LibInputDeprecated/LibInputDeprecated.stories.ts} +64 -19
- package/{dist/runtime/components/LibInput/LibInput.vue → src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -34
- package/src/runtime/components/LibLabel/LibLabel.vue +2 -2
- package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +5 -4
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +11 -13
- package/src/runtime/components/LibNotifications/LibNotification.vue +19 -11
- package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +2 -2
- package/src/runtime/components/LibNotifications/LibNotifications.vue +20 -12
- package/src/runtime/components/LibPagination/LibPagination.stories.ts +2 -2
- package/src/runtime/components/LibPagination/LibPagination.vue +19 -20
- package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
- package/src/runtime/components/LibPopup/LibPopup.stories.ts +2 -2
- package/src/runtime/components/LibPopup/LibPopup.vue +30 -67
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +3 -2
- package/src/runtime/components/LibRecorder/LibRecorder.vue +2 -3
- package/src/runtime/components/LibRoot/LibRoot.vue +14 -1
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +1 -1
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -8
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +42 -26
- package/src/runtime/components/LibTable/LibTable.vue +8 -9
- package/src/runtime/components/Scrolling.stories.ts +58 -0
- package/src/runtime/components/Template/NAME.vue +1 -1
- package/src/runtime/components/TestControls/TestControls.vue +1 -1
- package/src/runtime/components/index.ts +12 -12
- package/src/runtime/components/shared/props.ts +82 -19
- package/src/runtime/components/shared/storyHelpers/playInput.ts +6 -5
- package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +25 -11
- package/src/runtime/composables/index.ts +5 -0
- package/src/runtime/composables/useDarkMode.ts +2 -2
- package/src/runtime/composables/useDivideAttrs.ts +1 -0
- package/src/runtime/composables/useDragWithThreshold.ts +108 -0
- package/src/runtime/composables/usePreHydrationValue.ts +30 -0
- package/src/runtime/composables/useSetupI18n.ts +8 -2
- package/src/runtime/composables/useSuggestions.ts +92 -45
- package/src/runtime/directives/vResizableCols.ts +82 -74
- package/src/runtime/helpers/NotificationHandler.ts +5 -0
- package/src/runtime/helpers/index.ts +3 -1
- package/src/runtime/types/index.ts +5 -0
- package/src/runtime/utils/notifyIfError.ts +45 -0
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -34
- package/dist/runtime/assets/style.css +0 -1
- 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 -7
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -51
- 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/LibInput/LibInput.stories.d.ts +0 -33
- package/dist/runtime/components/LibInput/LibInput.stories.js +0 -339
- 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 -60
- 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/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
- package/dist/runtime/helpers/addValue.d.ts +0 -1
- package/dist/runtime/helpers/addValue.js +0 -8
- package/dist/types.d.ts +0 -7
- package/src/runtime/components/LibInput/LibInput.vue +0 -372
- package/src/runtime/helpers/addValue.ts +0 -10
- /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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
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 }"
|
|
18
18
|
>
|
|
19
19
|
<div :class="twMerge(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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:
|
|
72
|
-
@input="
|
|
73
|
-
@click="
|
|
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(
|
|
86
|
+
:class="twMerge(
|
|
87
|
+
`file-input--previews
|
|
79
88
|
flex items-stretch justify-center gap-2 flex-wrap
|
|
80
89
|
`,
|
|
81
|
-
|
|
90
|
+
multiple && `
|
|
82
91
|
w-full
|
|
83
92
|
`,
|
|
84
|
-
|
|
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="
|
|
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
|
-
|
|
161
|
-
})
|
|
179
|
+
emits("input", files.map((entry) => entry.file));
|
|
180
|
+
});
|
|
162
181
|
watch(errors, () => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
})
|
|
176
|
-
const $ = useDivideAttrs(["wrapper", "input", "previews"]
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
267
|
-
|
|
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
|
+
};
|