From f1525fbdbf41142e40c75bb949663e0f6da9adfe Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 8 Jul 2021 11:06:18 +0800 Subject: [PATCH] MDL-61460 tool_componentlibrary: JS Documentation fix --- .../amd/build/clipboardwrapper.min.js.map | 2 +- .../amd/build/jsrunner.min.js.map | 2 +- .../amd/build/loader.min.js.map | 2 +- .../amd/build/mustache.min.js.map | 2 +- .../amd/build/search.min.js.map | 2 +- .../amd/build/selectors.min.js.map | 2 +- .../amd/src/clipboardwrapper.js | 5 +- .../tool/componentlibrary/amd/src/jsrunner.js | 5 +- admin/tool/componentlibrary/amd/src/loader.js | 1 - .../tool/componentlibrary/amd/src/mustache.js | 10 ++- admin/tool/componentlibrary/amd/src/search.js | 15 +++- .../componentlibrary/amd/src/selectors.js | 73 ++++++++++++++++++- 12 files changed, 103 insertions(+), 18 deletions(-) diff --git a/admin/tool/componentlibrary/amd/build/clipboardwrapper.min.js.map b/admin/tool/componentlibrary/amd/build/clipboardwrapper.min.js.map index a3b127d4a44..080df4a7164 100644 --- a/admin/tool/componentlibrary/amd/build/clipboardwrapper.min.js.map +++ b/admin/tool/componentlibrary/amd/build/clipboardwrapper.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/clipboardwrapper.js"],"names":["idCounter","clipboardWrapper","document","querySelectorAll","selectors","clipboardcontent","forEach","element","id","Templates","renderForPromise","clipboardtarget","then","html","js","prependNodeContents","catch"],"mappings":"mPAwBA,OACA,O,qXAEIA,CAAAA,CAAS,CAAG,C,CAKHC,CAAgB,4CAAG,8FAC5BC,QAAQ,CAACC,gBAAT,CAA0BC,UAAUC,gBAApC,EAAsDC,OAAtD,CAA8D,SAAAC,CAAO,CAAI,CACrE,GAAI,CAACA,CAAO,CAACC,EAAb,CAAiB,CACbD,CAAO,CAACC,EAAR,yCAA8CR,CAAS,EAAvD,CACH,CACDS,UAAUC,gBAAV,CAA2B,uCAA3B,CAAoE,CAACC,eAAe,YAAMJ,CAAO,CAACC,EAAd,SAAhB,CAApE,EACCI,IADD,CACM,WAAgB,IAAdC,CAAAA,CAAc,GAAdA,IAAc,CAARC,CAAQ,GAARA,EAAQ,CAClBL,UAAUM,mBAAV,CAA8BR,CAA9B,CAAuCM,CAAvC,CAA6CC,CAA7C,EACA,MACH,CAJD,EAKCE,KALD,EAMH,CAVD,EAD4B,wCAAH,uD","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 * Interface to using clipboard.js\n *\n * @module tool_componentlibrary/clipboardwrapper\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport 'core/copy_to_clipboard';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Templates from 'core/templates';\n\nlet idCounter = 0;\n\n/**\n * Initialise the clipboard button on all reusable code.\n */\nexport const clipboardWrapper = async() => {\n document.querySelectorAll(selectors.clipboardcontent).forEach(element => {\n if (!element.id) {\n element.id = `tool_componentlibrary_content-${idCounter++}`;\n }\n Templates.renderForPromise('tool_componentlibrary/clipboardbutton', {clipboardtarget: `#${element.id} code`})\n .then(({html, js}) => {\n Templates.prependNodeContents(element, html, js);\n return;\n })\n .catch();\n });\n};\n"],"file":"clipboardwrapper.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/clipboardwrapper.js"],"names":["idCounter","clipboardWrapper","document","querySelectorAll","selectors","clipboardcontent","forEach","element","id","Templates","renderForPromise","clipboardtarget","then","html","js","prependNodeContents","catch"],"mappings":"mPAuBA,OACA,O,qXAEIA,CAAAA,CAAS,CAAG,C,CAOHC,CAAgB,4CAAG,8FAC5BC,QAAQ,CAACC,gBAAT,CAA0BC,UAAUC,gBAApC,EAAsDC,OAAtD,CAA8D,SAAAC,CAAO,CAAI,CACrE,GAAI,CAACA,CAAO,CAACC,EAAb,CAAiB,CACbD,CAAO,CAACC,EAAR,yCAA8CR,CAAS,EAAvD,CACH,CACDS,UAAUC,gBAAV,CAA2B,uCAA3B,CAAoE,CAACC,eAAe,YAAMJ,CAAO,CAACC,EAAd,SAAhB,CAApE,EACCI,IADD,CACM,WAAgB,IAAdC,CAAAA,CAAc,GAAdA,IAAc,CAARC,CAAQ,GAARA,EAAQ,CAClBL,UAAUM,mBAAV,CAA8BR,CAA9B,CAAuCM,CAAvC,CAA6CC,CAA7C,EACA,MACH,CAJD,EAKCE,KALD,EAMH,CAVD,EAD4B,wCAAH,uD","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 * Wrapper to ensure that all Hugo example snippets have a \"Copy to clipboard\" button.\n *\n * @module tool_componentlibrary/clipboardwrapper\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport 'core/copy_to_clipboard';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Templates from 'core/templates';\n\nlet idCounter = 0;\n\n/**\n * Initialise the clipboard button on all reusable code.\n *\n * @method\n */\nexport const clipboardWrapper = async() => {\n document.querySelectorAll(selectors.clipboardcontent).forEach(element => {\n if (!element.id) {\n element.id = `tool_componentlibrary_content-${idCounter++}`;\n }\n Templates.renderForPromise('tool_componentlibrary/clipboardbutton', {clipboardtarget: `#${element.id} code`})\n .then(({html, js}) => {\n Templates.prependNodeContents(element, html, js);\n return;\n })\n .catch();\n });\n};\n"],"file":"clipboardwrapper.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/build/jsrunner.min.js.map b/admin/tool/componentlibrary/amd/build/jsrunner.min.js.map index b0528822821..3137d7a70b9 100644 --- a/admin/tool/componentlibrary/amd/build/jsrunner.min.js.map +++ b/admin/tool/componentlibrary/amd/build/jsrunner.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/jsrunner.js"],"names":["jsRunner","compLib","document","querySelector","selectors","componentlibrary","querySelectorAll","jscode","forEach","runjs","eval","innerHTML"],"mappings":"mNAwBA,8C,wEAQO,GAAMA,CAAAA,QAAQ,CAAG,UAAM,CAC1B,GAAMC,CAAAA,OAAO,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,mBAAUC,gBAAjC,CAAhB,CACAJ,OAAO,CAACK,gBAAR,CAAyBF,mBAAUG,MAAnC,EAA2CC,OAA3C,CAAmD,SAAAC,KAAK,CAAI,CACxDC,IAAI,CAACD,KAAK,CAACE,SAAP,CACP,CAFD,CAGH,CALM,C","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 * This is called from to run any js code\n *\n * @module tool_componentlibrary/jsrunner\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\n\n/**\n * The Hugo shortcodes changes the JavaScript in markdownfiles from\n * the Moodle mustache {{js}} code... {{/js}} syntax into a div with\n * attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html.\n * This code fetches and runs the JavaScript content.\n */\nexport const jsRunner = () => {\n const compLib = document.querySelector(selectors.componentlibrary);\n compLib.querySelectorAll(selectors.jscode).forEach(runjs => {\n eval(runjs.innerHTML); // eslint-disable-line no-eval\n });\n};\n"],"file":"jsrunner.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/jsrunner.js"],"names":["jsRunner","compLib","document","querySelector","selectors","componentlibrary","querySelectorAll","jscode","forEach","runjs","eval","innerHTML"],"mappings":"mNAuBA,8C,wEAUO,GAAMA,CAAAA,QAAQ,CAAG,UAAM,CAC1B,GAAMC,CAAAA,OAAO,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,mBAAUC,gBAAjC,CAAhB,CACAJ,OAAO,CAACK,gBAAR,CAAyBF,mBAAUG,MAAnC,EAA2CC,OAA3C,CAAmD,SAAAC,KAAK,CAAI,CACxDC,IAAI,CAACD,KAAK,CAACE,SAAP,CACP,CAFD,CAGH,CALM,C","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 * Run the JS required for example code to work in the library.\n *\n * @module tool_componentlibrary/jsrunner\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\n\n/**\n * The Hugo shortcodes changes the JavaScript in markdownfiles from\n * the Moodle mustache {{js}} code... {{/js}} syntax into a div with\n * attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html.\n * This code fetches and runs the JavaScript content.\n *\n * @method\n */\nexport const jsRunner = () => {\n const compLib = document.querySelector(selectors.componentlibrary);\n compLib.querySelectorAll(selectors.jscode).forEach(runjs => {\n eval(runjs.innerHTML); // eslint-disable-line no-eval\n });\n};\n"],"file":"jsrunner.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/build/loader.min.js.map b/admin/tool/componentlibrary/amd/build/loader.min.js.map index c41b8db9a99..44286dee310 100644 --- a/admin/tool/componentlibrary/amd/build/loader.min.js.map +++ b/admin/tool/componentlibrary/amd/build/loader.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/loader.js"],"names":["init","jsonFile"],"mappings":"oNAkCoB,QAAPA,CAAAA,IAAO,CAAAC,CAAQ,CAAI,CAC5B,iBACA,iBACA,yBACA,aAAOA,CAAP,CACH,C","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 * This initialises the component library JS\n *\n * @module tool_componentlibrary/loader\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {mustache} from './mustache';\nimport {jsRunner} from './jsrunner';\nimport {clipboardWrapper} from './clipboardwrapper';\nimport {search} from './search';\n\n/**\n * Load all the component library JavaScript.\n *\n * @param {string} jsonFile Full path to the JSON file with the search DB.\n */\nexport const init = jsonFile => {\n mustache();\n jsRunner();\n clipboardWrapper();\n search(jsonFile);\n};\n"],"file":"loader.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/loader.js"],"names":["init","jsonFile"],"mappings":"oNAiCoB,QAAPA,CAAAA,IAAO,CAAAC,CAAQ,CAAI,CAC5B,iBACA,iBACA,yBACA,aAAOA,CAAP,CACH,C","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 * This initialises the component library JS\n *\n * @module tool_componentlibrary/loader\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {mustache} from './mustache';\nimport {jsRunner} from './jsrunner';\nimport {clipboardWrapper} from './clipboardwrapper';\nimport {search} from './search';\n\n/**\n * Load all the component library JavaScript.\n *\n * @param {string} jsonFile Full path to the JSON file with the search DB.\n */\nexport const init = jsonFile => {\n mustache();\n jsRunner();\n clipboardWrapper();\n search(jsonFile);\n};\n"],"file":"loader.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/build/mustache.min.js.map b/admin/tool/componentlibrary/amd/build/mustache.min.js.map index 501c0e43f61..a7b69afaf6c 100644 --- a/admin/tool/componentlibrary/amd/build/mustache.min.js.map +++ b/admin/tool/componentlibrary/amd/build/mustache.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/mustache.js"],"names":["renderTemplate","container","templateName","context","JSON","parse","e","Log","debug","Templates","renderForPromise","html","js","rendercontainer","querySelector","selectors","mustacherendered","replaceNodeContents","loadTemplate","sourcecontainer","mustachesource","contextcontainer","mustachecontext","dataset","template","mustacherawcontext","textContent","parts","split","component","shift","name","join","request","methodname","args","themename","Config","theme","includecomments","Ajax","call","done","source","example","match","precontainer","document","createElement","innerHTML","stringify","parentNode","appendChild","classList","add","fail","Notification","exception","mustache","querySelectorAll","mustachecode","forEach"],"mappings":"yQAwBA,OACA,OACA,OACA,OACA,OACA,O,qXASMA,CAAAA,CAAc,4CAAG,WAAMC,CAAN,CAAiBC,CAAjB,CAA+BC,CAA/B,+FACnB,GAAI,CACAA,CAAO,CAAGC,IAAI,CAACC,KAAL,CAAWF,CAAX,CACb,CAAC,MAAOG,CAAP,CAAU,CACRC,UAAIC,KAAJ,CAAU,oDAAV,EACAD,UAAIC,KAAJ,CAAUF,CAAV,CACH,CANkB,eAQMG,WAAUC,gBAAV,CAA2BR,CAA3B,CAAyCC,CAAzC,CARN,iBAQZQ,CARY,GAQZA,IARY,CAQNC,CARM,GAQNA,EARM,CAUbC,CAVa,CAUKZ,CAAS,CAACa,aAAV,CAAwBC,UAAUC,gBAAlC,CAVL,gBAabP,WAAUQ,mBAAV,CAA8BJ,CAA9B,CAA+CF,CAA/C,CAAqDC,CAArD,CAba,yCAAH,uD,CAqBdM,CAAY,CAAG,SAAAjB,CAAS,CAAI,IACpBkB,CAAAA,CAAe,CAAGlB,CAAS,CAACa,aAAV,CAAwBC,UAAUK,cAAlC,CADE,CAEpBC,CAAgB,CAAGpB,CAAS,CAACa,aAAV,CAAwBC,UAAUO,eAAlC,CAFC,CAGpBpB,CAAY,CAAGD,CAAS,CAACsB,OAAV,CAAkBC,QAHb,CAItBrB,CAAO,CAAGF,CAAS,CAACa,aAAV,CAAwBC,UAAUU,kBAAlC,EAAsDC,WAJ1C,CAMpBC,CAAK,CAAGzB,CAAY,CAAC0B,KAAb,CAAmB,GAAnB,CANY,CAOpBC,CAAS,CAAGF,CAAK,CAACG,KAAN,EAPQ,CAQpBC,CAAI,CAAGJ,CAAK,CAACK,IAAN,CAAW,GAAX,CARa,CAUpBC,CAAO,CAAG,CACZC,UAAU,CAAE,2BADA,CAEZC,IAAI,CAAE,CACFN,SAAS,CAAEA,CADT,CAEFL,QAAQ,CAAEO,CAFR,CAGFK,SAAS,CAAEC,UAAOC,KAHhB,CAIFC,eAAe,GAJb,CAFM,CAVU,CAoB1BC,UAAKC,IAAL,CAAU,CAACR,CAAD,CAAV,EAAqB,CAArB,EACKS,IADL,CACU,SAACC,CAAD,CAAY,CAEdxB,CAAe,CAACO,WAAhB,CAA8BiB,CAA9B,CACA,GAAI,CAACxC,CAAL,CAAc,CACV,GAAMyC,CAAAA,CAAO,CAAGD,CAAM,CAACE,KAAP,CAAa,yCAAb,CAAhB,CACA1C,CAAO,CAAGyC,CAAO,CAAC,CAAD,CAAjB,CAEA,GAAME,CAAAA,CAAY,CAAGC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAArB,CACAF,CAAY,CAACG,SAAb,CAAyB7C,IAAI,CAAC8C,SAAL,CAAe9C,IAAI,CAACC,KAAL,CAAWF,CAAX,CAAf,CAAoC,IAApC,CAA0C,CAA1C,CAAzB,CACAkB,CAAgB,CAAC8B,UAAjB,CAA4BC,WAA5B,CAAwCN,CAAxC,EACAzB,CAAgB,CAACgC,SAAjB,CAA2BC,GAA3B,CAA+B,QAA/B,CACH,CACDtD,CAAc,CAACC,CAAD,CAAYC,CAAZ,CAA0BC,CAA1B,CACjB,CAdL,EAeKoD,IAfL,CAeUC,UAAaC,SAfvB,CAgBP,C,CAMYC,CAAQ,CAAG,UAAM,CAC1BX,QAAQ,CAACY,gBAAT,CAA0B5C,UAAU6C,YAApC,EAAkDC,OAAlD,CAA0D,SAAC5D,CAAD,CAAe,CACrEiB,CAAY,CAACjB,CAAD,CACf,CAFD,CAGH,C","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 * This is called from to render mustache templates\n *\n * @module tool_componentlibrary/mustache\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\nimport Ajax from 'core/ajax';\nimport Config from 'core/config';\nimport Templates from 'core/templates';\nimport Log from 'core/log';\nimport Notification from 'core/notification';\n\n/**\n * Handle a template loaded response.\n *\n * @param {String} container The template container\n * @param {String} templateName The template name\n * @param {String} context Data for the template.\n */\nconst renderTemplate = async(container, templateName, context) => {\n try {\n context = JSON.parse(context);\n } catch (e) {\n Log.debug('Could not parse json example context for template.');\n Log.debug(e);\n }\n\n const {html, js} = await Templates.renderForPromise(templateName, context);\n\n const rendercontainer = container.querySelector(selectors.mustacherendered);\n\n // Load the rendered content in the renderer tab.\n await Templates.replaceNodeContents(rendercontainer, html, js);\n};\n\n/**\n * Load the a template source from Moodle.\n *\n * @param {String} container The template container\n */\nconst loadTemplate = container => {\n const sourcecontainer = container.querySelector(selectors.mustachesource);\n const contextcontainer = container.querySelector(selectors.mustachecontext);\n const templateName = container.dataset.template;\n let context = container.querySelector(selectors.mustacherawcontext).textContent;\n\n const parts = templateName.split('/');\n const component = parts.shift();\n const name = parts.join('/');\n\n const request = {\n methodname: 'core_output_load_template',\n args: {\n component: component,\n template: name,\n themename: Config.theme,\n includecomments: true\n }\n };\n\n Ajax.call([request])[0]\n .done((source) => {\n // Load the source template in Template tab.\n sourcecontainer.textContent = source;\n if (!context) {\n const example = source.match(/Example context \\(json\\):([\\s\\S]+?)(}})/);\n context = example[1];\n // Load the variables in the Variables tab.\n const precontainer = document.createElement(\"pre\");\n precontainer.innerHTML = JSON.stringify(JSON.parse(context), null, 4);\n contextcontainer.parentNode.appendChild(precontainer);\n contextcontainer.classList.add('d-none');\n }\n renderTemplate(container, templateName, context);\n })\n .fail(Notification.exception);\n};\n\n/**\n * Initialize module\n *\n */\nexport const mustache = () => {\n document.querySelectorAll(selectors.mustachecode).forEach((container) => {\n loadTemplate(container);\n });\n};\n"],"file":"mustache.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/mustache.js"],"names":["renderTemplate","container","templateName","context","JSON","parse","e","Log","debug","Templates","renderForPromise","html","js","rendercontainer","querySelector","selectors","mustacherendered","replaceNodeContents","loadTemplate","sourcecontainer","mustachesource","contextcontainer","mustachecontext","dataset","template","mustacherawcontext","textContent","parts","split","component","shift","name","join","request","methodname","args","themename","Config","theme","includecomments","Ajax","call","done","source","example","match","precontainer","document","createElement","innerHTML","stringify","parentNode","appendChild","classList","add","fail","Notification","exception","mustache","querySelectorAll","mustachecode","forEach"],"mappings":"yQAuBA,OACA,OACA,OACA,OACA,OACA,O,qXAWMA,CAAAA,CAAc,4CAAG,WAAMC,CAAN,CAAiBC,CAAjB,CAA+BC,CAA/B,+FACnB,GAAI,CACAA,CAAO,CAAGC,IAAI,CAACC,KAAL,CAAWF,CAAX,CACb,CAAC,MAAOG,CAAP,CAAU,CACRC,UAAIC,KAAJ,CAAU,oDAAV,EACAD,UAAIC,KAAJ,CAAUF,CAAV,CACH,CANkB,eAQMG,WAAUC,gBAAV,CAA2BR,CAA3B,CAAyCC,CAAzC,CARN,iBAQZQ,CARY,GAQZA,IARY,CAQNC,CARM,GAQNA,EARM,CAUbC,CAVa,CAUKZ,CAAS,CAACa,aAAV,CAAwBC,UAAUC,gBAAlC,CAVL,gBAabP,WAAUQ,mBAAV,CAA8BJ,CAA9B,CAA+CF,CAA/C,CAAqDC,CAArD,CAba,yCAAH,uD,CAuBdM,CAAY,CAAG,SAAAjB,CAAS,CAAI,IACpBkB,CAAAA,CAAe,CAAGlB,CAAS,CAACa,aAAV,CAAwBC,UAAUK,cAAlC,CADE,CAEpBC,CAAgB,CAAGpB,CAAS,CAACa,aAAV,CAAwBC,UAAUO,eAAlC,CA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AQ,CAAG,UAAM,CAC1BX,QAAQ,CAACY,gBAAT,CAA0B5C,UAAU6C,YAApC,EAAkDC,OAAlD,CAA0D,SAAC5D,CAAD,CAAe,CACrEiB,CAAY,CAACjB,CAAD,CACf,CAFD,CAGH,C","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 * Render mustache template examples within the component library.\n *\n * @module tool_componentlibrary/mustache\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\nimport Ajax from 'core/ajax';\nimport Config from 'core/config';\nimport Templates from 'core/templates';\nimport Log from 'core/log';\nimport Notification from 'core/notification';\n\n/**\n * Handle a template loaded response.\n *\n * @method\n * @private\n * @param {String} container The template container\n * @param {String} templateName The template name\n * @param {String} context Data for the template.\n */\nconst renderTemplate = async(container, templateName, context) => {\n try {\n context = JSON.parse(context);\n } catch (e) {\n Log.debug('Could not parse json example context for template.');\n Log.debug(e);\n }\n\n const {html, js} = await Templates.renderForPromise(templateName, context);\n\n const rendercontainer = container.querySelector(selectors.mustacherendered);\n\n // Load the rendered content in the renderer tab.\n await Templates.replaceNodeContents(rendercontainer, html, js);\n};\n\n/**\n * Load the a template source from Moodle.\n *\n * @method\n * @private\n * @param {String} container The template container\n */\nconst loadTemplate = container => {\n const sourcecontainer = container.querySelector(selectors.mustachesource);\n const contextcontainer = container.querySelector(selectors.mustachecontext);\n const templateName = container.dataset.template;\n let context = container.querySelector(selectors.mustacherawcontext).textContent;\n\n const parts = templateName.split('/');\n const component = parts.shift();\n const name = parts.join('/');\n\n const request = {\n methodname: 'core_output_load_template',\n args: {\n component: component,\n template: name,\n themename: Config.theme,\n includecomments: true\n }\n };\n\n Ajax.call([request])[0]\n .done((source) => {\n // Load the source template in Template tab.\n sourcecontainer.textContent = source;\n if (!context) {\n const example = source.match(/Example context \\(json\\):([\\s\\S]+?)(}})/);\n context = example[1];\n // Load the variables in the Variables tab.\n const precontainer = document.createElement(\"pre\");\n precontainer.innerHTML = JSON.stringify(JSON.parse(context), null, 4);\n contextcontainer.parentNode.appendChild(precontainer);\n contextcontainer.classList.add('d-none');\n }\n renderTemplate(container, templateName, context);\n })\n .fail(Notification.exception);\n};\n\n/**\n * Initialize the module.\n *\n * @method\n */\nexport const mustache = () => {\n document.querySelectorAll(selectors.mustachecode).forEach((container) => {\n loadTemplate(container);\n });\n};\n"],"file":"mustache.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/build/search.min.js.map b/admin/tool/componentlibrary/amd/build/search.min.js.map index 6aa211e0a8f..b3ff1293d90 100644 --- a/admin/tool/componentlibrary/amd/build/search.min.js.map +++ b/admin/tool/componentlibrary/amd/build/search.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/search.js"],"names":["lunrIndex","pagesIndex","fetchJson","jsonFile","fetch","response","ok","Log","debug","status","json","initLunr","then","jsondata","ref","field","boost","forEach","p","add","catch","Notification","exception","initUI","searchInput","document","querySelector","selectors","searchinput","addEventListener","e","query","currentTarget","value","length","dropdownmenu","classList","remove","renderResults","searchIndex","keyCode","enter","preventDefault","escape","search","map","result","filter","page","uri","results","dropdownMenu","innerHTML","baseUrl","M","cfg","wwwroot","slice","link","createElement","chapter","split","appendChild","createTextNode","title","href"],"mappings":"sQAwBA,OACA,OACA,OACA,O,qXAGIA,CAAAA,CAAS,CAAG,I,CACZC,CAAU,CAAG,I,CAQXC,CAAS,4CAAG,WAAMC,CAAN,wGACSC,CAAAA,KAAK,CAACD,CAAD,CADd,QACRE,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H,CAA3B,eAAwCd,CAAM,CAACkB,KAA/C,EAAjB,EACAN,CAAI,CAACtB,SAAL,CAAejB,GAAf,CAAmB,eAAnB,EACAuC,CAAI,CAACO,IAAL,CAAYZ,CAAO,CAAGP,CAAM,CAACG,GAA7B,CAEAE,CAAY,CAACW,WAAb,CAAyBJ,CAAzB,CACH,CARD,EAUAP,CAAY,CAACf,SAAb,CAAuBjB,GAAvB,CAA2B,MAA3B,CACH,C,UAOqB,QAATyB,CAAAA,MAAS,CAAAzC,CAAQ,CAAI,CAC9BQ,CAAQ,CAACR,CAAD,CAAR,CACAoB,CAAM,EACT,C","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 * Interface to the Lunr search engines.\n *\n * @module tool_componentlibrary/search\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport lunrJs from 'tool_componentlibrary/lunr';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Log from 'core/log';\nimport Notification from 'core/notification';\nimport {enter, escape} from 'core/key_codes';\n\nlet lunrIndex = null;\nlet pagesIndex = null;\n\n/**\n * Get the jsonFile that is generated when the component library is build.\n *\n * @param {String} jsonFile the URL to the json file.\n * @retrun {Object}\n */\nconst fetchJson = async(jsonFile) => {\n const response = await fetch(jsonFile);\n\n if (!response.ok) {\n Log.debug(`Error getting Hugo index file: ${response.status}`);\n }\n\n return await response.json();\n};\n\n/**\n * Initiate lunr on the data in the jsonFile and add the jsondata to the pagesIndex\n *\n * @param {String} jsonFile the URL to the json file.\n */\nconst initLunr = jsonFile => {\n fetchJson(jsonFile).then(jsondata => {\n pagesIndex = jsondata;\n // Using an arrow function here will break lunr on compile.\n lunrIndex = lunrJs(function() {\n this.ref('uri');\n this.field('title', {boost: 10});\n this.field('content');\n this.field('tags', {boost: 5});\n jsondata.forEach(p => {\n this.add(p);\n });\n });\n return null;\n }).catch(Notification.exception);\n};\n\n/**\n * Setup the eventlistener to listen on user input on the search field.\n */\nconst initUI = () => {\n const searchInput = document.querySelector(selectors.searchinput);\n searchInput.addEventListener('keyup', e => {\n const query = e.currentTarget.value;\n if (query.length < 2) {\n document.querySelector(selectors.dropdownmenu).classList.remove('show');\n return;\n }\n renderResults(searchIndex(query));\n });\n searchInput.addEventListener('keydown', e => {\n if (e.keyCode === enter) {\n e.preventDefault();\n }\n if (e.keyCode === escape) {\n searchInput.value = '';\n }\n });\n};\n\n/**\n * Trigger a search in lunr and transform the result.\n *\n * @param {String} query\n * @return {Array} results\n */\nconst searchIndex = query => {\n // Find the item in our index corresponding to the lunr one to have more info\n // Lunr result:\n // {ref: \"/section/page1\", score: 0.2725657778206127}\n // Our result:\n // {title:\"Page1\", href:\"/section/page1\", ...}\n\n return lunrIndex.search(query + ' ' + query + '*').map(result => {\n return pagesIndex.filter(page => {\n return page.uri === result.ref;\n })[0];\n });\n};\n\n/**\n * Display the 10 first results\n *\n * @param {Array} results to display\n */\nconst renderResults = results => {\n const dropdownMenu = document.querySelector(selectors.dropdownmenu);\n if (!results.length) {\n dropdownMenu.classList.remove('show');\n return;\n }\n\n // Clear out the results.\n dropdownMenu.innerHTML = '';\n\n const baseUrl = M.cfg.wwwroot + '/admin/tool/componentlibrary/docspage.php';\n\n // Only show the ten first results\n results.slice(0, 10).forEach(function(result) {\n const link = document.createElement(\"a\");\n const chapter = result.uri.split('/')[1];\n link.appendChild(document.createTextNode(`${chapter} > ${result.title}`));\n link.classList.add('dropdown-item');\n link.href = baseUrl + result.uri;\n\n dropdownMenu.appendChild(link);\n });\n\n dropdownMenu.classList.add('show');\n};\n\n/**\n * Initialize module.\n *\n * @param {String} jsonFile Full path to the search DB json file.\n */\nexport const search = jsonFile => {\n initLunr(jsonFile);\n initUI();\n};\n"],"file":"search.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/search.js"],"names":["lunrIndex","pagesIndex","fetchJson","jsonFile","fetch","response","ok","Log","debug","status","json","initLunr","then","jsondata","ref","field","boost","forEach","p","add","catch","Notification","exception","initUI","searchInput","document","querySelector","selectors","searchinput","addEventListener","e","query","currentTarget","value","length","dropdownmenu","classList","remove","renderResults","searchIndex","keyCode","enter","preventDefault","escape","search","map","result","filter","page","uri","results","dropdownMenu","innerHTML","baseUrl","M","cfg","wwwroot","slice","link","createElement","chapter","split","appendChild","createTextNode","title","href"],"mappings":"sQAuBA,OACA,OACA,OACA,O,qXAGIA,CAAAA,CAAS,CAAG,I,CACZC,CAAU,CAAG,I,CAUXC,CAAS,4CAAG,WAAMC,CAAN,wGACSC,CAAAA,KAAK,CAACD,CAAD,CADd,QACRE,CADQ,QAGd,GAAI,CAACA,CAAQ,CAACC,EAAd,CAAkB,CACdC,UAAIC,KAAJ,0CAA4CH,CAAQ,CAACI,MAArD,EACH,CALa,eAODJ,CAAAA,CAAQ,CAACK,IAAT,EAPC,iFAAH,uD,CAiBTC,CAAQ,CAAG,SAAAR,CAAQ,CAAI,CACzBD,CAAS,CAACC,CAAD,CAAT,CAAoBS,IAApB,CAAyB,SAAAC,CAAQ,CAAI,CACjCZ,CAAU,CAAGY,CAAb,CAEAb,CAAS,CAAG,cAAO,UAAW,YAC1B,KAAKc,GAAL,CAAS,KAAT,EACA,KAAKC,KAAL,CAAW,OAAX,CAAoB,CAACC,KAAK,CAAE,EAAR,CAApB,EACA,KAAKD,KAAL,CAAW,SAAX,EACA,KAAKA,KAAL,CAAW,MAAX,CAAmB,CAACC,KAAK,CAAE,CAAR,CAAnB,EACAH,CAAQ,CAACI,OAAT,CAAiB,SAAAC,CAAC,CAAI,CA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AAO,CAAI,CAC7B,GAAMC,CAAAA,CAAY,CAAG1B,QAAQ,CAACC,aAAT,CAAuBC,UAAUQ,YAAjC,CAArB,CACA,GAAI,CAACe,CAAO,CAAChB,MAAb,CAAqB,CACjBiB,CAAY,CAACf,SAAb,CAAuBC,MAAvB,CAA8B,MAA9B,EACA,MACH,CAGDc,CAAY,CAACC,SAAb,CAAyB,EAAzB,CAEA,GAAMC,CAAAA,CAAO,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,2CAAhC,CAGAN,CAAO,CAACO,KAAR,CAAc,CAAd,CAAiB,EAAjB,EAAqBxC,OAArB,CAA6B,SAAS6B,CAAT,CAAiB,IACpCY,CAAAA,CAAI,CAAGjC,QAAQ,CAACkC,aAAT,CAAuB,GAAvB,CAD6B,CAEpCC,CAAO,CAAGd,CAAM,CAACG,GAAP,CAAWY,KAAX,CAAiB,GAAjB,EAAsB,CAAtB,CAF0B,CAG1CH,CAAI,CAACI,WAAL,CAAiBrC,QAAQ,CAACsC,cAAT,WAA2BH,CAA3B,eAAwCd,CAAM,CAACkB,KAA/C,EAAjB,EACAN,CAAI,CAACtB,SAAL,CAAejB,GAAf,CAAmB,eAAnB,EACAuC,CAAI,CAACO,IAAL,CAAYZ,CAAO,CAAGP,CAAM,CAACG,GAA7B,CAEAE,CAAY,CAACW,WAAb,CAAyBJ,CAAzB,CACH,CARD,EAUAP,CAAY,CAACf,SAAb,CAAuBjB,GAAvB,CAA2B,MAA3B,CACH,C,UAQqB,QAATyB,CAAAA,MAAS,CAAAzC,CAAQ,CAAI,CAC9BQ,CAAQ,CAACR,CAAD,CAAR,CACAoB,CAAM,EACT,C","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 * Interface to the Lunr search engines.\n *\n * @module tool_componentlibrary/search\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport lunrJs from 'tool_componentlibrary/lunr';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Log from 'core/log';\nimport Notification from 'core/notification';\nimport {enter, escape} from 'core/key_codes';\n\nlet lunrIndex = null;\nlet pagesIndex = null;\n\n/**\n * Get the jsonFile that is generated when the component library is build.\n *\n * @method\n * @private\n * @param {String} jsonFile the URL to the json file.\n * @return {Object}\n */\nconst fetchJson = async(jsonFile) => {\n const response = await fetch(jsonFile);\n\n if (!response.ok) {\n Log.debug(`Error getting Hugo index file: ${response.status}`);\n }\n\n return await response.json();\n};\n\n/**\n * Initiate lunr on the data in the jsonFile and add the jsondata to the pagesIndex\n *\n * @method\n * @private\n * @param {String} jsonFile the URL to the json file.\n */\nconst initLunr = jsonFile => {\n fetchJson(jsonFile).then(jsondata => {\n pagesIndex = jsondata;\n // Using an arrow function here will break lunr on compile.\n lunrIndex = lunrJs(function() {\n this.ref('uri');\n this.field('title', {boost: 10});\n this.field('content');\n this.field('tags', {boost: 5});\n jsondata.forEach(p => {\n this.add(p);\n });\n });\n return null;\n }).catch(Notification.exception);\n};\n\n/**\n * Setup the eventlistener to listen on user input on the search field.\n *\n * @method\n * @private\n */\nconst initUI = () => {\n const searchInput = document.querySelector(selectors.searchinput);\n searchInput.addEventListener('keyup', e => {\n const query = e.currentTarget.value;\n if (query.length < 2) {\n document.querySelector(selectors.dropdownmenu).classList.remove('show');\n return;\n }\n renderResults(searchIndex(query));\n });\n searchInput.addEventListener('keydown', e => {\n if (e.keyCode === enter) {\n e.preventDefault();\n }\n if (e.keyCode === escape) {\n searchInput.value = '';\n }\n });\n};\n\n/**\n * Trigger a search in lunr and transform the result.\n *\n * @method\n * @private\n * @param {String} query\n * @return {Array} results\n */\nconst searchIndex = query => {\n // Find the item in our index corresponding to the lunr one to have more info\n // Lunr result:\n // {ref: \"/section/page1\", score: 0.2725657778206127}\n // Our result:\n // {title:\"Page1\", href:\"/section/page1\", ...}\n\n return lunrIndex.search(query + ' ' + query + '*').map(result => {\n return pagesIndex.filter(page => {\n return page.uri === result.ref;\n })[0];\n });\n};\n\n/**\n * Display the 10 first results\n *\n * @method\n * @private\n * @param {Array} results to display\n */\nconst renderResults = results => {\n const dropdownMenu = document.querySelector(selectors.dropdownmenu);\n if (!results.length) {\n dropdownMenu.classList.remove('show');\n return;\n }\n\n // Clear out the results.\n dropdownMenu.innerHTML = '';\n\n const baseUrl = M.cfg.wwwroot + '/admin/tool/componentlibrary/docspage.php';\n\n // Only show the ten first results\n results.slice(0, 10).forEach(function(result) {\n const link = document.createElement(\"a\");\n const chapter = result.uri.split('/')[1];\n link.appendChild(document.createTextNode(`${chapter} > ${result.title}`));\n link.classList.add('dropdown-item');\n link.href = baseUrl + result.uri;\n\n dropdownMenu.appendChild(link);\n });\n\n dropdownMenu.classList.add('show');\n};\n\n/**\n * Initialize module.\n *\n * @method\n * @param {String} jsonFile Full path to the search DB json file.\n */\nexport const search = jsonFile => {\n initLunr(jsonFile);\n initUI();\n};\n"],"file":"search.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/build/selectors.min.js.map b/admin/tool/componentlibrary/amd/build/selectors.min.js.map index 0ec1251ee04..55c47bad35a 100644 --- a/admin/tool/componentlibrary/amd/build/selectors.min.js.map +++ b/admin/tool/componentlibrary/amd/build/selectors.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/selectors.js"],"names":["clipboardbutton","clipboardcontent","searchinput","searchsubmit","dropdownmenu","componentlibrary","jscode","mustachecode","mustacherawcontext","mustacherendered","mustachesource","mustachecontext"],"mappings":"2JAwBe,CACXA,eAAe,CAAE,gBADN,CAEXC,gBAAgB,CAAE,iCAFP,CAGXC,WAAW,CAAE,mCAHF,CAIXC,YAAY,CAAE,yCAJH,CAKXC,YAAY,CAAE,4CALH,CAMXC,gBAAgB,CAAE,oCANP,CAOXC,MAAM,CAAE,yBAPG,CAQXC,YAAY,CAAE,gCARH,CASXC,kBAAkB,CAAE,8BATT,CAUXC,gBAAgB,CAAE,oCAVP,CAWXC,cAAc,CAAE,kCAXL,CAYXC,eAAe,CAAE,mCAZN,C","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 * Selectors for the component library\n *\n * @module tool_componentlibrary/selectors\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default {\n clipboardbutton: '.btn-clipboard',\n clipboardcontent: 'figure.highlight, div.highlight',\n searchinput: '[data-region=\"docsearch\"] input',\n searchsubmit: '[data-region=\"docsearch\"] .btn-submit',\n dropdownmenu: '[data-region=\"docsearch\"] .dropdown-menu',\n componentlibrary: '[data-region=\"componentlibrary\"]',\n jscode: '[data-action=\"runjs\"]',\n mustachecode: '[data-region=\"mustachecode\"]',\n mustacherawcontext: '[data-region=\"rawcontext\"]',\n mustacherendered: '[data-region=\"mustacherendered\"]',\n mustachesource: '[data-region=\"mustachesource\"]',\n mustachecontext: '[data-region=\"mustachecontext\"]',\n};\n"],"file":"selectors.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/selectors.js"],"names":["clipboardbutton","clipboardcontent","searchinput","searchsubmit","dropdownmenu","componentlibrary","jscode","mustachecode","mustacherawcontext","mustacherendered","mustachesource","mustachecontext"],"mappings":"2JAsBe,CAMXA,eAAe,CAAE,gBANN,CAaXC,gBAAgB,CAAE,iCAbP,CAoBXC,WAAW,CAAE,mCApBF,CA2BXC,YAAY,CAAE,yCA3BH,CAkCXC,YAAY,CAAE,4CAlCH,CAyCXC,gBAAgB,CAAE,oCAzCP,CAgDXC,MAAM,CAAE,yBAhDG,CAuDXC,YAAY,CAAE,gCAvDH,CA8DXC,kBAAkB,CAAE,8BA9DT,CAqEXC,gBAAgB,CAAE,oCArEP,CA4EXC,cAAc,CAAE,kCA5EL,CAmFXC,eAAe,CAAE,mCAnFN,C","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 * Selectors for the component library\n *\n * @module tool_componentlibrary/selectors\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n /**\n * A selector relating to the 'Copy to clipboard' button.\n *\n * @type {string}\n */\n clipboardbutton: '.btn-clipboard',\n\n /**\n * A selector relating to the content copied by the 'Copy to clipboard' button.\n *\n * @type {string}\n */\n clipboardcontent: 'figure.highlight, div.highlight',\n\n /**\n * A selector relating to the 'Search' text input.\n *\n * @type {string}\n */\n searchinput: '[data-region=\"docsearch\"] input',\n\n /**\n * A selector relating to the 'Search' submit btton.\n *\n * @type {string}\n */\n searchsubmit: '[data-region=\"docsearch\"] .btn-submit',\n\n /**\n * A selector relating to the search dropdown menu.\n *\n * @type {string}\n */\n dropdownmenu: '[data-region=\"docsearch\"] .dropdown-menu',\n\n /**\n * A selector relating to the entire Component Library content region.\n *\n * @type {string}\n */\n componentlibrary: '[data-region=\"componentlibrary\"]',\n\n /**\n * A selector relating to JS Code which is to be run for examples to function.\n *\n * @type {string}\n */\n jscode: '[data-action=\"runjs\"]',\n\n /**\n * A selector relating to Mustache Template code regions.\n *\n * @type {string}\n */\n mustachecode: '[data-region=\"mustachecode\"]',\n\n /**\n * A selector relating to raw Mustache content regions.\n *\n * @type {string}\n */\n mustacherawcontext: '[data-region=\"rawcontext\"]',\n\n /**\n * A selector relating to rendered Mustache content regions.\n *\n * @type {string}\n */\n mustacherendered: '[data-region=\"mustacherendered\"]',\n\n /**\n * A selector relating to Mustache source code regions.\n *\n * @type {string}\n */\n mustachesource: '[data-region=\"mustachesource\"]',\n\n /**\n * A selector relating to Mustache context regions.\n *\n * @type {string}\n */\n mustachecontext: '[data-region=\"mustachecontext\"]',\n};\n"],"file":"selectors.min.js"} \ No newline at end of file diff --git a/admin/tool/componentlibrary/amd/src/clipboardwrapper.js b/admin/tool/componentlibrary/amd/src/clipboardwrapper.js index 9b52314900c..3e3c9ef9ac0 100644 --- a/admin/tool/componentlibrary/amd/src/clipboardwrapper.js +++ b/admin/tool/componentlibrary/amd/src/clipboardwrapper.js @@ -14,10 +14,9 @@ // along with Moodle. If not, see . /** - * Interface to using clipboard.js + * Wrapper to ensure that all Hugo example snippets have a "Copy to clipboard" button. * * @module tool_componentlibrary/clipboardwrapper - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -29,6 +28,8 @@ let idCounter = 0; /** * Initialise the clipboard button on all reusable code. + * + * @method */ export const clipboardWrapper = async() => { document.querySelectorAll(selectors.clipboardcontent).forEach(element => { diff --git a/admin/tool/componentlibrary/amd/src/jsrunner.js b/admin/tool/componentlibrary/amd/src/jsrunner.js index c8827468d99..ccef9f6a132 100644 --- a/admin/tool/componentlibrary/amd/src/jsrunner.js +++ b/admin/tool/componentlibrary/amd/src/jsrunner.js @@ -14,10 +14,9 @@ // along with Moodle. If not, see . /** - * This is called from to run any js code + * Run the JS required for example code to work in the library. * * @module tool_componentlibrary/jsrunner - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -29,6 +28,8 @@ import selectors from 'tool_componentlibrary/selectors'; * the Moodle mustache {{js}} code... {{/js}} syntax into a div with * attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html. * This code fetches and runs the JavaScript content. + * + * @method */ export const jsRunner = () => { const compLib = document.querySelector(selectors.componentlibrary); diff --git a/admin/tool/componentlibrary/amd/src/loader.js b/admin/tool/componentlibrary/amd/src/loader.js index c7c201cdffd..3b6c28fe7eb 100644 --- a/admin/tool/componentlibrary/amd/src/loader.js +++ b/admin/tool/componentlibrary/amd/src/loader.js @@ -17,7 +17,6 @@ * This initialises the component library JS * * @module tool_componentlibrary/loader - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/componentlibrary/amd/src/mustache.js b/admin/tool/componentlibrary/amd/src/mustache.js index 131a5fd6327..4280317a43c 100644 --- a/admin/tool/componentlibrary/amd/src/mustache.js +++ b/admin/tool/componentlibrary/amd/src/mustache.js @@ -14,10 +14,9 @@ // along with Moodle. If not, see . /** - * This is called from to render mustache templates + * Render mustache template examples within the component library. * * @module tool_componentlibrary/mustache - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -32,6 +31,8 @@ import Notification from 'core/notification'; /** * Handle a template loaded response. * + * @method + * @private * @param {String} container The template container * @param {String} templateName The template name * @param {String} context Data for the template. @@ -55,6 +56,8 @@ const renderTemplate = async(container, templateName, context) => { /** * Load the a template source from Moodle. * + * @method + * @private * @param {String} container The template container */ const loadTemplate = container => { @@ -96,8 +99,9 @@ const loadTemplate = container => { }; /** - * Initialize module + * Initialize the module. * + * @method */ export const mustache = () => { document.querySelectorAll(selectors.mustachecode).forEach((container) => { diff --git a/admin/tool/componentlibrary/amd/src/search.js b/admin/tool/componentlibrary/amd/src/search.js index a088bae253c..5bdb21c01cf 100644 --- a/admin/tool/componentlibrary/amd/src/search.js +++ b/admin/tool/componentlibrary/amd/src/search.js @@ -17,7 +17,6 @@ * Interface to the Lunr search engines. * * @module tool_componentlibrary/search - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -34,8 +33,10 @@ let pagesIndex = null; /** * Get the jsonFile that is generated when the component library is build. * + * @method + * @private * @param {String} jsonFile the URL to the json file. - * @retrun {Object} + * @return {Object} */ const fetchJson = async(jsonFile) => { const response = await fetch(jsonFile); @@ -50,6 +51,8 @@ const fetchJson = async(jsonFile) => { /** * Initiate lunr on the data in the jsonFile and add the jsondata to the pagesIndex * + * @method + * @private * @param {String} jsonFile the URL to the json file. */ const initLunr = jsonFile => { @@ -71,6 +74,9 @@ const initLunr = jsonFile => { /** * Setup the eventlistener to listen on user input on the search field. + * + * @method + * @private */ const initUI = () => { const searchInput = document.querySelector(selectors.searchinput); @@ -95,6 +101,8 @@ const initUI = () => { /** * Trigger a search in lunr and transform the result. * + * @method + * @private * @param {String} query * @return {Array} results */ @@ -115,6 +123,8 @@ const searchIndex = query => { /** * Display the 10 first results * + * @method + * @private * @param {Array} results to display */ const renderResults = results => { @@ -146,6 +156,7 @@ const renderResults = results => { /** * Initialize module. * + * @method * @param {String} jsonFile Full path to the search DB json file. */ export const search = jsonFile => { diff --git a/admin/tool/componentlibrary/amd/src/selectors.js b/admin/tool/componentlibrary/amd/src/selectors.js index 432e6407984..a307b08ed90 100644 --- a/admin/tool/componentlibrary/amd/src/selectors.js +++ b/admin/tool/componentlibrary/amd/src/selectors.js @@ -17,22 +17,91 @@ * Selectors for the component library * * @module tool_componentlibrary/selectors - * @package tool_componentlibrary * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - export default { + /** + * A selector relating to the 'Copy to clipboard' button. + * + * @type {string} + */ clipboardbutton: '.btn-clipboard', + + /** + * A selector relating to the content copied by the 'Copy to clipboard' button. + * + * @type {string} + */ clipboardcontent: 'figure.highlight, div.highlight', + + /** + * A selector relating to the 'Search' text input. + * + * @type {string} + */ searchinput: '[data-region="docsearch"] input', + + /** + * A selector relating to the 'Search' submit btton. + * + * @type {string} + */ searchsubmit: '[data-region="docsearch"] .btn-submit', + + /** + * A selector relating to the search dropdown menu. + * + * @type {string} + */ dropdownmenu: '[data-region="docsearch"] .dropdown-menu', + + /** + * A selector relating to the entire Component Library content region. + * + * @type {string} + */ componentlibrary: '[data-region="componentlibrary"]', + + /** + * A selector relating to JS Code which is to be run for examples to function. + * + * @type {string} + */ jscode: '[data-action="runjs"]', + + /** + * A selector relating to Mustache Template code regions. + * + * @type {string} + */ mustachecode: '[data-region="mustachecode"]', + + /** + * A selector relating to raw Mustache content regions. + * + * @type {string} + */ mustacherawcontext: '[data-region="rawcontext"]', + + /** + * A selector relating to rendered Mustache content regions. + * + * @type {string} + */ mustacherendered: '[data-region="mustacherendered"]', + + /** + * A selector relating to Mustache source code regions. + * + * @type {string} + */ mustachesource: '[data-region="mustachesource"]', + + /** + * A selector relating to Mustache context regions. + * + * @type {string} + */ mustachecontext: '[data-region="mustachecontext"]', };