@univerjs/sheets-drawing 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/sheets`),t=require(`@univerjs/core`),n=require(`@univerjs/drawing`),r=require(`@univerjs/engine-render`);function i(t,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=t,{left:p,top:m,width:h,height:g}=(0,e.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function a(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:o=0,angle:s=0}=e,c=(s%360+360)%360;return a(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-o/2,top:r+o/2-i/2,width:o,height:i}:e,t)}let s=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var c=class extends n.UnitDrawingService{};const l=(0,t.createIdentifier)(`sheets-drawing.sheet-drawing.service`);let u=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const d={id:`sheet.mutation.set-drawing-apply`,type:t.CommandType.MUTATION,handler:(e,t)=>{let r=e.get(n.IDrawingManagerService),i=e.get(l),{op:a,unitId:o,subUnitId:s,type:c,objects:d}=t;switch(r.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case u.INSERT:r.addNotification(d),i.addNotification(d);break;case u.REMOVE:r.removeNotification(d),i.removeNotification(d);break;case u.UPDATE:r.updateNotification(d),i.updateNotification(d);break;case u.ARRANGE:r.orderNotification(d),i.orderNotification(d);break;case u.GROUP:r.groupUpdateNotification(d),i.groupUpdateNotification(d);break;case u.UNGROUP:r.ungroupUpdateNotification(d),i.ungroupUpdateNotification(d);break}return!0}},f={id:`sheet.operation.clear-drawing-transformer`,type:t.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},p={id:`sheet.command.insert-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),m=n.get(e.SheetInterceptorService),h=r.drawings,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchAddOp(h),x=m.onCommandExecute({id:p.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},m={id:`sheet.command.remove-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(e.SheetInterceptorService),p=n.get(l),{drawings:h}=r,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=p.getBatchRemoveOp(h),x=c.onCommandExecute({id:m.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},h={id:`sheet.command.set-drawing-arrange`,type:t.CommandType.COMMAND,handler:(e,n)=>{let r=e.get(t.ICommandService),i=e.get(t.IUndoRedoService);if(!n)return!1;let a=e.get(l),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:f}=n,p={unitId:o,subUnitId:s,drawingIds:c},m;if(f===t.ArrangeTypeEnum.forward?m=a.getForwardDrawingsOp(p):f===t.ArrangeTypeEnum.backward?m=a.getBackwardDrawingOp(p):f===t.ArrangeTypeEnum.front?m=a.getFrontDrawingsOp(p):f===t.ArrangeTypeEnum.back&&(m=a.getBackDrawingsOp(p)),m==null)return!1;let{objects:h,redo:g,undo:_}=m;return r.syncExecuteCommand(d.id,{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:d.id,params:{op:_,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}],redoMutations:[{id:d.id,params:{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}]}),!0):!1}},g={id:`sheet.command.set-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),p=n.get(e.SheetInterceptorService),{drawings:m}=r,{unitId:h,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),x=p.onCommandExecute({id:g.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:h,subUnitId:_,op:y,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:h,subUnitId:_,op:v,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:h,undoMutations:C,redoMutations:S}),!0):!1}};function _(e,t){return function(n,r){t(n,r,e)}}function v(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const y=`SHEET_DRAWING_PLUGIN`;let b=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(d))}_initCommands(){[g,p,m,h,f].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:y,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>n(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===e.RemoveSheetCommand.id){var r;let e=n.params,i=e.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:f,redo:p,objects:m}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:d.id,params:{op:p,unitId:c,subUnitId:l,objects:m,type:u.REMOVE}}],undos:[{id:d.id,params:{op:f,unitId:c,subUnitId:l,objects:m,type:u.INSERT}}]}}else if(n.id===e.CopySheetCommand.id){let{unitId:e,subUnitId:r,targetSubUnitId:i}=n.params;if(!e||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(e,r),o=Object.values(a).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,t.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:f,objects:p}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:d.id,params:{op:f,unitId:s,subUnitId:c,objects:p,type:u.INSERT}}],undos:[{id:d.id,params:{op:l,unitId:s,subUnitId:c,objects:p,type:u.REMOVE}}]}}return{redos:[],undos:[]}}}))}};b=v([_(0,(0,t.Inject)(e.SheetInterceptorService)),_(1,(0,t.Inject)(t.IUniverInstanceService)),_(2,t.ICommandService),_(3,l),_(4,n.IDrawingManagerService),_(5,t.IResourceManagerService)],b);var x=`@univerjs/sheets-drawing`,S=`0.20.0`;const C=`sheets-drawing.config`;Symbol(C);const w={};function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=class extends t.Plugin{constructor(e=w,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},w,this._config);this._configService.setConfig(C,i)}onStarting(){[[b],[l,{useClass:c}]].forEach(e=>this._injector.add(e)),this._injector.get(b)}};O(k,`pluginName`,y),O(k,`packageName`,x),O(k,`version`,S),O(k,`type`,t.UniverInstanceType.UNIVER_SHEET),k=v([(0,t.DependentOn)(n.UniverDrawingPlugin),_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],k),exports.ClearSheetDrawingTransformerOperation=f,exports.DrawingApplyType=u,exports.ISheetDrawingService=l,exports.InsertSheetDrawingCommand=p,exports.RemoveSheetDrawingCommand=m,exports.SHEET_DRAWING_PLUGIN=y,exports.SetDrawingApplyMutation=d,exports.SetDrawingArrangeCommand=h,exports.SetSheetDrawingCommand=g,exports.SheetDrawingAnchorType=s,Object.defineProperty(exports,`UniverSheetsDrawingPlugin`,{enumerable:!0,get:function(){return k}}),exports.drawingPositionToTransform=i,exports.transformToAxisAlignPosition=o,exports.transformToDrawingPosition=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/sheets`),t=require(`@univerjs/core`),n=require(`@univerjs/drawing`),r=require(`@univerjs/engine-render`);function i(t,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=t,{left:p,top:m,width:h,height:g}=(0,e.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function a(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:o=0,angle:s=0}=e,c=(s%360+360)%360;return a(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-o/2,top:r+o/2-i/2,width:o,height:i}:e,t)}let s=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var c=class extends n.UnitDrawingService{};const l=(0,t.createIdentifier)(`sheets-drawing.sheet-drawing.service`);let u=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const d={id:`sheet.mutation.set-drawing-apply`,type:t.CommandType.MUTATION,handler:(e,t)=>{let r=e.get(n.IDrawingManagerService),i=e.get(l),{op:a,unitId:o,subUnitId:s,type:c,objects:d}=t;switch(r.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case u.INSERT:r.addNotification(d),i.addNotification(d);break;case u.REMOVE:r.removeNotification(d),i.removeNotification(d);break;case u.UPDATE:r.updateNotification(d),i.updateNotification(d);break;case u.ARRANGE:r.orderNotification(d),i.orderNotification(d);break;case u.GROUP:r.groupUpdateNotification(d),i.groupUpdateNotification(d);break;case u.UNGROUP:r.ungroupUpdateNotification(d),i.ungroupUpdateNotification(d);break}return!0}},f={id:`sheet.operation.clear-drawing-transformer`,type:t.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},p={id:`sheet.command.insert-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),m=n.get(e.SheetInterceptorService),h=r.drawings,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchAddOp(h),x=m.onCommandExecute({id:p.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},m={id:`sheet.command.remove-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(e.SheetInterceptorService),p=n.get(l),{drawings:h}=r,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=p.getBatchRemoveOp(h),x=c.onCommandExecute({id:m.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},h={id:`sheet.command.set-drawing-arrange`,type:t.CommandType.COMMAND,handler:(e,n)=>{let r=e.get(t.ICommandService),i=e.get(t.IUndoRedoService);if(!n)return!1;let a=e.get(l),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:f}=n,p={unitId:o,subUnitId:s,drawingIds:c},m;if(f===t.ArrangeTypeEnum.forward?m=a.getForwardDrawingsOp(p):f===t.ArrangeTypeEnum.backward?m=a.getBackwardDrawingOp(p):f===t.ArrangeTypeEnum.front?m=a.getFrontDrawingsOp(p):f===t.ArrangeTypeEnum.back&&(m=a.getBackDrawingsOp(p)),m==null)return!1;let{objects:h,redo:g,undo:_}=m;return r.syncExecuteCommand(d.id,{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:d.id,params:{op:_,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}],redoMutations:[{id:d.id,params:{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}]}),!0):!1}},g={id:`sheet.command.set-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),p=n.get(e.SheetInterceptorService),{drawings:m}=r,{unitId:h,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),x=p.onCommandExecute({id:g.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:h,subUnitId:_,op:y,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:h,subUnitId:_,op:v,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:h,undoMutations:C,redoMutations:S}),!0):!1}};function _(e,t){return function(n,r){t(n,r,e)}}function v(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const y=`SHEET_DRAWING_PLUGIN`;let b=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(d))}_initCommands(){[g,p,m,h,f].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:y,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>n(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===e.RemoveSheetCommand.id){var r;let e=n.params,i=e.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:f,redo:p,objects:m}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:d.id,params:{op:p,unitId:c,subUnitId:l,objects:m,type:u.REMOVE}}],undos:[{id:d.id,params:{op:f,unitId:c,subUnitId:l,objects:m,type:u.INSERT}}]}}else if(n.id===e.CopySheetCommand.id){let{unitId:e,subUnitId:r,targetSubUnitId:i}=n.params;if(!e||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(e,r),o=Object.values(a).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,t.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:f,objects:p}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:d.id,params:{op:f,unitId:s,subUnitId:c,objects:p,type:u.INSERT}}],undos:[{id:d.id,params:{op:l,unitId:s,subUnitId:c,objects:p,type:u.REMOVE}}]}}return{redos:[],undos:[]}}}))}};b=v([_(0,(0,t.Inject)(e.SheetInterceptorService)),_(1,(0,t.Inject)(t.IUniverInstanceService)),_(2,t.ICommandService),_(3,l),_(4,n.IDrawingManagerService),_(5,t.IResourceManagerService)],b);var x=`@univerjs/sheets-drawing`,S=`0.20.1`;const C=`sheets-drawing.config`;Symbol(C);const w={};function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=class extends t.Plugin{constructor(e=w,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},w,this._config);this._configService.setConfig(C,i)}onStarting(){[[b],[l,{useClass:c}]].forEach(e=>this._injector.add(e)),this._injector.get(b)}};O(k,`pluginName`,y),O(k,`packageName`,x),O(k,`version`,S),O(k,`type`,t.UniverInstanceType.UNIVER_SHEET),k=v([(0,t.DependentOn)(n.UniverDrawingPlugin),_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],k),exports.ClearSheetDrawingTransformerOperation=f,exports.DrawingApplyType=u,exports.ISheetDrawingService=l,exports.InsertSheetDrawingCommand=p,exports.RemoveSheetDrawingCommand=m,exports.SHEET_DRAWING_PLUGIN=y,exports.SetDrawingApplyMutation=d,exports.SetDrawingArrangeCommand=h,exports.SetSheetDrawingCommand=g,exports.SheetDrawingAnchorType=s,Object.defineProperty(exports,`UniverSheetsDrawingPlugin`,{enumerable:!0,get:function(){return k}}),exports.drawingPositionToTransform=i,exports.transformToAxisAlignPosition=o,exports.transformToDrawingPosition=a;
package/lib/es/index.js CHANGED
@@ -1 +1 @@
1
- import{CopySheetCommand as e,RemoveSheetCommand as t,SheetInterceptorService as n,convertPositionSheetOverGridToAbsolute as r}from"@univerjs/sheets";import{ArrangeTypeEnum as i,CommandType as a,DependentOn as o,Disposable as s,DrawingTypeEnum as c,ICommandService as l,IConfigService as u,IResourceManagerService as d,IUndoRedoService as f,IUniverInstanceService as p,Inject as m,Injector as h,Plugin as g,UniverInstanceType as _,createIdentifier as v,generateRandomId as y,merge as b,sequenceExecute as x}from"@univerjs/core";import{IDrawingManagerService as S,UnitDrawingService as C,UniverDrawingPlugin as w}from"@univerjs/drawing";import{IRenderManagerService as T}from"@univerjs/engine-render";function E(e,t){if(!t)return;let{unitId:n,sheetId:i,skeleton:a}=t,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=r(n,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function D(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function O(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:o=0}=e,s=(o%360+360)%360;return D(s>=45&&s<135||s>=225&&s<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let k=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var A=class extends C{};const j=v(`sheets-drawing.sheet-drawing.service`);let M=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const N={id:`sheet.mutation.set-drawing-apply`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(S),r=e.get(j),{op:i,unitId:a,subUnitId:o,type:s,objects:c}=t;switch(n.applyJson1(a,o,i),r.applyJson1(a,o,i),s){case M.INSERT:n.addNotification(c),r.addNotification(c);break;case M.REMOVE:n.removeNotification(c),r.removeNotification(c);break;case M.UPDATE:n.updateNotification(c),r.updateNotification(c);break;case M.ARRANGE:n.orderNotification(c),r.orderNotification(c);break;case M.GROUP:n.groupUpdateNotification(c),r.groupUpdateNotification(c);break;case M.UNGROUP:n.ungroupUpdateNotification(c),r.ungroupUpdateNotification(c);break}return!0}},P={id:`sheet.operation.clear-drawing-transformer`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(T);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},F={id:`sheet.command.insert-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),u=t.drawings,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchAddOp(u),_=c.onCommandExecute({id:F.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},I={id:`sheet.command.remove-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(n),c=e.get(j),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=c.getBatchRemoveOp(u),_=s.onCommandExecute({id:I.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},L={id:`sheet.command.set-drawing-arrange`,type:a.COMMAND,handler:(e,t)=>{let n=e.get(l),r=e.get(f);if(!t)return!1;let a=e.get(j),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:u}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(u===i.forward?p=a.getForwardDrawingsOp(d):u===i.backward?p=a.getBackwardDrawingOp(d):u===i.front?p=a.getFrontDrawingsOp(d):u===i.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return n.syncExecuteCommand(N.id,{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE})?(r.pushUndoRedo({unitID:o,undoMutations:[{id:N.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}],redoMutations:[{id:N.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}]}),!0):!1}},R={id:`sheet.command.set-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchUpdateOp(u),_=c.onCommandExecute({id:R.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}};function z(e,t){return function(n,r){t(n,r,e)}}function B(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const V=`SHEET_DRAWING_PLUGIN`;let H=class extends s{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(N))}_initCommands(){[R,F,I,L,P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:V,businesses:[_.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===t.id){var r;let e=n.params,t=e.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!t||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,i),o=Object.values(a).filter(e=>e.drawingType!==c.DRAWING_CHART);if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:l,undo:u,redo:d,objects:f}=this._sheetDrawingService.getBatchRemoveOp(o);return{redos:[{id:N.id,params:{op:d,unitId:s,subUnitId:l,objects:f,type:M.REMOVE}}],undos:[{id:N.id,params:{op:u,unitId:s,subUnitId:l,objects:f,type:M.INSERT}}]}}else if(n.id===e.id){let{unitId:e,subUnitId:t,targetSubUnitId:r}=n.params;if(!e||!t||!r)return{redos:[],undos:[]};let i=this._sheetDrawingService.getDrawingData(e,t),a=Object.values(i).filter(e=>e.drawingType!==c.DRAWING_CHART).map(e=>({...e,subUnitId:r,drawingId:y(6)}));if(a.length===0)return{redos:[],undos:[]};let{unitId:o,subUnitId:s,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(a);return{redos:[{id:N.id,params:{op:u,unitId:o,subUnitId:s,objects:d,type:M.INSERT}}],undos:[{id:N.id,params:{op:l,unitId:o,subUnitId:s,objects:d,type:M.REMOVE}}]}}return{redos:[],undos:[]}}}))}};H=B([z(0,m(n)),z(1,m(p)),z(2,l),z(3,j),z(4,S),z(5,d)],H);var U=`@univerjs/sheets-drawing`,W=`0.20.0`;const G=`sheets-drawing.config`;Symbol(G);const K={};function q(e){"@babel/helpers - typeof";return q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},q(e)}function J(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Y(e){var t=J(e,`string`);return q(t)==`symbol`?t:t+``}function X(e,t,n){return(t=Y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Z=class extends g{constructor(e=K,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=b({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[H],[j,{useClass:A}]].forEach(e=>this._injector.add(e)),this._injector.get(H)}};X(Z,`pluginName`,V),X(Z,`packageName`,U),X(Z,`version`,W),X(Z,`type`,_.UNIVER_SHEET),Z=B([o(w),z(1,m(h)),z(2,u)],Z);export{P as ClearSheetDrawingTransformerOperation,M as DrawingApplyType,j as ISheetDrawingService,F as InsertSheetDrawingCommand,I as RemoveSheetDrawingCommand,V as SHEET_DRAWING_PLUGIN,N as SetDrawingApplyMutation,L as SetDrawingArrangeCommand,R as SetSheetDrawingCommand,k as SheetDrawingAnchorType,Z as UniverSheetsDrawingPlugin,E as drawingPositionToTransform,O as transformToAxisAlignPosition,D as transformToDrawingPosition};
1
+ import{CopySheetCommand as e,RemoveSheetCommand as t,SheetInterceptorService as n,convertPositionSheetOverGridToAbsolute as r}from"@univerjs/sheets";import{ArrangeTypeEnum as i,CommandType as a,DependentOn as o,Disposable as s,DrawingTypeEnum as c,ICommandService as l,IConfigService as u,IResourceManagerService as d,IUndoRedoService as f,IUniverInstanceService as p,Inject as m,Injector as h,Plugin as g,UniverInstanceType as _,createIdentifier as v,generateRandomId as y,merge as b,sequenceExecute as x}from"@univerjs/core";import{IDrawingManagerService as S,UnitDrawingService as C,UniverDrawingPlugin as w}from"@univerjs/drawing";import{IRenderManagerService as T}from"@univerjs/engine-render";function E(e,t){if(!t)return;let{unitId:n,sheetId:i,skeleton:a}=t,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=r(n,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function D(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function O(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:o=0}=e,s=(o%360+360)%360;return D(s>=45&&s<135||s>=225&&s<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let k=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var A=class extends C{};const j=v(`sheets-drawing.sheet-drawing.service`);let M=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const N={id:`sheet.mutation.set-drawing-apply`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(S),r=e.get(j),{op:i,unitId:a,subUnitId:o,type:s,objects:c}=t;switch(n.applyJson1(a,o,i),r.applyJson1(a,o,i),s){case M.INSERT:n.addNotification(c),r.addNotification(c);break;case M.REMOVE:n.removeNotification(c),r.removeNotification(c);break;case M.UPDATE:n.updateNotification(c),r.updateNotification(c);break;case M.ARRANGE:n.orderNotification(c),r.orderNotification(c);break;case M.GROUP:n.groupUpdateNotification(c),r.groupUpdateNotification(c);break;case M.UNGROUP:n.ungroupUpdateNotification(c),r.ungroupUpdateNotification(c);break}return!0}},P={id:`sheet.operation.clear-drawing-transformer`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(T);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},F={id:`sheet.command.insert-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),u=t.drawings,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchAddOp(u),_=c.onCommandExecute({id:F.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},I={id:`sheet.command.remove-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(n),c=e.get(j),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=c.getBatchRemoveOp(u),_=s.onCommandExecute({id:I.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},L={id:`sheet.command.set-drawing-arrange`,type:a.COMMAND,handler:(e,t)=>{let n=e.get(l),r=e.get(f);if(!t)return!1;let a=e.get(j),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:u}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(u===i.forward?p=a.getForwardDrawingsOp(d):u===i.backward?p=a.getBackwardDrawingOp(d):u===i.front?p=a.getFrontDrawingsOp(d):u===i.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return n.syncExecuteCommand(N.id,{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE})?(r.pushUndoRedo({unitID:o,undoMutations:[{id:N.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}],redoMutations:[{id:N.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}]}),!0):!1}},R={id:`sheet.command.set-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchUpdateOp(u),_=c.onCommandExecute({id:R.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}};function z(e,t){return function(n,r){t(n,r,e)}}function B(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const V=`SHEET_DRAWING_PLUGIN`;let H=class extends s{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(N))}_initCommands(){[R,F,I,L,P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:V,businesses:[_.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===t.id){var r;let e=n.params,t=e.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!t||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,i),o=Object.values(a).filter(e=>e.drawingType!==c.DRAWING_CHART);if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:l,undo:u,redo:d,objects:f}=this._sheetDrawingService.getBatchRemoveOp(o);return{redos:[{id:N.id,params:{op:d,unitId:s,subUnitId:l,objects:f,type:M.REMOVE}}],undos:[{id:N.id,params:{op:u,unitId:s,subUnitId:l,objects:f,type:M.INSERT}}]}}else if(n.id===e.id){let{unitId:e,subUnitId:t,targetSubUnitId:r}=n.params;if(!e||!t||!r)return{redos:[],undos:[]};let i=this._sheetDrawingService.getDrawingData(e,t),a=Object.values(i).filter(e=>e.drawingType!==c.DRAWING_CHART).map(e=>({...e,subUnitId:r,drawingId:y(6)}));if(a.length===0)return{redos:[],undos:[]};let{unitId:o,subUnitId:s,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(a);return{redos:[{id:N.id,params:{op:u,unitId:o,subUnitId:s,objects:d,type:M.INSERT}}],undos:[{id:N.id,params:{op:l,unitId:o,subUnitId:s,objects:d,type:M.REMOVE}}]}}return{redos:[],undos:[]}}}))}};H=B([z(0,m(n)),z(1,m(p)),z(2,l),z(3,j),z(4,S),z(5,d)],H);var U=`@univerjs/sheets-drawing`,W=`0.20.1`;const G=`sheets-drawing.config`;Symbol(G);const K={};function q(e){"@babel/helpers - typeof";return q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},q(e)}function J(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Y(e){var t=J(e,`string`);return q(t)==`symbol`?t:t+``}function X(e,t,n){return(t=Y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Z=class extends g{constructor(e=K,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=b({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[H],[j,{useClass:A}]].forEach(e=>this._injector.add(e)),this._injector.get(H)}};X(Z,`pluginName`,V),X(Z,`packageName`,U),X(Z,`version`,W),X(Z,`type`,_.UNIVER_SHEET),Z=B([o(w),z(1,m(h)),z(2,u)],Z);export{P as ClearSheetDrawingTransformerOperation,M as DrawingApplyType,j as ISheetDrawingService,F as InsertSheetDrawingCommand,I as RemoveSheetDrawingCommand,V as SHEET_DRAWING_PLUGIN,N as SetDrawingApplyMutation,L as SetDrawingArrangeCommand,R as SetSheetDrawingCommand,k as SheetDrawingAnchorType,Z as UniverSheetsDrawingPlugin,E as drawingPositionToTransform,O as transformToAxisAlignPosition,D as transformToDrawingPosition};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{CopySheetCommand as e,RemoveSheetCommand as t,SheetInterceptorService as n,convertPositionSheetOverGridToAbsolute as r}from"@univerjs/sheets";import{ArrangeTypeEnum as i,CommandType as a,DependentOn as o,Disposable as s,DrawingTypeEnum as c,ICommandService as l,IConfigService as u,IResourceManagerService as d,IUndoRedoService as f,IUniverInstanceService as p,Inject as m,Injector as h,Plugin as g,UniverInstanceType as _,createIdentifier as v,generateRandomId as y,merge as b,sequenceExecute as x}from"@univerjs/core";import{IDrawingManagerService as S,UnitDrawingService as C,UniverDrawingPlugin as w}from"@univerjs/drawing";import{IRenderManagerService as T}from"@univerjs/engine-render";function E(e,t){if(!t)return;let{unitId:n,sheetId:i,skeleton:a}=t,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=r(n,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function D(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function O(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:o=0}=e,s=(o%360+360)%360;return D(s>=45&&s<135||s>=225&&s<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let k=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var A=class extends C{};const j=v(`sheets-drawing.sheet-drawing.service`);let M=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const N={id:`sheet.mutation.set-drawing-apply`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(S),r=e.get(j),{op:i,unitId:a,subUnitId:o,type:s,objects:c}=t;switch(n.applyJson1(a,o,i),r.applyJson1(a,o,i),s){case M.INSERT:n.addNotification(c),r.addNotification(c);break;case M.REMOVE:n.removeNotification(c),r.removeNotification(c);break;case M.UPDATE:n.updateNotification(c),r.updateNotification(c);break;case M.ARRANGE:n.orderNotification(c),r.orderNotification(c);break;case M.GROUP:n.groupUpdateNotification(c),r.groupUpdateNotification(c);break;case M.UNGROUP:n.ungroupUpdateNotification(c),r.ungroupUpdateNotification(c);break}return!0}},P={id:`sheet.operation.clear-drawing-transformer`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(T);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},F={id:`sheet.command.insert-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),u=t.drawings,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchAddOp(u),_=c.onCommandExecute({id:F.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},I={id:`sheet.command.remove-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(n),c=e.get(j),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=c.getBatchRemoveOp(u),_=s.onCommandExecute({id:I.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},L={id:`sheet.command.set-drawing-arrange`,type:a.COMMAND,handler:(e,t)=>{let n=e.get(l),r=e.get(f);if(!t)return!1;let a=e.get(j),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:u}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(u===i.forward?p=a.getForwardDrawingsOp(d):u===i.backward?p=a.getBackwardDrawingOp(d):u===i.front?p=a.getFrontDrawingsOp(d):u===i.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return n.syncExecuteCommand(N.id,{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE})?(r.pushUndoRedo({unitID:o,undoMutations:[{id:N.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}],redoMutations:[{id:N.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}]}),!0):!1}},R={id:`sheet.command.set-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchUpdateOp(u),_=c.onCommandExecute({id:R.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}};function z(e,t){return function(n,r){t(n,r,e)}}function B(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const V=`SHEET_DRAWING_PLUGIN`;let H=class extends s{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(N))}_initCommands(){[R,F,I,L,P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:V,businesses:[_.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===t.id){var r;let e=n.params,t=e.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!t||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,i),o=Object.values(a).filter(e=>e.drawingType!==c.DRAWING_CHART);if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:l,undo:u,redo:d,objects:f}=this._sheetDrawingService.getBatchRemoveOp(o);return{redos:[{id:N.id,params:{op:d,unitId:s,subUnitId:l,objects:f,type:M.REMOVE}}],undos:[{id:N.id,params:{op:u,unitId:s,subUnitId:l,objects:f,type:M.INSERT}}]}}else if(n.id===e.id){let{unitId:e,subUnitId:t,targetSubUnitId:r}=n.params;if(!e||!t||!r)return{redos:[],undos:[]};let i=this._sheetDrawingService.getDrawingData(e,t),a=Object.values(i).filter(e=>e.drawingType!==c.DRAWING_CHART).map(e=>({...e,subUnitId:r,drawingId:y(6)}));if(a.length===0)return{redos:[],undos:[]};let{unitId:o,subUnitId:s,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(a);return{redos:[{id:N.id,params:{op:u,unitId:o,subUnitId:s,objects:d,type:M.INSERT}}],undos:[{id:N.id,params:{op:l,unitId:o,subUnitId:s,objects:d,type:M.REMOVE}}]}}return{redos:[],undos:[]}}}))}};H=B([z(0,m(n)),z(1,m(p)),z(2,l),z(3,j),z(4,S),z(5,d)],H);var U=`@univerjs/sheets-drawing`,W=`0.20.0`;const G=`sheets-drawing.config`;Symbol(G);const K={};function q(e){"@babel/helpers - typeof";return q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},q(e)}function J(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Y(e){var t=J(e,`string`);return q(t)==`symbol`?t:t+``}function X(e,t,n){return(t=Y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Z=class extends g{constructor(e=K,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=b({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[H],[j,{useClass:A}]].forEach(e=>this._injector.add(e)),this._injector.get(H)}};X(Z,`pluginName`,V),X(Z,`packageName`,U),X(Z,`version`,W),X(Z,`type`,_.UNIVER_SHEET),Z=B([o(w),z(1,m(h)),z(2,u)],Z);export{P as ClearSheetDrawingTransformerOperation,M as DrawingApplyType,j as ISheetDrawingService,F as InsertSheetDrawingCommand,I as RemoveSheetDrawingCommand,V as SHEET_DRAWING_PLUGIN,N as SetDrawingApplyMutation,L as SetDrawingArrangeCommand,R as SetSheetDrawingCommand,k as SheetDrawingAnchorType,Z as UniverSheetsDrawingPlugin,E as drawingPositionToTransform,O as transformToAxisAlignPosition,D as transformToDrawingPosition};
1
+ import{CopySheetCommand as e,RemoveSheetCommand as t,SheetInterceptorService as n,convertPositionSheetOverGridToAbsolute as r}from"@univerjs/sheets";import{ArrangeTypeEnum as i,CommandType as a,DependentOn as o,Disposable as s,DrawingTypeEnum as c,ICommandService as l,IConfigService as u,IResourceManagerService as d,IUndoRedoService as f,IUniverInstanceService as p,Inject as m,Injector as h,Plugin as g,UniverInstanceType as _,createIdentifier as v,generateRandomId as y,merge as b,sequenceExecute as x}from"@univerjs/core";import{IDrawingManagerService as S,UnitDrawingService as C,UniverDrawingPlugin as w}from"@univerjs/drawing";import{IRenderManagerService as T}from"@univerjs/engine-render";function E(e,t){if(!t)return;let{unitId:n,sheetId:i,skeleton:a}=t,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=r(n,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function D(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function O(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:o=0}=e,s=(o%360+360)%360;return D(s>=45&&s<135||s>=225&&s<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let k=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var A=class extends C{};const j=v(`sheets-drawing.sheet-drawing.service`);let M=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const N={id:`sheet.mutation.set-drawing-apply`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(S),r=e.get(j),{op:i,unitId:a,subUnitId:o,type:s,objects:c}=t;switch(n.applyJson1(a,o,i),r.applyJson1(a,o,i),s){case M.INSERT:n.addNotification(c),r.addNotification(c);break;case M.REMOVE:n.removeNotification(c),r.removeNotification(c);break;case M.UPDATE:n.updateNotification(c),r.updateNotification(c);break;case M.ARRANGE:n.orderNotification(c),r.orderNotification(c);break;case M.GROUP:n.groupUpdateNotification(c),r.groupUpdateNotification(c);break;case M.UNGROUP:n.ungroupUpdateNotification(c),r.ungroupUpdateNotification(c);break}return!0}},P={id:`sheet.operation.clear-drawing-transformer`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(T);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},F={id:`sheet.command.insert-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),u=t.drawings,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchAddOp(u),_=c.onCommandExecute({id:F.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},I={id:`sheet.command.remove-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(n),c=e.get(j),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=c.getBatchRemoveOp(u),_=s.onCommandExecute({id:I.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},L={id:`sheet.command.set-drawing-arrange`,type:a.COMMAND,handler:(e,t)=>{let n=e.get(l),r=e.get(f);if(!t)return!1;let a=e.get(j),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:u}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(u===i.forward?p=a.getForwardDrawingsOp(d):u===i.backward?p=a.getBackwardDrawingOp(d):u===i.front?p=a.getFrontDrawingsOp(d):u===i.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return n.syncExecuteCommand(N.id,{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE})?(r.pushUndoRedo({unitID:o,undoMutations:[{id:N.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}],redoMutations:[{id:N.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}]}),!0):!1}},R={id:`sheet.command.set-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchUpdateOp(u),_=c.onCommandExecute({id:R.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}};function z(e,t){return function(n,r){t(n,r,e)}}function B(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const V=`SHEET_DRAWING_PLUGIN`;let H=class extends s{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(N))}_initCommands(){[R,F,I,L,P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:V,businesses:[_.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===t.id){var r;let e=n.params,t=e.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!t||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,i),o=Object.values(a).filter(e=>e.drawingType!==c.DRAWING_CHART);if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:l,undo:u,redo:d,objects:f}=this._sheetDrawingService.getBatchRemoveOp(o);return{redos:[{id:N.id,params:{op:d,unitId:s,subUnitId:l,objects:f,type:M.REMOVE}}],undos:[{id:N.id,params:{op:u,unitId:s,subUnitId:l,objects:f,type:M.INSERT}}]}}else if(n.id===e.id){let{unitId:e,subUnitId:t,targetSubUnitId:r}=n.params;if(!e||!t||!r)return{redos:[],undos:[]};let i=this._sheetDrawingService.getDrawingData(e,t),a=Object.values(i).filter(e=>e.drawingType!==c.DRAWING_CHART).map(e=>({...e,subUnitId:r,drawingId:y(6)}));if(a.length===0)return{redos:[],undos:[]};let{unitId:o,subUnitId:s,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(a);return{redos:[{id:N.id,params:{op:u,unitId:o,subUnitId:s,objects:d,type:M.INSERT}}],undos:[{id:N.id,params:{op:l,unitId:o,subUnitId:s,objects:d,type:M.REMOVE}}]}}return{redos:[],undos:[]}}}))}};H=B([z(0,m(n)),z(1,m(p)),z(2,l),z(3,j),z(4,S),z(5,d)],H);var U=`@univerjs/sheets-drawing`,W=`0.20.1`;const G=`sheets-drawing.config`;Symbol(G);const K={};function q(e){"@babel/helpers - typeof";return q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},q(e)}function J(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Y(e){var t=J(e,`string`);return q(t)==`symbol`?t:t+``}function X(e,t,n){return(t=Y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Z=class extends g{constructor(e=K,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=b({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[H],[j,{useClass:A}]].forEach(e=>this._injector.add(e)),this._injector.get(H)}};X(Z,`pluginName`,V),X(Z,`packageName`,U),X(Z,`version`,W),X(Z,`type`,_.UNIVER_SHEET),Z=B([o(w),z(1,m(h)),z(2,u)],Z);export{P as ClearSheetDrawingTransformerOperation,M as DrawingApplyType,j as ISheetDrawingService,F as InsertSheetDrawingCommand,I as RemoveSheetDrawingCommand,V as SHEET_DRAWING_PLUGIN,N as SetDrawingApplyMutation,L as SetDrawingArrangeCommand,R as SetSheetDrawingCommand,k as SheetDrawingAnchorType,Z as UniverSheetsDrawingPlugin,E as drawingPositionToTransform,O as transformToAxisAlignPosition,D as transformToDrawingPosition};
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/sheets`),require(`@univerjs/core`),require(`@univerjs/drawing`),require(`@univerjs/engine-render`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/sheets`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawing={},e.UniverSheets,e.UniverCore,e.UniverDrawing,e.UniverEngineRender))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=(0,t.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function s(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:s=0}=e,c=(s%360+360)%360;return o(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let c=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var l=class extends r.UnitDrawingService{};let u=(0,n.createIdentifier)(`sheets-drawing.sheet-drawing.service`),d=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({}),f={id:`sheet.mutation.set-drawing-apply`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IDrawingManagerService),i=e.get(u),{op:a,unitId:o,subUnitId:s,type:c,objects:l}=t;switch(n.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case d.INSERT:n.addNotification(l),i.addNotification(l);break;case d.REMOVE:n.removeNotification(l),i.removeNotification(l);break;case d.UPDATE:n.updateNotification(l),i.updateNotification(l);break;case d.ARRANGE:n.orderNotification(l),i.orderNotification(l);break;case d.GROUP:n.groupUpdateNotification(l),i.groupUpdateNotification(l);break;case d.UNGROUP:n.ungroupUpdateNotification(l),i.ungroupUpdateNotification(l);break}return!0}},p={id:`sheet.operation.clear-drawing-transformer`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(i.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},m={id:`sheet.command.insert-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),h=r.drawings,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchAddOp(h),x=l.onCommandExecute({id:m.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:d.INSERT}},{id:p.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:d.REMOVE}},{id:p.id,params:[g]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},h={id:`sheet.command.remove-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(t.SheetInterceptorService),l=e.get(u),{drawings:m}=r,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=l.getBatchRemoveOp(m),x=c.onCommandExecute({id:h.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:d.REMOVE}},{id:p.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:d.INSERT}},{id:p.id,params:[g]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},g={id:`sheet.command.set-drawing-arrange`,type:n.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ICommandService),i=e.get(n.IUndoRedoService);if(!t)return!1;let a=e.get(u),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:l}=t,p={unitId:o,subUnitId:s,drawingIds:c},m;if(l===n.ArrangeTypeEnum.forward?m=a.getForwardDrawingsOp(p):l===n.ArrangeTypeEnum.backward?m=a.getBackwardDrawingOp(p):l===n.ArrangeTypeEnum.front?m=a.getFrontDrawingsOp(p):l===n.ArrangeTypeEnum.back&&(m=a.getBackDrawingsOp(p)),m==null)return!1;let{objects:h,redo:g,undo:_}=m;return r.syncExecuteCommand(f.id,{op:g,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:f.id,params:{op:_,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE}}],redoMutations:[{id:f.id,params:{op:g,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE}}]}),!0):!1}},_={id:`sheet.command.set-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),{drawings:m}=r,{unitId:h,subUnitId:g,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),x=l.onCommandExecute({id:_.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:h,subUnitId:g,op:y,objects:b,type:d.UPDATE}},{id:p.id,params:[h]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:h,subUnitId:g,op:v,objects:b,type:d.UPDATE}},{id:p.id,params:[h]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:h,undoMutations:C,redoMutations:S}),!0):!1}};function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=`SHEET_DRAWING_PLUGIN`,x=class extends n.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(f))}_initCommands(){[_,m,h,g,p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:b,businesses:[n.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===t.RemoveSheetCommand.id){var r;let t=e.params,i=t.unitId||this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=t.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:u,redo:p,objects:m}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:f.id,params:{op:p,unitId:c,subUnitId:l,objects:m,type:d.REMOVE}}],undos:[{id:f.id,params:{op:u,unitId:c,subUnitId:l,objects:m,type:d.INSERT}}]}}else if(e.id===t.CopySheetCommand.id){let{unitId:t,subUnitId:r,targetSubUnitId:i}=e.params;if(!t||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,r),o=Object.values(a).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,n.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:u,objects:p}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:f.id,params:{op:u,unitId:s,subUnitId:c,objects:p,type:d.INSERT}}],undos:[{id:f.id,params:{op:l,unitId:s,subUnitId:c,objects:p,type:d.REMOVE}}]}}return{redos:[],undos:[]}}}))}};x=y([v(0,(0,n.Inject)(t.SheetInterceptorService)),v(1,(0,n.Inject)(n.IUniverInstanceService)),v(2,n.ICommandService),v(3,u),v(4,r.IDrawingManagerService),v(5,n.IResourceManagerService)],x);var S=`@univerjs/sheets-drawing`,C=`0.20.0`;let w=`sheets-drawing.config`;Symbol(w);let T={};function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let A=class extends n.Plugin{constructor(e=T,t,r){super(),this._config=e,this._injector=t,this._configService=r;let{...i}=(0,n.merge)({},T,this._config);this._configService.setConfig(w,i)}onStarting(){[[x],[u,{useClass:l}]].forEach(e=>this._injector.add(e)),this._injector.get(x)}};k(A,`pluginName`,b),k(A,`packageName`,S),k(A,`version`,C),k(A,`type`,n.UniverInstanceType.UNIVER_SHEET),A=y([(0,n.DependentOn)(r.UniverDrawingPlugin),v(1,(0,n.Inject)(n.Injector)),v(2,n.IConfigService)],A),e.ClearSheetDrawingTransformerOperation=p,e.DrawingApplyType=d,e.ISheetDrawingService=u,e.InsertSheetDrawingCommand=m,e.RemoveSheetDrawingCommand=h,e.SHEET_DRAWING_PLUGIN=b,e.SetDrawingApplyMutation=f,e.SetDrawingArrangeCommand=g,e.SetSheetDrawingCommand=_,e.SheetDrawingAnchorType=c,Object.defineProperty(e,`UniverSheetsDrawingPlugin`,{enumerable:!0,get:function(){return A}}),e.drawingPositionToTransform=a,e.transformToAxisAlignPosition=s,e.transformToDrawingPosition=o});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/sheets`),require(`@univerjs/core`),require(`@univerjs/drawing`),require(`@univerjs/engine-render`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/sheets`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawing={},e.UniverSheets,e.UniverCore,e.UniverDrawing,e.UniverEngineRender))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=(0,t.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function s(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:s=0}=e,c=(s%360+360)%360;return o(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let c=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var l=class extends r.UnitDrawingService{};let u=(0,n.createIdentifier)(`sheets-drawing.sheet-drawing.service`),d=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({}),f={id:`sheet.mutation.set-drawing-apply`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IDrawingManagerService),i=e.get(u),{op:a,unitId:o,subUnitId:s,type:c,objects:l}=t;switch(n.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case d.INSERT:n.addNotification(l),i.addNotification(l);break;case d.REMOVE:n.removeNotification(l),i.removeNotification(l);break;case d.UPDATE:n.updateNotification(l),i.updateNotification(l);break;case d.ARRANGE:n.orderNotification(l),i.orderNotification(l);break;case d.GROUP:n.groupUpdateNotification(l),i.groupUpdateNotification(l);break;case d.UNGROUP:n.ungroupUpdateNotification(l),i.ungroupUpdateNotification(l);break}return!0}},p={id:`sheet.operation.clear-drawing-transformer`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(i.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},m={id:`sheet.command.insert-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),h=r.drawings,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchAddOp(h),x=l.onCommandExecute({id:m.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:d.INSERT}},{id:p.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:d.REMOVE}},{id:p.id,params:[g]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},h={id:`sheet.command.remove-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(t.SheetInterceptorService),l=e.get(u),{drawings:m}=r,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=l.getBatchRemoveOp(m),x=c.onCommandExecute({id:h.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:d.REMOVE}},{id:p.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:d.INSERT}},{id:p.id,params:[g]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},g={id:`sheet.command.set-drawing-arrange`,type:n.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ICommandService),i=e.get(n.IUndoRedoService);if(!t)return!1;let a=e.get(u),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:l}=t,p={unitId:o,subUnitId:s,drawingIds:c},m;if(l===n.ArrangeTypeEnum.forward?m=a.getForwardDrawingsOp(p):l===n.ArrangeTypeEnum.backward?m=a.getBackwardDrawingOp(p):l===n.ArrangeTypeEnum.front?m=a.getFrontDrawingsOp(p):l===n.ArrangeTypeEnum.back&&(m=a.getBackDrawingsOp(p)),m==null)return!1;let{objects:h,redo:g,undo:_}=m;return r.syncExecuteCommand(f.id,{op:g,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:f.id,params:{op:_,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE}}],redoMutations:[{id:f.id,params:{op:g,unitId:o,subUnitId:s,objects:h,type:d.ARRANGE}}]}),!0):!1}},_={id:`sheet.command.set-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),{drawings:m}=r,{unitId:h,subUnitId:g,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),x=l.onCommandExecute({id:_.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:f.id,params:{unitId:h,subUnitId:g,op:y,objects:b,type:d.UPDATE}},{id:p.id,params:[h]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:f.id,params:{unitId:h,subUnitId:g,op:v,objects:b,type:d.UPDATE}},{id:p.id,params:[h]},...x.undos];return(0,n.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:h,undoMutations:C,redoMutations:S}),!0):!1}};function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=`SHEET_DRAWING_PLUGIN`,x=class extends n.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(f))}_initCommands(){[_,m,h,g,p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:b,businesses:[n.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===t.RemoveSheetCommand.id){var r;let t=e.params,i=t.unitId||this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=t.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:u,redo:p,objects:m}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:f.id,params:{op:p,unitId:c,subUnitId:l,objects:m,type:d.REMOVE}}],undos:[{id:f.id,params:{op:u,unitId:c,subUnitId:l,objects:m,type:d.INSERT}}]}}else if(e.id===t.CopySheetCommand.id){let{unitId:t,subUnitId:r,targetSubUnitId:i}=e.params;if(!t||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,r),o=Object.values(a).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,n.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:u,objects:p}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:f.id,params:{op:u,unitId:s,subUnitId:c,objects:p,type:d.INSERT}}],undos:[{id:f.id,params:{op:l,unitId:s,subUnitId:c,objects:p,type:d.REMOVE}}]}}return{redos:[],undos:[]}}}))}};x=y([v(0,(0,n.Inject)(t.SheetInterceptorService)),v(1,(0,n.Inject)(n.IUniverInstanceService)),v(2,n.ICommandService),v(3,u),v(4,r.IDrawingManagerService),v(5,n.IResourceManagerService)],x);var S=`@univerjs/sheets-drawing`,C=`0.20.1`;let w=`sheets-drawing.config`;Symbol(w);let T={};function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let A=class extends n.Plugin{constructor(e=T,t,r){super(),this._config=e,this._injector=t,this._configService=r;let{...i}=(0,n.merge)({},T,this._config);this._configService.setConfig(w,i)}onStarting(){[[x],[u,{useClass:l}]].forEach(e=>this._injector.add(e)),this._injector.get(x)}};k(A,`pluginName`,b),k(A,`packageName`,S),k(A,`version`,C),k(A,`type`,n.UniverInstanceType.UNIVER_SHEET),A=y([(0,n.DependentOn)(r.UniverDrawingPlugin),v(1,(0,n.Inject)(n.Injector)),v(2,n.IConfigService)],A),e.ClearSheetDrawingTransformerOperation=p,e.DrawingApplyType=d,e.ISheetDrawingService=u,e.InsertSheetDrawingCommand=m,e.RemoveSheetDrawingCommand=h,e.SHEET_DRAWING_PLUGIN=b,e.SetDrawingApplyMutation=f,e.SetDrawingArrangeCommand=g,e.SetSheetDrawingCommand=_,e.SheetDrawingAnchorType=c,Object.defineProperty(e,`UniverSheetsDrawingPlugin`,{enumerable:!0,get:function(){return A}}),e.drawingPositionToTransform=a,e.transformToAxisAlignPosition=s,e.transformToDrawingPosition=o});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,15 +53,15 @@
53
53
  "lib"
54
54
  ],
55
55
  "dependencies": {
56
- "@univerjs/core": "0.20.0",
57
- "@univerjs/drawing": "0.20.0",
58
- "@univerjs/sheets": "0.20.0",
59
- "@univerjs/engine-render": "0.20.0"
56
+ "@univerjs/drawing": "0.20.1",
57
+ "@univerjs/core": "0.20.1",
58
+ "@univerjs/engine-render": "0.20.1",
59
+ "@univerjs/sheets": "0.20.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "typescript": "^6.0.2",
63
63
  "vitest": "^4.1.1",
64
- "@univerjs-infra/shared": "0.20.0"
64
+ "@univerjs-infra/shared": "0.20.1"
65
65
  },
66
66
  "scripts": {
67
67
  "test": "vitest run",