@univerjs/docs-drawing-ui 1.0.0-alpha.3 → 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 +906 -1351
- package/lib/es/index.js +898 -1339
- package/lib/index.js +898 -1339
- package/lib/types/commands/commands/update-doc-drawing.command.d.ts +1 -34
- package/lib/types/controllers/doc-drawing-notification.controller.d.ts +4 -1
- package/lib/types/index.d.ts +0 -4
- package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
- package/lib/types/commands/commands/insert-doc-drawing.command.d.ts +0 -20
- package/lib/types/commands/commands/interfaces.d.ts +0 -36
- 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,149 +1,16 @@
|
|
|
1
|
-
import { AlignTypeH, AlignTypeV,
|
|
2
|
-
import { IDocDrawingAdapterService, 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";
|
|
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
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 } from "@univerjs/ui";
|
|
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, _removeDrawings$, _documentDataModel$ge3;
|
|
23
|
-
const commandService = accessor.get(ICommandService);
|
|
24
|
-
const undoRedoService = accessor.get(IUndoRedoService);
|
|
25
|
-
const drawingAdapterService = accessor.get(IDocDrawingAdapterService);
|
|
26
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
27
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
28
|
-
const documentDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
29
|
-
if (params == null || documentDataModel == null) return false;
|
|
30
|
-
const docSelectionRenderService = renderManagerService.getRenderById(params.unitId).with(DocSelectionRenderService);
|
|
31
|
-
const { drawings: removeDrawings } = params;
|
|
32
|
-
const segmentId = (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "";
|
|
33
|
-
const textX = new TextX();
|
|
34
|
-
const jsonX = JSONX.getInstance();
|
|
35
|
-
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 : [];
|
|
36
|
-
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
37
|
-
const unitId = (_removeDrawings$ = removeDrawings[0]) === null || _removeDrawings$ === void 0 ? void 0 : _removeDrawings$.unitId;
|
|
38
|
-
if (unitId == null || removeCustomBlocks.length === 0) return false;
|
|
39
|
-
const drawings = (_documentDataModel$ge3 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : {};
|
|
40
|
-
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
41
|
-
const removeDrawingSnapshots = removeCustomBlocks.map((block) => drawings[block.blockId]).filter((drawing) => drawing != null);
|
|
42
|
-
const resourceRedoMutations = [];
|
|
43
|
-
const resourceUndoMutations = [];
|
|
44
|
-
const resourceMutationGroups = [];
|
|
45
|
-
for (const block of removeCustomBlocks) {
|
|
46
|
-
var _removeDrawingParam$s;
|
|
47
|
-
const { blockId } = block;
|
|
48
|
-
const drawing = drawings[blockId];
|
|
49
|
-
if (drawing == null) continue;
|
|
50
|
-
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
51
|
-
const mutationInfos = drawingAdapterService.getRemoveDrawingMutationInfos({
|
|
52
|
-
unitId,
|
|
53
|
-
subUnitId: (_removeDrawingParam$s = removeDrawingParam === null || removeDrawingParam === void 0 ? void 0 : removeDrawingParam.subUnitId) !== null && _removeDrawingParam$s !== void 0 ? _removeDrawingParam$s : unitId,
|
|
54
|
-
drawing,
|
|
55
|
-
removeDrawings: removeDrawingSnapshots
|
|
56
|
-
});
|
|
57
|
-
if (mutationInfos.redoMutations.length === 0 && mutationInfos.undoMutations.length === 0) continue;
|
|
58
|
-
resourceRedoMutations.push(...mutationInfos.redoMutations);
|
|
59
|
-
resourceUndoMutations.push(...mutationInfos.undoMutations);
|
|
60
|
-
resourceMutationGroups.push(mutationInfos);
|
|
61
|
-
}
|
|
62
|
-
if (!executeResourceMutationGroups(resourceMutationGroups, commandService)) return false;
|
|
63
|
-
const historyId = `doc-drawing-remove-resource:${unitId}:${removeCustomBlocks.map((block) => block.blockId).join(",")}`;
|
|
64
|
-
let batchingDisposable = null;
|
|
65
|
-
if (resourceRedoMutations.length > 0 || resourceUndoMutations.length > 0) {
|
|
66
|
-
batchingDisposable = undoRedoService.__tempBatchingUndoRedo(unitId);
|
|
67
|
-
undoRedoService.pushUndoRedo({
|
|
68
|
-
unitID: unitId,
|
|
69
|
-
redoMutations: resourceRedoMutations,
|
|
70
|
-
undoMutations: resourceUndoMutations,
|
|
71
|
-
id: historyId
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const memoryCursor = new MemoryCursor();
|
|
75
|
-
memoryCursor.reset();
|
|
76
|
-
const cursorIndex = removeCustomBlocks[0].startIndex;
|
|
77
|
-
const textRanges = [{
|
|
78
|
-
startOffset: cursorIndex,
|
|
79
|
-
endOffset: cursorIndex
|
|
80
|
-
}];
|
|
81
|
-
const doMutation = {
|
|
82
|
-
id: RichTextEditingMutation.id,
|
|
83
|
-
params: {
|
|
84
|
-
unitId,
|
|
85
|
-
actions: [],
|
|
86
|
-
textRanges
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const rawActions = [];
|
|
90
|
-
for (const block of removeCustomBlocks) {
|
|
91
|
-
const { startIndex } = block;
|
|
92
|
-
if (startIndex > memoryCursor.cursor) textX.push({
|
|
93
|
-
t: TextXActionType.RETAIN,
|
|
94
|
-
len: startIndex - memoryCursor.cursor
|
|
95
|
-
});
|
|
96
|
-
textX.push({
|
|
97
|
-
t: TextXActionType.DELETE,
|
|
98
|
-
len: 1
|
|
99
|
-
});
|
|
100
|
-
memoryCursor.moveCursorTo(startIndex + 1);
|
|
101
|
-
}
|
|
102
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
103
|
-
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
104
|
-
for (const block of removeCustomBlocks) {
|
|
105
|
-
const { blockId } = block;
|
|
106
|
-
const drawingIndex = documentDataModel.getDrawingsOrder().indexOf(blockId);
|
|
107
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawings[blockId]);
|
|
108
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
109
|
-
rawActions.push(removeDrawingAction);
|
|
110
|
-
rawActions.push(removeDrawingOrderAction);
|
|
111
|
-
}
|
|
112
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
113
|
-
return JSONX.compose(acc, cur);
|
|
114
|
-
}, null);
|
|
115
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
116
|
-
if (!result && batchingDisposable != null) {
|
|
117
|
-
batchingDisposable.dispose();
|
|
118
|
-
undoRedoService.rollback(historyId, unitId);
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
batchingDisposable === null || batchingDisposable === void 0 || batchingDisposable.dispose();
|
|
122
|
-
return Boolean(result);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
function executeResourceMutationGroups(mutationGroups, commandService) {
|
|
126
|
-
const executedUndoGroups = [];
|
|
127
|
-
for (const mutationGroup of mutationGroups) {
|
|
128
|
-
if (!executeMutations(mutationGroup.redoMutations, commandService)) {
|
|
129
|
-
executeMutationGroups([...executedUndoGroups].reverse(), commandService);
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
executedUndoGroups.push(mutationGroup.undoMutations);
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
function executeMutationGroups(mutationGroups, commandService) {
|
|
137
|
-
mutationGroups.forEach((mutations) => {
|
|
138
|
-
executeMutations(mutations, commandService);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function executeMutations(mutations, commandService) {
|
|
142
|
-
for (const mutation of mutations) if (!commandService.syncExecuteCommand(mutation.id, mutation.params)) return false;
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
14
|
//#region src/commands/commands/delete-doc-drawing.command.ts
|
|
148
15
|
const DeleteDocDrawingsCommand = {
|
|
149
16
|
id: "doc.command.delete-drawing",
|
|
@@ -182,179 +49,6 @@ const GroupDocDrawingCommand = {
|
|
|
182
49
|
}
|
|
183
50
|
};
|
|
184
51
|
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/commands/commands/insert-doc-drawing.command.ts
|
|
187
|
-
/**
|
|
188
|
-
* The command to insert new drawings
|
|
189
|
-
*/
|
|
190
|
-
const InsertDocDrawingCommand = {
|
|
191
|
-
id: "doc.command.insert-doc-image",
|
|
192
|
-
type: CommandType.COMMAND,
|
|
193
|
-
handler: (accessor, params) => {
|
|
194
|
-
var _ref, _contentInsertRange$s, _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3;
|
|
195
|
-
if (params == null) return false;
|
|
196
|
-
const commandService = accessor.get(ICommandService);
|
|
197
|
-
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
198
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
199
|
-
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
200
|
-
const documentDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
201
|
-
if (documentDataModel == null) return false;
|
|
202
|
-
const unitId = documentDataModel.getUnitId();
|
|
203
|
-
const explicitTextRange = params.textRange == null ? null : normalizeTextRange(params.textRange);
|
|
204
|
-
const contentInsertRange = explicitTextRange !== null && explicitTextRange !== void 0 ? explicitTextRange : getContentInsertRange(accessor, unitId);
|
|
205
|
-
const targetTextRange = contentInsertRange ? {
|
|
206
|
-
...activeTextRange,
|
|
207
|
-
startOffset: contentInsertRange.startOffset,
|
|
208
|
-
endOffset: contentInsertRange.endOffset,
|
|
209
|
-
collapsed: contentInsertRange.startOffset === contentInsertRange.endOffset,
|
|
210
|
-
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 : ""
|
|
211
|
-
} : activeTextRange;
|
|
212
|
-
if (targetTextRange == null) return false;
|
|
213
|
-
const { drawings } = params;
|
|
214
|
-
const { collapsed, startOffset, segmentId = "" } = targetTextRange;
|
|
215
|
-
const body = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
216
|
-
if (body == null) return false;
|
|
217
|
-
const textX = new TextX();
|
|
218
|
-
const jsonX = JSONX.getInstance();
|
|
219
|
-
const rawActions = [];
|
|
220
|
-
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;
|
|
221
|
-
let removeDrawingLen = 0;
|
|
222
|
-
if (collapsed) {
|
|
223
|
-
if (startOffset > 0) textX.push({
|
|
224
|
-
t: TextXActionType.RETAIN,
|
|
225
|
-
len: startOffset
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
var _documentDataModel$ge4, _documentDataModel$ge5;
|
|
229
|
-
const dos = BuildTextUtils.selection.delete([targetTextRange], body, 0, null, false);
|
|
230
|
-
textX.push(...dos);
|
|
231
|
-
const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [targetTextRange]);
|
|
232
|
-
const drawings = (_documentDataModel$ge4 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge4 !== void 0 ? _documentDataModel$ge4 : {};
|
|
233
|
-
const drawingOrder = (_documentDataModel$ge5 = documentDataModel.getDrawingsOrder()) !== null && _documentDataModel$ge5 !== void 0 ? _documentDataModel$ge5 : [];
|
|
234
|
-
const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
|
|
235
|
-
if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
|
|
236
|
-
else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
|
|
237
|
-
return 0;
|
|
238
|
-
});
|
|
239
|
-
if (sortedRemovedCustomBlockIds.length > 0) for (const blockId of sortedRemovedCustomBlockIds) {
|
|
240
|
-
const drawing = drawings[blockId];
|
|
241
|
-
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
242
|
-
if (drawing == null || drawingIndex < 0) continue;
|
|
243
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing);
|
|
244
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
245
|
-
rawActions.push(removeDrawingAction);
|
|
246
|
-
rawActions.push(removeDrawingOrderAction);
|
|
247
|
-
removeDrawingLen++;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
textX.push({
|
|
251
|
-
t: TextXActionType.INSERT,
|
|
252
|
-
body: {
|
|
253
|
-
dataStream: "\b".repeat(drawings.length),
|
|
254
|
-
customBlocks: drawings.map((drawing, i) => ({
|
|
255
|
-
startIndex: i,
|
|
256
|
-
blockId: drawing.drawingId
|
|
257
|
-
}))
|
|
258
|
-
},
|
|
259
|
-
len: drawings.length
|
|
260
|
-
});
|
|
261
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
262
|
-
const placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
263
|
-
rawActions.push(placeHolderAction);
|
|
264
|
-
for (const drawing of drawings) {
|
|
265
|
-
const { drawingId } = drawing;
|
|
266
|
-
const addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing);
|
|
267
|
-
const addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
268
|
-
rawActions.push(addDrawingAction);
|
|
269
|
-
rawActions.push(addDrawingOrderAction);
|
|
270
|
-
}
|
|
271
|
-
const doMutation = {
|
|
272
|
-
id: RichTextEditingMutation.id,
|
|
273
|
-
params: {
|
|
274
|
-
unitId,
|
|
275
|
-
actions: [],
|
|
276
|
-
textRanges: []
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
280
|
-
return JSONX.compose(acc, cur);
|
|
281
|
-
}, null);
|
|
282
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
283
|
-
return Boolean(result);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
function getContentInsertRange(accessor, unitId) {
|
|
287
|
-
try {
|
|
288
|
-
const range = accessor.get(DocContentInsertService).consumeInsertRange(unitId);
|
|
289
|
-
if (range == null) return null;
|
|
290
|
-
return {
|
|
291
|
-
startOffset: range.startOffset,
|
|
292
|
-
endOffset: range.endOffset,
|
|
293
|
-
collapsed: range.startOffset === range.endOffset,
|
|
294
|
-
segmentId: range.segmentId
|
|
295
|
-
};
|
|
296
|
-
} catch {
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function normalizeTextRange(textRange) {
|
|
301
|
-
var _textRange$endOffset, _textRange$collapsed, _textRange$segmentId;
|
|
302
|
-
const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
|
|
303
|
-
return {
|
|
304
|
-
...textRange,
|
|
305
|
-
endOffset,
|
|
306
|
-
collapsed: (_textRange$collapsed = textRange.collapsed) !== null && _textRange$collapsed !== void 0 ? _textRange$collapsed : textRange.startOffset === endOffset,
|
|
307
|
-
segmentId: (_textRange$segmentId = textRange.segmentId) !== null && _textRange$segmentId !== void 0 ? _textRange$segmentId : ""
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
//#endregion
|
|
312
|
-
//#region src/commands/commands/set-drawing-arrange.command.ts
|
|
313
|
-
/**
|
|
314
|
-
* The command to arrange drawings.
|
|
315
|
-
*/
|
|
316
|
-
const SetDocDrawingArrangeCommand = {
|
|
317
|
-
id: "doc.command.set-drawing-arrange",
|
|
318
|
-
type: CommandType.COMMAND,
|
|
319
|
-
handler: (accessor, params) => {
|
|
320
|
-
const commandService = accessor.get(ICommandService);
|
|
321
|
-
const docDrawingService = accessor.get(IDocDrawingService);
|
|
322
|
-
if (params == null) return false;
|
|
323
|
-
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
324
|
-
const drawingOrderMapParam = {
|
|
325
|
-
unitId,
|
|
326
|
-
subUnitId,
|
|
327
|
-
drawingIds
|
|
328
|
-
};
|
|
329
|
-
let jsonOp;
|
|
330
|
-
if (arrangeType === ArrangeTypeEnum.forward) jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
331
|
-
else if (arrangeType === ArrangeTypeEnum.backward) jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
332
|
-
else if (arrangeType === ArrangeTypeEnum.front) jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
333
|
-
else if (arrangeType === ArrangeTypeEnum.back) jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
334
|
-
if (jsonOp == null) return false;
|
|
335
|
-
const { redo } = jsonOp;
|
|
336
|
-
if (redo == null) return false;
|
|
337
|
-
const rawActions = [];
|
|
338
|
-
let redoCopy = Tools.deepClone(redo);
|
|
339
|
-
redoCopy = redoCopy.slice(3);
|
|
340
|
-
redoCopy.unshift("drawingsOrder");
|
|
341
|
-
rawActions.push(redoCopy);
|
|
342
|
-
const doMutation = {
|
|
343
|
-
id: RichTextEditingMutation.id,
|
|
344
|
-
params: {
|
|
345
|
-
unitId,
|
|
346
|
-
actions: [],
|
|
347
|
-
textRanges: null
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
351
|
-
return JSONX.compose(acc, cur);
|
|
352
|
-
}, null);
|
|
353
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
354
|
-
return Boolean(result);
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
52
|
//#endregion
|
|
359
53
|
//#region src/commands/commands/ungroup-doc-drawing.command.ts
|
|
360
54
|
/**
|
|
@@ -576,25 +270,10 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
|
|
|
576
270
|
}
|
|
577
271
|
_getImagePosition(imageWidth, imageHeight, insertPosition) {
|
|
578
272
|
var _ref;
|
|
579
|
-
|
|
273
|
+
return buildDocTransform(imageWidth, imageHeight, { left: ((_ref = insertPosition !== null && insertPosition !== void 0 ? insertPosition : this._getCurrentImageInsertPosition()) !== null && _ref !== void 0 ? _ref : {
|
|
580
274
|
left: 0,
|
|
581
275
|
top: 0
|
|
582
|
-
};
|
|
583
|
-
return {
|
|
584
|
-
size: {
|
|
585
|
-
width: imageWidth,
|
|
586
|
-
height: imageHeight
|
|
587
|
-
},
|
|
588
|
-
positionH: {
|
|
589
|
-
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
590
|
-
posOffset: position.left
|
|
591
|
-
},
|
|
592
|
-
positionV: {
|
|
593
|
-
relativeFrom: ObjectRelativeFromV.PARAGRAPH,
|
|
594
|
-
posOffset: 0
|
|
595
|
-
},
|
|
596
|
-
angle: 0
|
|
597
|
-
};
|
|
276
|
+
}).left });
|
|
598
277
|
}
|
|
599
278
|
_getCurrentImageInsertPosition() {
|
|
600
279
|
var _this$_docSelectionRe;
|
|
@@ -798,23 +477,6 @@ function createShapeSvgSource(shape, width, height) {
|
|
|
798
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>`;
|
|
799
478
|
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
800
479
|
}
|
|
801
|
-
function createDefaultDocTransform(width, height) {
|
|
802
|
-
return {
|
|
803
|
-
size: {
|
|
804
|
-
width,
|
|
805
|
-
height
|
|
806
|
-
},
|
|
807
|
-
positionH: {
|
|
808
|
-
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
809
|
-
posOffset: 0
|
|
810
|
-
},
|
|
811
|
-
positionV: {
|
|
812
|
-
relativeFrom: ObjectRelativeFromV.PARAGRAPH,
|
|
813
|
-
posOffset: 0
|
|
814
|
-
},
|
|
815
|
-
angle: 0
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
480
|
function createShapeInsertCommand(shape, width, height, id) {
|
|
819
481
|
return {
|
|
820
482
|
id,
|
|
@@ -824,7 +486,7 @@ function createShapeInsertCommand(shape, width, height, id) {
|
|
|
824
486
|
const commandService = accessor.get(ICommandService);
|
|
825
487
|
const unitId = (_univerInstanceServic = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
|
|
826
488
|
if (!unitId) return false;
|
|
827
|
-
const docTransform =
|
|
489
|
+
const docTransform = buildDocTransform(width, height);
|
|
828
490
|
return commandService.executeCommand(InsertDocDrawingCommand.id, {
|
|
829
491
|
unitId,
|
|
830
492
|
drawings: [{
|
|
@@ -854,662 +516,136 @@ const InsertDocRectangleShapeCommand = createShapeInsertCommand("rectangle", 144
|
|
|
854
516
|
const InsertDocEllipseShapeCommand = createShapeInsertCommand("ellipse", 112, 112, "doc.command.insert-float-shape.ellipse");
|
|
855
517
|
|
|
856
518
|
//#endregion
|
|
857
|
-
//#region src/commands/commands/
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
519
|
+
//#region src/commands/commands/move-drawings.command.ts
|
|
520
|
+
const MoveDocDrawingsCommand = {
|
|
521
|
+
id: "doc.command.move-drawing",
|
|
522
|
+
type: CommandType.COMMAND,
|
|
523
|
+
handler: (accessor, params) => {
|
|
524
|
+
const commandService = accessor.get(ICommandService);
|
|
525
|
+
const docDrawingService = accessor.get(IDocDrawingService);
|
|
526
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
527
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
528
|
+
const { direction } = params;
|
|
529
|
+
const drawings = docDrawingService.getFocusDrawings();
|
|
530
|
+
if (drawings.length === 0) return false;
|
|
531
|
+
const unitId = drawings[0].unitId;
|
|
532
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
533
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
534
|
+
if (scene == null) return false;
|
|
535
|
+
const transformer = scene.getTransformerByCreate();
|
|
536
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
537
|
+
const newDrawings = drawings.map((drawing) => {
|
|
538
|
+
var _documentDataModel$ge;
|
|
539
|
+
const { drawingId } = drawing;
|
|
540
|
+
const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingId];
|
|
541
|
+
if (drawingData == null || drawingData.layoutType === PositionedObjectLayoutType.INLINE) return null;
|
|
542
|
+
const { positionH, positionV } = drawingData.docTransform;
|
|
543
|
+
const newPositionH = { ...positionH };
|
|
544
|
+
const newPositionV = { ...positionV };
|
|
545
|
+
if (direction === Direction.UP) {
|
|
546
|
+
var _newPositionV$posOffs;
|
|
547
|
+
newPositionV.posOffset = ((_newPositionV$posOffs = newPositionV.posOffset) !== null && _newPositionV$posOffs !== void 0 ? _newPositionV$posOffs : 0) - 2;
|
|
548
|
+
} else if (direction === Direction.DOWN) {
|
|
549
|
+
var _newPositionV$posOffs2;
|
|
550
|
+
newPositionV.posOffset = ((_newPositionV$posOffs2 = newPositionV.posOffset) !== null && _newPositionV$posOffs2 !== void 0 ? _newPositionV$posOffs2 : 0) + 2;
|
|
551
|
+
} else if (direction === Direction.LEFT) {
|
|
552
|
+
var _newPositionH$posOffs;
|
|
553
|
+
newPositionH.posOffset = ((_newPositionH$posOffs = newPositionH.posOffset) !== null && _newPositionH$posOffs !== void 0 ? _newPositionH$posOffs : 0) - 2;
|
|
554
|
+
} else if (direction === Direction.RIGHT) {
|
|
555
|
+
var _newPositionH$posOffs2;
|
|
556
|
+
newPositionH.posOffset = ((_newPositionH$posOffs2 = newPositionH.posOffset) !== null && _newPositionH$posOffs2 !== void 0 ? _newPositionH$posOffs2 : 0) + 2;
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
drawingId,
|
|
560
|
+
key: direction === Direction.UP || direction === Direction.DOWN ? "positionV" : "positionH",
|
|
561
|
+
value: direction === Direction.UP || direction === Direction.DOWN ? newPositionV : newPositionH
|
|
562
|
+
};
|
|
563
|
+
}).filter((drawing) => drawing != null);
|
|
564
|
+
if (newDrawings.length === 0) return false;
|
|
565
|
+
const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
|
|
566
|
+
unitId,
|
|
567
|
+
subUnitId: unitId,
|
|
568
|
+
drawings: newDrawings
|
|
569
|
+
});
|
|
570
|
+
transformer.refreshControls();
|
|
571
|
+
return Boolean(result);
|
|
572
|
+
}
|
|
864
573
|
};
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
574
|
+
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/commands/operations/clear-drawing-transformer.operation.ts
|
|
577
|
+
const ClearDocDrawingTransformerOperation = {
|
|
578
|
+
id: "doc.operation.clear-drawing-transformer",
|
|
579
|
+
type: CommandType.MUTATION,
|
|
580
|
+
handler: (accessor, params) => {
|
|
581
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
582
|
+
params.forEach((unitId) => {
|
|
583
|
+
var _renderManagerService;
|
|
584
|
+
(_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
|
|
585
|
+
});
|
|
586
|
+
return true;
|
|
875
587
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
const textX = new TextX();
|
|
881
|
-
const jsonX = JSONX.getInstance();
|
|
882
|
-
const rawActions = [];
|
|
883
|
-
const oldBody = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
884
|
-
const body = (_documentDataModel$ge2 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.getBody();
|
|
885
|
-
if (oldBody == null || body == null) return;
|
|
886
|
-
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;
|
|
887
|
-
if (oldOffset == null) return;
|
|
888
|
-
offset = Math.min(body.dataStream.length - 2, offset);
|
|
889
|
-
if (segmentId === oldSegmentId) {
|
|
890
|
-
if (offset < oldOffset) {
|
|
891
|
-
if (offset > 0) textX.push({
|
|
892
|
-
t: TextXActionType.RETAIN,
|
|
893
|
-
len: offset
|
|
894
|
-
});
|
|
895
|
-
textX.push({
|
|
896
|
-
t: TextXActionType.INSERT,
|
|
897
|
-
body: {
|
|
898
|
-
dataStream: "\b",
|
|
899
|
-
customBlocks: [{
|
|
900
|
-
startIndex: 0,
|
|
901
|
-
blockId: drawingId
|
|
902
|
-
}]
|
|
903
|
-
},
|
|
904
|
-
len: 1
|
|
905
|
-
});
|
|
906
|
-
textX.push({
|
|
907
|
-
t: TextXActionType.RETAIN,
|
|
908
|
-
len: oldOffset - offset
|
|
909
|
-
});
|
|
910
|
-
textX.push({
|
|
911
|
-
t: TextXActionType.DELETE,
|
|
912
|
-
len: 1
|
|
913
|
-
});
|
|
914
|
-
} else {
|
|
915
|
-
if (oldOffset > 0) textX.push({
|
|
916
|
-
t: TextXActionType.RETAIN,
|
|
917
|
-
len: oldOffset
|
|
918
|
-
});
|
|
919
|
-
textX.push({
|
|
920
|
-
t: TextXActionType.DELETE,
|
|
921
|
-
len: 1
|
|
922
|
-
});
|
|
923
|
-
if (offset - oldOffset - 1 > 0) textX.push({
|
|
924
|
-
t: TextXActionType.RETAIN,
|
|
925
|
-
len: offset - oldOffset - 1
|
|
926
|
-
});
|
|
927
|
-
textX.push({
|
|
928
|
-
t: TextXActionType.INSERT,
|
|
929
|
-
body: {
|
|
930
|
-
dataStream: "\b",
|
|
931
|
-
customBlocks: [{
|
|
932
|
-
startIndex: 0,
|
|
933
|
-
blockId: drawingId
|
|
934
|
-
}]
|
|
935
|
-
},
|
|
936
|
-
len: 1
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
if (offset !== oldOffset) {
|
|
940
|
-
const path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
941
|
-
const action = jsonX.editOp(textX.serialize(), path);
|
|
942
|
-
rawActions.push(action);
|
|
943
|
-
}
|
|
944
|
-
} else {
|
|
945
|
-
if (oldOffset > 0) textX.push({
|
|
946
|
-
t: TextXActionType.RETAIN,
|
|
947
|
-
len: oldOffset
|
|
948
|
-
});
|
|
949
|
-
textX.push({
|
|
950
|
-
t: TextXActionType.DELETE,
|
|
951
|
-
len: 1
|
|
952
|
-
});
|
|
953
|
-
let path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
954
|
-
let action = jsonX.editOp(textX.serialize(), path);
|
|
955
|
-
rawActions.push(action);
|
|
956
|
-
textX.empty();
|
|
957
|
-
if (offset > 0) textX.push({
|
|
958
|
-
t: TextXActionType.RETAIN,
|
|
959
|
-
len: offset
|
|
960
|
-
});
|
|
961
|
-
textX.push({
|
|
962
|
-
t: TextXActionType.INSERT,
|
|
963
|
-
body: {
|
|
964
|
-
dataStream: "\b",
|
|
965
|
-
customBlocks: [{
|
|
966
|
-
startIndex: 0,
|
|
967
|
-
blockId: drawingId
|
|
968
|
-
}]
|
|
969
|
-
},
|
|
970
|
-
len: 1
|
|
971
|
-
});
|
|
972
|
-
path = getRichTextEditPath(documentDataModel, segmentId);
|
|
973
|
-
action = jsonX.editOp(textX.serialize(), path);
|
|
974
|
-
rawActions.push(action);
|
|
975
|
-
docSelectionRenderManager.setSegment(segmentId);
|
|
976
|
-
docSelectionRenderManager.setSegmentPage(segmentPage);
|
|
977
|
-
}
|
|
978
|
-
return rawActions;
|
|
979
|
-
}
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/views/doc-image-panel/component-name.ts
|
|
980
592
|
/**
|
|
981
|
-
*
|
|
593
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
594
|
+
*
|
|
595
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
596
|
+
* you may not use this file except in compliance with the License.
|
|
597
|
+
* You may obtain a copy of the License at
|
|
598
|
+
*
|
|
599
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
600
|
+
*
|
|
601
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
602
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
603
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
604
|
+
* See the License for the specific language governing permissions and
|
|
605
|
+
* limitations under the License.
|
|
982
606
|
*/
|
|
983
|
-
const
|
|
984
|
-
|
|
607
|
+
const COMPONENT_DOC_DRAWING_PANEL = "COMPONENT_DOC_DRAWING_PANEL";
|
|
608
|
+
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/commands/operations/open-drawing-panel.operation.ts
|
|
611
|
+
const SidebarDocDrawingOperation = {
|
|
612
|
+
id: "sidebar.operation.doc-image",
|
|
985
613
|
type: CommandType.COMMAND,
|
|
986
|
-
handler: (accessor, params) => {
|
|
987
|
-
|
|
988
|
-
const
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
const { drawingId } = drawing;
|
|
1005
|
-
const oldLayoutType = oldDrawings[drawingId].layoutType;
|
|
1006
|
-
const newLayoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
|
|
1007
|
-
if (oldLayoutType !== newLayoutType) {
|
|
1008
|
-
const updateLayoutTypeAction = jsonX.replaceOp([
|
|
1009
|
-
"drawings",
|
|
1010
|
-
drawingId,
|
|
1011
|
-
"layoutType"
|
|
1012
|
-
], oldLayoutType, newLayoutType);
|
|
1013
|
-
rawActions.push(updateLayoutTypeAction);
|
|
1014
|
-
}
|
|
1015
|
-
if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
|
|
1016
|
-
const oldBehindDoc = oldDrawings[drawingId].behindDoc;
|
|
1017
|
-
const newBehindDoc = wrappingStyle === "behindText" ? BooleanNumber.TRUE : BooleanNumber.FALSE;
|
|
1018
|
-
if (oldBehindDoc !== newBehindDoc) {
|
|
1019
|
-
const updateBehindDocAction = jsonX.replaceOp([
|
|
1020
|
-
"drawings",
|
|
1021
|
-
drawingId,
|
|
1022
|
-
"behindDoc"
|
|
1023
|
-
], oldBehindDoc, newBehindDoc);
|
|
1024
|
-
rawActions.push(updateBehindDocAction);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
if (wrappingStyle === "inline") continue;
|
|
1028
|
-
let drawingAnchor = null;
|
|
1029
|
-
for (const page of pages) {
|
|
1030
|
-
const { headerId, footerId, marginTop, marginLeft, marginBottom, pageWidth, pageHeight } = page;
|
|
1031
|
-
switch (editArea) {
|
|
1032
|
-
case DocumentEditArea.HEADER: {
|
|
1033
|
-
var _skeHeaders$get;
|
|
1034
|
-
const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
|
|
1035
|
-
if (headerSke != null) drawingAnchor = findDrawingAnchorInPage(headerSke, drawingId, headerSke.marginTop, marginLeft);
|
|
1036
|
-
break;
|
|
1037
|
-
}
|
|
1038
|
-
case DocumentEditArea.FOOTER: {
|
|
1039
|
-
var _skeFooters$get;
|
|
1040
|
-
const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
|
|
1041
|
-
if (footerSke != null) drawingAnchor = findDrawingAnchorInPage(footerSke, drawingId, pageHeight - marginBottom + footerSke.marginTop, marginLeft);
|
|
1042
|
-
break;
|
|
1043
|
-
}
|
|
1044
|
-
case DocumentEditArea.BODY:
|
|
1045
|
-
drawingAnchor = findDrawingAnchorInPage(page, drawingId, marginTop, marginLeft);
|
|
1046
|
-
break;
|
|
1047
|
-
}
|
|
1048
|
-
if (drawingAnchor != null) break;
|
|
1049
|
-
}
|
|
1050
|
-
if (drawingAnchor != null) {
|
|
1051
|
-
const { skeDrawing, pageMarginTop, pageMarginLeft } = drawingAnchor;
|
|
1052
|
-
const { aTop, aLeft } = skeDrawing;
|
|
1053
|
-
const oldPositionH = oldDrawings[drawingId].docTransform.positionH;
|
|
1054
|
-
let posOffsetH = aLeft;
|
|
1055
|
-
if (oldPositionH.relativeFrom === ObjectRelativeFromH.MARGIN) posOffsetH -= pageMarginLeft;
|
|
1056
|
-
else if (oldPositionH.relativeFrom === ObjectRelativeFromH.COLUMN) posOffsetH -= skeDrawing.columnLeft;
|
|
1057
|
-
const newPositionH = {
|
|
1058
|
-
relativeFrom: oldPositionH.relativeFrom,
|
|
1059
|
-
posOffset: posOffsetH
|
|
1060
|
-
};
|
|
1061
|
-
if (oldPositionH.posOffset !== newPositionH.posOffset) {
|
|
1062
|
-
const action = jsonX.replaceOp([
|
|
1063
|
-
"drawings",
|
|
1064
|
-
drawingId,
|
|
1065
|
-
"docTransform",
|
|
1066
|
-
"positionH"
|
|
1067
|
-
], oldPositionH, newPositionH);
|
|
1068
|
-
rawActions.push(action);
|
|
1069
|
-
}
|
|
1070
|
-
const oldPositionV = oldDrawings[drawingId].docTransform.positionV;
|
|
1071
|
-
let posOffsetV = aTop;
|
|
1072
|
-
if (oldPositionV.relativeFrom === ObjectRelativeFromV.PAGE) posOffsetV += pageMarginTop;
|
|
1073
|
-
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.LINE) posOffsetV -= skeDrawing.lineTop;
|
|
1074
|
-
else if (oldPositionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH) posOffsetV -= skeDrawing.blockAnchorTop;
|
|
1075
|
-
const newPositionV = {
|
|
1076
|
-
relativeFrom: oldPositionV.relativeFrom,
|
|
1077
|
-
posOffset: posOffsetV
|
|
1078
|
-
};
|
|
1079
|
-
if (oldPositionV.posOffset !== newPositionV.posOffset) {
|
|
1080
|
-
const action = jsonX.replaceOp([
|
|
1081
|
-
"drawings",
|
|
1082
|
-
drawingId,
|
|
1083
|
-
"docTransform",
|
|
1084
|
-
"positionV"
|
|
1085
|
-
], oldPositionV, newPositionV);
|
|
1086
|
-
rawActions.push(action);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
614
|
+
handler: async (accessor, params) => {
|
|
615
|
+
const sidebarService = accessor.get(ISidebarService);
|
|
616
|
+
const localeService = accessor.get(LocaleService);
|
|
617
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
618
|
+
switch (params.value) {
|
|
619
|
+
case "open":
|
|
620
|
+
sidebarService.open({
|
|
621
|
+
header: { title: localeService.t("docs-drawing-ui.panel.title") },
|
|
622
|
+
children: { label: COMPONENT_DOC_DRAWING_PANEL },
|
|
623
|
+
onClose: () => {
|
|
624
|
+
drawingManagerService.focusDrawing(null);
|
|
625
|
+
},
|
|
626
|
+
width: 360
|
|
627
|
+
});
|
|
628
|
+
break;
|
|
629
|
+
default:
|
|
630
|
+
sidebarService.close();
|
|
631
|
+
break;
|
|
1089
632
|
}
|
|
1090
|
-
|
|
1091
|
-
id: RichTextEditingMutation.id,
|
|
1092
|
-
params: {
|
|
1093
|
-
unitId,
|
|
1094
|
-
actions: [],
|
|
1095
|
-
textRanges: null
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1099
|
-
return JSONX.compose(acc, cur);
|
|
1100
|
-
}, null);
|
|
1101
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1102
|
-
transformer.refreshControls();
|
|
1103
|
-
return Boolean(result);
|
|
633
|
+
return true;
|
|
1104
634
|
}
|
|
1105
635
|
};
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
const
|
|
1110
|
-
id: "doc.
|
|
1111
|
-
type: CommandType.
|
|
636
|
+
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region src/commands/operations/edit-doc-drawing.operation.ts
|
|
639
|
+
const EditDocDrawingOperation = {
|
|
640
|
+
id: "doc.operation.edit-doc-image",
|
|
641
|
+
type: CommandType.OPERATION,
|
|
1112
642
|
handler: (accessor, params) => {
|
|
1113
|
-
|
|
643
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
1114
644
|
const commandService = accessor.get(ICommandService);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
const jsonX = JSONX.getInstance();
|
|
1120
|
-
const rawActions = [];
|
|
1121
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1122
|
-
for (const drawing of drawings) {
|
|
1123
|
-
const { drawingId } = drawing;
|
|
1124
|
-
for (const [key, value] of Object.entries(dist)) {
|
|
1125
|
-
const oldValue = oldDrawings[drawingId][key];
|
|
1126
|
-
if (oldValue !== value) {
|
|
1127
|
-
const action = jsonX.replaceOp([
|
|
1128
|
-
"drawings",
|
|
1129
|
-
drawingId,
|
|
1130
|
-
key
|
|
1131
|
-
], oldValue, value);
|
|
1132
|
-
rawActions.push(action);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
const doMutation = {
|
|
1137
|
-
id: RichTextEditingMutation.id,
|
|
1138
|
-
params: {
|
|
1139
|
-
unitId,
|
|
1140
|
-
actions: [],
|
|
1141
|
-
textRanges: null
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1145
|
-
return JSONX.compose(acc, cur);
|
|
1146
|
-
}, null);
|
|
1147
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1148
|
-
return Boolean(result);
|
|
1149
|
-
}
|
|
1150
|
-
};
|
|
1151
|
-
/**
|
|
1152
|
-
* The command to update drawing wrap text.
|
|
1153
|
-
*/
|
|
1154
|
-
const UpdateDocDrawingWrapTextCommand = {
|
|
1155
|
-
id: "doc.command.update-doc-drawing-wrap-text",
|
|
1156
|
-
type: CommandType.COMMAND,
|
|
1157
|
-
handler: (accessor, params) => {
|
|
1158
|
-
if (params == null) return false;
|
|
1159
|
-
const commandService = accessor.get(ICommandService);
|
|
1160
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1161
|
-
const { drawings, wrapText, unitId } = params;
|
|
1162
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1163
|
-
if (documentDataModel == null) return false;
|
|
1164
|
-
const jsonX = JSONX.getInstance();
|
|
1165
|
-
const rawActions = [];
|
|
1166
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1167
|
-
for (const drawing of drawings) {
|
|
1168
|
-
const { drawingId } = drawing;
|
|
1169
|
-
const oldWrapText = oldDrawings[drawingId].wrapText;
|
|
1170
|
-
if (oldWrapText !== wrapText) {
|
|
1171
|
-
const action = jsonX.replaceOp([
|
|
1172
|
-
"drawings",
|
|
1173
|
-
drawingId,
|
|
1174
|
-
"wrapText"
|
|
1175
|
-
], oldWrapText, wrapText);
|
|
1176
|
-
rawActions.push(action);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
const doMutation = {
|
|
1180
|
-
id: RichTextEditingMutation.id,
|
|
1181
|
-
params: {
|
|
1182
|
-
unitId,
|
|
1183
|
-
actions: [],
|
|
1184
|
-
textRanges: null
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1188
|
-
return JSONX.compose(acc, cur);
|
|
1189
|
-
}, null);
|
|
1190
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1191
|
-
return Boolean(result);
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
/**
|
|
1195
|
-
* The command to update drawing position.
|
|
1196
|
-
*/
|
|
1197
|
-
const UpdateDrawingDocTransformCommand = {
|
|
1198
|
-
id: "doc.command.update-drawing-doc-transform",
|
|
1199
|
-
type: CommandType.COMMAND,
|
|
1200
|
-
handler: (accessor, params) => {
|
|
1201
|
-
if (params == null) return false;
|
|
1202
|
-
const commandService = accessor.get(ICommandService);
|
|
1203
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1204
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1205
|
-
const { drawings, unitId } = params;
|
|
1206
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1207
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1208
|
-
if (scene == null) return false;
|
|
1209
|
-
const transformer = scene.getTransformerByCreate();
|
|
1210
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1211
|
-
if (documentDataModel == null) return false;
|
|
1212
|
-
const jsonX = JSONX.getInstance();
|
|
1213
|
-
const rawActions = [];
|
|
1214
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1215
|
-
for (const drawing of drawings) {
|
|
1216
|
-
const { drawingId, key, value } = drawing;
|
|
1217
|
-
const oldValue = oldDrawings[drawingId].docTransform[key];
|
|
1218
|
-
if (!Tools.diffValue(oldValue, value)) {
|
|
1219
|
-
const action = jsonX.replaceOp([
|
|
1220
|
-
"drawings",
|
|
1221
|
-
drawingId,
|
|
1222
|
-
"docTransform",
|
|
1223
|
-
key
|
|
1224
|
-
], oldValue, value);
|
|
1225
|
-
rawActions.push(action);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
const doMutation = {
|
|
1229
|
-
id: RichTextEditingMutation.id,
|
|
1230
|
-
params: {
|
|
1231
|
-
unitId,
|
|
1232
|
-
actions: [],
|
|
1233
|
-
textRanges: null,
|
|
1234
|
-
debounce: true
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1238
|
-
return JSONX.compose(acc, cur);
|
|
1239
|
-
}, null);
|
|
1240
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1241
|
-
if (accessor.has(DocRefreshDrawingsService)) {
|
|
1242
|
-
var _renderObject$with$ge;
|
|
1243
|
-
const skeleton = (_renderObject$with$ge = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton()) !== null && _renderObject$with$ge !== void 0 ? _renderObject$with$ge : null;
|
|
1244
|
-
accessor.get(DocRefreshDrawingsService).refreshDrawings(skeleton);
|
|
1245
|
-
}
|
|
1246
|
-
transformer.refreshControls();
|
|
1247
|
-
return Boolean(result);
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
/**
|
|
1251
|
-
* The command to move inline drawing.
|
|
1252
|
-
*/
|
|
1253
|
-
const IMoveInlineDrawingCommand = {
|
|
1254
|
-
id: "doc.command.move-inline-drawing",
|
|
1255
|
-
type: CommandType.COMMAND,
|
|
1256
|
-
handler: (accessor, params) => {
|
|
1257
|
-
var _renderManagerService, _docSelectionRenderSe;
|
|
1258
|
-
if (params == null) return false;
|
|
1259
|
-
const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
|
|
1260
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1261
|
-
const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSelectionRenderService);
|
|
1262
|
-
const docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService);
|
|
1263
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1264
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1265
|
-
const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
|
|
1266
|
-
if (scene == null || docSelectionRenderService == null) return false;
|
|
1267
|
-
const transformer = scene.getTransformerByCreate();
|
|
1268
|
-
const commandService = accessor.get(ICommandService);
|
|
1269
|
-
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1270
|
-
if (documentDataModel == null) return false;
|
|
1271
|
-
if (needRefreshDrawings) {
|
|
1272
|
-
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1273
|
-
transformer.refreshControls();
|
|
1274
|
-
return true;
|
|
1275
|
-
}
|
|
1276
|
-
const rawActions = [];
|
|
1277
|
-
const { drawingId } = drawing;
|
|
1278
|
-
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1279
|
-
if (actions == null || actions.length === 0) {
|
|
1280
|
-
docRefreshDrawingsService.refreshDrawings(skeleton);
|
|
1281
|
-
transformer.refreshControls();
|
|
1282
|
-
return false;
|
|
1283
|
-
}
|
|
1284
|
-
rawActions.push(...actions);
|
|
1285
|
-
const doMutation = {
|
|
1286
|
-
id: RichTextEditingMutation.id,
|
|
1287
|
-
params: {
|
|
1288
|
-
unitId,
|
|
1289
|
-
actions: [],
|
|
1290
|
-
textRanges: null
|
|
1291
|
-
}
|
|
1292
|
-
};
|
|
1293
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1294
|
-
return JSONX.compose(acc, cur);
|
|
1295
|
-
}, null);
|
|
1296
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1297
|
-
transformer.refreshControls();
|
|
1298
|
-
return Boolean(result);
|
|
1299
|
-
}
|
|
1300
|
-
};
|
|
1301
|
-
/**
|
|
1302
|
-
* The command to transform non-inline drawing.
|
|
1303
|
-
*/
|
|
1304
|
-
const ITransformNonInlineDrawingCommand = {
|
|
1305
|
-
id: "doc.command.transform-non-inline-drawing",
|
|
1306
|
-
type: CommandType.COMMAND,
|
|
1307
|
-
handler: (accessor, params) => {
|
|
1308
|
-
var _renderManagerService2, _docSelectionRenderSe2;
|
|
1309
|
-
if (params == null) return false;
|
|
1310
|
-
const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params;
|
|
1311
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1312
|
-
const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSelectionRenderService);
|
|
1313
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
1314
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1315
|
-
if (scene == null || docSelectionRenderService == null) return false;
|
|
1316
|
-
const transformer = scene.getTransformerByCreate();
|
|
1317
|
-
const commandService = accessor.get(ICommandService);
|
|
1318
|
-
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1319
|
-
if (documentDataModel == null) return false;
|
|
1320
|
-
const rawActions = [];
|
|
1321
|
-
const { drawingId } = drawing;
|
|
1322
|
-
const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe2 = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe2 !== void 0 ? _docSelectionRenderSe2 : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
|
|
1323
|
-
if (actions == null) return false;
|
|
1324
|
-
if (actions.length > 0) rawActions.push(...actions);
|
|
1325
|
-
const jsonX = JSONX.getInstance();
|
|
1326
|
-
const { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
|
|
1327
|
-
const { positionH: oldPositionH, positionV: oldPositionV, size: oldSize, angle: oldAngle } = oldDrawings[drawingId].docTransform;
|
|
1328
|
-
if (!Tools.diffValue(oldPositionH, docTransform.positionH)) {
|
|
1329
|
-
const updateAction = jsonX.replaceOp([
|
|
1330
|
-
"drawings",
|
|
1331
|
-
drawingId,
|
|
1332
|
-
"docTransform",
|
|
1333
|
-
"positionH"
|
|
1334
|
-
], oldPositionH, docTransform.positionH);
|
|
1335
|
-
rawActions.push(updateAction);
|
|
1336
|
-
}
|
|
1337
|
-
if (!Tools.diffValue(oldPositionV, docTransform.positionV)) {
|
|
1338
|
-
const updateAction = jsonX.replaceOp([
|
|
1339
|
-
"drawings",
|
|
1340
|
-
drawingId,
|
|
1341
|
-
"docTransform",
|
|
1342
|
-
"positionV"
|
|
1343
|
-
], oldPositionV, docTransform.positionV);
|
|
1344
|
-
rawActions.push(updateAction);
|
|
1345
|
-
}
|
|
1346
|
-
if (!Tools.diffValue(oldSize, docTransform.size)) {
|
|
1347
|
-
const updateAction = jsonX.replaceOp([
|
|
1348
|
-
"drawings",
|
|
1349
|
-
drawingId,
|
|
1350
|
-
"docTransform",
|
|
1351
|
-
"size"
|
|
1352
|
-
], oldSize, docTransform.size);
|
|
1353
|
-
rawActions.push(updateAction);
|
|
1354
|
-
}
|
|
1355
|
-
if (!Tools.diffValue(oldAngle, docTransform.angle)) {
|
|
1356
|
-
const updateAction = jsonX.replaceOp([
|
|
1357
|
-
"drawings",
|
|
1358
|
-
drawingId,
|
|
1359
|
-
"docTransform",
|
|
1360
|
-
"angle"
|
|
1361
|
-
], oldAngle, docTransform.angle);
|
|
1362
|
-
rawActions.push(updateAction);
|
|
1363
|
-
}
|
|
1364
|
-
const doMutation = {
|
|
1365
|
-
id: RichTextEditingMutation.id,
|
|
1366
|
-
params: {
|
|
1367
|
-
unitId,
|
|
1368
|
-
actions: [],
|
|
1369
|
-
textRanges: null,
|
|
1370
|
-
debounce: true
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
1374
|
-
return JSONX.compose(acc, cur);
|
|
1375
|
-
}, null);
|
|
1376
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1377
|
-
transformer.refreshControls();
|
|
1378
|
-
return Boolean(result);
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
//#endregion
|
|
1383
|
-
//#region src/commands/commands/move-drawings.command.ts
|
|
1384
|
-
const MoveDocDrawingsCommand = {
|
|
1385
|
-
id: "doc.command.move-drawing",
|
|
1386
|
-
type: CommandType.COMMAND,
|
|
1387
|
-
handler: (accessor, params) => {
|
|
1388
|
-
const commandService = accessor.get(ICommandService);
|
|
1389
|
-
const docDrawingService = accessor.get(IDocDrawingService);
|
|
1390
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1391
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1392
|
-
const { direction } = params;
|
|
1393
|
-
const drawings = docDrawingService.getFocusDrawings();
|
|
1394
|
-
if (drawings.length === 0) return false;
|
|
1395
|
-
const unitId = drawings[0].unitId;
|
|
1396
|
-
const renderObject = renderManagerService.getRenderById(unitId);
|
|
1397
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1398
|
-
if (scene == null) return false;
|
|
1399
|
-
const transformer = scene.getTransformerByCreate();
|
|
1400
|
-
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1401
|
-
const newDrawings = drawings.map((drawing) => {
|
|
1402
|
-
var _documentDataModel$ge;
|
|
1403
|
-
const { drawingId } = drawing;
|
|
1404
|
-
const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingId];
|
|
1405
|
-
if (drawingData == null || drawingData.layoutType === PositionedObjectLayoutType.INLINE) return null;
|
|
1406
|
-
const { positionH, positionV } = drawingData.docTransform;
|
|
1407
|
-
const newPositionH = { ...positionH };
|
|
1408
|
-
const newPositionV = { ...positionV };
|
|
1409
|
-
if (direction === Direction.UP) {
|
|
1410
|
-
var _newPositionV$posOffs;
|
|
1411
|
-
newPositionV.posOffset = ((_newPositionV$posOffs = newPositionV.posOffset) !== null && _newPositionV$posOffs !== void 0 ? _newPositionV$posOffs : 0) - 2;
|
|
1412
|
-
} else if (direction === Direction.DOWN) {
|
|
1413
|
-
var _newPositionV$posOffs2;
|
|
1414
|
-
newPositionV.posOffset = ((_newPositionV$posOffs2 = newPositionV.posOffset) !== null && _newPositionV$posOffs2 !== void 0 ? _newPositionV$posOffs2 : 0) + 2;
|
|
1415
|
-
} else if (direction === Direction.LEFT) {
|
|
1416
|
-
var _newPositionH$posOffs;
|
|
1417
|
-
newPositionH.posOffset = ((_newPositionH$posOffs = newPositionH.posOffset) !== null && _newPositionH$posOffs !== void 0 ? _newPositionH$posOffs : 0) - 2;
|
|
1418
|
-
} else if (direction === Direction.RIGHT) {
|
|
1419
|
-
var _newPositionH$posOffs2;
|
|
1420
|
-
newPositionH.posOffset = ((_newPositionH$posOffs2 = newPositionH.posOffset) !== null && _newPositionH$posOffs2 !== void 0 ? _newPositionH$posOffs2 : 0) + 2;
|
|
1421
|
-
}
|
|
1422
|
-
return {
|
|
1423
|
-
drawingId,
|
|
1424
|
-
key: direction === Direction.UP || direction === Direction.DOWN ? "positionV" : "positionH",
|
|
1425
|
-
value: direction === Direction.UP || direction === Direction.DOWN ? newPositionV : newPositionH
|
|
1426
|
-
};
|
|
1427
|
-
}).filter((drawing) => drawing != null);
|
|
1428
|
-
if (newDrawings.length === 0) return false;
|
|
1429
|
-
const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
|
|
1430
|
-
unitId,
|
|
1431
|
-
subUnitId: unitId,
|
|
1432
|
-
drawings: newDrawings
|
|
1433
|
-
});
|
|
1434
|
-
transformer.refreshControls();
|
|
1435
|
-
return Boolean(result);
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
//#endregion
|
|
1440
|
-
//#region src/commands/operations/clear-drawing-transformer.operation.ts
|
|
1441
|
-
const ClearDocDrawingTransformerOperation = {
|
|
1442
|
-
id: "doc.operation.clear-drawing-transformer",
|
|
1443
|
-
type: CommandType.MUTATION,
|
|
1444
|
-
handler: (accessor, params) => {
|
|
1445
|
-
const renderManagerService = accessor.get(IRenderManagerService);
|
|
1446
|
-
params.forEach((unitId) => {
|
|
1447
|
-
var _renderManagerService;
|
|
1448
|
-
(_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
|
|
1449
|
-
});
|
|
1450
|
-
return true;
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
|
|
1454
|
-
//#endregion
|
|
1455
|
-
//#region src/views/doc-image-panel/component-name.ts
|
|
1456
|
-
/**
|
|
1457
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1458
|
-
*
|
|
1459
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1460
|
-
* you may not use this file except in compliance with the License.
|
|
1461
|
-
* You may obtain a copy of the License at
|
|
1462
|
-
*
|
|
1463
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1464
|
-
*
|
|
1465
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1466
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1467
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1468
|
-
* See the License for the specific language governing permissions and
|
|
1469
|
-
* limitations under the License.
|
|
1470
|
-
*/
|
|
1471
|
-
const COMPONENT_DOC_DRAWING_PANEL = "COMPONENT_DOC_DRAWING_PANEL";
|
|
1472
|
-
|
|
1473
|
-
//#endregion
|
|
1474
|
-
//#region src/commands/operations/open-drawing-panel.operation.ts
|
|
1475
|
-
const SidebarDocDrawingOperation = {
|
|
1476
|
-
id: "sidebar.operation.doc-image",
|
|
1477
|
-
type: CommandType.COMMAND,
|
|
1478
|
-
handler: async (accessor, params) => {
|
|
1479
|
-
const sidebarService = accessor.get(ISidebarService);
|
|
1480
|
-
const localeService = accessor.get(LocaleService);
|
|
1481
|
-
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
1482
|
-
switch (params.value) {
|
|
1483
|
-
case "open":
|
|
1484
|
-
sidebarService.open({
|
|
1485
|
-
header: { title: localeService.t("docs-drawing-ui.panel.title") },
|
|
1486
|
-
children: { label: COMPONENT_DOC_DRAWING_PANEL },
|
|
1487
|
-
onClose: () => {
|
|
1488
|
-
drawingManagerService.focusDrawing(null);
|
|
1489
|
-
},
|
|
1490
|
-
width: 360
|
|
1491
|
-
});
|
|
1492
|
-
break;
|
|
1493
|
-
default:
|
|
1494
|
-
sidebarService.close();
|
|
1495
|
-
break;
|
|
1496
|
-
}
|
|
1497
|
-
return true;
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
|
|
1501
|
-
//#endregion
|
|
1502
|
-
//#region src/commands/operations/edit-doc-drawing.operation.ts
|
|
1503
|
-
const EditDocDrawingOperation = {
|
|
1504
|
-
id: "doc.operation.edit-doc-image",
|
|
1505
|
-
type: CommandType.OPERATION,
|
|
1506
|
-
handler: (accessor, params) => {
|
|
1507
|
-
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
1508
|
-
const commandService = accessor.get(ICommandService);
|
|
1509
|
-
if (params == null) return false;
|
|
1510
|
-
drawingManagerService.focusDrawing([params]);
|
|
1511
|
-
commandService.executeCommand(SidebarDocDrawingOperation.id, { value: "open" });
|
|
1512
|
-
return true;
|
|
645
|
+
if (params == null) return false;
|
|
646
|
+
drawingManagerService.focusDrawing([params]);
|
|
647
|
+
commandService.executeCommand(SidebarDocDrawingOperation.id, { value: "open" });
|
|
648
|
+
return true;
|
|
1513
649
|
}
|
|
1514
650
|
};
|
|
1515
651
|
|
|
@@ -2055,318 +1191,644 @@ const menuSchema = {
|
|
|
2055
1191
|
}
|
|
2056
1192
|
} }
|
|
2057
1193
|
}
|
|
2058
|
-
};
|
|
2059
|
-
|
|
2060
|
-
//#endregion
|
|
2061
|
-
//#region package.json
|
|
2062
|
-
var name = "@univerjs/docs-drawing-ui";
|
|
2063
|
-
var version = "1.0.0-alpha.
|
|
2064
|
-
|
|
2065
|
-
//#endregion
|
|
2066
|
-
//#region src/config/config.ts
|
|
2067
|
-
/**
|
|
2068
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2069
|
-
*
|
|
2070
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2071
|
-
* you may not use this file except in compliance with the License.
|
|
2072
|
-
* You may obtain a copy of the License at
|
|
2073
|
-
*
|
|
2074
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2075
|
-
*
|
|
2076
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2077
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2078
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2079
|
-
* See the License for the specific language governing permissions and
|
|
2080
|
-
* limitations under the License.
|
|
2081
|
-
*/
|
|
2082
|
-
const DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY = "docs-drawing-ui.config";
|
|
2083
|
-
const configSymbol = Symbol(DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY);
|
|
2084
|
-
const defaultPluginConfig = {};
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region package.json
|
|
1198
|
+
var name = "@univerjs/docs-drawing-ui";
|
|
1199
|
+
var version = "1.0.0-alpha.4";
|
|
1200
|
+
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region src/config/config.ts
|
|
1203
|
+
/**
|
|
1204
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1205
|
+
*
|
|
1206
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1207
|
+
* you may not use this file except in compliance with the License.
|
|
1208
|
+
* You may obtain a copy of the License at
|
|
1209
|
+
*
|
|
1210
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1211
|
+
*
|
|
1212
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1213
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1214
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1215
|
+
* See the License for the specific language governing permissions and
|
|
1216
|
+
* limitations under the License.
|
|
1217
|
+
*/
|
|
1218
|
+
const DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY = "docs-drawing-ui.config";
|
|
1219
|
+
const configSymbol = Symbol(DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY);
|
|
1220
|
+
const defaultPluginConfig = {};
|
|
1221
|
+
|
|
1222
|
+
//#endregion
|
|
1223
|
+
//#region src/views/doc-image-panel/DocDrawingPosition.tsx
|
|
1224
|
+
const MIN_OFFSET = -1e3;
|
|
1225
|
+
const MAX_OFFSET = 1e3;
|
|
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) {
|
|
1234
|
+
const commandService = useDependency(ICommandService);
|
|
1235
|
+
const localeService = useDependency(LocaleService);
|
|
1236
|
+
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
1237
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
1238
|
+
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
1239
|
+
const { drawings } = props;
|
|
1240
|
+
const { unitId } = drawings[0];
|
|
1241
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1242
|
+
const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
|
|
1243
|
+
const transformer = renderManagerService.getRenderById(unitId).scene.getTransformerByCreate();
|
|
1244
|
+
const HORIZONTAL_RELATIVE_FROM = [
|
|
1245
|
+
{
|
|
1246
|
+
label: localeService.t("docs-drawing-ui.image-position.column"),
|
|
1247
|
+
value: String(ObjectRelativeFromH.COLUMN)
|
|
1248
|
+
},
|
|
1249
|
+
{
|
|
1250
|
+
label: localeService.t("docs-drawing-ui.image-position.page"),
|
|
1251
|
+
value: String(ObjectRelativeFromH.PAGE)
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
label: localeService.t("docs-drawing-ui.image-position.margin"),
|
|
1255
|
+
value: String(ObjectRelativeFromH.MARGIN)
|
|
1256
|
+
}
|
|
1257
|
+
];
|
|
1258
|
+
const VERTICAL_RELATIVE_FROM = [
|
|
1259
|
+
{
|
|
1260
|
+
label: localeService.t("docs-drawing-ui.image-position.line"),
|
|
1261
|
+
value: String(ObjectRelativeFromV.LINE),
|
|
1262
|
+
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
label: localeService.t("docs-drawing-ui.image-position.page"),
|
|
1266
|
+
value: String(ObjectRelativeFromV.PAGE),
|
|
1267
|
+
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
label: localeService.t("docs-drawing-ui.image-position.margin"),
|
|
1271
|
+
value: String(ObjectRelativeFromV.MARGIN),
|
|
1272
|
+
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
label: localeService.t("docs-drawing-ui.image-position.paragraph"),
|
|
1276
|
+
value: String(ObjectRelativeFromV.PARAGRAPH)
|
|
1277
|
+
}
|
|
1278
|
+
];
|
|
1279
|
+
const [disabled, setDisabled] = useState(true);
|
|
1280
|
+
const [hPosition, setHPosition] = useState({
|
|
1281
|
+
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
1282
|
+
posOffset: 0
|
|
1283
|
+
});
|
|
1284
|
+
const [vPosition, setVPosition] = useState({
|
|
1285
|
+
relativeFrom: ObjectRelativeFromV.PAGE,
|
|
1286
|
+
posOffset: 0
|
|
1287
|
+
});
|
|
1288
|
+
const [followTextMove, setFollowTextMove] = useState(true);
|
|
1289
|
+
const [showPanel, setShowPanel] = useState(true);
|
|
1290
|
+
function handlePositionChange(direction, value) {
|
|
1291
|
+
var _renderManagerService2;
|
|
1292
|
+
if (direction === "positionH") setHPosition(value);
|
|
1293
|
+
else setVPosition(value);
|
|
1294
|
+
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
1295
|
+
if (focusDrawings.length === 0) return;
|
|
1296
|
+
const drawings = focusDrawings.map((drawing) => {
|
|
1297
|
+
return {
|
|
1298
|
+
unitId: drawing.unitId,
|
|
1299
|
+
subUnitId: drawing.subUnitId,
|
|
1300
|
+
drawingId: drawing.drawingId
|
|
1301
|
+
};
|
|
1302
|
+
});
|
|
1303
|
+
commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
|
|
1304
|
+
unitId: focusDrawings[0].unitId,
|
|
1305
|
+
subUnitId: focusDrawings[0].unitId,
|
|
1306
|
+
drawings: drawings.map((drawing) => ({
|
|
1307
|
+
drawingId: drawing.drawingId,
|
|
1308
|
+
key: direction,
|
|
1309
|
+
value
|
|
1310
|
+
}))
|
|
1311
|
+
});
|
|
1312
|
+
const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSelectionRenderService);
|
|
1313
|
+
if (docSelectionRenderService) docSelectionRenderService.blur();
|
|
1314
|
+
transformer.refreshControls();
|
|
1315
|
+
}
|
|
1316
|
+
function handleHorizontalRelativeFromChange(value) {
|
|
1317
|
+
var _renderManagerService3;
|
|
1318
|
+
const prevRelativeFrom = hPosition.relativeFrom;
|
|
1319
|
+
const prevPosOffset = hPosition.posOffset;
|
|
1320
|
+
const relativeFrom = Number(value);
|
|
1321
|
+
if (prevRelativeFrom === relativeFrom) return;
|
|
1322
|
+
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
1323
|
+
if (focusDrawings.length === 0) return;
|
|
1324
|
+
const drawingId = focusDrawings[0].drawingId;
|
|
1325
|
+
const unitId = focusDrawings[0].unitId;
|
|
1326
|
+
let drawing = null;
|
|
1327
|
+
let pageMarginLeft = 0;
|
|
1328
|
+
const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(DocSkeletonManagerService).getSkeleton();
|
|
1329
|
+
const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
|
|
1330
|
+
if (skeletonData == null) return;
|
|
1331
|
+
const { pages, skeHeaders, skeFooters } = skeletonData;
|
|
1332
|
+
for (const page of pages) {
|
|
1333
|
+
var _skeHeaders$get, _skeFooters$get;
|
|
1334
|
+
const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
|
|
1335
|
+
if (skeDrawings.has(drawingId)) {
|
|
1336
|
+
drawing = skeDrawings.get(drawingId);
|
|
1337
|
+
pageMarginLeft = marginLeft;
|
|
1338
|
+
break;
|
|
1339
|
+
}
|
|
1340
|
+
const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
|
|
1341
|
+
if (headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.has(drawingId)) {
|
|
1342
|
+
drawing = headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.get(drawingId);
|
|
1343
|
+
pageMarginLeft = marginLeft;
|
|
1344
|
+
break;
|
|
1345
|
+
}
|
|
1346
|
+
const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
|
|
1347
|
+
if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
|
|
1348
|
+
drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
|
|
1349
|
+
pageMarginLeft = marginLeft;
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
if (drawing == null) return;
|
|
1354
|
+
let delta = 0;
|
|
1355
|
+
if (prevRelativeFrom === ObjectRelativeFromH.COLUMN) delta -= drawing.columnLeft;
|
|
1356
|
+
else if (prevRelativeFrom === ObjectRelativeFromH.MARGIN) delta -= pageMarginLeft;
|
|
1357
|
+
if (relativeFrom === ObjectRelativeFromH.COLUMN) delta += drawing.columnLeft;
|
|
1358
|
+
else if (relativeFrom === ObjectRelativeFromH.MARGIN) delta += pageMarginLeft;
|
|
1359
|
+
else if (relativeFrom === ObjectRelativeFromH.PAGE) {}
|
|
1360
|
+
handlePositionChange("positionH", {
|
|
1361
|
+
relativeFrom,
|
|
1362
|
+
posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
function handleVerticalRelativeFromChange(value) {
|
|
1366
|
+
var _renderManagerService4, _renderManagerService5, _documentDataModel$ge, _glyph$parent, _column$parent;
|
|
1367
|
+
const prevRelativeFrom = vPosition.relativeFrom;
|
|
1368
|
+
const prevPosOffset = vPosition.posOffset;
|
|
1369
|
+
const relativeFrom = Number(value);
|
|
1370
|
+
if (prevRelativeFrom === relativeFrom) return;
|
|
1371
|
+
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
1372
|
+
if (focusDrawings.length === 0) return;
|
|
1373
|
+
const { drawingId, unitId } = focusDrawings[0];
|
|
1374
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
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);
|
|
1377
|
+
const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
|
|
1378
|
+
const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
|
|
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);
|
|
1380
|
+
if (drawing == null || skeleton == null || docSelectionRenderService == null) return;
|
|
1381
|
+
const { startIndex } = drawing;
|
|
1382
|
+
const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
|
|
1383
|
+
const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
|
|
1384
|
+
const column = line === null || line === void 0 ? void 0 : line.parent;
|
|
1385
|
+
const paragraphStartLine = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart);
|
|
1386
|
+
const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
|
|
1387
|
+
if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) return;
|
|
1388
|
+
let delta = 0;
|
|
1389
|
+
if (prevRelativeFrom === ObjectRelativeFromV.PARAGRAPH) delta -= paragraphStartLine.top;
|
|
1390
|
+
else if (prevRelativeFrom === ObjectRelativeFromV.LINE) delta -= line.top;
|
|
1391
|
+
else if (prevRelativeFrom === ObjectRelativeFromV.PAGE) delta += page.marginTop;
|
|
1392
|
+
if (relativeFrom === ObjectRelativeFromV.PARAGRAPH) delta += paragraphStartLine.top;
|
|
1393
|
+
else if (relativeFrom === ObjectRelativeFromV.LINE) delta += line.top;
|
|
1394
|
+
else if (relativeFrom === ObjectRelativeFromV.PAGE) delta -= page.marginTop;
|
|
1395
|
+
handlePositionChange("positionV", {
|
|
1396
|
+
relativeFrom,
|
|
1397
|
+
posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
function updateState(drawingParam) {
|
|
1401
|
+
var _snapshot$drawings;
|
|
1402
|
+
const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
|
|
1403
|
+
const drawing = snapshot === null || snapshot === void 0 || (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingParam.drawingId];
|
|
1404
|
+
if (drawing == null) return;
|
|
1405
|
+
const { layoutType } = drawing;
|
|
1406
|
+
const { positionH, positionV } = drawing.docTransform;
|
|
1407
|
+
setHPosition(positionH);
|
|
1408
|
+
setVPosition(positionV);
|
|
1409
|
+
setDisabled(layoutType === PositionedObjectLayoutType.INLINE);
|
|
1410
|
+
setFollowTextMove(positionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === ObjectRelativeFromV.LINE);
|
|
1411
|
+
}
|
|
1412
|
+
function updateFocusDrawingState() {
|
|
1413
|
+
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
1414
|
+
if (focusDrawings.length === 0) return;
|
|
1415
|
+
updateState(focusDrawings[0]);
|
|
1416
|
+
}
|
|
1417
|
+
function handleFollowTextMoveCheck(val) {
|
|
1418
|
+
setFollowTextMove(val);
|
|
1419
|
+
handleVerticalRelativeFromChange(val ? String(ObjectRelativeFromV.PARAGRAPH) : String(ObjectRelativeFromV.PAGE));
|
|
1420
|
+
}
|
|
1421
|
+
useEffect(() => {
|
|
1422
|
+
updateFocusDrawingState();
|
|
1423
|
+
const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
|
|
1424
|
+
if (drawingParams.length === 0) {
|
|
1425
|
+
setShowPanel(false);
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
setShowPanel(true);
|
|
1429
|
+
updateState(drawingParams[0]);
|
|
1430
|
+
});
|
|
1431
|
+
const mutationListener = commandService.onCommandExecuted(async (command) => {
|
|
1432
|
+
if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
|
|
1433
|
+
});
|
|
1434
|
+
return () => {
|
|
1435
|
+
subscription.unsubscribe();
|
|
1436
|
+
mutationListener.dispose();
|
|
1437
|
+
};
|
|
1438
|
+
}, []);
|
|
1439
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1440
|
+
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
|
|
1441
|
+
children: [
|
|
1442
|
+
/* @__PURE__ */ jsx("header", {
|
|
1443
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
1444
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.title") })
|
|
1445
|
+
}),
|
|
1446
|
+
/* @__PURE__ */ jsx("div", {
|
|
1447
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
1448
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
|
|
1449
|
+
}),
|
|
1450
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1451
|
+
className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
1452
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
1453
|
+
min: MIN_OFFSET,
|
|
1454
|
+
max: MAX_OFFSET,
|
|
1455
|
+
precision: 1,
|
|
1456
|
+
disabled,
|
|
1457
|
+
value: hPosition.posOffset,
|
|
1458
|
+
onChange: (val) => {
|
|
1459
|
+
handlePositionChange("positionH", {
|
|
1460
|
+
relativeFrom: hPosition.relativeFrom,
|
|
1461
|
+
posOffset: val
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
})] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.toTheRightOf") }), /* @__PURE__ */ jsx(Select, {
|
|
1465
|
+
value: String(hPosition.relativeFrom),
|
|
1466
|
+
disabled,
|
|
1467
|
+
options: HORIZONTAL_RELATIVE_FROM,
|
|
1468
|
+
onChange: handleHorizontalRelativeFromChange
|
|
1469
|
+
})] })]
|
|
1470
|
+
}),
|
|
1471
|
+
/* @__PURE__ */ jsx("div", {
|
|
1472
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
1473
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
|
|
1474
|
+
}),
|
|
1475
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1476
|
+
className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
1477
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
1478
|
+
min: MIN_OFFSET,
|
|
1479
|
+
max: MAX_OFFSET,
|
|
1480
|
+
precision: 1,
|
|
1481
|
+
disabled,
|
|
1482
|
+
value: vPosition.posOffset,
|
|
1483
|
+
onChange: (val) => {
|
|
1484
|
+
handlePositionChange("positionV", {
|
|
1485
|
+
relativeFrom: vPosition.relativeFrom,
|
|
1486
|
+
posOffset: val
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
})] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.bellow") }), /* @__PURE__ */ jsx(Select, {
|
|
1490
|
+
disabled,
|
|
1491
|
+
value: String(vPosition.relativeFrom),
|
|
1492
|
+
options: VERTICAL_RELATIVE_FROM,
|
|
1493
|
+
onChange: handleVerticalRelativeFromChange
|
|
1494
|
+
})] })]
|
|
1495
|
+
}),
|
|
1496
|
+
/* @__PURE__ */ jsx("div", {
|
|
1497
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
1498
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
|
|
1499
|
+
}),
|
|
1500
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Checkbox, {
|
|
1501
|
+
disabled,
|
|
1502
|
+
checked: followTextMove,
|
|
1503
|
+
onChange: handleFollowTextMoveCheck,
|
|
1504
|
+
children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
|
|
1505
|
+
}) })
|
|
1506
|
+
]
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
2085
1509
|
|
|
2086
1510
|
//#endregion
|
|
2087
|
-
//#region src/
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
const
|
|
2091
|
-
const
|
|
2092
|
-
const
|
|
2093
|
-
const
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2096
|
-
const
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
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
|
+
});
|
|
2118
1572
|
}
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
value: String(ObjectRelativeFromV.LINE),
|
|
2124
|
-
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
2125
|
-
},
|
|
2126
|
-
{
|
|
2127
|
-
label: localeService.t("docs-drawing-ui.image-position.page"),
|
|
2128
|
-
value: String(ObjectRelativeFromV.PAGE),
|
|
2129
|
-
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
2130
|
-
},
|
|
2131
|
-
{
|
|
2132
|
-
label: localeService.t("docs-drawing-ui.image-position.margin"),
|
|
2133
|
-
value: String(ObjectRelativeFromV.MARGIN),
|
|
2134
|
-
disabled: documentFlavor === DocumentFlavor.MODERN
|
|
2135
|
-
},
|
|
2136
|
-
{
|
|
2137
|
-
label: localeService.t("docs-drawing-ui.image-position.paragraph"),
|
|
2138
|
-
value: String(ObjectRelativeFromV.PARAGRAPH)
|
|
1573
|
+
if (offset !== oldOffset) {
|
|
1574
|
+
const path = getRichTextEditPath(documentDataModel, oldSegmentId);
|
|
1575
|
+
const action = jsonX.editOp(textX.serialize(), path);
|
|
1576
|
+
rawActions.push(action);
|
|
2139
1577
|
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
posOffset: 0
|
|
2145
|
-
});
|
|
2146
|
-
const [vPosition, setVPosition] = useState({
|
|
2147
|
-
relativeFrom: ObjectRelativeFromV.PAGE,
|
|
2148
|
-
posOffset: 0
|
|
2149
|
-
});
|
|
2150
|
-
const [followTextMove, setFollowTextMove] = useState(true);
|
|
2151
|
-
const [showPanel, setShowPanel] = useState(true);
|
|
2152
|
-
function handlePositionChange(direction, value) {
|
|
2153
|
-
var _renderManagerService;
|
|
2154
|
-
if (direction === "positionH") setHPosition(value);
|
|
2155
|
-
else setVPosition(value);
|
|
2156
|
-
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
2157
|
-
if (focusDrawings.length === 0) return;
|
|
2158
|
-
const drawings = focusDrawings.map((drawing) => {
|
|
2159
|
-
return {
|
|
2160
|
-
unitId: drawing.unitId,
|
|
2161
|
-
subUnitId: drawing.subUnitId,
|
|
2162
|
-
drawingId: drawing.drawingId
|
|
2163
|
-
};
|
|
1578
|
+
} else {
|
|
1579
|
+
if (oldOffset > 0) textX.push({
|
|
1580
|
+
t: TextXActionType.RETAIN,
|
|
1581
|
+
len: oldOffset
|
|
2164
1582
|
});
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
drawings: drawings.map((drawing) => ({
|
|
2169
|
-
drawingId: drawing.drawingId,
|
|
2170
|
-
key: direction,
|
|
2171
|
-
value
|
|
2172
|
-
}))
|
|
1583
|
+
textX.push({
|
|
1584
|
+
t: TextXActionType.DELETE,
|
|
1585
|
+
len: 1
|
|
2173
1586
|
});
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
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);
|
|
2177
1611
|
}
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
const
|
|
2191
|
-
const
|
|
2192
|
-
if (
|
|
2193
|
-
const
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
|
|
2209
|
-
if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
|
|
2210
|
-
drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
|
|
2211
|
-
pageMarginLeft = marginLeft;
|
|
2212
|
-
break;
|
|
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
|
+
}
|
|
2213
1642
|
}
|
|
2214
1643
|
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
});
|
|
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);
|
|
2226
1657
|
}
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
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;
|
|
2236
1670
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2237
|
-
|
|
2238
|
-
const
|
|
2239
|
-
const
|
|
2240
|
-
const
|
|
2241
|
-
const drawing
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
const
|
|
2265
|
-
|
|
2266
|
-
if (drawing == null) return;
|
|
2267
|
-
const { layoutType } = drawing;
|
|
2268
|
-
const { positionH, positionV } = drawing.docTransform;
|
|
2269
|
-
setHPosition(positionH);
|
|
2270
|
-
setVPosition(positionV);
|
|
2271
|
-
setDisabled(layoutType === PositionedObjectLayoutType.INLINE);
|
|
2272
|
-
setFollowTextMove(positionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === ObjectRelativeFromV.LINE);
|
|
2273
|
-
}
|
|
2274
|
-
function updateFocusDrawingState() {
|
|
2275
|
-
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
2276
|
-
if (focusDrawings.length === 0) return;
|
|
2277
|
-
updateState(focusDrawings[0]);
|
|
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);
|
|
2278
1700
|
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
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);
|
|
2282
1751
|
}
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
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
|
|
2289
1823
|
}
|
|
2290
|
-
setShowPanel(true);
|
|
2291
|
-
updateState(drawingParams[0]);
|
|
2292
|
-
});
|
|
2293
|
-
const mutationListener = commandService.onCommandExecuted(async (command) => {
|
|
2294
|
-
if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
|
|
2295
|
-
});
|
|
2296
|
-
return () => {
|
|
2297
|
-
subscription.unsubscribe();
|
|
2298
|
-
mutationListener.dispose();
|
|
2299
1824
|
};
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
}),
|
|
2308
|
-
/* @__PURE__ */ jsx("div", {
|
|
2309
|
-
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2310
|
-
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
|
|
2311
|
-
}),
|
|
2312
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2313
|
-
className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2314
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2315
|
-
min: MIN_OFFSET,
|
|
2316
|
-
max: MAX_OFFSET,
|
|
2317
|
-
precision: 1,
|
|
2318
|
-
disabled,
|
|
2319
|
-
value: hPosition.posOffset,
|
|
2320
|
-
onChange: (val) => {
|
|
2321
|
-
handlePositionChange("positionH", {
|
|
2322
|
-
relativeFrom: hPosition.relativeFrom,
|
|
2323
|
-
posOffset: val
|
|
2324
|
-
});
|
|
2325
|
-
}
|
|
2326
|
-
})] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.toTheRightOf") }), /* @__PURE__ */ jsx(Select, {
|
|
2327
|
-
value: String(hPosition.relativeFrom),
|
|
2328
|
-
disabled,
|
|
2329
|
-
options: HORIZONTAL_RELATIVE_FROM,
|
|
2330
|
-
onChange: handleHorizontalRelativeFromChange
|
|
2331
|
-
})] })]
|
|
2332
|
-
}),
|
|
2333
|
-
/* @__PURE__ */ jsx("div", {
|
|
2334
|
-
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2335
|
-
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
|
|
2336
|
-
}),
|
|
2337
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2338
|
-
className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2339
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2340
|
-
min: MIN_OFFSET,
|
|
2341
|
-
max: MAX_OFFSET,
|
|
2342
|
-
precision: 1,
|
|
2343
|
-
disabled,
|
|
2344
|
-
value: vPosition.posOffset,
|
|
2345
|
-
onChange: (val) => {
|
|
2346
|
-
handlePositionChange("positionV", {
|
|
2347
|
-
relativeFrom: vPosition.relativeFrom,
|
|
2348
|
-
posOffset: val
|
|
2349
|
-
});
|
|
2350
|
-
}
|
|
2351
|
-
})] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.bellow") }), /* @__PURE__ */ jsx(Select, {
|
|
2352
|
-
disabled,
|
|
2353
|
-
value: String(vPosition.relativeFrom),
|
|
2354
|
-
options: VERTICAL_RELATIVE_FROM,
|
|
2355
|
-
onChange: handleVerticalRelativeFromChange
|
|
2356
|
-
})] })]
|
|
2357
|
-
}),
|
|
2358
|
-
/* @__PURE__ */ jsx("div", {
|
|
2359
|
-
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2360
|
-
children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
|
|
2361
|
-
}),
|
|
2362
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Checkbox, {
|
|
2363
|
-
disabled,
|
|
2364
|
-
checked: followTextMove,
|
|
2365
|
-
onChange: handleFollowTextMoveCheck,
|
|
2366
|
-
children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
|
|
2367
|
-
}) })
|
|
2368
|
-
]
|
|
2369
|
-
});
|
|
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
|
+
}
|
|
2370
1832
|
};
|
|
2371
1833
|
|
|
2372
1834
|
//#endregion
|
|
@@ -2374,22 +1836,24 @@ const DocDrawingPosition = (props) => {
|
|
|
2374
1836
|
const MIN_MARGIN = 0;
|
|
2375
1837
|
const MAX_MARGIN = 100;
|
|
2376
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) {
|
|
2377
1846
|
const commandService = useDependency(ICommandService);
|
|
2378
1847
|
const localeService = useDependency(LocaleService);
|
|
2379
1848
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2380
|
-
const renderManagerService = useDependency(IRenderManagerService);
|
|
2381
1849
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
2382
1850
|
const { drawings } = props;
|
|
2383
|
-
const
|
|
2384
|
-
if (drawingParam == null) return null;
|
|
2385
|
-
const { unitId } = drawingParam;
|
|
1851
|
+
const { unitId } = drawings[0];
|
|
2386
1852
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2387
|
-
const renderObject = renderManagerService.getRenderUnitById(unitId);
|
|
2388
|
-
if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
|
|
2389
1853
|
const [disableWrapText, setDisableWrapText] = useState(true);
|
|
2390
1854
|
const [disableDistTB, setDisableDistTB] = useState(true);
|
|
2391
1855
|
const [disableDistLR, setDisableDistLR] = useState(true);
|
|
2392
|
-
const [wrappingStyle, setWrappingStyle] = useState(
|
|
1856
|
+
const [wrappingStyle, setWrappingStyle] = useState(TextWrappingStyle.INLINE);
|
|
2393
1857
|
const [wrapText, setWrapText] = useState("");
|
|
2394
1858
|
const [distToText, setDistToText] = useState({
|
|
2395
1859
|
distT: 0,
|
|
@@ -2477,17 +1941,17 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2477
1941
|
else setDisableDistTB(false);
|
|
2478
1942
|
if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE || layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
|
|
2479
1943
|
else setDisableDistLR(false);
|
|
2480
|
-
if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle(
|
|
2481
|
-
else setWrappingStyle(
|
|
1944
|
+
if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle(TextWrappingStyle.BEHIND_TEXT);
|
|
1945
|
+
else setWrappingStyle(TextWrappingStyle.IN_FRONT_OF_TEXT);
|
|
2482
1946
|
else switch (layoutType) {
|
|
2483
1947
|
case PositionedObjectLayoutType.INLINE:
|
|
2484
|
-
setWrappingStyle(
|
|
1948
|
+
setWrappingStyle(TextWrappingStyle.INLINE);
|
|
2485
1949
|
break;
|
|
2486
1950
|
case PositionedObjectLayoutType.WRAP_SQUARE:
|
|
2487
|
-
setWrappingStyle(
|
|
1951
|
+
setWrappingStyle(TextWrappingStyle.WRAP_SQUARE);
|
|
2488
1952
|
break;
|
|
2489
1953
|
case PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
|
|
2490
|
-
setWrappingStyle(
|
|
1954
|
+
setWrappingStyle(TextWrappingStyle.WRAP_TOP_AND_BOTTOM);
|
|
2491
1955
|
break;
|
|
2492
1956
|
default: throw new Error(`Unsupported layout type: ${layoutType}`);
|
|
2493
1957
|
}
|
|
@@ -2527,23 +1991,23 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2527
1991
|
direction: "vertical",
|
|
2528
1992
|
children: [
|
|
2529
1993
|
/* @__PURE__ */ jsx(Radio, {
|
|
2530
|
-
value:
|
|
1994
|
+
value: TextWrappingStyle.INLINE,
|
|
2531
1995
|
children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
|
|
2532
1996
|
}),
|
|
2533
1997
|
/* @__PURE__ */ jsx(Radio, {
|
|
2534
|
-
value:
|
|
1998
|
+
value: TextWrappingStyle.WRAP_SQUARE,
|
|
2535
1999
|
children: localeService.t("docs-drawing-ui.image-text-wrap.square")
|
|
2536
2000
|
}),
|
|
2537
2001
|
/* @__PURE__ */ jsx(Radio, {
|
|
2538
|
-
value:
|
|
2002
|
+
value: TextWrappingStyle.WRAP_TOP_AND_BOTTOM,
|
|
2539
2003
|
children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
|
|
2540
2004
|
}),
|
|
2541
2005
|
/* @__PURE__ */ jsx(Radio, {
|
|
2542
|
-
value:
|
|
2006
|
+
value: TextWrappingStyle.BEHIND_TEXT,
|
|
2543
2007
|
children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
|
|
2544
2008
|
}),
|
|
2545
2009
|
/* @__PURE__ */ jsx(Radio, {
|
|
2546
|
-
value:
|
|
2010
|
+
value: TextWrappingStyle.IN_FRONT_OF_TEXT,
|
|
2547
2011
|
children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
|
|
2548
2012
|
})
|
|
2549
2013
|
]
|
|
@@ -2622,21 +2086,28 @@ const DocDrawingTextWrap = (props) => {
|
|
|
2622
2086
|
})
|
|
2623
2087
|
]
|
|
2624
2088
|
});
|
|
2625
|
-
}
|
|
2089
|
+
}
|
|
2626
2090
|
|
|
2627
2091
|
//#endregion
|
|
2628
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
|
+
*/
|
|
2629
2108
|
const DocDrawingPanel = () => {
|
|
2630
2109
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2631
|
-
const
|
|
2632
|
-
useEffect(() => {
|
|
2633
|
-
const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
|
|
2634
|
-
setDrawings(drawings);
|
|
2635
|
-
});
|
|
2636
|
-
return () => {
|
|
2637
|
-
focusDispose.unsubscribe();
|
|
2638
|
-
};
|
|
2639
|
-
}, []);
|
|
2110
|
+
const drawings = useObservable(() => drawingManagerService.focus$, drawingManagerService.getFocusDrawings(), false, [drawingManagerService]);
|
|
2640
2111
|
return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
|
|
2641
2112
|
className: "univer-text-sm",
|
|
2642
2113
|
children: [
|
|
@@ -2684,6 +2155,19 @@ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))]
|
|
|
2684
2155
|
|
|
2685
2156
|
//#endregion
|
|
2686
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
|
+
}
|
|
2687
2171
|
function getAddOrRemoveDrawings(actions) {
|
|
2688
2172
|
if (JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
|
|
2689
2173
|
const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
|
|
@@ -2742,13 +2226,14 @@ function collectUpdatedDrawingIds(actions, drawingIds = /* @__PURE__ */ new Set(
|
|
|
2742
2226
|
return drawingIds;
|
|
2743
2227
|
}
|
|
2744
2228
|
let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends Disposable {
|
|
2745
|
-
constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
|
|
2229
|
+
constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService, _docRefreshDrawingsService) {
|
|
2746
2230
|
super();
|
|
2747
2231
|
this._univerInstanceService = _univerInstanceService;
|
|
2748
2232
|
this._commandService = _commandService;
|
|
2749
2233
|
this._drawingManagerService = _drawingManagerService;
|
|
2750
2234
|
this._docDrawingService = _docDrawingService;
|
|
2751
2235
|
this._renderManagerService = _renderManagerService;
|
|
2236
|
+
this._docRefreshDrawingsService = _docRefreshDrawingsService;
|
|
2752
2237
|
this._initialize();
|
|
2753
2238
|
}
|
|
2754
2239
|
_initialize() {
|
|
@@ -2765,6 +2250,10 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2765
2250
|
else this._removeDrawings(unitId, [drawingId]);
|
|
2766
2251
|
}
|
|
2767
2252
|
}));
|
|
2253
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
2254
|
+
if (command.id !== UpdateDocDrawingWrappingStyleCommand.id) return;
|
|
2255
|
+
this._preserveWrappingStylePosition(command.params);
|
|
2256
|
+
}));
|
|
2768
2257
|
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2769
2258
|
if (command.id !== RichTextEditingMutation.id) return;
|
|
2770
2259
|
const { unitId, actions } = command.params;
|
|
@@ -2772,6 +2261,15 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2772
2261
|
const updatedDrawingIds = [...collectUpdatedDrawingIds(actions)];
|
|
2773
2262
|
if (updatedDrawingIds.length > 0) this._syncDrawingDataFromSnapshot(unitId, updatedDrawingIds);
|
|
2774
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();
|
|
2272
|
+
}));
|
|
2775
2273
|
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2776
2274
|
var _this$_univerInstance;
|
|
2777
2275
|
if (command.id !== UndoCommand.id && command.id !== RedoCommand.id) return;
|
|
@@ -2784,6 +2282,65 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
|
|
|
2784
2282
|
scene.getTransformerByCreate().refreshControls();
|
|
2785
2283
|
}));
|
|
2786
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
|
+
}
|
|
2787
2344
|
_addDrawings(unitId, drawings) {
|
|
2788
2345
|
const drawingManagerService = this._drawingManagerService;
|
|
2789
2346
|
const docDrawingService = this._docDrawingService;
|
|
@@ -2855,7 +2412,8 @@ DocDrawingAddRemoveController = __decorate([
|
|
|
2855
2412
|
__decorateParam(1, ICommandService),
|
|
2856
2413
|
__decorateParam(2, IDrawingManagerService),
|
|
2857
2414
|
__decorateParam(3, IDocDrawingService),
|
|
2858
|
-
__decorateParam(4, IRenderManagerService)
|
|
2415
|
+
__decorateParam(4, IRenderManagerService),
|
|
2416
|
+
__decorateParam(5, Inject(DocRefreshDrawingsService))
|
|
2859
2417
|
], DocDrawingAddRemoveController);
|
|
2860
2418
|
|
|
2861
2419
|
//#endregion
|
|
@@ -3230,6 +2788,8 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
|
|
|
3230
2788
|
width,
|
|
3231
2789
|
height,
|
|
3232
2790
|
angle,
|
|
2791
|
+
flipX: drawingOrigin.docTransform.flipX,
|
|
2792
|
+
flipY: drawingOrigin.docTransform.flipY,
|
|
3233
2793
|
clipBounds: pageClipBounds
|
|
3234
2794
|
};
|
|
3235
2795
|
if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
|
|
@@ -3922,22 +3482,17 @@ let DocDrawingUIController = class DocDrawingUIController extends Disposable {
|
|
|
3922
3482
|
InsertDocImageCommand,
|
|
3923
3483
|
InsertDocRectangleShapeCommand,
|
|
3924
3484
|
InsertDocEllipseShapeCommand,
|
|
3925
|
-
InsertDocDrawingCommand,
|
|
3926
|
-
UpdateDocDrawingWrappingStyleCommand,
|
|
3927
3485
|
UpdateDocDrawingDistanceCommand,
|
|
3928
3486
|
UpdateDocDrawingWrapTextCommand,
|
|
3929
|
-
UpdateDrawingDocTransformCommand,
|
|
3930
3487
|
IMoveInlineDrawingCommand,
|
|
3931
3488
|
ITransformNonInlineDrawingCommand,
|
|
3932
|
-
RemoveDocDrawingCommand,
|
|
3933
3489
|
SidebarDocDrawingOperation,
|
|
3934
3490
|
ClearDocDrawingTransformerOperation,
|
|
3935
3491
|
EditDocDrawingOperation,
|
|
3936
3492
|
GroupDocDrawingCommand,
|
|
3937
3493
|
UngroupDocDrawingCommand,
|
|
3938
3494
|
MoveDocDrawingsCommand,
|
|
3939
|
-
DeleteDocDrawingsCommand
|
|
3940
|
-
SetDocDrawingArrangeCommand
|
|
3495
|
+
DeleteDocDrawingsCommand
|
|
3941
3496
|
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
3942
3497
|
}
|
|
3943
3498
|
_initShortcuts() {
|
|
@@ -4131,32 +3686,36 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
|
|
|
4131
3686
|
subUnitId,
|
|
4132
3687
|
drawingId
|
|
4133
3688
|
},
|
|
4134
|
-
disable: (_editCommandInfo$disa = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.disable) !== null && _editCommandInfo$disa !== void 0 ? _editCommandInfo$disa : drawingType === DrawingTypeEnum.DRAWING_DOM
|
|
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"
|
|
4135
3692
|
},
|
|
4136
3693
|
{
|
|
4137
|
-
label: "docs-drawing-ui.image-popup.
|
|
3694
|
+
label: "docs-drawing-ui.image-popup.crop",
|
|
4138
3695
|
index: 1,
|
|
4139
|
-
commandId:
|
|
3696
|
+
commandId: OpenImageCropOperation.id,
|
|
4140
3697
|
commandParams: {
|
|
4141
3698
|
unitId,
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
subUnitId,
|
|
4145
|
-
drawingId
|
|
4146
|
-
}]
|
|
3699
|
+
subUnitId,
|
|
3700
|
+
drawingId
|
|
4147
3701
|
},
|
|
4148
|
-
disable:
|
|
3702
|
+
disable: drawingType === DrawingTypeEnum.DRAWING_DOM,
|
|
3703
|
+
icon: "DrawingCropIcon"
|
|
4149
3704
|
},
|
|
4150
3705
|
{
|
|
4151
|
-
label: "docs-drawing-ui.image-popup.
|
|
3706
|
+
label: "docs-drawing-ui.image-popup.delete",
|
|
4152
3707
|
index: 2,
|
|
4153
|
-
commandId:
|
|
3708
|
+
commandId: RemoveDocDrawingCommand.id,
|
|
4154
3709
|
commandParams: {
|
|
4155
3710
|
unitId,
|
|
4156
|
-
|
|
4157
|
-
|
|
3711
|
+
drawings: [{
|
|
3712
|
+
unitId,
|
|
3713
|
+
subUnitId,
|
|
3714
|
+
drawingId
|
|
3715
|
+
}]
|
|
4158
3716
|
},
|
|
4159
|
-
disable:
|
|
3717
|
+
disable: false,
|
|
3718
|
+
icon: "DrawingDeleteIcon"
|
|
4160
3719
|
},
|
|
4161
3720
|
{
|
|
4162
3721
|
label: "docs-drawing-ui.image-popup.reset",
|
|
@@ -4233,4 +3792,4 @@ UniverDocsDrawingUIPlugin = __decorate([
|
|
|
4233
3792
|
], UniverDocsDrawingUIPlugin);
|
|
4234
3793
|
|
|
4235
3794
|
//#endregion
|
|
4236
|
-
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,
|
|
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 };
|