Parcourir la source

Updates code to mark isGenerated

main
Steve Ruiz il y a 4 ans
Parent
révision
71b8ac94af

+ 1
- 1
lib/code/dot.ts Voir le fichier

10
     super({
10
     super({
11
       id: uuid(),
11
       id: uuid(),
12
       type: ShapeType.Dot,
12
       type: ShapeType.Dot,
13
-      isGenerated: false,
13
+      isGenerated: true,
14
       name: "Dot",
14
       name: "Dot",
15
       parentId: "page0",
15
       parentId: "page0",
16
       childIndex: 0,
16
       childIndex: 0,

+ 1
- 1
lib/code/ellipse.ts Voir le fichier

10
     super({
10
     super({
11
       id: uuid(),
11
       id: uuid(),
12
       type: ShapeType.Ellipse,
12
       type: ShapeType.Ellipse,
13
-      isGenerated: false,
13
+      isGenerated: true,
14
       name: "Ellipse",
14
       name: "Ellipse",
15
       parentId: "page0",
15
       parentId: "page0",
16
       childIndex: 0,
16
       childIndex: 0,

+ 8
- 5
lib/code/index.ts Voir le fichier

1
 import { Shape } from "types"
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
 import * as vec from "utils/vec"
7
 import * as vec from "utils/vec"
4
 import Vector from "./vector"
8
 import Vector from "./vector"
5
 import { vectorToPoint } from "utils/utils"
9
 import { vectorToPoint } from "utils/utils"
12
  */
16
  */
13
 export default class CodeShape<T extends Shape> {
17
 export default class CodeShape<T extends Shape> {
14
   private _shape: T
18
   private _shape: T
15
-  private utils: ShapeUtility<Shape>
19
+  private utils: ShapeUtility<T>
16
 
20
 
17
   constructor(props: T) {
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
     codeShapes.add(this)
24
     codeShapes.add(this)
22
   }
25
   }
23
 
26
 

+ 1
- 1
lib/code/line.ts Voir le fichier

11
     super({
11
     super({
12
       id: uuid(),
12
       id: uuid(),
13
       type: ShapeType.Line,
13
       type: ShapeType.Line,
14
-      isGenerated: false,
14
+      isGenerated: true,
15
       name: "Line",
15
       name: "Line",
16
       parentId: "page0",
16
       parentId: "page0",
17
       childIndex: 0,
17
       childIndex: 0,

+ 1
- 1
lib/code/polyline.ts Voir le fichier

11
     super({
11
     super({
12
       id: uuid(),
12
       id: uuid(),
13
       type: ShapeType.Polyline,
13
       type: ShapeType.Polyline,
14
-      isGenerated: false,
14
+      isGenerated: true,
15
       name: "Polyline",
15
       name: "Polyline",
16
       parentId: "page0",
16
       parentId: "page0",
17
       childIndex: 0,
17
       childIndex: 0,

+ 1
- 1
lib/code/ray.ts Voir le fichier

11
     super({
11
     super({
12
       id: uuid(),
12
       id: uuid(),
13
       type: ShapeType.Ray,
13
       type: ShapeType.Ray,
14
-      isGenerated: false,
14
+      isGenerated: true,
15
       name: "Ray",
15
       name: "Ray",
16
       parentId: "page0",
16
       parentId: "page0",
17
       childIndex: 0,
17
       childIndex: 0,

+ 1
- 1
lib/shape-utils/circle.tsx Voir le fichier

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

+ 4
- 4
lib/shape-utils/index.tsx Voir le fichier

134
   return Object.freeze(shape)
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
 export default shapeUtilityMap
144
 export default shapeUtilityMap

+ 1
- 1
pages/_document.tsx Voir le fichier

19
         ),
19
         ),
20
       }
20
       }
21
     } catch (e) {
21
     } catch (e) {
22
-      console.log(e.message)
22
+      console.error(e.message)
23
     } finally {
23
     } finally {
24
     }
24
     }
25
   }
25
   }

+ 10
- 2
state/state.ts Voir le fichier

72
     SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" },
72
     SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" },
73
     TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel",
73
     TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel",
74
     RESET_CAMERA: "resetCamera",
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
     ZOOMED_TO_ACTUAL: {
85
     ZOOMED_TO_ACTUAL: {
78
       if: "hasSelection",
86
       if: "hasSelection",
79
       do: "zoomCameraToSelectionActual",
87
       do: "zoomCameraToSelectionActual",

Chargement…
Annuler
Enregistrer