Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quill-mention

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quill-mention - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

2

dist/quill.mention.min.js

@@ -1,1 +0,1 @@

!function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(t,e){t.exports=Quill},function(t,e,n){"use strict";var i,o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),s=(i=n(0))&&i.__esModule?i:{default:i},a=s.default.import("blots/embed"),r=function(t){function e(){return function(t,n){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,a),o(e,null,[{key:"create",value:function(t){var n=function t(e,n,i){null===e&&(e=Function.prototype);var o=Object.getOwnPropertyDescriptor(e,n);if(void 0===o){var s=Object.getPrototypeOf(e);return null===s?void 0:t(s,n,i)}if("value"in o)return o.value;var a=o.get;return void 0!==a?a.call(i):void 0}(e.__proto__||Object.getPrototypeOf(e),"create",this).call(this),i=document.createElement("span");return i.className="ql-mention-denotation-char",i.innerHTML=t.denotationChar,n.appendChild(i),n.innerHTML+=t.value,n.dataset.id=t.id,n.dataset.value=t.value,n.dataset.denotationChar=t.denotationChar,t.link&&(n.dataset.link=t.link),n}},{key:"value",value:function(t){return{id:t.dataset.id,value:t.dataset.value,link:t.dataset.link||null,denotationChar:t.dataset.denotationChar}}}]),e}();r.blotName="mention",r.tagName="span",r.className="mention",s.default.register(r)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40}},function(t,e,n){"use strict";var i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),s=r(n(0)),a=r(n(2));function r(t){return t&&t.__esModule?t:{default:t}}n(6),n(1);var l=function(){function t(e,n){!function(e,n){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.quill=e,this.options={source:null,renderItem:function(t,e){return""+t.value},mentionDenotationChars:["@"],allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1},i(this.options,n),this.mentionContainer=document.createElement("div"),this.mentionContainer.className="ql-mention-list-container",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionContainer.onmousemove=this.onContainerMouseMove.bind(this),this.options.fixMentionsToQuill&&(this.mentionContainer.style.width="auto"),this.mentionList=document.createElement("ul"),this.mentionList.className="ql-mention-list",this.mentionContainer.appendChild(this.mentionList),document.body.appendChild(this.mentionContainer),e.on("text-change",this.onTextChange.bind(this)),e.on("selection-change",this.onSelectionChange.bind(this)),e.keyboard.addBinding({key:a.default.TAB},this.selectHandler.bind(this)),e.keyboard.bindings[9].unshift(e.keyboard.bindings[9].pop()),e.keyboard.addBinding({key:a.default.ENTER},this.selectHandler.bind(this)),e.keyboard.bindings[13].unshift(e.keyboard.bindings[13].pop()),e.keyboard.addBinding({key:a.default.ESCAPE},this.escapeHandler.bind(this)),e.keyboard.addBinding({key:a.default.UP},this.upHandler.bind(this)),e.keyboard.addBinding({key:a.default.DOWN},this.downHandler.bind(this))}return o(t,[{key:"selectHandler",value:function(){return!this.isOpen||(this.selectItem(),!1)}},{key:"escapeHandler",value:function(){return!this.isOpen||(this.hideMentionList(),!1)}},{key:"upHandler",value:function(){return!this.isOpen||(this.prevItem(),!1)}},{key:"downHandler",value:function(){return!this.isOpen||(this.nextItem(),!1)}},{key:"showMentionList",value:function(){this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.setMentionContainerPosition(),this.isOpen=!0}},{key:"hideMentionList",value:function(){this.mentionContainer.style.display="none",this.isOpen=!1}},{key:"highlightItem",value:function(){for(var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=0;e<this.mentionList.childNodes.length;e+=1)this.mentionList.childNodes[e].classList.remove("selected");if(this.mentionList.childNodes[this.itemIndex].classList.add("selected"),t){var n=this.mentionList.childNodes[this.itemIndex].offsetHeight,i=this.itemIndex*n,o=this.mentionContainer.scrollTop,s=o+this.mentionContainer.offsetHeight;i<o?this.mentionContainer.scrollTop=i:i>s-n&&(this.mentionContainer.scrollTop+=i-s+n)}}},{key:"getItemData",value:function(){var t=this.mentionList.childNodes[this.itemIndex].dataset.link;return{id:this.mentionList.childNodes[this.itemIndex].dataset.id,value:t?'<a href="'+t+'" target="_blank">'+this.mentionList.childNodes[this.itemIndex].dataset.value:this.mentionList.childNodes[this.itemIndex].dataset.value,link:t||null,denotationChar:this.mentionList.childNodes[this.itemIndex].dataset.denotationChar}}},{key:"onContainerMouseMove",value:function(){this.suspendMouseEnter=!1}},{key:"selectItem",value:function(){var t=this.getItemData();this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,s.default.sources.API),this.quill.insertEmbed(this.mentionCharPos,"mention",t,s.default.sources.API),this.quill.insertText(this.mentionCharPos+1," ",s.default.sources.API),this.quill.setSelection(this.mentionCharPos+2,s.default.sources.API),this.hideMentionList()}},{key:"onItemMouseEnter",value:function(t){if(!this.suspendMouseEnter){var e=Number(t.target.dataset.index);Number.isNaN(e)||e===this.itemIndex||(this.itemIndex=e,this.highlightItem(!1))}}},{key:"onItemClick",value:function(t){t.stopImmediatePropagation(),t.preventDefault(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}},{key:"renderList",value:function(t,e,n){if(e&&e.length>0){this.values=e,this.mentionList.innerHTML="";for(var i=0;i<e.length;i+=1){var o=document.createElement("li");o.className="ql-mention-list-item",o.dataset.index=i,o.dataset.id=e[i].id,o.dataset.value=e[i].value,o.dataset.denotationChar=t,e[i].link&&(o.dataset.link=e[i].link),o.innerHTML=this.options.renderItem(e[i],n),o.onmouseenter=this.onItemMouseEnter.bind(this),o.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(o)}this.itemIndex=0,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}},{key:"nextItem",value:function(){this.itemIndex=(this.itemIndex+1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"prevItem",value:function(){this.itemIndex=(this.itemIndex+this.values.length-1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"hasValidChars",value:function(t){return this.options.allowedChars.test(t)}},{key:"containerBottomIsNotVisible",value:function(t){return t+this.mentionContainer.offsetHeight>window.pageYOffset+window.innerHeight}},{key:"containerRightIsNotVisible",value:function(t){return!this.options.fixMentionsToQuill&&t+this.mentionContainer.offsetWidth>window.pageXOffset+document.documentElement.clientWidth}},{key:"setMentionContainerPosition",value:function(){var t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.mentionCharPos),n=window.pageYOffset+this.options.offsetTop,i=window.pageXOffset+t.left+this.options.offsetLeft;if(this.options.fixMentionsToQuill){n+=t.bottom;var o=window.outerWidth-t.right;this.mentionContainer.style.right=o+"px"}else i+=e.left,n+=t.top+e.bottom;if(this.containerBottomIsNotVisible(n)){var s=this.mentionContainer.offsetHeight+this.options.offsetTop,a=window.pageYOffset+t.top;this.options.fixMentionsToQuill||(a+=e.top),n=a-s}if(this.containerRightIsNotVisible(i)){var r=this.mentionContainer.offsetWidth+this.options.offsetLeft;i=window.pageXOffset+document.documentElement.clientWidth-r}this.mentionContainer.style.top=n+"px",this.mentionContainer.style.left=i+"px",this.mentionContainer.style.visibility="visible"}},{key:"onSomethingChange",value:function(){var t=this.quill.getSelection();if(null!=t){this.cursorPos=t.index;var e=Math.max(0,this.cursorPos-this.options.maxChars),n=this.quill.getText(e,this.cursorPos-e),i=this.options.mentionDenotationChars.reduce(function(t,e){var i=t,o=n.lastIndexOf(e);return o>i?o:i},-1);if(i>-1){if(this.options.isolateCharacter&&0!=i&&!n[i-1].match(/\s/g))return void this.hideMentionList();var o=this.cursorPos-(n.length-i);this.mentionCharPos=o;var s=n.substring(i+1);if(s.length>=this.options.minChars&&this.hasValidChars(s)){var a=n[i];this.options.source(s,this.renderList.bind(this,a),a)}else this.hideMentionList()}else this.hideMentionList()}}},{key:"onTextChange",value:function(t,e,n){"user"===n&&this.onSomethingChange()}},{key:"onSelectionChange",value:function(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}}]),t}();s.default.register("modules/mention",l)},function(t,e,n){t.exports=n(3)},,function(t,e){}]);
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=4)}([function(t,e){t.exports=Quill},function(t,e,i){"use strict";var n,o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),s=(n=i(0))&&n.__esModule?n:{default:n},a=s.default.import("blots/embed"),r=function(t){function e(){return function(t,i){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,a),o(e,null,[{key:"create",value:function(t){var i=function t(e,i,n){null===e&&(e=Function.prototype);var o=Object.getOwnPropertyDescriptor(e,i);if(void 0===o){var s=Object.getPrototypeOf(e);return null===s?void 0:t(s,i,n)}if("value"in o)return o.value;var a=o.get;return void 0!==a?a.call(n):void 0}(e.__proto__||Object.getPrototypeOf(e),"create",this).call(this),n=document.createElement("span");return n.className="ql-mention-denotation-char",n.innerHTML=t.denotationChar,i.appendChild(n),i.innerHTML+=t.value,i.dataset.id=t.id,i.dataset.value=t.value,i.dataset.denotationChar=t.denotationChar,t.link&&(i.dataset.link=t.link),i}},{key:"value",value:function(t){return{id:t.dataset.id,value:t.dataset.value,link:t.dataset.link||null,denotationChar:t.dataset.denotationChar}}}]),e}();r.blotName="mention",r.tagName="span",r.className="mention",s.default.register(r)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40}},function(t,e,i){"use strict";var n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),s=r(i(0)),a=r(i(2));function r(t){return t&&t.__esModule?t:{default:t}}i(6),i(1);var l=function(){function t(e,i){!function(e,i){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.quill=e,this.options={source:null,renderItem:function(t,e){return""+t.value},mentionDenotationChars:["@"],allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1,defaultMenuOrientation:"bottom"},n(this.options,i),this.mentionContainer=document.createElement("div"),this.mentionContainer.className="ql-mention-list-container",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionContainer.onmousemove=this.onContainerMouseMove.bind(this),this.options.fixMentionsToQuill&&(this.mentionContainer.style.width="auto"),this.mentionList=document.createElement("ul"),this.mentionList.className="ql-mention-list",this.mentionContainer.appendChild(this.mentionList),this.quill.container.appendChild(this.mentionContainer),e.on("text-change",this.onTextChange.bind(this)),e.on("selection-change",this.onSelectionChange.bind(this)),e.keyboard.addBinding({key:a.default.TAB},this.selectHandler.bind(this)),e.keyboard.bindings[9].unshift(e.keyboard.bindings[9].pop()),e.keyboard.addBinding({key:a.default.ENTER},this.selectHandler.bind(this)),e.keyboard.bindings[13].unshift(e.keyboard.bindings[13].pop()),e.keyboard.addBinding({key:a.default.ESCAPE},this.escapeHandler.bind(this)),e.keyboard.addBinding({key:a.default.UP},this.upHandler.bind(this)),e.keyboard.addBinding({key:a.default.DOWN},this.downHandler.bind(this))}return o(t,[{key:"selectHandler",value:function(){return!this.isOpen||(this.selectItem(),!1)}},{key:"escapeHandler",value:function(){return!this.isOpen||(this.hideMentionList(),!1)}},{key:"upHandler",value:function(){return!this.isOpen||(this.prevItem(),!1)}},{key:"downHandler",value:function(){return!this.isOpen||(this.nextItem(),!1)}},{key:"showMentionList",value:function(){this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.setMentionContainerPosition(),this.isOpen=!0}},{key:"hideMentionList",value:function(){this.mentionContainer.style.display="none",this.isOpen=!1}},{key:"highlightItem",value:function(){for(var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=0;e<this.mentionList.childNodes.length;e+=1)this.mentionList.childNodes[e].classList.remove("selected");if(this.mentionList.childNodes[this.itemIndex].classList.add("selected"),t){var i=this.mentionList.childNodes[this.itemIndex].offsetHeight,n=this.itemIndex*i,o=this.mentionContainer.scrollTop,s=o+this.mentionContainer.offsetHeight;n<o?this.mentionContainer.scrollTop=n:n>s-i&&(this.mentionContainer.scrollTop+=n-s+i)}}},{key:"getItemData",value:function(){var t=this.mentionList.childNodes[this.itemIndex].dataset.link;return{id:this.mentionList.childNodes[this.itemIndex].dataset.id,value:t?'<a href="'+t+'" target="_blank">'+this.mentionList.childNodes[this.itemIndex].dataset.value:this.mentionList.childNodes[this.itemIndex].dataset.value,link:t||null,denotationChar:this.mentionList.childNodes[this.itemIndex].dataset.denotationChar}}},{key:"onContainerMouseMove",value:function(){this.suspendMouseEnter=!1}},{key:"selectItem",value:function(){var t=this.getItemData();this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,s.default.sources.API),this.quill.insertEmbed(this.mentionCharPos,"mention",t,s.default.sources.API),this.quill.insertText(this.mentionCharPos+1," ",s.default.sources.API),this.quill.setSelection(this.mentionCharPos+2,s.default.sources.API),this.hideMentionList()}},{key:"onItemMouseEnter",value:function(t){if(!this.suspendMouseEnter){var e=Number(t.target.dataset.index);Number.isNaN(e)||e===this.itemIndex||(this.itemIndex=e,this.highlightItem(!1))}}},{key:"onItemClick",value:function(t){t.stopImmediatePropagation(),t.preventDefault(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}},{key:"renderList",value:function(t,e,i){if(e&&e.length>0){this.values=e,this.mentionList.innerHTML="";for(var n=0;n<e.length;n+=1){var o=document.createElement("li");o.className="ql-mention-list-item",o.dataset.index=n,o.dataset.id=e[n].id,o.dataset.value=e[n].value,o.dataset.denotationChar=t,e[n].link&&(o.dataset.link=e[n].link),o.innerHTML=this.options.renderItem(e[n],i),o.onmouseenter=this.onItemMouseEnter.bind(this),o.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(o)}this.itemIndex=0,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}},{key:"nextItem",value:function(){this.itemIndex=(this.itemIndex+1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"prevItem",value:function(){this.itemIndex=(this.itemIndex+this.values.length-1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"hasValidChars",value:function(t){return this.options.allowedChars.test(t)}},{key:"containerBottomIsNotVisible",value:function(t,e){return t+this.mentionContainer.offsetHeight+e.top>window.pageYOffset+window.innerHeight}},{key:"containerRightIsNotVisible",value:function(t,e){return!this.options.fixMentionsToQuill&&t+this.mentionContainer.offsetWidth+e.left>window.pageXOffset+document.documentElement.clientWidth}},{key:"setMentionContainerPosition",value:function(){var t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.mentionCharPos),i=this.mentionContainer.offsetHeight,n=this.options.offsetTop,o=this.options.offsetLeft;if(this.options.fixMentionsToQuill?this.mentionContainer.style.right="0px":o+=e.left,this.containerRightIsNotVisible(o,t)){var s=this.mentionContainer.offsetWidth+this.options.offsetLeft;o=t.width-s}if("top"===this.options.defaultMenuOrientation){if((n=this.options.fixMentionsToQuill?-1*(i+this.options.offsetTop):e.top-(i+this.options.offsetTop))+t.top<=0){var a=this.options.offsetTop;this.options.fixMentionsToQuill?a+=t.height:a+=e.bottom,n=a}}else if(this.options.fixMentionsToQuill?n+=t.height:n+=e.bottom,this.containerBottomIsNotVisible(n,t)){var r=-1*this.options.offsetTop;this.options.fixMentionsToQuill||(r+=e.top),n=r-i}this.mentionContainer.style.top=n+"px",this.mentionContainer.style.left=o+"px",this.mentionContainer.style.visibility="visible"}},{key:"onSomethingChange",value:function(){var t=this.quill.getSelection();if(null!=t){this.cursorPos=t.index;var e=Math.max(0,this.cursorPos-this.options.maxChars),i=this.quill.getText(e,this.cursorPos-e),n=this.options.mentionDenotationChars.reduce(function(t,e){var n=t,o=i.lastIndexOf(e);return o>n?o:n},-1);if(n>-1){if(this.options.isolateCharacter&&0!=n&&!i[n-1].match(/\s/g))return void this.hideMentionList();var o=this.cursorPos-(i.length-n);this.mentionCharPos=o;var s=i.substring(n+1);if(s.length>=this.options.minChars&&this.hasValidChars(s)){var a=i[n];this.options.source(s,this.renderList.bind(this,a),a)}else this.hideMentionList()}else this.hideMentionList()}}},{key:"onTextChange",value:function(t,e,i){"user"===i&&this.onSomethingChange()}},{key:"onSelectionChange",value:function(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}}]),t}();s.default.register("modules/mention",l)},function(t,e,i){t.exports=i(3)},,function(t,e){}]);
{
"name": "quill-mention",
"version": "2.0.3",
"version": "2.0.4",
"description": "@mentions for the Quill rich text editor",

@@ -5,0 +5,0 @@ "main": "src/quill.mention.js",

@@ -75,2 +75,3 @@ ![Quill Mention](static/quill-mention.png "Quill Mention")

| `fixMentionsToQuill` | `false` | When set to true, the mentions menu will be rendered above or below the quill container. Otherwise, the mentions menu will track the denotation character(s);
| `defaultMenuOrientation` | `'bottom'` | Options are `'bottom'` and `'top'`. Determines what the default orientation of the menu will be. Quill-mention will attempt to render the menu either above or below the editor. If `'top'` is provided as a value, and there is not enough space above the editor, the menu will be rendered below. Vice versa, if there is not enough space below the editor, and `'bottom'` is provided as a value (or no value is provided at all), the menu will be rendered above the editor.

@@ -77,0 +78,0 @@

@@ -31,2 +31,3 @@ import Quill from 'quill';

fixMentionsToQuill: false,
defaultMenuOrientation: 'bottom',
};

@@ -49,3 +50,3 @@

document.body.appendChild(this.mentionContainer);
this.quill.container.appendChild(this.mentionContainer);

@@ -234,7 +235,8 @@ quill.on('text-change', this.onTextChange.bind(this));

containerBottomIsNotVisible(topPos) {
return topPos + this.mentionContainer.offsetHeight > window.pageYOffset + window.innerHeight;
containerBottomIsNotVisible(topPos, containerPos) {
const mentionContainerBottom = topPos + this.mentionContainer.offsetHeight + containerPos.top;
return mentionContainerBottom > window.pageYOffset + window.innerHeight;
}
containerRightIsNotVisible(leftPos) {
containerRightIsNotVisible(leftPos, containerPos) {
if (this.options.fixMentionsToQuill) {

@@ -244,3 +246,3 @@ return false;

const rightPos = leftPos + this.mentionContainer.offsetWidth;
const rightPos = leftPos + this.mentionContainer.offsetWidth + containerPos.left;
const browserWidth = window.pageXOffset + document.documentElement.clientWidth;

@@ -253,34 +255,60 @@ return rightPos > browserWidth;

const mentionCharPos = this.quill.getBounds(this.mentionCharPos);
const containerHeight = this.mentionContainer.offsetHeight;
let topPos = window.pageYOffset +
this.options.offsetTop;
let topPos = this.options.offsetTop;
let leftPos = this.options.offsetLeft;
let leftPos = window.pageXOffset +
containerPos.left +
this.options.offsetLeft;
// handle horizontal positioning
if (this.options.fixMentionsToQuill) {
topPos += containerPos.bottom;
const rightPos = window.outerWidth - containerPos.right;
const rightPos = 0;
this.mentionContainer.style.right = `${rightPos}px`;
} else {
leftPos += mentionCharPos.left;
topPos += containerPos.top + mentionCharPos.bottom;
}
if (this.containerBottomIsNotVisible(topPos)) {
const containerHeight = this.mentionContainer.offsetHeight + this.options.offsetTop;
let overMentionCharPos = window.pageYOffset + containerPos.top;
if (this.containerRightIsNotVisible(leftPos, containerPos)) {
const containerWidth = this.mentionContainer.offsetWidth + this.options.offsetLeft;
const quillWidth = containerPos.width;
leftPos = quillWidth - containerWidth;
}
if (!this.options.fixMentionsToQuill) {
overMentionCharPos += mentionCharPos.top;
// handle vertical positioning
if (this.options.defaultMenuOrientation === 'top') {
// Attempt to align the mention container with the top of the quill editor
if (this.options.fixMentionsToQuill) {
topPos = -1 * (containerHeight + this.options.offsetTop);
} else {
topPos = mentionCharPos.top - (containerHeight + this.options.offsetTop);
}
topPos = overMentionCharPos - containerHeight;
}
// default to bottom if the top is not visible
if (topPos + containerPos.top <= 0) {
let overMentionCharPos = this.options.offsetTop;
if (this.containerRightIsNotVisible(leftPos)) {
const containerWidth = this.mentionContainer.offsetWidth + this.options.offsetLeft;
const browserWidth = window.pageXOffset + document.documentElement.clientWidth;
leftPos = browserWidth - containerWidth;
if (this.options.fixMentionsToQuill) {
overMentionCharPos += containerPos.height;
} else {
overMentionCharPos += mentionCharPos.bottom;
}
topPos = overMentionCharPos;
}
} else {
// Attempt to align the mention container with the bottom of the quill editor
if (this.options.fixMentionsToQuill) {
topPos += containerPos.height;
} else {
topPos += mentionCharPos.bottom;
}
// default to the top if the bottom is not visible
if (this.containerBottomIsNotVisible(topPos, containerPos)) {
let overMentionCharPos = this.options.offsetTop * -1;
if (!this.options.fixMentionsToQuill) {
overMentionCharPos += mentionCharPos.top;
}
topPos = overMentionCharPos - containerHeight;
}
}

@@ -287,0 +315,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc