@ckeditor/ckeditor5-mention 31.1.0 → 32.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +2 -2
- package/build/mention.js +2 -3
- package/package.json +22 -22
- package/src/index.js +1 -1
- package/src/mention.js +1 -1
- package/src/mentioncommand.js +1 -1
- package/src/mentionediting.js +1 -1
- package/src/mentionui.js +86 -25
- package/src/ui/domwrapperview.js +1 -1
- package/src/ui/mentionlistitemview.js +1 -1
- package/src/ui/mentionsview.js +1 -1
- package/theme/mention.css +1 -1
- package/theme/mentionui.css +1 -1
package/LICENSE.md
CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
|
|
2
2
|
==========================
|
3
3
|
|
4
4
|
**CKEditor 5 mention feature** – https://github.com/ckeditor/ckeditor5-mention <br>
|
5
|
-
Copyright (c) 2003-
|
5
|
+
Copyright (c) 2003-2022, [CKSource](http://cksource.com) Holding sp. z o.o. All rights reserved.
|
6
6
|
|
7
7
|
Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
|
8
8
|
|
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
|
|
14
14
|
Trademarks
|
15
15
|
----------
|
16
16
|
|
17
|
-
**CKEditor** is a trademark of [CKSource](http://cksource.com)
|
17
|
+
**CKEditor** is a trademark of [CKSource](http://cksource.com) Holding sp. z o.o. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
package/build/mention.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
/*!
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource - Frederico Knabben. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md.
|
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 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]}}}]);
|
4
|
+
*/(()=>{var e={677:(e,t,n)=>{"use strict";n.d(t,{Z:()=>r});var i=n(609),o=n.n(i)()((function(e){return e[1]}));o.push([e.id,":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)}",""]);const r=o},216:(e,t,n)=>{"use strict";n.d(t,{Z:()=>r});var i=n(609),o=n.n(i)()((function(e){return e[1]}));o.push([e.id,":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}",""]);const r=o},609: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,i){"string"==typeof e&&(e=[[null,e,""]]);var o={};if(i)for(var r=0;r<this.length;r++){var s=this[r][0];null!=s&&(o[s]=!0)}for(var a=0;a<e.length;a++){var c=[].concat(e[a]);i&&o[c[0]]||(n&&(c[2]?c[2]="".concat(n," and ").concat(c[2]):c[2]=n),t.push(c))}},t}},62:(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,l="".concat(c," ").concat(d);n[c]=d+1;var u=a(l),m={css:r[1],media:r[2],sourceMap:r[3]};-1!==u?(s[u].references++,s[u].updater(m)):s.push({identifier:l,updater:p(m,t),references:1}),i.push(l)}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 l,u=(l=[],function(e,t){return l[e]=t,l.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=u(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 h(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 f=null,g=0;function p(e,t){var n,i,o;if(t.singleton){var r=g++;n=f||(f=d(t)),i=m.bind(null,n,r,!1),o=m.bind(null,n,r,!0)}else n=d(t),i=h.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 l=a(n[d]);0===s[l].references&&(s[l].updater(),s.splice(l,1))}n=r}}}},704:(e,t,n)=>{e.exports=n(79)("./src/core.js")},181:(e,t,n)=>{e.exports=n(79)("./src/typing.js")},273:(e,t,n)=>{e.exports=n(79)("./src/ui.js")},209:(e,t,n)=>{e.exports=n(79)("./src/utils.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={id:i,exports:{}};return e[i](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 i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},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})};var i={};(()=>{"use strict";n.r(i),n.d(i,{Mention:()=>ae,MentionEditing:()=>r,MentionUI:()=>X});var e=n(704),t=n(209);class o extends e.Command{refresh(){const e=this.editor.model,t=e.document;this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"mention")}execute(e){const n=this.editor.model,i=n.document.selection,o="string"==typeof e.mention?{id:e.mention}:e.mention,r=o.id,a=e.range||i.getFirstRange(),c=e.text||r,d=s({_text:c,id:r},o);if(1!=e.marker.length)throw new t.CKEditorError("mentioncommand-incorrect-marker",this);if(r.charAt(0)!=e.marker)throw new t.CKEditorError("mentioncommand-incorrect-id",this);n.change((e=>{const o=(0,t.toMap)(i.getAttributes()),r=new Map(o.entries());r.set("mention",d),n.insertContent(e.createText(c,r),a),n.insertContent(e.createText(" ",o),a.start.getShiftedBy(c.length))}))}}class r extends e.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:d}),e.conversion.for("downcast").add(c),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=u(i.textNode,e)||o,o=u(t,e)||o,o=u(i.nodeBefore,e)||o,o=u(i.nodeAfter,e)||o}if("$text"!=t.name&&"insert"==t.type){const t=i.nodeAfter;for(const n of e.createRangeIn(t).getItems())o=u(n,e)||o}if("insert"==t.type&&n.isInline(t.name)){const t=i.nodeAfter&&i.nodeAfter.nextSibling;o=u(i.nodeBefore,e)||o,o=u(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 o(e))}}function s(e,n){return Object.assign({uid:(0,t.uid)()},e,n||{})}function a(e,t){const n=e.getAttribute("data-mention"),i=e.getChild(0);if(!i)return;return s({id:n,_text:i.data},t)}function c(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 d(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 u(e,t){return!!l(e)&&(t.removeAttribute("mention",e),!0)}var m=n(273),h=n(181);const f=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};const g="object"==typeof global&&global&&global.Object===Object&&global;var p="object"==typeof self&&self&&self.Object===Object&&self;const v=g||p||Function("return this")();const b=function(){return v.Date.now()};var w=/\s/;const x=function(e){for(var t=e.length;t--&&w.test(e.charAt(t)););return t};var y=/^\s+/;const k=function(e){return e?e.slice(0,x(e)+1).replace(y,""):e};const _=v.Symbol;var C=Object.prototype,A=C.hasOwnProperty,T=C.toString,I=_?_.toStringTag:void 0;const M=function(e){var t=A.call(e,I),n=e[I];try{e[I]=void 0;var i=!0}catch(e){}var o=T.call(e);return i&&(t?e[I]=n:delete e[I]),o};var R=Object.prototype.toString;const S=function(e){return R.call(e)};var V=_?_.toStringTag:void 0;const E=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":V&&V in Object(e)?M(e):S(e)};const j=function(e){return null!=e&&"object"==typeof e};const O=function(e){return"symbol"==typeof e||j(e)&&"[object Symbol]"==E(e)};var P=/^[-+]0x[0-9a-f]+$/i,N=/^0b[01]+$/i,U=/^0o[0-7]+$/i,F=parseInt;const B=function(e){if("number"==typeof e)return e;if(O(e))return NaN;if(f(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=f(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)?F(e.slice(2),n?2:8):P.test(e)?NaN:+e};var $=Math.max,q=Math.min;const L=function(e,t,n){var i,o,r,s,a,c,d=0,l=!1,u=!1,m=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function h(t){var n=i,r=o;return i=o=void 0,d=t,s=e.apply(r,n)}function g(e){return d=e,a=setTimeout(v,t),l?h(e):s}function p(e){var n=e-c;return void 0===c||n>=t||n<0||u&&e-d>=r}function v(){var e=b();if(p(e))return w(e);a=setTimeout(v,function(e){var n=t-(e-c);return u?q(n,r-(e-d)):n}(e))}function w(e){return a=void 0,m&&i?h(e):(i=o=void 0,s)}function x(){var e=b(),n=p(e);if(i=arguments,o=this,c=e,n){if(void 0===a)return g(c);if(u)return clearTimeout(a),a=setTimeout(v,t),h(c)}return void 0===a&&(a=setTimeout(v,t)),s}return t=B(t)||0,f(n)&&(l=!!n.leading,r=(u="maxWait"in n)?$(B(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:w(b())},x};var D=n(62),K=n.n(D),W=n(216),Z={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};K()(W.Z,Z);W.Z.locals;class H extends m.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 t.Rect(this.element).contains(new t.Rect(e.element))}}class J extends m.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 z extends m.ListItemView{highlight(){this.children.first.isOn=!0}removeHighlight(){this.children.first.isOn=!1}}const G=[t.keyCodes.arrowup,t.keyCodes.arrowdown,t.keyCodes.esc],Q=[t.keyCodes.enter,t.keyCodes.tab];class X extends e.Plugin{static get pluginName(){return"MentionUI"}static get requires(){return[m.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,n=e.config.get("mention.commitKeys")||Q,i=G.concat(n);this._balloon=e.plugins.get(m.ContextualBalloon),e.editing.view.document.on("keydown",((e,o)=>{var r;r=o.keyCode,i.includes(r)&&this._isUIVisible&&(o.preventDefault(),e.stop(),o.keyCode==t.keyCodes.arrowdown&&this._mentionsView.selectNext(),o.keyCode==t.keyCodes.arrowup&&this._mentionsView.selectPrevious(),n.includes(o.keyCode)&&this._mentionsView.executeSelected(),o.keyCode==t.keyCodes.esc&&this._hideUIAndRemoveMarker())}),{priority:"highest"}),(0,m.clickOutsideHandler)({emitter:this._mentionsView,activator:()=>this._isUIVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideUIAndRemoveMarker()});const o=e.config.get("mention.feeds");for(const e of o){const n=e.feed,i=e.marker;if(!ie(i))throw new t.CKEditorError("mentionconfig-incorrect-marker",null,{marker:i});const o={marker:i,feedCallback:"function"==typeof n?n.bind(this.editor):ne(n),itemRenderer:e.itemRenderer};this._mentionsConfigurations.set(i,o)}this._setupTextWatcher(o),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,n=new H(e);return this._items=new t.Collection,n.items.bindTo(this._items).using((t=>{const{item:i,marker:o}=t,r=this.editor.config.get("mention.dropdownLimit")||10;if(n.items.length>=r)return;const s=new z(e),a=this._renderItem(i,o);return a.delegate("execute").to(s),s.children.add(a),s.item=i,s.marker=o,s.on("execute",(()=>{n.fire("execute",{item:i,marker:o})})),s})),n.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()})),n}_getItemRenderer(e){const{itemRenderer:t}=this._mentionsConfigurations.get(e);return t}_requestFeed(e,n){this._lastRequested=n;const{feedCallback:i}=this._mentionsConfigurations.get(e),o=i(n);o instanceof Promise?o.then((t=>{this._lastRequested==n?this.fire("requestFeed:response",{feed:t,marker:e,feedText:n}):this.fire("requestFeed:discarded",{feed:t,marker:e,feedText:n})})).catch((n=>{this.fire("requestFeed:error",{error:n}),(0,t.logWarning)("mention-feed-callback-error",{marker:e})})):this.fire("requestFeed:response",{feed:o,marker:e,feedText:n})}_setupTextWatcher(e){const t=this.editor,n=e.map((e=>({...e,pattern:te(e.marker,e.minimumCharacters||0)}))),i=new h.TextWatcher(t.model,function(e){return t=>{const n=ee(e,t);if(!n)return!1;let i=0;0!==n.position&&(i=n.position-1);const o=t.substring(i);return n.pattern.test(o)}}(n));i.on("matched",((e,i)=>{const o=ee(n,i.text),r=t.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")}(r))return void this._hideUIAndRemoveMarker();const s=function(e,t){let n=0;0!==e.position&&(n=e.position-1);const i=te(e.marker,0),o=t.substring(n);return o.match(i)[2]}(o,i.text),a=o.marker.length+s.length,c=r.getShiftedBy(-a),d=r.getShiftedBy(-s.length),l=t.model.createRange(c,d);if(oe(t)){const e=t.model.markers.get("mention");t.model.change((t=>{t.updateMarker(e,{range:l})}))}else t.model.change((e=>{e.addMarker("mention",{range:l,usingOperation:!1,affectsData:!1})}));this._requestFeedDebounced(o.marker,s)})),i.on("unmatched",(()=>{this._hideUIAndRemoveMarker()}));const o=t.commands.get("mention");return i.bind("isEnabled").to(o),i}_handleFeedResponse(e){const{feed:t,marker:n}=e;if(!oe(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),oe(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 J(n.locale,t):o=t}if(!i){const e=new m.ButtonView(n.locale);e.label=o,e.withText=!0,i=e}return i}_getBalloonPanelPositionData(e,n){const i=this.editor,o=i.editing,r=o.view.domConverter,s=o.mapper;return{target:()=>{let n=e.getRange();"$graveyard"==n.start.root.rootName&&(n=i.model.document.selection.getFirstRange());const o=s.toViewRange(n);return t.Rect.getDomRangeRects(r.viewRangeToDom(o)).pop()},limiter:()=>{const e=this.editor.editing.view,t=e.document.selection.editableElement;return t?e.domConverter.mapViewToDom(t.root):null},positions:Y(n)}}}function Y(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 ee(e,t){let n;for(const i of e){const e=t.lastIndexOf(i.marker);e>0&&!t.substring(e-1).match(i.pattern)||(!n||e>=n.position)&&(n={marker:i.marker,position:e,minimumCharacters:i.minimumCharacters,pattern:i.pattern})}return n}function te(e,n){const i=0==n?"*":`{${n},}`,o=t.env.features.isRegExpUnicodePropertySupported?"\\p{Ps}\\p{Pi}\"'":"\\(\\[{\"'";return new RegExp(`(?:^|[ ${o}])([${e}])(.${i})$`,"u")}function ne(e){return t=>e.filter((e=>("string"==typeof e?e:String(e.id)).toLowerCase().includes(t.toLowerCase())))}function ie(e){return e&&1==e.length}function oe(e){return e.model.markers.has("mention")}var re=n(677),se={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};K()(re.Z,se);re.Z.locals;class ae extends e.Plugin{toMentionAttribute(e,t){return a(e,t)}static get pluginName(){return"Mention"}static get requires(){return[r,X]}}})(),(window.CKEditor5=window.CKEditor5||{}).mention=i})();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-mention",
|
3
|
-
"version": "
|
3
|
+
"version": "32.0.0",
|
4
4
|
"description": "Mention feature for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -12,33 +12,33 @@
|
|
12
12
|
],
|
13
13
|
"main": "src/index.js",
|
14
14
|
"dependencies": {
|
15
|
-
"ckeditor5": "^
|
15
|
+
"ckeditor5": "^32.0.0",
|
16
16
|
"lodash-es": "^4.17.15"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"@ckeditor/ckeditor5-basic-styles": "^
|
20
|
-
"@ckeditor/ckeditor5-block-quote": "^
|
21
|
-
"@ckeditor/ckeditor5-clipboard": "^
|
22
|
-
"@ckeditor/ckeditor5-core": "^
|
23
|
-
"@ckeditor/ckeditor5-dev-utils": "^
|
24
|
-
"@ckeditor/ckeditor5-editor-classic": "^
|
25
|
-
"@ckeditor/ckeditor5-engine": "^
|
26
|
-
"@ckeditor/ckeditor5-font": "^
|
27
|
-
"@ckeditor/ckeditor5-link": "^
|
28
|
-
"@ckeditor/ckeditor5-paragraph": "^
|
29
|
-
"@ckeditor/ckeditor5-table": "^
|
30
|
-
"@ckeditor/ckeditor5-theme-lark": "^
|
31
|
-
"@ckeditor/ckeditor5-typing": "^
|
32
|
-
"@ckeditor/ckeditor5-ui": "^
|
33
|
-
"@ckeditor/ckeditor5-undo": "^
|
34
|
-
"@ckeditor/ckeditor5-utils": "^
|
35
|
-
"@ckeditor/ckeditor5-widget": "^
|
19
|
+
"@ckeditor/ckeditor5-basic-styles": "^32.0.0",
|
20
|
+
"@ckeditor/ckeditor5-block-quote": "^32.0.0",
|
21
|
+
"@ckeditor/ckeditor5-clipboard": "^32.0.0",
|
22
|
+
"@ckeditor/ckeditor5-core": "^32.0.0",
|
23
|
+
"@ckeditor/ckeditor5-dev-utils": "^27.1.0",
|
24
|
+
"@ckeditor/ckeditor5-editor-classic": "^32.0.0",
|
25
|
+
"@ckeditor/ckeditor5-engine": "^32.0.0",
|
26
|
+
"@ckeditor/ckeditor5-font": "^32.0.0",
|
27
|
+
"@ckeditor/ckeditor5-link": "^32.0.0",
|
28
|
+
"@ckeditor/ckeditor5-paragraph": "^32.0.0",
|
29
|
+
"@ckeditor/ckeditor5-table": "^32.0.0",
|
30
|
+
"@ckeditor/ckeditor5-theme-lark": "^32.0.0",
|
31
|
+
"@ckeditor/ckeditor5-typing": "^32.0.0",
|
32
|
+
"@ckeditor/ckeditor5-ui": "^32.0.0",
|
33
|
+
"@ckeditor/ckeditor5-undo": "^32.0.0",
|
34
|
+
"@ckeditor/ckeditor5-utils": "^32.0.0",
|
35
|
+
"@ckeditor/ckeditor5-widget": "^32.0.0",
|
36
36
|
"lodash": "^4.17.15",
|
37
|
-
"webpack": "^
|
38
|
-
"webpack-cli": "^
|
37
|
+
"webpack": "^5.58.1",
|
38
|
+
"webpack-cli": "^4.9.0"
|
39
39
|
},
|
40
40
|
"engines": {
|
41
|
-
"node": ">=
|
41
|
+
"node": ">=14.0.0",
|
42
42
|
"npm": ">=5.7.1"
|
43
43
|
},
|
44
44
|
"author": "CKSource (http://cksource.com/)",
|
package/src/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/src/mention.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/src/mentioncommand.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/src/mentionediting.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/src/mentionui.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
@@ -160,16 +160,14 @@ export default class MentionUI extends Plugin {
|
|
160
160
|
throw new CKEditorError( 'mentionconfig-incorrect-marker', null, { marker } );
|
161
161
|
}
|
162
162
|
|
163
|
-
const minimumCharacters = mentionDescription.minimumCharacters || 0;
|
164
163
|
const feedCallback = typeof feed == 'function' ? feed.bind( this.editor ) : createFeedCallback( feed );
|
165
|
-
const watcher = this._setupTextWatcherForFeed( marker, minimumCharacters );
|
166
164
|
const itemRenderer = mentionDescription.itemRenderer;
|
167
|
-
|
168
|
-
const definition = { watcher, marker, feedCallback, itemRenderer };
|
165
|
+
const definition = { marker, feedCallback, itemRenderer };
|
169
166
|
|
170
167
|
this._mentionsConfigurations.set( marker, definition );
|
171
168
|
}
|
172
169
|
|
170
|
+
this._setupTextWatcher( feeds );
|
173
171
|
this.listenTo( editor, 'change:isReadOnly', () => {
|
174
172
|
this._hideUIAndRemoveMarker();
|
175
173
|
} );
|
@@ -373,16 +371,21 @@ export default class MentionUI extends Plugin {
|
|
373
371
|
* Registers a text watcher for the marker.
|
374
372
|
*
|
375
373
|
* @private
|
376
|
-
* @param {
|
377
|
-
* @param {Number} minimumCharacters
|
374
|
+
* @param {Array.<Object>} feeds Feeds of mention plugin configured in editor
|
378
375
|
* @returns {module:typing/textwatcher~TextWatcher}
|
379
376
|
*/
|
380
|
-
|
377
|
+
_setupTextWatcher( feeds ) {
|
381
378
|
const editor = this.editor;
|
382
379
|
|
383
|
-
const
|
380
|
+
const feedsWithPattern = feeds.map( feed => ( {
|
381
|
+
...feed,
|
382
|
+
pattern: createRegExp( feed.marker, feed.minimumCharacters || 0 )
|
383
|
+
} ) );
|
384
|
+
|
385
|
+
const watcher = new TextWatcher( editor.model, createTestCallback( feedsWithPattern ) );
|
384
386
|
|
385
387
|
watcher.on( 'matched', ( evt, data ) => {
|
388
|
+
const markerDefinition = getLastValidMarkerInText( feedsWithPattern, data.text );
|
386
389
|
const selection = editor.model.document.selection;
|
387
390
|
const focus = selection.focus;
|
388
391
|
|
@@ -392,8 +395,8 @@ export default class MentionUI extends Plugin {
|
|
392
395
|
return;
|
393
396
|
}
|
394
397
|
|
395
|
-
const feedText = requestFeedText(
|
396
|
-
const matchedTextLength = marker.length + feedText.length;
|
398
|
+
const feedText = requestFeedText( markerDefinition, data.text );
|
399
|
+
const matchedTextLength = markerDefinition.marker.length + feedText.length;
|
397
400
|
|
398
401
|
// Create a marker range.
|
399
402
|
const start = focus.getShiftedBy( -matchedTextLength );
|
@@ -414,7 +417,7 @@ export default class MentionUI extends Plugin {
|
|
414
417
|
} );
|
415
418
|
}
|
416
419
|
|
417
|
-
this._requestFeedDebounced( marker, feedText );
|
420
|
+
this._requestFeedDebounced( markerDefinition.marker, feedText );
|
418
421
|
} );
|
419
422
|
|
420
423
|
watcher.on( 'unmatched', () => {
|
@@ -655,6 +658,43 @@ function getBalloonPanelPositions( preferredPosition ) {
|
|
655
658
|
];
|
656
659
|
}
|
657
660
|
|
661
|
+
// Returns a marker definition of the last valid occuring marker in given string.
|
662
|
+
// If there is no valid marker in string it returns undefined.
|
663
|
+
//
|
664
|
+
// Example of returned object:
|
665
|
+
//
|
666
|
+
// {
|
667
|
+
// marker: '@',
|
668
|
+
// position: 4,
|
669
|
+
// minimumCharacters: 0
|
670
|
+
// }
|
671
|
+
//
|
672
|
+
// @param {Array.<Object>} feedsWithPattern Registered feeds in editor for mention plugin with created RegExp for matching marker.
|
673
|
+
// @param {String} text String to find marker in
|
674
|
+
// @returns {Object} Matched marker's definition
|
675
|
+
function getLastValidMarkerInText( feedsWithPattern, text ) {
|
676
|
+
let lastValidMarker;
|
677
|
+
|
678
|
+
for ( const feed of feedsWithPattern ) {
|
679
|
+
const currentMarkerLastIndex = text.lastIndexOf( feed.marker );
|
680
|
+
|
681
|
+
if ( currentMarkerLastIndex > 0 && !text.substring( currentMarkerLastIndex - 1 ).match( feed.pattern ) ) {
|
682
|
+
continue;
|
683
|
+
}
|
684
|
+
|
685
|
+
if ( !lastValidMarker || currentMarkerLastIndex >= lastValidMarker.position ) {
|
686
|
+
lastValidMarker = {
|
687
|
+
marker: feed.marker,
|
688
|
+
position: currentMarkerLastIndex,
|
689
|
+
minimumCharacters: feed.minimumCharacters,
|
690
|
+
pattern: feed.pattern
|
691
|
+
};
|
692
|
+
}
|
693
|
+
}
|
694
|
+
|
695
|
+
return lastValidMarker;
|
696
|
+
}
|
697
|
+
|
658
698
|
// Creates a RegExp pattern for the marker.
|
659
699
|
//
|
660
700
|
// Function has to be exported to achieve 100% code coverage.
|
@@ -666,7 +706,7 @@ export function createRegExp( marker, minimumCharacters ) {
|
|
666
706
|
const numberOfCharacters = minimumCharacters == 0 ? '*' : `{${ minimumCharacters },}`;
|
667
707
|
|
668
708
|
const openAfterCharacters = env.features.isRegExpUnicodePropertySupported ? '\\p{Ps}\\p{Pi}"\'' : '\\(\\[{"\'';
|
669
|
-
const mentionCharacters = '
|
709
|
+
const mentionCharacters = '.';
|
670
710
|
|
671
711
|
// The pattern consists of 3 groups:
|
672
712
|
// - 0 (non-capturing): Opening sequence - start of the line, space or an opening punctuation character like "(" or "\"",
|
@@ -674,31 +714,52 @@ export function createRegExp( marker, minimumCharacters ) {
|
|
674
714
|
// - 2: Mention input (taking the minimal length into consideration to trigger the UI),
|
675
715
|
//
|
676
716
|
// The pattern matches up to the caret (end of string switch - $).
|
677
|
-
// (0: opening sequence )(1:
|
678
|
-
const pattern = `(?:^|[ ${ openAfterCharacters }])([${ marker }])(
|
679
|
-
|
717
|
+
// (0: opening sequence )(1: marker )(2: typed mention )$
|
718
|
+
const pattern = `(?:^|[ ${ openAfterCharacters }])([${ marker }])(${ mentionCharacters }${ numberOfCharacters })$`;
|
680
719
|
return new RegExp( pattern, 'u' );
|
681
720
|
}
|
682
721
|
|
683
722
|
// Creates a test callback for the marker to be used in the text watcher instance.
|
684
723
|
//
|
685
|
-
// @param {
|
686
|
-
// @param {Number} minimumCharacters
|
724
|
+
// @param {Array.<Object>} feedsWithPattern Feeds of mention plugin configured in editor with RegExp to match marker in text
|
687
725
|
// @returns {Function}
|
688
|
-
function createTestCallback(
|
689
|
-
const
|
726
|
+
function createTestCallback( feedsWithPattern ) {
|
727
|
+
const textMatcher = text => {
|
728
|
+
const markerDefinition = getLastValidMarkerInText( feedsWithPattern, text );
|
690
729
|
|
691
|
-
|
730
|
+
if ( !markerDefinition ) {
|
731
|
+
return false;
|
732
|
+
}
|
733
|
+
|
734
|
+
let splitStringFrom = 0;
|
735
|
+
|
736
|
+
if ( markerDefinition.position !== 0 ) {
|
737
|
+
splitStringFrom = markerDefinition.position - 1;
|
738
|
+
}
|
739
|
+
|
740
|
+
const textToTest = text.substring( splitStringFrom );
|
741
|
+
|
742
|
+
return markerDefinition.pattern.test( textToTest );
|
743
|
+
};
|
744
|
+
|
745
|
+
return textMatcher;
|
692
746
|
}
|
693
747
|
|
694
748
|
// Creates a text matcher from the marker.
|
695
749
|
//
|
696
|
-
// @param {
|
750
|
+
// @param {Object} markerDefinition
|
751
|
+
// @param {String} text
|
697
752
|
// @returns {Function}
|
698
|
-
function requestFeedText(
|
699
|
-
|
753
|
+
function requestFeedText( markerDefinition, text ) {
|
754
|
+
let splitStringFrom = 0;
|
755
|
+
|
756
|
+
if ( markerDefinition.position !== 0 ) {
|
757
|
+
splitStringFrom = markerDefinition.position - 1;
|
758
|
+
}
|
700
759
|
|
701
|
-
const
|
760
|
+
const regExp = createRegExp( markerDefinition.marker, 0 );
|
761
|
+
const textToMatch = text.substring( splitStringFrom );
|
762
|
+
const match = textToMatch.match( regExp );
|
702
763
|
|
703
764
|
return match[ 2 ];
|
704
765
|
}
|
package/src/ui/domwrapperview.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/src/ui/mentionsview.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
5
|
|
package/theme/mention.css
CHANGED
package/theme/mentionui.css
CHANGED