@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
@@ -0,0 +1,41 @@
1
+ import { type Theme } from "metamorphosis";
2
+ import { NotificationHandler } from "../../helpers/NotificationHandler.js.js";
3
+ type __VLS_Props = {
4
+ theme?: Theme;
5
+ outline?: boolean;
6
+ forceOutline?: boolean;
7
+ testWrapperMode?: boolean;
8
+ id?: string;
9
+ /** You can set a ref to the root element by passing :getRef="_ => el = _" */
10
+ getRef?: (el: HTMLElement | null) => void;
11
+ /** True by default, should be passed import.meta.client if using nuxt, or false when running server side. */
12
+ isClientSide?: boolean;
13
+ useBuiltinTranslations?: boolean;
14
+ useNotifications?: boolean;
15
+ notificationHandler?: NotificationHandler;
16
+ };
17
+ declare var __VLS_9: {};
18
+ type __VLS_Slots = {} & {
19
+ default?: (props: typeof __VLS_9) => any;
20
+ };
21
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {
22
+ darkMode: import("../../composables/useDarkMode.js.js").DarkModeState & import("../../composables/useDarkMode.js.js").DarkModeCommands;
23
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
24
+ theme: Theme;
25
+ id: string;
26
+ useBuiltinTranslations: boolean;
27
+ isClientSide: boolean;
28
+ outline: boolean;
29
+ forceOutline: boolean;
30
+ testWrapperMode: boolean;
31
+ getRef: (el: HTMLElement | null) => void;
32
+ useNotifications: boolean;
33
+ notificationHandler: NotificationHandler;
34
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
35
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
36
+ export default _default;
37
+ type __VLS_WithSlots<T, S> = T & {
38
+ new (): {
39
+ $slots: S;
40
+ };
41
+ };
@@ -1,8 +1,9 @@
1
1
  <template>
2
2
  <input
3
3
  :id="id ?? fallbackId"
4
- :class="twMerge(`
5
- input
4
+ :class="twMerge(
5
+ `
6
+ simple-input
6
7
  flex-1
7
8
  grow-[999999]
8
9
  rounded-sm
@@ -27,35 +28,35 @@
27
28
  dark:disabled:bg-neutral-950
28
29
  dark:disabled:text-neutral-500
29
30
  `,
30
- type === `text` && `
31
+ type === `text` && `
31
32
  min-w-[10ch]
32
33
  w-full
33
34
  `,
34
- type === `number` && `
35
+ type === `number` && `
35
36
  w-12
36
37
  placeholder:text-transparent
37
38
  appearance-none
38
39
  pr-0
39
40
  `,
40
- border && `
41
+ border && `
41
42
  border
42
43
  border-neutral-500
43
44
  focus:border-accent-500
44
45
  disabled:border-neutral-400
45
46
  dark:disabled:border-neutral-600
46
47
  `,
47
- !valid && `
48
+ !valid && `
48
49
  placeholder:text-danger-700
49
50
  border-danger-700
50
51
  focus:border-danger-700
51
- outlined:!ring-danger-700
52
+ outlined:!outline-danger-700
52
53
  text-danger-800
53
54
  dark:text-danger-400
54
55
  dark:placeholder:text-danger-700
55
56
  dark:border-danger-600
56
57
  `,
57
- ($attrs as any)?.class
58
- )"
58
+ $attrs?.class
59
+ )"
59
60
  :data-border="border"
60
61
  :data-invalid="!valid"
61
62
  :type="type"
@@ -63,86 +64,54 @@
63
64
  :disabled="disabled"
64
65
  :readonly="readonly"
65
66
  v-model="modelValue"
66
- v-bind="{...$attrs, class:undefined, ...ariaLabel}"
67
+ v-bind="{ ...$attrs, class: void 0, ...ariaLabel }"
67
68
  @keydown="handleKeydown"
68
- @input="emit('input', $event as InputEvent)"
69
+ @input="emit('input', $event)"
69
70
  >
70
71
  </template>
71
72
 
