@univerjs/docs-drawing-ui 0.2.12 → 0.2.13

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/es/index.js CHANGED
@@ -2,28 +2,28 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService, useDependency, PositionedObjectLayoutType, BooleanNumber, ObjectRelativeFromH, ObjectRelativeFromV, Tools, WrapTextType, Direction, IUndoRedoService, FOCUSING_UNIVER_EDITOR, Disposable, Injector, fromEventSubject, LifecycleService, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn, IConfigService } from "@univerjs/core";
5
+ import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService, IUndoRedoService, BuildTextUtils, Tools, Disposable, BooleanNumber, PositionedObjectLayoutType, WrapTextType, ObjectRelativeFromH, ObjectRelativeFromV, useDependency, Direction, FOCUSING_UNIVER_EDITOR, fromEventSubject, LifecycleService, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn, Injector, IConfigService } from "@univerjs/core";
6
6
  import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
7
- import { IDrawingManagerService, DRAWING_IMAGE_ALLOW_IMAGE_LIST, ArrangeTypeEnum, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, IImageIoService, UniverDrawingPlugin } from "@univerjs/drawing";
7
+ import { IDrawingManagerService, ArrangeTypeEnum, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, IImageIoService, UniverDrawingPlugin } from "@univerjs/drawing";
8
8
  import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
9
- import { ITextSelectionRenderManager, IRenderManagerService, DocumentEditArea, Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE, PageLayoutType, NodePositionConvertToCursor, getOneTextSelectionRange, DocumentSkeletonPageType, Vector2, getAnchorBounding, Rect, getColor, TEXT_RANGE_LAYER_INDEX } from "@univerjs/engine-render";
10
- import { takeUntil, Observable, BehaviorSubject, filter, debounceTime } from "rxjs";
11
- import { DocCanvasPopManagerService, docDrawingPositionToTransform } from "@univerjs/docs-ui";
12
- import { RichTextEditingMutation, getRichTextEditPath, TextSelectionManagerService, DocSkeletonManagerService, getRetainAndDeleteFromReplace, getCustomBlockIdsInSelections, SetDocZoomRatioOperation, getDocObject } from "@univerjs/docs";
13
- import { ISidebarService, MenuItemType, getMenuHiddenObservable, KeyCode, RibbonStartGroup, ComponentManager, IMenuManagerService, IShortcutService, IMessageService, IEditorService } from "@univerjs/ui";
9
+ import { IRenderManagerService, DocumentEditArea, Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE, PageLayoutType, DocumentSkeletonPageType, Vector2, Rect, getColor } from "@univerjs/engine-render";
10
+ import { takeUntil, BehaviorSubject, Observable, filter, debounceTime } from "rxjs";
11
+ import { DocSelectionRenderService, getRichTextEditPath, DocCanvasPopManagerService, getCustomBlockIdsInSelections, docDrawingPositionToTransform, SetDocZoomRatioOperation, NodePositionConvertToCursor, getOneTextSelectionRange, getAnchorBounding, TEXT_RANGE_LAYER_INDEX, getDocObject } from "@univerjs/docs-ui";
12
+ import { RichTextEditingMutation, DocSelectionManagerService, DocSkeletonManagerService } from "@univerjs/docs";
13
+ import { ISidebarService, IMessageService, ILocalFileService, MenuItemType, getMenuHiddenObservable, KeyCode, RibbonStartGroup, ComponentManager, IMenuManagerService, IShortcutService, IEditorService } from "@univerjs/ui";
14
+ import { MessageType, RadioGroup, Radio, InputNumber, Select, Checkbox } from "@univerjs/design";
14
15
  import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
15
16
  import clsx from "clsx";
16
- import { RadioGroup, Radio, InputNumber, Select, Checkbox, MessageType } from "@univerjs/design";
17
17
  const RemoveDocDrawingCommand = {
18
18
  id: "doc.command.remove-doc-image",
19
19
  type: CommandType.COMMAND,
20
20
  // eslint-disable-next-line max-lines-per-function
21
21
  handler: /* @__PURE__ */ __name((accessor, params) => {
22
22
  var _a8, _b, _c, _d;
23
- const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
23
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
24
24
  if (params == null || documentDataModel == null)
25
25
  return !1;
26
- const { drawings: removeDrawings } = params, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", textX = new TextX(), jsonX = JSONX.getInstance(), customBlocks = (_c = (_b = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.customBlocks) != null ? _c : [], removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1), unitId = removeDrawings[0].unitId, memoryCursor = new MemoryCursor();
26
+ const docSelectionRenderService = renderManagerService.getRenderById(params.unitId).with(DocSelectionRenderService), { drawings: removeDrawings } = params, segmentId = (_a8 = docSelectionRenderService.getSegment()) != null ? _a8 : "", textX = new TextX(), jsonX = JSONX.getInstance(), customBlocks = (_c = (_b = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.customBlocks) != null ? _c : [], removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1), unitId = removeDrawings[0].unitId, memoryCursor = new MemoryCursor();
27
27
  memoryCursor.reset();
28
28
  const cursorIndex = removeCustomBlocks[0].startIndex, textRanges = [
29
29
  {
@@ -282,41 +282,368 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width:
282
282
  }));
283
283
  });
284
284
  AddImageSingle.displayName = "AddImageSingle";
