Browse Source

[mega-chore] renaming (#223)

* Rename shape utils

* renames files

* Add husky

* Delete .babelrc

* Update TLDR.ts

* renames commands

* Update package.json

* more pre-commit work
main
Steve Ruiz 3 years ago
parent
commit
e11f05028f
No account linked to committer's email address
100 changed files with 153 additions and 285 deletions
  1. 4
    0
      .husky/pre-commit
  2. 15
    1
      package.json
  3. 5
    5
      packages/tldraw/src/TLDraw.tsx
  4. BIN
      packages/tldraw/src/assets/VerveineRegular.woff
  5. 1
    1
      packages/tldraw/src/components/ContextMenu/ContextMenu.tsx
  6. 1
    1
      packages/tldraw/src/components/Divider/Divider.tsx
  7. 1
    1
      packages/tldraw/src/components/DropdownMenu/DMArrow.tsx
  8. 1
    1
      packages/tldraw/src/components/DropdownMenu/DMContent.tsx
  9. 1
    1
      packages/tldraw/src/components/DropdownMenu/DMDivider.tsx
  10. 0
    23
      packages/tldraw/src/components/DropdownMenu/DMIconButton.tsx
  11. 1
    1
      packages/tldraw/src/components/DropdownMenu/DMRadioItem.tsx
  12. 0
    1
      packages/tldraw/src/components/DropdownMenu/index.tsx
  13. 1
    1
      packages/tldraw/src/components/FocusButton/FocusButton.tsx
  14. 1
    1
      packages/tldraw/src/components/IconButton/IconButton.tsx
  15. 1
    1
      packages/tldraw/src/components/Kbd/Kbd.tsx
  16. 1
    1
      packages/tldraw/src/components/MenuContent/MenuContent.ts
  17. 1
    1
      packages/tldraw/src/components/Panel/Panel.tsx
  18. 1
    1
      packages/tldraw/src/components/RowButton/RowButton.tsx
  19. 1
    1
      packages/tldraw/src/components/SmallIcon/SmallIcon.tsx
  20. 1
    1
      packages/tldraw/src/components/ToolButton/ToolButton.tsx
  21. 1
    1
      packages/tldraw/src/components/ToolsPanel/ActionButton.tsx
  22. 1
    1
      packages/tldraw/src/components/ToolsPanel/BackToContent.tsx
  23. 1
    1
      packages/tldraw/src/components/ToolsPanel/StatusBar.tsx
  24. 1
    1
      packages/tldraw/src/components/ToolsPanel/ToolsPanel.tsx
  25. 1
    1
      packages/tldraw/src/components/Tooltip/Tooltip.tsx
  26. 6
    6
      packages/tldraw/src/components/TopPanel/ColorMenu.tsx
  27. 1
    1
      packages/tldraw/src/components/TopPanel/PageMenu.tsx
  28. 1
    1
      packages/tldraw/src/components/TopPanel/PageOptionsDialog.tsx
  29. 1
    1
      packages/tldraw/src/components/TopPanel/TopPanel.tsx
  30. 1
    1
      packages/tldraw/src/components/TopPanel/ZoomMenu.tsx
  31. 0
    20
      packages/tldraw/src/components/icons/CheckIcon.tsx
  32. 1
    1
      packages/tldraw/src/components/icons/CircleIcon.tsx
  33. 0
    1
      packages/tldraw/src/components/icons/index.ts
  34. 1
    1
      packages/tldraw/src/hooks/index.ts
  35. 0
    9
      packages/tldraw/src/hooks/useCustomFonts.ts
  36. 0
    30
      packages/tldraw/src/hooks/useStyle.ts
  37. 25
    0
      packages/tldraw/src/hooks/useStylesheet.ts
  38. 0
    1
      packages/tldraw/src/hooks/useTheme.ts
  39. 1
    1
      packages/tldraw/src/index.ts
  40. 0
    1
      packages/tldraw/src/shape-utils/arrow/index.ts
  41. 0
    1
      packages/tldraw/src/shape-utils/draw/index.ts
  42. 0
    1
      packages/tldraw/src/shape-utils/ellipse/index.ts
  43. 0
    1
      packages/tldraw/src/shape-utils/group/index.ts
  44. 0
    50
      packages/tldraw/src/shape-utils/index.ts
  45. 0
    1
      packages/tldraw/src/shape-utils/rectangle/index.ts
  46. 0
    1
      packages/tldraw/src/shape-utils/sticky/index.ts
  47. 0
    1
      packages/tldraw/src/shape-utils/text/index.ts
  48. 2
    1
      packages/tldraw/src/state/TLDR.ts
  49. 10
    10
      packages/tldraw/src/state/TLDrawState.spec.ts
  50. 40
    34
      packages/tldraw/src/state/TLDrawState.ts
  51. 0
    0
      packages/tldraw/src/state/__snapshots__/TLDrawState.spec.ts.snap
  52. 0
    1
      packages/tldraw/src/state/command/align/index.ts
  53. 0
    1
      packages/tldraw/src/state/command/change-page/index.ts
  54. 0
    1
      packages/tldraw/src/state/command/create-page/index.ts
  55. 0
    1
      packages/tldraw/src/state/command/create/index.ts
  56. 0
    1
      packages/tldraw/src/state/command/delete-page/index.ts
  57. 0
    1
      packages/tldraw/src/state/command/delete/index.ts
  58. 0
    1
      packages/tldraw/src/state/command/distribute/index.ts
  59. 0
    1
      packages/tldraw/src/state/command/duplicate-page/index.ts
  60. 0
    1
      packages/tldraw/src/state/command/duplicate/index.ts
  61. 0
    1
      packages/tldraw/src/state/command/flip/index.ts
  62. 0
    1
      packages/tldraw/src/state/command/group/index.ts
  63. 0
    23
      packages/tldraw/src/state/command/index.ts
  64. 0
    1
      packages/tldraw/src/state/command/move-to-page/index.ts
  65. 0
    1
      packages/tldraw/src/state/command/move/index.ts
  66. 0
    1
      packages/tldraw/src/state/command/rename-page/index.ts
  67. 0
    1
      packages/tldraw/src/state/command/reset-bounds/index.ts
  68. 0
    1
      packages/tldraw/src/state/command/rotate/index.ts
  69. 0
    1
      packages/tldraw/src/state/command/stretch/index.ts
  70. 0
    1
      packages/tldraw/src/state/command/style/index.ts
  71. 0
    1
      packages/tldraw/src/state/command/toggle-decoration/index.ts
  72. 0
    1
      packages/tldraw/src/state/command/toggle/index.ts
  73. 0
    1
      packages/tldraw/src/state/command/translate/index.ts
  74. 0
    1
      packages/tldraw/src/state/command/ungroup/index.ts
  75. 0
    1
      packages/tldraw/src/state/command/update/index.ts
  76. 2
    2
      packages/tldraw/src/state/commands/alignShapes/alignShapes.spec.ts
  77. 2
    2
      packages/tldraw/src/state/commands/alignShapes/alignShapes.ts
  78. 1
    0
      packages/tldraw/src/state/commands/alignShapes/index.ts
  79. 0
    0
      packages/tldraw/src/state/commands/changePage/changePage.spec.ts
  80. 0
    0
      packages/tldraw/src/state/commands/changePage/changePage.ts
  81. 1
    0
      packages/tldraw/src/state/commands/changePage/index.ts
  82. 0
    0
      packages/tldraw/src/state/commands/createPage/createPage.spec.ts
  83. 0
    0
      packages/tldraw/src/state/commands/createPage/createPage.ts
  84. 1
    0
      packages/tldraw/src/state/commands/createPage/index.ts
  85. 0
    0
      packages/tldraw/src/state/commands/createShapes/createShapes.spec.ts
  86. 2
    2
      packages/tldraw/src/state/commands/createShapes/createShapes.ts
  87. 1
    0
      packages/tldraw/src/state/commands/createShapes/index.ts
  88. 0
    0
      packages/tldraw/src/state/commands/deletePage/deletePage.spec.ts
  89. 0
    0
      packages/tldraw/src/state/commands/deletePage/deletePage.ts
  90. 1
    0
      packages/tldraw/src/state/commands/deletePage/index.ts
  91. 0
    0
      packages/tldraw/src/state/commands/deleteShapes/deleteShapes.spec.ts
  92. 2
    4
      packages/tldraw/src/state/commands/deleteShapes/deleteShapes.ts
  93. 1
    0
      packages/tldraw/src/state/commands/deleteShapes/index.ts
  94. 2
    2
      packages/tldraw/src/state/commands/distributeShapes/distributeShapes.spec.ts
  95. 2
    2
      packages/tldraw/src/state/commands/distributeShapes/distributeShapes.ts
  96. 1
    0
      packages/tldraw/src/state/commands/distributeShapes/index.ts
  97. 0
    0
      packages/tldraw/src/state/commands/duplicatePage/duplicatePage.spec.ts
  98. 0
    0
      packages/tldraw/src/state/commands/duplicatePage/duplicatePage.ts
  99. 1
    0
      packages/tldraw/src/state/commands/duplicatePage/index.ts
  100. 0
    0
      packages/tldraw/src/state/commands/duplicateShapes/duplicateShapes.spec.ts

+ 4
- 0
.husky/pre-commit View File

1
+#!/bin/sh
2
+. "$(dirname "$0")/_/husky.sh"
3
+
4
+yarn test

+ 15
- 1
package.json View File

23
     "build:packages": "cd packages/tldraw && yarn build",
23
     "build:packages": "cd packages/tldraw && yarn build",
24
     "publish:patch": "yarn test && yarn build:packages && lerna publish patch",
24
     "publish:patch": "yarn test && yarn build:packages && lerna publish patch",
25
     "docs": "lerna run docs",
25
     "docs": "lerna run docs",
26
-    "docs:watch": "lerna run docs:watch"
26
+    "docs:watch": "lerna run docs:watch",
27
+    "postinstall": "husky install",
28
+    "fix:style": "yarn run prettier ./packages/tldraw/src --write"
27
   },
