Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(image): load multiple (#6537)

Univerab669e4503f9
diff --git a/packages/drawing-ui/src/controllers/image-update.controller.ts b/packages/drawing-ui/src/controllers/image-update.controller.ts
index 5f2a494f58..5b7214a724 100644
--- a/packages/drawing-ui/src/controllers/image-update.controller.ts
+++ b/packages/drawing-ui/src/controllers/image-update.controller.ts
@@ -29,6 +29,7 @@ import {
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService, SetDrawingSelectedOperation } from '@univerjs/drawing';
import { CURSOR_TYPE, IRenderManagerService } from '@univerjs/engine-render';
import { IDialogService } from '@univerjs/ui';
+import { bufferTime, filter, map } from 'rxjs';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
import { DrawingRenderService } from '../services/drawing-render.service';
import { getCurrentUnitInfo } from './utils';
@@ -157,9 +158,26 @@ export class ImageUpdateController extends Disposable {
private _drawingAddListener() {
this.disposeWithMe(
- this._drawingManagerService.add$.subscribe((params) => {
- this._insertImages(params);
- })
+ this._drawingManagerService.add$
+ .pipe(
+ bufferTime(33),
+ filter((batches) => batches.length > 0),
+
+ map((batches) => batches.flat()),
+
+ map((items) => {
+ const map = new Map<string, IDrawingSearch>();
+ for (const it of items) {
+ map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
+ }
+ return [...map.values()];
+ }),
+
+ filter((items) => items.length > 0)
+ )
+ .subscribe((uniqueParams) => {
+ void this._insertImages(uniqueParams);
+ })
);
}
diff --git a/packages/drawing-ui/src/services/drawing-render.service.ts b/packages/drawing-ui/src/services/drawing-render.service.ts
index bbb542ff65..8f228fde4a 100644
--- a/packages/drawing-ui/src/services/drawing-render.service.ts
+++ b/packages/drawing-ui/src/services/drawing-render.service.ts
@@ -34,7 +34,7 @@ export class DrawingRenderService {
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
) { }
- // eslint-disable-next-line max-lines-per-function
+ // eslint-disable-next-line max-lines-per-function, complexity
async renderImages(imageParam: IImageData, scene: Scene) {
const {
transform: singleTransform,
@@ -76,6 +76,14 @@ export class DrawingRenderService {
continue;
}
+ if (!this._drawingManagerService.getDrawingVisible()) {
+ continue;
+ }
+
+ if (subUnitId !== this._getActiveSheetId()) {
+ continue;
+ }
+
const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
const zIndex = orders.indexOf(drawingId);
const imageConfig: IImageProps = { ...transform, zIndex: zIndex === -1 ? (orders.length - 1) : zIndex };
@@ -117,14 +125,6 @@ export class DrawingRenderService {
this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
}
- if (!this._drawingManagerService.getDrawingVisible()) {
- continue;
- }
-
- if (subUnitId !== this._getActiveSheetId()) {
- continue;
- }
-
scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX);
if (this._drawingManagerService.getDrawingEditable()) {
scene.attachTransformerTo(image);