285
- const InsertDocImageOperation = {
286
- id: "doc.operation.insert-float-image",
287
- type: CommandType.OPERATION,
288
- handler: /* @__PURE__ */ __name(() => !0, "handler")
289
- }, uploadFileMenu = "univer-upload-file-menu", uploadFileMenuInput = "univer-upload-file-menu-input", styles$1 = {
290
- uploadFileMenu,
291
- uploadFileMenuInput
292
- }, UploadFileMenu = /* @__PURE__ */ __name(() => {
293
- const commandService = useDependency(ICommandService), fileInputRef = useRef(null), handleButtonClick = /* @__PURE__ */ __name(() => {
285
+ const GroupDocDrawingCommand = {
286
+ id: "doc.command.group-doc-image",
287
+ type: CommandType.COMMAND,
288
+ handler: /* @__PURE__ */ __name((accessor, params) => {
289
+ accessor.get(ICommandService), accessor.get(IUndoRedoService);
290
+ const docDrawingService = accessor.get(IDocDrawingService);
291
+ if (!params) return !1;
292
+ const unitIds = [];
293
+ return params.forEach(({ parent, children }) => {
294
+ unitIds.push(parent.unitId), children.forEach((child) => {
295
+ unitIds.push(child.unitId);
296
+ });
297
+ }), docDrawingService.getGroupDrawingOp(params), !1;
298
+ }, "handler")
299
+ }, InsertDocDrawingCommand = {
300
+ id: "doc.command.insert-doc-image",
301
+ type: CommandType.COMMAND,
302
+ // eslint-disable-next-line max-lines-per-function
303
+ handler: /* @__PURE__ */ __name((accessor, params) => {
304
+ var _a8, _b, _c, _d;
305
+ if (params == null)
306
+ return !1;
307
+ const commandService = accessor.get(ICommandService), docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = docSelectionManagerService.getActiveTextRange(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
308
+ if (activeTextRange == null || documentDataModel == null)
309
+ return !1;
310
+ const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
311
+ if (body == null)
312
+ return !1;
313
+ const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
314
+ let removeDrawingLen = 0;
315
+ if (collapsed)
316
+ startOffset > 0 && textX.push({
317
+ t: TextXActionType.RETAIN,
318
+ len: startOffset,
319
+ segmentId
320
+ });
321
+ else {
322
+ const { dos } = BuildTextUtils.selection.getDeleteActions(activeTextRange, segmentId, 0, body);
323
+ textX.push(...dos);
324
+ const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [activeTextRange]), drawings2 = (_c = documentDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = documentDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
325
+ if (sortedRemovedCustomBlockIds.length > 0)
326
+ for (const blockId of sortedRemovedCustomBlockIds) {
327
+ const drawing = drawings2[blockId], drawingIndex = drawingOrder.indexOf(blockId);
328
+ if (drawing == null || drawingIndex < 0)
329
+ continue;
330
+ const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
331
+ rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), removeDrawingLen++;
332
+ }
333
+ }
334
+ textX.push({
335
+ t: TextXActionType.INSERT,
336
+ body: {
337
+ dataStream: "\b".repeat(drawings.length),
338
+ customBlocks: drawings.map((drawing, i) => ({
339
+ startIndex: i,
340
+ blockId: drawing.drawingId
341
+ }))
342
+ },
343
+ len: drawings.length,
344
+ line: 0,
345
+ segmentId
346
+ });
347
+ const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
348
+ rawActions.push(placeHolderAction);
349
+ for (const drawing of drawings) {
350
+ const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
351
+ rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
352
+ }
353
+ const doMutation = {
354
+ id: RichTextEditingMutation.id,
355
+ params: {
356
+ unitId,
357
+ actions: [],
358
+ textRanges: []
359
+ }
360
+ };
361
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
362
+ }, "handler")
363
+ }, SetDocDrawingArrangeCommand = {
364
+ id: "doc.command.set-drawing-arrange",
365
+ type: CommandType.COMMAND,
366
+ handler: /* @__PURE__ */ __name((accessor, params) => {
367
+ const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService);
368
+ if (params == null)
369
+ return !1;
370
+ const { unitId, subUnitId, drawingIds, arrangeType } = params, drawingOrderMapParam = { unitId, subUnitId, drawingIds };
371
+ let jsonOp;
372
+ if (arrangeType === ArrangeTypeEnum.forward ? jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.backward ? jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.front ? jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.back && (jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam)), jsonOp == null)
373
+ return !1;
374
+ const { redo } = jsonOp;
375
+ if (redo == null)
376
+ return !1;
377
+ const rawActions = [];
378
+ let redoCopy = Tools.deepClone(redo);
379
+ redoCopy = redoCopy.slice(3), redoCopy.unshift("drawingsOrder"), rawActions.push(redoCopy);
380
+ const doMutation = {
381
+ id: RichTextEditingMutation.id,
382
+ params: {
383
+ unitId,
384
+ actions: [],
385
+ textRanges: null
386
+ }
387
+ };
388
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
389
+ }, "handler")
390
+ }, UngroupDocDrawingCommand = {
391
+ id: "doc.command.ungroup-doc-image",
392
+ type: CommandType.COMMAND,
393
+ handler: /* @__PURE__ */ __name((accessor, params) => {
394
+ accessor.get(ICommandService), accessor.get(IUndoRedoService);
395
+ const docDrawingService = accessor.get(IDocDrawingService);
396
+ if (!params) return !1;
397
+ const unitIds = [];
398
+ return params.forEach(({ parent, children }) => {
399
+ unitIds.push(parent.unitId), children.forEach((child) => {
400
+ unitIds.push(child.unitId);
401
+ });
402
+ }), docDrawingService.getUngroupDrawingOp(params), !1;
403
+ }, "handler")
404
+ }, _DocRefreshDrawingsService = class _DocRefreshDrawingsService {
405
+ constructor() {
406
+ __publicField(this, "_refreshDrawings$", new BehaviorSubject(null));
407
+ __publicField(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
408
+ }
409
+ refreshDrawings(skeleton) {
410
+ this._refreshDrawings$.next(skeleton);
411
+ }
412
+ };
413
+ __name(_DocRefreshDrawingsService, "DocRefreshDrawingsService");
414
+ let DocRefreshDrawingsService = _DocRefreshDrawingsService;
415
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
416
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
417
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
418
+ return kind && result && __defProp$5(target, key, result), result;
419
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a2;
420
+ let DocDrawingUpdateRenderController = (_a2 = class extends Disposable {
421
+ constructor(_context, _commandService, _docSelectionManagerService, _renderManagerSrv, _imageIoService, _docDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, _docSelectionRenderService, _docRefreshDrawingsService, _fileOpenerService) {
422
+ super(), this._context = _context, this._commandService = _commandService, this._docSelectionManagerService = _docSelectionManagerService, this._renderManagerSrv = _renderManagerSrv, this._imageIoService = _imageIoService, this._docDrawingService = _docDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._docSelectionRenderService = _docSelectionRenderService, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._fileOpenerService = _fileOpenerService, this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._editAreaChangeListener();
423
+ }
424
+ async insertDocImage() {
425
+ const files = await this._fileOpenerService.openFile({
426
+ multiple: !0,
427
+ accept: DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
428
+ }), fileLength = files.length;
429
+ return fileLength > DRAWING_IMAGE_COUNT_LIMIT ? (this._messageService.show({
430
+ type: MessageType.Error,
431
+ content: this._localeService.t("update-status.exceedMaxCount", String(DRAWING_IMAGE_COUNT_LIMIT))
432
+ }), !1) : fileLength === 0 ? !1 : (await this._insertFloatImages(files), !0);
433
+ }
434
+ // eslint-disable-next-line max-lines-per-function
435
+ async _insertFloatImages(files) {
436
+ let imageParams = [];
437
+ try {
438
+ imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
439
+ } catch (error) {
440
+ const type = error.message;
441
+ let content = "";
442
+ switch (type) {
443
+ case ImageUploadStatusType.ERROR_EXCEED_SIZE:
444
+ content = this._localeService.t("update-status.exceedMaxSize", String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024)));
445
+ break;
446
+ case ImageUploadStatusType.ERROR_IMAGE_TYPE:
447
+ content = this._localeService.t("update-status.invalidImageType");
448
+ break;
449
+ case ImageUploadStatusType.ERROR_IMAGE:
450
+ content = this._localeService.t("update-status.invalidImage");
451
+ break;
452
+ }
453
+ this._messageService.show({
454
+ type: MessageType.Error,
455
+ content
456
+ });
457
+ }
458
+ if (imageParams.length === 0)
459
+ return;
460
+ const { unitId } = this._context, docDrawingParams = [];
461
+ for (const imageParam of imageParams) {
462
+ if (imageParam == null)
463
+ continue;
464
+ const { imageId, imageSourceType, source, base64Cache } = imageParam, { width, height, image } = await getImageSize(base64Cache || "");
465
+ this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
466
+ let scale = 1;
467
+ if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
468
+ const scaleWidth = DRAWING_IMAGE_WIDTH_LIMIT / width, scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
469
+ scale = Math.min(scaleWidth, scaleHeight);
470
+ }
471
+ const docTransform = this._getImagePosition(width * scale, height * scale);
472
+ if (docTransform == null)
473
+ return;
474
+ const docDrawingParam = {
475
+ unitId,
476
+ subUnitId: unitId,
477
+ drawingId: imageId,
478
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
479
+ imageSourceType,
480
+ source,
481
+ transform: docDrawingPositionToTransform(docTransform),
482
+ docTransform,
483
+ behindDoc: BooleanNumber.FALSE,
484
+ title: "",
485
+ description: "",
486
+ layoutType: PositionedObjectLayoutType.INLINE,
487
+ // Insert inline drawing by default.
488
+ wrapText: WrapTextType.BOTH_SIDES,
489
+ distB: 0,
490
+ distL: 0,
491
+ distR: 0,
492
+ distT: 0
493
+ };
494
+ this._isInsertInHeaderFooter() && (docDrawingParam.isMultiTransform = BooleanNumber.TRUE, docDrawingParam.transforms = docDrawingParam.transform ? [docDrawingParam.transform] : null), docDrawingParams.push(docDrawingParam);
495
+ }
496
+ this._commandService.executeCommand(InsertDocDrawingCommand.id, {
497
+ unitId,
498
+ drawings: docDrawingParams
499
+ });
500
+ }
501
+ _isInsertInHeaderFooter() {
502
+ var _a8;
503
+ const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel(), editArea = viewModel == null ? void 0 : viewModel.getEditArea();
504
+ return editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER;
505
+ }
506
+ _getImagePosition(imageWidth, imageHeight) {
507
+ const activeTextRange = this._docSelectionRenderService.getActiveTextRange(), position = (activeTextRange == null ? void 0 : activeTextRange.getAbsolutePosition()) || {
508
+ left: 0,
509
+ top: 0
510
+ };
511
+ return {
512
+ size: {
513
+ width: imageWidth,
514
+ height: imageHeight
515
+ },
516
+ positionH: {
517
+ relativeFrom: ObjectRelativeFromH.PAGE,
518
+ posOffset: position.left
519
+ },
520
+ positionV: {
521
+ relativeFrom: ObjectRelativeFromV.MARGIN,
522
+ posOffset: position.top
523
+ },
524
+ angle: 0
525
+ };
526
+ }
527
+ _updateOrderListener() {
528
+ this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
529
+ const { unitId, subUnitId, drawingIds, arrangeType } = params;
530
+ this._commandService.executeCommand(SetDocDrawingArrangeCommand.id, {
531
+ unitId,
532
+ subUnitId,
533
+ drawingIds,
534
+ arrangeType
535
+ });
536
+ });
537
+ }
538
+ _groupDrawingListener() {
539
+ this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
540
+ this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
541
+ }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
542
+ this._commandService.executeCommand(UngroupDocDrawingCommand.id, params);
543
+ });
544
+ }
545
+ _getCurrentSceneAndTransformer() {
546
+ const { scene, mainComponent } = this._context;
547
+ if (scene == null || mainComponent == null)
548
+ return;
549
+ const transformer = scene.getTransformerByCreate(), { docsLeft, docsTop } = mainComponent.getOffsetConfig();
550
+ return { scene, transformer, docsLeft, docsTop };
551
+ }
552
+ _focusDrawingListener() {
553
+ this.disposeWithMe(
554
+ this._drawingManagerService.focus$.subscribe((params) => {
555
+ var _a8;
556
+ const { transformer, docsLeft, docsTop } = (_a8 = this._getCurrentSceneAndTransformer()) != null ? _a8 : {};
557
+ if (params == null || params.length === 0)
558
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._docDrawingService.focusDrawing([]), transformer && transformer.resetProps({
559
+ zeroTop: 0,
560
+ zeroLeft: 0
561
+ });
562
+ else {
563
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !0), this._docDrawingService.focusDrawing(params), this._docSelectionManagerService.getActiveTextRange() && this._docSelectionManagerService.replaceTextRanges([]);
564
+ const prevSegmentId = this._docSelectionRenderService.getSegment(), segmentId = this._findSegmentIdByDrawingId(params[0].drawingId);
565
+ prevSegmentId !== segmentId && this._docSelectionRenderService.setSegment(segmentId), transformer && transformer.resetProps({
566
+ zeroTop: docsTop,
567
+ zeroLeft: docsLeft
568
+ });
569
+ }
570
+ })
571
+ );
572
+ }
573
+ _findSegmentIdByDrawingId(drawingId) {
574
+ var _a8, _b, _c;
575
+ const { unit: DocDataModel } = this._context, { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
576
+ if (((_a8 = body == null ? void 0 : body.customBlocks) != null ? _a8 : []).some((b) => b.blockId === drawingId))
577
+ return "";
578
+ for (const headerId of Object.keys(headers))
579
+ if ((_b = headers[headerId].body.customBlocks) != null && _b.some((b) => b.blockId === drawingId))
580
+ return headerId;
581
+ for (const footerId of Object.keys(footers))
582
+ if ((_c = footers[footerId].body.customBlocks) != null && _c.some((b) => b.blockId === drawingId))
583
+ return footerId;
584
+ return "";
585
+ }
586
+ // Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
587
+ _updateDrawingsEditStatus() {
294
588
  var _a8;
295
- (_a8 = fileInputRef.current) == null || _a8.click();
296
- }, "handleButtonClick"), imageAccept = DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(","), handleFileChange = /* @__PURE__ */ __name((event) => {
297
- const fileList = event.target.files;
298
- if (fileList == null)
589
+ const { unit: docDataModel, scene, unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
590
+ if (viewModel == null || docDataModel == null)
299
591
  return;
300
- const files = Array.from(fileList);
301
- commandService.executeCommand(InsertDocImageOperation.id, { files }), fileInputRef.current && (fileInputRef.current.value = "");
302
- }, "handleFileChange");
303
- return /* @__PURE__ */ React.createElement("div", { onClick: handleButtonClick, className: styles$1.uploadFileMenu }, /* @__PURE__ */ React.createElement(
304
- "input",
305
- {
306
- type: "file",
307
- className: styles$1.uploadFileMenuInput,
308
- ref: fileInputRef,
309
- onChange: handleFileChange,
310
- accept: imageAccept,
311
- multiple: !0
592
+ const snapshot = docDataModel.getSnapshot(), { drawings = {} } = snapshot, isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
593
+ for (const key of Object.keys(drawings)) {
594
+ const drawing = drawings[key], objectKey = getDrawingShapeKeyByDrawingSearch({ unitId, drawingId: drawing.drawingId, subUnitId: unitId }), drawingShapes = scene.fuzzyMathObjects(objectKey, !0);
595
+ if (drawingShapes.length)
596
+ for (const shape of drawingShapes)
597
+ scene.detachTransformerFrom(shape), shape.setOpacity(0.5), (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) && (scene.attachTransformerTo(shape), shape.setOpacity(1));
312
598
  }
313
- ));
314
- }, "UploadFileMenu"), COMPONENT_DOC_UPLOAD_FILE_MENU = "COMPONENT_DOC_UPLOAD_FILE_MENU", ImageUploadIcon = "addition-and-subtraction-single", IMAGE_MENU_ID = "doc.menu.image", IMAGE_MENU_UPLOAD_FLOAT_ID = "doc.menu.image.upload.float", getDisableWhenSelectionInTableObservable = /* @__PURE__ */ __name((accessor) => {
315
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
599
+ }
600
+ _editAreaChangeListener() {
601
+ var _a8;
602
+ const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
603
+ viewModel != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
604
+ viewModel.editAreaChange$.subscribe(() => {
605
+ this._updateDrawingsEditStatus();
606
+ })
607
+ ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
608
+ skeleton != null && queueMicrotask(() => {
609
+ this._updateDrawingsEditStatus();
610
+ });
611
+ }), this.disposeWithMe(
612
+ this._commandService.onCommandExecuted(async (command) => {
613
+ command.id === RichTextEditingMutation.id && queueMicrotask(() => {
614
+ this._updateDrawingsEditStatus();
615
+ });
616
+ })
617
+ ));
618
+ }
619
+ }, __name(_a2, "DocDrawingUpdateRenderController"), _a2);
620
+ DocDrawingUpdateRenderController = __decorateClass$5([
621
+ __decorateParam$5(1, ICommandService),
622
+ __decorateParam$5(2, Inject(DocSelectionManagerService)),
623
+ __decorateParam$5(3, IRenderManagerService),
624
+ __decorateParam$5(4, IImageIoService),
625
+ __decorateParam$5(5, IDocDrawingService),
626
+ __decorateParam$5(6, IDrawingManagerService),
627
+ __decorateParam$5(7, IContextService),
628
+ __decorateParam$5(8, IMessageService),
629
+ __decorateParam$5(9, Inject(LocaleService)),
630
+ __decorateParam$5(10, Inject(DocSelectionRenderService)),
631
+ __decorateParam$5(11, Inject(DocRefreshDrawingsService)),
632
+ __decorateParam$5(12, ILocalFileService)
633
+ ], DocDrawingUpdateRenderController);
634
+ const InsertDocImageCommand = {
635
+ id: "doc.command.insert-float-image",
636
+ type: CommandType.COMMAND,
637
+ handler: /* @__PURE__ */ __name((accessor) => {
638
+ var _a8, _b;
639
+ return (_b = (_a8 = accessor.get(IRenderManagerService).getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a8.with(DocDrawingUpdateRenderController).insertDocImage()) != null ? _b : !1;
640
+ }, "handler")
641
+ }, ImageUploadIcon = "addition-and-subtraction-single", IMAGE_MENU_ID = "doc.menu.image", IMAGE_MENU_UPLOAD_FLOAT_ID = InsertDocImageCommand.id, getDisableWhenSelectionInTableObservable = /* @__PURE__ */ __name((accessor) => {
642
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
316
643
  return new Observable((subscriber) => {
317
- const observable = textSelectionManagerService.textSelection$.subscribe(() => {
644
+ const observable = docSelectionManagerService.textSelection$.subscribe(() => {
318
645
  var _a8;
319
- const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
646
+ const activeRange = docSelectionManagerService.getActiveTextRange();
320
647
  if (activeRange) {
321
648
  const { segmentId, startOffset, endOffset } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), tables = (_a8 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a8.tables;
322
649
  if (tables && tables.length && tables.some((table) => {
@@ -350,10 +677,7 @@ function UploadFloatImageMenuFactory(_accessor) {
350
677
  return {
351
678
  id: IMAGE_MENU_UPLOAD_FLOAT_ID,
352
679
  title: "docImage.upload.float",
353
- type: MenuItemType.SELECTOR,
354
- label: {
355
- name: COMPONENT_DOC_UPLOAD_FILE_MENU
356
- },
680
+ type: MenuItemType.BUTTON,
357
681
  hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC)
358
682
  };
359
683
  }
@@ -374,17 +698,7 @@ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "un
374
698
  imageCommonPanelInput,
375
699
  sheetImageMenu,
376
700
  sheetImageMenuInput
377
- }, _DocRefreshDrawingsService = class _DocRefreshDrawingsService {
378
- constructor() {
379
- __publicField(this, "_refreshDrawings$", new BehaviorSubject(null));
380
- __publicField(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
381
- }
382
- refreshDrawings(skeleton) {
383
- this._refreshDrawings$.next(skeleton);
384
- }
385
701
  };
386
- __name(_DocRefreshDrawingsService, "DocRefreshDrawingsService");
387
- let DocRefreshDrawingsService = _DocRefreshDrawingsService;
388
702
  var TextWrappingStyle = /* @__PURE__ */ ((TextWrappingStyle2) => (TextWrappingStyle2.INLINE = "inline", TextWrappingStyle2.BEHIND_TEXT = "behindText", TextWrappingStyle2.IN_FRONT_OF_TEXT = "inFrontOfText", TextWrappingStyle2.WRAP_SQUARE = "wrapSquare", TextWrappingStyle2.WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom", TextWrappingStyle2))(TextWrappingStyle || {});
389
703
  const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
390
704
  inline: PositionedObjectLayoutType.INLINE,
@@ -393,7 +707,7 @@ const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
393
707
  inFrontOfText: PositionedObjectLayoutType.WRAP_NONE,
394
708
  behindText: PositionedObjectLayoutType.WRAP_NONE
395
709
  };
396
- function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, textSelectionRenderManager) {
710
+ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, docSelectionRenderManager) {
397
711
  var _a8, _b;
398
712
  const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], oldBody = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId).getBody(), body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
399
713
  if (oldBody == null || body == null)
@@ -483,7 +797,7 @@ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPa
483
797
  len: 1,
484
798
  line: 0,
485
799
  segmentId
486
- }), path = getRichTextEditPath(documentDataModel, segmentId), action = jsonX.editOp(textX.serialize(), path), rawActions.push(action), textSelectionRenderManager.setSegment(segmentId), textSelectionRenderManager.setSegmentPage(segmentPage);
800
+ }), path = getRichTextEditPath(documentDataModel, segmentId), action = jsonX.editOp(textX.serialize(), path), rawActions.push(action), docSelectionRenderManager.setSegment(segmentId), docSelectionRenderManager.setSegmentPage(segmentPage);
487
801
  }
488
802
  return rawActions;
489
803
  }
@@ -669,11 +983,11 @@ const UpdateDocDrawingWrappingStyleCommand = {
669
983
  id: "doc.command.move-inline-drawing",
670
984
  type: CommandType.COMMAND,
671
985
  handler: /* @__PURE__ */ __name((accessor, params) => {
672
- var _a8;
986
+ var _a8, _b;
673
987
  if (params == null)
674
988
  return !1;
675
- const renderManagerService = accessor.get(IRenderManagerService), textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService), renderObject = renderManagerService.getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene, skeleton = renderObject == null ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
676
- if (scene == null)
989
+ const renderManagerService = accessor.get(IRenderManagerService), docSelectionRenderService = (_a8 = renderManagerService.getRenderById(params.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService), docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService), renderObject = renderManagerService.getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene, skeleton = renderObject == null ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
990
+ if (scene == null || docSelectionRenderService == null)
677
991
  return !1;
678
992
  const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
679
993
  if (documentDataModel == null)
@@ -681,14 +995,14 @@ const UpdateDocDrawingWrappingStyleCommand = {
681
995
  const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
682
996
  if (needRefreshDrawings)
683
997
  return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !0;
684
- const rawActions = [], { drawingId } = drawing, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", actions = getDeleteAndInsertCustomBlockActions(
998
+ const rawActions = [], { drawingId } = drawing, segmentId = (_b = docSelectionRenderService.getSegment()) != null ? _b : "", actions = getDeleteAndInsertCustomBlockActions(
685
999
  newSegmentId,
686
1000
  segmentId,
687
1001
  segmentPage,
688
1002
  offset,
689
1003
  drawingId,
690
1004
  documentDataModel,
691
- textSelectionRenderManager
1005
+ docSelectionRenderService
692
1006
  );
693
1007
  if (actions == null || actions.length === 0)
694
1008
  return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !1;
@@ -710,23 +1024,23 @@ const UpdateDocDrawingWrappingStyleCommand = {
710
1024
  type: CommandType.COMMAND,
711
1025
  // eslint-disable-next-line max-lines-per-function
712
1026
  handler: /* @__PURE__ */ __name((accessor, params) => {
713
- var _a8;
1027
+ var _a8, _b;
714
1028
  if (params == null)
715
1029
  return !1;
716
- const textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), renderObject = accessor.get(IRenderManagerService).getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene;
717
- if (scene == null)
1030
+ const renderManagerService = accessor.get(IRenderManagerService), docSelectionRenderService = (_a8 = renderManagerService.getRenderById(params.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService), renderObject = renderManagerService.getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene;
1031
+ if (scene == null || docSelectionRenderService == null)
718
1032
  return !1;
719
1033
  const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
720
1034
  if (documentDataModel == null)
721
1035
  return !1;
722
- const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", actions = getDeleteAndInsertCustomBlockActions(
1036
+ const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (_b = docSelectionRenderService.getSegment()) != null ? _b : "", actions = getDeleteAndInsertCustomBlockActions(
723
1037
  newSegmentId,
724
1038
  segmentId,
725
1039
  segmentPage,
726
1040
  offset,
727
1041
  drawingId,
728
1042
  documentDataModel,
729
- textSelectionRenderManager
1043
+ docSelectionRenderService
730
1044
  );
731
1045
  if (actions == null)
732
1046
  return !1;
@@ -942,7 +1256,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
942
1256
  }
943
1257
  )))))));
944
1258
  }, "DocDrawingTextWrap"), MIN_OFFSET = -1e3, MAX_OFFSET = 1e3, DocDrawingPosition = /* @__PURE__ */ __name((props) => {
945
- const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), textSelectionRenderService = useDependency(ITextSelectionRenderManager), { drawings } = props, drawingParam = drawings[0];
1259
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), { drawings } = props, drawingParam = drawings[0];
946
1260
  if (drawingParam == null)
947
1261
  return;
948
1262
  const { unitId } = drawingParam, documentDataModel = univerInstanceService.getUniverDocInstance(unitId), renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
@@ -977,6 +1291,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
977
1291
  posOffset: 0
978
1292
  }), [followTextMove, setFollowTextMove] = useState(!0), [showPanel, setShowPanel] = useState(!0);
