mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-26 02:10:07 +00:00
CopyTextToClipboard fixed for mobile browsers (#7672)
This commit is contained in:
parent
8e498027f6
commit
475e7ee62d
@ -549,6 +549,23 @@ export async function getBlobURL (blob: Blob): Promise<string> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function copyTextToClipboardOldBrowser (text: string): void {
|
||||||
|
const textarea = document.createElement('textarea')
|
||||||
|
textarea.value = text
|
||||||
|
textarea.classList.add('hulyClipboardArea')
|
||||||
|
document.body.appendChild(textarea)
|
||||||
|
textarea.select()
|
||||||
|
try {
|
||||||
|
document.execCommand('copy')
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
document.body.removeChild(textarea)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -562,7 +579,9 @@ export async function copyTextToClipboard (text: string | Promise<string>): Prom
|
|||||||
await navigator.clipboard.write([clipboardItem])
|
await navigator.clipboard.write([clipboardItem])
|
||||||
} catch {
|
} catch {
|
||||||
// Fallback to default clipboard API implementation
|
// Fallback to default clipboard API implementation
|
||||||
await navigator.clipboard.writeText(text instanceof Promise ? await text : text)
|
if (navigator.clipboard != null && typeof navigator.clipboard.writeText === 'function') {
|
||||||
|
await navigator.clipboard.writeText(text instanceof Promise ? await text : text)
|
||||||
|
} else copyTextToClipboardOldBrowser(text instanceof Promise ? await text : text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,6 +917,11 @@ a.no-line {
|
|||||||
|
|
||||||
.text-line-through { text-decoration: line-through; }
|
.text-line-through { text-decoration: line-through; }
|
||||||
|
|
||||||
|
.hulyClipboardArea {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
.hidden-text {
|
.hidden-text {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
@ -9,7 +9,14 @@ import {
|
|||||||
getCurrentAccount
|
getCurrentAccount
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import { type Asset, type IntlString, type Resource, getResource } from '@hcengineering/platform'
|
import { type Asset, type IntlString, type Resource, getResource } from '@hcengineering/platform'
|
||||||
import { MessageBox, getClient, updateAttribute, type ContextStore, contextStore } from '@hcengineering/presentation'
|
import {
|
||||||
|
MessageBox,
|
||||||
|
getClient,
|
||||||
|
updateAttribute,
|
||||||
|
type ContextStore,
|
||||||
|
contextStore,
|
||||||
|
copyTextToClipboardOldBrowser
|
||||||
|
} from '@hcengineering/presentation'
|
||||||
import {
|
import {
|
||||||
type AnyComponent,
|
type AnyComponent,
|
||||||
type AnySvelteComponent,
|
type AnySvelteComponent,
|
||||||
@ -73,7 +80,9 @@ async function CopyTextToClipboard (
|
|||||||
const text = Array.isArray(doc)
|
const text = Array.isArray(doc)
|
||||||
? (await Promise.all(doc.map(async (d) => await getText(d, props.props)))).join(',')
|
? (await Promise.all(doc.map(async (d) => await getText(d, props.props)))).join(',')
|
||||||
: await getText(doc, props.props)
|
: await getText(doc, props.props)
|
||||||
await navigator.clipboard.writeText(text)
|
if (navigator.clipboard != null && typeof navigator.clipboard.writeText === 'function') {
|
||||||
|
await navigator.clipboard.writeText(text)
|
||||||
|
} else copyTextToClipboardOldBrowser(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user