@univerjs/sheets-drawing 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1185 -1
- package/lib/cjs/index.js +697 -1
- package/lib/es/facade.js +1186 -1
- package/lib/es/index.js +678 -1
- package/lib/facade.js +1186 -1
- package/lib/index.js +678 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/es/index.js
CHANGED
|
@@ -1 +1,678 @@
|
|
|
1
|
-
import
|
|
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, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
|
|
3
|
+
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
4
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
5
|
+
|
|
6
|
+
//#region src/basics/transform-position.ts
|
|
7
|
+
function drawingPositionToTransform(position, sheetSkeletonParam) {
|
|
8
|
+
if (!sheetSkeletonParam) return;
|
|
9
|
+
const { unitId, sheetId, skeleton } = sheetSkeletonParam;
|
|
10
|
+
const { from, to, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = position;
|
|
11
|
+
let { left, top, width, height } = convertPositionSheetOverGridToAbsolute(unitId, sheetId, {
|
|
12
|
+
from,
|
|
13
|
+
to
|
|
14
|
+
}, skeleton);
|
|
15
|
+
const sheetWidth = skeleton.rowHeaderWidth + skeleton.columnTotalWidth;
|
|
16
|
+
const sheetHeight = skeleton.columnHeaderHeight + skeleton.rowTotalHeight;
|
|
17
|
+
if (left + width > sheetWidth) left = sheetWidth - width;
|
|
18
|
+
if (top + height > sheetHeight) top = sheetHeight - height;
|
|
19
|
+
return {
|
|
20
|
+
flipY,
|
|
21
|
+
flipX,
|
|
22
|
+
angle,
|
|
23
|
+
skewX,
|
|
24
|
+
skewY,
|
|
25
|
+
left,
|
|
26
|
+
top,
|
|
27
|
+
width,
|
|
28
|
+
height
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function transformToDrawingPosition(transform, skeleton) {
|
|
32
|
+
const { left = 0, top = 0, width = 0, height = 0, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = transform;
|
|
33
|
+
return {
|
|
34
|
+
flipY,
|
|
35
|
+
flipX,
|
|
36
|
+
angle,
|
|
37
|
+
skewX,
|
|
38
|
+
skewY,
|
|
39
|
+
from: skeleton.getCellIndexAndOffsetByPosition(left, top),
|
|
40
|
+
to: skeleton.getCellIndexAndOffsetByPosition(left + width, top + height)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* In excel, the basic drawing with rotate bound use major axis switch, axis-aligned bound will bu used.That means the position bound of drawing element will save as nearly axis-aligned rectangle.
|
|
45
|
+
* Here is the rule to convert transform to axis-aligned position:
|
|
46
|
+
* [-45°, 45°): use the original bound
|
|
47
|
+
* [45°, 135°): rotate the bound 90° clockwise,and the left, top, bottom,right will use the rotated bound.
|
|
48
|
+
* [135°, 225°): use the original bound
|
|
49
|
+
* [225°, 315°): rotate the bound 90° counterclockwise, and the left, top, bottom, right will use the rotated bound.
|
|
50
|
+
* @return The axis-aligned position of the drawing element.
|
|
51
|
+
*/
|
|
52
|
+
function transformToAxisAlignPosition(transform, skeleton) {
|
|
53
|
+
const { left = 0, top = 0, width = 0, height = 0, angle = 0 } = transform;
|
|
54
|
+
const norm = (angle % 360 + 360) % 360;
|
|
55
|
+
if (!(norm >= 45 && norm < 135 || norm >= 225 && norm < 315)) return transformToDrawingPosition(transform, skeleton);
|
|
56
|
+
return transformToDrawingPosition({
|
|
57
|
+
...transform,
|
|
58
|
+
left: left + width / 2 - height / 2,
|
|
59
|
+
top: top + height / 2 - width / 2,
|
|
60
|
+
width: height,
|
|
61
|
+
height: width
|
|
62
|
+
}, skeleton);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/services/sheet-drawing.service.ts
|
|
67
|
+
let SheetDrawingAnchorType = /* @__PURE__ */ function(SheetDrawingAnchorType) {
|
|
68
|
+
/**
|
|
69
|
+
* Only the position of the drawing follows the cell changes. When rows or columns are inserted or deleted, the position of the drawing changes, but the size remains the same.
|
|
70
|
+
*/
|
|
71
|
+
SheetDrawingAnchorType["Position"] = "0";
|
|
72
|
+
/**
|
|
73
|
+
* The size and position of the drawing follow the cell changes. When rows or columns are inserted or deleted, the size and position of the drawing change accordingly.
|
|
74
|
+
*/
|
|
75
|
+
SheetDrawingAnchorType["Both"] = "1";
|
|
76
|
+
/**
|
|
77
|
+
* The size and position of the drawing do not follow the cell changes. When rows or columns are inserted or deleted, the position and size of the drawing remain unchanged.
|
|
78
|
+
*/
|
|
79
|
+
SheetDrawingAnchorType["None"] = "2";
|
|
80
|
+
return SheetDrawingAnchorType;
|
|
81
|
+
}({});
|
|
82
|
+
var SheetDrawingService = class extends UnitDrawingService {};
|
|
83
|
+
const ISheetDrawingService = createIdentifier("sheets-drawing.sheet-drawing.service");
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/commands/mutations/set-drawing-apply.mutation.ts
|
|
87
|
+
let DrawingApplyType = /* @__PURE__ */ function(DrawingApplyType) {
|
|
88
|
+
DrawingApplyType[DrawingApplyType["INSERT"] = 0] = "INSERT";
|
|
89
|
+
DrawingApplyType[DrawingApplyType["REMOVE"] = 1] = "REMOVE";
|
|
90
|
+
DrawingApplyType[DrawingApplyType["UPDATE"] = 2] = "UPDATE";
|
|
91
|
+
DrawingApplyType[DrawingApplyType["ARRANGE"] = 3] = "ARRANGE";
|
|
92
|
+
DrawingApplyType[DrawingApplyType["GROUP"] = 4] = "GROUP";
|
|
93
|
+
DrawingApplyType[DrawingApplyType["UNGROUP"] = 5] = "UNGROUP";
|
|
94
|
+
return DrawingApplyType;
|
|
95
|
+
}({});
|
|
96
|
+
const SetDrawingApplyMutation = {
|
|
97
|
+
id: "sheet.mutation.set-drawing-apply",
|
|
98
|
+
type: CommandType.MUTATION,
|
|
99
|
+
handler: (accessor, params) => {
|
|
100
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
101
|
+
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
102
|
+
const { op, unitId, subUnitId, type, objects } = params;
|
|
103
|
+
drawingManagerService.applyJson1(unitId, subUnitId, op);
|
|
104
|
+
sheetDrawingService.applyJson1(unitId, subUnitId, op);
|
|
105
|
+
switch (type) {
|
|
106
|
+
case DrawingApplyType.INSERT:
|
|
107
|
+
drawingManagerService.addNotification(objects);
|
|
108
|
+
sheetDrawingService.addNotification(objects);
|
|
109
|
+
break;
|
|
110
|
+
case DrawingApplyType.REMOVE:
|
|
111
|
+
drawingManagerService.removeNotification(objects);
|
|
112
|
+
sheetDrawingService.removeNotification(objects);
|
|
113
|
+
break;
|
|
114
|
+
case DrawingApplyType.UPDATE:
|
|
115
|
+
drawingManagerService.updateNotification(objects);
|
|
116
|
+
sheetDrawingService.updateNotification(objects);
|
|
117
|
+
break;
|
|
118
|
+
case DrawingApplyType.ARRANGE:
|
|
119
|
+
drawingManagerService.orderNotification(objects);
|
|
120
|
+
sheetDrawingService.orderNotification(objects);
|
|
121
|
+
break;
|
|
122
|
+
case DrawingApplyType.GROUP:
|
|
123
|
+
drawingManagerService.groupUpdateNotification(objects);
|
|
124
|
+
sheetDrawingService.groupUpdateNotification(objects);
|
|
125
|
+
break;
|
|
126
|
+
case DrawingApplyType.UNGROUP:
|
|
127
|
+
drawingManagerService.ungroupUpdateNotification(objects);
|
|
128
|
+
sheetDrawingService.ungroupUpdateNotification(objects);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/commands/operations/clear-drawing-transformer.operation.ts
|
|
137
|
+
const ClearSheetDrawingTransformerOperation = {
|
|
138
|
+
id: "sheet.operation.clear-drawing-transformer",
|
|
139
|
+
type: CommandType.MUTATION,
|
|
140
|
+
handler: (accessor, params) => {
|
|
141
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
142
|
+
params.forEach((unitId) => {
|
|
143
|
+
var _renderManagerService;
|
|
144
|
+
(_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
|
|
145
|
+
});
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/commands/commands/insert-sheet-drawing.command.ts
|
|
152
|
+
const InsertSheetDrawingCommand = {
|
|
153
|
+
id: "sheet.command.insert-sheet-image",
|
|
154
|
+
type: CommandType.COMMAND,
|
|
155
|
+
handler: (accessor, params) => {
|
|
156
|
+
var _intercepted$preRedos, _intercepted$preUndos;
|
|
157
|
+
if (!params) return false;
|
|
158
|
+
const commandService = accessor.get(ICommandService);
|
|
159
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
160
|
+
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
161
|
+
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
162
|
+
const drawings = params.drawings;
|
|
163
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchAddOp(drawings);
|
|
164
|
+
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
165
|
+
id: InsertSheetDrawingCommand.id,
|
|
166
|
+
params
|
|
167
|
+
});
|
|
168
|
+
const redoMutations = [
|
|
169
|
+
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
170
|
+
{
|
|
171
|
+
id: SetDrawingApplyMutation.id,
|
|
172
|
+
params: {
|
|
173
|
+
unitId,
|
|
174
|
+
subUnitId,
|
|
175
|
+
op: redo,
|
|
176
|
+
objects,
|
|
177
|
+
type: DrawingApplyType.INSERT
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
182
|
+
params: [unitId]
|
|
183
|
+
},
|
|
184
|
+
...intercepted.redos
|
|
185
|
+
];
|
|
186
|
+
const undoMutations = [
|
|
187
|
+
...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
|
|
188
|
+
{
|
|
189
|
+
id: SetDrawingApplyMutation.id,
|
|
190
|
+
params: {
|
|
191
|
+
unitId,
|
|
192
|
+
subUnitId,
|
|
193
|
+
op: undo,
|
|
194
|
+
objects,
|
|
195
|
+
type: DrawingApplyType.REMOVE
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
200
|
+
params: [unitId]
|
|
201
|
+
},
|
|
202
|
+
...intercepted.undos
|
|
203
|
+
];
|
|
204
|
+
if (sequenceExecute(redoMutations, commandService)) {
|
|
205
|
+
undoRedoService.pushUndoRedo({
|
|
206
|
+
unitID: unitId,
|
|
207
|
+
undoMutations,
|
|
208
|
+
redoMutations
|
|
209
|
+
});
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/commands/commands/remove-sheet-drawing.command.ts
|
|
218
|
+
const RemoveSheetDrawingCommand = {
|
|
219
|
+
id: "sheet.command.remove-sheet-image",
|
|
220
|
+
type: CommandType.COMMAND,
|
|
221
|
+
handler: (accessor, params) => {
|
|
222
|
+
var _intercepted$preRedos, _intercepted$preUndos;
|
|
223
|
+
if (!params) return false;
|
|
224
|
+
const commandService = accessor.get(ICommandService);
|
|
225
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
226
|
+
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
227
|
+
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
228
|
+
const { drawings } = params;
|
|
229
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
|
|
230
|
+
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
231
|
+
id: RemoveSheetDrawingCommand.id,
|
|
232
|
+
params
|
|
233
|
+
});
|
|
234
|
+
const redoMutations = [
|
|
235
|
+
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
236
|
+
{
|
|
237
|
+
id: SetDrawingApplyMutation.id,
|
|
238
|
+
params: {
|
|
239
|
+
unitId,
|
|
240
|
+
subUnitId,
|
|
241
|
+
op: redo,
|
|
242
|
+
objects,
|
|
243
|
+
type: DrawingApplyType.REMOVE
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
248
|
+
params: [unitId]
|
|
249
|
+
},
|
|
250
|
+
...intercepted.redos
|
|
251
|
+
];
|
|
252
|
+
const undoMutations = [
|
|
253
|
+
...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
|
|
254
|
+
{
|
|
255
|
+
id: SetDrawingApplyMutation.id,
|
|
256
|
+
params: {
|
|
257
|
+
unitId,
|
|
258
|
+
subUnitId,
|
|
259
|
+
op: undo,
|
|
260
|
+
objects,
|
|
261
|
+
type: DrawingApplyType.INSERT
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
266
|
+
params: [unitId]
|
|
267
|
+
},
|
|
268
|
+
...intercepted.undos
|
|
269
|
+
];
|
|
270
|
+
if (sequenceExecute(redoMutations, commandService)) {
|
|
271
|
+
undoRedoService.pushUndoRedo({
|
|
272
|
+
unitID: unitId,
|
|
273
|
+
undoMutations,
|
|
274
|
+
redoMutations
|
|
275
|
+
});
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/commands/commands/set-drawing-arrange.command.ts
|
|
284
|
+
const SetDrawingArrangeCommand = {
|
|
285
|
+
id: "sheet.command.set-drawing-arrange",
|
|
286
|
+
type: CommandType.COMMAND,
|
|
287
|
+
handler: (accessor, params) => {
|
|
288
|
+
const commandService = accessor.get(ICommandService);
|
|
289
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
290
|
+
if (!params) return false;
|
|
291
|
+
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
292
|
+
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
293
|
+
const drawingOrderMapParam = {
|
|
294
|
+
unitId,
|
|
295
|
+
subUnitId,
|
|
296
|
+
drawingIds
|
|
297
|
+
};
|
|
298
|
+
let jsonOp;
|
|
299
|
+
if (arrangeType === ArrangeTypeEnum.forward) jsonOp = sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
300
|
+
else if (arrangeType === ArrangeTypeEnum.backward) jsonOp = sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
301
|
+
else if (arrangeType === ArrangeTypeEnum.front) jsonOp = sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
302
|
+
else if (arrangeType === ArrangeTypeEnum.back) jsonOp = sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
303
|
+
if (jsonOp == null) return false;
|
|
304
|
+
const { objects, redo, undo } = jsonOp;
|
|
305
|
+
if (commandService.syncExecuteCommand(SetDrawingApplyMutation.id, {
|
|
306
|
+
op: redo,
|
|
307
|
+
unitId,
|
|
308
|
+
subUnitId,
|
|
309
|
+
objects,
|
|
310
|
+
type: DrawingApplyType.ARRANGE
|
|
311
|
+
})) {
|
|
312
|
+
undoRedoService.pushUndoRedo({
|
|
313
|
+
unitID: unitId,
|
|
314
|
+
undoMutations: [{
|
|
315
|
+
id: SetDrawingApplyMutation.id,
|
|
316
|
+
params: {
|
|
317
|
+
op: undo,
|
|
318
|
+
unitId,
|
|
319
|
+
subUnitId,
|
|
320
|
+
objects,
|
|
321
|
+
type: DrawingApplyType.ARRANGE
|
|
322
|
+
}
|
|
323
|
+
}],
|
|
324
|
+
redoMutations: [{
|
|
325
|
+
id: SetDrawingApplyMutation.id,
|
|
326
|
+
params: {
|
|
327
|
+
op: redo,
|
|
328
|
+
unitId,
|
|
329
|
+
subUnitId,
|
|
330
|
+
objects,
|
|
331
|
+
type: DrawingApplyType.ARRANGE
|
|
332
|
+
}
|
|
333
|
+
}]
|
|
334
|
+
});
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/commands/commands/set-sheet-drawing.command.ts
|
|
343
|
+
const SetSheetDrawingCommand = {
|
|
344
|
+
id: "sheet.command.set-sheet-image",
|
|
345
|
+
type: CommandType.COMMAND,
|
|
346
|
+
handler: (accessor, params) => {
|
|
347
|
+
var _intercepted$preRedos, _intercepted$preUndos;
|
|
348
|
+
if (!params) return false;
|
|
349
|
+
const commandService = accessor.get(ICommandService);
|
|
350
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
351
|
+
const sheetDrawingService = accessor.get(ISheetDrawingService);
|
|
352
|
+
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
353
|
+
const { drawings } = params;
|
|
354
|
+
const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(drawings);
|
|
355
|
+
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
356
|
+
id: SetSheetDrawingCommand.id,
|
|
357
|
+
params
|
|
358
|
+
});
|
|
359
|
+
const redoMutations = [
|
|
360
|
+
...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
|
|
361
|
+
{
|
|
362
|
+
id: SetDrawingApplyMutation.id,
|
|
363
|
+
params: {
|
|
364
|
+
unitId,
|
|
365
|
+
subUnitId,
|
|
366
|
+
op: redo,
|
|
367
|
+
objects,
|
|
368
|
+
type: DrawingApplyType.UPDATE
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
373
|
+
params: [unitId]
|
|
374
|
+
},
|
|
375
|
+
...intercepted.redos
|
|
376
|
+
];
|
|
377
|
+
const undoMutations = [
|
|
378
|
+
...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
|
|
379
|
+
{
|
|
380
|
+
id: SetDrawingApplyMutation.id,
|
|
381
|
+
params: {
|
|
382
|
+
unitId,
|
|
383
|
+
subUnitId,
|
|
384
|
+
op: undo,
|
|
385
|
+
objects,
|
|
386
|
+
type: DrawingApplyType.UPDATE
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
id: ClearSheetDrawingTransformerOperation.id,
|
|
391
|
+
params: [unitId]
|
|
392
|
+
},
|
|
393
|
+
...intercepted.undos
|
|
394
|
+
];
|
|
395
|
+
if (sequenceExecute(redoMutations, commandService)) {
|
|
396
|
+
undoRedoService.pushUndoRedo({
|
|
397
|
+
unitID: unitId,
|
|
398
|
+
undoMutations,
|
|
399
|
+
redoMutations
|
|
400
|
+
});
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
409
|
+
function __decorateParam(paramIndex, decorator) {
|
|
410
|
+
return function(target, key) {
|
|
411
|
+
decorator(target, key, paramIndex);
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
417
|
+
function __decorate(decorators, target, key, desc) {
|
|
418
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
419
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
420
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
421
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/controllers/sheet-drawing.controller.ts
|
|
426
|
+
const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
|
|
427
|
+
let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disposable {
|
|
428
|
+
constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
|
|
429
|
+
super();
|
|
430
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
431
|
+
this._univerInstanceService = _univerInstanceService;
|
|
432
|
+
this._commandService = _commandService;
|
|
433
|
+
this._sheetDrawingService = _sheetDrawingService;
|
|
434
|
+
this._drawingManagerService = _drawingManagerService;
|
|
435
|
+
this._resourceManagerService = _resourceManagerService;
|
|
436
|
+
this._initCommands();
|
|
437
|
+
this._initSnapshot();
|
|
438
|
+
this._initSheetChange();
|
|
439
|
+
this.disposeWithMe(this._commandService.registerCommand(SetDrawingApplyMutation));
|
|
440
|
+
}
|
|
441
|
+
_initCommands() {
|
|
442
|
+
[
|
|
443
|
+
SetSheetDrawingCommand,
|
|
444
|
+
InsertSheetDrawingCommand,
|
|
445
|
+
RemoveSheetDrawingCommand,
|
|
446
|
+
SetDrawingArrangeCommand,
|
|
447
|
+
ClearSheetDrawingTransformerOperation
|
|
448
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
449
|
+
}
|
|
450
|
+
_initSnapshot() {
|
|
451
|
+
const toJson = (unitId, model) => {
|
|
452
|
+
const map = model || this._sheetDrawingService.getDrawingDataForUnit(unitId);
|
|
453
|
+
if (map) return JSON.stringify(map);
|
|
454
|
+
return "";
|
|
455
|
+
};
|
|
456
|
+
const parseJson = (json) => {
|
|
457
|
+
if (!json) return {};
|
|
458
|
+
try {
|
|
459
|
+
return JSON.parse(json);
|
|
460
|
+
} catch {
|
|
461
|
+
return {};
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
this.disposeWithMe(this._resourceManagerService.registerPluginResource({
|
|
465
|
+
pluginName: SHEET_DRAWING_PLUGIN,
|
|
466
|
+
businesses: [UniverInstanceType.UNIVER_SHEET],
|
|
467
|
+
toJson: (unitId, model) => toJson(unitId, model),
|
|
468
|
+
parseJson: (json) => parseJson(json),
|
|
469
|
+
onUnLoad: (unitId) => {
|
|
470
|
+
this._sheetDrawingService.removeDrawingDataForUnit(unitId);
|
|
471
|
+
this._drawingManagerService.removeDrawingDataForUnit(unitId);
|
|
472
|
+
},
|
|
473
|
+
onLoad: (unitId, value) => {
|
|
474
|
+
this._sheetDrawingService.registerDrawingData(unitId, value);
|
|
475
|
+
this._drawingManagerService.registerDrawingData(unitId, value);
|
|
476
|
+
}
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
_initSheetChange() {
|
|
480
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
|
|
481
|
+
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
482
|
+
var _getActiveSheet;
|
|
483
|
+
const params = commandInfo.params;
|
|
484
|
+
const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
|
|
485
|
+
const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
|
|
486
|
+
if (!unitId || !subUnitId) return {
|
|
487
|
+
redos: [],
|
|
488
|
+
undos: []
|
|
489
|
+
};
|
|
490
|
+
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
491
|
+
const drawings = Object.values(drawingData).filter((drawing) => {
|
|
492
|
+
if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
|
|
493
|
+
return true;
|
|
494
|
+
});
|
|
495
|
+
if (drawings.length === 0) return {
|
|
496
|
+
redos: [],
|
|
497
|
+
undos: []
|
|
498
|
+
};
|
|
499
|
+
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
|
|
500
|
+
return {
|
|
501
|
+
redos: [{
|
|
502
|
+
id: SetDrawingApplyMutation.id,
|
|
503
|
+
params: {
|
|
504
|
+
op: redo,
|
|
505
|
+
unitId: jsonOpUnitId,
|
|
506
|
+
subUnitId: jsonOpSubUnitId,
|
|
507
|
+
objects,
|
|
508
|
+
type: DrawingApplyType.REMOVE
|
|
509
|
+
}
|
|
510
|
+
}],
|
|
511
|
+
undos: [{
|
|
512
|
+
id: SetDrawingApplyMutation.id,
|
|
513
|
+
params: {
|
|
514
|
+
op: undo,
|
|
515
|
+
unitId: jsonOpUnitId,
|
|
516
|
+
subUnitId: jsonOpSubUnitId,
|
|
517
|
+
objects,
|
|
518
|
+
type: DrawingApplyType.INSERT
|
|
519
|
+
}
|
|
520
|
+
}]
|
|
521
|
+
};
|
|
522
|
+
} else if (commandInfo.id === CopySheetCommand.id) {
|
|
523
|
+
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
524
|
+
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
525
|
+
redos: [],
|
|
526
|
+
undos: []
|
|
527
|
+
};
|
|
528
|
+
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
|
|
529
|
+
const drawings = Object.values(drawingData).filter((drawing) => {
|
|
530
|
+
if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
|
|
531
|
+
return true;
|
|
532
|
+
}).map((drawing) => {
|
|
533
|
+
return {
|
|
534
|
+
...drawing,
|
|
535
|
+
subUnitId: targetSubUnitId,
|
|
536
|
+
drawingId: generateRandomId(6)
|
|
537
|
+
};
|
|
538
|
+
});
|
|
539
|
+
if (drawings.length === 0) return {
|
|
540
|
+
redos: [],
|
|
541
|
+
undos: []
|
|
542
|
+
};
|
|
543
|
+
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchAddOp(drawings);
|
|
544
|
+
return {
|
|
545
|
+
redos: [{
|
|
546
|
+
id: SetDrawingApplyMutation.id,
|
|
547
|
+
params: {
|
|
548
|
+
op: redo,
|
|
549
|
+
unitId: jsonOpUnitId,
|
|
550
|
+
subUnitId: jsonOpSubUnitId,
|
|
551
|
+
objects,
|
|
552
|
+
type: DrawingApplyType.INSERT
|
|
553
|
+
}
|
|
554
|
+
}],
|
|
555
|
+
undos: [{
|
|
556
|
+
id: SetDrawingApplyMutation.id,
|
|
557
|
+
params: {
|
|
558
|
+
op: undo,
|
|
559
|
+
unitId: jsonOpUnitId,
|
|
560
|
+
subUnitId: jsonOpSubUnitId,
|
|
561
|
+
objects,
|
|
562
|
+
type: DrawingApplyType.REMOVE
|
|
563
|
+
}
|
|
564
|
+
}]
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
return {
|
|
568
|
+
redos: [],
|
|
569
|
+
undos: []
|
|
570
|
+
};
|
|
571
|
+
} }));
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
SheetsDrawingLoadController = __decorate([
|
|
575
|
+
__decorateParam(0, Inject(SheetInterceptorService)),
|
|
576
|
+
__decorateParam(1, Inject(IUniverInstanceService)),
|
|
577
|
+
__decorateParam(2, ICommandService),
|
|
578
|
+
__decorateParam(3, ISheetDrawingService),
|
|
579
|
+
__decorateParam(4, IDrawingManagerService),
|
|
580
|
+
__decorateParam(5, IResourceManagerService)
|
|
581
|
+
], SheetsDrawingLoadController);
|
|
582
|
+
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region package.json
|
|
585
|
+
var name = "@univerjs/sheets-drawing";
|
|
586
|
+
var version = "0.21.0";
|
|
587
|
+
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/config/config.ts
|
|
590
|
+
/**
|
|
591
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
592
|
+
*
|
|
593
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
594
|
+
* you may not use this file except in compliance with the License.
|
|
595
|
+
* You may obtain a copy of the License at
|
|
596
|
+
*
|
|
597
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
598
|
+
*
|
|
599
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
600
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
601
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
602
|
+
* See the License for the specific language governing permissions and
|
|
603
|
+
* limitations under the License.
|
|
604
|
+
*/
|
|
605
|
+
const SHEETS_DRAWING_PLUGIN_CONFIG_KEY = "sheets-drawing.config";
|
|
606
|
+
const configSymbol = Symbol(SHEETS_DRAWING_PLUGIN_CONFIG_KEY);
|
|
607
|
+
const defaultPluginConfig = {};
|
|
608
|
+
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
611
|
+
function _typeof(o) {
|
|
612
|
+
"@babel/helpers - typeof";
|
|
613
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
614
|
+
return typeof o;
|
|
615
|
+
} : function(o) {
|
|
616
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
617
|
+
}, _typeof(o);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
622
|
+
function toPrimitive(t, r) {
|
|
623
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
624
|
+
var e = t[Symbol.toPrimitive];
|
|
625
|
+
if (void 0 !== e) {
|
|
626
|
+
var i = e.call(t, r || "default");
|
|
627
|
+
if ("object" != _typeof(i)) return i;
|
|
628
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
629
|
+
}
|
|
630
|
+
return ("string" === r ? String : Number)(t);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
635
|
+
function toPropertyKey(t) {
|
|
636
|
+
var i = toPrimitive(t, "string");
|
|
637
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
642
|
+
function _defineProperty(e, r, t) {
|
|
643
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
644
|
+
value: t,
|
|
645
|
+
enumerable: !0,
|
|
646
|
+
configurable: !0,
|
|
647
|
+
writable: !0
|
|
648
|
+
}) : e[r] = t, e;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
//#endregion
|
|
652
|
+
//#region src/plugin.ts
|
|
653
|
+
let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends Plugin {
|
|
654
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
655
|
+
super();
|
|
656
|
+
this._config = _config;
|
|
657
|
+
this._injector = _injector;
|
|
658
|
+
this._configService = _configService;
|
|
659
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
660
|
+
this._configService.setConfig(SHEETS_DRAWING_PLUGIN_CONFIG_KEY, rest);
|
|
661
|
+
}
|
|
662
|
+
onStarting() {
|
|
663
|
+
[[SheetsDrawingLoadController], [ISheetDrawingService, { useClass: SheetDrawingService }]].forEach((dependency) => this._injector.add(dependency));
|
|
664
|
+
this._injector.get(SheetsDrawingLoadController);
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
_defineProperty(UniverSheetsDrawingPlugin, "pluginName", SHEET_DRAWING_PLUGIN);
|
|
668
|
+
_defineProperty(UniverSheetsDrawingPlugin, "packageName", name);
|
|
669
|
+
_defineProperty(UniverSheetsDrawingPlugin, "version", version);
|
|
670
|
+
_defineProperty(UniverSheetsDrawingPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
671
|
+
UniverSheetsDrawingPlugin = __decorate([
|
|
672
|
+
DependentOn(UniverDrawingPlugin),
|
|
673
|
+
__decorateParam(1, Inject(Injector)),
|
|
674
|
+
__decorateParam(2, IConfigService)
|
|
675
|
+
], UniverSheetsDrawingPlugin);
|
|
676
|
+
|
|
677
|
+
//#endregion
|
|
678
|
+
export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition };
|