@univerjs/sheets-drawing-ui 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +463 -1
- package/lib/cjs/index.js +6203 -2
- package/lib/cjs/locale/ca-ES.js +54 -1
- package/lib/cjs/locale/en-US.js +69 -1
- package/lib/cjs/locale/es-ES.js +54 -1
- package/lib/cjs/locale/fa-IR.js +54 -1
- package/lib/cjs/locale/fr-FR.js +54 -1
- package/lib/cjs/locale/ja-JP.js +54 -1
- package/lib/cjs/locale/ko-KR.js +54 -1
- package/lib/cjs/locale/ru-RU.js +54 -1
- package/lib/cjs/locale/sk-SK.js +54 -1
- package/lib/cjs/locale/vi-VN.js +54 -1
- package/lib/cjs/locale/zh-CN.js +54 -1
- package/lib/cjs/locale/zh-TW.js +54 -1
- package/lib/es/facade.js +464 -1
- package/lib/es/index.js +6159 -2
- package/lib/es/locale/ca-ES.js +53 -1
- package/lib/es/locale/en-US.js +68 -1
- package/lib/es/locale/es-ES.js +53 -1
- package/lib/es/locale/fa-IR.js +53 -1
- package/lib/es/locale/fr-FR.js +53 -1
- package/lib/es/locale/ja-JP.js +53 -1
- package/lib/es/locale/ko-KR.js +53 -1
- package/lib/es/locale/ru-RU.js +53 -1
- package/lib/es/locale/sk-SK.js +53 -1
- package/lib/es/locale/vi-VN.js +53 -1
- package/lib/es/locale/zh-CN.js +53 -1
- package/lib/es/locale/zh-TW.js +53 -1
- package/lib/facade.js +464 -1
- package/lib/index.js +6159 -2
- package/lib/locale/ca-ES.js +53 -1
- package/lib/locale/en-US.js +68 -1
- package/lib/locale/es-ES.js +53 -1
- package/lib/locale/fa-IR.js +53 -1
- package/lib/locale/fr-FR.js +53 -1
- package/lib/locale/ja-JP.js +53 -1
- package/lib/locale/ko-KR.js +53 -1
- package/lib/locale/ru-RU.js +53 -1
- package/lib/locale/sk-SK.js +53 -1
- package/lib/locale/vi-VN.js +53 -1
- package/lib/locale/zh-CN.js +53 -1
- package/lib/locale/zh-TW.js +53 -1
- package/lib/umd/index.js +1 -1
- package/package.json +15 -15
package/lib/es/locale/zh-TW.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/zh-TW.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
sheetImage: {
|
|
4
|
+
title: "圖片",
|
|
5
|
+
upload: {
|
|
6
|
+
float: "浮動圖片",
|
|
7
|
+
cell: "儲存格圖片"
|
|
8
|
+
},
|
|
9
|
+
panel: { title: "編圖" },
|
|
10
|
+
save: {
|
|
11
|
+
title: "儲存儲存格圖片",
|
|
12
|
+
menuLabel: "儲存儲存格圖片",
|
|
13
|
+
imageCount: "圖片數量",
|
|
14
|
+
fileNameConfig: "檔案名稱",
|
|
15
|
+
useRowCol: "使用儲存格地址 (A1, B2...)",
|
|
16
|
+
useColumnValue: "使用某欄的值",
|
|
17
|
+
selectColumn: "選擇欄",
|
|
18
|
+
cancel: "取消",
|
|
19
|
+
confirm: "儲存",
|
|
20
|
+
saving: "儲存中...",
|
|
21
|
+
error: "儲存儲存格圖片失敗"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"image-popup": {
|
|
25
|
+
replace: "替換",
|
|
26
|
+
delete: "刪除",
|
|
27
|
+
edit: "編輯",
|
|
28
|
+
crop: "裁切",
|
|
29
|
+
reset: "重置大小",
|
|
30
|
+
flipH: "水平翻轉",
|
|
31
|
+
flipV: "垂直翻轉"
|
|
32
|
+
},
|
|
33
|
+
"drawing-anchor": {
|
|
34
|
+
title: "錨點屬性",
|
|
35
|
+
both: "與儲存格一起移動和調整大小",
|
|
36
|
+
position: "移動但不調整大小與儲存格",
|
|
37
|
+
none: "不要移動或調整大小與儲存格"
|
|
38
|
+
},
|
|
39
|
+
"update-status": {
|
|
40
|
+
exceedMaxSize: "圖片大小超過限制, 限制為{0}M",
|
|
41
|
+
invalidImageType: "圖片類型錯誤",
|
|
42
|
+
exceedMaxCount: "圖片只能一次上傳{0}張",
|
|
43
|
+
invalidImage: "無效圖片"
|
|
44
|
+
},
|
|
45
|
+
"cell-image": {
|
|
46
|
+
pasteTitle: "貼上為儲存格圖片",
|
|
47
|
+
pasteContent: "貼上儲存格圖片將覆蓋儲存格中的現有內容,繼續貼上",
|
|
48
|
+
pasteError: "此儲存格不支援儲存格圖片複製貼上"
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { locale as default };
|
package/lib/facade.js
CHANGED
|
@@ -1 +1,464 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SheetSkeletonService } from "@univerjs/sheets";
|
|
2
|
+
import { ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetSheetDrawingCommand, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
|
|
3
|
+
import { FileNamePart, IBatchSaveImagesService, SheetCanvasFloatDomManagerService, SheetDrawingUpdateController } from "@univerjs/sheets-drawing-ui";
|
|
4
|
+
import { transformComponentKey } from "@univerjs/sheets-ui/facade";
|
|
5
|
+
import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
6
|
+
import { ComponentManager } from "@univerjs/ui";
|
|
7
|
+
import { FEventName, FUniver } from "@univerjs/core/facade";
|
|
8
|
+
import { CanceledError, DrawingTypeEnum, ICommandService, IURLImageService, IUniverInstanceService, UniverInstanceType } from "@univerjs/core";
|
|
9
|
+
import { IDrawingManagerService } from "@univerjs/drawing";
|
|
10
|
+
import { IRenderManagerService, getCurrentTypeOfRenderer } from "@univerjs/engine-render";
|
|
11
|
+
|
|
12
|
+
//#region src/facade/f-worksheet.ts
|
|
13
|
+
var FWorksheetDrawingUIMixin = class extends FWorksheet {
|
|
14
|
+
getFloatDomById(id) {
|
|
15
|
+
const info = this._injector.get(SheetCanvasFloatDomManagerService).getFloatDomInfo(id);
|
|
16
|
+
if (!info) return null;
|
|
17
|
+
const { unitId, subUnitId } = info;
|
|
18
|
+
const { rect } = info;
|
|
19
|
+
const { left = 0, top = 0, width = 0, height = 0, flipX = false, flipY = false, angle = 0, skewX = 0, skewY = 0 } = rect.getState();
|
|
20
|
+
const drawingParm = this._injector.get(ISheetDrawingService).getDrawingByParam({
|
|
21
|
+
drawingId: info.id,
|
|
22
|
+
unitId,
|
|
23
|
+
subUnitId
|
|
24
|
+
});
|
|
25
|
+
if (!drawingParm) return null;
|
|
26
|
+
return {
|
|
27
|
+
position: {
|
|
28
|
+
left,
|
|
29
|
+
top,
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
flipX,
|
|
33
|
+
flipY,
|
|
34
|
+
angle,
|
|
35
|
+
skewX,
|
|
36
|
+
skewY
|
|
37
|
+
},
|
|
38
|
+
componentKey: drawingParm.componentKey,
|
|
39
|
+
allowTransform: drawingParm.allowTransform,
|
|
40
|
+
data: drawingParm.data,
|
|
41
|
+
id: info.id
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
getAllFloatDoms() {
|
|
45
|
+
const floatDomService = this._injector.get(SheetCanvasFloatDomManagerService);
|
|
46
|
+
const unitId = this._workbook.getUnitId();
|
|
47
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
48
|
+
return Array.from(floatDomService.getFloatDomsBySubUnitId(unitId, subUnitId).values()).map((info) => {
|
|
49
|
+
const { rect } = info;
|
|
50
|
+
const drawingParm = this._injector.get(ISheetDrawingService).getDrawingByParam({
|
|
51
|
+
drawingId: info.id,
|
|
52
|
+
unitId,
|
|
53
|
+
subUnitId
|
|
54
|
+
});
|
|
55
|
+
const { left, top, width, height, flipX, flipY, angle, skewX, skewY } = rect.getState();
|
|
56
|
+
return {
|
|
57
|
+
position: {
|
|
58
|
+
left,
|
|
59
|
+
top,
|
|
60
|
+
width,
|
|
61
|
+
height,
|
|
62
|
+
flipX,
|
|
63
|
+
flipY,
|
|
64
|
+
angle,
|
|
65
|
+
skewX,
|
|
66
|
+
skewY
|
|
67
|
+
},
|
|
68
|
+
componentKey: drawingParm.componentKey,
|
|
69
|
+
allowTransform: drawingParm.allowTransform,
|
|
70
|
+
data: drawingParm.data,
|
|
71
|
+
id: info.id
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
updateFloatDom(id, config) {
|
|
76
|
+
var _transformToDrawingPo, _transformToAxisAlign;
|
|
77
|
+
const sheetSkeletonService = this._injector.get(SheetSkeletonService);
|
|
78
|
+
const info = this._injector.get(SheetCanvasFloatDomManagerService).getFloatDomInfo(id);
|
|
79
|
+
if (!info) return this;
|
|
80
|
+
const { unitId, subUnitId } = info;
|
|
81
|
+
const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
82
|
+
if (!skeleton) return this;
|
|
83
|
+
const drawingParm = this._injector.get(ISheetDrawingService).getDrawingByParam({
|
|
84
|
+
unitId,
|
|
85
|
+
subUnitId,
|
|
86
|
+
drawingId: id
|
|
87
|
+
});
|
|
88
|
+
const newParam = {
|
|
89
|
+
...drawingParm,
|
|
90
|
+
componentKey: config.componentKey || drawingParm.componentKey,
|
|
91
|
+
allowTransform: config.allowTransform !== void 0 ? config.allowTransform : drawingParm.allowTransform,
|
|
92
|
+
data: config.data || drawingParm.data,
|
|
93
|
+
sheetTransform: config.position ? (_transformToDrawingPo = transformToDrawingPosition(config.position, skeleton)) !== null && _transformToDrawingPo !== void 0 ? _transformToDrawingPo : drawingParm.sheetTransform : drawingParm.sheetTransform,
|
|
94
|
+
transform: {
|
|
95
|
+
...drawingParm.transform,
|
|
96
|
+
...config.position
|
|
97
|
+
},
|
|
98
|
+
axisAlignSheetTransform: config.position ? (_transformToAxisAlign = transformToAxisAlignPosition(config.position, skeleton)) !== null && _transformToAxisAlign !== void 0 ? _transformToAxisAlign : drawingParm.sheetTransform : drawingParm.sheetTransform
|
|
99
|
+
};
|
|
100
|
+
if (!this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
101
|
+
unitId,
|
|
102
|
+
subUnitId,
|
|
103
|
+
drawings: [newParam]
|
|
104
|
+
})) throw new Error("updateFloatDom failed");
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
batchUpdateFloatDoms(updates) {
|
|
108
|
+
const floatDomService = this._injector.get(SheetCanvasFloatDomManagerService);
|
|
109
|
+
const drawingService = this._injector.get(ISheetDrawingService);
|
|
110
|
+
const sheetSkeletonService = this._injector.get(SheetSkeletonService);
|
|
111
|
+
const drawings = [];
|
|
112
|
+
for (const update of updates) {
|
|
113
|
+
var _transformToDrawingPo2, _transformToAxisAlign2;
|
|
114
|
+
const info = floatDomService.getFloatDomInfo(update.id);
|
|
115
|
+
if (!info) continue;
|
|
116
|
+
const { unitId, subUnitId } = info;
|
|
117
|
+
const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
118
|
+
if (!skeleton) continue;
|
|
119
|
+
const drawingParm = drawingService.getDrawingByParam({
|
|
120
|
+
unitId,
|
|
121
|
+
subUnitId,
|
|
122
|
+
drawingId: update.id
|
|
123
|
+
});
|
|
124
|
+
if (!drawingParm) continue;
|
|
125
|
+
const newParam = {
|
|
126
|
+
...drawingParm,
|
|
127
|
+
componentKey: update.config.componentKey || drawingParm.componentKey,
|
|
128
|
+
allowTransform: update.config.allowTransform !== void 0 ? update.config.allowTransform : drawingParm.allowTransform,
|
|
129
|
+
data: update.config.data || drawingParm.data,
|
|
130
|
+
sheetTransform: update.config.position ? (_transformToDrawingPo2 = transformToDrawingPosition(update.config.position, skeleton)) !== null && _transformToDrawingPo2 !== void 0 ? _transformToDrawingPo2 : drawingParm.sheetTransform : drawingParm.sheetTransform,
|
|
131
|
+
transform: {
|
|
132
|
+
...drawingParm.transform,
|
|
133
|
+
...update.config.position
|
|
134
|
+
},
|
|
135
|
+
axisAlignSheetTransform: update.config.position ? (_transformToAxisAlign2 = transformToAxisAlignPosition(update.config.position, skeleton)) !== null && _transformToAxisAlign2 !== void 0 ? _transformToAxisAlign2 : drawingParm.sheetTransform : drawingParm.sheetTransform
|
|
136
|
+
};
|
|
137
|
+
drawings.push(newParam);
|
|
138
|
+
}
|
|
139
|
+
if (drawings.length > 0) {
|
|
140
|
+
const unitId = this._workbook.getUnitId();
|
|
141
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
142
|
+
if (!this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
143
|
+
unitId,
|
|
144
|
+
subUnitId,
|
|
145
|
+
drawings
|
|
146
|
+
})) throw new Error("batchUpdateFloatDoms failed");
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
removeFloatDom(id) {
|
|
151
|
+
const info = this._injector.get(SheetCanvasFloatDomManagerService).getFloatDomInfo(id);
|
|
152
|
+
if (!info) return this;
|
|
153
|
+
const { unitId, subUnitId } = info;
|
|
154
|
+
const drawing = this._injector.get(ISheetDrawingService).getDrawingByParam({
|
|
155
|
+
unitId,
|
|
156
|
+
subUnitId,
|
|
157
|
+
drawingId: id
|
|
158
|
+
});
|
|
159
|
+
if (!drawing) return this;
|
|
160
|
+
if (!this._commandService.syncExecuteCommand(RemoveSheetDrawingCommand.id, {
|
|
161
|
+
unitId,
|
|
162
|
+
drawings: [drawing]
|
|
163
|
+
})) throw new Error("removeFloatDom failed");
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
addFloatDomToPosition(layer, id) {
|
|
167
|
+
const unitId = this._workbook.getUnitId();
|
|
168
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
169
|
+
const { key, disposableCollection } = transformComponentKey(layer, this._injector.get(ComponentManager));
|
|
170
|
+
const res = this._injector.get(SheetCanvasFloatDomManagerService).addFloatDomToPosition({
|
|
171
|
+
...layer,
|
|
172
|
+
componentKey: key,
|
|
173
|
+
unitId,
|
|
174
|
+
subUnitId
|
|
175
|
+
}, id);
|
|
176
|
+
if (res) {
|
|
177
|
+
disposableCollection.add(res.dispose);
|
|
178
|
+
return {
|
|
179
|
+
id: res.id,
|
|
180
|
+
dispose: () => {
|
|
181
|
+
disposableCollection.dispose();
|
|
182
|
+
res.dispose();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
disposableCollection.dispose();
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
addFloatDomToRange(fRange, layer, domLayout, id) {
|
|
190
|
+
const unitId = this._workbook.getUnitId();
|
|
191
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
192
|
+
const { key, disposableCollection } = transformComponentKey(layer, this._injector.get(ComponentManager));
|
|
193
|
+
const res = this._injector.get(SheetCanvasFloatDomManagerService).addFloatDomToRange(fRange.getRange(), {
|
|
194
|
+
...layer,
|
|
195
|
+
componentKey: key,
|
|
196
|
+
unitId,
|
|
197
|
+
subUnitId
|
|
198
|
+
}, domLayout, id);
|
|
199
|
+
if (res) {
|
|
200
|
+
disposableCollection.add(res.dispose);
|
|
201
|
+
return {
|
|
202
|
+
id: res.id,
|
|
203
|
+
dispose: () => {
|
|
204
|
+
disposableCollection.dispose();
|
|
205
|
+
res.dispose();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
disposableCollection.dispose();
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
addFloatDomToColumnHeader(column, layer, domLayout, id) {
|
|
213
|
+
const unitId = this._workbook.getUnitId();
|
|
214
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
215
|
+
const { key, disposableCollection } = transformComponentKey(layer, this._injector.get(ComponentManager));
|
|
216
|
+
const domRangeDispose = this._injector.get(SheetCanvasFloatDomManagerService).addFloatDomToColumnHeader(column, {
|
|
217
|
+
...layer,
|
|
218
|
+
componentKey: key,
|
|
219
|
+
unitId,
|
|
220
|
+
subUnitId
|
|
221
|
+
}, domLayout, id);
|
|
222
|
+
if (domRangeDispose) {
|
|
223
|
+
disposableCollection.add(domRangeDispose.dispose);
|
|
224
|
+
return {
|
|
225
|
+
id: domRangeDispose.id,
|
|
226
|
+
dispose: () => {
|
|
227
|
+
disposableCollection.dispose();
|
|
228
|
+
domRangeDispose.dispose();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
disposableCollection.dispose();
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
async saveCellImagesAsync(options, ranges) {
|
|
236
|
+
var _options$useCellAddre;
|
|
237
|
+
const batchSaveService = this._injector.get(IBatchSaveImagesService);
|
|
238
|
+
const unitId = this._fWorkbook.getId();
|
|
239
|
+
const subUnitId = this.getSheetId();
|
|
240
|
+
const iRanges = ranges ? ranges.map((r) => r.getRange()) : [this._worksheet.getCellMatrix().getDataRange()];
|
|
241
|
+
const images = batchSaveService.getCellImagesFromRanges(unitId, subUnitId, iRanges);
|
|
242
|
+
if (images.length === 0) return false;
|
|
243
|
+
if (images.length === 1) try {
|
|
244
|
+
await batchSaveService.downloadSingleImage(images[0]);
|
|
245
|
+
return true;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
console.error("Failed to download image:", error);
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
const fileNameParts = [];
|
|
251
|
+
const useCellAddress = (_options$useCellAddre = options === null || options === void 0 ? void 0 : options.useCellAddress) !== null && _options$useCellAddre !== void 0 ? _options$useCellAddre : true;
|
|
252
|
+
const useColumnIndex = options === null || options === void 0 ? void 0 : options.useColumnIndex;
|
|
253
|
+
if (useCellAddress) fileNameParts.push(FileNamePart.CELL_ADDRESS);
|
|
254
|
+
if (useColumnIndex !== void 0) fileNameParts.push(FileNamePart.COLUMN_VALUE);
|
|
255
|
+
if (fileNameParts.length === 0) fileNameParts.push(FileNamePart.CELL_ADDRESS);
|
|
256
|
+
try {
|
|
257
|
+
await batchSaveService.saveImagesWithContext(images, {
|
|
258
|
+
fileNameParts,
|
|
259
|
+
columnIndex: useColumnIndex
|
|
260
|
+
}, unitId, subUnitId);
|
|
261
|
+
return true;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error("Failed to save images:", error);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
FWorksheet.extend(FWorksheetDrawingUIMixin);
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/facade/f-event.ts
|
|
272
|
+
var FSheetsDrawingUIEventNameMixin = class extends FEventName {
|
|
273
|
+
get BeforeFloatDomAdd() {
|
|
274
|
+
return "BeforeFloatDomAdd";
|
|
275
|
+
}
|
|
276
|
+
get FloatDomAdded() {
|
|
277
|
+
return "FloatDomAdded";
|
|
278
|
+
}
|
|
279
|
+
get BeforeFloatDomUpdate() {
|
|
280
|
+
return "BeforeFloatDomUpdate";
|
|
281
|
+
}
|
|
282
|
+
get FloatDomUpdated() {
|
|
283
|
+
return "FloatDomUpdated";
|
|
284
|
+
}
|
|
285
|
+
get BeforeFloatDomDelete() {
|
|
286
|
+
return "BeforeFloatDomDelete";
|
|
287
|
+
}
|
|
288
|
+
get FloatDomDeleted() {
|
|
289
|
+
return "FloatDomDeleted";
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
FEventName.extend(FSheetsDrawingUIEventNameMixin);
|
|
293
|
+
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/facade/f-univer.ts
|
|
296
|
+
/**
|
|
297
|
+
* @ignore
|
|
298
|
+
*/
|
|
299
|
+
var FUniverSheetsDrawingUIMixin = class extends FUniver {
|
|
300
|
+
/**
|
|
301
|
+
* @ignore
|
|
302
|
+
*/
|
|
303
|
+
_initialize(injector) {
|
|
304
|
+
const commandService = injector.get(ICommandService);
|
|
305
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomAdd, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
306
|
+
if (commandInfo.id !== InsertSheetDrawingCommand.id) return;
|
|
307
|
+
const params = commandInfo.params;
|
|
308
|
+
const workbook = this.getActiveWorkbook();
|
|
309
|
+
if (workbook == null || params == null) return;
|
|
310
|
+
const { drawings } = params;
|
|
311
|
+
const floatDomDrawings = drawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_DOM);
|
|
312
|
+
if (floatDomDrawings.length === 0) return;
|
|
313
|
+
const eventParams = {
|
|
314
|
+
workbook,
|
|
315
|
+
drawings: floatDomDrawings
|
|
316
|
+
};
|
|
317
|
+
this.fireEvent(this.Event.BeforeFloatDomAdd, eventParams);
|
|
318
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
319
|
+
})));
|
|
320
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomAdded, () => commandService.onCommandExecuted((commandInfo) => {
|
|
321
|
+
if (commandInfo.id !== InsertSheetDrawingCommand.id) return;
|
|
322
|
+
const params = commandInfo.params;
|
|
323
|
+
const workbook = this.getActiveWorkbook();
|
|
324
|
+
if (workbook == null || params == null) return;
|
|
325
|
+
const { drawings } = params;
|
|
326
|
+
const floatDomDrawings = drawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_DOM);
|
|
327
|
+
if (floatDomDrawings.length === 0) return;
|
|
328
|
+
const eventParams = {
|
|
329
|
+
workbook,
|
|
330
|
+
drawings: floatDomDrawings
|
|
331
|
+
};
|
|
332
|
+
this.fireEvent(this.Event.FloatDomAdded, eventParams);
|
|
333
|
+
})));
|
|
334
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
335
|
+
if (commandInfo.id !== SetSheetDrawingCommand.id) return;
|
|
336
|
+
const params = commandInfo.params;
|
|
337
|
+
const workbook = this.getActiveWorkbook();
|
|
338
|
+
if (workbook == null || params == null) return;
|
|
339
|
+
const { drawings } = params;
|
|
340
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
341
|
+
const floatDomDrawings = [];
|
|
342
|
+
drawings.forEach((drawing) => {
|
|
343
|
+
const dom = drawingManagerService.getDrawingByParam(drawing);
|
|
344
|
+
if ((dom === null || dom === void 0 ? void 0 : dom.drawingType) === DrawingTypeEnum.DRAWING_DOM) floatDomDrawings.push(dom);
|
|
345
|
+
});
|
|
346
|
+
if (floatDomDrawings.length === 0) return;
|
|
347
|
+
const eventParams = {
|
|
348
|
+
workbook,
|
|
349
|
+
drawings: floatDomDrawings
|
|
350
|
+
};
|
|
351
|
+
this.fireEvent(this.Event.BeforeFloatDomUpdate, eventParams);
|
|
352
|
+
if (eventParams.cancel) {
|
|
353
|
+
drawingManagerService.updateNotification(drawings);
|
|
354
|
+
throw new CanceledError();
|
|
355
|
+
}
|
|
356
|
+
})));
|
|
357
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomUpdated, () => commandService.onCommandExecuted((commandInfo) => {
|
|
358
|
+
if (commandInfo.id !== SetSheetDrawingCommand.id) return;
|
|
359
|
+
const params = commandInfo.params;
|
|
360
|
+
const workbook = this.getActiveWorkbook();
|
|
361
|
+
if (workbook == null || params == null) return;
|
|
362
|
+
const { drawings } = params;
|
|
363
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
364
|
+
const floatDomDrawings = [];
|
|
365
|
+
drawings.forEach((drawing) => {
|
|
366
|
+
const dom = drawingManagerService.getDrawingByParam(drawing);
|
|
367
|
+
if ((dom === null || dom === void 0 ? void 0 : dom.drawingType) === DrawingTypeEnum.DRAWING_DOM) floatDomDrawings.push(dom);
|
|
368
|
+
});
|
|
369
|
+
if (floatDomDrawings.length === 0) return;
|
|
370
|
+
const eventParams = {
|
|
371
|
+
workbook,
|
|
372
|
+
drawings: floatDomDrawings
|
|
373
|
+
};
|
|
374
|
+
this.fireEvent(this.Event.FloatDomUpdated, eventParams);
|
|
375
|
+
})));
|
|
376
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomDelete, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
377
|
+
if (commandInfo.id !== RemoveSheetDrawingCommand.id) return;
|
|
378
|
+
const params = commandInfo.params;
|
|
379
|
+
const workbook = this.getActiveWorkbook();
|
|
380
|
+
if (workbook == null || params == null) return;
|
|
381
|
+
const drawingManagerService = injector.get(IDrawingManagerService);
|
|
382
|
+
const { drawings } = params;
|
|
383
|
+
const floatDomDrawings = drawings.map((drawing) => drawingManagerService.getDrawingByParam(drawing)).filter((drawing) => (drawing === null || drawing === void 0 ? void 0 : drawing.drawingType) === DrawingTypeEnum.DRAWING_DOM);
|
|
384
|
+
if (floatDomDrawings.length === 0) return;
|
|
385
|
+
const eventParams = {
|
|
386
|
+
workbook,
|
|
387
|
+
drawings: floatDomDrawings
|
|
388
|
+
};
|
|
389
|
+
this.fireEvent(this.Event.BeforeFloatDomDelete, eventParams);
|
|
390
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
391
|
+
})));
|
|
392
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomDeleted, () => commandService.onCommandExecuted((commandInfo) => {
|
|
393
|
+
if (commandInfo.id !== RemoveSheetDrawingCommand.id) return;
|
|
394
|
+
const params = commandInfo.params;
|
|
395
|
+
const workbook = this.getActiveWorkbook();
|
|
396
|
+
if (workbook == null || params == null) return;
|
|
397
|
+
const { drawings } = params;
|
|
398
|
+
const eventParams = {
|
|
399
|
+
workbook,
|
|
400
|
+
drawings: drawings.filter((i) => i.drawingType === DrawingTypeEnum.DRAWING_DOM).map((i) => i.drawingId)
|
|
401
|
+
};
|
|
402
|
+
this.fireEvent(this.Event.FloatDomDeleted, eventParams);
|
|
403
|
+
})));
|
|
404
|
+
}
|
|
405
|
+
registerURLImageDownloader(downloader) {
|
|
406
|
+
return this._injector.get(IURLImageService).registerURLImageDownloader(downloader);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
FUniver.extend(FUniverSheetsDrawingUIMixin);
|
|
410
|
+
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/facade/f-range.ts
|
|
413
|
+
var FRangeSheetsDrawingUIMixin = class extends FRange {
|
|
414
|
+
async insertCellImageAsync(file) {
|
|
415
|
+
var _getCurrentTypeOfRend;
|
|
416
|
+
const renderManagerService = this._injector.get(IRenderManagerService);
|
|
417
|
+
const controller = (_getCurrentTypeOfRend = getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET, this._injector.get(IUniverInstanceService), renderManagerService)) === null || _getCurrentTypeOfRend === void 0 ? void 0 : _getCurrentTypeOfRend.with(SheetDrawingUpdateController);
|
|
418
|
+
if (!controller) return false;
|
|
419
|
+
const location = {
|
|
420
|
+
unitId: this._workbook.getUnitId(),
|
|
421
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
422
|
+
row: this.getRow(),
|
|
423
|
+
col: this.getColumn()
|
|
424
|
+
};
|
|
425
|
+
if (typeof file === "string") return controller.insertCellImageByUrl(file, location);
|
|
426
|
+
else return controller.insertCellImageByFile(file, location);
|
|
427
|
+
}
|
|
428
|
+
async saveCellImagesAsync(options) {
|
|
429
|
+
var _options$useCellAddre;
|
|
430
|
+
const batchSaveService = this._injector.get(IBatchSaveImagesService);
|
|
431
|
+
const unitId = this._workbook.getUnitId();
|
|
432
|
+
const subUnitId = this._worksheet.getSheetId();
|
|
433
|
+
const range = this.getRange();
|
|
434
|
+
const images = batchSaveService.getCellImagesFromRanges(unitId, subUnitId, [range]);
|
|
435
|
+
if (images.length === 0) return false;
|
|
436
|
+
if (images.length === 1) try {
|
|
437
|
+
await batchSaveService.downloadSingleImage(images[0]);
|
|
438
|
+
return true;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
console.error("Failed to download image:", error);
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
const fileNameParts = [];
|
|
444
|
+
const useCellAddress = (_options$useCellAddre = options === null || options === void 0 ? void 0 : options.useCellAddress) !== null && _options$useCellAddre !== void 0 ? _options$useCellAddre : true;
|
|
445
|
+
const useColumnIndex = options === null || options === void 0 ? void 0 : options.useColumnIndex;
|
|
446
|
+
if (useCellAddress) fileNameParts.push(FileNamePart.CELL_ADDRESS);
|
|
447
|
+
if (useColumnIndex !== void 0) fileNameParts.push(FileNamePart.COLUMN_VALUE);
|
|
448
|
+
if (fileNameParts.length === 0) fileNameParts.push(FileNamePart.CELL_ADDRESS);
|
|
449
|
+
try {
|
|
450
|
+
await batchSaveService.saveImagesWithContext(images, {
|
|
451
|
+
fileNameParts,
|
|
452
|
+
columnIndex: useColumnIndex
|
|
453
|
+
}, unitId, subUnitId);
|
|
454
|
+
return true;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
console.error("Failed to save images:", error);
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
FRange.extend(FRangeSheetsDrawingUIMixin);
|
|
462
|
+
|
|
463
|
+
//#endregion
|
|
464
|
+
export { };
|