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.2.2 to 2.2.3

106

dist/quill.mention.csj.js

@@ -132,2 +132,51 @@ 'use strict';

function attachDataValues(element, data, dataAttributes) {
var mention = element;
Object.keys(data).forEach(function (key) {
if (dataAttributes.indexOf(key) > -1) {
mention.dataset[key] = data[key];
} else {
delete mention.dataset[key];
}
});
return mention;
}
function getMentionCharIndex(text, mentionDenotationChars) {
return mentionDenotationChars.reduce(function (prev, mentionChar) {
var mentionCharIndex = text.lastIndexOf(mentionChar);
if (mentionCharIndex > prev.mentionCharIndex) {
return {
mentionChar: mentionChar,
mentionCharIndex: mentionCharIndex
};
}
return {
mentionChar: prev.mentionChar,
mentionCharIndex: prev.mentionCharIndex
};
}, {
mentionChar: null,
mentionCharIndex: -1
});
}
function hasValidChars(text, allowedChars) {
return allowedChars.test(text);
}
function hasValidMentionCharIndex(mentionCharIndex, text, isolateChar) {
if (mentionCharIndex > -1) {
if (isolateChar && !(mentionCharIndex === 0 || !!text[mentionCharIndex - 1].match(/\s/g))) {
return false;
}
return true;
}
return false;
}
var Embed = Quill["import"]("blots/embed");

@@ -250,7 +299,7 @@

}, this.selectHandler.bind(this));
quill.keyboard.bindings[9].unshift(quill.keyboard.bindings[9].pop());
quill.keyboard.bindings[Keys.TAB].unshift(quill.keyboard.bindings[Keys.TAB].pop());
quill.keyboard.addBinding({
key: Keys.ENTER
}, this.selectHandler.bind(this));
quill.keyboard.bindings[13].unshift(quill.keyboard.bindings[13].pop());
quill.keyboard.bindings[Keys.ENTER].unshift(quill.keyboard.bindings[Keys.ENTER].pop());
quill.keyboard.addBinding({

@@ -427,17 +476,2 @@ key: Keys.ESCAPE

}, {
key: "attachDataValues",
value: function attachDataValues(element, data) {
var _this2 = this;
var mention = element;
Object.keys(data).forEach(function (key) {
if (_this2.options.dataAttributes.indexOf(key) > -1) {
mention.dataset[key] = data[key];
} else {
delete mention.dataset[key];
}
});
return mention;
}
}, {
key: "renderList",

@@ -457,3 +491,3 @@ value: function renderList(mentionChar, data, searchTerm) {

li.onclick = this.onItemClick.bind(this);
this.mentionList.appendChild(this.attachDataValues(li, data[i]));
this.mentionList.appendChild(attachDataValues(li, data[i], this.options.dataAttributes));
}

@@ -483,7 +517,2 @@

}, {
key: "hasValidChars",
value: function hasValidChars(s) {
return this.options.allowedChars.test(s);
}
}, {
key: "containerBottomIsNotVisible",

@@ -594,2 +623,9 @@ value: function containerBottomIsNotVisible(topPos, containerPos) {

}, {
key: "getTextBeforeCursor",
value: function getTextBeforeCursor() {
var startPos = Math.max(0, this.cursorPos - this.options.maxChars);
var textBeforeCursorPos = this.quill.getText(startPos, this.cursorPos - startPos);
return textBeforeCursorPos;
}
}, {
key: "onSomethingChange",

@@ -600,22 +636,14 @@ value: function onSomethingChange() {

this.cursorPos = range.index;
var startPos = Math.max(0, this.cursorPos - this.options.maxChars);
var beforeCursorPos = this.quill.getText(startPos, this.cursorPos - startPos);
var mentionCharIndex = this.options.mentionDenotationChars.reduce(function (prev, cur) {
var previousIndex = prev;
var mentionIndex = beforeCursorPos.lastIndexOf(cur);
return mentionIndex > previousIndex ? mentionIndex : previousIndex;
}, -1);
var textBeforeCursor = this.getTextBeforeCursor();
if (mentionCharIndex > -1) {
if (this.options.isolateCharacter && !(mentionCharIndex === 0 || !!beforeCursorPos[mentionCharIndex - 1].match(/\s/g))) {
this.hideMentionList();
return;
}
var _getMentionCharIndex = getMentionCharIndex(textBeforeCursor, this.options.mentionDenotationChars),
mentionChar = _getMentionCharIndex.mentionChar,
mentionCharIndex = _getMentionCharIndex.mentionCharIndex;
var mentionCharPos = this.cursorPos - (beforeCursorPos.length - mentionCharIndex);
if (hasValidMentionCharIndex(mentionCharIndex, textBeforeCursor, this.options.isolateCharacter)) {
var mentionCharPos = this.cursorPos - (textBeforeCursor.length - mentionCharIndex);
this.mentionCharPos = mentionCharPos;
var textAfter = beforeCursorPos.substring(mentionCharIndex + 1);
var textAfter = textBeforeCursor.substring(mentionCharIndex + mentionChar.length);
if (textAfter.length >= this.options.minChars && this.hasValidChars(textAfter)) {
var mentionChar = beforeCursorPos[mentionCharIndex];
if (textAfter.length >= this.options.minChars && hasValidChars(textAfter, this.options.allowedChars)) {
this.options.source(textAfter, this.renderList.bind(this, mentionChar), mentionChar);

@@ -622,0 +650,0 @@ } else {

@@ -128,2 +128,51 @@ import Quill from 'quill';

function attachDataValues(element, data, dataAttributes) {
var mention = element;
Object.keys(data).forEach(function (key) {
if (dataAttributes.indexOf(key) > -1) {
mention.dataset[key] = data[key];
} else {
delete mention.dataset[key];
}
});
return mention;
}
function getMentionCharIndex(text, mentionDenotationChars) {
return mentionDenotationChars.reduce(function (prev, mentionChar) {
var mentionCharIndex = text.lastIndexOf(mentionChar);
if (mentionCharIndex > prev.mentionCharIndex) {
return {
mentionChar: mentionChar,
mentionCharIndex: mentionCharIndex
};
}
return {
mentionChar: prev.mentionChar,
mentionCharIndex: prev.mentionCharIndex
};
}, {
mentionChar: null,
mentionCharIndex: -1
});
}
function hasValidChars(text, allowedChars) {
return allowedChars.test(text);
}
function hasValidMentionCharIndex(mentionCharIndex, text, isolateChar) {
if (mentionCharIndex > -1) {
if (isolateChar && !(mentionCharIndex === 0 || !!text[mentionCharIndex - 1].match(/\s/g))) {
return false;
}
return true;
}
return false;
}
var Embed = Quill["import"]("blots/embed");

@@ -246,7 +295,7 @@

}, this.selectHandler.bind(this));
quill.keyboard.bindings[9].unshift(quill.keyboard.bindings[9].pop());
quill.keyboard.bindings[Keys.TAB].unshift(quill.keyboard.bindings[Keys.TAB].pop());
quill.keyboard.addBinding({
key: Keys.ENTER
}, this.selectHandler.bind(this));
quill.keyboard.bindings[13].unshift(quill.keyboard.bindings[13].pop());
quill.keyboard.bindings[Keys.ENTER].unshift(quill.keyboard.bindings[Keys.ENTER].pop());
quill.keyboard.addBinding({

@@ -423,17 +472,2 @@ key: Keys.ESCAPE

}, {
key: "attachDataValues",
value: function attachDataValues(element, data) {
var _this2 = this;
var mention = element;
Object.keys(data).forEach(function (key) {
if (_this2.options.dataAttributes.indexOf(key) > -1) {
mention.dataset[key] = data[key];
} else {
delete mention.dataset[key];
}
});
return mention;
}
}, {
key: "renderList",

@@ -453,3 +487,3 @@ value: function renderList(mentionChar, data, searchTerm) {

li.onclick = this.onItemClick.bind(this);
this.mentionList.appendChild(this.attachDataValues(li, data[i]));
this.mentionList.appendChild(attachDataValues(li, data[i], this.options.dataAttributes));
}

@@ -479,7 +513,2 @@

}, {
key: "hasValidChars",
value: function hasValidChars(s) {
return this.options.allowedChars.test(s);
}
}, {
key: "containerBottomIsNotVisible",

@@ -590,2 +619,9 @@ value: function containerBottomIsNotVisible(topPos, containerPos) {

}, {
key: "getTextBeforeCursor",
value: function getTextBeforeCursor() {
var startPos = Math.max(0, this.cursorPos - this.options.maxChars);
var textBeforeCursorPos = this.quill.getText(startPos, this.cursorPos - startPos);
return textBeforeCursorPos;
}
}, {
key: "onSomethingChange",

@@ -596,22 +632,14 @@ value: function onSomethingChange() {

this.cursorPos = range.index;
var startPos = Math.max(0, this.cursorPos - this.options.maxChars);
var beforeCursorPos = this.quill.getText(startPos, this.cursorPos - startPos);
var mentionCharIndex = this.options.mentionDenotationChars.reduce(function (prev, cur) {
var previousIndex = prev;
var mentionIndex = beforeCursorPos.lastIndexOf(cur);
return mentionIndex > previousIndex ? mentionIndex : previousIndex;
}, -1);
var textBeforeCursor = this.getTextBeforeCursor();
if (mentionCharIndex > -1) {
if (this.options.isolateCharacter && !(mentionCharIndex === 0 || !!beforeCursorPos[mentionCharIndex - 1].match(/\s/g))) {
this.hideMentionList();
return;
}
var _getMentionCharIndex = getMentionCharIndex(textBeforeCursor, this.options.mentionDenotationChars),
mentionChar = _getMentionCharIndex.mentionChar,
mentionCharIndex = _getMentionCharIndex.mentionCharIndex;
var mentionCharPos = this.cursorPos - (beforeCursorPos.length - mentionCharIndex);
if (hasValidMentionCharIndex(mentionCharIndex, textBeforeCursor, this.options.isolateCharacter)) {
var mentionCharPos = this.cursorPos - (textBeforeCursor.length - mentionCharIndex);
this.mentionCharPos = mentionCharPos;
var textAfter = beforeCursorPos.substring(mentionCharIndex + 1);
var textAfter = textBeforeCursor.substring(mentionCharIndex + mentionChar.length);
if (textAfter.length >= this.options.minChars && this.hasValidChars(textAfter)) {
var mentionChar = beforeCursorPos[mentionCharIndex];
if (textAfter.length >= this.options.minChars && hasValidChars(textAfter, this.options.allowedChars)) {
this.options.source(textAfter, this.renderList.bind(this, mentionChar), mentionChar);

@@ -618,0 +646,0 @@ } else {

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

var quillMention=function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(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)}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}function s(){return(s=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}).apply(this,arguments)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t,e,i){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(i):s.value}})(t,e,i||t)}t=t&&t.hasOwnProperty("default")?t.default:t;var l={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40},u=function(t){function i(){return e(this,i),r(this,o(i).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");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&a(t,e)}(i,t),n(i,null,[{key:"create",value:function(t){var e=h(o(i),"create",this).call(this),n=document.createElement("span");return n.className="ql-mention-denotation-char",n.innerHTML=t.denotationChar,e.appendChild(n),e.innerHTML+=t.value,i.setDataValues(e,t)}},{key:"setDataValues",value:function(t,e){var i=t;return Object.keys(e).forEach((function(t){i.dataset[t]=e[t]})),i}},{key:"value",value:function(t){return t.dataset}}]),i}(t.import("blots/embed"));u.blotName="mention",u.tagName="span",u.className="mention",t.register(u);var c=function(){function i(t,n){e(this,i),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.quill=t,this.options={source:null,renderItem:function(t){return"".concat(t.value)},onSelect:function(t,e){e(t)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1,defaultMenuOrientation:"bottom",dataAttributes:["id","value","denotationChar","link","target"],linkTarget:"_blank",onOpen:function(){return!0},onClose:function(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0},s(this.options,n,{dataAttributes:Array.isArray(n.dataAttributes)?this.options.dataAttributes.concat(n.dataAttributes):this.options.dataAttributes}),this.mentionContainer=document.createElement("div"),this.mentionContainer.className=this.options.mentionContainerClass?this.options.mentionContainerClass:"",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=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList),this.quill.container.appendChild(this.mentionContainer),t.on("text-change",this.onTextChange.bind(this)),t.on("selection-change",this.onSelectionChange.bind(this)),t.keyboard.addBinding({key:l.TAB},this.selectHandler.bind(this)),t.keyboard.bindings[9].unshift(t.keyboard.bindings[9].pop()),t.keyboard.addBinding({key:l.ENTER},this.selectHandler.bind(this)),t.keyboard.bindings[13].unshift(t.keyboard.bindings[13].pop()),t.keyboard.addBinding({key:l.ESCAPE},this.escapeHandler.bind(this)),t.keyboard.addBinding({key:l.UP},this.upHandler.bind(this)),t.keyboard.addBinding({key:l.DOWN},this.downHandler.bind(this))}return n(i,[{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.setIsOpen(!0)}},{key:"hideMentionList",value:function(){this.mentionContainer.style.display="none",this.setIsOpen(!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,s=this.mentionContainer.scrollTop,o=s+this.mentionContainer.offsetHeight;n<s?this.mentionContainer.scrollTop=n:n>o-i&&(this.mentionContainer.scrollTop+=n-o+i)}}},{key:"getItemData",value:function(){var t=this.mentionList.childNodes[this.itemIndex].dataset.link,e=void 0!==t,i=this.mentionList.childNodes[this.itemIndex].dataset.target;return e&&(this.mentionList.childNodes[this.itemIndex].dataset.value='<a href="'.concat(t,'" target=').concat(i||this.options.linkTarget,">").concat(this.mentionList.childNodes[this.itemIndex].dataset.value)),this.mentionList.childNodes[this.itemIndex].dataset}},{key:"onContainerMouseMove",value:function(){this.suspendMouseEnter=!1}},{key:"selectItem",value:function(){var t=this,e=this.getItemData();this.options.onSelect(e,(function(e){t.insertItem(e)})),this.hideMentionList()}},{key:"insertItem",value:function(e){var i=e;if(null!==i){this.options.showDenotationChar||(i.denotationChar="");var n=this.mentionCharPos;this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,t.sources.USER),this.quill.insertEmbed(n,"mention",i,t.sources.USER),this.options.spaceAfterInsert?(this.quill.insertText(n+1," ",t.sources.USER),this.quill.setSelection(n+2,t.sources.USER)):this.quill.setSelection(n+1,t.sources.USER),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.preventDefault(),t.stopImmediatePropagation(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}},{key:"attachDataValues",value:function(t,e){var i=this,n=t;return Object.keys(e).forEach((function(t){i.options.dataAttributes.indexOf(t)>-1?n.dataset[t]=e[t]:delete n.dataset[t]})),n}},{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 s=document.createElement("li");s.className=this.options.listItemClass?this.options.listItemClass:"",s.dataset.index=n,s.innerHTML=this.options.renderItem(e[n],i),s.onmouseenter=this.onItemMouseEnter.bind(this),s.dataset.denotationChar=t,s.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(this.attachDataValues(s,e[n]))}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:"setIsOpen",value:function(t){this.isOpen!==t&&(t?this.options.onOpen():this.options.onClose(),this.isOpen=t)}},{key:"setMentionContainerPosition",value:function(){var t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.mentionCharPos),i=this.mentionContainer.offsetHeight,n=this.options.offsetTop,s=this.options.offsetLeft;if(this.options.fixMentionsToQuill){this.mentionContainer.style.right="".concat(0,"px")}else s+=e.left;if(this.containerRightIsNotVisible(s,t)){var o=this.mentionContainer.offsetWidth+this.options.offsetLeft;s=t.width-o}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}n>=0?(this.mentionContainer.classList.add("".concat(this.options.mentionContainerClass,"-bottom")),this.mentionContainer.classList.remove("".concat(this.options.mentionContainerClass,"-top"))):(this.mentionContainer.classList.add("".concat(this.options.mentionContainerClass,"-top")),this.mentionContainer.classList.remove("".concat(this.options.mentionContainerClass,"-bottom"))),this.mentionContainer.style.top="".concat(n,"px"),this.mentionContainer.style.left="".concat(s,"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,s=i.lastIndexOf(e);return s>n?s:n}),-1);if(n>-1){if(this.options.isolateCharacter&&0!==n&&!i[n-1].match(/\s/g))return void this.hideMentionList();var s=this.cursorPos-(i.length-n);this.mentionCharPos=s;var o=i.substring(n+1);if(o.length>=this.options.minChars&&this.hasValidChars(o)){var a=i[n];this.options.source(o,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()}}]),i}();return t.register("modules/mention",c),c}(Quill);
var quillMention=function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(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)}}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}function o(){return(o=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}).apply(this,arguments)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t,e,n){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}t=t&&t.hasOwnProperty("default")?t.default:t;var l={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40};function u(t,e,n){var i=t;return Object.keys(e).forEach((function(t){n.indexOf(t)>-1?i.dataset[t]=e[t]:delete i.dataset[t]})),i}var c=function(t){function n(){return e(this,n),r(this,s(n).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");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&a(t,e)}(n,t),i(n,null,[{key:"create",value:function(t){var e=h(s(n),"create",this).call(this),i=document.createElement("span");return i.className="ql-mention-denotation-char",i.innerHTML=t.denotationChar,e.appendChild(i),e.innerHTML+=t.value,n.setDataValues(e,t)}},{key:"setDataValues",value:function(t,e){var n=t;return Object.keys(e).forEach((function(t){n.dataset[t]=e[t]})),n}},{key:"value",value:function(t){return t.dataset}}]),n}(t.import("blots/embed"));c.blotName="mention",c.tagName="span",c.className="mention",t.register(c);var d=function(){function n(t,i){e(this,n),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.quill=t,this.options={source:null,renderItem:function(t){return"".concat(t.value)},onSelect:function(t,e){e(t)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1,defaultMenuOrientation:"bottom",dataAttributes:["id","value","denotationChar","link","target"],linkTarget:"_blank",onOpen:function(){return!0},onClose:function(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0},o(this.options,i,{dataAttributes:Array.isArray(i.dataAttributes)?this.options.dataAttributes.concat(i.dataAttributes):this.options.dataAttributes}),this.mentionContainer=document.createElement("div"),this.mentionContainer.className=this.options.mentionContainerClass?this.options.mentionContainerClass:"",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=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList),this.quill.container.appendChild(this.mentionContainer),t.on("text-change",this.onTextChange.bind(this)),t.on("selection-change",this.onSelectionChange.bind(this)),t.keyboard.addBinding({key:l.TAB},this.selectHandler.bind(this)),t.keyboard.bindings[l.TAB].unshift(t.keyboard.bindings[l.TAB].pop()),t.keyboard.addBinding({key:l.ENTER},this.selectHandler.bind(this)),t.keyboard.bindings[l.ENTER].unshift(t.keyboard.bindings[l.ENTER].pop()),t.keyboard.addBinding({key:l.ESCAPE},this.escapeHandler.bind(this)),t.keyboard.addBinding({key:l.UP},this.upHandler.bind(this)),t.keyboard.addBinding({key:l.DOWN},this.downHandler.bind(this))}return i(n,[{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.setIsOpen(!0)}},{key:"hideMentionList",value:function(){this.mentionContainer.style.display="none",this.setIsOpen(!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,e=void 0!==t,n=this.mentionList.childNodes[this.itemIndex].dataset.target;return e&&(this.mentionList.childNodes[this.itemIndex].dataset.value='<a href="'.concat(t,'" target=').concat(n||this.options.linkTarget,">").concat(this.mentionList.childNodes[this.itemIndex].dataset.value)),this.mentionList.childNodes[this.itemIndex].dataset}},{key:"onContainerMouseMove",value:function(){this.suspendMouseEnter=!1}},{key:"selectItem",value:function(){var t=this,e=this.getItemData();this.options.onSelect(e,(function(e){t.insertItem(e)})),this.hideMentionList()}},{key:"insertItem",value:function(e){var n=e;if(null!==n){this.options.showDenotationChar||(n.denotationChar="");var i=this.mentionCharPos;this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,t.sources.USER),this.quill.insertEmbed(i,"mention",n,t.sources.USER),this.options.spaceAfterInsert?(this.quill.insertText(i+1," ",t.sources.USER),this.quill.setSelection(i+2,t.sources.USER)):this.quill.setSelection(i+1,t.sources.USER),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.preventDefault(),t.stopImmediatePropagation(),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=this.options.listItemClass?this.options.listItemClass:"",o.dataset.index=i,o.innerHTML=this.options.renderItem(e[i],n),o.onmouseenter=this.onItemMouseEnter.bind(this),o.dataset.denotationChar=t,o.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(u(o,e[i],this.options.dataAttributes))}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:"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:"setIsOpen",value:function(t){this.isOpen!==t&&(t?this.options.onOpen():this.options.onClose(),this.isOpen=t)}},{key:"setMentionContainerPosition",value:function(){var t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.mentionCharPos),n=this.mentionContainer.offsetHeight,i=this.options.offsetTop,o=this.options.offsetLeft;if(this.options.fixMentionsToQuill){this.mentionContainer.style.right="".concat(0,"px")}else o+=e.left;if(this.containerRightIsNotVisible(o,t)){var s=this.mentionContainer.offsetWidth+this.options.offsetLeft;o=t.width-s}if("top"===this.options.defaultMenuOrientation){if((i=this.options.fixMentionsToQuill?-1*(n+this.options.offsetTop):e.top-(n+this.options.offsetTop))+t.top<=0){var a=this.options.offsetTop;this.options.fixMentionsToQuill?a+=t.height:a+=e.bottom,i=a}}else if(this.options.fixMentionsToQuill?i+=t.height:i+=e.bottom,this.containerBottomIsNotVisible(i,t)){var r=-1*this.options.offsetTop;this.options.fixMentionsToQuill||(r+=e.top),i=r-n}i>=0?(this.mentionContainer.classList.add("".concat(this.options.mentionContainerClass,"-bottom")),this.mentionContainer.classList.remove("".concat(this.options.mentionContainerClass,"-top"))):(this.mentionContainer.classList.add("".concat(this.options.mentionContainerClass,"-top")),this.mentionContainer.classList.remove("".concat(this.options.mentionContainerClass,"-bottom"))),this.mentionContainer.style.top="".concat(i,"px"),this.mentionContainer.style.left="".concat(o,"px"),this.mentionContainer.style.visibility="visible"}},{key:"getTextBeforeCursor",value:function(){var t=Math.max(0,this.cursorPos-this.options.maxChars);return this.quill.getText(t,this.cursorPos-t)}},{key:"onSomethingChange",value:function(){var t=this.quill.getSelection();if(null!=t){this.cursorPos=t.index;var e,n=this.getTextBeforeCursor(),i=(e=n,this.options.mentionDenotationChars.reduce((function(t,n){var i=e.lastIndexOf(n);return i>t.mentionCharIndex?{mentionChar:n,mentionCharIndex:i}:{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex}}),{mentionChar:null,mentionCharIndex:-1})),o=i.mentionChar,s=i.mentionCharIndex;if(function(t,e,n){return t>-1&&!(n&&0!==t&&!e[t-1].match(/\s/g))}(s,n,this.options.isolateCharacter)){var a=this.cursorPos-(n.length-s);this.mentionCharPos=a;var r=n.substring(s+o.length);r.length>=this.options.minChars&&function(t,e){return e.test(t)}(r,this.options.allowedChars)?this.options.source(r,this.renderList.bind(this,o),o):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()}}]),n}();return t.register("modules/mention",d),d}(Quill);
{
"name": "quill-mention",
"version": "2.2.2",
"version": "2.2.3",
"description": "@mentions for the Quill rich text editor",

@@ -19,9 +19,16 @@ "main": "dist/quill.mention.csj.js",

"devDependencies": {
"@ava/babel": "^0.4.0",
"@babel/core": "^7.7.4",
"@babel/plugin-transform-object-assign": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/register": "^7.7.7",
"ava": "^2.4.0",
"concurrently": "^5.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "1.19.1",
"rollup": "^1.27.8",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-local-resolve": "^1.0.7",
"rollup-plugin-postcss": "^2.0.3",

@@ -33,4 +40,10 @@ "rollup-plugin-terser": "^5.1.2",

"start": "concurrently \"rollup -c -w\" \"serve docs\"",
"build": "rollup -c"
"build": "rollup -c",
"test": "ava"
},
"ava": {
"require": [
"@babel/register"
]
},
"keywords": [

@@ -37,0 +50,0 @@ "quill",

Sorry, the diff of this file is not supported yet

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