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

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

3
 import styled from 'styles'
3
 import styled from 'styles'
4
 import { getShapeUtils } from 'state/shape-utils'
4
 import { getShapeUtils } from 'state/shape-utils'
5
 import { getPage, getSelectedIds, isMobile } from 'utils'
5
 import { getPage, getSelectedIds, isMobile } from 'utils'
6
-import { Shape as _Shape } from 'types'
7
 import useShapeEvents from 'hooks/useShapeEvents'
6
 import useShapeEvents from 'hooks/useShapeEvents'
7
+import { Shape as _Shape } from 'types'
8
 import vec from 'utils/vec'
8
 import vec from 'utils/vec'
9
 import { getShapeStyle } from 'state/shape-styles'
9
 import { getShapeStyle } from 'state/shape-styles'
10
 
10
 
83
               as="use"
83
               as="use"
84
               href={'#' + id}
84
               href={'#' + id}
85
               strokeWidth={+style.strokeWidth + 5}
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
         (isForeignObject ? (
93
         (isForeignObject ? (
94
           shapeUtils.render(shape, { isEditing, ref: rFocusable })
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
       {isParent &&
99
       {isParent &&
117
 
111
 
118
 interface RealShapeProps {
112
 interface RealShapeProps {
119
   id: string
113
   id: string
120
-  style: Partial<React.SVGProps<SVGUseElement>>
121
-  isParent: boolean
122
   shape: _Shape
114
   shape: _Shape
123
-  isEditing: boolean
115
+  isParent: boolean
124
 }
116
 }
125
 
117
 
126
 const RealShape = memo(function RealShape({ id, isParent }: RealShapeProps) {
118
 const RealShape = memo(function RealShape({ id, isParent }: RealShapeProps) {

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

130
 
130
 
131
   return (
131
   return (
132
     <Panel.Root
132
     <Panel.Root
133
+      dir="ltr"
133
       bp={{ '@initial': 'mobile', '@sm': 'small' }}
134
       bp={{ '@initial': 'mobile', '@sm': 'small' }}
134
       data-bp-desktop
135
       data-bp-desktop
135
       ref={rContainer}
136
       ref={rContainer}

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

18
 
18
 
19
   return (
19
   return (
20
     <Panel.Root
20
     <Panel.Root
21
+      dir="ltr"
21
       data-bp-desktop
22
       data-bp-desktop
22
       ref={rContainer}
23
       ref={rContainer}
23
       isOpen={isOpen}
24
       isOpen={isOpen}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save