@univerjs/docs-drawing-ui 1.0.0-alpha.2 → 1.0.0-alpha.4
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/index.js +806 -959
- package/lib/es/index.js +791 -943
- package/lib/index.js +791 -943
- package/lib/types/commands/commands/update-doc-drawing.command.d.ts +1 -34
- package/lib/types/controllers/doc-drawing-notification.controller.d.ts +5 -1
- package/lib/types/controllers/doc-float-dom.controller.d.ts +11 -1
- package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +2 -1
- package/lib/types/controllers/render-controllers/doc-drawing-update.render-controller.d.ts +2 -2
- package/lib/types/index.d.ts +4 -4
- package/lib/types/menu/drawing-popup-menu.controller.d.ts +6 -2
- package/lib/types/services/doc-drawing-floating-toolbar-adapter.service.d.ts +54 -0
- package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
- package/lib/types/commands/commands/insert-doc-drawing.command.d.ts +0 -20
- package/lib/types/commands/commands/interfaces.d.ts +0 -35
- package/lib/types/commands/commands/remove-doc-drawing.command.d.ts +0 -20
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +0 -25
package/lib/es/index.js
CHANGED
|
@@ -1,87 +1,16 @@
|
|
|
1
|
-
import { AlignTypeH, AlignTypeV,
|
|
2
|
-
import { IDocDrawingService, UniverDocsDrawingPlugin, getDocDrawingRenderOrder } from "@univerjs/docs-drawing";
|
|
3
|
-
import { DocContentInsertService, DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from "@univerjs/docs";
|
|
4
|
-
import { DOC_CONTENT_INSERT_MENU_ID, DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID, DOC_PARAGRAPH_T_INSERT_MENU_ID, DocCanvasPopManagerService, DocPrintInterceptorService, DocSelectionRenderService, EMPTY_PARAGRAPH_MENU_ID, IEditorService, INSERT_BELLOW_MENU_ID, NodePositionConvertToCursor, SetDocZoomRatioOperation, TEXT_RANGE_LAYER_INDEX, VIEWPORT_KEY, docDrawingPositionToTransform, getAnchorBounding, getCustomBlockIdsInSelections, getDocObject, getOneTextSelectionRange } from "@univerjs/docs-ui";
|
|
1
|
+
import { AlignTypeH, AlignTypeV, BooleanNumber, COLORS, CommandType, DOC_DRAWING_PRINTING_COMPONENT_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, ICommandService, IConfigService, IContextService, IImageIoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, JSONX, LifecycleService, LifecycleStages, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, Plugin, PositionedObjectLayoutType, RedoCommand, RxDisposable, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, WrapTextType, fromEventSubject, generateRandomId, getRichTextEditPath, isInternalEditorID, merge, throttle, toDisposable } from "@univerjs/core";
|
|
2
|
+
import { IDocDrawingAdapterService, IDocDrawingService, InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UniverDocsDrawingPlugin, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, getDocDrawingRenderOrder } from "@univerjs/docs-drawing";
|
|
5
3
|
import { CURSOR_TYPE, DocumentEditArea, DocumentSkeletonPageType, IRenderManagerService, Liquid, PageLayoutType, Rect, TRANSFORM_CHANGE_OBSERVABLE_TYPE, Vector2, getColor, getCurrentTypeOfRenderer, getDocsTableRenderViewport, getTableIdAndSliceIndex } from "@univerjs/engine-render";
|
|
6
4
|
import { Checkbox, InputNumber, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation, buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
|
|
6
|
+
import { DOC_CONTENT_INSERT_MENU_ID, DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID, DOC_PARAGRAPH_T_INSERT_MENU_ID, DocCanvasPopManagerService, DocPrintInterceptorService, DocSelectionRenderService, EMPTY_PARAGRAPH_MENU_ID, IEditorService, INSERT_BELLOW_MENU_ID, NodePositionConvertToCursor, SetDocZoomRatioOperation, TEXT_RANGE_LAYER_INDEX, VIEWPORT_KEY, getAnchorBounding, getDocObject, getOneTextSelectionRange } from "@univerjs/docs-ui";
|
|
7
|
+
import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
|
|
8
|
+
import { CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, UniverUIPlugin, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
9
9
|
import { BehaviorSubject, Observable, debounceTime, filter, map, of, switchMap, takeUntil } from "rxjs";
|
|
10
10
|
import { COMPONENT_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
|
|
11
11
|
import { useEffect, useMemo, useState } from "react";
|
|
12
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
|
|
14
|
-
//#region src/commands/commands/remove-doc-drawing.command.ts
|
|
15
|
-
/**
|
|
16
|
-
* The command to remove new sheet image
|
|
17
|
-
*/
|
|
18
|
-
const RemoveDocDrawingCommand = {
|
|
19
|
-
id: "doc.command.remove-doc-image",
|
|
20
|
-
type: CommandType.COMMAND,
|
|
21
|
-
handler: (accessor, params) => {
|
|
22
|
-
var _docSelectionRenderSe, _documentDataModel$ge, _documentDataModel$ge2;
|
|
23
|
-
const commandService = accessor.get(ICommandService);
|
|
24
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
25
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
26
|
-
const documentDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
27
|
-
if (params == null || documentDataModel == null) return false;
|
|
28
|
-
const docSelectionRenderService = renderManagerService.getRenderById(params.unitId).with(DocSelectionRenderService);
|
|
29
|
-
const { drawings: removeDrawings } = params;
|
|
30
|
-
const segmentId = (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "";
|
|
31
|
-
const textX = new TextX();
|
|
32
|
-
const jsonX = JSONX.getInstance();
|
|
33
|
-
const customBlocks = (_documentDataModel$ge = (_documentDataModel$ge2 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.customBlocks) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : [];
|
|
34
|
-
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
35
|
-
const unitId = removeDrawings[0].unitId;
|
|
36
|
-
const memoryCursor = new MemoryCursor();
|
|
37
|
-
memoryCursor.reset();
|
|
38
|
-
const cursorIndex = removeCustomBlocks[0].startIndex;
|
|
39
|
-
const textRanges = [{
|
|
40
|
-
startOffset: cursorIndex,
|
|
41
|
-
endOffset: cursorIndex
|
|
42
|
-
}];
|
|
43
|
-
const doMutation = {
|
|
44
|
-
id: RichTextEditingMutation.id,
|
|
45
|
-
params: {
|
|
46
|
-
unitId,
|
|
47
|
-
actions: [],
|
|
48
|
-
textRanges
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const rawActions = [];
|
|
52
|
-
for (const block of removeCustomBlocks) {
|
|
53
|
-
const { startIndex } = block;
|
|
54
|
-
if (startIndex > memoryCursor.cursor) textX.push({
|
|
55
|
-
t: TextXActionType.RETAIN,
|
|
56
|
-
len: startIndex - memoryCursor.cursor
|
|
57
|
-
});
|
|
58
|
-
textX.push({
|
|
59
|
-
t: TextXActionType.DELETE,
|
|
60
|
-
len: 1
|
|
61
|
-
});
|
|
62
|
-
memoryCursor.moveCursorTo(startIndex + 1);
|
|
63
|
-
}
|
|
64
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
65
|
-
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
66
|
-
for (const block of removeCustomBlocks) {
|
|
67
|
-
var _documentDataModel$ge3;
|
|
68
|
-
const { blockId } = block;
|
|
69
|
-
const drawing = ((_documentDataModel$ge3 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : {})[blockId];
|
|
70
|
-
const drawingIndex = documentDataModel.getDrawingsOrder().indexOf(blockId);
|
|
71
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing);
|
|
72
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
73
|
-
rawActions.push(removeDrawingAction);
|
|
74
|
-
rawActions.push(removeDrawingOrderAction);
|
|
75
|
-
}
|
|
76
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
77
|
-
return JSONX.compose(acc, cur);
|
|
78
|
-
}, null);
|
|
79
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
80
|
-
return Boolean(result);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
14
|
//#region src/commands/commands/delete-doc-drawing.command.ts
|
|
86
15
|
const DeleteDocDrawingsCommand = {
|
|
87
16
|
id: "doc.command.delete-drawing",
|
|
@@ -120,168 +49,6 @@ const GroupDocDrawingCommand = {
|
|
|
120
49
|
}
|
|
121
50
|
};
|
|
122
51
|
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/commands/commands/insert-doc-drawing.command.ts
|
|
125
|
-
/**
|
|
126
|
-
* The command to insert new drawings
|
|
127
|
-
*/
|
|
128
|
-
const InsertDocDrawingCommand = {
|
|
129
|
-
id: "doc.command.insert-doc-image",
|
|
130
|
-
type: CommandType.COMMAND,
|
|
131
|
-
handler: (accessor, params) => {
|
|
132
|
-
var _ref, _contentInsertRange$s, _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3;
|
|
133
|
-
if (params == null) return false;
|
|
134
|
-
const commandService = accessor.get(ICommandService);
|
|
135
|
-
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
136
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
137
|
-
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
138
|
-
const documentDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
139
|
-
if (documentDataModel == null) return false;
|
|
140
|
-
const unitId = documentDataModel.getUnitId();
|
|
141
|
-
const contentInsertRange = getContentInsertRange(accessor, unitId);
|
|
142
|
-
const targetTextRange = contentInsertRange ? {
|
|
143
|
-
...activeTextRange,
|
|
144
|
-
startOffset: contentInsertRange.startOffset,
|
|
145
|
-
endOffset: contentInsertRange.endOffset,
|
|
146
|
-
collapsed: contentInsertRange.startOffset === contentInsertRange.endOffset,
|
|
147
|
-
segmentId: (_ref = (_contentInsertRange$s = contentInsertRange.segmentId) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) !== null && _ref !== void 0 ? _ref : ""
|
|
148
|
-
} : activeTextRange;
|
|
149
|
-
if (targetTextRange == null) return false;
|
|
150
|
-
const { drawings } = params;
|
|
151
|
-
const { collapsed, startOffset, segmentId = "" } = targetTextRange;
|
|
152
|
-
const body = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
153
|
-
if (body == null) return false;
|
|
154
|
-
const textX = new TextX();
|
|
155
|
-
const jsonX = JSONX.getInstance();
|
|
156
|
-
const rawActions = [];
|
|
157
|
-
const drawingOrderLength = (_documentDataModel$ge2 = (_documentDataModel$ge3 = documentDataModel.getSnapshot().drawingsOrder) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.length) !== null && _documentDataModel$ge2 !== void 0 ? _documentDataModel$ge2 : 0;
|
|
158
|
-
let removeDrawingLen = 0;
|
|
159
|
-
if (collapsed) {
|
|
160
|
-
if (startOffset > 0) textX.push({
|
|
161
|
-
t: TextXActionType.RETAIN,
|
|
162
|
-
len: startOffset
|
|
163
|
-
});
|
|
164
|
-
} else {
|
|
165
|
-
var _documentDataModel$ge4, _documentDataModel$ge5;
|
|
166
|
-
const dos = BuildTextUtils.selection.delete([targetTextRange], body, 0, null, false);
|
|
167
|
-
textX.push(...dos);
|
|
168
|
-
const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [targetTextRange]);
|
|
169
|
-
const drawings = (_documentDataModel$ge4 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge4 !== void 0 ? _documentDataModel$ge4 : {};
|
|
170
|
-
const drawingOrder = (_documentDataModel$ge5 = documentDataModel.getDrawingsOrder()) !== null && _documentDataModel$ge5 !== void 0 ? _documentDataModel$ge5 : [];
|
|
171
|
-
const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
|
|
172
|
-
if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
|
|
173
|
-
else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
|
|
174
|
-
return 0;
|
|
175
|
-
});
|
|
176
|
-
if (sortedRemovedCustomBlockIds.length > 0) for (const blockId of sortedRemovedCustomBlockIds) {
|
|
177
|
-
const drawing = drawings[blockId];
|
|
178
|
-
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
179
|
-
if (drawing == null || drawingIndex < 0) continue;
|
|
180
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing);
|
|
181
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
182
|
-
rawActions.push(removeDrawingAction);
|
|
183
|
-
rawActions.push(removeDrawingOrderAction);
|
|
184
|
-
removeDrawingLen++;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
textX.push({
|
|
188
|
-
t: TextXActionType.INSERT,
|
|
189
|
-
body: {
|
|
190
|
-
dataStream: "\b".repeat(drawings.length),
|
|
191
|
-
customBlocks: drawings.map((drawing, i) => ({
|
|
192
|
-
startIndex: i,
|
|
193
|
-
blockId: drawing.drawingId
|
|
194
|
-
}))
|
|
195
|
-
},
|
|
196
|
-
len: drawings.length
|
|
197
|
-
});
|
|
198
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
199
|
-
const placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
200
|
-
rawActions.push(placeHolderAction);
|
|
201
|
-
for (const drawing of drawings) {
|
|
202
|
-
const { drawingId } = drawing;
|
|
203
|
-
const addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing);
|
|
204
|
-
const addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
205
|
-
rawActions.push(addDrawingAction);
|
|
206
|
-
rawActions.push(addDrawingOrderAction);
|
|
207
|
-
}
|
|
208
|
-
const doMutation = {
|
|
209
|
-
id: RichTextEditingMutation.id,
|
|
210
|
-
params: {
|
|
211
|
-
unitId,
|
|
212
|
-
actions: [],
|
|
213
|
-
textRanges: []
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
217
|
-
return JSONX.compose(acc, cur);
|
|
218
|
-
}, null);
|
|
219
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
220
|
-
return Boolean(result);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
function getContentInsertRange(accessor, unitId) {
|
|
224
|
-
try {
|
|
225
|
-
const range = accessor.get(DocContentInsertService).consumeInsertRange(unitId);
|
|
226
|
-
if (range == null) return null;
|
|
227
|
-
return {
|
|
228
|
-
startOffset: range.startOffset,
|
|
229
|
-
endOffset: range.endOffset,
|
|
230
|
-
collapsed: range.startOffset === range.endOffset,
|
|
231
|
-
segmentId: range.segmentId
|
|
232
|
-
};
|
|
233
|
-
} catch {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
//#endregion
|
|
239
|
-
//#region src/commands/commands/set-drawing-arrange.command.ts
|
|
240
|
-
/**
|
|
241
|
-
* The command to arrange drawings.
|
|
242
|
-
*/
|
|
243
|
-
const SetDocDrawingArrangeCommand = {
|
|
244
|
-
id: "doc.command.set-drawing-arrange",
|
|
245
|
-
type: CommandType.COMMAND,
|
|
246
|
-
handler: (accessor, params) => {
|
|
247
|
-
const commandService = accessor.get(ICommandService);
|
|
248
|
-
const docDrawingService = accessor.get(IDocDrawingService);
|
|
249
|
-
if (params == null) return false;
|
|
250
|
-
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
251
|
-
const drawingOrderMapParam = {
|
|
252
|
-
unitId,
|
|
253
|
-
subUnitId,
|
|
254
|
-
drawingIds
|
|
255
|
-
};
|
|
256
|
-
let jsonOp;
|
|
257
|
-
if (arrangeType === ArrangeTypeEnum.forward) jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
258
|
-
else if (arrangeType === ArrangeTypeEnum.backward) jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
259
|
-
else if (arrangeType === ArrangeTypeEnum.front) jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
260
|
-
else if (arrangeType === ArrangeTypeEnum.back) jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
261
|
-
if (jsonOp == null) return false;
|
|
262
|
-
const { redo } = jsonOp;
|
|
263
|
-
if (redo == null) return false;
|
|
264
|
-
const rawActions = [];
|
|
265
|
-
let redoCopy = Tools.deepClone(redo);
|
|
266
|
-
redoCopy = redoCopy.slice(3);
|
|
267
|
-
redoCopy.unshift("drawingsOrder");
|
|
268
|
-
rawActions.push(redoCopy);
|
|
269
|
-
const doMutation = {
|
|
270
|
-
id: RichTextEditingMutation.id,
|
|
271
|
-
params: {
|
|
272
|
-
unitId,
|
|
273
|
-
actions: [],
|
|
274
|
-
textRanges: null
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
278
|
-
return JSONX.compose(acc, cur);
|
|
279
|
-
}, null);
|
|
280
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
281
|
-
return Boolean(result);
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
|
|
285
52
|
//#endregion
|
|
286
53
|
//#region src/commands/commands/ungroup-doc-drawing.command.ts
|
|
287
54
|
/**
|
|
@@ -503,25 +270,10 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
|
|
|
503
270
|
}
|
|
504
271
|
_getImagePosition(imageWidth, imageHeight, insertPosition) {
|
|
505
272
|
var _ref;
|
|
506
|
-
|
|
273
|
+
return buildDocTransform(imageWidth, imageHeight, { left: ((_ref = insertPosition !== null && insertPosition !== void 0 ? insertPosition : this._getCurrentImageInsertPosition()) !== null && _ref !== void 0 ? _ref : {
|
|
507
274
|
left: 0,
|
|
508
275
|
top: 0
|
|
509
|
-
};
|
|
510
|
-
return {
|
|
511
|
-
size: {
|
|
512
|
-
width: imageWidth,
|
|
513
|
-
height: imageHeight
|
|
514
|
-
},
|
|
515
|
-
positionH: {
|
|
516
|
-
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
517
|
-
posOffset: position.left
|
|
518
|
-
},
|
|
519
|
-
positionV: {
|
|
520
|
-
relativeFrom: ObjectRelativeFromV.PARAGRAPH,
|
|
521
|
-
posOffset: 0
|
|
522
|
-
},
|
|
523
|
-
angle: 0
|
|
524
|
-
};
|
|
276
|
+
}).left });
|
|
525
277
|
}
|
|
526
278
|
_getCurrentImageInsertPosition() {
|
|
527
279
|
var _this$_docSelectionRe;
|
|
@@ -665,7 +417,10 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
|
|
|
665
417
|
});
|
|
666
418
|
}));
|
|
667
419
|
this.disposeWithMe(this._commandService.onCommandExecuted(async (command) => {
|
|
668
|
-
if (command.id
|
|
420
|
+
if (command.id !== RichTextEditingMutation.id) return;
|
|
421
|
+
const params = command.params;
|
|
422
|
+
if ((params === null || params === void 0 ? void 0 : params.unitId) && params.unitId !== this._context.unitId) return;
|
|
423
|
+
queueMicrotask(() => {
|
|
669
424
|
this._updateDrawingsEditStatus();
|
|
670
425
|
});
|
|
671
426
|
}));
|
|
@@ -722,23 +477,6 @@ function createShapeSvgSource(shape, width, height) {
|
|
|
722
477
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" fill="none">${shape === "ellipse" ? `<ellipse cx="${width / 2}" cy="${height / 2}" rx="${(width - 8) / 2}" ry="${(height - 8) / 2}" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />` : `<rect x="4" y="4" width="${width - 8}" height="${height - 8}" rx="14" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />`}</svg>`;
|
|
723
478
|
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
724
479
|
}
|
|
725
|
-
function createDefaultDocTransform(width, height) {
|
|
726
|
-
return {
|
|
727
|
-
size: {
|
|
728
|
-
width,
|
|
729
|
-
height
|
|
730
|
-
},
|
|
731
|
-
positionH: {
|
|
732
|
-
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
733
|
-
posOffset: 0
|
|
734
|
-
},
|
|
735
|
-
positionV: {
|
|
736
|
-
relativeFrom: ObjectRelativeFromV.PARAGRAPH,
|
|
737
|
-
posOffset: 0
|
|
738
|
-
},
|
|
739
|
-
angle: 0
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
480
|
function createShapeInsertCommand(shape, width, height, id) {
|
|
743
481
|
return {
|
|
744
482
|
id,
|
|
@@ -748,7 +486,7 @@ function createShapeInsertCommand(shape, width, height, id) {
|
|
|
748
486
|
const commandService = accessor.get(ICommandService);
|
|
749
487
|
const unitId = (_univerInstanceServic = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
|
|
750
488
|
if (!unitId) return false;
|
|
751
|
-
const docTransform =
|
|
489
|
+
const docTransform = buildDocTransform(width, height);
|
|
752
490
|
return commandService.executeCommand(InsertDocDrawingCommand.id, {
|
|
753
491
|
unitId,
|
|
754
492
|
drawings: [{
|
|
@@ -778,534 +516,13 @@ const InsertDocRectangleShapeCommand = createShapeInsertCommand("rectangle", 144
|
|
|
778
516
|
const InsertDocEllipseShapeCommand = createShapeInsertCommand("ellipse", 112, 112, "doc.command.insert-float-shape.ellipse");
|
|
779
517
|
|
|
780
518
|
//#endregion
|
|
781
|
-
//#region src/commands/commands/
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
["wrapSquare"]: PositionedObjectLayoutType.WRAP_SQUARE,
|
|
785
|
-
["wrapTopAndBottom"]: PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,
|
|
786
|
-
["inFrontOfText"]: PositionedObjectLayoutType.WRAP_NONE,
|
|
787
|
-
["behindText"]: PositionedObjectLayoutType.WRAP_NONE
|
|
788
|
-
};
|
|
789
|
-
function findDrawingAnchorInPage(page, drawingId, pageMarginTop, pageMarginLeft) {
|
|
790
|
-
const skeDrawing = page.skeDrawings.get(drawingId);
|
|
791
|
-
if (skeDrawing) return {
|
|
792
|
-
skeDrawing,
|
|
793
|
-
pageMarginTop,
|
|
794
|
-
pageMarginLeft
|
|
795
|
-
};
|
|
796
|
-
for (const table of page.skeTables.values()) for (const row of table.rows) for (const cell of row.cells) {
|
|
797
|
-
const cellAnchor = findDrawingAnchorInPage(cell, drawingId, cell.marginTop, cell.marginLeft);
|
|
798
|
-
if (cellAnchor) return cellAnchor;
|
|
799
|
-
}
|
|
800
|
-
return null;
|
|
801
|
-
}
|
|
802
|
-
function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, docSelectionRenderManager) {
|
|
803
|
-
var _documentDataModel$ge, _documentDataModel$ge2, _oldBody$customBlocks;
|
|
804
|
-
const textX = new TextX();
|
|
805
|
-
const jsonX = JSONX.getInstance();
|
|
806
|
-
const rawActions = [];
|
|
807
|
-
const oldBody = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
808
|
-
const body = (_documentDataModel$ge2 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.getBody();
|
|
809
|
-
if (oldBody == null || body == null) return;
|
|
810
|
-
const oldOffset = (_oldBody$customBlocks = oldBody.customBlocks) === null || _oldBody$customBlocks === void 0 || (_oldBody$customBlocks = _oldBody$customBlocks.find((block) => block.blockId === drawingId)) === null || _oldBody$customBlocks === void 0 ? void 0 : _oldBody$customBlocks.startIndex;
|
|
811
|
-
if (oldOffset == null) return;
|
|
812
|
-
offset = Math.min(body.dataStream.length - 2, offset);
|
|
813
|
-
if (segmentId === oldSegmentId) {
|
|
814
|
-
if (offset < oldOffset) {
|
|
815
|
-
if (offset > 0) textX.push({
|
|
816
|
-
t: TextXActionType.RETAIN,
|
|
817
|
-
len: offset
|
|
818
|
-
});
|
|
819
|
-
textX.push({
|
|
820
|
-
t: TextXActionType.INSERT,
|
|
821
|
-
body: {
|
|
822
|
-
dataStream: "\b",
|
|
823
|
-
customBlocks: [{
|
|
824
|
-
startIndex: 0,
|
|
825
|
-
blockId: drawingId
|
|
826
|
-
}]
|
|
827
|
-
},
|
|
828
|
-
len: 1
|
|
829
|
-
});
|
|
830
|
-
textX.push({
|
|
831
|
-
t: TextXActionType.RETAIN,
|
|
832
|
-
len: oldOffset - offset
|
|
833
|
-
});
|
|
834
|
-
textX.push({
|
|
835
|
-
t: TextXActionType.DELETE,
|
|
836
|
-
len: 1
|
|
837
|
-
});
|
|
838
|
-
} else {
|
|
839
|
-
if (oldOffset > 0) textX.push({
|
|
840
|
-
t: TextXActionType.RETAIN,
|
|
841
|
-
len: oldOffset
|
|
842
|
-
});
|
|
843
|
-
textX.push({
|
|
844
|
-
t: TextXActionType.DELETE,
|
|
845
|
-
len: 1
|
|
846
|
-
});
|
|
847
|
-
if (offset - oldOffset - 1 > 0) textX.push({
|
|
848
|
-
t: TextXActionType.RETAIN,
|
|
849
|
-
len: offset - oldOffset - 1
|
|
850
|
-
});
|
|
851
|
-
textX.push({
|
|
852
|
-
t: TextXActionType.INSERT,
|
|
853
|
-
body: {
|
|
854
|
-
dataStream: "\b",
|
|
855
|
-
customBlocks: [{
|
|
856
|
-
startIndex: 0,
|
|
857
|
-
blockId: drawingId
|
|
858
|
-
}]
|
|
859
|
-
},
|
|
860
|
-
len: 1
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
if (offset !== oldOffset) {
|
|
864
|
-
const path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
865
|
-
const action = jsonX.editOp(textX.serialize(), path);
|
|
866
|
-
rawActions.push(action);
|
|
867
|
-
}
|
|
868
|
-
} else {
|
|
869
|
-
if (oldOffset > 0) textX.push({
|
|
870
|
-
t: TextXActionType.RETAIN,
|
|
871
|
-
len: oldOffset
|
|
872
|
-
});
|
|
873
|
-
textX.push({
|
|
874
|
-
t: TextXActionType.DELETE,
|
|
875
|
-
len: 1
|
|
876
|
-
});
|
|
877
|
-
let path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
878
|
-
let action = jsonX.editOp(textX.serialize(), path);
|
|
879
|
-
rawActions.push(action);
|
|
880
|
-
textX.empty();
|
|
881
|
-
if (offset > 0) textX.push({
|
|
882
|
-
t: TextXActionType.RETAIN,
|
|
883
|
-
len: offset
|
|
884
|
-
});
|
|
885
|
-
textX.push({
|
|
886
|
-
t: TextXActionType.INSERT,
|
|
887
|
-
body: {
|
|
888
|
-
dataStream: "\b",
|
|
889
|
-
customBlocks: [{
|
|
890
|
-
startIndex: 0,
|
|
891
|
-
blockId: drawingId
|
|
892
|
-
}]
|
|
893
|
-
},
|
|
894
|
-
len: 1
|
|
895
|
-
});
|
|
896
|
-
path = getRichTextEditPath(documentDataModel, segmentId);
|
|
897
|
-
action = jsonX.editOp(textX.serialize(), path);
|
|
898
|
-
rawActions.push(action);
|
|
899
|
-
docSelectionRenderManager.setSegment(segmentId);
|
|
900
|
-
docSelectionRenderManager.setSegmentPage(segmentPage);
|
|
901
|
-
}
|
|
902
|
-
return rawActions;
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* The command to update drawing wrapping style.
|
|
906
|
-
*/
|
|
907
|
-
const UpdateDocDrawingWrappingStyleCommand = {
|
|
908
|
-
id: "doc.command.update-doc-drawing-wrapping-style",
|
|
519
|
+
//#region src/commands/commands/move-drawings.command.ts
|
|
520
|
+
const MoveDocDrawingsCommand = {
|
|
521
|
+
id: "doc.command.move-drawing",
|
|
909
522
|
type: CommandType.COMMAND,
|
|
910
523
|
handler: (accessor, params) => {
|
|
911
|
-
if (params == null) return false;
|
|
912
|
-
const { drawings, wrappingStyle, unitId } = params;
|
|
913
524
|
const commandService = accessor.get(ICommandService);
|
|
914
|
-
const
|
|
915
|
-
const renderObject = accessor.get(IRenderManagerService).getRenderById(unitId);
|
|
916
|
-
const skeletonData = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton().getSkeletonData();
|
|
917
|
-
const viewModel = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getViewModel();
|
|
918
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
919
|
-
const documentDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
920
|
-
if (documentDataModel == null || skeletonData == null || scene == null || viewModel == null) return false;
|
|
921
|
-
const editArea = viewModel.getEditArea();
|
|
922
|
-
const transformer = scene.getTransformerByCreate();
|
|
923
|
-
const { pages, skeHeaders, skeFooters } = skeletonData;
|
|
924
|
-
const jsonX = JSONX.getInstance();
|
|
925
|
-
const rawActions = [];
|
|
926
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
927
|
-
for (const drawing of drawings) {
|
|
928
|
-
const { drawingId } = drawing;
|
|
929
|
-
const oldLayoutType = oldDrawings[drawingId].layoutType;
|
|
930
|
-
const newLayoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
|
|
931
|
-
if (oldLayoutType !== newLayoutType) {
|
|
932
|
-
const updateLayoutTypeAction = jsonX.replaceOp([
|
|
933
|
-
"drawings",
|
|
934
|
-
drawingId,
|
|
935
|
-
"layoutType"
|
|
936
|
-
], oldLayoutType, newLayoutType);
|
|
937
|
-
rawActions.push(updateLayoutTypeAction);
|
|
938
|
-
}
|
|
939
|
-
if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
|
|
940
|
-
const oldBehindDoc = oldDrawings[drawingId].behindDoc;
|
|
941
|
-
const newBehindDoc = wrappingStyle === "behindText" ? BooleanNumber.TRUE : BooleanNumber.FALSE;
|
|
942
|
-
if (oldBehindDoc !== newBehindDoc) {
|
|
943
|
-
const updateBehindDocAction = jsonX.replaceOp([
|
|
944
|
-
"drawings",
|
|
945
|
-
drawingId,
|
|
946
|
-
"behindDoc"
|
|
947
|
-
], oldBehindDoc, newBehindDoc);
|
|
948
|
-
rawActions.push(updateBehindDocAction);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
if (wrappingStyle === "inline") continue;
|
|
952
|
-
let drawingAnchor = null;
|
|
953
|
-
for (const page of pages) {
|
|
954
|
-
const { headerId, footerId, marginTop, marginLeft, marginBottom, pageWidth, pageHeight } = page;
|
|
955
|
-
switch (editArea) {
|
|
956
|
-
case DocumentEditArea.HEADER: {
|
|
957
|
-
var _skeHeaders$get;
|
|
958
|
-
const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
|
|
959
|
-
if (headerSke != null) drawingAnchor = findDrawingAnchorInPage(headerSke, drawingId, headerSke.marginTop, marginLeft);
|
|
960
|
-
break;
|
|
961
|
-
}
|
|
962
|
-
case DocumentEditArea.FOOTER: {
|
|
963
|
-
var _skeFooters$get;
|
|
964
|
-
const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
|
|
965
|
-
if (footerSke != null) drawingAnchor = findDrawingAnchorInPage(footerSke, drawingId, pageHeight - marginBottom + footerSke.marginTop, marginLeft);
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
case DocumentEditArea.BODY:
|
|
969
|
-
drawingAnchor = findDrawingAnchorInPage(page, drawingId, marginTop, marginLeft);
|
|
970
|
-
break;
|
|
971
|
-
}
|
|
972
|
-
if (drawingAnchor != null) break;
|
|
973
|
-
}
|
|
974
|
-
if (drawingAnchor != null) {
|
|
975
|
-
const { skeDrawing, pageMarginTop, pageMarginLeft } = drawingAnchor;
|
|
976
|
-
const { aTop, aLeft } = skeDrawing;
|
|
977
|
-
const oldPositionH = oldDrawings[drawingId].docTransform.positionH;
|
|
978
|
-
let posOffsetH = aLeft;
|
|
979
|
-
if (oldPositionH.relativeFrom === ObjectRelativeFromH.MARGIN) posOffsetH -= pageMarginLeft;
|
|
980
|
-
else if (oldPositionH.relativeFrom === ObjectRelativeFromH.COLUMN) posOffsetH -= skeDrawing.columnLeft;
|
|
981
|
-
const newPositionH = {
|
|
982
|
-
relativeFrom: oldPositionH.relativeFrom,
|
|
983
|
-
posOffset: posOffsetH
|
|
984
|
-
};
|
|
985
|
-
if (oldPositionH.posOffset !== newPositionH.posOffset) {
|
|
986
|
-
const action = jsonX.replaceOp([
|
|
987
|
-
"drawings",
|
|
988
|
-
drawingId,
|
|
989
|
-
"docTransform",
|
|
990
|
-
"positionH"
|
|
991
|
-
], oldPositionH, newPositionH);
|
|
992
|
-
rawActions.push(action);
|
|
993
|
-
}
|
|
994
|
-
const oldPositionV = oldDrawings[drawingId].docTransform.positionV;
|
|
995
|
-
let posOffsetV = aTop;
|
|
996
|
-
if (oldPositionV.relativeFrom === ObjectRelativeFromV.PAGE) posOffsetV += pageMarginTop;
|
|
997
|
-
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.LINE) posOffsetV -= skeDrawing.lineTop;
|
|
998
|
-
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH) posOffsetV -= skeDrawing.blockAnchorTop;
|
|
999
|
-
const newPositionV = {
|
|
1000
|
-
relativeFrom: oldPositionV.relativeFrom,
|
|
1001
|
-
posOffset: posOffsetV
|
|
1002
|
-
};
|
|
1003
|
-
if (oldPositionV.posOffset !== newPositionV.posOffset) {
|
|
1004
|
-
const action = jsonX.replaceOp([
|
|
1005
|
-
"drawings",
|
|
1006
|
-
drawingId,
|
|
1007
|
-
"docTransform",
|
|
1008
|
-
"positionV"
|
|
1009
|
-
], oldPositionV, newPositionV);
|
|
1010
|
-
rawActions.push(action);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
const doMutation = {
|
|
1015
|
-
id: RichTextEditingMutation.id,
|
|
1016
|
-
params: {
|
|
1017
|
-
unitId,
|
|
1018
|
-
actions: [],
|
|
1019
|
-
textRanges: null
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1023
|
-
return JSONX.compose(acc, cur);
|
|
1024
|
-
}, null);
|
|
1025
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1026
|
-
transformer.refreshControls();
|
|
1027
|
-
return Boolean(result);
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
/**
|
|
1031
|
-
* The command to update drawing wrap text.
|
|
1032
|
-
*/
|
|
1033
|
-
const UpdateDocDrawingDistanceCommand = {
|
|
1034
|
-
id: "doc.command.update-doc-drawing-distance",
|
|
1035
|
-
type: CommandType.COMMAND,
|
|
1036
|
-
handler: (accessor, params) => {
|
|
1037
|
-
if (params == null) return false;
|
|
1038
|
-
const commandService = accessor.get(ICommandService);
|
|
1039
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1040
|
-
const { drawings, dist, unitId } = params;
|
|
1041
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1042
|
-
if (documentDataModel == null) return false;
|
|
1043
|
-
const jsonX = JSONX.getInstance();
|
|
1044
|
-
const rawActions = [];
|
|
1045
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1046
|
-
for (const drawing of drawings) {
|
|
1047
|
-
const { drawingId } = drawing;
|
|
1048
|
-
for (const [key, value] of Object.entries(dist)) {
|
|
1049
|
-
const oldValue = oldDrawings[drawingId][key];
|
|
1050
|
-
if (oldValue !== value) {
|
|
1051
|
-
const action = jsonX.replaceOp([
|
|
1052
|
-
"drawings",
|
|
1053
|
-
drawingId,
|
|
1054
|
-
key
|
|
1055
|
-
], oldValue, value);
|
|
1056
|
-
rawActions.push(action);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
const doMutation = {
|
|
1061
|
-
id: RichTextEditingMutation.id,
|
|
1062
|
-
params: {
|
|
1063
|
-
unitId,
|
|
1064
|
-
actions: [],
|
|
1065
|
-
textRanges: null
|
|
1066
|
-
}
|
|
1067
|
-
};
|
|
1068
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1069
|
-
return JSONX.compose(acc, cur);
|
|
1070
|
-
}, null);
|
|
1071
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1072
|
-
return Boolean(result);
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
/**
|
|
1076
|
-
* The command to update drawing wrap text.
|
|
1077
|
-
*/
|
|
1078
|
-
const UpdateDocDrawingWrapTextCommand = {
|
|
1079
|
-
id: "doc.command.update-doc-drawing-wrap-text",
|
|
1080
|
-
type: CommandType.COMMAND,
|
|
1081
|
-
handler: (accessor, params) => {
|
|
1082
|
-
if (params == null) return false;
|
|
1083
|
-
const commandService = accessor.get(ICommandService);
|
|
1084
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1085
|
-
const { drawings, wrapText, unitId } = params;
|
|
1086
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1087
|
-
if (documentDataModel == null) return false;
|
|
1088
|
-
const jsonX = JSONX.getInstance();
|
|
1089
|
-
const rawActions = [];
|
|
1090
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1091
|
-
for (const drawing of drawings) {
|
|
1092
|
-
const { drawingId } = drawing;
|
|
1093
|
-
const oldWrapText = oldDrawings[drawingId].wrapText;
|
|
1094
|
-
if (oldWrapText !== wrapText) {
|
|
1095
|
-
const action = jsonX.replaceOp([
|
|
1096
|
-
"drawings",
|
|
1097
|
-
drawingId,
|
|
1098
|
-
"wrapText"
|
|
1099
|
-
], oldWrapText, wrapText);
|
|
1100
|
-
rawActions.push(action);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
const doMutation = {
|
|
1104
|
-
id: RichTextEditingMutation.id,
|
|
1105
|
-
params: {
|
|
1106
|
-
unitId,
|
|
1107
|
-
actions: [],
|
|
1108
|
-
textRanges: null
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1112
|
-
return JSONX.compose(acc, cur);
|
|
1113
|
-
}, null);
|
|
1114
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1115
|
-
return Boolean(result);
|
|
1116
|
-
}
|
|
1117
|
-
};
|
|
1118
|
-
/**
|
|
1119
|
-
* The command to update drawing position.
|
|
1120
|
-
*/
|
|
1121
|
-
const UpdateDrawingDocTransformCommand = {
|
|
1122
|
-
id: "doc.command.update-drawing-doc-transform",
|
|
1123
|
-
type: CommandType.COMMAND,
|
|
1124
|
-
handler: (accessor, params) => {
|
|
1125
|
-
if (params == null) return false;
|
|
1126
|
-
const commandService = accessor.get(ICommandService);
|
|
1127
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1128
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1129
|
-
const { drawings, unitId } = params;
|
|
1130
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1131
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1132
|
-
if (scene == null) return false;
|
|
1133
|
-
const transformer = scene.getTransformerByCreate();
|
|
1134
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1135
|
-
if (documentDataModel == null) return false;
|
|
1136
|
-
const jsonX = JSONX.getInstance();
|
|
1137
|
-
const rawActions = [];
|
|
1138
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1139
|
-
for (const drawing of drawings) {
|
|
1140
|
-
const { drawingId, key, value } = drawing;
|
|
1141
|
-
const oldValue = oldDrawings[drawingId].docTransform[key];
|
|
1142
|
-
if (!Tools.diffValue(oldValue, value)) {
|
|
1143
|
-
const action = jsonX.replaceOp([
|
|
1144
|
-
"drawings",
|
|
1145
|
-
drawingId,
|
|
1146
|
-
"docTransform",
|
|
1147
|
-
key
|
|
1148
|
-
], oldValue, value);
|
|
1149
|
-
rawActions.push(action);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
const doMutation = {
|
|
1153
|
-
id: RichTextEditingMutation.id,
|
|
1154
|
-
params: {
|
|
1155
|
-
unitId,
|
|
1156
|
-
actions: [],
|
|
1157
|
-
textRanges: null,
|
|
1158
|
-
debounce: true
|
|
1159
|
-
}
|
|
1160
|
-
};
|
|
1161
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1162
|
-
return JSONX.compose(acc, cur);
|
|
1163
|
-
}, null);
|
|
1164
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1165
|
-
transformer.refreshControls();
|
|
1166
|
-
return Boolean(result);
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
/**
|
|
1170
|
-
* The command to move inline drawing.
|
|
1171
|
-
*/
|
|
1172
|
-
const IMoveInlineDrawingCommand = {
|
|
1173
|
-
id: "doc.command.move-inline-drawing",
|
|
1174
|
-
type: CommandType.COMMAND,
|
|
1175
|
-
handler: (accessor, params) => {
|
|
1176
|
-
var _renderManagerService, _docSelectionRenderSe;
|
|
1177
|
-
if (params == null) return false;
|
|
1178
|
-
const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
|
|
1179
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1180
|
-
const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSelectionRenderService);
|
|
1181
|
-
const docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService);
|
|
1182
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1183
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1184
|
-
const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
|
|
1185
|
-
if (scene == null || docSelectionRenderService == null) return false;
|
|
1186
|
-
const transformer = scene.getTransformerByCreate();
|
|
1187
|
-
const commandService = accessor.get(ICommandService);
|
|
1188
|
-
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1189
|
-
if (documentDataModel == null) return false;
|
|
1190
|
-
if (needRefreshDrawings) {
|
|
1191
|
-
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1192
|
-
transformer.refreshControls();
|
|
1193
|
-
return true;
|
|
1194
|
-
}
|
|
1195
|
-
const rawActions = [];
|
|
1196
|
-
const { drawingId } = drawing;
|
|
1197
|
-
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1198
|
-
if (actions == null || actions.length === 0) {
|
|
1199
|
-
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1200
|
-
transformer.refreshControls();
|
|
1201
|
-
return false;
|
|
1202
|
-
}
|
|
1203
|
-
rawActions.push(...actions);
|
|
1204
|
-
const doMutation = {
|
|
1205
|
-
id: RichTextEditingMutation.id,
|
|
1206
|
-
params: {
|
|
1207
|
-
unitId,
|
|
1208
|
-
actions: [],
|
|
1209
|
-
textRanges: null
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1213
|
-
return JSONX.compose(acc, cur);
|
|
1214
|
-
}, null);
|
|
1215
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1216
|
-
transformer.refreshControls();
|
|
1217
|
-
return Boolean(result);
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
/**
|
|
1221
|
-
* The command to transform non-inline drawing.
|
|
1222
|
-
*/
|
|
1223
|
-
const ITransformNonInlineDrawingCommand = {
|
|
1224
|
-
id: "doc.command.transform-non-inline-drawing",
|
|
1225
|
-
type: CommandType.COMMAND,
|
|
1226
|
-
handler: (accessor, params) => {
|
|
1227
|
-
var _renderManagerService2, _docSelectionRenderSe2;
|
|
1228
|
-
if (params == null) return false;
|
|
1229
|
-
const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params;
|
|
1230
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1231
|
-
const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSelectionRenderService);
|
|
1232
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1233
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1234
|
-
if (scene == null || docSelectionRenderService == null) return false;
|
|
1235
|
-
const transformer = scene.getTransformerByCreate();
|
|
1236
|
-
const commandService = accessor.get(ICommandService);
|
|
1237
|
-
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1238
|
-
if (documentDataModel == null) return false;
|
|
1239
|
-
const rawActions = [];
|
|
1240
|
-
const { drawingId } = drawing;
|
|
1241
|
-
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe2 = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe2 !== void 0 ? _docSelectionRenderSe2 : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1242
|
-
if (actions == null) return false;
|
|
1243
|
-
if (actions.length > 0) rawActions.push(...actions);
|
|
1244
|
-
const jsonX = JSONX.getInstance();
|
|
1245
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1246
|
-
const { positionH: oldPositionH, positionV: oldPositionV, size: oldSize, angle: oldAngle } = oldDrawings[drawingId].docTransform;
|
|
1247
|
-
if (!Tools.diffValue(oldPositionH, docTransform.positionH)) {
|
|
1248
|
-
const updateAction = jsonX.replaceOp([
|
|
1249
|
-
"drawings",
|
|
1250
|
-
drawingId,
|
|
1251
|
-
"docTransform",
|
|
1252
|
-
"positionH"
|
|
1253
|
-
], oldPositionH, docTransform.positionH);
|
|
1254
|
-
rawActions.push(updateAction);
|
|
1255
|
-
}
|
|
1256
|
-
if (!Tools.diffValue(oldPositionV, docTransform.positionV)) {
|
|
1257
|
-
const updateAction = jsonX.replaceOp([
|
|
1258
|
-
"drawings",
|
|
1259
|
-
drawingId,
|
|
1260
|
-
"docTransform",
|
|
1261
|
-
"positionV"
|
|
1262
|
-
], oldPositionV, docTransform.positionV);
|
|
1263
|
-
rawActions.push(updateAction);
|
|
1264
|
-
}
|
|
1265
|
-
if (!Tools.diffValue(oldSize, docTransform.size)) {
|
|
1266
|
-
const updateAction = jsonX.replaceOp([
|
|
1267
|
-
"drawings",
|
|
1268
|
-
drawingId,
|
|
1269
|
-
"docTransform",
|
|
1270
|
-
"size"
|
|
1271
|
-
], oldSize, docTransform.size);
|
|
1272
|
-
rawActions.push(updateAction);
|
|
1273
|
-
}
|
|
1274
|
-
if (!Tools.diffValue(oldAngle, docTransform.angle)) {
|
|
1275
|
-
const updateAction = jsonX.replaceOp([
|
|
1276
|
-
"drawings",
|
|
1277
|
-
drawingId,
|
|
1278
|
-
"docTransform",
|
|
1279
|
-
"angle"
|
|
1280
|
-
], oldAngle, docTransform.angle);
|
|
1281
|
-
rawActions.push(updateAction);
|
|
1282
|
-
}
|
|
1283
|
-
const doMutation = {
|
|
1284
|
-
id: RichTextEditingMutation.id,
|
|
1285
|
-
params: {
|
|
1286
|
-
unitId,
|
|
1287
|
-
actions: [],
|
|
1288
|
-
textRanges: null,
|
|
1289
|
-
debounce: true
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1293
|
-
return JSONX.compose(acc, cur);
|
|
1294
|
-
}, null);
|
|
1295
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1296
|
-
transformer.refreshControls();
|
|
1297
|
-
return Boolean(result);
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
|
|
1301
|
-
//#endregion
|
|
1302
|
-
//#region src/commands/commands/move-drawings.command.ts
|
|
1303
|
-
const MoveDocDrawingsCommand = {
|
|
1304
|
-
id: "doc.command.move-drawing",
|
|
1305
|
-
type: CommandType.COMMAND,
|
|
1306
|
-
handler: (accessor, params) => {
|
|
1307
|
-
const commandService = accessor.get(ICommandService);
|
|
1308
|
-
const docDrawingService = accessor.get(IDocDrawingService);
|
|
525
|
+
const docDrawingService = accessor.get(IDocDrawingService);
|
|
1309
526
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1310
527
|
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1311
528
|
const { direction } = params;
|
|
@@ -1464,6 +681,30 @@ function calcDocFloatDomPosition(object, renderUnit) {
|
|
|
1464
681
|
right: left + width
|
|
1465
682
|
}, renderUnit.scene, opacity, angle);
|
|
1466
683
|
}
|
|
684
|
+
function mergeDocFloatDomRuntimeProps(existingProps, param) {
|
|
685
|
+
const customBlockRenderViewport = pickValidCustomBlockRenderViewport(param.customBlockRenderViewport);
|
|
686
|
+
if (!customBlockRenderViewport) return existingProps;
|
|
687
|
+
return {
|
|
688
|
+
...existingProps,
|
|
689
|
+
customBlockRenderViewport
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function pickValidCustomBlockRenderViewport(viewport) {
|
|
693
|
+
const result = {};
|
|
694
|
+
if (isNonNegativeNumber(viewport === null || viewport === void 0 ? void 0 : viewport.bleedLeft)) result.bleedLeft = viewport.bleedLeft;
|
|
695
|
+
if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.bleedWidth)) result.bleedWidth = viewport.bleedWidth;
|
|
696
|
+
if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.contentHeight)) result.contentHeight = viewport.contentHeight;
|
|
697
|
+
if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.contentWidth)) result.contentWidth = viewport.contentWidth;
|
|
698
|
+
if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.height)) result.height = viewport.height;
|
|
699
|
+
if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.viewportHeight)) result.viewportHeight = viewport.viewportHeight;
|
|
700
|
+
return Object.keys(result).length ? result : void 0;
|
|
701
|
+
}
|
|
702
|
+
function isPositiveNumber(value) {
|
|
703
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
704
|
+
}
|
|
705
|
+
function isNonNegativeNumber(value) {
|
|
706
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
707
|
+
}
|
|
1467
708
|
let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
1468
709
|
constructor(_renderManagerService, _drawingManagerService, _drawingRenderService, _canvasFloatDomService, _univerInstanceService, _commandService) {
|
|
1469
710
|
super();
|
|
@@ -1481,6 +722,7 @@ let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
|
1481
722
|
}
|
|
1482
723
|
_initialize() {
|
|
1483
724
|
this._drawingAddRemoveListener();
|
|
725
|
+
this._drawingRuntimePropsListener();
|
|
1484
726
|
this._initScrollAndZoomEvent();
|
|
1485
727
|
}
|
|
1486
728
|
_getSceneAndTransformerByDrawingSearch(unitId) {
|
|
@@ -1516,6 +758,12 @@ let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
|
1516
758
|
const rects = await this._drawingRenderService.renderFloatDom(rectParam, renderObject.scene);
|
|
1517
759
|
if (rects == null || rects.length === 0) return;
|
|
1518
760
|
for (const rect of rects) {
|
|
761
|
+
var _renderObject$scene$g;
|
|
762
|
+
const runtimeParam = rectParam;
|
|
763
|
+
const runtimeViewport = pickValidCustomBlockRenderViewport(runtimeParam.customBlockRenderViewport);
|
|
764
|
+
const preserveRuntimeGeometry = isEmbedFloatDomRuntimeParam(runtimeParam);
|
|
765
|
+
syncRectWithRuntimeParam(rect, runtimeParam, runtimeViewport, void 0, preserveRuntimeGeometry);
|
|
766
|
+
const runtimeTransform = runtimeViewport || preserveRuntimeGeometry ? createTransformFromRect(rect) : void 0;
|
|
1519
767
|
this._addHoverForRect(rect);
|
|
1520
768
|
const disposableCollection = new DisposableCollection();
|
|
1521
769
|
const position$ = new BehaviorSubject(calcDocFloatDomPosition(rect, renderObject.renderUnit));
|
|
@@ -1523,7 +771,10 @@ let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
|
1523
771
|
const data = rectParam.data;
|
|
1524
772
|
const info = {
|
|
1525
773
|
dispose: disposableCollection,
|
|
774
|
+
preserveRuntimeGeometry,
|
|
1526
775
|
rect,
|
|
776
|
+
runtimeTransform,
|
|
777
|
+
runtimeViewport,
|
|
1527
778
|
position$,
|
|
1528
779
|
unitId
|
|
1529
780
|
};
|
|
@@ -1531,6 +782,8 @@ let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
|
1531
782
|
position$,
|
|
1532
783
|
id: rectParam.drawingId,
|
|
1533
784
|
componentKey: rectParam.componentKey,
|
|
785
|
+
eventPassThrough: preserveRuntimeGeometry ? false : void 0,
|
|
786
|
+
preserveOnFocusChange: preserveRuntimeGeometry,
|
|
1534
787
|
onPointerDown: (evt) => {
|
|
1535
788
|
canvas.dispatchEvent(new PointerEvent(evt.type, evt));
|
|
1536
789
|
},
|
|
@@ -1544,20 +797,42 @@ let DocFloatDomController = class DocFloatDomController extends Disposable {
|
|
|
1544
797
|
canvas.dispatchEvent(new WheelEvent(evt.type, evt));
|
|
1545
798
|
},
|
|
1546
799
|
data,
|
|
800
|
+
props: mergeDocFloatDomRuntimeProps(void 0, rectParam),
|
|
1547
801
|
unitId
|
|
1548
802
|
});
|
|
1549
803
|
const listener = rect.onTransformChange$.subscribeEvent(() => {
|
|
1550
804
|
const newPosition = calcDocFloatDomPosition(rect, renderObject.renderUnit);
|
|
1551
805
|
position$.next(newPosition);
|
|
1552
806
|
});
|
|
807
|
+
const scrollListener = subscribeViewportScrollAfter((_renderObject$scene$g = renderObject.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN)) === null || _renderObject$scene$g === void 0 ? void 0 : _renderObject$scene$g.onScrollAfter$, () => position$.next(calcDocFloatDomPosition(rect, renderObject.renderUnit)));
|
|
1553
808
|
disposableCollection.add(() => {
|
|
1554
809
|
this._canvasFloatDomService.removeFloatDom(rectParam.drawingId);
|
|
1555
810
|
});
|
|
1556
811
|
listener && disposableCollection.add(listener);
|
|
812
|
+
scrollListener && disposableCollection.add(scrollListener);
|
|
1557
813
|
this._domLayerInfoMap.set(rectParam.drawingId, info);
|
|
1558
814
|
}
|
|
1559
815
|
});
|
|
1560
816
|
}
|
|
817
|
+
_drawingRuntimePropsListener() {
|
|
818
|
+
this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
|
|
819
|
+
params.forEach((param) => {
|
|
820
|
+
var _this$_canvasFloatDom;
|
|
821
|
+
const floatDomInfo = this._domLayerInfoMap.get(param.drawingId);
|
|
822
|
+
if (!floatDomInfo) return;
|
|
823
|
+
const runtimeParam = param;
|
|
824
|
+
const runtimeViewport = pickValidCustomBlockRenderViewport(runtimeParam.customBlockRenderViewport);
|
|
825
|
+
if (runtimeViewport) floatDomInfo.runtimeViewport = runtimeViewport;
|
|
826
|
+
if (syncRectWithRuntimeParam(floatDomInfo.rect, runtimeParam, floatDomInfo.runtimeViewport, floatDomInfo.runtimeTransform, floatDomInfo.preserveRuntimeGeometry)) {
|
|
827
|
+
if (runtimeViewport || floatDomInfo.preserveRuntimeGeometry) floatDomInfo.runtimeTransform = createTransformFromRect(floatDomInfo.rect);
|
|
828
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(floatDomInfo.unitId);
|
|
829
|
+
if (renderObject) floatDomInfo.position$.next(calcDocFloatDomPosition(floatDomInfo.rect, renderObject.renderUnit));
|
|
830
|
+
}
|
|
831
|
+
const currentProps = (_this$_canvasFloatDom = this._canvasFloatDomService.domLayers.find(([id]) => id === param.drawingId)) === null || _this$_canvasFloatDom === void 0 ? void 0 : _this$_canvasFloatDom[1].props;
|
|
832
|
+
this._canvasFloatDomService.updateFloatDom(param.drawingId, { props: mergeDocFloatDomRuntimeProps(currentProps, param) });
|
|
833
|
+
});
|
|
834
|
+
}));
|
|
835
|
+
}
|
|
1561
836
|
_addHoverForRect(o) {
|
|
1562
837
|
this.disposeWithMe(toDisposable(o.onPointerEnter$.subscribeEvent(() => {
|
|
1563
838
|
o.cursor = CURSOR_TYPE.GRAB;
|
|
@@ -1658,6 +933,71 @@ DocFloatDomController = __decorate([
|
|
|
1658
933
|
__decorateParam(4, IUniverInstanceService),
|
|
1659
934
|
__decorateParam(5, ICommandService)
|
|
1660
935
|
], DocFloatDomController);
|
|
936
|
+
function syncRectWithRuntimeParam(rect, param, fallbackViewport, fallbackTransform, preserveRuntimeGeometry) {
|
|
937
|
+
const transform = getRuntimeTransform(param, rect, fallbackViewport, fallbackTransform, preserveRuntimeGeometry);
|
|
938
|
+
if (!transform) return false;
|
|
939
|
+
rect.transformByState(transform);
|
|
940
|
+
return true;
|
|
941
|
+
}
|
|
942
|
+
function getRuntimeTransform(param, rect, fallbackViewport, fallbackTransform, preserveRuntimeGeometry) {
|
|
943
|
+
var _param$transform, _param$transforms, _param$customBlockRen, _runtimeViewport$heig2;
|
|
944
|
+
const transform = (_param$transform = param.transform) !== null && _param$transform !== void 0 ? _param$transform : (_param$transforms = param.transforms) === null || _param$transforms === void 0 ? void 0 : _param$transforms[0];
|
|
945
|
+
const runtimeViewport = (_param$customBlockRen = param.customBlockRenderViewport) !== null && _param$customBlockRen !== void 0 ? _param$customBlockRen : fallbackViewport;
|
|
946
|
+
if (!param.customBlockRenderViewport && preserveRuntimeGeometry && fallbackTransform && transform) {
|
|
947
|
+
var _fallbackTransform$wi, _fallbackTransform$he;
|
|
948
|
+
return {
|
|
949
|
+
...transform,
|
|
950
|
+
width: (_fallbackTransform$wi = fallbackTransform.width) !== null && _fallbackTransform$wi !== void 0 ? _fallbackTransform$wi : transform.width,
|
|
951
|
+
height: (_fallbackTransform$he = fallbackTransform.height) !== null && _fallbackTransform$he !== void 0 ? _fallbackTransform$he : transform.height
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (!transform) {
|
|
955
|
+
var _runtimeViewport$heig;
|
|
956
|
+
const height = (_runtimeViewport$heig = runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) !== null && _runtimeViewport$heig !== void 0 ? _runtimeViewport$heig : runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight;
|
|
957
|
+
if (!isPositiveNumber(height)) return;
|
|
958
|
+
return {
|
|
959
|
+
left: rect.left,
|
|
960
|
+
top: rect.top,
|
|
961
|
+
width: rect.width,
|
|
962
|
+
height,
|
|
963
|
+
angle: rect.angle
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
const height = (_runtimeViewport$heig2 = runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) !== null && _runtimeViewport$heig2 !== void 0 ? _runtimeViewport$heig2 : runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight;
|
|
967
|
+
if (!isPositiveNumber(height)) return transform;
|
|
968
|
+
return {
|
|
969
|
+
...transform,
|
|
970
|
+
height
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function isEmbedFloatDomRuntimeParam(param) {
|
|
974
|
+
const data = param.data;
|
|
975
|
+
if (!data || typeof data !== "object") return false;
|
|
976
|
+
const candidate = data;
|
|
977
|
+
return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
|
|
978
|
+
}
|
|
979
|
+
function createTransformFromRect(rect) {
|
|
980
|
+
return {
|
|
981
|
+
angle: rect.angle,
|
|
982
|
+
height: rect.height,
|
|
983
|
+
left: rect.left,
|
|
984
|
+
top: rect.top,
|
|
985
|
+
width: rect.width
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function subscribeViewportScrollAfter(scrollEvent, callback) {
|
|
989
|
+
if (!scrollEvent || typeof scrollEvent !== "object") return;
|
|
990
|
+
const eventSubject = scrollEvent;
|
|
991
|
+
if (typeof eventSubject.subscribeEvent === "function") return eventSubject.subscribeEvent(callback);
|
|
992
|
+
const observable = scrollEvent;
|
|
993
|
+
if (typeof observable.subscribe === "function") {
|
|
994
|
+
const subscription = observable.subscribe(callback);
|
|
995
|
+
return toDisposable(() => {
|
|
996
|
+
var _subscription$unsubsc;
|
|
997
|
+
return (_subscription$unsubsc = subscription.unsubscribe) === null || _subscription$unsubsc === void 0 ? void 0 : _subscription$unsubsc.call(subscription);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1661
1001
|
|
|
1662
1002
|
//#endregion
|
|
1663
1003
|
//#region src/menu/image.menu.ts
|
|
@@ -1784,10 +1124,79 @@ function InsertEllipseShapeBelowMenuFactory(accessor) {
|
|
|
1784
1124
|
};
|
|
1785
1125
|
}
|
|
1786
1126
|
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/menu/schema.ts
|
|
1129
|
+
const menuSchema = {
|
|
1130
|
+
[RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
|
|
1131
|
+
order: 0,
|
|
1132
|
+
menuItemFactory: ImageMenuFactory,
|
|
1133
|
+
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1134
|
+
order: 0,
|
|
1135
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1136
|
+
}
|
|
1137
|
+
} },
|
|
1138
|
+
[ContextMenuPosition.PARAGRAPH]: {
|
|
1139
|
+
[ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1140
|
+
order: 5,
|
|
1141
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1142
|
+
} } },
|
|
1143
|
+
[EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1144
|
+
order: 5,
|
|
1145
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1146
|
+
} } },
|
|
1147
|
+
[DOC_CONTENT_INSERT_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1148
|
+
order: 5,
|
|
1149
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1150
|
+
} } },
|
|
1151
|
+
[DOC_PARAGRAPH_T_INSERT_MENU_ID]: { insert: {
|
|
1152
|
+
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1153
|
+
order: 1,
|
|
1154
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1155
|
+
},
|
|
1156
|
+
[DOCS_SHAPE_MENU_ID]: {
|
|
1157
|
+
order: 2,
|
|
1158
|
+
menuItemFactory: ShapeMenuFactory
|
|
1159
|
+
}
|
|
1160
|
+
} },
|
|
1161
|
+
[DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID]: { insert: {
|
|
1162
|
+
[`${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`]: {
|
|
1163
|
+
order: 1,
|
|
1164
|
+
menuItemFactory: UploadFloatImageBelowMenuFactory
|
|
1165
|
+
},
|
|
1166
|
+
[DOCS_SHAPE_BELOW_MENU_ID]: {
|
|
1167
|
+
order: 2,
|
|
1168
|
+
menuItemFactory: ShapeBelowMenuFactory
|
|
1169
|
+
}
|
|
1170
|
+
} },
|
|
1171
|
+
[DOCS_SHAPE_MENU_ID]: { shapes: {
|
|
1172
|
+
order: 0,
|
|
1173
|
+
[InsertDocRectangleShapeCommand.id]: {
|
|
1174
|
+
order: 0,
|
|
1175
|
+
menuItemFactory: InsertRectangleShapeMenuFactory
|
|
1176
|
+
},
|
|
1177
|
+
[InsertDocEllipseShapeCommand.id]: {
|
|
1178
|
+
order: 1,
|
|
1179
|
+
menuItemFactory: InsertEllipseShapeMenuFactory
|
|
1180
|
+
}
|
|
1181
|
+
} },
|
|
1182
|
+
[DOCS_SHAPE_BELOW_MENU_ID]: { shapes: {
|
|
1183
|
+
order: 0,
|
|
1184
|
+
[`${InsertDocRectangleShapeCommand.id}.below`]: {
|
|
1185
|
+
order: 0,
|
|
1186
|
+
menuItemFactory: InsertRectangleShapeBelowMenuFactory
|
|
1187
|
+
},
|
|
1188
|
+
[`${InsertDocEllipseShapeCommand.id}.below`]: {
|
|
1189
|
+
order: 1,
|
|
1190
|
+
menuItemFactory: InsertEllipseShapeBelowMenuFactory
|
|
1191
|
+
}
|
|
1192
|
+
} }
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1787
1196
|
//#endregion
|
|
1788
1197
|
//#region package.json
|
|
1789
1198
|
var name = "@univerjs/docs-drawing-ui";
|
|
1790
|
-
var version = "1.0.0-alpha.
|
|
1199
|
+
var version = "1.0.0-alpha.4";
|
|
1791
1200
|
|
|
1792
1201
|
//#endregion
|
|
1793
1202
|
//#region src/config/config.ts
|
|
@@ -1815,21 +1224,23 @@ const defaultPluginConfig = {};
|
|
|
1815
1224
|
const MIN_OFFSET = -1e3;
|
|
1816
1225
|
const MAX_OFFSET = 1e3;
|
|
1817
1226
|
const DocDrawingPosition = (props) => {
|
|
1227
|
+
var _renderManagerService;
|
|
1228
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
1229
|
+
const drawingParam = props.drawings[0];
|
|
1230
|
+
const scene = drawingParam ? (_renderManagerService = renderManagerService.getRenderById(drawingParam.unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.scene : void 0;
|
|
1231
|
+
return drawingParam && scene ? /* @__PURE__ */ jsx(DocDrawingPositionContent, { ...props }) : null;
|
|
1232
|
+
};
|
|
1233
|
+
function DocDrawingPositionContent(props) {
|
|
1818
1234
|
const commandService = useDependency(ICommandService);
|
|
1819
1235
|
const localeService = useDependency(LocaleService);
|
|
1820
1236
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
1821
1237
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
1822
1238
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
1823
1239
|
const { drawings } = props;
|
|
1824
|
-
const
|
|
1825
|
-
if (drawingParam == null) return;
|
|
1826
|
-
const { unitId } = drawingParam;
|
|
1240
|
+
const { unitId } = drawings[0];
|
|
1827
1241
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1828
1242
|
const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
|
|
1829
|
-
const
|
|
1830
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1831
|
-
if (scene == null) return;
|
|
1832
|
-
const transformer = scene.getTransformerByCreate();
|
|
1243
|
+
const transformer = renderManagerService.getRenderById(unitId).scene.getTransformerByCreate();
|
|
1833
1244
|
const HORIZONTAL_RELATIVE_FROM = [
|
|
1834
1245
|
{
|
|
1835
1246
|
label: localeService.t("docs-drawing-ui.image-position.column"),
|
|
@@ -1877,7 +1288,7 @@ const DocDrawingPosition = (props) => {
|
|
|
1877
1288
|
const [followTextMove, setFollowTextMove] = useState(true);
|
|
1878
1289
|
const [showPanel, setShowPanel] = useState(true);
|
|
1879
1290
|
function handlePositionChange(direction, value) {
|
|
1880
|
-
var
|
|
1291
|
+
var _renderManagerService2;
|
|
1881
1292
|
if (direction === "positionH") setHPosition(value);
|
|
1882
1293
|
else setVPosition(value);
|
|
1883
1294
|
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
@@ -1898,12 +1309,12 @@ const DocDrawingPosition = (props) => {
|
|
|
1898
1309
|
value
|
|
1899
1310
|
}))
|
|
1900
1311
|
});
|
|
1901
|
-
const docSelectionRenderService = (
|
|
1312
|
+
const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSelectionRenderService);
|
|
1902
1313
|
if (docSelectionRenderService) docSelectionRenderService.blur();
|
|
1903
1314
|
transformer.refreshControls();
|
|
1904
1315
|
}
|
|
1905
1316
|
function handleHorizontalRelativeFromChange(value) {
|
|
1906
|
-
var
|
|
1317
|
+
var _renderManagerService3;
|
|
1907
1318
|
const prevRelativeFrom = hPosition.relativeFrom;
|
|
1908
1319
|
const prevPosOffset = hPosition.posOffset;
|
|
1909
1320
|
const relativeFrom = Number(value);
|
|
@@ -1914,7 +1325,7 @@ const DocDrawingPosition = (props) => {
|
|
|
1914
1325
|
const unitId = focusDrawings[0].unitId;
|
|
1915
1326
|
let drawing = null;
|
|
1916
1327
|
let pageMarginLeft = 0;
|
|
1917
|
-
const skeleton = (
|
|
1328
|
+
const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(DocSkeletonManagerService).getSkeleton();
|
|
1918
1329
|
const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
|
|
1919
1330
|
if (skeletonData == null) return;
|
|
1920
1331
|
const { pages, skeHeaders, skeFooters } = skeletonData;
|
|
@@ -1952,7 +1363,7 @@ const DocDrawingPosition = (props) => {
|
|
|
1952
1363
|
});
|
|
1953
1364
|
}
|
|
1954
1365
|
function handleVerticalRelativeFromChange(value) {
|
|
1955
|
-
var
|
|
1366
|
+
var _renderManagerService4, _renderManagerService5, _documentDataModel$ge, _glyph$parent, _column$parent;
|
|
1956
1367
|
const prevRelativeFrom = vPosition.relativeFrom;
|
|
1957
1368
|
const prevPosOffset = vPosition.posOffset;
|
|
1958
1369
|
const relativeFrom = Number(value);
|
|
@@ -1961,8 +1372,8 @@ const DocDrawingPosition = (props) => {
|
|
|
1961
1372
|
if (focusDrawings.length === 0) return;
|
|
1962
1373
|
const { drawingId, unitId } = focusDrawings[0];
|
|
1963
1374
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1964
|
-
const skeleton = (
|
|
1965
|
-
const docSelectionRenderService = (
|
|
1375
|
+
const skeleton = (_renderManagerService4 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService4 === void 0 ? void 0 : _renderManagerService4.with(DocSkeletonManagerService).getSkeleton();
|
|
1376
|
+
const docSelectionRenderService = (_renderManagerService5 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService5 === void 0 ? void 0 : _renderManagerService5.with(DocSelectionRenderService);
|
|
1966
1377
|
const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
|
|
1967
1378
|
const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
|
|
1968
1379
|
const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.getBody()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.customBlocks) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.find((c) => c.blockId === drawingId);
|
|
@@ -2094,6 +1505,330 @@ const DocDrawingPosition = (props) => {
|
|
|
2094
1505
|
}) })
|
|
2095
1506
|
]
|
|
2096
1507
|
});
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
//#endregion
|
|
1511
|
+
//#region src/commands/commands/update-doc-drawing.command.ts
|
|
1512
|
+
function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, docSelectionRenderManager) {
|
|
1513
|
+
var _documentDataModel$ge, _documentDataModel$ge2, _oldBody$customBlocks;
|
|
1514
|
+
const textX = new TextX();
|
|
1515
|
+
const jsonX = JSONX.getInstance();
|
|
1516
|
+
const rawActions = [];
|
|
1517
|
+
const oldBody = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
1518
|
+
const body = (_documentDataModel$ge2 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.getBody();
|
|
1519
|
+
if (oldBody == null || body == null) return;
|
|
1520
|
+
const oldOffset = (_oldBody$customBlocks = oldBody.customBlocks) === null || _oldBody$customBlocks === void 0 || (_oldBody$customBlocks = _oldBody$customBlocks.find((block) => block.blockId === drawingId)) === null || _oldBody$customBlocks === void 0 ? void 0 : _oldBody$customBlocks.startIndex;
|
|
1521
|
+
if (oldOffset == null) return;
|
|
1522
|
+
offset = Math.min(body.dataStream.length - 2, offset);
|
|
1523
|
+
if (segmentId === oldSegmentId) {
|
|
1524
|
+
if (offset < oldOffset) {
|
|
1525
|
+
if (offset > 0) textX.push({
|
|
1526
|
+
t: TextXActionType.RETAIN,
|
|
1527
|
+
len: offset
|
|
1528
|
+
});
|
|
1529
|
+
textX.push({
|
|
1530
|
+
t: TextXActionType.INSERT,
|
|
1531
|
+
body: {
|
|
1532
|
+
dataStream: "\b",
|
|
1533
|
+
customBlocks: [{
|
|
1534
|
+
startIndex: 0,
|
|
1535
|
+
blockId: drawingId
|
|
1536
|
+
}]
|
|
1537
|
+
},
|
|
1538
|
+
len: 1
|
|
1539
|
+
});
|
|
1540
|
+
textX.push({
|
|
1541
|
+
t: TextXActionType.RETAIN,
|
|
1542
|
+
len: oldOffset - offset
|
|
1543
|
+
});
|
|
1544
|
+
textX.push({
|
|
1545
|
+
t: TextXActionType.DELETE,
|
|
1546
|
+
len: 1
|
|
1547
|
+
});
|
|
1548
|
+
} else {
|
|
1549
|
+
if (oldOffset > 0) textX.push({
|
|
1550
|
+
t: TextXActionType.RETAIN,
|
|
1551
|
+
len: oldOffset
|
|
1552
|
+
});
|
|
1553
|
+
textX.push({
|
|
1554
|
+
t: TextXActionType.DELETE,
|
|
1555
|
+
len: 1
|
|
1556
|
+
});
|
|
1557
|
+
if (offset - oldOffset - 1 > 0) textX.push({
|
|
1558
|
+
t: TextXActionType.RETAIN,
|
|
1559
|
+
len: offset - oldOffset - 1
|
|
1560
|
+
});
|
|
1561
|
+
textX.push({
|
|
1562
|
+
t: TextXActionType.INSERT,
|
|
1563
|
+
body: {
|
|
1564
|
+
dataStream: "\b",
|
|
1565
|
+
customBlocks: [{
|
|
1566
|
+
startIndex: 0,
|
|
1567
|
+
blockId: drawingId
|
|
1568
|
+
}]
|
|
1569
|
+
},
|
|
1570
|
+
len: 1
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
if (offset !== oldOffset) {
|
|
1574
|
+
const path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
1575
|
+
const action = jsonX.editOp(textX.serialize(), path);
|
|
1576
|
+
rawActions.push(action);
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
if (oldOffset > 0) textX.push({
|
|
1580
|
+
t: TextXActionType.RETAIN,
|
|
1581
|
+
len: oldOffset
|
|
1582
|
+
});
|
|
1583
|
+
textX.push({
|
|
1584
|
+
t: TextXActionType.DELETE,
|
|
1585
|
+
len: 1
|
|
1586
|
+
});
|
|
1587
|
+
let path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
1588
|
+
let action = jsonX.editOp(textX.serialize(), path);
|
|
1589
|
+
rawActions.push(action);
|
|
1590
|
+
textX.empty();
|
|
1591
|
+
if (offset > 0) textX.push({
|
|
1592
|
+
t: TextXActionType.RETAIN,
|
|
1593
|
+
len: offset
|
|
1594
|
+
});
|
|
1595
|
+
textX.push({
|
|
1596
|
+
t: TextXActionType.INSERT,
|
|
1597
|
+
body: {
|
|
1598
|
+
dataStream: "\b",
|
|
1599
|
+
customBlocks: [{
|
|
1600
|
+
startIndex: 0,
|
|
1601
|
+
blockId: drawingId
|
|
1602
|
+
}]
|
|
1603
|
+
},
|
|
1604
|
+
len: 1
|
|
1605
|
+
});
|
|
1606
|
+
path = getRichTextEditPath(documentDataModel, segmentId);
|
|
1607
|
+
action = jsonX.editOp(textX.serialize(), path);
|
|
1608
|
+
rawActions.push(action);
|
|
1609
|
+
docSelectionRenderManager.setSegment(segmentId);
|
|
1610
|
+
docSelectionRenderManager.setSegmentPage(segmentPage);
|
|
1611
|
+
}
|
|
1612
|
+
return rawActions;
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* The command to update drawing wrap text.
|
|
1616
|
+
*/
|
|
1617
|
+
const UpdateDocDrawingDistanceCommand = {
|
|
1618
|
+
id: "doc.command.update-doc-drawing-distance",
|
|
1619
|
+
type: CommandType.COMMAND,
|
|
1620
|
+
handler: (accessor, params) => {
|
|
1621
|
+
if (params == null) return false;
|
|
1622
|
+
const commandService = accessor.get(ICommandService);
|
|
1623
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1624
|
+
const { drawings, dist, unitId } = params;
|
|
1625
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1626
|
+
if (documentDataModel == null) return false;
|
|
1627
|
+
const jsonX = JSONX.getInstance();
|
|
1628
|
+
const rawActions = [];
|
|
1629
|
+
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1630
|
+
for (const drawing of drawings) {
|
|
1631
|
+
const { drawingId } = drawing;
|
|
1632
|
+
for (const [key, value] of Object.entries(dist)) {
|
|
1633
|
+
const oldValue = oldDrawings[drawingId][key];
|
|
1634
|
+
if (oldValue !== value) {
|
|
1635
|
+
const action = jsonX.replaceOp([
|
|
1636
|
+
"drawings",
|
|
1637
|
+
drawingId,
|
|
1638
|
+
key
|
|
1639
|
+
], oldValue, value);
|
|
1640
|
+
rawActions.push(action);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
const doMutation = {
|
|
1645
|
+
id: RichTextEditingMutation.id,
|
|
1646
|
+
params: {
|
|
1647
|
+
unitId,
|
|
1648
|
+
actions: [],
|
|
1649
|
+
textRanges: null
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1653
|
+
return JSONX.compose(acc, cur);
|
|
1654
|
+
}, null);
|
|
1655
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1656
|
+
return Boolean(result);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
/**
|
|
1660
|
+
* The command to update drawing wrap text.
|
|
1661
|
+
*/
|
|
1662
|
+
const UpdateDocDrawingWrapTextCommand = {
|
|
1663
|
+
id: "doc.command.update-doc-drawing-wrap-text",
|
|
1664
|
+
type: CommandType.COMMAND,
|
|
1665
|
+
handler: (accessor, params) => {
|
|
1666
|
+
if (params == null) return false;
|
|
1667
|
+
const commandService = accessor.get(ICommandService);
|
|
1668
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1669
|
+
const { drawings, wrapText, unitId } = params;
|
|
1670
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1671
|
+
if (documentDataModel == null) return false;
|
|
1672
|
+
const jsonX = JSONX.getInstance();
|
|
1673
|
+
const rawActions = [];
|
|
1674
|
+
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1675
|
+
for (const drawing of drawings) {
|
|
1676
|
+
const { drawingId } = drawing;
|
|
1677
|
+
const oldWrapText = oldDrawings[drawingId].wrapText;
|
|
1678
|
+
if (oldWrapText !== wrapText) {
|
|
1679
|
+
const action = jsonX.replaceOp([
|
|
1680
|
+
"drawings",
|
|
1681
|
+
drawingId,
|
|
1682
|
+
"wrapText"
|
|
1683
|
+
], oldWrapText, wrapText);
|
|
1684
|
+
rawActions.push(action);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
const doMutation = {
|
|
1688
|
+
id: RichTextEditingMutation.id,
|
|
1689
|
+
params: {
|
|
1690
|
+
unitId,
|
|
1691
|
+
actions: [],
|
|
1692
|
+
textRanges: null
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1696
|
+
return JSONX.compose(acc, cur);
|
|
1697
|
+
}, null);
|
|
1698
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1699
|
+
return Boolean(result);
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
/**
|
|
1703
|
+
* The command to move inline drawing.
|
|
1704
|
+
*/
|
|
1705
|
+
const IMoveInlineDrawingCommand = {
|
|
1706
|
+
id: "doc.command.move-inline-drawing",
|
|
1707
|
+
type: CommandType.COMMAND,
|
|
1708
|
+
handler: (accessor, params) => {
|
|
1709
|
+
var _renderManagerService, _docSelectionRenderSe;
|
|
1710
|
+
if (params == null) return false;
|
|
1711
|
+
const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
|
|
1712
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1713
|
+
const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSelectionRenderService);
|
|
1714
|
+
const docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService);
|
|
1715
|
+
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1716
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1717
|
+
const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
|
|
1718
|
+
if (scene == null || docSelectionRenderService == null) return false;
|
|
1719
|
+
const transformer = scene.getTransformerByCreate();
|
|
1720
|
+
const commandService = accessor.get(ICommandService);
|
|
1721
|
+
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1722
|
+
if (documentDataModel == null) return false;
|
|
1723
|
+
if (needRefreshDrawings) {
|
|
1724
|
+
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1725
|
+
transformer.refreshControls();
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
const rawActions = [];
|
|
1729
|
+
const { drawingId } = drawing;
|
|
1730
|
+
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1731
|
+
if (actions == null || actions.length === 0) {
|
|
1732
|
+
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1733
|
+
transformer.refreshControls();
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
rawActions.push(...actions);
|
|
1737
|
+
const doMutation = {
|
|
1738
|
+
id: RichTextEditingMutation.id,
|
|
1739
|
+
params: {
|
|
1740
|
+
unitId,
|
|
1741
|
+
actions: [],
|
|
1742
|
+
textRanges: null
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1746
|
+
return JSONX.compose(acc, cur);
|
|
1747
|
+
}, null);
|
|
1748
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1749
|
+
transformer.refreshControls();
|
|
1750
|
+
return Boolean(result);
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
/**
|
|
1754
|
+
* The command to transform non-inline drawing.
|
|
1755
|
+
*/
|
|
1756
|
+
const ITransformNonInlineDrawingCommand = {
|
|
1757
|
+
id: "doc.command.transform-non-inline-drawing",
|
|
1758
|
+
type: CommandType.COMMAND,
|
|
1759
|
+
handler: (accessor, params) => {
|
|
1760
|
+
var _renderManagerService2, _docSelectionRenderSe2;
|
|
1761
|
+
if (params == null) return false;
|
|
1762
|
+
const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params;
|
|
1763
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1764
|
+
const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSelectionRenderService);
|
|
1765
|
+
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1766
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1767
|
+
if (scene == null || docSelectionRenderService == null) return false;
|
|
1768
|
+
const transformer = scene.getTransformerByCreate();
|
|
1769
|
+
const commandService = accessor.get(ICommandService);
|
|
1770
|
+
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1771
|
+
if (documentDataModel == null) return false;
|
|
1772
|
+
const rawActions = [];
|
|
1773
|
+
const { drawingId } = drawing;
|
|
1774
|
+
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe2 = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe2 !== void 0 ? _docSelectionRenderSe2 : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1775
|
+
if (actions == null) return false;
|
|
1776
|
+
if (actions.length > 0) rawActions.push(...actions);
|
|
1777
|
+
const jsonX = JSONX.getInstance();
|
|
1778
|
+
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1779
|
+
const { positionH: oldPositionH, positionV: oldPositionV, size: oldSize, angle: oldAngle } = oldDrawings[drawingId].docTransform;
|
|
1780
|
+
if (!Tools.diffValue(oldPositionH, docTransform.positionH)) {
|
|
1781
|
+
const updateAction = jsonX.replaceOp([
|
|
1782
|
+
"drawings",
|
|
1783
|
+
drawingId,
|
|
1784
|
+
"docTransform",
|
|
1785
|
+
"positionH"
|
|
1786
|
+
], oldPositionH, docTransform.positionH);
|
|
1787
|
+
rawActions.push(updateAction);
|
|
1788
|
+
}
|
|
1789
|
+
if (!Tools.diffValue(oldPositionV, docTransform.positionV)) {
|
|
1790
|
+
const updateAction = jsonX.replaceOp([
|
|
1791
|
+
"drawings",
|
|
1792
|
+
drawingId,
|
|
1793
|
+
"docTransform",
|
|
1794
|
+
"positionV"
|
|
1795
|
+
], oldPositionV, docTransform.positionV);
|
|
1796
|
+
rawActions.push(updateAction);
|
|
1797
|
+
}
|
|
1798
|
+
if (!Tools.diffValue(oldSize, docTransform.size)) {
|
|
1799
|
+
const updateAction = jsonX.replaceOp([
|
|
1800
|
+
"drawings",
|
|
1801
|
+
drawingId,
|
|
1802
|
+
"docTransform",
|
|
1803
|
+
"size"
|
|
1804
|
+
], oldSize, docTransform.size);
|
|
1805
|
+
rawActions.push(updateAction);
|
|
1806
|
+
}
|
|
1807
|
+
if (!Tools.diffValue(oldAngle, docTransform.angle)) {
|
|
1808
|
+
const updateAction = jsonX.replaceOp([
|
|
1809
|
+
"drawings",
|
|
1810
|
+
drawingId,
|
|
1811
|
+
"docTransform",
|
|
1812
|
+
"angle"
|
|
1813
|
+
], oldAngle, docTransform.angle);
|
|
1814
|
+
rawActions.push(updateAction);
|
|
1815
|
+
}
|
|
1816
|
+
const doMutation = {
|
|
1817
|
+
id: RichTextEditingMutation.id,
|
|
1818
|
+
params: {
|
|
1819
|
+
unitId,
|
|
1820
|
+
actions: [],
|
|
1821
|
+
textRanges: null,
|
|
1822
|
+
debounce: true
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1826
|
+
return JSONX.compose(acc, cur);
|
|
1827
|
+
}, null);
|
|
1828
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1829
|
+
transformer.refreshControls();
|
|
1830
|
+
return Boolean(result);
|
|
1831
|
+
}
|
|
2097
1832
|
};
|
|
2098
1833
|
|
|
2099
1834
|
//#endregion
|
|
@@ -2101,22 +1836,24 @@ const DocDrawingPosition = (props) => {
|
|
|
2101
1836
|
const MIN_MARGIN = 0;
|
|
2102
1837
|
const MAX_MARGIN = 100;
|
|
2103
1838
|
const DocDrawingTextWrap = (props) => {
|
|
1839
|
+
var _renderManagerService;
|
|
1840
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
1841
|
+
const drawingParam = props.drawings[0];
|
|
1842
|
+
const scene = drawingParam ? (_renderManagerService = renderManagerService.getRenderUnitById(drawingParam.unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.scene : void 0;
|
|
1843
|
+
return drawingParam && scene ? /* @__PURE__ */ jsx(DocDrawingTextWrapContent, { ...props }) : null;
|
|
1844
|
+
};
|
|
1845
|
+
function DocDrawingTextWrapContent(props) {
|
|
2104
1846
|
const commandService = useDependency(ICommandService);
|
|
2105
1847
|
const localeService = useDependency(LocaleService);
|
|
2106
1848
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2107
|
-
const renderManagerService = useDependency(IRenderManagerService);
|
|
2108
1849
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
2109
1850
|
const { drawings } = props;
|
|
2110
|
-
const
|
|
2111
|
-
if (drawingParam == null) return null;
|
|
2112
|
-
const { unitId } = drawingParam;
|
|
1851
|
+
const { unitId } = drawings[0];
|
|
2113
1852
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2114
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
2115
|
-
if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
|
|
2116
1853
|
const [disableWrapText, setDisableWrapText] = useState(true);
|
|
2117
1854
|
const [disableDistTB, setDisableDistTB] = useState(true);
|
|
2118
1855
|
const [disableDistLR, setDisableDistLR] = useState(true);
|
|
2119
|
-
const [wrappingStyle, setWrappingStyle] = useState(
|
|
1856
|
+
const [wrappingStyle, setWrappingStyle] = useState(TextWrappingStyle.INLINE);
|
|
2120
1857
|
const [wrapText, setWrapText] = useState("");
|
|
2121
1858
|
const [distToText, setDistToText] = useState({
|
|
2122
1859
|
distT: 0,
|
|
@@ -2204,17 +1941,17 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2204
1941
|
else setDisableDistTB(false);
|
|
2205
1942
|
if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE || layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
|
|
2206
1943
|
else setDisableDistLR(false);
|
|
2207
|
-
if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle(
|
|
2208
|
-
else setWrappingStyle(
|
|
1944
|
+
if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle(TextWrappingStyle.BEHIND_TEXT);
|
|
1945
|
+
else setWrappingStyle(TextWrappingStyle.IN_FRONT_OF_TEXT);
|
|
2209
1946
|
else switch (layoutType) {
|
|
2210
1947
|
case PositionedObjectLayoutType.INLINE:
|
|
2211
|
-
setWrappingStyle(
|
|
1948
|
+
setWrappingStyle(TextWrappingStyle.INLINE);
|
|
2212
1949
|
break;
|
|
2213
1950
|
case PositionedObjectLayoutType.WRAP_SQUARE:
|
|
2214
|
-
setWrappingStyle(
|
|
1951
|
+
setWrappingStyle(TextWrappingStyle.WRAP_SQUARE);
|
|
2215
1952
|
break;
|
|
2216
1953
|
case PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
|
|
2217
|
-
setWrappingStyle(
|
|
1954
|
+
setWrappingStyle(TextWrappingStyle.WRAP_TOP_AND_BOTTOM);
|
|
2218
1955
|
break;
|
|
2219
1956
|
default: throw new Error(`Unsupported layout type: ${layoutType}`);
|
|
2220
1957
|
}
|
|
@@ -2254,23 +1991,23 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2254
1991
|
direction: "vertical",
|
|
2255
1992
|
children: [
|
|
2256
1993
|
/* @__PURE__ */ jsx(Radio, {
|
|
2257
|
-
value:
|
|
1994
|
+
value: TextWrappingStyle.INLINE,
|
|
2258
1995
|
children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
|
|
2259
1996
|
}),
|
|
2260
1997
|
/* @__PURE__ */ jsx(Radio, {
|
|
2261
|
-
value:
|
|
1998
|
+
value: TextWrappingStyle.WRAP_SQUARE,
|
|
2262
1999
|
children: localeService.t("docs-drawing-ui.image-text-wrap.square")
|
|
2263
2000
|
}),
|
|
2264
2001
|
/* @__PURE__ */ jsx(Radio, {
|
|
2265
|
-
value:
|
|
2002
|
+
value: TextWrappingStyle.WRAP_TOP_AND_BOTTOM,
|
|
2266
2003
|
children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
|
|
2267
2004
|
}),
|
|
2268
2005
|
/* @__PURE__ */ jsx(Radio, {
|
|
2269
|
-
value:
|
|
2006
|
+
value: TextWrappingStyle.BEHIND_TEXT,
|
|
2270
2007
|
children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
|
|
2271
2008
|
}),
|
|
2272
2009
|
/* @__PURE__ */ jsx(Radio, {
|
|
2273
|
-
value:
|
|
2010
|
+
value: TextWrappingStyle.IN_FRONT_OF_TEXT,
|
|
2274
2011
|
children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
|
|
2275
2012
|
})
|
|
2276
2013
|
]
|
|
@@ -2349,21 +2086,28 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2349
2086
|
})
|
|
2350
2087
|
]
|
|
2351
2088
|
});
|
|
2352
|
-
}
|
|
2089
|
+
}
|
|
2353
2090
|
|
|
2354
2091
|
//#endregion
|
|
2355
2092
|
//#region src/views/doc-image-panel/DocDrawingPanel.tsx
|
|
2093
|
+
/**
|
|
2094
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2095
|
+
*
|
|
2096
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2097
|
+
* you may not use this file except in compliance with the License.
|
|
2098
|
+
* You may obtain a copy of the License at
|
|
2099
|
+
*
|
|
2100
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2101
|
+
*
|
|
2102
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2103
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2104
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2105
|
+
* See the License for the specific language governing permissions and
|
|
2106
|
+
* limitations under the License.
|
|
2107
|
+
*/
|
|
2356
2108
|
const DocDrawingPanel = () => {
|
|
2357
2109
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2358
|
-
const
|
|
2359
|
-
useEffect(() => {
|
|
2360
|
-
const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
|
|
2361
|
-
setDrawings(drawings);
|
|
2362
|
-
});
|
|
2363
|
-
return () => {
|
|
2364
|
-
focusDispose.unsubscribe();
|
|
2365
|
-
};
|
|
2366
|
-
}, []);
|
|
2110
|
+
const drawings = useObservable(() => drawingManagerService.focus$, drawingManagerService.getFocusDrawings(), false, [drawingManagerService]);
|
|
2367
2111
|
return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
|
|
2368
2112
|
className: "univer-text-sm",
|
|
2369
2113
|
children: [
|
|
@@ -2411,6 +2155,19 @@ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))]
|
|
|
2411
2155
|
|
|
2412
2156
|
//#endregion
|
|
2413
2157
|
//#region src/controllers/doc-drawing-notification.controller.ts
|
|
2158
|
+
function findDrawingAnchorInPage(page, drawingId, pageMarginTop, pageMarginLeft) {
|
|
2159
|
+
const skeDrawing = page.skeDrawings.get(drawingId);
|
|
2160
|
+
if (skeDrawing) return {
|
|
2161
|
+
skeDrawing,
|
|
2162
|
+
pageMarginTop,
|
|
2163
|
+
pageMarginLeft
|
|
2164
|
+
};
|
|
2165
|
+
for (const table of page.skeTables.values()) for (const row of table.rows) for (const cell of row.cells) {
|
|
2166
|
+
const cellAnchor = findDrawingAnchorInPage(cell, drawingId, cell.marginTop, cell.marginLeft);
|
|
2167
|
+
if (cellAnchor) return cellAnchor;
|
|
2168
|
+
}
|
|
2169
|
+
return null;
|
|
2170
|
+
}
|
|
2414
2171
|
function getAddOrRemoveDrawings(actions) {
|
|
2415
2172
|
if (JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
|
|
2416
2173
|
const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
|
|
@@ -2450,14 +2207,33 @@ function getReOrderedDrawings(actions) {
|
|
|
2450
2207
|
}
|
|
2451
2208
|
return drawingIndexes;
|
|
2452
2209
|
}
|
|
2210
|
+
function collectUpdatedDrawingIds(actions, drawingIds = /* @__PURE__ */ new Set()) {
|
|
2211
|
+
if (JSONX.isNoop(actions) || !Array.isArray(actions)) return drawingIds;
|
|
2212
|
+
if (actions[0] === "drawings") {
|
|
2213
|
+
const drawingKeyOrOps = actions[1];
|
|
2214
|
+
if (typeof drawingKeyOrOps === "string") {
|
|
2215
|
+
drawingIds.add(drawingKeyOrOps);
|
|
2216
|
+
return drawingIds;
|
|
2217
|
+
}
|
|
2218
|
+
actions.slice(1).forEach((action) => {
|
|
2219
|
+
if (Array.isArray(action) && typeof action[0] === "string") drawingIds.add(action[0]);
|
|
2220
|
+
});
|
|
2221
|
+
return drawingIds;
|
|
2222
|
+
}
|
|
2223
|
+
actions.forEach((action) => {
|
|
2224
|
+
if (Array.isArray(action)) collectUpdatedDrawingIds(action, drawingIds);
|
|
2225
|
+
});
|
|
2226
|
+
return drawingIds;
|
|
2227
|
+
}
|
|
2453
2228
|
let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends Disposable {
|
|
2454
|
-
constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
|
|
2229
|
+
constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService, _docRefreshDrawingsService) {
|
|
2455
2230
|
super();
|
|
2456
2231
|
this._univerInstanceService = _univerInstanceService;
|
|
2457
2232
|
this._commandService = _commandService;
|
|
2458
2233
|
this._drawingManagerService = _drawingManagerService;
|
|
2459
2234
|
this._docDrawingService = _docDrawingService;
|
|
2460
2235
|
this._renderManagerService = _renderManagerService;
|
|
2236
|
+
this._docRefreshDrawingsService = _docRefreshDrawingsService;
|
|
2461
2237
|
this._initialize();
|
|
2462
2238
|
}
|
|
2463
2239
|
_initialize() {
|
|
@@ -2474,10 +2250,25 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2474
2250
|
else this._removeDrawings(unitId, [drawingId]);
|
|
2475
2251
|
}
|
|
2476
2252
|
}));
|
|
2253
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
2254
|
+
if (command.id !== UpdateDocDrawingWrappingStyleCommand.id) return;
|
|
2255
|
+
this._preserveWrappingStylePosition(command.params);
|
|
2256
|
+
}));
|
|
2477
2257
|
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2478
2258
|
if (command.id !== RichTextEditingMutation.id) return;
|
|
2479
2259
|
const { unitId, actions } = command.params;
|
|
2480
2260
|
if (getReOrderedDrawings(actions).length > 0) this._updateDrawingsOrder(unitId);
|
|
2261
|
+
const updatedDrawingIds = [...collectUpdatedDrawingIds(actions)];
|
|
2262
|
+
if (updatedDrawingIds.length > 0) this._syncDrawingDataFromSnapshot(unitId, updatedDrawingIds);
|
|
2263
|
+
}));
|
|
2264
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2265
|
+
if (command.id !== UpdateDrawingDocTransformCommand.id && command.id !== UpdateDocDrawingWrappingStyleCommand.id) return;
|
|
2266
|
+
const { unitId } = command.params;
|
|
2267
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
2268
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2269
|
+
if (renderObject == null || scene == null) return;
|
|
2270
|
+
this._docRefreshDrawingsService.refreshDrawings(renderObject.with(DocSkeletonManagerService).getSkeleton());
|
|
2271
|
+
scene.getTransformerByCreate().refreshControls();
|
|
2481
2272
|
}));
|
|
2482
2273
|
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2483
2274
|
var _this$_univerInstance;
|
|
@@ -2491,6 +2282,65 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2491
2282
|
scene.getTransformerByCreate().refreshControls();
|
|
2492
2283
|
}));
|
|
2493
2284
|
}
|
|
2285
|
+
_preserveWrappingStylePosition(params) {
|
|
2286
|
+
var _documentDataModel$ge;
|
|
2287
|
+
if (params.wrappingStyle === TextWrappingStyle.INLINE) return;
|
|
2288
|
+
const { unitId } = params;
|
|
2289
|
+
const documentDataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2290
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
2291
|
+
const skeletonManager = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService);
|
|
2292
|
+
const skeletonData = skeletonManager === null || skeletonManager === void 0 ? void 0 : skeletonManager.getSkeleton().getSkeletonData();
|
|
2293
|
+
const viewModel = skeletonManager === null || skeletonManager === void 0 ? void 0 : skeletonManager.getViewModel();
|
|
2294
|
+
if (!documentDataModel || !skeletonData || !viewModel) return;
|
|
2295
|
+
const editArea = viewModel.getEditArea();
|
|
2296
|
+
const { pages, skeHeaders, skeFooters } = skeletonData;
|
|
2297
|
+
const oldDrawings = (_documentDataModel$ge = documentDataModel.getDrawings()) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {};
|
|
2298
|
+
params.drawings = params.drawings.map((drawing) => {
|
|
2299
|
+
const oldDrawing = oldDrawings[drawing.drawingId];
|
|
2300
|
+
if (!oldDrawing) return drawing;
|
|
2301
|
+
let drawingAnchor = null;
|
|
2302
|
+
for (const page of pages) {
|
|
2303
|
+
const { headerId, footerId, marginTop, marginLeft, marginBottom, pageWidth, pageHeight } = page;
|
|
2304
|
+
if (editArea === DocumentEditArea.HEADER) {
|
|
2305
|
+
var _skeHeaders$get;
|
|
2306
|
+
const header = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
|
|
2307
|
+
if (header) drawingAnchor = findDrawingAnchorInPage(header, drawing.drawingId, header.marginTop, marginLeft);
|
|
2308
|
+
} else if (editArea === DocumentEditArea.FOOTER) {
|
|
2309
|
+
var _skeFooters$get;
|
|
2310
|
+
const footer = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
|
|
2311
|
+
if (footer) drawingAnchor = findDrawingAnchorInPage(footer, drawing.drawingId, pageHeight - marginBottom + footer.marginTop, marginLeft);
|
|
2312
|
+
} else drawingAnchor = findDrawingAnchorInPage(page, drawing.drawingId, marginTop, marginLeft);
|
|
2313
|
+
if (drawingAnchor) break;
|
|
2314
|
+
}
|
|
2315
|
+
if (!drawingAnchor) return drawing;
|
|
2316
|
+
const { skeDrawing, pageMarginTop, pageMarginLeft } = drawingAnchor;
|
|
2317
|
+
const oldPositionH = oldDrawing.docTransform.positionH;
|
|
2318
|
+
const oldPositionV = oldDrawing.docTransform.positionV;
|
|
2319
|
+
let posOffsetH = skeDrawing.aLeft;
|
|
2320
|
+
let posOffsetV = skeDrawing.aTop;
|
|
2321
|
+
if (oldPositionH.relativeFrom === ObjectRelativeFromH.MARGIN) posOffsetH -= pageMarginLeft;
|
|
2322
|
+
else if (oldPositionH.relativeFrom === ObjectRelativeFromH.COLUMN) posOffsetH -= skeDrawing.columnLeft;
|
|
2323
|
+
if (oldPositionV.relativeFrom === ObjectRelativeFromV.PAGE) posOffsetV += pageMarginTop;
|
|
2324
|
+
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.LINE) posOffsetV -= skeDrawing.lineTop;
|
|
2325
|
+
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH) posOffsetV -= skeDrawing.blockAnchorTop;
|
|
2326
|
+
return {
|
|
2327
|
+
...oldDrawing,
|
|
2328
|
+
...drawing,
|
|
2329
|
+
docTransform: {
|
|
2330
|
+
...oldDrawing.docTransform,
|
|
2331
|
+
...drawing.docTransform,
|
|
2332
|
+
positionH: {
|
|
2333
|
+
relativeFrom: oldPositionH.relativeFrom,
|
|
2334
|
+
posOffset: posOffsetH
|
|
2335
|
+
},
|
|
2336
|
+
positionV: {
|
|
2337
|
+
relativeFrom: oldPositionV.relativeFrom,
|
|
2338
|
+
posOffset: posOffsetV
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2494
2344
|
_addDrawings(unitId, drawings) {
|
|
2495
2345
|
const drawingManagerService = this._drawingManagerService;
|
|
2496
2346
|
const docDrawingService = this._docDrawingService;
|
|
@@ -2537,13 +2387,33 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2537
2387
|
drawingIds: drawingsOrder
|
|
2538
2388
|
});
|
|
2539
2389
|
}
|
|
2390
|
+
_syncDrawingDataFromSnapshot(unitId, drawingIds) {
|
|
2391
|
+
const documentDataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2392
|
+
if (documentDataModel == null) return;
|
|
2393
|
+
const { drawings = {}, drawingsOrder = [] } = documentDataModel.getSnapshot();
|
|
2394
|
+
const drawingData = drawings;
|
|
2395
|
+
const renderOrder = getDocDrawingRenderOrder(drawingsOrder, drawings);
|
|
2396
|
+
this._docDrawingService.setDrawingData(unitId, unitId, drawingData);
|
|
2397
|
+
this._drawingManagerService.setDrawingData(unitId, unitId, drawingData);
|
|
2398
|
+
this._docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
|
|
2399
|
+
this._drawingManagerService.setDrawingOrder(unitId, unitId, renderOrder);
|
|
2400
|
+
const objects = drawingIds.filter((drawingId) => drawingData[drawingId] != null).map((drawingId) => ({
|
|
2401
|
+
unitId,
|
|
2402
|
+
subUnitId: unitId,
|
|
2403
|
+
drawingId
|
|
2404
|
+
}));
|
|
2405
|
+
if (objects.length === 0) return;
|
|
2406
|
+
this._docDrawingService.updateNotification(objects);
|
|
2407
|
+
this._drawingManagerService.updateNotification(objects);
|
|
2408
|
+
}
|
|
2540
2409
|
};
|
|
2541
2410
|
DocDrawingAddRemoveController = __decorate([
|
|
2542
2411
|
__decorateParam(0, IUniverInstanceService),
|
|
2543
2412
|
__decorateParam(1, ICommandService),
|
|
2544
2413
|
__decorateParam(2, IDrawingManagerService),
|
|
2545
2414
|
__decorateParam(3, IDocDrawingService),
|
|
2546
|
-
__decorateParam(4, IRenderManagerService)
|
|
2415
|
+
__decorateParam(4, IRenderManagerService),
|
|
2416
|
+
__decorateParam(5, Inject(DocRefreshDrawingsService))
|
|
2547
2417
|
], DocDrawingAddRemoveController);
|
|
2548
2418
|
|
|
2549
2419
|
//#endregion
|
|
@@ -2918,6 +2788,8 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
|
|
|
2918
2788
|
width,
|
|
2919
2789
|
height,
|
|
2920
2790
|
angle,
|
|
2791
|
+
flipX: drawingOrigin.docTransform.flipX,
|
|
2792
|
+
flipY: drawingOrigin.docTransform.flipY,
|
|
2921
2793
|
clipBounds: pageClipBounds
|
|
2922
2794
|
};
|
|
2923
2795
|
if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
|
|
@@ -2927,6 +2799,7 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
|
|
|
2927
2799
|
behindText,
|
|
2928
2800
|
transform,
|
|
2929
2801
|
transforms: [transform],
|
|
2802
|
+
customBlockRenderViewport: drawing.customBlockRenderViewport,
|
|
2930
2803
|
isMultiTransform
|
|
2931
2804
|
};
|
|
2932
2805
|
else if (isMultiTransform === BooleanNumber.TRUE) updateDrawingMap[drawingId].transforms.push(transform);
|
|
@@ -3520,75 +3393,6 @@ DocDrawingTransformerController = __decorate([
|
|
|
3520
3393
|
__decorateParam(3, IRenderManagerService)
|
|
3521
3394
|
], DocDrawingTransformerController);
|
|
3522
3395
|
|
|
3523
|
-
//#endregion
|
|
3524
|
-
//#region src/menu/schema.ts
|
|
3525
|
-
const menuSchema = {
|
|
3526
|
-
[RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
|
|
3527
|
-
order: 0,
|
|
3528
|
-
menuItemFactory: ImageMenuFactory,
|
|
3529
|
-
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
3530
|
-
order: 0,
|
|
3531
|
-
menuItemFactory: UploadFloatImageMenuFactory
|
|
3532
|
-
}
|
|
3533
|
-
} },
|
|
3534
|
-
[ContextMenuPosition.PARAGRAPH]: {
|
|
3535
|
-
[ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
3536
|
-
order: 5,
|
|
3537
|
-
menuItemFactory: UploadFloatImageMenuFactory
|
|
3538
|
-
} } },
|
|
3539
|
-
[EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
3540
|
-
order: 5,
|
|
3541
|
-
menuItemFactory: UploadFloatImageMenuFactory
|
|
3542
|
-
} } },
|
|
3543
|
-
[DOC_CONTENT_INSERT_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
3544
|
-
order: 5,
|
|
3545
|
-
menuItemFactory: UploadFloatImageMenuFactory
|
|
3546
|
-
} } },
|
|
3547
|
-
[DOC_PARAGRAPH_T_INSERT_MENU_ID]: { insert: {
|
|
3548
|
-
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
3549
|
-
order: 1,
|
|
3550
|
-
menuItemFactory: UploadFloatImageMenuFactory
|
|
3551
|
-
},
|
|
3552
|
-
[DOCS_SHAPE_MENU_ID]: {
|
|
3553
|
-
order: 2,
|
|
3554
|
-
menuItemFactory: ShapeMenuFactory
|
|
3555
|
-
}
|
|
3556
|
-
} },
|
|
3557
|
-
[DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID]: { insert: {
|
|
3558
|
-
[`${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`]: {
|
|
3559
|
-
order: 1,
|
|
3560
|
-
menuItemFactory: UploadFloatImageBelowMenuFactory
|
|
3561
|
-
},
|
|
3562
|
-
[DOCS_SHAPE_BELOW_MENU_ID]: {
|
|
3563
|
-
order: 2,
|
|
3564
|
-
menuItemFactory: ShapeBelowMenuFactory
|
|
3565
|
-
}
|
|
3566
|
-
} },
|
|
3567
|
-
[DOCS_SHAPE_MENU_ID]: { shapes: {
|
|
3568
|
-
order: 0,
|
|
3569
|
-
[InsertDocRectangleShapeCommand.id]: {
|
|
3570
|
-
order: 0,
|
|
3571
|
-
menuItemFactory: InsertRectangleShapeMenuFactory
|
|
3572
|
-
},
|
|
3573
|
-
[InsertDocEllipseShapeCommand.id]: {
|
|
3574
|
-
order: 1,
|
|
3575
|
-
menuItemFactory: InsertEllipseShapeMenuFactory
|
|
3576
|
-
}
|
|
3577
|
-
} },
|
|
3578
|
-
[DOCS_SHAPE_BELOW_MENU_ID]: { shapes: {
|
|
3579
|
-
order: 0,
|
|
3580
|
-
[`${InsertDocRectangleShapeCommand.id}.below`]: {
|
|
3581
|
-
order: 0,
|
|
3582
|
-
menuItemFactory: InsertRectangleShapeBelowMenuFactory
|
|
3583
|
-
},
|
|
3584
|
-
[`${InsertDocEllipseShapeCommand.id}.below`]: {
|
|
3585
|
-
order: 1,
|
|
3586
|
-
menuItemFactory: InsertEllipseShapeBelowMenuFactory
|
|
3587
|
-
}
|
|
3588
|
-
} }
|
|
3589
|
-
}
|
|
3590
|
-
};
|
|
3591
|
-
|
|
3592
3396
|
//#endregion
|
|
3593
3397
|
//#region src/controllers/shortcuts/drawing.shortcut.ts
|
|
3594
3398
|
function whenDocDrawingFocused(contextService) {
|
|
@@ -3678,22 +3482,17 @@ let DocDrawingUIController = class DocDrawingUIController extends Disposable {
|
|
|
3678
3482
|
InsertDocImageCommand,
|
|
3679
3483
|
InsertDocRectangleShapeCommand,
|
|
3680
3484
|
InsertDocEllipseShapeCommand,
|
|
3681
|
-
InsertDocDrawingCommand,
|
|
3682
|
-
UpdateDocDrawingWrappingStyleCommand,
|
|
3683
3485
|
UpdateDocDrawingDistanceCommand,
|
|
3684
3486
|
UpdateDocDrawingWrapTextCommand,
|
|
3685
|
-
UpdateDrawingDocTransformCommand,
|
|
3686
3487
|
IMoveInlineDrawingCommand,
|
|
3687
3488
|
ITransformNonInlineDrawingCommand,
|
|
3688
|
-
RemoveDocDrawingCommand,
|
|
3689
3489
|
SidebarDocDrawingOperation,
|
|
3690
3490
|
ClearDocDrawingTransformerOperation,
|
|
3691
3491
|
EditDocDrawingOperation,
|
|
3692
3492
|
GroupDocDrawingCommand,
|
|
3693
3493
|
UngroupDocDrawingCommand,
|
|
3694
3494
|
MoveDocDrawingsCommand,
|
|
3695
|
-
DeleteDocDrawingsCommand
|
|
3696
|
-
SetDocDrawingArrangeCommand
|
|
3495
|
+
DeleteDocDrawingsCommand
|
|
3697
3496
|
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
3698
3497
|
}
|
|
3699
3498
|
_initShortcuts() {
|
|
@@ -3720,16 +3519,40 @@ DocDrawingUIController = __decorate([
|
|
|
3720
3519
|
__decorateParam(2, IShortcutService)
|
|
3721
3520
|
], DocDrawingUIController);
|
|
3722
3521
|
|
|
3522
|
+
//#endregion
|
|
3523
|
+
//#region src/services/doc-drawing-floating-toolbar-adapter.service.ts
|
|
3524
|
+
var DocDrawingFloatingToolbarAdapterService = class {
|
|
3525
|
+
constructor() {
|
|
3526
|
+
_defineProperty(this, "_adapters", []);
|
|
3527
|
+
}
|
|
3528
|
+
registerAdapter(adapter) {
|
|
3529
|
+
this._adapters.push(adapter);
|
|
3530
|
+
return toDisposable(() => {
|
|
3531
|
+
const index = this._adapters.indexOf(adapter);
|
|
3532
|
+
if (index >= 0) this._adapters.splice(index, 1);
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
getItems(params) {
|
|
3536
|
+
for (const adapter of this._adapters) {
|
|
3537
|
+
const items = adapter.getItems(params);
|
|
3538
|
+
if (items) return [...items].sort((a, b) => a.index - b.index);
|
|
3539
|
+
}
|
|
3540
|
+
return null;
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
3543
|
+
|
|
3723
3544
|
//#endregion
|
|
3724
3545
|
//#region src/menu/drawing-popup-menu.controller.ts
|
|
3725
3546
|
let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends RxDisposable {
|
|
3726
|
-
constructor(_drawingManagerService, _canvasPopManagerService, _renderManagerService, _univerInstanceService, _contextService, _commandService) {
|
|
3547
|
+
constructor(_drawingManagerService, _canvasPopManagerService, _renderManagerService, _univerInstanceService, _contextService, _drawingAdapterService, _floatingToolbarAdapterService, _commandService) {
|
|
3727
3548
|
super();
|
|
3728
3549
|
this._drawingManagerService = _drawingManagerService;
|
|
3729
3550
|
this._canvasPopManagerService = _canvasPopManagerService;
|
|
3730
3551
|
this._renderManagerService = _renderManagerService;
|
|
3731
3552
|
this._univerInstanceService = _univerInstanceService;
|
|
3732
3553
|
this._contextService = _contextService;
|
|
3554
|
+
this._drawingAdapterService = _drawingAdapterService;
|
|
3555
|
+
this._floatingToolbarAdapterService = _floatingToolbarAdapterService;
|
|
3733
3556
|
this._commandService = _commandService;
|
|
3734
3557
|
_defineProperty(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
|
|
3735
3558
|
_defineProperty(this, "_disposePopups", []);
|
|
@@ -3799,13 +3622,14 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
|
|
|
3799
3622
|
if (!drawingParam || drawingParam.drawingType === DrawingTypeEnum.DRAWING_DOM || drawingParam.drawingType === DrawingTypeEnum.DRAWING_SHAPE) return;
|
|
3800
3623
|
const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
|
|
3801
3624
|
const isImage = drawingType === DrawingTypeEnum.DRAWING_IMAGE;
|
|
3625
|
+
const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
|
|
3802
3626
|
const popup = this._canvasPopManagerService.attachPopupToObject(object, {
|
|
3803
3627
|
componentKey: COMPONENT_IMAGE_POPUP_MENU,
|
|
3804
|
-
direction: isImage ? "top-center" : "horizontal",
|
|
3805
|
-
offset: isImage ? [0, 8] : [2, 0],
|
|
3628
|
+
direction: isImage || isChart ? "top-center" : "horizontal",
|
|
3629
|
+
offset: isImage || isChart ? [0, 8] : [2, 0],
|
|
3806
3630
|
extraProps: {
|
|
3807
|
-
menuItems: this.
|
|
3808
|
-
variant: isImage ? "doc-floating-toolbar" : void 0,
|
|
3631
|
+
menuItems: this._getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType),
|
|
3632
|
+
variant: isImage ? "doc-floating-toolbar" : isChart ? "doc-chart-floating-toolbar" : void 0,
|
|
3809
3633
|
unitId,
|
|
3810
3634
|
subUnitId,
|
|
3811
3635
|
drawingId
|
|
@@ -3834,22 +3658,53 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
|
|
|
3834
3658
|
disposePopups.length = 0;
|
|
3835
3659
|
}));
|
|
3836
3660
|
}
|
|
3837
|
-
|
|
3661
|
+
_getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType) {
|
|
3662
|
+
var _editCommandInfo$labe, _editCommandInfo$comm, _editCommandInfo$comm2, _editCommandInfo$disa;
|
|
3663
|
+
const drawing = this._drawingManagerService.getDrawingByParam({
|
|
3664
|
+
unitId,
|
|
3665
|
+
subUnitId,
|
|
3666
|
+
drawingId
|
|
3667
|
+
});
|
|
3668
|
+
const floatingToolbarMenuItems = drawing ? this._floatingToolbarAdapterService.getItems({
|
|
3669
|
+
unitId,
|
|
3670
|
+
subUnitId,
|
|
3671
|
+
drawing
|
|
3672
|
+
}) : null;
|
|
3673
|
+
if (floatingToolbarMenuItems) return floatingToolbarMenuItems;
|
|
3674
|
+
const editCommandInfo = drawing ? this._drawingAdapterService.getEditDrawingCommandInfo({
|
|
3675
|
+
unitId,
|
|
3676
|
+
subUnitId,
|
|
3677
|
+
drawing
|
|
3678
|
+
}) : null;
|
|
3838
3679
|
return [
|
|
3839
3680
|
{
|
|
3840
|
-
label: "docs-drawing-ui.image-popup.edit",
|
|
3681
|
+
label: (_editCommandInfo$labe = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.label) !== null && _editCommandInfo$labe !== void 0 ? _editCommandInfo$labe : "docs-drawing-ui.image-popup.edit",
|
|
3841
3682
|
index: 0,
|
|
3842
|
-
commandId: EditDocDrawingOperation.id,
|
|
3683
|
+
commandId: (_editCommandInfo$comm = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandId) !== null && _editCommandInfo$comm !== void 0 ? _editCommandInfo$comm : EditDocDrawingOperation.id,
|
|
3684
|
+
commandParams: (_editCommandInfo$comm2 = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandParams) !== null && _editCommandInfo$comm2 !== void 0 ? _editCommandInfo$comm2 : {
|
|
3685
|
+
unitId,
|
|
3686
|
+
subUnitId,
|
|
3687
|
+
drawingId
|
|
3688
|
+
},
|
|
3689
|
+
disable: (_editCommandInfo$disa = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.disable) !== null && _editCommandInfo$disa !== void 0 ? _editCommandInfo$disa : drawingType === DrawingTypeEnum.DRAWING_DOM,
|
|
3690
|
+
hideOnClick: true,
|
|
3691
|
+
icon: "DrawingEditIcon"
|
|
3692
|
+
},
|
|
3693
|
+
{
|
|
3694
|
+
label: "docs-drawing-ui.image-popup.crop",
|
|
3695
|
+
index: 1,
|
|
3696
|
+
commandId: OpenImageCropOperation.id,
|
|
3843
3697
|
commandParams: {
|
|
3844
3698
|
unitId,
|
|
3845
3699
|
subUnitId,
|
|
3846
3700
|
drawingId
|
|
3847
3701
|
},
|
|
3848
|
-
disable: drawingType === DrawingTypeEnum.DRAWING_DOM
|
|
3702
|
+
disable: drawingType === DrawingTypeEnum.DRAWING_DOM,
|
|
3703
|
+
icon: "DrawingCropIcon"
|
|
3849
3704
|
},
|
|
3850
3705
|
{
|
|
3851
3706
|
label: "docs-drawing-ui.image-popup.delete",
|
|
3852
|
-
index:
|
|
3707
|
+
index: 2,
|
|
3853
3708
|
commandId: RemoveDocDrawingCommand.id,
|
|
3854
3709
|
commandParams: {
|
|
3855
3710
|
unitId,
|
|
@@ -3859,18 +3714,8 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
|
|
|
3859
3714
|
drawingId
|
|
3860
3715
|
}]
|
|
3861
3716
|
},
|
|
3862
|
-
disable: false
|
|
3863
|
-
|
|
3864
|
-
{
|
|
3865
|
-
label: "docs-drawing-ui.image-popup.crop",
|
|
3866
|
-
index: 2,
|
|
3867
|
-
commandId: OpenImageCropOperation.id,
|
|
3868
|
-
commandParams: {
|
|
3869
|
-
unitId,
|
|
3870
|
-
subUnitId,
|
|
3871
|
-
drawingId
|
|
3872
|
-
},
|
|
3873
|
-
disable: drawingType === DrawingTypeEnum.DRAWING_DOM
|
|
3717
|
+
disable: false,
|
|
3718
|
+
icon: "DrawingDeleteIcon"
|
|
3874
3719
|
},
|
|
3875
3720
|
{
|
|
3876
3721
|
label: "docs-drawing-ui.image-popup.reset",
|
|
@@ -3892,7 +3737,9 @@ DocDrawingPopupMenuController = __decorate([
|
|
|
3892
3737
|
__decorateParam(2, IRenderManagerService),
|
|
3893
3738
|
__decorateParam(3, IUniverInstanceService),
|
|
3894
3739
|
__decorateParam(4, IContextService),
|
|
3895
|
-
__decorateParam(5,
|
|
3740
|
+
__decorateParam(5, IDocDrawingAdapterService),
|
|
3741
|
+
__decorateParam(6, Inject(DocDrawingFloatingToolbarAdapterService)),
|
|
3742
|
+
__decorateParam(7, ICommandService)
|
|
3896
3743
|
], DocDrawingPopupMenuController);
|
|
3897
3744
|
|
|
3898
3745
|
//#endregion
|
|
@@ -3915,6 +3762,7 @@ let UniverDocsDrawingUIPlugin = class UniverDocsDrawingUIPlugin extends Plugin {
|
|
|
3915
3762
|
[DocDrawingTransformerController],
|
|
3916
3763
|
[DocDrawingAddRemoveController],
|
|
3917
3764
|
[DocRefreshDrawingsService],
|
|
3765
|
+
[DocDrawingFloatingToolbarAdapterService],
|
|
3918
3766
|
[DocFloatDomController],
|
|
3919
3767
|
[DocDrawingPrintingController]
|
|
3920
3768
|
].forEach((dependency) => this._injector.add(dependency));
|
|
@@ -3944,4 +3792,4 @@ UniverDocsDrawingUIPlugin = __decorate([
|
|
|
3944
3792
|
], UniverDocsDrawingUIPlugin);
|
|
3945
3793
|
|
|
3946
3794
|
//#endregion
|
|
3947
|
-
export { ClearDocDrawingTransformerOperation, DOCS_IMAGE_MENU_ID, DOCS_SHAPE_BELOW_MENU_ID, DOCS_SHAPE_MENU_ID, DeleteDocDrawingsCommand, DocDrawingPosition, DocDrawingTextWrap, DocFloatDomController, EditDocDrawingOperation, GroupDocDrawingCommand,
|
|
3795
|
+
export { ClearDocDrawingTransformerOperation, DOCS_IMAGE_MENU_ID, DOCS_SHAPE_BELOW_MENU_ID, DOCS_SHAPE_MENU_ID, DeleteDocDrawingsCommand, DocDrawingFloatingToolbarAdapterService, DocDrawingPosition, DocDrawingTextWrap, DocFloatDomController, menuSchema as DocsDrawingUIMenuSchema, EditDocDrawingOperation, GroupDocDrawingCommand, InsertDocEllipseShapeCommand, InsertDocImageCommand, InsertDocRectangleShapeCommand, MoveDocDrawingsCommand, SidebarDocDrawingOperation, UngroupDocDrawingCommand, UniverDocsDrawingUIPlugin };
|