![]() 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/ciruiteditor/lineeditor/ |
Upload File : |
import OOP from "absol/src/HTML5/OOP"; import BaseEditor from "../../core/BaseEditor"; import {$, _} from "../../core/FCore"; import '../../../css/lineeditor.css'; import R from '../../R'; import CMDTool from "../../fragment/CMDTool"; import ClipboardManager from "../../ClipboardManager"; import BoardTable from "absol-acomp/js/BoardTable"; import LineEditorCmd, {LineEditorCmdDescriptors, LineEditorCmdTree} from "./LineEditorCmd"; import LELine from "./LELine"; import {traversal} from "../../core/FNode"; import BaseBlock from "../../core/BaseBlock"; import {AssemblerInstance} from "../../core/Assembler"; `` function LineEditor() { BaseEditor.call(this); /** * * @type {LELine[]} */ this.lines = []; /** * * @type {LELine[]} */ this.activatedLines = []; this.cmdRunner.assign(LineEditorCmd); this.CMDTool = new CMDTool(); this.CMDTool.attach(this); this.CMDTool.bindWithEditor(this); var self = this; Object.keys(LineEditorCmd).forEach(function (cmd) { if (LineEditorCmd[cmd].bindKey) self.bindKeyToCmd(LineEditorCmd[cmd].bindKey.win, cmd); }); } OOP.mixClass(LineEditor, BaseEditor); LineEditor.prototype.clipboardType = "CB_LINES"; LineEditor.prototype.createView = function () { this.$view = _({ attr: { tabindex: 1 }, class: 'as-line-editor', child: [ { class: 'as-line-editor-header', child: this.CMDTool.getView() }, { tag: BoardTable.tag, class: ['as-line-editor-body', 'as-bscroller'] } ] }); this.$cmdToolCtn = $('.as-line-editor-header', this.$view); this.$body = $('.as-line-editor-body', this.$view) .on('orderchange', this.ev_lineOrderChange.bind(this)); this.$view.on('keydown', this.ev_cmdKeyDown.bind(this)) }; LineEditor.prototype.onAttached = function () { /*** * * @type {LayoutEditor} */ this.layoutEditor = this.getContext(R.LAYOUT_EDITOR); /*** * * @type {FormEditor} */ this.formEditor = this.getContext(R.FORM_EDITOR); }; LineEditor.prototype.onStart = function () { this.selfHolder = this.formEditor.getEditorHolderByEditor(this); this.CMDTool.start(); }; LineEditor.prototype.onStop = function () { if (this.selfHolder.tabframe.modified) this.layoutEditor.setLineData(this.getData()); }; LineEditor.prototype.onResume = function () { var pointList = this.getPointList(); var pointDict = this.getPointDict(); this.lines.forEach(function (ln) { ln.loadPoints(pointList, pointDict); ln.handleU(); ln.handleV(); }); }; LineEditor.prototype.setData = function (data) { this.getPointList(); var self = this; this._data = data; this.$body.clearChild(); this.lines = data.map(function (rawLine) { return new LELine(self); }); this.lines.forEach(function (line) { self.$body.addChild(line.getView()); }); var pointList = this.getPointList(); var pointDict = this.getPointDict(); this.lines.forEach(function (line, i) { line.loadPoints(pointList, pointDict); line.setData(data[i]); line.on('select', function (event) { if (self.isActivatedLine(line)) { if (event.shiftKey && self.activatedBlocks.length > 1) { self.deactivateLine(line); } else self.activateLine(line); } else { self.activateLine(line, event.shiftKey); } }); }) }; LineEditor.prototype.getData = function () { return this.lines.map(function (ln) { return ln.getData(); }); }; LineEditor.prototype.getCmdNames = function () { return Object.keys(LineEditorCmd); }; LineEditor.prototype.getCmdDescriptor = function (name) { var descriptor = LineEditorCmdDescriptors[name]; var res = Object.assign({ type: 'trigger', desc: 'command: ' + name, icon: 'span.mdi.mdi-apple-keyboard-command' }, descriptor); if (name === 'cut' || name === 'copy' || name === 'delete') { res.disabled = this.activatedLines.length === 0; if (name === 'delete' || name === 'cut') { res.disabled = res.disabled || this.activatedLines.some(function (ln) { return ln._data && ln._data.attributes && ln._data.attributes.permissions && ln._data.attributes.permissions.activatedLines === "GENERATOR"; }); } } else if (name === 'paste') { res.disabled = !ClipboardManager.get(this.clipboardType); } return res; }; LineEditor.prototype.getCmdGroupTree = function () { var tree = LineEditorCmdTree; return tree; }; LineEditor.prototype.activateLine = function (line, append) { var idx = this.activatedLines.indexOf(line); if (idx >= 0) { this.activatedLines.splice(idx, 1); if (!append) { this.activatedLines.splice(0, this.activatedLines.length).forEach(function (ln) { ln.getView().removeClass('as-activated'); }); } this.activatedLines.push(line); } else { if (!append) { this.activatedLines.splice(0, this.activatedLines.length).forEach(function (ln) { ln.getView().removeClass('as-activated'); }); } this.activatedLines.push(line); line.getView().addClass('as-activated'); } this.activatedLines.forEach(function (ln, i, arr) { if (i + 1 === arr.length) { ln.getView().addClass('as-focus'); } else { ln.getView().removeClass('as-focus'); } }); this.notifyCmdDescriptorsChange(); }; LineEditor.prototype.deactivateLine = function (line) { var idx = this.activatedLines.indexOf(line); if (idx < 0) return; this.activatedLines.splice(idx, 1); line.getView().removeClass('as-activated') .removeClass('as-focus'); this.notifyCmdDescriptorsChange(); }; LineEditor.prototype.deleteLine = function (line) { this.deactivateLine(line); var idx = this.lines.indexOf(line); if (idx < 0) return; this.lines.splice(idx, 1); line.getView().remove(); this.notifyUnsaved(); }; LineEditor.prototype.isActivatedLine = function (line) { return this.activatedLines.indexOf(line) >= 0; }; LineEditor.prototype.setClipboardLines = function (lines) { if (lines.length === 0) return; lines = lines.map(function (ln) { return ln.getData(); }); ClipboardManager.set(this.clipboardType, lines); this.notifyCmdDescriptorsChange(); }; LineEditor.prototype.getClipboardLines = function () { var lines = ClipboardManager.get(this.clipboardType); if (lines && lines.length > 0 && lines.push) { return lines; } return null; }; LineEditor.prototype.ev_lineOrderChange = function (event) { var from = event.from; var to = event.to; var line = this.lines.splice(from, 1)[0]; this.lines.splice(to, 0, line); this.notifyUnsaved(); this.layoutEditor.notifyUnsaved(); }; LineEditor.prototype.notifyUnsaved = function () { this.selfHolder.tabframe.modified = true; this.layoutEditor.notifyUnsaved(); }; LineEditor.prototype.notifySaved = function () { this.selfHolder.tabframe.modified = false; }; LineEditor.prototype._calcPointList = function () { if (this._pointListCache && !this._pointListCache.expire) { return this._pointListCache; } this._pointListCache = {}; setTimeout(function () { this.expire = true; }.bind(this._pointListCache), 300); var list = []; var rootLayout = this.layoutEditor.rootLayout; var rootFragment = this.layoutEditor.rootFragment; traversal(rootLayout, function (path) { var node = path.node; var item; if (node.fragment === rootFragment) { item = { text: '[' + node.tag + '] ' + node.attributes.name, value: node.attributes.name, order: 'z_' + node.tag + '_' + node.attributes.name, bTag: node.tag, pinList: Object.keys(node.pinHandlers).map(function (name) { return { text: name, value: name }; }) } if (node.tag.toLowerCase().match(/input|radio|checkbox|track|combo/)) { item.order = 'a_' + node.tag + '_' + node.attributes.name; } else if (node.tag.toLowerCase().match(/button|label|text/)) { item.order = 'c_' + node.tag + '_' + node.attributes.name; } list.push(item); } else { path.skipChildren(); } }); var blocks = this.layoutEditor.getBlockData(); blocks.forEach(function (block) { var id = block.attributes && block.attributes.id; var clazz = AssemblerInstance.classes['BLOCK'][block.tag] || BaseBlock; if (!id) return; var item = { text: '[' + block.tag + '] ' + id, value: id, order: 'b_' + block.tag + '_' + id, bTag: block.tag, pinList: Object.keys(clazz.prototype.pinHandlers).map(function (name) { return { text: name, value: name }; }) } if (block.tag === 'function' && block.attributes && block.attributes.args) { item.pinList.unshift.apply(item.pinList, block.attributes.args.map(function (it) { return { text: it, value: it }; })); } list.push(item); }); list.sort(function (a, b) { a = a.order; b = b.order; if (a === b) return 0; if (a < b) return -1; return 1; }); this._pointListCache.list = list; this._pointListCache.dict = list.reduce(function (ac, cr) { ac[cr.value] = cr; return ac; }, {}); return this._pointListCache; }; LineEditor.prototype.getPointList = function () { return this._calcPointList().list; }; LineEditor.prototype.getPointDict = function () { return this._calcPointList().dict; }; export default LineEditor;