@fluentui/react-toast 9.0.5 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.json +87 -3
  2. package/CHANGELOG.md +31 -4
  3. package/lib/components/ToastContainer/useToastContainer.js +28 -11
  4. package/lib/components/ToastContainer/useToastContainer.js.map +1 -1
  5. package/lib/components/ToastContainer/useToastContainerStyles.styles.js +2 -2
  6. package/lib/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
  7. package/lib/components/ToastTrigger/useToastTrigger.js +1 -1
  8. package/lib/components/ToastTrigger/useToastTrigger.js.map +1 -1
  9. package/lib/components/Toaster/useToastAnnounce.js +47 -0
  10. package/lib/components/Toaster/useToastAnnounce.js.map +1 -0
  11. package/lib/components/Toaster/useToaster.js +32 -30
  12. package/lib/components/Toaster/useToaster.js.map +1 -1
  13. package/lib/components/Toaster/useToasterFocusManagement.js +85 -0
  14. package/lib/components/Toaster/useToasterFocusManagement.js.map +1 -0
  15. package/lib/components/Toaster/useToasterStyles.styles.js +4 -1
  16. package/lib/components/Toaster/useToasterStyles.styles.js.map +1 -1
  17. package/lib/state/useToaster.js +24 -6
  18. package/lib/state/useToaster.js.map +1 -1
  19. package/lib-commonjs/components/ToastContainer/useToastContainer.js +28 -11
  20. package/lib-commonjs/components/ToastContainer/useToastContainer.js.map +1 -1
  21. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js +3 -3
  22. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
  23. package/lib-commonjs/components/ToastTrigger/useToastTrigger.js +1 -1
  24. package/lib-commonjs/components/ToastTrigger/useToastTrigger.js.map +1 -1
  25. package/lib-commonjs/components/Toaster/useToastAnnounce.js +50 -0
  26. package/lib-commonjs/components/Toaster/useToastAnnounce.js.map +1 -0
  27. package/lib-commonjs/components/Toaster/useToaster.js +31 -29
  28. package/lib-commonjs/components/Toaster/useToaster.js.map +1 -1
  29. package/lib-commonjs/components/Toaster/useToasterFocusManagement.js +92 -0
  30. package/lib-commonjs/components/Toaster/useToasterFocusManagement.js.map +1 -0
  31. package/lib-commonjs/components/Toaster/useToasterStyles.styles.js +4 -1
  32. package/lib-commonjs/components/Toaster/useToasterStyles.styles.js.map +1 -1
  33. package/lib-commonjs/state/useToaster.js +24 -6
  34. package/lib-commonjs/state/useToaster.js.map +1 -1
  35. package/package.json +9 -8
@@ -10,50 +10,52 @@ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildc
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
11
  const _reactUtilities = require("@fluentui/react-utilities");
12
12
  const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
+ const _reactTabster = require("@fluentui/react-tabster");
14
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
13
15
  const _state = require("../../state");
14
16
  const _toastContainer = require("../ToastContainer");
17
+ const _useToasterFocusManagement = require("./useToasterFocusManagement");
18
+ const _useToastAnnounce = require("./useToastAnnounce");
15
19
  const useToaster_unstable = (props)=>{
16
20
  const { offset , announce: announceProp , ...rest } = props;
17
21
  const announceRef = _react.useRef(()=>null);
18
- const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus } = (0, _state.useToaster)(rest);
22
+ const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus , closeAllToasts } = (0, _state.useToaster)(rest);
19
23
  const announce = _react.useCallback((message, options)=>announceRef.current(message, options), []);
20
24
  const { dir } = (0, _reactSharedContexts.useFluent_unstable)();
21
25
  const rootProps = (0, _reactUtilities.getNativeElementProps)('div', rest);
22
- // Adds native HTML focusin/focusout listeners
23
- // https://github.com/facebook/react/issues/25194
24
- const focusListenerRef = _react.useCallback((el)=>{
25
- if (el) {
26
- el.addEventListener('focusin', (e)=>{
27
- if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
28
- pauseAllToasts();
29
- }
30
- });
31
- el.addEventListener('focusout', (e)=>{
32
- if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
33
- playAllToasts();
34
- tryRestoreFocus();
35
- }
36
- });
26
+ const focusableGroupAttr = (0, _reactTabster.useFocusableGroup)({
27
+ tabBehavior: 'limited-trap-focus',
28
+ ignoreDefaultKeydown: {
29
+ Escape: true
37
30
  }
38
- }, [
39
- playAllToasts,
40
- pauseAllToasts,
41
- tryRestoreFocus
42
- ]);
43
- const createPositionSlot = (toastPosition)=>{
31
+ });
32
+ const onKeyDown = (0, _reactUtilities.useEventCallback)((e)=>{
33
+ var _props_onKeyDown;
34
+ if (e.key === _keyboardKeys.Escape) {
35
+ e.preventDefault();
36
+ closeAllToasts();
37
+ }
38
+ (_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, e);
39
+ });
40
+ const usePositionSlot = (toastPosition)=>{
44
41
  var _toastsToRender_get;
42
+ const focusManagementRef = (0, _useToasterFocusManagement.useToasterFocusManagement_unstable)(pauseAllToasts, playAllToasts);
43
+ const { announceToast , toasterRef } = (0, _useToastAnnounce.useToastAnnounce)(announceProp !== null && announceProp !== void 0 ? announceProp : announce);
45
44
  return (0, _reactUtilities.resolveShorthand)(toastsToRender.has(toastPosition) ? rootProps : null, {
46
45
  defaultProps: {
47
- ref: focusListenerRef,
46
+ ref: (0, _reactUtilities.useMergedRefs)(focusManagementRef, toasterRef),
48
47
  children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ _react.createElement(_toastContainer.ToastContainer, {
49
48
  ...toast,
50
49
  tryRestoreFocus: tryRestoreFocus,
51
50
  intent: toast.intent,
52
- announce: announce,
51
+ announce: announceToast,
53
52
  key: toast.toastId,
54
53
  visible: isToastVisible(toast.toastId)
55
54
  }, toast.content)),
56
- 'data-toaster-position': toastPosition
55
+ onKeyDown,
56
+ ...focusableGroupAttr,
57
+ 'data-toaster-position': toastPosition,
58
+ role: 'list'
57
59
  }
58
60
  });
59
61
  };
