@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,8 +1,10 @@
1
1
  <template>
2
2
  <div
3
- v-if="$values && $values?.length > 0"
4
- :class="twMerge(`
5
- values
3
+ v-if="$modelValue && $modelValue?.length > 0"
4
+ :class="
5
+ twMerge(
6
+ `
7
+ multivalues
6
8
  group
7
9
  flex
8
10
  flex-initial
@@ -12,18 +14,20 @@
12
14
  overflow-x-scroll
13
15
  scrollbar-hidden
14
16
  `,
15
- ($ as any)?.class)
16
- "
17
+ $.attrs?.class
18
+ )
19
+ "
17
20
  :data-disabled="disabled"
18
21
  :data-read-only="readonly"
19
22
  :aria-label="`Values for ${label}`"
20
23
  :tabindex="disabled ? -1 : 0"
21
- v-bind="{...$, class:undefined}"
24
+ v-bind="{ ...$.attrs, class: void 0 }"
22
25
  >
23
26
  <div
24
27
  :data-border="border"
25
- :class="twMerge(`
26
- value_wrapper
28
+ :class="twMerge(
29
+ `
30
+ multivalues--item
27
31
  flex-basis-0
28
32
  min-w-2
29
33
  flex
@@ -35,31 +39,31 @@
35
39
  px-1
36
40
  text-xs
37
41
  leading-none`,
38
- !(disabled || readonly) && `
42
+ !(disabled || readonly) && `
39
43
  group-focus:text-accent-500
40
44
  focus:text-accent-500`,
41
- border && `
45
+ border && `
42
46
  rounded-sm
43
47
  border-neutral-400
44
48
  border
45
49
  focus:border-accent-400
46
50
  `,
47
- border && (disabled || readonly) && `
51
+ border && (disabled || readonly) && `
48
52
  border-neutral-200
49
53
  focus:border-neutral-200
50
54
  dark:border-neutral-800
51
55
  dark:focus:border-neutral-800
