@proyecto-viviana/solid-stately 0.2.7 → 0.4.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 (254) 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/IncompleteDate.d.ts +61 -0
  5. package/dist/calendar/createCalendarState.d.ts +41 -16
  6. package/dist/calendar/createDateFieldState.d.ts +39 -9
  7. package/dist/calendar/createDatePickerState.d.ts +60 -0
  8. package/dist/calendar/createRangeCalendarState.d.ts +37 -10
  9. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  10. package/dist/calendar/index.d.ts +7 -6
  11. package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
  12. package/dist/checkbox/index.d.ts +1 -1
  13. package/dist/collections/ListCollection.d.ts +1 -1
  14. package/dist/collections/createListState.d.ts +11 -8
  15. package/dist/collections/createMenuState.d.ts +7 -7
  16. package/dist/collections/createSelectionState.d.ts +22 -10
  17. package/dist/collections/getChildNodes.d.ts +11 -0
  18. package/dist/collections/index.d.ts +6 -5
  19. package/dist/collections/types.d.ts +12 -12
  20. package/dist/color/Color.d.ts +1 -1
  21. package/dist/color/createColorAreaState.d.ts +4 -2
  22. package/dist/color/createColorFieldState.d.ts +38 -12
  23. package/dist/color/createColorSliderState.d.ts +9 -2
  24. package/dist/color/createColorWheelState.d.ts +13 -2
  25. package/dist/color/getColorChannels.d.ts +1 -1
  26. package/dist/color/index.d.ts +6 -6
  27. package/dist/color/types.d.ts +4 -4
  28. package/dist/combobox/createComboBoxState.d.ts +34 -13
  29. package/dist/combobox/index.d.ts +1 -1
  30. package/dist/data/createAsyncList.d.ts +4 -4
  31. package/dist/data/createListData.d.ts +2 -2
  32. package/dist/data/createTreeData.d.ts +6 -2
  33. package/dist/data/index.d.ts +3 -3
  34. package/dist/datepicker/index.d.ts +2 -4
  35. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  36. package/dist/disclosure/index.d.ts +1 -1
  37. package/dist/dnd/createDragState.d.ts +2 -2
  38. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  39. package/dist/dnd/createDropState.d.ts +2 -2
  40. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  41. package/dist/dnd/index.d.ts +5 -5
  42. package/dist/dnd/types.d.ts +19 -17
  43. package/dist/form/createFormValidationState.d.ts +3 -3
  44. package/dist/form/index.d.ts +1 -1
  45. package/dist/grid/createGridState.d.ts +2 -2
  46. package/dist/grid/index.d.ts +2 -2
  47. package/dist/grid/types.d.ts +27 -11
  48. package/dist/index.d.ts +31 -30
  49. package/dist/index.js +9077 -7246
  50. package/dist/index.js.map +1 -1
  51. package/dist/menu/index.d.ts +2 -2
  52. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  53. package/dist/numberfield/index.d.ts +1 -1
  54. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  55. package/dist/overlays/index.d.ts +1 -1
  56. package/dist/radio/createRadioGroupState.d.ts +7 -7
  57. package/dist/radio/index.d.ts +1 -1
  58. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  59. package/dist/searchfield/index.d.ts +2 -2
  60. package/dist/select/createSelectState.d.ts +14 -8
  61. package/dist/select/index.d.ts +1 -1
  62. package/dist/selection/Selection.d.ts +16 -0
  63. package/dist/selection/SelectionManager.d.ts +110 -0
  64. package/dist/selection/createMultipleSelectionState.d.ts +59 -0
  65. package/dist/selection/index.d.ts +6 -5
  66. package/dist/slider/createSliderState.d.ts +3 -3
  67. package/dist/slider/index.d.ts +2 -2
  68. package/dist/steplist/createStepListState.d.ts +48 -0
  69. package/dist/steplist/index.d.ts +1 -0
  70. package/dist/table/TableCollection.d.ts +33 -3
  71. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  72. package/dist/table/createTableState.d.ts +2 -2
  73. package/dist/table/createTreeGridState.d.ts +15 -0
  74. package/dist/table/index.d.ts +6 -3
  75. package/dist/table/types.d.ts +68 -10
  76. package/dist/tabs/createTabListState.d.ts +5 -5
  77. package/dist/tabs/index.d.ts +1 -1
  78. package/dist/textfield/createTextFieldState.d.ts +2 -2
  79. package/dist/textfield/index.d.ts +1 -1
  80. package/dist/toast/createToastState.d.ts +24 -2
  81. package/dist/toast/index.d.ts +1 -1
  82. package/dist/toggle/createToggleGroupState.d.ts +4 -4
  83. package/dist/toggle/createToggleState.d.ts +2 -2
  84. package/dist/toggle/index.d.ts +2 -2
  85. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  86. package/dist/tooltip/index.d.ts +1 -1
  87. package/dist/tree/TreeCollection.d.ts +2 -2
  88. package/dist/tree/createTreeState.d.ts +2 -2
  89. package/dist/tree/index.d.ts +3 -3
  90. package/dist/tree/types.d.ts +27 -13
  91. package/dist/utils/index.d.ts +1 -1
  92. package/dist/utils/reactivity.d.ts +1 -1
  93. package/package.json +29 -30
  94. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  95. package/src/autocomplete/createAutocompleteState.ts +24 -30
  96. package/src/autocomplete/index.d.ts +6 -2
  97. package/src/autocomplete/index.ts +1 -1
  98. package/src/calendar/IncompleteDate.ts +430 -0
  99. package/src/calendar/createCalendarState.d.ts +139 -117
  100. package/src/calendar/createCalendarState.ts +308 -94
  101. package/src/calendar/createDateFieldState.d.ts +130 -95
  102. package/src/calendar/createDateFieldState.ts +447 -334
  103. package/src/calendar/createDatePickerState.ts +347 -0
  104. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  105. package/src/calendar/createRangeCalendarState.ts +411 -85
  106. package/src/calendar/createTimeFieldState.d.ts +81 -79
  107. package/src/calendar/createTimeFieldState.ts +187 -108
  108. package/src/calendar/index.d.ts +80 -7
  109. package/src/calendar/index.ts +23 -12
  110. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  111. package/src/checkbox/createCheckboxGroupState.ts +20 -29
  112. package/src/checkbox/index.d.ts +6 -2
  113. package/src/checkbox/index.ts +1 -1
  114. package/src/collections/ListCollection.d.ts +25 -22
  115. package/src/collections/ListCollection.ts +6 -6
  116. package/src/collections/createListState.d.ts +73 -58
  117. package/src/collections/createListState.ts +67 -35
  118. package/src/collections/createMenuState.d.ts +36 -31
  119. package/src/collections/createMenuState.ts +21 -12
  120. package/src/collections/createSelectionState.d.ts +78 -65
  121. package/src/collections/createSelectionState.ts +66 -52
  122. package/src/collections/getChildNodes.ts +98 -0
  123. package/src/collections/index.d.ts +38 -6
  124. package/src/collections/index.ts +14 -10
  125. package/src/collections/types.d.ts +101 -101
  126. package/src/collections/types.ts +12 -12
  127. package/src/color/Color.d.ts +20 -5
  128. package/src/color/Color.ts +357 -254
  129. package/src/color/createColorAreaState.d.ts +67 -65
  130. package/src/color/createColorAreaState.ts +21 -13
  131. package/src/color/createColorFieldState.d.ts +46 -44
  132. package/src/color/createColorFieldState.ts +285 -149
  133. package/src/color/createColorSliderState.d.ts +58 -56
  134. package/src/color/createColorSliderState.ts +45 -14
  135. package/src/color/createColorWheelState.d.ts +42 -40
  136. package/src/color/createColorWheelState.ts +101 -64
  137. package/src/color/getColorChannels.ts +7 -5
  138. package/src/color/index.d.ts +36 -7
  139. package/src/color/index.ts +6 -9
  140. package/src/color/types.d.ts +68 -63
  141. package/src/color/types.ts +11 -19
  142. package/src/combobox/createComboBoxState.d.ts +107 -105
  143. package/src/combobox/createComboBoxState.ts +184 -89
  144. package/src/combobox/index.d.ts +10 -2
  145. package/src/combobox/index.ts +1 -1
  146. package/src/data/createAsyncList.ts +89 -63
  147. package/src/data/createListData.ts +67 -67
  148. package/src/data/createTreeData.ts +304 -91
  149. package/src/data/index.ts +3 -3
  150. package/src/datepicker/index.ts +6 -10
  151. package/src/disclosure/createDisclosureState.d.ts +47 -43
  152. package/src/disclosure/createDisclosureState.ts +7 -21
  153. package/src/disclosure/index.d.ts +10 -2
  154. package/src/disclosure/index.ts +1 -1
  155. package/src/dnd/createDragState.d.ts +51 -42
  156. package/src/dnd/createDragState.ts +12 -14
  157. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  158. package/src/dnd/createDraggableCollectionState.ts +14 -21
  159. package/src/dnd/createDropState.d.ts +64 -45
  160. package/src/dnd/createDropState.ts +22 -32
  161. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  162. package/src/dnd/createDroppableCollectionState.ts +40 -43
  163. package/src/dnd/index.d.ts +55 -6
  164. package/src/dnd/index.ts +6 -18
  165. package/src/dnd/types.d.ts +170 -157
  166. package/src/dnd/types.ts +24 -22
  167. package/src/form/createFormValidationState.d.ts +47 -45
  168. package/src/form/createFormValidationState.ts +30 -63
  169. package/src/form/index.d.ts +16 -2
  170. package/src/form/index.ts +1 -1
  171. package/src/grid/createGridState.d.ts +7 -4
  172. package/src/grid/createGridState.ts +78 -51
  173. package/src/grid/index.d.ts +3 -3
  174. package/src/grid/index.ts +2 -8
  175. package/src/grid/types.d.ts +136 -129
  176. package/src/grid/types.ts +34 -18
  177. package/src/index.d.ts +311 -26
  178. package/src/index.ts +59 -89
  179. package/src/menu/index.ts +2 -4
  180. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  181. package/src/numberfield/createNumberFieldState.ts +26 -31
  182. package/src/numberfield/index.d.ts +6 -2
  183. package/src/numberfield/index.ts +1 -1
  184. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  185. package/src/overlays/createOverlayTriggerState.ts +3 -4
  186. package/src/overlays/index.d.ts +6 -2
  187. package/src/overlays/index.ts +1 -1
  188. package/src/radio/createRadioGroupState.d.ts +54 -52
  189. package/src/radio/createRadioGroupState.ts +27 -29
  190. package/src/radio/index.d.ts +7 -2
  191. package/src/radio/index.ts +1 -1
  192. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  193. package/src/searchfield/createSearchFieldState.ts +5 -11
  194. package/src/searchfield/index.d.ts +3 -3
  195. package/src/searchfield/index.ts +2 -5
  196. package/src/select/createSelectState.d.ts +63 -61
  197. package/src/select/createSelectState.ts +42 -29
  198. package/src/select/index.d.ts +2 -2
  199. package/src/select/index.ts +1 -5
  200. package/src/selection/Selection.ts +28 -0
  201. package/src/selection/SelectionManager.ts +526 -0
  202. package/src/selection/createMultipleSelectionState.ts +247 -0
  203. package/src/selection/index.ts +12 -7
  204. package/src/slider/createSliderState.d.ts +60 -60
  205. package/src/slider/createSliderState.ts +55 -33
  206. package/src/slider/index.d.ts +3 -3
  207. package/src/slider/index.ts +2 -6
  208. package/src/ssr/index.d.ts +1 -1
  209. package/src/ssr/index.ts +2 -2
  210. package/src/steplist/createStepListState.ts +191 -0
  211. package/src/steplist/index.ts +5 -0
  212. package/src/table/TableCollection.d.ts +42 -40
  213. package/src/table/TableCollection.ts +266 -99
  214. package/src/table/createTableColumnResizeState.ts +242 -0
  215. package/src/table/createTableState.d.ts +7 -4
  216. package/src/table/createTableState.ts +30 -7
  217. package/src/table/createTreeGridState.ts +146 -0
  218. package/src/table/index.d.ts +14 -4
  219. package/src/table/index.ts +13 -3
  220. package/src/table/types.d.ts +98 -92
  221. package/src/table/types.ts +83 -13
  222. package/src/tabs/createTabListState.d.ts +59 -57
  223. package/src/tabs/createTabListState.ts +34 -39
  224. package/src/tabs/index.d.ts +8 -2
  225. package/src/tabs/index.ts +1 -1
  226. package/src/textfield/createTextFieldState.d.ts +16 -14
  227. package/src/textfield/createTextFieldState.ts +7 -18
  228. package/src/textfield/index.d.ts +6 -2
  229. package/src/textfield/index.ts +1 -1
  230. package/src/toast/createToastState.d.ts +92 -86
  231. package/src/toast/createToastState.ts +90 -52
  232. package/src/toast/index.d.ts +12 -2
  233. package/src/toast/index.ts +2 -1
  234. package/src/toggle/createToggleGroupState.ts +11 -21
  235. package/src/toggle/createToggleState.d.ts +19 -19
  236. package/src/toggle/createToggleState.ts +2 -16
  237. package/src/toggle/index.d.ts +2 -2
  238. package/src/toggle/index.ts +2 -6
  239. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  240. package/src/tooltip/createTooltipTriggerState.ts +12 -11
  241. package/src/tooltip/index.d.ts +7 -2
  242. package/src/tooltip/index.ts +1 -1
  243. package/src/tree/TreeCollection.d.ts +26 -23
  244. package/src/tree/TreeCollection.ts +29 -22
  245. package/src/tree/createTreeState.d.ts +7 -4
  246. package/src/tree/createTreeState.ts +70 -41
  247. package/src/tree/index.d.ts +10 -4
  248. package/src/tree/index.ts +3 -3
  249. package/src/tree/types.d.ts +131 -126
  250. package/src/tree/types.ts +30 -13
  251. package/src/utils/index.d.ts +2 -2
  252. package/src/utils/index.ts +1 -1
  253. package/src/utils/reactivity.d.ts +2 -2
  254. package/src/utils/reactivity.ts +3 -3
