foxact 0.2.53 → 0.2.55
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 +1 -1
- package/merge-refs/index.cjs +1 -0
- package/merge-refs/index.d.ts +4 -0
- package/merge-refs/index.mjs +1 -0
- package/package.json +20 -1
- package/sizes.json +1 -1
- package/use-fast-click/index.cjs +1 -1
- package/use-fast-click/index.mjs +1 -1
- package/use-is-online/index.cjs +1 -1
- package/use-is-online/index.mjs +1 -1
- package/use-media-query/index.cjs +1 -1
- package/use-media-query/index.mjs +1 -1
- package/use-page-visibility/index.cjs +1 -1
- package/use-page-visibility/index.mjs +1 -1
- package/use-readonly-search-params/index.cjs +1 -1
- package/use-readonly-search-params/index.mjs +1 -1
- package/use-state-with-deps/index.cjs +1 -0
- package/use-state-with-deps/index.d.ts +9 -0
- package/use-state-with-deps/index.mjs +1 -0
- package/use-url-hash-state/index.cjs +1 -1
- package/use-url-hash-state/index.mjs +1 -1
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
|
|
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
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=18>=Number.parseFloat(require("react").version)?function(){for(var r=arguments.length,e=Array(r),t=0;t<r;t++)e[t]=arguments[t];return r=>{e.forEach(e=>{"function"==typeof e?e(r):e&&(e.current=r)})}}:function(){for(var r=arguments.length,e=Array(r),t=0;t<r;t++)e[t]=arguments[t];return r=>{const t=new Set,n=new Set;return e.forEach(e=>{if("function"==typeof e){const o=e(r);"function"==typeof o?t.add(o):n.add(e)}else e&&(e.current=r)}),()=>{t.forEach(r=>r()),n.forEach(r=>r(null))}}};exports.mergeRefs=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{version as r}from"react";const t=18>=Number.parseFloat(r)?function(){for(var r=arguments.length,t=Array(r),e=0;e<r;e++)t[e]=arguments[e];return r=>{t.forEach(t=>{"function"==typeof t?t(r):t&&(t.current=r)})}}:function(){for(var r=arguments.length,t=Array(r),e=0;e<r;e++)t[e]=arguments[e];return r=>{const e=new Set,n=new Set;return t.forEach(t=>{if("function"==typeof t){const o=t(r);"function"==typeof o?e.add(o):n.add(t)}else t&&(t.current=r)}),()=>{e.forEach(r=>r()),n.forEach(r=>r(null))}}};export{t as mergeRefs};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxact",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.55",
|
|
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": {
|
|
@@ -204,6 +205,15 @@
|
|
|
204
205
|
"require": "./magic-portal/index.cjs",
|
|
205
206
|
"default": "./magic-portal/index.cjs"
|
|
206
207
|
},
|
|
208
|
+
"./merge-refs": {
|
|
209
|
+
"types": "./merge-refs/index.d.ts",
|
|
210
|
+
"import": {
|
|
211
|
+
"types": "./merge-refs/index.d.ts",
|
|
212
|
+
"default": "./merge-refs/index.mjs"
|
|
213
|
+
},
|
|
214
|
+
"require": "./merge-refs/index.cjs",
|
|
215
|
+
"default": "./merge-refs/index.cjs"
|
|
216
|
+
},
|
|
207
217
|
"./no-ssr": {
|
|
208
218
|
"types": "./no-ssr/index.d.ts",
|
|
209
219
|
"import": {
|
|
@@ -528,6 +538,15 @@
|
|
|
528
538
|
"require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
|
|
529
539
|
"default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs"
|
|
530
540
|
},
|
|
541
|
+
"./use-state-with-deps": {
|
|
542
|
+
"types": "./use-state-with-deps/index.d.ts",
|
|
543
|
+
"import": {
|
|
544
|
+
"types": "./use-state-with-deps/index.d.ts",
|
|
545
|
+
"default": "./use-state-with-deps/index.mjs"
|
|
546
|
+
},
|
|
547
|
+
"require": "./use-state-with-deps/index.cjs",
|
|
548
|
+
"default": "./use-state-with-deps/index.cjs"
|
|
549
|
+
},
|
|
531
550
|
"./use-typescript-happy-callback": {
|
|
532
551
|
"types": "./use-typescript-happy-callback/index.d.ts",
|
|
533
552
|
"import": {
|
package/sizes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"total":{"raw":
|
|
1
|
+
{"total":{"raw":28153,"gzip":17099,"br":0},"exports":{"compose-context-provider":{"raw":177,"gzip":155,"br":122},"context-state":{"raw":402,"gzip":259,"br":218},"create-context-reducer":{"raw":223,"gzip":146,"br":117},"create-context-state":{"raw":145,"gzip":116,"br":96},"create-magic-portal":{"raw":224,"gzip":136,"br":112},"create-fixed-array":{"raw":452,"gzip":282,"br":248},"create-session-storage-state":{"raw":406,"gzip":215,"br":188},"create-local-storage-state":{"raw":402,"gzip":216,"br":189},"context-reducer":{"raw":557,"gzip":332,"br":319},"current-year":{"raw":524,"gzip":355,"br":293},"email-protection":{"raw":426,"gzip":321,"br":272},"create-storage-state-factory":{"raw":592,"gzip":338,"br":304},"invariant":{"raw":178,"gzip":156,"br":118},"fetch-jsonp":{"raw":890,"gzip":546,"br":429},"is-safari":{"raw":233,"gzip":164,"br":119},"create-storage-hook":{"raw":2087,"gzip":897,"br":789},"noop":{"raw":33,"gzip":53,"br":37},"no-ssr":{"raw":465,"gzip":313,"br":260},"nullthrow":{"raw":187,"gzip":163,"br":121},"magic-portal":{"raw":1039,"gzip":521,"br":463},"request-idle-callback":{"raw":392,"gzip":221,"br":171},"types":{"raw":0,"gzip":20,"br":1},"merge-refs":{"raw":525,"gzip":280,"br":235},"use":{"raw":298,"gzip":197,"br":160},"use-abortable-effect":{"raw":215,"gzip":170,"br":144},"open-new-tab":{"raw":335,"gzip":255,"br":187},"typescript-happy-forward-ref":{"raw":119,"gzip":103,"br":80},"rem":{"raw":823,"gzip":395,"br":350},"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-error-boundary":{"raw":252,"gzip":195,"br":165},"use-clipboard":{"raw":1177,"gzip":650,"br":552},"use-is-client":{"raw":204,"gzip":153,"br":121},"use-debounced-value":{"raw":524,"gzip":342,"br":286},"use-isomorphic-layout-effect":{"raw":169,"gzip":137,"br":110},"use-intersection":{"raw":1230,"gzip":649,"br":597},"use-fast-click":{"raw":578,"gzip":377,"br":304},"use-local-storage":{"raw":384,"gzip":215,"br":201},"use-map":{"raw":339,"gzip":243,"br":208},"use-is-online":{"raw":370,"gzip":258,"br":220},"use-page-visibility":{"raw":359,"gzip":263,"br":210},"use-next-pathname":{"raw":314,"gzip":235,"br":203},"use-media-query":{"raw":604,"gzip":380,"br":315},"use-next-link":{"raw":1647,"gzip":875,"br":742},"use-retimer":{"raw":199,"gzip":166,"br":127},"use-react-router-is-match":{"raw":594,"gzip":395,"br":337},"use-set":{"raw":340,"gzip":238,"br":203},"use-react-router-enable-concurrent-navigation":{"raw":966,"gzip":470,"br":397},"use-session-storage":{"raw":390,"gzip":210,"br":201},"use-singleton":{"raw":149,"gzip":135,"br":116},"use-typescript-happy-callback":{"raw":107,"gzip":102,"br":77},"use-readonly-search-params":{"raw":1120,"gzip":573,"br":477},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":450,"gzip":318,"br":249},"use-state-with-deps":{"raw":464,"gzip":321,"br":295},"use-uncontrolled":{"raw":388,"gzip":273,"br":230},"use-url-hash-state":{"raw":1077,"gzip":611,"br":536}}}
|
package/use-fast-click/index.cjs
CHANGED
|
@@ -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(
|
|
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}};
|
package/use-fast-click/index.mjs
CHANGED
|
@@ -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
|
|
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};
|
package/use-is-online/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var
|
|
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)};
|
package/use-is-online/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{useSyncExternalStore as n}from"react";function
|
|
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"),
|
|
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
|
|
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
|
|
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
|
|
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"),
|
|
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{
|
|
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")
|
|
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
|
|
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};
|