@gitlab/at.js 1.5.8 → 1.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @gitlab/at.js - 1.5.8
2
+ * @gitlab/at.js - 1.5.11
3
3
  * Copyright (c) 2026 chord.luo <chord.luo@gmail.com>;
4
4
  * Homepage: https://gitlab.com/gitlab-org/frontend/At.js
5
5
  * License: MIT
@@ -465,7 +465,9 @@ Controller = class Controller {
465
465
  this.pos = 0;
466
466
  this.range = null;
467
467
  if ((this.$el = $(`#atwho-ground-${this.id}`, this.app.$el)).length === 0) {
468
- this.app.$el.append(this.$el = $(`<div id='atwho-ground-${this.id}'></div>`));
468
+ this.$el = $('<div></div>');
469
+ this.$el.attr('id', `atwho-ground-${this.id}`);
470
+ this.app.$el.append(this.$el);
469
471
  }
470
472
  this.model = new Model(this);
471
473
  this.view = new View(this);
@@ -587,6 +589,7 @@ Controller = class Controller {
587
589
  }
588
590
  query = this.catchQuery(e);
589
591
  if (!query) {
592
+ this._stopDelayedCall();
590
593
  this.expectedQueryCBId = null;
591
594
  return query;
592
595
  }
@@ -1 +1 @@
1
- (t=>{"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)})(function(o){var a={ESC:27,TAB:9,ENTER:13,CTRL:17,A:65,P:80,N:78,LEFT:37,UP:38,RIGHT:39,DOWN:40,BACKSPACE:8,SPACE:32},i={beforeSave:function(t){return e.arrayToDefaultHash(t)},matcher:function(t,e,i,s){var r;return t=t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i&&(t="(?:^|\\s)"+t),i=decodeURI("%C3%80"),r=decodeURI("%C3%BF"),(i=new RegExp(t+`([A-Za-z${i}-${r}0-9_${s?" ":""}'.+-]*)$|${t}([^\\x00-\\xff]*)$`,"gi").exec(e))?i[2]||i[1]:null},filter:function(t,e,i){for(var s,r=[],n=0,a=e.length;n<a;n++)s=e[n],~new String(s[i]).toLowerCase().indexOf(t.toLowerCase())&&r.push(s);return r},remoteFilter:null,sorter:function(t,e,i){var s,r,n,a;if(!t)return e;for(s=[],r=0,a=e.length;r<a;r++)(n=e[r]).atwho_order=new String(n[i]).toLowerCase().indexOf(t.toLowerCase()),-1<n.atwho_order&&s.push(n);return s.sort(function(t,e){return t.atwho_order-e.atwho_order})},tplEval:function(t,s){var e=t;try{return(e="string"!=typeof t?t(s):e).replace(/\$\{([^\}]*)\}/g,function(t,e,i){return s[e]})}catch(t){return""}},highlighter:function(t,e){return e?(e=new RegExp(">\\s*([^<]*?)("+e.replace("+","\\+")+")([^<]*)\\s*<","ig"),t.replace(e,function(t,e,i,s){return"> "+e+"<strong>"+i+"</strong>"+s+" <"})):t},beforeInsert:function(t,e,i){return t},beforeReposition:function(t){return t},afterMatchFailed:function(t,e){}},n=class{constructor(t){this.currentFlag=null,this.controllers={},this.aliasMaps={},this.$inputor=o(t),this.setupRootElement(),this.listen()}createContainer(t){var e;return null!=(e=this.$el)&&e.remove(),o(t.body).append(this.$el=o("<div class='atwho-container'></div>"))}setupRootElement(e,t=!1){if(e)this.window=e.contentWindow,this.document=e.contentDocument||this.window.document,this.iframe=e;else{this.document=this.$inputor[0].ownerDocument,this.window=this.document.defaultView||this.document.parentWindow;try{this.iframe=this.window.frameElement}catch(t){if(e=t,this.iframe=null,o.fn.atwho.debug)throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n"+e)}}return this.createContainer((this.iframeAsRoot=t)?this.document:document)}controller(t){var e,i,s,r;if(this.aliasMaps[t])i=this.controllers[this.aliasMaps[t]];else for(s in r=this.controllers)if(e=r[s],s===t){i=e;break}return i||this.controllers[this.currentFlag]}setContextFor(t){return this.currentFlag=t,this}reg(t,e){var i=(i=this.controllers)[t]||(i[t]=new(this.$inputor.is("[contentEditable]")?r:s)(this,t));return e.alias&&(this.aliasMaps[e.alias]=t),i.init(e),this}listen(){return this.$inputor.on("compositionstart",t=>{var e;return null!=(e=this.controller())&&e.view.hide(),this.isComposing=!0,null}).on("compositionend",t=>(this.isComposing=!1,setTimeout(t=>this.dispatch(t)),null)).on("keyup.atwhoInner",t=>this.onKeyup(t)).on("keydown.atwhoInner",t=>this.onKeydown(t)).on("blur.atwhoInner",t=>{var e;if(e=this.controller())return e.expectedQueryCBId=null,e.view.hide(t,e.getOpt("displayTimeout"))}).on("click.atwhoInner",t=>this.dispatch(t)).on("scroll.atwhoInner",(s=this.$inputor.scrollTop(),t=>{var e,i=t.target.scrollTop;return s!==i&&null!=(e=this.controller())&&e.view.hide(t),s=i,!0}));var s}shutdown(){var t,e=this.controllers;for(t in e)e[t].destroy(),delete this.controllers[t];return this.$inputor.off(".atwhoInner"),this.$el.remove()}dispatch(t){var e,i,s,r;if(void 0!==t){for(e in r=[],s=this.controllers)i=s[e],r.push(i.lookUp(t));return r}}onKeyup(t){var e;switch(t.keyCode){case a.ESC:t.preventDefault(),null!=(e=this.controller())&&e.view.hide();break;case a.DOWN:case a.UP:case a.CTRL:case a.ENTER:o.noop();break;case a.P:case a.N:t.ctrlKey||this.dispatch(t);break;default:this.dispatch(t)}}onKeydown(t){var e,i=null!=(e=this.controller())?e.view:void 0;if(i&&i.visible())switch(t.keyCode){case a.ESC:t.preventDefault(),i.hide(t);break;case a.UP:t.preventDefault(),i.prev();break;case a.DOWN:t.preventDefault(),i.next();break;case a.P:t.ctrlKey&&(t.preventDefault(),i.prev());break;case a.N:t.ctrlKey&&(t.preventDefault(),i.next());break;case a.TAB:case a.ENTER:case a.SPACE:!i.visible()||!this.controller().getOpt("spaceSelectsMatch")&&t.keyCode===a.SPACE||!this.controller().getOpt("tabSelectsMatch")&&t.keyCode===a.TAB||(i.highlighted()?(t.preventDefault(),i.choose(t)):i.hide(t));break;default:o.noop()}}},e=class{uid(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date).getTime()}constructor(t,e){this.app=t,this.at=e,this.$inputor=this.app.$inputor,this.id=this.$inputor[0].id||this.uid(),this.expectedQueryCBId=null,this.setting=null,this.query=null,this.pos=0,this.range=null,0===(this.$el=o("#atwho-ground-"+this.id,this.app.$el)).length&&this.app.$el.append(this.$el=o(`<div id='atwho-ground-${this.id}'></div>`)),this.model=new h(this),this.view=new l(this)}init(t){return this.setting=o.extend({},this.setting||o.fn.atwho.default,t),this.view.init(),this.model.reload(this.setting.data)}destroy(){return this.trigger("beforeDestroy"),this.model.destroy(),this.view.destroy(),this.$el.remove()}callDefault(e,...t){try{return i[e].apply(this,t)}catch(t){return o.error(t+" Or maybe At.js doesn't have function "+e)}}trigger(t,e=[]){var i;return e.push(this),i=this.getOpt("alias"),this.$inputor.trigger(i?t+`-${i}.atwho`:t+".atwho",e)}callbacks(t){return this.getOpt("callbacks")[t]||i[t]}getOpt(t,e){try{return this.setting[t]}catch(t){return null}}insertContentFor(t){var e=this.getOpt("insertTpl"),t=o.extend({},t.data("item-data"),{"atwho-at":this.at});return this.callbacks("tplEval").call(this,e,t,"onInsert")}renderView(t){var e=this.getOpt("searchKey");return t=this.callbacks("sorter").call(this,this.query.text,t,e),this.view.render(t.slice(0,this.getOpt("limit")))}static arrayToDefaultHash(t){var e,i,s,r;if(!o.isArray(t))return t;for(r=[],e=0,s=t.length;e<s;e++)i=t[e],o.isPlainObject(i)?r.push(i):r.push({name:i});return r}lookUp(t){var e;if((!t||"click"!==t.type||this.getOpt("lookUpOnClick"))&&(!this.getOpt("suspendOnComposing")||!this.app.isComposing))return(t=this.catchQuery(t))?(this.app.setContextFor(this.at),(e=this.getOpt("delay"))?this._delayLookUp(t,e):this._lookUp(t)):this.expectedQueryCBId=null,t}_delayLookUp(t,e){var i,s=Date.now?Date.now():(new Date).getTime();return this.previousCallTime||(this.previousCallTime=s),0<(i=e-(s-this.previousCallTime))&&i<e?(this.previousCallTime=s,this._stopDelayedCall(),this.delayedCallTimeout=setTimeout(()=>(this.previousCallTime=0,this.delayedCallTimeout=null,this._lookUp(t)),e)):(this._stopDelayedCall(),this.previousCallTime!==s&&(this.previousCallTime=0),this._lookUp(t))}_stopDelayedCall(){if(this.delayedCallTimeout)return clearTimeout(this.delayedCallTimeout),this.delayedCallTimeout=null}_generateQueryCBId(){return{}}_lookUp(t){var e=function(t,e){if(t===this.expectedQueryCBId)return e&&0<e.length?this.renderView(this.constructor.arrayToDefaultHash(e)):this.view.hide()};return this.expectedQueryCBId=this._generateQueryCBId(),this.model.query(t.text,o.proxy(e,this,this.expectedQueryCBId))}},s=class extends e{catchQuery(){var t=this.$inputor.val(),e=this.$inputor.caret("pos",{iframe:this.app.iframe}),t=t.slice(0,e),t=this.callbacks("matcher").call(this,this.at,t,this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),i="string"==typeof t;if(!(i&&t.length<this.getOpt("minLen",0)))return i&&t.length<=this.getOpt("maxLen",20)?(e=(i=e-t.length)+t.length,this.pos=i,this.trigger("matched",[this.at,(t={text:t,headPos:i,endPos:e}).text])):(t=null,this.view.hide()),this.query=t}rect(){var t,e;if(t=this.$inputor.caret("offset",this.pos-1,{iframe:this.app.iframe}))return this.app.iframe&&!this.app.iframeAsRoot&&(e=o(this.app.iframe).offset(),t.left+=e.left,t.top+=e.top),e=this.app.document.selection?0:2,{left:t.left,top:t.top,bottom:t.top+t.height+e}}insert(t,e){var i=this.$inputor,s=i.val(),r=s.slice(0,Math.max(this.query.headPos-this.at.length,0)),n=""===(n=this.getOpt("suffix"))?n:n||" ",n=""+r+(t+=n)+s.slice(this.query.endPos||0);return i.val(n),i.caret("pos",r.length+t.length,{iframe:this.app.iframe}),i.is(":focus")||i.focus(),i.change()}},r=class extends e{_getRange(){var t=this.app.window.getSelection();if(0<t.rangeCount)return t.getRangeAt(0)}_setRange(t,e,i=this._getRange()){if(i&&e)return e=o(e)[0],"after"===t?(i.setEndAfter(e),i.setStartAfter(e)):(i.setEndBefore(e),i.setStartBefore(e)),i.collapse(!1),this._clearRange(i)}_clearRange(t=this._getRange()){var e=this.app.window.getSelection();if(null==this.ctrl_a_pressed)return e.removeAllRanges(),e.addRange(t)}_movingEvent(t){return"click"===t.type||(t=t.which)===a.RIGHT||t===a.LEFT||t===a.UP||t===a.DOWN}_unwrap(t){var e;return(e=(t=o(t).unwrap().get(0)).nextSibling)&&e.nodeValue&&(t.nodeValue+=e.nodeValue,o(e).remove()),t}catchQuery(t){var e,i,s,r,n;if((n=this._getRange())&&n.collapsed)if(t.which===a.ENTER)(e=o(n.startContainer).closest(".atwho-query")).contents().unwrap(),e.is(":empty")&&e.remove(),(e=o(".atwho-query",this.app.document)).text(e.text()).contents().last().unwrap(),this._clearRange();else{if(/firefox/i.test(navigator.userAgent)){if(o(n.startContainer).is(this.$inputor))return void this._clearRange();t.which===a.BACKSPACE&&n.startContainer.nodeType===document.ELEMENT_NODE&&0<=(r=n.startOffset-1)?((i=n.cloneRange()).setStart(n.startContainer,r),o(i.cloneContents()).contents().last().is(".atwho-inserted")&&(r=o(n.startContainer).contents().get(r),this._setRange("after",o(r).contents().last()))):t.which===a.LEFT&&n.startContainer.nodeType===document.TEXT_NODE&&(r=o(n.startContainer.previousSibling)).is(".atwho-inserted")&&0===n.startOffset&&this._setRange("after",r.contents().last())}if(o(n.startContainer).closest(".atwho-inserted").addClass("atwho-query").siblings().removeClass("atwho-query"),0<(e=o(".atwho-query",this.app.document)).length&&e.is(":empty")&&0===e.text().length&&e.remove(),this._movingEvent(t)||e.removeClass("atwho-inserted"),0<e.length)switch(t.which){case a.LEFT:return this._setRange("before",e.get(0),n),void e.removeClass("atwho-query");case a.RIGHT:return this._setRange("after",e.get(0).nextSibling,n),void e.removeClass("atwho-query")}if(0<e.length&&(r=e.attr("data-atwho-at-query"))&&(e.empty().html(r).attr("data-atwho-at-query",null),this._setRange("after",e.get(0),n)),(i=n.cloneRange()).setStart(n.startContainer,0),i="string"==typeof(r=this.callbacks("matcher").call(this,this.at,i.toString(),this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar"))),0===e.length&&i&&0<=(s=n.startOffset-this.at.length-r.length)&&(n.setStart(n.startContainer,s),e=o("<span/>",this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass("atwho-query"),n.surroundContents(e.get(0)),s=e.contents().last().get(0))&&(/firefox/i.test(navigator.userAgent)?(n.setStart(s,s.length),n.setEnd(s,s.length),this._clearRange(n)):this._setRange("after",s,n)),!(i&&r.length<this.getOpt("minLen",0)))return i&&r.length<=this.getOpt("maxLen",20)?(this.trigger("matched",[this.at,(s={text:r,el:e}).text]),this.query=s):(this.view.hide(),this.query={el:e},0<=e.text().indexOf(this.at)&&(this._movingEvent(t)&&e.hasClass("atwho-inserted")?e.removeClass("atwho-query"):!1!==this.callbacks("afterMatchFailed").call(this,this.at,e)&&this._setRange("after",this._unwrap(e.text(e.text()).contents().first()))),null)}}rect(){var t,e=this.query.el.offset();if(e&&this.query.el[0].getClientRects().length)return this.app.iframe&&!this.app.iframeAsRoot&&(t=o(this.app.iframe).offset(),e.left+=t.left-this.$inputor.scrollLeft(),e.top+=t.top-this.$inputor.scrollTop()),e.bottom=e.top+this.query.el.height(),e}insert(t,e){var i;return this.$inputor.is(":focus")||this.$inputor.focus(),(i=this.getOpt("functionOverrides")).insert?i.insert.call(this,t,e):(i=""===(i=this.getOpt("suffix"))?i:i||" ",e=e.data("item-data"),this.query.el.removeClass("atwho-query").addClass("atwho-inserted").html(t).attr("data-atwho-at-query",""+e["atwho-at"]+this.query.text).attr("contenteditable","false"),(t=this._getRange())&&(this.query.el.length&&t.setEndAfter(this.query.el[0]),t.collapse(!1),t.insertNode(e=this.app.document.createTextNode(""+i)),this._setRange("after",e,t)),this.$inputor.is(":focus")||this.$inputor.focus(),this.$inputor.change())}},h=class{constructor(t){this.context=t,this.at=this.context.at,this.storage=this.context.$inputor}destroy(){return this.storage.data(this.at,null)}saved(){return 0<this.fetch()}query(t,e){var i=this.fetch(),s=this.context.getOpt("searchKey");return i=this.context.callbacks("filter").call(this.context,t,i,s)||[],s=this.context.callbacks("remoteFilter"),0<i.length||!s&&0===i.length?e(i):s.call(this.context,t,e)}fetch(){return this.storage.data(this.at)||[]}save(t){return this.storage.data(this.at,this.context.callbacks("beforeSave").call(this.context,t||[]))}load(t){if(!this.saved()&&t)return this._load(t)}reload(t){return this._load(t)}_load(t){if("string"==typeof t)throw new Error("@gitlab/at.js removed support for $.ajax");return this.save(t)}},l=class{constructor(t){this.context=t,this.$el=o("<div class='atwho-view'><ul class='atwho-view-ul'></ul></div>"),this.$elUl=this.$el.children(),this.timeoutID=null,this.context.$el.append(this.$el),this.bindEvent()}init(){var t=this.context.getOpt("alias")||this.context.at.charCodeAt(0),e=this.context.getOpt("headerTpl");return e&&1===this.$el.children().length&&this.$el.prepend(e),this.$el.attr({id:"at-view-"+t})}destroy(){return this.$el.remove()}bindEvent(){var e=this.$el.find("ul"),i=0,s=0;return e.on("mousemove.atwho-view","li",t=>{if((i!==t.clientX||s!==t.clientY)&&(i=t.clientX,s=t.clientY,!(t=o(t.currentTarget)).hasClass("cur")))return e.find(".cur").removeClass("cur"),t.addClass("cur")}).on("click.atwho-view","li",t=>(e.find(".cur").removeClass("cur"),o(t.currentTarget).addClass("cur"),this.choose(t),t.preventDefault()))}visible(){return o.expr.filters.visible(this.$el[0])}highlighted(){return 0<this.$el.find(".cur").length}choose(t){var e,i;if((e=this.$el.find(".cur")).length&&(i=this.context.insertContentFor(e),this.context._stopDelayedCall(),this.context.insert(this.context.callbacks("beforeInsert").call(this.context,i,e,t),e),this.context.trigger("inserted",[e,t]),this.hide(t)),this.context.getOpt("hideWithoutSuffix"))return this.stopShowing=!0}reposition(t){var e=this.context.app.iframeAsRoot?this.context.app.window:window;return t.bottom+this.$el.height()-o(e).scrollTop()>o(e).height()&&(t.bottom=t.top-this.$el.height()),t.left>(e=o(e).width()-this.$el.width()-5)&&(t.left=e),e={left:t.left,top:t.bottom},null!=(t=this.context.callbacks("beforeReposition"))&&t.call(this.context,e),this.$el.offset(e),this.context.trigger("reposition",[e])}next(){var t=this.$el.find(".cur").removeClass("cur").next();return(t=t.length?t:this.$el.find("li:first")).addClass("cur"),t=(t=t[0]).offsetTop+t.offsetHeight+(t.nextSibling?t.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,t-this.$el.height()))}prev(){var t=this.$el.find(".cur").removeClass("cur").prev();return(t=t.length?t:this.$el.find("li:last")).addClass("cur"),t=(t=t[0]).offsetTop+t.offsetHeight+(t.nextSibling?t.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,t-this.$el.height()))}scrollTop(t){return this.$elUl.scrollTop(t)}show(){var t;if(!this.stopShowing)return this.visible()||(this.$el.show(),this.$el.scrollTop(0),this.context.trigger("shown")),(t=this.context.rect())?this.reposition(t):void 0;this.stopShowing=!1}hide(t,e){if(this.visible())return isNaN(e)?(this.$el.hide(),this.context.trigger("hidden",[t])):(t=()=>this.hide(),clearTimeout(this.timeoutID),this.timeoutID=setTimeout(t,e))}render(t){var e,i,s,r,n,a;if(o.isArray(t)&&0<t.length){for(this.$el.find("ul").empty(),e=this.$el.find("ul"),a=this.context.getOpt("displayTpl"),i=0,r=t.length;i<r;i++)s=t[i],s=o.extend({},s,{"atwho-at":this.context.at}),n=this.context.callbacks("tplEval").call(this.context,a,s,"onDisplay"),(n=o(this.context.callbacks("highlighter").call(this.context,n,this.context.query.text))).data("item-data",s),e.append(n);return this.show(),this.context.getOpt("highlightFirst")?e.find("li:first").addClass("cur"):void 0}this.hide()}},c={load:function(t,e){if(t=this.controller(t))return t.model.load(e)},isSelecting:function(){var t;return!(null==(t=this.controller())||!t.view.visible())},hide:function(){var t;return null!=(t=this.controller())?t.view.hide():void 0},reposition:function(){var t;if(t=this.controller())return t.view.reposition(t.rect())},setIframe:function(t,e){return this.setupRootElement(t,e),null},run:function(){return this.dispatch()},destroy:function(){return this.shutdown(),this.$inputor.data("atwho",null)}};o.fn.atwho=function(i){var s=arguments,r=null;return this.filter('textarea, input, [contenteditable=""], [contenteditable=true]').each(function(){var t,e;return(e=(t=o(this)).data("atwho"))||t.data("atwho",e=new n(this)),"object"!=typeof i&&i?c[i]&&e?r=c[i].apply(e,Array.prototype.slice.call(s,1)):o.error(`Method ${i} does not exist on jQuery.atwho`):e.reg(i.at,i)}),null!=r?r:this},o.fn.atwho.default={at:void 0,alias:void 0,data:null,displayTpl:"<li>${name}</li>",insertTpl:"${atwho-at}${name}",headerTpl:null,callbacks:i,functionOverrides:{},searchKey:"name",suffix:void 0,hideWithoutSuffix:!1,startWithSpace:!0,acceptSpaceBar:!1,highlightFirst:!0,limit:5,maxLen:20,minLen:0,displayTimeout:300,delay:null,spaceSelectsMatch:!1,tabSelectsMatch:!0,editableAtwhoQueryAttrs:{},scrollDuration:150,suspendOnComposing:!0,lookUpOnClick:!0},o.fn.atwho.debug=!1});
1
+ (t=>{"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)})(function(o){var a={ESC:27,TAB:9,ENTER:13,CTRL:17,A:65,P:80,N:78,LEFT:37,UP:38,RIGHT:39,DOWN:40,BACKSPACE:8,SPACE:32},i={beforeSave:function(t){return e.arrayToDefaultHash(t)},matcher:function(t,e,i,s){var r;return t=t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i&&(t="(?:^|\\s)"+t),i=decodeURI("%C3%80"),r=decodeURI("%C3%BF"),(i=new RegExp(t+`([A-Za-z${i}-${r}0-9_${s?" ":""}'.+-]*)$|${t}([^\\x00-\\xff]*)$`,"gi").exec(e))?i[2]||i[1]:null},filter:function(t,e,i){for(var s,r=[],n=0,a=e.length;n<a;n++)s=e[n],~new String(s[i]).toLowerCase().indexOf(t.toLowerCase())&&r.push(s);return r},remoteFilter:null,sorter:function(t,e,i){var s,r,n,a;if(!t)return e;for(s=[],r=0,a=e.length;r<a;r++)(n=e[r]).atwho_order=new String(n[i]).toLowerCase().indexOf(t.toLowerCase()),-1<n.atwho_order&&s.push(n);return s.sort(function(t,e){return t.atwho_order-e.atwho_order})},tplEval:function(t,s){var e=t;try{return(e="string"!=typeof t?t(s):e).replace(/\$\{([^\}]*)\}/g,function(t,e,i){return s[e]})}catch(t){return""}},highlighter:function(t,e){return e?(e=new RegExp(">\\s*([^<]*?)("+e.replace("+","\\+")+")([^<]*)\\s*<","ig"),t.replace(e,function(t,e,i,s){return"> "+e+"<strong>"+i+"</strong>"+s+" <"})):t},beforeInsert:function(t,e,i){return t},beforeReposition:function(t){return t},afterMatchFailed:function(t,e){}},n=class{constructor(t){this.currentFlag=null,this.controllers={},this.aliasMaps={},this.$inputor=o(t),this.setupRootElement(),this.listen()}createContainer(t){var e;return null!=(e=this.$el)&&e.remove(),o(t.body).append(this.$el=o("<div class='atwho-container'></div>"))}setupRootElement(e,t=!1){if(e)this.window=e.contentWindow,this.document=e.contentDocument||this.window.document,this.iframe=e;else{this.document=this.$inputor[0].ownerDocument,this.window=this.document.defaultView||this.document.parentWindow;try{this.iframe=this.window.frameElement}catch(t){if(e=t,this.iframe=null,o.fn.atwho.debug)throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n"+e)}}return this.createContainer((this.iframeAsRoot=t)?this.document:document)}controller(t){var e,i,s,r;if(this.aliasMaps[t])i=this.controllers[this.aliasMaps[t]];else for(s in r=this.controllers)if(e=r[s],s===t){i=e;break}return i||this.controllers[this.currentFlag]}setContextFor(t){return this.currentFlag=t,this}reg(t,e){var i=(i=this.controllers)[t]||(i[t]=new(this.$inputor.is("[contentEditable]")?r:s)(this,t));return e.alias&&(this.aliasMaps[e.alias]=t),i.init(e),this}listen(){return this.$inputor.on("compositionstart",t=>{var e;return null!=(e=this.controller())&&e.view.hide(),this.isComposing=!0,null}).on("compositionend",t=>(this.isComposing=!1,setTimeout(t=>this.dispatch(t)),null)).on("keyup.atwhoInner",t=>this.onKeyup(t)).on("keydown.atwhoInner",t=>this.onKeydown(t)).on("blur.atwhoInner",t=>{var e;if(e=this.controller())return e.expectedQueryCBId=null,e.view.hide(t,e.getOpt("displayTimeout"))}).on("click.atwhoInner",t=>this.dispatch(t)).on("scroll.atwhoInner",(s=this.$inputor.scrollTop(),t=>{var e,i=t.target.scrollTop;return s!==i&&null!=(e=this.controller())&&e.view.hide(t),s=i,!0}));var s}shutdown(){var t,e=this.controllers;for(t in e)e[t].destroy(),delete this.controllers[t];return this.$inputor.off(".atwhoInner"),this.$el.remove()}dispatch(t){var e,i,s,r;if(void 0!==t){for(e in r=[],s=this.controllers)i=s[e],r.push(i.lookUp(t));return r}}onKeyup(t){var e;switch(t.keyCode){case a.ESC:t.preventDefault(),null!=(e=this.controller())&&e.view.hide();break;case a.DOWN:case a.UP:case a.CTRL:case a.ENTER:o.noop();break;case a.P:case a.N:t.ctrlKey||this.dispatch(t);break;default:this.dispatch(t)}}onKeydown(t){var e,i=null!=(e=this.controller())?e.view:void 0;if(i&&i.visible())switch(t.keyCode){case a.ESC:t.preventDefault(),i.hide(t);break;case a.UP:t.preventDefault(),i.prev();break;case a.DOWN:t.preventDefault(),i.next();break;case a.P:t.ctrlKey&&(t.preventDefault(),i.prev());break;case a.N:t.ctrlKey&&(t.preventDefault(),i.next());break;case a.TAB:case a.ENTER:case a.SPACE:!i.visible()||!this.controller().getOpt("spaceSelectsMatch")&&t.keyCode===a.SPACE||!this.controller().getOpt("tabSelectsMatch")&&t.keyCode===a.TAB||(i.highlighted()?(t.preventDefault(),i.choose(t)):i.hide(t));break;default:o.noop()}}},e=class{uid(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date).getTime()}constructor(t,e){this.app=t,this.at=e,this.$inputor=this.app.$inputor,this.id=this.$inputor[0].id||this.uid(),this.expectedQueryCBId=null,this.setting=null,this.query=null,this.pos=0,this.range=null,0===(this.$el=o("#atwho-ground-"+this.id,this.app.$el)).length&&(this.$el=o("<div></div>"),this.$el.attr("id","atwho-ground-"+this.id),this.app.$el.append(this.$el)),this.model=new h(this),this.view=new l(this)}init(t){return this.setting=o.extend({},this.setting||o.fn.atwho.default,t),this.view.init(),this.model.reload(this.setting.data)}destroy(){return this.trigger("beforeDestroy"),this.model.destroy(),this.view.destroy(),this.$el.remove()}callDefault(e,...t){try{return i[e].apply(this,t)}catch(t){return o.error(t+" Or maybe At.js doesn't have function "+e)}}trigger(t,e=[]){var i;return e.push(this),i=this.getOpt("alias"),this.$inputor.trigger(i?t+`-${i}.atwho`:t+".atwho",e)}callbacks(t){return this.getOpt("callbacks")[t]||i[t]}getOpt(t,e){try{return this.setting[t]}catch(t){return null}}insertContentFor(t){var e=this.getOpt("insertTpl"),t=o.extend({},t.data("item-data"),{"atwho-at":this.at});return this.callbacks("tplEval").call(this,e,t,"onInsert")}renderView(t){var e=this.getOpt("searchKey");return t=this.callbacks("sorter").call(this,this.query.text,t,e),this.view.render(t.slice(0,this.getOpt("limit")))}static arrayToDefaultHash(t){var e,i,s,r;if(!o.isArray(t))return t;for(r=[],e=0,s=t.length;e<s;e++)i=t[e],o.isPlainObject(i)?r.push(i):r.push({name:i});return r}lookUp(t){var e;if((!t||"click"!==t.type||this.getOpt("lookUpOnClick"))&&(!this.getOpt("suspendOnComposing")||!this.app.isComposing))return(t=this.catchQuery(t))?(this.app.setContextFor(this.at),(e=this.getOpt("delay"))?this._delayLookUp(t,e):this._lookUp(t)):(this._stopDelayedCall(),this.expectedQueryCBId=null),t}_delayLookUp(t,e){var i,s=Date.now?Date.now():(new Date).getTime();return this.previousCallTime||(this.previousCallTime=s),0<(i=e-(s-this.previousCallTime))&&i<e?(this.previousCallTime=s,this._stopDelayedCall(),this.delayedCallTimeout=setTimeout(()=>(this.previousCallTime=0,this.delayedCallTimeout=null,this._lookUp(t)),e)):(this._stopDelayedCall(),this.previousCallTime!==s&&(this.previousCallTime=0),this._lookUp(t))}_stopDelayedCall(){if(this.delayedCallTimeout)return clearTimeout(this.delayedCallTimeout),this.delayedCallTimeout=null}_generateQueryCBId(){return{}}_lookUp(t){var e=function(t,e){if(t===this.expectedQueryCBId)return e&&0<e.length?this.renderView(this.constructor.arrayToDefaultHash(e)):this.view.hide()};return this.expectedQueryCBId=this._generateQueryCBId(),this.model.query(t.text,o.proxy(e,this,this.expectedQueryCBId))}},s=class extends e{catchQuery(){var t=this.$inputor.val(),e=this.$inputor.caret("pos",{iframe:this.app.iframe}),t=t.slice(0,e),t=this.callbacks("matcher").call(this,this.at,t,this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),i="string"==typeof t;if(!(i&&t.length<this.getOpt("minLen",0)))return i&&t.length<=this.getOpt("maxLen",20)?(e=(i=e-t.length)+t.length,this.pos=i,this.trigger("matched",[this.at,(t={text:t,headPos:i,endPos:e}).text])):(t=null,this.view.hide()),this.query=t}rect(){var t,e;if(t=this.$inputor.caret("offset",this.pos-1,{iframe:this.app.iframe}))return this.app.iframe&&!this.app.iframeAsRoot&&(e=o(this.app.iframe).offset(),t.left+=e.left,t.top+=e.top),e=this.app.document.selection?0:2,{left:t.left,top:t.top,bottom:t.top+t.height+e}}insert(t,e){var i=this.$inputor,s=i.val(),r=s.slice(0,Math.max(this.query.headPos-this.at.length,0)),n=""===(n=this.getOpt("suffix"))?n:n||" ",n=""+r+(t+=n)+s.slice(this.query.endPos||0);return i.val(n),i.caret("pos",r.length+t.length,{iframe:this.app.iframe}),i.is(":focus")||i.focus(),i.change()}},r=class extends e{_getRange(){var t=this.app.window.getSelection();if(0<t.rangeCount)return t.getRangeAt(0)}_setRange(t,e,i=this._getRange()){if(i&&e)return e=o(e)[0],"after"===t?(i.setEndAfter(e),i.setStartAfter(e)):(i.setEndBefore(e),i.setStartBefore(e)),i.collapse(!1),this._clearRange(i)}_clearRange(t=this._getRange()){var e=this.app.window.getSelection();if(null==this.ctrl_a_pressed)return e.removeAllRanges(),e.addRange(t)}_movingEvent(t){return"click"===t.type||(t=t.which)===a.RIGHT||t===a.LEFT||t===a.UP||t===a.DOWN}_unwrap(t){var e;return(e=(t=o(t).unwrap().get(0)).nextSibling)&&e.nodeValue&&(t.nodeValue+=e.nodeValue,o(e).remove()),t}catchQuery(t){var e,i,s,r,n;if((n=this._getRange())&&n.collapsed)if(t.which===a.ENTER)(e=o(n.startContainer).closest(".atwho-query")).contents().unwrap(),e.is(":empty")&&e.remove(),(e=o(".atwho-query",this.app.document)).text(e.text()).contents().last().unwrap(),this._clearRange();else{if(/firefox/i.test(navigator.userAgent)){if(o(n.startContainer).is(this.$inputor))return void this._clearRange();t.which===a.BACKSPACE&&n.startContainer.nodeType===document.ELEMENT_NODE&&0<=(r=n.startOffset-1)?((i=n.cloneRange()).setStart(n.startContainer,r),o(i.cloneContents()).contents().last().is(".atwho-inserted")&&(r=o(n.startContainer).contents().get(r),this._setRange("after",o(r).contents().last()))):t.which===a.LEFT&&n.startContainer.nodeType===document.TEXT_NODE&&(r=o(n.startContainer.previousSibling)).is(".atwho-inserted")&&0===n.startOffset&&this._setRange("after",r.contents().last())}if(o(n.startContainer).closest(".atwho-inserted").addClass("atwho-query").siblings().removeClass("atwho-query"),0<(e=o(".atwho-query",this.app.document)).length&&e.is(":empty")&&0===e.text().length&&e.remove(),this._movingEvent(t)||e.removeClass("atwho-inserted"),0<e.length)switch(t.which){case a.LEFT:return this._setRange("before",e.get(0),n),void e.removeClass("atwho-query");case a.RIGHT:return this._setRange("after",e.get(0).nextSibling,n),void e.removeClass("atwho-query")}if(0<e.length&&(r=e.attr("data-atwho-at-query"))&&(e.empty().html(r).attr("data-atwho-at-query",null),this._setRange("after",e.get(0),n)),(i=n.cloneRange()).setStart(n.startContainer,0),i="string"==typeof(r=this.callbacks("matcher").call(this,this.at,i.toString(),this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar"))),0===e.length&&i&&0<=(s=n.startOffset-this.at.length-r.length)&&(n.setStart(n.startContainer,s),e=o("<span/>",this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass("atwho-query"),n.surroundContents(e.get(0)),s=e.contents().last().get(0))&&(/firefox/i.test(navigator.userAgent)?(n.setStart(s,s.length),n.setEnd(s,s.length),this._clearRange(n)):this._setRange("after",s,n)),!(i&&r.length<this.getOpt("minLen",0)))return i&&r.length<=this.getOpt("maxLen",20)?(this.trigger("matched",[this.at,(s={text:r,el:e}).text]),this.query=s):(this.view.hide(),this.query={el:e},0<=e.text().indexOf(this.at)&&(this._movingEvent(t)&&e.hasClass("atwho-inserted")?e.removeClass("atwho-query"):!1!==this.callbacks("afterMatchFailed").call(this,this.at,e)&&this._setRange("after",this._unwrap(e.text(e.text()).contents().first()))),null)}}rect(){var t,e=this.query.el.offset();if(e&&this.query.el[0].getClientRects().length)return this.app.iframe&&!this.app.iframeAsRoot&&(t=o(this.app.iframe).offset(),e.left+=t.left-this.$inputor.scrollLeft(),e.top+=t.top-this.$inputor.scrollTop()),e.bottom=e.top+this.query.el.height(),e}insert(t,e){var i;return this.$inputor.is(":focus")||this.$inputor.focus(),(i=this.getOpt("functionOverrides")).insert?i.insert.call(this,t,e):(i=""===(i=this.getOpt("suffix"))?i:i||" ",e=e.data("item-data"),this.query.el.removeClass("atwho-query").addClass("atwho-inserted").html(t).attr("data-atwho-at-query",""+e["atwho-at"]+this.query.text).attr("contenteditable","false"),(t=this._getRange())&&(this.query.el.length&&t.setEndAfter(this.query.el[0]),t.collapse(!1),t.insertNode(e=this.app.document.createTextNode(""+i)),this._setRange("after",e,t)),this.$inputor.is(":focus")||this.$inputor.focus(),this.$inputor.change())}},h=class{constructor(t){this.context=t,this.at=this.context.at,this.storage=this.context.$inputor}destroy(){return this.storage.data(this.at,null)}saved(){return 0<this.fetch()}query(t,e){var i=this.fetch(),s=this.context.getOpt("searchKey");return i=this.context.callbacks("filter").call(this.context,t,i,s)||[],s=this.context.callbacks("remoteFilter"),0<i.length||!s&&0===i.length?e(i):s.call(this.context,t,e)}fetch(){return this.storage.data(this.at)||[]}save(t){return this.storage.data(this.at,this.context.callbacks("beforeSave").call(this.context,t||[]))}load(t){if(!this.saved()&&t)return this._load(t)}reload(t){return this._load(t)}_load(t){if("string"==typeof t)throw new Error("@gitlab/at.js removed support for $.ajax");return this.save(t)}},l=class{constructor(t){this.context=t,this.$el=o("<div class='atwho-view'><ul class='atwho-view-ul'></ul></div>"),this.$elUl=this.$el.children(),this.timeoutID=null,this.context.$el.append(this.$el),this.bindEvent()}init(){var t=this.context.getOpt("alias")||this.context.at.charCodeAt(0),e=this.context.getOpt("headerTpl");return e&&1===this.$el.children().length&&this.$el.prepend(e),this.$el.attr({id:"at-view-"+t})}destroy(){return this.$el.remove()}bindEvent(){var e=this.$el.find("ul"),i=0,s=0;return e.on("mousemove.atwho-view","li",t=>{if((i!==t.clientX||s!==t.clientY)&&(i=t.clientX,s=t.clientY,!(t=o(t.currentTarget)).hasClass("cur")))return e.find(".cur").removeClass("cur"),t.addClass("cur")}).on("click.atwho-view","li",t=>(e.find(".cur").removeClass("cur"),o(t.currentTarget).addClass("cur"),this.choose(t),t.preventDefault()))}visible(){return o.expr.filters.visible(this.$el[0])}highlighted(){return 0<this.$el.find(".cur").length}choose(t){var e,i;if((e=this.$el.find(".cur")).length&&(i=this.context.insertContentFor(e),this.context._stopDelayedCall(),this.context.insert(this.context.callbacks("beforeInsert").call(this.context,i,e,t),e),this.context.trigger("inserted",[e,t]),this.hide(t)),this.context.getOpt("hideWithoutSuffix"))return this.stopShowing=!0}reposition(t){var e=this.context.app.iframeAsRoot?this.context.app.window:window;return t.bottom+this.$el.height()-o(e).scrollTop()>o(e).height()&&(t.bottom=t.top-this.$el.height()),t.left>(e=o(e).width()-this.$el.width()-5)&&(t.left=e),e={left:t.left,top:t.bottom},null!=(t=this.context.callbacks("beforeReposition"))&&t.call(this.context,e),this.$el.offset(e),this.context.trigger("reposition",[e])}next(){var t=this.$el.find(".cur").removeClass("cur").next();return(t=t.length?t:this.$el.find("li:first")).addClass("cur"),t=(t=t[0]).offsetTop+t.offsetHeight+(t.nextSibling?t.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,t-this.$el.height()))}prev(){var t=this.$el.find(".cur").removeClass("cur").prev();return(t=t.length?t:this.$el.find("li:last")).addClass("cur"),t=(t=t[0]).offsetTop+t.offsetHeight+(t.nextSibling?t.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,t-this.$el.height()))}scrollTop(t){return this.$elUl.scrollTop(t)}show(){var t;if(!this.stopShowing)return this.visible()||(this.$el.show(),this.$el.scrollTop(0),this.context.trigger("shown")),(t=this.context.rect())?this.reposition(t):void 0;this.stopShowing=!1}hide(t,e){if(this.visible())return isNaN(e)?(this.$el.hide(),this.context.trigger("hidden",[t])):(t=()=>this.hide(),clearTimeout(this.timeoutID),this.timeoutID=setTimeout(t,e))}render(t){var e,i,s,r,n,a;if(o.isArray(t)&&0<t.length){for(this.$el.find("ul").empty(),e=this.$el.find("ul"),a=this.context.getOpt("displayTpl"),i=0,r=t.length;i<r;i++)s=t[i],s=o.extend({},s,{"atwho-at":this.context.at}),n=this.context.callbacks("tplEval").call(this.context,a,s,"onDisplay"),(n=o(this.context.callbacks("highlighter").call(this.context,n,this.context.query.text))).data("item-data",s),e.append(n);return this.show(),this.context.getOpt("highlightFirst")?e.find("li:first").addClass("cur"):void 0}this.hide()}},c={load:function(t,e){if(t=this.controller(t))return t.model.load(e)},isSelecting:function(){var t;return!(null==(t=this.controller())||!t.view.visible())},hide:function(){var t;return null!=(t=this.controller())?t.view.hide():void 0},reposition:function(){var t;if(t=this.controller())return t.view.reposition(t.rect())},setIframe:function(t,e){return this.setupRootElement(t,e),null},run:function(){return this.dispatch()},destroy:function(){return this.shutdown(),this.$inputor.data("atwho",null)}};o.fn.atwho=function(i){var s=arguments,r=null;return this.filter('textarea, input, [contenteditable=""], [contenteditable=true]').each(function(){var t,e;return(e=(t=o(this)).data("atwho"))||t.data("atwho",e=new n(this)),"object"!=typeof i&&i?c[i]&&e?r=c[i].apply(e,Array.prototype.slice.call(s,1)):o.error(`Method ${i} does not exist on jQuery.atwho`):e.reg(i.at,i)}),null!=r?r:this},o.fn.atwho.default={at:void 0,alias:void 0,data:null,displayTpl:"<li>${name}</li>",insertTpl:"${atwho-at}${name}",headerTpl:null,callbacks:i,functionOverrides:{},searchKey:"name",suffix:void 0,hideWithoutSuffix:!1,startWithSpace:!0,acceptSpaceBar:!1,highlightFirst:!0,limit:5,maxLen:20,minLen:0,displayTimeout:300,delay:null,spaceSelectsMatch:!1,tabSelectsMatch:!0,editableAtwhoQueryAttrs:{},scrollDuration:150,suspendOnComposing:!0,lookUpOnClick:!0},o.fn.atwho.debug=!1});
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "homepage": "https://gitlab.com/gitlab-org/frontend/At.js",
9
9
  "license": "MIT",
10
- "version": "1.5.8",
10
+ "version": "1.5.11",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "https://gitlab.com/gitlab-org/frontend/At.js"
@@ -12,7 +12,9 @@ class Controller
12
12
  @pos = 0
13
13
  @range = null
14
14
  if (@$el = $("#atwho-ground-#{@id}", @app.$el)).length == 0
15
- @app.$el.append @$el = $("<div id='atwho-ground-#{@id}'></div>")
15
+ @$el = $('<div></div>')
16
+ @$el.attr('id', "atwho-ground-#{@id}")
17
+ @app.$el.append @$el
16
18
 
17
19
  @model = new Model(this)
18
20
  @view = new View(this)
@@ -95,6 +97,7 @@ class Controller
95
97
  return if @getOpt('suspendOnComposing') and @app.isComposing
96
98
  query = @catchQuery e
97
99
  if not query
100
+ @_stopDelayedCall()
98
101
  @expectedQueryCBId = null
99
102
  return query
100
103
  @app.setContextFor @at