3 lines
7.9 KiB
JavaScript
3 lines
7.9 KiB
JavaScript
!function t(r,e,n){function i(o,s){if(!e[o]){if(!r[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var f=e[o]={exports:{}};r[o][0].call(f.exports,function(t){var e=r[o][1][t];return i(e?e:t)},f,f.exports,t,r,e,n)}return e[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(t,r,e){"use strict";function n(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function i(t,r){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?t:r}function a(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}function o(t){t.requestModules(["Array"]).then(function(){var r=function(r){function e(t,r,a,o){n(this,e);var s=i(this,Object.getPrototypeOf(e).call(this,t,r,a,o));s._length=0,s.instances=[];for(var l=0,u=o[l];l<o.length;l++)"string"==typeof u&&s._length++;var f=s;return s.observe(function(t){for(var r=0,e=t[r];r<t.length;r++)"insert"===e.type?"string"==typeof e.value&&f._length++:"delete"===e.type&&"string"==typeof e.value&&f._length--}),s}return a(e,r),s(e,[{key:"toString",value:function(){return this.valArray.map(function(t){return"string"==typeof t?t:void 0}).join("")}},{key:"toOTOps",value:function(){function t(){var t={};for(var r in e.attributes)t[r]=e.attributes[r];e={insert:[],attributes:t}}for(var r=[],e={insert:[],attributes:{}},n=0;n<this.valArray.length;n++){var i=this.valArray[n];i.constructor===Array?(e.insert.length>0&&(e.insert=e.insert.join(""),r.push(e),t()),null===i[1]?delete e.attributes[i[0]]:e.attributes[i[0]]=i[1]):e.insert.push(i)}return e.insert.length>0&&(e.insert=e.insert.join(""),r.push(e)),r}},{key:"insert",value:function(t,r){for(var n=0,i={},a=0;a<this.valArray.length&&n!==t;a++){var o=this.valArray[a];"string"==typeof o?n++:o.constructor===Array&&(null===o[1]?delete i[o[0]]:i[o[0]]=o[1])}return l(Object.getPrototypeOf(e.prototype),"insert",this).call(this,a,r.split("")),i}},{key:"delete",value:function(t,r){var n=0,i={},a=t+r;if(!(0>=r)){var o,s,u,f;for(o=0,u=this.valArray[o];t>n&&o<this.valArray.length;u=this.valArray[++o])"string"==typeof u?n++:u.constructor===Array&&(i[u[0]]=u[1]);for(s=o,u=this.valArray[s];a>n&&s<this.valArray.length;u=this.valArray[++s])"string"==typeof u&&n++;if(s===this.valArray.length)for(f=s-1,u=this.valArray[f];f>=o;u=this.valArray[--f])l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,f,1);else{"string"==typeof u&&s--;var c={};for(f=s,u=this.valArray[f];f>=o;u=this.valArray[--f])u.constructor===Array?void 0===c[u[0]]?(u[1]===i[u[0]]&&l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,f,1),c[u[0]]=u[1]):l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,f,1):"string"==typeof u&&l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,f,1)}}}},{key:"select",value:function(t,r,n,i){if(null==t||null==r||null==n||void 0===i)throw new Error("You must define four parameters");for(var a,o,s=[n,null],u=0,f=0;f<this.valArray.length;f++){var c=this.valArray[f];if(u===t)break;c.constructor===Array?c[0]===n&&(s[1]=c[1]):"string"==typeof c&&u++}s[1]!==i&&(a=f,o=[n,i]);for(var y=[];f<this.valArray.length;f++){var h=this.valArray[f];if(u===r)break;h.constructor===Array?h[0]===n&&(s[1]=h[1],y.push(f)):"string"==typeof h&&u++}for(var v=y.length-1;v>=0;v--){var p=y[v];l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,p,1),f>p&&f--,a>p&&a--}if(s[1]!==i&&f<this.valArray.length){var g,d=!0;for(v=f,g=this.valArray[v];v<this.valArray.length&&g.constructor===Array;g=this.valArray[++v])if(g[0]===n){d=!1,g[1]===i&&l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,v,1);break}if(d){var b=[n,s[1]];l(Object.getPrototypeOf(e.prototype),"insert",this).call(this,f,[b])}}if(null!=a)for(l(Object.getPrototypeOf(e.prototype),"insert",this).call(this,a,[o]),v=a-1,g=this.valArray[v];v>=0&&g.constructor===Array;g=this.valArray[--v])g[0]===n&&l(Object.getPrototypeOf(e.prototype),"delete",this).call(this,v,1)}},{key:"bind",value:function(t){function r(t){if(n){n=!1;try{t()}catch(r){throw n=!0,new Error(r)}n=!0}}this.instances.push(t);var e=this,n=!0;t.setContents(this.toOTOps()),t.on("text-change",function(n){r(function(){for(var r,i=0,a=0;a<n.ops.length;a++){var o=n.ops[a];if(null!=o.insert){var s=e.insert(i,o.insert);for(r in o.attributes)o.attributes[r]!==s[r]&&e.select(i,i+o.insert.length,r,o.attributes[r]);for(r in s)(null==o.attributes||s[r]!==o.attributes[r])&&e.select(i,i+o.insert.length,r,null);i+=o.insert.length}if(null!=o["delete"]&&e["delete"](i,o["delete"]),null!=o.retain){var l=i+o.retain;if(l>e.length){for(var u=l-e.length,f="";0!==u;)u--,f+="\n";for(r in o.attributes)t.formatText(e.length,e.length+o.retain,r,null);t.insertText(e.length,f,o.attributes),e.insert(e.length,f)}for(r in o.attributes)e.select(i,i+o.retain,r,o.attributes[r]);i=l}}})}),this.observe(function(n){r(function(){for(var r,i,a=0;a<n.length;a++){var o=n[a];if("insert"===o.type){if("string"==typeof o.value){for(var s=0,l={},u=o.index-1;u>=0;u--)r=e.valArray[u],"string"==typeof r?s++:r.constructor===Array&&"undefined"==typeof l[r[0]]&&(l[r[0]]=r[1]);t.insertText(s,o.value,l)}else if(o.value.constructor===Array){i=null;for(var f=o.value,c=0,y=o.index-1;y>=0;y--)if(r=e.valArray[y],r.constructor===Array){if(f[0]===r[0]){i=r[1];break}}else"string"==typeof r&&c++;for(;y>=0;y--)r=e.valArray[y],"string"==typeof r&&c++;if(f[1]===i)return;for(var h=c,v=o.index+1;v<e.valArray.length;v++)if(r=e.valArray[v],r.constructor===Array){if(r[0]===f[0])break}else"string"==typeof r&&h++;c!==h&&t.formatText(c,h,f[0],f[1])}}else if("delete"===o.type)if("string"==typeof o.value){for(var p=0,g=0;g<o.index;g++)r=e.valArray[g],"string"==typeof r&&p++;var d=o.length;t.deleteText(p,p+d)}else if(o.value.constructor===Array){i=null;var b,A=0;for(b=o.index-1;b>=0;b--)if(r=e.valArray[b],r.constructor===Array){if(r[0]===o.value[0]){i=r[1];break}}else"string"==typeof r&&A++;for(;b>=0;r=e.valArray[--b])"string"==typeof r&&A++;var O=A;for(b=o.index;b<e.valArray.length;b++)if(r=e.valArray[b],r.constructor===Array){if(r[0]===o.value[0])break}else"string"==typeof r&&O++;i!==o.value[1]&&A!==O&&t.formatText(A,O,o.value[0],i)}}t.editor.checkUpdate()})})}},{key:"_changed",value:regeneratorRuntime.mark(function o(){var r=arguments;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.instances.forEach(function(t){t.editor.checkUpdate()}),e.delegateYield(t.Array["class"].prototype._changed.apply(this,r),"t0",2);case 2:case"end":return e.stop()}},o,this)})},{key:"length",get:function(){return this._length}}]),e}(t.Array["class"]);t.extend("Richtext",new t.utils.CustomType({name:"Richtext","class":r,struct:"List",initType:regeneratorRuntime.mark(function e(n,i){var a,o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a=[],e.delegateYield(t.Struct.List.map.call(this,i,function(t){return a.push(t.content),JSON.stringify(t.id)}),"t0",2);case 2:return o=e.t0,e.abrupt("return",new r(n,i.id,o,a));case 4:case"end":return e.stop()}},e,this)})}))})}var s=function(){function t(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(r,e,n){return e&&t(r.prototype,e),n&&t(r,n),r}}(),l=function u(t,r,e){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,r);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:u(i,r,e)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(e)};r.exports=o,"undefined"!=typeof Y&&o(Y)},{}]},{},[1]);
|
|
//# sourceMappingURL=y-richtext.js.map
|