diff --git a/lib/code/dot.ts b/lib/code/dot.ts index d241d3a2b..4d99c1baf 100644 --- a/lib/code/dot.ts +++ b/lib/code/dot.ts @@ -10,7 +10,7 @@ export default class Dot extends CodeShape { super({ id: uuid(), type: ShapeType.Dot, - isGenerated: false, + isGenerated: true, name: "Dot", parentId: "page0", childIndex: 0, diff --git a/lib/code/ellipse.ts b/lib/code/ellipse.ts index 860b6f307..21f9f94a8 100644 --- a/lib/code/ellipse.ts +++ b/lib/code/ellipse.ts @@ -10,7 +10,7 @@ export default class Ellipse extends CodeShape { super({ id: uuid(), type: ShapeType.Ellipse, - isGenerated: false, + isGenerated: true, name: "Ellipse", parentId: "page0", childIndex: 0, diff --git a/lib/code/index.ts b/lib/code/index.ts index c8deb291f..a3bc45293 100644 --- a/lib/code/index.ts +++ b/lib/code/index.ts @@ -1,5 +1,9 @@ import { Shape } from "types" -import { getShapeUtils, ShapeUtility } from "lib/shape-utils" +import shapeUtilityMap, { + createShape, + getShapeUtils, + ShapeUtility, +} from "lib/shape-utils" import * as vec from "utils/vec" import Vector from "./vector" import { vectorToPoint } from "utils/utils" @@ -12,12 +16,11 @@ export const codeShapes = new Set>([]) */ export default class CodeShape { private _shape: T - private utils: ShapeUtility + private utils: ShapeUtility constructor(props: T) { - this._shape = props - this.utils = getShapeUtils(this.shape) - + this._shape = createShape(props.type, props) + this.utils = getShapeUtils(this._shape) codeShapes.add(this) } diff --git a/lib/code/line.ts b/lib/code/line.ts index db8642426..21f402f19 100644 --- a/lib/code/line.ts +++ b/lib/code/line.ts @@ -11,7 +11,7 @@ export default class Line extends CodeShape { super({ id: uuid(), type: ShapeType.Line, - isGenerated: false, + isGenerated: true, name: "Line", parentId: "page0", childIndex: 0, diff --git a/lib/code/polyline.ts b/lib/code/polyline.ts index ff9e7e023..86e0ca799 100644 --- a/lib/code/polyline.ts +++ b/lib/code/polyline.ts @@ -11,7 +11,7 @@ export default class Polyline extends CodeShape { super({ id: uuid(), type: ShapeType.Polyline, - isGenerated: false, + isGenerated: true, name: "Polyline", parentId: "page0", childIndex: 0, diff --git a/lib/code/ray.ts b/lib/code/ray.ts index 3a906a0a3..7e03c1067 100644 --- a/lib/code/ray.ts +++ b/lib/code/ray.ts @@ -11,7 +11,7 @@ export default class Ray extends CodeShape { super({ id: uuid(), type: ShapeType.Ray, - isGenerated: false, + isGenerated: true, name: "Ray", parentId: "page0", childIndex: 0, diff --git a/lib/shape-utils/circle.tsx b/lib/shape-utils/circle.tsx index 4b16533aa..88dd0951f 100644 --- a/lib/shape-utils/circle.tsx +++ b/lib/shape-utils/circle.tsx @@ -1,7 +1,7 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { CircleShape, ShapeType, Corner, Edge } from "types" -import { registerShapeUtils } from "./index" +import shapeUtilityMap, { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectCircleBounds } from "utils/intersections" import { pointInCircle } from "utils/hitTests" diff --git a/lib/shape-utils/index.tsx b/lib/shape-utils/index.tsx index fa7c8728b..d5d5e9f29 100644 --- a/lib/shape-utils/index.tsx +++ b/lib/shape-utils/index.tsx @@ -134,11 +134,11 @@ export function registerShapeUtils( return Object.freeze(shape) } -export function createShape( - type: T, - props: Partial> +export function createShape( + type: T["type"], + props: Partial ) { - return shapeUtilityMap[type].create(props) as ShapeByType + return shapeUtilityMap[type].create(props) as T } export default shapeUtilityMap diff --git a/pages/_document.tsx b/pages/_document.tsx index a3f4a7690..1b56c88ab 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -19,7 +19,7 @@ class MyDocument extends NextDocument { ), } } catch (e) { - console.log(e.message) + console.error(e.message) } finally { } } diff --git a/state/state.ts b/state/state.ts index 5d05d02a8..515e60a9c 100644 --- a/state/state.ts +++ b/state/state.ts @@ -72,8 +72,16 @@ const state = createState({ SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" }, TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel", RESET_CAMERA: "resetCamera", - ZOOMED_TO_FIT: "zoomCameraToFit", - ZOOMED_TO_SELECTION: { if: "hasSelection", do: "zoomCameraToSelection" }, + ZOOMED_TO_FIT: { + if: "hasSelection", + do: "zoomCameraToFit", + else: "resetCamera", + }, + ZOOMED_TO_SELECTION: { + if: "hasSelection", + do: "zoomCameraToSelection", + else: "resetCamera", + }, ZOOMED_TO_ACTUAL: { if: "hasSelection", do: "zoomCameraToSelectionActual",