@@ -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. */
@@ -35,11 +31,20 @@ export interface QueuedToast<T> {
35
31
  timeout?: number;
36
32
  }
37
33
 
34
+ /** The kind of queue mutation that triggered a notification, passed to `wrapUpdate`. */
35
+ export type ToastAction = "add" | "remove" | "clear";
36
+
38
37
  export interface ToastQueueOptions {
39
38
  /** The maximum number of toasts to display at once. */
40
39
  maxVisibleToasts?: number;
41
40
  /** Whether toasts should stack (true) or queue (false). */
42
41
  hasExitAnimation?: boolean;
42
+ /**
43
+ * Wraps each update to the visible toasts (e.g. in `document.startViewTransition()`),
44
+ * so the resulting re-render can be animated. Receives the action that triggered the
45
+ * update. Mirrors `@react-stately/toast`'s `wrapUpdate`.
46
+ */
47
+ wrapUpdate?: (fn: () => void, action: ToastAction) => void;
43
48
  }
44
49
 
45
50
  export interface ToastStateProps<T> {
@@ -60,16 +65,14 @@ export interface ToastState<T> {
60
65
  * If hasExitAnimation is false, close() removes immediately and this is not needed.
61
66
  */
62
67
  remove: (key: string) => void;
68
+ /** Clears all queued and visible toasts. */
69
+ clear: () => void;
63
70
  /** Pauses all toast timers. */
64
71
  pauseAll: () => void;
65
72
  /** Resumes all toast timers. */
66
73
  resumeAll: () => void;
67
74
  }
68
75
 
69
- // ============================================
70
- // TIMER CLASS
71
- // ============================================
72
-
73
76
  /**
74
77
  * A Timer that supports pause and resume.
75
78
  */
@@ -119,10 +122,6 @@ export class Timer {
119
122
  }
120
123
  }
