More clipboard write fixes, add utility function (#2286)

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2022-10-06 15:38:47 +06:00
committed by GitHub
parent a0814a356f
commit d2a16ffd72
9 changed files with 30 additions and 21 deletions
@@ -14,6 +14,7 @@
-->
<script lang="ts">
import { Asset, IntlString } from '@hcengineering/platform'
import { copyTextToClipboard } from '@hcengineering/presentation'
import { Button } from '@hcengineering/ui'
export let icon: Asset
@@ -25,5 +26,5 @@
{icon}
kind={'transparent'}
showTooltip={{ label: title, direction: 'bottom' }}
on:click={() => navigator.clipboard.writeText(text)}
on:click={() => copyTextToClipboard(text)}
/>
+2 -12
View File
@@ -1,5 +1,5 @@
import { Doc, DocumentUpdate, Ref, RelatedDocument, TxOperations } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import { copyTextToClipboard, getClient } from '@hcengineering/presentation'
import { Issue, Project, Sprint, Team, trackerId } from '@hcengineering/tracker'
import { getCurrentLocation, getPanelURI, Location } from '@hcengineering/ui'
import { workbenchId } from '@hcengineering/workbench'
@@ -48,17 +48,7 @@ export async function copyToClipboard (object: Issue, ev: Event, { type }: { typ
return
}
try {
// Chromium
await navigator.clipboard.writeText(text)
} catch {
// Safari specific behavior
// see https://bugs.webkit.org/show_bug.cgi?id=222262
const clipboardItem = new ClipboardItem({
'text/plain': Promise.resolve(text)
})
await navigator.clipboard.write([clipboardItem])
}
await copyTextToClipboard(text)
}
export function generateIssueShortLink (issueId: string): string {