@univerjs/sheets-drawing-ui 0.3.0 → 0.4.0-alpha.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
@@ -2,19 +2,19 @@ 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, IUndoRedoService, LocaleService, IUniverInstanceService, useDependency, OnLifecycle, LifecycleStages, Inject, Injector, RxDisposable, UniverInstanceType, connectInjector, toDisposable, FOCUSING_COMMON_DRAWINGS, IContextService, Disposable, Direction, FOCUSING_FX_BAR_EDITOR, EDITOR_ACTIVATED, Rectangle, DrawingTypeEnum as DrawingTypeEnum$1, DisposableCollection, generateRandomId, Tools, UserManagerService, IPermissionService, LifecycleService, DependentOn, Plugin, IConfigService } from "@univerjs/core";
5
+ import { CommandType, ICommandService, IUndoRedoService, LocaleService, IUniverInstanceService, useDependency, Inject, Injector, IContextService, RxDisposable, UniverInstanceType, connectInjector, toDisposable, FOCUSING_COMMON_DRAWINGS, Disposable, Direction, FOCUSING_FX_BAR_EDITOR, EDITOR_ACTIVATED, Tools, UserManagerService, IPermissionService, Rectangle, DrawingTypeEnum as DrawingTypeEnum$1, DisposableCollection, generateRandomId, DependentOn, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
6
+ import { IDrawingManagerService, IImageIoService, DrawingTypeEnum, ArrangeTypeEnum, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, getDrawingShapeKeyByDrawingSearch, UniverDrawingPlugin } from "@univerjs/drawing";
6
7
  import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, DrawingRenderService, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
8
+ import { IRenderManagerService, precisionTo, getGroupState, transformObjectOutOfGroup, RENDER_CLASS_TYPE, Rect, DRAWING_OBJECT_LAYER_INDEX, SHEET_VIEWPORT_KEY } from "@univerjs/engine-render";
7
9
  import { ISheetDrawingService, SetDrawingApplyMutation, DrawingApplyType, SheetDrawingAnchorType, UniverSheetsDrawingPlugin } from "@univerjs/sheets-drawing";
8
- import { IDrawingManagerService, IImageIoService, DrawingTypeEnum, ArrangeTypeEnum, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, getDrawingShapeKeyByDrawingSearch, UniverDrawingPlugin } from "@univerjs/drawing";
9
- import { IRenderManagerService, precisionTo, getGroupState, transformObjectOutOfGroup, Rect, DRAWING_OBJECT_LAYER_INDEX, SHEET_VIEWPORT_KEY, RENDER_CLASS_TYPE } from "@univerjs/engine-render";
10
- import { SheetCanvasPopManagerService, attachRangeWithCoord, SheetSkeletonManagerService, ISheetSelectionRenderService, getCurrentRangeDisable$, SetScrollOperation, SetZoomRatioOperation, SheetPrintInterceptorService, COPY_TYPE, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges, ISheetClipboardService } from "@univerjs/sheets-ui";
11
- import { ISidebarService, IUIPartsService, BuiltInUIPart, ILocalFileService, IMessageService, MenuItemType, getMenuHiddenObservable, KeyCode, RibbonStartGroup, ComponentManager, IMenuManagerService, IShortcutService, CanvasFloatDomService } from "@univerjs/ui";
12
- import { takeUntil, Subject, BehaviorSubject, combineLatest, map, filter, distinctUntilChanged } from "rxjs";
13
- import { getSheetCommandTarget, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, InsertRowCommand, InsertColCommand, RemoveRowCommand, RemoveColCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, DeltaRowHeightCommand, SetRowHeightCommand, DeltaColumnWidthCommand, SetColWidthCommand, SetRowHiddenCommand, SetSpecificRowsVisibleCommand, SetSpecificColsVisibleCommand, SetColHiddenCommand, MoveColsCommand, MoveRowsCommand, MoveRangeCommand, SetRowVisibleMutation, SetRowHiddenMutation, SetColVisibleMutation, SetColHiddenMutation, SetWorksheetRowHeightMutation, SetWorksheetColWidthMutation, SheetInterceptorService, SetWorksheetActiveOperation, SetFrozenMutation, WorkbookViewPermission, WorksheetViewPermission } from "@univerjs/sheets";
10
+ import { SheetCanvasPopManagerService, attachRangeWithCoord, ISheetSelectionRenderService, SheetSkeletonManagerService, getCurrentRangeDisable$, COPY_TYPE, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges, ISheetClipboardService, SheetPrintInterceptorService, SetScrollOperation, SetZoomRatioOperation } from "@univerjs/sheets-ui";
11
+ import { ISidebarService, IUIPartsService, BuiltInUIPart, ILocalFileService, IMessageService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, KeyCode, ComponentManager, IMenuManagerService, IShortcutService, CanvasFloatDomService } from "@univerjs/ui";
12
+ import { takeUntil, combineLatest, map, filter, distinctUntilChanged, Subject, BehaviorSubject } from "rxjs";
13
+ import { getSheetCommandTarget, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, WorkbookViewPermission, WorksheetViewPermission, InsertRowCommand, InsertColCommand, RemoveRowCommand, RemoveColCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, DeltaRowHeightCommand, SetRowHeightCommand, DeltaColumnWidthCommand, SetColWidthCommand, SetRowHiddenCommand, SetSpecificRowsVisibleCommand, SetSpecificColsVisibleCommand, SetColHiddenCommand, MoveColsCommand, MoveRowsCommand, MoveRangeCommand, SetRowVisibleMutation, SetRowHiddenMutation, SetColVisibleMutation, SetColHiddenMutation, SetWorksheetRowHeightMutation, SetWorksheetColWidthMutation, SheetInterceptorService, SetWorksheetActiveOperation, SetFrozenMutation } from "@univerjs/sheets";
14
14
  import React, { useEffect, forwardRef, useRef, createElement, useState } from "react";
15
15
  import { MessageType, RadioGroup, Radio } from "@univerjs/design";
16
16
  import clsx from "clsx";
17
- const ClearSheetDrawingTransformerOperation = {
17
+ const PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config", defaultPluginConfig = {}, ClearSheetDrawingTransformerOperation = {
18
18
  id: "sheet.operation.clear-drawing-transformer",
19
19
  type: CommandType.MUTATION,
20
20
  handler: /* @__PURE__ */ __name((accessor, params) => {
@@ -211,7 +211,6 @@ let DrawingPopupMenuController = (_a = class extends RxDisposable {
211
211
  }
212
212
  }, __name(_a, "DrawingPopupMenuController"), _a);
213
213
  DrawingPopupMenuController = __decorateClass$9([
214
- OnLifecycle(LifecycleStages.Steady, DrawingPopupMenuController),
215
214
  __decorateParam$9(0, Inject(Injector)),
216
215
  __decorateParam$9(1, IDrawingManagerService),
217
216
  __decorateParam$9(2, Inject(SheetCanvasPopManagerService)),
@@ -283,6 +282,114 @@ function transformToDrawingPosition(transform, selectionRenderService) {
283
282
  };
284
283
  }
285
284
  __name(transformToDrawingPosition, "transformToDrawingPosition");
285
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
286
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
287
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
288
+ return kind && result && __defProp$8(target, key, result), result;
289
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a2;
290
+ let SheetsDrawingRenderController = (_a2 = class extends Disposable {
291
+ constructor(_context, _sheetDrawingService, _drawingManagerService, _sheetSelectionRenderService, _sheetSkeletonManagerService) {
292
+ super(), this._context = _context, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._sheetSelectionRenderService = _sheetSelectionRenderService, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._init();
293
+ }
294
+ _init() {
295
+ this._drawingInitializeListener();
296
+ }
297
+ _drawingInitializeListener() {
298
+ this._sheetDrawingService.initializeNotification(this._context.unitId);
299
+ const data = this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);
300
+ for (const subUnit in data) {
301
+ const subUnitData = data[subUnit];
302
+ for (const drawingId in subUnitData.data) {
303
+ const drawingData = subUnitData.data[drawingId];
304
+ drawingData.transform = drawingPositionToTransform(drawingData.sheetTransform, this._sheetSelectionRenderService, this._sheetSkeletonManagerService);
305
+ }
306
+ }
307
+ this._drawingManagerService.registerDrawingData(this._context.unitId, this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)), this._drawingManagerService.initializeNotification(this._context.unitId);
308
+ }
309
+ }, __name(_a2, "SheetsDrawingRenderController"), _a2);
310
+ SheetsDrawingRenderController = __decorateClass$8([
311
+ __decorateParam$8(1, ISheetDrawingService),
312
+ __decorateParam$8(2, IDrawingManagerService),
313
+ __decorateParam$8(3, Inject(ISheetSelectionRenderService)),
314
+ __decorateParam$8(4, Inject(SheetSkeletonManagerService))
315
+ ], SheetsDrawingRenderController);
316
+ var __assign = function() {
317
+ return __assign = Object.assign || function(t) {
318
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
319
+ s = arguments[i];
320
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
321
+ }
322
+ return t;
323
+ }, __assign.apply(this, arguments);
324
+ }, __rest = function(s, e) {
325
+ var t = {};
326
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
327
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
328
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
329
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
330
+ return t;
331
+ }, IconBase = forwardRef(function(props, ref) {
332
+ var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
333
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
334
+ });
335
+ function render(node, id, runtimeProps, rootProps, extend) {
336
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
337
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
338
+ }));
339
+ }
340
+ __name(render, "render");
341
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
342
+ var attrs = __assign({}, node.attrs);
343
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
344
+ var defIds = runtimeProps.defIds;
345
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a11) {
346
+ var key = _a11[0], value = _a11[1];
347
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
348
+ })), attrs;
349
+ }
350
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
351
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
352
+ var _a11, defIds = runtimeProps.defIds;
353
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a11 = node.children) === null || _a11 === void 0) && _a11.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
354
+ return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
355
+ }) }) : node;
356
+ }
357
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
358
+ function generateShortUuid() {
359
+ return Math.random().toString(36).substring(2, 8);
360
+ }
361
+ __name(generateShortUuid, "generateShortUuid");
362
+ IconBase.displayName = "UniverIcon";
363
+ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, AddImageSingle = forwardRef(function(props, ref) {
364
+ return createElement(IconBase, Object.assign({}, props, {
365
+ id: "add-image-single",
366
+ ref,
367
+ icon: element
368
+ }));
369
+ });
370
+ AddImageSingle.displayName = "AddImageSingle";
371
+ const DeleteDrawingsCommand = {
372
+ id: "sheet.command.delete-drawing",
373
+ type: CommandType.COMMAND,
374
+ handler: /* @__PURE__ */ __name((accessor) => {
375
+ const commandService = accessor.get(ICommandService), drawings = accessor.get(ISheetDrawingService).getFocusDrawings();
376
+ if (drawings.length === 0)
377
+ return !1;
378
+ const unitId = drawings[0].unitId, newDrawings = drawings.map((drawing) => {
379
+ const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
380
+ return {
381
+ unitId: unitId2,
382
+ subUnitId,
383
+ drawingId,
384
+ drawingType
385
+ };
386
+ });
387
+ return commandService.executeCommand(RemoveSheetDrawingCommand.id, {
388
+ unitId,
389
+ drawings: newDrawings
390
+ });
391
+ }, "handler")
392
+ };
286
393
  function ungroupToGroup(ungroupParams) {
287
394
  const newGroupParams = [];
288
395
  return ungroupParams.forEach((ungroupParam) => {
@@ -455,12 +562,12 @@ const GroupSheetDrawingCommand = {
455
562
  }), !0) : !1;
456
563
  }, "handler")
