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