diff --git a/src/lib/action.ts b/src/lib/action.ts index 54dfb2ea..f06bad7e 100644 --- a/src/lib/action.ts +++ b/src/lib/action.ts @@ -3,6 +3,7 @@ import React from "react"; import { PartialRecord } from "@mehra/ts"; import AssertType from "../types/assert"; +import { FabricTeXImage } from "../types/fabric"; import { Tool, Tools } from "./tools"; import Pages from "./pages"; @@ -237,10 +238,10 @@ More details printed to console.` return "invalid latex"; } - const img = await this.canvas.addImage( + const img: FabricTeXImage = await this.canvas.addImage( dataURL, {}, - { scaleX: 3, scaleY: 3 } + { scaleX: 3, scaleY: 3, data: { texSource: text } } ); this.history.add([img]); diff --git a/src/lib/page.ts b/src/lib/page.ts index 3e5747c4..85b1488d 100644 --- a/src/lib/page.ts +++ b/src/lib/page.ts @@ -71,7 +71,7 @@ export default class Page extends fabric.Canvas { // and https://github.com/cjquines/qboard/issues/176 // for more details. // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this as any)._toObject(obj, "toObject", ["strokeUniform"]) + (this as any)._toObject(obj, "toObject", ["data", "strokeUniform"]) ); }; diff --git a/src/lib/pages.ts b/src/lib/pages.ts index 189cfd10..ea2317c5 100644 --- a/src/lib/pages.ts +++ b/src/lib/pages.ts @@ -42,6 +42,7 @@ export default class Pages { savePage = (): void => { this.pagesJSON[this.currentIndex] = this.canvas.toObject([ "id", + "data", "strokeUniform", ]); }; diff --git a/src/types/fabric.ts b/src/types/fabric.ts index 1724c731..d1d292a2 100644 --- a/src/types/fabric.ts +++ b/src/types/fabric.ts @@ -36,3 +36,13 @@ export function isFabricCollection( ): obj is fabric.Object & fabric.ICollection { return "_objects" in obj; } + +export interface FabricTeXImage extends fabric.Image { + data: { + texSource: string; + }; +} + +export function isFabricTeXImage(image: fabric.Image): image is FabricTeXImage { + return typeof image?.data?.texSource === "string"; +}