foxact 0.2.9 → 0.2.11

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
@@ -12,11 +12,7 @@ https://foxact.skk.moe
12
12
 
13
13
  #### React 18 Safe
14
14
 
15
- All hooks and utils are React 18+ Concurrent Rendering resilient.
16
-
17
- **foxact** strictly follows React best practices, e.g. never read and write ref during the render phase, unlike many other open-sourced React Hooks libraries.
18
-
19
- You can use **foxact** with `<Suspense />`, `startTransition`, `<OffScreen />` without worrying about app falling apart.
15
+ All hooks and utils are React 18+ Concurrent Rendering resilient. **foxact** strictly follows React best practices, e.g. never read and write ref during the render phase, unlike many other open-sourced React Hooks libraries. You can use **foxact** with `<Suspense />`, `startTransition`, `<OffScreen />` without worrying about app falling apart.
20
16
 
21
17
  #### SSR Friendly
22
18
 
@@ -26,15 +22,15 @@ Supports [Next.js](https://nextjs.org) (both Pages Directory and App Router), [W
26
22
 
27
23
  #### Type Safe and Sound
28
24
 
29
- Written in TypeScript with TSDocs, supports TypeScript 4.8+.
25
+ Written in TypeScript. Unlocking strong typing benefits with TypeScript 4.8+.
30
26
 
31
27
  #### Super Lightweight
32
28
 
33
- The entire **foxact** library has zero dependencies and is **less than 5 KiB gzipped in sum**. And what's more...
29
+ The entire **foxact** library has zero dependencies and is **less than 5 KiB gzipped in sum**, ensuring a lean and efficient solution. And what's more...And what's more...
34
30
 
35
31
  #### Fully Tree Shakable
36
32
 
37
- Every hook and util is isolated and side-effects free. Feel free to take what you want from **foxact** without worrying about client bundle size.
33
+ Every hook and util is isolated and side-effects free, eliminating unused code and delivering leaner bundles for lightning-fast load times. Feel free to take what you want from **foxact** without worrying about client bundle size.
38
34
 
39
35
  ## License
40
36
 
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.cjs");exports.createContextState=function(n){let o=t.createContext(n),u=t.createContext(r.noop);return[r=>{let{children:i}=r,[a,c]=t.useState(n);return e.jsx(o.Provider,{value:a,children:e.jsx(u.Provider,{value:c,children:i})})},()=>t.useContext(o),()=>t.useContext(u)]};
1
+ "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.cjs");exports.createContextState=function(n){let o=t.createContext(n),u=t.createContext(r.noop);return[r=>{let{children:i}=r,[a,c]=t.useState(n);return e.jsx(o.Provider,{value:a,children:e.jsx(u.Provider,{value:c,children:i})})},()=>t.useContext(o),()=>t.useContext(u),o]};
@@ -2,6 +2,6 @@ import * as react from 'react';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
 
4
4
  /** @see https://foxact.skk.moe/context-state */
5
- declare function createContextState<T>(initialState: T): readonly [({ children }: React.PropsWithChildren) => react_jsx_runtime.JSX.Element, () => T, () => react.Dispatch<react.SetStateAction<T>>];
5
+ declare function createContextState<T>(initialState: T): readonly [({ children }: React.PropsWithChildren) => react_jsx_runtime.JSX.Element, () => T, () => react.Dispatch<react.SetStateAction<T>>, react.Context<T>];
6
6
 
