@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,33 +1,42 @@
1
1
  import { isBlank } from "@alanscodelog/utils/isBlank.js";
2
2
  import { isObject } from "@alanscodelog/utils/isObject.js";
3
+ import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
4
+ import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js";
3
5
  import { computed, ref, toRaw, watch } from "vue";
4
- export function useSuggestions($inputValue, $modelValue, emit, opts, debug = false) {
6
+ export function useSuggestions($inputValue, $modelValue, $open, emit, opts, debug = false) {
5
7
  if (typeof opts.suggestions?.[0] === "object" && !opts.suggestionLabel && !opts.suggestionsFilter) {
6
8
  throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.");
7
9
  }
8
- const isOpen = ref(false);
9
10
  const activeSuggestion = ref(-1);
10
- watch(isOpen, (val) => {
11
- emit("update:isOpen", val);
12
- });
13
11
  watch(activeSuggestion, (val) => {
14
12
  emit("update:activeSuggestion", val);
15
13
  });
16
- const suggestionKey = (item) => {
14
+ if (opts.suggestions) {
15
+ for (const suggestion of opts.suggestions) {
16
+ suggestionLabelGuard(suggestion, opts.suggestionLabel);
17
+ }
18
+ }
19
+ const getSuggestionLabel = (item) => {
20
+ suggestionLabelGuard(item, opts.suggestionLabel);
17
21
  if (isObject(item)) {
18
- if (opts.suggestionLabel) {
19
- return opts.suggestionLabel(item);
20
- }
21
- throw new Error("`suggestionLabel` must be passed if suggestions are objects.");
22
+ return opts.suggestionLabel(item);
22
23
  }
23
24
  return item;
24
25
  };
25
- const getSuggestionLabel = (item) => opts.suggestionLabel?.(item) ?? suggestionKey(item) ?? "";
26
- const defaultSuggestionsFilter = (input, items) => input === "" ? [...items] : items.filter((item) => getSuggestionLabel(item).toLowerCase().includes(input.toLowerCase()));
26
+ const defaultSuggestionsFilter = (input, items) => input === "" ? [...items] : items.filter((item) => {
27
+ if (Array.isArray($modelValue.value)) {
28
+ if ($modelValue.value.includes(getSuggestionLabel(item))) return true;
29
+ }
30
+ return getSuggestionLabel(item).toLowerCase().includes(input.toLowerCase());
31
+ });
27
32
  const suggestionsFilter = computed(() => opts.suggestionsFilter ?? defaultSuggestionsFilter);
28
33
  const suggestionsList = computed(() => {
29
34
  if (opts.suggestions) {
30
- const res = suggestionsFilter.value($inputValue.value, opts.suggestions);
35
+ const suggestions = [...opts.suggestions];
36
+ if (Array.isArray($modelValue.value) && !opts.showSelectedValues) {
37
+ pushIfNotIn(suggestions, $modelValue.value);
38
+ }
39
+ const res = suggestionsFilter.value($inputValue.value, suggestions);
31
40
  return res;
32
41
  }
33
42
  return void 0;
@@ -43,19 +52,30 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
43
52
  if (opts.suggestions) {
44
53
  const res = suggestionAvailable.value ? suggestionsList.value : opts.suggestions;
45
54
  if (opts.restrictToSuggestions && !isValidSuggestion.value) return res;
46
- if (opts.preventDuplicateValues && opts.values) {
47
- return res.filter((suggestion) => !opts.values.includes(suggestionKey(suggestion)));
48
- }
49
55
  return res;
50
56
  }
51
57
  return void 0;
52
58
  });
53
- const closeSuggestions = () => {
59
+ function setValue(val) {
60
+ if (Array.isArray($modelValue.value)) {
61
+ if ($modelValue.value.includes(val)) {
62
+ removeIfIn($modelValue.value, val);
63
+ return true;
64
+ } else {
65
+ pushIfNotIn($modelValue.value, [val]);
66
+ }
67
+ } else {
68
+ $modelValue.value = val;
69
+ }
70
+ return false;
71
+ }
72
+ function closeSuggestions() {
73
+ if (!opts.canClose) return;
54
74
  if (debug) console.log("closeSuggestions");
55
- isOpen.value = false;
75
+ $open.value = false;
56
76
  activeSuggestion.value = -1;
57
- };
58
- const openSuggestions = () => {
77
+ }
78
+ function openSuggestions() {
59
79
  if (debug) console.log("openSuggestions", { openable: openable.value });
60
80
  if (!openable.value) return;
61
81
  if (activeSuggestion.value === -1) {
@@ -65,20 +85,22 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
65
85
  activeSuggestion.value = 0;
66
86
  }
67
87
  }
68
- isOpen.value = true;
69
- };
70
- function enterSuggestion(num) {
88
+ $open.value = true;
89
+ }
90
+ function enterSuggestion(num, doClose = true) {
71
91
  if (num < -1 || num > (filteredSuggestions.value?.length ?? 0)) return;
72
92
  if (debug) console.log("enterSuggestion", num);
73
93
  if (filteredSuggestions.value === void 0) return;
74
94
  const suggestion = filteredSuggestions.value[num];
75
- const val = suggestionKey(suggestion);
76
- $modelValue.value = val;
77
- $inputValue.value = getSuggestionLabel(suggestion);
78
- closeSuggestions();
79
- emit("submit", val, toRaw(suggestion));
95
+ const val = getSuggestionLabel(suggestion);
96
+ const wasRemoved = setValue(val);
97
+ $inputValue.value = Array.isArray($modelValue.value) ? "" : getSuggestionLabel(suggestion);
98
+ if (doClose) {
99
+ closeSuggestions();
100
+ }
101
+ emit("submit", val, toRaw(suggestion), wasRemoved);
80
102
  }
81
- const enterSelected = () => {
103
+ function enterSelected(doClose = true) {
82
104
  if (activeSuggestion.value === -1) {
83
105
  if (!opts.restrictToSuggestions) {
84
106
  if (debug) console.log("enterSelected, unrestricted, emitting submit");
@@ -89,9 +111,9 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
89
111
  return;
90
112
  }
91
113
  if (debug) console.log("enterSelected");
92
- enterSuggestion(activeSuggestion.value);
93
- };
94
- const selectSuggestion = (num) => {
114
+ enterSuggestion(activeSuggestion.value, doClose);
115
+ }
116
+ function selectSuggestion(num) {
95
117
  if (debug) console.log("selectSuggestion", num);
96
118
  if (num >= -1) {
97
119
  activeSuggestion.value = num;
@@ -99,37 +121,41 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
99
121
  if (num === Infinity && (filteredSuggestions.value?.length ?? 0) > 0) {
100
122
  activeSuggestion.value = filteredSuggestions.value.length - 1;
101
123
  }
102
- };
103
- const toggleSuggestions = () => {
104
- isOpen.value ? closeSuggestions() : openSuggestions();
105
- };
106
- const prevSuggestion = () => {
124
+ }
125
+ function toggleSuggestions() {
126
+ $open.value ? closeSuggestions() : openSuggestions();
127
+ }
128
+ function prevSuggestion() {
107
129
  if (!filteredSuggestions.value) return;
108
130
  if (activeSuggestion.value > 0) {
109
131
  activeSuggestion.value--;
110
132
  } else if (filteredSuggestions.value) {
111
133
  activeSuggestion.value = filteredSuggestions.value.length - 1;
112
134
  }
113
- };
114
- const nextSuggestion = () => {
135
+ }
136
+ function nextSuggestion() {
115
137
  if (!filteredSuggestions.value) return;
116
138
  if (activeSuggestion.value >= filteredSuggestions.value.length - 1) {
117
139
  activeSuggestion.value = 0;
118
140
  } else {
119
141
  activeSuggestion.value++;
120
142
  }
121
- };
122
- const firstSuggestion = () => {
143
+ }
144
+ function firstSuggestion() {
123
145
  selectSuggestion(0);
124
- };
125
- const lastSuggestion = () => {
146
+ }
147
+ function lastSuggestion() {
126
148
  selectSuggestion(Infinity);
127
- };
128
- const cancel = () => {
149
+ }
150
+ function cancel() {
151
+ if (Array.isArray($modelValue.value)) {
152
+ $inputValue.value = "";
153
+ return;
154
+ }
129
155
  if (debug) console.log("cancel");
130
156
  $inputValue.value = getSuggestionLabel($modelValue.value);
131
157
  closeSuggestions();
132
- };
158
+ }
133
159
  watch(() => opts.canOpen, (val) => {
134
160
  if (!val) {
135
161
  if (debug) console.log("canOpen changed to false, closing suggestions");
@@ -149,10 +175,14 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
149
175
  }
150
176
  });
151
177
  watch($modelValue, () => {
152
- $inputValue.value = getSuggestionLabel($modelValue.value);
178
+ if (Array.isArray($modelValue.value)) {
179
+ $inputValue.value = "";
180
+ } else {
181
+ $inputValue.value = getSuggestionLabel($modelValue.value);
182
+ }
153
183
  if (debug) console.log("modelValue changed");
154
184
  });
155
- const defaultSuggestionSelector = (suggestions, input) => {
185
+ function defaultSuggestionSelector(suggestions, input) {
156
186
  if (input.length === 0) return 0;
157
187
  let longestMatch;
158
188
  let ii = -1;
@@ -168,17 +198,17 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
168
198
  }
169
199
  }
170
200
  return ii;
171
- };
201
+ }
172
202
  watch($inputValue, () => {
173
203
  if (debug) console.log("input changed:", $inputValue.value, "modelValue:", $modelValue.value);
174
- if (getSuggestionLabel($modelValue.value) === $inputValue.value) return;
204
+ if (!Array.isArray($modelValue.value) && getSuggestionLabel($modelValue.value) === $inputValue.value) return;
175
205
  if (suggestionAvailable.value) {
176
206
  if (debug) console.log("input changed, suggestion available, opening suggestions");
177
207
  openSuggestions();
178
208
  }
179
- if (!opts.restrictToSuggestions) {
209
+ if (!opts.restrictToSuggestions && !Array.isArray($modelValue.value)) {
180
210
  if (debug) console.log("input changed, unrestricted, setting modelValue");
181
- $modelValue.value = $inputValue.value;
211
+ setValue($inputValue.value);
182
212
  }
183
213
  if (exactlyMatchingSuggestion.value && suggestionsList.value) {
184
214
  if (debug) console.log("input changed, exactly matching, setting activeSuggestion");
@@ -200,11 +230,11 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
200
230
  hasValidSuggestion: isValidSuggestion,
201
231
  openable,
202
232
  getLabel: getSuggestionLabel,
203
- isOpen,
233
+ $open,
204
234
  open: openSuggestions,
205
235
  close: closeSuggestions,
206
236
  enterSelected,
207
- enterSuggestion,
237
+ enterIndex: enterSuggestion,
208
238
  toggle: toggleSuggestions,
209
239
  cancel,
210
240
  select: selectSuggestion,
@@ -214,13 +244,20 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
214
244
  last: lastSuggestion
215
245
  };
216
246
  }
217
- export function useSuggestionsInputAria(id, isOpen, activeSuggestion, suggestions) {
247
+ export function useSuggestionsInputAria(id, $open, activeSuggestion, suggestions) {
218
248
  const ariaInputProps = computed(() => ({
219
249
  "aria-autocomplete": suggestions !== void 0 ? "both" : void 0,
220
250
  "aria-controls": suggestions !== void 0 ? `suggestions-${id.value}` : void 0,
221
251
  role: suggestions ? "combobox" : void 0,
222
- "aria-expanded": suggestions !== void 0 ? isOpen.value : void 0,
223
- "aria-activedescendant": isOpen.value ? `suggestion-${id.value}-${activeSuggestion.value}` : void 0
252
+ "aria-expanded": suggestions !== void 0 ? $open.value : void 0,
253
+ "aria-activedescendant": $open.value ? `suggestion-${id.value}-${activeSuggestion.value}` : void 0
224
254
  }));
225
255
  return ariaInputProps;
226
256
  }
257
+ export function suggestionLabelGuard(item, suggestionLabeler) {
258
+ if (isObject(item)) {
259
+ if (!suggestionLabeler) {
260
+ throw new Error("`suggestionLabel` must be passed if suggestions are objects.");
261
+ }
262
+ }
263
+ }
@@ -48,7 +48,7 @@ export const vResizableCols = {
48
48
  return {};
49
49
  }
50
50
  };
51
- const setWidth = (col, amountInPx, el) => {
51
+ function setWidth(col, amountInPx, el) {
52
52
  const $el = getElInfo(el);
53
53
  const width = Math.max($el.margin, amountInPx);
54
54
  const index = getColEls(el).findIndex((_) => col === _);
@@ -57,12 +57,12 @@ const setWidth = (col, amountInPx, el) => {
57
57
  } else {
58
58
  $el.widths.value[index] = `${width}px`;
59
59
  }
60
- };
61
- const getBox = (el) => {
60
+ }
61
+ function getBox(el) {
62
62
  const rect = el.getBoundingClientRect();
63
63
  return { x: Math.round(rect.x), width: Math.round(rect.width) };
64
- };
65
- const getCols = (el) => {
64
+ }
65
+ function getCols(el) {
66
66
  const $el = getElInfo(el);
67
67
  if (!$el.target) unreachable();
68
68
  let col = getColEls(el)[$el.grips.get($el.target)];
@@ -77,75 +77,81 @@ const getCols = (el) => {
77
77
  }
78
78
  }
79
79
  return { col, colNext };
80
- };
81
- const createPointerDownHandler = (el) => (e) => {
82
- const $el = getElInfo(el);
83
- if (!$el.isDragging) {
84
- castType(e.target);
85
- $el.target = e.target;
86
- $el.isDragging = true;
87
- e.preventDefault();
88
- document.addEventListener("pointerup", $el.pointerUpHandler);
89
- const { col, colNext } = getCols(el);
90
- if (col === null || colNext === null) {
91
- el.classList.add("resizable-cols-error");
92
- } else {
93
- document.addEventListener("pointermove", $el.pointerMoveHandler);
94
- const box = getBox(col);
95
- if (box) {
96
- $el.offset = e.pageX - (box.x + box.width);
80
+ }
81
+ function createPointerDownHandler(el) {
82
+ return (e) => {
83
+ const $el = getElInfo(el);
84
+ if (!$el.isDragging) {
85
+ castType(e.target);
86
+ $el.target = e.target;
87
+ $el.isDragging = true;
88
+ e.preventDefault();
89
+ document.addEventListener("pointerup", $el.pointerUpHandler);
90
+ const { col, colNext } = getCols(el);
91
+ if (col === null || colNext === null) {
92
+ el.classList.add("resizable-cols-error");
93
+ } else {
94
+ document.addEventListener("pointermove", $el.pointerMoveHandler);
95
+ const box = getBox(col);
96
+ if (box) {
97
+ $el.offset = e.pageX - (box.x + box.width);
98
+ }
97
99
  }
98
100
  }
99
- }
100
- };
101
- const createPointerMoveHandler = (el) => (e) => {
102
- const $el = getElInfo(el);
103
- if ($el.isDragging) {
104
- e.preventDefault();
105
- const { col, colNext } = getCols(el);
106
- if (col !== null) {
107
- const leftBox = getBox(col);
108
- const oldWidth = leftBox.width;
109
- const leftBound = leftBox.x;
110
- const rightBox = colNext ? getBox(colNext) : getBox(el);
111
- const rightBound = rightBox.x + rightBox.width;
112
- const margin = $el.margin;
113
- const pos = e.pageX - $el.offset;
114
- if ($el.fitWidth) {
115
- if (pos > leftBound + margin && pos < rightBound - margin) {
116
- const newWidth = pos - leftBound;
117
- const diff = oldWidth - newWidth;
118
- if (rightBox.width + diff < margin) {
119
- el.classList.add("resizable-cols-error");
120
- return;
101
+ };
102
+ }
103
+ function createPointerMoveHandler(el) {
104
+ return (e) => {
105
+ const $el = getElInfo(el);
106
+ if ($el.isDragging) {
107
+ e.preventDefault();
108
+ const { col, colNext } = getCols(el);
109
+ if (col !== null) {
110
+ const leftBox = getBox(col);
111
+ const oldWidth = leftBox.width;
112
+ const leftBound = leftBox.x;
113
+ const rightBox = colNext ? getBox(colNext) : getBox(el);
114
+ const rightBound = rightBox.x + rightBox.width;
115
+ const margin = $el.margin;
116
+ const pos = e.pageX - $el.offset;
117
+ if ($el.fitWidth) {
118
+ if (pos > leftBound + margin && pos < rightBound - margin) {
119
+ const newWidth = pos - leftBound;
120
+ const diff = oldWidth - newWidth;
121
+ if (rightBox.width + diff < margin) {
122
+ el.classList.add("resizable-cols-error");
123
+ return;
124
+ }
125
+ setWidth(col, newWidth, el);
126
+ setWidth(colNext, rightBox.width + diff, el);
127
+ }
128
+ } else {
129
+ if (pos > leftBound + margin) {
130
+ const newWidth = pos - leftBound;
131
+ setWidth(col, newWidth, el);
121
132
  }
122
- setWidth(col, newWidth, el);
123
- setWidth(colNext, rightBox.width + diff, el);
124
- }
125
- } else {
126
- if (pos > leftBound + margin) {
127
- const newWidth = pos - leftBound;
128
- setWidth(col, newWidth, el);
129
133
  }
134
+ positionGrips(el);
130
135
  }
131
- positionGrips(el);
132
136
  }
133
- }
134
- };
135
- const createPointerUpHandler = (el) => (e) => {
136
- const $el = getElInfo(el);
137
- if ($el.isDragging) {
138
- e.preventDefault();
139
- $el.isDragging = false;
140
- el.classList.remove("resizable-cols-error");
141
- $el.offset = 0;
142
- delete $el.target;
143
- document.removeEventListener("pointermove", $el.pointerMoveHandler);
144
- document.removeEventListener("pointerup", $el.pointerUpHandler);
145
- document.removeEventListener("pointerleave", $el.pointerLeaveHandler);
146
- }
147
- };
148
- const createGrip = () => {
137
+ };
138
+ }
139
+ function createPointerUpHandler(el) {
140
+ return (e) => {
141
+ const $el = getElInfo(el);
142
+ if ($el.isDragging) {
143
+ e.preventDefault();
144
+ $el.isDragging = false;
145
+ el.classList.remove("resizable-cols-error");
146
+ $el.offset = 0;
147
+ delete $el.target;
148
+ document.removeEventListener("pointermove", $el.pointerMoveHandler);
149
+ document.removeEventListener("pointerup", $el.pointerUpHandler);
150
+ document.removeEventListener("pointerleave", $el.pointerLeaveHandler);
151
+ }
152
+ };
153
+ }
154
+ function createGrip() {
149
155
  const grip = document.createElement("div");
150
156
  grip.style.position = "absolute";
151
157
  grip.style.cursor = "col-resize";
@@ -153,31 +159,31 @@ const createGrip = () => {
153
159
  grip.style.bottom = "0";
154
160
  grip.classList.add("grip");
155
161
  return grip;
156
- };
162
+ }
157
163
  const removeGrips = (el) => {
158
164
  const grips = Array.from(el.querySelectorAll(".grip") ?? []);
159
165
  for (const grip of grips) {
160
166
  el.removeChild(grip);
161
167
  }
162
168
  };
163
- const getTestGripSize = (el) => {
169
+ function getTestGripSize(el) {
164
170
  const testGrip = createGrip();
165
171
  el.appendChild(testGrip);
166
172
  const dynamicMinWidth = getBox(testGrip).width * 3;
167
173
  el.removeChild(testGrip);
168
174
  return dynamicMinWidth;
169
- };
170
- const getElInfo = (el) => {
175
+ }
176
+ function getElInfo(el) {
171
177
  const $el = elMap.get(el);
172
178
  if (!$el) unreachable("El went missing.");
173
179
  return $el;
174
- };
175
- const getColEls = (el) => {
180
+ }
181
+ function getColEls(el) {
176
182
  const $el = elMap.get(el);
177
183
  if (!$el) unreachable("El went missing.");
178
184
  return [...el.querySelectorAll(`:scope ${$el.selector ? $el.selector : "tr > td"}`)];
179
- };
180
- const setupColumns = (el, opts) => {
185
+ }
186
+ function setupColumns(el, opts) {
181
187
  const gripWidth = getTestGripSize(el);
182
188
  const $el = {
183
189
  grips: /* @__PURE__ */ new Map(),
@@ -207,19 +213,21 @@ const setupColumns = (el, opts) => {
207
213
  }
208
214
  positionGrips(el);
209
215
  el.classList.add("resizable-cols-setup");
210
- };
211
- const positionGrips = (el) => {
216
+ }
217
+ function positionGrips(el) {
212
218
  let xPos = 0;
213
219
  const $el = getElInfo(el);
214
220
  for (const grip of $el.grips.keys()) {
215
221
  const col = $el.grips.get(grip);
216
- const colBox = getBox(getColEls(el)[col]);
222
+ const colEls = getColEls(el)[col];
223
+ if (!colEls) unreachable();
224
+ const colBox = getBox(colEls);
217
225
  const gripBox = getBox(grip);
218
226
  grip.style.left = `${xPos + colBox.width - gripBox.width / 2}px`;
219
227
  xPos += colBox.width;
220
228
  }
221
- };
222
- const setColWidths = (el, children) => {
229
+ }
230
+ function setColWidths(el, children) {
223
231
  const $el = getElInfo(el);
224
232
  const header = children ?? getColEls(el).slice(0, $el.colCount);
225
233
  const len = $el.colCount;
@@ -237,8 +245,8 @@ const setColWidths = (el, children) => {
237
245
  } else {
238
246
  el.style.minWidth = "";
239
247
  }
240
- };
241
- const teardownColumns = (el) => {
248
+ }
249
+ function teardownColumns(el) {
242
250
  const $el = getElInfo(el);
243
251
  el.removeEventListener("pointerdown", $el.pointerDownHandler);
244
252
  document.removeEventListener("pointermove", $el.pointerMoveHandler);
@@ -249,4 +257,4 @@ const teardownColumns = (el) => {
249
257
  elMap.delete(el);
250
258
  el.classList.remove("resizable-cols-setup");
251
259
  removeGrips(el);
252
- };
260
+ }
@@ -28,11 +28,16 @@ export type RawNotificationEntry<TOptions extends string[] = ["Ok", "Cancel"], T
28
28
  message: string;
29
29
  title?: string;
30
30
  code?: string;
31
+ /** @default ["Ok", "Cancel"] */
31
32
  options?: TOptions;
33
+ /** @default false */
32
34
  requiresAction?: boolean;
33
35
  cancellable?: TCancellable;
36
+ /** @default "Ok" */
34
37
  default?: TOptions[number];
38
+ /** @default [] */
35
39
  dangerous?: TOptions[number][];
40
+ /** @default false if cancellable, otherwise the default timeout */
36
41
  timeout?: number | boolean;
37
42
  icon?: string;
38
43
  };
@@ -1,7 +1,9 @@
1
- export { addValue } from "./addValue.js.js";
2
1
  export { base64ToImg } from "./base64ToImg.js.js";
3
2
  export { copy } from "./copy.js.js";
3
+ export { createNoonUtcDate } from "./createNoonUtcDate.js.js";
4
4
  export { createRecorderHandler } from "./storybook.js.js";
5
+ export { defaultTranslationFunction } from "./defaultTranslationFunction.js.js";
6
+ export { getTimeZoneList } from "./getTimeZoneList.js.js";
5
7
  export { hasModifiers } from "./hasModifiers.js.js";
6
8
  export { NotificationHandler } from "./NotificationHandler.js.js";
7
9
  export { readFile } from "./readFile.js.js";
@@ -1,7 +1,9 @@
1
- export { addValue } from "./addValue.js";
2
1
  export { base64ToImg } from "./base64ToImg.js";
3
2
  export { copy } from "./copy.js";
3
+ export { createNoonUtcDate } from "./createNoonUtcDate.js";
4
4
  export { createRecorderHandler } from "./storybook.js";
5
+ export { defaultTranslationFunction } from "./defaultTranslationFunction.js";
6
+ export { getTimeZoneList } from "./getTimeZoneList.js";
5
7
  export { hasModifiers } from "./hasModifiers.js";
6
8
  export { NotificationHandler } from "./NotificationHandler.js";
7
9
  export { readFile } from "./readFile.js";
@@ -53,18 +53,24 @@ export type FileInputError = ErrorW<{
53
53
  isValidMimeType: boolean;
54
54
  isValidExtension: boolean;
55
55
  }>;
56
+ /** h 0-360+ (deg), s 0-100%, v 0-100%, a 0-1 */
56
57
  export type HsvaColor = {
57
58
  h: number;
58
59
  s: number;
59
60
  v: number;
60
61
  a?: number;
61
62
  };
63
+ /** rgb 0-255, 0-1 for alpha */
62
64
  export type RgbaColor = {
63
65
  r: number;
64
66
  g: number;
65
67
  b: number;
66
68
  a?: number;
67
69
  };
70
+ export type Point = {
71
+ x: number;
72
+ y: number;
73
+ };
68
74
  export type ScrollNearContainerEdgesOptions = {
69
75
  containerEl: Ref<HTMLElement | null>;
70
76
  /** Margin inside contianer that allows scrolling. 10 by default. */
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Notifies the user if the given value is an error. Useful for making non-critical errors don't go unnoticed.
3
+ *
4
+ * Integrates with {@link TypedError} from `@alanscodelog/utils` to display the error code as well if it has one.
5
+ *
6
+ * If the value is not an error, it is returned.
7
+ */
8
+ export declare function notifyIfError<T>(err: T, { logger, ns, force, }?: {
9
+ logger?: {
10
+ debug: (...args: any[]) => void;
11
+ };
12
+ ns?: string;
13
+ force?: boolean;
14
+ }): T;
@@ -0,0 +1,29 @@
1
+ import { TypedError } from "@alanscodelog/utils/TypedError.js";
2
+ import { useNotificationHandler } from "../composables/useNotificationHandler.js";
3
+ export function notifyIfError(err, {
4
+ logger,
5
+ ns,
6
+ force = false
7
+ } = {}) {
8
+ if (force || err instanceof Error) {
9
+ const errMessage = {
10
+ message: err instanceof Error ? err.message : `Unknown error ${err}`,
11
+ code: err instanceof TypedError ? err.code : void 0
12
+ };
13
+ if (logger) {
14
+ logger.debug({
15
+ ns,
16
+ ...errMessage,
17
+ stack: err instanceof Error ? err.stack : void 0
18
+ });
19
+ }
20
+ void useNotificationHandler().notify({
21
+ title: "Error",
22
+ ...errMessage,
23
+ options: ["Ok"],
24
+ cancellable: "Ok",
25
+ timeout: true
26
+ });
27
+ }
28
+ return err;
29
+ }
package/dist/types.d.mts CHANGED
@@ -1,7 +1,3 @@
1
- import type { NuxtModule } from '@nuxt/schema'
1
+ export { default } from './module.mjs'
2
2
 
3
- import type { default as Module } from './module.js'
4
-
5
- export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
-
7
- export { default } from './module.js'
3
+ export { type ModuleOptions } from './module.mjs'