Socket
Socket
Sign inDemoInstall

@radix-ui/react-focus-scope

Package Overview
Dependencies
Maintainers
5
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-focus-scope - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

2

dist/index.js

@@ -1,2 +0,2 @@

var e,t,n=require("@radix-ui/react-use-callback-ref").useCallbackRef,r=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e);function u(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e){var t=document.activeElement;function n(t){if(!u.paused){var n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||a(e,n)}}var r,u={paused:!1,pause:function(){return u.paused=!0},resume:function(){return u.paused=!1},trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:function(){var n;!function(e){e.removeAttribute("tabIndex")}(e),u.untrap(),n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0}),e.dispatchEvent(n),n.defaultPrevented||i(t),s.remove(u)}};return s.add(u),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),r=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0}),e.dispatchEvent(r),r.defaultPrevented||a(e,null),u}function a(e,t){var n,r=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}})}(e),u=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;if(u&Node.DOCUMENT_POSITION_PRECEDING)i(null!==(n=r.firstChild())&&void 0!==n?n:e);else if(u&Node.DOCUMENT_POSITION_FOLLOWING){var o;i(null!==(o=r.lastChild())&&void 0!==o?o:e)}}function i(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}var f,s=(f=[],{add:function(e){var t=f[0];e!==t&&(null==t||t.pause()),(f=d(f,e)).unshift(e)},remove:function(e){var t;null===(t=(f=d(f,e))[0])||void 0===t||t.resume()},size:function(){return f.length}});function d(e,t){var n=u(e),r=n.indexOf(t);return-1!==r&&n.splice(r,1),n}function l(e){var t=e.children,u=e.trapped,o=void 0!==u&&u,a=r.useRef(null),i=r.useRef(),f=n(e.onMountAutoFocus),s=n(e.onUnmountAutoFocus);return r.useEffect((function(){var e=a.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",f),e.addEventListener("focusScope.autoFocusOnDestroy",s),i.current=c(e),function(){e.removeEventListener("focusScope.autoFocusOnCreate",f),setTimeout((function(){var t;null===(t=i.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",s)}),0)}}),[a,f,s]),r.useEffect((function(){var e;if(o)return null===(e=i.current)||void 0===e||e.trap(),function(){var e;return null===(e=i.current)||void 0===e?void 0:e.untrap()}}),[o]),t({ref:a})}exports.FocusScope=l;var v=l;exports.Root=v;
function e(e){return e&&e.__esModule?e.default:e}function t(e,t,n){Object.defineProperty(e,t,{get:n,enumerable:!0})}var n=require("@radix-ui/react-use-callback-ref").useCallbackRef,r=e(require("@babel/runtime-corejs3/core-js-stable/instance/splice")),u=e(require("@babel/runtime-corejs3/core-js-stable/instance/index-of")),o=e(require("@babel/runtime-corejs3/helpers/toConsumableArray")),c=require("react"),a=c.useRef,i=c.useEffect,s=e(require("@babel/runtime-corejs3/core-js-stable/set-timeout")),l={};function d(e){var t=document.activeElement;function n(t){if(!u.paused){var n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||f(e,n)}}var r,u={paused:!1,pause:function(){return u.paused=!0},resume:function(){return u.paused=!1},trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:function(){var n;!function(e){e.removeAttribute("tabIndex")}(e),u.untrap(),n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0}),e.dispatchEvent(n),n.defaultPrevented||v(t),b.remove(u)}};return b.add(u),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),r=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0}),e.dispatchEvent(r),r.defaultPrevented||f(e,null),u}function f(e,t){var n,r=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}})}(e),u=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;if(u&Node.DOCUMENT_POSITION_PRECEDING)v(null!==(n=r.firstChild())&&void 0!==n?n:e);else if(u&Node.DOCUMENT_POSITION_FOLLOWING){var o;v(null!==(o=r.lastChild())&&void 0!==o?o:e)}}function v(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}var p,b=(p=[],{add:function(e){var t=p[0];e!==t&&(null==t||t.pause()),(p=E(p,e)).unshift(e)},remove:function(e){var t;null===(t=(p=E(p,e))[0])||void 0===t||t.resume()},size:function(){return p.length}});function E(e,t){var n=o(e),c=u(n).call(n,t);return-1!==c&&r(n).call(n,c,1),n}function m(e){var t=e.children,r=e.trapped,u=void 0!==r&&r,o=a(null),c=a(),l=n(e.onMountAutoFocus),f=n(e.onUnmountAutoFocus);return i((function(){var e=o.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",l),e.addEventListener("focusScope.autoFocusOnDestroy",f),c.current=d(e),function(){e.removeEventListener("focusScope.autoFocusOnCreate",l),s((function(){var t;null===(t=c.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",f)}),0)}}),[o,l,f]),i((function(){var e;if(u)return null===(e=c.current)||void 0===e||e.trap(),function(){var e;return null===(e=c.current)||void 0===e?void 0:e.untrap()}}),[u]),t({ref:o})}exports.FocusScope=m;var O=m;exports.Root=O,t(l,"Root",(function(){return O})),t(l,"FocusScope",(function(){return m}));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{useCallbackRef as e}from"@radix-ui/react-use-callback-ref";import*as t from"react";function n(e){const t=document.activeElement;function n(t){if(c.paused)return;const n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||o(e,n)}const c={paused:!1,pause:()=>c.paused=!0,resume:()=>c.paused=!1,trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:()=>{!function(e){e.removeAttribute("tabIndex")}(e),c.untrap(),function(){const n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0});e.dispatchEvent(n),n.defaultPrevented||u(t)}(),r.remove(c)}};return r.add(c),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),function(){const t=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0});e.dispatchEvent(t),t.defaultPrevented||o(e,null)}(),c}function o(e,t){const n=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP})}(e),o=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;var r;if(o&Node.DOCUMENT_POSITION_PRECEDING)u(null!==(r=n.firstChild())&&void 0!==r?r:e);else if(o&Node.DOCUMENT_POSITION_FOLLOWING){var c;u(null!==(c=n.lastChild())&&void 0!==c?c:e)}}function u(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}const r=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=c(e,t),e.unshift(t)},remove(t){var n;e=c(e,t),null===(n=e[0])||void 0===n||n.resume()},size:()=>e.length}}();function c(e,t){const n=[...e],o=n.indexOf(t);return-1!==o&&n.splice(o,1),n}export function FocusScope(o){const{children:u,trapped:r=!1}=o,c=t.useRef(null),s=t.useRef(),a=e(o.onMountAutoFocus),i=e(o.onUnmountAutoFocus);return t.useEffect((()=>{const e=c.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",a),e.addEventListener("focusScope.autoFocusOnDestroy",i),s.current=n(e),()=>{e.removeEventListener("focusScope.autoFocusOnCreate",a),setTimeout((()=>{var t;null===(t=s.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",i)}),0)}}),[c,a,i]),t.useEffect((()=>{var e;if(r)return null===(e=s.current)||void 0===e||e.trap(),()=>{var e;return null===(e=s.current)||void 0===e?void 0:e.untrap()}}),[r]),u({ref:c})}export const Root=FocusScope;
function e(e,t,n){Object.defineProperty(e,t,{get:n,enumerable:!0})}import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import n from"@babel/runtime-corejs3/core-js-stable/instance/splice";import r from"@babel/runtime-corejs3/core-js-stable/instance/index-of";import o from"@babel/runtime-corejs3/helpers/esm/toConsumableArray";import{useRef as u,useEffect as c}from"react";import a from"@babel/runtime-corejs3/core-js-stable/set-timeout";var i={};function s(e){var t=document.activeElement;function n(t){if(!o.paused){var n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||f(e,n)}}var r,o={paused:!1,pause:function(){return o.paused=!0},resume:function(){return o.paused=!1},trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:function(){var n;!function(e){e.removeAttribute("tabIndex")}(e),o.untrap(),n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0}),e.dispatchEvent(n),n.defaultPrevented||l(t),v.remove(o)}};return v.add(o),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),r=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0}),e.dispatchEvent(r),r.defaultPrevented||f(e,null),o}function f(e,t){var n,r=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}})}(e),o=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;if(o&Node.DOCUMENT_POSITION_PRECEDING)l(null!==(n=r.firstChild())&&void 0!==n?n:e);else if(o&Node.DOCUMENT_POSITION_FOLLOWING){var u;l(null!==(u=r.lastChild())&&void 0!==u?u:e)}}function l(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}var d,v=(d=[],{add:function(e){var t=d[0];e!==t&&(null==t||t.pause()),(d=p(d,e)).unshift(e)},remove:function(e){var t;null===(t=(d=p(d,e))[0])||void 0===t||t.resume()},size:function(){return d.length}});function p(e,t){var u=o(e),c=r(u).call(u,t);return-1!==c&&n(u).call(u,c,1),u}function m(e){var n=e.children,r=e.trapped,o=void 0!==r&&r,i=u(null),f=u(),l=t(e.onMountAutoFocus),d=t(e.onUnmountAutoFocus);return c((function(){var e=i.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",l),e.addEventListener("focusScope.autoFocusOnDestroy",d),f.current=s(e),function(){e.removeEventListener("focusScope.autoFocusOnCreate",l),a((function(){var t;null===(t=f.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",d)}),0)}}),[i,l,d]),c((function(){var e;if(o)return null===(e=f.current)||void 0===e||e.trap(),function(){var e;return null===(e=f.current)||void 0===e?void 0:e.untrap()}}),[o]),n({ref:i})}export{m as FocusScope};export var Root=m;e(i,"Root",(function(){return Root})),e(i,"FocusScope",(function(){return m}));
//# sourceMappingURL=index.module.js.map
{
"name": "@radix-ui/react-focus-scope",
"version": "0.0.6",
"version": "0.0.7",
"license": "MIT",

@@ -16,6 +16,8 @@ "source": "src/index.ts",

"clean": "rm -rf dist",
"prepublish": "yarn clean"
"prepublish": "yarn clean",
"version": "yarn version"
},
"dependencies": {
"@radix-ui/react-use-callback-ref": "0.0.1"
"@babel/runtime-corejs3": "^7.13.10",
"@radix-ui/react-use-callback-ref": "0.0.2"
},

@@ -22,0 +24,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc