UNPKG

@znuny/ckeditor5-autocomplete-plugin

Version:

A plugin for CKEditor 5 that provides an extendable autocomplete functionality with predefined mention and HTML replacement logic.

66 lines 23.4 kB
(()=>{var e={72:(e,t,n)=>{"use strict";var o,i=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},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={},o=[],i=0;i<e.length;i++){var r=e[i],a=t.base?r[0]+t.base:r[0],l=n[a]||0,d="".concat(a," ").concat(l);n[a]=l+1;var m=c(d),u={css:r[1],media:r[2],sourceMap:r[3]};-1!==m?(s[m].references++,s[m].updater(u)):s.push({identifier:d,updater:p(u,t),references:1}),o.push(d)}return o}function l(e){var t=document.createElement("style"),o=e.attributes||{};if(void 0===o.nonce){var i=n.nc;i&&(o.nonce=i)}if(Object.keys(o).forEach(function(e){t.setAttribute(e,o[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 d,m=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function u(e,t,n,o){var i=n?"":o.media?"@media ".concat(o.media," {").concat(o.css,"}"):o.css;if(e.styleSheet)e.styleSheet.cssText=m(t,i);else{var r=document.createTextNode(i),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(r,s[t]):e.appendChild(r)}}function h(e,t,n){var o=n.css,i=n.media,r=n.sourceMap;if(i?e.setAttribute("media",i):e.removeAttribute("media"),r&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}var g=null,f=0;function p(e,t){var n,o,i;if(t.singleton){var r=f++;n=g||(g=l(t)),o=u.bind(null,n,r,!1),i=u.bind(null,n,r,!0)}else n=l(t),o=h.bind(null,n,t),i=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else i()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=i());var n=a(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var o=0;o<n.length;o++){var i=c(n[o]);s[i].references--}for(var r=a(e,t),l=0;l<n.length;l++){var d=c(n[l]);0===s[d].references&&(s[d].updater(),s.splice(d,1))}n=r}}}},237:e=>{"use strict";e.exports=CKEditor5.dll},311:(e,t,n)=>{e.exports=n(237)("./src/ui.js")},314:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=e(t);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n}).join("")},t.i=function(e,n,o){"string"==typeof e&&(e=[[null,e,""]]);var i={};if(o)for(var r=0;r<this.length;r++){var s=this[r][0];null!=s&&(i[s]=!0)}for(var c=0;c<e.length;c++){var a=[].concat(e[c]);o&&i[a[0]]||(n&&(a[2]?a[2]="".concat(n," and ").concat(a[2]):a[2]=n),t.push(a))}},t}},530:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});var o=n(314),i=n.n(o)()(function(e){return e[1]});i.push([e.id,":root{--ck-mention-list-max-height:300px}.ck.ck-mentions{max-height:var(--ck-mention-list-max-height);overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}.ck.ck-mentions>.ck-list__item{flex-shrink:0;overflow:hidden}.ck.ck-mentions .ck-button,.ck.ck-mentions .ck-button.ck-off{background:var(--ck-color-mention-selection-background,var(--ck-color-button-default-background))!important;color:var(--ck-color-mention-selection-text,var(--ck-color-text))!important}.ck.ck-mentions .ck-button.ck-on{background:var(--ck-color-mention-selection-background-selected,var(--ck-color-list-button-on-background))!important;color:var(--ck-color-mention-selection-text-selected,var(--ck-color-list-button-on-text))!important}.ck.ck-mentions .ck-button:hover,.ck.ck-mentions .ck-button>:hover{cursor:pointer}.ck.ck-mentions .custom-flex-column-item{display:flex;flex-direction:column}",""]);const r=i},584:(e,t,n)=>{e.exports=n(237)("./src/utils.js")},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")},784:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});var o=n(314),i=n.n(o)()(function(e){return e[1]});i.push([e.id,".ck-content .mention{background:var(--ck-color-mention-background,rgba(20,99,255,.4));color:var(--ck-color-mention-text,#262626)}",""]);const r=i},834:(e,t,n)=>{e.exports=n(237)("./src/typing.js")}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={id:o,exports:{}};return e[o](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nc=void 0;var o={};(()=>{"use strict";n.r(o),n.d(o,{Autocomplete:()=>b});var e=n(782),t=n(783),i=n(834),r=n(311),s=n(584),c=n(72),a=n.n(c),l=n(530),d={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};a()(l.A,d);l.A.locals; /** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ class m extends r.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 s.Rect(this.element).contains(new s.Rect(e.element))}} /** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ class u extends r.ListItemView{highlight(){this.children.first.isOn=!0}removeHighlight(){this.children.first.isOn=!1}} /** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ class h extends r.View{constructor(e,t){super(e),this.template=void 0,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")}),this.listenTo(this.domElement,"mouseover",()=>{this.fire("mouseover")})}render(){super.render(),this.element=this.domElement}focus(){this.domElement.focus()}}class g{constructor(e,t,n,o){this.availableMentionsViewItems=new s.Collection,this.editor=e,this.pluginMarkerName=t,this.mentionsView=this.createMentionView(o),this.balloon=e.plugins.get(r.ContextualBalloon);const i=n||g.defaultCommitKeyCodes,c=g.defaultHandledKeyCodes.concat(i);e.editing.view.document.on("keydown",(e,t)=>{c.includes(t.keyCode)&&this.isUIVisible()&&(t.preventDefault(),e.stop(),t.keyCode==s.keyCodes.arrowdown&&this.mentionsView.selectNext(),t.keyCode==s.keyCodes.arrowup&&this.mentionsView.selectPrevious(),i.includes(t.keyCode)&&this.mentionsView.executeSelected(),t.keyCode==s.keyCodes.esc&&this.hideUIAndRemoveMarker())},{priority:"highest"}),(0,r.clickOutsideHandler)({emitter:this.mentionsView,activator:()=>this.isUIVisible(),contextElements:()=>[this.balloon.view.element],callback:()=>this.hideUIAndRemoveMarker()})}createMentionView(e){const t=this.editor.locale,n=new m(t);return n.items.bindTo(this.availableMentionsViewItems).using(o=>{const{item:i,marker:r}=o,s=e??10;if(-1!==s&&n.items.length>=s)return null;const c=new u(t),a=this.renderItem(i);a.delegate("execute").to(c),a.delegate("mouseover").to(c),c.children.add(a),c.item=i,c.marker=r,c.on("execute",()=>{n.fire("execute",o)});const l=n.items.length;return c.on("mouseover",()=>{n.select(l)}),c}),n.on("execute",(e,t)=>{t.confirmedSelectionHandler(),this.hideUIAndRemoveMarker(),this.editor.editing.view.focus()}),n}renderItem(e){const t=this.editor;let n,o=e.name??e.content.toString().substring(0,30);if(e.completionElementRenderer){const i=e.completionElementRenderer(e);"string"!=typeof i?n=new h(t.locale,i):o=i}if(!n){const e=new r.ButtonView(t.locale);e.label=o,e.withText=!0,e.template&&e.extendTemplate({on:{mouseover:e.bindTemplate.to("mouseover")}}),n=e}return n}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.isUIVisible()&&(this.balloon.hasView(this.mentionsView)&&this.balloon.remove(this.mentionsView),this.isInCompletionMode()&&this.editor.model.change(e=>e.removeMarker(this.pluginMarkerName)),this.mentionsView.position=void 0)}getBalloonPanelPositionData(e,t){const n=this.editor,o=n.editing,i=o.view.domConverter,r=o.mapper,c=n.locale.uiLanguageDirection;return{target:()=>{let t=e.getRange();"$graveyard"==t.start.root.rootName&&(t=n.model.document.selection.getFirstRange());const o=r.toViewRange(t);return s.Rect.getDomRangeRects(i.viewRangeToDom(o)).pop()},limiter:()=>{const e=this.editor.editing.view,t=e.document.selection.editableElement;return t?e.domConverter.mapViewToDom(t.root):null},positions:this.getBalloonPanelPositions(t,c)}}getBalloonPanelPositions(e,t){const n={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(n,e)?[n[e]]:"rtl"!==t?[n.caret_se,n.caret_sw,n.caret_ne,n.caret_nw]:[n.caret_sw,n.caret_se,n.caret_nw,n.caret_ne]}isInCompletionMode(){return this.editor.model.markers.has(this.pluginMarkerName)}isUIVisible(){return this.balloon.visibleView===this.mentionsView}}g.defaultHandledKeyCodes=[s.keyCodes.arrowup,s.keyCodes.arrowdown,s.keyCodes.esc],g.defaultCommitKeyCodes=[s.keyCodes.enter,s.keyCodes.tab]; /** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ class f{static mergeMentionObjects(e,t){return Object.assign({uid:(0,s.uid)()},e,t||{})}static createViewMentionElement(e,{writer:t}){if(!e)return;const n={class:"mention",[f.identifyingMentionAttributeName]:e.name??e.content.toString()};for(const t of e.attributes??[])"class"!==t.name&&t.name!==f.identifyingMentionAttributeName&&(n[t.name]=t.value);const o={id:e.uid,priority:20};return t.createAttributeElement(f.mentionCompletionElementTagName,n,o)}static preventPartialMentionDowncast(e){e.on("attribute:mention",(e,t,n)=>{const o=t.attributeNewValue;if(!t.item.is("$textProxy")||!o)return;const i=t.range.start;(i.textNode||i.nodeAfter).data!=o.content.toString()&&n.consumable.consume(t.item,e.name)},{priority:"highest"})}static extendAttributeOnMentionPostFixer(e,t){const n=t.differ.getChanges();let o=!1;for(const t of n)if("attribute"===t.type&&"mention"!=t.attributeKey){const n=t.range.start.nodeBefore,i=t.range.end.nodeAfter;for(const r of[n,i])f.isBrokenMentionNode(r)&&r.getAttribute(t.attributeKey)!=t.attributeNewValue&&(e.setAttribute(t.attributeKey,t.attributeNewValue,r),o=!0)}return o}static isBrokenMentionNode(e){if(!e||!e.is("$text")&&!e.is("$textProxy")||!e.hasAttribute("mention"))return!1;return e.data!=e.getAttribute("mention").content.toString()}static removePartialMentionPostFixer(e,t){const n=t.document.differ.getChanges();let o=!1;for(const i of n){if("attribute"==i.type)continue;const n=i.position;if("$text"==i.name){const t=n.textNode&&n.textNode.nextSibling;o=f.checkAndFix(n.textNode,e)||o,o=f.checkAndFix(t,e)||o,o=f.checkAndFix(n.nodeBefore,e)||o,o=f.checkAndFix(n.nodeAfter,e)||o}if("$text"!=i.name&&"insert"==i.type){const t=n.nodeAfter;for(const n of e.createRangeIn(t).getItems())o=f.checkAndFix(n,e)||o}if("insert"==i.type&&t.schema.isInline(i.name)){const t=n.nodeAfter&&n.nodeAfter.nextSibling;o=f.checkAndFix(n.nodeBefore,e)||o,o=f.checkAndFix(t,e)||o}}return o}static checkAndFix(e,t){return!!f.isBrokenMentionNode(e)&&(t.removeAttribute("mention",e),!0)}static selectionMentionAttributePostFixer(e,t){const n=t.selection,o=n.focus;return!!(n.isCollapsed&&n.hasAttribute("mention")&&f.shouldNotTypeWithMentionAt(o))&&(e.removeSelectionAttribute("mention"),!0)}static shouldNotTypeWithMentionAt(e){const t=e.isAtStart;return e.nodeBefore&&e.nodeBefore.is("$text")||t}} /** * @copyright Copyright (c) 2024, Znuny GmbH. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ var p;f.identifyingMentionAttributeName="data-mention",f.mentionCompletionElementTagName="span",f.makeItMentionable=(e,t)=>{e.model.schema.extend("$text",{allowAttributes:"mention"}),void 0!==t&&f.isValidHtmlElementTagName(t)&&(f.mentionCompletionElementTagName=t),e.conversion.for("upcast").elementToAttribute({view:{name:f.mentionCompletionElementTagName,attributes:[f.identifyingMentionAttributeName],classes:"mention"},model:{key:"mention",value:e=>f.toMentionAttribute(e)}}),e.conversion.for("downcast").attributeToElement({model:"mention",view:f.createViewMentionElement}),e.conversion.for("downcast").add(f.preventPartialMentionDowncast),e.model.document.registerPostFixer(t=>f.removePartialMentionPostFixer(t,e.model)),e.model.document.registerPostFixer(t=>f.extendAttributeOnMentionPostFixer(t,e.model.document)),e.model.document.registerPostFixer(t=>f.selectionMentionAttributePostFixer(t,e.model.document))},f.isValidHtmlElementTagName=e=>{const t=document.createElement(e);return t instanceof HTMLElement&&!(t instanceof HTMLUnknownElement)},f.toMentionAttribute=(e,t)=>{const n=[];for(const t of e.getAttributeKeys())if("class"!==t&&t!==f.identifyingMentionAttributeName){const o=e.getAttribute(t);o&&n.push({name:t,value:o})}const o=e.getAttribute(f.identifyingMentionAttributeName),i=e.getChild(0);if(!i)return;const r={name:o,content:i.data,attributes:n};return f.mergeMentionObjects(r,t)},function(e){e.NAME_STARTS_WITH="nameStartsWith",e.NAME_INCLUDES="nameIncludes",e.CONTENT_STARTS_WITH="contentStartsWith",e.CONTENT_INCLUDES="contentIncludes",e.EVERYTHING="everything"}(p||(p={}));var v=n(784),k={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};a()(v.A,k);v.A.locals; /** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ class b extends e.Plugin{static get requires(){return[r.ContextualBalloon]}static get pluginName(){return"Autocomplete"}static get pluginMarkerName(){return this.pluginName}static get pluginConfigurationName(){return this.pluginName.toLowerCase()}constructor(e){super(e),this.config=null,this.selectionUi=null,this.getAllMarkerPositions=(e,t)=>{const n=[];let o=0,i=-1;for(;-1!=o;)o=e.indexOf(t,i+1),-1!=o&&(n.push(o),i=o);return n},this.isSelectionAboveFulfilledCompletionReplacement=e=>{const n=new t.ModelRange(e.range.end.getShiftedBy(-1),e.range.end);return!0===this.editor.model.getSelectedContent(this.editor.model.createSelection(n)).getChild(0)?.hasAttribute("mention")},this.applyMatchingCompletionsToSelectionUi=(e,t,n)=>{let o=this.editor.model.markers.get(b.pluginMarkerName);if(void 0!==t){const i=n.range.start.getShiftedBy(t),r=this.editor.model.createRange(i,i);this.editor.model.change(e=>{o?e.updateMarker(o,{range:r}):(e.addMarker(b.pluginMarkerName,{range:r,usingOperation:!1,affectsData:!1}),o=this.editor.model.markers.get(b.pluginMarkerName))}),this.selectionUi?.availableMentionsViewItems.clear();for(const[t,o]of e)this.addGroupCompletionsToSelectionUi(t,o,i,n)}o&&e.size>0?this.selectionUi?.showOrUpdateUI(o):this.selectionUi?.hideUIAndRemoveMarker()},this.addGroupCompletionsToSelectionUi=(e,t,n,o)=>{const i=e.selectionDropdownLimit||this.config?.overallSelectionDropdownLimit||10;for(let r=0;r<t.length&&(r<i||-1===i);r++){const i=t[r];this.selectionUi?.availableMentionsViewItems.add({item:{...i,completionElementRenderer:i.completionElementRenderer??e.completionElementRenderer},marker:e.matchingMarker,confirmedSelectionHandler:()=>{this.editor.model.canEditAt(o.range)&&(void 0!==e.confirmedSelectionHandler?e.confirmedSelectionHandler(this.editor.model,this.editor.data,o,i):this.editor.model.change(e=>{const t=this.editor.model.createRange(n,this.editor.model.document.selection.focus);if(i.useAsHTMLReplacement){const e=this.editor.data.processor.toView(i.content.toString()),n=this.editor.data.toModel(e);this.editor.model.insertContent(n,t)}else{const n=(0,s.toMap)(this.editor.model.document.selection.getAttributes()),o=new Map(n.entries()),r=i.content.toString(),c={id:i.name??r},a=f.mergeMentionObjects({name:i.name??r,content:r,attributes:i.attributes},c);o.set("mention",a),this.editor.model.insertContent(e.createText(r,o),t)}}))}})}},this.createTextWatcherCallback=e=>t=>{for(const n of e)if(this.testMarkerMatchingForCompletionGroup(t,n))return!0;return!1},this.testMarkerMatchingForCompletionGroup=(e,t)=>{if(t.markerMatchingCallback&&"function"==typeof t.markerMatchingCallback)return t.markerMatchingCallback(e,t.matchingMarker);const n=e.split(" ");return n[n.length-1].includes(t.matchingMarker)},this.getMatchingHandlerByStrategy=(e,t=!1)=>{switch(e){case p.NAME_STARTS_WITH:return t?(e,t)=>t.name?.startsWith(e)??!1:(e,t)=>t.name?.toLowerCase().startsWith(e.toLowerCase())??!1;case p.NAME_INCLUDES:return t?(e,t)=>t.name?.includes(e)??!1:(e,t)=>t.name?.toLowerCase().includes(e.toLowerCase())??!1;case p.CONTENT_STARTS_WITH:return t?(e,t)=>t.content.toString().startsWith(e)??!1:(e,t)=>t.content.toString().toLowerCase().startsWith(e.toLowerCase())??!1;case p.CONTENT_INCLUDES:return t?(e,t)=>t.content.toString().includes(e)??!1:(e,t)=>t.content.toString().toLowerCase().includes(e.toLowerCase())??!1;case p.EVERYTHING:return(e,t)=>!0;default:return(e,t)=>!1}},this.processCSSOverwrite=()=>{if(null===this.config)return;const e=document.documentElement;this.config.overwriteCSSMentionBackgroundColor&&e.style.setProperty("--ck-color-mention-background",this.config.overwriteCSSMentionBackgroundColor),this.config.overwriteCSSMentionTextColor&&e.style.setProperty("--ck-color-mention-text",this.config.overwriteCSSMentionTextColor),this.config.overwriteCSSSelectionBackgroundColor&&e.style.setProperty("--ck-color-mention-selection-background",this.config.overwriteCSSSelectionBackgroundColor),this.config.overwriteCSSSelectionBackgroundColorSelected&&e.style.setProperty("--ck-color-mention-selection-background-selected",this.config.overwriteCSSSelectionBackgroundColorSelected),this.config.overwriteCSSSelectionTextColor&&e.style.setProperty("--ck-color-mention-selection-text",this.config.overwriteCSSSelectionTextColor),this.config.overwriteCSSSelectionTextColorSelected&&e.style.setProperty("--ck-color-mention-selection-text-selected",this.config.overwriteCSSSelectionTextColorSelected),this.config.overwriteCSSSelectionListMaxHeight&&e.style.setProperty("--ck-mention-list-max-height",this.config.overwriteCSSSelectionListMaxHeight)};try{this.editor.config.define(b.pluginConfigurationName,[]),this.config=this.editor.config.get(b.pluginConfigurationName),this.selectionUi=new g(this.editor,b.pluginMarkerName,this.config.commitKeyCodes,this.config.overallSelectionDropdownLimit)}catch(e){throw console.error(e),e}}init(){if(void 0===this.config||null===this.config||"object"!=typeof this.config||null===this.selectionUi)return void console.error("Autocomplete init aborted due to invalid config",this.config);this.processCSSOverwrite(),f.makeItMentionable(this.editor,this.config.overwriteMentionCompletionElementTagName);const e=new i.TextWatcher(this.editor.model,this.createTextWatcherCallback(this.config.completionGroups));e.on("unmatched",async()=>{this.selectionUi?.hideUIAndRemoveMarker()});const t=this.config;e.on("matched",async(e,n)=>{if(!0!==this.config?.allowAutocompletionAboveFulfilledCompletionReplacements&&this.isSelectionAboveFulfilledCompletionReplacement(n))return void this.selectionUi?.hideUIAndRemoveMarker();let o;const i=new Map;for(const e of t.completionGroups)if(this.testMarkerMatchingForCompletionGroup(n.text,e)){const t=n.text.split(" "),r=t[t.length-1];let s=[];const c=!0===e.testAllPossibleMarkersOfASelection?this.getAllMarkerPositions(r,e.matchingMarker):[r.lastIndexOf(e.matchingMarker)];for(const t of c){const c=t+e.matchingMarker.length,a=r.substring(c);if("function"==typeof e.completions)s=await e.completions(a);else if(a.length>0){const t=this.getMatchingHandlerByStrategy(e.completionMatchingHandler,e.completionMatchingHandlerCaseSensitivity);for(const n of e.completions)t(a,n)&&s.push(n)}else e.offerCompletionOptionsWithMarkerMatchingOnly||(s=e.completions);if(s.length>0){void 0===o&&(o=n.text.length-r.length+t),i.set(e,s);break}}if(!1===this.config?.combineResultOfCompletionGroupsWithSameMarker)break}this.applyMatchingCompletionsToSelectionUi(i,o,n)})}}})(),(window.CKEditor5=window.CKEditor5||{}).autocompletePlugin=o})();