quill-mention
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -0,0 +0,0 @@ { |
{ | ||
"files.eol": "\n" | ||
} |
@@ -1,1 +0,1 @@ | ||
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.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.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=0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(2),s=(i.n(n),i(3)),o=(i.n(s),i(4)),h=i(5);Quill.register("modules/mention",class{constructor(t,e){this.isOpen=!1,this.itemIndex=0,this.atPos=null,this.cursorPos=null,this.values=[],this.quill=t,this.source=e.source,this.renderItem=e.renderItem,this.minChars=e.minChars||0,this.maxChars=(e.maxChars||30)+1,this.allowedChars=e.allowedChars||/^[a-zA-Z0-9_]*$/,this.mentionContainer=document.createElement("div"),this.mentionContainer.className="ql-mention-list-container",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionList=document.createElement("ul"),this.mentionList.className="ql-mention-list",this.mentionContainer.appendChild(this.mentionList),document.body.appendChild(this.mentionContainer),t.on("text-change",this.onTextChange.bind(this)),t.on("selection-change",this.onSelectionChange.bind(this)),t.keyboard.addBinding({key:o.a.TAB},this.selectHandler.bind(this)),t.keyboard.bindings[9].unshift(t.keyboard.bindings[9].pop()),t.keyboard.addBinding({key:o.a.ENTER},this.selectHandler.bind(this)),t.keyboard.bindings[13].unshift(t.keyboard.bindings[13].pop()),t.keyboard.addBinding({key:o.a.ESCAPE},this.escapeHandler.bind(this)),t.keyboard.addBinding({key:o.a.UP},this.upHandler.bind(this)),t.keyboard.addBinding({key:o.a.DOWN},this.downHandler.bind(this))}selectHandler(){return!this.isOpen||(this.selectItem(),!1)}escapeHandler(){return!this.isOpen||(this.hideMentionList(),!1)}upHandler(){return!this.isOpen||(this.prevItem(),!1)}downHandler(){return!this.isOpen||(this.nextItem(),!1)}showMentionList(){this.mentionContainer.style.display="",this.mentionContainer.style.visibility="hidden",this.setMentionListPosition(),this.isOpen=!0}hideMentionList(){this.mentionContainer.style.display="none",this.isOpen=!1}highlightItem(){for(let t=0;t<this.mentionList.childNodes.length;t+=1)this.mentionList.childNodes[t].classList.remove("selected");this.mentionList.childNodes[this.itemIndex].classList.add("selected")}getItemData(){return{id:this.mentionList.childNodes[this.itemIndex].dataset.id,value:this.mentionList.childNodes[this.itemIndex].dataset.value}}selectItem(){const t=this.getItemData();this.quill.deleteText(this.atPos,this.cursorPos-this.atPos,Quill.sources.API),this.quill.insertEmbed(this.atPos,"mention",t,Quill.sources.API),this.quill.insertText(this.atPos+1," ",Quill.sources.API),this.quill.setSelection(this.atPos+2,Quill.sources.API),this.hideMentionList()}onItemClick(t){t.stopImmediatePropagation(),t.preventDefault(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}renderList(t,e){if(t&&t.length>0){this.values=t,this.mentionList.innerHTML="";for(let i=0;i<t.length;i+=1){const n=document.createElement("li");n.className="ql-mention-list-item",n.dataset.index=i,n.dataset.id=t[i].id,n.dataset.value=t[i].value,n.innerHTML=this.renderItem(t[i],e),n.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(n)}this.itemIndex=0,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}nextItem(){this.itemIndex=(this.itemIndex+1)%this.values.length,this.highlightItem()}prevItem(){this.itemIndex=(this.itemIndex+this.values.length-1)%this.values.length,this.highlightItem()}hasValidChars(t){return this.allowedChars.test(t)}setMentionListPosition(){const t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.atPos);let i=window.scrollY+t.top+e.bottom,n=window.scrollX+t.left+e.left;i+this.mentionContainer.offsetHeight>h.a.getHeight()&&(i=window.scrollY+t.top+e.top-this.mentionContainer.offsetHeight),n+this.mentionContainer.offsetWidth>h.a.getWidth()&&(n=h.a.getWidth()-this.mentionContainer.offsetWidth),this.mentionContainer.style.top=`${i}px`,this.mentionContainer.style.left=`${n}px`,this.mentionContainer.style.visibility="visible"}onSomethingChange(){const t=this.quill.getSelection();if(null==t)return;this.cursorPos=t.index;const e=Math.max(0,this.cursorPos-this.maxChars),i=this.quill.getText(e,this.cursorPos-e),n=i.lastIndexOf("@");if(n>-1){const t=this.cursorPos-(i.length-n);this.atPos=t;const e=i.substring(n+1);e.length>=this.minChars&&this.hasValidChars(e)?this.source(e):this.hideMentionList()}else this.hideMentionList()}onTextChange(t,e,i){"user"===i&&this.onSomethingChange()}onSelectionChange(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}})},function(t,e){},function(t,e){const i=Quill.import("blots/embed");class n extends i{static create(t){const e=super.create(),i=document.createElement("span");return i.className="ql-mention-at-sign",i.innerHTML="@",e.appendChild(i),e.innerHTML+=t.value,e.dataset.id=t.id,e.dataset.value=t.value,e}static value(t){return{id:t.dataset.id,value:t.dataset.value}}}n.blotName="mention",n.tagName="span",n.className="mention",Quill.register(n)},function(t,e,i){"use strict";e.a={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40}},function(t,e,i){"use strict";e.a=class{static getWidth(){return Math.max(document.body.scrollWidth,document.documentElement.scrollWidth,document.body.offsetWidth,document.documentElement.offsetWidth,document.documentElement.clientWidth)}static getHeight(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.documentElement.clientHeight)}}}]); | ||
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.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.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=0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(2),s=(i.n(n),i(3)),o=(i.n(s),i(4));Quill.register("modules/mention",class{constructor(t,e){this.isOpen=!1,this.itemIndex=0,this.atPos=null,this.cursorPos=null,this.values=[],this.quill=t,this.source=e.source,this.renderItem=e.renderItem,this.minChars=e.minChars||0,this.maxChars=(e.maxChars||30)+1,this.allowedChars=e.allowedChars||/^[a-zA-Z0-9_]*$/,this.mentionContainer=document.createElement("div"),this.mentionContainer.className="ql-mention-list-container",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionList=document.createElement("ul"),this.mentionList.className="ql-mention-list",this.mentionContainer.appendChild(this.mentionList),document.body.appendChild(this.mentionContainer),t.on("text-change",this.onTextChange.bind(this)),t.on("selection-change",this.onSelectionChange.bind(this)),t.keyboard.addBinding({key:o.a.TAB},this.selectHandler.bind(this)),t.keyboard.bindings[9].unshift(t.keyboard.bindings[9].pop()),t.keyboard.addBinding({key:o.a.ENTER},this.selectHandler.bind(this)),t.keyboard.bindings[13].unshift(t.keyboard.bindings[13].pop()),t.keyboard.addBinding({key:o.a.ESCAPE},this.escapeHandler.bind(this)),t.keyboard.addBinding({key:o.a.UP},this.upHandler.bind(this)),t.keyboard.addBinding({key:o.a.DOWN},this.downHandler.bind(this))}selectHandler(){return!this.isOpen||(this.selectItem(),!1)}escapeHandler(){return!this.isOpen||(this.hideMentionList(),!1)}upHandler(){return!this.isOpen||(this.prevItem(),!1)}downHandler(){return!this.isOpen||(this.nextItem(),!1)}showMentionList(){this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.setMentionContainerPosition(),this.isOpen=!0}hideMentionList(){this.mentionContainer.style.display="none",this.isOpen=!1}highlightItem(){for(let t=0;t<this.mentionList.childNodes.length;t+=1)this.mentionList.childNodes[t].classList.remove("selected");this.mentionList.childNodes[this.itemIndex].classList.add("selected")}getItemData(){return{id:this.mentionList.childNodes[this.itemIndex].dataset.id,value:this.mentionList.childNodes[this.itemIndex].dataset.value}}selectItem(){const t=this.getItemData();this.quill.deleteText(this.atPos,this.cursorPos-this.atPos,Quill.sources.API),this.quill.insertEmbed(this.atPos,"mention",t,Quill.sources.API),this.quill.insertText(this.atPos+1," ",Quill.sources.API),this.quill.setSelection(this.atPos+2,Quill.sources.API),this.hideMentionList()}onItemClick(t){t.stopImmediatePropagation(),t.preventDefault(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}renderList(t,e){if(t&&t.length>0){this.values=t,this.mentionList.innerHTML="";for(let i=0;i<t.length;i+=1){const n=document.createElement("li");n.className="ql-mention-list-item",n.dataset.index=i,n.dataset.id=t[i].id,n.dataset.value=t[i].value,n.innerHTML=this.renderItem(t[i],e),n.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(n)}this.itemIndex=0,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}nextItem(){this.itemIndex=(this.itemIndex+1)%this.values.length,this.highlightItem()}prevItem(){this.itemIndex=(this.itemIndex+this.values.length-1)%this.values.length,this.highlightItem()}hasValidChars(t){return this.allowedChars.test(t)}setMentionContainerPosition(){const t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.atPos);let i=window.scrollY+t.top+e.bottom,n=window.scrollX+t.left+e.left;i+this.mentionContainer.offsetHeight>window.innerHeight&&(i=window.scrollY+t.top+e.top-this.mentionContainer.offsetHeight),n+this.mentionContainer.offsetWidth>window.innerWidth&&(n=window.innerWidth-this.mentionContainer.offsetWidth),this.mentionContainer.style.top=`${i}px`,this.mentionContainer.style.left=`${n}px`,this.mentionContainer.style.visibility="visible"}onSomethingChange(){const t=this.quill.getSelection();if(null==t)return;this.cursorPos=t.index;const e=Math.max(0,this.cursorPos-this.maxChars),i=this.quill.getText(e,this.cursorPos-e),n=i.lastIndexOf("@");if(n>-1){const t=this.cursorPos-(i.length-n);this.atPos=t;const e=i.substring(n+1);e.length>=this.minChars&&this.hasValidChars(e)?this.source(e):this.hideMentionList()}else this.hideMentionList()}onTextChange(t,e,i){"user"===i&&this.onSomethingChange()}onSelectionChange(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}})},function(t,e){},function(t,e){const i=Quill.import("blots/embed");class n extends i{static create(t){const e=super.create(),i=document.createElement("span");return i.className="ql-mention-at-sign",i.innerHTML="@",e.appendChild(i),e.innerHTML+=t.value,e.dataset.id=t.id,e.dataset.value=t.value,e}static value(t){return{id:t.dataset.id,value:t.dataset.value}}}n.blotName="mention",n.tagName="span",n.className="mention",Quill.register(n)},function(t,e,i){"use strict";e.a={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40}}]); |
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "quill-mention", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "@mentions for the Quill rich text editor", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -0,0 +0,0 @@ # Quill Mention |
const Embed = Quill.import('blots/embed'); | ||
class MentionBlot extends Embed { | ||
@@ -4,0 +5,0 @@ static create(data) { |
@@ -0,0 +0,0 @@ const Keys = { |
import './quill.mention.css'; | ||
import './blots/mention'; | ||
import Keys from './constants/keys'; | ||
import Utilities from './helpers/utilities'; | ||
@@ -91,5 +90,5 @@ | ||
showMentionList() { | ||
this.mentionContainer.style.visibility = 'hidden'; | ||
this.mentionContainer.style.display = ''; | ||
this.mentionContainer.style.visibility = 'hidden'; | ||
this.setMentionListPosition(); | ||
this.setMentionContainerPosition(); | ||
this.isOpen = true; | ||
@@ -170,3 +169,3 @@ } | ||
setMentionListPosition() { | ||
setMentionContainerPosition() { | ||
const containerPos = this.quill.container.getBoundingClientRect(); | ||
@@ -176,7 +175,7 @@ const atPos = this.quill.getBounds(this.atPos); | ||
let leftPos = window.scrollX + containerPos.left + atPos.left; | ||
if (topPos + this.mentionContainer.offsetHeight > Utilities.getHeight()) { | ||
if (topPos + this.mentionContainer.offsetHeight > window.innerHeight) { | ||
topPos = (window.scrollY + containerPos.top + atPos.top) - this.mentionContainer.offsetHeight; | ||
} | ||
if (leftPos + this.mentionContainer.offsetWidth > Utilities.getWidth()) { | ||
leftPos = Utilities.getWidth() - this.mentionContainer.offsetWidth; | ||
if (leftPos + this.mentionContainer.offsetWidth > window.innerWidth) { | ||
leftPos = window.innerWidth - this.mentionContainer.offsetWidth; | ||
} | ||
@@ -183,0 +182,0 @@ this.mentionContainer.style.top = `${topPos}px`; |
@@ -0,0 +0,0 @@ const path = require('path'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34523
15
729