@univerjs/sheets-drawing 0.20.1 → 0.21.0
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/facade.js +1185 -1
- package/lib/cjs/index.js +697 -1
- package/lib/es/facade.js +1186 -1
- package/lib/es/index.js +678 -1
- package/lib/facade.js +1186 -1
- package/lib/index.js +678 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/facade.js
CHANGED
|
@@ -1 +1,1186 @@
|
|
|
1
|
-
import{ArrangeTypeEnum as e,CanceledError as t,DrawingTypeEnum as n,ICommandService as r,ImageSourceType as i,Inject as a,Injector as o,generateRandomId as s}from"@univerjs/core";import{FBase as c,FEnum as l,FEventName as u,FUniver as d}from"@univerjs/core/facade";import{IDrawingManagerService as f,SetDrawingSelectedOperation as p,getImageSize as m}from"@univerjs/drawing";import{SheetSkeletonService as h,convertPositionCellToSheetOverGrid as g,convertPositionSheetOverGridToAbsolute as _}from"@univerjs/sheets";import{ISheetDrawingService as v,InsertSheetDrawingCommand as y,RemoveSheetDrawingCommand as b,SetDrawingArrangeCommand as x,SetSheetDrawingCommand as S,SheetDrawingAnchorType as C,transformToAxisAlignPosition as w}from"@univerjs/sheets-drawing";import{FWorksheet as T}from"@univerjs/sheets/facade";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}function A(e,t){return function(n,r){t(n,r,e)}}function j(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}function M(e,t){let{from:n,to:r,flipY:i=!1,flipX:a=!1,angle:o=0,skewX:s=0,skewY:c=0}=e.sheetTransform,{column:l,columnOffset:u,row:d,rowOffset:f}=n,{width:p,height:m}=_(e.unitId,e.subUnitId,{from:n,to:r},t);return{...e,column:l,columnOffset:u,row:d,rowOffset:f,width:p,height:m,flipY:i,flipX:a,angle:o,skewX:s,skewY:c}}function N(e,t){let n=t.ensureSkeleton(e.unitId,e.subUnitId);if(!n)throw Error(`Skeleton for unitId ${e.unitId} and subUnitId ${e.subUnitId} not found`);let{column:r,columnOffset:i,row:a,rowOffset:o,flipY:s=!1,flipX:c=!1,angle:l=0,skewX:u=0,skewY:d=0,width:f,height:p}=e,{sheetTransform:m,transform:h}=g(e.unitId,e.subUnitId,{column:r,columnOffset:i,row:a,rowOffset:o},f,p,n);return{...e,sheetTransform:{...m,flipY:s,flipX:c,angle:l,skewX:u,skewY:d},transform:{...h,flipY:s,flipX:c,angle:l,skewX:u,skewY:d},axisAlignSheetTransform:w(h,n)}}let P=class{constructor(e,t,r){this._injector=r,k(this,`_image`,void 0),this._image={drawingId:s(6),drawingType:n.DRAWING_IMAGE,imageSourceType:i.BASE64,source:``,unitId:e,subUnitId:t,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0,axisAlignSheetTransform:{from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}}}setImage(e){let{unitId:t,subUnitId:n}=e,r=this._injector.get(h).getSkeleton(t,n);if(!r)throw Error(`Skeleton for unitId ${t} and subUnitId ${n} not found`);return e.sheetTransform==null&&(e.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),e.axisAlignSheetTransform==null&&(e.axisAlignSheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=M(e,r),this}setSource(e,t){let n=t==null?i.URL:t;return this._image.source=e,this._image.imageSourceType=n,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(e){return this._image.column=e,this}setRow(e){return this._image.row=e,this}setColumnOffset(e){return this._image.columnOffset=e,this}setRowOffset(e){return this._image.rowOffset=e,this}setWidth(e){return this._image.width=e,this}setHeight(e){return this._image.height=e,this}setAnchorType(e){return this._image.anchorType=e,this}setCropTop(e){return this._initializeSrcRect(),this._image.srcRect.top=e,this}setCropLeft(e){return this._initializeSrcRect(),this._image.srcRect.left=e,this}setCropBottom(e){return this._initializeSrcRect(),this._image.srcRect.bottom=e,this}setCropRight(e){return this._initializeSrcRect(),this._image.srcRect.right=e,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(e){return this._image.angle=e,this}setUnitId(e){return this._image.unitId=e,this}setSubUnitId(e){return this._image.subUnitId=e,this}async buildAsync(){let e=this._injector.get(h);if(this._image.width===0||this._image.height===0){let e=await m(this._image.source),t=e.width,n=e.height;this._image.width===0&&(this._image.width=t),this._image.height===0&&(this._image.height=n)}return N(this._image,e)}};P=j([A(2,a(o))],P);let F=class extends c{constructor(e,t,n){super(),this._image=e,this._commandService=t,this._injector=n}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(b.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){let e=this._injector.createInstance(P);return e.setImage(this._image),e}setSource(e,t){let n=t==null?i.URL:t;return this._image.source=e,this._image.imageSourceType=n,this._commandService.syncExecuteCommand(S.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(e,t,n,r){let i=this.toBuilder();i.setColumn(t),i.setRow(e),n!=null&&i.setRowOffset(n),r!=null&&i.setColumnOffset(r);let a=await i.buildAsync();return this._commandService.syncExecuteCommand(S.id,{unitId:this._image.unitId,drawings:[a]})}async setSizeAsync(e,t){let n=this.toBuilder();n.setWidth(e),n.setHeight(t);let r=await n.buildAsync();return this._commandService.syncExecuteCommand(S.id,{unitId:this._image.unitId,drawings:[r]})}setCrop(e,t,n,r){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),e!=null&&(this._image.srcRect.top=e),t!=null&&(this._image.srcRect.left=t),n!=null&&(this._image.srcRect.bottom=n),r!=null&&(this._image.srcRect.right=r),this._commandService.syncExecuteCommand(S.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(e){if(this._image.sheetTransform.angle=e,this._image.transform&&(this._image.transform.angle=e),this._image.transform){let e=this._injector.get(h).getSkeleton(this._image.unitId,this._image.subUnitId);if(!e)throw Error(`Skeleton for unitId ${this._image.unitId} and subUnitId ${this._image.subUnitId} not found`);this._image.axisAlignSheetTransform&&(this._image.axisAlignSheetTransform=w(this._image.transform,e))}return this._commandService.syncExecuteCommand(S.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(x.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.forward})}setBackward(){return this._commandService.syncExecuteCommand(x.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.backward})}setBack(){return this._commandService.syncExecuteCommand(x.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.back})}setFront(){return this._commandService.syncExecuteCommand(x.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.front})}};F=j([A(1,r),A(2,a(o))],F);var I=class extends T{async insertImage(e,t,n,r,a){let o=this.newOverGridImage();if(typeof e==`string`)o.setSource(e);else{let t=await e.getBlob().getDataAsString();o.setSource(t,i.BASE64)}t===void 0?o.setColumn(0):o.setColumn(t),n===void 0?o.setRow(0):o.setRow(n),r===void 0?o.setColumnOffset(0):o.setColumnOffset(r),a===void 0?o.setRowOffset(0):o.setRowOffset(a);let s=await o.buildAsync();return this._commandService.syncExecuteCommand(y.id,{unitId:this._fWorkbook.getId(),drawings:[s]})}insertImages(e){let t=e.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(y.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(e){let t=e.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(b.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){let e=this._injector.get(v).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),t=[];for(let r in e){let i=e[r];i.drawingType===n.DRAWING_IMAGE&&t.push(this._injector.createInstance(F,i))}return t}getImageById(e){let t=this._injector.get(v).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:e});return t&&t.drawingType===n.DRAWING_IMAGE?this._injector.createInstance(F,t):null}getActiveImages(){let e=this._injector.get(v).getFocusDrawings(),t=[];for(let n in e){let r=e[n];t.push(this._injector.createInstance(F,r))}return t}updateImages(e){return this._commandService.syncExecuteCommand(S.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}newOverGridImage(){let e=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(P,e,t)}};T.extend(I);var L=class extends l{get DrawingType(){return n}get ImageSourceType(){return i}get SheetDrawingAnchorType(){return C}};l.extend(L);var R=class extends u{get BeforeFloatDomAdd(){return`BeforeFloatDomAdd`}get FloatDomAdded(){return`FloatDomAdded`}get BeforeFloatDomUpdate(){return`BeforeFloatDomUpdate`}get FloatDomUpdated(){return`FloatDomUpdated`}get BeforeFloatDomDelete(){return`BeforeFloatDomDelete`}get FloatDomDeleted(){return`FloatDomDeleted`}get BeforeOverGridImageChange(){return`BeforeOverGridImageChange`}get OverGridImageChanged(){return`OverGridImageChanged`}get BeforeOverGridImageInsert(){return`BeforeOverGridImageInsert`}get OverGridImageInserted(){return`OverGridImageInserted`}get BeforeOverGridImageRemove(){return`BeforeOverGridImageRemove`}get OverGridImageRemoved(){return`OverGridImageRemoved`}get BeforeOverGridImageSelect(){return`BeforeOverGridImageSelect`}get OverGridImageSelected(){return`OverGridImageSelected`}};u.extend(R);var z=class extends d{_initialize(e){let n=e.get(r);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>n.beforeCommandExecuted(e=>{if(e.id!==y.id)return;let n=e.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:i}=n,a={workbook:r,insertImageParams:i};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,a),a.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>n.beforeCommandExecuted(n=>{if(n.id!==b.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let a=e.get(f),{drawings:o}=r,s=o.map(e=>a.getDrawingByParam(e)),c={workbook:i,images:this._createFOverGridImage(s)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,c),c.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>n.beforeCommandExecuted(n=>{if(n.id!==S.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let{drawings:a}=r,o=e.get(f),s=[];a.forEach(e=>{let t=o.getDrawingByParam(e);t!=null&&s.push({changeParam:e,image:this._injector.createInstance(F,t)})});let c={workbook:i,images:s};if(this.fireEvent(this.Event.BeforeOverGridImageChange,c),c.cancel)throw o.updateNotification(a),new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>n.beforeCommandExecuted(n=>{if(n.id!==p.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null)return;let a=e.get(f),o=a.getFocusDrawings(),s=r.map(e=>a.getDrawingByParam(e)),c={workbook:i,selectedImages:this._createFOverGridImage(s),oldSelectedImages:this._createFOverGridImage(o)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,c),c.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>n.onCommandExecuted(e=>{if(e.id!==y.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,i={workbook:n,images:this._createFOverGridImage(r)};this.fireEvent(this.Event.OverGridImageInserted,i)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>n.onCommandExecuted(e=>{if(e.id!==b.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,i={workbook:n,removeImageParams:r};this.fireEvent(this.Event.OverGridImageRemoved,i)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>n.onCommandExecuted(t=>{if(t.id!==S.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:i}=n,a=e.get(f),o={workbook:r,images:i.map(e=>this._injector.createInstance(F,a.getDrawingByParam(e)))};this.fireEvent(this.Event.OverGridImageChanged,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>n.onCommandExecuted(t=>{if(t.id!==p.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null)return;let i=e.get(f),a=n.map(e=>i.getDrawingByParam(e)),o={workbook:r,selectedImages:this._createFOverGridImage(a)};this.fireEvent(this.Event.OverGridImageSelected,o)})))}_createFOverGridImage(e){return e.map(e=>this._injector.createInstance(F,e))}};d.extend(z);export{};
|
|
1
|
+
import { ArrangeTypeEnum, CanceledError, DrawingTypeEnum, ICommandService, ImageSourceType, Inject, Injector, generateRandomId } from "@univerjs/core";
|
|
2
|
+
import { FBase, FEnum, FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
|
+
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize } from "@univerjs/drawing";
|
|
4
|
+
import { SheetSkeletonService, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
5
|
+
import { ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, transformToAxisAlignPosition } from "@univerjs/sheets-drawing";
|
|
6
|
+
import { FWorksheet } from "@univerjs/sheets/facade";
|
|
7
|
+
|
|
8
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
9
|
+
function _typeof(o) {
|
|
10
|
+
"@babel/helpers - typeof";
|
|
11
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
12
|
+
return typeof o;
|
|
13
|
+
} : function(o) {
|
|
14
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
15
|
+
}, _typeof(o);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
20
|
+
function toPrimitive(t, r) {
|
|
21
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
22
|
+
var e = t[Symbol.toPrimitive];
|
|
23
|
+
if (void 0 !== e) {
|
|
24
|
+
var i = e.call(t, r || "default");
|
|
25
|
+
if ("object" != _typeof(i)) return i;
|
|
26
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
27
|
+
}
|
|
28
|
+
return ("string" === r ? String : Number)(t);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
33
|
+
function toPropertyKey(t) {
|
|
34
|
+
var i = toPrimitive(t, "string");
|
|
35
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
40
|
+
function _defineProperty(e, r, t) {
|
|
41
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
42
|
+
value: t,
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0
|
|
46
|
+
}) : e[r] = t, e;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
51
|
+
function __decorateParam(paramIndex, decorator) {
|
|
52
|
+
return function(target, key) {
|
|
53
|
+
decorator(target, key, paramIndex);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
59
|
+
function __decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
62
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/facade/f-over-grid-image.ts
|
|
68
|
+
/**
|
|
69
|
+
* Convert the image parameter to a FOverGridImage
|
|
70
|
+
* @param {ISheetImage} sheetImage The image parameter
|
|
71
|
+
* @param {SpreadsheetSkeleton} skeleton The skeleton of the sheet where the image is located
|
|
72
|
+
* @returns {IFOverGridImage} The FOverGridImage {@link IFOverGridImage}
|
|
73
|
+
*/
|
|
74
|
+
function convertSheetImageToFOverGridImage(sheetImage, skeleton) {
|
|
75
|
+
const { from, to, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = sheetImage.sheetTransform;
|
|
76
|
+
const { column: fromColumn, columnOffset: fromColumnOffset, row: fromRow, rowOffset: fromRowOffset } = from;
|
|
77
|
+
const { width, height } = convertPositionSheetOverGridToAbsolute(sheetImage.unitId, sheetImage.subUnitId, {
|
|
78
|
+
from,
|
|
79
|
+
to
|
|
80
|
+
}, skeleton);
|
|
81
|
+
return {
|
|
82
|
+
...sheetImage,
|
|
83
|
+
column: fromColumn,
|
|
84
|
+
columnOffset: fromColumnOffset,
|
|
85
|
+
row: fromRow,
|
|
86
|
+
rowOffset: fromRowOffset,
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
flipY,
|
|
90
|
+
flipX,
|
|
91
|
+
angle,
|
|
92
|
+
skewX,
|
|
93
|
+
skewY
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Convert the FOverGridImage to a ISheetImage
|
|
98
|
+
* @param {IFOverGridImage} fOverGridImage The FOverGridImage
|
|
99
|
+
* @param {ISheetSelectionRenderService} selectionRenderService The selection render service
|
|
100
|
+
* @param {SheetSkeletonManagerService} sheetSkeletonManagerService The skeleton manager service
|
|
101
|
+
* @returns {ISheetImage} The ISheetImage {@link ISheetImage}
|
|
102
|
+
*/
|
|
103
|
+
function convertFOverGridImageToSheetImage(fOverGridImage, sheetSkeletonService) {
|
|
104
|
+
const skeleton = sheetSkeletonService.ensureSkeleton(fOverGridImage.unitId, fOverGridImage.subUnitId);
|
|
105
|
+
if (!skeleton) throw new Error(`Skeleton for unitId ${fOverGridImage.unitId} and subUnitId ${fOverGridImage.subUnitId} not found`);
|
|
106
|
+
const { column: fromColumn, columnOffset: fromColumnOffset, row: fromRow, rowOffset: fromRowOffset, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0, width, height } = fOverGridImage;
|
|
107
|
+
const { sheetTransform, transform } = convertPositionCellToSheetOverGrid(fOverGridImage.unitId, fOverGridImage.subUnitId, {
|
|
108
|
+
column: fromColumn,
|
|
109
|
+
columnOffset: fromColumnOffset,
|
|
110
|
+
row: fromRow,
|
|
111
|
+
rowOffset: fromRowOffset
|
|
112
|
+
}, width, height, skeleton);
|
|
113
|
+
return {
|
|
114
|
+
...fOverGridImage,
|
|
115
|
+
sheetTransform: {
|
|
116
|
+
...sheetTransform,
|
|
117
|
+
flipY,
|
|
118
|
+
flipX,
|
|
119
|
+
angle,
|
|
120
|
+
skewX,
|
|
121
|
+
skewY
|
|
122
|
+
},
|
|
123
|
+
transform: {
|
|
124
|
+
...transform,
|
|
125
|
+
flipY,
|
|
126
|
+
flipX,
|
|
127
|
+
angle,
|
|
128
|
+
skewX,
|
|
129
|
+
skewY
|
|
130
|
+
},
|
|
131
|
+
axisAlignSheetTransform: transformToAxisAlignPosition(transform, skeleton)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
135
|
+
constructor(unitId, subUnitId, _injector) {
|
|
136
|
+
this._injector = _injector;
|
|
137
|
+
_defineProperty(this, "_image", void 0);
|
|
138
|
+
this._image = {
|
|
139
|
+
drawingId: generateRandomId(6),
|
|
140
|
+
drawingType: DrawingTypeEnum.DRAWING_IMAGE,
|
|
141
|
+
imageSourceType: ImageSourceType.BASE64,
|
|
142
|
+
source: "",
|
|
143
|
+
unitId,
|
|
144
|
+
subUnitId,
|
|
145
|
+
column: 0,
|
|
146
|
+
columnOffset: 0,
|
|
147
|
+
row: 0,
|
|
148
|
+
rowOffset: 0,
|
|
149
|
+
width: 0,
|
|
150
|
+
height: 0,
|
|
151
|
+
axisAlignSheetTransform: {
|
|
152
|
+
from: {
|
|
153
|
+
column: 0,
|
|
154
|
+
columnOffset: 0,
|
|
155
|
+
row: 0,
|
|
156
|
+
rowOffset: 0
|
|
157
|
+
},
|
|
158
|
+
to: {
|
|
159
|
+
column: 0,
|
|
160
|
+
columnOffset: 0,
|
|
161
|
+
row: 0,
|
|
162
|
+
rowOffset: 0
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Set the initial image configuration for the image builder.
|
|
169
|
+
* @param {ISheetImage} image - The image configuration
|
|
170
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* // create a new image builder and set initial image configuration.
|
|
174
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
175
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
176
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
177
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
178
|
+
* .setImage({
|
|
179
|
+
* drawingId: '123456',
|
|
180
|
+
* drawingType: univerAPI.Enum.DrawingType.DRAWING_IMAGE,
|
|
181
|
+
* imageSourceType: univerAPI.Enum.ImageSourceType.BASE64,
|
|
182
|
+
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
183
|
+
* unitId: fWorkbook.getId(),
|
|
184
|
+
* subUnitId: fWorksheet.getSheetId(),
|
|
185
|
+
* })
|
|
186
|
+
* .setColumn(5)
|
|
187
|
+
* .setRow(5)
|
|
188
|
+
* .buildAsync();
|
|
189
|
+
* fWorksheet.insertImages([image]);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
setImage(image) {
|
|
193
|
+
const { unitId, subUnitId } = image;
|
|
194
|
+
const skeleton = this._injector.get(SheetSkeletonService).getSkeleton(unitId, subUnitId);
|
|
195
|
+
if (!skeleton) throw new Error(`Skeleton for unitId ${unitId} and subUnitId ${subUnitId} not found`);
|
|
196
|
+
if (image.sheetTransform == null) image.sheetTransform = {
|
|
197
|
+
from: {
|
|
198
|
+
column: 0,
|
|
199
|
+
columnOffset: 0,
|
|
200
|
+
row: 0,
|
|
201
|
+
rowOffset: 0
|
|
202
|
+
},
|
|
203
|
+
to: {
|
|
204
|
+
column: 0,
|
|
205
|
+
columnOffset: 0,
|
|
206
|
+
row: 0,
|
|
207
|
+
rowOffset: 0
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
if (image.axisAlignSheetTransform == null) image.axisAlignSheetTransform = {
|
|
211
|
+
from: {
|
|
212
|
+
column: 0,
|
|
213
|
+
columnOffset: 0,
|
|
214
|
+
row: 0,
|
|
215
|
+
rowOffset: 0
|
|
216
|
+
},
|
|
217
|
+
to: {
|
|
218
|
+
column: 0,
|
|
219
|
+
columnOffset: 0,
|
|
220
|
+
row: 0,
|
|
221
|
+
rowOffset: 0
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
this._image = convertSheetImageToFOverGridImage(image, skeleton);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
setSource(source, sourceType) {
|
|
228
|
+
const sourceTypeVal = sourceType !== null && sourceType !== void 0 ? sourceType : ImageSourceType.URL;
|
|
229
|
+
this._image.source = source;
|
|
230
|
+
this._image.imageSourceType = sourceTypeVal;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Get the source of the image
|
|
235
|
+
* @returns {string} The source of the image
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
239
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
240
|
+
* const images = fWorksheet.getImages();
|
|
241
|
+
* images.forEach((image) => {
|
|
242
|
+
* console.log(image, image.toBuilder().getSource());
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
getSource() {
|
|
247
|
+
return this._image.source;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get the source type of the image
|
|
251
|
+
* @returns {ImageSourceType} The source type of the image
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
255
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
256
|
+
* const images = fWorksheet.getImages();
|
|
257
|
+
* images.forEach((image) => {
|
|
258
|
+
* console.log(image, image.toBuilder().getSourceType());
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
getSourceType() {
|
|
263
|
+
return this._image.imageSourceType;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Set the horizontal position of the image
|
|
267
|
+
* @param {number} column - The column index of the image start position, start at 0
|
|
268
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* // create a new image builder and set image source.
|
|
272
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
273
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
274
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
275
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
276
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
277
|
+
* .setColumn(5)
|
|
278
|
+
* .setRow(5)
|
|
279
|
+
* .buildAsync();
|
|
280
|
+
* fWorksheet.insertImages([image]);
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
setColumn(column) {
|
|
284
|
+
this._image.column = column;
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Set the vertical position of the image
|
|
289
|
+
* @param {number} row - The row index of the image start position, start at 0
|
|
290
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* // create a new image builder and set image source.
|
|
294
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
295
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
296
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
297
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
298
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
299
|
+
* .setColumn(5)
|
|
300
|
+
* .setRow(5)
|
|
301
|
+
* .buildAsync();
|
|
302
|
+
* fWorksheet.insertImages([image]);
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
setRow(row) {
|
|
306
|
+
this._image.row = row;
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Set the horizontal offset of the image
|
|
311
|
+
* @param {number} offset - The column offset of the image start position, pixel unit
|
|
312
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* // create a new image builder and set image source.
|
|
316
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and horizontal offset is 10px.
|
|
317
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
318
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
319
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
320
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
321
|
+
* .setColumn(5)
|
|
322
|
+
* .setRow(5)
|
|
323
|
+
* .setColumnOffset(10)
|
|
324
|
+
* .buildAsync();
|
|
325
|
+
* fWorksheet.insertImages([image]);
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
setColumnOffset(offset) {
|
|
329
|
+
this._image.columnOffset = offset;
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Set the vertical offset of the image
|
|
334
|
+
* @param {number} offset - The row offset of the image start position, pixel unit
|
|
335
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* // create a new image builder and set image source.
|
|
339
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and vertical offset is 10px.
|
|
340
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
341
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
342
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
343
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
344
|
+
* .setColumn(5)
|
|
345
|
+
* .setRow(5)
|
|
346
|
+
* .setRowOffset(10)
|
|
347
|
+
* .buildAsync();
|
|
348
|
+
* fWorksheet.insertImages([image]);
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
setRowOffset(offset) {
|
|
352
|
+
this._image.rowOffset = offset;
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Set the width of the image
|
|
357
|
+
* @param {number} width - The width of the image, pixel unit
|
|
358
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
359
|
+
* @example
|
|
360
|
+
* ```ts
|
|
361
|
+
* // create a new image builder and set image source.
|
|
362
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
|
|
363
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
364
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
365
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
366
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
367
|
+
* .setColumn(5)
|
|
368
|
+
* .setRow(5)
|
|
369
|
+
* .setWidth(120)
|
|
370
|
+
* .setHeight(50)
|
|
371
|
+
* .buildAsync();
|
|
372
|
+
* fWorksheet.insertImages([image]);
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
setWidth(width) {
|
|
376
|
+
this._image.width = width;
|
|
377
|
+
return this;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Set the height of the image
|
|
381
|
+
* @param {number} height - The height of the image, pixel unit
|
|
382
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* // create a new image builder and set image source.
|
|
386
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
|
|
387
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
388
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
389
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
390
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
391
|
+
* .setColumn(5)
|
|
392
|
+
* .setRow(5)
|
|
393
|
+
* .setWidth(120)
|
|
394
|
+
* .setHeight(50)
|
|
395
|
+
* .buildAsync();
|
|
396
|
+
* fWorksheet.insertImages([image]);
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
setHeight(height) {
|
|
400
|
+
this._image.height = height;
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Set the anchor type of the image, whether the position and size change with the cell
|
|
405
|
+
* @param {SheetDrawingAnchorType} anchorType - The anchor type of the image
|
|
406
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
410
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
411
|
+
*
|
|
412
|
+
* // image1 position is start from A6 cell, anchor type is Position.
|
|
413
|
+
* // Only the position of the drawing follows the cell changes. When rows or columns are inserted or deleted, the position of the drawing changes, but the size remains the same.
|
|
414
|
+
* const image1 = await fWorksheet.newOverGridImage()
|
|
415
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
416
|
+
* .setColumn(0)
|
|
417
|
+
* .setRow(5)
|
|
418
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Position)
|
|
419
|
+
* .buildAsync();
|
|
420
|
+
*
|
|
421
|
+
* // image2 position is start from C6 cell, anchor type is Both.
|
|
422
|
+
* // The size and position of the drawing follow the cell changes. When rows or columns are inserted or deleted, the size and position of the drawing change accordingly.
|
|
423
|
+
* const image2 = await fWorksheet.newOverGridImage()
|
|
424
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
425
|
+
* .setColumn(2)
|
|
426
|
+
* .setRow(5)
|
|
427
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Both)
|
|
428
|
+
* .buildAsync();
|
|
429
|
+
*
|
|
430
|
+
* // image3 position is start from E6 cell, anchor type is None.
|
|
431
|
+
* // The size and position of the drawing do not follow the cell changes. When rows or columns are inserted or deleted, the position and size of the drawing remain unchanged.
|
|
432
|
+
* const image3 = await fWorksheet.newOverGridImage()
|
|
433
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
434
|
+
* .setColumn(4)
|
|
435
|
+
* .setRow(5)
|
|
436
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.None)
|
|
437
|
+
* .buildAsync();
|
|
438
|
+
*
|
|
439
|
+
* // insert images into the sheet
|
|
440
|
+
* fWorksheet.insertImages([image1, image2, image3]);
|
|
441
|
+
*
|
|
442
|
+
* // after 2 seconds, set the row height of the 5th row to 100px and insert a row before the 5th row.
|
|
443
|
+
* // then observe the position and size changes of the images.
|
|
444
|
+
* setTimeout(() => {
|
|
445
|
+
* fWorksheet.setRowHeight(5, 100).insertRowBefore(5);
|
|
446
|
+
* }, 2000);
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
setAnchorType(anchorType) {
|
|
450
|
+
this._image.anchorType = anchorType;
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
|
|
455
|
+
* @param {number} top - The number of pixels to crop from the top of the image
|
|
456
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* // create a new image builder and set image source.
|
|
460
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, top crop is 10px.
|
|
461
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
462
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
463
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
464
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
465
|
+
* .setColumn(5)
|
|
466
|
+
* .setRow(5)
|
|
467
|
+
* .setCropTop(10)
|
|
468
|
+
* .buildAsync();
|
|
469
|
+
* fWorksheet.insertImages([image]);
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
setCropTop(top) {
|
|
473
|
+
this._initializeSrcRect();
|
|
474
|
+
this._image.srcRect.top = top;
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
|
|
479
|
+
* @param {number} left - The number of pixels to crop from the left side of the image
|
|
480
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* // create a new image builder and set image source.
|
|
484
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, left crop is 10px.
|
|
485
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
486
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
487
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
488
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
489
|
+
* .setColumn(5)
|
|
490
|
+
* .setRow(5)
|
|
491
|
+
* .setCropLeft(10)
|
|
492
|
+
* .buildAsync();
|
|
493
|
+
* fWorksheet.insertImages([image]);
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
setCropLeft(left) {
|
|
497
|
+
this._initializeSrcRect();
|
|
498
|
+
this._image.srcRect.left = left;
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
|
|
503
|
+
* @param {number} bottom - The number of pixels to crop from the bottom of the image
|
|
504
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* // create a new image builder and set image source.
|
|
508
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, bottom crop is 10px.
|
|
509
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
510
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
511
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
512
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
513
|
+
* .setColumn(5)
|
|
514
|
+
* .setRow(5)
|
|
515
|
+
* .setCropBottom(10)
|
|
516
|
+
* .buildAsync();
|
|
517
|
+
* fWorksheet.insertImages([image]);
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
setCropBottom(bottom) {
|
|
521
|
+
this._initializeSrcRect();
|
|
522
|
+
this._image.srcRect.bottom = bottom;
|
|
523
|
+
return this;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
|
|
527
|
+
* @param {number} right - The number of pixels to crop from the right side of the image
|
|
528
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
529
|
+
* @example
|
|
530
|
+
* ```ts
|
|
531
|
+
* // create a new image builder and set image source.
|
|
532
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, right crop is 10px.
|
|
533
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
534
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
535
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
536
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
537
|
+
* .setColumn(5)
|
|
538
|
+
* .setRow(5)
|
|
539
|
+
* .setCropRight(10)
|
|
540
|
+
* .buildAsync();
|
|
541
|
+
* fWorksheet.insertImages([image]);
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
setCropRight(right) {
|
|
545
|
+
this._initializeSrcRect();
|
|
546
|
+
this._image.srcRect.right = right;
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
_initializeSrcRect() {
|
|
550
|
+
if (this._image.srcRect == null) this._image.srcRect = {
|
|
551
|
+
top: 0,
|
|
552
|
+
left: 0,
|
|
553
|
+
bottom: 0,
|
|
554
|
+
right: 0
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Set the rotation angle of the image
|
|
559
|
+
* @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
560
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
561
|
+
* @example
|
|
562
|
+
* ```ts
|
|
563
|
+
* // create a new image builder and set image source.
|
|
564
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, rotate 90 degrees.
|
|
565
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
566
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
567
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
568
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
569
|
+
* .setColumn(5)
|
|
570
|
+
* .setRow(5)
|
|
571
|
+
* .setRotate(90)
|
|
572
|
+
* .buildAsync();
|
|
573
|
+
* fWorksheet.insertImages([image]);
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
setRotate(angle) {
|
|
577
|
+
this._image.angle = angle;
|
|
578
|
+
return this;
|
|
579
|
+
}
|
|
580
|
+
setUnitId(unitId) {
|
|
581
|
+
this._image.unitId = unitId;
|
|
582
|
+
return this;
|
|
583
|
+
}
|
|
584
|
+
setSubUnitId(subUnitId) {
|
|
585
|
+
this._image.subUnitId = subUnitId;
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
async buildAsync() {
|
|
589
|
+
const sheetSkeletonService = this._injector.get(SheetSkeletonService);
|
|
590
|
+
if (this._image.width === 0 || this._image.height === 0) {
|
|
591
|
+
const size = await getImageSize(this._image.source);
|
|
592
|
+
const width = size.width;
|
|
593
|
+
const height = size.height;
|
|
594
|
+
if (this._image.width === 0) this._image.width = width;
|
|
595
|
+
if (this._image.height === 0) this._image.height = height;
|
|
596
|
+
}
|
|
597
|
+
return convertFOverGridImageToSheetImage(this._image, sheetSkeletonService);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
FOverGridImageBuilder = __decorate([__decorateParam(2, Inject(Injector))], FOverGridImageBuilder);
|
|
601
|
+
let FOverGridImage = class FOverGridImage extends FBase {
|
|
602
|
+
constructor(_image, _commandService, _injector) {
|
|
603
|
+
super();
|
|
604
|
+
this._image = _image;
|
|
605
|
+
this._commandService = _commandService;
|
|
606
|
+
this._injector = _injector;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Get the id of the image
|
|
610
|
+
* @returns {string} The id of the image
|
|
611
|
+
* @example
|
|
612
|
+
* ```ts
|
|
613
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
614
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
615
|
+
* const images = fWorksheet.getImages();
|
|
616
|
+
* images.forEach((image) => {
|
|
617
|
+
* console.log(image, image.getId());
|
|
618
|
+
* });
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
getId() {
|
|
622
|
+
return this._image.drawingId;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Get the drawing type of the image
|
|
626
|
+
* @returns {DrawingTypeEnum} The drawing type of the image
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
630
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
631
|
+
* const images = fWorksheet.getImages();
|
|
632
|
+
* images.forEach((image) => {
|
|
633
|
+
* console.log(image, image.getType());
|
|
634
|
+
* });
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
getType() {
|
|
638
|
+
return this._image.drawingType;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Remove the image from the sheet
|
|
642
|
+
* @returns {boolean} true if the image is removed successfully, otherwise false
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
646
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
647
|
+
* const image = fWorksheet.getImages()[0];
|
|
648
|
+
* const result = image?.remove();
|
|
649
|
+
* console.log(result);
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
remove() {
|
|
653
|
+
return this._commandService.syncExecuteCommand(RemoveSheetDrawingCommand.id, {
|
|
654
|
+
unitId: this._image.unitId,
|
|
655
|
+
drawings: [this._image]
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Convert the image to a FOverGridImageBuilder
|
|
660
|
+
* @returns {FOverGridImageBuilder} The builder FOverGridImageBuilder
|
|
661
|
+
* @example
|
|
662
|
+
* ```ts
|
|
663
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
664
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
665
|
+
* const images = fWorksheet.getImages();
|
|
666
|
+
* images.forEach((image) => {
|
|
667
|
+
* console.log(image, image.toBuilder().getSource());
|
|
668
|
+
* });
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
toBuilder() {
|
|
672
|
+
const builder = this._injector.createInstance(FOverGridImageBuilder);
|
|
673
|
+
builder.setImage(this._image);
|
|
674
|
+
return builder;
|
|
675
|
+
}
|
|
676
|
+
setSource(source, sourceType) {
|
|
677
|
+
const sourceTypeVal = sourceType !== null && sourceType !== void 0 ? sourceType : ImageSourceType.URL;
|
|
678
|
+
this._image.source = source;
|
|
679
|
+
this._image.imageSourceType = sourceTypeVal;
|
|
680
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
681
|
+
unitId: this._image.unitId,
|
|
682
|
+
drawings: [this._image]
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
async setPositionAsync(row, column, rowOffset, columnOffset) {
|
|
686
|
+
const builder = this.toBuilder();
|
|
687
|
+
builder.setColumn(column);
|
|
688
|
+
builder.setRow(row);
|
|
689
|
+
if (rowOffset != null) builder.setRowOffset(rowOffset);
|
|
690
|
+
if (columnOffset != null) builder.setColumnOffset(columnOffset);
|
|
691
|
+
const param = await builder.buildAsync();
|
|
692
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
693
|
+
unitId: this._image.unitId,
|
|
694
|
+
drawings: [param]
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Set the size of the image
|
|
699
|
+
* @param {number} width - The width of the image, pixel unit
|
|
700
|
+
* @param {number} height - The height of the image, pixel unit
|
|
701
|
+
* @returns {boolean} true if the size is set successfully, otherwise false
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* // set the image width 120px and height 50px
|
|
705
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
706
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
707
|
+
* const image = fWorksheet.getImages()[0];
|
|
708
|
+
* const result = image?.setSizeAsync(120, 50);
|
|
709
|
+
* console.log(result);
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
async setSizeAsync(width, height) {
|
|
713
|
+
const builder = this.toBuilder();
|
|
714
|
+
builder.setWidth(width);
|
|
715
|
+
builder.setHeight(height);
|
|
716
|
+
const param = await builder.buildAsync();
|
|
717
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
718
|
+
unitId: this._image.unitId,
|
|
719
|
+
drawings: [param]
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Set the cropping region of the image by defining the top, bottom, left, and right edges, thereby displaying the specific part of the image you want.
|
|
724
|
+
* @param {number} top - The number of pixels to crop from the top of the image
|
|
725
|
+
* @param {number} left - The number of pixels to crop from the left side of the image
|
|
726
|
+
* @param {number} bottom - The number of pixels to crop from the bottom of the image
|
|
727
|
+
* @param {number} right - The number of pixels to crop from the right side of the image
|
|
728
|
+
* @returns {boolean} true if the crop is set successfully, otherwise false
|
|
729
|
+
* @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* // set the crop of the image, top 10px, left 10px, bottom 10px, right 10px.
|
|
732
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
733
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
734
|
+
* const image = fWorksheet.getImages()[0];
|
|
735
|
+
* const result = image?.setCrop(10, 10, 10, 10);
|
|
736
|
+
* console.log(result);
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
setCrop(top, left, bottom, right) {
|
|
740
|
+
if (this._image.srcRect == null) this._image.srcRect = {
|
|
741
|
+
top: 0,
|
|
742
|
+
left: 0,
|
|
743
|
+
bottom: 0,
|
|
744
|
+
right: 0
|
|
745
|
+
};
|
|
746
|
+
if (top != null) this._image.srcRect.top = top;
|
|
747
|
+
if (left != null) this._image.srcRect.left = left;
|
|
748
|
+
if (bottom != null) this._image.srcRect.bottom = bottom;
|
|
749
|
+
if (right != null) this._image.srcRect.right = right;
|
|
750
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
751
|
+
unitId: this._image.unitId,
|
|
752
|
+
drawings: [this._image]
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Set the rotation angle of the image
|
|
757
|
+
* @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
758
|
+
* @returns {boolean} true if the rotation is set successfully, otherwise false
|
|
759
|
+
* @example
|
|
760
|
+
* ```ts
|
|
761
|
+
* // set 90 degrees rotation of the image
|
|
762
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
763
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
764
|
+
* const image = fWorksheet.getImages()[0];
|
|
765
|
+
* const result = image?.setRotate(90);
|
|
766
|
+
* console.log(result);
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
setRotate(angle) {
|
|
770
|
+
this._image.sheetTransform.angle = angle;
|
|
771
|
+
this._image.transform && (this._image.transform.angle = angle);
|
|
772
|
+
if (this._image.transform) {
|
|
773
|
+
const skeleton = this._injector.get(SheetSkeletonService).getSkeleton(this._image.unitId, this._image.subUnitId);
|
|
774
|
+
if (!skeleton) throw new Error(`Skeleton for unitId ${this._image.unitId} and subUnitId ${this._image.subUnitId} not found`);
|
|
775
|
+
this._image.axisAlignSheetTransform && (this._image.axisAlignSheetTransform = transformToAxisAlignPosition(this._image.transform, skeleton));
|
|
776
|
+
}
|
|
777
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
778
|
+
unitId: this._image.unitId,
|
|
779
|
+
drawings: [this._image]
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Move the image layer forward by one level
|
|
784
|
+
* @returns {boolean} true if the image is moved forward successfully, otherwise false
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
788
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
789
|
+
* const image = fWorksheet.getImages()[0];
|
|
790
|
+
* const result = image?.setForward();
|
|
791
|
+
* console.log(result);
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
setForward() {
|
|
795
|
+
return this._commandService.syncExecuteCommand(SetDrawingArrangeCommand.id, {
|
|
796
|
+
unitId: this._image.unitId,
|
|
797
|
+
subUnitId: this._image.subUnitId,
|
|
798
|
+
drawingIds: [this._image.drawingId],
|
|
799
|
+
arrangeType: ArrangeTypeEnum.forward
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Move the image layer backward by one level
|
|
804
|
+
* @returns {boolean} true if the image is moved backward successfully, otherwise false
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
808
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
809
|
+
* const image = fWorksheet.getImages()[0];
|
|
810
|
+
* const result = image?.setBackward();
|
|
811
|
+
* console.log(result);
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
setBackward() {
|
|
815
|
+
return this._commandService.syncExecuteCommand(SetDrawingArrangeCommand.id, {
|
|
816
|
+
unitId: this._image.unitId,
|
|
817
|
+
subUnitId: this._image.subUnitId,
|
|
818
|
+
drawingIds: [this._image.drawingId],
|
|
819
|
+
arrangeType: ArrangeTypeEnum.backward
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Move the image layer to the bottom layer
|
|
824
|
+
* @returns {boolean} true if the image is moved to the bottom layer successfully, otherwise false
|
|
825
|
+
* @example
|
|
826
|
+
* ```ts
|
|
827
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
828
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
829
|
+
* const image = fWorksheet.getImages()[0];
|
|
830
|
+
* const result = image?.setBack();
|
|
831
|
+
* console.log(result);
|
|
832
|
+
* ```
|
|
833
|
+
*/
|
|
834
|
+
setBack() {
|
|
835
|
+
return this._commandService.syncExecuteCommand(SetDrawingArrangeCommand.id, {
|
|
836
|
+
unitId: this._image.unitId,
|
|
837
|
+
subUnitId: this._image.subUnitId,
|
|
838
|
+
drawingIds: [this._image.drawingId],
|
|
839
|
+
arrangeType: ArrangeTypeEnum.back
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Move the image layer to the top layer
|
|
844
|
+
* @returns {boolean} true if the image is moved to the top layer successfully, otherwise false
|
|
845
|
+
* @example
|
|
846
|
+
* ```ts
|
|
847
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
848
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
849
|
+
* const image = fWorksheet.getImages()[0];
|
|
850
|
+
* const result = image?.setFront();
|
|
851
|
+
* console.log(result);
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
setFront() {
|
|
855
|
+
return this._commandService.syncExecuteCommand(SetDrawingArrangeCommand.id, {
|
|
856
|
+
unitId: this._image.unitId,
|
|
857
|
+
subUnitId: this._image.subUnitId,
|
|
858
|
+
drawingIds: [this._image.drawingId],
|
|
859
|
+
arrangeType: ArrangeTypeEnum.front
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
FOverGridImage = __decorate([__decorateParam(1, ICommandService), __decorateParam(2, Inject(Injector))], FOverGridImage);
|
|
864
|
+
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region src/facade/f-worksheet.ts
|
|
867
|
+
var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
868
|
+
async insertImage(url, column, row, offsetX, offsetY) {
|
|
869
|
+
const imageBuilder = this.newOverGridImage();
|
|
870
|
+
if (typeof url === "string") imageBuilder.setSource(url);
|
|
871
|
+
else {
|
|
872
|
+
const base64 = await url.getBlob().getDataAsString();
|
|
873
|
+
imageBuilder.setSource(base64, ImageSourceType.BASE64);
|
|
874
|
+
}
|
|
875
|
+
if (column !== void 0) imageBuilder.setColumn(column);
|
|
876
|
+
else imageBuilder.setColumn(0);
|
|
877
|
+
if (row !== void 0) imageBuilder.setRow(row);
|
|
878
|
+
else imageBuilder.setRow(0);
|
|
879
|
+
if (offsetX !== void 0) imageBuilder.setColumnOffset(offsetX);
|
|
880
|
+
else imageBuilder.setColumnOffset(0);
|
|
881
|
+
if (offsetY !== void 0) imageBuilder.setRowOffset(offsetY);
|
|
882
|
+
else imageBuilder.setRowOffset(0);
|
|
883
|
+
const param = await imageBuilder.buildAsync();
|
|
884
|
+
return this._commandService.syncExecuteCommand(InsertSheetDrawingCommand.id, {
|
|
885
|
+
unitId: this._fWorkbook.getId(),
|
|
886
|
+
drawings: [param]
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
insertImages(sheetImages) {
|
|
890
|
+
const param = sheetImages.map((image) => {
|
|
891
|
+
image.unitId = this._fWorkbook.getId();
|
|
892
|
+
image.subUnitId = this.getSheetId();
|
|
893
|
+
return image;
|
|
894
|
+
});
|
|
895
|
+
this._commandService.syncExecuteCommand(InsertSheetDrawingCommand.id, {
|
|
896
|
+
unitId: this._fWorkbook.getId(),
|
|
897
|
+
drawings: param
|
|
898
|
+
});
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
deleteImages(sheetImages) {
|
|
902
|
+
const drawings = sheetImages.map((image) => {
|
|
903
|
+
return {
|
|
904
|
+
unitId: this._fWorkbook.getId(),
|
|
905
|
+
drawingId: image.getId(),
|
|
906
|
+
subUnitId: this.getSheetId(),
|
|
907
|
+
drawingType: image.getType()
|
|
908
|
+
};
|
|
909
|
+
});
|
|
910
|
+
this._commandService.syncExecuteCommand(RemoveSheetDrawingCommand.id, {
|
|
911
|
+
unitId: this._fWorkbook.getId(),
|
|
912
|
+
drawings
|
|
913
|
+
});
|
|
914
|
+
return this;
|
|
915
|
+
}
|
|
916
|
+
getImages() {
|
|
917
|
+
const drawingData = this._injector.get(ISheetDrawingService).getDrawingData(this._fWorkbook.getId(), this.getSheetId());
|
|
918
|
+
const images = [];
|
|
919
|
+
for (const drawingId in drawingData) {
|
|
920
|
+
const drawing = drawingData[drawingId];
|
|
921
|
+
if (drawing.drawingType !== DrawingTypeEnum.DRAWING_IMAGE) continue;
|
|
922
|
+
images.push(this._injector.createInstance(FOverGridImage, drawing));
|
|
923
|
+
}
|
|
924
|
+
return images;
|
|
925
|
+
}
|
|
926
|
+
getImageById(id) {
|
|
927
|
+
const drawing = this._injector.get(ISheetDrawingService).getDrawingByParam({
|
|
928
|
+
unitId: this._fWorkbook.getId(),
|
|
929
|
+
subUnitId: this.getSheetId(),
|
|
930
|
+
drawingId: id
|
|
931
|
+
});
|
|
932
|
+
if (drawing && drawing.drawingType === DrawingTypeEnum.DRAWING_IMAGE) return this._injector.createInstance(FOverGridImage, drawing);
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
getActiveImages() {
|
|
936
|
+
const drawingData = this._injector.get(ISheetDrawingService).getFocusDrawings();
|
|
937
|
+
const images = [];
|
|
938
|
+
for (const drawingId in drawingData) {
|
|
939
|
+
const drawing = drawingData[drawingId];
|
|
940
|
+
images.push(this._injector.createInstance(FOverGridImage, drawing));
|
|
941
|
+
}
|
|
942
|
+
return images;
|
|
943
|
+
}
|
|
944
|
+
updateImages(sheetImages) {
|
|
945
|
+
this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
946
|
+
unitId: this._fWorkbook.getId(),
|
|
947
|
+
drawings: sheetImages
|
|
948
|
+
});
|
|
949
|
+
return this;
|
|
950
|
+
}
|
|
951
|
+
newOverGridImage() {
|
|
952
|
+
const unitId = this._fWorkbook.getId();
|
|
953
|
+
const subUnitId = this.getSheetId();
|
|
954
|
+
return this._injector.createInstance(FOverGridImageBuilder, unitId, subUnitId);
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
FWorksheet.extend(FWorksheetDrawingMixin);
|
|
958
|
+
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region src/facade/f-enum.ts
|
|
961
|
+
/**
|
|
962
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
963
|
+
*
|
|
964
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
965
|
+
* you may not use this file except in compliance with the License.
|
|
966
|
+
* You may obtain a copy of the License at
|
|
967
|
+
*
|
|
968
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
969
|
+
*
|
|
970
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
971
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
972
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
973
|
+
* See the License for the specific language governing permissions and
|
|
974
|
+
* limitations under the License.
|
|
975
|
+
*/
|
|
976
|
+
var FSheetsDrawingEnumMixin = class extends FEnum {
|
|
977
|
+
get DrawingType() {
|
|
978
|
+
return DrawingTypeEnum;
|
|
979
|
+
}
|
|
980
|
+
get ImageSourceType() {
|
|
981
|
+
return ImageSourceType;
|
|
982
|
+
}
|
|
983
|
+
get SheetDrawingAnchorType() {
|
|
984
|
+
return SheetDrawingAnchorType;
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
FEnum.extend(FSheetsDrawingEnumMixin);
|
|
988
|
+
|
|
989
|
+
//#endregion
|
|
990
|
+
//#region src/facade/f-event.ts
|
|
991
|
+
var FSheetsDrawingEventNameMixin = class extends FEventName {
|
|
992
|
+
get BeforeFloatDomAdd() {
|
|
993
|
+
return "BeforeFloatDomAdd";
|
|
994
|
+
}
|
|
995
|
+
get FloatDomAdded() {
|
|
996
|
+
return "FloatDomAdded";
|
|
997
|
+
}
|
|
998
|
+
get BeforeFloatDomUpdate() {
|
|
999
|
+
return "BeforeFloatDomUpdate";
|
|
1000
|
+
}
|
|
1001
|
+
get FloatDomUpdated() {
|
|
1002
|
+
return "FloatDomUpdated";
|
|
1003
|
+
}
|
|
1004
|
+
get BeforeFloatDomDelete() {
|
|
1005
|
+
return "BeforeFloatDomDelete";
|
|
1006
|
+
}
|
|
1007
|
+
get FloatDomDeleted() {
|
|
1008
|
+
return "FloatDomDeleted";
|
|
1009
|
+
}
|
|
1010
|
+
get BeforeOverGridImageChange() {
|
|
1011
|
+
return "BeforeOverGridImageChange";
|
|
1012
|
+
}
|
|
1013
|
+
get OverGridImageChanged() {
|
|
1014
|
+
return "OverGridImageChanged";
|
|
1015
|
+
}
|
|
1016
|
+
get BeforeOverGridImageInsert() {
|
|
1017
|
+
return "BeforeOverGridImageInsert";
|
|
1018
|
+
}
|
|
1019
|
+
get OverGridImageInserted() {
|
|
1020
|
+
return "OverGridImageInserted";
|
|
1021
|
+
}
|
|
1022
|
+
get BeforeOverGridImageRemove() {
|
|
1023
|
+
return "BeforeOverGridImageRemove";
|
|
1024
|
+
}
|
|
1025
|
+
get OverGridImageRemoved() {
|
|
1026
|
+
return "OverGridImageRemoved";
|
|
1027
|
+
}
|
|
1028
|
+
get BeforeOverGridImageSelect() {
|
|
1029
|
+
return "BeforeOverGridImageSelect";
|
|
1030
|
+
}
|
|
1031
|
+
get OverGridImageSelected() {
|
|
1032
|
+
return "OverGridImageSelected";
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
FEventName.extend(FSheetsDrawingEventNameMixin);
|
|
1036
|
+
|
|
1037
|
+
//#endregion
|
|
1038
|
+
//#region src/facade/f-univer.ts
|
|
1039
|
+
/**
|
|
1040
|
+
* @ignore
|
|
1041
|
+
*/
|
|
1042
|
+
var FUniverSheetsDrawingMixin = class extends FUniver {
|
|
1043
|
+
/**
|
|
1044
|
+
* @ignore
|
|
1045
|
+
*/
|
|
1046
|
+
_initialize(injector) {
|
|
1047
|
+
const commandService = injector.get(ICommandService);
|
|
1048
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1049
|
+
if (commandInfo.id !== InsertSheetDrawingCommand.id) return;
|
|
1050
|
+
const params = commandInfo.params;
|
|
1051
|
+
const workbook = this.getActiveWorkbook();
|
|
1052
|
+
if (workbook == null || params == null) return;
|
|
1053
|
+
const { drawings } = params;
|
|
1054
|
+
const eventParams = {
|
|
1055
|
+
workbook,
|
|
1056
|
+
insertImageParams: drawings
|
|
1057
|
+
};
|
|
1058
|
+
this.fireEvent(this.Event.BeforeOverGridImageInsert, eventParams);
|
|
1059
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
1060
|
+
})));
|
|
1061
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1062
|
+
if (commandInfo.id !== RemoveSheetDrawingCommand.id) return;
|
|
1063
|
+
const params = commandInfo.params;
|
|
1064
|
+
const workbook = this.getActiveWorkbook();
|
|
1065
|
+
if (workbook == null || params == null) return;
|
|
1066
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
1067
|
+
const { drawings } = params;
|
|
1068
|
+
const willRemoveDrawings = drawings.map((drawing) => {
|
|
1069
|
+
return drawingManagerService.getDrawingByParam(drawing);
|
|
1070
|
+
});
|
|
1071
|
+
const eventParams = {
|
|
1072
|
+
workbook,
|
|
1073
|
+
images: this._createFOverGridImage(willRemoveDrawings)
|
|
1074
|
+
};
|
|
1075
|
+
this.fireEvent(this.Event.BeforeOverGridImageRemove, eventParams);
|
|
1076
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
1077
|
+
})));
|
|
1078
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1079
|
+
if (commandInfo.id !== SetSheetDrawingCommand.id) return;
|
|
1080
|
+
const params = commandInfo.params;
|
|
1081
|
+
const workbook = this.getActiveWorkbook();
|
|
1082
|
+
if (workbook == null || params == null) return;
|
|
1083
|
+
const { drawings } = params;
|
|
1084
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
1085
|
+
const images = [];
|
|
1086
|
+
drawings.forEach((drawing) => {
|
|
1087
|
+
const image = drawingManagerService.getDrawingByParam(drawing);
|
|
1088
|
+
if (image == null) return;
|
|
1089
|
+
images.push({
|
|
1090
|
+
changeParam: drawing,
|
|
1091
|
+
image: this._injector.createInstance(FOverGridImage, image)
|
|
1092
|
+
});
|
|
1093
|
+
});
|
|
1094
|
+
const eventParams = {
|
|
1095
|
+
workbook,
|
|
1096
|
+
images
|
|
1097
|
+
};
|
|
1098
|
+
this.fireEvent(this.Event.BeforeOverGridImageChange, eventParams);
|
|
1099
|
+
if (eventParams.cancel) {
|
|
1100
|
+
drawingManagerService.updateNotification(drawings);
|
|
1101
|
+
throw new CanceledError();
|
|
1102
|
+
}
|
|
1103
|
+
})));
|
|
1104
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1105
|
+
if (commandInfo.id !== SetDrawingSelectedOperation.id) return;
|
|
1106
|
+
const drawings = commandInfo.params;
|
|
1107
|
+
const workbook = this.getActiveWorkbook();
|
|
1108
|
+
if (workbook == null) return;
|
|
1109
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
1110
|
+
const oldSelectedDrawings = drawingManagerService.getFocusDrawings();
|
|
1111
|
+
const selectedDrawings = drawings.map((drawing) => {
|
|
1112
|
+
return drawingManagerService.getDrawingByParam(drawing);
|
|
1113
|
+
});
|
|
1114
|
+
const eventParams = {
|
|
1115
|
+
workbook,
|
|
1116
|
+
selectedImages: this._createFOverGridImage(selectedDrawings),
|
|
1117
|
+
oldSelectedImages: this._createFOverGridImage(oldSelectedDrawings)
|
|
1118
|
+
};
|
|
1119
|
+
this.fireEvent(this.Event.BeforeOverGridImageSelect, eventParams);
|
|
1120
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
1121
|
+
})));
|
|
1122
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted, () => commandService.onCommandExecuted((commandInfo) => {
|
|
1123
|
+
if (commandInfo.id !== InsertSheetDrawingCommand.id) return;
|
|
1124
|
+
const params = commandInfo.params;
|
|
1125
|
+
const workbook = this.getActiveWorkbook();
|
|
1126
|
+
if (workbook == null || params == null) return;
|
|
1127
|
+
const { drawings } = params;
|
|
1128
|
+
const eventParams = {
|
|
1129
|
+
workbook,
|
|
1130
|
+
images: this._createFOverGridImage(drawings)
|
|
1131
|
+
};
|
|
1132
|
+
this.fireEvent(this.Event.OverGridImageInserted, eventParams);
|
|
1133
|
+
})));
|
|
1134
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved, () => commandService.onCommandExecuted((commandInfo) => {
|
|
1135
|
+
if (commandInfo.id !== RemoveSheetDrawingCommand.id) return;
|
|
1136
|
+
const params = commandInfo.params;
|
|
1137
|
+
const workbook = this.getActiveWorkbook();
|
|
1138
|
+
if (workbook == null || params == null) return;
|
|
1139
|
+
const { drawings } = params;
|
|
1140
|
+
const eventParams = {
|
|
1141
|
+
workbook,
|
|
1142
|
+
removeImageParams: drawings
|
|
1143
|
+
};
|
|
1144
|
+
this.fireEvent(this.Event.OverGridImageRemoved, eventParams);
|
|
1145
|
+
})));
|
|
1146
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged, () => commandService.onCommandExecuted((commandInfo) => {
|
|
1147
|
+
if (commandInfo.id !== SetSheetDrawingCommand.id) return;
|
|
1148
|
+
const params = commandInfo.params;
|
|
1149
|
+
const workbook = this.getActiveWorkbook();
|
|
1150
|
+
if (workbook == null || params == null) return;
|
|
1151
|
+
const { drawings } = params;
|
|
1152
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
1153
|
+
const eventParams = {
|
|
1154
|
+
workbook,
|
|
1155
|
+
images: drawings.map((drawing) => {
|
|
1156
|
+
return this._injector.createInstance(FOverGridImage, drawingManagerService.getDrawingByParam(drawing));
|
|
1157
|
+
})
|
|
1158
|
+
};
|
|
1159
|
+
this.fireEvent(this.Event.OverGridImageChanged, eventParams);
|
|
1160
|
+
})));
|
|
1161
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected, () => commandService.onCommandExecuted((commandInfo) => {
|
|
1162
|
+
if (commandInfo.id !== SetDrawingSelectedOperation.id) return;
|
|
1163
|
+
const drawings = commandInfo.params;
|
|
1164
|
+
const workbook = this.getActiveWorkbook();
|
|
1165
|
+
if (workbook == null) return;
|
|
1166
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
1167
|
+
const selectedDrawings = drawings.map((drawing) => {
|
|
1168
|
+
return drawingManagerService.getDrawingByParam(drawing);
|
|
1169
|
+
});
|
|
1170
|
+
const eventParams = {
|
|
1171
|
+
workbook,
|
|
1172
|
+
selectedImages: this._createFOverGridImage(selectedDrawings)
|
|
1173
|
+
};
|
|
1174
|
+
this.fireEvent(this.Event.OverGridImageSelected, eventParams);
|
|
1175
|
+
})));
|
|
1176
|
+
}
|
|
1177
|
+
_createFOverGridImage(drawings) {
|
|
1178
|
+
return drawings.map((drawing) => {
|
|
1179
|
+
return this._injector.createInstance(FOverGridImage, drawing);
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
FUniver.extend(FUniverSheetsDrawingMixin);
|
|
1184
|
+
|
|
1185
|
+
//#endregion
|
|
1186
|
+
export { };
|