This commit is contained in:
Steve Ruiz 2021-12-27 18:50:33 +00:00
commit 7c02a6d514
5 changed files with 29 additions and 28 deletions

View file

@ -120,6 +120,8 @@ export class StateManager<T extends Record<string, any>> {
* Save the current state to indexdb. * Save the current state to indexdb.
*/ */
protected persist = (id?: string): void | Promise<void> => { protected persist = (id?: string): void | Promise<void> => {
if (this._status !== 'ready') return
if (this.onPersist) { if (this.onPersist) {
this.onPersist(this._state, id) this.onPersist(this._state, id)
} }

View file

@ -634,40 +634,25 @@ describe('TldrawTestApp', () => {
jest.setTimeout(10000) jest.setTimeout(10000)
describe('When changing versions', () => { describe('When changing versions', () => {
it('migrates correctly', (done) => { it('migrates correctly', async () => {
const defaultState = TldrawTestApp.defaultState const defaultState = TldrawTestApp.defaultState
const withoutRoom = { const withoutRoom = {
...defaultState, ...defaultState,
} }
delete withoutRoom.room delete withoutRoom.room
TldrawTestApp.defaultState = withoutRoom TldrawTestApp.defaultState = withoutRoom
const app = new TldrawTestApp('migrate_1') const app = new TldrawTestApp('migrate_1')
await app.ready
app.createShapes({ app.createShapes({
id: 'rect1', id: 'rect1',
type: TDShapeType.Rectangle, type: TDShapeType.Rectangle,
}) })
setTimeout(() => {
// TODO: Force the version to change and restore room.
TldrawTestApp.version = 100 TldrawTestApp.version = 100
TldrawTestApp.defaultState.room = defaultState.room TldrawTestApp.defaultState.room = defaultState.room
const app2 = new TldrawTestApp('migrate_1') const app2 = new TldrawTestApp('migrate_1')
await app2.ready
setTimeout(() => {
try {
expect(app2.getShape('rect1')).toBeTruthy() expect(app2.getShape('rect1')).toBeTruthy()
done() return
} catch (e) {
done(e)
}
}, 100)
}, 100)
}) })
}) })

View file

@ -360,8 +360,12 @@ export class TldrawApp extends StateManager<TDSnapshot> {
const toShape = page.shapes[binding.toId] const toShape = page.shapes[binding.toId]
const fromShape = page.shapes[binding.fromId] const fromShape = page.shapes[binding.fromId]
const toUtils = TLDR.getShapeUtil(toShape) if (!(toShape && fromShape)) {
delete next.document.pages[pageId].bindings[binding.id]
return
}
const toUtils = TLDR.getShapeUtil(toShape)
const fromUtils = TLDR.getShapeUtil(fromShape) const fromUtils = TLDR.getShapeUtil(fromShape)
// We only need to update the binding's "from" shape // We only need to update the binding's "from" shape
@ -1011,7 +1015,6 @@ export class TldrawApp extends StateManager<TDSnapshot> {
setDisableAssets = (disableAssets: boolean): this => { setDisableAssets = (disableAssets: boolean): this => {
this.patchState({ appState: { disableAssets } }, 'ui:toggled_disable_images') this.patchState({ appState: { disableAssets } }, 'ui:toggled_disable_images')
this.persist()
return this return this
} }
@ -3361,12 +3364,12 @@ export class TldrawApp extends StateManager<TDSnapshot> {
getShapeUtil = TLDR.getShapeUtil getShapeUtil = TLDR.getShapeUtil
static version = 15.3 static version = 15.2
static defaultDocument: TDDocument = { static defaultDocument: TDDocument = {
id: 'doc', id: 'doc',
name: 'New Document', name: 'New Document',
version: 15, version: TldrawApp.version,
pages: { pages: {
page: { page: {
id: 'page', id: 'page',

View file

@ -142,6 +142,7 @@ const Wrapper = styled('div', {
width: '100%', width: '100%',
borderRadius: '3px', borderRadius: '3px',
perspective: '800px', perspective: '800px',
overflow: 'hidden',
p: { p: {
userSelect: 'none', userSelect: 'none',
}, },
@ -183,6 +184,9 @@ const Wrapper = styled('div', {
}) })
const ImageElement = styled('img', { const ImageElement = styled('img', {
position: 'absolute',
top: 0,
left: 0,
width: '100%', width: '100%',
height: '100%', height: '100%',
maxWidth: '100%', maxWidth: '100%',

View file

@ -186,6 +186,7 @@ const Wrapper = styled('div', {
width: '100%', width: '100%',
borderRadius: '3px', borderRadius: '3px',
perspective: '800px', perspective: '800px',
overflow: 'hidden',
p: { p: {
userSelect: 'none', userSelect: 'none',
}, },
@ -227,8 +228,14 @@ const Wrapper = styled('div', {
}) })
const VideoElement = styled('video', { const VideoElement = styled('video', {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
maxWidth: '100%', maxWidth: '100%',
minWidth: '100%', minWidth: '100%',
pointerEvents: 'all', pointerEvents: 'none',
objectFit: 'cover',
borderRadius: 2, borderRadius: 2,
}) })