{"version":3,"file":"courseeditor.min.js","sources":["https:\/\/dl1.cuni.cz\/course\/format\/amd\/src\/courseeditor.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 * Generic reactive module used in the course editor.\n *\n * @module core_courseformat\/courseeditor\n * @copyright 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport DefaultMutations from 'core_courseformat\/local\/courseeditor\/mutations';\nimport CourseEditor from 'core_courseformat\/local\/courseeditor\/courseeditor';\nimport events from 'core_course\/events';\n\n\/\/ A map with all the course editor instances.\nconst courseEditorMap = new Map();\n\n\/\/ Map with all the state keys the backend send us to know if the frontend cache is valid or not.\nconst courseStateKeyMap = new Map();\n\n\/**\n * Trigger a state changed event.\n *\n * This function will be moved to core_course\/events module\n * when the file is migrated to the new JS events structure proposed in MDL-70990.\n *\n * @method dispatchStateChangedEvent\n * @param {object} detail the full state\n * @param {object} target the custom event target (document if none provided)\n *\/\nfunction dispatchStateChangedEvent(detail, target) {\n if (target === undefined) {\n target = document;\n }\n target.dispatchEvent(new CustomEvent(events.stateChanged, {\n bubbles: true,\n detail: detail,\n }));\n}\n\n\/**\n * Setup the current view settings\n *\n * The backend cache state revision is a combination of the course->cacherev, the\n * user course preferences and completion state. The backend updates that number\n * everytime some change in the course affects the user course state.\n *\n * @param {number} courseId the course id\n * @param {setup} setup format, page and course settings\n * @param {boolean} setup.editing if the page is in edit mode\n * @param {boolean} setup.supportscomponents if the format supports components for content\n * @param {String} setup.statekey the backend cached state revision\n * @param {Array} setup.overriddenStrings optional overridden strings\n *\/\nexport const setViewFormat = (courseId, setup) => {\n courseId = parseInt(courseId);\n \/\/ Caches are ignored in edit mode.\n if (!setup.editing) {\n courseStateKeyMap.set(courseId, setup.statekey);\n }\n const editor = getCourseEditor(courseId);\n editor.setViewFormat(setup);\n};\n\n\/**\n * Get a specific course editor reactive instance.\n *\n * @param {number} courseId the course id\n * @returns {CourseEditor}\n *\/\nexport const getCourseEditor = (courseId) => {\n courseId = parseInt(courseId);\n\n if (!courseEditorMap.has(courseId)) {\n courseEditorMap.set(\n courseId,\n new CourseEditor({\n name: `CourseEditor${courseId}`,\n eventName: events.stateChanged,\n eventDispatch: dispatchStateChangedEvent,\n \/\/ Mutations can be overridden by the format plugin using setMutations\n \/\/ but we need the default one at least.\n mutations: new DefaultMutations(),\n })\n );\n courseEditorMap.get(courseId).loadCourse(courseId, courseStateKeyMap.get(courseId));\n }\n return courseEditorMap.get(courseId);\n};\n\n\/**\n * Get the current course reactive instance.\n *\n * @returns {CourseEditor}\n *\/\nexport const getCurrentCourseEditor = () => getCourseEditor(M.cfg.courseId);\n"],"names":["courseEditorMap","Map","courseStateKeyMap","dispatchStateChangedEvent","detail","target","undefined","document","dispatchEvent","CustomEvent","events","stateChanged","bubbles","courseId","setup","parseInt","editing","set","statekey","getCourseEditor","setViewFormat","has","CourseEditor","name","eventName","eventDispatch","mutations","DefaultMutations","get","loadCourse","M","cfg"],"mappings":";;;;;;;oSA4BMA,gBAAkB,IAAIC,IAGtBC,kBAAoB,IAAID,aAYrBE,0BAA0BC,OAAQC,aACxBC,IAAXD,SACAA,OAASE,UAEbF,OAAOG,cAAc,IAAIC,YAAYC,gBAAOC,aAAc,CACtDC,SAAS,EACTR,OAAQA,iCAkBa,CAACS,SAAUC,SACpCD,SAAWE,SAASF,UAEfC,MAAME,SACPd,kBAAkBe,IAAIJ,SAAUC,MAAMI,UAE3BC,gBAAgBN,UACxBO,cAAcN,cASZK,gBAAmBN,WAC5BA,SAAWE,SAASF,UAEfb,gBAAgBqB,IAAIR,YACrBb,gBAAgBiB,IACZJ,SACA,IAAIS,sBAAa,CACbC,2BAAqBV,UACrBW,UAAWd,gBAAOC,aAClBc,cAAetB,0BAGfuB,UAAW,IAAIC,sBAGvB3B,gBAAgB4B,IAAIf,UAAUgB,WAAWhB,SAAUX,kBAAkB0B,IAAIf,YAEtEb,gBAAgB4B,IAAIf,oFAQO,IAAMM,gBAAgBW,EAAEC,IAAIlB"}