@univerjs/sheets-drawing-ui 0.2.8 → 0.2.10

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
@@ -6,7 +6,7 @@ import { CommandType, ICommandService, IUndoRedoService, LocaleService, IUniverI
6
6
  import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, DrawingRenderService, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
7
7
  import { ISheetDrawingService, SetDrawingApplyMutation, DrawingApplyType, SheetDrawingAnchorType, UniverSheetsDrawingPlugin } from "@univerjs/sheets-drawing";
8
8
  import { IDrawingManagerService, IImageIoService, ArrangeTypeEnum, DrawingTypeEnum, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_ALLOW_IMAGE_LIST, getDrawingShapeKeyByDrawingSearch, UniverDrawingPlugin } from "@univerjs/drawing";
9
- import { IRenderManagerService, getGroupState, transformObjectOutOfGroup, precisionTo, Rect, DRAWING_OBJECT_LAYER_INDEX, pxToNum, SHEET_VIEWPORT_KEY, RENDER_CLASS_TYPE } from "@univerjs/engine-render";
9
+ import { IRenderManagerService, getGroupState, transformObjectOutOfGroup, precisionTo, Rect, DRAWING_OBJECT_LAYER_INDEX, SHEET_VIEWPORT_KEY, RENDER_CLASS_TYPE } from "@univerjs/engine-render";
10
10
  import { SheetCanvasPopManagerService, attachRangeWithCoord, SheetSkeletonManagerService, ISheetSelectionRenderService, getCurrentRangeDisable$, SetScrollOperation, SetZoomRatioOperation, SheetPrintInterceptorService, COPY_TYPE, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges, ISheetClipboardService } from "@univerjs/sheets-ui";
11
11
  import { takeUntil, Subject, BehaviorSubject, combineLatest, map, filter, distinctUntilChanged, first } from "rxjs";
12
12
  import { ISidebarService, BuiltInUIPart, IUIPartsService, IMessageService, MenuItemType, MenuPosition, MenuGroup, getMenuHiddenObservable, KeyCode, ComponentManager, IMenuService, IShortcutService, CanvasFloatDomService } from "@univerjs/ui";
@@ -121,7 +121,7 @@ let DrawingPopupMenuController = (_a = class extends RxDisposable {
121
121
  this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId) && (this._popupMenuListener(unitId), this._initImagePopupMenu.add(unitId));
122
122
  }
123
123
  _hasCropObject(scene) {
124
- const objects = scene.getAllObjects();
124
+ const objects = scene.getAllObjectsByOrder();
125
125
  for (const object of objects)
126
126
  if (object instanceof ImageCropperObject)
127
127
  return !0;
@@ -473,7 +473,7 @@ let SheetDrawingUpdateController = (_a2 = class extends Disposable {
473
473
  constructor(_context, _skeletonManagerService, _commandService, _selectionRenderService, _imageIoService, _sheetDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, selectionManagerService) {
474
474
  super();
475
475
  __publicField(this, "_workbookSelections");
476
- this._context = _context, this._skeletonManagerService = _skeletonManagerService, this._commandService = _commandService, this._selectionRenderService = _selectionRenderService, this._imageIoService = _imageIoService, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._workbookSelections = selectionManagerService.getWorkbookSelections(this._context.unitId), this._initCommandListeners(), this._updateImageListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._drawingAddListener();
476
+ this._context = _context, this._skeletonManagerService = _skeletonManagerService, this._commandService = _commandService, this._selectionRenderService = _selectionRenderService, this._imageIoService = _imageIoService, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._workbookSelections = selectionManagerService.getWorkbookSelections(this._context.unitId), this._initCommandListeners(), this._updateImageListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener();
477
477
  }
478
478
  /**
479
479
  * Upload image to cell or float image
@@ -648,24 +648,6 @@ let SheetDrawingUpdateController = (_a2 = class extends Disposable {
648
648
  })
649
649
  );
650
650
  }
651
- _drawingAddListener() {
652
- this.disposeWithMe(
653
- this._sheetDrawingService.add$.subscribe((params) => {
654
- this._registerDrawing(params);
655
- })
656
- );
657
- }
658
- _registerDrawing(params) {
659
- params.forEach((param) => {
660
- const drawingParam = this._sheetDrawingService.getDrawingByParam(param);
661
- if (drawingParam == null || drawingParam.unitId !== this._context.unitId)
662
- return;
663
- const { sheetTransform } = drawingParam;
664
- drawingParam.transform = drawingPositionToTransform(sheetTransform, this._selectionRenderService, this._skeletonManagerService);
665
- });
666
- const unitId = params[0].unitId;
667
- this._drawingManagerService.registerDrawingData(unitId, this._sheetDrawingService.getDrawingDataForUnit(unitId)), this._drawingManagerService.initializeNotification(unitId);
668
- }
669
651
  }, __name(_a2, "SheetDrawingUpdateController"), _a2);
670
652
  SheetDrawingUpdateController = __decorateClass$8([
671
653
  __decorateParam$8(1, Inject(SheetSkeletonManagerService)),
@@ -1788,20 +1770,20 @@ function transformBound2DOMBound(originBound, scene, skeleton, worksheet) {
1788
1770
  }
1789
1771
  __name(transformBound2DOMBound, "transformBound2DOMBound");
1790
1772
  const calcPosition = /* @__PURE__ */ __name((targetObject, currentRender, skeleton, worksheet) => {
1791
- const { scene, engine } = currentRender, { left, top, width, height, angle } = targetObject, canvasElement = engine.getCanvasElement(), canvasClientRect = canvasElement.getBoundingClientRect(), widthOfCanvas = pxToNum(canvasElement.style.width), { top: topOffset, left: leftOffset, width: domWidth } = canvasClientRect, scaleAdjust = domWidth / widthOfCanvas, bound = {
1773
+ const { scene } = currentRender, { left, top, width, height, angle } = targetObject, bound = {
1792
1774
  left,
1793
1775
  right: left + width,
1794
1776
  top,
1795
1777
  bottom: top + height
1796
1778
  }, offsetBound = transformBound2DOMBound(bound, scene, skeleton, worksheet);
1797
1779
  return {
1798
- startX: offsetBound.left * scaleAdjust + leftOffset,
1799
- endX: offsetBound.right * scaleAdjust + leftOffset,
1800
- startY: offsetBound.top * scaleAdjust + topOffset,
1801
- endY: offsetBound.bottom * scaleAdjust + topOffset,
1780
+ startX: offsetBound.left,
1781
+ endX: offsetBound.right,
1782
+ startY: offsetBound.top,
1783
+ endY: offsetBound.bottom,
1802
1784
  rotate: angle,
1803
- width: width * scaleAdjust,
1804
- height: height * scaleAdjust,
1785
+ width,
1786
+ height,
1805
1787
  absolute: offsetBound.absolute
1806
1788
  };
1807
1789
  }, "calcPosition");
@@ -1895,7 +1877,8 @@ let SheetCanvasFloatDomManagerService = (_a5 = class extends Disposable {
1895
1877
  canvas.dispatchEvent(new WheelEvent(evt.type, evt));
1896
1878
  }, "onWheel"),
1897
1879
  props: (_c = (_b = map2.get(drawingId)) == null ? void 0 : _b.props) != null ? _c : this._getFloatDomProps(drawingId),
1898
- data
1880
+ data,
1881
+ unitId
1899
1882
  });
1900
1883
  const listener = rect.onTransformChange$.subscribeEvent(() => {
1901
1884
  const newPosition = calcPosition(rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);
@@ -2147,7 +2130,7 @@ let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2147
2130
  const unitId2 = workbook.getUnitId(), subUnitId2 = sheet.getSheetId(), drawingData = this._drawingManagerService.getDrawingData(unitId2, subUnitId2), drawingDataValues = Object.values(drawingData), renderObject = this._renderManagerService.getRenderById(unitId2), scene = renderObject == null ? void 0 : renderObject.scene;
2148
2131
  if (scene == null)
2149
2132
  return;
2150
- scene.getAllObjects().forEach((object) => {
2133
+ scene.getAllObjectsByOrder().forEach((object) => {
2151
2134
  object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
2152
2135
  });
2153
2136
  }
@@ -2176,7 +2159,7 @@ let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2176
2159
  const unitId2 = workbook.getUnitId(), subUnitId2 = sheet.getSheetId(), drawingData = this._drawingManagerService.getDrawingData(unitId2, subUnitId2), drawingDataValues = Object.values(drawingData), renderObject = this._renderManagerService.getRenderById(unitId2), scene = renderObject == null ? void 0 : renderObject.scene;
2177
2160
  if (scene == null)
2178
2161
  return;
2179
- scene.getAllObjects().forEach((object) => {
2162
+ scene.getAllObjectsByOrder().forEach((object) => {
2180
2163
  object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.detachTransformerFrom(object);
2181
2164
  });
2182
2165
  }
@@ -2204,7 +2187,7 @@ let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2204
2187
  ).subscribe({
2205
2188
  next: /* @__PURE__ */ __name((permission) => {
2206
2189
  initialViewPermission = permission, this._drawingManagerService.setDrawingVisible(permission);
2207
- const objects = scene.getAllObjects(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2190
+ const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2208
2191
  permission ? this._drawingManagerService.addNotification(drawingDataValues) : (objects.forEach((object) => {
2209
2192
  object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
2210
2193
  }), transformer.clearSelectedObjects());
@@ -2243,7 +2226,7 @@ let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2243
2226
  ).subscribe({
2244
2227
  next: /* @__PURE__ */ __name((permission) => {
2245
2228
  initialEditPermission = permission, this._drawingManagerService.setDrawingEditable(permission);
2246
- const objects = scene.getAllObjects(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2229
+ const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2247
2230
  permission ? (objects.forEach((object) => {
2248
2231
  object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.attachTransformerTo(object);
2249
2232
  }), this._drawingManagerService.addNotification(drawingDataValues)) : (objects.forEach((object) => {
@@ -2259,7 +2242,7 @@ let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2259
2242
  const unitId2 = workbook.getUnitId(), subUnitId2 = sheet.getSheetId(), drawingData = this._drawingManagerService.getDrawingData(unitId2, subUnitId2), drawingDataValues = Object.values(drawingData), renderObject2 = this._renderManagerService.getRenderById(unitId2), scene2 = renderObject2 == null ? void 0 : renderObject2.scene;
2260
2243
  if (scene2 == null)
2261
2244
  return;
2262
- this._drawingManagerService.setDrawingEditable(!0), scene2.getAllObjects().forEach((object) => {
2245
+ this._drawingManagerService.setDrawingEditable(!0), scene2.getAllObjectsByOrder().forEach((object) => {
2263
2246
  object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene2.detachTransformerFrom(object);
2264
2247
  });
2265
2248
  }, "complete")
@@ -2420,21 +2403,22 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
2420
2403
  return kind && result && __defProp$1(target, key, result), result;
2421
2404
  }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a9;
2422
2405
  let SheetsDrawingRenderController = (_a9 = class extends Disposable {
2423
- constructor(_context, _sheetDrawingService, _lifecycleService) {
2424
- super(), this._context = _context, this._sheetDrawingService = _sheetDrawingService, this._lifecycleService = _lifecycleService, this._init();
2406
+ constructor(_context, _sheetDrawingService, _drawingManagerService, _lifecycleService) {
2407
+ super(), this._context = _context, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._lifecycleService = _lifecycleService, this._init();
2425
2408
  }
2426
2409
  _init() {
2427
2410
  this._drawingInitializeListener();
2428
2411
  }
2429
2412
  _drawingInitializeListener() {
2430
2413
  this._lifecycleService.lifecycle$.pipe(filter((e) => e === LifecycleStages.Steady), first()).subscribe(() => {
2431
- this._context.type === UniverInstanceType.UNIVER_SHEET && this._sheetDrawingService.initializeNotification(this._context.unitId);
2414
+ this._context.type === UniverInstanceType.UNIVER_SHEET && (this._sheetDrawingService.initializeNotification(this._context.unitId), this._drawingManagerService.initializeNotification(this._context.unitId));
2432
2415
  });
2433
2416
  }
2434
2417
  }, __name(_a9, "SheetsDrawingRenderController"), _a9);
2435
2418
  SheetsDrawingRenderController = __decorateClass$1([
2436
2419
  __decorateParam$1(1, ISheetDrawingService),
2437
- __decorateParam$1(2, Inject(LifecycleService))
2420
+ __decorateParam$1(2, IDrawingManagerService),
2421
+ __decorateParam$1(3, Inject(LifecycleService))
2438
2422
  ], SheetsDrawingRenderController);
2439
2423
  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) => {
2440
2424
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -1,11 +1,13 @@
1
1
  import { Disposable, LifecycleService } from '@univerjs/core';
2
+ import { IDrawingManagerService } from '@univerjs/drawing';
2
3
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
4
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
4
5
  export declare class SheetsDrawingRenderController extends Disposable implements IRenderModule {
5
6
  private _context;
6
7
  private readonly _sheetDrawingService;
8
+ private readonly _drawingManagerService;
7
9
  private _lifecycleService;
8
- constructor(_context: IRenderContext, _sheetDrawingService: ISheetDrawingService, _lifecycleService: LifecycleService);
10
+ constructor(_context: IRenderContext, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _lifecycleService: LifecycleService);
9
11
  private _init;
10
12
  private _drawingInitializeListener;
11
13
  }
@@ -30,6 +30,4 @@ export declare class SheetDrawingUpdateController extends Disposable implements
30
30
  private _updateImageListener;
31
31
  private _groupDrawingListener;
32
32
  private _focusDrawingListener;
33
- private _drawingAddListener;
34
- private _registerDrawing;
35
33
  }
@@ -4,10 +4,22 @@ import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService }
4
4
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
5
5
  import { CanvasFloatDomService } from '@univerjs/ui';
6
6
  export interface ICanvasFloatDom {
7
+ /**
8
+ * whether allow transform float-dom
9
+ */
7
10
  allowTransform: boolean;
11
+ /**
12
+ * initial position of float-dom
13
+ */
8
14
  initPosition: IPosition;
9
15
  componentKey: string;
16
+ /**
17
+ * unitId of workbook, if not set, will use current workbook
18
+ */
10
19
  unitId?: string;
20
+ /**
21
+ * subUnitId of worksheet, if not set, will use current worksheet
22
+ */
11
23
  subUnitId?: string;
12
24
  /**
13
25
  * @deprecated Please use `data`. for saving to disk, everything add to float-dom must be serializable.