Przeglądaj źródła

[fix] multiplayer (sorta) (#426)

* Fix multiplayer

* Update TldrawApp.ts

* Update TldrawApp.ts

* Update TldrawApp.ts
main
Steve Ruiz 3 lat temu
rodzic
commit
33acf03004
No account linked to committer's email address

+ 1
- 1
examples/tldraw-example/src/multiplayer/useMultiplayerState.ts Wyświetl plik

121
           migrated?: boolean
121
           migrated?: boolean
122
         }>
122
         }>
123
 
123
 
124
-        // No doc? No problem. This was likely
124
+        // No doc? No problem. This was likely a newer document
125
         if (doc) {
125
         if (doc) {
126
           const {
126
           const {
127
             document: {
127
             document: {

+ 4
- 2
packages/tldraw/src/Tldraw.tsx Wyświetl plik

357
 
357
 
358
   const page = document.pages[appState.currentPageId]
358
   const page = document.pages[appState.currentPageId]
359
   const pageState = document.pageStates[page.id]
359
   const pageState = document.pageStates[page.id]
360
-  const { selectedIds } = state.document.pageStates[page.id]
360
+  const { selectedIds } = pageState
361
 
361
 
362
   const isHideBoundsShape =
362
   const isHideBoundsShape =
363
-    pageState.selectedIds.length === 1 &&
363
+    selectedIds.length === 1 &&
364
+    page.shapes[selectedIds[0]] &&
364
     TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideBounds
365
     TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideBounds
365
 
366
 
366
   const isHideResizeHandlesShape =
367
   const isHideResizeHandlesShape =
367
     selectedIds.length === 1 &&
368
     selectedIds.length === 1 &&
369
+    page.shapes[selectedIds[0]] &&
368
     TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideResizeHandles
370
     TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideResizeHandles
369
 
371
 
370
   const isInSession = app.session !== undefined
372
   const isInSession = app.session !== undefined

+ 22
- 8
packages/tldraw/src/state/TldrawApp.ts Wyświetl plik

548
     this.useStore.setState((current) => {
548
     this.useStore.setState((current) => {
549
       const { hoveredId, editingId, bindingId, selectedIds } = current.document.pageStates[pageId]
549
       const { hoveredId, editingId, bindingId, selectedIds } = current.document.pageStates[pageId]
550
 
550
 
551
-      const next = {
551
+      const keepShapes: Record<string, TDShape> = {}
552
+      const keepBindings: Record<string, TDBinding> = {}
553
+
554
+      if (this.session) {
555
+        selectedIds.forEach((id) => (keepShapes[id] = this.getShape(id)))
556
+        Object.assign(keepBindings, this.bindings) // ROUGH
557
+      }
558
+
559
+      if (editingId) {
560
+        keepShapes[editingId] = this.getShape(editingId)
561
+      }
562
+
563
+      const next: TDSnapshot = {
552
         ...current,
564
         ...current,
553
         document: {
565
         document: {
554
           ...current.document,
566
           ...current.document,
555
           pages: {
567
           pages: {
556
             [pageId]: {
568
             [pageId]: {
557
               ...current.document.pages[pageId],
569
               ...current.document.pages[pageId],
558
-              shapes,
559
-              bindings,
570
+              shapes: {
571
+                ...shapes,
572
+                ...keepShapes,
573
+              },
574
+              bindings: {
575
+                ...bindings,
576
+                ...keepBindings,
577
+              },
560
             },
578
             },
561
           },
579
           },
562
           pageStates: {
580
           pageStates: {
569
                   ? undefined
587
                   ? undefined
570
                   : hoveredId
588
                   : hoveredId
571
                 : undefined,
589
                 : undefined,
572
-              editingId: editingId
573
-                ? shapes[editingId] === undefined
574
-                  ? undefined
575
-                  : hoveredId
576
-                : undefined,
590
+              editingId: editingId,
577
               bindingId: bindingId
591
               bindingId: bindingId
578
                 ? bindings[bindingId] === undefined
592
                 ? bindings[bindingId] === undefined
579
                   ? undefined
593
                   ? undefined

Ładowanie…
Anuluj
Zapisz