fix(copy): prevent shorthand copy if source is present in useCopy (#559)
* fix(copy): prevent shorthand copy if source is present in useCopy * refactor(copy): normalized copy usage
This commit is contained in:
		
							parent
							
								
									7b6232a151
								
							
						
					
					
						commit
						86e964a274
					
				| @ -7,7 +7,13 @@ export function useCopy({ source, text = 'Copied to the clipboard' }: { source?: | |||||||
| 
 | 
 | ||||||
|   return { |   return { | ||||||
|     async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) { |     async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) { | ||||||
|       await copy(content); |       if (source) { | ||||||
|  |         await copy(); | ||||||
|  |       } | ||||||
|  |       else { | ||||||
|  |         await copy(content); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       message.success(notificationMessage ?? text); |       message.success(notificationMessage ?? text); | ||||||
|     }, |     }, | ||||||
|   }; |   }; | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ const { copy } = useCopy({ source: header, text: 'Header copied to the clipboard | |||||||
|       </n-statistic> |       </n-statistic> | ||||||
|     </c-card> |     </c-card> | ||||||
|     <div mt-5 flex justify-center> |     <div mt-5 flex justify-center> | ||||||
|       <c-button @click="copy"> |       <c-button @click="copy()"> | ||||||
|         Copy header |         Copy header | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash | |||||||
|     <c-input-text :value="hashed" readonly text-center /> |     <c-input-text :value="hashed" readonly text-center /> | ||||||
| 
 | 
 | ||||||
|     <div mt-5 flex justify-center> |     <div mt-5 flex justify-center> | ||||||
|       <c-button @click="copy"> |       <c-button @click="copy()"> | ||||||
|         Copy hash |         Copy hash | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -151,10 +151,10 @@ function copyAsBulletList() { | |||||||
|         </tbody> |         </tbody> | ||||||
|       </n-table> |       </n-table> | ||||||
|       <div mt-5 flex justify-center gap-3> |       <div mt-5 flex justify-center gap-3> | ||||||
|         <c-button @click="copyAsMarkdown"> |         <c-button @click="copyAsMarkdown()"> | ||||||
|           Copy as markdown table |           Copy as markdown table | ||||||
|         </c-button> |         </c-button> | ||||||
|         <c-button @click="copyAsBulletList"> |         <c-button @click="copyAsBulletList()"> | ||||||
|           Copy as bullet list |           Copy as bullet list | ||||||
|         </c-button> |         </c-button> | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
| @ -100,12 +100,12 @@ const { copy: copyPassphrase } = useCopy({ source: passphrase, text: 'Passphrase | |||||||
|           <n-input-group> |           <n-input-group> | ||||||
|             <c-input-text v-model:value="entropy" placeholder="Your string..." /> |             <c-input-text v-model:value="entropy" placeholder="Your string..." /> | ||||||
| 
 | 
 | ||||||
|             <c-button @click="refreshEntropy"> |             <c-button @click="refreshEntropy()"> | ||||||
|               <n-icon size="22"> |               <n-icon size="22"> | ||||||
|                 <Refresh /> |                 <Refresh /> | ||||||
|               </n-icon> |               </n-icon> | ||||||
|             </c-button> |             </c-button> | ||||||
|             <c-button @click="copyEntropy"> |             <c-button @click="copyEntropy()"> | ||||||
|               <n-icon size="22"> |               <n-icon size="22"> | ||||||
|                 <Copy /> |                 <Copy /> | ||||||
|               </n-icon> |               </n-icon> | ||||||
| @ -122,7 +122,7 @@ const { copy: copyPassphrase } = useCopy({ source: passphrase, text: 'Passphrase | |||||||
|       <n-input-group> |       <n-input-group> | ||||||
|         <c-input-text v-model:value="passphrase" placeholder="Your mnemonic..." raw-text /> |         <c-input-text v-model:value="passphrase" placeholder="Your mnemonic..." raw-text /> | ||||||
| 
 | 
 | ||||||
|         <c-button @click="copyPassphrase"> |         <c-button @click="copyPassphrase()"> | ||||||
|           <n-icon size="22" :component="Copy" /> |           <n-icon size="22" :component="Copy" /> | ||||||
|         </c-button> |         </c-button> | ||||||
|       </n-input-group> |       </n-input-group> | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ const { copy: copyUnescaped } = useCopy({ source: unescapeOutput }); | |||||||
|     </n-form-item> |     </n-form-item> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button @click="copyEscaped"> |       <c-button @click="copyEscaped()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
| @ -66,7 +66,7 @@ const { copy: copyUnescaped } = useCopy({ source: unescapeOutput }); | |||||||
|     </n-form-item> |     </n-form-item> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button @click="copyUnescaped"> |       <c-button @click="copyUnescaped()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to | |||||||
|     <c-input-text :value="loremIpsumText" multiline placeholder="Your lorem ipsum..." readonly mt-5 rows="5" /> |     <c-input-text :value="loremIpsumText" multiline placeholder="Your lorem ipsum..." readonly mt-5 rows="5" /> | ||||||
| 
 | 
 | ||||||
|     <div mt-5 flex justify-center> |     <div mt-5 flex justify-center> | ||||||
|       <c-button autofocus @click="copy"> |       <c-button autofocus @click="copy()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ const { copy } = useCopy({ source: details, text: 'Vendor info copied to the cli | |||||||
|     </c-card> |     </c-card> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button :disabled="!details" @click="copy"> |       <c-button :disabled="!details" @click="copy()"> | ||||||
|         Copy vendor info |         Copy vendor info | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ const { copy } = useCopy({ source: port, text: 'Port copied to the clipboard' }) | |||||||
|       {{ port }} |       {{ port }} | ||||||
|     </div> |     </div> | ||||||
|     <div flex justify-center gap-3> |     <div flex justify-center gap-3> | ||||||
|       <c-button @click="copy"> |       <c-button @click="copy()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|       <c-button @click="refreshPort"> |       <c-button @click="refreshPort"> | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic numb | |||||||
|         <div class="result"> |         <div class="result"> | ||||||
|           {{ outputRoman }} |           {{ outputRoman }} | ||||||
|         </div> |         </div> | ||||||
|         <c-button autofocus :disabled="validationNumeral.validationStatus === 'error'" @click="copyRoman"> |         <c-button autofocus :disabled="validationNumeral.validationStatus === 'error'" @click="copyRoman()"> | ||||||
|           Copy |           Copy | ||||||
|         </c-button> |         </c-button> | ||||||
|       </div> |       </div> | ||||||
| @ -61,7 +61,7 @@ const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic numb | |||||||
|         <div class="result"> |         <div class="result"> | ||||||
|           {{ outputNumeral }} |           {{ outputNumeral }} | ||||||
|         </div> |         </div> | ||||||
|         <c-button :disabled="!validationRoman.isValid" @click="copyArabic"> |         <c-button :disabled="!validationRoman.isValid" @click="copyArabic()"> | ||||||
|           Copy |           Copy | ||||||
|         </c-button> |         </c-button> | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ const { copy } = useCopy({ source: slug, text: 'Slug copied to clipboard' }); | |||||||
|     <c-input-text :value="slug" multiline readonly placeholder="You slug will be generated here (ex: my-file-path)" label="Your slug" mb-5 /> |     <c-input-text :value="slug" multiline readonly placeholder="You slug will be generated here (ex: my-file-path)" label="Your slug" mb-5 /> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button :disabled="slug.length === 0" @click="copy"> |       <c-button :disabled="slug.length === 0" @click="copy()"> | ||||||
|         Copy slug |         Copy slug | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied. | |||||||
|       </c-card> |       </c-card> | ||||||
| 
 | 
 | ||||||
|       <div mt-3 flex justify-center> |       <div mt-3 flex justify-center> | ||||||
|         <c-button autofocus @click="copy"> |         <c-button autofocus @click="copy()"> | ||||||
|           Copy NATO string |           Copy NATO string | ||||||
|         </c-button> |         </c-button> | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
| @ -66,7 +66,7 @@ const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard' | |||||||
|       /> |       /> | ||||||
| 
 | 
 | ||||||
|       <div mt-5 flex justify-center gap-3> |       <div mt-5 flex justify-center gap-3> | ||||||
|         <c-button @click="copy"> |         <c-button @click="copy()"> | ||||||
|           Copy |           Copy | ||||||
|         </c-button> |         </c-button> | ||||||
|         <c-button @click="refreshToken"> |         <c-button @click="refreshToken"> | ||||||
|  | |||||||
| @ -60,7 +60,7 @@ const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded str | |||||||
|     /> |     /> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button @click="copyEncoded"> |       <c-button @click="copyEncoded()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
| @ -89,7 +89,7 @@ const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded str | |||||||
|     /> |     /> | ||||||
| 
 | 
 | ||||||
|     <div flex justify-center> |     <div flex justify-center> | ||||||
|       <c-button @click="copyDecoded"> |       <c-button @click="copyDecoded()"> | ||||||
|         Copy |         Copy | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user