@witchcraft/ui 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +18 -28
  2. package/dist/module.d.mts +3 -1
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +21 -12
  5. package/dist/runtime/assets/base.css +1 -1
  6. package/dist/runtime/assets/locales/en.json +2 -2
  7. package/dist/runtime/assets/tailwind.css +1 -1
  8. package/dist/runtime/assets/utils.css +1 -0
  9. package/dist/runtime/build/WitchcraftUiResolver.js +1 -1
  10. package/dist/runtime/components/Aria/Aria.vue +5 -9
  11. package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
  12. package/dist/runtime/components/Icon/Icon.vue +12 -28
  13. package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
  14. package/dist/runtime/components/LibButton/LibButton.vue +93 -117
  15. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
  16. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +53 -76
  17. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
  18. package/dist/runtime/components/LibColorInput/LibColorInput.vue +131 -101
  19. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
  20. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +326 -296
  21. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
  22. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.d.ts +2 -0
  23. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +18 -0
  24. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.d.ts +2 -0
  25. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +17 -0
  26. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.d.ts +2 -0
  27. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.js +8 -0
  28. package/dist/runtime/components/LibColorPicker/utils/truncate.d.ts +1 -0
  29. package/dist/runtime/components/LibColorPicker/utils/truncate.js +5 -0
  30. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +42 -64
  31. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
  32. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +20 -54
  33. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
  34. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +205 -173
  35. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
  36. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +215 -164
  37. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
  38. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +9 -10
  39. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
  40. package/dist/runtime/components/LibDebug/LibDebug.vue +47 -65
  41. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
  42. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +19 -34
  43. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
  44. package/dist/runtime/components/LibFileInput/LibFileInput.vue +155 -173
  45. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
  46. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +352 -0
  47. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
  48. package/dist/runtime/components/LibLabel/LibLabel.vue +30 -46
  49. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +27 -0
  50. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +50 -66
  51. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
  52. package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -56
  53. package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
  54. package/dist/runtime/components/LibNotifications/LibNotifications.vue +71 -83
  55. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
  56. package/dist/runtime/components/LibPagination/LibPagination.vue +86 -131
  57. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
  58. package/dist/runtime/components/LibPalette/LibPalette.vue +23 -26
  59. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
  60. package/dist/runtime/components/LibPopup/LibPopup.vue +326 -400
  61. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
  62. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +73 -93
  63. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
  64. package/dist/runtime/components/LibRecorder/LibRecorder.vue +134 -179
  65. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
  66. package/dist/runtime/components/LibRoot/LibRoot.vue +75 -89
  67. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
  68. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +51 -82
  69. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
  70. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +147 -164
  71. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
  72. package/dist/runtime/components/LibTable/LibTable.vue +69 -106
  73. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
  74. package/dist/runtime/components/Template/NAME.vue +15 -36
  75. package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
  76. package/dist/runtime/components/TestControls/TestControls.vue +7 -10
  77. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
  78. package/dist/runtime/components/index.d.ts +12 -11
  79. package/dist/runtime/components/index.js +12 -11
  80. package/dist/runtime/components/shared/props.d.ts +81 -16
  81. package/dist/runtime/components/shared/storyHelpers/playInput.js +5 -5
  82. package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +15 -11
  83. package/dist/runtime/composables/index.d.ts +5 -0
  84. package/dist/runtime/composables/index.js +5 -0
  85. package/dist/runtime/composables/useDivideAttrs.js +1 -0
  86. package/dist/runtime/composables/useDragWithThreshold.d.ts +71 -0
  87. package/dist/runtime/composables/useDragWithThreshold.js +40 -0
  88. package/dist/runtime/composables/usePreHydrationValue.d.ts +12 -0
  89. package/dist/runtime/composables/usePreHydrationValue.js +15 -0
  90. package/dist/runtime/composables/useSetupI18n.d.ts +2 -0
  91. package/dist/runtime/composables/useSetupI18n.js +5 -1
  92. package/dist/runtime/composables/useSuggestions.d.ts +7 -5
  93. package/dist/runtime/composables/useSuggestions.js +94 -57
  94. package/dist/runtime/directives/vResizableCols.js +92 -84
  95. package/dist/runtime/helpers/NotificationHandler.d.ts +5 -0
  96. package/dist/runtime/helpers/index.d.ts +3 -1
  97. package/dist/runtime/helpers/index.js +3 -1
  98. package/dist/runtime/types/index.d.ts +6 -0
  99. package/dist/runtime/utils/notifyIfError.d.ts +14 -0
  100. package/dist/runtime/utils/notifyIfError.js +29 -0
  101. package/dist/types.d.mts +2 -6
  102. package/package.json +27 -29
  103. package/src/module.ts +31 -12
  104. package/src/runtime/assets/base.css +10 -1
  105. package/src/runtime/assets/locales/en.json +2 -2
  106. package/src/runtime/assets/tailwind.css +1 -1
  107. package/src/runtime/assets/{style.css → utils.css} +86 -4
  108. package/src/runtime/build/WitchcraftUiResolver.ts +1 -1
  109. package/src/runtime/components/Focus.stories.ts +3 -2
  110. package/src/runtime/components/Icon/Icon.vue +10 -6
  111. package/src/runtime/components/LibButton/LibButton.vue +41 -47
  112. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +7 -4
  113. package/src/runtime/components/LibColorInput/LibColorInput.vue +111 -37
  114. package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +25 -4
  115. package/src/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
  116. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +24 -0
  117. package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +23 -0
  118. package/src/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.ts +13 -0
  119. package/src/runtime/components/LibColorPicker/utils/truncate.ts +6 -0
  120. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +1 -1
  121. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
  122. package/src/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
  123. package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
  124. package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
  125. package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
  126. package/src/runtime/components/LibDebug/LibDebug.vue +15 -5
  127. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
  128. package/src/runtime/components/LibFileInput/LibFileInput.vue +54 -29
  129. package/src/runtime/components/{LibInput/LibInput.stories.ts → LibInputDeprecated/LibInputDeprecated.stories.ts} +64 -19
  130. package/{dist/runtime/components/LibInput/LibInput.vue → src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -34
  131. package/src/runtime/components/LibLabel/LibLabel.vue +2 -2
  132. package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +5 -4
  133. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +11 -13
  134. package/src/runtime/components/LibNotifications/LibNotification.vue +19 -11
  135. package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +2 -2
  136. package/src/runtime/components/LibNotifications/LibNotifications.vue +20 -12
  137. package/src/runtime/components/LibPagination/LibPagination.stories.ts +2 -2
  138. package/src/runtime/components/LibPagination/LibPagination.vue +19 -20
  139. package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
  140. package/src/runtime/components/LibPopup/LibPopup.stories.ts +2 -2
  141. package/src/runtime/components/LibPopup/LibPopup.vue +30 -67
  142. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +3 -2
  143. package/src/runtime/components/LibRecorder/LibRecorder.vue +2 -3
  144. package/src/runtime/components/LibRoot/LibRoot.vue +14 -1
  145. package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +1 -1
  146. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -8
  147. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +42 -26
  148. package/src/runtime/components/LibTable/LibTable.vue +8 -9
  149. package/src/runtime/components/Scrolling.stories.ts +58 -0
  150. package/src/runtime/components/Template/NAME.vue +1 -1
  151. package/src/runtime/components/TestControls/TestControls.vue +1 -1
  152. package/src/runtime/components/index.ts +12 -12
  153. package/src/runtime/components/shared/props.ts +82 -19
  154. package/src/runtime/components/shared/storyHelpers/playInput.ts +6 -5
  155. package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +25 -11
  156. package/src/runtime/composables/index.ts +5 -0
  157. package/src/runtime/composables/useDarkMode.ts +2 -2
  158. package/src/runtime/composables/useDivideAttrs.ts +1 -0
  159. package/src/runtime/composables/useDragWithThreshold.ts +108 -0
  160. package/src/runtime/composables/usePreHydrationValue.ts +30 -0
  161. package/src/runtime/composables/useSetupI18n.ts +8 -2
  162. package/src/runtime/composables/useSuggestions.ts +92 -45
  163. package/src/runtime/directives/vResizableCols.ts +82 -74
  164. package/src/runtime/helpers/NotificationHandler.ts +5 -0
  165. package/src/runtime/helpers/index.ts +3 -1
  166. package/src/runtime/types/index.ts +5 -0
  167. package/src/runtime/utils/notifyIfError.ts +45 -0
  168. package/dist/module.cjs +0 -5
  169. package/dist/module.d.ts +0 -34
  170. package/dist/runtime/assets/style.css +0 -1
  171. package/dist/runtime/components/Focus.stories.d.ts +0 -11
  172. package/dist/runtime/components/Focus.stories.js +0 -53
  173. package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
  174. package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
  175. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
  176. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
  177. package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
  178. package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
  179. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -7
  180. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -51
  181. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
  182. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
  183. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
  184. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
  185. package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
  186. package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
  187. package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
  188. package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
  189. package/dist/runtime/components/LibInput/LibInput.stories.d.ts +0 -33
  190. package/dist/runtime/components/LibInput/LibInput.stories.js +0 -339
  191. package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
  192. package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
  193. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
  194. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -60
  195. package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
  196. package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
  197. package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
  198. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
  199. package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
  200. package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
  201. package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
  202. package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
  203. package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
  204. package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
  205. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
  206. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
  207. package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
  208. package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
  209. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
  210. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
  211. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
  212. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
  213. package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
  214. package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
  215. package/dist/runtime/components/reset.stories.d.ts +0 -5
  216. package/dist/runtime/components/reset.stories.js +0 -19
  217. package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
  218. package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
  219. package/dist/runtime/helpers/addValue.d.ts +0 -1
  220. package/dist/runtime/helpers/addValue.js +0 -8
  221. package/dist/types.d.ts +0 -7
  222. package/src/runtime/components/LibInput/LibInput.vue +0 -372
  223. package/src/runtime/helpers/addValue.ts +0 -10
  224. /package/src/runtime/components/{reset.stories.ts → Reset.stories.ts} +0 -0
@@ -1,4 +1,5 @@
1
1
  import { type PropType } from "vue";
2
+ import type { PopupPositioner, PopupPositionModifier } from "../../types/index.js";
2
3
  export interface LinkableByIdProps {
3
4
  /**
4
5
  * The id for the input. Uses vue's useId if none provided.
@@ -8,6 +9,11 @@ export interface LinkableByIdProps {
8
9
  id?: string;
9
10
  }
10
11
  export declare const getFallbackId: () => string;
12
+ export interface ButtonProps {
13
+ border?: boolean;
14
+ color?: "warning" | "ok" | "danger" | "primary" | "secondary" | false;
15
+ autoTitleFromAria?: boolean;
16
+ }
11
17
  export interface LabelProps {
12
18
  /** For the label. Note the component might or might not support an actual label element. If none is supported, this is used for the `aria-label`. */
13
19
  label?: string;
@@ -53,6 +59,8 @@ export type SuggestionsProps<T = any> = {
53
59
  allowOpenEmpty?: boolean;
54
60
  /** Whether the suggestions dropdown can be opened. Default is true. */
55
61
  canOpen?: boolean;
62
+ /** Whether the suggestions dropdown can be closed. Default is true. */
63
+ canClose?: boolean;
56
64
  /** Whether the input is valid. Default is true. */
57
65
  isValid?: boolean;
58
66
  /**
@@ -61,12 +69,81 @@ export type SuggestionsProps<T = any> = {
61
69
  * You can implement custom behavior here like fuzzy matching. Note that an exactly matching selection is always picked (the function will not be called).
62
70
  */
63
71
  suggestionSelector?: (suggestions: T[], input: string) => number;
72
+ /** In the case modelValue is an array of values, whether to show the selected values in the suggestions list. Default is true so users can deselect from the list as well. If false, the checkboxes will also not be shown. */
73
+ showSelectedValues?: boolean;
64
74
  };
65
- export type SuggestionsOptions<T> = SuggestionsProps<T> & MultiValueProps;
66
- export interface SuggestionsEmits {
67
- (e: "submit", val: string, suggestion?: any): void;
75
+ export type SuggestionsOptions<T> = SuggestionsProps<T>;
76
+ export interface SuggestionsEmits<TMultivalue extends boolean = false> {
77
+ (e: "submit", val: string, suggestion?: any, wasRemoved?: boolean): void;
68
78
  (e: "update:isOpen", val: boolean): void;
69
- (e: "update:activeSuggestion", val: number): void;
79
+ (e: "update:activeSuggestion", val: TMultivalue extends true ? number[] : number): void;
80
+ }
81
+ export interface PopupProps {
82
+ /**
83
+ * Whether to use the dialog element instead of a regular backdrop. While using the dialog element would be ideal, css variables won't be applied to it, tailwind themes will fail, etc, if the css variables are not applied to `::backdrop`.
84
+ *
85
+ * Using a div ends up easier to setup.
86
+ *
87
+ * The default is now false.
88
+ */
89
+ useDialogForBackdrop?: false;
90
+ /** Wether to use a backdrop (clicking it will close the popup), or not (use is allowed to click elsewhere. */
91
+ useBackdrop?: boolean;
92
+ /**
93
+ * The preferred horizontal positioning of the popup. The first position in the array to fit is used.
94
+ *
95
+ * All elements need to have box-sizing: border-box set. Also note that while the component should work with dynamic popup sizes, in practice there's issues with the positioning being slightly off. Giving the popup element a static size is better. If you need margins around the popup, this can be done with a wrapper element + padding.
96
+ *
97
+ * The positions `right`/`left`/`top`/`bottom` are relative to the opposite side of the button element so as to try not to cover the triggering button.
98
+ *
99
+ * So positioning `right` and `left` look like this:
100
+ *
101
+ * ```
102
+ * // right
103
+ * [button]
104
+ * [----popup----]
105
+ *
106
+ * // left
107
+ * [button]
108
+ * [----popup----]
109
+ * ```
110
+ *
111
+ * Positions `*-most` try to position the popup as close to that side of the screen as possible, otherwise limiting the popup to that edge. For example:
112
+ *
113
+ * ```
114
+ * [--------------screen---------------]
115
+ * // right-most
116
+ * [button]
117
+ * [----popup----]
118
+ * // near the edge:
119
+ * [button]
120
+ * [----popup----]
121
+ * ```
122
+ *
123
+ * There is also the `center-screen` position, which centers the popup on the screen.
124
+ *
125
+ * These last two (`*-most` and `center-screen`) are greedy, they will always find a position that fits. Positions listed after are ignored.
126
+ *
127
+ * You can also specify a function instead which is given some additional information regarding the space around the button reference element. It should a number for the x position (or y, if preferredVertical).
128
+ *
129
+ * If you only need to slightly modify the position, you can use the `modifyPosition` option instead.
130
+ */
131
+ preferredHorizontal?: ("center" | "right" | "left" | "either" | "center-screen" | "right-most" | "left-most" | "center-most")[] | PopupPositioner;
132
+ /** See `preferredHorizontal`. */
133
+ preferredVertical?: ("top" | "bottom" | "center" | "either" | "center-screen" | "top-most" | "bottom-most" | "center-most")[] | PopupPositioner;
134
+ /**
135
+ * When the user scrolls or resizes, normally the entire popup position is recomputed, taking into account the preferred positioning.
136
+ *
137
+ * This can cause it to shift around.
138
+ *
139
+ * Set this to true to only shift the popup depending on how much the button element moved and avoid recalculating the best position.
140
+ */
141
+ avoidRepositioning?: boolean;
142
+ /**
143
+ * Allows modifying the calculated position, to for example, clamp it.
144
+ */
145
+ modifyPosition?: PopupPositionModifier;
146
+ canClose?: boolean;
70
147
  }
71
148
  export declare const baseInteractiveProps: {
72
149
  readonly unstyle: {
@@ -106,18 +183,6 @@ export declare const baseInteractivePropsDefaults: {
106
183
  border: boolean;
107
184
  unstyle: boolean;
108
185
  };
109
- export type MultiValueProps = {
110
- /**
111
- * If values is used, for components that handle multiple values, prevents adding of duplicate values.
112
- *
113
- * For other components, it prevents suggesting values that have already been added.
114
- *
115
- * Default is true.
116
- */
117
- preventDuplicateValues?: boolean;
118
- /** The selected values.*/
119
- values?: string[];
120
- };
121
186
  /**
122
187
  * @internal
123
188
  * For easily typing attributes created by useDivideAttrs. See readme.
@@ -14,13 +14,13 @@ export const playMultipleValues = async ({ canvasElement, args }) => {
14
14
  await userEvent.type(input, "A");
15
15
  await expect(canvas.getByTestId("model-value")).toHaveTextContent("A");
16
16
  await userEvent.keyboard("{Enter}");
17
- await expect(canvas.getByTestId("values").textContent).toBe([...initialValues, "A"].join(", "));
17
+ await expect(canvas.getByTestId("values").textContent).toBe([...initialValues].join(", "));
18
18
  await expect(canvas.getByTestId("model-value")).toBeEmptyDOMElement();
19
- await userEvent.type(input, "B");
20
- await expect(canvas.getByTestId("model-value")).toHaveTextContent("B");
19
+ await userEvent.type(input, "D");
20
+ await expect(canvas.getByTestId("model-value")).toHaveTextContent("D");
21
21
  await userEvent.keyboard("{Enter}");
22
- await expect(canvas.getByTestId("values").textContent).toBe([...initialValues, "A", "B"].join(", "));
22
+ await expect(canvas.getByTestId("values").textContent).toBe([...initialValues, "D"].join(", "));
23
23
  await userEvent.clear(input);
24
24
  await userEvent.keyboard("{Enter}");
25
- await expect(canvas.getByTestId("values").textContent).toBe([...initialValues, "A", "B"].join(", "));
25
+ await expect(canvas.getByTestId("values").textContent).toBe([...initialValues, "D"].join(", "));
26
26
  };
@@ -18,7 +18,7 @@ export const playBasicSelect = async ({ canvasElement, args }) => {
18
18
  await expect(canvas.queryByRole("option", { selected: true })).toBeInTheDocument();
19
19
  await userEvent.clear(input);
20
20
  await userEvent.type(input, "unmatched");
21
- if (!args.suggestionsFilter) {
21
+ if (!args.suggestionsFilter && !args.values) {
22
22
  await expect(canvas.queryAllByRole("option", { selected: true })).toEqual([]);
23
23
  }
24
24
  await userEvent.clear(input);
@@ -32,7 +32,9 @@ export const playBasicSelect = async ({ canvasElement, args }) => {
32
32
  }
33
33
  await userEvent.clear(input);
34
34
  await userEvent.keyboard("AB{Escape}");
35
- await expect(canvas.queryByRole("listbox")).toBeNull();
35
+ if (!args.values) {
36
+ await expect(canvas.queryByRole("listbox")).toBeNull();
37
+ }
36
38
  if (args.values === void 0) {
37
39
  if (args.restrictToSuggestions) {
38
40
  await expect(canvas.getByTestId("model-value").textContent).toBe("A");
@@ -50,16 +52,24 @@ export const playBasicKeyboardSelect = async ({ canvasElement, args }) => {
50
52
  await userEvent.keyboard("{ArrowUp}");
51
53
  await expect(canvas.queryByRole("option", { name: "A", selected: true })).toBeInTheDocument();
52
54
  await userEvent.keyboard("{ArrowUp}");
53
- await expect(canvas.queryByRole("option", { name: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", selected: true })).toBeInTheDocument();
55
+ await expect(canvas.queryByRole("option", {
56
+ name: args.values ? "C" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
57
+ selected: true
58
+ })).toBeInTheDocument();
54
59
  await userEvent.keyboard("{ArrowDown}");
55
60
  await expect(canvas.queryByRole("option", { name: "A", selected: true })).toBeInTheDocument();
56
61
  await userEvent.keyboard("{PageDown}");
57
- await expect(canvas.queryByRole("option", { name: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", selected: true })).toBeInTheDocument();
62
+ await expect(canvas.queryByRole("option", {
63
+ name: args.values ? "C" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
64
+ selected: true
65
+ })).toBeInTheDocument();
58
66
  await userEvent.keyboard("{PageUp}");
59
67
  await expect(canvas.queryByRole("option", { name: "A", selected: true })).toBeInTheDocument();
60
68
  const testOpen = async (key) => {
61
69
  await userEvent.keyboard("{Escape}");
62
- await expect(canvas.queryByRole("listbox")).toBeNull();
70
+ if (!args.values) {
71
+ await expect(canvas.queryByRole("listbox")).toBeNull();
72
+ }
63
73
  await userEvent.keyboard(`{${key}}`);
64
74
  await expect(canvas.queryByRole("listbox")).toBeInTheDocument();
65
75
  };
@@ -74,10 +84,4 @@ export const playBasicClickSelect = async ({ canvasElement, args }) => {
74
84
  await userEvent.clear(input);
75
85
  await userEvent.type(input, "A");
76
86
  await userEvent.click(canvas.getByRole("option", { name: "AB" }));
77
- if (args.values === void 0) {
78
- await expect(canvas.getByTestId("model-value").textContent).toBe("AB");
79
- await expect(canvas.queryByRole("listbox")).toBeNull();
80
- } else {
81
- await expect(canvas.getByTestId("values")).toHaveTextContent(/AB$/);
82
- }
83
87
  };
@@ -1,10 +1,15 @@
1
+ export { languageLocaleInjectionKey } from "./useSetupLocale.js.js";
1
2
  export { useAccesibilityOutline } from "./useAccesibilityOutline.js.js";
2
3
  export { useAriaLabel } from "./useAriaLabel.js.js";
3
4
  export { useDarkMode } from "./useDarkMode.js.js";
4
5
  export { useDivideAttrs } from "./useDivideAttrs.js.js";
6
+ export { useDragWithThreshold } from "./useDragWithThreshold.js.js";
5
7
  export { useGlobalResizeObserver } from "./useGlobalResizeObserver.js.js";
6
8
  export { useInjectedDarkMode } from "./useInjectedDarkMode.js.js";
9
+ export { useInjectedI18n } from "./useInjectedI18n.js.js";
10
+ export { useInjectedLocale } from "./useInjectedLocale.js.js";
7
11
  export { useNotificationHandler } from "./useNotificationHandler.js.js";
12
+ export { usePreHydrationValue } from "./usePreHydrationValue.js.js";
8
13
  export { useScrollNearContainerEdges } from "./useScrollNearContainerEdges.js.js";
9
14
  export { useSetupDarkMode } from "./useSetupDarkMode.js.js";
10
15
  export { useShowDevOnlyKey } from "./useShowDevOnlyKey.js.js";
@@ -1,10 +1,15 @@
1
+ export { languageLocaleInjectionKey } from "./useSetupLocale.js";
1
2
  export { useAccesibilityOutline } from "./useAccesibilityOutline.js";
2
3
  export { useAriaLabel } from "./useAriaLabel.js";
3
4
  export { useDarkMode } from "./useDarkMode.js";
4
5
  export { useDivideAttrs } from "./useDivideAttrs.js";
6
+ export { useDragWithThreshold } from "./useDragWithThreshold.js";
5
7
  export { useGlobalResizeObserver } from "./useGlobalResizeObserver.js";
6
8
  export { useInjectedDarkMode } from "./useInjectedDarkMode.js";
9
+ export { useInjectedI18n } from "./useInjectedI18n.js";
10
+ export { useInjectedLocale } from "./useInjectedLocale.js";
7
11
  export { useNotificationHandler } from "./useNotificationHandler.js";
12
+ export { usePreHydrationValue } from "./usePreHydrationValue.js";
8
13
  export { useScrollNearContainerEdges } from "./useScrollNearContainerEdges.js";
9
14
  export { useSetupDarkMode } from "./useSetupDarkMode.js";
10
15
  export { useShowDevOnlyKey } from "./useShowDevOnlyKey.js";
@@ -8,6 +8,7 @@ export const useDivideAttrs = (divisionKeys) => computed(() => {
8
8
  res[`${key}Attrs`] = {};
9
9
  for (let i = 0; i < unseen.length; i++) {
10
10
  const attrKey = unseen[i];
11
+ if (!attrKey) continue;
11
12
  if (attrKey.startsWith(`${key}-`)) {
12
13
  res[`${key}Attrs`][attrKey.slice(key.length + 1)] = attrs[attrKey];
13
14
  unseen.splice(i, 1);
@@ -0,0 +1,71 @@
1
+ import { type Ref } from "vue";
2
+ import type { Point } from "../types/index.js.js";
3
+ /**
4
+ * A composable for dragging items only after a certain threshold of movement has been reached.
5
+ *
6
+ * What to do with the actual pointer coordinates is up to you.
7
+ *
8
+ * The is compatible with the `useScrollNearContainerEdges` composable as well.
9
+ *
10
+ * ```ts
11
+ * const {
12
+ * pointerCoords,
13
+ * passedDragThreshold,
14
+ * startDragThresholdCheck,
15
+ * endDragThresholdCheck,
16
+ * checkDragThreshold,
17
+ * } = useDragWithThreshold({ threshold: ref(5) })
18
+ *
19
+ * function grabPointerDown(e: PointerEvent): void {
20
+ * startDragThresholdCheck(e)
21
+ * e.preventDefault()
22
+ *
23
+ * document.addEventListener("pointermove", grabPointerMove)
24
+ * document.addEventListener("pointerup", grabPointerUp)
25
+ * document.addEventListener("keyup", escapeDrag)
26
+ * }
27
+ * function grabPointerMove(e: PointerEvent): void {
28
+ * e.preventDefault()
29
+ * checkDragThreshold(e)
30
+ * if (passedDragThreshold.value) {
31
+ *
32
+ * }
33
+ * }
34
+ * function grabPointerUp(e: PointerEvent): void {
35
+ * if (passedDragThreshold.value) {
36
+ * // drag
37
+ * } else {
38
+ * // handleAsClick(e)
39
+ * }
40
+ * stopDrag()
41
+ * }
42
+ *
43
+ * function stopDrag(): void {
44
+ * endDragThresholdCheck()
45
+ * document.removeEventListener("keyup", escapeDrag)
46
+ * document.removeEventListener("pointermove", grabPointerMove)
47
+ * document.removeEventListener("pointerup", grabPointerUp)
48
+ * }
49
+ *
50
+ * function escapeDrag(e: KeyboardEvent): void {
51
+ * if (e.code === "Escape") stopDrag()
52
+ * }
53
+ * ```
54
+ */
55
+ export declare const useDragWithThreshold: ({ initialOffset, pointerCoords, threshold, }?: {
56
+ initialOffset?: Ref<Point | undefined>;
57
+ pointerCoords?: Ref<Point | undefined>;
58
+ threshold?: Ref<number>;
59
+ }) => {
60
+ initialOffset: Ref<Point | undefined, Point | undefined>;
61
+ pointerCoords: Ref<Point | undefined, Point | undefined>;
62
+ threshold: Ref<number, number>;
63
+ passedDragThreshold: Ref<boolean, boolean>;
64
+ getEventCoords: (e: {
65
+ clientX: number;
66
+ clientY: number;
67
+ }) => Point;
68
+ checkDragThreshold: (e: PointerEvent) => void;
69
+ startDragThresholdCheck: (e: PointerEvent) => void;
70
+ endDragThresholdCheck: () => void;
71
+ };
@@ -0,0 +1,40 @@
1
+ import { ref } from "vue";
2
+ export const useDragWithThreshold = ({
3
+ initialOffset = ref({ x: 0, y: 0 }),
4
+ pointerCoords = ref({ x: 0, y: 0 }),
5
+ threshold = ref(10)
6
+ } = {}) => {
7
+ const passedDragThreshold = ref(false);
8
+ function getDistance(p1, p2) {
9
+ const xDiff = p2.x - p1.x;
10
+ const yDiff = p2.y - p1.y;
11
+ return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
12
+ }
13
+ function getEventCoords(e) {
14
+ return { x: e.clientX, y: e.clientY };
15
+ }
16
+ function checkDragThreshold(e) {
17
+ pointerCoords.value = getEventCoords(e);
18
+ passedDragThreshold.value ||= initialOffset.value !== void 0 && getDistance(initialOffset.value, pointerCoords.value) >= threshold.value;
19
+ }
20
+ function startDragThresholdCheck(e) {
21
+ passedDragThreshold.value = false;
22
+ initialOffset.value = getEventCoords(e);
23
+ pointerCoords.value = getEventCoords(e);
24
+ }
25
+ function endDragThresholdCheck() {
26
+ passedDragThreshold.value = false;
27
+ initialOffset.value = void 0;
28
+ pointerCoords.value = void 0;
29
+ }
30
+ return {
31
+ initialOffset,
32
+ pointerCoords,
33
+ threshold,
34
+ passedDragThreshold,
35
+ getEventCoords,
36
+ checkDragThreshold,
37
+ startDragThresholdCheck,
38
+ endDragThresholdCheck
39
+ };
40
+ };
@@ -0,0 +1,12 @@
1
+ import { type Ref } from "vue";
2
+ /**
3
+ *
4
+ * This takes the value of the element at the given id (onBeforeMount, i.e. pre-hydration if available), and sets the given ref to that value onMounted.
5
+ *
6
+ * This should be compatible with both nuxt and vue.
7
+ *
8
+ * Nore that while it's generic, you will need to provide a transform function to convert the string to the desired type.
9
+ *
10
+ * @experimental
11
+ */
12
+ export declare function usePreHydrationValue<T>(id: string, refVal: Ref<T>, transform?: (val: string) => T): void;
@@ -0,0 +1,15 @@
1
+ import { onBeforeMount, onMounted } from "vue";
2
+ export function usePreHydrationValue(id, refVal, transform = (val) => val) {
3
+ let temp = "";
4
+ onBeforeMount(() => {
5
+ const el = document.getElementById(id);
6
+ if (el?.value) {
7
+ temp = el.value;
8
+ }
9
+ });
10
+ onMounted(() => {
11
+ if (temp) {
12
+ refVal.value = transform(temp);
13
+ }
14
+ });
15
+ }
@@ -6,6 +6,8 @@ export type TranslationFunction = (key: string, replacements?: Record<string, an
6
6
  * Should be called only once. You can choose to await it or not (see the `useDummyMessageSetWhileLoading` option).
7
7
  *
8
8
  * A default function is available, see {@link defaultTranslationFunction}.
9
+ *
10
+ * To avoid hydration errors, on the server, the message loading is awaited.
9
11
  */
10
12
  export declare function useSetupI18n({ locale, useBuiltinTranslations, useDummyMessageSetWhileLoading, translationFunction, }: {
11
13
  locale: Ref<string>;
@@ -40,7 +40,11 @@ export async function useSetupI18n({
40
40
  messages.value = newMessages;
41
41
  }
42
42
  }
43
- void loadMessageSet(locale.value);
43
+ if (import.meta.server) {
44
+ await loadMessageSet(locale.value);
45
+ } else {
46
+ void loadMessageSet(locale.value);
47
+ }
44
48
  watch(locale, async () => {
45
49
  void loadMessageSet(locale.value);
46
50
  });
@@ -1,3 +1,4 @@
1
+ import { type AnyFunction } from "@alanscodelog/utils";
1
2
  import { type Ref } from "vue";
2
3
  import { type SuggestionsEmits, type SuggestionsOptions } from "../components/shared/props.js.js";
3
4
  /**
@@ -5,7 +6,7 @@ import { type SuggestionsEmits, type SuggestionsOptions } from "../components/sh
5
6
  *
6
7
  * Note that while object suggestions are supported, the `suggestionLabel` prop is required and $inputModel and $modelValue will still be string values (as returned by the suggestionLabel function).
7
8
  */
8
- export declare function useSuggestions<TSuggestion>($inputValue: Ref<string>, $modelValue: Ref<string>, emit: SuggestionsEmits, opts: SuggestionsOptions<TSuggestion>, debug?: boolean): {
9
+ export declare function useSuggestions<TSuggestion, TMultivalue extends boolean = false>($inputValue: Ref<string>, $modelValue: Ref<TMultivalue extends true ? string[] : string>, $open: Ref<boolean>, emit: SuggestionsEmits, opts: SuggestionsOptions<TSuggestion>, debug?: boolean): {
9
10
  list: import("vue").ComputedRef<any[] | undefined>;
10
11
  filtered: import("vue").ComputedRef<any[] | undefined>;
11
12
  active: Ref<number, number>;
@@ -16,11 +17,11 @@ export declare function useSuggestions<TSuggestion>($inputValue: Ref<string>, $m
16
17
  hasValidSuggestion: import("vue").ComputedRef<boolean>;
17
18
  openable: import("vue").ComputedRef<boolean | undefined>;
18
19
  getLabel: (item: any) => string;
19
- isOpen: Ref<boolean, boolean>;
20
+ $open: Ref<boolean, boolean>;
20
21
  open: () => void;
21
22
  close: () => void;
22
- enterSelected: () => void;
23
- enterSuggestion: (num: number) => void;
23
+ enterSelected: (doClose?: boolean) => void;
24
+ enterIndex: (num: number, doClose?: boolean) => void;
24
25
  toggle: () => void;
25
26
  cancel: () => void;
26
27
  select: (num: number) => void;
@@ -29,10 +30,11 @@ export declare function useSuggestions<TSuggestion>($inputValue: Ref<string>, $m
29
30
  first: () => void;
30
31
  last: () => void;
31
32
  };
32
- export declare function useSuggestionsInputAria(id: Ref<string>, isOpen: Ref<boolean>, activeSuggestion: Ref<number>, suggestions: Ref<any | undefined>): import("vue").ComputedRef<{
33
+ export declare function useSuggestionsInputAria(id: Ref<string>, $open: Ref<boolean>, activeSuggestion: Ref<number>, suggestions: Ref<any | undefined>): import("vue").ComputedRef<{
33
34
  "aria-autocomplete": "both" | undefined;
34
35
  "aria-controls": string | undefined;
35
36
  role: string | undefined;
36
37
  "aria-expanded": boolean | undefined;
37
38
  "aria-activedescendant": string | undefined;
38
39
  }>;
40
+ export declare function suggestionLabelGuard<TFunction extends AnyFunction>(item: any, suggestionLabeler: TFunction | undefined): asserts suggestionLabeler is TFunction;