foxact 0.2.21 → 0.2.23

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.
@@ -0,0 +1 @@
1
+ "use strict";exports.noSSR=r=>{const o=Error(r);throw o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};
@@ -0,0 +1,4 @@
1
+ /** @see https://foxact.skk.moe/no-ssr */
2
+ declare const noSSR: (extraMessage?: string) => never;
3
+
4
+ export { noSSR };
@@ -0,0 +1 @@
1
+ "use strict";exports.noSSR=r=>{const o=Error(r);throw o.digest="NEXT_DYNAMIC_NO_SSR_CODE",o.recoverableError="NO_SSR",o};
@@ -0,0 +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};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
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": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/SukkaW/foxact"
8
+ "url": "git+https://github.com/SukkaW/foxact.git"
9
9
  },
10
10
  "bugs": {
11
11
  "url": "https://github.com/SukkaW/foxact/issues"
@@ -21,8 +21,6 @@
21
21
  "author": "Sukka <https://skk.moe>",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@eslint-sukka/node": "^4.1.7",
25
- "@eslint-sukka/react": "^4.1.7",
26
24
  "client-only": "^0.0.1",
27
25
  "server-only": "^0.0.1"
28
26
  },
@@ -94,14 +92,14 @@
94
92
  "require": "./create-context-state/index.cjs",
95
93
  "default": "./create-context-state/index.js"
96
94
  },
97
- "./noop": {
98
- "types": "./noop/index.d.ts",
95
+ "./no-ssr": {
96
+ "types": "./no-ssr/index.d.ts",
99
97
  "import": {
100
- "types": "./noop/index.d.ts",
101
- "default": "./noop/index.mjs"
98
+ "types": "./no-ssr/index.d.ts",
99
+ "default": "./no-ssr/index.mjs"
102
100
  },
103
- "require": "./noop/index.cjs",
104
- "default": "./noop/index.js"
101
+ "require": "./no-ssr/index.cjs",
102
+ "default": "./no-ssr/index.js"
105
103
  },
106
104
  "./create-fixed-array": {
107
105
  "types": "./create-fixed-array/index.d.ts",
@@ -112,6 +110,15 @@
112
110
  "require": "./create-fixed-array/index.cjs",
113
111
  "default": "./create-fixed-array/index.js"
114
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
+ },
115
122
  "./rem": {
116
123
  "types": "./rem/index.d.ts",
117
124
  "import": {
@@ -229,6 +236,15 @@
229
236
  "require": "./use-isomorphic-layout-effect/index.cjs",
230
237
  "default": "./use-isomorphic-layout-effect/index.js"
231
238
  },
239
+ "./use-local-storage": {
240
+ "types": "./use-local-storage/index.d.ts",
241
+ "import": {
242
+ "types": "./use-local-storage/index.d.ts",
243
+ "default": "./use-local-storage/index.mjs"
244
+ },
245
+ "require": "./use-local-storage/index.cjs",
246
+ "default": "./use-local-storage/index.js"
247
+ },
232
248
  "./use-map": {
233
249
  "types": "./use-map/index.d.ts",
234
250
  "import": {
@@ -283,15 +299,6 @@
283
299
  "require": "./use-set/index.cjs",
284
300
  "default": "./use-set/index.js"
285
301
  },
286
- "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired": {
287
- "types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
288
- "import": {
289
- "types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
290
- "default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs"
291
- },
292
- "require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
293
- "default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js"
294
- },
295
302
  "./use-singleton": {
296
303
  "types": "./use-singleton/index.d.ts",
297
304
  "import": {
@@ -301,6 +308,15 @@
301
308
  "require": "./use-singleton/index.cjs",
302
309
  "default": "./use-singleton/index.js"
303
310
  },
311
+ "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired": {
312
+ "types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
313
+ "import": {
314
+ "types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
315
+ "default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs"
316
+ },
317
+ "require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
318
+ "default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js"
319
+ },
304
320
  "./use-uncontrolled": {
305
321
  "types": "./use-uncontrolled/index.d.ts",
306
322
  "import": {
@@ -309,6 +325,15 @@
309
325
  },
310
326
  "require": "./use-uncontrolled/index.cjs",
311
327
  "default": "./use-uncontrolled/index.js"
328
+ },
329
+ "./use-url-hash-state": {
330
+ "types": "./use-url-hash-state/index.d.ts",
331
+ "import": {
332
+ "types": "./use-url-hash-state/index.d.ts",
333
+ "default": "./use-url-hash-state/index.mjs"
334
+ },
335
+ "require": "./use-url-hash-state/index.cjs",
336
+ "default": "./use-url-hash-state/index.js"
312
337
  }
313
338
  }
314
339
  }
package/sizes.json CHANGED
@@ -1 +1 @@
1
- {"total":{"raw":10452,"gzip":6832,"br":0},"exports":{"compose-context-provider":{"raw":165,"gzip":150,"br":118},"context-state":{"raw":378,"gzip":243,"br":210},"noop":{"raw":34,"gzip":54,"br":38},"create-fixed-array":{"raw":101,"gzip":105,"br":89},"create-context-state":{"raw":146,"gzip":116,"br":102},"rem":{"raw":589,"gzip":331,"br":285},"request-idle-callback":{"raw":411,"gzip":232,"br":179},"use":{"raw":277,"gzip":185,"br":155},"typescript-happy-forward-ref":{"raw":120,"gzip":104,"br":95},"use-clipboard":{"raw":1076,"gzip":617,"br":533},"use-composition-input":{"raw":455,"gzip":282,"br":240},"use-debounced-state":{"raw":410,"gzip":291,"br":247},"use-debounced-value":{"raw":471,"gzip":313,"br":254},"use-error-boundary":{"raw":245,"gzip":197,"br":173},"use-is-client":{"raw":152,"gzip":144,"br":122},"use-isomorphic-layout-effect":{"raw":179,"gzip":145,"br":115},"use-map":{"raw":355,"gzip":249,"br":213},"use-next-pathname":{"raw":322,"gzip":242,"br":202},"use-react-router-enable-concurrent-navigation":{"raw":956,"gzip":455,"br":382},"use-array":{"raw":338,"gzip":247,"br":207},"use-set":{"raw":356,"gzip":243,"br":208},"use-intersection":{"raw":1239,"gzip":659,"br":605},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":467,"gzip":326,"br":257},"use-uncontrolled":{"raw":301,"gzip":232,"br":197},"use-singleton":{"raw":139,"gzip":131,"br":104},"use-react-router-is-match":{"raw":569,"gzip":371,"br":313},"use-retimer":{"raw":201,"gzip":168,"br":127}}}
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}}}
@@ -0,0 +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]};
@@ -0,0 +1,4 @@
1
+ /** @see https://foxact.skk.moe/use-local-storage */
2
+ declare const useLocalStorage: <T extends string | number>(key: string, serverValue?: T | undefined) => any[];
3
+
4
+ export { useLocalStorage };
@@ -0,0 +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]};
@@ -0,0 +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};
@@ -0,0 +1 @@
1
+ "use strict";require("client-only");var e=require("react"),n=require("../noop/index.cjs"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs");const o=e=>e,r=(()=>{if("undefined"==typeof window)return e=>n.noop;let e=!1;const t=new Set,o=()=>{t.forEach(e=>e())};return n=>(t.add(n),e||(e=!0,window.addEventListener("hashchange",o)),()=>{t.delete(n)})})(),s=e=>"function"==typeof e;exports.unstable_useUrlHashState=function(n,a){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o;const i=t.useStableHandler(l);return[e.useSyncExternalStore(r,()=>{const e=new URLSearchParams(location.hash.slice(1)),t=e.get(n);return null!==t?l(t):a},()=>a),e.useCallback(e=>{let t;const o=location.hash,r=new URLSearchParams(o.slice(1));if(s(e)){const o=r.get(n);t=e(null!==o?i(o):a)}else t=e;t===a||void 0===t?r.delete(n):r.set(n,JSON.stringify(t));const l=r.toString();o!==l&&(location.hash=l)},[a,n,i])]};
@@ -0,0 +1,5 @@
1
+ /** @see https://foxact.skk.moe/use-url-hash-state */
2
+ declare function useUrlHashState<T>(key: string, defaultValue?: undefined): readonly [T | undefined, React.Dispatch<React.SetStateAction<T | undefined>>];
3
+ declare function useUrlHashState<T>(key: string, defaultValue: T, transform?: (value: string) => T): readonly [T, React.Dispatch<React.SetStateAction<T>>];
4
+
5
+ export { useUrlHashState as unstable_useUrlHashState };
@@ -0,0 +1 @@
1
+ "use strict";require("client-only");var e=require("react"),n=require("../noop/index.js"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js");const o=e=>e,r=(()=>{if("undefined"==typeof window)return e=>n.noop;let e=!1;const t=new Set,o=()=>{t.forEach(e=>e())};return n=>(t.add(n),e||(e=!0,window.addEventListener("hashchange",o)),()=>{t.delete(n)})})(),s=e=>"function"==typeof e;exports.unstable_useUrlHashState=function(n,a){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o;const i=t.useStableHandler(l);return[e.useSyncExternalStore(r,()=>{const e=new URLSearchParams(location.hash.slice(1)),t=e.get(n);return null!==t?l(t):a},()=>a),e.useCallback(e=>{let t;const o=location.hash,r=new URLSearchParams(o.slice(1));if(s(e)){const o=r.get(n);t=e(null!==o?i(o):a)}else t=e;t===a||void 0===t?r.delete(n):r.set(n,JSON.stringify(t));const l=r.toString();o!==l&&(location.hash=l)},[a,n,i])]};
@@ -0,0 +1 @@
1
+ import"client-only";import{useSyncExternalStore as e,useCallback as t}from"react";import{noop as n}from"../noop/index.mjs";import{useStableHandler as o}from"../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs";const r=e=>e,s=(()=>{if("undefined"==typeof window)return e=>n;let e=!1;const t=new Set,o=()=>{t.forEach(e=>e())};return n=>(t.add(n),e||(e=!0,window.addEventListener("hashchange",o)),()=>{t.delete(n)})})(),a=e=>"function"==typeof e;function i(n,i){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r;const c=o(l);return[e(s,()=>{const e=new URLSearchParams(location.hash.slice(1)),t=e.get(n);return null!==t?l(t):i},()=>i),t(e=>{let t;const o=location.hash,r=new URLSearchParams(o.slice(1));if(a(e)){const o=r.get(n);t=e(null!==o?c(o):i)}else t=e;t===i||void 0===t?r.delete(n):r.set(n,JSON.stringify(t));const s=r.toString();o!==s&&(location.hash=s)},[i,n,c])]}export{i as unstable_useUrlHashState};