bug fixes

This commit is contained in:
Steve Ruiz 2022-01-06 10:45:11 +00:00
parent 225f312bd0
commit 5c33fbd89c
2 changed files with 30 additions and 27 deletions

View file

@ -424,8 +424,10 @@ const InnerTldraw = React.memo(function InnerTldraw({
const elm = rWrapper.current
if (!elm) return
if (!elm.contains(e.relatedTarget)) return
elm.dispatchEvent(new Event('pointerdown', { bubbles: true }))
elm.dispatchEvent(new Event('pointerup', { bubbles: true }))
const event = new Event('pointerdown', { bubbles: true }) as any
event.pointerId = -1 // Hopefully fix a bug where @use-gesture tries to set pointer capture
elm.dispatchEvent(event)
elm.dispatchEvent(event)
}, [])
const isInSession = app.session !== undefined

View file

@ -1766,25 +1766,28 @@ export class TldrawApp extends StateManager<TDSnapshot> {
bindingsToPaste
)
}
try {
if (!('clipboard' in navigator && navigator.clipboard.readText)) {
throw Error('This browser does not support the clipboard API.')
TLDR.warn('This browser does not support the Clipboard API!')
if (this.clipboard) {
pasteInCurrentPage(this.clipboard.shapes, this.clipboard.bindings, this.clipboard.assets)
}
return
}
navigator.clipboard.readText().then((result) => {
try {
navigator.clipboard
.readText()
.then((result) => {
const data: {
type: string
shapes: TDShape[]
bindings: TDBinding[]
assets: TDAsset[]
} = JSON.parse(result)
if (data.type !== 'tldr/clipboard') {
throw Error('The pasted string was not from the Tldraw clipboard.')
}
if (data.type === 'tldr/clipboard') {
pasteInCurrentPage(data.shapes, data.bindings, data.assets)
} catch (e) {
TLDR.warn(e)
} else {
TLDR.warn('The selected shape was not a tldraw shape, treating as text.')
const shapeId = Utils.uniqueId()
this.createShapes({
id: shapeId,
@ -1797,14 +1800,12 @@ export class TldrawApp extends StateManager<TDSnapshot> {
this.select(shapeId)
}
})
} catch (e) {
// Navigator does not support clipboard. Note that this fallback will
// not support pasting from one document to another.
.catch(() => {
TLDR.warn('Read permissions denied!')
if (this.clipboard) {
pasteInCurrentPage(this.clipboard.shapes, this.clipboard.bindings, this.clipboard.assets)
}
}
})
return this
}