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

quill-placeholder-autocomplete-module

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quill-placeholder-autocomplete-module - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

.nvmrc

2

dist/quill-placeholder-autocomplete-module.min.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.QuillPlaceholderAutocomplete=t():e.QuillPlaceholderAutocomplete=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),e.exports=n(2)},function(e,t){},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o,i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=n(3),s=n(4),l=(o=s)&&o.__esModule?o:{default:o};t.default=function(e){var t=e.import("delta");return e.register("formats/suggest",(0,l.default)(e)),function(){function n(e,t){var o=this,i=t.onClose,s=t.onOpen,l=t.getPlaceholders,a=t.container;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this.quill=e,this.onClose=i,this.onOpen=s,this.getPlaceholders=l,"string"==typeof a?this.container=this.quill.container.parentNode.querySelector(a):void 0===a?(this.container=(0,r.h)("ul",{}),this.quill.container.parentNode.appendChild(this.container)):this.container=a,this.container.classList.add("ql-autocomplete-menu","completions"),this.container.style.position="absolute",this.container.style.display="none",this.onSelectionChange=this.maybeUnfocus.bind(this),this.onTextChange=this.update.bind(this),this.open=!1,this.quill.suggestsDialogOpen=!1,this.hashIndex=null,this.focusedButton=null,this.buttons=[],this.placeholders=[],this.toolbarHeight=0,e.keyboard.addBinding({key:51,altKey:!0,ctrlKey:null},this.onHashKey.bind(this)),e.root.addEventListener("keydown",function(e){e.defaultPrevented||"#"===e.key&&(o.toolbarHeight||(o.toolbarHeight=o.quill.getModule("toolbar").container.offsetHeight),o.onHashKey(o.quill.getSelection()),e.preventDefault())},!0),e.keyboard.addBinding({key:40,collapsed:!0,format:["suggest"]},this.handleArrow.bind(this)),e.keyboard.addBinding({key:27,collapsed:null,format:["suggest"]},this.handleEscape.bind(this)),e.suggestHandler=this.handleEnterTab.bind(this)}return i(n,[{key:"onHashKey",value:function(t,n){if(this.open)return!0;t.length>0&&this.quill.deleteText(t.index,t.length,e.sources.USER),this.quill.insertText(t.index,"#","suggest","@@placeholder",e.sources.USER);var o=this.quill.getBounds(t.index);this.quill.setSelection(t.index+1,e.sources.SILENT),this.hashIndex=t.index,this.container.style.left=o.left+"px",this.container.style.top=o.top+o.height+this.toolbarHeight+2+"px",this.open=!0,this.quill.suggestsDialogOpen=!0,this.quill.on("text-change",this.onTextChange),this.quill.once("selection-change",this.onSelectionChange),this.update(),this.onOpen&&this.onOpen()}},{key:"handleArrow",value:function(){if(!this.open)return!0;this.buttons[0].focus()}},{key:"handleEnterTab",value:function(){if(!this.open)return!0;this.close(this.placeholders[0])}},{key:"handleEscape",value:function(){if(!this.open)return!0;this.close()}},{key:"emptyCompletionsContainer",value:function(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},{key:"update",value:function(){var e=this,t=this.quill.getSelection().index;if(this.hashIndex>=t)return this.close(null);this.originalQuery=this.quill.getText(this.hashIndex+1,t-this.hashIndex-1),this.query=this.originalQuery.toLowerCase(),this.placeholders=this.getPlaceholders().filter(function(t){return t.label.toLowerCase().startsWith(e.query)}).sort(function(e,t){return e.label>t.label}),this.renderCompletions(this.placeholders)}},{key:"maybeUnfocus",value:function(){this.container.querySelector("*:focus")||this.close(null)}},{key:"renderCompletions",value:function(e){var t=this;this.emptyCompletionsContainer();var n=Array(e.length);this.buttons=n;e.forEach(function(e,o){var i=(0,r.h)("li",{},(0,r.h)("button",{type:"button"},(0,r.h)("span",{className:"matched"},"#"+e.label.slice(0,t.query.length)),(0,r.h)("span",{className:"unmatched"},e.label.slice(t.query.length))));t.container.appendChild(i),n[o]=i.firstChild,n[o].addEventListener("keydown",function(e,o){return function(i){"ArrowDown"===i.key||40===i.keyCode?(i.preventDefault(),n[Math.min(n.length-1,e+1)].focus()):"ArrowUp"===i.key||38===i.keyCode?(i.preventDefault(),n[Math.max(0,e-1)].focus()):"Enter"===i.key||13===i.keyCode||" "===i.key||32===i.keyCode||"Tab"===i.key||9===i.keyCode?(i.preventDefault(),t.close(o)):"Escape"!==i.key&&27!==i.keyCode||(i.preventDefault(),t.close())}}(o,e)),n[o].addEventListener("mousedown",function(){return t.close(e)}),n[o].addEventListener("focus",function(){return t.focusedButton=o}),n[o].addEventListener("unfocus",function(){return t.focusedButton=null})}),this.container.style.display="block"}},{key:"close",value:function(n){this.container.style.display="none",this.emptyCompletionsContainer(),this.quill.off("selection-change",this.onSelectionChange),this.quill.off("text-change",this.onTextChange);var o=(new t).retain(this.hashIndex).delete(this.query.length+1);this.quill.updateContents(o,e.sources.USER),n&&(this.quill.insertEmbed(this.hashIndex,"placeholder",n,e.sources.USER),this.quill.setSelection(this.hashIndex+1,0,e.sources.SILENT)),this.quill.focus(),this.open=!1,this.quill.suggestsDialogOpen=!1,this.onClose&&this.onClose(n||null)}}]),n}()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.h=function(e,t){for(var n=arguments.length,o=Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];var r=document.createElement(e);return Object.keys(t).forEach(function(e){return r[e]=t[e]}),o.forEach(function(e){"string"==typeof e&&(e=document.createTextNode(e)),r.appendChild(e)}),r}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),i=function e(t,n,o){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var r=Object.getPrototypeOf(t);return null===r?void 0:e(r,n,o)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(o):void 0};t.default=function(e){var t=e.import("blots/inline"),n=function(e){function n(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,t),o(n,[{key:"format",value:function(e,t){"suggest"===e&&t?this.domNode.setAttribute("data-id",t):i(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"format",this).call(this,e,t)}},{key:"formats",value:function(){var e=i(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"formats",this).call(this);return e.suggest=n.formats(this.domNode),e}}],[{key:"create",value:function(e){var t=i(n.__proto__||Object.getPrototypeOf(n),"create",this).call(this);return t.dataset.id=e,t}},{key:"formats",value:function(e){return e.dataset.id}}]),n}();return n.blotName="suggest",n.tagName="SPAN",n.className="suggest",n}}]).default});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.QuillPlaceholderAutocomplete=e():t.QuillPlaceholderAutocomplete=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){n(1),t.exports=n(2)},function(t,e){},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&a.return&&a.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=u(n(3)),s=n(5),a=u(n(6));function u(t){return t&&t.__esModule?t:{default:t}}e.default=function(t){var e=t.import("delta");return t.register("formats/suggest",(0,a.default)(t)),function(){function n(t,e){var r=this,i=e.onClose,o=e.onOpen,a=e.getPlaceholders,u=e.container;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.quill=t,this.onClose=i,this.onOpen=o,this.getPlaceholders=a,"string"==typeof u?this.container=this.quill.container.parentNode.querySelector(u):void 0===u?(this.container=(0,s.h)("ul",{}),this.quill.container.parentNode.appendChild(this.container)):this.container=u,this.container.classList.add("ql-autocomplete-menu","completions"),this.container.style.position="absolute",this.container.style.display="none",this.onSelectionChange=this.maybeUnfocus.bind(this),this.onTextChange=this.update.bind(this),this.open=!1,this.quill.suggestsDialogOpen=!1,this.hashIndex=null,this.focusedButton=null,this.buttons=[],this.matchedPlaceholders=[],this.placeholders=[],this.toolbarHeight=0,t.root.addEventListener("keydown",function(t){t.defaultPrevented||"#"===t.key&&(r.toolbarHeight||(r.toolbarHeight=r.quill.getModule("toolbar").container.offsetHeight),r.onHashKey(r.quill.getSelection()),t.preventDefault())},!0),t.keyboard.addBinding({key:40,collapsed:!0,format:["suggest"]},this.handleArrow.bind(this)),t.keyboard.addBinding({key:27,collapsed:null,format:["suggest"]},this.handleEscape.bind(this))}return i(n,[{key:"onHashKey",value:function(e){var n=this;if(this.open)return!0;e.length>0&&this.quill.deleteText(e.index,e.length,t.sources.USER),this.quill.insertText(e.index,"#","suggest","@@placeholder",t.sources.USER);var r=this.quill.getBounds(e.index),i=this.toolbarHeight+2;this.quill.setSelection(e.index+1,t.sources.SILENT),this.hashIndex=e.index,this.container.style.left=r.left+"px",this.container.style.top=r.top+r.height+i+"px",this.open=!0,this.quill.suggestsDialogOpen=!0,this.quill.on("text-change",this.onTextChange),this.quill.once("selection-change",this.onSelectionChange),this.quill.root.addEventListener("keydown",function(t){"Enter"===t.key&&n.handleEnterTab()},{once:!0}),this.update(),this.onOpen&&this.onOpen()}},{key:"handleArrow",value:function(){if(!this.open)return!0;this.buttons[0].focus()}},{key:"handleEnterTab",value:function(){if(!this.open)return!0;this.close(this.matchedPlaceholders[0])}},{key:"handleEscape",value:function(){if(!this.open)return!0;this.close()}},{key:"emptyCompletionsContainer",value:function(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},{key:"update",value:function(){var t=this.quill.getSelection().index,e=this.getPlaceholders(),n=e.map(function(t){return t.label.toLowerCase()}),i=(0,o.default)(n,!1),s=null;if(this.hashIndex>=t)return this.close(null);this.originalQuery=this.quill.getText(this.hashIndex+1,t-this.hashIndex-1),this.query=this.originalQuery.toLowerCase(),this.query.length&&(s=i.get(this.query)),s=s?s.map(function(t){return r(t,2)[1]}):n,this.matchedPlaceholders=e.filter(function(t){var e=t.label;return-1!==s.indexOf(e)}),this.renderCompletions(this.matchedPlaceholders)}},{key:"maybeUnfocus",value:function(){this.container.querySelector("*:focus")||this.close(null)}},{key:"renderCompletions",value:function(t){var e=this;this.emptyCompletionsContainer();var n=Array(t.length);this.buttons=n;var r=new RegExp("^(.*)("+this.query+")(.*)$");t.forEach(function(t,i){var o=t.label,a=(o.match(r)||[null,o]).slice(1).map(function(t,e){return t.length?(0,s.h)("span",{className:1===e?"matched":"unmatched"},(0===e?"#":"")+t):null}).filter(function(t){return t}),u=(0,s.h)("li",{},s.h.apply(void 0,["button",{type:"button"}].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}(a))));e.container.appendChild(u),n[i]=u.firstChild,n[i].addEventListener("keydown",function(t,r){return function(i){"ArrowDown"===i.key||40===i.keyCode?(i.preventDefault(),n[Math.min(n.length-1,t+1)].focus()):"ArrowUp"===i.key||38===i.keyCode?(i.preventDefault(),n[Math.max(0,t-1)].focus()):"Enter"===i.key||13===i.keyCode||" "===i.key||32===i.keyCode||"Tab"===i.key||9===i.keyCode?(i.preventDefault(),e.close(r)):"Escape"!==i.key&&27!==i.keyCode||(i.preventDefault(),e.close())}}(i,t)),n[i].addEventListener("mousedown",function(){return e.close(t)}),n[i].addEventListener("focus",function(){return e.focusedButton=i}),n[i].addEventListener("unfocus",function(){return e.focusedButton=null})}),this.container.style.display="block"}},{key:"close",value:function(n){this.container.style.display="none",this.emptyCompletionsContainer(),this.quill.off("selection-change",this.onSelectionChange),this.quill.off("text-change",this.onTextChange);var r=(new e).retain(this.hashIndex).delete(this.query.length+1);this.quill.updateContents(r,t.sources.USER),n&&(this.quill.insertEmbed(this.hashIndex,"placeholder",n,t.sources.USER),this.quill.setSelection(this.hashIndex+1,0,t.sources.SILENT)),this.quill.focus(),this.open=!1,this.quill.suggestsDialogOpen=!1,this.onClose&&this.onClose(n||null)}}]),n}()}},function(t,e,n){t.exports=n(4)},function(t,e){!function(){var e=function(t,e,n,r){var i={};t=t||[],i.gramSizeLower=n||2,i.gramSizeUpper=r||3,i.useLevenshtein="boolean"!=typeof e||e,i.exactSet={},i.matchDict={},i.items={};var o=function(t,e){if(null===t&&null===e)throw"Trying to compare two null values";if(null===t||null===e)return 0;var n=function(t,e){for(var n,r,i=[],o=0;o<=e.length;o++)for(var s=0;s<=t.length;s++)r=o&&s?t.charAt(s-1)===e.charAt(o-1)?n:Math.min(i[s],i[s-1],n)+1:o+s,n=i[s],i[s]=r;return i.pop()}(t=String(t),e=String(e));return t.length>e.length?1-n/t.length:1-n/e.length},s=/[^a-zA-Z0-9\u00C0-\u00FF, ]+/g,a=function(t,e){for(var n={},r=function(t,e){e=e||2;var n="-"+t.toLowerCase().replace(s,"")+"-",r=e-n.length,i=[];if(r>0)for(var o=0;o<r;++o)t+="-";for(o=0;o<n.length-e+1;++o)i.push(n.slice(o,o+e));return i}(t,e=e||2),i=0;i<r.length;++i)r[i]in n?n[r[i]]+=1:n[r[i]]=1;return n};i.get=function(t,e,n){void 0===n&&(n=.33);var r=this._get(t,n);return r||void 0===e?r:e},i._get=function(t,e){var n=this._normalizeStr(t),r=this.exactSet[n];if(r)return[[1,r]];for(var i=[],o=this.gramSizeUpper;o>=this.gramSizeLower;--o)if((i=this.__get(t,o,e))&&i.length>0)return i;return null},i.__get=function(t,e,n){var r,i,s,u,l=this._normalizeStr(t),h={},c=a(l,e),f=this.items[e],p=0;for(r in c)if(i=c[r],p+=Math.pow(i,2),r in this.matchDict)for(S=0;S<this.matchDict[r].length;++S)s=this.matchDict[r][S][0],u=this.matchDict[r][S][1],s in h?h[s]+=i*u:h[s]=i*u;if(function(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}(h))return null;var d,y=Math.sqrt(p),g=[];for(var v in h)d=h[v],g.push([d/(y*f[v][0]),f[v][1]]);var m=function(t,e){return t[0]<e[0]?1:t[0]>e[0]?-1:0};if(g.sort(m),this.useLevenshtein){for(var b=[],x=Math.min(50,g.length),S=0;S<x;++S)b.push([o(g[S][1],l),g[S][1]]);(g=b).sort(m)}b=[];return g.forEach(function(t){t[0]>=n&&b.push([t[0],this.exactSet[t[1]]])}.bind(this)),b},i.add=function(t){if(this._normalizeStr(t)in this.exactSet)return!1;for(var e=this.gramSizeLower;e<this.gramSizeUpper+1;++e)this._add(t,e)},i._add=function(t,e){var n=this._normalizeStr(t),r=this.items[e]||[],i=r.length;r.push(0);var o,s,u=a(n,e),l=0;for(o in u)s=u[o],l+=Math.pow(s,2),o in this.matchDict?this.matchDict[o].push([i,s]):this.matchDict[o]=[[i,s]];var h=Math.sqrt(l);r[i]=[h,n],this.items[e]=r,this.exactSet[n]=t},i._normalizeStr=function(t){if("[object String]"!==Object.prototype.toString.call(t))throw"Must use a string as argument to FuzzySet functions";return t.toLowerCase()},i.length=function(){var t,e=0;for(t in this.exactSet)this.exactSet.hasOwnProperty(t)&&(e+=1);return e},i.isEmpty=function(){for(var t in this.exactSet)if(this.exactSet.hasOwnProperty(t))return!1;return!0},i.values=function(){var t,e=[];for(t in this.exactSet)this.exactSet.hasOwnProperty(t)&&e.push(this.exactSet[t]);return e};for(var u=i.gramSizeLower;u<i.gramSizeUpper+1;++u)i.items[u]=[];for(u=0;u<t.length;++u)i.add(t[u]);return i};void 0!==t&&t.exports?(t.exports=e,this.FuzzySet=e):this.FuzzySet=e}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.h=function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];var o=document.createElement(t);return Object.keys(e).forEach(function(t){return o[t]=e[t]}),r.forEach(function(t){"string"==typeof t&&(t=document.createTextNode(t)),o.appendChild(t)}),o}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),i=function t(e,n,r){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,n);if(void 0===i){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,n,r)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(r):void 0};e.default=function(t){var e=t.import("blots/inline"),n=function(t){function n(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(n,e),r(n,[{key:"format",value:function(t,e){"suggest"===t&&e?this.domNode.setAttribute("data-id",e):i(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"format",this).call(this,t,e)}},{key:"formats",value:function(){var t=i(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"formats",this).call(this);return t.suggest=n.formats(this.domNode),t}}],[{key:"create",value:function(t){var e=i(n.__proto__||Object.getPrototypeOf(n),"create",this).call(this);return e.dataset.id=t,e}},{key:"formats",value:function(t){return t.dataset.id}}]),n}();return n.blotName="suggest",n.tagName="SPAN",n.className="suggest",n}}]).default});
{
"name": "quill-placeholder-autocomplete-module",
"version": "1.0.4",
"version": "1.0.5",
"description": "brings autocomplete to Quill placeholder module",

@@ -27,13 +27,14 @@ "main": "dist/quill-placeholder-autocomplete-module.min.js",

"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-core": "~6.26.3",
"babel-loader": "~7.1.2",
"babel-preset-env": "^1.7.0",
"css-loader": "^0.28.8",
"eslint": "^4.15.0",
"extract-text-webpack-plugin": "^3.0.2",
"eslint": "^5.1.0",
"extract-text-webpack-plugin": "~3.0.2",
"fuzzyset.js": "~0.0.5",
"quill": "1.3.6",
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.10.0"
"uglifyjs-webpack-plugin": "~1.1.8",
"webpack": "~3.10.0"
},
"dependencies": {}
}

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

