UNPKG

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

Version:

SpreadJS drag merge module

12 lines 8.12 kB
/*! * * SpreadJS Library 18.0.7 * * 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(o){!function(){"use strict";var t,n,e,r;function i(e){var r,r,r=n[e];return void 0!==r||(r=n[e]={exports:{}},t[e].call(r.exports,r,r.exports,i)),r.exports}t={"./dist/plugins/dragMerge/dragMerge-action.js":function(e,r,t){var n,s,t,i,o,c,a,u,g;function f(e,r){return e.JS(r)}function d(e,r){return g.call(this,e,r)||this}n=this&&this.__extends||(u=function(e,r){return(u=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])}))(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}u(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}),Object.defineProperty(r,"__esModule",{value:!0}),r.Commands=void 0,s=t("Core"),Object.defineProperty(r,"Commands",{enumerable:!0,get:function(){return s.Commands}}),t=s.Commands.ActionBase,i=s.Commands.zA,o="dragMerge",c=Math.max,n(d,g=t),d.prototype.canExecute=function(){var e,r,t,r,r,e=this.Mf,r=this.tT,t=f(e,r.oldSelection),r=f(e,r.newSelection);if(t.equals(r)){if((r=e.getSpan(t.row,t.col))&&t.equals(r))return!1;if(1===t.rowCount&&1===t.colCount)return!1}return!0},d.prototype.canUndo=function(){var e,e,e=s.Commands.TI(this.Mf.name()),e=this.tT[e];return s.Commands.AI(e)},d.prototype.undo=function(){var e,r,t,e=this;if(!e.canUndo())return!1;r=e.Mf,e.X5(r,!0),t=s.Commands.TI(r.name()),r.Ut.undo(e.tT[t]),e.q5(r,!0)},d.prototype.execute=function(){var e,r,t,n,i,n,o,a,i,u,e=this,r=e.Mf,t=e.tT,n=t.oldSelection,i=t.newSelection;if(!e.canExecute())return!1;r.Ut.startTransaction(),e.X5(r,!0),r.Ut.do("clearSpan",n.row,n.col,n.rowCount,n.colCount),n=i.row,o=i.col,a=i.rowCount,i=i.colCount,r.addSpan(n,o,a,i),r.setSelection(n,o,c(a,1),c(i,1)),e.q5(r,!0),t[u=s.Commands.TI(r.name())]=r.Ut.endTransaction()},a=d,s.Commands[o]={canUndo:!0,execute:function(e,r,t){return i(e,a,r,t)}},s.Commands.Ttt=function(e){e.register(o,s.Commands[o])}},"./dist/plugins/dragMerge/dragMerge-event.js":function(e,r,t){var n,r,d,u,l,M;function s(e,r){e.ki(n.Events.DragMerging,r)}function c(e,r){e.ki(n.Events.DragMerged,r)}Object.defineProperty(r,"__esModule",{value:!0}),r=(n=t("Core")).GC$,d=null,u=void 0,l=Math.abs,M=n.Ec,r.extend(n.nk.prototype,{Att:function(e){var r,t,n,i,r,t,n=e,i=this.Mf.Ut.findSpan(e.row,e.col);return n=i&&i.containsRange(e)?i:n},zL:function(e,r,t){var n,i,o,a,u,s,c,g,f,o,a,n,u,o,n=this.Mf,i=n.options.rightToLeft,o=n.parent,a=n.U5(),u=n.Dn,s=4,c=8,g=2,f=4;if(o&&o.options.allowUserDragMerge&&a&&!n.Oi&&u.Itt){if(a=(o=u.Itt).x,n=o.y,u=o.width,o=o.height,!i&&l(a+u-r)<=2&&l(n+o/2-t)<=4||i&&l(a-r)<=2&&l(n+o/2-t)<=4)return{right:!0};if(l(a+u/2-r)<=4&&l(n+o-t)<=2)return{bottom:!0}}return d},pk:function(e){var r,e,t,n,n,i,o,a,u,r=this;r.ab=!0,r.rb=!0,r.Uk=!0,r.Rk={e9:e.rowViewportIndex,r9:e.colViewportIndex,Bk:e.hitTestType},r.xtt=e.dragMergeInfo,t=(e=r.Mf).Ut,n=e.U5(),r.Ntt=r.Att(n),i=(n=e.JS(r.Ntt)).row,o=n.col,a=n.rowCount,u=n.colCount,t.GT(i,o,a,u)?(r.rb=!1,r.Uk=!1):(r.ktt=e.Ut.getSpans(n),e.suspendPaint(),t.do("clearSpan",i,o,a,u),e.resumePaint(),r.Dtt=n,r._tt(),r.Ett(n),r.Ok())},Hk:function(){var e,r,t,t,n,i,r,i,r,t,n,e=this,r=e.Mf,t=r.parent;t&&!t.options.allowUserDragMerge?e.ND():(t=e.Q9(),n=e.K9(),i=e.Dtt||e.Ntt,r=r.JS(i),0<=t&&0<=n&&(i=e.xtt,r=e.jtt(r,t,n,i),t=(e.Ott=r).rowCount,n=r.colCount,0<t)&&0<n&&(e._tt(),e.Ett(r),e.Dtt=r,e.a9()))},_tt:function(){var e,r,r,e=this.Mf,r=this.Dtt;r&&((r=e.j1(r)).x-=2,r.y-=2,r.width+=4,r.height+=4,e.Dn.O1(r))},jtt:function(e,r,t,n){var i,o,a,u,s,e,c,g,f,d,l,h,p,v,i,o=this.Mf,a=e.row,u=e.col,s=e.rowCount,e=e.colCount;return n.right?(d=t-(g=u)+1,l=c=a,h=u+e,p=f=s,v=t-u-e+1):n.bottom&&(f=r-(c=a)+1,l=a+s,h=g=u,p=r-a-s+1,v=d=e),o.Ut.eE(l,h,p,v)&&(c=a,g=u,f=s,d=e),M(c,g,f,d)},ND:function(){var e,r,t,n,i,o,a,e,t,e=this,r=e.Mf,t=r.parent,n=e.ktt,i=e.Ntt,o=e.Ott||i;e.ab=!1,e.rb=!1,e.Uk=!1,e.Ott=u,e.ktt=u,e.Dtt=u,e.Ntt=u,e.l9(),t&&t.options.allowUserDragMerge&&(a=r.Ut,r.suspendPaint(),0<n.length&&n.forEach(function(e){a.do("addSpan",e)}),r.resumePaint(),e={sheetName:r.name(),sheet:r,mergeRange:o,cancel:!1},s(r,e),e.cancel||(t={cmd:"dragMerge",sheetName:r.name(),oldSelection:i,newSelection:o},r.Qy().execute(t),c(r,{sheetName:r.name(),sheet:r,mergeRange:o})))},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 m,r,n,g,t,i,o,a;function f(e){var e=e.parent;return e&&e.options.backColor||i}function u(e,r,t){var n,n,t,e,r,n=e.C0(t.row);if((1===n||n!==e.C0(t.row+t.rowCount-1))&&0<(n=e.dw(1)).length)return t=r.y+r.height/2,e=n[0],r=n[n.length-1],e.y<=t&&t<=e.y+e.height||r.y<=t&&t<=r.y+r.height?1:void 0}function s(e,r,t){var n,n,t,e,r,n=e.S0(t.col);if((1===n||n!==e.S0(t.col+t.colCount-1))&&0<(n=e.yw(1)).length)return t=r.x+r.width/2,e=n[0],r=n[n.length-1],e.x<=t&&t<=e.x+e.width||r.x<=t&&t<=r.x+r.width?1:void 0}function w(e,r,t){var e,n,i,o,a,r,t,n=e.Fi(),i=e.Gy(n),o=e.Sy(n),a=u(e,r,t),r=s(e,r,t),t=e.options.rightToLeft,e=1===a&&1===r?n.c9(a,r):1===a?new m.Rect(n.b6,n.Cy,n.F6+i+n.zy,o):1===r?new m.Rect(n.Py,n.T6,i,n.L6+o+n.Iy):t?new m.Rect(n.Hy,n.T6,n.F6+i+n.zy,n.L6+o+n.Iy):new m.Rect(n.b6,n.T6,n.F6+i+n.zy,n.L6+o+n.Iy);return e}Object.defineProperty(r,"__esModule",{value:!0}),m=t("Core"),r=t("Common"),n=t("./dist/plugins/dragMerge/dragMerge-action.js"),g=r.Common.ft,t=m.GC$,i="white",t.extend(m.g7.prototype,{Btt:function(e,r){var t,n,i,i,o,a,u,s,c,g,f,d,l,h,p,v,M,_,n,c,t=this,n=t.Mf,i=n.rt;(0,m.needPaintSelection)(n)&&(c=(i=n.j1(i.Att(r))).x,g=i.y,f=i.width,d=i.height,l=n.options.rightToLeft?c-2:c+f-2,_=w(n,M=new m.Rect(l,h=g+d/(u=2)-(s=o=4),p=4,v=a=8),r),c=w(n,n=new m.Rect(l=c+f/2-4,h=g+d-2,p=8,v=4),r),t.Itt=i,t.Ltt(e,M,n,_,c))},Ltt:function(e,r,t,n,i){var o,a=this.Mf,a=m.Pf.vl(a,a.getSelectionBorderColor());e.save(),e.fillStyle=a,n&&(e.rect(n.x,n.y,n.width,n.height),e.clip()),e.beginPath(),e.rect(r.x,r.y,r.width,r.height),e.fill(),e.restore(),e.save(),e.fillStyle=a,i&&(e.rect(i.x,i.y,i.width,i.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,n,i,o,e,a,u,o,s,o,s,o,s,o,s,i,n,c,s,t=e,n=t.Mf,i=n.parent,o=n.rt,e=e.J(),a=2,u=1;i&&i.options.allowUserDragMerge&&o.Uk&&(o=n.getActiveRowIndex(),s=n.getActiveColumnIndex(),s=(o=n.getActualStyle(o,s))&&o.backColor,o=f(n),(s=g._(m.Pf.vl(n,s||o))).a*=.6/255,e.fillStyle=g.j(s),e.strokeStyle=m.Pf.vl(n,n.getSelectionBorderColor()),e.lineWidth=2,e.beginPath(),o=i.SC,i=(s=n.j1(r)).x,n=s.y,c=s.width,s=s.height,2007<o?(e.rect(i,n,c-1,s-1),e.strokeRect(i-1,n-1,c+1,s+1)):(e.rect(i+1,n+1,c-2-.5,s-2-.5),e.strokeRect(i-.5,n-.5,c,s)),e.fill(),e.restore(),t.Btt(e,r))}}),m.Workbook.ch("dragMerge",o={init:function(){n.Commands.Ttt(this.commandManager())}}),m.Worksheet.ch("dragMerge",a={paintAdornment:function(e){var e,r,t,n,n,e=e.ctx,r=this,t=r.Dn,n=r.Ut.getSelections();r.parent&&r.parent.options.allowUserDragMerge&&1===n.length&&!r.Oi&&(n=r.U5(),t.Btt(e,n))}})},Common:function(e){e.exports=o.Spread},Core:function(e){e.exports=o.Spread.Sheets}},n={},e={},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"),(((o=void 0===o?{}:o).Spread=o.Spread||{}).Sheets=o.Spread.Sheets||{}).DragMerge=e}()});