Skip to content
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

feat:-add-paste-file-feature-for-base64-file-converter #121

Open
wants to merge 2 commits into
base: developing/2.0.0
Choose a base branch
from
Open
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
24 changes: 21 additions & 3 deletions src/tools/base64-file-converter/base64-file-converter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,28 @@ async function onUpload(file: File) {
fileInput.value = file;
}
}

function onPaste(event: ClipboardEvent) {
if (event.clipboardData) {
const { items } = event.clipboardData;
for (const item of items) {
if (item.kind === 'file') {
fileInput.value = item.getAsFile()!;
}
else if (item.kind === 'string' && item.type.match('^text/plain')) {
item.getAsString(s => base64Input.value = s);
}
else {
// eslint-disable-next-line no-console
console.info('Unsupport clipboardData', item);
}
}
}
}
</script>

<template>
<c-card title="Base64 to file">
<c-card title="Base64 to file" @paste="onPaste">
<n-grid cols="3" x-gap="12">
<n-gi span="2">
<c-input-text
Expand Down Expand Up @@ -121,8 +139,8 @@ async function onUpload(file: File) {
</div>
</c-card>

<c-card title="File to base64">
<c-file-upload title="Drag and drop a file here, or click to select a file" @file-upload="onUpload" />
<c-card title="File to base64" @paste="onPaste">
<c-file-upload title="Drag and drop a file here, Focus this card and paste a file here, or click to select a file" @file-upload="onUpload" />
<c-input-text :value="fileBase64" multiline readonly placeholder="File in base64 will be here" rows="5" my-2 />

<div flex justify-center>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "**/*.d.ts", "node_modules/vite-plugin-pwa/client.d.ts"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"lib": ["ES2022"],
"lib": ["ES2022", "DOM.Iterable"],
"target": "es2022",
"module": "es2022",
"moduleResolution": "Node",
Expand Down
Loading