979
1293
  function handlePositionChange(direction, value) {
1294
+ var _a8;
980
1295
  direction === "positionH" ? setHPosition(value) : setVPosition(value);
981
1296
  const focusDrawings = drawingManagerService.getFocusDrawings();
982
1297
  if (focusDrawings.length === 0)
@@ -994,7 +1309,9 @@ const UpdateDocDrawingWrappingStyleCommand = {
994
1309
  key: direction,
995
1310
  value
996
1311
  }))
997
- }), textSelectionRenderService.blur(), transformer.refreshControls();
1312
+ });
1313
+ const docSelectionRenderService = (_a8 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
1314
+ docSelectionRenderService && docSelectionRenderService.blur(), transformer.refreshControls();
998
1315
  }
999
1316
  __name(handlePositionChange, "handlePositionChange");
1000
1317
  function handleHorizontalRelativeFromChange(value) {
@@ -1040,17 +1357,17 @@ const UpdateDocDrawingWrappingStyleCommand = {
1040
1357
  }
1041
1358
  __name(handleHorizontalRelativeFromChange, "handleHorizontalRelativeFromChange");
1042
1359
  function handleVerticalRelativeFromChange(value) {
1043
- var _a8, _b, _c, _d, _e;
1360
+ var _a8, _b, _c, _d, _e, _f;
1044
1361
  const prevRelativeFrom = vPosition.relativeFrom, prevPosOffset = vPosition.posOffset, relativeFrom = Number(value);
1045
1362
  if (prevRelativeFrom === relativeFrom)
1046
1363
  return;
1047
1364
  const focusDrawings = drawingManagerService.getFocusDrawings();
1048
1365
  if (focusDrawings.length === 0)
1049
1366
  return;
1050
- const { drawingId, unitId: unitId2 } = focusDrawings[0], documentDataModel2 = univerInstanceService.getUniverDocInstance(unitId2), skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), segmentId = textSelectionRenderService.getSegment(), segmentPage = textSelectionRenderService.getSegmentPage(), drawing = (_c = (_b = documentDataModel2 == null ? void 0 : documentDataModel2.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.customBlocks) == null ? void 0 : _c.find((c) => c.blockId === drawingId);
1051
- if (drawing == null || skeleton == null)
1367
+ const { drawingId, unitId: unitId2 } = focusDrawings[0], documentDataModel2 = univerInstanceService.getUniverDocInstance(unitId2), skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), docSelectionRenderService = (_b = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _b.with(DocSelectionRenderService), segmentId = docSelectionRenderService == null ? void 0 : docSelectionRenderService.getSegment(), segmentPage = docSelectionRenderService == null ? void 0 : docSelectionRenderService.getSegmentPage(), drawing = (_d = (_c = documentDataModel2 == null ? void 0 : documentDataModel2.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.customBlocks) == null ? void 0 : _d.find((c) => c.blockId === drawingId);
1368
+ if (drawing == null || skeleton == null || docSelectionRenderService == null)
1052
1369
  return;
1053
- const { startIndex } = drawing, glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage), line = (_d = glyph == null ? void 0 : glyph.parent) == null ? void 0 : _d.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart), page = (_e = column == null ? void 0 : column.parent) == null ? void 0 : _e.parent;
1370
+ const { startIndex } = drawing, glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage), line = (_e = glyph == null ? void 0 : glyph.parent) == null ? void 0 : _e.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart), page = (_f = column == null ? void 0 : column.parent) == null ? void 0 : _f.parent;
1054
1371
  if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null)
1055
1372
  return;
1056
1373
  let delta = 0;
@@ -1185,156 +1502,37 @@ const UpdateDocDrawingWrappingStyleCommand = {
1185
1502
  drawingId,
1186
1503
  key: direction === Direction.UP || direction === Direction.DOWN ? "positionV" : "positionH",
1187
1504
  value: direction === Direction.UP || direction === Direction.DOWN ? newPositionV : newPositionH
1188
- };
1189
- }).filter((drawing) => drawing != null);
1190
- if (newDrawings.length === 0)
1191
- return !1;
1192
- const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
1193
- unitId,
1194
- subUnitId: unitId,
1195
- drawings: newDrawings
1196
- });
1197
- return transformer.refreshControls(), !!result;
1198
- }, "handler")
1199
- }, DeleteDocDrawingsCommand = {
1200
- id: "doc.command.delete-drawing",
1201
- type: CommandType.COMMAND,
1202
- handler: /* @__PURE__ */ __name((accessor) => {
1203
- const commandService = accessor.get(ICommandService), drawings = accessor.get(IDocDrawingService).getFocusDrawings();
1204
- if (drawings.length === 0)
1205
- return !1;
1206
- const { unitId } = drawings[0], newDrawings = drawings.map((drawing) => {
1207
- const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
1208
- return {
1209
- unitId: unitId2,
1210
- subUnitId,
1211
- drawingId,
1212
- drawingType
1213
- };
1214
- });
1215
- return commandService.executeCommand(RemoveDocDrawingCommand.id, {
1216
- unitId,
1217
- drawings: newDrawings
1218
- });
1219
- }, "handler")
1220
- }, SetDocDrawingArrangeCommand = {
1221
- id: "doc.command.set-drawing-arrange",
1222
- type: CommandType.COMMAND,
1223
- handler: /* @__PURE__ */ __name((accessor, params) => {
1224
- const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService);
1225
- if (params == null)
1226
- return !1;
1227
- const { unitId, subUnitId, drawingIds, arrangeType } = params, drawingOrderMapParam = { unitId, subUnitId, drawingIds };
1228
- let jsonOp;
1229
- if (arrangeType === ArrangeTypeEnum.forward ? jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.backward ? jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.front ? jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.back && (jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam)), jsonOp == null)
1230
- return !1;
1231
- const { redo } = jsonOp;
1232
- if (redo == null)
1233
- return !1;
1234
- const rawActions = [];
1235
- let redoCopy = Tools.deepClone(redo);
1236
- redoCopy = redoCopy.slice(3), redoCopy.unshift("drawingsOrder"), rawActions.push(redoCopy);
1237
- const doMutation = {
1238
- id: RichTextEditingMutation.id,
1239
- params: {
1240
- unitId,
1241
- actions: [],
1242
- textRanges: null
1243
- }
1244
- };
1245
- return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1246
- }, "handler")
1247
- }, UngroupDocDrawingCommand = {
1248
- id: "doc.command.ungroup-doc-image",
1249
- type: CommandType.COMMAND,
1250
- handler: /* @__PURE__ */ __name((accessor, params) => {
1251
- accessor.get(ICommandService), accessor.get(IUndoRedoService);
1252
- const docDrawingService = accessor.get(IDocDrawingService);
1253
- if (!params) return !1;
1254
- const unitIds = [];
1255
- return params.forEach(({ parent, children }) => {
1256
- unitIds.push(parent.unitId), children.forEach((child) => {
1257
- unitIds.push(child.unitId);
1258
- });
1259
- }), docDrawingService.getUngroupDrawingOp(params), !1;
1260
- }, "handler")
1261
- }, GroupDocDrawingCommand = {
1262
- id: "doc.command.group-doc-image",
1263
- type: CommandType.COMMAND,
1264
- handler: /* @__PURE__ */ __name((accessor, params) => {
1265
- accessor.get(ICommandService), accessor.get(IUndoRedoService);
1266
- const docDrawingService = accessor.get(IDocDrawingService);
1267
- if (!params) return !1;
1268
- const unitIds = [];
1269
- return params.forEach(({ parent, children }) => {
1270
- unitIds.push(parent.unitId), children.forEach((child) => {
1271
- unitIds.push(child.unitId);
1272
- });
1273
- }), docDrawingService.getGroupDrawingOp(params), !1;
1274
- }, "handler")
1275
- }, InsertDocDrawingCommand = {
1276
- id: "doc.command.insert-doc-image",
1277
- type: CommandType.COMMAND,
1278
- // eslint-disable-next-line max-lines-per-function
1279
- handler: /* @__PURE__ */ __name((accessor, params) => {
1280
- var _a8, _b, _c, _d;
1281
- if (params == null)
1282
- return !1;
1283
- const commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
1284
- if (activeTextRange == null || documentDataModel == null)
1285
- return !1;
1286
- const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1287
- if (body == null)
1288
- return !1;
1289
- const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
1290
- let removeDrawingLen = 0;
1291
- if (collapsed)
1292
- startOffset > 0 && textX.push({
1293
- t: TextXActionType.RETAIN,
1294
- len: startOffset,
1295
- segmentId
1296
- });
1297
- else {
1298
- const { dos } = getRetainAndDeleteFromReplace(activeTextRange, segmentId, 0, body);
1299
- textX.push(...dos);
1300
- const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [activeTextRange]), drawings2 = (_c = documentDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = documentDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
1301
- if (sortedRemovedCustomBlockIds.length > 0)
1302
- for (const blockId of sortedRemovedCustomBlockIds) {
1303
- const drawing = drawings2[blockId], drawingIndex = drawingOrder.indexOf(blockId);
1304
- if (drawing == null || drawingIndex < 0)
1305
- continue;
1306
- const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
1307
- rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), removeDrawingLen++;
1308
- }
1309
- }
1310
- textX.push({
1311
- t: TextXActionType.INSERT,
1312
- body: {
1313
- dataStream: "\b".repeat(drawings.length),
1314
- customBlocks: drawings.map((drawing, i) => ({
1315
- startIndex: i,
1316
- blockId: drawing.drawingId
1317
- }))
1318
- },
1319
- len: drawings.length,
1320
- line: 0,
1321
- segmentId
1505
+ };
1506
+ }).filter((drawing) => drawing != null);
1507
+ if (newDrawings.length === 0)
1508
+ return !1;
1509
+ const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
1510
+ unitId,
1511
+ subUnitId: unitId,
1512
+ drawings: newDrawings
1513
+ });
1514
+ return transformer.refreshControls(), !!result;
1515
+ }, "handler")
1516
+ }, DeleteDocDrawingsCommand = {
1517
+ id: "doc.command.delete-drawing",
1518
+ type: CommandType.COMMAND,
1519
+ handler: /* @__PURE__ */ __name((accessor) => {
1520
+ const commandService = accessor.get(ICommandService), drawings = accessor.get(IDocDrawingService).getFocusDrawings();
1521
+ if (drawings.length === 0)
1522
+ return !1;
1523
+ const { unitId } = drawings[0], newDrawings = drawings.map((drawing) => {
1524
+ const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
1525
+ return {
1526
+ unitId: unitId2,
1527
+ subUnitId,
1528
+ drawingId,
1529
+ drawingType
1530
+ };
1531
+ });
1532
+ return commandService.executeCommand(RemoveDocDrawingCommand.id, {
1533
+ unitId,
1534
+ drawings: newDrawings
1322
1535
  });
1323
- const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
1324
- rawActions.push(placeHolderAction);
1325
- for (const drawing of drawings) {
1326
- const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
1327
- rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
1328
- }
1329
- const doMutation = {
1330
- id: RichTextEditingMutation.id,
1331
- params: {
1332
- unitId,
1333
- actions: [],
1334
- textRanges: []
1335
- }
1336
- };
1337
- return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1338
1536
  }, "handler")
1339
1537
  };