52
56
  `,
53
- ($.itemAttrs as any)?.class
54
- )"
55
- :tabindex="canEdit ? 0 : undefined"
56
- v-for="(value) of $values"
57
+ $.itemAttrs?.class
58
+ )"
59
+ :tabindex="canEdit ? 0 : void 0"
60
+ v-for="(value) of $modelValue"
57
61
  :key="value"
58
62
  @keydown.ctrl.c.prevent="copy(value.toString())"
59
63
  >
60
- <span class="value_label truncate">{{ value }}</span>
64
+ <span class="multivalues--label truncate">{{ value }}</span>
61
65
  <lib-button
62
- class="!p-0 text-sm !leading-none"
66
+ class="multivalues--remove-button !p-0 text-sm !leading-none"
63
67
  :aria-label="`Remove ${value}`"
64
68
  :border="false"
65
69
  :disabled="disabled || readonly"
@@ -71,57 +75,37 @@
71
75
  </div>
72
76
  </template>
73
77
 
74
- <script setup lang="ts" generic="T extends string | number">
75
- import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js"
76
- import { computed, type HTMLAttributes } from "vue"
77
-
78
- import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
79
- import { copy } from "../../helpers/copy.js"
80
- import { twMerge } from "../../utils/twMerge.js"
81
- import Icon from "../Icon/Icon.vue"
82
- import LibButton from "../LibButton/LibButton.vue"
83
- import { type BaseInteractiveProps, baseInteractivePropsDefaults,type LabelProps, type MultiValueProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
84
-
85
-
78
+ <script setup>
79
+ import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js";
80
+ import { computed } from "vue";
81
+ import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
82
+ import { copy } from "../../helpers/copy.js";
83
+ import { twMerge } from "../../utils/twMerge.js";
84
+ import Icon from "../Icon/Icon.vue";
85
+ import LibButton from "../LibButton/LibButton.vue";
86
+ import { baseInteractivePropsDefaults } from "../shared/props.js";
86
87
  defineOptions({
87
- name: "lib-multi-values",
88
- inheritAttrs: false,
89
- })
90
-
91
- const $ = useDivideAttrs(["item"] as const)
92
- // eslint-disable-next-line no-use-before-define
93
- const props = withDefaults(defineProps<Props>(), {
94
- ...baseInteractivePropsDefaults
95
- })
96
-
97
-
98
- const canEdit = computed(() => !props.disabled && !props.readonly)
99
- const $values = defineModel<T[]>("values", { default: () => []})
100
-
101
- const removeVal = (value: T) => {
102
- if (!canEdit.value) return
103
- removeIfIn($values.value, value)
104
- }
88
+ name: "lib-multi-values",
89
+ inheritAttrs: false
90
+ });
91
+ const $ = useDivideAttrs(["item"]);
92
+ const props = defineProps(/* @__PURE__ */ _mergeDefaults({
93
+ label: { type: String, required: false },
94
+ disabled: { type: Boolean, required: false },
95
+ readonly: { type: Boolean, required: false },
96
+ border: { type: Boolean, required: false },
97
+ unstyle: { type: Boolean, required: false }
98
+ }, {
99
+ ...baseInteractivePropsDefaults
100
+ }));
101
+ const canEdit = computed(() => !props.disabled && !props.readonly);
102
+ const $modelValue = defineModel({ type: Array, ...{ default: () => [] } });
103
+ const removeVal = (value) => {
104
+ if (!canEdit.value) return;
105
+ removeIfIn($modelValue.value, value);
106
+ };
105
107
  </script>
106
108
 
107
- <script lang="ts">
108
- type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes>>
109
-
110
- type RealProps =
111
- & LabelProps
112
- & BaseInteractiveProps
113
- & MultiValueProps
114
- & {
115
- border?: boolean
116
- }
117
- interface Props
118
- extends
119
- /** @vue-ignore */
120
- Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
121
- /** @vue-ignore */
122
- WrapperTypes,
123
- RealProps
124
- {}
109
+ <script>
125
110
 
126
111
  </script>
127
-
@@ -0,0 +1,29 @@
1
+ import { type HTMLAttributes } from "vue";
2
+ import { type BaseInteractiveProps, type LabelProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js.js";
3
+ type WrapperTypes = Partial<WrapperProps<"item", HTMLAttributes>>;
4
+ type RealProps = LabelProps & BaseInteractiveProps & {
5
+ border?: boolean;
6
+ };
7
+ interface Props extends
8
+ /** @vue-ignore */
9
+ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>,
10
+ /** @vue-ignore */
11
+ WrapperTypes, RealProps {
12
+ }
13
+ declare const _default: <T extends string | number>(__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<{
14
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
15
+ readonly "onUpdate:modelValue"?: ((value: T[]) => any) | undefined;
16
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onUpdate:modelValue"> & (Props & {
17
+ modelValue?: T[];
18
+ }) & Partial<{}>> & import("vue").PublicProps;
19
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
20
+ attrs: any;
21
+ slots: {};
22
+ emit: (evt: "update:modelValue", value: T[]) => void;
23
+ }>) => import("vue").VNode & {
24
+ __ctx?: Awaited<typeof __VLS_setup>;
25
+ };
26
+ export default _default;
27
+ type __VLS_PrettifyLocal<T> = {
28
+ [K in keyof T as K]: T[K];
29
+ } & {};
@@ -1,8 +1,9 @@
1
1
  <template>
2
- <div :class="twMerge(`notification
2
+ <div :class="twMerge(
3
+ `notification
3
4
  max-w-700px
4
5
  bg-neutral-50
5
- dark:bg-neutral-950
6
+ dark:bg-neutral-900
6
7
  text-fg
7
8
  dark:text-bg
8
9
  border
@@ -13,13 +14,14 @@
13
14
  gap-2
14
15
  p-2 m-2
15
16
  `,
16
- ($attrs as any).class)"
17
- v-bind="{ ...$attrs, class: undefined }"
17
+ $attrs.class
18
+ )"
19
+ v-bind="{ ...$attrs, class: void 0 }"
18
20
  tabindex="0"
19
21
  ref="notificationEl"
20
22
  @keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
21
23
  >
22
- <div class="header flex-reverse flex justify-between">
24
+ <div class="notification--header flex-reverse flex justify-between">
23
25
  <div v-if="notification.title"
24
26
  tabindex="0"
25
27
  class="title
@@ -30,35 +32,45 @@
30
32
  >
31
33
  {{ notification.title }}
32
34
  </div>
33
- <div class="flex-1"/>
35
+ <div class="notification--spacer flex-1"/>
34
36
  <div class="actions flex">
35
37
  <LibButton :border="false"
36
- class="copy text-neutral-700"
38
+ class="notification--copy-button text-neutral-700"
37
39
  @click="copy(handler ? handler.stringify(notification) : JSON.stringify(notification))"
