quill-placeholder-module
Version:
Quill module for inserting placeholders
2 lines • 4.34 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("PlaceholderModule",[],t):"object"==typeof exports?exports.PlaceholderModule=t():e.PlaceholderModule=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){var r=e.import("parchment"),o=i.default(e);return o.className=t&&t.className||"ql-placeholder-content",e.register(o),function t(i,l){var a=this;n(this,t),this.quill=i,this.onTextChange=function(t,r,n){if(n===e.sources.USER){var o=a.quill.getContents(),i=o.diff(r);i.ops.filter(function(e){return e.insert&&e.insert.placeholder&&e.insert.placeholder.required}).length&&a.quill.updateContents(i,e.sources.SILENT)}},this.onClick=function(t){var n=r.find(t.target.parentNode);if(n instanceof o){var i=a.quill.getIndex(n);a.quill.setSelection(i,n.length(),e.sources.USER)}},this.toolbarHandler=function(t){var r=a.quill.getSelection(),n=a.placeholders.filter(function(e){return e.id===t})[0];if(!n)throw new Error("Missing placeholder for "+t);a.quill.deleteText(r.index,r.length),a.quill.insertEmbed(r.index,"placeholder",n,e.sources.USER),a.quill.setSelection(r.index+1,0)},this.placeholders=l.placeholders,o.delimiters=l.delimiters||["{","}"],this.quill.getModule("toolbar").addHandler("placeholder",this.toolbarHandler),this.quill.root.addEventListener("click",this.onClick),this.quill.on("text-change",this.onTextChange)}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(1);t.default=o},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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}function i(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)}function l(e){var t=e.import("blots/embed"),r=function(t){function r(){return n(this,r),o(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return i(r,t),a(r,[{key:"length",value:function(){return 1}},{key:"deleteAt",value:function(e,t){this.domNode.dataset.required||u(r.prototype.__proto__||Object.getPrototypeOf(r.prototype),"deleteAt",this).call(this,e,t)}}],[{key:"create",value:function(t){var n=u(r.__proto__||Object.getPrototypeOf(r),"create",this).call(this,t);t.required&&n.setAttribute("data-required","true"),n.setAttribute("data-id",t.id),n.setAttribute("data-label",t.label),n.setAttribute("spellcheck","false");var o=r.delimiters,i="string"==typeof o?""+o+t.label+o:""+o[0]+t.label+(o[1]||o[0]),l=document.createTextNode(i);if(e.version<"1.3"){var a=document.createElement("span");a.setAttribute("contenteditable","false"),a.appendChild(l),n.appendChild(a)}else n.appendChild(l);return n}},{key:"value",value:function(e){return e.dataset}}]),r}(t);return r.blotName="placeholder",r.tagName="span",r}var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=function e(t,r,n){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,r);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,r,n)}if("value"in o)return o.value;var l=o.get;if(void 0!==l)return l.call(n)};Object.defineProperty(t,"__esModule",{value:!0}),t.default=l}])});
//# sourceMappingURL=placeholder-module.min.js.map