@willbooster/shared-lib-react 4.0.5 → 4.1.1

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");exports.useStorage=function(t,n,s,o={}){const r=e.useSyncExternalStore(e=>{const t=t=>{t.key===n&&e()};return globalThis.addEventListener("storage",t),()=>{globalThis.removeEventListener("storage",t)}},()=>window[t].getItem(n),()=>"ssrJsonText"in o&&o.ssrJsonText),i=e.useMemo(()=>{try{if(r){var e,t;const n=JSON.parse(r);return null!=(e=null==(t=o.parseAfterJsonParse)?void 0:t.call(o,n))?e:n}}catch(e){}return"function"==typeof s?s():s},[r,s]),l=e.useCallback(e=>{const s="function"==typeof e?e(i):e;let o=null;null==s?window[t].removeItem(n):(o=JSON.stringify(s),window[t].setItem(n,o)),globalThis.dispatchEvent(new StorageEvent("storage",{key:n,newValue:o}))},[n,i]);return e.useEffect(()=>{const e="function"==typeof s?s():s;null===window[t].getItem(n)&&void 0!==e&&window[t].setItem(n,JSON.stringify(e))},[n,s]),[i,l]};
1
+ "use strict";var e=require("react");exports.useStorage=function(t,n,s,o={}){const r=e.useSyncExternalStore(e=>{const t=t=>{t.key===n&&e()};return globalThis.addEventListener("storage",t),()=>{globalThis.removeEventListener("storage",t)}},()=>window[t].getItem(n),()=>"ssrJsonText"in o&&o.ssrJsonText),i=e.useMemo(()=>{try{if(r){var e,t;const n=JSON.parse(r),s=null!=(e=null==(t=o.parseAfterJsonParse)?void 0:t.call(o,n))?e:n;if(!o.validValues||o.validValues.has(s))return s}}catch(e){}return"function"==typeof s?s():s},[r,s]),a=e.useCallback(e=>{const s="function"==typeof e?e(i):e;let o=null;null==s?window[t].removeItem(n):(o=JSON.stringify(s),window[t].setItem(n,o)),globalThis.dispatchEvent(new StorageEvent("storage",{key:n,newValue:o}))},[n,i]);return e.useEffect(()=>{const e="function"==typeof s?s():s;null===window[t].getItem(n)&&void 0!==e&&window[t].setItem(n,JSON.stringify(e))},[n,s]),[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 initialValueOrFunc: T | (() => 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 globalThis.addEventListener('storage', newCallback);\n return () => {\n globalThis.removeEventListener('storage', newCallback);\n };\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) as unknown as T;\n return nonReactiveOptions.parseAfterJsonParse?.(json) ?? json;\n }\n } catch {\n // do nothing\n }\n return typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n }, [jsonText, initialValueOrFunc]); // Don't add nonReactiveOptions to deps because it's not allowed to change.\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 globalThis.dispatchEvent(new StorageEvent('storage', { key, newValue }));\n },\n\n [key, value] // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n );\n\n useEffect(() => {\n const resolvedInitialValue =\n typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n if (window[nonReactiveStorageType].getItem(key) === null && resolvedInitialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(resolvedInitialValue));\n }\n }, [key, initialValueOrFunc]); // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n\n return [value, setState];\n}\n"],"names":["nonReactiveStorageType","key","initialValueOrFunc","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","globalThis","addEventListener","removeEventListener","window","getItem","ssrJsonText","value","useMemo","_nonReactiveOptions$p","_nonReactiveOptions$p2","json","JSON","parse","parseAfterJsonParse","call","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","resolvedInitialValue","undefined"],"mappings":"uDAUO,SACLA,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EAAAA,qBACdC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,KAGzB,OADAG,WAAWC,iBAAiB,UAAWH,GAChC,KACLE,WAAWE,oBAAoB,UAAWJ,KAG9C,IAAMK,OAAOZ,GAAwBa,QAAQZ,GAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBW,aAE5DC,EAAQC,EAAAA,QAAQ,KACpB,IACE,GAAIZ,EAAU,CAAA,IAAAa,EAAAC,EACZ,MAAMC,EAAOC,KAAKC,MAAMjB,GACxB,OAAqD,OAArDa,EAA6C,OAA7CC,EAAOf,EAAmBmB,0BAAmB,EAAtCJ,EAAAK,KAAApB,EAAyCgB,IAAKF,EAAIE,CAC3D,CACF,CAAE,MAAAK,GACA,CAEF,MAAqC,mBAAvBtB,EAAqCA,IAAmCA,GACrF,CAACE,EAAUF,IAERuB,EAAWC,EAAAA,YACdC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCZ,GAASY,EAGpG,IAAIE,EAA0B,KAC1BD,QACFhB,OAAOZ,GAAwB8B,WAAW7B,IAE1C4B,EAAWT,KAAKW,UAAUH,GAC1BhB,OAAOZ,GAAwBgC,QAAQ/B,EAAK4B,IAE9CpB,WAAWwB,cAAc,IAAIC,aAAa,UAAW,CAAEjC,MAAK4B,eAG9D,CAAC5B,EAAKc,IAWR,OARAoB,EAAAA,UAAU,KACR,MAAMC,EAC0B,mBAAvBlC,EAAqCA,IAAmCA,EAC7B,OAAhDU,OAAOZ,GAAwBa,QAAQZ,SAA0CoC,IAAzBD,GAC1DxB,OAAOZ,GAAwBgC,QAAQ/B,EAAKmB,KAAKW,UAAUK,KAE5D,CAACnC,EAAKC,IAEF,CAACa,EAAOU,EACjB"}
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 parseAfterJsonParse?: (value: unknown) => T;\n ssrJsonText?: string;\n validValues?: Set<T>;\n};\n\nexport function useStorage<T>(\n nonReactiveStorageType: 'localStorage' | 'sessionStorage',\n key: string,\n initialValueOrFunc: T | (() => 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 globalThis.addEventListener('storage', newCallback);\n return () => {\n globalThis.removeEventListener('storage', newCallback);\n };\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) as unknown as T;\n const value = nonReactiveOptions.parseAfterJsonParse?.(json) ?? json;\n if (!nonReactiveOptions.validValues || nonReactiveOptions.validValues.has(value)) return value;\n }\n } catch {\n // do nothing\n }\n return typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n }, [jsonText, initialValueOrFunc]); // Don't add nonReactiveOptions to deps because it's not allowed to change.\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 globalThis.dispatchEvent(new StorageEvent('storage', { key, newValue }));\n },\n\n [key, value] // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n );\n\n useEffect(() => {\n const resolvedInitialValue =\n typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n if (window[nonReactiveStorageType].getItem(key) === null && resolvedInitialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(resolvedInitialValue));\n }\n }, [key, initialValueOrFunc]); // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n\n return [value, setState];\n}\n"],"names":["nonReactiveStorageType","key","initialValueOrFunc","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","globalThis","addEventListener","removeEventListener","window","getItem","ssrJsonText","value","useMemo","_nonReactiveOptions$p","_nonReactiveOptions$p2","json","JSON","parse","parseAfterJsonParse","call","validValues","has","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","resolvedInitialValue","undefined"],"mappings":"uDASO,SACLA,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EAAAA,qBACdC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,KAGzB,OADAG,WAAWC,iBAAiB,UAAWH,GAChC,KACLE,WAAWE,oBAAoB,UAAWJ,KAG9C,IAAMK,OAAOZ,GAAwBa,QAAQZ,GAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBW,aAE5DC,EAAQC,EAAAA,QAAQ,KACpB,IACE,GAAIZ,EAAU,CAAA,IAAAa,EAAAC,EACZ,MAAMC,EAAOC,KAAKC,MAAMjB,GAClBW,EAAsD,OAAjDE,EAAyC,OAAzCC,EAAGf,EAAmBmB,0BAAmB,EAAtCJ,EAAAK,KAAApB,EAAyCgB,IAAKF,EAAIE,EAChE,IAAKhB,EAAmBqB,aAAerB,EAAmBqB,YAAYC,IAAIV,GAAQ,OAAOA,CAC3F,CACF,CAAE,MAAAW,GACA,CAEF,MAAqC,mBAAvBxB,EAAqCA,IAAmCA,GACrF,CAACE,EAAUF,IAERyB,EAAWC,EAAAA,YACdC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCd,GAASc,EAGpG,IAAIE,EAA0B,KAC1BD,QACFlB,OAAOZ,GAAwBgC,WAAW/B,IAE1C8B,EAAWX,KAAKa,UAAUH,GAC1BlB,OAAOZ,GAAwBkC,QAAQjC,EAAK8B,IAE9CtB,WAAW0B,cAAc,IAAIC,aAAa,UAAW,CAAEnC,MAAK8B,eAG9D,CAAC9B,EAAKc,IAWR,OARAsB,EAAAA,UAAU,KACR,MAAMC,EAC0B,mBAAvBpC,EAAqCA,IAAmCA,EAC7B,OAAhDU,OAAOZ,GAAwBa,QAAQZ,SAA0CsC,IAAzBD,GAC1D1B,OAAOZ,GAAwBkC,QAAQjC,EAAKmB,KAAKa,UAAUK,KAE5D,CAACrC,EAAKC,IAEF,CAACa,EAAOY,EACjB"}
@@ -1,8 +1,7 @@
1
1
  import type React from 'react';
2
2
  export type UseStorageOptions<T> = {
3
3
  parseAfterJsonParse?: (value: unknown) => T;
4
- ssrJsonText: string;
5
- } | {
6
- parseAfterJsonParse?: (value: unknown) => T;
4
+ ssrJsonText?: string;
5
+ validValues?: Set<T>;
7
6
  };
8
7
  export declare function useStorage<T>(nonReactiveStorageType: 'localStorage' | 'sessionStorage', key: string, initialValueOrFunc: T | (() => T), nonReactiveOptions?: UseStorageOptions<T>): [T, React.Dispatch<React.SetStateAction<T>>];
@@ -1,2 +1,2 @@
1
- import{useSyncExternalStore as t,useMemo as e,useCallback as n,useEffect as o}from"react";function r(r,s,i,l={}){const a=t(t=>{const e=e=>{e.key===s&&t()};return globalThis.addEventListener("storage",e),()=>{globalThis.removeEventListener("storage",e)}},()=>window[r].getItem(s),()=>"ssrJsonText"in l&&l.ssrJsonText),c=e(()=>{try{if(a){var t,e;const n=JSON.parse(a);return null!=(t=null==(e=l.parseAfterJsonParse)?void 0:e.call(l,n))?t:n}}catch(t){}return"function"==typeof i?i():i},[a,i]),u=n(t=>{const e="function"==typeof t?t(c):t;let n=null;null==e?window[r].removeItem(s):(n=JSON.stringify(e),window[r].setItem(s,n)),globalThis.dispatchEvent(new StorageEvent("storage",{key:s,newValue:n}))},[s,c]);return o(()=>{const t="function"==typeof i?i():i;null===window[r].getItem(s)&&void 0!==t&&window[r].setItem(s,JSON.stringify(t))},[s,i]),[c,u]}export{r as useStorage};
1
+ import{useSyncExternalStore as e,useMemo as t,useCallback as n,useEffect as o}from"react";function s(s,r,i,l={}){const a=e(e=>{const t=t=>{t.key===r&&e()};return globalThis.addEventListener("storage",t),()=>{globalThis.removeEventListener("storage",t)}},()=>window[s].getItem(r),()=>"ssrJsonText"in l&&l.ssrJsonText),u=t(()=>{try{if(a){var e,t;const n=JSON.parse(a),o=null!=(e=null==(t=l.parseAfterJsonParse)?void 0:t.call(l,n))?e:n;if(!l.validValues||l.validValues.has(o))return o}}catch(e){}return"function"==typeof i?i():i},[a,i]),c=n(e=>{const t="function"==typeof e?e(u):e;let n=null;null==t?window[s].removeItem(r):(n=JSON.stringify(t),window[s].setItem(r,n)),globalThis.dispatchEvent(new StorageEvent("storage",{key:r,newValue:n}))},[r,u]);return o(()=>{const e="function"==typeof i?i():i;null===window[s].getItem(r)&&void 0!==e&&window[s].setItem(r,JSON.stringify(e))},[r,i]),[u,c]}export{s 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 initialValueOrFunc: T | (() => 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 globalThis.addEventListener('storage', newCallback);\n return () => {\n globalThis.removeEventListener('storage', newCallback);\n };\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) as unknown as T;\n return nonReactiveOptions.parseAfterJsonParse?.(json) ?? json;\n }\n } catch {\n // do nothing\n }\n return typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n }, [jsonText, initialValueOrFunc]); // Don't add nonReactiveOptions to deps because it's not allowed to change.\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 globalThis.dispatchEvent(new StorageEvent('storage', { key, newValue }));\n },\n\n [key, value] // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n );\n\n useEffect(() => {\n const resolvedInitialValue =\n typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n if (window[nonReactiveStorageType].getItem(key) === null && resolvedInitialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(resolvedInitialValue));\n }\n }, [key, initialValueOrFunc]); // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n\n return [value, setState];\n}\n"],"names":["useStorage","nonReactiveStorageType","key","initialValueOrFunc","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","globalThis","addEventListener","removeEventListener","window","getItem","ssrJsonText","value","useMemo","_nonReactiveOptions$p","_nonReactiveOptions$p2","json","JSON","parse","parseAfterJsonParse","call","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","resolvedInitialValue","undefined"],"mappings":"0FAUO,SAASA,EACdC,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EACdC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,KAGzB,OADAG,WAAWC,iBAAiB,UAAWH,GAChC,KACLE,WAAWE,oBAAoB,UAAWJ,KAG9C,IAAMK,OAAOZ,GAAwBa,QAAQZ,GAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBW,aAE5DC,EAAQC,EAAQ,KACpB,IACE,GAAIZ,EAAU,CAAA,IAAAa,EAAAC,EACZ,MAAMC,EAAOC,KAAKC,MAAMjB,GACxB,OAAqD,OAArDa,EAA6C,OAA7CC,EAAOf,EAAmBmB,0BAAmB,EAAtCJ,EAAAK,KAAApB,EAAyCgB,IAAKF,EAAIE,CAC3D,CACF,CAAE,MAAAK,GACA,CAEF,MAAqC,mBAAvBtB,EAAqCA,IAAmCA,GACrF,CAACE,EAAUF,IAERuB,EAAWC,EACdC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCZ,GAASY,EAGpG,IAAIE,EAA0B,KAC1BD,QACFhB,OAAOZ,GAAwB8B,WAAW7B,IAE1C4B,EAAWT,KAAKW,UAAUH,GAC1BhB,OAAOZ,GAAwBgC,QAAQ/B,EAAK4B,IAE9CpB,WAAWwB,cAAc,IAAIC,aAAa,UAAW,CAAEjC,MAAK4B,eAG9D,CAAC5B,EAAKc,IAWR,OARAoB,EAAU,KACR,MAAMC,EAC0B,mBAAvBlC,EAAqCA,IAAmCA,EAC7B,OAAhDU,OAAOZ,GAAwBa,QAAQZ,SAA0CoC,IAAzBD,GAC1DxB,OAAOZ,GAAwBgC,QAAQ/B,EAAKmB,KAAKW,UAAUK,KAE5D,CAACnC,EAAKC,IAEF,CAACa,EAAOU,EACjB"}
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 parseAfterJsonParse?: (value: unknown) => T;\n ssrJsonText?: string;\n validValues?: Set<T>;\n};\n\nexport function useStorage<T>(\n nonReactiveStorageType: 'localStorage' | 'sessionStorage',\n key: string,\n initialValueOrFunc: T | (() => 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 globalThis.addEventListener('storage', newCallback);\n return () => {\n globalThis.removeEventListener('storage', newCallback);\n };\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) as unknown as T;\n const value = nonReactiveOptions.parseAfterJsonParse?.(json) ?? json;\n if (!nonReactiveOptions.validValues || nonReactiveOptions.validValues.has(value)) return value;\n }\n } catch {\n // do nothing\n }\n return typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n }, [jsonText, initialValueOrFunc]); // Don't add nonReactiveOptions to deps because it's not allowed to change.\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 globalThis.dispatchEvent(new StorageEvent('storage', { key, newValue }));\n },\n\n [key, value] // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n );\n\n useEffect(() => {\n const resolvedInitialValue =\n typeof initialValueOrFunc === 'function' ? (initialValueOrFunc as () => T)() : initialValueOrFunc;\n if (window[nonReactiveStorageType].getItem(key) === null && resolvedInitialValue !== undefined) {\n window[nonReactiveStorageType].setItem(key, JSON.stringify(resolvedInitialValue));\n }\n }, [key, initialValueOrFunc]); // Don't add nonReactiveStorageType to deps because it's not allowed to change.\n\n return [value, setState];\n}\n"],"names":["useStorage","nonReactiveStorageType","key","initialValueOrFunc","nonReactiveOptions","jsonText","useSyncExternalStore","callback","newCallback","event","globalThis","addEventListener","removeEventListener","window","getItem","ssrJsonText","value","useMemo","_nonReactiveOptions$p","_nonReactiveOptions$p2","json","JSON","parse","parseAfterJsonParse","call","validValues","has","_unused","setState","useCallback","valueOrFunc","nextState","newValue","removeItem","stringify","setItem","dispatchEvent","StorageEvent","useEffect","resolvedInitialValue","undefined"],"mappings":"0FASO,SAASA,EACdC,EACAC,EACAC,EACAC,EAA2C,CAAA,GAE3C,MAAMC,EAAWC,EACdC,IACC,MAAMC,EAAeC,IACfA,EAAMP,MAAQA,GAAKK,KAGzB,OADAG,WAAWC,iBAAiB,UAAWH,GAChC,KACLE,WAAWE,oBAAoB,UAAWJ,KAG9C,IAAMK,OAAOZ,GAAwBa,QAAQZ,GAC7C,IAAM,gBAAiBE,GAAsBA,EAAmBW,aAE5DC,EAAQC,EAAQ,KACpB,IACE,GAAIZ,EAAU,CAAA,IAAAa,EAAAC,EACZ,MAAMC,EAAOC,KAAKC,MAAMjB,GAClBW,EAAsD,OAAjDE,EAAyC,OAAzCC,EAAGf,EAAmBmB,0BAAmB,EAAtCJ,EAAAK,KAAApB,EAAyCgB,IAAKF,EAAIE,EAChE,IAAKhB,EAAmBqB,aAAerB,EAAmBqB,YAAYC,IAAIV,GAAQ,OAAOA,CAC3F,CACF,CAAE,MAAAW,GACA,CAEF,MAAqC,mBAAvBxB,EAAqCA,IAAmCA,GACrF,CAACE,EAAUF,IAERyB,EAAWC,EACdC,IACC,MAAMC,EAAmC,mBAAhBD,EAA8BA,EAAoCd,GAASc,EAGpG,IAAIE,EAA0B,KAC1BD,QACFlB,OAAOZ,GAAwBgC,WAAW/B,IAE1C8B,EAAWX,KAAKa,UAAUH,GAC1BlB,OAAOZ,GAAwBkC,QAAQjC,EAAK8B,IAE9CtB,WAAW0B,cAAc,IAAIC,aAAa,UAAW,CAAEnC,MAAK8B,eAG9D,CAAC9B,EAAKc,IAWR,OARAsB,EAAU,KACR,MAAMC,EAC0B,mBAAvBpC,EAAqCA,IAAmCA,EAC7B,OAAhDU,OAAOZ,GAAwBa,QAAQZ,SAA0CsC,IAAzBD,GAC1D1B,OAAOZ,GAAwBkC,QAAQjC,EAAKmB,KAAKa,UAAUK,KAE5D,CAACrC,EAAKC,IAEF,CAACa,EAAOY,EACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-react",
3
- "version": "4.0.5",
3
+ "version": "4.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -35,25 +35,25 @@
35
35
  },
