![]() 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/blockeditor/ |
Upload File : |
import OOP from "absol/src/HTML5/OOP"; import BaseEditor from "../../core/BaseEditor"; import {$, _} from "../../core/FCore"; import '../../../css/blockeditor.css'; import BEBase from "./types/BEBase"; import "./types/BEFunction"; import "./types/BEEntry"; import "./types/BEFileDownloader"; import "./types/BEPropsGate"; import "./types/BERadioGroup"; import "./types/BESnackBar"; import "./types/BETimer"; import R from '../../R'; import CMDTool from "../../fragment/CMDTool"; import BlockEditorCmd, {BlockEditorCmdDescriptors, BlockEditorCmdTree} from "./BlockEditorCmd"; import ClipboardManager from "../../ClipboardManager"; import BoardTable from "absol-acomp/js/BoardTable"; function BlockEditor() { BaseEditor.call(this); this.cmdRunner.assign(BlockEditorCmd); this.activatedBlocks = []; this.CMDTool = new CMDTool(); this.CMDTool.attach(this); this.CMDTool.bindWithEditor(this); var self = this; Object.keys(BlockEditorCmdDescriptors).forEach(function (cmd) { if (BlockEditorCmdDescriptors[cmd].bindKey) self.bindKeyToCmd(BlockEditorCmdDescriptors[cmd].bindKey.win, cmd); }); } OOP.mixClass(BlockEditor, BaseEditor); BlockEditor.prototype.clipboardType = "CB_BLOCKS"; BlockEditor.prototype.createView = function () { this.$view = _({ attr: { tabindex: 1 }, class: 'as-block-editor', child: [ { class: 'as-block-editor-header', child: this.CMDTool.getView() }, { tag: BoardTable.tag, class: ['as-block-editor-body', 'as-bscroller'] } ] }); this.$cmdToolCtn = $('.as-block-editor-header', this.$view); this.$body = $('.as-block-editor-body', this.$view) .on('orderchange', this.ev_blockOrderChange.bind(this)); this.$view.on('keydown', this.ev_cmdKeyDown.bind(this)) }; BlockEditor.prototype.onAttached = function () { /*** * * @type {LayoutEditor} */ this.layoutEditor = this.getContext(R.LAYOUT_EDITOR); /*** * * @type {FormEditor} */ this.formEditor = this.getContext(R.FORM_EDITOR); } BlockEditor.prototype.onStart = function () { this.selfHolder = this.formEditor.getEditorHolderByEditor(this); this.CMDTool.start(); }; BlockEditor.prototype.onPause = function () { if (this.selfHolder.tabframe.modified) this.layoutEditor.setBlockData(this.getData()); }; BlockEditor.prototype.setData = function (data) { var self = this; this._data = data; this.$body.clearChild(); this.blocks = data.map(function (it) { var clazz = BEBase.prototype.tag2Class[it.tag] || BEBase; var block = new clazz(self); block.setData(it); block.on('select', function (event) { if (self.isActivatedBlock(block)) { if (event.shiftKey && self.activatedBlocks.length > 1) { self.deactivateBlock(block); } else self.activateBlock(block); } else { self.activateBlock(block, event.shiftKey); } }); return block; }); this.blocks.forEach(function (blk) { self.$body.addChild(blk.getView()); }); }; BlockEditor.prototype.getData = function () { return this.blocks.map(function (blk) { return blk.getData(); }); }; BlockEditor.prototype.getCmdNames = function () { return Object.keys(BlockEditorCmd); }; BlockEditor.prototype.getCmdDescriptor = function (name) { var descriptor = BlockEditorCmdDescriptors[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.activatedBlocks.length === 0; if (name === 'delete' || name === 'cut') { res.disabled = res.disabled || this.activatedBlocks.some(function (blk) { return blk._data && blk._data.attributes && blk._data.attributes.permissions && blk._data.attributes.permissions.edit_attributes === "GENERATOR"; }); } } else if (name === 'paste') { res.disabled = !ClipboardManager.get(this.clipboardType); } return res; }; BlockEditor.prototype.getCmdGroupTree = function () { var tree = BlockEditorCmdTree; return tree; }; BlockEditor.prototype.activateBlock = function (block, append) { var idx = this.activatedBlocks.indexOf(block); if (idx >= 0) { this.activatedBlocks.splice(idx, 1); if (!append) { this.activatedBlocks.splice(0, this.activatedBlocks.length).forEach(function (blk) { blk.getView().removeClass('as-activated').removeClass('as-focus'); }); } this.activatedBlocks.push(block); } else { if (!append) { this.activatedBlocks.splice(0, this.activatedBlocks.length).forEach(function (blk) { blk.getView().removeClass('as-activated').removeClass('as-focus'); }); } this.activatedBlocks.push(block); block.getView().addClass('as-activated'); } this.activatedBlocks.forEach(function (blk, i, arr) { if (i + 1 === arr.length) { blk.getView().addClass('as-focus'); } else { blk.getView().removeClass('as-focus'); } }); this.notifyCmdDescriptorsChange(); }; BlockEditor.prototype.deactivateBlock = function (block) { var idx = this.activatedBlocks.indexOf(block); if (idx < 0) return; this.activatedBlocks.splice(idx, 1); block.getView().removeClass('as-activated') .removeClass('as-focus'); this.notifyCmdDescriptorsChange(); }; BlockEditor.prototype.deleteBlock = function (block) { this.deactivateBlock(block); var idx = this.blocks.indexOf(block); if (idx < 0) return; this.blocks.splice(idx, 1); block.destroy(); block.getView().remove(); this.notifyUnsaved(); }; BlockEditor.prototype.isActivatedBlock = function (block) { return this.activatedBlocks.indexOf(block) >= 0; }; BlockEditor.prototype.setClipboardBlocks = function (blocks) { if (blocks.length === 0) return; blocks = blocks.map(function (blk) { return blk.getData(); }); ClipboardManager.set(this.clipboardType, blocks); this.notifyCmdDescriptorsChange(); }; BlockEditor.prototype.getClipboardBlocks = function () { var blocks = ClipboardManager.get(this.clipboardType); if (blocks && blocks.length > 0 && blocks.push) { return blocks; } return null; }; BlockEditor.prototype.findBlockById = function (id) { var block; for (var i = 0; i < this.blocks.length; ++i) { block = this.blocks[i]; if (block._data && block._data.attributes && block._data.attributes.id === id) { return block; } } return null; }; BlockEditor.prototype.ev_blockOrderChange = function (event) { var from = event.from; var to = event.to; var block = this.blocks.splice(from, 1)[0]; this.blocks.splice(to, 0, block); this.notifyUnsaved(); this.layoutEditor.notifyUnsaved(); }; BlockEditor.prototype.notifyUnsaved = function () { this.selfHolder.tabframe.modified = true; this.layoutEditor.notifyUnsaved(); }; BlockEditor.prototype.notifySaved = function () { this.selfHolder.tabframe.modified = false; }; export default BlockEditor;