@proyecto-viviana/solid-stately 0.2.7 → 0.3.0

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 (242) hide show
  1. package/README.md +30 -283
  2. package/dist/autocomplete/createAutocompleteState.d.ts +2 -2
  3. package/dist/autocomplete/index.d.ts +1 -1
  4. package/dist/calendar/createCalendarState.d.ts +22 -7
  5. package/dist/calendar/createDateFieldState.d.ts +30 -7
  6. package/dist/calendar/createDatePickerState.d.ts +60 -0
  7. package/dist/calendar/createRangeCalendarState.d.ts +27 -8
  8. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  9. package/dist/calendar/index.d.ts +7 -6
  10. package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
  11. package/dist/checkbox/index.d.ts +1 -1
  12. package/dist/collections/ListCollection.d.ts +1 -1
  13. package/dist/collections/createListState.d.ts +8 -8
  14. package/dist/collections/createMenuState.d.ts +7 -7
  15. package/dist/collections/createSelectionState.d.ts +5 -5
  16. package/dist/collections/index.d.ts +5 -5
  17. package/dist/collections/types.d.ts +12 -12
  18. package/dist/color/Color.d.ts +1 -1
  19. package/dist/color/createColorAreaState.d.ts +4 -2
  20. package/dist/color/createColorFieldState.d.ts +38 -12
  21. package/dist/color/createColorSliderState.d.ts +9 -2
  22. package/dist/color/createColorWheelState.d.ts +13 -2
  23. package/dist/color/getColorChannels.d.ts +1 -1
  24. package/dist/color/index.d.ts +6 -6
  25. package/dist/color/types.d.ts +4 -4
  26. package/dist/combobox/createComboBoxState.d.ts +27 -13
  27. package/dist/combobox/index.d.ts +1 -1
  28. package/dist/data/createAsyncList.d.ts +4 -4
  29. package/dist/data/createListData.d.ts +2 -2
  30. package/dist/data/createTreeData.d.ts +6 -2
  31. package/dist/data/index.d.ts +3 -3
  32. package/dist/datepicker/index.d.ts +2 -4
  33. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  34. package/dist/disclosure/index.d.ts +1 -1
  35. package/dist/dnd/createDragState.d.ts +2 -2
  36. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  37. package/dist/dnd/createDropState.d.ts +2 -2
  38. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  39. package/dist/dnd/index.d.ts +5 -5
  40. package/dist/dnd/types.d.ts +16 -16
  41. package/dist/form/createFormValidationState.d.ts +3 -3
  42. package/dist/form/index.d.ts +1 -1
  43. package/dist/grid/createGridState.d.ts +2 -2
  44. package/dist/grid/index.d.ts +2 -2
  45. package/dist/grid/types.d.ts +13 -11
  46. package/dist/index.d.ts +31 -30
  47. package/dist/index.js +7924 -7238
  48. package/dist/index.js.map +1 -1
  49. package/dist/menu/index.d.ts +2 -2
  50. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  51. package/dist/numberfield/index.d.ts +1 -1
  52. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  53. package/dist/overlays/index.d.ts +1 -1
  54. package/dist/radio/createRadioGroupState.d.ts +7 -7
  55. package/dist/radio/index.d.ts +1 -1
  56. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  57. package/dist/searchfield/index.d.ts +2 -2
  58. package/dist/select/createSelectState.d.ts +8 -8
  59. package/dist/select/index.d.ts +1 -1
  60. package/dist/selection/index.d.ts +5 -5
  61. package/dist/slider/createSliderState.d.ts +3 -3
  62. package/dist/slider/index.d.ts +2 -2
  63. package/dist/steplist/createStepListState.d.ts +48 -0
  64. package/dist/steplist/index.d.ts +1 -0
  65. package/dist/table/TableCollection.d.ts +3 -3
  66. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  67. package/dist/table/createTableState.d.ts +2 -2
  68. package/dist/table/index.d.ts +5 -3
  69. package/dist/table/types.d.ts +10 -10
  70. package/dist/tabs/createTabListState.d.ts +5 -5
  71. package/dist/tabs/index.d.ts +1 -1
  72. package/dist/textfield/createTextFieldState.d.ts +2 -2
  73. package/dist/textfield/index.d.ts +1 -1
  74. package/dist/toast/createToastState.d.ts +8 -2
  75. package/dist/toast/index.d.ts +1 -1
  76. package/dist/toggle/createToggleGroupState.d.ts +4 -4
  77. package/dist/toggle/createToggleState.d.ts +2 -2
  78. package/dist/toggle/index.d.ts +2 -2
  79. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  80. package/dist/tooltip/index.d.ts +1 -1
  81. package/dist/tree/TreeCollection.d.ts +2 -2
  82. package/dist/tree/createTreeState.d.ts +2 -2
  83. package/dist/tree/index.d.ts +3 -3
  84. package/dist/tree/types.d.ts +19 -13
  85. package/dist/utils/index.d.ts +1 -1
  86. package/dist/utils/reactivity.d.ts +1 -1
  87. package/package.json +29 -30
  88. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  89. package/src/autocomplete/createAutocompleteState.ts +24 -30
  90. package/src/autocomplete/index.d.ts +6 -2
  91. package/src/autocomplete/index.ts +1 -1
  92. package/src/calendar/createCalendarState.d.ts +139 -117
  93. package/src/calendar/createCalendarState.ts +221 -74
  94. package/src/calendar/createDateFieldState.d.ts +130 -95
  95. package/src/calendar/createDateFieldState.ts +263 -151
  96. package/src/calendar/createDatePickerState.ts +347 -0
  97. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  98. package/src/calendar/createRangeCalendarState.ts +293 -79
  99. package/src/calendar/createTimeFieldState.d.ts +81 -79
  100. package/src/calendar/createTimeFieldState.ts +187 -108
  101. package/src/calendar/index.d.ts +80 -7
  102. package/src/calendar/index.ts +21 -12
  103. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  104. package/src/checkbox/createCheckboxGroupState.ts +20 -29
  105. package/src/checkbox/index.d.ts +6 -2
  106. package/src/checkbox/index.ts +1 -1
  107. package/src/collections/ListCollection.d.ts +25 -22
  108. package/src/collections/ListCollection.ts +6 -6
  109. package/src/collections/createListState.d.ts +73 -58
  110. package/src/collections/createListState.ts +19 -18
  111. package/src/collections/createMenuState.d.ts +36 -31
  112. package/src/collections/createMenuState.ts +18 -12
  113. package/src/collections/createSelectionState.d.ts +78 -65
  114. package/src/collections/createSelectionState.ts +36 -32
  115. package/src/collections/index.d.ts +38 -6
  116. package/src/collections/index.ts +5 -10
  117. package/src/collections/types.d.ts +101 -101
  118. package/src/collections/types.ts +12 -12
  119. package/src/color/Color.d.ts +20 -5
  120. package/src/color/Color.ts +357 -254
  121. package/src/color/createColorAreaState.d.ts +67 -65
  122. package/src/color/createColorAreaState.ts +21 -13
  123. package/src/color/createColorFieldState.d.ts +46 -44
  124. package/src/color/createColorFieldState.ts +285 -149
  125. package/src/color/createColorSliderState.d.ts +58 -56
  126. package/src/color/createColorSliderState.ts +45 -14
  127. package/src/color/createColorWheelState.d.ts +42 -40
  128. package/src/color/createColorWheelState.ts +101 -64
  129. package/src/color/getColorChannels.ts +7 -5
  130. package/src/color/index.d.ts +36 -7
  131. package/src/color/index.ts +6 -9
  132. package/src/color/types.d.ts +68 -63
  133. package/src/color/types.ts +11 -19
  134. package/src/combobox/createComboBoxState.d.ts +107 -105
  135. package/src/combobox/createComboBoxState.ts +176 -89
  136. package/src/combobox/index.d.ts +10 -2
  137. package/src/combobox/index.ts +1 -1
  138. package/src/data/createAsyncList.ts +89 -63
  139. package/src/data/createListData.ts +67 -67
  140. package/src/data/createTreeData.ts +304 -91
  141. package/src/data/index.ts +3 -3
  142. package/src/datepicker/index.ts +6 -10
  143. package/src/disclosure/createDisclosureState.d.ts +47 -43
  144. package/src/disclosure/createDisclosureState.ts +7 -21
  145. package/src/disclosure/index.d.ts +10 -2
  146. package/src/disclosure/index.ts +1 -1
  147. package/src/dnd/createDragState.d.ts +51 -42
  148. package/src/dnd/createDragState.ts +12 -14
  149. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  150. package/src/dnd/createDraggableCollectionState.ts +14 -21
  151. package/src/dnd/createDropState.d.ts +64 -45
  152. package/src/dnd/createDropState.ts +22 -32
  153. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  154. package/src/dnd/createDroppableCollectionState.ts +40 -43
  155. package/src/dnd/index.d.ts +54 -6
  156. package/src/dnd/index.ts +5 -18
  157. package/src/dnd/types.d.ts +167 -156
  158. package/src/dnd/types.ts +20 -21
  159. package/src/form/createFormValidationState.d.ts +47 -45
  160. package/src/form/createFormValidationState.ts +30 -63
  161. package/src/form/index.d.ts +16 -2
  162. package/src/form/index.ts +1 -1
  163. package/src/grid/createGridState.d.ts +7 -4
  164. package/src/grid/createGridState.ts +44 -51
  165. package/src/grid/index.d.ts +3 -3
  166. package/src/grid/index.ts +2 -8
  167. package/src/grid/types.d.ts +136 -129
  168. package/src/grid/types.ts +20 -18
  169. package/src/index.d.ts +310 -26
  170. package/src/index.ts +48 -89
  171. package/src/menu/index.ts +2 -4
  172. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  173. package/src/numberfield/createNumberFieldState.ts +26 -31
  174. package/src/numberfield/index.d.ts +6 -2
  175. package/src/numberfield/index.ts +1 -1
  176. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  177. package/src/overlays/createOverlayTriggerState.ts +3 -4
  178. package/src/overlays/index.d.ts +6 -2
  179. package/src/overlays/index.ts +1 -1
  180. package/src/radio/createRadioGroupState.d.ts +54 -52
  181. package/src/radio/createRadioGroupState.ts +27 -29
  182. package/src/radio/index.d.ts +7 -2
  183. package/src/radio/index.ts +1 -1
  184. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  185. package/src/searchfield/createSearchFieldState.ts +5 -11
  186. package/src/searchfield/index.d.ts +3 -3
  187. package/src/searchfield/index.ts +2 -5
  188. package/src/select/createSelectState.d.ts +63 -61
  189. package/src/select/createSelectState.ts +27 -27
  190. package/src/select/index.d.ts +2 -2
  191. package/src/select/index.ts +1 -5
  192. package/src/selection/index.ts +6 -7
  193. package/src/slider/createSliderState.d.ts +60 -60
  194. package/src/slider/createSliderState.ts +55 -33
  195. package/src/slider/index.d.ts +3 -3
  196. package/src/slider/index.ts +2 -6
  197. package/src/ssr/index.d.ts +1 -1
  198. package/src/ssr/index.ts +2 -2
  199. package/src/steplist/createStepListState.ts +191 -0
  200. package/src/steplist/index.ts +5 -0
  201. package/src/table/TableCollection.d.ts +42 -40
  202. package/src/table/TableCollection.ts +61 -64
  203. package/src/table/createTableColumnResizeState.ts +242 -0
  204. package/src/table/createTableState.d.ts +7 -4
  205. package/src/table/createTableState.ts +10 -7
  206. package/src/table/index.d.ts +14 -4
  207. package/src/table/index.ts +10 -3
  208. package/src/table/types.d.ts +98 -92
  209. package/src/table/types.ts +17 -13
  210. package/src/tabs/createTabListState.d.ts +59 -57
  211. package/src/tabs/createTabListState.ts +24 -31
  212. package/src/tabs/index.d.ts +8 -2
  213. package/src/tabs/index.ts +1 -1
  214. package/src/textfield/createTextFieldState.d.ts +16 -14
  215. package/src/textfield/createTextFieldState.ts +7 -18
  216. package/src/textfield/index.d.ts +6 -2
  217. package/src/textfield/index.ts +1 -1
  218. package/src/toast/createToastState.d.ts +92 -86
  219. package/src/toast/createToastState.ts +48 -43
  220. package/src/toast/index.d.ts +12 -2
  221. package/src/toast/index.ts +1 -1
  222. package/src/toggle/createToggleGroupState.ts +11 -21
  223. package/src/toggle/createToggleState.d.ts +19 -19
  224. package/src/toggle/createToggleState.ts +2 -16
  225. package/src/toggle/index.d.ts +2 -2
  226. package/src/toggle/index.ts +2 -6
  227. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  228. package/src/tooltip/createTooltipTriggerState.ts +12 -11
  229. package/src/tooltip/index.d.ts +7 -2
  230. package/src/tooltip/index.ts +1 -1
  231. package/src/tree/TreeCollection.d.ts +26 -23
  232. package/src/tree/TreeCollection.ts +29 -22
  233. package/src/tree/createTreeState.d.ts +7 -4
  234. package/src/tree/createTreeState.ts +39 -41
  235. package/src/tree/index.d.ts +10 -4
  236. package/src/tree/index.ts +3 -3
  237. package/src/tree/types.d.ts +131 -126
  238. package/src/tree/types.ts +22 -13
  239. package/src/utils/index.d.ts +2 -2
  240. package/src/utils/index.ts +1 -1
  241. package/src/utils/reactivity.d.ts +2 -2
  242. package/src/utils/reactivity.ts +3 -3