457
564
  };
458
- var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
459
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
565
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
566
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
460
567
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
461
- return kind && result && __defProp$8(target, key, result), result;
462
- }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a2;
463
- let SheetDrawingUpdateController = (_a2 = class extends Disposable {
568
+ return kind && result && __defProp$7(target, key, result), result;
569
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a3;
570
+ let SheetDrawingUpdateController = (_a3 = class extends Disposable {
464
571
  constructor(_context, _skeletonManagerService, _commandService, _selectionRenderService, _imageIoService, _fileOpenerService, _sheetDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, selectionManagerService) {
465
572
  super();
466
573
  __publicField(this, "_workbookSelections");
@@ -617,75 +724,20 @@ let SheetDrawingUpdateController = (_a2 = class extends Disposable {
617
724
  })
618
725
  );
619
726
  }
620
- }, __name(_a2, "SheetDrawingUpdateController"), _a2);
621
- SheetDrawingUpdateController = __decorateClass$8([
622
- __decorateParam$8(1, Inject(SheetSkeletonManagerService)),
623
- __decorateParam$8(2, ICommandService),
624
- __decorateParam$8(3, ISheetSelectionRenderService),
625
- __decorateParam$8(4, IImageIoService),
626
- __decorateParam$8(5, ILocalFileService),
627
- __decorateParam$8(6, ISheetDrawingService),
628
- __decorateParam$8(7, IDrawingManagerService),
629
- __decorateParam$8(8, IContextService),
630
- __decorateParam$8(9, IMessageService),
631
- __decorateParam$8(10, Inject(LocaleService)),
632
- __decorateParam$8(11, Inject(SheetsSelectionsService))
727
+ }, __name(_a3, "SheetDrawingUpdateController"), _a3);
728
+ SheetDrawingUpdateController = __decorateClass$7([
729
+ __decorateParam$7(1, Inject(SheetSkeletonManagerService)),
730
+ __decorateParam$7(2, ICommandService),
731
+ __decorateParam$7(3, ISheetSelectionRenderService),
732
+ __decorateParam$7(4, IImageIoService),
733
+ __decorateParam$7(5, ILocalFileService),
734
+ __decorateParam$7(6, ISheetDrawingService),
735
+ __decorateParam$7(7, IDrawingManagerService),
736
+ __decorateParam$7(8, IContextService),
737
+ __decorateParam$7(9, IMessageService),
738
+ __decorateParam$7(10, Inject(LocaleService)),
739
+ __decorateParam$7(11, Inject(SheetsSelectionsService))
633
740
  ], SheetDrawingUpdateController);
634
- var __assign = function() {
635
- return __assign = Object.assign || function(t) {
636
- for (var s, i = 1, n = arguments.length; i < n; i++) {
637
- s = arguments[i];
638
- for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
639
- }
640
- return t;
641
- }, __assign.apply(this, arguments);
642
- }, __rest = function(s, e) {
643
- var t = {};
644
- for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
645
- if (s != null && typeof Object.getOwnPropertySymbols == "function")
646
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
647
- e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
648
- return t;
649
- }, IconBase = forwardRef(function(props, ref) {
650
- var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
651
- return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
652
- });
653
- function render(node, id, runtimeProps, rootProps, extend) {
654
- return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
655
- return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
656
- }));
657
- }
658
- __name(render, "render");
659
- function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
660
- var attrs = __assign({}, node.attrs);
661
- extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
662
- var defIds = runtimeProps.defIds;
663
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a11) {
664
- var key = _a11[0], value = _a11[1];
665
- typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
666
- })), attrs;
667
- }
668
- __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
669
- function replaceRuntimeIdsInDefs(node, runtimeProps) {
670
- var _a11, defIds = runtimeProps.defIds;
671
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a11 = node.children) === null || _a11 === void 0) && _a11.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
672
- return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
673
- }) }) : node;
674
- }
675
- __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
676
- function generateShortUuid() {
677
- return Math.random().toString(36).substring(2, 8);
678
- }
679
- __name(generateShortUuid, "generateShortUuid");
680
- IconBase.displayName = "UniverIcon";
681
- var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, AddImageSingle = forwardRef(function(props, ref) {
682
- return createElement(IconBase, Object.assign({}, props, {
683
- id: "add-image-single",
684
- ref,
685
- icon: element
686
- }));
687
- });
688
- AddImageSingle.displayName = "AddImageSingle";
689
741
  const InsertFloatImageCommand = {
690
742
  id: "sheet.command.insert-float-image",
691
743
  type: CommandType.COMMAND,
@@ -693,6 +745,29 @@ const InsertFloatImageCommand = {
693
745
  var _a11, _b;
694
746
  return (_b = (_a11 = accessor.get(IRenderManagerService).getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a11.with(SheetDrawingUpdateController).insertFloatImage()) != null ? _b : !1;
695
747
  }, "handler")
748
+ }, MoveDrawingsCommand = {
749
+ id: "sheet.command.move-drawing",
750
+ type: CommandType.COMMAND,
751
+ handler: /* @__PURE__ */ __name((accessor, params) => {
752
+ const commandService = accessor.get(ICommandService), drawingManagerService = accessor.get(ISheetDrawingService), selectionRenderService = accessor.get(ISheetSelectionRenderService), { direction } = params, drawings = drawingManagerService.getFocusDrawings();
753
+ if (drawings.length === 0)
754
+ return !1;
755
+ const unitId = drawings[0].unitId, newDrawings = drawings.map((drawing) => {
756
+ const { transform } = drawing;
757
+ if (transform == null)
758
+ return null;
759
+ const newTransform = { ...transform }, { left = 0, top = 0 } = transform;
760
+ return direction === Direction.UP ? newTransform.top = top - 1 : direction === Direction.DOWN ? newTransform.top = top + 1 : direction === Direction.LEFT ? newTransform.left = left - 1 : direction === Direction.RIGHT && (newTransform.left = left + 1), {
761
+ ...drawing,
762
+ transform: newTransform,
763
+ sheetTransform: transformToDrawingPosition(newTransform, selectionRenderService)
764
+ };
765
+ }).filter((drawing) => drawing != null);
766
+ return commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
767
+ unitId,
768
+ drawings: newDrawings
769
+ }) ? (commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]), !0) : !1;
770
+ }, "handler")
696
771
  }, IMAGE_UPLOAD_ICON = "addition-and-subtraction-single", IMAGE_MENU_ID = "sheet.menu.image";
697
772
  function ImageMenuFactory(accessor) {
698
773
  return {
@@ -803,50 +878,17 @@ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "un
803
878
  focusDispose.unsubscribe();
804
879
  };
805
880
  }, []), !!(drawings != null && drawings.length) && /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanel }, /* @__PURE__ */ React.createElement(DrawingCommonPanel, { drawings }), /* @__PURE__ */ React.createElement(SheetDrawingAnchor, { drawings }));
