@committed/hooks
Advanced tools
Comparing version 0.6.3 to 0.7.0
@@ -1,2 +0,2 @@ | ||
import n,{useState as t,useRef as e,useEffect as r,useLayoutEffect as o,useMemo as u,useCallback as c}from"react";function i(e){void 0===e&&(e=!1);var r=t(e),o=r[1];return[r[0],n.useMemo(function(){return{toggle:function(){return o(function(n){return!n})},setTrue:function(){return o(!0)},setFalse:function(){return o(!1)}}},[o])]}function a(){}function l(n,o,u){var c=e(void 0!==n).current,i=void 0!==n,l=t(function(){if(void 0===n&&void 0!==u)return"function"!=typeof u?u:u()}),f=l[0],v=l[1],d=a;return"production"!==process.env.NODE_ENV&&(d=function(){c!==i&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),r(d,[d,i]),[c?n:f,c?o:v]}function f(n,e){var o=t(n),u=o[0],c=o[1];return r(function(){if(null!==e){var t=setTimeout(function(){c(n)},e);return function(){clearTimeout(t)}}c(n)},[n,e]),[u,function(){return c(n)}]}function v(){return v=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},v.apply(this,arguments)}function d(n,t){var e=Object.keys(v({},n,t)),r={};return e.forEach(function(e){n[""+e]!==t[""+e]&&(r[""+e]={from:n[""+e],to:t[""+e]})}),r}function s(n,t,o){void 0===t&&(t={}),void 0===o&&(o={});var u=e(t),c=e(o);r(function(){if("production"!==process.env.NODE_ENV){var e=d(u.current,t),r=d(c.current,o);Object.keys(v({},e,r)).length&&console.log(n+" updated:","props",e,"state",r),u.current=t,c.current=o}})}function p(n,t,o,u){var c=e();r(function(){c.current=t},[t]),r(function(){var t;if(!0!==u||"production"!==process.env.NODE_ENV){var e=null!=(t=null==o?void 0:o.current)?t:window;return e.addEventListener(n,r),function(){e.removeEventListener(n,r)}}function r(n){var t=c.current;null!=t&&t(n)}},[n,o])}var g={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function m(n){var t=n.querySelector("link[rel*='icon']");return null!==t?{type:t.getAttribute("type"),href:t.getAttribute("href")}:null}function y(n,t){if(null===t||null===t.href||null===t.type){var e;null==(e=n.querySelector("link[rel*='icon']"))||e.remove()}else{var r,o=null!=(r=n.querySelector("link[rel*='icon']"))?r:n.createElement("link");o.type=t.type,o.href=t.href,o.rel="shortcut icon",n.getElementsByTagName("head")[0].appendChild(o)}}function h(n,t){void 0===t&&(t={});var r=e(m(document)),u=t.retain,c=void 0!==u&&u;o(function(){return r.current=m(document),c?void 0:function(){y(document,r.current)}},[c]),o(function(){var t,e=n.toLowerCase().split(".").pop();void 0!==(t=e)&&Object.keys(g).includes(t)?y(document,{type:g[e],href:n}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+n)},[n])}function S(n){var e=t(!1),r=e[0],o=e[1];return p("mouseover",function(){return o(!0)},n),p("mouseout",function(){return o(!1)},n),[r]}function k(n,t){var o=e();r(function(){o.current=n},[n]),r(function(){if(null!==t){var n=setInterval(function(){var n=o.current;null!=n&&n()},t);return function(){return clearInterval(n)}}},[t])}var w=["Alt","Control","Meta","OS","Shift"],E={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},O={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function C(n,t){return""===n?function(){return!0}:function(e){if(t.ignoreRepeat&&e.repeat)return!1;var r=n.split("+").filter(function(n){return n.length>0});return r.length===function(n){var t=0;return w.forEach(function(e){n.getModifierState(e)&&t++}),w.includes(n.key)||t++,t}(e)&&r.every(function(n){var r,o=null!=(r=E[n.toLowerCase()])?r:n;return!!e.getModifierState(o)||e.key===n||e.key===O[n.toLowerCase()]||e.key.length>1&&e.key.toLowerCase()===n.toLowerCase()||e.code===n||!t.ignoreKey&&e.code==="Key"+n.toUpperCase()})}}function A(n,t,o){void 0===o&&(o={});var i=e();r(function(){i.current=t},[t]);var a=o.element,l=o.event,f=void 0===l?"keydown":l,v=o.development,d=o.ignoreKey,s=void 0!==d&&d,g=o.ignoreRepeat,m=void 0!==g&&g,y=u(function(){var t={ignoreKey:s,ignoreRepeat:m};return"function"==typeof n?n:Array.isArray(n)?function(e){return n.map(function(n){return C(n,t)}).some(function(n){return n(e)})}:C(n,t)},[n,s,m]);p(f,c(function(n){null!=i.current&&y(n)&&i.current(n)},[y]),a,v)}function N(t,e,r){var o=void 0===r?{serialize:JSON.stringify,deserialize:JSON.parse}:r,u=o.serialize,c=o.deserialize,i=n.useState(function(){var n=window.localStorage.getItem(t);if(null!=n)try{return c(n)}catch(n){window.localStorage.removeItem(t)}return function(n){return"function"==typeof n}(e)?e():e}),a=i[0],l=i[1],f=n.useRef(t);n.useEffect(function(){var n=f.current;n!==t&&window.localStorage.removeItem(n),f.current=t,null==a?window.localStorage.removeItem(t):window.localStorage.setItem(t,u(a))},[t,a,u]);var v=n.useCallback(function(){window.localStorage.removeItem(t)},[t]);return[a,l,v]}function j(n){void 0===n&&(n=!1);var t=i(n),e=t[1];return[t[0],e.setTrue,e.setFalse]}function T(n,t){var o=e();r(function(){o.current=n},[n]),r(function(){var n=null;function e(){null!==t&&(n=setTimeout(r,t))}function r(){var n=function(){var n=o.current,t=void 0;return null!=n&&(t=n()),t}();n instanceof Promise?n.then(e):e()}return r(),function(){n&&clearTimeout(n),n=null}},[t])}function b(n,t){var o=e();r(function(){o.current=n},[n]),r(function(){if(null!==t){var n=setTimeout(function(){var n=o.current;null!=n&&n()},t);return function(){return clearTimeout(n)}}},[t])}function I(n,t){void 0===t&&(t={});var r=t.append,u=void 0!==r&&r,c=t.retain,i=void 0!==c&&c,a=t.separator,l=void 0===a?"":a,f=e(document.title);o(function(){return f.current=document.title,i?void 0:function(){document.title=f.current}},[i]),o(function(){document.title=u?f.current+l+n:n},[n,l,u])}function L(n){return"function"==typeof n}function R(n){var e,r=t({current:(e=n,"function"==typeof e?n():n),undoStack:[],redoStack:[]}),o=r[0],u=r[1],i=c(function(){u(function(n){if(0===n.undoStack.length)return n;var t=n.current,e=n.undoStack,r=n.redoStack;return{current:e[e.length-1],undoStack:e.slice(0,e.length-1),redoStack:[].concat(r,[t])}})},[]),a=c(function(){u(function(n){if(0===n.redoStack.length)return n;var t=n.redoStack;return{current:t[t.length-1],undoStack:[].concat(n.undoStack,[n.current]),redoStack:t.slice(0,t.length-1)}})},[]),l=c(function(n){u(function(t){var e=t.current,r=t.undoStack;return{current:L(n)?n(e):n,undoStack:[].concat(r,[e]),redoStack:[]}})},[]);return[o.current,l,{undo:i,redo:a,canUndo:o.undoStack.length>0,canRedo:o.redoStack.length>0}]}export{w as KEYBOARD_MODIFIERS,i as useBoolean,l as useControllableState,f as useDebounce,s as useDebug,p as useEventListener,h as useFavicon,S as useHover,k as useInterval,A as useKeyboard,N as useLocalState,j as useModal,T as usePoll,b as useTimeout,I as useTitle,R as useTrackedState}; | ||
import n,{useState as e,useRef as t,useEffect as r,useLayoutEffect as o,useMemo as u,useCallback as i}from"react";function c(t){void 0===t&&(t=!1);var r=e(t),o=r[1];return[r[0],n.useMemo(function(){return{toggle:function(){return o(function(n){return!n})},setTrue:function(){return o(!0)},setFalse:function(){return o(!1)}}},[o])]}function a(n){void 0===n&&(n=2e3);var t=e(),r=t[0],o=t[1],u=e(!1),i=u[0],c=u[1],a=e(),l=a[0],f=a[1];return{copy:function(e){try{return"clipboard"in navigator?Promise.resolve(navigator.clipboard.writeText(e).then(function(){return function(e){l&&clearTimeout(l);var t=setTimeout(function(){return c(!1)},n);f(t),c(!0)}()}).catch(function(n){return o(n)})):(o(new Error("useClipboard: clipboard is not supported")),Promise.resolve())}catch(n){return Promise.reject(n)}},reset:function(){c(!1),o(void 0),l&&clearTimeout(l)},error:r,copied:i}}function l(){}function f(n,o,u){var i=t(void 0!==n).current,c=void 0!==n,a=e(function(){if(void 0===n&&void 0!==u)return"function"!=typeof u?u:u()}),f=a[0],v=a[1],d=l;return"production"!==process.env.NODE_ENV&&(d=function(){i!==c&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),r(d,[d,c]),[i?n:f,i?o:v]}function v(n,t){var o=e(n),u=o[0],i=o[1];return r(function(){if(null!==t){var e=setTimeout(function(){i(n)},t);return function(){clearTimeout(e)}}i(n)},[n,t]),[u,function(){return i(n)}]}function d(){return d=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},d.apply(this,arguments)}function s(n,e){var t=Object.keys(d({},n,e)),r={};return t.forEach(function(t){n[""+t]!==e[""+t]&&(r[""+t]={from:n[""+t],to:e[""+t]})}),r}function p(n,e,o){void 0===e&&(e={}),void 0===o&&(o={});var u=t(e),i=t(o);r(function(){if("production"!==process.env.NODE_ENV){var t=s(u.current,e),r=s(i.current,o);Object.keys(d({},t,r)).length&&console.log(n+" updated:","props",t,"state",r),u.current=e,i.current=o}})}function g(n,e,o,u){var i=t();r(function(){i.current=e},[e]),r(function(){var e;if(!0!==u||"production"!==process.env.NODE_ENV){var t=null!=(e=null==o?void 0:o.current)?e:window;return t.addEventListener(n,r),function(){t.removeEventListener(n,r)}}function r(n){var e=i.current;null!=e&&e(n)}},[n,o])}var m={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function h(n){var e=n.querySelector("link[rel*='icon']");return null!==e?{type:e.getAttribute("type"),href:e.getAttribute("href")}:null}function y(n,e){if(null===e||null===e.href||null===e.type){var t;null==(t=n.querySelector("link[rel*='icon']"))||t.remove()}else{var r,o=null!=(r=n.querySelector("link[rel*='icon']"))?r:n.createElement("link");o.type=e.type,o.href=e.href,o.rel="shortcut icon",n.getElementsByTagName("head")[0].appendChild(o)}}function S(n,e){void 0===e&&(e={});var r=t(h(document)),u=e.retain,i=void 0!==u&&u;o(function(){return r.current=h(document),i?void 0:function(){y(document,r.current)}},[i]),o(function(){var e,t=n.toLowerCase().split(".").pop();void 0!==(e=t)&&Object.keys(m).includes(e)?y(document,{type:m[t],href:n}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+n)},[n])}function w(n){var t=e(!1),r=t[0],o=t[1];return g("mouseover",function(){return o(!0)},n),g("mouseout",function(){return o(!1)},n),[r]}function k(n,e){var o=t();r(function(){o.current=n},[n]),r(function(){if(null!==e){var n=setInterval(function(){var n=o.current;null!=n&&n()},e);return function(){return clearInterval(n)}}},[e])}var E=["Alt","Control","Meta","OS","Shift"],C={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},O={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function T(n,e){return""===n?function(){return!0}:function(t){if(e.ignoreRepeat&&t.repeat)return!1;var r=n.split("+").filter(function(n){return n.length>0});return r.length===function(n){var e=0;return E.forEach(function(t){n.getModifierState(t)&&e++}),E.includes(n.key)||e++,e}(t)&&r.every(function(n){var r,o=null!=(r=C[n.toLowerCase()])?r:n;return!!t.getModifierState(o)||t.key===n||t.key===O[n.toLowerCase()]||t.key.length>1&&t.key.toLowerCase()===n.toLowerCase()||t.code===n||!e.ignoreKey&&t.code==="Key"+n.toUpperCase()})}}function b(n,e,o){void 0===o&&(o={});var c=t();r(function(){c.current=e},[e]);var a=o.element,l=o.event,f=void 0===l?"keydown":l,v=o.development,d=o.ignoreKey,s=void 0!==d&&d,p=o.ignoreRepeat,m=void 0!==p&&p,h=u(function(){var e={ignoreKey:s,ignoreRepeat:m};return"function"==typeof n?n:Array.isArray(n)?function(t){return n.map(function(n){return T(n,e)}).some(function(n){return n(t)})}:T(n,e)},[n,s,m]);g(f,i(function(n){null!=c.current&&h(n)&&c.current(n)},[h]),a,v)}function A(e,t,r){var o=void 0===r?{serialize:JSON.stringify,deserialize:JSON.parse}:r,u=o.serialize,i=o.deserialize,c=n.useState(function(){var n=window.localStorage.getItem(e);if(null!=n)try{return i(n)}catch(n){window.localStorage.removeItem(e)}return function(n){return"function"==typeof n}(t)?t():t}),a=c[0],l=c[1],f=n.useRef(e);n.useEffect(function(){var n=f.current;n!==e&&window.localStorage.removeItem(n),f.current=e,null==a?window.localStorage.removeItem(e):window.localStorage.setItem(e,u(a))},[e,a,u]);var v=n.useCallback(function(){window.localStorage.removeItem(e)},[e]);return[a,l,v]}function N(n){void 0===n&&(n=!1);var e=c(n),t=e[1];return[e[0],t.setTrue,t.setFalse]}function j(n,e){var o=t();r(function(){o.current=n},[n]),r(function(){var n=null;function t(){null!==e&&(n=setTimeout(r,e))}function r(){var n=function(){var n=o.current,e=void 0;return null!=n&&(e=n()),e}();n instanceof Promise?n.then(t):t()}return r(),function(){n&&clearTimeout(n),n=null}},[e])}function I(n,e){var o=t();r(function(){o.current=n},[n]),r(function(){if(null!==e){var n=setTimeout(function(){var n=o.current;null!=n&&n()},e);return function(){return clearTimeout(n)}}},[e])}function L(n,e){void 0===e&&(e={});var r=e.append,u=void 0!==r&&r,i=e.retain,c=void 0!==i&&i,a=e.separator,l=void 0===a?"":a,f=t(document.title);o(function(){return f.current=document.title,c?void 0:function(){document.title=f.current}},[c]),o(function(){document.title=u?f.current+l+n:n},[n,l,u])}function R(n){return"function"==typeof n}function D(n){var t,r=e({current:(t=n,"function"==typeof t?n():n),undoStack:[],redoStack:[]}),o=r[0],u=r[1],c=i(function(){u(function(n){if(0===n.undoStack.length)return n;var e=n.current,t=n.undoStack,r=n.redoStack;return{current:t[t.length-1],undoStack:t.slice(0,t.length-1),redoStack:[].concat(r,[e])}})},[]),a=i(function(){u(function(n){if(0===n.redoStack.length)return n;var e=n.redoStack;return{current:e[e.length-1],undoStack:[].concat(n.undoStack,[n.current]),redoStack:e.slice(0,e.length-1)}})},[]),l=i(function(n){u(function(e){var t=e.current,r=e.undoStack;return{current:R(n)?n(t):n,undoStack:[].concat(r,[t]),redoStack:[]}})},[]);return[o.current,l,{undo:c,redo:a,canUndo:o.undoStack.length>0,canRedo:o.redoStack.length>0}]}export{E as KEYBOARD_MODIFIERS,c as useBoolean,a as useClipboard,f as useControllableState,v as useDebounce,p as useDebug,g as useEventListener,S as useFavicon,w as useHover,k as useInterval,b as useKeyboard,A as useLocalState,N as useModal,j as usePoll,I as useTimeout,L as useTitle,D as useTrackedState}; | ||
//# sourceMappingURL=hooks.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/t(e);function r(t){void 0===t&&(t=!1);var r=e.useState(t),o=r[1];return[r[0],n.default.useMemo(function(){return{toggle:function(){return o(function(e){return!e})},setTrue:function(){return o(!0)},setFalse:function(){return o(!1)}}},[o])]}function o(){}function u(){return u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function c(e,t){var n=Object.keys(u({},e,t)),r={};return n.forEach(function(n){e[""+n]!==t[""+n]&&(r[""+n]={from:e[""+n],to:t[""+n]})}),r}function i(t,n,r,o){var u=e.useRef();e.useEffect(function(){u.current=n},[n]),e.useEffect(function(){var e;if(!0!==o||"production"!==process.env.NODE_ENV){var n=null!=(e=null==r?void 0:r.current)?e:window;return n.addEventListener(t,c),function(){n.removeEventListener(t,c)}}function c(e){var t=u.current;null!=t&&t(e)}},[t,r])}var a={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function f(e){var t=e.querySelector("link[rel*='icon']");return null!==t?{type:t.getAttribute("type"),href:t.getAttribute("href")}:null}function l(e,t){if(null===t||null===t.href||null===t.type){var n;null==(n=e.querySelector("link[rel*='icon']"))||n.remove()}else{var r,o=null!=(r=e.querySelector("link[rel*='icon']"))?r:e.createElement("link");o.type=t.type,o.href=t.href,o.rel="shortcut icon",e.getElementsByTagName("head")[0].appendChild(o)}}var s=["Alt","Control","Meta","OS","Shift"],v={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},d={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function p(e,t){return""===e?function(){return!0}:function(n){if(t.ignoreRepeat&&n.repeat)return!1;var r=e.split("+").filter(function(e){return e.length>0});return r.length===function(e){var t=0;return s.forEach(function(n){e.getModifierState(n)&&t++}),s.includes(e.key)||t++,t}(n)&&r.every(function(e){var r,o=null!=(r=v[e.toLowerCase()])?r:e;return!!n.getModifierState(o)||n.key===e||n.key===d[e.toLowerCase()]||n.key.length>1&&n.key.toLowerCase()===e.toLowerCase()||n.code===e||!t.ignoreKey&&n.code==="Key"+e.toUpperCase()})}}function g(e){return"function"==typeof e}exports.KEYBOARD_MODIFIERS=s,exports.useBoolean=r,exports.useControllableState=function(t,n,r){var u=e.useRef(void 0!==t).current,c=void 0!==t,i=e.useState(function(){if(void 0===t&&void 0!==r)return"function"!=typeof r?r:r()}),a=i[0],f=i[1],l=o;return"production"!==process.env.NODE_ENV&&(l=function(){u!==c&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),e.useEffect(l,[l,c]),[u?t:a,u?n:f]},exports.useDebounce=function(t,n){var r=e.useState(t),o=r[0],u=r[1];return e.useEffect(function(){if(null!==n){var e=setTimeout(function(){u(t)},n);return function(){clearTimeout(e)}}u(t)},[t,n]),[o,function(){return u(t)}]},exports.useDebug=function(t,n,r){void 0===n&&(n={}),void 0===r&&(r={});var o=e.useRef(n),i=e.useRef(r);e.useEffect(function(){if("production"!==process.env.NODE_ENV){var e=c(o.current,n),a=c(i.current,r);Object.keys(u({},e,a)).length&&console.log(t+" updated:","props",e,"state",a),o.current=n,i.current=r}})},exports.useEventListener=i,exports.useFavicon=function(t,n){void 0===n&&(n={});var r=e.useRef(f(document)),o=n.retain,u=void 0!==o&&o;e.useLayoutEffect(function(){return r.current=f(document),u?void 0:function(){l(document,r.current)}},[u]),e.useLayoutEffect(function(){var e,n=t.toLowerCase().split(".").pop();void 0!==(e=n)&&Object.keys(a).includes(e)?l(document,{type:a[n],href:t}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+t)},[t])},exports.useHover=function(t){var n=e.useState(!1),r=n[0],o=n[1];return i("mouseover",function(){return o(!0)},t),i("mouseout",function(){return o(!1)},t),[r]},exports.useInterval=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){if(null!==n){var e=setInterval(function(){var e=r.current;null!=e&&e()},n);return function(){return clearInterval(e)}}},[n])},exports.useKeyboard=function(t,n,r){void 0===r&&(r={});var o=e.useRef();e.useEffect(function(){o.current=n},[n]);var u=r.element,c=r.event,a=void 0===c?"keydown":c,f=r.development,l=r.ignoreKey,s=void 0!==l&&l,v=r.ignoreRepeat,d=void 0!==v&&v,g=e.useMemo(function(){var e={ignoreKey:s,ignoreRepeat:d};return"function"==typeof t?t:Array.isArray(t)?function(n){return t.map(function(t){return p(t,e)}).some(function(e){return e(n)})}:p(t,e)},[t,s,d]);i(a,e.useCallback(function(e){null!=o.current&&g(e)&&o.current(e)},[g]),u,f)},exports.useLocalState=function(e,t,r){var o=void 0===r?{serialize:JSON.stringify,deserialize:JSON.parse}:r,u=o.serialize,c=o.deserialize,i=n.default.useState(function(){var n=window.localStorage.getItem(e);if(null!=n)try{return c(n)}catch(t){window.localStorage.removeItem(e)}return function(e){return"function"==typeof e}(t)?t():t}),a=i[0],f=i[1],l=n.default.useRef(e);n.default.useEffect(function(){var t=l.current;t!==e&&window.localStorage.removeItem(t),l.current=e,null==a?window.localStorage.removeItem(e):window.localStorage.setItem(e,u(a))},[e,a,u]);var s=n.default.useCallback(function(){window.localStorage.removeItem(e)},[e]);return[a,f,s]},exports.useModal=function(e){void 0===e&&(e=!1);var t=r(e),n=t[1];return[t[0],n.setTrue,n.setFalse]},exports.usePoll=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){var e=null;function t(){null!==n&&(e=setTimeout(o,n))}function o(){var e=function(){var e=r.current,t=void 0;return null!=e&&(t=e()),t}();e instanceof Promise?e.then(t):t()}return o(),function(){e&&clearTimeout(e),e=null}},[n])},exports.useTimeout=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){if(null!==n){var e=setTimeout(function(){var e=r.current;null!=e&&e()},n);return function(){return clearTimeout(e)}}},[n])},exports.useTitle=function(t,n){void 0===n&&(n={});var r=n.append,o=void 0!==r&&r,u=n.retain,c=void 0!==u&&u,i=n.separator,a=void 0===i?"":i,f=e.useRef(document.title);e.useLayoutEffect(function(){return f.current=document.title,c?void 0:function(){document.title=f.current}},[c]),e.useLayoutEffect(function(){document.title=o?f.current+a+t:t},[t,a,o])},exports.useTrackedState=function(t){var n,r=e.useState({current:(n=t,"function"==typeof n?t():t),undoStack:[],redoStack:[]}),o=r[0],u=r[1],c=e.useCallback(function(){u(function(e){if(0===e.undoStack.length)return e;var t=e.current,n=e.undoStack,r=e.redoStack;return{current:n[n.length-1],undoStack:n.slice(0,n.length-1),redoStack:[].concat(r,[t])}})},[]),i=e.useCallback(function(){u(function(e){if(0===e.redoStack.length)return e;var t=e.redoStack;return{current:t[t.length-1],undoStack:[].concat(e.undoStack,[e.current]),redoStack:t.slice(0,t.length-1)}})},[]),a=e.useCallback(function(e){u(function(t){var n=t.current,r=t.undoStack;return{current:g(e)?e(n):e,undoStack:[].concat(r,[n]),redoStack:[]}})},[]);return[o.current,a,{undo:c,redo:i,canUndo:o.undoStack.length>0,canRedo:o.redoStack.length>0}]}; | ||
var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/t(e);function r(t){void 0===t&&(t=!1);var r=e.useState(t),o=r[1];return[r[0],n.default.useMemo(function(){return{toggle:function(){return o(function(e){return!e})},setTrue:function(){return o(!0)},setFalse:function(){return o(!1)}}},[o])]}function o(){}function u(){return u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function c(e,t){var n=Object.keys(u({},e,t)),r={};return n.forEach(function(n){e[""+n]!==t[""+n]&&(r[""+n]={from:e[""+n],to:t[""+n]})}),r}function i(t,n,r,o){var u=e.useRef();e.useEffect(function(){u.current=n},[n]),e.useEffect(function(){var e;if(!0!==o||"production"!==process.env.NODE_ENV){var n=null!=(e=null==r?void 0:r.current)?e:window;return n.addEventListener(t,c),function(){n.removeEventListener(t,c)}}function c(e){var t=u.current;null!=t&&t(e)}},[t,r])}var a={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function f(e){var t=e.querySelector("link[rel*='icon']");return null!==t?{type:t.getAttribute("type"),href:t.getAttribute("href")}:null}function l(e,t){if(null===t||null===t.href||null===t.type){var n;null==(n=e.querySelector("link[rel*='icon']"))||n.remove()}else{var r,o=null!=(r=e.querySelector("link[rel*='icon']"))?r:e.createElement("link");o.type=t.type,o.href=t.href,o.rel="shortcut icon",e.getElementsByTagName("head")[0].appendChild(o)}}var s=["Alt","Control","Meta","OS","Shift"],v={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},d={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function p(e,t){return""===e?function(){return!0}:function(n){if(t.ignoreRepeat&&n.repeat)return!1;var r=e.split("+").filter(function(e){return e.length>0});return r.length===function(e){var t=0;return s.forEach(function(n){e.getModifierState(n)&&t++}),s.includes(e.key)||t++,t}(n)&&r.every(function(e){var r,o=null!=(r=v[e.toLowerCase()])?r:e;return!!n.getModifierState(o)||n.key===e||n.key===d[e.toLowerCase()]||n.key.length>1&&n.key.toLowerCase()===e.toLowerCase()||n.code===e||!t.ignoreKey&&n.code==="Key"+e.toUpperCase()})}}function g(e){return"function"==typeof e}exports.KEYBOARD_MODIFIERS=s,exports.useBoolean=r,exports.useClipboard=function(t){void 0===t&&(t=2e3);var n=e.useState(),r=n[0],o=n[1],u=e.useState(!1),c=u[0],i=u[1],a=e.useState(),f=a[0],l=a[1];return{copy:function(e){try{return"clipboard"in navigator?Promise.resolve(navigator.clipboard.writeText(e).then(function(){return function(e){f&&clearTimeout(f);var n=setTimeout(function(){return i(!1)},t);l(n),i(!0)}()}).catch(function(e){return o(e)})):(o(new Error("useClipboard: clipboard is not supported")),Promise.resolve())}catch(e){return Promise.reject(e)}},reset:function(){i(!1),o(void 0),f&&clearTimeout(f)},error:r,copied:c}},exports.useControllableState=function(t,n,r){var u=e.useRef(void 0!==t).current,c=void 0!==t,i=e.useState(function(){if(void 0===t&&void 0!==r)return"function"!=typeof r?r:r()}),a=i[0],f=i[1],l=o;return"production"!==process.env.NODE_ENV&&(l=function(){u!==c&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),e.useEffect(l,[l,c]),[u?t:a,u?n:f]},exports.useDebounce=function(t,n){var r=e.useState(t),o=r[0],u=r[1];return e.useEffect(function(){if(null!==n){var e=setTimeout(function(){u(t)},n);return function(){clearTimeout(e)}}u(t)},[t,n]),[o,function(){return u(t)}]},exports.useDebug=function(t,n,r){void 0===n&&(n={}),void 0===r&&(r={});var o=e.useRef(n),i=e.useRef(r);e.useEffect(function(){if("production"!==process.env.NODE_ENV){var e=c(o.current,n),a=c(i.current,r);Object.keys(u({},e,a)).length&&console.log(t+" updated:","props",e,"state",a),o.current=n,i.current=r}})},exports.useEventListener=i,exports.useFavicon=function(t,n){void 0===n&&(n={});var r=e.useRef(f(document)),o=n.retain,u=void 0!==o&&o;e.useLayoutEffect(function(){return r.current=f(document),u?void 0:function(){l(document,r.current)}},[u]),e.useLayoutEffect(function(){var e,n=t.toLowerCase().split(".").pop();void 0!==(e=n)&&Object.keys(a).includes(e)?l(document,{type:a[n],href:t}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+t)},[t])},exports.useHover=function(t){var n=e.useState(!1),r=n[0],o=n[1];return i("mouseover",function(){return o(!0)},t),i("mouseout",function(){return o(!1)},t),[r]},exports.useInterval=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){if(null!==n){var e=setInterval(function(){var e=r.current;null!=e&&e()},n);return function(){return clearInterval(e)}}},[n])},exports.useKeyboard=function(t,n,r){void 0===r&&(r={});var o=e.useRef();e.useEffect(function(){o.current=n},[n]);var u=r.element,c=r.event,a=void 0===c?"keydown":c,f=r.development,l=r.ignoreKey,s=void 0!==l&&l,v=r.ignoreRepeat,d=void 0!==v&&v,g=e.useMemo(function(){var e={ignoreKey:s,ignoreRepeat:d};return"function"==typeof t?t:Array.isArray(t)?function(n){return t.map(function(t){return p(t,e)}).some(function(e){return e(n)})}:p(t,e)},[t,s,d]);i(a,e.useCallback(function(e){null!=o.current&&g(e)&&o.current(e)},[g]),u,f)},exports.useLocalState=function(e,t,r){var o=void 0===r?{serialize:JSON.stringify,deserialize:JSON.parse}:r,u=o.serialize,c=o.deserialize,i=n.default.useState(function(){var n=window.localStorage.getItem(e);if(null!=n)try{return c(n)}catch(t){window.localStorage.removeItem(e)}return function(e){return"function"==typeof e}(t)?t():t}),a=i[0],f=i[1],l=n.default.useRef(e);n.default.useEffect(function(){var t=l.current;t!==e&&window.localStorage.removeItem(t),l.current=e,null==a?window.localStorage.removeItem(e):window.localStorage.setItem(e,u(a))},[e,a,u]);var s=n.default.useCallback(function(){window.localStorage.removeItem(e)},[e]);return[a,f,s]},exports.useModal=function(e){void 0===e&&(e=!1);var t=r(e),n=t[1];return[t[0],n.setTrue,n.setFalse]},exports.usePoll=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){var e=null;function t(){null!==n&&(e=setTimeout(o,n))}function o(){var e=function(){var e=r.current,t=void 0;return null!=e&&(t=e()),t}();e instanceof Promise?e.then(t):t()}return o(),function(){e&&clearTimeout(e),e=null}},[n])},exports.useTimeout=function(t,n){var r=e.useRef();e.useEffect(function(){r.current=t},[t]),e.useEffect(function(){if(null!==n){var e=setTimeout(function(){var e=r.current;null!=e&&e()},n);return function(){return clearTimeout(e)}}},[n])},exports.useTitle=function(t,n){void 0===n&&(n={});var r=n.append,o=void 0!==r&&r,u=n.retain,c=void 0!==u&&u,i=n.separator,a=void 0===i?"":i,f=e.useRef(document.title);e.useLayoutEffect(function(){return f.current=document.title,c?void 0:function(){document.title=f.current}},[c]),e.useLayoutEffect(function(){document.title=o?f.current+a+t:t},[t,a,o])},exports.useTrackedState=function(t){var n,r=e.useState({current:(n=t,"function"==typeof n?t():t),undoStack:[],redoStack:[]}),o=r[0],u=r[1],c=e.useCallback(function(){u(function(e){if(0===e.undoStack.length)return e;var t=e.current,n=e.undoStack,r=e.redoStack;return{current:n[n.length-1],undoStack:n.slice(0,n.length-1),redoStack:[].concat(r,[t])}})},[]),i=e.useCallback(function(){u(function(e){if(0===e.redoStack.length)return e;var t=e.redoStack;return{current:t[t.length-1],undoStack:[].concat(e.undoStack,[e.current]),redoStack:t.slice(0,t.length-1)}})},[]),a=e.useCallback(function(e){u(function(t){var n=t.current,r=t.undoStack;return{current:g(e)?e(n):e,undoStack:[].concat(r,[n]),redoStack:[]}})},[]);return[o.current,a,{undo:c,redo:i,canUndo:o.undoStack.length>0,canRedo:o.redoStack.length>0}]}; | ||
//# sourceMappingURL=hooks.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e||self).hooks={},e.react)}(this,function(e,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(t);function u(e){void 0===e&&(e=!1);var n=t.useState(e),u=n[1];return[n[0],r.default.useMemo(function(){return{toggle:function(){return u(function(e){return!e})},setTrue:function(){return u(!0)},setFalse:function(){return u(!1)}}},[u])]}function o(){}function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(this,arguments)}function i(e,t){var n=Object.keys(c({},e,t)),r={};return n.forEach(function(n){e[""+n]!==t[""+n]&&(r[""+n]={from:e[""+n],to:t[""+n]})}),r}function f(e,n,r,u){var o=t.useRef();t.useEffect(function(){o.current=n},[n]),t.useEffect(function(){var t;if(!0!==u||"production"!==process.env.NODE_ENV){var n=null!=(t=null==r?void 0:r.current)?t:window;return n.addEventListener(e,c),function(){n.removeEventListener(e,c)}}function c(e){var t=o.current;null!=t&&t(e)}},[e,r])}var a={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function l(e){var t=e.querySelector("link[rel*='icon']");return null!==t?{type:t.getAttribute("type"),href:t.getAttribute("href")}:null}function s(e,t){if(null===t||null===t.href||null===t.type){var n;null==(n=e.querySelector("link[rel*='icon']"))||n.remove()}else{var r,u=null!=(r=e.querySelector("link[rel*='icon']"))?r:e.createElement("link");u.type=t.type,u.href=t.href,u.rel="shortcut icon",e.getElementsByTagName("head")[0].appendChild(u)}}var d=["Alt","Control","Meta","OS","Shift"],v={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},p={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function g(e,t){return""===e?function(){return!0}:function(n){if(t.ignoreRepeat&&n.repeat)return!1;var r=e.split("+").filter(function(e){return e.length>0});return r.length===function(e){var t=0;return d.forEach(function(n){e.getModifierState(n)&&t++}),d.includes(e.key)||t++,t}(n)&&r.every(function(e){var r,u=null!=(r=v[e.toLowerCase()])?r:e;return!!n.getModifierState(u)||n.key===e||n.key===p[e.toLowerCase()]||n.key.length>1&&n.key.toLowerCase()===e.toLowerCase()||n.code===e||!t.ignoreKey&&n.code==="Key"+e.toUpperCase()})}}function m(e){return"function"==typeof e}e.KEYBOARD_MODIFIERS=d,e.useBoolean=u,e.useControllableState=function(e,n,r){var u=t.useRef(void 0!==e).current,c=void 0!==e,i=t.useState(function(){if(void 0===e&&void 0!==r)return"function"!=typeof r?r:r()}),f=i[0],a=i[1],l=o;return"production"!==process.env.NODE_ENV&&(l=function(){u!==c&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),t.useEffect(l,[l,c]),[u?e:f,u?n:a]},e.useDebounce=function(e,n){var r=t.useState(e),u=r[0],o=r[1];return t.useEffect(function(){if(null!==n){var t=setTimeout(function(){o(e)},n);return function(){clearTimeout(t)}}o(e)},[e,n]),[u,function(){return o(e)}]},e.useDebug=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});var u=t.useRef(n),o=t.useRef(r);t.useEffect(function(){if("production"!==process.env.NODE_ENV){var t=i(u.current,n),f=i(o.current,r);Object.keys(c({},t,f)).length&&console.log(e+" updated:","props",t,"state",f),u.current=n,o.current=r}})},e.useEventListener=f,e.useFavicon=function(e,n){void 0===n&&(n={});var r=t.useRef(l(document)),u=n.retain,o=void 0!==u&&u;t.useLayoutEffect(function(){return r.current=l(document),o?void 0:function(){s(document,r.current)}},[o]),t.useLayoutEffect(function(){var t,n=e.toLowerCase().split(".").pop();void 0!==(t=n)&&Object.keys(a).includes(t)?s(document,{type:a[n],href:e}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+e)},[e])},e.useHover=function(e){var n=t.useState(!1),r=n[0],u=n[1];return f("mouseover",function(){return u(!0)},e),f("mouseout",function(){return u(!1)},e),[r]},e.useInterval=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){if(null!==n){var e=setInterval(function(){var e=r.current;null!=e&&e()},n);return function(){return clearInterval(e)}}},[n])},e.useKeyboard=function(e,n,r){void 0===r&&(r={});var u=t.useRef();t.useEffect(function(){u.current=n},[n]);var o=r.element,c=r.event,i=void 0===c?"keydown":c,a=r.development,l=r.ignoreKey,s=void 0!==l&&l,d=r.ignoreRepeat,v=void 0!==d&&d,p=t.useMemo(function(){var t={ignoreKey:s,ignoreRepeat:v};return"function"==typeof e?e:Array.isArray(e)?function(n){return e.map(function(e){return g(e,t)}).some(function(e){return e(n)})}:g(e,t)},[e,s,v]);f(i,t.useCallback(function(e){null!=u.current&&p(e)&&u.current(e)},[p]),o,a)},e.useLocalState=function(e,t,n){var u=void 0===n?{serialize:JSON.stringify,deserialize:JSON.parse}:n,o=u.serialize,c=u.deserialize,i=r.default.useState(function(){var n=window.localStorage.getItem(e);if(null!=n)try{return c(n)}catch(t){window.localStorage.removeItem(e)}return function(e){return"function"==typeof e}(t)?t():t}),f=i[0],a=i[1],l=r.default.useRef(e);r.default.useEffect(function(){var t=l.current;t!==e&&window.localStorage.removeItem(t),l.current=e,null==f?window.localStorage.removeItem(e):window.localStorage.setItem(e,o(f))},[e,f,o]);var s=r.default.useCallback(function(){window.localStorage.removeItem(e)},[e]);return[f,a,s]},e.useModal=function(e){void 0===e&&(e=!1);var t=u(e),n=t[1];return[t[0],n.setTrue,n.setFalse]},e.usePoll=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){var e=null;function t(){null!==n&&(e=setTimeout(u,n))}function u(){var e=function(){var e=r.current,t=void 0;return null!=e&&(t=e()),t}();e instanceof Promise?e.then(t):t()}return u(),function(){e&&clearTimeout(e),e=null}},[n])},e.useTimeout=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){if(null!==n){var e=setTimeout(function(){var e=r.current;null!=e&&e()},n);return function(){return clearTimeout(e)}}},[n])},e.useTitle=function(e,n){void 0===n&&(n={});var r=n.append,u=void 0!==r&&r,o=n.retain,c=void 0!==o&&o,i=n.separator,f=void 0===i?"":i,a=t.useRef(document.title);t.useLayoutEffect(function(){return a.current=document.title,c?void 0:function(){document.title=a.current}},[c]),t.useLayoutEffect(function(){document.title=u?a.current+f+e:e},[e,f,u])},e.useTrackedState=function(e){var n,r=t.useState({current:(n=e,"function"==typeof n?e():e),undoStack:[],redoStack:[]}),u=r[0],o=r[1],c=t.useCallback(function(){o(function(e){if(0===e.undoStack.length)return e;var t=e.current,n=e.undoStack,r=e.redoStack;return{current:n[n.length-1],undoStack:n.slice(0,n.length-1),redoStack:[].concat(r,[t])}})},[]),i=t.useCallback(function(){o(function(e){if(0===e.redoStack.length)return e;var t=e.redoStack;return{current:t[t.length-1],undoStack:[].concat(e.undoStack,[e.current]),redoStack:t.slice(0,t.length-1)}})},[]),f=t.useCallback(function(e){o(function(t){var n=t.current,r=t.undoStack;return{current:m(e)?e(n):e,undoStack:[].concat(r,[n]),redoStack:[]}})},[]);return[u.current,f,{undo:c,redo:i,canUndo:u.undoStack.length>0,canRedo:u.redoStack.length>0}]}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e||self).hooks={},e.react)}(this,function(e,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(t);function o(e){void 0===e&&(e=!1);var n=t.useState(e),o=n[1];return[n[0],r.default.useMemo(function(){return{toggle:function(){return o(function(e){return!e})},setTrue:function(){return o(!0)},setFalse:function(){return o(!1)}}},[o])]}function u(){}function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(this,arguments)}function i(e,t){var n=Object.keys(c({},e,t)),r={};return n.forEach(function(n){e[""+n]!==t[""+n]&&(r[""+n]={from:e[""+n],to:t[""+n]})}),r}function a(e,n,r,o){var u=t.useRef();t.useEffect(function(){u.current=n},[n]),t.useEffect(function(){var t;if(!0!==o||"production"!==process.env.NODE_ENV){var n=null!=(t=null==r?void 0:r.current)?t:window;return n.addEventListener(e,c),function(){n.removeEventListener(e,c)}}function c(e){var t=u.current;null!=t&&t(e)}},[e,r])}var f={gif:"image/gif",ico:"image/x-icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"};function l(e){var t=e.querySelector("link[rel*='icon']");return null!==t?{type:t.getAttribute("type"),href:t.getAttribute("href")}:null}function s(e,t){if(null===t||null===t.href||null===t.type){var n;null==(n=e.querySelector("link[rel*='icon']"))||n.remove()}else{var r,o=null!=(r=e.querySelector("link[rel*='icon']"))?r:e.createElement("link");o.type=t.type,o.href=t.href,o.rel="shortcut icon",e.getElementsByTagName("head")[0].appendChild(o)}}var d=["Alt","Control","Meta","OS","Shift"],v={alt:"Alt",ctrl:"Control",control:"Control",shift:"Shift",meta:"Meta",option:"Alt"},p={plus:"+",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",esc:"Escape"};function g(e,t){return""===e?function(){return!0}:function(n){if(t.ignoreRepeat&&n.repeat)return!1;var r=e.split("+").filter(function(e){return e.length>0});return r.length===function(e){var t=0;return d.forEach(function(n){e.getModifierState(n)&&t++}),d.includes(e.key)||t++,t}(n)&&r.every(function(e){var r,o=null!=(r=v[e.toLowerCase()])?r:e;return!!n.getModifierState(o)||n.key===e||n.key===p[e.toLowerCase()]||n.key.length>1&&n.key.toLowerCase()===e.toLowerCase()||n.code===e||!t.ignoreKey&&n.code==="Key"+e.toUpperCase()})}}function m(e){return"function"==typeof e}e.KEYBOARD_MODIFIERS=d,e.useBoolean=o,e.useClipboard=function(e){void 0===e&&(e=2e3);var n=t.useState(),r=n[0],o=n[1],u=t.useState(!1),c=u[0],i=u[1],a=t.useState(),f=a[0],l=a[1];return{copy:function(t){try{return"clipboard"in navigator?Promise.resolve(navigator.clipboard.writeText(t).then(function(){return function(t){f&&clearTimeout(f);var n=setTimeout(function(){return i(!1)},e);l(n),i(!0)}()}).catch(function(e){return o(e)})):(o(new Error("useClipboard: clipboard is not supported")),Promise.resolve())}catch(e){return Promise.reject(e)}},reset:function(){i(!1),o(void 0),f&&clearTimeout(f)},error:r,copied:c}},e.useControllableState=function(e,n,r){var o=t.useRef(void 0!==e).current,c=void 0!==e,i=t.useState(function(){if(void 0===e&&void 0!==r)return"function"!=typeof r?r:r()}),a=i[0],f=i[1],l=u;return"production"!==process.env.NODE_ENV&&(l=function(){o!==c&&console.warn("Components should not switch from uncontrolled to controlled (or vice versa)")}),t.useEffect(l,[l,c]),[o?e:a,o?n:f]},e.useDebounce=function(e,n){var r=t.useState(e),o=r[0],u=r[1];return t.useEffect(function(){if(null!==n){var t=setTimeout(function(){u(e)},n);return function(){clearTimeout(t)}}u(e)},[e,n]),[o,function(){return u(e)}]},e.useDebug=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});var o=t.useRef(n),u=t.useRef(r);t.useEffect(function(){if("production"!==process.env.NODE_ENV){var t=i(o.current,n),a=i(u.current,r);Object.keys(c({},t,a)).length&&console.log(e+" updated:","props",t,"state",a),o.current=n,u.current=r}})},e.useEventListener=a,e.useFavicon=function(e,n){void 0===n&&(n={});var r=t.useRef(l(document)),o=n.retain,u=void 0!==o&&o;t.useLayoutEffect(function(){return r.current=l(document),u?void 0:function(){s(document,r.current)}},[u]),t.useLayoutEffect(function(){var t,n=e.toLowerCase().split(".").pop();void 0!==(t=n)&&Object.keys(f).includes(t)?s(document,{type:f[n],href:e}):"production"!==process.env.NODE_ENV&&console.warn("Unrecognised image type href: "+e)},[e])},e.useHover=function(e){var n=t.useState(!1),r=n[0],o=n[1];return a("mouseover",function(){return o(!0)},e),a("mouseout",function(){return o(!1)},e),[r]},e.useInterval=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){if(null!==n){var e=setInterval(function(){var e=r.current;null!=e&&e()},n);return function(){return clearInterval(e)}}},[n])},e.useKeyboard=function(e,n,r){void 0===r&&(r={});var o=t.useRef();t.useEffect(function(){o.current=n},[n]);var u=r.element,c=r.event,i=void 0===c?"keydown":c,f=r.development,l=r.ignoreKey,s=void 0!==l&&l,d=r.ignoreRepeat,v=void 0!==d&&d,p=t.useMemo(function(){var t={ignoreKey:s,ignoreRepeat:v};return"function"==typeof e?e:Array.isArray(e)?function(n){return e.map(function(e){return g(e,t)}).some(function(e){return e(n)})}:g(e,t)},[e,s,v]);a(i,t.useCallback(function(e){null!=o.current&&p(e)&&o.current(e)},[p]),u,f)},e.useLocalState=function(e,t,n){var o=void 0===n?{serialize:JSON.stringify,deserialize:JSON.parse}:n,u=o.serialize,c=o.deserialize,i=r.default.useState(function(){var n=window.localStorage.getItem(e);if(null!=n)try{return c(n)}catch(t){window.localStorage.removeItem(e)}return function(e){return"function"==typeof e}(t)?t():t}),a=i[0],f=i[1],l=r.default.useRef(e);r.default.useEffect(function(){var t=l.current;t!==e&&window.localStorage.removeItem(t),l.current=e,null==a?window.localStorage.removeItem(e):window.localStorage.setItem(e,u(a))},[e,a,u]);var s=r.default.useCallback(function(){window.localStorage.removeItem(e)},[e]);return[a,f,s]},e.useModal=function(e){void 0===e&&(e=!1);var t=o(e),n=t[1];return[t[0],n.setTrue,n.setFalse]},e.usePoll=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){var e=null;function t(){null!==n&&(e=setTimeout(o,n))}function o(){var e=function(){var e=r.current,t=void 0;return null!=e&&(t=e()),t}();e instanceof Promise?e.then(t):t()}return o(),function(){e&&clearTimeout(e),e=null}},[n])},e.useTimeout=function(e,n){var r=t.useRef();t.useEffect(function(){r.current=e},[e]),t.useEffect(function(){if(null!==n){var e=setTimeout(function(){var e=r.current;null!=e&&e()},n);return function(){return clearTimeout(e)}}},[n])},e.useTitle=function(e,n){void 0===n&&(n={});var r=n.append,o=void 0!==r&&r,u=n.retain,c=void 0!==u&&u,i=n.separator,a=void 0===i?"":i,f=t.useRef(document.title);t.useLayoutEffect(function(){return f.current=document.title,c?void 0:function(){document.title=f.current}},[c]),t.useLayoutEffect(function(){document.title=o?f.current+a+e:e},[e,a,o])},e.useTrackedState=function(e){var n,r=t.useState({current:(n=e,"function"==typeof n?e():e),undoStack:[],redoStack:[]}),o=r[0],u=r[1],c=t.useCallback(function(){u(function(e){if(0===e.undoStack.length)return e;var t=e.current,n=e.undoStack,r=e.redoStack;return{current:n[n.length-1],undoStack:n.slice(0,n.length-1),redoStack:[].concat(r,[t])}})},[]),i=t.useCallback(function(){u(function(e){if(0===e.redoStack.length)return e;var t=e.redoStack;return{current:t[t.length-1],undoStack:[].concat(e.undoStack,[e.current]),redoStack:t.slice(0,t.length-1)}})},[]),a=t.useCallback(function(e){u(function(t){var n=t.current,r=t.undoStack;return{current:m(e)?e(n):e,undoStack:[].concat(r,[n]),redoStack:[]}})},[]);return[o.current,a,{undo:c,redo:i,canUndo:o.undoStack.length>0,canRedo:o.redoStack.length>0}]}}); | ||
//# sourceMappingURL=hooks.umd.js.map |
export * from './useBoolean'; | ||
export * from './useClipboard'; | ||
export * from './useControllableState'; | ||
@@ -3,0 +4,0 @@ export * from './useDebounce'; |
{ | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"name": "@committed/hooks", | ||
@@ -4,0 +4,0 @@ "description": "Committed hooks library", |
@@ -16,3 +16,3 @@ <h1 align="center">Committed Hooks</h1> | ||
For documentation see <https://https://hooks.committed.software> | ||
For documentation see <https://hooks.committed.software> | ||
@@ -19,0 +19,0 @@ ## Install |
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
206598
44
391