Bladeren bron

Adds multiple pages, pageStates to state object (groan)

main
Steve Ruiz 3 jaren geleden
bovenliggende
commit
594bc7c2ff

+ 5
- 5
packages/core/src/types.ts Bestand weergeven

13
 
13
 
14
 export interface TLPageState {
14
 export interface TLPageState {
15
   id: string
15
   id: string
16
+  selectedIds: string[]
17
+  camera: {
18
+    point: number[]
19
+    zoom: number
20
+  }
16
   brush?: TLBounds
21
   brush?: TLBounds
17
   pointedId?: string
22
   pointedId?: string
18
   hoveredId?: string
23
   hoveredId?: string
20
   bindingId?: string
25
   bindingId?: string
21
   boundsRotation?: number
26
   boundsRotation?: number
22
   currentParentId?: string
27
   currentParentId?: string
23
-  selectedIds: string[]
24
-  camera: {
25
-    point: number[]
26
-    zoom: number
27
-  }
28
 }
28
 }
29
 
29
 
30
 export interface TLHandle {
30
 export interface TLHandle {

+ 2
- 31
packages/tldraw/src/components/menu/menu.tsx Bestand weergeven

10
   DropdownMenuButton,
10
   DropdownMenuButton,
11
   DropdownMenuSubMenu,
11
   DropdownMenuSubMenu,
12
   DropdownMenuDivider,
12
   DropdownMenuDivider,
13
-  DropdownMenuCheckboxItem,
14
   IconWrapper,
13
   IconWrapper,
15
   Kbd,
14
   Kbd,
16
 } from '~components/shared'
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
 export const Menu = React.memo(() => {
19
 export const Menu = React.memo(() => {
21
   const { tlstate } = useTLDrawContext()
20
   const { tlstate } = useTLDrawContext()
96
     </DropdownMenuSubMenu>
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 Bestand weergeven

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
 export function Preferences() {
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
   const isDarkMode = theme === 'dark'
13
   const isDarkMode = theme === 'dark'
6
 
14
 
15
+  const toggleDebugMode = React.useCallback(() => {
16
+    tlstate.toggleDebugMode()
17
+  }, [tlstate])
18
+
7
   return (
19
   return (
8
     <DropdownMenuSubMenu label="Preferences">
20
     <DropdownMenuSubMenu label="Preferences">
9
-      <DropdownMenuCheckboxItem
10
-        checked={isDarkMode}
11
-        onCheckedChange={() => setTheme(isDarkMode ? 'light' : 'dark')}
12
-      >
21
+      <DropdownMenuCheckboxItem checked={isDarkMode} onCheckedChange={toggle}>
13
         <span>Dark Mode</span>
22
         <span>Dark Mode</span>
14
       </DropdownMenuCheckboxItem>
23
       </DropdownMenuCheckboxItem>
15
       <DropdownMenuCheckboxItem checked={isDebugMode} onCheckedChange={toggleDebugMode}>
24
       <DropdownMenuCheckboxItem checked={isDebugMode} onCheckedChange={toggleDebugMode}>

+ 1
- 1
packages/tldraw/src/components/page-options-dialog/page-options-dialog.test.tsx Bestand weergeven

4
 
4
 
5
 describe('page options dialog', () => {
5
 describe('page options dialog', () => {
6
   test('mounts component without crashing', () => {
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 Bestand weergeven

54
 
54
 
55
   React.useEffect(() => {
55
   React.useEffect(() => {
56
     if (!currentPageId) return
56
     if (!currentPageId) return
57
-    tlstate.setCurrentPageId(currentPageId)
57
+    tlstate.changePage(currentPageId)
58
   }, [currentPageId, tlstate])
58
   }, [currentPageId, tlstate])
59
 
59
 
60
   React.useEffect(() => {
60
   React.useEffect(() => {

+ 441
- 297
packages/tldraw/src/state/tlstate.ts
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 3
- 6
packages/tldraw/src/types.ts Bestand weergeven

6
 import type { StoreApi } from 'zustand'
6
 import type { StoreApi } from 'zustand'
7
 
7
 
8
 export type TLStore = StoreApi<Data>
8
 export type TLStore = StoreApi<Data>
9
+
9
 export type TLChange = Data
10
 export type TLChange = Data
10
 
11
 
11
 export type TLDrawPage = TLPage<TLDrawShape, TLDrawBinding>
12
 export type TLDrawPage = TLPage<TLDrawShape, TLDrawBinding>
23
 }
24
 }
24
 
25
 
25
 export interface Data {
26
 export interface Data {
26
-  page: TLPage<TLDrawShape, TLDrawBinding>
27
-  pageState: TLPageState
27
+  document: TLDrawDocument
28
   settings: TLDrawSettings
28
   settings: TLDrawSettings
29
   appState: {
29
   appState: {
30
     selectedStyle: ShapeStyles
30
     selectedStyle: ShapeStyles
40
     status: { current: TLDrawStatus; previous: TLDrawStatus }
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
 export type DeepPartial<T> = T extends Function
45
 export type DeepPartial<T> = T extends Function
49
   ? T
46
   ? T

Laden…
Annuleren
Opslaan