{"version":3,"file":"tab.min.js","sources":["https:\/\/moodle.tau.ac.il\/2023\/course\/format\/multitopic\/amd\/src\/courseformat\/contenttabs\/tab.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 .\n\n\/**\n * Tab format component.\n *\n * @module format_multitopic\/courseformat\/contenttabs\/tab\n * @class format_multitopic\/courseformat\/contenttabs\/tab\n * @copyright 2023 James Calder and Otago Polytechnic\n * @copyright based on work by 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport TabTitle from 'format_multitopic\/courseformat\/contenttabs\/tabtitle';\nimport DndSection from 'core_courseformat\/local\/courseeditor\/dndsection';\n\nexport default class extends DndSection {\n\n \/**\n * Constructor hook.\n *\/\n create() {\n \/\/ Optional component name for debugging.\n this.name = 'contenttabs_tab';\n \/\/ Default query selectors.\n this.selectors = {\n SECTION_ITEM: `a.nav-link`,\n };\n \/\/ CSS classes.\n this.classes = {\n LOCKED: 'editinprogress',\n DROPBEFORE: 'drop-before',\n DROPAFTER: 'drop-after',\n };\n\n \/\/ We need our id to watch specific events.\n this.id = this.element.dataset.id;\n }\n\n \/**\n * Initial state ready method.\n *\n * @param {Object} state the initial state\n *\/\n stateReady(state) {\n this.configState(state);\n \/\/ Drag and drop is only available for components compatible course formats.\n if (this.reactive.isEditing && this.reactive.supportComponents) {\n const sectionItem = this.getElement(this.selectors.SECTION_ITEM);\n \/\/ Init the inner dragable element.\n const headerComponent = new TabTitle({\n ...this,\n element: sectionItem,\n fullregion: this.element,\n });\n this.configDragDrop(headerComponent);\n }\n }\n\n \/**\n * Component watchers.\n *\n * @returns {Array} of watchers\n *\/\n getWatchers() {\n return [\n {watch: `section[${this.id}]:updated`, handler: this._refreshSection},\n ];\n }\n\n \/**\n * Validate 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 \/\/ We accept a section that fits\n if (dropdata?.type === 'section') {\n const sectionzeroid = this.course.sectionlist[0];\n const origin = this.reactive.get(\"section\", dropdata.id);\n const target = this.section;\n const targettablevel = this.element.className.match(\/\\btab_level_(\\d+)\\b\/)[1];\n return dropdata?.id != this.id && targettablevel == origin.levelsan\n && (target.levelsan == targettablevel || target.number > origin.number)\n && origin.id != sectionzeroid;\n }\n return false;\n }\n\n \/**\n * Display the component dropzone.\n *\n * @param {Object} dropdata the accepted drop data\n *\/\n showDropZone(dropdata) {\n if (dropdata.type == 'section') {\n const origin = this.reactive.get(\"section\", dropdata.id);\n const targettablevel = this.element.className.match(\/\\btab_level_(\\d+)\\b\/)[1];\n if (targettablevel == origin.levelsan) {\n \/\/ The relative move of section depends on the section number.\n if (this.section.number > dropdata.number) {\n this.element.classList.remove(this.classes.DROPBEFORE);\n this.element.classList.add(this.classes.DROPAFTER);\n } else {\n this.element.classList.add(this.classes.DROPBEFORE);\n this.element.classList.remove(this.classes.DROPAFTER);\n }\n }\n }\n }\n\n \/**\n * Hide the component dropzone.\n *\/\n hideDropZone() {\n this.element.classList.remove(this.classes.DROPBEFORE);\n this.element.classList.remove(this.classes.DROPAFTER);\n }\n\n \/**\n * Drop event handler.\n *\n * @param {Object} dropdata the accepted drop data\n *\/\n drop(dropdata) {\n \/\/ Call the move mutation.\n if (dropdata.type == 'section') {\n const origin = this.reactive.get(\"section\", dropdata.id);\n const target = this.section;\n const targettablevel = this.element.className.match(\/\\btab_level_(\\d+)\\b\/)[1];\n if (targettablevel == origin.levelsan) {\n this.reactive.dispatch('sectionMove', [origin.id], target.id);\n }\n }\n }\n\n \/**\n * Update a tab using the state information.\n *\n * @param {object} param\n * @param {Object} param.element details the update details.\n *\/\n _refreshSection({element}) {\n \/\/ Update classes.\n this.element.classList.toggle(this.classes.DRAGGING, element.dragging ?? false);\n this.element.classList.toggle(this.classes.LOCKED, element.locked ?? false);\n this.locked = element.locked;\n \/\/ Update title.\n this.getElement(\"div.tab_content\").innerHTML = element.title;\n }\n\n}"],"names":["DndSection","create","name","selectors","SECTION_ITEM","classes","LOCKED","DROPBEFORE","DROPAFTER","id","this","element","dataset","stateReady","state","configState","reactive","isEditing","supportComponents","sectionItem","getElement","headerComponent","TabTitle","fullregion","configDragDrop","getWatchers","watch","handler","_refreshSection","validateDropData","dropdata","type","sectionzeroid","course","sectionlist","origin","get","target","section","targettablevel","className","match","levelsan","number","showDropZone","classList","remove","add","hideDropZone","drop","dispatch","toggle","DRAGGING","dragging","locked","innerHTML","title"],"mappings":";;;;;;;;;wMA4B6BA,oBAKzBC,cAESC,KAAO,uBAEPC,UAAY,CACbC,gCAGCC,QAAU,CACXC,OAAQ,iBACRC,WAAY,cACZC,UAAW,mBAIVC,GAAKC,KAAKC,QAAQC,QAAQH,GAQnCI,WAAWC,eACFC,YAAYD,OAEbJ,KAAKM,SAASC,WAAaP,KAAKM,SAASE,kBAAmB,OACtDC,YAAcT,KAAKU,WAAWV,KAAKP,UAAUC,cAE7CiB,gBAAkB,IAAIC,kBAAS,IAC9BZ,KACHC,QAASQ,YACTI,WAAYb,KAAKC,eAEhBa,eAAeH,kBAS5BI,oBACW,CACH,CAACC,wBAAkBhB,KAAKD,gBAAekB,QAASjB,KAAKkB,kBAU7DC,iBAAiBC,aAEU,aAAnBA,MAAAA,gBAAAA,SAAUC,MAAoB,OACxBC,cAAgBtB,KAAKuB,OAAOC,YAAY,GACxCC,OAASzB,KAAKM,SAASoB,IAAI,UAAWN,SAASrB,IAC\/C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