From 52698ded934996266313befefdf4bfd250339c56 Mon Sep 17 00:00:00 2001 From: Smrtnyk Date: Thu, 26 Dec 2024 22:11:54 +0100 Subject: [PATCH] chore(floor-creator): remove obsolete code in floor-creator Fabric has fixed a bug and we don't need the workaround anymore --- packages/floor-creator/src/CanvasHistory.ts | 8 ++------ packages/floor-creator/src/FloorViewer.ts | 12 ------------ packages/floor-creator/src/TouchManager.ts | 1 - 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/floor-creator/src/CanvasHistory.ts b/packages/floor-creator/src/CanvasHistory.ts index 0feda3e6..29de576a 100644 --- a/packages/floor-creator/src/CanvasHistory.ts +++ b/packages/floor-creator/src/CanvasHistory.ts @@ -2,7 +2,7 @@ import type { FloorEditor } from "./FloorEditor.js"; import type { FabricObject, TFiller } from "fabric"; import { Group } from "fabric"; import { EventEmitter } from "@posva/event-emitter"; -import { isEqual, once } from "es-toolkit"; +import { delay, isEqual, once } from "es-toolkit"; export interface HistoryState { width: number; @@ -240,9 +240,7 @@ export class CanvasHistory extends EventEmitter { }); // Additional wait to ensure all object events have fired - await new Promise((resolve) => { - setTimeout(resolve, 0); - }); + await delay(0); } finally { this.isHistoryProcessing = false; this.emit("stateChange"); @@ -253,11 +251,9 @@ export class CanvasHistory extends EventEmitter { const obj1 = JSON.parse(json1); const obj2 = JSON.parse(json2); - // Normalize the objects by removing irrelevant properties const objects1 = CanvasHistory.normalize(obj1.objects); const objects2 = CanvasHistory.normalize(obj2.objects); - // Compare the normalized objects return isEqual(objects1, objects2); } } diff --git a/packages/floor-creator/src/FloorViewer.ts b/packages/floor-creator/src/FloorViewer.ts index a16c86ba..d491d7a4 100644 --- a/packages/floor-creator/src/FloorViewer.ts +++ b/packages/floor-creator/src/FloorViewer.ts @@ -54,18 +54,6 @@ export class FloorViewer extends Floor { this.eventManager.destroy(); this.zoomManager.destroy(); this.touchManager.destroy(); - // This is an ugly hack to work around the fact that fabric does not clear the mouseDownTimeout - // during dispose. This causes an exception to be thrown if the canvas is disposed while the mouse - // is down. Reported this issue https://github.com/fabricjs/fabric.js/issues/10248 - // @ts-expect-error -- private property - // eslint-disable-next-line no-underscore-dangle -- fabric naming - const mouseDownTimeout = this.canvas._willAddMouseDown; - if (mouseDownTimeout) { - clearTimeout(mouseDownTimeout); - // @ts-expect-error -- private property - // eslint-disable-next-line no-underscore-dangle -- fabric naming - this.canvas._willAddMouseDown = 0; - } await this.canvas.dispose(); } diff --git a/packages/floor-creator/src/TouchManager.ts b/packages/floor-creator/src/TouchManager.ts index ce31a12c..725e1c64 100644 --- a/packages/floor-creator/src/TouchManager.ts +++ b/packages/floor-creator/src/TouchManager.ts @@ -31,7 +31,6 @@ export class TouchManager { const pinch = new Pinch({ enable: true, direction: DIRECTION_ALL }); const pan = new Pan({ direction: DIRECTION_ALL, threshold: 50 }); - // Add the recognizers to the hammerManager instance this.hammerManager.add([pinch, pan, doubleTap]); this.hammerManager.on("pinch", this.onPinch);