focus-trap
Advanced tools
Comparing version 7.3.1 to 7.4.0
# Changelog | ||
## 7.4.0 | ||
### Minor Changes | ||
- da97007: Added new onPost/Pause and onPost/Unpause hooks when un/pausing a trap (also called when auto-un/paused as a result of de/activating a second trap while another is currently active). ([focus-trap-react#948](https://github.com/focus-trap/focus-trap-react/issues/948)) | ||
## 7.3.1 | ||
@@ -4,0 +10,0 @@ |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
@@ -635,5 +635,3 @@ */ | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
} | ||
onActivate === null || onActivate === void 0 ? void 0 : onActivate(); | ||
var finishActivation = function finishActivation() { | ||
@@ -644,5 +642,3 @@ if (checkCanFocusTrap) { | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
onPostActivate === null || onPostActivate === void 0 ? void 0 : onPostActivate(); | ||
}; | ||
@@ -675,5 +671,3 @@ if (checkCanFocusTrap) { | ||
var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate'); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
onDeactivate === null || onDeactivate === void 0 ? void 0 : onDeactivate(); | ||
var finishDeactivation = function finishDeactivation() { | ||
@@ -684,5 +678,3 @@ delay(function () { | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
} | ||
onPostDeactivate === null || onPostDeactivate === void 0 ? void 0 : onPostDeactivate(); | ||
}); | ||
@@ -697,17 +689,25 @@ }; | ||
}, | ||
pause: function pause() { | ||
pause: function pause(pauseOptions) { | ||
if (state.paused || !state.active) { | ||
return this; | ||
} | ||
var onPause = getOption(pauseOptions, 'onPause'); | ||
var onPostPause = getOption(pauseOptions, 'onPostPause'); | ||
state.paused = true; | ||
onPause === null || onPause === void 0 ? void 0 : onPause(); | ||
removeListeners(); | ||
onPostPause === null || onPostPause === void 0 ? void 0 : onPostPause(); | ||
return this; | ||
}, | ||
unpause: function unpause() { | ||
unpause: function unpause(unpauseOptions) { | ||
if (!state.paused || !state.active) { | ||
return this; | ||
} | ||
var onUnpause = getOption(unpauseOptions, 'onUnpause'); | ||
var onPostUnpause = getOption(unpauseOptions, 'onPostUnpause'); | ||
state.paused = false; | ||
onUnpause === null || onUnpause === void 0 ? void 0 : onUnpause(); | ||
updateTabbableNodes(); | ||
addListeners(); | ||
onPostUnpause === null || onPostUnpause === void 0 ? void 0 : onPostUnpause(); | ||
return this; | ||
@@ -714,0 +714,0 @@ }, |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
import{tabbable as e,focusable as t,isTabbable as n,isFocusable as r}from"tabbable";function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var r=e.indexOf(t);-1===r||e.splice(r,1),e.push(t)},u=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},s=function(e){return"Tab"===e.key||9===e.keyCode},l=function(e){return s(e)&&!e.shiftKey},b=function(e){return s(e)&&e.shiftKey},f=function(e){return setTimeout(e,0)},v=function(e,t){var n=-1;return e.every((function(e,r){return!t(e)||(n=r,!1)})),n},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,n):e},p=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},y=[],h=function(a,i){var h,m=(null==i?void 0:i.document)||document,g=(null==i?void 0:i.trapStack)||y,w=o({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:l,isKeyBackward:b},i),O={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},F=function(e,t,n){return e&&void 0!==e[t]?e[t]:w[n||t]},k=function(e){return O.containerGroups.findIndex((function(t){var n=t.container,r=t.tabbableNodes;return n.contains(e)||r.find((function(t){return t===e}))}))},E=function(e){var t=w[e];if("function"==typeof t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];t=t.apply(void 0,r)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=m.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},N=function(){var e=E("initialFocus");if(!1===e)return!1;if(void 0===e)if(k(m.activeElement)>=0)e=m.activeElement;else{var t=O.tabbableGroups[0];e=t&&t.firstTabbableNode||E("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(O.containerGroups=O.containers.map((function(r){var a=e(r,w.tabbableOptions),o=t(r,w.tabbableOptions);return{container:r,tabbableNodes:a,focusableNodes:o,firstTabbableNode:a.length>0?a[0]:null,lastTabbableNode:a.length>0?a[a.length-1]:null,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=o.findIndex((function(t){return t===e}));if(!(r<0))return t?o.slice(r+1).find((function(e){return n(e,w.tabbableOptions)})):o.slice(0,r).reverse().find((function(e){return n(e,w.tabbableOptions)}))}}})),O.tabbableGroups=O.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),O.tabbableGroups.length<=0&&!E("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},D=function e(t){!1!==t&&t!==m.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!w.preventScroll}),O.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(N()))},G=function(e){var t=E("setReturnFocus",e);return t||!1!==t&&e},P=function(e){var t=p(e);k(t)>=0||(d(w.clickOutsideDeactivates,e)?h.deactivate({returnFocus:w.returnFocusOnDeactivate}):d(w.allowOutsideClick,e)||e.preventDefault())},j=function(e){var t=p(e),n=k(t)>=0;n||t instanceof Document?n&&(O.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),D(O.mostRecentlyFocusedNode||N()))},C=function(e){if(!(t=e,"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!1===d(w.escapeDeactivates,e)))return e.preventDefault(),void h.deactivate();var t;(w.isKeyForward(e)||w.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=p(e);T();var o=null;if(O.tabbableGroups.length>0){var i=k(a),c=i>=0?O.containerGroups[i]:void 0;if(i<0)o=t?O.tabbableGroups[O.tabbableGroups.length-1].lastTabbableNode:O.tabbableGroups[0].firstTabbableNode;else if(t){var u=v(O.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(u<0&&(c.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!c.nextTabbableNode(a,!1))&&(u=i),u>=0){var l=0===u?O.tabbableGroups.length-1:u-1;o=O.tabbableGroups[l].lastTabbableNode}else s(e)||(o=c.nextTabbableNode(a,!1))}else{var b=v(O.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(c.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!c.nextTabbableNode(a))&&(b=i),b>=0){var f=b===O.tabbableGroups.length-1?0:b+1;o=O.tabbableGroups[f].firstTabbableNode}else s(e)||(o=c.nextTabbableNode(a))}}else o=E("fallbackFocus");o&&(s(e)&&e.preventDefault(),D(o))}(e,w.isKeyBackward(e))},L=function(e){var t=p(e);k(t)>=0||d(w.clickOutsideDeactivates,e)||d(w.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},x=function(){if(O.active)return c(g,h),O.delayInitialFocusTimer=w.delayInitialFocus?f((function(){D(N())})):D(N()),m.addEventListener("focusin",j,!0),m.addEventListener("mousedown",P,{capture:!0,passive:!1}),m.addEventListener("touchstart",P,{capture:!0,passive:!1}),m.addEventListener("click",L,{capture:!0,passive:!1}),m.addEventListener("keydown",C,{capture:!0,passive:!1}),h},I=function(){if(O.active)return m.removeEventListener("focusin",j,!0),m.removeEventListener("mousedown",P,!0),m.removeEventListener("touchstart",P,!0),m.removeEventListener("click",L,!0),m.removeEventListener("keydown",C,!0),h};return(h={get active(){return O.active},get paused(){return O.paused},activate:function(e){if(O.active)return this;var t=F(e,"onActivate"),n=F(e,"onPostActivate"),r=F(e,"checkCanFocusTrap");r||T(),O.active=!0,O.paused=!1,O.nodeFocusedBeforeActivation=m.activeElement,t&&t();var a=function(){r&&T(),x(),n&&n()};return r?(r(O.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(e){if(!O.active)return this;var t=o({onDeactivate:w.onDeactivate,onPostDeactivate:w.onPostDeactivate,checkCanReturnFocus:w.checkCanReturnFocus},e);clearTimeout(O.delayInitialFocusTimer),O.delayInitialFocusTimer=void 0,I(),O.active=!1,O.paused=!1,u(g,h);var n=F(t,"onDeactivate"),r=F(t,"onPostDeactivate"),a=F(t,"checkCanReturnFocus"),i=F(t,"returnFocus","returnFocusOnDeactivate");n&&n();var c=function(){f((function(){i&&D(G(O.nodeFocusedBeforeActivation)),r&&r()}))};return i&&a?(a(G(O.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return O.paused||!O.active||(O.paused=!0,I()),this},unpause:function(){return O.paused&&O.active?(O.paused=!1,T(),x(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return O.containers=t.map((function(e){return"string"==typeof e?m.querySelector(e):e})),O.active&&T(),this}}).updateContainerElements(a),h};export{h as createFocusTrap}; | ||
import{tabbable as e,focusable as t,isTabbable as n,isFocusable as r}from"tabbable";function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var u=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var r=e.indexOf(t);-1===r||e.splice(r,1),e.push(t)},c=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},s=function(e){return"Tab"===e.key||9===e.keyCode},l=function(e){return s(e)&&!e.shiftKey},b=function(e){return s(e)&&e.shiftKey},f=function(e){return setTimeout(e,0)},v=function(e,t){var n=-1;return e.every((function(e,r){return!t(e)||(n=r,!1)})),n},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,n):e},p=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},y=[],h=function(a,i){var h,m=(null==i?void 0:i.document)||document,g=(null==i?void 0:i.trapStack)||y,w=o({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:l,isKeyBackward:b},i),O={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},F=function(e,t,n){return e&&void 0!==e[t]?e[t]:w[n||t]},k=function(e){return O.containerGroups.findIndex((function(t){var n=t.container,r=t.tabbableNodes;return n.contains(e)||r.find((function(t){return t===e}))}))},E=function(e){var t=w[e];if("function"==typeof t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];t=t.apply(void 0,r)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=m.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},N=function(){var e=E("initialFocus");if(!1===e)return!1;if(void 0===e)if(k(m.activeElement)>=0)e=m.activeElement;else{var t=O.tabbableGroups[0];e=t&&t.firstTabbableNode||E("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},P=function(){if(O.containerGroups=O.containers.map((function(r){var a=e(r,w.tabbableOptions),o=t(r,w.tabbableOptions);return{container:r,tabbableNodes:a,focusableNodes:o,firstTabbableNode:a.length>0?a[0]:null,lastTabbableNode:a.length>0?a[a.length-1]:null,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=o.findIndex((function(t){return t===e}));if(!(r<0))return t?o.slice(r+1).find((function(e){return n(e,w.tabbableOptions)})):o.slice(0,r).reverse().find((function(e){return n(e,w.tabbableOptions)}))}}})),O.tabbableGroups=O.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),O.tabbableGroups.length<=0&&!E("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},T=function e(t){!1!==t&&t!==m.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!w.preventScroll}),O.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(N()))},D=function(e){var t=E("setReturnFocus",e);return t||!1!==t&&e},G=function(e){var t=p(e);k(t)>=0||(d(w.clickOutsideDeactivates,e)?h.deactivate({returnFocus:w.returnFocusOnDeactivate}):d(w.allowOutsideClick,e)||e.preventDefault())},j=function(e){var t=p(e),n=k(t)>=0;n||t instanceof Document?n&&(O.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),T(O.mostRecentlyFocusedNode||N()))},C=function(e){if(!(t=e,"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!1===d(w.escapeDeactivates,e)))return e.preventDefault(),void h.deactivate();var t;(w.isKeyForward(e)||w.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=p(e);P();var o=null;if(O.tabbableGroups.length>0){var i=k(a),u=i>=0?O.containerGroups[i]:void 0;if(i<0)o=t?O.tabbableGroups[O.tabbableGroups.length-1].lastTabbableNode:O.tabbableGroups[0].firstTabbableNode;else if(t){var c=v(O.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(u.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!u.nextTabbableNode(a,!1))&&(c=i),c>=0){var l=0===c?O.tabbableGroups.length-1:c-1;o=O.tabbableGroups[l].lastTabbableNode}else s(e)||(o=u.nextTabbableNode(a,!1))}else{var b=v(O.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(u.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!u.nextTabbableNode(a))&&(b=i),b>=0){var f=b===O.tabbableGroups.length-1?0:b+1;o=O.tabbableGroups[f].firstTabbableNode}else s(e)||(o=u.nextTabbableNode(a))}}else o=E("fallbackFocus");o&&(s(e)&&e.preventDefault(),T(o))}(e,w.isKeyBackward(e))},L=function(e){var t=p(e);k(t)>=0||d(w.clickOutsideDeactivates,e)||d(w.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},x=function(){if(O.active)return u(g,h),O.delayInitialFocusTimer=w.delayInitialFocus?f((function(){T(N())})):T(N()),m.addEventListener("focusin",j,!0),m.addEventListener("mousedown",G,{capture:!0,passive:!1}),m.addEventListener("touchstart",G,{capture:!0,passive:!1}),m.addEventListener("click",L,{capture:!0,passive:!1}),m.addEventListener("keydown",C,{capture:!0,passive:!1}),h},I=function(){if(O.active)return m.removeEventListener("focusin",j,!0),m.removeEventListener("mousedown",G,!0),m.removeEventListener("touchstart",G,!0),m.removeEventListener("click",L,!0),m.removeEventListener("keydown",C,!0),h};return(h={get active(){return O.active},get paused(){return O.paused},activate:function(e){if(O.active)return this;var t=F(e,"onActivate"),n=F(e,"onPostActivate"),r=F(e,"checkCanFocusTrap");r||P(),O.active=!0,O.paused=!1,O.nodeFocusedBeforeActivation=m.activeElement,null==t||t();var a=function(){r&&P(),x(),null==n||n()};return r?(r(O.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(e){if(!O.active)return this;var t=o({onDeactivate:w.onDeactivate,onPostDeactivate:w.onPostDeactivate,checkCanReturnFocus:w.checkCanReturnFocus},e);clearTimeout(O.delayInitialFocusTimer),O.delayInitialFocusTimer=void 0,I(),O.active=!1,O.paused=!1,c(g,h);var n=F(t,"onDeactivate"),r=F(t,"onPostDeactivate"),a=F(t,"checkCanReturnFocus"),i=F(t,"returnFocus","returnFocusOnDeactivate");null==n||n();var u=function(){f((function(){i&&T(D(O.nodeFocusedBeforeActivation)),null==r||r()}))};return i&&a?(a(D(O.nodeFocusedBeforeActivation)).then(u,u),this):(u(),this)},pause:function(e){if(O.paused||!O.active)return this;var t=F(e,"onPause"),n=F(e,"onPostPause");return O.paused=!0,null==t||t(),I(),null==n||n(),this},unpause:function(e){if(!O.paused||!O.active)return this;var t=F(e,"onUnpause"),n=F(e,"onPostUnpause");return O.paused=!1,null==t||t(),P(),x(),null==n||n(),this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return O.containers=t.map((function(e){return"string"==typeof e?m.querySelector(e):e})),O.active&&P(),this}}).updateContainerElements(a),h};export{h as createFocusTrap}; | ||
//# sourceMappingURL=focus-trap.esm.min.js.map |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
@@ -639,5 +639,3 @@ */ | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
} | ||
onActivate === null || onActivate === void 0 ? void 0 : onActivate(); | ||
var finishActivation = function finishActivation() { | ||
@@ -648,5 +646,3 @@ if (checkCanFocusTrap) { | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
onPostActivate === null || onPostActivate === void 0 ? void 0 : onPostActivate(); | ||
}; | ||
@@ -679,5 +675,3 @@ if (checkCanFocusTrap) { | ||
var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate'); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
onDeactivate === null || onDeactivate === void 0 ? void 0 : onDeactivate(); | ||
var finishDeactivation = function finishDeactivation() { | ||
@@ -688,5 +682,3 @@ delay(function () { | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
} | ||
onPostDeactivate === null || onPostDeactivate === void 0 ? void 0 : onPostDeactivate(); | ||
}); | ||
@@ -701,17 +693,25 @@ }; | ||
}, | ||
pause: function pause() { | ||
pause: function pause(pauseOptions) { | ||
if (state.paused || !state.active) { | ||
return this; | ||
} | ||
var onPause = getOption(pauseOptions, 'onPause'); | ||
var onPostPause = getOption(pauseOptions, 'onPostPause'); | ||
state.paused = true; | ||
onPause === null || onPause === void 0 ? void 0 : onPause(); | ||
removeListeners(); | ||
onPostPause === null || onPostPause === void 0 ? void 0 : onPostPause(); | ||
return this; | ||
}, | ||
unpause: function unpause() { | ||
unpause: function unpause(unpauseOptions) { | ||
if (!state.paused || !state.active) { | ||
return this; | ||
} | ||
var onUnpause = getOption(unpauseOptions, 'onUnpause'); | ||
var onPostUnpause = getOption(unpauseOptions, 'onPostUnpause'); | ||
state.paused = false; | ||
onUnpause === null || onUnpause === void 0 ? void 0 : onUnpause(); | ||
updateTabbableNodes(); | ||
addListeners(); | ||
onPostUnpause === null || onPostUnpause === void 0 ? void 0 : onPostUnpause(); | ||
return this; | ||
@@ -718,0 +718,0 @@ }, |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tabbable");function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},o=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},i=function(e){return"Tab"===e.key||9===e.keyCode},u=function(e){return i(e)&&!e.shiftKey},c=function(e){return i(e)&&e.shiftKey},s=function(e){return setTimeout(e,0)},l=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},b=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},f=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},v=[];exports.createFocusTrap=function(t,a){var d,p=(null==a?void 0:a.document)||document,y=(null==a?void 0:a.trapStack)||v,h=n({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:u,isKeyBackward:c},a),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(t){var n=e.tabbable(t,h.tabbableOptions),a=e.focusable(t,h.tabbableOptions);return{container:t,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(e){return e===t}));if(!(r<0))return n?a.slice(r+1).find((function(t){return e.isTabbable(t,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(t){return e.isTabbable(t,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!O("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=f(e);w(t)>=0||(b(h.clickOutsideDeactivates,e)?d.deactivate({returnFocus:h.returnFocusOnDeactivate}):b(h.allowOutsideClick,e)||e.preventDefault())},D=function(e){var t=f(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},P=function(t){if(!(n=t,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===b(h.escapeDeactivates,t)))return t.preventDefault(),void d.deactivate();var n;(h.isKeyForward(t)||h.isKeyBackward(t))&&function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=f(t);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),u=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=l(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else i(t)||(r=u.nextTabbableNode(a,!1))}else{var b=l(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a))&&(b=o),b>=0){var v=b===m.tabbableGroups.length-1?0:b+1;r=m.tabbableGroups[v].firstTabbableNode}else i(t)||(r=u.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(i(t)&&t.preventDefault(),k(r))}(t,h.isKeyBackward(t))},G=function(e){var t=f(e);w(t)>=0||b(h.clickOutsideDeactivates,e)||b(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return r(y,d),m.delayInitialFocusTimer=h.delayInitialFocus?s((function(){k(F())})):k(F()),p.addEventListener("focusin",D,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",P,{capture:!0,passive:!1}),d},x=function(){if(m.active)return p.removeEventListener("focusin",D,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",P,!0),d};return(d={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,t&&t();var r=function(){a&&T(),j(),n&&n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=n({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,o(y,d);var a=g(t,"onDeactivate"),r=g(t,"onPostDeactivate"),i=g(t,"checkCanReturnFocus"),u=g(t,"returnFocus","returnFocusOnDeactivate");a&&a();var c=function(){s((function(){u&&k(E(m.nodeFocusedBeforeActivation)),r&&r()}))};return u&&i?(i(E(m.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return m.paused||!m.active||(m.paused=!0,x()),this},unpause:function(){return m.paused&&m.active?(m.paused=!1,T(),j(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(t),d}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tabbable");function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},o=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},i=function(e){return"Tab"===e.key||9===e.keyCode},u=function(e){return i(e)&&!e.shiftKey},c=function(e){return i(e)&&e.shiftKey},s=function(e){return setTimeout(e,0)},l=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},b=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},f=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},v=[];exports.createFocusTrap=function(t,a){var d,p=(null==a?void 0:a.document)||document,y=(null==a?void 0:a.trapStack)||v,h=n({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:u,isKeyBackward:c},a),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(t){var n=e.tabbable(t,h.tabbableOptions),a=e.focusable(t,h.tabbableOptions);return{container:t,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(e){return e===t}));if(!(r<0))return n?a.slice(r+1).find((function(t){return e.isTabbable(t,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(t){return e.isTabbable(t,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!O("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=f(e);w(t)>=0||(b(h.clickOutsideDeactivates,e)?d.deactivate({returnFocus:h.returnFocusOnDeactivate}):b(h.allowOutsideClick,e)||e.preventDefault())},P=function(e){var t=f(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},D=function(t){if(!(n=t,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===b(h.escapeDeactivates,t)))return t.preventDefault(),void d.deactivate();var n;(h.isKeyForward(t)||h.isKeyBackward(t))&&function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=f(t);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),u=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=l(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else i(t)||(r=u.nextTabbableNode(a,!1))}else{var b=l(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a))&&(b=o),b>=0){var v=b===m.tabbableGroups.length-1?0:b+1;r=m.tabbableGroups[v].firstTabbableNode}else i(t)||(r=u.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(i(t)&&t.preventDefault(),k(r))}(t,h.isKeyBackward(t))},G=function(e){var t=f(e);w(t)>=0||b(h.clickOutsideDeactivates,e)||b(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return r(y,d),m.delayInitialFocusTimer=h.delayInitialFocus?s((function(){k(F())})):k(F()),p.addEventListener("focusin",P,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",D,{capture:!0,passive:!1}),d},x=function(){if(m.active)return p.removeEventListener("focusin",P,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",D,!0),d};return(d={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,null==t||t();var r=function(){a&&T(),j(),null==n||n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=n({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,o(y,d);var a=g(t,"onDeactivate"),r=g(t,"onPostDeactivate"),i=g(t,"checkCanReturnFocus"),u=g(t,"returnFocus","returnFocusOnDeactivate");null==a||a();var c=function(){s((function(){u&&k(E(m.nodeFocusedBeforeActivation)),null==r||r()}))};return u&&i?(i(E(m.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(e){if(m.paused||!m.active)return this;var t=g(e,"onPause"),n=g(e,"onPostPause");return m.paused=!0,null==t||t(),x(),null==n||n(),this},unpause:function(e){if(!m.paused||!m.active)return this;var t=g(e,"onUnpause"),n=g(e,"onPostUnpause");return m.paused=!1,null==t||t(),T(),j(),null==n||n(),this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(t),d}; | ||
//# sourceMappingURL=focus-trap.min.js.map |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
@@ -644,5 +644,3 @@ */ | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
} | ||
onActivate === null || onActivate === void 0 ? void 0 : onActivate(); | ||
var finishActivation = function finishActivation() { | ||
@@ -653,5 +651,3 @@ if (checkCanFocusTrap) { | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
onPostActivate === null || onPostActivate === void 0 ? void 0 : onPostActivate(); | ||
}; | ||
@@ -684,5 +680,3 @@ if (checkCanFocusTrap) { | ||
var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate'); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
onDeactivate === null || onDeactivate === void 0 ? void 0 : onDeactivate(); | ||
var finishDeactivation = function finishDeactivation() { | ||
@@ -693,5 +687,3 @@ delay(function () { | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
} | ||
onPostDeactivate === null || onPostDeactivate === void 0 ? void 0 : onPostDeactivate(); | ||
}); | ||
@@ -706,17 +698,25 @@ }; | ||
}, | ||
pause: function pause() { | ||
pause: function pause(pauseOptions) { | ||
if (state.paused || !state.active) { | ||
return this; | ||
} | ||
var onPause = getOption(pauseOptions, 'onPause'); | ||
var onPostPause = getOption(pauseOptions, 'onPostPause'); | ||
state.paused = true; | ||
onPause === null || onPause === void 0 ? void 0 : onPause(); | ||
removeListeners(); | ||
onPostPause === null || onPostPause === void 0 ? void 0 : onPostPause(); | ||
return this; | ||
}, | ||
unpause: function unpause() { | ||
unpause: function unpause(unpauseOptions) { | ||
if (!state.paused || !state.active) { | ||
return this; | ||
} | ||
var onUnpause = getOption(unpauseOptions, 'onUnpause'); | ||
var onPostUnpause = getOption(unpauseOptions, 'onPostUnpause'); | ||
state.paused = false; | ||
onUnpause === null || onUnpause === void 0 ? void 0 : onUnpause(); | ||
updateTabbableNodes(); | ||
addListeners(); | ||
onPostUnpause === null || onPostUnpause === void 0 ? void 0 : onPostUnpause(); | ||
return this; | ||
@@ -723,0 +723,0 @@ }, |
/*! | ||
* focus-trap 7.3.1 | ||
* focus-trap 7.4.0 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tabbable")):"function"==typeof define&&define.amd?define(["exports","tabbable"],t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.focusTrap,a=e.focusTrap={};t(a,e.tabbable),a.noConflict=function(){return e.focusTrap=n,a}}())}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function r(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},i=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},u=function(e){return"Tab"===e.key||9===e.keyCode},c=function(e){return u(e)&&!e.shiftKey},s=function(e){return u(e)&&e.shiftKey},l=function(e){return setTimeout(e,0)},b=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},f=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},d=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},v=[];e.createFocusTrap=function(e,n){var r,p=(null==n?void 0:n.document)||document,y=(null==n?void 0:n.trapStack)||v,h=a({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:c,isKeyBackward:s},n),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(e){var n=t.tabbable(e,h.tabbableOptions),a=t.focusable(e,h.tabbableOptions);return{container:e,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(t){return t===e}));if(!(r<0))return n?a.slice(r+1).find((function(e){return t.isTabbable(e,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(e){return t.isTabbable(e,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!O("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=d(e);w(t)>=0||(f(h.clickOutsideDeactivates,e)?r.deactivate({returnFocus:h.returnFocusOnDeactivate}):f(h.allowOutsideClick,e)||e.preventDefault())},D=function(e){var t=d(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},P=function(e){if(!(n=e,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===f(h.escapeDeactivates,e)))return e.preventDefault(),void r.deactivate();var n;(h.isKeyForward(e)||h.isKeyBackward(e))&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=d(e);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),i=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=b(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else u(e)||(r=i.nextTabbableNode(a,!1))}else{var l=b(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(l<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a))&&(l=o),l>=0){var f=l===m.tabbableGroups.length-1?0:l+1;r=m.tabbableGroups[f].firstTabbableNode}else u(e)||(r=i.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(u(e)&&e.preventDefault(),k(r))}(e,h.isKeyBackward(e))},G=function(e){var t=d(e);w(t)>=0||f(h.clickOutsideDeactivates,e)||f(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return o(y,r),m.delayInitialFocusTimer=h.delayInitialFocus?l((function(){k(F())})):k(F()),p.addEventListener("focusin",D,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",P,{capture:!0,passive:!1}),r},x=function(){if(m.active)return p.removeEventListener("focusin",D,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",P,!0),r};return(r={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,t&&t();var r=function(){a&&T(),j(),n&&n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=a({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,i(y,r);var n=g(t,"onDeactivate"),o=g(t,"onPostDeactivate"),u=g(t,"checkCanReturnFocus"),c=g(t,"returnFocus","returnFocusOnDeactivate");n&&n();var s=function(){l((function(){c&&k(E(m.nodeFocusedBeforeActivation)),o&&o()}))};return c&&u?(u(E(m.nodeFocusedBeforeActivation)).then(s,s),this):(s(),this)},pause:function(){return m.paused||!m.active||(m.paused=!0,x()),this},unpause:function(){return m.paused&&m.active?(m.paused=!1,T(),j(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(e),r},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tabbable")):"function"==typeof define&&define.amd?define(["exports","tabbable"],t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.focusTrap,a=e.focusTrap={};t(a,e.tabbable),a.noConflict=function(){return e.focusTrap=n,a}}())}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function r(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},i=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},u=function(e){return"Tab"===e.key||9===e.keyCode},c=function(e){return u(e)&&!e.shiftKey},s=function(e){return u(e)&&e.shiftKey},l=function(e){return setTimeout(e,0)},b=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},f=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},v=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},d=[];e.createFocusTrap=function(e,n){var r,p=(null==n?void 0:n.document)||document,y=(null==n?void 0:n.trapStack)||d,h=a({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:c,isKeyBackward:s},n),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(e){var n=t.tabbable(e,h.tabbableOptions),a=t.focusable(e,h.tabbableOptions);return{container:e,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(t){return t===e}));if(!(r<0))return n?a.slice(r+1).find((function(e){return t.isTabbable(e,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(e){return t.isTabbable(e,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!O("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=v(e);w(t)>=0||(f(h.clickOutsideDeactivates,e)?r.deactivate({returnFocus:h.returnFocusOnDeactivate}):f(h.allowOutsideClick,e)||e.preventDefault())},P=function(e){var t=v(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},D=function(e){if(!(n=e,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===f(h.escapeDeactivates,e)))return e.preventDefault(),void r.deactivate();var n;(h.isKeyForward(e)||h.isKeyBackward(e))&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=v(e);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),i=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=b(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else u(e)||(r=i.nextTabbableNode(a,!1))}else{var l=b(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(l<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a))&&(l=o),l>=0){var f=l===m.tabbableGroups.length-1?0:l+1;r=m.tabbableGroups[f].firstTabbableNode}else u(e)||(r=i.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(u(e)&&e.preventDefault(),k(r))}(e,h.isKeyBackward(e))},G=function(e){var t=v(e);w(t)>=0||f(h.clickOutsideDeactivates,e)||f(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return o(y,r),m.delayInitialFocusTimer=h.delayInitialFocus?l((function(){k(F())})):k(F()),p.addEventListener("focusin",P,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",D,{capture:!0,passive:!1}),r},x=function(){if(m.active)return p.removeEventListener("focusin",P,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",D,!0),r};return(r={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,null==t||t();var r=function(){a&&T(),j(),null==n||n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=a({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,i(y,r);var n=g(t,"onDeactivate"),o=g(t,"onPostDeactivate"),u=g(t,"checkCanReturnFocus"),c=g(t,"returnFocus","returnFocusOnDeactivate");null==n||n();var s=function(){l((function(){c&&k(E(m.nodeFocusedBeforeActivation)),null==o||o()}))};return c&&u?(u(E(m.nodeFocusedBeforeActivation)).then(s,s),this):(s(),this)},pause:function(e){if(m.paused||!m.active)return this;var t=g(e,"onPause"),n=g(e,"onPostPause");return m.paused=!0,null==t||t(),x(),null==n||n(),this},unpause:function(e){if(!m.paused||!m.active)return this;var t=g(e,"onUnpause"),n=g(e,"onPostUnpause");return m.paused=!1,null==t||t(),T(),j(),null==n||n(),this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(e),r},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=focus-trap.umd.min.js.map |
@@ -42,2 +42,26 @@ import { CheckOptions as TabbableCheckOptions } from 'tabbable'; | ||
/** | ||
* A function that will be called immediately after the trap's state is updated to be paused. | ||
*/ | ||
onPause?: () => void; | ||
/** | ||
* A function that will be called after the trap has been completely paused and is no longer | ||
* managing/trapping focus. | ||
*/ | ||
onPostPause?: () => void; | ||
/** | ||
* A function that will be called immediately after the trap's state is updated to be active | ||
* again, but prior to updating its knowledge of what nodes are tabbable within its containers, | ||
* and prior to actively managing/trapping focus. | ||
*/ | ||
onUnpause?: () => void; | ||
/** | ||
* A function that will be called after the trap has been completely unpaused and is once | ||
* again managing/trapping focus. | ||
*/ | ||
onPostUnpause?: () => void; | ||
/** | ||
* A function for determining if it is safe to send focus to the focus trap | ||
@@ -202,2 +226,4 @@ * or not. | ||
type ActivateOptions = Pick<Options, 'onActivate' | 'onPostActivate' | 'checkCanFocusTrap'>; | ||
type PauseOptions = Pick<Options, 'onPause' | 'onPostPause'>; | ||
type UnpauseOptions = Pick<Options, 'onUnpause' | 'onPostUnpause'>; | ||
@@ -213,4 +239,4 @@ interface DeactivateOptions extends Pick<Options, 'onDeactivate' | 'onPostDeactivate' | 'checkCanReturnFocus'> { | ||
deactivate(deactivateOptions?: DeactivateOptions): FocusTrap; | ||
pause(): FocusTrap; | ||
unpause(): FocusTrap; | ||
pause(pauseOptions?: PauseOptions): FocusTrap; | ||
unpause(unpauseOptions?: UnpauseOptions): FocusTrap; | ||
updateContainerElements(containerElements: HTMLElement | SVGElement | string | Array<HTMLElement | SVGElement | string>): FocusTrap; | ||
@@ -217,0 +243,0 @@ } |
32
index.js
@@ -682,5 +682,3 @@ import { tabbable, focusable, isFocusable, isTabbable } from 'tabbable'; | ||
if (onActivate) { | ||
onActivate(); | ||
} | ||
onActivate?.(); | ||
@@ -692,5 +690,3 @@ const finishActivation = () => { | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
onPostActivate?.(); | ||
}; | ||
@@ -740,5 +736,3 @@ | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
onDeactivate?.(); | ||
@@ -750,5 +744,3 @@ const finishDeactivation = () => { | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
} | ||
onPostDeactivate?.(); | ||
}); | ||
@@ -768,3 +760,3 @@ }; | ||
pause() { | ||
pause(pauseOptions) { | ||
if (state.paused || !state.active) { | ||
@@ -774,9 +766,15 @@ return this; | ||
const onPause = getOption(pauseOptions, 'onPause'); | ||
const onPostPause = getOption(pauseOptions, 'onPostPause'); | ||
state.paused = true; | ||
onPause?.(); | ||
removeListeners(); | ||
onPostPause?.(); | ||
return this; | ||
}, | ||
unpause() { | ||
unpause(unpauseOptions) { | ||
if (!state.paused || !state.active) { | ||
@@ -786,6 +784,12 @@ return this; | ||
const onUnpause = getOption(unpauseOptions, 'onUnpause'); | ||
const onPostUnpause = getOption(unpauseOptions, 'onPostUnpause'); | ||
state.paused = false; | ||
onUnpause?.(); | ||
updateTabbableNodes(); | ||
addListeners(); | ||
onPostUnpause?.(); | ||
return this; | ||
@@ -792,0 +796,0 @@ }, |
{ | ||
"name": "focus-trap", | ||
"version": "7.3.1", | ||
"version": "7.4.0", | ||
"description": "Trap focus within a DOM node.", | ||
@@ -82,6 +82,6 @@ "main": "dist/focus-trap.js", | ||
"cross-env": "^7.0.3", | ||
"cypress": "^12.5.1", | ||
"cypress": "^12.7.0", | ||
"cypress-plugin-tab": "^1.0.5", | ||
"eslint": "^8.34.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint": "^8.35.0", | ||
"eslint-config-prettier": "^8.7.0", | ||
"eslint-plugin-cypress": "^2.12.1", | ||
@@ -97,5 +97,5 @@ "eslint-plugin-jest": "^27.2.1", | ||
"rollup-plugin-terser": "^7.0.1", | ||
"start-server-and-test": "^1.15.4", | ||
"start-server-and-test": "^2.0.0", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
@@ -96,2 +96,6 @@ # focus-trap [![CI](https://github.com/focus-trap/focus-trap/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/focus-trap/focus-trap/actions?query=workflow:CI+branch:master) [![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE) | ||
- **onPostActivate** `{() => void}`: A function that will be called **after** sending focus to the target element upon activation. | ||
- **onPause** `{() => void}`: A function that will be called immediately after the trap's state is updated to be paused. | ||
- **onPostPause** `{() => void}`: A function that will be called after the trap has been completely paused and is no longer managing/trapping focus. | ||
- **onUnpause** `{() => void}`: A function that will be called immediately after the trap's state is updated to be active again, but prior to updating its knowledge of what nodes are tabbable within its containers, and prior to actively managing/trapping focus. | ||
- **onPostUnpause** `{() => void}`: A function that will be called after the trap has been completely unpaused and is once again managing/trapping focus. | ||
- **checkCanFocusTrap** `{(containers: Array<HTMLElement | SVGElement>) => Promise<void>}`: Animated dialogs have a small delay between when `onActivate` is called and when the focus trap is focusable. `checkCanFocusTrap` expects a promise to be returned. When that promise settles (resolves or rejects), focus will be sent to the first tabbable node (in tab order) in the focus trap (or the node configured in the `initialFocus` option). | ||
@@ -210,3 +214,3 @@ - **onDeactivate** `{() => void}`: A function that will be called **before** returning focus to the node that had focus prior to activation (or configured with the `setReturnFocus` option) upon deactivation. | ||
```typescript | ||
trap.pause() => FocusTrap | ||
trap.pause([pauseOptions]) => FocusTrap | ||
``` | ||
@@ -224,6 +228,13 @@ | ||
`pauseOptions`: | ||
These options are used to override the focus trap's default behavior for this particular pausing. | ||
- **onPause** `{() => void}`: Default: whatever you chose for `createOptions.onPause`. `null` or `false` are the equivalent of a `noop`. | ||
- **onPostPause** `{() => void}`: Default: whatever you chose for `createOptions.onPostPause`. `null` or `false` are the equivalent of a `noop`. | ||
### trap.unpause() | ||
```typescript | ||
trap.unpause() => FocusTrap | ||
trap.unpause([unpauseOptions]) => FocusTrap | ||
``` | ||
@@ -239,2 +250,9 @@ | ||
`unpauseOptions`: | ||
These options are used to override the focus trap's default behavior for this particular unpausing. | ||
- **onUnpause** `{() => void}`: Default: whatever you chose for `createOptions.onUnpause`. `null` or `false` are the equivalent of a `noop`. | ||
- **onPostUnpause** `{() => void}`: Default: whatever you chose for `createOptions.onPostUnpause`. `null` or `false` are the equivalent of a `noop`. | ||
### trap.updateContainerElements() | ||
@@ -241,0 +259,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487362
3109
394