@servicetitan/anvil2 1.26.5 → 1.26.7

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.
@@ -1,13 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { createContext, forwardRef, useRef, useState, useEffect, useContext, useCallback, useMemo } from 'react';
2
+ import { createContext, forwardRef, useRef, useState, useEffect, useCallback, useMemo, useContext } from 'react';
3
+ import { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
3
4
  import { c as cx } from './index-tZvMCc77.js';
4
5
  import { B as Button } from './Button-DPIUyV2O-DxCH2dlc.js';
5
6
  import { A as Alert } from './Alert-BGxnwh4U-ytPHdG2h.js';
6
7
  import { P as ProgressBar } from './ProgressBar-BscwJegu-B8smpeOp.js';
7
8
  import { u as useSwipe } from './useSwipe-DIUHs7T5-DIUHs7T5.js';
8
9
  import { S as SrOnly } from './SrOnly-BXm1DGl3-BJVodjQp.js';
9
- import { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
10
- import { a as ThemeProviderContext, T as ThemeProvider } from './ThemeProvider-C15J9JBA-BiL6I6O0.js';
11
10
 
12
11
  import './toast.css';/**
13
12
  * Convert array of 16 byte values to UUID string format of the form:
@@ -62,29 +61,30 @@ function v4(options, buf, offset) {
62
61
  return unsafeStringify(rnds);
63
62
  }
64
63
 
65
- const toaster = "_toaster_1ovnt_3";
66
- const hidden = "_hidden_1ovnt_65";
67
- const stacked = "_stacked_1ovnt_72";
68
- const open = "_open_1ovnt_152";
69
- const close = "_close_1ovnt_153";
70
- const slideIn = "_slideIn_1ovnt_1";
71
- const slideOut = "_slideOut_1ovnt_1";
64
+ const toaster = "_toaster_u439w_3";
65
+ const hidden = "_hidden_u439w_18";
66
+ const stacked = "_stacked_u439w_82";
67
+ const open = "_open_u439w_163";
68
+ const close = "_close_u439w_164";
69
+ const slideIn = "_slideIn_u439w_1";
70
+ const slideOut = "_slideOut_u439w_1";
72
71
  const styles = {
73
72
  toaster: toaster,
74
- "toast-wrapper": "_toast-wrapper_1ovnt_28",
75
- "toast-alert": "_toast-alert_1ovnt_42",
76
- "alert-action": "_alert-action_1ovnt_47",
77
- "message-container": "_message-container_1ovnt_53",
78
- "show-extra-toast": "_show-extra-toast_1ovnt_62",
79
73
  hidden: hidden,
74
+ "toast-stack": "_toast-stack_u439w_21",
75
+ "toast-wrapper": "_toast-wrapper_u439w_38",
76
+ "toast-alert": "_toast-alert_u439w_52",
77
+ "alert-action": "_alert-action_u439w_57",
78
+ "message-container": "_message-container_u439w_63",
79
+ "show-extra-toast": "_show-extra-toast_u439w_72",
80
80
  stacked: stacked,
81
- "stack-one": "_stack-one_1ovnt_75",
82
- "stack-two": "_stack-two_1ovnt_75",
83
- "stacked-show-extra": "_stacked-show-extra_1ovnt_91",
84
- "stacked-extra": "_stacked-extra_1ovnt_105",
85
- "show-more-button-container": "_show-more-button-container_1ovnt_118",
86
- "show-collapse-button-container": "_show-collapse-button-container_1ovnt_119",
87
- "show-collapse-button": "_show-collapse-button_1ovnt_119",
81
+ "stack-one": "_stack-one_u439w_85",
82
+ "stack-two": "_stack-two_u439w_85",
83
+ "stacked-show-extra": "_stacked-show-extra_u439w_101",
84
+ "stacked-extra": "_stacked-extra_u439w_115",
85
+ "show-more-button-container": "_show-more-button-container_u439w_128",
86
+ "show-collapse-button-container": "_show-collapse-button-container_u439w_129",
87
+ "show-collapse-button": "_show-collapse-button_u439w_129",
88
88
  open: open,
89
89
  close: close,
90
90
  slideIn: slideIn,
@@ -177,92 +177,7 @@ const useToasts = () => {
177
177
  return context;
178
178
  };
179
179
 
180
- const toast$1 = () => {
181
- const toastMethods = [
182
- "info",
183
- "success",
184
- "warning",
185
- "danger",
186
- "promise",
187
- "update",
188
- "dismiss"
189
- ];
190
- console.error(
191
- "Please use one of the following toast methods:\n",
192
- ...toastMethods.map((m) => ` toast.${m}()
193
- `)
194
- );
195
- };
196
- const TOAST_EVENT_NAME = "hammer-toast";
197
- const TOAST_TYPES = ["info", "success", "warning", "danger"];
198
- const methods = {};
199
- TOAST_TYPES.forEach((type) => {
200
- methods[type] = (props) => {
201
- const uniqueId = v4();
202
- const ToastAddEvent = new CustomEvent(TOAST_EVENT_NAME, {
203
- composed: true,
204
- detail: {
205
- id: uniqueId,
206
- eventType: "add",
207
- status: type,
208
- createdAt: Date.now(),
209
- ...props
210
- }
211
- });
212
- dispatchEvent(ToastAddEvent);
213
- return uniqueId;
214
- };
215
- });
216
- const update = (id, props) => {
217
- const ToastEvent = new CustomEvent(
218
- TOAST_EVENT_NAME,
219
- {
220
- composed: true,
221
- detail: {
222
- eventType: "update",
223
- id,
224
- ...props
225
- }
226
- }
227
- );
228
- dispatchEvent(ToastEvent);
229
- };
230
- const dismiss = (id) => {
231
- const ToastEvent = new CustomEvent(
232
- TOAST_EVENT_NAME,
233
- {
234
- composed: true,
235
- detail: {
236
- eventType: "dismiss",
237
- id
238
- }
239
- }
240
- );
241
- dispatchEvent(ToastEvent);
242
- };
243
- const promise = async (promise2, toastConfig) => {
244
- const id = toast$1.info({ ...toastConfig.loading, duration: false });
245
- await Promise.resolve(promise2).then((res) => {
246
- toast$1.update(id, {
247
- ...toastConfig.success(res),
248
- status: "success"
249
- });
250
- }).catch((err) => {
251
- toast$1.update(id, {
252
- ...toastConfig.error(err),
253
- status: "danger"
254
- });
255
- });
256
- return id;
257
- };
258
- toast$1.info = methods.info;
259
- toast$1.success = methods.success;
260
- toast$1.warning = methods.warning;
261
- toast$1.danger = methods.danger;
262
- toast$1.update = update;
263
- toast$1.dismiss = dismiss;
264
- toast$1.promise = promise;
265
-
180
+ const ANIMATION_DURATION = 300;
266
181
  const useShowMoreButtonPositionStyles = () => {
267
182
  const { toastHeights, toastsBeforeStack } = useToasts();
268
183
  const totalToasts = toastHeights.length;
@@ -371,7 +286,7 @@ const closeToast = (setToasts, setToastHeights, closingToastClassName, id) => {
371
286
  );
372
287
  setTimeout(() => {
373
288
  setToastsAfterClose(setToasts, setToastHeights, id);
374
- }, 290);
289
+ }, ANIMATION_DURATION - 10);
375
290
  }
376
291
  };
377
292
  const useCloseToast = (closingToastClassName) => {
@@ -381,6 +296,92 @@ const useCloseToast = (closingToastClassName) => {
381
296
  };
382
297
  };
383
298
 
299
+ const toast$1 = () => {
300
+ const toastMethods = [
301
+ "info",
302
+ "success",
303
+ "warning",
304
+ "danger",
305
+ "promise",
306
+ "update",
307
+ "dismiss"
308
+ ];
309
+ console.error(
310
+ "Please use one of the following toast methods:\n",
311
+ ...toastMethods.map((m) => ` toast.${m}()
312
+ `)
313
+ );
314
+ };
315
+ const TOAST_EVENT_NAME = "hammer-toast";
316
+ const TOAST_TYPES = ["info", "success", "warning", "danger"];
317
+ const methods = {};
318
+ TOAST_TYPES.forEach((type) => {
319
+ methods[type] = (props) => {
320
+ const uniqueId = v4();
321
+ const ToastAddEvent = new CustomEvent(TOAST_EVENT_NAME, {
322
+ composed: true,
323
+ detail: {
324
+ id: uniqueId,
325
+ eventType: "add",
326
+ status: type,
327
+ createdAt: Date.now(),
328
+ ...props
329
+ }
330
+ });
331
+ dispatchEvent(ToastAddEvent);
332
+ return uniqueId;
333
+ };
334
+ });
335
+ const update = (id, props) => {
336
+ const ToastEvent = new CustomEvent(
337
+ TOAST_EVENT_NAME,
338
+ {
339
+ composed: true,
340
+ detail: {
341
+ eventType: "update",
342
+ id,
343
+ ...props
344
+ }
345
+ }
346
+ );
347
+ dispatchEvent(ToastEvent);
348
+ };
349
+ const dismiss = (id) => {
350
+ const ToastEvent = new CustomEvent(
351
+ TOAST_EVENT_NAME,
352
+ {
353
+ composed: true,
354
+ detail: {
355
+ eventType: "dismiss",
356
+ id
357
+ }
358
+ }
359
+ );
360
+ dispatchEvent(ToastEvent);
361
+ };
362
+ const promise = async (promise2, toastConfig) => {
363
+ const id = toast$1.info({ ...toastConfig.loading, duration: false });
364
+ await Promise.resolve(promise2).then((res) => {
365
+ toast$1.update(id, {
366
+ ...toastConfig.success(res),
367
+ status: "success"
368
+ });
369
+ }).catch((err) => {
370
+ toast$1.update(id, {
371
+ ...toastConfig.error(err),
372
+ status: "danger"
373
+ });
374
+ });
375
+ return id;
376
+ };
377
+ toast$1.info = methods.info;
378
+ toast$1.success = methods.success;
379
+ toast$1.warning = methods.warning;
380
+ toast$1.danger = methods.danger;
381
+ toast$1.update = update;
382
+ toast$1.dismiss = dismiss;
383
+ toast$1.promise = promise;
384
+
384
385
  const Toast = forwardRef(
385
386
  ({
386
387
  actions,
@@ -626,140 +627,43 @@ function useHotkeyFocus({
626
627
  return { returnFocusRef: previousFocusElement };
627
628
  }
628
629
 
629
- const Toaster$1 = forwardRef(
630
- (props, ref) => {
631
- return /* @__PURE__ */ jsx(ToastProvider, { children: /* @__PURE__ */ jsx(ToasterContent, { ...props, ...ref }) });
632
- }
633
- );
634
- const ToasterContent = forwardRef(
630
+ const ToastStack = forwardRef(
635
631
  ({
636
632
  className,
637
633
  duration = false,
638
634
  focusKey = "t",
639
- forceRender = false,
640
- id,
635
+ toasts,
641
636
  toastsBeforeStack = 3,
642
637
  ...props
643
638
  }, ref) => {
644
- const toasterRef = useRef(null);
639
+ const toastStackRef = useRef(null);
645
640
  const firstToastRef = useRef(null);
646
- const mergedToasterRef = useMergeRefs([toasterRef, ref]);
641
+ const mergedToastStackRef = useMergeRefs([toastStackRef, ref]);
647
642
  const {
648
- toasts,
649
643
  setToastsBeforeStack,
650
644
  extraToastsVisible,
651
645
  setExtraToastsVisible,
652
- setToasts,
653
646
  getToasterHeight
654
647
  } = useToasts();
655
648
  const toastCount = toasts.length;
649
+ const isToastStackEmpty = toastCount === 0;
656
650
  const lastToastCount = useRef(0);
657
- const a1ToastGroupObserver = useRef(null);
658
- const a1ToastGroupObserverConnected = useRef(false);
659
- const themeContext = useContext(ThemeProviderContext);
660
- const closeToast = useCloseToast(styles.close);
661
- const [toasterHeight, setToasterHeight] = useState(0);
662
- const [a1ToastGroups, setA1ToastGroups] = useState([]);
663
- const updateA1ToastGroups = () => {
664
- const mfeRoots = document.querySelectorAll(
665
- "[data-mfe-portal-name],[data-mfe-name]"
666
- );
667
- const a1ToastGroupsLocal = [
668
- ...document.getElementsByClassName("ToastGroup")
669
- ];
670
- if (mfeRoots.length > 0) {
671
- mfeRoots.forEach((el) => {
672
- setTimeout(() => {
673
- if (el.shadowRoot) {
674
- a1ToastGroupsLocal.push(
675
- ...el.shadowRoot.querySelectorAll(".ToastGroup")
676
- );
677
- }
678
- setA1ToastGroups(a1ToastGroupsLocal);
679
- });
680
- });
681
- } else {
682
- setA1ToastGroups(a1ToastGroupsLocal);
683
- }
684
- };
685
- const handleToasterBlur = useCallback(() => {
686
- setExtraToastsVisible(false);
687
- setToastPausedStatus("resumed");
688
- if (toasterRef.current?.scrollTo) {
689
- toasterRef.current?.scrollTo(0, 0);
690
- }
691
- }, [setExtraToastsVisible]);
692
- useEffect(() => {
693
- const toastEventListener = (e) => {
694
- const toasters = document.querySelectorAll("[data-anv='toaster']");
695
- const shadowToasters = toasterRef.current?.getRootNode()?.querySelectorAll("[data-anv='toaster']") || [];
696
- if (toasters.length && id !== toasters[0].getAttribute("data-toaster-id")) {
697
- return;
698
- } else if (
699
- // Toaster(s) exist in the shadow dom, bail out if this toaster is not the first one
700
- shadowToasters.length && id !== shadowToasters[0].getAttribute("data-toaster-id")
701
- ) {
702
- return;
703
- }
704
- const { eventType, ...toastProps } = e.detail;
705
- if (eventType === "add") {
706
- const toastAddProps = toastProps;
707
- if (!toastAddProps.toasterId || toastAddProps.toasterId === id) {
708
- setToasts((prev) => [...prev, toastProps]);
709
- }
710
- } else if (eventType === "update") {
711
- setToasts((prev) => {
712
- return prev.map((t) => {
713
- if (t.id === toastProps.id) {
714
- return {
715
- ...t,
716
- ...toastProps
717
- };
718
- } else {
719
- return t;
720
- }
721
- });
722
- });
723
- } else if (eventType === "dismiss") {
724
- if (toastProps.id) {
725
- closeToast(toastProps.id);
726
- } else {
727
- closeToast();
728
- }
729
- }
730
- };
731
- window.addEventListener("hammer-toast", toastEventListener);
732
- a1ToastGroupObserver.current = new MutationObserver(updateA1ToastGroups);
733
- return () => window.removeEventListener("hammer-toast", toastEventListener);
734
- }, []);
651
+ const [toastStackHeight, setToastStackHeight] = useState(0);
652
+ const [toastPausedStatus, setToastPausedStatus] = useState(undefined);
735
653
  useEffect(() => {
736
- if (a1ToastGroupObserver.current !== null) {
737
- if (toastCount > 0 && a1ToastGroupObserverConnected.current === false) {
738
- a1ToastGroupObserver.current.observe(document.body, {
739
- childList: true,
740
- subtree: true
741
- });
742
- a1ToastGroupObserverConnected.current = true;
743
- updateA1ToastGroups();
744
- } else if (toastCount === 0 && a1ToastGroupObserverConnected.current === true) {
745
- a1ToastGroupObserver.current.disconnect();
746
- a1ToastGroupObserverConnected.current = false;
747
- }
654
+ if (toastCount === 0) {
655
+ setToastPausedStatus(undefined);
748
656
  }
749
657
  }, [toastCount]);
750
- useEffect(() => {
751
- if (a1ToastGroups && a1ToastGroups.length > 0) {
752
- a1ToastGroups.forEach((group) => {
753
- group.style.top = toastCount === 0 ? "16px" : `calc(${toasterHeight}px + 3.5rem)`;
754
- });
755
- }
756
- }, [toasterHeight, a1ToastGroups.length]);
757
658
  useEffect(() => {
758
659
  let timer;
759
660
  if (toastCount > lastToastCount.current) {
760
- setToasterHeight(getToasterHeight());
661
+ setToastStackHeight(getToasterHeight());
761
662
  } else {
762
- timer = setTimeout(() => setToasterHeight(getToasterHeight()), 290);
663
+ timer = setTimeout(
664
+ () => setToastStackHeight(getToasterHeight()),
665
+ ANIMATION_DURATION - 10
666
+ );
763
667
  }
764
668
  lastToastCount.current = toastCount;
765
669
  return () => {
@@ -769,9 +673,15 @@ const ToasterContent = forwardRef(
769
673
  useEffect(() => {
770
674
  setToastsBeforeStack(toastsBeforeStack);
771
675
  }, [setToastsBeforeStack, toastsBeforeStack]);
772
- const isToasterEmpty = toastCount === 0;
676
+ const handleToastStackBlur = useCallback(() => {
677
+ setExtraToastsVisible(false);
678
+ setToastPausedStatus("resumed");
679
+ if (toastStackRef.current?.scrollTo) {
680
+ toastStackRef.current?.scrollTo(0, 0);
681
+ }
682
+ }, [setExtraToastsVisible]);
773
683
  const { returnFocusRef } = useHotkeyFocus({
774
- disabled: isToasterEmpty,
684
+ disabled: isToastStackEmpty,
775
685
  hotkey: focusKey,
776
686
  onHotkeyIn: async () => {
777
687
  setExtraToastsVisible(true);
@@ -783,44 +693,48 @@ const ToasterContent = forwardRef(
783
693
  },
784
694
  onHotkeyOut: () => {
785
695
  setExtraToastsVisible(false);
786
- handleToasterBlur();
696
+ handleToastStackBlur();
787
697
  },
788
698
  refToFocus: firstToastRef,
789
- rootRef: toasterRef
699
+ rootRef: toastStackRef
790
700
  });
791
701
  const showMoreButtonPositionStyles = useShowMoreButtonPositionStyles();
792
- const [toastPausedStatus, setToastPausedStatus] = useState(undefined);
793
702
  const showMoreButton = !extraToastsVisible && toastCount > toastsBeforeStack;
794
703
  const extraToastsLength = toastCount - toastsBeforeStack;
795
704
  const showMoreButtonText = `${extraToastsLength} more message${extraToastsLength > 1 ? "s" : ""}`;
796
- const toasterClasses = cx(styles.toaster, className, {
705
+ const toastStackClasses = cx(styles["toast-stack"], className, {
797
706
  [styles["show-more-button"]]: showMoreButton,
798
707
  [styles["show-extra-toast"]]: extraToastsVisible
799
708
  });
800
- const handleToasterFocusHover = () => {
709
+ const handleToastStackFocusHover = () => {
801
710
  if (toastPausedStatus === "resumed" || toastPausedStatus === undefined) {
802
711
  setToastPausedStatus(Date.now());
803
712
  }
804
713
  };
805
- const handleToasterOnBlur = () => {
806
- if (!toasterRef.current?.matches(":focus-within")) {
807
- handleToasterBlur();
714
+ const handleToastStackOnBlur = () => {
715
+ if (!toastStackRef.current?.matches(":focus-within")) {
716
+ handleToastStackBlur();
808
717
  }
809
718
  };
719
+ const handleShowMoreButtonClick = () => {
720
+ setExtraToastsVisible(true);
721
+ };
722
+ const toastStackHeightStyle = extraToastsVisible ? "calc(100vh - var(--toaster-padding) * 2)" : toastCount > 0 ? `calc(${toastStackHeight}px + 2rem + var(--toaster-padding))` : 0;
723
+ const toastStackPaddingStyle = toastCount > 0 ? "var(--toaster-padding) 0 var(--toaster-padding) var(--toaster-padding)" : 0;
810
724
  return /* @__PURE__ */ jsxs(Fragment, { children: [
811
725
  /* @__PURE__ */ jsxs(
812
726
  "div",
813
727
  {
814
- "data-anv": "toaster",
815
- "data-toaster-id": id,
816
- className: toasterClasses,
817
- ref: mergedToasterRef,
818
- onMouseOver: handleToasterFocusHover,
819
- onMouseLeave: handleToasterBlur,
820
- onFocus: handleToasterFocusHover,
821
- onBlur: handleToasterOnBlur,
728
+ "data-anv": "toast-stack",
729
+ className: toastStackClasses,
730
+ ref: mergedToastStackRef,
731
+ onMouseOver: handleToastStackFocusHover,
732
+ onMouseLeave: handleToastStackBlur,
733
+ onFocus: handleToastStackFocusHover,
734
+ onBlur: handleToastStackOnBlur,
822
735
  style: {
823
- height: extraToastsVisible ? "100vh" : `calc(${toasterHeight}px + 2rem + var(--toaster-padding))`
736
+ height: toastStackHeightStyle,
737
+ padding: toastStackPaddingStyle
824
738
  },
825
739
  ...props,
826
740
  children: [
@@ -864,18 +778,13 @@ const ToasterContent = forwardRef(
864
778
  className: styles["show-more-button-container"],
865
779
  style: showMoreButtonPositionStyles,
866
780
  children: /* @__PURE__ */ jsx(
867
- ThemeProvider,
781
+ Button,
868
782
  {
869
- mode: themeContext.mode === "dark" ? "light" : "dark",
870
- children: /* @__PURE__ */ jsx(
871
- Button,
872
- {
873
- onClick: () => setExtraToastsVisible(true),
874
- appearance: "secondary",
875
- tabIndex: 0,
876
- children: showMoreButtonText
877
- }
878
- )
783
+ className: styles["show-collapse-button"],
784
+ onClick: handleShowMoreButtonClick,
785
+ appearance: "secondary",
786
+ tabIndex: 0,
787
+ children: showMoreButtonText
879
788
  }
880
789
  )
881
790
  }
@@ -892,7 +801,7 @@ const ToasterContent = forwardRef(
892
801
  Button,
893
802
  {
894
803
  className: styles["show-collapse-button"],
895
- onClick: handleToasterBlur,
804
+ onClick: handleToastStackBlur,
896
805
  appearance: "secondary",
897
806
  children: "Collapse Messages"
898
807
  }
@@ -900,16 +809,222 @@ const ToasterContent = forwardRef(
900
809
  ] });
901
810
  }
902
811
  );
812
+ ToastStack.displayName = "ToastStack";
813
+
814
+ const ToasterContent = forwardRef(
815
+ ({
816
+ className,
817
+ disableEvents = false,
818
+ forceRender = false,
819
+ id,
820
+ onToastEvent,
821
+ // ToastStackProps
822
+ duration,
823
+ focusKey,
824
+ toastsBeforeStack,
825
+ ...props
826
+ }, ref) => {
827
+ const toasterRef = useRef(null);
828
+ const mergedToasterRef = useMergeRefs([toasterRef, ref]);
829
+ const { toasts, setToasts } = useToasts();
830
+ const disableEventsRef = useRef(disableEvents);
831
+ const toastCountRef = useRef(0);
832
+ useEffect(() => {
833
+ disableEventsRef.current = disableEvents;
834
+ }, [disableEvents]);
835
+ useEffect(() => {
836
+ toastCountRef.current = toasts.length;
837
+ }, [toasts.length]);
838
+ const closeToast = useCloseToast(styles.close);
839
+ useEffect(() => {
840
+ let timeout;
841
+ const toastEventListener = (e) => {
842
+ if (disableEventsRef.current) {
843
+ return;
844
+ }
845
+ const { eventType, ...toastProps } = e.detail;
846
+ if (eventType === "add") {
847
+ const toastAddProps = toastProps;
848
+ if (!toastAddProps.toasterId || toastAddProps.toasterId === id) {
849
+ setToasts((prev) => [...prev, toastProps]);
850
+ }
851
+ timeout = setTimeout(() => {
852
+ onToastEvent?.({
853
+ eventType: "add",
854
+ toastCount: toastCountRef.current,
855
+ id: toastAddProps.id,
856
+ toasterId: id,
857
+ toastProps: toastAddProps
858
+ });
859
+ });
860
+ } else if (eventType === "update") {
861
+ const toastUpdateProps = toastProps;
862
+ setToasts((prev) => {
863
+ return prev.map((t) => {
864
+ if (t.id === toastUpdateProps.id) {
865
+ return {
866
+ ...t,
867
+ ...toastUpdateProps
868
+ };
869
+ } else {
870
+ return t;
871
+ }
872
+ });
873
+ });
874
+ onToastEvent?.({
875
+ eventType: "update",
876
+ toastCount: toastCountRef.current,
877
+ id: toastUpdateProps.id,
878
+ toasterId: id,
879
+ toastProps: toastUpdateProps
880
+ });
881
+ } else if (eventType === "dismiss") {
882
+ if (toastProps.id) {
883
+ closeToast(toastProps.id);
884
+ timeout = setTimeout(() => {
885
+ onToastEvent?.({
886
+ eventType: "dismiss",
887
+ toastCount: toastCountRef.current,
888
+ id: toastProps.id,
889
+ toasterId: id
890
+ });
891
+ }, ANIMATION_DURATION);
892
+ } else {
893
+ closeToast();
894
+ onToastEvent?.({
895
+ eventType: "dismiss-all",
896
+ toastCount: 0,
897
+ toasterId: id
898
+ });
899
+ }
900
+ }
901
+ };
902
+ window.addEventListener("hammer-toast", toastEventListener);
903
+ return () => {
904
+ window.removeEventListener("hammer-toast", toastEventListener);
905
+ clearTimeout(timeout);
906
+ };
907
+ }, []);
908
+ const toasterClasses = cx(styles.toaster, {
909
+ [`${className}`]: className != null
910
+ });
911
+ return /* @__PURE__ */ jsx(
912
+ "div",
913
+ {
914
+ "data-anv": "toaster",
915
+ "data-toaster-id": id,
916
+ className: toasterClasses,
917
+ ref: mergedToasterRef,
918
+ ...props,
919
+ children: /* @__PURE__ */ jsx(
920
+ ToastStack,
921
+ {
922
+ toasts,
923
+ duration,
924
+ focusKey,
925
+ toastsBeforeStack
926
+ }
927
+ )
928
+ }
929
+ );
930
+ }
931
+ );
932
+ const Toaster$1 = forwardRef(
933
+ (props, ref) => {
934
+ return /* @__PURE__ */ jsx(ToastProvider, { children: /* @__PURE__ */ jsx(ToasterContent, { ...props, ref }) });
935
+ }
936
+ );
903
937
  Toaster$1.displayName = "Toaster";
904
938
  ToasterContent.displayName = "ToasterContent";
905
939
 
940
+ const SHADOW_HOST_DATA_ATTRS = "[data-mfe-portal-name], [data-mfe-name]";
906
941
  const Toaster = forwardRef(
907
- (props, ref) => {
908
- return /* @__PURE__ */ jsx(Toaster$1, { ref, ...props });
942
+ ({ onToastEvent, ...props }, ref) => {
943
+ const { id } = props;
944
+ const toasterRef = useRef(null);
945
+ const mergedToasterRef = useMergeRefs([toasterRef, ref]);
946
+ const [shouldDisableEvents, setShouldDisableEvents] = useState(false);
947
+ useEffect(() => {
948
+ const toasters = document.querySelectorAll("[data-anv='toaster']");
949
+ const shadowToasters = toasterRef.current?.getRootNode()?.querySelectorAll("[data-anv='toaster']") || [];
950
+ if (toasters.length && id !== toasters[0].getAttribute("data-toaster-id")) {
951
+ setShouldDisableEvents(true);
952
+ } else if (
953
+ // Toaster(s) exist in the shadow dom, bail out if this toaster is not the first one
954
+ shadowToasters.length && id !== shadowToasters[0].getAttribute("data-toaster-id")
955
+ ) {
956
+ setShouldDisableEvents(true);
957
+ }
958
+ }, [id]);
959
+ const a1ToastGroupObserver = useRef(null);
960
+ const a1ToastGroupObserverConnected = useRef(false);
961
+ const [a1ToastGroups, setA1ToastGroups] = useState([]);
962
+ const [toastCount, setToastCount] = useState(0);
963
+ const handleToastEvent = (event) => {
964
+ const { toastCount: newToastCount } = event;
965
+ setToastCount(newToastCount);
966
+ onToastEvent?.(event);
967
+ };
968
+ const updateA1ToastGroups = () => {
969
+ const mfeRoots = document.querySelectorAll(SHADOW_HOST_DATA_ATTRS);
970
+ const a1ToastGroupsLocal = [
971
+ ...document.getElementsByClassName("ToastGroup")
972
+ ];
973
+ if (mfeRoots.length > 0) {
974
+ mfeRoots.forEach((el) => {
975
+ setTimeout(() => {
976
+ if (el.shadowRoot) {
977
+ a1ToastGroupsLocal.push(
978
+ ...el.shadowRoot.querySelectorAll(".ToastGroup")
979
+ );
980
+ }
981
+ setA1ToastGroups(a1ToastGroupsLocal);
982
+ });
983
+ });
984
+ } else {
985
+ setA1ToastGroups(a1ToastGroupsLocal);
986
+ }
987
+ };
988
+ useEffect(() => {
989
+ a1ToastGroupObserver.current = new MutationObserver(updateA1ToastGroups);
990
+ }, []);
991
+ useEffect(() => {
992
+ if (a1ToastGroupObserver.current !== null) {
993
+ if (toastCount > 0 && a1ToastGroupObserverConnected.current === false) {
994
+ a1ToastGroupObserver.current.observe(document.body, {
995
+ childList: true,
996
+ subtree: true
997
+ });
998
+ a1ToastGroupObserverConnected.current = true;
999
+ updateA1ToastGroups();
1000
+ } else if (toastCount === 0 && a1ToastGroupObserverConnected.current === true) {
1001
+ a1ToastGroupObserver.current.disconnect();
1002
+ a1ToastGroupObserverConnected.current = false;
1003
+ }
1004
+ }
1005
+ }, [toastCount]);
1006
+ useEffect(() => {
1007
+ if (a1ToastGroups && a1ToastGroups.length > 0) {
1008
+ const toasterHeight = toasterRef.current?.firstElementChild?.getBoundingClientRect().height;
1009
+ a1ToastGroups.forEach((group) => {
1010
+ group.style.top = toastCount === 0 ? "16px" : `calc(${toasterHeight}px + 2.5rem)`;
1011
+ });
1012
+ }
1013
+ }, [a1ToastGroups.length, toastCount]);
1014
+ return /* @__PURE__ */ jsx(
1015
+ Toaster$1,
1016
+ {
1017
+ ...props,
1018
+ onToastEvent: handleToastEvent,
1019
+ disableEvents: shouldDisableEvents,
1020
+ ref: mergedToasterRef
1021
+ }
1022
+ );
909
1023
  }
910
1024
  );
1025
+ Toaster.displayName = "Toaster";
911
1026
 
912
1027
  const toast = toast$1;
913
1028
 
914
1029
  export { Toaster as T, toast as t };
915
- //# sourceMappingURL=toast-D-wmh-pM.js.map
1030
+ //# sourceMappingURL=toast-BVHe-A2D.js.map