1340
1538
  function whenDocDrawingFocused(contextService) {
@@ -1401,25 +1599,25 @@ const MoveDrawingDownShortcutItem = {
1401
1599
  }
1402
1600
  }
1403
1601
  };
1404
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1405
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1602
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1603
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1406
1604
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1407
- return kind && result && __defProp$5(target, key, result), result;
1408
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a2;
1409
- let DocDrawingUIController = (_a2 = class extends Disposable {
1410
- constructor(_injector, _componentManager, _menuManagerService, _commandService, _shortcutService) {
1411
- super(), this._injector = _injector, this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
1605
+ return kind && result && __defProp$4(target, key, result), result;
1606
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
1607
+ let DocDrawingUIController = (_a3 = class extends Disposable {
1608
+ constructor(_componentManager, _menuManagerService, _commandService, _shortcutService) {
1609
+ super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
1412
1610
  }
1413
1611
  _initCustomComponents() {
1414
1612
  const componentManager = this._componentManager;
1415
- this.disposeWithMe(componentManager.register(ImageUploadIcon, AddImageSingle)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_UPLOAD_FILE_MENU, UploadFileMenu)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
1613
+ this.disposeWithMe(componentManager.register(ImageUploadIcon, AddImageSingle)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
1416
1614
  }
1417
1615
  _initMenus() {
1418
1616
  this._menuManagerService.mergeMenu(menuSchema);
1419
1617
  }
1420
1618
  _initCommands() {
1421
1619
  [
1422
- InsertDocImageOperation,
1620
+ InsertDocImageCommand,
1423
1621
  InsertDocDrawingCommand,
1424
1622
  UpdateDocDrawingWrappingStyleCommand,
1425
1623
  UpdateDocDrawingDistanceCommand,
@@ -1453,251 +1651,14 @@ let DocDrawingUIController = (_a2 = class extends Disposable {
1453
1651
  _init() {
1454
1652
  this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
1455
1653
  }
1456
- }, __name(_a2, "DocDrawingUIController"), _a2);
1457
- DocDrawingUIController = __decorateClass$5([
1654
+ }, __name(_a3, "DocDrawingUIController"), _a3);
1655
+ DocDrawingUIController = __decorateClass$4([
1458
1656
  OnLifecycle(LifecycleStages.Ready, DocDrawingUIController),
1459
- __decorateParam$5(0, Inject(Injector)),
1460
- __decorateParam$5(1, Inject(ComponentManager)),
1461
- __decorateParam$5(2, IMenuManagerService),
1462
- __decorateParam$5(3, ICommandService),
1463
- __decorateParam$5(4, IShortcutService)
1657
+ __decorateParam$4(0, Inject(ComponentManager)),
1658
+ __decorateParam$4(1, IMenuManagerService),
1659
+ __decorateParam$4(2, ICommandService),
1660
+ __decorateParam$4(3, IShortcutService)
1464
1661
  ], DocDrawingUIController);
1465
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1466
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1467
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1468
- return kind && result && __defProp$4(target, key, result), result;
1469
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
1470
- let DocDrawingUpdateRenderController = (_a3 = class extends Disposable {
1471
- constructor(_context, _commandService, _textSelectionManagerService, _renderManagerSrv, _imageIoService, _docDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, _textSelectionManager, _textSelectionRenderManager, _docRefreshDrawingsService) {
1472
- super(), this._context = _context, this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._renderManagerSrv = _renderManagerSrv, this._imageIoService = _imageIoService, this._docDrawingService = _docDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._textSelectionManager = _textSelectionManager, this._textSelectionRenderManager = _textSelectionRenderManager, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._initCommandListeners(), this._updateDrawingListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._editAreaChangeListener();
1473
- }
1474
- /**
1475
- * Upload image to cell or float image
1476
- */
1477
- _initCommandListeners() {
1478
- this.disposeWithMe(
1479
- this._commandService.onCommandExecuted(async (command) => {
1480
- if (command.id === InsertDocImageOperation.id) {
1481
- const params = command.params;
1482
- if (params.files == null)
1483
- return;
1484
- const fileLength = params.files.length;
1485
- if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
1486
- this._messageService.show({
1487
- type: MessageType.Error,
1488
- content: this._localeService.t("update-status.exceedMaxCount", String(DRAWING_IMAGE_COUNT_LIMIT))
1489
- });
1490
- return;
1491
- }
1492
- this._imageIoService.setWaitCount(fileLength), await this._insertFloatImages(params.files);
1493
- }
1494
- })
1495
- );
1496
- }
1497
- // eslint-disable-next-line max-lines-per-function
1498
- async _insertFloatImages(files) {
1499
- let imageParams = [];
1500
- try {
1501
- imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
1502
- } catch (error) {
1503
- const type = error.message;
1504
- let content = "";
1505
- switch (type) {
1506
- case ImageUploadStatusType.ERROR_EXCEED_SIZE:
1507
- content = this._localeService.t("update-status.exceedMaxSize", String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024)));
1508
- break;
1509
- case ImageUploadStatusType.ERROR_IMAGE_TYPE:
1510
- content = this._localeService.t("update-status.invalidImageType");
1511
- break;
1512
- case ImageUploadStatusType.ERROR_IMAGE:
1513
- content = this._localeService.t("update-status.invalidImage");
1514
- break;
1515
- }
1516
- this._messageService.show({
1517
- type: MessageType.Error,
1518
- content
1519
- });
1520
- }
1521
- if (imageParams.length === 0)
1522
- return;
1523
- const { unitId } = this._context, docDrawingParams = [];
1524
- for (const imageParam of imageParams) {
1525
- if (imageParam == null)
1526
- continue;
1527
- const { imageId, imageSourceType, source, base64Cache } = imageParam, { width, height, image } = await getImageSize(base64Cache || "");
1528
- this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
1529
- let scale = 1;
1530
- if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
1531
- const scaleWidth = DRAWING_IMAGE_WIDTH_LIMIT / width, scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
1532
- scale = Math.min(scaleWidth, scaleHeight);
1533
- }
1534
- const docTransform = this._getImagePosition(width * scale, height * scale);
1535
- if (docTransform == null)
1536
- return;
1537
- const docDrawingParam = {
1538
- unitId,
1539
- subUnitId: unitId,
1540
- drawingId: imageId,
1541
- drawingType: DrawingTypeEnum.DRAWING_IMAGE,
1542
- imageSourceType,
1543
- source,
1544
- transform: docDrawingPositionToTransform(docTransform),
1545
- docTransform,
1546
- behindDoc: BooleanNumber.FALSE,
1547
- title: "",
1548
- description: "",
1549
- layoutType: PositionedObjectLayoutType.INLINE,
1550
- // Insert inline drawing by default.
1551
- wrapText: WrapTextType.BOTH_SIDES,
1552
- distB: 0,
1553
- distL: 0,
1554
- distR: 0,
1555
- distT: 0
1556
- };
1557
- this._isInsertInHeaderFooter() && (docDrawingParam.isMultiTransform = BooleanNumber.TRUE, docDrawingParam.transforms = docDrawingParam.transform ? [docDrawingParam.transform] : null), docDrawingParams.push(docDrawingParam);
1558
- }
1559
- this._commandService.executeCommand(InsertDocDrawingCommand.id, {
1560
- unitId,
1561
- drawings: docDrawingParams
1562
- });
1563
- }
1564
- _isInsertInHeaderFooter() {
1565
- var _a8;
1566
- const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel(), editArea = viewModel == null ? void 0 : viewModel.getEditArea();
1567
- return editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER;
1568
- }
1569
- _getImagePosition(imageWidth, imageHeight) {
1570
- const activeTextRange = this._textSelectionManagerService.getActiveTextRange(), position = (activeTextRange == null ? void 0 : activeTextRange.getAbsolutePosition()) || {
1571
- left: 0,
1572
- top: 0
1573
- };
1574
- return {
1575
- size: {
1576
- width: imageWidth,
1577
- height: imageHeight
1578
- },
1579
- positionH: {
1580
- relativeFrom: ObjectRelativeFromH.PAGE,
1581
- posOffset: position.left
1582
- },
1583
- positionV: {
1584
- relativeFrom: ObjectRelativeFromV.MARGIN,
1585
- posOffset: position.top
1586
- },
1587
- angle: 0
1588
- };
1589
- }
1590
- _updateOrderListener() {
1591
- this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
1592
- const { unitId, subUnitId, drawingIds, arrangeType } = params;
1593
- this._commandService.executeCommand(SetDocDrawingArrangeCommand.id, {
1594
- unitId,
1595
- subUnitId,
1596
- drawingIds,
1597
- arrangeType
1598
- });
1599
- });
1600
- }
1601
- _updateDrawingListener() {
1602
- this._drawingManagerService.featurePluginUpdate$.subscribe((params) => {
1603
- });
1604
- }
1605
- _groupDrawingListener() {
1606
- this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
1607
- this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
1608
- }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
1609
- this._commandService.executeCommand(UngroupDocDrawingCommand.id, params);
1610
- });
1611
- }
1612
- _getCurrentSceneAndTransformer() {
1613
- const { scene, mainComponent } = this._context;
1614
- if (scene == null || mainComponent == null)
1615
- return;
1616
- const transformer = scene.getTransformerByCreate(), { docsLeft, docsTop } = mainComponent.getOffsetConfig();
1617
- return { scene, transformer, docsLeft, docsTop };
1618
- }
1619
- _focusDrawingListener() {
1620
- this.disposeWithMe(
1621
- this._drawingManagerService.focus$.subscribe((params) => {
1622
- var _a8;
1623
- const { transformer, docsLeft, docsTop } = (_a8 = this._getCurrentSceneAndTransformer()) != null ? _a8 : {};
1624
- if (params == null || params.length === 0)
1625
- this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._docDrawingService.focusDrawing([]), transformer && transformer.resetProps({
1626
- zeroTop: 0,
1627
- zeroLeft: 0
1628
- });
1629
- else {
1630
- this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !0), this._docDrawingService.focusDrawing(params), this._textSelectionManager.getActiveTextRange() && this._textSelectionManager.replaceTextRanges([]);
1631
- const prevSegmentId = this._textSelectionRenderManager.getSegment(), segmentId = this._findSegmentIdByDrawingId(params[0].drawingId);
1632
- prevSegmentId !== segmentId && this._textSelectionRenderManager.setSegment(segmentId), transformer && transformer.resetProps({
1633
- zeroTop: docsTop,
1634
- zeroLeft: docsLeft
1635
- });
1636
- }
1637
- })
1638
- );
1639
- }
1640
- _findSegmentIdByDrawingId(drawingId) {
1641
- var _a8, _b, _c;
1642
- const { unit: DocDataModel } = this._context, { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
1643
- if (((_a8 = body == null ? void 0 : body.customBlocks) != null ? _a8 : []).some((b) => b.blockId === drawingId))
1644
- return "";
1645
- for (const headerId of Object.keys(headers))
1646
- if ((_b = headers[headerId].body.customBlocks) != null && _b.some((b) => b.blockId === drawingId))
1647
- return headerId;
1648
- for (const footerId of Object.keys(footers))
1649
- if ((_c = footers[footerId].body.customBlocks) != null && _c.some((b) => b.blockId === drawingId))
1650
- return footerId;
1651
- return "";
1652
- }
1653
- // Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
1654
- _updateDrawingsEditStatus() {
1655
- var _a8;
1656
- const { unit: docDataModel, scene, unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
1657
- if (viewModel == null || docDataModel == null)
1658
- return;
1659
- const snapshot = docDataModel.getSnapshot(), { drawings = {} } = snapshot, isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
1660
- for (const key of Object.keys(drawings)) {
1661
- const drawing = drawings[key], objectKey = getDrawingShapeKeyByDrawingSearch({ unitId, drawingId: drawing.drawingId, subUnitId: unitId }), drawingShapes = scene.fuzzyMathObjects(objectKey, !0);
1662
- if (drawingShapes.length)
1663
- for (const shape of drawingShapes)
1664
- scene.detachTransformerFrom(shape), shape.setOpacity(0.5), (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) && (scene.attachTransformerTo(shape), shape.setOpacity(1));
1665
- }
1666
- }
1667
- _editAreaChangeListener() {
1668
- var _a8;
1669
- const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
1670
- viewModel != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
1671
- viewModel.editAreaChange$.subscribe(() => {
1672
- this._updateDrawingsEditStatus();
1673
- })
1674
- ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
1675
- skeleton != null && queueMicrotask(() => {
1676
- this._updateDrawingsEditStatus();
1677
- });
1678
- }), this.disposeWithMe(
1679
- this._commandService.onCommandExecuted(async (command) => {
1680
- command.id === RichTextEditingMutation.id && queueMicrotask(() => {
1681
- this._updateDrawingsEditStatus();
1682
- });
1683
- })
1684
- ));
1685
- }
1686
- }, __name(_a3, "DocDrawingUpdateRenderController"), _a3);
1687
- DocDrawingUpdateRenderController = __decorateClass$4([
1688
- __decorateParam$4(1, ICommandService),
1689
- __decorateParam$4(2, Inject(TextSelectionManagerService)),
1690
- __decorateParam$4(3, IRenderManagerService),
1691
- __decorateParam$4(4, IImageIoService),
1692
- __decorateParam$4(5, IDocDrawingService),
1693
- __decorateParam$4(6, IDrawingManagerService),
1694
- __decorateParam$4(7, IContextService),
1695
- __decorateParam$4(8, IMessageService),
1696
- __decorateParam$4(9, Inject(LocaleService)),
1697
- __decorateParam$4(10, Inject(TextSelectionManagerService)),
1698
- __decorateParam$4(11, ITextSelectionRenderManager),
1699
- __decorateParam$4(12, Inject(DocRefreshDrawingsService))
1700
- ], DocDrawingUpdateRenderController);
1701
1662
  var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1702
1663
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1703
1664
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -1983,14 +1944,14 @@ function isInTableCell(nodePosition) {
1983
1944
  __name(isInTableCell, "isInTableCell");
1984
1945
  var _a6;
1985
1946
  let DocDrawingTransformerController = (_a6 = class extends Disposable {
1986
- constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService, _textSelectionRenderManager) {
1947
+ constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
1987
1948
  super();
1988
1949
  __publicField(this, "_liquid", new Liquid());
1989
1950
  __publicField(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
1990
1951
  // Use to cache the drawings is under transforming or scaling.
1991
1952
  __publicField(this, "_transformerCache", /* @__PURE__ */ new Map());
1992
1953
  __publicField(this, "_anchorShape");
1993
- this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._init();
1954
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._init();
1994
1955
  }
1995
1956
  _init() {
1996
1957
  this._listenDrawingFocus();
@@ -2144,7 +2105,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2144
2105
  contentBoxPointGroup != null && this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2145
2106
  }
2146
2107
  _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
2147
- var _a8;
2108
+ var _a8, _b;
2148
2109
  const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2149
2110
  if (currentRender == null)
2150
2111
  return;
@@ -2157,6 +2118,9 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2157
2118
  const HALF = 0.5, coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
2158
2119
  if (coord == null)
2159
2120
  return;
2121
+ const docSelectionRenderService = (_a8 = this._renderManagerService.getRenderById(drawing.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
2122
+ if (docSelectionRenderService == null)
2123
+ return;
2160
2124
  const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(
2161
2125
  coord,
2162
2126
  pageLayoutType,
@@ -2164,8 +2128,8 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2164
2128
  pageMarginTop,
2165
2129
  {
2166
2130
  strict: !1,
2167
- segmentId: this._textSelectionRenderManager.getSegment(),
2168
- segmentPage: this._textSelectionRenderManager.getSegmentPage()
2131
+ segmentId: docSelectionRenderService.getSegment(),
2132
+ segmentPage: docSelectionRenderService.getSegmentPage()
2169
2133
  }
2170
2134
  );
2171
2135
  if (nodeInfo) {
@@ -2180,13 +2144,13 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2180
2144
  const positionWithIsBack = {
2181
2145
  ...nodePosition,
2182
2146
  isBack
2183
- }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList, contentBoxPointGroup } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_a8 = getOneTextSelectionRange(cursorList)) != null ? _a8 : {};
2147
+ }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList, contentBoxPointGroup } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_b = getOneTextSelectionRange(cursorList)) != null ? _b : {};
2184
2148
  if (startOffset != null)
2185
2149
  return { offset: startOffset, contentBoxPointGroup, segmentId, segmentPage: segmentPageIndex };
2186
2150
  }
