tldraw/packages
alex 25328f98d0
refactor copy/export, fix safari copy-as-image being broken (#2411)
In #2198, we introduced a regression on ios around image exports. ios
will block copys if they're not called syncronously in a UI event. It's
important to make ios copys like this:
```ts
navigator.clipboard.write(new ClipboardItem(getStuffToCopyAsAPromise())
```

instead of
```ts
getStuffToCopyAsAPromise().then(stuff => {
    navigator.clipboard.write(new ClipboardItem(stuff))
})
```

We've written and fixed this bug a few times, which i think is because
of how our export/copy code is written: the formatting is interspersed
with interacting with the browser APIs, which makes it hard to change
one without accidentally affecting the other.

This diff fixes the bug, but also restructures our export/copy code: all
the formatting is handled by `exportToBlob` and related which just
return `Blob`s. This leaves `copyAs`, `exportAs` etc. to just handle
interacting with the browser APIs.

Fixes #2312

### Change Type

- [x] `patch` — Bug fix

### Test Plan

1. Test copy/export as on all browsers

### Release Notes

- Fix a bug preventing copying as an image on iOS

---------

Co-authored-by: huppy-bot[bot] <128400622+huppy-bot[bot]@users.noreply.github.com>
2024-01-09 14:50:10 +00:00
..
assets Fix trademark links (#2380) 2023-12-26 09:22:04 +00:00
editor [fix] next selected shapes comment (#2427) 2024-01-09 10:16:16 +00:00
state Update CHANGELOG.md [skip ci] 2023-12-20 15:27:34 +00:00
store Fix meta examples (#2379) 2024-01-03 08:26:22 +00:00
tldraw refactor copy/export, fix safari copy-as-image being broken (#2411) 2024-01-09 14:50:10 +00:00
tlschema Add url validation (#2428) 2024-01-09 10:49:57 +00:00
utils Add url validation (#2428) 2024-01-09 10:49:57 +00:00
validate Add url validation (#2428) 2024-01-09 10:49:57 +00:00