@alilc/lowcode-editor-skeleton
Version:
alibaba lowcode editor skeleton
53 lines (51 loc) • 1.54 kB
JavaScript
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _lowcodeEditorCore = require("@alilc/lowcode-editor-core");
var StageChain = exports["default"] = /*#__PURE__*/function () {
function StageChain(stage) {
this.emitter = void 0;
this.stage = void 0;
this.emitter = (0, _lowcodeEditorCore.createModuleEventBus)('StageChain');
this.stage = stage;
}
var _proto = StageChain.prototype;
_proto.stagePush = function stagePush(stage) {
if (!stage) return;
stage.setPrevious(this.stage);
stage.setReferLeft(this.stage);
this.stage = stage;
this.emitter.emit('stagechange');
};
_proto.stageBack = function stageBack() {
var stage = this.stage.getPrevious();
if (!stage) return;
stage.setReferRight(this.stage);
this.stage = stage;
this.emitter.emit('stagechange');
}
/**
* 回到最开始
*/;
_proto.stageBackToRoot = function stageBackToRoot() {
var rootStage = this.stage.getPrevious();
while (rootStage && !rootStage.isRoot) {
rootStage = rootStage.getPrevious();
}
if (!rootStage) return;
rootStage.setReferRight(this.stage);
this.stage = rootStage;
this.emitter.emit('stagechange');
};
_proto.getCurrentStage = function getCurrentStage() {
return this.stage;
};
_proto.onStageChange = function onStageChange(func) {
var _this = this;
this.emitter.on('stagechange', func);
return function () {
_this.emitter.removeListener('stagechange', func);
};
};
return StageChain;
}();