2187
2151
  // eslint-disable-next-line max-lines-per-function, complexity
2188
2152
  _getDrawingAnchor(drawing, object) {
2189
- var _a8, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2153
+ var _a8, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2190
2154
  const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton(), skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData();
2191
2155
  if (skeletonData == null || currentRender == null)
2192
2156
  return;
@@ -2205,10 +2169,13 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2205
2169
  }, { x, y } = scene.getViewportScrollXY(activeViewport), coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
2206
2170
  if (coord == null)
2207
2171
  return;
2172
+ const docSelectionRenderService = (_a8 = this._renderManagerService.getRenderById(drawing.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
2173
+ if (docSelectionRenderService == null)
2174
+ return;
2208
2175
  const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2209
2176
  strict: !1,
2210
- segmentId: this._textSelectionRenderManager.getSegment(),
2211
- segmentPage: this._textSelectionRenderManager.getSegmentPage()
2177
+ segmentId: docSelectionRenderService.getSegment(),
2178
+ segmentPage: docSelectionRenderService.getSegmentPage()
2212
2179
  });
2213
2180
  if (nodeInfo) {
2214
2181
  const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
@@ -2216,7 +2183,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2216
2183
  }
2217
2184
  if (glyphAnchor == null)
2218
2185
  return;
