Pārlūkot izejas kodu

Improves behavior with locked shapes

main
Steve Ruiz 4 gadus atpakaļ
vecāks
revīzija
b0a260d6a6

+ 0
- 11
hooks/useZoomEvents.ts Parādīt failu

@@ -20,10 +20,6 @@ export default function useZoomEvents() {
20 20
         if (event.ctrlKey) {
21 21
           const { point } = inputs.wheel(event as WheelEvent)
22 22
           fastZoomUpdate(point, delta[1])
23
-          // state.send('ZOOMED_CAMERA', {
24
-          //   delta: delta[1],
25
-          //   ...inputs.wheel(event as WheelEvent),
26
-          // })
27 23
           return
28 24
         }
29 25
 
@@ -60,13 +56,6 @@ export default function useZoomEvents() {
60 56
           angleDelta
61 57
         )
62 58
 
63
-        // state.send('PINCHED', {
64
-        //   delta: vec.sub(rPinchPoint.current, origin),
65
-        //   point: origin,
66
-        //   distanceDelta,
67
-        //   angleDelta,
68
-        // })
69
-
70 59
         rPinchDa.current = da
71 60
         rPinchPoint.current = origin
72 61
       },

+ 3
- 16
lib/shape-utils/arrow.tsx Parādīt failu

@@ -1,7 +1,6 @@
1 1
 import { uniqueId } from 'utils/utils'
2 2
 import vec from 'utils/vec'
3 3
 import {
4
-  ease,
5 4
   getSvgPathFromStroke,
6 5
   rng,
7 6
   getBoundsFromPoints,
@@ -151,18 +150,7 @@ const arrow = registerShapeUtils<ArrowShape>({
151 150
       body = <path d={path} />
152 151
     }
153 152
 
154
-    return (
155
-      <g id={id}>
156
-        {body}
157
-        {/* <circle
158
-          cx={start.point[0]}
159
-          cy={start.point[1]}
160
-          r={Math.max(4, +style.strokeWidth)}
161
-          fill={style.stroke}
162
-          strokeDasharray="none"
163
-        /> */}
164
-      </g>
165
-    )
153
+    return <g id={id}>{body}</g>
166 154
   },
167 155
 
168 156
   rotateBy(shape, delta) {
@@ -379,7 +367,7 @@ function getBendPoint(shape: ArrowShape) {
379 367
 
380 368
   const dist = vec.dist(start.point, end.point)
381 369
   const midPoint = vec.med(start.point, end.point)
382
-  const bendDist = (dist / 2) * shape.bend * Math.min(1, dist / 128)
370
+  const bendDist = (dist / 2) * shape.bend
383 371
   const u = vec.uni(vec.vec(start.point, end.point))
384 372
 
385 373
   return Math.abs(bendDist) < 10
@@ -430,10 +418,9 @@ function getResizeOffset(a: Bounds, b: Bounds) {
430 418
 
431 419
 function renderPath(shape: ArrowShape, endAngle = 0) {
432 420
   const { style, id } = shape
433
-  const { start, end, bend } = shape.handles
421
+  const { start, end } = shape.handles
434 422
 
435 423
   const getRandom = rng(id)
436
-  const offsetA = getRandom()
437 424
 
438 425
   const strokeWidth = +getShapeStyle(style).strokeWidth * 2
439 426
 

+ 11
- 4
state/commands/delete-selected.ts Parādīt failu

@@ -5,7 +5,9 @@ import { Data, ShapeType } from 'types'
5 5
 import {
6 6
   getDocumentBranch,
7 7
   getPage,
8
+  getPageState,
8 9
   getSelectedIds,
10
+  getSelectedShapes,
9 11
   setSelectedIds,
10 12
   setToArray,
11 13
   updateParents,
@@ -16,8 +18,11 @@ import { getShapeUtils } from 'lib/shape-utils'
16 18
 export default function deleteSelected(data: Data) {
17 19
   const { currentPageId } = data
18 20
 
19
-  const selectedIds = getSelectedIds(data)
20
-  const selectedIdsArr = setToArray(selectedIds)
21
+  const selectedShapes = getSelectedShapes(data)
22
+
23
+  const selectedIdsArr = selectedShapes
24
+    .filter((shape) => !shape.isLocked)
25
+    .map((shape) => shape.id)
21 26
 
22 27
   const page = getPage(current(data))
23 28
 
@@ -25,7 +30,9 @@ export default function deleteSelected(data: Data) {
25 30
     .flatMap((id) => getDocumentBranch(data, id))
26 31
     .map((id) => page.shapes[id])
27 32
 
28
-  selectedIds.clear()
33
+  const remainingIds = selectedShapes
34
+    .filter((shape) => shape.isLocked)
35
+    .map((shape) => shape.id)
29 36
 
30 37
   history.execute(
31 38
     data,
@@ -62,7 +69,7 @@ export default function deleteSelected(data: Data) {
62 69
           delete page.shapes[shape.id]
63 70
         }
64 71
 
65
-        setSelectedIds(data, [])
72
+        setSelectedIds(data, remainingIds)
66 73
       },
67 74
       undo(data) {
68 75
         const page = getPage(data, currentPageId)

+ 3
- 1
state/commands/distribute.ts Parādīt failu

@@ -12,7 +12,9 @@ import { getShapeUtils } from 'lib/shape-utils'
12 12
 export default function distributeCommand(data: Data, type: DistributeType) {
13 13
   const { currentPageId } = data
14 14
 
15
-  const selectedShapes = getSelectedShapes(data)
15
+  const selectedShapes = getSelectedShapes(data).filter(
16
+    (shape) => !shape.isLocked
17
+  )
16 18
 
17 19
   const entries = selectedShapes.map(
18 20
     (shape) => [shape.id, getShapeUtils(shape).getBounds(shape)] as const

+ 1
- 1
state/commands/edit.ts Parādīt failu

@@ -15,7 +15,7 @@ export default function handleCommand(
15 15
     new Command({
16 16
       name: 'edited_shape',
17 17
       category: 'canvas',
18
-      do(data, isInitial) {
18
+      do(data) {
19 19
         const { initialShape, currentPageId } = after
20 20
 
21 21
         const page = getPage(data, currentPageId)

+ 2
- 0
state/commands/reset-bounds.ts Parādīt failu

@@ -17,6 +17,7 @@ export default function resetBoundsCommand(data: Data) {
17 17
       category: 'canvas',
18 18
       do(data) {
19 19
         getSelectedShapes(data).forEach((shape) => {
20
+          if (shape.isLocked) return
20 21
           getShapeUtils(shape).onBoundsReset(shape)
21 22
         })
22 23
 
@@ -25,6 +26,7 @@ export default function resetBoundsCommand(data: Data) {
25 26
       undo(data) {
26 27
         const page = getPage(data)
27 28
         getSelectedShapes(data).forEach((shape) => {
29
+          if (shape.isLocked) return
28 30
           page.shapes[shape.id] = initialShapes[shape.id]
29 31
         })
30 32
 

+ 4
- 0
state/commands/rotate-ccw.ts Parādīt failu

@@ -67,6 +67,7 @@ export default function rotateCcwCommand(data: Data) {
67 67
 
68 68
         for (let id in nextShapes) {
69 69
           const shape = shapes[id]
70
+          if (shape.isLocked) continue
70 71
 
71 72
           getShapeUtils(shape)
72 73
             .setProperty(shape, 'rotation', nextShapes[id].rotation)
@@ -82,6 +83,9 @@ export default function rotateCcwCommand(data: Data) {
82 83
           const { point, rotation } = initialShapes[id]
83 84
 
84 85
           const shape = shapes[id]
86
+
87
+          if (shape.isLocked) continue
88
+
85 89
           const utils = getShapeUtils(shape)
86 90
           utils
87 91
             .setProperty(shape, 'rotation', rotation)

+ 1
- 1
state/commands/toggle.ts Parādīt failu

@@ -19,7 +19,7 @@ export default function toggleCommand(
19 19
   history.execute(
20 20
     data,
21 21
     new Command({
22
-      name: 'hide_shapes',
22
+      name: 'toggle_shape_prop',
23 23
       category: 'canvas',
24 24
       do(data) {
25 25
         const { shapes } = getPage(data, currentPageId)

+ 1
- 1
state/state.ts Parādīt failu

@@ -911,7 +911,7 @@ const state = createState({
911 911
       return data.isReadOnly
912 912
     },
913 913
     canEditSelectedShape(data, payload, result: Shape) {
914
-      return getShapeUtils(result).canEdit
914
+      return getShapeUtils(result).canEdit && !result.isLocked
915 915
     },
916 916
     distanceImpliesDrag(data, payload: PointerInfo) {
917 917
       return vec.dist2(payload.origin, payload.point) > 8

Notiek ielāde…
Atcelt
Saglabāt