瀏覽代碼

Adds migration for documents

main
Steve Ruiz 3 年之前
父節點
當前提交
10d0a5f5a1

+ 19
- 0
packages/tldraw/src/state/migration.spec.ts 查看文件

1
+/* eslint-disable @typescript-eslint/ban-ts-comment */
2
+import { TLDrawState } from '~state'
3
+import type { TLDrawDocument } from '~types'
4
+import oldDoc from '../test/old-doc.json'
5
+
6
+describe('When migrating bindings', () => {
7
+  it('migrates', () => {
8
+    Object.values((oldDoc as TLDrawDocument).pages).forEach((page) => {
9
+      Object.values(page.bindings).forEach((binding) => {
10
+        if ('meta' in binding) {
11
+          // @ts-ignore
12
+          Object.assign(binding, binding.meta)
13
+        }
14
+      })
15
+    })
16
+
17
+    new TLDrawState().loadDocument(oldDoc)
18
+  })
19
+})

+ 11
- 1
packages/tldraw/src/state/tlstate.ts 查看文件

1
+/* eslint-disable @typescript-eslint/ban-ts-comment */
1
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
 import { StateManager } from 'rko'
3
 import { StateManager } from 'rko'
3
 import { Vec } from '@tldraw/vec'
4
 import { Vec } from '@tldraw/vec'
99
     onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void
100
     onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void
100
   ) {
101
   ) {
101
     super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
102
     super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
103
+      Object.values(prev.document.pages).forEach((page) => {
104
+        Object.values(page.bindings).forEach((binding) => {
105
+          if ('meta' in binding) {
106
+            // @ts-ignore
107
+            Object.assign(binding, binding.meta)
108
+          }
109
+        })
110
+      })
111
+
102
       return {
112
       return {
103
         ...next,
113
         ...next,
104
         document: { ...next.document, ...prev.document },
114
         document: { ...next.document, ...prev.document },
2446
     }
2456
     }
2447
   }
2457
   }
2448
 
2458
 
2449
-  static version = 10.5
2459
+  static version = 11
2450
 
2460
 
2451
   static defaultDocument: TLDrawDocument = {
2461
   static defaultDocument: TLDrawDocument = {
2452
     id: 'doc',
2462
     id: 'doc',

+ 31877
- 0
packages/tldraw/src/test/old-doc.json
文件差異過大導致無法顯示
查看文件


+ 1
- 1
packages/www/public/sw.js
文件差異過大導致無法顯示
查看文件


+ 1
- 1
packages/www/public/sw.js.map
文件差異過大導致無法顯示
查看文件


packages/www/public/worker-ZEMX_X-_TfacxHZIWvwLo.js → packages/www/public/worker-HKFtmQufnTIV6sQ0dJS4-.js 查看文件


Loading…
取消
儲存