![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-form/js/editor/ |
Upload File : |
import FCore from "../core/FCore"; import EventEmitter from "absol/src/HTML5/EventEmitter"; import Context from "absol/src/AppPattern/Context"; import '../../css/undohistory.css'; import R from "../R"; import BaseEditor from "../core/BaseEditor"; import Dom from "absol/src/HTML5/Dom"; import WindowManager from "../dom/WindowManager"; var _ = FCore._; var $ = FCore.$; function UndoHistory() { BaseEditor.call(this); this._lastPosition = undefined; this.items = []; this.lastItemIndex = this.items.length - 1; } Object.defineProperties(UndoHistory.prototype, Object.getOwnPropertyDescriptors(BaseEditor.prototype)); UndoHistory.prototype.constructor = UndoHistory; UndoHistory.prototype.CONFIG_STORE_KEY = "AS_UndoHistory_config"; UndoHistory.prototype.config = { windowStyle: { left: '57px', top: Dom.getScreenSize().height - 230 + 'px' } }; UndoHistory.prototype.getView = function () { if (this.$view) return this.$view; this.$view = _({ attr: { tabIndex: '1' }, class: ['as-undo-history'], child: [ { class: 'as-undo-history-header-name', child: { tag: 'span', child: { text: 'History' } } }, { class: 'as-undo-history-active-buttons', child: [ { tag: 'button', class: 'as-undo-history-active-undo', attr: { title: 'Undo' }, props: { disabled: true }, child: 'span.mdi.mdi-undo' }, { tag: 'button', class: 'as-undo-history-active-redo', attr: { title: 'Redo' }, props: { disabled: true }, child: 'span.mdi.mdi-redo' }, { class: 'as-undo-history-active-buttons-right-container', child: { tag: 'button', attr: { title: 'Clear' }, class: 'as-undo-history-active-clear', child: 'span.mdi.mdi-delete' } } ] }, { tag: 'bscroller', class: ['as-undo-history-item-list'], child: this.items.map(function (item) { return item.getView() }) } ], on: { keydown: this.ev_cmdKeyDown.bind(this) } }); this.$list = $('.as-undo-history-item-list', this.$view); this.$undoBtn = $('button.as-undo-history-active-undo', this.$view) .on('click', this.undo.bind(this)); this.$redoBtn = $('button.as-undo-history-active-redo', this.$view) .on('click', this.redo.bind(this)); this.$clear = $('button.as-undo-history-active-clear', this.$view) .on('click', this.clear.bind(this)); return this.$view; }; UndoHistory.prototype.checkout = function (item, viewOnly) { var cItem; var found = false; for (var i = this.items.length - 1; i >= 0; --i) { cItem = this.items[i]; if (cItem == item) { cItem.setActive(true); found = true; this.lastItemIndex = i; } else { cItem.setActive(false); } cItem.setDisabled(!found); } this.$list.scrollInto(item.getView()); this.$undoBtn.disabled = this.lastItemIndex <= 0; this.$redoBtn.disabled = this.lastItemIndex >= this.items.length - 1; if (!viewOnly) this.emit('checkout', { type: 'checkout', target: this, item: item }, this); }; UndoHistory.prototype.undo = function () { if (this.lastItemIndex > 0) { this.checkout(this.items[this.lastItemIndex - 1]); } }; UndoHistory.prototype.redo = function () { if (this.lastItemIndex < this.items.length - 1) { this.checkout(this.items[this.lastItemIndex + 1]); } } /** * @param {String} type * @param {*} data * @param {String} description * @param {Date} timestamp */ UndoHistory.prototype.commit = function (type, data, description, timestamp) { var item; while (this.items.length > this.lastItemIndex + 1) { item = this.items.pop(); item.getView().remove(); } var res = new UndoHistoryItem(this, type, data, description, timestamp); this.items.push(res); this.$list.addChild(res.getView()); this.checkout(res, true); return res; }; UndoHistory.prototype.clear = function () { if (this.items.length < 2) return; var lastItem = this.items.pop(); var lastData = lastItem.data; lastItem.getView().remove(); while (this.items.length > 0) { lastItem = this.items.pop(); lastItem.getView().remove(); } this.commit('clear', lastData, 'Clear History'); } UndoHistory.prototype.renew = function () { var lastItem; while (this.items.length > 0) { lastItem = this.items.pop(); lastItem.getView().remove(); } }; UndoHistory.prototype.ev_cmdKeyDown = function (event) { this.editor && this.editor.ev_cmdKeyDown(event); }; /** * @param {UndoHistory}parent * @param {String} type * @param {*} data * @param {String} description * @param {Date} timestamp */ export function UndoHistoryItem(parent, type, data, description, timestamp) { this.parent = parent; this.type = type || 'edit'; this.data = data; this.description = description || 'Change'; this.timestamp = timestamp || new Date(); this._active = false; this._disabled = false; } UndoHistoryItem.prototype.typeIcon = { move: 'span.mdi.mdi-move-resize', remove: 'span.mdi.mdi-delete-variant[style="color: rgb(255,59,59)"]', 'edit-attribute': 'span.mdi.mdi-circle-edit-outline', edit: 'span.mdi.mdi-circle-edit-outline', add: 'span.mdi.mdi-pen-plus', 'set-data': 'span.mdi.mdi-open-in-app', 'move-resize': 'span.mdi.mdi-move-resize', 'move-order': 'span.mdi.mdi-arrow-up-down-bold', 'clear': 'span.mdi.mdi-check-outline', 'cut': 'span.mdi.mdi-content-cut' }; UndoHistoryItem.prototype.setActive = function (bool) { this._active = !!bool; if (this.$view) { if (bool) { this.$view.addClass('as-undo-history-item-active'); } else { this.$view.removeClass('as-undo-history-item-active'); } } }; UndoHistoryItem.prototype.setDisabled = function (bool) { this._disabled = !!bool; if (this.$view) { if (bool) { this.$view.addClass('as-undo-history-item-disabled'); } else { this.$view.removeClass('as-undo-history-item-disabled'); } } }; UndoHistoryItem.prototype.getActive = function () { return this._active; }; UndoHistoryItem.prototype.getView = function () { if (this.$view) return this.$view; this.$view = _({ class: ['as-undo-history-item'].concat(this._active ? ['as-undo-history-item-active'] : []).concat(this._disabled ? ['as-undo-history-item-disabled'] : []), attr: { title: this.timestamp.toLocaleTimeString() }, child: [ { class: 'as-undo-history-item-icon-container', child: this.typeIcon[this.type] }, { text: this.description } ], on: { click: this.ev_click.bind(this) } }); return this.$view; }; UndoHistoryItem.prototype.ev_click = function (event) { this.parent.checkout(this); }; export default UndoHistory;