121
124
 
122
- // ============================================
123
- // TOAST QUEUE CLASS
124
- // ============================================
125
-
126
125
  type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
127
126
 
128
127
  /**
@@ -135,10 +134,29 @@ export class ToastQueue<T> {
135
134
  private maxVisibleToasts: number;
136
135
  private hasExitAnimation: boolean;
137
136
  private keyCounter = 0;
137
+ private wrapUpdate?: (fn: () => void, action: ToastAction) => void;
138
138
 
139
139
  constructor(options: ToastQueueOptions = {}) {
140
140
  this.maxVisibleToasts = options.maxVisibleToasts ?? 5;
141
141
  this.hasExitAnimation = options.hasExitAnimation ?? false;
142
+ this.wrapUpdate = options.wrapUpdate;
143
+ }
144
+
145
+ /**
146
+ * Installs (or clears) the function that wraps visible-toast updates, so the
147
+ * resulting re-render can be animated. Used to attach `document.startViewTransition`
148
+ * to a shared queue (e.g. the global queue) after construction.
149
+ */
150
+ setWrapUpdate(wrapUpdate?: (fn: () => void, action: ToastAction) => void): void {
151
+ this.wrapUpdate = wrapUpdate;
152
+ }
153
+
154
+ private runWithWrapUpdate(fn: () => void, action: ToastAction): void {
155
+ if (this.wrapUpdate) {
156
+ this.wrapUpdate(fn, action);
157
+ } else {
158
+ fn();
159
+ }
142
160
  }