806
- }, "SheetDrawingPanel"), MoveDrawingsCommand = {
807
- id: "sheet.command.move-drawing",
808
- type: CommandType.COMMAND,
809
- handler: /* @__PURE__ */ __name((accessor, params) => {
810
- const commandService = accessor.get(ICommandService), drawingManagerService = accessor.get(ISheetDrawingService), selectionRenderService = accessor.get(ISheetSelectionRenderService), { direction } = params, drawings = drawingManagerService.getFocusDrawings();
811
- if (drawings.length === 0)
812
- return !1;
813
- const unitId = drawings[0].unitId, newDrawings = drawings.map((drawing) => {
814
- const { transform } = drawing;
815
- if (transform == null)
816
- return null;
817
- const newTransform = { ...transform }, { left = 0, top = 0 } = transform;
818
- return direction === Direction.UP ? newTransform.top = top - 1 : direction === Direction.DOWN ? newTransform.top = top + 1 : direction === Direction.LEFT ? newTransform.left = left - 1 : direction === Direction.RIGHT && (newTransform.left = left + 1), {
819
- ...drawing,
820
- transform: newTransform,
821
- sheetTransform: transformToDrawingPosition(newTransform, selectionRenderService)
822
- };
823
- }).filter((drawing) => drawing != null);
824
- return commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
825
- unitId,
826
- drawings: newDrawings
827
- }) ? (commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]), !0) : !1;
828
- }, "handler")
829
- }, DeleteDrawingsCommand = {
830
- id: "sheet.command.delete-drawing",
831
- type: CommandType.COMMAND,
832
- handler: /* @__PURE__ */ __name((accessor) => {
833
- const commandService = accessor.get(ICommandService), drawings = accessor.get(ISheetDrawingService).getFocusDrawings();
834
- if (drawings.length === 0)
835
- return !1;
836
- const unitId = drawings[0].unitId, newDrawings = drawings.map((drawing) => {
837
- const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
838
- return {
839
- unitId: unitId2,
840
- subUnitId,
841
- drawingId,
842
- drawingType
843
- };
844
- });
845
- return commandService.executeCommand(RemoveSheetDrawingCommand.id, {
846
- unitId,
847
- drawings: newDrawings
848
- });
849
- }, "handler")
881
+ }, "SheetDrawingPanel"), menuSchema = {
882
+ [RibbonStartGroup.FORMULAS_INSERT]: {
883
+ [IMAGE_MENU_ID]: {
884
+ order: 3,
885
+ menuItemFactory: ImageMenuFactory,
886
+ [InsertFloatImageCommand.id]: {
887
+ order: 0,
888
+ menuItemFactory: UploadFloatImageMenuFactory
889
+ }
890
+ }
891
+ }
850
892
  };
