@univerjs/sheets-drawing-ui 0.6.0-nightly.202502181606 → 0.6.0-nightly.202502201606
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 +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +519 -381
- package/lib/es/index.js +955 -969
- package/lib/types/facade/f-event.d.ts +61 -45
- package/lib/types/facade/f-over-grid-image.d.ts +378 -217
- package/lib/types/facade/f-worksheet.d.ts +290 -131
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +2 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +16 -16
package/lib/es/facade.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Inject as
|
|
5
|
-
import { FBase as
|
|
6
|
-
import { getImageSize as
|
|
7
|
-
import { IRenderManagerService as
|
|
8
|
-
import { SetSheetDrawingCommand as h, SetDrawingArrangeCommand as w, SheetCanvasFloatDomManagerService as
|
|
9
|
-
import { SheetSkeletonManagerService as
|
|
10
|
-
import { ISheetDrawingService as l, SheetDrawingAnchorType as
|
|
11
|
-
import { transformComponentKey as
|
|
12
|
-
import { FWorksheet as
|
|
13
|
-
import { ComponentManager as
|
|
14
|
-
var
|
|
15
|
-
for (var n = i > 1 ? void 0 : i ?
|
|
16
|
-
(o =
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
const { from:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{ from:
|
|
24
|
-
|
|
25
|
-
), {
|
|
1
|
+
var K = Object.defineProperty;
|
|
2
|
+
var L = (e, r, t) => r in e ? K(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var T = (e, r, t) => L(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { Inject as U, Injector as P, ICommandService as j, ImageSourceType as f, ArrangeTypeEnum as v, DrawingTypeEnum as _, generateRandomId as X, toDisposable as y } from "@univerjs/core";
|
|
5
|
+
import { FBase as Y, FEnum as W, FEventName as M, FUniver as H } from "@univerjs/core/facade";
|
|
6
|
+
import { getImageSize as V, IDrawingManagerService as I, SetDrawingSelectedOperation as x } from "@univerjs/drawing";
|
|
7
|
+
import { IRenderManagerService as A } from "@univerjs/engine-render";
|
|
8
|
+
import { RemoveSheetDrawingCommand as S, SetSheetDrawingCommand as h, SetDrawingArrangeCommand as w, SheetCanvasFloatDomManagerService as D, InsertSheetDrawingCommand as p } from "@univerjs/sheets-drawing-ui";
|
|
9
|
+
import { SheetSkeletonManagerService as F, ISheetSelectionRenderService as q, convertPositionSheetOverGridToAbsolute as J, convertPositionCellToSheetOverGrid as Q } from "@univerjs/sheets-ui";
|
|
10
|
+
import { ISheetDrawingService as l, SheetDrawingAnchorType as Z } from "@univerjs/sheets-drawing";
|
|
11
|
+
import { transformComponentKey as R } from "@univerjs/sheets-ui/facade";
|
|
12
|
+
import { FWorksheet as z } from "@univerjs/sheets/facade";
|
|
13
|
+
import { ComponentManager as G } from "@univerjs/ui";
|
|
14
|
+
var ee = Object.getOwnPropertyDescriptor, N = (e, r, t, i) => {
|
|
15
|
+
for (var n = i > 1 ? void 0 : i ? ee(r, t) : r, s = e.length - 1, o; s >= 0; s--)
|
|
16
|
+
(o = e[s]) && (n = o(n) || n);
|
|
17
|
+
return n;
|
|
18
|
+
}, B = (e, r) => (t, i) => r(t, i, e);
|
|
19
|
+
function te(e, r) {
|
|
20
|
+
const { from: t, to: i, flipY: n = !1, flipX: s = !1, angle: o = 0, skewX: d = 0, skewY: a = 0 } = e.sheetTransform, { column: g, columnOffset: c, row: u, rowOffset: O } = t, k = J(
|
|
21
|
+
e.unitId,
|
|
22
|
+
e.subUnitId,
|
|
23
|
+
{ from: t, to: i },
|
|
24
|
+
r
|
|
25
|
+
), { width: E, height: C } = k;
|
|
26
26
|
return {
|
|
27
|
-
...
|
|
27
|
+
...e,
|
|
28
28
|
column: g,
|
|
29
29
|
columnOffset: c,
|
|
30
30
|
row: u,
|
|
31
|
-
rowOffset:
|
|
31
|
+
rowOffset: O,
|
|
32
32
|
width: E,
|
|
33
|
-
height:
|
|
33
|
+
height: C,
|
|
34
34
|
flipY: n,
|
|
35
35
|
flipX: s,
|
|
36
36
|
angle: o,
|
|
@@ -38,20 +38,20 @@ function ie(r, t) {
|
|
|
38
38
|
skewY: a
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
const { column: i, columnOffset: n, row: s, rowOffset: o, flipY: d = !1, flipX: a = !1, angle: g = 0, skewX: c = 0, skewY: u = 0, width:
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
function re(e, r, t) {
|
|
42
|
+
const { column: i, columnOffset: n, row: s, rowOffset: o, flipY: d = !1, flipX: a = !1, angle: g = 0, skewX: c = 0, skewY: u = 0, width: O, height: k } = e, E = Q(
|
|
43
|
+
e.unitId,
|
|
44
|
+
e.subUnitId,
|
|
45
45
|
{ column: i, columnOffset: n, row: s, rowOffset: o },
|
|
46
|
-
b,
|
|
47
46
|
O,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
k,
|
|
48
|
+
r,
|
|
49
|
+
t
|
|
50
|
+
), { sheetTransform: C, transform: $ } = E;
|
|
51
51
|
return {
|
|
52
|
-
...
|
|
52
|
+
...e,
|
|
53
53
|
sheetTransform: {
|
|
54
|
-
...
|
|
54
|
+
...C,
|
|
55
55
|
flipY: d,
|
|
56
56
|
flipX: a,
|
|
57
57
|
angle: g,
|
|
@@ -59,7 +59,7 @@ function ne(r, t, e) {
|
|
|
59
59
|
skewY: u
|
|
60
60
|
},
|
|
61
61
|
transform: {
|
|
62
|
-
|
|
62
|
+
...$,
|
|
63
63
|
flipY: d,
|
|
64
64
|
flipX: a,
|
|
65
65
|
angle: g,
|
|
@@ -68,16 +68,16 @@ function ne(r, t, e) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
let
|
|
72
|
-
constructor(r, t
|
|
73
|
-
|
|
74
|
-
this._injector =
|
|
75
|
-
drawingId:
|
|
71
|
+
let b = class {
|
|
72
|
+
constructor(e, r, t) {
|
|
73
|
+
T(this, "_image");
|
|
74
|
+
this._injector = t, this._image = {
|
|
75
|
+
drawingId: X(6),
|
|
76
76
|
drawingType: _.DRAWING_IMAGE,
|
|
77
|
-
imageSourceType:
|
|
77
|
+
imageSourceType: f.BASE64,
|
|
78
78
|
source: "",
|
|
79
|
-
unitId:
|
|
80
|
-
subUnitId:
|
|
79
|
+
unitId: e,
|
|
80
|
+
subUnitId: r,
|
|
81
81
|
column: 0,
|
|
82
82
|
columnOffset: 0,
|
|
83
83
|
row: 0,
|
|
@@ -88,31 +88,35 @@ let p = class {
|
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Set the initial image configuration for the image builder.
|
|
91
|
-
* @param image The image
|
|
92
|
-
* @returns The
|
|
91
|
+
* @param {ISheetImage} image - The image configuration
|
|
92
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
93
93
|
* @example
|
|
94
94
|
* ```ts
|
|
95
|
-
* // create a new image builder.
|
|
96
|
-
*
|
|
97
|
-
* const
|
|
98
|
-
* const
|
|
99
|
-
* const
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
95
|
+
* // create a new image builder and set initial image configuration.
|
|
96
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
97
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
98
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
99
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
100
|
+
* .setImage({
|
|
101
|
+
* drawingId: '123456',
|
|
102
|
+
* drawingType: univerAPI.Enum.DrawingType.DRAWING_IMAGE,
|
|
103
|
+
* imageSourceType: univerAPI.Enum.ImageSourceType.BASE64,
|
|
104
|
+
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
105
|
+
* unitId: fWorkbook.getId(),
|
|
106
|
+
* subUnitId: fWorksheet.getSheetId(),
|
|
107
|
+
* })
|
|
108
|
+
* .setColumn(5)
|
|
109
|
+
* .setRow(5)
|
|
110
|
+
* .buildAsync();
|
|
111
|
+
* fWorksheet.insertImages([image]);
|
|
108
112
|
* ```
|
|
109
113
|
*/
|
|
110
|
-
setImage(
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
113
|
-
throw new Error(`Render Unit with unitId ${
|
|
114
|
-
const i =
|
|
115
|
-
return
|
|
114
|
+
setImage(e) {
|
|
115
|
+
const t = this._injector.get(A).getRenderById(e.unitId);
|
|
116
|
+
if (!t)
|
|
117
|
+
throw new Error(`Render Unit with unitId ${e.unitId} not found`);
|
|
118
|
+
const i = t.with(F);
|
|
119
|
+
return e.sheetTransform == null && (e.sheetTransform = {
|
|
116
120
|
from: {
|
|
117
121
|
column: 0,
|
|
118
122
|
columnOffset: 0,
|
|
@@ -125,204 +129,312 @@ let p = class {
|
|
|
125
129
|
row: 0,
|
|
126
130
|
rowOffset: 0
|
|
127
131
|
}
|
|
128
|
-
}), this._image =
|
|
132
|
+
}), this._image = te(e, i), this;
|
|
129
133
|
}
|
|
130
|
-
setSource(
|
|
131
|
-
const
|
|
132
|
-
return this._image.source =
|
|
134
|
+
setSource(e, r) {
|
|
135
|
+
const t = r != null ? r : f.URL;
|
|
136
|
+
return this._image.source = e, this._image.imageSourceType = t, this;
|
|
133
137
|
}
|
|
134
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Get the source of the image
|
|
140
|
+
* @returns {string} The source of the image
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
144
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
145
|
+
* const images = fWorksheet.getImages();
|
|
146
|
+
* images.forEach((image) => {
|
|
147
|
+
* console.log(image, image.toBuilder().getSource());
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
getSource() {
|
|
135
152
|
return this._image.source;
|
|
136
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the source type of the image
|
|
156
|
+
* @returns {ImageSourceType} The source type of the image
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
160
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
161
|
+
* const images = fWorksheet.getImages();
|
|
162
|
+
* images.forEach((image) => {
|
|
163
|
+
* console.log(image, image.toBuilder().getSourceType());
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
137
167
|
getSourceType() {
|
|
138
168
|
return this._image.imageSourceType;
|
|
139
169
|
}
|
|
140
170
|
/**
|
|
141
|
-
* Set the position of the image
|
|
142
|
-
* @param column
|
|
143
|
-
* @returns The
|
|
171
|
+
* Set the horizontal position of the image
|
|
172
|
+
* @param {number} column - The column index of the image start position
|
|
173
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
144
174
|
* @example
|
|
145
175
|
* ```ts
|
|
146
|
-
* // create a new image builder.
|
|
147
|
-
*
|
|
148
|
-
* const
|
|
149
|
-
* const
|
|
150
|
-
* const
|
|
151
|
-
*
|
|
176
|
+
* // create a new image builder and set image source.
|
|
177
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
178
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
179
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
180
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
181
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
182
|
+
* .setColumn(5)
|
|
183
|
+
* .setRow(5)
|
|
184
|
+
* .buildAsync();
|
|
185
|
+
* fWorksheet.insertImages([image]);
|
|
152
186
|
* ```
|
|
153
187
|
*/
|
|
154
|
-
setColumn(
|
|
155
|
-
return this._image.column =
|
|
188
|
+
setColumn(e) {
|
|
189
|
+
return this._image.column = e, this;
|
|
156
190
|
}
|
|
157
191
|
/**
|
|
158
|
-
* Set the position of the image
|
|
159
|
-
* @param row The
|
|
160
|
-
* @returns The
|
|
192
|
+
* Set the vertical position of the image
|
|
193
|
+
* @param {number} row - The row index of the image start position
|
|
194
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
161
195
|
* @example
|
|
162
196
|
* ```ts
|
|
163
|
-
* // create a new image builder.
|
|
164
|
-
*
|
|
165
|
-
* const
|
|
166
|
-
* const
|
|
167
|
-
* const
|
|
168
|
-
*
|
|
197
|
+
* // create a new image builder and set image source.
|
|
198
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
|
|
199
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
200
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
201
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
202
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
203
|
+
* .setColumn(5)
|
|
204
|
+
* .setRow(5)
|
|
205
|
+
* .buildAsync();
|
|
206
|
+
* fWorksheet.insertImages([image]);
|
|
169
207
|
* ```
|
|
170
208
|
*/
|
|
171
|
-
setRow(
|
|
172
|
-
return this._image.row =
|
|
209
|
+
setRow(e) {
|
|
210
|
+
return this._image.row = e, this;
|
|
173
211
|
}
|
|
174
212
|
/**
|
|
175
|
-
* Set the
|
|
176
|
-
* @param offset The offset
|
|
177
|
-
* @returns The
|
|
213
|
+
* Set the horizontal offset of the image
|
|
214
|
+
* @param {number} offset - The column offset of the image start position, pixel unit
|
|
215
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
178
216
|
* @example
|
|
179
217
|
* ```ts
|
|
180
|
-
* // create a new image builder.
|
|
181
|
-
*
|
|
182
|
-
* const
|
|
183
|
-
* const
|
|
184
|
-
* const
|
|
185
|
-
*
|
|
218
|
+
* // create a new image builder and set image source.
|
|
219
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and horizontal offset is 10px.
|
|
220
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
221
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
222
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
223
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
224
|
+
* .setColumn(5)
|
|
225
|
+
* .setRow(5)
|
|
226
|
+
* .setColumnOffset(10)
|
|
227
|
+
* .buildAsync();
|
|
228
|
+
* fWorksheet.insertImages([image]);
|
|
186
229
|
* ```
|
|
187
230
|
*/
|
|
188
|
-
setColumnOffset(
|
|
189
|
-
return this._image.columnOffset =
|
|
231
|
+
setColumnOffset(e) {
|
|
232
|
+
return this._image.columnOffset = e, this;
|
|
190
233
|
}
|
|
191
234
|
/**
|
|
192
|
-
* Set the
|
|
193
|
-
* @param offset The offset
|
|
194
|
-
* @returns The
|
|
235
|
+
* Set the vertical offset of the image
|
|
236
|
+
* @param {number} offset - The row offset of the image start position, pixel unit
|
|
237
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
195
238
|
* @example
|
|
196
239
|
* ```ts
|
|
197
|
-
* // create a new image builder.
|
|
198
|
-
*
|
|
199
|
-
* const
|
|
200
|
-
* const
|
|
201
|
-
* const
|
|
202
|
-
*
|
|
240
|
+
* // create a new image builder and set image source.
|
|
241
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and vertical offset is 10px.
|
|
242
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
243
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
244
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
245
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
246
|
+
* .setColumn(5)
|
|
247
|
+
* .setRow(5)
|
|
248
|
+
* .setRowOffset(10)
|
|
249
|
+
* .buildAsync();
|
|
250
|
+
* fWorksheet.insertImages([image]);
|
|
203
251
|
* ```
|
|
204
252
|
*/
|
|
205
|
-
setRowOffset(
|
|
206
|
-
return this._image.rowOffset =
|
|
253
|
+
setRowOffset(e) {
|
|
254
|
+
return this._image.rowOffset = e, this;
|
|
207
255
|
}
|
|
208
256
|
/**
|
|
209
|
-
*
|
|
210
|
-
* @param width The width of the image,
|
|
211
|
-
* @returns The
|
|
257
|
+
* Set the width of the image
|
|
258
|
+
* @param {number} width - The width of the image, pixel unit
|
|
259
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
212
260
|
* @example
|
|
213
261
|
* ```ts
|
|
214
|
-
* // create a new image builder.
|
|
215
|
-
*
|
|
216
|
-
* const
|
|
217
|
-
* const
|
|
218
|
-
* const
|
|
219
|
-
*
|
|
262
|
+
* // create a new image builder and set image source.
|
|
263
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
|
|
264
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
265
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
266
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
267
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
268
|
+
* .setColumn(5)
|
|
269
|
+
* .setRow(5)
|
|
270
|
+
* .setWidth(120)
|
|
271
|
+
* .setHeight(50)
|
|
272
|
+
* .buildAsync();
|
|
273
|
+
* fWorksheet.insertImages([image]);
|
|
220
274
|
* ```
|
|
221
275
|
*/
|
|
222
|
-
setWidth(
|
|
223
|
-
return this._image.width =
|
|
276
|
+
setWidth(e) {
|
|
277
|
+
return this._image.width = e, this;
|
|
224
278
|
}
|
|
225
279
|
/**
|
|
226
280
|
* Set the height of the image
|
|
227
|
-
* @param height The height of the image,
|
|
228
|
-
* @returns The
|
|
281
|
+
* @param {number} height - The height of the image, pixel unit
|
|
282
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
229
283
|
* @example
|
|
230
284
|
* ```ts
|
|
231
|
-
* // create a new image builder.
|
|
232
|
-
*
|
|
233
|
-
* const
|
|
234
|
-
* const
|
|
235
|
-
* const
|
|
236
|
-
*
|
|
285
|
+
* // create a new image builder and set image source.
|
|
286
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
|
|
287
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
288
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
289
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
290
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
291
|
+
* .setColumn(5)
|
|
292
|
+
* .setRow(5)
|
|
293
|
+
* .setWidth(120)
|
|
294
|
+
* .setHeight(50)
|
|
295
|
+
* .buildAsync();
|
|
296
|
+
* fWorksheet.insertImages([image]);
|
|
237
297
|
* ```
|
|
238
298
|
*/
|
|
239
|
-
setHeight(
|
|
240
|
-
return this._image.height =
|
|
299
|
+
setHeight(e) {
|
|
300
|
+
return this._image.height = e, this;
|
|
241
301
|
}
|
|
242
302
|
/**
|
|
243
303
|
* Set the anchor type of the image, whether the position and size change with the cell
|
|
244
|
-
* @param anchorType The anchor type
|
|
245
|
-
* @returns The
|
|
304
|
+
* @param {SheetDrawingAnchorType} anchorType - The anchor type of the image
|
|
305
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
246
306
|
* @example
|
|
247
307
|
* ```ts
|
|
248
|
-
*
|
|
249
|
-
* const
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
308
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
309
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
310
|
+
*
|
|
311
|
+
* // image1 position is start from A6 cell, anchor type is Position.
|
|
312
|
+
* // 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.
|
|
313
|
+
* const image1 = await fWorksheet.newOverGridImage()
|
|
314
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
315
|
+
* .setColumn(0)
|
|
316
|
+
* .setRow(5)
|
|
317
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Position)
|
|
318
|
+
* .buildAsync();
|
|
319
|
+
*
|
|
320
|
+
* // image2 position is start from C6 cell, anchor type is Both.
|
|
321
|
+
* // 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.
|
|
322
|
+
* const image2 = await fWorksheet.newOverGridImage()
|
|
323
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
324
|
+
* .setColumn(2)
|
|
325
|
+
* .setRow(5)
|
|
326
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Both)
|
|
327
|
+
* .buildAsync();
|
|
328
|
+
*
|
|
329
|
+
* // image3 position is start from E6 cell, anchor type is None.
|
|
330
|
+
* // 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.
|
|
331
|
+
* const image3 = await fWorksheet.newOverGridImage()
|
|
332
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
333
|
+
* .setColumn(4)
|
|
334
|
+
* .setRow(5)
|
|
335
|
+
* .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.None)
|
|
336
|
+
* .buildAsync();
|
|
337
|
+
*
|
|
338
|
+
* // insert images into the sheet
|
|
339
|
+
* fWorksheet.insertImages([image1, image2, image3]);
|
|
340
|
+
*
|
|
341
|
+
* // after 2 seconds, set the row height of the 5th row to 100px and insert a row before the 5th row.
|
|
342
|
+
* // then observe the position and size changes of the images.
|
|
343
|
+
* setTimeout(() => {
|
|
344
|
+
* fWorksheet.setRowHeight(5, 100).insertRowBefore(5);
|
|
345
|
+
* }, 2000);
|
|
254
346
|
* ```
|
|
255
347
|
*/
|
|
256
|
-
setAnchorType(
|
|
257
|
-
return this._image.anchorType =
|
|
348
|
+
setAnchorType(e) {
|
|
349
|
+
return this._image.anchorType = e, this;
|
|
258
350
|
}
|
|
259
351
|
/**
|
|
260
352
|
* Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
|
|
261
|
-
* @param top
|
|
262
|
-
* @returns The
|
|
353
|
+
* @param {number} top - The number of pixels to crop from the top of the image
|
|
354
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
263
355
|
* @example
|
|
264
356
|
* ```ts
|
|
265
|
-
* // create a new image builder.
|
|
266
|
-
*
|
|
267
|
-
* const
|
|
268
|
-
* const
|
|
269
|
-
* const
|
|
270
|
-
*
|
|
357
|
+
* // create a new image builder and set image source.
|
|
358
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, top crop is 10px.
|
|
359
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
360
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
361
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
362
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
363
|
+
* .setColumn(5)
|
|
364
|
+
* .setRow(5)
|
|
365
|
+
* .setCropTop(10)
|
|
366
|
+
* .buildAsync();
|
|
367
|
+
* fWorksheet.insertImages([image]);
|
|
271
368
|
* ```
|
|
272
369
|
*/
|
|
273
|
-
setCropTop(
|
|
274
|
-
return this._initializeSrcRect(), this._image.srcRect.top =
|
|
370
|
+
setCropTop(e) {
|
|
371
|
+
return this._initializeSrcRect(), this._image.srcRect.top = e, this;
|
|
275
372
|
}
|
|
276
373
|
/**
|
|
277
374
|
* Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
|
|
278
|
-
* @param left
|
|
279
|
-
* @returns The
|
|
375
|
+
* @param {number} left - The number of pixels to crop from the left side of the image
|
|
376
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
280
377
|
* @example
|
|
281
378
|
* ```ts
|
|
282
|
-
* // create a new image builder.
|
|
283
|
-
*
|
|
284
|
-
* const
|
|
285
|
-
* const
|
|
286
|
-
* const
|
|
287
|
-
*
|
|
379
|
+
* // create a new image builder and set image source.
|
|
380
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, left crop is 10px.
|
|
381
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
382
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
383
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
384
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
385
|
+
* .setColumn(5)
|
|
386
|
+
* .setRow(5)
|
|
387
|
+
* .setCropLeft(10)
|
|
388
|
+
* .buildAsync();
|
|
389
|
+
* fWorksheet.insertImages([image]);
|
|
288
390
|
* ```
|
|
289
391
|
*/
|
|
290
|
-
setCropLeft(
|
|
291
|
-
return this._initializeSrcRect(), this._image.srcRect.left =
|
|
392
|
+
setCropLeft(e) {
|
|
393
|
+
return this._initializeSrcRect(), this._image.srcRect.left = e, this;
|
|
292
394
|
}
|
|
293
395
|
/**
|
|
294
396
|
* Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
|
|
295
|
-
* @param bottom
|
|
296
|
-
* @returns The
|
|
397
|
+
* @param {number} bottom - The number of pixels to crop from the bottom of the image
|
|
398
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
297
399
|
* @example
|
|
298
400
|
* ```ts
|
|
299
|
-
* // create a new image builder.
|
|
300
|
-
*
|
|
301
|
-
* const
|
|
302
|
-
* const
|
|
303
|
-
* const
|
|
304
|
-
*
|
|
401
|
+
* // create a new image builder and set image source.
|
|
402
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, bottom crop is 10px.
|
|
403
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
404
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
405
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
406
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
407
|
+
* .setColumn(5)
|
|
408
|
+
* .setRow(5)
|
|
409
|
+
* .setCropBottom(10)
|
|
410
|
+
* .buildAsync();
|
|
411
|
+
* fWorksheet.insertImages([image]);
|
|
305
412
|
* ```
|
|
306
413
|
*/
|
|
307
|
-
setCropBottom(
|
|
308
|
-
return this._initializeSrcRect(), this._image.srcRect.bottom =
|
|
414
|
+
setCropBottom(e) {
|
|
415
|
+
return this._initializeSrcRect(), this._image.srcRect.bottom = e, this;
|
|
309
416
|
}
|
|
310
417
|
/**
|
|
311
418
|
* Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
|
|
312
|
-
* @param right
|
|
313
|
-
* @returns The
|
|
419
|
+
* @param {number} right - The number of pixels to crop from the right side of the image
|
|
420
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
314
421
|
* @example
|
|
315
422
|
* ```ts
|
|
316
|
-
* // create a new image builder.
|
|
317
|
-
*
|
|
318
|
-
* const
|
|
319
|
-
* const
|
|
320
|
-
* const
|
|
321
|
-
*
|
|
423
|
+
* // create a new image builder and set image source.
|
|
424
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, right crop is 10px.
|
|
425
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
426
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
427
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
428
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
429
|
+
* .setColumn(5)
|
|
430
|
+
* .setRow(5)
|
|
431
|
+
* .setCropRight(10)
|
|
432
|
+
* .buildAsync();
|
|
433
|
+
* fWorksheet.insertImages([image]);
|
|
322
434
|
* ```
|
|
323
435
|
*/
|
|
324
|
-
setCropRight(
|
|
325
|
-
return this._initializeSrcRect(), this._image.srcRect.right =
|
|
436
|
+
setCropRight(e) {
|
|
437
|
+
return this._initializeSrcRect(), this._image.srcRect.right = e, this;
|
|
326
438
|
}
|
|
327
439
|
_initializeSrcRect() {
|
|
328
440
|
this._image.srcRect == null && (this._image.srcRect = {
|
|
@@ -334,172 +446,198 @@ let p = class {
|
|
|
334
446
|
}
|
|
335
447
|
/**
|
|
336
448
|
* Set the rotation angle of the image
|
|
337
|
-
* @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
338
|
-
* @returns The
|
|
449
|
+
* @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
450
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
339
451
|
* @example
|
|
340
452
|
* ```ts
|
|
341
|
-
* // create a new image builder.
|
|
342
|
-
*
|
|
343
|
-
* const
|
|
344
|
-
* const
|
|
345
|
-
* const
|
|
346
|
-
*
|
|
453
|
+
* // create a new image builder and set image source.
|
|
454
|
+
* // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, rotate 90 degrees.
|
|
455
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
456
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
457
|
+
* const image = await fWorksheet.newOverGridImage()
|
|
458
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
|
|
459
|
+
* .setColumn(5)
|
|
460
|
+
* .setRow(5)
|
|
461
|
+
* .setRotate(90)
|
|
462
|
+
* .buildAsync();
|
|
463
|
+
* fWorksheet.insertImages([image]);
|
|
347
464
|
* ```
|
|
348
465
|
*/
|
|
349
|
-
setRotate(
|
|
350
|
-
return this._image.angle =
|
|
466
|
+
setRotate(e) {
|
|
467
|
+
return this._image.angle = e, this;
|
|
351
468
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
// return this;
|
|
355
|
-
// }
|
|
356
|
-
setUnitId(r) {
|
|
357
|
-
return this._image.unitId = r, this;
|
|
469
|
+
setUnitId(e) {
|
|
470
|
+
return this._image.unitId = e, this;
|
|
358
471
|
}
|
|
359
|
-
setSubUnitId(
|
|
360
|
-
return this._image.subUnitId =
|
|
472
|
+
setSubUnitId(e) {
|
|
473
|
+
return this._image.subUnitId = e, this;
|
|
361
474
|
}
|
|
362
475
|
async buildAsync() {
|
|
363
|
-
const
|
|
364
|
-
if (!
|
|
476
|
+
const r = this._injector.get(A).getRenderById(this._image.unitId);
|
|
477
|
+
if (!r)
|
|
365
478
|
throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
|
|
366
|
-
const
|
|
479
|
+
const t = r.with(q), i = r.with(F);
|
|
367
480
|
if (this._image.width === 0 || this._image.height === 0) {
|
|
368
|
-
const n = await
|
|
481
|
+
const n = await V(this._image.source), s = n.width, o = n.height;
|
|
369
482
|
this._image.width === 0 && (this._image.width = s), this._image.height === 0 && (this._image.height = o);
|
|
370
483
|
}
|
|
371
|
-
return
|
|
484
|
+
return re(this._image, t, i);
|
|
372
485
|
}
|
|
373
486
|
};
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
],
|
|
377
|
-
let m = class extends
|
|
378
|
-
constructor(r, t
|
|
379
|
-
super(), this._image =
|
|
487
|
+
b = N([
|
|
488
|
+
B(2, U(P))
|
|
489
|
+
], b);
|
|
490
|
+
let m = class extends Y {
|
|
491
|
+
constructor(e, r, t) {
|
|
492
|
+
super(), this._image = e, this._commandService = r, this._injector = t;
|
|
380
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Get the id of the image
|
|
496
|
+
* @returns {string} The id of the image
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
500
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
501
|
+
* const images = fWorksheet.getImages();
|
|
502
|
+
* images.forEach((image) => {
|
|
503
|
+
* console.log(image, image.getId());
|
|
504
|
+
* });
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
381
507
|
getId() {
|
|
382
508
|
return this._image.drawingId;
|
|
383
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* Get the drawing type of the image
|
|
512
|
+
* @returns {DrawingTypeEnum} The drawing type of the image
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
516
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
517
|
+
* const images = fWorksheet.getImages();
|
|
518
|
+
* images.forEach((image) => {
|
|
519
|
+
* console.log(image, image.getType());
|
|
520
|
+
* });
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
384
523
|
getType() {
|
|
385
524
|
return this._image.drawingType;
|
|
386
525
|
}
|
|
387
526
|
/**
|
|
388
527
|
* Remove the image from the sheet
|
|
389
|
-
* @returns
|
|
528
|
+
* @returns {boolean} true if the image is removed successfully, otherwise false
|
|
390
529
|
* @example
|
|
391
530
|
* ```ts
|
|
392
|
-
*
|
|
393
|
-
* const
|
|
394
|
-
* const
|
|
395
|
-
* const
|
|
396
|
-
* console.log(
|
|
531
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
532
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
533
|
+
* const image = fWorksheet.getImages()[0];
|
|
534
|
+
* const result = image?.remove();
|
|
535
|
+
* console.log(result);
|
|
397
536
|
* ```
|
|
398
537
|
*/
|
|
399
538
|
remove() {
|
|
400
|
-
return this._commandService.syncExecuteCommand(
|
|
539
|
+
return this._commandService.syncExecuteCommand(S.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
401
540
|
}
|
|
402
541
|
/**
|
|
403
542
|
* Convert the image to a FOverGridImageBuilder
|
|
404
|
-
* @returns The builder FOverGridImageBuilder
|
|
543
|
+
* @returns {FOverGridImageBuilder} The builder FOverGridImageBuilder
|
|
405
544
|
* @example
|
|
406
545
|
* ```ts
|
|
407
|
-
*
|
|
408
|
-
* const
|
|
409
|
-
* const
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* activeSheet.updateImages([param]);
|
|
546
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
547
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
548
|
+
* const images = fWorksheet.getImages();
|
|
549
|
+
* images.forEach((image) => {
|
|
550
|
+
* console.log(image, image.toBuilder().getSource());
|
|
551
|
+
* });
|
|
414
552
|
* ```
|
|
415
553
|
*/
|
|
416
554
|
toBuilder() {
|
|
417
|
-
const
|
|
418
|
-
return
|
|
555
|
+
const e = this._injector.createInstance(b);
|
|
556
|
+
return e.setImage(this._image), e;
|
|
419
557
|
}
|
|
420
|
-
setSource(
|
|
421
|
-
const
|
|
422
|
-
return this._image.source =
|
|
558
|
+
setSource(e, r) {
|
|
559
|
+
const t = r != null ? r : f.URL;
|
|
560
|
+
return this._image.source = e, this._image.imageSourceType = t, this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
423
561
|
}
|
|
424
|
-
async setPositionAsync(r, t,
|
|
562
|
+
async setPositionAsync(e, r, t, i) {
|
|
425
563
|
const n = this.toBuilder();
|
|
426
|
-
n.setColumn(
|
|
564
|
+
n.setColumn(r), n.setRow(e), t != null && n.setRowOffset(t), i != null && n.setColumnOffset(i);
|
|
427
565
|
const s = await n.buildAsync();
|
|
428
566
|
return this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [s] });
|
|
429
567
|
}
|
|
430
568
|
/**
|
|
431
569
|
* Set the size of the image
|
|
432
|
-
* @param width
|
|
433
|
-
* @param height
|
|
434
|
-
* @returns
|
|
570
|
+
* @param {number} width - The width of the image, pixel unit
|
|
571
|
+
* @param {number} height - The height of the image, pixel unit
|
|
572
|
+
* @returns {boolean} true if the size is set successfully, otherwise false
|
|
435
573
|
* @example
|
|
436
574
|
* ```ts
|
|
437
|
-
* // set the
|
|
438
|
-
* const
|
|
439
|
-
* const
|
|
440
|
-
* const image =
|
|
441
|
-
*
|
|
575
|
+
* // set the image width 120px and height 50px
|
|
576
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
577
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
578
|
+
* const image = fWorksheet.getImages()[0];
|
|
579
|
+
* const result = image?.setSizeAsync(120, 50);
|
|
580
|
+
* console.log(result);
|
|
581
|
+
* ```
|
|
442
582
|
*/
|
|
443
|
-
async setSizeAsync(
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
const i = await
|
|
583
|
+
async setSizeAsync(e, r) {
|
|
584
|
+
const t = this.toBuilder();
|
|
585
|
+
t.setWidth(e), t.setHeight(r);
|
|
586
|
+
const i = await t.buildAsync();
|
|
447
587
|
return this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [i] });
|
|
448
588
|
}
|
|
449
589
|
/**
|
|
450
590
|
* 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.
|
|
451
|
-
* @param top
|
|
452
|
-
* @param left
|
|
453
|
-
* @param bottom
|
|
454
|
-
* @param right
|
|
455
|
-
* @returns
|
|
591
|
+
* @param {number} top - The number of pixels to crop from the top of the image
|
|
592
|
+
* @param {number} left - The number of pixels to crop from the left side of the image
|
|
593
|
+
* @param {number} bottom - The number of pixels to crop from the bottom of the image
|
|
594
|
+
* @param {number} right - The number of pixels to crop from the right side of the image
|
|
595
|
+
* @returns {boolean} true if the crop is set successfully, otherwise false
|
|
456
596
|
* @example
|
|
457
597
|
* ```ts
|
|
458
|
-
* // set the crop of the image
|
|
459
|
-
* const
|
|
460
|
-
* const
|
|
461
|
-
* const image =
|
|
462
|
-
*
|
|
598
|
+
* // set the crop of the image, top 10px, left 10px, bottom 10px, right 10px.
|
|
599
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
600
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
601
|
+
* const image = fWorksheet.getImages()[0];
|
|
602
|
+
* const result = image?.setCrop(10, 10, 10, 10);
|
|
603
|
+
* console.log(result);
|
|
463
604
|
* ```
|
|
464
605
|
*/
|
|
465
|
-
setCrop(r, t,
|
|
606
|
+
setCrop(e, r, t, i) {
|
|
466
607
|
return this._image.srcRect == null && (this._image.srcRect = {
|
|
467
608
|
top: 0,
|
|
468
609
|
left: 0,
|
|
469
610
|
bottom: 0,
|
|
470
611
|
right: 0
|
|
471
|
-
}),
|
|
612
|
+
}), e != null && (this._image.srcRect.top = e), r != null && (this._image.srcRect.left = r), t != null && (this._image.srcRect.bottom = t), i != null && (this._image.srcRect.right = i), this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
472
613
|
}
|
|
473
|
-
// setPresetGeometry(prstGeom: PresetGeometryType): boolean {
|
|
474
|
-
// this._image.prstGeom = prstGeom;
|
|
475
|
-
// return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
476
|
-
// }
|
|
477
614
|
/**
|
|
478
615
|
* Set the rotation angle of the image
|
|
479
|
-
* @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
480
|
-
* @returns
|
|
616
|
+
* @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
617
|
+
* @returns {boolean} true if the rotation is set successfully, otherwise false
|
|
481
618
|
* @example
|
|
482
619
|
* ```ts
|
|
483
|
-
* // set
|
|
484
|
-
* const
|
|
485
|
-
* const
|
|
486
|
-
* const image =
|
|
487
|
-
*
|
|
620
|
+
* // set 90 degrees rotation of the image
|
|
621
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
622
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
623
|
+
* const image = fWorksheet.getImages()[0];
|
|
624
|
+
* const result = image?.setRotate(90);
|
|
625
|
+
* console.log(result);
|
|
488
626
|
* ```
|
|
489
627
|
*/
|
|
490
|
-
setRotate(
|
|
491
|
-
return this._image.sheetTransform.angle =
|
|
628
|
+
setRotate(e) {
|
|
629
|
+
return this._image.sheetTransform.angle = e, this._image.transform && (this._image.transform.angle = e), this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
492
630
|
}
|
|
493
631
|
/**
|
|
494
632
|
* Move the image layer forward by one level
|
|
495
|
-
* @returns
|
|
633
|
+
* @returns {boolean} true if the image is moved forward successfully, otherwise false
|
|
496
634
|
* @example
|
|
497
635
|
* ```ts
|
|
498
|
-
*
|
|
499
|
-
* const
|
|
500
|
-
* const
|
|
501
|
-
* const
|
|
502
|
-
* console.log(
|
|
636
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
637
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
638
|
+
* const image = fWorksheet.getImages()[0];
|
|
639
|
+
* const result = image?.setForward();
|
|
640
|
+
* console.log(result);
|
|
503
641
|
* ```
|
|
504
642
|
*/
|
|
505
643
|
setForward() {
|
|
@@ -515,11 +653,11 @@ let m = class extends V {
|
|
|
515
653
|
* @returns success or not
|
|
516
654
|
* @example
|
|
517
655
|
* ```ts
|
|
518
|
-
*
|
|
519
|
-
* const
|
|
520
|
-
* const
|
|
521
|
-
* const
|
|
522
|
-
* console.log(
|
|
656
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
657
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
658
|
+
* const image = fWorksheet.getImages()[0];
|
|
659
|
+
* const result = image?.setBackward();
|
|
660
|
+
* console.log(result);
|
|
523
661
|
* ```
|
|
524
662
|
*/
|
|
525
663
|
setBackward() {
|
|
@@ -531,15 +669,15 @@ let m = class extends V {
|
|
|
531
669
|
});
|
|
532
670
|
}
|
|
533
671
|
/**
|
|
534
|
-
* Move the image layer to the
|
|
672
|
+
* Move the image layer to the bottom layer
|
|
535
673
|
* @returns success or not
|
|
536
674
|
* @example
|
|
537
675
|
* ```ts
|
|
538
|
-
*
|
|
539
|
-
* const
|
|
540
|
-
* const
|
|
541
|
-
* const
|
|
542
|
-
* console.log(
|
|
676
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
677
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
678
|
+
* const image = fWorksheet.getImages()[0];
|
|
679
|
+
* const result = image?.setBack();
|
|
680
|
+
* console.log(result);
|
|
543
681
|
* ```
|
|
544
682
|
*/
|
|
545
683
|
setBack() {
|
|
@@ -551,15 +689,15 @@ let m = class extends V {
|
|
|
551
689
|
});
|
|
552
690
|
}
|
|
553
691
|
/**
|
|
554
|
-
* Move the image layer to the
|
|
692
|
+
* Move the image layer to the top layer
|
|
555
693
|
* @returns success or not
|
|
556
694
|
* @example
|
|
557
695
|
* ```ts
|
|
558
|
-
*
|
|
559
|
-
* const
|
|
560
|
-
* const
|
|
561
|
-
* const
|
|
562
|
-
* console.log(
|
|
696
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
697
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
698
|
+
* const image = fWorksheet.getImages()[0];
|
|
699
|
+
* const result = image?.setFront();
|
|
700
|
+
* console.log(result);
|
|
563
701
|
* ```
|
|
564
702
|
*/
|
|
565
703
|
setFront() {
|
|
@@ -571,13 +709,13 @@ let m = class extends V {
|
|
|
571
709
|
});
|
|
572
710
|
}
|
|
573
711
|
};
|
|
574
|
-
m =
|
|
575
|
-
|
|
576
|
-
|
|
712
|
+
m = N([
|
|
713
|
+
B(1, j),
|
|
714
|
+
B(2, U(P))
|
|
577
715
|
], m);
|
|
578
|
-
class
|
|
579
|
-
addFloatDomToPosition(
|
|
580
|
-
const i = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: s, disposableCollection: o } =
|
|
716
|
+
class ie extends z {
|
|
717
|
+
addFloatDomToPosition(r, t) {
|
|
718
|
+
const i = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: s, disposableCollection: o } = R(r, this._injector.get(G)), a = this._injector.get(D).addFloatDomToPosition({ ...r, componentKey: s, unitId: i, subUnitId: n }, t);
|
|
581
719
|
return a ? (o.add(a.dispose), {
|
|
582
720
|
id: a.id,
|
|
583
721
|
dispose: () => {
|
|
@@ -585,8 +723,8 @@ class se extends N {
|
|
|
585
723
|
}
|
|
586
724
|
}) : (o.dispose(), null);
|
|
587
725
|
}
|
|
588
|
-
addFloatDomToRange(
|
|
589
|
-
const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } =
|
|
726
|
+
addFloatDomToRange(r, t, i, n) {
|
|
727
|
+
const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } = R(t, this._injector.get(G)), c = this._injector.get(D).addFloatDomToRange(r.getRange(), { ...t, componentKey: d, unitId: s, subUnitId: o }, i, n);
|
|
590
728
|
return c ? (a.add(c.dispose), {
|
|
591
729
|
id: c.id,
|
|
592
730
|
dispose: () => {
|
|
@@ -594,8 +732,8 @@ class se extends N {
|
|
|
594
732
|
}
|
|
595
733
|
}) : (a.dispose(), null);
|
|
596
734
|
}
|
|
597
|
-
addFloatDomToColumnHeader(
|
|
598
|
-
const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } =
|
|
735
|
+
addFloatDomToColumnHeader(r, t, i, n) {
|
|
736
|
+
const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } = R(t, this._injector.get(G)), c = this._injector.get(D).addFloatDomToColumnHeader(r, { ...t, componentKey: d, unitId: s, subUnitId: o }, i, n);
|
|
599
737
|
return c ? (a.add(c.dispose), {
|
|
600
738
|
id: c.id,
|
|
601
739
|
dispose: () => {
|
|
@@ -603,100 +741,100 @@ class se extends N {
|
|
|
603
741
|
}
|
|
604
742
|
}) : (a.dispose(), null);
|
|
605
743
|
}
|
|
606
|
-
async insertImage(
|
|
744
|
+
async insertImage(r, t, i, n, s) {
|
|
607
745
|
const o = this.newOverGridImage();
|
|
608
|
-
if (typeof
|
|
609
|
-
o.setSource(
|
|
746
|
+
if (typeof r == "string")
|
|
747
|
+
o.setSource(r);
|
|
610
748
|
else {
|
|
611
|
-
const g = await
|
|
612
|
-
o.setSource(g,
|
|
749
|
+
const g = await r.getBlob().getDataAsString();
|
|
750
|
+
o.setSource(g, f.BASE64);
|
|
613
751
|
}
|
|
614
|
-
|
|
752
|
+
t !== void 0 ? o.setColumn(t) : o.setColumn(0), i !== void 0 ? o.setRow(i) : o.setRow(0), n !== void 0 ? o.setColumnOffset(n) : o.setColumnOffset(0), s !== void 0 ? o.setRowOffset(s) : o.setRowOffset(0);
|
|
615
753
|
const d = await o.buildAsync();
|
|
616
|
-
return this._commandService.syncExecuteCommand(
|
|
754
|
+
return this._commandService.syncExecuteCommand(p.id, { unitId: this._fWorkbook.getId(), drawings: [d] });
|
|
617
755
|
}
|
|
618
|
-
insertImages(
|
|
619
|
-
const
|
|
620
|
-
return this._commandService.syncExecuteCommand(
|
|
756
|
+
insertImages(r) {
|
|
757
|
+
const t = r.map((i) => (i.unitId = this._fWorkbook.getId(), i.subUnitId = this.getSheetId(), i));
|
|
758
|
+
return this._commandService.syncExecuteCommand(p.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
|
|
621
759
|
}
|
|
622
|
-
deleteImages(
|
|
623
|
-
const
|
|
760
|
+
deleteImages(r) {
|
|
761
|
+
const t = r.map((i) => ({
|
|
624
762
|
unitId: this._fWorkbook.getId(),
|
|
625
763
|
drawingId: i.getId(),
|
|
626
764
|
subUnitId: this.getSheetId(),
|
|
627
765
|
drawingType: i.getType()
|
|
628
766
|
}));
|
|
629
|
-
return this._commandService.syncExecuteCommand(
|
|
767
|
+
return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
|
|
630
768
|
}
|
|
631
769
|
getImages() {
|
|
632
|
-
const
|
|
633
|
-
for (const n in
|
|
634
|
-
const s =
|
|
770
|
+
const t = this._injector.get(l).getDrawingData(this._fWorkbook.getId(), this.getSheetId()), i = [];
|
|
771
|
+
for (const n in t) {
|
|
772
|
+
const s = t[n];
|
|
635
773
|
s.drawingType === _.DRAWING_IMAGE && i.push(this._injector.createInstance(m, s));
|
|
636
774
|
}
|
|
637
775
|
return i;
|
|
638
776
|
}
|
|
639
|
-
getImageById(
|
|
640
|
-
const i = this._injector.get(l).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId:
|
|
777
|
+
getImageById(r) {
|
|
778
|
+
const i = this._injector.get(l).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId: r });
|
|
641
779
|
return i && i.drawingType === _.DRAWING_IMAGE ? this._injector.createInstance(m, i) : null;
|
|
642
780
|
}
|
|
643
781
|
getActiveImages() {
|
|
644
|
-
const
|
|
645
|
-
for (const n in
|
|
646
|
-
const s =
|
|
782
|
+
const t = this._injector.get(l).getFocusDrawings(), i = [];
|
|
783
|
+
for (const n in t) {
|
|
784
|
+
const s = t[n];
|
|
647
785
|
i.push(this._injector.createInstance(m, s));
|
|
648
786
|
}
|
|
649
787
|
return i;
|
|
650
788
|
}
|
|
651
|
-
updateImages(
|
|
652
|
-
return this._commandService.syncExecuteCommand(h.id, { unitId: this._fWorkbook.getId(), drawings:
|
|
789
|
+
updateImages(r) {
|
|
790
|
+
return this._commandService.syncExecuteCommand(h.id, { unitId: this._fWorkbook.getId(), drawings: r }), this;
|
|
653
791
|
}
|
|
654
|
-
onImageInserted(
|
|
655
|
-
const
|
|
656
|
-
return
|
|
792
|
+
onImageInserted(r) {
|
|
793
|
+
const t = this._injector.get(l);
|
|
794
|
+
return y(t.add$.subscribe((i) => {
|
|
657
795
|
const n = i.map(
|
|
658
|
-
(s) => this._injector.createInstance(m,
|
|
796
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
659
797
|
);
|
|
660
|
-
|
|
798
|
+
r(n);
|
|
661
799
|
}));
|
|
662
800
|
}
|
|
663
|
-
onImageDeleted(
|
|
664
|
-
const
|
|
665
|
-
return
|
|
801
|
+
onImageDeleted(r) {
|
|
802
|
+
const t = this._injector.get(l);
|
|
803
|
+
return y(t.remove$.subscribe((i) => {
|
|
666
804
|
const n = i.map(
|
|
667
|
-
(s) => this._injector.createInstance(m,
|
|
805
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
668
806
|
);
|
|
669
|
-
|
|
807
|
+
r(n);
|
|
670
808
|
}));
|
|
671
809
|
}
|
|
672
|
-
onImageChanged(
|
|
673
|
-
const
|
|
674
|
-
return
|
|
810
|
+
onImageChanged(r) {
|
|
811
|
+
const t = this._injector.get(l);
|
|
812
|
+
return y(t.update$.subscribe((i) => {
|
|
675
813
|
const n = i.map(
|
|
676
|
-
(s) => this._injector.createInstance(m,
|
|
814
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
677
815
|
);
|
|
678
|
-
|
|
816
|
+
r(n);
|
|
679
817
|
}));
|
|
680
818
|
}
|
|
681
819
|
newOverGridImage() {
|
|
682
|
-
const
|
|
683
|
-
return this._injector.createInstance(
|
|
820
|
+
const r = this._fWorkbook.getId(), t = this.getSheetId();
|
|
821
|
+
return this._injector.createInstance(b, r, t);
|
|
684
822
|
}
|
|
685
823
|
}
|
|
686
|
-
|
|
687
|
-
class
|
|
824
|
+
z.extend(ie);
|
|
825
|
+
class ne extends W {
|
|
688
826
|
get DrawingType() {
|
|
689
827
|
return _;
|
|
690
828
|
}
|
|
691
829
|
get ImageSourceType() {
|
|
692
|
-
return
|
|
830
|
+
return f;
|
|
693
831
|
}
|
|
694
832
|
get SheetDrawingAnchorType() {
|
|
695
|
-
return
|
|
833
|
+
return Z;
|
|
696
834
|
}
|
|
697
835
|
}
|
|
698
|
-
|
|
699
|
-
class
|
|
836
|
+
W.extend(ne);
|
|
837
|
+
class se extends M {
|
|
700
838
|
get BeforeOverGridImageChange() {
|
|
701
839
|
return "BeforeOverGridImageChange";
|
|
702
840
|
}
|
|
@@ -722,18 +860,18 @@ class ae extends H {
|
|
|
722
860
|
return "OverGridImageSelected";
|
|
723
861
|
}
|
|
724
862
|
}
|
|
725
|
-
|
|
726
|
-
class
|
|
863
|
+
M.extend(se);
|
|
864
|
+
class oe extends H {
|
|
727
865
|
/**
|
|
728
866
|
* @ignore
|
|
729
867
|
*/
|
|
730
868
|
// eslint-disable-next-line max-lines-per-function
|
|
731
|
-
_initialize(
|
|
732
|
-
const
|
|
869
|
+
_initialize(r) {
|
|
870
|
+
const t = r.get(j);
|
|
733
871
|
this.registerEventHandler(
|
|
734
872
|
this.Event.BeforeOverGridImageInsert,
|
|
735
|
-
() =>
|
|
736
|
-
if (i.id !==
|
|
873
|
+
() => t.beforeCommandExecuted((i) => {
|
|
874
|
+
if (i.id !== p.id) return;
|
|
737
875
|
const n = i.params, s = this.getActiveWorkbook();
|
|
738
876
|
if (s == null || n == null)
|
|
739
877
|
return;
|
|
@@ -746,12 +884,12 @@ class de extends z {
|
|
|
746
884
|
})
|
|
747
885
|
), this.registerEventHandler(
|
|
748
886
|
this.Event.BeforeOverGridImageRemove,
|
|
749
|
-
() =>
|
|
750
|
-
if (i.id !==
|
|
887
|
+
() => t.beforeCommandExecuted((i) => {
|
|
888
|
+
if (i.id !== S.id) return;
|
|
751
889
|
const n = i.params, s = this.getActiveWorkbook();
|
|
752
890
|
if (s == null || n == null)
|
|
753
891
|
return;
|
|
754
|
-
const o =
|
|
892
|
+
const o = r.get(I), { drawings: d } = n, a = d.map((c) => o.getDrawingByParam(c)), g = {
|
|
755
893
|
workbook: s,
|
|
756
894
|
images: this._createFOverGridImage(a)
|
|
757
895
|
};
|
|
@@ -760,12 +898,12 @@ class de extends z {
|
|
|
760
898
|
})
|
|
761
899
|
), this.registerEventHandler(
|
|
762
900
|
this.Event.BeforeOverGridImageChange,
|
|
763
|
-
() =>
|
|
901
|
+
() => t.beforeCommandExecuted((i) => {
|
|
764
902
|
if (i.id !== h.id) return;
|
|
765
903
|
const n = i.params, s = this.getActiveWorkbook();
|
|
766
904
|
if (s == null || n == null)
|
|
767
905
|
return;
|
|
768
|
-
const { drawings: o } = n, d =
|
|
906
|
+
const { drawings: o } = n, d = r.get(I), a = [];
|
|
769
907
|
o.forEach((c) => {
|
|
770
908
|
const u = d.getDrawingByParam(c);
|
|
771
909
|
u != null && a.push({
|
|
@@ -782,12 +920,12 @@ class de extends z {
|
|
|
782
920
|
})
|
|
783
921
|
), this.registerEventHandler(
|
|
784
922
|
this.Event.BeforeOverGridImageSelect,
|
|
785
|
-
() =>
|
|
786
|
-
if (i.id !==
|
|
923
|
+
() => t.beforeCommandExecuted((i) => {
|
|
924
|
+
if (i.id !== x.id) return;
|
|
787
925
|
const n = i.params, s = this.getActiveWorkbook();
|
|
788
926
|
if (s == null)
|
|
789
927
|
return;
|
|
790
|
-
const o =
|
|
928
|
+
const o = r.get(I), d = o.getFocusDrawings(), a = n.map((c) => o.getDrawingByParam(c)), g = {
|
|
791
929
|
workbook: s,
|
|
792
930
|
selectedImages: this._createFOverGridImage(a),
|
|
793
931
|
oldSelectedImages: this._createFOverGridImage(d)
|
|
@@ -797,8 +935,8 @@ class de extends z {
|
|
|
797
935
|
})
|
|
798
936
|
), this.registerEventHandler(
|
|
799
937
|
this.Event.OverGridImageInserted,
|
|
800
|
-
() =>
|
|
801
|
-
if (i.id !==
|
|
938
|
+
() => t.onCommandExecuted((i) => {
|
|
939
|
+
if (i.id !== p.id) return;
|
|
802
940
|
const n = i.params, s = this.getActiveWorkbook();
|
|
803
941
|
if (s == null || n == null)
|
|
804
942
|
return;
|
|
@@ -810,8 +948,8 @@ class de extends z {
|
|
|
810
948
|
})
|
|
811
949
|
), this.registerEventHandler(
|
|
812
950
|
this.Event.OverGridImageRemoved,
|
|
813
|
-
() =>
|
|
814
|
-
if (i.id !==
|
|
951
|
+
() => t.onCommandExecuted((i) => {
|
|
952
|
+
if (i.id !== S.id) return;
|
|
815
953
|
const n = i.params, s = this.getActiveWorkbook();
|
|
816
954
|
if (s == null || n == null)
|
|
817
955
|
return;
|
|
@@ -823,12 +961,12 @@ class de extends z {
|
|
|
823
961
|
})
|
|
824
962
|
), this.registerEventHandler(
|
|
825
963
|
this.Event.OverGridImageChanged,
|
|
826
|
-
() =>
|
|
964
|
+
() => t.onCommandExecuted((i) => {
|
|
827
965
|
if (i.id !== h.id) return;
|
|
828
966
|
const n = i.params, s = this.getActiveWorkbook();
|
|
829
967
|
if (s == null || n == null)
|
|
830
968
|
return;
|
|
831
|
-
const { drawings: o } = n, d =
|
|
969
|
+
const { drawings: o } = n, d = r.get(I), a = o.map((g) => this._injector.createInstance(m, d.getDrawingByParam(g)));
|
|
832
970
|
this.fireEvent(this.Event.OverGridImageChanged, {
|
|
833
971
|
workbook: s,
|
|
834
972
|
images: a
|
|
@@ -836,12 +974,12 @@ class de extends z {
|
|
|
836
974
|
})
|
|
837
975
|
), this.registerEventHandler(
|
|
838
976
|
this.Event.OverGridImageSelected,
|
|
839
|
-
() =>
|
|
840
|
-
if (i.id !==
|
|
977
|
+
() => t.onCommandExecuted((i) => {
|
|
978
|
+
if (i.id !== x.id) return;
|
|
841
979
|
const n = i.params, s = this.getActiveWorkbook();
|
|
842
980
|
if (s == null)
|
|
843
981
|
return;
|
|
844
|
-
const o =
|
|
982
|
+
const o = r.get(I), d = n.map((a) => o.getDrawingByParam(a));
|
|
845
983
|
this.fireEvent(this.Event.OverGridImageSelected, {
|
|
846
984
|
workbook: s,
|
|
847
985
|
selectedImages: this._createFOverGridImage(d)
|
|
@@ -849,8 +987,8 @@ class de extends z {
|
|
|
849
987
|
})
|
|
850
988
|
);
|
|
851
989
|
}
|
|
852
|
-
_createFOverGridImage(
|
|
853
|
-
return
|
|
990
|
+
_createFOverGridImage(r) {
|
|
991
|
+
return r.map((t) => this._injector.createInstance(m, t));
|
|
854
992
|
}
|
|
855
993
|
}
|
|
856
|
-
|
|
994
|
+
H.extend(oe);
|