foxact 0.2.53 → 0.2.54

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/README.md CHANGED
@@ -26,7 +26,7 @@ Written in TypeScript. Unlocking strong typing benefits with TypeScript 4.8+.
26
26
 
27
27
  #### Super Lightweight
28
28
 
29
- The entire **foxact** library has zero dependencies, ensuring a lean and efficient solution. And what's more...
29
+ The entire **foxact** library has very few dependencies, ensuring a lean and efficient solution. And what's more...
30
30
 
31
31
  #### Fully Tree Shakable
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.53",
3
+ "version": "0.2.54",
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": {
@@ -22,6 +22,7 @@
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
24
  "client-only": "^0.0.1",
25
+ "event-target-bus": "^1.0.0",
25
26
  "server-only": "^0.0.1"
26
27
  },
27
28
  "peerDependencies": {
@@ -60,15 +61,6 @@
60
61
  "require": "./compose-context-provider/index.cjs",
61
62
  "default": "./compose-context-provider/index.cjs"
62
63
  },
63
- "./context-reducer": {
64
- "types": "./context-reducer/index.d.ts",
65
- "import": {
66
- "types": "./context-reducer/index.d.ts",
67
- "default": "./context-reducer/index.mjs"
68
- },
69
- "require": "./context-reducer/index.cjs",
70
- "default": "./context-reducer/index.cjs"
71
- },
72
64
  "./context-state": {
73
65
  "types": "./context-state/index.d.ts",
74
66
  "import": {
@@ -87,6 +79,15 @@
87
79
  "require": "./create-context-reducer/index.cjs",
88
80
  "default": "./create-context-reducer/index.cjs"
89
81
  },
82
+ "./context-reducer": {
83
+ "types": "./context-reducer/index.d.ts",
84
+ "import": {
85
+ "types": "./context-reducer/index.d.ts",
86
+ "default": "./context-reducer/index.mjs"
87
+ },
88
+ "require": "./context-reducer/index.cjs",
89
+ "default": "./context-reducer/index.cjs"
90
+ },
90
91
  "./create-context-state": {
91
92
  "types": "./create-context-state/index.d.ts",
92
93
  "import": {
@@ -186,15 +187,6 @@
186
187
  "require": "./invariant/index.cjs",
187
188
  "default": "./invariant/index.cjs"
188
189
  },
189
- "./is-safari": {
190
- "types": "./is-safari/index.d.ts",
191
- "import": {
192
- "types": "./is-safari/index.d.ts",
193
- "default": "./is-safari/index.mjs"
194
- },
195
- "require": "./is-safari/index.cjs",
196
- "default": "./is-safari/index.cjs"
197
- },
198
190
  "./magic-portal": {
199
191
  "types": "./magic-portal/index.d.ts",
200
192
  "import": {
@@ -213,6 +205,15 @@
213
205
  "require": "./no-ssr/index.cjs",
214
206
  "default": "./no-ssr/index.cjs"
215
207
  },
208
+ "./is-safari": {
209
+ "types": "./is-safari/index.d.ts",
210
+ "import": {
211
+ "types": "./is-safari/index.d.ts",
212
+ "default": "./is-safari/index.mjs"
213
+ },
214
+ "require": "./is-safari/index.cjs",
215
+ "default": "./is-safari/index.cjs"
216
+ },
216
217
  "./noop": {
217
218
  "types": "./noop/index.d.ts",
218
219
  "import": {
@@ -240,15 +241,6 @@
240
241
  "require": "./open-new-tab/index.cjs",
241
242
  "default": "./open-new-tab/index.cjs"
242
243
  },
243
- "./rem": {
244
- "types": "./rem/index.d.ts",
245
- "import": {
246
- "types": "./rem/index.d.ts",
247
- "default": "./rem/index.mjs"
248
- },
249
- "require": "./rem/index.cjs",
250
- "default": "./rem/index.cjs"
251
- },
252
244
  "./request-idle-callback": {
253
245
  "types": "./request-idle-callback/index.d.ts",
254
246
  "import": {
@@ -258,6 +250,15 @@
258
250
  "require": "./request-idle-callback/index.cjs",
259
251
  "default": "./request-idle-callback/index.cjs"
260
252
  },
253
+ "./rem": {
254
+ "types": "./rem/index.d.ts",
255
+ "import": {
256
+ "types": "./rem/index.d.ts",
257
+ "default": "./rem/index.mjs"
258
+ },
259
+ "require": "./rem/index.cjs",
260
+ "default": "./rem/index.cjs"
261
+ },
261
262
  "./types": {
262
263
  "types": "./types/index.d.ts",
263
264
  "import": {
@@ -528,6 +529,15 @@
528
529
  "require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
529
530
  "default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs"
530
531
  },
532
+ "./use-state-with-deps": {
533
+ "types": "./use-state-with-deps/index.d.ts",
534
+ "import": {
535
+ "types": "./use-state-with-deps/index.d.ts",
536
+ "default": "./use-state-with-deps/index.mjs"
537
+ },
538
+ "require": "./use-state-with-deps/index.cjs",
539
+ "default": "./use-state-with-deps/index.cjs"
540
+ },
531
541
  "./use-typescript-happy-callback": {
532
542
  "types": "./use-typescript-happy-callback/index.d.ts",
533
543
  "import": {
package/sizes.json CHANGED
@@ -1 +1 @@
1
- {"total":{"raw":27165,"gzip":16404,"br":0},"exports":{"context-reducer":{"raw":557,"gzip":332,"br":319},"create-context-state":{"raw":145,"gzip":116,"br":96},"context-state":{"raw":402,"gzip":259,"br":218},"create-local-storage-state":{"raw":402,"gzip":216,"br":189},"create-context-reducer":{"raw":223,"gzip":146,"br":117},"create-session-storage-state":{"raw":406,"gzip":215,"br":188},"compose-context-provider":{"raw":177,"gzip":155,"br":122},"create-fixed-array":{"raw":452,"gzip":282,"br":248},"create-magic-portal":{"raw":224,"gzip":136,"br":112},"create-storage-state-factory":{"raw":592,"gzip":338,"br":304},"fetch-jsonp":{"raw":890,"gzip":546,"br":429},"current-year":{"raw":524,"gzip":355,"br":293},"email-protection":{"raw":426,"gzip":321,"br":272},"is-safari":{"raw":233,"gzip":164,"br":119},"create-storage-hook":{"raw":2087,"gzip":897,"br":789},"noop":{"raw":33,"gzip":53,"br":37},"invariant":{"raw":178,"gzip":156,"br":118},"open-new-tab":{"raw":335,"gzip":255,"br":187},"nullthrow":{"raw":187,"gzip":163,"br":121},"magic-portal":{"raw":1039,"gzip":521,"br":463},"types":{"raw":0,"gzip":20,"br":1},"typescript-happy-forward-ref":{"raw":119,"gzip":103,"br":80},"no-ssr":{"raw":465,"gzip":313,"br":260},"use":{"raw":298,"gzip":197,"br":160},"use-abortable-effect":{"raw":215,"gzip":170,"br":144},"request-idle-callback":{"raw":392,"gzip":221,"br":171},"use-component-will-receive-update":{"raw":216,"gzip":188,"br":154},"rem":{"raw":823,"gzip":395,"br":350},"use-composition-input":{"raw":470,"gzip":286,"br":241},"use-array":{"raw":322,"gzip":236,"br":202},"use-clipboard":{"raw":1177,"gzip":650,"br":552},"use-debounced-value":{"raw":524,"gzip":342,"br":286},"use-fast-click":{"raw":553,"gzip":364,"br":297},"use-debounced-state":{"raw":401,"gzip":280,"br":242},"use-is-client":{"raw":204,"gzip":153,"br":121},"use-error-boundary":{"raw":252,"gzip":195,"br":165},"use-isomorphic-layout-effect":{"raw":169,"gzip":137,"br":110},"use-local-storage":{"raw":384,"gzip":215,"br":201},"use-intersection":{"raw":1230,"gzip":649,"br":597},"use-is-online":{"raw":350,"gzip":209,"br":162},"use-next-pathname":{"raw":314,"gzip":235,"br":203},"use-page-visibility":{"raw":284,"gzip":203,"br":150},"use-media-query":{"raw":702,"gzip":404,"br":331},"use-map":{"raw":339,"gzip":243,"br":208},"use-readonly-search-params":{"raw":1096,"gzip":551,"br":443},"use-next-link":{"raw":1647,"gzip":875,"br":742},"use-react-router-enable-concurrent-navigation":{"raw":966,"gzip":470,"br":397},"use-react-router-is-match":{"raw":594,"gzip":395,"br":337},"use-set":{"raw":340,"gzip":238,"br":203},"use-singleton":{"raw":149,"gzip":135,"br":116},"use-retimer":{"raw":199,"gzip":166,"br":127},"use-typescript-happy-callback":{"raw":107,"gzip":102,"br":77},"use-uncontrolled":{"raw":388,"gzip":273,"br":230},"use-session-storage":{"raw":390,"gzip":210,"br":201},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":450,"gzip":318,"br":249},"use-url-hash-state":{"raw":1124,"gzip":637,"br":559}}}
1
+ {"total":{"raw":27628,"gzip":16819,"br":0},"exports":{"compose-context-provider":{"raw":177,"gzip":155,"br":122},"create-context-state":{"raw":145,"gzip":116,"br":96},"context-reducer":{"raw":557,"gzip":332,"br":319},"context-state":{"raw":402,"gzip":259,"br":218},"create-magic-portal":{"raw":224,"gzip":136,"br":112},"create-context-reducer":{"raw":223,"gzip":146,"br":117},"create-local-storage-state":{"raw":402,"gzip":216,"br":189},"create-storage-state-factory":{"raw":592,"gzip":338,"br":304},"create-session-storage-state":{"raw":406,"gzip":215,"br":188},"create-fixed-array":{"raw":452,"gzip":282,"br":248},"current-year":{"raw":524,"gzip":355,"br":293},"invariant":{"raw":178,"gzip":156,"br":118},"create-storage-hook":{"raw":2087,"gzip":897,"br":789},"fetch-jsonp":{"raw":890,"gzip":546,"br":429},"is-safari":{"raw":233,"gzip":164,"br":119},"noop":{"raw":33,"gzip":53,"br":37},"email-protection":{"raw":426,"gzip":321,"br":272},"open-new-tab":{"raw":335,"gzip":255,"br":187},"magic-portal":{"raw":1039,"gzip":521,"br":463},"nullthrow":{"raw":187,"gzip":163,"br":121},"types":{"raw":0,"gzip":20,"br":1},"typescript-happy-forward-ref":{"raw":119,"gzip":103,"br":80},"use":{"raw":298,"gzip":197,"br":160},"no-ssr":{"raw":465,"gzip":313,"br":260},"rem":{"raw":823,"gzip":395,"br":350},"request-idle-callback":{"raw":392,"gzip":221,"br":171},"use-abortable-effect":{"raw":215,"gzip":170,"br":144},"use-component-will-receive-update":{"raw":216,"gzip":188,"br":154},"use-composition-input":{"raw":470,"gzip":286,"br":241},"use-debounced-state":{"raw":401,"gzip":280,"br":242},"use-array":{"raw":322,"gzip":236,"br":202},"use-debounced-value":{"raw":524,"gzip":342,"br":286},"use-clipboard":{"raw":1177,"gzip":650,"br":552},"use-fast-click":{"raw":578,"gzip":377,"br":304},"use-is-client":{"raw":204,"gzip":153,"br":121},"use-isomorphic-layout-effect":{"raw":169,"gzip":137,"br":110},"use-is-online":{"raw":370,"gzip":258,"br":220},"use-local-storage":{"raw":384,"gzip":215,"br":201},"use-error-boundary":{"raw":252,"gzip":195,"br":165},"use-media-query":{"raw":604,"gzip":380,"br":315},"use-map":{"raw":339,"gzip":243,"br":208},"use-next-pathname":{"raw":314,"gzip":235,"br":203},"use-page-visibility":{"raw":359,"gzip":263,"br":210},"use-intersection":{"raw":1230,"gzip":649,"br":597},"use-react-router-is-match":{"raw":594,"gzip":395,"br":337},"use-react-router-enable-concurrent-navigation":{"raw":966,"gzip":470,"br":397},"use-readonly-search-params":{"raw":1120,"gzip":573,"br":477},"use-session-storage":{"raw":390,"gzip":210,"br":201},"use-singleton":{"raw":149,"gzip":135,"br":116},"use-set":{"raw":340,"gzip":238,"br":203},"use-next-link":{"raw":1647,"gzip":875,"br":742},"use-typescript-happy-callback":{"raw":107,"gzip":102,"br":77},"use-retimer":{"raw":199,"gzip":166,"br":127},"use-uncontrolled":{"raw":388,"gzip":273,"br":230},"use-state-with-deps":{"raw":464,"gzip":321,"br":295},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":450,"gzip":318,"br":249},"use-url-hash-state":{"raw":1077,"gzip":611,"br":536}}}
@@ -1 +1 @@
1
- "use strict";var e=require("react"),n=require("../use-media-query/index.cjs");require("../no-ssr/index.cjs"),require("../noop/index.cjs"),exports.useFastClick=function(o){const s=e.useCallback(e=>{("mousedown"!==e.type||0===e.button)&&("development"!==process.env.NODE_ENV||e.currentTarget instanceof HTMLDivElement||e.currentTarget instanceof HTMLButtonElement||console.warn('[foxact/use-fast-click] You should only use "useFastClick" on <div /> or <button /> elements'),o(e))},[o]);return n.useMediaQuery("(pointer: coarse)",!1)?{onClick:s}:{onMouseDown:s}};
1
+ "use strict";var e=require("react"),n=require("../use-media-query/index.cjs");require("../no-ssr/index.cjs"),require("../noop/index.cjs"),require("event-target-bus"),exports.useFastClick=function(t){const r=e.useCallback(e=>{("mousedown"!==e.type||0===e.button)&&("development"!==process.env.NODE_ENV||e.currentTarget instanceof HTMLDivElement||e.currentTarget instanceof HTMLButtonElement||console.warn('[foxact/use-fast-click] You should only use "useFastClick" on <div /> or <button /> elements'),t(e))},[t]);return n.useMediaQuery("(pointer: coarse)",!1)?{onClick:r}:{onMouseDown:r}};
@@ -1 +1 @@
1
- import{useCallback as e}from"react";import{useMediaQuery as o}from"../use-media-query/index.mjs";import"../no-ssr/index.mjs";import"../noop/index.mjs";function n(n){const t=e(e=>{("mousedown"!==e.type||0===e.button)&&("development"!==process.env.NODE_ENV||e.currentTarget instanceof HTMLDivElement||e.currentTarget instanceof HTMLButtonElement||console.warn('[foxact/use-fast-click] You should only use "useFastClick" on <div /> or <button /> elements'),n(e))},[n]);return o("(pointer: coarse)",!1)?{onClick:t}:{onMouseDown:t}}export{n as useFastClick};
1
+ import{useCallback as e}from"react";import{useMediaQuery as o}from"../use-media-query/index.mjs";import"../no-ssr/index.mjs";import"../noop/index.mjs";import"event-target-bus";function t(t){const n=e(e=>{("mousedown"!==e.type||0===e.button)&&("development"!==process.env.NODE_ENV||e.currentTarget instanceof HTMLDivElement||e.currentTarget instanceof HTMLButtonElement||console.warn('[foxact/use-fast-click] You should only use "useFastClick" on <div /> or <button /> elements'),t(e))},[t]);return o("(pointer: coarse)",!1)?{onClick:n}:{onMouseDown:n}}export{t as useFastClick};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- "use strict";var e=require("react");function n(e){return window.addEventListener("online",e),window.addEventListener("offline",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}}function t(){return!("u"<typeof window)&&navigator.onLine}exports.useIsOnline=function(){return e.useSyncExternalStore(n,t,t)};
2
+ "use strict";var n=require("react"),e=require("event-target-bus");let t=null,r=null;function u(n){null!=t||(t=e.createEventTargetBus(window,"online")),null!=r||(r=e.createEventTargetBus(window,"offline"));const u=t.on(n),o=r.on(n);return()=>{u(),o()}}function o(){return!("u"<typeof window)&&navigator.onLine}exports.useIsOnline=function(){return n.useSyncExternalStore(u,o,o)};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useSyncExternalStore as n}from"react";function e(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function i(){return!("u"<typeof window)&&navigator.onLine}function o(){return n(e,i,i)}export{o as useIsOnline};
2
+ import{useSyncExternalStore as n}from"react";import{createEventTargetBus as o}from"event-target-bus";let t=null,e=null;function r(n){null!=t||(t=o(window,"online")),null!=e||(e=o(window,"offline"));const r=t.on(n),i=e.on(n);return()=>{r(),i()}}function i(){return!("u"<typeof window)&&navigator.onLine}function u(){return n(r,i,i)}export{u as useIsOnline};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- "use strict";var e=require("../no-ssr/index.cjs"),n=require("../noop/index.cjs"),t=require("react");const r=new Map;function o(){throw e.noSSRError("useMediaQuery cannot be used on the server without a serverValue")}exports.useMediaQuery=function(e,a){"u">typeof window&&!r.has(e)&&r.set(e,window.matchMedia(e).matches);const i=t.useCallback(t=>(function(e,t){if("u"<typeof window)return n.noop;const o=window.matchMedia(e),a=()=>{r.set(e,o.matches),t()};return o.addEventListener("change",a),()=>{o.removeEventListener("change",a)}})(e,t),[e]);return t.useSyncExternalStore(i,()=>{var n;return!("u"<typeof window)&&(null!=(n=r.get(e))?n:window.matchMedia(e).matches)},void 0===a?o:()=>a)};
2
+ "use strict";var e=require("../no-ssr/index.cjs"),r=require("../noop/index.cjs"),t=require("react"),n=require("event-target-bus");const o=new Map;function u(){throw e.noSSRError("useMediaQuery cannot be used on the server without a serverValue")}exports.useMediaQuery=function(e,i){const a=t.useCallback(t=>(function(e,t){if("u"<typeof window)return r.noop;let u=o.get(e);return u||(u=n.createEventTargetBus(window.matchMedia(e),"change"),o.set(e,u)),u.on(t)})(e,t),[e]);return t.useSyncExternalStore(a,()=>"u"<typeof window?null!=i&&i:window.matchMedia(e).matches,void 0===i?u:()=>i)};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{noSSRError as e}from"../no-ssr/index.mjs";import{noop as t}from"../noop/index.mjs";import{useCallback as n,useSyncExternalStore as o}from"react";const r=new Map;function i(){throw e("useMediaQuery cannot be used on the server without a serverValue")}function a(e,a){return"u">typeof window&&!r.has(e)&&r.set(e,window.matchMedia(e).matches),o(n(n=>(function(e,n){if("u"<typeof window)return t;const o=window.matchMedia(e),i=()=>{r.set(e,o.matches),n()};return o.addEventListener("change",i),()=>{o.removeEventListener("change",i)}})(e,n),[e]),()=>{var t;return!("u"<typeof window)&&(null!=(t=r.get(e))?t:window.matchMedia(e).matches)},void 0===a?i:()=>a)}export{a as useMediaQuery};
2
+ import{noSSRError as e}from"../no-ssr/index.mjs";import{noop as t}from"../noop/index.mjs";import{useCallback as o,useSyncExternalStore as n}from"react";import{createEventTargetBus as r}from"event-target-bus";const i=new Map;function u(){throw e("useMediaQuery cannot be used on the server without a serverValue")}function a(e,a){return n(o(o=>(function(e,o){if("u"<typeof window)return t;let n=i.get(e);return n||(n=r(window.matchMedia(e),"change"),i.set(e,n)),n.on(o)})(e,o),[e]),()=>"u"<typeof window?null!=a&&a:window.matchMedia(e).matches,void 0===a?u:()=>a)}export{a as useMediaQuery};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- "use strict";var e=require("react");const t=e=>(document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}),i=()=>!("u"<typeof document)&&!document.hidden;exports.usePageVisibility=function(){return e.useSyncExternalStore(t,i,i)};
2
+ "use strict";var e=require("react"),t=require("event-target-bus"),n=require("../noop/index.cjs");let r=null;const u=e=>"u"<typeof window?n.noop:(null!=r||(r=t.createEventTargetBus(document,"visibilitychange")),r.on(e)),i=()=>!("u"<typeof document)&&!document.hidden;exports.usePageVisibility=function(){return e.useSyncExternalStore(u,i,i)};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useSyncExternalStore as e}from"react";const t=e=>(document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}),i=()=>!("u"<typeof document)&&!document.hidden;function n(){return e(t,i,i)}export{n as usePageVisibility};
2
+ import{useSyncExternalStore as t}from"react";import{createEventTargetBus as o}from"event-target-bus";import{noop as e}from"../noop/index.mjs";let n=null;const i=t=>"u"<typeof window?e:(null!=n||(n=o(document,"visibilitychange")),n.on(t)),r=()=>!("u"<typeof document)&&!document.hidden;function u(){return t(i,r,r)}export{u as usePageVisibility};
@@ -1 +1 @@
1
- "use strict";var e=require("../no-ssr/index.cjs"),r=require("../noop/index.cjs"),n=require("react");class a extends Error{constructor(){var e;super("[foxact/use-readonly-search-params] Method unavailable on `ReadonlyURLSearchParams`"),(e="name")in this?Object.defineProperty(this,e,{value:"ReadonlyURLSearchParamsError",enumerable:!0,configurable:!0,writable:!0}):this[e]="ReadonlyURLSearchParamsError"}}class o extends URLSearchParams{append(){throw new a}delete(){throw new a}set(){throw new a}sort(){throw new a}}function t(e){return"u"<typeof window?r.noop:(window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)})}let s=null,c=null;function u(){return"u"<typeof window?new o:window.location.search===s&&null!==c?c:c=new o(s=window.location.search)}function i(){throw e.noSSRError('[foxact] useReadonlySearchParams cannot be used on the server without a "getServerDefaultValue" function')}exports.ReadonlyURLSearchParams=o,exports.useReadonlySearchParams=function(e){return n.useSyncExternalStore(t,u,null==e?i:()=>{const r=e();return r instanceof o?r:new o(r)})};
1
+ "use strict";var e=require("event-target-bus"),r=require("../no-ssr/index.cjs"),n=require("../noop/index.cjs"),a=require("react");class t extends Error{constructor(){var e;super("[foxact/use-readonly-search-params] Method unavailable on `ReadonlyURLSearchParams`"),(e="name")in this?Object.defineProperty(this,e,{value:"ReadonlyURLSearchParamsError",enumerable:!0,configurable:!0,writable:!0}):this[e]="ReadonlyURLSearchParamsError"}}class o extends URLSearchParams{append(){throw new t}delete(){throw new t}set(){throw new t}sort(){throw new t}}let s=null;function u(r){return"u"<typeof window?n.noop:(null!=s||(s=e.createEventTargetBus(window,"popstate")),s.on(r))}let l=null,c=null;function i(){return"u"<typeof window?new o:window.location.search===l&&null!==c?c:c=new o(l=window.location.search)}function w(){throw r.noSSRError('[foxact] useReadonlySearchParams cannot be used on the server without a "getServerDefaultValue" function')}exports.ReadonlyURLSearchParams=o,exports.useReadonlySearchParams=function(e){return a.useSyncExternalStore(u,i,null==e?w:()=>{const r=e();return r instanceof o?r:new o(r)})};
@@ -1 +1 @@
1
- import{noSSRError as e}from"../no-ssr/index.mjs";import{noop as r}from"../noop/index.mjs";import{useSyncExternalStore as n}from"react";class o extends Error{constructor(){var e;super("[foxact/use-readonly-search-params] Method unavailable on `ReadonlyURLSearchParams`"),(e="name")in this?Object.defineProperty(this,e,{value:"ReadonlyURLSearchParamsError",enumerable:!0,configurable:!0,writable:!0}):this[e]="ReadonlyURLSearchParamsError"}}class a extends URLSearchParams{append(){throw new o}delete(){throw new o}set(){throw new o}sort(){throw new o}}function t(e){return"u"<typeof window?r:(window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)})}let s=null,i=null;function c(){return"u"<typeof window?new a:window.location.search===s&&null!==i?i:i=new a(s=window.location.search)}function l(){throw e('[foxact] useReadonlySearchParams cannot be used on the server without a "getServerDefaultValue" function')}function u(e){return n(t,c,null==e?l:()=>{const r=e();return r instanceof a?r:new a(r)})}export{a as ReadonlyURLSearchParams,u as useReadonlySearchParams};
1
+ import{createEventTargetBus as e}from"event-target-bus";import{noSSRError as r}from"../no-ssr/index.mjs";import{noop as n}from"../noop/index.mjs";import{useSyncExternalStore as o}from"react";class a extends Error{constructor(){var e;super("[foxact/use-readonly-search-params] Method unavailable on `ReadonlyURLSearchParams`"),(e="name")in this?Object.defineProperty(this,e,{value:"ReadonlyURLSearchParamsError",enumerable:!0,configurable:!0,writable:!0}):this[e]="ReadonlyURLSearchParamsError"}}class t extends URLSearchParams{append(){throw new a}delete(){throw new a}set(){throw new a}sort(){throw new a}}let s=null;function l(r){return"u"<typeof window?n:(null!=s||(s=e(window,"popstate")),s.on(r))}let u=null,c=null;function i(){return"u"<typeof window?new t:window.location.search===u&&null!==c?c:c=new t(u=window.location.search)}function w(){throw r('[foxact] useReadonlySearchParams cannot be used on the server without a "getServerDefaultValue" function')}function d(e){return o(l,i,null==e?w:()=>{const r=e();return r instanceof t?r:new t(r)})}export{t as ReadonlyURLSearchParams,d as useReadonlySearchParams};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("react"),t=require("../use-isomorphic-layout-effect/index.cjs");require("client-only"),exports.useStateWithDeps=function(r){const[,u]=e.useState({}),c=e.useRef(!1),s=e.useRef(r),n=e.useRef({}),o=e.useCallback(e=>{let t=!1;const r=s.current;for(const u in e)Object.prototype.hasOwnProperty.call(e,u)&&r[u]!==e[u]&&(r[u]=e[u],n.current[u]&&(t=!0));t&&!c.current&&u({})},[]);return t.useLayoutEffect(()=>(c.current=!1,()=>{c.current=!0})),[s,n,o]};
@@ -0,0 +1,9 @@
1
+ import { RefObject } from 'react';
2
+
3
+ declare function useStateWithDeps<S extends Record<string, any> = Record<string, any>>(initialState: S): [
4
+ stateRef: RefObject<S>,
5
+ stateDependenciesRef: RefObject<Partial<Record<keyof S, boolean>>>,
6
+ setState: (payload: Partial<S>) => void
7
+ ];
8
+
9
+ export { useStateWithDeps };
@@ -0,0 +1 @@
1
+ import{useState as t,useRef as r,useCallback as e}from"react";import{useLayoutEffect as o}from"../use-isomorphic-layout-effect/index.mjs";import"client-only";function n(n){const[,c]=t({}),i=r(!1),u=r(n),p=r({}),s=e(t=>{let r=!1;const e=u.current;for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&e[o]!==t[o]&&(e[o]=t[o],p.current[o]&&(r=!0));r&&!i.current&&c({})},[]);return o(()=>(i.current=!1,()=>{i.current=!0})),[u,p,s]}export{n as useStateWithDeps};
@@ -1 +1 @@
1
- "use strict";require("client-only");var e=require("react"),r=require("../noop/index.cjs"),n=require("../no-ssr/index.cjs"),t=require("../chunks/index.b9dLwVor.cjs"),s=require("../chunks/index.BtiK5_Nn.cjs");const a=(()=>{if("u"<typeof window)return e=>r.noop;let e=!1;const n=new Set,t=()=>{n.forEach(e=>e())};return r=>(n.add(r),e||(e=!0,window.addEventListener("hashchange",t)),()=>{n.delete(r)})})();function l(){throw n.noSSRError("useUrlHashState cannot be used on the server without a serverValue")}exports.unstable_useUrlHashState=function(r,n){var i;let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{raw:!1,serializer:t.t,deserializer:t.t};const u=o.raw?t.t:o.serializer,c=o.raw?t.t:o.deserializer,h=void 0===n?l:()=>u(n),d=e.useSyncExternalStore(a,()=>new URLSearchParams(location.hash.slice(1)).get(r),h),w=e.useMemo(()=>null===d?null!=n?n:null:c(d),[n,c,d]),S=e.useCallback(e=>{const t=location.hash,a=new URLSearchParams(t.slice(1)),l=s.n(e)?e(w):e;l===n||null===l?a.delete(r):a.set(r,u(l));const i=a.toString();t!==i&&(location.hash=i)},[n,w,r,u]);return[null!=(i=null!=w?w:n)?i:null,S]};
1
+ "use strict";require("client-only");var e=require("react"),r=require("../noop/index.cjs"),n=require("../no-ssr/index.cjs"),t=require("../chunks/index.b9dLwVor.cjs"),s=require("../chunks/index.BtiK5_Nn.cjs"),l=require("event-target-bus");let a=null;const i=e=>"u"<typeof window?r.noop:(null!=a||(a=l.createEventTargetBus(window,"hashchange")),a.on(e));function o(){throw n.noSSRError("useUrlHashState cannot be used on the server without a serverValue")}exports.unstable_useUrlHashState=function(r,n){var l;let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{raw:!1,serializer:t.t,deserializer:t.t};const u=a.raw?t.t:a.serializer,c=a.raw?t.t:a.deserializer,h=void 0===n?o:()=>u(n),d=e.useSyncExternalStore(i,()=>new URLSearchParams(location.hash.slice(1)).get(r),h),w=e.useMemo(()=>null===d?null!=n?n:null:c(d),[n,c,d]),S=e.useCallback(e=>{const t=location.hash,l=new URLSearchParams(t.slice(1)),a=s.n(e)?e(w):e;a===n||null===a?l.delete(r):l.set(r,u(a));const i=l.toString();t!==i&&(location.hash=i)},[n,w,r,u]);return[null!=(l=null!=w?w:n)?l:null,S]};
@@ -1 +1 @@
1
- import"client-only";import{useSyncExternalStore as e,useMemo as r,useCallback as t}from"react";import{noop as n}from"../noop/index.mjs";import{noSSRError as o}from"../no-ssr/index.mjs";import{t as s}from"../chunks/index.D0KaUCcV.mjs";import{n as a}from"../chunks/index.C9-3oDdv.mjs";const l=(()=>{if("u"<typeof window)return e=>n;let e=!1;const r=new Set,t=()=>{r.forEach(e=>e())};return n=>(r.add(n),e||(e=!0,window.addEventListener("hashchange",t)),()=>{r.delete(n)})})();function i(){throw o("useUrlHashState cannot be used on the server without a serverValue")}function u(n,o){var u;let c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{raw:!1,serializer:s,deserializer:s};const h=c.raw?s:c.serializer,d=c.raw?s:c.deserializer,m=e(l,()=>new URLSearchParams(location.hash.slice(1)).get(n),void 0===o?i:()=>h(o)),w=r(()=>null===m?null!=o?o:null:d(m),[o,d,m]),f=t(e=>{const r=location.hash,t=new URLSearchParams(r.slice(1)),s=a(e)?e(w):e;s===o||null===s?t.delete(n):t.set(n,h(s));const l=t.toString();r!==l&&(location.hash=l)},[o,w,n,h]);return[null!=(u=null!=w?w:o)?u:null,f]}export{u as unstable_useUrlHashState};
1
+ import"client-only";import{useSyncExternalStore as e,useMemo as n,useCallback as r}from"react";import{noop as t}from"../noop/index.mjs";import{noSSRError as o}from"../no-ssr/index.mjs";import{t as l}from"../chunks/index.D0KaUCcV.mjs";import{n as s}from"../chunks/index.C9-3oDdv.mjs";import{createEventTargetBus as a}from"event-target-bus";let i=null;const u=e=>"u"<typeof window?t:(null!=i||(i=a(window,"hashchange")),i.on(e));function h(){throw o("useUrlHashState cannot be used on the server without a serverValue")}function c(t,o){var a;let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{raw:!1,serializer:l,deserializer:l};const c=i.raw?l:i.serializer,m=i.raw?l:i.deserializer,d=e(u,()=>new URLSearchParams(location.hash.slice(1)).get(t),void 0===o?h:()=>c(o)),w=n(()=>null===d?null!=o?o:null:m(d),[o,m,d]),p=r(e=>{const n=location.hash,r=new URLSearchParams(n.slice(1)),l=s(e)?e(w):e;l===o||null===l?r.delete(t):r.set(t,c(l));const a=r.toString();n!==a&&(location.hash=a)},[o,w,t,c]);return[null!=(a=null!=w?w:o)?a:null,p]}export{c as unstable_useUrlHashState};