diff --git a/public/lib/amd/build/deprecated.min.js b/public/lib/amd/build/deprecated.min.js index 2807ee061ba..e24fcae25c3 100644 --- a/public/lib/amd/build/deprecated.min.js +++ b/public/lib/amd/build/deprecated.min.js @@ -1,4 +1,4 @@ -define("core/deprecated",["exports","core/config","core/notification"],(function(_exports,Cfg,_notification){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=function(thing){let{alternativeNotice:alternativeNotice=null,replacement:replacement=null,since:since=null,reason:reason=null,mdl:mdl=null,final:final=!1,emit:emit=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null===replacement&&null===reason&&null===mdl)throw new Error("You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.");const message=getMessage(thing,alternativeNotice,replacement,since,reason,mdl);canEmit()&&emit&&(!final&&isIgnored(thing)||(0,_notification.alert)("Deprecation Warning",getHTMLMessage(thing,alternativeNotice,replacement,since,reason,mdl)));if(final)throw new Error(message);console.error(message)},Cfg=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} +define("core/deprecated",["exports","core/config","core/notification"],(function(_exports,Cfg,_notification){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=function(thing){let{alternativeNotice:alternativeNotice=null,replacement:replacement=null,since:since=null,reason:reason=null,mdl:mdl=null,final:final=!1,emit:emit=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null===replacement&&null===reason&&null===mdl)throw new Error("You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.");const message=getMessage(thing,alternativeNotice,replacement,since,reason,mdl);(final||canEmit())&&(final||emit&&!isIgnored(thing))&&(0,_notification.alert)("Deprecation Warning",getHTMLMessage(thing,alternativeNotice,replacement,since,reason,mdl));if(final)throw new Error(message);console.error(message)},Cfg=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} /** * The core/deprecated module allows you to mark things as deprecated and warn appropriately. * diff --git a/public/lib/amd/build/deprecated.min.js.map b/public/lib/amd/build/deprecated.min.js.map index 8bd63f92cbc..343ca796910 100644 --- a/public/lib/amd/build/deprecated.min.js.map +++ b/public/lib/amd/build/deprecated.min.js.map @@ -1 +1 @@ -{"version":3,"file":"deprecated.min.js","sources":["../src/deprecated.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 * The core/deprecated module allows you to mark things as deprecated and warn appropriately.\n *\n * @module core/deprecated\n * @copyright Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @example Mark something as deprecated\n * import emitDeprecation from 'core/deprecated';\n *\n * emitDeprecation('myFunction', {\n * replacement: 'myNewFunction',\n * since: '5.0',\n * mdl: 'MDL-12345',\n * });\n */\n\nimport * as Cfg from 'core/config';\nimport {alert as emitNotice} from 'core/notification';\n\n/**\n * Helper to get the message to display to users.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {String} [alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [replacement] The name of the replacement thing, if there is one.\n * @param {String} [since] The version since which this thing has been deprecated.\n * @param {String} [reason] The reason why this thing was deprecated.\n * @param {String} [mdl] The issue number with more information about this deprecation.\n * @returns {String} The message to display to users.\n */\nconst getMessage = (\n thing,\n alternativeNotice,\n replacement,\n since,\n reason,\n mdl,\n) => {\n const stringParts = [];\n stringParts.push(`Deprecation: `);\n\n if (alternativeNotice) {\n stringParts.push(alternativeNotice);\n } else {\n stringParts.push(`${thing} has been deprecated`);\n }\n\n if(since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.');\n\n if (reason) {\n stringParts.push(` ${reason}`);\n }\n\n if (replacement) {\n stringParts.push(` Please use ${replacement} instead.`);\n }\n\n if (mdl) {\n stringParts.push(` See ${mdl} for more information.`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Helper to get the message to display to users.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {String} [alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [replacement] The name of the replacement thing, if there is one.\n * @param {String} [since] The version since which this thing has been deprecated.\n * @param {String} [reason] The reason why this thing was deprecated.\n * @param {String} [mdl] The issue number with more information about this deprecation.\n * @returns {String} The message to display to users.\n */\nconst getHTMLMessage = (\n thing,\n alternativeNotice,\n replacement,\n since,\n reason,\n mdl,\n) => {\n const stringParts = [];\n\n stringParts.push(`

Deprecation

`);\n if (alternativeNotice) {\n stringParts.push(`

${alternativeNotice}`);\n } else {\n stringParts.push(`

${thing} is deprecated`);\n }\n\n if (since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.

');\n\n if (reason) {\n stringParts.push(`

${reason}

`);\n }\n\n if (replacement) {\n stringParts.push(`

Please use ${replacement} instead.

`);\n }\n\n if (mdl) {\n const url = `https://moodle.atlassian.net/browse/${mdl}`;\n stringParts.push(`

See ${mdl} for more information.

`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Whether the thing being deprecated is in the ignore list or not.\n *\n * Items in the ignore list will only trigger the notification if they are finally deprecated,\n * but will still log the deprecation in the console.\n *\n * @param {string} thing\n * @returns {boolean}\n */\nconst isIgnored = (thing) => {\n const ignored = Cfg.deprecationignorelist || [];\n return ignored.includes(thing);\n};\n\n/**\n * Check environment conditions to determine if a message can be emitted.\n *\n * @returns Whether a message can be emitted\n */\nconst canEmit = () => {\n if (Cfg.developerdebug) {\n return true;\n }\n\n if (document.querySelector('body.behat-site')) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Mark a thing as deprecated, emitting a warning to the console and optionally displaying a toast notification.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {Object} options\n * @param {String} [options.alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [options.replacement] The name of the replacement thing, if there is one.\n * @param {String} [options.since] The version since which this thing has been deprecated.\n * @param {String} [options.reason] The reason why this thing was deprecated.\n * @param {String} [options.mdl] The issue number with more information about this deprecation.\n * @param {Boolean} [options.final=false] Whether this deprecation is final,\n * meaning it should throw an error instead of just emitting a warning.\n * @param {Boolean} [options.emit=true] Whether to emit a toast notification about this deprecation (in addition to\n */\nexport default function (thing, {\n alternativeNotice = null,\n replacement = null,\n since = null,\n reason = null,\n mdl = null,\n final = false,\n emit = true,\n} = {}) {\n if (replacement === null && reason === null && mdl === null) {\n throw new Error('You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.');\n }\n\n const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl);\n\n // If developer debug is enabled display a modal.\n if (canEmit() && emit) {\n if (final || !isIgnored(thing)) {\n emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl));\n }\n }\n\n // If this is a final deprecation, throw an error to break the execution.\n if (final) {\n throw new Error(message);\n } else {\n console.error(message); // eslint-disable-line no-console\n }\n}\n"],"names":["thing","alternativeNotice","replacement","since","reason","mdl","final","emit","Error","message","getMessage","canEmit","isIgnored","getHTMLMessage","console","error","stringParts","push","join","url","Cfg","deprecationignorelist","includes","developerdebug","document","querySelector"],"mappings":"kdAqLyBA,WAAOC,kBAC5BA,kBAAoB,KADQC,YAE5BA,YAAc,KAFcC,MAG5BA,MAAQ,KAHoBC,OAI5BA,OAAS,KAJmBC,IAK5BA,IAAM,KALsBC,MAM5BA,OAAQ,EANoBC,KAO5BA,MAAO,0DACP,MACoB,OAAhBL,aAAmC,OAAXE,QAA2B,OAARC,UACrC,IAAIG,MAAM,iHAGdC,QAAUC,WAAWV,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,KAG7EM,WAAaJ,QACTD,OAAUM,UAAUZ,gCACT,sBAAuBa,eAAeb,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,UAK3GC,YACM,IAAIE,MAAMC,SAEhBK,QAAQC,MAAMN;;;;;;;;;;;;;;;iBAjKhBC,WAAa,CACfV,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,UACpBA,YAAYC,sBAERhB,kBACAe,YAAYC,KAAKhB,mBAEjBe,YAAYC,eAAQjB,+BAGX,OAAVG,OACCa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,KAEbb,QACAY,YAAYC,gBAASb,SAGrBF,aACAc,YAAYC,2BAAoBf,0BAGhCG,KACAW,YAAYC,oBAAaZ,+BAGtBW,YAAYE,KAAK,KAetBL,eAAiB,CACnBb,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,MAEpBA,YAAYC,6BACRhB,kBACAe,YAAYC,kBAAWhB,oBAEvBe,YAAYC,wBAAiBjB,gCAGnB,OAAVG,OACAa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,SAEbb,QACAY,YAAYC,kBAAWb,gBAGvBF,aACAc,YAAYC,mCAA4Bf,qCAGxCG,IAAK,OACCc,kDAA6Cd,KACnDW,YAAYC,+BAAwBE,2DAAkDd,8CAGnFW,YAAYE,KAAK,KAYtBN,UAAaZ,QACCoB,IAAIC,uBAAyB,IAC9BC,SAAStB,OAQtBW,QAAU,MACRS,IAAIG,kBAIJC,SAASC,cAAc"} \ No newline at end of file +{"version":3,"file":"deprecated.min.js","sources":["../src/deprecated.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 * The core/deprecated module allows you to mark things as deprecated and warn appropriately.\n *\n * @module core/deprecated\n * @copyright Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @example Mark something as deprecated\n * import emitDeprecation from 'core/deprecated';\n *\n * emitDeprecation('myFunction', {\n * replacement: 'myNewFunction',\n * since: '5.0',\n * mdl: 'MDL-12345',\n * });\n */\n\nimport * as Cfg from 'core/config';\nimport {alert as emitNotice} from 'core/notification';\n\n/**\n * Helper to get the message to display to users.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {String} [alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [replacement] The name of the replacement thing, if there is one.\n * @param {String} [since] The version since which this thing has been deprecated.\n * @param {String} [reason] The reason why this thing was deprecated.\n * @param {String} [mdl] The issue number with more information about this deprecation.\n * @returns {String} The message to display to users.\n */\nconst getMessage = (\n thing,\n alternativeNotice,\n replacement,\n since,\n reason,\n mdl,\n) => {\n const stringParts = [];\n stringParts.push(`Deprecation: `);\n\n if (alternativeNotice) {\n stringParts.push(alternativeNotice);\n } else {\n stringParts.push(`${thing} has been deprecated`);\n }\n\n if(since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.');\n\n if (reason) {\n stringParts.push(` ${reason}`);\n }\n\n if (replacement) {\n stringParts.push(` Please use ${replacement} instead.`);\n }\n\n if (mdl) {\n stringParts.push(` See ${mdl} for more information.`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Helper to get the message to display to users.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {String} [alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [replacement] The name of the replacement thing, if there is one.\n * @param {String} [since] The version since which this thing has been deprecated.\n * @param {String} [reason] The reason why this thing was deprecated.\n * @param {String} [mdl] The issue number with more information about this deprecation.\n * @returns {String} The message to display to users.\n */\nconst getHTMLMessage = (\n thing,\n alternativeNotice,\n replacement,\n since,\n reason,\n mdl,\n) => {\n const stringParts = [];\n\n stringParts.push(`

Deprecation

`);\n if (alternativeNotice) {\n stringParts.push(`

${alternativeNotice}`);\n } else {\n stringParts.push(`

${thing} is deprecated`);\n }\n\n if (since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.

');\n\n if (reason) {\n stringParts.push(`

${reason}

`);\n }\n\n if (replacement) {\n stringParts.push(`

Please use ${replacement} instead.

`);\n }\n\n if (mdl) {\n const url = `https://moodle.atlassian.net/browse/${mdl}`;\n stringParts.push(`

See ${mdl} for more information.

`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Whether the thing being deprecated is in the ignore list or not.\n *\n * Items in the ignore list will only trigger the notification if they are finally deprecated,\n * but will still log the deprecation in the console.\n *\n * @param {string} thing\n * @returns {boolean}\n */\nconst isIgnored = (thing) => {\n const ignored = Cfg.deprecationignorelist || [];\n return ignored.includes(thing);\n};\n\n/**\n * Check environment conditions to determine if a message can be emitted.\n *\n * @returns Whether a message can be emitted\n */\nconst canEmit = () => {\n if (Cfg.developerdebug) {\n return true;\n }\n\n if (document.querySelector('body.behat-site')) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Mark a thing as deprecated, emitting a warning to the console and optionally displaying a toast notification.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {Object} options\n * @param {String} [options.alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [options.replacement] The name of the replacement thing, if there is one.\n * @param {String} [options.since] The version since which this thing has been deprecated.\n * @param {String} [options.reason] The reason why this thing was deprecated.\n * @param {String} [options.mdl] The issue number with more information about this deprecation.\n * @param {Boolean} [options.final=false] Whether this deprecation is final,\n * meaning it should throw an error instead of just emitting a warning.\n * @param {Boolean} [options.emit=true] Whether to emit a toast notification about this deprecation (in addition to\n */\nexport default function (thing, {\n alternativeNotice = null,\n replacement = null,\n since = null,\n reason = null,\n mdl = null,\n final = false,\n emit = true,\n} = {}) {\n if (replacement === null && reason === null && mdl === null) {\n throw new Error('You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.');\n }\n\n const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl);\n\n // Always emit if the deprecation is final.\n // For non-final deprecations emit if the message does not prevent it, and the user has not ignored it.\n // Non-final deprecations are only shown.\n if (final || canEmit()) {\n if (final || (emit && !isIgnored(thing))) {\n emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl));\n }\n }\n\n // If this is a final deprecation, throw an error to break the execution.\n if (final) {\n throw new Error(message);\n } else {\n console.error(message); // eslint-disable-line no-console\n }\n}\n"],"names":["thing","alternativeNotice","replacement","since","reason","mdl","final","emit","Error","message","getMessage","canEmit","isIgnored","getHTMLMessage","console","error","stringParts","push","join","url","Cfg","deprecationignorelist","includes","developerdebug","document","querySelector"],"mappings":"kdAqLyBA,WAAOC,kBAC5BA,kBAAoB,KADQC,YAE5BA,YAAc,KAFcC,MAG5BA,MAAQ,KAHoBC,OAI5BA,OAAS,KAJmBC,IAK5BA,IAAM,KALsBC,MAM5BA,OAAQ,EANoBC,KAO5BA,MAAO,0DACP,MACoB,OAAhBL,aAAmC,OAAXE,QAA2B,OAARC,UACrC,IAAIG,MAAM,iHAGdC,QAAUC,WAAWV,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,MAK7EC,OAASK,aACLL,OAAUC,OAASK,UAAUZ,iCAClB,sBAAuBa,eAAeb,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,SAK3GC,YACM,IAAIE,MAAMC,SAEhBK,QAAQC,MAAMN;;;;;;;;;;;;;;;iBAnKhBC,WAAa,CACfV,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,UACpBA,YAAYC,sBAERhB,kBACAe,YAAYC,KAAKhB,mBAEjBe,YAAYC,eAAQjB,+BAGX,OAAVG,OACCa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,KAEbb,QACAY,YAAYC,gBAASb,SAGrBF,aACAc,YAAYC,2BAAoBf,0BAGhCG,KACAW,YAAYC,oBAAaZ,+BAGtBW,YAAYE,KAAK,KAetBL,eAAiB,CACnBb,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,MAEpBA,YAAYC,6BACRhB,kBACAe,YAAYC,kBAAWhB,oBAEvBe,YAAYC,wBAAiBjB,gCAGnB,OAAVG,OACAa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,SAEbb,QACAY,YAAYC,kBAAWb,gBAGvBF,aACAc,YAAYC,mCAA4Bf,qCAGxCG,IAAK,OACCc,kDAA6Cd,KACnDW,YAAYC,+BAAwBE,2DAAkDd,8CAGnFW,YAAYE,KAAK,KAYtBN,UAAaZ,QACCoB,IAAIC,uBAAyB,IAC9BC,SAAStB,OAQtBW,QAAU,MACRS,IAAIG,kBAIJC,SAASC,cAAc"} \ No newline at end of file diff --git a/public/lib/amd/src/deprecated.js b/public/lib/amd/src/deprecated.js index b8cd9a05dfb..a033a953178 100644 --- a/public/lib/amd/src/deprecated.js +++ b/public/lib/amd/src/deprecated.js @@ -194,9 +194,11 @@ export default function (thing, { const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl); - // If developer debug is enabled display a modal. - if (canEmit() && emit) { - if (final || !isIgnored(thing)) { + // Always emit if the deprecation is final. + // For non-final deprecations emit if the message does not prevent it, and the user has not ignored it. + // Non-final deprecations are only shown. + if (final || canEmit()) { + if (final || (emit && !isIgnored(thing))) { emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl)); } }