38
40
  >
39
41
  <icon><i-fa6-regular-copy/></icon>
40
42
  </LibButton>
41
- <lib-button v-if="notification.cancellable" :border="false" @click="NotificationHandler.dismiss(notification)">
43
+ <lib-button
44
+ v-if="notification.cancellable"
45
+ class="notification--cancel-button"
46
+ :border="false"
47
+ @click="NotificationHandler.dismiss(notification)"
48
+ >
42
49
  <icon><i-fa6-solid-xmark/></icon>
43
50
  </lib-button>
44
51
  </div>
45
52
  </div>
46
- <div class="message whitespace-pre-wrap" tabindex="0">
53
+ <div class="notification--message whitespace-pre-wrap" tabindex="0">
47
54
  {{ notification.message }}
48
55
  </div>
49
- <div class="bottom flex items-end justify-between">
56
+ <div class="notification--footer flex items-end justify-between">
50
57
  <div v-if="notification.code" class="code text-xs text-neutral-700 dark:text-neutral-300">
51
58
  Code: {{ notification.code }}
52
59
  </div>
53
- <div class="flex-1 py-1"/>
60
+ <div class="notification--footer-spacer flex-1 py-1"/>
54
61
  <div v-if="notification.options"
55
- class="options
62
+ class="notification--options
56
63
  flex flex-wrap justify-end
57
64
  gap-2
58
65
  "
59
66
  >
60
67
  <lib-button :label="option"
61
- :class="buttonColors[i] == 'secondary' ? 'p-0': undefined"
68
+ :class="twMerge(
69
+ `
70
+ notification--option-button
71
+ `,
72
+ buttonColors[i] == 'secondary' && 'p-0'
73
+ )"
62
74
  :border="buttonColors[i] !== 'secondary'"
63
75
  :color="buttonColors[i]"
64
76
  v-for="option, i in notification.options"
@@ -69,53 +81,33 @@
69
81
  </div>
70
82
  </div>
71
83
  </template>
72
- <script setup lang="ts">
73
- import { computed, type HTMLAttributes,ref, useAttrs } from "vue"
74
-
75
- import { copy } from "../../helpers/copy.js"
76
- import { type NotificationEntry, NotificationHandler } from "../../helpers/NotificationHandler.js"
77
- import { twMerge } from "../../utils/twMerge.js"
78
- import Icon from "../Icon/Icon.vue"
79
- import LibButton from "../LibButton/LibButton.vue"
80
- import type { TailwindClassProp } from "../shared/props.js"
81
-
82
84
 
85
+ <script setup>
86
+ import { computed, ref, useAttrs } from "vue";
87
+ import { copy } from "../../helpers/copy.js";
88
+ import { NotificationHandler } from "../../helpers/NotificationHandler.js";
89
+ import { twMerge } from "../../utils/twMerge.js";
90
+ import Icon from "../Icon/Icon.vue";
91
+ import LibButton from "../LibButton/LibButton.vue";
83
92
  defineOptions({
84
- name: "lib-notification",
85
- inheritAttrs: false,
86
- })
87
- const $attrs = useAttrs()
88
-
89
- // eslint-disable-next-line no-use-before-define
90
- const props = withDefaults(defineProps<Props>(), {
91
- handler: undefined,
92
- })
93
-
94
- const getColor = (notification: NotificationEntry, option: string): "ok" | "primary" | "danger" | "secondary" => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary"
95
-
96
- /* Todo make this more flexible? */
97
- // eslint-disable-next-line @stylistic/space-in-parens
98
- const buttonColors = computed(() => props.notification.options.map((option: any /* what ??? */) => getColor(props.notification, option)))
99
-
100
- const notificationEl = ref<null | HTMLElement>(null)
93
+ name: "lib-notification",
94
+ inheritAttrs: false
95
+ });
96
+ const $attrs = useAttrs();
97
+ const props = defineProps({
98
+ notification: { type: null, required: true },
99
+ handler: { type: Object, required: false, default: void 0 }
100
+ });
101
+ const getColor = (notification, option) => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary";
102
+ const buttonColors = computed(() => props.notification.options.map((option) => getColor(props.notification, option)));
103
+ const notificationEl = ref(null);
101
104
  defineExpose({
102
- focus: () => {
103
- notificationEl.value?.focus()
104
- },
105
- })
106
-
105
+ focus: () => {
106
+ notificationEl.value?.focus();
107
+ }
108
+ });
107
109
  </script>
108
110
 
109
- <script lang="ts">
110
- type RealProps = {
111
- notification: NotificationEntry
112
- handler?: NotificationHandler
113
- }
111
+ <script>
114
112
 
115
- interface Props
116
- extends
117
- /** @vue-ignore */
118
- Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
119
- RealProps
120
- {}
121
113
  </script>
@@ -0,0 +1,17 @@
1
+ import { type HTMLAttributes } from "vue";
2
+ import { type NotificationEntry, NotificationHandler } from "../../helpers/NotificationHandler.js.js";
3
+ import type { TailwindClassProp } from "../shared/props.js.js";
4
+ type RealProps = {
5
+ notification: NotificationEntry;
6
+ handler?: NotificationHandler;
7
+ };
8
+ interface Props extends
9
+ /** @vue-ignore */
10
+ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
11
+ }
12
+ declare const _default: import("vue").DefineComponent<Props, {
13
+ focus: () => void;
14
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
15
+ handler: NotificationHandler;
16
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
+ export default _default;
@@ -2,15 +2,16 @@
2
2
  <TransitionGroup name="list"
3
3
  tag="div"
4
4
  :class="twMerge(`notifications
5
- fixed
5
+ absolute
6
6
  z-50
7
7
  inset-y-0 right-0
8
8
  w-1/3
9
9
  min-w-[300px]
10
10
  pointer-events-none
11
11
  overflow-hidden
12
- `, ($attrs as any).class)"
13
- v-bind="{ ...$attrs, class: undefined }"
12
+ flex flex-col
13
+ `, $attrs.class)"
14
+ v-bind="{ ...$attrs, class: void 0 }"
14
15
  >
15
16
  <lib-notification class="pointer-events-auto"
16
17
  :handler="handler"
@@ -21,22 +22,25 @@
21
22
  />
22
23
  </TransitionGroup>
23
24
  <Transition>
24
- <div v-show="topNotifications.length > 0"/>
25
+ <div
26
+ v-show="topNotifications.length > 0"
27
+ :class="twMerge(`notifications--none`, $attrs.class)"
28
+ />
25
29
  </Transition>
26
30
  <Transition>
27
31
  <dialog v-show="topNotifications.length > 0"
28
32
  :id="id"
29
- class="modal
33
+ :class="twMerge(`notifications-modal
30
34
  bg-transparent
31
35
  p-0
32
36
  backdrop:bg-black/50
33
37
  backdrop:p-5
