@rockshin/tao-ui 0.0.26 → 0.0.28

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.
@@ -4,7 +4,7 @@ import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
4
4
  import { cx } from "../../utils/semantic.js";
5
5
  import { MobileSelectDrawer } from "./mobile-select.js";
6
6
  import { CheckIcon, ChevronDownIcon, CloseIcon, LoadingIcon, SearchIcon } from "./select-icons.js";
7
- import { defaultFilter, filterTree, flattenOptions } from "./select-model.js";
7
+ import { buildSelectIndex, defaultFilter, filterTree, flattenLeafOptions } from "./select-model.js";
8
8
  import { SearchableSelectList } from "./select-searchable-list.js";
9
9
  import { SelectTags } from "./select-tags.js";
10
10
  import "./select.css";
@@ -72,9 +72,12 @@ function Select(props) {
72
72
  const [activeSearchIndex, setActiveSearchIndex] = useState(0);
73
73
  const [hovering, setHovering] = useState(false);
74
74
  const suppressCloseRef = useRef(false);
75
- const allOptions = useMemo(()=>flattenOptions(options), [
75
+ const { optionByToken, optionByValue } = useMemo(()=>buildSelectIndex(options), [
76
76
  options
77
77
  ]);
78
+ const selectedValueSet = useMemo(()=>new Set(valueArray), [
79
+ valueArray
80
+ ]);
78
81
  const handleValueChange = useCallback((next)=>{
79
82
  if (isMultiple) {
80
83
  if (tokenSeparators && tokenSeparators.length > 0) {
@@ -82,8 +85,8 @@ function Select(props) {
82
85
  if (sep) {
83
86
  const tokens = next.split(sep).map((t)=>t.trim()).filter(Boolean);
84
87
  const toAdd = tokens.filter((t_0)=>{
85
- const opt = allOptions.find((o)=>o.value === t_0 || o.label === t_0);
86
- return opt && !valueArray.includes(opt.value);
88
+ const opt = optionByToken.get(t_0);
89
+ return opt && !selectedValueSet.has(opt.value);
87
90
  });
88
91
  if (toAdd.length > 0) {
89
92
  const nextArray = [
@@ -92,10 +95,10 @@ function Select(props) {
92
95
  ];
93
96
  if (null != maxCount && nextArray.length > maxCount) return;
94
97
  if (!isValueControlled) setValueInternal(nextArray);
95
- const selectedOpts = nextArray.map((v)=>allOptions.find((o_0)=>o_0.value === v)).filter(Boolean);
98
+ const selectedOpts = nextArray.map((v)=>optionByValue.get(v)).filter(Boolean);
96
99
  onChange?.(nextArray, selectedOpts);
97
100
  for (const v_0 of toAdd){
98
- const opt_0 = allOptions.find((o_1)=>o_1.value === v_0);
101
+ const opt_0 = optionByValue.get(v_0);
99
102
  if (opt_0) onSelect?.(v_0, opt_0);
100
103
  }
101
104
  }
@@ -104,22 +107,22 @@ function Select(props) {
104
107
  }
105
108
  if (!hasInlineSearch) suppressCloseRef.current = true;
106
109
  const current = valueArray;
107
- const existed = current.includes(next);
110
+ const existed = selectedValueSet.has(next);
108
111
  const nextArray_0 = existed ? current.filter((v_1)=>v_1 !== next) : [
109
112
  ...current,
110
113
  next
111
114
  ];
112
115
  if (!existed && null != maxCount && nextArray_0.length > maxCount) return;
113
116
  if (!isValueControlled) setValueInternal(nextArray_0);
114
- const selectedOpts_0 = nextArray_0.map((v_2)=>allOptions.find((o_2)=>o_2.value === v_2)).filter(Boolean);
117
+ const selectedOpts_0 = nextArray_0.map((v_2)=>optionByValue.get(v_2)).filter(Boolean);
115
118
  onChange?.(nextArray_0, selectedOpts_0);
116
- const opt_1 = allOptions.find((o_3)=>o_3.value === next);
119
+ const opt_1 = optionByValue.get(next);
117
120
  if (opt_1) if (existed) onDeselect?.(next, opt_1);
118
121
  else onSelect?.(next, opt_1);
119
122
  if (autoClearSearchValue && !isSearchControlled) setSearchInternal('');
120
123
  return;
121
124
  }
122
- const opt_2 = allOptions.find((o_4)=>o_4.value === next);
125
+ const opt_2 = optionByValue.get(next);
123
126
  if (!isValueControlled) setValueInternal(next);
124
127
  onChange?.(next, opt_2);
125
128
  if (opt_2) onSelect?.(next, opt_2);
@@ -130,7 +133,9 @@ function Select(props) {
130
133
  maxCount,
131
134
  tokenSeparators,
132
135
  isValueControlled,
133
- allOptions,
136
+ optionByToken,
137
+ optionByValue,
138
+ selectedValueSet,
134
139
  onChange,
135
140
  onSelect,
136
141
  onDeselect,
@@ -204,35 +209,37 @@ function Select(props) {
204
209
  if (!isMultiple) return;
205
210
  const nextArray_1 = valueArray.filter((v_4)=>v_4 !== removedValue);
206
211
  if (!isValueControlled) setValueInternal(nextArray_1);
207
- const selectedOpts_1 = nextArray_1.map((v_5)=>allOptions.find((o_5)=>o_5.value === v_5)).filter(Boolean);
212
+ const selectedOpts_1 = nextArray_1.map((v_5)=>optionByValue.get(v_5)).filter(Boolean);
208
213
  onChange?.(nextArray_1, selectedOpts_1);
209
- const opt_3 = allOptions.find((o_6)=>o_6.value === removedValue);
214
+ const opt_3 = optionByValue.get(removedValue);
210
215
  if (opt_3) onDeselect?.(removedValue, opt_3);
211
216
  }, [
212
217
  isMultiple,
213
218
  valueArray,
214
219
  isValueControlled,
215
- allOptions,
220
+ optionByValue,
216
221
  onChange,
217
222
  onDeselect
218
223
  ]);
219
224
  const handleMultiChange = useCallback((nextArray_2)=>{
220
225
  if (!isValueControlled) setValueInternal(nextArray_2);
221
- const selectedOpts_2 = nextArray_2.map((v_6)=>allOptions.find((o_7)=>o_7.value === v_6)).filter(Boolean);
226
+ const selectedOpts_2 = nextArray_2.map((v_6)=>optionByValue.get(v_6)).filter(Boolean);
222
227
  onChange?.(nextArray_2, selectedOpts_2);
223
228
  const prev = valueArray;
224
- for (const v_7 of nextArray_2)if (!prev.includes(v_7)) {
225
- const opt_4 = allOptions.find((o_8)=>o_8.value === v_7);
229
+ const nextSet = new Set(nextArray_2);
230
+ for (const v_7 of nextArray_2)if (!selectedValueSet.has(v_7)) {
231
+ const opt_4 = optionByValue.get(v_7);
226
232
  if (opt_4) onSelect?.(v_7, opt_4);
227
233
  }
228
- for (const v_8 of prev)if (!nextArray_2.includes(v_8)) {
229
- const opt_5 = allOptions.find((o_9)=>o_9.value === v_8);
234
+ for (const v_8 of prev)if (!nextSet.has(v_8)) {
235
+ const opt_5 = optionByValue.get(v_8);
230
236
  if (opt_5) onDeselect?.(v_8, opt_5);
231
237
  }
232
238
  }, [
233
239
  valueArray,
240
+ selectedValueSet,
234
241
  isValueControlled,
235
- allOptions,
242
+ optionByValue,
236
243
  onChange,
237
244
  onSelect,
238
245
  onDeselect
@@ -242,13 +249,13 @@ function Select(props) {
242
249
  if (hideSelected && isMultiple && valueArray.length > 0) {
243
250
  const filterSelected = (list)=>{
244
251
  const result = [];
245
- for (const o_10 of list)if (o_10.options) {
246
- const kids = filterSelected(o_10.options);
252
+ for (const o of list)if (o.options) {
253
+ const kids = filterSelected(o.options);
247
254
  if (kids.length) result.push({
248
- ...o_10,
255
+ ...o,
249
256
  options: kids
250
257
  });
251
- } else if (!valueArray.includes(o_10.value)) result.push(o_10);
258
+ } else if (!selectedValueSet.has(o.value)) result.push(o);
252
259
  return result;
253
260
  };
254
261
  opts = filterSelected(opts);
@@ -263,23 +270,27 @@ function Select(props) {
263
270
  filterOption,
264
271
  hideSelected,
265
272
  isMultiple,
266
- valueArray
273
+ selectedValueSet,
274
+ valueArray.length
275
+ ]);
276
+ const filteredFlatOptions = useMemo(()=>flattenLeafOptions(filteredOptions), [
277
+ filteredOptions
267
278
  ]);
268
279
  const allowClearEnabled = !!allowClear;
269
280
  const clearIcon = 'object' == typeof allowClear && allowClear.clearIcon || /*#__PURE__*/ jsx(CloseIcon, {});
270
281
  const showClearBtn = allowClearEnabled && (isMultiple ? valueArray.length > 0 : !!value) && !resolvedDisabled;
271
- const selectedOption = useMemo(()=>!isMultiple && value ? allOptions.find((o_11)=>o_11.value === value) : void 0, [
282
+ const selectedOption = useMemo(()=>!isMultiple && value ? optionByValue.get(value) : void 0, [
272
283
  isMultiple,
273
284
  value,
274
- allOptions
285
+ optionByValue
275
286
  ]);
276
- const selectedOptions = useMemo(()=>isMultiple ? valueArray.map((v_9)=>allOptions.find((o_12)=>o_12.value === v_9) ?? ('tags' === mode ? {
287
+ const selectedOptions = useMemo(()=>isMultiple ? valueArray.map((v_9)=>optionByValue.get(v_9) ?? ('tags' === mode ? {
277
288
  label: v_9,
278
289
  value: v_9
279
290
  } : void 0)).filter(Boolean) : [], [
280
291
  isMultiple,
281
292
  valueArray,
282
- allOptions,
293
+ optionByValue,
283
294
  mode
284
295
  ]);
285
296
  const statusProps = {
@@ -449,13 +460,13 @@ function Select(props) {
449
460
  };
450
461
  if ('number' == typeof popupMatchSelectWidth) contentStyle.width = popupMatchSelectWidth;
451
462
  const radixValue = isMultiple ? '' : value || void 0;
452
- const resultCount = flattenOptions(filteredOptions).length;
463
+ const resultCount = filteredFlatOptions.length;
453
464
  const overMaxCount = isMultiple && null != maxCount && valueArray.length >= maxCount;
454
465
  let optIndex = 0;
455
466
  const renderItem = (opt_6)=>{
456
467
  const index = optIndex++;
457
468
  const textLabel = 'string' == typeof opt_6.label ? opt_6.label : String(opt_6.label);
458
- const isSelected = valueArray.includes(opt_6.value);
469
+ const isSelected = selectedValueSet.has(opt_6.value);
459
470
  const itemDisabled = opt_6.disabled || !isSelected && overMaxCount;
460
471
  return /*#__PURE__*/ jsxs(__rspack_external__radix_ui_react_select_4606f4d3.Item, {
461
472
  value: opt_6.value,
@@ -514,7 +525,7 @@ function Select(props) {
514
525
  ]
515
526
  }, opt_6.value);
516
527
  };
517
- const renderTree = (opts_0)=>opts_0.map((o_13)=>o_13.options ? /*#__PURE__*/ jsxs(__rspack_external__radix_ui_react_select_4606f4d3.Group, {
528
+ const renderTree = (opts_0)=>opts_0.map((o_0)=>o_0.options ? /*#__PURE__*/ jsxs(__rspack_external__radix_ui_react_select_4606f4d3.Group, {
518
529
  "data-tao-select-group": "",
519
530
  className: cx(classNames?.group),
520
531
  style: styles?.group,
@@ -523,11 +534,11 @@ function Select(props) {
523
534
  "data-tao-select-group-label": "",
524
535
  className: cx(classNames?.groupLabel),
525
536
  style: styles?.groupLabel,
526
- children: o_13.label
537
+ children: o_0.label
527
538
  }),
528
- o_13.options.map(renderItem)
539
+ o_0.options.map(renderItem)
529
540
  ]
530
- }, o_13.value) : renderItem(o_13));
541
+ }, o_0.value) : renderItem(o_0));
531
542
  const menuNode = /*#__PURE__*/ jsx(__rspack_external__radix_ui_react_select_4606f4d3.Viewport, {
532
543
  "data-tao-select-viewport": "",
533
544
  style: {
@@ -540,8 +551,8 @@ function Select(props) {
540
551
  children: notFoundContent
541
552
  })
542
553
  });
543
- const isSearchableOptionDisabled = (option)=>!!option.disabled || overMaxCount && !valueArray.includes(option.value);
544
- const searchableOptions = flattenOptions(filteredOptions).filter((option_0)=>!isSearchableOptionDisabled(option_0));
554
+ const isSearchableOptionDisabled = (option)=>!!option.disabled || overMaxCount && !selectedValueSet.has(option.value);
555
+ const searchableOptions = filteredFlatOptions.filter((option_0)=>!isSearchableOptionDisabled(option_0));
545
556
  const activeSearchOption = searchableOptions[Math.min(activeSearchIndex, Math.max(searchableOptions.length - 1, 0))];
546
557
  const searchableMenuNode = /*#__PURE__*/ jsx(SearchableSelectList, {
547
558
  id: searchListboxId,
@@ -1,5 +1,5 @@
1
- import { type SemanticClassNames, type SemanticStyles } from '../../utils/semantic';
2
1
  import type { CSSProperties, ReactNode } from 'react';
2
+ import { type SemanticClassNames, type SemanticStyles } from '../../utils/semantic';
3
3
  import './sonner.css';
4
4
  export type SonnerSemanticPart = 'viewport' | 'toast' | 'content' | 'title' | 'description' | 'actions' | 'action' | 'cancel' | 'close';
5
5
  export type SonnerType = 'default' | 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
@@ -27,6 +27,7 @@ export interface SonnerToastItem extends SonnerToastOptions {
27
27
  type: SonnerType;
28
28
  createdAt: number;
29
29
  custom?: ReactNode;
30
+ /** @deprecated Toast lifecycle state is internal and no longer exposed. */
30
31
  removing?: boolean;
31
32
  }
32
33
  export interface SonnerProps {
@@ -1,16 +1,16 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
3
  import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
3
4
  import { cx } from "../../utils/semantic.js";
4
5
  import { Button } from "../button/button.js";
5
- import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
6
  import "./sonner.css";
7
7
  const listeners = new Set();
8
8
  let state = {
9
9
  toasts: []
10
10
  };
11
11
  let seed = 0;
12
- const timers = new Map();
13
- const removeTimers = new Map();
12
+ let generationSeed = 0;
13
+ const runtimes = new Map();
14
14
  const REMOVE_DELAY = 220;
15
15
  function emit() {
16
16
  listeners.forEach((listener)=>{
@@ -24,69 +24,47 @@ function subscribe(listener) {
24
24
  function getSnapshot() {
25
25
  return state;
26
26
  }
27
- function clearTimer(id) {
28
- const timer = timers.get(id);
29
- if (timer) {
30
- clearTimeout(timer);
31
- timers.delete(id);
32
- }
33
- }
34
- function clearRemoveTimer(id) {
35
- const timer = removeTimers.get(id);
36
- if (timer) {
37
- clearTimeout(timer);
38
- removeTimers.delete(id);
39
- }
27
+ function clearRuntimeTimers(runtime) {
28
+ if (runtime.dismissTimer) clearTimeout(runtime.dismissTimer);
29
+ if (runtime.removeTimer) clearTimeout(runtime.removeTimer);
30
+ runtime.dismissTimer = void 0;
31
+ runtime.removeTimer = void 0;
40
32
  }
41
- function dismiss(id) {
42
- if (!id) {
43
- state.toasts.forEach((toast)=>{
44
- clearTimer(toast.id);
45
- });
46
- state.toasts.forEach((toast)=>{
47
- clearRemoveTimer(toast.id);
48
- });
49
- state = {
50
- toasts: state.toasts.map((toast)=>({
51
- ...toast,
52
- removing: true
53
- }))
54
- };
55
- emit();
56
- state.toasts.forEach((toast)=>{
57
- removeTimers.set(toast.id, setTimeout(()=>{
58
- removeTimers.delete(toast.id);
59
- state = {
60
- toasts: state.toasts.filter((item)=>item.id !== toast.id)
61
- };
62
- emit();
63
- }, REMOVE_DELAY));
64
- });
65
- return;
66
- }
67
- clearTimer(id);
68
- clearRemoveTimer(id);
33
+ function beginExit(id) {
34
+ const runtime = runtimes.get(id);
35
+ if (!runtime || !state.toasts.some((toast)=>toast.id === id)) return;
36
+ clearRuntimeTimers(runtime);
69
37
  state = {
70
38
  toasts: state.toasts.map((toast)=>toast.id === id ? {
71
39
  ...toast,
72
- removing: true
40
+ phase: 'exiting'
73
41
  } : toast)
74
42
  };
75
43
  emit();
76
- removeTimers.set(id, setTimeout(()=>{
77
- removeTimers.delete(id);
44
+ const generation = runtime.generation;
45
+ runtime.removeTimer = setTimeout(()=>{
46
+ const current = runtimes.get(id);
47
+ if (!current || current.generation !== generation) return;
48
+ runtimes.delete(id);
78
49
  state = {
79
50
  toasts: state.toasts.filter((toast)=>toast.id !== id)
80
51
  };
81
52
  emit();
82
- }, REMOVE_DELAY));
53
+ }, REMOVE_DELAY);
54
+ }
55
+ function dismiss(id) {
56
+ if (id) return void beginExit(id);
57
+ for (const toast of state.toasts)beginExit(toast.id);
83
58
  }
84
59
  function scheduleDismiss(id, duration) {
85
- clearTimer(id);
60
+ const runtime = runtimes.get(id);
61
+ if (!runtime) return;
62
+ if (runtime.dismissTimer) clearTimeout(runtime.dismissTimer);
86
63
  if (null == duration || duration <= 0) return;
87
- timers.set(id, setTimeout(()=>{
88
- dismiss(id);
89
- }, duration));
64
+ const generation = runtime.generation;
65
+ runtime.dismissTimer = setTimeout(()=>{
66
+ if (runtimes.get(id)?.generation === generation) beginExit(id);
67
+ }, duration);
90
68
  }
91
69
  function isToastOptions(value) {
92
70
  return null != value && 'object' == typeof value && !Array.isArray(value) && !('$$typeof' in value);
@@ -99,12 +77,19 @@ function normalizeOptions(options) {
99
77
  function create(type, options, custom) {
100
78
  const normalized = normalizeOptions(options);
101
79
  const id = normalized.id ?? `toast-${Date.now()}-${seed++}`;
80
+ const previousRuntime = runtimes.get(id);
81
+ if (previousRuntime) clearRuntimeTimers(previousRuntime);
82
+ const runtime = {
83
+ generation: generationSeed++
84
+ };
85
+ runtimes.set(id, runtime);
102
86
  const next = {
103
87
  ...normalized,
104
88
  id,
105
89
  type,
106
90
  createdAt: Date.now(),
107
- custom
91
+ custom,
92
+ phase: 'active'
108
93
  };
109
94
  state = {
110
95
  toasts: [
@@ -116,6 +101,13 @@ function create(type, options, custom) {
116
101
  scheduleDismiss(id, normalized.duration);
117
102
  return id;
118
103
  }
104
+ function replacePromiseToast(id, type, options) {
105
+ const normalized = normalizeOptions(options);
106
+ create(type, {
107
+ ...normalized,
108
+ id
109
+ });
110
+ }
119
111
  function resolveDataType(type, richColors) {
120
112
  if ('custom' === type) return 'custom';
121
113
  if ('loading' === type) return 'loading';
@@ -146,9 +138,12 @@ function renderPromiseState(stateValue, payload) {
146
138
  function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap = 12, expand = true, richColors = false, closeButton = false, duration = 4000, className, style, classNames, styles }) {
147
139
  useTaoConfig();
148
140
  const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
149
- const [heights, setHeights] = useState([]);
141
+ const [heights, setHeights] = useState(()=>new Map());
150
142
  useEffect(()=>{
151
- for (const toast of snapshot.toasts)if (!timers.has(toast.id)) scheduleDismiss(toast.id, toast.duration ?? duration);
143
+ for (const toast of snapshot.toasts){
144
+ const runtime = runtimes.get(toast.id);
145
+ if ('active' === toast.phase && runtime && !runtime.dismissTimer) scheduleDismiss(toast.id, toast.duration ?? duration);
146
+ }
152
147
  }, [
153
148
  duration,
154
149
  snapshot.toasts
@@ -162,7 +157,8 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
162
157
  snapshot.toasts,
163
158
  visibleToasts
164
159
  ]);
165
- const frontToastHeight = heights[0]?.height ?? 0;
160
+ const frontToastHeight = heights.get(visible[0]?.id ?? '') ?? 0;
161
+ let nextOffset = 0;
166
162
  return /*#__PURE__*/ jsx(TaoPortalScope, {
167
163
  children: /*#__PURE__*/ jsx("div", {
168
164
  className: cx(classNames?.viewport, className),
@@ -178,6 +174,8 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
178
174
  children: visible.map((toast_0, index)=>{
179
175
  const showClose = toast_0.closable ?? closeButton;
180
176
  const yPosition = position.startsWith('top') ? 'top' : 'bottom';
177
+ const toastOffset = nextOffset;
178
+ nextOffset += (heights.get(toast_0.id) ?? 0) + gap;
181
179
  return /*#__PURE__*/ jsx(ToastView, {
182
180
  toast: toast_0,
183
181
  richColors: richColors,
@@ -186,8 +184,7 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
186
184
  index: index,
187
185
  visibleToasts: visible.length,
188
186
  expanded: expand,
189
- gap: gap,
190
- heights: heights,
187
+ offset: toastOffset,
191
188
  frontToastHeight: frontToastHeight,
192
189
  setHeights: setHeights,
193
190
  classNames: classNames,
@@ -197,41 +194,37 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
197
194
  })
198
195
  });
199
196
  }
200
- function ToastView({ toast, richColors, showClose, yPosition, index, visibleToasts, expanded, gap, heights, frontToastHeight, setHeights, classNames, styles }) {
197
+ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToasts, expanded, offset, frontToastHeight, setHeights, classNames, styles }) {
201
198
  const [mounted, setMounted] = useState(false);
202
199
  const [offsetBeforeRemove, setOffsetBeforeRemove] = useState(0);
203
200
  const ref = useRef(null);
204
- const offset = useMemo(()=>heights.slice(0, index).reduce((sum, item)=>sum + item.height, 0) + index * gap, [
205
- gap,
206
- heights,
207
- index
208
- ]);
209
201
  useEffect(()=>{
210
202
  const frame = requestAnimationFrame(()=>setMounted(true));
211
203
  return ()=>cancelAnimationFrame(frame);
212
204
  }, []);
213
205
  useEffect(()=>{
214
- if (toast.removing) setOffsetBeforeRemove(offset);
206
+ if ('exiting' === toast.phase) setOffsetBeforeRemove(offset);
215
207
  }, [
216
208
  offset,
217
- toast.removing
209
+ toast.phase
218
210
  ]);
219
211
  useLayoutEffect(()=>{
220
212
  const node = ref.current;
221
213
  if (!node) return;
222
214
  const nextHeight = node.getBoundingClientRect().height;
223
215
  setHeights((current)=>{
224
- const filtered = current.filter((item_0)=>item_0.id !== toast.id);
225
- return [
226
- ...filtered,
227
- {
228
- id: toast.id,
229
- height: nextHeight
230
- }
231
- ];
216
+ if (current.get(toast.id) === nextHeight) return current;
217
+ const next = new Map(current);
218
+ next.set(toast.id, nextHeight);
219
+ return next;
232
220
  });
233
221
  return ()=>{
234
- setHeights((current_0)=>current_0.filter((item_1)=>item_1.id !== toast.id));
222
+ setHeights((current_0)=>{
223
+ if (!current_0.has(toast.id)) return current_0;
224
+ const next_0 = new Map(current_0);
225
+ next_0.delete(toast.id);
226
+ return next_0;
227
+ });
235
228
  };
236
229
  }, [
237
230
  setHeights,
@@ -244,7 +237,7 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
244
237
  ]);
245
238
  const isFront = 0 === index;
246
239
  const isVisible = index < visibleToasts;
247
- const activeOffset = toast.removing ? offsetBeforeRemove : offset;
240
+ const activeOffset = 'exiting' === toast.phase ? offsetBeforeRemove : offset;
248
241
  return /*#__PURE__*/ jsx("div", {
249
242
  ref: ref,
250
243
  className: cx(classNames?.toast),
@@ -255,7 +248,7 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
255
248
  "data-tao-type": resolveDataType(toast.type, richColors),
256
249
  "data-tao-mounted": mounted,
257
250
  "data-tao-y-position": yPosition,
258
- "data-tao-removing": toast.removing ? 'true' : 'false',
251
+ "data-tao-removing": 'exiting' === toast.phase ? 'true' : 'false',
259
252
  "data-tao-front": isFront ? 'true' : 'false',
260
253
  "data-tao-expanded": expanded ? 'true' : 'false',
261
254
  "data-tao-visible": isVisible ? 'true' : 'false',
@@ -354,14 +347,14 @@ const sonner_toast = Object.assign(baseToast, {
354
347
  });
355
348
  try {
356
349
  const value = await promise;
357
- dismiss(id);
358
350
  const success = renderPromiseState(messages.success, value);
359
- if (success) create('success', success);
351
+ if (success) replacePromiseToast(id, 'success', success);
352
+ else dismiss(id);
360
353
  return value;
361
354
  } catch (error) {
362
- dismiss(id);
363
355
  const failure = renderPromiseState(messages.error, error);
364
- if (failure) create('error', failure);
356
+ if (failure) replacePromiseToast(id, 'error', failure);
357
+ else dismiss(id);
365
358
  throw error;
366
359
  }
367
360
  },