Procházet zdrojové kódy

Updates code to mark isGenerated

main
Steve Ruiz před 4 roky
rodič
revize
71b8ac94af

+ 1
- 1
lib/code/dot.ts Zobrazit soubor

@@ -10,7 +10,7 @@ export default class Dot extends CodeShape<DotShape> {
10 10
     super({
11 11
       id: uuid(),
12 12
       type: ShapeType.Dot,
13
-      isGenerated: false,
13
+      isGenerated: true,
14 14
       name: "Dot",
15 15
       parentId: "page0",
16 16
       childIndex: 0,

+ 1
- 1
lib/code/ellipse.ts Zobrazit soubor

@@ -10,7 +10,7 @@ export default class Ellipse extends CodeShape<EllipseShape> {
10 10
     super({
11 11
       id: uuid(),
12 12
       type: ShapeType.Ellipse,
13
-      isGenerated: false,
13
+      isGenerated: true,
14 14
       name: "Ellipse",
15 15
       parentId: "page0",
16 16
       childIndex: 0,

+ 8
- 5
lib/code/index.ts Zobrazit soubor

@@ -1,5 +1,9 @@
1 1
 import { Shape } from "types"
2
-import { getShapeUtils, ShapeUtility } from "lib/shape-utils"
2
+import shapeUtilityMap, {
3
+  createShape,
4
+  getShapeUtils,
5
+  ShapeUtility,
6
+} from "lib/shape-utils"
3 7
 import * as vec from "utils/vec"
4 8
 import Vector from "./vector"
5 9
 import { vectorToPoint } from "utils/utils"
@@ -12,12 +16,11 @@ export const codeShapes = new Set<CodeShape<Shape>>([])
12 16
  */
13 17
 export default class CodeShape<T extends Shape> {
14 18
   private _shape: T
15
-  private utils: ShapeUtility<Shape>
19
+  private utils: ShapeUtility<T>
16 20
 
17 21
   constructor(props: T) {
18
-    this._shape = props
19
-    this.utils = getShapeUtils(this.shape)
20
-
22
+    this._shape = createShape<T>(props.type, props)
23
+    this.utils = getShapeUtils<T>(this._shape)
21 24
     codeShapes.add(this)
22 25
   }
23 26
 

+ 1
- 1
lib/code/line.ts Zobrazit soubor

@@ -11,7 +11,7 @@ export default class Line extends CodeShape<LineShape> {
11 11
     super({
12 12
       id: uuid(),
13 13
       type: ShapeType.Line,
14
-      isGenerated: false,
14
+      isGenerated: true,
15 15
       name: "Line",
16 16
       parentId: "page0",
17 17
       childIndex: 0,

+ 1
- 1
lib/code/polyline.ts Zobrazit soubor

@@ -11,7 +11,7 @@ export default class Polyline extends CodeShape<PolylineShape> {
11 11
     super({
12 12
       id: uuid(),
13 13
       type: ShapeType.Polyline,
14
-      isGenerated: false,
14
+      isGenerated: true,
15 15
       name: "Polyline",
16 16
       parentId: "page0",
17 17
       childIndex: 0,

+ 1
- 1
lib/code/ray.ts Zobrazit soubor

@@ -11,7 +11,7 @@ export default class Ray extends CodeShape<RayShape> {
11 11
     super({
12 12
       id: uuid(),
13 13
       type: ShapeType.Ray,
14
-      isGenerated: false,
14
+      isGenerated: true,
15 15
       name: "Ray",
16 16
       parentId: "page0",
17 17
       childIndex: 0,

+ 1
- 1
lib/shape-utils/circle.tsx Zobrazit soubor

@@ -1,7 +1,7 @@
1 1
 import { v4 as uuid } from "uuid"
2 2
 import * as vec from "utils/vec"
3 3
 import { CircleShape, ShapeType, Corner, Edge } from "types"
4
-import { registerShapeUtils } from "./index"
4
+import shapeUtilityMap, { registerShapeUtils } from "./index"
5 5
 import { boundsContained } from "utils/bounds"
6 6
 import { intersectCircleBounds } from "utils/intersections"
7 7
 import { pointInCircle } from "utils/hitTests"

+ 4
- 4
lib/shape-utils/index.tsx Zobrazit soubor

@@ -134,11 +134,11 @@ export function registerShapeUtils<T extends Shape>(
134 134
   return Object.freeze(shape)
135 135
 }
136 136
 
137
-export function createShape<T extends ShapeType>(
138
-  type: T,
139
-  props: Partial<ShapeByType<T>>
137
+export function createShape<T extends Shape>(
138
+  type: T["type"],
139
+  props: Partial<T>
140 140
 ) {
141
-  return shapeUtilityMap[type].create(props) as ShapeByType<T>
141
+  return shapeUtilityMap[type].create(props) as T
142 142
 }
143 143
 
144 144
 export default shapeUtilityMap

+ 1
- 1
pages/_document.tsx Zobrazit soubor

@@ -19,7 +19,7 @@ class MyDocument extends NextDocument {
19 19
         ),
20 20
       }
21 21
     } catch (e) {
22
-      console.log(e.message)
22
+      console.error(e.message)
23 23
     } finally {
24 24
     }
25 25
   }

+ 10
- 2
state/state.ts Zobrazit soubor

@@ -72,8 +72,16 @@ const state = createState({
72 72
     SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" },
73 73
     TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel",
74 74
     RESET_CAMERA: "resetCamera",
75
-    ZOOMED_TO_FIT: "zoomCameraToFit",
76
-    ZOOMED_TO_SELECTION: { if: "hasSelection", do: "zoomCameraToSelection" },
75
+    ZOOMED_TO_FIT: {
76
+      if: "hasSelection",
77
+      do: "zoomCameraToFit",
78
+      else: "resetCamera",
79
+    },
80
+    ZOOMED_TO_SELECTION: {
81
+      if: "hasSelection",
82
+      do: "zoomCameraToSelection",
83
+      else: "resetCamera",
84
+    },
77 85
     ZOOMED_TO_ACTUAL: {
78 86
       if: "hasSelection",
79 87
       do: "zoomCameraToSelectionActual",

Načítá se…
Zrušit
Uložit