@reactuses/core 6.0.3 → 6.0.5

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/dist/index.cjs CHANGED
@@ -3308,17 +3308,38 @@ function _async_to_generator$1(fn) {
3308
3308
  }
3309
3309
  const useClipboard = ()=>{
3310
3310
  const [text, setText] = React.useState('');
3311
- const updateText = React.useCallback(()=>{
3312
- window.navigator.clipboard.readText().then((value)=>{
3311
+ const updateText = React.useCallback(/*#__PURE__*/ _async_to_generator$1(function*() {
3312
+ // Check if document is focused before attempting to read clipboard
3313
+ if (!document.hasFocus()) {
3314
+ return;
3315
+ }
3316
+ try {
3317
+ const value = yield window.navigator.clipboard.readText();
3313
3318
  setText(value);
3314
- });
3315
- }, []);
3319
+ } catch (error) {
3320
+ // Handle cases where clipboard access is denied or unavailable
3321
+ console.warn('Failed to read clipboard:', error);
3322
+ }
3323
+ }), []);
3316
3324
  useEventListener('copy', updateText);
3317
3325
  useEventListener('cut', updateText);
3326
+ // Also listen for focus events to update clipboard when window regains focus
3327
+ useEventListener('focus', updateText, window);
3318
3328
  const copy = React.useCallback(/*#__PURE__*/ _async_to_generator$1(function*(txt) {
3319
3329
  setText(txt);
3320
- yield window.navigator.clipboard.writeText(txt);
3330
+ try {
3331
+ yield window.navigator.clipboard.writeText(txt);
3332
+ } catch (error) {
3333
+ console.warn('Failed to write to clipboard:', error);
3334
+ throw error // Re-throw so caller can handle it
3335
+ ;
3336
+ }
3321
3337
  }), []);
3338
+ React.useEffect(()=>{
3339
+ updateText();
3340
+ }, [
3341
+ updateText
3342
+ ]);
3322
3343
  return [
3323
3344
  text,
3324
3345
  copy
package/dist/index.mjs CHANGED
@@ -3300,17 +3300,38 @@ function _async_to_generator$1(fn) {
3300
3300
  }
3301
3301
  const useClipboard = ()=>{
3302
3302
  const [text, setText] = useState('');
3303
- const updateText = useCallback(()=>{
3304
- window.navigator.clipboard.readText().then((value)=>{
3303
+ const updateText = useCallback(/*#__PURE__*/ _async_to_generator$1(function*() {
3304
+ // Check if document is focused before attempting to read clipboard
3305
+ if (!document.hasFocus()) {
3306
+ return;
3307
+ }
3308
+ try {
3309
+ const value = yield window.navigator.clipboard.readText();
3305
3310
  setText(value);
3306
- });
3307
- }, []);
3311
+ } catch (error) {
3312
+ // Handle cases where clipboard access is denied or unavailable
3313
+ console.warn('Failed to read clipboard:', error);
3314
+ }
3315
+ }), []);
3308
3316
  useEventListener('copy', updateText);
3309
3317
  useEventListener('cut', updateText);
3318
+ // Also listen for focus events to update clipboard when window regains focus
3319
+ useEventListener('focus', updateText, window);
3310
3320
  const copy = useCallback(/*#__PURE__*/ _async_to_generator$1(function*(txt) {
3311
3321
  setText(txt);
3312
- yield window.navigator.clipboard.writeText(txt);
3322
+ try {
3323
+ yield window.navigator.clipboard.writeText(txt);
3324
+ } catch (error) {
3325
+ console.warn('Failed to write to clipboard:', error);
3326
+ throw error // Re-throw so caller can handle it
3327
+ ;
3328
+ }
3313
3329
  }), []);
3330
+ useEffect(()=>{
3331
+ updateText();
3332
+ }, [
3333
+ updateText
3334
+ ]);
3314
3335
  return [
3315
3336
  text,
3316
3337
  copy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "6.0.3",
3
+ "version": "6.0.5",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {