Browse Source

Improves performance issue caused by @radix-ui/use-direction

main
Steve Ruiz 3 years ago
parent
commit
9f16f886ea

+ 4
- 4
components/canvas/context-menu/context-menu.tsx View File

@@ -96,7 +96,7 @@ export default function ContextMenu({
96 96
   const hasThreeOrMore = selectedShapeIds.length > 2
97 97
 
98 98
   return (
99
-    <_ContextMenu.Root>
99
+    <_ContextMenu.Root dir="ltr">
100 100
       <_ContextMenu.Trigger>{children}</_ContextMenu.Trigger>
101 101
       <StyledContent ref={rContent} isMobile={isMobile()}>
102 102
         {selectedShapeIds.length ? (
@@ -342,7 +342,7 @@ function SubMenu({
342 342
   children: React.ReactNode
343 343
 }) {
344 344
   return (
345
-    <_ContextMenu.Root>
345
+    <_ContextMenu.Root dir="ltr">
346 346
       <_ContextMenu.TriggerItem
347 347
         as={RowButton}
348 348
         bp={{ '@initial': 'mobile', '@sm': 'small' }}
@@ -367,7 +367,7 @@ function AlignDistributeSubMenu({
367 367
   hasThreeOrMore: boolean
368 368
 }) {
369 369
   return (
370
-    <_ContextMenu.Root>
370
+    <_ContextMenu.Root dir="ltr">
371 371
       <_ContextMenu.TriggerItem
372 372
         as={RowButton}
373 373
         bp={{ '@initial': 'mobile', '@sm': 'small' }}
@@ -451,7 +451,7 @@ function MoveToPageMenu() {
451 451
   if (sorted.length === 0) return null
452 452
 
453 453
   return (
454
-    <_ContextMenu.Root>
454
+    <_ContextMenu.Root dir="ltr">
455 455
       <_ContextMenu.TriggerItem
456 456
         as={RowButton}
457 457
         bp={{ '@initial': 'mobile', '@sm': 'small' }}

+ 4
- 12
components/canvas/shape.tsx View File

@@ -3,8 +3,8 @@ import { useSelector } from 'state'
3 3
 import styled from 'styles'
4 4
 import { getShapeUtils } from 'state/shape-utils'
5 5
 import { getPage, getSelectedIds, isMobile } from 'utils'
6
-import { Shape as _Shape } from 'types'
7 6
 import useShapeEvents from 'hooks/useShapeEvents'
7
+import { Shape as _Shape } from 'types'
8 8
 import vec from 'utils/vec'
9 9
 import { getShapeStyle } from 'state/shape-styles'
10 10
 
@@ -83,7 +83,7 @@ function Shape({ id, isSelecting, parentPoint }: ShapeProps): JSX.Element {
83 83
               as="use"
84 84
               href={'#' + id}
85 85
               strokeWidth={+style.strokeWidth + 5}
86
-              variant={getShapeUtils(shape).canStyleFill ? 'filled' : 'hollow'}
86
+              variant={shapeUtils.canStyleFill ? 'filled' : 'hollow'}
87 87
             />
88 88
           )}
89 89
         </>
@@ -93,13 +93,7 @@ function Shape({ id, isSelecting, parentPoint }: ShapeProps): JSX.Element {
93 93
         (isForeignObject ? (
94 94
           shapeUtils.render(shape, { isEditing, ref: rFocusable })
95 95
         ) : (
96
-          <RealShape
97
-            isParent={isParent}
98
-            id={id}
99
-            shape={shape}
100
-            style={style}
101
-            isEditing={isEditing}
102
-          />
96
+          <RealShape id={id} isParent={isParent} shape={shape} />
103 97
         ))}
104 98
 
105 99
       {isParent &&
@@ -117,10 +111,8 @@ function Shape({ id, isSelecting, parentPoint }: ShapeProps): JSX.Element {
117 111
 
118 112
 interface RealShapeProps {
119 113
   id: string
120
-  style: Partial<React.SVGProps<SVGUseElement>>
121
-  isParent: boolean
122 114
   shape: _Shape
123
-  isEditing: boolean
115
+  isParent: boolean
124 116
 }
125 117
 
126 118
 const RealShape = memo(function RealShape({ id, isParent }: RealShapeProps) {

+ 1
- 0
components/code-panel/code-panel.tsx View File

@@ -130,6 +130,7 @@ export default function CodePanel(): JSX.Element {
130 130
 
131 131
   return (
132 132
     <Panel.Root
133
+      dir="ltr"
133 134
       bp={{ '@initial': 'mobile', '@sm': 'small' }}
134 135
       data-bp-desktop
135 136
       ref={rContainer}

+ 1
- 0
components/controls-panel/controls-panel.tsx View File

@@ -18,6 +18,7 @@ export default function ControlPanel(): JSX.Element {
18 18
 
19 19
   return (
20 20
     <Panel.Root
21
+      dir="ltr"
21 22
       data-bp-desktop
22 23
       ref={rContainer}
23 24
       isOpen={isOpen}

+ 3
- 2
components/page-panel/page-panel.tsx View File

@@ -29,6 +29,7 @@ export default function PagePanel(): JSX.Element {
29 29
 
30 30
   return (
31 31
     <DropdownMenu.Root
32
+      dir="ltr"
32 33
       open={isOpen}
33 34
       onOpenChange={(isOpen) => {
34 35
         if (rIsOpen.current !== isOpen) {
@@ -36,7 +37,7 @@ export default function PagePanel(): JSX.Element {
36 37
         }
37 38
       }}
38 39
     >
39
-      <PanelRoot>
40
+      <PanelRoot dir="ltr">
40 41
         <DropdownMenu.Trigger
41 42
           as={RowButton}
42 43
           bp={{ '@initial': 'mobile', '@sm': 'small' }}
@@ -55,7 +56,7 @@ export default function PagePanel(): JSX.Element {
55 56
               }}
56 57
             >
57 58
               {sorted.map(({ id, name }) => (
58
-                <ContextMenu.Root key={id}>
59
+                <ContextMenu.Root dir="ltr" key={id}>
59 60
                   <ContextMenu.Trigger>
60 61
                     <StyledRadioItem
61 62
                       key={id}

+ 1
- 1
components/style-panel/color-picker.tsx View File

@@ -12,7 +12,7 @@ interface Props {
12 12
 
13 13
 export default function ColorPicker({ color, onChange }: Props): JSX.Element {
14 14
   return (
15
-    <DropdownMenu.Root>
15
+    <DropdownMenu.Root dir="ltr">
16 16
       <DropdownMenu.Trigger
17 17
         as={RowButton}
18 18
         bp={{ '@initial': 'mobile', '@sm': 'small' }}

+ 1
- 0
components/style-panel/is-filled-picker.tsx View File

@@ -15,6 +15,7 @@ export default function IsFilledPicker({
15 15
 }: Props): JSX.Element {
16 16
   return (
17 17
     <Checkbox.Root
18
+      dir="ltr"
18 19
       as={RowButton}
19 20
       bp={{ '@initial': 'mobile', '@sm': 'small' }}
20 21
       checked={isFilled}

+ 1
- 1
components/style-panel/quick-color-select.tsx View File

@@ -10,7 +10,7 @@ export default function QuickColorSelect(): JSX.Element {
10 10
   const color = useSelector((s) => s.values.selectedStyle.color)
11 11
 
12 12
   return (
13
-    <DropdownMenu.Root>
13
+    <DropdownMenu.Root dir="ltr">
14 14
       <DropdownMenu.Trigger
15 15
         as={IconButton}
16 16
         bp={{ '@initial': 'mobile', '@sm': 'small' }}

+ 1
- 1
components/style-panel/quick-dash-select.tsx View File

@@ -21,7 +21,7 @@ export default function QuickdashSelect(): JSX.Element {
21 21
   const dash = useSelector((s) => s.values.selectedStyle.dash)
22 22
 
23 23
   return (
24
-    <DropdownMenu.Root>
24
+    <DropdownMenu.Root dir="ltr">
25 25
       <DropdownMenu.Trigger
26 26
         as={IconButton}
27 27
         bp={{ '@initial': 'mobile', '@sm': 'small' }}

+ 1
- 1
components/style-panel/quick-size-select.tsx View File

@@ -16,7 +16,7 @@ export default function QuickSizeSelect(): JSX.Element {
16 16
   const size = useSelector((s) => s.values.selectedStyle.size)
17 17
 
18 18
   return (
19
-    <DropdownMenu.Root>
19
+    <DropdownMenu.Root dir="ltr">
20 20
       <DropdownMenu.Trigger
21 21
         as={IconButton}
22 22
         bp={{ '@initial': 'mobile', '@sm': 'small' }}

+ 42
- 29
components/style-panel/style-panel.tsx View File

@@ -36,12 +36,28 @@ import QuickSizeSelect from './quick-size-select'
36 36
 import QuickdashSelect from './quick-dash-select'
37 37
 import Tooltip from 'components/tooltip'
38 38
 
39
+const breakpoints = { '@initial': 'mobile', '@sm': 'small' } as any
40
+const handleStylePanelOpen = () => state.send('TOGGLED_STYLE_PANEL_OPEN')
41
+const handleColorChange = (color) => state.send('CHANGED_STYLE', { color })
42
+const handleRotateCcw = () => () => state.send('ROTATED_CCW')
43
+const handleIsFilledChange = (dash) => state.send('CHANGED_STYLE', { dash })
44
+const handleDuplicate = () => state.send('DUPLICATED')
45
+const handleHide = () => state.send('TOGGLED_SHAPE_HIDE')
46
+const handleLock = () => state.send('TOGGLED_SHAPE_LOCK')
47
+const handleAspectLock = () => state.send('TOGGLED_SHAPE_ASPECT_LOCK')
48
+const handleMoveToBack = () => state.send('MOVED', { type: MoveType.ToBack })
49
+const handleMoveBackward = () =>
50
+  state.send('MOVED', { type: MoveType.Backward })
51
+const handleMoveForward = () => state.send('MOVED', { type: MoveType.Forward })
52
+const handleMoveToFront = () => state.send('MOVED', { type: MoveType.ToFront })
53
+const handleDelete = () => state.send('DELETED')
54
+
39 55
 export default function StylePanel(): JSX.Element {
40 56
   const rContainer = useRef<HTMLDivElement>(null)
41 57
   const isOpen = useSelector((s) => s.data.settings.isStyleOpen)
42 58
 
43 59
   return (
44
-    <StylePanelRoot ref={rContainer} isOpen={isOpen}>
60
+    <StylePanelRoot dir="ltr" ref={rContainer} isOpen={isOpen}>
45 61
       {isOpen ? (
46 62
         <SelectedShapeStyles />
47 63
       ) : (
@@ -50,10 +66,10 @@ export default function StylePanel(): JSX.Element {
50 66
           <QuickSizeSelect />
51 67
           <QuickdashSelect />
52 68
           <IconButton
53
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
69
+            bp={breakpoints}
54 70
             title="Style"
55 71
             size="small"
56
-            onClick={() => state.send('TOGGLED_STYLE_PANEL_OPEN')}
72
+            onClick={handleStylePanelOpen}
57 73
           >
58 74
             <Tooltip label="More">
59 75
               <ChevronDown />
@@ -99,21 +115,18 @@ function SelectedShapeStyles(): JSX.Element {
99 115
       <Panel.Header side="right">
100 116
         <h3>Style</h3>
101 117
         <IconButton
102
-          bp={{ '@initial': 'mobile', '@sm': 'small' }}
118
+          bp={breakpoints}
103 119
           size="small"
104
-          onClick={() => state.send('TOGGLED_STYLE_PANEL_OPEN')}
120
+          onClick={handleStylePanelOpen}
105 121
         >
106 122
           <X />
107 123
         </IconButton>
108 124
       </Panel.Header>
109 125
       <Content>
110
-        <ColorPicker
111
-          color={commonStyle.color}
112
-          onChange={(color) => state.send('CHANGED_STYLE', { color })}
113
-        />
126
+        <ColorPicker color={commonStyle.color} onChange={handleColorChange} />
114 127
         <IsFilledPicker
115 128
           isFilled={commonStyle.isFilled}
116
-          onChange={(isFilled) => state.send('CHANGED_STYLE', { isFilled })}
129
+          onChange={handleIsFilledChange}
117 130
         />
118 131
         <Row>
119 132
           <label htmlFor="size">Size</label>
@@ -125,10 +138,10 @@ function SelectedShapeStyles(): JSX.Element {
125 138
         </Row>
126 139
         <ButtonsRow>
127 140
           <IconButton
128
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
141
+            bp={breakpoints}
129 142
             disabled={!hasSelection}
130 143
             size="small"
131
-            onClick={() => state.send('DUPLICATED')}
144
+            onClick={handleDuplicate}
132 145
           >
133 146
             <Tooltip label="Duplicate">
134 147
               <CopyIcon />
@@ -138,7 +151,7 @@ function SelectedShapeStyles(): JSX.Element {
138 151
           <IconButton
139 152
             disabled={!hasSelection}
140 153
             size="small"
141
-            onClick={() => state.send('ROTATED_CCW')}
154
+            onClick={handleRotateCcw}
142 155
           >
143 156
             <Tooltip label="Rotate">
144 157
               <RotateCounterClockwiseIcon />
@@ -146,10 +159,10 @@ function SelectedShapeStyles(): JSX.Element {
146 159
           </IconButton>
147 160
 
148 161
           <IconButton
149
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
162
+            bp={breakpoints}
150 163
             disabled={!hasSelection}
151 164
             size="small"
152
-            onClick={() => state.send('TOGGLED_SHAPE_HIDE')}
165
+            onClick={handleHide}
153 166
           >
154 167
             <Tooltip label="Toogle Hidden">
155 168
               {isAllHidden ? <EyeClosedIcon /> : <EyeOpenIcon />}
@@ -157,10 +170,10 @@ function SelectedShapeStyles(): JSX.Element {
157 170
           </IconButton>
158 171
 
159 172
           <IconButton
160
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
173
+            bp={breakpoints}
161 174
             disabled={!hasSelection}
162 175
             size="small"
163
-            onClick={() => state.send('TOGGLED_SHAPE_LOCK')}
176
+            onClick={handleLock}
164 177
           >
165 178
             <Tooltip label="Toogle Locked">
166 179
               {isAllLocked ? <LockClosedIcon /> : <LockOpen1Icon />}
@@ -168,10 +181,10 @@ function SelectedShapeStyles(): JSX.Element {
168 181
           </IconButton>
169 182
 
170 183
           <IconButton
171
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
184
+            bp={breakpoints}
172 185
             disabled={!hasSelection}
173 186
             size="small"
174
-            onClick={() => state.send('TOGGLED_SHAPE_ASPECT_LOCK')}
187
+            onClick={handleAspectLock}
175 188
           >
176 189
             <Tooltip label="Toogle Aspect Ratio Lock">
177 190
               {isAllAspectLocked ? <AspectRatioIcon /> : <BoxIcon />}
@@ -180,10 +193,10 @@ function SelectedShapeStyles(): JSX.Element {
180 193
         </ButtonsRow>
181 194
         <ButtonsRow>
182 195
           <IconButton
183
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
196
+            bp={breakpoints}
184 197
             disabled={!hasSelection}
185 198
             size="small"
186
-            onClick={() => state.send('MOVED', { type: MoveType.ToBack })}
199
+            onClick={handleMoveToBack}
187 200
           >
188 201
             <Tooltip label="Move to Back">
189 202
               <PinBottomIcon />
@@ -191,10 +204,10 @@ function SelectedShapeStyles(): JSX.Element {
191 204
           </IconButton>
192 205
 
193 206
           <IconButton
194
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
207
+            bp={breakpoints}
195 208
             disabled={!hasSelection}
196 209
             size="small"
197
-            onClick={() => state.send('MOVED', { type: MoveType.Backward })}
210
+            onClick={handleMoveBackward}
198 211
           >
199 212
             <Tooltip label="Move Backward">
200 213
               <ArrowDownIcon />
@@ -202,10 +215,10 @@ function SelectedShapeStyles(): JSX.Element {
202 215
           </IconButton>
203 216
 
204 217
           <IconButton
205
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
218
+            bp={breakpoints}
206 219
             disabled={!hasSelection}
207 220
             size="small"
208
-            onClick={() => state.send('MOVED', { type: MoveType.Forward })}
221
+            onClick={handleMoveForward}
209 222
           >
210 223
             <Tooltip label="Move Forward">
211 224
               <ArrowUpIcon />
@@ -213,10 +226,10 @@ function SelectedShapeStyles(): JSX.Element {
213 226
           </IconButton>
214 227
 
215 228
           <IconButton
216
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
229
+            bp={breakpoints}
217 230
             disabled={!hasSelection}
218 231
             size="small"
219
-            onClick={() => state.send('MOVED', { type: MoveType.ToFront })}
232
+            onClick={handleMoveToFront}
220 233
           >
221 234
             <Tooltip label="More to Front">
222 235
               <PinTopIcon />
@@ -224,10 +237,10 @@ function SelectedShapeStyles(): JSX.Element {
224 237
           </IconButton>
225 238
 
226 239
           <IconButton
227
-            bp={{ '@initial': 'mobile', '@sm': 'small' }}
240
+            bp={breakpoints}
228 241
             disabled={!hasSelection}
229 242
             size="small"
230
-            onClick={() => state.send('DELETED')}
243
+            onClick={handleDelete}
231 244
           >
232 245
             <Tooltip label="Delete">
233 246
               <Trash2 size="15" />

Loading…
Cancel
Save