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)) {
throw Error('This browser does not support the clipboard API.')
}
navigator.clipboard.readText().then((result) => { if (!('clipboard' in navigator && navigator.clipboard.readText)) {
try { TLDR.warn('This browser does not support the Clipboard API!')
const data: { if (this.clipboard) {
type: string pasteInCurrentPage(this.clipboard.shapes, this.clipboard.bindings, this.clipboard.assets)
shapes: TDShape[] }
bindings: TDBinding[] return
assets: TDAsset[] }
} = JSON.parse(result)
if (data.type !== 'tldr/clipboard') { navigator.clipboard
throw Error('The pasted string was not from the Tldraw clipboard.') .readText()
} .then((result) => {
const data: {
type: string
shapes: TDShape[]
bindings: TDBinding[]
assets: TDAsset[]
} = JSON.parse(result)
if (data.type === 'tldr/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
} }