@univerjs/sheets-drawing-ui 1.0.4 → 1.1.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/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, ILogService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DEFAULT_TRANSFORMER_CONFIG, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_EXTENSION_TYPE, SHEET_VIEWPORT_KEY, SheetExtension, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, DropdownMenu, FormLayout, Input, MessageType, MobileSelect, Radio, RadioGroup, Select, borderClassName, clsx, render, unmount } from "@univerjs/design";
@@ -427,7 +427,7 @@ function readUint32Be(bytes, offset) {
427
427
  }
428
428
 
429
429
  //#endregion
430
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
430
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
431
431
  function _typeof(o) {
432
432
  "@babel/helpers - typeof";
433
433
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -438,7 +438,7 @@ function _typeof(o) {
438
438
  }
439
439
 
440
440
  //#endregion
441
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
441
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
442
442
  function toPrimitive(t, r) {
443
443
  if ("object" != _typeof(t) || !t) return t;
444
444
  var e = t[Symbol.toPrimitive];
@@ -451,14 +451,14 @@ function toPrimitive(t, r) {
451
451
  }
452
452
 
453
453
  //#endregion
454
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
454
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
455
455
  function toPropertyKey(t) {
456
456
  var i = toPrimitive(t, "string");
457
457
  return "symbol" == _typeof(i) ? i : i + "";
458
458
  }
459
459
 
460
460
  //#endregion
461
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
461
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
462
462
  function _defineProperty(e, r, t) {
463
463
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
464
464
  value: t,
@@ -469,7 +469,7 @@ function _defineProperty(e, r, t) {
469
469
  }
470
470
 
471
471
  //#endregion
472
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
472
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
473
473
  function __decorateParam(paramIndex, decorator) {
474
474
  return function(target, key) {
475
475
  decorator(target, key, paramIndex);
@@ -477,7 +477,7 @@ function __decorateParam(paramIndex, decorator) {
477
477
  }
478
478
 
479
479
  //#endregion
480
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
480
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
481
481
  function __decorate(decorators, target, key, desc) {
482
482
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
483
483
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3070,7 +3070,12 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3070
3070
  domAnchor,
3071
3071
  unitId,
3072
3072
  subUnitId,
3073
- id: drawingId
3073
+ id: drawingId,
3074
+ runtimeMetadata: {
3075
+ componentKey,
3076
+ data,
3077
+ allowTransform
3078
+ }
3074
3079
  };
3075
3080
  const initedPosition = calcSheetFloatDomPosition(domRect, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet, floatDomInfo);
3076
3081
  const position$ = new BehaviorSubject(initedPosition);
@@ -3274,7 +3279,12 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3274
3279
  right: viewMain.right
3275
3280
  },
3276
3281
  domAnchor: domLayoutParam,
3277
- scrollDirectionResponse: "HORIZONTAL"
3282
+ scrollDirectionResponse: "HORIZONTAL",
3283
+ runtimeMetadata: {
3284
+ componentKey,
3285
+ data,
3286
+ allowTransform
3287
+ }
3278
3288
  };
3279
3289
  const initedPosition = calcSheetFloatDomPosition(domRect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet, floatDomInfo);
3280
3290
  const position$ = new BehaviorSubject(initedPosition);
@@ -3717,7 +3727,7 @@ const menuSchema = {
3717
3727
  //#endregion
3718
3728
  //#region package.json
3719
3729
  var name = "@univerjs/sheets-drawing-ui";
3720
- var version = "1.0.4";
3730
+ var version = "1.1.0";
3721
3731
 
3722
3732
  //#endregion
3723
3733
  //#region src/config/config.ts
@@ -4898,13 +4908,14 @@ SheetCellImageCopyPasteController = __decorate([
4898
4908
  //#endregion
4899
4909
  //#region src/controllers/sheet-drawing-active-render.controller.ts
4900
4910
  let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderController extends Disposable {
4901
- constructor(_context, _commandService, _sheetSkeletonService, _sheetDrawingService, _drawingManagerService) {
4911
+ constructor(_context, _commandService, _sheetSkeletonService, _sheetDrawingService, _drawingManagerService, _logService) {
4902
4912
  super();
4903
4913
  this._context = _context;
4904
4914
  this._commandService = _commandService;
4905
4915
  this._sheetSkeletonService = _sheetSkeletonService;
4906
4916
  this._sheetDrawingService = _sheetDrawingService;
4907
4917
  this._drawingManagerService = _drawingManagerService;
4918
+ this._logService = _logService;
4908
4919
  _defineProperty(this, "_renderTimeout", void 0);
4909
4920
  this._commandListener();
4910
4921
  }
@@ -4926,64 +4937,58 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4926
4937
  }, 0);
4927
4938
  }
4928
4939
  _commandListener() {
4940
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
4941
+ if (command.id !== SetWorksheetActiveOperation.id) return;
4942
+ const { unitId, subUnitId } = command.params;
4943
+ const { unit, unitId: contextUnitId } = this._context;
4944
+ if (unitId !== contextUnitId || !unit.getSheetBySheetId(subUnitId) || unit.getActiveSheet().getSheetId() === subUnitId) return;
4945
+ this._clearDrawings(unitId, subUnitId);
4946
+ }));
4929
4947
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
4930
4948
  if (command.id === SetWorksheetActiveOperation.id) {
4931
4949
  const { unitId, subUnitId } = command.params;
4932
- this._updateDrawings(unitId, subUnitId);
4950
+ if (unitId === this._context.unitId && subUnitId === this._context.unit.getActiveSheet().getSheetId()) this._updateDrawings(unitId, subUnitId);
4933
4951
  }
4934
4952
  }));
