瀏覽代碼

Improves bounds corner touch targets on mobile

main
Steve Ruiz 4 年之前
父節點
當前提交
03d0eadb6e

+ 1
- 1
components/canvas/bounds/bounding-box.tsx 查看文件

@@ -28,7 +28,7 @@ export default function Bounds() {
28 28
   if (!bounds) return null
29 29
   if (!isSelecting) return null
30 30
 
31
-  const size = (isMobile().any ? 12 : 8) / zoom // Touch target size
31
+  const size = (isMobile().any ? 10 : 8) / zoom // Touch target size
32 32
 
33 33
   return (
34 34
     <g

+ 33
- 19
components/canvas/bounds/corner-handle.tsx 查看文件

@@ -1,6 +1,6 @@
1
-import useHandleEvents from "hooks/useBoundsHandleEvents"
2
-import styled from "styles"
3
-import { Corner, Bounds } from "types"
1
+import useHandleEvents from 'hooks/useBoundsHandleEvents'
2
+import styled from 'styles'
3
+import { Corner, Bounds } from 'types'
4 4
 
5 5
 export default function CornerHandle({
6 6
   size,
@@ -17,27 +17,41 @@ export default function CornerHandle({
17 17
   const isLeft = corner === Corner.TopLeft || corner === Corner.BottomLeft
18 18
 
19 19
   return (
20
-    <StyledCorner
21
-      corner={corner}
22
-      x={(isLeft ? 0 : bounds.width) - size / 2}
23
-      y={(isTop ? 0 : bounds.height) - size / 2}
24
-      width={size}
25
-      height={size}
26
-      {...events}
27
-    />
20
+    <g>
21
+      <StyledCorner
22
+        corner={corner}
23
+        x={(isLeft ? 0 : bounds.width) - size}
24
+        y={(isTop ? 0 : bounds.height) - size}
25
+        width={size * 2}
26
+        height={size * 2}
27
+        {...events}
28
+      />
29
+      <StyledCornerInner
30
+        x={(isLeft ? 0 : bounds.width) - size / 2}
31
+        y={(isTop ? 0 : bounds.height) - size / 2}
32
+        width={size}
33
+        height={size}
34
+        pointerEvents="none"
35
+      />
36
+    </g>
28 37
   )
29 38
 }
30 39
 
31
-const StyledCorner = styled("rect", {
32
-  stroke: "$bounds",
33
-  fill: "#fff",
34
-  zStrokeWidth: 2,
40
+const StyledCorner = styled('rect', {
41
+  stroke: 'none',
42
+  fill: 'transparent',
35 43
   variants: {
36 44
     corner: {
37
-      [Corner.TopLeft]: { cursor: "nwse-resize" },
38
-      [Corner.TopRight]: { cursor: "nesw-resize" },
39
-      [Corner.BottomRight]: { cursor: "nwse-resize" },
40
-      [Corner.BottomLeft]: { cursor: "nesw-resize" },
45
+      [Corner.TopLeft]: { cursor: 'nwse-resize' },
46
+      [Corner.TopRight]: { cursor: 'nesw-resize' },
47
+      [Corner.BottomRight]: { cursor: 'nwse-resize' },
48
+      [Corner.BottomLeft]: { cursor: 'nesw-resize' },
41 49
     },
42 50
   },
43 51
 })
52
+
53
+const StyledCornerInner = styled('rect', {
54
+  stroke: '$bounds',
55
+  fill: '#fff',
56
+  zStrokeWidth: 2,
57
+})

+ 10
- 10
components/canvas/bounds/edge-handle.tsx 查看文件

@@ -1,6 +1,6 @@
1
-import useHandleEvents from "hooks/useBoundsHandleEvents"
2
-import styled from "styles"
3
-import { Edge, Bounds } from "types"
1
+import useHandleEvents from 'hooks/useBoundsHandleEvents'
2
+import styled from 'styles'
3
+import { Edge, Bounds } from 'types'
4 4
 
5 5
 export default function EdgeHandle({
6 6
   size,
@@ -28,15 +28,15 @@ export default function EdgeHandle({
28 28
   )
29 29
 }
30 30
 
31
-const StyledEdge = styled("rect", {
32
-  stroke: "none",
33
-  fill: "none",
31
+const StyledEdge = styled('rect', {
32
+  stroke: 'none',
33
+  fill: 'none',
34 34
   variants: {
35 35
     edge: {
36
-      [Edge.Top]: { cursor: "ns-resize" },
37
-      [Edge.Right]: { cursor: "ew-resize" },
38
-      [Edge.Bottom]: { cursor: "ns-resize" },
39
-      [Edge.Left]: { cursor: "ew-resize" },
36
+      [Edge.Top]: { cursor: 'ns-resize' },
37
+      [Edge.Right]: { cursor: 'ew-resize' },
38
+      [Edge.Bottom]: { cursor: 'ns-resize' },
39
+      [Edge.Left]: { cursor: 'ew-resize' },
40 40
     },
41 41
   },
42 42
 })

+ 26
- 26
components/code-panel/code-editor.tsx 查看文件

@@ -1,11 +1,11 @@
1
-import Editor, { Monaco } from "@monaco-editor/react"
2
-import useTheme from "hooks/useTheme"
3
-import prettier from "prettier/standalone"
4
-import parserTypeScript from "prettier/parser-typescript"
5
-import codeAsString from "./code-as-string"
6
-import React, { useCallback, useEffect, useRef } from "react"
7
-import styled from "styles"
8
-import { IMonaco, IMonacoEditor } from "types"
1
+import Editor, { Monaco } from '@monaco-editor/react'
2
+import useTheme from 'hooks/useTheme'
3
+import prettier from 'prettier/standalone'
4
+import parserTypeScript from 'prettier/parser-typescript'
5
+import codeAsString from './code-as-string'
6
+import React, { useCallback, useEffect, useRef } from 'react'
7
+import styled from 'styles'
8
+import { IMonaco, IMonacoEditor } from 'types'
9 9
 
10 10
 interface Props {
11 11
   value: string
@@ -48,7 +48,7 @@ export default function CodeEditor({
48 48
       checkJs: false,
49 49
       strict: false,
50 50
       noLib: true,
51
-      lib: ["es6"],
51
+      lib: ['es6'],
52 52
       target: monaco.languages.typescript.ScriptTarget.ES2015,
53 53
       allowNonTsExtensions: true,
54 54
     })
@@ -69,13 +69,13 @@ export default function CodeEditor({
69 69
 
70 70
     monaco.languages.typescript.javascriptDefaults.addExtraLib(codeAsString)
71 71
 
72
-    monaco.languages.registerDocumentFormattingEditProvider("javascript", {
72
+    monaco.languages.registerDocumentFormattingEditProvider('javascript', {
73 73
       async provideDocumentFormattingEdits(model) {
74 74
         const text = prettier.format(model.getValue(), {
75
-          parser: "typescript",
75
+          parser: 'typescript',
76 76
           plugins: [parserTypeScript],
77 77
           singleQuote: true,
78
-          trailingComma: "es5",
78
+          trailingComma: 'es5',
79 79
           semi: false,
80 80
         })
81 81
 
@@ -114,12 +114,12 @@ export default function CodeEditor({
114 114
     (e: React.KeyboardEvent<HTMLDivElement>) => {
115 115
       onKey && onKey()
116 116
       e.stopPropagation()
117
-      const metaKey = navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey
118
-      if (e.key === "s" && metaKey) {
117
+      const metaKey = navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey
118
+      if (e.key === 's' && metaKey) {
119 119
         const editor = rEditor.current
120 120
         if (!editor) return
121 121
         editor
122
-          .getAction("editor.action.formatDocument")
122
+          .getAction('editor.action.formatDocument')
123 123
           .run()
124 124
           .then(() =>
125 125
             onSave(rEditor.current?.getModel().getValue(), rEditor.current)
@@ -127,10 +127,10 @@ export default function CodeEditor({
127 127
 
128 128
         e.preventDefault()
129 129
       }
130
-      if (e.key === "p" && metaKey) {
130
+      if (e.key === 'p' && metaKey) {
131 131
         e.preventDefault()
132 132
       }
133
-      if (e.key === "d" && metaKey) {
133
+      if (e.key === 'd' && metaKey) {
134 134
         e.preventDefault()
135 135
       }
136 136
     },
@@ -167,7 +167,7 @@ export default function CodeEditor({
167 167
         ),
168 168
         options: {
169 169
           isWholeLine: true,
170
-          className: "editorLineError",
170
+          className: 'editorLineError',
171 171
         },
172 172
       },
173 173
     ])
@@ -176,7 +176,7 @@ export default function CodeEditor({
176 176
   useEffect(() => {
177 177
     const monaco = rMonaco.current
178 178
     if (!monaco) return
179
-    monaco.editor.setTheme(theme === "dark" ? "vs-dark" : "light")
179
+    monaco.editor.setTheme(theme === 'dark' ? 'vs-dark' : 'light')
180 180
   }, [theme])
181 181
 
182 182
   useEffect(() => {
@@ -194,7 +194,7 @@ export default function CodeEditor({
194 194
         height="100%"
195 195
         language="javascript"
196 196
         value={value}
197
-        theme={theme === "dark" ? "vs-dark" : "light"}
197
+        theme={theme === 'dark' ? 'vs-dark' : 'light'}
198 198
         beforeMount={handleBeforeMount}
199 199
         onMount={handleMount}
200 200
         onChange={handleChange}
@@ -203,12 +203,12 @@ export default function CodeEditor({
203 203
   )
204 204
 }
205 205
 
206
-const EditorContainer = styled("div", {
207
-  height: "100%",
208
-  pointerEvents: "all",
209
-  userSelect: "all",
206
+const EditorContainer = styled('div', {
207
+  height: '100%',
208
+  pointerEvents: 'all',
209
+  userSelect: 'all',
210 210
 
211
-  ".editorLineError": {
212
-    backgroundColor: "$lineError",
211
+  '.editorLineError': {
212
+    backgroundColor: '$lineError',
213 213
   },
214 214
 })

+ 9
- 7
components/editor.tsx 查看文件

@@ -40,9 +40,11 @@ const Layout = styled('div', {
40 40
   left: 0,
41 41
   bottom: 0,
42 42
   right: 0,
43
+  height: '100%',
44
+  width: '100%',
43 45
   display: 'grid',
44
-  gridTemplateRows: '1fr auto 40px',
45
-  gridTemplateColumns: 'minmax(50%, 400px) 1fr auto',
46
+  gridTemplateRows: '1fr auto 144px',
47
+  gridTemplateColumns: 'minmax(0, 720px) 1fr auto',
46 48
   gridTemplateAreas: `
47 49
     "leftPanels main rightPanels"
48 50
     "tools tools tools"
@@ -59,11 +61,11 @@ const LeftPanels = styled('main', {
59 61
 })
60 62
 
61 63
 const RightPanels = styled('main', {
62
-  display: 'grid',
63 64
   gridArea: 'rightPanels',
64
-  gridTemplateRows: 'auto',
65
-  height: 'fit-content',
66
-  justifyContent: 'flex-end',
67 65
   padding: 8,
68
-  gap: 8,
66
+  // display: 'grid',
67
+  // gridTemplateRows: 'auto',
68
+  // height: 'fit-content',
69
+  // justifyContent: 'flex-end',
70
+  // gap: 8,
69 71
 })

+ 1
- 4
components/panel.tsx 查看文件

@@ -13,10 +13,7 @@ export const Root = styled('div', {
13 13
 
14 14
   variants: {
15 15
     isOpen: {
16
-      true: {
17
-        width: 'auto',
18
-        minWidth: 300,
19
-      },
16
+      true: {},
20 17
       false: {
21 18
         height: 34,
22 19
         width: 34,

Loading…
取消
儲存