72
-
73
- <script lang="ts" setup generic="T">
74
- import { keys } from "@alanscodelog/utils/keys.js"
75
- import { pick } from "@alanscodelog/utils/pick.js"
76
- import type { MakeRequired } from "@alanscodelog/utils/types"
77
- import { castType } from "@alanscodelog/utils/utils"
78
- import { getCurrentInstance, type InputHTMLAttributes, type InputTypeHTMLAttribute,toRef,useAttrs } from "vue"
79
-
80
- import { useAriaLabel } from "../../composables/useAriaLabel.js"
81
- import { hasModifiers } from "../../helpers/hasModifiers.js"
82
- import { twMerge } from "../../utils/twMerge.js"
83
- import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
84
-
85
-
73
+ <script setup>
74
+ import { useAttrs } from "vue";
75
+ import { useAriaLabel } from "../../composables/useAriaLabel.js";
76
+ import { usePreHydrationValue } from "../../composables/usePreHydrationValue.js";
77
+ import { hasModifiers } from "../../helpers/hasModifiers.js";
78
+ import { twMerge } from "../../utils/twMerge.js";
79
+ import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
86
80
  defineOptions({
87
- name: "lib-simple-input",
88
- inheritAttrs: false,
89
- })
90
-
91
- const fallbackId = getFallbackId()
92
-
93
- // eslint-disable-next-line no-use-before-define
94
- const props = withDefaults(defineProps<Props>(), {
95
- id: "",
96
- placeholder: "",
97
- valid: true,
98
- label: "",
99
- type: undefined,
100
- ...baseInteractivePropsDefaults
101
- })
102
-
103
- const modelValue = defineModel<T>({ required: true })
104
-
105
- const emit = defineEmits<{
106
- /* User presses enter.*/
107
- (e: "submit", val: T): void
108
- (e: "input", val: InputEvent): void
109
- }>()
110
- const $attrs = useAttrs()
111
- const ariaLabel = useAriaLabel(props, fallbackId)
112
-
113
- function handleKeydown(e: KeyboardEvent) {
114
- if (e.key === "Enter" && !hasModifiers(e)) {
115
- emit("submit", modelValue.value)
116
- }
81
+ name: "lib-simple-input",
82
+ inheritAttrs: false
83
+ });
84
+ const fallbackId = getFallbackId();
85
+ const props = defineProps(/* @__PURE__ */ _mergeDefaults({
86
+ id: { type: String, required: false },
87
+ label: { type: String, required: false },
88
+ disabled: { type: Boolean, required: false },
89
+ readonly: { type: Boolean, required: false },
90
+ border: { type: Boolean, required: false },
91
+ unstyle: { type: Boolean, required: false },
92
+ placeholder: { type: null, required: false },
93
+ type: { type: null, required: false },
94
+ valid: { type: Boolean, required: false }
95
+ }, {
96
+ id: "",
97
+ placeholder: "",
98
+ valid: true,
99
+ label: "",
100
+ type: void 0,
101
+ ...baseInteractivePropsDefaults
102
+ }));
103
+ const modelValue = defineModel({ type: null, ...{ required: true } });
104
+ const emit = defineEmits(["submit", "input"]);
105
+ const $attrs = useAttrs();
106
+ const ariaLabel = useAriaLabel(props, fallbackId);
107
+ function handleKeydown(e) {
108
+ if (e.key === "Enter" && !hasModifiers(e)) {
109
+ emit("submit", modelValue.value);
110
+ }
117
111
  }
118
-
112
+ usePreHydrationValue(props.id ?? fallbackId, modelValue);
119
113
  </script>
120
114
 
121
- <script lang="ts">
122
-
123
- type RealProps =
124
- & LinkableByIdProps
125
- & LabelProps
126
- & BaseInteractiveProps
127
- & {
128
- placeholder?: InputHTMLAttributes["placeholder"]
129
- disabled?: InputHTMLAttributes["disabled"]
130
- id?: InputHTMLAttributes["id"]
131
- type?: InputHTMLAttributes["type"]
132
- valid?: boolean
133
- }
115
+ <script>
134
116
 
