File tree 4 files changed +33
-8
lines changed
bundle/hooks/useClipboard
4 files changed +33
-8
lines changed Original file line number Diff line number Diff line change 1
- import { useCallback , useEffect , useState } from 'react' ;
1
+ import { useEffect , useState } from 'react' ;
2
2
import { usePermission } from '../usePermission/usePermission' ;
3
3
export const isPermissionAllowed = ( status ) => status === 'granted' || status === 'prompt' ;
4
4
export const legacyCopyToClipboard = ( value ) => {
@@ -53,7 +53,7 @@ export const useClipboard = (params) => {
53
53
document . removeEventListener ( 'cut' , set ) ;
54
54
} ;
55
55
} , [ enabled ] ) ;
56
- const copy = useCallback ( async ( value ) => {
56
+ const copy = async ( value ) => {
57
57
try {
58
58
if ( supported || isPermissionAllowed ( clipboardWritePermissionWrite . state ) ) {
59
59
await navigator . clipboard . writeText ( value ) ;
@@ -66,6 +66,19 @@ export const useClipboard = (params) => {
66
66
legacyCopyToClipboard ( value ) ;
67
67
}
68
68
setValue ( value ) ;
69
- } , [ ] ) ;
69
+ } ;
70
70
return { supported, value, copy } ;
71
71
} ;
72
+ export const copy = async ( value ) => {
73
+ try {
74
+ try {
75
+ await navigator . clipboard . writeText ( value ) ;
76
+ }
77
+ catch {
78
+ return legacyCopyToClipboard ( value ) ;
79
+ }
80
+ }
81
+ catch {
82
+ return legacyCopyToClipboard ( value ) ;
83
+ }
84
+ } ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const Demo = () => {
20
20
< div
21
21
ref = { clickOutsideRef }
22
22
className = { cn (
23
- 'relative flex flex-col items-center justify-center rounded-lg border border-red-500 p-12' ,
23
+ 'relative flex flex-col items-center justify-center rounded-xl border-2 border-red-500 p-12' ,
24
24
{ 'border-green-500' : counter . value > 5 }
25
25
) }
26
26
>
Original file line number Diff line number Diff line change 1
- import { useCallback , useEffect , useState } from 'react' ;
1
+ import { useEffect , useState } from 'react' ;
2
2
3
3
import { usePermission } from '../usePermission/usePermission' ;
4
4
@@ -76,7 +76,7 @@ export const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipbo
76
76
} ;
77
77
} , [ enabled ] ) ;
78
78
79
- const copy = useCallback ( async ( value : string ) => {
79
+ const copy = async ( value : string ) => {
80
80
try {
81
81
if ( supported || isPermissionAllowed ( clipboardWritePermissionWrite . state ) ) {
82
82
await navigator . clipboard . writeText ( value ) ;
@@ -88,7 +88,19 @@ export const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipbo
88
88
}
89
89
90
90
setValue ( value ) ;
91
- } , [ ] ) ;
91
+ } ;
92
92
93
93
return { supported, value, copy } ;
94
94
} ;
95
+
96
+ export const copy = async ( value : string ) => {
97
+ try {
98
+ try {
99
+ await navigator . clipboard . writeText ( value ) ;
100
+ } catch {
101
+ return legacyCopyToClipboard ( value ) ;
102
+ }
103
+ } catch {
104
+ return legacyCopyToClipboard ( value ) ;
105
+ }
106
+ } ;
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ export default {
104
104
example,
105
105
description : jsdoc . description . description ,
106
106
category : jsdoc . category ! . name ,
107
- lastModified : new Date ( lastCommit . date ) . getTime ( ) ,
107
+ lastModified : new Date ( lastCommit ? .date ?? new Date ( ) ) . getTime ( ) ,
108
108
usage,
109
109
apiParameters : jsdoc . apiParameters ?? [ ] ,
110
110
contributors
You can’t perform that action at this time.
0 commit comments