@univerjs/docs-drawing-ui 1.0.0-alpha.3 → 1.0.0-alpha.4

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