浏览代码

[fix] current style and selected style (#298)

* Fix selectedStyles from being new on each update

* Fix again

* Update TldrawApp.ts

* Fix log around current style and selected style

* Add stub test, move style menu into folder

* Cleanup repo

* cleanup context menu
main
Steve Ruiz 3 年前
父节点
当前提交
eb20f1c816
没有帐户链接到提交者的电子邮件
共有 76 个文件被更改,包括 211 次插入188 次删除
  1. 0
    11
      packages/tldraw/src/components/ContextMenu/CMIconButton.tsx
  2. 0
    11
      packages/tldraw/src/components/ContextMenu/CMRowButton.tsx
  3. 0
    15
      packages/tldraw/src/components/ContextMenu/CMTriggerButton.tsx
  4. 51
    20
      packages/tldraw/src/components/ContextMenu/ContextMenu.tsx
  5. 1
    1
      packages/tldraw/src/components/FocusButton/FocusButton.tsx
  6. 0
    0
      packages/tldraw/src/components/Primitives/Divider/Divider.tsx
  7. 0
    0
      packages/tldraw/src/components/Primitives/Divider/index.ts
  8. 0
    0
      packages/tldraw/src/components/Primitives/DropdownMenu/DMArrow.tsx
  9. 1
    1
      packages/tldraw/src/components/Primitives/DropdownMenu/DMCheckboxItem.tsx
  10. 1
    1
      packages/tldraw/src/components/Primitives/DropdownMenu/DMContent.tsx
  11. 0
    0
      packages/tldraw/src/components/Primitives/DropdownMenu/DMDivider.tsx
  12. 1
    1
      packages/tldraw/src/components/Primitives/DropdownMenu/DMItem.tsx
  13. 0
    0
      packages/tldraw/src/components/Primitives/DropdownMenu/DMRadioItem.tsx
  14. 2
    2
      packages/tldraw/src/components/Primitives/DropdownMenu/DMSubMenu.tsx
  15. 1
    1
      packages/tldraw/src/components/Primitives/DropdownMenu/DMTriggerIcon.tsx
  16. 0
    0
      packages/tldraw/src/components/Primitives/DropdownMenu/index.tsx
  17. 0
    0
      packages/tldraw/src/components/Primitives/IconButton/IconButton.tsx
  18. 0
    0
      packages/tldraw/src/components/Primitives/IconButton/index.ts
  19. 0
    0
      packages/tldraw/src/components/Primitives/Kbd/Kbd.tsx
  20. 0
    0
      packages/tldraw/src/components/Primitives/Kbd/index.ts
  21. 0
    0
      packages/tldraw/src/components/Primitives/MenuContent/MenuContent.ts
  22. 0
    0
      packages/tldraw/src/components/Primitives/MenuContent/index.ts
  23. 0
    0
      packages/tldraw/src/components/Primitives/Panel/Panel.tsx
  24. 0
    0
      packages/tldraw/src/components/Primitives/Panel/index.ts
  25. 2
    2
      packages/tldraw/src/components/Primitives/RowButton/RowButton.tsx
  26. 0
    0
      packages/tldraw/src/components/Primitives/RowButton/index.ts
  27. 0
    0
      packages/tldraw/src/components/Primitives/SmallIcon/SmallIcon.tsx
  28. 0
    0
      packages/tldraw/src/components/Primitives/SmallIcon/index.ts
  29. 1
    1
      packages/tldraw/src/components/Primitives/ToolButton/ToolButton.tsx
  30. 0
    0
      packages/tldraw/src/components/Primitives/ToolButton/index.ts
  31. 1
    1
      packages/tldraw/src/components/Primitives/Tooltip/Tooltip.tsx
  32. 0
    0
      packages/tldraw/src/components/Primitives/Tooltip/index.ts
  33. 0
    0
      packages/tldraw/src/components/Primitives/icons/BoxIcon.tsx
  34. 0
    0
      packages/tldraw/src/components/Primitives/icons/CircleIcon.tsx
  35. 0
    0
      packages/tldraw/src/components/Primitives/icons/DashDashedIcon.tsx
  36. 0
    0
      packages/tldraw/src/components/Primitives/icons/DashDottedIcon.tsx
  37. 0
    0
      packages/tldraw/src/components/Primitives/icons/DashDrawIcon.tsx
  38. 0
    0
      packages/tldraw/src/components/Primitives/icons/DashSolidIcon.tsx
  39. 0
    0
      packages/tldraw/src/components/Primitives/icons/EraserIcon.tsx
  40. 0
    0
      packages/tldraw/src/components/Primitives/icons/HeartIcon.tsx
  41. 0
    0
      packages/tldraw/src/components/Primitives/icons/IsFilledIcon.tsx
  42. 0
    0
      packages/tldraw/src/components/Primitives/icons/MultiplayerIcon.tsx
  43. 0
    0
      packages/tldraw/src/components/Primitives/icons/RedoIcon.tsx
  44. 0
    0
      packages/tldraw/src/components/Primitives/icons/SizeLargeIcon.tsx
  45. 0
    0
      packages/tldraw/src/components/Primitives/icons/SizeMediumIcon.tsx
  46. 0
    0
      packages/tldraw/src/components/Primitives/icons/SizeSmallIcon.tsx
  47. 0
    0
      packages/tldraw/src/components/Primitives/icons/TrashIcon.tsx
  48. 0
    0
      packages/tldraw/src/components/Primitives/icons/UndoIcon.tsx
  49. 0
    0
      packages/tldraw/src/components/Primitives/icons/index.ts
  50. 5
    5
      packages/tldraw/src/components/ToolsPanel/ActionButton.tsx
  51. 2
    2
      packages/tldraw/src/components/ToolsPanel/BackToContent.tsx
  52. 3
    3
      packages/tldraw/src/components/ToolsPanel/DeleteButton.tsx
  53. 2
    2
      packages/tldraw/src/components/ToolsPanel/LockButton.tsx
  54. 3
    3
      packages/tldraw/src/components/ToolsPanel/PenMenu.tsx
  55. 3
    3
      packages/tldraw/src/components/ToolsPanel/PrimaryTools.tsx
  56. 3
    3
      packages/tldraw/src/components/ToolsPanel/ShapesMenu.tsx
  57. 0
    3
      packages/tldraw/src/components/TopPanel/HelpMenu.tsx
  58. 10
    4
      packages/tldraw/src/components/TopPanel/Menu/Menu.tsx
  59. 0
    0
      packages/tldraw/src/components/TopPanel/Menu/index.ts
  60. 3
    3
      packages/tldraw/src/components/TopPanel/MultiplayerMenu/MultiplayerMenu.tsx
  61. 1
    0
      packages/tldraw/src/components/TopPanel/MultiplayerMenu/index.ts
  62. 5
    5
      packages/tldraw/src/components/TopPanel/PageMenu/PageMenu.tsx
  63. 1
    0
      packages/tldraw/src/components/TopPanel/PageMenu/index.ts
  64. 4
    4
      packages/tldraw/src/components/TopPanel/PageOptionsDialog/PageOptionsDialog.tsx
  65. 1
    0
      packages/tldraw/src/components/TopPanel/PageOptionsDialog/index.ts
  66. 1
    1
      packages/tldraw/src/components/TopPanel/PreferencesMenu/PreferencesMenu.tsx
  67. 1
    0
      packages/tldraw/src/components/TopPanel/PreferencesMenu/index.ts
  68. 4
    0
      packages/tldraw/src/components/TopPanel/StyleMenu/StyleMenu.test.tsx
  69. 86
    23
      packages/tldraw/src/components/TopPanel/StyleMenu/StyleMenu.tsx
  70. 1
    0
      packages/tldraw/src/components/TopPanel/StyleMenu/index.ts
  71. 2
    2
      packages/tldraw/src/components/TopPanel/TopPanel.tsx
  72. 2
    2
      packages/tldraw/src/components/TopPanel/ZoomMenu/ZoomMenu.tsx
  73. 1
    0
      packages/tldraw/src/components/TopPanel/ZoomMenu/index.ts
  74. 0
    38
      packages/tldraw/src/state/TLDR.ts
  75. 5
    13
      packages/tldraw/src/state/TldrawApp.ts
  76. 0
    1
      packages/tldraw/src/types.ts

+ 0
- 11
packages/tldraw/src/components/ContextMenu/CMIconButton.tsx 查看文件

1
-import * as React from 'react'
2
-import { ContextMenuItem } from '@radix-ui/react-context-menu'
3
-import { ToolButton, ToolButtonProps } from '~components/ToolButton'
4
-
5
-export function CMIconButton({ onSelect, ...rest }: ToolButtonProps): JSX.Element {
6
-  return (
7
-    <ContextMenuItem dir="ltr" onSelect={onSelect} asChild>
8
-      <ToolButton {...rest} />
9
-    </ContextMenuItem>
10
-  )
11
-}

+ 0
- 11
packages/tldraw/src/components/ContextMenu/CMRowButton.tsx 查看文件

1
-import * as React from 'react'
2
-import { ContextMenuItem } from '@radix-ui/react-context-menu'
3
-import { RowButton, RowButtonProps } from '~components/RowButton'
4
-
5
-export const CMRowButton = ({ ...rest }: RowButtonProps) => {
6
-  return (
7
-    <ContextMenuItem asChild>
8
-      <RowButton {...rest} />
9
-    </ContextMenuItem>
10
-  )
11
-}

+ 0
- 15
packages/tldraw/src/components/ContextMenu/CMTriggerButton.tsx 查看文件

1
-import * as React from 'react'
2
-import { ContextMenuTriggerItem } from '@radix-ui/react-context-menu'
3
-import { RowButton, RowButtonProps } from '~components/RowButton'
4
-
5
-interface CMTriggerButtonProps extends RowButtonProps {
6
-  isSubmenu?: boolean
7
-}
8
-
9
-export const CMTriggerButton = ({ isSubmenu, ...rest }: CMTriggerButtonProps) => {
10
-  return (
11
-    <ContextMenuTriggerItem asChild>
12
-      <RowButton hasArrow={isSubmenu} {...rest} />
13
-    </ContextMenuTriggerItem>
14
-  )
15
-}

+ 51
- 20
packages/tldraw/src/components/ContextMenu/ContextMenu.tsx 查看文件

15
   StretchHorizontallyIcon,
15
   StretchHorizontallyIcon,
16
   StretchVerticallyIcon,
16
   StretchVerticallyIcon,
17
 } from '@radix-ui/react-icons'
