@univerjs/sheets-drawing-ui 0.6.7 → 0.6.9
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/facade.js +1010 -0
- package/lib/index.js +3656 -0
- package/lib/locale/en-US.js +49 -0
- package/lib/locale/fa-IR.js +49 -0
- package/lib/locale/fr-FR.js +49 -0
- package/lib/locale/ru-RU.js +49 -0
- package/lib/locale/vi-VN.js +49 -0
- package/lib/locale/zh-CN.js +49 -0
- package/lib/locale/zh-TW.js +49 -0
- package/package.json +15 -15
package/lib/facade.js
ADDED
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var V = (r, e, t) => e in r ? L(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var U = (r, e, t) => V(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Inject as A, Injector as j, ICommandService as P, ImageSourceType as f, ArrangeTypeEnum as v, DrawingTypeEnum as _, generateRandomId as X, toDisposable as y, UniverInstanceType as Y, IUniverInstanceService as q } from "@univerjs/core";
|
|
5
|
+
import { FBase as J, FEnum as W, FEventName as M, FUniver as H } from "@univerjs/core/facade";
|
|
6
|
+
import { getImageSize as Q, IDrawingManagerService as I, SetDrawingSelectedOperation as x } from "@univerjs/drawing";
|
|
7
|
+
import { IRenderManagerService as B, getCurrentTypeOfRenderer as Z } from "@univerjs/engine-render";
|
|
8
|
+
import { RemoveSheetDrawingCommand as S, SetSheetDrawingCommand as h, SetDrawingArrangeCommand as w, SheetCanvasFloatDomManagerService as D, InsertSheetDrawingCommand as p, SheetDrawingUpdateController as ee } from "@univerjs/sheets-drawing-ui";
|
|
9
|
+
import { SheetSkeletonManagerService as F, ISheetSelectionRenderService as te, convertPositionSheetOverGridToAbsolute as re, convertPositionCellToSheetOverGrid as ie } from "@univerjs/sheets-ui";
|
|
10
|
+
import { ISheetDrawingService as l, SheetDrawingAnchorType as ne } from "@univerjs/sheets-drawing";
|
|
11
|
+
import { transformComponentKey as R } from "@univerjs/sheets-ui/facade";
|
|
12
|
+
import { FWorksheet as z, FRange as N } from "@univerjs/sheets/facade";
|
|
13
|
+
import { ComponentManager as G } from "@univerjs/ui";
|
|
14
|
+
var se = Object.getOwnPropertyDescriptor, $ = (r, e, t, i) => {
|
|
15
|
+
for (var n = i > 1 ? void 0 : i ? se(e, t) : e, s = r.length - 1, o; s >= 0; s--)
|
|
16
|
+
(o = r[s]) && (n = o(n) || n);
|
|
17
|
+
return n;
|
|
18
|
+
}, T = (r, e) => (t, i) => e(t, i, r);
|
|
19
|
+
function oe(r, e) {
|
|
20
|
+
const { from: t, to: i, flipY: n = !1, flipX: s = !1, angle: o = 0, skewX: d = 0, skewY: a = 0 } = r.sheetTransform, { column: g, columnOffset: c, row: u, rowOffset: O } = t, k = re(
|
|
21
|
+
r.unitId,
|
|
22
|
+
r.subUnitId,
|
|
23
|
+
{ from: t, to: i },
|
|
24
|
+
e
|
|
25
|
+
), { width: E, height: C } = k;
|
|
26
|
+
return {
|
|
27
|
+
...r,
|
|
28
|
+
column: g,
|
|
29
|
+
columnOffset: c,
|
|
30
|
+
row: u,
|
|
31
|
+
rowOffset: O,
|
|
32
|
+
width: E,
|
|
33
|
+
height: C,
|
|
34
|
+
flipY: n,
|
|
35
|
+
flipX: s,
|
|
36
|
+
angle: o,
|
|
37
|
+
skewX: d,
|
|
38
|
+
skewY: a
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function ae(r, e, 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 } = r, E = ie(
|
|
43
|
+
r.unitId,
|
|
44
|
+
r.subUnitId,
|
|
45
|
+
{ column: i, columnOffset: n, row: s, rowOffset: o },
|
|
46
|
+
O,
|
|
47
|
+
k,
|
|
48
|
+
e,
|
|
49
|
+
t
|
|
50
|
+
), { sheetTransform: C, transform: K } = E;
|
|
51
|
+
return {
|
|
52
|
+
...r,
|
|
53
|
+
sheetTransform: {
|
|
54
|
+
...C,
|
|
55
|
+
flipY: d,
|
|
56
|
+
flipX: a,
|
|
57
|
+
angle: g,
|
|
58
|
+
skewX: c,
|
|
59
|
+
skewY: u
|
|
60
|
+
},
|
|
61
|
+
transform: {
|
|
62
|
+
...K,
|
|
63
|
+
flipY: d,
|
|
64
|
+
flipX: a,
|
|
65
|
+
angle: g,
|
|
66
|
+
skewX: c,
|
|
67
|
+
skewY: u
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
let b = class {
|
|
72
|
+
constructor(r, e, t) {
|
|
73
|
+
U(this, "_image");
|
|
74
|
+
this._injector = t, this._image = {
|
|
75
|
+
drawingId: X(6),
|
|
76
|
+
drawingType: _.DRAWING_IMAGE,
|
|
77
|
+
imageSourceType: f.BASE64,
|
|
78
|
+
source: "",
|
|
79
|
+
unitId: r,
|
|
80
|
+
subUnitId: e,
|
|
81
|
+
column: 0,
|
|
82
|
+
columnOffset: 0,
|
|
83
|
+
row: 0,
|
|
84
|
+
rowOffset: 0,
|
|
85
|
+
width: 0,
|
|
86
|
+
height: 0
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set the initial image configuration for the image builder.
|
|
91
|
+
* @param {ISheetImage} image - The image configuration
|
|
92
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
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]);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
setImage(r) {
|
|
115
|
+
const t = this._injector.get(B).getRenderById(r.unitId);
|
|
116
|
+
if (!t)
|
|
117
|
+
throw new Error(`Render Unit with unitId ${r.unitId} not found`);
|
|
118
|
+
const i = t.with(F);
|
|
119
|
+
return r.sheetTransform == null && (r.sheetTransform = {
|
|
120
|
+
from: {
|
|
121
|
+
column: 0,
|
|
122
|
+
columnOffset: 0,
|
|
123
|
+
row: 0,
|
|
124
|
+
rowOffset: 0
|
|
125
|
+
},
|
|
126
|
+
to: {
|
|
127
|
+
column: 0,
|
|
128
|
+
columnOffset: 0,
|
|
129
|
+
row: 0,
|
|
130
|
+
rowOffset: 0
|
|
131
|
+
}
|
|
132
|
+
}), this._image = oe(r, i), this;
|
|
133
|
+
}
|
|
134
|
+
setSource(r, e) {
|
|
135
|
+
const t = e != null ? e : f.URL;
|
|
136
|
+
return this._image.source = r, this._image.imageSourceType = t, this;
|
|
137
|
+
}
|
|
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() {
|
|
152
|
+
return this._image.source;
|
|
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
|
+
*/
|
|
167
|
+
getSourceType() {
|
|
168
|
+
return this._image.imageSourceType;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set the horizontal position of the image
|
|
172
|
+
* @param {number} column - The column index of the image start position, start at 0
|
|
173
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
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]);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
setColumn(r) {
|
|
189
|
+
return this._image.column = r, this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Set the vertical position of the image
|
|
193
|
+
* @param {number} row - The row index of the image start position, start at 0
|
|
194
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
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]);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
setRow(r) {
|
|
210
|
+
return this._image.row = r, this;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
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
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
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]);
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
setColumnOffset(r) {
|
|
232
|
+
return this._image.columnOffset = r, this;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
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
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
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]);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
setRowOffset(r) {
|
|
254
|
+
return this._image.rowOffset = r, this;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
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
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
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]);
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
setWidth(r) {
|
|
277
|
+
return this._image.width = r, this;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Set the height of the image
|
|
281
|
+
* @param {number} height - The height of the image, pixel unit
|
|
282
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
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]);
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
setHeight(r) {
|
|
300
|
+
return this._image.height = r, this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Set the anchor type of the image, whether the position and size change with the cell
|
|
304
|
+
* @param {SheetDrawingAnchorType} anchorType - The anchor type of the image
|
|
305
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
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);
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
setAnchorType(r) {
|
|
349
|
+
return this._image.anchorType = r, this;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
|
|
353
|
+
* @param {number} top - The number of pixels to crop from the top of the image
|
|
354
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
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]);
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
setCropTop(r) {
|
|
371
|
+
return this._initializeSrcRect(), this._image.srcRect.top = r, this;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
|
|
375
|
+
* @param {number} left - The number of pixels to crop from the left side of the image
|
|
376
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
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]);
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
setCropLeft(r) {
|
|
393
|
+
return this._initializeSrcRect(), this._image.srcRect.left = r, this;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
|
|
397
|
+
* @param {number} bottom - The number of pixels to crop from the bottom of the image
|
|
398
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
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]);
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
setCropBottom(r) {
|
|
415
|
+
return this._initializeSrcRect(), this._image.srcRect.bottom = r, this;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
|
|
419
|
+
* @param {number} right - The number of pixels to crop from the right side of the image
|
|
420
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
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]);
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
setCropRight(r) {
|
|
437
|
+
return this._initializeSrcRect(), this._image.srcRect.right = r, this;
|
|
438
|
+
}
|
|
439
|
+
_initializeSrcRect() {
|
|
440
|
+
this._image.srcRect == null && (this._image.srcRect = {
|
|
441
|
+
top: 0,
|
|
442
|
+
left: 0,
|
|
443
|
+
bottom: 0,
|
|
444
|
+
right: 0
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Set the rotation angle of the image
|
|
449
|
+
* @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
|
|
450
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
451
|
+
* @example
|
|
452
|
+
* ```ts
|
|
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]);
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
setRotate(r) {
|
|
467
|
+
return this._image.angle = r, this;
|
|
468
|
+
}
|
|
469
|
+
setUnitId(r) {
|
|
470
|
+
return this._image.unitId = r, this;
|
|
471
|
+
}
|
|
472
|
+
setSubUnitId(r) {
|
|
473
|
+
return this._image.subUnitId = r, this;
|
|
474
|
+
}
|
|
475
|
+
async buildAsync() {
|
|
476
|
+
const e = this._injector.get(B).getRenderById(this._image.unitId);
|
|
477
|
+
if (!e)
|
|
478
|
+
throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
|
|
479
|
+
const t = e.with(te), i = e.with(F);
|
|
480
|
+
if (this._image.width === 0 || this._image.height === 0) {
|
|
481
|
+
const n = await Q(this._image.source), s = n.width, o = n.height;
|
|
482
|
+
this._image.width === 0 && (this._image.width = s), this._image.height === 0 && (this._image.height = o);
|
|
483
|
+
}
|
|
484
|
+
return ae(this._image, t, i);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
b = $([
|
|
488
|
+
T(2, A(j))
|
|
489
|
+
], b);
|
|
490
|
+
let m = class extends J {
|
|
491
|
+
constructor(r, e, t) {
|
|
492
|
+
super(), this._image = r, this._commandService = e, this._injector = t;
|
|
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
|
+
*/
|
|
507
|
+
getId() {
|
|
508
|
+
return this._image.drawingId;
|
|
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
|
+
*/
|
|
523
|
+
getType() {
|
|
524
|
+
return this._image.drawingType;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Remove the image from the sheet
|
|
528
|
+
* @returns {boolean} true if the image is removed successfully, otherwise false
|
|
529
|
+
* @example
|
|
530
|
+
* ```ts
|
|
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);
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
remove() {
|
|
539
|
+
return this._commandService.syncExecuteCommand(S.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Convert the image to a FOverGridImageBuilder
|
|
543
|
+
* @returns {FOverGridImageBuilder} The builder FOverGridImageBuilder
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
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
|
+
* });
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
toBuilder() {
|
|
555
|
+
const r = this._injector.createInstance(b);
|
|
556
|
+
return r.setImage(this._image), r;
|
|
557
|
+
}
|
|
558
|
+
setSource(r, e) {
|
|
559
|
+
const t = e != null ? e : f.URL;
|
|
560
|
+
return this._image.source = r, this._image.imageSourceType = t, this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
561
|
+
}
|
|
562
|
+
async setPositionAsync(r, e, t, i) {
|
|
563
|
+
const n = this.toBuilder();
|
|
564
|
+
n.setColumn(e), n.setRow(r), t != null && n.setRowOffset(t), i != null && n.setColumnOffset(i);
|
|
565
|
+
const s = await n.buildAsync();
|
|
566
|
+
return this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [s] });
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Set the size of the image
|
|
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
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
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
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
async setSizeAsync(r, e) {
|
|
584
|
+
const t = this.toBuilder();
|
|
585
|
+
t.setWidth(r), t.setHeight(e);
|
|
586
|
+
const i = await t.buildAsync();
|
|
587
|
+
return this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [i] });
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
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.
|
|
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
|
|
596
|
+
* @example
|
|
597
|
+
* ```ts
|
|
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);
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
setCrop(r, e, t, i) {
|
|
607
|
+
return this._image.srcRect == null && (this._image.srcRect = {
|
|
608
|
+
top: 0,
|
|
609
|
+
left: 0,
|
|
610
|
+
bottom: 0,
|
|
611
|
+
right: 0
|
|
612
|
+
}), r != null && (this._image.srcRect.top = r), e != null && (this._image.srcRect.left = e), 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] });
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Set the rotation angle of the image
|
|
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
|
|
618
|
+
* @example
|
|
619
|
+
* ```ts
|
|
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);
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
setRotate(r) {
|
|
629
|
+
return this._image.sheetTransform.angle = r, this._image.transform && (this._image.transform.angle = r), this._commandService.syncExecuteCommand(h.id, { unitId: this._image.unitId, drawings: [this._image] });
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Move the image layer forward by one level
|
|
633
|
+
* @returns {boolean} true if the image is moved forward successfully, otherwise false
|
|
634
|
+
* @example
|
|
635
|
+
* ```ts
|
|
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);
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
setForward() {
|
|
644
|
+
return this._commandService.syncExecuteCommand(w.id, {
|
|
645
|
+
unitId: this._image.unitId,
|
|
646
|
+
subUnitId: this._image.subUnitId,
|
|
647
|
+
drawingIds: [this._image.drawingId],
|
|
648
|
+
arrangeType: v.forward
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Move the image layer backward by one level
|
|
653
|
+
* @returns {boolean} true if the image is moved backward successfully, otherwise false
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
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);
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
setBackward() {
|
|
664
|
+
return this._commandService.syncExecuteCommand(w.id, {
|
|
665
|
+
unitId: this._image.unitId,
|
|
666
|
+
subUnitId: this._image.subUnitId,
|
|
667
|
+
drawingIds: [this._image.drawingId],
|
|
668
|
+
arrangeType: v.backward
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Move the image layer to the bottom layer
|
|
673
|
+
* @returns {boolean} true if the image is moved to the bottom layer successfully, otherwise false
|
|
674
|
+
* @example
|
|
675
|
+
* ```ts
|
|
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);
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
setBack() {
|
|
684
|
+
return this._commandService.syncExecuteCommand(w.id, {
|
|
685
|
+
unitId: this._image.unitId,
|
|
686
|
+
subUnitId: this._image.subUnitId,
|
|
687
|
+
drawingIds: [this._image.drawingId],
|
|
688
|
+
arrangeType: v.back
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Move the image layer to the top layer
|
|
693
|
+
* @returns {boolean} true if the image is moved to the top layer successfully, otherwise false
|
|
694
|
+
* @example
|
|
695
|
+
* ```ts
|
|
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);
|
|
701
|
+
* ```
|
|
702
|
+
*/
|
|
703
|
+
setFront() {
|
|
704
|
+
return this._commandService.syncExecuteCommand(w.id, {
|
|
705
|
+
unitId: this._image.unitId,
|
|
706
|
+
subUnitId: this._image.subUnitId,
|
|
707
|
+
drawingIds: [this._image.drawingId],
|
|
708
|
+
arrangeType: v.front
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
m = $([
|
|
713
|
+
T(1, P),
|
|
714
|
+
T(2, A(j))
|
|
715
|
+
], m);
|
|
716
|
+
class de extends z {
|
|
717
|
+
addFloatDomToPosition(e, t) {
|
|
718
|
+
const i = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: s, disposableCollection: o } = R(e, this._injector.get(G)), a = this._injector.get(D).addFloatDomToPosition({ ...e, componentKey: s, unitId: i, subUnitId: n }, t);
|
|
719
|
+
return a ? (o.add(a.dispose), {
|
|
720
|
+
id: a.id,
|
|
721
|
+
dispose: () => {
|
|
722
|
+
o.dispose(), a.dispose();
|
|
723
|
+
}
|
|
724
|
+
}) : (o.dispose(), null);
|
|
725
|
+
}
|
|
726
|
+
addFloatDomToRange(e, 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(e.getRange(), { ...t, componentKey: d, unitId: s, subUnitId: o }, i, n);
|
|
728
|
+
return c ? (a.add(c.dispose), {
|
|
729
|
+
id: c.id,
|
|
730
|
+
dispose: () => {
|
|
731
|
+
a.dispose(), c.dispose();
|
|
732
|
+
}
|
|
733
|
+
}) : (a.dispose(), null);
|
|
734
|
+
}
|
|
735
|
+
addFloatDomToColumnHeader(e, 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(e, { ...t, componentKey: d, unitId: s, subUnitId: o }, i, n);
|
|
737
|
+
return c ? (a.add(c.dispose), {
|
|
738
|
+
id: c.id,
|
|
739
|
+
dispose: () => {
|
|
740
|
+
a.dispose(), c.dispose();
|
|
741
|
+
}
|
|
742
|
+
}) : (a.dispose(), null);
|
|
743
|
+
}
|
|
744
|
+
async insertImage(e, t, i, n, s) {
|
|
745
|
+
const o = this.newOverGridImage();
|
|
746
|
+
if (typeof e == "string")
|
|
747
|
+
o.setSource(e);
|
|
748
|
+
else {
|
|
749
|
+
const g = await e.getBlob().getDataAsString();
|
|
750
|
+
o.setSource(g, f.BASE64);
|
|
751
|
+
}
|
|
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);
|
|
753
|
+
const d = await o.buildAsync();
|
|
754
|
+
return this._commandService.syncExecuteCommand(p.id, { unitId: this._fWorkbook.getId(), drawings: [d] });
|
|
755
|
+
}
|
|
756
|
+
insertImages(e) {
|
|
757
|
+
const t = e.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;
|
|
759
|
+
}
|
|
760
|
+
deleteImages(e) {
|
|
761
|
+
const t = e.map((i) => ({
|
|
762
|
+
unitId: this._fWorkbook.getId(),
|
|
763
|
+
drawingId: i.getId(),
|
|
764
|
+
subUnitId: this.getSheetId(),
|
|
765
|
+
drawingType: i.getType()
|
|
766
|
+
}));
|
|
767
|
+
return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
|
|
768
|
+
}
|
|
769
|
+
getImages() {
|
|
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];
|
|
773
|
+
s.drawingType === _.DRAWING_IMAGE && i.push(this._injector.createInstance(m, s));
|
|
774
|
+
}
|
|
775
|
+
return i;
|
|
776
|
+
}
|
|
777
|
+
getImageById(e) {
|
|
778
|
+
const i = this._injector.get(l).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId: e });
|
|
779
|
+
return i && i.drawingType === _.DRAWING_IMAGE ? this._injector.createInstance(m, i) : null;
|
|
780
|
+
}
|
|
781
|
+
getActiveImages() {
|
|
782
|
+
const t = this._injector.get(l).getFocusDrawings(), i = [];
|
|
783
|
+
for (const n in t) {
|
|
784
|
+
const s = t[n];
|
|
785
|
+
i.push(this._injector.createInstance(m, s));
|
|
786
|
+
}
|
|
787
|
+
return i;
|
|
788
|
+
}
|
|
789
|
+
updateImages(e) {
|
|
790
|
+
return this._commandService.syncExecuteCommand(h.id, { unitId: this._fWorkbook.getId(), drawings: e }), this;
|
|
791
|
+
}
|
|
792
|
+
onImageInserted(e) {
|
|
793
|
+
const t = this._injector.get(l);
|
|
794
|
+
return y(t.add$.subscribe((i) => {
|
|
795
|
+
const n = i.map(
|
|
796
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
797
|
+
);
|
|
798
|
+
e(n);
|
|
799
|
+
}));
|
|
800
|
+
}
|
|
801
|
+
onImageDeleted(e) {
|
|
802
|
+
const t = this._injector.get(l);
|
|
803
|
+
return y(t.remove$.subscribe((i) => {
|
|
804
|
+
const n = i.map(
|
|
805
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
806
|
+
);
|
|
807
|
+
e(n);
|
|
808
|
+
}));
|
|
809
|
+
}
|
|
810
|
+
onImageChanged(e) {
|
|
811
|
+
const t = this._injector.get(l);
|
|
812
|
+
return y(t.update$.subscribe((i) => {
|
|
813
|
+
const n = i.map(
|
|
814
|
+
(s) => this._injector.createInstance(m, t.getDrawingByParam(s))
|
|
815
|
+
);
|
|
816
|
+
e(n);
|
|
817
|
+
}));
|
|
818
|
+
}
|
|
819
|
+
newOverGridImage() {
|
|
820
|
+
const e = this._fWorkbook.getId(), t = this.getSheetId();
|
|
821
|
+
return this._injector.createInstance(b, e, t);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
z.extend(de);
|
|
825
|
+
class ce extends W {
|
|
826
|
+
get DrawingType() {
|
|
827
|
+
return _;
|
|
828
|
+
}
|
|
829
|
+
get ImageSourceType() {
|
|
830
|
+
return f;
|
|
831
|
+
}
|
|
832
|
+
get SheetDrawingAnchorType() {
|
|
833
|
+
return ne;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
W.extend(ce);
|
|
837
|
+
class ge extends M {
|
|
838
|
+
get BeforeOverGridImageChange() {
|
|
839
|
+
return "BeforeOverGridImageChange";
|
|
840
|
+
}
|
|
841
|
+
get OverGridImageChanged() {
|
|
842
|
+
return "OverGridImageChanged";
|
|
843
|
+
}
|
|
844
|
+
get BeforeOverGridImageInsert() {
|
|
845
|
+
return "BeforeOverGridImageInsert";
|
|
846
|
+
}
|
|
847
|
+
get OverGridImageInserted() {
|
|
848
|
+
return "OverGridImageInserted";
|
|
849
|
+
}
|
|
850
|
+
get BeforeOverGridImageRemove() {
|
|
851
|
+
return "BeforeOverGridImageRemove";
|
|
852
|
+
}
|
|
853
|
+
get OverGridImageRemoved() {
|
|
854
|
+
return "OverGridImageRemoved";
|
|
855
|
+
}
|
|
856
|
+
get BeforeOverGridImageSelect() {
|
|
857
|
+
return "BeforeOverGridImageSelect";
|
|
858
|
+
}
|
|
859
|
+
get OverGridImageSelected() {
|
|
860
|
+
return "OverGridImageSelected";
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
M.extend(ge);
|
|
864
|
+
class me extends H {
|
|
865
|
+
/**
|
|
866
|
+
* @ignore
|
|
867
|
+
*/
|
|
868
|
+
// eslint-disable-next-line max-lines-per-function
|
|
869
|
+
_initialize(e) {
|
|
870
|
+
const t = e.get(P);
|
|
871
|
+
this.registerEventHandler(
|
|
872
|
+
this.Event.BeforeOverGridImageInsert,
|
|
873
|
+
() => t.beforeCommandExecuted((i) => {
|
|
874
|
+
if (i.id !== p.id) return;
|
|
875
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
876
|
+
if (s == null || n == null)
|
|
877
|
+
return;
|
|
878
|
+
const { drawings: o } = n, d = {
|
|
879
|
+
workbook: s,
|
|
880
|
+
insertImageParams: o
|
|
881
|
+
};
|
|
882
|
+
if (this.fireEvent(this.Event.BeforeOverGridImageInsert, d), d.cancel)
|
|
883
|
+
throw new Error("Canceled by BeforeOverGridImageInsert event");
|
|
884
|
+
})
|
|
885
|
+
), this.registerEventHandler(
|
|
886
|
+
this.Event.BeforeOverGridImageRemove,
|
|
887
|
+
() => t.beforeCommandExecuted((i) => {
|
|
888
|
+
if (i.id !== S.id) return;
|
|
889
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
890
|
+
if (s == null || n == null)
|
|
891
|
+
return;
|
|
892
|
+
const o = e.get(I), { drawings: d } = n, a = d.map((c) => o.getDrawingByParam(c)), g = {
|
|
893
|
+
workbook: s,
|
|
894
|
+
images: this._createFOverGridImage(a)
|
|
895
|
+
};
|
|
896
|
+
if (this.fireEvent(this.Event.BeforeOverGridImageRemove, g), g.cancel)
|
|
897
|
+
throw new Error("Canceled by BeforeOverGridImageRemove event");
|
|
898
|
+
})
|
|
899
|
+
), this.registerEventHandler(
|
|
900
|
+
this.Event.BeforeOverGridImageChange,
|
|
901
|
+
() => t.beforeCommandExecuted((i) => {
|
|
902
|
+
if (i.id !== h.id) return;
|
|
903
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
904
|
+
if (s == null || n == null)
|
|
905
|
+
return;
|
|
906
|
+
const { drawings: o } = n, d = e.get(I), a = [];
|
|
907
|
+
o.forEach((c) => {
|
|
908
|
+
const u = d.getDrawingByParam(c);
|
|
909
|
+
u != null && a.push({
|
|
910
|
+
changeParam: c,
|
|
911
|
+
image: this._injector.createInstance(m, u)
|
|
912
|
+
});
|
|
913
|
+
});
|
|
914
|
+
const g = {
|
|
915
|
+
workbook: s,
|
|
916
|
+
images: a
|
|
917
|
+
};
|
|
918
|
+
if (this.fireEvent(this.Event.BeforeOverGridImageChange, g), g.cancel)
|
|
919
|
+
throw d.updateNotification(o), new Error("Canceled by BeforeOverGridImageChange event");
|
|
920
|
+
})
|
|
921
|
+
), this.registerEventHandler(
|
|
922
|
+
this.Event.BeforeOverGridImageSelect,
|
|
923
|
+
() => t.beforeCommandExecuted((i) => {
|
|
924
|
+
if (i.id !== x.id) return;
|
|
925
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
926
|
+
if (s == null)
|
|
927
|
+
return;
|
|
928
|
+
const o = e.get(I), d = o.getFocusDrawings(), a = n.map((c) => o.getDrawingByParam(c)), g = {
|
|
929
|
+
workbook: s,
|
|
930
|
+
selectedImages: this._createFOverGridImage(a),
|
|
931
|
+
oldSelectedImages: this._createFOverGridImage(d)
|
|
932
|
+
};
|
|
933
|
+
if (this.fireEvent(this.Event.BeforeOverGridImageSelect, g), g.cancel)
|
|
934
|
+
throw new Error("Canceled by BeforeOverGridImageSelect event");
|
|
935
|
+
})
|
|
936
|
+
), this.registerEventHandler(
|
|
937
|
+
this.Event.OverGridImageInserted,
|
|
938
|
+
() => t.onCommandExecuted((i) => {
|
|
939
|
+
if (i.id !== p.id) return;
|
|
940
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
941
|
+
if (s == null || n == null)
|
|
942
|
+
return;
|
|
943
|
+
const { drawings: o } = n;
|
|
944
|
+
this.fireEvent(this.Event.OverGridImageInserted, {
|
|
945
|
+
workbook: s,
|
|
946
|
+
images: this._createFOverGridImage(o)
|
|
947
|
+
});
|
|
948
|
+
})
|
|
949
|
+
), this.registerEventHandler(
|
|
950
|
+
this.Event.OverGridImageRemoved,
|
|
951
|
+
() => t.onCommandExecuted((i) => {
|
|
952
|
+
if (i.id !== S.id) return;
|
|
953
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
954
|
+
if (s == null || n == null)
|
|
955
|
+
return;
|
|
956
|
+
const { drawings: o } = n;
|
|
957
|
+
this.fireEvent(this.Event.OverGridImageRemoved, {
|
|
958
|
+
workbook: s,
|
|
959
|
+
removeImageParams: o
|
|
960
|
+
});
|
|
961
|
+
})
|
|
962
|
+
), this.registerEventHandler(
|
|
963
|
+
this.Event.OverGridImageChanged,
|
|
964
|
+
() => t.onCommandExecuted((i) => {
|
|
965
|
+
if (i.id !== h.id) return;
|
|
966
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
967
|
+
if (s == null || n == null)
|
|
968
|
+
return;
|
|
969
|
+
const { drawings: o } = n, d = e.get(I), a = o.map((g) => this._injector.createInstance(m, d.getDrawingByParam(g)));
|
|
970
|
+
this.fireEvent(this.Event.OverGridImageChanged, {
|
|
971
|
+
workbook: s,
|
|
972
|
+
images: a
|
|
973
|
+
});
|
|
974
|
+
})
|
|
975
|
+
), this.registerEventHandler(
|
|
976
|
+
this.Event.OverGridImageSelected,
|
|
977
|
+
() => t.onCommandExecuted((i) => {
|
|
978
|
+
if (i.id !== x.id) return;
|
|
979
|
+
const n = i.params, s = this.getActiveWorkbook();
|
|
980
|
+
if (s == null)
|
|
981
|
+
return;
|
|
982
|
+
const o = e.get(I), d = n.map((a) => o.getDrawingByParam(a));
|
|
983
|
+
this.fireEvent(this.Event.OverGridImageSelected, {
|
|
984
|
+
workbook: s,
|
|
985
|
+
selectedImages: this._createFOverGridImage(d)
|
|
986
|
+
});
|
|
987
|
+
})
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
_createFOverGridImage(e) {
|
|
991
|
+
return e.map((t) => this._injector.createInstance(m, t));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
H.extend(me);
|
|
995
|
+
class he extends N {
|
|
996
|
+
async insertCellImageAsync(e) {
|
|
997
|
+
var s;
|
|
998
|
+
const t = this._injector.get(B), i = (s = Z(Y.UNIVER_SHEET, this._injector.get(q), t)) == null ? void 0 : s.with(ee);
|
|
999
|
+
if (!i)
|
|
1000
|
+
return !1;
|
|
1001
|
+
const n = {
|
|
1002
|
+
unitId: this._workbook.getUnitId(),
|
|
1003
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
1004
|
+
row: this.getRow(),
|
|
1005
|
+
col: this.getColumn()
|
|
1006
|
+
};
|
|
1007
|
+
return typeof e == "string" ? i.insertCellImageByUrl(e, n) : i.insertCellImageByFile(e, n);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
N.extend(he);
|