import FuzzySet from 'fuzzyset.js';
import { h } from './utils';

@@ -37,3 +38,3 @@ import getSuggestBlot from './suggestBlot';

this.container.style.display = 'none';
// prepare handlers and bind/unbind them when appropriate
this.onSelectionChange = this.maybeUnfocus.bind(this);

@@ -47,2 +48,3 @@ this.onTextChange = this.update.bind(this);

this.buttons = [];
this.matchedPlaceholders = [];
this.placeholders = [];

@@ -52,7 +54,7 @@ this.toolbarHeight = 0;

// TODO: Once Quill supports using event.key (issue #1091) use that instead of alt-3
quill.keyboard.addBinding({
key: 51, // '3' keyCode
altKey: true,
ctrlKey: null // both
}, this.onHashKey.bind(this));
// quill.keyboard.addBinding({
// key: 51, // '3' keyCode
// altKey: true,
// ctrlKey: null // both
// }, this.onHashKey.bind(this));

@@ -86,3 +88,3 @@ quill.root.addEventListener('keydown', (event) => {

quill.suggestHandler = this.handleEnterTab.bind(this);
// quill.suggestHandler = this.onHashKey.bind(this);
}

@@ -94,7 +96,6 @@

* @param {Quill.RangeStatic} range concerned region
* @param {any} context editor context
* @returns {Boolean} can stop event propagation
* @memberof AutoComplete
*/
onHashKey(range, _) {
onHashKey(range) {
// prevent from opening twice

@@ -111,2 +112,3 @@ // NOTE: returning true stops event propagation in Quill

const hashSignBounds = this.quill.getBounds(range.index);
const rest = this.toolbarHeight + 2;
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);

@@ -116,3 +118,3 @@

this.container.style.left = hashSignBounds.left + 'px';
this.container.style.top = hashSignBounds.top + hashSignBounds.height + this.toolbarHeight + 2 + 'px';
this.container.style.top = hashSignBounds.top + hashSignBounds.height + rest + 'px';
this.open = true;

@@ -124,2 +126,8 @@ this.quill.suggestsDialogOpen = true;

this.quill.once('selection-change', this.onSelectionChange);
// binding handler to react when user pressed Enter
// when autocomplete UI is in default state
this.quill.root.addEventListener('keydown', (event) => {
if (event.key === 'Enter')
this.handleEnterTab();
}, { once: true });
this.update();

@@ -150,3 +158,3 @@ this.onOpen && this.onOpen();

return true;
this.close(this.placeholders[0]);
this.close(this.matchedPlaceholders[0]);
}

@@ -180,2 +188,6 @@

const sel = this.quill.getSelection().index;
const placeholders = this.getPlaceholders();
const labels = placeholders.map(({ label }) => label.toLowerCase());
const fs = FuzzySet(labels, false);
let labelResults = null;
// Deleted the at character

@@ -187,7 +199,10 @@ if (this.hashIndex >= sel) {

this.query = this.originalQuery.toLowerCase();
// TODO: Should use fuse.js or similar fuzzy-matcher
this.placeholders = this.getPlaceholders()
.filter(ph => ph.label.toLowerCase().startsWith(this.query))
.sort((ph1, ph2) => ph1.label > ph2.label);
this.renderCompletions(this.placeholders);
if (this.query.length)
labelResults = fs.get(this.query);
labelResults = labelResults
? labelResults.map(([ , label ]) => label)
: labels;
this.matchedPlaceholders = placeholders
.filter(({ label }) => labelResults.indexOf(label) !== -1);
this.renderCompletions(this.matchedPlaceholders);
}

@@ -234,8 +249,23 @@

};
const regex = new RegExp('^(.*)('+this.query+')(.*)$');
// prepare buttons corresponding to each placeholder
placeholders.forEach((placeholder, i) => {
const { label } = placeholder;
const match = label.match(regex) || [ null, label ];
const elements = match.slice(1)
.map((str, i) => {
if (!str.length)
return null;
return h(
'span',
{ className: i === 1 ? 'matched' : 'unmatched' },
`${i === 0 ? '#' : ''}${str}`
);
}).filter(elem => elem);
const li = h('li', {},
h('button', { type: 'button' },
h('span', { className: 'matched' }, '#' + placeholder.label.slice(0, this.query.length)),
h('span', { className: 'unmatched' }, placeholder.label.slice(this.query.length))));
h('button', { type: 'button' }, ...elements)
);
this.container.appendChild(li);

@@ -242,0 +272,0 @@ buttons[i] = li.firstChild;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc