UNPKG

@tencentcloud/roomkit-electron-vue3

Version:

<h1 align="center"> TUIRoomKit</h1> Conference (TUIRoomKit) is a product suitable for multi-person audio and video conversation scenarios such as business meetings, webinars, and online education. By integrating this product, you can add room management,

97 lines (96 loc) 2.98 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { inject } from "vue"; import { ipcRenderer } from "electron"; import bus from "../../../hooks/useMitt.mjs"; import EventEmitter from "../emitter.mjs"; class HistoryManager extends EventEmitter { constructor(canvas) { super(); __publicField(this, "canvas", inject("canvas")); __publicField(this, "step", 0); __publicField(this, "historyList", []); this.canvas = canvas; this.initEvent(); this.setupIpcListeners(); } renderCanvas(data) { if (!this.canvas) return; this.canvas.loadFromJSON(data, () => { var _a; (_a = this.canvas) == null ? void 0 : _a.renderAll(); }); } undo() { bus.emit("exitTextEditing"); if (!this.canvas || this.step === 0) return; this.step = this.step - 1; this.emit("change-step", this.step); this.step === 0 ? this.canvas.clearCanvas() : this.renderCanvas(this.historyList[this.step - 1]); } redo() { if (!this.canvas || this.step >= this.historyList.length) return; const canvasState = this.historyList[this.step]; this.step = this.step + 1; this.emit("change-step", this.step); this.renderCanvas(canvasState); } addToUndoStack() { if (!this.canvas) return; const data = this.canvas.toJSON(); if (this.historyList.length !== this.step) { this.historyList = this.historyList.slice(0, this.step); } this.historyList.push(data); this.emit("change-history", this.historyList.length); this.step = this.historyList.length; this.emit("change-step", this.step); } clearHistoryList() { this.historyList = []; this.step = 0; } isCanvasEmpty() { var _a; return ((_a = this.canvas) == null ? void 0 : _a.getObjects().length) === 0; } clear() { var _a; if (this.isCanvasEmpty() === true) { return; } (_a = this.canvas) == null ? void 0 : _a.clearCanvas(); if (this.historyList.length > 0) { this.addToUndoStack(); } } initEvent() { if (this.canvas) { this.canvas.on("push-canvas-to-stack", this.addToUndoUpdate.bind(this)); } } setupIpcListeners() { ipcRenderer.on( "whiteboard:clear", this.clearHistoryList = this.clearHistoryList.bind(this) ); ipcRenderer.on( "annotation:clear", this.clearHistoryList = this.clearHistoryList.bind(this) ); } addToUndoUpdate() { this.addToUndoStack(); } destroy() { if (this.canvas) { this.canvas.off("push-canvas-to-stack", this.addToUndoUpdate); } ipcRenderer.removeAllListeners("whiteboard:clear"); ipcRenderer.removeAllListeners("annotation:clear"); } } export { HistoryManager as default };