foxact 0.2.7 → 0.2.8
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/package.json +10 -1
- package/sizes.json +1 -1
- package/use-clipboard/index.cjs +1 -1
- package/use-clipboard/index.d.ts +2 -1
- package/use-clipboard/index.js +1 -1
- package/use-clipboard/index.mjs +1 -1
- package/use-isomorphic-layout-effect/index.d.ts +3 -3
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs +1 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts +9 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js +1 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxact",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "React Hooks/Utils done right. For browser, SSR, and React Server Components.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -164,6 +164,15 @@
|
|
|
164
164
|
"require": "./use-set/index.cjs",
|
|
165
165
|
"default": "./use-set/index.js"
|
|
166
166
|
},
|
|
167
|
+
"./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired": {
|
|
168
|
+
"types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
|
|
169
|
+
"import": {
|
|
170
|
+
"types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
|
|
171
|
+
"default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs"
|
|
172
|
+
},
|
|
173
|
+
"require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
|
|
174
|
+
"default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js"
|
|
175
|
+
},
|
|
167
176
|
"./use-uncontrolled": {
|
|
168
177
|
"types": "./use-uncontrolled/index.d.ts",
|
|
169
178
|
"import": {
|
package/sizes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"total":{"raw":
|
|
1
|
+
{"total":{"raw":5781,"gzip":3804},"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-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}}}
|
package/use-clipboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");class
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),r=require("../noop/index.cjs"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs");class a extends Error{}exports.UseClipboardError=a,exports.useClipboard=function(){let{timeout:l=1e3,usePromptAsFallback:o=!1,promptFallbackText:i="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[u,c]=e.useState(null),[s,d]=e.useState(!1),p=e.useRef(null),b=t.useStableHandler(n||r.noop),w=e.useCallback(e=>{p.current&&clearTimeout(p.current),e&&(p.current=window.setTimeout(()=>d(!1),l)),d(e)},[l]),y=e.useCallback(e=>{c(e),b(e)},[b]),h=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),w(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(r){if(o)try{window.prompt(i,e)}catch(e){y(e)}else y(r)}},[w,i,y,o]),x=e.useCallback(()=>{d(!1),c(null),p.current&&clearTimeout(p.current)},[]);return{copy:h,reset:x,error:u,copied:s}};
|
package/use-clipboard/index.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ interface UseClipboardOption {
|
|
|
4
4
|
timeout?: number;
|
|
5
5
|
usePromptAsFallback?: boolean;
|
|
6
6
|
promptFallbackText?: string;
|
|
7
|
+
onCopyError?: (error: Error) => void;
|
|
7
8
|
}
|
|
8
9
|
/** @see https://foxact.skk.moe/use-clipboard */
|
|
9
|
-
declare function useClipboard({ timeout, usePromptAsFallback, promptFallbackText }?: UseClipboardOption): {
|
|
10
|
+
declare function useClipboard({ timeout, usePromptAsFallback, promptFallbackText, onCopyError }?: UseClipboardOption): {
|
|
10
11
|
copy: (valueToCopy: string) => Promise<void>;
|
|
11
12
|
reset: () => void;
|
|
12
13
|
error: Error | null;
|
package/use-clipboard/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");class
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),r=require("../noop/index.js"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js");class a extends Error{}exports.UseClipboardError=a,exports.useClipboard=function(){let{timeout:l=1e3,usePromptAsFallback:o=!1,promptFallbackText:i="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[u,c]=e.useState(null),[s,d]=e.useState(!1),p=e.useRef(null),b=t.useStableHandler(n||r.noop),w=e.useCallback(e=>{p.current&&clearTimeout(p.current),e&&(p.current=window.setTimeout(()=>d(!1),l)),d(e)},[l]),y=e.useCallback(e=>{c(e),b(e)},[b]),h=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),w(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(r){if(o)try{window.prompt(i,e)}catch(e){y(e)}else y(r)}},[w,i,y,o]),x=e.useCallback(()=>{d(!1),c(null),p.current&&clearTimeout(p.current)},[]);return{copy:h,reset:x,error:u,copied:s}};
|
package/use-clipboard/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"client-only";import{useState as r,useRef as
|
|
1
|
+
import"client-only";import{useState as r,useRef as o,useCallback as e}from"react";import{noop as t}from"../noop/index.mjs";import{useStableHandler as i}from"../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs";class a extends Error{}function l(){let{timeout:l=1e3,usePromptAsFallback:n=!1,promptFallbackText:c="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:u}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[p,d]=r(null),[s,m]=r(!1),w=o(null),y=i(u||t),b=e(r=>{w.current&&clearTimeout(w.current),r&&(w.current=window.setTimeout(()=>m(!1),l)),m(r)},[l]),f=e(r=>{d(r),y(r)},[y]),h=e(async r=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(r),b(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(o){if(n)try{window.prompt(c,r)}catch(r){f(r)}else f(o)}},[b,c,f,n]),x=e(()=>{m(!1),d(null),w.current&&clearTimeout(w.current)},[]);return{copy:h,reset:x,error:p,copied:s}}export{a as UseClipboardError,l as useClipboard};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useLayoutEffect as useLayoutEffect$1 } from 'react';
|
|
2
2
|
|
|
3
3
|
/** @see https://foxact.skk.moe/use-isomorphic-layout-effect */
|
|
4
|
-
declare const useIsomorphicLayoutEffect: typeof
|
|
4
|
+
declare const useIsomorphicLayoutEffect: typeof useLayoutEffect$1;
|
|
5
5
|
/** @see https://foxact.skk.moe/use-isomorphic-layout-effect */
|
|
6
|
-
declare const useLayoutEffect: typeof
|
|
6
|
+
declare const useLayoutEffect: typeof useLayoutEffect$1;
|
|
7
7
|
|
|
8
8
|
export { useIsomorphicLayoutEffect, useLayoutEffect };
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("react");const t="undefined"!=typeof window?e.useInsertionEffect||e.useLayoutEffect:e.useEffect;function r(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}exports.useStableHandler=function(n){let o=e.useRef(r);return t(()=>{o.current=n},[n]),e.useCallback(function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];let n=o.current;return n(...t)},[])};
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similar to useCallback, with a few subtle differences:
|
|
3
|
+
* - The returned function is a stable reference, and will always be the same between renders
|
|
4
|
+
* - No dependency lists required
|
|
5
|
+
* - Properties or state accessed within the callback will always be "current"
|
|
6
|
+
*/
|
|
7
|
+
declare function useStableHandler<Args extends any[], Result>(callback: (...args: Args) => Result): typeof callback;
|
|
8
|
+
|
|
9
|
+
export { useStableHandler };
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("react");const t="undefined"!=typeof window?e.useInsertionEffect||e.useLayoutEffect:e.useEffect;function r(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}exports.useStableHandler=function(n){let o=e.useRef(r);return t(()=>{o.current=n},[n]),e.useCallback(function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];let n=o.current;return n(...t)},[])};
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useLayoutEffect as t,useEffect as n,useRef as r,useCallback as o}from"react";let f="undefined"!=typeof window?e.useInsertionEffect||t:n;function u(e){let t=r(a);return f(()=>{t.current=e},[e]),o(function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];let o=t.current;return o(...n)},[])}function a(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}export{u as useStableHandler};
|