29
   },
28
   "devDependencies": {
30
   "devDependencies": {
29
     "@swc-node/jest": "^1.3.3",
31
     "@swc-node/jest": "^1.3.3",
37
     "@typescript-eslint/parser": "^4.19.0",
39
     "@typescript-eslint/parser": "^4.19.0",
38
     "eslint": "^7.32.0",
40
     "eslint": "^7.32.0",
39
     "fake-indexeddb": "^3.1.3",
41
     "fake-indexeddb": "^3.1.3",
42
+    "husky": "^7.0.4",
40
     "init-package-json": "^2.0.4",
43
     "init-package-json": "^2.0.4",
41
     "jest": "^27.3.1",
44
     "jest": "^27.3.1",
42
     "lerna": "^3.22.1",
45
     "lerna": "^3.22.1",
46
+    "lint-staged": "^11.2.6",
47
+    "prettier": "^2.4.1",
43
     "resize-observer-polyfill": "^1.5.1",
48
     "resize-observer-polyfill": "^1.5.1",
44
     "tslib": "^2.3.0",
49
     "tslib": "^2.3.0",
45
     "typedoc": "^0.22.3",
50
     "typedoc": "^0.22.3",
51
     "semi": false,
56
     "semi": false,
52
     "printWidth": 100
57
     "printWidth": 100
53
   },
58
   },
