@univerjs/sheets-drawing 1.0.0-alpha.8 → 1.0.0-beta.1
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/cjs/facade.js +288 -21
- package/lib/cjs/index.js +258 -52
- package/lib/es/facade.js +289 -22
- package/lib/es/index.js +256 -54
- package/lib/facade.js +289 -22
- package/lib/index.js +256 -54
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +6 -2
- package/lib/types/commands/commands/set-sheet-drawing-placement.command.d.ts +26 -0
- package/lib/types/facade/f-over-grid-image.d.ts +130 -4
- package/lib/types/facade/f-worksheet.d.ts +128 -1
- package/lib/types/index.d.ts +4 -0
- package/lib/types/services/sheet-drawing-placement.d.ts +86 -0
- package/lib/types/services/sheet-drawing.service.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/es/facade.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ArrangeTypeEnum, CanceledError, DrawingTypeEnum, ICommandService, IUndo
|
|
|
2
2
|
import { FBase, FEnum, FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
3
|
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize, isGroupableDrawingType } from "@univerjs/drawing";
|
|
4
4
|
import { SheetSkeletonService, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
5
|
-
import { DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, transformToAxisAlignPosition } from "@univerjs/sheets-drawing";
|
|
5
|
+
import { DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SheetDrawingAnchorType, applySheetDrawingPlacement, getSheetDrawingPlacement, normalizeSheetDrawingPlacement, transformToAxisAlignPosition } from "@univerjs/sheets-drawing";
|
|
6
6
|
import { getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
|
|
7
7
|
import { FWorksheet } from "@univerjs/sheets/facade";
|
|
8
8
|
|
|
@@ -132,9 +132,10 @@ function convertFOverGridImageToSheetImage(fOverGridImage, sheetSkeletonService)
|
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
135
|
-
constructor(unitId, subUnitId,
|
|
136
|
-
this.
|
|
135
|
+
constructor(unitId, subUnitId, _sheetSkeletonService) {
|
|
136
|
+
this._sheetSkeletonService = _sheetSkeletonService;
|
|
137
137
|
_defineProperty(this, "_image", void 0);
|
|
138
|
+
_defineProperty(this, "_placement", void 0);
|
|
138
139
|
this._image = {
|
|
139
140
|
drawingId: generateRandomId(6),
|
|
140
141
|
drawingType: DrawingTypeEnum.DRAWING_IMAGE,
|
|
@@ -192,7 +193,7 @@ let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
|
192
193
|
*/
|
|
193
194
|
setImage(image) {
|
|
194
195
|
const { unitId, subUnitId } = image;
|
|
195
|
-
const skeleton = this.
|
|
196
|
+
const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
|
|
196
197
|
if (!skeleton) throw new Error(`Skeleton for unitId ${unitId} and subUnitId ${subUnitId} not found`);
|
|
197
198
|
if (image.sheetTransform == null) image.sheetTransform = {
|
|
198
199
|
from: {
|
|
@@ -226,7 +227,7 @@ let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
|
226
227
|
return this;
|
|
227
228
|
}
|
|
228
229
|
setSource(source, sourceType) {
|
|
229
|
-
const sourceTypeVal = sourceType
|
|
230
|
+
const sourceTypeVal = sourceType ?? ImageSourceType.URL;
|
|
230
231
|
this._image.source = source;
|
|
231
232
|
this._image.imageSourceType = sourceTypeVal;
|
|
232
233
|
return this;
|
|
@@ -461,6 +462,73 @@ let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
|
461
462
|
return this;
|
|
462
463
|
}
|
|
463
464
|
/**
|
|
465
|
+
* Set an explicit OneCell, TwoCell, or Absolute placement for the image.
|
|
466
|
+
*
|
|
467
|
+
* This placement takes precedence over the individual row, column, size,
|
|
468
|
+
* and anchor type builder fields. Use bounds inference for an existing
|
|
469
|
+
* transform; use exact markers when a caller explicitly chose cells.
|
|
470
|
+
* @param {ISheetDrawingPlacementInput} placement Exact placement or bounds with an explicit anchor type.
|
|
471
|
+
* @returns {FOverGridImageBuilder} This builder.
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts
|
|
474
|
+
* const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
475
|
+
* const image = await sheet.newOverGridImage()
|
|
476
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=96&v=4')
|
|
477
|
+
* .setPlacement({
|
|
478
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Position,
|
|
479
|
+
* from: { row: 2, column: 2, rowOffset: 8, columnOffset: 8 },
|
|
480
|
+
* width: 240,
|
|
481
|
+
* height: 120,
|
|
482
|
+
* })
|
|
483
|
+
* .buildAsync();
|
|
484
|
+
* sheet.insertImages([image]);
|
|
485
|
+
* ```
|
|
486
|
+
* @example Infer Position markers from model-space bounds
|
|
487
|
+
* ```ts
|
|
488
|
+
* const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
489
|
+
* const image = await sheet.newOverGridImage()
|
|
490
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=96&v=4')
|
|
491
|
+
* .setPlacement({
|
|
492
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Position,
|
|
493
|
+
* bounds: { left: 120, top: 80, width: 240, height: 120 },
|
|
494
|
+
* })
|
|
495
|
+
* .buildAsync();
|
|
496
|
+
* sheet.insertImages([image]);
|
|
497
|
+
* ```
|
|
498
|
+
* @example TwoCell
|
|
499
|
+
* ```ts
|
|
500
|
+
* const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
501
|
+
* const image = await sheet.newOverGridImage()
|
|
502
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=96&v=4')
|
|
503
|
+
* .setPlacement({
|
|
504
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Both,
|
|
505
|
+
* from: { row: 2, column: 2, rowOffset: 8, columnOffset: 8 },
|
|
506
|
+
* to: { row: 8, column: 6, rowOffset: 0, columnOffset: 0 },
|
|
507
|
+
* })
|
|
508
|
+
* .buildAsync();
|
|
509
|
+
* sheet.insertImages([image]);
|
|
510
|
+
* ```
|
|
511
|
+
* @example Absolute
|
|
512
|
+
* ```ts
|
|
513
|
+
* const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
514
|
+
* const image = await sheet.newOverGridImage()
|
|
515
|
+
* .setSource('https://avatars.githubusercontent.com/u/61444807?s=96&v=4')
|
|
516
|
+
* .setPlacement({
|
|
517
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.None,
|
|
518
|
+
* left: 640,
|
|
519
|
+
* top: 96,
|
|
520
|
+
* width: 240,
|
|
521
|
+
* height: 120,
|
|
522
|
+
* })
|
|
523
|
+
* .buildAsync();
|
|
524
|
+
* sheet.insertImages([image]);
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
setPlacement(placement) {
|
|
528
|
+
this._placement = placement;
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
464
532
|
* Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
|
|
465
533
|
* @param {number} top - The number of pixels to crop from the top of the image
|
|
466
534
|
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
@@ -601,24 +669,63 @@ let FOverGridImageBuilder = class FOverGridImageBuilder {
|
|
|
601
669
|
return this;
|
|
602
670
|
}
|
|
603
671
|
async buildAsync() {
|
|
604
|
-
|
|
605
|
-
|
|
672
|
+
var _this$_placement;
|
|
673
|
+
const sheetSkeletonService = this._sheetSkeletonService;
|
|
674
|
+
if (!this._placement && (this._image.width === 0 || this._image.height === 0)) {
|
|
606
675
|
const size = await getImageSize(this._image.source);
|
|
607
676
|
const width = size.width;
|
|
608
677
|
const height = size.height;
|
|
609
678
|
if (this._image.width === 0) this._image.width = width;
|
|
610
679
|
if (this._image.height === 0) this._image.height = height;
|
|
611
680
|
}
|
|
612
|
-
|
|
681
|
+
if (((_this$_placement = this._placement) === null || _this$_placement === void 0 ? void 0 : _this$_placement.kind) === SheetDrawingAnchorType.None) {
|
|
682
|
+
const { left, top, width, height } = "bounds" in this._placement ? this._placement.bounds : this._placement;
|
|
683
|
+
const sheetTransform = {
|
|
684
|
+
from: {
|
|
685
|
+
column: 0,
|
|
686
|
+
columnOffset: left,
|
|
687
|
+
row: 0,
|
|
688
|
+
rowOffset: top
|
|
689
|
+
},
|
|
690
|
+
to: {
|
|
691
|
+
column: 0,
|
|
692
|
+
columnOffset: left + width,
|
|
693
|
+
row: 0,
|
|
694
|
+
rowOffset: top + height
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
return applySheetDrawingPlacement({
|
|
698
|
+
...this._image,
|
|
699
|
+
transform: {
|
|
700
|
+
left,
|
|
701
|
+
top,
|
|
702
|
+
width,
|
|
703
|
+
height,
|
|
704
|
+
flipY: this._image.flipY,
|
|
705
|
+
flipX: this._image.flipX,
|
|
706
|
+
angle: this._image.angle,
|
|
707
|
+
skewX: this._image.skewX,
|
|
708
|
+
skewY: this._image.skewY
|
|
709
|
+
},
|
|
710
|
+
sheetTransform,
|
|
711
|
+
axisAlignSheetTransform: sheetTransform
|
|
712
|
+
}, this._placement);
|
|
713
|
+
}
|
|
714
|
+
const image = convertFOverGridImageToSheetImage(this._image, sheetSkeletonService);
|
|
715
|
+
if (!this._placement) return image;
|
|
716
|
+
const skeleton = sheetSkeletonService.ensureSkeleton(image.unitId, image.subUnitId);
|
|
717
|
+
return applySheetDrawingPlacement(image, this._placement, skeleton);
|
|
613
718
|
}
|
|
614
719
|
};
|
|
615
|
-
FOverGridImageBuilder = __decorate([__decorateParam(2, Inject(
|
|
720
|
+
FOverGridImageBuilder = __decorate([__decorateParam(2, Inject(SheetSkeletonService))], FOverGridImageBuilder);
|
|
616
721
|
let FOverGridImage = class FOverGridImage extends FBase {
|
|
617
|
-
constructor(_image, _commandService, _injector) {
|
|
722
|
+
constructor(_image, _commandService, _injector, _sheetDrawingService, _sheetSkeletonService) {
|
|
618
723
|
super();
|
|
619
724
|
this._image = _image;
|
|
620
725
|
this._commandService = _commandService;
|
|
621
726
|
this._injector = _injector;
|
|
727
|
+
this._sheetDrawingService = _sheetDrawingService;
|
|
728
|
+
this._sheetSkeletonService = _sheetSkeletonService;
|
|
622
729
|
}
|
|
623
730
|
/**
|
|
624
731
|
* Get the id of the image
|
|
@@ -655,6 +762,78 @@ let FOverGridImage = class FOverGridImage extends FBase {
|
|
|
655
762
|
return this._image.drawingType;
|
|
656
763
|
}
|
|
657
764
|
/**
|
|
765
|
+
* Get this image's explicit placement.
|
|
766
|
+
* @returns {ISheetDrawingPlacement} OneCell, TwoCell, or Absolute placement.
|
|
767
|
+
* @example
|
|
768
|
+
* ```ts
|
|
769
|
+
* const image = univerAPI.getActiveWorkbook().getActiveSheet().getImages()[0];
|
|
770
|
+
* console.log(image.getPlacement());
|
|
771
|
+
* ```
|
|
772
|
+
*/
|
|
773
|
+
getPlacement() {
|
|
774
|
+
return getSheetDrawingPlacement(this._sheetDrawingService.getDrawingByParam({
|
|
775
|
+
unitId: this._image.unitId,
|
|
776
|
+
subUnitId: this._image.subUnitId,
|
|
777
|
+
drawingId: this._image.drawingId
|
|
778
|
+
}) ?? this._image);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Set this image's explicit placement through the drawing command.
|
|
782
|
+
* `Position`, `Both`, and `None` correspond to OneCell, TwoCell, and
|
|
783
|
+
* Absolute. Bounds inference is preferable when preserving the current
|
|
784
|
+
* visual bounds; exact markers are for user-selected cells and offsets.
|
|
785
|
+
* @param {ISheetDrawingPlacementInput} placement Exact placement or bounds with an explicit anchor type.
|
|
786
|
+
* @returns {boolean} `true` when the command succeeds.
|
|
787
|
+
* @example OneCell
|
|
788
|
+
* ```ts
|
|
789
|
+
* const image = univerAPI.getActiveWorkbook().getActiveSheet().getImages()[0];
|
|
790
|
+
* image.setPlacement({
|
|
791
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Position,
|
|
792
|
+
* from: { row: 4, column: 3, rowOffset: 8, columnOffset: 8 },
|
|
793
|
+
* width: 320,
|
|
794
|
+
* height: 180,
|
|
795
|
+
* });
|
|
796
|
+
* ```
|
|
797
|
+
* @example Infer TwoCell markers while preserving current model-space bounds
|
|
798
|
+
* ```ts
|
|
799
|
+
* const image = univerAPI.getActiveWorkbook().getActiveSheet().getImages()[0];
|
|
800
|
+
* image.setPlacement({
|
|
801
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Both,
|
|
802
|
+
* bounds: { left: 120, top: 80, width: 320, height: 160 },
|
|
803
|
+
* });
|
|
804
|
+
* ```
|
|
805
|
+
* @example TwoCell
|
|
806
|
+
* ```ts
|
|
807
|
+
* const image = univerAPI.getActiveWorkbook().getActiveSheet().getImages()[0];
|
|
808
|
+
* image.setPlacement({
|
|
809
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.Both,
|
|
810
|
+
* from: { row: 4, column: 3, rowOffset: 8, columnOffset: 8 },
|
|
811
|
+
* to: { row: 10, column: 8, rowOffset: 0, columnOffset: 0 },
|
|
812
|
+
* });
|
|
813
|
+
* ```
|
|
814
|
+
* @example Absolute
|
|
815
|
+
* ```ts
|
|
816
|
+
* const image = univerAPI.getActiveWorkbook().getActiveSheet().getImages()[0];
|
|
817
|
+
* image.setPlacement({
|
|
818
|
+
* kind: univerAPI.Enum.SheetDrawingAnchorType.None,
|
|
819
|
+
* left: 640,
|
|
820
|
+
* top: 96,
|
|
821
|
+
* width: 320,
|
|
822
|
+
* height: 180,
|
|
823
|
+
* });
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
setPlacement(placement) {
|
|
827
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingPlacementCommand.id, {
|
|
828
|
+
unitId: this._image.unitId,
|
|
829
|
+
subUnitId: this._image.subUnitId,
|
|
830
|
+
drawings: [{
|
|
831
|
+
drawingId: this._image.drawingId,
|
|
832
|
+
placement
|
|
833
|
+
}]
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
658
837
|
* Remove the image from the sheet
|
|
659
838
|
* @returns {boolean} true if the image is removed successfully, otherwise false
|
|
660
839
|
* @example
|
|
@@ -693,7 +872,7 @@ let FOverGridImage = class FOverGridImage extends FBase {
|
|
|
693
872
|
return builder;
|
|
694
873
|
}
|
|
695
874
|
setSource(source, sourceType) {
|
|
696
|
-
const sourceTypeVal = sourceType
|
|
875
|
+
const sourceTypeVal = sourceType ?? ImageSourceType.URL;
|
|
697
876
|
this._image.source = source;
|
|
698
877
|
this._image.imageSourceType = sourceTypeVal;
|
|
699
878
|
return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
|
|
@@ -792,7 +971,7 @@ let FOverGridImage = class FOverGridImage extends FBase {
|
|
|
792
971
|
this._image.sheetTransform.angle = angle;
|
|
793
972
|
this._image.transform && (this._image.transform.angle = angle);
|
|
794
973
|
if (this._image.transform) {
|
|
795
|
-
const skeleton = this.
|
|
974
|
+
const skeleton = this._sheetSkeletonService.getSkeleton(this._image.unitId, this._image.subUnitId);
|
|
796
975
|
if (!skeleton) throw new Error(`Skeleton for unitId ${this._image.unitId} and subUnitId ${this._image.subUnitId} not found`);
|
|
797
976
|
this._image.axisAlignSheetTransform && (this._image.axisAlignSheetTransform = transformToAxisAlignPosition(this._image.transform, skeleton));
|
|
798
977
|
}
|
|
@@ -886,11 +1065,25 @@ let FOverGridImage = class FOverGridImage extends FBase {
|
|
|
886
1065
|
});
|
|
887
1066
|
}
|
|
888
1067
|
};
|
|
889
|
-
FOverGridImage = __decorate([
|
|
1068
|
+
FOverGridImage = __decorate([
|
|
1069
|
+
__decorateParam(1, ICommandService),
|
|
1070
|
+
__decorateParam(2, Inject(Injector)),
|
|
1071
|
+
__decorateParam(3, ISheetDrawingService),
|
|
1072
|
+
__decorateParam(4, Inject(SheetSkeletonService))
|
|
1073
|
+
], FOverGridImage);
|
|
890
1074
|
|
|
891
1075
|
//#endregion
|
|
892
1076
|
//#region src/facade/f-worksheet.ts
|
|
893
1077
|
var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
1078
|
+
get _sheetDrawingService() {
|
|
1079
|
+
return this._injector.get(ISheetDrawingService);
|
|
1080
|
+
}
|
|
1081
|
+
get _sheetSkeletonService() {
|
|
1082
|
+
return this._injector.get(SheetSkeletonService);
|
|
1083
|
+
}
|
|
1084
|
+
get _undoRedoService() {
|
|
1085
|
+
return this._injector.get(IUndoRedoService);
|
|
1086
|
+
}
|
|
894
1087
|
async insertImage(url, column, row, offsetX, offsetY) {
|
|
895
1088
|
const imageBuilder = this.newOverGridImage();
|
|
896
1089
|
if (typeof url === "string") imageBuilder.setSource(url);
|
|
@@ -940,7 +1133,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
940
1133
|
return this;
|
|
941
1134
|
}
|
|
942
1135
|
getImages() {
|
|
943
|
-
const drawingData = this.
|
|
1136
|
+
const drawingData = this._sheetDrawingService.getDrawingData(this._fWorkbook.getId(), this.getSheetId());
|
|
944
1137
|
const images = [];
|
|
945
1138
|
for (const drawingId in drawingData) {
|
|
946
1139
|
const drawing = drawingData[drawingId];
|
|
@@ -950,7 +1143,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
950
1143
|
return images;
|
|
951
1144
|
}
|
|
952
1145
|
getImageById(id) {
|
|
953
|
-
const drawing = this.
|
|
1146
|
+
const drawing = this._sheetDrawingService.getDrawingByParam({
|
|
954
1147
|
unitId: this._fWorkbook.getId(),
|
|
955
1148
|
subUnitId: this.getSheetId(),
|
|
956
1149
|
drawingId: id
|
|
@@ -959,7 +1152,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
959
1152
|
return null;
|
|
960
1153
|
}
|
|
961
1154
|
getActiveImages() {
|
|
962
|
-
const drawingData = this.
|
|
1155
|
+
const drawingData = this._sheetDrawingService.getFocusDrawings();
|
|
963
1156
|
const images = [];
|
|
964
1157
|
for (const drawingId in drawingData) {
|
|
965
1158
|
const drawing = drawingData[drawingId];
|
|
@@ -974,6 +1167,70 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
974
1167
|
});
|
|
975
1168
|
return this;
|
|
976
1169
|
}
|
|
1170
|
+
getDrawingPlacement(drawingId) {
|
|
1171
|
+
const drawing = this._sheetDrawingService.getDrawingByParam({
|
|
1172
|
+
unitId: this._fWorkbook.getId(),
|
|
1173
|
+
subUnitId: this.getSheetId(),
|
|
1174
|
+
drawingId
|
|
1175
|
+
});
|
|
1176
|
+
return drawing ? getSheetDrawingPlacement(drawing) : null;
|
|
1177
|
+
}
|
|
1178
|
+
setDrawingPlacement(drawingId, placement) {
|
|
1179
|
+
return this._commandService.syncExecuteCommand(SetSheetDrawingPlacementCommand.id, {
|
|
1180
|
+
unitId: this._fWorkbook.getId(),
|
|
1181
|
+
subUnitId: this.getSheetId(),
|
|
1182
|
+
drawings: [{
|
|
1183
|
+
drawingId,
|
|
1184
|
+
placement
|
|
1185
|
+
}]
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
resolveDrawingPlacement(placement) {
|
|
1189
|
+
const skeleton = placement.kind === SheetDrawingAnchorType.None ? void 0 : this._sheetSkeletonService.ensureSkeleton(this._fWorkbook.getId(), this.getSheetId());
|
|
1190
|
+
if (placement.kind !== SheetDrawingAnchorType.None && !skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
1191
|
+
return normalizeSheetDrawingPlacement(placement, skeleton);
|
|
1192
|
+
}
|
|
1193
|
+
getDrawingLayout() {
|
|
1194
|
+
const unitId = this._fWorkbook.getId();
|
|
1195
|
+
const subUnitId = this.getSheetId();
|
|
1196
|
+
const skeleton = this._sheetSkeletonService.ensureSkeleton(unitId, subUnitId);
|
|
1197
|
+
if (!skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
1198
|
+
const { startRow, endRow, startColumn, endColumn } = this._worksheet.getDataRealRange();
|
|
1199
|
+
const startCell = skeleton.getCellWithCoordByIndex(startRow, startColumn, false);
|
|
1200
|
+
const endCell = skeleton.getCellWithCoordByIndex(endRow, endColumn, false);
|
|
1201
|
+
const drawingService = this._sheetDrawingService;
|
|
1202
|
+
const drawingData = drawingService.getDrawingData(unitId, subUnitId);
|
|
1203
|
+
const orderedIds = drawingService.getDrawingOrder(unitId, subUnitId);
|
|
1204
|
+
const drawingIds = [...orderedIds, ...Object.keys(drawingData).filter((drawingId) => !orderedIds.includes(drawingId))];
|
|
1205
|
+
const drawings = [];
|
|
1206
|
+
for (const drawingId of drawingIds) {
|
|
1207
|
+
const drawing = drawingData[drawingId];
|
|
1208
|
+
const bounds = drawing && getDrawingBounds(drawing);
|
|
1209
|
+
if (!drawing || !bounds) continue;
|
|
1210
|
+
drawings.push({
|
|
1211
|
+
drawingId,
|
|
1212
|
+
drawingType: drawing.drawingType,
|
|
1213
|
+
bounds,
|
|
1214
|
+
placement: getSheetDrawingPlacement(drawing),
|
|
1215
|
+
groupId: drawing.groupId
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
return {
|
|
1219
|
+
gridBounds: {
|
|
1220
|
+
left: 0,
|
|
1221
|
+
top: 0,
|
|
1222
|
+
width: skeleton.columnTotalWidth,
|
|
1223
|
+
height: skeleton.rowTotalHeight
|
|
1224
|
+
},
|
|
1225
|
+
dataBounds: {
|
|
1226
|
+
left: startCell.startX,
|
|
1227
|
+
top: startCell.startY,
|
|
1228
|
+
width: endCell.endX - startCell.startX,
|
|
1229
|
+
height: endCell.endY - startCell.startY
|
|
1230
|
+
},
|
|
1231
|
+
drawings
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
977
1234
|
newOverGridImage() {
|
|
978
1235
|
const unitId = this._fWorkbook.getId();
|
|
979
1236
|
const subUnitId = this.getSheetId();
|
|
@@ -984,7 +1241,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
984
1241
|
if (uniqueDrawingIds.length < 2) return null;
|
|
985
1242
|
const unitId = this._fWorkbook.getId();
|
|
986
1243
|
const subUnitId = this.getSheetId();
|
|
987
|
-
const sheetDrawingService = this.
|
|
1244
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
988
1245
|
if (sheetDrawingService.getDrawingByParam({
|
|
989
1246
|
unitId,
|
|
990
1247
|
subUnitId,
|
|
@@ -1024,7 +1281,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1024
1281
|
ungroupDrawings(groupIds) {
|
|
1025
1282
|
const unitId = this._fWorkbook.getId();
|
|
1026
1283
|
const subUnitId = this.getSheetId();
|
|
1027
|
-
const sheetDrawingService = this.
|
|
1284
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1028
1285
|
const groupParams = [];
|
|
1029
1286
|
for (const groupId of groupIds) {
|
|
1030
1287
|
const groupDrawing = sheetDrawingService.getDrawingByParam({
|
|
@@ -1062,7 +1319,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1062
1319
|
getDrawingGroupChildren(groupId, recursive = false) {
|
|
1063
1320
|
const unitId = this._fWorkbook.getId();
|
|
1064
1321
|
const subUnitId = this.getSheetId();
|
|
1065
|
-
const sheetDrawingService = this.
|
|
1322
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1066
1323
|
if (!recursive) return sheetDrawingService.getDrawingsByGroup({
|
|
1067
1324
|
unitId,
|
|
1068
1325
|
subUnitId,
|
|
@@ -1079,7 +1336,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1079
1336
|
getDrawingParentGroup(drawingId) {
|
|
1080
1337
|
const unitId = this._fWorkbook.getId();
|
|
1081
1338
|
const subUnitId = this.getSheetId();
|
|
1082
|
-
const sheetDrawingService = this.
|
|
1339
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1083
1340
|
const drawing = sheetDrawingService.getDrawingByParam({
|
|
1084
1341
|
unitId,
|
|
1085
1342
|
subUnitId,
|
|
@@ -1099,9 +1356,9 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1099
1356
|
}
|
|
1100
1357
|
_applyGroupDrawingOperation(groupParams, type) {
|
|
1101
1358
|
if (groupParams.length === 0) return false;
|
|
1102
|
-
const sheetDrawingService = this.
|
|
1359
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1103
1360
|
const commandService = this._commandService;
|
|
1104
|
-
const undoRedoService = this.
|
|
1361
|
+
const undoRedoService = this._undoRedoService;
|
|
1105
1362
|
const { unitId, subUnitId, undo, redo, objects } = type === DrawingApplyType.GROUP ? sheetDrawingService.getGroupDrawingOp(groupParams) : sheetDrawingService.getUngroupDrawingOp(groupParams);
|
|
1106
1363
|
if (commandService.syncExecuteCommand(SetDrawingApplyMutation.id, {
|
|
1107
1364
|
op: redo,
|
|
@@ -1175,6 +1432,16 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1175
1432
|
});
|
|
1176
1433
|
}
|
|
1177
1434
|
};
|
|
1435
|
+
function getDrawingBounds(drawing) {
|
|
1436
|
+
const { left, top, width, height } = drawing.transform ?? {};
|
|
1437
|
+
if (typeof left !== "number" || typeof top !== "number" || typeof width !== "number" || typeof height !== "number" || !Number.isFinite(left) || !Number.isFinite(top) || !Number.isFinite(width) || !Number.isFinite(height)) return null;
|
|
1438
|
+
return {
|
|
1439
|
+
left,
|
|
1440
|
+
top,
|
|
1441
|
+
width,
|
|
1442
|
+
height
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1178
1445
|
FWorksheet.extend(FWorksheetDrawingMixin);
|
|
1179
1446
|
|
|
1180
1447
|
//#endregion
|