851
893
  function whenSheetDrawingFocused(contextService) {
852
894
  return !contextService.getContextValue(FOCUSING_FX_BAR_EDITOR) && !contextService.getContextValue(EDITOR_ACTIVATED) && contextService.getContextValue(FOCUSING_COMMON_DRAWINGS);
@@ -900,26 +942,15 @@ const MoveDrawingDownShortcutItem = {
900
942
  preconditions: whenSheetDrawingFocused,
901
943
  binding: KeyCode.DELETE,
902
944
  mac: KeyCode.BACKSPACE
903
- }, menuSchema = {
904
- [RibbonStartGroup.FORMULAS_INSERT]: {
905
- [IMAGE_MENU_ID]: {
906
- order: 3,
907
- menuItemFactory: ImageMenuFactory,
908
- [InsertFloatImageCommand.id]: {
909
- order: 0,
910
- menuItemFactory: UploadFloatImageMenuFactory
911
- }
912
- }
913
- }
914
945
  };
915
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
916
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
946
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
947
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
917
948
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
918
- return kind && result && __defProp$7(target, key, result), result;
919
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a3;
920
- let SheetDrawingUIController = (_a3 = class extends Disposable {
921
- constructor(_injector, _componentManager, _menuManagerService, _commandService, _shortcutService) {
922
- super(), this._injector = _injector, this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
949
+ return kind && result && __defProp$6(target, key, result), result;
950
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a4;
951
+ let SheetDrawingUIController = (_a4 = class extends Disposable {
952
+ constructor(_componentManager, _menuManagerService, _commandService, _shortcutService) {
953
+ super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
923
954
  }
924
955
  _initCustomComponents() {
925
956
  const componentManager = this._componentManager;
@@ -959,25 +990,373 @@ let SheetDrawingUIController = (_a3 = class extends Disposable {
959
990
  _init() {
960
991
  this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
961
992
  }
962
- }, __name(_a3, "SheetDrawingUIController"), _a3);
963
- SheetDrawingUIController = __decorateClass$7([
964
- OnLifecycle(LifecycleStages.Rendered, SheetDrawingUIController),
965
- __decorateParam$7(0, Inject(Injector)),
966
- __decorateParam$7(1, Inject(ComponentManager)),
967
- __decorateParam$7(2, IMenuManagerService),
968
- __decorateParam$7(3, ICommandService),
969
- __decorateParam$7(4, IShortcutService)
993
+ }, __name(_a4, "SheetDrawingUIController"), _a4);
994
+ SheetDrawingUIController = __decorateClass$6([
995
+ __decorateParam$6(0, Inject(ComponentManager)),
996
+ __decorateParam$6(1, IMenuManagerService),
997
+ __decorateParam$6(2, ICommandService),
998
+ __decorateParam$6(3, IShortcutService)
970
999
  ], SheetDrawingUIController);
971
- var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
972
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1000
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1001
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
973
1002
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
974
- return kind && result && __defProp$6(target, key, result), result;
975
- }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6");
976
- const UPDATE_COMMANDS = [
977
- InsertRowCommand.id,
978
- InsertColCommand.id,
979
- RemoveRowCommand.id,
980
- RemoveColCommand.id,
1003
+ return kind && result && __defProp$5(target, key, result), result;
1004
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a5;
1005
+ let SheetsDrawingCopyPasteController = (_a5 = class extends Disposable {
1006
+ constructor(_sheetClipboardService, _renderManagerService, _sheetDrawingService) {
1007
+ super();
1008
+ __publicField(this, "_copyInfo");
1009
+ this._sheetClipboardService = _sheetClipboardService, this._renderManagerService = _renderManagerService, this._sheetDrawingService = _sheetDrawingService, this._initCopyPaste();
1010
+ }
1011
+ _initCopyPaste() {
1012
+ this._sheetClipboardService.addClipboardHook({
1013
+ id: "SHEET_IMAGE_UI_PLUGIN",
1014
+ onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => this._collect(unitId, subUnitId, range), "onBeforeCopy"),
1015
+ onPasteCells: /* @__PURE__ */ __name((pasteFrom, pasteTo, data, payload) => {
1016
+ const { copyType = COPY_TYPE.COPY, pasteType } = payload, { range: copyRange } = pasteFrom || {}, { range: pastedRange, unitId, subUnitId } = pasteTo;
1017
+ return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
1018
+ }, "onPasteCells"),
1019
+ onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => ({ undos: [], redos: [] }), "onPastePlainText")
1020
+ });
1021
+ }
1022
+ _collect(unitId, subUnitId, range) {
1023
+ var _a11;
1024
+ const skeletonManagerService = (_a11 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(SheetSkeletonManagerService);
1025
+ if (!skeletonManagerService) return;
1026
+ const selectionRect = skeletonManagerService.attachRangeWithCoord(range);
1027
+ if (!selectionRect)
1028
+ return;
1029
+ const { startX, endX, startY, endY } = selectionRect, drawings = this._sheetDrawingService.getDrawingData(unitId, subUnitId), containedDrawings = [];
1030
+ Object.keys(drawings).forEach((drawingId) => {
1031
+ const drawing = drawings[drawingId], { transform } = drawing;
1032
+ if (drawing.anchorType !== SheetDrawingAnchorType.Both || !transform)
1033
+ return;
1034
+ const { left = 0, top = 0, width = 0, height = 0 } = transform, { drawingStartX, drawingEndX, drawingStartY, drawingEndY } = {
1035
+ drawingStartX: left,
1036
+ drawingEndX: left + width,
1037
+ drawingStartY: top,
1038
+ drawingEndY: top + height
1039
+ };
1040
+ startX <= drawingStartX && drawingEndX <= endX && startY <= drawingStartY && drawingEndY <= endY && containedDrawings.push(drawing);
1041
+ }), containedDrawings.length && (this._copyInfo = {
1042
+ drawings: containedDrawings,
1043
+ unitId,
1044
+ subUnitId
1045
+ });
1046
+ }
1047
+ // eslint-disable-next-line max-lines-per-function
1048
+ _generateMutations(pastedRange, copyInfo) {
1049
+ var _a11;
1050
+ if (!this._copyInfo)
1051
+ return { redos: [], undos: [] };
1052
+ if ([
1053
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
1054
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
1055
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
1056
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA
1057
+ ].includes(
1058
+ copyInfo.pasteType
1059
+ ))
1060
+ return { redos: [], undos: [] };
1061
+ const { copyRange } = copyInfo;
1062
+ if (!copyRange)
1063
+ return { redos: [], undos: [] };
1064
+ const { drawings, unitId, subUnitId } = this._copyInfo, { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyRange, pastedRange]), { row: copyRow, col: copyCol } = mapFunc(vCopyRange.startRow, vCopyRange.startColumn), { row: pasteRow, col: pasteCol } = mapFunc(vPastedRange.startRow, vPastedRange.startColumn), skeletonManagerService = (_a11 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(SheetSkeletonManagerService);
1065
+ if (!skeletonManagerService)
1066
+ return { redos: [], undos: [] };
1067
+ const copyRect = skeletonManagerService.attachRangeWithCoord({
1068
+ startRow: copyRow,
1069
+ endRow: copyRow,
1070
+ startColumn: copyCol,
1071
+ endColumn: copyCol
1072
+ }), pasteRect = skeletonManagerService.attachRangeWithCoord({
1073
+ startRow: pasteRow,
1074
+ endRow: pasteRow,
1075
+ startColumn: pasteCol,
1076
+ endColumn: pasteCol
1077
+ });
1078
+ if (!copyRect || !pasteRect)
1079
+ return { redos: [], undos: [] };
1080
+ const redos = [], undos = [], leftOffset = pasteRect.startX - copyRect.startX, topOffset = pasteRect.startY - copyRect.startY, rowOffset = pasteRow - copyRow, columnOffset = pasteCol - copyCol, isCut = copyInfo.copyType === COPY_TYPE.CUT, { _sheetDrawingService } = this;
1081
+ return drawings.forEach((drawing) => {
1082
+ const { transform, sheetTransform } = drawing;
1083
+ if (!transform)
1084
+ return;
1085
+ const drawingObject = {
1086
+ ...drawing,
1087
+ unitId,
1088
+ subUnitId,
1089
+ drawingId: isCut ? drawing.drawingId : Tools.generateRandomId(),
1090
+ transform: {
1091
+ ...transform,
1092
+ left: transform.left + leftOffset,
1093
+ top: transform.top + topOffset
1094
+ },
1095
+ sheetTransform: {
1096
+ to: { ...sheetTransform.to, row: sheetTransform.to.row + rowOffset, column: sheetTransform.to.column + columnOffset },
1097
+ from: { ...sheetTransform.from, row: sheetTransform.from.row + rowOffset, column: sheetTransform.from.column + columnOffset }
1098
+ }
1099
+ };
1100
+ if (isCut) {
1101
+ const { undo, redo, objects } = _sheetDrawingService.getBatchUpdateOp([drawingObject]);
1102
+ redos.push({
1103
+ id: SetDrawingApplyMutation.id,
1104
+ params: {
1105
+ unitId,
1106
+ subUnitId,
1107
+ type: DrawingApplyType.UPDATE,
1108
+ op: redo,
1109
+ objects
1110
+ }
1111
+ }), undos.push({
1112
+ id: SetDrawingApplyMutation.id,
1113
+ params: {
1114
+ unitId,
1115
+ subUnitId,
1116
+ type: DrawingApplyType.UPDATE,
1117
+ op: undo,
1118
+ objects
1119
+ }
1120
+ });
1121
+ } else {
1122
+ const { undo, redo, objects } = _sheetDrawingService.getBatchAddOp([drawingObject]);
1123
+ redos.push({ id: SetDrawingApplyMutation.id, params: { op: redo, unitId, subUnitId, objects, type: DrawingApplyType.INSERT } }), undos.push({ id: SetDrawingApplyMutation.id, params: { op: undo, unitId, subUnitId, objects, type: DrawingApplyType.REMOVE } });
1124
+ }
1125
+ }), {
1126
+ redos,
1127
+ undos
1128
+ };
1129
+ }
1130
+ }, __name(_a5, "SheetsDrawingCopyPasteController"), _a5);
1131
+ SheetsDrawingCopyPasteController = __decorateClass$5([
1132
+ __decorateParam$5(0, ISheetClipboardService),
1133
+ __decorateParam$5(1, IRenderManagerService),
1134
+ __decorateParam$5(2, ISheetDrawingService)
1135
+ ], SheetsDrawingCopyPasteController);
1136
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1137
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1138
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1139
+ return kind && result && __defProp$4(target, key, result), result;
1140
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a6;
1141
+ let SheetDrawingPermissionController = (_a6 = class extends Disposable {
1142
+ constructor(_drawingManagerService, _renderManagerService, _permissionService, _univerInstanceService, _userManagerService) {
1143
+ super(), this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._permissionService = _permissionService, this._univerInstanceService = _univerInstanceService, this._userManagerService = _userManagerService, this._initDrawingVisible(), this._initDrawingEditable(), this._initViewPermissionChange(), this._initEditPermissionChange();
1144
+ }
1145
+ _initDrawingVisible() {
1146
+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
1147
+ this.disposeWithMe(
1148
+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
1149
+ if (!workbook) {
1150
+ this._drawingManagerService.setDrawingVisible(!1);
1151
+ return;
1152
+ }
1153
+ workbook.activeSheet$.subscribe((sheet) => {
1154
+ if (!sheet) {
1155
+ this._drawingManagerService.setDrawingVisible(!1);
1156
+ return;
1157
+ }
1158
+ const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
1159
+ if (this._permissionService.composePermission([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).every((permission) => permission.value))
1160
+ this._drawingManagerService.setDrawingVisible(!0);
1161
+ else {
1162
+ this._drawingManagerService.setDrawingVisible(!1);
1163
+ 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;
1164
+ if (scene == null)
1165
+ return;
1166
+ scene.getAllObjectsByOrder().forEach((object) => {
1167
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
1168
+ });
1169
+ }
1170
+ });
1171
+ })
1172
+ );
1173
+ }
1174
+ _initDrawingEditable() {
1175
+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
1176
+ this.disposeWithMe(
1177
+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
1178
+ if (!workbook) {
1179
+ this._drawingManagerService.setDrawingEditable(!1);
1180
+ return;
1181
+ }
1182
+ workbook.activeSheet$.subscribe((sheet) => {
1183
+ if (!sheet) {
1184
+ this._drawingManagerService.setDrawingEditable(!1);
1185
+ return;
1186
+ }
1187
+ const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
1188
+ if (this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value))
1189
+ this._drawingManagerService.setDrawingEditable(!0);
1190
+ else {
1191
+ this._drawingManagerService.setDrawingEditable(!1);
1192
+ 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;
1193
+ if (scene == null)
1194
+ return;
1195
+ scene.getAllObjectsByOrder().forEach((object) => {
1196
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.detachTransformerFrom(object);
1197
+ });
1198
+ }
1199
+ });
1200
+ })
1201
+ );
1202
+ }
1203
+ _initViewPermissionChange() {
1204
+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
1205
+ this.disposeWithMe(
1206
+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
1207
+ workbook && workbook.activeSheet$.subscribe((sheet) => {
1208
+ var _a11;
1209
+ if (!sheet)
1210
+ return;
1211
+ const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
1212
+ let initialViewPermission = !0;
1213
+ const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
1214
+ if (scene == null)
1215
+ return;
1216
+ const transformer = scene.getTransformerByCreate(), worksheetViewPermission$ = this._permissionService.composePermission$([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));
1217
+ worksheetViewPermission$ == null || worksheetViewPermission$.pipe(
1218
+ filter((permission) => permission !== initialViewPermission),
1219
+ distinctUntilChanged()
1220
+ ).subscribe({
1221
+ next: /* @__PURE__ */ __name((permission) => {
1222
+ initialViewPermission = permission, this._drawingManagerService.setDrawingVisible(permission);
1223
+ const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
1224
+ permission ? this._drawingManagerService.addNotification(drawingDataValues) : (objects.forEach((object) => {
1225
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
1226
+ }), transformer.clearSelectedObjects());
1227
+ }, "next")
1228
+ }), (_a11 = this._permissionService.getPermissionPoint$(new WorksheetViewPermission(unitId, subUnitId).id)) == null || _a11.pipe(
1229
+ filter((permission) => permission.value !== initialViewPermission),
1230
+ distinctUntilChanged()
1231
+ ).subscribe({
1232
+ complete: /* @__PURE__ */ __name(() => {
1233
+ initialViewPermission = !0, this._drawingManagerService.setDrawingVisible(!0);
1234
+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
1235
+ this._drawingManagerService.addNotification(drawingDataValues);
1236
+ }, "complete")
1237
+ });
1238
+ });
1239
+ })
1240
+ );
1241
+ }
1242
+ _initEditPermissionChange() {
1243
+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
1244
+ this.disposeWithMe(
1245
+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
1246
+ workbook && workbook.activeSheet$.subscribe((sheet) => {
1247
+ var _a11;
1248
+ if (!sheet)
1249
+ return;
1250
+ const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
1251
+ let initialEditPermission = !0;
1252
+ const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
1253
+ if (scene == null)
1254
+ return;
1255
+ const transformer = scene.getTransformerByCreate(), composeWorksheetEditPermission = this._permissionService.composePermission$([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));
1256
+ composeWorksheetEditPermission == null || composeWorksheetEditPermission.pipe(
1257
+ filter((permission) => permission !== initialEditPermission),
1258
+ distinctUntilChanged()
1259
+ ).subscribe({
1260
+ next: /* @__PURE__ */ __name((permission) => {
1261
+ initialEditPermission = permission, this._drawingManagerService.setDrawingEditable(permission);
1262
+ const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
1263
+ permission ? (objects.forEach((object) => {
1264
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.attachTransformerTo(object);
1265
+ }), this._drawingManagerService.addNotification(drawingDataValues)) : (objects.forEach((object) => {
1266
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.detachTransformerFrom(object);
1267
+ }), transformer.clearSelectedObjects());
1268
+ }, "next")
1269
+ }), (_a11 = this._permissionService.getPermissionPoint$(new WorksheetEditPermission(unitId, subUnitId).id)) == null || _a11.pipe(
1270
+ filter((permission) => permission.value !== initialEditPermission),
1271
+ distinctUntilChanged()
1272
+ ).subscribe({
1273
+ complete: /* @__PURE__ */ __name(() => {
1274
+ initialEditPermission = !0;
1275
+ 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;
1276
+ if (scene2 == null)
1277
+ return;
1278
+ this._drawingManagerService.setDrawingEditable(!0), scene2.getAllObjectsByOrder().forEach((object) => {
1279
+ object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene2.detachTransformerFrom(object);
1280
+ });
1281
+ }, "complete")
1282
+ });
1283
+ });
1284
+ })
1285
+ );
1286
+ }
1287
+ }, __name(_a6, "SheetDrawingPermissionController"), _a6);
1288
+ SheetDrawingPermissionController = __decorateClass$4([
1289
+ __decorateParam$4(0, IDrawingManagerService),
1290
+ __decorateParam$4(1, IRenderManagerService),
1291
+ __decorateParam$4(2, IPermissionService),
1292
+ __decorateParam$4(3, IUniverInstanceService),
1293
+ __decorateParam$4(4, Inject(UserManagerService))
1294
+ ], SheetDrawingPermissionController);
1295
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1296
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1297
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1298
+ return kind && result && __defProp$3(target, key, result), result;
1299
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a7;
1300
+ let SheetDrawingPrintingController = (_a7 = class extends Disposable {
1301
+ constructor(_sheetPrintInterceptorService, _drawingRenderService, _drawingManagerService, _renderManagerService) {
1302
+ super(), this._sheetPrintInterceptorService = _sheetPrintInterceptorService, this._drawingRenderService = _drawingRenderService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._initPrinting();
1303
+ }
1304
+ _initPrinting() {
1305
+ this.disposeWithMe(
1306
+ this._sheetPrintInterceptorService.interceptor.intercept(
1307
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,
1308
+ {
1309
+ handler: /* @__PURE__ */ __name((_param, pos, next) => {
1310
+ const { unitId, scene, subUnitId } = pos, unitData = this._drawingManagerService.getDrawingDataForUnit(unitId), subUnitData = unitData == null ? void 0 : unitData[subUnitId];
1311
+ return subUnitData && subUnitData.order.forEach((id) => {
1312
+ this._drawingRenderService.renderDrawing(subUnitData.data[id], scene);
1313
+ }), next();
1314
+ }, "handler")
1315
+ }
1316
+ )
1317
+ ), this.disposeWithMe(
1318
+ this._sheetPrintInterceptorService.interceptor.intercept(
1319
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,
1320
+ {
1321
+ handler: /* @__PURE__ */ __name((range, pos, next) => {
1322
+ const { unitId, subUnitId } = pos, renderer = this._renderManagerService.getRenderById(unitId);
1323
+ if (!renderer)
1324
+ return next(range);
1325
+ const skeleton = renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
1326
+ if (!skeleton)
1327
+ return next(range);
1328
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId), subUnitData = unitData == null ? void 0 : unitData[pos.subUnitId];
1329
+ if (!subUnitData)
1330
+ return next(range);
1331
+ const { scaleX, scaleY } = renderer.scene, newRange = range ? { ...range } : { startColumn: 0, endColumn: 0, endRow: 0, startRow: 0 }, data = subUnitData.order.map((key) => subUnitData.data[key]).filter((item) => item.drawingType !== DrawingTypeEnum.DRAWING_DOM);
1332
+ return data.length ? (data.forEach((param) => {
1333
+ if (!param.groupId && param.transform && Tools.isDefine(param.transform.left) && Tools.isDefine(param.transform.top) && Tools.isDefine(param.transform.width) && Tools.isDefine(param.transform.height)) {
1334
+ const start = skeleton.skeleton.getCellPositionByOffset(param.transform.left, param.transform.top, scaleX, scaleY, { x: 0, y: 0 }), end = skeleton.skeleton.getCellPositionByOffset(param.transform.left + param.transform.width, param.transform.top + param.transform.height, scaleX, scaleY, { x: 0, y: 0 });
1335
+ start.column < newRange.startColumn && (newRange.startColumn = start.column), start.row < newRange.startRow && (newRange.startRow = start.row), newRange.endRow < end.row && (newRange.endRow = end.row), newRange.endColumn < end.column && (newRange.endColumn = end.column);
1336
+ }
1337
+ }), next(newRange)) : next(range);
1338
+ }, "handler")
1339
+ }
1340
+ )
1341
+ );
1342
+ }
1343
+ }, __name(_a7, "SheetDrawingPrintingController"), _a7);
1344
+ SheetDrawingPrintingController = __decorateClass$3([
1345
+ __decorateParam$3(0, Inject(SheetPrintInterceptorService)),
1346
+ __decorateParam$3(1, Inject(DrawingRenderService)),
1347
+ __decorateParam$3(2, IDrawingManagerService),
1348
+ __decorateParam$3(3, IRenderManagerService)
1349
+ ], SheetDrawingPrintingController);
1350
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1351
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1352
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1353
+ return kind && result && __defProp$2(target, key, result), result;
1354
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
1355
+ const UPDATE_COMMANDS = [
1356
+ InsertRowCommand.id,
1357
+ InsertColCommand.id,
1358
+ RemoveRowCommand.id,
1359
+ RemoveColCommand.id,
981
1360
  DeleteRangeMoveLeftCommand.id,
982
1361
  DeleteRangeMoveUpCommand.id,
983
1362
  InsertRangeMoveDownCommand.id,
@@ -1001,8 +1380,8 @@ const UPDATE_COMMANDS = [
1001
1380
  SetWorksheetRowHeightMutation.id,
1002
1381
  SetWorksheetColWidthMutation.id
1003
1382
  ];
1004
- var _a4;
1005
- let SheetDrawingTransformAffectedController = (_a4 = class extends Disposable {
1383
+ var _a8;
1384
+ let SheetDrawingTransformAffectedController = (_a8 = class extends Disposable {
1006
1385
  constructor(_context, _renderManagerService, _commandService, _selectionRenderService, _skeletonManagerService, _sheetInterceptorService, _sheetDrawingService, _drawingManagerService, _univerInstanceService) {
1007
1386
  super(), this._context = _context, this._renderManagerService = _renderManagerService, this._commandService = _commandService, this._selectionRenderService = _selectionRenderService, this._skeletonManagerService = _skeletonManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._univerInstanceService = _univerInstanceService, this._sheetInterceptorListener(), this._commandListener(), this._sheetRefreshListener();
1008
1387
  }
@@ -1717,22 +2096,22 @@ let SheetDrawingTransformAffectedController = (_a4 = class extends Disposable {
1717
2096
  }
1718
2097
  }), updateDrawings.length !== 0 && (this._drawingManagerService.refreshTransform(updateDrawings), this._commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]));
1719
2098
  }
1720
- }, __name(_a4, "SheetDrawingTransformAffectedController"), _a4);
1721
- SheetDrawingTransformAffectedController = __decorateClass$6([
1722
- __decorateParam$6(1, IRenderManagerService),
1723
- __decorateParam$6(2, ICommandService),
1724
- __decorateParam$6(3, ISheetSelectionRenderService),
1725
- __decorateParam$6(4, Inject(SheetSkeletonManagerService)),
1726
- __decorateParam$6(5, Inject(SheetInterceptorService)),
1727
- __decorateParam$6(6, ISheetDrawingService),
1728
- __decorateParam$6(7, IDrawingManagerService),
1729
- __decorateParam$6(8, IUniverInstanceService)
2099
+ }, __name(_a8, "SheetDrawingTransformAffectedController"), _a8);
2100
+ SheetDrawingTransformAffectedController = __decorateClass$2([
2101
+ __decorateParam$2(1, IRenderManagerService),
2102
+ __decorateParam$2(2, ICommandService),
2103
+ __decorateParam$2(3, ISheetSelectionRenderService),
2104
+ __decorateParam$2(4, Inject(SheetSkeletonManagerService)),
2105
+ __decorateParam$2(5, Inject(SheetInterceptorService)),
2106
+ __decorateParam$2(6, ISheetDrawingService),
2107
+ __decorateParam$2(7, IDrawingManagerService),
2108
+ __decorateParam$2(8, IUniverInstanceService)
1730
2109
  ], SheetDrawingTransformAffectedController);
