@univerjs/sheets-drawing 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/lib/cjs/facade.js +15 -11
- package/lib/cjs/index.js +142 -46
- package/lib/es/facade.js +15 -11
- package/lib/es/index.js +144 -49
- package/lib/facade.js +15 -11
- package/lib/index.js +144 -49
- package/lib/types/commands/commands/remove-sheet-drawing.command.d.ts +2 -1
- package/lib/types/facade/f-over-grid-image.d.ts +4 -0
- package/lib/types/facade/f-worksheet.d.ts +13 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/services/sheet-drawing-placement.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, RemoveSheetCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, UniverSheetsPlugin, attachRangeWithCoord, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute, getSheetCommandTarget } from "@univerjs/sheets";
|
|
2
|
-
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
|
|
2
|
+
import { ArrangeTypeEnum, CommandType, CustomCommandExecutionError, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
|
|
3
3
|
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
|
|
4
|
-
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
4
|
+
import { IRenderManagerService, Transform, Vector2, getGroupState } from "@univerjs/engine-render";
|
|
5
5
|
|
|
6
6
|
// src/basics/transform-position.ts
|
|
7
7
|
function drawingPositionToTransform(position, sheetSkeletonParam) {
|
|
@@ -214,6 +214,32 @@ const InsertSheetDrawingCommand = {
|
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
// src/commands/commands/remove-sheet-drawing.command.ts
|
|
217
|
+
function expandDrawingRemovalParams(service, requested) {
|
|
218
|
+
const drawings = [];
|
|
219
|
+
const visit = (search, ancestors) => {
|
|
220
|
+
if (ancestors.has(search.drawingId)) throw new CustomCommandExecutionError(RemoveSheetDrawingCommand.id);
|
|
221
|
+
if (drawings.some((drawing) => drawing.unitId === search.unitId && drawing.subUnitId === search.subUnitId && drawing.drawingId === search.drawingId)) return;
|
|
222
|
+
const current = service.getDrawingByParam(search);
|
|
223
|
+
drawings.push({
|
|
224
|
+
unitId: search.unitId,
|
|
225
|
+
subUnitId: search.subUnitId,
|
|
226
|
+
drawingId: search.drawingId,
|
|
227
|
+
drawingType: (current === null || current === void 0 ? void 0 : current.drawingType) ?? search.drawingType
|
|
228
|
+
});
|
|
229
|
+
if (!current) return;
|
|
230
|
+
const children = Object.values(service.getDrawingData(search.unitId, search.subUnitId)).filter((drawing) => current.drawingType === DrawingTypeEnum.DRAWING_GROUP && drawing.groupId === search.drawingId);
|
|
231
|
+
const nextAncestors = new Set(ancestors);
|
|
232
|
+
nextAncestors.add(search.drawingId);
|
|
233
|
+
children.forEach((drawing) => visit({
|
|
234
|
+
unitId: search.unitId,
|
|
235
|
+
subUnitId: search.subUnitId,
|
|
236
|
+
drawingId: drawing.drawingId,
|
|
237
|
+
drawingType: drawing.drawingType
|
|
238
|
+
}, nextAncestors));
|
|
239
|
+
};
|
|
240
|
+
requested.forEach((drawing) => visit(drawing, /* @__PURE__ */ new Set()));
|
|
241
|
+
return drawings;
|
|
242
|
+
}
|
|
217
243
|
const RemoveSheetDrawingCommand = {
|
|
218
244
|
id: "sheet.command.remove-sheet-image",
|
|
219
245
|
type: CommandType.COMMAND,
|
|
@@ -223,13 +249,20 @@ const RemoveSheetDrawingCommand = {
|
|
|
223
249
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
224
250
|
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
225
251
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
252
|
+
const normalizedParams = {
|
|
253
|
+
...params,
|
|
254
|
+
drawings: expandDrawingRemovalParams(sheetDrawingService, params.drawings)
|
|
255
|
+
};
|
|
256
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
257
|
+
id: RemoveSheetDrawingCommand.id,
|
|
258
|
+
params: normalizedParams
|
|
259
|
+
})) return false;
|
|
229
260
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
230
261
|
id: RemoveSheetDrawingCommand.id,
|
|
231
|
-
params
|
|
262
|
+
params: normalizedParams
|
|
232
263
|
});
|
|
264
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(normalizedParams.drawings);
|
|
265
|
+
if (Array.isArray(objects) && objects.length === 0) return false;
|
|
233
266
|
const redoMutations = [
|
|
234
267
|
...intercepted.preRedos ?? [],
|
|
235
268
|
{
|
|
@@ -372,6 +405,47 @@ function getSheetDrawingPlacement(drawing) {
|
|
|
372
405
|
function applySheetDrawingPlacement(drawing, input, skeleton) {
|
|
373
406
|
return resolveSheetDrawingPlacement(drawing, normalizePlacement(input, skeleton, requiresDrawingArea(drawing)), skeleton);
|
|
374
407
|
}
|
|
408
|
+
/** Place a batch at the logical start corner of a Chart Sheet, preserving its relative geometry. */
|
|
409
|
+
function transformDrawingsToChartSheet(drawings, chartSheetBounds, rightToLeft) {
|
|
410
|
+
if (validateBounds(chartSheetBounds, true)) return null;
|
|
411
|
+
if (!drawings.length) return [];
|
|
412
|
+
const bounds = [];
|
|
413
|
+
for (const drawing of drawings) {
|
|
414
|
+
const state = drawing.transform;
|
|
415
|
+
if (!state || validateBounds(state, requiresDrawingArea(drawing)) || [
|
|
416
|
+
state.angle,
|
|
417
|
+
state.skewX,
|
|
418
|
+
state.skewY,
|
|
419
|
+
state.scaleX,
|
|
420
|
+
state.scaleY
|
|
421
|
+
].some((value) => value !== void 0 && !Number.isFinite(value))) return null;
|
|
422
|
+
const { width = 0, height = 0, angle = 0 } = state;
|
|
423
|
+
const matrix = Transform.create().composeMatrix(state);
|
|
424
|
+
if (angle) matrix.rotate(-angle).translate(width / 2, height / 2).rotate(angle).translate(-width / 2, -height / 2);
|
|
425
|
+
const box = matrix.makeBoundingBoxFromPoints([
|
|
426
|
+
new Vector2(0, 0),
|
|
427
|
+
new Vector2(width, 0),
|
|
428
|
+
new Vector2(width, height),
|
|
429
|
+
new Vector2(0, height)
|
|
430
|
+
]);
|
|
431
|
+
bounds.push({
|
|
432
|
+
left: box.left,
|
|
433
|
+
top: box.top,
|
|
434
|
+
width: box.width,
|
|
435
|
+
height: box.height
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const group = getGroupState(0, 0, bounds);
|
|
439
|
+
const scale = Math.min(1, group.width ? chartSheetBounds.width / group.width : 1, group.height ? chartSheetBounds.height / group.height : 1);
|
|
440
|
+
const left = rightToLeft ? chartSheetBounds.left + chartSheetBounds.width - group.width * scale : chartSheetBounds.left;
|
|
441
|
+
return drawings.map((drawing) => applySheetDrawingPlacement(drawing, {
|
|
442
|
+
kind: "2",
|
|
443
|
+
left: left + (drawing.transform.left - group.left) * scale,
|
|
444
|
+
top: chartSheetBounds.top + (drawing.transform.top - group.top) * scale,
|
|
445
|
+
width: drawing.transform.width * scale,
|
|
446
|
+
height: drawing.transform.height * scale
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
375
449
|
/** Refresh layout-derived geometry without changing the drawing's anchor semantics. */
|
|
376
450
|
function refreshSheetDrawingPlacement(drawing, skeleton) {
|
|
377
451
|
const result = tryRefreshSheetDrawingPlacement(drawing, skeleton);
|
|
@@ -595,8 +669,11 @@ const SetSheetDrawingPlacementCommand = {
|
|
|
595
669
|
type: CommandType.COMMAND,
|
|
596
670
|
handler: (accessor, params) => {
|
|
597
671
|
if (!(params === null || params === void 0 ? void 0 : params.drawings.length)) return false;
|
|
672
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
673
|
+
id: SetSheetDrawingPlacementCommand.id,
|
|
674
|
+
params
|
|
675
|
+
})) return false;
|
|
598
676
|
const commandService = accessor.get(ICommandService);
|
|
599
|
-
const undoRedoService = accessor.get(IUndoRedoService);
|
|
600
677
|
const drawingService = accessor.get(ISheetDrawingService);
|
|
601
678
|
const skeleton = params.drawings.every(({ placement }) => placement.kind === "2") ? void 0 : accessor.get(SheetSkeletonService).ensureSkeleton(params.unitId, params.subUnitId);
|
|
602
679
|
const updatedDrawings = [];
|
|
@@ -609,38 +686,52 @@ const SetSheetDrawingPlacementCommand = {
|
|
|
609
686
|
if (!drawing) return false;
|
|
610
687
|
updatedDrawings.push(applySheetDrawingPlacement(drawing, placement, skeleton));
|
|
611
688
|
}
|
|
689
|
+
const intercepted = accessor.get(SheetInterceptorService).onCommandExecute({
|
|
690
|
+
id: SetSheetDrawingPlacementCommand.id,
|
|
691
|
+
params
|
|
692
|
+
});
|
|
612
693
|
const { unitId, subUnitId, undo, redo, objects } = drawingService.getBatchUpdateOp(updatedDrawings);
|
|
613
|
-
const redoMutations = [
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
694
|
+
const redoMutations = [
|
|
695
|
+
...intercepted.preRedos ?? [],
|
|
696
|
+
{
|
|
697
|
+
id: SetDrawingApplyMutation.id,
|
|
698
|
+
params: {
|
|
699
|
+
unitId,
|
|
700
|
+
subUnitId,
|
|
701
|
+
op: redo,
|
|
702
|
+
objects,
|
|
703
|
+
type: 2
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
708
|
+
params: [unitId]
|
|
709
|
+
},
|
|
710
|
+
...intercepted.redos
|
|
711
|
+
];
|
|
712
|
+
const undoMutations = [
|
|
713
|
+
...intercepted.preUndos ?? [],
|
|
714
|
+
{
|
|
715
|
+
id: SetDrawingApplyMutation.id,
|
|
716
|
+
params: {
|
|
717
|
+
unitId,
|
|
718
|
+
subUnitId,
|
|
719
|
+
op: undo,
|
|
720
|
+
objects,
|
|
721
|
+
type: 2
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
726
|
+
params: [unitId]
|
|
727
|
+
},
|
|
728
|
+
...intercepted.undos
|
|
729
|
+
];
|
|
639
730
|
if (!sequenceExecute(redoMutations, commandService).result) return false;
|
|
640
|
-
|
|
731
|
+
accessor.get(IUndoRedoService).pushUndoRedo({
|
|
641
732
|
unitID: unitId,
|
|
642
|
-
|
|
643
|
-
|
|
733
|
+
redoMutations,
|
|
734
|
+
undoMutations
|
|
644
735
|
});
|
|
645
736
|
return true;
|
|
646
737
|
}
|
|
@@ -712,6 +803,10 @@ const SetSheetDrawingCommand = {
|
|
|
712
803
|
...params,
|
|
713
804
|
drawings: normalizedDrawings
|
|
714
805
|
};
|
|
806
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
807
|
+
id: SetSheetDrawingCommand.id,
|
|
808
|
+
params: normalizedParams
|
|
809
|
+
})) return false;
|
|
715
810
|
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(normalizedDrawings);
|
|
716
811
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
717
812
|
id: SetSheetDrawingCommand.id,
|
|
@@ -819,14 +914,14 @@ const SetWorksheetBackgroundImageCommand = {
|
|
|
819
914
|
}
|
|
820
915
|
};
|
|
821
916
|
|
|
822
|
-
// \0@oxc-project+runtime@0.
|
|
917
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
823
918
|
function __decorateParam(paramIndex, decorator) {
|
|
824
919
|
return function(target, key) {
|
|
825
920
|
decorator(target, key, paramIndex);
|
|
826
921
|
};
|
|
827
922
|
}
|
|
828
923
|
|
|
829
|
-
// \0@oxc-project+runtime@0.
|
|
924
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
830
925
|
function __decorate(decorators, target, key, desc) {
|
|
831
926
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
832
927
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1008,7 +1103,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
1008
1103
|
|
|
1009
1104
|
// package.json
|
|
1010
1105
|
var name = "@univerjs/sheets-drawing";
|
|
1011
|
-
var version = "1.
|
|
1106
|
+
var version = "1.5.1";
|
|
1012
1107
|
|
|
1013
1108
|
// src/config/config.ts
|
|
1014
1109
|
/**
|
|
@@ -1030,7 +1125,7 @@ const SHEETS_DRAWING_PLUGIN_CONFIG_KEY = "sheets-drawing.config";
|
|
|
1030
1125
|
const configSymbol = Symbol(SHEETS_DRAWING_PLUGIN_CONFIG_KEY);
|
|
1031
1126
|
const defaultPluginConfig = {};
|
|
1032
1127
|
|
|
1033
|
-
// \0@oxc-project+runtime@0.
|
|
1128
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
1034
1129
|
function _typeof(o) {
|
|
1035
1130
|
"@babel/helpers - typeof";
|
|
1036
1131
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1040,25 +1135,25 @@ function _typeof(o) {
|
|
|
1040
1135
|
}, _typeof(o);
|
|
1041
1136
|
}
|
|
1042
1137
|
|
|
1043
|
-
// \0@oxc-project+runtime@0.
|
|
1044
|
-
function toPrimitive(t,
|
|
1138
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
1139
|
+
function toPrimitive(t, e) {
|
|
1045
1140
|
if ("object" != _typeof(t) || !t) return t;
|
|
1046
|
-
var
|
|
1047
|
-
if (void 0 !==
|
|
1048
|
-
var i =
|
|
1141
|
+
var r;
|
|
1142
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
1143
|
+
var i = r.call(t, e || "default");
|
|
1049
1144
|
if ("object" != _typeof(i)) return i;
|
|
1050
1145
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1051
1146
|
}
|
|
1052
|
-
return ("string" ===
|
|
1147
|
+
return ("string" === e ? String : Number)(t);
|
|
1053
1148
|
}
|
|
1054
1149
|
|
|
1055
|
-
// \0@oxc-project+runtime@0.
|
|
1150
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
1056
1151
|
function toPropertyKey(t) {
|
|
1057
1152
|
var i = toPrimitive(t, "string");
|
|
1058
1153
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
1059
1154
|
}
|
|
1060
1155
|
|
|
1061
|
-
// \0@oxc-project+runtime@0.
|
|
1156
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
1062
1157
|
function _defineProperty(e, r, t) {
|
|
1063
1158
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1064
1159
|
value: t,
|
|
@@ -2078,4 +2173,4 @@ UniverSheetsDrawingPlugin = __decorate([
|
|
|
2078
2173
|
__decorateParam(2, IConfigService)
|
|
2079
2174
|
], UniverSheetsDrawingPlugin);
|
|
2080
2175
|
|
|
2081
|
-
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, isKnownSheetNonRotatableDrawingType, normalizeSheetDrawingPlacement, refreshSheetDrawingPlacement, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
2176
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, isKnownSheetNonRotatableDrawingType, normalizeSheetDrawingPlacement, refreshSheetDrawingPlacement, resolveSheetDrawingRotateEnabled, transformDrawingsToChartSheet, transformToAxisAlignPosition, transformToDrawingPosition };
|
package/lib/facade.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, Remo
|
|
|
6
6
|
import { getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
|
|
7
7
|
import { FWorksheet } from "@univerjs/sheets/facade";
|
|
8
8
|
|
|
9
|
-
// \0@oxc-project+runtime@0.
|
|
9
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
10
10
|
function _typeof(o) {
|
|
11
11
|
"@babel/helpers - typeof";
|
|
12
12
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -16,25 +16,25 @@ function _typeof(o) {
|
|
|
16
16
|
}, _typeof(o);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// \0@oxc-project+runtime@0.
|
|
20
|
-
function toPrimitive(t,
|
|
19
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
20
|
+
function toPrimitive(t, e) {
|
|
21
21
|
if ("object" != _typeof(t) || !t) return t;
|
|
22
|
-
var
|
|
23
|
-
if (void 0 !==
|
|
24
|
-
var i =
|
|
22
|
+
var r;
|
|
23
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
24
|
+
var i = r.call(t, e || "default");
|
|
25
25
|
if ("object" != _typeof(i)) return i;
|
|
26
26
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
27
27
|
}
|
|
28
|
-
return ("string" ===
|
|
28
|
+
return ("string" === e ? String : Number)(t);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// \0@oxc-project+runtime@0.
|
|
31
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
32
32
|
function toPropertyKey(t) {
|
|
33
33
|
var i = toPrimitive(t, "string");
|
|
34
34
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// \0@oxc-project+runtime@0.
|
|
37
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
38
38
|
function _defineProperty(e, r, t) {
|
|
39
39
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
40
40
|
value: t,
|
|
@@ -44,14 +44,14 @@ function _defineProperty(e, r, t) {
|
|
|
44
44
|
}) : e[r] = t, e;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// \0@oxc-project+runtime@0.
|
|
47
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
48
48
|
function __decorateParam(paramIndex, decorator) {
|
|
49
49
|
return function(target, key) {
|
|
50
50
|
decorator(target, key, paramIndex);
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// \0@oxc-project+runtime@0.
|
|
54
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
55
55
|
function __decorate(decorators, target, key, desc) {
|
|
56
56
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
57
57
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -909,6 +909,10 @@ let FOverGridImage = class FOverGridImage extends FBase {
|
|
|
909
909
|
}
|
|
910
910
|
/**
|
|
911
911
|
* Remove the image from the sheet
|
|
912
|
+
*
|
|
913
|
+
* For multiple images on the same worksheet, prefer {@link FWorksheet.deleteImages} with the image
|
|
914
|
+
* handles instead of calling this method on each image.
|
|
915
|
+
*
|
|
912
916
|
* @returns {boolean} true if the image is removed successfully, otherwise false
|
|
913
917
|
* @example
|
|
914
918
|
* ```ts
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, RemoveSheetCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, UniverSheetsPlugin, attachRangeWithCoord, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute, getSheetCommandTarget } from "@univerjs/sheets";
|
|
2
|
-
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
|
|
2
|
+
import { ArrangeTypeEnum, CommandType, CustomCommandExecutionError, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
|
|
3
3
|
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
|
|
4
|
-
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
4
|
+
import { IRenderManagerService, Transform, Vector2, getGroupState } from "@univerjs/engine-render";
|
|
5
5
|
|
|
6
6
|
// src/basics/transform-position.ts
|
|
7
7
|
function drawingPositionToTransform(position, sheetSkeletonParam) {
|
|
@@ -214,6 +214,32 @@ const InsertSheetDrawingCommand = {
|
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
// src/commands/commands/remove-sheet-drawing.command.ts
|
|
217
|
+
function expandDrawingRemovalParams(service, requested) {
|
|
218
|
+
const drawings = [];
|
|
219
|
+
const visit = (search, ancestors) => {
|
|
220
|
+
if (ancestors.has(search.drawingId)) throw new CustomCommandExecutionError(RemoveSheetDrawingCommand.id);
|
|
221
|
+
if (drawings.some((drawing) => drawing.unitId === search.unitId && drawing.subUnitId === search.subUnitId && drawing.drawingId === search.drawingId)) return;
|
|
222
|
+
const current = service.getDrawingByParam(search);
|
|
223
|
+
drawings.push({
|
|
224
|
+
unitId: search.unitId,
|
|
225
|
+
subUnitId: search.subUnitId,
|
|
226
|
+
drawingId: search.drawingId,
|
|
227
|
+
drawingType: (current === null || current === void 0 ? void 0 : current.drawingType) ?? search.drawingType
|
|
228
|
+
});
|
|
229
|
+
if (!current) return;
|
|
230
|
+
const children = Object.values(service.getDrawingData(search.unitId, search.subUnitId)).filter((drawing) => current.drawingType === DrawingTypeEnum.DRAWING_GROUP && drawing.groupId === search.drawingId);
|
|
231
|
+
const nextAncestors = new Set(ancestors);
|
|
232
|
+
nextAncestors.add(search.drawingId);
|
|
233
|
+
children.forEach((drawing) => visit({
|
|
234
|
+
unitId: search.unitId,
|
|
235
|
+
subUnitId: search.subUnitId,
|
|
236
|
+
drawingId: drawing.drawingId,
|
|
237
|
+
drawingType: drawing.drawingType
|
|
238
|
+
}, nextAncestors));
|
|
239
|
+
};
|
|
240
|
+
requested.forEach((drawing) => visit(drawing, /* @__PURE__ */ new Set()));
|
|
241
|
+
return drawings;
|
|
242
|
+
}
|
|
217
243
|
const RemoveSheetDrawingCommand = {
|
|
218
244
|
id: "sheet.command.remove-sheet-image",
|
|
219
245
|
type: CommandType.COMMAND,
|
|
@@ -223,13 +249,20 @@ const RemoveSheetDrawingCommand = {
|
|
|
223
249
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
224
250
|
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
225
251
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
252
|
+
const normalizedParams = {
|
|
253
|
+
...params,
|
|
254
|
+
drawings: expandDrawingRemovalParams(sheetDrawingService, params.drawings)
|
|
255
|
+
};
|
|
256
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
257
|
+
id: RemoveSheetDrawingCommand.id,
|
|
258
|
+
params: normalizedParams
|
|
259
|
+
})) return false;
|
|
229
260
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
230
261
|
id: RemoveSheetDrawingCommand.id,
|
|
231
|
-
params
|
|
262
|
+
params: normalizedParams
|
|
232
263
|
});
|
|
264
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(normalizedParams.drawings);
|
|
265
|
+
if (Array.isArray(objects) && objects.length === 0) return false;
|
|
233
266
|
const redoMutations = [
|
|
234
267
|
...intercepted.preRedos ?? [],
|
|
235
268
|
{
|
|
@@ -372,6 +405,47 @@ function getSheetDrawingPlacement(drawing) {
|
|
|
372
405
|
function applySheetDrawingPlacement(drawing, input, skeleton) {
|
|
373
406
|
return resolveSheetDrawingPlacement(drawing, normalizePlacement(input, skeleton, requiresDrawingArea(drawing)), skeleton);
|
|
374
407
|
}
|
|
408
|
+
/** Place a batch at the logical start corner of a Chart Sheet, preserving its relative geometry. */
|
|
409
|
+
function transformDrawingsToChartSheet(drawings, chartSheetBounds, rightToLeft) {
|
|
410
|
+
if (validateBounds(chartSheetBounds, true)) return null;
|
|
411
|
+
if (!drawings.length) return [];
|
|
412
|
+
const bounds = [];
|
|
413
|
+
for (const drawing of drawings) {
|
|
414
|
+
const state = drawing.transform;
|
|
415
|
+
if (!state || validateBounds(state, requiresDrawingArea(drawing)) || [
|
|
416
|
+
state.angle,
|
|
417
|
+
state.skewX,
|
|
418
|
+
state.skewY,
|
|
419
|
+
state.scaleX,
|
|
420
|
+
state.scaleY
|
|
421
|
+
].some((value) => value !== void 0 && !Number.isFinite(value))) return null;
|
|
422
|
+
const { width = 0, height = 0, angle = 0 } = state;
|
|
423
|
+
const matrix = Transform.create().composeMatrix(state);
|
|
424
|
+
if (angle) matrix.rotate(-angle).translate(width / 2, height / 2).rotate(angle).translate(-width / 2, -height / 2);
|
|
425
|
+
const box = matrix.makeBoundingBoxFromPoints([
|
|
426
|
+
new Vector2(0, 0),
|
|
427
|
+
new Vector2(width, 0),
|
|
428
|
+
new Vector2(width, height),
|
|
429
|
+
new Vector2(0, height)
|
|
430
|
+
]);
|
|
431
|
+
bounds.push({
|
|
432
|
+
left: box.left,
|
|
433
|
+
top: box.top,
|
|
434
|
+
width: box.width,
|
|
435
|
+
height: box.height
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const group = getGroupState(0, 0, bounds);
|
|
439
|
+
const scale = Math.min(1, group.width ? chartSheetBounds.width / group.width : 1, group.height ? chartSheetBounds.height / group.height : 1);
|
|
440
|
+
const left = rightToLeft ? chartSheetBounds.left + chartSheetBounds.width - group.width * scale : chartSheetBounds.left;
|
|
441
|
+
return drawings.map((drawing) => applySheetDrawingPlacement(drawing, {
|
|
442
|
+
kind: "2",
|
|
443
|
+
left: left + (drawing.transform.left - group.left) * scale,
|
|
444
|
+
top: chartSheetBounds.top + (drawing.transform.top - group.top) * scale,
|
|
445
|
+
width: drawing.transform.width * scale,
|
|
446
|
+
height: drawing.transform.height * scale
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
375
449
|
/** Refresh layout-derived geometry without changing the drawing's anchor semantics. */
|
|
376
450
|
function refreshSheetDrawingPlacement(drawing, skeleton) {
|
|
377
451
|
const result = tryRefreshSheetDrawingPlacement(drawing, skeleton);
|
|
@@ -595,8 +669,11 @@ const SetSheetDrawingPlacementCommand = {
|
|
|
595
669
|
type: CommandType.COMMAND,
|
|
596
670
|
handler: (accessor, params) => {
|
|
597
671
|
if (!(params === null || params === void 0 ? void 0 : params.drawings.length)) return false;
|
|
672
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
673
|
+
id: SetSheetDrawingPlacementCommand.id,
|
|
674
|
+
params
|
|
675
|
+
})) return false;
|
|
598
676
|
const commandService = accessor.get(ICommandService);
|
|
599
|
-
const undoRedoService = accessor.get(IUndoRedoService);
|
|
600
677
|
const drawingService = accessor.get(ISheetDrawingService);
|
|
601
678
|
const skeleton = params.drawings.every(({ placement }) => placement.kind === "2") ? void 0 : accessor.get(SheetSkeletonService).ensureSkeleton(params.unitId, params.subUnitId);
|
|
602
679
|
const updatedDrawings = [];
|
|
@@ -609,38 +686,52 @@ const SetSheetDrawingPlacementCommand = {
|
|
|
609
686
|
if (!drawing) return false;
|
|
610
687
|
updatedDrawings.push(applySheetDrawingPlacement(drawing, placement, skeleton));
|
|
611
688
|
}
|
|
689
|
+
const intercepted = accessor.get(SheetInterceptorService).onCommandExecute({
|
|
690
|
+
id: SetSheetDrawingPlacementCommand.id,
|
|
691
|
+
params
|
|
692
|
+
});
|
|
612
693
|
const { unitId, subUnitId, undo, redo, objects } = drawingService.getBatchUpdateOp(updatedDrawings);
|
|
613
|
-
const redoMutations = [
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
694
|
+
const redoMutations = [
|
|
695
|
+
...intercepted.preRedos ?? [],
|
|
696
|
+
{
|
|
697
|
+
id: SetDrawingApplyMutation.id,
|
|
698
|
+
params: {
|
|
699
|
+
unitId,
|
|
700
|
+
subUnitId,
|
|
701
|
+
op: redo,
|
|
702
|
+
objects,
|
|
703
|
+
type: 2
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
708
|
+
params: [unitId]
|
|
709
|
+
},
|
|
710
|
+
...intercepted.redos
|
|
711
|
+
];
|
|
712
|
+
const undoMutations = [
|
|
713
|
+
...intercepted.preUndos ?? [],
|
|
714
|
+
{
|
|
715
|
+
id: SetDrawingApplyMutation.id,
|
|
716
|
+
params: {
|
|
717
|
+
unitId,
|
|
718
|
+
subUnitId,
|
|
719
|
+
op: undo,
|
|
720
|
+
objects,
|
|
721
|
+
type: 2
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
726
|
+
params: [unitId]
|
|
727
|
+
},
|
|
728
|
+
...intercepted.undos
|
|
729
|
+
];
|
|
639
730
|
if (!sequenceExecute(redoMutations, commandService).result) return false;
|
|
640
|
-
|
|
731
|
+
accessor.get(IUndoRedoService).pushUndoRedo({
|
|
641
732
|
unitID: unitId,
|
|
642
|
-
|
|
643
|
-
|
|
733
|
+
redoMutations,
|
|
734
|
+
undoMutations
|
|
644
735
|
});
|
|
645
736
|
return true;
|
|
646
737
|
}
|
|
@@ -712,6 +803,10 @@ const SetSheetDrawingCommand = {
|
|
|
712
803
|
...params,
|
|
713
804
|
drawings: normalizedDrawings
|
|
714
805
|
};
|
|
806
|
+
if (!accessor.get(IDrawingManagerService).canExecuteCommand({
|
|
807
|
+
id: SetSheetDrawingCommand.id,
|
|
808
|
+
params: normalizedParams
|
|
809
|
+
})) return false;
|
|
715
810
|
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(normalizedDrawings);
|
|
716
811
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
717
812
|
id: SetSheetDrawingCommand.id,
|
|
@@ -819,14 +914,14 @@ const SetWorksheetBackgroundImageCommand = {
|
|
|
819
914
|
}
|
|
820
915
|
};
|
|
821
916
|
|
|
822
|
-
// \0@oxc-project+runtime@0.
|
|
917
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
823
918
|
function __decorateParam(paramIndex, decorator) {
|
|
824
919
|
return function(target, key) {
|
|
825
920
|
decorator(target, key, paramIndex);
|
|
826
921
|
};
|
|
827
922
|
}
|
|
828
923
|
|
|
829
|
-
// \0@oxc-project+runtime@0.
|
|
924
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
830
925
|
function __decorate(decorators, target, key, desc) {
|
|
831
926
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
832
927
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1008,7 +1103,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
1008
1103
|
|
|
1009
1104
|
// package.json
|
|
1010
1105
|
var name = "@univerjs/sheets-drawing";
|
|
1011
|
-
var version = "1.
|
|
1106
|
+
var version = "1.5.1";
|
|
1012
1107
|
|
|
1013
1108
|
// src/config/config.ts
|
|
1014
1109
|
/**
|
|
@@ -1030,7 +1125,7 @@ const SHEETS_DRAWING_PLUGIN_CONFIG_KEY = "sheets-drawing.config";
|
|
|
1030
1125
|
const configSymbol = Symbol(SHEETS_DRAWING_PLUGIN_CONFIG_KEY);
|
|
1031
1126
|
const defaultPluginConfig = {};
|
|
1032
1127
|
|
|
1033
|
-
// \0@oxc-project+runtime@0.
|
|
1128
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
1034
1129
|
function _typeof(o) {
|
|
1035
1130
|
"@babel/helpers - typeof";
|
|
1036
1131
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1040,25 +1135,25 @@ function _typeof(o) {
|
|
|
1040
1135
|
}, _typeof(o);
|
|
1041
1136
|
}
|
|
1042
1137
|
|
|
1043
|
-
// \0@oxc-project+runtime@0.
|
|
1044
|
-
function toPrimitive(t,
|
|
1138
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
1139
|
+
function toPrimitive(t, e) {
|
|
1045
1140
|
if ("object" != _typeof(t) || !t) return t;
|
|
1046
|
-
var
|
|
1047
|
-
if (void 0 !==
|
|
1048
|
-
var i =
|
|
1141
|
+
var r;
|
|
1142
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
1143
|
+
var i = r.call(t, e || "default");
|
|
1049
1144
|
if ("object" != _typeof(i)) return i;
|
|
1050
1145
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1051
1146
|
}
|
|
1052
|
-
return ("string" ===
|
|
1147
|
+
return ("string" === e ? String : Number)(t);
|
|
1053
1148
|
}
|
|
1054
1149
|
|
|
1055
|
-
// \0@oxc-project+runtime@0.
|
|
1150
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
1056
1151
|
function toPropertyKey(t) {
|
|
1057
1152
|
var i = toPrimitive(t, "string");
|
|
1058
1153
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
1059
1154
|
}
|
|
1060
1155
|
|
|
1061
|
-
// \0@oxc-project+runtime@0.
|
|
1156
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
1062
1157
|
function _defineProperty(e, r, t) {
|
|
1063
1158
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1064
1159
|
value: t,
|
|
@@ -2078,4 +2173,4 @@ UniverSheetsDrawingPlugin = __decorate([
|
|
|
2078
2173
|
__decorateParam(2, IConfigService)
|
|
2079
2174
|
], UniverSheetsDrawingPlugin);
|
|
2080
2175
|
|
|
2081
|
-
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, isKnownSheetNonRotatableDrawingType, normalizeSheetDrawingPlacement, refreshSheetDrawingPlacement, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
2176
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, isKnownSheetNonRotatableDrawingType, normalizeSheetDrawingPlacement, refreshSheetDrawingPlacement, resolveSheetDrawingRotateEnabled, transformDrawingsToChartSheet, transformToAxisAlignPosition, transformToDrawingPosition };
|