@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) • 3.15 kB
JavaScript
"use strict";
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);
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const electron = require("electron");
const useMitt = require("../../../hooks/useMitt.js");
const emitter = require("../emitter.js");
class HistoryManager extends emitter.default {
constructor(canvas) {
super();
__publicField(this, "canvas", Vue.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() {
useMitt.default.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() {
electron.ipcRenderer.on(
"whiteboard:clear",
this.clearHistoryList = this.clearHistoryList.bind(this)
);
electron.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);
}
electron.ipcRenderer.removeAllListeners("whiteboard:clear");
electron.ipcRenderer.removeAllListeners("annotation:clear");
}
}
exports.default = HistoryManager;