17
 } from '@radix-ui/react-icons'
18
-import { CMRowButton } from './CMRowButton'
19
-import { CMIconButton } from './CMIconButton'
20
-import { CMTriggerButton } from './CMTriggerButton'
21
-import { Divider } from '~components/Divider'
22
-import { MenuContent } from '~components/MenuContent'
23
-
24
-const has1SelectedIdsSelector = (s: TDSnapshot) => {
25
-  return s.document.pageStates[s.appState.currentPageId].selectedIds.length > 0
26
-}
27
-const has2SelectedIdsSelector = (s: TDSnapshot) => {
28
-  return s.document.pageStates[s.appState.currentPageId].selectedIds.length > 1
29
-}
30
-const has3SelectedIdsSelector = (s: TDSnapshot) => {
31
-  return s.document.pageStates[s.appState.currentPageId].selectedIds.length > 2
18
+import { Divider } from '~components/Primitives/Divider'
19
+import { MenuContent } from '~components/Primitives/MenuContent'
20
+import { RowButton, RowButtonProps } from '~components/Primitives/RowButton'
21
+import { ToolButton, ToolButtonProps } from '~components/Primitives/ToolButton'
22
+
23
+const numberOfSelectedIdsSelector = (s: TDSnapshot) => {
24
+  return s.document.pageStates[s.appState.currentPageId].selectedIds.length
32
 }
25
 }
33
 
26
 
34
 const isDebugModeSelector = (s: TDSnapshot) => {
27
 const isDebugModeSelector = (s: TDSnapshot) => {
50
 
43
 
51
 export const ContextMenu = ({ onBlur, children }: ContextMenuProps): JSX.Element => {
44
 export const ContextMenu = ({ onBlur, children }: ContextMenuProps): JSX.Element => {
52
   const app = useTldrawApp()
45
   const app = useTldrawApp()
53
-  const hasSelection = app.useStore(has1SelectedIdsSelector)
54
-  const hasTwoOrMore = app.useStore(has2SelectedIdsSelector)
55
-  const hasThreeOrMore = app.useStore(has3SelectedIdsSelector)
46
+  const numberOfSelectedIds = app.useStore(numberOfSelectedIdsSelector)
56
   const isDebugMode = app.useStore(isDebugModeSelector)
47
   const isDebugMode = app.useStore(isDebugModeSelector)
57
   const hasGroupSelected = app.useStore(hasGroupSelectedSelector)
48
   const hasGroupSelected = app.useStore(hasGroupSelectedSelector)
58
 
49
 
122
     app.redo()
113
     app.redo()
123
   }, [app])
114
   }, [app])
124
 
115
 
116
+  const hasSelection = numberOfSelectedIds > 0
117
+  const hasTwoOrMore = numberOfSelectedIds > 1
118
+  const hasThreeOrMore = numberOfSelectedIds > 2
119
+
125
   return (
120
   return (
126
     <RadixContextMenu.Root dir="ltr">
121
     <RadixContextMenu.Root dir="ltr">
127
       <RadixContextMenu.Trigger dir="ltr">{children}</RadixContextMenu.Trigger>
122
       <RadixContextMenu.Trigger dir="ltr">{children}</RadixContextMenu.Trigger>
216
   )
211
   )
217
 }
212
 }
218
 
213
 
