@univerjs/sheets-drawing 1.0.0-alpha.8 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +288 -21
- package/lib/cjs/index.js +258 -52
- package/lib/es/facade.js +289 -22
- package/lib/es/index.js +256 -54
- package/lib/facade.js +289 -22
- package/lib/index.js +256 -54
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +6 -2
- package/lib/types/commands/commands/set-sheet-drawing-placement.command.d.ts +26 -0
- package/lib/types/facade/f-over-grid-image.d.ts +130 -4
- package/lib/types/facade/f-worksheet.d.ts +128 -1
- package/lib/types/index.d.ts +4 -0
- package/lib/types/services/sheet-drawing-placement.d.ts +86 -0
- package/lib/types/services/sheet-drawing.service.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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, SheetsSelectionsService, UniverSheetsPlugin, attachRangeWithCoord, convertPositionSheetOverGridToAbsolute, getSheetCommandTarget } from "@univerjs/sheets";
|
|
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, SheetsSelectionsService, UniverSheetsPlugin, attachRangeWithCoord, convertPositionCellToSheetOverGrid, convertPositionSheetOverGridToAbsolute, getSheetCommandTarget } from "@univerjs/sheets";
|
|
2
2
|
import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, RANGE_TYPE, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
|
|
3
3
|
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
|
|
4
4
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
@@ -153,7 +153,6 @@ const InsertSheetDrawingCommand = {
|
|
|
153
153
|
id: "sheet.command.insert-sheet-image",
|
|
154
154
|
type: CommandType.COMMAND,
|
|
155
155
|
handler: (accessor, params) => {
|
|
156
|
-
var _intercepted$preRedos, _intercepted$preUndos;
|
|
157
156
|
if (!params) return false;
|
|
158
157
|
const commandService = accessor.get(ICommandService);
|
|
159
158
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -166,7 +165,7 @@ const InsertSheetDrawingCommand = {
|
|
|
166
165
|
params
|
|
167
166
|
});
|
|
168
167
|
const redoMutations = [
|
|
169
|
-
...
|
|
168
|
+
...intercepted.preRedos ?? [],
|
|
170
169
|
{
|
|
171
170
|
id: SetDrawingApplyMutation.id,
|
|
172
171
|
params: {
|
|
@@ -184,7 +183,7 @@ const InsertSheetDrawingCommand = {
|
|
|
184
183
|
...intercepted.redos
|
|
185
184
|
];
|
|
186
185
|
const undoMutations = [
|
|
187
|
-
...
|
|
186
|
+
...intercepted.preUndos ?? [],
|
|
188
187
|
{
|
|
189
188
|
id: SetDrawingApplyMutation.id,
|
|
190
189
|
params: {
|
|
@@ -219,7 +218,6 @@ const RemoveSheetDrawingCommand = {
|
|
|
219
218
|
id: "sheet.command.remove-sheet-image",
|
|
220
219
|
type: CommandType.COMMAND,
|
|
221
220
|
handler: (accessor, params) => {
|
|
222
|
-
var _intercepted$preRedos, _intercepted$preUndos;
|
|
223
221
|
if (!params) return false;
|
|
224
222
|
const commandService = accessor.get(ICommandService);
|
|
225
223
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -233,7 +231,7 @@ const RemoveSheetDrawingCommand = {
|
|
|
233
231
|
params
|
|
234
232
|
});
|
|
235
233
|
const redoMutations = [
|
|
236
|
-
...
|
|
234
|
+
...intercepted.preRedos ?? [],
|
|
237
235
|
{
|
|
238
236
|
id: SetDrawingApplyMutation.id,
|
|
239
237
|
params: {
|
|
@@ -251,7 +249,7 @@ const RemoveSheetDrawingCommand = {
|
|
|
251
249
|
...intercepted.redos
|
|
252
250
|
];
|
|
253
251
|
const undoMutations = [
|
|
254
|
-
...
|
|
252
|
+
...intercepted.preUndos ?? [],
|
|
255
253
|
{
|
|
256
254
|
id: SetDrawingApplyMutation.id,
|
|
257
255
|
params: {
|
|
@@ -290,17 +288,18 @@ const SetDrawingArrangeCommand = {
|
|
|
290
288
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
291
289
|
if (!params) return false;
|
|
292
290
|
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
293
|
-
const { unitId, subUnitId, drawingIds
|
|
291
|
+
const { unitId, subUnitId, drawingIds } = params;
|
|
294
292
|
const drawingOrderMapParam = {
|
|
295
293
|
unitId,
|
|
296
294
|
subUnitId,
|
|
297
295
|
drawingIds
|
|
298
296
|
};
|
|
299
297
|
let jsonOp;
|
|
300
|
-
if (
|
|
301
|
-
else if (arrangeType === ArrangeTypeEnum.
|
|
302
|
-
else if (arrangeType === ArrangeTypeEnum.
|
|
303
|
-
else if (arrangeType === ArrangeTypeEnum.
|
|
298
|
+
if (params.zOrder !== void 0) jsonOp = sheetDrawingService.getDrawingOrderOp(drawingOrderMapParam, params.zOrder);
|
|
299
|
+
else if (params.arrangeType === ArrangeTypeEnum.forward) jsonOp = sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
300
|
+
else if (params.arrangeType === ArrangeTypeEnum.backward) jsonOp = sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
301
|
+
else if (params.arrangeType === ArrangeTypeEnum.front) jsonOp = sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
302
|
+
else if (params.arrangeType === ArrangeTypeEnum.back) jsonOp = sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
304
303
|
if (jsonOp == null) return false;
|
|
305
304
|
const { objects, redo, undo } = jsonOp;
|
|
306
305
|
if (commandService.syncExecuteCommand(SetDrawingApplyMutation.id, {
|
|
@@ -339,6 +338,226 @@ const SetDrawingArrangeCommand = {
|
|
|
339
338
|
}
|
|
340
339
|
};
|
|
341
340
|
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/services/sheet-drawing-placement.ts
|
|
343
|
+
function getSheetDrawingPlacement(drawing) {
|
|
344
|
+
var _drawing$transform5, _drawing$transform6;
|
|
345
|
+
const anchorType = drawing.anchorType ?? "0";
|
|
346
|
+
if (anchorType === "2") {
|
|
347
|
+
var _drawing$transform, _drawing$transform2, _drawing$transform3, _drawing$transform4;
|
|
348
|
+
return {
|
|
349
|
+
kind: "2",
|
|
350
|
+
left: ((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.left) ?? 0,
|
|
351
|
+
top: ((_drawing$transform2 = drawing.transform) === null || _drawing$transform2 === void 0 ? void 0 : _drawing$transform2.top) ?? 0,
|
|
352
|
+
width: ((_drawing$transform3 = drawing.transform) === null || _drawing$transform3 === void 0 ? void 0 : _drawing$transform3.width) ?? 0,
|
|
353
|
+
height: ((_drawing$transform4 = drawing.transform) === null || _drawing$transform4 === void 0 ? void 0 : _drawing$transform4.height) ?? 0
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if (anchorType === "1") return {
|
|
357
|
+
kind: "1",
|
|
358
|
+
from: { ...drawing.sheetTransform.from },
|
|
359
|
+
to: { ...drawing.sheetTransform.to }
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
kind: "0",
|
|
363
|
+
from: { ...drawing.sheetTransform.from },
|
|
364
|
+
width: ((_drawing$transform5 = drawing.transform) === null || _drawing$transform5 === void 0 ? void 0 : _drawing$transform5.width) ?? 0,
|
|
365
|
+
height: ((_drawing$transform6 = drawing.transform) === null || _drawing$transform6 === void 0 ? void 0 : _drawing$transform6.height) ?? 0
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function applySheetDrawingPlacement(drawing, input, skeleton) {
|
|
369
|
+
const placement = normalizeSheetDrawingPlacement(input, skeleton);
|
|
370
|
+
if (placement.kind === "2") {
|
|
371
|
+
const transform = withExistingTransform(drawing.transform, placement);
|
|
372
|
+
const sheetTransform = absoluteSheetTransform(placement, drawing.sheetTransform);
|
|
373
|
+
return {
|
|
374
|
+
...drawing,
|
|
375
|
+
anchorType: "2",
|
|
376
|
+
transform,
|
|
377
|
+
sheetTransform,
|
|
378
|
+
axisAlignSheetTransform: sheetTransform
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (!skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
382
|
+
if (placement.kind === "0") {
|
|
383
|
+
const converted = convertPositionCellToSheetOverGrid(drawing.unitId, drawing.subUnitId, placement.from, placement.width, placement.height, skeleton);
|
|
384
|
+
const sheetTransform = withExistingSheetTransform(drawing.sheetTransform, converted.sheetTransform);
|
|
385
|
+
const transform = withExistingTransform(drawing.transform, converted.transform);
|
|
386
|
+
return {
|
|
387
|
+
...drawing,
|
|
388
|
+
anchorType: "0",
|
|
389
|
+
sheetTransform,
|
|
390
|
+
transform,
|
|
391
|
+
axisAlignSheetTransform: transformToAxisAlignPosition(transform, skeleton)
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const sheetTransform = withExistingSheetTransform(drawing.sheetTransform, {
|
|
395
|
+
from: placement.from,
|
|
396
|
+
to: placement.to
|
|
397
|
+
});
|
|
398
|
+
const bounds = convertPositionSheetOverGridToAbsolute(drawing.unitId, drawing.subUnitId, sheetTransform, skeleton);
|
|
399
|
+
const transform = withExistingTransform(drawing.transform, bounds);
|
|
400
|
+
return {
|
|
401
|
+
...drawing,
|
|
402
|
+
anchorType: "1",
|
|
403
|
+
sheetTransform,
|
|
404
|
+
transform,
|
|
405
|
+
axisAlignSheetTransform: transformToAxisAlignPosition(transform, skeleton)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Normalize exact markers or model-space bounds to the authoritative
|
|
410
|
+
* Position, Both, or None Placement.
|
|
411
|
+
*/
|
|
412
|
+
function normalizeSheetDrawingPlacement(input, skeleton) {
|
|
413
|
+
if (!("bounds" in input)) {
|
|
414
|
+
validatePlacement(input);
|
|
415
|
+
if (input.kind === "1" && skeleton) validateBounds(convertPositionSheetOverGridToAbsolute(skeleton.worksheet.getUnitId(), skeleton.worksheet.getSheetId(), {
|
|
416
|
+
from: input.from,
|
|
417
|
+
to: input.to
|
|
418
|
+
}, skeleton));
|
|
419
|
+
return input;
|
|
420
|
+
}
|
|
421
|
+
validateBounds(input.bounds);
|
|
422
|
+
if (input.kind === "2") return {
|
|
423
|
+
kind: "2",
|
|
424
|
+
...input.bounds
|
|
425
|
+
};
|
|
426
|
+
if (!skeleton) throw new Error("SHEET_DRAWING_PLACEMENT_SKELETON_REQUIRED");
|
|
427
|
+
const sheetTransform = transformToDrawingPosition(input.bounds, skeleton);
|
|
428
|
+
if (input.kind === "0") return {
|
|
429
|
+
kind: "0",
|
|
430
|
+
from: sheetTransform.from,
|
|
431
|
+
width: input.bounds.width,
|
|
432
|
+
height: input.bounds.height
|
|
433
|
+
};
|
|
434
|
+
if (input.kind === "1") return {
|
|
435
|
+
kind: "1",
|
|
436
|
+
from: sheetTransform.from,
|
|
437
|
+
to: sheetTransform.to
|
|
438
|
+
};
|
|
439
|
+
throw new Error("SHEET_DRAWING_PLACEMENT_KIND_INVALID");
|
|
440
|
+
}
|
|
441
|
+
function withExistingSheetTransform(current, placement) {
|
|
442
|
+
return {
|
|
443
|
+
...current,
|
|
444
|
+
from: { ...placement.from },
|
|
445
|
+
to: { ...placement.to }
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function withExistingTransform(current, bounds) {
|
|
449
|
+
return {
|
|
450
|
+
...current,
|
|
451
|
+
left: bounds.left,
|
|
452
|
+
top: bounds.top,
|
|
453
|
+
width: bounds.width,
|
|
454
|
+
height: bounds.height
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function absoluteSheetTransform(placement, current) {
|
|
458
|
+
return {
|
|
459
|
+
...current,
|
|
460
|
+
from: {
|
|
461
|
+
column: 0,
|
|
462
|
+
columnOffset: placement.left,
|
|
463
|
+
row: 0,
|
|
464
|
+
rowOffset: placement.top
|
|
465
|
+
},
|
|
466
|
+
to: {
|
|
467
|
+
column: 0,
|
|
468
|
+
columnOffset: placement.left + placement.width,
|
|
469
|
+
row: 0,
|
|
470
|
+
rowOffset: placement.top + placement.height
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function validatePlacement(placement) {
|
|
475
|
+
if (placement.kind === "0") {
|
|
476
|
+
validateCellPosition(placement.from);
|
|
477
|
+
validateExtent(placement.width, placement.height);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (placement.kind === "1") {
|
|
481
|
+
validateCellPosition(placement.from);
|
|
482
|
+
validateCellPosition(placement.to);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (placement.kind === "2") {
|
|
486
|
+
if (!Number.isFinite(placement.left) || !Number.isFinite(placement.top)) throw new TypeError("SHEET_DRAWING_PLACEMENT_POSITION_INVALID");
|
|
487
|
+
validateExtent(placement.width, placement.height);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
throw new Error("SHEET_DRAWING_PLACEMENT_KIND_INVALID");
|
|
491
|
+
}
|
|
492
|
+
function validateBounds(bounds) {
|
|
493
|
+
if (!Number.isFinite(bounds.left) || !Number.isFinite(bounds.top)) throw new TypeError("SHEET_DRAWING_PLACEMENT_POSITION_INVALID");
|
|
494
|
+
validateExtent(bounds.width, bounds.height);
|
|
495
|
+
}
|
|
496
|
+
function validateCellPosition(position) {
|
|
497
|
+
if (!Number.isInteger(position.row) || !Number.isInteger(position.column) || position.row < 0 || position.column < 0 || !Number.isFinite(position.rowOffset) || !Number.isFinite(position.columnOffset)) throw new Error("SHEET_DRAWING_PLACEMENT_CELL_INVALID");
|
|
498
|
+
}
|
|
499
|
+
function validateExtent(width, height) {
|
|
500
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) throw new Error("SHEET_DRAWING_PLACEMENT_EXTENT_INVALID");
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/commands/commands/set-sheet-drawing-placement.command.ts
|
|
505
|
+
const SetSheetDrawingPlacementCommand = {
|
|
506
|
+
id: "sheet.command.set-drawing-placement",
|
|
507
|
+
type: CommandType.COMMAND,
|
|
508
|
+
handler: (accessor, params) => {
|
|
509
|
+
if (!(params === null || params === void 0 ? void 0 : params.drawings.length)) return false;
|
|
510
|
+
const commandService = accessor.get(ICommandService);
|
|
511
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
512
|
+
const drawingService = accessor.get(ISheetDrawingService);
|
|
513
|
+
const skeleton = params.drawings.every(({ placement }) => placement.kind === "2") ? void 0 : accessor.get(SheetSkeletonService).ensureSkeleton(params.unitId, params.subUnitId);
|
|
514
|
+
const updatedDrawings = [];
|
|
515
|
+
for (const { drawingId, placement } of params.drawings) {
|
|
516
|
+
const drawing = drawingService.getDrawingByParam({
|
|
517
|
+
unitId: params.unitId,
|
|
518
|
+
subUnitId: params.subUnitId,
|
|
519
|
+
drawingId
|
|
520
|
+
});
|
|
521
|
+
if (!drawing) return false;
|
|
522
|
+
updatedDrawings.push(applySheetDrawingPlacement(drawing, placement, skeleton));
|
|
523
|
+
}
|
|
524
|
+
const { unitId, subUnitId, undo, redo, objects } = drawingService.getBatchUpdateOp(updatedDrawings);
|
|
525
|
+
const redoMutations = [{
|
|
526
|
+
id: SetDrawingApplyMutation.id,
|
|
527
|
+
params: {
|
|
528
|
+
unitId,
|
|
529
|
+
subUnitId,
|
|
530
|
+
op: redo,
|
|
531
|
+
objects,
|
|
532
|
+
type: 2
|
|
533
|
+
}
|
|
534
|
+
}, {
|
|
535
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
536
|
+
params: [unitId]
|
|
537
|
+
}];
|
|
538
|
+
const undoMutations = [{
|
|
539
|
+
id: SetDrawingApplyMutation.id,
|
|
540
|
+
params: {
|
|
541
|
+
unitId,
|
|
542
|
+
subUnitId,
|
|
543
|
+
op: undo,
|
|
544
|
+
objects,
|
|
545
|
+
type: 2
|
|
546
|
+
}
|
|
547
|
+
}, {
|
|
548
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
549
|
+
params: [unitId]
|
|
550
|
+
}];
|
|
551
|
+
if (!sequenceExecute(redoMutations, commandService).result) return false;
|
|
552
|
+
undoRedoService.pushUndoRedo({
|
|
553
|
+
unitID: unitId,
|
|
554
|
+
undoMutations,
|
|
555
|
+
redoMutations
|
|
556
|
+
});
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
342
561
|
//#endregion
|
|
343
562
|
//#region src/common/rotate-enabled.ts
|
|
344
563
|
function isKnownSheetNonRotatableDrawingType(drawingType) {
|
|
@@ -346,10 +565,7 @@ function isKnownSheetNonRotatableDrawingType(drawingType) {
|
|
|
346
565
|
}
|
|
347
566
|
function resolveSheetDrawingRotateEnabled(drawing, drawingService, getChildren) {
|
|
348
567
|
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
|
-
},
|
|
568
|
+
getChildren: (current) => (getChildren === null || getChildren === void 0 ? void 0 : getChildren(current)) ?? drawingService.getDrawingsByGroup(current),
|
|
353
569
|
isKnownNonRotatableType: isKnownSheetNonRotatableDrawingType
|
|
354
570
|
});
|
|
355
571
|
}
|
|
@@ -363,7 +579,7 @@ function hasIncomingAngle(drawing) {
|
|
|
363
579
|
function preserveAngle(incoming, current) {
|
|
364
580
|
const currentAngle = current === null || current === void 0 ? void 0 : current.angle;
|
|
365
581
|
const next = {
|
|
366
|
-
...current
|
|
582
|
+
...current ?? {},
|
|
367
583
|
...incoming
|
|
368
584
|
};
|
|
369
585
|
if (currentAngle === void 0) delete next.angle;
|
|
@@ -371,7 +587,7 @@ function preserveAngle(incoming, current) {
|
|
|
371
587
|
return next;
|
|
372
588
|
}
|
|
373
589
|
function normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService) {
|
|
374
|
-
var _drawing$
|
|
590
|
+
var _drawing$transform2, _drawing$sheetTransfo2, _drawing$axisAlignShe2;
|
|
375
591
|
if (!drawing.drawingId || !drawing.unitId || !drawing.subUnitId || !hasIncomingAngle(drawing)) return drawing;
|
|
376
592
|
const current = sheetDrawingService.getDrawingByParam({
|
|
377
593
|
unitId: drawing.unitId,
|
|
@@ -382,7 +598,7 @@ function normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService) {
|
|
|
382
598
|
if (resolveSheetDrawingRotateEnabled({
|
|
383
599
|
...current,
|
|
384
600
|
...drawing,
|
|
385
|
-
drawingType:
|
|
601
|
+
drawingType: drawing.drawingType ?? current.drawingType,
|
|
386
602
|
transform: {
|
|
387
603
|
...current.transform,
|
|
388
604
|
...drawing.transform
|
|
@@ -398,7 +614,6 @@ const SetSheetDrawingCommand = {
|
|
|
398
614
|
id: "sheet.command.set-sheet-image",
|
|
399
615
|
type: CommandType.COMMAND,
|
|
400
616
|
handler: (accessor, params) => {
|
|
401
|
-
var _intercepted$preRedos, _intercepted$preUndos;
|
|
402
617
|
if (!params) return false;
|
|
403
618
|
const commandService = accessor.get(ICommandService);
|
|
404
619
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -416,7 +631,7 @@ const SetSheetDrawingCommand = {
|
|
|
416
631
|
params: normalizedParams
|
|
417
632
|
});
|
|
418
633
|
const redoMutations = [
|
|
419
|
-
...
|
|
634
|
+
...intercepted.preRedos ?? [],
|
|
420
635
|
{
|
|
421
636
|
id: SetDrawingApplyMutation.id,
|
|
422
637
|
params: {
|
|
@@ -434,7 +649,7 @@ const SetSheetDrawingCommand = {
|
|
|
434
649
|
...intercepted.redos
|
|
435
650
|
];
|
|
436
651
|
const undoMutations = [
|
|
437
|
-
...
|
|
652
|
+
...intercepted.preUndos ?? [],
|
|
438
653
|
{
|
|
439
654
|
id: SetDrawingApplyMutation.id,
|
|
440
655
|
params: {
|
|
@@ -518,6 +733,7 @@ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disp
|
|
|
518
733
|
InsertSheetDrawingCommand,
|
|
519
734
|
RemoveSheetDrawingCommand,
|
|
520
735
|
SetDrawingArrangeCommand,
|
|
736
|
+
SetSheetDrawingPlacementCommand,
|
|
521
737
|
ClearSheetDrawingTransformerOperation
|
|
522
738
|
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
523
739
|
}
|
|
@@ -652,7 +868,7 @@ SheetsDrawingLoadController = __decorate([
|
|
|
652
868
|
//#endregion
|
|
653
869
|
//#region package.json
|
|
654
870
|
var name = "@univerjs/sheets-drawing";
|
|
655
|
-
var version = "1.0.0-
|
|
871
|
+
var version = "1.0.0-beta.1";
|
|
656
872
|
|
|
657
873
|
//#endregion
|
|
658
874
|
//#region src/config/config.ts
|
|
@@ -733,10 +949,7 @@ var SheetDrawingTransformPlanService = class {
|
|
|
733
949
|
}
|
|
734
950
|
register(extension) {
|
|
735
951
|
this._extensions.push(extension);
|
|
736
|
-
this._extensions.sort((a, b) =>
|
|
737
|
-
var _b$priority, _a$priority;
|
|
738
|
-
return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
|
|
739
|
-
});
|
|
952
|
+
this._extensions.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
740
953
|
return toDisposable(() => {
|
|
741
954
|
const index = this._extensions.indexOf(extension);
|
|
742
955
|
if (index >= 0) this._extensions.splice(index, 1);
|
|
@@ -744,13 +957,12 @@ var SheetDrawingTransformPlanService = class {
|
|
|
744
957
|
}
|
|
745
958
|
transform(plan) {
|
|
746
959
|
return this._extensions.reduce((all, extension) => {
|
|
747
|
-
var _next$preRedos, _next$redos, _next$preUndos, _next$undos;
|
|
748
960
|
const next = extension.transform(plan);
|
|
749
961
|
if (!next) return all;
|
|
750
|
-
all.preRedos.push(...
|
|
751
|
-
all.redos.push(...
|
|
752
|
-
all.preUndos.push(...
|
|
753
|
-
all.undos.push(...
|
|
962
|
+
all.preRedos.push(...next.preRedos ?? []);
|
|
963
|
+
all.redos.push(...next.redos ?? []);
|
|
964
|
+
all.preUndos.push(...next.preUndos ?? []);
|
|
965
|
+
all.undos.push(...next.undos ?? []);
|
|
754
966
|
return all;
|
|
755
967
|
}, createEmptyResult());
|
|
756
968
|
}
|
|
@@ -947,7 +1159,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
947
1159
|
deletes: new Set(deletes.map(({ drawingId }) => drawingId).filter((drawingId) => Boolean(drawingId)))
|
|
948
1160
|
};
|
|
949
1161
|
updates.forEach((patch) => {
|
|
950
|
-
var _patch$sheetTransform, _patch$axisAlignSheet;
|
|
951
1162
|
if (!patch.drawingId) return;
|
|
952
1163
|
const original = originals.get(patch.drawingId);
|
|
953
1164
|
if (!original) return;
|
|
@@ -958,8 +1169,8 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
958
1169
|
...original.transform,
|
|
959
1170
|
...patch.transform
|
|
960
1171
|
},
|
|
961
|
-
sheetTransform:
|
|
962
|
-
axisAlignSheetTransform:
|
|
1172
|
+
sheetTransform: patch.sheetTransform ?? original.sheetTransform,
|
|
1173
|
+
axisAlignSheetTransform: patch.axisAlignSheetTransform ?? original.axisAlignSheetTransform
|
|
963
1174
|
});
|
|
964
1175
|
});
|
|
965
1176
|
const feature = this._transformPlanService.transform(plan);
|
|
@@ -1101,7 +1312,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1101
1312
|
drawingId
|
|
1102
1313
|
});
|
|
1103
1314
|
else {
|
|
1104
|
-
var _param$axisAlignSheet;
|
|
1105
1315
|
const param = this._shrinkCol(startColumn, endColumn, {
|
|
1106
1316
|
sheetSkeletonParam,
|
|
1107
1317
|
sheetTransform,
|
|
@@ -1110,7 +1320,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1110
1320
|
});
|
|
1111
1321
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1112
1322
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1113
|
-
axisAlignSheetTransform = (
|
|
1323
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1114
1324
|
}
|
|
1115
1325
|
else if (type === 1 && fromColumn >= startColumn && toColumn <= endColumn) if (fromRow >= startRow && toRow <= endRow) deleteDrawings.push({
|
|
1116
1326
|
unitId,
|
|
@@ -1118,7 +1328,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1118
1328
|
drawingId
|
|
1119
1329
|
});
|
|
1120
1330
|
else {
|
|
1121
|
-
var _param$axisAlignSheet2;
|
|
1122
1331
|
const param = this._shrinkRow(startRow, endRow, {
|
|
1123
1332
|
sheetSkeletonParam,
|
|
1124
1333
|
sheetTransform,
|
|
@@ -1127,10 +1336,9 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1127
1336
|
});
|
|
1128
1337
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1129
1338
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1130
|
-
axisAlignSheetTransform = (
|
|
1339
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1131
1340
|
}
|
|
1132
1341
|
else if (type === 2) {
|
|
1133
|
-
var _param$axisAlignSheet3;
|
|
1134
1342
|
const param = this._expandRow(startRow, endRow, {
|
|
1135
1343
|
sheetSkeletonParam,
|
|
1136
1344
|
sheetTransform,
|
|
@@ -1139,9 +1347,8 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1139
1347
|
});
|
|
1140
1348
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1141
1349
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1142
|
-
axisAlignSheetTransform = (
|
|
1350
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1143
1351
|
} else if (type === 3) {
|
|
1144
|
-
var _param$axisAlignSheet4;
|
|
1145
1352
|
const param = this._expandCol(startColumn, endColumn, {
|
|
1146
1353
|
sheetSkeletonParam,
|
|
1147
1354
|
sheetTransform,
|
|
@@ -1150,7 +1357,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1150
1357
|
});
|
|
1151
1358
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1152
1359
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1153
|
-
axisAlignSheetTransform = (
|
|
1360
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1154
1361
|
}
|
|
1155
1362
|
if (newSheetTransform && newTransform) {
|
|
1156
1363
|
const newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
|
|
@@ -1547,7 +1754,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1547
1754
|
let newTransform;
|
|
1548
1755
|
let axisAlignSheetTransform;
|
|
1549
1756
|
if (type === "insert") {
|
|
1550
|
-
var _param$axisAlignSheet5;
|
|
1551
1757
|
const param = this._expandRow(rowStartIndex, rowEndIndex, {
|
|
1552
1758
|
sheetSkeletonParam,
|
|
1553
1759
|
sheetTransform,
|
|
@@ -1556,7 +1762,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1556
1762
|
});
|
|
1557
1763
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1558
1764
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1559
|
-
axisAlignSheetTransform = (
|
|
1765
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1560
1766
|
} else {
|
|
1561
1767
|
const { from, to } = sheetTransform;
|
|
1562
1768
|
const { row: fromRow } = from;
|
|
@@ -1567,7 +1773,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1567
1773
|
drawingId
|
|
1568
1774
|
});
|
|
1569
1775
|
else {
|
|
1570
|
-
var _param$axisAlignSheet6;
|
|
1571
1776
|
const param = this._shrinkRow(rowStartIndex, rowEndIndex, {
|
|
1572
1777
|
sheetSkeletonParam,
|
|
1573
1778
|
sheetTransform,
|
|
@@ -1576,7 +1781,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1576
1781
|
});
|
|
1577
1782
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1578
1783
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1579
|
-
axisAlignSheetTransform = (
|
|
1784
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1580
1785
|
}
|
|
1581
1786
|
}
|
|
1582
1787
|
if (!newSheetTransform || !newTransform) return;
|
|
@@ -1617,7 +1822,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1617
1822
|
let newTransform;
|
|
1618
1823
|
let axisAlignSheetTransform;
|
|
1619
1824
|
if (type === "insert") {
|
|
1620
|
-
var _param$axisAlignSheet7;
|
|
1621
1825
|
const param = this._expandCol(colStartIndex, colEndIndex, {
|
|
1622
1826
|
sheetSkeletonParam,
|
|
1623
1827
|
sheetTransform,
|
|
@@ -1626,7 +1830,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1626
1830
|
});
|
|
1627
1831
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1628
1832
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1629
|
-
axisAlignSheetTransform = (
|
|
1833
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1630
1834
|
} else {
|
|
1631
1835
|
const { from, to } = sheetTransform;
|
|
1632
1836
|
const { column: fromColumn } = from;
|
|
@@ -1637,7 +1841,6 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1637
1841
|
drawingId
|
|
1638
1842
|
});
|
|
1639
1843
|
else {
|
|
1640
|
-
var _param$axisAlignSheet8;
|
|
1641
1844
|
const param = this._shrinkCol(colStartIndex, colEndIndex, {
|
|
1642
1845
|
sheetSkeletonParam,
|
|
1643
1846
|
sheetTransform,
|
|
@@ -1646,7 +1849,7 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1646
1849
|
});
|
|
1647
1850
|
newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
|
|
1648
1851
|
newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
|
|
1649
|
-
axisAlignSheetTransform = (
|
|
1852
|
+
axisAlignSheetTransform = (param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) ?? void 0;
|
|
1650
1853
|
}
|
|
1651
1854
|
}
|
|
1652
1855
|
if (!newSheetTransform || !newTransform) return;
|
|
@@ -1983,9 +2186,8 @@ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffecte
|
|
|
1983
2186
|
}));
|
|
1984
2187
|
}
|
|
1985
2188
|
_refreshDrawingTransform(command, unitId, subUnitId, ranges) {
|
|
1986
|
-
var _this$_drawingManager;
|
|
1987
2189
|
const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
|
|
1988
|
-
const drawingData =
|
|
2190
|
+
const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId) ?? {};
|
|
1989
2191
|
const updateDrawings = [];
|
|
1990
2192
|
Object.keys(drawingData).forEach((drawingId) => {
|
|
1991
2193
|
const drawing = drawingData[drawingId];
|
|
@@ -2071,4 +2273,4 @@ UniverSheetsDrawingPlugin = __decorate([
|
|
|
2071
2273
|
], UniverSheetsDrawingPlugin);
|
|
2072
2274
|
|
|
2073
2275
|
//#endregion
|
|
2074
|
-
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, drawingPositionToTransform, isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
2276
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, isKnownSheetNonRotatableDrawingType, normalizeSheetDrawingPlacement, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
import type { ICommand } from '@univerjs/core';
|
|
17
17
|
import type { IDrawingOrderMapParam } from '@univerjs/drawing';
|
|
18
18
|
import { ArrangeTypeEnum } from '@univerjs/core';
|
|
19
|
-
export
|
|
19
|
+
export type ISetDrawingArrangeCommandParams = IDrawingOrderMapParam & ({
|
|
20
20
|
arrangeType: ArrangeTypeEnum;
|
|
21
|
-
|
|
21
|
+
zOrder?: never;
|
|
22
|
+
} | {
|
|
23
|
+
arrangeType?: never;
|
|
24
|
+
zOrder: number;
|
|
25
|
+
});
|
|
22
26
|
export declare const SetDrawingArrangeCommand: ICommand;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { ICommand } from '@univerjs/core';
|
|
17
|
+
import type { ISheetDrawingPlacementInput } from '../../services/sheet-drawing-placement';
|
|
18
|
+
export interface ISetSheetDrawingPlacementCommandParams {
|
|
19
|
+
unitId: string;
|
|
20
|
+
subUnitId: string;
|
|
21
|
+
drawings: Array<{
|
|
22
|
+
drawingId: string;
|
|
23
|
+
placement: ISheetDrawingPlacementInput;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export declare const SetSheetDrawingPlacementCommand: ICommand<ISetSheetDrawingPlacementCommandParams>;
|