@siberiacancode/reactuse 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_rollupPluginBabelHelpers-DKURZ6hh.js +3 -0
- package/dist/cjs/_rollupPluginBabelHelpers-DKURZ6hh.js.map +1 -0
- package/dist/cjs/hooks/index.js +2 -2
- package/dist/cjs/hooks/useBattery/useBattery.js +3 -0
- package/dist/cjs/hooks/useBattery/useBattery.js.map +1 -0
- package/dist/cjs/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/cjs/hooks/useCounter/useCounter.js +2 -2
- package/dist/cjs/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.js +2 -2
- package/dist/cjs/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.js +2 -2
- package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/cjs/hooks/useKeyPress/useKeyPress.js.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/cjs/hooks/useMount/useMount.js +1 -1
- package/dist/cjs/hooks/useMutationObserver.js +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.js +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.js +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/cjs/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.js +2 -2
- package/dist/cjs/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/cjs/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/cjs/hooks/useToggle.js +2 -2
- package/dist/cjs/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/cjs/hooks/useWindowSize/useWindowSize.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/utils/helpers/debounce.js +1 -1
- package/dist/cjs/utils/helpers/index.js +1 -1
- package/dist/cjs/utils/helpers/isClient.js +1 -1
- package/dist/cjs/utils/helpers/isShallowEqual.js +1 -1
- package/dist/esm/{_rollupPluginBabelHelpers-BDc6tlcX.js → _rollupPluginBabelHelpers-CVdsimvi.js} +3 -3
- package/dist/esm/_rollupPluginBabelHelpers-CVdsimvi.js.map +1 -0
- package/dist/esm/hooks/index.js +2 -2
- package/dist/esm/hooks/useBattery/useBattery.js +3 -0
- package/dist/esm/hooks/useBattery/useBattery.js.map +1 -0
- package/dist/esm/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/esm/hooks/useClickOutside/useClickOutside.js +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/esm/hooks/useCounter/useCounter.js +2 -2
- package/dist/esm/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.js +2 -2
- package/dist/esm/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/esm/hooks/useHover/useHover.js +2 -2
- package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/esm/hooks/useKeyPress/useKeyPress.js.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/esm/hooks/useMount/useMount.js +1 -1
- package/dist/esm/hooks/useMutationObserver.js +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.js +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js +1 -1
- package/dist/esm/hooks/useOnline/useOnline.js +1 -1
- package/dist/esm/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/esm/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.js +2 -2
- package/dist/esm/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/esm/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/esm/hooks/useToggle.js +2 -2
- package/dist/esm/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/esm/hooks/useWindowSize/useWindowSize.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/helpers/debounce.js +1 -1
- package/dist/esm/utils/helpers/index.js +1 -1
- package/dist/esm/utils/helpers/isClient.js +1 -1
- package/dist/esm/utils/helpers/isShallowEqual.js +1 -1
- package/dist/index.d.ts +115 -36
- package/package.json +4 -7
- package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js +0 -3
- package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js.map +0 -1
- package/dist/esm/_rollupPluginBabelHelpers-BDc6tlcX.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.js","sources":["../../../../src/hooks/useWindowSize/useWindowSize.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { isClient } from '@/utils/helpers';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/** The use window size return type */\ninterface UseWindowSizeParams {\n /** The initial window width */\n initialWidth?: number;\n /** The initial window height */\n initialHeight?: number;\n}\n\n/** The use window size return type */\nexport interface UseWindowSizeReturn {\n /** The current window width */\n width: number;\n /** The current window height */\n height: number;\n}\n\n/**\n * @name useWindowSize\n * @description - Hook that manages a window size\n *\n * @param {
|
|
1
|
+
{"version":3,"file":"useWindowSize.js","sources":["../../../../src/hooks/useWindowSize/useWindowSize.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { isClient } from '@/utils/helpers';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/** The use window size return type */\ninterface UseWindowSizeParams {\n /** The initial window width */\n initialWidth?: number;\n /** The initial window height */\n initialHeight?: number;\n}\n\n/** The use window size return type */\nexport interface UseWindowSizeReturn {\n /** The current window width */\n width: number;\n /** The current window height */\n height: number;\n}\n\n/**\n * @name useWindowSize\n * @description - Hook that manages a window size\n *\n * @param {number} [params.initialWidth=Number.POSITIVE_INFINITY] The initial window width\n * @param {number} [params.initialHeight=Number.POSITIVE_INFINITY] The initial window height\n * @returns {UseWindowSizeReturn} An object containing the current window width and height\n *\n * @example\n * const { width, height } = useWindowSize()\n */\nexport const useWindowSize = (params?: UseWindowSizeParams) => {\n const [size, setSize] = useState({\n width: isClient ? window.innerWidth : params?.initialWidth ?? Number.POSITIVE_INFINITY,\n height: isClient ? window.innerHeight : params?.initialWidth ?? Number.POSITIVE_INFINITY\n });\n\n useEventListener(window, 'resize', () => {\n setSize({\n width: window.innerWidth,\n height: window.innerHeight\n });\n });\n\n return size;\n};\n"],"names":["params","_params$initialWidth","_params$initialWidth2","_useState","useState","width","isClient","window","innerWidth","initialWidth","Number","POSITIVE_INFINITY","height","innerHeight","_useState2","_slicedToArray","size","setSize","useEventListener"],"mappings":";qNAiC6B,SAACA,GAAiC,IAAAC,EAAAC,EAC7DC,EAAwBC,EAAAA,SAAS,CAC/BC,MAAOC,EAAAA,SAAWC,OAAOC,WAAiCP,QAAvBA,EAAGD,aAAAA,EAAAA,EAAQS,wBAAYR,EAAAA,EAAIS,OAAOC,kBACrEC,OAAQN,EAAAA,SAAWC,OAAOM,YAAkC,QAAvBX,EAAGF,aAAAA,EAAAA,EAAQS,oBAAYP,IAAAA,EAAAA,EAAIQ,OAAOC,oBACvEG,EAAAC,EAAAA,eAAAZ,EAAA,GAHKa,EAAIF,EAAA,GAAEG,EAAOH,EAAA,GAYpB,OAPAI,mBAAiBX,OAAQ,UAAU,WACjCU,EAAQ,CACNZ,MAAOE,OAAOC,WACdI,OAAQL,OAAOM,aAEnB,IAEOG,CACT"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
"use strict";var e=require("./hooks/useBoolean/useBoolean.js"),
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
"use strict";var e=require("./hooks/useBattery/useBattery.js"),s=require("./hooks/useBoolean/useBoolean.js"),o=require("./hooks/useClickOutside/useClickOutside.js"),u=require("./hooks/useCopyToClipboard/useCopyToClipboard.js"),r=require("./hooks/useCounter/useCounter.js"),t=require("./hooks/useDebouncedValue/useDebouncedValue.js"),i=require("./hooks/useDocumentTitle/useDocumentTitle.js"),n=require("./hooks/useDocumentVisibility/useDocumentVisibility.js"),a=require("./hooks/useEventListener/useEventListener.js"),l=require("./hooks/useHover/useHover.js"),p=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js"),c=require("./hooks/useKeyPress/useKeyPress.js"),h=require("./hooks/useKeyPressEvent/useKeyPressEvent.js"),k=require("./hooks/useKeysPressed/useKeysPressed.js"),q=require("./hooks/useLocalStorage/useLocalStorage.js"),d=require("./hooks/useMount/useMount.js"),j=require("./hooks/useNetwork/useNetwork.js"),y=require("./hooks/useNonInitialEffect/useNonInitialEffect.js"),x=require("./hooks/useOnline/useOnline.js"),C=require("./hooks/useOrientation/useOrientation.js"),E=require("./hooks/useRenderCount/useRenderCount.js"),S=require("./hooks/useSessionStorage/useSessionStorage.js"),m=require("./hooks/useStorage/useStorage.js"),v=require("./hooks/useTimeout/useTimeout.js"),g=require("./hooks/useUnmount/useUnmount.js"),b=require("./hooks/useWindowEvent/useWindowEvent.js"),f=require("./hooks/useWindowSize/useWindowSize.js");require("./_rollupPluginBabelHelpers-DKURZ6hh.js"),require("react"),require("./utils/helpers/debounce.js"),require("./utils/helpers/isClient.js"),require("./hooks/useMutationObserver.js"),require("./utils/helpers/isShallowEqual.js"),exports.useBattery=e.useBattery,exports.useBoolean=s.useBoolean,exports.useClickOutside=o.useClickOutside,exports.legacyCopyToClipboard=u.legacyCopyToClipboard,exports.useCopyToClipboard=u.useCopyToClipboard,exports.useCounter=r.useCounter,exports.useDebouncedValue=t.useDebouncedValue,exports.useDocumentTitle=i.useDocumentTitle,exports.useDocumentVisibility=n.useDocumentVisibility,exports.useEventListener=a.useEventListener,exports.useHover=l.useHover,exports.useIsomorphicLayoutEffect=p.useIsomorphicLayoutEffect,exports.useKeyPress=c.useKeyPress,exports.useKeyPressEvent=h.useKeyPressEvent,exports.useKeysPressed=k.useKeysPressed,exports.useLocalStorage=q.useLocalStorage,exports.useMount=d.useMount,exports.getConnection=j.getConnection,exports.useNetwork=j.useNetwork,exports.useNonInitialEffect=y.useNonInitialEffect,exports.useOnline=x.useOnline,exports.useOrientation=C.useOrientation,exports.useRenderCount=E.useRenderCount,exports.useSessionStorage=S.useSessionStorage,exports.dispatchStorageEvent=m.dispatchStorageEvent,exports.useStorage=m.useStorage,exports.useTimeout=v.useTimeout,exports.useUnmount=g.useUnmount,exports.useWindowEvent=b.useWindowEvent,exports.useWindowSize=f.useWindowSize;
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
"use strict";exports.debounce=function(e,r){var t;return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,o)}),r)}};
|
|
3
3
|
//# sourceMappingURL=debounce.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
"use strict";var e=require("./debounce.js"),s=require("./isClient.js"),i=require("./isShallowEqual.js");exports.debounce=e.debounce,exports.isClient=s.isClient,exports.isShallowEqual=i.isShallowEqual;
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
"use strict";var e,n,d=!("undefined"==typeof window||null===(e=window)||void 0===e||!e.document||null===(n=window)||void 0===n||null===(n=n.document)||void 0===n||!n.createElement);exports.isClient=d;
|
|
3
3
|
//# sourceMappingURL=isClient.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
"use strict";exports.isShallowEqual=function(e,r){var t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(var l=0,s=t;l<s.length;l++){var u=s[l];if(e[u]!==r[u])return!1}return!0};
|
|
3
3
|
//# sourceMappingURL=isShallowEqual.js.map
|
package/dist/esm/{_rollupPluginBabelHelpers-BDc6tlcX.js → _rollupPluginBabelHelpers-CVdsimvi.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){
|
|
3
|
-
//# sourceMappingURL=_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){c(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof g?r:g,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:P(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var y="suspendedStart",p="suspendedYield",v="executing",d="completed",m={};function g(){}function b(){}function w(){}var O={};l(O,c,(function(){return this}));var j=Object.getPrototypeOf,E=j&&j(j(T([])));E&&E!==n&&o.call(E,c)&&(O=E);var L=w.prototype=g.prototype=Object.create(O);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function P(r,e,n){var o=y;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===y)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?d:p,f.arg===m)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=d,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function A(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function k(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(L,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},x(S.prototype),l(S.prototype,u,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new S(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(L),l(L,f,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(k),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),m},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),k(e),m}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;k(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}function n(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:String(r)}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function i(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var a=t.apply(r,e);function c(t){i(a,n,o,c,u,"next",t)}function u(t){i(a,n,o,c,u,"throw",t)}c(void 0)}))}}function c(t,r,e){return(r=n(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function u(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,c=[],u=!0,f=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;u=!1}else for(;!(u=(n=i.call(e)).done)&&(c.push(n.value),c.length!==r);u=!0);}catch(t){f=!0,o=t}finally{try{if(!u&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(f)throw o}}return c}}(t,r)||l(t,r)||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 f(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||l(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,r){if(t){if("string"==typeof t)return s(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?s(t,r):void 0}}function s(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}export{u as _,r as a,o as b,f as c,a as d,e};
|
|
3
|
+
//# sourceMappingURL=_rollupPluginBabelHelpers-CVdsimvi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers-CVdsimvi.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
export{useBoolean}from"./useBoolean/useBoolean.js";export{useClickOutside}from"./useClickOutside/useClickOutside.js";export{legacyCopyToClipboard,useCopyToClipboard}from"./useCopyToClipboard/useCopyToClipboard.js";export{useCounter}from"./useCounter/useCounter.js";export{useDebouncedValue}from"./useDebouncedValue/useDebouncedValue.js";export{useDocumentTitle}from"./useDocumentTitle/useDocumentTitle.js";export{useDocumentVisibility}from"./useDocumentVisibility/useDocumentVisibility.js";export{useEventListener}from"./useEventListener/useEventListener.js";export{useHover}from"./useHover/useHover.js";export{useIsomorphicLayoutEffect}from"./useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";export{useKeyPress}from"./useKeyPress/useKeyPress.js";export{useKeyPressEvent}from"./useKeyPressEvent/useKeyPressEvent.js";export{useKeysPressed}from"./useKeysPressed/useKeysPressed.js";export{useLocalStorage}from"./useLocalStorage/useLocalStorage.js";export{useMount}from"./useMount/useMount.js";export{getConnection,useNetwork}from"./useNetwork/useNetwork.js";export{useNonInitialEffect}from"./useNonInitialEffect/useNonInitialEffect.js";export{useOnline}from"./useOnline/useOnline.js";export{useOrientation}from"./useOrientation/useOrientation.js";export{useRenderCount}from"./useRenderCount/useRenderCount.js";export{useSessionStorage}from"./useSessionStorage/useSessionStorage.js";export{dispatchStorageEvent,useStorage}from"./useStorage/useStorage.js";export{useTimeout}from"./useTimeout/useTimeout.js";export{useUnmount}from"./useUnmount/useUnmount.js";export{useWindowEvent}from"./useWindowEvent/useWindowEvent.js";export{useWindowSize}from"./useWindowSize/useWindowSize.js";import"../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
export{useBattery}from"./useBattery/useBattery.js";export{useBoolean}from"./useBoolean/useBoolean.js";export{useClickOutside}from"./useClickOutside/useClickOutside.js";export{legacyCopyToClipboard,useCopyToClipboard}from"./useCopyToClipboard/useCopyToClipboard.js";export{useCounter}from"./useCounter/useCounter.js";export{useDebouncedValue}from"./useDebouncedValue/useDebouncedValue.js";export{useDocumentTitle}from"./useDocumentTitle/useDocumentTitle.js";export{useDocumentVisibility}from"./useDocumentVisibility/useDocumentVisibility.js";export{useEventListener}from"./useEventListener/useEventListener.js";export{useHover}from"./useHover/useHover.js";export{useIsomorphicLayoutEffect}from"./useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";export{useKeyPress}from"./useKeyPress/useKeyPress.js";export{useKeyPressEvent}from"./useKeyPressEvent/useKeyPressEvent.js";export{useKeysPressed}from"./useKeysPressed/useKeysPressed.js";export{useLocalStorage}from"./useLocalStorage/useLocalStorage.js";export{useMount}from"./useMount/useMount.js";export{getConnection,useNetwork}from"./useNetwork/useNetwork.js";export{useNonInitialEffect}from"./useNonInitialEffect/useNonInitialEffect.js";export{useOnline}from"./useOnline/useOnline.js";export{useOrientation}from"./useOrientation/useOrientation.js";export{useRenderCount}from"./useRenderCount/useRenderCount.js";export{useSessionStorage}from"./useSessionStorage/useSessionStorage.js";export{dispatchStorageEvent,useStorage}from"./useStorage/useStorage.js";export{useTimeout}from"./useTimeout/useTimeout.js";export{useUnmount}from"./useUnmount/useUnmount.js";export{useWindowEvent}from"./useWindowEvent/useWindowEvent.js";export{useWindowSize}from"./useWindowSize/useWindowSize.js";import"../_rollupPluginBabelHelpers-CVdsimvi.js";import"react";import"../utils/helpers/debounce.js";import"../utils/helpers/isClient.js";import"./useMutationObserver.js";import"../utils/helpers/isShallowEqual.js";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e,a as n}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import i from"react";var r=function(){var r=i.useState({supported:!1,loading:!0,level:0,charging:!1,chargingTime:0,dischargingTime:0}),t=e(r,2),a=t[0],g=t[1];return i.useEffect((function(){var e;if(!(navigator&&"getBattery"in navigator&&"function"==typeof navigator.getBattery))return g(n(n({},a),{},{loading:!1}));var i=function(){var n,i,r,t;return g({supported:!0,loading:!0,level:(null===(n=e)||void 0===n?void 0:n.level)||0,charging:(null===(i=e)||void 0===i?void 0:i.charging)||!1,dischargingTime:(null===(r=e)||void 0===r?void 0:r.dischargingTime)||0,chargingTime:(null===(t=e)||void 0===t?void 0:t.chargingTime)||0})};return navigator.getBattery().then((function(n){e=n,i(),n.addEventListener("levelchange",i),n.addEventListener("chargingchange",i),n.addEventListener("chargingtimechange",i),n.addEventListener("dischargingtimechange",i)})),function(){e&&(e.removeEventListener("levelchange",i),e.removeEventListener("chargingchange",i),e.removeEventListener("chargingtimechange",i),e.removeEventListener("dischargingtimechange",i))}}),[]),a};export{r as useBattery};
|
|
3
|
+
//# sourceMappingURL=useBattery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBattery.js","sources":["../../../../src/hooks/useBattery/useBattery.ts"],"sourcesContent":["import React from 'react';\n\n/** State for hook use battery */\ninterface UseBatteryStateReturn {\n /** Is battery API supported? */\n supported: boolean;\n /** Is battery information loading? */\n loading: boolean;\n /** Is charging battery? */\n charging: boolean;\n /** Time until the battery is fully charged */\n chargingTime: number;\n /** Time until the battery is completely discharged */\n dischargingTime: number;\n /** Battery charge level from 0 to 1 */\n level: number;\n}\n\n/**\n * @name useBattery\n * @description - Hook for getting information about battery status\n *\n * @returns {UseBatteryStateReturn} Object containing battery information & Battery API support\n *\n * @example\n * const battery = useBattery();\n */\nexport const useBattery = () => {\n const [state, setState] = React.useState<UseBatteryStateReturn>({\n supported: false,\n loading: true,\n level: 0,\n charging: false,\n chargingTime: 0,\n dischargingTime: 0\n });\n\n React.useEffect(() => {\n const isSupported =\n navigator && 'getBattery' in navigator && typeof navigator.getBattery === 'function';\n if (!isSupported) return setState({ ...state, loading: false });\n\n let battery: BatteryManager | null;\n\n const handleChange = () =>\n setState({\n supported: true,\n loading: true,\n level: battery?.level || 0,\n charging: battery?.charging || false,\n dischargingTime: battery?.dischargingTime || 0,\n chargingTime: battery?.chargingTime || 0\n });\n\n navigator.getBattery().then((batteryManager) => {\n battery = batteryManager;\n handleChange();\n\n batteryManager.addEventListener('levelchange', handleChange);\n batteryManager.addEventListener('chargingchange', handleChange);\n batteryManager.addEventListener('chargingtimechange', handleChange);\n batteryManager.addEventListener('dischargingtimechange', handleChange);\n });\n\n return () => {\n if (!battery) return;\n battery.removeEventListener('levelchange', handleChange);\n battery.removeEventListener('chargingchange', handleChange);\n battery.removeEventListener('chargingtimechange', handleChange);\n battery.removeEventListener('dischargingtimechange', handleChange);\n };\n }, []);\n\n return state;\n};\n"],"names":["useBattery","_React$useState","React","useState","supported","loading","level","charging","chargingTime","dischargingTime","_React$useState2","_slicedToArray","state","setState","useEffect","battery","navigator","getBattery","_objectSpread","handleChange","_battery","_battery2","_battery3","_battery4","then","batteryManager","addEventListener","removeEventListener"],"mappings":";gGA2BaA,EAAa,WACxB,IAAAC,EAA0BC,EAAMC,SAAgC,CAC9DC,WAAW,EACXC,SAAS,EACTC,MAAO,EACPC,UAAU,EACVC,aAAc,EACdC,gBAAiB,IACjBC,EAAAC,EAAAV,EAAA,GAPKW,EAAKF,EAAA,GAAEG,EAAQH,EAAA,GA6CtB,OApCAR,EAAMY,WAAU,WACd,IAIIC,EAFJ,KADEC,WAAa,eAAgBA,WAA6C,mBAAzBA,UAAUC,YAC3C,OAAOJ,EAAQK,EAAAA,EAAA,CAAA,EAAMN,GAAK,GAAA,CAAEP,SAAS,KAIvD,IAAMc,EAAe,WAAH,IAAAC,EAAAC,EAAAC,EAAAC,EAAA,OAChBV,EAAS,CACPT,WAAW,EACXC,SAAS,EACTC,OAAc,QAAPc,EAAAL,SAAO,IAAAK,OAAA,EAAPA,EAASd,QAAS,EACzBC,UAAiB,QAAPc,EAAAN,SAAO,IAAAM,OAAA,EAAPA,EAASd,YAAY,EAC/BE,iBAAwB,QAAPa,EAAAP,SAAO,IAAAO,OAAA,EAAPA,EAASb,kBAAmB,EAC7CD,cAAqBe,QAAPA,EAAAR,SAAAQ,IAAOA,OAAPA,EAAAA,EAASf,eAAgB,GACvC,EAYJ,OAVAQ,UAAUC,aAAaO,MAAK,SAACC,GAC3BV,EAAUU,EACVN,IAEAM,EAAeC,iBAAiB,cAAeP,GAC/CM,EAAeC,iBAAiB,iBAAkBP,GAClDM,EAAeC,iBAAiB,qBAAsBP,GACtDM,EAAeC,iBAAiB,wBAAyBP,EAC3D,IAEO,WACAJ,IACLA,EAAQY,oBAAoB,cAAeR,GAC3CJ,EAAQY,oBAAoB,iBAAkBR,GAC9CJ,EAAQY,oBAAoB,qBAAsBR,GAClDJ,EAAQY,oBAAoB,wBAAyBR,IAExD,GAAE,IAEIP,CACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as r}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as r}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import t from"react";var n=function(){var n=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=t.useState(n),o=r(e,2),u=o[0],l=o[1];return[u,function(r){return l((function(t){return null!=r?r:!t}))}]};export{n as useBoolean};
|
|
3
3
|
//# sourceMappingURL=useBoolean.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import t from"react";import{useIsomorphicLayoutEffect as e}from"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";import"../../utils/helpers/isClient.js";var n=function(t){return"function"==typeof t?t():t instanceof Element?t:t.current},r=function(){var r=void 0===(arguments.length<=1?void 0:arguments[1])?null:arguments.length<=0?void 0:arguments[0],o=(arguments.length<=1?void 0:arguments[1])?arguments.length<=1?void 0:arguments[1]:arguments.length<=0?void 0:arguments[0],u=t.useRef(null),i=t.useRef(o);if(e((function(){i.current=o}),[o]),t.useEffect((function(){var t=function(t){if(Array.isArray(r))r.forEach((function(e){var r=n(e);r&&!r.contains(t.target)&&i.current(t)}));else{var e=r?n(r):u.current;e&&!e.contains(t.target)&&i.current(t)}};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),function(){document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}),[]),!r)return u};export{r as useClickOutside};
|
|
3
3
|
//# sourceMappingURL=useClickOutside.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.js","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n// composedPath что это такое\n\ntype UseClickOutsideTarget = React.RefObject<Element | null> | (() => Element) | Element;\n\nconst getElement = (target: UseClickOutsideTarget) => {\n if (typeof target === 'function') {\n return target();\n }\n\n if (target instanceof Element) {\n return target;\n }\n\n return target.current;\n};\n\nexport type UseClickOutsideReturn<\n Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any\n> = React.RefObject<Target>;\n\nexport type UseClickOutside = {\n <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(\n target: Target,\n callback: (event: Event) => void\n ): void;\n\n <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(\n callback: (event: Event) => void,\n target?: never\n ): UseClickOutsideReturn<Target>;\n};\n\
|
|
1
|
+
{"version":3,"file":"useClickOutside.js","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n// composedPath что это такое\n\ntype UseClickOutsideTarget = React.RefObject<Element | null> | (() => Element) | Element;\n\nconst getElement = (target: UseClickOutsideTarget) => {\n if (typeof target === 'function') {\n return target();\n }\n\n if (target instanceof Element) {\n return target;\n }\n\n return target.current;\n};\n\nexport type UseClickOutsideReturn<\n Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any\n> = React.RefObject<Target>;\n\nexport type UseClickOutside = {\n <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(\n target: Target,\n callback: (event: Event) => void\n ): void;\n\n <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(\n callback: (event: Event) => void,\n target?: never\n ): UseClickOutsideReturn<Target>;\n};\n\nexport const useClickOutside = ((...params: any[]) => {\n const target = (typeof params[1] === 'undefined' ? null : params[0]) as\n | UseClickOutsideTarget\n | Array<UseClickOutsideTarget>\n | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = React.useRef<Element>(null);\n const internalCallbackRef = React.useRef(callback);\n\n useIsomorphicLayoutEffect(() => {\n internalCallbackRef.current = callback;\n }, [callback]);\n\n React.useEffect(() => {\n const handler = (event: Event) => {\n if (Array.isArray(target)) {\n target.forEach((target) => {\n const element = getElement(target);\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n });\n\n return;\n }\n\n const element = target ? getElement(target) : internalRef.current;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('mousedown', handler);\n document.addEventListener('touchstart', handler);\n\n return () => {\n document.removeEventListener('mousedown', handler);\n document.removeEventListener('touchstart', handler);\n };\n }, []);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["getElement","target","Element","current","useClickOutside","arguments","length","undefined","callback","internalRef","React","useRef","internalCallbackRef","useIsomorphicLayoutEffect","useEffect","handler","event","Array","isArray","forEach","element","contains","document","addEventListener","removeEventListener"],"mappings":";mKAQA,IAAMA,EAAa,SAACC,GAClB,MAAsB,mBAAXA,EACFA,IAGLA,aAAkBC,QACbD,EAGFA,EAAOE,OAChB,EAkBaC,EAAmB,WAC9B,IAAMH,OAA+B,KAArBI,UAAAC,QAAA,OAAAC,EAAAF,UAAA,IAAmC,KAAIA,UAAAC,QAAAC,OAAAA,EAAAF,UAG1C,GACPG,GAAYH,UAAAC,QAAA,OAAAC,EAAAF,UAAA,IAAAA,UAAAC,QAAAC,OAAAA,EAAAF,UAAAA,GAAAA,UAAAC,QAAAC,OAAAA,EAAAF,UAA4D,GAExEI,EAAcC,EAAMC,OAAgB,MACpCC,EAAsBF,EAAMC,OAAOH,GAoCzC,GAlCAK,GAA0B,WACxBD,EAAoBT,QAAUK,CAChC,GAAG,CAACA,IAEJE,EAAMI,WAAU,WACd,IAAMC,EAAU,SAACC,GACf,GAAIC,MAAMC,QAAQjB,GAChBA,EAAOkB,SAAQ,SAAClB,GACd,IAAMmB,EAAUpB,EAAWC,GAEvBmB,IAAYA,EAAQC,SAASL,EAAMf,SACrCW,EAAoBT,QAAQa,EAEhC,QAPF,CAYA,IAAMI,EAAUnB,EAASD,EAAWC,GAAUQ,EAAYN,QAEtDiB,IAAYA,EAAQC,SAASL,EAAMf,SACrCW,EAAoBT,QAAQa,EAL9B,GAYF,OAHAM,SAASC,iBAAiB,YAAaR,GACvCO,SAASC,iBAAiB,aAAcR,GAEjC,WACLO,SAASE,oBAAoB,YAAaT,GAC1CO,SAASE,oBAAoB,aAAcT,GAE9C,GAAE,KAECd,EACJ,OAAOQ,CACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e,
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e,d as r,e as t}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import n from"react";var a=function(e){var r=document.createElement("textarea");r.value=e,document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)},o=function(){var o=n.useState(null),c=e(o,2),u=c[0],i=c[1],l=n.useCallback(function(){var e=r(t().mark((function e(r){var n;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,null===(n=navigator)||void 0===n||null===(n=n.clipboard)||void 0===n||!n.writeText){e.next=7;break}return e.next=4,navigator.clipboard.writeText(r);case 4:i(r),e.next=8;break;case 7:throw new Error("writeText not supported");case 8:e.next=14;break;case 10:e.prev=10,e.t0=e.catch(0),a(r),i(r);case 14:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(r){return e.apply(this,arguments)}}(),[]);return[u,l]};export{a as legacyCopyToClipboard,o as useCopyToClipboard};
|
|
3
3
|
//# sourceMappingURL=useCopyToClipboard.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as n}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as n}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import t from"react";var e=function(){var e,o,i,u="number"==typeof(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:null===(e=arguments.length<=0?void 0:arguments[0])||void 0===e?void 0:e.initialValue,r="number"==typeof(arguments.length<=0?void 0:arguments[0])?null!==(o=arguments.length<=1?void 0:arguments[1])&&void 0!==o?o:{}:null!==(i=arguments.length<=0?void 0:arguments[0])&&void 0!==i?i:{},l=r.max,a=void 0===l?Number.POSITIVE_INFINITY:l,m=r.min,f=void 0===m?Number.NEGATIVE_INFINITY:m,v=t.useState(null!=u?u:0),d=n(v,2),c=d[0],h=d[1];t.useEffect((function(){}),[f,a]);return{count:c,set:function(n){h((function(t){return Math.max(f,Math.min(a,"number"==typeof n?n:n(t)))}))},inc:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;h((function(t){return"number"==typeof a&&c===a?t:Math.max(Math.min(a,t+n),f)}))},dec:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;h((function(t){return"number"==typeof f&&t===f?t:Math.min(Math.max(f,t-n),a)}))},reset:function(){var n=null!=u?u:0;return"number"==typeof a&&n>a?h(a):"number"==typeof f&&n<f?h(f):void h(n)}}};export{e as useCounter};
|
|
3
3
|
//# sourceMappingURL=useCounter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCounter.js","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import React from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The min of count value */\n min?: number;\n /** The max of count value */\n max?: number;\n}\n\nexport interface UseCounterParams {\n /** The initial number value, defaults to 0 */\n initialValue?: number;\n /** The min of count value */\n min?: number;\n /** The max of count value */\n max?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** The current count value */\n count: number;\n /** Function to set a specific value to the counter */\n set: React.Dispatch<React.SetStateAction<number>>;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n}\n\nexport type UseCounter = {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n ({ initialValue, max, min }: UseCounterParams, options?: never): UseCounterReturn;\n};\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities\n *\n * @overload\n * @param {number} [initialValue=0] The initial number value\n * @param {
|
|
1
|
+
{"version":3,"file":"useCounter.js","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import React from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The min of count value */\n min?: number;\n /** The max of count value */\n max?: number;\n}\n\nexport interface UseCounterParams {\n /** The initial number value, defaults to 0 */\n initialValue?: number;\n /** The min of count value */\n min?: number;\n /** The max of count value */\n max?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** The current count value */\n count: number;\n /** Function to set a specific value to the counter */\n set: React.Dispatch<React.SetStateAction<number>>;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n}\n\nexport type UseCounter = {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n ({ initialValue, max, min }: UseCounterParams, options?: never): UseCounterReturn;\n};\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities\n *\n * @overload\n * @param {number} [initialValue=0] The initial number value\n * @param {number} [options.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [options.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n\n * @overload\n * @param {number} [params.initialValue=0] The initial number value\n * @param {number} [params.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [params.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter(5);\n */\nexport const useCounter: UseCounter = (...params) => {\n const initialValue = typeof params[0] === 'number' ? params[0] : params[0]?.initialValue;\n const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } =\n typeof params[0] === 'number' ? params[1] ?? {} : params[0] ?? {};\n\n const [count, setCount] = React.useState(initialValue ?? 0);\n\n React.useEffect(() => {}, [min, max]);\n\n const inc = (value: number = 1) => {\n setCount((prevCount) => {\n if (typeof max === 'number' && count === max) return prevCount;\n return Math.max(Math.min(max, prevCount + value), min);\n });\n };\n\n const dec = (value: number = 1) => {\n setCount((prevCount) => {\n if (typeof min === 'number' && prevCount === min) return prevCount;\n return Math.min(Math.max(min, prevCount - value), max);\n });\n };\n\n const reset = () => {\n const value = initialValue ?? 0;\n if (typeof max === 'number' && value > max) return setCount(max);\n if (typeof min === 'number' && value < min) return setCount(min);\n setCount(value);\n };\n\n const set = (value: React.SetStateAction<number>) => {\n setCount((prevCount) => {\n const updatedCount = Math.max(\n min,\n Math.min(max, typeof value === 'number' ? value : value(prevCount))\n );\n\n return updatedCount;\n });\n };\n\n return { count, set, inc, dec, reset } as const;\n};\n"],"names":["useCounter","_ref","_ref3","_ref4","initialValue","arguments","length","undefined","_ref2","_ref2$max","max","Number","POSITIVE_INFINITY","_ref2$min","min","NEGATIVE_INFINITY","_React$useState","React","useState","_React$useState2","_slicedToArray","count","setCount","useEffect","set","value","prevCount","Math","inc","dec","reset"],"mappings":";yFA0DaA,EAAyB,WAAe,IAAAC,EAAAC,EAAAC,EAC7CC,EAAoC,iBAArBC,UAAAC,QAAAC,OAAAA,EAAAF,cAA6BA,UAAAC,QAAA,OAAAC,EAAAF,UAAAJ,GAAAA,QAAAA,EAAAI,UAAAC,QAAA,OAAAC,EAAAF,UAAAJ,UAAeA,IAAfA,OAAeA,EAAAA,EAAWG,aAC5EI,EACuB,iBAArBH,UAAAC,QAAA,OAAAC,EAAAF,sBAA6BH,EAAAG,UAAAC,QAAAC,OAAAA,EAAAF,oBAAA,IAAAH,EAAAA,EAAgB,CAAE,EAAA,QAAAC,EAAAE,UAAAC,QAAAC,OAAAA,EAAAF,UAAA,UAAAF,IAAAA,EAAAA,EAAgB,CAAE,EAAAM,EAAAD,EAD3DE,IAAAA,OAAG,IAAAD,EAAGE,OAAOC,kBAAiBH,EAAAI,EAAAL,EAAEM,IAAAA,OAAG,IAAAD,EAAGF,OAAOI,kBAAiBF,EAGtEG,EAA0BC,EAAMC,SAASd,QAAAA,EAAgB,GAAEe,EAAAC,EAAAJ,EAAA,GAApDK,EAAKF,EAAA,GAAEG,EAAQH,EAAA,GAEtBF,EAAMM,WAAU,WAAM,GAAI,CAACT,EAAKJ,IAkChC,MAAO,CAAEW,MAAAA,EAAOG,IAXJ,SAACC,GACXH,GAAS,SAACI,GAMR,OALqBC,KAAKjB,IACxBI,EACAa,KAAKb,IAAIJ,EAAsB,iBAAVe,EAAqBA,EAAQA,EAAMC,IAI5D,KAGmBE,IAhCT,WAAuB,IAAtBH,EAAapB,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,EAC3BiB,GAAS,SAACI,GACR,MAAmB,iBAARhB,GAAoBW,IAAUX,EAAYgB,EAC9CC,KAAKjB,IAAIiB,KAAKb,IAAIJ,EAAKgB,EAAYD,GAAQX,EACpD,KA4BwBe,IAzBd,WAAuB,IAAtBJ,EAAapB,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,EAC3BiB,GAAS,SAACI,GACR,MAAmB,iBAARZ,GAAoBY,IAAcZ,EAAYY,EAClDC,KAAKb,IAAIa,KAAKjB,IAAII,EAAKY,EAAYD,GAAQf,EACpD,KAqB6BoB,MAlBjB,WACZ,IAAML,EAAQrB,QAAAA,EAAgB,EAC9B,MAAmB,iBAARM,GAAoBe,EAAQf,EAAYY,EAASZ,GACzC,iBAARI,GAAoBW,EAAQX,EAAYQ,EAASR,QAC5DQ,EAASG,IAeb"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import r from"react";import{debounce as t}from"../../utils/helpers/debounce.js";import"../../utils/helpers/isClient.js";var o=function(o,u,n){console.log("@",n);var s=r.useRef(o),i=r.useState(o),l=e(i,2),c=l[0],f=l[1],p=r.useMemo((function(){return t((function(e){return f(e)}),u)}),[u]);return r.useEffect((function(){s.current!==o&&(p(o),s.current=o)}),[o]),[c,p]};export{o as useDebouncedValue};
|
|
3
3
|
//# sourceMappingURL=useDebouncedValue.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as t}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as t}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import e from"react";import{useIsomorphicLayoutEffect as o}from"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";import{useMutationObserver as n}from"../useMutationObserver.js";import"../../utils/helpers/isClient.js";function r(r,u){var i=e.useRef(document.title),c=e.useState(null!=r?r:document.title),l=t(c,2),m=l[0],s=l[1];n((function(){document&&document.title!==m&&s(document.title)}),{childList:!0},document.head.querySelector("title")),o((function(){if(null!=u&&u.restoreOnUnmount)return function(){document.title=i.current}}),[]);var f=function(t){var e=t.trim();e.length>0&&(document.title=e)};return o((function(){"string"==typeof r&&f(r)}),[r]),[m,f]}export{r as useDocumentTitle};
|
|
3
3
|
//# sourceMappingURL=useDocumentTitle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentTitle.js","sources":["../../../../src/hooks/useDocumentTitle/useDocumentTitle.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useMutationObserver } from '../useMutationObserver';\n\nexport interface UseDocumentTitleOptions {\n /** Restore the previous title on unmount */\n restoreOnUnmount?: boolean;\n}\n\nexport type UseDocumentTitleReturn = [\n /** The current title */\n title: string,\n\n /** Function to update the title */\n setTitle: (title: string) => void\n];\n\n/**\n * @name useDocumentTitle\n * @description - Hook that manages the document title and allows updating it\n *\n * @param {string} [value] The initial title. If not provided, the current document title will be used\n * @param {
|
|
1
|
+
{"version":3,"file":"useDocumentTitle.js","sources":["../../../../src/hooks/useDocumentTitle/useDocumentTitle.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useMutationObserver } from '../useMutationObserver';\n\n/** The use document title options type */\nexport interface UseDocumentTitleOptions {\n /** Restore the previous title on unmount */\n restoreOnUnmount?: boolean;\n}\n\n/** The use document title return type */\nexport type UseDocumentTitleReturn = [\n /** The current title */\n title: string,\n\n /** Function to update the title */\n setTitle: (title: string) => void\n];\n\n/**\n * @name useDocumentTitle\n * @description - Hook that manages the document title and allows updating it\n *\n * @param {string} [value] The initial title. If not provided, the current document title will be used\n * @param {boolean} [options.restoreOnUnmount] Restore the previous title on unmount\n * @returns {UseDocumentTitleReturn} An array containing the current title and a function to update the title\n *\n * @example\n * const [title, setTitle] = useDocumentTitle();\n */\nexport function useDocumentTitle(\n value?: string,\n options?: UseDocumentTitleOptions\n): UseDocumentTitleReturn {\n const prevTitleRef = React.useRef(document.title);\n const [title, setTitle] = React.useState(value ?? document.title);\n\n useMutationObserver(\n () => {\n if (document && document.title !== title) {\n setTitle(document.title);\n }\n },\n { childList: true },\n document.head.querySelector('title')\n );\n\n useIsomorphicLayoutEffect(() => {\n if (options?.restoreOnUnmount) {\n return () => {\n document.title = prevTitleRef.current;\n };\n }\n }, []);\n\n const set = (value: string) => {\n const updatedValue = value.trim();\n if (updatedValue.length > 0) document.title = updatedValue;\n };\n\n useIsomorphicLayoutEffect(() => {\n if (typeof value !== 'string') return;\n set(value);\n }, [value]);\n\n return [title, set];\n}\n"],"names":["useDocumentTitle","value","options","prevTitleRef","React","useRef","document","title","_React$useState","useState","_React$useState2","_slicedToArray","setTitle","useMutationObserver","childList","head","querySelector","useIsomorphicLayoutEffect","restoreOnUnmount","current","set","updatedValue","trim","length"],"mappings":";mSA+BO,SAASA,EACdC,EACAC,GAEA,IAAMC,EAAeC,EAAMC,OAAOC,SAASC,OAC3CC,EAA0BJ,EAAMK,SAASR,QAAAA,EAASK,SAASC,OAAMG,EAAAC,EAAAH,EAAA,GAA1DD,EAAKG,EAAA,GAAEE,EAAQF,EAAA,GAEtBG,GACE,WACMP,UAAYA,SAASC,QAAUA,GACjCK,EAASN,SAASC,MAEtB,GACA,CAAEO,WAAW,GACbR,SAASS,KAAKC,cAAc,UAG9BC,GAA0B,WACxB,GAAIf,SAAAA,EAASgB,iBACX,OAAO,WACLZ,SAASC,MAAQJ,EAAagB,QAGnC,GAAE,IAEH,IAAMC,EAAM,SAACnB,GACX,IAAMoB,EAAepB,EAAMqB,OACvBD,EAAaE,OAAS,IAAGjB,SAASC,MAAQc,IAQhD,OALAJ,GAA0B,WACH,iBAAVhB,GACXmB,EAAInB,EACN,GAAG,CAACA,IAEG,CAACM,EAAOa,EACjB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import n from"react";var t=function(){return document.visibilityState},i=function(){return"hidden"},e=function(n){return window.addEventListener("visibilitychange",n),function(){window.removeEventListener("visibilitychange",n)}},r=function(){return n.useSyncExternalStore(e,t,i)};export{r as useDocumentVisibility};
|
|
3
3
|
//# sourceMappingURL=useDocumentVisibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentVisibility.js","sources":["../../../../src/hooks/useDocumentVisibility/useDocumentVisibility.ts"],"sourcesContent":["import React from 'react';\n\nconst getSnapshot = () => document.visibilityState;\nconst getServerSnapshot = (): DocumentVisibilityState => 'hidden';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('visibilitychange', callback);\n return () => {\n window.removeEventListener('visibilitychange', callback);\n };\n};\n\nexport const useDocumentVisibility = () =>\n React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","document","visibilityState","getServerSnapshot","subscribe","callback","window","addEventListener","removeEventListener","useDocumentVisibility","React","useSyncExternalStore"],"mappings":";qBAEA,IAAMA,EAAc,WAAH,OAASC,SAASC,eAAe,EAC5CC,EAAoB,WAAH,MAAkC,QAAQ,EAC3DC,EAAY,SAACC,GAEjB,OADAC,OAAOC,iBAAiB,mBAAoBF,GACrC,WACLC,OAAOE,oBAAoB,mBAAoBH,GAEnD,
|
|
1
|
+
{"version":3,"file":"useDocumentVisibility.js","sources":["../../../../src/hooks/useDocumentVisibility/useDocumentVisibility.ts"],"sourcesContent":["import React from 'react';\n\nconst getSnapshot = () => document.visibilityState;\nconst getServerSnapshot = (): DocumentVisibilityState => 'hidden';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('visibilitychange', callback);\n return () => {\n window.removeEventListener('visibilitychange', callback);\n };\n};\n\n/**\n * @name useDocumentVisibility\n * @description – Hook that provides the current visibility state of the document\n *\n * @returns {DocumentVisibilityState} The current visibility state of the document, which can be 'visible' or 'hidden'\n *\n * @example\n * const visibilityState = useDocumentVisibility();\n */\nexport const useDocumentVisibility = () =>\n React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","document","visibilityState","getServerSnapshot","subscribe","callback","window","addEventListener","removeEventListener","useDocumentVisibility","React","useSyncExternalStore"],"mappings":";qBAEA,IAAMA,EAAc,WAAH,OAASC,SAASC,eAAe,EAC5CC,EAAoB,WAAH,MAAkC,QAAQ,EAC3DC,EAAY,SAACC,GAEjB,OADAC,OAAOC,iBAAiB,mBAAoBF,GACrC,WACLC,OAAOE,oBAAoB,mBAAoBH,GAEnD,EAWaI,EAAwB,WAAH,OAChCC,EAAMC,qBAAqBP,EAAWJ,EAAaG,EAAkB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import n from"react";var
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import n from"react";var t=function(){var t=(arguments.length<=1?void 0:arguments[1])instanceof Function?null:arguments.length<=0?void 0:arguments[0],e=t?arguments.length<=1?void 0:arguments[1]:arguments.length<=0?void 0:arguments[0],r=Array.isArray(e)?e:[e],o=t?arguments.length<=2?void 0:arguments[2]:arguments.length<=1?void 0:arguments[1],i=t?arguments.length<=3?void 0:arguments[3]:arguments.length<=2?void 0:arguments[2],f=n.useRef(null);if(n.useEffect((function(){var n=t?function(n){return"function"==typeof n?n():n instanceof Element||n instanceof Window||n instanceof Document?n:n.current}(t):f.current;if(n)return r.forEach((function(t){return n.addEventListener(t,o,i)})),function(){r.forEach((function(t){return n.removeEventListener(t,o,i)}))}}),[t,e,o,i]),!t)return f};export{t as useEventListener};
|
|
3
3
|
//# sourceMappingURL=useEventListener.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventListener.js","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import React from 'react';\n\nexport type UseEventListenerTarget =\n | React.RefObject<Element | null>\n | (() => Element)\n | Element\n | Window\n | Document;\n\nconst getElement = (target: UseEventListenerTarget) => {\n if (typeof target === 'function') {\n return target();\n }\n\n if (target instanceof Element || target instanceof Window || target instanceof Document) {\n return target;\n }\n\n return target.current;\n};\n\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\nexport type UseEventListenerReturn<Target extends UseEventListenerTarget = any> =\n React.RefObject<Target>;\n\nexport type UseEventListener = {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: Window,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: Document,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <\n Target extends UseEventListenerTarget,\n Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap\n >(\n target: Target,\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n};\n\n/**\n * @name useEventListener\n * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter(5);\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (params[1] instanceof Function ? null : params[0]) as\n | UseEventListenerTarget\n | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => void;\n const options: UseEventListenerOptions | undefined = target ? params[3] : params[2];\n\n const internalRef = React.useRef<Element | Document | Window>(null);\n\n React.useEffect(() => {\n const element = target ? getElement(target) : internalRef.current;\n if (element) {\n element.addEventListener(event, listener, options);\n return () => element.removeEventListener(event, listener, options);\n }\n
|
|
1
|
+
{"version":3,"file":"useEventListener.js","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import React from 'react';\n\nexport type UseEventListenerTarget =\n | React.RefObject<Element | null>\n | (() => Element)\n | Element\n | Window\n | Document;\n\nconst getElement = (target: UseEventListenerTarget) => {\n if (typeof target === 'function') {\n return target();\n }\n\n if (target instanceof Element || target instanceof Window || target instanceof Document) {\n return target;\n }\n\n return target.current;\n};\n\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\nexport type UseEventListenerReturn<Target extends UseEventListenerTarget = any> =\n React.RefObject<Target>;\n\nexport type UseEventListener = {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: Window,\n event: Event | Event[],\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: Document,\n event: Event | Event[],\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <\n Target extends UseEventListenerTarget,\n Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap\n >(\n target: Target,\n event: Event | Event[],\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event | Event[],\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n};\n\n/**\n * @name useEventListener\n * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter(5);\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (params[1] instanceof Function ? null : params[0]) as\n | UseEventListenerTarget\n | undefined;\n const event = (target ? params[1] : params[0]) as string | string[];\n const events = Array.isArray(event) ? event : [event];\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => void;\n const options: UseEventListenerOptions | undefined = target ? params[3] : params[2];\n\n const internalRef = React.useRef<Element | Document | Window>(null);\n\n React.useEffect(() => {\n const element = target ? getElement(target) : internalRef.current;\n if (element) {\n events.forEach((event) => element.addEventListener(event, listener, options));\n return () => {\n events.forEach((event) => element.removeEventListener(event, listener, options));\n };\n }\n }, [target, event, listener, options]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","target","arguments","length","undefined","Function","event","events","Array","isArray","listener","options","internalRef","React","useRef","useEffect","element","Element","Window","Document","current","getElement","forEach","addEventListener","removeEventListener"],"mappings":";qBASA,IAyDaA,EAAoB,WAC/B,IAAMC,GAAUC,UAAAC,QAAA,OAAAC,EAAAF,UAAA,cAAqBG,SAAW,KAAIH,UAAAC,QAAAC,OAAAA,EAAAF,UAEvC,GACPI,EAASL,EAAMC,UAAAC,QAAAC,OAAAA,EAAAF,UAAA,GAAAA,UAAAC,eAAAC,EAAAF,UAA8C,GAC7DK,EAASC,MAAMC,QAAQH,GAASA,EAAQ,CAACA,GACzCI,EAAYT,EAAMC,UAAAC,QAAAC,OAAAA,EAAAF,UAAA,GAAAA,UAAAC,eAAAC,EAAAF,UAAoD,GACtES,EAA+CV,EAAMC,UAAAC,QAAAC,OAAAA,EAAAF,UAAA,GAAAA,UAAAC,eAAAC,EAAAF,UAAwB,GAE7EU,EAAcC,EAAMC,OAAoC,MAY9D,GAVAD,EAAME,WAAU,WACd,IAAMC,EAAUf,EArED,SAACA,GAClB,MAAsB,mBAAXA,EACFA,IAGLA,aAAkBgB,SAAWhB,aAAkBiB,QAAUjB,aAAkBkB,SACtElB,EAGFA,EAAOmB,OAChB,CA2D6BC,CAAWpB,GAAUW,EAAYQ,QAC1D,GAAIJ,EAEF,OADAT,EAAOe,SAAQ,SAAChB,GAAK,OAAKU,EAAQO,iBAAiBjB,EAAOI,EAAUC,MAC7D,WACLJ,EAAOe,SAAQ,SAAChB,GAAK,OAAKU,EAAQQ,oBAAoBlB,EAAOI,EAAUC,MAG5E,GAAE,CAACV,EAAQK,EAAOI,EAAUC,KAEzBV,EACJ,OAAOW,CACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import n from"react";import{useEventListener as t}from"../useEventListener/useEventListener.js";var l=function(){var l=(arguments.length<=0?void 0:arguments[0])instanceof Function?null:arguments.length<=0?void 0:arguments[0],o=l?arguments.length<=1?void 0:arguments[1]:arguments.length<=0?void 0:arguments[0],r=n.useState(!1),u=e(r,2),i=u[0],s=u[1],v=n.useRef(null);return t(null!=l?l:v,"mouseenter",(function(){null==o||o(),s(!0)})),t(null!=l?l:v,"mouseleave",(function(){return s(!1)})),l?i:[v,i]};export{l as useHover};
|
|
3
3
|
//# sourceMappingURL=useHover.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import e from"react";import{isClient as t}from"../../utils/helpers/isClient.js";var r=t?e.useLayoutEffect:e.useEffect;export{r as useIsomorphicLayoutEffect};
|
|
3
3
|
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import r from"react";import{useEventListener as n}from"../useEventListener/useEventListener.js";var i=function(i,t){var o,u,l=r.useState(!1),s=e(l,2),a=s[0],y=s[1];return n(null!==(o=null==t?void 0:t.target)&&void 0!==o?o:window,"keydown",(function(e){(Array.isArray(i)?i.includes(e.key):e.key===i)&&y(!0)})),n(null!==(u=null==t?void 0:t.target)&&void 0!==u?u:window,"keyup",(function(e){(Array.isArray(i)?i.includes(e.key):e.key===i)&&y(!1)})),a};export{i as useKeyPress};
|
|
3
3
|
//# sourceMappingURL=useKeyPress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyPress.js","sources":["../../../../src/hooks/useKeyPress/useKeyPress.ts"],"sourcesContent":["import React from 'react';\n\nimport type { UseEventListenerTarget } from '../useEventListener/useEventListener';\nimport { useEventListener } from '../useEventListener/useEventListener';\n\nexport type UseKeyPressKey = string | string[];\n\nexport type UseKeyPressOptions = {\n target
|
|
1
|
+
{"version":3,"file":"useKeyPress.js","sources":["../../../../src/hooks/useKeyPress/useKeyPress.ts"],"sourcesContent":["import React from 'react';\n\nimport type { UseEventListenerTarget } from '../useEventListener/useEventListener';\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/** The key or keys to listen for */\nexport type UseKeyPressKey = string | string[];\n\n/** The use key press options */\nexport type UseKeyPressOptions = {\n /** The target to attach the event listeners to */\n target?: UseEventListenerTarget;\n};\n\n/**\n * @name useKeyPress\n * @description - Hook that listens for key press events\n *\n * @param {UseKeyPressKey} key The key or keys to listen for\n * @param {UseEventListenerTarget} [options.target=window] The target to attach the event listeners to\n * @returns {useKeyPressReturns} Return boolean type (`true` if the specified keys are currently pressed)\n *\n * @example\n * const isKeyPressed = useKeyPress('a');\n */\nexport const useKeyPress = (key: UseKeyPressKey, options?: UseKeyPressOptions) => {\n const [pressed, setPressed] = React.useState(false);\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (Array.isArray(key) ? key.includes(event.key) : event.key === key) setPressed(true);\n };\n\n const onKeyUp = (event: KeyboardEvent) => {\n if (Array.isArray(key) ? key.includes(event.key) : event.key === key) setPressed(false);\n };\n\n useEventListener(options?.target ?? window, 'keydown', onKeyDown);\n useEventListener(options?.target ?? window, 'keyup', onKeyUp);\n\n return pressed;\n};\n"],"names":["useKeyPress","key","options","_options$target","_options$target2","_React$useState","React","useState","_React$useState2","_slicedToArray","pressed","setPressed","useEventListener","target","window","event","Array","isArray","includes"],"mappings":";gKAyBO,IAAMA,EAAc,SAACC,EAAqBC,GAAiC,IAAAC,EAAAC,EAChFC,EAA8BC,EAAMC,UAAS,GAAMC,EAAAC,EAAAJ,EAAA,GAA5CK,EAAOF,EAAA,GAAEG,EAAUH,EAAA,GAa1B,OAHAI,UAAgBT,EAACD,aAAO,EAAPA,EAASW,cAAM,IAAAV,EAAAA,EAAIW,OAAQ,WAR1B,SAACC,IACbC,MAAMC,QAAQhB,GAAOA,EAAIiB,SAASH,EAAMd,KAAOc,EAAMd,MAAQA,IAAKU,GAAW,MAQnFC,UAAgBR,EAACF,aAAO,EAAPA,EAASW,cAAM,IAAAT,EAAAA,EAAIU,OAAQ,SAL5B,SAACC,IACXC,MAAMC,QAAQhB,GAAOA,EAAIiB,SAASH,EAAMd,KAAOc,EAAMd,MAAQA,IAAKU,GAAW,MAM5ED,CACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import{useEventListener as n}from"../useEventListener/useEventListener.js";import"react";var e=function(){var e=Array.isArray(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:[arguments.length<=0?void 0:arguments[0]],t=(arguments.length<=1?void 0:arguments[1])instanceof Function?null:arguments.length<=1?void 0:arguments[1],i=t?arguments.length<=2?void 0:arguments[2]:arguments.length<=1?void 0:arguments[1];n(null!=t?t:window,"keydown",(function(n){e.includes(n.key)&&i(n)}),t?arguments.length<=3?void 0:arguments[3]:arguments.length<=2?void 0:arguments[2])};export{e as useKeyPressEvent};
|
|
3
3
|
//# sourceMappingURL=useKeyPressEvent.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e,
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e,c as n}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import o from"react";import{useEventListener as t}from"../useEventListener/useEventListener.js";var r=function(r){var u,i,c,l=null===(u=null==r?void 0:r.enabled)||void 0===u||u,d=o.useState([]),f=e(d,2),s=f[0],a=f[1];return o.useEffect((function(){a([])}),[l]),t(null!==(i=null==r?void 0:r.target)&&void 0!==i?i:window,"keydown",(function(e){l&&a((function(o){return o.some((function(n){return n.code===e.code}))?o:[].concat(n(o),[{key:e.key,code:e.code}])}))})),t(null!==(c=null==r?void 0:r.target)&&void 0!==c?c:window,"keyup",(function(e){l&&a((function(n){return n.filter((function(n){return n.code!==e.code}))}))})),s};export{r as useKeysPressed};
|
|
3
3
|
//# sourceMappingURL=useKeysPressed.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeysPressed.js","sources":["../../../../src/hooks/useKeysPressed/useKeysPressed.ts"],"sourcesContent":["import React from 'react';\n\nimport type { UseEventListenerTarget } from '../useEventListener/useEventListener';\nimport { useEventListener } from '../useEventListener/useEventListener';\n\nexport const useKeysPressed = (
|
|
1
|
+
{"version":3,"file":"useKeysPressed.js","sources":["../../../../src/hooks/useKeysPressed/useKeysPressed.ts"],"sourcesContent":["import React from 'react';\n\nimport type { UseEventListenerTarget } from '../useEventListener/useEventListener';\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/** The use keys pressed params */\ninterface UseKeysPressedParams {\n /** The target to attach the event listeners to */\n target?: UseEventListenerTarget;\n\n /** Enable or disable the event listeners */\n enabled?: boolean;\n}\n\n/**\n * @name useKeysPressed\n * @description - Hook that listens for key press events\n *\n * @param {UseEventListenerTarget} [params.target=window] The target to attach the event listeners to\n * @param {boolean} [params.enabled=bollean] Enable or disable the event listeners\n * @returns {useKeysPressedReturns} Array of strings with keys that were press\n *\n * @example\n * const pressedKeys = useKeysPressed();\n */\nexport const useKeysPressed = (params?: UseKeysPressedParams) => {\n const enabled = params?.enabled ?? true;\n const [keys, setKeys] = React.useState<{ key: string; code: string }[]>([]);\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (!enabled) return;\n setKeys((prevKeys) => {\n if (prevKeys.some(({ code }) => code === event.code)) return prevKeys;\n return [...prevKeys, { key: event.key, code: event.code }];\n });\n };\n\n const onKeyUp = (event: KeyboardEvent) => {\n if (!enabled) return;\n setKeys((prevKeys) => prevKeys.filter(({ code }) => code !== event.code));\n };\n\n React.useEffect(() => {\n setKeys([]);\n }, [enabled]);\n\n useEventListener(params?.target ?? window, 'keydown', onKeyDown);\n useEventListener(params?.target ?? window, 'keyup', onKeyUp);\n\n return keys;\n};\n"],"names":["useKeysPressed","params","_params$enabled","_params$target","_params$target2","enabled","_React$useState","React","useState","_React$useState2","_slicedToArray","keys","setKeys","useEffect","useEventListener","target","window","event","prevKeys","some","_ref","code","concat","_toConsumableArray","key","filter","_ref2"],"mappings":";2KAyBaA,EAAiB,SAACC,GAAkC,IAAAC,EAAAC,EAAAC,EACzDC,EAAyBH,QAAlBA,EAAGD,aAAM,EAANA,EAAQI,eAAOH,IAAAA,GAAAA,EAC/BI,EAAwBC,EAAMC,SAA0C,IAAGC,EAAAC,EAAAJ,EAAA,GAApEK,EAAIF,EAAA,GAAEG,EAAOH,EAAA,GAsBpB,OAPAF,EAAMM,WAAU,WACdD,EAAQ,GACV,GAAG,CAACP,IAEJS,UAAgBX,EAACF,aAAM,EAANA,EAAQc,cAAM,IAAAZ,EAAAA,EAAIa,OAAQ,WAjBzB,SAACC,GACZZ,GACLO,GAAQ,SAACM,GACP,OAAIA,EAASC,MAAK,SAAAC,GAAO,OAAAA,EAAJC,OAAoBJ,EAAMI,QAAcH,EAC7D,GAAAI,OAAAC,EAAWL,GAAU,CAAA,CAAEM,IAAKP,EAAMO,IAAKH,KAAMJ,EAAMI,OACrD,OAaFP,UAAgBV,EAACH,aAAM,EAANA,EAAQc,cAAM,IAAAX,EAAAA,EAAIY,OAAQ,SAV3B,SAACC,GACVZ,GACLO,GAAQ,SAACM,GAAQ,OAAKA,EAASO,QAAO,SAAAC,GAAO,OAAAA,EAAJL,OAAoBJ,EAAMI,cAU9DV,CACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{a as r}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{a as r}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import{useStorage as o}from"../useStorage/useStorage.js";import"react";var e=function(e,a,t){return o(e,r({initialValue:a,storage:window.localStorage},t))};export{e as useLocalStorage};
|
|
3
3
|
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.js","sources":["../../../../src/hooks/useLocalStorage/useLocalStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\nimport { useStorage } from '../useStorage/useStorage';\n\nexport const useLocalStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: UseStorageOptions<Value>\n) => useStorage(key, initialValue,
|
|
1
|
+
{"version":3,"file":"useLocalStorage.js","sources":["../../../../src/hooks/useLocalStorage/useLocalStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\nimport { useStorage } from '../useStorage/useStorage';\n\nexport const useLocalStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: UseStorageOptions<Value>\n) => useStorage(key, { initialValue, storage: window.localStorage, ...options });\n"],"names":["useLocalStorage","key","initialValue","options","useStorage","_objectSpread","storage","window","localStorage"],"mappings":";uIAGO,IAAMA,EAAkB,SAC7BC,EACAC,EACAC,GAAkC,OAC/BC,EAAWH,EAAGI,EAAA,CAAIH,aAAAA,EAAcI,QAASC,OAAOC,cAAiBL,GAAU"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import r from"react";function e(e,n,t){var u=r.useRef(),c=r.useRef(null);return r.useEffect((function(){var r="function"==typeof t?t():t;return(r||c.current)&&(u.current=new MutationObserver(e),u.current.observe(r||c.current,n)),function(){var r;null===(r=u.current)||void 0===r||r.disconnect()}}),[e,n]),c}export{e as useMutationObserver};
|
|
3
3
|
//# sourceMappingURL=useMutationObserver.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import n from"react";import"../../utils/helpers/isClient.js";import{isShallowEqual as e}from"../../utils/helpers/isShallowEqual.js";var i=function(){var n,e,i;return(null===(n=navigator)||void 0===n?void 0:n.connection)||(null===(e=navigator)||void 0===e?void 0:e.mozConnection)||(null===(i=navigator)||void 0===i?void 0:i.webkitConnection)},o=function(n){window.addEventListener("online",n,{passive:!0}),window.addEventListener("offline",n,{passive:!0});var e=i();return e&&e.addEventListener("change",n,{passive:!0}),function(){window.removeEventListener("online",n),window.removeEventListener("offline",n),e&&e.removeEventListener("change",n)}},t=function(){throw Error("useNetwork is a client side hook")},r=function(){var r=n.useRef();return n.useSyncExternalStore(o,(function(){var n=navigator.onLine,o=i(),t={online:n,downlink:null==o?void 0:o.downlink,downlinkMax:null==o?void 0:o.downlinkMax,effectiveType:null==o?void 0:o.effectiveType,rtt:null==o?void 0:o.rtt,saveData:null==o?void 0:o.saveData,type:null==o?void 0:o.type};return r.current&&e(r.current,t)?r.current:(r.current=t,t)}),t)};export{i as getConnection,r as useNetwork};
|
|
3
3
|
//# sourceMappingURL=useNetwork.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNetwork.js","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import React from 'react';\n\nimport { isShallowEqual } from '@/utils/helpers';\n\nexport type ConnectionType = Connection['type'];\nexport type ConnectionEffectiveType = Connection['effectiveType'];\nexport interface UseNetworkReturn {\n online: boolean;\n downlink?: Connection['downlink'];\n downlinkMax?: Connection['downlinkMax'];\n effectiveType?: Connection['effectiveType'];\n rtt?: Connection['rtt'];\n saveData?: Connection['saveData'];\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n};\n\nconst getServerSnapshot = () => {\n throw Error('useNetwork is a client side hook');\n};\n\nexport const useNetwork = (): UseNetworkReturn => {\n const cache = React.useRef<UseNetworkReturn>();\n\n const getSnapshot = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n const nextState = {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n\n if (cache.current && isShallowEqual(cache.current as any, nextState)) {\n return cache.current;\n }\n\n cache.current = nextState;\n return nextState;\n };\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"names":["getConnection","_navigator","_navigator2","_navigator3","navigator","connection","mozConnection","webkitConnection","subscribe","callback","window","addEventListener","passive","removeEventListener","getServerSnapshot","Error","useNetwork","cache","React","useRef","useSyncExternalStore","online","onLine","nextState","downlink","downlinkMax","effectiveType","rtt","saveData","type","current","isShallowEqual"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useNetwork.js","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import React from 'react';\n\nimport { isShallowEqual } from '@/utils/helpers';\n\nexport type ConnectionType = Connection['type'];\nexport type ConnectionEffectiveType = Connection['effectiveType'];\n\n/** The use network return type */\nexport interface UseNetworkReturn {\n /** Indicates if the device is currently online */\n online: boolean;\n /** The estimated downlink speed in megabits per seconds */\n downlink?: Connection['downlink'];\n /** The maximum downlink speed, if available */\n downlinkMax?: Connection['downlinkMax'];\n /** The effective type of connection (e.g., '2g', '3g', '4g') */\n effectiveType?: Connection['effectiveType'];\n /** The estimated round-trip time in milliseconds */\n rtt?: Connection['rtt'];\n /** Indicates if the user has enabled data saving mode */\n saveData?: Connection['saveData'];\n /** The type of network connection (e.g., 'wifi', 'cellular') */\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n};\n\nconst getServerSnapshot = () => {\n throw Error('useNetwork is a client side hook');\n};\n\n/**\n * @name useNetwork\n * @description - Hook to track network status.\n *\n * @returns {UseNetworkReturn} An object containing the network status.\n *\n * @example\n * const network = useNetwork();\n */\nexport const useNetwork = (): UseNetworkReturn => {\n const cache = React.useRef<UseNetworkReturn>();\n\n const getSnapshot = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n const nextState = {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n\n if (cache.current && isShallowEqual(cache.current as any, nextState)) {\n return cache.current;\n }\n\n cache.current = nextState;\n return nextState;\n };\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"names":["getConnection","_navigator","_navigator2","_navigator3","navigator","connection","mozConnection","webkitConnection","subscribe","callback","window","addEventListener","passive","removeEventListener","getServerSnapshot","Error","useNetwork","cache","React","useRef","useSyncExternalStore","online","onLine","nextState","downlink","downlinkMax","effectiveType","rtt","saveData","type","current","isShallowEqual"],"mappings":";oIAyBaA,IAAAA,EAAgB,WAAH,IAAAC,EAAAC,EAAAC,EAAA,OACfF,QAATA,EAAAG,iBAAAH,IAASA,OAATA,EAAAA,EAAWI,cAAuBH,QAAbA,EAAIE,iBAAAF,IAASA,OAATA,EAAAA,EAAWI,iBAA0BH,QAAbA,EAAIC,iBAAAD,IAASA,OAATA,EAAAA,EAAWI,iBAAgB,EAE5EC,EAAY,SAACC,GACjBC,OAAOC,iBAAiB,SAAUF,EAAU,CAAEG,SAAS,IACvDF,OAAOC,iBAAiB,UAAWF,EAAU,CAAEG,SAAS,IAExD,IAAMP,EAAaL,IAMnB,OAJIK,GACFA,EAAWM,iBAAiB,SAAUF,EAAU,CAAEG,SAAS,IAGtD,WACLF,OAAOG,oBAAoB,SAAUJ,GACrCC,OAAOG,oBAAoB,UAAWJ,GAElCJ,GACFA,EAAWQ,oBAAoB,SAAUJ,GAG/C,EAEMK,EAAoB,WACxB,MAAMC,MAAM,mCACd,EAWaC,EAAa,WACxB,IAAMC,EAAQC,EAAMC,SAwBpB,OAAOD,EAAME,qBAAqBZ,GAtBd,WAClB,IAAMa,EAASjB,UAAUkB,OACnBjB,EAAaL,IAEbuB,EAAY,CAChBF,OAAAA,EACAG,SAAUnB,aAAAA,EAAAA,EAAYmB,SACtBC,YAAapB,aAAAA,EAAAA,EAAYoB,YACzBC,cAAerB,aAAAA,EAAAA,EAAYqB,cAC3BC,IAAKtB,aAAAA,EAAAA,EAAYsB,IACjBC,SAAUvB,aAAAA,EAAAA,EAAYuB,SACtBC,KAAMxB,aAAU,EAAVA,EAAYwB,MAGpB,OAAIZ,EAAMa,SAAWC,EAAed,EAAMa,QAAgBP,GACjDN,EAAMa,SAGfb,EAAMa,QAAUP,EACTA,KAGiDT,EAC5D"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import r from"react";import{useIsomorphicLayoutEffect as t}from"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";import"../../utils/helpers/isClient.js";var o=function(o,e){var i=r.useRef(!0);t((function(){if(!i.current){var r=o();return r&&"function"==typeof r?r:void 0}i.current=!1}),e)};export{o as useNonInitialEffect};
|
|
3
3
|
//# sourceMappingURL=useNonInitialEffect.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import n from"react";var e=function(){return navigator.onLine},t=function(){return!1},r=function(n){return window.addEventListener("online",n),window.addEventListener("offline",n),function(){window.removeEventListener("online",n),window.removeEventListener("offline",n)}},o=function(){return n.useSyncExternalStore(r,e,t)};export{o as useOnline};
|
|
3
3
|
//# sourceMappingURL=useOnline.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{_ as e}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{_ as e}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import{useState as n}from"react";import{useIsomorphicLayoutEffect as r}from"../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";import"../../utils/helpers/isClient.js";var o=function(){var o=n({angle:0,type:"landscape-primary"}),t=e(o,2),i=t[0],a=t[1];return r((function(){var e,n=function(){var e=window.screen.orientation,n=e.angle,r=e.type;a({angle:n,type:r})};return null===(e=window.screen.orientation)||void 0===e||e.addEventListener("change",n),function(){var e;return null===(e=window.screen.orientation)||void 0===e?void 0:e.removeEventListener("change",n)}}),[]),i};export{o as useOrientation};
|
|
3
3
|
//# sourceMappingURL=useOrientation.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
2
|
import r from"react";var e=function(){var e=r.useRef(0);return r.useEffect((function(){e.current+=1})),e.current};export{e as useRenderCount};
|
|
3
3
|
//# sourceMappingURL=useRenderCount.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import{a as r}from"../../_rollupPluginBabelHelpers-
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{a as r}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import{useStorage as e}from"../useStorage/useStorage.js";import"react";var o=function(o,t,a){return e(o,r({initialValue:t,storage:window.sessionStorage},a))};export{o as useSessionStorage};
|
|
3
3
|
//# sourceMappingURL=useSessionStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorage.js","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\nimport { useStorage } from '../useStorage/useStorage';\n\nexport const useSessionStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: UseStorageOptions<Value>\n) => useStorage(key, initialValue,
|
|
1
|
+
{"version":3,"file":"useSessionStorage.js","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\nimport { useStorage } from '../useStorage/useStorage';\n\nexport const useSessionStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: UseStorageOptions<Value>\n) => useStorage(key, { initialValue, storage: window.sessionStorage, ...options });\n"],"names":["useSessionStorage","key","initialValue","options","useStorage","_objectSpread","storage","window","sessionStorage"],"mappings":";uIAGO,IAAMA,EAAoB,SAC/BC,EACAC,EACAC,GAAkC,OAC/BC,EAAWH,EAAGI,EAAA,CAAIH,aAAAA,EAAcI,QAASC,OAAOC,gBAAmBL,GAAU"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.
|
|
2
|
-
import e from"react";var
|
|
1
|
+
/* @license @siberiacancode/reactuse v0.0.3 */
|
|
2
|
+
import{b as e}from"../../_rollupPluginBabelHelpers-CVdsimvi.js";import n from"react";var r=function(e){return window.dispatchEvent(new StorageEvent("storage",e))},t=function(e,n,t){var i=e.getItem(n);e.setItem(n,t),r({key:n,oldValue:i,newValue:t,storageArea:e})},i=function(e,n){var t=e.getItem(n);e.removeItem(n),r({key:n,oldValue:t,newValue:null,storageArea:e})},o=function(e,n,r){var t=e.getItem(n);if(t)return r(t)},u=function(e){return window.addEventListener("storage",e),function(){return window.removeEventListener("storage",e)}},a=function(r,a){var l,f="object"===e(a)?a:void 0,c=f?null==f?void 0:f.initialValue:a,s=null!==(l=null==f?void 0:f.storage)&&void 0!==l?l:window.localStorage,d=function(e){return null!=f&&f.serializer?f.serializer(e):JSON.stringify(e)},v=function(e){if(null!=f&&f.deserializer)return f.deserializer(e);if("undefined"!==e)try{return JSON.parse(e)}catch(n){return e}},g=n.useSyncExternalStore(u,(function(){return o(s,r,v)}),(function(){return function(e){return e instanceof Function?e():e}(c)}));n.useEffect((function(){if(void 0===o(s,r,v)&&c){var e=c instanceof Function?c():c;t(s,r,d(e))}}),[r]);return[g,function(e){if(null===e)return i(s,r);t(s,r,d(e))},function(){return i(s,r)}]};export{r as dispatchStorageEvent,a as useStorage};
|
|
3
3
|
//# sourceMappingURL=useStorage.js.map
|