From 628b4ca26209542a6e8e4ba6abaf894e4bef8c94 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Wed, 23 Oct 2019 15:16:30 +0800 Subject: [PATCH] MDL-65896 core: fix emoji picker IE11 support --- lib/amd/build/emoji/picker.min.js | 2 +- lib/amd/build/emoji/picker.min.js.map | 2 +- lib/amd/src/emoji/picker.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/amd/build/emoji/picker.min.js b/lib/amd/build/emoji/picker.min.js index e68677c4445..668973a9be9 100644 --- a/lib/amd/build/emoji/picker.min.js +++ b/lib/amd/build/emoji/picker.min.js @@ -1,2 +1,2 @@ -define ("core/emoji/picker",["exports","core/localstorage","core/emoji/data","core/utils","core/str","core/templates"],function(a,b,c,d,e,f){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function g(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){g=function(a){return typeof a}}else{g=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return g(a)}function h(a){return k(a)||j(a)||i()}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function j(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function k(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);bb){b=0}for(var i in c){var j=c[i];d.push([j,i])}d.sort(function(c,d){var e=l(c,1),f=e[0],a=l(d,1),g=a[0];if(fg){return 1}else{return 0}});var e=d.reduce(function(a,c){var d=l(c,2),e=d[0],f=d[1];if(e<=b){a.categoryName=f;a.previousPosition=a.currentPosition;a.currentPosition=b}else if(null===a.nextPosition){a.nextPosition=e}return a},{categoryName:null,currentPosition:null,previousPosition:null,nextPosition:null}),f=e.categoryName,g=e.previousPosition,h=e.nextPosition;return[G(a,f),g,h]},J=function(){var a=b.default.get(u);return a?JSON.parse(a):[]},K=function(a){b.default.set(u,JSON.stringify(a))},L=function(a,b,c){var d=a[0].data.name,e=a[0].data.displayName,f=J(),g=[c].concat(h(f.filter(function(a){return a.unified!=c.unified})));g=g.slice(0,3*w);var i=z(d,e,g);K(g);return[A(i.concat(a.slice(b))),i.length]},M=function(a,b,c){var d=a>v?Math.floor(a/v):0,e=d>=t?d-t:d,f=c.slice(e,d+b+t);return f},N=function(){var a=q(regeneratorRuntime.mark(function a(b){var c;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:c=null;if(!(b.type===x.HEADER)){a.next=7;break}a.next=4;return C(b.index,b.data.displayName);case 4:c=a.sent;a.next=10;break;case 7:a.next=9;return D(b.index,b.data);case 9:c=a.sent;case 10:c.style.position="absolute";c.style.left=0;c.style.right=0;c.style.top="".concat(b.index*v,"px");return a.abrupt("return",c);case 15:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),O=function(c,a){if(c.index!==a.index){return!1}if(c.type!==a.type){return!1}if(g(c.data)!=g(a.data)){return!1}if(c.type===x.HEADER){return c.data.name===a.data.name}else{if(c.data.length!==a.data.length){return!1}for(var b=0;bd.index){g=h;break}}if(null!==g){var k=f[g],l=b.querySelector("[data-row=\"".concat(k.index,"\"]"));b.insertBefore(a,l);f.splice(g,0,f)}else{f.push(d);b.append(a)}});h.forEach(function(a){return a.forEach(function(a){return b.removeChild(a)})});case 9:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),Q=function(a){var b=[],c=[],d=0,e=!1,f=function(){var d=q(regeneratorRuntime.mark(function d(){var g;return regeneratorRuntime.wrap(function(d){while(1){switch(d.prev=d.next){case 0:if(c.length){d.next=2;break}return d.abrupt("return");case 2:if(!e){d.next=4;break}return d.abrupt("return");case 4:e=!0;g=c.slice();c=[];d.next=9;return P(a,b,g);case 9:b=g;e=!1;f();case 12:case"end":return d.stop();}}},d)}));return function(){return d.apply(this,arguments)}}();return function(b,e){var g=2=j||gk){requestAnimationFrame(function(){e(g,f);b=g})}}},X=function(a,b,d){var f=b.querySelector(y.ROW_CONTAINER),g=Q(f);b.append(f);return q(regeneratorRuntime.mark(function f(){var h,i,j,k;return regeneratorRuntime.wrap(function(f){while(1){switch(f.prev=f.next){case 0:h=a.value.toLowerCase();if(!h){f.next=11;break}R(d,b);i=Object.keys(c.byShortName).reduce(function(a,b){if(b.includes(h)){a.push({shortnames:[b],unified:c.byShortName[b]})}return a},[]);f.next=6;return(0,e.get_string)("searchresults","core");case 6:j=f.sent;k=z(j,j,i,0);g(0,k,k.length);f.next=12;break;case 11:S(d,b,a);case 12:case"end":return f.stop();}}},f)}))},Y=function(a,b,c,e,f,g,h,i){var j=a.querySelector(y.SEARCH_INPUT),k=a.querySelector(y.SEARCH_RESULTS_CONTAINER),m=a.querySelector(y.EMOJI_PREVIEW),n=a.querySelector(y.EMOJI_SHORT_NAME),o=V(i,b,k,j,f,c),p=W(a,e,b,g,c),q=X(j,k,b);a.addEventListener("focus",T(m,n),!0);a.addEventListener("blur",U(m,n),!0);a.addEventListener("mouseenter",T(m,n),!0);a.addEventListener("mouseleave",U(m,n),!0);a.addEventListener("click",function(a){var b=o(a,h,g),c=l(b,2);h=c[0];g=c[1]});b.addEventListener("scroll",(0,d.throttle)(function(){return p(g,h)},50));j.addEventListener("input",(0,d.debounce)(q,200))},Z=function(a,b){var d=a.querySelector(y.EMOJIS_CONTAINER),e=d.querySelector(y.ROW_CONTAINER),f=J(),g=[{name:"Recent",emojis:f}].concat(h(c.byCategory)),i=[],j=0;g.forEach(function(b){var c=G(a,b.name),d=c.title,e=z(b.name,d,b.emojis,i.length);if("Recent"===b.name){j=e.length}i=i.concat(e)});i=A(i);var k=B(i),l=Q(e);l(0,i);Y(a,d,l,0,b,k,i,j)};a.default=Z;return a.default}); +define ("core/emoji/picker",["exports","core/localstorage","core/emoji/data","core/utils","core/str","core/templates"],function(a,b,c,d,e,f){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function g(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){g=function(a){return typeof a}}else{g=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return g(a)}function h(a){return k(a)||j(a)||i()}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function j(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function k(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);bb){b=0}for(var i in c){var j=c[i];d.push([j,i])}d.sort(function(c,d){var e=l(c,1),f=e[0],a=l(d,1),g=a[0];if(fg){return 1}else{return 0}});var e=d.reduce(function(a,c){var d=l(c,2),e=d[0],f=d[1];if(e<=b){a.categoryName=f;a.previousPosition=a.currentPosition;a.currentPosition=b}else if(null===a.nextPosition){a.nextPosition=e}return a},{categoryName:null,currentPosition:null,previousPosition:null,nextPosition:null}),f=e.categoryName,g=e.previousPosition,h=e.nextPosition;return[G(a,f),g,h]},J=function(){var a=b.default.get(u);return a?JSON.parse(a):[]},K=function(a){b.default.set(u,JSON.stringify(a))},L=function(a,b,c){var d=a[0].data.name,e=a[0].data.displayName,f=J(),g=[c].concat(h(f.filter(function(a){return a.unified!=c.unified})));g=g.slice(0,3*w);var i=z(d,e,g);K(g);return[A(i.concat(a.slice(b))),i.length]},M=function(a,b,c){var d=a>v?Math.floor(a/v):0,e=d>=t?d-t:d,f=c.slice(e,d+b+t);return f},N=function(){var a=q(regeneratorRuntime.mark(function a(b){var c;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:c=null;if(!(b.type===x.HEADER)){a.next=7;break}a.next=4;return C(b.index,b.data.displayName);case 4:c=a.sent;a.next=10;break;case 7:a.next=9;return D(b.index,b.data);case 9:c=a.sent;case 10:c.style.position="absolute";c.style.left=0;c.style.right=0;c.style.top="".concat(b.index*v,"px");return a.abrupt("return",c);case 15:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),O=function(c,a){if(c.index!==a.index){return!1}if(c.type!==a.type){return!1}if(g(c.data)!=g(a.data)){return!1}if(c.type===x.HEADER){return c.data.name===a.data.name}else{if(c.data.length!==a.data.length){return!1}for(var b=0;bd.index){g=h;break}}if(null!==g){var k=f[g],l=b.querySelector("[data-row=\"".concat(k.index,"\"]"));b.insertBefore(a,l);f.splice(g,0,f)}else{f.push(d);b.appendChild(a)}});h.forEach(function(a){return a.forEach(function(a){return b.removeChild(a)})});case 9:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),Q=function(a){var b=[],c=[],d=0,e=!1,f=function(){var d=q(regeneratorRuntime.mark(function d(){var g;return regeneratorRuntime.wrap(function(d){while(1){switch(d.prev=d.next){case 0:if(c.length){d.next=2;break}return d.abrupt("return");case 2:if(!e){d.next=4;break}return d.abrupt("return");case 4:e=!0;g=c.slice();c=[];d.next=9;return P(a,b,g);case 9:b=g;e=!1;f();case 12:case"end":return d.stop();}}},d)}));return function(){return d.apply(this,arguments)}}();return function(b,e){var g=2=j||gk){requestAnimationFrame(function(){e(g,f);b=g})}}},X=function(a,b,d){var f=b.querySelector(y.ROW_CONTAINER),g=Q(f);b.appendChild(f);return q(regeneratorRuntime.mark(function f(){var h,i,j,k;return regeneratorRuntime.wrap(function(f){while(1){switch(f.prev=f.next){case 0:h=a.value.toLowerCase();if(!h){f.next=11;break}R(d,b);i=Object.keys(c.byShortName).reduce(function(a,b){if(b.includes(h)){a.push({shortnames:[b],unified:c.byShortName[b]})}return a},[]);f.next=6;return(0,e.get_string)("searchresults","core");case 6:j=f.sent;k=z(j,j,i,0);g(0,k,k.length);f.next=12;break;case 11:S(d,b,a);case 12:case"end":return f.stop();}}},f)}))},Y=function(a,b,c,e,f,g,h,i){var j=a.querySelector(y.SEARCH_INPUT),k=a.querySelector(y.SEARCH_RESULTS_CONTAINER),m=a.querySelector(y.EMOJI_PREVIEW),n=a.querySelector(y.EMOJI_SHORT_NAME),o=V(i,b,k,j,f,c),p=W(a,e,b,g,c),q=X(j,k,b);a.addEventListener("focus",T(m,n),!0);a.addEventListener("blur",U(m,n),!0);a.addEventListener("mouseenter",T(m,n),!0);a.addEventListener("mouseleave",U(m,n),!0);a.addEventListener("click",function(a){var b=o(a,h,g),c=l(b,2);h=c[0];g=c[1]});b.addEventListener("scroll",(0,d.throttle)(function(){return p(g,h)},50));j.addEventListener("input",(0,d.debounce)(q,200))},Z=function(a,b){var d=a.querySelector(y.EMOJIS_CONTAINER),e=d.querySelector(y.ROW_CONTAINER),f=J(),g=[{name:"Recent",emojis:f}].concat(h(c.byCategory)),i=[],j=0;g.forEach(function(b){var c=G(a,b.name),d=c.title,e=z(b.name,d,b.emojis,i.length);if("Recent"===b.name){j=e.length}i=i.concat(e)});i=A(i);var k=B(i),l=Q(e);l(0,i);Y(a,d,l,0,b,k,i,j)};a.default=Z;return a.default}); //# sourceMappingURL=picker.min.js.map diff --git a/lib/amd/build/emoji/picker.min.js.map b/lib/amd/build/emoji/picker.min.js.map index a06026481bb..be585eedceb 100644 --- a/lib/amd/build/emoji/picker.min.js.map +++ b/lib/amd/build/emoji/picker.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/emoji/picker.js"],"names":["ROW_RENDER_BUFFER_COUNT","RECENT_EMOJIS_STORAGE_KEY","ROW_HEIGHT_RAW","EMOJIS_PER_ROW","ROW_TYPE","EMOJI","HEADER","SELECTORS","CATEGORY_SELECTOR","EMOJIS_CONTAINER","EMOJI_PREVIEW","EMOJI_SHORT_NAME","ROW_CONTAINER","SEARCH_INPUT","SEARCH_RESULTS_CONTAINER","createRowDataForCategory","categoryName","categoryDisplayName","emojis","totalRowCount","rowData","push","index","length","type","data","name","displayName","i","rowEmojis","slice","addIndexesToRowData","map","getCategoryScrollPositionsFromRowData","reduce","carry","row","createHeaderRow","rowIndex","context","text","html","temp","document","createElement","innerHTML","firstChild","createEmojiRow","emojiData","charCodes","unified","split","code","emojiText","String","fromCodePoint","apply","shortnames","join","spacer","spacers","Array","fill","isEmojiElement","element","getAttribute","findCategorySelectorFromElement","parentElement","getCategorySelectorByCategoryName","root","querySelector","setCategorySelectorActive","allCategorySelectors","querySelectorAll","forEach","selector","classList","remove","add","getCategoryByScrollPosition","position","categoryScrollPositions","positions","categoryPosition","sort","a","b","candidate","previousPosition","currentPosition","nextPosition","getRecentEmojis","storedData","LocalStorage","get","JSON","parse","saveRecentEmoji","recentEmojis","set","stringify","addRecentEmoji","recentEmojiRowCount","newEmoji","newRecentEmojis","filter","emoji","newRecentEmojiRowData","concat","getRowsToRender","scrollPosition","visibleRowCount","minVisibleRow","Math","floor","start","rows","createRowElement","style","left","right","top","doRowsMatch","renderRows","rowContainer","currentRows","nextRows","toAdd","nextRow","some","currentRow","toKeep","toRemove","toRemoveElements","Promise","all","nextRowIndex","nextRowData","nextRowNode","insertBefore","splice","append","removeChild","generateRenderRowsAtPositionFunction","rowCount","isRendering","renderNextRows","nextRowsToRender","rowLimit","height","showSearchResults","emojiContainer","searchResultsContainer","clearSearch","searchInput","value","getHandleMouseEnter","emojiPreview","emojiShortName","e","target","textContent","getHandleMouseLeave","getHandleClick","selectCallback","renderAtPosition","newRowData","newCategoryScrollPositions","replace","currentScrollTop","scrollTop","isRecentEmojiRowVisible","categorySelector","selectedCategory","getHandleScroll","currentVisibleRowScrollPosition","initialCategoryScrollPositions","currentCategoryElement","previousCategoryPosition","nextCategoryPosition","newScrollPosition","upperScrollBound","lowerScrollBound","updateActiveCategory","requestAnimationFrame","getHandleSearch","renderSearchResultsAtPosition","searchTerm","toLowerCase","matchingEmojis","Object","keys","EmojiData","byShortName","shortName","includes","searchResultsString","registerEventListeners","clickHandler","scrollHandler","searchHandler","addEventListener","allData","byCategory","category","title","categoryRowData"],"mappings":"4NAqBA,uDACA,kU,6vDAMMA,CAAAA,CAAuB,CAAG,C,CAC1BC,CAAyB,CAAG,sB,CAC5BC,CAAc,CAAG,E,CACjBC,CAAc,CAAG,C,CAEjBC,CAAQ,CAAG,CACbC,KAAK,CAAE,CADM,CAEbC,MAAM,CAAE,CAFK,C,CAIXC,CAAS,CAAG,CACdC,iBAAiB,CAAE,iCADL,CAEdC,gBAAgB,CAAE,oCAFJ,CAGdC,aAAa,CAAE,iCAHD,CAIdC,gBAAgB,CAAE,oCAJJ,CAKdC,aAAa,CAAE,iCALD,CAMdC,YAAY,CAAE,gCANA,CAOdC,wBAAwB,CAAE,4CAPZ,C,CAmBZC,CAAwB,CAAG,SAACC,CAAD,CAAeC,CAAf,CAAoCC,CAApC,CAA4CC,CAA5C,CAA8D,CAC3F,GAAMC,CAAAA,CAAO,CAAG,EAAhB,CACAA,CAAO,CAACC,IAAR,CAAa,CACTC,KAAK,CAAEH,CAAa,CAAGC,CAAO,CAACG,MADtB,CAETC,IAAI,CAAEpB,CAAQ,CAACE,MAFN,CAGTmB,IAAI,CAAE,CACFC,IAAI,CAAEV,CADJ,CAEFW,WAAW,CAAEV,CAFX,CAHG,CAAb,EASA,IAAK,GAAIW,CAAAA,CAAC,CAAG,CAAR,CACKC,CADV,CAAgBD,CAAC,CAAGV,CAAM,CAACK,MAA3B,CAAmCK,CAAC,EAAIzB,CAAxC,CAAwD,CAC9C0B,CAD8C,CAClCX,CAAM,CAACY,KAAP,CAAaF,CAAb,CAAgBA,CAAC,CAAGzB,CAApB,CADkC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AIlB,CAJkB,CAKlBD,CALkB,CAMlBnF,CANkB,CAOlB7D,CAPkB,CAQlBkF,CARkB,CAUzB,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 * Emoji picker.\n *\n * @copyright 2019 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport LocalStorage from 'core/localstorage';\nimport * as EmojiData from 'core/emoji/data';\nimport {throttle, debounce} from 'core/utils';\nimport {get_string} from 'core/str';\nimport {render as renderTemplate} from 'core/templates';\n\nconst VISIBLE_ROW_COUNT = 10;\nconst ROW_RENDER_BUFFER_COUNT = 5;\nconst RECENT_EMOJIS_STORAGE_KEY = 'moodle-recent-emojis';\nconst ROW_HEIGHT_RAW = 40;\nconst EMOJIS_PER_ROW = 7;\nconst MAX_RECENT_COUNT = EMOJIS_PER_ROW * 3;\nconst ROW_TYPE = {\n EMOJI: 0,\n HEADER: 1\n};\nconst SELECTORS = {\n CATEGORY_SELECTOR: '[data-action=\"show-category\"]',\n EMOJIS_CONTAINER: '[data-region=\"emojis-container\"]',\n EMOJI_PREVIEW: '[data-region=\"emoji-preview\"]',\n EMOJI_SHORT_NAME: '[data-region=\"emoji-short-name\"]',\n ROW_CONTAINER: '[data-region=\"row-container\"]',\n SEARCH_INPUT: '[data-region=\"search-input\"]',\n SEARCH_RESULTS_CONTAINER: '[data-region=\"search-results-container\"]'\n};\n\n/**\n * Create the row data for a category.\n *\n * @param {String} categoryName The category name\n * @param {String} categoryDisplayName The category display name\n * @param {Array} emojis The emoji data\n * @param {Number} totalRowCount The total number of rows generated so far\n * @return {Array}\n */\nconst createRowDataForCategory = (categoryName, categoryDisplayName, emojis, totalRowCount) => {\n const rowData = [];\n rowData.push({\n index: totalRowCount + rowData.length,\n type: ROW_TYPE.HEADER,\n data: {\n name: categoryName,\n displayName: categoryDisplayName\n }\n });\n\n for (let i = 0; i < emojis.length; i += EMOJIS_PER_ROW) {\n const rowEmojis = emojis.slice(i, i + EMOJIS_PER_ROW);\n rowData.push({\n index: totalRowCount + rowData.length,\n type: ROW_TYPE.EMOJI,\n data: rowEmojis\n });\n }\n\n return rowData;\n};\n\n/**\n * Add each row's index to it's value in the row data.\n *\n * @param {Array} rowData List of emoji row data\n * @return {Array}\n */\nconst addIndexesToRowData = (rowData) => {\n return rowData.map((data, index) => {\n return {...data, index};\n });\n};\n\n/**\n * Calculate the scroll position for the beginning of each category from\n * the row data.\n *\n * @param {Array} rowData List of emoji row data\n * @return {Object}\n */\nconst getCategoryScrollPositionsFromRowData = (rowData) => {\n return rowData.reduce((carry, row, index) => {\n if (row.type === ROW_TYPE.HEADER) {\n carry[row.data.name] = index * ROW_HEIGHT_RAW;\n }\n return carry;\n }, {});\n};\n\n/**\n * Create a header row element for the category name.\n *\n * @param {Number} rowIndex Index of the row in the row data\n * @param {String} name The category display name\n * @return {Element}\n */\nconst createHeaderRow = async (rowIndex, name) => {\n const context = {\n index: rowIndex,\n text: name\n };\n const html = await renderTemplate('core/emoji/header_row', context);\n const temp = document.createElement('div');\n temp.innerHTML = html;\n return temp.firstChild;\n};\n\n/**\n * Create an emoji row element.\n *\n * @param {Number} rowIndex Index of the row in the row data\n * @param {Array} emojis The list of emoji data for the row\n * @return {Element}\n */\nconst createEmojiRow = async (rowIndex, emojis) => {\n const context = {\n index: rowIndex,\n emojis: emojis.map(emojiData => {\n const charCodes = emojiData.unified.split('-').map(code => `0x${code}`);\n const emojiText = String.fromCodePoint.apply(null, charCodes);\n return {\n shortnames: `:${emojiData.shortnames.join(': :')}:`,\n unified: emojiData.unified,\n text: emojiText,\n spacer: false\n };\n }),\n spacers: Array(EMOJIS_PER_ROW - emojis.length).fill(true)\n };\n const html = await renderTemplate('core/emoji/emoji_row', context);\n const temp = document.createElement('div');\n temp.innerHTML = html;\n return temp.firstChild;\n};\n\n/**\n * Check if the element is an emoji element.\n *\n * @param {Element} element Element to check\n * @return {Bool}\n */\nconst isEmojiElement = element => element.getAttribute('data-short-names') !== null;\n\n/**\n * Search from an element and up through it's ancestors to fine the category\n * selector element and return it.\n *\n * @param {Element} element Element to begin searching from\n * @return {Element|null}\n */\nconst findCategorySelectorFromElement = element => {\n if (!element) {\n return null;\n }\n\n if (element.getAttribute('data-action') === 'show-category') {\n return element;\n } else {\n return findCategorySelectorFromElement(element.parentElement);\n }\n};\n\nconst getCategorySelectorByCategoryName = (root, name) => {\n return root.querySelector(`[data-category=\"${name}\"]`);\n};\n\n/**\n * Sets the given category selector element as active.\n *\n * @param {Element} root The root picker element\n * @param {Element} element The category selector element to make active\n */\nconst setCategorySelectorActive = (root, element) => {\n const allCategorySelectors = root.querySelectorAll(SELECTORS.CATEGORY_SELECTOR);\n allCategorySelectors.forEach(selector => {\n selector.classList.remove('selected');\n });\n\n element.classList.add('selected');\n};\n\n/**\n * Get the category selector element and the scroll positions for the previous and\n * next categories for the given scroll position.\n *\n * @param {Element} root The picker root element\n * @param {Number} position The position to get the category for\n * @param {Object} categoryScrollPositions Set of scroll positions for all categories\n * @return {Array}\n */\nconst getCategoryByScrollPosition = (root, position, categoryScrollPositions) => {\n let positions = [];\n\n if (position < 0) {\n position = 0;\n }\n\n // Get all of the category positions.\n for (const categoryName in categoryScrollPositions) {\n const categoryPosition = categoryScrollPositions[categoryName];\n positions.push([categoryPosition, categoryName]);\n }\n\n // Sort the positions in ascending order.\n positions.sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (a > b) {\n return 1;\n } else {\n return 0;\n }\n });\n\n // Get the current category name as well as the previous and next category\n // positions from the sorted list of positions.\n const {categoryName, previousPosition, nextPosition} = positions.reduce(\n (carry, candidate) => {\n const [categoryPosition, categoryName] = candidate;\n\n if (categoryPosition <= position) {\n carry.categoryName = categoryName;\n carry.previousPosition = carry.currentPosition;\n carry.currentPosition = position;\n } else if (carry.nextPosition === null) {\n carry.nextPosition = categoryPosition;\n }\n\n return carry;\n },\n {\n categoryName: null,\n currentPosition: null,\n previousPosition: null,\n nextPosition: null\n }\n );\n\n return [getCategorySelectorByCategoryName(root, categoryName), previousPosition, nextPosition];\n};\n\n/**\n * Get the list of recent emojis data from local storage.\n *\n * @return {Array}\n */\nconst getRecentEmojis = () => {\n const storedData = LocalStorage.get(RECENT_EMOJIS_STORAGE_KEY);\n return storedData ? JSON.parse(storedData) : [];\n};\n\n/**\n * Save the list of recent emojis in local storage.\n *\n * @param {Array} recentEmojis List of emoji data to save\n */\nconst saveRecentEmoji = (recentEmojis) => {\n LocalStorage.set(RECENT_EMOJIS_STORAGE_KEY, JSON.stringify(recentEmojis));\n};\n\n/**\n * Add an emoji data to the set of recent emojis. This function will update the row\n * data to ensure that the recent emoji rows are correct and all of the rows are\n * re-indexed.\n *\n * The new set of recent emojis are saved in local storage and the full set of updated\n * row data and new emoji row count are returned.\n *\n * @param {Array} rowData The emoji rows data\n * @param {Number} recentEmojiRowCount Count of the recent emoji rows\n * @param {Object} newEmoji The emoji data for the emoji to add to the recent emoji list\n * @return {Array}\n */\nconst addRecentEmoji = (rowData, recentEmojiRowCount, newEmoji) => {\n // The first set of rows is always the recent emojis.\n const categoryName = rowData[0].data.name;\n const categoryDisplayName = rowData[0].data.displayName;\n const recentEmojis = getRecentEmojis();\n // Add the new emoji to the start of the list of recent emojis.\n let newRecentEmojis = [newEmoji, ...recentEmojis.filter(emoji => emoji.unified != newEmoji.unified)];\n // Limit the number of recent emojis.\n newRecentEmojis = newRecentEmojis.slice(0, MAX_RECENT_COUNT);\n const newRecentEmojiRowData = createRowDataForCategory(categoryName, categoryDisplayName, newRecentEmojis);\n\n // Save the new list in local storage.\n saveRecentEmoji(newRecentEmojis);\n\n return [\n // Return the new rowData and re-index it to make sure it's all correct.\n addIndexesToRowData(newRecentEmojiRowData.concat(rowData.slice(recentEmojiRowCount))),\n newRecentEmojiRowData.length\n ];\n};\n\n/**\n * Calculate which rows should be visible based on the given scroll position. Adds a\n * buffer to amount to either side of the total number of requested rows so that\n * scrolling the emoji rows container is smooth.\n *\n * @param {Number} scrollPosition Scroll position within the emoji container\n * @param {Number} visibleRowCount How many rows should be visible\n * @param {Array} rowData The emoji rows data\n * @return {Array}\n */\nconst getRowsToRender = (scrollPosition, visibleRowCount, rowData) => {\n const minVisibleRow = scrollPosition > ROW_HEIGHT_RAW ? Math.floor(scrollPosition / ROW_HEIGHT_RAW) : 0;\n const start = minVisibleRow >= ROW_RENDER_BUFFER_COUNT ? minVisibleRow - ROW_RENDER_BUFFER_COUNT : minVisibleRow;\n const end = minVisibleRow + visibleRowCount + ROW_RENDER_BUFFER_COUNT;\n const rows = rowData.slice(start, end);\n return rows;\n};\n\n/**\n * Create a row element from the row data.\n *\n * @param {Object} rowData The emoji row data\n * @return {Element}\n */\nconst createRowElement = async (rowData) => {\n let row = null;\n if (rowData.type === ROW_TYPE.HEADER) {\n row = await createHeaderRow(rowData.index, rowData.data.displayName);\n } else {\n row = await createEmojiRow(rowData.index, rowData.data);\n }\n\n row.style.position = 'absolute';\n row.style.left = 0;\n row.style.right = 0;\n row.style.top = `${rowData.index * ROW_HEIGHT_RAW}px`;\n\n return row;\n};\n\n/**\n * Check if the given rows match.\n *\n * @param {Object} a The first row\n * @param {Object} b The second row\n * @return {Bool}\n */\nconst doRowsMatch = (a, b) => {\n if (a.index !== b.index) {\n return false;\n }\n\n if (a.type !== b.type) {\n return false;\n }\n\n if (typeof a.data != typeof b.data) {\n return false;\n }\n\n if (a.type === ROW_TYPE.HEADER) {\n return a.data.name === b.data.name;\n } else {\n if (a.data.length !== b.data.length) {\n return false;\n }\n\n for (let i = 0; i < a.data.length; i++) {\n if (a.data[i].unified != b.data[i].unified) {\n return false;\n }\n }\n }\n\n return true;\n};\n\n/**\n * Update the visible rows. Deletes any row elements that should no longer\n * be visible and creates the newly visible row elements. Any rows that haven't\n * changed visibility will be left untouched.\n *\n * @param {Element} rowContainer The container element for the emoji rows\n * @param {Array} currentRows List of row data that matches the currently visible rows\n * @param {Array} nextRows List of row data containing the new list of rows to be made visible\n */\nconst renderRows = async (rowContainer, currentRows, nextRows) => {\n // We need to add any rows that are in nextRows but not in currentRows.\n const toAdd = nextRows.filter(nextRow => !currentRows.some(currentRow => doRowsMatch(currentRow, nextRow)));\n // Remember which rows will still be visible so that we can insert our element in the correct place in the DOM.\n let toKeep = currentRows.filter(currentRow => nextRows.some(nextRow => doRowsMatch(currentRow, nextRow)));\n // We need to remove any rows that are in currentRows but not in nextRows.\n const toRemove = currentRows.filter(currentRow => !nextRows.some(nextRow => doRowsMatch(currentRow, nextRow)));\n const toRemoveElements = toRemove.map(rowData => rowContainer.querySelectorAll(`[data-row=\"${rowData.index}\"]`));\n\n // Render all of the templates first.\n const rows = await Promise.all(toAdd.map(rowData => createRowElement(rowData)));\n\n rows.forEach((row, index) => {\n const rowData = toAdd[index];\n let nextRowIndex = null;\n\n for (let i = 0; i < toKeep.length; i++) {\n const candidate = toKeep[i];\n if (candidate.index > rowData.index) {\n nextRowIndex = i;\n break;\n }\n }\n\n // Make sure the elements get added to the DOM in the correct order (ascending by row data index)\n // so that they appear naturally in the tab order.\n if (nextRowIndex !== null) {\n const nextRowData = toKeep[nextRowIndex];\n const nextRowNode = rowContainer.querySelector(`[data-row=\"${nextRowData.index}\"]`);\n\n rowContainer.insertBefore(row, nextRowNode);\n toKeep.splice(nextRowIndex, 0, toKeep);\n } else {\n toKeep.push(rowData);\n rowContainer.append(row);\n }\n });\n\n toRemoveElements.forEach(rows => rows.forEach(row => rowContainer.removeChild(row)));\n};\n\n/**\n * Build a function to render the visible emoji rows for a given scroll\n * position.\n *\n * @param {Element} rowContainer The container element for the emoji rows\n * @return {Function}\n */\nconst generateRenderRowsAtPositionFunction = (rowContainer) => {\n let currentRows = [];\n let nextRows = [];\n let rowCount = 0;\n let isRendering = false;\n const renderNextRows = async () => {\n if (!nextRows.length) {\n return;\n }\n\n if (isRendering) {\n return;\n }\n\n isRendering = true;\n const nextRowsToRender = nextRows.slice();\n nextRows = [];\n\n await renderRows(rowContainer, currentRows, nextRowsToRender);\n currentRows = nextRowsToRender;\n isRendering = false;\n renderNextRows();\n };\n\n return (scrollPosition, rowData, rowLimit = VISIBLE_ROW_COUNT) => {\n nextRows = getRowsToRender(scrollPosition, rowLimit, rowData);\n renderNextRows();\n\n if (rowCount !== rowData.length) {\n // Adjust the height of the container to match the number of rows.\n rowContainer.style.height = `${rowData.length * ROW_HEIGHT_RAW}px`;\n }\n\n rowCount = rowData.length;\n };\n};\n\n/**\n * Show the search results container and hide the emoji container.\n *\n * @param {Element} emojiContainer The emojis container\n * @param {Element} searchResultsContainer The search results container\n */\nconst showSearchResults = (emojiContainer, searchResultsContainer) => {\n searchResultsContainer.classList.remove('hidden');\n emojiContainer.classList.add('hidden');\n};\n\n/**\n * Hide the search result container and show the emojis container.\n *\n * @param {Element} emojiContainer The emojis container\n * @param {Element} searchResultsContainer The search results container\n * @param {Element} searchInput The search input\n */\nconst clearSearch = (emojiContainer, searchResultsContainer, searchInput) => {\n searchResultsContainer.classList.add('hidden');\n emojiContainer.classList.remove('hidden');\n searchInput.value = '';\n};\n\n/**\n * Build function to handle mouse hovering an emoji. Shows the preview.\n *\n * @param {Element} emojiPreview The emoji preview element\n * @param {Element} emojiShortName The emoji short name element\n * @return {Function}\n */\nconst getHandleMouseEnter = (emojiPreview, emojiShortName) => {\n return (e) => {\n const target = e.target;\n if (isEmojiElement(target)) {\n emojiShortName.textContent = target.getAttribute('data-short-names');\n emojiPreview.textContent = target.textContent;\n }\n };\n};\n\n/**\n * Build function to handle mouse leaving an emoji. Removes the preview.\n *\n * @param {Element} emojiPreview The emoji preview element\n * @param {Element} emojiShortName The emoji short name element\n * @return {Function}\n */\nconst getHandleMouseLeave = (emojiPreview, emojiShortName) => {\n return (e) => {\n const target = e.target;\n if (isEmojiElement(target)) {\n emojiShortName.textContent = '';\n emojiPreview.textContent = '';\n }\n };\n};\n\n/**\n * Build the function to handle a user clicking something in the picker.\n *\n * The function currently handles clicking on the category selector or selecting\n * a specific emoji.\n *\n * @param {Number} recentEmojiRowCount Number of rows of recent emojis\n * @param {Element} emojiContainer Container element for the visible of emojis\n * @param {Element} searchResultsContainer Contaienr element for the search results\n * @param {Element} searchInput Search input element\n * @param {Function} selectCallback Callback function to execute when a user selects an emoji\n * @param {Function} renderAtPosition Render function to display current visible emojis\n * @return {Function}\n */\nconst getHandleClick = (\n recentEmojiRowCount,\n emojiContainer,\n searchResultsContainer,\n searchInput,\n selectCallback,\n renderAtPosition\n) => {\n return (e, rowData, categoryScrollPositions) => {\n const target = e.target;\n let newRowData = rowData;\n let newCategoryScrollPositions = categoryScrollPositions;\n\n // Hide the search results if they are visible.\n clearSearch(emojiContainer, searchResultsContainer, searchInput);\n\n if (isEmojiElement(target)) {\n // Emoji selected.\n const unified = target.getAttribute('data-unified');\n const shortnames = target.getAttribute('data-short-names').replace(/:/g, '').split(' ');\n // Build the emoji data from the selected element.\n const emojiData = {unified, shortnames};\n const currentScrollTop = emojiContainer.scrollTop;\n const isRecentEmojiRowVisible = emojiContainer.querySelector(`[data-row=\"${recentEmojiRowCount - 1}\"]`) !== null;\n // Save the selected emoji in the recent emojis list.\n [newRowData, recentEmojiRowCount] = addRecentEmoji(rowData, recentEmojiRowCount, emojiData);\n // Re-index the category scroll positions because the additional recent emoji may have\n // changed their positions.\n newCategoryScrollPositions = getCategoryScrollPositionsFromRowData(newRowData);\n\n if (isRecentEmojiRowVisible) {\n // If the list of recent emojis is currently visible then we need to re-render the emojis\n // to update the display and show the newly selected recent emoji.\n renderAtPosition(currentScrollTop, newRowData);\n }\n\n // Call the client's callback function with the selected emoji.\n selectCallback(target.textContent);\n // Return the newly calculated row data and scroll positions.\n return [newRowData, newCategoryScrollPositions];\n }\n\n const categorySelector = findCategorySelectorFromElement(target);\n if (categorySelector) {\n // Category selector.\n const selectedCategory = categorySelector.getAttribute('data-category');\n const position = categoryScrollPositions[selectedCategory];\n // Scroll the container to the selected category. This will trigger the\n // on scroll handler to re-render the visibile emojis.\n emojiContainer.scrollTop = position;\n }\n\n return [newRowData, newCategoryScrollPositions];\n };\n};\n\n/**\n * Build the function that handles scrolling of the emoji container to display the\n * correct emojis.\n *\n * We render the emoji rows as they are needed rather than all up front so that we\n * can avoid adding tends of thousands of elements to the DOM unnecessarily which\n * would bog down performance.\n *\n * @param {Element} root The picker root element\n * @param {Number} currentVisibleRowScrollPosition The current scroll position of the container\n * @param {Element} emojiContainer The emojis container element\n * @param {Object} initialCategoryScrollPositions Scroll positions for each category\n * @param {Function} renderAtPosition Function to render the appropriate emojis for a scroll position\n * @return {Function}\n */\nconst getHandleScroll = (\n root,\n currentVisibleRowScrollPosition,\n emojiContainer,\n initialCategoryScrollPositions,\n renderAtPosition\n) => {\n // Scope some local variables to track the scroll positions of the categories. We need to\n // recalculate these because adding recent emojis can change those positions by adding\n // additional rows.\n let [\n currentCategoryElement,\n previousCategoryPosition,\n nextCategoryPosition\n ] = getCategoryByScrollPosition(root, emojiContainer.scrollTop, initialCategoryScrollPositions);\n\n return (categoryScrollPositions, rowData) => {\n const newScrollPosition = emojiContainer.scrollTop;\n const upperScrollBound = currentVisibleRowScrollPosition + ROW_HEIGHT_RAW;\n const lowerScrollBound = currentVisibleRowScrollPosition - ROW_HEIGHT_RAW;\n // We only need to update the active category indicator if the user has scrolled into a\n // new category scroll position.\n const updateActiveCategory = (newScrollPosition >= nextCategoryPosition) ||\n (newScrollPosition < previousCategoryPosition);\n // We only need to render new emoji rows if the user has scrolled far enough that a new row\n // would be visible (i.e. they've scrolled up or down more than 40px - the height of a row).\n const updateRenderRows = (newScrollPosition < lowerScrollBound) || (newScrollPosition > upperScrollBound);\n\n if (updateActiveCategory) {\n // New category is visible so update the active category selector and re-index the\n // positions incase anything has changed.\n [\n currentCategoryElement,\n previousCategoryPosition,\n nextCategoryPosition\n ] = getCategoryByScrollPosition(root, newScrollPosition, categoryScrollPositions);\n setCategorySelectorActive(root, currentCategoryElement);\n }\n\n if (updateRenderRows) {\n // A new row should be visible so re-render the visible emojis at this new position.\n // We request an animation frame from the browser so that we're not blocking anything.\n // The animation only needs to occur as soon as the browser is ready not immediately.\n requestAnimationFrame(() => {\n renderAtPosition(newScrollPosition, rowData);\n // Remember the updated position.\n currentVisibleRowScrollPosition = newScrollPosition;\n });\n }\n };\n};\n\n/**\n * Build the function that handles search input from the user.\n *\n * @param {Element} searchInput The search input element\n * @param {Element} searchResultsContainer Container element to display the search results\n * @param {Element} emojiContainer Container element for the emoji rows\n * @return {Function}\n */\nconst getHandleSearch = (searchInput, searchResultsContainer, emojiContainer) => {\n const rowContainer = searchResultsContainer.querySelector(SELECTORS.ROW_CONTAINER);\n // Build a render function for the search results.\n const renderSearchResultsAtPosition = generateRenderRowsAtPositionFunction(rowContainer);\n searchResultsContainer.append(rowContainer);\n\n return async () => {\n const searchTerm = searchInput.value.toLowerCase();\n\n if (searchTerm) {\n // Display the search results container and hide the emojis container.\n showSearchResults(emojiContainer, searchResultsContainer);\n\n // Find which emojis match the user's search input.\n const matchingEmojis = Object.keys(EmojiData.byShortName).reduce((carry, shortName) => {\n if (shortName.includes(searchTerm)) {\n carry.push({\n shortnames: [shortName],\n unified: EmojiData.byShortName[shortName]\n });\n }\n return carry;\n }, []);\n\n const searchResultsString = await get_string('searchresults', 'core');\n const rowData = createRowDataForCategory(searchResultsString, searchResultsString, matchingEmojis, 0);\n // Show the emoji rows for the search results.\n renderSearchResultsAtPosition(0, rowData, rowData.length);\n } else {\n // Hide the search container and show the emojis container.\n clearSearch(emojiContainer, searchResultsContainer, searchInput);\n }\n };\n};\n\n/**\n * Register the emoji picker event listeners.\n *\n * @param {Element} root The picker root element\n * @param {Element} emojiContainer Root element containing the list of visible emojis\n * @param {Function} renderAtPosition Function to render the visible emojis at a given scroll position\n * @param {Number} currentVisibleRowScrollPosition What is the current scroll position\n * @param {Function} selectCallback Function to execute when the user picks an emoji\n * @param {Object} categoryScrollPositions Scroll positions for where each of the emoji categories begin\n * @param {Array} rowData Data representing each of the display rows for hte emoji container\n * @param {Number} recentEmojiRowCount Number of rows of recent emojis\n */\nconst registerEventListeners = (\n root,\n emojiContainer,\n renderAtPosition,\n currentVisibleRowScrollPosition,\n selectCallback,\n categoryScrollPositions,\n rowData,\n recentEmojiRowCount\n) => {\n const searchInput = root.querySelector(SELECTORS.SEARCH_INPUT);\n const searchResultsContainer = root.querySelector(SELECTORS.SEARCH_RESULTS_CONTAINER);\n const emojiPreview = root.querySelector(SELECTORS.EMOJI_PREVIEW);\n const emojiShortName = root.querySelector(SELECTORS.EMOJI_SHORT_NAME);\n // Build the click handler function.\n const clickHandler = getHandleClick(\n recentEmojiRowCount,\n emojiContainer,\n searchResultsContainer,\n searchInput,\n selectCallback,\n renderAtPosition\n );\n // Build the scroll handler function.\n const scrollHandler = getHandleScroll(\n root,\n currentVisibleRowScrollPosition,\n emojiContainer,\n categoryScrollPositions,\n renderAtPosition\n );\n const searchHandler = getHandleSearch(searchInput, searchResultsContainer, emojiContainer);\n\n // Mouse enter/leave events to show the emoji preview on hover or focus.\n root.addEventListener('focus', getHandleMouseEnter(emojiPreview, emojiShortName), true);\n root.addEventListener('blur', getHandleMouseLeave(emojiPreview, emojiShortName), true);\n root.addEventListener('mouseenter', getHandleMouseEnter(emojiPreview, emojiShortName), true);\n root.addEventListener('mouseleave', getHandleMouseLeave(emojiPreview, emojiShortName), true);\n // User selects an emoji or clicks on one of the emoji category selectors.\n root.addEventListener('click', e => {\n // Update the row data and category scroll positions because they may have changes if the\n // user selects an emoji which updates the recent emojis list.\n [rowData, categoryScrollPositions] = clickHandler(e, rowData, categoryScrollPositions);\n });\n // Throttle the scroll event to only execute once every 50 milliseconds to prevent performance issues\n // in the browser when re-rendering the picker emojis. The scroll event fires a lot otherwise.\n emojiContainer.addEventListener('scroll', throttle(() => scrollHandler(categoryScrollPositions, rowData), 50));\n // Debounce the search input so that it only executes 200 milliseconds after the user has finished typing.\n searchInput.addEventListener('input', debounce(searchHandler, 200));\n};\n\n/**\n * Initialise the emoji picker.\n *\n * @param {Element} root The root element for the picker\n * @param {Function} selectCallback Callback for when the user selects an emoji\n */\nexport default (root, selectCallback) => {\n const emojiContainer = root.querySelector(SELECTORS.EMOJIS_CONTAINER);\n const rowContainer = emojiContainer.querySelector(SELECTORS.ROW_CONTAINER);\n const recentEmojis = getRecentEmojis();\n // Add the recent emojis category to the list of standard categories.\n const allData = [{\n name: 'Recent',\n emojis: recentEmojis\n }, ...EmojiData.byCategory];\n let rowData = [];\n let recentEmojiRowCount = 0;\n\n /**\n * Split categories data into rows which represent how they will be displayed in the\n * picker. Each category will add a row containing the display name for the category\n * and a row for every 9 emojis in the category. The row data will be used to calculate\n * which emojis should be visible in the picker at any given time.\n *\n * E.g.\n * input = [\n * {name: 'example1', emojis: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]},\n * {name: 'example2', emojis: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]},\n * ]\n * output = [\n * {type: 'categoryName': data: 'Example 1'},\n * {type: 'emojiRow': data: [1, 2, 3, 4, 5, 6, 7, 8, 9]},\n * {type: 'emojiRow': data: [10, 11, 12]},\n * {type: 'categoryName': data: 'Example 2'},\n * {type: 'emojiRow': data: [13, 14, 15, 16, 17, 18, 19, 20, 21]},\n * {type: 'emojiRow': data: [22, 23]},\n * ]\n */\n allData.forEach(category => {\n const categorySelector = getCategorySelectorByCategoryName(root, category.name);\n // Get the display name from the category selector button so that we don't need to\n // send an ajax request for the string.\n const categoryDisplayName = categorySelector.title;\n const categoryRowData = createRowDataForCategory(category.name, categoryDisplayName, category.emojis, rowData.length);\n\n if (category.name === 'Recent') {\n // Remember how many recent emoji rows there are because it needs to be used to\n // re-index the row data later when we're adding more recent emojis.\n recentEmojiRowCount = categoryRowData.length;\n }\n\n rowData = rowData.concat(categoryRowData);\n });\n\n // Index the row data so that we can calculate which rows should be visible.\n rowData = addIndexesToRowData(rowData);\n // Calculate the scroll positions for each of the categories within the emoji container.\n // These are used to know where to jump to when the user selects a specific category.\n const categoryScrollPositions = getCategoryScrollPositionsFromRowData(rowData);\n const renderAtPosition = generateRenderRowsAtPositionFunction(rowContainer);\n // Display the initial set of emojis.\n renderAtPosition(0, rowData);\n\n registerEventListeners(\n root,\n emojiContainer,\n renderAtPosition,\n 0,\n selectCallback,\n categoryScrollPositions,\n rowData,\n recentEmojiRowCount\n );\n};"],"file":"picker.min.js"} \ No newline at end of file +{"version":3,"sources":["../../src/emoji/picker.js"],"names":["ROW_RENDER_BUFFER_COUNT","RECENT_EMOJIS_STORAGE_KEY","ROW_HEIGHT_RAW","EMOJIS_PER_ROW","ROW_TYPE","EMOJI","HEADER","SELECTORS","CATEGORY_SELECTOR","EMOJIS_CONTAINER","EMOJI_PREVIEW","EMOJI_SHORT_NAME","ROW_CONTAINER","SEARCH_INPUT","SEARCH_RESULTS_CONTAINER","createRowDataForCategory","categoryName","categoryDisplayName","emojis","totalRowCount","rowData","push","index","length","type","data","name","displayName","i","rowEmojis","slice","addIndexesToRowData","map","getCategoryScrollPositionsFromRowData","reduce","carry","row","createHeaderRow","rowIndex","context","text","html","temp","document","createElement","innerHTML","firstChild","createEmojiRow","emojiData","charCodes","unified","split","code","emojiText","String","fromCodePoint","apply","shortnames","join","spacer","spacers","Array","fill","isEmojiElement","element","getAttribute","findCategorySelectorFromElement","parentElement","getCategorySelectorByCategoryName","root","querySelector","setCategorySelectorActive","allCategorySelectors","querySelectorAll","forEach","selector","classList","remove","add","getCategoryByScrollPosition","position","categoryScrollPositions","positions","categoryPosition","sort","a","b","candidate","previousPosition","currentPosition","nextPosition","getRecentEmojis","storedData","LocalStorage","get","JSON","parse","saveRecentEmoji","recentEmojis","set","stringify","addRecentEmoji","recentEmojiRowCount","newEmoji","newRecentEmojis","filter","emoji","newRecentEmojiRowData","concat","getRowsToRender","scrollPosition","visibleRowCount","minVisibleRow","Math","floor","start","rows","createRowElement","style","left","right","top","doRowsMatch","renderRows","rowContainer","currentRows","nextRows","toAdd","nextRow","some","currentRow","toKeep","toRemove","toRemoveElements","Promise","all","nextRowIndex","nextRowData","nextRowNode","insertBefore","splice","appendChild","removeChild","generateRenderRowsAtPositionFunction","rowCount","isRendering","renderNextRows","nextRowsToRender","rowLimit","height","showSearchResults","emojiContainer","searchResultsContainer","clearSearch","searchInput","value","getHandleMouseEnter","emojiPreview","emojiShortName","e","target","textContent","getHandleMouseLeave","getHandleClick","selectCallback","renderAtPosition","newRowData","newCategoryScrollPositions","replace","currentScrollTop","scrollTop","isRecentEmojiRowVisible","categorySelector","selectedCategory","getHandleScroll","currentVisibleRowScrollPosition","initialCategoryScrollPositions","currentCategoryElement","previousCategoryPosition","nextCategoryPosition","newScrollPosition","upperScrollBound","lowerScrollBound","updateActiveCategory","requestAnimationFrame","getHandleSearch","renderSearchResultsAtPosition","searchTerm","toLowerCase","matchingEmojis","Object","keys","EmojiData","byShortName","shortName","includes","searchResultsString","registerEventListeners","clickHandler","scrollHandler","searchHandler","addEventListener","allData","byCategory","category","title","categoryRowData"],"mappings":"4NAqBA,uDACA,kU,6vDAMMA,CAAAA,CAAuB,CAAG,C,CAC1BC,CAAyB,CAAG,sB,CAC5BC,CAAc,CAAG,E,CACjBC,CAAc,CAAG,C,CAEjBC,CAAQ,CAAG,CACbC,KAAK,CAAE,CADM,CAEbC,MAAM,CAAE,CAFK,C,CAIXC,CAAS,CAAG,CACdC,iBAAiB,CAAE,iCADL,CAEdC,gBAAgB,CAAE,oCAFJ,CAGdC,aAAa,CAAE,iCAHD,CAIdC,gBAAgB,CAAE,oCAJJ,CAKdC,aAAa,CAAE,iCALD,CAMdC,YAAY,CAAE,gCANA,CAOdC,wBAAwB,CAAE,4CAPZ,C,CAmBZC,CAAwB,CAAG,SAACC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hB,CAAqC2L,CAAQ,CAAC1L,MAA9C,CAAsDE,CAAO,CAACG,MAA9D,CALxB,CAOxB,GAAsB,QAAlB,GAAAqL,CAAQ,CAAClL,IAAb,CAAgC,CAG5B4E,CAAmB,CAAGwG,CAAe,CAACvL,MACzC,CAEDH,CAAO,CAAGA,CAAO,CAACwF,MAAR,CAAekG,CAAf,CACb,CAdD,EAiBA1L,CAAO,CAAGW,CAAmB,CAACX,CAAD,CAA7B,CAjDqC,GAoD/B6D,CAAAA,CAAuB,CAAGhD,CAAqC,CAACb,CAAD,CApDhC,CAqD/BiJ,CAAgB,CAAGtB,CAAoC,CAACnB,CAAD,CArDxB,CAuDrCyC,CAAgB,CAAC,CAAD,CAAIjJ,CAAJ,CAAhB,CAEAiL,CAAsB,CAClBhI,CADkB,CAElBkF,CAFkB,CAGlBc,CAHkB,CAIlB,CAJkB,CAKlBD,CALkB,CAMlBnF,CANkB,CAOlB7D,CAPkB,CAQlBkF,CARkB,CAUzB,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 * Emoji picker.\n *\n * @copyright 2019 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport LocalStorage from 'core/localstorage';\nimport * as EmojiData from 'core/emoji/data';\nimport {throttle, debounce} from 'core/utils';\nimport {get_string} from 'core/str';\nimport {render as renderTemplate} from 'core/templates';\n\nconst VISIBLE_ROW_COUNT = 10;\nconst ROW_RENDER_BUFFER_COUNT = 5;\nconst RECENT_EMOJIS_STORAGE_KEY = 'moodle-recent-emojis';\nconst ROW_HEIGHT_RAW = 40;\nconst EMOJIS_PER_ROW = 7;\nconst MAX_RECENT_COUNT = EMOJIS_PER_ROW * 3;\nconst ROW_TYPE = {\n EMOJI: 0,\n HEADER: 1\n};\nconst SELECTORS = {\n CATEGORY_SELECTOR: '[data-action=\"show-category\"]',\n EMOJIS_CONTAINER: '[data-region=\"emojis-container\"]',\n EMOJI_PREVIEW: '[data-region=\"emoji-preview\"]',\n EMOJI_SHORT_NAME: '[data-region=\"emoji-short-name\"]',\n ROW_CONTAINER: '[data-region=\"row-container\"]',\n SEARCH_INPUT: '[data-region=\"search-input\"]',\n SEARCH_RESULTS_CONTAINER: '[data-region=\"search-results-container\"]'\n};\n\n/**\n * Create the row data for a category.\n *\n * @param {String} categoryName The category name\n * @param {String} categoryDisplayName The category display name\n * @param {Array} emojis The emoji data\n * @param {Number} totalRowCount The total number of rows generated so far\n * @return {Array}\n */\nconst createRowDataForCategory = (categoryName, categoryDisplayName, emojis, totalRowCount) => {\n const rowData = [];\n rowData.push({\n index: totalRowCount + rowData.length,\n type: ROW_TYPE.HEADER,\n data: {\n name: categoryName,\n displayName: categoryDisplayName\n }\n });\n\n for (let i = 0; i < emojis.length; i += EMOJIS_PER_ROW) {\n const rowEmojis = emojis.slice(i, i + EMOJIS_PER_ROW);\n rowData.push({\n index: totalRowCount + rowData.length,\n type: ROW_TYPE.EMOJI,\n data: rowEmojis\n });\n }\n\n return rowData;\n};\n\n/**\n * Add each row's index to it's value in the row data.\n *\n * @param {Array} rowData List of emoji row data\n * @return {Array}\n */\nconst addIndexesToRowData = (rowData) => {\n return rowData.map((data, index) => {\n return {...data, index};\n });\n};\n\n/**\n * Calculate the scroll position for the beginning of each category from\n * the row data.\n *\n * @param {Array} rowData List of emoji row data\n * @return {Object}\n */\nconst getCategoryScrollPositionsFromRowData = (rowData) => {\n return rowData.reduce((carry, row, index) => {\n if (row.type === ROW_TYPE.HEADER) {\n carry[row.data.name] = index * ROW_HEIGHT_RAW;\n }\n return carry;\n }, {});\n};\n\n/**\n * Create a header row element for the category name.\n *\n * @param {Number} rowIndex Index of the row in the row data\n * @param {String} name The category display name\n * @return {Element}\n */\nconst createHeaderRow = async (rowIndex, name) => {\n const context = {\n index: rowIndex,\n text: name\n };\n const html = await renderTemplate('core/emoji/header_row', context);\n const temp = document.createElement('div');\n temp.innerHTML = html;\n return temp.firstChild;\n};\n\n/**\n * Create an emoji row element.\n *\n * @param {Number} rowIndex Index of the row in the row data\n * @param {Array} emojis The list of emoji data for the row\n * @return {Element}\n */\nconst createEmojiRow = async (rowIndex, emojis) => {\n const context = {\n index: rowIndex,\n emojis: emojis.map(emojiData => {\n const charCodes = emojiData.unified.split('-').map(code => `0x${code}`);\n const emojiText = String.fromCodePoint.apply(null, charCodes);\n return {\n shortnames: `:${emojiData.shortnames.join(': :')}:`,\n unified: emojiData.unified,\n text: emojiText,\n spacer: false\n };\n }),\n spacers: Array(EMOJIS_PER_ROW - emojis.length).fill(true)\n };\n const html = await renderTemplate('core/emoji/emoji_row', context);\n const temp = document.createElement('div');\n temp.innerHTML = html;\n return temp.firstChild;\n};\n\n/**\n * Check if the element is an emoji element.\n *\n * @param {Element} element Element to check\n * @return {Bool}\n */\nconst isEmojiElement = element => element.getAttribute('data-short-names') !== null;\n\n/**\n * Search from an element and up through it's ancestors to fine the category\n * selector element and return it.\n *\n * @param {Element} element Element to begin searching from\n * @return {Element|null}\n */\nconst findCategorySelectorFromElement = element => {\n if (!element) {\n return null;\n }\n\n if (element.getAttribute('data-action') === 'show-category') {\n return element;\n } else {\n return findCategorySelectorFromElement(element.parentElement);\n }\n};\n\nconst getCategorySelectorByCategoryName = (root, name) => {\n return root.querySelector(`[data-category=\"${name}\"]`);\n};\n\n/**\n * Sets the given category selector element as active.\n *\n * @param {Element} root The root picker element\n * @param {Element} element The category selector element to make active\n */\nconst setCategorySelectorActive = (root, element) => {\n const allCategorySelectors = root.querySelectorAll(SELECTORS.CATEGORY_SELECTOR);\n allCategorySelectors.forEach(selector => {\n selector.classList.remove('selected');\n });\n\n element.classList.add('selected');\n};\n\n/**\n * Get the category selector element and the scroll positions for the previous and\n * next categories for the given scroll position.\n *\n * @param {Element} root The picker root element\n * @param {Number} position The position to get the category for\n * @param {Object} categoryScrollPositions Set of scroll positions for all categories\n * @return {Array}\n */\nconst getCategoryByScrollPosition = (root, position, categoryScrollPositions) => {\n let positions = [];\n\n if (position < 0) {\n position = 0;\n }\n\n // Get all of the category positions.\n for (const categoryName in categoryScrollPositions) {\n const categoryPosition = categoryScrollPositions[categoryName];\n positions.push([categoryPosition, categoryName]);\n }\n\n // Sort the positions in ascending order.\n positions.sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (a > b) {\n return 1;\n } else {\n return 0;\n }\n });\n\n // Get the current category name as well as the previous and next category\n // positions from the sorted list of positions.\n const {categoryName, previousPosition, nextPosition} = positions.reduce(\n (carry, candidate) => {\n const [categoryPosition, categoryName] = candidate;\n\n if (categoryPosition <= position) {\n carry.categoryName = categoryName;\n carry.previousPosition = carry.currentPosition;\n carry.currentPosition = position;\n } else if (carry.nextPosition === null) {\n carry.nextPosition = categoryPosition;\n }\n\n return carry;\n },\n {\n categoryName: null,\n currentPosition: null,\n previousPosition: null,\n nextPosition: null\n }\n );\n\n return [getCategorySelectorByCategoryName(root, categoryName), previousPosition, nextPosition];\n};\n\n/**\n * Get the list of recent emojis data from local storage.\n *\n * @return {Array}\n */\nconst getRecentEmojis = () => {\n const storedData = LocalStorage.get(RECENT_EMOJIS_STORAGE_KEY);\n return storedData ? JSON.parse(storedData) : [];\n};\n\n/**\n * Save the list of recent emojis in local storage.\n *\n * @param {Array} recentEmojis List of emoji data to save\n */\nconst saveRecentEmoji = (recentEmojis) => {\n LocalStorage.set(RECENT_EMOJIS_STORAGE_KEY, JSON.stringify(recentEmojis));\n};\n\n/**\n * Add an emoji data to the set of recent emojis. This function will update the row\n * data to ensure that the recent emoji rows are correct and all of the rows are\n * re-indexed.\n *\n * The new set of recent emojis are saved in local storage and the full set of updated\n * row data and new emoji row count are returned.\n *\n * @param {Array} rowData The emoji rows data\n * @param {Number} recentEmojiRowCount Count of the recent emoji rows\n * @param {Object} newEmoji The emoji data for the emoji to add to the recent emoji list\n * @return {Array}\n */\nconst addRecentEmoji = (rowData, recentEmojiRowCount, newEmoji) => {\n // The first set of rows is always the recent emojis.\n const categoryName = rowData[0].data.name;\n const categoryDisplayName = rowData[0].data.displayName;\n const recentEmojis = getRecentEmojis();\n // Add the new emoji to the start of the list of recent emojis.\n let newRecentEmojis = [newEmoji, ...recentEmojis.filter(emoji => emoji.unified != newEmoji.unified)];\n // Limit the number of recent emojis.\n newRecentEmojis = newRecentEmojis.slice(0, MAX_RECENT_COUNT);\n const newRecentEmojiRowData = createRowDataForCategory(categoryName, categoryDisplayName, newRecentEmojis);\n\n // Save the new list in local storage.\n saveRecentEmoji(newRecentEmojis);\n\n return [\n // Return the new rowData and re-index it to make sure it's all correct.\n addIndexesToRowData(newRecentEmojiRowData.concat(rowData.slice(recentEmojiRowCount))),\n newRecentEmojiRowData.length\n ];\n};\n\n/**\n * Calculate which rows should be visible based on the given scroll position. Adds a\n * buffer to amount to either side of the total number of requested rows so that\n * scrolling the emoji rows container is smooth.\n *\n * @param {Number} scrollPosition Scroll position within the emoji container\n * @param {Number} visibleRowCount How many rows should be visible\n * @param {Array} rowData The emoji rows data\n * @return {Array}\n */\nconst getRowsToRender = (scrollPosition, visibleRowCount, rowData) => {\n const minVisibleRow = scrollPosition > ROW_HEIGHT_RAW ? Math.floor(scrollPosition / ROW_HEIGHT_RAW) : 0;\n const start = minVisibleRow >= ROW_RENDER_BUFFER_COUNT ? minVisibleRow - ROW_RENDER_BUFFER_COUNT : minVisibleRow;\n const end = minVisibleRow + visibleRowCount + ROW_RENDER_BUFFER_COUNT;\n const rows = rowData.slice(start, end);\n return rows;\n};\n\n/**\n * Create a row element from the row data.\n *\n * @param {Object} rowData The emoji row data\n * @return {Element}\n */\nconst createRowElement = async (rowData) => {\n let row = null;\n if (rowData.type === ROW_TYPE.HEADER) {\n row = await createHeaderRow(rowData.index, rowData.data.displayName);\n } else {\n row = await createEmojiRow(rowData.index, rowData.data);\n }\n\n row.style.position = 'absolute';\n row.style.left = 0;\n row.style.right = 0;\n row.style.top = `${rowData.index * ROW_HEIGHT_RAW}px`;\n\n return row;\n};\n\n/**\n * Check if the given rows match.\n *\n * @param {Object} a The first row\n * @param {Object} b The second row\n * @return {Bool}\n */\nconst doRowsMatch = (a, b) => {\n if (a.index !== b.index) {\n return false;\n }\n\n if (a.type !== b.type) {\n return false;\n }\n\n if (typeof a.data != typeof b.data) {\n return false;\n }\n\n if (a.type === ROW_TYPE.HEADER) {\n return a.data.name === b.data.name;\n } else {\n if (a.data.length !== b.data.length) {\n return false;\n }\n\n for (let i = 0; i < a.data.length; i++) {\n if (a.data[i].unified != b.data[i].unified) {\n return false;\n }\n }\n }\n\n return true;\n};\n\n/**\n * Update the visible rows. Deletes any row elements that should no longer\n * be visible and creates the newly visible row elements. Any rows that haven't\n * changed visibility will be left untouched.\n *\n * @param {Element} rowContainer The container element for the emoji rows\n * @param {Array} currentRows List of row data that matches the currently visible rows\n * @param {Array} nextRows List of row data containing the new list of rows to be made visible\n */\nconst renderRows = async (rowContainer, currentRows, nextRows) => {\n // We need to add any rows that are in nextRows but not in currentRows.\n const toAdd = nextRows.filter(nextRow => !currentRows.some(currentRow => doRowsMatch(currentRow, nextRow)));\n // Remember which rows will still be visible so that we can insert our element in the correct place in the DOM.\n let toKeep = currentRows.filter(currentRow => nextRows.some(nextRow => doRowsMatch(currentRow, nextRow)));\n // We need to remove any rows that are in currentRows but not in nextRows.\n const toRemove = currentRows.filter(currentRow => !nextRows.some(nextRow => doRowsMatch(currentRow, nextRow)));\n const toRemoveElements = toRemove.map(rowData => rowContainer.querySelectorAll(`[data-row=\"${rowData.index}\"]`));\n\n // Render all of the templates first.\n const rows = await Promise.all(toAdd.map(rowData => createRowElement(rowData)));\n\n rows.forEach((row, index) => {\n const rowData = toAdd[index];\n let nextRowIndex = null;\n\n for (let i = 0; i < toKeep.length; i++) {\n const candidate = toKeep[i];\n if (candidate.index > rowData.index) {\n nextRowIndex = i;\n break;\n }\n }\n\n // Make sure the elements get added to the DOM in the correct order (ascending by row data index)\n // so that they appear naturally in the tab order.\n if (nextRowIndex !== null) {\n const nextRowData = toKeep[nextRowIndex];\n const nextRowNode = rowContainer.querySelector(`[data-row=\"${nextRowData.index}\"]`);\n\n rowContainer.insertBefore(row, nextRowNode);\n toKeep.splice(nextRowIndex, 0, toKeep);\n } else {\n toKeep.push(rowData);\n rowContainer.appendChild(row);\n }\n });\n\n toRemoveElements.forEach(rows => rows.forEach(row => rowContainer.removeChild(row)));\n};\n\n/**\n * Build a function to render the visible emoji rows for a given scroll\n * position.\n *\n * @param {Element} rowContainer The container element for the emoji rows\n * @return {Function}\n */\nconst generateRenderRowsAtPositionFunction = (rowContainer) => {\n let currentRows = [];\n let nextRows = [];\n let rowCount = 0;\n let isRendering = false;\n const renderNextRows = async () => {\n if (!nextRows.length) {\n return;\n }\n\n if (isRendering) {\n return;\n }\n\n isRendering = true;\n const nextRowsToRender = nextRows.slice();\n nextRows = [];\n\n await renderRows(rowContainer, currentRows, nextRowsToRender);\n currentRows = nextRowsToRender;\n isRendering = false;\n renderNextRows();\n };\n\n return (scrollPosition, rowData, rowLimit = VISIBLE_ROW_COUNT) => {\n nextRows = getRowsToRender(scrollPosition, rowLimit, rowData);\n renderNextRows();\n\n if (rowCount !== rowData.length) {\n // Adjust the height of the container to match the number of rows.\n rowContainer.style.height = `${rowData.length * ROW_HEIGHT_RAW}px`;\n }\n\n rowCount = rowData.length;\n };\n};\n\n/**\n * Show the search results container and hide the emoji container.\n *\n * @param {Element} emojiContainer The emojis container\n * @param {Element} searchResultsContainer The search results container\n */\nconst showSearchResults = (emojiContainer, searchResultsContainer) => {\n searchResultsContainer.classList.remove('hidden');\n emojiContainer.classList.add('hidden');\n};\n\n/**\n * Hide the search result container and show the emojis container.\n *\n * @param {Element} emojiContainer The emojis container\n * @param {Element} searchResultsContainer The search results container\n * @param {Element} searchInput The search input\n */\nconst clearSearch = (emojiContainer, searchResultsContainer, searchInput) => {\n searchResultsContainer.classList.add('hidden');\n emojiContainer.classList.remove('hidden');\n searchInput.value = '';\n};\n\n/**\n * Build function to handle mouse hovering an emoji. Shows the preview.\n *\n * @param {Element} emojiPreview The emoji preview element\n * @param {Element} emojiShortName The emoji short name element\n * @return {Function}\n */\nconst getHandleMouseEnter = (emojiPreview, emojiShortName) => {\n return (e) => {\n const target = e.target;\n if (isEmojiElement(target)) {\n emojiShortName.textContent = target.getAttribute('data-short-names');\n emojiPreview.textContent = target.textContent;\n }\n };\n};\n\n/**\n * Build function to handle mouse leaving an emoji. Removes the preview.\n *\n * @param {Element} emojiPreview The emoji preview element\n * @param {Element} emojiShortName The emoji short name element\n * @return {Function}\n */\nconst getHandleMouseLeave = (emojiPreview, emojiShortName) => {\n return (e) => {\n const target = e.target;\n if (isEmojiElement(target)) {\n emojiShortName.textContent = '';\n emojiPreview.textContent = '';\n }\n };\n};\n\n/**\n * Build the function to handle a user clicking something in the picker.\n *\n * The function currently handles clicking on the category selector or selecting\n * a specific emoji.\n *\n * @param {Number} recentEmojiRowCount Number of rows of recent emojis\n * @param {Element} emojiContainer Container element for the visible of emojis\n * @param {Element} searchResultsContainer Contaienr element for the search results\n * @param {Element} searchInput Search input element\n * @param {Function} selectCallback Callback function to execute when a user selects an emoji\n * @param {Function} renderAtPosition Render function to display current visible emojis\n * @return {Function}\n */\nconst getHandleClick = (\n recentEmojiRowCount,\n emojiContainer,\n searchResultsContainer,\n searchInput,\n selectCallback,\n renderAtPosition\n) => {\n return (e, rowData, categoryScrollPositions) => {\n const target = e.target;\n let newRowData = rowData;\n let newCategoryScrollPositions = categoryScrollPositions;\n\n // Hide the search results if they are visible.\n clearSearch(emojiContainer, searchResultsContainer, searchInput);\n\n if (isEmojiElement(target)) {\n // Emoji selected.\n const unified = target.getAttribute('data-unified');\n const shortnames = target.getAttribute('data-short-names').replace(/:/g, '').split(' ');\n // Build the emoji data from the selected element.\n const emojiData = {unified, shortnames};\n const currentScrollTop = emojiContainer.scrollTop;\n const isRecentEmojiRowVisible = emojiContainer.querySelector(`[data-row=\"${recentEmojiRowCount - 1}\"]`) !== null;\n // Save the selected emoji in the recent emojis list.\n [newRowData, recentEmojiRowCount] = addRecentEmoji(rowData, recentEmojiRowCount, emojiData);\n // Re-index the category scroll positions because the additional recent emoji may have\n // changed their positions.\n newCategoryScrollPositions = getCategoryScrollPositionsFromRowData(newRowData);\n\n if (isRecentEmojiRowVisible) {\n // If the list of recent emojis is currently visible then we need to re-render the emojis\n // to update the display and show the newly selected recent emoji.\n renderAtPosition(currentScrollTop, newRowData);\n }\n\n // Call the client's callback function with the selected emoji.\n selectCallback(target.textContent);\n // Return the newly calculated row data and scroll positions.\n return [newRowData, newCategoryScrollPositions];\n }\n\n const categorySelector = findCategorySelectorFromElement(target);\n if (categorySelector) {\n // Category selector.\n const selectedCategory = categorySelector.getAttribute('data-category');\n const position = categoryScrollPositions[selectedCategory];\n // Scroll the container to the selected category. This will trigger the\n // on scroll handler to re-render the visibile emojis.\n emojiContainer.scrollTop = position;\n }\n\n return [newRowData, newCategoryScrollPositions];\n };\n};\n\n/**\n * Build the function that handles scrolling of the emoji container to display the\n * correct emojis.\n *\n * We render the emoji rows as they are needed rather than all up front so that we\n * can avoid adding tends of thousands of elements to the DOM unnecessarily which\n * would bog down performance.\n *\n * @param {Element} root The picker root element\n * @param {Number} currentVisibleRowScrollPosition The current scroll position of the container\n * @param {Element} emojiContainer The emojis container element\n * @param {Object} initialCategoryScrollPositions Scroll positions for each category\n * @param {Function} renderAtPosition Function to render the appropriate emojis for a scroll position\n * @return {Function}\n */\nconst getHandleScroll = (\n root,\n currentVisibleRowScrollPosition,\n emojiContainer,\n initialCategoryScrollPositions,\n renderAtPosition\n) => {\n // Scope some local variables to track the scroll positions of the categories. We need to\n // recalculate these because adding recent emojis can change those positions by adding\n // additional rows.\n let [\n currentCategoryElement,\n previousCategoryPosition,\n nextCategoryPosition\n ] = getCategoryByScrollPosition(root, emojiContainer.scrollTop, initialCategoryScrollPositions);\n\n return (categoryScrollPositions, rowData) => {\n const newScrollPosition = emojiContainer.scrollTop;\n const upperScrollBound = currentVisibleRowScrollPosition + ROW_HEIGHT_RAW;\n const lowerScrollBound = currentVisibleRowScrollPosition - ROW_HEIGHT_RAW;\n // We only need to update the active category indicator if the user has scrolled into a\n // new category scroll position.\n const updateActiveCategory = (newScrollPosition >= nextCategoryPosition) ||\n (newScrollPosition < previousCategoryPosition);\n // We only need to render new emoji rows if the user has scrolled far enough that a new row\n // would be visible (i.e. they've scrolled up or down more than 40px - the height of a row).\n const updateRenderRows = (newScrollPosition < lowerScrollBound) || (newScrollPosition > upperScrollBound);\n\n if (updateActiveCategory) {\n // New category is visible so update the active category selector and re-index the\n // positions incase anything has changed.\n [\n currentCategoryElement,\n previousCategoryPosition,\n nextCategoryPosition\n ] = getCategoryByScrollPosition(root, newScrollPosition, categoryScrollPositions);\n setCategorySelectorActive(root, currentCategoryElement);\n }\n\n if (updateRenderRows) {\n // A new row should be visible so re-render the visible emojis at this new position.\n // We request an animation frame from the browser so that we're not blocking anything.\n // The animation only needs to occur as soon as the browser is ready not immediately.\n requestAnimationFrame(() => {\n renderAtPosition(newScrollPosition, rowData);\n // Remember the updated position.\n currentVisibleRowScrollPosition = newScrollPosition;\n });\n }\n };\n};\n\n/**\n * Build the function that handles search input from the user.\n *\n * @param {Element} searchInput The search input element\n * @param {Element} searchResultsContainer Container element to display the search results\n * @param {Element} emojiContainer Container element for the emoji rows\n * @return {Function}\n */\nconst getHandleSearch = (searchInput, searchResultsContainer, emojiContainer) => {\n const rowContainer = searchResultsContainer.querySelector(SELECTORS.ROW_CONTAINER);\n // Build a render function for the search results.\n const renderSearchResultsAtPosition = generateRenderRowsAtPositionFunction(rowContainer);\n searchResultsContainer.appendChild(rowContainer);\n\n return async () => {\n const searchTerm = searchInput.value.toLowerCase();\n\n if (searchTerm) {\n // Display the search results container and hide the emojis container.\n showSearchResults(emojiContainer, searchResultsContainer);\n\n // Find which emojis match the user's search input.\n const matchingEmojis = Object.keys(EmojiData.byShortName).reduce((carry, shortName) => {\n if (shortName.includes(searchTerm)) {\n carry.push({\n shortnames: [shortName],\n unified: EmojiData.byShortName[shortName]\n });\n }\n return carry;\n }, []);\n\n const searchResultsString = await get_string('searchresults', 'core');\n const rowData = createRowDataForCategory(searchResultsString, searchResultsString, matchingEmojis, 0);\n // Show the emoji rows for the search results.\n renderSearchResultsAtPosition(0, rowData, rowData.length);\n } else {\n // Hide the search container and show the emojis container.\n clearSearch(emojiContainer, searchResultsContainer, searchInput);\n }\n };\n};\n\n/**\n * Register the emoji picker event listeners.\n *\n * @param {Element} root The picker root element\n * @param {Element} emojiContainer Root element containing the list of visible emojis\n * @param {Function} renderAtPosition Function to render the visible emojis at a given scroll position\n * @param {Number} currentVisibleRowScrollPosition What is the current scroll position\n * @param {Function} selectCallback Function to execute when the user picks an emoji\n * @param {Object} categoryScrollPositions Scroll positions for where each of the emoji categories begin\n * @param {Array} rowData Data representing each of the display rows for hte emoji container\n * @param {Number} recentEmojiRowCount Number of rows of recent emojis\n */\nconst registerEventListeners = (\n root,\n emojiContainer,\n renderAtPosition,\n currentVisibleRowScrollPosition,\n selectCallback,\n categoryScrollPositions,\n rowData,\n recentEmojiRowCount\n) => {\n const searchInput = root.querySelector(SELECTORS.SEARCH_INPUT);\n const searchResultsContainer = root.querySelector(SELECTORS.SEARCH_RESULTS_CONTAINER);\n const emojiPreview = root.querySelector(SELECTORS.EMOJI_PREVIEW);\n const emojiShortName = root.querySelector(SELECTORS.EMOJI_SHORT_NAME);\n // Build the click handler function.\n const clickHandler = getHandleClick(\n recentEmojiRowCount,\n emojiContainer,\n searchResultsContainer,\n searchInput,\n selectCallback,\n renderAtPosition\n );\n // Build the scroll handler function.\n const scrollHandler = getHandleScroll(\n root,\n currentVisibleRowScrollPosition,\n emojiContainer,\n categoryScrollPositions,\n renderAtPosition\n );\n const searchHandler = getHandleSearch(searchInput, searchResultsContainer, emojiContainer);\n\n // Mouse enter/leave events to show the emoji preview on hover or focus.\n root.addEventListener('focus', getHandleMouseEnter(emojiPreview, emojiShortName), true);\n root.addEventListener('blur', getHandleMouseLeave(emojiPreview, emojiShortName), true);\n root.addEventListener('mouseenter', getHandleMouseEnter(emojiPreview, emojiShortName), true);\n root.addEventListener('mouseleave', getHandleMouseLeave(emojiPreview, emojiShortName), true);\n // User selects an emoji or clicks on one of the emoji category selectors.\n root.addEventListener('click', e => {\n // Update the row data and category scroll positions because they may have changes if the\n // user selects an emoji which updates the recent emojis list.\n [rowData, categoryScrollPositions] = clickHandler(e, rowData, categoryScrollPositions);\n });\n // Throttle the scroll event to only execute once every 50 milliseconds to prevent performance issues\n // in the browser when re-rendering the picker emojis. The scroll event fires a lot otherwise.\n emojiContainer.addEventListener('scroll', throttle(() => scrollHandler(categoryScrollPositions, rowData), 50));\n // Debounce the search input so that it only executes 200 milliseconds after the user has finished typing.\n searchInput.addEventListener('input', debounce(searchHandler, 200));\n};\n\n/**\n * Initialise the emoji picker.\n *\n * @param {Element} root The root element for the picker\n * @param {Function} selectCallback Callback for when the user selects an emoji\n */\nexport default (root, selectCallback) => {\n const emojiContainer = root.querySelector(SELECTORS.EMOJIS_CONTAINER);\n const rowContainer = emojiContainer.querySelector(SELECTORS.ROW_CONTAINER);\n const recentEmojis = getRecentEmojis();\n // Add the recent emojis category to the list of standard categories.\n const allData = [{\n name: 'Recent',\n emojis: recentEmojis\n }, ...EmojiData.byCategory];\n let rowData = [];\n let recentEmojiRowCount = 0;\n\n /**\n * Split categories data into rows which represent how they will be displayed in the\n * picker. Each category will add a row containing the display name for the category\n * and a row for every 9 emojis in the category. The row data will be used to calculate\n * which emojis should be visible in the picker at any given time.\n *\n * E.g.\n * input = [\n * {name: 'example1', emojis: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]},\n * {name: 'example2', emojis: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]},\n * ]\n * output = [\n * {type: 'categoryName': data: 'Example 1'},\n * {type: 'emojiRow': data: [1, 2, 3, 4, 5, 6, 7, 8, 9]},\n * {type: 'emojiRow': data: [10, 11, 12]},\n * {type: 'categoryName': data: 'Example 2'},\n * {type: 'emojiRow': data: [13, 14, 15, 16, 17, 18, 19, 20, 21]},\n * {type: 'emojiRow': data: [22, 23]},\n * ]\n */\n allData.forEach(category => {\n const categorySelector = getCategorySelectorByCategoryName(root, category.name);\n // Get the display name from the category selector button so that we don't need to\n // send an ajax request for the string.\n const categoryDisplayName = categorySelector.title;\n const categoryRowData = createRowDataForCategory(category.name, categoryDisplayName, category.emojis, rowData.length);\n\n if (category.name === 'Recent') {\n // Remember how many recent emoji rows there are because it needs to be used to\n // re-index the row data later when we're adding more recent emojis.\n recentEmojiRowCount = categoryRowData.length;\n }\n\n rowData = rowData.concat(categoryRowData);\n });\n\n // Index the row data so that we can calculate which rows should be visible.\n rowData = addIndexesToRowData(rowData);\n // Calculate the scroll positions for each of the categories within the emoji container.\n // These are used to know where to jump to when the user selects a specific category.\n const categoryScrollPositions = getCategoryScrollPositionsFromRowData(rowData);\n const renderAtPosition = generateRenderRowsAtPositionFunction(rowContainer);\n // Display the initial set of emojis.\n renderAtPosition(0, rowData);\n\n registerEventListeners(\n root,\n emojiContainer,\n renderAtPosition,\n 0,\n selectCallback,\n categoryScrollPositions,\n rowData,\n recentEmojiRowCount\n );\n};"],"file":"picker.min.js"} \ No newline at end of file diff --git a/lib/amd/src/emoji/picker.js b/lib/amd/src/emoji/picker.js index f1347cc2026..e1d350e5c83 100644 --- a/lib/amd/src/emoji/picker.js +++ b/lib/amd/src/emoji/picker.js @@ -430,7 +430,7 @@ const renderRows = async (rowContainer, currentRows, nextRows) => { toKeep.splice(nextRowIndex, 0, toKeep); } else { toKeep.push(rowData); - rowContainer.append(row); + rowContainer.appendChild(row); } }); @@ -688,7 +688,7 @@ const getHandleSearch = (searchInput, searchResultsContainer, emojiContainer) => const rowContainer = searchResultsContainer.querySelector(SELECTORS.ROW_CONTAINER); // Build a render function for the search results. const renderSearchResultsAtPosition = generateRenderRowsAtPositionFunction(rowContainer); - searchResultsContainer.append(rowContainer); + searchResultsContainer.appendChild(rowContainer); return async () => { const searchTerm = searchInput.value.toLowerCase();