@willbooster/shared-lib-react 3.2.4 → 3.2.6
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react");function t(
|
|
1
|
+
"use strict";var e=require("react");exports.useStorage=function(t,n,r,s={}){const o=e.useSyncExternalStore((e=>{const t=t=>{t.key===n&&e()};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)}),(()=>window[t].getItem(n)),(()=>"ssrJsonText"in s&&s.ssrJsonText)),i=e.useMemo((()=>{try{if(o){const e=JSON.parse(o);return null!=s&&s.parseAfterJsonParse?null==s?void 0:s.parseAfterJsonParse(e):e}}catch(e){}return r}),[o,r]),a=e.useCallback((e=>{const r="function"==typeof e?e(i):e;let s=null;null==r?window[t].removeItem(n):(s=JSON.stringify(r),window[t].setItem(n,s)),window.dispatchEvent(new StorageEvent("storage",{key:n,newValue:s}))}),[n,i]);return e.useEffect((()=>{null===window[t].getItem(n)&&void 0!==r&&window[t].setItem(n,JSON.stringify(r))}),[n,r]),[i,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 { 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
|
|
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 (callback) => {\n const newCallback = (event: StorageEvent): void => {\n if (event.key === key) callback();\n };\n window.addEventListener('storage', newCallback);\n return () => window.removeEventListener('storage', newCallback);\n },\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 const nextState = typeof valueOrFunc === 'function' ? (valueOrFunc as (prevState: T) => T)(value) : valueOrFunc;\n\n // eslint-disable-next-line unicorn/no-null\n let newValue: string | null = null;\n if (nextState === undefined || nextState === null) {\n window[nonReactiveStorageType].removeItem(key);\n } else {\n newValue = JSON.stringify(nextState);\n window[nonReactiveStorageType].setItem(key, newValue);\n }\n window.dispatchEvent(new StorageEvent('storage', { key, newValue }));\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"],"names":["nonReactiveStorageType","key","initialValue","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","window","addEventListener","removeEventListener","getItem","ssrJsonText","value","useMemo","json","JSON","parse","parseAfterJsonParse","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","undefined"],"mappings":"uDAUO,SACLA,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EAAoBA,sBAClCC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,GAAU,EAGnC,OADAG,OAAOC,iBAAiB,UAAWH,GAC5B,IAAME,OAAOE,oBAAoB,UAAWJ,EAAY,IAEjE,IAAME,OAAOT,GAAwBY,QAAQX,KAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBU,cAE5DC,EAAQC,EAAAA,SAAQ,KACpB,IACE,GAAIX,EAAU,CACZ,MAAMY,EAAOC,KAAKC,MAAMd,GACxB,OAAyB,MAAlBD,GAAAA,EAAoBgB,oBAAsBhB,MAAAA,OAAAA,EAAAA,EAAoBgB,oBAAoBH,GAAQA,CACnG,CACD,CAAC,MAAAI,GACA,CAEF,OAAOlB,CAAY,GAElB,CAACE,EAAUF,IAERmB,EAAWC,EAAWA,aACzBC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCT,GAASS,EAGpG,IAAIE,EAA0B,KAC1BD,QACFf,OAAOT,GAAwB0B,WAAWzB,IAE1CwB,EAAWR,KAAKU,UAAUH,GAC1Bf,OAAOT,GAAwB4B,QAAQ3B,EAAKwB,IAE9ChB,OAAOoB,cAAc,IAAIC,aAAa,UAAW,CAAE7B,MAAKwB,aAAY,GAGtE,CAACxB,EAAKa,IAUR,OAPAiB,EAAAA,WAAU,KAC4C,OAAhDtB,OAAOT,GAAwBY,QAAQX,SAAkC+B,IAAjB9B,GAC1DO,OAAOT,GAAwB4B,QAAQ3B,EAAKgB,KAAKU,UAAUzB,GAC7D,GAEC,CAACD,EAAKC,IAEF,CAACY,EAAOO,EACjB"}
|
package/dist/hooks/useStorage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useSyncExternalStore as
|
|
1
|
+
import{useSyncExternalStore as e,useMemo as t,useCallback as n,useEffect as r}from"react";function o(o,s,i,w={}){const a=e((e=>{const t=t=>{t.key===s&&e()};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)}),(()=>window[o].getItem(s)),(()=>"ssrJsonText"in w&&w.ssrJsonText)),d=t((()=>{try{if(a){const e=JSON.parse(a);return null!=w&&w.parseAfterJsonParse?null==w?void 0:w.parseAfterJsonParse(e):e}}catch(e){}return i}),[a,i]),l=n((e=>{const t="function"==typeof e?e(d):e;let n=null;null==t?window[o].removeItem(s):(n=JSON.stringify(t),window[o].setItem(s,n)),window.dispatchEvent(new StorageEvent("storage",{key:s,newValue:n}))}),[s,d]);return r((()=>{null===window[o].getItem(s)&&void 0!==i&&window[o].setItem(s,JSON.stringify(i))}),[s,i]),[d,l]}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 { 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
|
|
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 (callback) => {\n const newCallback = (event: StorageEvent): void => {\n if (event.key === key) callback();\n };\n window.addEventListener('storage', newCallback);\n return () => window.removeEventListener('storage', newCallback);\n },\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 const nextState = typeof valueOrFunc === 'function' ? (valueOrFunc as (prevState: T) => T)(value) : valueOrFunc;\n\n // eslint-disable-next-line unicorn/no-null\n let newValue: string | null = null;\n if (nextState === undefined || nextState === null) {\n window[nonReactiveStorageType].removeItem(key);\n } else {\n newValue = JSON.stringify(nextState);\n window[nonReactiveStorageType].setItem(key, newValue);\n }\n window.dispatchEvent(new StorageEvent('storage', { key, newValue }));\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"],"names":["useStorage","nonReactiveStorageType","key","initialValue","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","window","addEventListener","removeEventListener","getItem","ssrJsonText","value","useMemo","json","JSON","parse","parseAfterJsonParse","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","undefined"],"mappings":"0FAUO,SAASA,EACdC,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,GACdC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,GAAU,EAGnC,OADAG,OAAOC,iBAAiB,UAAWH,GAC5B,IAAME,OAAOE,oBAAoB,UAAWJ,EAAY,IAEjE,IAAME,OAAOT,GAAwBY,QAAQX,KAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBU,cAE5DC,EAAQC,GAAQ,KACpB,IACE,GAAIX,EAAU,CACZ,MAAMY,EAAOC,KAAKC,MAAMd,GACxB,OAAyB,MAAlBD,GAAAA,EAAoBgB,oBAAsBhB,MAAAA,OAAAA,EAAAA,EAAoBgB,oBAAoBH,GAAQA,CACnG,CACD,CAAC,MAAAI,GACA,CAEF,OAAOlB,CAAY,GAElB,CAACE,EAAUF,IAERmB,EAAWC,GACdC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCT,GAASS,EAGpG,IAAIE,EAA0B,KAC1BD,QACFf,OAAOT,GAAwB0B,WAAWzB,IAE1CwB,EAAWR,KAAKU,UAAUH,GAC1Bf,OAAOT,GAAwB4B,QAAQ3B,EAAKwB,IAE9ChB,OAAOoB,cAAc,IAAIC,aAAa,UAAW,CAAE7B,MAAKwB,aAAY,GAGtE,CAACxB,EAAKa,IAUR,OAPAiB,GAAU,KAC4C,OAAhDtB,OAAOT,GAAwBY,QAAQX,SAAkC+B,IAAjB9B,GAC1DO,OAAOT,GAAwB4B,QAAQ3B,EAAKgB,KAAKU,UAAUzB,GAC7D,GAEC,CAACD,EAAKC,IAEF,CAACY,EAAOO,EACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/shared-lib-react",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "WillBooster Inc.",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,21 +35,21 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "7.24.7",
|
|
37
37
|
"@mdx-js/react": "3.0.1",
|
|
38
|
-
"@storybook/addon-actions": "8.1.
|
|
39
|
-
"@storybook/addon-docs": "8.1.
|
|
40
|
-
"@storybook/addon-essentials": "8.1.
|
|
41
|
-
"@storybook/addon-interactions": "8.1.
|
|
42
|
-
"@storybook/addon-links": "8.1.
|
|
38
|
+
"@storybook/addon-actions": "8.1.10",
|
|
39
|
+
"@storybook/addon-docs": "8.1.10",
|
|
40
|
+
"@storybook/addon-essentials": "8.1.10",
|
|
41
|
+
"@storybook/addon-interactions": "8.1.10",
|
|
42
|
+
"@storybook/addon-links": "8.1.10",
|
|
43
43
|
"@storybook/builder-webpack4": "6.5.16",
|
|
44
44
|
"@storybook/manager-webpack4": "6.5.16",
|
|
45
|
-
"@storybook/react": "8.1.
|
|
45
|
+
"@storybook/react": "8.1.10",
|
|
46
46
|
"@storybook/testing-library": "0.2.2",
|
|
47
47
|
"@types/eslint": "8.56.10",
|
|
48
48
|
"@types/micromatch": "4.0.7",
|
|
49
49
|
"@types/react": "18.3.3",
|
|
50
50
|
"@types/react-dom": "18.3.0",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
52
|
-
"@typescript-eslint/parser": "7.
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "7.13.1",
|
|
52
|
+
"@typescript-eslint/parser": "7.13.1",
|
|
53
53
|
"@willbooster/eslint-config-ts-react": "10.2.0",
|
|
54
54
|
"@willbooster/prettier-config": "9.1.2",
|
|
55
55
|
"babel-loader": "9.1.3",
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
"eslint-config-prettier": "9.1.0",
|
|
59
59
|
"eslint-import-resolver-typescript": "3.6.1",
|
|
60
60
|
"eslint-plugin-import": "2.29.1",
|
|
61
|
-
"eslint-plugin-react": "7.34.
|
|
61
|
+
"eslint-plugin-react": "7.34.3",
|
|
62
62
|
"eslint-plugin-react-hooks": "4.6.2",
|
|
63
63
|
"eslint-plugin-sort-class-members": "1.20.0",
|
|
64
64
|
"eslint-plugin-sort-destructure-keys": "2.0.0",
|
|
65
65
|
"eslint-plugin-storybook": "0.8.0",
|
|
66
|
-
"eslint-plugin-unicorn": "
|
|
67
|
-
"lint-staged": "15.2.
|
|
66
|
+
"eslint-plugin-unicorn": "54.0.0",
|
|
67
|
+
"lint-staged": "15.2.7",
|
|
68
68
|
"micromatch": "4.0.7",
|
|
69
|
-
"prettier": "3.3.
|
|
69
|
+
"prettier": "3.3.2",
|
|
70
70
|
"react": "18.3.1",
|
|
71
71
|
"react-dom": "18.3.1",
|
|
72
72
|
"sort-package-json": "2.10.0",
|
|
73
|
-
"typescript": "5.
|
|
73
|
+
"typescript": "5.5.2",
|
|
74
74
|
"vitest": "1.6.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|