2219
- const line = (_a8 = glyphAnchor.parent) == null ? void 0 : _a8.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = (_b = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart)) != null ? _b : column == null ? void 0 : column.lines[0], page = (_c = column == null ? void 0 : column.parent) == null ? void 0 : _c.parent;
2186
+ const line = (_b = glyphAnchor.parent) == null ? void 0 : _b.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = (_c = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart)) != null ? _c : column == null ? void 0 : column.lines[0], page = (_d = column == null ? void 0 : column.parent) == null ? void 0 : _d.parent;
2220
2187
  if (line == null || column == null || paragraphStartLine == null || page == null)
2221
2188
  return;
2222
2189
  this._liquid.reset();
@@ -2226,7 +2193,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2226
2193
  if (segmentPage > -1 && pIndex === segmentPage) {
2227
2194
  switch (pageType) {
2228
2195
  case DocumentSkeletonPageType.HEADER: {
2229
- const headerSke = (_d = skeHeaders.get(headerId)) == null ? void 0 : _d.get(pageWidth);
2196
+ const headerSke = (_e = skeHeaders.get(headerId)) == null ? void 0 : _e.get(pageWidth);
2230
2197
  if (headerSke)
2231
2198
  this._liquid.translatePagePadding({
2232
2199
  marginTop: headerSke.marginTop,
@@ -2237,7 +2204,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2237
2204
  break;
2238
2205
  }
2239
2206
  case DocumentSkeletonPageType.FOOTER: {
2240
- const footerSke = (_e = skeFooters.get(footerId)) == null ? void 0 : _e.get(pageWidth);
2207
+ const footerSke = (_f = skeFooters.get(footerId)) == null ? void 0 : _f.get(pageWidth);
2241
2208
  if (footerSke)
2242
2209
  this._liquid.translatePagePadding({
2243
2210
  marginTop: pageHeight - marginBottom + footerSke.marginTop,
@@ -2254,7 +2221,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2254
2221
  break;
2255
2222
  this._liquid.restorePagePadding(p), this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
2256
2223
  }
2257
- switch (positionV.relativeFrom === ObjectRelativeFromV.LINE ? glyphAnchor = line.divides[0].glyphGroup[0] : glyphAnchor = (_i = (_h = (_g = (_f = paragraphStartLine.divides) == null ? void 0 : _f[0]) == null ? void 0 : _g.glyphGroup) == null ? void 0 : _h[0]) != null ? _i : glyphAnchor, docTransform.positionH = {
2224
+ switch (positionV.relativeFrom === ObjectRelativeFromV.LINE ? glyphAnchor = line.divides[0].glyphGroup[0] : glyphAnchor = (_j = (_i = (_h = (_g = paragraphStartLine.divides) == null ? void 0 : _g[0]) == null ? void 0 : _h.glyphGroup) == null ? void 0 : _i[0]) != null ? _j : glyphAnchor, docTransform.positionH = {
2258
2225
  relativeFrom: positionH.relativeFrom,
2259
2226
  posOffset: left - this._liquid.x - docsLeft
2260
2227
  }, positionH.relativeFrom) {
@@ -2292,7 +2259,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2292
2259
  const positionWithIsBack = {
2293
2260
  ...nodePosition,
2294
2261
  isBack
2295
- }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_j = getOneTextSelectionRange(cursorList)) != null ? _j : {};
2262
+ }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_k = getOneTextSelectionRange(cursorList)) != null ? _k : {};
2296
2263
  if (startOffset != null)
2297
2264
  return { offset: startOffset, docTransform, segmentId, segmentPage };
2298
2265
  }
@@ -2457,8 +2424,7 @@ DocDrawingTransformerController = __decorateClass$1([
2457
2424
  __decorateParam$1(0, ICommandService),
2458
2425
  __decorateParam$1(1, IUniverInstanceService),
2459
2426
  __decorateParam$1(2, IDrawingManagerService),
2460
- __decorateParam$1(3, IRenderManagerService),
2461
- __decorateParam$1(4, ITextSelectionRenderManager)
2427
+ __decorateParam$1(3, IRenderManagerService)
2462
2428
  ], DocDrawingTransformerController);
2463
2429
  const PLUGIN_CONFIG_KEY = "docs-drawing-ui.config", defaultPluginConfig = {};
2464
2430
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
@@ -2466,7 +2432,7 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
2466
2432
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2467
2433
  return kind && result && __defProp2(target, key, result), result;
2468
2434
  }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField");
2469
- const PLUGIN_NAME = "DOCS_DRAWING_UI_PLUGIN";
2435
+ const PLUGIN_NAME = "DOC_DRAWING_UI_PLUGIN";
2470
2436
  var _a7;
2471
2437
  let UniverDocsDrawingUIPlugin = (_a7 = class extends Plugin {
2472
2438
  constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
@@ -2499,14 +2465,13 @@ UniverDocsDrawingUIPlugin = __decorateClass([
2499
2465
  __decorateParam(3, IConfigService)
2500
2466
  ], UniverDocsDrawingUIPlugin);
2501
2467
  export {
2502
- COMPONENT_DOC_UPLOAD_FILE_MENU,
2503
2468
  ClearDocDrawingTransformerOperation,
2504
2469
  DeleteDocDrawingsCommand,
2505
2470
  EditDocDrawingOperation,
2506
2471
  GroupDocDrawingCommand,
2507
2472
  IMAGE_MENU_ID,
2508
2473
  InsertDocDrawingCommand,
2509
- InsertDocImageOperation,
2474
+ InsertDocImageCommand,
2510
2475
  MoveDocDrawingsCommand,
2511
2476
  RemoveDocDrawingCommand,
2512
2477
  SetDocDrawingArrangeCommand,