214
+/* ---------- Align and Distribute Sub Menu --------- */
215
+
219
 function AlignDistributeSubMenu({
216
 function AlignDistributeSubMenu({
220
   hasThreeOrMore,
217
   hasThreeOrMore,
221
 }: {
218
 }: {
268
     <RadixContextMenu.Root dir="ltr">
265
     <RadixContextMenu.Root dir="ltr">
269
       <CMTriggerButton isSubmenu>Align / Distribute</CMTriggerButton>
266
       <CMTriggerButton isSubmenu>Align / Distribute</CMTriggerButton>
270
       <RadixContextMenu.Content asChild sideOffset={2} alignOffset={-2}>
267
       <RadixContextMenu.Content asChild sideOffset={2} alignOffset={-2}>
271
-        <StyledGridContent selectedStyle={hasThreeOrMore ? 'threeOrMore' : 'twoOrMore'}>
268
+        <StyledGridContent numberOfSelected={hasThreeOrMore ? 'threeOrMore' : 'twoOrMore'}>
272
           <CMIconButton onClick={alignLeft}>
269
           <CMIconButton onClick={alignLeft}>
273
             <AlignLeftIcon />
270
             <AlignLeftIcon />
274
           </CMIconButton>
271
           </CMIconButton>
313
 const StyledGridContent = styled(MenuContent, {
310
 const StyledGridContent = styled(MenuContent, {
314
   display: 'grid',
311
   display: 'grid',
315
   variants: {
312
   variants: {
316
-    selectedStyle: {
313
+    numberOfSelected: {
317
       threeOrMore: {
314
       threeOrMore: {
318
         gridTemplateColumns: 'repeat(5, auto)',
315
         gridTemplateColumns: 'repeat(5, auto)',
319
       },
316
       },
324
   },
321
   },
325
 })
322
 })
326
 
323
 
327
-/* ------------------ Move to Page ------------------ */
324
+/* -------------- Move to Page Sub Menu ------------- */
328
 
325
 
329
 const currentPageIdSelector = (s: TDSnapshot) => s.appState.currentPageId
326
 const currentPageIdSelector = (s: TDSnapshot) => s.appState.currentPageId
330
 const documentPagesSelector = (s: TDSnapshot) => s.document.pages
327
 const documentPagesSelector = (s: TDSnapshot) => s.document.pages
387
 const CMArrow = styled(RadixContextMenu.ContextMenuArrow, {
384
 const CMArrow = styled(RadixContextMenu.ContextMenuArrow, {
388
   fill: '$panel',
385
   fill: '$panel',
389
 })
386
 })
387
+
388
+/* ------------------- IconButton ------------------- */
389
+
390
+function CMIconButton({ onSelect, ...rest }: ToolButtonProps): JSX.Element {
391
+  return (
392
+    <RadixContextMenu.ContextMenuItem dir="ltr" onSelect={onSelect} asChild>
393
+      <ToolButton {...rest} />
394
+    </RadixContextMenu.ContextMenuItem>
395
+  )
396
+}
397
+
398
+/* -------------------- RowButton ------------------- */
399
+
400
+const CMRowButton = ({ ...rest }: RowButtonProps) => {
401
+  return (
402
+    <RadixContextMenu.ContextMenuItem asChild>
403
+      <RowButton {...rest} />
404
+    </RadixContextMenu.ContextMenuItem>
405
+  )
406
+}
407
+
408
+/* ----------------- Trigger Button ----------------- */
409
+
410
+interface CMTriggerButtonProps extends RowButtonProps {
411
+  isSubmenu?: boolean
412
+}
413
+
414
+export const CMTriggerButton = ({ isSubmenu, ...rest }: CMTriggerButtonProps) => {
415
+  return (
416
+    <RadixContextMenu.ContextMenuTriggerItem asChild>
417
+      <RowButton hasArrow={isSubmenu} {...rest} />
418
+    </RadixContextMenu.ContextMenuTriggerItem>
419
+  )
420
+}

+ 1
- 1
packages/tldraw/src/components/FocusButton/FocusButton.tsx 查看文件

1
 import { DotFilledIcon } from '@radix-ui/react-icons'
1
 import { DotFilledIcon } from '@radix-ui/react-icons'
2
 import * as React from 'react'
2
 import * as React from 'react'
3
-import { IconButton } from '~components/IconButton/IconButton'
3
+import { IconButton } from '~components/Primitives/IconButton/IconButton'
4
 import { styled } from '~styles'
4
 import { styled } from '~styles'
5
 
5
 
6
 interface FocusButtonProps {
6
 interface FocusButtonProps {

packages/tldraw/src/components/Divider/Divider.tsx → packages/tldraw/src/components/Primitives/Divider/Divider.tsx 查看文件


packages/tldraw/src/components/Divider/index.ts → packages/tldraw/src/components/Primitives/Divider/index.ts 查看文件


packages/tldraw/src/components/DropdownMenu/DMArrow.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMArrow.tsx 查看文件


packages/tldraw/src/components/DropdownMenu/DMCheckboxItem.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMCheckboxItem.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { CheckboxItem } from '@radix-ui/react-dropdown-menu'
2
 import { CheckboxItem } from '@radix-ui/react-dropdown-menu'
3
-import { RowButton, RowButtonProps } from '~components/RowButton'
3
+import { RowButton, RowButtonProps } from '~components/Primitives/RowButton'
4
 import { preventEvent } from '~components/preventEvent'
4
 import { preventEvent } from '~components/preventEvent'
5
 
5
 
6
 interface DMCheckboxItemProps {
6
 interface DMCheckboxItemProps {

packages/tldraw/src/components/DropdownMenu/DMContent.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMContent.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { Content } from '@radix-ui/react-dropdown-menu'
2
 import { Content } from '@radix-ui/react-dropdown-menu'
3
 import { styled } from '~styles/stitches.config'
3
 import { styled } from '~styles/stitches.config'
4
-import { MenuContent } from '~components/MenuContent'
4
+import { MenuContent } from '~components/Primitives/MenuContent'
5
 import { stopPropagation } from '~components/stopPropagation'
5
 import { stopPropagation } from '~components/stopPropagation'
6
 
6
 
7
 export interface DMContentProps {
7
 export interface DMContentProps {

packages/tldraw/src/components/DropdownMenu/DMDivider.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMDivider.tsx 查看文件


packages/tldraw/src/components/DropdownMenu/DMItem.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMItem.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { Item } from '@radix-ui/react-dropdown-menu'
2
 import { Item } from '@radix-ui/react-dropdown-menu'
3
-import { RowButton, RowButtonProps } from '~components/RowButton'
3
+import { RowButton, RowButtonProps } from '~components/Primitives/RowButton'
4
 
4
 
5
 export function DMItem({
5
 export function DMItem({
6
   onSelect,
6
   onSelect,

packages/tldraw/src/components/DropdownMenu/DMRadioItem.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMRadioItem.tsx 查看文件


packages/tldraw/src/components/DropdownMenu/DMSubMenu.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMSubMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { Root, TriggerItem, Content, Arrow } from '@radix-ui/react-dropdown-menu'
2
 import { Root, TriggerItem, Content, Arrow } from '@radix-ui/react-dropdown-menu'
3
-import { RowButton } from '~components/RowButton'
4
-import { MenuContent } from '~components/MenuContent'
3
+import { RowButton } from '~components/Primitives/RowButton'
4
+import { MenuContent } from '~components/Primitives/MenuContent'
5
 
5
 
6
 export interface DMSubMenuProps {
6
 export interface DMSubMenuProps {
7
   label: string
7
   label: string

packages/tldraw/src/components/DropdownMenu/DMTriggerIcon.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/DMTriggerIcon.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { Trigger } from '@radix-ui/react-dropdown-menu'
2
 import { Trigger } from '@radix-ui/react-dropdown-menu'
3
-import { ToolButton, ToolButtonProps } from '~components/ToolButton'
3
+import { ToolButton, ToolButtonProps } from '~components/Primitives/ToolButton'
4
 
4
 
5
 interface DMTriggerIconProps extends ToolButtonProps {
5
 interface DMTriggerIconProps extends ToolButtonProps {
6
   children: React.ReactNode
6
   children: React.ReactNode

packages/tldraw/src/components/DropdownMenu/index.tsx → packages/tldraw/src/components/Primitives/DropdownMenu/index.tsx 查看文件


packages/tldraw/src/components/IconButton/IconButton.tsx → packages/tldraw/src/components/Primitives/IconButton/IconButton.tsx 查看文件


packages/tldraw/src/components/IconButton/index.ts → packages/tldraw/src/components/Primitives/IconButton/index.ts 查看文件


packages/tldraw/src/components/Kbd/Kbd.tsx → packages/tldraw/src/components/Primitives/Kbd/Kbd.tsx 查看文件


packages/tldraw/src/components/Kbd/index.ts → packages/tldraw/src/components/Primitives/Kbd/index.ts 查看文件


packages/tldraw/src/components/MenuContent/MenuContent.ts → packages/tldraw/src/components/Primitives/MenuContent/MenuContent.ts 查看文件


packages/tldraw/src/components/MenuContent/index.ts → packages/tldraw/src/components/Primitives/MenuContent/index.ts 查看文件


packages/tldraw/src/components/Panel/Panel.tsx → packages/tldraw/src/components/Primitives/Panel/Panel.tsx 查看文件


packages/tldraw/src/components/Panel/index.ts → packages/tldraw/src/components/Primitives/Panel/index.ts 查看文件


packages/tldraw/src/components/RowButton/RowButton.tsx → packages/tldraw/src/components/Primitives/RowButton/RowButton.tsx 查看文件

2
 import { ChevronRightIcon, CheckIcon } from '@radix-ui/react-icons'
2
 import { ChevronRightIcon, CheckIcon } from '@radix-ui/react-icons'
3
 import * as React from 'react'
3
 import * as React from 'react'
4
 import { breakpoints } from '~components/breakpoints'
4
 import { breakpoints } from '~components/breakpoints'
5
-import { Kbd } from '~components/Kbd'
6
-import { SmallIcon } from '~components/SmallIcon'
5
+import { Kbd } from '~components/Primitives/Kbd'
6
+import { SmallIcon } from '~components/Primitives/SmallIcon'
7
 import { styled } from '~styles'
7
 import { styled } from '~styles'
8
 
8
 
9
 export interface RowButtonProps {
9
 export interface RowButtonProps {

packages/tldraw/src/components/RowButton/index.ts → packages/tldraw/src/components/Primitives/RowButton/index.ts 查看文件


packages/tldraw/src/components/SmallIcon/SmallIcon.tsx → packages/tldraw/src/components/Primitives/SmallIcon/SmallIcon.tsx 查看文件


packages/tldraw/src/components/SmallIcon/index.ts → packages/tldraw/src/components/Primitives/SmallIcon/index.ts 查看文件


packages/tldraw/src/components/ToolButton/ToolButton.tsx → packages/tldraw/src/components/Primitives/ToolButton/ToolButton.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { breakpoints } from '~components/breakpoints'
2
 import { breakpoints } from '~components/breakpoints'
3
-import { Tooltip } from '~components/Tooltip'
3
+import { Tooltip } from '~components/Primitives/Tooltip'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
 import { styled } from '~styles'
5
 import { styled } from '~styles'
6
 
6
 

packages/tldraw/src/components/ToolButton/index.ts → packages/tldraw/src/components/Primitives/ToolButton/index.ts 查看文件


packages/tldraw/src/components/Tooltip/Tooltip.tsx → packages/tldraw/src/components/Primitives/Tooltip/Tooltip.tsx 查看文件

1
 import * as RadixTooltip from '@radix-ui/react-tooltip'
1
 import * as RadixTooltip from '@radix-ui/react-tooltip'
2
 import * as React from 'react'
2
 import * as React from 'react'
3
-import { Kbd } from '~components/Kbd'
3
+import { Kbd } from '~components/Primitives/Kbd'
4
 import { styled } from '~styles'
4
 import { styled } from '~styles'
5
 
5
 
6
 /* -------------------------------------------------- */
6
 /* -------------------------------------------------- */

packages/tldraw/src/components/Tooltip/index.ts → packages/tldraw/src/components/Primitives/Tooltip/index.ts 查看文件


packages/tldraw/src/components/icons/BoxIcon.tsx → packages/tldraw/src/components/Primitives/icons/BoxIcon.tsx 查看文件


packages/tldraw/src/components/icons/CircleIcon.tsx → packages/tldraw/src/components/Primitives/icons/CircleIcon.tsx 查看文件


packages/tldraw/src/components/icons/DashDashedIcon.tsx → packages/tldraw/src/components/Primitives/icons/DashDashedIcon.tsx 查看文件


packages/tldraw/src/components/icons/DashDottedIcon.tsx → packages/tldraw/src/components/Primitives/icons/DashDottedIcon.tsx 查看文件


packages/tldraw/src/components/icons/DashDrawIcon.tsx → packages/tldraw/src/components/Primitives/icons/DashDrawIcon.tsx 查看文件


packages/tldraw/src/components/icons/DashSolidIcon.tsx → packages/tldraw/src/components/Primitives/icons/DashSolidIcon.tsx 查看文件


packages/tldraw/src/components/icons/EraserIcon.tsx → packages/tldraw/src/components/Primitives/icons/EraserIcon.tsx 查看文件


packages/tldraw/src/components/icons/HeartIcon.tsx → packages/tldraw/src/components/Primitives/icons/HeartIcon.tsx 查看文件


packages/tldraw/src/components/icons/IsFilledIcon.tsx → packages/tldraw/src/components/Primitives/icons/IsFilledIcon.tsx 查看文件


packages/tldraw/src/components/icons/MultiplayerIcon.tsx → packages/tldraw/src/components/Primitives/icons/MultiplayerIcon.tsx 查看文件


packages/tldraw/src/components/icons/RedoIcon.tsx → packages/tldraw/src/components/Primitives/icons/RedoIcon.tsx 查看文件


packages/tldraw/src/components/icons/SizeLargeIcon.tsx → packages/tldraw/src/components/Primitives/icons/SizeLargeIcon.tsx 查看文件


packages/tldraw/src/components/icons/SizeMediumIcon.tsx → packages/tldraw/src/components/Primitives/icons/SizeMediumIcon.tsx 查看文件


packages/tldraw/src/components/icons/SizeSmallIcon.tsx → packages/tldraw/src/components/Primitives/icons/SizeSmallIcon.tsx 查看文件


packages/tldraw/src/components/icons/TrashIcon.tsx → packages/tldraw/src/components/Primitives/icons/TrashIcon.tsx 查看文件


packages/tldraw/src/components/icons/UndoIcon.tsx → packages/tldraw/src/components/Primitives/icons/UndoIcon.tsx 查看文件


packages/tldraw/src/components/icons/index.ts → packages/tldraw/src/components/Primitives/icons/index.ts 查看文件


+ 5
- 5
packages/tldraw/src/components/ToolsPanel/ActionButton.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import { Tooltip } from '~components/Tooltip/Tooltip'
2
+import { Tooltip } from '~components/Primitives/Tooltip/Tooltip'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
 import { styled } from '~styles'
5
 import { styled } from '~styles'
28
   StretchVerticallyIcon,
28
   StretchVerticallyIcon,
29
   BoxIcon,
29
   BoxIcon,
30
 } from '@radix-ui/react-icons'
30
 } from '@radix-ui/react-icons'
31
-import { DMContent } from '~components/DropdownMenu'
32
-import { Divider } from '~components/Divider'
33
-import { TrashIcon } from '~components/icons'
34
-import { ToolButton } from '~components/ToolButton'
31
+import { DMContent } from '~components/Primitives/DropdownMenu'
32
+import { Divider } from '~components/Primitives/Divider'
33
+import { TrashIcon } from '~components/Primitives/icons'
34
+import { ToolButton } from '~components/Primitives/ToolButton'
35
 
35
 
36
 const selectedShapesCountSelector = (s: TDSnapshot) =>
36
 const selectedShapesCountSelector = (s: TDSnapshot) =>
37
   s.document.pageStates[s.appState.currentPageId].selectedIds.length
37
   s.document.pageStates[s.appState.currentPageId].selectedIds.length

+ 2
- 2
packages/tldraw/src/components/ToolsPanel/BackToContent.tsx 查看文件

2
 import { styled } from '~styles'
2
 import { styled } from '~styles'
3
 import type { TDSnapshot } from '~types'
3
 import type { TDSnapshot } from '~types'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
-import { RowButton } from '~components/RowButton'
6
-import { MenuContent } from '~components/MenuContent'
5
+import { RowButton } from '~components/Primitives/RowButton'
6
+import { MenuContent } from '~components/Primitives/MenuContent'
7
 
7
 
8
 const isEmptyCanvasSelector = (s: TDSnapshot) =>
8
 const isEmptyCanvasSelector = (s: TDSnapshot) =>
9
   Object.keys(s.document.pages[s.appState.currentPageId].shapes).length > 0 &&
9
   Object.keys(s.document.pages[s.appState.currentPageId].shapes).length > 0 &&

+ 3
- 3
packages/tldraw/src/components/ToolsPanel/DeleteButton.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import { Tooltip } from '~components/Tooltip'
2
+import { Tooltip } from '~components/Primitives/Tooltip'
3
 import { useTldrawApp } from '~hooks'
3
 import { useTldrawApp } from '~hooks'
4
-import { ToolButton } from '~components/ToolButton'
5
-import { TrashIcon } from '~components/icons'
4
+import { ToolButton } from '~components/Primitives/ToolButton'
5
+import { TrashIcon } from '~components/Primitives/icons'
6
 
6
 
7
 export function DeleteButton(): JSX.Element {
7
 export function DeleteButton(): JSX.Element {
8
   const app = useTldrawApp()
8
   const app = useTldrawApp()

+ 2
- 2
packages/tldraw/src/components/ToolsPanel/LockButton.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { LockClosedIcon, LockOpen1Icon } from '@radix-ui/react-icons'
2
 import { LockClosedIcon, LockOpen1Icon } from '@radix-ui/react-icons'
3
-import { Tooltip } from '~components/Tooltip'
3
+import { Tooltip } from '~components/Primitives/Tooltip'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
-import { ToolButton } from '~components/ToolButton'
5
+import { ToolButton } from '~components/Primitives/ToolButton'
6
 import type { TDSnapshot } from '~types'
6
 import type { TDSnapshot } from '~types'
7
 
7
 
8
 const isToolLockedSelector = (s: TDSnapshot) => s.appState.isToolLocked
8
 const isToolLockedSelector = (s: TDSnapshot) => s.appState.isToolLocked

+ 3
- 3
packages/tldraw/src/components/ToolsPanel/PenMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
-import { Panel } from '~components/Panel'
4
-import { ToolButton } from '~components/ToolButton'
3
+import { Panel } from '~components/Primitives/Panel'
4
+import { ToolButton } from '~components/Primitives/ToolButton'
5
 import { TDShapeType, TDToolType } from '~types'
5
 import { TDShapeType, TDToolType } from '~types'
6
 import { useTldrawApp } from '~hooks'
6
 import { useTldrawApp } from '~hooks'
7
 import { Pencil1Icon } from '@radix-ui/react-icons'
7
 import { Pencil1Icon } from '@radix-ui/react-icons'
8
-import { Tooltip } from '~components/Tooltip'
8
+import { Tooltip } from '~components/Primitives/Tooltip'
9
 
9
 
10
 interface ShapesMenuProps {
10
 interface ShapesMenuProps {
11
   activeTool: TDToolType
11
   activeTool: TDToolType

+ 3
- 3
packages/tldraw/src/components/ToolsPanel/PrimaryTools.tsx 查看文件

8
 } from '@radix-ui/react-icons'
8
 } from '@radix-ui/react-icons'
9
 import { TDSnapshot, TDShapeType } from '~types'
9
 import { TDSnapshot, TDShapeType } from '~types'
10
 import { useTldrawApp } from '~hooks'
10
 import { useTldrawApp } from '~hooks'
11
-import { ToolButtonWithTooltip } from '~components/ToolButton'
12
-import { Panel } from '~components/Panel'
11
+import { ToolButtonWithTooltip } from '~components/Primitives/ToolButton'
12
+import { Panel } from '~components/Primitives/Panel'
13
 import { ShapesMenu } from './ShapesMenu'
13
 import { ShapesMenu } from './ShapesMenu'
14
-import { EraserIcon } from '~components/icons'
14
+import { EraserIcon } from '~components/Primitives/icons'
15
 
15
 
16
 const activeToolSelector = (s: TDSnapshot) => s.appState.activeTool
16
 const activeToolSelector = (s: TDSnapshot) => s.appState.activeTool
17
 const toolLockedSelector = (s: TDSnapshot) => s.appState.isToolLocked
17
 const toolLockedSelector = (s: TDSnapshot) => s.appState.isToolLocked

+ 3
- 3
packages/tldraw/src/components/ToolsPanel/ShapesMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
-import { Panel } from '~components/Panel'
4
-import { ToolButton } from '~components/ToolButton'
3
+import { Panel } from '~components/Primitives/Panel'
4
+import { ToolButton } from '~components/Primitives/ToolButton'
5
 import { TDShapeType, TDToolType } from '~types'
5
 import { TDShapeType, TDToolType } from '~types'
6
 import { useTldrawApp } from '~hooks'
6
 import { useTldrawApp } from '~hooks'
7
 import { SquareIcon, CircleIcon } from '@radix-ui/react-icons'
7
 import { SquareIcon, CircleIcon } from '@radix-ui/react-icons'
8
-import { Tooltip } from '~components/Tooltip'
8
+import { Tooltip } from '~components/Primitives/Tooltip'
9
 
9
 
10
 interface ShapesMenuProps {
10
 interface ShapesMenuProps {
11
   activeTool: TDToolType
11
   activeTool: TDToolType

+ 0
- 3
packages/tldraw/src/components/TopPanel/HelpMenu.tsx 查看文件

1
-export function HelpMenu() {
2
-  return <div />
3
-}

packages/tldraw/src/components/TopPanel/Menu.tsx → packages/tldraw/src/components/TopPanel/Menu/Menu.tsx 查看文件

2
 import { ExitIcon, GitHubLogoIcon, HamburgerMenuIcon, TwitterLogoIcon } from '@radix-ui/react-icons'
2
 import { ExitIcon, GitHubLogoIcon, HamburgerMenuIcon, TwitterLogoIcon } from '@radix-ui/react-icons'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
-import { PreferencesMenu } from './PreferencesMenu'
6
-import { DMItem, DMContent, DMDivider, DMSubMenu, DMTriggerIcon } from '~components/DropdownMenu'
7
-import { SmallIcon } from '~components/SmallIcon'
5
+import { PreferencesMenu } from '../PreferencesMenu'
6
+import {
7
+  DMItem,
8
+  DMContent,
9
+  DMDivider,
10
+  DMSubMenu,
11
+  DMTriggerIcon,
12
+} from '~components/Primitives/DropdownMenu'
13
+import { SmallIcon } from '~components/Primitives/SmallIcon'
8
 import { useFileSystemHandlers } from '~hooks'
14
 import { useFileSystemHandlers } from '~hooks'
9
-import { HeartIcon } from '~components/icons/HeartIcon'
15
+import { HeartIcon } from '~components/Primitives/icons/HeartIcon'
10
 import { preventEvent } from '~components/preventEvent'
16
 import { preventEvent } from '~components/preventEvent'
11
 
17
 
12
 interface MenuProps {
18
 interface MenuProps {

+ 0
- 0
packages/tldraw/src/components/TopPanel/Menu/index.ts 查看文件


packages/tldraw/src/components/TopPanel/MultiplayerMenu.tsx → packages/tldraw/src/components/TopPanel/MultiplayerMenu/MultiplayerMenu.tsx 查看文件

2
 import { CheckIcon, ClipboardIcon } from '@radix-ui/react-icons'
2
 import { CheckIcon, ClipboardIcon } from '@radix-ui/react-icons'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
-import { DMItem, DMContent, DMDivider, DMTriggerIcon } from '~components/DropdownMenu'
6
-import { SmallIcon } from '~components/SmallIcon'
7
-import { MultiplayerIcon } from '~components/icons'
5
+import { DMItem, DMContent, DMDivider, DMTriggerIcon } from '~components/Primitives/DropdownMenu'
6
+import { SmallIcon } from '~components/Primitives/SmallIcon'
7
+import { MultiplayerIcon } from '~components/Primitives/icons'
8
 import type { TDSnapshot } from '~types'
8
 import type { TDSnapshot } from '~types'
9
 import { TLDR } from '~state/TLDR'
9
 import { TLDR } from '~state/TLDR'
10
 
10
 

+ 1
- 0
packages/tldraw/src/components/TopPanel/MultiplayerMenu/index.ts 查看文件

1
+export * from './MultiplayerMenu'

packages/tldraw/src/components/TopPanel/PageMenu.tsx → packages/tldraw/src/components/TopPanel/PageMenu/PageMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
 import { PlusIcon, CheckIcon } from '@radix-ui/react-icons'
3
 import { PlusIcon, CheckIcon } from '@radix-ui/react-icons'
4
-import { PageOptionsDialog } from './PageOptionsDialog'
4
+import { PageOptionsDialog } from '../PageOptionsDialog'
5
 import { styled } from '~styles'
5
 import { styled } from '~styles'
6
 import { useTldrawApp } from '~hooks'
6
 import { useTldrawApp } from '~hooks'
7
 import type { TDSnapshot } from '~types'
7
 import type { TDSnapshot } from '~types'
8
-import { DMContent, DMDivider } from '~components/DropdownMenu'
9
-import { SmallIcon } from '~components/SmallIcon'
10
-import { RowButton } from '~components/RowButton'
11
-import { ToolButton } from '~components/ToolButton'
8
+import { DMContent, DMDivider } from '~components/Primitives/DropdownMenu'
9
+import { SmallIcon } from '~components/Primitives/SmallIcon'
10
+import { RowButton } from '~components/Primitives/RowButton'
11
+import { ToolButton } from '~components/Primitives/ToolButton'
12
 
12
 
13
 const sortedSelector = (s: TDSnapshot) =>
13
 const sortedSelector = (s: TDSnapshot) =>
14
   Object.values(s.document.pages).sort((a, b) => (a.childIndex || 0) - (b.childIndex || 0))
14
   Object.values(s.document.pages).sort((a, b) => (a.childIndex || 0) - (b.childIndex || 0))

+ 1
- 0
packages/tldraw/src/components/TopPanel/PageMenu/index.ts 查看文件

1
+export * from './PageMenu'

packages/tldraw/src/components/TopPanel/PageOptionsDialog.tsx → packages/tldraw/src/components/TopPanel/PageOptionsDialog/PageOptionsDialog.tsx 查看文件

3
 import { MixerVerticalIcon } from '@radix-ui/react-icons'
3
 import { MixerVerticalIcon } from '@radix-ui/react-icons'
4
 import type { TDSnapshot, TDPage } from '~types'
4
 import type { TDSnapshot, TDPage } from '~types'
5
 import { useTldrawApp } from '~hooks'
5
 import { useTldrawApp } from '~hooks'
6
-import { RowButton, RowButtonProps } from '~components/RowButton'
6
+import { RowButton, RowButtonProps } from '~components/Primitives/RowButton'
7
 import { styled } from '~styles'
7
 import { styled } from '~styles'
8
-import { Divider } from '~components/Divider'
9
-import { IconButton } from '~components/IconButton/IconButton'
10
-import { SmallIcon } from '~components/SmallIcon'
8
+import { Divider } from '~components/Primitives/Divider'
9
+import { IconButton } from '~components/Primitives/IconButton/IconButton'
10
+import { SmallIcon } from '~components/Primitives/SmallIcon'
11
 import { breakpoints } from '~components/breakpoints'
11
 import { breakpoints } from '~components/breakpoints'
12
 
12
 
13
 const canDeleteSelector = (s: TDSnapshot) => {
13
 const canDeleteSelector = (s: TDSnapshot) => {

+ 1
- 0
packages/tldraw/src/components/TopPanel/PageOptionsDialog/index.ts 查看文件

1
+export * from './PageOptionsDialog'

packages/tldraw/src/components/TopPanel/PreferencesMenu.tsx → packages/tldraw/src/components/TopPanel/PreferencesMenu/PreferencesMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import { DMCheckboxItem, DMDivider, DMSubMenu } from '~components/DropdownMenu'
2
+import { DMCheckboxItem, DMDivider, DMSubMenu } from '~components/Primitives/DropdownMenu'
3
 import { useTldrawApp } from '~hooks'
3
 import { useTldrawApp } from '~hooks'
4
 import type { TDSnapshot } from '~types'
4
 import type { TDSnapshot } from '~types'
5
 
5
 

+ 1
- 0
packages/tldraw/src/components/TopPanel/PreferencesMenu/index.ts 查看文件

1
+export * from './PreferencesMenu'

+ 4
- 0
packages/tldraw/src/components/TopPanel/StyleMenu/StyleMenu.test.tsx 查看文件

1
+describe('the style menu', () => {
2
+  test.todo('Correctly sets the style properties when shapes are selected')
3
+  test.todo('Correctly sets the style properties when nothing is selected')
4
+})

packages/tldraw/src/components/TopPanel/StyleMenu.tsx → packages/tldraw/src/components/TopPanel/StyleMenu/StyleMenu.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
2
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
-import { strokes, fills } from '~state/shapes/shared/shape-styles'
3
+import { strokes, fills, defaultStyle } from '~state/shapes/shared/shape-styles'
4
 import { useTldrawApp } from '~hooks'
4
 import { useTldrawApp } from '~hooks'
5
-import { DMCheckboxItem, DMContent, DMRadioItem, DMTriggerIcon } from '~components/DropdownMenu'
5
+import {
6
+  DMCheckboxItem,
7
+  DMContent,
8
+  DMRadioItem,
9
+  DMTriggerIcon,
10
+} from '~components/Primitives/DropdownMenu'
6
 import {
11
 import {
7
   CircleIcon,
12
   CircleIcon,
8
   DashDashedIcon,
13
   DashDashedIcon,
12
   SizeLargeIcon,
17
   SizeLargeIcon,
13
   SizeMediumIcon,
18
   SizeMediumIcon,
14
   SizeSmallIcon,
19
   SizeSmallIcon,
15
-} from '~components/icons'
16
-import { ToolButton } from '~components/ToolButton'
17
-import { TDSnapshot, ColorStyle, DashStyle, SizeStyle } from '~types'
20
+} from '~components/Primitives/icons'
21
+import { ToolButton } from '~components/Primitives/ToolButton'
22
+import { TDSnapshot, ColorStyle, DashStyle, SizeStyle, ShapeStyles } from '~types'
18
 import { styled } from '~styles'
23
 import { styled } from '~styles'
19
 import { breakpoints } from '~components/breakpoints'
24
 import { breakpoints } from '~components/breakpoints'
20
-import { Divider } from '~components/Divider'
25
+import { Divider } from '~components/Primitives/Divider'
21
 import { preventEvent } from '~components/preventEvent'
26
 import { preventEvent } from '~components/preventEvent'
22
 
27
 
23
-const selectedStyleSelector = (s: TDSnapshot) => s.appState.selectedStyle
28
+const currentStyleSelector = (s: TDSnapshot) => s.appState.currentStyle
29
+const selectedIdsSelector = (s: TDSnapshot) =>
30
+  s.document.pageStates[s.appState.currentPageId].selectedIds
31
+
32
+const STYLE_KEYS = Object.keys(defaultStyle) as (keyof ShapeStyles)[]
24
 
33
 
25
-const dashes = {
34
+const DASHES = {
26
   [DashStyle.Draw]: <DashDrawIcon />,
35
   [DashStyle.Draw]: <DashDrawIcon />,
27
   [DashStyle.Solid]: <DashSolidIcon />,
36
   [DashStyle.Solid]: <DashSolidIcon />,
28
   [DashStyle.Dashed]: <DashDashedIcon />,
37
   [DashStyle.Dashed]: <DashDashedIcon />,
29
   [DashStyle.Dotted]: <DashDottedIcon />,
38
   [DashStyle.Dotted]: <DashDottedIcon />,
30
 }
39
 }
31
 
40
 
32
-const sizes = {
41
+const SIZES = {
33
   [SizeStyle.Small]: <SizeSmallIcon />,
42
   [SizeStyle.Small]: <SizeSmallIcon />,
34
   [SizeStyle.Medium]: <SizeMediumIcon />,
43
   [SizeStyle.Medium]: <SizeMediumIcon />,
35
   [SizeStyle.Large]: <SizeLargeIcon />,
44
   [SizeStyle.Large]: <SizeLargeIcon />,
42
 
51
 
43
   const theme = app.useStore(themeSelector)
52
   const theme = app.useStore(themeSelector)
44
 
53
 
45
-  const style = app.useStore(selectedStyleSelector)
54
+  const currentStyle = app.useStore(currentStyleSelector)
55
+  const selectedIds = app.useStore(selectedIdsSelector)
56
+
57
+  const [displayedStyle, setDisplayedStyle] = React.useState(currentStyle)
58
+  const rDisplayedStyle = React.useRef(currentStyle)
59
+
60
+  React.useEffect(() => {
61
+    const {
62
+      appState: { currentStyle },
63
+      page,
64
+      selectedIds,
65
+    } = app
66
+
67
+    let commonStyle = {} as ShapeStyles
68
+
69
+    if (selectedIds.length <= 0) {
70
+      commonStyle = currentStyle
71
+    } else {
72
+      const overrides = new Set<string>([])
73
+
74
+      app.selectedIds
75
+        .map((id) => page.shapes[id])
76
+        .forEach((shape) => {
77
+          STYLE_KEYS.forEach((key) => {
78
+            if (overrides.has(key)) return
79
+            if (commonStyle[key] === undefined) {
80
+              // eslint-disable-next-line @typescript-eslint/ban-ts-comment
81
+              // @ts-ignore
82
+              commonStyle[key] = shape.style[key]
83
+            } else {
84
+              if (commonStyle[key] === shape.style[key]) return
85
+              // eslint-disable-next-line @typescript-eslint/ban-ts-comment
86
+              // @ts-ignore
87
+              commonStyle[key] = shape.style[key]
88
+              overrides.add(key)
89
+            }
90
+          })
91
+        })
92
+    }
93
+
94
+    // Until we can work out the correct logic for deciding whether or not to
95
+    // update the selected style, do a string comparison. Yuck!
96
+    if (JSON.stringify(commonStyle) !== JSON.stringify(rDisplayedStyle.current)) {
97
+      rDisplayedStyle.current = commonStyle
98
+      setDisplayedStyle(commonStyle)
99
+    }
100
+  }, [currentStyle, selectedIds])
46
 
101
 
47
   const handleToggleFilled = React.useCallback((checked: boolean) => {
102
   const handleToggleFilled = React.useCallback((checked: boolean) => {
48
     app.style({ isFilled: checked })
103
     app.style({ isFilled: checked })
61
       <DMTriggerIcon>
116
       <DMTriggerIcon>
62
         <OverlapIcons
117
         <OverlapIcons
63
           style={{
118
           style={{
64
-            color: strokes[theme][style.color as ColorStyle],
119
+            color: strokes[theme][displayedStyle.color as ColorStyle],
65
           }}
120
           }}
66
         >
121
         >
67
-          {style.isFilled && (
68
-            <CircleIcon size={16} stroke="none" fill={fills[theme][style.color as ColorStyle]} />
122
+          {displayedStyle.isFilled && (
123
+            <CircleIcon
124
+              size={16}
125
+              stroke="none"
126
+              fill={fills[theme][displayedStyle.color as ColorStyle]}
127
+            />
69
           )}
128
           )}
70
-          {dashes[style.dash]}
129
+          {DASHES[displayedStyle.dash]}
71
         </OverlapIcons>
130
         </OverlapIcons>
72
       </DMTriggerIcon>
131
       </DMTriggerIcon>
73
       <DMContent>
132
       <DMContent>
78
               <DropdownMenu.Item key={colorStyle} onSelect={preventEvent} asChild>
137
               <DropdownMenu.Item key={colorStyle} onSelect={preventEvent} asChild>
79
                 <ToolButton
138
                 <ToolButton
80
                   variant="icon"
139
                   variant="icon"
81
-                  isActive={style.color === colorStyle}
140
+                  isActive={displayedStyle.color === colorStyle}
82
                   onClick={() => app.style({ color: colorStyle as ColorStyle })}
141
                   onClick={() => app.style({ color: colorStyle as ColorStyle })}
83
                 >
142
                 >
84
                   <CircleIcon
143
                   <CircleIcon
85
                     size={18}
144
                     size={18}
86
                     strokeWidth={2.5}
145
                     strokeWidth={2.5}
87
-                    fill={style.isFilled ? fills.light[colorStyle as ColorStyle] : 'transparent'}
146
+                    fill={
147
+                      displayedStyle.isFilled
148
+                        ? fills.light[colorStyle as ColorStyle]
149
+                        : 'transparent'
150
+                    }
88
                     stroke={strokes.light[colorStyle as ColorStyle]}
151
                     stroke={strokes.light[colorStyle as ColorStyle]}
89
                   />
152
                   />
90
                 </ToolButton>
153
                 </ToolButton>
95
         <Divider />
158
         <Divider />
96
         <StyledRow>
159
         <StyledRow>
97
           Dash
160
           Dash
98
-          <StyledGroup dir="ltr" value={style.dash} onValueChange={handleDashChange}>
161
+          <StyledGroup dir="ltr" value={displayedStyle.dash} onValueChange={handleDashChange}>
99
             {Object.values(DashStyle).map((dashStyle) => (
162
             {Object.values(DashStyle).map((dashStyle) => (
100
               <DMRadioItem
163
               <DMRadioItem
101
                 key={dashStyle}
164
                 key={dashStyle}
102
-                isActive={dashStyle === style.dash}
165
+                isActive={dashStyle === displayedStyle.dash}
103
                 value={dashStyle}
166
                 value={dashStyle}
104
                 onSelect={preventEvent}
167
                 onSelect={preventEvent}
105
                 bp={breakpoints}
168
                 bp={breakpoints}
106
               >
169
               >
107
-                {dashes[dashStyle as DashStyle]}
170
+                {DASHES[dashStyle as DashStyle]}
108
               </DMRadioItem>
171
               </DMRadioItem>
109
             ))}
172
             ))}
110
           </StyledGroup>
173
           </StyledGroup>
112
         <Divider />
175
         <Divider />
113
         <StyledRow>
176
         <StyledRow>
114
           Size
177
           Size
115
-          <StyledGroup dir="ltr" value={style.size} onValueChange={handleSizeChange}>
178
+          <StyledGroup dir="ltr" value={displayedStyle.size} onValueChange={handleSizeChange}>
116
             {Object.values(SizeStyle).map((sizeStyle) => (
179
             {Object.values(SizeStyle).map((sizeStyle) => (
117
               <DMRadioItem
180
               <DMRadioItem
118
                 key={sizeStyle}
181
                 key={sizeStyle}
119
-                isActive={sizeStyle === style.size}
182
+                isActive={sizeStyle === displayedStyle.size}
120
                 value={sizeStyle}
183
                 value={sizeStyle}
121
                 onSelect={preventEvent}
184
                 onSelect={preventEvent}
122
                 bp={breakpoints}
185
                 bp={breakpoints}
123
               >
186
               >
124
-                {sizes[sizeStyle as SizeStyle]}
187
+                {SIZES[sizeStyle as SizeStyle]}
125
               </DMRadioItem>
188
               </DMRadioItem>
126
             ))}
189
             ))}
127
           </StyledGroup>
190
           </StyledGroup>
128
         </StyledRow>
191
         </StyledRow>
129
         <Divider />
192
         <Divider />
130
-        <DMCheckboxItem checked={!!style.isFilled} onCheckedChange={handleToggleFilled}>
193
+        <DMCheckboxItem checked={!!displayedStyle.isFilled} onCheckedChange={handleToggleFilled}>
131
           Fill
194
           Fill
132
         </DMCheckboxItem>
195
         </DMCheckboxItem>
133
       </DMContent>
196
       </DMContent>

+ 1
- 0
packages/tldraw/src/components/TopPanel/StyleMenu/index.ts 查看文件

1
+export * from './StyleMenu'

+ 2
- 2
packages/tldraw/src/components/TopPanel/TopPanel.tsx 查看文件

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import { Menu } from './Menu'
2
+import { Menu } from './Menu/Menu'
3
 import { styled } from '~styles'
3
 import { styled } from '~styles'
4
 import { PageMenu } from './PageMenu'
4
 import { PageMenu } from './PageMenu'
5
 import { ZoomMenu } from './ZoomMenu'
5
 import { ZoomMenu } from './ZoomMenu'
6
 import { StyleMenu } from './StyleMenu'
6
 import { StyleMenu } from './StyleMenu'
7
-import { Panel } from '~components/Panel'
7
+import { Panel } from '~components/Primitives/Panel'
8
 
8
 
9
 interface TopPanelProps {
9
 interface TopPanelProps {
10
   readOnly: boolean
10
   readOnly: boolean

packages/tldraw/src/components/TopPanel/ZoomMenu.tsx → packages/tldraw/src/components/TopPanel/ZoomMenu/ZoomMenu.tsx 查看文件

3
 import type { TDSnapshot } from '~types'
3
 import type { TDSnapshot } from '~types'
4
 import { styled } from '~styles'
4
 import { styled } from '~styles'
5
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
5
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
6
-import { DMItem, DMContent } from '~components/DropdownMenu'
7
-import { ToolButton } from '~components/ToolButton'
6
+import { DMItem, DMContent } from '~components/Primitives/DropdownMenu'
7
+import { ToolButton } from '~components/Primitives/ToolButton'
8
 import { preventEvent } from '~components/preventEvent'
8
 import { preventEvent } from '~components/preventEvent'
9
 
9
 
10
 const zoomSelector = (s: TDSnapshot) => s.document.pageStates[s.appState.currentPageId].camera.zoom
10
 const zoomSelector = (s: TDSnapshot) => s.document.pageStates[s.appState.currentPageId].camera.zoom

+ 1
- 0
packages/tldraw/src/components/TopPanel/ZoomMenu/index.ts 查看文件

1
+export * from './ZoomMenu'

+ 0
- 38
packages/tldraw/src/state/TLDR.ts 查看文件

735
     TLDR.updateParents(data, pageId, parentToUpdateIds)
735
     TLDR.updateParents(data, pageId, parentToUpdateIds)
736
   }
736
   }
737
 
737
 
738
-  static getSelectedStyle(data: TDSnapshot, pageId: string): ShapeStyles | false {
739
-    const { currentStyle } = data.appState
740
-
741
-    const page = data.document.pages[pageId]
742
-    const pageState = data.document.pageStates[pageId]
743
-
744
-    if (pageState.selectedIds.length === 0) {
745
-      return currentStyle
746
-    }
747
-
748
-    const shapeStyles = pageState.selectedIds.map((id) => page.shapes[id].style)
749
-
750
-    const commonStyle = {} as ShapeStyles
751
-
752
-    const overrides = new Set<string>([])
753
-
754
-    for (const shapeStyle of shapeStyles) {
755
-      const styles = Object.keys(currentStyle) as (keyof ShapeStyles)[]
756
-
757
-      styles.forEach((key) => {
758
-        if (overrides.has(key)) return
759
-        if (commonStyle[key] === undefined) {
760
-          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
761
-          // @ts-ignore
762
-          commonStyle[key] = shapeStyle[key]
763
-        } else {
764
-          if (commonStyle[key] === shapeStyle[key]) return
765
-          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
766
-          // @ts-ignore
767
-          commonStyle[key] = currentStyle[key]
768
-          overrides.add(key)
769
-        }
770
-      })
771
-    }
772
-
773
-    return commonStyle
774
-  }
775
-
776
   /* -------------------------------------------------- */
738
   /* -------------------------------------------------- */
777
   /*                      Bindings                      */
739
   /*                      Bindings                      */
778
   /* -------------------------------------------------- */
740
   /* -------------------------------------------------- */

+ 5
- 13
packages/tldraw/src/state/TldrawApp.ts 查看文件

247
    * @protected
247
    * @protected
248
    * @returns The final state
248
    * @returns The final state
249
    */
249
    */
250
-  protected cleanup = (state: TDSnapshot, prev: TDSnapshot): TDSnapshot => {
250
+  protected cleanup = (
251
+    state: TDSnapshot,
252
+    prev: TDSnapshot,
253
+    patch: Patch<TDSnapshot>
254
+  ): TDSnapshot => {
251
     const next = { ...state }
255
     const next = { ...state }
252
 
256
 
253
     // Remove deleted shapes and bindings (in Commands, these will be set to undefined)
257
     // Remove deleted shapes and bindings (in Commands, these will be set to undefined)
415
       }
419
       }
416
     }
420
     }
417
 
421
 
418
-    // Apply selected style change, if any
419
-
420
-    const newSelectedStyle = TLDR.getSelectedStyle(next, currentPageId)
421
-
422
-    if (newSelectedStyle) {
423
-      next.appState = {
424
-        ...next.appState,
425
-        selectedStyle: newSelectedStyle,
426
-      }
427
-    }
428
-
429
     // Temporary block on editing pages while in readonly mode.
422
     // Temporary block on editing pages while in readonly mode.
430
     // This is a broad solution but not a very good one: the UX
423
     // This is a broad solution but not a very good one: the UX
431
     // for interacting with a readOnly document will be more nuanced.
424
     // for interacting with a readOnly document will be more nuanced.
2855
       currentPageId: 'page',
2848
       currentPageId: 'page',
2856
       pages: [{ id: 'page', name: 'page', childIndex: 1 }],
2849
       pages: [{ id: 'page', name: 'page', childIndex: 1 }],
2857
       currentStyle: defaultStyle,
2850
       currentStyle: defaultStyle,
2858
-      selectedStyle: defaultStyle,
2859
       isToolLocked: false,
2851
       isToolLocked: false,
2860
       isStyleOpen: false,
2852
       isStyleOpen: false,
2861
       isEmptyCanvas: false,
2853
       isEmptyCanvas: false,

+ 0
- 1
packages/tldraw/src/types.ts 查看文件

92
     showCloneHandles: boolean
92
     showCloneHandles: boolean
93
   }
93
   }
94
   appState: {
94
   appState: {
95
-    selectedStyle: ShapeStyles
96
     currentStyle: ShapeStyles
95
     currentStyle: ShapeStyles
97
     currentPageId: string
96
     currentPageId: string
98
     pages: Pick<TLPage<TDShape, TDBinding>, 'id' | 'name' | 'childIndex'>[]
97
     pages: Pick<TLPage<TDShape, TDBinding>, 'id' | 'name' | 'childIndex'>[]

正在加载...
取消
保存