@@ -69,10 +71,10 @@ const useToaster_unstable = (props)=>{
69
71
  root: (0, _reactUtilities.resolveShorthand)(rootProps, {
70
72
  required: true
71
73
  }),
72
- bottomStart: createPositionSlot(_state.TOAST_POSITIONS.bottomStart),
73
- bottomEnd: createPositionSlot(_state.TOAST_POSITIONS.bottomEnd),
74
- topStart: createPositionSlot(_state.TOAST_POSITIONS.topStart),
75
- topEnd: createPositionSlot(_state.TOAST_POSITIONS.topEnd),
74
+ bottomStart: usePositionSlot(_state.TOAST_POSITIONS.bottomStart),
75
+ bottomEnd: usePositionSlot(_state.TOAST_POSITIONS.bottomEnd),
76
+ topStart: usePositionSlot(_state.TOAST_POSITIONS.topStart),
77
+ topEnd: usePositionSlot(_state.TOAST_POSITIONS.topEnd),
76
78
  announceRef,
77
79
  offset,
78
80
  announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,
@@ -1 +1 @@
1
- {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, isHTMLElement, resolveShorthand } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { TOAST_POSITIONS, useToaster } from '../../state';\nimport { ToastContainer } from '../ToastContainer';\n/**\n * Create the state required to render Toaster.\n *\n * @param props - props from this instance of Toaster\n */ export const useToaster_unstable = (props)=>{\n const { offset , announce: announceProp , ...rest } = props;\n const announceRef = React.useRef(()=>null);\n const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus } = useToaster(rest);\n const announce = React.useCallback((message, options)=>announceRef.current(message, options), []);\n const { dir } = useFluent();\n const rootProps = getNativeElementProps('div', rest);\n // Adds native HTML focusin/focusout listeners\n // https://github.com/facebook/react/issues/25194\n const focusListenerRef = React.useCallback((el)=>{\n if (el) {\n el.addEventListener('focusin', (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n pauseAllToasts();\n }\n });\n el.addEventListener('focusout', (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n playAllToasts();\n tryRestoreFocus();\n }\n });\n }\n }, [\n playAllToasts,\n pauseAllToasts,\n tryRestoreFocus\n ]);\n const createPositionSlot = (toastPosition)=>{\n var _toastsToRender_get;\n return resolveShorthand(toastsToRender.has(toastPosition) ? rootProps : null, {\n defaultProps: {\n ref: focusListenerRef,\n children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ React.createElement(ToastContainer, {\n ...toast,\n tryRestoreFocus: tryRestoreFocus,\n intent: toast.intent,\n announce: announce,\n key: toast.toastId,\n visible: isToastVisible(toast.toastId)\n }, toast.content)),\n 'data-toaster-position': toastPosition\n }\n });\n };\n return {\n dir,\n components: {\n root: 'div',\n bottomStart: 'div',\n bottomEnd: 'div',\n topStart: 'div',\n topEnd: 'div'\n },\n root: resolveShorthand(rootProps, {\n required: true\n }),\n bottomStart: createPositionSlot(TOAST_POSITIONS.bottomStart),\n bottomEnd: createPositionSlot(TOAST_POSITIONS.bottomEnd),\n topStart: createPositionSlot(TOAST_POSITIONS.topStart),\n topEnd: createPositionSlot(TOAST_POSITIONS.topEnd),\n announceRef,\n offset,\n announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,\n renderAriaLive: !announceProp\n };\n};\n"],"names":["useToaster_unstable","props","offset","announce","announceProp","rest","announceRef","React","useRef","toastsToRender","isToastVisible","pauseAllToasts","playAllToasts","tryRestoreFocus","useToaster","useCallback","message","options","current","dir","useFluent","rootProps","getNativeElementProps","focusListenerRef","el","addEventListener","e","isHTMLElement","currentTarget","contains","relatedTarget","createPositionSlot","toastPosition","_toastsToRender_get","resolveShorthand","has","defaultProps","ref","children","get","map","toast","createElement","ToastContainer","intent","key","toastId","visible","content","components","root","bottomStart","bottomEnd","topStart","topEnd","required","TOAST_POSITIONS","renderAriaLive"],"mappings":";;;;+BASiBA;;aAAAA;;;6DATM;gCACgD;qCACvB;uBACJ;gCACb;AAKpB,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,MAAM,EAAEC,OAAM,EAAGC,UAAUC,aAAY,EAAG,GAAGC,MAAM,GAAGJ;IACtD,MAAMK,cAAcC,OAAMC,MAAM,CAAC,IAAI,IAAI;IACzC,MAAM,EAAEC,eAAc,EAAGC,eAAc,EAAGC,eAAc,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,IAAAA,iBAAU,EAACT;IAC3G,MAAMF,WAAWI,OAAMQ,WAAW,CAAC,CAACC,SAASC,UAAUX,YAAYY,OAAO,CAACF,SAASC,UAAU,EAAE;IAChG,MAAM,EAAEE,IAAG,EAAG,GAAGC,IAAAA,uCAAS;IAC1B,MAAMC,YAAYC,IAAAA,qCAAqB,EAAC,OAAOjB;IAC/C,8CAA8C;IAC9C,iDAAiD;IACjD,MAAMkB,mBAAmBhB,OAAMQ,WAAW,CAAC,CAACS,KAAK;QAC7C,IAAIA,IAAI;YACJA,GAAGC,gBAAgB,CAAC,WAAW,CAACC,IAAI;gBAChC,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAK,CAACF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;oBACtHnB;gBACJ,CAAC;YACL;YACAa,GAAGC,gBAAgB,CAAC,YAAY,CAACC,IAAI;gBACjC,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAK,CAACF,EAAEE,aAAa,CA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1
+ {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useFocusableGroup } from '@fluentui/react-tabster';\nimport { Escape } from '@fluentui/keyboard-keys';\nimport { TOAST_POSITIONS, useToaster } from '../../state';\nimport { ToastContainer } from '../ToastContainer';\nimport { useToasterFocusManagement_unstable } from './useToasterFocusManagement';\nimport { useToastAnnounce } from './useToastAnnounce';\n/**\n * Create the state required to render Toaster.\n *\n * @param props - props from this instance of Toaster\n */ export const useToaster_unstable = (props)=>{\n const { offset , announce: announceProp , ...rest } = props;\n const announceRef = React.useRef(()=>null);\n const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus , closeAllToasts } = useToaster(rest);\n const announce = React.useCallback((message, options)=>announceRef.current(message, options), []);\n const { dir } = useFluent();\n const rootProps = getNativeElementProps('div', rest);\n const focusableGroupAttr = useFocusableGroup({\n tabBehavior: 'limited-trap-focus',\n ignoreDefaultKeydown: {\n Escape: true\n }\n });\n const onKeyDown = useEventCallback((e)=>{\n var _props_onKeyDown;\n if (e.key === Escape) {\n e.preventDefault();\n closeAllToasts();\n }\n (_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, e);\n });\n const usePositionSlot = (toastPosition)=>{\n var _toastsToRender_get;\n const focusManagementRef = useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts);\n const { announceToast , toasterRef } = useToastAnnounce(announceProp !== null && announceProp !== void 0 ? announceProp : announce);\n return resolveShorthand(toastsToRender.has(toastPosition) ? rootProps : null, {\n defaultProps: {\n ref: useMergedRefs(focusManagementRef, toasterRef),\n children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ React.createElement(ToastContainer, {\n ...toast,\n tryRestoreFocus: tryRestoreFocus,\n intent: toast.intent,\n announce: announceToast,\n key: toast.toastId,\n visible: isToastVisible(toast.toastId)\n }, toast.content)),\n onKeyDown,\n ...focusableGroupAttr,\n 'data-toaster-position': toastPosition,\n role: 'list'\n }\n });\n };\n return {\n dir,\n components: {\n root: 'div',\n bottomStart: 'div',\n bottomEnd: 'div',\n topStart: 'div',\n topEnd: 'div'\n },\n root: resolveShorthand(rootProps, {\n required: true\n }),\n bottomStart: usePositionSlot(TOAST_POSITIONS.bottomStart),\n bottomEnd: usePositionSlot(TOAST_POSITIONS.bottomEnd),\n topStart: usePositionSlot(TOAST_POSITIONS.topStart),\n topEnd: usePositionSlot(TOAST_POSITIONS.topEnd),\n announceRef,\n offset,\n announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,\n renderAriaLive: !announceProp\n };\n};\n"],"names":["useToaster_unstable","props","offset","announce","announceProp","rest","announceRef","React","useRef","toastsToRender","isToastVisible","pauseAllToasts","playAllToasts","tryRestoreFocus","closeAllToasts","useToaster","useCallback","message","options","current","dir","useFluent","rootProps","getNativeElementProps","focusableGroupAttr","useFocusableGroup","tabBehavior","ignoreDefaultKeydown","Escape","onKeyDown","useEventCallback","e","_props_onKeyDown","key","preventDefault","call","usePositionSlot","toastPosition","_toastsToRender_get","focusManagementRef","useToasterFocusManagement_unstable","announceToast","toasterRef","useToastAnnounce","resolveShorthand","has","defaultProps","ref","useMergedRefs","children","get","map","toast","createElement","ToastContainer","intent","toastId","visible","content","role","components","root","bottomStart","bottomEnd","topStart","topEnd","required","TOAST_POSITIONS","renderAriaLive"],"mappings":";;;;+BAaiBA;;aAAAA;;;6DAbM;gCACkE;qCACzC;8BACd;8BACX;uBACqB;gCACb;2CACoB;kCAClB;AAKtB,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,MAAM,EAAEC,OAAM,EAAGC,UAAUC,aAAY,EAAG,GAAGC,MAAM,GAAGJ;IACtD,MAAMK,cAAcC,OAAMC,MA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KAAK,IAAI,KAAK,IAAIA,oBAAoBa,GAAG,CAAC,CAACC,QAAQ,WAAW,GAAG7C,OAAM8C,aAAa,CAACC,8BAAc,EAAE;wBACrM,GAAGF,KAAK;wBACRvC,iBAAiBA;wBACjB0C,QAAQH,MAAMG,MAAM;wBACpBpD,UAAUsC;wBACVR,KAAKmB,MAAMI,OAAO;wBAClBC,SAAS/C,eAAe0C,MAAMI,OAAO;oBACzC,GAAGJ,MAAMM,OAAO,EAAE;gBACtB7B;gBACA,GAAGL,kBAAkB;gBACrB,yBAAyBa;gBACzBsB,MAAM;YACV;QACJ;IACJ;IACA,OAAO;QACHvC;QACAwC,YAAY;YACRC,MAAM;YACNC,aAAa;YACbC,WAAW;YACXC,UAAU;YACVC,QAAQ;QACZ;QACAJ,MAAMjB,IAAAA,gCAAgB,EAACtB,WAAW;YAC9B4C,UAAU,IAAI;QAClB;QACAJ,aAAa1B,gBAAgB+B,sBAAe,CAACL,WAAW;QACxDC,WAAW3B,gBAAgB+B,sBAAe,CAACJ,SAAS;QACpDC,UAAU5B,gBAAgB+B,sBAAe,CAACH,QAAQ;QAClDC,QAAQ7B,gBAAgB+B,sBAAe,CAACF,MAAM;QAC9C3D;QACAJ;QACAC,UAAUC,iBAAiB,IAAI,IAAIA,iBAAiB,KAAK,IAAIA,eAAeD,QAAQ;QACpFiE,gBAAgB,CAAChE;IACrB;AACJ"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useToasterFocusManagement_unstable", {
6
+ enumerable: true,
7
+ get: ()=>useToasterFocusManagement_unstable
8
+ });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _reactUtilities = require("@fluentui/react-utilities");
11
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
12
+ const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
14
+ const _toastContainer = require("../ToastContainer");
15
+ const noop = ()=>undefined;
16
+ function useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts) {
17
+ const { targetDocument } = (0, _reactSharedContexts.useFluent_unstable)();
18
+ const cleanupListenersRef = _react.useRef(noop);
19
+ return _react.useCallback((el)=>{
20
+ if (!el || !targetDocument) {
21
+ cleanupListenersRef.current();
22
+ cleanupListenersRef.current = noop;
23
+ return;
24
+ }
25
+ const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {
26
+ acceptNode (node) {
27
+ if ((0, _reactUtilities.isHTMLElement)(node) && node.classList.contains(_toastContainer.toastContainerClassNames.root)) {
28
+ return NodeFilter.FILTER_ACCEPT;
29
+ }
30
+ return NodeFilter.FILTER_SKIP;
31
+ }
32
+ });
33
+ /**
34
+ * FIXME: https://github.com/microsoft/tabster/issues/299
35
+ * Toasts should be arrow navigable and focus should be trapped in a stack of tasts
36
+ * This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers
37
+ * Once tabster fully supports this use case, remove this hook
38
+ */ const keydownListener = (e)=>{
39
+ const { target , key } = e;
40
+ if (!(0, _reactUtilities.isHTMLElement)(target)) {
41
+ return;
42
+ }
43
+ if (key === _keyboardKeys.ArrowDown) {
44
+ toastContainerWalker.currentNode = target;
45
+ let nextToastContainer = toastContainerWalker.nextNode();
46
+ if (!nextToastContainer) {
47
+ toastContainerWalker.currentNode = el;
48
+ nextToastContainer = toastContainerWalker.nextNode();
49
+ }
50
+ if ((0, _reactUtilities.isHTMLElement)(nextToastContainer)) {
51
+ nextToastContainer.focus();
52
+ }
53
+ }
54
+ if (key === _keyboardKeys.ArrowUp) {
55
+ toastContainerWalker.currentNode = target;
56
+ let prevToastContainer = toastContainerWalker.previousNode();
57
+ if (prevToastContainer && prevToastContainer.contains(target)) {
58
+ prevToastContainer = toastContainerWalker.previousNode();
59
+ }
60
+ if (!prevToastContainer) {
61
+ toastContainerWalker.currentNode = el;
62
+ prevToastContainer = toastContainerWalker.lastChild();
63
+ }
64
+ if ((0, _reactUtilities.isHTMLElement)(prevToastContainer)) {
65
+ prevToastContainer.focus();
66
+ }
67
+ }
68
+ };
69
+ const focusInListener = (e)=>{
70
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
71
+ pauseAllToasts();
72
+ }
73
+ };
74
+ const focusOutListener = (e)=>{
75
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
76
+ playAllToasts();
77
+ }
78
+ };
79
+ el.addEventListener('keydown', keydownListener);
80
+ el.addEventListener('focusin', focusInListener);
81
+ el.addEventListener('focusout', focusOutListener);
82
+ cleanupListenersRef.current = ()=>{
83
+ el.removeEventListener('keydown', keydownListener);
84
+ el.removeEventListener('focusin', focusInListener);
85
+ el.removeEventListener('focusout', focusOutListener);
86
+ };
87
+ }, [
88
+ targetDocument,
89
+ pauseAllToasts,
90
+ playAllToasts
91
+ ]);
92
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useToasterFocusManagement.js"],"sourcesContent":["import { isHTMLElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowDown, ArrowUp } from '@fluentui/keyboard-keys';\nimport { toastContainerClassNames } from '../ToastContainer';\nconst noop = ()=>undefined;\n/**\n * @internal\n */ export function useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts) {\n const { targetDocument } = useFluent();\n const cleanupListenersRef = React.useRef(noop);\n return React.useCallback((el)=>{\n if (!el || !targetDocument) {\n cleanupListenersRef.current();\n cleanupListenersRef.current = noop;\n return;\n }\n const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {\n acceptNode (node) {\n if (isHTMLElement(node) && node.classList.contains(toastContainerClassNames.root)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n return NodeFilter.FILTER_SKIP;\n }\n });\n /**\n * FIXME: https://github.com/microsoft/tabster/issues/299\n * Toasts should be arrow navigable and focus should be trapped in a stack of tasts\n * This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers\n * Once tabster fully supports this use case, remove this hook\n */ const keydownListener = (e)=>{\n const { target , key } = e;\n if (!isHTMLElement(target)) {\n return;\n }\n if (key === ArrowDown) {\n toastContainerWalker.currentNode = target;\n let nextToastContainer = toastContainerWalker.nextNode();\n if (!nextToastContainer) {\n toastContainerWalker.currentNode = el;\n nextToastContainer = toastContainerWalker.nextNode();\n }\n if (isHTMLElement(nextToastContainer)) {\n nextToastContainer.focus();\n }\n }\n if (key === ArrowUp) {\n toastContainerWalker.currentNode = target;\n let prevToastContainer = toastContainerWalker.previousNode();\n if (prevToastContainer && prevToastContainer.contains(target)) {\n prevToastContainer = toastContainerWalker.previousNode();\n }\n if (!prevToastContainer) {\n toastContainerWalker.currentNode = el;\n prevToastContainer = toastContainerWalker.lastChild();\n }\n if (isHTMLElement(prevToastContainer)) {\n prevToastContainer.focus();\n }\n }\n };\n const focusInListener = (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n pauseAllToasts();\n }\n };\n const focusOutListener = (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n playAllToasts();\n }\n };\n el.addEventListener('keydown', keydownListener);\n el.addEventListener('focusin', focusInListener);\n el.addEventListener('focusout', focusOutListener);\n cleanupListenersRef.current = ()=>{\n el.removeEventListener('keydown', keydownListener);\n el.removeEventListener('focusin', focusInListener);\n el.removeEventListener('focusout', focusOutListener);\n };\n }, [\n targetDocument,\n pauseAllToasts,\n playAllToasts\n ]);\n}\n"],"names":["useToasterFocusManagement_unstable","noop","undefined","pauseAllToasts","playAllToasts","targetDocument","useFluent","cleanupListenersRef","React","useRef","useCallback","el","current","toastContainerWalker","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","isHTMLElement","classList","contains","toastContainerClassNames","root","FILTER_ACCEPT","FILTER_SKIP","keydownListener","e","target","key","ArrowDown","currentNode","nextToastContainer","nextNode","focus","ArrowUp","prevToastContainer","previousNode","lastChild","focusInListener","currentTarget","relatedTarget","focusOutListener","addEventListener","removeEventListener"],"mappings":";;;;+BAQoBA;;aAAAA;;;gCARU;6DACP;qCACyB;8BACb;gCACM;AACzC,MAAMC,OAAO,IAAIC;AAGN,SAASF,mCAAmCG,cAAc,EAAEC,aAAa,EAAE;IAClF,MAAM,EAAEC,eAAc,EAAG,GAAGC,IAAAA,uCAAS;IACrC,MAAMC,sBAAsBC,OAAMC,MAAM,CAACR;IACzC,OAAOO,OAAME,WAAW,CAAC,CAACC,KAAK;QAC3B,IAAI,CAACA,MAAM,CAACN,gBAAgB;YACxBE,oBAAoBK,OAAO;YAC3BL,oBAAoBK,OAAO,GAAGX;YAC9B;QACJ,CAAC;QACD,MAAMY,uBAAuBR,eAAeS,gBAAgB,CAACH,IAAII,WAAWC,YAAY,EAAE;YACtFC,YAAYC,IAAI,EAAE;gBACd,IAAIC,IAAAA,6BAAa,EAACD,SAASA,KAAKE,SAAS,CAACC,QAAQ,CAACC,wCAAwB,CAACC,IAAI,GAAG;oBAC/E,OAAOR,WAAWS,aAAa;gBACnC,CAAC;gBACD,OAAOT,WAAWU,WAAW;YACjC;QACJ;QACA;;;;;OAKD,GAAG,MAAMC,kBAAkB,CAACC,IAAI;YAC3B,MAAM,EAAEC,OAAM,EAAGC,IAAG,EAAG,GAAGF;YAC1B,IAAI,CAACR,IAAAA,6BAAa,EAACS,SAAS;gBACxB;YACJ,CAAC;YACD,IAAIC,QAAQC,uBAAS,EAAE;gBACnBjB,qBAAqBkB,WAAW,GAAGH;gBACnC,IAAII,qBAAqBnB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oBK,OAAO,GAAG,IAAI;YAC9BD,GAAGiC,mBAAmB,CAAC,WAAWlB;YAClCf,GAAGiC,mBAAmB,CAAC,WAAWL;YAClC5B,GAAGiC,mBAAmB,CAAC,YAAYF;QACvC;IACJ,GAAG;QACCrC;QACAF;QACAC;KACH;AACL"}
@@ -14,7 +14,6 @@ _export(exports, {
14
14
  });
