@univerjs/sheets-drawing 1.0.0-alpha.1 → 1.0.0-alpha.3
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 +2 -11
- package/lib/cjs/index.js +91 -19
- package/lib/es/facade.js +3 -12
- package/lib/es/index.js +91 -22
- package/lib/facade.js +3 -12
- package/lib/index.js +91 -22
- package/lib/types/common/rotate-enabled.d.ts +20 -0
- package/lib/types/facade/f-enum.d.ts +1 -4
- package/lib/types/facade/f-over-grid-image.d.ts +6 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/facade.js
CHANGED
|
@@ -97,8 +97,7 @@ function convertSheetImageToFOverGridImage(sheetImage, skeleton) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Convert the FOverGridImage to a ISheetImage
|
|
99
99
|
* @param {IFOverGridImage} fOverGridImage The FOverGridImage
|
|
100
|
-
* @param {
|
|
101
|
-
* @param {SheetSkeletonManagerService} sheetSkeletonManagerService The skeleton manager service
|
|
100
|
+
* @param {SheetSkeletonService} sheetSkeletonService The sheet skeleton service
|
|
102
101
|
* @returns {ISheetImage} The ISheetImage {@link ISheetImage}
|
|
103
102
|
*/
|
|
104
103
|
function convertFOverGridImageToSheetImage(fOverGridImage, sheetSkeletonService) {
|
|
@@ -891,11 +890,6 @@ FOverGridImage = __decorate([__decorateParam(1, _univerjs_core.ICommandService),
|
|
|
891
890
|
|
|
892
891
|
//#endregion
|
|
893
892
|
//#region src/facade/f-worksheet.ts
|
|
894
|
-
const GROUPABLE_DRAWING_TYPES = /* @__PURE__ */ new Set([
|
|
895
|
-
_univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
896
|
-
_univerjs_core.DrawingTypeEnum.DRAWING_SHAPE,
|
|
897
|
-
_univerjs_core.DrawingTypeEnum.DRAWING_GROUP
|
|
898
|
-
]);
|
|
899
893
|
var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
900
894
|
async insertImage(url, column, row, offsetX, offsetY) {
|
|
901
895
|
const imageBuilder = this.newOverGridImage();
|
|
@@ -1002,7 +996,7 @@ var FWorksheetDrawingMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
1002
996
|
drawingId
|
|
1003
997
|
}));
|
|
1004
998
|
if (drawings.some((drawing) => !drawing)) return null;
|
|
1005
|
-
if (drawings.some((drawing) => !
|
|
999
|
+
if (drawings.some((drawing) => !(0, _univerjs_drawing.isGroupableDrawingType)(drawing.drawingType))) return null;
|
|
1006
1000
|
const validDrawings = drawings;
|
|
1007
1001
|
const groupTransform = (0, _univerjs_engine_render.getGroupState)(0, 0, validDrawings.map((drawing) => drawing.transform || {}));
|
|
1008
1002
|
const groupParam = {
|
|
@@ -1204,9 +1198,6 @@ var FSheetsDrawingEnumMixin = class extends _univerjs_core_facade.FEnum {
|
|
|
1204
1198
|
get DrawingType() {
|
|
1205
1199
|
return _univerjs_core.DrawingTypeEnum;
|
|
1206
1200
|
}
|
|
1207
|
-
get ImageSourceType() {
|
|
1208
|
-
return _univerjs_core.ImageSourceType;
|
|
1209
|
-
}
|
|
1210
1201
|
get SheetDrawingAnchorType() {
|
|
1211
1202
|
return _univerjs_sheets_drawing.SheetDrawingAnchorType;
|
|
1212
1203
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -228,6 +228,7 @@ const RemoveSheetDrawingCommand = {
|
|
|
228
228
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
229
229
|
const { drawings } = params;
|
|
230
230
|
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
|
|
231
|
+
if (Array.isArray(objects) && objects.length === 0) return false;
|
|
231
232
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
232
233
|
id: RemoveSheetDrawingCommand.id,
|
|
233
234
|
params
|
|
@@ -339,8 +340,61 @@ const SetDrawingArrangeCommand = {
|
|
|
339
340
|
}
|
|
340
341
|
};
|
|
341
342
|
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/common/rotate-enabled.ts
|
|
345
|
+
function isKnownSheetNonRotatableDrawingType(drawingType) {
|
|
346
|
+
return drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART;
|
|
347
|
+
}
|
|
348
|
+
function resolveSheetDrawingRotateEnabled(drawing, drawingService, getChildren) {
|
|
349
|
+
return (0, _univerjs_drawing.resolveDrawingRotateEnabled)(drawing, {
|
|
350
|
+
getChildren: (current) => {
|
|
351
|
+
var _getChildren;
|
|
352
|
+
return (_getChildren = getChildren === null || getChildren === void 0 ? void 0 : getChildren(current)) !== null && _getChildren !== void 0 ? _getChildren : drawingService.getDrawingsByGroup(current);
|
|
353
|
+
},
|
|
354
|
+
isKnownNonRotatableType: isKnownSheetNonRotatableDrawingType
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
342
358
|
//#endregion
|
|
343
359
|
//#region src/commands/commands/set-sheet-drawing.command.ts
|
|
360
|
+
function hasIncomingAngle(drawing) {
|
|
361
|
+
var _drawing$transform, _drawing$sheetTransfo, _drawing$axisAlignShe;
|
|
362
|
+
return ((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.angle) !== void 0 || ((_drawing$sheetTransfo = drawing.sheetTransform) === null || _drawing$sheetTransfo === void 0 ? void 0 : _drawing$sheetTransfo.angle) !== void 0 || ((_drawing$axisAlignShe = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe === void 0 ? void 0 : _drawing$axisAlignShe.angle) !== void 0;
|
|
363
|
+
}
|
|
364
|
+
function preserveAngle(incoming, current) {
|
|
365
|
+
const currentAngle = current === null || current === void 0 ? void 0 : current.angle;
|
|
366
|
+
const next = {
|
|
367
|
+
...current !== null && current !== void 0 ? current : {},
|
|
368
|
+
...incoming
|
|
369
|
+
};
|
|
370
|
+
if (currentAngle === void 0) delete next.angle;
|
|
371
|
+
else next.angle = currentAngle;
|
|
372
|
+
return next;
|
|
373
|
+
}
|
|
374
|
+
function normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService) {
|
|
375
|
+
var _drawing$drawingType, _drawing$transform2, _drawing$sheetTransfo2, _drawing$axisAlignShe2;
|
|
376
|
+
if (!drawing.drawingId || !drawing.unitId || !drawing.subUnitId || !hasIncomingAngle(drawing)) return drawing;
|
|
377
|
+
const current = sheetDrawingService.getDrawingByParam({
|
|
378
|
+
unitId: drawing.unitId,
|
|
379
|
+
subUnitId: drawing.subUnitId,
|
|
380
|
+
drawingId: drawing.drawingId
|
|
381
|
+
});
|
|
382
|
+
if (!current) return drawing;
|
|
383
|
+
if (resolveSheetDrawingRotateEnabled({
|
|
384
|
+
...current,
|
|
385
|
+
...drawing,
|
|
386
|
+
drawingType: (_drawing$drawingType = drawing.drawingType) !== null && _drawing$drawingType !== void 0 ? _drawing$drawingType : current.drawingType,
|
|
387
|
+
transform: {
|
|
388
|
+
...current.transform,
|
|
389
|
+
...drawing.transform
|
|
390
|
+
}
|
|
391
|
+
}, sheetDrawingService)) return drawing;
|
|
392
|
+
const normalized = { ...drawing };
|
|
393
|
+
if (((_drawing$transform2 = drawing.transform) === null || _drawing$transform2 === void 0 ? void 0 : _drawing$transform2.angle) !== void 0) normalized.transform = preserveAngle(drawing.transform, current.transform);
|
|
394
|
+
if (((_drawing$sheetTransfo2 = drawing.sheetTransform) === null || _drawing$sheetTransfo2 === void 0 ? void 0 : _drawing$sheetTransfo2.angle) !== void 0) normalized.sheetTransform = preserveAngle(drawing.sheetTransform, current.sheetTransform);
|
|
395
|
+
if (((_drawing$axisAlignShe2 = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe2 === void 0 ? void 0 : _drawing$axisAlignShe2.angle) !== void 0) normalized.axisAlignSheetTransform = preserveAngle(drawing.axisAlignSheetTransform, current.axisAlignSheetTransform);
|
|
396
|
+
return normalized;
|
|
397
|
+
}
|
|
344
398
|
const SetSheetDrawingCommand = {
|
|
345
399
|
id: "sheet.command.set-sheet-image",
|
|
346
400
|
type: _univerjs_core.CommandType.COMMAND,
|
|
@@ -352,10 +406,15 @@ const SetSheetDrawingCommand = {
|
|
|
352
406
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
353
407
|
const sheetInterceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
|
|
354
408
|
const { drawings } = params;
|
|
355
|
-
const
|
|
409
|
+
const normalizedDrawings = drawings.map((drawing) => normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService));
|
|
410
|
+
const normalizedParams = {
|
|
411
|
+
...params,
|
|
412
|
+
drawings: normalizedDrawings
|
|
413
|
+
};
|
|
414
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(normalizedDrawings);
|
|
356
415
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
357
416
|
id: SetSheetDrawingCommand.id,
|
|
358
|
-
params
|
|
417
|
+
params: normalizedParams
|
|
359
418
|
});
|
|
360
419
|
const redoMutations = [
|
|
361
420
|
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
@@ -425,6 +484,21 @@ function __decorate(decorators, target, key, desc) {
|
|
|
425
484
|
//#endregion
|
|
426
485
|
//#region src/controllers/sheet-drawing.controller.ts
|
|
427
486
|
const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
|
|
487
|
+
function getDrawingsInOrder(drawingData, drawingOrder) {
|
|
488
|
+
const visited = /* @__PURE__ */ new Set();
|
|
489
|
+
const drawings = [];
|
|
490
|
+
drawingOrder.forEach((drawingId) => {
|
|
491
|
+
const drawing = drawingData[drawingId];
|
|
492
|
+
if (drawing) {
|
|
493
|
+
visited.add(drawingId);
|
|
494
|
+
drawings.push(drawing);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
Object.values(drawingData).forEach((drawing) => {
|
|
498
|
+
if (!visited.has(drawing.drawingId)) drawings.push(drawing);
|
|
499
|
+
});
|
|
500
|
+
return drawings;
|
|
501
|
+
}
|
|
428
502
|
let SheetsDrawingLoadController = class SheetsDrawingLoadController extends _univerjs_core.Disposable {
|
|
429
503
|
constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
|
|
430
504
|
super();
|
|
@@ -489,15 +563,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends _uni
|
|
|
489
563
|
undos: []
|
|
490
564
|
};
|
|
491
565
|
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
492
|
-
const drawings = Object.values(drawingData)
|
|
493
|
-
if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART) return false;
|
|
494
|
-
return true;
|
|
495
|
-
});
|
|
566
|
+
const drawings = Object.values(drawingData);
|
|
496
567
|
if (drawings.length === 0) return {
|
|
497
568
|
redos: [],
|
|
498
569
|
undos: []
|
|
499
570
|
};
|
|
500
571
|
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
|
|
572
|
+
if (Array.isArray(objects) && objects.length === 0) return {
|
|
573
|
+
redos: [],
|
|
574
|
+
undos: []
|
|
575
|
+
};
|
|
501
576
|
return {
|
|
502
577
|
redos: [{
|
|
503
578
|
id: SetDrawingApplyMutation.id,
|
|
@@ -521,22 +596,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends _uni
|
|
|
521
596
|
}]
|
|
522
597
|
};
|
|
523
598
|
} else if (commandInfo.id === _univerjs_sheets.CopySheetCommand.id) {
|
|
524
|
-
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
599
|
+
const { unitId, subUnitId, targetSubUnitId, copyContext } = commandInfo.params;
|
|
525
600
|
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
526
601
|
redos: [],
|
|
527
602
|
undos: []
|
|
528
603
|
};
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}).
|
|
534
|
-
return {
|
|
535
|
-
...drawing,
|
|
536
|
-
subUnitId: targetSubUnitId,
|
|
537
|
-
drawingId: (0, _univerjs_core.generateRandomId)(6)
|
|
538
|
-
};
|
|
539
|
-
});
|
|
604
|
+
const drawings = (0, _univerjs_drawing.getOrCreateDrawingCopyPlan)(copyContext, getDrawingsInOrder(this._sheetDrawingService.getDrawingData(unitId, subUnitId), this._sheetDrawingService.getDrawingOrder(unitId, subUnitId)), {
|
|
605
|
+
unitId,
|
|
606
|
+
sourceSubUnitId: subUnitId,
|
|
607
|
+
targetSubUnitId
|
|
608
|
+
}).drawings;
|
|
540
609
|
if (drawings.length === 0) return {
|
|
541
610
|
redos: [],
|
|
542
611
|
undos: []
|
|
@@ -584,7 +653,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
584
653
|
//#endregion
|
|
585
654
|
//#region package.json
|
|
586
655
|
var name = "@univerjs/sheets-drawing";
|
|
587
|
-
var version = "1.0.0-alpha.
|
|
656
|
+
var version = "1.0.0-alpha.3";
|
|
588
657
|
|
|
589
658
|
//#endregion
|
|
590
659
|
//#region src/config/config.ts
|
|
@@ -686,6 +755,7 @@ exports.SetDrawingApplyMutation = SetDrawingApplyMutation;
|
|
|
686
755
|
exports.SetDrawingArrangeCommand = SetDrawingArrangeCommand;
|
|
687
756
|
exports.SetSheetDrawingCommand = SetSheetDrawingCommand;
|
|
688
757
|
exports.SheetDrawingAnchorType = SheetDrawingAnchorType;
|
|
758
|
+
exports.SheetDrawingService = SheetDrawingService;
|
|
689
759
|
Object.defineProperty(exports, 'UniverSheetsDrawingPlugin', {
|
|
690
760
|
enumerable: true,
|
|
691
761
|
get: function () {
|
|
@@ -693,5 +763,7 @@ Object.defineProperty(exports, 'UniverSheetsDrawingPlugin', {
|
|
|
693
763
|
}
|
|
694
764
|
});
|
|
695
765
|
exports.drawingPositionToTransform = drawingPositionToTransform;
|
|
766
|
+
exports.isKnownSheetNonRotatableDrawingType = isKnownSheetNonRotatableDrawingType;
|
|
767
|
+
exports.resolveSheetDrawingRotateEnabled = resolveSheetDrawingRotateEnabled;
|
|
696
768
|
exports.transformToAxisAlignPosition = transformToAxisAlignPosition;
|
|
697
769
|
exports.transformToDrawingPosition = transformToDrawingPosition;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArrangeTypeEnum, CanceledError, DrawingTypeEnum, ICommandService, IUndoRedoService, ImageSourceType, Inject, Injector, generateRandomId } from "@univerjs/core";
|
|
2
2
|
import { FBase, FEnum, FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
|
-
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize } from "@univerjs/drawing";
|
|
3
|
+
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize, isGroupableDrawingType } from "@univerjs/drawing";
|
|
4
4
|
import { SheetSkeletonService, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
5
5
|
import { DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, transformToAxisAlignPosition } from "@univerjs/sheets-drawing";
|
|
6
6
|
import { getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
|
|
@@ -97,8 +97,7 @@ function convertSheetImageToFOverGridImage(sheetImage, skeleton) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Convert the FOverGridImage to a ISheetImage
|
|
99
99
|
* @param {IFOverGridImage} fOverGridImage The FOverGridImage
|
|
100
|
-
* @param {
|
|
101
|
-
* @param {SheetSkeletonManagerService} sheetSkeletonManagerService The skeleton manager service
|
|
100
|
+
* @param {SheetSkeletonService} sheetSkeletonService The sheet skeleton service
|
|
102
101
|
* @returns {ISheetImage} The ISheetImage {@link ISheetImage}
|
|
103
102
|
*/
|
|
104
103
|
function convertFOverGridImageToSheetImage(fOverGridImage, sheetSkeletonService) {
|
|
@@ -891,11 +890,6 @@ FOverGridImage = __decorate([__decorateParam(1, ICommandService), __decoratePara
|
|
|
891
890
|
|
|
892
891
|
//#endregion
|
|
893
892
|
//#region src/facade/f-worksheet.ts
|
|
894
|
-
const GROUPABLE_DRAWING_TYPES = /* @__PURE__ */ new Set([
|
|
895
|
-
DrawingTypeEnum.DRAWING_IMAGE,
|
|
896
|
-
DrawingTypeEnum.DRAWING_SHAPE,
|
|
897
|
-
DrawingTypeEnum.DRAWING_GROUP
|
|
898
|
-
]);
|
|
899
893
|
var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
900
894
|
async insertImage(url, column, row, offsetX, offsetY) {
|
|
901
895
|
const imageBuilder = this.newOverGridImage();
|
|
@@ -1002,7 +996,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1002
996
|
drawingId
|
|
1003
997
|
}));
|
|
1004
998
|
if (drawings.some((drawing) => !drawing)) return null;
|
|
1005
|
-
if (drawings.some((drawing) => !
|
|
999
|
+
if (drawings.some((drawing) => !isGroupableDrawingType(drawing.drawingType))) return null;
|
|
1006
1000
|
const validDrawings = drawings;
|
|
1007
1001
|
const groupTransform = getGroupState(0, 0, validDrawings.map((drawing) => drawing.transform || {}));
|
|
1008
1002
|
const groupParam = {
|
|
@@ -1204,9 +1198,6 @@ var FSheetsDrawingEnumMixin = class extends FEnum {
|
|
|
1204
1198
|
get DrawingType() {
|
|
1205
1199
|
return DrawingTypeEnum;
|
|
1206
1200
|
}
|
|
1207
|
-
get ImageSourceType() {
|
|
1208
|
-
return ImageSourceType;
|
|
1209
|
-
}
|
|
1210
1201
|
get SheetDrawingAnchorType() {
|
|
1211
1202
|
return SheetDrawingAnchorType;
|
|
1212
1203
|
}
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CopySheetCommand, RemoveSheetCommand, SheetInterceptorService, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
2
|
-
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier,
|
|
3
|
-
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
2
|
+
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge, sequenceExecute } from "@univerjs/core";
|
|
3
|
+
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
|
|
4
4
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
5
5
|
|
|
6
6
|
//#region src/basics/transform-position.ts
|
|
@@ -227,6 +227,7 @@ const RemoveSheetDrawingCommand = {
|
|
|
227
227
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
228
228
|
const { drawings } = params;
|
|
229
229
|
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
|
|
230
|
+
if (Array.isArray(objects) && objects.length === 0) return false;
|
|
230
231
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
231
232
|
id: RemoveSheetDrawingCommand.id,
|
|
232
233
|
params
|
|
@@ -338,8 +339,61 @@ const SetDrawingArrangeCommand = {
|
|
|
338
339
|
}
|
|
339
340
|
};
|
|
340
341
|
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/common/rotate-enabled.ts
|
|
344
|
+
function isKnownSheetNonRotatableDrawingType(drawingType) {
|
|
345
|
+
return drawingType === DrawingTypeEnum.DRAWING_CHART;
|
|
346
|
+
}
|
|
347
|
+
function resolveSheetDrawingRotateEnabled(drawing, drawingService, getChildren) {
|
|
348
|
+
return resolveDrawingRotateEnabled(drawing, {
|
|
349
|
+
getChildren: (current) => {
|
|
350
|
+
var _getChildren;
|
|
351
|
+
return (_getChildren = getChildren === null || getChildren === void 0 ? void 0 : getChildren(current)) !== null && _getChildren !== void 0 ? _getChildren : drawingService.getDrawingsByGroup(current);
|
|
352
|
+
},
|
|
353
|
+
isKnownNonRotatableType: isKnownSheetNonRotatableDrawingType
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
341
357
|
//#endregion
|
|
342
358
|
//#region src/commands/commands/set-sheet-drawing.command.ts
|
|
359
|
+
function hasIncomingAngle(drawing) {
|
|
360
|
+
var _drawing$transform, _drawing$sheetTransfo, _drawing$axisAlignShe;
|
|
361
|
+
return ((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.angle) !== void 0 || ((_drawing$sheetTransfo = drawing.sheetTransform) === null || _drawing$sheetTransfo === void 0 ? void 0 : _drawing$sheetTransfo.angle) !== void 0 || ((_drawing$axisAlignShe = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe === void 0 ? void 0 : _drawing$axisAlignShe.angle) !== void 0;
|
|
362
|
+
}
|
|
363
|
+
function preserveAngle(incoming, current) {
|
|
364
|
+
const currentAngle = current === null || current === void 0 ? void 0 : current.angle;
|
|
365
|
+
const next = {
|
|
366
|
+
...current !== null && current !== void 0 ? current : {},
|
|
367
|
+
...incoming
|
|
368
|
+
};
|
|
369
|
+
if (currentAngle === void 0) delete next.angle;
|
|
370
|
+
else next.angle = currentAngle;
|
|
371
|
+
return next;
|
|
372
|
+
}
|
|
373
|
+
function normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService) {
|
|
374
|
+
var _drawing$drawingType, _drawing$transform2, _drawing$sheetTransfo2, _drawing$axisAlignShe2;
|
|
375
|
+
if (!drawing.drawingId || !drawing.unitId || !drawing.subUnitId || !hasIncomingAngle(drawing)) return drawing;
|
|
376
|
+
const current = sheetDrawingService.getDrawingByParam({
|
|
377
|
+
unitId: drawing.unitId,
|
|
378
|
+
subUnitId: drawing.subUnitId,
|
|
379
|
+
drawingId: drawing.drawingId
|
|
380
|
+
});
|
|
381
|
+
if (!current) return drawing;
|
|
382
|
+
if (resolveSheetDrawingRotateEnabled({
|
|
383
|
+
...current,
|
|
384
|
+
...drawing,
|
|
385
|
+
drawingType: (_drawing$drawingType = drawing.drawingType) !== null && _drawing$drawingType !== void 0 ? _drawing$drawingType : current.drawingType,
|
|
386
|
+
transform: {
|
|
387
|
+
...current.transform,
|
|
388
|
+
...drawing.transform
|
|
389
|
+
}
|
|
390
|
+
}, sheetDrawingService)) return drawing;
|
|
391
|
+
const normalized = { ...drawing };
|
|
392
|
+
if (((_drawing$transform2 = drawing.transform) === null || _drawing$transform2 === void 0 ? void 0 : _drawing$transform2.angle) !== void 0) normalized.transform = preserveAngle(drawing.transform, current.transform);
|
|
393
|
+
if (((_drawing$sheetTransfo2 = drawing.sheetTransform) === null || _drawing$sheetTransfo2 === void 0 ? void 0 : _drawing$sheetTransfo2.angle) !== void 0) normalized.sheetTransform = preserveAngle(drawing.sheetTransform, current.sheetTransform);
|
|
394
|
+
if (((_drawing$axisAlignShe2 = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe2 === void 0 ? void 0 : _drawing$axisAlignShe2.angle) !== void 0) normalized.axisAlignSheetTransform = preserveAngle(drawing.axisAlignSheetTransform, current.axisAlignSheetTransform);
|
|
395
|
+
return normalized;
|
|
396
|
+
}
|
|
343
397
|
const SetSheetDrawingCommand = {
|
|
344
398
|
id: "sheet.command.set-sheet-image",
|
|
345
399
|
type: CommandType.COMMAND,
|
|
@@ -351,10 +405,15 @@ const SetSheetDrawingCommand = {
|
|
|
351
405
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
352
406
|
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
353
407
|
const { drawings } = params;
|
|
354
|
-
const
|
|
408
|
+
const normalizedDrawings = drawings.map((drawing) => normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService));
|
|
409
|
+
const normalizedParams = {
|
|
410
|
+
...params,
|
|
411
|
+
drawings: normalizedDrawings
|
|
412
|
+
};
|
|
413
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(normalizedDrawings);
|
|
355
414
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
356
415
|
id: SetSheetDrawingCommand.id,
|
|
357
|
-
params
|
|
416
|
+
params: normalizedParams
|
|
358
417
|
});
|
|
359
418
|
const redoMutations = [
|
|
360
419
|
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
@@ -424,6 +483,21 @@ function __decorate(decorators, target, key, desc) {
|
|
|
424
483
|
//#endregion
|
|
425
484
|
//#region src/controllers/sheet-drawing.controller.ts
|
|
426
485
|
const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
|
|
486
|
+
function getDrawingsInOrder(drawingData, drawingOrder) {
|
|
487
|
+
const visited = /* @__PURE__ */ new Set();
|
|
488
|
+
const drawings = [];
|
|
489
|
+
drawingOrder.forEach((drawingId) => {
|
|
490
|
+
const drawing = drawingData[drawingId];
|
|
491
|
+
if (drawing) {
|
|
492
|
+
visited.add(drawingId);
|
|
493
|
+
drawings.push(drawing);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
Object.values(drawingData).forEach((drawing) => {
|
|
497
|
+
if (!visited.has(drawing.drawingId)) drawings.push(drawing);
|
|
498
|
+
});
|
|
499
|
+
return drawings;
|
|
500
|
+
}
|
|
427
501
|
let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disposable {
|
|
428
502
|
constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
|
|
429
503
|
super();
|
|
@@ -488,15 +562,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disp
|
|
|
488
562
|
undos: []
|
|
489
563
|
};
|
|
490
564
|
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
491
|
-
const drawings = Object.values(drawingData)
|
|
492
|
-
if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
|
|
493
|
-
return true;
|
|
494
|
-
});
|
|
565
|
+
const drawings = Object.values(drawingData);
|
|
495
566
|
if (drawings.length === 0) return {
|
|
496
567
|
redos: [],
|
|
497
568
|
undos: []
|
|
498
569
|
};
|
|
499
570
|
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
|
|
571
|
+
if (Array.isArray(objects) && objects.length === 0) return {
|
|
572
|
+
redos: [],
|
|
573
|
+
undos: []
|
|
574
|
+
};
|
|
500
575
|
return {
|
|
501
576
|
redos: [{
|
|
502
577
|
id: SetDrawingApplyMutation.id,
|
|
@@ -520,22 +595,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disp
|
|
|
520
595
|
}]
|
|
521
596
|
};
|
|
522
597
|
} else if (commandInfo.id === CopySheetCommand.id) {
|
|
523
|
-
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
598
|
+
const { unitId, subUnitId, targetSubUnitId, copyContext } = commandInfo.params;
|
|
524
599
|
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
525
600
|
redos: [],
|
|
526
601
|
undos: []
|
|
527
602
|
};
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}).
|
|
533
|
-
return {
|
|
534
|
-
...drawing,
|
|
535
|
-
subUnitId: targetSubUnitId,
|
|
536
|
-
drawingId: generateRandomId(6)
|
|
537
|
-
};
|
|
538
|
-
});
|
|
603
|
+
const drawings = getOrCreateDrawingCopyPlan(copyContext, getDrawingsInOrder(this._sheetDrawingService.getDrawingData(unitId, subUnitId), this._sheetDrawingService.getDrawingOrder(unitId, subUnitId)), {
|
|
604
|
+
unitId,
|
|
605
|
+
sourceSubUnitId: subUnitId,
|
|
606
|
+
targetSubUnitId
|
|
607
|
+
}).drawings;
|
|
539
608
|
if (drawings.length === 0) return {
|
|
540
609
|
redos: [],
|
|
541
610
|
undos: []
|
|
@@ -583,7 +652,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
583
652
|
//#endregion
|
|
584
653
|
//#region package.json
|
|
585
654
|
var name = "@univerjs/sheets-drawing";
|
|
586
|
-
var version = "1.0.0-alpha.
|
|
655
|
+
var version = "1.0.0-alpha.3";
|
|
587
656
|
|
|
588
657
|
//#endregion
|
|
589
658
|
//#region src/config/config.ts
|
|
@@ -675,4 +744,4 @@ UniverSheetsDrawingPlugin = __decorate([
|
|
|
675
744
|
], UniverSheetsDrawingPlugin);
|
|
676
745
|
|
|
677
746
|
//#endregion
|
|
678
|
-
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
747
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, SheetDrawingService, UniverSheetsDrawingPlugin, drawingPositionToTransform, isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
package/lib/facade.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArrangeTypeEnum, CanceledError, DrawingTypeEnum, ICommandService, IUndoRedoService, ImageSourceType, Inject, Injector, generateRandomId } from "@univerjs/core";
|
|
2
2
|
import { FBase, FEnum, FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
|
-
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize } from "@univerjs/drawing";
|
|
3
|
+
import { IDrawingManagerService, SetDrawingSelectedOperation, getImageSize, isGroupableDrawingType } from "@univerjs/drawing";
|
|
4
4
|
import { SheetSkeletonService, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
5
5
|
import { DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, transformToAxisAlignPosition } from "@univerjs/sheets-drawing";
|
|
6
6
|
import { getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
|
|
@@ -97,8 +97,7 @@ function convertSheetImageToFOverGridImage(sheetImage, skeleton) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Convert the FOverGridImage to a ISheetImage
|
|
99
99
|
* @param {IFOverGridImage} fOverGridImage The FOverGridImage
|
|
100
|
-
* @param {
|
|
101
|
-
* @param {SheetSkeletonManagerService} sheetSkeletonManagerService The skeleton manager service
|
|
100
|
+
* @param {SheetSkeletonService} sheetSkeletonService The sheet skeleton service
|
|
102
101
|
* @returns {ISheetImage} The ISheetImage {@link ISheetImage}
|
|
103
102
|
*/
|
|
104
103
|
function convertFOverGridImageToSheetImage(fOverGridImage, sheetSkeletonService) {
|
|
@@ -891,11 +890,6 @@ FOverGridImage = __decorate([__decorateParam(1, ICommandService), __decoratePara
|
|
|
891
890
|
|
|
892
891
|
//#endregion
|
|
893
892
|
//#region src/facade/f-worksheet.ts
|
|
894
|
-
const GROUPABLE_DRAWING_TYPES = /* @__PURE__ */ new Set([
|
|
895
|
-
DrawingTypeEnum.DRAWING_IMAGE,
|
|
896
|
-
DrawingTypeEnum.DRAWING_SHAPE,
|
|
897
|
-
DrawingTypeEnum.DRAWING_GROUP
|
|
898
|
-
]);
|
|
899
893
|
var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
900
894
|
async insertImage(url, column, row, offsetX, offsetY) {
|
|
901
895
|
const imageBuilder = this.newOverGridImage();
|
|
@@ -1002,7 +996,7 @@ var FWorksheetDrawingMixin = class extends FWorksheet {
|
|
|
1002
996
|
drawingId
|
|
1003
997
|
}));
|
|
1004
998
|
if (drawings.some((drawing) => !drawing)) return null;
|
|
1005
|
-
if (drawings.some((drawing) => !
|
|
999
|
+
if (drawings.some((drawing) => !isGroupableDrawingType(drawing.drawingType))) return null;
|
|
1006
1000
|
const validDrawings = drawings;
|
|
1007
1001
|
const groupTransform = getGroupState(0, 0, validDrawings.map((drawing) => drawing.transform || {}));
|
|
1008
1002
|
const groupParam = {
|
|
@@ -1204,9 +1198,6 @@ var FSheetsDrawingEnumMixin = class extends FEnum {
|
|
|
1204
1198
|
get DrawingType() {
|
|
1205
1199
|
return DrawingTypeEnum;
|
|
1206
1200
|
}
|
|
1207
|
-
get ImageSourceType() {
|
|
1208
|
-
return ImageSourceType;
|
|
1209
|
-
}
|
|
1210
1201
|
get SheetDrawingAnchorType() {
|
|
1211
1202
|
return SheetDrawingAnchorType;
|
|
1212
1203
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CopySheetCommand, RemoveSheetCommand, SheetInterceptorService, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
|
|
2
|
-
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier,
|
|
3
|
-
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
2
|
+
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge, sequenceExecute } from "@univerjs/core";
|
|
3
|
+
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
|
|
4
4
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
5
5
|
|
|
6
6
|
//#region src/basics/transform-position.ts
|
|
@@ -227,6 +227,7 @@ const RemoveSheetDrawingCommand = {
|
|
|
227
227
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
228
228
|
const { drawings } = params;
|
|
229
229
|
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
|
|
230
|
+
if (Array.isArray(objects) && objects.length === 0) return false;
|
|
230
231
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
231
232
|
id: RemoveSheetDrawingCommand.id,
|
|
232
233
|
params
|
|
@@ -338,8 +339,61 @@ const SetDrawingArrangeCommand = {
|
|
|
338
339
|
}
|
|
339
340
|
};
|
|
340
341
|
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/common/rotate-enabled.ts
|
|
344
|
+
function isKnownSheetNonRotatableDrawingType(drawingType) {
|
|
345
|
+
return drawingType === DrawingTypeEnum.DRAWING_CHART;
|
|
346
|
+
}
|
|
347
|
+
function resolveSheetDrawingRotateEnabled(drawing, drawingService, getChildren) {
|
|
348
|
+
return resolveDrawingRotateEnabled(drawing, {
|
|
349
|
+
getChildren: (current) => {
|
|
350
|
+
var _getChildren;
|
|
351
|
+
return (_getChildren = getChildren === null || getChildren === void 0 ? void 0 : getChildren(current)) !== null && _getChildren !== void 0 ? _getChildren : drawingService.getDrawingsByGroup(current);
|
|
352
|
+
},
|
|
353
|
+
isKnownNonRotatableType: isKnownSheetNonRotatableDrawingType
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
341
357
|
//#endregion
|
|
342
358
|
//#region src/commands/commands/set-sheet-drawing.command.ts
|
|
359
|
+
function hasIncomingAngle(drawing) {
|
|
360
|
+
var _drawing$transform, _drawing$sheetTransfo, _drawing$axisAlignShe;
|
|
361
|
+
return ((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.angle) !== void 0 || ((_drawing$sheetTransfo = drawing.sheetTransform) === null || _drawing$sheetTransfo === void 0 ? void 0 : _drawing$sheetTransfo.angle) !== void 0 || ((_drawing$axisAlignShe = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe === void 0 ? void 0 : _drawing$axisAlignShe.angle) !== void 0;
|
|
362
|
+
}
|
|
363
|
+
function preserveAngle(incoming, current) {
|
|
364
|
+
const currentAngle = current === null || current === void 0 ? void 0 : current.angle;
|
|
365
|
+
const next = {
|
|
366
|
+
...current !== null && current !== void 0 ? current : {},
|
|
367
|
+
...incoming
|
|
368
|
+
};
|
|
369
|
+
if (currentAngle === void 0) delete next.angle;
|
|
370
|
+
else next.angle = currentAngle;
|
|
371
|
+
return next;
|
|
372
|
+
}
|
|
373
|
+
function normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService) {
|
|
374
|
+
var _drawing$drawingType, _drawing$transform2, _drawing$sheetTransfo2, _drawing$axisAlignShe2;
|
|
375
|
+
if (!drawing.drawingId || !drawing.unitId || !drawing.subUnitId || !hasIncomingAngle(drawing)) return drawing;
|
|
376
|
+
const current = sheetDrawingService.getDrawingByParam({
|
|
377
|
+
unitId: drawing.unitId,
|
|
378
|
+
subUnitId: drawing.subUnitId,
|
|
379
|
+
drawingId: drawing.drawingId
|
|
380
|
+
});
|
|
381
|
+
if (!current) return drawing;
|
|
382
|
+
if (resolveSheetDrawingRotateEnabled({
|
|
383
|
+
...current,
|
|
384
|
+
...drawing,
|
|
385
|
+
drawingType: (_drawing$drawingType = drawing.drawingType) !== null && _drawing$drawingType !== void 0 ? _drawing$drawingType : current.drawingType,
|
|
386
|
+
transform: {
|
|
387
|
+
...current.transform,
|
|
388
|
+
...drawing.transform
|
|
389
|
+
}
|
|
390
|
+
}, sheetDrawingService)) return drawing;
|
|
391
|
+
const normalized = { ...drawing };
|
|
392
|
+
if (((_drawing$transform2 = drawing.transform) === null || _drawing$transform2 === void 0 ? void 0 : _drawing$transform2.angle) !== void 0) normalized.transform = preserveAngle(drawing.transform, current.transform);
|
|
393
|
+
if (((_drawing$sheetTransfo2 = drawing.sheetTransform) === null || _drawing$sheetTransfo2 === void 0 ? void 0 : _drawing$sheetTransfo2.angle) !== void 0) normalized.sheetTransform = preserveAngle(drawing.sheetTransform, current.sheetTransform);
|
|
394
|
+
if (((_drawing$axisAlignShe2 = drawing.axisAlignSheetTransform) === null || _drawing$axisAlignShe2 === void 0 ? void 0 : _drawing$axisAlignShe2.angle) !== void 0) normalized.axisAlignSheetTransform = preserveAngle(drawing.axisAlignSheetTransform, current.axisAlignSheetTransform);
|
|
395
|
+
return normalized;
|
|
396
|
+
}
|
|
343
397
|
const SetSheetDrawingCommand = {
|
|
344
398
|
id: "sheet.command.set-sheet-image",
|
|
345
399
|
type: CommandType.COMMAND,
|
|
@@ -351,10 +405,15 @@ const SetSheetDrawingCommand = {
|
|
|
351
405
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
352
406
|
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
353
407
|
const { drawings } = params;
|
|
354
|
-
const
|
|
408
|
+
const normalizedDrawings = drawings.map((drawing) => normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService));
|
|
409
|
+
const normalizedParams = {
|
|
410
|
+
...params,
|
|
411
|
+
drawings: normalizedDrawings
|
|
412
|
+
};
|
|
413
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(normalizedDrawings);
|
|
355
414
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
356
415
|
id: SetSheetDrawingCommand.id,
|
|
357
|
-
params
|
|
416
|
+
params: normalizedParams
|
|
358
417
|
});
|
|
359
418
|
const redoMutations = [
|
|
360
419
|
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
@@ -424,6 +483,21 @@ function __decorate(decorators, target, key, desc) {
|
|
|
424
483
|
//#endregion
|
|
425
484
|
//#region src/controllers/sheet-drawing.controller.ts
|
|
426
485
|
const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
|
|
486
|
+
function getDrawingsInOrder(drawingData, drawingOrder) {
|
|
487
|
+
const visited = /* @__PURE__ */ new Set();
|
|
488
|
+
const drawings = [];
|
|
489
|
+
drawingOrder.forEach((drawingId) => {
|
|
490
|
+
const drawing = drawingData[drawingId];
|
|
491
|
+
if (drawing) {
|
|
492
|
+
visited.add(drawingId);
|
|
493
|
+
drawings.push(drawing);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
Object.values(drawingData).forEach((drawing) => {
|
|
497
|
+
if (!visited.has(drawing.drawingId)) drawings.push(drawing);
|
|
498
|
+
});
|
|
499
|
+
return drawings;
|
|
500
|
+
}
|
|
427
501
|
let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disposable {
|
|
428
502
|
constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
|
|
429
503
|
super();
|
|
@@ -488,15 +562,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disp
|
|
|
488
562
|
undos: []
|
|
489
563
|
};
|
|
490
564
|
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
491
|
-
const drawings = Object.values(drawingData)
|
|
492
|
-
if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
|
|
493
|
-
return true;
|
|
494
|
-
});
|
|
565
|
+
const drawings = Object.values(drawingData);
|
|
495
566
|
if (drawings.length === 0) return {
|
|
496
567
|
redos: [],
|
|
497
568
|
undos: []
|
|
498
569
|
};
|
|
499
570
|
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
|
|
571
|
+
if (Array.isArray(objects) && objects.length === 0) return {
|
|
572
|
+
redos: [],
|
|
573
|
+
undos: []
|
|
574
|
+
};
|
|
500
575
|
return {
|
|
501
576
|
redos: [{
|
|
502
577
|
id: SetDrawingApplyMutation.id,
|
|
@@ -520,22 +595,16 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disp
|
|
|
520
595
|
}]
|
|
521
596
|
};
|
|
522
597
|
} else if (commandInfo.id === CopySheetCommand.id) {
|
|
523
|
-
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
598
|
+
const { unitId, subUnitId, targetSubUnitId, copyContext } = commandInfo.params;
|
|
524
599
|
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
525
600
|
redos: [],
|
|
526
601
|
undos: []
|
|
527
602
|
};
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}).
|
|
533
|
-
return {
|
|
534
|
-
...drawing,
|
|
535
|
-
subUnitId: targetSubUnitId,
|
|
536
|
-
drawingId: generateRandomId(6)
|
|
537
|
-
};
|
|
538
|
-
});
|
|
603
|
+
const drawings = getOrCreateDrawingCopyPlan(copyContext, getDrawingsInOrder(this._sheetDrawingService.getDrawingData(unitId, subUnitId), this._sheetDrawingService.getDrawingOrder(unitId, subUnitId)), {
|
|
604
|
+
unitId,
|
|
605
|
+
sourceSubUnitId: subUnitId,
|
|
606
|
+
targetSubUnitId
|
|
607
|
+
}).drawings;
|
|
539
608
|
if (drawings.length === 0) return {
|
|
540
609
|
redos: [],
|
|
541
610
|
undos: []
|
|
@@ -583,7 +652,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
583
652
|
//#endregion
|
|
584
653
|
//#region package.json
|
|
585
654
|
var name = "@univerjs/sheets-drawing";
|
|
586
|
-
var version = "1.0.0-alpha.
|
|
655
|
+
var version = "1.0.0-alpha.3";
|
|
587
656
|
|
|
588
657
|
//#endregion
|
|
589
658
|
//#region src/config/config.ts
|
|
@@ -675,4 +744,4 @@ UniverSheetsDrawingPlugin = __decorate([
|
|
|
675
744
|
], UniverSheetsDrawingPlugin);
|
|
676
745
|
|
|
677
746
|
//#endregion
|
|
678
|
-
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
747
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, SheetDrawingService, UniverSheetsDrawingPlugin, drawingPositionToTransform, isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DrawingType, IDrawingParam } from '@univerjs/core';
|
|
17
|
+
import type { IUnitDrawingService } from '@univerjs/drawing';
|
|
18
|
+
import type { ISheetDrawing } from '../services/sheet-drawing.service';
|
|
19
|
+
export declare function isKnownSheetNonRotatableDrawingType(drawingType: DrawingType): boolean;
|
|
20
|
+
export declare function resolveSheetDrawingRotateEnabled(drawing: IDrawingParam, drawingService: Pick<IUnitDrawingService<ISheetDrawing>, 'getDrawingsByGroup'>, getChildren?: (drawing: IDrawingParam) => readonly IDrawingParam[] | null | undefined): boolean;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { DrawingTypeEnum
|
|
16
|
+
import { DrawingTypeEnum } from '@univerjs/core';
|
|
17
17
|
import { FEnum } from '@univerjs/core/facade';
|
|
18
18
|
import { SheetDrawingAnchorType } from '@univerjs/sheets-drawing';
|
|
19
19
|
/**
|
|
@@ -22,14 +22,11 @@ import { SheetDrawingAnchorType } from '@univerjs/sheets-drawing';
|
|
|
22
22
|
export interface IFSheetsDrawingEnumMixin {
|
|
23
23
|
/** Please refer to {@link DrawingTypeEnum}. */
|
|
24
24
|
DrawingType: typeof DrawingTypeEnum;
|
|
25
|
-
/** Please refer to {@link ImageSourceType}. */
|
|
26
|
-
ImageSourceType: Omit<typeof ImageSourceType, 'UUID'>;
|
|
27
25
|
/** Please refer to {@link SheetDrawingAnchorType}. */
|
|
28
26
|
SheetDrawingAnchorType: typeof SheetDrawingAnchorType;
|
|
29
27
|
}
|
|
30
28
|
export declare class FSheetsDrawingEnumMixin extends FEnum implements IFSheetsDrawingEnumMixin {
|
|
31
29
|
get DrawingType(): typeof DrawingTypeEnum;
|
|
32
|
-
get ImageSourceType(): Omit<typeof ImageSourceType, 'UUID'>;
|
|
33
30
|
get SheetDrawingAnchorType(): typeof SheetDrawingAnchorType;
|
|
34
31
|
}
|
|
35
32
|
declare module '@univerjs/core/facade' {
|
|
@@ -54,6 +54,12 @@ export declare class FOverGridImageBuilder {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
setImage(image: ISheetImage): FOverGridImageBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Set the source of the image. The source type defaults to URL.
|
|
59
|
+
* @param {string} source - The source of the image
|
|
60
|
+
* @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
|
|
61
|
+
*/
|
|
62
|
+
setSource(source: string): FOverGridImageBuilder;
|
|
57
63
|
/**
|
|
58
64
|
* Set the source of the image.
|
|
59
65
|
* @param {string} source - The source of the image
|
|
@@ -74,7 +80,6 @@ export declare class FOverGridImageBuilder {
|
|
|
74
80
|
* fWorksheet.insertImages([image]);
|
|
75
81
|
* ```
|
|
76
82
|
*/
|
|
77
|
-
setSource(source: string): FOverGridImageBuilder;
|
|
78
83
|
setSource(source: string, sourceType?: ImageSourceType): FOverGridImageBuilder;
|
|
79
84
|
/**
|
|
80
85
|
* Get the source of the image
|
package/lib/types/index.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ export type { ISetDrawingCommandParams } from './commands/commands/set-sheet-dra
|
|
|
25
25
|
export { DrawingApplyType, SetDrawingApplyMutation } from './commands/mutations/set-drawing-apply.mutation';
|
|
26
26
|
export type { ISetDrawingApplyMutationParams } from './commands/mutations/set-drawing-apply.mutation';
|
|
27
27
|
export { ClearSheetDrawingTransformerOperation } from './commands/operations/clear-drawing-transformer.operation';
|
|
28
|
+
export { isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled } from './common/rotate-enabled';
|
|
28
29
|
export type { IUniverSheetsDrawingConfig } from './config/config';
|
|
29
30
|
export { SHEET_DRAWING_PLUGIN } from './controllers/sheet-drawing.controller';
|
|
30
31
|
export { UniverSheetsDrawingPlugin } from './plugin';
|
|
31
|
-
export { ISheetDrawingService, SheetDrawingAnchorType } from './services/sheet-drawing.service';
|
|
32
|
+
export { ISheetDrawingService, SheetDrawingAnchorType, SheetDrawingService } from './services/sheet-drawing.service';
|
|
32
33
|
export type { IFloatDomData, ISheetDrawing, ISheetDrawingPosition, ISheetFloatDom, ISheetImage, ISheetShape, } from './services/sheet-drawing.service';
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets/facade")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/sheets/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverCoreFacade,e.UniverDrawing,e.UniverSheets,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverSheetsFacade))})(this,function(e,t,n,r,i,a,o){function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function p(e,t){let{from:n,to:i,flipY:a=!1,flipX:o=!1,angle:s=0,skewX:c=0,skewY:l=0}=e.sheetTransform,{column:u,columnOffset:d,row:f,rowOffset:p}=n,{width:m,height:h}=(0,r.convertPositionSheetOverGridToAbsolute)(e.unitId,e.subUnitId,{from:n,to:i},t);return{...e,column:u,columnOffset:d,row:f,rowOffset:p,width:m,height:h,flipY:a,flipX:o,angle:s,skewX:c,skewY:l}}function m(e,t){let n=t.ensureSkeleton(e.unitId,e.subUnitId);if(!n)throw Error(`Skeleton for unitId ${e.unitId} and subUnitId ${e.subUnitId} not found`);let{column:a,columnOffset:o,row:s,rowOffset:c,flipY:l=!1,flipX:u=!1,angle:d=0,skewX:f=0,skewY:p=0,width:m,height:h}=e,{sheetTransform:g,transform:_}=(0,r.convertPositionCellToSheetOverGrid)(e.unitId,e.subUnitId,{column:a,columnOffset:o,row:s,rowOffset:c},m,h,n);return{...e,sheetTransform:{...g,flipY:l,flipX:u,angle:d,skewX:f,skewY:p},transform:{..._,flipY:l,flipX:u,angle:d,skewX:f,skewY:p},axisAlignSheetTransform:(0,i.transformToAxisAlignPosition)(_,n)}}let h=class{constructor(t,n,r){this._injector=r,u(this,`_image`,void 0),this._image={drawingId:(0,e.generateRandomId)(6),drawingType:e.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:e.ImageSourceType.BASE64,source:``,unitId:t,subUnitId:n,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0,axisAlignSheetTransform:{from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}}}setImage(e){let{unitId:t,subUnitId:n}=e,i=this._injector.get(r.SheetSkeletonService).getSkeleton(t,n);if(!i)throw Error(`Skeleton for unitId ${t} and subUnitId ${n} not found`);return e.sheetTransform==null&&(e.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),e.axisAlignSheetTransform==null&&(e.axisAlignSheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=p(e,i),this}setSource(t,n){let r=n==null?e.ImageSourceType.URL:n;return this._image.source=t,this._image.imageSourceType=r,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(e){return this._image.column=e,this}setRow(e){return this._image.row=e,this}setColumnOffset(e){return this._image.columnOffset=e,this}setRowOffset(e){return this._image.rowOffset=e,this}setWidth(e){return this._image.width=e,this}setHeight(e){return this._image.height=e,this}setAnchorType(e){return this._image.anchorType=e,this}setCropTop(e){return this._initializeSrcRect(),this._image.srcRect.top=e,this}setCropLeft(e){return this._initializeSrcRect(),this._image.srcRect.left=e,this}setCropBottom(e){return this._initializeSrcRect(),this._image.srcRect.bottom=e,this}setCropRight(e){return this._initializeSrcRect(),this._image.srcRect.right=e,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(e){return this._image.angle=e,this}setUnitId(e){return this._image.unitId=e,this}setSubUnitId(e){return this._image.subUnitId=e,this}async buildAsync(){let e=this._injector.get(r.SheetSkeletonService);if(this._image.width===0||this._image.height===0){let e=await(0,n.getImageSize)(this._image.source),t=e.width,r=e.height;this._image.width===0&&(this._image.width=t),this._image.height===0&&(this._image.height=r)}return m(this._image,e)}};h=f([d(2,(0,e.Inject)(e.Injector))],h);let g=class extends t.FBase{constructor(e,t,n){super(),this._image=e,this._commandService=t,this._injector=n}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(i.RemoveSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){let e=this._injector.createInstance(h,this._image.unitId,this._image.subUnitId);return e.setImage(this._image),e}setSource(t,n){let r=n==null?e.ImageSourceType.URL:n;return this._image.source=t,this._image.imageSourceType=r,this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(e,t,n,r){let a=this.toBuilder();a.setColumn(t),a.setRow(e),n!=null&&a.setRowOffset(n),r!=null&&a.setColumnOffset(r);let o=await a.buildAsync();return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[o]})}async setSizeAsync(e,t){let n=this.toBuilder();n.setWidth(e),n.setHeight(t);let r=await n.buildAsync();return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[r]})}setCrop(e,t,n,r){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),e!=null&&(this._image.srcRect.top=e),t!=null&&(this._image.srcRect.left=t),n!=null&&(this._image.srcRect.bottom=n),r!=null&&(this._image.srcRect.right=r),this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(e){if(this._image.sheetTransform.angle=e,this._image.transform&&(this._image.transform.angle=e),this._image.transform){let e=this._injector.get(r.SheetSkeletonService).getSkeleton(this._image.unitId,this._image.subUnitId);if(!e)throw Error(`Skeleton for unitId ${this._image.unitId} and subUnitId ${this._image.subUnitId} not found`);this._image.axisAlignSheetTransform&&(this._image.axisAlignSheetTransform=(0,i.transformToAxisAlignPosition)(this._image.transform,e))}return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.forward})}setBackward(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.backward})}setBack(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.back})}setFront(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.front})}};g=f([d(1,e.ICommandService),d(2,(0,e.Inject)(e.Injector))],g);let _=new Set([e.DrawingTypeEnum.DRAWING_IMAGE,e.DrawingTypeEnum.DRAWING_SHAPE,e.DrawingTypeEnum.DRAWING_GROUP]);var v=class extends o.FWorksheet{async insertImage(t,n,r,a,o){let s=this.newOverGridImage();if(typeof t==`string`)s.setSource(t);else{let n=await t.getBlob().getDataAsString();s.setSource(n,e.ImageSourceType.BASE64)}n===void 0?s.setColumn(0):s.setColumn(n),r===void 0?s.setRow(0):s.setRow(r),a===void 0?s.setColumnOffset(0):s.setColumnOffset(a),o===void 0?s.setRowOffset(0):s.setRowOffset(o);let c=await s.buildAsync();return this._commandService.syncExecuteCommand(i.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[c]})}insertImages(e){let t=e.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(i.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(e){let t=e.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(i.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){let t=this._injector.get(i.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),n=[];for(let r in t){let i=t[r];i.drawingType===e.DrawingTypeEnum.DRAWING_IMAGE&&n.push(this._injector.createInstance(g,i))}return n}getImageById(t){let n=this._injector.get(i.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:t});return n&&n.drawingType===e.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(g,n):null}getActiveImages(){let e=this._injector.get(i.ISheetDrawingService).getFocusDrawings(),t=[];for(let n in e){let r=e[n];t.push(this._injector.createInstance(g,r))}return t}updateImages(e){return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}newOverGridImage(){let e=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(h,e,t)}groupDrawings(t,n=(0,e.generateRandomId)(10)){let r=Array.from(new Set(t));if(r.length<2)return null;let o=this._fWorkbook.getId(),s=this.getSheetId(),c=this._injector.get(i.ISheetDrawingService);if(c.getDrawingByParam({unitId:o,subUnitId:s,drawingId:n}))return null;let l=r.map(e=>c.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e}));if(l.some(e=>!e)||l.some(e=>!_.has(e.drawingType)))return null;let u=l,d=(0,a.getGroupState)(0,0,u.map(e=>e.transform||{})),f={unitId:o,subUnitId:s,drawingId:n,drawingType:e.DrawingTypeEnum.DRAWING_GROUP,transform:d,groupBaseBound:{left:d.left,top:d.top,width:d.width,height:d.height}},p=u.map(e=>({...e,groupId:n}));return this._applyGroupDrawingOperation([{parent:f,children:p}],i.DrawingApplyType.GROUP)?n:null}ungroupDrawings(t){let n=this._fWorkbook.getId(),r=this.getSheetId(),o=this._injector.get(i.ISheetDrawingService),s=[];for(let i of t){let t=o.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i});if(!t||t.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP)continue;let c=t.transform||{width:0,height:0},l=o.getDrawingsByGroup({unitId:n,subUnitId:r,drawingId:i}).map(e=>{let n=(0,a.transformObjectOutOfGroup)(e.transform||{},c,c.width||0,c.height||0,t.groupBaseBound);return{...e,transform:{...e.transform,...n},groupId:void 0}});l.length>0&&s.push({parent:t,children:l})}return this._applyGroupDrawingOperation(s,i.DrawingApplyType.UNGROUP)}getDrawingGroupChildren(e,t=!1){let n=this._fWorkbook.getId(),r=this.getSheetId(),a=this._injector.get(i.ISheetDrawingService);if(!t)return a.getDrawingsByGroup({unitId:n,subUnitId:r,drawingId:e});let o=a.getDrawingsByGroupNested({unitId:n,subUnitId:r,drawingId:e});return o?[...o.flatChildren||[],...o.groups.filter(t=>t.drawingId!==e)]:[]}getDrawingParentGroup(t){let n=this._fWorkbook.getId(),r=this.getSheetId(),a=this._injector.get(i.ISheetDrawingService),o=a.getDrawingByParam({unitId:n,subUnitId:r,drawingId:t});if(!(o!=null&&o.groupId))return null;let s=a.getDrawingByParam({unitId:n,subUnitId:r,drawingId:o.groupId});return!s||s.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP?null:s}isDrawingGrouped(e){return this.getDrawingParentGroup(e)!==null}_applyGroupDrawingOperation(t,n){if(t.length===0)return!1;let r=this._injector.get(i.ISheetDrawingService),a=this._commandService,o=this._injector.get(e.IUndoRedoService),{unitId:s,subUnitId:c,undo:l,redo:u,objects:d}=n===i.DrawingApplyType.GROUP?r.getGroupDrawingOp(t):r.getUngroupDrawingOp(t);if(a.syncExecuteCommand(i.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:n})){let e=n===i.DrawingApplyType.GROUP?i.DrawingApplyType.UNGROUP:i.DrawingApplyType.GROUP;return o.pushUndoRedo({unitID:s,undoMutations:[{id:i.SetDrawingApplyMutation.id,params:{op:l,unitId:s,subUnitId:c,objects:this._invertGroupOperationObjects(d,n),type:e}}],redoMutations:[{id:i.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:n}}]}),!0}return!1}_invertGroupOperationObjects(e,t){return t===i.DrawingApplyType.GROUP?e.map(e=>{let{parent:t,children:n}=e,r=t.transform||{width:0,height:0};return{parent:{...t,transform:{left:0,top:0}},children:n.map(e=>({...e,transform:(0,a.transformObjectOutOfGroup)(e.transform||{},r,r.width||0,r.height||0,t.groupBaseBound),groupId:void 0}))}}):e.map(e=>{let{parent:t,children:n}=e,r=(0,a.getGroupState)(0,0,n.map(e=>e.transform||{}));return{parent:{...t,transform:r},children:n.map(e=>({...e,groupId:t.drawingId}))}})}};o.FWorksheet.extend(v);var y=class extends t.FEnum{get DrawingType(){return e.DrawingTypeEnum}get ImageSourceType(){return e.ImageSourceType}get SheetDrawingAnchorType(){return i.SheetDrawingAnchorType}};t.FEnum.extend(y);var b=class extends t.FEventName{get BeforeFloatDomAdd(){return`BeforeFloatDomAdd`}get FloatDomAdded(){return`FloatDomAdded`}get BeforeFloatDomUpdate(){return`BeforeFloatDomUpdate`}get FloatDomUpdated(){return`FloatDomUpdated`}get BeforeFloatDomDelete(){return`BeforeFloatDomDelete`}get FloatDomDeleted(){return`FloatDomDeleted`}get BeforeOverGridImageChange(){return`BeforeOverGridImageChange`}get OverGridImageChanged(){return`OverGridImageChanged`}get BeforeOverGridImageInsert(){return`BeforeOverGridImageInsert`}get OverGridImageInserted(){return`OverGridImageInserted`}get BeforeOverGridImageRemove(){return`BeforeOverGridImageRemove`}get OverGridImageRemoved(){return`OverGridImageRemoved`}get BeforeOverGridImageSelect(){return`BeforeOverGridImageSelect`}get OverGridImageSelected(){return`OverGridImageSelected`}};t.FEventName.extend(b);var x=class extends t.FUniver{_initialize(t){let r=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>r.beforeCommandExecuted(t=>{if(t.id!==i.InsertSheetDrawingCommand.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:a}=n,o={workbook:r,insertImageParams:a};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,o),o.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>r.beforeCommandExecuted(r=>{if(r.id!==i.RemoveSheetDrawingCommand.id)return;let a=r.params,o=this.getActiveWorkbook();if(o==null||a==null)return;let s=t.get(n.IDrawingManagerService),{drawings:c}=a,l=c.map(e=>s.getDrawingByParam(e)),u={workbook:o,images:this._createFOverGridImage(l)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,u),u.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>r.beforeCommandExecuted(r=>{if(r.id!==i.SetSheetDrawingCommand.id)return;let a=r.params,o=this.getActiveWorkbook();if(o==null||a==null)return;let{drawings:s}=a,c=t.get(n.IDrawingManagerService),l=[];s.forEach(e=>{let t=c.getDrawingByParam(e);t!=null&&l.push({changeParam:e,image:this._injector.createInstance(g,t)})});let u={workbook:o,images:l};if(this.fireEvent(this.Event.BeforeOverGridImageChange,u),u.cancel)throw c.updateNotification(s),new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>r.beforeCommandExecuted(r=>{if(r.id!==n.SetDrawingSelectedOperation.id)return;let i=r.params,a=this.getActiveWorkbook();if(a==null)return;let o=t.get(n.IDrawingManagerService),s=o.getFocusDrawings(),c=i.map(e=>o.getDrawingByParam(e)),l={workbook:a,selectedImages:this._createFOverGridImage(c),oldSelectedImages:this._createFOverGridImage(s)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>r.onCommandExecuted(e=>{if(e.id!==i.InsertSheetDrawingCommand.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,a={workbook:n,images:this._createFOverGridImage(r)};this.fireEvent(this.Event.OverGridImageInserted,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>r.onCommandExecuted(e=>{if(e.id!==i.RemoveSheetDrawingCommand.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,a={workbook:n,removeImageParams:r};this.fireEvent(this.Event.OverGridImageRemoved,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>r.onCommandExecuted(e=>{if(e.id!==i.SetSheetDrawingCommand.id)return;let r=e.params,a=this.getActiveWorkbook();if(a==null||r==null)return;let{drawings:o}=r,s=t.get(n.IDrawingManagerService),c={workbook:a,images:o.map(e=>this._injector.createInstance(g,s.getDrawingByParam(e)))};this.fireEvent(this.Event.OverGridImageChanged,c)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>r.onCommandExecuted(e=>{if(e.id!==n.SetDrawingSelectedOperation.id)return;let r=e.params,i=this.getActiveWorkbook();if(i==null)return;let a=t.get(n.IDrawingManagerService),o=r.map(e=>a.getDrawingByParam(e)),s={workbook:i,selectedImages:this._createFOverGridImage(o)};this.fireEvent(this.Event.OverGridImageSelected,s)})))}_createFOverGridImage(e){return e.map(e=>this._injector.createInstance(g,e))}};t.FUniver.extend(x)});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets/facade")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/sheets/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverCoreFacade,e.UniverDrawing,e.UniverSheets,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverSheetsFacade))})(this,function(e,t,n,r,i,a,o){function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function p(e,t){let{from:n,to:i,flipY:a=!1,flipX:o=!1,angle:s=0,skewX:c=0,skewY:l=0}=e.sheetTransform,{column:u,columnOffset:d,row:f,rowOffset:p}=n,{width:m,height:h}=(0,r.convertPositionSheetOverGridToAbsolute)(e.unitId,e.subUnitId,{from:n,to:i},t);return{...e,column:u,columnOffset:d,row:f,rowOffset:p,width:m,height:h,flipY:a,flipX:o,angle:s,skewX:c,skewY:l}}function m(e,t){let n=t.ensureSkeleton(e.unitId,e.subUnitId);if(!n)throw Error(`Skeleton for unitId ${e.unitId} and subUnitId ${e.subUnitId} not found`);let{column:a,columnOffset:o,row:s,rowOffset:c,flipY:l=!1,flipX:u=!1,angle:d=0,skewX:f=0,skewY:p=0,width:m,height:h}=e,{sheetTransform:g,transform:_}=(0,r.convertPositionCellToSheetOverGrid)(e.unitId,e.subUnitId,{column:a,columnOffset:o,row:s,rowOffset:c},m,h,n);return{...e,sheetTransform:{...g,flipY:l,flipX:u,angle:d,skewX:f,skewY:p},transform:{..._,flipY:l,flipX:u,angle:d,skewX:f,skewY:p},axisAlignSheetTransform:(0,i.transformToAxisAlignPosition)(_,n)}}let h=class{constructor(t,n,r){this._injector=r,u(this,`_image`,void 0),this._image={drawingId:(0,e.generateRandomId)(6),drawingType:e.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:e.ImageSourceType.BASE64,source:``,unitId:t,subUnitId:n,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0,axisAlignSheetTransform:{from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}}}setImage(e){let{unitId:t,subUnitId:n}=e,i=this._injector.get(r.SheetSkeletonService).getSkeleton(t,n);if(!i)throw Error(`Skeleton for unitId ${t} and subUnitId ${n} not found`);return e.sheetTransform==null&&(e.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),e.axisAlignSheetTransform==null&&(e.axisAlignSheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=p(e,i),this}setSource(t,n){let r=n==null?e.ImageSourceType.URL:n;return this._image.source=t,this._image.imageSourceType=r,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(e){return this._image.column=e,this}setRow(e){return this._image.row=e,this}setColumnOffset(e){return this._image.columnOffset=e,this}setRowOffset(e){return this._image.rowOffset=e,this}setWidth(e){return this._image.width=e,this}setHeight(e){return this._image.height=e,this}setAnchorType(e){return this._image.anchorType=e,this}setCropTop(e){return this._initializeSrcRect(),this._image.srcRect.top=e,this}setCropLeft(e){return this._initializeSrcRect(),this._image.srcRect.left=e,this}setCropBottom(e){return this._initializeSrcRect(),this._image.srcRect.bottom=e,this}setCropRight(e){return this._initializeSrcRect(),this._image.srcRect.right=e,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(e){return this._image.angle=e,this}setUnitId(e){return this._image.unitId=e,this}setSubUnitId(e){return this._image.subUnitId=e,this}async buildAsync(){let e=this._injector.get(r.SheetSkeletonService);if(this._image.width===0||this._image.height===0){let e=await(0,n.getImageSize)(this._image.source),t=e.width,r=e.height;this._image.width===0&&(this._image.width=t),this._image.height===0&&(this._image.height=r)}return m(this._image,e)}};h=f([d(2,(0,e.Inject)(e.Injector))],h);let g=class extends t.FBase{constructor(e,t,n){super(),this._image=e,this._commandService=t,this._injector=n}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(i.RemoveSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){let e=this._injector.createInstance(h,this._image.unitId,this._image.subUnitId);return e.setImage(this._image),e}setSource(t,n){let r=n==null?e.ImageSourceType.URL:n;return this._image.source=t,this._image.imageSourceType=r,this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(e,t,n,r){let a=this.toBuilder();a.setColumn(t),a.setRow(e),n!=null&&a.setRowOffset(n),r!=null&&a.setColumnOffset(r);let o=await a.buildAsync();return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[o]})}async setSizeAsync(e,t){let n=this.toBuilder();n.setWidth(e),n.setHeight(t);let r=await n.buildAsync();return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[r]})}setCrop(e,t,n,r){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),e!=null&&(this._image.srcRect.top=e),t!=null&&(this._image.srcRect.left=t),n!=null&&(this._image.srcRect.bottom=n),r!=null&&(this._image.srcRect.right=r),this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(e){if(this._image.sheetTransform.angle=e,this._image.transform&&(this._image.transform.angle=e),this._image.transform){let e=this._injector.get(r.SheetSkeletonService).getSkeleton(this._image.unitId,this._image.subUnitId);if(!e)throw Error(`Skeleton for unitId ${this._image.unitId} and subUnitId ${this._image.subUnitId} not found`);this._image.axisAlignSheetTransform&&(this._image.axisAlignSheetTransform=(0,i.transformToAxisAlignPosition)(this._image.transform,e))}return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.forward})}setBackward(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.backward})}setBack(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.back})}setFront(){return this._commandService.syncExecuteCommand(i.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.ArrangeTypeEnum.front})}};g=f([d(1,e.ICommandService),d(2,(0,e.Inject)(e.Injector))],g);var _=class extends o.FWorksheet{async insertImage(t,n,r,a,o){let s=this.newOverGridImage();if(typeof t==`string`)s.setSource(t);else{let n=await t.getBlob().getDataAsString();s.setSource(n,e.ImageSourceType.BASE64)}n===void 0?s.setColumn(0):s.setColumn(n),r===void 0?s.setRow(0):s.setRow(r),a===void 0?s.setColumnOffset(0):s.setColumnOffset(a),o===void 0?s.setRowOffset(0):s.setRowOffset(o);let c=await s.buildAsync();return this._commandService.syncExecuteCommand(i.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[c]})}insertImages(e){let t=e.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(i.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(e){let t=e.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(i.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){let t=this._injector.get(i.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),n=[];for(let r in t){let i=t[r];i.drawingType===e.DrawingTypeEnum.DRAWING_IMAGE&&n.push(this._injector.createInstance(g,i))}return n}getImageById(t){let n=this._injector.get(i.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:t});return n&&n.drawingType===e.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(g,n):null}getActiveImages(){let e=this._injector.get(i.ISheetDrawingService).getFocusDrawings(),t=[];for(let n in e){let r=e[n];t.push(this._injector.createInstance(g,r))}return t}updateImages(e){return this._commandService.syncExecuteCommand(i.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}newOverGridImage(){let e=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(h,e,t)}groupDrawings(t,r=(0,e.generateRandomId)(10)){let o=Array.from(new Set(t));if(o.length<2)return null;let s=this._fWorkbook.getId(),c=this.getSheetId(),l=this._injector.get(i.ISheetDrawingService);if(l.getDrawingByParam({unitId:s,subUnitId:c,drawingId:r}))return null;let u=o.map(e=>l.getDrawingByParam({unitId:s,subUnitId:c,drawingId:e}));if(u.some(e=>!e)||u.some(e=>!(0,n.isGroupableDrawingType)(e.drawingType)))return null;let d=u,f=(0,a.getGroupState)(0,0,d.map(e=>e.transform||{})),p={unitId:s,subUnitId:c,drawingId:r,drawingType:e.DrawingTypeEnum.DRAWING_GROUP,transform:f,groupBaseBound:{left:f.left,top:f.top,width:f.width,height:f.height}},m=d.map(e=>({...e,groupId:r}));return this._applyGroupDrawingOperation([{parent:p,children:m}],i.DrawingApplyType.GROUP)?r:null}ungroupDrawings(t){let n=this._fWorkbook.getId(),r=this.getSheetId(),o=this._injector.get(i.ISheetDrawingService),s=[];for(let i of t){let t=o.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i});if(!t||t.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP)continue;let c=t.transform||{width:0,height:0},l=o.getDrawingsByGroup({unitId:n,subUnitId:r,drawingId:i}).map(e=>{let n=(0,a.transformObjectOutOfGroup)(e.transform||{},c,c.width||0,c.height||0,t.groupBaseBound);return{...e,transform:{...e.transform,...n},groupId:void 0}});l.length>0&&s.push({parent:t,children:l})}return this._applyGroupDrawingOperation(s,i.DrawingApplyType.UNGROUP)}getDrawingGroupChildren(e,t=!1){let n=this._fWorkbook.getId(),r=this.getSheetId(),a=this._injector.get(i.ISheetDrawingService);if(!t)return a.getDrawingsByGroup({unitId:n,subUnitId:r,drawingId:e});let o=a.getDrawingsByGroupNested({unitId:n,subUnitId:r,drawingId:e});return o?[...o.flatChildren||[],...o.groups.filter(t=>t.drawingId!==e)]:[]}getDrawingParentGroup(t){let n=this._fWorkbook.getId(),r=this.getSheetId(),a=this._injector.get(i.ISheetDrawingService),o=a.getDrawingByParam({unitId:n,subUnitId:r,drawingId:t});if(!(o!=null&&o.groupId))return null;let s=a.getDrawingByParam({unitId:n,subUnitId:r,drawingId:o.groupId});return!s||s.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP?null:s}isDrawingGrouped(e){return this.getDrawingParentGroup(e)!==null}_applyGroupDrawingOperation(t,n){if(t.length===0)return!1;let r=this._injector.get(i.ISheetDrawingService),a=this._commandService,o=this._injector.get(e.IUndoRedoService),{unitId:s,subUnitId:c,undo:l,redo:u,objects:d}=n===i.DrawingApplyType.GROUP?r.getGroupDrawingOp(t):r.getUngroupDrawingOp(t);if(a.syncExecuteCommand(i.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:n})){let e=n===i.DrawingApplyType.GROUP?i.DrawingApplyType.UNGROUP:i.DrawingApplyType.GROUP;return o.pushUndoRedo({unitID:s,undoMutations:[{id:i.SetDrawingApplyMutation.id,params:{op:l,unitId:s,subUnitId:c,objects:this._invertGroupOperationObjects(d,n),type:e}}],redoMutations:[{id:i.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:n}}]}),!0}return!1}_invertGroupOperationObjects(e,t){return t===i.DrawingApplyType.GROUP?e.map(e=>{let{parent:t,children:n}=e,r=t.transform||{width:0,height:0};return{parent:{...t,transform:{left:0,top:0}},children:n.map(e=>({...e,transform:(0,a.transformObjectOutOfGroup)(e.transform||{},r,r.width||0,r.height||0,t.groupBaseBound),groupId:void 0}))}}):e.map(e=>{let{parent:t,children:n}=e,r=(0,a.getGroupState)(0,0,n.map(e=>e.transform||{}));return{parent:{...t,transform:r},children:n.map(e=>({...e,groupId:t.drawingId}))}})}};o.FWorksheet.extend(_);var v=class extends t.FEnum{get DrawingType(){return e.DrawingTypeEnum}get SheetDrawingAnchorType(){return i.SheetDrawingAnchorType}};t.FEnum.extend(v);var y=class extends t.FEventName{get BeforeFloatDomAdd(){return`BeforeFloatDomAdd`}get FloatDomAdded(){return`FloatDomAdded`}get BeforeFloatDomUpdate(){return`BeforeFloatDomUpdate`}get FloatDomUpdated(){return`FloatDomUpdated`}get BeforeFloatDomDelete(){return`BeforeFloatDomDelete`}get FloatDomDeleted(){return`FloatDomDeleted`}get BeforeOverGridImageChange(){return`BeforeOverGridImageChange`}get OverGridImageChanged(){return`OverGridImageChanged`}get BeforeOverGridImageInsert(){return`BeforeOverGridImageInsert`}get OverGridImageInserted(){return`OverGridImageInserted`}get BeforeOverGridImageRemove(){return`BeforeOverGridImageRemove`}get OverGridImageRemoved(){return`OverGridImageRemoved`}get BeforeOverGridImageSelect(){return`BeforeOverGridImageSelect`}get OverGridImageSelected(){return`OverGridImageSelected`}};t.FEventName.extend(y);var b=class extends t.FUniver{_initialize(t){let r=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>r.beforeCommandExecuted(t=>{if(t.id!==i.InsertSheetDrawingCommand.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:a}=n,o={workbook:r,insertImageParams:a};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,o),o.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>r.beforeCommandExecuted(r=>{if(r.id!==i.RemoveSheetDrawingCommand.id)return;let a=r.params,o=this.getActiveWorkbook();if(o==null||a==null)return;let s=t.get(n.IDrawingManagerService),{drawings:c}=a,l=c.map(e=>s.getDrawingByParam(e)),u={workbook:o,images:this._createFOverGridImage(l)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,u),u.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>r.beforeCommandExecuted(r=>{if(r.id!==i.SetSheetDrawingCommand.id)return;let a=r.params,o=this.getActiveWorkbook();if(o==null||a==null)return;let{drawings:s}=a,c=t.get(n.IDrawingManagerService),l=[];s.forEach(e=>{let t=c.getDrawingByParam(e);t!=null&&l.push({changeParam:e,image:this._injector.createInstance(g,t)})});let u={workbook:o,images:l};if(this.fireEvent(this.Event.BeforeOverGridImageChange,u),u.cancel)throw c.updateNotification(s),new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>r.beforeCommandExecuted(r=>{if(r.id!==n.SetDrawingSelectedOperation.id)return;let i=r.params,a=this.getActiveWorkbook();if(a==null)return;let o=t.get(n.IDrawingManagerService),s=o.getFocusDrawings(),c=i.map(e=>o.getDrawingByParam(e)),l={workbook:a,selectedImages:this._createFOverGridImage(c),oldSelectedImages:this._createFOverGridImage(s)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>r.onCommandExecuted(e=>{if(e.id!==i.InsertSheetDrawingCommand.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,a={workbook:n,images:this._createFOverGridImage(r)};this.fireEvent(this.Event.OverGridImageInserted,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>r.onCommandExecuted(e=>{if(e.id!==i.RemoveSheetDrawingCommand.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t,a={workbook:n,removeImageParams:r};this.fireEvent(this.Event.OverGridImageRemoved,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>r.onCommandExecuted(e=>{if(e.id!==i.SetSheetDrawingCommand.id)return;let r=e.params,a=this.getActiveWorkbook();if(a==null||r==null)return;let{drawings:o}=r,s=t.get(n.IDrawingManagerService),c={workbook:a,images:o.map(e=>this._injector.createInstance(g,s.getDrawingByParam(e)))};this.fireEvent(this.Event.OverGridImageChanged,c)}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>r.onCommandExecuted(e=>{if(e.id!==n.SetDrawingSelectedOperation.id)return;let r=e.params,i=this.getActiveWorkbook();if(i==null)return;let a=t.get(n.IDrawingManagerService),o=r.map(e=>a.getDrawingByParam(e)),s={workbook:i,selectedImages:this._createFOverGridImage(o)};this.fireEvent(this.Event.OverGridImageSelected,s)})))}_createFOverGridImage(e){return e.map(e=>this._injector.createInstance(g,e))}};t.FUniver.extend(b)});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/sheets"),require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/sheets`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawing={},e.UniverSheets,e.UniverCore,e.UniverDrawing,e.UniverEngineRender))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=(0,t.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function s(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:s=0}=e,c=(s%360+360)%360;return o(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let c=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var l=class extends r.UnitDrawingService{};let u=(0,n.createIdentifier)(`sheets-drawing.sheet-drawing.service`),d=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({}),f={id:`sheet.mutation.set-drawing-apply`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IDrawingManagerService),i=e.get(u),{op:a,unitId:o,subUnitId:s,type:c,objects:l}=t;switch(n.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case 0:n.addNotification(l),i.addNotification(l);break;case 1:n.removeNotification(l),i.removeNotification(l);break;case 2:n.updateNotification(l),i.updateNotification(l);break;case 3:n.orderNotification(l),i.orderNotification(l);break;case 4:n.groupUpdateNotification(l),i.groupUpdateNotification(l);break;case 5:n.ungroupUpdateNotification(l),i.ungroupUpdateNotification(l);break}return!0}},p={id:`sheet.operation.clear-drawing-transformer`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(i.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},m={id:`sheet.command.insert-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),d=r.drawings,{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchAddOp(d),b=l.onCommandExecute({id:m.id,params:r}),x=[...(i=b.preRedos)==null?[]:i,{id:f.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:0}},{id:p.id,params:[h]},...b.redos],S=[...(a=b.preUndos)==null?[]:a,{id:f.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:1}},{id:p.id,params:[h]},...b.undos];return(0,n.sequenceExecute)(x,o).result?(s.pushUndoRedo({unitID:h,undoMutations:S,redoMutations:x}),!0):!1}},h={id:`sheet.command.remove-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(t.SheetInterceptorService),l=e.get(u),{drawings:d}=r,{unitId:m,subUnitId:g,undo:_,redo:v,objects:y}=l.getBatchRemoveOp(d),b=c.onCommandExecute({id:h.id,params:r}),x=[...(i=b.preRedos)==null?[]:i,{id:f.id,params:{unitId:m,subUnitId:g,op:v,objects:y,type:1}},{id:p.id,params:[m]},...b.redos],S=[...(a=b.preUndos)==null?[]:a,{id:f.id,params:{unitId:m,subUnitId:g,op:_,objects:y,type:0}},{id:p.id,params:[m]},...b.undos];return(0,n.sequenceExecute)(x,o).result?(s.pushUndoRedo({unitID:m,undoMutations:S,redoMutations:x}),!0):!1}},g={id:`sheet.command.set-drawing-arrange`,type:n.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ICommandService),i=e.get(n.IUndoRedoService);if(!t)return!1;let a=e.get(u),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:l}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(l===n.ArrangeTypeEnum.forward?p=a.getForwardDrawingsOp(d):l===n.ArrangeTypeEnum.backward?p=a.getBackwardDrawingOp(d):l===n.ArrangeTypeEnum.front?p=a.getFrontDrawingsOp(d):l===n.ArrangeTypeEnum.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return r.syncExecuteCommand(f.id,{op:h,unitId:o,subUnitId:s,objects:m,type:3})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:f.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:3}}],redoMutations:[{id:f.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:3}}]}),!0):!1}},_={id:`sheet.command.set-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),{drawings:d}=r,{unitId:m,subUnitId:h,undo:g,redo:v,objects:y}=c.getBatchUpdateOp(d),b=l.onCommandExecute({id:_.id,params:r}),x=[...(i=b.preRedos)==null?[]:i,{id:f.id,params:{unitId:m,subUnitId:h,op:v,objects:y,type:2}},{id:p.id,params:[m]},...b.redos],S=[...(a=b.preUndos)==null?[]:a,{id:f.id,params:{unitId:m,subUnitId:h,op:g,objects:y,type:2}},{id:p.id,params:[m]},...b.undos];return(0,n.sequenceExecute)(x,o).result?(s.pushUndoRedo({unitID:m,undoMutations:S,redoMutations:x}),!0):!1}};function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=`SHEET_DRAWING_PLUGIN`,x=class extends n.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(f))}_initCommands(){[_,m,h,g,p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:b,businesses:[n.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===t.RemoveSheetCommand.id){var r;let t=e.params,i=t.unitId||this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=t.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:u,redo:d,objects:p}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:f.id,params:{op:d,unitId:c,subUnitId:l,objects:p,type:1}}],undos:[{id:f.id,params:{op:u,unitId:c,subUnitId:l,objects:p,type:0}}]}}else if(e.id===t.CopySheetCommand.id){let{unitId:t,subUnitId:r,targetSubUnitId:i}=e.params;if(!t||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,r),o=Object.values(a).filter(e=>e.drawingType!==n.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,n.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:f.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:0}}],undos:[{id:f.id,params:{op:l,unitId:s,subUnitId:c,objects:d,type:1}}]}}return{redos:[],undos:[]}}}))}};x=y([v(0,(0,n.Inject)(t.SheetInterceptorService)),v(1,(0,n.Inject)(n.IUniverInstanceService)),v(2,n.ICommandService),v(3,u),v(4,r.IDrawingManagerService),v(5,n.IResourceManagerService)],x);var S=`@univerjs/sheets-drawing`,C=`1.0.0-alpha.1`;let w={};function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=class extends n.Plugin{constructor(e=w,t,r){super(),this._config=e,this._injector=t,this._configService=r;let{...i}=(0,n.merge)({},w,this._config);this._configService.setConfig(`sheets-drawing.config`,i)}onStarting(){[[x],[u,{useClass:l}]].forEach(e=>this._injector.add(e)),this._injector.get(x)}};O(k,`pluginName`,b),O(k,`packageName`,S),O(k,`version`,C),O(k,`type`,n.UniverInstanceType.UNIVER_SHEET),k=y([(0,n.DependentOn)(r.UniverDrawingPlugin),v(1,(0,n.Inject)(n.Injector)),v(2,n.IConfigService)],k),e.ClearSheetDrawingTransformerOperation=p,e.DrawingApplyType=d,e.ISheetDrawingService=u,e.InsertSheetDrawingCommand=m,e.RemoveSheetDrawingCommand=h,e.SHEET_DRAWING_PLUGIN=b,e.SetDrawingApplyMutation=f,e.SetDrawingArrangeCommand=g,e.SetSheetDrawingCommand=_,e.SheetDrawingAnchorType=c,Object.defineProperty(e,"UniverSheetsDrawingPlugin",{enumerable:!0,get:function(){return k}}),e.drawingPositionToTransform=a,e.transformToAxisAlignPosition=s,e.transformToDrawingPosition=o});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/sheets"),require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/sheets`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawing={},e.UniverSheets,e.UniverCore,e.UniverDrawing,e.UniverEngineRender))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=(0,t.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function s(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:s=0}=e,c=(s%360+360)%360;return o(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let c=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var l=class extends r.UnitDrawingService{};let u=(0,n.createIdentifier)(`sheets-drawing.sheet-drawing.service`),d=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({}),f={id:`sheet.mutation.set-drawing-apply`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IDrawingManagerService),i=e.get(u),{op:a,unitId:o,subUnitId:s,type:c,objects:l}=t;switch(n.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case 0:n.addNotification(l),i.addNotification(l);break;case 1:n.removeNotification(l),i.removeNotification(l);break;case 2:n.updateNotification(l),i.updateNotification(l);break;case 3:n.orderNotification(l),i.orderNotification(l);break;case 4:n.groupUpdateNotification(l),i.groupUpdateNotification(l);break;case 5:n.ungroupUpdateNotification(l),i.ungroupUpdateNotification(l);break}return!0}},p={id:`sheet.operation.clear-drawing-transformer`,type:n.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(i.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},m={id:`sheet.command.insert-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),d=r.drawings,{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchAddOp(d),b=l.onCommandExecute({id:m.id,params:r}),x=[...(i=b.preRedos)==null?[]:i,{id:f.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:0}},{id:p.id,params:[h]},...b.redos],S=[...(a=b.preUndos)==null?[]:a,{id:f.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:1}},{id:p.id,params:[h]},...b.undos];return(0,n.sequenceExecute)(x,o).result?(s.pushUndoRedo({unitID:h,undoMutations:S,redoMutations:x}),!0):!1}},h={id:`sheet.command.remove-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(t.SheetInterceptorService),l=e.get(u),{drawings:d}=r,{unitId:m,subUnitId:g,undo:_,redo:v,objects:y}=l.getBatchRemoveOp(d);if(Array.isArray(y)&&y.length===0)return!1;let b=c.onCommandExecute({id:h.id,params:r}),x=[...(i=b.preRedos)==null?[]:i,{id:f.id,params:{unitId:m,subUnitId:g,op:v,objects:y,type:1}},{id:p.id,params:[m]},...b.redos],S=[...(a=b.preUndos)==null?[]:a,{id:f.id,params:{unitId:m,subUnitId:g,op:_,objects:y,type:0}},{id:p.id,params:[m]},...b.undos];return(0,n.sequenceExecute)(x,o).result?(s.pushUndoRedo({unitID:m,undoMutations:S,redoMutations:x}),!0):!1}},g={id:`sheet.command.set-drawing-arrange`,type:n.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ICommandService),i=e.get(n.IUndoRedoService);if(!t)return!1;let a=e.get(u),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:l}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(l===n.ArrangeTypeEnum.forward?p=a.getForwardDrawingsOp(d):l===n.ArrangeTypeEnum.backward?p=a.getBackwardDrawingOp(d):l===n.ArrangeTypeEnum.front?p=a.getFrontDrawingsOp(d):l===n.ArrangeTypeEnum.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return r.syncExecuteCommand(f.id,{op:h,unitId:o,subUnitId:s,objects:m,type:3})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:f.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:3}}],redoMutations:[{id:f.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:3}}]}),!0):!1}};function _(e){return e===n.DrawingTypeEnum.DRAWING_CHART}function v(e,t,n){return(0,r.resolveDrawingRotateEnabled)(e,{getChildren:e=>{var r;return(r=n==null?void 0:n(e))==null?t.getDrawingsByGroup(e):r},isKnownNonRotatableType:_})}function y(e){var t,n,r;return((t=e.transform)==null?void 0:t.angle)!==void 0||((n=e.sheetTransform)==null?void 0:n.angle)!==void 0||((r=e.axisAlignSheetTransform)==null?void 0:r.angle)!==void 0}function b(e,t){let n=t==null?void 0:t.angle,r={...t==null?{}:t,...e};return n===void 0?delete r.angle:r.angle=n,r}function x(e,t){var n,r,i,a;if(!e.drawingId||!e.unitId||!e.subUnitId||!y(e))return e;let o=t.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId});if(!o||v({...o,...e,drawingType:(n=e.drawingType)==null?o.drawingType:n,transform:{...o.transform,...e.transform}},t))return e;let s={...e};return((r=e.transform)==null?void 0:r.angle)!==void 0&&(s.transform=b(e.transform,o.transform)),((i=e.sheetTransform)==null?void 0:i.angle)!==void 0&&(s.sheetTransform=b(e.sheetTransform,o.sheetTransform)),((a=e.axisAlignSheetTransform)==null?void 0:a.angle)!==void 0&&(s.axisAlignSheetTransform=b(e.axisAlignSheetTransform,o.axisAlignSheetTransform)),s}let S={id:`sheet.command.set-sheet-image`,type:n.CommandType.COMMAND,handler:(e,r)=>{var i,a;if(!r)return!1;let o=e.get(n.ICommandService),s=e.get(n.IUndoRedoService),c=e.get(u),l=e.get(t.SheetInterceptorService),{drawings:d}=r,m=d.map(e=>x(e,c)),h={...r,drawings:m},{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),C=l.onCommandExecute({id:S.id,params:h}),w=[...(i=C.preRedos)==null?[]:i,{id:f.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:2}},{id:p.id,params:[g]},...C.redos],T=[...(a=C.preUndos)==null?[]:a,{id:f.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:2}},{id:p.id,params:[g]},...C.undos];return(0,n.sequenceExecute)(w,o).result?(s.pushUndoRedo({unitID:g,undoMutations:T,redoMutations:w}),!0):!1}};function C(e,t){return function(n,r){t(n,r,e)}}function w(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let T=`SHEET_DRAWING_PLUGIN`;function E(e,t){let n=new Set,r=[];return t.forEach(t=>{let i=e[t];i&&(n.add(t),r.push(i))}),Object.values(e).forEach(e=>{n.has(e.drawingId)||r.push(e)}),r}let D=class extends n.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(f))}_initCommands(){[S,m,h,g,p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:T,businesses:[n.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===t.RemoveSheetCommand.id){var i;let t=e.params,r=t.unitId||this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=t.subUnitId||((i=this._univerInstanceService.getCurrentUnitOfType(n.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:i.getSheetId());if(!r||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(r,a),s=Object.values(o);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:u,redo:d,objects:p}=this._sheetDrawingService.getBatchRemoveOp(s);return Array.isArray(p)&&p.length===0?{redos:[],undos:[]}:{redos:[{id:f.id,params:{op:d,unitId:c,subUnitId:l,objects:p,type:1}}],undos:[{id:f.id,params:{op:u,unitId:c,subUnitId:l,objects:p,type:0}}]}}else if(e.id===t.CopySheetCommand.id){let{unitId:t,subUnitId:n,targetSubUnitId:i,copyContext:a}=e.params;if(!t||!n||!i)return{redos:[],undos:[]};let o=(0,r.getOrCreateDrawingCopyPlan)(a,E(this._sheetDrawingService.getDrawingData(t,n),this._sheetDrawingService.getDrawingOrder(t,n)),{unitId:t,sourceSubUnitId:n,targetSubUnitId:i}).drawings;if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:f.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:0}}],undos:[{id:f.id,params:{op:l,unitId:s,subUnitId:c,objects:d,type:1}}]}}return{redos:[],undos:[]}}}))}};D=w([C(0,(0,n.Inject)(t.SheetInterceptorService)),C(1,(0,n.Inject)(n.IUniverInstanceService)),C(2,n.ICommandService),C(3,u),C(4,r.IDrawingManagerService),C(5,n.IResourceManagerService)],D);var O=`@univerjs/sheets-drawing`,k=`1.0.0-alpha.3`;let A={};function j(e){"@babel/helpers - typeof";return j=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},j(e)}function M(e,t){if(j(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=M(e,`string`);return j(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let F=class extends n.Plugin{constructor(e=A,t,r){super(),this._config=e,this._injector=t,this._configService=r;let{...i}=(0,n.merge)({},A,this._config);this._configService.setConfig(`sheets-drawing.config`,i)}onStarting(){[[D],[u,{useClass:l}]].forEach(e=>this._injector.add(e)),this._injector.get(D)}};P(F,`pluginName`,T),P(F,`packageName`,O),P(F,`version`,k),P(F,`type`,n.UniverInstanceType.UNIVER_SHEET),F=w([(0,n.DependentOn)(r.UniverDrawingPlugin),C(1,(0,n.Inject)(n.Injector)),C(2,n.IConfigService)],F),e.ClearSheetDrawingTransformerOperation=p,e.DrawingApplyType=d,e.ISheetDrawingService=u,e.InsertSheetDrawingCommand=m,e.RemoveSheetDrawingCommand=h,e.SHEET_DRAWING_PLUGIN=T,e.SetDrawingApplyMutation=f,e.SetDrawingArrangeCommand=g,e.SetSheetDrawingCommand=S,e.SheetDrawingAnchorType=c,e.SheetDrawingService=l,Object.defineProperty(e,"UniverSheetsDrawingPlugin",{enumerable:!0,get:function(){return F}}),e.drawingPositionToTransform=a,e.isKnownSheetNonRotatableDrawingType=_,e.resolveSheetDrawingRotateEnabled=v,e.transformToAxisAlignPosition=s,e.transformToDrawingPosition=o});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Drawing model integration for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"lib"
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@univerjs/core": "1.0.0-alpha.
|
|
63
|
-
"@univerjs/drawing": "1.0.0-alpha.
|
|
64
|
-
"@univerjs/engine-render": "1.0.0-alpha.
|
|
65
|
-
"@univerjs/sheets": "1.0.0-alpha.
|
|
62
|
+
"@univerjs/core": "1.0.0-alpha.3",
|
|
63
|
+
"@univerjs/drawing": "1.0.0-alpha.3",
|
|
64
|
+
"@univerjs/engine-render": "1.0.0-alpha.3",
|
|
65
|
+
"@univerjs/sheets": "1.0.0-alpha.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"typescript": "^6.0.3",
|
|
69
|
-
"vitest": "^4.1.
|
|
70
|
-
"@univerjs-infra/shared": "1.0.0-alpha.
|
|
69
|
+
"vitest": "^4.1.10",
|
|
70
|
+
"@univerjs-infra/shared": "1.0.0-alpha.3"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "vitest run",
|