2016-02-23 15:41:22 +01:00

2 lines
8.2 KiB
JavaScript

!function t(e,r,n){function i(a,s){if(!r[a]){if(!e[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[a]={exports:{}};e[a][0].call(u.exports,function(t){var r=e[a][1][t];return i(r?r:t)},u,u.exports,t,e,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}({1:[function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(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}function o(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)}function a(t){t.requestModules(["Array"]).then(function(){var e=function(e){function r(t,e,o){n(this,r);var a=i(this,Object.getPrototypeOf(r).call(this,t,e,o));return a.instances=[],a}return o(r,e),s(r,[{key:"_destroy",value:function(){for(var t=this.instances.length-1;t>=0;t--)this.unbindQuill(this.instances[t].editor);l(Object.getPrototypeOf(r.prototype),"_destroy",this).call(this)}},{key:"toString",value:function(){return this._content.map(function(t){return"string"==typeof t.val?t.val:void 0}).join("")}},{key:"toOTOps",value:function(){function t(){var t={};for(var e in r.attributes)t[e]=r.attributes[e];r={insert:[],attributes:t}}for(var e=[],r={insert:[],attributes:{}},n=0;n<this._content.length;n++){var i=this._content[n].val;i.constructor===Array?(r.insert.length>0&&(r.insert=r.insert.join(""),e.push(r),t()),null===i[1]?delete r.attributes[i[0]]:r.attributes[i[0]]=i[1]):r.insert.push(i)}return r.insert.length>0&&(r.insert=r.insert.join(""),e.push(r)),e}},{key:"insert",value:function(t,e){for(var n=0,i={},o=0;o<this._content.length&&n!==t;o++){var a=this._content[o].val;"string"==typeof a?n++:a.constructor===Array&&(null===a[1]?delete i[a[0]]:i[a[0]]=a[1])}return l(Object.getPrototypeOf(r.prototype),"insert",this).call(this,o,e.split("")),i}},{key:"delete",value:function(t,e){var n=0,i={},o=t+e;if(!(0>=e)){var a,s,c,u;for(a=0;t>n&&a<this._content.length;a++)c=this._content[a].val,"string"==typeof c?n++:c.constructor===Array&&(i[c[0]]=c[1]);for(s=a;o>n&&s<this._content.length;s++)c=this._content[s].val,"string"==typeof c&&n++;if(s===this._content.length)for(u=s-1;u>=a;u--)c=this._content[u].val,l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,u,1);else{"string"==typeof c&&s--;var f={};for(u=s;u>=a;u--)c=this._content[u].val,c.constructor===Array?void 0===f[c[0]]?(c[1]===i[c[0]]&&l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,u,1),f[c[0]]=c[1]):l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,u,1):"string"==typeof c&&l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,u,1)}}}},{key:"select",value:function(t,e,n,i){if(null==t||null==e||null==n||void 0===i)throw new Error("You must define four parameters");for(var o,a,s=[n,null],c=0,u=0;u<this._content.length;u++){var f=this._content[u].val;if(c===t)break;f.constructor===Array?f[0]===n&&(s[1]=f[1]):"string"==typeof f&&c++}s[1]!==i&&(o=u,a=[n,i]);for(var h=[];u<this._content.length;u++){var p=this._content[u].val;if(c===e)break;p.constructor===Array?p[0]===n&&(s[1]=p[1],h.push(u)):"string"==typeof p&&c++}for(var v=h.length-1;v>=0;v--){var y=h[v];l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,y,1),u>y&&u--,o>y&&o--}if(s[1]!==i&&u<this._content.length){var g,d=!0;for(v=u;v<this._content.length&&(g=this._content[v].val,g.constructor===Array);v++)if(g[0]===n){d=!1,g[1]===i&&l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,v,1);break}if(d){var b=[n,s[1]];l(Object.getPrototypeOf(r.prototype),"insert",this).call(this,u,[b])}}if(null!=o)for(l(Object.getPrototypeOf(r.prototype),"insert",this).call(this,o,[a]),v=o-1;v>=0&&(g=this._content[v].val,g.constructor===Array);v--)g[0]===n&&l(Object.getPrototypeOf(r.prototype),"delete",this).call(this,v,1)}},{key:"bind",value:function(){this.bindQuill.apply(this,arguments)}},{key:"unbindQuill",value:function(t){var e=this.instances.findIndex(function(e){return e.editor===t});if(e>=0){var r=this.instances[e];this.unobserve(r.yCallback),r.editor.off("text-change",r.quillCallback),this.instances.splice(e,1)}}},{key:"bindQuill",value:function(t){function e(t){if(o){o=!1;try{t()}catch(e){throw o=!0,new Error(e)}o=!0}}function r(r){e(function(){for(var e,n=0,o=0;o<r.ops.length;o++){var a=r.ops[o];if(null!=a.insert){var s=i.insert(n,a.insert);for(e in a.attributes)a.attributes[e]!==s[e]&&i.select(n,n+a.insert.length,e,a.attributes[e]);for(e in s)(null==a.attributes||s[e]!==a.attributes[e])&&i.select(n,n+a.insert.length,e,null);n+=a.insert.length}if(null!=a["delete"]&&i["delete"](n,a["delete"]),null!=a.retain){var l=n+a.retain;if(l>i.length){var c=t.getText(i.length);t.insertText(i.length,c);for(e in a.attributes)t.formatText(i.length+c.length,i.length+2*c.length,e,null);i.insert(i.length,c)}for(e in a.attributes)i.select(n,n+a.retain,e,a.attributes[e]),t.formatText(n,n+a.retain,e,a.attributes[e]);n=l}}})}function n(r){e(function(){for(var e,n,o=0;o<r.length;o++){var a=r[o];if("insert"===a.type){if("string"==typeof a.value){for(var s=0,l={},c=a.index-1;c>=0;c--)e=i._content[c].val,"string"==typeof e?s++:e.constructor===Array&&"undefined"==typeof l[e[0]]&&(l[e[0]]=e[1]);t.insertText(s,a.value,l)}else if(a.value.constructor===Array){n=null;for(var u=a.value,f=0,h=a.index-1;h>=0;h--)if(e=i._content[h].val,e.constructor===Array){if(u[0]===e[0]){n=e[1];break}}else"string"==typeof e&&f++;for(;h>=0;h--)e=i._content[h].val,"string"==typeof e&&f++;if(u[1]===n)return;for(var p=f,v=a.index+1;v<i._content.length;v++)if(e=i._content[v].val,e.constructor===Array){if(e[0]===u[0])break}else"string"==typeof e&&p++;f!==p&&t.formatText(f,p,u[0],u[1])}}else if("delete"===a.type)if("string"==typeof a.value){for(var y=0,g=0;g<a.index;g++)e=i._content[g].val,"string"==typeof e&&y++;var d=a.length;t.deleteText(y,y+d)}else if(a.value.constructor===Array){n=null;var b,O=0;for(b=a.index-1;b>=0;b--)if(e=i._content[b].val,e.constructor===Array){if(e[0]===a.value[0]){n=e[1];break}}else"string"==typeof e&&O++;for(;b>=0;b--)e=i._content[b].val,"string"==typeof e&&O++;var _=O;for(b=a.index;b<i._content.length;b++)if(e=i._content[b].val,e.constructor===Array){if(e[0]===a.value[0])break}else"string"==typeof e&&_++;n!==a.value[1]&&O!==_&&t.formatText(O,_,a.value[0],n)}}t.editor.checkUpdate()})}var i=this,o=!0;t.setContents(this.toOTOps()),t.on("text-change",r),this.observe(n),this.instances.push({editor:t,yCallback:n,quillCallback:r})}},{key:"_changed",value:regeneratorRuntime.mark(function a(){var e=arguments;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.instances.forEach(function(t){t.editor.editor.checkUpdate()}),r.delegateYield(t.Array["class"].prototype._changed.apply(this,e),"t0",2);case 2:case"end":return r.stop()}},a,this)})},{key:"length",get:function(){return this.toString().length}}]),r}(t.Array["class"]);t.extend("Richtext",new t.utils.CustomType({name:"Richtext","class":e,struct:"List",initType:regeneratorRuntime.mark(function r(n,i){var o;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(t.Struct.List.map.call(this,i,function(t){return{id:JSON.stringify(t.id),val:t.content}}),"t0",1);case 1:return o=r.t0,r.abrupt("return",new e(n,i.id,o));case 3:case"end":return r.stop()}},r,this)})}))})}var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),l=function c(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:c(i,e,r)}if("value"in n)return n.value;var o=n.get;if(void 0!==o)return o.call(r)};e.exports=a,"undefined"!=typeof Y&&a(Y)},{}]},{},[1]);
//# sourceMappingURL=y-richtext.js.map