15
15
  const _react = require("@griffel/react");
16
16
  const _index = require("../../state/index");
17
- var _state_bottomStart, _state_bottomEnd, _state_topStart, _state_topEnd;
18
17
  const toasterClassNames = {
19
18
  root: 'fui-Toaster'
20
19
  };
@@ -27,24 +26,28 @@ const useToasterStyles_unstable = (state)=>{
27
26
  const rootBaseClassName = useRootBaseClassName();
28
27
  const className = (0, _react.mergeClasses)(toasterClassNames.root, rootBaseClassName, state.root.className);
29
28
  if (state.bottomStart) {
29
+ var _state_bottomStart;
30
30
  state.bottomStart.className = className;
31
31
  var _style;
32
32
  (_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};
33
33
  Object.assign(state.bottomStart.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.bottomStart, state.dir, state.offset));
34
34
  }
35
35
  if (state.bottomEnd) {
36
+ var _state_bottomEnd;
36
37
  state.bottomEnd.className = className;
37
38
  var _style1;
38
39
  (_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};
39
40
  Object.assign(state.bottomEnd.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.bottomEnd, state.dir, state.offset));
40
41
  }
41
42
  if (state.topStart) {
43
+ var _state_topStart;
42
44
  state.topStart.className = className;
43
45
  var _style2;
44
46
  (_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};
45
47
  Object.assign(state.topStart.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.topStart, state.dir, state.offset));