7
7
  export { createContextState };
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.js");exports.createContextState=function(n){let o=t.createContext(n),u=t.createContext(r.noop);return[r=>{let{children:i}=r,[a,c]=t.useState(n);return e.jsx(o.Provider,{value:a,children:e.jsx(u.Provider,{value:c,children:i})})},()=>t.useContext(o),()=>t.useContext(u)]};
1
+ "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.js");exports.createContextState=function(n){let o=t.createContext(n),u=t.createContext(r.noop);return[r=>{let{children:i}=r,[a,c]=t.useState(n);return e.jsx(o.Provider,{value:a,children:e.jsx(u.Provider,{value:c,children:i})})},()=>t.useContext(o),()=>t.useContext(u),o]};
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import"client-only";import{useContext as e,useState as t,createContext as o}from"react";import{noop as i}from"../noop/index.mjs";function n(n){let m=o(n),l=o(i);return[e=>{let{children:o}=e,[i,c]=t(n);return r(m.Provider,{value:i,children:r(l.Provider,{value:c,children:o})})},()=>e(m),()=>e(l)]}export{n as createContextState};
1
+ import{jsx as r}from"react/jsx-runtime";import"client-only";import{createContext as e,useContext as t,useState as o}from"react";import{noop as i}from"../noop/index.mjs";function n(n){let m=e(n),l=e(i);return[e=>{let{children:t}=e,[i,c]=o(n);return r(m.Provider,{value:i,children:r(l.Provider,{value:c,children:t})})},()=>t(m),()=>t(l),m]}export{n as createContextState};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "React Hooks/Utils done right. For browser, SSR, and React Server Components.",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -74,15 +74,6 @@
74
74
  "require": "./noop/index.cjs",
75
75
  "default": "./noop/index.js"
76
76
  },
