Adds migration for documents
This commit is contained in:
parent
5901035214
commit
10d0a5f5a1
6 changed files with 31909 additions and 3 deletions
19
packages/tldraw/src/state/migration.spec.ts
Normal file
19
packages/tldraw/src/state/migration.spec.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { TLDrawState } from '~state'
|
||||
import type { TLDrawDocument } from '~types'
|
||||
import oldDoc from '../test/old-doc.json'
|
||||
|
||||
describe('When migrating bindings', () => {
|
||||
it('migrates', () => {
|
||||
Object.values((oldDoc as TLDrawDocument).pages).forEach((page) => {
|
||||
Object.values(page.bindings).forEach((binding) => {
|
||||
if ('meta' in binding) {
|
||||
// @ts-ignore
|
||||
Object.assign(binding, binding.meta)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
new TLDrawState().loadDocument(oldDoc)
|
||||
})
|
||||
})
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import { StateManager } from 'rko'
|
||||
import { Vec } from '@tldraw/vec'
|
||||
|
@ -99,6 +100,15 @@ export class TLDrawState extends StateManager<Data> {
|
|||
onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void
|
||||
) {
|
||||
super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
|
||||
Object.values(prev.document.pages).forEach((page) => {
|
||||
Object.values(page.bindings).forEach((binding) => {
|
||||
if ('meta' in binding) {
|
||||
// @ts-ignore
|
||||
Object.assign(binding, binding.meta)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
...next,
|
||||
document: { ...next.document, ...prev.document },
|
||||
|
@ -2446,7 +2456,7 @@ export class TLDrawState extends StateManager<Data> {
|
|||
}
|
||||
}
|
||||
|
||||
static version = 10.5
|
||||
static version = 11
|
||||
|
||||
static defaultDocument: TLDrawDocument = {
|
||||
id: 'doc',
|
||||
|
|
31877
packages/tldraw/src/test/old-doc.json
Normal file
31877
packages/tldraw/src/test/old-doc.json
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue