@univerjs/docs-drawing-ui 0.25.0 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/lib/cjs/index.js +1864 -1522
  2. package/lib/cjs/locale/ar-SA.js +5 -0
  3. package/lib/cjs/locale/ca-ES.js +5 -0
  4. package/lib/cjs/locale/de-DE.js +5 -0
  5. package/lib/cjs/locale/en-US.js +5 -0
  6. package/lib/cjs/locale/es-ES.js +5 -0
  7. package/lib/cjs/locale/fa-IR.js +5 -0
  8. package/lib/cjs/locale/fr-FR.js +5 -0
  9. package/lib/cjs/locale/id-ID.js +5 -0
  10. package/lib/cjs/locale/it-IT.js +5 -0
  11. package/lib/cjs/locale/ja-JP.js +5 -0
  12. package/lib/cjs/locale/ko-KR.js +5 -0
  13. package/lib/cjs/locale/pl-PL.js +5 -0
  14. package/lib/cjs/locale/pt-BR.js +5 -0
  15. package/lib/cjs/locale/ru-RU.js +5 -0
  16. package/lib/cjs/locale/sk-SK.js +5 -0
  17. package/lib/cjs/locale/vi-VN.js +5 -0
  18. package/lib/cjs/locale/zh-CN.js +5 -0
  19. package/lib/cjs/locale/zh-HK.js +5 -0
  20. package/lib/cjs/locale/zh-TW.js +5 -0
  21. package/lib/es/index.js +1860 -1522
  22. package/lib/es/locale/ar-SA.js +5 -0
  23. package/lib/es/locale/ca-ES.js +5 -0
  24. package/lib/es/locale/de-DE.js +5 -0
  25. package/lib/es/locale/en-US.js +5 -0
  26. package/lib/es/locale/es-ES.js +5 -0
  27. package/lib/es/locale/fa-IR.js +5 -0
  28. package/lib/es/locale/fr-FR.js +5 -0
  29. package/lib/es/locale/id-ID.js +5 -0
  30. package/lib/es/locale/it-IT.js +5 -0
  31. package/lib/es/locale/ja-JP.js +5 -0
  32. package/lib/es/locale/ko-KR.js +5 -0
  33. package/lib/es/locale/pl-PL.js +5 -0
  34. package/lib/es/locale/pt-BR.js +5 -0
  35. package/lib/es/locale/ru-RU.js +5 -0
  36. package/lib/es/locale/sk-SK.js +5 -0
  37. package/lib/es/locale/vi-VN.js +5 -0
  38. package/lib/es/locale/zh-CN.js +5 -0
  39. package/lib/es/locale/zh-HK.js +5 -0
  40. package/lib/es/locale/zh-TW.js +5 -0
  41. package/lib/index.js +1860 -1522
  42. package/lib/locale/ar-SA.js +5 -0
  43. package/lib/locale/ca-ES.js +5 -0
  44. package/lib/locale/de-DE.js +5 -0
  45. package/lib/locale/en-US.js +5 -0
  46. package/lib/locale/es-ES.js +5 -0
  47. package/lib/locale/fa-IR.js +5 -0
  48. package/lib/locale/fr-FR.js +5 -0
  49. package/lib/locale/id-ID.js +5 -0
  50. package/lib/locale/it-IT.js +5 -0
  51. package/lib/locale/ja-JP.js +5 -0
  52. package/lib/locale/ko-KR.js +5 -0
  53. package/lib/locale/pl-PL.js +5 -0
  54. package/lib/locale/pt-BR.js +5 -0
  55. package/lib/locale/ru-RU.js +5 -0
  56. package/lib/locale/sk-SK.js +5 -0
  57. package/lib/locale/vi-VN.js +5 -0
  58. package/lib/locale/zh-CN.js +5 -0
  59. package/lib/locale/zh-HK.js +5 -0
  60. package/lib/locale/zh-TW.js +5 -0
  61. package/lib/types/commands/commands/insert-shape.command.d.ts +18 -0
  62. package/lib/types/controllers/components.controller.d.ts +22 -0
  63. package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +67 -3
  64. package/lib/types/controllers/{doc-drawing.controller.d.ts → ui.controller.d.ts} +2 -3
  65. package/lib/types/index.d.ts +2 -0
  66. package/lib/types/locale/en-US.d.ts +7 -0
  67. package/lib/types/locale/types.d.ts +18 -0
  68. package/lib/types/menu/image.menu.d.ts +4 -2
  69. package/lib/types/menu/shape.menu.d.ts +26 -0
  70. package/lib/types/views/{printing-float-dom/index.d.ts → DocPrintingFloatDom.d.ts} +3 -1
  71. package/lib/types/views/doc-image-panel/DocDrawingPanel.d.ts +1 -1
  72. package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +1 -1
  73. package/lib/types/views/doc-image-panel/DocDrawingTextWrap.d.ts +1 -1
  74. package/lib/umd/index.js +1 -1
  75. package/lib/umd/locale/ar-SA.js +1 -1
  76. package/lib/umd/locale/ca-ES.js +1 -1
  77. package/lib/umd/locale/de-DE.js +1 -1
  78. package/lib/umd/locale/en-US.js +1 -1
  79. package/lib/umd/locale/es-ES.js +1 -1
  80. package/lib/umd/locale/fa-IR.js +1 -1
  81. package/lib/umd/locale/fr-FR.js +1 -1
  82. package/lib/umd/locale/id-ID.js +1 -1
  83. package/lib/umd/locale/it-IT.js +1 -1
  84. package/lib/umd/locale/ja-JP.js +1 -1
  85. package/lib/umd/locale/ko-KR.js +1 -1
  86. package/lib/umd/locale/pl-PL.js +1 -1
  87. package/lib/umd/locale/pt-BR.js +1 -1
  88. package/lib/umd/locale/ru-RU.js +1 -1
  89. package/lib/umd/locale/sk-SK.js +1 -1
  90. package/lib/umd/locale/vi-VN.js +1 -1
  91. package/lib/umd/locale/zh-CN.js +1 -1
  92. package/lib/umd/locale/zh-HK.js +1 -1
  93. package/lib/umd/locale/zh-TW.js +1 -1
  94. package/package.json +13 -12
package/lib/cjs/index.js CHANGED
@@ -62,7 +62,7 @@ const RemoveDocDrawingCommand = {
62
62
  });
63
63
  memoryCursor.moveCursorTo(startIndex + 1);
64
64
  }
65
- const path = (0, _univerjs_docs_ui.getRichTextEditPath)(documentDataModel, segmentId);
65
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
66
66
  rawActions.push(jsonX.editOp(textX.serialize(), path));
67
67
  for (const block of removeCustomBlocks) {
68
68
  var _documentDataModel$ge3;
@@ -196,7 +196,7 @@ const InsertDocDrawingCommand = {
196
196
  },
197
197
  len: drawings.length
198
198
  });
199
- const path = (0, _univerjs_docs_ui.getRichTextEditPath)(documentDataModel, segmentId);
199
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
200
200
  const placeHolderAction = jsonX.editOp(textX.serialize(), path);
201
201
  rawActions.push(placeHolderAction);
202
202
  for (const drawing of drawings) {
@@ -223,7 +223,7 @@ const InsertDocDrawingCommand = {
223
223
  };
224
224
  function getContentInsertRange(accessor, unitId) {
225
225
  try {
226
- const range = accessor.get(_univerjs_docs_ui.DocContentInsertService).consumeInsertRange(unitId);
226
+ const range = accessor.get(_univerjs_docs.DocContentInsertService).consumeInsertRange(unitId);
227
227
  if (range == null) return null;
228
228
  return {
229
229
  startOffset: range.startOffset,
@@ -307,7 +307,7 @@ const UngroupDocDrawingCommand = {
307
307
  };
308
308
 
309
309
  //#endregion
310
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
310
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
311
311
  function _typeof(o) {
312
312
  "@babel/helpers - typeof";
313
313
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -318,7 +318,7 @@ function _typeof(o) {
318
318
  }
319
319
 
320
320
  //#endregion
321
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
321
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
322
322
  function toPrimitive(t, r) {
323
323
  if ("object" != _typeof(t) || !t) return t;
324
324
  var e = t[Symbol.toPrimitive];
@@ -331,14 +331,14 @@ function toPrimitive(t, r) {
331
331
  }
332
332
 
333
333
  //#endregion
334
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
334
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
335
335
  function toPropertyKey(t) {
336
336
  var i = toPrimitive(t, "string");
337
337
  return "symbol" == _typeof(i) ? i : i + "";
338
338
  }
339
339
 
340
340
  //#endregion
341
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
341
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
342
342
  function _defineProperty(e, r, t) {
343
343
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
344
344
  value: t,
@@ -361,7 +361,7 @@ var DocRefreshDrawingsService = class {
361
361
  };
362
362
 
363
363
  //#endregion
364
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
364
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
365
365
  function __decorateParam(paramIndex, decorator) {
366
366
  return function(target, key) {
367
367
  decorator(target, key, paramIndex);
@@ -369,7 +369,7 @@ function __decorateParam(paramIndex, decorator) {
369
369
  }
370
370
 
371
371
  //#endregion
372
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
372
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
373
373
  function __decorate(decorators, target, key, desc) {
374
374
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
375
375
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -594,6 +594,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
594
594
  zeroLeft: docsLeft
595
595
  });
596
596
  }
597
+ this._updateDrawingsEditStatus();
597
598
  }));
598
599
  }
599
600
  _findSegmentIdByDrawingId(drawingId) {
@@ -619,6 +620,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
619
620
  if (viewModel == null || docDataModel == null) return;
620
621
  const { drawings = {} } = docDataModel.getSnapshot();
621
622
  const isEditBody = viewModel.getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY;
623
+ const isDocInputFocusing = this._docSelectionRenderService.isFocusing;
622
624
  for (const key of Object.keys(drawings)) {
623
625
  const drawing = drawings[key];
624
626
  const objectKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
@@ -630,8 +632,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
630
632
  if (drawingShapes.length) for (const shape of drawingShapes) {
631
633
  scene.detachTransformerFrom(shape);
632
634
  try {
633
- shape.setOpacity(.5);
635
+ shape.setOpacity(isDocInputFocusing ? .5 : 1);
634
636
  } catch (e) {}
637
+ if (!isDocInputFocusing) continue;
635
638
  if (isEditBody && drawing.isMultiTransform !== _univerjs_core.BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE) {
636
639
  if (drawing.allowTransform !== false) scene.attachTransformerTo(shape);
637
640
  try {
@@ -650,6 +653,12 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
650
653
  this.disposeWithMe(viewModel.editAreaChange$.subscribe(() => {
651
654
  this._updateDrawingsEditStatus();
652
655
  }));
656
+ this.disposeWithMe(this._docSelectionRenderService.onFocus$.subscribe(() => {
657
+ this._updateDrawingsEditStatus();
658
+ }));
659
+ this.disposeWithMe(this._docSelectionRenderService.onBlur$.subscribe(() => {
660
+ this._updateDrawingsEditStatus();
661
+ }));
653
662
  this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
654
663
  if (skeleton == null) return;
655
664
  queueMicrotask(() => {
@@ -706,6 +715,69 @@ const InsertDocImageCommand = {
706
715
  }
707
716
  };
708
717
 
718
+ //#endregion
719
+ //#region src/commands/commands/insert-shape.command.ts
720
+ const DOC_SHAPE_FILL = "#3A60F7";
721
+ const DOC_SHAPE_STROKE = "#1D3EA6";
722
+ function createShapeSvgSource(shape, width, height) {
723
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" fill="none">${shape === "ellipse" ? `<ellipse cx="${width / 2}" cy="${height / 2}" rx="${(width - 8) / 2}" ry="${(height - 8) / 2}" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />` : `<rect x="4" y="4" width="${width - 8}" height="${height - 8}" rx="14" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />`}</svg>`;
724
+ return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
725
+ }
726
+ function createDefaultDocTransform(width, height) {
727
+ return {
728
+ size: {
729
+ width,
730
+ height
731
+ },
732
+ positionH: {
733
+ relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
734
+ posOffset: 0
735
+ },
736
+ positionV: {
737
+ relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
738
+ posOffset: 0
739
+ },
740
+ angle: 0
741
+ };
742
+ }
743
+ function createShapeInsertCommand(shape, width, height, id) {
744
+ return {
745
+ id,
746
+ type: _univerjs_core.CommandType.COMMAND,
747
+ handler: async (accessor) => {
748
+ var _univerInstanceServic;
749
+ const commandService = accessor.get(_univerjs_core.ICommandService);
750
+ const unitId = (_univerInstanceServic = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
751
+ if (!unitId) return false;
752
+ const docTransform = createDefaultDocTransform(width, height);
753
+ return commandService.executeCommand(InsertDocDrawingCommand.id, {
754
+ unitId,
755
+ drawings: [{
756
+ unitId,
757
+ subUnitId: unitId,
758
+ drawingId: (0, _univerjs_core.generateRandomId)(6),
759
+ drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
760
+ imageSourceType: _univerjs_drawing.ImageSourceType.BASE64,
761
+ source: createShapeSvgSource(shape, width, height),
762
+ transform: (0, _univerjs_docs_ui.docDrawingPositionToTransform)(docTransform),
763
+ docTransform,
764
+ behindDoc: _univerjs_core.BooleanNumber.FALSE,
765
+ title: "",
766
+ description: "",
767
+ layoutType: _univerjs_core.PositionedObjectLayoutType.INLINE,
768
+ wrapText: _univerjs_core.WrapTextType.BOTH_SIDES,
769
+ distB: 0,
770
+ distL: 0,
771
+ distR: 0,
772
+ distT: 0
773
+ }]
774
+ });
775
+ }
776
+ };
777
+ }
778
+ const InsertDocRectangleShapeCommand = createShapeInsertCommand("rectangle", 144, 96, "doc.command.insert-float-shape.rectangle");
779
+ const InsertDocEllipseShapeCommand = createShapeInsertCommand("ellipse", 112, 112, "doc.command.insert-float-shape.ellipse");
780
+
709
781
  //#endregion
710
782
  //#region src/commands/commands/update-doc-drawing.command.ts
711
783
  const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
@@ -790,7 +862,7 @@ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPa
790
862
  });
791
863
  }
792
864
  if (offset !== oldOffset) {
793
- const path = (0, _univerjs_docs_ui.getRichTextEditPath)(documentDataModel, oldSegmentId);
865
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, oldSegmentId);
794
866
  const action = jsonX.editOp(textX.serialize(), path);
795
867
  rawActions.push(action);
796
868
  }
@@ -803,7 +875,7 @@ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPa
803
875
  t: _univerjs_core.TextXActionType.DELETE,
804
876
  len: 1
805
877
  });
806
- let path = (0, _univerjs_docs_ui.getRichTextEditPath)(documentDataModel, oldSegmentId);
878
+ let path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, oldSegmentId);
807
879
  let action = jsonX.editOp(textX.serialize(), path);
808
880
  rawActions.push(action);
809
881
  textX.empty();
@@ -822,7 +894,7 @@ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPa
822
894
  },
823
895
  len: 1
824
896
  });
825
- path = (0, _univerjs_docs_ui.getRichTextEditPath)(documentDataModel, segmentId);
897
+ path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
826
898
  action = jsonX.editOp(textX.serialize(), path);
827
899
  rawActions.push(action);
828
900
  docSelectionRenderManager.setSegment(segmentId);
@@ -1625,23 +1697,95 @@ function ImageMenuFactory(accessor) {
1625
1697
  icon: "AddImageIcon",
1626
1698
  tooltip: "docs-drawing-ui.title",
1627
1699
  disabled$: getDisableWhenSelectionInTableObservable(accessor),
1628
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC, void 0, _univerjs_core.DOCS_ZEN_EDITOR_UNIT_ID_KEY)
1700
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1629
1701
  };
1630
1702
  }
1631
- function UploadFloatImageMenuFactory(_accessor) {
1703
+ function UploadFloatImageMenuFactory(accessor) {
1632
1704
  return {
1633
1705
  id: IMAGE_MENU_UPLOAD_FLOAT_ID,
1634
1706
  title: "docs-drawing-ui.upload.float",
1635
1707
  type: _univerjs_ui.MenuItemType.BUTTON,
1636
1708
  icon: "AddImageIcon",
1637
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(_accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC, void 0, _univerjs_core.DOCS_ZEN_EDITOR_UNIT_ID_KEY)
1709
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1710
+ };
1711
+ }
1712
+ function UploadFloatImageBelowMenuFactory(accessor) {
1713
+ return {
1714
+ id: `${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`,
1715
+ commandId: IMAGE_MENU_UPLOAD_FLOAT_ID,
1716
+ title: "docs-drawing-ui.upload.float",
1717
+ type: _univerjs_ui.MenuItemType.BUTTON,
1718
+ icon: "AddImageIcon",
1719
+ params: { paragraphMenuPlacement: "below" },
1720
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1721
+ };
1722
+ }
1723
+
1724
+ //#endregion
1725
+ //#region src/menu/shape.menu.ts
1726
+ const DOCS_SHAPE_MENU_ID = "doc.command.menu-insert-shape";
1727
+ const DOCS_SHAPE_BELOW_MENU_ID = "doc.command.menu-insert-shape.below";
1728
+ function ShapeMenuFactory(accessor) {
1729
+ return {
1730
+ id: DOCS_SHAPE_MENU_ID,
1731
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
1732
+ icon: "ShapeIcon",
1733
+ title: "docs-drawing-ui.shape.insert.title",
1734
+ tooltip: "docs-drawing-ui.shape.insert.title",
1735
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1736
+ };
1737
+ }
1738
+ function ShapeBelowMenuFactory(accessor) {
1739
+ return {
1740
+ id: DOCS_SHAPE_BELOW_MENU_ID,
1741
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
1742
+ icon: "ShapeIcon",
1743
+ title: "docs-drawing-ui.shape.insert.title",
1744
+ tooltip: "docs-drawing-ui.shape.insert.title",
1745
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1746
+ };
1747
+ }
1748
+ function InsertRectangleShapeMenuFactory(accessor) {
1749
+ return {
1750
+ id: InsertDocRectangleShapeCommand.id,
1751
+ title: "docs-drawing-ui.shape.insert.rectangle",
1752
+ type: _univerjs_ui.MenuItemType.BUTTON,
1753
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1754
+ };
1755
+ }
1756
+ function InsertEllipseShapeMenuFactory(accessor) {
1757
+ return {
1758
+ id: InsertDocEllipseShapeCommand.id,
1759
+ title: "docs-drawing-ui.shape.insert.ellipse",
1760
+ type: _univerjs_ui.MenuItemType.BUTTON,
1761
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1762
+ };
1763
+ }
1764
+ function InsertRectangleShapeBelowMenuFactory(accessor) {
1765
+ return {
1766
+ id: `${InsertDocRectangleShapeCommand.id}.below`,
1767
+ commandId: InsertDocRectangleShapeCommand.id,
1768
+ title: "docs-drawing-ui.shape.insert.rectangle",
1769
+ type: _univerjs_ui.MenuItemType.BUTTON,
1770
+ params: { paragraphMenuPlacement: "below" },
1771
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1772
+ };
1773
+ }
1774
+ function InsertEllipseShapeBelowMenuFactory(accessor) {
1775
+ return {
1776
+ id: `${InsertDocEllipseShapeCommand.id}.below`,
1777
+ commandId: InsertDocEllipseShapeCommand.id,
1778
+ title: "docs-drawing-ui.shape.insert.ellipse",
1779
+ type: _univerjs_ui.MenuItemType.BUTTON,
1780
+ params: { paragraphMenuPlacement: "below" },
1781
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
1638
1782
  };
1639
1783
  }
1640
1784
 
1641
1785
  //#endregion
1642
1786
  //#region package.json
1643
1787
  var name = "@univerjs/docs-drawing-ui";
1644
- var version = "0.25.0";
1788
+ var version = "1.0.0-alpha.0";
1645
1789
 
1646
1790
  //#endregion
1647
1791
  //#region src/config/config.ts
@@ -1665,1587 +1809,1782 @@ const configSymbol = Symbol(DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY);
1665
1809
  const defaultPluginConfig = {};
1666
1810
 
1667
1811
  //#endregion
1668
- //#region src/controllers/doc-drawing-notification.controller.ts
1669
- function getAddOrRemoveDrawings(actions) {
1670
- if (_univerjs_core.JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
1671
- const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
1672
- if (drawingsOp == null || !Array.isArray(drawingsOp) || drawingsOp.length < 3) return null;
1673
- if (typeof drawingsOp[1] === "string" && typeof drawingsOp[2] !== "object") return null;
1674
- if (Array.isArray(drawingsOp[1]) && typeof drawingsOp[1][1] !== "object") return null;
1675
- const drawings = [];
1676
- if (Array.isArray(drawingsOp === null || drawingsOp === void 0 ? void 0 : drawingsOp[1])) {
1677
- for (const op of drawingsOp) if (Array.isArray(op)) {
1678
- var _ref, _ref2;
1679
- drawings.push({
1680
- type: (op === null || op === void 0 || (_ref = op[1]) === null || _ref === void 0 ? void 0 : _ref.i) ? "add" : "remove",
1681
- drawingId: op === null || op === void 0 ? void 0 : op[0],
1682
- drawing: op === null || op === void 0 || (_ref2 = op[1]) === null || _ref2 === void 0 ? void 0 : _ref2.i
1683
- });
1812
+ //#region src/views/doc-image-panel/DocDrawingPosition.tsx
1813
+ const MIN_OFFSET = -1e3;
1814
+ const MAX_OFFSET = 1e3;
1815
+ const DocDrawingPosition = (props) => {
1816
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1817
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1818
+ const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
1819
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1820
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1821
+ const { drawings } = props;
1822
+ const drawingParam = drawings[0];
1823
+ if (drawingParam == null) return;
1824
+ const { unitId } = drawingParam;
1825
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
1826
+ const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
1827
+ const renderObject = renderManagerService.getRenderById(unitId);
1828
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1829
+ if (scene == null) return;
1830
+ const transformer = scene.getTransformerByCreate();
1831
+ const HORIZONTAL_RELATIVE_FROM = [
1832
+ {
1833
+ label: localeService.t("docs-drawing-ui.image-position.column"),
1834
+ value: String(_univerjs_core.ObjectRelativeFromH.COLUMN)
1835
+ },
1836
+ {
1837
+ label: localeService.t("docs-drawing-ui.image-position.page"),
1838
+ value: String(_univerjs_core.ObjectRelativeFromH.PAGE)
1839
+ },
1840
+ {
1841
+ label: localeService.t("docs-drawing-ui.image-position.margin"),
1842
+ value: String(_univerjs_core.ObjectRelativeFromH.MARGIN)
1684
1843
  }
1685
- } else {
1686
- var _drawingsOp$, _drawingsOp$2;
1687
- drawings.push({
1688
- type: ((_drawingsOp$ = drawingsOp[2]) === null || _drawingsOp$ === void 0 ? void 0 : _drawingsOp$.i) ? "add" : "remove",
1689
- drawingId: drawingsOp[1],
1690
- drawing: (_drawingsOp$2 = drawingsOp[2]) === null || _drawingsOp$2 === void 0 ? void 0 : _drawingsOp$2.i
1691
- });
1692
- }
1693
- return drawings;
1694
- }
1695
- function getReOrderedDrawings(actions) {
1696
- if (!Array.isArray(actions) || actions.length < 3 || actions[0] !== "drawingsOrder") return [];
1697
- const drawingIndexes = [];
1698
- for (let i = 1; i < actions.length; i++) {
1699
- const action = actions[i];
1700
- if (Array.isArray(action) && typeof action[0] === "number" && typeof action[1] === "object") drawingIndexes.push(action[0]);
1701
- else {
1702
- drawingIndexes.length = 0;
1703
- break;
1844
+ ];
1845
+ const VERTICAL_RELATIVE_FROM = [
1846
+ {
1847
+ label: localeService.t("docs-drawing-ui.image-position.line"),
1848
+ value: String(_univerjs_core.ObjectRelativeFromV.LINE),
1849
+ disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
1850
+ },
1851
+ {
1852
+ label: localeService.t("docs-drawing-ui.image-position.page"),
1853
+ value: String(_univerjs_core.ObjectRelativeFromV.PAGE),
1854
+ disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
1855
+ },
1856
+ {
1857
+ label: localeService.t("docs-drawing-ui.image-position.margin"),
1858
+ value: String(_univerjs_core.ObjectRelativeFromV.MARGIN),
1859
+ disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
1860
+ },
1861
+ {
1862
+ label: localeService.t("docs-drawing-ui.image-position.paragraph"),
1863
+ value: String(_univerjs_core.ObjectRelativeFromV.PARAGRAPH)
1704
1864
  }
1705
- }
1706
- return drawingIndexes;
1707
- }
1708
- let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends _univerjs_core.Disposable {
1709
- constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
1710
- super();
1711
- this._univerInstanceService = _univerInstanceService;
1712
- this._commandService = _commandService;
1713
- this._drawingManagerService = _drawingManagerService;
1714
- this._docDrawingService = _docDrawingService;
1715
- this._renderManagerService = _renderManagerService;
1716
- this._initialize();
1717
- }
1718
- _initialize() {
1719
- this._commandExecutedListener();
1720
- }
1721
- _commandExecutedListener() {
1722
- this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1723
- if (command.id !== _univerjs_docs.RichTextEditingMutation.id) return;
1724
- const { unitId, actions, isSync, syncer } = command.params;
1725
- const addOrRemoveDrawings = getAddOrRemoveDrawings(actions);
1726
- if (addOrRemoveDrawings != null) for (const { type, drawingId, drawing } of addOrRemoveDrawings) {
1727
- if (isSync && (drawing === null || drawing === void 0 ? void 0 : drawing.unitId) === syncer) continue;
1728
- if (type === "add") this._addDrawings(unitId, [drawing]);
1729
- else this._removeDrawings(unitId, [drawingId]);
1730
- }
1731
- }));
1732
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1733
- if (command.id !== _univerjs_docs.RichTextEditingMutation.id) return;
1734
- const { unitId, actions } = command.params;
1735
- if (getReOrderedDrawings(actions).length > 0) this._updateDrawingsOrder(unitId);
1736
- }));
1737
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1738
- var _this$_univerInstance;
1739
- if (command.id !== _univerjs_core.UndoCommand.id && command.id !== _univerjs_core.RedoCommand.id) return;
1740
- const unitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUniverDocInstance()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
1741
- const focusedDrawings = this._drawingManagerService.getFocusDrawings();
1742
- if (unitId == null || focusedDrawings.length === 0) return;
1743
- const renderObject = this._renderManagerService.getRenderById(unitId);
1744
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1745
- if (scene == null) return false;
1746
- scene.getTransformerByCreate().refreshControls();
1747
- }));
1748
- }
1749
- _addDrawings(unitId, drawings) {
1750
- const drawingManagerService = this._drawingManagerService;
1751
- const docDrawingService = this._docDrawingService;
1752
- const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchAddOp(drawings);
1753
- drawingManagerService.applyJson1(unitId, subUnitId, op);
1754
- docDrawingService.applyJson1(unitId, subUnitId, op);
1755
- drawingManagerService.addNotification(objects);
1756
- docDrawingService.addNotification(objects);
1757
- }
1758
- _removeDrawings(unitId, drawingIds) {
1759
- const drawingManagerService = this._drawingManagerService;
1760
- const docDrawingService = this._docDrawingService;
1761
- const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchRemoveOp(drawingIds.map((drawingId) => {
1865
+ ];
1866
+ const [disabled, setDisabled] = (0, react.useState)(true);
1867
+ const [hPosition, setHPosition] = (0, react.useState)({
1868
+ relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
1869
+ posOffset: 0
1870
+ });
1871
+ const [vPosition, setVPosition] = (0, react.useState)({
1872
+ relativeFrom: _univerjs_core.ObjectRelativeFromV.PAGE,
1873
+ posOffset: 0
1874
+ });
1875
+ const [followTextMove, setFollowTextMove] = (0, react.useState)(true);
1876
+ const [showPanel, setShowPanel] = (0, react.useState)(true);
1877
+ function handlePositionChange(direction, value) {
1878
+ var _renderManagerService;
1879
+ if (direction === "positionH") setHPosition(value);
1880
+ else setVPosition(value);
1881
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1882
+ if (focusDrawings.length === 0) return;
1883
+ const drawings = focusDrawings.map((drawing) => {
1762
1884
  return {
1763
- unitId,
1764
- subUnitId: unitId,
1765
- drawingId
1885
+ unitId: drawing.unitId,
1886
+ subUnitId: drawing.subUnitId,
1887
+ drawingId: drawing.drawingId
1766
1888
  };
1767
- }));
1768
- drawingManagerService.applyJson1(unitId, subUnitId, op);
1769
- docDrawingService.applyJson1(unitId, subUnitId, op);
1770
- drawingManagerService.removeNotification(objects);
1771
- docDrawingService.removeNotification(objects);
1772
- }
1773
- _updateDrawingsOrder(unitId) {
1774
- const documentDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
1775
- if (documentDataModel == null) return;
1776
- const drawingsOrder = documentDataModel.getSnapshot().drawingsOrder;
1777
- if (drawingsOrder == null) return;
1778
- const drawingManagerService = this._drawingManagerService;
1779
- const docDrawingService = this._docDrawingService;
1780
- drawingManagerService.setDrawingOrder(unitId, unitId, drawingsOrder);
1781
- docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
1782
- const objects = {
1783
- unitId,
1784
- subUnitId: unitId,
1785
- drawingIds: drawingsOrder
1786
- };
1787
- drawingManagerService.orderNotification(objects);
1788
- docDrawingService.orderNotification(objects);
1889
+ });
1890
+ commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
1891
+ unitId: focusDrawings[0].unitId,
1892
+ subUnitId: focusDrawings[0].unitId,
1893
+ drawings: drawings.map((drawing) => ({
1894
+ drawingId: drawing.drawingId,
1895
+ key: direction,
1896
+ value
1897
+ }))
1898
+ });
1899
+ const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs_ui.DocSelectionRenderService);
1900
+ if (docSelectionRenderService) docSelectionRenderService.blur();
1901
+ transformer.refreshControls();
1789
1902
  }
1790
- };
1791
- DocDrawingAddRemoveController = __decorate([
1792
- __decorateParam(0, _univerjs_core.IUniverInstanceService),
1793
- __decorateParam(1, _univerjs_core.ICommandService),
1794
- __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
1795
- __decorateParam(3, _univerjs_docs_drawing.IDocDrawingService),
1796
- __decorateParam(4, _univerjs_engine_render.IRenderManagerService)
1797
- ], DocDrawingAddRemoveController);
1798
-
1799
- //#endregion
1800
- //#region src/views/printing-float-dom/index.tsx
1801
- const DocPrintingFloatDom = (props) => {
1802
- const { floatDomInfos, scene, offset, bound } = props;
1803
- const width = bound.right - bound.left;
1804
- const height = bound.bottom - bound.top;
1805
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1806
- className: "univer-absolute univer-left-0 univer-top-0",
1807
- children: (0, react.useMemo)(() => floatDomInfos.map((info) => {
1808
- const { width = 0, height = 0, left = 0, top = 0 } = info.transform;
1809
- const domPos = calcDocFloatDomPositionByRect({
1810
- left,
1811
- right: left + width,
1812
- top,
1813
- bottom: top + height
1814
- }, scene);
1815
- const floatDom = {
1816
- position$: new rxjs.BehaviorSubject(domPos),
1817
- position: domPos,
1818
- id: info.drawingId,
1819
- componentKey: info.componentKey,
1820
- onPointerMove: () => {},
1821
- onPointerDown: () => {},
1822
- onPointerUp: () => {},
1823
- onWheel: () => {},
1824
- unitId: info.unitId,
1825
- data: info.data
1826
- };
1827
- return [info.drawingId, floatDom];
1828
- }).filter(([_, floatDom]) => !(floatDom.position.endX < 0 || floatDom.position.endY < 0 || floatDom.position.startX > width || floatDom.position.startY > height)), [
1829
- floatDomInfos,
1830
- scene,
1831
- offset,
1832
- width,
1833
- height
1834
- ]).map(([id, floatDom]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.PrintFloatDomSingle, {
1835
- layer: floatDom,
1836
- id,
1837
- position: floatDom.position
1838
- }, id))
1839
- });
1840
- };
1841
-
1842
- //#endregion
1843
- //#region src/controllers/doc-drawing-printing.controller.tsx
1844
- let DocDrawingPrintingController = class DocDrawingPrintingController extends _univerjs_core.Disposable {
1845
- constructor(_docPrintInterceptorService, _drawingRenderService, _drawingManagerService, _componetManager, _injector) {
1846
- super();
1847
- this._docPrintInterceptorService = _docPrintInterceptorService;
1848
- this._drawingRenderService = _drawingRenderService;
1849
- this._drawingManagerService = _drawingManagerService;
1850
- this._componetManager = _componetManager;
1851
- this._injector = _injector;
1852
- this._initPrinting();
1853
- this._initPrintingDom();
1854
- }
1855
- _initPrinting() {
1856
- this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (_param, pos, next) => {
1857
- const { unitId, scene } = pos;
1858
- const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
1859
- const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
1860
- if (subUnitData) subUnitData.order.forEach((id) => {
1861
- const drawing = subUnitData.data[id];
1862
- if (drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_CHART && drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) this._drawingRenderService.renderDrawing(drawing, scene);
1863
- });
1864
- return next();
1865
- } }));
1866
- }
1867
- _initPrintingDom() {
1868
- this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT, { handler: (disposableCollection, pos, next) => {
1869
- const { unitId } = pos;
1870
- const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
1871
- const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
1872
- if (subUnitData) {
1873
- const floatDomInfos = subUnitData.order.map((id) => {
1874
- const drawing = subUnitData.data[id];
1875
- if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART) return {
1876
- ...drawing,
1877
- componentKey: this._componetManager.get(_univerjs_core.DOC_DRAWING_PRINTING_COMPONENT_KEY)
1878
- };
1879
- if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_DOM) {
1880
- const printingComponentKey = this._docPrintInterceptorService.getPrintComponent(drawing.componentKey);
1881
- return {
1882
- ...drawing,
1883
- componentKey: this._componetManager.get(printingComponentKey || drawing.componentKey)
1884
- };
1885
- }
1886
- return null;
1887
- }).filter(Boolean);
1888
- (0, _univerjs_design.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)((0, _univerjs_ui.connectInjector)(DocPrintingFloatDom, this._injector), {
1889
- unitId,
1890
- floatDomInfos,
1891
- scene: pos.scene,
1892
- skeleton: pos.skeleton,
1893
- offset: pos.offset,
1894
- bound: pos.bound
1895
- }), pos.root);
1896
- disposableCollection === null || disposableCollection === void 0 || disposableCollection.add(() => {
1897
- (0, _univerjs_design.unmount)(pos.root);
1898
- });
1899
- return next(disposableCollection);
1900
- }
1901
- } }));
1902
- }
1903
- };
1904
- DocDrawingPrintingController = __decorate([
1905
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocPrintInterceptorService)),
1906
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_drawing_ui.DrawingRenderService)),
1907
- __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
1908
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
1909
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
1910
- ], DocDrawingPrintingController);
1911
-
1912
- //#endregion
1913
- //#region src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
1914
- function getDocsTableCellDrawingOffset(unitId, table, row, cell) {
1915
- const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(table.tableId).tableId;
1916
- const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, sourceTableId);
1917
- const scrollLeft = viewport && viewport.contentWidth > viewport.viewportWidth ? viewport.scrollLeft : 0;
1918
- return {
1919
- left: table.left + cell.left - scrollLeft + cell.marginLeft,
1920
- top: table.top + row.top + cell.marginTop
1921
- };
1922
- }
1923
- let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateController extends _univerjs_core.Disposable {
1924
- constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
1925
- super();
1926
- this._context = _context;
1927
- this._docSkeletonManagerService = _docSkeletonManagerService;
1928
- this._commandService = _commandService;
1929
- this._editorService = _editorService;
1930
- this._drawingManagerService = _drawingManagerService;
1931
- this._docRefreshDrawingsService = _docRefreshDrawingsService;
1932
- this._univerInstanceService = _univerInstanceService;
1933
- this._lifecycleService = _lifecycleService;
1934
- _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
1935
- this._initialize();
1936
- this._commandExecutedListener();
1937
- }
1938
- _initialize() {
1939
- this._initialRenderRefresh();
1940
- this._drawingInitializeListener();
1941
- this._initResize();
1942
- }
1943
- _initialRenderRefresh() {
1944
- this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
1945
- if (documentSkeleton == null) return;
1946
- this._refreshDrawing(documentSkeleton);
1947
- }));
1948
- this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
1949
- if (skeleton == null) return;
1950
- this._refreshDrawing(skeleton);
1951
- }));
1952
- }
1953
- _commandExecutedListener() {
1954
- const updateCommandList = [_univerjs_docs.RichTextEditingMutation.id, _univerjs_docs_ui.SetDocZoomRatioOperation.id];
1955
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1956
- if (updateCommandList.includes(command.id)) {
1957
- const { unitId: commandUnitId } = command.params;
1958
- const { unitId, mainComponent } = this._context;
1959
- if (commandUnitId !== unitId) return;
1960
- const skeleton = this._docSkeletonManagerService.getSkeleton();
1961
- if (skeleton == null) return;
1962
- if (this._editorService.isEditor(unitId) && unitId !== _univerjs_core.DOCS_ZEN_EDITOR_UNIT_ID_KEY) {
1963
- mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
1964
- return;
1965
- }
1966
- this._refreshDrawing(skeleton);
1967
- }
1968
- }));
1969
- }
1970
- _initResize() {
1971
- this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.engine.onTransformChange$).pipe((0, rxjs.filter)((evt) => evt.type === _univerjs_engine_render.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize), (0, rxjs.debounceTime)(16)).subscribe(() => {
1972
- var _scene$getTransformer;
1973
- const skeleton = this._docSkeletonManagerService.getSkeleton();
1974
- const { scene } = this._context;
1975
- (_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.refreshControls();
1976
- this._refreshDrawing(skeleton);
1977
- }));
1978
- }
1979
- _refreshDrawing(skeleton) {
1903
+ function handleHorizontalRelativeFromChange(value) {
1904
+ var _renderManagerService2;
1905
+ const prevRelativeFrom = hPosition.relativeFrom;
1906
+ const prevPosOffset = hPosition.posOffset;
1907
+ const relativeFrom = Number(value);
1908
+ if (prevRelativeFrom === relativeFrom) return;
1909
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1910
+ if (focusDrawings.length === 0) return;
1911
+ const drawingId = focusDrawings[0].drawingId;
1912
+ const unitId = focusDrawings[0].unitId;
1913
+ let drawing = null;
1914
+ let pageMarginLeft = 0;
1915
+ const skeleton = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
1980
1916
  const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
1981
- const { mainComponent, unitId } = this._context;
1982
- const documentComponent = mainComponent;
1983
- if (!skeletonData) return;
1984
- const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;
1917
+ if (skeletonData == null) return;
1985
1918
  const { pages, skeHeaders, skeFooters } = skeletonData;
1986
- const updateDrawingMap = {};
1987
- this._liquid.reset();
1988
- /**
1989
- * TODO: @DR-Univer We should not refresh all floating elements, but instead make a diff.
1990
- */
1991
- for (let i = 0, len = pages.length; i < len; i++) {
1992
- const page = pages[i];
1993
- const { headerId, footerId, pageWidth } = page;
1994
- if (headerId) {
1995
- var _skeHeaders$get;
1996
- const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
1997
- if (headerPage) {
1998
- this._calculateDrawingPosition(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
1999
- this._calculateTableCellDrawingPositions(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
2000
- }
1919
+ for (const page of pages) {
1920
+ var _skeHeaders$get, _skeFooters$get;
1921
+ const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
1922
+ if (skeDrawings.has(drawingId)) {
1923
+ drawing = skeDrawings.get(drawingId);
1924
+ pageMarginLeft = marginLeft;
1925
+ break;
2001
1926
  }
2002
- if (footerId) {
2003
- var _skeFooters$get;
2004
- const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2005
- if (footerPage) {
2006
- const footerTop = page.pageHeight - page.marginBottom + footerPage.marginTop;
2007
- this._calculateDrawingPosition(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2008
- this._calculateTableCellDrawingPositions(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2009
- }
1927
+ const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
1928
+ if (headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.has(drawingId)) {
1929
+ drawing = headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.get(drawingId);
1930
+ pageMarginLeft = marginLeft;
1931
+ break;
1932
+ }
1933
+ const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
1934
+ if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
1935
+ drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
1936
+ pageMarginLeft = marginLeft;
1937
+ break;
2010
1938
  }
2011
- this._calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2012
- this._calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2013
- this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2014
1939
  }
2015
- const updateDrawings = Object.values(updateDrawingMap);
2016
- const nonMultiDrawings = updateDrawings.filter((drawing) => !drawing.isMultiTransform);
2017
- const multiDrawings = updateDrawings.filter((drawing) => drawing.isMultiTransform);
2018
- if (nonMultiDrawings.length > 0) this._drawingManagerService.refreshTransform(nonMultiDrawings);
2019
- this._handleMultiDrawingsTransform(multiDrawings);
2020
- }
2021
- _handleMultiDrawingsTransform(multiDrawings) {
2022
- const { scene, unitId } = this._context;
2023
- const transformer = scene.getTransformerByCreate();
2024
- multiDrawings.forEach((updateParam) => {
2025
- const param = this._drawingManagerService.getDrawingByParam(updateParam);
2026
- if (param == null) return;
2027
- param.transform = updateParam.transform;
2028
- param.transforms = updateParam.transforms;
2029
- param.isMultiTransform = updateParam.isMultiTransform;
1940
+ if (drawing == null) return;
1941
+ let delta = 0;
1942
+ if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) delta -= drawing.columnLeft;
1943
+ else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) delta -= pageMarginLeft;
1944
+ if (relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) delta += drawing.columnLeft;
1945
+ else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) delta += pageMarginLeft;
1946
+ else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.PAGE) {}
1947
+ handlePositionChange("positionH", {
1948
+ relativeFrom,
1949
+ posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2030
1950
  });
2031
- const selectedObjectKeys = [...transformer.getSelectedObjectMap().keys()];
2032
- const allMultiDrawings = Object.values(this._drawingManagerService.getDrawingData(unitId, unitId)).filter((drawing) => drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE);
2033
- this._drawingManagerService.removeNotification(allMultiDrawings);
2034
- if (multiDrawings.length > 0) this._drawingManagerService.addNotification(multiDrawings);
2035
- for (const key of selectedObjectKeys) {
2036
- const drawingShape = scene.getObject(key);
2037
- if (drawingShape) transformer.setSelectedControl(drawingShape);
2038
- }
2039
1951
  }
2040
- _calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft) {
2041
- const { skeDrawings } = page;
2042
- this._liquid.translatePagePadding({
2043
- marginTop,
2044
- marginLeft
2045
- });
2046
- skeDrawings.forEach((drawing) => {
2047
- const { aLeft, aTop, height, width, angle, drawingId, drawingOrigin } = drawing;
2048
- const behindText = drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === _univerjs_core.BooleanNumber.TRUE;
2049
- const { isMultiTransform = _univerjs_core.BooleanNumber.FALSE } = drawingOrigin;
2050
- const transform = {
2051
- left: aLeft + docsLeft + this._liquid.x,
2052
- top: aTop + docsTop + this._liquid.y,
2053
- width,
2054
- height,
2055
- angle
2056
- };
2057
- if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
2058
- unitId,
2059
- subUnitId: unitId,
2060
- drawingId,
2061
- behindText,
2062
- transform,
2063
- transforms: [transform],
2064
- isMultiTransform
2065
- };
2066
- else if (isMultiTransform === _univerjs_core.BooleanNumber.TRUE) updateDrawingMap[drawingId].transforms.push(transform);
2067
- });
2068
- this._liquid.restorePagePadding({
2069
- marginTop,
2070
- marginLeft
1952
+ function handleVerticalRelativeFromChange(value) {
1953
+ var _renderManagerService3, _renderManagerService4, _documentDataModel$ge, _glyph$parent, _column$parent;
1954
+ const prevRelativeFrom = vPosition.relativeFrom;
1955
+ const prevPosOffset = vPosition.posOffset;
1956
+ const relativeFrom = Number(value);
1957
+ if (prevRelativeFrom === relativeFrom) return;
1958
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1959
+ if (focusDrawings.length === 0) return;
1960
+ const { drawingId, unitId } = focusDrawings[0];
1961
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
1962
+ const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
1963
+ const docSelectionRenderService = (_renderManagerService4 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService4 === void 0 ? void 0 : _renderManagerService4.with(_univerjs_docs_ui.DocSelectionRenderService);
1964
+ const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
1965
+ const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
1966
+ const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId).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);
1967
+ if (drawing == null || skeleton == null || docSelectionRenderService == null) return;
1968
+ const { startIndex } = drawing;
1969
+ const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
1970
+ const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
1971
+ const column = line === null || line === void 0 ? void 0 : line.parent;
1972
+ 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);
1973
+ const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
1974
+ if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) return;
1975
+ let delta = 0;
1976
+ if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH) delta -= paragraphStartLine.top;
1977
+ else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) delta -= line.top;
1978
+ else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.PAGE) delta += page.marginTop;
1979
+ if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH) delta += paragraphStartLine.top;
1980
+ else if (relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) delta += line.top;
1981
+ else if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PAGE) delta -= page.marginTop;
1982
+ handlePositionChange("positionV", {
1983
+ relativeFrom,
1984
+ posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2071
1985
  });
2072
1986
  }
2073
- _calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, baseMarginTop, baseMarginLeft) {
2074
- var _page$skeTables;
2075
- (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
2076
- table.rows.forEach((row) => {
2077
- row.cells.forEach((cell) => {
2078
- const cellOffset = getDocsTableCellDrawingOffset(unitId, table, row, cell);
2079
- const marginTop = baseMarginTop + cellOffset.top;
2080
- const marginLeft = baseMarginLeft + cellOffset.left;
2081
- this._calculateDrawingPosition(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2082
- this._calculateTableCellDrawingPositions(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2083
- });
2084
- });
2085
- });
1987
+ function updateState(drawingParam) {
1988
+ var _snapshot$drawings;
1989
+ const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
1990
+ const drawing = snapshot === null || snapshot === void 0 || (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingParam.drawingId];
1991
+ if (drawing == null) return;
1992
+ const { layoutType } = drawing;
1993
+ const { positionH, positionV } = drawing.docTransform;
1994
+ setHPosition(positionH);
1995
+ setVPosition(positionV);
1996
+ setDisabled(layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE);
1997
+ setFollowTextMove(positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE);
2086
1998
  }
2087
- _drawingInitializeListener() {
2088
- const init = () => {
2089
- const skeleton = this._docSkeletonManagerService.getSkeleton();
2090
- if (skeleton == null) return;
2091
- this._refreshDrawing(skeleton);
2092
- this._drawingManagerService.initializeNotification(this._context.unitId);
2093
- };
2094
- if (this._lifecycleService.stage >= _univerjs_core.LifecycleStages.Rendered) if (this._docSkeletonManagerService.getSkeleton()) init();
2095
- else setTimeout(init, 500);
2096
- else this.disposeWithMe(this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((stage) => stage === _univerjs_core.LifecycleStages.Rendered)).subscribe(init));
1999
+ function updateFocusDrawingState() {
2000
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2001
+ if (focusDrawings.length === 0) return;
2002
+ updateState(focusDrawings[0]);
2003
+ }
2004
+ function handleFollowTextMoveCheck(val) {
2005
+ setFollowTextMove(val);
2006
+ handleVerticalRelativeFromChange(val ? String(_univerjs_core.ObjectRelativeFromV.PARAGRAPH) : String(_univerjs_core.ObjectRelativeFromV.PAGE));
2097
2007
  }
2008
+ (0, react.useEffect)(() => {
2009
+ updateFocusDrawingState();
2010
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2011
+ if (drawingParams.length === 0) {
2012
+ setShowPanel(false);
2013
+ return;
2014
+ }
2015
+ setShowPanel(true);
2016
+ updateState(drawingParams[0]);
2017
+ });
2018
+ const mutationListener = commandService.onCommandExecuted(async (command) => {
2019
+ if (command.id === _univerjs_docs.RichTextEditingMutation.id) updateFocusDrawingState();
2020
+ });
2021
+ return () => {
2022
+ subscription.unsubscribe();
2023
+ mutationListener.dispose();
2024
+ };
2025
+ }, []);
2026
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2027
+ className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2028
+ children: [
2029
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
2030
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2031
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.title") })
2032
+ }),
2033
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2034
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2035
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
2036
+ }),
2037
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2038
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2039
+ 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, {
2040
+ min: MIN_OFFSET,
2041
+ max: MAX_OFFSET,
2042
+ precision: 1,
2043
+ disabled,
2044
+ value: hPosition.posOffset,
2045
+ onChange: (val) => {
2046
+ handlePositionChange("positionH", {
2047
+ relativeFrom: hPosition.relativeFrom,
2048
+ posOffset: val
2049
+ });
2050
+ }
2051
+ })] }), /* @__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, {
2052
+ value: String(hPosition.relativeFrom),
2053
+ disabled,
2054
+ options: HORIZONTAL_RELATIVE_FROM,
2055
+ onChange: handleHorizontalRelativeFromChange
2056
+ })] })]
2057
+ }),
2058
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2059
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2060
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
2061
+ }),
2062
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2063
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2064
+ 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, {
2065
+ min: MIN_OFFSET,
2066
+ max: MAX_OFFSET,
2067
+ precision: 1,
2068
+ disabled,
2069
+ value: vPosition.posOffset,
2070
+ onChange: (val) => {
2071
+ handlePositionChange("positionV", {
2072
+ relativeFrom: vPosition.relativeFrom,
2073
+ posOffset: val
2074
+ });
2075
+ }
2076
+ })] }), /* @__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, {
2077
+ disabled,
2078
+ value: String(vPosition.relativeFrom),
2079
+ options: VERTICAL_RELATIVE_FROM,
2080
+ onChange: handleVerticalRelativeFromChange
2081
+ })] })]
2082
+ }),
2083
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2084
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2085
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
2086
+ }),
2087
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2088
+ disabled,
2089
+ checked: followTextMove,
2090
+ onChange: handleFollowTextMoveCheck,
2091
+ children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
2092
+ }) })
2093
+ ]
2094
+ });
2098
2095
  };
2099
- DocDrawingTransformUpdateController = __decorate([
2100
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
2101
- __decorateParam(2, _univerjs_core.ICommandService),
2102
- __decorateParam(3, _univerjs_docs_ui.IEditorService),
2103
- __decorateParam(4, _univerjs_drawing.IDrawingManagerService),
2104
- __decorateParam(5, (0, _univerjs_core.Inject)(DocRefreshDrawingsService)),
2105
- __decorateParam(6, _univerjs_core.IUniverInstanceService),
2106
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LifecycleService))
2107
- ], DocDrawingTransformUpdateController);
2108
2096
 
2109
2097
  //#endregion
2110
- //#region src/controllers/doc-drawing-transformer-update.controller.ts
2111
- const INLINE_DRAWING_ANCHOR_KEY_PREFIX = "__InlineDrawingAnchor__";
2112
- function getDocsTableCellAnchorContext(unitId, cell) {
2113
- var _row$cells;
2114
- const row = cell.parent;
2115
- const table = row === null || row === void 0 ? void 0 : row.parent;
2116
- const hostPage = table === null || table === void 0 ? void 0 : table.parent;
2117
- if (!row || !table || !hostPage || !((_row$cells = row.cells) === null || _row$cells === void 0 ? void 0 : _row$cells.includes(cell))) return null;
2118
- return {
2119
- cell,
2120
- hostPage,
2121
- offset: getDocsTableCellDrawingOffset(unitId, table, row, cell),
2122
- row,
2123
- table
2124
- };
2125
- }
2126
- let DocDrawingTransformerController = class DocDrawingTransformerController extends _univerjs_core.Disposable {
2127
- constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
2128
- super();
2129
- this._commandService = _commandService;
2130
- this._univerInstanceService = _univerInstanceService;
2131
- this._drawingManagerService = _drawingManagerService;
2132
- this._renderManagerService = _renderManagerService;
2133
- _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
2134
- _defineProperty(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
2135
- _defineProperty(this, "_transformerCache", /* @__PURE__ */ new Map());
2136
- _defineProperty(this, "_anchorShape", void 0);
2137
- this._init();
2138
- }
2139
- _init() {
2140
- this._listenDrawingFocus();
2141
- }
2142
- _listenDrawingFocus() {
2143
- this.disposeWithMe(this._drawingManagerService.add$.subscribe((drawingParams) => {
2144
- if (drawingParams.length === 0) return;
2145
- for (const drawingParam of drawingParams) {
2146
- const { unitId } = drawingParam;
2147
- if (!this._listenerOnImageMap.has(unitId)) {
2148
- this._listenTransformerChange(unitId);
2149
- this._listenerOnImageMap.add(unitId);
2150
- }
2151
- }
2152
- }));
2153
- }
2154
- _listenTransformerChange(unitId) {
2155
- var _this$_getSceneAndTra;
2156
- const transformer = (_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.transformer;
2157
- if (transformer == null) return;
2158
- this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeStart$.subscribe((state) => {
2159
- this._transformerCache.clear();
2160
- const { objects } = state;
2161
- for (const object of objects.values()) {
2162
- var _documentDataModel$ge;
2163
- const { oKey, width, height, left, top, angle } = object;
2164
- const drawing = this._drawingManagerService.getDrawingOKey(oKey);
2165
- if (drawing == null) continue;
2166
- const documentDataModel = this._univerInstanceService.getUniverDocInstance(drawing.unitId);
2167
- const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawing.drawingId];
2168
- if ((drawingData === null || drawingData === void 0 ? void 0 : drawingData.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) try {
2169
- object.setOpacity(.2);
2170
- } catch (e) {}
2171
- if (drawingData != null) this._transformerCache.set(drawing.drawingId, {
2172
- drawing: drawingData,
2173
- top,
2174
- left,
2175
- width,
2176
- height,
2177
- angle
2178
- });
2179
- }
2180
- })));
2181
- const throttleMultipleDrawingUpdate = (0, _univerjs_core.throttle)(this._updateMultipleDrawingDocTransform.bind(this), 50);
2182
- (0, _univerjs_core.throttle)(this._nonInlineDrawingTransform.bind(this), 50);
2183
- this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changing$.subscribe((state) => {
2184
- const { objects, offsetX, offsetY } = state;
2185
- if (objects.size > 1) throttleMultipleDrawingUpdate(objects);
2186
- else if (objects.size === 1) {
2187
- const drawingCache = this._transformerCache.values().next().value;
2188
- const { width, height, top, left, angle } = objects.values().next().value;
2189
- if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
2190
- if (drawingCache && drawingCache.drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE) {}
2191
- if (drawingCache && drawingCache.drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
2192
- }
2193
- })));
2194
- this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeEnd$.subscribe((state) => {
2195
- const { objects, offsetX, offsetY } = state;
2196
- for (const object of objects.values()) {
2197
- const drawing = this._drawingManagerService.getDrawingOKey(object.oKey);
2198
- if (drawing == null) continue;
2199
- const drawingCache = this._transformerCache.get(drawing === null || drawing === void 0 ? void 0 : drawing.drawingId);
2200
- if ((drawingCache === null || drawingCache === void 0 ? void 0 : drawingCache.drawing.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) try {
2201
- object.setOpacity(1);
2202
- } catch (e) {}
2203
- }
2204
- if (this._anchorShape) this._anchorShape.hide();
2205
- if (objects.size > 1) this._updateMultipleDrawingDocTransform(objects);
2206
- else if (objects.size === 1) {
2207
- const drawingCache = this._transformerCache.values().next().value;
2208
- const object = objects.values().next().value;
2209
- const { width, height, top, left, angle } = object;
2210
- if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
2211
- if (drawingCache && drawingCache.drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) {
2212
- if (width !== drawingCache.width || height !== drawingCache.height || angle !== drawingCache.angle) this._updateDrawingSize(drawingCache, object);
2213
- else if (offsetX != null && offsetY != null) this._moveInlineDrawing(drawingCache.drawing, offsetX, offsetY);
2214
- } else if (drawingCache) this._nonInlineDrawingTransform(drawingCache.drawing, object);
2215
- }
2216
- this._transformerCache.clear();
2217
- })));
2218
- }
2219
- _updateMultipleDrawingDocTransform(objects) {
2220
- if (objects.size < 1) return;
2221
- const drawings = [];
2222
- let unitId;
2223
- let subUnitId;
2224
- for (const object of objects.values()) {
2225
- const { oKey, left, top, angle } = object;
2226
- let { width, height } = object;
2227
- const drawing = this._drawingManagerService.getDrawingOKey(oKey);
2228
- if (drawing == null) continue;
2229
- if (unitId == null) unitId = drawing.unitId;
2230
- if (subUnitId == null) subUnitId = drawing.subUnitId;
2231
- const drawingCache = this._transformerCache.get(drawing.drawingId);
2232
- if (drawingCache == null) continue;
2233
- const { drawing: drawingData, top: oldTop, left: oldLeft, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
2234
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawingData);
2235
- width = Math.min(width, maxWidth);
2236
- height = Math.min(height, maxHeight);
2237
- if (oldWidth !== width || oldHeight !== height) drawings.push({
2238
- drawingId: drawing.drawingId,
2239
- key: "size",
2240
- value: {
2241
- width,
2242
- height
2243
- }
2244
- });
2245
- if (oldAngle !== angle) drawings.push({
2246
- drawingId: drawing.drawingId,
2247
- key: "angle",
2248
- value: angle
2249
- });
2250
- if (oldTop !== top || oldLeft !== left) {
2251
- const verticalDelta = top - oldTop;
2252
- const horizontalDelta = left - oldLeft;
2253
- if (verticalDelta !== 0) drawings.push({
2254
- drawingId: drawing.drawingId,
2255
- key: "positionV",
2256
- value: {
2257
- relativeFrom: drawingData.docTransform.positionV.relativeFrom,
2258
- posOffset: drawingData.docTransform.positionV.posOffset + verticalDelta
2259
- }
2260
- });
2261
- if (horizontalDelta !== 0) drawings.push({
2262
- drawingId: drawing.drawingId,
2263
- key: "positionH",
2264
- value: {
2265
- relativeFrom: drawingData.docTransform.positionH.relativeFrom,
2266
- posOffset: drawingData.docTransform.positionH.posOffset + horizontalDelta
2267
- }
2268
- });
2269
- }
2270
- }
2271
- if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2098
+ //#region src/views/doc-image-panel/DocDrawingTextWrap.tsx
2099
+ const MIN_MARGIN = 0;
2100
+ const MAX_MARGIN = 100;
2101
+ const DocDrawingTextWrap = (props) => {
2102
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2103
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2104
+ const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2105
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2106
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2107
+ const { drawings } = props;
2108
+ const drawingParam = drawings[0];
2109
+ if (drawingParam == null) return null;
2110
+ const { unitId } = drawingParam;
2111
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2112
+ const renderObject = renderManagerService.getRenderById(unitId);
2113
+ if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
2114
+ const [disableWrapText, setDisableWrapText] = (0, react.useState)(true);
2115
+ const [disableDistTB, setDisableDistTB] = (0, react.useState)(true);
2116
+ const [disableDistLR, setDisableDistLR] = (0, react.useState)(true);
2117
+ const [wrappingStyle, setWrappingStyle] = (0, react.useState)("inline");
2118
+ const [wrapText, setWrapText] = (0, react.useState)("");
2119
+ const [distToText, setDistToText] = (0, react.useState)({
2120
+ distT: 0,
2121
+ distL: 0,
2122
+ distB: 0,
2123
+ distR: 0
2124
+ });
2125
+ const [showPanel, setShowPanel] = (0, react.useState)(true);
2126
+ function handleWrappingStyleChange(value) {
2127
+ setWrappingStyle(value);
2128
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2129
+ if (focusDrawings.length === 0) return;
2130
+ const { unitId, subUnitId } = focusDrawings[0];
2131
+ const drawings = focusDrawings.map(({ unitId, subUnitId, drawingId }) => ({
2272
2132
  unitId,
2273
2133
  subUnitId,
2274
- drawings
2134
+ drawingId
2135
+ }));
2136
+ commandService.executeCommand(UpdateDocDrawingWrappingStyleCommand.id, {
2137
+ unitId,
2138
+ subUnitId,
2139
+ drawings,
2140
+ wrappingStyle: value
2275
2141
  });
2276
2142
  }
2277
- _updateDrawingAnchor(objects) {
2278
- if (this._transformerCache.size !== 1) return;
2279
- const drawingCache = this._transformerCache.values().next().value;
2280
- const object = objects.values().next().value;
2281
- this._getDrawingAnchor(drawingCache.drawing, object);
2282
- }
2283
- _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
2284
- var _this$_getInlineDrawi;
2285
- if (this._transformerCache.size !== 1) return;
2286
- const { contentBoxPointGroup } = (_this$_getInlineDrawi = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) !== null && _this$_getInlineDrawi !== void 0 ? _this$_getInlineDrawi : {};
2287
- if (contentBoxPointGroup == null) return;
2288
- this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2143
+ function handleWrapTextChange(value) {
2144
+ setWrapText(value);
2145
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2146
+ if (focusDrawings.length === 0) return;
2147
+ const drawings = focusDrawings.map((drawing) => {
2148
+ return {
2149
+ unitId: drawing.unitId,
2150
+ subUnitId: drawing.subUnitId,
2151
+ drawingId: drawing.drawingId
2152
+ };
2153
+ });
2154
+ commandService.executeCommand(UpdateDocDrawingWrapTextCommand.id, {
2155
+ unitId: focusDrawings[0].unitId,
2156
+ subUnitId: focusDrawings[0].unitId,
2157
+ drawings,
2158
+ wrapText: value
2159
+ });
2289
2160
  }
2290
- _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
2291
- var _this$_renderManagerS, _getOneTextSelectionR;
2292
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2293
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2294
- if (currentRender == null) return;
2295
- const { mainComponent, scene } = currentRender;
2296
- const documentComponent = mainComponent;
2297
- const activeViewport = scene.getViewports()[0];
2298
- const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = documentComponent.getOffsetConfig();
2299
- let glyphAnchor = null;
2300
- let isBack = false;
2301
- let segmentPageIndex = -1;
2302
- let segmentId = "";
2303
- const HALF = .5;
2304
- const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
2305
- if (coord == null) return;
2306
- const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocSelectionRenderService);
2307
- if (docSelectionRenderService == null) return;
2308
- const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2309
- strict: false,
2310
- segmentId: docSelectionRenderService.getSegment(),
2311
- segmentPage: docSelectionRenderService.getSegmentPage()
2161
+ function handleDistToTextChange(value, direction) {
2162
+ if (value == null) return;
2163
+ setDistToText({
2164
+ ...distToText,
2165
+ [direction]: value
2166
+ });
2167
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2168
+ if (focusDrawings.length === 0) return;
2169
+ const drawings = focusDrawings.map((drawing) => {
2170
+ return {
2171
+ unitId: drawing.unitId,
2172
+ subUnitId: drawing.subUnitId,
2173
+ drawingId: drawing.drawingId
2174
+ };
2175
+ });
2176
+ commandService.executeCommand(UpdateDocDrawingDistanceCommand.id, {
2177
+ unitId: focusDrawings[0].unitId,
2178
+ subUnitId: focusDrawings[0].unitId,
2179
+ drawings,
2180
+ dist: { [direction]: value }
2312
2181
  });
2313
- if (nodeInfo) {
2314
- const { node, ratioX, segmentPage, segmentId: nodeSegmentId } = nodeInfo;
2315
- isBack = ratioX < HALF;
2316
- glyphAnchor = node;
2317
- segmentPageIndex = segmentPage;
2318
- segmentId = nodeSegmentId;
2319
- }
2320
- if (glyphAnchor == null) return;
2321
- const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex);
2322
- const docObject = this._getDocObject();
2323
- if (nodePosition == null || skeleton == null || docObject == null) return;
2324
- const positionWithIsBack = {
2325
- ...nodePosition,
2326
- isBack
2327
- };
2328
- const { cursorList, contentBoxPointGroup } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
2329
- const { startOffset } = (_getOneTextSelectionR = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
2330
- if (startOffset == null) return;
2331
- return {
2332
- offset: startOffset,
2333
- contentBoxPointGroup,
2334
- segmentId,
2335
- segmentPage: segmentPageIndex
2336
- };
2337
2182
  }
2338
- _getDrawingAnchor(drawing, object) {
2339
- var _this$_renderManagerS2, _glyphAnchor$parent, _column$lines$find, _column$parent, _tableCellContext$hos, _getOneTextSelectionR2;
2340
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2341
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2342
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2343
- if (skeletonData == null || currentRender == null) return;
2344
- const { pages, skeHeaders, skeFooters } = skeletonData;
2345
- const { mainComponent, scene } = currentRender;
2346
- const documentComponent = mainComponent;
2347
- const activeViewport = scene.getViewports()[0];
2348
- const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig();
2349
- const { left, top, angle } = object;
2350
- let { width, height } = object;
2351
- const { positionV, positionH } = drawing.docTransform;
2352
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2353
- width = Math.min(width, maxWidth);
2354
- height = Math.min(height, maxHeight);
2355
- let glyphAnchor = null;
2356
- let segmentId = "";
2357
- let segmentPage = -1;
2358
- const isBack = false;
2359
- const docTransform = {
2360
- ...drawing.docTransform,
2361
- size: {
2362
- width,
2363
- height
2364
- },
2365
- angle
2366
- };
2367
- const { x, y } = scene.getViewportScrollXY(activeViewport);
2368
- const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
2369
- if (coord == null) return;
2370
- const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
2371
- if (docSelectionRenderService == null) return;
2372
- const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2373
- strict: false,
2374
- segmentId: docSelectionRenderService.getSegment(),
2375
- segmentPage: docSelectionRenderService.getSegmentPage()
2183
+ function updateFocusDrawingState() {
2184
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2185
+ if (focusDrawings.length === 0) return;
2186
+ updateState(focusDrawings[0]);
2187
+ }
2188
+ function updateState(drawingParam) {
2189
+ var _documentDataModel$ge;
2190
+ const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingParam.drawingId];
2191
+ if (drawing == null) return;
2192
+ const { distT = 0, distL = 0, distB = 0, distR = 0, layoutType = _univerjs_core.PositionedObjectLayoutType.INLINE, behindDoc = _univerjs_core.BooleanNumber.FALSE, wrapText = _univerjs_core.WrapTextType.BOTH_SIDES } = drawing;
2193
+ setDistToText({
2194
+ distT,
2195
+ distL,
2196
+ distB,
2197
+ distR
2376
2198
  });
2377
- if (nodeInfo) {
2378
- const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
2379
- glyphAnchor = node;
2380
- segmentPage = segmentPageIndex;
2381
- segmentId = nodeSegmentId;
2382
- }
2383
- if (glyphAnchor == null) return;
2384
- const line = (_glyphAnchor$parent = glyphAnchor.parent) === null || _glyphAnchor$parent === void 0 ? void 0 : _glyphAnchor$parent.parent;
2385
- const column = line === null || line === void 0 ? void 0 : line.parent;
2386
- const paragraphStartLine = (_column$lines$find = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) !== null && _column$lines$find !== void 0 ? _column$lines$find : column === null || column === void 0 ? void 0 : column.lines[0];
2387
- const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
2388
- if (line == null || column == null || paragraphStartLine == null || page == null) return;
2389
- this._liquid.reset();
2390
- const tableCellContext = page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? getDocsTableCellAnchorContext(drawing.unitId, page) : null;
2391
- const anchorPage = (_tableCellContext$hos = tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) !== null && _tableCellContext$hos !== void 0 ? _tableCellContext$hos : page;
2392
- const pageType = anchorPage.type;
2393
- for (const p of pages) {
2394
- const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p;
2395
- const pIndex = pages.indexOf(p);
2396
- if (segmentPage > -1 && pIndex === segmentPage) {
2397
- switch (pageType) {
2398
- case _univerjs_engine_render.DocumentSkeletonPageType.HEADER: {
2399
- var _skeHeaders$get;
2400
- const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2401
- if (headerSke) this._liquid.translatePagePadding({
2402
- marginTop: headerSke.marginTop,
2403
- marginLeft
2404
- });
2405
- else throw new Error("header skeleton not found");
2406
- break;
2407
- }
2408
- case _univerjs_engine_render.DocumentSkeletonPageType.FOOTER: {
2409
- var _skeFooters$get;
2410
- const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2411
- if (footerSke) this._liquid.translatePagePadding({
2412
- marginTop: pageHeight - marginBottom + footerSke.marginTop,
2413
- marginLeft
2414
- });
2415
- else throw new Error("footer skeleton not found");
2416
- break;
2417
- }
2418
- default:
2419
- this._liquid.translatePagePadding(p);
2420
- break;
2421
- }
2422
- break;
2423
- }
2424
- this._liquid.translatePagePadding(p);
2425
- if (p === anchorPage) break;
2426
- this._liquid.restorePagePadding(p);
2427
- this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
2428
- }
2429
- if (tableCellContext) this._liquid.translate(tableCellContext.offset.left, tableCellContext.offset.top);
2430
- if (positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) glyphAnchor = line.divides[0].glyphGroup[0];
2431
- else {
2432
- var _paragraphStartLine$d, _paragraphStartLine$d2;
2433
- glyphAnchor = (_paragraphStartLine$d = (_paragraphStartLine$d2 = paragraphStartLine.divides) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2[0]) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2.glyphGroup) === null || _paragraphStartLine$d2 === void 0 ? void 0 : _paragraphStartLine$d2[0]) !== null && _paragraphStartLine$d !== void 0 ? _paragraphStartLine$d : glyphAnchor;
2434
- }
2435
- docTransform.positionH = {
2436
- relativeFrom: positionH.relativeFrom,
2437
- posOffset: left - this._liquid.x - docsLeft
2438
- };
2439
- switch (positionH.relativeFrom) {
2440
- case _univerjs_core.ObjectRelativeFromH.MARGIN:
2441
- docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
2442
- break;
2443
- case _univerjs_core.ObjectRelativeFromH.COLUMN:
2444
- docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - column.left;
2445
- break;
2446
- }
2447
- docTransform.positionV = {
2448
- relativeFrom: positionV.relativeFrom,
2449
- posOffset: top - this._liquid.y - docsTop
2450
- };
2451
- switch (positionV.relativeFrom) {
2452
- case _univerjs_core.ObjectRelativeFromV.PAGE:
2453
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
2199
+ setWrapText(wrapText);
2200
+ setDisableWrapText(layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE);
2201
+ if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) setDisableDistTB(true);
2202
+ else setDisableDistTB(false);
2203
+ if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
2204
+ else setDisableDistLR(false);
2205
+ if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === _univerjs_core.BooleanNumber.TRUE) setWrappingStyle("behindText");
2206
+ else setWrappingStyle("inFrontOfText");
2207
+ else switch (layoutType) {
2208
+ case _univerjs_core.PositionedObjectLayoutType.INLINE:
2209
+ setWrappingStyle("inline");
2454
2210
  break;
2455
- case _univerjs_core.ObjectRelativeFromV.LINE:
2456
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - line.top;
2211
+ case _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE:
2212
+ setWrappingStyle("wrapSquare");
2457
2213
  break;
2458
- case _univerjs_core.ObjectRelativeFromV.PARAGRAPH:
2459
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - paragraphStartLine.top;
2214
+ case _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
2215
+ setWrappingStyle("wrapTopAndBottom");
2460
2216
  break;
2217
+ default: throw new Error(`Unsupported layout type: ${layoutType}`);
2461
2218
  }
2462
- if (glyphAnchor == null) return;
2463
- const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage);
2464
- const docObject = this._getDocObject();
2465
- if (nodePosition == null || skeleton == null || docObject == null) return;
2466
- const positionWithIsBack = {
2467
- ...nodePosition,
2468
- isBack
2469
- };
2470
- const { cursorList } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
2471
- const { startOffset } = (_getOneTextSelectionR2 = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
2472
- if (startOffset == null) return;
2473
- return {
2474
- offset: startOffset,
2475
- docTransform,
2476
- segmentId,
2477
- segmentPage
2478
- };
2479
2219
  }
2480
- _updateDrawingSize(drawingCache, object) {
2481
- const drawings = [];
2482
- const { drawing, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
2483
- const { unitId, subUnitId } = drawing;
2484
- let { width, height, angle } = object;
2485
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2486
- width = Math.min(maxWidth, width);
2487
- height = Math.min(maxHeight, height);
2488
- if (width !== oldWidth || height !== oldHeight) drawings.push({
2489
- drawingId: drawing.drawingId,
2490
- key: "size",
2491
- value: {
2492
- width,
2493
- height
2220
+ (0, react.useEffect)(() => {
2221
+ updateFocusDrawingState();
2222
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2223
+ if (drawingParams.length === 0) {
2224
+ setShowPanel(false);
2225
+ return;
2494
2226
  }
2227
+ setShowPanel(true);
2228
+ updateState(drawingParams[0]);
2495
2229
  });
2496
- if (angle !== oldAngle) drawings.push({
2497
- drawingId: drawing.drawingId,
2498
- key: "angle",
2499
- value: angle
2500
- });
2501
- if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2502
- unitId,
2503
- subUnitId,
2504
- drawings
2505
- });
2506
- }
2507
- _moveInlineDrawing(drawing, offsetX, offsetY) {
2508
- const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY);
2509
- const { offset, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
2510
- return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
2511
- unitId: drawing.unitId,
2512
- subUnitId: drawing.unitId,
2513
- drawing,
2514
- offset,
2515
- segmentId,
2516
- segmentPage,
2517
- needRefreshDrawings: offset == null
2230
+ const mutationListener = commandService.onCommandExecuted(async (command) => {
2231
+ if (command.id === _univerjs_docs.RichTextEditingMutation.id) updateFocusDrawingState();
2518
2232
  });
2519
- }
2520
- _limitDrawingInPage(drawing, object) {
2521
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2522
- const { left, top, width, height, angle } = object;
2523
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2524
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2525
- const { pages } = skeletonData !== null && skeletonData !== void 0 ? skeletonData : {};
2526
- if (skeletonData == null || currentRender == null || pages == null) return {
2527
- left,
2528
- top,
2529
- width,
2530
- height,
2531
- angle
2532
- };
2533
- const { mainComponent } = currentRender;
2534
- const { top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = mainComponent;
2535
- let newTop = top;
2536
- this._liquid.reset();
2537
- for (const page of pages) {
2538
- const { marginBottom, pageHeight } = page;
2539
- const nextPage = pages[pages.indexOf(page) + 1];
2540
- if (nextPage == null) continue;
2541
- if (_univerjs_core.Tools.hasIntersectionBetweenTwoRanges(top, top + height, this._liquid.y + docsTop + pageHeight - marginBottom, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop)) if (top + height / 2 < this._liquid.y + docsTop + pageHeight + pageMarginTop / 2) newTop = Math.min(top, this._liquid.y + docsTop + pageHeight - marginBottom - height);
2542
- else newTop = Math.max(top, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop);
2543
- this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2544
- }
2545
- return {
2546
- left,
2547
- top: newTop,
2548
- width,
2549
- height,
2550
- angle
2233
+ return () => {
2234
+ subscription.unsubscribe();
2235
+ mutationListener.dispose();
2551
2236
  };
2552
- }
2553
- _nonInlineDrawingTransform(drawing, object, isMoving = false) {
2554
- const objectPosition = drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
2555
- if (isMoving && objectPosition.top !== object.top) return;
2556
- const anchor = this._getDrawingAnchor(drawing, objectPosition);
2557
- const { offset, docTransform, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
2558
- if (offset == null || docTransform == null) return this._updateMultipleDrawingDocTransform(new Map([[drawing.drawingId, object]]));
2559
- return this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
2560
- unitId: drawing.unitId,
2561
- subUnitId: drawing.unitId,
2562
- drawing,
2563
- offset,
2564
- docTransform,
2565
- segmentId,
2566
- segmentPage
2567
- });
2568
- }
2569
- _getSceneAndTransformerByDrawingSearch(unitId) {
2570
- if (unitId == null) return;
2571
- const renderObject = this._renderManagerService.getRenderById(unitId);
2572
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2573
- if (scene == null) return;
2574
- return {
2575
- scene,
2576
- transformer: scene.getTransformerByCreate()
2237
+ }, []);
2238
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2239
+ className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2240
+ children: [
2241
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
2242
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2243
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.title") })
2244
+ }),
2245
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2246
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2247
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrappingStyle") })
2248
+ }),
2249
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2250
+ value: wrappingStyle,
2251
+ onChange: handleWrappingStyleChange,
2252
+ direction: "vertical",
2253
+ children: [
2254
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2255
+ value: "inline",
2256
+ children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
2257
+ }),
2258
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2259
+ value: "wrapSquare",
2260
+ children: localeService.t("docs-drawing-ui.image-text-wrap.square")
2261
+ }),
2262
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2263
+ value: "wrapTopAndBottom",
2264
+ children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
2265
+ }),
2266
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2267
+ value: "behindText",
2268
+ children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
2269
+ }),
2270
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2271
+ value: "inFrontOfText",
2272
+ children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
2273
+ })
2274
+ ]
2275
+ }) }),
2276
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2277
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2278
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrapText") })
2279
+ }),
2280
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2281
+ disabled: disableWrapText,
2282
+ value: wrapText,
2283
+ onChange: handleWrapTextChange,
2284
+ direction: "horizontal",
2285
+ children: [
2286
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2287
+ value: _univerjs_core.WrapTextType.BOTH_SIDES,
2288
+ children: localeService.t("docs-drawing-ui.image-text-wrap.bothSide")
2289
+ }),
2290
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2291
+ value: _univerjs_core.WrapTextType.LEFT,
2292
+ children: localeService.t("docs-drawing-ui.image-text-wrap.leftOnly")
2293
+ }),
2294
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2295
+ value: _univerjs_core.WrapTextType.RIGHT,
2296
+ children: localeService.t("docs-drawing-ui.image-text-wrap.rightOnly")
2297
+ })
2298
+ ]
2299
+ }) }),
2300
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2301
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2302
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.distanceFromText") })
2303
+ }),
2304
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2305
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2306
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.top") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
2307
+ min: MIN_MARGIN,
2308
+ max: MAX_MARGIN,
2309
+ disabled: disableDistTB,
2310
+ precision: 1,
2311
+ value: distToText.distT,
2312
+ onChange: (val) => {
2313
+ handleDistToTextChange(val, "distT");
2314
+ }
2315
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.left") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
2316
+ min: MIN_MARGIN,
2317
+ max: MAX_MARGIN,
2318
+ disabled: disableDistLR,
2319
+ precision: 1,
2320
+ value: distToText.distL,
2321
+ onChange: (val) => {
2322
+ handleDistToTextChange(val, "distL");
2323
+ }
2324
+ })] })]
2325
+ }),
2326
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2327
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2328
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.bottom") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
2329
+ min: MIN_MARGIN,
2330
+ max: MAX_MARGIN,
2331
+ disabled: disableDistTB,
2332
+ precision: 1,
2333
+ value: distToText.distB,
2334
+ onChange: (val) => {
2335
+ handleDistToTextChange(val, "distB");
2336
+ }
2337
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.right") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
2338
+ min: MIN_MARGIN,
2339
+ max: MAX_MARGIN,
2340
+ disabled: disableDistLR,
2341
+ precision: 1,
2342
+ value: distToText.distR,
2343
+ onChange: (val) => {
2344
+ handleDistToTextChange(val, "distR");
2345
+ }
2346
+ })] })]
2347
+ })
2348
+ ]
2349
+ });
2350
+ };
2351
+
2352
+ //#endregion
2353
+ //#region src/views/doc-image-panel/DocDrawingPanel.tsx
2354
+ const DocDrawingPanel = () => {
2355
+ const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2356
+ const [drawings, setDrawings] = (0, react.useState)(drawingManagerService.getFocusDrawings());
2357
+ (0, react.useEffect)(() => {
2358
+ const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
2359
+ setDrawings(drawings);
2360
+ });
2361
+ return () => {
2362
+ focusDispose.unsubscribe();
2577
2363
  };
2364
+ }, []);
2365
+ return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2366
+ className: "univer-text-sm",
2367
+ children: [
2368
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_drawing_ui.DrawingCommonPanel, {
2369
+ drawings,
2370
+ hasAlign: false,
2371
+ hasCropper: true,
2372
+ hasGroup: false,
2373
+ hasTransform: false
2374
+ }),
2375
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocDrawingTextWrap, { drawings }),
2376
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocDrawingPosition, { drawings })
2377
+ ]
2378
+ });
2379
+ };
2380
+
2381
+ //#endregion
2382
+ //#region src/controllers/components.controller.ts
2383
+ /**
2384
+ * Copyright 2023-present DreamNum Co., Ltd.
2385
+ *
2386
+ * Licensed under the Apache License, Version 2.0 (the "License");
2387
+ * you may not use this file except in compliance with the License.
2388
+ * You may obtain a copy of the License at
2389
+ *
2390
+ * http://www.apache.org/licenses/LICENSE-2.0
2391
+ *
2392
+ * Unless required by applicable law or agreed to in writing, software
2393
+ * distributed under the License is distributed on an "AS IS" BASIS,
2394
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2395
+ * See the License for the specific language governing permissions and
2396
+ * limitations under the License.
2397
+ */
2398
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
2399
+ constructor(_componentManager) {
2400
+ super();
2401
+ this._componentManager = _componentManager;
2402
+ this._registerComponents();
2578
2403
  }
2579
- _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
2580
- const { documentTransform } = document.getOffsetConfig();
2581
- const originCoord = viewport.transformVector2SceneCoord(_univerjs_engine_render.Vector2.FromArray([evtOffsetX, evtOffsetY]));
2582
- if (!originCoord) return;
2583
- return documentTransform.clone().invert().applyPoint(originCoord);
2404
+ _registerComponents() {
2405
+ this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
2584
2406
  }
2585
- _createOrUpdateInlineAnchor(unitId, pointsGroup) {
2586
- const currentRender = this._renderManagerService.getRenderById(unitId);
2587
- if (currentRender == null) return;
2588
- const { mainComponent, scene } = currentRender;
2589
- const { docsLeft, docsTop } = mainComponent.getOffsetConfig();
2590
- const { left: boundingLeft, top: boundingTop, height } = (0, _univerjs_docs_ui.getAnchorBounding)(pointsGroup);
2591
- const left = boundingLeft + docsLeft;
2592
- const top = boundingTop + docsTop;
2593
- if (this._anchorShape) {
2594
- this._anchorShape.transformByState({
2595
- left,
2596
- top,
2597
- height
2407
+ };
2408
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))], ComponentsController);
2409
+
2410
+ //#endregion
2411
+ //#region src/controllers/doc-drawing-notification.controller.ts
2412
+ function getAddOrRemoveDrawings(actions) {
2413
+ if (_univerjs_core.JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
2414
+ const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
2415
+ if (drawingsOp == null || !Array.isArray(drawingsOp) || drawingsOp.length < 3) return null;
2416
+ if (typeof drawingsOp[1] === "string" && typeof drawingsOp[2] !== "object") return null;
2417
+ if (Array.isArray(drawingsOp[1]) && typeof drawingsOp[1][1] !== "object") return null;
2418
+ const drawings = [];
2419
+ if (Array.isArray(drawingsOp === null || drawingsOp === void 0 ? void 0 : drawingsOp[1])) {
2420
+ for (const op of drawingsOp) if (Array.isArray(op)) {
2421
+ var _ref, _ref2;
2422
+ drawings.push({
2423
+ type: (op === null || op === void 0 || (_ref = op[1]) === null || _ref === void 0 ? void 0 : _ref.i) ? "add" : "remove",
2424
+ drawingId: op === null || op === void 0 ? void 0 : op[0],
2425
+ drawing: op === null || op === void 0 || (_ref2 = op[1]) === null || _ref2 === void 0 ? void 0 : _ref2.i
2598
2426
  });
2599
- this._anchorShape.show();
2600
- return;
2601
2427
  }
2602
- const anchor = new _univerjs_engine_render.Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + (0, _univerjs_core.generateRandomId)(6), {
2603
- left,
2604
- top,
2605
- height,
2606
- strokeWidth: 2,
2607
- stroke: (0, _univerjs_engine_render.getColor)(_univerjs_core.COLORS.darkgray, 1),
2608
- evented: false
2428
+ } else {
2429
+ var _drawingsOp$, _drawingsOp$2;
2430
+ drawings.push({
2431
+ type: ((_drawingsOp$ = drawingsOp[2]) === null || _drawingsOp$ === void 0 ? void 0 : _drawingsOp$.i) ? "add" : "remove",
2432
+ drawingId: drawingsOp[1],
2433
+ drawing: (_drawingsOp$2 = drawingsOp[2]) === null || _drawingsOp$2 === void 0 ? void 0 : _drawingsOp$2.i
2609
2434
  });
2610
- this._anchorShape = anchor;
2611
- scene.addObject(anchor, _univerjs_docs_ui.TEXT_RANGE_LAYER_INDEX);
2612
- }
2613
- _getDocObject() {
2614
- return (0, _univerjs_docs_ui.getDocObject)(this._univerInstanceService, this._renderManagerService);
2615
2435
  }
2616
- _getPageContentSize(drawing) {
2617
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2618
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2619
- const MAX_WIDTH = 500;
2620
- const MAX_HEIGHT = 500;
2621
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2622
- if (skeletonData == null || currentRender == null) return {
2623
- width: MAX_WIDTH,
2624
- height: MAX_HEIGHT
2625
- };
2626
- const { pages } = skeletonData;
2627
- let page = null;
2628
- for (const p of pages) {
2629
- const { skeDrawings } = p;
2630
- if (skeDrawings.has(drawing.drawingId)) {
2631
- page = p;
2632
- break;
2633
- }
2436
+ return drawings;
2437
+ }
2438
+ function getReOrderedDrawings(actions) {
2439
+ if (!Array.isArray(actions) || actions.length < 3 || actions[0] !== "drawingsOrder") return [];
2440
+ const drawingIndexes = [];
2441
+ for (let i = 1; i < actions.length; i++) {
2442
+ const action = actions[i];
2443
+ if (Array.isArray(action) && typeof action[0] === "number" && typeof action[1] === "object") drawingIndexes.push(action[0]);
2444
+ else {
2445
+ drawingIndexes.length = 0;
2446
+ break;
2634
2447
  }
2635
- if (page) {
2636
- const { pageWidth, pageHeight, marginLeft, marginBottom, marginRight, marginTop } = page;
2637
- return {
2638
- width: Math.max(MAX_WIDTH, pageWidth - marginLeft - marginRight),
2639
- height: Math.max(MAX_HEIGHT, pageHeight - marginTop - marginBottom)
2448
+ }
2449
+ return drawingIndexes;
2450
+ }
2451
+ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends _univerjs_core.Disposable {
2452
+ constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
2453
+ super();
2454
+ this._univerInstanceService = _univerInstanceService;
2455
+ this._commandService = _commandService;
2456
+ this._drawingManagerService = _drawingManagerService;
2457
+ this._docDrawingService = _docDrawingService;
2458
+ this._renderManagerService = _renderManagerService;
2459
+ this._initialize();
2460
+ }
2461
+ _initialize() {
2462
+ this._commandExecutedListener();
2463
+ }
2464
+ _commandExecutedListener() {
2465
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
2466
+ if (command.id !== _univerjs_docs.RichTextEditingMutation.id) return;
2467
+ const { unitId, actions, isSync, syncer } = command.params;
2468
+ const addOrRemoveDrawings = getAddOrRemoveDrawings(actions);
2469
+ if (addOrRemoveDrawings != null) for (const { type, drawingId, drawing } of addOrRemoveDrawings) {
2470
+ if (isSync && (drawing === null || drawing === void 0 ? void 0 : drawing.unitId) === syncer) continue;
2471
+ if (type === "add") this._addDrawings(unitId, [drawing]);
2472
+ else this._removeDrawings(unitId, [drawingId]);
2473
+ }
2474
+ }));
2475
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2476
+ if (command.id !== _univerjs_docs.RichTextEditingMutation.id) return;
2477
+ const { unitId, actions } = command.params;
2478
+ if (getReOrderedDrawings(actions).length > 0) this._updateDrawingsOrder(unitId);
2479
+ }));
2480
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2481
+ var _this$_univerInstance;
2482
+ if (command.id !== _univerjs_core.UndoCommand.id && command.id !== _univerjs_core.RedoCommand.id) return;
2483
+ const unitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUniverDocInstance()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
2484
+ const focusedDrawings = this._drawingManagerService.getFocusDrawings();
2485
+ if (unitId == null || focusedDrawings.length === 0) return;
2486
+ const renderObject = this._renderManagerService.getRenderById(unitId);
2487
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2488
+ if (scene == null) return false;
2489
+ scene.getTransformerByCreate().refreshControls();
2490
+ }));
2491
+ }
2492
+ _addDrawings(unitId, drawings) {
2493
+ const drawingManagerService = this._drawingManagerService;
2494
+ const docDrawingService = this._docDrawingService;
2495
+ const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchAddOp(drawings);
2496
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
2497
+ docDrawingService.applyJson1(unitId, subUnitId, op);
2498
+ drawingManagerService.addNotification(objects);
2499
+ docDrawingService.addNotification(objects);
2500
+ }
2501
+ _removeDrawings(unitId, drawingIds) {
2502
+ const drawingManagerService = this._drawingManagerService;
2503
+ const docDrawingService = this._docDrawingService;
2504
+ const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchRemoveOp(drawingIds.map((drawingId) => {
2505
+ return {
2506
+ unitId,
2507
+ subUnitId: unitId,
2508
+ drawingId
2640
2509
  };
2641
- } else return {
2642
- width: MAX_WIDTH,
2643
- height: MAX_HEIGHT
2510
+ }));
2511
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
2512
+ docDrawingService.applyJson1(unitId, subUnitId, op);
2513
+ drawingManagerService.removeNotification(objects);
2514
+ docDrawingService.removeNotification(objects);
2515
+ }
2516
+ _updateDrawingsOrder(unitId) {
2517
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
2518
+ if (documentDataModel == null) return;
2519
+ const { drawings, drawingsOrder } = documentDataModel.getSnapshot();
2520
+ if (drawingsOrder == null) return;
2521
+ const renderOrder = (0, _univerjs_docs_drawing.getDocDrawingRenderOrder)(drawingsOrder, drawings);
2522
+ const drawingManagerService = this._drawingManagerService;
2523
+ const docDrawingService = this._docDrawingService;
2524
+ drawingManagerService.setDrawingOrder(unitId, unitId, renderOrder);
2525
+ docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
2526
+ const objects = {
2527
+ unitId,
2528
+ subUnitId: unitId,
2529
+ drawingIds: renderOrder
2644
2530
  };
2531
+ drawingManagerService.orderNotification(objects);
2532
+ docDrawingService.orderNotification({
2533
+ unitId,
2534
+ subUnitId: unitId,
2535
+ drawingIds: drawingsOrder
2536
+ });
2645
2537
  }
2646
2538
  };
2647
- DocDrawingTransformerController = __decorate([
2648
- __decorateParam(0, _univerjs_core.ICommandService),
2649
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
2539
+ DocDrawingAddRemoveController = __decorate([
2540
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
2541
+ __decorateParam(1, _univerjs_core.ICommandService),
2650
2542
  __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
2651
- __decorateParam(3, _univerjs_engine_render.IRenderManagerService)
2652
- ], DocDrawingTransformerController);
2543
+ __decorateParam(3, _univerjs_docs_drawing.IDocDrawingService),
2544
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService)
2545
+ ], DocDrawingAddRemoveController);
2653
2546
 
2654
2547
  //#endregion
2655
- //#region src/menu/schema.ts
2656
- const menuSchema = {
2657
- [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
2658
- order: 0,
2659
- menuItemFactory: ImageMenuFactory,
2660
- [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2661
- order: 0,
2662
- menuItemFactory: UploadFloatImageMenuFactory
2663
- }
2664
- } },
2665
- [_univerjs_ui.ContextMenuPosition.PARAGRAPH]: {
2666
- [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [_univerjs_docs_ui.INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2667
- order: 5,
2668
- menuItemFactory: UploadFloatImageMenuFactory
2669
- } } },
2670
- [_univerjs_docs_ui.EMPTY_PARAGRAPH_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2671
- order: 5,
2672
- menuItemFactory: UploadFloatImageMenuFactory
2673
- } } },
2674
- [_univerjs_docs_ui.DOC_CONTENT_INSERT_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2675
- order: 5,
2676
- menuItemFactory: UploadFloatImageMenuFactory
2677
- } } }
2548
+ //#region src/views/DocPrintingFloatDom.tsx
2549
+ const DocPrintingFloatDom = (props) => {
2550
+ const { floatDomInfos, scene, offset, bound } = props;
2551
+ const width = bound.right - bound.left;
2552
+ const height = bound.bottom - bound.top;
2553
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2554
+ className: "univer-absolute univer-left-0 univer-top-0",
2555
+ children: (0, react.useMemo)(() => floatDomInfos.map((info) => {
2556
+ const { width = 0, height = 0, left = 0, top = 0 } = info.transform;
2557
+ const domPos = calcDocFloatDomPositionByRect({
2558
+ left,
2559
+ right: left + width,
2560
+ top,
2561
+ bottom: top + height
2562
+ }, scene);
2563
+ const floatDom = {
2564
+ position$: new rxjs.BehaviorSubject(domPos),
2565
+ position: domPos,
2566
+ id: info.drawingId,
2567
+ componentKey: info.componentKey,
2568
+ onPointerMove: () => {},
2569
+ onPointerDown: () => {},
2570
+ onPointerUp: () => {},
2571
+ onWheel: () => {},
2572
+ unitId: info.unitId,
2573
+ data: info.data
2574
+ };
2575
+ return [info.drawingId, floatDom];
2576
+ }).filter(([_, floatDom]) => !(floatDom.position.endX < 0 || floatDom.position.endY < 0 || floatDom.position.startX > width || floatDom.position.startY > height)), [
2577
+ floatDomInfos,
2578
+ scene,
2579
+ offset,
2580
+ width,
2581
+ height
2582
+ ]).map(([id, floatDom]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.PrintFloatDomSingle, {
2583
+ layer: floatDom,
2584
+ id,
2585
+ position: floatDom.position
2586
+ }, id))
2587
+ });
2588
+ };
2589
+ function mountDocPrintingFloatDom(props, root, injector) {
2590
+ (0, _univerjs_design.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)((0, _univerjs_ui.connectInjector)(DocPrintingFloatDom, injector), { ...props }), root);
2591
+ return () => (0, _univerjs_design.unmount)(root);
2592
+ }
2593
+
2594
+ //#endregion
2595
+ //#region src/controllers/doc-drawing-printing.controller.ts
2596
+ let DocDrawingPrintingController = class DocDrawingPrintingController extends _univerjs_core.Disposable {
2597
+ constructor(_docPrintInterceptorService, _drawingRenderService, _drawingManagerService, _componetManager, _injector) {
2598
+ super();
2599
+ this._docPrintInterceptorService = _docPrintInterceptorService;
2600
+ this._drawingRenderService = _drawingRenderService;
2601
+ this._drawingManagerService = _drawingManagerService;
2602
+ this._componetManager = _componetManager;
2603
+ this._injector = _injector;
2604
+ this._initPrinting();
2605
+ this._initPrintingDom();
2606
+ }
2607
+ _initPrinting() {
2608
+ this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (_param, pos, next) => {
2609
+ const { unitId, scene } = pos;
2610
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
2611
+ const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
2612
+ if (subUnitData) subUnitData.order.forEach((id) => {
2613
+ const drawing = subUnitData.data[id];
2614
+ if (drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_CHART && drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) this._drawingRenderService.renderDrawing(drawing, scene);
2615
+ });
2616
+ return next();
2617
+ } }));
2618
+ }
2619
+ _initPrintingDom() {
2620
+ this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT, { handler: (disposableCollection, pos, next) => {
2621
+ const { unitId } = pos;
2622
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
2623
+ const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
2624
+ if (subUnitData) {
2625
+ const unmountPrintingFloatDom = mountDocPrintingFloatDom({
2626
+ unitId,
2627
+ floatDomInfos: subUnitData.order.map((id) => {
2628
+ const drawing = subUnitData.data[id];
2629
+ if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART) return {
2630
+ ...drawing,
2631
+ componentKey: this._componetManager.get(_univerjs_core.DOC_DRAWING_PRINTING_COMPONENT_KEY)
2632
+ };
2633
+ if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_DOM) {
2634
+ const printingComponentKey = this._docPrintInterceptorService.getPrintComponent(drawing.componentKey);
2635
+ return {
2636
+ ...drawing,
2637
+ componentKey: this._componetManager.get(printingComponentKey || drawing.componentKey)
2638
+ };
2639
+ }
2640
+ return null;
2641
+ }).filter(Boolean),
2642
+ scene: pos.scene,
2643
+ skeleton: pos.skeleton,
2644
+ offset: pos.offset,
2645
+ bound: pos.bound
2646
+ }, pos.root, this._injector);
2647
+ disposableCollection === null || disposableCollection === void 0 || disposableCollection.add(() => {
2648
+ unmountPrintingFloatDom();
2649
+ });
2650
+ return next(disposableCollection);
2651
+ }
2652
+ } }));
2678
2653
  }
2679
2654
  };
2655
+ DocDrawingPrintingController = __decorate([
2656
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocPrintInterceptorService)),
2657
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_drawing_ui.DrawingRenderService)),
2658
+ __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
2659
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
2660
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
2661
+ ], DocDrawingPrintingController);
2680
2662
 
2681
2663
  //#endregion
2682
- //#region src/views/doc-image-panel/DocDrawingPosition.tsx
2683
- const MIN_OFFSET = -1e3;
2684
- const MAX_OFFSET = 1e3;
2685
- const DocDrawingPosition = (props) => {
2686
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2687
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2688
- const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2689
- const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2690
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2691
- const { drawings } = props;
2692
- const drawingParam = drawings[0];
2693
- if (drawingParam == null) return;
2694
- const { unitId } = drawingParam;
2695
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2696
- const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
2697
- const renderObject = renderManagerService.getRenderById(unitId);
2698
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2699
- if (scene == null) return;
2700
- const transformer = scene.getTransformerByCreate();
2701
- const HORIZONTAL_RELATIVE_FROM = [
2702
- {
2703
- label: localeService.t("docs-drawing-ui.image-position.column"),
2704
- value: String(_univerjs_core.ObjectRelativeFromH.COLUMN)
2705
- },
2706
- {
2707
- label: localeService.t("docs-drawing-ui.image-position.page"),
2708
- value: String(_univerjs_core.ObjectRelativeFromH.PAGE)
2709
- },
2710
- {
2711
- label: localeService.t("docs-drawing-ui.image-position.margin"),
2712
- value: String(_univerjs_core.ObjectRelativeFromH.MARGIN)
2713
- }
2714
- ];
2715
- const VERTICAL_RELATIVE_FROM = [
2716
- {
2717
- label: localeService.t("docs-drawing-ui.image-position.line"),
2718
- value: String(_univerjs_core.ObjectRelativeFromV.LINE),
2719
- disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
2720
- },
2721
- {
2722
- label: localeService.t("docs-drawing-ui.image-position.page"),
2723
- value: String(_univerjs_core.ObjectRelativeFromV.PAGE),
2724
- disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
2725
- },
2726
- {
2727
- label: localeService.t("docs-drawing-ui.image-position.margin"),
2728
- value: String(_univerjs_core.ObjectRelativeFromV.MARGIN),
2729
- disabled: documentFlavor === _univerjs_core.DocumentFlavor.MODERN
2730
- },
2731
- {
2732
- label: localeService.t("docs-drawing-ui.image-position.paragraph"),
2733
- value: String(_univerjs_core.ObjectRelativeFromV.PARAGRAPH)
2664
+ //#region src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
2665
+ function getDocsDrawingPageClipBounds(config) {
2666
+ const { docsLeft, docsTop, pageOffsetLeft, pageOffsetTop, clipOffsetLeft = 0, clipOffsetTop = 0, page } = config;
2667
+ const { pageWidth, pageHeight } = page;
2668
+ if (!Number.isFinite(pageWidth) || !Number.isFinite(pageHeight) || pageWidth <= 0 || pageHeight <= 0) return;
2669
+ return {
2670
+ left: docsLeft + pageOffsetLeft + clipOffsetLeft,
2671
+ top: docsTop + pageOffsetTop + clipOffsetTop,
2672
+ width: pageWidth,
2673
+ height: pageHeight
2674
+ };
2675
+ }
2676
+ function getDocsDrawingClipPage(config) {
2677
+ const { drawing, hostPage, page } = config;
2678
+ if (hostPage == null || drawing.behindText !== true || drawing.transform == null) return page;
2679
+ const { width, height } = drawing.transform;
2680
+ if (width == null || height == null) return page;
2681
+ if (width > page.pageWidth || height > page.pageHeight) return hostPage;
2682
+ const widthRatio = width / hostPage.pageWidth;
2683
+ const heightRatio = height / hostPage.pageHeight;
2684
+ if (widthRatio >= .8 && heightRatio >= .8) return hostPage;
2685
+ return page;
2686
+ }
2687
+ function getDocsPageRelativeDrawingLeft(config) {
2688
+ const { hostPage, positionH, width } = config;
2689
+ if (positionH.relativeFrom !== _univerjs_core.ObjectRelativeFromH.PAGE) return;
2690
+ if (positionH.align === _univerjs_core.AlignTypeH.RIGHT) return hostPage.pageWidth - width;
2691
+ if (positionH.align === _univerjs_core.AlignTypeH.CENTER) return hostPage.pageWidth / 2 - width / 2;
2692
+ if (positionH.posOffset != null) return positionH.posOffset;
2693
+ return 0;
2694
+ }
2695
+ function getDocsPageRelativeDrawingTop(config) {
2696
+ const { hostPage, positionV, height } = config;
2697
+ if (positionV.relativeFrom !== _univerjs_core.ObjectRelativeFromV.PAGE) return;
2698
+ if (positionV.align === _univerjs_core.AlignTypeV.BOTTOM) return hostPage.pageHeight - height;
2699
+ if (positionV.align === _univerjs_core.AlignTypeV.CENTER) return hostPage.pageHeight / 2 - height / 2;
2700
+ if (positionV.posOffset != null) return positionV.posOffset;
2701
+ return 0;
2702
+ }
2703
+ function getDocsPageRelativeDrawingAnchorPage(config) {
2704
+ const { page, clipPage, hostPage } = config;
2705
+ if (hostPage != null && hostPage === clipPage) return hostPage;
2706
+ if (hostPage == null && page === clipPage) return page;
2707
+ }
2708
+ function getDocsDrawingBehindText(config) {
2709
+ const { drawingOrigin, hostPage } = config;
2710
+ if (hostPage != null) return true;
2711
+ return drawingOrigin.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === _univerjs_core.BooleanNumber.TRUE;
2712
+ }
2713
+ function getDocsTableCellDrawingOffset(unitId, table, row, cell) {
2714
+ const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(table.tableId).tableId;
2715
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, sourceTableId);
2716
+ const scrollLeft = hasHorizontalTableViewport(viewport) ? viewport.scrollLeft : 0;
2717
+ return {
2718
+ left: table.left + cell.left - scrollLeft + cell.marginLeft,
2719
+ top: table.top + row.top + cell.marginTop
2720
+ };
2721
+ }
2722
+ function hasHorizontalTableViewport(viewport) {
2723
+ var _viewport$leadingInse, _viewport$trailingIns;
2724
+ return viewport != null && ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
2725
+ }
2726
+ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateController extends _univerjs_core.Disposable {
2727
+ constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
2728
+ super();
2729
+ this._context = _context;
2730
+ this._docSkeletonManagerService = _docSkeletonManagerService;
2731
+ this._commandService = _commandService;
2732
+ this._editorService = _editorService;
2733
+ this._drawingManagerService = _drawingManagerService;
2734
+ this._docRefreshDrawingsService = _docRefreshDrawingsService;
2735
+ this._univerInstanceService = _univerInstanceService;
2736
+ this._lifecycleService = _lifecycleService;
2737
+ _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
2738
+ this._initialize();
2739
+ this._commandExecutedListener();
2740
+ }
2741
+ _initialize() {
2742
+ this._initialRenderRefresh();
2743
+ this._drawingInitializeListener();
2744
+ this._initResize();
2745
+ }
2746
+ _initialRenderRefresh() {
2747
+ this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
2748
+ if (documentSkeleton == null) return;
2749
+ this._refreshDrawing(documentSkeleton);
2750
+ }));
2751
+ this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
2752
+ if (skeleton == null) return;
2753
+ this._refreshDrawing(skeleton);
2754
+ }));
2755
+ }
2756
+ _commandExecutedListener() {
2757
+ const updateCommandList = [_univerjs_docs.RichTextEditingMutation.id, _univerjs_docs_ui.SetDocZoomRatioOperation.id];
2758
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2759
+ if (updateCommandList.includes(command.id)) {
2760
+ const { unitId: commandUnitId } = command.params;
2761
+ const { unitId, mainComponent } = this._context;
2762
+ if (commandUnitId !== unitId) return;
2763
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2764
+ if (skeleton == null) return;
2765
+ if (this._editorService.isEditor(unitId)) {
2766
+ mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
2767
+ return;
2768
+ }
2769
+ this._refreshDrawing(skeleton);
2770
+ }
2771
+ }));
2772
+ }
2773
+ _initResize() {
2774
+ this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.engine.onTransformChange$).pipe((0, rxjs.filter)((evt) => evt.type === _univerjs_engine_render.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize), (0, rxjs.debounceTime)(16)).subscribe(() => {
2775
+ var _scene$getTransformer;
2776
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2777
+ const { scene } = this._context;
2778
+ (_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.refreshControls();
2779
+ this._refreshDrawing(skeleton);
2780
+ }));
2781
+ }
2782
+ _refreshDrawing(skeleton) {
2783
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2784
+ const { mainComponent, unitId } = this._context;
2785
+ const documentComponent = mainComponent;
2786
+ if (!skeletonData) return;
2787
+ const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;
2788
+ if (docsLeft <= -1e4 || docsTop <= -1e4) return;
2789
+ const { pages, skeHeaders, skeFooters } = skeletonData;
2790
+ const updateDrawingMap = {};
2791
+ this._liquid.reset();
2792
+ /**
2793
+ * TODO: @DR-Univer We should not refresh all floating elements, but instead make a diff.
2794
+ */
2795
+ for (let i = 0, len = pages.length; i < len; i++) {
2796
+ const page = pages[i];
2797
+ const { headerId, footerId, pageWidth } = page;
2798
+ if (headerId) {
2799
+ var _skeHeaders$get;
2800
+ const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2801
+ if (headerPage) {
2802
+ this._calculateDrawingPosition(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft, page);
2803
+ this._calculateTableCellDrawingPositions(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
2804
+ }
2805
+ }
2806
+ if (footerId) {
2807
+ var _skeFooters$get;
2808
+ const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2809
+ if (footerPage) {
2810
+ const footerTop = page.pageHeight - page.marginBottom + footerPage.marginTop;
2811
+ this._calculateDrawingPosition(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft, page);
2812
+ this._calculateTableCellDrawingPositions(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2813
+ }
2814
+ }
2815
+ this._calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2816
+ this._calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2817
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2734
2818
  }
2735
- ];
2736
- const [disabled, setDisabled] = (0, react.useState)(true);
2737
- const [hPosition, setHPosition] = (0, react.useState)({
2738
- relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
2739
- posOffset: 0
2740
- });
2741
- const [vPosition, setVPosition] = (0, react.useState)({
2742
- relativeFrom: _univerjs_core.ObjectRelativeFromV.PAGE,
2743
- posOffset: 0
2744
- });
2745
- const [followTextMove, setFollowTextMove] = (0, react.useState)(true);
2746
- const [showPanel, setShowPanel] = (0, react.useState)(true);
2747
- function handlePositionChange(direction, value) {
2748
- var _renderManagerService;
2749
- if (direction === "positionH") setHPosition(value);
2750
- else setVPosition(value);
2751
- const focusDrawings = drawingManagerService.getFocusDrawings();
2752
- if (focusDrawings.length === 0) return;
2753
- const drawings = focusDrawings.map((drawing) => {
2819
+ const updateDrawings = Object.values(updateDrawingMap);
2820
+ for (const drawing of updateDrawings) drawing.hidden = false;
2821
+ const staleNonMultiDrawings = this._getStaleNonMultiDrawings(unitId, updateDrawingMap);
2822
+ const nonMultiDrawings = updateDrawings.filter((drawing) => !drawing.isMultiTransform).concat(staleNonMultiDrawings);
2823
+ const multiDrawings = updateDrawings.filter((drawing) => drawing.isMultiTransform);
2824
+ if (nonMultiDrawings.length > 0) this._drawingManagerService.refreshTransform(nonMultiDrawings);
2825
+ this._handleMultiDrawingsTransform(multiDrawings);
2826
+ }
2827
+ _getStaleNonMultiDrawings(unitId, updateDrawingMap) {
2828
+ var _this$_drawingManager;
2829
+ const drawingData = (_this$_drawingManager = this._drawingManagerService.getDrawingData(unitId, unitId)) !== null && _this$_drawingManager !== void 0 ? _this$_drawingManager : {};
2830
+ return Object.values(drawingData).filter((drawing) => drawing.isMultiTransform !== _univerjs_core.BooleanNumber.TRUE).filter((drawing) => updateDrawingMap[drawing.drawingId] == null).map((drawing) => {
2831
+ var _drawing$transforms, _drawing$isMultiTrans;
2754
2832
  return {
2755
- unitId: drawing.unitId,
2756
- subUnitId: drawing.subUnitId,
2757
- drawingId: drawing.drawingId
2833
+ unitId,
2834
+ subUnitId: unitId,
2835
+ drawingId: drawing.drawingId,
2836
+ behindText: false,
2837
+ hidden: true,
2838
+ transform: drawing.transform,
2839
+ transforms: (_drawing$transforms = drawing.transforms) !== null && _drawing$transforms !== void 0 ? _drawing$transforms : [],
2840
+ isMultiTransform: (_drawing$isMultiTrans = drawing.isMultiTransform) !== null && _drawing$isMultiTrans !== void 0 ? _drawing$isMultiTrans : _univerjs_core.BooleanNumber.FALSE
2758
2841
  };
2759
2842
  });
2760
- commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2761
- unitId: focusDrawings[0].unitId,
2762
- subUnitId: focusDrawings[0].unitId,
2763
- drawings: drawings.map((drawing) => ({
2764
- drawingId: drawing.drawingId,
2765
- key: direction,
2766
- value
2767
- }))
2843
+ }
2844
+ _handleMultiDrawingsTransform(multiDrawings) {
2845
+ const { scene, unitId } = this._context;
2846
+ const transformer = scene.getTransformerByCreate();
2847
+ multiDrawings.forEach((updateParam) => {
2848
+ const param = this._drawingManagerService.getDrawingByParam(updateParam);
2849
+ if (param == null) return;
2850
+ param.transform = updateParam.transform;
2851
+ param.transforms = updateParam.transforms;
2852
+ param.isMultiTransform = updateParam.isMultiTransform;
2768
2853
  });
2769
- const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs_ui.DocSelectionRenderService);
2770
- if (docSelectionRenderService) docSelectionRenderService.blur();
2771
- transformer.refreshControls();
2854
+ const selectedObjectKeys = [...transformer.getSelectedObjectMap().keys()];
2855
+ const allMultiDrawings = Object.values(this._drawingManagerService.getDrawingData(unitId, unitId)).filter((drawing) => drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE);
2856
+ this._drawingManagerService.removeNotification(allMultiDrawings);
2857
+ if (multiDrawings.length > 0) this._drawingManagerService.addNotification(multiDrawings);
2858
+ for (const key of selectedObjectKeys) {
2859
+ const drawingShape = scene.getObject(key);
2860
+ if (drawingShape) transformer.setSelectedControl(drawingShape);
2861
+ }
2772
2862
  }
2773
- function handleHorizontalRelativeFromChange(value) {
2774
- var _renderManagerService2;
2775
- const prevRelativeFrom = hPosition.relativeFrom;
2776
- const prevPosOffset = hPosition.posOffset;
2777
- const relativeFrom = Number(value);
2778
- if (prevRelativeFrom === relativeFrom) return;
2779
- const focusDrawings = drawingManagerService.getFocusDrawings();
2780
- if (focusDrawings.length === 0) return;
2781
- const drawingId = focusDrawings[0].drawingId;
2782
- const unitId = focusDrawings[0].unitId;
2783
- let drawing = null;
2784
- let pageMarginLeft = 0;
2785
- const skeleton = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2786
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2787
- if (skeletonData == null) return;
2788
- const { pages, skeHeaders, skeFooters } = skeletonData;
2789
- for (const page of pages) {
2790
- var _skeHeaders$get, _skeFooters$get;
2791
- const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
2792
- if (skeDrawings.has(drawingId)) {
2793
- drawing = skeDrawings.get(drawingId);
2794
- pageMarginLeft = marginLeft;
2795
- break;
2863
+ _calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft, hostPage, clipOffset) {
2864
+ const { skeDrawings } = page;
2865
+ const pageOffsetLeft = this._liquid.x;
2866
+ const pageOffsetTop = this._liquid.y;
2867
+ this._liquid.translatePagePadding({
2868
+ marginTop,
2869
+ marginLeft
2870
+ });
2871
+ skeDrawings.forEach((drawing) => {
2872
+ const { aLeft, aTop, height, width, angle, drawingId, drawingOrigin } = drawing;
2873
+ const behindText = getDocsDrawingBehindText({
2874
+ drawingOrigin,
2875
+ hostPage
2876
+ });
2877
+ const { isMultiTransform = _univerjs_core.BooleanNumber.FALSE } = drawingOrigin;
2878
+ const clipPage = getDocsDrawingClipPage({
2879
+ drawing: {
2880
+ behindText,
2881
+ transform: {
2882
+ width,
2883
+ height
2884
+ }
2885
+ },
2886
+ hostPage,
2887
+ page
2888
+ });
2889
+ const pageClipBounds = getDocsDrawingPageClipBounds({
2890
+ docsLeft,
2891
+ docsTop,
2892
+ pageOffsetLeft,
2893
+ pageOffsetTop,
2894
+ clipOffsetLeft: clipOffset === null || clipOffset === void 0 ? void 0 : clipOffset.left,
2895
+ clipOffsetTop: clipOffset === null || clipOffset === void 0 ? void 0 : clipOffset.top,
2896
+ page: clipPage
2897
+ });
2898
+ const pageRelativeAnchorPage = getDocsPageRelativeDrawingAnchorPage({
2899
+ page,
2900
+ clipPage,
2901
+ hostPage
2902
+ });
2903
+ const pageRelativeLeft = pageRelativeAnchorPage != null ? getDocsPageRelativeDrawingLeft({
2904
+ hostPage: pageRelativeAnchorPage,
2905
+ positionH: drawingOrigin.docTransform.positionH,
2906
+ width
2907
+ }) : void 0;
2908
+ const pageRelativeTop = pageRelativeAnchorPage != null ? getDocsPageRelativeDrawingTop({
2909
+ hostPage: pageRelativeAnchorPage,
2910
+ positionV: drawingOrigin.docTransform.positionV,
2911
+ height
2912
+ }) : void 0;
2913
+ const transform = {
2914
+ left: (pageRelativeLeft !== null && pageRelativeLeft !== void 0 ? pageRelativeLeft : aLeft) + docsLeft + (pageRelativeLeft == null ? this._liquid.x : pageOffsetLeft),
2915
+ top: (pageRelativeTop !== null && pageRelativeTop !== void 0 ? pageRelativeTop : aTop) + docsTop + (pageRelativeTop == null ? this._liquid.y : pageOffsetTop),
2916
+ width,
2917
+ height,
2918
+ angle,
2919
+ clipBounds: pageClipBounds
2920
+ };
2921
+ if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
2922
+ unitId,
2923
+ subUnitId: unitId,
2924
+ drawingId,
2925
+ behindText,
2926
+ transform,
2927
+ transforms: [transform],
2928
+ isMultiTransform
2929
+ };
2930
+ else if (isMultiTransform === _univerjs_core.BooleanNumber.TRUE) updateDrawingMap[drawingId].transforms.push(transform);
2931
+ });
2932
+ this._liquid.restorePagePadding({
2933
+ marginTop,
2934
+ marginLeft
2935
+ });
2936
+ }
2937
+ _calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, baseMarginTop, baseMarginLeft) {
2938
+ var _page$skeTables;
2939
+ (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
2940
+ table.rows.forEach((row) => {
2941
+ row.cells.forEach((cell) => {
2942
+ const cellOffset = getDocsTableCellDrawingOffset(unitId, table, row, cell);
2943
+ const marginTop = baseMarginTop + cellOffset.top;
2944
+ const marginLeft = baseMarginLeft + cellOffset.left;
2945
+ this._calculateDrawingPosition(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft, void 0, {
2946
+ left: marginLeft,
2947
+ top: marginTop
2948
+ });
2949
+ this._calculateTableCellDrawingPositions(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2950
+ });
2951
+ });
2952
+ });
2953
+ }
2954
+ _drawingInitializeListener() {
2955
+ const init = () => {
2956
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2957
+ if (skeleton == null) return;
2958
+ this._drawingManagerService.initializeNotification(this._context.unitId);
2959
+ this._refreshDrawing(skeleton);
2960
+ };
2961
+ if (this._lifecycleService.stage >= _univerjs_core.LifecycleStages.Rendered) if (this._docSkeletonManagerService.getSkeleton()) init();
2962
+ else setTimeout(init, 500);
2963
+ else this.disposeWithMe(this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((stage) => stage === _univerjs_core.LifecycleStages.Rendered)).subscribe(init));
2964
+ }
2965
+ };
2966
+ DocDrawingTransformUpdateController = __decorate([
2967
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
2968
+ __decorateParam(2, _univerjs_core.ICommandService),
2969
+ __decorateParam(3, _univerjs_docs_ui.IEditorService),
2970
+ __decorateParam(4, _univerjs_drawing.IDrawingManagerService),
2971
+ __decorateParam(5, (0, _univerjs_core.Inject)(DocRefreshDrawingsService)),
2972
+ __decorateParam(6, _univerjs_core.IUniverInstanceService),
2973
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LifecycleService))
2974
+ ], DocDrawingTransformUpdateController);
2975
+
2976
+ //#endregion
2977
+ //#region src/controllers/doc-drawing-transformer-update.controller.ts
2978
+ const INLINE_DRAWING_ANCHOR_KEY_PREFIX = "__InlineDrawingAnchor__";
2979
+ function getDocsTableCellAnchorContext(unitId, cell) {
2980
+ var _row$cells;
2981
+ const row = cell.parent;
2982
+ const table = row === null || row === void 0 ? void 0 : row.parent;
2983
+ const hostPage = table === null || table === void 0 ? void 0 : table.parent;
2984
+ if (!row || !table || !hostPage || !((_row$cells = row.cells) === null || _row$cells === void 0 ? void 0 : _row$cells.includes(cell))) return null;
2985
+ return {
2986
+ cell,
2987
+ hostPage,
2988
+ offset: getDocsTableCellDrawingOffset(unitId, table, row, cell),
2989
+ row,
2990
+ table
2991
+ };
2992
+ }
2993
+ let DocDrawingTransformerController = class DocDrawingTransformerController extends _univerjs_core.Disposable {
2994
+ constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
2995
+ super();
2996
+ this._commandService = _commandService;
2997
+ this._univerInstanceService = _univerInstanceService;
2998
+ this._drawingManagerService = _drawingManagerService;
2999
+ this._renderManagerService = _renderManagerService;
3000
+ _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
3001
+ _defineProperty(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
3002
+ _defineProperty(this, "_transformerCache", /* @__PURE__ */ new Map());
3003
+ _defineProperty(this, "_anchorShape", void 0);
3004
+ this._init();
3005
+ }
3006
+ _init() {
3007
+ this._listenDrawingFocus();
3008
+ }
3009
+ _listenDrawingFocus() {
3010
+ this.disposeWithMe(this._drawingManagerService.add$.subscribe((drawingParams) => {
3011
+ if (drawingParams.length === 0) return;
3012
+ for (const drawingParam of drawingParams) {
3013
+ const { unitId } = drawingParam;
3014
+ if (!this._listenerOnImageMap.has(unitId)) {
3015
+ this._listenTransformerChange(unitId);
3016
+ this._listenerOnImageMap.add(unitId);
3017
+ }
2796
3018
  }
2797
- const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2798
- if (headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.has(drawingId)) {
2799
- drawing = headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.get(drawingId);
2800
- pageMarginLeft = marginLeft;
2801
- break;
3019
+ }));
3020
+ }
3021
+ _listenTransformerChange(unitId) {
3022
+ var _this$_getSceneAndTra;
3023
+ const transformer = (_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.transformer;
3024
+ if (transformer == null) return;
3025
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeStart$.subscribe((state) => {
3026
+ this._transformerCache.clear();
3027
+ const { objects } = state;
3028
+ for (const object of objects.values()) {
3029
+ var _documentDataModel$ge;
3030
+ const { oKey, width, height, left, top, angle } = object;
3031
+ const drawing = this._drawingManagerService.getDrawingOKey(oKey);
3032
+ if (drawing == null) continue;
3033
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(drawing.unitId);
3034
+ const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawing.drawingId];
3035
+ if ((drawingData === null || drawingData === void 0 ? void 0 : drawingData.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) try {
3036
+ object.setOpacity(.2);
3037
+ } catch (e) {}
3038
+ if (drawingData != null) this._transformerCache.set(drawing.drawingId, {
3039
+ drawing: drawingData,
3040
+ top,
3041
+ left,
3042
+ width,
3043
+ height,
3044
+ angle
3045
+ });
2802
3046
  }
2803
- const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2804
- if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
2805
- drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
2806
- pageMarginLeft = marginLeft;
2807
- break;
3047
+ })));
3048
+ const throttleMultipleDrawingUpdate = (0, _univerjs_core.throttle)(this._updateMultipleDrawingDocTransform.bind(this), 50);
3049
+ (0, _univerjs_core.throttle)(this._nonInlineDrawingTransform.bind(this), 50);
3050
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changing$.subscribe((state) => {
3051
+ const { objects, offsetX, offsetY } = state;
3052
+ if (objects.size > 1) throttleMultipleDrawingUpdate(objects);
3053
+ else if (objects.size === 1) {
3054
+ const drawingCache = this._transformerCache.values().next().value;
3055
+ const { width, height, top, left, angle } = objects.values().next().value;
3056
+ if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
3057
+ if (drawingCache && drawingCache.drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE) {}
3058
+ if (drawingCache && drawingCache.drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
2808
3059
  }
2809
- }
2810
- if (drawing == null) return;
2811
- let delta = 0;
2812
- if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) delta -= drawing.columnLeft;
2813
- else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) delta -= pageMarginLeft;
2814
- if (relativeFrom === _univerjs_core.ObjectRelativeFromH.COLUMN) delta += drawing.columnLeft;
2815
- else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.MARGIN) delta += pageMarginLeft;
2816
- else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.PAGE) {}
2817
- handlePositionChange("positionH", {
2818
- relativeFrom,
2819
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2820
- });
3060
+ })));
3061
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeEnd$.subscribe((state) => {
3062
+ const { objects, offsetX, offsetY } = state;
3063
+ for (const object of objects.values()) {
3064
+ const drawing = this._drawingManagerService.getDrawingOKey(object.oKey);
3065
+ if (drawing == null) continue;
3066
+ const drawingCache = this._transformerCache.get(drawing === null || drawing === void 0 ? void 0 : drawing.drawingId);
3067
+ if ((drawingCache === null || drawingCache === void 0 ? void 0 : drawingCache.drawing.layoutType) === _univerjs_core.PositionedObjectLayoutType.INLINE) try {
3068
+ object.setOpacity(1);
3069
+ } catch (e) {}
3070
+ }
3071
+ if (this._anchorShape) this._anchorShape.hide();
3072
+ if (objects.size > 1) this._updateMultipleDrawingDocTransform(objects);
3073
+ else if (objects.size === 1) {
3074
+ const drawingCache = this._transformerCache.values().next().value;
3075
+ const object = objects.values().next().value;
3076
+ const { width, height, top, left, angle } = object;
3077
+ if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
3078
+ if (drawingCache && drawingCache.drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) {
3079
+ if (width !== drawingCache.width || height !== drawingCache.height || angle !== drawingCache.angle) this._updateDrawingSize(drawingCache, object);
3080
+ else if (offsetX != null && offsetY != null) this._moveInlineDrawing(drawingCache.drawing, offsetX, offsetY);
3081
+ } else if (drawingCache) this._nonInlineDrawingTransform(drawingCache.drawing, object);
3082
+ }
3083
+ this._transformerCache.clear();
3084
+ })));
2821
3085
  }
2822
- function handleVerticalRelativeFromChange(value) {
2823
- var _renderManagerService3, _renderManagerService4, _documentDataModel$ge, _glyph$parent, _column$parent;
2824
- const prevRelativeFrom = vPosition.relativeFrom;
2825
- const prevPosOffset = vPosition.posOffset;
2826
- const relativeFrom = Number(value);
2827
- if (prevRelativeFrom === relativeFrom) return;
2828
- const focusDrawings = drawingManagerService.getFocusDrawings();
2829
- if (focusDrawings.length === 0) return;
2830
- const { drawingId, unitId } = focusDrawings[0];
2831
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2832
- const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
2833
- const docSelectionRenderService = (_renderManagerService4 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService4 === void 0 ? void 0 : _renderManagerService4.with(_univerjs_docs_ui.DocSelectionRenderService);
2834
- const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
2835
- const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
2836
- const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId).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);
2837
- if (drawing == null || skeleton == null || docSelectionRenderService == null) return;
2838
- const { startIndex } = drawing;
2839
- const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
2840
- const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
2841
- const column = line === null || line === void 0 ? void 0 : line.parent;
2842
- 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);
2843
- const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
2844
- if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) return;
2845
- let delta = 0;
2846
- if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH) delta -= paragraphStartLine.top;
2847
- else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) delta -= line.top;
2848
- else if (prevRelativeFrom === _univerjs_core.ObjectRelativeFromV.PAGE) delta += page.marginTop;
2849
- if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH) delta += paragraphStartLine.top;
2850
- else if (relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) delta += line.top;
2851
- else if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PAGE) delta -= page.marginTop;
2852
- handlePositionChange("positionV", {
2853
- relativeFrom,
2854
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
3086
+ _updateMultipleDrawingDocTransform(objects) {
3087
+ if (objects.size < 1) return;
3088
+ const drawings = [];
3089
+ let unitId;
3090
+ let subUnitId;
3091
+ for (const object of objects.values()) {
3092
+ const { oKey, left, top, angle } = object;
3093
+ let { width, height } = object;
3094
+ const drawing = this._drawingManagerService.getDrawingOKey(oKey);
3095
+ if (drawing == null) continue;
3096
+ if (unitId == null) unitId = drawing.unitId;
3097
+ if (subUnitId == null) subUnitId = drawing.subUnitId;
3098
+ const drawingCache = this._transformerCache.get(drawing.drawingId);
3099
+ if (drawingCache == null) continue;
3100
+ const { drawing: drawingData, top: oldTop, left: oldLeft, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
3101
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawingData);
3102
+ width = Math.min(width, maxWidth);
3103
+ height = Math.min(height, maxHeight);
3104
+ if (oldWidth !== width || oldHeight !== height) drawings.push({
3105
+ drawingId: drawing.drawingId,
3106
+ key: "size",
3107
+ value: {
3108
+ width,
3109
+ height
3110
+ }
3111
+ });
3112
+ if (oldAngle !== angle) drawings.push({
3113
+ drawingId: drawing.drawingId,
3114
+ key: "angle",
3115
+ value: angle
3116
+ });
3117
+ if (oldTop !== top || oldLeft !== left) {
3118
+ const verticalDelta = top - oldTop;
3119
+ const horizontalDelta = left - oldLeft;
3120
+ if (verticalDelta !== 0) drawings.push({
3121
+ drawingId: drawing.drawingId,
3122
+ key: "positionV",
3123
+ value: {
3124
+ relativeFrom: drawingData.docTransform.positionV.relativeFrom,
3125
+ posOffset: drawingData.docTransform.positionV.posOffset + verticalDelta
3126
+ }
3127
+ });
3128
+ if (horizontalDelta !== 0) drawings.push({
3129
+ drawingId: drawing.drawingId,
3130
+ key: "positionH",
3131
+ value: {
3132
+ relativeFrom: drawingData.docTransform.positionH.relativeFrom,
3133
+ posOffset: drawingData.docTransform.positionH.posOffset + horizontalDelta
3134
+ }
3135
+ });
3136
+ }
3137
+ }
3138
+ if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
3139
+ unitId,
3140
+ subUnitId,
3141
+ drawings
2855
3142
  });
2856
3143
  }
2857
- function updateState(drawingParam) {
2858
- var _snapshot$drawings;
2859
- const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
2860
- const drawing = snapshot === null || snapshot === void 0 || (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingParam.drawingId];
2861
- if (drawing == null) return;
2862
- const { layoutType } = drawing;
2863
- const { positionH, positionV } = drawing.docTransform;
2864
- setHPosition(positionH);
2865
- setVPosition(positionV);
2866
- setDisabled(layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE);
2867
- setFollowTextMove(positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE);
2868
- }
2869
- function updateFocusDrawingState() {
2870
- const focusDrawings = drawingManagerService.getFocusDrawings();
2871
- if (focusDrawings.length === 0) return;
2872
- updateState(focusDrawings[0]);
3144
+ _updateDrawingAnchor(objects) {
3145
+ if (this._transformerCache.size !== 1) return;
3146
+ const drawingCache = this._transformerCache.values().next().value;
3147
+ const object = objects.values().next().value;
3148
+ this._getDrawingAnchor(drawingCache.drawing, object);
2873
3149
  }
2874
- function handleFollowTextMoveCheck(val) {
2875
- setFollowTextMove(val);
2876
- handleVerticalRelativeFromChange(val ? String(_univerjs_core.ObjectRelativeFromV.PARAGRAPH) : String(_univerjs_core.ObjectRelativeFromV.PAGE));
3150
+ _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
3151
+ var _this$_getInlineDrawi;
3152
+ if (this._transformerCache.size !== 1) return;
3153
+ const { contentBoxPointGroup } = (_this$_getInlineDrawi = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) !== null && _this$_getInlineDrawi !== void 0 ? _this$_getInlineDrawi : {};
3154
+ if (contentBoxPointGroup == null) return;
3155
+ this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2877
3156
  }
2878
- (0, react.useEffect)(() => {
2879
- updateFocusDrawingState();
2880
- const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2881
- if (drawingParams.length === 0) {
2882
- setShowPanel(false);
2883
- return;
2884
- }
2885
- setShowPanel(true);
2886
- updateState(drawingParams[0]);
2887
- });
2888
- const mutationListener = commandService.onCommandExecuted(async (command) => {
2889
- if (command.id === _univerjs_docs.RichTextEditingMutation.id) updateFocusDrawingState();
3157
+ _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
3158
+ var _this$_renderManagerS, _getOneTextSelectionR;
3159
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3160
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3161
+ if (currentRender == null) return;
3162
+ const { mainComponent, scene } = currentRender;
3163
+ const documentComponent = mainComponent;
3164
+ const activeViewport = scene.getViewports()[0];
3165
+ const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = documentComponent.getOffsetConfig();
3166
+ let glyphAnchor = null;
3167
+ let isBack = false;
3168
+ let segmentPageIndex = -1;
3169
+ let segmentId = "";
3170
+ const HALF = .5;
3171
+ const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
3172
+ if (coord == null) return;
3173
+ const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocSelectionRenderService);
3174
+ if (docSelectionRenderService == null) return;
3175
+ const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3176
+ strict: false,
3177
+ segmentId: docSelectionRenderService.getSegment(),
3178
+ segmentPage: docSelectionRenderService.getSegmentPage()
2890
3179
  });
2891
- return () => {
2892
- subscription.unsubscribe();
2893
- mutationListener.dispose();
3180
+ if (nodeInfo) {
3181
+ const { node, ratioX, segmentPage, segmentId: nodeSegmentId } = nodeInfo;
3182
+ isBack = ratioX < HALF;
3183
+ glyphAnchor = node;
3184
+ segmentPageIndex = segmentPage;
3185
+ segmentId = nodeSegmentId;
3186
+ }
3187
+ if (glyphAnchor == null) return;
3188
+ const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex);
3189
+ const docObject = this._getDocObject();
3190
+ if (nodePosition == null || skeleton == null || docObject == null) return;
3191
+ const positionWithIsBack = {
3192
+ ...nodePosition,
3193
+ isBack
2894
3194
  };
2895
- }, []);
2896
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2897
- className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2898
- children: [
2899
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
2900
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2901
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.title") })
2902
- }),
2903
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2904
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2905
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
2906
- }),
2907
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2908
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2909
- 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, {
2910
- min: MIN_OFFSET,
2911
- max: MAX_OFFSET,
2912
- precision: 1,
2913
- disabled,
2914
- value: hPosition.posOffset,
2915
- onChange: (val) => {
2916
- handlePositionChange("positionH", {
2917
- relativeFrom: hPosition.relativeFrom,
2918
- posOffset: val
2919
- });
2920
- }
2921
- })] }), /* @__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, {
2922
- value: String(hPosition.relativeFrom),
2923
- disabled,
2924
- options: HORIZONTAL_RELATIVE_FROM,
2925
- onChange: handleHorizontalRelativeFromChange
2926
- })] })]
2927
- }),
2928
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2929
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2930
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
2931
- }),
2932
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2933
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2934
- 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, {
2935
- min: MIN_OFFSET,
2936
- max: MAX_OFFSET,
2937
- precision: 1,
2938
- disabled,
2939
- value: vPosition.posOffset,
2940
- onChange: (val) => {
2941
- handlePositionChange("positionV", {
2942
- relativeFrom: vPosition.relativeFrom,
2943
- posOffset: val
2944
- });
2945
- }
2946
- })] }), /* @__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, {
2947
- disabled,
2948
- value: String(vPosition.relativeFrom),
2949
- options: VERTICAL_RELATIVE_FROM,
2950
- onChange: handleVerticalRelativeFromChange
2951
- })] })]
2952
- }),
2953
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2954
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2955
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
2956
- }),
2957
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2958
- disabled,
2959
- checked: followTextMove,
2960
- onChange: handleFollowTextMoveCheck,
2961
- children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
2962
- }) })
2963
- ]
2964
- });
2965
- };
2966
-
2967
- //#endregion
2968
- //#region src/views/doc-image-panel/DocDrawingTextWrap.tsx
2969
- const MIN_MARGIN = 0;
2970
- const MAX_MARGIN = 100;
2971
- const DocDrawingTextWrap = (props) => {
2972
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2973
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2974
- const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2975
- const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2976
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2977
- const { drawings } = props;
2978
- const drawingParam = drawings[0];
2979
- if (drawingParam == null) return null;
2980
- const { unitId } = drawingParam;
2981
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2982
- const renderObject = renderManagerService.getRenderById(unitId);
2983
- if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
2984
- const [disableWrapText, setDisableWrapText] = (0, react.useState)(true);
2985
- const [disableDistTB, setDisableDistTB] = (0, react.useState)(true);
2986
- const [disableDistLR, setDisableDistLR] = (0, react.useState)(true);
2987
- const [wrappingStyle, setWrappingStyle] = (0, react.useState)("inline");
2988
- const [wrapText, setWrapText] = (0, react.useState)("");
2989
- const [distToText, setDistToText] = (0, react.useState)({
2990
- distT: 0,
2991
- distL: 0,
2992
- distB: 0,
2993
- distR: 0
2994
- });
2995
- const [showPanel, setShowPanel] = (0, react.useState)(true);
2996
- function handleWrappingStyleChange(value) {
2997
- setWrappingStyle(value);
2998
- const focusDrawings = drawingManagerService.getFocusDrawings();
2999
- if (focusDrawings.length === 0) return;
3000
- const { unitId, subUnitId } = focusDrawings[0];
3001
- const drawings = focusDrawings.map(({ unitId, subUnitId, drawingId }) => ({
3002
- unitId,
3003
- subUnitId,
3004
- drawingId
3005
- }));
3006
- commandService.executeCommand(UpdateDocDrawingWrappingStyleCommand.id, {
3195
+ const { cursorList, contentBoxPointGroup } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3196
+ const { startOffset } = (_getOneTextSelectionR = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
3197
+ if (startOffset == null) return;
3198
+ return {
3199
+ offset: startOffset,
3200
+ contentBoxPointGroup,
3201
+ segmentId,
3202
+ segmentPage: segmentPageIndex
3203
+ };
3204
+ }
3205
+ _getDrawingAnchor(drawing, object) {
3206
+ var _this$_renderManagerS2, _glyphAnchor$parent, _column$lines$find, _column$parent, _tableCellContext$hos, _getOneTextSelectionR2;
3207
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3208
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3209
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3210
+ if (skeletonData == null || currentRender == null) return;
3211
+ const { pages, skeHeaders, skeFooters } = skeletonData;
3212
+ const { mainComponent, scene } = currentRender;
3213
+ const documentComponent = mainComponent;
3214
+ const activeViewport = scene.getViewports()[0];
3215
+ const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig();
3216
+ const { left, top, angle } = object;
3217
+ let { width, height } = object;
3218
+ const { positionV, positionH } = drawing.docTransform;
3219
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
3220
+ width = Math.min(width, maxWidth);
3221
+ height = Math.min(height, maxHeight);
3222
+ let glyphAnchor = null;
3223
+ let segmentId = "";
3224
+ let segmentPage = -1;
3225
+ const isBack = false;
3226
+ const docTransform = {
3227
+ ...drawing.docTransform,
3228
+ size: {
3229
+ width,
3230
+ height
3231
+ },
3232
+ angle
3233
+ };
3234
+ const { x, y } = scene.getViewportScrollXY(activeViewport);
3235
+ const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
3236
+ if (coord == null) return;
3237
+ const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
3238
+ if (docSelectionRenderService == null) return;
3239
+ const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3240
+ strict: false,
3241
+ segmentId: docSelectionRenderService.getSegment(),
3242
+ segmentPage: docSelectionRenderService.getSegmentPage()
3243
+ });
3244
+ if (nodeInfo) {
3245
+ const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
3246
+ glyphAnchor = node;
3247
+ segmentPage = segmentPageIndex;
3248
+ segmentId = nodeSegmentId;
3249
+ }
3250
+ if (glyphAnchor == null) return;
3251
+ const line = (_glyphAnchor$parent = glyphAnchor.parent) === null || _glyphAnchor$parent === void 0 ? void 0 : _glyphAnchor$parent.parent;
3252
+ const column = line === null || line === void 0 ? void 0 : line.parent;
3253
+ const paragraphStartLine = (_column$lines$find = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) !== null && _column$lines$find !== void 0 ? _column$lines$find : column === null || column === void 0 ? void 0 : column.lines[0];
3254
+ const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
3255
+ if (line == null || column == null || paragraphStartLine == null || page == null) return;
3256
+ this._liquid.reset();
3257
+ const tableCellContext = page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? getDocsTableCellAnchorContext(drawing.unitId, page) : null;
3258
+ const anchorPage = (_tableCellContext$hos = tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) !== null && _tableCellContext$hos !== void 0 ? _tableCellContext$hos : page;
3259
+ const pageType = anchorPage.type;
3260
+ for (const p of pages) {
3261
+ const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p;
3262
+ const pIndex = pages.indexOf(p);
3263
+ if (segmentPage > -1 && pIndex === segmentPage) {
3264
+ switch (pageType) {
3265
+ case _univerjs_engine_render.DocumentSkeletonPageType.HEADER: {
3266
+ var _skeHeaders$get;
3267
+ const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
3268
+ if (headerSke) this._liquid.translatePagePadding({
3269
+ marginTop: headerSke.marginTop,
3270
+ marginLeft
3271
+ });
3272
+ else throw new Error("header skeleton not found");
3273
+ break;
3274
+ }
3275
+ case _univerjs_engine_render.DocumentSkeletonPageType.FOOTER: {
3276
+ var _skeFooters$get;
3277
+ const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
3278
+ if (footerSke) this._liquid.translatePagePadding({
3279
+ marginTop: pageHeight - marginBottom + footerSke.marginTop,
3280
+ marginLeft
3281
+ });
3282
+ else throw new Error("footer skeleton not found");
3283
+ break;
3284
+ }
3285
+ default:
3286
+ this._liquid.translatePagePadding(p);
3287
+ break;
3288
+ }
3289
+ break;
3290
+ }
3291
+ this._liquid.translatePagePadding(p);
3292
+ if (p === anchorPage) break;
3293
+ this._liquid.restorePagePadding(p);
3294
+ this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
3295
+ }
3296
+ if (tableCellContext) this._liquid.translate(tableCellContext.offset.left, tableCellContext.offset.top);
3297
+ if (positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) glyphAnchor = line.divides[0].glyphGroup[0];
3298
+ else {
3299
+ var _paragraphStartLine$d, _paragraphStartLine$d2;
3300
+ glyphAnchor = (_paragraphStartLine$d = (_paragraphStartLine$d2 = paragraphStartLine.divides) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2[0]) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2.glyphGroup) === null || _paragraphStartLine$d2 === void 0 ? void 0 : _paragraphStartLine$d2[0]) !== null && _paragraphStartLine$d !== void 0 ? _paragraphStartLine$d : glyphAnchor;
3301
+ }
3302
+ docTransform.positionH = {
3303
+ relativeFrom: positionH.relativeFrom,
3304
+ posOffset: left - this._liquid.x - docsLeft
3305
+ };
3306
+ switch (positionH.relativeFrom) {
3307
+ case _univerjs_core.ObjectRelativeFromH.MARGIN:
3308
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
3309
+ break;
3310
+ case _univerjs_core.ObjectRelativeFromH.COLUMN:
3311
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - column.left;
3312
+ break;
3313
+ }
3314
+ docTransform.positionV = {
3315
+ relativeFrom: positionV.relativeFrom,
3316
+ posOffset: top - this._liquid.y - docsTop
3317
+ };
3318
+ switch (positionV.relativeFrom) {
3319
+ case _univerjs_core.ObjectRelativeFromV.PAGE:
3320
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
3321
+ break;
3322
+ case _univerjs_core.ObjectRelativeFromV.LINE:
3323
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - line.top;
3324
+ break;
3325
+ case _univerjs_core.ObjectRelativeFromV.PARAGRAPH:
3326
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - paragraphStartLine.top;
3327
+ break;
3328
+ }
3329
+ if (glyphAnchor == null) return;
3330
+ const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage);
3331
+ const docObject = this._getDocObject();
3332
+ if (nodePosition == null || skeleton == null || docObject == null) return;
3333
+ const positionWithIsBack = {
3334
+ ...nodePosition,
3335
+ isBack
3336
+ };
3337
+ const { cursorList } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3338
+ const { startOffset } = (_getOneTextSelectionR2 = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
3339
+ if (startOffset == null) return;
3340
+ return {
3341
+ offset: startOffset,
3342
+ docTransform,
3343
+ segmentId,
3344
+ segmentPage
3345
+ };
3346
+ }
3347
+ _updateDrawingSize(drawingCache, object) {
3348
+ const drawings = [];
3349
+ const { drawing, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
3350
+ const { unitId, subUnitId } = drawing;
3351
+ let { width, height, angle } = object;
3352
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
3353
+ width = Math.min(maxWidth, width);
3354
+ height = Math.min(maxHeight, height);
3355
+ if (width !== oldWidth || height !== oldHeight) drawings.push({
3356
+ drawingId: drawing.drawingId,
3357
+ key: "size",
3358
+ value: {
3359
+ width,
3360
+ height
3361
+ }
3362
+ });
3363
+ if (angle !== oldAngle) drawings.push({
3364
+ drawingId: drawing.drawingId,
3365
+ key: "angle",
3366
+ value: angle
3367
+ });
3368
+ if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
3007
3369
  unitId,
3008
3370
  subUnitId,
3009
- drawings,
3010
- wrappingStyle: value
3371
+ drawings
3011
3372
  });
3012
3373
  }
3013
- function handleWrapTextChange(value) {
3014
- setWrapText(value);
3015
- const focusDrawings = drawingManagerService.getFocusDrawings();
3016
- if (focusDrawings.length === 0) return;
3017
- const drawings = focusDrawings.map((drawing) => {
3018
- return {
3019
- unitId: drawing.unitId,
3020
- subUnitId: drawing.subUnitId,
3021
- drawingId: drawing.drawingId
3022
- };
3023
- });
3024
- commandService.executeCommand(UpdateDocDrawingWrapTextCommand.id, {
3025
- unitId: focusDrawings[0].unitId,
3026
- subUnitId: focusDrawings[0].unitId,
3027
- drawings,
3028
- wrapText: value
3374
+ _moveInlineDrawing(drawing, offsetX, offsetY) {
3375
+ const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY);
3376
+ const { offset, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3377
+ return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
3378
+ unitId: drawing.unitId,
3379
+ subUnitId: drawing.unitId,
3380
+ drawing,
3381
+ offset,
3382
+ segmentId,
3383
+ segmentPage,
3384
+ needRefreshDrawings: offset == null
3029
3385
  });
3030
3386
  }
3031
- function handleDistToTextChange(value, direction) {
3032
- if (value == null) return;
3033
- setDistToText({
3034
- ...distToText,
3035
- [direction]: value
3036
- });
3037
- const focusDrawings = drawingManagerService.getFocusDrawings();
3038
- if (focusDrawings.length === 0) return;
3039
- const drawings = focusDrawings.map((drawing) => {
3040
- return {
3041
- unitId: drawing.unitId,
3042
- subUnitId: drawing.subUnitId,
3043
- drawingId: drawing.drawingId
3044
- };
3045
- });
3046
- commandService.executeCommand(UpdateDocDrawingDistanceCommand.id, {
3047
- unitId: focusDrawings[0].unitId,
3048
- subUnitId: focusDrawings[0].unitId,
3049
- drawings,
3050
- dist: { [direction]: value }
3387
+ _limitDrawingInPage(drawing, object) {
3388
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3389
+ const { left, top, width, height, angle } = object;
3390
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3391
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3392
+ const { pages } = skeletonData !== null && skeletonData !== void 0 ? skeletonData : {};
3393
+ if (skeletonData == null || currentRender == null || pages == null) return {
3394
+ left,
3395
+ top,
3396
+ width,
3397
+ height,
3398
+ angle
3399
+ };
3400
+ const { mainComponent } = currentRender;
3401
+ const { top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = mainComponent;
3402
+ let newTop = top;
3403
+ this._liquid.reset();
3404
+ for (const page of pages) {
3405
+ const { marginBottom, pageHeight } = page;
3406
+ const nextPage = pages[pages.indexOf(page) + 1];
3407
+ if (nextPage == null) continue;
3408
+ if (_univerjs_core.Tools.hasIntersectionBetweenTwoRanges(top, top + height, this._liquid.y + docsTop + pageHeight - marginBottom, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop)) if (top + height / 2 < this._liquid.y + docsTop + pageHeight + pageMarginTop / 2) newTop = Math.min(top, this._liquid.y + docsTop + pageHeight - marginBottom - height);
3409
+ else newTop = Math.max(top, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop);
3410
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
3411
+ }
3412
+ return {
3413
+ left,
3414
+ top: newTop,
3415
+ width,
3416
+ height,
3417
+ angle
3418
+ };
3419
+ }
3420
+ _nonInlineDrawingTransform(drawing, object, isMoving = false) {
3421
+ const objectPosition = drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
3422
+ if (isMoving && objectPosition.top !== object.top) return;
3423
+ const anchor = this._getDrawingAnchor(drawing, objectPosition);
3424
+ const { offset, docTransform, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3425
+ if (offset == null || docTransform == null) return this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[drawing.drawingId, object]]));
3426
+ return this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
3427
+ unitId: drawing.unitId,
3428
+ subUnitId: drawing.unitId,
3429
+ drawing,
3430
+ offset,
3431
+ docTransform,
3432
+ segmentId,
3433
+ segmentPage
3051
3434
  });
3052
3435
  }
3053
- function updateFocusDrawingState() {
3054
- const focusDrawings = drawingManagerService.getFocusDrawings();
3055
- if (focusDrawings.length === 0) return;
3056
- updateState(focusDrawings[0]);
3436
+ _getSceneAndTransformerByDrawingSearch(unitId) {
3437
+ if (unitId == null) return;
3438
+ const renderObject = this._renderManagerService.getRenderById(unitId);
3439
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3440
+ if (scene == null) return;
3441
+ return {
3442
+ scene,
3443
+ transformer: scene.getTransformerByCreate()
3444
+ };
3057
3445
  }
3058
- function updateState(drawingParam) {
3059
- var _documentDataModel$ge;
3060
- const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingParam.drawingId];
3061
- if (drawing == null) return;
3062
- const { distT = 0, distL = 0, distB = 0, distR = 0, layoutType = _univerjs_core.PositionedObjectLayoutType.INLINE, behindDoc = _univerjs_core.BooleanNumber.FALSE, wrapText = _univerjs_core.WrapTextType.BOTH_SIDES } = drawing;
3063
- setDistToText({
3064
- distT,
3065
- distL,
3066
- distB,
3067
- distR
3068
- });
3069
- setWrapText(wrapText);
3070
- setDisableWrapText(layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE);
3071
- if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) setDisableDistTB(true);
3072
- else setDisableDistTB(false);
3073
- if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
3074
- else setDisableDistLR(false);
3075
- if (layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === _univerjs_core.BooleanNumber.TRUE) setWrappingStyle("behindText");
3076
- else setWrappingStyle("inFrontOfText");
3077
- else switch (layoutType) {
3078
- case _univerjs_core.PositionedObjectLayoutType.INLINE:
3079
- setWrappingStyle("inline");
3080
- break;
3081
- case _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE:
3082
- setWrappingStyle("wrapSquare");
3083
- break;
3084
- case _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
3085
- setWrappingStyle("wrapTopAndBottom");
3086
- break;
3087
- default: throw new Error(`Unsupported layout type: ${layoutType}`);
3446
+ _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
3447
+ const { documentTransform } = document.getOffsetConfig();
3448
+ const originCoord = viewport.transformVector2SceneCoord(_univerjs_engine_render.Vector2.FromArray([evtOffsetX, evtOffsetY]));
3449
+ if (!originCoord) return;
3450
+ return documentTransform.clone().invert().applyPoint(originCoord);
3451
+ }
3452
+ _createOrUpdateInlineAnchor(unitId, pointsGroup) {
3453
+ const currentRender = this._renderManagerService.getRenderById(unitId);
3454
+ if (currentRender == null) return;
3455
+ const { mainComponent, scene } = currentRender;
3456
+ const { docsLeft, docsTop } = mainComponent.getOffsetConfig();
3457
+ const { left: boundingLeft, top: boundingTop, height } = (0, _univerjs_docs_ui.getAnchorBounding)(pointsGroup);
3458
+ const left = boundingLeft + docsLeft;
3459
+ const top = boundingTop + docsTop;
3460
+ if (this._anchorShape) {
3461
+ this._anchorShape.transformByState({
3462
+ left,
3463
+ top,
3464
+ height
3465
+ });
3466
+ this._anchorShape.show();
3467
+ return;
3088
3468
  }
3469
+ const anchor = new _univerjs_engine_render.Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + (0, _univerjs_core.generateRandomId)(6), {
3470
+ left,
3471
+ top,
3472
+ height,
3473
+ strokeWidth: 2,
3474
+ stroke: (0, _univerjs_engine_render.getColor)(_univerjs_core.COLORS.darkgray, 1),
3475
+ evented: false
3476
+ });
3477
+ this._anchorShape = anchor;
3478
+ scene.addObject(anchor, _univerjs_docs_ui.TEXT_RANGE_LAYER_INDEX);
3089
3479
  }
3090
- (0, react.useEffect)(() => {
3091
- updateFocusDrawingState();
3092
- const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
3093
- if (drawingParams.length === 0) {
3094
- setShowPanel(false);
3095
- return;
3480
+ _getDocObject() {
3481
+ return (0, _univerjs_docs_ui.getDocObject)(this._univerInstanceService, this._renderManagerService);
3482
+ }
3483
+ _getPageContentSize(drawing) {
3484
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3485
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3486
+ const MAX_WIDTH = 500;
3487
+ const MAX_HEIGHT = 500;
3488
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3489
+ if (skeletonData == null || currentRender == null) return {
3490
+ width: MAX_WIDTH,
3491
+ height: MAX_HEIGHT
3492
+ };
3493
+ const { pages } = skeletonData;
3494
+ let page = null;
3495
+ for (const p of pages) {
3496
+ const { skeDrawings } = p;
3497
+ if (skeDrawings.has(drawing.drawingId)) {
3498
+ page = p;
3499
+ break;
3096
3500
  }
3097
- setShowPanel(true);
3098
- updateState(drawingParams[0]);
3099
- });
3100
- const mutationListener = commandService.onCommandExecuted(async (command) => {
3101
- if (command.id === _univerjs_docs.RichTextEditingMutation.id) updateFocusDrawingState();
3102
- });
3103
- return () => {
3104
- subscription.unsubscribe();
3105
- mutationListener.dispose();
3501
+ }
3502
+ if (page) {
3503
+ const { pageWidth, pageHeight, marginLeft, marginBottom, marginRight, marginTop } = page;
3504
+ return {
3505
+ width: Math.max(MAX_WIDTH, pageWidth - marginLeft - marginRight),
3506
+ height: Math.max(MAX_HEIGHT, pageHeight - marginTop - marginBottom)
3507
+ };
3508
+ } else return {
3509
+ width: MAX_WIDTH,
3510
+ height: MAX_HEIGHT
3106
3511
  };
3107
- }, []);
3108
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3109
- className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
3110
- children: [
3111
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
3112
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3113
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.title") })
3114
- }),
3115
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3116
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3117
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrappingStyle") })
3118
- }),
3119
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
3120
- value: wrappingStyle,
3121
- onChange: handleWrappingStyleChange,
3122
- direction: "vertical",
3123
- children: [
3124
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3125
- value: "inline",
3126
- children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
3127
- }),
3128
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3129
- value: "wrapSquare",
3130
- children: localeService.t("docs-drawing-ui.image-text-wrap.square")
3131
- }),
3132
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3133
- value: "wrapTopAndBottom",
3134
- children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
3135
- }),
3136
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3137
- value: "behindText",
3138
- children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
3139
- }),
3140
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3141
- value: "inFrontOfText",
3142
- children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
3143
- })
3144
- ]
3145
- }) }),
3146
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3147
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3148
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrapText") })
3149
- }),
3150
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
3151
- disabled: disableWrapText,
3152
- value: wrapText,
3153
- onChange: handleWrapTextChange,
3154
- direction: "horizontal",
3155
- children: [
3156
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3157
- value: _univerjs_core.WrapTextType.BOTH_SIDES,
3158
- children: localeService.t("docs-drawing-ui.image-text-wrap.bothSide")
3159
- }),
3160
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3161
- value: _univerjs_core.WrapTextType.LEFT,
3162
- children: localeService.t("docs-drawing-ui.image-text-wrap.leftOnly")
3163
- }),
3164
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
3165
- value: _univerjs_core.WrapTextType.RIGHT,
3166
- children: localeService.t("docs-drawing-ui.image-text-wrap.rightOnly")
3167
- })
3168
- ]
3169
- }) }),
3170
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3171
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3172
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.distanceFromText") })
3173
- }),
3174
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3175
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
3176
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.top") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
3177
- min: MIN_MARGIN,
3178
- max: MAX_MARGIN,
3179
- disabled: disableDistTB,
3180
- precision: 1,
3181
- value: distToText.distT,
3182
- onChange: (val) => {
3183
- handleDistToTextChange(val, "distT");
3184
- }
3185
- })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.left") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
3186
- min: MIN_MARGIN,
3187
- max: MAX_MARGIN,
3188
- disabled: disableDistLR,
3189
- precision: 1,
3190
- value: distToText.distL,
3191
- onChange: (val) => {
3192
- handleDistToTextChange(val, "distL");
3193
- }
3194
- })] })]
3195
- }),
3196
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3197
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
3198
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.bottom") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
3199
- min: MIN_MARGIN,
3200
- max: MAX_MARGIN,
3201
- disabled: disableDistTB,
3202
- precision: 1,
3203
- value: distToText.distB,
3204
- onChange: (val) => {
3205
- handleDistToTextChange(val, "distB");
3206
- }
3207
- })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.right") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
3208
- min: MIN_MARGIN,
3209
- max: MAX_MARGIN,
3210
- disabled: disableDistLR,
3211
- precision: 1,
3212
- value: distToText.distR,
3213
- onChange: (val) => {
3214
- handleDistToTextChange(val, "distR");
3215
- }
3216
- })] })]
3217
- })
3218
- ]
3219
- });
3512
+ }
3220
3513
  };
3514
+ DocDrawingTransformerController = __decorate([
3515
+ __decorateParam(0, _univerjs_core.ICommandService),
3516
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
3517
+ __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
3518
+ __decorateParam(3, _univerjs_engine_render.IRenderManagerService)
3519
+ ], DocDrawingTransformerController);
3221
3520
 
3222
3521
  //#endregion
3223
- //#region src/views/doc-image-panel/DocDrawingPanel.tsx
3224
- const DocDrawingPanel = () => {
3225
- const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3226
- const [drawings, setDrawings] = (0, react.useState)(drawingManagerService.getFocusDrawings());
3227
- (0, react.useEffect)(() => {
3228
- const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
3229
- setDrawings(drawings);
3230
- });
3231
- return () => {
3232
- focusDispose.unsubscribe();
3233
- };
3234
- }, []);
3235
- return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3236
- className: "univer-text-sm",
3237
- children: [
3238
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_drawing_ui.DrawingCommonPanel, {
3239
- drawings,
3240
- hasAlign: false,
3241
- hasCropper: true,
3242
- hasGroup: false,
3243
- hasTransform: false
3244
- }),
3245
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocDrawingTextWrap, { drawings }),
3246
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocDrawingPosition, { drawings })
3247
- ]
3248
- });
3522
+ //#region src/menu/schema.ts
3523
+ const menuSchema = {
3524
+ [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
3525
+ order: 0,
3526
+ menuItemFactory: ImageMenuFactory,
3527
+ [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3528
+ order: 0,
3529
+ menuItemFactory: UploadFloatImageMenuFactory
3530
+ }
3531
+ } },
3532
+ [_univerjs_ui.ContextMenuPosition.PARAGRAPH]: {
3533
+ [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [_univerjs_docs_ui.INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3534
+ order: 5,
3535
+ menuItemFactory: UploadFloatImageMenuFactory
3536
+ } } },
3537
+ [_univerjs_docs_ui.EMPTY_PARAGRAPH_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3538
+ order: 5,
3539
+ menuItemFactory: UploadFloatImageMenuFactory
3540
+ } } },
3541
+ [_univerjs_docs_ui.DOC_CONTENT_INSERT_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3542
+ order: 5,
3543
+ menuItemFactory: UploadFloatImageMenuFactory
3544
+ } } },
3545
+ [_univerjs_docs_ui.DOC_PARAGRAPH_T_INSERT_MENU_ID]: { insert: {
3546
+ [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3547
+ order: 1,
3548
+ menuItemFactory: UploadFloatImageMenuFactory
3549
+ },
3550
+ [DOCS_SHAPE_MENU_ID]: {
3551
+ order: 2,
3552
+ menuItemFactory: ShapeMenuFactory
3553
+ }
3554
+ } },
3555
+ [_univerjs_docs_ui.DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID]: { insert: {
3556
+ [`${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`]: {
3557
+ order: 1,
3558
+ menuItemFactory: UploadFloatImageBelowMenuFactory
3559
+ },
3560
+ [DOCS_SHAPE_BELOW_MENU_ID]: {
3561
+ order: 2,
3562
+ menuItemFactory: ShapeBelowMenuFactory
3563
+ }
3564
+ } },
3565
+ [DOCS_SHAPE_MENU_ID]: { shapes: {
3566
+ order: 0,
3567
+ [InsertDocRectangleShapeCommand.id]: {
3568
+ order: 0,
3569
+ menuItemFactory: InsertRectangleShapeMenuFactory
3570
+ },
3571
+ [InsertDocEllipseShapeCommand.id]: {
3572
+ order: 1,
3573
+ menuItemFactory: InsertEllipseShapeMenuFactory
3574
+ }
3575
+ } },
3576
+ [DOCS_SHAPE_BELOW_MENU_ID]: { shapes: {
3577
+ order: 0,
3578
+ [`${InsertDocRectangleShapeCommand.id}.below`]: {
3579
+ order: 0,
3580
+ menuItemFactory: InsertRectangleShapeBelowMenuFactory
3581
+ },
3582
+ [`${InsertDocEllipseShapeCommand.id}.below`]: {
3583
+ order: 1,
3584
+ menuItemFactory: InsertEllipseShapeBelowMenuFactory
3585
+ }
3586
+ } }
3587
+ }
3249
3588
  };
3250
3589
 
3251
3590
  //#endregion
@@ -3304,7 +3643,7 @@ const DeleteDrawingsShortcutItem = {
3304
3643
  };
3305
3644
 
3306
3645
  //#endregion
3307
- //#region src/controllers/doc-drawing.controller.ts
3646
+ //#region src/controllers/ui.controller.ts
3308
3647
  /**
3309
3648
  * Copyright 2023-present DreamNum Co., Ltd.
3310
3649
  *
@@ -3321,24 +3660,22 @@ const DeleteDrawingsShortcutItem = {
3321
3660
  * limitations under the License.
3322
3661
  */
3323
3662
  let DocDrawingUIController = class DocDrawingUIController extends _univerjs_core.Disposable {
3324
- constructor(_componentManager, _menuManagerService, _commandService, _shortcutService) {
3663
+ constructor(_menuManagerService, _commandService, _shortcutService) {
3325
3664
  super();
3326
- this._componentManager = _componentManager;
3327
3665
  this._menuManagerService = _menuManagerService;
3328
3666
  this._commandService = _commandService;
3329
3667
  this._shortcutService = _shortcutService;
3330
3668
  this._init();
3331
3669
  }
3332
- _initCustomComponents() {
3333
- const componentManager = this._componentManager;
3334
- this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
3335
- }
3670
+ _initCustomComponents() {}
3336
3671
  _initMenus() {
3337
3672
  this._menuManagerService.mergeMenu(menuSchema);
3338
3673
  }
3339
3674
  _initCommands() {
3340
3675
  [
3341
3676
  InsertDocImageCommand,
3677
+ InsertDocRectangleShapeCommand,
3678
+ InsertDocEllipseShapeCommand,
3342
3679
  InsertDocDrawingCommand,
3343
3680
  UpdateDocDrawingWrappingStyleCommand,
3344
3681
  UpdateDocDrawingDistanceCommand,
@@ -3376,10 +3713,9 @@ let DocDrawingUIController = class DocDrawingUIController extends _univerjs_core
3376
3713
  }
3377
3714
  };
3378
3715
  DocDrawingUIController = __decorate([
3379
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
3380
- __decorateParam(1, _univerjs_ui.IMenuManagerService),
3381
- __decorateParam(2, _univerjs_core.ICommandService),
3382
- __decorateParam(3, _univerjs_ui.IShortcutService)
3716
+ __decorateParam(0, _univerjs_ui.IMenuManagerService),
3717
+ __decorateParam(1, _univerjs_core.ICommandService),
3718
+ __decorateParam(2, _univerjs_ui.IShortcutService)
3383
3719
  ], DocDrawingUIController);
3384
3720
 
3385
3721
  //#endregion
@@ -3571,6 +3907,7 @@ let UniverDocsDrawingUIPlugin = class UniverDocsDrawingUIPlugin extends _univerj
3571
3907
  }
3572
3908
  onStarting() {
3573
3909
  [
3910
+ [ComponentsController],
3574
3911
  [DocDrawingUIController],
3575
3912
  [DocDrawingPopupMenuController],
3576
3913
  [DocDrawingTransformerController],
@@ -3579,6 +3916,7 @@ let UniverDocsDrawingUIPlugin = class UniverDocsDrawingUIPlugin extends _univerj
3579
3916
  [DocFloatDomController],
3580
3917
  [DocDrawingPrintingController]
3581
3918
  ].forEach((dependency) => this._injector.add(dependency));
3919
+ this._injector.get(ComponentsController);
3582
3920
  }
3583
3921
  onReady() {
3584
3922
  [[DocDrawingUpdateRenderController], [DocDrawingTransformUpdateController]].forEach((m) => this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_DOC, m));
@@ -3606,6 +3944,8 @@ UniverDocsDrawingUIPlugin = __decorate([
3606
3944
  //#endregion
3607
3945
  exports.ClearDocDrawingTransformerOperation = ClearDocDrawingTransformerOperation;
3608
3946
  exports.DOCS_IMAGE_MENU_ID = DOCS_IMAGE_MENU_ID;
3947
+ exports.DOCS_SHAPE_BELOW_MENU_ID = DOCS_SHAPE_BELOW_MENU_ID;
3948
+ exports.DOCS_SHAPE_MENU_ID = DOCS_SHAPE_MENU_ID;
3609
3949
  exports.DeleteDocDrawingsCommand = DeleteDocDrawingsCommand;
3610
3950
  exports.DocDrawingPosition = DocDrawingPosition;
3611
3951
  exports.DocDrawingTextWrap = DocDrawingTextWrap;
@@ -3618,7 +3958,9 @@ Object.defineProperty(exports, 'DocFloatDomController', {
3618
3958
  exports.EditDocDrawingOperation = EditDocDrawingOperation;
3619
3959
  exports.GroupDocDrawingCommand = GroupDocDrawingCommand;
3620
3960
  exports.InsertDocDrawingCommand = InsertDocDrawingCommand;
3961
+ exports.InsertDocEllipseShapeCommand = InsertDocEllipseShapeCommand;
3621
3962
  exports.InsertDocImageCommand = InsertDocImageCommand;
3963
+ exports.InsertDocRectangleShapeCommand = InsertDocRectangleShapeCommand;
3622
3964
  exports.MoveDocDrawingsCommand = MoveDocDrawingsCommand;
3623
3965
  exports.RemoveDocDrawingCommand = RemoveDocDrawingCommand;
3624
3966
  exports.SetDocDrawingArrangeCommand = SetDocDrawingArrangeCommand;