4935
4953
  this.disposeWithMe(this._context.activated$.subscribe((activated) => {
4936
4954
  const { unit, unitId } = this._context;
4937
- if (activated) this._updateDrawings(unitId, unit.getActiveSheet().getSheetId());
4938
- else this._clearDrawings(unitId);
4955
+ if (activated) {
4956
+ const subUnitId = unit.getActiveSheet().getSheetId();
4957
+ this._clearDrawings(unitId, subUnitId);
4958
+ this._updateDrawings(unitId, subUnitId);
4959
+ } else this._clearDrawings(unitId);
4939
4960
  }));
4940
4961
  }
4941
- _clearDrawings(selfUnitId) {
4942
- this._scheduleRender(() => {
4943
- const drawingMap = this._drawingManagerService.drawingManagerData;
4944
- const removeDrawings = [];
4945
- Object.keys(drawingMap ?? {}).forEach((unitId) => {
4946
- const subUnitMap = drawingMap[unitId] ?? {};
4947
- Object.keys(subUnitMap).forEach((subUnitId) => {
4948
- var _subUnitMap$subUnitId;
4949
- const drawingData = ((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {};
4950
- Object.keys(drawingData).forEach((drawingId) => {
4951
- if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
4952
- });
4953
- });
4954
- });
4955
- this._sheetDrawingService.removeNotification(removeDrawings);
4956
- this._drawingManagerService.removeNotification(removeDrawings);
4957
- });
4962
+ _clearDrawings(unitId, keepSubUnitId) {
4963
+ this._cancelPendingRender();
4964
+ const subUnitMap = this._drawingManagerService.drawingManagerData[unitId] ?? {};
4965
+ const removeDrawings = [];
4966
+ for (const subUnitId of Object.keys(subUnitMap)) {
4967
+ var _subUnitMap$subUnitId;
4968
+ if (subUnitId === keepSubUnitId) continue;
4969
+ for (const drawing of Object.values(((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {})) removeDrawings.push(drawing);
4970
+ }
4971
+ this._sheetDrawingService.removeNotification(removeDrawings);
4972
+ this._drawingManagerService.removeNotification(removeDrawings);
4958
4973
  }
4959
4974
  _updateDrawings(showUnitId, showSubunitId) {
4960
4975
  this._scheduleRender(() => {
4976
+ var _subUnitMap$showSubun;
4961
4977
  const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(showUnitId, showSubunitId);
4962
- const drawingMap = this._drawingManagerService.drawingManagerData;
4963
- const insertDrawings = [];
4964
- const refreshedDrawings = [];
4965
- const removeDrawings = [];
4966
- Object.keys(drawingMap ?? {}).forEach((unitId) => {
4967
- if (unitId !== showUnitId) return;
4968
- const subUnitMap = drawingMap[unitId] ?? {};
4969
- Object.keys(subUnitMap).forEach((subUnitId) => {
4970
- var _subUnitMap$subUnitId2;
4971
- const drawingData = ((_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) ?? {};
4972
- Object.keys(drawingData).forEach((drawingId) => {
4973
- if (unitId === showUnitId && subUnitId === showSubunitId) {
4974
- const drawing = drawingData[drawingId];
4975
- if (sheetSkeletonParam && drawing.sheetTransform && drawing.anchorType !== SheetDrawingAnchorType.None) refreshedDrawings.push(applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(drawing), sheetSkeletonParam.skeleton));
4976
- insertDrawings.push(drawingData[drawingId]);
4977
- } else removeDrawings.push(drawingData[drawingId]);
4978
- });
4979
- });
4980
- });
4978
+ const drawingData = ((_subUnitMap$showSubun = (this._drawingManagerService.drawingManagerData[showUnitId] ?? {})[showSubunitId]) === null || _subUnitMap$showSubun === void 0 ? void 0 : _subUnitMap$showSubun.data) ?? {};
4979
+ const { successDrawings, refreshedDrawings, failures } = prepareSheetDrawings(Object.values(drawingData), sheetSkeletonParam === null || sheetSkeletonParam === void 0 ? void 0 : sheetSkeletonParam.skeleton);
4980
+ const removeDrawings = failures.map(({ drawingId }) => drawingData[drawingId]);
4981
4981
  this._sheetDrawingService.refreshTransform(refreshedDrawings);
4982
4982
  this._drawingManagerService.refreshTransform(refreshedDrawings);
4983
4983
  this._sheetDrawingService.removeNotification(removeDrawings);
4984
- this._sheetDrawingService.addNotification(insertDrawings);
4984
+ this._sheetDrawingService.addNotification(successDrawings);
4985
4985
  this._drawingManagerService.removeNotification(removeDrawings);
4986
- this._drawingManagerService.addNotification(insertDrawings);
4986
+ this._drawingManagerService.addNotification(successDrawings);
4987
+ if (failures.length) this._logService.error("[SheetDrawingActiveRenderController]", {
4988
+ unitId: showUnitId,
4989
+ subUnitId: showSubunitId,
4990
+ failures
4991
+ });
4987
4992
  });
4988
4993
  }
4989
4994
  };
@@ -4991,8 +4996,33 @@ SheetDrawingActiveRenderController = __decorate([
4991
4996
  __decorateParam(1, ICommandService),
4992
4997
  __decorateParam(2, Inject(SheetSkeletonService)),
4993
4998
  __decorateParam(3, ISheetDrawingService),
4994
- __decorateParam(4, IDrawingManagerService)
4999
+ __decorateParam(4, IDrawingManagerService),
5000
+ __decorateParam(5, ILogService)
4995
5001
  ], SheetDrawingActiveRenderController);
5002
+ function prepareSheetDrawings(drawings, skeleton) {
5003
+ const successDrawings = [];
5004
+ const refreshedDrawings = [];
5005
+ const failures = [];
5006
+ for (const drawing of drawings) {
5007
+ if (skeleton && drawing.sheetTransform && drawing.anchorType !== SheetDrawingAnchorType.None) try {
5008
+ refreshedDrawings.push(applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(drawing), skeleton));
5009
+ } catch (error) {
5010
+ failures.push({
5011
+ drawingId: drawing.drawingId,
5012
+ drawingType: drawing.drawingType,
5013
+ anchorType: drawing.anchorType ?? SheetDrawingAnchorType.Position,
5014
+ error
5015
+ });
5016
+ continue;
5017
+ }
5018
+ successDrawings.push(drawing);
5019
+ }
5020
+ return {
5021
+ successDrawings,
5022
+ refreshedDrawings,
5023
+ failures
5024
+ };
5025
+ }
4996
5026
 
4997
5027
  //#endregion
4998
5028
  //#region src/controllers/sheet-drawing-copy-paste.controller.ts
package/lib/facade.js CHANGED
@@ -13,16 +13,23 @@ import { IRenderManagerService, getCurrentTypeOfRenderer } from "@univerjs/engin
13
13
  var FWorksheetDrawingUIMixin = class extends FWorksheet {
14
14
  getFloatDomById(id) {
15
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,
16
+ return info ? this._getFloatDomResult(info) : null;
17
+ }
18
+ getAllFloatDoms() {
19
+ const floatDomService = this._injector.get(SheetCanvasFloatDomManagerService);
20
+ const unitId = this._workbook.getUnitId();
21
+ const subUnitId = this._worksheet.getSheetId();
22
+ return floatDomService.getFloatDomsBySubUnitId(unitId, subUnitId).map((info) => this._getFloatDomResult(info)).filter((dom) => dom != null);
23
+ }
24
+ _getFloatDomResult(info) {
25
+ const { unitId, subUnitId, id, rect, runtimeMetadata } = info;
26
+ const metadata = runtimeMetadata ?? this._injector.get(ISheetDrawingService).getDrawingByParam({
27
+ drawingId: id,
22
28
  unitId,
23
29
  subUnitId
24
30
  });
25
- if (!drawingParm) return null;
31
+ if (!metadata) return null;
32
+ const { left = 0, top = 0, width = 0, height = 0, flipX = false, flipY = false, angle = 0, skewX = 0, skewY = 0 } = rect.getState();
26
33
  return {
27
34
  position: {
28
35
  left,
@@ -35,44 +42,12 @@ var FWorksheetDrawingUIMixin = class extends FWorksheet {
35
42
  skewX,
36
43
  skewY
37
44
  },
38
- componentKey: drawingParm.componentKey,
39
- allowTransform: drawingParm.allowTransform,
40
- data: drawingParm.data,
41
- id: info.id
45
+ componentKey: metadata.componentKey,
46
+ allowTransform: metadata.allowTransform,
47
+ data: metadata.data,
48
+ id
42
49
  };
43
50
  }
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
- if (!drawingParm) return null;
56
- const { left, top, width, height, flipX, flipY, angle, skewX, skewY } = rect.getState();
57
- return {
58
- position: {
59
- left,
60
- top,
61
- width,
62
- height,
63
- flipX,
64
- flipY,
65
- angle,
66
- skewX,
67
- skewY
68
- },
69
- componentKey: drawingParm.componentKey,
70
- allowTransform: drawingParm.allowTransform,
71
- data: drawingParm.data,
72
- id: info.id
73
- };
74
- }).filter((dom) => dom != null);
75
- }
76
51
  updateFloatDom(id, config) {
77
52
  const sheetSkeletonService = this._injector.get(SheetSkeletonService);
78
53
  const info = this._injector.get(SheetCanvasFloatDomManagerService).getFloatDomInfo(id);
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, ILogService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DEFAULT_TRANSFORMER_CONFIG, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_EXTENSION_TYPE, SHEET_VIEWPORT_KEY, SheetExtension, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, DropdownMenu, FormLayout, Input, MessageType, MobileSelect, Radio, RadioGroup, Select, borderClassName, clsx, render, unmount } from "@univerjs/design";
@@ -427,7 +427,7 @@ function readUint32Be(bytes, offset) {
427
427
  }
428
428
 
429
429
  //#endregion
430
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
430
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
431
431
  function _typeof(o) {
432
432
  "@babel/helpers - typeof";
433
433
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -438,7 +438,7 @@ function _typeof(o) {
438
438
  }
439
439
 
440
440
  //#endregion
441
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
441
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
442
442
  function toPrimitive(t, r) {
443
443
  if ("object" != _typeof(t) || !t) return t;
444
444
  var e = t[Symbol.toPrimitive];
@@ -451,14 +451,14 @@ function toPrimitive(t, r) {
451
451
  }
452
452
 
453
453
  //#endregion
454
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
454
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
455
455
  function toPropertyKey(t) {
456
456
  var i = toPrimitive(t, "string");
457
457
  return "symbol" == _typeof(i) ? i : i + "";
458
458
  }
459
459
 
460
460
  //#endregion
461
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
461
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
462
462
  function _defineProperty(e, r, t) {
463
463
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
464
464
  value: t,
@@ -469,7 +469,7 @@ function _defineProperty(e, r, t) {
469
469
  }
470
470
 
471
471
  //#endregion
472
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
472
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
473
473
  function __decorateParam(paramIndex, decorator) {
474
474
  return function(target, key) {
475
475
  decorator(target, key, paramIndex);
@@ -477,7 +477,7 @@ function __decorateParam(paramIndex, decorator) {
477
477
  }
478
478
 
479
479
  //#endregion
480
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
480
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
481
481
  function __decorate(decorators, target, key, desc) {
482
482
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
483
483
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3070,7 +3070,12 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3070
3070
  domAnchor,
3071
3071
  unitId,
3072
3072
  subUnitId,
3073
- id: drawingId
3073
+ id: drawingId,
3074
+ runtimeMetadata: {
3075
+ componentKey,
3076
+ data,
3077
+ allowTransform
3078
+ }
3074
3079
  };
3075
3080
  const initedPosition = calcSheetFloatDomPosition(domRect, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet, floatDomInfo);
3076
3081
  const position$ = new BehaviorSubject(initedPosition);
@@ -3274,7 +3279,12 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3274
3279
  right: viewMain.right
3275
3280
  },
3276
3281
  domAnchor: domLayoutParam,
3277
- scrollDirectionResponse: "HORIZONTAL"
3282
+ scrollDirectionResponse: "HORIZONTAL",
3283
+ runtimeMetadata: {
3284
+ componentKey,
3285
+ data,
3286
+ allowTransform
3287
+ }
3278
3288
  };
3279
3289
  const initedPosition = calcSheetFloatDomPosition(domRect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet, floatDomInfo);
3280
3290
  const position$ = new BehaviorSubject(initedPosition);
@@ -3717,7 +3727,7 @@ const menuSchema = {
3717
3727
  //#endregion
3718
3728
  //#region package.json
3719
3729
  var name = "@univerjs/sheets-drawing-ui";
3720
- var version = "1.0.4";
3730
+ var version = "1.1.0";
3721
3731
 
3722
3732
  //#endregion
3723
3733
  //#region src/config/config.ts
@@ -4898,13 +4908,14 @@ SheetCellImageCopyPasteController = __decorate([
4898
4908
  //#endregion
4899
4909
  //#region src/controllers/sheet-drawing-active-render.controller.ts
4900
4910
  let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderController extends Disposable {
4901
- constructor(_context, _commandService, _sheetSkeletonService, _sheetDrawingService, _drawingManagerService) {
4911
+ constructor(_context, _commandService, _sheetSkeletonService, _sheetDrawingService, _drawingManagerService, _logService) {
4902
4912
  super();
4903
4913
  this._context = _context;
4904
4914
  this._commandService = _commandService;
4905
4915
  this._sheetSkeletonService = _sheetSkeletonService;
4906
4916
  this._sheetDrawingService = _sheetDrawingService;
4907
4917
  this._drawingManagerService = _drawingManagerService;
4918
+ this._logService = _logService;
4908
4919
  _defineProperty(this, "_renderTimeout", void 0);
4909
4920
  this._commandListener();
4910
4921
  }
@@ -4926,64 +4937,58 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4926
4937
  }, 0);
4927
4938
  }
4928
4939
  _commandListener() {
4940
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
4941
+ if (command.id !== SetWorksheetActiveOperation.id) return;
4942
+ const { unitId, subUnitId } = command.params;
4943
+ const { unit, unitId: contextUnitId } = this._context;
4944
+ if (unitId !== contextUnitId || !unit.getSheetBySheetId(subUnitId) || unit.getActiveSheet().getSheetId() === subUnitId) return;
4945
+ this._clearDrawings(unitId, subUnitId);
4946
+ }));
4929
4947
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
4930
4948
  if (command.id === SetWorksheetActiveOperation.id) {
4931
4949
  const { unitId, subUnitId } = command.params;
4932
- this._updateDrawings(unitId, subUnitId);
4950
+ if (unitId === this._context.unitId && subUnitId === this._context.unit.getActiveSheet().getSheetId()) this._updateDrawings(unitId, subUnitId);
4933
4951
  }
4934
4952
  }));
4935
4953
  this.disposeWithMe(this._context.activated$.subscribe((activated) => {
4936
4954
  const { unit, unitId } = this._context;
4937
- if (activated) this._updateDrawings(unitId, unit.getActiveSheet().getSheetId());
4938
- else this._clearDrawings(unitId);
4955
+ if (activated) {
4956
+ const subUnitId = unit.getActiveSheet().getSheetId();
4957
+ this._clearDrawings(unitId, subUnitId);
4958
+ this._updateDrawings(unitId, subUnitId);
4959
+ } else this._clearDrawings(unitId);
4939
4960
  }));
4940
4961
  }
4941
- _clearDrawings(selfUnitId) {
4942
- this._scheduleRender(() => {
4943
- const drawingMap = this._drawingManagerService.drawingManagerData;
4944
- const removeDrawings = [];
4945
- Object.keys(drawingMap ?? {}).forEach((unitId) => {
4946
- const subUnitMap = drawingMap[unitId] ?? {};
4947
- Object.keys(subUnitMap).forEach((subUnitId) => {
4948
- var _subUnitMap$subUnitId;
4949
- const drawingData = ((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {};
4950
- Object.keys(drawingData).forEach((drawingId) => {
4951
- if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
4952
- });
4953
- });
4954
- });
4955
- this._sheetDrawingService.removeNotification(removeDrawings);
4956
- this._drawingManagerService.removeNotification(removeDrawings);
4957
- });
4962
+ _clearDrawings(unitId, keepSubUnitId) {
4963
+ this._cancelPendingRender();
4964
+ const subUnitMap = this._drawingManagerService.drawingManagerData[unitId] ?? {};
4965
+ const removeDrawings = [];
4966
+ for (const subUnitId of Object.keys(subUnitMap)) {
4967
+ var _subUnitMap$subUnitId;
4968
+ if (subUnitId === keepSubUnitId) continue;
4969
+ for (const drawing of Object.values(((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {})) removeDrawings.push(drawing);
4970
+ }
4971
+ this._sheetDrawingService.removeNotification(removeDrawings);
4972
+ this._drawingManagerService.removeNotification(removeDrawings);
4958
4973
  }
4959
4974
  _updateDrawings(showUnitId, showSubunitId) {
4960
4975
  this._scheduleRender(() => {
4976
+ var _subUnitMap$showSubun;
4961
4977
  const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(showUnitId, showSubunitId);
4962
- const drawingMap = this._drawingManagerService.drawingManagerData;
4963
- const insertDrawings = [];
4964
- const refreshedDrawings = [];
4965
- const removeDrawings = [];
4966
- Object.keys(drawingMap ?? {}).forEach((unitId) => {
4967
- if (unitId !== showUnitId) return;
4968
- const subUnitMap = drawingMap[unitId] ?? {};
4969
- Object.keys(subUnitMap).forEach((subUnitId) => {
4970
- var _subUnitMap$subUnitId2;
4971
- const drawingData = ((_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) ?? {};
4972
- Object.keys(drawingData).forEach((drawingId) => {
4973
- if (unitId === showUnitId && subUnitId === showSubunitId) {
4974
- const drawing = drawingData[drawingId];
4975
- if (sheetSkeletonParam && drawing.sheetTransform && drawing.anchorType !== SheetDrawingAnchorType.None) refreshedDrawings.push(applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(drawing), sheetSkeletonParam.skeleton));
4976
- insertDrawings.push(drawingData[drawingId]);
4977
- } else removeDrawings.push(drawingData[drawingId]);
4978
- });
4979
- });
4980
- });
4978
+ const drawingData = ((_subUnitMap$showSubun = (this._drawingManagerService.drawingManagerData[showUnitId] ?? {})[showSubunitId]) === null || _subUnitMap$showSubun === void 0 ? void 0 : _subUnitMap$showSubun.data) ?? {};
4979
+ const { successDrawings, refreshedDrawings, failures } = prepareSheetDrawings(Object.values(drawingData), sheetSkeletonParam === null || sheetSkeletonParam === void 0 ? void 0 : sheetSkeletonParam.skeleton);
4980
+ const removeDrawings = failures.map(({ drawingId }) => drawingData[drawingId]);
4981
4981
  this._sheetDrawingService.refreshTransform(refreshedDrawings);
4982
4982
  this._drawingManagerService.refreshTransform(refreshedDrawings);
4983
4983
  this._sheetDrawingService.removeNotification(removeDrawings);
4984
- this._sheetDrawingService.addNotification(insertDrawings);
4984
+ this._sheetDrawingService.addNotification(successDrawings);
4985
4985
  this._drawingManagerService.removeNotification(removeDrawings);
4986
- this._drawingManagerService.addNotification(insertDrawings);
4986
+ this._drawingManagerService.addNotification(successDrawings);
4987
+ if (failures.length) this._logService.error("[SheetDrawingActiveRenderController]", {
4988
+ unitId: showUnitId,
4989
+ subUnitId: showSubunitId,
4990
+ failures
4991
+ });
4987
4992
  });
4988
4993
  }
4989
4994
  };
@@ -4991,8 +4996,33 @@ SheetDrawingActiveRenderController = __decorate([
4991
4996
  __decorateParam(1, ICommandService),
4992
4997
  __decorateParam(2, Inject(SheetSkeletonService)),
4993
4998
  __decorateParam(3, ISheetDrawingService),
4994
- __decorateParam(4, IDrawingManagerService)
4999
+ __decorateParam(4, IDrawingManagerService),
5000
+ __decorateParam(5, ILogService)
4995
5001
  ], SheetDrawingActiveRenderController);
5002
+ function prepareSheetDrawings(drawings, skeleton) {
5003
+ const successDrawings = [];
5004
+ const refreshedDrawings = [];
5005
+ const failures = [];
5006
+ for (const drawing of drawings) {
5007
+ if (skeleton && drawing.sheetTransform && drawing.anchorType !== SheetDrawingAnchorType.None) try {
5008
+ refreshedDrawings.push(applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(drawing), skeleton));
5009
+ } catch (error) {
5010
+ failures.push({
5011
+ drawingId: drawing.drawingId,
5012
+ drawingType: drawing.drawingType,
5013
+ anchorType: drawing.anchorType ?? SheetDrawingAnchorType.Position,
5014
+ error
5015
+ });
5016
+ continue;
5017
+ }
5018
+ successDrawings.push(drawing);
5019
+ }
5020
+ return {
5021
+ successDrawings,
5022
+ refreshedDrawings,
5023
+ failures
5024
+ };
5025
+ }
4996
5026
 
4997
5027
  //#endregion
4998
5028
  //#region src/controllers/sheet-drawing-copy-paste.controller.ts
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import type { Workbook } from '@univerjs/core';
17
17
  import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
18
- import { Disposable, ICommandService } from '@univerjs/core';
18
+ import { Disposable, ICommandService, ILogService } from '@univerjs/core';
19
19
  import { IDrawingManagerService } from '@univerjs/drawing';
20
20
  import { SheetSkeletonService } from '@univerjs/sheets';
21
21
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
@@ -25,8 +25,9 @@ export declare class SheetDrawingActiveRenderController extends Disposable imple
25
25
  private readonly _sheetSkeletonService;
26
26
  private readonly _sheetDrawingService;
27
27
  private readonly _drawingManagerService;
28
+ private readonly _logService;
28
29
  private _renderTimeout;
29
- constructor(_context: IRenderContext<Workbook>, _commandService: ICommandService, _sheetSkeletonService: SheetSkeletonService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService);
30
+ constructor(_context: IRenderContext<Workbook>, _commandService: ICommandService, _sheetSkeletonService: SheetSkeletonService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _logService: ILogService);
30
31
  dispose(): void;
31
32
  private _cancelPendingRender;
32
33
  private _scheduleRender;
@@ -405,6 +405,7 @@ export interface IFWorksheetDrawingUIMixin {
405
405
  export declare class FWorksheetDrawingUIMixin extends FWorksheet implements IFWorksheetDrawingUIMixin {
406
406
  getFloatDomById(id: string): Nullable<IFCanvasFloatDomResult>;
407
407
  getAllFloatDoms(): IFCanvasFloatDomResult[];
408
+ private _getFloatDomResult;
408
409
  updateFloatDom(id: string, config: Partial<Omit<IFCanvasFloatDomResult, 'id'>>): this;
409
410
  batchUpdateFloatDoms(updates: Array<{
410
411
  id: string;
@@ -70,6 +70,8 @@ export interface ICanvasFloatDomInfo {
70
70
  scrollDirectionResponse?: ScrollDirectionResponse;
71
71
  domAnchor?: IDOMAnchor;
72
72
  id: string;
73
+ /** Query attributes for float doms created without a backing drawing. */
74
+ runtimeMetadata?: Pick<ICanvasFloatDom, 'componentKey' | 'data' | 'allowTransform'>;
73
75
  domId?: string;
74
76
  floatDomConfig?: IFloatDom;
75
77
  runtimeMounted?: boolean;