foxact 0.2.24 → 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxact",
|
|
3
|
-
"version": "0.2.
|
|
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": {
|
|
@@ -92,15 +92,6 @@
|
|
|
92
92
|
"require": "./create-context-state/index.cjs",
|
|
93
93
|
"default": "./create-context-state/index.js"
|
|
94
94
|
},
|
|
95
|
-
"./create-fixed-array": {
|
|
96
|
-
"types": "./create-fixed-array/index.d.ts",
|
|
97
|
-
"import": {
|
|
98
|
-
"types": "./create-fixed-array/index.d.ts",
|
|
99
|
-
"default": "./create-fixed-array/index.mjs"
|
|
100
|
-
},
|
|
101
|
-
"require": "./create-fixed-array/index.cjs",
|
|
102
|
-
"default": "./create-fixed-array/index.js"
|
|
103
|
-
},
|
|
104
95
|
"./no-ssr": {
|
|
105
96
|
"types": "./no-ssr/index.d.ts",
|
|
106
97
|
"import": {
|
|
@@ -110,15 +101,6 @@
|
|
|
110
101
|
"require": "./no-ssr/index.cjs",
|
|
111
102
|
"default": "./no-ssr/index.js"
|
|
112
103
|
},
|
|
113
|
-
"./noop": {
|
|
114
|
-
"types": "./noop/index.d.ts",
|
|
115
|
-
"import": {
|
|
116
|
-
"types": "./noop/index.d.ts",
|
|
117
|
-
"default": "./noop/index.mjs"
|
|
118
|
-
},
|
|
119
|
-
"require": "./noop/index.cjs",
|
|
120
|
-
"default": "./noop/index.js"
|
|
121
|
-
},
|
|
122
104
|
"./rem": {
|
|
123
105
|
"types": "./rem/index.d.ts",
|
|
124
106
|
"import": {
|
|
@@ -128,6 +110,15 @@
|
|
|
128
110
|
"require": "./rem/index.cjs",
|
|
129
111
|
"default": "./rem/index.js"
|
|
130
112
|
},
|
|
113
|
+
"./noop": {
|
|
114
|
+
"types": "./noop/index.d.ts",
|
|
115
|
+
"import": {
|
|
116
|
+
"types": "./noop/index.d.ts",
|
|
117
|
+
"default": "./noop/index.mjs"
|
|
118
|
+
},
|
|
119
|
+
"require": "./noop/index.cjs",
|
|
120
|
+
"default": "./noop/index.js"
|
|
121
|
+
},
|
|
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-
|
|
222
|
-
"types": "./use-
|
|
212
|
+
"./use-debounced-value": {
|
|
213
|
+
"types": "./use-debounced-value/index.d.ts",
|
|
223
214
|
"import": {
|
|
224
|
-
"types": "./use-
|
|
225
|
-
"default": "./use-
|
|
215
|
+
"types": "./use-debounced-value/index.d.ts",
|
|
216
|
+
"default": "./use-debounced-value/index.mjs"
|
|
226
217
|
},
|
|
227
|
-
"require": "./use-
|
|
228
|
-
"default": "./use-
|
|
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":
|
|
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"),
|
|
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,6 +1,24 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
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;
|
|
3
21
|
/** @see https://foxact.skk.moe/use-local-storage */
|
|
4
|
-
declare function useLocalStorage<T
|
|
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>>];
|
|
5
23
|
|
|
6
|
-
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"),
|
|
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{
|
|
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};
|