mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-09 23:08:29 +00:00
feature-web: allow pasting of valid URLs from clipboard
This commit is contained in:
parent
4d2c8b0a8c
commit
f29b4f7cb5
@ -2,6 +2,8 @@ const allowedLinkTypes = new Set(["text/plain", "text/uri-list"]);
|
||||
|
||||
export const pasteLinkFromClipboard = async () => {
|
||||
const clipboard = await navigator.clipboard.read();
|
||||
let pastedText = null;
|
||||
|
||||
|
||||
if (clipboard?.length) {
|
||||
const clipboardItem = clipboard[0];
|
||||
@ -9,9 +11,20 @@ export const pasteLinkFromClipboard = async () => {
|
||||
if (allowedLinkTypes.has(type)) {
|
||||
const blob = await clipboardItem.getType(type);
|
||||
const blobText = await blob.text();
|
||||
try {
|
||||
new URL(blobText);
|
||||
pastedText = blobText;
|
||||
break;
|
||||
} catch (e) {
|
||||
console.warn(`Content '${blobText}' is not a valid URL.`);
|
||||
}
|
||||
|
||||
return blobText;
|
||||
}
|
||||
}
|
||||
if(pastedText){
|
||||
return pastedText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,21 +1,17 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler",
|
||||
"types": ["turnstile-types"],
|
||||
"lib": ["WebWorker"]
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
|
||||
//
|
||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"types": ["turnstile-types"],
|
||||
"lib": ["WebWorker"]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user