AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"dndcmitem.min.js","sources":["../../../src/local/courseeditor/dndcmitem.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Course index cm component.\n *\n * This component is used to control specific course modules interactions like drag and drop\n * in both course index and course content.\n *\n * @module core_cour
seformat/local/courseeditor/dndcmitem\n * @class core_courseformat/local/courseeditor/dndcmitem\n * @copyright 2021 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {BaseComponent, DragDrop} from 'core/reactive';\n\nexport default class extends BaseComponent {\n\n /**\n * Configure the component drag and drop.\n *\n * @param {number} cmid course module id\n */\n configDragDrop(cmid) {\n\n this.id = cmid;\n\n // Drag and drop is only available for components compatible course formats.\n if (this.reactive.isEditing && this.reactive.supportComponents) {\n // Init element drag and drop.\n this.dragdrop = new DragDrop(this);\n // Save dropzone classes.\n this.classes = this.dragdrop.getClasses();\n }\n }\n\n /**\n * Remove all subcomponents dependencies.\n */\n destroy() {\n if (this.dragdrop !== undefined) {\n
this.dragdrop.unregister();\n }\n }\n\n /**\n * Enable or disable the draggable property.\n *\n * @param {bool} value the new draggable value\n */\n setDraggable(value) {\n this.dragdrop?.setDraggable(value);\n }\n\n // Drag and drop methods.\n\n /**\n * The element drop start hook.\n *\n * @param {Object} dropdata the dropdata\n */\n dragStart(dropdata) {\n this.reactive.dispatch('cmDrag', [dropdata.id], true);\n }\n\n /**\n * The element drop end hook.\n *\n * @param {Object} dropdata the dropdata\n */\n dragEnd(dropdata) {\n this.reactive.dispatch('cmDrag', [dropdata.id], false);\n }\n\n /**\n * Get the draggable data of this component.\n *\n * @returns {Object} exported course module drop data\n */\n getDraggableData() {\n const exporter = this.reactive.getExporter();\n return exporter.cmDraggableData(this.reactive.state, this.id);\n }\n\n /**\n * Va
lidate if the drop data can be dropped over the component.\n *\n * @param {Object} dropdata the exported drop data.\n * @returns {boolean}\n */\n validateDropData(dropdata) {\n if (dropdata?.type !== 'cm') {\n return false;\n }\n // Prevent delegated sections loops.\n if (dropdata?.delegatesection === true) {\n const mycminfo = this.reactive.get('cm', this.id);\n const mysection = this.reactive.get('section', mycminfo.sectionid);\n if (mysection?.component !== null) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Display the component dropzone.\n *\n * @param {Object} dropdata the accepted drop data\n */\n showDropZone(dropdata) {\n // If we are the next cmid of the dragged element we accept the drop because otherwise it\n // will get captured by the section. However, we won't trigger any mutation.\n if (dropdata.nextcmid !=
this.id && dropdata.id != this.id) {\n this.element.classList.add(this.classes.DROPUP);\n }\n }\n\n /**\n * Hide the component dropzone.\n */\n hideDropZone() {\n this.element.classList.remove(this.classes.DROPUP);\n }\n\n /**\n * Drop event handler.\n *\n * @param {Object} dropdata the accepted drop data\n * @param {Event} event the drop event\n */\n drop(dropdata, event) {\n // Call the move mutation if necessary.\n if (dropdata.id != this.id && dropdata.nextcmid != this.id) {\n const mutation = (event.altKey) ? 'cmDuplicate' : 'cmMove';\n this.reactive.dispatch(mutation, [dropdata.id], null, this.id);\n }\n }\n\n}\n"],"names":["BaseComponent","configDragDrop","cmid","id","this","reactive","isEditing","supportComponents","dragdrop","DragDrop","classes","getClasses","destroy","undefined","unregister","setDraggable","value","dragStart","dropdata","dispatch","dragEnd","getDraggableData","getExp
orter","cmDraggableData","state","validateDropData","type","delegatesection","mycminfo","get","mysection","sectionid","component","showDropZone","nextcmid","element","classList","add","DROPUP","hideDropZone","remove","drop","event","mutation","altKey"],"mappings":";;;;;;;;;;;;uBA6B6BA,wBAOzBC,eAAeC,WAENC,GAAKD,KAGNE,KAAKC,SAASC,WAAaF,KAAKC,SAASE,yBAEpCC,SAAW,IAAIC,mBAASL,WAExBM,QAAUN,KAAKI,SAASG,cAOrCC,eAC0BC,IAAlBT,KAAKI,eACAA,SAASM,aAStBC,aAAaC,sDACJR,mDAAUO,aAAaC,OAUhCC,UAAUC,eACDb,SAASc,SAAS,SAAU,CAACD,SAASf,KAAK,GAQpDiB,QAAQF,eACCb,SAASc,SAAS,SAAU,CAACD,SAASf,KAAK,GAQpDkB,0BACqBjB,KAAKC,SAASiB,cACfC,gBAAgBnB,KAAKC,SAASmB,MAAOpB,KAAKD,IAS9DsB,iBAAiBP,aACU,QAAnBA,MAAAA,gBAAAA,SAAUQ,aACH,MAGuB,KAA9BR,MAAAA,gBAAAA,SAAUS,iBAA0B,OAC9BC,SAAWxB,KAAKC,SAASwB,IAAI,KAAMzB,KAAKD,IACxC2B,UAAY1B,KAAKC,SAASwB,IAAI,UAAWD,SAASG,cAC3B,QAAzBD,MAAAA,iBAAAA,UAAWE,kBACJ,SAGR,EAQXC,aAAaf,UAGLA,SAASgB,UAAY9B,KAAKD,IAAMe,SAASf,IAAMC,KAAKD,SAC/CgC,QAAQC,UAAUC,IAAIjC,KAAKM,QAAQ4B,QAOhDC,oBACSJ,QAAQC,UAAUI,OAAOpC,KAAKM,QAAQ4B,QAS/
CG,KAAKvB,SAAUwB,UAEPxB,SAASf,IAAMC,KAAKD,IAAMe,SAASgB,UAAY9B,KAAKD,GAAI,OAClDwC,SAAYD,MAAME,OAAU,cAAgB,cAC7CvC,SAASc,SAASwB,SAAU,CAACzB,SAASf,IAAK,KAAMC,KAAKD"}