ソースを参照

Adds multiple pages, pageStates to state object (groan)

main
Steve Ruiz 3年前
コミット
594bc7c2ff

+ 5
- 5
packages/core/src/types.ts ファイルの表示

@@ -13,6 +13,11 @@ export interface TLPage<T extends TLShape, B extends TLBinding> {
13 13
 
14 14
 export interface TLPageState {
15 15
   id: string
16
+  selectedIds: string[]
17
+  camera: {
18
+    point: number[]
19
+    zoom: number
20
+  }
16 21
   brush?: TLBounds
17 22
   pointedId?: string
18 23
   hoveredId?: string
@@ -20,11 +25,6 @@ export interface TLPageState {
20 25
   bindingId?: string
21 26
   boundsRotation?: number
22 27
   currentParentId?: string
23
-  selectedIds: string[]
24
-  camera: {
25
-    point: number[]
26
-    zoom: number
27
-  }
28 28
 }
29 29
 
30 30
 export interface TLHandle {

+ 2
- 31
packages/tldraw/src/components/menu/menu.tsx ファイルの表示

@@ -10,12 +10,11 @@ import {
10 10
   DropdownMenuButton,
11 11
   DropdownMenuSubMenu,
12 12
   DropdownMenuDivider,
13
-  DropdownMenuCheckboxItem,
14 13
   IconWrapper,
15 14
   Kbd,
16 15
 } from '~components/shared'
17
-import { useTLDrawContext, useTheme } from '~hooks'
18
-import type { Data } from '~types'
16
+import { useTLDrawContext } from '~hooks'
17
+import { Preferences } from './preferences'
19 18
 
20 19
 export const Menu = React.memo(() => {
21 20
   const { tlstate } = useTLDrawContext()
@@ -96,31 +95,3 @@ function RecentFiles() {
96 95
     </DropdownMenuSubMenu>
97 96
   )
98 97
 }
99
-
100
-const isDebugModeSelector = (s: Data) => s.settings.isDebugMode
101
-
102
-function Preferences() {
103
-  const { tlstate, useSelector } = useTLDrawContext()
104
-  const { theme, setTheme } = useTheme()
105
-
106
-  const isDebugMode = useSelector(isDebugModeSelector)
107
-  const isDarkMode = theme === 'dark'
108
-
109
-  const toggleDebugMode = React.useCallback(() => {
110
-    tlstate.toggleDebugMode()
111
-  }, [tlstate])
112
-
113
-  return (
114
-    <DropdownMenuSubMenu label="Preferences">
115
-      <DropdownMenuCheckboxItem
116
-        checked={isDarkMode}
117
-        onCheckedChange={() => setTheme(isDarkMode ? 'light' : 'dark')}
118
-      >
119
-        <span>Dark Mode</span>
120
-      </DropdownMenuCheckboxItem>
121
-      <DropdownMenuCheckboxItem checked={isDebugMode} onCheckedChange={toggleDebugMode}>
122
-        <span>Debug Mode</span>
123
-      </DropdownMenuCheckboxItem>
124
-    </DropdownMenuSubMenu>
125
-  )
126
-}

+ 15
- 6
packages/tldraw/src/components/menu/preferences.tsx ファイルの表示

@@ -1,15 +1,24 @@
1
+import * as React from 'react'
2
+import { DropdownMenuSubMenu, DropdownMenuCheckboxItem } from '~components/shared'
3
+import { useTheme, useTLDrawContext } from '~hooks'
4
+import type { Data } from '~types'
5
+
6
+const isDebugModeSelector = (s: Data) => s.settings.isDebugMode
7
+
1 8
 export function Preferences() {
2
-  const { theme, setTheme } = useTheme()
9
+  const { theme, toggle } = useTheme()
10
+  const { tlstate, useSelector } = useTLDrawContext()
3 11
 
4
-  const isDebugMode = useSelector((s) => s.data.settings.isDebugMode)
12
+  const isDebugMode = useSelector(isDebugModeSelector)
5 13
   const isDarkMode = theme === 'dark'
6 14
 
15
+  const toggleDebugMode = React.useCallback(() => {
16
+    tlstate.toggleDebugMode()
17
+  }, [tlstate])
18
+
7 19
   return (
8 20
     <DropdownMenuSubMenu label="Preferences">
9
-      <DropdownMenuCheckboxItem
10
-        checked={isDarkMode}
11
-        onCheckedChange={() => setTheme(isDarkMode ? 'light' : 'dark')}
12
-      >
21
+      <DropdownMenuCheckboxItem checked={isDarkMode} onCheckedChange={toggle}>
13 22
         <span>Dark Mode</span>
14 23
       </DropdownMenuCheckboxItem>
15 24
       <DropdownMenuCheckboxItem checked={isDebugMode} onCheckedChange={toggleDebugMode}>

+ 1
- 1
packages/tldraw/src/components/page-options-dialog/page-options-dialog.test.tsx ファイルの表示

@@ -4,6 +4,6 @@ import { mockDocument, renderWithContext } from '~test'
4 4
 
5 5
 describe('page options dialog', () => {
6 6
   test('mounts component without crashing', () => {
7
-    renderWithContext(<PageOptionsDialog page={mockDocument.pages.page} />)
7
+    renderWithContext(<PageOptionsDialog page={mockDocument.pages.page1} />)
8 8
   })
9 9
 })

+ 1
- 1
packages/tldraw/src/components/tldraw/tldraw.tsx ファイルの表示

@@ -54,7 +54,7 @@ export function TLDraw({ document, currentPageId, onMount, onChange: _onChange }
54 54
 
55 55
   React.useEffect(() => {
56 56
     if (!currentPageId) return
57
-    tlstate.setCurrentPageId(currentPageId)
57
+    tlstate.changePage(currentPageId)
58 58
   }, [currentPageId, tlstate])
59 59
 
60 60
   React.useEffect(() => {

+ 441
- 297
packages/tldraw/src/state/tlstate.ts
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 3
- 6
packages/tldraw/src/types.ts ファイルの表示

@@ -6,6 +6,7 @@ import type { TLPage, TLPageState, TLSettings } from '@tldraw/core'
6 6
 import type { StoreApi } from 'zustand'
7 7
 
8 8
 export type TLStore = StoreApi<Data>
9
+
9 10
 export type TLChange = Data
10 11
 
11 12
 export type TLDrawPage = TLPage<TLDrawShape, TLDrawBinding>
@@ -23,8 +24,7 @@ export interface TLDrawSettings extends TLSettings {
23 24
 }
24 25
 
25 26
 export interface Data {
26
-  page: TLPage<TLDrawShape, TLDrawBinding>
27
-  pageState: TLPageState
27
+  document: TLDrawDocument
28 28
   settings: TLDrawSettings
29 29
   appState: {
30 30
     selectedStyle: ShapeStyles
@@ -40,10 +40,7 @@ export interface Data {
40 40
     status: { current: TLDrawStatus; previous: TLDrawStatus }
41 41
   }
42 42
 }
43
-export interface PagePartial {
44
-  shapes: DeepPartial<Data['page']['shapes']>
45
-  bindings: DeepPartial<Data['page']['bindings']>
46
-}
43
+export type PagePartial = DeepPartial<TLDrawPage>
47 44
 
48 45
 export type DeepPartial<T> = T extends Function
49 46
   ? T

読み込み中…
キャンセル
保存