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 const elm = rWrapper.current
if (!elm) return if (!elm) return
if (!elm.contains(e.relatedTarget)) return if (!elm.contains(e.relatedTarget)) return
elm.dispatchEvent(new Event('pointerdown', { bubbles: true })) const event = new Event('pointerdown', { bubbles: true }) as any
elm.dispatchEvent(new Event('pointerup', { bubbles: true })) 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 const isInSession = app.session !== undefined

View file

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