46
48
  }
47
49
  if (state.topEnd) {
50
+ var _state_topEnd;
48
51
  state.topEnd.className = className;
49
52
  var _style3;
50
53
  (_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};
@@ -1 +1 @@
1
- {"version":3,"sources":["useToasterStyles.styles.js"],"sourcesContent":["var _state_bottomStart, _state_bottomEnd, _state_topStart, _state_topEnd;\nimport { __resetStyles, mergeClasses } from '@griffel/react';\nimport { TOAST_POSITIONS, getPositionStyles } from '../../state/index';\nexport const toasterClassNames = {\n root: 'fui-Toaster'\n};\n/**\n * Styles for the root slot\n */\nconst useRootBaseClassName = /*#__PURE__*/__resetStyles(\"r3hfdjz\", null, [\".r3hfdjz{position:fixed;width:292px;pointer-events:none;}\"]);\n/**\n * Apply styling to the Toaster slots based on the state\n */\nexport const useToasterStyles_unstable = state => {\n const rootBaseClassName = useRootBaseClassName();\n const className = mergeClasses(toasterClassNames.root, rootBaseClassName, state.root.className);\n if (state.bottomStart) {\n state.bottomStart.className = className;\n var _style;\n (_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};\n Object.assign(state.bottomStart.style, getPositionStyles(TOAST_POSITIONS.bottomStart, state.dir, state.offset));\n }\n if (state.bottomEnd) {\n state.bottomEnd.className = className;\n var _style1;\n (_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};\n Object.assign(state.bottomEnd.style, getPositionStyles(TOAST_POSITIONS.bottomEnd, state.dir, state.offset));\n }\n if (state.topStart) {\n state.topStart.className = className;\n var _style2;\n (_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};\n Object.assign(state.topStart.style, getPositionStyles(TOAST_POSITIONS.topStart, state.dir, state.offset));\n }\n if (state.topEnd) {\n state.topEnd.className = className;\n var _style3;\n (_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};\n Object.assign(state.topEnd.style, getPositionStyles(TOAST_POSITIONS.topEnd, state.dir, state.offset));\n }\n return state;\n};\n//# sourceMappingURL=useToasterStyles.styles.js.map"],"names":["toasterClassNames","useToasterStyles_unstable","_state_bottomStart","_state_bottomEnd","_state_topStart","_state_topEnd","root","useRootBaseClassName","__resetStyles","state","rootBaseClassName","className","mergeClasses","bottomStart","_style","style","Object","assign","getPositionStyles","TOAST_POSITIONS","dir","offset","bottomEnd","_style1","topStart","_style2","topEnd","_style3"],"mappings":";;;;;;;;;;;IAGaA,iBAAiB,MAAjBA;IAUAC,yBAAyB,MAAzBA;;uBAZ+B;uBACO;AAFnD,IAAIC,oBAAoBC,kBAAkBC,iBAAiBC;AAGpD,MAAML,oBAAoB;IAC/BM,MAAM;AACR;AACA;;CAEC,GACD,MAAMC,uBAAuB,WAAW,GAAEC,IAAAA,uBAAa,EAAC,WAAW,IAAI,EAAE;IAAC;CAA4D;AAI/H,MAAMP,4BAA4BQ,CAAAA,QAAS;IAChD,MAAMC,oBAAoBH;IAC1B,MAAMI,YAAYC,IAAAA,mBAAY,EAACZ,kBAAkBM,IAAI,EAAEI,mBAAmBD,MAAMH,IAAI,CAACK,SAAS;IAC9F,IAAIF,MAAMI,WAAW,EAAE;QACrBJ,MAAMI,WAAW,CAACF,SAAS,GAAGA;QAC9B,IAAIG;QACHA,CAAAA,SAAS,AAACZ,CAAAA,qBAAqBO,MAAMI,WAAW,AAAD,EAAGE,KAAK,AAAD,MAAO,IAAI,IAAID,WAAW,KAAK,IAAIA,SAASZ,mBAAmBa,KAAK,GAAG,CAAC,CAAC;QAChIC,OAAOC,MAAM,CAACR,MAAMI,WAAW,CAACE,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACN,WAAW,EAAEJ,MAAMW,GAAG,EAAEX,MAAMY,MAAM;IAC/G,CAAC;IACD,IAAIZ,MAAMa,SAAS,EAAE;QACnBb,MAAMa,SAAS,CAACX,SAAS,GAAGA;QAC5B,IAAIY;QACHA,C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el/react';\nimport { TOAST_POSITIONS, getPositionStyles } from '../../state/index';\nexport const toasterClassNames = {\n root: 'fui-Toaster'\n};\n/**\n * Styles for the root slot\n */\nconst useRootBaseClassName = /*#__PURE__*/__resetStyles(\"r3hfdjz\", null, [\".r3hfdjz{position:fixed;width:292px;pointer-events:none;}\"]);\n/**\n * Apply styling to the Toaster slots based on the state\n */\nexport const useToasterStyles_unstable = state => {\n const rootBaseClassName = useRootBaseClassName();\n const className = mergeClasses(toasterClassNames.root, rootBaseClassName, state.root.className);\n if (state.bottomStart) {\n var _state_bottomStart;\n state.bottomStart.className = className;\n var _style;\n (_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};\n Object.assign(state.bottomStart.style, getPositionStyles(TOAST_POSITIONS.bottomStart, state.dir, state.offset));\n }\n if (state.bottomEnd) {\n var _state_bottomEnd;\n state.bottomEnd.className = className;\n var _style1;\n (_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};\n Object.assign(state.bottomEnd.style, getPositionStyles(TOAST_POSITIONS.bottomEnd, state.dir, state.offset));\n }\n if (state.topStart) {\n var _state_topStart;\n state.topStart.className = className;\n var _style2;\n (_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};\n Object.assign(state.topStart.style, getPositionStyles(TOAST_POSITIONS.topStart, state.dir, state.offset));\n }\n if (state.topEnd) {\n var _state_topEnd;\n state.topEnd.className = className;\n var _style3;\n (_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};\n Object.assign(state.topEnd.style, getPositionStyles(TOAST_POSITIONS.topEnd, state.dir, state.offset));\n }\n return state;\n};\n//# sourceMappingURL=useToasterStyles.styles.js.map"],"names":["toasterClassNames","useToasterStyles_unstable","root","useRootBaseClassName","__resetStyles","state","rootBaseClassName","className","mergeClasses","bottomStart","_state_bottomStart","_style","style","Object","assign","getPositionStyles","TOAST_POSITIONS","dir","offset","bottomEnd","_state_bottomEnd","_style1","topStart","_state_topStart","_style2","topEnd","_state_topEnd","_style3"],"mappings":";;;;;;;;;;;IAEaA,iBAAiB,MAAjBA;IAUAC,yBAAyB,MAAzBA;;uBAZ+B;uBACO;AAC5C,MAAMD,oBAAoB;IAC/BE,MAAM;AACR;AACA;;CAEC,GACD,MAAMC,uBAAuB,WAAW,GAAEC,IAAAA,uBAAa,EAAC,WAAW,IAAI,EAAE;IAAC;CAA4D;AAI/H,MAAMH,4BAA4BI,CAAAA,QAAS;IAChD,MAAMC,oBAAoBH;IAC1B,MAAMI,YAAYC,IAAAA,mBAAY,EAACR,kBAAkBE,IAAI,EAAEI,mBAAmBD,MAAMH,IAAI,CAACK,SAAS;IAC9F,IAAIF,MAAMI,WAAW,EAAE;QACrB,IAAIC;QACJL,MAAMI,WAAW,CAACF,SAAS,GAAGA;QAC9B,IAAII;QACHA,CAAAA,SAAS,AAACD,CAAAA,qBAAqBL,MAAMI,WAAW,AAAD,EAAGG,KAAK,AAAD,MAAO,IAAI,IAAID,WAAW,KAAK,IAAIA,SAASD,mBAAmBE,KAAK,GAAG,CAAC,CAAC;QAChIC,OAAOC,MAAM,CAACT,MAAMI,WAAW,CAACG,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACP,WAAW,EAAEJ,MAAMY,GAAG,EAAEZ,MAAMa,MAAM;IAC/G,CAAC;IACD,IAAIb,MAAMc,SAAS,EAAE;QACnB,IAAIC;QACJf,MAAMc,SAAS,CAACZ,SAAS,GAAGA;QAC5B,IAAIc;QACHA,CAAAA,UAAU,AAACD,CAAAA,mBAAmBf,MAAMc,SAAS,AAAD,EAAGP,KAAK,AAAD,MAAO,IAAI,IAAIS,YAAY,KAAK,IAAIA,UAAUD,iBAAiBR,KAAK,GAAG,CAAC,CAAC;QAC7HC,OAAOC,MAAM,CAACT,MAAMc,SAAS,CAACP,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACG,SAAS,EAAEd,MAAMY,GAAG,EAAEZ,MAAMa,MAAM;IAC3G,CAAC;IACD,IAAIb,MAAMiB,QAAQ,EAAE;QAClB,IAAIC;QACJlB,MAAMiB,QAAQ,CAACf,SAAS,GAAGA;QAC3B,IAAIiB;QACHA,CAAAA,UAAU,AAACD,CAAAA,kBAAkBlB,MAAMiB,QAAQ,AAAD,EAAGV,KAAK,AAAD,MAAO,IAAI,IAAIY,YAAY,KAAK,IAAIA,UAAUD,gBAAgBX,KAAK,GAAG,CAAC,CAAC;QAC1HC,OAAOC,MAAM,CAACT,MAAMiB,QAAQ,CAACV,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACM,QAAQ,EAAEjB,MAAMY,GAAG,EAAEZ,MAAMa,MAAM;IACzG,CAAC;IACD,IAAIb,MAAMoB,MAAM,EAAE;QAChB,IAAIC;QACJrB,MAAMoB,MAAM,CAAClB,SAAS,GAAGA;QACzB,IAAIoB;QACHA,CAAAA,UAAU,AAACD,CAAAA,gBAAgBrB,MAAMoB,MAAM,AAAD,EAAGb,KAAK,AAAD,MAAO,IAAI,IAAIe,YAAY,KAAK,IAAIA,UAAUD,cAAcd,KAAK,GAAG,CAAC,CAAC;QACpHC,OAAOC,MAAM,CAACT,MAAMoB,MAAM,CAACb,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACS,MAAM,EAAEpB,MAAMY,GAAG,EAAEZ,MAAMa,MAAM;IACrG,CAAC;IACD,OAAOb;AACT,GACA,mDAAmD"}
@@ -27,11 +27,6 @@ function useToaster(options = {}) {
27
27
  return shortcuts.focus(e);
28
28
  }
