UNPKG

@alilc/lowcode-plugin-command

Version:
46 lines (45 loc) 1.87 kB
"use strict"; exports.__esModule = true; exports.historyCommand = void 0; var historyCommand = exports.historyCommand = function historyCommand(ctx) { var command = ctx.command, project = ctx.project; return { init: function init() { command.registerCommand({ name: 'undo', description: 'Undo the last operation.', handler: function handler() { var _project$currentDocum, _project$currentDocum2; var state = ((_project$currentDocum = project.currentDocument) === null || _project$currentDocum === void 0 ? void 0 : _project$currentDocum.history.getState()) || 0; var enable = !!(state & 1); if (!enable) { throw new Error('Can not undo.'); } (_project$currentDocum2 = project.currentDocument) === null || _project$currentDocum2 === void 0 ? void 0 : _project$currentDocum2.history.back(); } }); command.registerCommand({ name: 'redo', description: 'Redo the last operation.', handler: function handler() { var _project$currentDocum3, _project$currentDocum4; var state = ((_project$currentDocum3 = project.currentDocument) === null || _project$currentDocum3 === void 0 ? void 0 : _project$currentDocum3.history.getState()) || 0; var enable = !!(state & 2); if (!enable) { throw new Error('Can not redo.'); } (_project$currentDocum4 = project.currentDocument) === null || _project$currentDocum4 === void 0 ? void 0 : _project$currentDocum4.history.forward(); } }); }, destroy: function destroy() { command.unregisterCommand('history:undo'); command.unregisterCommand('history:redo'); } }; }; historyCommand.pluginName = '___history_command___'; historyCommand.meta = { commandScope: 'history' };