59
+  "husky": {
60
+    "hooks": {
61
+      "pre-commit": "lint-staged",
62
+      "pre-push": "test && lint-staged"
63
+    }
64
+  },
65
+  "lint-staged": {
66
+    "*": "fix:style && eslint"
67
+  },
54
   "jest": {
68
   "jest": {
55
     "setupFilesAfterEnv": [
69
     "setupFilesAfterEnv": [
56
       "<rootDir>/setupTests.ts"
70
       "<rootDir>/setupTests.ts"

+ 5
- 5
packages/tldraw/src/TLDraw.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { IdProvider } from '@radix-ui/react-id'
2
 import { IdProvider } from '@radix-ui/react-id'
3
 import { Renderer } from '@tldraw/core'
3
 import { Renderer } from '@tldraw/core'
4
-import styled, { dark } from '~styles'
4
+import { styled, dark } from '~styles'
5
 import { Data, TLDrawDocument, TLDrawStatus, TLDrawUser } from '~types'
5
 import { Data, TLDrawDocument, TLDrawStatus, TLDrawUser } from '~types'
6
 import { TLDrawState } from '~state'
6
 import { TLDrawState } from '~state'
7
 import {
7
 import {
8
   TLDrawContext,
8
   TLDrawContext,
9
   TLDrawContextType,
9
   TLDrawContextType,
10
-  useCustomFonts,
10
+  useStylesheet,
11
   useKeyboardShortcuts,
11
   useKeyboardShortcuts,
12
   useTLDrawContext,
12
   useTLDrawContext,
13
 } from '~hooks'
13
 } from '~hooks'
14
-import { shapeUtils } from '~shape-utils'
14
+import { shapeUtils } from '~state/shapes'
15
 import { ToolsPanel } from '~components/ToolsPanel'
15
 import { ToolsPanel } from '~components/ToolsPanel'
16
 import { TopPanel } from '~components/TopPanel'
16
 import { TopPanel } from '~components/TopPanel'
17
-import { TLDR } from '~state/tldr'
17
+import { TLDR } from '~state/TLDR'
18
 import { ContextMenu } from '~components/ContextMenu'
18
 import { ContextMenu } from '~components/ContextMenu'
19
 import { FocusButton } from '~components/FocusButton/FocusButton'
19
 import { FocusButton } from '~components/FocusButton/FocusButton'
20
 
20
 
430
     focusableRef: React.RefObject<HTMLDivElement>
430
     focusableRef: React.RefObject<HTMLDivElement>
431
   }) => {
431
   }) => {
432
     useKeyboardShortcuts(focusableRef)
432
     useKeyboardShortcuts(focusableRef)
433
-    useCustomFonts()
433
+    useStylesheet()
434
 
434
 
435
     React.useEffect(() => {
435
     React.useEffect(() => {
436
       if (autofocus) {
436
       if (autofocus) {

BIN
packages/tldraw/src/assets/VerveineRegular.woff View File


+ 1
- 1
packages/tldraw/src/components/ContextMenu/ContextMenu.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import styled from '~styles'
2
+import { styled } from '~styles'
3
 import * as RadixContextMenu from '@radix-ui/react-context-menu'
3
 import * as RadixContextMenu from '@radix-ui/react-context-menu'
4
 import { useTLDrawContext } from '~hooks'
4
 import { useTLDrawContext } from '~hooks'
5
 import { Data, AlignType, DistributeType, StretchType } from '~types'
5
 import { Data, AlignType, DistributeType, StretchType } from '~types'

+ 1
- 1
packages/tldraw/src/components/Divider/Divider.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import styled from '~styles'
2
+import { styled } from '~styles'
3
 
3
 
4
 export const Divider = styled('hr', {
4
 export const Divider = styled('hr', {
5
   height: 1,
5
   height: 1,

+ 1
- 1
packages/tldraw/src/components/DropdownMenu/DMArrow.tsx View File

1
 import { Arrow } from '@radix-ui/react-dropdown-menu'
1
 import { Arrow } from '@radix-ui/react-dropdown-menu'
2
 import { breakpoints } from '~components/breakpoints'
2
 import { breakpoints } from '~components/breakpoints'
3
-import styled from '~styles/stitches.config'
3
+import { styled } from '~styles/stitches.config'
4
 
4
 
5
 export const DMArrow = styled(Arrow, { fill: '$panel', bp: breakpoints })
5
 export const DMArrow = styled(Arrow, { fill: '$panel', bp: breakpoints })

+ 1
- 1
packages/tldraw/src/components/DropdownMenu/DMContent.tsx View File

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/MenuContent'
5
 
5
 
6
 export interface DMContentProps {
6
 export interface DMContentProps {

+ 1
- 1
packages/tldraw/src/components/DropdownMenu/DMDivider.tsx View File

1
 import { Separator } from '@radix-ui/react-dropdown-menu'
1
 import { Separator } from '@radix-ui/react-dropdown-menu'
2
-import styled from '~styles/stitches.config'
2
+import { styled } from '~styles/stitches.config'
3
 
3
 
4
 export const DMDivider = styled(Separator, {
4
 export const DMDivider = styled(Separator, {
5
   backgroundColor: '$hover',
5
   backgroundColor: '$hover',

+ 0
- 23
packages/tldraw/src/components/DropdownMenu/DMIconButton.tsx View File

1
-import * as React from 'react'
2
-import { Item } from '@radix-ui/react-dropdown-menu'
3
-import { IconButton } from '~components/IconButton/IconButton'
4
-
5
-interface DMIconButtonProps {
6
-  onSelect: () => void
7
-  disabled?: boolean
8
-  children: React.ReactNode
9
-}
10
-
11
-export function DMIconButton({
12
-  onSelect,
13
-  children,
14
-  disabled = false,
15
-}: DMIconButtonProps): JSX.Element {
16
-  return (
17
-    <Item dir="ltr" asChild>
18
-      <IconButton disabled={disabled} onSelect={onSelect}>
19
-        {children}
20
-      </IconButton>
21
-    </Item>
22
-  )
23
-}

+ 1
- 1
packages/tldraw/src/components/DropdownMenu/DMRadioItem.tsx View File

1
 import { RadioItem } from '@radix-ui/react-dropdown-menu'
1
 import { RadioItem } from '@radix-ui/react-dropdown-menu'
2
-import styled from '~styles/stitches.config'
2
+import { styled } from '~styles/stitches.config'
3
 
3
 
4
 export const DMRadioItem = styled(RadioItem, {
4
 export const DMRadioItem = styled(RadioItem, {
5
   height: '32px',
5
   height: '32px',

+ 0
- 1
packages/tldraw/src/components/DropdownMenu/index.tsx View File

3
 export * from './DMCheckboxItem'
3
 export * from './DMCheckboxItem'
4
 export * from './DMContent'
4
 export * from './DMContent'
5
 export * from './DMDivider'
5
 export * from './DMDivider'
6
-export * from './DMIconButton'
7
 export * from './DMRadioItem'
6
 export * from './DMRadioItem'
8
 export * from './DMSubMenu'
7
 export * from './DMSubMenu'
9
 export * from './DMTriggerIcon'
8
 export * from './DMTriggerIcon'

+ 1
- 1
packages/tldraw/src/components/FocusButton/FocusButton.tsx View File

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/IconButton/IconButton'
4
-import styled from '~styles'
4
+import { styled } from '~styles'
5
 
5
 
6
 interface FocusButtonProps {
6
 interface FocusButtonProps {
7
   onSelect: () => void
7
   onSelect: () => void

+ 1
- 1
packages/tldraw/src/components/IconButton/IconButton.tsx View File

1
-import styled from '~styles'
1
+import { styled } from '~styles'
2
 
2
 
3
 export const IconButton = styled('button', {
3
 export const IconButton = styled('button', {
4
   position: 'relative',
4
   position: 'relative',

+ 1
- 1
packages/tldraw/src/components/Kbd/Kbd.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import styled from '~styles'
2
+import { styled } from '~styles'
3
 import { Utils } from '@tldraw/core'
3
 import { Utils } from '@tldraw/core'
4
 
4
 
5
 /* -------------------------------------------------- */
5
 /* -------------------------------------------------- */

+ 1
- 1
packages/tldraw/src/components/MenuContent/MenuContent.ts View File

1
-import styled from '~styles'
1
+import { styled } from '~styles'
2
 
2
 
3
 export const MenuContent = styled('div', {
3
 export const MenuContent = styled('div', {
4
   position: 'relative',
4
   position: 'relative',

+ 1
- 1
packages/tldraw/src/components/Panel/Panel.tsx View File

1
-import styled from '~styles/stitches.config'
1
+import { styled } from '~styles/stitches.config'
2
 
2
 
3
 export const Panel = styled('div', {
3
 export const Panel = styled('div', {
4
   backgroundColor: '$panel',
4
   backgroundColor: '$panel',

+ 1
- 1
packages/tldraw/src/components/RowButton/RowButton.tsx View File

4
 import { breakpoints } from '~components/breakpoints'
4
 import { breakpoints } from '~components/breakpoints'
5
 import { Kbd } from '~components/Kbd'
5
 import { Kbd } from '~components/Kbd'
6
 import { SmallIcon } from '~components/SmallIcon'
6
 import { SmallIcon } from '~components/SmallIcon'
7
-import styled from '~styles'
7
+import { styled } from '~styles'
8
 
8
 
9
 export interface RowButtonProps {
9
 export interface RowButtonProps {
10
   onSelect?: () => void
10
   onSelect?: () => void

+ 1
- 1
packages/tldraw/src/components/SmallIcon/SmallIcon.tsx View File

1
-import styled from '~styles'
1
+import { styled } from '~styles'
2
 
2
 
3
 export const SmallIcon = styled('div', {
3
 export const SmallIcon = styled('div', {
4
   height: '100%',
4
   height: '100%',

+ 1
- 1
packages/tldraw/src/components/ToolButton/ToolButton.tsx View File

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/Tooltip'
4
-import styled from '~styles'
4
+import { styled } from '~styles'
5
 
5
 
6
 export interface ToolButtonProps {
6
 export interface ToolButtonProps {
7
   onClick?: () => void
7
   onClick?: () => void

+ 1
- 1
packages/tldraw/src/components/ToolsPanel/ActionButton.tsx View File

2
 import { Tooltip } from '~components/Tooltip/Tooltip'
2
 import { Tooltip } from '~components/Tooltip/Tooltip'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
3
 import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4
 import { useTLDrawContext } from '~hooks'
4
 import { useTLDrawContext } from '~hooks'
5
-import styled from '~styles'
5
+import { styled } from '~styles'
6
 import { AlignType, Data, DistributeType, StretchType } from '~types'
6
 import { AlignType, Data, DistributeType, StretchType } from '~types'
7
 import {
7
 import {
8
   ArrowDownIcon,
8
   ArrowDownIcon,

+ 1
- 1
packages/tldraw/src/components/ToolsPanel/BackToContent.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import styled from '~styles'
2
+import { styled } from '~styles'
3
 import type { Data } from '~types'
3
 import type { Data } from '~types'
4
 import { useTLDrawContext } from '~hooks'
4
 import { useTLDrawContext } from '~hooks'
5
 import { RowButton } from '~components/RowButton'
5
 import { RowButton } from '~components/RowButton'

+ 1
- 1
packages/tldraw/src/components/ToolsPanel/StatusBar.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { useTLDrawContext } from '~hooks'
2
 import { useTLDrawContext } from '~hooks'
3
 import type { Data } from '~types'
3
 import type { Data } from '~types'
4
-import styled from '~styles'
4
+import { styled } from '~styles'
5
 import { breakpoints } from '~components/breakpoints'
5
 import { breakpoints } from '~components/breakpoints'
6
 
6
 
7
 const statusSelector = (s: Data) => s.appState.status
7
 const statusSelector = (s: Data) => s.appState.status

+ 1
- 1
packages/tldraw/src/components/ToolsPanel/ToolsPanel.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import styled from '~styles'
2
+import { styled } from '~styles'
3
 import type { Data } from '~types'
3
 import type { Data } from '~types'
4
 import { useTLDrawContext } from '~hooks'
4
 import { useTLDrawContext } from '~hooks'
5
 import { StatusBar } from './StatusBar'
5
 import { StatusBar } from './StatusBar'

+ 1
- 1
packages/tldraw/src/components/Tooltip/Tooltip.tsx View File

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/Kbd'
4
-import styled from '~styles'
4
+import { styled } from '~styles'
5
 
5
 
6
 /* -------------------------------------------------- */
6
 /* -------------------------------------------------- */
7
 /*                       Tooltip                      */
7
 /*                       Tooltip                      */

+ 6
- 6
packages/tldraw/src/components/TopPanel/ColorMenu.tsx View File

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 } from '~shape-utils'
4
-import { useTheme, useTLDrawContext } from '~hooks'
5
-import type { Data, ColorStyle } from '~types'
6
-import CircleIcon from '~components/icons/CircleIcon'
3
+import { strokes } from '~state/shapes/shape-styles'
4
+import { useTLDrawContext } from '~hooks'
7
 import { DMContent, DMTriggerIcon } from '~components/DropdownMenu'
5
 import { DMContent, DMTriggerIcon } from '~components/DropdownMenu'
8
-import { BoxIcon } from '~components/icons'
6
+import { BoxIcon, CircleIcon } from '~components/icons'
9
 import { ToolButton } from '~components/ToolButton'
7
 import { ToolButton } from '~components/ToolButton'
8
+import type { Data, ColorStyle } from '~types'
10
 
9
 
11
 const selectColor = (s: Data) => s.appState.selectedStyle.color
10
 const selectColor = (s: Data) => s.appState.selectedStyle.color
12
 const preventEvent = (e: Event) => e.preventDefault()
11
 const preventEvent = (e: Event) => e.preventDefault()
12
+const themeSelector = (data: Data) => (data.settings.isDarkMode ? 'dark' : 'light')
13
 
13
 
14
 export const ColorMenu = React.memo((): JSX.Element => {
14
 export const ColorMenu = React.memo((): JSX.Element => {
15
-  const { theme } = useTheme()
16
   const { tlstate, useSelector } = useTLDrawContext()
15
   const { tlstate, useSelector } = useTLDrawContext()
17
 
16
 
17
+  const theme = useSelector(themeSelector)
18
   const color = useSelector(selectColor)
18
   const color = useSelector(selectColor)
19
 
19
 
20
   return (
20
   return (

+ 1
- 1
packages/tldraw/src/components/TopPanel/PageMenu.tsx View File

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 { useTLDrawContext } from '~hooks'
6
 import { useTLDrawContext } from '~hooks'
7
 import type { Data } from '~types'
7
 import type { Data } from '~types'
8
 import { DMContent, DMDivider } from '~components/DropdownMenu'
8
 import { DMContent, DMDivider } from '~components/DropdownMenu'

+ 1
- 1
packages/tldraw/src/components/TopPanel/PageOptionsDialog.tsx View File

4
 import type { Data, TLDrawPage } from '~types'
4
 import type { Data, TLDrawPage } from '~types'
5
 import { useTLDrawContext } from '~hooks'
5
 import { useTLDrawContext } from '~hooks'
6
 import { RowButton, RowButtonProps } from '~components/RowButton'
6
 import { RowButton, RowButtonProps } from '~components/RowButton'
7
-import styled from '~styles'
7
+import { styled } from '~styles'
8
 import { Divider } from '~components/Divider'
8
 import { Divider } from '~components/Divider'
9
 import { IconButton } from '~components/IconButton/IconButton'
9
 import { IconButton } from '~components/IconButton/IconButton'
10
 import { SmallIcon } from '~components/SmallIcon'
10
 import { SmallIcon } from '~components/SmallIcon'

+ 1
- 1
packages/tldraw/src/components/TopPanel/TopPanel.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { Menu } from './Menu'
2
 import { Menu } from './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 { DashMenu } from './DashMenu'
6
 import { DashMenu } from './DashMenu'

+ 1
- 1
packages/tldraw/src/components/TopPanel/ZoomMenu.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { useTLDrawContext } from '~hooks'
2
 import { useTLDrawContext } from '~hooks'
3
 import type { Data } from '~types'
3
 import type { Data } 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'
6
 import { DMItem, DMContent } from '~components/DropdownMenu'
7
 import { ToolButton } from '~components/ToolButton'
7
 import { ToolButton } from '~components/ToolButton'

+ 0
- 20
packages/tldraw/src/components/icons/CheckIcon.tsx View File

1
-import * as React from 'react'
2
-
3
-function CheckIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element {
4
-  return (
5
-    <svg viewBox="0 0 15 15" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}>
6
-      <path
7
-        d="M1.06555 6.39147C1.06555 6.39147 1.18669 6.37676 1.32187 6.60547C1.41196 6.75789 1.43336 6.79297 1.54896 6.97656C1.67649 7.1791 1.90215 7.46571 1.98273 7.55604C1.89684 7.45413 2.06332 7.64638 1.98273 7.55604C2.06863 7.65796 2.15476 7.76164 2.24114 7.86709C2.32752 7.97255 2.43047 8.09537 2.54999 8.23556C2.66951 8.37575 2.82609 8.54986 3.01971 8.75788C3.21333 8.96589 3.41752 9.17647 3.63228 9.38961C3.43268 9.19463 3.84705 9.60274 3.63228 9.38961C3.83189 9.58458 3.98492 9.65483 3.97262 9.74102C4.18567 9.85603 3.96031 9.82721 3.97262 9.74102C3.91266 9.99944 3.75956 9.626 3.97262 9.74102C4.03257 9.4826 4.10858 9.33351 4.21165 9.13551C4.31473 8.93751 4.42218 8.73459 4.534 8.52675C4.64583 8.31892 4.76102 8.10882 4.87957 7.89646C4.99812 7.68411 5.13449 7.4489 5.28871 7.19083C5.44292 6.93276 5.63515 6.62674 5.86541 6.27278C6.09567 5.91882 6.34391 5.55345 6.61015 5.17668C6.87639 4.7999 7.15756 4.4262 7.45365 4.05557C7.74975 3.68495 8.06403 3.32626 8.39649 2.97952C8.72895 2.63277 9.04339 2.32894 9.33982 2.06804C9.63624 1.80713 9.87576 1.60935 10.0584 1.4747C10.241 1.34004 10.4399 1.20541 10.655 1.07079C10.8702 0.936165 10.9439 0.993562 10.8761 1.24297C10.8084 1.49239 10.7342 1.72411 10.6535 1.93813C10.5728 2.15215 10.452 2.43667 10.291 2.79168C10.13 3.14669 9.94264 3.53252 9.7288 3.94917C9.51497 4.36582 9.29528 4.77352 9.06973 5.17228C8.84418 5.57104 8.62072 5.96246 8.39936 6.34654C8.178 6.73061 7.9685 7.0987 7.77088 7.45081C7.57326 7.80292 7.40426 8.10581 7.26389 8.35948C7.12353 8.61314 6.99519 8.84594 6.87889 9.05785C6.76259 9.26977 6.64515 9.48087 6.52659 9.69115C6.40803 9.90143 6.25752 10.1532 6.07507 10.4466C5.89262 10.7399 5.72254 11.0063 5.56483 11.2458C5.40712 11.4852 5.23545 11.6777 5.04981 11.8232C4.86416 11.9686 4.59686 12.0243 4.2479 11.9903C3.89894 11.9563 3.61525 11.8614 3.39684 11.7055C3.17844 11.5497 2.99758 11.3507 2.85427 11.1085C2.71096 10.8663 2.56178 10.5997 2.40673 10.3088C2.25167 10.0179 2.11187 9.72784 1.98731 9.4386C1.86275 9.14937 1.76835 8.91301 1.70411 8.72952C1.63988 8.54604 1.58816 8.38956 1.54896 8.26008C1.50977 8.13061 1.47123 8.0037 1.43336 7.87934C1.39549 7.75498 1.35833 7.63676 1.32187 7.52466C1.28541 7.41257 1.24607 7.2993 1.20384 7.18486C1.16161 7.07041 1.21291 7.20988 1.06555 6.85296C0.918183 6.49603 1.06555 6.39147 1.06555 6.39147Z"
8
-        fill="currentColor"
9
-      />
10
-      <path
11
-        d="M1.98273 7.55604C1.90215 7.46571 1.67649 7.1791 1.54896 6.97656C1.43336 6.79297 1.41196 6.75789 1.32187 6.60547C1.18669 6.37676 1.06555 6.39147 1.06555 6.39147C1.06555 6.39147 0.918183 6.49603 1.06555 6.85296C1.21291 7.20988 1.16161 7.07041 1.20384 7.18486C1.24607 7.2993 1.28541 7.41257 1.32187 7.52466C1.35833 7.63676 1.39549 7.75498 1.43336 7.87934C1.47123 8.0037 1.50977 8.13061 1.54896 8.26008C1.58816 8.38956 1.63988 8.54604 1.70411 8.72952C1.76835 8.91301 1.86275 9.14937 1.98731 9.4386C2.11187 9.72784 2.25167 10.0179 2.40673 10.3088C2.56178 10.5997 2.71096 10.8663 2.85427 11.1085C2.99758 11.3507 3.17844 11.5497 3.39684 11.7055C3.61525 11.8614 3.89894 11.9563 4.2479 11.9903C4.59686 12.0243 4.86416 11.9686 5.04981 11.8232C5.23545 11.6777 5.40712 11.4852 5.56483 11.2458C5.72254 11.0063 5.89262 10.7399 6.07507 10.4466C6.25752 10.1532 6.40803 9.90143 6.52659 9.69115C6.64515 9.48087 6.76259 9.26977 6.87889 9.05785C6.99519 8.84594 7.12353 8.61314 7.26389 8.35948C7.40426 8.10581 7.57326 7.80292 7.77088 7.45081C7.9685 7.0987 8.178 6.73061 8.39936 6.34654C8.62072 5.96246 8.84418 5.57104 9.06973 5.17228C9.29528 4.77352 9.51497 4.36582 9.7288 3.94917C9.94264 3.53252 10.13 3.14669 10.291 2.79168C10.452 2.43667 10.5728 2.15215 10.6535 1.93813C10.7342 1.72411 10.8084 1.49239 10.8761 1.24297C10.9439 0.993562 10.8702 0.936165 10.655 1.07079C10.4399 1.20541 10.241 1.34004 10.0584 1.4747C9.87576 1.60935 9.63624 1.80713 9.33982 2.06804C9.04339 2.32894 8.72895 2.63277 8.39649 2.97952C8.06403 3.32626 7.74975 3.68495 7.45365 4.05557C7.15756 4.4262 6.87639 4.7999 6.61015 5.17668C6.34391 5.55345 6.09567 5.91882 5.86541 6.27278C5.63515 6.62674 5.44292 6.93276 5.28871 7.19083C5.13449 7.4489 4.99812 7.68411 4.87957 7.89646C4.76102 8.10882 4.64583 8.31892 4.534 8.52675C4.42218 8.73459 4.31473 8.93751 4.21165 9.13551C4.10858 9.33351 4.03257 9.4826 3.97262 9.74102M1.98273 7.55604C2.06332 7.64638 1.89684 7.45413 1.98273 7.55604ZM1.98273 7.55604C2.06863 7.65796 2.15476 7.76164 2.24114 7.86709C2.32752 7.97255 2.43047 8.09537 2.54999 8.23556C2.66951 8.37575 2.82609 8.54986 3.01971 8.75788C3.21333 8.96589 3.41752 9.17647 3.63228 9.38961M3.63228 9.38961C3.84705 9.60274 3.43268 9.19463 3.63228 9.38961ZM3.63228 9.38961C3.83189 9.58458 3.98492 9.65483 3.97262 9.74102M3.97262 9.74102C3.96031 9.82721 4.18567 9.85603 3.97262 9.74102ZM3.97262 9.74102C3.75956 9.626 3.91266 9.99944 3.97262 9.74102Z"
12
-        stroke="currentColor"
13
-        strokeLinecap="round"
14
-        strokeLinejoin="round"
15
-      />
16
-    </svg>
17
-  )
18
-}
19
-
20
-export default CheckIcon

+ 1
- 1
packages/tldraw/src/components/icons/CircleIcon.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 
2
 
3
-export default function CircleIcon(
3
+export function CircleIcon(
4
   props: Pick<React.SVGProps<SVGSVGElement>, 'stroke' | 'fill'> & {
4
   props: Pick<React.SVGProps<SVGSVGElement>, 'stroke' | 'fill'> & {
5
     size: number
5
     size: number
6
   }
6
   }

+ 0
- 1
packages/tldraw/src/components/icons/index.ts View File

1
 export * from './BoxIcon'
1
 export * from './BoxIcon'
2
-export * from './CheckIcon'
3
 export * from './CircleIcon'
2
 export * from './CircleIcon'
4
 export * from './DashDashedIcon'
3
 export * from './DashDashedIcon'
5
 export * from './DashDottedIcon'
4
 export * from './DashDottedIcon'

+ 1
- 1
packages/tldraw/src/hooks/index.ts View File

1
 export * from './useKeyboardShortcuts'
1
 export * from './useKeyboardShortcuts'
2
 export * from './useTLDrawContext'
2
 export * from './useTLDrawContext'
3
 export * from './useTheme'
3
 export * from './useTheme'
4
-export * from './useCustomFonts'
4
+export * from './useStylesheet'
5
 export * from './useFileSystemHandlers'
5
 export * from './useFileSystemHandlers'
6
 export * from './useFileSystem'
6
 export * from './useFileSystem'

+ 0
- 9
packages/tldraw/src/hooks/useCustomFonts.ts View File

1
-import { useStyle, css } from '~hooks/useStyle'
2
-
3
-const customFonts = css`
4
-  @import url('https://fonts.googleapis.com/css2?family=Caveat+Brush&display=swap');
5
-`
6
-
7
-export function useCustomFonts() {
8
-  useStyle('tldraw-fonts', customFonts)
9
-}

+ 0
- 30
packages/tldraw/src/hooks/useStyle.ts View File

1
-import * as React from 'react'
2
-
3
-const styles = new Map<string, HTMLStyleElement>()
4
-
5
-export const css = (strings: TemplateStringsArray, ...args: unknown[]) =>
6
-  strings.reduce(
7
-    (acc, string, index) => acc + string + (index < args.length ? args[index] : ''),
8
-    ''
9
-  )
10
-
11
-export function useStyle(uid: string, rules: string) {
12
-  React.useLayoutEffect(() => {
13
-    if (styles.get(uid)) {
14
-      return () => void null
15
-    }
16
-
17
-    const style = document.createElement('style')
18
-    style.innerHTML = rules
19
-    style.setAttribute('id', uid)
20
-    document.head.appendChild(style)
21
-    styles.set(uid, style)
22
-
23
-    return () => {
24
-      if (style && document.head.contains(style)) {
25
-        document.head.removeChild(style)
26
-        styles.delete(uid)
27
-      }
28
-    }
29
-  }, [uid, rules])
30
-}

+ 25
- 0
packages/tldraw/src/hooks/useStylesheet.ts View File

1
+import * as React from 'react'
2
+
3
+const styles = new Map<string, HTMLStyleElement>()
4
+
5
+const UID = `tldraw-fonts`
6
+const CSS = `@import url('https://fonts.googleapis.com/css2?family=Caveat+Brush&display=swap')`
7
+
8
+export function useStylesheet() {
9
+  React.useLayoutEffect(() => {
10
+    if (styles.get(UID)) return
11
+
12
+    const style = document.createElement('style')
13
+    style.innerHTML = CSS
14
+    style.setAttribute('id', UID)
15
+    document.head.appendChild(style)
16
+    styles.set(UID, style)
17
+
18
+    return () => {
19
+      if (style && document.head.contains(style)) {
20
+        document.head.removeChild(style)
21
+        styles.delete(UID)
22
+      }
23
+    }
24
+  }, [UID, CSS])
25
+}

+ 0
- 1
packages/tldraw/src/hooks/useTheme.ts View File

5
 
5
 
6
 export function useTheme() {
6
 export function useTheme() {
7
   const { tlstate, useSelector } = useTLDrawContext()
7
   const { tlstate, useSelector } = useTLDrawContext()
8
-
9
   const theme = useSelector(themeSelector)
8
   const theme = useSelector(themeSelector)
10
 
9
 
11
   return {
10
   return {

+ 1
- 1
packages/tldraw/src/index.ts View File

1
 export * from './TLDraw'
1
 export * from './TLDraw'
2
 export * from './types'
2
 export * from './types'
3
-export * from './shape-utils'
3
+export * from './state/shapes'
4
 export { TLDrawState } from './state'
4
 export { TLDrawState } from './state'
5
 export { useFileSystem } from './hooks'
5
 export { useFileSystem } from './hooks'

+ 0
- 1
packages/tldraw/src/shape-utils/arrow/index.ts View File

1
-export * from './arrow'

+ 0
- 1
packages/tldraw/src/shape-utils/draw/index.ts View File

1
-export * from './draw'

+ 0
- 1
packages/tldraw/src/shape-utils/ellipse/index.ts View File

1
-export * from './ellipse'

+ 0
- 1
packages/tldraw/src/shape-utils/group/index.ts View File

1
-export * from './group'

+ 0
- 50
packages/tldraw/src/shape-utils/index.ts View File

1
-import type { TLDrawShapeUtil } from './TLDrawShapeUtil'
2
-import { RectangleUtil } from './rectangle'
3
-import { EllipseUtil } from './ellipse'
4
-import { ArrowUtil } from './arrow'
5
-import { GroupUtil } from './group'
6
-import { StickyUtil } from './sticky'
7
-import { TextUtil } from './text'
8
-import { DrawUtil } from './draw'
9
-import { TLDrawShape, TLDrawShapeType } from '~types'
10
-
11
-export * from './shape-styles'
12
-export * from './TLDrawShapeUtil'
13
-
14
-export const Rectangle = new RectangleUtil()
15
-export const Ellipse = new EllipseUtil()
16
-export const Draw = new DrawUtil()
17
-export const Arrow = new ArrowUtil()
18
-export const Text = new TextUtil()
19
-export const Group = new GroupUtil()
20
-export const Sticky = new StickyUtil()
21
-
22
-// type Utils = RectangleUtil | EllipseUtil | DrawUtil | ArrowUtil | TextUtil | GroupUtil | StickyUtil
23
-
24
-// type MappedByKey<U extends string | number, K extends string | number, T extends Record<K, U>> = {
25
-//   [P in T[K]]: T extends any ? (P extends T[K] ? T : never) : never
26
-// }
27
-
28
-// export type ShapeUtilsMap = MappedByKey<Utils['type'], 'type', Utils>
29
-
30
-// export const getShapeUtils = <T extends Utils['type']>(
31
-//   type: T | Extract<TLDrawShape, { type: T }>
32
-// ): ShapeUtilsMap[T] => {
33
-//   if (typeof type === 'string') return shapeUtils[type]
34
-//   return shapeUtils[type.type]
35
-// }
36
-
37
-export const shapeUtils = {
38
-  [TLDrawShapeType.Rectangle]: Rectangle,
39
-  [TLDrawShapeType.Ellipse]: Ellipse,
40
-  [TLDrawShapeType.Draw]: Draw,
41
-  [TLDrawShapeType.Arrow]: Arrow,
42
-  [TLDrawShapeType.Text]: Text,
43
-  [TLDrawShapeType.Group]: Group,
44
-  [TLDrawShapeType.Sticky]: Sticky,
45
-}
46
-
47
-export const getShapeUtils = <T extends TLDrawShape>(shape: T | T['type']) => {
48
-  if (typeof shape === 'string') return shapeUtils[shape] as unknown as TLDrawShapeUtil<T>
49
-  return shapeUtils[shape.type] as unknown as TLDrawShapeUtil<T>
50
-}

+ 0
- 1
packages/tldraw/src/shape-utils/rectangle/index.ts View File

1
-export * from './rectangle'

+ 0
- 1
packages/tldraw/src/shape-utils/sticky/index.ts View File

1
-export * from './sticky'

+ 0
- 1
packages/tldraw/src/shape-utils/text/index.ts View File

1
-export * from './text'

packages/tldraw/src/state/tldr.ts → packages/tldraw/src/state/TLDR.ts View File

1
 import { TLBounds, TLTransformInfo, Utils, TLPageState } from '@tldraw/core'
1
 import { TLBounds, TLTransformInfo, Utils, TLPageState } from '@tldraw/core'
2
-import { getShapeUtils, TLDrawShapeUtil } from '~shape-utils'
3
 import {
2
 import {
4
   Data,
3
   Data,
5
   ShapeStyles,
4
   ShapeStyles,
13
   ArrowShape,
12
   ArrowShape,
14
 } from '~types'
13
 } from '~types'
15
 import { Vec } from '@tldraw/vec'
14
 import { Vec } from '@tldraw/vec'
15
+import type { TLDrawShapeUtil } from './shapes/TLDrawShapeUtil'
16
+import { getShapeUtils } from './shapes'
16
 
17
 
17
 export class TLDR {
18
 export class TLDR {
18
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
   // eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/tldraw/src/state/tlstate.spec.ts → packages/tldraw/src/state/TLDrawState.spec.ts View File

1
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
1
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
-import { TLDrawState } from './tlstate'
3
-import { mockDocument, TLStateUtils } from '~test'
2
+import { TLDrawState } from './TLDrawState'
3
+import { mockDocument, TLDrawStateUtils } from '~test'
4
 import { ArrowShape, ColorStyle, SessionType, TLDrawShapeType } from '~types'
4
 import { ArrowShape, ColorStyle, SessionType, TLDrawShapeType } from '~types'
5
-import type { SelectTool } from './tool/SelectTool'
5
+import type { SelectTool } from './tools/SelectTool'
6
 
6
 
7
 describe('TLDrawState', () => {
7
 describe('TLDrawState', () => {
8
   const tlstate = new TLDrawState()
8
   const tlstate = new TLDrawState()
9
 
9
 
10
-  const tlu = new TLStateUtils(tlstate)
10
+  const tlu = new TLDrawStateUtils(tlstate)
11
 
11
 
12
   describe('When copying and pasting...', () => {
12
   describe('When copying and pasting...', () => {
13
     it('copies a shape', () => {
13
     it('copies a shape', () => {
357
         .loadDocument(mockDocument)
357
         .loadDocument(mockDocument)
358
         .group(['rect1', 'rect2'], 'groupA')
358
         .group(['rect1', 'rect2'], 'groupA')
359
 
359
 
360
-      const tlu = new TLStateUtils(tlstate)
360
+      const tlu = new TLDrawStateUtils(tlstate)
361
       tlu.clickShape('rect1')
361
       tlu.clickShape('rect1')
362
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toBeUndefined()
362
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toBeUndefined()
363
       expect(tlstate.selectedIds).toStrictEqual(['groupA'])
363
       expect(tlstate.selectedIds).toStrictEqual(['groupA'])
368
         .loadDocument(mockDocument)
368
         .loadDocument(mockDocument)
369
         .group(['rect1', 'rect2'], 'groupA')
369
         .group(['rect1', 'rect2'], 'groupA')
370
 
370
 
371
-      const tlu = new TLStateUtils(tlstate)
371
+      const tlu = new TLDrawStateUtils(tlstate)
372
       tlu.doubleClickShape('rect1')
372
       tlu.doubleClickShape('rect1')
373
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toStrictEqual('groupA')
373
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toStrictEqual('groupA')
374
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
374
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
379
         .loadDocument(mockDocument)
379
         .loadDocument(mockDocument)
380
         .group(['rect1', 'rect2'], 'groupA')
380
         .group(['rect1', 'rect2'], 'groupA')
381
 
381
 
382
-      const tlu = new TLStateUtils(tlstate)
382
+      const tlu = new TLDrawStateUtils(tlstate)
383
       tlu.doubleClickShape('rect1')
383
       tlu.doubleClickShape('rect1')
384
       tlu.clickShape('rect3')
384
       tlu.clickShape('rect3')
385
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toBeUndefined()
385
       expect((tlstate.currentTool as SelectTool).selectedGroupId).toBeUndefined()
392
         .group(['rect1', 'rect2'], 'groupA')
392
         .group(['rect1', 'rect2'], 'groupA')
393
         .deselectAll()
393
         .deselectAll()
394
 
394
 
395
-      const tlu = new TLStateUtils(tlstate)
395
+      const tlu = new TLDrawStateUtils(tlstate)
396
 
396
 
397
       tlu.clickShape('rect1', { ctrlKey: true, shiftKey: true })
397
       tlu.clickShape('rect1', { ctrlKey: true, shiftKey: true })
398
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
398
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
406
         .loadDocument(mockDocument)
406
         .loadDocument(mockDocument)
407
         .group(['rect1', 'rect2'], 'groupA')
407
         .group(['rect1', 'rect2'], 'groupA')
408
 
408
 
409
-      const tlu = new TLStateUtils(tlstate)
409
+      const tlu = new TLDrawStateUtils(tlstate)
410
 
410
 
411
       tlu.clickShape('rect1', { ctrlKey: true, shiftKey: true })
411
       tlu.clickShape('rect1', { ctrlKey: true, shiftKey: true })
412
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
412
       expect(tlstate.selectedIds).toStrictEqual(['rect1'])
438
         )
438
         )
439
         .selectTool(TLDrawShapeType.Rectangle)
439
         .selectTool(TLDrawShapeType.Rectangle)
440
 
440
 
441
-      const tlu = new TLStateUtils(tlstate)
441
+      const tlu = new TLDrawStateUtils(tlstate)
442
 
442
 
443
       const prevA = tlstate.shapes.map((shape) => shape.id)
443
       const prevA = tlstate.shapes.map((shape) => shape.id)
444
 
444
 

packages/tldraw/src/state/tlstate.ts → packages/tldraw/src/state/TLDrawState.ts View File

40
   ExceptFirst,
40
   ExceptFirst,
41
   ExceptFirstTwo,
41
   ExceptFirstTwo,
42
 } from '~types'
42
 } from '~types'
43
-import { TLDR } from './tldr'
44
-import { defaultStyle, shapeUtils } from '~shape-utils'
45
-import * as Commands from './command'
46
-import { ArgsOfType, getSession } from './session'
47
-import { sample } from './utils'
48
-import { createTools, ToolType } from './tool'
49
-import type { BaseTool } from './tool/BaseTool'
43
+import {
44
+  migrate,
45
+  FileSystemHandle,
46
+  loadFileHandle,
47
+  openFromFileSystem,
48
+  saveToFileSystem,
49
+} from './data'
50
+import { TLDR } from './TLDR'
51
+import { shapeUtils } from '~state/shapes'
52
+import { defaultStyle } from '~state/shapes/shape-styles'
53
+import * as Commands from './commands'
54
+import { ArgsOfType, getSession } from './sessions'
55
+import { createTools, ToolType } from './tools'
56
+import type { BaseTool } from './tools/BaseTool'
50
 import { USER_COLORS, FIT_TO_SCREEN_PADDING } from '~constants'
57
 import { USER_COLORS, FIT_TO_SCREEN_PADDING } from '~constants'
51
-import { migrate } from './data/migrate'
52
-import { loadFileHandle, openFromFileSystem, saveToFileSystem } from './data/filesystem'
53
-import type { FileSystemHandle } from './data/browser-fs-access'
54
 
58
 
55
 const uuid = Utils.uniqueId()
59
 const uuid = Utils.uniqueId()
56
 
60
 
791
         users: {
795
         users: {
792
           [uuid]: {
796
           [uuid]: {
793
             id: uuid,
797
             id: uuid,
794
-            color: sample(USER_COLORS),
798
+            color: USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)],
795
             point: [100, 100],
799
             point: [100, 100],
796
             selectedIds: [],
800
             selectedIds: [],
797
             activeShapes: [],
801
             activeShapes: [],
1992
    */
1996
    */
1993
   create = (shapes: TLDrawShape[] = [], bindings: TLDrawBinding[] = []): this => {
1997
   create = (shapes: TLDrawShape[] = [], bindings: TLDrawBinding[] = []): this => {
1994
     if (shapes.length === 0) return this
1998
     if (shapes.length === 0) return this
1995
-    return this.setState(Commands.create(this.state, shapes, bindings))
1999
+    return this.setState(Commands.createShapes(this.state, shapes, bindings))
1996
   }
2000
   }
1997
 
2001
 
1998
   /**
2002
   /**
2002
    */
2006
    */
2003
   patchCreate = (shapes: TLDrawShape[] = [], bindings: TLDrawBinding[] = []): this => {
2007
   patchCreate = (shapes: TLDrawShape[] = [], bindings: TLDrawBinding[] = []): this => {
2004
     if (shapes.length === 0) return this
2008
     if (shapes.length === 0) return this
2005
-    return this.patchState(Commands.create(this.state, shapes, bindings).after)
2009
+    return this.patchState(Commands.createShapes(this.state, shapes, bindings).after)
2006
   }
2010
   }
2007
 
2011
 
2008
   /**
2012
   /**
2030
    * @param ids The ids of the shapes to change (defaults to selection).
2034
    * @param ids The ids of the shapes to change (defaults to selection).
2031
    */
2035
    */
2032
   style = (style: Partial<ShapeStyles>, ids = this.selectedIds): this => {
2036
   style = (style: Partial<ShapeStyles>, ids = this.selectedIds): this => {
2033
-    return this.setState(Commands.style(this.state, ids, style))
2037
+    return this.setState(Commands.styleShapes(this.state, ids, style))
2034
   }
2038
   }
2035
 
2039
 
2036
   /**
2040
   /**
2040
    */
2044
    */
2041
   align = (type: AlignType, ids = this.selectedIds): this => {
2045
   align = (type: AlignType, ids = this.selectedIds): this => {
2042
     if (ids.length < 2) return this
2046
     if (ids.length < 2) return this
2043
-    return this.setState(Commands.align(this.state, ids, type))
2047
+    return this.setState(Commands.alignShapes(this.state, ids, type))
2044
   }
2048
   }
2045
 
2049
 
2046
   /**
2050
   /**
2050
    */
2054
    */
2051
   distribute = (direction: DistributeType, ids = this.selectedIds): this => {
2055
   distribute = (direction: DistributeType, ids = this.selectedIds): this => {
2052
     if (ids.length < 3) return this
2056
     if (ids.length < 3) return this
2053
-    return this.setState(Commands.distribute(this.state, ids, direction))
2057
+    return this.setState(Commands.distributeShapes(this.state, ids, direction))
2054
   }
2058
   }
2055
 
2059
 
2056
   /**
2060
   /**
2060
    */
2064
    */
2061
   stretch = (direction: StretchType, ids = this.selectedIds): this => {
2065
   stretch = (direction: StretchType, ids = this.selectedIds): this => {
2062
     if (ids.length < 2) return this
2066
     if (ids.length < 2) return this
2063
-    return this.setState(Commands.stretch(this.state, ids, direction))
2067
+    return this.setState(Commands.stretchShapes(this.state, ids, direction))
2064
   }
2068
   }
2065
 
2069
 
2066
   /**
2070
   /**
2069
    */
2073
    */
2070
   flipHorizontal = (ids = this.selectedIds): this => {
2074
   flipHorizontal = (ids = this.selectedIds): this => {
2071
     if (ids.length === 0) return this
2075
     if (ids.length === 0) return this
2072
-    return this.setState(Commands.flip(this.state, ids, FlipType.Horizontal))
2076
+    return this.setState(Commands.flipShapes(this.state, ids, FlipType.Horizontal))
2073
   }
2077
   }
2074
 
2078
 
2075
   /**
2079
   /**
2078
    */
2082
    */
2079
   flipVertical = (ids = this.selectedIds): this => {
2083
   flipVertical = (ids = this.selectedIds): this => {
2080
     if (ids.length === 0) return this
2084
     if (ids.length === 0) return this
2081
-    return this.setState(Commands.flip(this.state, ids, FlipType.Vertical))
2085
+    return this.setState(Commands.flipShapes(this.state, ids, FlipType.Vertical))
2082
   }
2086
   }
2083
 
2087
 
2084
   /**
2088
   /**
2093
     ids = this.selectedIds
2097
     ids = this.selectedIds
2094
   ): this => {
2098
   ): this => {
2095
     if (ids.length === 0) return this
2099
     if (ids.length === 0) return this
2096
-    this.setState(Commands.moveToPage(this.state, ids, this.bounds, fromPageId, toPageId))
2100
+    this.setState(Commands.moveShapesToPage(this.state, ids, this.bounds, fromPageId, toPageId))
2097
     return this
2101
     return this
2098
   }
2102
   }
2099
 
2103
 
2103
    */
2107
    */
2104
   moveToBack = (ids = this.selectedIds): this => {
2108
   moveToBack = (ids = this.selectedIds): this => {
2105
     if (ids.length === 0) return this
2109
     if (ids.length === 0) return this
2106
-    return this.setState(Commands.move(this.state, ids, MoveType.ToBack))
2110
+    return this.setState(Commands.reorderShapes(this.state, ids, MoveType.ToBack))
2107
   }
2111
   }
2108
 
2112
 
2109
   /**
2113
   /**
2112
    */
2116
    */
2113
   moveBackward = (ids = this.selectedIds): this => {
2117
   moveBackward = (ids = this.selectedIds): this => {
2114
     if (ids.length === 0) return this
2118
     if (ids.length === 0) return this
2115
-    return this.setState(Commands.move(this.state, ids, MoveType.Backward))
2119
+    return this.setState(Commands.reorderShapes(this.state, ids, MoveType.Backward))
2116
   }
2120
   }
2117
 
2121
 
2118
   /**
2122
   /**
2121
    */
2125
    */
2122
   moveForward = (ids = this.selectedIds): this => {
2126
   moveForward = (ids = this.selectedIds): this => {
2123
     if (ids.length === 0) return this
2127
     if (ids.length === 0) return this
2124
-    return this.setState(Commands.move(this.state, ids, MoveType.Forward))
2128
+    return this.setState(Commands.reorderShapes(this.state, ids, MoveType.Forward))
2125
   }
2129
   }
2126
 
2130
 
2127
   /**
2131
   /**
2130
    */
2134
    */
2131
   moveToFront = (ids = this.selectedIds): this => {
2135
   moveToFront = (ids = this.selectedIds): this => {
2132
     if (ids.length === 0) return this
2136
     if (ids.length === 0) return this
2133
-    return this.setState(Commands.move(this.state, ids, MoveType.ToFront))
2137
+    return this.setState(Commands.reorderShapes(this.state, ids, MoveType.ToFront))
2134
   }
2138
   }
2135
 
2139
 
2136
   /**
2140
   /**
2141
    */
2145
    */
2142
   nudge = (delta: number[], isMajor = false, ids = this.selectedIds): this => {
2146
   nudge = (delta: number[], isMajor = false, ids = this.selectedIds): this => {
2143
     if (ids.length === 0) return this
2147
     if (ids.length === 0) return this
2144
-    return this.setState(Commands.translate(this.state, ids, Vec.mul(delta, isMajor ? 10 : 1)))
2148
+    return this.setState(
2149
+      Commands.translateShapes(this.state, ids, Vec.mul(delta, isMajor ? 10 : 1))
2150
+    )
2145
   }
2151
   }
2146
 
2152
 
2147
   /**
2153
   /**
2151
   duplicate = (ids = this.selectedIds, point?: number[]): this => {
2157
   duplicate = (ids = this.selectedIds, point?: number[]): this => {
2152
     if (this.readOnly) return this
2158
     if (this.readOnly) return this
2153
     if (ids.length === 0) return this
2159
     if (ids.length === 0) return this
2154
-    return this.setState(Commands.duplicate(this.state, ids, point))
2160
+    return this.setState(Commands.duplicateShapes(this.state, ids, point))
2155
   }
2161
   }
2156
 
2162
 
2157
   /**
2163
   /**
2171
    */
2177
    */
2172
   toggleHidden = (ids = this.selectedIds): this => {
2178
   toggleHidden = (ids = this.selectedIds): this => {
2173
     if (ids.length === 0) return this
2179
     if (ids.length === 0) return this
2174
-    return this.setState(Commands.toggle(this.state, ids, 'isHidden'))
2180
+    return this.setState(Commands.toggleShapeProp(this.state, ids, 'isHidden'))
2175
   }
2181
   }
2176
 
2182
 
2177
   /**
2183
   /**
2180
    */
2186
    */
2181
   toggleLocked = (ids = this.selectedIds): this => {
2187
   toggleLocked = (ids = this.selectedIds): this => {
2182
     if (ids.length === 0) return this
2188
     if (ids.length === 0) return this
2183
-    return this.setState(Commands.toggle(this.state, ids, 'isLocked'))
2189
+    return this.setState(Commands.toggleShapeProp(this.state, ids, 'isLocked'))
2184
   }
2190
   }
2185
 
2191
 
2186
   /**
2192
   /**
2189
    */
2195
    */
2190
   toggleAspectRatioLocked = (ids = this.selectedIds): this => {
2196
   toggleAspectRatioLocked = (ids = this.selectedIds): this => {
2191
     if (ids.length === 0) return this
2197
     if (ids.length === 0) return this
2192
-    return this.setState(Commands.toggle(this.state, ids, 'isAspectRatioLocked'))
2198
+    return this.setState(Commands.toggleShapeProp(this.state, ids, 'isAspectRatioLocked'))
2193
   }
2199
   }
2194
 
2200
 
2195
   /**
2201
   /**
2199
    */
2205
    */
2200
   toggleDecoration = (handleId: string, ids = this.selectedIds): this => {
2206
   toggleDecoration = (handleId: string, ids = this.selectedIds): this => {
2201
     if (ids.length === 0 || !(handleId === 'start' || handleId === 'end')) return this
2207
     if (ids.length === 0 || !(handleId === 'start' || handleId === 'end')) return this
2202
-    return this.setState(Commands.toggleDecoration(this.state, ids, handleId))
2208
+    return this.setState(Commands.toggleShapesDecoration(this.state, ids, handleId))
2203
   }
2209
   }
2204
 
2210
 
2205
   /**
2211
   /**
2209
    */
2215
    */
2210
   rotate = (delta = Math.PI * -0.5, ids = this.selectedIds): this => {
2216
   rotate = (delta = Math.PI * -0.5, ids = this.selectedIds): this => {
2211
     if (ids.length === 0) return this
2217
     if (ids.length === 0) return this
2212
-    const change = Commands.rotate(this.state, ids, delta)
2218
+    const change = Commands.rotateShapes(this.state, ids, delta)
2213
     if (!change) return this
2219
     if (!change) return this
2214
     return this.setState(change)
2220
     return this.setState(change)
2215
   }
2221
   }
2232
 
2238
 
2233
     if (ids.length < 2) return this
2239
     if (ids.length < 2) return this
2234
 
2240
 
2235
-    const command = Commands.group(this.state, ids, groupId, pageId)
2241
+    const command = Commands.groupShapes(this.state, ids, groupId, pageId)
2236
     if (!command) return this
2242
     if (!command) return this
2237
     return this.setState(command)
2243
     return this.setState(command)
2238
   }
2244
   }
2250
 
2256
 
2251
     if (groups.length === 0) return this
2257
     if (groups.length === 0) return this
2252
 
2258
 
2253
-    const command = Commands.ungroup(this.state, ids, groups as GroupShape[], pageId)
2259
+    const command = Commands.ungroupShapes(this.state, ids, groups as GroupShape[], pageId)
2254
     if (!command) return this
2260
     if (!command) return this
2255
     return this.setState(command)
2261
     return this.setState(command)
2256
   }
2262
   }
2582
       users: {
2588
       users: {
2583
         [uuid]: {
2589
         [uuid]: {
2584
           id: uuid,
2590
           id: uuid,
2585
-          color: sample(USER_COLORS),
2591
+          color: USER_COLORS[0],
2586
           point: [100, 100],
2592
           point: [100, 100],
2587
           selectedIds: [],
2593
           selectedIds: [],
2588
           activeShapes: [],
2594
           activeShapes: [],

packages/tldraw/src/state/__snapshots__/tlstate.spec.ts.snap → packages/tldraw/src/state/__snapshots__/TLDrawState.spec.ts.snap View File


+ 0
- 1
packages/tldraw/src/state/command/align/index.ts View File

1
-export * from './align.command'

+ 0
- 1
packages/tldraw/src/state/command/change-page/index.ts View File

1
-export * from './change-page.command'

+ 0
- 1
packages/tldraw/src/state/command/create-page/index.ts View File

1
-export * from './create-page.command'

+ 0
- 1
packages/tldraw/src/state/command/create/index.ts View File

1
-export * from './create.command'

+ 0
- 1
packages/tldraw/src/state/command/delete-page/index.ts View File

1
-export * from './delete-page.command'

+ 0
- 1
packages/tldraw/src/state/command/delete/index.ts View File

1
-export * from './delete.command'

+ 0
- 1
packages/tldraw/src/state/command/distribute/index.ts View File

1
-export * from './distribute.command'

+ 0
- 1
packages/tldraw/src/state/command/duplicate-page/index.ts View File

1
-export * from './duplicate-page.command'

+ 0
- 1
packages/tldraw/src/state/command/duplicate/index.ts View File

1
-export * from './duplicate.command'

+ 0
- 1
packages/tldraw/src/state/command/flip/index.ts View File

1
-export * from './flip.command'

+ 0
- 1
packages/tldraw/src/state/command/group/index.ts View File

1
-export * from './group.command'

+ 0
- 23
packages/tldraw/src/state/command/index.ts View File

1
-export * from './align'
2
-export * from './change-page'
3
-export * from './create-page'
4
-export * from './create'
5
-export * from './delete-page'
6
-export * from './delete'
7
-export * from './distribute'
8
-export * from './duplicate-page'
9
-export * from './duplicate'
10
-export * from './flip'
11
-export * from './group'
12
-export * from './move-to-page'
13
-export * from './move'
14
-export * from './rename-page'
15
-export * from './reset-bounds'
16
-export * from './rotate'
17
-export * from './stretch'
18
-export * from './style'
19
-export * from './toggle-decoration'
20
-export * from './toggle'
21
-export * from './translate'
22
-export * from './ungroup'
23
-export * from './update'

+ 0
- 1
packages/tldraw/src/state/command/move-to-page/index.ts View File

1
-export * from './move-to-page.command'

+ 0
- 1
packages/tldraw/src/state/command/move/index.ts View File

1
-export * from './move.command'

+ 0
- 1
packages/tldraw/src/state/command/rename-page/index.ts View File

1
-export * from './rename-page.command'

+ 0
- 1
packages/tldraw/src/state/command/reset-bounds/index.ts View File

1
-export * from './reset-bounds.command'

+ 0
- 1
packages/tldraw/src/state/command/rotate/index.ts View File

1
-export * from './rotate.command'

+ 0
- 1
packages/tldraw/src/state/command/stretch/index.ts View File

1
-export * from './stretch.command'

+ 0
- 1
packages/tldraw/src/state/command/style/index.ts View File

1
-export * from './style.command'

+ 0
- 1
packages/tldraw/src/state/command/toggle-decoration/index.ts View File

1
-export * from './toggle-decoration.command'

+ 0
- 1
packages/tldraw/src/state/command/toggle/index.ts View File

1
-export * from './toggle.command'

+ 0
- 1
packages/tldraw/src/state/command/translate/index.ts View File

1
-export * from './translate.command'

+ 0
- 1
packages/tldraw/src/state/command/ungroup/index.ts View File

1
-export * from './ungroup.command'

+ 0
- 1
packages/tldraw/src/state/command/update/index.ts View File

1
-export * from './update.command'

packages/tldraw/src/state/command/align/align.command.spec.ts → packages/tldraw/src/state/commands/alignShapes/alignShapes.spec.ts View File

1
 import Vec from '@tldraw/vec'
1
 import Vec from '@tldraw/vec'
2
 import { TLDrawState } from '~state'
2
 import { TLDrawState } from '~state'
3
-import { mockDocument, TLStateUtils } from '~test'
3
+import { mockDocument, TLDrawStateUtils } from '~test'
4
 import { AlignType, TLDrawShapeType } from '~types'
4
 import { AlignType, TLDrawShapeType } from '~types'
5
 
5
 
6
 describe('Align command', () => {
6
 describe('Align command', () => {
95
 
95
 
96
     tlstate.undo().delete(['rect4']).selectAll().align(AlignType.CenterVertical)
96
     tlstate.undo().delete(['rect4']).selectAll().align(AlignType.CenterVertical)
97
 
97
 
98
-    new TLStateUtils(tlstate).expectShapesToBeAtPoints({
98
+    new TLDrawStateUtils(tlstate).expectShapesToBeAtPoints({
99
       rect1: p0,
99
       rect1: p0,
100
       rect2: Vec.add(p0, [100, 100]),
100
       rect2: Vec.add(p0, [100, 100]),
101
       rect3: p1,
101
       rect3: p1,

packages/tldraw/src/state/command/align/align.command.ts → packages/tldraw/src/state/commands/alignShapes/alignShapes.ts View File

2
 import { Utils } from '@tldraw/core'
2
 import { Utils } from '@tldraw/core'
3
 import { AlignType, TLDrawCommand, TLDrawShapeType } from '~types'
3
 import { AlignType, TLDrawCommand, TLDrawShapeType } from '~types'
4
 import type { Data } from '~types'
4
 import type { Data } from '~types'
5
-import { TLDR } from '~state/tldr'
5
+import { TLDR } from '~state/TLDR'
6
 import Vec from '@tldraw/vec'
6
 import Vec from '@tldraw/vec'
7
 
7
 
8
-export function align(data: Data, ids: string[], type: AlignType): TLDrawCommand {
8
+export function alignShapes(data: Data, ids: string[], type: AlignType): TLDrawCommand {
9
   const { currentPageId } = data.appState
9
   const { currentPageId } = data.appState
10
 
10
 
11
   const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))
11
   const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))

+ 1
- 0
packages/tldraw/src/state/commands/alignShapes/index.ts View File

1
+export * from './alignShapes'

packages/tldraw/src/state/command/change-page/change-page.command.spec.ts → packages/tldraw/src/state/commands/changePage/changePage.spec.ts View File


packages/tldraw/src/state/command/change-page/change-page.command.ts → packages/tldraw/src/state/commands/changePage/changePage.ts View File


+ 1
- 0
packages/tldraw/src/state/commands/changePage/index.ts View File

1
+export * from './changePage'

packages/tldraw/src/state/command/create-page/create-page.command.spec.ts → packages/tldraw/src/state/commands/createPage/createPage.spec.ts View File


packages/tldraw/src/state/command/create-page/create-page.command.ts → packages/tldraw/src/state/commands/createPage/createPage.ts View File


+ 1
- 0
packages/tldraw/src/state/commands/createPage/index.ts View File

1
+export * from './createPage'

packages/tldraw/src/state/command/create/create.command.spec.ts → packages/tldraw/src/state/commands/createShapes/createShapes.spec.ts View File


packages/tldraw/src/state/command/create/create.command.ts → packages/tldraw/src/state/commands/createShapes/createShapes.ts View File

1
 import type { Patch } from 'rko'
1
 import type { Patch } from 'rko'
2
-import { TLDR } from '~state/tldr'
2
+import { TLDR } from '~state/TLDR'
3
 import type { TLDrawShape, Data, TLDrawCommand, TLDrawBinding } from '~types'
3
 import type { TLDrawShape, Data, TLDrawCommand, TLDrawBinding } from '~types'
4
 
4
 
5
-export function create(
5
+export function createShapes(
6
   data: Data,
6
   data: Data,
7
   shapes: TLDrawShape[],
7
   shapes: TLDrawShape[],
8
   bindings: TLDrawBinding[] = []
8
   bindings: TLDrawBinding[] = []

+ 1
- 0
packages/tldraw/src/state/commands/createShapes/index.ts View File

1
+export * from './createShapes'

packages/tldraw/src/state/command/delete-page/delete-page.command.spec.ts → packages/tldraw/src/state/commands/deletePage/deletePage.spec.ts View File


packages/tldraw/src/state/command/delete-page/delete-page.command.ts → packages/tldraw/src/state/commands/deletePage/deletePage.ts View File


+ 1
- 0
packages/tldraw/src/state/commands/deletePage/index.ts View File

1
+export * from './deletePage'

packages/tldraw/src/state/command/delete/delete.command.spec.ts → packages/tldraw/src/state/commands/deleteShapes/deleteShapes.spec.ts View File


packages/tldraw/src/state/command/delete/delete.command.ts → packages/tldraw/src/state/commands/deleteShapes/deleteShapes.ts View File

1
-import { TLDR } from '~state/tldr'
1
+import { TLDR } from '~state/TLDR'
2
 import type { Data, TLDrawCommand } from '~types'
2
 import type { Data, TLDrawCommand } from '~types'
3
-import { removeShapesFromPage } from '../utils/removeShapesFromPage'
4
-
5
-// - [ ] Update parents and possibly delete parents
3
+import { removeShapesFromPage } from '../shared/removeShapesFromPage'
6
 
4
 
7
 export function deleteShapes(
5
 export function deleteShapes(
8
   data: Data,
6
   data: Data,

+ 1
- 0
packages/tldraw/src/state/commands/deleteShapes/index.ts View File

1
+export * from './deleteShapes'

packages/tldraw/src/state/command/distribute/distribute.command.spec.ts → packages/tldraw/src/state/commands/distributeShapes/distributeShapes.spec.ts View File

1
 import Vec from '@tldraw/vec'
1
 import Vec from '@tldraw/vec'
2
 import { TLDrawState } from '~state'
2
 import { TLDrawState } from '~state'
3
-import { mockDocument, TLStateUtils } from '~test'
3
+import { mockDocument, TLDrawStateUtils } from '~test'
4
 import { AlignType, DistributeType, TLDrawShapeType } from '~types'
4
 import { AlignType, DistributeType, TLDrawShapeType } from '~types'
5
 
5
 
6
 describe('Distribute command', () => {
6
 describe('Distribute command', () => {
59
 
59
 
60
     tlstate.undo().delete(['rect4']).selectAll().distribute(DistributeType.Vertical)
60
     tlstate.undo().delete(['rect4']).selectAll().distribute(DistributeType.Vertical)
61
 
61
 
62
-    new TLStateUtils(tlstate).expectShapesToBeAtPoints({
62
+    new TLDrawStateUtils(tlstate).expectShapesToBeAtPoints({
63
       rect1: p0,
63
       rect1: p0,
64
       rect2: Vec.add(p0, [100, 100]),
64
       rect2: Vec.add(p0, [100, 100]),
65
       rect3: p1,
65
       rect3: p1,

packages/tldraw/src/state/command/distribute/distribute.command.ts → packages/tldraw/src/state/commands/distributeShapes/distributeShapes.ts View File

1
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
1
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
 import { Utils } from '@tldraw/core'
2
 import { Utils } from '@tldraw/core'
3
 import { DistributeType, TLDrawShape, Data, TLDrawCommand, TLDrawShapeType } from '~types'
3
 import { DistributeType, TLDrawShape, Data, TLDrawCommand, TLDrawShapeType } from '~types'
4
-import { TLDR } from '~state/tldr'
4
+import { TLDR } from '~state/TLDR'
5
 import Vec from '@tldraw/vec'
5
 import Vec from '@tldraw/vec'
6
 
6
 
7
-export function distribute(data: Data, ids: string[], type: DistributeType): TLDrawCommand {
7
+export function distributeShapes(data: Data, ids: string[], type: DistributeType): TLDrawCommand {
8
   const { currentPageId } = data.appState
8
   const { currentPageId } = data.appState
9
 
9
 
10
   const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))
10
   const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))

+ 1
- 0
packages/tldraw/src/state/commands/distributeShapes/index.ts View File

1
+export * from './distributeShapes'

packages/tldraw/src/state/command/duplicate-page/duplicate-page.command.spec.ts → packages/tldraw/src/state/commands/duplicatePage/duplicatePage.spec.ts View File


packages/tldraw/src/state/command/duplicate-page/duplicate-page.command.ts → packages/tldraw/src/state/commands/duplicatePage/duplicatePage.ts View File


+ 1
- 0
packages/tldraw/src/state/commands/duplicatePage/index.ts View File

1
+export * from './duplicatePage'

packages/tldraw/src/state/command/duplicate/duplicate.command.spec.ts → packages/tldraw/src/state/commands/duplicateShapes/duplicateShapes.spec.ts View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save