@@ -6,25 +6,27 @@
6
6
  * This is a port of @react-stately/utils's useControlledState pattern
7
7
  * as used by @react-aria/textfield.
8
8
  */
9
- import { Accessor } from 'solid-js';
10
- import { type MaybeAccessor } from '../utils';
9
+ import { Accessor } from "solid-js";
10
+ import { type MaybeAccessor } from "../utils";
11
11
  export interface TextFieldStateOptions {
12
- /** The current value (controlled). */
13
- value?: string;
14
- /** The default value (uncontrolled). */
15
- defaultValue?: string;
16
- /** Handler that is called when the value changes. */
17
- onChange?: (value: string) => void;
12
+ /** The current value (controlled). */
13
+ value?: string;
14
+ /** The default value (uncontrolled). */
15
+ defaultValue?: string;
16
+ /** Handler that is called when the value changes. */
17
+ onChange?: (value: string) => void;
18
18
  }
19
19
  export interface TextFieldState {
20
- /** The current value of the text field. */
21
- readonly value: Accessor<string>;
22
- /** Sets the value of the text field. */
23
- setValue(value: string): void;
20
+ /** The current value of the text field. */
21
+ readonly value: Accessor<string>;
22
+ /** Sets the value of the text field. */
23
+ setValue(value: string): void;
24
24
  }