143
161
 
144
162
  /**
@@ -164,7 +182,7 @@ export class ToastQueue<T> {
164
182
  priority: options.priority ?? 0,
165
183
  onClose: options.onClose,
166
184
  timeout: options.timeout,
167
- animation: 'entering',
185
+ animation: "entering",
168
186
  };
169
187
 
170
188
  // Find insertion point based on priority
@@ -172,7 +190,7 @@ export class ToastQueue<T> {
172
190
  let high = this.queue.length;
173
191
  while (low < high) {
174
192
  const mid = Math.floor((low + high) / 2);
175
- if (toast.priority > this.queue[mid].priority) {
193
+ if (toast.priority >= this.queue[mid].priority) {
176
194
  high = mid;
177
195
  } else {
178
196
  low = mid + 1;
@@ -180,14 +198,10 @@ export class ToastQueue<T> {
180
198
  }
181
199
 
182
200
  // Insert at the correct position
183
- this.queue = [
184
- ...this.queue.slice(0, low),
185
- toast,
186
- ...this.queue.slice(low),
187
- ];
201
+ this.queue = [...this.queue.slice(0, low), toast, ...this.queue.slice(low)];
188
202
 
189
203
  // Start timer for visible toasts
190
- this.updateVisibility();
204
+ this.updateVisibility("add");
191
205
 
192
206
  return key;
193
207
  }
@@ -201,12 +215,13 @@ export class ToastQueue<T> {
201
215
 
202
216
  // Cancel any existing timer
203
217
  toast.timer?.cancel();
204
- toast.timer = null;
205
218
 
206
- if (this.hasExitAnimation && toast.animation !== 'queued') {
219
+ if (this.hasExitAnimation && toast.animation !== "queued") {
207
220
  // Mark as exiting for animation
208
- toast.animation = 'exiting';
209
- this.notify();
221
+ this.queue = this.queue.map((t) =>
222
+ t.key === key ? { ...t, timer: null, animation: "exiting" } : t,
223
+ );
224
+ this.notify("remove");
210
225
  } else {
211
226
  // Remove immediately
212
227
  this.remove(key);
@@ -224,7 +239,19 @@ export class ToastQueue<T> {
224
239
  }
225
240
 
226
241
  this.queue = this.queue.filter((t) => t.key !== key);
227
- this.updateVisibility();
242
+ this.updateVisibility("remove");
243
+ }
244
+
245
+ /**
246
+ * Clear all queued and visible toasts.
247
+ */
248
+ clear(): void {
249
+ for (const toast of this.queue) {
250
+ toast.timer?.cancel();
251
+ }
252
+
253
+ this.queue = [];
254
+ this.notify("clear");
228
255
  }
