From 3ff84d3eb7981f97b34b94e3441d40eee97b9be7 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 7 Jul 2023 16:31:54 +0800 Subject: [PATCH] MDL-78316 core: Improve jsdoc typedef for icons --- lib/amd/build/icon_system_fontawesome.min.js.map | 2 +- lib/amd/src/icon_system_fontawesome.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) rewrite lib/amd/build/icon_system_fontawesome.min.js.map (82%) diff --git a/lib/amd/build/icon_system_fontawesome.min.js.map b/lib/amd/build/icon_system_fontawesome.min.js.map dissimilarity index 82% index a302c5fefe8..3b7db8da356 100644 --- a/lib/amd/build/icon_system_fontawesome.min.js.map +++ b/lib/amd/build/icon_system_fontawesome.min.js.map @@ -1 +1 @@ -{"version":3,"file":"icon_system_fontawesome.min.js","sources":["../src/icon_system_fontawesome.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 * An Icon System implementation for FontAwesome.\n *\n * @module core/icon_system_fontawesome\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from './ajax';\nimport LocalStorage from './localstorage';\nimport IconSystem from './icon_system';\nimport * as Mustache from './mustache';\nimport * as Config from './config';\nimport * as Url from './url';\n\n/**\n * The FontAwesome icon system.\n */\nexport default class IconSystemFontawesome extends IconSystem {\n /**\n * @var {Map} staticMap A map of icon names to FA Icon.\n * @private\n */\n static staticMap = null;\n\n /**\n * @var {Promise} fetchPromise The promise used when fetching the result\n * @private\n */\n static fetchPromise = null;\n\n /**\n * @var {string} cacheKey The key used to store the icon map in LocalStorage.\n * @private\n */\n static cacheKey = `core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;\n\n /**\n * Prefetch resources so later calls to renderIcon can be resolved synchronously.\n *\n * @returns {Promise}\n */\n init() {\n if (IconSystemFontawesome.staticMap) {\n return Promise.resolve(this);\n }\n\n if (this.getMapFromCache()) {\n return Promise.resolve(this);\n }\n\n if (IconSystemFontawesome.fetchPromise) {\n return IconSystemFontawesome.fetchPromise;\n }\n\n return this.fetchMapFromServer();\n }\n\n /**\n * Get the icon map from LocalStorage.\n *\n * @private\n * @returns {Map}\n */\n getMapFromCache() {\n const map = LocalStorage.get(IconSystemFontawesome.cacheKey);\n if (map) {\n IconSystemFontawesome.staticMap = new Map(JSON.parse(map));\n }\n return IconSystemFontawesome.staticMap;\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @private\n * @returns {Promise}\n */\n _fetchMapFromServer() {\n return fetchMany([{\n methodname: 'core_output_load_fontawesome_icon_system_map',\n args: {\n themename: Config.theme,\n },\n }], true, false, false, 0, Config.themerev)[0];\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @returns {Promise}\n * @private\n */\n async fetchMapFromServer() {\n IconSystemFontawesome.fetchPromise = (async () => {\n const mapData = await this._fetchMapFromServer();\n\n IconSystemFontawesome.staticMap = new Map(Object.entries(mapData).map(([, value]) => ([\n `${value.component}/${value.pix}`,\n value.to,\n ])));\n LocalStorage.set(\n IconSystemFontawesome.cacheKey,\n JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries())),\n );\n\n return this;\n })();\n\n return IconSystemFontawesome.fetchPromise;\n }\n\n /**\n * Render an icon.\n *\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @param {string} template\n * @return {string} The rendered HTML content\n */\n renderIcon(key, component, title, template) {\n const iconKey = `${component}/${key}`;\n const mappedIcon = IconSystemFontawesome.staticMap.get(iconKey);\n const unmappedIcon = this.getUnmappedIcon(mappedIcon, key, component, title);\n\n const context = {\n title,\n unmappedIcon,\n alt: title,\n key: mappedIcon,\n };\n\n if (typeof title === \"undefined\" || title === '') {\n context['aria-hidden'] = true;\n }\n\n return Mustache.render(template, context).trim();\n }\n\n /**\n * Get the unamapped icon content, if the icon is not mapped.\n *\n * @param {object>} mappedIcon\n * @param {string} key\n * @param {string} component\n * @param {StaticRange} title\n * @returns {object>|null}\n * @private\n */\n getUnmappedIcon(mappedIcon, key, component, title) {\n if (mappedIcon) {\n return null;\n }\n\n return {\n attributes: [\n {name: 'src', value: Url.imageUrl(key, component)},\n {name: 'alt', value: title},\n {name: 'title', value: title}\n ],\n };\n }\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {string}\n * @method getTemplateName\n */\n getTemplateName() {\n return 'core/pix_icon_fontawesome';\n }\n}\n"],"names":["IconSystemFontawesome","IconSystem","init","staticMap","this","getMapFromCache","Promise","resolve","fetchPromise","fetchMapFromServer","map","LocalStorage","get","cacheKey","Map","JSON","parse","_fetchMapFromServer","methodname","args","themename","Config","theme","themerev","mapData","Object","entries","_ref","value","component","pix","to","set","stringify","Array","from","renderIcon","key","title","template","iconKey","mappedIcon","context","unmappedIcon","getUnmappedIcon","alt","Mustache","render","trim","attributes","name","Url","imageUrl","getTemplateName"],"mappings":"iqDAiCqBA,8BAA8BC,qBAwB/CC,cACQF,sBAAsBG,WAItBC,KAAKC,kBAHEC,QAAQC,QAAQH,MAOvBJ,sBAAsBQ,aACfR,sBAAsBQ,aAG1BJ,KAAKK,qBAShBJ,wBACUK,IAAMC,sBAAaC,IAAIZ,sBAAsBa,iBAC/CH,MACAV,sBAAsBG,UAAY,IAAIW,IAAIC,KAAKC,MAAMN,OAElDV,sBAAsBG,UASjCc,6BACW,cAAU,CAAC,CACdC,WAAY,+CACZC,KAAM,CACFC,UAAWC,OAAOC,UAEtB,GAAM,GAAO,EAAO,EAAGD,OAAOE,UAAU,qCAU5CvB,sBAAsBQ,aAAe,iBAC3BgB,cAAgBpB,KAAKa,6BAE3BjB,sBAAsBG,UAAY,IAAIW,IAAIW,OAAOC,QAAQF,SAASd,KAAIiB,YAAIC,kBAAY,WAC/EA,MAAMC,sBAAaD,MAAME,KAC5BF,MAAMG,8BAEGC,IACThC,sBAAsBa,SACtBE,KAAKkB,UAAUC,MAAMC,KAAKnC,sBAAsBG,UAAUuB,aAGvDtB,MAZ0B,GAe9BJ,sBAAsBQ,aAYjC4B,WAAWC,IAAKR,UAAWS,MAAOC,gBACxBC,kBAAaX,sBAAaQ,KAC1BI,WAAazC,sBAAsBG,UAAUS,IAAI4B,SAGjDE,QAAU,CACZJ,MAAAA,MACAK,aAJiBvC,KAAKwC,gBAAgBH,WAAYJ,IAAKR,UAAWS,OAKlEO,IAAKP,MACLD,IAAKI,wBAGY,IAAVH,OAAmC,KAAVA,QAChCI,QAAQ,gBAAiB,GAGtBI,SAASC,OAAOR,SAAUG,SAASM,OAa9CJ,gBAAgBH,WAAYJ,IAAKR,UAAWS,cACpCG,WACO,KAGJ,CACHQ,WAAY,CACR,CAACC,KAAM,MAAOtB,MAAOuB,IAAIC,SAASf,IAAKR,YACvC,CAACqB,KAAM,MAAOtB,MAAOU,OACrB,CAACY,KAAM,QAAStB,MAAOU,SAWnCe,wBACW,2FAzJMrD,kCAKE,sBALFA,qCAWK,sBAXLA,iEAiB0BqB,OAAOC"} \ No newline at end of file +{"version":3,"file":"icon_system_fontawesome.min.js","sources":["../src/icon_system_fontawesome.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 * An Icon System implementation for FontAwesome.\n *\n * @module core/icon_system_fontawesome\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from './ajax';\nimport LocalStorage from './localstorage';\nimport IconSystem from './icon_system';\nimport * as Mustache from './mustache';\nimport * as Config from './config';\nimport * as Url from './url';\n\n/**\n * An set of properties for an icon.\n * @typedef {object} IconProperties\n * @property {array} attributes\n * @private\n */\n\n/**\n * The FontAwesome icon system.\n */\nexport default class IconSystemFontawesome extends IconSystem {\n /**\n * @var {Map} staticMap A map of icon names to FA Icon.\n * @private\n */\n static staticMap = null;\n\n /**\n * @var {Promise} fetchPromise The promise used when fetching the result\n * @private\n */\n static fetchPromise = null;\n\n /**\n * @var {string} cacheKey The key used to store the icon map in LocalStorage.\n * @private\n */\n static cacheKey = `core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;\n\n /**\n * Prefetch resources so later calls to renderIcon can be resolved synchronously.\n *\n * @returns {Promise}\n */\n init() {\n if (IconSystemFontawesome.staticMap) {\n return Promise.resolve(this);\n }\n\n if (this.getMapFromCache()) {\n return Promise.resolve(this);\n }\n\n if (IconSystemFontawesome.fetchPromise) {\n return IconSystemFontawesome.fetchPromise;\n }\n\n return this.fetchMapFromServer();\n }\n\n /**\n * Get the icon map from LocalStorage.\n *\n * @private\n * @returns {Map}\n */\n getMapFromCache() {\n const map = LocalStorage.get(IconSystemFontawesome.cacheKey);\n if (map) {\n IconSystemFontawesome.staticMap = new Map(JSON.parse(map));\n }\n return IconSystemFontawesome.staticMap;\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @private\n * @returns {Promise}\n */\n _fetchMapFromServer() {\n return fetchMany([{\n methodname: 'core_output_load_fontawesome_icon_system_map',\n args: {\n themename: Config.theme,\n },\n }], true, false, false, 0, Config.themerev)[0];\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @returns {Promise}\n * @private\n */\n async fetchMapFromServer() {\n IconSystemFontawesome.fetchPromise = (async () => {\n const mapData = await this._fetchMapFromServer();\n\n IconSystemFontawesome.staticMap = new Map(Object.entries(mapData).map(([, value]) => ([\n `${value.component}/${value.pix}`,\n value.to,\n ])));\n LocalStorage.set(\n IconSystemFontawesome.cacheKey,\n JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries())),\n );\n\n return this;\n })();\n\n return IconSystemFontawesome.fetchPromise;\n }\n\n /**\n * Render an icon.\n *\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @param {string} template\n * @return {string} The rendered HTML content\n */\n renderIcon(key, component, title, template) {\n const iconKey = `${component}/${key}`;\n const mappedIcon = IconSystemFontawesome.staticMap.get(iconKey);\n const unmappedIcon = this.getUnmappedIcon(mappedIcon, key, component, title);\n\n const context = {\n title,\n unmappedIcon,\n alt: title,\n key: mappedIcon,\n };\n\n if (typeof title === \"undefined\" || title === '') {\n context['aria-hidden'] = true;\n }\n\n return Mustache.render(template, context).trim();\n }\n\n /**\n * Get the unmapped icon content, if the icon is not mapped.\n *\n * @param {IconProperties} mappedIcon\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @returns {IconProperties|null}\n * @private\n */\n getUnmappedIcon(mappedIcon, key, component, title) {\n if (mappedIcon) {\n return null;\n }\n\n return {\n attributes: [\n {name: 'src', value: Url.imageUrl(key, component)},\n {name: 'alt', value: title},\n {name: 'title', value: title}\n ],\n };\n }\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {string}\n * @method getTemplateName\n */\n getTemplateName() {\n return 'core/pix_icon_fontawesome';\n }\n}\n"],"names":["IconSystemFontawesome","IconSystem","init","staticMap","this","getMapFromCache","Promise","resolve","fetchPromise","fetchMapFromServer","map","LocalStorage","get","cacheKey","Map","JSON","parse","_fetchMapFromServer","methodname","args","themename","Config","theme","themerev","mapData","Object","entries","_ref","value","component","pix","to","set","stringify","Array","from","renderIcon","key","title","template","iconKey","mappedIcon","context","unmappedIcon","getUnmappedIcon","alt","Mustache","render","trim","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e,wBACW,2FAzJMrD,kCAKE,sBALFA,qCAWK,sBAXLA,iEAiB0BqB,OAAOC"} \ No newline at end of file diff --git a/lib/amd/src/icon_system_fontawesome.js b/lib/amd/src/icon_system_fontawesome.js index 3d2c3a0e4ff..df9f44d7287 100644 --- a/lib/amd/src/icon_system_fontawesome.js +++ b/lib/amd/src/icon_system_fontawesome.js @@ -29,6 +29,13 @@ import * as Config from './config'; import * as Url from './url'; /** + * An set of properties for an icon. + * @typedef {object} IconProperties + * @property {array} attributes + * @private + */ + +/** * The FontAwesome icon system. */ export default class IconSystemFontawesome extends IconSystem { @@ -154,13 +161,13 @@ export default class IconSystemFontawesome extends IconSystem { } /** - * Get the unamapped icon content, if the icon is not mapped. + * Get the unmapped icon content, if the icon is not mapped. * - * @param {object>} mappedIcon + * @param {IconProperties} mappedIcon * @param {string} key * @param {string} component - * @param {StaticRange} title - * @returns {object>|null} + * @param {string} title + * @returns {IconProperties|null} * @private */ getUnmappedIcon(mappedIcon, key, component, title) { -- 2.11.4.GIT