@univerjs/sheets-drawing 1.0.0-alpha.8 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +284 -21
- package/lib/cjs/index.js +252 -47
- package/lib/es/facade.js +285 -22
- package/lib/es/index.js +250 -49
- package/lib/facade.js +285 -22
- package/lib/index.js +250 -49
- 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 +129 -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/cjs/facade.js
CHANGED
|
@@ -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: (0, _univerjs_core.generateRandomId)(6),
|
|
140
141
|
drawingType: _univerjs_core.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 ?? _univerjs_core.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 (0, _univerjs_drawing.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) === _univerjs_sheets_drawing.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 (0, _univerjs_sheets_drawing.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 (0, _univerjs_sheets_drawing.applySheetDrawingPlacement)(image, this._placement, skeleton);
|
|
613
718
|
}
|
|
614
719
|
};
|
|
615
|
-
FOverGridImageBuilder = __decorate([__decorateParam(2, (0, _univerjs_core.Inject)(
|
|
720
|
+
FOverGridImageBuilder = __decorate([__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetSkeletonService))], FOverGridImageBuilder);
|
|
616
721
|
let FOverGridImage = class FOverGridImage extends _univerjs_core_facade.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 _univerjs_core_facade.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 (0, _univerjs_sheets_drawing.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(_univerjs_sheets_drawing.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 _univerjs_core_facade.FBase {
|
|
|
693
872
|
return builder;
|
|
694
873
|
}
|
|
695
874
|
setSource(source, sourceType) {
|
|
696
|
-
const sourceTypeVal = sourceType
|
|
875
|
+
const sourceTypeVal = sourceType ?? _univerjs_core.ImageSourceType.URL;
|
|
697
876
|
this._image.source = source;
|
|
698
877
|
this._image.imageSourceType = sourceTypeVal;
|
|
699
878
|
return this._commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
|
|
@@ -792,7 +971,7 @@ let FOverGridImage = class FOverGridImage extends _univerjs_core_facade.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 = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(this._image.transform, skeleton));
|
|
798
977
|
}
|
|
@@ -886,11 +1065,21 @@ let FOverGridImage = class FOverGridImage extends _univerjs_core_facade.FBase {
|
|
|
886
1065
|
});
|
|
887
1066
|
}
|
|
888
1067
|
};
|
|
889
|
-
FOverGridImage = __decorate([
|
|
1068
|
+
FOverGridImage = __decorate([
|
|
1069
|
+
__decorateParam(1, _univerjs_core.ICommandService),
|
|
1070
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1071
|
+
__decorateParam(3, _univerjs_sheets_drawing.ISheetDrawingService),
|
|
1072
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetSkeletonService))
|
|
1073
|
+
], FOverGridImage);
|
|
890
1074
|
|
|
891
1075
|
//#endregion
|
|
892
1076
|
//#region src/facade/f-worksheet.ts
|
|
893
1077
|
var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
1078
|
+
_initialize(injector) {
|
|
1079
|
+
this._sheetDrawingService = injector.get(_univerjs_sheets_drawing.ISheetDrawingService);
|
|
1080
|
+
this._sheetSkeletonService = injector.get(_univerjs_sheets.SheetSkeletonService);
|
|
1081
|
+
this._undoRedoService = injector.get(_univerjs_core.IUndoRedoService);
|
|
1082
|
+
}
|
|
894
1083
|
async insertImage(url, column, row, offsetX, offsetY) {
|
|
895
1084
|
const imageBuilder = this.newOverGridImage();
|
|
896
1085
|
if (typeof url === "string") imageBuilder.setSource(url);
|
|
@@ -940,7 +1129,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
940
1129
|
return this;
|
|
941
1130
|
}
|
|
942
1131
|
getImages() {
|
|
943
|
-
const drawingData = this.
|
|
1132
|
+
const drawingData = this._sheetDrawingService.getDrawingData(this._fWorkbook.getId(), this.getSheetId());
|
|
944
1133
|
const images = [];
|
|
945
1134
|
for (const drawingId in drawingData) {
|
|
946
1135
|
const drawing = drawingData[drawingId];
|
|
@@ -950,7 +1139,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
950
1139
|
return images;
|
|
951
1140
|
}
|
|
952
1141
|
getImageById(id) {
|
|
953
|
-
const drawing = this.
|
|
1142
|
+
const drawing = this._sheetDrawingService.getDrawingByParam({
|
|
954
1143
|
unitId: this._fWorkbook.getId(),
|
|
955
1144
|
subUnitId: this.getSheetId(),
|
|
956
1145
|
drawingId: id
|
|
@@ -959,7 +1148,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
959
1148
|
return null;
|
|
960
1149
|
}
|
|
961
1150
|
getActiveImages() {
|
|
962
|
-
const drawingData = this.
|
|
1151
|
+
const drawingData = this._sheetDrawingService.getFocusDrawings();
|
|
963
1152
|
const images = [];
|
|
964
1153
|
for (const drawingId in drawingData) {
|
|
965
1154
|
const drawing = drawingData[drawingId];
|
|
@@ -974,6 +1163,70 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
974
1163
|
});
|
|
975
1164
|
return this;
|
|
976
1165
|
}
|
|
1166
|
+
getDrawingPlacement(drawingId) {
|
|
1167
|
+
const drawing = this._sheetDrawingService.getDrawingByParam({
|
|
1168
|
+
unitId: this._fWorkbook.getId(),
|
|
1169
|
+
subUnitId: this.getSheetId(),
|
|
1170
|
+
drawingId
|
|
1171
|
+
});
|
|
1172
|
+
return drawing ? (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawing) : null;
|
|
1173
|
+
}
|
|
1174
|
+
setDrawingPlacement(drawingId, placement) {
|
|
1175
|
+
return this._commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingPlacementCommand.id, {
|
|
1176
|
+
unitId: this._fWorkbook.getId(),
|
|
1177
|
+
subUnitId: this.getSheetId(),
|
|
1178
|
+
drawings: [{
|
|
1179
|
+
drawingId,
|
|
1180
|
+
placement
|
|
1181
|
+
}]
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
resolveDrawingPlacement(placement) {
|
|
1185
|
+
const skeleton = placement.kind === _univerjs_sheets_drawing.SheetDrawingAnchorType.None ? void 0 : this._sheetSkeletonService.ensureSkeleton(this._fWorkbook.getId(), this.getSheetId());
|
|
1186
|
+
if (placement.kind !== _univerjs_sheets_drawing.SheetDrawingAnchorType.None && !skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
1187
|
+
return (0, _univerjs_sheets_drawing.normalizeSheetDrawingPlacement)(placement, skeleton);
|
|
1188
|
+
}
|
|
1189
|
+
getDrawingLayout() {
|
|
1190
|
+
const unitId = this._fWorkbook.getId();
|
|
1191
|
+
const subUnitId = this.getSheetId();
|
|
1192
|
+
const skeleton = this._sheetSkeletonService.ensureSkeleton(unitId, subUnitId);
|
|
1193
|
+
if (!skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
1194
|
+
const { startRow, endRow, startColumn, endColumn } = this._worksheet.getDataRealRange();
|
|
1195
|
+
const startCell = skeleton.getCellWithCoordByIndex(startRow, startColumn, false);
|
|
1196
|
+
const endCell = skeleton.getCellWithCoordByIndex(endRow, endColumn, false);
|
|
1197
|
+
const drawingService = this._sheetDrawingService;
|
|
1198
|
+
const drawingData = drawingService.getDrawingData(unitId, subUnitId);
|
|
1199
|
+
const orderedIds = drawingService.getDrawingOrder(unitId, subUnitId);
|
|
1200
|
+
const drawingIds = [...orderedIds, ...Object.keys(drawingData).filter((drawingId) => !orderedIds.includes(drawingId))];
|
|
1201
|
+
const drawings = [];
|
|
1202
|
+
for (const drawingId of drawingIds) {
|
|
1203
|
+
const drawing = drawingData[drawingId];
|
|
1204
|
+
const bounds = drawing && getDrawingBounds(drawing);
|
|
1205
|
+
if (!drawing || !bounds) continue;
|
|
1206
|
+
drawings.push({
|
|
1207
|
+
drawingId,
|
|
1208
|
+
drawingType: drawing.drawingType,
|
|
1209
|
+
bounds,
|
|
1210
|
+
placement: (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawing),
|
|
1211
|
+
groupId: drawing.groupId
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
return {
|
|
1215
|
+
gridBounds: {
|
|
1216
|
+
left: 0,
|
|
1217
|
+
top: 0,
|
|
1218
|
+
width: skeleton.columnTotalWidth,
|
|
1219
|
+
height: skeleton.rowTotalHeight
|
|
1220
|
+
},
|
|
1221
|
+
dataBounds: {
|
|
1222
|
+
left: startCell.startX,
|
|
1223
|
+
top: startCell.startY,
|
|
1224
|
+
width: endCell.endX - startCell.startX,
|
|
1225
|
+
height: endCell.endY - startCell.startY
|
|
1226
|
+
},
|
|
1227
|
+
drawings
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
977
1230
|
newOverGridImage() {
|
|
978
1231
|
const unitId = this._fWorkbook.getId();
|
|
979
1232
|
const subUnitId = this.getSheetId();
|
|
@@ -984,7 +1237,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
984
1237
|
if (uniqueDrawingIds.length < 2) return null;
|
|
985
1238
|
const unitId = this._fWorkbook.getId();
|
|
986
1239
|
const subUnitId = this.getSheetId();
|
|
987
|
-
const sheetDrawingService = this.
|
|
1240
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
988
1241
|
if (sheetDrawingService.getDrawingByParam({
|
|
989
1242
|
unitId,
|
|
990
1243
|
subUnitId,
|
|
@@ -1024,7 +1277,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1024
1277
|
ungroupDrawings(groupIds) {
|
|
1025
1278
|
const unitId = this._fWorkbook.getId();
|
|
1026
1279
|
const subUnitId = this.getSheetId();
|
|
1027
|
-
const sheetDrawingService = this.
|
|
1280
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1028
1281
|
const groupParams = [];
|
|
1029
1282
|
for (const groupId of groupIds) {
|
|
1030
1283
|
const groupDrawing = sheetDrawingService.getDrawingByParam({
|
|
@@ -1062,7 +1315,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1062
1315
|
getDrawingGroupChildren(groupId, recursive = false) {
|
|
1063
1316
|
const unitId = this._fWorkbook.getId();
|
|
1064
1317
|
const subUnitId = this.getSheetId();
|
|
1065
|
-
const sheetDrawingService = this.
|
|
1318
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1066
1319
|
if (!recursive) return sheetDrawingService.getDrawingsByGroup({
|
|
1067
1320
|
unitId,
|
|
1068
1321
|
subUnitId,
|
|
@@ -1079,7 +1332,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1079
1332
|
getDrawingParentGroup(drawingId) {
|
|
1080
1333
|
const unitId = this._fWorkbook.getId();
|
|
1081
1334
|
const subUnitId = this.getSheetId();
|
|
1082
|
-
const sheetDrawingService = this.
|
|
1335
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1083
1336
|
const drawing = sheetDrawingService.getDrawingByParam({
|
|
1084
1337
|
unitId,
|
|
1085
1338
|
subUnitId,
|
|
@@ -1099,9 +1352,9 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1099
1352
|
}
|
|
1100
1353
|
_applyGroupDrawingOperation(groupParams, type) {
|
|
1101
1354
|
if (groupParams.length === 0) return false;
|
|
1102
|
-
const sheetDrawingService = this.
|
|
1355
|
+
const sheetDrawingService = this._sheetDrawingService;
|
|
1103
1356
|
const commandService = this._commandService;
|
|
1104
|
-
const undoRedoService = this.
|
|
1357
|
+
const undoRedoService = this._undoRedoService;
|
|
1105
1358
|
const { unitId, subUnitId, undo, redo, objects } = type === _univerjs_sheets_drawing.DrawingApplyType.GROUP ? sheetDrawingService.getGroupDrawingOp(groupParams) : sheetDrawingService.getUngroupDrawingOp(groupParams);
|
|
1106
1359
|
if (commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetDrawingApplyMutation.id, {
|
|
1107
1360
|
op: redo,
|
|
@@ -1175,6 +1428,16 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1175
1428
|
});
|
|
1176
1429
|
}
|
|
1177
1430
|
};
|
|
1431
|
+
function getDrawingBounds(drawing) {
|
|
1432
|
+
const { left, top, width, height } = drawing.transform ?? {};
|
|
1433
|
+
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;
|
|
1434
|
+
return {
|
|
1435
|
+
left,
|
|
1436
|
+
top,
|
|
1437
|
+
width,
|
|
1438
|
+
height
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1178
1441
|
_univerjs_sheets_facade.FWorksheet.extend(FWorksheetDrawingMixin);
|
|
1179
1442
|
|
|
1180
1443
|
//#endregion
|