gaosp
2024-01-16 522048130f147c2e8fbfb2798bfa83f3da5b4eed
1
var TableMergeUtils=function(){"use strict";function r(r,t){var o=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.push.apply(o,n)}return o}function t(t){for(var o=1;o<arguments.length;o++){var e=null!=arguments[o]?arguments[o]:{};o%2?r(Object(e),!0).forEach((function(r){n(t,r,e[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):r(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}))}return t}function o(r,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,a(n.key),n)}}function n(r,t,o){return(t=a(t))in r?Object.defineProperty(r,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):r[t]=o,r}function e(r,t){if(null==r)return{};var o,n,e=function(r,t){if(null==r)return{};var o,n,e={},s=Object.keys(r);for(n=0;n<s.length;n++)o=s[n],t.indexOf(o)>=0||(e[o]=r[o]);return e}(r,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(r);for(n=0;n<s.length;n++)o=s[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(r,o)&&(e[o]=r[o])}return e}function s(r){return function(r){if(Array.isArray(r))return i(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(!r)return;if("string"==typeof r)return i(r,t);var o=Object.prototype.toString.call(r).slice(8,-1);"Object"===o&&r.constructor&&(o=r.constructor.name);if("Map"===o||"Set"===o)return Array.from(r);if("Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return i(r,t)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var o=0,n=new Array(t);o<t;o++)n[o]=r[o];return n}function a(r){var t=function(r,t){if("object"!=typeof r||null===r)return r;var o=r[Symbol.toPrimitive];if(void 0!==o){var n=o.call(r,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==typeof t?t:String(t)}function l(r){var o=JSON.parse(JSON.stringify(r)),n=o[0].reduce((function(r,t){return r+t.colspan}),0),e=Array.from({length:n},(function(){return 0})),s=Array.from({length:n},(function(){return[]}));return o.forEach((function(r,o){r.forEach((function(r,i){r._row=o,r._col=i,r._startRow=o,r._endRow=o+r.rowspan-1;for(var a=e.reduce((function(r,t,o){return t<r.height?{index:o,height:t}:r}),{index:0,height:e[0]}).index,l=r.colspan;l>0;){var w=a+l-1;w<n&&(s[w].push(t({},r)),e[w]+=r.rowspan),l--}r._startCol=a,r._endCol=r._startCol+r.colspan-1}))})),{_rows:o,_cols:s}}function w(r,t,o,n){return!(t<o||r>n)&&{start:r===o,end:t===n,pass:r>=o&&t<=n,common:Math.min(t,n)-Math.max(r,o)+1,comCol:[Math.max(r,o),Math.min(t,n)]}}function c(r,t,o,n){var e=l(r)._rows,s=e[t][o],i=e[t][o+n],a=i&&i.rowspan===s.rowspan&&-1===n&&i._endCol+1===s._startCol,w=i&&i.rowspan===s.rowspan&&1===n&&i._startCol-1===s._endCol;return a||w?r[t][o+n]:null}function h(r,t,o,n){var e=l(r)._rows,s=e[t][o],i=null,a=null,c=null;return e.forEach((function(t,o){t.forEach((function(t,e){var l=w(t._startCol,t._endCol,s._startCol,s._endCol);l.start&&l.end&&(-1===n&&t._endRow+1===s._startRow||1===n&&t._startRow-1===s._endRow)&&(i=r[o][e],a=o,c=e)}))})),{targetCell:i,row:a,col:c}}var u=["rows","cols"],f={rowspan:1,colspan:1,width:100,height:40},p=function(){function r(o){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),n(this,"rows",[]),n(this,"options",{minRetainRow:0,minRetainCol:0,minSplitHcolspan:2,minSplitVrowspan:2,fixRowType:1}),this.rows=o,this.options=t(t({},this.options),e)}var i,a,p;return i=r,a=[{key:"getDisabledHandles",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,o=[],n=this.rows[r]&&this.rows[r][t];return n?(this.rows.reduce((function(r,t){return r+Math.min.apply(Math,s(t.map((function(r){return r.rowspan}))))}),0)-n.rowspan<this.options.minRetainRow&&o.push("delRow"),this.rows[0].reduce((function(r,t){return r+t.colspan}),0)-n.colspan<this.options.minRetainCol&&o.push("delCol"),n.colspan<this.options.minSplitHcolspan&&o.push("splitH"),n.rowspan<this.options.minSplitVrowspan&&o.push("splitV"),c(this.rows,r,t,-1)||o.push("leftMerge"),c(this.rows,r,t,1)||o.push("rightMerge"),h(this.rows,r,t,-1).targetCell||o.push("topMerge"),h(this.rows,r,t,1).targetCell||o.push("bottomMerge")):o=["insertRow","insertCol","delRow","delCol","splitH","splitV","leftMerge","rightMerge","topMerge","bottomMerge"],o}},{key:"handFixRow",value:function(){1===this.options.fixRowType?this.rows.forEach((function(r){if(r.length>1){var t=r.reduce((function(r,t){return Math.min(r,t.rowspan)}),r[0].rowspan)-1;t>0&&r.forEach((function(r){return r.rowspan-=t}))}})):2===this.options.fixRowType&&function(r){var t=0;r.forEach((function(o,n){var e=o.length&&o.every((function(r){return r.rowspan>1}));e&&(r.splice(n+t+1,0,[]),t++)}))}(this.rows)}},{key:"insertRow",value:function(r,o,n){var e=this;if(!this.getDisabledHandles(r,o).includes("insertRow")){var s=l(this.rows)._rows,i=this.rows[r][o],a=n?r+i.rowspan:r;if(a<s.length){s.forEach((function(r,t){t<a&&r.forEach((function(r){w(r._startRow,r._endRow,a,a)&&(e.rows[r._row][r._col].rowspan++,e.rows[r._row][r._col].height+=f.height)}))}));var c=this.rows[a].map((function(r){return t(t({},f),{},{width:r.width,colspan:r.colspan})}));this.rows.splice(a,0,c)}else{var h=this.rows[this.rows.length-1].map((function(r){return t(t({},f),{},{width:r.width,colspan:r.colspan})}));this.rows.splice(a,0,h)}var u=n?r:r+1;return{rows:this.rows,row:u,col:o,disabledHandles:this.getDisabledHandles(u,o)}}}},{key:"insertCol",value:function(r,o,n){var e=this;if(!this.getDisabledHandles(r,o).includes("insertCol")){var s=l(this.rows)._rows,i=s[r][o];s.forEach((function(s,a){if(r===a)e.rows[a].splice(o+n,0,t(t({},f),{},{rowspan:i.rowspan}));else if(n){var l=-1;if(s.forEach((function(r,t){w(r._startCol,r._endCol,i._startCol,i._endCol)&&(l=t)})),l>-1){var c=s[l];w(c._startCol,c._endCol,i._startCol,i._endCol).end?e.rows[a].splice(l+n,0,t(t({},f),{},{rowspan:c.rowspan,colspan:1})):(e.rows[c._row][c._col].colspan++,e.rows[c._row][c._col].width+=f.width)}}else{var h=s.findIndex((function(r){return w(r._startCol,r._endCol,i._startCol,i._endCol)}));if(h>-1){var u=s[h];w(u._startCol,u._endCol,i._startCol,i._endCol).start?e.rows[a].splice(h+n,0,t(t({},f),{},{rowspan:u.rowspan,colspan:1})):(e.rows[u._row][u._col].colspan++,e.rows[u._row][u._col].width+=f.width)}}}));var a=n?o:o+1;return{rows:this.rows,row:r,col:a,disabledHandles:this.getDisabledHandles(r,a)}}}},{key:"delRow",value:function(r,o){var n,e=this;if(!this.getDisabledHandles(r,o).includes("delRow")){var i=l(this.rows)._rows,a=i[r][o];i.forEach((function(n,s){if(s<r)n.forEach((function(r){var t=w(r._startRow,r._endRow,a._startRow,a._endRow);t&&(e.rows[r._row][r._col].rowspan-=t.common,e.rows[r._row][r._col].height-=a.height)}));else if(s>r){var l=[];n.forEach((function(n,s){var c=w(n._startRow,n._endRow,a._startRow,a._endRow);if(c&&(l.push(s),!c.pass)){var u=t(t({},e.rows[n._row][n._col]),{},{rowspan:n.rowspan-c.common}),f=h(i,r,o,1),p=f.row,d=f.col;e.rows[p].splice(d+1,0,u)}}));var c=e.rows[s].filter((function(r,t){return!l.includes(t)}));e.rows.splice(s,1,c)}}));var c=r+a.rowspan;i[r].forEach((function(r){var o=l(e.rows)._rows;if(r.rowspan>a.rowspan){var n=o[c].findIndex((function(t){return t._startCol>r._endCol}));-1===n&&o[c].forEach((function(t,o){t._endCol<r._startCol&&(n=o+1)})),e.rows[c].splice(n,0,t(t({},r),{},{rowspan:r.rowspan-a.rowspan,height:r.height-a.height}))}})),this.rows.splice(r,1);var u=this.rows.filter((function(r){return 0!==r.length}));return(n=this.rows).splice.apply(n,[0,this.rows.length].concat(s(u))),{rows:this.rows,row:-1,col:-1,disabledHandles:this.getDisabledHandles(-1,-1)}}}},{key:"delCol",value:function(r,t){var o,n=this;if(!this.getDisabledHandles(r,t).includes("delCol")){var e=l(this.rows)._rows,i=e[r][t];e.forEach((function(r,t){var o=[];r.forEach((function(r,t){var e=w(r._startCol,r._endCol,i._startCol,i._endCol);e&&(e.pass?o.push(t):(n.rows[r._row][r._col].colspan-=e.common,n.rows[r._row][r._col].width-=i.width))}));var e=n.rows[t].filter((function(r,t){return!o.includes(t)}));t<n.rows.length?n.rows.splice(t,1,e):n.rows.splice(t-n.rows.length,1,e)})),this.rows.every((function(r){return 1===r.length}))&&this.rows.forEach((function(r){return r.forEach((function(r){return r.rowspan=1}))}));var a=this.rows.filter((function(r){return 0!==r.length}));return(o=this.rows).splice.apply(o,[0,this.rows.length].concat(s(a))),this.handFixRow(),{rows:this.rows,row:-1,col:-1,disabledHandles:this.getDisabledHandles(-1,-1)}}}},{key:"splitH",value:function(r,o){var n=this;if(!this.getDisabledHandles(r,o).includes("splitH")){var e=l(this.rows),s=e._rows,i=e._cols,a=this.rows[r][o],c=s[r][o];if(a.colspan>1){var h=c.colspan;a.colspan-=Math.floor(h/2);for(var u=c._startCol,p=c._startCol+a.colspan-1,d=0;u<=p;)d+=i[u].find((function(r){return 1===r.colspan})).width,u++;a.width=d;for(var g=h-a.colspan,v=p+1,_=v+g-1,b=0;v<=_;)b+=i[v].find((function(r){return 1===r.colspan})).width,v++;this.rows[r].splice(o+1,0,t(t({},f),{},{width:b,height:a.height,colspan:g,rowspan:a.rowspan}))}else s.forEach((function(e,s){if(s===r)a.width/=2,n.rows[r].splice(o+1,0,t(t({},f),{},{width:a.width,height:a.height,rowspan:a.rowspan}));else{var i=e.findIndex((function(r){return w(r._startCol,r._endCol,c._startCol,c._endCol)}));i>-1&&(n.rows[s][i].colspan+=1)}}));return{rows:this.rows,row:r,col:o,disabledHandles:this.getDisabledHandles(r,o)}}}},{key:"splitV",value:function(r,o){var n=this;if(!this.getDisabledHandles(r,o).includes("splitV")){var e=l(this.rows)._rows,s=e[r][o],i=this.rows[r][o];if(i.rowspan>1){var a=s.rowspan;i.rowspan-=Math.floor(a/2);for(var c=s._startRow,h=s._startRow+i.rowspan-1,u=0;c<=h;)u+=e[c].find((function(r){return 1===r.rowspan})).height,c++;i.height=u;for(var p=a-i.rowspan,d=h+1,g=d+p-1,v=0;d<=g;)v+=e[d].find((function(r){return 1===r.rowspan})).height,d++;var _=r+i.rowspan,b=e[_].findIndex((function(r){return r._startCol>s._endCol}));-1===b?(e[_].forEach((function(r,t){r._endCol<s._startCol&&(b=t)})),this.rows[_].splice(b+1,0,t(t({},f),{},{rowspan:p,colspan:i.colspan,width:i.width,height:v}))):this.rows[_].splice(b,0,t(t({},f),{},{rowspan:p,colspan:i.colspan,width:i.width,height:v}))}else i.height/=2,this.rows.splice(r+1,0,Array.from({length:1},(function(){return t(t({},f),{},{colspan:i.colspan,width:i.width,height:i.height})}))),e.forEach((function(t,e){t.forEach((function(t,i){e===r&&i===o||w(t._startRow,t._endRow,s._startRow,s._endRow)&&n.rows[t._row][t._col].rowspan++}))}));return{rows:this.rows,row:r,col:o,disabledHandles:this.getDisabledHandles(r,o)}}}},{key:"leftMerge",value:function(r,t){if(!this.getDisabledHandles(r,t).includes("leftMerge")){var o=c(this.rows,r,t,-1);if(o){var n=this.rows[r][t];return o.colspan+=n.colspan,o.width+=n.width,this.rows[r].splice(t,1),{rows:this.rows,row:r,col:t-1,disabledHandles:this.getDisabledHandles(r,t-1)}}}}},{key:"rightMerge",value:function(r,t){if(!this.getDisabledHandles(r,t).includes("rightMerge")){var o=c(this.rows,r,t,1);if(o){var n=this.rows[r][t];return n.colspan+=o.colspan,n.width+=o.width,this.rows[r].splice(t+1,1),{rows:this.rows,row:r,col:t,disabledHandles:this.getDisabledHandles(r,t)}}}}},{key:"topMerge",value:function(r,t){if(!this.getDisabledHandles(r,t).includes("topMerge")){var o=h(this.rows,r,t,-1),n=o.targetCell,e=o.row,s=o.col;if(n){if(1===this.rows[r].length)this.delRow(this.rows,r,t);else{var i=this.rows[r][t];n.rowspan+=i.rowspan,n.height+=i.height,this.rows[r].splice(t,1)}return{rows:this.rows,row:e,col:s,disabledHandles:this.getDisabledHandles(e,s)}}}}},{key:"bottomMerge",value:function(r,t){if(!this.getDisabledHandles(r,t).includes("bottomMerge")){var o=h(this.rows,r,t,1),n=o.targetCell,e=o.row,s=o.col;if(n){if(1===this.rows[e].length)this.delRow(e,s);else{var i=this.rows[r][t];i.rowspan+=n.rowspan,i.height+=n.height,this.rows[e].splice(s,1)}return{rows:this.rows,row:r,col:t,disabledHandles:this.getDisabledHandles(r,t)}}}}}],p=[{key:"init",value:function(r){var o=r.rows,n=r.cols,s=e(r,u);return Array.from({length:o},(function(){return Array.from({length:n},(function(){return t(t({},f),s)}))}))}}],a&&o(i.prototype,a),p&&o(i,p),Object.defineProperty(i,"prototype",{writable:!1}),r}();return p}();