quill-mention
Advanced tools
Comparing version 3.4.0 to 3.4.1
@@ -11,21 +11,38 @@ 'use strict'; | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -36,2 +53,3 @@ if (!(instance instanceof Constructor)) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -43,15 +61,13 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -67,8 +83,11 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -80,6 +99,9 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -89,2 +111,3 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -97,9 +120,7 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -109,9 +130,12 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
@@ -121,2 +145,3 @@ if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
@@ -129,2 +154,3 @@ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -134,4 +160,6 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
@@ -143,11 +171,16 @@ if (call && (typeof call === "object" || typeof call === "function")) { | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
@@ -157,5 +190,7 @@ } else { | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
@@ -166,20 +201,27 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
_get = Reflect.get; | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -193,9 +235,14 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
@@ -205,3 +252,5 @@ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
var i = 0; | ||
var F = function () {}; | ||
return { | ||
@@ -224,7 +273,9 @@ s: F, | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
didErr = false, | ||
err; | ||
return { | ||
@@ -252,16 +303,2 @@ s: function () { | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -287,8 +324,11 @@ var Keys = { | ||
} | ||
function getMentionCharIndex(text, mentionDenotationChars, isolateChar, allowInlineMentionChar) { | ||
return mentionDenotationChars.reduce(function (prev, mentionChar) { | ||
var mentionCharIndex; | ||
if (isolateChar && allowInlineMentionChar) { | ||
var regex = new RegExp("^".concat(mentionChar, "|\\s").concat(mentionChar), 'g'); | ||
var lastMatch = (text.match(regex) || []).pop(); | ||
if (!lastMatch) { | ||
@@ -300,2 +340,3 @@ return { | ||
} | ||
mentionCharIndex = lastMatch !== mentionChar ? text.lastIndexOf(lastMatch) + lastMatch.length - mentionChar.length : 0; | ||
@@ -305,2 +346,3 @@ } else { | ||
} | ||
if (mentionCharIndex > prev.mentionCharIndex) { | ||
@@ -312,2 +354,3 @@ return { | ||
} | ||
return { | ||
@@ -322,5 +365,7 @@ mentionChar: prev.mentionChar, | ||
} | ||
function hasValidChars(text, allowedChars) { | ||
return allowedChars.test(text); | ||
} | ||
function hasValidMentionCharIndex(mentionCharIndex, text, isolateChar, textPrefix) { | ||
@@ -330,5 +375,7 @@ if (mentionCharIndex === -1) { | ||
} | ||
if (!isolateChar) { | ||
return true; | ||
} | ||
var mentionPrefix = mentionCharIndex ? text[mentionCharIndex - 1] : textPrefix; | ||
@@ -339,11 +386,19 @@ return !mentionPrefix || !!mentionPrefix.match(/\s/); | ||
var Embed = Quill__default["default"]["import"]("blots/embed"); | ||
var MentionBlot = /*#__PURE__*/function (_Embed) { | ||
_inherits(MentionBlot, _Embed); | ||
var _super = _createSuper(MentionBlot); | ||
function MentionBlot(scroll, node) { | ||
var _this; | ||
_classCallCheck(this, MentionBlot); | ||
_this = _super.call(this, scroll, node); | ||
_defineProperty(_assertThisInitialized(_this), "hoverHandler", void 0); | ||
_defineProperty(_assertThisInitialized(_this), "hoverHandler", void 0); | ||
_this.clickHandler = null; | ||
@@ -354,2 +409,3 @@ _this.hoverHandler = null; | ||
} | ||
_createClass(MentionBlot, [{ | ||
@@ -359,2 +415,3 @@ key: "attach", | ||
_get(_getPrototypeOf(MentionBlot.prototype), "attach", this).call(this); | ||
if (!this.mounted) { | ||
@@ -372,3 +429,5 @@ this.mounted = true; | ||
_get(_getPrototypeOf(MentionBlot.prototype), "detach", this).call(this); | ||
this.mounted = false; | ||
if (this.clickHandler) { | ||
@@ -383,4 +442,6 @@ this.domNode.removeEventListener("click", this.clickHandler); | ||
var _this2 = this; | ||
return function (e) { | ||
var event = _this2.buildEvent("mention-clicked", e); | ||
window.dispatchEvent(event); | ||
@@ -394,4 +455,6 @@ e.preventDefault(); | ||
var _this3 = this; | ||
return function (e) { | ||
var event = _this3.buildEvent('mention-hovered', e); | ||
window.dispatchEvent(event); | ||
@@ -416,2 +479,3 @@ e.preventDefault(); | ||
var node = _get(_getPrototypeOf(MentionBlot), "create", this).call(this); | ||
var denotationChar = document.createElement("span"); | ||
@@ -439,4 +503,6 @@ denotationChar.className = "ql-mention-denotation-char"; | ||
}]); | ||
return MentionBlot; | ||
}(Embed); | ||
MentionBlot.blotName = "mention"; | ||
@@ -450,3 +516,5 @@ MentionBlot.tagName = "span"; | ||
var _this = this; | ||
_classCallCheck(this, Mention); | ||
this.isOpen = false; | ||
@@ -457,7 +525,7 @@ this.itemIndex = 0; | ||
this.values = []; | ||
this.suspendMouseEnter = false; | ||
//this token is an object that may contains one key "abandoned", set to | ||
this.suspendMouseEnter = false; //this token is an object that may contains one key "abandoned", set to | ||
//true when the previous source call should be ignored in favor or a | ||
//more recent execution. This token will be null unless a source call | ||
//is in progress. | ||
this.existingSourceExecutionToken = null; | ||
@@ -507,7 +575,8 @@ this.quill = quill; | ||
}; | ||
_extends(this.options, options, { | ||
dataAttributes: Array.isArray(options.dataAttributes) ? this.options.dataAttributes.concat(options.dataAttributes) : this.options.dataAttributes | ||
}); | ||
}); //Bind all option-functions so they have a reasonable context | ||
//Bind all option-functions so they have a reasonable context | ||
for (var o in this.options) { | ||
@@ -517,5 +586,5 @@ if (typeof this.options[o] === 'function') { | ||
} | ||
} | ||
} //create mention container | ||
//create mention container | ||
this.mentionContainer = document.createElement("div"); | ||
@@ -525,5 +594,7 @@ this.mentionContainer.className = this.options.mentionContainerClass ? this.options.mentionContainerClass : ""; | ||
this.mentionContainer.onmousemove = this.onContainerMouseMove.bind(this); | ||
if (this.options.fixMentionsToQuill) { | ||
this.mentionContainer.style.width = "auto"; | ||
} | ||
this.mentionList = document.createElement("ul"); | ||
@@ -535,9 +606,9 @@ this.mentionList.id = 'quill-mention-list'; | ||
quill.on("text-change", this.onTextChange.bind(this)); | ||
quill.on("selection-change", this.onSelectionChange.bind(this)); | ||
quill.on("selection-change", this.onSelectionChange.bind(this)); //Pasting doesn't fire selection-change after the pasted text is | ||
//inserted, so here we manually trigger one | ||
//Pasting doesn't fire selection-change after the pasted text is | ||
//inserted, so here we manually trigger one | ||
quill.container.addEventListener("paste", function () { | ||
setTimeout(function () { | ||
var range = quill.getSelection(); | ||
_this.onSelectionChange(range); | ||
@@ -550,4 +621,6 @@ }); | ||
quill.keyboard.bindings[Keys.TAB].unshift(quill.keyboard.bindings[Keys.TAB].pop()); | ||
var _iterator = _createForOfIteratorHelper(this.options.selectKeys), | ||
_step; | ||
_step; | ||
try { | ||
@@ -565,2 +638,3 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
quill.keyboard.bindings[Keys.ENTER].unshift(quill.keyboard.bindings[Keys.ENTER].pop()); | ||
@@ -577,2 +651,3 @@ quill.keyboard.addBinding({ | ||
} | ||
_createClass(Mention, [{ | ||
@@ -585,2 +660,3 @@ key: "selectHandler", | ||
} | ||
return true; | ||
@@ -595,5 +671,7 @@ } | ||
} | ||
this.hideMentionList(); | ||
return false; | ||
} | ||
return true; | ||
@@ -608,2 +686,3 @@ } | ||
} | ||
return true; | ||
@@ -618,2 +697,3 @@ } | ||
} | ||
return true; | ||
@@ -629,2 +709,3 @@ } | ||
} | ||
this.mentionContainer.style.visibility = "hidden"; | ||
@@ -649,10 +730,14 @@ this.mentionContainer.style.display = ""; | ||
var scrollItemInView = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
for (var i = 0; i < this.mentionList.childNodes.length; i += 1) { | ||
this.mentionList.childNodes[i].classList.remove("selected"); | ||
} | ||
if (this.itemIndex === -1 || this.mentionList.childNodes[this.itemIndex].dataset.disabled === "true") { | ||
return; | ||
} | ||
this.mentionList.childNodes[this.itemIndex].classList.add("selected"); | ||
this.quill.root.setAttribute('aria-activedescendant', this.mentionList.childNodes[this.itemIndex].id); | ||
if (scrollItemInView) { | ||
@@ -663,2 +748,3 @@ var itemHeight = this.mentionList.childNodes[this.itemIndex].offsetHeight; | ||
var containerBottom = containerTop + this.mentionContainer.offsetHeight; | ||
if (itemPos < containerTop) { | ||
@@ -679,5 +765,7 @@ // Scroll up if the item is above the top of the container | ||
var itemTarget = this.mentionList.childNodes[this.itemIndex].dataset.target; | ||
if (hasLinkValue) { | ||
this.mentionList.childNodes[this.itemIndex].dataset.value = "<a href=\"".concat(link, "\" target=").concat(itemTarget || this.options.linkTarget, ">").concat(this.mentionList.childNodes[this.itemIndex].dataset.value); | ||
} | ||
return this.mentionList.childNodes[this.itemIndex].dataset; | ||
@@ -694,9 +782,13 @@ } | ||
var _this2 = this; | ||
if (this.itemIndex === -1) { | ||
return; | ||
} | ||
var data = this.getItemData(); | ||
if (data.disabled) { | ||
return; | ||
} | ||
this.options.onSelect(data, function (asyncData) { | ||
@@ -714,10 +806,15 @@ var programmaticInsert = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var render = data; | ||
if (render === null) { | ||
return; | ||
} | ||
var options = _objectSpread2(_objectSpread2({}, this.options), overriddenOptions); | ||
if (!options.showDenotationChar) { | ||
render.denotationChar = ""; | ||
} | ||
var insertAtPos; | ||
if (!programmaticInsert) { | ||
@@ -729,6 +826,8 @@ insertAtPos = this.mentionCharPos; | ||
} | ||
var delta = this.quill.insertEmbed(insertAtPos, options.blotName, render, Quill__default["default"].sources.USER); | ||
if (options.spaceAfterInsert) { | ||
this.quill.insertText(insertAtPos + 1, " ", Quill__default["default"].sources.USER); | ||
// setSelection here sets cursor position | ||
this.quill.insertText(insertAtPos + 1, " ", Quill__default["default"].sources.USER); // setSelection here sets cursor position | ||
this.quill.setSelection(insertAtPos + 2, Quill__default["default"].sources.USER); | ||
@@ -738,2 +837,3 @@ } else { | ||
} | ||
this.hideMentionList(); | ||
@@ -748,3 +848,5 @@ return delta; | ||
} | ||
var index = Number(e.target.dataset.index); | ||
if (!Number.isNaN(index) && index !== this.itemIndex) { | ||
@@ -761,2 +863,3 @@ this.itemIndex = index; | ||
} | ||
this.itemIndex = -1; | ||
@@ -771,2 +874,3 @@ this.highlightItem(false); | ||
} | ||
e.preventDefault(); | ||
@@ -788,5 +892,7 @@ e.stopImmediatePropagation(); | ||
var renderedLoading = this.options.renderLoading(); | ||
if (!renderedLoading) { | ||
return; | ||
} | ||
if (this.mentionContainer.getElementsByClassName("ql-mention-loading").length > 0) { | ||
@@ -796,2 +902,3 @@ this.showMentionList(); | ||
} | ||
this.mentionList.innerHTML = ""; | ||
@@ -808,2 +915,3 @@ var loadingDiv = document.createElement("div"); | ||
var loadingDiv = this.mentionContainer.getElementsByClassName("ql-mention-loading"); | ||
if (loadingDiv.length > 0) { | ||
@@ -821,2 +929,3 @@ loadingDiv[0].remove(); | ||
var initialSelection = -1; | ||
for (var i = 0; i < data.length; i += 1) { | ||
@@ -826,2 +935,3 @@ var li = document.createElement("li"); | ||
li.className = this.options.listItemClass ? this.options.listItemClass : ""; | ||
if (data[i].disabled) { | ||
@@ -833,4 +943,6 @@ li.className += " disabled"; | ||
} | ||
li.dataset.index = i; | ||
li.innerHTML = this.options.renderItem(data[i], searchTerm); | ||
if (!data[i].disabled) { | ||
@@ -843,5 +955,7 @@ li.onmouseenter = this.onItemMouseEnter.bind(this); | ||
} | ||
li.dataset.denotationChar = mentionChar; | ||
this.mentionList.appendChild(attachDataValues(li, data[i], this.options.dataAttributes)); | ||
} | ||
this.itemIndex = initialSelection; | ||
@@ -859,2 +973,3 @@ this.highlightItem(); | ||
var newIndex; | ||
do { | ||
@@ -864,2 +979,3 @@ increment++; | ||
var disabled = this.mentionList.childNodes[newIndex].dataset.disabled === "true"; | ||
if (increment === this.values.length + 1) { | ||
@@ -871,2 +987,3 @@ //we've wrapped around w/o finding an enabled item | ||
} while (disabled); | ||
this.itemIndex = newIndex; | ||
@@ -881,2 +998,3 @@ this.suspendMouseEnter = true; | ||
var newIndex; | ||
do { | ||
@@ -886,2 +1004,3 @@ decrement++; | ||
var disabled = this.mentionList.childNodes[newIndex].dataset.disabled === "true"; | ||
if (decrement === this.values.length + 1) { | ||
@@ -893,2 +1012,3 @@ //we've wrapped around w/o finding an enabled item | ||
} while (disabled); | ||
this.itemIndex = newIndex; | ||
@@ -910,2 +1030,3 @@ this.suspendMouseEnter = true; | ||
} | ||
var rightPos = leftPos + this.mentionContainer.offsetWidth + containerPos.left; | ||
@@ -924,2 +1045,3 @@ var browserWidth = window.pageXOffset + document.documentElement.clientWidth; | ||
} | ||
this.isOpen = isOpen; | ||
@@ -941,2 +1063,3 @@ } | ||
var _this3 = this; | ||
var containerPos = this.quill.container.getBoundingClientRect(); | ||
@@ -946,5 +1069,4 @@ var mentionCharPos = this.quill.getBounds(this.mentionCharPos); | ||
var topPos = this.options.offsetTop; | ||
var leftPos = this.options.offsetLeft; | ||
var leftPos = this.options.offsetLeft; // handle horizontal positioning | ||
// handle horizontal positioning | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -956,2 +1078,3 @@ var rightPos = 0; | ||
} | ||
if (this.containerRightIsNotVisible(leftPos, containerPos)) { | ||
@@ -961,5 +1084,5 @@ var containerWidth = this.mentionContainer.offsetWidth + this.options.offsetLeft; | ||
leftPos = quillWidth - containerWidth; | ||
} | ||
} // handle vertical positioning | ||
// handle vertical positioning | ||
if (this.options.defaultMenuOrientation === "top") { | ||
@@ -971,7 +1094,8 @@ // Attempt to align the mention container with the top of the quill editor | ||
topPos = mentionCharPos.top - (containerHeight + this.options.offsetTop); | ||
} | ||
} // default to bottom if the top is not visible | ||
// default to bottom if the top is not visible | ||
if (topPos + containerPos.top <= 0) { | ||
var overMentionCharPos = this.options.offsetTop; | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -982,2 +1106,3 @@ overMentionCharPos += containerPos.height; | ||
} | ||
topPos = overMentionCharPos; | ||
@@ -991,16 +1116,20 @@ } | ||
topPos += mentionCharPos.bottom; | ||
} | ||
} // default to the top if the bottom is not visible | ||
// default to the top if the bottom is not visible | ||
if (this.containerBottomIsNotVisible(topPos, containerPos)) { | ||
var _overMentionCharPos = this.options.offsetTop * -1; | ||
if (!this.options.fixMentionsToQuill) { | ||
_overMentionCharPos += mentionCharPos.top; | ||
} | ||
topPos = _overMentionCharPos - containerHeight; | ||
} | ||
} | ||
if (topPos >= 0) { | ||
this.options.mentionContainerClass.split(' ').forEach(function (className) { | ||
_this3.mentionContainer.classList.add("".concat(className, "-bottom")); | ||
_this3.mentionContainer.classList.remove("".concat(className, "-top")); | ||
@@ -1011,5 +1140,7 @@ }); | ||
_this3.mentionContainer.classList.add("".concat(className, "-top")); | ||
_this3.mentionContainer.classList.remove("".concat(className, "-bottom")); | ||
}); | ||
} | ||
this.mentionContainer.style.top = "".concat(topPos, "px"); | ||
@@ -1023,2 +1154,3 @@ this.mentionContainer.style.left = "".concat(leftPos, "px"); | ||
var _this4 = this; | ||
this.mentionContainer.style.position = "fixed"; | ||
@@ -1033,10 +1165,8 @@ this.mentionContainer.style.height = null; | ||
height: mentionCharPos.height | ||
}; | ||
}; //Which rectangle should it be relative to | ||
//Which rectangle should it be relative to | ||
var relativeToPos = this.options.fixMentionsToQuill ? containerPos : mentionCharPosAbsolute; | ||
var topPos = this.options.offsetTop; | ||
var leftPos = this.options.offsetLeft; | ||
var leftPos = this.options.offsetLeft; // handle horizontal positioning | ||
// handle horizontal positioning | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -1046,5 +1176,4 @@ var rightPos = relativeToPos.right; | ||
} else { | ||
leftPos += relativeToPos.left; | ||
leftPos += relativeToPos.left; //if its off the righ edge, push it back | ||
//if its off the righ edge, push it back | ||
if (leftPos + this.mentionContainer.offsetWidth > document.documentElement.clientWidth) { | ||
@@ -1054,2 +1183,3 @@ leftPos -= leftPos + this.mentionContainer.offsetWidth - document.documentElement.clientWidth; | ||
} | ||
var availableSpaceTop = relativeToPos.top; | ||
@@ -1060,2 +1190,3 @@ var availableSpaceBottom = document.documentElement.clientHeight - (relativeToPos.top + relativeToPos.height); | ||
var placement; | ||
if (this.options.defaultMenuOrientation === "top" && fitsTop) { | ||
@@ -1069,4 +1200,6 @@ placement = "top"; | ||
} | ||
if (placement === "bottom") { | ||
topPos = relativeToPos.top + relativeToPos.height; | ||
if (!fitsBottom) { | ||
@@ -1077,4 +1210,6 @@ //shrink it to fit | ||
} | ||
this.options.mentionContainerClass.split(" ").forEach(function (className) { | ||
_this4.mentionContainer.classList.add("".concat(className, "-bottom")); | ||
_this4.mentionContainer.classList.remove("".concat(className, "-top")); | ||
@@ -1084,2 +1219,3 @@ }); | ||
topPos = relativeToPos.top - this.mentionContainer.offsetHeight; | ||
if (!fitsTop) { | ||
@@ -1091,7 +1227,10 @@ //shrink it to fit | ||
} | ||
this.options.mentionContainerClass.split(" ").forEach(function (className) { | ||
_this4.mentionContainer.classList.add("".concat(className, "-top")); | ||
_this4.mentionContainer.classList.remove("".concat(className, "-bottom")); | ||
}); | ||
} | ||
this.mentionContainer.style.top = "".concat(topPos, "px"); | ||
@@ -1112,2 +1251,3 @@ this.mentionContainer.style.left = "".concat(leftPos, "px"); | ||
var _this5 = this; | ||
var range = this.quill.getSelection(); | ||
@@ -1119,5 +1259,7 @@ if (range == null) return; | ||
var textPrefix = textOffset ? this.quill.getText(textOffset - 1, textOffset) : ''; | ||
var _getMentionCharIndex = getMentionCharIndex(textBeforeCursor, this.options.mentionDenotationChars, this.options.isolateCharacter, this.options.allowInlineMentionChar), | ||
mentionChar = _getMentionCharIndex.mentionChar, | ||
mentionCharIndex = _getMentionCharIndex.mentionCharIndex; | ||
mentionChar = _getMentionCharIndex.mentionChar, | ||
mentionCharIndex = _getMentionCharIndex.mentionCharIndex; | ||
if (hasValidMentionCharIndex(mentionCharIndex, textBeforeCursor, this.options.isolateCharacter, textPrefix)) { | ||
@@ -1127,2 +1269,3 @@ var mentionCharPos = this.cursorPos - (textBeforeCursor.length - mentionCharIndex); | ||
var textAfter = textBeforeCursor.substring(mentionCharIndex + mentionChar.length); | ||
if (textAfter.length >= this.options.minChars && hasValidChars(textAfter, this.getAllowedCharsRegex(mentionChar))) { | ||
@@ -1132,2 +1275,3 @@ if (this.existingSourceExecutionToken) { | ||
} | ||
this.renderLoading(); | ||
@@ -1142,3 +1286,5 @@ var sourceRequestToken = { | ||
} | ||
_this5.existingSourceExecutionToken = null; | ||
_this5.renderList(mentionChar, data, searchTerm); | ||
@@ -1150,2 +1296,3 @@ }, mentionChar); | ||
} | ||
this.hideMentionList(); | ||
@@ -1157,2 +1304,3 @@ } | ||
} | ||
this.hideMentionList(); | ||
@@ -1195,6 +1343,8 @@ } | ||
}]); | ||
return Mention; | ||
}(); | ||
Quill__default["default"].register("modules/mention", Mention); | ||
module.exports = Mention; |
@@ -5,21 +5,38 @@ import Quill from 'quill'; | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -30,2 +47,3 @@ if (!(instance instanceof Constructor)) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -37,15 +55,13 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -61,8 +77,11 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -74,6 +93,9 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -83,2 +105,3 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -91,9 +114,7 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -103,9 +124,12 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
@@ -115,2 +139,3 @@ if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
@@ -123,2 +148,3 @@ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -128,4 +154,6 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
@@ -137,11 +165,16 @@ if (call && (typeof call === "object" || typeof call === "function")) { | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
@@ -151,5 +184,7 @@ } else { | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
@@ -160,20 +195,27 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
_get = Reflect.get; | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -187,9 +229,14 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
@@ -199,3 +246,5 @@ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
var i = 0; | ||
var F = function () {}; | ||
return { | ||
@@ -218,7 +267,9 @@ s: F, | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
didErr = false, | ||
err; | ||
return { | ||
@@ -246,16 +297,2 @@ s: function () { | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -281,8 +318,11 @@ var Keys = { | ||
} | ||
function getMentionCharIndex(text, mentionDenotationChars, isolateChar, allowInlineMentionChar) { | ||
return mentionDenotationChars.reduce(function (prev, mentionChar) { | ||
var mentionCharIndex; | ||
if (isolateChar && allowInlineMentionChar) { | ||
var regex = new RegExp("^".concat(mentionChar, "|\\s").concat(mentionChar), 'g'); | ||
var lastMatch = (text.match(regex) || []).pop(); | ||
if (!lastMatch) { | ||
@@ -294,2 +334,3 @@ return { | ||
} | ||
mentionCharIndex = lastMatch !== mentionChar ? text.lastIndexOf(lastMatch) + lastMatch.length - mentionChar.length : 0; | ||
@@ -299,2 +340,3 @@ } else { | ||
} | ||
if (mentionCharIndex > prev.mentionCharIndex) { | ||
@@ -306,2 +348,3 @@ return { | ||
} | ||
return { | ||
@@ -316,5 +359,7 @@ mentionChar: prev.mentionChar, | ||
} | ||
function hasValidChars(text, allowedChars) { | ||
return allowedChars.test(text); | ||
} | ||
function hasValidMentionCharIndex(mentionCharIndex, text, isolateChar, textPrefix) { | ||
@@ -324,5 +369,7 @@ if (mentionCharIndex === -1) { | ||
} | ||
if (!isolateChar) { | ||
return true; | ||
} | ||
var mentionPrefix = mentionCharIndex ? text[mentionCharIndex - 1] : textPrefix; | ||
@@ -333,11 +380,19 @@ return !mentionPrefix || !!mentionPrefix.match(/\s/); | ||
var Embed = Quill["import"]("blots/embed"); | ||
var MentionBlot = /*#__PURE__*/function (_Embed) { | ||
_inherits(MentionBlot, _Embed); | ||
var _super = _createSuper(MentionBlot); | ||
function MentionBlot(scroll, node) { | ||
var _this; | ||
_classCallCheck(this, MentionBlot); | ||
_this = _super.call(this, scroll, node); | ||
_defineProperty(_assertThisInitialized(_this), "hoverHandler", void 0); | ||
_defineProperty(_assertThisInitialized(_this), "hoverHandler", void 0); | ||
_this.clickHandler = null; | ||
@@ -348,2 +403,3 @@ _this.hoverHandler = null; | ||
} | ||
_createClass(MentionBlot, [{ | ||
@@ -353,2 +409,3 @@ key: "attach", | ||
_get(_getPrototypeOf(MentionBlot.prototype), "attach", this).call(this); | ||
if (!this.mounted) { | ||
@@ -366,3 +423,5 @@ this.mounted = true; | ||
_get(_getPrototypeOf(MentionBlot.prototype), "detach", this).call(this); | ||
this.mounted = false; | ||
if (this.clickHandler) { | ||
@@ -377,4 +436,6 @@ this.domNode.removeEventListener("click", this.clickHandler); | ||
var _this2 = this; | ||
return function (e) { | ||
var event = _this2.buildEvent("mention-clicked", e); | ||
window.dispatchEvent(event); | ||
@@ -388,4 +449,6 @@ e.preventDefault(); | ||
var _this3 = this; | ||
return function (e) { | ||
var event = _this3.buildEvent('mention-hovered', e); | ||
window.dispatchEvent(event); | ||
@@ -410,2 +473,3 @@ e.preventDefault(); | ||
var node = _get(_getPrototypeOf(MentionBlot), "create", this).call(this); | ||
var denotationChar = document.createElement("span"); | ||
@@ -433,4 +497,6 @@ denotationChar.className = "ql-mention-denotation-char"; | ||
}]); | ||
return MentionBlot; | ||
}(Embed); | ||
MentionBlot.blotName = "mention"; | ||
@@ -444,3 +510,5 @@ MentionBlot.tagName = "span"; | ||
var _this = this; | ||
_classCallCheck(this, Mention); | ||
this.isOpen = false; | ||
@@ -451,7 +519,7 @@ this.itemIndex = 0; | ||
this.values = []; | ||
this.suspendMouseEnter = false; | ||
//this token is an object that may contains one key "abandoned", set to | ||
this.suspendMouseEnter = false; //this token is an object that may contains one key "abandoned", set to | ||
//true when the previous source call should be ignored in favor or a | ||
//more recent execution. This token will be null unless a source call | ||
//is in progress. | ||
this.existingSourceExecutionToken = null; | ||
@@ -501,7 +569,8 @@ this.quill = quill; | ||
}; | ||
_extends(this.options, options, { | ||
dataAttributes: Array.isArray(options.dataAttributes) ? this.options.dataAttributes.concat(options.dataAttributes) : this.options.dataAttributes | ||
}); | ||
}); //Bind all option-functions so they have a reasonable context | ||
//Bind all option-functions so they have a reasonable context | ||
for (var o in this.options) { | ||
@@ -511,5 +580,5 @@ if (typeof this.options[o] === 'function') { | ||
} | ||
} | ||
} //create mention container | ||
//create mention container | ||
this.mentionContainer = document.createElement("div"); | ||
@@ -519,5 +588,7 @@ this.mentionContainer.className = this.options.mentionContainerClass ? this.options.mentionContainerClass : ""; | ||
this.mentionContainer.onmousemove = this.onContainerMouseMove.bind(this); | ||
if (this.options.fixMentionsToQuill) { | ||
this.mentionContainer.style.width = "auto"; | ||
} | ||
this.mentionList = document.createElement("ul"); | ||
@@ -529,9 +600,9 @@ this.mentionList.id = 'quill-mention-list'; | ||
quill.on("text-change", this.onTextChange.bind(this)); | ||
quill.on("selection-change", this.onSelectionChange.bind(this)); | ||
quill.on("selection-change", this.onSelectionChange.bind(this)); //Pasting doesn't fire selection-change after the pasted text is | ||
//inserted, so here we manually trigger one | ||
//Pasting doesn't fire selection-change after the pasted text is | ||
//inserted, so here we manually trigger one | ||
quill.container.addEventListener("paste", function () { | ||
setTimeout(function () { | ||
var range = quill.getSelection(); | ||
_this.onSelectionChange(range); | ||
@@ -544,4 +615,6 @@ }); | ||
quill.keyboard.bindings[Keys.TAB].unshift(quill.keyboard.bindings[Keys.TAB].pop()); | ||
var _iterator = _createForOfIteratorHelper(this.options.selectKeys), | ||
_step; | ||
_step; | ||
try { | ||
@@ -559,2 +632,3 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
quill.keyboard.bindings[Keys.ENTER].unshift(quill.keyboard.bindings[Keys.ENTER].pop()); | ||
@@ -571,2 +645,3 @@ quill.keyboard.addBinding({ | ||
} | ||
_createClass(Mention, [{ | ||
@@ -579,2 +654,3 @@ key: "selectHandler", | ||
} | ||
return true; | ||
@@ -589,5 +665,7 @@ } | ||
} | ||
this.hideMentionList(); | ||
return false; | ||
} | ||
return true; | ||
@@ -602,2 +680,3 @@ } | ||
} | ||
return true; | ||
@@ -612,2 +691,3 @@ } | ||
} | ||
return true; | ||
@@ -623,2 +703,3 @@ } | ||
} | ||
this.mentionContainer.style.visibility = "hidden"; | ||
@@ -643,10 +724,14 @@ this.mentionContainer.style.display = ""; | ||
var scrollItemInView = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
for (var i = 0; i < this.mentionList.childNodes.length; i += 1) { | ||
this.mentionList.childNodes[i].classList.remove("selected"); | ||
} | ||
if (this.itemIndex === -1 || this.mentionList.childNodes[this.itemIndex].dataset.disabled === "true") { | ||
return; | ||
} | ||
this.mentionList.childNodes[this.itemIndex].classList.add("selected"); | ||
this.quill.root.setAttribute('aria-activedescendant', this.mentionList.childNodes[this.itemIndex].id); | ||
if (scrollItemInView) { | ||
@@ -657,2 +742,3 @@ var itemHeight = this.mentionList.childNodes[this.itemIndex].offsetHeight; | ||
var containerBottom = containerTop + this.mentionContainer.offsetHeight; | ||
if (itemPos < containerTop) { | ||
@@ -673,5 +759,7 @@ // Scroll up if the item is above the top of the container | ||
var itemTarget = this.mentionList.childNodes[this.itemIndex].dataset.target; | ||
if (hasLinkValue) { | ||
this.mentionList.childNodes[this.itemIndex].dataset.value = "<a href=\"".concat(link, "\" target=").concat(itemTarget || this.options.linkTarget, ">").concat(this.mentionList.childNodes[this.itemIndex].dataset.value); | ||
} | ||
return this.mentionList.childNodes[this.itemIndex].dataset; | ||
@@ -688,9 +776,13 @@ } | ||
var _this2 = this; | ||
if (this.itemIndex === -1) { | ||
return; | ||
} | ||
var data = this.getItemData(); | ||
if (data.disabled) { | ||
return; | ||
} | ||
this.options.onSelect(data, function (asyncData) { | ||
@@ -708,10 +800,15 @@ var programmaticInsert = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var render = data; | ||
if (render === null) { | ||
return; | ||
} | ||
var options = _objectSpread2(_objectSpread2({}, this.options), overriddenOptions); | ||
if (!options.showDenotationChar) { | ||
render.denotationChar = ""; | ||
} | ||
var insertAtPos; | ||
if (!programmaticInsert) { | ||
@@ -723,6 +820,8 @@ insertAtPos = this.mentionCharPos; | ||
} | ||
var delta = this.quill.insertEmbed(insertAtPos, options.blotName, render, Quill.sources.USER); | ||
if (options.spaceAfterInsert) { | ||
this.quill.insertText(insertAtPos + 1, " ", Quill.sources.USER); | ||
// setSelection here sets cursor position | ||
this.quill.insertText(insertAtPos + 1, " ", Quill.sources.USER); // setSelection here sets cursor position | ||
this.quill.setSelection(insertAtPos + 2, Quill.sources.USER); | ||
@@ -732,2 +831,3 @@ } else { | ||
} | ||
this.hideMentionList(); | ||
@@ -742,3 +842,5 @@ return delta; | ||
} | ||
var index = Number(e.target.dataset.index); | ||
if (!Number.isNaN(index) && index !== this.itemIndex) { | ||
@@ -755,2 +857,3 @@ this.itemIndex = index; | ||
} | ||
this.itemIndex = -1; | ||
@@ -765,2 +868,3 @@ this.highlightItem(false); | ||
} | ||
e.preventDefault(); | ||
@@ -782,5 +886,7 @@ e.stopImmediatePropagation(); | ||
var renderedLoading = this.options.renderLoading(); | ||
if (!renderedLoading) { | ||
return; | ||
} | ||
if (this.mentionContainer.getElementsByClassName("ql-mention-loading").length > 0) { | ||
@@ -790,2 +896,3 @@ this.showMentionList(); | ||
} | ||
this.mentionList.innerHTML = ""; | ||
@@ -802,2 +909,3 @@ var loadingDiv = document.createElement("div"); | ||
var loadingDiv = this.mentionContainer.getElementsByClassName("ql-mention-loading"); | ||
if (loadingDiv.length > 0) { | ||
@@ -815,2 +923,3 @@ loadingDiv[0].remove(); | ||
var initialSelection = -1; | ||
for (var i = 0; i < data.length; i += 1) { | ||
@@ -820,2 +929,3 @@ var li = document.createElement("li"); | ||
li.className = this.options.listItemClass ? this.options.listItemClass : ""; | ||
if (data[i].disabled) { | ||
@@ -827,4 +937,6 @@ li.className += " disabled"; | ||
} | ||
li.dataset.index = i; | ||
li.innerHTML = this.options.renderItem(data[i], searchTerm); | ||
if (!data[i].disabled) { | ||
@@ -837,5 +949,7 @@ li.onmouseenter = this.onItemMouseEnter.bind(this); | ||
} | ||
li.dataset.denotationChar = mentionChar; | ||
this.mentionList.appendChild(attachDataValues(li, data[i], this.options.dataAttributes)); | ||
} | ||
this.itemIndex = initialSelection; | ||
@@ -853,2 +967,3 @@ this.highlightItem(); | ||
var newIndex; | ||
do { | ||
@@ -858,2 +973,3 @@ increment++; | ||
var disabled = this.mentionList.childNodes[newIndex].dataset.disabled === "true"; | ||
if (increment === this.values.length + 1) { | ||
@@ -865,2 +981,3 @@ //we've wrapped around w/o finding an enabled item | ||
} while (disabled); | ||
this.itemIndex = newIndex; | ||
@@ -875,2 +992,3 @@ this.suspendMouseEnter = true; | ||
var newIndex; | ||
do { | ||
@@ -880,2 +998,3 @@ decrement++; | ||
var disabled = this.mentionList.childNodes[newIndex].dataset.disabled === "true"; | ||
if (decrement === this.values.length + 1) { | ||
@@ -887,2 +1006,3 @@ //we've wrapped around w/o finding an enabled item | ||
} while (disabled); | ||
this.itemIndex = newIndex; | ||
@@ -904,2 +1024,3 @@ this.suspendMouseEnter = true; | ||
} | ||
var rightPos = leftPos + this.mentionContainer.offsetWidth + containerPos.left; | ||
@@ -918,2 +1039,3 @@ var browserWidth = window.pageXOffset + document.documentElement.clientWidth; | ||
} | ||
this.isOpen = isOpen; | ||
@@ -935,2 +1057,3 @@ } | ||
var _this3 = this; | ||
var containerPos = this.quill.container.getBoundingClientRect(); | ||
@@ -940,5 +1063,4 @@ var mentionCharPos = this.quill.getBounds(this.mentionCharPos); | ||
var topPos = this.options.offsetTop; | ||
var leftPos = this.options.offsetLeft; | ||
var leftPos = this.options.offsetLeft; // handle horizontal positioning | ||
// handle horizontal positioning | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -950,2 +1072,3 @@ var rightPos = 0; | ||
} | ||
if (this.containerRightIsNotVisible(leftPos, containerPos)) { | ||
@@ -955,5 +1078,5 @@ var containerWidth = this.mentionContainer.offsetWidth + this.options.offsetLeft; | ||
leftPos = quillWidth - containerWidth; | ||
} | ||
} // handle vertical positioning | ||
// handle vertical positioning | ||
if (this.options.defaultMenuOrientation === "top") { | ||
@@ -965,7 +1088,8 @@ // Attempt to align the mention container with the top of the quill editor | ||
topPos = mentionCharPos.top - (containerHeight + this.options.offsetTop); | ||
} | ||
} // default to bottom if the top is not visible | ||
// default to bottom if the top is not visible | ||
if (topPos + containerPos.top <= 0) { | ||
var overMentionCharPos = this.options.offsetTop; | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -976,2 +1100,3 @@ overMentionCharPos += containerPos.height; | ||
} | ||
topPos = overMentionCharPos; | ||
@@ -985,16 +1110,20 @@ } | ||
topPos += mentionCharPos.bottom; | ||
} | ||
} // default to the top if the bottom is not visible | ||
// default to the top if the bottom is not visible | ||
if (this.containerBottomIsNotVisible(topPos, containerPos)) { | ||
var _overMentionCharPos = this.options.offsetTop * -1; | ||
if (!this.options.fixMentionsToQuill) { | ||
_overMentionCharPos += mentionCharPos.top; | ||
} | ||
topPos = _overMentionCharPos - containerHeight; | ||
} | ||
} | ||
if (topPos >= 0) { | ||
this.options.mentionContainerClass.split(' ').forEach(function (className) { | ||
_this3.mentionContainer.classList.add("".concat(className, "-bottom")); | ||
_this3.mentionContainer.classList.remove("".concat(className, "-top")); | ||
@@ -1005,5 +1134,7 @@ }); | ||
_this3.mentionContainer.classList.add("".concat(className, "-top")); | ||
_this3.mentionContainer.classList.remove("".concat(className, "-bottom")); | ||
}); | ||
} | ||
this.mentionContainer.style.top = "".concat(topPos, "px"); | ||
@@ -1017,2 +1148,3 @@ this.mentionContainer.style.left = "".concat(leftPos, "px"); | ||
var _this4 = this; | ||
this.mentionContainer.style.position = "fixed"; | ||
@@ -1027,10 +1159,8 @@ this.mentionContainer.style.height = null; | ||
height: mentionCharPos.height | ||
}; | ||
}; //Which rectangle should it be relative to | ||
//Which rectangle should it be relative to | ||
var relativeToPos = this.options.fixMentionsToQuill ? containerPos : mentionCharPosAbsolute; | ||
var topPos = this.options.offsetTop; | ||
var leftPos = this.options.offsetLeft; | ||
var leftPos = this.options.offsetLeft; // handle horizontal positioning | ||
// handle horizontal positioning | ||
if (this.options.fixMentionsToQuill) { | ||
@@ -1040,5 +1170,4 @@ var rightPos = relativeToPos.right; | ||
} else { | ||
leftPos += relativeToPos.left; | ||
leftPos += relativeToPos.left; //if its off the righ edge, push it back | ||
//if its off the righ edge, push it back | ||
if (leftPos + this.mentionContainer.offsetWidth > document.documentElement.clientWidth) { | ||
@@ -1048,2 +1177,3 @@ leftPos -= leftPos + this.mentionContainer.offsetWidth - document.documentElement.clientWidth; | ||
} | ||
var availableSpaceTop = relativeToPos.top; | ||
@@ -1054,2 +1184,3 @@ var availableSpaceBottom = document.documentElement.clientHeight - (relativeToPos.top + relativeToPos.height); | ||
var placement; | ||
if (this.options.defaultMenuOrientation === "top" && fitsTop) { | ||
@@ -1063,4 +1194,6 @@ placement = "top"; | ||
} | ||
if (placement === "bottom") { | ||
topPos = relativeToPos.top + relativeToPos.height; | ||
if (!fitsBottom) { | ||
@@ -1071,4 +1204,6 @@ //shrink it to fit | ||
} | ||
this.options.mentionContainerClass.split(" ").forEach(function (className) { | ||
_this4.mentionContainer.classList.add("".concat(className, "-bottom")); | ||
_this4.mentionContainer.classList.remove("".concat(className, "-top")); | ||
@@ -1078,2 +1213,3 @@ }); | ||
topPos = relativeToPos.top - this.mentionContainer.offsetHeight; | ||
if (!fitsTop) { | ||
@@ -1085,7 +1221,10 @@ //shrink it to fit | ||
} | ||
this.options.mentionContainerClass.split(" ").forEach(function (className) { | ||
_this4.mentionContainer.classList.add("".concat(className, "-top")); | ||
_this4.mentionContainer.classList.remove("".concat(className, "-bottom")); | ||
}); | ||
} | ||
this.mentionContainer.style.top = "".concat(topPos, "px"); | ||
@@ -1106,2 +1245,3 @@ this.mentionContainer.style.left = "".concat(leftPos, "px"); | ||
var _this5 = this; | ||
var range = this.quill.getSelection(); | ||
@@ -1113,5 +1253,7 @@ if (range == null) return; | ||
var textPrefix = textOffset ? this.quill.getText(textOffset - 1, textOffset) : ''; | ||
var _getMentionCharIndex = getMentionCharIndex(textBeforeCursor, this.options.mentionDenotationChars, this.options.isolateCharacter, this.options.allowInlineMentionChar), | ||
mentionChar = _getMentionCharIndex.mentionChar, | ||
mentionCharIndex = _getMentionCharIndex.mentionCharIndex; | ||
mentionChar = _getMentionCharIndex.mentionChar, | ||
mentionCharIndex = _getMentionCharIndex.mentionCharIndex; | ||
if (hasValidMentionCharIndex(mentionCharIndex, textBeforeCursor, this.options.isolateCharacter, textPrefix)) { | ||
@@ -1121,2 +1263,3 @@ var mentionCharPos = this.cursorPos - (textBeforeCursor.length - mentionCharIndex); | ||
var textAfter = textBeforeCursor.substring(mentionCharIndex + mentionChar.length); | ||
if (textAfter.length >= this.options.minChars && hasValidChars(textAfter, this.getAllowedCharsRegex(mentionChar))) { | ||
@@ -1126,2 +1269,3 @@ if (this.existingSourceExecutionToken) { | ||
} | ||
this.renderLoading(); | ||
@@ -1136,3 +1280,5 @@ var sourceRequestToken = { | ||
} | ||
_this5.existingSourceExecutionToken = null; | ||
_this5.renderList(mentionChar, data, searchTerm); | ||
@@ -1144,2 +1290,3 @@ }, mentionChar); | ||
} | ||
this.hideMentionList(); | ||
@@ -1151,2 +1298,3 @@ } | ||
} | ||
this.hideMentionList(); | ||
@@ -1189,6 +1337,8 @@ } | ||
}]); | ||
return Mention; | ||
}(); | ||
Quill.register("modules/mention", Mention); | ||
export { Mention as default }; |
@@ -1,1 +0,1 @@ | ||
var quillMention=function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){l(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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,g(i.key),i)}}function a(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function l(t,e,n){return(e=g(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(){return h=Object.assign?Object.assign.bind():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},h.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}function d(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=u(t);if(e){var o=u(this).constructor;n=Reflect.construct(i,arguments,o)}else n=i.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return d(t)}(this,n)}}function m(){return m="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=u(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},m.apply(this,arguments)}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function v(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return p(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,o=function(){};return{s:o,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,r=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return r=t.done,t},e:function(t){a=!0,s=t},f:function(){try{r||null==n.return||n.return()}finally{if(a)throw s}}}}function g(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var y=9,b=13,C=27,x=38,k=40;function I(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 L=function(t){!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}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(n,t);var e=f(n);function n(t,i){var o;return s(this,n),l(d(o=e.call(this,t,i)),"hoverHandler",void 0),l(d(o),"hoverHandler",void 0),o.clickHandler=null,o.hoverHandler=null,o.mounted=!1,o}return a(n,[{key:"attach",value:function(){m(u(n.prototype),"attach",this).call(this),this.mounted||(this.mounted=!0,this.clickHandler=this.getClickHandler(),this.hoverHandler=this.getHoverHandler(),this.domNode.addEventListener("click",this.clickHandler,!1),this.domNode.addEventListener("mouseenter",this.hoverHandler,!1))}},{key:"detach",value:function(){m(u(n.prototype),"detach",this).call(this),this.mounted=!1,this.clickHandler&&(this.domNode.removeEventListener("click",this.clickHandler),this.clickHandler=null)}},{key:"getClickHandler",value:function(){var t=this;return function(e){var n=t.buildEvent("mention-clicked",e);window.dispatchEvent(n),e.preventDefault()}}},{key:"getHoverHandler",value:function(){var t=this;return function(e){var n=t.buildEvent("mention-hovered",e);window.dispatchEvent(n),e.preventDefault()}}},{key:"buildEvent",value:function(t,e){var n=new Event(t,{bubbles:!0,cancelable:!0});return n.value=h({},this.domNode.dataset),n.event=e,n}}],[{key:"create",value:function(t){var e=m(u(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}(n.default.import("blots/embed"));L.blotName="mention",L.tagName="span",L.className="mention",n.default.register(L);var E=function(){function t(e,n){var i=this;for(var o in s(this,t),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.existingSourceExecutionToken=null,this.quill=e,this.options={source:null,renderItem:function(t){return"".concat(t.value)},renderLoading:function(){return null},onSelect:function(t,e){e(t)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,allowInlineMentionChar:!1,fixMentionsToQuill:!1,positioningStrategy:"normal",defaultMenuOrientation:"bottom",blotName:"mention",dataAttributes:["id","value","denotationChar","link","target","disabled"],linkTarget:"_blank",onOpen:function(){return!0},onBeforeClose:function(){return!0},onClose:function(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0,selectKeys:[b]},h(this.options,n,{dataAttributes:Array.isArray(n.dataAttributes)?this.options.dataAttributes.concat(n.dataAttributes):this.options.dataAttributes}),this.options)"function"==typeof this.options[o]&&(this.options[o]=this.options[o].bind(this));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.id="quill-mention-list",e.root.setAttribute("aria-owns","quill-mention-list"),this.mentionList.className=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList),e.on("text-change",this.onTextChange.bind(this)),e.on("selection-change",this.onSelectionChange.bind(this)),e.container.addEventListener("paste",(function(){setTimeout((function(){var t=e.getSelection();i.onSelectionChange(t)}))})),e.keyboard.addBinding({key:y},this.selectHandler.bind(this)),e.keyboard.bindings[y].unshift(e.keyboard.bindings[y].pop());var r,a=v(this.options.selectKeys);try{for(a.s();!(r=a.n()).done;){var l=r.value;e.keyboard.addBinding({key:l},this.selectHandler.bind(this))}}catch(t){a.e(t)}finally{a.f()}e.keyboard.bindings[b].unshift(e.keyboard.bindings[b].pop()),e.keyboard.addBinding({key:C},this.escapeHandler.bind(this)),e.keyboard.addBinding({key:x},this.upHandler.bind(this)),e.keyboard.addBinding({key:k},this.downHandler.bind(this))}return a(t,[{key:"selectHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.selectItem(),!1)}},{key:"escapeHandler",value:function(){return!this.isOpen||(this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList(),!1)}},{key:"upHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.prevItem(),!1)}},{key:"downHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.nextItem(),!1)}},{key:"showMentionList",value:function(){"fixed"===this.options.positioningStrategy?document.body.appendChild(this.mentionContainer):this.quill.container.appendChild(this.mentionContainer),this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.mentionContainer.scrollTop=0,this.setMentionContainerPosition(),this.setIsOpen(!0)}},{key:"hideMentionList",value:function(){this.options.onBeforeClose(),this.mentionContainer.style.display="none",this.mentionContainer.remove(),this.setIsOpen(!1),this.quill.root.removeAttribute("aria-activedescendant")}},{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(-1!==this.itemIndex&&"true"!==this.mentionList.childNodes[this.itemIndex].dataset.disabled&&(this.mentionList.childNodes[this.itemIndex].classList.add("selected"),this.quill.root.setAttribute("aria-activedescendant",this.mentionList.childNodes[this.itemIndex].id),t)){var n=this.mentionList.childNodes[this.itemIndex].offsetHeight,i=this.mentionList.childNodes[this.itemIndex].offsetTop,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;if(-1!==this.itemIndex){var e=this.getItemData();e.disabled||(this.options.onSelect(e,(function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.insertItem(e,n,i)})),this.hideMentionList())}}},{key:"insertItem",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=t;if(null!==s){var r,a=o(o({},this.options),i);a.showDenotationChar||(s.denotationChar=""),e?r=this.cursorPos:(r=this.mentionCharPos,this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,n.default.sources.USER));var l=this.quill.insertEmbed(r,a.blotName,s,n.default.sources.USER);return a.spaceAfterInsert?(this.quill.insertText(r+1," ",n.default.sources.USER),this.quill.setSelection(r+2,n.default.sources.USER)):this.quill.setSelection(r+1,n.default.sources.USER),this.hideMentionList(),l}}},{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:"onDisabledItemMouseEnter",value:function(t){this.suspendMouseEnter||(this.itemIndex=-1,this.highlightItem(!1))}},{key:"onItemClick",value:function(t){0===t.button&&(t.preventDefault(),t.stopImmediatePropagation(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem())}},{key:"onItemMouseDown",value:function(t){t.preventDefault(),t.stopImmediatePropagation()}},{key:"renderLoading",value:function(){if(this.options.renderLoading())if(this.mentionContainer.getElementsByClassName("ql-mention-loading").length>0)this.showMentionList();else{this.mentionList.innerHTML="";var t=document.createElement("div");t.className="ql-mention-loading",t.innerHTML=this.options.renderLoading(),this.mentionContainer.append(t),this.showMentionList()}}},{key:"removeLoading",value:function(){var t=this.mentionContainer.getElementsByClassName("ql-mention-loading");t.length>0&&t[0].remove()}},{key:"renderList",value:function(t,e,n){if(e&&e.length>0){this.removeLoading(),this.values=e,this.mentionList.innerHTML="";for(var i=-1,o=0;o<e.length;o+=1){var s=document.createElement("li");s.id="quill-mention-item-"+o,s.className=this.options.listItemClass?this.options.listItemClass:"",e[o].disabled?(s.className+=" disabled",s.setAttribute("aria-hidden","true")):-1===i&&(i=o),s.dataset.index=o,s.innerHTML=this.options.renderItem(e[o],n),e[o].disabled?s.onmouseenter=this.onDisabledItemMouseEnter.bind(this):(s.onmouseenter=this.onItemMouseEnter.bind(this),s.onmouseup=this.onItemClick.bind(this),s.onmousedown=this.onItemMouseDown.bind(this)),s.dataset.denotationChar=t,this.mentionList.appendChild(I(s,e[o],this.options.dataAttributes))}this.itemIndex=i,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}},{key:"nextItem",value:function(){var t,e=0;do{e++,t=(this.itemIndex+e)%this.values.length;var n="true"===this.mentionList.childNodes[t].dataset.disabled;if(e===this.values.length+1){t=-1;break}}while(n);this.itemIndex=t,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"prevItem",value:function(){var t,e=0;do{e++,t=(this.itemIndex+this.values.length-e)%this.values.length;var n="true"===this.mentionList.childNodes[t].dataset.disabled;if(e===this.values.length+1){t=-1;break}}while(n);this.itemIndex=t,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(){"fixed"===this.options.positioningStrategy?this.setMentionContainerPosition_Fixed():this.setMentionContainerPosition_Normal()}},{key:"setMentionContainerPosition_Normal",value:function(){var t=this,e=this.quill.container.getBoundingClientRect(),n=this.quill.getBounds(this.mentionCharPos),i=this.mentionContainer.offsetHeight,o=this.options.offsetTop,s=this.options.offsetLeft;if(this.options.fixMentionsToQuill){this.mentionContainer.style.right="".concat(0,"px")}else s+=n.left;if(this.containerRightIsNotVisible(s,e)){var r=this.mentionContainer.offsetWidth+this.options.offsetLeft;s=e.width-r}if("top"===this.options.defaultMenuOrientation){if((o=this.options.fixMentionsToQuill?-1*(i+this.options.offsetTop):n.top-(i+this.options.offsetTop))+e.top<=0){var a=this.options.offsetTop;this.options.fixMentionsToQuill?a+=e.height:a+=n.bottom,o=a}}else if(this.options.fixMentionsToQuill?o+=e.height:o+=n.bottom,this.containerBottomIsNotVisible(o,e)){var l=-1*this.options.offsetTop;this.options.fixMentionsToQuill||(l+=n.top),o=l-i}o>=0?this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-bottom")),t.mentionContainer.classList.remove("".concat(e,"-top"))})):this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-top")),t.mentionContainer.classList.remove("".concat(e,"-bottom"))})),this.mentionContainer.style.top="".concat(o,"px"),this.mentionContainer.style.left="".concat(s,"px"),this.mentionContainer.style.visibility="visible"}},{key:"setMentionContainerPosition_Fixed",value:function(){var t=this;this.mentionContainer.style.position="fixed",this.mentionContainer.style.height=null;var e=this.quill.container.getBoundingClientRect(),n=this.quill.getBounds(this.mentionCharPos),i={left:e.left+n.left,top:e.top+n.top,width:0,height:n.height},o=this.options.fixMentionsToQuill?e:i,s=this.options.offsetTop,r=this.options.offsetLeft;if(this.options.fixMentionsToQuill){var a=o.right;this.mentionContainer.style.right="".concat(a,"px")}else(r+=o.left)+this.mentionContainer.offsetWidth>document.documentElement.clientWidth&&(r-=r+this.mentionContainer.offsetWidth-document.documentElement.clientWidth);var l=o.top,h=document.documentElement.clientHeight-(o.top+o.height),u=this.mentionContainer.offsetHeight<=h,c=this.mentionContainer.offsetHeight<=l;"bottom"===("top"===this.options.defaultMenuOrientation&&c?"top":"bottom"===this.options.defaultMenuOrientation&&u||h>l?"bottom":"top")?(s=o.top+o.height,u||(this.mentionContainer.style.height=h-3+"px"),this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-bottom")),t.mentionContainer.classList.remove("".concat(e,"-top"))}))):(s=o.top-this.mentionContainer.offsetHeight,c||(this.mentionContainer.style.height=l-3+"px",s=3),this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-top")),t.mentionContainer.classList.remove("".concat(e,"-bottom"))}))),this.mentionContainer.style.top="".concat(s,"px"),this.mentionContainer.style.left="".concat(r,"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,e=this.quill.getSelection();if(null!=e){this.cursorPos=e.index;var n,i,o,s,r=this.getTextBeforeCursor(),a=Math.max(0,this.cursorPos-this.options.maxChars),l=a?this.quill.getText(a-1,a):"",h=(n=r,i=this.options.mentionDenotationChars,o=this.options.isolateCharacter,s=this.options.allowInlineMentionChar,i.reduce((function(t,e){var i;if(o&&s){var r=new RegExp("^".concat(e,"|\\s").concat(e),"g"),a=(n.match(r)||[]).pop();if(!a)return{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex};i=a!==e?n.lastIndexOf(a)+a.length-e.length:0}else i=n.lastIndexOf(e);return i>t.mentionCharIndex?{mentionChar:e,mentionCharIndex:i}:{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex}}),{mentionChar:null,mentionCharIndex:-1})),u=h.mentionChar,c=h.mentionCharIndex;if(function(t,e,n,i){if(-1===t)return!1;if(!n)return!0;var o=t?e[t-1]:i;return!o||!!o.match(/\s/)}(c,r,this.options.isolateCharacter,l)){var d=this.cursorPos-(r.length-c);this.mentionCharPos=d;var f=r.substring(c+u.length);if(f.length>=this.options.minChars&&function(t,e){return e.test(t)}(f,this.getAllowedCharsRegex(u))){this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.renderLoading();var m={abandoned:!1};this.existingSourceExecutionToken=m,this.options.source(f,(function(e,n){m.abandoned||(t.existingSourceExecutionToken=null,t.renderList(u,e,n))}),u)}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}}},{key:"getAllowedCharsRegex",value:function(t){return this.options.allowedChars instanceof RegExp?this.options.allowedChars:this.options.allowedChars(t)}},{key:"onTextChange",value:function(t,e,n){"user"===n&&this.onSomethingChange()}},{key:"onSelectionChange",value:function(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}},{key:"openMenu",value:function(t){var e=this.quill.getSelection(!0);this.quill.insertText(e.index,t),this.quill.blur(),this.quill.focus()}}]),t}();return n.default.register("modules/mention",E),E}(Quill); | ||
var quillMention=function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){l(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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 a(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(){return h=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},h.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function c(t,e){return c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},c(t,e)}function d(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return d(t)}function m(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=u(t);if(e){var o=u(this).constructor;n=Reflect.construct(i,arguments,o)}else n=i.apply(this,arguments);return f(this,n)}}function p(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=u(t)););return t}function v(){return v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=p(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},v.apply(this,arguments)}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function y(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return g(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?g(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,o=function(){};return{s:o,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,r=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return r=t.done,t},e:function(t){a=!0,s=t},f:function(){try{r||null==n.return||n.return()}finally{if(a)throw s}}}}var C=9,b=13,x=27,k=38,I=40;function L(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 E=function(t){!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&&c(t,e)}(n,t);var e=m(n);function n(t,i){var o;return s(this,n),l(d(o=e.call(this,t,i)),"hoverHandler",void 0),l(d(o),"hoverHandler",void 0),o.clickHandler=null,o.hoverHandler=null,o.mounted=!1,o}return a(n,[{key:"attach",value:function(){v(u(n.prototype),"attach",this).call(this),this.mounted||(this.mounted=!0,this.clickHandler=this.getClickHandler(),this.hoverHandler=this.getHoverHandler(),this.domNode.addEventListener("click",this.clickHandler,!1),this.domNode.addEventListener("mouseenter",this.hoverHandler,!1))}},{key:"detach",value:function(){v(u(n.prototype),"detach",this).call(this),this.mounted=!1,this.clickHandler&&(this.domNode.removeEventListener("click",this.clickHandler),this.clickHandler=null)}},{key:"getClickHandler",value:function(){var t=this;return function(e){var n=t.buildEvent("mention-clicked",e);window.dispatchEvent(n),e.preventDefault()}}},{key:"getHoverHandler",value:function(){var t=this;return function(e){var n=t.buildEvent("mention-hovered",e);window.dispatchEvent(n),e.preventDefault()}}},{key:"buildEvent",value:function(t,e){var n=new Event(t,{bubbles:!0,cancelable:!0});return n.value=h({},this.domNode.dataset),n.event=e,n}}],[{key:"create",value:function(t){var e=v(u(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}(n.default.import("blots/embed"));E.blotName="mention",E.tagName="span",E.className="mention",n.default.register(E);var w=function(){function t(e,n){var i=this;for(var o in s(this,t),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.existingSourceExecutionToken=null,this.quill=e,this.options={source:null,renderItem:function(t){return"".concat(t.value)},renderLoading:function(){return null},onSelect:function(t,e){e(t)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,allowInlineMentionChar:!1,fixMentionsToQuill:!1,positioningStrategy:"normal",defaultMenuOrientation:"bottom",blotName:"mention",dataAttributes:["id","value","denotationChar","link","target","disabled"],linkTarget:"_blank",onOpen:function(){return!0},onBeforeClose:function(){return!0},onClose:function(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0,selectKeys:[b]},h(this.options,n,{dataAttributes:Array.isArray(n.dataAttributes)?this.options.dataAttributes.concat(n.dataAttributes):this.options.dataAttributes}),this.options)"function"==typeof this.options[o]&&(this.options[o]=this.options[o].bind(this));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.id="quill-mention-list",e.root.setAttribute("aria-owns","quill-mention-list"),this.mentionList.className=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList),e.on("text-change",this.onTextChange.bind(this)),e.on("selection-change",this.onSelectionChange.bind(this)),e.container.addEventListener("paste",(function(){setTimeout((function(){var t=e.getSelection();i.onSelectionChange(t)}))})),e.keyboard.addBinding({key:C},this.selectHandler.bind(this)),e.keyboard.bindings[C].unshift(e.keyboard.bindings[C].pop());var r,a=y(this.options.selectKeys);try{for(a.s();!(r=a.n()).done;){var l=r.value;e.keyboard.addBinding({key:l},this.selectHandler.bind(this))}}catch(t){a.e(t)}finally{a.f()}e.keyboard.bindings[b].unshift(e.keyboard.bindings[b].pop()),e.keyboard.addBinding({key:x},this.escapeHandler.bind(this)),e.keyboard.addBinding({key:k},this.upHandler.bind(this)),e.keyboard.addBinding({key:I},this.downHandler.bind(this))}return a(t,[{key:"selectHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.selectItem(),!1)}},{key:"escapeHandler",value:function(){return!this.isOpen||(this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList(),!1)}},{key:"upHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.prevItem(),!1)}},{key:"downHandler",value:function(){return!(this.isOpen&&!this.existingSourceExecutionToken)||(this.nextItem(),!1)}},{key:"showMentionList",value:function(){"fixed"===this.options.positioningStrategy?document.body.appendChild(this.mentionContainer):this.quill.container.appendChild(this.mentionContainer),this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.mentionContainer.scrollTop=0,this.setMentionContainerPosition(),this.setIsOpen(!0)}},{key:"hideMentionList",value:function(){this.options.onBeforeClose(),this.mentionContainer.style.display="none",this.mentionContainer.remove(),this.setIsOpen(!1),this.quill.root.removeAttribute("aria-activedescendant")}},{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(-1!==this.itemIndex&&"true"!==this.mentionList.childNodes[this.itemIndex].dataset.disabled&&(this.mentionList.childNodes[this.itemIndex].classList.add("selected"),this.quill.root.setAttribute("aria-activedescendant",this.mentionList.childNodes[this.itemIndex].id),t)){var n=this.mentionList.childNodes[this.itemIndex].offsetHeight,i=this.mentionList.childNodes[this.itemIndex].offsetTop,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;if(-1!==this.itemIndex){var e=this.getItemData();e.disabled||(this.options.onSelect(e,(function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.insertItem(e,n,i)})),this.hideMentionList())}}},{key:"insertItem",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=t;if(null!==s){var r,a=o(o({},this.options),i);a.showDenotationChar||(s.denotationChar=""),e?r=this.cursorPos:(r=this.mentionCharPos,this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,n.default.sources.USER));var l=this.quill.insertEmbed(r,a.blotName,s,n.default.sources.USER);return a.spaceAfterInsert?(this.quill.insertText(r+1," ",n.default.sources.USER),this.quill.setSelection(r+2,n.default.sources.USER)):this.quill.setSelection(r+1,n.default.sources.USER),this.hideMentionList(),l}}},{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:"onDisabledItemMouseEnter",value:function(t){this.suspendMouseEnter||(this.itemIndex=-1,this.highlightItem(!1))}},{key:"onItemClick",value:function(t){0===t.button&&(t.preventDefault(),t.stopImmediatePropagation(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem())}},{key:"onItemMouseDown",value:function(t){t.preventDefault(),t.stopImmediatePropagation()}},{key:"renderLoading",value:function(){if(this.options.renderLoading())if(this.mentionContainer.getElementsByClassName("ql-mention-loading").length>0)this.showMentionList();else{this.mentionList.innerHTML="";var t=document.createElement("div");t.className="ql-mention-loading",t.innerHTML=this.options.renderLoading(),this.mentionContainer.append(t),this.showMentionList()}}},{key:"removeLoading",value:function(){var t=this.mentionContainer.getElementsByClassName("ql-mention-loading");t.length>0&&t[0].remove()}},{key:"renderList",value:function(t,e,n){if(e&&e.length>0){this.removeLoading(),this.values=e,this.mentionList.innerHTML="";for(var i=-1,o=0;o<e.length;o+=1){var s=document.createElement("li");s.id="quill-mention-item-"+o,s.className=this.options.listItemClass?this.options.listItemClass:"",e[o].disabled?(s.className+=" disabled",s.setAttribute("aria-hidden","true")):-1===i&&(i=o),s.dataset.index=o,s.innerHTML=this.options.renderItem(e[o],n),e[o].disabled?s.onmouseenter=this.onDisabledItemMouseEnter.bind(this):(s.onmouseenter=this.onItemMouseEnter.bind(this),s.onmouseup=this.onItemClick.bind(this),s.onmousedown=this.onItemMouseDown.bind(this)),s.dataset.denotationChar=t,this.mentionList.appendChild(L(s,e[o],this.options.dataAttributes))}this.itemIndex=i,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}},{key:"nextItem",value:function(){var t,e=0;do{e++,t=(this.itemIndex+e)%this.values.length;var n="true"===this.mentionList.childNodes[t].dataset.disabled;if(e===this.values.length+1){t=-1;break}}while(n);this.itemIndex=t,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"prevItem",value:function(){var t,e=0;do{e++,t=(this.itemIndex+this.values.length-e)%this.values.length;var n="true"===this.mentionList.childNodes[t].dataset.disabled;if(e===this.values.length+1){t=-1;break}}while(n);this.itemIndex=t,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(){"fixed"===this.options.positioningStrategy?this.setMentionContainerPosition_Fixed():this.setMentionContainerPosition_Normal()}},{key:"setMentionContainerPosition_Normal",value:function(){var t=this,e=this.quill.container.getBoundingClientRect(),n=this.quill.getBounds(this.mentionCharPos),i=this.mentionContainer.offsetHeight,o=this.options.offsetTop,s=this.options.offsetLeft;if(this.options.fixMentionsToQuill){this.mentionContainer.style.right="".concat(0,"px")}else s+=n.left;if(this.containerRightIsNotVisible(s,e)){var r=this.mentionContainer.offsetWidth+this.options.offsetLeft;s=e.width-r}if("top"===this.options.defaultMenuOrientation){if((o=this.options.fixMentionsToQuill?-1*(i+this.options.offsetTop):n.top-(i+this.options.offsetTop))+e.top<=0){var a=this.options.offsetTop;this.options.fixMentionsToQuill?a+=e.height:a+=n.bottom,o=a}}else if(this.options.fixMentionsToQuill?o+=e.height:o+=n.bottom,this.containerBottomIsNotVisible(o,e)){var l=-1*this.options.offsetTop;this.options.fixMentionsToQuill||(l+=n.top),o=l-i}o>=0?this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-bottom")),t.mentionContainer.classList.remove("".concat(e,"-top"))})):this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-top")),t.mentionContainer.classList.remove("".concat(e,"-bottom"))})),this.mentionContainer.style.top="".concat(o,"px"),this.mentionContainer.style.left="".concat(s,"px"),this.mentionContainer.style.visibility="visible"}},{key:"setMentionContainerPosition_Fixed",value:function(){var t=this;this.mentionContainer.style.position="fixed",this.mentionContainer.style.height=null;var e=this.quill.container.getBoundingClientRect(),n=this.quill.getBounds(this.mentionCharPos),i={left:e.left+n.left,top:e.top+n.top,width:0,height:n.height},o=this.options.fixMentionsToQuill?e:i,s=this.options.offsetTop,r=this.options.offsetLeft;if(this.options.fixMentionsToQuill){var a=o.right;this.mentionContainer.style.right="".concat(a,"px")}else(r+=o.left)+this.mentionContainer.offsetWidth>document.documentElement.clientWidth&&(r-=r+this.mentionContainer.offsetWidth-document.documentElement.clientWidth);var l=o.top,h=document.documentElement.clientHeight-(o.top+o.height),u=this.mentionContainer.offsetHeight<=h,c=this.mentionContainer.offsetHeight<=l;"bottom"===("top"===this.options.defaultMenuOrientation&&c?"top":"bottom"===this.options.defaultMenuOrientation&&u||h>l?"bottom":"top")?(s=o.top+o.height,u||(this.mentionContainer.style.height=h-3+"px"),this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-bottom")),t.mentionContainer.classList.remove("".concat(e,"-top"))}))):(s=o.top-this.mentionContainer.offsetHeight,c||(this.mentionContainer.style.height=l-3+"px",s=3),this.options.mentionContainerClass.split(" ").forEach((function(e){t.mentionContainer.classList.add("".concat(e,"-top")),t.mentionContainer.classList.remove("".concat(e,"-bottom"))}))),this.mentionContainer.style.top="".concat(s,"px"),this.mentionContainer.style.left="".concat(r,"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,e=this.quill.getSelection();if(null!=e){this.cursorPos=e.index;var n,i,o,s,r=this.getTextBeforeCursor(),a=Math.max(0,this.cursorPos-this.options.maxChars),l=a?this.quill.getText(a-1,a):"",h=(n=r,i=this.options.mentionDenotationChars,o=this.options.isolateCharacter,s=this.options.allowInlineMentionChar,i.reduce((function(t,e){var i;if(o&&s){var r=new RegExp("^".concat(e,"|\\s").concat(e),"g"),a=(n.match(r)||[]).pop();if(!a)return{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex};i=a!==e?n.lastIndexOf(a)+a.length-e.length:0}else i=n.lastIndexOf(e);return i>t.mentionCharIndex?{mentionChar:e,mentionCharIndex:i}:{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex}}),{mentionChar:null,mentionCharIndex:-1})),u=h.mentionChar,c=h.mentionCharIndex;if(function(t,e,n,i){if(-1===t)return!1;if(!n)return!0;var o=t?e[t-1]:i;return!o||!!o.match(/\s/)}(c,r,this.options.isolateCharacter,l)){var d=this.cursorPos-(r.length-c);this.mentionCharPos=d;var f=r.substring(c+u.length);if(f.length>=this.options.minChars&&function(t,e){return e.test(t)}(f,this.getAllowedCharsRegex(u))){this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.renderLoading();var m={abandoned:!1};this.existingSourceExecutionToken=m,this.options.source(f,(function(e,n){m.abandoned||(t.existingSourceExecutionToken=null,t.renderList(u,e,n))}),u)}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}}},{key:"getAllowedCharsRegex",value:function(t){return this.options.allowedChars instanceof RegExp?this.options.allowedChars:this.options.allowedChars(t)}},{key:"onTextChange",value:function(t,e,n){"user"===n&&this.onSomethingChange()}},{key:"onSelectionChange",value:function(t){t&&0===t.length?this.onSomethingChange():this.hideMentionList()}},{key:"openMenu",value:function(t){var e=this.quill.getSelection(!0);this.quill.insertText(e.index,t),this.quill.blur(),this.quill.focus()}}]),t}();return n.default.register("modules/mention",w),w}(Quill); |
{ | ||
"name": "quill-mention", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "@mentions for the Quill rich text editor", | ||
@@ -36,3 +36,3 @@ "homepage": "https://quill-mention.com/", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"serve": "^12.0.1" | ||
"serve": "^14.2.1" | ||
}, | ||
@@ -39,0 +39,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
114204
2245