@ckeditor/ckeditor5-mention 29.1.0 → 31.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/build/mention.js CHANGED
@@ -2,4 +2,4 @@
2
2
  * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
4
  */
5
- window.CKEditor5=window.CKEditor5||{},window.CKEditor5.mention=function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=12)}([function(e,t,n){e.exports=n(3)("./src/utils.js")},function(e,t,n){e.exports=n(3)("./src/ui.js")},function(e,t,n){e.exports=n(3)("./src/core.js")},function(e,t){e.exports=CKEditor5.dll},function(e,t,n){"use strict";var i,o=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},r=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),s=[];function a(e){for(var t=-1,n=0;n<s.length;n++)if(s[n].identifier===e){t=n;break}return t}function c(e,t){for(var n={},i=[],o=0;o<e.length;o++){var r=e[o],c=t.base?r[0]+t.base:r[0],d=n[c]||0,u="".concat(c," ").concat(d);n[c]=d+1;var l=a(u),m={css:r[1],media:r[2],sourceMap:r[3]};-1!==l?(s[l].references++,s[l].updater(m)):s.push({identifier:u,updater:p(m,t),references:1}),i.push(u)}return i}function d(e){var t=document.createElement("style"),i=e.attributes||{};if(void 0===i.nonce){var o=n.nc;o&&(i.nonce=o)}if(Object.keys(i).forEach((function(e){t.setAttribute(e,i[e])})),"function"==typeof e.insert)e.insert(t);else{var s=r(e.insert||"head");if(!s)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");s.appendChild(t)}return t}var u,l=(u=[],function(e,t){return u[e]=t,u.filter(Boolean).join("\n")});function m(e,t,n,i){var o=n?"":i.media?"@media ".concat(i.media," {").concat(i.css,"}"):i.css;if(e.styleSheet)e.styleSheet.cssText=l(t,o);else{var r=document.createTextNode(o),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(r,s[t]):e.appendChild(r)}}function f(e,t,n){var i=n.css,o=n.media,r=n.sourceMap;if(o?e.setAttribute("media",o):e.removeAttribute("media"),r&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}var h=null,g=0;function p(e,t){var n,i,o;if(t.singleton){var r=g++;n=h||(h=d(t)),i=m.bind(null,n,r,!1),o=m.bind(null,n,r,!0)}else n=d(t),i=f.bind(null,n,t),o=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return i(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;i(e=t)}else o()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=o());var n=c(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var i=0;i<n.length;i++){var o=a(n[i]);s[o].references--}for(var r=c(e,t),d=0;d<n.length;d++){var u=a(n[d]);0===s[u].references&&(s[u].updater(),s.splice(u,1))}n=r}}}},function(e,t,n){e.exports=n(3)("./src/typing.js")},function(e,t,n){"use strict";(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.a=n}).call(this,n(9))},function(e,t,n){var i=n(4),o=n(8);"string"==typeof(o=o.__esModule?o.default:o)&&(o=[[e.i,o,""]]);var r={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};i(o,r);e.exports=o.locals||{}},function(e,t){e.exports=":root{--ck-mention-list-max-height:300px}.ck.ck-mentions{max-height:var(--ck-mention-list-max-height);overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain}.ck.ck-mentions>.ck-list__item{overflow:hidden;flex-shrink:0}"},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var i=n(4),o=n(11);"string"==typeof(o=o.__esModule?o.default:o)&&(o=[[e.i,o,""]]);var r={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};i(o,r);e.exports=o.locals||{}},function(e,t){e.exports=":root{--ck-color-mention-background:rgba(153,0,48,0.1);--ck-color-mention-text:#990030}.ck-content .mention{background:var(--ck-color-mention-background);color:var(--ck-color-mention-text)}"},function(e,t,n){"use strict";n.r(t),n.d(t,"Mention",(function(){return ee})),n.d(t,"MentionEditing",(function(){return s})),n.d(t,"MentionUI",(function(){return z}));var i=n(2),o=n(0);class r extends i.Command{refresh(){const e=this.editor.model,t=e.document;this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"mention")}execute(e){const t=this.editor.model,n=t.document.selection,i="string"==typeof e.mention?{id:e.mention}:e.mention,r=i.id,s=e.range||n.getFirstRange(),c=e.text||r,d=a({_text:c,id:r},i);if(1!=e.marker.length)throw new o.CKEditorError("mentioncommand-incorrect-marker",this);if(r.charAt(0)!=e.marker)throw new o.CKEditorError("mentioncommand-incorrect-id",this);t.change(e=>{const i=Object(o.toMap)(n.getAttributes()),r=new Map(i.entries());r.set("mention",d),t.insertContent(e.createText(c,r),s),t.insertContent(e.createText(" ",i),s.start.getShiftedBy(c.length))})}}class s extends i.Plugin{static get pluginName(){return"MentionEditing"}init(){const e=this.editor,t=e.model,n=t.document;t.schema.extend("$text",{allowAttributes:"mention"}),e.conversion.for("upcast").elementToAttribute({view:{name:"span",key:"data-mention",classes:"mention"},model:{key:"mention",value:e=>c(e)}}),e.conversion.for("downcast").attributeToElement({model:"mention",view:u}),e.conversion.for("downcast").add(d),n.registerPostFixer(e=>function(e,t,n){const i=t.differ.getChanges();let o=!1;for(const t of i){const i=t.position;if("$text"==t.name){const t=i.textNode&&i.textNode.nextSibling;o=m(i.textNode,e)||o,o=m(t,e)||o,o=m(i.nodeBefore,e)||o,o=m(i.nodeAfter,e)||o}if("$text"!=t.name&&"insert"==t.type){const t=i.nodeAfter;for(const n of e.createRangeIn(t).getItems())o=m(n,e)||o}if("insert"==t.type&&n.isInline(t.name)){const t=i.nodeAfter&&i.nodeAfter.nextSibling;o=m(i.nodeBefore,e)||o,o=m(t,e)||o}}return o}(e,n,t.schema)),n.registerPostFixer(e=>function(e,t){const n=t.differ.getChanges();let i=!1;for(const t of n)if("attribute"===t.type&&"mention"!=t.attributeKey){const n=t.range.start.nodeBefore,o=t.range.end.nodeAfter;for(const r of[n,o])l(r)&&r.getAttribute(t.attributeKey)!=t.attributeNewValue&&(e.setAttribute(t.attributeKey,t.attributeNewValue,r),i=!0)}return i}(e,n)),n.registerPostFixer(e=>function(e,t){const n=t.selection,i=n.focus;if(n.isCollapsed&&n.hasAttribute("mention")&&function(e){const t=e.isAtStart;return e.nodeBefore&&e.nodeBefore.is("$text")||t}(i))return e.removeSelectionAttribute("mention"),!0}(e,n)),e.commands.add("mention",new r(e))}}function a(e,t){return Object.assign({uid:Object(o.uid)()},e,t||{})}function c(e,t){const n=e.getAttribute("data-mention"),i=e.getChild(0);if(!i)return;return a({id:n,_text:i.data},t)}function d(e){e.on("attribute:mention",(e,t,n)=>{const i=t.attributeNewValue;if(!t.item.is("$textProxy")||!i)return;const o=t.range.start;(o.textNode||o.nodeAfter).data!=i._text&&n.consumable.consume(t.item,e.name)},{priority:"highest"})}function u(e,{writer:t}){if(!e)return;const n={class:"mention","data-mention":e.id},i={id:e.uid,priority:20};return t.createAttributeElement("span",n,i)}function l(e){if(!e||!e.is("$text")&&!e.is("$textProxy")||!e.hasAttribute("mention"))return!1;return e.data!=e.getAttribute("mention")._text}function m(e,t){return!!l(e)&&(t.removeAttribute("mention",e),!0)}var f=n(1),h=n(5);var g=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},p=n(6),v="object"==typeof self&&self&&self.Object===Object&&self,b=p.a||v||Function("return this")(),w=function(){return b.Date.now()},x=/\s/;var y=function(e){for(var t=e.length;t--&&x.test(e.charAt(t)););return t},_=/^\s+/;var k=function(e){return e?e.slice(0,y(e)+1).replace(_,""):e},C=b.Symbol,A=Object.prototype,j=A.hasOwnProperty,T=A.toString,M=C?C.toStringTag:void 0;var S=function(e){var t=j.call(e,M),n=e[M];try{e[M]=void 0;var i=!0}catch(e){}var o=T.call(e);return i&&(t?e[M]=n:delete e[M]),o},E=Object.prototype.toString;var I=function(e){return E.call(e)},O=C?C.toStringTag:void 0;var V=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":O&&O in Object(e)?S(e):I(e)};var R=function(e){return null!=e&&"object"==typeof e};var P=function(e){return"symbol"==typeof e||R(e)&&"[object Symbol]"==V(e)},F=/^[-+]0x[0-9a-f]+$/i,N=/^0b[01]+$/i,U=/^0o[0-7]+$/i,B=parseInt;var $=function(e){if("number"==typeof e)return e;if(P(e))return NaN;if(g(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=g(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=k(e);var n=N.test(e);return n||U.test(e)?B(e.slice(2),n?2:8):F.test(e)?NaN:+e},q=Math.max,D=Math.min;var L=function(e,t,n){var i,o,r,s,a,c,d=0,u=!1,l=!1,m=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function f(t){var n=i,r=o;return i=o=void 0,d=t,s=e.apply(r,n)}function h(e){return d=e,a=setTimeout(v,t),u?f(e):s}function p(e){var n=e-c;return void 0===c||n>=t||n<0||l&&e-d>=r}function v(){var e=w();if(p(e))return b(e);a=setTimeout(v,function(e){var n=t-(e-c);return l?D(n,r-(e-d)):n}(e))}function b(e){return a=void 0,m&&i?f(e):(i=o=void 0,s)}function x(){var e=w(),n=p(e);if(i=arguments,o=this,c=e,n){if(void 0===a)return h(c);if(l)return clearTimeout(a),a=setTimeout(v,t),f(c)}return void 0===a&&(a=setTimeout(v,t)),s}return t=$(t)||0,g(n)&&(u=!!n.leading,r=(l="maxWait"in n)?q($(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m),x.cancel=function(){void 0!==a&&clearTimeout(a),d=0,i=c=o=a=void 0},x.flush=function(){return void 0===a?s:b(w())},x};n(7);class K extends f.ListView{constructor(e){super(e),this.extendTemplate({attributes:{class:["ck-mentions"],tabindex:"-1"}})}selectFirst(){this.select(0)}selectNext(){const e=this.selected,t=this.items.getIndex(e);this.select(t+1)}selectPrevious(){const e=this.selected,t=this.items.getIndex(e);this.select(t-1)}select(e){let t=0;e>0&&e<this.items.length?t=e:e<0&&(t=this.items.length-1);const n=this.items.get(t);this.selected!==n&&(this.selected&&this.selected.removeHighlight(),n.highlight(),this.selected=n,this._isItemVisibleInScrolledArea(n)||(this.element.scrollTop=n.element.offsetTop))}executeSelected(){this.selected.fire("execute")}_isItemVisibleInScrolledArea(e){return new o.Rect(this.element).contains(new o.Rect(e.element))}}class W extends f.View{constructor(e,t){super(e),this.template=!1,this.domElement=t,this.domElement.classList.add("ck-button"),this.set("isOn",!1),this.on("change:isOn",(e,t,n)=>{n?(this.domElement.classList.add("ck-on"),this.domElement.classList.remove("ck-off")):(this.domElement.classList.add("ck-off"),this.domElement.classList.remove("ck-on"))}),this.listenTo(this.domElement,"click",()=>{this.fire("execute")})}render(){super.render(),this.element=this.domElement}}class H extends f.ListItemView{highlight(){this.children.first.isOn=!0}removeHighlight(){this.children.first.isOn=!1}}const J=[o.keyCodes.arrowup,o.keyCodes.arrowdown,o.keyCodes.enter,o.keyCodes.tab,o.keyCodes.esc];class z extends i.Plugin{static get pluginName(){return"MentionUI"}static get requires(){return[f.ContextualBalloon]}constructor(e){super(e),this._mentionsView=this._createMentionView(),this._mentionsConfigurations=new Map,this._requestFeedDebounced=L(this._requestFeed,100),e.config.define("mention",{feeds:[]})}init(){const e=this.editor;this._balloon=e.plugins.get(f.ContextualBalloon),e.editing.view.document.on("keydown",(e,t)=>{var n;n=t.keyCode,J.includes(n)&&this._isUIVisible&&(t.preventDefault(),e.stop(),t.keyCode==o.keyCodes.arrowdown&&this._mentionsView.selectNext(),t.keyCode==o.keyCodes.arrowup&&this._mentionsView.selectPrevious(),t.keyCode!=o.keyCodes.enter&&t.keyCode!=o.keyCodes.tab||this._mentionsView.executeSelected(),t.keyCode==o.keyCodes.esc&&this._hideUIAndRemoveMarker())},{priority:"highest"}),Object(f.clickOutsideHandler)({emitter:this._mentionsView,activator:()=>this._isUIVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideUIAndRemoveMarker()});const t=e.config.get("mention.feeds");for(const e of t){const t=e.feed,n=e.marker;if(!Y(n))throw new o.CKEditorError("mentionconfig-incorrect-marker",null,{marker:n});const i=e.minimumCharacters||0,r="function"==typeof t?t.bind(this.editor):X(t),s={watcher:this._setupTextWatcherForFeed(n,i),marker:n,feedCallback:r,itemRenderer:e.itemRenderer};this._mentionsConfigurations.set(n,s)}this.on("requestFeed:response",(e,t)=>this._handleFeedResponse(t)),this.on("requestFeed:error",()=>this._hideUIAndRemoveMarker())}destroy(){super.destroy(),this._mentionsView.destroy()}get _isUIVisible(){return this._balloon.visibleView===this._mentionsView}_createMentionView(){const e=this.editor.locale,t=new K(e);return this._items=new o.Collection,t.items.bindTo(this._items).using(n=>{const{item:i,marker:o}=n,r=new H(e),s=this._renderItem(i,o);return s.delegate("execute").to(r),r.children.add(s),r.item=i,r.marker=o,r.on("execute",()=>{t.fire("execute",{item:i,marker:o})}),r}),t.on("execute",(e,t)=>{const n=this.editor,i=n.model,o=t.item,r=t.marker,s=n.model.markers.get("mention"),a=i.createPositionAt(i.document.selection.focus),c=i.createPositionAt(s.getStart()),d=i.createRange(c,a);this._hideUIAndRemoveMarker(),n.execute("mention",{mention:o,text:o.text,marker:r,range:d}),n.editing.view.focus()}),t}_getItemRenderer(e){const{itemRenderer:t}=this._mentionsConfigurations.get(e);return t}_requestFeed(e,t){this._lastRequested=t;const{feedCallback:n}=this._mentionsConfigurations.get(e),i=n(t);i instanceof Promise?i.then(n=>{this._lastRequested==t?this.fire("requestFeed:response",{feed:n,marker:e,feedText:t}):this.fire("requestFeed:discarded",{feed:n,marker:e,feedText:t})}).catch(t=>{this.fire("requestFeed:error",{error:t}),Object(o.logWarning)("mention-feed-callback-error",{marker:e})}):this.fire("requestFeed:response",{feed:i,marker:e,feedText:t})}_setupTextWatcherForFeed(e,t){const n=this.editor,i=new h.TextWatcher(n.model,function(e,t){const n=Q(e,t);return e=>n.test(e)}(e,t));i.on("matched",(t,i)=>{const o=n.model.document.selection.focus;if(function(e){const t=e.textNode&&e.textNode.hasAttribute("mention"),n=e.nodeBefore;return t||n&&n.is("$text")&&n.hasAttribute("mention")}(o))return void this._hideUIAndRemoveMarker();const r=function(e,t){const n=Q(e,0);return t.match(n)[2]}(e,i.text),s=e.length+r.length,a=o.getShiftedBy(-s),c=o.getShiftedBy(-r.length),d=n.model.createRange(a,c);if(Z(n)){const e=n.model.markers.get("mention");n.model.change(t=>{t.updateMarker(e,{range:d})})}else n.model.change(e=>{e.addMarker("mention",{range:d,usingOperation:!1,affectsData:!1})});this._requestFeedDebounced(e,r)}),i.on("unmatched",()=>{this._hideUIAndRemoveMarker()});const o=n.commands.get("mention");return i.bind("isEnabled").to(o),i}_handleFeedResponse(e){const{feed:t,marker:n}=e;if(!Z(this.editor))return;this._items.clear();for(const e of t){const t="object"!=typeof e?{id:e,text:e}:e;this._items.add({item:t,marker:n})}const i=this.editor.model.markers.get("mention");this._items.length?this._showOrUpdateUI(i):this._hideUIAndRemoveMarker()}_showOrUpdateUI(e){this._isUIVisible?this._balloon.updatePosition(this._getBalloonPanelPositionData(e,this._mentionsView.position)):this._balloon.add({view:this._mentionsView,position:this._getBalloonPanelPositionData(e,this._mentionsView.position),withArrow:!1,singleViewMode:!0}),this._mentionsView.position=this._balloon.view.position,this._mentionsView.selectFirst()}_hideUIAndRemoveMarker(){this._balloon.hasView(this._mentionsView)&&this._balloon.remove(this._mentionsView),Z(this.editor)&&this.editor.model.change(e=>e.removeMarker("mention")),this._mentionsView.position=void 0}_renderItem(e,t){const n=this.editor;let i,o=e.id;const r=this._getItemRenderer(t);if(r){const t=r(e);"string"!=typeof t?i=new W(n.locale,t):o=t}if(!i){const e=new f.ButtonView(n.locale);e.label=o,e.withText=!0,i=e}return i}_getBalloonPanelPositionData(e,t){const n=this.editor,i=n.editing,r=i.view.domConverter,s=i.mapper;return{target:()=>{let t=e.getRange();"$graveyard"==t.start.root.rootName&&(t=n.model.document.selection.getFirstRange());const i=s.toViewRange(t);return o.Rect.getDomRangeRects(r.viewRangeToDom(i)).pop()},limiter:()=>{const e=this.editor.editing.view,t=e.document.selection.editableElement;return t?e.domConverter.mapViewToDom(t.root):null},positions:G(t)}}}function G(e){const t={caret_se:e=>({top:e.bottom+3,left:e.right,name:"caret_se"}),caret_ne:(e,t)=>({top:e.top-t.height-3,left:e.right,name:"caret_ne"}),caret_sw:(e,t)=>({top:e.bottom+3,left:e.right-t.width,name:"caret_sw"}),caret_nw:(e,t)=>({top:e.top-t.height-3,left:e.right-t.width,name:"caret_nw"})};return Object.prototype.hasOwnProperty.call(t,e)?[t[e]]:[t.caret_se,t.caret_sw,t.caret_ne,t.caret_nw]}function Q(e,t){const n=0==t?"*":`{${t},}`,i=o.env.features.isRegExpUnicodePropertySupported?"\\p{Ps}\\p{Pi}\"'":"\\(\\[{\"'";return new RegExp(`(?:^|[ ${i}])([${e}])([\\S]${n})$`,"u")}function X(e){return t=>e.filter(e=>("string"==typeof e?e:String(e.id)).toLowerCase().includes(t.toLowerCase())).slice(0,10)}function Y(e){return e&&1==e.length}function Z(e){return e.model.markers.has("mention")}n(10);class ee extends i.Plugin{toMentionAttribute(e,t){return c(e,t)}static get pluginName(){return"Mention"}static get requires(){return[s,z]}}}]);
5
+ window.CKEditor5=window.CKEditor5||{},window.CKEditor5.mention=function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=12)}([function(e,t,n){e.exports=n(3)("./src/utils.js")},function(e,t,n){e.exports=n(3)("./src/ui.js")},function(e,t,n){e.exports=n(3)("./src/core.js")},function(e,t){e.exports=CKEditor5.dll},function(e,t,n){"use strict";var i,o=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},r=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),s=[];function c(e){for(var t=-1,n=0;n<s.length;n++)if(s[n].identifier===e){t=n;break}return t}function a(e,t){for(var n={},i=[],o=0;o<e.length;o++){var r=e[o],a=t.base?r[0]+t.base:r[0],d=n[a]||0,u="".concat(a," ").concat(d);n[a]=d+1;var l=c(u),m={css:r[1],media:r[2],sourceMap:r[3]};-1!==l?(s[l].references++,s[l].updater(m)):s.push({identifier:u,updater:p(m,t),references:1}),i.push(u)}return i}function d(e){var t=document.createElement("style"),i=e.attributes||{};if(void 0===i.nonce){var o=n.nc;o&&(i.nonce=o)}if(Object.keys(i).forEach((function(e){t.setAttribute(e,i[e])})),"function"==typeof e.insert)e.insert(t);else{var s=r(e.insert||"head");if(!s)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");s.appendChild(t)}return t}var u,l=(u=[],function(e,t){return u[e]=t,u.filter(Boolean).join("\n")});function m(e,t,n,i){var o=n?"":i.media?"@media ".concat(i.media," {").concat(i.css,"}"):i.css;if(e.styleSheet)e.styleSheet.cssText=l(t,o);else{var r=document.createTextNode(o),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(r,s[t]):e.appendChild(r)}}function f(e,t,n){var i=n.css,o=n.media,r=n.sourceMap;if(o?e.setAttribute("media",o):e.removeAttribute("media"),r&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}var h=null,g=0;function p(e,t){var n,i,o;if(t.singleton){var r=g++;n=h||(h=d(t)),i=m.bind(null,n,r,!1),o=m.bind(null,n,r,!0)}else n=d(t),i=f.bind(null,n,t),o=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return i(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;i(e=t)}else o()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=o());var n=a(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var i=0;i<n.length;i++){var o=c(n[i]);s[o].references--}for(var r=a(e,t),d=0;d<n.length;d++){var u=c(n[d]);0===s[u].references&&(s[u].updater(),s.splice(u,1))}n=r}}}},function(e,t,n){e.exports=n(3)("./src/typing.js")},function(e,t,n){"use strict";(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.a=n}).call(this,n(9))},function(e,t,n){var i=n(4),o=n(8);"string"==typeof(o=o.__esModule?o.default:o)&&(o=[[e.i,o,""]]);var r={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};i(o,r);e.exports=o.locals||{}},function(e,t){e.exports=":root{--ck-mention-list-max-height:300px}.ck.ck-mentions{max-height:var(--ck-mention-list-max-height);overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain}.ck.ck-mentions>.ck-list__item{overflow:hidden;flex-shrink:0}"},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var i=n(4),o=n(11);"string"==typeof(o=o.__esModule?o.default:o)&&(o=[[e.i,o,""]]);var r={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};i(o,r);e.exports=o.locals||{}},function(e,t){e.exports=":root{--ck-color-mention-background:rgba(153,0,48,0.1);--ck-color-mention-text:#990030}.ck-content .mention{background:var(--ck-color-mention-background);color:var(--ck-color-mention-text)}"},function(e,t,n){"use strict";n.r(t),n.d(t,"Mention",(function(){return te})),n.d(t,"MentionEditing",(function(){return s})),n.d(t,"MentionUI",(function(){return G}));var i=n(2),o=n(0);class r extends i.Command{refresh(){const e=this.editor.model,t=e.document;this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"mention")}execute(e){const t=this.editor.model,n=t.document.selection,i="string"==typeof e.mention?{id:e.mention}:e.mention,r=i.id,s=e.range||n.getFirstRange(),a=e.text||r,d=c({_text:a,id:r},i);if(1!=e.marker.length)throw new o.CKEditorError("mentioncommand-incorrect-marker",this);if(r.charAt(0)!=e.marker)throw new o.CKEditorError("mentioncommand-incorrect-id",this);t.change(e=>{const i=Object(o.toMap)(n.getAttributes()),r=new Map(i.entries());r.set("mention",d),t.insertContent(e.createText(a,r),s),t.insertContent(e.createText(" ",i),s.start.getShiftedBy(a.length))})}}class s extends i.Plugin{static get pluginName(){return"MentionEditing"}init(){const e=this.editor,t=e.model,n=t.document;t.schema.extend("$text",{allowAttributes:"mention"}),e.conversion.for("upcast").elementToAttribute({view:{name:"span",key:"data-mention",classes:"mention"},model:{key:"mention",value:e=>a(e)}}),e.conversion.for("downcast").attributeToElement({model:"mention",view:u}),e.conversion.for("downcast").add(d),n.registerPostFixer(e=>function(e,t,n){const i=t.differ.getChanges();let o=!1;for(const t of i){const i=t.position;if("$text"==t.name){const t=i.textNode&&i.textNode.nextSibling;o=m(i.textNode,e)||o,o=m(t,e)||o,o=m(i.nodeBefore,e)||o,o=m(i.nodeAfter,e)||o}if("$text"!=t.name&&"insert"==t.type){const t=i.nodeAfter;for(const n of e.createRangeIn(t).getItems())o=m(n,e)||o}if("insert"==t.type&&n.isInline(t.name)){const t=i.nodeAfter&&i.nodeAfter.nextSibling;o=m(i.nodeBefore,e)||o,o=m(t,e)||o}}return o}(e,n,t.schema)),n.registerPostFixer(e=>function(e,t){const n=t.differ.getChanges();let i=!1;for(const t of n)if("attribute"===t.type&&"mention"!=t.attributeKey){const n=t.range.start.nodeBefore,o=t.range.end.nodeAfter;for(const r of[n,o])l(r)&&r.getAttribute(t.attributeKey)!=t.attributeNewValue&&(e.setAttribute(t.attributeKey,t.attributeNewValue,r),i=!0)}return i}(e,n)),n.registerPostFixer(e=>function(e,t){const n=t.selection,i=n.focus;if(n.isCollapsed&&n.hasAttribute("mention")&&function(e){const t=e.isAtStart;return e.nodeBefore&&e.nodeBefore.is("$text")||t}(i))return e.removeSelectionAttribute("mention"),!0}(e,n)),e.commands.add("mention",new r(e))}}function c(e,t){return Object.assign({uid:Object(o.uid)()},e,t||{})}function a(e,t){const n=e.getAttribute("data-mention"),i=e.getChild(0);if(!i)return;return c({id:n,_text:i.data},t)}function d(e){e.on("attribute:mention",(e,t,n)=>{const i=t.attributeNewValue;if(!t.item.is("$textProxy")||!i)return;const o=t.range.start;(o.textNode||o.nodeAfter).data!=i._text&&n.consumable.consume(t.item,e.name)},{priority:"highest"})}function u(e,{writer:t}){if(!e)return;const n={class:"mention","data-mention":e.id},i={id:e.uid,priority:20};return t.createAttributeElement("span",n,i)}function l(e){if(!e||!e.is("$text")&&!e.is("$textProxy")||!e.hasAttribute("mention"))return!1;return e.data!=e.getAttribute("mention")._text}function m(e,t){return!!l(e)&&(t.removeAttribute("mention",e),!0)}var f=n(1),h=n(5);var g=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},p=n(6),v="object"==typeof self&&self&&self.Object===Object&&self,b=p.a||v||Function("return this")(),w=function(){return b.Date.now()},x=/\s/;var y=function(e){for(var t=e.length;t--&&x.test(e.charAt(t)););return t},_=/^\s+/;var k=function(e){return e?e.slice(0,y(e)+1).replace(_,""):e},C=b.Symbol,A=Object.prototype,T=A.hasOwnProperty,j=A.toString,M=C?C.toStringTag:void 0;var I=function(e){var t=T.call(e,M),n=e[M];try{e[M]=void 0;var i=!0}catch(e){}var o=j.call(e);return i&&(t?e[M]=n:delete e[M]),o},O=Object.prototype.toString;var R=function(e){return O.call(e)},S=C?C.toStringTag:void 0;var E=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":S&&S in Object(e)?I(e):R(e)};var V=function(e){return null!=e&&"object"==typeof e};var P=function(e){return"symbol"==typeof e||V(e)&&"[object Symbol]"==E(e)},F=/^[-+]0x[0-9a-f]+$/i,N=/^0b[01]+$/i,U=/^0o[0-7]+$/i,B=parseInt;var $=function(e){if("number"==typeof e)return e;if(P(e))return NaN;if(g(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=g(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=k(e);var n=N.test(e);return n||U.test(e)?B(e.slice(2),n?2:8):F.test(e)?NaN:+e},q=Math.max,L=Math.min;var D=function(e,t,n){var i,o,r,s,c,a,d=0,u=!1,l=!1,m=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function f(t){var n=i,r=o;return i=o=void 0,d=t,s=e.apply(r,n)}function h(e){return d=e,c=setTimeout(v,t),u?f(e):s}function p(e){var n=e-a;return void 0===a||n>=t||n<0||l&&e-d>=r}function v(){var e=w();if(p(e))return b(e);c=setTimeout(v,function(e){var n=t-(e-a);return l?L(n,r-(e-d)):n}(e))}function b(e){return c=void 0,m&&i?f(e):(i=o=void 0,s)}function x(){var e=w(),n=p(e);if(i=arguments,o=this,a=e,n){if(void 0===c)return h(a);if(l)return clearTimeout(c),c=setTimeout(v,t),f(a)}return void 0===c&&(c=setTimeout(v,t)),s}return t=$(t)||0,g(n)&&(u=!!n.leading,r=(l="maxWait"in n)?q($(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m),x.cancel=function(){void 0!==c&&clearTimeout(c),d=0,i=a=o=c=void 0},x.flush=function(){return void 0===c?s:b(w())},x};n(7);class K extends f.ListView{constructor(e){super(e),this.extendTemplate({attributes:{class:["ck-mentions"],tabindex:"-1"}})}selectFirst(){this.select(0)}selectNext(){const e=this.selected,t=this.items.getIndex(e);this.select(t+1)}selectPrevious(){const e=this.selected,t=this.items.getIndex(e);this.select(t-1)}select(e){let t=0;e>0&&e<this.items.length?t=e:e<0&&(t=this.items.length-1);const n=this.items.get(t);this.selected!==n&&(this.selected&&this.selected.removeHighlight(),n.highlight(),this.selected=n,this._isItemVisibleInScrolledArea(n)||(this.element.scrollTop=n.element.offsetTop))}executeSelected(){this.selected.fire("execute")}_isItemVisibleInScrolledArea(e){return new o.Rect(this.element).contains(new o.Rect(e.element))}}class W extends f.View{constructor(e,t){super(e),this.template=!1,this.domElement=t,this.domElement.classList.add("ck-button"),this.set("isOn",!1),this.on("change:isOn",(e,t,n)=>{n?(this.domElement.classList.add("ck-on"),this.domElement.classList.remove("ck-off")):(this.domElement.classList.add("ck-off"),this.domElement.classList.remove("ck-on"))}),this.listenTo(this.domElement,"click",()=>{this.fire("execute")})}render(){super.render(),this.element=this.domElement}}class H extends f.ListItemView{highlight(){this.children.first.isOn=!0}removeHighlight(){this.children.first.isOn=!1}}const J=[o.keyCodes.arrowup,o.keyCodes.arrowdown,o.keyCodes.esc],z=[o.keyCodes.enter,o.keyCodes.tab];class G extends i.Plugin{static get pluginName(){return"MentionUI"}static get requires(){return[f.ContextualBalloon]}constructor(e){super(e),this._mentionsView=this._createMentionView(),this._mentionsConfigurations=new Map,this._requestFeedDebounced=D(this._requestFeed,100),e.config.define("mention",{feeds:[]})}init(){const e=this.editor,t=e.config.get("mention.commitKeys")||z,n=J.concat(t);this._balloon=e.plugins.get(f.ContextualBalloon),e.editing.view.document.on("keydown",(e,i)=>{var r;r=i.keyCode,n.includes(r)&&this._isUIVisible&&(i.preventDefault(),e.stop(),i.keyCode==o.keyCodes.arrowdown&&this._mentionsView.selectNext(),i.keyCode==o.keyCodes.arrowup&&this._mentionsView.selectPrevious(),t.includes(i.keyCode)&&this._mentionsView.executeSelected(),i.keyCode==o.keyCodes.esc&&this._hideUIAndRemoveMarker())},{priority:"highest"}),Object(f.clickOutsideHandler)({emitter:this._mentionsView,activator:()=>this._isUIVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideUIAndRemoveMarker()});const i=e.config.get("mention.feeds");for(const e of i){const t=e.feed,n=e.marker;if(!Z(n))throw new o.CKEditorError("mentionconfig-incorrect-marker",null,{marker:n});const i=e.minimumCharacters||0,r="function"==typeof t?t.bind(this.editor):Y(t),s={watcher:this._setupTextWatcherForFeed(n,i),marker:n,feedCallback:r,itemRenderer:e.itemRenderer};this._mentionsConfigurations.set(n,s)}this.listenTo(e,"change:isReadOnly",()=>{this._hideUIAndRemoveMarker()}),this.on("requestFeed:response",(e,t)=>this._handleFeedResponse(t)),this.on("requestFeed:error",()=>this._hideUIAndRemoveMarker())}destroy(){super.destroy(),this._mentionsView.destroy()}get _isUIVisible(){return this._balloon.visibleView===this._mentionsView}_createMentionView(){const e=this.editor.locale,t=new K(e);return this._items=new o.Collection,t.items.bindTo(this._items).using(n=>{const{item:i,marker:o}=n,r=this.editor.config.get("mention.dropdownLimit")||10;if(t.items.length>=r)return;const s=new H(e),c=this._renderItem(i,o);return c.delegate("execute").to(s),s.children.add(c),s.item=i,s.marker=o,s.on("execute",()=>{t.fire("execute",{item:i,marker:o})}),s}),t.on("execute",(e,t)=>{const n=this.editor,i=n.model,o=t.item,r=t.marker,s=n.model.markers.get("mention"),c=i.createPositionAt(i.document.selection.focus),a=i.createPositionAt(s.getStart()),d=i.createRange(a,c);this._hideUIAndRemoveMarker(),n.execute("mention",{mention:o,text:o.text,marker:r,range:d}),n.editing.view.focus()}),t}_getItemRenderer(e){const{itemRenderer:t}=this._mentionsConfigurations.get(e);return t}_requestFeed(e,t){this._lastRequested=t;const{feedCallback:n}=this._mentionsConfigurations.get(e),i=n(t);i instanceof Promise?i.then(n=>{this._lastRequested==t?this.fire("requestFeed:response",{feed:n,marker:e,feedText:t}):this.fire("requestFeed:discarded",{feed:n,marker:e,feedText:t})}).catch(t=>{this.fire("requestFeed:error",{error:t}),Object(o.logWarning)("mention-feed-callback-error",{marker:e})}):this.fire("requestFeed:response",{feed:i,marker:e,feedText:t})}_setupTextWatcherForFeed(e,t){const n=this.editor,i=new h.TextWatcher(n.model,function(e,t){const n=X(e,t);return e=>n.test(e)}(e,t));i.on("matched",(t,i)=>{const o=n.model.document.selection.focus;if(function(e){const t=e.textNode&&e.textNode.hasAttribute("mention"),n=e.nodeBefore;return t||n&&n.is("$text")&&n.hasAttribute("mention")}(o))return void this._hideUIAndRemoveMarker();const r=function(e,t){const n=X(e,0);return t.match(n)[2]}(e,i.text),s=e.length+r.length,c=o.getShiftedBy(-s),a=o.getShiftedBy(-r.length),d=n.model.createRange(c,a);if(ee(n)){const e=n.model.markers.get("mention");n.model.change(t=>{t.updateMarker(e,{range:d})})}else n.model.change(e=>{e.addMarker("mention",{range:d,usingOperation:!1,affectsData:!1})});this._requestFeedDebounced(e,r)}),i.on("unmatched",()=>{this._hideUIAndRemoveMarker()});const o=n.commands.get("mention");return i.bind("isEnabled").to(o),i}_handleFeedResponse(e){const{feed:t,marker:n}=e;if(!ee(this.editor))return;this._items.clear();for(const e of t){const t="object"!=typeof e?{id:e,text:e}:e;this._items.add({item:t,marker:n})}const i=this.editor.model.markers.get("mention");this._items.length?this._showOrUpdateUI(i):this._hideUIAndRemoveMarker()}_showOrUpdateUI(e){this._isUIVisible?this._balloon.updatePosition(this._getBalloonPanelPositionData(e,this._mentionsView.position)):this._balloon.add({view:this._mentionsView,position:this._getBalloonPanelPositionData(e,this._mentionsView.position),singleViewMode:!0}),this._mentionsView.position=this._balloon.view.position,this._mentionsView.selectFirst()}_hideUIAndRemoveMarker(){this._balloon.hasView(this._mentionsView)&&this._balloon.remove(this._mentionsView),ee(this.editor)&&this.editor.model.change(e=>e.removeMarker("mention")),this._mentionsView.position=void 0}_renderItem(e,t){const n=this.editor;let i,o=e.id;const r=this._getItemRenderer(t);if(r){const t=r(e);"string"!=typeof t?i=new W(n.locale,t):o=t}if(!i){const e=new f.ButtonView(n.locale);e.label=o,e.withText=!0,i=e}return i}_getBalloonPanelPositionData(e,t){const n=this.editor,i=n.editing,r=i.view.domConverter,s=i.mapper;return{target:()=>{let t=e.getRange();"$graveyard"==t.start.root.rootName&&(t=n.model.document.selection.getFirstRange());const i=s.toViewRange(t);return o.Rect.getDomRangeRects(r.viewRangeToDom(i)).pop()},limiter:()=>{const e=this.editor.editing.view,t=e.document.selection.editableElement;return t?e.domConverter.mapViewToDom(t.root):null},positions:Q(t)}}}function Q(e){const t={caret_se:e=>({top:e.bottom+3,left:e.right,name:"caret_se",config:{withArrow:!1}}),caret_ne:(e,t)=>({top:e.top-t.height-3,left:e.right,name:"caret_ne",config:{withArrow:!1}}),caret_sw:(e,t)=>({top:e.bottom+3,left:e.right-t.width,name:"caret_sw",config:{withArrow:!1}}),caret_nw:(e,t)=>({top:e.top-t.height-3,left:e.right-t.width,name:"caret_nw",config:{withArrow:!1}})};return Object.prototype.hasOwnProperty.call(t,e)?[t[e]]:[t.caret_se,t.caret_sw,t.caret_ne,t.caret_nw]}function X(e,t){const n=0==t?"*":`{${t},}`,i=o.env.features.isRegExpUnicodePropertySupported?"\\p{Ps}\\p{Pi}\"'":"\\(\\[{\"'";return new RegExp(`(?:^|[ ${i}])([${e}])([\\S]${n})$`,"u")}function Y(e){return t=>e.filter(e=>("string"==typeof e?e:String(e.id)).toLowerCase().includes(t.toLowerCase()))}function Z(e){return e&&1==e.length}function ee(e){return e.model.markers.has("mention")}n(10);class te extends i.Plugin{toMentionAttribute(e,t){return a(e,t)}static get pluginName(){return"Mention"}static get requires(){return[s,G]}}}]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-mention",
3
- "version": "29.1.0",
3
+ "version": "31.1.0",
4
4
  "description": "Mention feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,27 +12,27 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^29.1.0",
15
+ "ckeditor5": "^31.1.0",
16
16
  "lodash-es": "^4.17.15"
17
17
  },
18
18
  "devDependencies": {
19
- "@ckeditor/ckeditor5-basic-styles": "^29.1.0",
20
- "@ckeditor/ckeditor5-block-quote": "^29.1.0",
21
- "@ckeditor/ckeditor5-clipboard": "^29.1.0",
22
- "@ckeditor/ckeditor5-core": "^29.1.0",
23
- "@ckeditor/ckeditor5-dev-utils": "^25.3.0",
24
- "@ckeditor/ckeditor5-editor-classic": "^29.1.0",
25
- "@ckeditor/ckeditor5-engine": "^29.1.0",
26
- "@ckeditor/ckeditor5-font": "^29.1.0",
27
- "@ckeditor/ckeditor5-link": "^29.1.0",
28
- "@ckeditor/ckeditor5-paragraph": "^29.1.0",
29
- "@ckeditor/ckeditor5-table": "^29.1.0",
30
- "@ckeditor/ckeditor5-theme-lark": "^29.1.0",
31
- "@ckeditor/ckeditor5-typing": "^29.1.0",
32
- "@ckeditor/ckeditor5-ui": "^29.1.0",
33
- "@ckeditor/ckeditor5-undo": "^29.1.0",
34
- "@ckeditor/ckeditor5-utils": "^29.1.0",
35
- "@ckeditor/ckeditor5-widget": "^29.1.0",
19
+ "@ckeditor/ckeditor5-basic-styles": "^31.1.0",
20
+ "@ckeditor/ckeditor5-block-quote": "^31.1.0",
21
+ "@ckeditor/ckeditor5-clipboard": "^31.1.0",
22
+ "@ckeditor/ckeditor5-core": "^31.1.0",
23
+ "@ckeditor/ckeditor5-dev-utils": "^26.0.0",
24
+ "@ckeditor/ckeditor5-editor-classic": "^31.1.0",
25
+ "@ckeditor/ckeditor5-engine": "^31.1.0",
26
+ "@ckeditor/ckeditor5-font": "^31.1.0",
27
+ "@ckeditor/ckeditor5-link": "^31.1.0",
28
+ "@ckeditor/ckeditor5-paragraph": "^31.1.0",
29
+ "@ckeditor/ckeditor5-table": "^31.1.0",
30
+ "@ckeditor/ckeditor5-theme-lark": "^31.1.0",
31
+ "@ckeditor/ckeditor5-typing": "^31.1.0",
32
+ "@ckeditor/ckeditor5-ui": "^31.1.0",
33
+ "@ckeditor/ckeditor5-undo": "^31.1.0",
34
+ "@ckeditor/ckeditor5-utils": "^31.1.0",
35
+ "@ckeditor/ckeditor5-widget": "^31.1.0",
36
36
  "lodash": "^4.17.15",
37
37
  "webpack": "^4.43.0",
38
38
  "webpack-cli": "^3.3.11"
package/src/mention.js CHANGED
@@ -105,6 +105,71 @@ export default class Mention extends Plugin {
105
105
  * @member {Array.<module:mention/mention~MentionFeed>} module:mention/mention~MentionConfig#feeds
106
106
  */
107
107
 
108
+ /**
109
+ * The configuration of the custom commit keys supported by the editor.
110
+ *
111
+ * ClassicEditor
112
+ * .create( editorElement, {
113
+ * plugins: [ Mention, ... ],
114
+ * mention: {
115
+ * // [ Enter, Space ]
116
+ * commitKeys: [ 13, 32 ]
117
+ * feeds: [
118
+ * { ... }
119
+ * ...
120
+ * ]
121
+ * }
122
+ * } )
123
+ * .then( ... )
124
+ * .catch( ... );
125
+ *
126
+ * Custom commit keys configuration allows you to customize how users will confirm the selection of mentions from the dropdown list.
127
+ * You can add as many mention commit keys as you need. For instance, in the snippet above new mentions will be committed by pressing
128
+ * either <kbd>Enter</kbd> or <kbd>Space</kbd> (13 and 32 key codes respectively).
129
+ *
130
+ * @member {Array.<Number>} module:mention/mention~MentionConfig#commitKeys
131
+ * @default [ 13, 9 ] // [ Enter, Tab ]
132
+ */
133
+
134
+ /**
135
+ * The configuration of the custom number of visible mentions.
136
+ *
137
+ * Customizing the number of visible mentions allows you to specify how many available elements will the users be able to see
138
+ * in the dropdown list. You can specify any number you see fit. For example, in the snippets below you will find the
139
+ * dropdownLimit set to `20` and `Infinity` (this will result in showing all available mentions).
140
+ *
141
+ * ClassicEditor
142
+ * .create( editorElement, {
143
+ * plugins: [ Mention, ... ],
144
+ * mention: {
145
+ * dropdownLimit: 20,
146
+ * feeds: [
147
+ * { ... }
148
+ * ...
149
+ * ]
150
+ * }
151
+ * } )
152
+ * .then( ... )
153
+ * .catch( ... );
154
+ *
155
+ * ClassicEditor
156
+ * .create( editorElement, {
157
+ * plugins: [ Mention, ... ],
158
+ * mention: {
159
+ * dropdownLimit: Infinity,
160
+ * feeds: [
161
+ * { ... }
162
+ * ...
163
+ * ]
164
+ * }
165
+ * } )
166
+ * .then( ... )
167
+ * .catch( ... );
168
+ *
169
+ * @member {Number} module:mention/mention~MentionConfig#dropdownLimit
170
+ * @default 10
171
+ */
172
+
108
173
  /**
109
174
  * The mention feed descriptor. Used in {@link module:mention/mention~MentionConfig `config.mention`}.
110
175
  *
@@ -126,8 +191,6 @@ export default class Mention extends Plugin {
126
191
  * .filter( tag => {
127
192
  * return tag.toLowerCase().includes( queryText.toLowerCase() );
128
193
  * } )
129
- * // Return 10 items max - needed for generic queries when the list may contain hundreds of elements.
130
- * .slice( 0, 10 );
131
194
  * }
132
195
  * };
133
196
  *
@@ -68,8 +68,8 @@ export default class MentionCommand extends Command {
68
68
  * @param {String} options.marker The marker character (e.g. `'@'`).
69
69
  * @param {String} [options.text] The text of the inserted mention. Defaults to the full mention string composed from `marker` and
70
70
  * `mention` string or `mention.id` if an object is passed.
71
- * @param {String} [options.range] The range to replace. Note that the replaced range might be shorter than the inserted text with the
72
- * mention attribute.
71
+ * @param {module:engine/model/range~Range} [options.range] The range to replace.
72
+ * Note that the replaced range might be shorter than the inserted text with the mention attribute.
73
73
  * @fires execute
74
74
  */
75
75
  execute( options ) {
package/src/mentionui.js CHANGED
@@ -20,15 +20,19 @@ import MentionListItemView from './ui/mentionlistitemview';
20
20
 
21
21
  const VERTICAL_SPACING = 3;
22
22
 
23
- // The key codes that mention UI handles when it is open.
24
- const handledKeyCodes = [
23
+ // The key codes that mention UI handles when it is open (without commit keys).
24
+ const defaultHandledKeyCodes = [
25
25
  keyCodes.arrowup,
26
26
  keyCodes.arrowdown,
27
- keyCodes.enter,
28
- keyCodes.tab,
29
27
  keyCodes.esc
30
28
  ];
31
29
 
30
+ // Dropdown commit key codes.
31
+ const defaultCommitKeyCodes = [
32
+ keyCodes.enter,
33
+ keyCodes.tab
34
+ ];
35
+
32
36
  /**
33
37
  * The mention UI feature.
34
38
  *
@@ -90,6 +94,9 @@ export default class MentionUI extends Plugin {
90
94
  init() {
91
95
  const editor = this.editor;
92
96
 
97
+ const commitKeys = editor.config.get( 'mention.commitKeys' ) || defaultCommitKeyCodes;
98
+ const handledKeyCodes = defaultHandledKeyCodes.concat( commitKeys );
99
+
93
100
  /**
94
101
  * The contextual balloon plugin instance.
95
102
  *
@@ -112,7 +119,7 @@ export default class MentionUI extends Plugin {
112
119
  this._mentionsView.selectPrevious();
113
120
  }
114
121
 
115
- if ( data.keyCode == keyCodes.enter || data.keyCode == keyCodes.tab ) {
122
+ if ( commitKeys.includes( data.keyCode ) ) {
116
123
  this._mentionsView.executeSelected();
117
124
  }
118
125
 
@@ -163,8 +170,19 @@ export default class MentionUI extends Plugin {
163
170
  this._mentionsConfigurations.set( marker, definition );
164
171
  }
165
172
 
173
+ this.listenTo( editor, 'change:isReadOnly', () => {
174
+ this._hideUIAndRemoveMarker();
175
+ } );
166
176
  this.on( 'requestFeed:response', ( evt, data ) => this._handleFeedResponse( data ) );
167
177
  this.on( 'requestFeed:error', () => this._hideUIAndRemoveMarker() );
178
+
179
+ // Checks if a given key code is handled by the mention UI.
180
+ //
181
+ // @param {Number}
182
+ // @returns {Boolean}
183
+ function isHandledKey( keyCode ) {
184
+ return handledKeyCodes.includes( keyCode );
185
+ }
168
186
  }
169
187
 
170
188
  /**
@@ -205,6 +223,13 @@ export default class MentionUI extends Plugin {
205
223
  mentionsView.items.bindTo( this._items ).using( data => {
206
224
  const { item, marker } = data;
207
225
 
226
+ // Set to 10 by default for backwards compatibility. See: #10479
227
+ const dropdownLimit = this.editor.config.get( 'mention.dropdownLimit' ) || 10;
228
+
229
+ if ( mentionsView.items.length >= dropdownLimit ) {
230
+ return;
231
+ }
232
+
208
233
  const listItemView = new MentionListItemView( locale );
209
234
 
210
235
  const view = this._renderItem( item, marker );
@@ -448,7 +473,6 @@ export default class MentionUI extends Plugin {
448
473
  this._balloon.add( {
449
474
  view: this._mentionsView,
450
475
  position: this._getBalloonPanelPositionData( markerMarker, this._mentionsView.position ),
451
- withArrow: false,
452
476
  singleViewMode: true
453
477
  } );
454
478
  }
@@ -571,7 +595,10 @@ function getBalloonPanelPositions( preferredPosition ) {
571
595
  return {
572
596
  top: targetRect.bottom + VERTICAL_SPACING,
573
597
  left: targetRect.right,
574
- name: 'caret_se'
598
+ name: 'caret_se',
599
+ config: {
600
+ withArrow: false
601
+ }
575
602
  };
576
603
  },
577
604
 
@@ -580,7 +607,10 @@ function getBalloonPanelPositions( preferredPosition ) {
580
607
  return {
581
608
  top: targetRect.top - balloonRect.height - VERTICAL_SPACING,
582
609
  left: targetRect.right,
583
- name: 'caret_ne'
610
+ name: 'caret_ne',
611
+ config: {
612
+ withArrow: false
613
+ }
584
614
  };
585
615
  },
586
616
 
@@ -589,7 +619,10 @@ function getBalloonPanelPositions( preferredPosition ) {
589
619
  return {
590
620
  top: targetRect.bottom + VERTICAL_SPACING,
591
621
  left: targetRect.right - balloonRect.width,
592
- name: 'caret_sw'
622
+ name: 'caret_sw',
623
+ config: {
624
+ withArrow: false
625
+ }
593
626
  };
594
627
  },
595
628
 
@@ -598,7 +631,10 @@ function getBalloonPanelPositions( preferredPosition ) {
598
631
  return {
599
632
  top: targetRect.top - balloonRect.height - VERTICAL_SPACING,
600
633
  left: targetRect.right - balloonRect.width,
601
- name: 'caret_nw'
634
+ name: 'caret_nw',
635
+ config: {
636
+ withArrow: false
637
+ }
602
638
  };
603
639
  }
604
640
  };
@@ -678,22 +714,11 @@ function createFeedCallback( feedItems ) {
678
714
 
679
715
  // The default feed is case insensitive.
680
716
  return itemId.toLowerCase().includes( feedText.toLowerCase() );
681
- } )
682
- // Do not return more than 10 items.
683
- .slice( 0, 10 );
684
-
717
+ } );
685
718
  return filteredItems;
686
719
  };
687
720
  }
688
721
 
689
- // Checks if a given key code is handled by the mention UI.
690
- //
691
- // @param {Number}
692
- // @returns {Boolean}
693
- function isHandledKey( keyCode ) {
694
- return handledKeyCodes.includes( keyCode );
695
- }
696
-
697
722
  // Checks if position in inside or right after a text with a mention.
698
723
  //
699
724
  // @param {module:engine/model/position~Position} position.
package/CHANGELOG.md DELETED
@@ -1,97 +0,0 @@
1
- Changelog
2
- =========
3
-
4
- All changes in the package are documented in the main repository. See: https://github.com/ckeditor/ckeditor5/blob/master/CHANGELOG.md.
5
-
6
- Changes for the past releases are available below.
7
-
8
- ## [19.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v18.0.0...v19.0.0) (2020-04-29)
9
-
10
- ### Bug fixes
11
-
12
- * Mention UI is no longer appearing when mention command is disabled. Closes [ckeditor/ckeditor5#5958](https://github.com/ckeditor/ckeditor5/issues/5958). ([eca1e48](https://github.com/ckeditor/ckeditor5-mention/commit/eca1e48))
13
- * Mentions can now be matched by any character typed. Closes [ckeditor/ckeditor5#6398](https://github.com/ckeditor/ckeditor5/issues/6398). ([aa7d04d](https://github.com/ckeditor/ckeditor5-mention/commit/aa7d04d))
14
-
15
-
16
- ## [18.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v17.0.0...v18.0.0) (2020-03-19)
17
-
18
- Internal changes only (updated dependencies, documentation, etc.).
19
-
20
-
21
- ## [17.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v16.0.0...v17.0.0) (2020-02-19)
22
-
23
- ### Features
24
-
25
- * Implemented debounced mechanism for requesting a mention feed. Closes [ckeditor/ckeditor5#4619](https://github.com/ckeditor/ckeditor5/issues/4619). ([f50db9c](https://github.com/ckeditor/ckeditor5-mention/commit/f50db9c))
26
-
27
-
28
- ## [16.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v15.0.0...v16.0.0) (2019-12-04)
29
-
30
- Internal changes only (updated dependencies, documentation, etc.).
31
-
32
-
33
- ## [15.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v13.0.0...v15.0.0) (2019-10-23)
34
-
35
- ### Other changes
36
-
37
- * Bind the `feed` callback function to the editor instance. ([0ba40a9](https://github.com/ckeditor/ckeditor5-mention/commit/0ba40a9))
38
-
39
- Thanks [@oliverguenther](https://github.com/oliverguenther) for the contribution!
40
-
41
-
42
- ## [13.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v12.0.1...v13.0.0) (2019-08-26)
43
-
44
- ### Other changes
45
-
46
- * The issue tracker for this package was moved to https://github.com/ckeditor/ckeditor5/issues. See [ckeditor/ckeditor5#1988](https://github.com/ckeditor/ckeditor5/issues/1988). ([2a33675](https://github.com/ckeditor/ckeditor5-mention/commit/2a33675))
47
- * Use RegExp Unicode support feature detection form ckeditor5-utils. ([d47923e](https://github.com/ckeditor/ckeditor5-mention/commit/d47923e))
48
-
49
- ### BREAKING CHANGES
50
-
51
- * The `mention/featuredetection` namespace is removed. Please use `env.features` from ckeditor5-utils instead.
52
-
53
-
54
- ## [12.0.1](https://github.com/ckeditor/ckeditor5-mention/compare/v12.0.0...v12.0.1) (2019-07-10)
55
-
56
- Internal changes only (updated dependencies, documentation, etc.).
57
-
58
-
59
- ## [12.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v11.0.0...v12.0.0) (2019-07-04)
60
-
61
- ### Bug fixes
62
-
63
- * It should be possible to type before a mention which is at the beginning of a block. Closes [#77](https://github.com/ckeditor/ckeditor5-mention/issues/77). ([946e762](https://github.com/ckeditor/ckeditor5-mention/commit/946e762))
64
- * Mentions should work when different UTF character classes are used in the feed configuration. Closes [#38](https://github.com/ckeditor/ckeditor5-mention/issues/38). ([764f099](https://github.com/ckeditor/ckeditor5-mention/commit/764f099))
65
- * Partial mentions should not be downcasted (e.g. not copied to clipboard). Closes [#24](https://github.com/ckeditor/ckeditor5-mention/issues/24). ([8956b1f](https://github.com/ckeditor/ckeditor5-mention/commit/8956b1f))
66
-
67
- ### Other changes
68
-
69
- * Moved the `TextWatcher` util to `@ckeditor/ckeditor5-typing`. ([a644043](https://github.com/ckeditor/ckeditor5-mention/commit/a644043))
70
-
71
- ### BREAKING CHANGES
72
-
73
- * The `TextWatcher` util was moved to `@ckeditor/ckeditor5-typing`.
74
-
75
-
76
- ## [11.0.0](https://github.com/ckeditor/ckeditor5-mention/compare/v10.0.0...v11.0.0) (2019-06-05)
77
-
78
- ### Bug fixes
79
-
80
- * A mention can now be preceded by characters such as brackets, quotes, soft break, etc. Closes [#44](https://github.com/ckeditor/ckeditor5-mention/issues/44). ([86262d1](https://github.com/ckeditor/ckeditor5-mention/commit/86262d1))
81
- * The mention plugin should not throw errors when another `ContextualBalloon` is already visible. Closes [#67](https://github.com/ckeditor/ckeditor5-mention/issues/67). ([de9ee71](https://github.com/ckeditor/ckeditor5-mention/commit/de9ee71))
82
- * The mention panel should have precedence over all other panels. Closes [#74](https://github.com/ckeditor/ckeditor5-mention/issues/74). ([3e8a84c](https://github.com/ckeditor/ckeditor5-mention/commit/3e8a84c))
83
- * The Mention UI will use `ContextualBalloon` plugin to display to prevent balloon collisions with other features. Closes [#27](https://github.com/ckeditor/ckeditor5-mention/issues/27). ([9ae7f30](https://github.com/ckeditor/ckeditor5-mention/commit/9ae7f30))
84
-
85
- ### Other changes
86
-
87
- * Remove unknown stack option from `ContextualBalloon#add()` method call. ([b6a50cf](https://github.com/ckeditor/ckeditor5-mention/commit/b6a50cf))
88
- * Use `Model#insertContent()` instead of `model.Writer#insertText()`. Closes [#69](https://github.com/ckeditor/ckeditor5-mention/issues/69). ([ee973bb](https://github.com/ckeditor/ckeditor5-mention/commit/ee973bb))
89
-
90
- ### BREAKING CHANGES
91
-
92
- * The `MentionUI#panelView` property is removed. The mention feature now uses the `ContextualBalloon` plugin.
93
-
94
-
95
- ## [10.0.0](https://github.com/ckeditor/ckeditor5-mention/tree/v10.0.0) (2019-04-10)
96
-
97
- The initial release.