@univerjs/sheets-drawing-ui 1.4.0 → 1.5.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/README.md +9 -5
- package/lib/cjs/index.js +657 -280
- package/lib/es/index.js +662 -285
- package/lib/index.js +662 -285
- package/lib/types/controllers/sheet-drawing-copy-paste.controller.d.ts +7 -3
- package/lib/types/controllers/sheet-drawing-permission.controller.d.ts +2 -0
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +7 -4
- package/lib/types/facade/f-worksheet.d.ts +5 -1
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +8 -1
- package/lib/types/views/background/worksheet-background-image.extension.d.ts +1 -0
- package/lib/umd/index.js +2 -2
- package/package.json +16 -16
package/lib/cjs/index.js
CHANGED
|
@@ -423,7 +423,7 @@ function readUint32Be(bytes, offset) {
|
|
|
423
423
|
return ((bytes[offset] ?? 0) << 24 >>> 0 | (bytes[offset + 1] ?? 0) << 16 | (bytes[offset + 2] ?? 0) << 8 | (bytes[offset + 3] ?? 0)) >>> 0;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
// \0@oxc-project+runtime@0.
|
|
426
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
427
427
|
function _typeof(o) {
|
|
428
428
|
"@babel/helpers - typeof";
|
|
429
429
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -433,25 +433,25 @@ function _typeof(o) {
|
|
|
433
433
|
}, _typeof(o);
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
// \0@oxc-project+runtime@0.
|
|
437
|
-
function toPrimitive(t,
|
|
436
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
437
|
+
function toPrimitive(t, e) {
|
|
438
438
|
if ("object" != _typeof(t) || !t) return t;
|
|
439
|
-
var
|
|
440
|
-
if (void 0 !==
|
|
441
|
-
var i =
|
|
439
|
+
var r;
|
|
440
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
441
|
+
var i = r.call(t, e || "default");
|
|
442
442
|
if ("object" != _typeof(i)) return i;
|
|
443
443
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
444
444
|
}
|
|
445
|
-
return ("string" ===
|
|
445
|
+
return ("string" === e ? String : Number)(t);
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
// \0@oxc-project+runtime@0.
|
|
448
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
449
449
|
function toPropertyKey(t) {
|
|
450
450
|
var i = toPrimitive(t, "string");
|
|
451
451
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
-
// \0@oxc-project+runtime@0.
|
|
454
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
455
455
|
function _defineProperty(e, r, t) {
|
|
456
456
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
457
457
|
value: t,
|
|
@@ -461,14 +461,14 @@ function _defineProperty(e, r, t) {
|
|
|
461
461
|
}) : e[r] = t, e;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
-
// \0@oxc-project+runtime@0.
|
|
464
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
465
465
|
function __decorateParam(paramIndex, decorator) {
|
|
466
466
|
return function(target, key) {
|
|
467
467
|
decorator(target, key, paramIndex);
|
|
468
468
|
};
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
// \0@oxc-project+runtime@0.
|
|
471
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
472
472
|
function __decorate(decorators, target, key, desc) {
|
|
473
473
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
474
474
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -519,12 +519,11 @@ function getDrawingSizeByCell(accessor, location, originImageWidth, originImageH
|
|
|
519
519
|
};
|
|
520
520
|
}
|
|
521
521
|
let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _univerjs_core.Disposable {
|
|
522
|
-
constructor(_context, _commandService, _sheetInterceptorService,
|
|
522
|
+
constructor(_context, _commandService, _sheetInterceptorService, _imageIoService, _fileOpenerService, _sheetDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, selectionManagerService, _sheetSkeletonService, _injector, _urlImageService) {
|
|
523
523
|
super();
|
|
524
524
|
this._context = _context;
|
|
525
525
|
this._commandService = _commandService;
|
|
526
526
|
this._sheetInterceptorService = _sheetInterceptorService;
|
|
527
|
-
this._selectionRenderService = _selectionRenderService;
|
|
528
527
|
this._imageIoService = _imageIoService;
|
|
529
528
|
this._fileOpenerService = _fileOpenerService;
|
|
530
529
|
this._sheetDrawingService = _sheetDrawingService;
|
|
@@ -543,6 +542,8 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
543
542
|
this._focusDrawingListener();
|
|
544
543
|
}
|
|
545
544
|
async insertFloatImage() {
|
|
545
|
+
const target = this._captureImageTarget();
|
|
546
|
+
if (!target) return false;
|
|
546
547
|
const files = await this._fileOpenerService.openFile({
|
|
547
548
|
multiple: true,
|
|
548
549
|
accept: _univerjs_drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
|
|
@@ -555,18 +556,19 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
555
556
|
});
|
|
556
557
|
return false;
|
|
557
558
|
} else if (fileLength === 0) return false;
|
|
558
|
-
files.
|
|
559
|
-
|
|
559
|
+
return (await Promise.all(files.map((file) => this._insertFloatImage(file, target).catch((error) => {
|
|
560
|
+
this._injector.get(_univerjs_core.ILogService).error(error);
|
|
561
|
+
return false;
|
|
562
|
+
})))).every(Boolean);
|
|
560
563
|
}
|
|
561
564
|
async insertCellImage() {
|
|
565
|
+
const target = this._captureCellImageTarget();
|
|
566
|
+
if (!target) return false;
|
|
562
567
|
const file = (await this._fileOpenerService.openFile({
|
|
563
568
|
multiple: false,
|
|
564
569
|
accept: _univerjs_drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
|
|
565
570
|
}))[0];
|
|
566
|
-
if (file)
|
|
567
|
-
await this._insertCellImage(file);
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
571
|
+
if (file) return this._insertCellImage(file, void 0, target);
|
|
570
572
|
return false;
|
|
571
573
|
}
|
|
572
574
|
async setWorksheetBackgroundImage(files) {
|
|
@@ -611,6 +613,15 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
611
613
|
return this._insertCellImage(file, location);
|
|
612
614
|
}
|
|
613
615
|
async insertFloatImageByFile(file) {
|
|
616
|
+
const target = this._captureImageTarget();
|
|
617
|
+
if (!target) return false;
|
|
618
|
+
return this._insertFloatImage(file, target).catch((error) => {
|
|
619
|
+
this._injector.get(_univerjs_core.ILogService).error(error);
|
|
620
|
+
return false;
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
async _insertFloatImage(file, target) {
|
|
624
|
+
if (!this._isImageTargetValid(target)) return false;
|
|
614
625
|
let imageParam;
|
|
615
626
|
try {
|
|
616
627
|
imageParam = await this._imageIoService.saveImage(file);
|
|
@@ -629,11 +640,14 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
629
640
|
content: this._localeService.t("sheets-drawing-ui.update-status.invalidImage")
|
|
630
641
|
});
|
|
631
642
|
}
|
|
632
|
-
if (imageParam == null) return;
|
|
633
|
-
const { unitId, subUnitId } =
|
|
643
|
+
if (imageParam == null || !this._isImageTargetValid(target)) return false;
|
|
644
|
+
const { unitId, subUnitId } = target;
|
|
634
645
|
const { imageId, imageSourceType, source, base64Cache } = imageParam;
|
|
635
|
-
const
|
|
636
|
-
|
|
646
|
+
const imageSize = await (0, _univerjs_drawing.getImageSize)(base64Cache || "").catch(() => null);
|
|
647
|
+
if (!imageSize) return false;
|
|
648
|
+
const { width, height, image } = imageSize;
|
|
649
|
+
if (!this._isImageTargetValid(target) || !Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return false;
|
|
650
|
+
const { sceneWidth, sceneHeight } = target;
|
|
637
651
|
this._imageIoService.addImageSourceCache(source, imageSourceType, image);
|
|
638
652
|
let scale = 1;
|
|
639
653
|
if (width > _univerjs_drawing.DRAWING_IMAGE_WIDTH_LIMIT || height > _univerjs_drawing.DRAWING_IMAGE_HEIGHT_LIMIT) {
|
|
@@ -641,13 +655,51 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
641
655
|
const scaleHeight = _univerjs_drawing.DRAWING_IMAGE_HEIGHT_LIMIT / height;
|
|
642
656
|
scale = Math.min(scaleWidth, scaleHeight);
|
|
643
657
|
}
|
|
658
|
+
if (target.worksheet.getConfig().type === _univerjs_core.SheetTypes.CHART) {
|
|
659
|
+
const bounds = this._getChartImageBounds(target.render);
|
|
660
|
+
if (!bounds) return false;
|
|
661
|
+
const marker = {
|
|
662
|
+
row: 0,
|
|
663
|
+
column: 0,
|
|
664
|
+
rowOffset: 0,
|
|
665
|
+
columnOffset: 0
|
|
666
|
+
};
|
|
667
|
+
const placed = (0, _univerjs_sheets_drawing.transformDrawingsToChartSheet)([{
|
|
668
|
+
unitId,
|
|
669
|
+
subUnitId,
|
|
670
|
+
drawingId: imageId,
|
|
671
|
+
drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
672
|
+
imageSourceType,
|
|
673
|
+
source,
|
|
674
|
+
transform: {
|
|
675
|
+
left: 0,
|
|
676
|
+
top: 0,
|
|
677
|
+
width: width * scale,
|
|
678
|
+
height: height * scale
|
|
679
|
+
},
|
|
680
|
+
sheetTransform: {
|
|
681
|
+
from: marker,
|
|
682
|
+
to: marker
|
|
683
|
+
},
|
|
684
|
+
axisAlignSheetTransform: {
|
|
685
|
+
from: marker,
|
|
686
|
+
to: marker
|
|
687
|
+
}
|
|
688
|
+
}], bounds, target.worksheet.getConfig().rightToLeft === _univerjs_core.BooleanNumber.TRUE);
|
|
689
|
+
if (!(placed === null || placed === void 0 ? void 0 : placed.length)) return false;
|
|
690
|
+
const [drawing] = placed;
|
|
691
|
+
return this._commandService.executeCommand(_univerjs_sheets_drawing.InsertSheetDrawingCommand.id, {
|
|
692
|
+
unitId,
|
|
693
|
+
drawings: [drawing]
|
|
694
|
+
});
|
|
695
|
+
}
|
|
644
696
|
const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
|
|
645
|
-
if (!sheetSkeletonParam) return;
|
|
697
|
+
if (!sheetSkeletonParam) return false;
|
|
646
698
|
const { skeleton } = sheetSkeletonParam;
|
|
647
|
-
const sheetTransform = this._getImagePosition(width * scale, height * scale, sceneWidth, sceneHeight, skeleton);
|
|
648
|
-
if (!sheetTransform) return;
|
|
699
|
+
const sheetTransform = this._getImagePosition(width * scale, height * scale, sceneWidth, sceneHeight, skeleton, target.range);
|
|
700
|
+
if (!sheetTransform) return false;
|
|
649
701
|
const newTransform = (0, _univerjs_sheets_drawing.drawingPositionToTransform)(sheetTransform, sheetSkeletonParam);
|
|
650
|
-
if (!newTransform) return;
|
|
702
|
+
if (!newTransform) return false;
|
|
651
703
|
const sheetDrawingParam = {
|
|
652
704
|
unitId,
|
|
653
705
|
subUnitId,
|
|
@@ -664,7 +716,9 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
664
716
|
drawings: [sheetDrawingParam]
|
|
665
717
|
});
|
|
666
718
|
}
|
|
667
|
-
async _insertCellImage(file, location) {
|
|
719
|
+
async _insertCellImage(file, location, capturedTarget) {
|
|
720
|
+
const target = capturedTarget ?? this._captureCellImageTarget(location);
|
|
721
|
+
if (!target || !this._isImageTargetValid(target)) return false;
|
|
668
722
|
let imageParam;
|
|
669
723
|
try {
|
|
670
724
|
imageParam = await this._imageIoService.saveImage(file);
|
|
@@ -687,21 +741,11 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
687
741
|
const { imageId, imageSourceType, source, base64Cache } = imageParam;
|
|
688
742
|
const { width, height, image } = await (0, _univerjs_drawing.getImageSize)(base64Cache || "");
|
|
689
743
|
this._imageIoService.addImageSourceCache(source, imageSourceType, image);
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
let col = selection.primary.actualColumn;
|
|
694
|
-
if (selection.primary.isMerged) {
|
|
695
|
-
row = selection.primary.startRow;
|
|
696
|
-
col = selection.primary.startColumn;
|
|
697
|
-
}
|
|
744
|
+
if (!this._isImageTargetValid(target)) return false;
|
|
745
|
+
const cellLocation = target.location;
|
|
746
|
+
const { row, col } = cellLocation;
|
|
698
747
|
const docDataModel = (0, _univerjs_core.createDocumentModelWithStyle)("", {});
|
|
699
|
-
const imageSize = getDrawingSizeByCell(this._injector,
|
|
700
|
-
unitId: this._context.unitId,
|
|
701
|
-
subUnitId: this._context.unit.getActiveSheet().getSheetId(),
|
|
702
|
-
row,
|
|
703
|
-
col
|
|
704
|
-
}, width, height, 0);
|
|
748
|
+
const imageSize = getDrawingSizeByCell(this._injector, cellLocation, width, height, 0);
|
|
705
749
|
if (!imageSize) return false;
|
|
706
750
|
const docTransform = (0, _univerjs_docs.buildDocTransform)(imageSize.width, imageSize.height);
|
|
707
751
|
const docDrawingParam = {
|
|
@@ -735,17 +779,25 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
735
779
|
if (jsonXActions) {
|
|
736
780
|
docDataModel.apply(jsonXActions);
|
|
737
781
|
return this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
|
|
738
|
-
value: { [
|
|
782
|
+
value: { [row]: { [col]: {
|
|
739
783
|
p: docDataModel.getSnapshot(),
|
|
740
784
|
t: 1
|
|
741
785
|
} } },
|
|
742
|
-
unitId:
|
|
743
|
-
subUnitId:
|
|
786
|
+
unitId: target.unitId,
|
|
787
|
+
subUnitId: target.subUnitId,
|
|
788
|
+
range: {
|
|
789
|
+
startRow: row,
|
|
790
|
+
endRow: row,
|
|
791
|
+
startColumn: col,
|
|
792
|
+
endColumn: col
|
|
793
|
+
}
|
|
744
794
|
});
|
|
745
795
|
}
|
|
746
796
|
return false;
|
|
747
797
|
}
|
|
748
798
|
async insertCellImageByUrl(url, location) {
|
|
799
|
+
const target = this._captureCellImageTarget(location);
|
|
800
|
+
if (!target) return false;
|
|
749
801
|
let src = url;
|
|
750
802
|
try {
|
|
751
803
|
src = await this._urlImageService.getImage(url);
|
|
@@ -754,15 +806,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
754
806
|
}
|
|
755
807
|
const { width, height, image } = await (0, _univerjs_drawing.getImageSize)(src || "");
|
|
756
808
|
this._imageIoService.addImageSourceCache(url, _univerjs_core.ImageSourceType.URL, image);
|
|
757
|
-
|
|
758
|
-
|
|
809
|
+
if (!this._isImageTargetValid(target)) return false;
|
|
810
|
+
const cellLocation = target.location;
|
|
759
811
|
const docDataModel = (0, _univerjs_core.createDocumentModelWithStyle)("", {});
|
|
760
|
-
const imageSize = getDrawingSizeByCell(this._injector,
|
|
761
|
-
unitId: this._context.unitId,
|
|
762
|
-
subUnitId: this._context.unit.getActiveSheet().getSheetId(),
|
|
763
|
-
row: selection.primary.actualRow,
|
|
764
|
-
col: selection.primary.actualColumn
|
|
765
|
-
}, width, height, 0);
|
|
812
|
+
const imageSize = getDrawingSizeByCell(this._injector, cellLocation, width, height, 0);
|
|
766
813
|
if (!imageSize) return false;
|
|
767
814
|
const docTransform = (0, _univerjs_docs.buildDocTransform)(imageSize.width, imageSize.height);
|
|
768
815
|
const docDrawingParam = {
|
|
@@ -796,16 +843,87 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
796
843
|
if (jsonXActions) {
|
|
797
844
|
docDataModel.apply(jsonXActions);
|
|
798
845
|
return this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
|
|
799
|
-
value: { [
|
|
846
|
+
value: { [cellLocation.row]: { [cellLocation.col]: {
|
|
800
847
|
p: docDataModel.getSnapshot(),
|
|
801
848
|
t: 1
|
|
802
849
|
} } },
|
|
803
|
-
unitId:
|
|
804
|
-
subUnitId:
|
|
850
|
+
unitId: target.unitId,
|
|
851
|
+
subUnitId: target.subUnitId,
|
|
852
|
+
range: {
|
|
853
|
+
startRow: cellLocation.row,
|
|
854
|
+
endRow: cellLocation.row,
|
|
855
|
+
startColumn: cellLocation.col,
|
|
856
|
+
endColumn: cellLocation.col
|
|
857
|
+
}
|
|
805
858
|
});
|
|
806
859
|
}
|
|
807
860
|
return false;
|
|
808
861
|
}
|
|
862
|
+
_captureImageTarget(location) {
|
|
863
|
+
if (this._disposed) return null;
|
|
864
|
+
const instances = this._injector.get(_univerjs_core.IUniverInstanceService);
|
|
865
|
+
const host = (0, _univerjs_sheets.getSheetCommandTarget)(instances, location ?? { unitId: this._context.unitId });
|
|
866
|
+
const render = host && this._injector.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(host.unitId);
|
|
867
|
+
const sheetType = (host === null || host === void 0 ? void 0 : host.worksheet.getConfig().type) ?? _univerjs_core.SheetTypes.GRID;
|
|
868
|
+
if (!host || !render || sheetType !== _univerjs_core.SheetTypes.GRID && sheetType !== _univerjs_core.SheetTypes.CHART) return null;
|
|
869
|
+
const frame = render.components.get(_univerjs_sheets_ui.SHEET_VIEW_KEY.CHART_PAGE);
|
|
870
|
+
const pageFrame = frame instanceof _univerjs_engine_render.Rect ? frame : void 0;
|
|
871
|
+
const selections = this._workbookSelections.getCurrentSelections();
|
|
872
|
+
const range = (selections === null || selections === void 0 ? void 0 : selections.length) ? { ...selections[selections.length - 1].range } : {
|
|
873
|
+
startRow: 0,
|
|
874
|
+
endRow: 0,
|
|
875
|
+
startColumn: 0,
|
|
876
|
+
endColumn: 0
|
|
877
|
+
};
|
|
878
|
+
const target = {
|
|
879
|
+
...host,
|
|
880
|
+
render,
|
|
881
|
+
location,
|
|
882
|
+
pageFrame,
|
|
883
|
+
range,
|
|
884
|
+
sceneWidth: render.scene.width,
|
|
885
|
+
sceneHeight: render.scene.height
|
|
886
|
+
};
|
|
887
|
+
return this._isImageTargetValid(target) ? target : null;
|
|
888
|
+
}
|
|
889
|
+
_captureCellImageTarget(location) {
|
|
890
|
+
const target = this._captureImageTarget(location);
|
|
891
|
+
if (!target || (target.worksheet.getConfig().type ?? _univerjs_core.SheetTypes.GRID) !== _univerjs_core.SheetTypes.GRID) return null;
|
|
892
|
+
if (!location) {
|
|
893
|
+
const selection = this._workbookSelections.getCurrentLastSelection();
|
|
894
|
+
if (!selection) return null;
|
|
895
|
+
const { primary } = selection;
|
|
896
|
+
target.location = {
|
|
897
|
+
unitId: target.unitId,
|
|
898
|
+
subUnitId: target.subUnitId,
|
|
899
|
+
row: primary.isMerged ? primary.startRow : primary.actualRow,
|
|
900
|
+
col: primary.isMerged ? primary.startColumn : primary.actualColumn
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
return target;
|
|
904
|
+
}
|
|
905
|
+
_isImageTargetValid(target) {
|
|
906
|
+
if (this._disposed) return false;
|
|
907
|
+
const instances = this._injector.get(_univerjs_core.IUniverInstanceService);
|
|
908
|
+
const { workbook, worksheet, unitId, subUnitId, render } = target;
|
|
909
|
+
if (instances.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) !== workbook || workbook.getSheetBySheetId(subUnitId) !== worksheet || render.isDisposed() || this._injector.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId) !== render) return false;
|
|
910
|
+
return worksheet.getConfig().type !== _univerjs_core.SheetTypes.CHART || target.pageFrame === render.components.get(_univerjs_sheets_ui.SHEET_VIEW_KEY.CHART_PAGE) && Boolean(this._getChartImageBounds(render));
|
|
911
|
+
}
|
|
912
|
+
_getChartImageBounds(render) {
|
|
913
|
+
const frame = render.components.get(_univerjs_sheets_ui.SHEET_VIEW_KEY.CHART_PAGE);
|
|
914
|
+
if (!frame || ![
|
|
915
|
+
frame.left,
|
|
916
|
+
frame.top,
|
|
917
|
+
frame.width,
|
|
918
|
+
frame.height
|
|
919
|
+
].every(Number.isFinite) || frame.width <= 0 || frame.height <= 0) return null;
|
|
920
|
+
return {
|
|
921
|
+
left: frame.left,
|
|
922
|
+
top: frame.top,
|
|
923
|
+
width: frame.width,
|
|
924
|
+
height: frame.height
|
|
925
|
+
};
|
|
926
|
+
}
|
|
809
927
|
_getUnitInfo() {
|
|
810
928
|
const workbook = this._context.unit;
|
|
811
929
|
const worksheet = workbook.getActiveSheet();
|
|
@@ -814,15 +932,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
814
932
|
subUnitId: worksheet.getSheetId()
|
|
815
933
|
};
|
|
816
934
|
}
|
|
817
|
-
_getImagePosition(imageWidth, imageHeight, sceneWidth, sceneHeight, skeleton) {
|
|
818
|
-
const selections = this._workbookSelections.getCurrentSelections();
|
|
819
|
-
let range = {
|
|
820
|
-
startRow: 0,
|
|
821
|
-
endRow: 0,
|
|
822
|
-
startColumn: 0,
|
|
823
|
-
endColumn: 0
|
|
824
|
-
};
|
|
825
|
-
if (selections && selections.length > 0) range = selections[selections.length - 1].range;
|
|
935
|
+
_getImagePosition(imageWidth, imageHeight, sceneWidth, sceneHeight, skeleton, range) {
|
|
826
936
|
const rangeWithCoord = (0, _univerjs_sheets.attachRangeWithCoord)(skeleton, range);
|
|
827
937
|
if (rangeWithCoord == null) return;
|
|
828
938
|
let { startColumn, startRow, startX, startY } = rangeWithCoord;
|
|
@@ -844,7 +954,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
844
954
|
isChangeStart = true;
|
|
845
955
|
}
|
|
846
956
|
if (isChangeStart) {
|
|
847
|
-
const newCoord =
|
|
957
|
+
const newCoord = skeleton.getCellWithCoordByOffset(startX, startY, 1, 1, {
|
|
958
|
+
x: 0,
|
|
959
|
+
y: 0
|
|
960
|
+
});
|
|
848
961
|
if (newCoord == null) return;
|
|
849
962
|
startX = newCoord.startX;
|
|
850
963
|
startY = newCoord.startY;
|
|
@@ -857,7 +970,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
857
970
|
row: startRow,
|
|
858
971
|
rowOffset: 0
|
|
859
972
|
};
|
|
860
|
-
const endSelectionCell =
|
|
973
|
+
const endSelectionCell = skeleton.getCellWithCoordByOffset(startX + imageWidth, startY + imageHeight, 1, 1, {
|
|
974
|
+
x: 0,
|
|
975
|
+
y: 0
|
|
976
|
+
});
|
|
861
977
|
if (endSelectionCell == null) return;
|
|
862
978
|
return {
|
|
863
979
|
from,
|
|
@@ -887,14 +1003,27 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
887
1003
|
params.forEach((param) => {
|
|
888
1004
|
const { unitId, subUnitId, drawingId, transform } = param;
|
|
889
1005
|
const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
|
|
890
|
-
if (!transform
|
|
891
|
-
const { skeleton } = sheetSkeletonParam;
|
|
1006
|
+
if (!transform) return;
|
|
892
1007
|
const sheetDrawing = this._sheetDrawingService.getDrawingByParam({
|
|
893
1008
|
unitId,
|
|
894
1009
|
subUnitId,
|
|
895
1010
|
drawingId
|
|
896
1011
|
});
|
|
897
1012
|
if (sheetDrawing == null || sheetDrawing.unitId !== this._context.unitId) return;
|
|
1013
|
+
if (sheetDrawing.anchorType === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) {
|
|
1014
|
+
const next = {
|
|
1015
|
+
...sheetDrawing,
|
|
1016
|
+
...param,
|
|
1017
|
+
transform: {
|
|
1018
|
+
...sheetDrawing.transform,
|
|
1019
|
+
...transform
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
drawings.push((0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(next, (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(next)));
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (!sheetSkeletonParam) return;
|
|
1026
|
+
const { skeleton } = sheetSkeletonParam;
|
|
898
1027
|
const sheetTransform = (0, _univerjs_sheets_drawing.transformToDrawingPosition)({
|
|
899
1028
|
...sheetDrawing.transform,
|
|
900
1029
|
...transform
|
|
@@ -1019,18 +1148,17 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
|
|
|
1019
1148
|
SheetDrawingUpdateController = __decorate([
|
|
1020
1149
|
__decorateParam(1, _univerjs_core.ICommandService),
|
|
1021
1150
|
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
1022
|
-
__decorateParam(3,
|
|
1023
|
-
__decorateParam(4,
|
|
1024
|
-
__decorateParam(5,
|
|
1025
|
-
__decorateParam(6,
|
|
1026
|
-
__decorateParam(7,
|
|
1027
|
-
__decorateParam(8,
|
|
1028
|
-
__decorateParam(9,
|
|
1029
|
-
__decorateParam(10, (0, _univerjs_core.Inject)(
|
|
1030
|
-
__decorateParam(11, (0, _univerjs_core.Inject)(_univerjs_sheets.
|
|
1031
|
-
__decorateParam(12, (0, _univerjs_core.Inject)(
|
|
1032
|
-
__decorateParam(13,
|
|
1033
|
-
__decorateParam(14, _univerjs_core.IURLImageService)
|
|
1151
|
+
__decorateParam(3, _univerjs_core.IImageIoService),
|
|
1152
|
+
__decorateParam(4, _univerjs_ui.ILocalFileService),
|
|
1153
|
+
__decorateParam(5, _univerjs_sheets_drawing.ISheetDrawingService),
|
|
1154
|
+
__decorateParam(6, _univerjs_drawing.IDrawingManagerService),
|
|
1155
|
+
__decorateParam(7, _univerjs_core.IContextService),
|
|
1156
|
+
__decorateParam(8, _univerjs_ui.IMessageService),
|
|
1157
|
+
__decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
1158
|
+
__decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
|
|
1159
|
+
__decorateParam(11, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetSkeletonService)),
|
|
1160
|
+
__decorateParam(12, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1161
|
+
__decorateParam(13, _univerjs_core.IURLImageService)
|
|
1034
1162
|
], SheetDrawingUpdateController);
|
|
1035
1163
|
|
|
1036
1164
|
// src/commands/commands/insert-image.command.ts
|
|
@@ -1074,27 +1202,60 @@ const MoveDrawingsCommand = {
|
|
|
1074
1202
|
const drawings = drawingManagerService.getFocusDrawings();
|
|
1075
1203
|
if (drawings.length === 0) return false;
|
|
1076
1204
|
const unitId = drawings[0].unitId;
|
|
1077
|
-
const
|
|
1078
|
-
const
|
|
1079
|
-
const
|
|
1080
|
-
if (!transform
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1205
|
+
const movableDrawings = drawings.flatMap((drawing) => {
|
|
1206
|
+
const sheetDrawing = drawing;
|
|
1207
|
+
const { transform, anchorType = _univerjs_sheets_drawing.SheetDrawingAnchorType.Position } = sheetDrawing;
|
|
1208
|
+
if (!transform) return [];
|
|
1209
|
+
const skeleton = sheetSkeletonService.getSkeleton(drawing.unitId, drawing.subUnitId);
|
|
1210
|
+
if (anchorType !== _univerjs_sheets_drawing.SheetDrawingAnchorType.None && !skeleton) return [];
|
|
1211
|
+
return [{
|
|
1212
|
+
drawing: sheetDrawing,
|
|
1213
|
+
skeleton,
|
|
1214
|
+
anchorType
|
|
1215
|
+
}];
|
|
1216
|
+
});
|
|
1217
|
+
if (movableDrawings.length === 0) return false;
|
|
1218
|
+
let moveX = direction === _univerjs_core.Direction.LEFT ? -1 : direction === _univerjs_core.Direction.RIGHT ? 1 : 0;
|
|
1219
|
+
let moveY = direction === _univerjs_core.Direction.UP ? -1 : direction === _univerjs_core.Direction.DOWN ? 1 : 0;
|
|
1220
|
+
let minX = -Infinity;
|
|
1221
|
+
let minY = -Infinity;
|
|
1222
|
+
let maxX = Infinity;
|
|
1223
|
+
let maxY = Infinity;
|
|
1224
|
+
for (const { drawing, skeleton } of movableDrawings) {
|
|
1225
|
+
if (!skeleton) continue;
|
|
1226
|
+
const { left = 0, top = 0, width = 0, height = 0 } = drawing.transform;
|
|
1227
|
+
const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop, columnTotalWidth, rowTotalHeight } = skeleton;
|
|
1228
|
+
minX = Math.max(minX, rowHeaderWidthAndMarginLeft - left);
|
|
1229
|
+
minY = Math.max(minY, columnHeaderHeightAndMarginTop - top);
|
|
1230
|
+
maxX = Math.min(maxX, rowHeaderWidthAndMarginLeft + columnTotalWidth - left - width);
|
|
1231
|
+
maxY = Math.min(maxY, columnHeaderHeightAndMarginTop + rowTotalHeight - top - height);
|
|
1232
|
+
}
|
|
1233
|
+
moveX = Math.max(minX, Math.min(moveX, maxX));
|
|
1234
|
+
moveY = Math.max(minY, Math.min(moveY, maxY));
|
|
1235
|
+
if (moveX === 0 && moveY === 0) return false;
|
|
1236
|
+
const newDrawings = movableDrawings.flatMap(({ drawing, skeleton, anchorType }) => {
|
|
1237
|
+
const { left = 0, top = 0, width = 0, height = 0 } = drawing.transform;
|
|
1238
|
+
const bounds = {
|
|
1239
|
+
left: left + moveX,
|
|
1240
|
+
top: top + moveY,
|
|
1241
|
+
width,
|
|
1242
|
+
height
|
|
1092
1243
|
};
|
|
1093
|
-
|
|
1244
|
+
if (anchorType === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) return [(0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(drawing, {
|
|
1245
|
+
kind: anchorType,
|
|
1246
|
+
bounds
|
|
1247
|
+
})];
|
|
1248
|
+
if (!skeleton) return [];
|
|
1249
|
+
return [(0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(drawing, {
|
|
1250
|
+
kind: anchorType,
|
|
1251
|
+
bounds
|
|
1252
|
+
}, skeleton)];
|
|
1253
|
+
});
|
|
1254
|
+
if (newDrawings.length === 0) return false;
|
|
1094
1255
|
if (undoRedoGroupService.runTimed(unitId, `sheet-drawing:nudge:${drawings[0].subUnitId}:${drawings.map((drawing) => drawing.drawingId).sort().join(",")}`, () => commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
|
|
1095
1256
|
unitId,
|
|
1096
1257
|
drawings: newDrawings
|
|
1097
|
-
}))) {
|
|
1258
|
+
}), "append")) {
|
|
1098
1259
|
commandService.syncExecuteCommand(_univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id, [unitId]);
|
|
1099
1260
|
return true;
|
|
1100
1261
|
}
|
|
@@ -1866,9 +2027,12 @@ function applyFloatDomTransformerConfig(rect, floatDomParam) {
|
|
|
1866
2027
|
};
|
|
1867
2028
|
}
|
|
1868
2029
|
function applySheetChartTransformerConfig(rect) {
|
|
2030
|
+
var _rect$transformerConf, _rect$transformerConf2;
|
|
1869
2031
|
rect.transformerConfig = {
|
|
1870
2032
|
...rect.transformerConfig,
|
|
1871
|
-
...SHEET_CHART_TRANSFORMER_CONFIG
|
|
2033
|
+
...SHEET_CHART_TRANSFORMER_CONFIG,
|
|
2034
|
+
moveEnabled: ((_rect$transformerConf = rect.transformerConfig) === null || _rect$transformerConf === void 0 ? void 0 : _rect$transformerConf.moveEnabled) ?? SHEET_CHART_TRANSFORMER_CONFIG.moveEnabled,
|
|
2035
|
+
resizeEnabled: ((_rect$transformerConf2 = rect.transformerConfig) === null || _rect$transformerConf2 === void 0 ? void 0 : _rect$transformerConf2.resizeEnabled) ?? SHEET_CHART_TRANSFORMER_CONFIG.resizeEnabled
|
|
1872
2036
|
};
|
|
1873
2037
|
}
|
|
1874
2038
|
function isStage2RuntimeEmbedFloatDom(floatDomParam) {
|
|
@@ -1997,8 +2161,8 @@ function transformBound2DOMBound(posOfFloatObject, scene, skeleton, worksheet, f
|
|
|
1997
2161
|
const { boundsOfViewArea: specBoundsOfViewArea, scrollDirectionResponse } = floatDomInfo || {};
|
|
1998
2162
|
const { rowHeaderWidth, columnHeaderHeight } = skeleton;
|
|
1999
2163
|
const boundsOfViewArea = {
|
|
2000
|
-
top: skipBoundsOfViewArea ? 0 : columnHeaderHeight,
|
|
2001
|
-
left: skipBoundsOfViewArea ? 0 : rowHeaderWidth
|
|
2164
|
+
top: skipBoundsOfViewArea ? 0 : columnHeaderHeight * scaleY,
|
|
2165
|
+
left: skipBoundsOfViewArea ? 0 : rowHeaderWidth * scaleX
|
|
2002
2166
|
};
|
|
2003
2167
|
if (specBoundsOfViewArea) {
|
|
2004
2168
|
if (_univerjs_core.Tools.isDefine(boundsOfViewArea.top)) boundsOfViewArea.top = specBoundsOfViewArea.top;
|
|
@@ -2096,6 +2260,10 @@ const calcSheetFloatDomPosition = (floatObject, scene, skeleton, worksheet, floa
|
|
|
2096
2260
|
};
|
|
2097
2261
|
};
|
|
2098
2262
|
let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = class SheetCanvasFloatDomManagerService extends _univerjs_core.Disposable {
|
|
2263
|
+
registerMoveTransformConstraint(constraint) {
|
|
2264
|
+
this._moveTransformConstraints.add(constraint);
|
|
2265
|
+
return (0, _univerjs_core.toDisposable)(() => this._moveTransformConstraints.delete(constraint));
|
|
2266
|
+
}
|
|
2099
2267
|
constructor(_renderManagerService, _univerInstanceService, _commandService, _drawingManagerService, _canvasFloatDomService, _sheetDrawingService, _lifecycleService, _canvasFloatDomPreviewService) {
|
|
2100
2268
|
super();
|
|
2101
2269
|
this._renderManagerService = _renderManagerService;
|
|
@@ -2113,12 +2281,29 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2113
2281
|
_defineProperty(this, "add$", this._add$.asObservable());
|
|
2114
2282
|
_defineProperty(this, "_remove$", new rxjs.Subject());
|
|
2115
2283
|
_defineProperty(this, "remove$", this._remove$.asObservable());
|
|
2284
|
+
_defineProperty(this, "_moveTransformConstraints", /* @__PURE__ */ new Set());
|
|
2285
|
+
_defineProperty(this, "_floatDomMoveDisposables", /* @__PURE__ */ new Map());
|
|
2116
2286
|
_defineProperty(this, "_renderObjectFactories", /* @__PURE__ */ new Map());
|
|
2117
2287
|
this._drawingAddListener();
|
|
2118
2288
|
this._featureUpdateListener();
|
|
2119
2289
|
this._deleteListener();
|
|
2120
2290
|
this._bindScrollEvent();
|
|
2121
2291
|
this._bindEmbedFloatDragHandleEvent();
|
|
2292
|
+
this.disposeWithMe(this._renderManagerService.disposed$.subscribe((unitId) => {
|
|
2293
|
+
for (const info of Array.from(this._domLayerInfoMap.values())) if (info.unitId === unitId) this._removeDom(info.id);
|
|
2294
|
+
}));
|
|
2295
|
+
this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
2296
|
+
for (const info of Array.from(this._domLayerInfoMap.values())) if (info.unitId === unit.getUnitId()) this._removeDom(info.id);
|
|
2297
|
+
}));
|
|
2298
|
+
}
|
|
2299
|
+
dispose() {
|
|
2300
|
+
this._moveTransformConstraints.clear();
|
|
2301
|
+
for (const id of Array.from(this._domLayerInfoMap.keys())) this._removeDom(id);
|
|
2302
|
+
this._renderObjectFactories.clear();
|
|
2303
|
+
this._transformChange$.complete();
|
|
2304
|
+
this._add$.complete();
|
|
2305
|
+
this._remove$.complete();
|
|
2306
|
+
super.dispose();
|
|
2122
2307
|
}
|
|
2123
2308
|
/**
|
|
2124
2309
|
* Register a factory that creates the canvas-side render object for a sheet
|
|
@@ -2143,14 +2328,26 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2143
2328
|
const factory = factories === null || factories === void 0 ? void 0 : factories[factories.length - 1];
|
|
2144
2329
|
return (factory === null || factory === void 0 ? void 0 : factory(context)) ?? new _univerjs_engine_render.Rect(context.key, context.config);
|
|
2145
2330
|
}
|
|
2331
|
+
_forwardWheelToCanvas(canvas, event) {
|
|
2332
|
+
if (!canvas.dispatchEvent(new WheelEvent(event.type, event))) event.preventDefault();
|
|
2333
|
+
}
|
|
2146
2334
|
_bindScrollEvent() {
|
|
2147
|
-
this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((s) => s === _univerjs_core.LifecycleStages.Rendered), (0, rxjs.take)(1)).subscribe(() => {
|
|
2335
|
+
this.disposeWithMe(this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((s) => s === _univerjs_core.LifecycleStages.Rendered), (0, rxjs.take)(1)).subscribe(() => {
|
|
2148
2336
|
this._scrollUpdateListener();
|
|
2149
|
-
});
|
|
2337
|
+
}));
|
|
2150
2338
|
}
|
|
2151
2339
|
getFloatDomInfo(id) {
|
|
2152
2340
|
return this._domLayerInfoMap.get(id);
|
|
2153
2341
|
}
|
|
2342
|
+
updateFloatDomEventOptions(id, eventOptions) {
|
|
2343
|
+
const info = this._domLayerInfoMap.get(id);
|
|
2344
|
+
if (!(info === null || info === void 0 ? void 0 : info.floatDomConfig)) return;
|
|
2345
|
+
info.floatDomConfig = {
|
|
2346
|
+
...info.floatDomConfig,
|
|
2347
|
+
eventOptions
|
|
2348
|
+
};
|
|
2349
|
+
this._canvasFloatDomService.updateFloatDom(id, { eventOptions });
|
|
2350
|
+
}
|
|
2154
2351
|
getFloatDomsBySubUnitId(unitId, subUnitId) {
|
|
2155
2352
|
return Array.from(this._domLayerInfoMap.values()).filter((info) => info.subUnitId === subUnitId && info.unitId === unitId);
|
|
2156
2353
|
}
|
|
@@ -2167,6 +2364,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2167
2364
|
this.disposeWithMe(() => document.removeEventListener(EMBED_FLOAT_DRAG_HANDLE_POINTER_DOWN_EVENT, listener));
|
|
2168
2365
|
}
|
|
2169
2366
|
_handleEmbedFloatDragHandlePointerDown(event) {
|
|
2367
|
+
var _this$_floatDomMoveDi, _this$_univerInstance2;
|
|
2170
2368
|
const detail = event.detail;
|
|
2171
2369
|
if (!(detail === null || detail === void 0 ? void 0 : detail.hostAnchorId)) return;
|
|
2172
2370
|
const info = this._domLayerInfoMap.get(detail.hostAnchorId);
|
|
@@ -2174,7 +2372,21 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2174
2372
|
const dragState = createFloatDomMoveDragState(info, detail);
|
|
2175
2373
|
const renderObject = this._getSceneAndTransformerByDrawingSearch(info.unitId);
|
|
2176
2374
|
if (!dragState || !renderObject) return;
|
|
2177
|
-
|
|
2375
|
+
(_this$_floatDomMoveDi = this._floatDomMoveDisposables.get(info.id)) === null || _this$_floatDomMoveDi === void 0 || _this$_floatDomMoveDi.dispose();
|
|
2376
|
+
const { scene, transformer, canvas } = renderObject;
|
|
2377
|
+
const isCurrentHost = () => {
|
|
2378
|
+
var _this$_getSceneAndTra, _this$_univerInstance;
|
|
2379
|
+
return this._domLayerInfoMap.get(info.id) === info && ((_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(info.unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.scene) === scene && ((_this$_univerInstance = this._univerInstanceService.getUnit(info.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getActiveSheet().getSheetId()) === info.subUnitId;
|
|
2380
|
+
};
|
|
2381
|
+
const isChartSheet = ((_this$_univerInstance2 = this._univerInstanceService.getUnit(info.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance2 === void 0 || (_this$_univerInstance2 = _this$_univerInstance2.getSheetBySheetId(info.subUnitId)) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getConfig().type) === _univerjs_core.SheetTypes.CHART;
|
|
2382
|
+
const toScenePoint = (point) => {
|
|
2383
|
+
const bounds = canvas.getBoundingClientRect();
|
|
2384
|
+
return scene.getMainViewport().transformVector2SceneCoord(_univerjs_engine_render.Vector2.FromArray([point.clientX - bounds.left, point.clientY - bounds.top]));
|
|
2385
|
+
};
|
|
2386
|
+
const startPoint = isChartSheet ? toScenePoint({
|
|
2387
|
+
clientX: dragState.startClientX,
|
|
2388
|
+
clientY: dragState.startClientY
|
|
2389
|
+
}) : void 0;
|
|
2178
2390
|
if (info.rect.oKey) {
|
|
2179
2391
|
var _scene$getTransformer;
|
|
2180
2392
|
transformer.clearControlByIds([info.rect.oKey]);
|
|
@@ -2182,15 +2394,35 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2182
2394
|
}
|
|
2183
2395
|
const handlePointerMove = (pointerEvent) => {
|
|
2184
2396
|
if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
|
|
2397
|
+
if (!isCurrentHost()) return;
|
|
2185
2398
|
pointerEvent.preventDefault();
|
|
2186
|
-
const
|
|
2187
|
-
|
|
2399
|
+
const point = startPoint && toScenePoint(pointerEvent);
|
|
2400
|
+
const nextTransform = point && startPoint ? {
|
|
2401
|
+
left: dragState.startLeft + point.x - startPoint.x,
|
|
2402
|
+
top: dragState.startTop + point.y - startPoint.y
|
|
2403
|
+
} : resolveFloatDomMoveDragTransform(dragState, pointerEvent, scene);
|
|
2404
|
+
const drawing = this._sheetDrawingService.getDrawingByParam({
|
|
2405
|
+
unitId: info.unitId,
|
|
2406
|
+
subUnitId: info.subUnitId,
|
|
2407
|
+
drawingId: info.id
|
|
2408
|
+
});
|
|
2409
|
+
if ((drawing === null || drawing === void 0 ? void 0 : drawing.anchorType) === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) {
|
|
2410
|
+
const next = {
|
|
2411
|
+
...drawing,
|
|
2412
|
+
transform: {
|
|
2413
|
+
...drawing.transform,
|
|
2414
|
+
...nextTransform
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
let transform = (0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(drawing, (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(next)).transform;
|
|
2418
|
+
for (const constraint of this._moveTransformConstraints) transform = constraint(drawing, transform);
|
|
2419
|
+
info.rect.transformByState(transform);
|
|
2420
|
+
} else info.rect.transformByState(nextTransform);
|
|
2188
2421
|
};
|
|
2189
2422
|
const handlePointerUp = (pointerEvent) => {
|
|
2190
2423
|
if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
window.removeEventListener("pointercancel", handlePointerCancel, true);
|
|
2424
|
+
cleanupDrag();
|
|
2425
|
+
if (!isCurrentHost()) return;
|
|
2194
2426
|
pointerEvent.preventDefault();
|
|
2195
2427
|
if (info.rect.left !== dragState.startLeft || info.rect.top !== dragState.startTop) this._commitFloatDomMove(info);
|
|
2196
2428
|
if (info.runtimeStage === "stage1") {
|
|
@@ -2200,9 +2432,8 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2200
2432
|
};
|
|
2201
2433
|
const handlePointerCancel = (pointerEvent) => {
|
|
2202
2434
|
if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
window.removeEventListener("pointercancel", handlePointerCancel, true);
|
|
2435
|
+
cleanupDrag();
|
|
2436
|
+
if (!isCurrentHost()) return;
|
|
2206
2437
|
info.rect.transformByState({
|
|
2207
2438
|
left: dragState.startLeft,
|
|
2208
2439
|
top: dragState.startTop
|
|
@@ -2212,6 +2443,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2212
2443
|
(_scene$attachTransfor2 = scene.attachTransformerTo) === null || _scene$attachTransfor2 === void 0 || _scene$attachTransfor2.call(scene, info.rect);
|
|
2213
2444
|
}
|
|
2214
2445
|
};
|
|
2446
|
+
const cleanupDrag = () => {
|
|
2447
|
+
this._floatDomMoveDisposables.delete(info.id);
|
|
2448
|
+
window.removeEventListener("pointermove", handlePointerMove, true);
|
|
2449
|
+
window.removeEventListener("pointerup", handlePointerUp, true);
|
|
2450
|
+
window.removeEventListener("pointercancel", handlePointerCancel, true);
|
|
2451
|
+
};
|
|
2452
|
+
this._floatDomMoveDisposables.set(info.id, { dispose: cleanupDrag });
|
|
2215
2453
|
window.addEventListener("pointermove", handlePointerMove, true);
|
|
2216
2454
|
window.addEventListener("pointerup", handlePointerUp, true);
|
|
2217
2455
|
window.addEventListener("pointercancel", handlePointerCancel, true);
|
|
@@ -2224,7 +2462,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2224
2462
|
subUnitId: info.subUnitId,
|
|
2225
2463
|
drawingId: info.id
|
|
2226
2464
|
});
|
|
2227
|
-
if (!
|
|
2465
|
+
if (!(drawing === null || drawing === void 0 ? void 0 : drawing.transform) || this._domLayerInfoMap.get(info.id) !== info) return;
|
|
2228
2466
|
const transform = {
|
|
2229
2467
|
...drawing.transform,
|
|
2230
2468
|
left: info.rect.left,
|
|
@@ -2237,6 +2475,18 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2237
2475
|
skewX: info.rect.skewX,
|
|
2238
2476
|
skewY: info.rect.skewY
|
|
2239
2477
|
};
|
|
2478
|
+
if (drawing.anchorType === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) {
|
|
2479
|
+
const next = {
|
|
2480
|
+
...drawing,
|
|
2481
|
+
transform
|
|
2482
|
+
};
|
|
2483
|
+
this._commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
|
|
2484
|
+
unitId: info.unitId,
|
|
2485
|
+
drawings: [(0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(drawing, (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(next))]
|
|
2486
|
+
});
|
|
2487
|
+
return;
|
|
2488
|
+
}
|
|
2489
|
+
if (!skeletonParam) return;
|
|
2240
2490
|
const sheetTransform = (0, _univerjs_sheets_drawing.transformToDrawingPosition)(transform, skeletonParam.skeleton);
|
|
2241
2491
|
const axisAlignSheetTransform = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(transform, skeletonParam.skeleton);
|
|
2242
2492
|
if (!sheetTransform || !axisAlignSheetTransform) return;
|
|
@@ -2417,7 +2667,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2417
2667
|
const activeSheetId = workbook.getActiveSheet().getSheetId();
|
|
2418
2668
|
if (!floatDomParam || !target) return;
|
|
2419
2669
|
const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId);
|
|
2420
|
-
if (!skeleton) return;
|
|
2670
|
+
if (!skeleton && (target.worksheet.getConfig().type !== _univerjs_core.SheetTypes.CHART || floatDomParam.anchorType !== _univerjs_sheets_drawing.SheetDrawingAnchorType.None)) return;
|
|
2421
2671
|
const { transform, drawingType, data, hidden, groupId } = floatDomParam;
|
|
2422
2672
|
if (!isCanvasFloatDomDrawingType(drawingType)) return;
|
|
2423
2673
|
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
@@ -2465,6 +2715,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2465
2715
|
top,
|
|
2466
2716
|
width,
|
|
2467
2717
|
height,
|
|
2718
|
+
angle,
|
|
2719
|
+
flipX,
|
|
2720
|
+
flipY,
|
|
2721
|
+
skewX,
|
|
2722
|
+
skewY,
|
|
2468
2723
|
zIndex: this._getDrawingZIndex(unitId, subUnitId, drawingId)
|
|
2469
2724
|
};
|
|
2470
2725
|
const isChart = drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART;
|
|
@@ -2506,18 +2761,17 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2506
2761
|
});
|
|
2507
2762
|
previewSubscription && disposableCollection.add(previewSubscription);
|
|
2508
2763
|
}
|
|
2509
|
-
const initPosition =
|
|
2764
|
+
const initPosition = this._calculateFloatDomPosition(rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton);
|
|
2510
2765
|
const position$ = new rxjs.BehaviorSubject(initPosition);
|
|
2511
2766
|
const domId = `${SHEET_FLOAT_DOM_PREFIX}${(0, _univerjs_core.generateRandomId)(6)}`;
|
|
2512
2767
|
const shouldAutoMountRuntime = shouldAutoMountFloatDomRuntime(floatDomParam);
|
|
2513
2768
|
const shouldSyncEmbedRuntimeStage = isEmbedFloatDomData(floatDomParam);
|
|
2514
2769
|
let info;
|
|
2515
2770
|
const handleRuntimeStageEnter = (stage) => {
|
|
2516
|
-
if (info)
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
}
|
|
2771
|
+
if (!info || this._domLayerInfoMap.get(drawingId) !== info) return;
|
|
2772
|
+
info.runtimeStage = stage;
|
|
2773
|
+
info.runtimeMounted = shouldAutoMountRuntime || stage === "stage2";
|
|
2774
|
+
if (shouldUpdateFloatDomLayerOnRuntimeStageChange(floatDomParam)) this._canvasFloatDomService.updateFloatDom(drawingId, { eventPassThrough: shouldPassThroughFloatDomRuntimeEvents(floatDomParam, stage) });
|
|
2521
2775
|
syncFloatDomHostSelectionOnStageEnter(stage, this._getSceneAndTransformerByDrawingSearch(unitId), rect);
|
|
2522
2776
|
};
|
|
2523
2777
|
const floatDomConfig = {
|
|
@@ -2526,6 +2780,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2526
2780
|
domId,
|
|
2527
2781
|
componentKey: floatDomParam.componentKey,
|
|
2528
2782
|
eventPassThrough: shouldPassThroughFloatDomRuntimeEvents(floatDomParam, "inactive"),
|
|
2783
|
+
preventBrowserZoom: true,
|
|
2529
2784
|
preserveOnFocusChange: shouldPreserveFloatDomOnFocusChange(floatDomParam),
|
|
2530
2785
|
onPointerDown: (evt) => {
|
|
2531
2786
|
if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) canvas.dispatchEvent(new PointerEvent(evt.type, evt));
|
|
@@ -2537,7 +2792,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2537
2792
|
if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) canvas.dispatchEvent(new PointerEvent(evt.type, evt));
|
|
2538
2793
|
},
|
|
2539
2794
|
onWheel: (evt) => {
|
|
2540
|
-
if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt))
|
|
2795
|
+
if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) this._forwardWheelToCanvas(canvas, evt);
|
|
2541
2796
|
},
|
|
2542
2797
|
data,
|
|
2543
2798
|
props: shouldSyncEmbedRuntimeStage ? { onRuntimeStageEnter: handleRuntimeStageEnter } : void 0,
|
|
@@ -2616,7 +2871,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2616
2871
|
disposableCollection.add(sceneUpListener);
|
|
2617
2872
|
}
|
|
2618
2873
|
const listener = rect.onTransformChange$.subscribeEvent(() => {
|
|
2619
|
-
const newPosition =
|
|
2874
|
+
const newPosition = this._calculateFloatDomPosition(rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton);
|
|
2620
2875
|
position$.next(newPosition);
|
|
2621
2876
|
if (previewObjectKey) this._syncPreviewObjectTransform(scene.getObject(previewObjectKey), rect);
|
|
2622
2877
|
});
|
|
@@ -2625,7 +2880,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2625
2880
|
if (previewObjectKey) scene.removeObject(previewObjectKey);
|
|
2626
2881
|
});
|
|
2627
2882
|
listener && disposableCollection.add(listener);
|
|
2628
|
-
this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
|
|
2883
|
+
this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton, target.worksheet);
|
|
2629
2884
|
this._domLayerInfoMap.set(drawingId, info);
|
|
2630
2885
|
});
|
|
2631
2886
|
}));
|
|
@@ -2662,11 +2917,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2662
2917
|
subUnitId
|
|
2663
2918
|
});
|
|
2664
2919
|
const skeleton = (_this$_renderManagerS3 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId);
|
|
2665
|
-
if (!renderObject || !target || !skeleton) return;
|
|
2920
|
+
if (!renderObject || !target || !skeleton && target.worksheet.getConfig().type !== _univerjs_core.SheetTypes.CHART) return;
|
|
2666
2921
|
ids.forEach((id) => {
|
|
2667
2922
|
const floatDomInfo = this._domLayerInfoMap.get(id);
|
|
2668
2923
|
if (floatDomInfo) {
|
|
2669
|
-
const position =
|
|
2924
|
+
const position = this._calculateFloatDomPosition(floatDomInfo.rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton, floatDomInfo);
|
|
2670
2925
|
floatDomInfo.position$.next(position);
|
|
2671
2926
|
}
|
|
2672
2927
|
});
|
|
@@ -2696,9 +2951,35 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2696
2951
|
_bindFloatDomScroll(disposableCollection, info, scene, skeleton, worksheet) {
|
|
2697
2952
|
const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
|
|
2698
2953
|
if (!viewport) return;
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2954
|
+
const updatePosition = () => {
|
|
2955
|
+
if (this._domLayerInfoMap.get(info.id) !== info) return;
|
|
2956
|
+
info.position$.next(this._calculateFloatDomPosition(info.rect, scene, worksheet, skeleton, info));
|
|
2957
|
+
};
|
|
2958
|
+
disposableCollection.add((0, _univerjs_core.fromEventSubject)(viewport.onScrollAfter$).subscribe(updatePosition));
|
|
2959
|
+
if (worksheet.getConfig().type === _univerjs_core.SheetTypes.CHART) {
|
|
2960
|
+
disposableCollection.add(scene.onTransformChange$.subscribeEvent(updatePosition));
|
|
2961
|
+
disposableCollection.add(viewport.onResized$.subscribe(updatePosition));
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
_calculateFloatDomPosition(rect, scene, worksheet, skeleton, info) {
|
|
2965
|
+
if (skeleton) return calcSheetFloatDomPosition(rect, scene, skeleton, worksheet, info);
|
|
2966
|
+
const center = scene.getMainViewport().getAbsoluteVector(_univerjs_engine_render.Vector2.FromArray([rect.left + rect.width / 2, rect.top + rect.height / 2]));
|
|
2967
|
+
const { scaleX, scaleY, angle } = scene.transform.decompose();
|
|
2968
|
+
const width = rect.width * scaleX;
|
|
2969
|
+
const height = rect.height * scaleY;
|
|
2970
|
+
return {
|
|
2971
|
+
startX: center.x - width / 2,
|
|
2972
|
+
startY: center.y - height / 2,
|
|
2973
|
+
endX: center.x + width / 2,
|
|
2974
|
+
endY: center.y + height / 2,
|
|
2975
|
+
width,
|
|
2976
|
+
height,
|
|
2977
|
+
rotate: rect.angle + angle,
|
|
2978
|
+
absolute: {
|
|
2979
|
+
left: false,
|
|
2980
|
+
top: false
|
|
2981
|
+
}
|
|
2982
|
+
};
|
|
2702
2983
|
}
|
|
2703
2984
|
updateFloatDomProps(unitId, subUnitId, id, props) {
|
|
2704
2985
|
const info = this._domLayerInfoMap.get(id);
|
|
@@ -2868,9 +3149,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
2868
3149
|
return this._createFloatDomDisposable(id);
|
|
2869
3150
|
}
|
|
2870
3151
|
_removeDom(id, removeDrawing = false) {
|
|
3152
|
+
var _this$_floatDomMoveDi2;
|
|
2871
3153
|
const info = this._domLayerInfoMap.get(id);
|
|
2872
3154
|
if (!info) return;
|
|
2873
3155
|
const { unitId, subUnitId } = info;
|
|
3156
|
+
(_this$_floatDomMoveDi2 = this._floatDomMoveDisposables.get(id)) === null || _this$_floatDomMoveDi2 === void 0 || _this$_floatDomMoveDi2.dispose();
|
|
2874
3157
|
this._domLayerInfoMap.delete(id);
|
|
2875
3158
|
info.dispose.dispose();
|
|
2876
3159
|
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
@@ -3034,17 +3317,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
3034
3317
|
subUnitId
|
|
3035
3318
|
}, domRect, scene, this._drawingManagerService);
|
|
3036
3319
|
const disposableCollection = new _univerjs_core.DisposableCollection();
|
|
3037
|
-
const viewMain = scene.getMainViewport();
|
|
3038
|
-
const { rowHeaderWidth, columnHeaderHeight } = skeletonParam.skeleton;
|
|
3039
3320
|
const floatDomInfo = {
|
|
3040
3321
|
dispose: disposableCollection,
|
|
3041
3322
|
rect: domRect,
|
|
3042
|
-
boundsOfViewArea: {
|
|
3043
|
-
top: columnHeaderHeight,
|
|
3044
|
-
left: rowHeaderWidth,
|
|
3045
|
-
bottom: viewMain.bottom,
|
|
3046
|
-
right: viewMain.right
|
|
3047
|
-
},
|
|
3048
3323
|
domAnchor,
|
|
3049
3324
|
unitId,
|
|
3050
3325
|
subUnitId,
|
|
@@ -3061,12 +3336,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
3061
3336
|
let floatDomCfg = {
|
|
3062
3337
|
position$,
|
|
3063
3338
|
id: drawingId,
|
|
3339
|
+
preventBrowserZoom: true,
|
|
3064
3340
|
componentKey: floatDomParam.componentKey,
|
|
3065
3341
|
onPointerDown: () => {},
|
|
3066
3342
|
onPointerMove: () => {},
|
|
3067
3343
|
onPointerUp: () => {},
|
|
3068
3344
|
onWheel: (evt) => {
|
|
3069
|
-
|
|
3345
|
+
this._forwardWheelToCanvas(canvas, evt);
|
|
3070
3346
|
},
|
|
3071
3347
|
data,
|
|
3072
3348
|
unitId
|
|
@@ -3270,12 +3546,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
|
|
|
3270
3546
|
let floatDomCfg = {
|
|
3271
3547
|
position$,
|
|
3272
3548
|
id: drawingId,
|
|
3549
|
+
preventBrowserZoom: true,
|
|
3273
3550
|
componentKey: floatDomParam.componentKey,
|
|
3274
3551
|
onPointerDown: () => {},
|
|
3275
3552
|
onPointerMove: () => {},
|
|
3276
3553
|
onPointerUp: () => {},
|
|
3277
3554
|
onWheel: (evt) => {
|
|
3278
|
-
|
|
3555
|
+
this._forwardWheelToCanvas(canvas, evt);
|
|
3279
3556
|
},
|
|
3280
3557
|
data,
|
|
3281
3558
|
unitId
|
|
@@ -3514,6 +3791,25 @@ function touchSheetsDrawingFloatingHostCapabilityWhenReady(injector) {
|
|
|
3514
3791
|
|
|
3515
3792
|
// src/menu/image.menu.ts
|
|
3516
3793
|
const SHEETS_IMAGE_MENU_ID = "sheet.menu.image";
|
|
3794
|
+
/** Chart Sheets have no cells; other sheet types retain the existing range-menu permission rules. */
|
|
3795
|
+
function getImageMenuDisabled$(accessor, floating) {
|
|
3796
|
+
return (0, _univerjs_sheets_ui.deriveStateFromActiveSheet$)(accessor.get(_univerjs_core.IUniverInstanceService), true, ({ workbook, worksheet }) => {
|
|
3797
|
+
if (worksheet.getConfig().type === _univerjs_core.SheetTypes.CHART) {
|
|
3798
|
+
if (!floating) return (0, rxjs.of)(true);
|
|
3799
|
+
const permissions = accessor.get(_univerjs_core.IPermissionService);
|
|
3800
|
+
const ids = [new _univerjs_sheets.WorkbookEditablePermission(workbook.getUnitId()).id, new _univerjs_sheets.WorksheetEditPermission(workbook.getUnitId(), worksheet.getSheetId()).id];
|
|
3801
|
+
return permissions.permissionPointUpdate$.pipe((0, rxjs.startWith)(null), (0, rxjs.map)(() => ids.some((id) => {
|
|
3802
|
+
var _permissions$getPermi;
|
|
3803
|
+
return ((_permissions$getPermi = permissions.getPermissionPoint(id)) === null || _permissions$getPermi === void 0 ? void 0 : _permissions$getPermi.value) !== true;
|
|
3804
|
+
})), (0, rxjs.distinctUntilChanged)());
|
|
3805
|
+
}
|
|
3806
|
+
return (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
3807
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
3808
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission],
|
|
3809
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
3810
|
+
});
|
|
3811
|
+
});
|
|
3812
|
+
}
|
|
3517
3813
|
function ImageMenuFactory(accessor) {
|
|
3518
3814
|
return {
|
|
3519
3815
|
id: SHEETS_IMAGE_MENU_ID,
|
|
@@ -3521,17 +3817,14 @@ function ImageMenuFactory(accessor) {
|
|
|
3521
3817
|
icon: "AddImageIcon",
|
|
3522
3818
|
tooltip: "sheets-drawing-ui.title",
|
|
3523
3819
|
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
3524
|
-
disabled$:
|
|
3525
|
-
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
3526
|
-
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission],
|
|
3527
|
-
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
3528
|
-
})
|
|
3820
|
+
disabled$: getImageMenuDisabled$(accessor, true)
|
|
3529
3821
|
};
|
|
3530
3822
|
}
|
|
3531
3823
|
function UploadFloatImageMenuFactory(accessor) {
|
|
3532
3824
|
return {
|
|
3533
3825
|
id: InsertFloatImageCommand.id,
|
|
3534
3826
|
title: "sheets-drawing-ui.upload.float",
|
|
3827
|
+
disabled$: getImageMenuDisabled$(accessor, true),
|
|
3535
3828
|
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
3536
3829
|
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
|
|
3537
3830
|
};
|
|
@@ -3540,6 +3833,7 @@ function UploadCellImageMenuFactory(accessor) {
|
|
|
3540
3833
|
return {
|
|
3541
3834
|
id: InsertCellImageCommand.id,
|
|
3542
3835
|
title: "sheets-drawing-ui.upload.cell",
|
|
3836
|
+
disabled$: getImageMenuDisabled$(accessor, false),
|
|
3543
3837
|
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
3544
3838
|
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
|
|
3545
3839
|
};
|
|
@@ -3699,7 +3993,7 @@ const menuSchema = {
|
|
|
3699
3993
|
|
|
3700
3994
|
// package.json
|
|
3701
3995
|
var name = "@univerjs/sheets-drawing-ui";
|
|
3702
|
-
var version = "1.
|
|
3996
|
+
var version = "1.5.0";
|
|
3703
3997
|
|
|
3704
3998
|
// src/config/config.ts
|
|
3705
3999
|
const SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config";
|
|
@@ -4623,10 +4917,11 @@ SheetsDrawingRenderController = __decorate([
|
|
|
4623
4917
|
|
|
4624
4918
|
// src/views/background/worksheet-background-image.extension.ts
|
|
4625
4919
|
const WORKSHEET_BACKGROUND_IMAGE_EXTENSION_KEY = "WorksheetBackgroundImageExtension";
|
|
4626
|
-
var WorksheetBackgroundImageExtension = class extends _univerjs_engine_render.SheetExtension {
|
|
4920
|
+
var WorksheetBackgroundImageExtension = class WorksheetBackgroundImageExtension extends _univerjs_engine_render.SheetExtension {
|
|
4627
4921
|
constructor(injector, _requestRender) {
|
|
4628
4922
|
super();
|
|
4629
4923
|
this._requestRender = _requestRender;
|
|
4924
|
+
_defineProperty(this, "viewportCacheReusable", this.constructor === WorksheetBackgroundImageExtension);
|
|
4630
4925
|
_defineProperty(this, "uKey", WORKSHEET_BACKGROUND_IMAGE_EXTENSION_KEY);
|
|
4631
4926
|
_defineProperty(this, "type", _univerjs_engine_render.SHEET_EXTENSION_TYPE.BACKGROUND);
|
|
4632
4927
|
_defineProperty(this, "_imageCache", void 0);
|
|
@@ -5044,7 +5339,11 @@ const specialPastes = [
|
|
|
5044
5339
|
_univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
|
|
5045
5340
|
];
|
|
5046
5341
|
let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController extends _univerjs_core.RxDisposable {
|
|
5047
|
-
|
|
5342
|
+
dispose() {
|
|
5343
|
+
this._copyInfo = null;
|
|
5344
|
+
super.dispose();
|
|
5345
|
+
}
|
|
5346
|
+
constructor(_sheetClipboardService, _renderManagerService, _sheetSkeletonService, _drawingService, _clipboardInterfaceService, _commandService, _instanceService, _permissions) {
|
|
5048
5347
|
super();
|
|
5049
5348
|
this._sheetClipboardService = _sheetClipboardService;
|
|
5050
5349
|
this._renderManagerService = _renderManagerService;
|
|
@@ -5052,6 +5351,8 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
|
|
|
5052
5351
|
this._drawingService = _drawingService;
|
|
5053
5352
|
this._clipboardInterfaceService = _clipboardInterfaceService;
|
|
5054
5353
|
this._commandService = _commandService;
|
|
5354
|
+
this._instanceService = _instanceService;
|
|
5355
|
+
this._permissions = _permissions;
|
|
5055
5356
|
_defineProperty(this, "_copyInfo", void 0);
|
|
5056
5357
|
this._initCopyPaste();
|
|
5057
5358
|
}
|
|
@@ -5061,12 +5362,15 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
|
|
|
5061
5362
|
_initCopyPaste() {
|
|
5062
5363
|
this.disposeWithMe(this._sheetClipboardService.addClipboardHook({
|
|
5063
5364
|
id: "SHEET_IMAGE_UI_PLUGIN",
|
|
5064
|
-
onBeforeCopyFocusedObject: (unitId,
|
|
5365
|
+
onBeforeCopyFocusedObject: (unitId, subUnitId, copyType) => {
|
|
5065
5366
|
this._copyInfo = null;
|
|
5066
5367
|
const drawings = this._focusedDrawings.filter((drawing) => drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE);
|
|
5067
5368
|
if (drawings.length === 0) return false;
|
|
5068
5369
|
const [drawing] = drawings;
|
|
5069
5370
|
if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
|
|
5371
|
+
var _this$_instanceServic;
|
|
5372
|
+
const worksheet = (_this$_instanceServic = this._instanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getSheetBySheetId(subUnitId);
|
|
5373
|
+
if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) === _univerjs_core.SheetTypes.CHART) return false;
|
|
5070
5374
|
const params = {
|
|
5071
5375
|
unitId,
|
|
5072
5376
|
drawings
|
|
@@ -5196,12 +5500,15 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
|
|
|
5196
5500
|
};
|
|
5197
5501
|
}
|
|
5198
5502
|
_generateSingleDrawingPasteMutations(pasteContext, copyType) {
|
|
5503
|
+
var _this$_instanceServic2;
|
|
5199
5504
|
const { pasteType, pasteTo } = pasteContext;
|
|
5200
5505
|
if (specialPastes.includes(pasteType)) return {
|
|
5201
5506
|
redos: [],
|
|
5202
5507
|
undos: []
|
|
5203
5508
|
};
|
|
5204
5509
|
const { unitId, subUnitId, range } = pasteTo;
|
|
5510
|
+
const worksheet = (_this$_instanceServic2 = this._instanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceServic2 === void 0 ? void 0 : _this$_instanceServic2.getSheetBySheetId(subUnitId);
|
|
5511
|
+
if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) === _univerjs_core.SheetTypes.CHART) return this._generateChartSheetImagePasteMutations(pasteTo);
|
|
5205
5512
|
const pasteToSkeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
5206
5513
|
if (!pasteToSkeleton) return {
|
|
5207
5514
|
redos: [],
|
|
@@ -5247,6 +5554,47 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
|
|
|
5247
5554
|
}
|
|
5248
5555
|
});
|
|
5249
5556
|
}
|
|
5557
|
+
_generateChartSheetImagePasteMutations(pasteTo) {
|
|
5558
|
+
var _this$_renderManagerS;
|
|
5559
|
+
const { unitId, subUnitId } = pasteTo;
|
|
5560
|
+
const worksheet = this._instanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(subUnitId);
|
|
5561
|
+
if (!this._permissions.permissionCheckWithoutRange({
|
|
5562
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
5563
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
|
|
5564
|
+
}, unitId, subUnitId)) throw new _univerjs_core.CustomCommandExecutionError(_univerjs_sheets_ui.SheetPasteCommand.id);
|
|
5565
|
+
const source = this._copyInfo;
|
|
5566
|
+
if (!this._permissions.permissionCheckWithoutRange({
|
|
5567
|
+
workbookTypes: [_univerjs_sheets.WorkbookCopyPermission],
|
|
5568
|
+
worksheetTypes: [_univerjs_sheets.WorksheetCopyPermission]
|
|
5569
|
+
}, source.unitId, source.subUnitId) || source.drawings.some((drawing) => !_univerjs_core.Tools.diffValue(drawing, this._drawingService.getDrawingByParam(drawing)))) throw new _univerjs_core.CustomCommandExecutionError(_univerjs_sheets_ui.SheetPasteCommand.id);
|
|
5570
|
+
const frame = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.components.get(_univerjs_sheets_ui.SHEET_VIEW_KEY.CHART_PAGE);
|
|
5571
|
+
const originals = this._copyInfo.drawings;
|
|
5572
|
+
const placed = frame && (0, _univerjs_sheets_drawing.transformDrawingsToChartSheet)(originals, {
|
|
5573
|
+
left: frame.left,
|
|
5574
|
+
top: frame.top,
|
|
5575
|
+
width: frame.width,
|
|
5576
|
+
height: frame.height
|
|
5577
|
+
}, worksheet.getConfig().rightToLeft === _univerjs_core.BooleanNumber.TRUE);
|
|
5578
|
+
if (!placed) return {
|
|
5579
|
+
redos: [],
|
|
5580
|
+
undos: []
|
|
5581
|
+
};
|
|
5582
|
+
const copies = new Map(placed.map((drawing) => [drawing.drawingId, drawing]));
|
|
5583
|
+
return this._generateMutations(originals, {
|
|
5584
|
+
unitId,
|
|
5585
|
+
subUnitId,
|
|
5586
|
+
isCut: false,
|
|
5587
|
+
getTransform: (_transform, _sheetTransform, drawing) => {
|
|
5588
|
+
const copy = copies.get(drawing.drawingId);
|
|
5589
|
+
return {
|
|
5590
|
+
anchorType: copy.anchorType,
|
|
5591
|
+
transform: copy.transform,
|
|
5592
|
+
sheetTransform: copy.sheetTransform,
|
|
5593
|
+
axisAlignSheetTransform: copy.axisAlignSheetTransform
|
|
5594
|
+
};
|
|
5595
|
+
}
|
|
5596
|
+
});
|
|
5597
|
+
}
|
|
5250
5598
|
_generateMutations(drawings, payload) {
|
|
5251
5599
|
const { unitId, subUnitId, getTransform, isCut } = payload;
|
|
5252
5600
|
const redos = [];
|
|
@@ -5255,15 +5603,13 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
|
|
|
5255
5603
|
drawings.forEach((drawing) => {
|
|
5256
5604
|
const { transform, sheetTransform } = drawing;
|
|
5257
5605
|
if (!transform) return;
|
|
5258
|
-
const transformContext = getTransform(transform, sheetTransform);
|
|
5606
|
+
const transformContext = getTransform(transform, sheetTransform, drawing);
|
|
5259
5607
|
const drawingObject = {
|
|
5260
5608
|
...drawing,
|
|
5261
|
-
|
|
5262
|
-
subUnitId,
|
|
5609
|
+
...transformContext,
|
|
5263
5610
|
drawingId: isCut ? drawing.drawingId : (0, _univerjs_core.generateRandomId)(),
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
axisAlignSheetTransform: transformContext.axisAlignSheetTransform
|
|
5611
|
+
unitId,
|
|
5612
|
+
subUnitId
|
|
5267
5613
|
};
|
|
5268
5614
|
if (isCut) {
|
|
5269
5615
|
const { undo, redo, objects } = _drawingService.getBatchUpdateOp([drawingObject]);
|
|
@@ -5406,9 +5752,135 @@ SheetsDrawingCopyPasteController = __decorate([
|
|
|
5406
5752
|
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetSkeletonService)),
|
|
5407
5753
|
__decorateParam(3, _univerjs_drawing.IDrawingManagerService),
|
|
5408
5754
|
__decorateParam(4, _univerjs_ui.IClipboardInterfaceService),
|
|
5409
|
-
__decorateParam(5, _univerjs_core.ICommandService)
|
|
5755
|
+
__decorateParam(5, _univerjs_core.ICommandService),
|
|
5756
|
+
__decorateParam(6, _univerjs_core.IUniverInstanceService),
|
|
5757
|
+
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController))
|
|
5410
5758
|
], SheetsDrawingCopyPasteController);
|
|
5411
5759
|
|
|
5760
|
+
// src/commands/commands/flip-drawings.command.ts
|
|
5761
|
+
/**
|
|
5762
|
+
* The command to flip sheet drawing elements
|
|
5763
|
+
*/
|
|
5764
|
+
const FlipSheetDrawingCommand = {
|
|
5765
|
+
id: "sheet.command.toggle-flip-drawings",
|
|
5766
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
5767
|
+
handler: (accessor, params) => {
|
|
5768
|
+
if (!params) return false;
|
|
5769
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
5770
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
5771
|
+
const sheetDrawingService = accessor.get(_univerjs_sheets_drawing.ISheetDrawingService);
|
|
5772
|
+
const sheetSkeletonService = accessor.get(_univerjs_sheets.SheetSkeletonService);
|
|
5773
|
+
const { drawings } = params;
|
|
5774
|
+
const flipH = params.flipH;
|
|
5775
|
+
const flipV = params.flipV;
|
|
5776
|
+
const unitIds = [];
|
|
5777
|
+
const updateParams = [];
|
|
5778
|
+
for (const param of drawings) {
|
|
5779
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
5780
|
+
unitIds.push(unitId);
|
|
5781
|
+
const drawingData = sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
5782
|
+
const existing = drawingData === null || drawingData === void 0 ? void 0 : drawingData[drawingId];
|
|
5783
|
+
if (!existing) continue;
|
|
5784
|
+
const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
5785
|
+
if (!skeleton) continue;
|
|
5786
|
+
const transform = { ...existing.transform };
|
|
5787
|
+
if (flipH) transform.flipX = !transform.flipX;
|
|
5788
|
+
if (flipV) transform.flipY = !transform.flipY;
|
|
5789
|
+
const sheetTransform = (0, _univerjs_sheets_drawing.transformToDrawingPosition)(transform, skeleton);
|
|
5790
|
+
const axisAlignSheetTransform = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(transform, skeleton);
|
|
5791
|
+
const updateParamItem = {
|
|
5792
|
+
unitId,
|
|
5793
|
+
subUnitId,
|
|
5794
|
+
drawingType: existing.drawingType,
|
|
5795
|
+
drawingId,
|
|
5796
|
+
transform,
|
|
5797
|
+
sheetTransform,
|
|
5798
|
+
axisAlignSheetTransform
|
|
5799
|
+
};
|
|
5800
|
+
if (existing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) {
|
|
5801
|
+
const scene = getSceneByDrawingSearch(accessor, unitId);
|
|
5802
|
+
if (scene) {
|
|
5803
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
5804
|
+
unitId,
|
|
5805
|
+
subUnitId,
|
|
5806
|
+
drawingId
|
|
5807
|
+
});
|
|
5808
|
+
const imageShape = scene.getObject(drawingShapeKey);
|
|
5809
|
+
if (imageShape) {
|
|
5810
|
+
const srcRect = imageShape.srcRect;
|
|
5811
|
+
if (srcRect) {
|
|
5812
|
+
let newSrcRect;
|
|
5813
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = srcRect;
|
|
5814
|
+
if (flipH) {
|
|
5815
|
+
const centerX = left + (right - left) / 2;
|
|
5816
|
+
newSrcRect = {
|
|
5817
|
+
left: centerX - (right - left) / 2,
|
|
5818
|
+
top,
|
|
5819
|
+
right: centerX + (right - left) / 2,
|
|
5820
|
+
bottom
|
|
5821
|
+
};
|
|
5822
|
+
}
|
|
5823
|
+
if (flipV) {
|
|
5824
|
+
const centerY = top + (bottom - top) / 2;
|
|
5825
|
+
newSrcRect = {
|
|
5826
|
+
left,
|
|
5827
|
+
top: centerY - (bottom - top) / 2,
|
|
5828
|
+
right,
|
|
5829
|
+
bottom: centerY + (bottom - top) / 2
|
|
5830
|
+
};
|
|
5831
|
+
}
|
|
5832
|
+
if (newSrcRect) updateParamItem.srcRect = newSrcRect;
|
|
5833
|
+
}
|
|
5834
|
+
}
|
|
5835
|
+
}
|
|
5836
|
+
}
|
|
5837
|
+
updateParams.push(updateParamItem);
|
|
5838
|
+
}
|
|
5839
|
+
if (updateParams.length === 0) return false;
|
|
5840
|
+
const { unitId: opUnitId, subUnitId: opSubUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(updateParams);
|
|
5841
|
+
const updateMutation = {
|
|
5842
|
+
id: _univerjs_sheets_drawing.SetDrawingApplyMutation.id,
|
|
5843
|
+
params: {
|
|
5844
|
+
unitId: opUnitId,
|
|
5845
|
+
subUnitId: opSubUnitId,
|
|
5846
|
+
op: redo,
|
|
5847
|
+
objects,
|
|
5848
|
+
type: _univerjs_sheets_drawing.DrawingApplyType.UPDATE
|
|
5849
|
+
}
|
|
5850
|
+
};
|
|
5851
|
+
const undoUpdateMutation = {
|
|
5852
|
+
id: _univerjs_sheets_drawing.SetDrawingApplyMutation.id,
|
|
5853
|
+
params: {
|
|
5854
|
+
unitId: opUnitId,
|
|
5855
|
+
subUnitId: opSubUnitId,
|
|
5856
|
+
op: undo,
|
|
5857
|
+
objects,
|
|
5858
|
+
type: _univerjs_sheets_drawing.DrawingApplyType.UPDATE
|
|
5859
|
+
}
|
|
5860
|
+
};
|
|
5861
|
+
if ((0, _univerjs_core.sequenceExecute)([updateMutation], commandService).result) {
|
|
5862
|
+
undoRedoService.pushUndoRedo({
|
|
5863
|
+
unitID: opUnitId,
|
|
5864
|
+
undoMutations: [undoUpdateMutation, {
|
|
5865
|
+
id: _univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id,
|
|
5866
|
+
params: unitIds
|
|
5867
|
+
}],
|
|
5868
|
+
redoMutations: [updateMutation, {
|
|
5869
|
+
id: _univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id,
|
|
5870
|
+
params: unitIds
|
|
5871
|
+
}]
|
|
5872
|
+
});
|
|
5873
|
+
return true;
|
|
5874
|
+
}
|
|
5875
|
+
return false;
|
|
5876
|
+
}
|
|
5877
|
+
};
|
|
5878
|
+
function getSceneByDrawingSearch(accessor, unitId) {
|
|
5879
|
+
const render = accessor.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId);
|
|
5880
|
+
if (!render) return null;
|
|
5881
|
+
return render.scene;
|
|
5882
|
+
}
|
|
5883
|
+
|
|
5412
5884
|
// src/controllers/sheet-drawing-permission.controller.ts
|
|
5413
5885
|
const drawingObjectTypes = [
|
|
5414
5886
|
_univerjs_engine_render.ObjectType.IMAGE,
|
|
@@ -5432,6 +5904,7 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
|
|
|
5432
5904
|
this._initViewPermissionChange();
|
|
5433
5905
|
this._initEditPermissionChange();
|
|
5434
5906
|
this._initCommandPermissionCheck();
|
|
5907
|
+
this._initChartSheetCommandPermissionCheck();
|
|
5435
5908
|
}
|
|
5436
5909
|
_initDrawingVisible() {
|
|
5437
5910
|
const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
@@ -5607,6 +6080,30 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
|
|
|
5607
6080
|
}
|
|
5608
6081
|
}));
|
|
5609
6082
|
}
|
|
6083
|
+
_initChartSheetCommandPermissionCheck() {
|
|
6084
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
6085
|
+
if (command.id === GroupSheetDrawingCommand.id || command.id === UngroupSheetDrawingCommand.id) {
|
|
6086
|
+
for (const group of command.params ?? []) {
|
|
6087
|
+
this._checkChartSheetEditPermission(group.parent.unitId, group.parent.subUnitId);
|
|
6088
|
+
for (const child of group.children) this._checkChartSheetEditPermission(child.unitId, child.subUnitId);
|
|
6089
|
+
}
|
|
6090
|
+
return;
|
|
6091
|
+
}
|
|
6092
|
+
if (command.id === FlipSheetDrawingCommand.id) {
|
|
6093
|
+
const params = command.params;
|
|
6094
|
+
for (const drawing of (params === null || params === void 0 ? void 0 : params.drawings) ?? []) this._checkChartSheetEditPermission(drawing.unitId, drawing.subUnitId);
|
|
6095
|
+
}
|
|
6096
|
+
}));
|
|
6097
|
+
}
|
|
6098
|
+
_checkChartSheetEditPermission(unitId, subUnitId) {
|
|
6099
|
+
var _this$_univerInstance;
|
|
6100
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
6101
|
+
if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) !== _univerjs_core.SheetTypes.CHART) return;
|
|
6102
|
+
if (!this._sheetPermissionCheckController.permissionCheckWithoutRange({
|
|
6103
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
6104
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
|
|
6105
|
+
}, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-drawing-ui.permission.dialog.editErr"));
|
|
6106
|
+
}
|
|
5610
6107
|
_initCommandPermissionCheck() {
|
|
5611
6108
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
5612
6109
|
let unitId;
|
|
@@ -5830,130 +6327,6 @@ SheetDrawingPrintingController = __decorate([
|
|
|
5830
6327
|
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
|
|
5831
6328
|
], SheetDrawingPrintingController);
|
|
5832
6329
|
|
|
5833
|
-
// src/commands/commands/flip-drawings.command.ts
|
|
5834
|
-
/**
|
|
5835
|
-
* The command to flip sheet drawing elements
|
|
5836
|
-
*/
|
|
5837
|
-
const FlipSheetDrawingCommand = {
|
|
5838
|
-
id: "sheet.command.toggle-flip-drawings",
|
|
5839
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
5840
|
-
handler: (accessor, params) => {
|
|
5841
|
-
if (!params) return false;
|
|
5842
|
-
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
5843
|
-
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
5844
|
-
const sheetDrawingService = accessor.get(_univerjs_sheets_drawing.ISheetDrawingService);
|
|
5845
|
-
const sheetSkeletonService = accessor.get(_univerjs_sheets.SheetSkeletonService);
|
|
5846
|
-
const { drawings } = params;
|
|
5847
|
-
const flipH = params.flipH;
|
|
5848
|
-
const flipV = params.flipV;
|
|
5849
|
-
const unitIds = [];
|
|
5850
|
-
const updateParams = [];
|
|
5851
|
-
for (const param of drawings) {
|
|
5852
|
-
const { unitId, subUnitId, drawingId } = param;
|
|
5853
|
-
unitIds.push(unitId);
|
|
5854
|
-
const drawingData = sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
5855
|
-
const existing = drawingData === null || drawingData === void 0 ? void 0 : drawingData[drawingId];
|
|
5856
|
-
if (!existing) continue;
|
|
5857
|
-
const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
5858
|
-
if (!skeleton) continue;
|
|
5859
|
-
const transform = { ...existing.transform };
|
|
5860
|
-
if (flipH) transform.flipX = !transform.flipX;
|
|
5861
|
-
if (flipV) transform.flipY = !transform.flipY;
|
|
5862
|
-
const sheetTransform = (0, _univerjs_sheets_drawing.transformToDrawingPosition)(transform, skeleton);
|
|
5863
|
-
const axisAlignSheetTransform = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(transform, skeleton);
|
|
5864
|
-
const updateParamItem = {
|
|
5865
|
-
unitId,
|
|
5866
|
-
subUnitId,
|
|
5867
|
-
drawingType: existing.drawingType,
|
|
5868
|
-
drawingId,
|
|
5869
|
-
transform,
|
|
5870
|
-
sheetTransform,
|
|
5871
|
-
axisAlignSheetTransform
|
|
5872
|
-
};
|
|
5873
|
-
if (existing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) {
|
|
5874
|
-
const scene = getSceneByDrawingSearch(accessor, unitId);
|
|
5875
|
-
if (scene) {
|
|
5876
|
-
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
5877
|
-
unitId,
|
|
5878
|
-
subUnitId,
|
|
5879
|
-
drawingId
|
|
5880
|
-
});
|
|
5881
|
-
const imageShape = scene.getObject(drawingShapeKey);
|
|
5882
|
-
if (imageShape) {
|
|
5883
|
-
const srcRect = imageShape.srcRect;
|
|
5884
|
-
if (srcRect) {
|
|
5885
|
-
let newSrcRect;
|
|
5886
|
-
const { left = 0, top = 0, right = 0, bottom = 0 } = srcRect;
|
|
5887
|
-
if (flipH) {
|
|
5888
|
-
const centerX = left + (right - left) / 2;
|
|
5889
|
-
newSrcRect = {
|
|
5890
|
-
left: centerX - (right - left) / 2,
|
|
5891
|
-
top,
|
|
5892
|
-
right: centerX + (right - left) / 2,
|
|
5893
|
-
bottom
|
|
5894
|
-
};
|
|
5895
|
-
}
|
|
5896
|
-
if (flipV) {
|
|
5897
|
-
const centerY = top + (bottom - top) / 2;
|
|
5898
|
-
newSrcRect = {
|
|
5899
|
-
left,
|
|
5900
|
-
top: centerY - (bottom - top) / 2,
|
|
5901
|
-
right,
|
|
5902
|
-
bottom: centerY + (bottom - top) / 2
|
|
5903
|
-
};
|
|
5904
|
-
}
|
|
5905
|
-
if (newSrcRect) updateParamItem.srcRect = newSrcRect;
|
|
5906
|
-
}
|
|
5907
|
-
}
|
|
5908
|
-
}
|
|
5909
|
-
}
|
|
5910
|
-
updateParams.push(updateParamItem);
|
|
5911
|
-
}
|
|
5912
|
-
if (updateParams.length === 0) return false;
|
|
5913
|
-
const { unitId: opUnitId, subUnitId: opSubUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(updateParams);
|
|
5914
|
-
const updateMutation = {
|
|
5915
|
-
id: _univerjs_sheets_drawing.SetDrawingApplyMutation.id,
|
|
5916
|
-
params: {
|
|
5917
|
-
unitId: opUnitId,
|
|
5918
|
-
subUnitId: opSubUnitId,
|
|
5919
|
-
op: redo,
|
|
5920
|
-
objects,
|
|
5921
|
-
type: _univerjs_sheets_drawing.DrawingApplyType.UPDATE
|
|
5922
|
-
}
|
|
5923
|
-
};
|
|
5924
|
-
const undoUpdateMutation = {
|
|
5925
|
-
id: _univerjs_sheets_drawing.SetDrawingApplyMutation.id,
|
|
5926
|
-
params: {
|
|
5927
|
-
unitId: opUnitId,
|
|
5928
|
-
subUnitId: opSubUnitId,
|
|
5929
|
-
op: undo,
|
|
5930
|
-
objects,
|
|
5931
|
-
type: _univerjs_sheets_drawing.DrawingApplyType.UPDATE
|
|
5932
|
-
}
|
|
5933
|
-
};
|
|
5934
|
-
if ((0, _univerjs_core.sequenceExecute)([updateMutation], commandService).result) {
|
|
5935
|
-
undoRedoService.pushUndoRedo({
|
|
5936
|
-
unitID: opUnitId,
|
|
5937
|
-
undoMutations: [undoUpdateMutation, {
|
|
5938
|
-
id: _univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id,
|
|
5939
|
-
params: unitIds
|
|
5940
|
-
}],
|
|
5941
|
-
redoMutations: [updateMutation, {
|
|
5942
|
-
id: _univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id,
|
|
5943
|
-
params: unitIds
|
|
5944
|
-
}]
|
|
5945
|
-
});
|
|
5946
|
-
return true;
|
|
5947
|
-
}
|
|
5948
|
-
return false;
|
|
5949
|
-
}
|
|
5950
|
-
};
|
|
5951
|
-
function getSceneByDrawingSearch(accessor, unitId) {
|
|
5952
|
-
const render = accessor.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId);
|
|
5953
|
-
if (!render) return null;
|
|
5954
|
-
return render.scene;
|
|
5955
|
-
}
|
|
5956
|
-
|
|
5957
6330
|
// src/controllers/shortcuts/drawing.shortcut.ts
|
|
5958
6331
|
function whenSheetDrawingFocused(contextService) {
|
|
5959
6332
|
return contextService.getContextValue(_univerjs_core.FOCUSING_SHEET) && !contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) && !contextService.getContextValue(_univerjs_core.FOCUSING_PANEL_EDITOR) && contextService.getContextValue(_univerjs_core.FOCUSING_COMMON_DRAWINGS) && !contextService.getContextValue(_univerjs_core.FOCUSING_SHAPE_TEXT_EDITOR);
|
|
@@ -6337,11 +6710,13 @@ let MobileDrawingPopupMenuController = class MobileDrawingPopupMenuController ex
|
|
|
6337
6710
|
_getFloatingObjectMenuItems() {
|
|
6338
6711
|
return this._menuManagerService.getFlatMenuByPositionKey(_univerjs_ui.FloatingObjectToolbarPosition.SHEET).flatMap(({ item }, index) => {
|
|
6339
6712
|
if (!item || item.type !== _univerjs_ui.MenuItemType.BUTTON || !item.title) return [];
|
|
6713
|
+
const { icon, params } = item;
|
|
6340
6714
|
return [{
|
|
6341
6715
|
label: item.title,
|
|
6716
|
+
...typeof icon === "string" ? { icon } : {},
|
|
6342
6717
|
index: 100 + index,
|
|
6343
6718
|
commandId: item.commandId ?? item.id,
|
|
6344
|
-
commandParams: typeof
|
|
6719
|
+
commandParams: typeof params === "function" ? params.call(item) : params,
|
|
6345
6720
|
disable: false
|
|
6346
6721
|
}];
|
|
6347
6722
|
});
|
|
@@ -6867,11 +7242,13 @@ let DrawingPopupMenuController = class DrawingPopupMenuController extends _unive
|
|
|
6867
7242
|
_getFloatingObjectMenuItems() {
|
|
6868
7243
|
return this._menuManagerService.getFlatMenuByPositionKey(_univerjs_ui.FloatingObjectToolbarPosition.SHEET).flatMap(({ item }, index) => {
|
|
6869
7244
|
if (!item || item.type !== _univerjs_ui.MenuItemType.BUTTON || !item.title) return [];
|
|
7245
|
+
const { icon, params } = item;
|
|
6870
7246
|
return [{
|
|
6871
7247
|
label: item.title,
|
|
7248
|
+
...typeof icon === "string" ? { icon } : {},
|
|
6872
7249
|
index: 100 + index,
|
|
6873
7250
|
commandId: item.commandId ?? item.id,
|
|
6874
|
-
commandParams: typeof
|
|
7251
|
+
commandParams: typeof params === "function" ? params.call(item) : params,
|
|
6875
7252
|
disable: false
|
|
6876
7253
|
}];
|
|
6877
7254
|
});
|