77
- "./request-idle-callback": {
78
- "types": "./request-idle-callback/index.d.ts",
79
- "import": {
80
- "types": "./request-idle-callback/index.d.ts",
81
- "default": "./request-idle-callback/index.mjs"
82
- },
83
- "require": "./request-idle-callback/index.cjs",
84
- "default": "./request-idle-callback/index.js"
85
- },
86
77
  "./typescript-happy-forward-ref": {
87
78
  "types": "./typescript-happy-forward-ref/index.d.ts",
88
79
  "import": {
@@ -92,6 +83,15 @@
92
83
  "require": "./typescript-happy-forward-ref/index.cjs",
93
84
  "default": "./typescript-happy-forward-ref/index.js"
94
85
  },
86
+ "./use": {
87
+ "types": "./use/index.d.ts",
88
+ "import": {
89
+ "types": "./use/index.d.ts",
90
+ "default": "./use/index.mjs"
91
+ },
92
+ "require": "./use/index.cjs",
93
+ "default": "./use/index.js"
94
+ },
95
95
  "./use-array": {
96
96
  "types": "./use-array/index.d.ts",
97
97
  "import": {
@@ -101,6 +101,15 @@
101
101
  "require": "./use-array/index.cjs",
102
102
  "default": "./use-array/index.js"
103
103
  },
104
+ "./request-idle-callback": {
105
+ "types": "./request-idle-callback/index.d.ts",
106
+ "import": {
107
+ "types": "./request-idle-callback/index.d.ts",
108
+ "default": "./request-idle-callback/index.mjs"
109
+ },
110
+ "require": "./request-idle-callback/index.cjs",
111
+ "default": "./request-idle-callback/index.js"
112
+ },
104
113
  "./use-clipboard": {
105
114
  "types": "./use-clipboard/index.d.ts",
106
115
  "import": {
@@ -110,6 +119,15 @@
110
119
  "require": "./use-clipboard/index.cjs",
111
120
  "default": "./use-clipboard/index.js"
112
121
  },
122
+ "./use-composition-input": {
123
+ "types": "./use-composition-input/index.d.ts",
124
+ "import": {
125
+ "types": "./use-composition-input/index.d.ts",
126
+ "default": "./use-composition-input/index.mjs"
127
+ },
128
+ "require": "./use-composition-input/index.cjs",
129
+ "default": "./use-composition-input/index.js"
130
+ },
113
131
  "./use-debounced-state": {
114
132
  "types": "./use-debounced-state/index.d.ts",
115
133
  "import": {
package/sizes.json CHANGED
@@ -1 +1 @@
1
- {"total":{"raw":6531,"gzip":4335},"exports":{"context-state":{"raw":369,"gzip":240},"create-context-state":{"raw":146,"gzip":119},"noop":{"raw":32,"gzip":52},"request-idle-callback":{"raw":407,"gzip":229},"typescript-happy-forward-ref":{"raw":118,"gzip":102},"use-array":{"raw":329,"gzip":241},"use-clipboard":{"raw":1071,"gzip":617},"use-debounced-state":{"raw":380,"gzip":273},"use-debounced-value":{"raw":370,"gzip":258},"use-error-boundary":{"raw":172,"gzip":157},"use-intersection":{"raw":1214,"gzip":649},"use-isomorphic-layout-effect":{"raw":177,"gzip":143},"use-map":{"raw":348,"gzip":246},"use-retimer":{"raw":197,"gzip":165},"use-set":{"raw":349,"gzip":242},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":461,"gzip":327},"use-uncontrolled":{"raw":391,"gzip":275}}}
1
+ {"total":{"raw":7145,"gzip":4735,"br":0},"exports":{"create-context-state":{"raw":146,"gzip":116,"br":102},"noop":{"raw":32,"gzip":52,"br":36},"typescript-happy-forward-ref":{"raw":118,"gzip":102,"br":87},"use":{"raw":279,"gzip":175,"br":151},"use-array":{"raw":329,"gzip":242,"br":201},"request-idle-callback":{"raw":407,"gzip":231,"br":180},"use-composition-input":{"raw":420,"gzip":262,"br":230},"context-state":{"raw":371,"gzip":240,"br":204},"use-debounced-value":{"raw":370,"gzip":263,"br":214},"use-error-boundary":{"raw":172,"gzip":157,"br":148},"use-isomorphic-layout-effect":{"raw":177,"gzip":143,"br":120},"use-intersection":{"raw":1214,"gzip":652,"br":592},"use-map":{"raw":348,"gzip":243,"br":210},"use-retimer":{"raw":197,"gzip":165,"br":125},"use-set":{"raw":349,"gzip":242,"br":203},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":461,"gzip":325,"br":256},"use-debounced-state":{"raw":380,"gzip":275,"br":231},"use-clipboard":{"raw":1071,"gzip":614,"br":527},"use-uncontrolled":{"raw":304,"gzip":236,"br":201}}}
package/use/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react");const e=t.use||(t=>{if("pending"===t.status)throw t;if("fulfilled"===t.status)return t.value;if("rejected"===t.status)throw t.reason;throw t.status="pending",t.then(e=>{t.status="fulfilled",t.value=e},e=>{t.status="rejected",t.reason=e}),t});exports.use=e;
package/use/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import react__default from 'react';
2
+
3
+ declare const use: typeof react__default.use;
4
+
5
+ export { use };
package/use/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react");const e=t.use||(t=>{if("pending"===t.status)throw t;if("fulfilled"===t.status)return t.value;if("rejected"===t.status)throw t.reason;throw t.status="pending",t.then(e=>{t.status="fulfilled",t.value=e},e=>{t.status="rejected",t.reason=e}),t});exports.use=e;
package/use/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import t from"react";let e=t.use||(t=>{if("pending"===t.status)throw t;if("fulfilled"===t.status)return t.value;if("rejected"===t.status)throw t.reason;throw t.status="pending",t.then(e=>{t.status="fulfilled",t.value=e},e=>{t.status="rejected",t.reason=e}),t});export{e as use};
@@ -0,0 +1 @@
1
+ "use strict";require("client-only");var e=require("react");exports.useCompositionInput=r=>{let t=e.useRef();t.current||(t.current={c:!1,e:!1});let u=e.useCallback(e=>{if("value"in e.target){let u=e.target.value;t.current.c?t.current.e=!1:(r(u),t.current.e=!0)}},[r]),c=e.useCallback(()=>{t.current.c=!0,t.current.e=!1},[]),n=e.useCallback(e=>{t.current.c=!1,t.current.e||u(e)},[u]);return{onChange:u,onCompositionStart:c,onCompositionEnd:n}};
@@ -0,0 +1,7 @@
1
+ type UseCompositionInputCallback = (value: string) => void;
2
+ type UseCompositionInputReturnKey = 'onChange' | 'onCompositionStart' | 'onCompositionEnd';
3
+ type UseCompositionInputReturn = Pick<JSX.IntrinsicElements['input'], UseCompositionInputReturnKey>;
4
+ /** @see https://foxact.skk.moe/use-composition-input */
5
+ declare const useCompositionInput: (cb: UseCompositionInputCallback) => UseCompositionInputReturn;
6
+
7
+ export { UseCompositionInputCallback, UseCompositionInputReturn, UseCompositionInputReturnKey, useCompositionInput };
@@ -0,0 +1 @@
1
+ "use strict";require("client-only");var e=require("react");exports.useCompositionInput=r=>{let t=e.useRef();t.current||(t.current={c:!1,e:!1});let u=e.useCallback(e=>{if("value"in e.target){let u=e.target.value;t.current.c?t.current.e=!1:(r(u),t.current.e=!0)}},[r]),c=e.useCallback(()=>{t.current.c=!0,t.current.e=!1},[]),n=e.useCallback(e=>{t.current.c=!1,t.current.e||u(e)},[u]);return{onChange:u,onCompositionStart:c,onCompositionEnd:n}};
@@ -0,0 +1 @@
1
+ import"client-only";import{useRef as e,useCallback as r}from"react";let t=t=>{let c=e();c.current||(c.current={c:!1,e:!1});let n=r(e=>{if("value"in e.target){let r=e.target.value;c.current.c?c.current.e=!1:(t(r),c.current.e=!0)}},[t]),u=r(()=>{c.current.c=!0,c.current.e=!1},[]),l=r(e=>{c.current.c=!1,c.current.e||n(e)},[n]);return{onChange:n,onCompositionStart:u,onCompositionEnd:l}};export{t as useCompositionInput};
@@ -1,3 +1,4 @@
1
+ /** @see https://foxact.skk.moe/use-debounced-state */
1
2
  declare function useDebouncedState<T>(defaultValue: T | (() => T), wait: number, leading?: boolean): readonly [T, (newValue: T) => void];
2
3
 
3
4
  export { useDebouncedState };
@@ -1,3 +1,4 @@
1
+ /** @see https://foxact.skk.moe/use-debounced-value */
1
2
  declare function useDebouncedValue<T>(value: T, wait: number, leading?: boolean): T;
2
3
 
3
4
  export { useDebouncedValue };
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @see https://foxact.skk.moe/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired
2
3
  * Similar to useCallback, with a few subtle differences:
3
4
  * - The returned function is a stable reference, and will always be the same between renders
4
5
  * - No dependency lists required
@@ -1 +1 @@
1
- "use strict";require("client-only");var e=require("react"),r=require("../noop/index.cjs");const t=e=>e;exports.useUncontrolled=function(n){let u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,[c,l]=e.useState(n),o=e.useRef(null),s=e.useRef(r.noop);e.useInsertionEffect(()=>{s.current=u},[u]);let i=e.useCallback(()=>{o.current&&l(s.current(o.current.value))},[]);return[c,i,o]};
1
+ "use strict";require("client-only");var e=require("react");const r=e=>e;exports.useUncontrolled=function(u){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r,t=e.useRef(null),n=e.useCallback((e,r)=>l(r),[l]),[c,s]=e.useReducer(n,u),a=e.useCallback(()=>{t.current&&s(t.current.value)},[]);return[c,a,t]};
@@ -1 +1 @@
1
- "use strict";require("client-only");var e=require("react"),r=require("../noop/index.js");const t=e=>e;exports.useUncontrolled=function(n){let u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,[c,l]=e.useState(n),o=e.useRef(null),s=e.useRef(r.noop);e.useInsertionEffect(()=>{s.current=u},[u]);let i=e.useCallback(()=>{o.current&&l(s.current(o.current.value))},[]);return[c,i,o]};
1
+ "use strict";require("client-only");var e=require("react");const r=e=>e;exports.useUncontrolled=function(u){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r,t=e.useRef(null),n=e.useCallback((e,r)=>l(r),[l]),[c,s]=e.useReducer(n,u),a=e.useCallback(()=>{t.current&&s(t.current.value)},[]);return[c,a,t]};
@@ -1 +1 @@
1
- import"client-only";import{useState as r,useRef as t,useInsertionEffect as e,useCallback as n}from"react";import{noop as o}from"../noop/index.mjs";let l=r=>r;function u(u){let c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l,[i,m]=r(u),p=t(null),d=t(o);e(()=>{d.current=c},[c]);let f=n(()=>{p.current&&m(d.current(p.current.value))},[]);return[i,f,p]}export{u as useUncontrolled};
1
+ import"client-only";import{useRef as t,useCallback as e,useReducer as r}from"react";let n=t=>t;function l(l){let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n,u=t(null),c=e((t,e)=>o(e),[o]),[i,m]=r(c,l),p=e(()=>{u.current&&m(u.current.value)},[]);return[i,p,u]}export{l as useUncontrolled};