![]() 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 BEEntry from "./types/BEEntry"; import BEFunction from "./types/BEFunction"; import BERadioGroup from "./types/BERadioGroup"; import BEPropsGate from "./types/BEPropsGate"; import BETimer from "./types/BETimer"; import BESnackBar from "./types/BESnackBar"; import BEFileDownloader from "./types/BEFileDownloader"; import BEBase from "./types/BEBase"; import {randomUniqueIdent} from "../../core/utils"; import {vScrollIntoView} from "absol-acomp/js/utils"; var BlockEditorCmd = {}; BlockEditorCmd.preview = function () { this.layoutEditor.execCmd('preview'); }; BlockEditorCmd.delete = function () { var blocks = this.activatedBlocks.slice(); for (var i = 0; i < blocks.length; ++i) { this.deleteBlock(blocks[i]); } }; BlockEditorCmd.copy = function () { this.setClipboardBlocks(this.activatedBlocks); }; BlockEditorCmd.save = function () { this.layoutEditor.execCmd('save'); }; BlockEditorCmd.paste = function () { var rawBlocks = this.getClipboardBlocks(); if (!rawBlocks) return; var self = this; rawBlocks.forEach(function (rawBlock, i) { var clazz = BEBase.prototype.tag2Class[rawBlock.tag] || BEBase; var block = new clazz(this); 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); } }); this.$body.addChild(block.getView()); this.blocks.push(block); if (i + 1 === rawBlocks.length) vScrollIntoView(block.getView()); var id = (rawBlock.attributes && rawBlock.attributes.id) || randomUniqueIdent(); var idPart; var idNum; if (self.findBlockById(id)) { idPart = id.split('_'); idNum = parseInt(idPart[idPart.length - 1]); if (isNaN(idNum)) { idPart.push(0); idNum = 1; } idPart[idPart.length - 1] = idNum; id = idPart.join('_'); while (self.findBlockById(id)) { idNum++; idPart[idPart.length - 1] = idNum; id = idPart.join('_'); } rawBlock.attributes = rawBlock.attributes || {}; rawBlock.attributes.id = id; } if (rawBlock.attributes && rawBlock.attributes.permissions && rawBlock.attributes.permissions.edit_attributes) { delete rawBlock.attributes.permissions.edit_attributes; } block.setData(rawBlock); this.activateBlock(block, i > 0); }.bind(this)); this.notifyUnsaved(); }; export var BlockEditorCmdTree = [ ['preview'], ['save'], [ // 'cut', 'copy', 'paste', 'delete' ], [ BEEntry, BEFunction, BERadioGroup, BEPropsGate, BETimer, BESnackBar, BEFileDownloader ].map(function (clazz) { return 'insert_' + clazz.prototype.tag; }) ]; export var BlockEditorCmdDescriptors = { preview: { type: 'trigger', icon: 'span.mdi.mdi-play', desc: 'Preview', bindKey: { win: 'Ctrl-K', mac: 'TODO?' } }, save: { type: 'trigger', icon: 'span.mdi.mdi-content-save', desc: 'Save', bindKey: { win: 'Ctrl-S', mac: '//todo' } }, cut: { type: 'trigger', icon: 'span.mdi.mdi-content-cut', desc: 'Cut', bindKey: { win: 'Ctrl-X', mac: 'TODO?' } }, copy: { type: 'trigger', icon: 'span.mdi.mdi-content-copy', desc: 'Copy', bindKey: { win: 'Ctrl-C', mac: 'TODO?' } }, paste: { type: 'trigger', icon: 'span.mdi.mdi-content-paste', desc: 'Paste', bindKey: { win: 'Ctrl-V', mac: 'TODO?' } }, delete: { type: 'trigger', icon: 'span.mdi.mdi-delete-variant', desc: 'Delete', bindKey: { win: 'Delete', mac: 'Delete' } } }; [ BEEntry, BEFunction, BERadioGroup, BEPropsGate, BETimer, BESnackBar, BEFileDownloader ].forEach(function (clazz) { BlockEditorCmdDescriptors['insert_' + clazz.prototype.tag] = { type: 'trigger', icon: clazz.prototype.menuIcon, desc: "Insert " + clazz.prototype.tag }; BlockEditorCmd['insert_' + clazz.prototype.tag] = function () { var block = new clazz(this); var self = this; 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); } }); this.$body.addChild(block.getView()); this.blocks.push(block); vScrollIntoView(block.getView()); block.setData({ attributes: { id: randomUniqueIdent() } }); this.activateBlock(block); this.notifyUnsaved(); } }); export default BlockEditorCmd;