File tree Expand file tree Collapse file tree 5 files changed +52
-14
lines changed Expand file tree Collapse file tree 5 files changed +52
-14
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import { VueInput } from ' @vue/devtools-ui'
2
+ import { VueIcon , VueInput } from ' @vue/devtools-ui'
3
3
import AppConnecting from ' ~/components/AppConnecting.vue'
4
4
5
5
const props = defineProps <{
@@ -16,6 +16,8 @@ const _network = scriptWrapper(props.network!)
16
16
17
17
const local = ref (_local )
18
18
const network = ref (_network )
19
+
20
+ const { copy } = useCopy ()
19
21
</script >
20
22
21
23
<template >
@@ -28,11 +30,13 @@ const network = ref(_network)
28
30
<p class =" text-center text-sm op80 text-base" >
29
31
Add one of the following to the top of your page 👇:
30
32
</p >
31
- <div class =" mt-3 $ui-fcc flex-row" >
32
- <VueInput v-model =" local" left-icon =" i-carbon-copy" class =" w-400px!" />
33
+ <div class =" mt-3 $ui-fcc flex-row gap3" >
34
+ <VueInput v-model =" local" class =" w-380px!" />
35
+ <VueIcon icon =" i-carbon-copy" class =" cursor-pointer text-primary-300 hover:text-primary-500" @click =" copy(local)" />
33
36
</div >
34
- <div class =" mt-3 $ui-fcc flex-row" >
35
- <VueInput v-model =" network" left-icon =" i-carbon-copy" class =" w-400px!" />
37
+ <div class =" mt-3 $ui-fcc flex-row gap3" >
38
+ <VueInput v-model =" network" class =" w-380px!" />
39
+ <VueIcon icon =" i-carbon-copy" class =" cursor-pointer text-primary-300 hover:text-primary-500" @click =" copy(network)" />
36
40
</div >
37
41
</div >
38
42
</AppConnecting >
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ const codeSnippets = computed(() => {
57
57
return items
58
58
})
59
59
60
- const copy = useCopy ()
60
+ const { copy } = useCopy ()
61
61
const timeAgo = useTimeAgo (() => asset .value .mtime )
62
62
const fileSize = computed (() => {
63
63
const size = asset .value .size
@@ -159,7 +159,7 @@ const supportsPreview = computed(() => {
159
159
icon =" i-carbon-copy"
160
160
action mr1 mt--2px flex-none
161
161
:border =" false"
162
- @click =" copy(asset.publicPath, 'assets-public-path')"
162
+ @click =" copy(asset.publicPath, { silent: false, type: 'assets-public-path' } )"
163
163
/>
164
164
<RouterLink
165
165
:to =" asset.publicPath"
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const props = defineProps<{
9
9
}>()
10
10
11
11
const selected = shallowRef <CodeSnippet | undefined >(props .codeSnippets [0 ])
12
- const copy = useCopy ()
12
+ const { copy } = useCopy ()
13
13
14
14
const selectedLang = computed (() => (selected .value ?.lang || ' text' ) as BuiltinLanguage )
15
15
@@ -45,7 +45,7 @@ watchEffect(() => {
45
45
w-full of-auto p3
46
46
/>
47
47
<div flex =" ~ gap-2" px3 pb3 >
48
- <VueButton @click =" copy(selected!.code, eventType || `code-snippet-${selected.name}`)" >
48
+ <VueButton @click =" copy(selected!.code, { silent: false, type: eventType || `code-snippet-${selected.name}` } )" >
49
49
Copy
50
50
<template #icon >
51
51
<slot name =" i-carbon-copy" />
Original file line number Diff line number Diff line change
1
+ import { showVueNotification } from '@vue/devtools-ui'
2
+
3
+ interface CopyOptions {
4
+ silent ?: boolean
5
+ type ?: string
6
+ }
7
+
1
8
export function useCopy ( ) {
2
- const clipboard = useClipboard ( )
9
+ const { copy : _copy , copied } = useClipboard ( )
10
+
11
+ const copy = ( text : string , options : CopyOptions = { } ) => {
12
+ const {
13
+ silent = false ,
14
+ type = '' ,
15
+ } = options
16
+ _copy ( text ) . then ( ( ) => {
17
+ if ( ! silent ) {
18
+ showVueNotification ( {
19
+ message : 'Copied to clipboard' ,
20
+ type : 'success' ,
21
+ duration : 3000 ,
22
+ } )
23
+ }
24
+ } ) . catch ( ( ) => {
25
+ if ( ! silent ) {
26
+ showVueNotification ( {
27
+ message : 'Failed to copy to clipboard' ,
28
+ type : 'error' ,
29
+ duration : 3000 ,
30
+ } )
31
+ }
32
+ } )
33
+ }
3
34
4
- return ( text : string , type ?: string ) => {
5
- clipboard . copy ( text )
35
+ return {
36
+ copy,
37
+ copied,
6
38
}
7
39
}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const props = withDefaults(defineProps<{
15
15
loading? : boolean
16
16
autoFocus? : boolean
17
17
loadingDebounceTime? : number
18
+ readonly? : boolean
18
19
}>(), {
19
20
placeholder: ' ' ,
20
21
variant: ' normal' ,
@@ -26,6 +27,7 @@ const props = withDefaults(defineProps<{
26
27
loading: false ,
27
28
autoFocus: false ,
28
29
loadingDebounceTime: 0 ,
30
+ readonly: false ,
29
31
})
30
32
31
33
const emit = defineEmits <{
@@ -42,7 +44,7 @@ const focused = refWithControl(false, {
42
44
emit (' updateFocused' , value )
43
45
},
44
46
})
45
- const noFocusAnimation = computed (() => props .variant === ' flat' || props .variant === ' warning' )
47
+ const noFocusAnimation = computed (() => props .variant === ' flat' || props .variant === ' warning' || props . disabled || props . readonly )
46
48
47
49
const disabled = computed (() => props .disabled || loading .value )
48
50
@@ -100,7 +102,7 @@ watchEffect(() => {
100
102
<input
101
103
ref =" inputRef" v-model =" value"
102
104
class =" $ui-base w-full bg-transparent color-inherit outline-none placeholder-color-gray-500 dark:placeholder-gray-300" :type =" props.password ? 'password' : 'text'"
103
- :placeholder =" placeholder" :disabled =" disabled"
105
+ :placeholder =" placeholder" :disabled =" disabled || readonly "
104
106
@blur =" focused = false"
105
107
>
106
108
<div v-if =" loading" :class =" iconClasses" >
You can’t perform that action at this time.
0 commit comments