1731
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1732
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2110
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2111
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1733
2112
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1734
- return kind && result && __defProp$5(target, key, result), result;
1735
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5");
2113
+ return kind && result && __defProp$1(target, key, result), result;
2114
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
1736
2115
  function transformBound2DOMBound(originBound, scene, skeleton, worksheet) {
1737
2116
  const { scaleX, scaleY } = scene.getAncestorScale(), viewMain = scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN), absolute = {
1738
2117
  left: !0,
@@ -1786,8 +2165,8 @@ const calcPosition = /* @__PURE__ */ __name((targetObject, currentRender, skelet
1786
2165
  absolute: offsetBound.absolute
1787
2166
  };
1788
2167
  }, "calcPosition");
1789
- var _a5;
1790
- let SheetCanvasFloatDomManagerService = (_a5 = class extends Disposable {
2168
+ var _a9;
2169
+ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
1791
2170
  constructor(_renderManagerService, _univerInstanceService, _commandService, _drawingManagerService, _canvasFloatDomService, _sheetDrawingService) {
1792
2171
  super();
1793
2172
  __publicField(this, "_domLayerMap", /* @__PURE__ */ new Map());
@@ -1953,488 +2332,99 @@ let SheetCanvasFloatDomManagerService = (_a5 = class extends Disposable {
1953
2332
  };
1954
2333
  }
1955
2334
  _featureUpdateListener() {
1956
- this.disposeWithMe(
1957
- this._drawingManagerService.update$.subscribe((params) => {
1958
- params.forEach((data) => {
1959
- const sheetDrawing = this._drawingManagerService.getDrawingByParam(data);
1960
- if (!sheetDrawing || sheetDrawing.drawingType !== DrawingTypeEnum$1.DRAWING_DOM)
1961
- return;
1962
- const newValue = {
1963
- ...sheetDrawing.transform
1964
- };
1965
- this._transformChange$.next({ id: data.drawingId, value: newValue });
1966
- });
1967
- })
1968
- );
1969
- }
1970
- _deleteListener() {
1971
- this.disposeWithMe(
1972
- this._drawingManagerService.remove$.subscribe((params) => {
1973
- params.forEach((param) => {
1974
- this._removeDom(param.drawingId);
1975
- });
1976
- })
1977
- );
1978
- }
1979
- addFloatDomToPosition(layer, propId) {
1980
- const target = getSheetCommandTarget(this._univerInstanceService, {
1981
- unitId: layer.unitId,
1982
- subUnitId: layer.subUnitId
1983
- });
1984
- if (!target)
1985
- throw new Error("cannot find current target!");
1986
- const { unitId, subUnitId } = target, { initPosition, componentKey, data, allowTransform = !0 } = layer, id = propId != null ? propId : generateRandomId(), sheetTransform = this._getPosition(initPosition, unitId);
1987
- if (sheetTransform == null)
1988
- return;
1989
- this._ensureMap(unitId, subUnitId).set(id, layer);
1990
- const sheetDrawingParam = {
1991
- unitId,
1992
- subUnitId,
1993
- drawingId: id,
1994
- drawingType: DrawingTypeEnum$1.DRAWING_DOM,
1995
- componentKey,
1996
- sheetTransform,
1997
- transform: {
1998
- left: initPosition.startX,
1999
- top: initPosition.startY,
2000
- width: initPosition.endX - initPosition.startX,
2001
- height: initPosition.endY - initPosition.startY
2002
- },
2003
- data,
2004
- allowTransform
2005
- };
2006
- return this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
2007
- unitId,
2008
- drawings: [sheetDrawingParam]
2009
- }), {
2010
- id,
2011
- dispose: /* @__PURE__ */ __name(() => {
2012
- this._removeDom(id, !0);
2013
- }, "dispose")
2014
- };
2015
- }
2016
- _removeDom(id, removeDrawing = !1) {
2017
- const info = this._domLayerInfoMap.get(id);
2018
- if (!info)
2019
- return;
2020
- const { unitId, subUnitId } = info;
2021
- this._domLayerInfoMap.delete(id), info.dispose.dispose();
2022
- const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2023
- if (renderObject && renderObject.scene.removeObject(info.rect), removeDrawing) {
2024
- this._ensureMap(unitId, subUnitId).delete(id);
2025
- const param = this._drawingManagerService.getDrawingByParam({ unitId, subUnitId, drawingId: id });
2026
- if (!param)
2027
- return;
2028
- const jsonOp = this._sheetDrawingService.getBatchRemoveOp([param]), { redo, objects } = jsonOp;
2029
- this._commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.REMOVE });
2030
- }
2031
- }
2032
- addHook(hook) {
2033
- return this._hooks.push(hook), {
2034
- dispose: /* @__PURE__ */ __name(() => {
2035
- const index = this._hooks.findIndex((h) => h === hook);
2036
- this._hooks.splice(index, 1);
2037
- }, "dispose")
2038
- };
2039
- }
2040
- }, __name(_a5, "SheetCanvasFloatDomManagerService"), _a5);
2041
- SheetCanvasFloatDomManagerService = __decorateClass$5([
2042
- OnLifecycle(LifecycleStages.Starting, SheetCanvasFloatDomManagerService),
2043
- __decorateParam$5(0, Inject(IRenderManagerService)),
2044
- __decorateParam$5(1, IUniverInstanceService),
2045
- __decorateParam$5(2, Inject(ICommandService)),
2046
- __decorateParam$5(3, IDrawingManagerService),
2047
- __decorateParam$5(4, Inject(CanvasFloatDomService)),
2048
- __decorateParam$5(5, ISheetDrawingService)
2049
- ], SheetCanvasFloatDomManagerService);
2050
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2051
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2052
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2053
- return kind && result && __defProp$4(target, key, result), result;
2054
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a6;
2055
- let SheetDrawingPrintingController = (_a6 = class extends Disposable {
2056
- constructor(_sheetPrintInterceptorService, _drawingRenderService, _drawingManagerService, _renderManagerService) {
2057
- super(), this._sheetPrintInterceptorService = _sheetPrintInterceptorService, this._drawingRenderService = _drawingRenderService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._initPrinting();
2058
- }
2059
- _initPrinting() {
2060
- this.disposeWithMe(
2061
- this._sheetPrintInterceptorService.interceptor.intercept(
2062
- this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,
2063
- {
2064
- handler: /* @__PURE__ */ __name((_param, pos, next) => {
2065
- const { unitId, scene, subUnitId } = pos, unitData = this._drawingManagerService.getDrawingDataForUnit(unitId), subUnitData = unitData == null ? void 0 : unitData[subUnitId];
2066
- return subUnitData && subUnitData.order.forEach((id) => {
2067
- this._drawingRenderService.renderDrawing(subUnitData.data[id], scene);
2068
- }), next();
2069
- }, "handler")
2070
- }
2071
- )
2072
- ), this.disposeWithMe(
2073
- this._sheetPrintInterceptorService.interceptor.intercept(
2074
- this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,
2075
- {
2076
- handler: /* @__PURE__ */ __name((range, pos, next) => {
2077
- const { unitId, subUnitId } = pos, renderer = this._renderManagerService.getRenderById(unitId);
2078
- if (!renderer)
2079
- return next(range);
2080
- const skeleton = renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
2081
- if (!skeleton)
2082
- return next(range);
2083
- const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId), subUnitData = unitData == null ? void 0 : unitData[pos.subUnitId];
2084
- if (!subUnitData)
2085
- return next(range);
2086
- const { scaleX, scaleY } = renderer.scene, newRange = range ? { ...range } : { startColumn: 0, endColumn: 0, endRow: 0, startRow: 0 }, data = subUnitData.order.map((key) => subUnitData.data[key]).filter((item) => item.drawingType !== DrawingTypeEnum.DRAWING_DOM);
2087
- return data.length ? (data.forEach((param) => {
2088
- if (!param.groupId && param.transform && Tools.isDefine(param.transform.left) && Tools.isDefine(param.transform.top) && Tools.isDefine(param.transform.width) && Tools.isDefine(param.transform.height)) {
2089
- const start = skeleton.skeleton.getCellPositionByOffset(param.transform.left, param.transform.top, scaleX, scaleY, { x: 0, y: 0 }), end = skeleton.skeleton.getCellPositionByOffset(param.transform.left + param.transform.width, param.transform.top + param.transform.height, scaleX, scaleY, { x: 0, y: 0 });
2090
- start.column < newRange.startColumn && (newRange.startColumn = start.column), start.row < newRange.startRow && (newRange.startRow = start.row), newRange.endRow < end.row && (newRange.endRow = end.row), newRange.endColumn < end.column && (newRange.endColumn = end.column);
2091
- }
2092
- }), next(newRange)) : next(range);
2093
- }, "handler")
2094
- }
2095
- )
2096
- );
2097
- }
2098
- }, __name(_a6, "SheetDrawingPrintingController"), _a6);
2099
- SheetDrawingPrintingController = __decorateClass$4([
2100
- OnLifecycle(LifecycleStages.Rendered, SheetDrawingPrintingController),
2101
- __decorateParam$4(0, Inject(SheetPrintInterceptorService)),
2102
- __decorateParam$4(1, Inject(DrawingRenderService)),
2103
- __decorateParam$4(2, IDrawingManagerService),
2104
- __decorateParam$4(3, IRenderManagerService)
2105
- ], SheetDrawingPrintingController);
2106
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2107
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2108
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2109
- return kind && result && __defProp$3(target, key, result), result;
2110
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a7;
2111
- let SheetDrawingPermissionController = (_a7 = class extends Disposable {
2112
- constructor(_drawingManagerService, _renderManagerService, _permissionService, _univerInstanceService, _userManagerService) {
2113
- super(), this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._permissionService = _permissionService, this._univerInstanceService = _univerInstanceService, this._userManagerService = _userManagerService, this._initDrawingVisible(), this._initDrawingEditable(), this._initViewPermissionChange(), this._initEditPermissionChange();
2114
- }
2115
- _initDrawingVisible() {
2116
- const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
2117
- this.disposeWithMe(
2118
- combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
2119
- if (!workbook) {
2120
- this._drawingManagerService.setDrawingVisible(!1);
2121
- return;
2122
- }
2123
- workbook.activeSheet$.subscribe((sheet) => {
2124
- if (!sheet) {
2125
- this._drawingManagerService.setDrawingVisible(!1);
2126
- return;
2127
- }
2128
- const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
2129
- if (this._permissionService.composePermission([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).every((permission) => permission.value))
2130
- this._drawingManagerService.setDrawingVisible(!0);
2131
- else {
2132
- this._drawingManagerService.setDrawingVisible(!1);
2133
- 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;
2134
- if (scene == null)
2135
- return;
2136
- scene.getAllObjectsByOrder().forEach((object) => {
2137
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
2138
- });
2139
- }
2140
- });
2141
- })
2142
- );
2143
- }
2144
- _initDrawingEditable() {
2145
- const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
2146
- this.disposeWithMe(
2147
- combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
2148
- if (!workbook) {
2149
- this._drawingManagerService.setDrawingEditable(!1);
2150
- return;
2151
- }
2152
- workbook.activeSheet$.subscribe((sheet) => {
2153
- if (!sheet) {
2154
- this._drawingManagerService.setDrawingEditable(!1);
2155
- return;
2156
- }
2157
- const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
2158
- if (this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value))
2159
- this._drawingManagerService.setDrawingEditable(!0);
2160
- else {
2161
- this._drawingManagerService.setDrawingEditable(!1);
2162
- 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;
2163
- if (scene == null)
2164
- return;
2165
- scene.getAllObjectsByOrder().forEach((object) => {
2166
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.detachTransformerFrom(object);
2167
- });
2168
- }
2169
- });
2170
- })
2171
- );
2172
- }
2173
- _initViewPermissionChange() {
2174
- const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
2175
- this.disposeWithMe(
2176
- combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
2177
- workbook && workbook.activeSheet$.subscribe((sheet) => {
2178
- var _a11;
2179
- if (!sheet)
2180
- return;
2181
- const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
2182
- let initialViewPermission = !0;
2183
- const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
2184
- if (scene == null)
2185
- return;
2186
- const transformer = scene.getTransformerByCreate(), worksheetViewPermission$ = this._permissionService.composePermission$([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));
2187
- worksheetViewPermission$ == null || worksheetViewPermission$.pipe(
2188
- filter((permission) => permission !== initialViewPermission),
2189
- distinctUntilChanged()
2190
- ).subscribe({
2191
- next: /* @__PURE__ */ __name((permission) => {
2192
- initialViewPermission = permission, this._drawingManagerService.setDrawingVisible(permission);
2193
- const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2194
- permission ? this._drawingManagerService.addNotification(drawingDataValues) : (objects.forEach((object) => {
2195
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.removeObject(object);
2196
- }), transformer.clearSelectedObjects());
2197
- }, "next")
2198
- }), (_a11 = this._permissionService.getPermissionPoint$(new WorksheetViewPermission(unitId, subUnitId).id)) == null || _a11.pipe(
2199
- filter((permission) => permission.value !== initialViewPermission),
2200
- distinctUntilChanged()
2201
- ).subscribe({
2202
- complete: /* @__PURE__ */ __name(() => {
2203
- initialViewPermission = !0, this._drawingManagerService.setDrawingVisible(!0);
2204
- const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2205
- this._drawingManagerService.addNotification(drawingDataValues);
2206
- }, "complete")
2207
- });
2335
+ this.disposeWithMe(
2336
+ this._drawingManagerService.update$.subscribe((params) => {
2337
+ params.forEach((data) => {
2338
+ const sheetDrawing = this._drawingManagerService.getDrawingByParam(data);
2339
+ if (!sheetDrawing || sheetDrawing.drawingType !== DrawingTypeEnum$1.DRAWING_DOM)
2340
+ return;
2341
+ const newValue = {
2342
+ ...sheetDrawing.transform
2343
+ };
2344
+ this._transformChange$.next({ id: data.drawingId, value: newValue });
2208
2345
  });
2209
2346
  })
2210
2347
  );
2211
2348
  }
2212
- _initEditPermissionChange() {
2213
- const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
2349
+ _deleteListener() {
2214
2350
  this.disposeWithMe(
2215
- combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {
2216
- workbook && workbook.activeSheet$.subscribe((sheet) => {
2217
- var _a11;
2218
- if (!sheet)
2219
- return;
2220
- const unitId = workbook.getUnitId(), subUnitId = sheet.getSheetId();
2221
- let initialEditPermission = !0;
2222
- const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
2223
- if (scene == null)
2224
- return;
2225
- const transformer = scene.getTransformerByCreate(), composeWorksheetEditPermission = this._permissionService.composePermission$([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));
2226
- composeWorksheetEditPermission == null || composeWorksheetEditPermission.pipe(
2227
- filter((permission) => permission !== initialEditPermission),
2228
- distinctUntilChanged()
2229
- ).subscribe({
2230
- next: /* @__PURE__ */ __name((permission) => {
2231
- initialEditPermission = permission, this._drawingManagerService.setDrawingEditable(permission);
2232
- const objects = scene.getAllObjectsByOrder(), drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId), drawingDataValues = Object.values(drawingData);
2233
- permission ? (objects.forEach((object) => {
2234
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.attachTransformerTo(object);
2235
- }), this._drawingManagerService.addNotification(drawingDataValues)) : (objects.forEach((object) => {
2236
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene.detachTransformerFrom(object);
2237
- }), transformer.clearSelectedObjects());
2238
- }, "next")
2239
- }), (_a11 = this._permissionService.getPermissionPoint$(new WorksheetEditPermission(unitId, subUnitId).id)) == null || _a11.pipe(
2240
- filter((permission) => permission.value !== initialEditPermission),
2241
- distinctUntilChanged()
2242
- ).subscribe({
2243
- complete: /* @__PURE__ */ __name(() => {
2244
- initialEditPermission = !0;
2245
- 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;
2246
- if (scene2 == null)
2247
- return;
2248
- this._drawingManagerService.setDrawingEditable(!0), scene2.getAllObjectsByOrder().forEach((object) => {
2249
- object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId)) && scene2.detachTransformerFrom(object);
2250
- });
2251
- }, "complete")
2252
- });
2351
+ this._drawingManagerService.remove$.subscribe((params) => {
2352
+ params.forEach((param) => {
2353
+ this._removeDom(param.drawingId);
2253
2354
  });
2254
2355
  })
2255
2356
  );
2256
2357
  }
2257
- }, __name(_a7, "SheetDrawingPermissionController"), _a7);
2258
- SheetDrawingPermissionController = __decorateClass$3([
2259
- OnLifecycle(LifecycleStages.Rendered, SheetDrawingPermissionController),
2260
- __decorateParam$3(0, IDrawingManagerService),
2261
- __decorateParam$3(1, IRenderManagerService),
2262
- __decorateParam$3(2, IPermissionService),
2263
- __decorateParam$3(3, IUniverInstanceService),
2264
- __decorateParam$3(4, Inject(UserManagerService))
2265
- ], SheetDrawingPermissionController);
2266
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2267
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2268
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2269
- return kind && result && __defProp$2(target, key, result), result;
2270
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a8;
2271
- let SheetsDrawingCopyPasteController = (_a8 = class extends Disposable {
2272
- constructor(_sheetClipboardService, _renderManagerService, _sheetDrawingService) {
2273
- super();
2274
- __publicField(this, "_copyInfo");
2275
- this._sheetClipboardService = _sheetClipboardService, this._renderManagerService = _renderManagerService, this._sheetDrawingService = _sheetDrawingService, this._initCopyPaste();
2276
- }
2277
- _initCopyPaste() {
2278
- this._sheetClipboardService.addClipboardHook({
2279
- id: "SHEET_IMAGE_UI_PLUGIN",
2280
- onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => this._collect(unitId, subUnitId, range), "onBeforeCopy"),
2281
- onPasteCells: /* @__PURE__ */ __name((pasteFrom, pasteTo, data, payload) => {
2282
- const { copyType = COPY_TYPE.COPY, pasteType } = payload, { range: copyRange } = pasteFrom || {}, { range: pastedRange, unitId, subUnitId } = pasteTo;
2283
- return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
2284
- }, "onPasteCells"),
2285
- onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => ({ undos: [], redos: [] }), "onPastePlainText")
2358
+ addFloatDomToPosition(layer, propId) {
2359
+ const target = getSheetCommandTarget(this._univerInstanceService, {
2360
+ unitId: layer.unitId,
2361
+ subUnitId: layer.subUnitId
2286
2362
  });
2287
- }
2288
- _collect(unitId, subUnitId, range) {
2289
- var _a11;
2290
- const skeletonManagerService = (_a11 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(SheetSkeletonManagerService);
2291
- if (!skeletonManagerService) return;
2292
- const selectionRect = skeletonManagerService.attachRangeWithCoord(range);
2293
- if (!selectionRect)
2363
+ if (!target)
2364
+ throw new Error("cannot find current target!");
2365
+ const { unitId, subUnitId } = target, { initPosition, componentKey, data, allowTransform = !0 } = layer, id = propId != null ? propId : generateRandomId(), sheetTransform = this._getPosition(initPosition, unitId);
2366
+ if (sheetTransform == null)
2294
2367
  return;
2295
- const { startX, endX, startY, endY } = selectionRect, drawings = this._sheetDrawingService.getDrawingData(unitId, subUnitId), containedDrawings = [];
2296
- Object.keys(drawings).forEach((drawingId) => {
2297
- const drawing = drawings[drawingId], { transform } = drawing;
2298
- if (drawing.anchorType !== SheetDrawingAnchorType.Both || !transform)
2299
- return;
2300
- const { left = 0, top = 0, width = 0, height = 0 } = transform, { drawingStartX, drawingEndX, drawingStartY, drawingEndY } = {
2301
- drawingStartX: left,
2302
- drawingEndX: left + width,
2303
- drawingStartY: top,
2304
- drawingEndY: top + height
2305
- };
2306
- startX <= drawingStartX && drawingEndX <= endX && startY <= drawingStartY && drawingEndY <= endY && containedDrawings.push(drawing);
2307
- }), containedDrawings.length && (this._copyInfo = {
2308
- drawings: containedDrawings,
2368
+ this._ensureMap(unitId, subUnitId).set(id, layer);
2369
+ const sheetDrawingParam = {
2309
2370
  unitId,
2310
- subUnitId
2311
- });
2312
- }
2313
- // eslint-disable-next-line max-lines-per-function
2314
- _generateMutations(pastedRange, copyInfo) {
2315
- var _a11;
2316
- if (!this._copyInfo)
2317
- return { redos: [], undos: [] };
2318
- if ([
2319
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
2320
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
2321
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
2322
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA
2323
- ].includes(
2324
- copyInfo.pasteType
2325
- ))
2326
- return { redos: [], undos: [] };
2327
- const { copyRange } = copyInfo;
2328
- if (!copyRange)
2329
- return { redos: [], undos: [] };
2330
- const { drawings, unitId, subUnitId } = this._copyInfo, { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyRange, pastedRange]), { row: copyRow, col: copyCol } = mapFunc(vCopyRange.startRow, vCopyRange.startColumn), { row: pasteRow, col: pasteCol } = mapFunc(vPastedRange.startRow, vPastedRange.startColumn), skeletonManagerService = (_a11 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(SheetSkeletonManagerService);
2331
- if (!skeletonManagerService)
2332
- return { redos: [], undos: [] };
2333
- const copyRect = skeletonManagerService.attachRangeWithCoord({
2334
- startRow: copyRow,
2335
- endRow: copyRow,
2336
- startColumn: copyCol,
2337
- endColumn: copyCol
2338
- }), pasteRect = skeletonManagerService.attachRangeWithCoord({
2339
- startRow: pasteRow,
2340
- endRow: pasteRow,
2341
- startColumn: pasteCol,
2342
- endColumn: pasteCol
2343
- });
2344
- if (!copyRect || !pasteRect)
2345
- return { redos: [], undos: [] };
2346
- const redos = [], undos = [], leftOffset = pasteRect.startX - copyRect.startX, topOffset = pasteRect.startY - copyRect.startY, rowOffset = pasteRow - copyRow, columnOffset = pasteCol - copyCol, isCut = copyInfo.copyType === COPY_TYPE.CUT, { _sheetDrawingService } = this;
2347
- return drawings.forEach((drawing) => {
2348
- const { transform, sheetTransform } = drawing;
2349
- if (!transform)
2350
- return;
2351
- const drawingObject = {
2352
- ...drawing,
2353
- unitId,
2354
- subUnitId,
2355
- drawingId: isCut ? drawing.drawingId : Tools.generateRandomId(),
2356
- transform: {
2357
- ...transform,
2358
- left: transform.left + leftOffset,
2359
- top: transform.top + topOffset
2360
- },
2361
- sheetTransform: {
2362
- to: { ...sheetTransform.to, row: sheetTransform.to.row + rowOffset, column: sheetTransform.to.column + columnOffset },
2363
- from: { ...sheetTransform.from, row: sheetTransform.from.row + rowOffset, column: sheetTransform.from.column + columnOffset }
2364
- }
2365
- };
2366
- if (isCut) {
2367
- const { undo, redo, objects } = _sheetDrawingService.getBatchUpdateOp([drawingObject]);
2368
- redos.push({
2369
- id: SetDrawingApplyMutation.id,
2370
- params: {
2371
- unitId,
2372
- subUnitId,
2373
- type: DrawingApplyType.UPDATE,
2374
- op: redo,
2375
- objects
2376
- }
2377
- }), undos.push({
2378
- id: SetDrawingApplyMutation.id,
2379
- params: {
2380
- unitId,
2381
- subUnitId,
2382
- type: DrawingApplyType.UPDATE,
2383
- op: undo,
2384
- objects
2385
- }
2386
- });
2387
- } else {
2388
- const { undo, redo, objects } = _sheetDrawingService.getBatchAddOp([drawingObject]);
2389
- redos.push({ id: SetDrawingApplyMutation.id, params: { op: redo, unitId, subUnitId, objects, type: DrawingApplyType.INSERT } }), undos.push({ id: SetDrawingApplyMutation.id, params: { op: undo, unitId, subUnitId, objects, type: DrawingApplyType.REMOVE } });
2390
- }
2371
+ subUnitId,
2372
+ drawingId: id,
2373
+ drawingType: DrawingTypeEnum$1.DRAWING_DOM,
2374
+ componentKey,
2375
+ sheetTransform,
2376
+ transform: {
2377
+ left: initPosition.startX,
2378
+ top: initPosition.startY,
2379
+ width: initPosition.endX - initPosition.startX,
2380
+ height: initPosition.endY - initPosition.startY
2381
+ },
2382
+ data,
2383
+ allowTransform
2384
+ };
2385
+ return this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
2386
+ unitId,
2387
+ drawings: [sheetDrawingParam]
2391
2388
  }), {
2392
- redos,
2393
- undos
2389
+ id,
2390
+ dispose: /* @__PURE__ */ __name(() => {
2391
+ this._removeDom(id, !0);
2392
+ }, "dispose")
2394
2393
  };
2395
2394
  }
2396
- }, __name(_a8, "SheetsDrawingCopyPasteController"), _a8);
2397
- SheetsDrawingCopyPasteController = __decorateClass$2([
2398
- OnLifecycle(LifecycleStages.Ready, SheetsDrawingCopyPasteController),
2399
- __decorateParam$2(0, ISheetClipboardService),
2400
- __decorateParam$2(1, IRenderManagerService),
2401
- __decorateParam$2(2, ISheetDrawingService)
2402
- ], SheetsDrawingCopyPasteController);
2403
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2404
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2405
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2406
- return kind && result && __defProp$1(target, key, result), result;
2407
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a9;
2408
- let SheetsDrawingRenderController = (_a9 = class extends Disposable {
2409
- constructor(_context, _sheetDrawingService, _drawingManagerService, _lifecycleService, _sheetSelectionRenderService, _sheetSkeletonManagerService) {
2410
- super(), this._context = _context, this._sheetDrawingService = _sheetDrawingService, this._drawingManagerService = _drawingManagerService, this._lifecycleService = _lifecycleService, this._sheetSelectionRenderService = _sheetSelectionRenderService, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._init();
2411
- }
2412
- _init() {
2413
- this._drawingInitializeListener();
2414
- }
2415
- _drawingInitializeListener() {
2416
- if (this._context.type === UniverInstanceType.UNIVER_SHEET) {
2417
- this._sheetDrawingService.initializeNotification(this._context.unitId);
2418
- const data = this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);
2419
- for (const subUnit in data) {
2420
- const subUnitData = data[subUnit];
2421
- for (const drawingId in subUnitData.data) {
2422
- const drawingData = subUnitData.data[drawingId];
2423
- drawingData.transform = drawingPositionToTransform(drawingData.sheetTransform, this._sheetSelectionRenderService, this._sheetSkeletonManagerService);
2424
- }
2425
- }
2426
- this._drawingManagerService.registerDrawingData(this._context.unitId, this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)), this._drawingManagerService.initializeNotification(this._context.unitId);
2395
+ _removeDom(id, removeDrawing = !1) {
2396
+ const info = this._domLayerInfoMap.get(id);
2397
+ if (!info)
2398
+ return;
2399
+ const { unitId, subUnitId } = info;
2400
+ this._domLayerInfoMap.delete(id), info.dispose.dispose();
2401
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2402
+ if (renderObject && renderObject.scene.removeObject(info.rect), removeDrawing) {
2403
+ this._ensureMap(unitId, subUnitId).delete(id);
2404
+ const param = this._drawingManagerService.getDrawingByParam({ unitId, subUnitId, drawingId: id });
2405
+ if (!param)
2406
+ return;
2407
+ const jsonOp = this._sheetDrawingService.getBatchRemoveOp([param]), { redo, objects } = jsonOp;
2408
+ this._commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.REMOVE });
2427
2409
  }
2428
2410
  }
2429
- }, __name(_a9, "SheetsDrawingRenderController"), _a9);
2430
- SheetsDrawingRenderController = __decorateClass$1([
2431
- __decorateParam$1(1, ISheetDrawingService),
2432
- __decorateParam$1(2, IDrawingManagerService),
2433
- __decorateParam$1(3, Inject(LifecycleService)),
2434
- __decorateParam$1(4, Inject(ISheetSelectionRenderService)),
2435
- __decorateParam$1(5, Inject(SheetSkeletonManagerService))
2436
- ], SheetsDrawingRenderController);
2437
- const PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config", defaultPluginConfig = {};
2411
+ addHook(hook) {
2412
+ return this._hooks.push(hook), {
2413
+ dispose: /* @__PURE__ */ __name(() => {
2414
+ const index = this._hooks.findIndex((h) => h === hook);
2415
+ this._hooks.splice(index, 1);
2416
+ }, "dispose")
2417
+ };
2418
+ }
2419
+ }, __name(_a9, "SheetCanvasFloatDomManagerService"), _a9);
2420
+ SheetCanvasFloatDomManagerService = __decorateClass$1([
2421
+ __decorateParam$1(0, Inject(IRenderManagerService)),
2422
+ __decorateParam$1(1, IUniverInstanceService),
2423
+ __decorateParam$1(2, Inject(ICommandService)),
2424
+ __decorateParam$1(3, IDrawingManagerService),
2425
+ __decorateParam$1(4, Inject(CanvasFloatDomService)),
2426
+ __decorateParam$1(5, ISheetDrawingService)
2427
+ ], SheetCanvasFloatDomManagerService);
2438
2428
  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) => {
2439
2429
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2440
2430
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -2449,20 +2439,31 @@ let UniverSheetsDrawingUIPlugin = (_a10 = class extends Plugin {
2449
2439
  menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
2450
2440
  }
2451
2441
  onStarting() {
2452
- this._initDependencies();
2453
- }
2454
- onRendered() {
2455
- this._registerRenderModules();
2456
- }
2457
- _initDependencies() {
2458
- [
2442
+ registerDependencies(this._injector, [
2459
2443
  [SheetCanvasFloatDomManagerService],
2460
2444
  [SheetDrawingUIController],
2461
2445
  [DrawingPopupMenuController],
2462
2446
  [SheetDrawingPrintingController],
2463
2447
  [SheetDrawingPermissionController],
2464
2448
  [SheetsDrawingCopyPasteController]
2465
- ].forEach((dependency) => this._injector.add(dependency));
2449
+ ]), touchDependencies(this._injector, [
2450
+ [SheetCanvasFloatDomManagerService]
2451
+ ]);
2452
+ }
2453
+ onReady() {
2454
+ touchDependencies(this._injector, [
2455
+ [SheetsDrawingCopyPasteController]
2456
+ ]);
2457
+ }
2458
+ onRendered() {
2459
+ this._registerRenderModules(), touchDependencies(this._injector, [
2460
+ [SheetDrawingPermissionController],
2461
+ [SheetDrawingPrintingController],
2462
+ [SheetDrawingUIController]
2463
+ ]);
2464
+ }
2465
+ onSteady() {
2466
+ this._injector.get(DrawingPopupMenuController);
2466
2467
  }
2467
2468
  _registerRenderModules() {
2468
2469
  [