25
25
  /**
26
26
  * Provides state management for text input components.
27
27
  * Supports both controlled and uncontrolled modes.
28
28
  */
29
- export declare function createTextFieldState(props?: MaybeAccessor<TextFieldStateOptions>): TextFieldState;
30
- //# sourceMappingURL=createTextFieldState.d.ts.map
29
+ export declare function createTextFieldState(
30
+ props?: MaybeAccessor<TextFieldStateOptions>,
31
+ ): TextFieldState;
32
+ //# sourceMappingURL=createTextFieldState.d.ts.map
@@ -7,12 +7,8 @@
7
7
  * as used by @react-aria/textfield.
8
8
  */
9
9
 
10
- import { createSignal, Accessor } from 'solid-js';
11
- import { type MaybeAccessor, access } from '../utils';
12
-
13
- // ============================================
14
- // TYPES
15
- // ============================================
10
+ import { createSignal, Accessor } from "solid-js";
11
+ import { type MaybeAccessor, access } from "../utils";
16
12
 
17
13
  export interface TextFieldStateOptions {
18
14
  /** The current value (controlled). */
@@ -30,34 +26,27 @@ export interface TextFieldState {
30
26
  setValue(value: string): void;
31
27
  }
32
28
 
33
- // ============================================
34
- // IMPLEMENTATION
35
- // ============================================
36
-
37
29
  /**
38
30
  * Provides state management for text input components.
39
31
  * Supports both controlled and uncontrolled modes.
40
32
  */
41
- export function createTextFieldState(props: MaybeAccessor<TextFieldStateOptions> = {}): TextFieldState {
33
+ export function createTextFieldState(
34
+ props: MaybeAccessor<TextFieldStateOptions> = {},
35
+ ): TextFieldState {
42
36
  const getProps = () => access(props);
43
37
 
44
- // Get initial value
45
38
  const initialProps = getProps();
46
- const initialValue = initialProps.value ?? initialProps.defaultValue ?? '';
39
+ const initialValue = initialProps.value ?? initialProps.defaultValue ?? "";
47
40
 
48
- // Create internal signal for uncontrolled mode
49
41
  const [internalValue, setInternalValue] = createSignal(initialValue);
50
42
 
51
- // Determine if controlled
52
43
  const isControlled = () => getProps().value !== undefined;
53
44
 
54
- // Get current value
55
45
  const value: Accessor<string> = () => {
56
46
  const p = getProps();
57
- return isControlled() ? (p.value ?? '') : internalValue();
47
+ return isControlled() ? (p.value ?? "") : internalValue();
58
48
  };
59
49
 
60
- // Update value
61
50
  function setValue(newValue: string): void {
62
51
  const p = getProps();
63
52
 
@@ -1,2 +1,6 @@
1
- export { createTextFieldState, type TextFieldStateOptions, type TextFieldState, } from './createTextFieldState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createTextFieldState,
3
+ type TextFieldStateOptions,
4
+ type TextFieldState,
5
+ } from "./createTextFieldState";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ export {
2
2
  createTextFieldState,
3
3
  type TextFieldStateOptions,
4
4
  type TextFieldState,
5
- } from './createTextFieldState';
5
+ } from "./createTextFieldState";
@@ -2,71 +2,73 @@
2
2
  * Toast state management for SolidJS
3
3
  * Based on @react-stately/toast useToastState
4
4
  */
5
- import { type Accessor } from 'solid-js';
5
+ import { type Accessor } from "solid-js";
6
6
  export interface ToastOptions {
7
- /** A timeout to automatically close the toast, in milliseconds. */
8
- timeout?: number;
9
- /** The priority of the toast relative to other toasts. */
10
- priority?: number;
11
- /** Handler called when the toast is closed. */
12
- onClose?: () => void;
7
+ /** A timeout to automatically close the toast, in milliseconds. */
8
+ timeout?: number;
9
+ /** The priority of the toast relative to other toasts. */
10
+ priority?: number;
11
+ /** Handler called when the toast is closed. */
12
+ onClose?: () => void;
13
13
  }
14
14
  export interface QueuedToast<T> {
15
- /** The content of the toast. */
16
- content: T;
17
- /** A unique key for the toast. */
18
- key: string;
19
- /** The timer for the toast. */
20
- timer: Timer | null;
21
- /** Whether the toast should be animated. */
22
- animation?: 'entering' | 'exiting' | 'queued';
23
- /** The priority of the toast. */
24
- priority: number;
25
- /** Handler called when the toast is closed. */
26
- onClose?: () => void;
27
- /** The timeout for the toast. */
28
- timeout?: number;
15
+ /** The content of the toast. */
16
+ content: T;
17
+ /** A unique key for the toast. */
18
+ key: string;
19
+ /** The timer for the toast. */
20
+ timer: Timer | null;
21
+ /** Whether the toast should be animated. */
22
+ animation?: "entering" | "exiting" | "queued";
23
+ /** The priority of the toast. */
24
+ priority: number;
25
+ /** Handler called when the toast is closed. */
26
+ onClose?: () => void;
27
+ /** The timeout for the toast. */
28
+ timeout?: number;
29
29
  }
30
30
  export interface ToastQueueOptions {
31
- /** The maximum number of toasts to display at once. */
32
- maxVisibleToasts?: number;
33
- /** Whether toasts should stack (true) or queue (false). */
34
- hasExitAnimation?: boolean;
31
+ /** The maximum number of toasts to display at once. */
32
+ maxVisibleToasts?: number;
33
+ /** Whether toasts should stack (true) or queue (false). */
34
+ hasExitAnimation?: boolean;
35
35
  }
36
36
  export interface ToastStateProps<T> {
37
- /** The toast queue to use. */
38
- queue: ToastQueue<T>;
37
+ /** The toast queue to use. */
38
+ queue: ToastQueue<T>;
39
39
  }
40
40
  export interface ToastState<T> {
41
- /** The currently visible toasts. */
42
- visibleToasts: Accessor<QueuedToast<T>[]>;
43
- /** Adds a toast to the queue. */
44
- add: (content: T, options?: ToastOptions) => string;
45
- /** Closes a toast by key. Starts exit animation if hasExitAnimation is enabled. */
46
- close: (key: string) => void;
47
- /**
48
- * Removes a toast after exit animation completes.
49
- * Call this from the component layer when the CSS exit animation finishes.
50
- */
51
- remove: (key: string) => void;
52
- /** Pauses all toast timers. */
53
- pauseAll: () => void;
54
- /** Resumes all toast timers. */
55
- resumeAll: () => void;
41
+ /** The currently visible toasts. */
42
+ visibleToasts: Accessor<QueuedToast<T>[]>;
43
+ /** Adds a toast to the queue. */
44
+ add: (content: T, options?: ToastOptions) => string;
45
+ /** Closes a toast by key. Starts exit animation if hasExitAnimation is enabled. */
46
+ close: (key: string) => void;
47
+ /**
48
+ * Removes a toast after exit animation completes.
49
+ * Call this from the component layer when the CSS exit animation finishes.
50
+ */
51
+ remove: (key: string) => void;
52
+ /** Clears all queued and visible toasts. */
53
+ clear: () => void;
54
+ /** Pauses all toast timers. */
55
+ pauseAll: () => void;
56
+ /** Resumes all toast timers. */
57
+ resumeAll: () => void;
56
58
  }
57
59
  /**
58
60
  * A Timer that supports pause and resume.
59
61
  */
60
62
  export declare class Timer {
61
- private timerId;
62
- private startTime;
63
- private remaining;
64
- private callback;
65
- constructor(callback: () => void, delay: number);
66
- pause(): void;
67
- resume(): void;
68
- reset(delay: number): void;
69
- cancel(): void;
63
+ private timerId;
64
+ private startTime;
65
+ private remaining;
66
+ private callback;
67
+ constructor(callback: () => void, delay: number);
68
+ pause(): void;
69
+ resume(): void;
70
+ reset(delay: number): void;
71
+ cancel(): void;
70
72
  }
71
73
  type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
72
74
  /**
@@ -74,38 +76,42 @@ type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
74
76
  * Can be created once and shared across the app (singleton pattern).
75
77
  */
76
78
  export declare class ToastQueue<T> {
77
- private queue;
78
- private subscriptions;
79
- private maxVisibleToasts;
80
- private hasExitAnimation;
81
- private keyCounter;
82
- constructor(options?: ToastQueueOptions);
83
- /**
84
- * Subscribe to queue changes.
85
- */
86
- subscribe(callback: SubscribeCallback<T>): () => void;
87
- /**
88
- * Add a toast to the queue.
89
- */
90
- add(content: T, options?: ToastOptions): string;
91
- /**
92
- * Close a toast by key.
93
- */
94
- close(key: string): void;
95
- /**
96
- * Remove a toast after exit animation completes.
97
- */
98
- remove(key: string): void;
99
- /**
100
- * Pause all toast timers.
101
- */
102
- pauseAll(): void;
103
- /**
104
- * Resume all toast timers.
105
- */
106
- resumeAll(): void;
107
- private updateVisibility;
108
- private notify;
79
+ private queue;
80
+ private subscriptions;
81
+ private maxVisibleToasts;
82
+ private hasExitAnimation;
83
+ private keyCounter;
84
+ constructor(options?: ToastQueueOptions);
85
+ /**
86
+ * Subscribe to queue changes.
87
+ */
88
+ subscribe(callback: SubscribeCallback<T>): () => void;
89
+ /**
90
+ * Add a toast to the queue.
91
+ */
92
+ add(content: T, options?: ToastOptions): string;
93
+ /**
94
+ * Close a toast by key.
95
+ */
96
+ close(key: string): void;
97
+ /**
98
+ * Remove a toast after exit animation completes.
99
+ */
100
+ remove(key: string): void;
101
+ /**
102
+ * Clear all queued and visible toasts.
103
+ */
104
+ clear(): void;
105
+ /**
106
+ * Pause all toast timers.
107
+ */
108
+ pauseAll(): void;
109
+ /**
110
+ * Resume all toast timers.
111
+ */
112
+ resumeAll(): void;
113
+ private updateVisibility;
114
+ private notify;
109
115
  }
110
116
  /**
111
117
  * Creates reactive toast state from a ToastQueue.
@@ -117,7 +123,7 @@ export declare function createToastState<T>(props: ToastStateProps<T>): ToastSta
117
123
  * Use this if you don't need a global queue.
118
124
  */
119
125
  export declare function createToastQueue<T>(options?: ToastQueueOptions): ToastState<T> & {
120
- queue: ToastQueue<T>;
126
+ queue: ToastQueue<T>;
121
127
  };
122
- export {};
123
- //# sourceMappingURL=createToastState.d.ts.map
128
+
129
+ //# sourceMappingURL=createToastState.d.ts.map
@@ -3,11 +3,7 @@
3
3
  * Based on @react-stately/toast useToastState
4
4
  */
5
5
 
6
- import { createSignal, onCleanup, type Accessor } from 'solid-js';
7
-
8
- // ============================================
9
- // TYPES
10
- // ============================================
6
+ import { createSignal, onCleanup, type Accessor } from "solid-js";
11
7
 
12
8
  export interface ToastOptions {
13
9
  /** A timeout to automatically close the toast, in milliseconds. */
@@ -26,7 +22,7 @@ export interface QueuedToast<T> {
26
22
  /** The timer for the toast. */
27
23
  timer: Timer | null;
28
24
  /** Whether the toast should be animated. */
29
- animation?: 'entering' | 'exiting' | 'queued';
25
+ animation?: "entering" | "exiting" | "queued";
30
26
  /** The priority of the toast. */
31
27
  priority: number;
32
28
  /** Handler called when the toast is closed. */
@@ -60,16 +56,14 @@ export interface ToastState<T> {
60
56
  * If hasExitAnimation is false, close() removes immediately and this is not needed.
61
57
  */
62
58
  remove: (key: string) => void;
59
+ /** Clears all queued and visible toasts. */
60
+ clear: () => void;
63
61
  /** Pauses all toast timers. */
64
62
  pauseAll: () => void;
65
63
  /** Resumes all toast timers. */
66
64
  resumeAll: () => void;
67
65
  }
68
66
 
69
- // ============================================
70
- // TIMER CLASS
71
- // ============================================
72
-
73
67
  /**
74
68
  * A Timer that supports pause and resume.
75
69
  */
@@ -119,10 +113,6 @@ export class Timer {
119
113
  }
120
114
  }
121
115
 
122
- // ============================================
123
- // TOAST QUEUE CLASS
124
- // ============================================
125
-
126
116
  type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
127
117
 
128
118
  /**
@@ -164,7 +154,7 @@ export class ToastQueue<T> {
164
154
  priority: options.priority ?? 0,
165
155
  onClose: options.onClose,
166
156
  timeout: options.timeout,
167
- animation: 'entering',
157
+ animation: "entering",
168
158
  };
169
159
 
170
160
  // Find insertion point based on priority
@@ -172,7 +162,7 @@ export class ToastQueue<T> {
172
162
  let high = this.queue.length;
173
163
  while (low < high) {
174
164
  const mid = Math.floor((low + high) / 2);
175
- if (toast.priority > this.queue[mid].priority) {
165
+ if (toast.priority >= this.queue[mid].priority) {
176
166
  high = mid;
177
167
  } else {
178
168
  low = mid + 1;
@@ -180,11 +170,7 @@ export class ToastQueue<T> {
180
170
  }
181
171
 
182
172
  // Insert at the correct position
183
- this.queue = [
184
- ...this.queue.slice(0, low),
185
- toast,
186
- ...this.queue.slice(low),
187
- ];
173
+ this.queue = [...this.queue.slice(0, low), toast, ...this.queue.slice(low)];
188
174
 
189
175
  // Start timer for visible toasts
190
176
  this.updateVisibility();
@@ -201,11 +187,12 @@ export class ToastQueue<T> {
201
187
 
202
188
  // Cancel any existing timer
203
189
  toast.timer?.cancel();
204
- toast.timer = null;
205
190
 
206
- if (this.hasExitAnimation && toast.animation !== 'queued') {
191
+ if (this.hasExitAnimation && toast.animation !== "queued") {
207
192
  // Mark as exiting for animation
208
- toast.animation = 'exiting';
193
+ this.queue = this.queue.map((t) =>
194
+ t.key === key ? { ...t, timer: null, animation: "exiting" } : t,
195
+ );
209
196
  this.notify();
210
197
  } else {
211
198
  // Remove immediately
@@ -227,6 +214,18 @@ export class ToastQueue<T> {
227
214
  this.updateVisibility();
228
215
  }
229
216
 
217
+ /**
218
+ * Clear all queued and visible toasts.
219
+ */
220
+ clear(): void {
221
+ for (const toast of this.queue) {
222
+ toast.timer?.cancel();
223
+ }
224
+
225
+ this.queue = [];
226
+ this.notify();
227
+ }
228
+
230
229
  /**
231
230
  * Pause all toast timers.
232
231
  */
@@ -248,24 +247,35 @@ export class ToastQueue<T> {
248
247
  private updateVisibility(): void {
249
248
  // Mark toasts as visible or queued based on maxVisibleToasts
250
249
  const visibleCount = this.queue.filter(
251
- (t) => t.animation !== 'queued' && t.animation !== 'exiting'
250
+ (t) => t.animation !== "queued" && t.animation !== "exiting",
252
251
  ).length;
253
252
 
254
253
  let promoted = 0;
255
- for (const toast of this.queue) {
256
- if (toast.animation === 'queued' && visibleCount + promoted < this.maxVisibleToasts) {
257
- toast.animation = 'entering';
254
+ this.queue = this.queue.map((toast) => {
255
+ let nextToast = toast;
256
+
257
+ if (nextToast.animation === "queued" && visibleCount + promoted < this.maxVisibleToasts) {
258
+ nextToast = { ...nextToast, animation: "entering" };
258
259
  promoted++;
259
260
  }
260
- if (toast.animation === 'queued') continue;
261
+ if (nextToast.animation === "queued") return nextToast;
261
262
 
262
263
  // Start timer for visible toasts
263
- if (toast.timeout != null && toast.timer === null && toast.animation !== 'exiting') {
264
- toast.timer = new Timer(() => {
265
- this.close(toast.key);
266
- }, toast.timeout);
264
+ if (
265
+ nextToast.timeout != null &&
266
+ nextToast.timer === null &&
267
+ nextToast.animation !== "exiting"
268
+ ) {
269
+ nextToast = {
270
+ ...nextToast,
271
+ timer: new Timer(() => {
272
+ this.close(nextToast.key);
273
+ }, nextToast.timeout),
274
+ };
267
275
  }
268
- }
276
+
277
+ return nextToast;
278
+ });
269
279
 
270
280
  this.notify();
271
281
  }
@@ -278,10 +288,6 @@ export class ToastQueue<T> {
278
288
  }
279
289
  }
280
290
 
281
- // ============================================
282
- // HOOK
283
- // ============================================
284
-
285
291
  /**
286
292
  * Creates reactive toast state from a ToastQueue.
287
293
  * Use this hook to subscribe to toast changes in your component.
@@ -303,20 +309,19 @@ export function createToastState<T>(props: ToastStateProps<T>): ToastState<T> {
303
309
  add: (content, options) => props.queue.add(content, options),
304
310
  close: (key) => props.queue.close(key),
305
311
  remove: (key) => props.queue.remove(key),
312
+ clear: () => props.queue.clear(),
306
313
  pauseAll: () => props.queue.pauseAll(),
307
314
  resumeAll: () => props.queue.resumeAll(),
308
315
  };
309
316
  }
310
317
 
311
- // ============================================
312
- // CONVENIENCE HOOKS
313
- // ============================================
314
-
315
318
  /**
316
319
  * Creates a new ToastQueue and returns reactive state.
317
320
  * Use this if you don't need a global queue.
318
321
  */
319
- export function createToastQueue<T>(options?: ToastQueueOptions): ToastState<T> & { queue: ToastQueue<T> } {
322
+ export function createToastQueue<T>(
323
+ options?: ToastQueueOptions,
324
+ ): ToastState<T> & { queue: ToastQueue<T> } {
320
325
  const queue = new ToastQueue<T>(options);
321
326
  const state = createToastState({ queue });
322
327
  return { ...state, queue };
@@ -1,2 +1,12 @@
1
- export { createToastState, createToastQueue, ToastQueue, Timer, type ToastOptions, type QueuedToast, type ToastQueueOptions, type ToastStateProps, type ToastState, } from './createToastState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createToastState,
3
+ createToastQueue,
4
+ ToastQueue,
5
+ Timer,
6
+ type ToastOptions,
7
+ type QueuedToast,
8
+ type ToastQueueOptions,
9
+ type ToastStateProps,
10
+ type ToastState,
11
+ } from "./createToastState";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -8,4 +8,4 @@ export {
8
8
  type ToastQueueOptions,
9
9
  type ToastStateProps,
10
10
  type ToastState,
11
- } from './createToastState';
11
+ } from "./createToastState";
@@ -7,20 +7,16 @@
7
7
  * This is a port of @react-stately/toggle's useToggleGroupState.
8
8
  */
9
9
 
10
- import { createSignal } from 'solid-js';
11
- import type { Key } from '../collections';
12
- import { type MaybeAccessor, access } from '../utils';
13
-
14
- // ============================================
15
- // TYPES
16
- // ============================================
10
+ import { createSignal } from "solid-js";
11
+ import type { Key } from "../collections";
12
+ import { type MaybeAccessor, access } from "../utils";
17
13
 
18
14
  export interface ToggleGroupProps {
19
15
  /**
20
16
  * Whether single or multiple selection is enabled.
21
17
  * @default 'single'
22
18
  */
23
- selectionMode?: 'single' | 'multiple';
19
+ selectionMode?: "single" | "multiple";
24
20
  /** Whether empty selection is disallowed. */
25
21
  disallowEmptySelection?: boolean;
26
22
  /** Controlled selected keys. */
@@ -35,7 +31,7 @@ export interface ToggleGroupProps {
35
31
 
36
32
  export interface ToggleGroupState {
37
33
  /** Whether single or multiple selection is enabled. */
38
- readonly selectionMode: 'single' | 'multiple';
34
+ readonly selectionMode: "single" | "multiple";
39
35
  /** Whether all items are disabled. */
40
36
  readonly isDisabled: boolean;
41
37
  /** Current selected keys. */
@@ -52,21 +48,17 @@ function toKeySet(keys?: Iterable<Key>): Set<Key> {
52
48
  return new Set(keys ? Array.from(keys) : []);
53
49
  }
54
50
 
55
- // ============================================
56
- // IMPLEMENTATION
57
- // ============================================
58
-
59
51
  /**
60
52
  * Manages state for a group of toggle buttons.
61
53
  */
62
54
  export function createToggleGroupState(
63
- props: MaybeAccessor<ToggleGroupProps> = {}
55
+ props: MaybeAccessor<ToggleGroupProps> = {},
64
56
  ): ToggleGroupState {
65
57
  const getProps = () => access(props);
66
58
 
67
59
  const initialProps = getProps();
68
60
  const [internalSelectedKeys, setInternalSelectedKeys] = createSignal<Set<Key>>(
69
- toKeySet(initialProps.defaultSelectedKeys)
61
+ toKeySet(initialProps.defaultSelectedKeys),
70
62
  );
71
63
 
72
64
  const isControlled = () => getProps().selectedKeys !== undefined;
@@ -83,12 +75,12 @@ export function createToggleGroupState(
83
75
 
84
76
  function toggleKey(key: Key): void {
85
77
  const props = getProps();
86
- const mode = props.selectionMode ?? 'single';
78
+ const mode = props.selectionMode ?? "single";
87
79
  const disallowEmptySelection = props.disallowEmptySelection ?? false;
88
80
  const currentKeys = selectedKeys();
89
81
 
90
82
  let nextKeys: Set<Key>;
91
- if (mode === 'multiple') {
83
+ if (mode === "multiple") {
92
84
  nextKeys = new Set(currentKeys);
93
85
  if (nextKeys.has(key) && (!disallowEmptySelection || nextKeys.size > 1)) {
94
86
  nextKeys.delete(key);
@@ -96,9 +88,7 @@ export function createToggleGroupState(
96
88
  nextKeys.add(key);
97
89
  }
98
90
  } else {
99
- nextKeys = new Set(
100
- currentKeys.has(key) && !disallowEmptySelection ? [] : [key]
101
- );
91
+ nextKeys = new Set(currentKeys.has(key) && !disallowEmptySelection ? [] : [key]);
102
92
  }
103
93
 
104
94
  setSelectedKeys(nextKeys);
@@ -112,7 +102,7 @@ export function createToggleGroupState(
112
102
 
113
103
  return {
114
104
  get selectionMode() {
115
- return getProps().selectionMode ?? 'single';
105
+ return getProps().selectionMode ?? "single";
116
106
  },
117
107
  get isDisabled() {
118
108
  return getProps().isDisabled ?? false;