Initial commit

This commit is contained in:
schihei committed 2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 files changed
+5280367

No files matched your search

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Toaster", {
enumerable: true,
get: function() {
return Toaster;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _useToaster = require("./useToaster");
const _renderToaster = require("./renderToaster");
const _useToasterStylesstyles = require("./useToasterStyles.styles");
const Toaster = (props)=>{
const state = (0, _useToaster.useToaster_unstable)(props);
(0, _useToasterStylesstyles.useToasterStyles_unstable)(state);
(0, _reactsharedcontexts.useCustomStyleHook_unstable)('useToasterStyles_unstable')(state);
return (0, _renderToaster.renderToaster_unstable)(state);
};
Toaster.displayName = 'Toaster';
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/Toaster.tsx"],"sourcesContent":["import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';\nimport * as React from 'react';\n\nimport { useToaster_unstable } from './useToaster';\nimport { renderToaster_unstable } from './renderToaster';\nimport { useToasterStyles_unstable } from './useToasterStyles.styles';\nimport type { ToasterProps } from './Toaster.types';\n\n/**\n * Toaster component - renders a collection of toasts dispatched imperatively\n */\nexport const Toaster: React.FC<ToasterProps> = props => {\n const state = useToaster_unstable(props);\n\n useToasterStyles_unstable(state);\n useCustomStyleHook_unstable('useToasterStyles_unstable')(state);\n return renderToaster_unstable(state);\n};\n\nToaster.displayName = 'Toaster';\n"],"names":["Toaster","props","state","useToaster_unstable","useToasterStyles_unstable","useCustomStyleHook_unstable","renderToaster_unstable","displayName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWaA;;;eAAAA;;;;qCAX+B;iEACrB;4BAEa;+BACG;wCACG;AAMnC,MAAMA,UAAkCC,CAAAA;IAC7C,MAAMC,QAAQC,IAAAA,+BAAAA,EAAoBF;IAElCG,IAAAA,iDAAAA,EAA0BF;IAC1BG,IAAAA,gDAAAA,EAA4B,6BAA6BH;IACzD,OAAOI,IAAAA,qCAAAA,EAAuBJ;AAChC;AAEAF,QAAQO,WAAW,GAAG"}
@@ -0,0 +1,6 @@
/**
* State used in rendering Toaster
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/Toaster.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\nimport { ToasterOptions } from '../../state/types';\nimport { Announce, AriaLiveProps } from '../AriaLive';\n\nexport type ToasterSlots = {\n /**\n * NOTE: This root slot maps in exactly the same way to the containers rendered for each toast position\n * There is no intention (currently) to let users customize the div for each toast position.\n */\n root: Slot<'div'>;\n};\n\nexport type ToasterSlotsInternal = ToasterSlots & {\n bottomEnd?: Slot<'div'>;\n bottomStart?: Slot<'div'>;\n topEnd?: Slot<'div'>;\n topStart?: Slot<'div'>;\n top?: Slot<'div'>;\n bottom?: Slot<'div'>;\n};\n\n/**\n * Toaster Props\n */\nexport type ToasterProps = Omit<ComponentProps<ToasterSlots>, 'children'> &\n Partial<ToasterOptions> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * User override API for aria-live narration for toasts\n */\n announce?: Announce;\n\n inline?: boolean;\n };\n\n/**\n * State used in rendering Toaster\n */\nexport type ToasterState = ComponentState<ToasterSlotsInternal> &\n Pick<AriaLiveProps, 'announceRef'> &\n Pick<PortalProps, 'mountNode'> &\n Pick<Required<ToasterProps>, 'announce' | 'inline'> & {\n offset: ToasterOptions['offset'] | undefined;\n renderAriaLive: boolean;\n dir: 'rtl' | 'ltr';\n };\n"],"names":[],"rangeMappings":";;","mappings":"AAoCA;;CAEC"}
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
Toaster: function() {
return _Toaster.Toaster;
},
renderToaster_unstable: function() {
return _renderToaster.renderToaster_unstable;
},
toasterClassNames: function() {
return _useToasterStylesstyles.toasterClassNames;
},
useToasterStyles_unstable: function() {
return _useToasterStylesstyles.useToasterStyles_unstable;
},
useToaster_unstable: function() {
return _useToaster.useToaster_unstable;
}
});
const _Toaster = require("./Toaster");
const _renderToaster = require("./renderToaster");
const _useToaster = require("./useToaster");
const _useToasterStylesstyles = require("./useToasterStyles.styles");
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/index.ts"],"sourcesContent":["export { Toaster } from './Toaster';\nexport type { ToasterProps, ToasterSlots, ToasterSlotsInternal, ToasterState } from './Toaster.types';\nexport { renderToaster_unstable } from './renderToaster';\nexport { useToaster_unstable } from './useToaster';\nexport { toasterClassNames, useToasterStyles_unstable } from './useToasterStyles.styles';\n"],"names":["Toaster","renderToaster_unstable","toasterClassNames","useToasterStyles_unstable","useToaster_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAASA,OAAO;eAAPA,gBAAO;;IAEPC,sBAAsB;eAAtBA,qCAAsB;;IAEtBC,iBAAiB;eAAjBA,yCAAiB;;IAAEC,yBAAyB;eAAzBA,iDAAyB;;IAD5CC,mBAAmB;eAAnBA,+BAAmB;;;yBAHJ;+BAEe;4BACH;wCACyB"}
@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "renderToaster_unstable", {
enumerable: true,
get: function() {
return renderToaster_unstable;
}
});
const _jsxruntime = require("@fluentui/react-jsx-runtime/jsx-runtime");
const _reactutilities = require("@fluentui/react-utilities");
const _reactportal = require("@fluentui/react-portal");
const _AriaLive = require("../AriaLive");
const renderToaster_unstable = (state)=>{
const { announceRef, renderAriaLive, inline, mountNode } = state;
(0, _reactutilities.assertSlots)(state);
const hasToasts = !!state.bottomStart || !!state.bottomEnd || !!state.topStart || !!state.topEnd || !!state.top || !!state.bottom;
const ariaLive = renderAriaLive ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_AriaLive.AriaLive, {
announceRef: announceRef
}) : null;
const positionSlots = /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
children: [
state.bottom ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.bottom, {}) : null,
state.bottomStart ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.bottomStart, {}) : null,
state.bottomEnd ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.bottomEnd, {}) : null,
state.topStart ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.topStart, {}) : null,
state.topEnd ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.topEnd, {}) : null,
state.top ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.top, {}) : null
]
});
if (inline) {
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
children: [
ariaLive,
hasToasts ? positionSlots : null
]
});
}
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
children: [
ariaLive,
hasToasts ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactportal.Portal, {
mountNode: mountNode,
children: positionSlots
}) : null
]
});
};
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/renderToaster.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\n\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { Portal } from '@fluentui/react-portal';\nimport type { ToasterState, ToasterSlotsInternal } from './Toaster.types';\nimport { AriaLive } from '../AriaLive';\n\n/**\n * Render the final JSX of Toaster\n */\nexport const renderToaster_unstable = (state: ToasterState) => {\n const { announceRef, renderAriaLive, inline, mountNode } = state;\n assertSlots<ToasterSlotsInternal>(state);\n\n const hasToasts =\n !!state.bottomStart || !!state.bottomEnd || !!state.topStart || !!state.topEnd || !!state.top || !!state.bottom;\n\n const ariaLive = renderAriaLive ? <AriaLive announceRef={announceRef} /> : null;\n const positionSlots = (\n <>\n {state.bottom ? <state.bottom /> : null}\n {state.bottomStart ? <state.bottomStart /> : null}\n {state.bottomEnd ? <state.bottomEnd /> : null}\n {state.topStart ? <state.topStart /> : null}\n {state.topEnd ? <state.topEnd /> : null}\n {state.top ? <state.top /> : null}\n </>\n );\n\n if (inline) {\n return (\n <>\n {ariaLive}\n {hasToasts ? positionSlots : null}\n </>\n );\n }\n\n return (\n <>\n {ariaLive}\n {hasToasts ? <Portal mountNode={mountNode}>{positionSlots}</Portal> : null}\n </>\n );\n};\n"],"names":["renderToaster_unstable","state","announceRef","renderAriaLive","inline","mountNode","assertSlots","hasToasts","bottomStart","bottomEnd","topStart","topEnd","top","bottom","ariaLive","_jsx","AriaLive","positionSlots","_jsxs","_Fragment","Portal"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWaA;;;eAAAA;;;4BAVb;gCAE4B;6BACL;0BAEE;AAKlB,MAAMA,yBAAyB,CAACC;IACrC,MAAM,EAAEC,WAAW,EAAEC,cAAc,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;IAC3DK,IAAAA,2BAAAA,EAAkCL;IAElC,MAAMM,YACJ,CAAC,CAACN,MAAMO,WAAW,IAAI,CAAC,CAACP,MAAMQ,SAAS,IAAI,CAAC,CAACR,MAAMS,QAAQ,IAAI,CAAC,CAACT,MAAMU,MAAM,IAAI,CAAC,CAACV,MAAMW,GAAG,IAAI,CAAC,CAACX,MAAMY,MAAM;IAEjH,MAAMC,WAAWX,iBAAAA,WAAAA,GAAiBY,IAAAA,eAAA,EAACC,kBAAAA,EAAAA;QAASd,aAAaA;SAAkB;IAC3E,MAAMe,gBAAAA,WAAAA,GACJC,IAAAA,gBAAA,EAAAC,oBAAA,EAAA;;YACGlB,MAAMY,MAAM,GAAA,WAAA,GAAGE,IAAAA,eAAA,EAACd,MAAMY,MAAM,EAAA,CAAA,KAAM;YAClCZ,MAAMO,WAAW,GAAA,WAAA,GAAGO,IAAAA,eAAA,EAACd,MAAMO,WAAW,EAAA,CAAA,KAAM;YAC5CP,MAAMQ,SAAS,GAAA,WAAA,GAAGM,IAAAA,eAAA,EAACd,MAAMQ,SAAS,EAAA,CAAA,KAAM;YACxCR,MAAMS,QAAQ,GAAA,WAAA,GAAGK,IAAAA,eAAA,EAACd,MAAMS,QAAQ,EAAA,CAAA,KAAM;YACtCT,MAAMU,MAAM,GAAA,WAAA,GAAGI,IAAAA,eAAA,EAACd,MAAMU,MAAM,EAAA,CAAA,KAAM;YAClCV,MAAMW,GAAG,GAAA,WAAA,GAAGG,IAAAA,eAAA,EAACd,MAAMW,GAAG,EAAA,CAAA,KAAM;;;IAIjC,IAAIR,QAAQ;QACV,OAAA,WAAA,GACEc,IAAAA,gBAAA,EAAAC,oBAAA,EAAA;;gBACGL;gBACAP,YAAYU,gBAAgB;;;IAGnC;IAEA,OAAA,WAAA,GACEC,IAAAA,gBAAA,EAAAC,oBAAA,EAAA;;YACGL;YACAP,YAAAA,WAAAA,GAAYQ,IAAAA,eAAA,EAACK,mBAAAA,EAAAA;gBAAOf,WAAWA;0BAAYY;iBAA0B;;;AAG5E"}
@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useToastAnnounce", {
enumerable: true,
get: function() {
return useToastAnnounce;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
function useToastAnnounce(announce) {
const activeRef = _react.useRef(true);
const cleanupRef = _react.useRef(()=>undefined);
const announceToast = _react.useCallback((message, options)=>{
if (activeRef.current) {
announce(message, options);
}
}, [
announce
]);
const toasterRef = _react.useCallback((el)=>{
if (!el) {
cleanupRef.current();
return;
}
const onFocusIn = (e)=>{
if ((0, _reactutilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactutilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
return;
}
activeRef.current = false;
};
const onFocusOut = (e)=>{
if ((0, _reactutilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactutilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
return;
}
activeRef.current = true;
};
el.addEventListener('focusin', onFocusIn);
el.addEventListener('focusout', onFocusOut);
cleanupRef.current = ()=>{
el.removeEventListener('focusin', onFocusIn);
el.removeEventListener('focusout', onFocusOut);
};
}, []);
return {
announceToast,
toasterRef
};
}
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/useToastAnnounce.ts"],"sourcesContent":["import * as React from 'react';\nimport { Announce } from '../AriaLive';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n\n/**\n * Wraps an aria live announcement function.\n * Aria live announcements can be detrimental once the user is already navigating\n * multiple toasts. Once the user is focused inside the toaster, the announecments should be disabled.\n * @param announce\n * @returns A function to announce a toast and a ref to attach to the toaster element\n */\nexport function useToastAnnounce(announce: Announce) {\n const activeRef = React.useRef(true);\n const cleanupRef = React.useRef<() => void>(() => undefined);\n const announceToast = React.useCallback<Announce>(\n (message, options) => {\n if (activeRef.current) {\n announce(message, options);\n }\n },\n [announce],\n );\n\n const toasterRef = React.useCallback((el: HTMLDivElement | null) => {\n if (!el) {\n cleanupRef.current();\n return;\n }\n\n const onFocusIn = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n return;\n }\n\n activeRef.current = false;\n };\n\n const onFocusOut = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n return;\n }\n\n activeRef.current = true;\n };\n\n el.addEventListener('focusin', onFocusIn);\n el.addEventListener('focusout', onFocusOut);\n\n cleanupRef.current = () => {\n el.removeEventListener('focusin', onFocusIn);\n el.removeEventListener('focusout', onFocusOut);\n };\n }, []);\n\n return {\n announceToast,\n toasterRef,\n };\n}\n"],"names":["useToastAnnounce","announce","activeRef","React","useRef","cleanupRef","undefined","announceToast","useCallback","message","options","current","toasterRef","el","onFocusIn","e","isHTMLElement","currentTarget","contains","relatedTarget","onFocusOut","addEventListener","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWgBA;;;eAAAA;;;;iEAXO;gCAEO;AASvB,SAASA,iBAAiBC,QAAkB;IACjD,MAAMC,YAAYC,OAAMC,MAAM,CAAC;IAC/B,MAAMC,aAAaF,OAAMC,MAAM,CAAa,IAAME;IAClD,MAAMC,gBAAgBJ,OAAMK,WAAW,CACrC,CAACC,SAASC;QACR,IAAIR,UAAUS,OAAO,EAAE;YACrBV,SAASQ,SAASC;QACpB;IACF,GACA;QAACT;KAAS;IAGZ,MAAMW,aAAaT,OAAMK,WAAW,CAAC,CAACK;QACpC,IAAI,CAACA,IAAI;YACPR,WAAWM,OAAO;YAClB;QACF;QAEA,MAAMG,YAAY,CAACC;YACjB,IACEC,IAAAA,6BAAAA,EAAcD,EAAEE,aAAa,KAC7BF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAAA,EAAcD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,OAC5E;gBACA;YACF;YAEAjB,UAAUS,OAAO,GAAG;QACtB;QAEA,MAAMS,aAAa,CAACL;YAClB,IACEC,IAAAA,6BAAAA,EAAcD,EAAEE,aAAa,KAC7BF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAAA,EAAcD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,OAC5E;gBACA;YACF;YAEAjB,UAAUS,OAAO,GAAG;QACtB;QAEAE,GAAGQ,gBAAgB,CAAC,WAAWP;QAC/BD,GAAGQ,gBAAgB,CAAC,YAAYD;QAEhCf,WAAWM,OAAO,GAAG;YACnBE,GAAGS,mBAAmB,CAAC,WAAWR;YAClCD,GAAGS,mBAAmB,CAAC,YAAYF;QACrC;IACF,GAAG,EAAE;IAEL,OAAO;QACLb;QACAK;IACF;AACF"}
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useToaster_unstable", {
enumerable: true,
get: function() {
return useToaster_unstable;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _reacttabster = require("@fluentui/react-tabster");
const _keyboardkeys = require("@fluentui/keyboard-keys");
const _state = require("../../state");
const _ToastContainer = require("../ToastContainer");
const _useToasterFocusManagement = require("./useToasterFocusManagement");
const _useToastAnnounce = require("./useToastAnnounce");
const useToaster_unstable = (props)=>{
'use no memo';
const { offset, announce: announceProp, mountNode, inline = false, ...rest } = props;
const announceRef = _react.useRef(()=>null);
const { toastsToRender, isToastVisible, pauseAllToasts, playAllToasts, tryRestoreFocus, closeAllToasts } = (0, _state.useToaster)(rest);
const announce = _react.useCallback((message, options)=>announceRef.current(message, options), []);
const { dir } = (0, _reactsharedcontexts.useFluent_unstable)();
const rootProps = _reactutilities.slot.always((0, _reactutilities.getIntrinsicElementProps)('div', rest), {
elementType: 'div'
});
const focusableGroupAttr = (0, _reacttabster.useFocusableGroup)({
tabBehavior: 'limited-trap-focus',
ignoreDefaultKeydown: {
Escape: true
}
});
const onKeyDown = (0, _reactutilities.useEventCallback)((e)=>{
var _props_onKeyDown;
if (e.key === _keyboardkeys.Escape) {
e.preventDefault();
closeAllToasts();
}
(_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, e);
});
const usePositionSlot = (toastPosition)=>{
var _toastsToRender_get;
const focusManagementRef = (0, _useToasterFocusManagement.useToasterFocusManagement_unstable)(pauseAllToasts, playAllToasts);
const { announceToast, toasterRef } = (0, _useToastAnnounce.useToastAnnounce)(announceProp !== null && announceProp !== void 0 ? announceProp : announce);
return _reactutilities.slot.optional(toastsToRender.has(toastPosition) ? rootProps : null, {
defaultProps: {
ref: (0, _reactutilities.useMergedRefs)(focusManagementRef, toasterRef),
children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ _react.createElement(_ToastContainer.ToastContainer, {
...toast,
tryRestoreFocus: tryRestoreFocus,
intent: toast.intent,
announce: announceToast,
key: toast.toastId,
visible: isToastVisible(toast.toastId)
}, toast.content)),
onKeyDown,
...focusableGroupAttr,
'data-toaster-position': toastPosition,
role: 'list'
},
elementType: 'div'
});
};
return {
dir,
mountNode,
components: {
root: 'div',
bottomStart: 'div',
bottomEnd: 'div',
topStart: 'div',
topEnd: 'div',
top: 'div',
bottom: 'div'
},
root: _reactutilities.slot.always(rootProps, {
elementType: 'div'
}),
bottomStart: usePositionSlot(_state.TOAST_POSITIONS.bottomStart),
bottomEnd: usePositionSlot(_state.TOAST_POSITIONS.bottomEnd),
topStart: usePositionSlot(_state.TOAST_POSITIONS.topStart),
topEnd: usePositionSlot(_state.TOAST_POSITIONS.topEnd),
top: usePositionSlot(_state.TOAST_POSITIONS.top),
bottom: usePositionSlot(_state.TOAST_POSITIONS.bottom),
announceRef,
offset,
announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,
renderAriaLive: !announceProp,
inline
};
};
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/useToaster.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n ExtractSlotProps,\n Slot,\n getIntrinsicElementProps,\n useEventCallback,\n useMergedRefs,\n slot,\n} 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 type { ToasterProps, ToasterState } from './Toaster.types';\nimport { TOAST_POSITIONS, ToastPosition, useToaster } from '../../state';\nimport { Announce } from '../AriaLive';\nimport { ToastContainer } from '../ToastContainer';\nimport { useToasterFocusManagement_unstable } from './useToasterFocusManagement';\nimport { useToastAnnounce } from './useToastAnnounce';\n\n/**\n * Create the state required to render Toaster.\n *\n * @param props - props from this instance of Toaster\n */\nexport const useToaster_unstable = (props: ToasterProps): ToasterState => {\n 'use no memo';\n\n const { offset, announce: announceProp, mountNode, inline = false, ...rest } = props;\n const announceRef = React.useRef<Announce>(() => null);\n const { toastsToRender, isToastVisible, pauseAllToasts, playAllToasts, tryRestoreFocus, closeAllToasts } =\n useToaster<HTMLDivElement>(rest);\n const announce = React.useCallback<Announce>((message, options) => announceRef.current(message, options), []);\n const { dir } = useFluent();\n\n const rootProps = slot.always(getIntrinsicElementProps<ExtractSlotProps<Slot<'div'>>>('div', rest), {\n elementType: 'div',\n });\n const focusableGroupAttr = useFocusableGroup({\n tabBehavior: 'limited-trap-focus',\n ignoreDefaultKeydown: { Escape: true },\n });\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key === Escape) {\n e.preventDefault();\n closeAllToasts();\n }\n props.onKeyDown?.(e);\n });\n const usePositionSlot = (toastPosition: ToastPosition) => {\n const focusManagementRef = useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts);\n const { announceToast, toasterRef } = useToastAnnounce(announceProp ?? announce);\n return slot.optional<ExtractSlotProps<Slot<'div'>>>(toastsToRender.has(toastPosition) ? rootProps : null, {\n defaultProps: {\n ref: useMergedRefs(focusManagementRef, toasterRef),\n children: toastsToRender.get(toastPosition)?.map(toast => (\n <ToastContainer\n {...toast}\n tryRestoreFocus={tryRestoreFocus}\n intent={toast.intent}\n announce={announceToast}\n key={toast.toastId}\n visible={isToastVisible(toast.toastId)}\n >\n {toast.content as React.ReactNode}\n </ToastContainer>\n )),\n onKeyDown,\n ...focusableGroupAttr,\n 'data-toaster-position': toastPosition,\n role: 'list',\n // Explicitly casting because our slot types can't handle data attributes\n } as ExtractSlotProps<Slot<'div'>>,\n elementType: 'div',\n });\n };\n\n return {\n dir,\n mountNode,\n components: {\n root: 'div',\n bottomStart: 'div',\n bottomEnd: 'div',\n topStart: 'div',\n topEnd: 'div',\n top: 'div',\n bottom: 'div',\n },\n root: slot.always(rootProps, { elementType: 'div' }),\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 top: usePositionSlot(TOAST_POSITIONS.top),\n bottom: usePositionSlot(TOAST_POSITIONS.bottom),\n announceRef,\n offset,\n announce: announceProp ?? announce,\n renderAriaLive: !announceProp,\n inline,\n };\n};\n"],"names":["useToaster_unstable","props","offset","announce","announceProp","mountNode","inline","rest","announceRef","React","useRef","toastsToRender","isToastVisible","pauseAllToasts","playAllToasts","tryRestoreFocus","closeAllToasts","useToaster","useCallback","message","options","current","dir","useFluent","rootProps","slot","always","getIntrinsicElementProps","elementType","focusableGroupAttr","useFocusableGroup","tabBehavior","ignoreDefaultKeydown","Escape","onKeyDown","useEventCallback","e","key","preventDefault","usePositionSlot","toastPosition","focusManagementRef","useToasterFocusManagement_unstable","announceToast","toasterRef","useToastAnnounce","optional","has","defaultProps","ref","useMergedRefs","children","get","map","toast","createElement","ToastContainer","intent","toastId","visible","content","role","components","root","bottomStart","bottomEnd","topStart","topEnd","top","bottom","TOAST_POSITIONS","renderAriaLive"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAwBaALine truncated
@@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useToasterFocusManagement_unstable", {
enumerable: true,
get: function() {
return useToasterFocusManagement_unstable;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _reactutilities = require("@fluentui/react-utilities");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _keyboardkeys = require("@fluentui/keyboard-keys");
const _ToastContainer = require("../ToastContainer");
const noop = ()=>undefined;
function useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts) {
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const cleanupListenersRef = _react.useRef(noop);
return _react.useCallback((el)=>{
if (!el || !targetDocument) {
cleanupListenersRef.current();
cleanupListenersRef.current = noop;
return;
}
const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {
acceptNode (node) {
if ((0, _reactutilities.isHTMLElement)(node) && node.classList.contains(_ToastContainer.toastContainerClassNames.root)) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_SKIP;
}
});
/**
* FIXME: https://github.com/microsoft/tabster/issues/299
* Toasts should be arrow navigable and focus should be trapped in a stack of tasts
* This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers
* Once tabster fully supports this use case, remove this hook
*/ const keydownListener = (e)=>{
const { target, key } = e;
if (!(0, _reactutilities.isHTMLElement)(target)) {
return;
}
if (key === _keyboardkeys.ArrowDown) {
toastContainerWalker.currentNode = target;
let nextToastContainer = toastContainerWalker.nextNode();
if (!nextToastContainer) {
toastContainerWalker.currentNode = el;
nextToastContainer = toastContainerWalker.nextNode();
}
if ((0, _reactutilities.isHTMLElement)(nextToastContainer)) {
nextToastContainer.focus();
}
}
if (key === _keyboardkeys.ArrowUp) {
toastContainerWalker.currentNode = target;
let prevToastContainer = toastContainerWalker.previousNode();
if (prevToastContainer && prevToastContainer.contains(target)) {
prevToastContainer = toastContainerWalker.previousNode();
}
if (!prevToastContainer) {
toastContainerWalker.currentNode = el;
prevToastContainer = toastContainerWalker.lastChild();
}
if ((0, _reactutilities.isHTMLElement)(prevToastContainer)) {
prevToastContainer.focus();
}
}
};
const focusInListener = (e)=>{
if ((0, _reactutilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactutilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
pauseAllToasts();
}
};
const focusOutListener = (e)=>{
if ((0, _reactutilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactutilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
playAllToasts();
}
};
el.addEventListener('keydown', keydownListener);
el.addEventListener('focusin', focusInListener);
el.addEventListener('focusout', focusOutListener);
cleanupListenersRef.current = ()=>{
el.removeEventListener('keydown', keydownListener);
el.removeEventListener('focusin', focusInListener);
el.removeEventListener('focusout', focusOutListener);
};
}, [
targetDocument,
pauseAllToasts,
playAllToasts
]);
}
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Toaster/useToasterFocusManagement.ts"],"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';\n\nconst noop = () => undefined;\n\n/**\n * @internal\n */\nexport function useToasterFocusManagement_unstable(pauseAllToasts: () => void, playAllToasts: () => void) {\n const { targetDocument } = useFluent();\n const cleanupListenersRef = React.useRef<() => void>(noop);\n\n return React.useCallback(\n (el: HTMLDivElement) => {\n if (!el || !targetDocument) {\n cleanupListenersRef.current();\n cleanupListenersRef.current = noop;\n return;\n }\n\n const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Node) {\n if (isHTMLElement(node) && node.classList.contains(toastContainerClassNames.root)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n },\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 */\n const keydownListener = (e: KeyboardEvent) => {\n const { target, key } = e;\n if (!isHTMLElement(target)) {\n return;\n }\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\n if (isHTMLElement(nextToastContainer)) {\n nextToastContainer.focus();\n }\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\n if (!prevToastContainer) {\n toastContainerWalker.currentNode = el;\n prevToastContainer = toastContainerWalker.lastChild();\n }\n\n if (isHTMLElement(prevToastContainer)) {\n prevToastContainer.focus();\n }\n }\n };\n\n const focusInListener = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n pauseAllToasts();\n }\n };\n\n const focusOutListener = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n playAllToasts();\n }\n };\n\n el.addEventListener('keydown', keydownListener);\n el.addEventListener('focusin', focusInListener);\n el.addEventListener('focusout', focusOutListener);\n\n cleanupListenersRef.current = () => {\n el.removeEventListener('keydown', keydownListener);\n el.removeEventListener('focusin', focusInListener);\n el.removeEventListener('focusout', focusOutListener);\n };\n },\n [targetDocument, pauseAllToasts, 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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWgBA;;;eAAAA;;;;gCAXc;iEACP;qCACyB;8BACb;gCACM;AAEzC,MAAMC,OAAO,IAAMC;AAKZ,SAASF,mCAAmCG,cAA0B,EAAEC,aAAyB;IACtG,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAAA;IAC3B,MAAMC,sBAAsBC,OAAMC,MAAM,CAAaR;IAErD,OAAOO,OAAME,WAAW,CACtB,CAACC;QACC,IAAI,CAACA,MAAM,CAACN,gBAAgB;YAC1BE,oBAAoBK,OAAO;YAC3BL,oBAAoBK,OAAO,GAAGX;YAC9B;QACF;QAEA,MAAMY,uBAAuLine truncated
@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
toasterClassNames: function() {
return toasterClassNames;
},
useToasterStyles_unstable: function() {
return useToasterStyles_unstable;
}
});
const _react = require("@griffel/react");
const _index = require("../../state/index");
const toasterClassNames = {
root: 'fui-Toaster'
};
/**
* Styles for the root slot
*/ const useRootBaseClassName = /*#__PURE__*/ (0, _react.__resetStyles)("r3hfdjz", null, [
".r3hfdjz{position:fixed;width:292px;pointer-events:none;}"
]);
const useToasterStyles = /*#__PURE__*/ (0, _react.__styles)({
inline: {
qhf8xq: "f1euv43f"
}
}, {
d: [
".f1euv43f{position:absolute;}"
]
});
const useToasterStyles_unstable = (state)=>{
'use no memo';
const rootBaseClassName = useRootBaseClassName();
const styles = useToasterStyles();
const className = (0, _react.mergeClasses)(toasterClassNames.root, rootBaseClassName, state.inline && styles.inline, state.root.className);
if (state.bottomStart) {
var _state_bottomStart;
state.bottomStart.className = className;
var _style;
(_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};
Object.assign(state.bottomStart.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.bottomStart, state.dir, state.offset));
}
if (state.bottomEnd) {
var _state_bottomEnd;
state.bottomEnd.className = className;
var _style1;
(_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};
Object.assign(state.bottomEnd.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.bottomEnd, state.dir, state.offset));
}
if (state.topStart) {
var _state_topStart;
state.topStart.className = className;
var _style2;
(_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};
Object.assign(state.topStart.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.topStart, state.dir, state.offset));
}
if (state.topEnd) {
var _state_topEnd;
state.topEnd.className = className;
var _style3;
(_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};
Object.assign(state.topEnd.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.topEnd, state.dir, state.offset));
}
if (state.top) {
var _state_top;
state.top.className = className;
var _style4;
(_style4 = (_state_top = state.top).style) !== null && _style4 !== void 0 ? _style4 : _state_top.style = {};
Object.assign(state.top.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.top, state.dir, state.offset));
}
if (state.bottom) {
var _state_bottom;
state.bottom.className = className;
var _style5;
(_style5 = (_state_bottom = state.bottom).style) !== null && _style5 !== void 0 ? _style5 : _state_bottom.style = {};
Object.assign(state.bottom.style, (0, _index.getPositionStyles)(_index.TOAST_POSITIONS.bottom, state.dir, state.offset));
}
return state;
};
@@ -0,0 +1 @@
{"version":3,"sources":["useToasterStyles.styles.js"],"sourcesContent":["import { makeResetStyles, makeStyles, 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 */ const useRootBaseClassName = makeResetStyles({\n position: 'fixed',\n width: '292px',\n pointerEvents: 'none'\n});\nconst useToasterStyles = makeStyles({\n inline: {\n position: 'absolute'\n }\n});\n/**\n * Apply styling to the Toaster slots based on the state\n */ export const useToasterStyles_unstable = (state)=>{\n 'use no memo';\n const rootBaseClassName = useRootBaseClassName();\n const styles = useToasterStyles();\n const className = mergeClasses(toasterClassNames.root, rootBaseClassName, state.inline && styles.inline, 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 if (state.top) {\n var _state_top;\n state.top.className = className;\n var _style4;\n (_style4 = (_state_top = state.top).style) !== null && _style4 !== void 0 ? _style4 : _state_top.style = {};\n Object.assign(state.top.style, getPositionStyles(TOAST_POSITIONS.top, state.dir, state.offset));\n }\n if (state.bottom) {\n var _state_bottom;\n state.bottom.className = className;\n var _style5;\n (_style5 = (_state_bottom = state.bottom).style) !== null && _style5 !== void 0 ? _style5 : _state_bottom.style = {};\n Object.assign(state.bottom.style, getPositionStyles(TOAST_POSITIONS.bottom, state.dir, state.offset));\n }\n return state;\n};\n"],"names":["toasterClassNames","useToasterStyles_unstable","root","useRootBaseClassName","__resetStyles","useToasterStyles","__styles","inline","qhf8xq","d","state","rootBaseClassName","styles","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","top","_state_top","_style4","bottom","_state_bottom","_style5"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAEaA,iBAAiB;eAAjBA;;IAiBIC,yBAAyB;eAAzBA;;;uBAnByC;uBACP;AAC5C,MAAMD,oBAAoB;IAC7BE,MAAM;AACV;AACA;;CAEA,GAAI,MAAMC,uBAAoB,WAAA,GAAGC,IAAAA,oBAAA,EAAA,WAAA,MAAA;IAAA;CAIhC;AACD,MAAMC,mBAAgB,WAAA,GAAGC,IAAAA,eAAA,EAAA;IAAAC,QAAA;QAAAC,QAAA;IAAA;AAAA,GAAA;IAAAC,GAAA;QAAA;KAAA;AAAA;AAOd,MAAMR,4BAA6BS,CAAAA;IAC1C;IACA,MAAMC,oBAAoBR;IAC1B,MAAMS,SAASP;IACf,MAAMQ,YAAYC,IAAAA,mBAAY,EAACd,kBAAkBE,IAAI,EAAES,mBAAmBD,MAAMH,MAAM,IAAIK,OAAOL,MAAM,EAAEG,MAAMR,IAAI,CAACW,SAAS;IAC7H,IAAIH,MAAMK,WAAW,EAAE;QACnB,IAAIC;QACJN,MAAMK,WAAW,CAACF,SAAS,GAAGA;QAC9B,IAAII;QACHA,CAAAA,SAAS,AAACD,CAAAA,qBAAqBN,MAAMK,WAAW,AAAXA,EAAaG,KAAK,AAALA,MAAW,QAAQD,WAAW,KAAK,IAAIA,SAASD,mBAAmBE,KAAK,GAAG,CAAC;QAC/HC,OAAOC,MAAM,CAACV,MAAMK,WAAW,CAACG,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACP,WAAW,EAAEL,MAAMa,GAAG,EAAEb,MAAMc,MAAM;IACjH;IACA,IAAId,MAAMe,SAAS,EAAE;QACjB,IAAIC;QACJhB,MAAMe,SAAS,CAACZ,SAAS,GAAGA;QAC5B,IAAIc;QACHA,CAAAA,UAAU,AAACD,CAAAA,mBAAmBhB,MAAMe,SAAS,AAATA,EAAWP,KAAK,AAALA,MAAW,QAAQS,YAAY,KAAK,IAAIA,UAAUD,iBAAiBR,KAAK,GAAG,CAAC;QAC5HC,OAAOC,MAAM,CAACV,MAAMe,SAAS,CAACP,KAAK,EAAEG,IAAAA,wBAAiB,EAACC,sBAAe,CAACG,SAAS,EAAEf,MAAMa,GAAG,EAAEb,MAAMc,MAAM;IAC7G;IACA,IAAId,MLine truncated