@spark-ui/components 10.11.1 → 10.11.2
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/CHANGELOG.md +6 -0
- package/dist/snackbar/index.d.mts +46 -1
- package/dist/snackbar/index.d.ts +46 -1
- package/dist/snackbar/index.js +185 -37
- package/dist/snackbar/index.js.map +1 -1
- package/dist/snackbar/index.mjs +157 -12
- package/dist/snackbar/index.mjs.map +1 -1
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.11.2](https://github.com/leboncoin/spark-web/compare/v10.11.1...v10.11.2) (2025-07-15)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **components:** local fork of react-stately/toast to resolve deps issue ([36b7ce4](https://github.com/leboncoin/spark-web/commit/36b7ce4acd31a7b9909a25df29d0e05675c49516))
|
|
11
|
+
|
|
6
12
|
## [10.11.1](https://github.com/leboncoin/spark-web/compare/v10.11.0...v10.11.1) (2025-07-11)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { QueuedToast, ToastState, ToastOptions } from '@react-stately/toast';
|
|
2
1
|
import { ReactNode, ComponentPropsWithRef, PropsWithChildren, ReactElement, Ref } from 'react';
|
|
3
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
3
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
@@ -8,6 +7,52 @@ import { ButtonProps } from '../button/index.mjs';
|
|
|
8
7
|
import { IconButtonProps } from '../icon-button/index.mjs';
|
|
9
8
|
import { IconProps } from '../icon/index.mjs';
|
|
10
9
|
|
|
10
|
+
interface ToastOptions {
|
|
11
|
+
/** Handler that is called when the toast is closed, either by the user or after a timeout. */
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
/** A timeout to automatically close the toast after, in milliseconds. */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** The priority of the toast relative to other toasts. Larger numbers indicate higher priority. */
|
|
16
|
+
priority?: number;
|
|
17
|
+
}
|
|
18
|
+
interface QueuedToast<T> extends ToastOptions {
|
|
19
|
+
/** The content of the toast. */
|
|
20
|
+
content: T;
|
|
21
|
+
/** A unique key for the toast. */
|
|
22
|
+
key: string;
|
|
23
|
+
/** A timer for the toast, if a timeout was set. */
|
|
24
|
+
timer?: Timer;
|
|
25
|
+
/** The current animation state for the toast. */
|
|
26
|
+
animation?: 'entering' | 'queued' | 'exiting' | null;
|
|
27
|
+
}
|
|
28
|
+
interface ToastState<T> {
|
|
29
|
+
/** Adds a new toast to the queue. */
|
|
30
|
+
add(content: T, options?: ToastOptions): string;
|
|
31
|
+
/**
|
|
32
|
+
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
33
|
+
* transitions to an "exiting" state instead of being removed immediately.
|
|
34
|
+
*/
|
|
35
|
+
close(key: string): void;
|
|
36
|
+
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
37
|
+
remove(key: string): void;
|
|
38
|
+
/** Pauses the timers for all visible toasts. */
|
|
39
|
+
pauseAll(): void;
|
|
40
|
+
/** Resumes the timers for all visible toasts. */
|
|
41
|
+
resumeAll(): void;
|
|
42
|
+
/** The visible toasts. */
|
|
43
|
+
visibleToasts: QueuedToast<T>[];
|
|
44
|
+
}
|
|
45
|
+
declare class Timer {
|
|
46
|
+
private timerId;
|
|
47
|
+
private startTime;
|
|
48
|
+
private remaining;
|
|
49
|
+
private callback;
|
|
50
|
+
constructor(callback: () => void, delay: number);
|
|
51
|
+
reset(delay: number): void;
|
|
52
|
+
pause(): void;
|
|
53
|
+
resume(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
11
56
|
declare const snackbarItemVariant: (props?: ({
|
|
12
57
|
design?: "filled" | "tinted" | null | undefined;
|
|
13
58
|
intent?: "main" | "success" | "alert" | "error" | "info" | "neutral" | "basic" | "support" | "accent" | "inverse" | null | undefined;
|
package/dist/snackbar/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { QueuedToast, ToastState, ToastOptions } from '@react-stately/toast';
|
|
2
1
|
import { ReactNode, ComponentPropsWithRef, PropsWithChildren, ReactElement, Ref } from 'react';
|
|
3
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
3
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
@@ -8,6 +7,52 @@ import { ButtonProps } from '../button/index.js';
|
|
|
8
7
|
import { IconButtonProps } from '../icon-button/index.js';
|
|
9
8
|
import { IconProps } from '../icon/index.js';
|
|
10
9
|
|
|
10
|
+
interface ToastOptions {
|
|
11
|
+
/** Handler that is called when the toast is closed, either by the user or after a timeout. */
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
/** A timeout to automatically close the toast after, in milliseconds. */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** The priority of the toast relative to other toasts. Larger numbers indicate higher priority. */
|
|
16
|
+
priority?: number;
|
|
17
|
+
}
|
|
18
|
+
interface QueuedToast<T> extends ToastOptions {
|
|
19
|
+
/** The content of the toast. */
|
|
20
|
+
content: T;
|
|
21
|
+
/** A unique key for the toast. */
|
|
22
|
+
key: string;
|
|
23
|
+
/** A timer for the toast, if a timeout was set. */
|
|
24
|
+
timer?: Timer;
|
|
25
|
+
/** The current animation state for the toast. */
|
|
26
|
+
animation?: 'entering' | 'queued' | 'exiting' | null;
|
|
27
|
+
}
|
|
28
|
+
interface ToastState<T> {
|
|
29
|
+
/** Adds a new toast to the queue. */
|
|
30
|
+
add(content: T, options?: ToastOptions): string;
|
|
31
|
+
/**
|
|
32
|
+
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
33
|
+
* transitions to an "exiting" state instead of being removed immediately.
|
|
34
|
+
*/
|
|
35
|
+
close(key: string): void;
|
|
36
|
+
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
37
|
+
remove(key: string): void;
|
|
38
|
+
/** Pauses the timers for all visible toasts. */
|
|
39
|
+
pauseAll(): void;
|
|
40
|
+
/** Resumes the timers for all visible toasts. */
|
|
41
|
+
resumeAll(): void;
|
|
42
|
+
/** The visible toasts. */
|
|
43
|
+
visibleToasts: QueuedToast<T>[];
|
|
44
|
+
}
|
|
45
|
+
declare class Timer {
|
|
46
|
+
private timerId;
|
|
47
|
+
private startTime;
|
|
48
|
+
private remaining;
|
|
49
|
+
private callback;
|
|
50
|
+
constructor(callback: () => void, delay: number);
|
|
51
|
+
reset(delay: number): void;
|
|
52
|
+
pause(): void;
|
|
53
|
+
resume(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
11
56
|
declare const snackbarItemVariant: (props?: ({
|
|
12
57
|
design?: "filled" | "tinted" | null | undefined;
|
|
13
58
|
intent?: "main" | "success" | "alert" | "error" | "info" | "neutral" | "basic" | "support" | "accent" | "inverse" | null | undefined;
|
package/dist/snackbar/index.js
CHANGED
|
@@ -27,17 +27,165 @@ __export(snackbar_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(snackbar_exports);
|
|
28
28
|
|
|
29
29
|
// src/snackbar/Snackbar.tsx
|
|
30
|
-
var
|
|
31
|
-
var import_react9 = require("react");
|
|
30
|
+
var import_react10 = require("react");
|
|
32
31
|
var import_react_dom = require("react-dom");
|
|
33
32
|
|
|
33
|
+
// src/snackbar/local-toast/useToastState.ts
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_shim = require("use-sync-external-store/shim/index.js");
|
|
36
|
+
function useToastQueue(queue) {
|
|
37
|
+
let subscribe = (0, import_react.useCallback)((fn) => queue.subscribe(fn), [queue]);
|
|
38
|
+
let getSnapshot = (0, import_react.useCallback)(() => queue.visibleToasts, [queue]);
|
|
39
|
+
let visibleToasts = (0, import_shim.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
40
|
+
return {
|
|
41
|
+
visibleToasts,
|
|
42
|
+
add: (content, options) => queue.add(content, options),
|
|
43
|
+
close: (key) => queue.close(key),
|
|
44
|
+
remove: (key) => queue.remove(key),
|
|
45
|
+
pauseAll: () => queue.pauseAll(),
|
|
46
|
+
resumeAll: () => queue.resumeAll()
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var ToastQueue = class {
|
|
50
|
+
queue = [];
|
|
51
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
52
|
+
maxVisibleToasts;
|
|
53
|
+
hasExitAnimation;
|
|
54
|
+
/** The currently visible toasts. */
|
|
55
|
+
visibleToasts = [];
|
|
56
|
+
constructor(options) {
|
|
57
|
+
this.maxVisibleToasts = options?.maxVisibleToasts ?? 1;
|
|
58
|
+
this.hasExitAnimation = options?.hasExitAnimation ?? false;
|
|
59
|
+
}
|
|
60
|
+
/** Subscribes to updates to the visible toasts. */
|
|
61
|
+
subscribe(fn) {
|
|
62
|
+
this.subscriptions.add(fn);
|
|
63
|
+
return () => this.subscriptions.delete(fn);
|
|
64
|
+
}
|
|
65
|
+
/** Adds a new toast to the queue. */
|
|
66
|
+
add(content, options = {}) {
|
|
67
|
+
let toastKey = Math.random().toString(36);
|
|
68
|
+
let toast = {
|
|
69
|
+
...options,
|
|
70
|
+
content,
|
|
71
|
+
key: toastKey,
|
|
72
|
+
timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : void 0
|
|
73
|
+
};
|
|
74
|
+
let low = 0;
|
|
75
|
+
let high = this.queue.length;
|
|
76
|
+
while (low < high) {
|
|
77
|
+
let mid = Math.floor((low + high) / 2);
|
|
78
|
+
if ((toast.priority || 0) > (this.queue[mid]?.priority || 0)) {
|
|
79
|
+
high = mid;
|
|
80
|
+
} else {
|
|
81
|
+
low = mid + 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.queue.splice(low, 0, toast);
|
|
85
|
+
toast.animation = low < this.maxVisibleToasts ? "entering" : "queued";
|
|
86
|
+
let i = this.maxVisibleToasts;
|
|
87
|
+
while (i < this.queue.length) {
|
|
88
|
+
;
|
|
89
|
+
this.queue[i++].animation = "queued";
|
|
90
|
+
}
|
|
91
|
+
this.updateVisibleToasts({ action: "add" });
|
|
92
|
+
return toastKey;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
96
|
+
* transitions to an "exiting" state instead of being removed immediately.
|
|
97
|
+
*/
|
|
98
|
+
close(key) {
|
|
99
|
+
let index = this.queue.findIndex((t) => t.key === key);
|
|
100
|
+
if (index >= 0) {
|
|
101
|
+
this.queue[index]?.onClose?.();
|
|
102
|
+
this.queue.splice(index, 1);
|
|
103
|
+
}
|
|
104
|
+
this.updateVisibleToasts({ action: "close", key });
|
|
105
|
+
}
|
|
106
|
+
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
107
|
+
remove(key) {
|
|
108
|
+
this.updateVisibleToasts({ action: "remove", key });
|
|
109
|
+
}
|
|
110
|
+
updateVisibleToasts(options) {
|
|
111
|
+
let { action, key } = options;
|
|
112
|
+
let toasts = this.queue.slice(0, this.maxVisibleToasts);
|
|
113
|
+
if (action === "add" && this.hasExitAnimation) {
|
|
114
|
+
let prevToasts = this.visibleToasts.filter((t) => !toasts.some((t2) => t.key === t2.key)).map((t) => ({ ...t, animation: "exiting" }));
|
|
115
|
+
this.visibleToasts = prevToasts.concat(toasts).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
116
|
+
} else if (action === "close" && this.hasExitAnimation) {
|
|
117
|
+
this.visibleToasts = this.visibleToasts.map((t) => {
|
|
118
|
+
if (t.key !== key) {
|
|
119
|
+
return t;
|
|
120
|
+
} else {
|
|
121
|
+
return { ...t, animation: "exiting" };
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
this.visibleToasts = toasts;
|
|
126
|
+
}
|
|
127
|
+
for (let fn of this.subscriptions) {
|
|
128
|
+
fn();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Pauses the timers for all visible toasts. */
|
|
132
|
+
pauseAll() {
|
|
133
|
+
for (let toast of this.visibleToasts) {
|
|
134
|
+
if (toast.timer) {
|
|
135
|
+
toast.timer.pause();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Resumes the timers for all visible toasts. */
|
|
140
|
+
resumeAll() {
|
|
141
|
+
for (let toast of this.visibleToasts) {
|
|
142
|
+
if (toast.timer) {
|
|
143
|
+
toast.timer.resume();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var Timer = class {
|
|
149
|
+
timerId;
|
|
150
|
+
startTime = null;
|
|
151
|
+
remaining;
|
|
152
|
+
callback;
|
|
153
|
+
constructor(callback, delay) {
|
|
154
|
+
this.remaining = delay;
|
|
155
|
+
this.callback = callback;
|
|
156
|
+
}
|
|
157
|
+
reset(delay) {
|
|
158
|
+
this.remaining = delay;
|
|
159
|
+
this.resume();
|
|
160
|
+
}
|
|
161
|
+
pause() {
|
|
162
|
+
if (this.timerId == null) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
clearTimeout(this.timerId);
|
|
166
|
+
this.timerId = null;
|
|
167
|
+
this.remaining -= Date.now() - this.startTime;
|
|
168
|
+
}
|
|
169
|
+
resume() {
|
|
170
|
+
if (this.remaining <= 0) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.startTime = Date.now();
|
|
174
|
+
this.timerId = setTimeout(() => {
|
|
175
|
+
this.timerId = null;
|
|
176
|
+
this.remaining = 0;
|
|
177
|
+
this.callback();
|
|
178
|
+
}, this.remaining);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
34
182
|
// src/snackbar/SnackbarRegion.tsx
|
|
35
183
|
var import_toast2 = require("@react-aria/toast");
|
|
36
|
-
var
|
|
184
|
+
var import_react8 = require("react");
|
|
37
185
|
|
|
38
186
|
// src/snackbar/SnackbarItem.tsx
|
|
39
187
|
var import_toast = require("@react-aria/toast");
|
|
40
|
-
var
|
|
188
|
+
var import_react7 = require("react");
|
|
41
189
|
|
|
42
190
|
// src/snackbar/SnackbarItem.styles.ts
|
|
43
191
|
var import_class_variance_authority = require("class-variance-authority");
|
|
@@ -265,11 +413,11 @@ var import_class_variance_authority5 = require("class-variance-authority");
|
|
|
265
413
|
|
|
266
414
|
// src/button/Button.tsx
|
|
267
415
|
var import_class_variance_authority4 = require("class-variance-authority");
|
|
268
|
-
var
|
|
416
|
+
var import_react3 = require("react");
|
|
269
417
|
|
|
270
418
|
// src/slot/Slot.tsx
|
|
271
419
|
var import_radix_ui = require("radix-ui");
|
|
272
|
-
var
|
|
420
|
+
var import_react2 = require("react");
|
|
273
421
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
274
422
|
var Slottable = import_radix_ui.Slot.Slottable;
|
|
275
423
|
var Slot = ({ ref, ...props }) => {
|
|
@@ -277,7 +425,7 @@ var Slot = ({ ref, ...props }) => {
|
|
|
277
425
|
};
|
|
278
426
|
var wrapPolymorphicSlot = (asChild, children, callback) => {
|
|
279
427
|
if (!asChild) return callback(children);
|
|
280
|
-
return (0,
|
|
428
|
+
return (0, import_react2.isValidElement)(children) ? (0, import_react2.cloneElement)(
|
|
281
429
|
children,
|
|
282
430
|
void 0,
|
|
283
431
|
callback(children.props.children)
|
|
@@ -1115,7 +1263,7 @@ var Button = ({
|
|
|
1115
1263
|
}) => {
|
|
1116
1264
|
const Component = asChild ? Slot : "button";
|
|
1117
1265
|
const shouldNotInteract = !!disabled || isLoading;
|
|
1118
|
-
const disabledEventHandlers = (0,
|
|
1266
|
+
const disabledEventHandlers = (0, import_react3.useMemo)(() => {
|
|
1119
1267
|
const result = {};
|
|
1120
1268
|
if (shouldNotInteract) {
|
|
1121
1269
|
blockedEventHandlers.forEach((eventHandler) => result[eventHandler] = void 0);
|
|
@@ -1169,9 +1317,9 @@ var Button = ({
|
|
|
1169
1317
|
Button.displayName = "Button";
|
|
1170
1318
|
|
|
1171
1319
|
// src/snackbar/SnackbarItemContext.tsx
|
|
1172
|
-
var
|
|
1173
|
-
var SnackbarItemContext = (0,
|
|
1174
|
-
var useSnackbarItemContext = () => (0,
|
|
1320
|
+
var import_react4 = require("react");
|
|
1321
|
+
var SnackbarItemContext = (0, import_react4.createContext)({});
|
|
1322
|
+
var useSnackbarItemContext = () => (0, import_react4.useContext)(SnackbarItemContext);
|
|
1175
1323
|
|
|
1176
1324
|
// src/snackbar/SnackbarItemAction.tsx
|
|
1177
1325
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
@@ -1219,7 +1367,7 @@ var import_Close = require("@spark-ui/icons/Close");
|
|
|
1219
1367
|
var import_class_variance_authority8 = require("class-variance-authority");
|
|
1220
1368
|
|
|
1221
1369
|
// src/icon/Icon.tsx
|
|
1222
|
-
var
|
|
1370
|
+
var import_react5 = require("react");
|
|
1223
1371
|
|
|
1224
1372
|
// src/icon/Icon.styles.tsx
|
|
1225
1373
|
var import_internal_utils8 = require("@spark-ui/internal-utils");
|
|
@@ -1264,9 +1412,9 @@ var Icon = ({
|
|
|
1264
1412
|
children,
|
|
1265
1413
|
...others
|
|
1266
1414
|
}) => {
|
|
1267
|
-
const child =
|
|
1415
|
+
const child = import_react5.Children.only(children);
|
|
1268
1416
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1269
|
-
(0,
|
|
1417
|
+
(0, import_react5.cloneElement)(child, {
|
|
1270
1418
|
className: iconStyles({ className, size, intent }),
|
|
1271
1419
|
"data-spark-component": "icon",
|
|
1272
1420
|
"aria-hidden": "true",
|
|
@@ -1385,7 +1533,7 @@ var SnackbarItemIcon = ({
|
|
|
1385
1533
|
SnackbarItemIcon.displayName = "Snackbar.ItemIcon";
|
|
1386
1534
|
|
|
1387
1535
|
// src/snackbar/useSwipe.ts
|
|
1388
|
-
var
|
|
1536
|
+
var import_react6 = require("react");
|
|
1389
1537
|
var SWIPE_THRESHOLD = 75;
|
|
1390
1538
|
var useSwipe = ({
|
|
1391
1539
|
swipeRef,
|
|
@@ -1395,10 +1543,10 @@ var useSwipe = ({
|
|
|
1395
1543
|
onSwipeEnd,
|
|
1396
1544
|
threshold = 10
|
|
1397
1545
|
}) => {
|
|
1398
|
-
const [state, setState] = (0,
|
|
1399
|
-
const direction = (0,
|
|
1400
|
-
const origin = (0,
|
|
1401
|
-
const delta = (0,
|
|
1546
|
+
const [state, setState] = (0, import_react6.useState)();
|
|
1547
|
+
const direction = (0, import_react6.useRef)(null);
|
|
1548
|
+
const origin = (0, import_react6.useRef)(null);
|
|
1549
|
+
const delta = (0, import_react6.useRef)(null);
|
|
1402
1550
|
const handleSwipeStart = (evt) => {
|
|
1403
1551
|
origin.current = { x: evt.clientX, y: evt.clientY };
|
|
1404
1552
|
document.addEventListener("selectstart", (e) => e.preventDefault());
|
|
@@ -1461,7 +1609,7 @@ var useSwipe = ({
|
|
|
1461
1609
|
document.removeEventListener("selectstart", (e) => e.preventDefault());
|
|
1462
1610
|
}
|
|
1463
1611
|
};
|
|
1464
|
-
(0,
|
|
1612
|
+
(0, import_react6.useEffect)(() => {
|
|
1465
1613
|
if (!swipeRef.current) return;
|
|
1466
1614
|
const swipeElement = swipeRef.current;
|
|
1467
1615
|
swipeElement.addEventListener("pointerdown", handleSwipeStart);
|
|
@@ -1494,7 +1642,7 @@ var SnackbarItem = ({
|
|
|
1494
1642
|
ref: forwardedRef,
|
|
1495
1643
|
...rest
|
|
1496
1644
|
}) => {
|
|
1497
|
-
const innerRef = (0,
|
|
1645
|
+
const innerRef = (0, import_react7.useRef)(null);
|
|
1498
1646
|
const ref = typeof forwardedRef !== "function" ? forwardedRef || innerRef : innerRef;
|
|
1499
1647
|
const { toast, state } = useSnackbarItemContext();
|
|
1500
1648
|
const { state: swipeState, direction: swipeDirection } = useSwipe({
|
|
@@ -1521,10 +1669,10 @@ var SnackbarItem = ({
|
|
|
1521
1669
|
state,
|
|
1522
1670
|
ref
|
|
1523
1671
|
);
|
|
1524
|
-
const findElement = (0,
|
|
1672
|
+
const findElement = (0, import_react7.useCallback)(
|
|
1525
1673
|
(elementDisplayName) => {
|
|
1526
|
-
const childrenArray =
|
|
1527
|
-
const match = childrenArray.filter(
|
|
1674
|
+
const childrenArray = import_react7.Children.toArray(children);
|
|
1675
|
+
const match = childrenArray.filter(import_react7.isValidElement).find(
|
|
1528
1676
|
(child) => !!child.type.displayName?.includes(
|
|
1529
1677
|
elementDisplayName
|
|
1530
1678
|
)
|
|
@@ -1587,7 +1735,7 @@ var SnackbarItem = ({
|
|
|
1587
1735
|
SnackbarItem.displayName = "Snackbar.Item";
|
|
1588
1736
|
var renderSubComponent = (childItem, defaultItem, props) => {
|
|
1589
1737
|
if (childItem) {
|
|
1590
|
-
return (0,
|
|
1738
|
+
return (0, import_react7.cloneElement)(childItem, { ...props, ...childItem.props });
|
|
1591
1739
|
} else if (defaultItem) {
|
|
1592
1740
|
const Item = defaultItem;
|
|
1593
1741
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Item, { ...props });
|
|
@@ -1635,7 +1783,7 @@ var SnackbarRegion = ({
|
|
|
1635
1783
|
ref: forwardedRef,
|
|
1636
1784
|
...rest
|
|
1637
1785
|
}) => {
|
|
1638
|
-
const innerRef = (0,
|
|
1786
|
+
const innerRef = (0, import_react8.useRef)(null);
|
|
1639
1787
|
const ref = forwardedRef && typeof forwardedRef !== "function" ? forwardedRef : innerRef;
|
|
1640
1788
|
const { regionProps } = (0, import_toast2.useToastRegion)(rest, state, ref);
|
|
1641
1789
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
@@ -1645,26 +1793,26 @@ var SnackbarRegion = ({
|
|
|
1645
1793
|
ref,
|
|
1646
1794
|
"data-position": position,
|
|
1647
1795
|
className: snackbarRegionVariant({ position, className }),
|
|
1648
|
-
children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SnackbarItemContext.Provider, { value: { toast, state }, children: (0,
|
|
1796
|
+
children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SnackbarItemContext.Provider, { value: { toast, state }, children: (0, import_react8.cloneElement)(children, { key: toast.key }) }, toast.key))
|
|
1649
1797
|
}
|
|
1650
1798
|
);
|
|
1651
1799
|
};
|
|
1652
1800
|
|
|
1653
1801
|
// src/snackbar/useSnackbarGlobalStore.ts
|
|
1654
|
-
var
|
|
1802
|
+
var import_react9 = require("react");
|
|
1655
1803
|
var useSnackbarGlobalStore = ({
|
|
1656
1804
|
providers,
|
|
1657
1805
|
subscriptions
|
|
1658
1806
|
}) => {
|
|
1659
|
-
const subscribe = (0,
|
|
1807
|
+
const subscribe = (0, import_react9.useCallback)(
|
|
1660
1808
|
(listener) => {
|
|
1661
1809
|
subscriptions.add(listener);
|
|
1662
1810
|
return () => subscriptions.delete(listener);
|
|
1663
1811
|
},
|
|
1664
1812
|
[subscriptions]
|
|
1665
1813
|
);
|
|
1666
|
-
const getLastSnackbarProvider = (0,
|
|
1667
|
-
const addProvider = (0,
|
|
1814
|
+
const getLastSnackbarProvider = (0, import_react9.useCallback)(() => [...providers].reverse()[0], [providers]);
|
|
1815
|
+
const addProvider = (0, import_react9.useCallback)(
|
|
1668
1816
|
(provider2) => {
|
|
1669
1817
|
providers.add(provider2);
|
|
1670
1818
|
for (const subscribeFn of subscriptions) {
|
|
@@ -1673,7 +1821,7 @@ var useSnackbarGlobalStore = ({
|
|
|
1673
1821
|
},
|
|
1674
1822
|
[providers, subscriptions]
|
|
1675
1823
|
);
|
|
1676
|
-
const deleteProvider = (0,
|
|
1824
|
+
const deleteProvider = (0, import_react9.useCallback)(
|
|
1677
1825
|
(provider2) => {
|
|
1678
1826
|
providers.delete(provider2);
|
|
1679
1827
|
for (const subscribeFn of subscriptions) {
|
|
@@ -1682,7 +1830,7 @@ var useSnackbarGlobalStore = ({
|
|
|
1682
1830
|
},
|
|
1683
1831
|
[providers, subscriptions]
|
|
1684
1832
|
);
|
|
1685
|
-
const provider = (0,
|
|
1833
|
+
const provider = (0, import_react9.useSyncExternalStore)(subscribe, getLastSnackbarProvider, getLastSnackbarProvider);
|
|
1686
1834
|
return {
|
|
1687
1835
|
provider,
|
|
1688
1836
|
addProvider,
|
|
@@ -1695,7 +1843,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
|
1695
1843
|
var GLOBAL_SNACKBAR_QUEUE = null;
|
|
1696
1844
|
var getGlobalSnackBarQueue = () => {
|
|
1697
1845
|
if (!GLOBAL_SNACKBAR_QUEUE) {
|
|
1698
|
-
GLOBAL_SNACKBAR_QUEUE = new
|
|
1846
|
+
GLOBAL_SNACKBAR_QUEUE = new ToastQueue({
|
|
1699
1847
|
maxVisibleToasts: 1,
|
|
1700
1848
|
hasExitAnimation: true
|
|
1701
1849
|
});
|
|
@@ -1710,10 +1858,10 @@ var GLOBAL_SNACKBAR_STORE = {
|
|
|
1710
1858
|
subscriptions: /* @__PURE__ */ new Set()
|
|
1711
1859
|
};
|
|
1712
1860
|
var Snackbar = ({ ref: forwardedRef, ...props }) => {
|
|
1713
|
-
const ref = (0,
|
|
1714
|
-
const state =
|
|
1861
|
+
const ref = (0, import_react10.useRef)(null);
|
|
1862
|
+
const state = useToastQueue(getGlobalSnackBarQueue());
|
|
1715
1863
|
const { provider, addProvider, deleteProvider } = useSnackbarGlobalStore(GLOBAL_SNACKBAR_STORE);
|
|
1716
|
-
(0,
|
|
1864
|
+
(0, import_react10.useEffect)(() => {
|
|
1717
1865
|
addProvider(ref);
|
|
1718
1866
|
return () => {
|
|
1719
1867
|
for (const toast of getGlobalSnackBarQueue().visibleToasts) {
|