36
36
  "prettier": "@willbooster/prettier-config",
37
37
  "devDependencies": {
38
- "@babel/core": "7.28.0",
38
+ "@babel/core": "7.28.3",
39
39
  "@mdx-js/react": "3.1.0",
40
40
  "@storybook/addon-actions": "9.0.8",
41
- "@storybook/addon-docs": "9.1.1",
41
+ "@storybook/addon-docs": "9.1.3",
42
42
  "@storybook/addon-essentials": "8.6.14",
43
43
  "@storybook/addon-interactions": "8.6.14",
44
- "@storybook/addon-links": "9.1.1",
44
+ "@storybook/addon-links": "9.1.3",
45
45
  "@storybook/builder-webpack4": "6.5.16",
46
46
  "@storybook/manager-webpack4": "6.5.16",
47
- "@storybook/react": "9.1.1",
47
+ "@storybook/react": "9.1.3",
48
48
  "@storybook/testing-library": "0.2.2",
49
49
  "@types/eslint": "9.6.1",
50
50
  "@types/micromatch": "4.0.9",
51
- "@types/react": "19.1.9",
51
+ "@types/react": "19.1.11",
52
52
  "@types/react-dom": "19.1.7",
53
- "@willbooster/eslint-config-ts-react": "11.5.4",
53
+ "@willbooster/eslint-config-ts-react": "11.5.5",
54
54
  "@willbooster/prettier-config": "10.2.0",
55
55
  "babel-loader": "10.0.0",
56
- "build-ts": "15.0.19",
56
+ "build-ts": "15.0.20",
57
57
  "eslint": "9.33.0",
58
58
  "eslint-config-flat-gitignore": "2.1.0",
59
59
  "eslint-config-prettier": "10.1.8",
@@ -64,9 +64,9 @@
64
64
  "eslint-plugin-react-hooks": "5.2.0",
65
65
  "eslint-plugin-sort-class-members": "1.21.0",
66
66
  "eslint-plugin-sort-destructure-keys": "2.0.0",
67
- "eslint-plugin-storybook": "9.1.1",
67
+ "eslint-plugin-storybook": "9.1.3",
68
68
  "eslint-plugin-unicorn": "60.0.0",
69
- "eslint-plugin-unused-imports": "4.1.4",
69
+ "eslint-plugin-unused-imports": "4.2.0",
70
70
  "globals": "16.3.0",
71
71
  "lint-staged": "16.1.5",
72
72
  "micromatch": "4.0.8",
@@ -76,7 +76,7 @@
76
76
  "react-dom": "19.1.1",
77
77
  "sort-package-json": "3.4.0",
78
78
  "typescript": "5.9.2",
79
- "typescript-eslint": "8.39.0",
79
+ "typescript-eslint": "8.40.0",
80
80
  "vitest": "3.2.4"
81
81
  },
82
82
  "peerDependencies": {