29
29
  });
30
- const tryRestoreFocus = _react.useCallback(()=>{
31
- var _lastActiveElementRef_current;
32
- (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
33
- lastActiveElementRef.current = null;
34
- }, []);
35
30
  const pauseAllToasts = _react.useCallback(()=>{
36
31
  toaster.visibleToasts.forEach((toastId)=>{
37
32
  var _toast_imperativeRef_current;
@@ -67,6 +62,28 @@ function useToaster(options = {}) {
67
62
  }, [
68
63
  toaster
69
64
  ]);
65
+ const tryRestoreFocus = _react.useCallback(()=>{
66
+ const mostRecentToast = getMostRecentVisibleToast();
67
+ if (mostRecentToast === null || mostRecentToast === void 0 ? void 0 : mostRecentToast.imperativeRef.current) {
68
+ mostRecentToast.imperativeRef.current.focus();
69
+ } else {
70
+ var _lastActiveElementRef_current;
71
+ (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
72
+ lastActiveElementRef.current = null;
73
+ }
74
+ }, [
75
+ getMostRecentVisibleToast
76
+ ]);
77
+ const closeAllToasts = _react.useCallback(()=>{
78
+ toaster.visibleToasts.forEach((toastId)=>{
79
+ const toast = toaster.toasts.get(toastId);
80
+ toast === null || toast === void 0 ? void 0 : toast.close();
81
+ });
82
+ tryRestoreFocus();
83
+ }, [
84
+ toaster,
85
+ tryRestoreFocus
86
+ ]);
70
87
  _react.useEffect(()=>{
71
88
  if (!targetDocument) {
72
89
  return;
@@ -166,6 +183,7 @@ function useToaster(options = {}) {
166
183
  toastsToRender,
167
184
  pauseAllToasts,
168
185
  playAllToasts,
169
- tryRestoreFocus
186
+ tryRestoreFocus,
187
+ closeAllToasts
170
188
  };
171
189
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport { EVENTS } from './constants';\nexport function useToaster(options = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId , shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(()=>createToaster(options));\n const { targetDocument } = useFluent();\n const lastActiveElementRef = React.useRef(null);\n const isCorrectToaster = useEventCallback((toasterId)=>{\n return toasterId === userToasterId;\n });\n const isFocusShortcut = useEventCallback((e)=>{\n if (shortcuts === null || shortcuts === void 0 ? void 0 : shortcuts.focus) {\n return shortcuts.focus(e);\n }\n });\n const tryRestoreFocus = React.useCallback(()=>{\n var _lastActiveElementRef_current;\n (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();\n lastActiveElementRef.current = null;\n }, []);\n const pauseAllToasts = React.useCallback(()=>{\n toaster.visibleToasts.forEach((toastId)=>{\n var _toast_imperativeRef_current;\n const toast = toaster.toasts.get(toastId);\n (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();\n });\n }, [\n toaster\n ]);\n const playAllToasts = React.useCallback(()=>{\n toaster.visibleToasts.forEach((toastId)=>{\n var _toast_imperativeRef_current;\n const toast = toaster.toasts.get(toastId);\n (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();\n });\n }, [\n toaster\n ]);\n const getMostRecentVisibleToast = React.useCallback(()=>{\n return Array.from(toaster.visibleToasts).reduce((cur, next)=>{\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n if (!cur) {\n return toast;\n }\n if (cur.order < (toast === null || toast === void 0 ? void 0 : toast.order)) {\n return toast;\n }\n return cur;\n }, undefined);\n }, [\n toaster\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n const addToastListener = (eventType, callback)=>{\n const listener = (e)=>{\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n callback(e);\n forceUpdate();\n };\n targetDocument.addEventListener(eventType, listener);\n return ()=>targetDocument.removeEventListener(eventType, listener);\n };\n const buildToast = (e)=>{\n toaster.buildToast(e.detail, forceUpdate);\n };\n const dismissToast = (e)=>{\n toaster.dismissToast(e.detail.toastId);\n };\n const updateToast = (e)=>{\n toaster.updateToast(e.detail);\n };\n const dismissAllToasts = (e)=>{\n toaster.dismissAllToasts();\n };\n const pauseToast = (e)=>{\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n var _toast_imperativeRef_current;\n (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();\n }\n };\n const playToast = (e)=>{\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n var _toast_imperativeRef_current;\n (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();\n }\n };\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n const focusShortcutListener = (e)=>{\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n if (mostRecentToast) {\n var _mostRecentToast_imperativeRef_current;\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement) ? targetDocument.activeElement : null;\n (_mostRecentToast_imperativeRef_current = mostRecentToast.imperativeRef.current) === null || _mostRecentToast_imperativeRef_current === void 0 ? void 0 : _mostRecentToast_imperativeRef_current.focus();\n }\n }\n };\n targetDocument.addEventListener('keydown', focusShortcutListener);\n return ()=>{\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut\n ]);\n const toastsToRender = (()=>{\n if (!toaster) {\n return new Map();\n }\n const toRender = new Map();\n const toasts = Array.from(toaster.toasts.values());\n toasts.forEach((toast)=>{\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position).push(toast);\n } else {\n toRender.get(position).unshift(toast);\n }\n });\n return toRender;\n })();\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus\n };\n}\n"],"names":["useToaster","options","forceUpdate","useForceUpdate","toasterId","userToasterId","shortcuts","toaster","React","useState","createToaster","targetDocument","useFluent","lastActiveElementRef","useRef","isCorrectToaster","useEventCallback","isFocusShortcut","e","focus","tryRestoreFocus","useCallback","_lastActiveElementRef_current","current","pauseAllToasts","visibleToasts","forEach","toastId","_toast_imperativeRef_current","toast","toasts","get","imperativeRef","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","EVENTS","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","mostRecentToast","_mostRecentToast_imperativeRef_current","isHTMLElement","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":";;;;+BAKgBA;;aAAAA;;;6DALO;gCACyC;qCAChB;yBAClB;2BACP;AAChB,SAASA,WAAWC,UAAU,CAAC,CAAC,EAAE;IACrC,MAAMC,cAAcC,IAAAA,8BAAc;IAClC,MAAM,EAAEC,WAAWC,cAAa,EAAGC,UAAS,EAAG,GAAGL;IAClD,gEAAgE;IAChE,MAAM,CAACM,QAAQ,GAAGC,O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BU,OAAO,GAAGiD,IAAAA,6BAAa,EAAC7D,eAAe8D,aAAa,IAAI9D,eAAe8D,aAAa,GAAG,IAAI;oBAC/GF,CAAAA,yCAAyCD,gBAAgBtC,aAAa,CAACT,OAAO,AAAD,MAAO,IAAI,IAAIgD,2CAA2C,KAAK,IAAI,KAAK,IAAIA,uCAAuCpD,KAAK,EAAE;gBAC5M,CAAC;YACL,CAAC;QACL;QACAR,eAAeuC,gBAAgB,CAAC,WAAWmB;QAC3C,OAAO,IAAI;YACPX;YACAO;YACAJ;YACAE;YACAI;YACAC;YACAzD,eAAewC,mBAAmB,CAAC,WAAWkB;QAClD;IACJ,GAAG;QACC9D;QACAL;QACAS;QACAI;QACAS;QACAY;QACAnB;KACH;IACD,MAAMyD,iBAAiB,AAAC,CAAA,IAAI;QACxB,IAAI,CAACnE,SAAS;YACV,OAAO,IAAIoE;QACf,CAAC;QACD,MAAMC,WAAW,IAAID;QACrB,MAAM7C,SAASO,MAAMC,IAAI,CAAC/B,QAAQuB,MAAM,CAAC+C,MAAM;QAC/C/C,OAAOJ,OAAO,CAAC,CAACG,QAAQ;YACpB,MAAM,EAAEiD,SAAQ,EAAG,GAAGjD;YACtB+C,SAASG,GAAG,CAACD,aAAaF,SAASI,GAAG,CAACF,UAAU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBAC/BL,SAAS7C,GAAG,CAAC+C,UAAUI,IAAI,CAACrD;YAChC,OAAO;gBACH+C,SAAS7C,GAAG,CAAC+C,UAAUK,OAAO,CAACtD;YACnC,CAAC;QACL;QACA,OAAO+C;IACX,CAAA;IACA,OAAO;QACHQ,gBAAgB7E,QAAQ6E,cAAc;QACtCV;QACAlD;QACAU;QACAd;IACJ;AACJ"}
1
+ {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport { EVENTS } from './constants';\nexport function useToaster(options = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId , shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(()=>createToaster(options));\n const { targetDocument } = useFluent();\n const lastActiveElementRef = React.useRef(null);\n const isCorrectToaster = useEventCallback((toasterId)=>{\n return toasterId === userToasterId;\n });\n const isFocusShortcut = useEventCallback((e)=>{\n if (shortcuts === null || shortcuts === void 0 ? void 0 : shortcuts.focus) {\n return shortcuts.focus(e);\n }\n });\n const pauseAllToasts = React.useCallback(()=>{\n toaster.visibleToasts.forEach((toastId)=>{\n var _toast_imperativeRef_current;\n const toast = toaster.toasts.get(toastId);\n (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();\n });\n }, [\n toaster\n ]);\n const playAllToasts = React.useCallback(()=>{\n toaster.visibleToasts.forEach((toastId)=>{\n var _toast_imperativeRef_current;\n const toast = toaster.toasts.get(toastId);\n (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();\n });\n }, [\n toaster\n ]);\n const getMostRecentVisibleToast = React.useCallback(()=>{\n return Array.from(toaster.visibleToasts).reduce((cur, next)=>{\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n if (!cur) {\n return toast;\n }\n if (cur.order < (toast === null || toast === void 0 ? void 0 : toast.order)) {\n return toast;\n }\n return cur;\n }, undefined);\n }, [\n toaster\n ]);\n const tryRestoreFocus = React.useCallback(()=>{\n const mostRecentToast = getMostRecentVisibleToast();\n if (mostRecentToast === null || mostRecentToast === void 0 ? void 0 : mostRecentToast.imperativeRef.current) {\n mostRecentToast.imperativeRef.current.focus();\n } else {\n var _lastActiveElementRef_current;\n (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();\n lastActiveElementRef.current = null;\n }\n }, [\n getMostRecentVisibleToast\n ]);\n const closeAllToasts = React.useCallback(()=>{\n toaster.visibleToasts.forEach((toastId)=>{\n const toast = toaster.toasts.get(toastId);\n toast === null || toast === void 0 ? void 0 : toast.close();\n });\n tryRestoreFocus();\n }, [\n toaster,\n tryRestoreFocus\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n const addToastListener = (eventType, callback)=>{\n const listener = (e)=>{\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n callback(e);\n forceUpdate();\n };\n targetDocument.addEventListener(eventType, listener);\n return ()=>targetDocument.removeEventListener(eventType, listener);\n };\n const buildToast = (e)=>{\n toaster.buildToast(e.detail, forceUpdate);\n };\n const dismissToast = (e)=>{\n toaster.dismissToast(e.detail.toastId);\n };\n const updateToast = (e)=>{\n toaster.updateToast(e.detail);\n };\n const dismissAllToasts = (e)=>{\n toaster.dismissAllToasts();\n };\n const pauseToast = (e)=>{\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n var _toast_imperativeRef_current;\n (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();\n }\n };\n const playToast = (e)=>{\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n var _toast_imperativeRef_current;\n (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();\n }\n };\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n const focusShortcutListener = (e)=>{\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n if (mostRecentToast) {\n var _mostRecentToast_imperativeRef_current;\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement) ? targetDocument.activeElement : null;\n (_mostRecentToast_imperativeRef_current = mostRecentToast.imperativeRef.current) === null || _mostRecentToast_imperativeRef_current === void 0 ? void 0 : _mostRecentToast_imperativeRef_current.focus();\n }\n }\n };\n targetDocument.addEventListener('keydown', focusShortcutListener);\n return ()=>{\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut\n ]);\n const toastsToRender = (()=>{\n if (!toaster) {\n return new Map();\n }\n const toRender = new Map();\n const toasts = Array.from(toaster.toasts.values());\n toasts.forEach((toast)=>{\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position).push(toast);\n } else {\n toRender.get(position).unshift(toast);\n }\n });\n return toRender;\n })();\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n closeAllToasts\n };\n}\n"],"names":["useToaster","options","forceUpdate","useForceUpdate","toasterId","userToasterId","shortcuts","toaster","React","useState","createToaster","targetDocument","useFluent","lastActiveElementRef","useRef","isCorrectToaster","useEventCallback","isFocusShortcut","e","focus","pauseAllToasts","useCallback","visibleToasts","forEach","toastId","_toast_imperativeRef_current","toast","toasts","get","imperativeRef","current","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","tryRestoreFocus","mostRecentToast","_lastActiveElementRef_current","closeAllToasts","close","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","EVENTS","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","_mostRecentToast_imperativeRef_current","isHTMLElement","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":";;;;+BAKgBA;;aAAAA;;;6DALO;gCACyC;qCAChB;yBAClB;2BACP;AAChB,SAASA,WAAWC,UAAU,CAAC,CAAC,EAAE;IACrC,MAAMC,cAAcC,IAAAA,8BAAc;IAClC,MAAM,EAAEC,WAAWC,cAAa,EAAGC,UAAS,EAAG,GAAGL;IAClD,gEAAgE;IAChE,MAAM,CAACM,QAAQ,GAAGC,OAAMC,QAAQ,CAAC,IAAIC,IAAAA,sBAAa,EAACT;IACnD,MAAM,EAAEU,eAAc,EAAG,GAAGC,IAAAA,uCAAS;IACrC,MAAMC,uBAAuBL,OAAMM,MAAM,CAAC,IAAI;IAC9C,MAAMC,mBAAmBC,IAAAA,gCAAgB,EAAC,CAACZ,YAAY;QACnD,OAAOA,cAAcC;IACzB;IACA,MAAMY,kBAAkBD,IAAAA,gCAAgB,EAAC,CAACE,IAAI;QAC1C,IAAIZ,cAAc,IAAI,IAAIA,cAAc,KAAK,IAAI,KAAK,IAAIA,UAAUa,KAAK,EAAE;YACvE,OAAOb,UAAUa,KAAK,CAACD;QAC3B,CAAC;IACL;IACA,MAAME,iBAAiBZ,OAAMa,WAAW,CAAC,IAAI;QACzCd,QAAQe,aAAa,CAACC,OAAO,CAAC,CAACC,UAAU;YACrC,IAAIC;YACJ,MAAMC,QAAQnB,QAAQoB,MAAM,CAACC,GAAG,CAACJ;YAChCC,CAAAA,+BAA+BC,UAAU,IAAI,IAAIA,UAAU,KAAK,IAAI,KAAK,IAAIA,MAAMG,aAAa,CAACC,OAAO,AAAD,MAAO,IAAI,IAAIL,iCAAiC,KA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,CAAC;QACL;QACAR,eAAe0C,gBAAgB,CAAC,WAAWmB;QAC3C,OAAO,IAAI;YACPX;YACAO;YACAJ;YACAE;YACAI;YACAC;YACA5D,eAAe2C,mBAAmB,CAAC,WAAWkB;QAClD;IACJ,GAAG;QACCjE;QACAL;QACAS;QACAI;QACAK;QACAc;QACAjB;KACH;IACD,MAAM2D,iBAAiB,AAAC,CAAA,IAAI;QACxB,IAAI,CAACrE,SAAS;YACV,OAAO,IAAIsE;QACf,CAAC;QACD,MAAMC,WAAW,IAAID;QACrB,MAAMlD,SAASQ,MAAMC,IAAI,CAAC7B,QAAQoB,MAAM,CAACoD,MAAM;QAC/CpD,OAAOJ,OAAO,CAAC,CAACG,QAAQ;YACpB,MAAM,EAAEsD,SAAQ,EAAG,GAAGtD;YACtBoD,SAASG,GAAG,CAACD,aAAaF,SAASI,GAAG,CAACF,UAAU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBAC/BL,SAASlD,GAAG,CAACoD,UAAUI,IAAI,CAAC1D;YAChC,OAAO;gBACHoD,SAASlD,GAAG,CAACoD,UAAUK,OAAO,CAAC3D;YACnC,CAAC;QACL;QACA,OAAOoD;IACX,CAAA;IACA,OAAO;QACHQ,gBAAgB/E,QAAQ+E,cAAc;QACtCV;QACAxD;QACAY;QACAU;QACAG;IACJ;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-toast",
3
- "version": "9.0.5",
3
+ "version": "9.1.0",
4
4
  "description": "Toast component for Fluent UI",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -36,14 +36,15 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "react-transition-group": "^4.4.1",
39
- "@fluentui/react-aria": "^9.3.27",
39
+ "@fluentui/keyboard-keys": "^9.0.3",
40
+ "@fluentui/react-aria": "^9.3.28",
40
41
  "@fluentui/react-icons": "^2.0.207",
41
- "@fluentui/react-jsx-runtime": "9.0.0-alpha.12",
42
- "@fluentui/react-portal": "^9.3.3",
43
- "@fluentui/react-shared-contexts": "^9.6.0",
44
- "@fluentui/react-tabster": "^9.11.0",
45
- "@fluentui/react-theme": "^9.1.9",
46
- "@fluentui/react-utilities": "^9.10.1",
42
+ "@fluentui/react-jsx-runtime": "9.0.0-alpha.13",
43
+ "@fluentui/react-portal": "^9.3.5",
44
+ "@fluentui/react-shared-contexts": "^9.7.1",
45
+ "@fluentui/react-tabster": "^9.12.0",
46
+ "@fluentui/react-theme": "^9.1.10",
47
+ "@fluentui/react-utilities": "^9.11.0",
47
48
  "@griffel/react": "^1.5.7",
48
49
  "@swc/helpers": "^0.4.14"
49
50
  },