229
256
 
230
257
  /**
@@ -245,43 +272,55 @@ export class ToastQueue<T> {
245
272
  }
246
273
  }
247
274
 
248
- private updateVisibility(): void {
275
+ private updateVisibility(action: ToastAction): void {
249
276
  // Mark toasts as visible or queued based on maxVisibleToasts
250
277
  const visibleCount = this.queue.filter(
251
- (t) => t.animation !== 'queued' && t.animation !== 'exiting'
278
+ (t) => t.animation !== "queued" && t.animation !== "exiting",
252
279
  ).length;
253
280
 
254
281
  let promoted = 0;
255
- for (const toast of this.queue) {
256
- if (toast.animation === 'queued' && visibleCount + promoted < this.maxVisibleToasts) {
257
- toast.animation = 'entering';
282
+ this.queue = this.queue.map((toast) => {
283
+ let nextToast = toast;
284
+
285
+ if (nextToast.animation === "queued" && visibleCount + promoted < this.maxVisibleToasts) {
286
+ nextToast = { ...nextToast, animation: "entering" };
258
287
  promoted++;
259
288
  }
260
- if (toast.animation === 'queued') continue;
289
+ if (nextToast.animation === "queued") return nextToast;
261
290
 
262
291
  // 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);
292
+ if (
293
+ nextToast.timeout != null &&
294
+ nextToast.timer === null &&
295
+ nextToast.animation !== "exiting"
296
+ ) {
297
+ nextToast = {
298
+ ...nextToast,
299
+ timer: new Timer(() => {
300
+ this.close(nextToast.key);
301
+ }, nextToast.timeout),
302
+ };
267
303
  }
268
- }
269
304
 
270
- this.notify();
305
+ return nextToast;
306
+ });
307
+
308
+ this.notify(action);
271
309
  }
272
310
 
273
- private notify(): void {
311
+ private notify(action: ToastAction = "add"): void {
274
312
  const toasts = [...this.queue];
275
- for (const callback of this.subscriptions) {
276
- callback(toasts);
277
- }
313
+ // The new visible toasts are computed synchronously above; only the subscriber
314
+ // fan-out (which drives the re-render) is wrapped, so it can run inside a view
315
+ // transition. Mirrors @react-stately/toast's updateVisibleToasts.
316
+ this.runWithWrapUpdate(() => {
317
+ for (const callback of this.subscriptions) {
318
+ callback(toasts);
319
+ }
320
+ }, action);
278
321
  }
279
322
  }
280
323
 
281
- // ============================================
282
- // HOOK
283
- // ============================================
284
-
285
324
  /**
286
325
  * Creates reactive toast state from a ToastQueue.
287
326
  * Use this hook to subscribe to toast changes in your component.
@@ -303,20 +342,19 @@ export function createToastState<T>(props: ToastStateProps<T>): ToastState<T> {
303
342
  add: (content, options) => props.queue.add(content, options),
304
343
  close: (key) => props.queue.close(key),
305
344
  remove: (key) => props.queue.remove(key),
345
+ clear: () => props.queue.clear(),
306
346
  pauseAll: () => props.queue.pauseAll(),
307
347
  resumeAll: () => props.queue.resumeAll(),
308
348
  };
309
349
  }
310
350
 
311
- // ============================================
312
- // CONVENIENCE HOOKS
313
- // ============================================
314
-
315
351
  /**
316
352
  * Creates a new ToastQueue and returns reactive state.
317
353
  * Use this if you don't need a global queue.
318
354
  */
