@interop-ui/react-utils
Advanced tools
Comparing version 0.0.1-0 to 0.0.1-1
@@ -1,2 +0,2 @@ | ||
var e,t,r=require("@interop-ui/utils"),n=r.interopDataAttrObj,o=r.interopDataAttrSelector,u=r.isFunction,i=r.canUseDOM,a=r.observeElementRect,c=r.arrayInsert,s=r.clamp,f=(e={},t=require("react"),Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e);function l(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.checkForDefaultPrevented,o=void 0===n||n;return function(r){if(null==e||e(r),!1===o||!r.defaultPrevented)return null==t?void 0:t(r)}}function p(e,t){var r=f.createContext(null);return r.displayName=e,[r,function(e){var n=f.useContext(r);if(null===n)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return n}]}function d(e,t){return"root"===t?e:e+"."+t}function v(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}function b(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.forEach((function(t){return v(t,e)}))}}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return m(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return S(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return S(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}exports.composeEventHandlers=l,exports.createContext=p,exports.createStyleObj=function(e,t){return[u(t)?t((function(t){var r=d(e,t);return o(r)})):t,function(t){var r=d(e,t);return n(r)}]},exports.getNamespacedPart=d,exports.forwardRef=function(e){return f.forwardRef(e)},exports.memo=function(e,t){return f.memo(e,t)},exports.useAccessibleMouseDown=function(e,t){var r=t.isDisabled,n=t.onMouseDown,o=t.onKeyDown,u=f.useCallback((function(t){r?t.preventDefault():0===t.button&&!1===t.ctrlKey&&e(t)}),[e,r]),i=f.useCallback((function(t){r||" "!==t.key&&"Enter"!==t.key||(t.preventDefault(),e(t))}),[e,r]);return{onMouseDown:l(n,u),onKeyDown:l(o,i)}},exports.useCallbackRef=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f.useEffect,r=f.useRef(e);return t((function(){r.current=e})),f.useCallback((function(){r.current.apply(r,arguments)}),[])},exports.composeRefs=b,exports.useComposedRefs=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return f.useCallback(b.apply(void 0,t),t)},exports.useConstant=function(e){var t=f.useRef();return t.current||(t.current={v:e()}),t.current.v},exports.useControlledState=function(e){var t=e.prop,r=e.defaultProp,n=e.onChange,o=void 0===n?function(){}:n,u=e.unstable__isControlled,i=y(f.useState(r),2),a=i[0],c=i[1],s=void 0!==u?u:void 0!==t,l=s?t:a,p=f.useRef(s),d=f.useRef(l),v=f.useRef(l),b=f.useRef(o);f.useEffect((function(){v.current=l,b.current=o}));var m=f.useCallback((function(e){var t=function(t){var r=function(e,t){var r;if("function"==typeof t){r=t(e)}else r=t;return r}(t,e);return b.current(r),r};p.current?t(v.current):c(t)}),[]),h=f.useCallback((function(){m(d.current)}),[m]);return[l,m,h]};var g=0;exports.useId=function(){return h(f.useState((function(){return g+=1})),1)[0]};var w=i()?f.useLayoutEffect:f.useEffect;function x(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return O(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return O(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure 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 r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function I(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function A(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){j(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function j(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return E(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return E(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function D(e,t){switch(t.type){case"register":var r=t.tabStop;if(0===e.tabStops.length)return A(A({},e),{},{tabStops:[r]});if(e.tabStops.map((function(e){return e.id})).includes(r.id))return console.warn("".concat(r.id," tab stop is already registered")),e;var n=e.tabStops.findIndex((function(e){return!(!e.ref.current||!r.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(r.ref.current)&Node.DOCUMENT_POSITION_PRECEDING)}));return-1===n&&(n=e.tabStops.length),A(A({},e),{},{tabStops:c(e.tabStops,r,n)});case"unregister":var o=t.id,u=e.tabStops.filter((function(e){return e.id!==o}));return u.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):A(A({},e),{},{tabStops:u});case"moveFocus":var i=t.id;if(null===i)return A(A({},e),{},{currentTabStopId:null});var a=e.tabStops.findIndex((function(e){return e.id===i}));return-1===a?e:A(A({},e),{},{currentTabStopId:e.tabStops[a].id});case"moveFocusToNext":var f,l;if(null==e.currentTabStopId)return D(e,{type:"moveFocus",id:null!==(l=e.tabStops[0].id)&&void 0!==l?l:null});var p=e.tabStops.findIndex((function(t){return t.id===e.currentTabStopId})),d=e.tabStops.length,v=e.shouldLoop?(p+1)%d:s(p+1,[0,d-1]);return D(e,{type:"moveFocus",id:null!==(f=e.tabStops[v].id)&&void 0!==f?f:null});case"moveFocusToPrevious":var b=D(A(A({},e),{},{tabStops:e.tabStops.slice().reverse()}),{type:"moveFocusToNext"}).currentTabStopId;return A(A({},e),{},{currentTabStopId:b});case"moveFocusToFirst":var y,m=e.tabStops[0];return D(e,{type:"moveFocus",id:null!==(y=m.id)&&void 0!==y?y:null});case"moveFocusToLast":var h,S=e.tabStops[e.tabStops.length-1];return D(e,{type:"moveFocus",id:null!==(h=S.id)&&void 0!==h?h:null});case"updateOrientation":return A(A({},e),{},{orientation:t.orientation});case"updateShouldLoop":return A(A({},e),{},{shouldLoop:t.shouldLoop});default:throw new Error}}exports.useIsomorphicLayoutEffect=w,exports.usePrevious=function(e){var t=f.useRef();return f.useEffect((function(){t.current=e}),[e]),t.current},exports.useRect=function(e){var t=e.refToObserve,r=e.isObserving,n=void 0===r||r,o=e.shouldResetWhenNotObserving,u=void 0!==o&&o,i=x(f.useState(),2),c=i[0],s=i[1];return w((function(){if(n&&t.current){var e=a(t.current,s);return function(){u&&s(void 0),e()}}}),[n,t,u]),c},exports.useRovingTabIndex=function(e){var t=e.id,r=e.isSelected,n=e.elementRef,o=e.onFocus,u=e.onKeyDown,i=P("useRovingTabIndex"),a=i.orientation,c=i.currentTabStopId,s=L("useRovingTabIndex"),p=c===t,d=r;f.useEffect((function(){return s({type:"register",tabStop:{id:t,ref:n}}),function(){s({type:"unregister",id:t})}}),[s,n,t]),f.useEffect((function(){var e;p&&(null===(e=n.current)||void 0===e||e.focus())}),[n,p]);var v=f.useCallback((function(e){if("vertical"!==a){if("ArrowRight"===e.key)return"next";if("ArrowLeft"===e.key)return"previous"}else{if("ArrowDown"===e.key)return"next";if("ArrowUp"===e.key)return"previous"}return null}),[a]),b=f.useCallback((function(e){return s({type:"moveFocus",id:t})}),[s,t]),y=f.useCallback((function(e){var t=v(e);"next"===t?(e.preventDefault(),s({type:"moveFocusToNext"})):"previous"===t?(e.preventDefault(),s({type:"moveFocusToPrevious"})):"Home"===e.key?(e.preventDefault(),s({type:"moveFocusToFirst"})):"End"===e.key&&(e.preventDefault(),s({type:"moveFocusToLast"}))}),[s,v]);return{onFocus:l(o,b,{checkForDefaultPrevented:!1}),onKeyDown:l(u,y),tabIndex:d?0:-1}},exports.RovingTabIndexProvider=function(e){var t=e.children,r=e.orientation,n=e.shouldLoop,o=void 0===n||n,u=T(f.useReducer(D,{orientation:r,shouldLoop:o,tabStops:[],currentTabStopId:null}),2),i=u[0],a=u[1];return f.useEffect((function(){a({type:"updateOrientation",orientation:r})}),[r,a]),f.useEffect((function(){a({type:"updateShouldLoop",shouldLoop:o})}),[o,a]),f.createElement(C.Provider,{value:i},f.createElement(F.Provider,{value:a},t))};var R=T(p("RovingTabIndexStateContext","RovingTabIndexProvider"),2),C=R[0],P=R[1],k=T(p("RovingTabIndexStateContext","RovingTabIndexProvider"),2),F=k[0],L=k[1]; | ||
var e,t,r=require("@interop-ui/utils"),n=r.interopDataAttrObj,o=r.interopDataAttrSelector,u=r.isFunction,a=r.canUseDOM,i=r.observeElementRect,c=r.arrayInsert,f=r.clamp,s=(e={},t=require("react"),Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e);function l(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.checkForDefaultPrevented,o=void 0===n||n;return function(r){if(null==e||e(r),!1===o||!r.defaultPrevented)return null==t?void 0:t(r)}}function p(e,t){var r=s.createContext(null);return r.displayName=e,[r,function(e){var n=s.useContext(r);if(null===n)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return n}]}function d(e,t){return"root"===t?e:e+"."+t}function v(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}function y(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.forEach((function(t){return v(t,e)}))}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return m(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function S(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return h(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}exports.composeEventHandlers=l,exports.createContext=p,exports.createStyleObj=function(e,t){return[u(t)?t((function(t){var r=d(e,t);return o(r)})):t,function(t){var r=d(e,t);return n(r)}]},exports.getNamespacedPart=d,exports.forwardRef=function(e){return s.forwardRef(e)},exports.memo=function(e,t){return s.memo(e,t)},exports.useAccessibleMouseDown=function(e,t){var r=t.isDisabled,n=t.onMouseDown,o=t.onKeyDown,u=s.useCallback((function(t){r?t.preventDefault():0===t.button&&!1===t.ctrlKey&&e(t)}),[e,r]),a=s.useCallback((function(t){r||" "!==t.key&&"Enter"!==t.key||(t.preventDefault(),e(t))}),[e,r]);return{onMouseDown:l(n,u),onKeyDown:l(o,a)}},exports.useCallbackRef=function(e){var t=s.useRef(e);return s.useEffect((function(){t.current=e})),s.useCallback((function(){t.current.apply(t,arguments)}),[])},exports.composeRefs=y,exports.useComposedRefs=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return s.useCallback(y.apply(void 0,t),t)},exports.useConstant=function(e){var t=s.useRef();return t.current||(t.current={v:e()}),t.current.v},exports.useControlledState=function(e){var t=e.prop,r=e.defaultProp,n=e.onChange,o=void 0===n?function(){}:n,u=e.unstable__isControlled,a=b(s.useState(r),2),i=a[0],c=a[1],f=void 0!==u?u:void 0!==t,l=f?t:i,p=s.useRef(f),d=s.useRef(l),v=s.useRef(l),y=s.useRef(o);s.useEffect((function(){v.current=l,y.current=o}));var m=s.useCallback((function(e){var t=function(t){var r=function(e,t){var r;if("function"==typeof t){r=t(e)}else r=t;return r}(t,e);return y.current(r),r};p.current?t(v.current):c(t)}),[]),S=s.useCallback((function(){m(d.current)}),[m]);return[l,m,S]};var g=0;exports.useId=function(){return S(s.useState((function(){return g+=1})),1)[0]};var w=a()?s.useLayoutEffect:s.useEffect;function x(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return O(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return O(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure 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 r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function I(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function A(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){j(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function j(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return E(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return E(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function D(e,t){switch(t.type){case"register":var r=t.tabStop;if(0===e.tabStops.length)return A(A({},e),{},{tabStops:[r]});if(e.tabStops.map((function(e){return e.id})).includes(r.id))return console.warn("".concat(r.id," tab stop is already registered")),e;var n=e.tabStops.findIndex((function(e){return!(!e.ref.current||!r.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(r.ref.current)&Node.DOCUMENT_POSITION_PRECEDING)}));return-1===n&&(n=e.tabStops.length),A(A({},e),{},{tabStops:c(e.tabStops,r,n)});case"unregister":var o=t.id,u=e.tabStops.filter((function(e){return e.id!==o}));return u.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):A(A({},e),{},{tabStops:u});case"moveFocus":var a=t.id;if(null===a)return A(A({},e),{},{currentTabStopId:null});var i=e.tabStops.findIndex((function(e){return e.id===a}));return-1===i?e:A(A({},e),{},{currentTabStopId:e.tabStops[i].id});case"moveFocusToNext":var s,l;if(null==e.currentTabStopId)return D(e,{type:"moveFocus",id:null!==(l=e.tabStops[0].id)&&void 0!==l?l:null});var p=e.tabStops.findIndex((function(t){return t.id===e.currentTabStopId})),d=e.tabStops.length,v=e.shouldLoop?(p+1)%d:f(p+1,[0,d-1]);return D(e,{type:"moveFocus",id:null!==(s=e.tabStops[v].id)&&void 0!==s?s:null});case"moveFocusToPrevious":var y=D(A(A({},e),{},{tabStops:e.tabStops.slice().reverse()}),{type:"moveFocusToNext"}).currentTabStopId;return A(A({},e),{},{currentTabStopId:y});case"moveFocusToFirst":var b,m=e.tabStops[0];return D(e,{type:"moveFocus",id:null!==(b=m.id)&&void 0!==b?b:null});case"moveFocusToLast":var S,h=e.tabStops[e.tabStops.length-1];return D(e,{type:"moveFocus",id:null!==(S=h.id)&&void 0!==S?S:null});case"updateOrientation":return A(A({},e),{},{orientation:t.orientation});case"updateShouldLoop":return A(A({},e),{},{shouldLoop:t.shouldLoop});default:throw new Error}}exports.useIsomorphicLayoutEffect=w,exports.usePrevious=function(e){var t=s.useRef();return s.useEffect((function(){t.current=e}),[e]),t.current},exports.useRect=function(e){var t=x(s.useState(),2),r=t[0],n=t[1];return w((function(){if(e.current){var t=i(e.current,n);return function(){n(void 0),t()}}}),[e]),r},exports.useRovingTabIndex=function(e){var t=e.id,r=e.isSelected,n=e.elementRef,o=e.onFocus,u=e.onKeyDown,a=R("useRovingTabIndex"),i=a.orientation,c=a.currentTabStopId,f=L("useRovingTabIndex"),p=c===t,d=r;s.useEffect((function(){return f({type:"register",tabStop:{id:t,ref:n}}),function(){f({type:"unregister",id:t})}}),[f,n,t]),s.useEffect((function(){var e;p&&(null===(e=n.current)||void 0===e||e.focus())}),[n,p]);var v=s.useCallback((function(e){if("vertical"!==i){if("ArrowRight"===e.key)return"next";if("ArrowLeft"===e.key)return"previous"}else{if("ArrowDown"===e.key)return"next";if("ArrowUp"===e.key)return"previous"}return null}),[i]),y=s.useCallback((function(e){return f({type:"moveFocus",id:t})}),[f,t]),b=s.useCallback((function(e){var t=v(e);"next"===t?(e.preventDefault(),f({type:"moveFocusToNext"})):"previous"===t?(e.preventDefault(),f({type:"moveFocusToPrevious"})):"Home"===e.key?(e.preventDefault(),f({type:"moveFocusToFirst"})):"End"===e.key&&(e.preventDefault(),f({type:"moveFocusToLast"}))}),[f,v]);return{onFocus:l(o,y,{checkForDefaultPrevented:!1}),onKeyDown:l(u,b),tabIndex:d?0:-1}},exports.RovingTabIndexProvider=function(e){var t=e.children,r=e.orientation,n=e.shouldLoop,o=void 0===n||n,u=T(s.useReducer(D,{orientation:r,shouldLoop:o,tabStops:[],currentTabStopId:null}),2),a=u[0],i=u[1];return s.useEffect((function(){i({type:"updateOrientation",orientation:r})}),[r,i]),s.useEffect((function(){i({type:"updateShouldLoop",shouldLoop:o})}),[o,i]),s.createElement(P.Provider,{value:a},s.createElement(F.Provider,{value:i},t))};var C=T(p("RovingTabIndexStateContext","RovingTabIndexProvider"),2),P=C[0],R=C[1],k=T(p("RovingTabIndexStateContext","RovingTabIndexProvider"),2),F=k[0],L=k[1]; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{interopDataAttrObj as e,interopDataAttrSelector as t,isFunction as o,canUseDOM as r,observeElementRect as n,arrayInsert as u,clamp as s}from"@interop-ui/utils";import*as c from"react";export function composeEventHandlers(e,t,{checkForDefaultPrevented:o=!0}={}){return function(r){if(null==e||e(r),!1===o||!r.defaultPrevented)return null==t?void 0:t(r)}}export function createContext(e,t){const o=c.createContext(null);return o.displayName=e,[o,function(e){let r=c.useContext(o);if(null===r)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return r}]}export function createStyleObj(r,n){return[o(n)?n(e=>{const o=getNamespacedPart(r,e);return t(o)}):n,t=>{const o=getNamespacedPart(r,t);return e(o)}]}export function getNamespacedPart(e,t){return"root"===t?e:e+"."+t}export function forwardRef(e){return c.forwardRef(e)}export function memo(e,t){return c.memo(e,t)}export function useAccessibleMouseDown(e,{isDisabled:t,onMouseDown:o,onKeyDown:r}){const n=c.useCallback(o=>{t?o.preventDefault():0===o.button&&!1===o.ctrlKey&&e(o)},[e,t]),u=c.useCallback(o=>{t||" "!==o.key&&"Enter"!==o.key||(o.preventDefault(),e(o))},[e,t]);return{onMouseDown:composeEventHandlers(o,n),onKeyDown:composeEventHandlers(r,u)}}export function useCallbackRef(e,t=c.useEffect){const o=c.useRef(e);return t(()=>{o.current=e}),c.useCallback((...e)=>{o.current(...e)},[])}export function composeRefs(...e){return t=>e.forEach(e=>function(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}(e,t))}export function useComposedRefs(...e){return c.useCallback(composeRefs(...e),e)}export function useConstant(e){const t=c.useRef();return t.current||(t.current={v:e()}),t.current.v}export function useControlledState({prop:e,defaultProp:t,onChange:o=(()=>{}),unstable__isControlled:r}){const[n,u]=c.useState(t),s=void 0!==r?r:void 0!==e,a=s?e:n,i=c.useRef(s),l=c.useRef(a),p=c.useRef(a),f=c.useRef(o);c.useEffect(()=>{p.current=a,f.current=o});const d=c.useCallback((function(e){const t=t=>{const o=function(e,t){let o;if("function"==typeof t){o=t(e)}else o=t;return o}(t,e);return f.current(o),o};i.current?t(p.current):u(t)}),[]),b=c.useCallback((function(){d(l.current)}),[d]);return[a,d,b]}let a=0;export const useId=()=>{const[e]=c.useState(()=>(a+=1,a));return e};export const useIsomorphicLayoutEffect=r()?c.useLayoutEffect:c.useEffect;export function usePrevious(e){const t=c.useRef();return c.useEffect(()=>{t.current=e},[e]),t.current}export function useRect({refToObserve:e,isObserving:t=!0,shouldResetWhenNotObserving:o=!1}){const[r,u]=c.useState();return useIsomorphicLayoutEffect(()=>{if(t&&e.current){const t=n(e.current,u);return()=>{o&&u(void 0),t()}}},[t,e,o]),r}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function l(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?i(Object(o),!0).forEach((function(t){p(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):i(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function p(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}export function useRovingTabIndex({id:e,isSelected:t,elementRef:o,onFocus:r,onKeyDown:n}){const{orientation:u,currentTabStopId:s}=b("useRovingTabIndex"),a=m("useRovingTabIndex"),i=s===e,l=t;c.useEffect(()=>(a({type:"register",tabStop:{id:e,ref:o}}),()=>{a({type:"unregister",id:e})}),[a,o,e]),c.useEffect(()=>{var e;i&&(null===(e=o.current)||void 0===e||e.focus())},[o,i]);const p=c.useCallback(e=>{if("vertical"!==u){if("ArrowRight"===e.key)return"next";if("ArrowLeft"===e.key)return"previous"}else{if("ArrowDown"===e.key)return"next";if("ArrowUp"===e.key)return"previous"}return null},[u]),f=c.useCallback(t=>a({type:"moveFocus",id:e}),[a,e]),d=c.useCallback(e=>{const t=p(e);"next"===t?(e.preventDefault(),a({type:"moveFocusToNext"})):"previous"===t?(e.preventDefault(),a({type:"moveFocusToPrevious"})):"Home"===e.key?(e.preventDefault(),a({type:"moveFocusToFirst"})):"End"===e.key&&(e.preventDefault(),a({type:"moveFocusToLast"}))},[a,p]);return{onFocus:composeEventHandlers(r,f,{checkForDefaultPrevented:!1}),onKeyDown:composeEventHandlers(n,d),tabIndex:l?0:-1}}export function RovingTabIndexProvider({children:e,orientation:t,shouldLoop:o=!0}){const[r,n]=c.useReducer(f,{orientation:t,shouldLoop:o,tabStops:[],currentTabStopId:null});return c.useEffect(()=>{n({type:"updateOrientation",orientation:t})},[t,n]),c.useEffect(()=>{n({type:"updateShouldLoop",shouldLoop:o})},[o,n]),c.createElement(d.Provider,{value:r},c.createElement(v.Provider,{value:n},e))}function f(e,t){switch(t.type){case"register":{const o=t.tabStop;if(0===e.tabStops.length)return l(l({},e),{},{tabStops:[o]});if(e.tabStops.map(e=>e.id).includes(o.id))return console.warn("".concat(o.id," tab stop is already registered")),e;let r=e.tabStops.findIndex(e=>!(!e.ref.current||!o.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(o.ref.current)&Node.DOCUMENT_POSITION_PRECEDING));return-1===r&&(r=e.tabStops.length),l(l({},e),{},{tabStops:u(e.tabStops,o,r)})}case"unregister":{const{id:o}=t,r=e.tabStops.filter(e=>e.id!==o);return r.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):l(l({},e),{},{tabStops:r})}case"moveFocus":{const{id:o}=t;if(null===o)return l(l({},e),{},{currentTabStopId:null});const r=e.tabStops.findIndex(e=>e.id===o);return-1===r?e:l(l({},e),{},{currentTabStopId:e.tabStops[r].id})}case"moveFocusToNext":{var o,r;if(null==e.currentTabStopId)return f(e,{type:"moveFocus",id:null!==(r=e.tabStops[0].id)&&void 0!==r?r:null});const t=e.tabStops.findIndex(t=>t.id===e.currentTabStopId),n=e.tabStops.length,u=e.shouldLoop?(t+1)%n:s(t+1,[0,n-1]);return f(e,{type:"moveFocus",id:null!==(o=e.tabStops[u].id)&&void 0!==o?o:null})}case"moveFocusToPrevious":{const t=l(l({},e),{},{tabStops:e.tabStops.slice().reverse()}),{currentTabStopId:o}=f(t,{type:"moveFocusToNext"});return l(l({},e),{},{currentTabStopId:o})}case"moveFocusToFirst":{var n;const t=e.tabStops[0];return f(e,{type:"moveFocus",id:null!==(n=t.id)&&void 0!==n?n:null})}case"moveFocusToLast":{var c;const t=e.tabStops[e.tabStops.length-1];return f(e,{type:"moveFocus",id:null!==(c=t.id)&&void 0!==c?c:null})}case"updateOrientation":return l(l({},e),{},{orientation:t.orientation});case"updateShouldLoop":return l(l({},e),{},{shouldLoop:t.shouldLoop});default:throw new Error}}const[d,b]=createContext("RovingTabIndexStateContext","RovingTabIndexProvider"),[v,m]=createContext("RovingTabIndexStateContext","RovingTabIndexProvider"); | ||
import{interopDataAttrObj as e,interopDataAttrSelector as t,isFunction as o,canUseDOM as r,observeElementRect as n,arrayInsert as u,clamp as c}from"@interop-ui/utils";import*as s from"react";export function composeEventHandlers(e,t,{checkForDefaultPrevented:o=!0}={}){return function(r){if(null==e||e(r),!1===o||!r.defaultPrevented)return null==t?void 0:t(r)}}export function createContext(e,t){const o=s.createContext(null);return o.displayName=e,[o,function(e){let r=s.useContext(o);if(null===r)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return r}]}export function createStyleObj(r,n){return[o(n)?n(e=>{const o=getNamespacedPart(r,e);return t(o)}):n,t=>{const o=getNamespacedPart(r,t);return e(o)}]}export function getNamespacedPart(e,t){return"root"===t?e:e+"."+t}export function forwardRef(e){return s.forwardRef(e)}export function memo(e,t){return s.memo(e,t)}export function useAccessibleMouseDown(e,{isDisabled:t,onMouseDown:o,onKeyDown:r}){const n=s.useCallback(o=>{t?o.preventDefault():0===o.button&&!1===o.ctrlKey&&e(o)},[e,t]),u=s.useCallback(o=>{t||" "!==o.key&&"Enter"!==o.key||(o.preventDefault(),e(o))},[e,t]);return{onMouseDown:composeEventHandlers(o,n),onKeyDown:composeEventHandlers(r,u)}}export function useCallbackRef(e){const t=s.useRef(e);return s.useEffect(()=>{t.current=e}),s.useCallback((...e)=>{t.current(...e)},[])}export function composeRefs(...e){return t=>e.forEach(e=>function(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}(e,t))}export function useComposedRefs(...e){return s.useCallback(composeRefs(...e),e)}export function useConstant(e){const t=s.useRef();return t.current||(t.current={v:e()}),t.current.v}export function useControlledState({prop:e,defaultProp:t,onChange:o=(()=>{}),unstable__isControlled:r}){const[n,u]=s.useState(t),c=void 0!==r?r:void 0!==e,a=c?e:n,i=s.useRef(c),l=s.useRef(a),p=s.useRef(a),f=s.useRef(o);s.useEffect(()=>{p.current=a,f.current=o});const d=s.useCallback((function(e){const t=t=>{const o=function(e,t){let o;if("function"==typeof t){o=t(e)}else o=t;return o}(t,e);return f.current(o),o};i.current?t(p.current):u(t)}),[]),b=s.useCallback((function(){d(l.current)}),[d]);return[a,d,b]}let a=0;export const useId=()=>{const[e]=s.useState(()=>(a+=1,a));return e};export const useIsomorphicLayoutEffect=r()?s.useLayoutEffect:s.useEffect;export function usePrevious(e){const t=s.useRef();return s.useEffect(()=>{t.current=e},[e]),t.current}export function useRect(e){const[t,o]=s.useState();return useIsomorphicLayoutEffect(()=>{if(e.current){const t=n(e.current,o);return()=>{o(void 0),t()}}},[e]),t}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function l(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?i(Object(o),!0).forEach((function(t){p(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):i(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function p(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}export function useRovingTabIndex({id:e,isSelected:t,elementRef:o,onFocus:r,onKeyDown:n}){const{orientation:u,currentTabStopId:c}=b("useRovingTabIndex"),a=m("useRovingTabIndex"),i=c===e,l=t;s.useEffect(()=>(a({type:"register",tabStop:{id:e,ref:o}}),()=>{a({type:"unregister",id:e})}),[a,o,e]),s.useEffect(()=>{var e;i&&(null===(e=o.current)||void 0===e||e.focus())},[o,i]);const p=s.useCallback(e=>{if("vertical"!==u){if("ArrowRight"===e.key)return"next";if("ArrowLeft"===e.key)return"previous"}else{if("ArrowDown"===e.key)return"next";if("ArrowUp"===e.key)return"previous"}return null},[u]),f=s.useCallback(t=>a({type:"moveFocus",id:e}),[a,e]),d=s.useCallback(e=>{const t=p(e);"next"===t?(e.preventDefault(),a({type:"moveFocusToNext"})):"previous"===t?(e.preventDefault(),a({type:"moveFocusToPrevious"})):"Home"===e.key?(e.preventDefault(),a({type:"moveFocusToFirst"})):"End"===e.key&&(e.preventDefault(),a({type:"moveFocusToLast"}))},[a,p]);return{onFocus:composeEventHandlers(r,f,{checkForDefaultPrevented:!1}),onKeyDown:composeEventHandlers(n,d),tabIndex:l?0:-1}}export function RovingTabIndexProvider({children:e,orientation:t,shouldLoop:o=!0}){const[r,n]=s.useReducer(f,{orientation:t,shouldLoop:o,tabStops:[],currentTabStopId:null});return s.useEffect(()=>{n({type:"updateOrientation",orientation:t})},[t,n]),s.useEffect(()=>{n({type:"updateShouldLoop",shouldLoop:o})},[o,n]),s.createElement(d.Provider,{value:r},s.createElement(v.Provider,{value:n},e))}function f(e,t){switch(t.type){case"register":{const o=t.tabStop;if(0===e.tabStops.length)return l(l({},e),{},{tabStops:[o]});if(e.tabStops.map(e=>e.id).includes(o.id))return console.warn("".concat(o.id," tab stop is already registered")),e;let r=e.tabStops.findIndex(e=>!(!e.ref.current||!o.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(o.ref.current)&Node.DOCUMENT_POSITION_PRECEDING));return-1===r&&(r=e.tabStops.length),l(l({},e),{},{tabStops:u(e.tabStops,o,r)})}case"unregister":{const{id:o}=t,r=e.tabStops.filter(e=>e.id!==o);return r.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):l(l({},e),{},{tabStops:r})}case"moveFocus":{const{id:o}=t;if(null===o)return l(l({},e),{},{currentTabStopId:null});const r=e.tabStops.findIndex(e=>e.id===o);return-1===r?e:l(l({},e),{},{currentTabStopId:e.tabStops[r].id})}case"moveFocusToNext":{var o,r;if(null==e.currentTabStopId)return f(e,{type:"moveFocus",id:null!==(r=e.tabStops[0].id)&&void 0!==r?r:null});const t=e.tabStops.findIndex(t=>t.id===e.currentTabStopId),n=e.tabStops.length,u=e.shouldLoop?(t+1)%n:c(t+1,[0,n-1]);return f(e,{type:"moveFocus",id:null!==(o=e.tabStops[u].id)&&void 0!==o?o:null})}case"moveFocusToPrevious":{const t=l(l({},e),{},{tabStops:e.tabStops.slice().reverse()}),{currentTabStopId:o}=f(t,{type:"moveFocusToNext"});return l(l({},e),{},{currentTabStopId:o})}case"moveFocusToFirst":{var n;const t=e.tabStops[0];return f(e,{type:"moveFocus",id:null!==(n=t.id)&&void 0!==n?n:null})}case"moveFocusToLast":{var s;const t=e.tabStops[e.tabStops.length-1];return f(e,{type:"moveFocus",id:null!==(s=t.id)&&void 0!==s?s:null})}case"updateOrientation":return l(l({},e),{},{orientation:t.orientation});case"updateShouldLoop":return l(l({},e),{},{shouldLoop:t.shouldLoop});default:throw new Error}}const[d,b]=createContext("RovingTabIndexStateContext","RovingTabIndexProvider"),[v,m]=createContext("RovingTabIndexStateContext","RovingTabIndexProvider"); | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@interop-ui/react-utils", | ||
"version": "0.0.1-0", | ||
"version": "0.0.1-1", | ||
"license": "MIT", | ||
@@ -19,3 +19,3 @@ "source": "src/index.ts", | ||
"dependencies": { | ||
"@interop-ui/utils": "0.0.1-0" | ||
"@interop-ui/utils": "0.0.1-1" | ||
}, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
95255
249
1
+ Added@interop-ui/utils@0.0.1-1(transitive)
- Removed@interop-ui/utils@0.0.1-0(transitive)
Updated@interop-ui/utils@0.0.1-1