foxact 0.2.22 → 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.22",
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"
@@ -92,6 +92,15 @@
92
92
  "require": "./create-context-state/index.cjs",
93
93
  "default": "./create-context-state/index.js"
94
94
  },
95
+ "./no-ssr": {
96
+ "types": "./no-ssr/index.d.ts",
97
+ "import": {
98
+ "types": "./no-ssr/index.d.ts",
99
+ "default": "./no-ssr/index.mjs"
100
+ },
101
+ "require": "./no-ssr/index.cjs",
102
+ "default": "./no-ssr/index.js"
103
+ },
95
104
  "./create-fixed-array": {
96
105
  "types": "./create-fixed-array/index.d.ts",
97
106
  "import": {
@@ -218,15 +227,6 @@
218
227
  "require": "./use-is-client/index.cjs",
219
228
  "default": "./use-is-client/index.js"
220
229
  },
221
- "./use-map": {
222
- "types": "./use-map/index.d.ts",
223
- "import": {
224
- "types": "./use-map/index.d.ts",
225
- "default": "./use-map/index.mjs"
226
- },
227
- "require": "./use-map/index.cjs",
228
- "default": "./use-map/index.js"
229
- },
230
230
  "./use-isomorphic-layout-effect": {
231
231
  "types": "./use-isomorphic-layout-effect/index.d.ts",
232
232
  "import": {
@@ -236,6 +236,24 @@
236
236
  "require": "./use-isomorphic-layout-effect/index.cjs",
237
237
  "default": "./use-isomorphic-layout-effect/index.js"
238
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
+ },
248
+ "./use-map": {
249
+ "types": "./use-map/index.d.ts",
250
+ "import": {
251
+ "types": "./use-map/index.d.ts",
252
+ "default": "./use-map/index.mjs"
253
+ },
254
+ "require": "./use-map/index.cjs",
255
+ "default": "./use-map/index.js"
256
+ },
239
257
  "./use-next-pathname": {
240
258
  "types": "./use-next-pathname/index.d.ts",
241
259
  "import": {
@@ -307,6 +325,15 @@
307
325
  },
308
326
  "require": "./use-uncontrolled/index.cjs",
309
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"
310
337
  }
311
338
  }
312
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},"create-context-state":{"raw":146,"gzip":116,"br":102},"create-fixed-array":{"raw":101,"gzip":105,"br":89},"rem":{"raw":589,"gzip":331,"br":285},"noop":{"raw":34,"gzip":54,"br":38},"request-idle-callback":{"raw":411,"gzip":232,"br":179},"typescript-happy-forward-ref":{"raw":120,"gzip":104,"br":95},"use-array":{"raw":338,"gzip":247,"br":207},"use":{"raw":277,"gzip":185,"br":155},"use-clipboard":{"raw":1076,"gzip":617,"br":533},"use-error-boundary":{"raw":245,"gzip":197,"br":173},"use-debounced-state":{"raw":410,"gzip":291,"br":247},"use-is-client":{"raw":152,"gzip":144,"br":122},"use-debounced-value":{"raw":471,"gzip":313,"br":254},"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-intersection":{"raw":1239,"gzip":659,"br":605},"use-retimer":{"raw":201,"gzip":168,"br":127},"use-singleton":{"raw":139,"gzip":131,"br":104},"use-composition-input":{"raw":455,"gzip":282,"br":240},"use-set":{"raw":356,"gzip":243,"br":208},"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-react-router-enable-concurrent-navigation":{"raw":956,"gzip":455,"br":382},"use-react-router-is-match":{"raw":569,"gzip":371,"br":313}}}
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};