319
- export function createToastQueue<T>(options?: ToastQueueOptions): ToastState<T> & { queue: ToastQueue<T> } {
355
+ export function createToastQueue<T>(
356
+ options?: ToastQueueOptions,
357
+ ): ToastState<T> & { queue: ToastQueue<T> } {
320
358
  const queue = new ToastQueue<T>(options);
321
359
  const state = createToastState({ queue });
322
360
  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
@@ -6,6 +6,7 @@ export {
6
6
  type ToastOptions,
7
7
  type QueuedToast,
8
8
  type ToastQueueOptions,
9
+ type ToastAction,
9
10
  type ToastStateProps,
10
11
  type ToastState,
11
- } from './createToastState';
12
+ } 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;
@@ -5,30 +5,30 @@
5
5
  *
6
6
  * This is a 1:1 port of @react-stately/toggle's useToggleState.
7
7
  */
8
- import { Accessor } from 'solid-js';
9
- import { type MaybeAccessor } from '../utils';
8
+ import { Accessor } from "solid-js";
9
+ import { type MaybeAccessor } from "../utils";
10
10
  export interface ToggleStateOptions {
11
- /** Whether the element should be selected (controlled). */
12
- isSelected?: boolean;
13
- /** Whether the element should be selected by default (uncontrolled). */
14
- defaultSelected?: boolean;
15
- /** Handler that is called when the element's selection state changes. */
16
- onChange?: (isSelected: boolean) => void;
17
- /** Whether the element is read only. */
18
- isReadOnly?: boolean;
11
+ /** Whether the element should be selected (controlled). */
12
+ isSelected?: boolean;
13
+ /** Whether the element should be selected by default (uncontrolled). */
14
+ defaultSelected?: boolean;
15
+ /** Handler that is called when the element's selection state changes. */
16
+ onChange?: (isSelected: boolean) => void;
17
+ /** Whether the element is read only. */
18
+ isReadOnly?: boolean;
19
19
  }
20
20
  export interface ToggleState {
21
- /** Whether the toggle is selected. */
22
- readonly isSelected: Accessor<boolean>;
23
- /** Whether the toggle is selected by default. */
24
- readonly defaultSelected: boolean;
25
- /** Updates selection state. */
26
- setSelected(isSelected: boolean): void;
27
- /** Toggle the selection state. */
28
- toggle(): void;
21
+ /** Whether the toggle is selected. */
22
+ readonly isSelected: Accessor<boolean>;
23
+ /** Whether the toggle is selected by default. */
24
+ readonly defaultSelected: boolean;
25
+ /** Updates selection state. */
26
+ setSelected(isSelected: boolean): void;
27
+ /** Toggle the selection state. */
28
+ toggle(): void;
29
29
  }
30
30
  /**
31
31
  * Provides state management for toggle components like checkboxes and switches.
32
32
  */
33
33
  export declare function createToggleState(props?: MaybeAccessor<ToggleStateOptions>): ToggleState;
34
- //# sourceMappingURL=createToggleState.d.ts.map
34
+ //# sourceMappingURL=createToggleState.d.ts.map
@@ -6,12 +6,8 @@
6
6
  * This is a 1:1 port of @react-stately/toggle's useToggleState.
7
7
  */
8
8
 
9
- import { createSignal, Accessor } from 'solid-js';
10
- import { type MaybeAccessor, access } from '../utils';
11
-
12
- // ============================================
13
- // TYPES
14
- // ============================================
9
+ import { createSignal, Accessor } from "solid-js";
10
+ import { type MaybeAccessor, access } from "../utils";
15
11
 
16
12
  export interface ToggleStateOptions {
17
13
  /** Whether the element should be selected (controlled). */
@@ -35,33 +31,24 @@ export interface ToggleState {
35
31
  toggle(): void;
36
32
  }
37
33
 
38
- // ============================================
39
- // IMPLEMENTATION
40
- // ============================================
41
-
42
34
  /**
43
35
  * Provides state management for toggle components like checkboxes and switches.
44
36
  */
45
37
  export function createToggleState(props: MaybeAccessor<ToggleStateOptions> = {}): ToggleState {
46
38
  const getProps = () => access(props);
47
39
 
48
- // Get initial values
49
40
  const initialProps = getProps();
50
41
  const initialSelected = initialProps.isSelected ?? initialProps.defaultSelected ?? false;
51
42
 
52
- // Create internal signal for uncontrolled mode
53
43
  const [internalSelected, setInternalSelected] = createSignal(initialSelected);
54
44
 
55
- // Determine if controlled
56
45
  const isControlled = () => getProps().isSelected !== undefined;
57
46
 
58
- // Get current selection state
59
47
  const isSelected: Accessor<boolean> = () => {
60
48
  const p = getProps();
61
49
  return isControlled() ? (p.isSelected ?? false) : internalSelected();
62
50
  };
63
51
 
64
- // Update selection state
65
52
  function setSelected(value: boolean): void {
66
53
  const p = getProps();
67
54
  if (p.isReadOnly) {
@@ -75,7 +62,6 @@ export function createToggleState(props: MaybeAccessor<ToggleStateOptions> = {})
75
62
  p.onChange?.(value);
76
63
  }
77
64
 
78
- // Toggle selection state
79
65
  function toggle(): void {
80
66
  const p = getProps();
81
67
  if (p.isReadOnly) {
@@ -1,2 +1,2 @@
1
- export { createToggleState, type ToggleStateOptions, type ToggleState, } from './createToggleState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export { createToggleState, type ToggleStateOptions, type ToggleState } from "./createToggleState";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,7 @@
1
- export {
2
- createToggleState,
3
- type ToggleStateOptions,
4
- type ToggleState,
5
- } from './createToggleState';
1
+ export { createToggleState, type ToggleStateOptions, type ToggleState } from "./createToggleState";
6
2
 
7
3
  export {
8
4
  createToggleGroupState,
9
5
  type ToggleGroupProps,
10
6
  type ToggleGroupState,
11
- } from './createToggleGroupState';
7
+ } from "./createToggleGroupState";
@@ -5,25 +5,25 @@
5
5
  * Tracks whether the tooltip is open, and provides methods to toggle this state.
6
6
  * Ensures only one tooltip is open at a time and controls the delay for showing a tooltip.
7
7
  */
8
- import { type Accessor } from 'solid-js';
9
- import { type OverlayTriggerProps } from '../overlays';
8
+ import { type Accessor } from "solid-js";
9
+ import { type OverlayTriggerProps } from "../overlays";
10
10
  export interface TooltipTriggerProps extends OverlayTriggerProps {
11
- /** The delay time in milliseconds for the tooltip to show up. */
12
- delay?: number;
13
- /** The delay time in milliseconds for the tooltip to close. */
14
- closeDelay?: number;
11
+ /** The delay time in milliseconds for the tooltip to show up. */
12
+ delay?: number;
13
+ /** The delay time in milliseconds for the tooltip to close. */
14
+ closeDelay?: number;
15
15
  }
16
16
  export interface TooltipTriggerState {
17
- /** Whether the tooltip is currently showing. */
18
- readonly isOpen: Accessor<boolean>;
19
- /**
20
- * Shows the tooltip. By default, the tooltip becomes visible after a delay
21
- * depending on a global warmup timer. The `immediate` option shows the
22
- * tooltip immediately instead.
23
- */
24
- open(immediate?: boolean): void;
25
- /** Hides the tooltip. */
26
- close(immediate?: boolean): void;
17
+ /** Whether the tooltip is currently showing. */
18
+ readonly isOpen: Accessor<boolean>;
19
+ /**
20
+ * Shows the tooltip. By default, the tooltip becomes visible after a delay
21
+ * depending on a global warmup timer. The `immediate` option shows the
22
+ * tooltip immediately instead.
23
+ */
24
+ open(immediate?: boolean): void;
25
+ /** Hides the tooltip. */
26
+ close(immediate?: boolean): void;
27
27
  }
28
28
  /**
29
29
  * Resets the global tooltip state. Useful for testing.
@@ -36,4 +36,4 @@ export declare function resetTooltipState(): void;
36
36
  * the delay for showing a tooltip.
37
37
  */
38
38
  export declare function createTooltipTriggerState(props?: TooltipTriggerProps): TooltipTriggerState;
39
- //# sourceMappingURL=createTooltipTriggerState.d.ts.map
39
+ //# sourceMappingURL=createTooltipTriggerState.d.ts.map
@@ -6,9 +6,9 @@
6
6
  * Ensures only one tooltip is open at a time and controls the delay for showing a tooltip.
7
7
  */
8
8
 
9
- import { createSignal, onCleanup, type Accessor } from 'solid-js';
10
- import { createOverlayTriggerState, type OverlayTriggerProps } from '../overlays';
11
- import { isServer } from '../ssr';
9
+ import { createSignal, onCleanup, type Accessor } from "solid-js";
10
+ import { createOverlayTriggerState, type OverlayTriggerProps } from "../overlays";
11
+ import { isServer } from "../ssr";
12
12
 
13
13
  // Default delays (in ms)
14
14
  const TOOLTIP_DELAY = 1500;
@@ -64,9 +64,7 @@ export function resetTooltipState(): void {
64
64
  * methods to toggle this state. Ensures only one tooltip is open at a time and controls
65
65
  * the delay for showing a tooltip.
66
66
  */
67
- export function createTooltipTriggerState(
68
- props: TooltipTriggerProps = {}
69
- ): TooltipTriggerState {
67
+ export function createTooltipTriggerState(props: TooltipTriggerProps = {}): TooltipTriggerState {
70
68
  const delay = () => props.delay ?? TOOLTIP_DELAY;
71
69
  const closeDelay = () => props.closeDelay ?? TOOLTIP_COOLDOWN;
72
70
 
@@ -132,11 +130,14 @@ export function createTooltipTriggerState(
132
130
  if (globalCooldownTimeout) {
133
131
  clearTimeout(globalCooldownTimeout);
134
132
  }
135
- globalCooldownTimeout = setTimeout(() => {
136
- delete tooltips[id];
137
- globalCooldownTimeout = null;
138
- globalWarmedUp = false;
139
- }, Math.max(TOOLTIP_COOLDOWN, closeDelay()));
133
+ globalCooldownTimeout = setTimeout(
134
+ () => {
135
+ delete tooltips[id];
136
+ globalCooldownTimeout = null;
137
+ globalWarmedUp = false;
138
+ },
139
+ Math.max(TOOLTIP_COOLDOWN, closeDelay()),
140
+ );
140
141
  }
141
142
  };
142
143
 
@@ -1,2 +1,7 @@
1
- export { createTooltipTriggerState, resetTooltipState, type TooltipTriggerProps, type TooltipTriggerState, } from './createTooltipTriggerState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createTooltipTriggerState,
3
+ resetTooltipState,
4
+ type TooltipTriggerProps,
5
+ type TooltipTriggerState,
6
+ } from "./createTooltipTriggerState";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -3,4 +3,4 @@ export {
3
3
  resetTooltipState,
4
4
  type TooltipTriggerProps,
5
5
  type TooltipTriggerState,
6
- } from './createTooltipTriggerState';
6
+ } from "./createTooltipTriggerState";