UNPKG

@grapecity-software/spread-sheets-drag-merge

Version:

SpreadJS drag merge module

12 lines 8.13 kB
/*! * * SpreadJS Library 18.2.5 * * Copyright(c) GrapeCity Software inc. All rights reserved. * * Licensed under the SpreadJS Commercial License. * info.xa@grapecity.com * https://www.grapecity.com.cn/developer/spreadjs * */ !function(e){var r;"object"==typeof module&&"object"==typeof module.exports?(r=require("@grapecity-software/spread-common"),require("@grapecity-software/spread-sheets-core"),module.exports=e(r)):"function"==typeof define&&define.amd?define(["@grapecity-software/spread-common","@grapecity-software/spread-sheets-core"],e):"object"==typeof exports?(r=require("@grapecity-software/spread-common"),require("@grapecity-software/spread-sheets-core"),exports.Spread=e(r)):e(GC)}((function(e){!function(){"use strict";var r,t={"./dist/plugins/dragMerge/dragMerge-action.js":function(e,r,t){var n,i,o,a,u,s,c=this&&this.qKr||(f=function(e,r){return f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},f(e,r)},function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function t(){this.constructor=e}f(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}),f;function g(e,r){return e.JS(r)}Object.defineProperty(r,"__esModule",{value:!0}),r.Commands=void 0,n=t("Core"),Object.defineProperty(r,"Commands",{enumerable:!0,get:function(){return n.Commands}}),i=n.Commands.ActionBase,o=n.Commands.zA,a="dragMerge",u=Math.max,s=function(e){function r(r,t){return e.call(this,r,t)||this}return c(r,e),r.prototype.canExecute=function(){var e,r=this.Mf,t=this.tT,n=g(r,t.oldSelection),i=g(r,t.newSelection);if(n.equals(i)){if((e=r.getSpan(n.row,n.col))&&n.equals(e))return!1;if(1===n.rowCount&&1===n.colCount)return!1}return!0},r.prototype.canUndo=function(){var e=n.Commands.TI(this.Mf.name()),r=this.tT[e];return n.Commands.AI(r)},r.prototype.undo=function(){var e,r,t=this;if(!t.canUndo())return!1;e=t.Mf,t.X5(e,!0),r=n.Commands.TI(e.name()),e.Ut.undo(t.tT[r]),t.q5(e,!0)},r.prototype.execute=function(){var e,r,t,i,o=this,a=o.Mf,s=o.tT,c=s.oldSelection,f=s.newSelection;if(!o.canExecute())return!1;n.Commands.startTransaction(this.Mf.getParent(),this.tT),o.X5(a,!0),a.Ut.do("clearSpan",c.row,c.col,c.rowCount,c.colCount),e=f.row,r=f.col,t=f.rowCount,i=f.colCount,a.addSpan(e,r,t,i),a.setSelection(e,r,u(t,1),u(i,1)),o.q5(a,!0),n.Commands.endTransaction(this.Mf.getParent(),this.tT)},r}(i),n.Commands[a]={canUndo:!0,execute:function(e,r,t){return o(e,s,r,t)}},n.Commands.Ttt=function(e){e.register(a,n.Commands[a])}},"./dist/plugins/dragMerge/dragMerge-event.js":function(e,r,t){var n,i,o,a,u,s;function c(e,r){e.ki(n.Events.DragMerging,r)}function f(e,r){e.ki(n.Events.DragMerged,r)}Object.defineProperty(r,"__esModule",{value:!0}),i=(n=t("Core")).GC$,o=null,a=void 0,u=Math.abs,s=n.Ec,i.extend(n.nk.prototype,{Att:function(e){var r=this,t=r.Mf,n=e,i=t.Ut.findSpan(e.row,e.col);return i&&i.containsRange(e)&&(n=i),n},zL:function(e,r,t){var n,i,a,s,c,f=this.Mf,g=f.options.rightToLeft,d=f.parent,h=f.U5(),l=f.Dn,p=4,v=8,M=p/2,_=v/2;if(d&&d.options.allowUserDragMerge&&h&&!f.Oi&&l.Itt){if(i=(n=l.Itt).x,a=n.y,s=n.width,c=n.height,!g&&u(i+s-r)<=M&&u(a+c/2-t)<=_||g&&u(i-r)<=M&&u(a+c/2-t)<=_)return{right:!0};if(u(i+s/2-r)<=_&&u(a+c-t)<=M)return{bottom:!0}}return o},pk:function(e){var r,t,n,i,o,a,u,s,c=this;if(c.ab=!0,c.rb=!0,c.Uk=!0,c.Rk={e9:e.rowViewportIndex,r9:e.colViewportIndex,Bk:e.hitTestType},c.xtt=e.dragMergeInfo,t=(r=c.Mf).Ut,n=r.U5(),c.Ntt=c.Att(n),o=(i=r.JS(c.Ntt)).row,a=i.col,u=i.rowCount,s=i.colCount,t.GT(o,a,u,s))return c.rb=!1,void(c.Uk=!1);c.ktt=r.Ut.getSpans(i),r.suspendPaint(),t.do("clearSpan",o,a,u,s),r.resumePaint(),c.Dtt=i,c._tt(),c.Ett(i),c.Ok()},Hk:function(){var e,r,t,n,i,o,a,u,s=this,c=s.Mf,f=c.parent;!f||f.options.allowUserDragMerge?(e=s.Q9(),r=s.K9(),t=s.Dtt||s.Ntt,n=c.JS(t),e>=0&&r>=0&&(i=s.xtt,o=s.jtt(n,e,r,i),s.Ott=o,a=o.rowCount,u=o.colCount,a>0&&u>0&&(s._tt(),s.Ett(o),s.Dtt=o,s.a9()))):s.ND()},_tt:function(){var e,r=this.Mf,t=this.Dtt;t&&((e=r.j1(t)).x-=2,e.y-=2,e.width+=4,e.height+=4,r.Dn.O1(e))},jtt:function(e,r,t,n){var i,o,a,u,c,f,g,d,h=this,l=h.Mf,p=e.row,v=e.col,M=e.rowCount,_=e.colCount;return n.right?(o=v,u=t-v+1,c=i=p,f=v+_,g=a=M,d=t-v-_+1):n.bottom&&(i=p,a=r-p+1,c=p+M,f=o=v,g=r-p-M+1,d=u=_),l.Ut.eE(c,f,g,d)&&(i=p,o=v,a=M,u=_),s(i,o,a,u)},ND:function(){var e,r,t,n=this,i=n.Mf,o=i.parent,u=n.ktt,s=n.Ntt,g=n.Ott||s;n.ab=!1,n.rb=!1,n.Uk=!1,n.Ott=a,n.ktt=a,n.Dtt=a,n.Ntt=a,n.l9(),o&&o.options.allowUserDragMerge&&(e=i.Ut,i.suspendPaint(),u.length>0&&u.forEach((function(r){e.do("addSpan",r)})),i.resumePaint(),r={sheetName:i.name(),sheet:i,mergeRange:g,cancel:!1},c(i,r),r.cancel||(t={cmd:"dragMerge",sheetName:i.name(),oldSelection:s,newSelection:g},i.Qy().execute(t),f(i,{sheetName:i.name(),sheet:i,mergeRange:g})))},Ett:function(e){var r,t,n=this.Mf.Dn,i;(0,n.Rtt)(n,e)}})},"./dist/plugins/dragMerge/dragMerge.js":function(e,r,t){var n,i,o,a,u,s,c,f;function g(e){var r=e.parent;return r&&r.options.backColor||s}function d(e,r,t){var n,i,o,a,u=e.C0(t.row);if((1===u||u!==e.C0(t.row+t.rowCount-1))&&(n=e.dw(1)).length>0){if(i=r.y+r.height/2,o=n[0],a=n[n.length-1],o.y<=i&&i<=o.y+o.height)return 1;if(a.y<=i&&i<=a.y+a.height)return 1}}function h(e,r,t){var n,i,o,a,u=e.S0(t.col);if((1===u||u!==e.S0(t.col+t.colCount-1))&&(n=e.yw(1)).length>0){if(i=r.x+r.width/2,o=n[0],a=n[n.length-1],o.x<=i&&i<=o.x+o.width)return 1;if(a.x<=i&&i<=a.x+a.width)return 1}}function l(e,r,t){var i,o=e.Fi(),a=e.Gy(o),u=e.Sy(o),s=d(e,r,t),c=h(e,r,t),f=e.options.rightToLeft;return i=1===s&&1===c?o.c9(s,c):1===s?new n.Rect(o.b6,o.Cy,o.F6+a+o.zy,u):1===c?new n.Rect(o.Py,o.T6,a,o.L6+u+o.Iy):f?new n.Rect(o.Hy,o.T6,o.F6+a+o.zy,o.L6+u+o.Iy):new n.Rect(o.b6,o.T6,o.F6+a+o.zy,o.L6+u+o.Iy)}Object.defineProperty(r,"__esModule",{value:!0}),n=t("Core"),i=t("Common"),o=t("./dist/plugins/dragMerge/dragMerge-action.js"),a=i.Common.ft,u=n.GC$,s="white",u.extend(n.g7.prototype,{Btt:function(e,r){var t,i,o,a,u,s,c,f,g,d,h,p,v,M,_,m,w,j=this,y=j.Mf,b=y.rt;(0,n.needPaintSelection)(y)&&(a=(i=4)/2,u=(o=8)/2,s=(t=y.j1(b.Att(r))).x,c=t.y,f=t.width,g=t.height,d=y.options.rightToLeft?s-a:s+f-a,h=c+g/2-u,p=i,v=o,_=l(y,M=new n.Rect(d,h,p,v),r),d=s+f/2-u,h=c+g-a,p=o,v=i,w=l(y,m=new n.Rect(d,h,p,v),r),j.Itt=t,j.Ltt(e,M,m,_,w))},Ltt:function(e,r,t,i,o){var a,u=this.Mf,s=n.Pf.vl(u,u.getSelectionBorderColor());e.save(),e.fillStyle=s,i&&(e.rect(i.x,i.y,i.width,i.height),e.clip()),e.beginPath(),e.rect(r.x,r.y,r.width,r.height),e.fill(),e.restore(),e.save(),e.fillStyle=s,o&&(e.rect(o.x,o.y,o.width,o.height),e.clip()),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.fill(),e.restore()},Rtt:function(e,r){var t,i,o,u,s,c,f,d,h,l,p,v,M=e,_=M.Mf,m=_.parent,w=_.rt,j=e.J(),y=2,b=y/2;m&&m.options.allowUserDragMerge&&w.Uk&&(t=_.getActiveRowIndex(),i=_.getActiveColumnIndex(),u=(o=_.getActualStyle(t,i))&&o.backColor,s=g(_),(c=a._(n.Pf.vl(_,u||s))).a*=.6/255,j.fillStyle=a.j(c),j.strokeStyle=n.Pf.vl(_,_.getSelectionBorderColor()),j.lineWidth=2,j.beginPath(),f=m.SC,h=(d=_.j1(r)).x,l=d.y,p=d.width,v=d.height,f>2007?(j.rect(h,l,p-b,v-b),j.strokeRect(h-1,l-1,p+1,v+1)):(j.rect(h+1,l+1,p-y-.5,v-y-.5),j.strokeRect(h-.5,l-.5,p,v)),j.fill(),j.restore(),M.Btt(j,r))}}),c={init:function(){o.Commands.Ttt(this.commandManager())}},n.Workbook.ch("dragMerge",c),f={paintAdornment:function(e){var r,t=e.ctx,n=this,i=n.Dn,o=n.Ut.getSelections();n.parent&&n.parent.options.allowUserDragMerge&&1===o.length&&!n.Oi&&(r=n.U5(),i.Btt(t,r))}},n.Worksheet.ch("dragMerge",f)},Common:function(r){r.exports=e.Spread},Core:function(r){r.exports=e.Spread.Sheets}},n={};function i(e){var r,o=n[e];return void 0!==o?o.exports:(r=n[e]={exports:{}},t[e].call(r.exports,r,r.exports,i),r.exports)}r={},function(){var e=r;Object.defineProperty(e,"__esModule",{value:!0}),i("./dist/plugins/dragMerge/dragMerge-action.js"),i("./dist/plugins/dragMerge/dragMerge.js"),i("./dist/plugins/dragMerge/dragMerge-event.js")}(),(((e=void 0===e?{}:e).Spread=e.Spread||{}).Sheets=e.Spread.Sheets||{}).DragMerge=r}()}));