34
- "
38
+ `, $attrs.class)"
35
39
  ref="dialogEl"
36
- @click.self.prevent="NotificationHandler.dismiss(topNotifications[0])"
40
+ @click.self.prevent="topNotifications[0] && NotificationHandler.dismiss(topNotifications[0])"
37
41
  >
38
42
  <form>
39
- <lib-notification v-if="topNotifications.length > 0"
43
+ <lib-notification v-if="topNotifications.length > 0 && topNotifications[0]"
40
44
  :handler="handler"
41
45
  class="top-notification"
42
46
  :notification="topNotifications[0]"
@@ -46,88 +50,72 @@
46
50
  </dialog>
47
51
  </Transition>
48
52
  </template>
49
- <script setup lang="ts">
50
- import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js"
51
- import { type HTMLAttributes,nextTick, onBeforeUnmount, type PropType, ref, shallowReactive } from "vue"
52
-
53
- import LibNotification from "./LibNotification.vue"
54
-
55
- import { type NotificationEntry, NotificationHandler } from "../../helpers/NotificationHandler.js"
56
- import { twMerge } from "../../utils/twMerge.js"
57
- import type { LinkableByIdProps, TailwindClassProp } from "../shared/props.js"
58
53
 
54
+ <script setup>
55
+ import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js";
56
+ import { nextTick, onBeforeUnmount, ref, shallowReactive, Transition, TransitionGroup } from "vue";
57
+ import LibNotification from "./LibNotification.vue";
58
+ import { useNotificationHandler } from "../../composables/useNotificationHandler.js";
59
+ import { NotificationHandler } from "../../helpers/NotificationHandler.js";
60
+ import { twMerge } from "../../utils/twMerge.js";
59
61
  defineOptions({
60
- name: "lib-notifications",
61
- inheritAttrs: false,
62
- })
63
-
64
-
65
- // eslint-disable-next-line no-use-before-define
66
- const props = defineProps<Props>()
67
-
68
- const dialogEl = ref<HTMLDialogElement | null>(null)
69
-
70
- const isOpen = ref(false)
71
- const notifications = shallowReactive<NotificationEntry[]>([])
72
- const topNotifications = shallowReactive<NotificationEntry[]>([])
62
+ name: "lib-notifications",
63
+ inheritAttrs: false
64
+ });
65
+ const props = defineProps({
66
+ id: { type: String, required: false },
67
+ handler: { type: Object, required: false }
68
+ });
69
+ const dialogEl = ref(null);
70
+ const isOpen = ref(false);
71
+ const notifications = shallowReactive([]);
72
+ const topNotifications = shallowReactive([]);
73
73
  const open = () => {
74
- if (!isOpen.value) {
75
- void nextTick(() => {
76
- dialogEl.value!.showModal()
77
- isOpen.value = true
78
- })
79
- }
80
- }
74
+ if (!isOpen.value) {
75
+ void nextTick(() => {
76
+ dialogEl.value.showModal();
77
+ isOpen.value = true;
78
+ });
79
+ }
80
+ };
81
81
  const close = () => {
82
- if (isOpen.value && topNotifications.length === 0) {
83
- dialogEl.value!.close()
84
- isOpen.value = false
85
- }
82
+ if (isOpen.value && topNotifications.length === 0) {
83
+ dialogEl.value.close();
84
+ isOpen.value = false;
85
+ }
86
+ };
87
+ const addNotification = (entry) => {
88
+ if (entry.resolution === void 0) {
89
+ if (entry.requiresAction) {
90
+ topNotifications.push(entry);
91
+ open();
92
+ entry.promise.then(() => {
93
+ removeIfIn(topNotifications, entry);
94
+ close();
95
+ });
96
+ } else {
97
+ notifications.splice(0, 0, entry);
98
+ entry.promise.then(() => {
99
+ removeIfIn(notifications, entry);
100
+ });
101
+ }
102
+ }
103
+ };
104
+ const notificationListener = (entry, type) => {
105
+ if (type === "added") {
106
+ addNotification(entry);
107
+ }
108
+ };
109
+ const handler = props.handler ?? useNotificationHandler();
110
+ handler.addNotificationListener(notificationListener);
111
+ for (const entry of handler.queue) {
112
+ addNotification(entry);
86
113
  }
87
-
88
- const addNotification = (entry: NotificationEntry) => {
89
- if (entry.resolution === undefined) {
90
- if (entry.requiresAction) {
91
- topNotifications.push(entry)
92
- open()
93
- entry.promise.then(() => {
94
- removeIfIn(topNotifications, entry)
95
- close()
96
- })
97
- } else {
98
- notifications.splice(0, 0, entry)
99
- entry.promise.then(() => {
100
- removeIfIn(notifications, entry)
101
- })
102
- }
103
- }
104
- }
105
-
106
- const notificationListener = (entry: NotificationEntry, type: "added" | "resolved" | "deleted"): void => {
107
- if (type === "added") {
108
- addNotification(entry)
109
- }
110
- }
111
- props.handler.addNotificationListener(notificationListener)
112
-
113
- for (const entry of props.handler.queue) { addNotification(entry) }
114
114
  onBeforeUnmount(() => {
115
- props.handler.removeNotificationListener(notificationListener)
116
- })
117
-
115
+ handler.removeNotificationListener(notificationListener);
116
+ });
118
117
  </script>
119
- <script lang="ts">
120
118
 
121
- type RealProps =
122
- & LinkableByIdProps
123
- & {
124
- handler: NotificationHandler
125
- }
119
+ <script>
126
120
 
127
- interface Props
128
- extends
129
- /** @vue-ignore */
130
- Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
131
- RealProps
132
- {}
133
121
  </script>
@@ -0,0 +1,13 @@
1
+ import { type HTMLAttributes } from "vue";
2
+ import { NotificationHandler } from "../../helpers/NotificationHandler.js.js";
3
+ import type { LinkableByIdProps, TailwindClassProp } from "../shared/props.js.js";
4
+ type RealProps = LinkableByIdProps & {
5
+ /** If not provided, uses the global handler (this requires useNotificationHandler be called and configured). */
6
+ handler?: NotificationHandler;
7
+ };
8
+ interface Props extends
9
+ /** @vue-ignore */
10
+ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
11
+ }
12
+ declare const _default: import("vue").DefineComponent<Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ export default _default;