@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.
- package/README.md +30 -283
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -2
- package/dist/autocomplete/index.d.ts +1 -1
- package/dist/calendar/IncompleteDate.d.ts +61 -0
- package/dist/calendar/createCalendarState.d.ts +41 -16
- package/dist/calendar/createDateFieldState.d.ts +39 -9
- package/dist/calendar/createDatePickerState.d.ts +60 -0
- package/dist/calendar/createRangeCalendarState.d.ts +37 -10
- package/dist/calendar/createTimeFieldState.d.ts +34 -7
- package/dist/calendar/index.d.ts +7 -6
- package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/collections/ListCollection.d.ts +1 -1
- package/dist/collections/createListState.d.ts +11 -8
- package/dist/collections/createMenuState.d.ts +7 -7
- package/dist/collections/createSelectionState.d.ts +22 -10
- package/dist/collections/getChildNodes.d.ts +11 -0
- package/dist/collections/index.d.ts +6 -5
- package/dist/collections/types.d.ts +12 -12
- package/dist/color/Color.d.ts +1 -1
- package/dist/color/createColorAreaState.d.ts +4 -2
- package/dist/color/createColorFieldState.d.ts +38 -12
- package/dist/color/createColorSliderState.d.ts +9 -2
- package/dist/color/createColorWheelState.d.ts +13 -2
- package/dist/color/getColorChannels.d.ts +1 -1
- package/dist/color/index.d.ts +6 -6
- package/dist/color/types.d.ts +4 -4
- package/dist/combobox/createComboBoxState.d.ts +34 -13
- package/dist/combobox/index.d.ts +1 -1
- package/dist/data/createAsyncList.d.ts +4 -4
- package/dist/data/createListData.d.ts +2 -2
- package/dist/data/createTreeData.d.ts +6 -2
- package/dist/data/index.d.ts +3 -3
- package/dist/datepicker/index.d.ts +2 -4
- package/dist/disclosure/createDisclosureState.d.ts +2 -2
- package/dist/disclosure/index.d.ts +1 -1
- package/dist/dnd/createDragState.d.ts +2 -2
- package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
- package/dist/dnd/createDropState.d.ts +2 -2
- package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
- package/dist/dnd/index.d.ts +5 -5
- package/dist/dnd/types.d.ts +19 -17
- package/dist/form/createFormValidationState.d.ts +3 -3
- package/dist/form/index.d.ts +1 -1
- package/dist/grid/createGridState.d.ts +2 -2
- package/dist/grid/index.d.ts +2 -2
- package/dist/grid/types.d.ts +27 -11
- package/dist/index.d.ts +31 -30
- package/dist/index.js +9077 -7246
- package/dist/index.js.map +1 -1
- package/dist/menu/index.d.ts +2 -2
- package/dist/numberfield/createNumberFieldState.d.ts +2 -2
- package/dist/numberfield/index.d.ts +1 -1
- package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
- package/dist/overlays/index.d.ts +1 -1
- package/dist/radio/createRadioGroupState.d.ts +7 -7
- package/dist/radio/index.d.ts +1 -1
- package/dist/searchfield/createSearchFieldState.d.ts +2 -2
- package/dist/searchfield/index.d.ts +2 -2
- package/dist/select/createSelectState.d.ts +14 -8
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/Selection.d.ts +16 -0
- package/dist/selection/SelectionManager.d.ts +110 -0
- package/dist/selection/createMultipleSelectionState.d.ts +59 -0
- package/dist/selection/index.d.ts +6 -5
- package/dist/slider/createSliderState.d.ts +3 -3
- package/dist/slider/index.d.ts +2 -2
- package/dist/steplist/createStepListState.d.ts +48 -0
- package/dist/steplist/index.d.ts +1 -0
- package/dist/table/TableCollection.d.ts +33 -3
- package/dist/table/createTableColumnResizeState.d.ts +54 -0
- package/dist/table/createTableState.d.ts +2 -2
- package/dist/table/createTreeGridState.d.ts +15 -0
- package/dist/table/index.d.ts +6 -3
- package/dist/table/types.d.ts +68 -10
- package/dist/tabs/createTabListState.d.ts +5 -5
- package/dist/tabs/index.d.ts +1 -1
- package/dist/textfield/createTextFieldState.d.ts +2 -2
- package/dist/textfield/index.d.ts +1 -1
- package/dist/toast/createToastState.d.ts +24 -2
- package/dist/toast/index.d.ts +1 -1
- package/dist/toggle/createToggleGroupState.d.ts +4 -4
- package/dist/toggle/createToggleState.d.ts +2 -2
- package/dist/toggle/index.d.ts +2 -2
- package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tree/TreeCollection.d.ts +2 -2
- package/dist/tree/createTreeState.d.ts +2 -2
- package/dist/tree/index.d.ts +3 -3
- package/dist/tree/types.d.ts +27 -13
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/reactivity.d.ts +1 -1
- package/package.json +29 -30
- package/src/autocomplete/createAutocompleteState.d.ts +19 -17
- package/src/autocomplete/createAutocompleteState.ts +24 -30
- package/src/autocomplete/index.d.ts +6 -2
- package/src/autocomplete/index.ts +1 -1
- package/src/calendar/IncompleteDate.ts +430 -0
- package/src/calendar/createCalendarState.d.ts +139 -117
- package/src/calendar/createCalendarState.ts +308 -94
- package/src/calendar/createDateFieldState.d.ts +130 -95
- package/src/calendar/createDateFieldState.ts +447 -334
- package/src/calendar/createDatePickerState.ts +347 -0
- package/src/calendar/createRangeCalendarState.d.ts +154 -129
- package/src/calendar/createRangeCalendarState.ts +411 -85
- package/src/calendar/createTimeFieldState.d.ts +81 -79
- package/src/calendar/createTimeFieldState.ts +187 -108
- package/src/calendar/index.d.ts +80 -7
- package/src/calendar/index.ts +23 -12
- package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
- package/src/checkbox/createCheckboxGroupState.ts +20 -29
- package/src/checkbox/index.d.ts +6 -2
- package/src/checkbox/index.ts +1 -1
- package/src/collections/ListCollection.d.ts +25 -22
- package/src/collections/ListCollection.ts +6 -6
- package/src/collections/createListState.d.ts +73 -58
- package/src/collections/createListState.ts +67 -35
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +21 -12
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +66 -52
- package/src/collections/getChildNodes.ts +98 -0
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +14 -10
- package/src/collections/types.d.ts +101 -101
- package/src/collections/types.ts +12 -12
- package/src/color/Color.d.ts +20 -5
- package/src/color/Color.ts +357 -254
- package/src/color/createColorAreaState.d.ts +67 -65
- package/src/color/createColorAreaState.ts +21 -13
- package/src/color/createColorFieldState.d.ts +46 -44
- package/src/color/createColorFieldState.ts +285 -149
- package/src/color/createColorSliderState.d.ts +58 -56
- package/src/color/createColorSliderState.ts +45 -14
- package/src/color/createColorWheelState.d.ts +42 -40
- package/src/color/createColorWheelState.ts +101 -64
- package/src/color/getColorChannels.ts +7 -5
- package/src/color/index.d.ts +36 -7
- package/src/color/index.ts +6 -9
- package/src/color/types.d.ts +68 -63
- package/src/color/types.ts +11 -19
- package/src/combobox/createComboBoxState.d.ts +107 -105
- package/src/combobox/createComboBoxState.ts +184 -89
- package/src/combobox/index.d.ts +10 -2
- package/src/combobox/index.ts +1 -1
- package/src/data/createAsyncList.ts +89 -63
- package/src/data/createListData.ts +67 -67
- package/src/data/createTreeData.ts +304 -91
- package/src/data/index.ts +3 -3
- package/src/datepicker/index.ts +6 -10
- package/src/disclosure/createDisclosureState.d.ts +47 -43
- package/src/disclosure/createDisclosureState.ts +7 -21
- package/src/disclosure/index.d.ts +10 -2
- package/src/disclosure/index.ts +1 -1
- package/src/dnd/createDragState.d.ts +51 -42
- package/src/dnd/createDragState.ts +12 -14
- package/src/dnd/createDraggableCollectionState.d.ts +52 -41
- package/src/dnd/createDraggableCollectionState.ts +14 -21
- package/src/dnd/createDropState.d.ts +64 -45
- package/src/dnd/createDropState.ts +22 -32
- package/src/dnd/createDroppableCollectionState.d.ts +88 -59
- package/src/dnd/createDroppableCollectionState.ts +40 -43
- package/src/dnd/index.d.ts +55 -6
- package/src/dnd/index.ts +6 -18
- package/src/dnd/types.d.ts +170 -157
- package/src/dnd/types.ts +24 -22
- package/src/form/createFormValidationState.d.ts +47 -45
- package/src/form/createFormValidationState.ts +30 -63
- package/src/form/index.d.ts +16 -2
- package/src/form/index.ts +1 -1
- package/src/grid/createGridState.d.ts +7 -4
- package/src/grid/createGridState.ts +78 -51
- package/src/grid/index.d.ts +3 -3
- package/src/grid/index.ts +2 -8
- package/src/grid/types.d.ts +136 -129
- package/src/grid/types.ts +34 -18
- package/src/index.d.ts +311 -26
- package/src/index.ts +59 -89
- package/src/menu/index.ts +2 -4
- package/src/numberfield/createNumberFieldState.d.ts +56 -54
- package/src/numberfield/createNumberFieldState.ts +26 -31
- package/src/numberfield/index.d.ts +6 -2
- package/src/numberfield/index.ts +1 -1
- package/src/overlays/createOverlayTriggerState.d.ts +22 -20
- package/src/overlays/createOverlayTriggerState.ts +3 -4
- package/src/overlays/index.d.ts +6 -2
- package/src/overlays/index.ts +1 -1
- package/src/radio/createRadioGroupState.d.ts +54 -52
- package/src/radio/createRadioGroupState.ts +27 -29
- package/src/radio/index.d.ts +7 -2
- package/src/radio/index.ts +1 -1
- package/src/searchfield/createSearchFieldState.d.ts +16 -14
- package/src/searchfield/createSearchFieldState.ts +5 -11
- package/src/searchfield/index.d.ts +3 -3
- package/src/searchfield/index.ts +2 -5
- package/src/select/createSelectState.d.ts +63 -61
- package/src/select/createSelectState.ts +42 -29
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/Selection.ts +28 -0
- package/src/selection/SelectionManager.ts +526 -0
- package/src/selection/createMultipleSelectionState.ts +247 -0
- package/src/selection/index.ts +12 -7
- package/src/slider/createSliderState.d.ts +60 -60
- package/src/slider/createSliderState.ts +55 -33
- package/src/slider/index.d.ts +3 -3
- package/src/slider/index.ts +2 -6
- package/src/ssr/index.d.ts +1 -1
- package/src/ssr/index.ts +2 -2
- package/src/steplist/createStepListState.ts +191 -0
- package/src/steplist/index.ts +5 -0
- package/src/table/TableCollection.d.ts +42 -40
- package/src/table/TableCollection.ts +266 -99
- package/src/table/createTableColumnResizeState.ts +242 -0
- package/src/table/createTableState.d.ts +7 -4
- package/src/table/createTableState.ts +30 -7
- package/src/table/createTreeGridState.ts +146 -0
- package/src/table/index.d.ts +14 -4
- package/src/table/index.ts +13 -3
- package/src/table/types.d.ts +98 -92
- package/src/table/types.ts +83 -13
- package/src/tabs/createTabListState.d.ts +59 -57
- package/src/tabs/createTabListState.ts +34 -39
- package/src/tabs/index.d.ts +8 -2
- package/src/tabs/index.ts +1 -1
- package/src/textfield/createTextFieldState.d.ts +16 -14
- package/src/textfield/createTextFieldState.ts +7 -18
- package/src/textfield/index.d.ts +6 -2
- package/src/textfield/index.ts +1 -1
- package/src/toast/createToastState.d.ts +92 -86
- package/src/toast/createToastState.ts +90 -52
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +2 -1
- package/src/toggle/createToggleGroupState.ts +11 -21
- package/src/toggle/createToggleState.d.ts +19 -19
- package/src/toggle/createToggleState.ts +2 -16
- package/src/toggle/index.d.ts +2 -2
- package/src/toggle/index.ts +2 -6
- package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
- package/src/tooltip/createTooltipTriggerState.ts +12 -11
- package/src/tooltip/index.d.ts +7 -2
- package/src/tooltip/index.ts +1 -1
- package/src/tree/TreeCollection.d.ts +26 -23
- package/src/tree/TreeCollection.ts +29 -22
- package/src/tree/createTreeState.d.ts +7 -4
- package/src/tree/createTreeState.ts +70 -41
- package/src/tree/index.d.ts +10 -4
- package/src/tree/index.ts +3 -3
- package/src/tree/types.d.ts +131 -126
- package/src/tree/types.ts +30 -13
- package/src/utils/index.d.ts +2 -2
- package/src/utils/index.ts +1 -1
- package/src/utils/reactivity.d.ts +2 -2
- 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
|
|
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?:
|
|
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:
|
|
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
|
|
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 !==
|
|
219
|
+
if (this.hasExitAnimation && toast.animation !== "queued") {
|
|
207
220
|
// Mark as exiting for animation
|
|
208
|
-
|
|
209
|
-
|
|
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 !==
|
|
278
|
+
(t) => t.animation !== "queued" && t.animation !== "exiting",
|
|
252
279
|
).length;
|
|
253
280
|
|
|
254
281
|
let promoted = 0;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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 (
|
|
289
|
+
if (nextToast.animation === "queued") return nextToast;
|
|
261
290
|
|
|
262
291
|
// Start timer for visible toasts
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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
|
-
|
|
276
|
-
|
|
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>(
|
|
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 };
|
package/src/toast/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
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
|
package/src/toast/index.ts
CHANGED
|
@@ -7,20 +7,16 @@
|
|
|
7
7
|
* This is a port of @react-stately/toggle's useToggleGroupState.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { createSignal } from
|
|
11
|
-
import type { Key } from
|
|
12
|
-
import { type MaybeAccessor, access } from
|
|
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?:
|
|
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:
|
|
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 ??
|
|
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 ===
|
|
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 ??
|
|
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
|
|
9
|
-
import { type MaybeAccessor } from
|
|
8
|
+
import { Accessor } from "solid-js";
|
|
9
|
+
import { type MaybeAccessor } from "../utils";
|
|
10
10
|
export interface ToggleStateOptions {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
10
|
-
import { type MaybeAccessor, access } from
|
|
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) {
|
package/src/toggle/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createToggleState, type ToggleStateOptions, type ToggleState
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { createToggleState, type ToggleStateOptions, type ToggleState } from "./createToggleState";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/toggle/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
9
|
-
import { type OverlayTriggerProps } from
|
|
8
|
+
import { type Accessor } from "solid-js";
|
|
9
|
+
import { type OverlayTriggerProps } from "../overlays";
|
|
10
10
|
export interface TooltipTriggerProps extends OverlayTriggerProps {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
10
|
-
import { createOverlayTriggerState, type OverlayTriggerProps } from
|
|
11
|
-
import { isServer } from
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
package/src/tooltip/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createTooltipTriggerState,
|
|
3
|
+
resetTooltipState,
|
|
4
|
+
type TooltipTriggerProps,
|
|
5
|
+
type TooltipTriggerState,
|
|
6
|
+
} from "./createTooltipTriggerState";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/tooltip/index.ts
CHANGED