@interop-ui/react-utils
Advanced tools
Comparing version 0.0.1-3 to 0.0.1-4
import * as React from "react"; | ||
import { interopDataAttrObj, interopDataAttrSelector, ElementTagNameMap } from "@interop-ui/utils"; | ||
export function composeEventHandlers<E extends React.SyntheticEvent | Event>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, { checkForDefaultPrevented }?: { | ||
@@ -3,0 +4,0 @@ checkForDefaultPrevented?: boolean | undefined; |
@@ -1,2 +0,2 @@ | ||
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.useDocumentRef=function(e){var t=s.useRef(document);return w((function(){e.current instanceof Element&&(t.current=e.current.ownerDocument)})),t},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=P("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(C.Provider,{value:a},s.createElement(F.Provider,{value:i},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}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 S=a()?s.useLayoutEffect:s.useEffect;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 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 g(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 g(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 g(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.useIsomorphicLayoutEffect=S,exports.useDocumentRef=function(e){var t=s.useRef(document);return S((function(){e.current instanceof Element&&(t.current=e.current.ownerDocument)})),t};var w=0;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.useId=function(){return h(s.useState((function(){return w+=1})),1)[0]},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 S((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=P("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(C.Provider,{value:a},s.createElement(F.Provider,{value:i},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]; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{interopDataAttrObj as e,interopDataAttrSelector as t,isFunction as o,canUseDOM as n,observeElementRect as r,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(n){if(null==e||e(n),!1===o||!n.defaultPrevented)return null==t?void 0:t(n)}}export function createContext(e,t){const o=s.createContext(null);return o.displayName=e,[o,function(e){const n=s.useContext(o);if(null===n)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return n}]}export function createStyleObj(n,r){return[o(r)?r(e=>{const o=getNamespacedPart(n,e);return t(o)}):r,t=>{const o=getNamespacedPart(n,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:n}){const r=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,r),onKeyDown:composeEventHandlers(n,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:n}){const[r,u]=s.useState(t),c=void 0!==n?n:void 0!==e,a=c?e:r,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=n()?s.useLayoutEffect:s.useEffect;export function usePrevious(e){const t=s.useRef();return s.useEffect(()=>{t.current=e},[e]),t.current}export function useDocumentRef(e){const t=s.useRef(document);return useIsomorphicLayoutEffect(()=>{e.current instanceof Element&&(t.current=e.current.ownerDocument)}),t}export function useRect(e){const[t,o]=s.useState();return useIsomorphicLayoutEffect(()=>{if(e.current){const t=r(e.current,o);return()=>{o(void 0),t()}}},[e]),t}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}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:n,onKeyDown:r}){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(n,f,{checkForDefaultPrevented:!1}),onKeyDown:composeEventHandlers(r,d),tabIndex:l?0:-1}}export function RovingTabIndexProvider({children:e,orientation:t,shouldLoop:o=!0}){const[n,r]=s.useReducer(f,{orientation:t,shouldLoop:o,tabStops:[],currentTabStopId:null});return s.useEffect(()=>{r({type:"updateOrientation",orientation:t})},[t,r]),s.useEffect(()=>{r({type:"updateShouldLoop",shouldLoop:o})},[o,r]),s.createElement(d.Provider,{value:n},s.createElement(v.Provider,{value:r},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 n=e.tabStops.findIndex(e=>!(!e.ref.current||!o.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(o.ref.current)&Node.DOCUMENT_POSITION_PRECEDING));return-1===n&&(n=e.tabStops.length),l(l({},e),{},{tabStops:u(e.tabStops,o,n)})}case"unregister":{const{id:o}=t,n=e.tabStops.filter(e=>e.id!==o);return n.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):l(l({},e),{},{tabStops:n})}case"moveFocus":{const{id:o}=t;if(null===o)return l(l({},e),{},{currentTabStopId:null});const n=e.tabStops.findIndex(e=>e.id===o);return-1===n?e:l(l({},e),{},{currentTabStopId:e.tabStops[n].id})}case"moveFocusToNext":{var o,n;if(null==e.currentTabStopId)return f(e,{type:"moveFocus",id:null!==(n=e.tabStops[0].id)&&void 0!==n?n:null});const t=e.tabStops.findIndex(t=>t.id===e.currentTabStopId),r=e.tabStops.length,u=e.shouldLoop?(t+1)%r:c(t+1,[0,r-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 r;const t=e.tabStops[0];return f(e,{type:"moveFocus",id:null!==(r=t.id)&&void 0!==r?r: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"); | ||
import{interopDataAttrObj as e,interopDataAttrSelector as t,isFunction as o,canUseDOM as n,observeElementRect as r,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(n){if(null==e||e(n),!1===o||!n.defaultPrevented)return null==t?void 0:t(n)}}export function createContext(e,t){const o=s.createContext(null);return o.displayName=e,[o,function(e){const n=s.useContext(o);if(null===n)throw new Error("`".concat(e,"` must be used within `").concat(t,"`"));return n}]}export function createStyleObj(n,r){return[o(r)?r(e=>{const o=getNamespacedPart(n,e);return t(o)}):r,t=>{const o=getNamespacedPart(n,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:n}){const r=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,r),onKeyDown:composeEventHandlers(n,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:n}){const[r,u]=s.useState(t),c=void 0!==n?n:void 0!==e,a=c?e:r,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]}export const useIsomorphicLayoutEffect=n()?s.useLayoutEffect:s.useEffect;export function useDocumentRef(e){const t=s.useRef(document);return useIsomorphicLayoutEffect(()=>{e.current instanceof Element&&(t.current=e.current.ownerDocument)}),t}let a=0;export const useId=()=>{const[e]=s.useState(()=>(a+=1,a));return e};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=r(e.current,o);return()=>{o(void 0),t()}}},[e]),t}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}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:n,onKeyDown:r}){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(n,f,{checkForDefaultPrevented:!1}),onKeyDown:composeEventHandlers(r,d),tabIndex:l?0:-1}}export function RovingTabIndexProvider({children:e,orientation:t,shouldLoop:o=!0}){const[n,r]=s.useReducer(f,{orientation:t,shouldLoop:o,tabStops:[],currentTabStopId:null});return s.useEffect(()=>{r({type:"updateOrientation",orientation:t})},[t,r]),s.useEffect(()=>{r({type:"updateShouldLoop",shouldLoop:o})},[o,r]),s.createElement(d.Provider,{value:n},s.createElement(v.Provider,{value:r},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 n=e.tabStops.findIndex(e=>!(!e.ref.current||!o.ref.current)&&Boolean(e.ref.current.compareDocumentPosition(o.ref.current)&Node.DOCUMENT_POSITION_PRECEDING));return-1===n&&(n=e.tabStops.length),l(l({},e),{},{tabStops:u(e.tabStops,o,n)})}case"unregister":{const{id:o}=t,n=e.tabStops.filter(e=>e.id!==o);return n.length===e.tabStops.length?(console.warn("".concat(o," tab stop is already unregistered")),e):l(l({},e),{},{tabStops:n})}case"moveFocus":{const{id:o}=t;if(null===o)return l(l({},e),{},{currentTabStopId:null});const n=e.tabStops.findIndex(e=>e.id===o);return-1===n?e:l(l({},e),{},{currentTabStopId:e.tabStops[n].id})}case"moveFocusToNext":{var o,n;if(null==e.currentTabStopId)return f(e,{type:"moveFocus",id:null!==(n=e.tabStops[0].id)&&void 0!==n?n:null});const t=e.tabStops.findIndex(t=>t.id===e.currentTabStopId),r=e.tabStops.length,u=e.shouldLoop?(t+1)%r:c(t+1,[0,r-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 r;const t=e.tabStops[0];return f(e,{type:"moveFocus",id:null!==(r=t.id)&&void 0!==r?r: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-3", | ||
"version": "0.0.1-4", | ||
"license": "MIT", | ||
@@ -14,9 +14,9 @@ "source": "src/index.ts", | ||
"scripts": { | ||
"build": "parcel build src/index.ts", | ||
"build": "parcel build src/index.ts --no-cache", | ||
"clean": "rm -rf dist", | ||
"bump": "yarn version --deferred", | ||
"version": "yarn version", | ||
"prepublish": "yarn clean && yarn build" | ||
}, | ||
"dependencies": { | ||
"@interop-ui/utils": "0.0.1-2" | ||
"@interop-ui/utils": "0.0.1-3" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": { |
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
248
97024
+ Added@interop-ui/utils@0.0.1-3(transitive)
- Removed@interop-ui/utils@0.0.1-2(transitive)
Updated@interop-ui/utils@0.0.1-3