135
- interface Props
136
- extends
137
- /** @vue-ignore */
138
- Partial<Omit<
139
- InputHTMLAttributes,
140
- | "class"
141
- | "readonly"
142
- | "disabled"
143
- | "onSubmit"
144
- | "onInput"
145
- > & TailwindClassProp>,
146
- RealProps
147
- {}
148
117
  </script>
@@ -0,0 +1,35 @@
1
+ import { type InputHTMLAttributes } from "vue";
2
+ import { type BaseInteractiveProps, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js.js";
3
+ type RealProps = LinkableByIdProps & LabelProps & BaseInteractiveProps & {
4
+ placeholder?: InputHTMLAttributes["placeholder"];
5
+ disabled?: InputHTMLAttributes["disabled"];
6
+ id?: InputHTMLAttributes["id"];
7
+ type?: InputHTMLAttributes["type"];
8
+ valid?: boolean;
9
+ };
10
+ interface Props extends
11
+ /** @vue-ignore */
12
+ Partial<Omit<InputHTMLAttributes, "class" | "readonly" | "disabled" | "onSubmit" | "onInput"> & TailwindClassProp>, RealProps {
13
+ }
14
+ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
15
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
16
+ readonly onInput?: ((val: InputEvent) => any) | undefined;
17
+ readonly onSubmit?: ((val: T) => any) | undefined;
18
+ readonly "onUpdate:modelValue"?: ((value: T) => any) | undefined;
19
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onInput" | "onSubmit" | "onUpdate:modelValue"> & (Props & {
20
+ modelValue: T;
21
+ }) & Partial<{}>> & import("vue").PublicProps;
22
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
23
+ attrs: any;
24
+ slots: {};
25
+ emit: {
26
+ (e: "submit", val: T): void;
27
+ (e: "input", val: InputEvent): void;
28
+ } & ((evt: "update:modelValue", value: T) => void);
29
+ }>) => import("vue").VNode & {
30
+ __ctx?: Awaited<typeof __VLS_setup>;
31
+ };
32
+ export default _default;
33
+ type __VLS_PrettifyLocal<T> = {
34
+ [K in keyof T as K]: T[K];
35
+ } & {};
@@ -1,198 +1,181 @@
1
1
  <template>
2
2
  <div
3
- v-if="suggestions.isOpen"
3
+ v-if="$open"
4
4
  :id="`suggestions-${id ?? fallbackId}`"
5
- :class="twMerge(`
5
+ :class="twMerge(
6
+ `
6
7
  suggestions
7
8
  bg-bg
8
9
  dark:bg-fg
10
+ dark:text-bg
9
11
  `,
10
- ($.attrs as any)?.class
11
- )"
12
- :data-open="suggestions.isOpen"
12
+ $.attrs?.class
13
+ )"
14
+ :data-open="$open"
13
15
  role="listbox"
14
16
  ref="el"
15
- v-bind="{...$.attrs, class:undefined}"
17
+ v-bind="{ ...$.attrs, class: void 0 }"
16
18
  >
17
19
  <!-- Click event is just in case, it should not really be triggered. We can do click selections via the blur handler. -->
18
20
  <div :id="`suggestion-${id ?? fallbackId}-${index}`"
19
21
  role="option"
20
- :class="twMerge(`
21
- px-1
22
- user-select-none
23
- cursor-pointer
24
- px-2
25
- `,
26
- index=== suggestions.active && `bg-accent-200 dark:bg-accent-800`,
27
- ($.itemAttrs as any)?.class
28
- )"
29
- v-bind="{...$.itemAttrs, class:undefined}"
22
+ :class="twMerge(
23
+ `
24
+ suggestions--item
25
+ user-select-none
26
+ cursor-pointer
27
+ px-2
28
+ `,
29
+ index === suggestions.active && `
30
+ bg-accent-200
31
+ dark:bg-accent-800/70
32
+ `,
33
+ $.itemAttrs?.class
34
+ )"
35
+ v-bind="{ ...$.itemAttrs, class: void 0 }"
30
36
  :aria-selected="index === suggestions.active ? true : false"
31
37
  :aria-label="suggestions.getLabel(item)"
32
38
  v-for="(item, index) in suggestions.filtered"
33
39
  :key="item"
34
40
  @mouseover="suggestions.active = index"
35
41
  @mousedown.prevent
36
- @mouseup="suggestions.enterSuggestion(index)"
42
+ @mouseup="suggestions.enterIndex(index, !Array.isArray($modelValue))"
37
43
  >
38
- <slot name="item" :item="item" :index="index">
39
- {{ item }}
44
+ <slot name="item"
45
+ :item="item"
46
+ :index="index"
47
+ :is-selected="Array.isArray($modelValue) ? $modelValue.includes(item) : $modelValue === item"
48
+ >
49
+ <div class="flex gap-2 nowrap">
50
+ <lib-checkbox
51
+ v-if="Array.isArray($modelValue) && showSelectedValues"
52
+ :model-value="$modelValue.includes(item)"
53
+ @mousedown.prevent
54
+ />
55
+ <div> {{ item }} </div>
56
+ </div>
40
57
  </slot>
41
58
  </div>
42
59
  </div>
43
60
  </template>
44
61
 
45
-
46
- <script setup lang="ts" generic="TSuggestion extends string | object">
47
-
48
- import { type HTMLAttributes,reactive, ref } from "vue"
49
-
50
- import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
51
- import { useSuggestions } from "../../composables/useSuggestions.js"
52
- import { hasModifiers } from "../../helpers/hasModifiers.js"
53
- import { twMerge } from "../../utils/twMerge.js"
54
- import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type MultiValueProps, type SuggestionsEmits, type SuggestionsProps, type WrapperProps } from "../shared/props.js"
55
-
62
+ <script setup>
63
+ import { reactive, ref } from "vue";
64
+ import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
65
+ import { useSuggestions } from "../../composables/useSuggestions.js";
66
+ import { hasModifiers } from "../../helpers/hasModifiers.js";
67
+ import { twMerge } from "../../utils/twMerge.js";
68
+ import LibCheckbox from "../LibCheckbox/LibCheckbox.vue";
69
+ import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
56
70
  defineOptions({
57
- name: "lib-suggestions",
58
- inheritAttrs: false,
59
- })
60
-
61
- const $ = useDivideAttrs(["item"] as const)
62
-
63
- const emits = defineEmits<SuggestionsEmits>()
64
-
65
- const fallbackId = getFallbackId()
66
- // eslint-disable-next-line no-use-before-define
67
- const props = withDefaults(defineProps<Props & SuggestionsProps<TSuggestion>>(), {
68
- isValid: true,
69
- canOpen: true,
70
- values: undefined,
71
- filterKeydown: undefined,
72
- ...baseInteractivePropsDefaults
73
- })
74
-
75
- /**
76
- * The final valid value. This is *not* the value you want to share with the input. If `restrictToSuggestions` is true this will not update on any invalid values that `inputValue` might be set to.
77
- *
78
- * If suggestions are objects, this will be the string returned by the `suggestionLabel` prop.
79
- */
80
- const $modelValue = defineModel<string>("modelValue", { required: true })
81
- /**
82
- * If the element is bound to an input, this is the value that the input should be sharing.
83
- *
84
- * It allows the component to read even invalid output, and also to reset that invalid output when either modelValue is set to a new value, or when the component is closed via cancel.
85
- */
86
- const $inputValue = defineModel<string >("inputValue", { default: "" })
87
-
88
-
71
+ name: "lib-suggestions",
72
+ inheritAttrs: false
73
+ });
74
+ const $ = useDivideAttrs(["item"]);
75
+ const emits = defineEmits(["submit", "update:isOpen", "update:activeSuggestion"]);
76
+ const fallbackId = getFallbackId();
77
+ const props = defineProps(/* @__PURE__ */ _mergeDefaults({
78
+ id: { type: String, required: false },
79
+ label: { type: String, required: false },
80
+ disabled: { type: Boolean, required: false },
81
+ readonly: { type: Boolean, required: false },
82
+ border: { type: Boolean, required: false },
83
+ unstyle: { type: Boolean, required: false },
84
+ filterKeydown: { type: Function, required: false },
85
+ filterBlur: { type: Function, required: false },
86
+ filterFocus: { type: Function, required: false },
87
+ suggestions: { type: Array, required: false },
88
+ suggestionLabel: { type: Function, required: false },
89
+ restrictToSuggestions: { type: Boolean, required: false },
90
+ updateOnlyOnSubmit: { type: Boolean, required: false },
91
+ suggestionsFilter: { type: Function, required: false },
92
+ allowOpenEmpty: { type: Boolean, required: false },
93
+ canOpen: { type: Boolean, required: false },
94
+ canClose: { type: Boolean, required: false },
95
+ isValid: { type: Boolean, required: false },
96
+ suggestionSelector: { type: Function, required: false },
97
+ showSelectedValues: { type: Boolean, required: false }
98
+ }, {
99
+ isValid: true,
100
+ canOpen: true,
101
+ filterKeydown: void 0,
102
+ ...baseInteractivePropsDefaults
103
+ }));
104
+ const $modelValue = defineModel("modelValue", { type: null, ...{ required: true } });
105
+ const $inputValue = defineModel("inputValue", { type: String, ...{ default: "" } });
106
+ const $open = defineModel("open", { type: Boolean, ...{ default: false } });
89
107
  if (typeof props.suggestions?.[0] === "object" && !props.suggestionLabel && !props.suggestionsFilter) {
90
- throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.")
108
+ throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.");
91
109
  }
92
-
93
- const el = ref<HTMLElement | null>(null)
94
- const mousedown = ref(false)
95
-
110
+ const el = ref(null);
96
111
  const suggestions = reactive(useSuggestions(
97
- $inputValue,
98
- $modelValue,
99
- emits,
100
- props
101
- ))
102
-
103
- const inputKeydownHandler = (e: KeyboardEvent): void => {
104
- if (props.filterKeydown?.(e)) return
105
- if (hasModifiers(e)) return
106
- if (e.key === "Enter") {
107
- suggestions.enterSelected()
108
- e.preventDefault()
109
- } else if (e.key === "Escape") {
110
- suggestions.cancel()
111
- e.preventDefault()
112
- } else if (!suggestions.isOpen && ["ArrowDown", "ArrowUp", "PageUp", "PageDown"].includes(e.key) && suggestions.available) {
113
- suggestions.open()
114
- e.preventDefault()
115
- if (e.key === "PageUp") {
116
- suggestions.first()
117
- } else if (e.key === "PageDown") {
118
- suggestions.last()
119
- }
120
- } else if (e.key === "ArrowUp") {
121
- suggestions.prev()
122
- e.preventDefault()
123
- } else if (e.key === "ArrowDown") {
124
- suggestions.next()
125
- e.preventDefault()
126
- } else if (e.key === "PageUp") {
127
- suggestions.first()
128
- e.preventDefault()
129
- } else if (e.key === "PageDown") {
130
- suggestions.last()
131
- e.preventDefault()
132
- }
133
- }
134
- const inputBlurHandler = (e: MouseEvent): void => {
135
- if (props.filterBlur?.(e)) return
136
-
137
- if (!suggestions.isOpen) return
138
-
139
- if (props.restrictToSuggestions) {
140
- suggestions.cancel()
141
- } else {
142
- $modelValue.value = $inputValue.value
143
- }
144
- if (suggestions.isOpen) {
145
- suggestions.close()
146
- }
147
- }
148
- const inputFocusHandler = (e: FocusEvent): void => {
149
- if (props.filterFocus?.(e)) return
150
- suggestions.open()
151
- }
152
-
112
+ $inputValue,
113
+ $modelValue,
114
+ $open,
115
+ emits,
116
+ props
117
+ ));
118
+ const inputKeydownHandler = (e) => {
119
+ if (props.filterKeydown?.(e)) return;
120
+ if (hasModifiers(e)) return;
121
+ if (e.key === "Enter") {
122
+ suggestions.enterSelected(!Array.isArray($modelValue));
123
+ e.preventDefault();
124
+ } else if (e.key === "Escape") {
125
+ suggestions.cancel();
126
+ e.preventDefault();
127
+ } else if (!$open.value && ["ArrowDown", "ArrowUp", "PageUp", "PageDown"].includes(e.key) && suggestions.available) {
128
+ suggestions.open();
129
+ e.preventDefault();
130
+ if (e.key === "PageUp") {
131
+ suggestions.first();
132
+ } else if (e.key === "PageDown") {
133
+ suggestions.last();
134
+ }
135
+ } else if (e.key === "ArrowUp") {
136
+ suggestions.prev();
137
+ e.preventDefault();
138
+ } else if (e.key === "ArrowDown") {
139
+ suggestions.next();
140
+ e.preventDefault();
141
+ } else if (e.key === "PageUp") {
142
+ suggestions.first();
143
+ e.preventDefault();
144
+ } else if (e.key === "PageDown") {
145
+ suggestions.last();
146
+ e.preventDefault();
147
+ }
148
+ };
149
+ const inputBlurHandler = (e) => {
150
+ if (props.filterBlur?.(e)) return;
151
+ if (!$open.value) return;
152
+ if (props.restrictToSuggestions) {
153
+ suggestions.cancel();
154
+ } else {
155
+ if (!Array.isArray($modelValue.value)) {
156
+ $modelValue.value = $inputValue.value;
157
+ }
158
+ }
159
+ if ($open.value) {
160
+ suggestions.close();
161
+ }
162
+ };
163
+ const inputFocusHandler = (e) => {
164
+ if (props.filterFocus?.(e)) return;
165
+ suggestions.open();
166
+ };
153
167
  defineExpose({
154
- suggestions,
155
- el,
156
- /** A simple keydown handler that can be passed to an input to control the component while still focused inside it. */
157
- inputKeydownHandler,
158
- /** A blur handler for the input that controls the component. This also takes care of making clicking on a suggestion work, since otherwise if canOpen is set to false in the blur handler, no click event will fire. */
159
- inputBlurHandler,
160
- /** A focus handler for the input that controls the component. */
161
- inputFocusHandler,
162
- })
163
-
168
+ suggestions,
169
+ el,
170
+ /** A simple keydown handler that can be passed to an input to control the component while still focused inside it. */
171
+ inputKeydownHandler,
172
+ /** A blur handler for the input that controls the component. This also takes care of making clicking on a suggestion work, since otherwise if canOpen is set to false in the blur handler, no click event will fire. */
173
+ inputBlurHandler,
174
+ /** A focus handler for the input that controls the component. */
175
+ inputFocusHandler
176
+ });
164
177
  </script>
165
178
 
166
- <script lang="ts">
167
- type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes, {
168
- /** Tailwind classes. */
169
- class?: string
170
- }>>
171
-
172
- type RealProps =
173
- & LinkableByIdProps
174
- & LabelProps
175
- & BaseInteractiveProps
176
- & MultiValueProps
177
- & {
178
- /** Return true to prevent the keydown event from being handled. */
179
- filterKeydown?: (e: KeyboardEvent) => boolean
180
- /** Return true to prevent the blur event from being handled. */
181
- filterBlur?: (e: MouseEvent) => boolean
182
- /** Return true to prevent the focus event from being handled. */
183
- filterFocus?: (e: FocusEvent) => boolean
184
- }
185
-
186
- interface Props
187
- extends
188
- /** @vue-ignore */
189
- Partial<Omit<HTMLAttributes,"class" | "onSubmit"> & {
190
- /** Tailwind classes. */
191
- class?: string
192
- }>,
193
- /** @vue-ignore */
194
- WrapperTypes,
195
- RealProps
196
- {}
179
+ <script>
197
180
 
198
181
  </script>