Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

docs(useClipboardItems): fix demo by using text/plain mime type #4513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions 15 packages/core/useClipboardItems/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ const input = ref('')

const { content, isSupported, copy } = useClipboardItems()
const computedText = ref('')
const computedMimeType = ref('')
effect(() => {
Promise.all(content.value.map(item => item.getType('text/html')))
.then((blobs) => {
return Promise.all(blobs.map(blob => blob.text()))
})
.then((texts) => {
computedText.value = texts.join('')
Promise.all(content.value.map(item => item.getType('text/plain')))
.then(async (blobs) => {
computedMimeType.value = blobs.map(blob => blob.type).join(', ')
computedText.value = (await Promise.all(blobs.map(blob => blob.text()))).join(', ')
})
})
const permissionRead = usePermission('clipboard-read')
const permissionWrite = usePermission('clipboard-write')

function createClipboardItems(text: string) {
const mime = 'text/html'
const mime = 'text/plain'
const blob = new Blob([text], { type: mime })
return new ClipboardItem({
[mime]: blob,
Expand All @@ -34,7 +33,7 @@ function createClipboardItems(text: string) {
<b>{{ permissionWrite }}</b>
</note>
<p>
Current copied: <code>{{ (computedText && `${computedText} (mime: text/html)`) || "none" }}</code>
Current copied: <code>{{ (computedText && `${computedText} (mime: ${computedMimeType})`) || "none" }}</code>
</p>
<input v-model="input" type="text">
<button
Expand Down
4 changes: 2 additions & 2 deletions 4 packages/core/useClipboardItems/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Reactive [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipbo
```js
import { useClipboardItems } from '@vueuse/core'

const mime = 'text/html'
const mime = 'text/plain'
const source = ref([
new ClipboardItem({
[mime]: new Blob(['<b>HTML content</b>'], { type: mime }),
[mime]: new Blob(['plain text'], { type: mime }),
})
])

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.