@willbooster/shared-lib-react 3.2.3 → 3.2.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/hooks/useInterval.cjs.map +1 -1
- package/dist/hooks/useInterval.d.ts +1 -1
- package/dist/hooks/useInterval.js.map +1 -1
- package/dist/hooks/useLocalStorage.cjs.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts +1 -1
- package/dist/hooks/useLocalStorage.js.map +1 -1
- package/dist/hooks/useSessionStorage.cjs.map +1 -1
- package/dist/hooks/useSessionStorage.d.ts +1 -1
- package/dist/hooks/useSessionStorage.js.map +1 -1
- package/dist/hooks/useStorage.cjs +1 -1
- package/dist/hooks/useStorage.cjs.map +1 -1
- package/dist/hooks/useStorage.d.ts +2 -2
- package/dist/hooks/useStorage.js +1 -1
- package/dist/hooks/useStorage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterval.cjs","sources":["../../src/hooks/useInterval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport function useInterval(
|
|
1
|
+
{"version":3,"file":"useInterval.cjs","sources":["../../src/hooks/useInterval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport function useInterval(nonReactiveCallback: () => void, milliseconds: number): () => void {\n const timerId = useRef<number>();\n\n const clearInterval = useCallback(() => {\n window.clearInterval(timerId.current);\n }, []);\n\n useEffect(() => {\n timerId.current = window.setInterval(nonReactiveCallback, milliseconds);\n return clearInterval;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [milliseconds]);\n\n return clearInterval;\n}\n"],"names":["nonReactiveCallback","milliseconds","timerId","useRef","clearInterval","useCallback","window","current","useEffect","setInterval"],"mappings":"wDAEO,SAAqBA,EAAiCC,GAC3D,MAAMC,EAAUC,EAAAA,SAEVC,EAAgBC,EAAAA,aAAY,KAChCC,OAAOF,cAAcF,EAAQK,QAAQ,GACpC,IAQH,OANAC,EAAAA,WAAU,KACRN,EAAQK,QAAUD,OAAOG,YAAYT,EAAqBC,GACnDG,IAEN,CAACH,IAEGG,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useInterval(
|
|
1
|
+
export declare function useInterval(nonReactiveCallback: () => void, milliseconds: number): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterval.js","sources":["../../src/hooks/useInterval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport function useInterval(
|
|
1
|
+
{"version":3,"file":"useInterval.js","sources":["../../src/hooks/useInterval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport function useInterval(nonReactiveCallback: () => void, milliseconds: number): () => void {\n const timerId = useRef<number>();\n\n const clearInterval = useCallback(() => {\n window.clearInterval(timerId.current);\n }, []);\n\n useEffect(() => {\n timerId.current = window.setInterval(nonReactiveCallback, milliseconds);\n return clearInterval;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [milliseconds]);\n\n return clearInterval;\n}\n"],"names":["useInterval","nonReactiveCallback","milliseconds","timerId","useRef","clearInterval","useCallback","window","current","useEffect","setInterval"],"mappings":"+DAEO,SAASA,EAAYC,EAAiCC,GAC3D,MAAMC,EAAUC,IAEVC,EAAgBC,GAAY,KAChCC,OAAOF,cAAcF,EAAQK,QAAQ,GACpC,IAQH,OANAC,GAAU,KACRN,EAAQK,QAAUD,OAAOG,YAAYT,EAAqBC,GACnDG,IAEN,CAACH,IAEGG,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.cjs","sources":["../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n
|
|
1
|
+
{"version":3,"file":"useLocalStorage.cjs","sources":["../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n return useStorage('localStorage', key, initialValue, nonReactiveOptions);\n}\n"],"names":["key","initialValue","nonReactiveOptions","useStorage"],"mappings":"uEAKO,SACLA,EACAC,EACAC,EAA2C,CAAA,GAE3C,OAAOC,EAAUA,WAAC,eAAgBH,EAAKC,EAAcC,EACvD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { UseStorageOptions } from './useStorage.js';
|
|
3
|
-
export declare function useLocalStorage<T>(key: string, initialValue: T,
|
|
3
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T, nonReactiveOptions?: UseStorageOptions<T>): [T, React.Dispatch<React.SetStateAction<T>>];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.js","sources":["../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n
|
|
1
|
+
{"version":3,"file":"useLocalStorage.js","sources":["../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n return useStorage('localStorage', key, initialValue, nonReactiveOptions);\n}\n"],"names":["useLocalStorage","key","initialValue","nonReactiveOptions","useStorage"],"mappings":"6CAKO,SAASA,EACdC,EACAC,EACAC,EAA2C,CAAA,GAE3C,OAAOC,EAAW,eAAgBH,EAAKC,EAAcC,EACvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorage.cjs","sources":["../../src/hooks/useSessionStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useSessionStorage<T>(\n key: string,\n initialValue: T,\n
|
|
1
|
+
{"version":3,"file":"useSessionStorage.cjs","sources":["../../src/hooks/useSessionStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useSessionStorage<T>(\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n return useStorage('sessionStorage', key, initialValue, nonReactiveOptions);\n}\n"],"names":["key","initialValue","nonReactiveOptions","useStorage"],"mappings":"yEAKO,SACLA,EACAC,EACAC,EAA2C,CAAA,GAE3C,OAAOC,EAAUA,WAAC,iBAAkBH,EAAKC,EAAcC,EACzD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { UseStorageOptions } from './useStorage.js';
|
|
3
|
-
export declare function useSessionStorage<T>(key: string, initialValue: T,
|
|
3
|
+
export declare function useSessionStorage<T>(key: string, initialValue: T, nonReactiveOptions?: UseStorageOptions<T>): [T, React.Dispatch<React.SetStateAction<T>>];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorage.js","sources":["../../src/hooks/useSessionStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useSessionStorage<T>(\n key: string,\n initialValue: T,\n
|
|
1
|
+
{"version":3,"file":"useSessionStorage.js","sources":["../../src/hooks/useSessionStorage.ts"],"sourcesContent":["import type React from 'react';\n\nimport type { UseStorageOptions } from './useStorage.js';\nimport { useStorage } from './useStorage.js';\n\nexport function useSessionStorage<T>(\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n return useStorage('sessionStorage', key, initialValue, nonReactiveOptions);\n}\n"],"names":["useSessionStorage","key","initialValue","nonReactiveOptions","useStorage"],"mappings":"6CAKO,SAASA,EACdC,EACAC,EACAC,EAA2C,CAAA,GAE3C,OAAOC,EAAW,iBAAkBH,EAAKC,EAAcC,EACzD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react");function t(e){return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}exports.useStorage=function(n,r,s,o={}){const i=e.useSyncExternalStore(t,(()=>
|
|
1
|
+
"use strict";var e=require("react");function t(e){return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}exports.useStorage=function(n,r,s,o={}){const i=e.useSyncExternalStore(t,(()=>window[n].getItem(r)),(()=>"ssrJsonText"in o&&o.ssrJsonText)),u=e.useMemo((()=>{try{if(i){const e=JSON.parse(i);return null!=o&&o.parseAfterJsonParse?null==o?void 0:o.parseAfterJsonParse(e):e}}catch(e){}return s}),[i,s]),a=e.useCallback((e=>{try{const t="function"==typeof e?e(u):e;null==t?window[n].removeItem(r):window[n].setItem(r,JSON.stringify(t))}catch(e){console.warn(e)}}),[r,u]);return e.useEffect((()=>{null===window[n].getItem(r)&&void 0!==s&&window[n].setItem(r,JSON.stringify(s))}),[r,s]),[u,a]};
|
|
2
2
|
//# sourceMappingURL=useStorage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.cjs","sources":["../../src/hooks/useStorage.ts"],"sourcesContent":["import type React from 'react';\nimport { useCallback, useEffect, useSyncExternalStore } from 'react';\n\nexport type UseStorageOptions<T> =\n | {\n parseAfterJsonParse?: (value: unknown) => T;\n
|
|
1
|
+
{"version":3,"file":"useStorage.cjs","sources":["../../src/hooks/useStorage.ts"],"sourcesContent":["import type React from 'react';\nimport { useMemo, useCallback, useEffect, useSyncExternalStore } from 'react';\n\nexport type UseStorageOptions<T> =\n | {\n parseAfterJsonParse?: (value: unknown) => T;\n ssrJsonText: string;\n }\n | { parseAfterJsonParse?: (value: unknown) => T };\n\nexport function useStorage<T>(\n nonReactiveStorageType: 'localStorage' | 'sessionStorage',\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n const jsonText = useSyncExternalStore(\n subscribeStorageEvent,\n () => window[nonReactiveStorageType].getItem(key),\n () => 'ssrJsonText' in nonReactiveOptions && nonReactiveOptions.ssrJsonText\n );\n const value = useMemo(() => {\n try {\n if (jsonText) {\n const json = JSON.parse(jsonText);\n return nonReactiveOptions?.parseAfterJsonParse ? nonReactiveOptions?.parseAfterJsonParse(json) : json;\n }\n } catch {\n // do nothing\n }\n return initialValue;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [jsonText, initialValue]);\n\n const setState = useCallback(\n (valueOrFunc: T | ((prevState: T) => T)) => {\n try {\n const nextState = typeof valueOrFunc === 'function' ? (valueOrFunc as (prevState: T) => T)(value) : valueOrFunc;\n\n if (nextState === undefined || nextState === null) {\n window[nonReactiveStorageType].removeItem(key);\n } else {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(nextState));\n }\n } catch (error) {\n console.warn(error);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [key, value]\n );\n\n useEffect(() => {\n if (window[nonReactiveStorageType].getItem(key) === null && initialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(initialValue));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, initialValue]);\n\n return [value, setState];\n}\n\nfunction subscribeStorageEvent(callback: (this: Window, ev: StorageEvent) => unknown) {\n window.addEventListener('storage', callback);\n return () => window.removeEventListener('storage', callback);\n}\n"],"names":["subscribeStorageEvent","callback","window","addEventListener","removeEventListener","nonReactiveStorageType","key","initialValue","nonReactiveOptions","jsonText","useSyncExternalStore","getItem","ssrJsonText","value","useMemo","json","JSON","parse","parseAfterJsonParse","_unused","setState","useCallback","valueOrFunc","nextState","removeItem","setItem","stringify","error","console","warn","useEffect","undefined"],"mappings":"oCA8DA,SAASA,EAAsBC,GAE7B,OADAC,OAAOC,iBAAiB,UAAWF,GAC5B,IAAMC,OAAOE,oBAAoB,UAAWH,EACrD,oBAvDO,SACLI,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EAAoBA,qBACnCV,GACA,IAAME,OAAOG,GAAwBM,QAAQL,KAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBI,cAE5DC,EAAQC,EAAAA,SAAQ,KACpB,IACE,GAAIL,EAAU,CACZ,MAAMM,EAAOC,KAAKC,MAAMR,GACxB,OAAyB,MAAlBD,GAAAA,EAAoBU,oBAAsBV,MAAAA,OAAAA,EAAAA,EAAoBU,oBAAoBH,GAAQA,CACnG,CACD,CAAC,MAAAI,GACA,CAEF,OAAOZ,CAAY,GAElB,CAACE,EAAUF,IAERa,EAAWC,EAAWA,aACzBC,IACC,IACE,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCT,GAASS,EAEhGC,QACFrB,OAAOG,GAAwBmB,WAAWlB,GAE1CJ,OAAOG,GAAwBoB,QAAQnB,EAAKU,KAAKU,UAAUH,GAE9D,CAAC,MAAOI,GACPC,QAAQC,KAAKF,EACf,IAGF,CAACrB,EAAKO,IAUR,OAPAiB,EAAAA,WAAU,KAC4C,OAAhD5B,OAAOG,GAAwBM,QAAQL,SAAkCyB,IAAjBxB,GAC1DL,OAAOG,GAAwBoB,QAAQnB,EAAKU,KAAKU,UAAUnB,GAC7D,GAEC,CAACD,EAAKC,IAEF,CAACM,EAAOO,EACjB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
export type UseStorageOptions<T> = {
|
|
3
3
|
parseAfterJsonParse?: (value: unknown) => T;
|
|
4
|
-
|
|
4
|
+
ssrJsonText: string;
|
|
5
5
|
} | {
|
|
6
6
|
parseAfterJsonParse?: (value: unknown) => T;
|
|
7
7
|
};
|
|
8
|
-
export declare function useStorage<T>(
|
|
8
|
+
export declare function useStorage<T>(nonReactiveStorageType: 'localStorage' | 'sessionStorage', key: string, initialValue: T, nonReactiveOptions?: UseStorageOptions<T>): [T, React.Dispatch<React.SetStateAction<T>>];
|
package/dist/hooks/useStorage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useSyncExternalStore as e,useCallback as
|
|
1
|
+
import{useSyncExternalStore as t,useMemo as e,useCallback as n,useEffect as r}from"react";function o(o,i,w,a={}){const c=t(s,(()=>window[o].getItem(i)),(()=>"ssrJsonText"in a&&a.ssrJsonText)),d=e((()=>{try{if(c){const t=JSON.parse(c);return null!=a&&a.parseAfterJsonParse?null==a?void 0:a.parseAfterJsonParse(t):t}}catch(t){}return w}),[c,w]),u=n((t=>{try{const e="function"==typeof t?t(d):t;null==e?window[o].removeItem(i):window[o].setItem(i,JSON.stringify(e))}catch(t){console.warn(t)}}),[i,d]);return r((()=>{null===window[o].getItem(i)&&void 0!==w&&window[o].setItem(i,JSON.stringify(w))}),[i,w]),[d,u]}function s(t){return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)}export{o as useStorage};
|
|
2
2
|
//# sourceMappingURL=useStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.js","sources":["../../src/hooks/useStorage.ts"],"sourcesContent":["import type React from 'react';\nimport { useCallback, useEffect, useSyncExternalStore } from 'react';\n\nexport type UseStorageOptions<T> =\n | {\n parseAfterJsonParse?: (value: unknown) => T;\n
|
|
1
|
+
{"version":3,"file":"useStorage.js","sources":["../../src/hooks/useStorage.ts"],"sourcesContent":["import type React from 'react';\nimport { useMemo, useCallback, useEffect, useSyncExternalStore } from 'react';\n\nexport type UseStorageOptions<T> =\n | {\n parseAfterJsonParse?: (value: unknown) => T;\n ssrJsonText: string;\n }\n | { parseAfterJsonParse?: (value: unknown) => T };\n\nexport function useStorage<T>(\n nonReactiveStorageType: 'localStorage' | 'sessionStorage',\n key: string,\n initialValue: T,\n nonReactiveOptions: UseStorageOptions<T> = {}\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n const jsonText = useSyncExternalStore(\n subscribeStorageEvent,\n () => window[nonReactiveStorageType].getItem(key),\n () => 'ssrJsonText' in nonReactiveOptions && nonReactiveOptions.ssrJsonText\n );\n const value = useMemo(() => {\n try {\n if (jsonText) {\n const json = JSON.parse(jsonText);\n return nonReactiveOptions?.parseAfterJsonParse ? nonReactiveOptions?.parseAfterJsonParse(json) : json;\n }\n } catch {\n // do nothing\n }\n return initialValue;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [jsonText, initialValue]);\n\n const setState = useCallback(\n (valueOrFunc: T | ((prevState: T) => T)) => {\n try {\n const nextState = typeof valueOrFunc === 'function' ? (valueOrFunc as (prevState: T) => T)(value) : valueOrFunc;\n\n if (nextState === undefined || nextState === null) {\n window[nonReactiveStorageType].removeItem(key);\n } else {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(nextState));\n }\n } catch (error) {\n console.warn(error);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [key, value]\n );\n\n useEffect(() => {\n if (window[nonReactiveStorageType].getItem(key) === null && initialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(initialValue));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, initialValue]);\n\n return [value, setState];\n}\n\nfunction subscribeStorageEvent(callback: (this: Window, ev: StorageEvent) => unknown) {\n window.addEventListener('storage', callback);\n return () => window.removeEventListener('storage', callback);\n}\n"],"names":["useStorage","nonReactiveStorageType","key","initialValue","nonReactiveOptions","jsonText","useSyncExternalStore","subscribeStorageEvent","window","getItem","ssrJsonText","value","useMemo","json","JSON","parse","parseAfterJsonParse","_unused","setState","useCallback","valueOrFunc","nextState","removeItem","setItem","stringify","error","console","warn","useEffect","undefined","callback","addEventListener","removeEventListener"],"mappings":"0FAUO,SAASA,EACdC,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EACfC,GACA,IAAMC,OAAOP,GAAwBQ,QAAQP,KAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBM,cAE5DC,EAAQC,GAAQ,KACpB,IACE,GAAIP,EAAU,CACZ,MAAMQ,EAAOC,KAAKC,MAAMV,GACxB,OAAyB,MAAlBD,GAAAA,EAAoBY,oBAAsBZ,MAAAA,OAAAA,EAAAA,EAAoBY,oBAAoBH,GAAQA,CACnG,CACD,CAAC,MAAAI,GACA,CAEF,OAAOd,CAAY,GAElB,CAACE,EAAUF,IAERe,EAAWC,GACdC,IACC,IACE,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCT,GAASS,EAEhGC,QACFb,OAAOP,GAAwBqB,WAAWpB,GAE1CM,OAAOP,GAAwBsB,QAAQrB,EAAKY,KAAKU,UAAUH,GAE9D,CAAC,MAAOI,GACPC,QAAQC,KAAKF,EACf,IAGF,CAACvB,EAAKS,IAUR,OAPAiB,GAAU,KAC4C,OAAhDpB,OAAOP,GAAwBQ,QAAQP,SAAkC2B,IAAjB1B,GAC1DK,OAAOP,GAAwBsB,QAAQrB,EAAKY,KAAKU,UAAUrB,GAC7D,GAEC,CAACD,EAAKC,IAEF,CAACQ,EAAOO,EACjB,CAEA,SAASX,EAAsBuB,GAE7B,OADAtB,OAAOuB,iBAAiB,UAAWD,GAC5B,IAAMtB,OAAOwB,oBAAoB,UAAWF,EACrD"}
|