foxact 0.2.23 → 0.2.25

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/no-ssr/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";exports.noSSR=r=>{const o=Error(r);throw o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};
1
+ "use strict";const r=r=>{const o=Error(r);return o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};exports.noSSR=o=>{if("undefined"==typeof window)throw r(o)},exports.noSSRError=r;
package/no-ssr/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ /** @private */
2
+ declare const noSSRError: (errorMessage?: string) => Error;
1
3
  /** @see https://foxact.skk.moe/no-ssr */
2
- declare const noSSR: (extraMessage?: string) => never;
4
+ declare const noSSR: (extraMessage?: string) => void;
3
5
 
4
- export { noSSR };
6
+ export { noSSR, noSSRError };
package/no-ssr/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";exports.noSSR=r=>{const o=Error(r);throw o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};
1
+ "use strict";const r=r=>{const o=Error(r);return o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};exports.noSSR=o=>{if("undefined"==typeof window)throw r(o)},exports.noSSRError=r;
package/no-ssr/index.mjs CHANGED
@@ -1 +1 @@
1
- const r=r=>{const o=Error(r);throw o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};export{r as noSSR};
1
+ const r=r=>{const o=Error(r);return o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o},o=o=>{if("undefined"==typeof window)throw r(o)};export{o as noSSR,r as noSSRError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "React Hooks/Utils done right. For browser, SSR, and React Server Components.",
5
5
  "homepage": "https://foxact.skk.moe",
6
6
  "repository": {
@@ -101,14 +101,14 @@
101
101
  "require": "./no-ssr/index.cjs",
102
102
  "default": "./no-ssr/index.js"
103
103
  },
104
- "./create-fixed-array": {
105
- "types": "./create-fixed-array/index.d.ts",
104
+ "./rem": {
105
+ "types": "./rem/index.d.ts",
106
106
  "import": {
107
- "types": "./create-fixed-array/index.d.ts",
108
- "default": "./create-fixed-array/index.mjs"
107
+ "types": "./rem/index.d.ts",
108
+ "default": "./rem/index.mjs"
109
109
  },
110
- "require": "./create-fixed-array/index.cjs",
111
- "default": "./create-fixed-array/index.js"
110
+ "require": "./rem/index.cjs",
111
+ "default": "./rem/index.js"
112
112
  },
113
113
  "./noop": {
114
114
  "types": "./noop/index.d.ts",
@@ -119,15 +119,6 @@
119
119
  "require": "./noop/index.cjs",
120
120
  "default": "./noop/index.js"
121
121
  },
122
- "./rem": {
123
- "types": "./rem/index.d.ts",
124
- "import": {
125
- "types": "./rem/index.d.ts",
126
- "default": "./rem/index.mjs"
127
- },
128
- "require": "./rem/index.cjs",
129
- "default": "./rem/index.js"
130
- },
131
122
  "./request-idle-callback": {
132
123
  "types": "./request-idle-callback/index.d.ts",
133
124
  "import": {
@@ -137,6 +128,15 @@
137
128
  "require": "./request-idle-callback/index.cjs",
138
129
  "default": "./request-idle-callback/index.js"
139
130
  },
131
+ "./create-fixed-array": {
132
+ "types": "./create-fixed-array/index.d.ts",
133
+ "import": {
134
+ "types": "./create-fixed-array/index.d.ts",
135
+ "default": "./create-fixed-array/index.mjs"
136
+ },
137
+ "require": "./create-fixed-array/index.cjs",
138
+ "default": "./create-fixed-array/index.js"
139
+ },
140
140
  "./typescript-happy-forward-ref": {
141
141
  "types": "./typescript-happy-forward-ref/index.d.ts",
142
142
  "import": {
@@ -191,15 +191,6 @@
191
191
  "require": "./use-debounced-state/index.cjs",
192
192
  "default": "./use-debounced-state/index.js"
193
193
  },
194
- "./use-debounced-value": {
195
- "types": "./use-debounced-value/index.d.ts",
196
- "import": {
197
- "types": "./use-debounced-value/index.d.ts",
198
- "default": "./use-debounced-value/index.mjs"
199
- },
200
- "require": "./use-debounced-value/index.cjs",
201
- "default": "./use-debounced-value/index.js"
202
- },
203
194
  "./use-error-boundary": {
204
195
  "types": "./use-error-boundary/index.d.ts",
205
196
  "import": {
@@ -218,14 +209,14 @@
218
209
  "require": "./use-intersection/index.cjs",
219
210
  "default": "./use-intersection/index.js"
220
211
  },
221
- "./use-is-client": {
222
- "types": "./use-is-client/index.d.ts",
212
+ "./use-debounced-value": {
213
+ "types": "./use-debounced-value/index.d.ts",
223
214
  "import": {
224
- "types": "./use-is-client/index.d.ts",
225
- "default": "./use-is-client/index.mjs"
215
+ "types": "./use-debounced-value/index.d.ts",
216
+ "default": "./use-debounced-value/index.mjs"
226
217
  },
227
- "require": "./use-is-client/index.cjs",
228
- "default": "./use-is-client/index.js"
218
+ "require": "./use-debounced-value/index.cjs",
219
+ "default": "./use-debounced-value/index.js"
229
220
  },
230
221
  "./use-isomorphic-layout-effect": {
231
222
  "types": "./use-isomorphic-layout-effect/index.d.ts",
@@ -263,6 +254,15 @@
263
254
  "require": "./use-next-pathname/index.cjs",
264
255
  "default": "./use-next-pathname/index.js"
265
256
  },
257
+ "./use-is-client": {
258
+ "types": "./use-is-client/index.d.ts",
259
+ "import": {
260
+ "types": "./use-is-client/index.d.ts",
261
+ "default": "./use-is-client/index.mjs"
262
+ },
263
+ "require": "./use-is-client/index.cjs",
264
+ "default": "./use-is-client/index.js"
265
+ },
266
266
  "./use-react-router-enable-concurrent-navigation": {
267
267
  "types": "./use-react-router-enable-concurrent-navigation/index.d.ts",
268
268
  "import": {
package/sizes.json CHANGED
@@ -1 +1 @@
1
- {"total":{"raw":12820,"gzip":8125,"br":0},"exports":{"compose-context-provider":{"raw":165,"gzip":150,"br":118},"context-state":{"raw":378,"gzip":243,"br":210},"create-context-state":{"raw":146,"gzip":116,"br":102},"no-ssr":{"raw":122,"gzip":129,"br":109},"noop":{"raw":34,"gzip":54,"br":38},"create-fixed-array":{"raw":101,"gzip":105,"br":89},"typescript-happy-forward-ref":{"raw":120,"gzip":104,"br":95},"use":{"raw":277,"gzip":185,"br":155},"request-idle-callback":{"raw":411,"gzip":232,"br":179},"rem":{"raw":589,"gzip":331,"br":285},"use-array":{"raw":338,"gzip":247,"br":207},"use-debounced-state":{"raw":410,"gzip":291,"br":247},"use-composition-input":{"raw":455,"gzip":282,"br":240},"use-clipboard":{"raw":1076,"gzip":617,"br":533},"use-debounced-value":{"raw":471,"gzip":313,"br":254},"use-error-boundary":{"raw":245,"gzip":197,"br":173},"use-isomorphic-layout-effect":{"raw":179,"gzip":145,"br":115},"use-is-client":{"raw":152,"gzip":144,"br":122},"use-intersection":{"raw":1239,"gzip":659,"br":605},"use-map":{"raw":355,"gzip":249,"br":213},"use-next-pathname":{"raw":322,"gzip":242,"br":202},"use-local-storage":{"raw":1285,"gzip":599,"br":515},"use-retimer":{"raw":201,"gzip":168,"br":127},"use-react-router-is-match":{"raw":569,"gzip":371,"br":313},"use-set":{"raw":356,"gzip":243,"br":208},"use-singleton":{"raw":139,"gzip":131,"br":104},"use-react-router-enable-concurrent-navigation":{"raw":956,"gzip":455,"br":382},"use-uncontrolled":{"raw":301,"gzip":232,"br":197},"use-url-hash-state":{"raw":961,"gzip":565,"br":487},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":467,"gzip":326,"br":257}}}
1
+ {"total":{"raw":13233,"gzip":8322,"br":0},"exports":{"compose-context-provider":{"raw":165,"gzip":150,"br":118},"context-state":{"raw":378,"gzip":243,"br":210},"no-ssr":{"raw":187,"gzip":172,"br":143},"noop":{"raw":34,"gzip":54,"br":38},"rem":{"raw":589,"gzip":331,"br":285},"request-idle-callback":{"raw":411,"gzip":232,"br":179},"typescript-happy-forward-ref":{"raw":120,"gzip":104,"br":95},"use":{"raw":277,"gzip":185,"br":155},"create-fixed-array":{"raw":101,"gzip":105,"br":89},"use-array":{"raw":338,"gzip":247,"br":207},"use-composition-input":{"raw":455,"gzip":282,"br":240},"create-context-state":{"raw":146,"gzip":116,"br":102},"use-error-boundary":{"raw":245,"gzip":197,"br":173},"use-debounced-state":{"raw":410,"gzip":291,"br":247},"use-debounced-value":{"raw":471,"gzip":313,"br":254},"use-isomorphic-layout-effect":{"raw":179,"gzip":145,"br":115},"use-clipboard":{"raw":1076,"gzip":617,"br":533},"use-map":{"raw":355,"gzip":249,"br":213},"use-is-client":{"raw":152,"gzip":144,"br":122},"use-next-pathname":{"raw":322,"gzip":242,"br":202},"use-react-router-is-match":{"raw":569,"gzip":371,"br":313},"use-react-router-enable-concurrent-navigation":{"raw":956,"gzip":455,"br":382},"use-retimer":{"raw":201,"gzip":168,"br":127},"use-set":{"raw":356,"gzip":243,"br":208},"use-singleton":{"raw":139,"gzip":131,"br":104},"use-intersection":{"raw":1239,"gzip":659,"br":605},"use-uncontrolled":{"raw":301,"gzip":232,"br":197},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":467,"gzip":326,"br":257},"use-local-storage":{"raw":1633,"gzip":753,"br":660},"use-url-hash-state":{"raw":961,"gzip":565,"br":487}}}
@@ -1 +1 @@
1
- "use strict";var e=require("react"),n=require("../noop/index.cjs"),o=require("../use-isomorphic-layout-effect/index.cjs"),t=require("../no-ssr/index.cjs");function r(e,n){"undefined"!=typeof window&&window.dispatchEvent(new StorageEvent("storage",{key:e,newValue:n}))}require("client-only");const i=(e,n)=>{if("undefined"!=typeof window){const o=JSON.stringify(n);try{window.localStorage.setItem(e,o)}catch(e){console.error(e)}finally{r(e,o)}}},l=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{r(e,null)}},c=e=>{if("undefined"!=typeof window)try{return window.localStorage.getItem(e)}catch(e){console.warn(e)}return null},s=e=>"undefined"!=typeof window?(window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)):n.noop,a=()=>t.noSSR("foxact: useLocalStorage without `serverValue` will only be used at client side."),u=e=>"function"==typeof e;exports.useLocalStorage=(n,t)=>{const r=void 0!==t?()=>JSON.stringify(t):a,d=e.useSyncExternalStore(s,()=>c(n),r),w=e.useCallback(e=>{try{const o=u(e)?e(null!=d?JSON.parse(d):null):e;null==o?l(n):i(n,o)}catch(e){console.warn(e)}},[n,d]);return o.useIsomorphicLayoutEffect(()=>{null===c(n)&&void 0!==t&&i(n,t)},[n,t]),[null!=d?JSON.parse(d):t,w]};
1
+ "use strict";require("client-only");var e=require("react"),n=require("../noop/index.cjs"),o=require("../use-isomorphic-layout-effect/index.cjs"),r=require("../no-ssr/index.cjs");const t="foxact-local-storage",i=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(t,{detail:e}))},l=(e,n,o)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,o(n))}catch(e){console.error(e)}finally{i(e)}},a=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{i(e)}},s=(e,n)=>{if("undefined"==typeof window)return null;try{const o=window.localStorage.getItem(e);return null===o?null:n(o)}catch(e){return console.warn(e),null}},u=()=>{throw r.noSSRError("useLocalStorage cannot be used on the server without a serverValue")},c=e=>"function"==typeof e,d=e=>e;exports.useLocalStorage=function(r,i){var w;let f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const y=e.useCallback(e=>{if("undefined"==typeof window)return n.noop;const o=n=>{"key"in n&&n.key!==r||e()},i=n=>{n.detail===r&&e()};return window.addEventListener("storage",o),window.addEventListener(t,i),()=>{window.removeEventListener("storage",o),window.removeEventListener(t,i)}},[r]),v=f.raw?d:f.serializer,p=f.raw?d:f.deserializer,g=void 0!==i?()=>i:u,h=e.useSyncExternalStore(y,()=>s(r,p),g),S=e.useCallback(e=>{try{const n=c(e)?e(null!=h?h:null):e;null===n?a(r):l(r,n,v)}catch(e){console.warn(e)}},[r,v,h]);return o.useIsomorphicLayoutEffect(()=>{null===s(r,p)&&void 0!==i&&l(r,i,v)},[p,r,v,i]),[null!==(w=null!=h?h:i)&&void 0!==w?w:null,S]};
@@ -1,4 +1,24 @@
1
+ import * as react from 'react';
2
+
3
+ declare const FOXACT_LOCAL_STORAGE_EVENT_KEY = "foxact-local-storage";
4
+ type CustomStorageEvent = CustomEvent<string>;
5
+ declare global {
6
+ interface WindowEventMap {
7
+ [FOXACT_LOCAL_STORAGE_EVENT_KEY]: CustomStorageEvent;
8
+ }
9
+ }
10
+ type Serializer<T> = (value: T) => string;
11
+ type Deserializer<T> = (value: string) => T;
12
+ interface UseLocalStorageRawOption {
13
+ raw: true;
14
+ }
15
+ interface UseLocalStorageParserOption<T> {
16
+ raw?: false;
17
+ serializer: Serializer<T>;
18
+ deserializer: Deserializer<T>;
19
+ }
20
+ type NotUndefined<T> = T extends undefined ? never : T;
1
21
  /** @see https://foxact.skk.moe/use-local-storage */
2
- declare const useLocalStorage: <T extends string | number>(key: string, serverValue?: T | undefined) => any[];
22
+ declare function useLocalStorage<T>(key: string, serverValue?: NotUndefined<T> | undefined, options?: UseLocalStorageRawOption | UseLocalStorageParserOption<T>): readonly [NonNullable<T> | null, react.Dispatch<react.SetStateAction<T | null>>];
3
23
 
4
- export { useLocalStorage };
24
+ export { type Deserializer, type Serializer, type UseLocalStorageParserOption, type UseLocalStorageRawOption, useLocalStorage };
@@ -1 +1 @@
1
- "use strict";var e=require("react"),n=require("../noop/index.js"),o=require("../use-isomorphic-layout-effect/index.js"),t=require("../no-ssr/index.js");function r(e,n){"undefined"!=typeof window&&window.dispatchEvent(new StorageEvent("storage",{key:e,newValue:n}))}require("client-only");const i=(e,n)=>{if("undefined"!=typeof window){const o=JSON.stringify(n);try{window.localStorage.setItem(e,o)}catch(e){console.error(e)}finally{r(e,o)}}},l=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{r(e,null)}},s=e=>{if("undefined"!=typeof window)try{return window.localStorage.getItem(e)}catch(e){console.warn(e)}return null},a=e=>"undefined"!=typeof window?(window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)):n.noop,c=()=>t.noSSR("foxact: useLocalStorage without `serverValue` will only be used at client side."),u=e=>"function"==typeof e;exports.useLocalStorage=(n,t)=>{const r=void 0!==t?()=>JSON.stringify(t):c,d=e.useSyncExternalStore(a,()=>s(n),r),w=e.useCallback(e=>{try{const o=u(e)?e(null!=d?JSON.parse(d):null):e;null==o?l(n):i(n,o)}catch(e){console.warn(e)}},[n,d]);return o.useIsomorphicLayoutEffect(()=>{null===s(n)&&void 0!==t&&i(n,t)},[n,t]),[null!=d?JSON.parse(d):t,w]};
1
+ "use strict";require("client-only");var e=require("react"),n=require("../noop/index.js"),o=require("../use-isomorphic-layout-effect/index.js"),r=require("../no-ssr/index.js");const t="foxact-local-storage",i=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(t,{detail:e}))},l=(e,n,o)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,o(n))}catch(e){console.error(e)}finally{i(e)}},a=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{i(e)}},s=(e,n)=>{if("undefined"==typeof window)return null;try{const o=window.localStorage.getItem(e);return null===o?null:n(o)}catch(e){return console.warn(e),null}},u=()=>{throw r.noSSRError("useLocalStorage cannot be used on the server without a serverValue")},d=e=>"function"==typeof e,c=e=>e;exports.useLocalStorage=function(r,i){var w;let f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const y=e.useCallback(e=>{if("undefined"==typeof window)return n.noop;const o=n=>{"key"in n&&n.key!==r||e()},i=n=>{n.detail===r&&e()};return window.addEventListener("storage",o),window.addEventListener(t,i),()=>{window.removeEventListener("storage",o),window.removeEventListener(t,i)}},[r]),v=f.raw?c:f.serializer,p=f.raw?c:f.deserializer,g=void 0!==i?()=>i:u,h=e.useSyncExternalStore(y,()=>s(r,p),g),S=e.useCallback(e=>{try{const n=d(e)?e(null!=h?h:null):e;null===n?a(r):l(r,n,v)}catch(e){console.warn(e)}},[r,v,h]);return o.useIsomorphicLayoutEffect(()=>{null===s(r,p)&&void 0!==i&&l(r,i,v)},[p,r,v,i]),[null!==(w=null!=h?h:i)&&void 0!==w?w:null,S]};
@@ -1 +1 @@
1
- import{useSyncExternalStore as e,useCallback as o}from"react";import{noop as n}from"../noop/index.mjs";import{useIsomorphicLayoutEffect as t}from"../use-isomorphic-layout-effect/index.mjs";import{noSSR as r}from"../no-ssr/index.mjs";import"client-only";function i(e,o){"undefined"!=typeof window&&window.dispatchEvent(new StorageEvent("storage",{key:e,newValue:o}))}const l=(e,o)=>{if("undefined"!=typeof window){const n=JSON.stringify(o);try{window.localStorage.setItem(e,n)}catch(e){console.error(e)}finally{i(e,n)}}},a=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{i(e,null)}},d=e=>{if("undefined"!=typeof window)try{return window.localStorage.getItem(e)}catch(e){console.warn(e)}return null},s=e=>"undefined"!=typeof window?(window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)):n,c=()=>r("foxact: useLocalStorage without `serverValue` will only be used at client side."),f=e=>"function"==typeof e,w=(n,r)=>{const i=void 0!==r?()=>JSON.stringify(r):c,w=e(s,()=>d(n),i),u=o(e=>{try{const o=f(e)?e(null!=w?JSON.parse(w):null):e;null==o?a(n):l(n,o)}catch(e){console.warn(e)}},[n,w]);return t(()=>{null===d(n)&&void 0!==r&&l(n,r)},[n,r]),[null!=w?JSON.parse(w):r,u]};export{w as useLocalStorage};
1
+ import"client-only";import{useCallback as e,useSyncExternalStore as n}from"react";import{noop as o}from"../noop/index.mjs";import{useIsomorphicLayoutEffect as t}from"../use-isomorphic-layout-effect/index.mjs";import{noSSRError as r}from"../no-ssr/index.mjs";const i="foxact-local-storage",l=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(i,{detail:e}))},a=(e,n,o)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,o(n))}catch(e){console.error(e)}finally{l(e)}},d=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{l(e)}},s=(e,n)=>{if("undefined"==typeof window)return null;try{const o=window.localStorage.getItem(e);return null===o?null:n(o)}catch(e){return console.warn(e),null}},w=()=>{throw r("useLocalStorage cannot be used on the server without a serverValue")},c=e=>"function"==typeof e,u=e=>e;function f(r,l){var f;let m=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const y=e(e=>{if("undefined"==typeof window)return o;const n=n=>{"key"in n&&n.key!==r||e()},t=n=>{n.detail===r&&e()};return window.addEventListener("storage",n),window.addEventListener(i,t),()=>{window.removeEventListener("storage",n),window.removeEventListener(i,t)}},[r]),p=m.raw?u:m.serializer,v=m.raw?u:m.deserializer,g=void 0!==l?()=>l:w,h=n(y,()=>s(r,v),g),S=e(e=>{try{const n=c(e)?e(null!=h?h:null):e;null===n?d(r):a(r,n,p)}catch(e){console.warn(e)}},[r,p,h]);return t(()=>{null===s(r,v)&&void 0!==l&&a(r,l,p)},[v,r,p,l]),[null!==(f=null!=h?h:l)&&void 0!==f?f:null,S]}export{f as useLocalStorage};