소스 검색

[fix] multiplayer (sorta) (#426)

* Fix multiplayer

* Update TldrawApp.ts

* Update TldrawApp.ts

* Update TldrawApp.ts
main
Steve Ruiz 3 년 전
부모
커밋
33acf03004
No account linked to committer's email address
3개의 변경된 파일27개의 추가작업 그리고 11개의 파일을 삭제
  1. 1
    1
      examples/tldraw-example/src/multiplayer/useMultiplayerState.ts
  2. 4
    2
      packages/tldraw/src/Tldraw.tsx
  3. 22
    8
      packages/tldraw/src/state/TldrawApp.ts

+ 1
- 1
examples/tldraw-example/src/multiplayer/useMultiplayerState.ts 파일 보기

@@ -121,7 +121,7 @@ export function useMultiplayerState(roomId: string) {
121 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 125
         if (doc) {
126 126
           const {
127 127
             document: {

+ 4
- 2
packages/tldraw/src/Tldraw.tsx 파일 보기

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

+ 22
- 8
packages/tldraw/src/state/TldrawApp.ts 파일 보기

@@ -548,15 +548,33 @@ export class TldrawApp extends StateManager<TDSnapshot> {
548 548
     this.useStore.setState((current) => {
549 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 564
         ...current,
553 565
         document: {
554 566
           ...current.document,
555 567
           pages: {
556 568
             [pageId]: {
557 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 580
           pageStates: {
@@ -569,11 +587,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
569 587
                   ? undefined
570 588
                   : hoveredId
571 589
                 : undefined,
572
-              editingId: editingId
573
-                ? shapes[editingId] === undefined
574
-                  ? undefined
575
-                  : hoveredId
576
-                : undefined,
590
+              editingId: editingId,
577 591
               bindingId: bindingId
578 592
                 ? bindings[bindingId] === undefined
579 593
                   ? undefined

Loading…
취소
저장