@univerjs/docs-ui 1.0.4 → 1.2.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 (98) hide show
  1. package/README.md +45 -0
  2. package/lib/cjs/index.js +937 -296
  3. package/lib/cjs/locale/ar-SA.js +6 -0
  4. package/lib/cjs/locale/ca-ES.js +6 -0
  5. package/lib/cjs/locale/de-DE.js +6 -0
  6. package/lib/cjs/locale/en-US.js +6 -0
  7. package/lib/cjs/locale/es-ES.js +6 -0
  8. package/lib/cjs/locale/fa-IR.js +6 -0
  9. package/lib/cjs/locale/fr-FR.js +6 -0
  10. package/lib/cjs/locale/id-ID.js +6 -0
  11. package/lib/cjs/locale/it-IT.js +6 -0
  12. package/lib/cjs/locale/ja-JP.js +6 -0
  13. package/lib/cjs/locale/ko-KR.js +6 -0
  14. package/lib/cjs/locale/pl-PL.js +6 -0
  15. package/lib/cjs/locale/pt-BR.js +6 -0
  16. package/lib/cjs/locale/ru-RU.js +6 -0
  17. package/lib/cjs/locale/sk-SK.js +6 -0
  18. package/lib/cjs/locale/vi-VN.js +6 -0
  19. package/lib/cjs/locale/zh-CN.js +6 -0
  20. package/lib/cjs/locale/zh-HK.js +6 -0
  21. package/lib/cjs/locale/zh-TW.js +6 -0
  22. package/lib/es/index.js +918 -283
  23. package/lib/es/locale/ar-SA.js +6 -0
  24. package/lib/es/locale/ca-ES.js +6 -0
  25. package/lib/es/locale/de-DE.js +6 -0
  26. package/lib/es/locale/en-US.js +6 -0
  27. package/lib/es/locale/es-ES.js +6 -0
  28. package/lib/es/locale/fa-IR.js +6 -0
  29. package/lib/es/locale/fr-FR.js +6 -0
  30. package/lib/es/locale/id-ID.js +6 -0
  31. package/lib/es/locale/it-IT.js +6 -0
  32. package/lib/es/locale/ja-JP.js +6 -0
  33. package/lib/es/locale/ko-KR.js +6 -0
  34. package/lib/es/locale/pl-PL.js +6 -0
  35. package/lib/es/locale/pt-BR.js +6 -0
  36. package/lib/es/locale/ru-RU.js +6 -0
  37. package/lib/es/locale/sk-SK.js +6 -0
  38. package/lib/es/locale/vi-VN.js +6 -0
  39. package/lib/es/locale/zh-CN.js +6 -0
  40. package/lib/es/locale/zh-HK.js +6 -0
  41. package/lib/es/locale/zh-TW.js +6 -0
  42. package/lib/index.css +41 -82
  43. package/lib/index.js +918 -283
  44. package/lib/locale/ar-SA.js +6 -0
  45. package/lib/locale/ca-ES.js +6 -0
  46. package/lib/locale/de-DE.js +6 -0
  47. package/lib/locale/en-US.js +6 -0
  48. package/lib/locale/es-ES.js +6 -0
  49. package/lib/locale/fa-IR.js +6 -0
  50. package/lib/locale/fr-FR.js +6 -0
  51. package/lib/locale/id-ID.js +6 -0
  52. package/lib/locale/it-IT.js +6 -0
  53. package/lib/locale/ja-JP.js +6 -0
  54. package/lib/locale/ko-KR.js +6 -0
  55. package/lib/locale/pl-PL.js +6 -0
  56. package/lib/locale/pt-BR.js +6 -0
  57. package/lib/locale/ru-RU.js +6 -0
  58. package/lib/locale/sk-SK.js +6 -0
  59. package/lib/locale/vi-VN.js +6 -0
  60. package/lib/locale/zh-CN.js +6 -0
  61. package/lib/locale/zh-HK.js +6 -0
  62. package/lib/locale/zh-TW.js +6 -0
  63. package/lib/types/config/config.d.ts +5 -0
  64. package/lib/types/index.d.ts +1 -0
  65. package/lib/types/locale/en-US.d.ts +6 -0
  66. package/lib/types/menu/display.menu.d.ts +21 -0
  67. package/lib/types/plugin.d.ts +1 -1
  68. package/lib/types/services/clipboard/clipboard.service.d.ts +1 -1
  69. package/lib/types/services/doc-heading-collapse.service.d.ts +38 -0
  70. package/lib/types/services/doc-paragraph-menu.service.d.ts +12 -3
  71. package/lib/types/services/doc-popup-manager.service.d.ts +4 -1
  72. package/lib/types/services/doc-zoom.d.ts +4 -1
  73. package/lib/types/views/ParagraphMenu.d.ts +2 -2
  74. package/lib/types/views/doc-side-menu-layout.d.ts +17 -0
  75. package/lib/types/views/heading-collapse-shape.d.ts +38 -0
  76. package/lib/types/views/paragraph-setting/hook/utils.d.ts +2 -0
  77. package/lib/umd/facade.js +1 -1
  78. package/lib/umd/index.js +16 -16
  79. package/lib/umd/locale/ar-SA.js +1 -1
  80. package/lib/umd/locale/ca-ES.js +1 -1
  81. package/lib/umd/locale/de-DE.js +1 -1
  82. package/lib/umd/locale/en-US.js +1 -1
  83. package/lib/umd/locale/es-ES.js +1 -1
  84. package/lib/umd/locale/fa-IR.js +1 -1
  85. package/lib/umd/locale/fr-FR.js +1 -1
  86. package/lib/umd/locale/id-ID.js +1 -1
  87. package/lib/umd/locale/it-IT.js +1 -1
  88. package/lib/umd/locale/ja-JP.js +1 -1
  89. package/lib/umd/locale/ko-KR.js +1 -1
  90. package/lib/umd/locale/pl-PL.js +1 -1
  91. package/lib/umd/locale/pt-BR.js +1 -1
  92. package/lib/umd/locale/ru-RU.js +1 -1
  93. package/lib/umd/locale/sk-SK.js +1 -1
  94. package/lib/umd/locale/vi-VN.js +1 -1
  95. package/lib/umd/locale/zh-CN.js +1 -1
  96. package/lib/umd/locale/zh-HK.js +1 -1
  97. package/lib/umd/locale/zh-TW.js +1 -1
  98. package/package.json +15 -15
package/lib/cjs/index.js CHANGED
@@ -270,7 +270,7 @@ function getCustomDecorationAtPosition(customDecorations, position) {
270
270
  }
271
271
 
272
272
  //#endregion
273
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
273
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
274
274
  function _typeof(o) {
275
275
  "@babel/helpers - typeof";
276
276
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -281,7 +281,7 @@ function _typeof(o) {
281
281
  }
282
282
 
283
283
  //#endregion
284
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
284
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
285
285
  function toPrimitive(t, r) {
286
286
  if ("object" != _typeof(t) || !t) return t;
287
287
  var e = t[Symbol.toPrimitive];
@@ -294,14 +294,14 @@ function toPrimitive(t, r) {
294
294
  }
295
295
 
296
296
  //#endregion
297
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
297
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
298
298
  function toPropertyKey(t) {
299
299
  var i = toPrimitive(t, "string");
300
300
  return "symbol" == _typeof(i) ? i : i + "";
301
301
  }
302
302
 
303
303
  //#endregion
304
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
304
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
305
305
  function _defineProperty(e, r, t) {
306
306
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
307
307
  value: t,
@@ -312,7 +312,7 @@ function _defineProperty(e, r, t) {
312
312
  }
313
313
 
314
314
  //#endregion
315
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
315
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
316
316
  function __decorateParam(paramIndex, decorator) {
317
317
  return function(target, key) {
318
318
  decorator(target, key, paramIndex);
@@ -320,7 +320,7 @@ function __decorateParam(paramIndex, decorator) {
320
320
  }
321
321
 
322
322
  //#endregion
323
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
323
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
324
324
  function __decorate(decorators, target, key, desc) {
325
325
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
326
326
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -436,8 +436,8 @@ let DocMenuStyleService = class DocMenuStyleService extends _univerjs_core.Dispo
436
436
  }));
437
437
  }
438
438
  _listenDocRangeChange() {
439
- this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(() => {
440
- this._clearStyleCache();
439
+ this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(({ options }) => {
440
+ if (!(options === null || options === void 0 ? void 0 : options.preserveInputStyle)) this._clearStyleCache();
441
441
  }));
442
442
  }
443
443
  getStyleCache() {
@@ -521,15 +521,34 @@ const BreakLineCommand = {
521
521
  const { horizontalLine, insertionMode = "split-paragraph" } = params ?? {};
522
522
  const { segmentId } = activeTextRange;
523
523
  const docDataModel = (params === null || params === void 0 ? void 0 : params.unitId) ? univerInstanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
524
- const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId ?? "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
524
+ let originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId ?? "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
525
525
  if (docDataModel == null || originBody == null) return false;
526
526
  const unitId = docDataModel.getUnitId();
527
527
  const { startOffset, endOffset } = activeTextRange;
528
528
  const paragraphs = originBody.paragraphs ?? [];
529
529
  const isBareStructuralGap = isTopLevelStructuralGap(originBody.dataStream, startOffset) && originBody.dataStream[startOffset] !== _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
530
530
  const insertsAtStructuralGap = insertionMode === "insert-gap" || isBareStructuralGap;
531
- const prevParagraph = insertsAtStructuralGap ? void 0 : paragraphs.find((p) => p.startIndex >= startOffset);
531
+ let prevParagraph = insertsAtStructuralGap ? void 0 : paragraphs.find((p) => p.startIndex >= startOffset);
532
532
  if (!prevParagraph && !insertsAtStructuralGap) return false;
533
+ if (!segmentId && (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.headingCollapsed) && docDataModel.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) {
534
+ const paragraphId = prevParagraph.paragraphId;
535
+ const viewModel = new _univerjs_engine_render.DocumentViewModel(docDataModel);
536
+ try {
537
+ if (viewModel.getHeadingSections().some((section) => section.paragraphId === paragraphId)) {
538
+ var _originBody$paragraph;
539
+ if (!commandService.syncExecuteCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
540
+ unitId,
541
+ paragraphId,
542
+ collapsed: false
543
+ })) return false;
544
+ originBody = docDataModel.getBody();
545
+ prevParagraph = originBody === null || originBody === void 0 || (_originBody$paragraph = originBody.paragraphs) === null || _originBody$paragraph === void 0 ? void 0 : _originBody$paragraph.find((paragraph) => paragraph.startIndex >= startOffset);
546
+ if (!originBody || !prevParagraph) return false;
547
+ }
548
+ } finally {
549
+ viewModel.dispose();
550
+ }
551
+ }
533
552
  const isAtParagraphEnd = startOffset === (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex);
534
553
  const prevParagraphIndex = prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex;
535
554
  const defaultTextStyle = docMenuStyleService.getDefaultStyle();
@@ -2867,7 +2886,7 @@ function getTextRangeFromCharIndex(startOffset, endOffset, scene, document, skel
2867
2886
  function getRectRangeFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
2868
2887
  const startNodePosition = skeleton.findNodePositionByCharIndex(startOffset, true, segmentId, segmentPage);
2869
2888
  const endNodePosition = skeleton.findNodePositionByCharIndex(endOffset, true, segmentId, segmentPage);
2870
- if (startNodePosition == null || endNodePosition == null) return;
2889
+ if (startNodePosition == null || endNodePosition == null || startNodePosition.path.indexOf("cells") === -1 || endNodePosition.path.indexOf("cells") === -1) return;
2871
2890
  return new RectRange(scene, document, skeleton, startNodePosition, endNodePosition, style, segmentId, segmentPage);
2872
2891
  }
2873
2892
  function getRangeListFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
@@ -3458,7 +3477,12 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
3458
3477
  this._addRectRanges(rectRanges);
3459
3478
  };
3460
3479
  for (const range of ranges) {
3461
- const { startOffset, endOffset, rangeType, startNodePosition, endNodePosition } = range;
3480
+ const { rangeType } = range;
3481
+ let { startOffset, endOffset, startNodePosition, endNodePosition } = range;
3482
+ if (rangeType !== _univerjs_core.DOC_RANGE_TYPE.RECT && range.direction === _univerjs_core.RANGE_DIRECTION.BACKWARD && startOffset < endOffset) {
3483
+ [startOffset, endOffset] = [endOffset, startOffset];
3484
+ [startNodePosition, endNodePosition] = [endNodePosition, startNodePosition];
3485
+ }
3462
3486
  const rangeStyle = range.style ?? style;
3463
3487
  if (rangeType !== _univerjs_core.DOC_RANGE_TYPE.RECT && startOffset === endOffset) {
3464
3488
  const textRange = cursorConvertToTextRange(scene, {
@@ -6256,6 +6280,14 @@ const DeleteLeftCommand = {
6256
6280
  const { segmentId, style, segmentPage } = activeRange;
6257
6281
  const body = (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
6258
6282
  if (body == null) return false;
6283
+ if (activeRange.collapsed && !segmentId) {
6284
+ const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset - 1);
6285
+ if (hidden) return commandService.executeCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
6286
+ unitId,
6287
+ paragraphId: hidden.paragraphId,
6288
+ collapsed: false
6289
+ });
6290
+ }
6259
6291
  const originalLength = body.dataStream.length;
6260
6292
  const typingStyle = captureDeletedTypingStyle(accessor, docDataModel, body, activeRange);
6261
6293
  const actualRange = activeRange;
@@ -6414,6 +6446,14 @@ const DeleteRightCommand = {
6414
6446
  const { segmentId, style, segmentPage } = activeRange;
6415
6447
  const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf5 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf5 === void 0 ? void 0 : _docDataModel$getSelf5.getBody();
6416
6448
  if (!docDataModel || !body) return false;
6449
+ if (activeRange.collapsed && !segmentId) {
6450
+ const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset + 1);
6451
+ if (hidden) return commandService.executeCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
6452
+ unitId: docDataModel.getUnitId(),
6453
+ paragraphId: hidden.paragraphId,
6454
+ collapsed: false
6455
+ });
6456
+ }
6417
6457
  const actualRange = activeRange;
6418
6458
  const { startOffset, endOffset, collapsed } = actualRange;
6419
6459
  if (collapsed && shouldResetEmptyCenteredParagraphAlignment(accessor, docDataModel)) {
@@ -8561,23 +8601,39 @@ function getTableClipboardBodySlice(body, range) {
8561
8601
  return getTableCellContentClipboardBodySlice(body, startOffset, endOffset);
8562
8602
  }
8563
8603
  function getTableCellContentClipboardBodySlice(body, start, end) {
8564
- var _bodySlice$textRuns, _bodySlice$tables, _bodySlice$paragraphs;
8604
+ var _bodySlice$textRuns, _bodySlice$docxExport;
8565
8605
  const bodySlice = (0, _univerjs_core.getBodySlice)(body, start, end + 2);
8566
- bodySlice.dataStream = _univerjs_core.DataStreamTreeTokenType.TABLE_START + _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_START + _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_START + bodySlice.dataStream + _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_END + _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_END + _univerjs_core.DataStreamTreeTokenType.TABLE_END;
8606
+ const prefix = _univerjs_core.DataStreamTreeTokenType.TABLE_START + _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_START + _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_START;
8607
+ bodySlice.dataStream = prefix + bodySlice.dataStream + _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_END + _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_END + _univerjs_core.DataStreamTreeTokenType.TABLE_END;
8608
+ const offset = prefix.length;
8567
8609
  (_bodySlice$textRuns = bodySlice.textRuns) === null || _bodySlice$textRuns === void 0 || _bodySlice$textRuns.forEach((textRun) => {
8568
- const { st, ed } = textRun;
8569
- textRun.st = st + 3;
8570
- textRun.ed = ed + 3;
8610
+ textRun.st += offset;
8611
+ textRun.ed += offset;
8571
8612
  });
8572
- (_bodySlice$tables = bodySlice.tables) === null || _bodySlice$tables === void 0 || _bodySlice$tables.forEach((table) => {
8573
- const { startIndex, endIndex } = table;
8574
- table.startIndex = startIndex + 3;
8575
- table.endIndex = endIndex + 3;
8576
- });
8577
- (_bodySlice$paragraphs = bodySlice.paragraphs) === null || _bodySlice$paragraphs === void 0 || _bodySlice$paragraphs.forEach((paragraph) => {
8578
- const { startIndex } = paragraph;
8579
- paragraph.startIndex = startIndex + 3;
8613
+ [
8614
+ bodySlice.paragraphs,
8615
+ bodySlice.sectionBreaks,
8616
+ bodySlice.customBlocks,
8617
+ bodySlice.docxRawCustomBlocks,
8618
+ bodySlice.docxRawBlocks
8619
+ ].forEach((items) => items === null || items === void 0 ? void 0 : items.forEach((item) => {
8620
+ item.startIndex += offset;
8621
+ }));
8622
+ [
8623
+ bodySlice.tables,
8624
+ bodySlice.columnGroups,
8625
+ bodySlice.blockRanges,
8626
+ bodySlice.customRanges,
8627
+ bodySlice.customDecorations
8628
+ ].forEach((ranges) => ranges === null || ranges === void 0 ? void 0 : ranges.forEach((range) => {
8629
+ range.startIndex += offset;
8630
+ range.endIndex += offset;
8631
+ }));
8632
+ (_bodySlice$docxExport = bodySlice.docxExportExcludedRanges) === null || _bodySlice$docxExport === void 0 || _bodySlice$docxExport.forEach((range) => {
8633
+ range.start += offset;
8634
+ range.end += offset;
8580
8635
  });
8636
+ if (bodySlice.renderedPageBreaks) bodySlice.renderedPageBreaks = bodySlice.renderedPageBreaks.map((index) => index + offset);
8581
8637
  return bodySlice;
8582
8638
  }
8583
8639
  const IDocClipboardService = (0, _univerjs_core.createIdentifier)("doc.clipboard-service");
@@ -8759,13 +8815,21 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
8759
8815
  this.dismissPasteOptions();
8760
8816
  const unitId = payload.unitId ?? this._getCurrentDocumentUnitId();
8761
8817
  if (!unitId || !this._canEditTargets(unitId)) return false;
8762
- if (!cachedSource && !payload.html && !payload.text && !payload.internalJson && !payload.files.length) return false;
8818
+ const isCommentEditor = (0, _univerjs_core.isCommentEditorID)(unitId);
8819
+ if (!cachedSource && !payload.html && !payload.text && !payload.internalJson && (isCommentEditor || !payload.files.length)) return false;
8763
8820
  const generation = this._pasteGeneration;
8764
- const mode = unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
8821
+ const mode = isCommentEditor || unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
8765
8822
  const style = this._getPasteStyle(unitId);
8766
- const source = await this._preparePaste(payload, mode, cachedSource);
8823
+ const source = await (isCommentEditor && payload.text !== void 0 ? { body: { dataStream: payload.text } } : this._preparePaste(payload, mode, cachedSource));
8767
8824
  if (generation !== this._pasteGeneration || !this._canEditTargets(unitId)) return false;
8768
- let doc = applyDocPasteMode(source, mode, style, payload.text);
8825
+ let doc;
8826
+ if (isCommentEditor) {
8827
+ const text = payload.text ?? getClipboardPlainText(source);
8828
+ if (!text) return false;
8829
+ const body = _univerjs_core.BuildTextUtils.transform.fromPlainText(text);
8830
+ delete body.customRanges;
8831
+ doc = { body };
8832
+ } else doc = applyDocPasteMode(source, mode, style, payload.text);
8769
8833
  if (unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
8770
8834
  doc = {
8771
8835
  ...source,
@@ -11729,7 +11793,6 @@ const DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS = {
11729
11793
  align: "center"
11730
11794
  };
11731
11795
  const defaultPluginConfig = {
11732
- toc: false,
11733
11796
  footer: true,
11734
11797
  wordCount: true,
11735
11798
  placeholder: true,
@@ -12159,6 +12222,7 @@ function getLineFontFamily(line) {
12159
12222
  function drawParagraphPlaceholders(ctx, placeholders, color = PLACEHOLDER_COLOR) {
12160
12223
  ctx.save();
12161
12224
  ctx.fillStyle = color;
12225
+ ctx.globalAlpha *= .5;
12162
12226
  ctx.textBaseline = "alphabetic";
12163
12227
  for (const placeholder of placeholders) {
12164
12228
  const clipLeft = placeholder.clipLeft ?? placeholder.x;
@@ -12782,12 +12846,35 @@ var DocLayoutInteractionService = class extends _univerjs_core.Disposable {
12782
12846
  //#region src/services/doc-zoom.ts
12783
12847
  const DEFAULT_DOC_ZOOM_RATIO = 1;
12784
12848
  const DEFAULT_MODERN_DOC_ZOOM_RATIO = 1;
12849
+ const DOC_ZOOM_SHORTCUTS = [
12850
+ 50,
12851
+ 80,
12852
+ 100,
12853
+ 130,
12854
+ 150,
12855
+ 170,
12856
+ 200,
12857
+ 400
12858
+ ];
12785
12859
  function getDocEffectiveZoomRatio(documentModel) {
12786
12860
  var _documentModel$getSet, _documentModel$getSna;
12787
12861
  const zoomRatio = (_documentModel$getSet = documentModel.getSettings()) === null || _documentModel$getSet === void 0 ? void 0 : _documentModel$getSet.zoomRatio;
12788
12862
  if (zoomRatio != null) return zoomRatio;
12789
12863
  return ((_documentModel$getSna = documentModel.getSnapshot().documentStyle) === null || _documentModel$getSna === void 0 ? void 0 : _documentModel$getSna.documentFlavor) === _univerjs_core.DocumentFlavor.MODERN ? 1 : DEFAULT_DOC_ZOOM_RATIO;
12790
12864
  }
12865
+ function getDocZoomRatio$(commandService, instanceService) {
12866
+ return instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.switchMap)((documentModel) => {
12867
+ if (!documentModel) return (0, rxjs.of)(100);
12868
+ return new rxjs.Observable((subscriber) => {
12869
+ const update = () => subscriber.next(Math.round(getDocEffectiveZoomRatio(documentModel) * 100));
12870
+ const disposable = commandService.onCommandExecuted((command) => {
12871
+ if (command.id === SetDocZoomRatioOperation.id && command.params.unitId === documentModel.getUnitId()) update();
12872
+ });
12873
+ update();
12874
+ return () => disposable.dispose();
12875
+ });
12876
+ }), (0, rxjs.distinctUntilChanged)());
12877
+ }
12791
12878
 
12792
12879
  //#endregion
12793
12880
  //#region src/services/doc-view-scale.ts
@@ -13437,11 +13524,13 @@ function doesDocMutationRequireLayout(actions, drawings) {
13437
13524
  if (!sawComponent || !drawingOnly) return true;
13438
13525
  if (transitions.size === 0) return false;
13439
13526
  for (const [drawingId, transition] of transitions) {
13440
- var _drawings$drawingId;
13441
- const currentLayoutType = drawings === null || drawings === void 0 || (_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.layoutType;
13527
+ var _currentDrawing$docTr, _currentDrawing$docTr2;
13528
+ const currentDrawing = drawings === null || drawings === void 0 ? void 0 : drawings[drawingId];
13529
+ const currentLayoutType = currentDrawing === null || currentDrawing === void 0 ? void 0 : currentDrawing.layoutType;
13442
13530
  const before = transition.before ?? currentLayoutType;
13443
13531
  const after = transition.after ?? currentLayoutType;
13444
13532
  if (before == null || after == null || before !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE || after !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return true;
13533
+ if ((currentDrawing === null || currentDrawing === void 0 || (_currentDrawing$docTr = currentDrawing.docTransform) === null || _currentDrawing$docTr === void 0 ? void 0 : _currentDrawing$docTr.positionH.relativeFrom) !== _univerjs_core.ObjectRelativeFromH.PAGE || (currentDrawing === null || currentDrawing === void 0 || (_currentDrawing$docTr2 = currentDrawing.docTransform) === null || _currentDrawing$docTr2 === void 0 ? void 0 : _currentDrawing$docTr2.positionV.relativeFrom) !== _univerjs_core.ObjectRelativeFromV.PAGE) return true;
13445
13534
  }
13446
13535
  return false;
13447
13536
  }
@@ -13634,9 +13723,13 @@ let DocRenderController = class DocRenderController extends _univerjs_core.RxDis
13634
13723
  const interactionAnchor = priorityAnchorBelongsToMutation ? options.anchor : options.priorityAnchor ?? options.anchor;
13635
13724
  let interactionViewportAnchor = priorityAnchorBelongsToMutation ? null : this._captureViewportAnchor(skeleton, options.priorityAnchor, options.invalidation);
13636
13725
  const foregroundEndOffset = this._resolveContinuousForegroundEndOffset(skeleton, options.invalidation);
13726
+ const viewport = this._context.scene.getViewport("viewMain");
13727
+ const docsComponent = this._context.mainComponent;
13728
+ const minimumPublicationHeight = this._context.unit.documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN && viewport != null && docsComponent instanceof _univerjs_engine_render.Documents ? Math.max(0, viewport.calcViewportInfo().viewBound.bottom - docsComponent.getOffsetConfig().docsTop) : void 0;
13637
13729
  this._layoutCoordinator.schedule(skeleton, {
13638
13730
  ...options,
13639
13731
  anchor: interactionAnchor,
13732
+ ...minimumPublicationHeight != null && Number.isFinite(minimumPublicationHeight) && minimumPublicationHeight > 0 ? { minimumPublicationHeight } : {},
13640
13733
  ...foregroundEndOffset == null ? {} : { foregroundEndOffset },
13641
13734
  preserveInteractionWindow: interactionAnchor != null && interactionAnchor !== options.anchor,
13642
13735
  reuseUnaffectedTail: false
@@ -14996,7 +15089,8 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
14996
15089
  const updatePosition = () => {
14997
15090
  try {
14998
15091
  const newPosition = calc();
14999
- if (newPosition) position$.next(newPosition);
15092
+ const previous = position$.value;
15093
+ if (newPosition && (newPosition.left !== previous.left || newPosition.right !== previous.right || newPosition.top !== previous.top || newPosition.bottom !== previous.bottom)) position$.next(newPosition);
15000
15094
  } catch {}
15001
15095
  };
15002
15096
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
@@ -15052,6 +15146,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
15052
15146
  disposable.add(currentRender.scene.onTransformChange$.subscribeEvent(() => {
15053
15147
  updatePositions();
15054
15148
  }));
15149
+ if (currentRender.mainComponent) disposable.add(currentRender.mainComponent.onTransformChange$.subscribeEvent(updatePositions));
15055
15150
  return {
15056
15151
  positions,
15057
15152
  positions$,
@@ -15063,14 +15158,18 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
15063
15158
  if (!currentRender) throw new Error(`Current render not found, unitId: ${unitId}`);
15064
15159
  const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
15065
15160
  const popupManagerService = this._resolvePopupManagerService(popupInjector);
15066
- const { position, position$, disposable } = this._createRectPositionObserver(rect, currentRender);
15161
+ const { position, position$, disposable, updatePosition } = this._createRectPositionObserver(rect, currentRender);
15162
+ if (popup.positionChanges$) disposable.add(popup.positionChanges$.subscribe(updatePosition));
15067
15163
  const id = popupManagerService.addPopup({
15068
15164
  ...popup,
15069
15165
  unitId,
15070
15166
  subUnitId: "default",
15071
15167
  connectorInjector: popupInjector,
15072
15168
  anchorRect: position,
15073
- anchorRect$: position$,
15169
+ anchorRect$: position$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
15170
+ leading: true,
15171
+ trailing: true
15172
+ })),
15074
15173
  canvasElement: currentRender.engine.getCanvasElement()
15075
15174
  });
15076
15175
  const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
@@ -15102,7 +15201,10 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
15102
15201
  subUnitId: "default",
15103
15202
  connectorInjector: popupInjector,
15104
15203
  anchorRect: position,
15105
- anchorRect$: position$,
15204
+ anchorRect$: position$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
15205
+ leading: true,
15206
+ trailing: true
15207
+ })),
15106
15208
  canvasElement: currentRender.engine.getCanvasElement()
15107
15209
  });
15108
15210
  const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
@@ -15144,7 +15246,11 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
15144
15246
  }
15145
15247
  return direction.includes("top") ? bounds[0] : bounds[bounds.length - 1];
15146
15248
  };
15147
- const position$ = bounds$.pipe((0, rxjs.filter)((bounds) => bounds.length > 0), (0, rxjs.map)(getAnchor));
15249
+ const popupBounds$ = bounds$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
15250
+ leading: true,
15251
+ trailing: true
15252
+ }));
15253
+ const position$ = popupBounds$.pipe((0, rxjs.filter)((bounds) => bounds.length > 0), (0, rxjs.map)(getAnchor));
15148
15254
  let id;
15149
15255
  let popupActivity = null;
15150
15256
  const removePopup = () => {
@@ -15169,7 +15275,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
15169
15275
  anchorRect: getAnchor(bounds),
15170
15276
  anchorRect$: position$,
15171
15277
  excludeRects: bounds,
15172
- excludeRects$: bounds$,
15278
+ excludeRects$: popupBounds$,
15173
15279
  direction: [
15174
15280
  "top",
15175
15281
  "bottom",
@@ -15478,6 +15584,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15478
15584
  }));
15479
15585
  }
15480
15586
  _initResetDirty() {
15587
+ this.disposeWithMe(this._documents.onTransformChange$.subscribeEvent(() => {
15588
+ this._customRangeDirty = true;
15589
+ this._bulletDirty = true;
15590
+ this._paragraphDirty = true;
15591
+ this._tableBoundsDirty = true;
15592
+ }));
15481
15593
  this.disposeWithMe(this._skeleton.dirty$.subscribe(() => {
15482
15594
  this._customRangeDirty = true;
15483
15595
  this._bulletDirty = true;
@@ -15969,6 +16081,9 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15969
16081
  return (_this$_tableCellBound2 = this._tableCellBounds.get(tableId)) === null || _this$_tableCellBound2 === void 0 ? void 0 : _this$_tableCellBound2.find((bound) => bound.rowIndex === rowIndex && bound.colIndex === colIndex && (pageIndex == null || bound.pageIndex === pageIndex));
15970
16082
  }
15971
16083
  findParagraphBoundByIndex(index) {
16084
+ this._buildParagraphBounds();
16085
+ const paragraph = this._paragraphBounds.get(index);
16086
+ if (paragraph) return paragraph;
15972
16087
  this._buildTableBounds();
15973
16088
  this._buildTableCellsForDocumentRange(index, index);
15974
16089
  let tableParagraph = this._tableParagraphBoundsByIndex.get(index);
@@ -15980,9 +16095,6 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15980
16095
  if (tableParagraph) return tableParagraph;
15981
16096
  }
15982
16097
  if (tableParagraph) return tableParagraph;
15983
- this._buildParagraphBounds();
15984
- const paragraph = this._paragraphBounds.get(index);
15985
- if (paragraph) return paragraph;
15986
16098
  }
15987
16099
  findParagraphBoundsInRange(startIndex, endIndex) {
15988
16100
  this._buildTableBounds();
@@ -18463,6 +18575,46 @@ function PasteRibbonMenuFactory(accessor) {
18463
18575
  };
18464
18576
  }
18465
18577
 
18578
+ //#endregion
18579
+ //#region src/menu/display.menu.ts
18580
+ const DOC_ZOOM_RATIO_MENU_ID = "doc.menu.zoom-ratio";
18581
+ function DocZoomRatioMenuItemFactory(accessor) {
18582
+ const commandService = accessor.get(_univerjs_core.ICommandService);
18583
+ const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
18584
+ return {
18585
+ id: DOC_ZOOM_RATIO_MENU_ID,
18586
+ type: _univerjs_ui.MenuItemType.SELECTOR,
18587
+ icon: "ZoomInIcon",
18588
+ tooltip: "docs-ui.toolbar.zoom",
18589
+ selectionsCommandId: SetDocZoomRatioOperation.id,
18590
+ selections: DOC_ZOOM_SHORTCUTS.map((value) => ({
18591
+ value,
18592
+ label: `${value}%`,
18593
+ params: () => {
18594
+ var _instanceService$getC;
18595
+ return {
18596
+ unitId: (_instanceService$getC = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _instanceService$getC === void 0 ? void 0 : _instanceService$getC.getUnitId(),
18597
+ zoomRatio: value / 100
18598
+ };
18599
+ }
18600
+ })),
18601
+ value$: getDocZoomRatio$(commandService, instanceService),
18602
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
18603
+ };
18604
+ }
18605
+ function DocFullscreenMenuItemFactory(accessor) {
18606
+ const root = accessor.get(_univerjs_ui.ILayoutService).rootContainerElement;
18607
+ const fullscreen$ = root ? (0, rxjs.merge)((0, rxjs.of)(null), (0, rxjs.fromEvent)(root.ownerDocument, "fullscreenchange")).pipe((0, rxjs.map)(() => root.ownerDocument.fullscreenElement === root), (0, rxjs.distinctUntilChanged)()) : (0, rxjs.of)(false);
18608
+ return {
18609
+ id: _univerjs_ui.ToggleFullscreenOperation.id,
18610
+ type: _univerjs_ui.MenuItemType.BUTTON,
18611
+ tooltip: "docs-ui.toolbar.fullscreen",
18612
+ icon: fullscreen$.pipe((0, rxjs.map)((fullscreen) => fullscreen ? "ShrinkIcon" : "ExpandIcon")),
18613
+ activated$: fullscreen$,
18614
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
18615
+ };
18616
+ }
18617
+
18466
18618
  //#endregion
18467
18619
  //#region src/views/paragraph-menu/theme-color.ts
18468
18620
  function getHighlightBackgroundColor(themeService, index) {
@@ -18871,7 +19023,7 @@ function ParagraphMenuInsertBelowSubmenuItemFactory(accessor) {
18871
19023
  return {
18872
19024
  id: DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,
18873
19025
  type: _univerjs_ui.MenuItemType.SUBITEMS,
18874
- icon: "TextTypeIcon",
19026
+ icon: "InsertBelowDoubleIcon",
18875
19027
  title: "docs-ui.rightClick.insertBellow",
18876
19028
  tooltip: "docs-ui.rightClick.insertBellow",
18877
19029
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -19089,7 +19241,8 @@ const menuSchema = {
19089
19241
  order: 0,
19090
19242
  gridLayout: {
19091
19243
  row: 2,
19092
- column: 1
19244
+ column: 1,
19245
+ width: 44
19093
19246
  },
19094
19247
  menuItemFactory: BoldMenuItemFactory
19095
19248
  },
@@ -19097,7 +19250,8 @@ const menuSchema = {
19097
19250
  order: 1,
19098
19251
  gridLayout: {
19099
19252
  row: 2,
19100
- column: 2
19253
+ column: 2,
19254
+ width: 44
19101
19255
  },
19102
19256
  menuItemFactory: ItalicMenuItemFactory
19103
19257
  },
@@ -19105,7 +19259,8 @@ const menuSchema = {
19105
19259
  order: 2,
19106
19260
  gridLayout: {
19107
19261
  row: 2,
19108
- column: 3
19262
+ column: 3,
19263
+ width: 44
19109
19264
  },
19110
19265
  menuItemFactory: UnderlineMenuItemFactory
19111
19266
  },
@@ -19113,7 +19268,8 @@ const menuSchema = {
19113
19268
  order: 3,
19114
19269
  gridLayout: {
19115
19270
  row: 2,
19116
- column: 4
19271
+ column: 4,
19272
+ width: 44
19117
19273
  },
19118
19274
  menuItemFactory: StrikeThroughMenuItemFactory
19119
19275
  },
@@ -19121,7 +19277,8 @@ const menuSchema = {
19121
19277
  order: 4,
19122
19278
  gridLayout: {
19123
19279
  row: 2,
19124
- column: 5
19280
+ column: 6,
19281
+ width: 44
19125
19282
  },
19126
19283
  menuItemFactory: SubscriptMenuItemFactory
19127
19284
  },
@@ -19129,7 +19286,8 @@ const menuSchema = {
19129
19286
  order: 5,
19130
19287
  gridLayout: {
19131
19288
  row: 2,
19132
- column: 6
19289
+ column: 5,
19290
+ width: 44
19133
19291
  },
19134
19292
  menuItemFactory: SuperscriptMenuItemFactory
19135
19293
  },
@@ -19139,7 +19297,7 @@ const menuSchema = {
19139
19297
  row: 1,
19140
19298
  column: 1,
19141
19299
  columnSpan: 2,
19142
- width: 100
19300
+ width: 96
19143
19301
  },
19144
19302
  menuItemFactory: HeadingSelectorMenuItemFactory
19145
19303
  },
@@ -19148,7 +19306,8 @@ const menuSchema = {
19148
19306
  gridLayout: {
19149
19307
  row: 1,
19150
19308
  column: 7,
19151
- width: 64
19309
+ columnSpan: 2,
19310
+ width: 96
19152
19311
  },
19153
19312
  menuItemFactory: FontSizeSelectorMenuItemFactory
19154
19313
  },
@@ -19158,7 +19317,7 @@ const menuSchema = {
19158
19317
  row: 1,
19159
19318
  column: 3,
19160
19319
  columnSpan: 4,
19161
- width: 160
19320
+ width: 200
19162
19321
  },
19163
19322
  menuItemFactory: FontFamilySelectorMenuItemFactory
19164
19323
  },
@@ -19166,7 +19325,8 @@ const menuSchema = {
19166
19325
  order: 8,
19167
19326
  gridLayout: {
19168
19327
  row: 2,
19169
- column: 7
19328
+ column: 8,
19329
+ width: 44
19170
19330
  },
19171
19331
  menuItemFactory: TextColorSelectorMenuItemFactory,
19172
19332
  [ResetInlineFormatTextColorCommand.id]: {
@@ -19178,7 +19338,8 @@ const menuSchema = {
19178
19338
  order: 9,
19179
19339
  gridLayout: {
19180
19340
  row: 2,
19181
- column: 8
19341
+ column: 7,
19342
+ width: 44
19182
19343
  },
19183
19344
  menuItemFactory: BackgroundColorSelectorMenuItemFactory,
19184
19345
  [ResetInlineFormatTextBackgroundColorCommand.id]: {
@@ -19229,16 +19390,6 @@ const menuSchema = {
19229
19390
  showLabel: true
19230
19391
  },
19231
19392
  menuItemFactory: HeaderFooterMenuItemFactory
19232
- },
19233
- [DocOpenPageSettingCommand.id]: {
19234
- order: 12,
19235
- gridLayout: {
19236
- row: 1,
19237
- column: 4,
19238
- rowSpan: 2,
19239
- showLabel: true
19240
- },
19241
- menuItemFactory: PageSettingMenuItemFactory
19242
19393
  }
19243
19394
  },
19244
19395
  [_univerjs_ui.RibbonInsertGroup.MEDIA]: {
@@ -19313,6 +19464,34 @@ const menuSchema = {
19313
19464
  menuItemFactory: SymbolPickerMenuItemFactory
19314
19465
  }
19315
19466
  },
19467
+ [_univerjs_ui.RibbonViewGroup.DISPLAY]: {
19468
+ [DocOpenPageSettingCommand.id]: {
19469
+ order: 0,
19470
+ gridLayout: {
19471
+ row: 1,
19472
+ column: 1,
19473
+ rowSpan: 2,
19474
+ showLabel: true
19475
+ },
19476
+ menuItemFactory: PageSettingMenuItemFactory
19477
+ },
19478
+ [DOC_ZOOM_RATIO_MENU_ID]: {
19479
+ order: 1,
19480
+ gridLayout: {
19481
+ row: 1,
19482
+ column: 2
19483
+ },
19484
+ menuItemFactory: DocZoomRatioMenuItemFactory
19485
+ },
19486
+ [_univerjs_ui.ToggleFullscreenOperation.id]: {
19487
+ order: 2,
19488
+ gridLayout: {
19489
+ row: 2,
19490
+ column: 2
19491
+ },
19492
+ menuItemFactory: DocFullscreenMenuItemFactory
19493
+ }
19494
+ },
19316
19495
  [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: {
19317
19496
  [_univerjs_ui.ContextMenuGroup.OTHERS]: { [OpenDocParagraphPermissionOperation.id]: {
19318
19497
  order: 10,
@@ -20031,45 +20210,23 @@ const BulletListShortCut = {
20031
20210
 
20032
20211
  //#endregion
20033
20212
  //#region src/views/count-bar/ZoomSlider.tsx
20034
- const ZOOM_MAP = [
20035
- 50,
20036
- 80,
20037
- 100,
20038
- 130,
20039
- 150,
20040
- 170,
20041
- 200,
20042
- 400
20043
- ];
20044
20213
  const DOC_ZOOM_RANGE = [10, 400];
20045
20214
  function ZoomSlider() {
20046
20215
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
20047
20216
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
20048
- const documentDataModel = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.filter)((documentDataModel) => documentDataModel != null)), null, false, [univerInstanceService]);
20049
- const getCurrentZoom = (0, react.useCallback)((docModel = documentDataModel) => {
20050
- if (!docModel) return 100;
20051
- return Math.round(getDocEffectiveZoomRatio(docModel) * 100);
20052
- }, [documentDataModel]);
20053
- const [zoom, setZoom] = (0, react.useState)(100);
20054
- (0, react.useEffect)(() => setZoom(getCurrentZoom(documentDataModel)), [documentDataModel, getCurrentZoom]);
20055
- (0, react.useEffect)(() => {
20056
- return commandService.onCommandExecuted((commandInfo) => {
20057
- if (commandInfo.id === SetDocZoomRatioOperation.id) setZoom(getCurrentZoom());
20058
- }).dispose;
20059
- }, [commandService, getCurrentZoom]);
20217
+ const zoom = (0, _univerjs_ui.useObservable)(() => getDocZoomRatio$(commandService, univerInstanceService), 100, void 0, [commandService, univerInstanceService]);
20060
20218
  function handleChange(value) {
20061
- setZoom(value);
20219
+ const documentDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
20062
20220
  if (documentDataModel == null) return;
20063
- const zoomRatio = value / 100;
20064
- commandService.executeCommand(SetDocZoomRatioOperation.id, {
20221
+ return commandService.executeCommand(SetDocZoomRatioOperation.id, {
20065
20222
  unitId: documentDataModel.getUnitId(),
20066
- zoomRatio
20223
+ zoomRatio: value / 100
20067
20224
  });
20068
20225
  }
20069
20226
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.Slider, {
20070
20227
  min: DOC_ZOOM_RANGE[0],
20071
20228
  value: zoom,
20072
- shortcuts: ZOOM_MAP,
20229
+ shortcuts: DOC_ZOOM_SHORTCUTS,
20073
20230
  onChange: handleChange
20074
20231
  });
20075
20232
  }
@@ -20653,10 +20810,30 @@ function DocFooter() {
20653
20810
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocFooterContent, {});
20654
20811
  }
20655
20812
 
20813
+ //#endregion
20814
+ //#region src/views/doc-side-menu-layout.ts
20815
+ function isDocSideMenuTableOverlapping(outline, table, viewport) {
20816
+ if (table.bottom <= outline.top || table.top >= outline.bottom) return false;
20817
+ let left = table.left;
20818
+ let right = table.right;
20819
+ if (viewport && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth) {
20820
+ const clipLeft = viewport.viewportLeft ?? table.left - (viewport.leadingInsetLeft ?? 0);
20821
+ left = Math.max(clipLeft, table.left - viewport.scrollLeft);
20822
+ right = Math.min(clipLeft + viewport.viewportWidth, table.left + viewport.contentWidth - viewport.scrollLeft);
20823
+ }
20824
+ return right > left && left < outline.right && right > outline.left;
20825
+ }
20826
+
20656
20827
  //#endregion
20657
20828
  //#region src/views/SideMenu.tsx
20658
20829
  const SideMenu = (0, react.forwardRef)((props, ref) => {
20659
- const { label, menus, onClick, className, style, mode, maxHeight, activeId, open, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
20830
+ const { label, menus, onClick, className, style, mode = "side-bar", maxHeight, activeId, open: controlledOpen, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
20831
+ const [expanded, setExpanded] = (0, react.useState)(mode === "side-bar");
20832
+ const open = controlledOpen ?? expanded;
20833
+ const handleOpenChange = (0, react.useCallback)((nextOpen) => {
20834
+ if (controlledOpen === void 0) setExpanded(nextOpen);
20835
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(nextOpen);
20836
+ }, [controlledOpen, onOpenChange]);
20660
20837
  const panelId = (0, react.useId)();
20661
20838
  const wrapperRef = (0, react.useRef)(null);
20662
20839
  const containerRef = (0, react.useRef)(null);
@@ -20684,13 +20861,13 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
20684
20861
  if (!open || mode !== "float") return;
20685
20862
  const handlePointerDown = (event) => {
20686
20863
  var _wrapperRef$current;
20687
- if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target))) onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
20864
+ if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target))) handleOpenChange(false);
20688
20865
  };
20689
20866
  document.addEventListener("pointerdown", handlePointerDown);
20690
20867
  return () => document.removeEventListener("pointerdown", handlePointerDown);
20691
20868
  }, [
20869
+ handleOpenChange,
20692
20870
  mode,
20693
- onOpenChange,
20694
20871
  open
20695
20872
  ]);
20696
20873
  const handleKeyDown = (event) => {
@@ -20699,7 +20876,7 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
20699
20876
  var _toggleRef$current;
20700
20877
  event.preventDefault();
20701
20878
  event.stopPropagation();
20702
- onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
20879
+ handleOpenChange(false);
20703
20880
  (_toggleRef$current = toggleRef.current) === null || _toggleRef$current === void 0 || _toggleRef$current.focus();
20704
20881
  return;
20705
20882
  }
@@ -20728,51 +20905,47 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
20728
20905
  };
20729
20906
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20730
20907
  ref: wrapperRef,
20731
- className: (0, _univerjs_design.clsx)("univer-relative univer-ml-3", wrapperClass),
20908
+ className: (0, _univerjs_design.clsx)("univer-relative univer-ms-4", wrapperClass),
20732
20909
  style: {
20733
- width,
20910
+ width: open ? width : 32,
20734
20911
  ...wrapperStyle
20735
20912
  },
20736
20913
  onKeyDown: handleKeyDown,
20737
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
20914
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
20738
20915
  ref: toggleRef,
20739
20916
  type: "button",
20917
+ variant: "ghost",
20918
+ size: "icon",
20740
20919
  "aria-label": label,
20741
20920
  "aria-expanded": !!open,
20742
20921
  "aria-controls": open ? panelId : void 0,
20743
20922
  title: label,
20744
- onClick: () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(!open),
20745
- className: (0, _univerjs_design.clsx)("univer-absolute univer-top-1.5 univer-z-10 univer-flex univer-size-8 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-md univer-border-0 univer-bg-gray-0 univer-text-gray-500 univer-transition-colors hover:univer-bg-gray-100 hover:univer-text-gray-900 focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:univer-outline-primary-600 dark:univer-bg-gray-900 dark:univer-text-gray-400 dark:hover:univer-bg-gray-800", !open && "univer-shadow-sm", iconClass),
20746
- style: {
20747
- left: open ? width - 40 : 0,
20748
- ...iconStyle
20749
- },
20750
- children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, { "aria-hidden": "true" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, { "aria-hidden": "true" })
20751
- }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("nav", {
20923
+ onClick: () => handleOpenChange(!open),
20924
+ className: (0, _univerjs_design.clsx)("univer-absolute univer-start-0 univer-top-0 univer-z-10 !univer-text-gray-500 hover:!univer-text-gray-900 focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:univer-outline-primary-600 dark:!univer-text-gray-400 dark:hover:!univer-text-gray-100", iconClass),
20925
+ style: iconStyle,
20926
+ children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, {
20927
+ "aria-hidden": "true",
20928
+ className: "!univer-size-6"
20929
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {
20930
+ "aria-hidden": "true",
20931
+ className: "!univer-size-5"
20932
+ })
20933
+ }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
20752
20934
  id: panelId,
20753
20935
  "aria-label": label,
20754
- className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-w-full univer-flex-col univer-overflow-hidden univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-text-gray-700 dark:univer-border-gray-700 dark:univer-bg-gray-900 dark:univer-text-gray-200", mode === "float" ? "univer-shadow-md" : "univer-shadow-sm", className),
20936
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-w-full univer-flex-col univer-overflow-hidden univer-pt-10", mode === "float" && "univer-bg-gray-0 dark:univer-bg-gray-900", className),
20755
20937
  style: {
20756
20938
  maxHeight,
20757
20939
  ...style
20758
20940
  },
20759
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20760
- className: "univer-flex univer-h-11 univer-shrink-0 univer-items-center univer-gap-2 univer-px-3 univer-pr-12 univer-text-xs univer-font-medium univer-text-gray-500 dark:univer-text-gray-400",
20761
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {
20762
- "aria-hidden": "true",
20763
- className: "univer-shrink-0 univer-text-sm"
20764
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20765
- className: "univer-truncate",
20766
- children: label
20767
- })]
20768
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20941
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20769
20942
  ref: containerRef,
20770
- className: (0, _univerjs_design.clsx)("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-px-2 univer-pb-2", _univerjs_design.scrollbarClassName),
20943
+ className: (0, _univerjs_design.clsx)("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-pb-2", _univerjs_design.scrollbarClassName),
20771
20944
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
20772
20945
  className: "univer-m-0 univer-list-none univer-p-0",
20773
20946
  children: menus === null || menus === void 0 ? void 0 : menus.map((menu) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
20774
- className: menu.isTitle ? "univer-mb-1 univer-pb-1" : void 0,
20775
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
20947
+ className: menu.isTitle ? "univer-mb-2" : void 0,
20948
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
20776
20949
  ref: (element) => {
20777
20950
  if (element) itemsRef.current.set(menu.id, element);
20778
20951
  else itemsRef.current.delete(menu.id);
@@ -20780,39 +20953,28 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
20780
20953
  type: "button",
20781
20954
  "aria-current": menu.id === activeId ? "location" : void 0,
20782
20955
  title: menu.text,
20783
- className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded univer-border-0 univer-bg-transparent univer-py-1.5 univer-pr-2 univer-text-left univer-text-sm univer-leading-5 univer-transition-colors hover:univer-bg-gray-100 focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:-univer-outline-offset-2 focus-visible:univer-outline-primary-600 dark:hover:univer-bg-gray-800", menu.isTitle ? "univer-font-semibold" : "univer-font-normal", {
20784
- "univer-bg-primary-50 univer-text-primary-700 hover:univer-bg-primary-50 dark:univer-bg-gray-700 dark:univer-text-primary-200 dark:hover:univer-bg-gray-700": menu.id === activeId,
20785
- "univer-text-gray-900 dark:univer-text-gray-100": menu.isTitle && menu.id !== activeId,
20786
- "univer-text-gray-600 dark:univer-text-gray-300": !menu.isTitle && menu.id !== activeId
20956
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-border-0 univer-bg-transparent univer-py-1.5 univer-pe-2 univer-text-start univer-text-sm univer-leading-5 univer-transition-colors focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:-univer-outline-offset-2 focus-visible:univer-outline-primary-600", menu.isTitle ? "univer-font-medium" : "univer-font-normal", {
20957
+ "univer-text-primary-600 dark:univer-text-primary-400": menu.id === activeId,
20958
+ "univer-text-gray-600 hover:univer-text-gray-900 dark:univer-text-gray-300 dark:hover:univer-text-gray-100": menu.isTitle && menu.id !== activeId,
20959
+ "univer-text-gray-500 hover:univer-text-gray-900 dark:univer-text-gray-400 dark:hover:univer-text-gray-100": !menu.isTitle && menu.id !== activeId
20787
20960
  }),
20788
- style: { paddingLeft: 10 + Math.max(0, menu.level - 1) * 12 },
20961
+ style: { paddingInlineStart: menu.isTitle ? 0 : 12 + Math.max(0, menu.level - 1) * 12 },
20789
20962
  onClick: () => {
20790
20963
  onClick === null || onClick === void 0 || onClick(menu);
20791
20964
  if (mode === "float") {
20792
20965
  var _toggleRef$current2;
20793
- onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
20966
+ handleOpenChange(false);
20794
20967
  (_toggleRef$current2 = toggleRef.current) === null || _toggleRef$current2 === void 0 || _toggleRef$current2.focus();
20795
20968
  }
20796
20969
  },
20797
- children: [
20798
- menu.level > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20799
- "aria-hidden": "true",
20800
- className: "univer-absolute univer-bottom-0 univer-top-0 univer-w-px univer-bg-gray-200 dark:univer-bg-gray-700",
20801
- style: { left: 14 + Math.max(0, menu.level - 2) * 12 }
20802
- }),
20803
- menu.id === activeId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20804
- "aria-hidden": "true",
20805
- className: "univer-absolute univer-bottom-2 univer-left-0 univer-top-2 univer-w-0.5 univer-rounded-full univer-bg-primary-600 dark:univer-bg-primary-400"
20806
- }),
20807
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20808
- className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
20809
- children: menu.text
20810
- })
20811
- ]
20970
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20971
+ className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
20972
+ children: menu.text
20973
+ })
20812
20974
  })
20813
20975
  }, menu.id))
20814
20976
  })
20815
- })]
20977
+ })
20816
20978
  })]
20817
20979
  });
20818
20980
  });
@@ -20834,52 +20996,77 @@ function findActiveHeading(boundMap, paragraphMap, scrollTop, bottom) {
20834
20996
  if (!boundMap) return;
20835
20997
  const paragraphBounds = Array.from(boundMap.values());
20836
20998
  const paragraphIndex = paragraphBounds.findIndex((p) => p.paragraphStart !== p.paragraphEnd && p.rect.top < bottom && p.rect.bottom > scrollTop);
20837
- if (paragraphIndex === -1) return void 0;
20838
- const lastParagraphIndex = paragraphBounds === null || paragraphBounds === void 0 ? void 0 : paragraphBounds.findLastIndex((p) => p.paragraphStart !== p.paragraphEnd && p.rect.top < bottom && p.rect.bottom > scrollTop);
20999
+ if (paragraphIndex === -1) return;
21000
+ let lastParagraphIndex = paragraphBounds.length - 1;
21001
+ while (lastParagraphIndex > paragraphIndex) {
21002
+ const bound = paragraphBounds[lastParagraphIndex];
21003
+ if (bound.paragraphStart !== bound.paragraphEnd && bound.rect.top < bottom && bound.rect.bottom > scrollTop) break;
21004
+ lastParagraphIndex--;
21005
+ }
20839
21006
  for (let i = paragraphIndex; i <= lastParagraphIndex; i++) {
20840
- var _paragraph$paragraphS;
20841
21007
  const bound = paragraphBounds[i];
20842
21008
  const paragraph = paragraphMap.get(bound.startIndex);
20843
- if (paragraph === null || paragraph === void 0 || (_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) return paragraph.paragraphStyle.headingId;
21009
+ if (paragraph) return paragraph.paragraphId;
20844
21010
  }
20845
21011
  for (let i = paragraphIndex; i >= 0; i--) {
20846
- var _paragraph$paragraphS2;
20847
21012
  const bound = paragraphBounds[i];
20848
21013
  const paragraph = paragraphMap.get(bound.startIndex);
20849
- if (paragraph === null || paragraph === void 0 || (_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.headingId) return paragraph.paragraphStyle.headingId;
21014
+ if (paragraph) return paragraph.paragraphId;
20850
21015
  }
20851
21016
  }
20852
21017
  const TITLE_ID = "__title";
20853
21018
  function DocSideMenu() {
20854
21019
  const config = (0, _univerjs_ui.useConfigValue)(DOCS_UI_PLUGIN_CONFIG_KEY);
20855
21020
  const workbenchService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IWorkbenchService);
20856
- if ((0, _univerjs_ui.useObservable)(workbenchService.rootUnitType$, null, true) === _univerjs_core.UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocSideMenuContent, {});
21021
+ if ((0, _univerjs_ui.useObservable)(workbenchService.rootUnitType$, null, true) === _univerjs_core.UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocSideMenuContent, { toc: config === null || config === void 0 ? void 0 : config.toc });
20857
21022
  return null;
20858
21023
  }
20859
- function DocSideMenuContent() {
20860
- var _documentData$body, _documentData$body3;
21024
+ function DocSideMenuContent({ toc }) {
21025
+ var _currentDoc$getSnapsh, _documentData$body, _documentData$body3, _menus$find;
20861
21026
  const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
20862
21027
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
20863
21028
  const currentDoc = (0, _univerjs_ui.useObservable)(() => instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), void 0, false, [instanceService]);
21029
+ const enabled = toc ?? (currentDoc === null || currentDoc === void 0 || (_currentDoc$getSnapsh = currentDoc.getSnapshot().documentStyle) === null || _currentDoc$getSnapsh === void 0 ? void 0 : _currentDoc$getSnapsh.documentFlavor) === _univerjs_core.DocumentFlavor.MODERN;
20864
21030
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
20865
21031
  const documentData = (0, _univerjs_ui.useObservable)(currentDoc ? () => currentDoc.change$.pipe((0, rxjs.debounceTime)(100), (0, rxjs.map)(() => currentDoc.getSnapshot())) : null, currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getSnapshot(), false, [currentDoc]);
20866
21032
  const fullDataStream = (documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) ?? "";
20867
21033
  const [activeId, setActiveId] = (0, react.useState)(void 0);
21034
+ const [outlineHeight, setOutlineHeight] = (0, react.useState)(0);
21035
+ const containerRef = (0, react.useRef)(null);
20868
21036
  const unitId = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) ?? "";
20869
21037
  const renderer = renderManagerService.getRenderUnitById(unitId);
20870
21038
  const title = documentData === null || documentData === void 0 ? void 0 : documentData.title;
20871
21039
  const docEventManagerService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocEventManagerService);
20872
- const paragraphBounds = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds;
21040
+ const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
20873
21041
  const readLayout = () => {
20874
21042
  var _renderer$mainCompone;
21043
+ const scaleX = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleX) ?? 1;
21044
+ const scaleY = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) ?? 1;
21045
+ const scrollX = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollX) ?? 0;
21046
+ const scrollY = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollY) ?? 0;
21047
+ const canvasHeight = (renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) ?? 0;
21048
+ const left = (((renderer === null || renderer === void 0 || (_renderer$mainCompone = renderer.mainComponent) === null || _renderer$mainCompone === void 0 ? void 0 : _renderer$mainCompone.left) ?? 0) - scrollX) * scaleX;
21049
+ const outlineRect = {
21050
+ left: scrollX + 16 / scaleX,
21051
+ right: scrollX + 272 / scaleX,
21052
+ top: scrollY + 16 / scaleY,
21053
+ bottom: scrollY + Math.min(canvasHeight - 16, 16 + outlineHeight) / scaleY
21054
+ };
21055
+ const overlapsTable = left >= 288 && outlineHeight > 0 && Array.from((docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.tableBounds.values()) ?? []).some(({ tableId, rect }) => isDocSideMenuTableOverlapping(outlineRect, rect, (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId)));
20875
21056
  return {
20876
- left: (renderer === null || renderer === void 0 || (_renderer$mainCompone = renderer.mainComponent) === null || _renderer$mainCompone === void 0 ? void 0 : _renderer$mainCompone.left) ?? 0,
20877
- canvasHeight: (renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) ?? 0,
21057
+ left,
21058
+ canvasHeight,
20878
21059
  canvasWidth: (renderer === null || renderer === void 0 ? void 0 : renderer.engine.width) ?? 0,
20879
- scaleY: (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) ?? 1
21060
+ scaleY,
21061
+ overlapsTable
20880
21062
  };
20881
21063
  };
20882
- const { left, canvasHeight, canvasWidth, scaleY } = (0, _univerjs_ui.useObservable)((renderer === null || renderer === void 0 ? void 0 : renderer.engine.onTransformChange$) ? () => (0, rxjs.merge)((0, _univerjs_core.fromEventSubject)(renderer.engine.onTransformChange$), ...renderer.mainComponent ? [(0, _univerjs_core.fromEventSubject)(renderer.mainComponent.onTransformChange$)] : []).pipe((0, rxjs.auditTime)(33), (0, rxjs.map)(readLayout), (0, rxjs.startWith)(readLayout())) : null, readLayout(), false, [renderer]);
21064
+ const layout = (0, _univerjs_ui.useObservable)((renderer === null || renderer === void 0 ? void 0 : renderer.engine.onTransformChange$) ? () => (0, rxjs.merge)((0, _univerjs_core.fromEventSubject)(renderer.engine.onTransformChange$), (0, _univerjs_core.fromEventSubject)(renderer.scene.onTransformChange$), ...renderer.mainComponent instanceof _univerjs_engine_render.Documents ? [renderer.mainComponent.pageRender$] : [], ...viewport ? [(0, _univerjs_core.fromEventSubject)(viewport.onScrollAfter$)] : [], ...renderer.mainComponent ? [(0, _univerjs_core.fromEventSubject)(renderer.mainComponent.onTransformChange$)] : []).pipe((0, rxjs.auditTime)(33), (0, rxjs.map)(readLayout), (0, rxjs.startWith)(readLayout()), (0, rxjs.distinctUntilChanged)((previous, current) => previous.left === current.left && previous.canvasHeight === current.canvasHeight && previous.canvasWidth === current.canvasWidth && previous.scaleY === current.scaleY && previous.overlapsTable === current.overlapsTable)) : null, readLayout(), false, [
21065
+ renderer,
21066
+ viewport,
21067
+ outlineHeight
21068
+ ]);
21069
+ const { left, canvasHeight, canvasWidth, scaleY } = layout;
20883
21070
  const paragraphs = (0, react.useMemo)(() => {
20884
21071
  var _documentData$body2;
20885
21072
  return (documentData === null || documentData === void 0 || (_documentData$body2 = documentData.body) === null || _documentData$body2 === void 0 ? void 0 : _documentData$body2.paragraphs) ?? [];
@@ -20888,22 +21075,26 @@ function DocSideMenuContent() {
20888
21075
  dataStream: fullDataStream,
20889
21076
  paragraphs
20890
21077
  }), [fullDataStream, paragraphs]);
21078
+ const headingParagraphs = (0, react.useMemo)(() => paragraphs.filter((p) => {
21079
+ var _p$paragraphStyle;
21080
+ return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.NORMAL_TEXT;
21081
+ }).map((p) => p.paragraphId ? p : {
21082
+ ...p,
21083
+ paragraphId: `__paragraph_${p.startIndex}`
21084
+ }), [paragraphs]);
20891
21085
  const paragraphMap = (0, react.useMemo)(() => {
20892
21086
  const map = /* @__PURE__ */ new Map();
20893
- paragraphs.forEach((p) => {
21087
+ headingParagraphs.forEach((p) => {
20894
21088
  map.set(p.startIndex, p);
20895
21089
  });
20896
21090
  return map;
20897
- }, [paragraphs]);
20898
- const mode = left < 240 ? "float" : "side-bar";
20899
- const paragraphMenus = paragraphs === null || paragraphs === void 0 ? void 0 : paragraphs.filter((p) => {
20900
- var _p$paragraphStyle;
20901
- return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.NORMAL_TEXT;
20902
- }).map((p) => {
21091
+ }, [headingParagraphs]);
21092
+ const mode = left < 288 || layout.overlapsTable ? "float" : "side-bar";
21093
+ const paragraphMenus = headingParagraphs.map((p) => {
20903
21094
  var _p$paragraphStyle2;
20904
21095
  const level = transformNamedStyleTypeToLevel(p.paragraphStyle.namedStyleType);
20905
21096
  return {
20906
- id: p.paragraphStyle.headingId,
21097
+ id: p.paragraphId,
20907
21098
  text: (0, _univerjs_core.getPlainText)(fullDataStream.slice(paragraphStarts.get(p.startIndex), p.startIndex)),
20908
21099
  level,
20909
21100
  isTitle: ((_p$paragraphStyle2 = p.paragraphStyle) === null || _p$paragraphStyle2 === void 0 ? void 0 : _p$paragraphStyle2.namedStyleType) === _univerjs_core.NamedStyleType.TITLE
@@ -20912,7 +21103,7 @@ function DocSideMenuContent() {
20912
21103
  const handleScroll = (0, _univerjs_ui.useEvent)((params) => {
20913
21104
  const scrollTop = params.viewportScrollY;
20914
21105
  const bottom = scrollTop + canvasHeight / scaleY;
20915
- const activeId = findActiveHeading(paragraphBounds, paragraphMap, scrollTop, bottom);
21106
+ const activeId = findActiveHeading(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds, paragraphMap, scrollTop, bottom);
20916
21107
  if (activeId) setActiveId(activeId);
20917
21108
  });
20918
21109
  const menus = (paragraphMenus === null || paragraphMenus === void 0 ? void 0 : paragraphMenus.find((p) => p.isTitle)) ? paragraphMenus : [...title ? [{
@@ -20921,7 +21112,32 @@ function DocSideMenuContent() {
20921
21112
  level: 1,
20922
21113
  isTitle: true
20923
21114
  }] : [], ...paragraphMenus ?? []].filter(Boolean);
20924
- const [open, setOpen] = (0, react.useState)(true);
21115
+ const outlineTitle = (_menus$find = menus.find((menu) => menu.isTitle)) === null || _menus$find === void 0 ? void 0 : _menus$find.text;
21116
+ (0, react.useLayoutEffect)(() => {
21117
+ setOutlineHeight(0);
21118
+ }, [
21119
+ unitId,
21120
+ menus.length,
21121
+ outlineTitle
21122
+ ]);
21123
+ (0, react.useLayoutEffect)(() => {
21124
+ const container = containerRef.current;
21125
+ const menu = container === null || container === void 0 ? void 0 : container.firstElementChild;
21126
+ if (!container || !menu) return;
21127
+ const measureOutline = () => {
21128
+ var _container$querySelec;
21129
+ const height = (_container$querySelec = container.querySelector("nav")) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.getBoundingClientRect().height;
21130
+ if (height) setOutlineHeight(height);
21131
+ };
21132
+ const observer = new ResizeObserver(measureOutline);
21133
+ observer.observe(menu);
21134
+ return () => observer.disconnect();
21135
+ }, [
21136
+ mode,
21137
+ unitId,
21138
+ menus.length,
21139
+ enabled
21140
+ ]);
20925
21141
  (0, react.useEffect)(() => {
20926
21142
  const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
20927
21143
  if (!viewport) return;
@@ -20938,31 +21154,27 @@ function DocSideMenuContent() {
20938
21154
  setActiveId(menu.id);
20939
21155
  return;
20940
21156
  }
20941
- const paragraph = paragraphs.find((p) => {
20942
- var _p$paragraphStyle3;
20943
- return ((_p$paragraphStyle3 = p.paragraphStyle) === null || _p$paragraphStyle3 === void 0 ? void 0 : _p$paragraphStyle3.headingId) === menu.id;
20944
- });
21157
+ const paragraph = headingParagraphs.find((p) => p.paragraphId === menu.id);
20945
21158
  if (!paragraph) return;
20946
- const bound = paragraphBounds === null || paragraphBounds === void 0 ? void 0 : paragraphBounds.get(paragraph.startIndex);
21159
+ const bound = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds.get(paragraph.startIndex);
20947
21160
  if (!bound) return;
20948
21161
  viewport.scrollToViewportPos({ viewportScrollY: bound.rect.top });
20949
21162
  setActiveId(menu.id);
20950
21163
  });
20951
- if (!currentDoc || (0, _univerjs_core.isInternalEditorID)(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
21164
+ if (!enabled || !currentDoc || (0, _univerjs_core.isInternalEditorID)(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
20952
21165
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
21166
+ ref: containerRef,
20953
21167
  className: "univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",
20954
21168
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SideMenu, {
20955
21169
  label: localeService.t("docs-ui.outline.title"),
20956
21170
  menus,
20957
- open,
20958
- onOpenChange: setOpen,
20959
21171
  mode,
20960
21172
  maxWidth: Math.max(0, Math.floor(mode === "float" ? canvasWidth : left) - 24),
20961
21173
  wrapperClass: "univer-mt-4",
20962
21174
  activeId,
20963
21175
  onClick: handleClick,
20964
21176
  maxHeight: Math.max(0, canvasHeight - 32)
20965
- })
21177
+ }, mode)
20966
21178
  });
20967
21179
  }
20968
21180
 
@@ -21340,7 +21552,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
21340
21552
  //#endregion
21341
21553
  //#region package.json
21342
21554
  var name = "@univerjs/docs-ui";
21343
- var version = "1.0.4";
21555
+ var version = "1.2.0";
21344
21556
 
21345
21557
  //#endregion
21346
21558
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -22202,7 +22414,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
22202
22414
  }
22203
22415
  _deferUnmaterializedCursorMove(doc, skeleton, offset, segmentId, resume) {
22204
22416
  var _skeleton$getSkeleton, _render$getInjector, _doc$getBody;
22205
- if (segmentId !== "") return false;
22417
+ if (segmentId !== "" || skeleton.getViewModel().getCollapsedHeadingAtOffset(offset)) return false;
22206
22418
  const pageIndex = skeleton.findBodyPageIndexByCharIndex(offset);
22207
22419
  const page = (_skeleton$getSkeleton = skeleton.getSkeletonData()) === null || _skeleton$getSkeleton === void 0 ? void 0 : _skeleton$getSkeleton.pages[pageIndex];
22208
22420
  if (pageIndex >= 0 && !(page === null || page === void 0 ? void 0 : page.isMaterializationPlaceholder)) return false;
@@ -22311,6 +22523,13 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
22311
22523
  const visited = /* @__PURE__ */ new Set();
22312
22524
  while (current >= 0 && current < dataStream.length && !visited.has(current)) {
22313
22525
  visited.add(current);
22526
+ if (!segmentId) {
22527
+ const hidden = skeleton.getViewModel().getCollapsedHeadingAtOffset(current);
22528
+ if (hidden) {
22529
+ current = step < 0 ? hidden.paragraphIndex : hidden.endOffset;
22530
+ continue;
22531
+ }
22532
+ }
22314
22533
  const normalizedCursor = this._normalizeCursorOffset(dataStream, customRanges, current, direction);
22315
22534
  if (normalizedCursor < 0 || normalizedCursor >= dataStream.length) return;
22316
22535
  if (this._isRenderableCursorOffset(skeleton, dataStream, normalizedCursor, segmentId, segmentPage)) return normalizedCursor;
@@ -24528,6 +24747,7 @@ let MobileComponentsController = class MobileComponentsController extends _unive
24528
24747
  H5Icon: _univerjs_icons.H5Icon,
24529
24748
  HeaderFooterIcon: _univerjs_icons.HeaderFooterIcon,
24530
24749
  HorizontallyIcon: _univerjs_icons.HorizontallyIcon,
24750
+ InsertBelowDoubleIcon: _univerjs_icons.InsertBelowDoubleIcon,
24531
24751
  InsertDoubleIcon: _univerjs_icons.InsertDoubleIcon,
24532
24752
  InsertRowAboveDoubleIcon: _univerjs_icons.InsertRowAboveDoubleIcon,
24533
24753
  InsertRowBelowDoubleIcon: _univerjs_icons.InsertRowBelowDoubleIcon,
@@ -24560,6 +24780,7 @@ let MobileComponentsController = class MobileComponentsController extends _unive
24560
24780
  TodoListDoubleIcon: _univerjs_icons.TodoListDoubleIcon,
24561
24781
  UnderlineIcon: _univerjs_icons.UnderlineIcon,
24562
24782
  UnorderIcon: _univerjs_icons.UnorderIcon,
24783
+ ZoomInIcon: _univerjs_icons.ZoomInIcon,
24563
24784
  DefaultTextColorIcon,
24564
24785
  HeaderTextColorIcon,
24565
24786
  MoreRightIcon: _univerjs_icons.MoreRightIcon,
@@ -28308,6 +28529,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28308
28529
  var _this$_paragraphMenu2;
28309
28530
  return ((_this$_paragraphMenu2 = this._paragraphMenu) === null || _this$_paragraphMenu2 === void 0 ? void 0 : _this$_paragraphMenu2.target) ?? null;
28310
28531
  }
28532
+ get focusedTableTarget() {
28533
+ var _this$_focusedTableMe;
28534
+ return ((_this$_focusedTableMe = this._focusedTableMenu) === null || _this$_focusedTableMe === void 0 ? void 0 : _this$_focusedTableMe.target) ?? null;
28535
+ }
28311
28536
  setBlockMenuDragging(isDragging) {
28312
28537
  this._isBlockMenuDragging = isDragging;
28313
28538
  if (isDragging) this._dragInteraction ??= this._docLayoutInteractionService.beginInteraction();
@@ -28335,6 +28560,11 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28335
28560
  _defineProperty(this, "_paragraphMenu", null);
28336
28561
  _defineProperty(this, "_activeTarget$", new rxjs.BehaviorSubject(null));
28337
28562
  _defineProperty(this, "activeTarget$", this._activeTarget$.asObservable());
28563
+ _defineProperty(this, "_focusedTableMenu", null);
28564
+ _defineProperty(this, "_focusedTableTarget$", new rxjs.BehaviorSubject(null));
28565
+ _defineProperty(this, "focusedTableTarget$", this._focusedTableTarget$.asObservable());
28566
+ _defineProperty(this, "_focusedTableMenuDismiss$", new rxjs.Subject());
28567
+ _defineProperty(this, "focusedTableMenuDismiss$", this._focusedTableMenuDismiss$.asObservable());
28338
28568
  _defineProperty(this, "_slashMenuRequest$", new rxjs.BehaviorSubject(null));
28339
28569
  _defineProperty(this, "slashMenuRequest$", this._slashMenuRequest$.asObservable());
28340
28570
  _defineProperty(this, "_isBlockMenuDragging", false);
@@ -28350,6 +28580,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28350
28580
  this._isBlockMenuDragging = false;
28351
28581
  this.hideParagraphMenu(true);
28352
28582
  }
28583
+ if (this._focusedTableMenu && !this._canEditDocument(this._focusedTableMenu.target.menuRange)) this.hideFocusedTableMenu();
28353
28584
  }));
28354
28585
  }
28355
28586
  _isCursorInActiveParagraph() {
@@ -28386,9 +28617,11 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28386
28617
  _hasExpandedSelection() {
28387
28618
  return this._hasExpandedSelectionRanges(this._docSelectionManagerService.getDocRanges());
28388
28619
  }
28389
- setParagraphMenuActive(active) {
28390
- if (this._paragraphMenu) this._paragraphMenu.active = active;
28391
- if (active && this._paragraphMenu) this._menuInteraction ??= this._docLayoutInteractionService.beginInteraction();
28620
+ setParagraphMenuActive(active, focusedTable = false) {
28621
+ var _this$_paragraphMenu3, _this$_focusedTableMe2;
28622
+ const menu = focusedTable ? this._focusedTableMenu : this._paragraphMenu;
28623
+ if (menu) menu.active = active;
28624
+ if (((_this$_paragraphMenu3 = this._paragraphMenu) === null || _this$_paragraphMenu3 === void 0 ? void 0 : _this$_paragraphMenu3.active) || ((_this$_focusedTableMe2 = this._focusedTableMenu) === null || _this$_focusedTableMe2 === void 0 ? void 0 : _this$_focusedTableMe2.active)) this._menuInteraction ??= this._docLayoutInteractionService.beginInteraction();
28392
28625
  else {
28393
28626
  var _this$_menuInteractio;
28394
28627
  (_this$_menuInteractio = this._menuInteraction) === null || _this$_menuInteractio === void 0 || _this$_menuInteractio.dispose();
@@ -28397,7 +28630,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28397
28630
  }
28398
28631
  _init() {
28399
28632
  const handleHoverTarget = (paragraph, tableBound) => {
28633
+ var _this$_focusedTableMe3;
28400
28634
  if (this._isBlockMenuDragging) return;
28635
+ if ((_this$_focusedTableMe3 = this._focusedTableMenu) === null || _this$_focusedTableMe3 === void 0 ? void 0 : _this$_focusedTableMe3.active) return;
28401
28636
  if (this._docSelectionRenderService.isOnPointerEvent) {
28402
28637
  this.hideParagraphMenu(true);
28403
28638
  return;
@@ -28408,18 +28643,18 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28408
28643
  return;
28409
28644
  }
28410
28645
  if (selectionState.hasRectRange) {
28411
- var _this$_paragraphMenu3;
28646
+ var _this$_paragraphMenu4;
28412
28647
  if (tableBound) {
28413
28648
  this.showTableMenu(tableBound);
28414
28649
  return;
28415
28650
  }
28416
- if (((_this$_paragraphMenu3 = this._paragraphMenu) === null || _this$_paragraphMenu3 === void 0 ? void 0 : _this$_paragraphMenu3.target.kind) === _univerjs_core.DocumentBlockType.TABLE) return;
28651
+ if (((_this$_paragraphMenu4 = this._paragraphMenu) === null || _this$_paragraphMenu4 === void 0 ? void 0 : _this$_paragraphMenu4.target.kind) === _univerjs_core.DocumentBlockType.TABLE) return;
28417
28652
  this.hideParagraphMenu(true);
28418
28653
  return;
28419
28654
  }
28420
28655
  if (this._docSkeletonManagerService.getViewModel().getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY && !this._floatMenuService.floatMenu && !this._context.unit.getDisabled() && this._canEditDocument()) {
28421
- var _this$_paragraphMenu4;
28422
- if ((_this$_paragraphMenu4 = this._paragraphMenu) === null || _this$_paragraphMenu4 === void 0 ? void 0 : _this$_paragraphMenu4.active) return;
28656
+ var _this$_paragraphMenu5;
28657
+ if ((_this$_paragraphMenu5 = this._paragraphMenu) === null || _this$_paragraphMenu5 === void 0 ? void 0 : _this$_paragraphMenu5.active) return;
28423
28658
  if (paragraph) {
28424
28659
  this.showParagraphMenu(paragraph);
28425
28660
  return;
@@ -28445,16 +28680,17 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28445
28680
  this.hideParagraphMenu(true);
28446
28681
  }));
28447
28682
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
28448
- var _this$_paragraphMenu5;
28683
+ var _this$_paragraphMenu6;
28449
28684
  const selectionState = this._getExpandedSelectionState([...textRanges, ...rectRanges]);
28450
- if (selectionState.hasExpandedTextRange || selectionState.hasRectRange && ((_this$_paragraphMenu5 = this._paragraphMenu) === null || _this$_paragraphMenu5 === void 0 ? void 0 : _this$_paragraphMenu5.target.kind) !== _univerjs_core.DocumentBlockType.TABLE) this.hideParagraphMenu(true);
28685
+ if (selectionState.hasExpandedTextRange || selectionState.hasRectRange && ((_this$_paragraphMenu6 = this._paragraphMenu) === null || _this$_paragraphMenu6 === void 0 ? void 0 : _this$_paragraphMenu6.target.kind) !== _univerjs_core.DocumentBlockType.TABLE) this.hideParagraphMenu(true);
28451
28686
  }));
28452
28687
  let lastScrollY = 0;
28453
28688
  this.disposeWithMe(this._context.scene.getViewport("viewMain").onScrollAfter$.subscribeEvent((e) => {
28454
- var _this$_paragraphMenu6;
28689
+ var _this$_paragraphMenu7;
28455
28690
  if (lastScrollY === e.scrollY) return;
28456
28691
  lastScrollY = e.scrollY;
28457
- if ((_this$_paragraphMenu6 = this._paragraphMenu) === null || _this$_paragraphMenu6 === void 0 ? void 0 : _this$_paragraphMenu6.blockRange) return;
28692
+ this._focusedTableMenuDismiss$.next();
28693
+ if ((_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.blockRange) return;
28458
28694
  if (this._isBlockMenuDragging) return;
28459
28695
  this.hideParagraphMenu(true);
28460
28696
  }));
@@ -28465,6 +28701,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28465
28701
  this.disposeWithMe(this._docSelectionRenderService.onKeydown$.subscribe((config) => {
28466
28702
  if (this._isBlockMenuDragging) return;
28467
28703
  if (this._handleSlashMenuKeydown(config)) return;
28704
+ this._focusedTableMenuDismiss$.next();
28468
28705
  this.hideParagraphMenu(true);
28469
28706
  }));
28470
28707
  this.disposeWithMe(this._docSelectionRenderService.onInputBefore$.subscribe((config) => {
@@ -28520,10 +28757,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28520
28757
  return null;
28521
28758
  }
28522
28759
  _getSlashMenuParagraph(config) {
28523
- var _this$_paragraphMenu7;
28760
+ var _this$_paragraphMenu8;
28524
28761
  const activeRange = this._getCollapsedTextRange(config);
28525
28762
  const offset = activeRange === null || activeRange === void 0 ? void 0 : activeRange.startOffset;
28526
- const activeParagraph = ((_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.paragraph) ?? null;
28763
+ const activeParagraph = ((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.paragraph) ?? null;
28527
28764
  if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) return activeParagraph;
28528
28765
  if (activeParagraph && offset == null) return activeParagraph;
28529
28766
  if (offset == null) return null;
@@ -28544,7 +28781,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28544
28781
  }
28545
28782
  }
28546
28783
  showParagraphMenu(paragraph) {
28547
- var _this$_paragraphMenu8;
28784
+ var _this$_paragraphMenu9;
28548
28785
  if (this._hasExpandedSelection()) {
28549
28786
  this.hideParagraphMenu(true);
28550
28787
  return;
@@ -28554,15 +28791,21 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28554
28791
  this.hideParagraphMenu(true);
28555
28792
  return;
28556
28793
  }
28557
- if (((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.target.key) === target.key) return;
28794
+ if (((_this$_paragraphMenu9 = this._paragraphMenu) === null || _this$_paragraphMenu9 === void 0 ? void 0 : _this$_paragraphMenu9.target.key) === target.key) return;
28558
28795
  this.hideParagraphMenu(true);
28559
28796
  const targetParagraph = target.paragraph ?? paragraph;
28560
28797
  const blockRange = target.blockRange;
28561
28798
  const getFirstLine = () => {
28799
+ var _this$_context$unit$g;
28562
28800
  const latestParagraphBound = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex) ?? targetParagraph;
28563
28801
  const baseAnchor = blockRange ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph) : latestParagraphBound.firstLine ?? paragraph.firstLine;
28564
- if (!target.cellRange) return baseAnchor;
28565
- return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, baseAnchor);
28802
+ const menuAnchor = ((_this$_context$unit$g = this._context.unit.getSnapshot().documentStyle) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.documentFlavor) === _univerjs_core.DocumentFlavor.MODERN && this._docSkeletonManagerService.getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === targetParagraph.startIndex && heading.startOffset < heading.endOffset) ? {
28803
+ ...baseAnchor,
28804
+ left: baseAnchor.left - 24,
28805
+ right: baseAnchor.right - 24
28806
+ } : baseAnchor;
28807
+ if (!target.cellRange) return menuAnchor;
28808
+ return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, menuAnchor);
28566
28809
  };
28567
28810
  const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
28568
28811
  componentKey: DOC_PARAGRAPH_MENU_COMPONENT_KEY,
@@ -28589,15 +28832,19 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28589
28832
  };
28590
28833
  this._activeTarget$.next(target);
28591
28834
  }
28592
- showTableMenu(tableBound) {
28593
- var _body$tables, _this$_paragraphMenu9;
28594
- if (this._hasExpandedTextSelection()) {
28835
+ showTableMenu(tableBound, focused = false) {
28836
+ var _this$_focusedTableMe4, _body$tables, _this$_paragraphMenu10;
28837
+ if (!focused && ((_this$_focusedTableMe4 = this._focusedTableMenu) === null || _this$_focusedTableMe4 === void 0 || (_this$_focusedTableMe4 = _this$_focusedTableMe4.target.table) === null || _this$_focusedTableMe4 === void 0 ? void 0 : _this$_focusedTableMe4.tableId) === tableBound.tableId) return;
28838
+ if (!focused && this._hasExpandedTextSelection()) {
28595
28839
  this.hideParagraphMenu(true);
28596
28840
  return;
28597
28841
  }
28598
28842
  const body = this._context.unit.getBody();
28599
28843
  const table = body === null || body === void 0 || (_body$tables = body.tables) === null || _body$tables === void 0 ? void 0 : _body$tables.find((item) => item.tableId === tableBound.tableId);
28600
- if (!table) return;
28844
+ if (!table) {
28845
+ if (focused) this.hideFocusedTableMenu();
28846
+ return;
28847
+ }
28601
28848
  const target = {
28602
28849
  kind: _univerjs_core.DocumentBlockType.TABLE,
28603
28850
  key: `${_univerjs_core.DocumentBlockType.TABLE}:${table.tableId}`,
@@ -28610,17 +28857,21 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28610
28857
  },
28611
28858
  moveRange: {
28612
28859
  startOffset: table.startIndex,
28613
- endOffset: table.endIndex
28860
+ endOffset: table.endIndex + ((body === null || body === void 0 ? void 0 : body.dataStream[table.endIndex]) === "\r" ? 1 : 0)
28614
28861
  },
28615
28862
  emptyMode: false,
28616
28863
  draggable: true
28617
28864
  };
28618
28865
  if (!this._canEditDocument(target.menuRange)) {
28866
+ if (focused) {
28867
+ this.hideFocusedTableMenu();
28868
+ return;
28869
+ }
28619
28870
  this.hideParagraphMenu(true);
28620
28871
  return;
28621
28872
  }
28622
- if (this._shouldKeepCurrentCellMenuForTable(table)) return;
28623
- if (((_this$_paragraphMenu9 = this._paragraphMenu) === null || _this$_paragraphMenu9 === void 0 ? void 0 : _this$_paragraphMenu9.target.key) === target.key) return;
28873
+ if (!focused && this._shouldKeepCurrentCellMenuForTable(table)) return;
28874
+ if (!focused && ((_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target.key) === target.key) return;
28624
28875
  const anchorRect = getTableAnchorRect(tableBound);
28625
28876
  const paragraph = {
28626
28877
  rect: tableBound.rect,
@@ -28631,8 +28882,16 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28631
28882
  pageIndex: tableBound.pageIndex,
28632
28883
  firstLine: anchorRect
28633
28884
  };
28885
+ if (focused) {
28886
+ target.paragraph = paragraph;
28887
+ this._showFocusedTableMenu(tableBound, target);
28888
+ return;
28889
+ }
28890
+ this._showHoverTableMenu(tableBound, target, paragraph);
28891
+ }
28892
+ _showHoverTableMenu(tableBound, target, paragraph) {
28634
28893
  this.hideParagraphMenu(true);
28635
- const getFirstLine = () => getTableAnchorRect(this._docEventManagerService.tableBounds.get(table.tableId) ?? tableBound);
28894
+ const getFirstLine = () => getTableAnchorRect(this._docEventManagerService.tableBounds.get(tableBound.tableId) ?? tableBound);
28636
28895
  const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
28637
28896
  componentKey: DOC_TABLE_BLOCK_MENU_COMPONENT_KEY,
28638
28897
  constrainToCanvas: true,
@@ -28651,9 +28910,40 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28651
28910
  };
28652
28911
  this._activeTarget$.next(target);
28653
28912
  }
28913
+ _showFocusedTableMenu(tableBound, target) {
28914
+ var _this$_focusedTableMe5, _this$_paragraphMenu11;
28915
+ if (((_this$_focusedTableMe5 = this._focusedTableMenu) === null || _this$_focusedTableMe5 === void 0 ? void 0 : _this$_focusedTableMe5.target.key) === target.key) {
28916
+ this._focusedTableMenu.target = target;
28917
+ this._focusedTableMenu.bound = tableBound;
28918
+ this._focusedTableTarget$.next(target);
28919
+ return;
28920
+ }
28921
+ this.hideFocusedTableMenu();
28922
+ if (((_this$_paragraphMenu11 = this._paragraphMenu) === null || _this$_paragraphMenu11 === void 0 ? void 0 : _this$_paragraphMenu11.target.key) === target.key) this.hideParagraphMenu(true);
28923
+ const getFocusedAnchor = () => {
28924
+ var _this$_focusedTableMe6;
28925
+ return getTableAnchorRect(this._docEventManagerService.tableBounds.get(tableBound.tableId) ?? ((_this$_focusedTableMe6 = this._focusedTableMenu) === null || _this$_focusedTableMe6 === void 0 ? void 0 : _this$_focusedTableMe6.bound) ?? tableBound);
28926
+ };
28927
+ const disposable = this._docPopupManagerService.attachPopupToRect(getFocusedAnchor, {
28928
+ componentKey: DOC_TABLE_BLOCK_MENU_COMPONENT_KEY,
28929
+ extraProps: { focusedTableMenu: true },
28930
+ constrainToCanvas: true,
28931
+ requiresStableLayout: false,
28932
+ direction: "top-right",
28933
+ onClickOutside: () => this._focusedTableMenuDismiss$.next(),
28934
+ zIndex: 102
28935
+ }, this._context.unitId);
28936
+ this._focusedTableMenu = {
28937
+ target,
28938
+ bound: tableBound,
28939
+ disposable,
28940
+ active: false
28941
+ };
28942
+ this._focusedTableTarget$.next(target);
28943
+ }
28654
28944
  _shouldKeepCurrentCellMenuForTable(table) {
28655
- var _this$_paragraphMenu10;
28656
- const target = (_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target;
28945
+ var _this$_paragraphMenu12;
28946
+ const target = (_this$_paragraphMenu12 = this._paragraphMenu) === null || _this$_paragraphMenu12 === void 0 ? void 0 : _this$_paragraphMenu12.target;
28657
28947
  if (!target || target.kind === _univerjs_core.DocumentBlockType.TABLE || !target.cellRange) return false;
28658
28948
  return target.cellRange.startOffset >= table.startIndex && target.cellRange.startOffset <= table.endIndex;
28659
28949
  }
@@ -28696,22 +28986,32 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
28696
28986
  hideParagraphMenu(force = false) {
28697
28987
  if (this._isBlockMenuDragging) return;
28698
28988
  if (this._paragraphMenu && (this._paragraphMenu.disposable.canDispose() || force)) {
28699
- var _this$_menuInteractio2;
28700
28989
  this._paragraphMenu.disposable.dispose();
28701
28990
  this._paragraphMenu = null;
28702
- (_this$_menuInteractio2 = this._menuInteraction) === null || _this$_menuInteractio2 === void 0 || _this$_menuInteractio2.dispose();
28703
- this._menuInteraction = null;
28991
+ this.setParagraphMenuActive(false);
28704
28992
  this._isSlashMenuActive = false;
28705
28993
  this._slashMenuRequest$.next(null);
28706
28994
  this._activeTarget$.next(null);
28707
28995
  }
28708
28996
  }
28997
+ hideFocusedTableMenu() {
28998
+ var _this$_focusedTableMe7;
28999
+ (_this$_focusedTableMe7 = this._focusedTableMenu) === null || _this$_focusedTableMe7 === void 0 || _this$_focusedTableMe7.disposable.dispose();
29000
+ this._focusedTableMenu = null;
29001
+ this._focusedTableTarget$.next(null);
29002
+ this.setParagraphMenuActive(false, true);
29003
+ }
28709
29004
  _canEditDocument(range, segmentId = "") {
28710
29005
  return (0, _univerjs_docs.canEditDocumentTargets)(this._permissionService, this._context.unitId, range ? (0, _univerjs_docs.getDocumentEditTargetObjectIds)(this._context.unit, segmentId, range) : []);
28711
29006
  }
28712
29007
  dispose() {
28713
- var _this$_menuInteractio3, _this$_dragInteractio2;
28714
- (_this$_menuInteractio3 = this._menuInteraction) === null || _this$_menuInteractio3 === void 0 || _this$_menuInteractio3.dispose();
29008
+ var _this$_menuInteractio2, _this$_dragInteractio2;
29009
+ this._isBlockMenuDragging = false;
29010
+ this.hideFocusedTableMenu();
29011
+ this.hideParagraphMenu(true);
29012
+ this._focusedTableTarget$.complete();
29013
+ this._focusedTableMenuDismiss$.complete();
29014
+ (_this$_menuInteractio2 = this._menuInteraction) === null || _this$_menuInteractio2 === void 0 || _this$_menuInteractio2.dispose();
28715
29015
  this._menuInteraction = null;
28716
29016
  (_this$_dragInteractio2 = this._dragInteraction) === null || _this$_dragInteractio2 === void 0 || _this$_dragInteractio2.dispose();
28717
29017
  this._dragInteraction = null;
@@ -29043,9 +29343,6 @@ function createParagraphMenuHoverOpenScheduler(openMenu, delay = 800) {
29043
29343
  }
29044
29344
  };
29045
29345
  }
29046
- function setParagraphMenuInteractionActive(docParagraphMenuService, active) {
29047
- docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(active);
29048
- }
29049
29346
  function isEmptyParagraphMenuTarget(dataStream, paragraph) {
29050
29347
  if (!paragraph) return false;
29051
29348
  return dataStream.slice(paragraph.paragraphStart, paragraph.paragraphEnd).replace(/[\r\n]/g, "") === "";
@@ -29455,7 +29752,7 @@ function getBlockRangeClipboardTargetRange(commandId, target, paragraph) {
29455
29752
  return null;
29456
29753
  }
29457
29754
  function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29458
- var _doc$getBody, _paragraphObj$paragra;
29755
+ var _popup$extraProps, _doc$getBody, _paragraphObj$paragra;
29459
29756
  const [visible, setVisible] = (0, react.useState)(false);
29460
29757
  const [openMode, setOpenMode] = (0, react.useState)("pointer");
29461
29758
  const [anchorRect, setAnchorRect] = (0, react.useState)(null);
@@ -29464,10 +29761,12 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29464
29761
  const targetRangeRef = (0, react.useRef)(null);
29465
29762
  const dragTargetOffsetRef = (0, react.useRef)(null);
29466
29763
  const dragRangeRef = (0, react.useRef)(null);
29764
+ const dragCleanupRef = (0, react.useRef)(null);
29467
29765
  const isDraggingRef = (0, react.useRef)(false);
29468
29766
  const openMenuRef = (0, react.useRef)(() => void 0);
29469
29767
  const hoverOpenSchedulerRef = (0, react.useRef)(createParagraphMenuHoverOpenScheduler(() => openMenuRef.current()));
29470
29768
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
29769
+ const logService = (0, _univerjs_ui.useDependency)(_univerjs_core.ILogService);
29471
29770
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
29472
29771
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
29473
29772
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
@@ -29488,12 +29787,20 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29488
29787
  const doc = univerInstanceService.getUnit(popup.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
29489
29788
  const docParagraphMenuService = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocParagraphMenuService);
29490
29789
  const docEventManagerService = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocEventManagerService);
29491
- const activeTarget = (0, _univerjs_ui.useObservable)(docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget$);
29790
+ const isFocusedTableMenu = ((_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.focusedTableMenu) === true;
29791
+ const activeTarget = (0, _univerjs_ui.useObservable)(isFocusedTableMenu ? docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.focusedTableTarget$ : docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget$);
29492
29792
  const slashMenuRequest = (0, _univerjs_ui.useObservable)(docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.slashMenuRequest$);
29493
29793
  const paragraph = (0, _univerjs_ui.useObservable)(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.hoverParagraph$);
29494
29794
  const paragraphLeft = (0, _univerjs_ui.useObservable)(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.hoverParagraphLeft$);
29495
- const rawActiveTarget = activeTarget ?? (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget);
29496
- const currentActiveTarget = tableBlockOnly ? (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" ? rawActiveTarget : null : (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" ? null : rawActiveTarget;
29795
+ const getActiveTarget = () => {
29796
+ if (isFocusedTableMenu) return (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.focusedTableTarget) ?? activeTarget;
29797
+ return (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
29798
+ };
29799
+ const setMenuInteractionActive = (active) => {
29800
+ docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(active, isFocusedTableMenu);
29801
+ };
29802
+ const rawActiveTarget = getActiveTarget();
29803
+ const currentActiveTarget = (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" === tableBlockOnly ? rawActiveTarget : null;
29497
29804
  const activeParagraphBound = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.paragraph) ?? (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeParagraph) ?? paragraph ?? paragraphLeft;
29498
29805
  const startIndex = activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.startIndex;
29499
29806
  const dataStream = (doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.dataStream) ?? "";
@@ -29503,6 +29810,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29503
29810
  }, [doc, startIndex]);
29504
29811
  const isEmptyParagraph = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
29505
29812
  const namedStyleType = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra === void 0 ? void 0 : _paragraphObj$paragra.namedStyleType;
29813
+ const isModernHeading = (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) === _univerjs_core.DocumentFlavor.MODERN && startIndex != null && (renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(_univerjs_docs.DocSkeletonManagerService).getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === startIndex && heading.startOffset < heading.endOffset));
29506
29814
  const targetIconKey = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey(namedStyleType);
29507
29815
  const TargetIcon = iconManager.get(targetIconKey);
29508
29816
  const paragraphMenuType = (0, react.useMemo)(() => getParagraphMenuType(currentActiveTarget, isEmptyParagraph), [currentActiveTarget, isEmptyParagraph]);
@@ -29546,13 +29854,41 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29546
29854
  if (activeElement === focusedElement || !focusedElement.isConnected && activeElement === body) layoutService.focus();
29547
29855
  }, [layoutService]);
29548
29856
  (0, react.useLayoutEffect)(() => restoreMenuFocus, [restoreMenuFocus]);
29549
- const handleHideMenu = () => {
29857
+ const handleHideMenu = (0, react.useCallback)(() => {
29858
+ hoverOpenSchedulerRef.current.cancel();
29550
29859
  restoreMenuFocus();
29551
29860
  setVisible(false);
29552
29861
  setOpenMode("pointer");
29553
29862
  targetRangeRef.current = null;
29554
- setParagraphMenuInteractionActive(docParagraphMenuService, false);
29555
- };
29863
+ docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(false, isFocusedTableMenu);
29864
+ }, [
29865
+ docParagraphMenuService,
29866
+ isFocusedTableMenu,
29867
+ restoreMenuFocus
29868
+ ]);
29869
+ (0, react.useEffect)(() => {
29870
+ if (!isFocusedTableMenu || !docParagraphMenuService) return;
29871
+ const subscription = docParagraphMenuService.focusedTableMenuDismiss$.subscribe(handleHideMenu);
29872
+ const ownerDocument = popup.canvasElement.ownerDocument;
29873
+ const handleKeydown = (event) => {
29874
+ if (event.key === "Escape") {
29875
+ event.preventDefault();
29876
+ event.stopPropagation();
29877
+ handleHideMenu();
29878
+ }
29879
+ };
29880
+ if (visible) ownerDocument.addEventListener("keydown", handleKeydown, true);
29881
+ return () => {
29882
+ subscription.unsubscribe();
29883
+ ownerDocument.removeEventListener("keydown", handleKeydown, true);
29884
+ };
29885
+ }, [
29886
+ docParagraphMenuService,
29887
+ isFocusedTableMenu,
29888
+ handleHideMenu,
29889
+ popup.canvasElement,
29890
+ visible
29891
+ ]);
29556
29892
  const clearHideTimer = () => {
29557
29893
  if (hideTimerRef.current != null) {
29558
29894
  window.clearTimeout(hideTimerRef.current);
@@ -29570,8 +29906,8 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29570
29906
  const handleOpenMenu = (mode = "pointer") => {
29571
29907
  clearHideTimer();
29572
29908
  if (openMode === "slash") return;
29573
- const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
29574
- setParagraphMenuInteractionActive(docParagraphMenuService, true);
29909
+ const latestTarget = getActiveTarget();
29910
+ setMenuInteractionActive(true);
29575
29911
  const targetRange = latestTarget ? {
29576
29912
  ...latestTarget.menuRange,
29577
29913
  segmentId: activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId
@@ -29619,7 +29955,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29619
29955
  return commandService.executeCommand(resolved.commandId, resolved.params);
29620
29956
  };
29621
29957
  const unwrapActiveBlockRange = async () => {
29622
- const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
29958
+ const latestTarget = getActiveTarget();
29623
29959
  if (!latestTarget || latestTarget.kind !== "blockRange" || !latestTarget.blockRange || !(doc === null || doc === void 0 ? void 0 : doc.getBody())) return null;
29624
29960
  const previousBody = doc.getBody();
29625
29961
  const { body, range } = unwrapBlockRangeBody(previousBody, latestTarget.blockRange);
@@ -29642,7 +29978,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29642
29978
  return nextRange;
29643
29979
  };
29644
29980
  const executeParagraphMenuOption = async (option) => {
29645
- const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
29981
+ const latestTarget = getActiveTarget();
29646
29982
  const targetRange = getTargetSelectionRange(latestTarget, activeParagraphBound ?? void 0);
29647
29983
  const blockRange = getBlockSelectionRange(latestTarget, activeParagraphBound ?? void 0);
29648
29984
  const formattingRange = getParagraphFormattingRange(latestTarget, activeParagraphBound ?? void 0);
@@ -29746,31 +30082,38 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29746
30082
  const hoverBridgeStyle = visible && (menuDirection === "left" || menuDirection === "right") ? getParagraphMenuHoverBridgeStyle(anchorRect, menuDirection) : void 0;
29747
30083
  const resolvedParagraphMenuType = openMode === "slash" ? DOC_PARAGRAPH_T_INSERT_MENU_ID : paragraphMenuType;
29748
30084
  (0, react.useEffect)(() => () => {
30085
+ var _dragCleanupRef$curre;
30086
+ (_dragCleanupRef$curre = dragCleanupRef.current) === null || _dragCleanupRef$curre === void 0 || _dragCleanupRef$curre.call(dragCleanupRef);
29749
30087
  if (hideTimerRef.current != null) {
29750
30088
  window.clearTimeout(hideTimerRef.current);
29751
30089
  hideTimerRef.current = null;
29752
30090
  }
29753
30091
  hoverOpenSchedulerRef.current.cancel();
29754
- setParagraphMenuInteractionActive(docParagraphMenuService, false);
29755
- }, []);
30092
+ docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(false, isFocusedTableMenu);
30093
+ }, [docParagraphMenuService, isFocusedTableMenu]);
29756
30094
  (0, react.useEffect)(() => {
29757
- if (!slashMenuRequest || handledSlashRequestNonceRef.current >= slashMenuRequest.nonce) return;
30095
+ if (tableBlockOnly || !slashMenuRequest || handledSlashRequestNonceRef.current >= slashMenuRequest.nonce) return;
29758
30096
  handledSlashRequestNonceRef.current = slashMenuRequest.nonce;
29759
30097
  hoverOpenSchedulerRef.current.cancel();
29760
30098
  clearHideTimer();
29761
30099
  isMouseOver.current = false;
29762
30100
  handleOpenSlashMenu(slashMenuRequest);
29763
- }, [slashMenuRequest]);
30101
+ }, [slashMenuRequest, tableBlockOnly]);
29764
30102
  if (!currentActiveTarget) return null;
29765
30103
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
29766
30104
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
29767
30105
  "data-u-comp": "paragraph-menu",
30106
+ "data-u-table-menu": tableBlockOnly ? "true" : void 0,
30107
+ "data-u-focused-table-menu": isFocusedTableMenu ? "true" : void 0,
29768
30108
  ref: anchorRef,
29769
- className: (0, _univerjs_design.clsx)("univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md univer-border univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colors hover:univer-bg-gray-50 hover:univer-shadow-md dark:!univer-border-gray-700 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800", { "univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800": visible }),
30109
+ className: (0, _univerjs_design.clsx)("univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colors hover:univer-bg-gray-50 hover:univer-shadow-md dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800", {
30110
+ "univer-mr-1": !isModernHeading,
30111
+ "univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800": visible
30112
+ }),
29770
30113
  onMouseEnter: (e) => {
29771
30114
  var _popup$onPointerEnter;
29772
30115
  (_popup$onPointerEnter = popup.onPointerEnter) === null || _popup$onPointerEnter === void 0 || _popup$onPointerEnter.call(popup, e);
29773
- setParagraphMenuInteractionActive(docParagraphMenuService, true);
30116
+ setMenuInteractionActive(true);
29774
30117
  isMouseOver.current = true;
29775
30118
  scheduleOpenMenu();
29776
30119
  },
@@ -29792,7 +30135,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29792
30135
  title: localeService.t("docs-ui.doc.blockMenu.dragBlock"),
29793
30136
  onPointerDown: (event) => {
29794
30137
  var _event$currentTarget$, _event$currentTarget;
29795
- const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
30138
+ const latestTarget = getActiveTarget();
29796
30139
  const moveRange = latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.moveRange;
29797
30140
  if (!moveRange || !(latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.draggable)) return;
29798
30141
  event.preventDefault();
@@ -29820,6 +30163,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29820
30163
  window.removeEventListener("pointerup", handlePointerUp);
29821
30164
  window.removeEventListener("pointercancel", handlePointerCancel);
29822
30165
  window.removeEventListener("blur", handleWindowBlur);
30166
+ dragCleanupRef.current = null;
29823
30167
  const range = dragRangeRef.current;
29824
30168
  const targetOffset = dragTargetOffsetRef.current;
29825
30169
  dragRangeRef.current = null;
@@ -29835,7 +30179,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29835
30179
  unitId: popup.unitId,
29836
30180
  sourceRange: range,
29837
30181
  targetOffset
29838
- });
30182
+ }).catch((error) => logService.error(error));
29839
30183
  };
29840
30184
  const handlePointerUp = (upEvent) => {
29841
30185
  if (upEvent.pointerId !== pointerId) return;
@@ -29849,6 +30193,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29849
30193
  const handleWindowBlur = () => {
29850
30194
  finishDrag(false);
29851
30195
  };
30196
+ dragCleanupRef.current = () => finishDrag(false);
29852
30197
  window.addEventListener("pointermove", handlePointerMove);
29853
30198
  window.addEventListener("pointerup", handlePointerUp);
29854
30199
  window.addEventListener("pointercancel", handlePointerCancel);
@@ -29864,7 +30209,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29864
30209
  onMouseEnter: (e) => {
29865
30210
  var _popup$onPointerEnter2;
29866
30211
  (_popup$onPointerEnter2 = popup.onPointerEnter) === null || _popup$onPointerEnter2 === void 0 || _popup$onPointerEnter2.call(popup, e);
29867
- setParagraphMenuInteractionActive(docParagraphMenuService, true);
30212
+ setMenuInteractionActive(true);
29868
30213
  isMouseOver.current = true;
29869
30214
  clearHideTimer();
29870
30215
  },
@@ -29887,7 +30232,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29887
30232
  onMouseEnter: (e) => {
29888
30233
  var _popup$onPointerEnter3;
29889
30234
  (_popup$onPointerEnter3 = popup.onPointerEnter) === null || _popup$onPointerEnter3 === void 0 || _popup$onPointerEnter3.call(popup, e);
29890
- setParagraphMenuInteractionActive(docParagraphMenuService, true);
30235
+ setMenuInteractionActive(true);
29891
30236
  isMouseOver.current = true;
29892
30237
  clearHideTimer();
29893
30238
  },
@@ -29905,7 +30250,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29905
30250
  autoFocusTarget: openMode === "slash" ? "container" : void 0,
29906
30251
  suppressHoverUntilPointerMove: openMode === "slash",
29907
30252
  onMenuPointerEnter: () => {
29908
- setParagraphMenuInteractionActive(docParagraphMenuService, true);
30253
+ setMenuInteractionActive(true);
29909
30254
  isMouseOver.current = true;
29910
30255
  clearHideTimer();
29911
30256
  },
@@ -29919,7 +30264,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29919
30264
  onOptionSelect: async (params) => {
29920
30265
  const targetRange = targetRangeRef.current ?? getParagraphMenuTargetRange(activeParagraphBound);
29921
30266
  const { commandId, params: commandParams } = getParagraphMenuCommand(params, targetRange);
29922
- const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
30267
+ const latestTarget = getActiveTarget();
29923
30268
  if ((latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.kind) === "table" && commandId && targetRange) {
29924
30269
  univerInstanceService.focusUnit(popup.unitId);
29925
30270
  const tableRange = {
@@ -30062,6 +30407,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
30062
30407
  H5Icon: _univerjs_icons.H5Icon,
30063
30408
  HeaderFooterIcon: _univerjs_icons.HeaderFooterIcon,
30064
30409
  HorizontallyIcon: _univerjs_icons.HorizontallyIcon,
30410
+ InsertBelowDoubleIcon: _univerjs_icons.InsertBelowDoubleIcon,
30065
30411
  InsertDoubleIcon: _univerjs_icons.InsertDoubleIcon,
30066
30412
  InsertRowAboveDoubleIcon: _univerjs_icons.InsertRowAboveDoubleIcon,
30067
30413
  InsertRowBelowDoubleIcon: _univerjs_icons.InsertRowBelowDoubleIcon,
@@ -30095,6 +30441,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
30095
30441
  TodoListDoubleIcon: _univerjs_icons.TodoListDoubleIcon,
30096
30442
  UnderlineIcon: _univerjs_icons.UnderlineIcon,
30097
30443
  UnorderIcon: _univerjs_icons.UnorderIcon,
30444
+ ZoomInIcon: _univerjs_icons.ZoomInIcon,
30098
30445
  DefaultTextColorIcon,
30099
30446
  HeaderTextColorIcon,
30100
30447
  MoreRightIcon: _univerjs_icons.MoreRightIcon,
@@ -30622,6 +30969,289 @@ let DocContextualRibbonService = class DocContextualRibbonService extends _unive
30622
30969
  };
30623
30970
  DocContextualRibbonService = __decorate([__decorateParam(0, _univerjs_ui.IRibbonService)], DocContextualRibbonService);
30624
30971
 
30972
+ //#endregion
30973
+ //#region src/views/heading-collapse-shape.ts
30974
+ var HeadingCollapseShape = class extends _univerjs_engine_render.Shape {
30975
+ constructor(key, colors, activate) {
30976
+ super(key, {
30977
+ width: 24,
30978
+ height: 28,
30979
+ debounceParentDirty: false
30980
+ });
30981
+ _defineProperty(this, "_collapsed", false);
30982
+ _defineProperty(this, "_label", "");
30983
+ _defineProperty(this, "_colors", void 0);
30984
+ _defineProperty(this, "_hovered", false);
30985
+ _defineProperty(this, "_tooltipVisible", false);
30986
+ _defineProperty(this, "_tooltipTimer", null);
30987
+ _defineProperty(this, "_pressed", false);
30988
+ this._colors = colors;
30989
+ this.cursor = _univerjs_engine_render.CURSOR_TYPE.POINTER;
30990
+ this.disposeWithMe(this.onPointerEnter$.subscribeEvent((event) => {
30991
+ if (this._hovered || event.buttons) return;
30992
+ this._hovered = true;
30993
+ this._tooltipTimer = setTimeout(() => {
30994
+ this._tooltipTimer = null;
30995
+ this._tooltipVisible = true;
30996
+ this.makeDirty(true);
30997
+ }, 500);
30998
+ this.makeDirty(true);
30999
+ }));
31000
+ this.disposeWithMe(this.onPointerLeave$.subscribeEvent(() => this.resetHover()));
31001
+ this.disposeWithMe(this.onPointerDown$.subscribeEvent((event, state) => {
31002
+ state.stopPropagation();
31003
+ event.preventDefault();
31004
+ this._pressed = event.button === 0;
31005
+ }));
31006
+ this.disposeWithMe(this.onPointerUp$.subscribeEvent((event, state) => {
31007
+ state.stopPropagation();
31008
+ event.preventDefault();
31009
+ const activateButton = this._pressed && event.button === 0;
31010
+ this._pressed = false;
31011
+ this._hideTooltip();
31012
+ if (activateButton) activate();
31013
+ }));
31014
+ this.disposeWithMe(this.onClick$.subscribeEvent((_event, state) => state.stopPropagation()));
31015
+ this.disposeWithMe(this.onDblclick$.subscribeEvent((_event, state) => state.stopPropagation()));
31016
+ }
31017
+ update(collapsed, label, colors) {
31018
+ if (collapsed === this._collapsed && label === this._label && colors === this._colors) return;
31019
+ this._collapsed = collapsed;
31020
+ this._label = label;
31021
+ this._colors = colors;
31022
+ this.makeDirty(true);
31023
+ }
31024
+ resetHover() {
31025
+ this._hideTooltip();
31026
+ this._pressed = false;
31027
+ if (this._hovered) {
31028
+ this._hovered = false;
31029
+ this.makeDirty(true);
31030
+ }
31031
+ }
31032
+ _hideTooltip() {
31033
+ if (this._tooltipTimer !== null) {
31034
+ clearTimeout(this._tooltipTimer);
31035
+ this._tooltipTimer = null;
31036
+ }
31037
+ if (this._tooltipVisible) {
31038
+ this._tooltipVisible = false;
31039
+ this.makeDirty(true);
31040
+ }
31041
+ }
31042
+ _draw(ctx, bounds) {
31043
+ ctx.fillStyle = this._hovered ? this._colors.hover : this._colors.normal;
31044
+ ctx.beginPath();
31045
+ if (this._collapsed) {
31046
+ ctx.moveTo(9, 8);
31047
+ ctx.lineTo(16, 14);
31048
+ ctx.lineTo(9, 20);
31049
+ } else {
31050
+ ctx.moveTo(6, 11);
31051
+ ctx.lineTo(18, 11);
31052
+ ctx.lineTo(12, 18);
31053
+ }
31054
+ ctx.closePath();
31055
+ ctx.fill();
31056
+ if (!this._tooltipVisible) return;
31057
+ ctx.save();
31058
+ ctx.font = "12px sans-serif";
31059
+ const width = ctx.measureText(this._label).width + 20;
31060
+ const viewport = bounds === null || bounds === void 0 ? void 0 : bounds.viewBound;
31061
+ const centeredLeft = (this.width - width) / 2;
31062
+ const left = viewport ? Math.max(viewport.left - this.left, Math.min(centeredLeft, viewport.right - this.left - width)) : centeredLeft;
31063
+ const below = viewport != null && this.top - 36 < viewport.top;
31064
+ ctx.translate(left, below ? this.height + 8 : -36);
31065
+ _univerjs_engine_render.Rect.drawWith(ctx, {
31066
+ width,
31067
+ height: 28,
31068
+ radius: 6,
31069
+ fill: this._colors.tooltipBackground
31070
+ });
31071
+ ctx.fillStyle = this._colors.tooltipBackground;
31072
+ ctx.beginPath();
31073
+ const arrow = this.width / 2 - left;
31074
+ const arrowBase = below ? 0 : 28;
31075
+ ctx.moveTo(arrow - 4, arrowBase);
31076
+ ctx.lineTo(arrow, below ? -4 : 32);
31077
+ ctx.lineTo(arrow + 4, arrowBase);
31078
+ ctx.fill();
31079
+ ctx.fillStyle = this._colors.tooltipText;
31080
+ ctx.textAlign = "center";
31081
+ ctx.textBaseline = "middle";
31082
+ ctx.fillText(this._label, width / 2, 14);
31083
+ ctx.restore();
31084
+ }
31085
+ dispose() {
31086
+ this.resetHover();
31087
+ super.dispose();
31088
+ }
31089
+ };
31090
+
31091
+ //#endregion
31092
+ //#region src/services/doc-heading-collapse.service.ts
31093
+ let DocHeadingCollapseService = class DocHeadingCollapseService extends _univerjs_core.Disposable {
31094
+ constructor(_context, _skeletonManager, _eventManager, _selections, _commandService, _layoutService, themeService, localeService) {
31095
+ super();
31096
+ this._context = _context;
31097
+ this._skeletonManager = _skeletonManager;
31098
+ this._eventManager = _eventManager;
31099
+ this._selections = _selections;
31100
+ this._commandService = _commandService;
31101
+ this._layoutService = _layoutService;
31102
+ _defineProperty(this, "_buttons", /* @__PURE__ */ new Map());
31103
+ _defineProperty(this, "_colors", void 0);
31104
+ _defineProperty(this, "_expandLabel", "");
31105
+ _defineProperty(this, "_collapseLabel", "");
31106
+ this._colors = this._getColors(themeService);
31107
+ if ((0, _univerjs_core.isInternalEditorID)(_context.unitId)) return;
31108
+ this.disposeWithMe(themeService.currentTheme$.subscribe(() => {
31109
+ this._colors = this._getColors(themeService);
31110
+ this._update();
31111
+ }));
31112
+ this.disposeWithMe(localeService.currentLocale$.subscribe(() => {
31113
+ this._expandLabel = localeService.t("docs-ui.heading.expand");
31114
+ this._collapseLabel = localeService.t("docs-ui.heading.collapse");
31115
+ this._update();
31116
+ }));
31117
+ this.disposeWithMe(_context.scene.beforeRender$.subscribe(() => this._update()));
31118
+ this.disposeWithMe(this._skeletonManager.currentSkeleton$.subscribe(() => this._update()));
31119
+ this.disposeWithMe(this._skeletonManager.getSkeleton().dirty$.subscribe(() => this._update()));
31120
+ const resetHover = () => this._buttons.forEach((button) => button.resetHover());
31121
+ const viewport = _context.scene.getViewport("viewMain");
31122
+ if (viewport) {
31123
+ let scrollX = viewport.viewportScrollX;
31124
+ let scrollY = viewport.viewportScrollY;
31125
+ this.disposeWithMe(viewport.onScrollAfter$.subscribeEvent((event) => {
31126
+ if (event.viewportScrollX !== scrollX || event.viewportScrollY !== scrollY) {
31127
+ resetHover();
31128
+ scrollX = event.viewportScrollX;
31129
+ scrollY = event.viewportScrollY;
31130
+ }
31131
+ }));
31132
+ }
31133
+ this.disposeWithMe(_context.scene.onPointerCancel$.subscribeEvent(resetHover));
31134
+ this.disposeWithMe(_context.scene.onTransformChange$.subscribeEvent(({ value, preValue }) => {
31135
+ if (value.scaleX != null && value.scaleX !== preValue.scaleX || value.scaleY != null && value.scaleY !== preValue.scaleY) resetHover();
31136
+ }));
31137
+ this.disposeWithMe(_context.scene.onPointerLeave$.subscribeEvent(resetHover));
31138
+ this.disposeWithMe(this._selections.textSelection$.subscribe(({ unitId }) => {
31139
+ if (unitId === _context.unitId) this._normalizeSelection();
31140
+ }));
31141
+ }
31142
+ _getColors(themeService) {
31143
+ return {
31144
+ normal: themeService.getColorFromTheme("gray.900"),
31145
+ hover: themeService.getColorFromTheme("primary.600"),
31146
+ tooltipBackground: themeService.getColorFromTheme("gray.700"),
31147
+ tooltipText: themeService.getColorFromTheme("gray.0")
31148
+ };
31149
+ }
31150
+ _normalizeSelection() {
31151
+ const target = {
31152
+ unitId: this._context.unitId,
31153
+ subUnitId: this._context.unitId
31154
+ };
31155
+ const info = this._selections.getSelectionInfo(target);
31156
+ if (!info || info.segmentId) return;
31157
+ const viewModel = this._skeletonManager.getViewModel();
31158
+ const hiddenRect = info.rectRanges.find((range) => !range.segmentId && range.startOffset != null && viewModel.getCollapsedHeadingAtOffset(range.startOffset));
31159
+ if ((hiddenRect === null || hiddenRect === void 0 ? void 0 : hiddenRect.startOffset) != null) {
31160
+ const offset = viewModel.getCollapsedHeadingAtOffset(hiddenRect.startOffset).paragraphIndex;
31161
+ const textRanges = [{
31162
+ startOffset: offset,
31163
+ endOffset: offset,
31164
+ collapsed: true,
31165
+ isActive: true
31166
+ }];
31167
+ this._selections.replaceSelectionInfoWithoutRefresh({
31168
+ ...info,
31169
+ textRanges,
31170
+ rectRanges: []
31171
+ }, target);
31172
+ this._selections.replaceDocRanges(textRanges, target, false, { forceFocus: false });
31173
+ return;
31174
+ }
31175
+ let changed = false;
31176
+ const textRanges = info.textRanges.map((range) => {
31177
+ var _viewModel$getCollaps, _viewModel$getCollaps2;
31178
+ if (range.segmentId) return range;
31179
+ const startOffset = ((_viewModel$getCollaps = viewModel.getCollapsedHeadingAtOffset(range.startOffset)) === null || _viewModel$getCollaps === void 0 ? void 0 : _viewModel$getCollaps.paragraphIndex) ?? range.startOffset;
31180
+ const endOffset = ((_viewModel$getCollaps2 = viewModel.getCollapsedHeadingAtOffset(range.endOffset)) === null || _viewModel$getCollaps2 === void 0 ? void 0 : _viewModel$getCollaps2.paragraphIndex) ?? range.endOffset;
31181
+ if (startOffset === range.startOffset && endOffset === range.endOffset) return range;
31182
+ changed = true;
31183
+ return {
31184
+ ...range,
31185
+ startOffset,
31186
+ endOffset,
31187
+ collapsed: startOffset === endOffset,
31188
+ startNodePosition: void 0,
31189
+ endNodePosition: void 0
31190
+ };
31191
+ });
31192
+ if (changed) {
31193
+ this._selections.replaceSelectionInfoWithoutRefresh({
31194
+ ...info,
31195
+ textRanges
31196
+ }, target);
31197
+ this._selections.replaceDocRanges([...textRanges, ...info.rectRanges], target, false, { forceFocus: false });
31198
+ }
31199
+ }
31200
+ _update() {
31201
+ this._normalizeSelection();
31202
+ const active = /* @__PURE__ */ new Set();
31203
+ const viewModel = this._skeletonManager.getViewModel();
31204
+ if (this._context.unit.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) for (const heading of viewModel.getHeadingSections()) {
31205
+ if (heading.startOffset >= heading.endOffset || viewModel.getCollapsedHeadingAtOffset(heading.paragraphIndex)) continue;
31206
+ const bound = this._eventManager.findParagraphBoundByIndex(heading.paragraphIndex);
31207
+ if (!bound || bound.segmentId) continue;
31208
+ active.add(heading.paragraphId);
31209
+ let button = this._buttons.get(heading.paragraphId);
31210
+ if (!button) {
31211
+ button = new HeadingCollapseShape(`__DocHeadingCollapse__${heading.paragraphId}`, this._colors, () => {
31212
+ var _this$_context$unit$g;
31213
+ const paragraph = (_this$_context$unit$g = this._context.unit.getBody()) === null || _this$_context$unit$g === void 0 || (_this$_context$unit$g = _this$_context$unit$g.paragraphs) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.find((item) => item.paragraphId === heading.paragraphId);
31214
+ if (paragraph && this._commandService.syncExecuteCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
31215
+ unitId: this._context.unitId,
31216
+ paragraphId: heading.paragraphId,
31217
+ collapsed: paragraph.headingCollapsed !== true
31218
+ })) this._layoutService.focus(this._context.unitId);
31219
+ });
31220
+ this._buttons.set(heading.paragraphId, button);
31221
+ this._context.scene.addObject(button, 3);
31222
+ }
31223
+ const left = bound.firstLine.left - button.width;
31224
+ const top = (bound.firstLine.top + bound.firstLine.bottom - button.height) / 2;
31225
+ if (button.left !== left || button.top !== top) {
31226
+ button.resetHover();
31227
+ button.transformByState({
31228
+ left,
31229
+ top
31230
+ });
31231
+ }
31232
+ button.update(heading.collapsed, heading.collapsed ? this._expandLabel : this._collapseLabel, this._colors);
31233
+ }
31234
+ for (const [id, button] of this._buttons) if (!active.has(id)) {
31235
+ button.dispose();
31236
+ this._buttons.delete(id);
31237
+ }
31238
+ }
31239
+ dispose() {
31240
+ super.dispose();
31241
+ this._buttons.forEach((button) => button.dispose());
31242
+ this._buttons.clear();
31243
+ }
31244
+ };
31245
+ DocHeadingCollapseService = __decorate([
31246
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
31247
+ __decorateParam(2, (0, _univerjs_core.Inject)(DocEventManagerService)),
31248
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
31249
+ __decorateParam(4, _univerjs_core.ICommandService),
31250
+ __decorateParam(5, _univerjs_ui.ILayoutService),
31251
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
31252
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
31253
+ ], DocHeadingCollapseService);
31254
+
30625
31255
  //#endregion
30626
31256
  //#region src/shortcuts/core-editing.shortcut.ts
30627
31257
  const BreakLineShortcut = {
@@ -31046,6 +31676,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
31046
31676
  [DocFloatMenuService],
31047
31677
  [DocPasteOptionsRenderController],
31048
31678
  [DocParagraphMenuService],
31679
+ [DocHeadingCollapseService],
31049
31680
  [DocHeaderFooterController],
31050
31681
  [DocHeaderFooterRibbonController],
31051
31682
  [DocResizeRenderController],
@@ -31250,6 +31881,35 @@ const mobileButtonClassName = `
31250
31881
  `;
31251
31882
  const activeButtonClassName = "univer-bg-primary-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-400";
31252
31883
  function MobileRichTextToolbar({ editorId, className }) {
31884
+ function resolveToolbarState(editor, defaultTextColor) {
31885
+ var _style$ul, _style$st, _style$cl;
31886
+ const body = editor === null || editor === void 0 ? void 0 : editor.getDocumentData().body;
31887
+ const ranges = (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges()) ?? [];
31888
+ const range = ranges.find((item) => item.isActive) ?? ranges[0];
31889
+ if (!body || !range) return {
31890
+ bold: false,
31891
+ italic: false,
31892
+ underline: false,
31893
+ strike: false,
31894
+ color: defaultTextColor,
31895
+ bulletList: false,
31896
+ orderList: false
31897
+ };
31898
+ const style = getStyleInTextRange(body, range, {});
31899
+ const listTypes = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges([range], body.paragraphs ?? [], body.dataStream).map((paragraph) => {
31900
+ var _paragraph$bullet;
31901
+ return (_paragraph$bullet = paragraph.bullet) === null || _paragraph$bullet === void 0 ? void 0 : _paragraph$bullet.listType;
31902
+ }).filter((listType) => typeof listType === "string");
31903
+ return {
31904
+ bold: style.bl === _univerjs_core.BooleanNumber.TRUE,
31905
+ italic: style.it === _univerjs_core.BooleanNumber.TRUE,
31906
+ underline: ((_style$ul = style.ul) === null || _style$ul === void 0 ? void 0 : _style$ul.s) === _univerjs_core.BooleanNumber.TRUE,
31907
+ strike: ((_style$st = style.st) === null || _style$st === void 0 ? void 0 : _style$st.s) === _univerjs_core.BooleanNumber.TRUE,
31908
+ color: ((_style$cl = style.cl) === null || _style$cl === void 0 ? void 0 : _style$cl.rgb) ?? defaultTextColor,
31909
+ bulletList: Boolean(listTypes.length && listTypes.every((listType) => listType.startsWith(_univerjs_core.PresetListType.BULLET_LIST))),
31910
+ orderList: Boolean(listTypes.length && listTypes.every((listType) => listType.startsWith(_univerjs_core.PresetListType.ORDER_LIST)))
31911
+ };
31912
+ }
31253
31913
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
31254
31914
  const editorService = (0, _univerjs_ui.useDependency)(IEditorService);
31255
31915
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
@@ -31263,12 +31923,11 @@ function MobileRichTextToolbar({ editorId, className }) {
31263
31923
  return () => cancelAnimationFrame(frame);
31264
31924
  }, [editorId, editorService]);
31265
31925
  (0, react.useEffect)(() => {
31266
- if (!editor) return void 0;
31926
+ if (!editor) return;
31267
31927
  const subscription = (0, rxjs.merge)(editor.input$, editor.selectionChange$).subscribe(() => setRevision((value) => value + 1));
31268
31928
  return () => subscription.unsubscribe();
31269
31929
  }, [editor]);
31270
- const defaultTextColor = themeService.getColorFromTheme("gray.900");
31271
- const state = resolveToolbarState(editor, defaultTextColor);
31930
+ const state = resolveToolbarState(editor, themeService.getColorFromTheme("gray.900"));
31272
31931
  const colors = COLOR_TOKENS.map((token) => themeService.getColorFromTheme(token));
31273
31932
  async function execute(commandId, params) {
31274
31933
  const activeEditor = editorService.getEditor(editorId);
@@ -31367,18 +32026,23 @@ function MobileRichTextToolbar({ editorId, className }) {
31367
32026
  style: { backgroundColor: color },
31368
32027
  onClick: () => execute(SetInlineFormatTextColorCommand.id, { value: color })
31369
32028
  }, color)),
31370
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
31371
- "aria-label": localeService.t("docs-ui.toolbar.textColor.main"),
31372
- className: (0, _univerjs_design.clsx)(_univerjs_design.resetButtonClassName, "univer-relative univer-flex univer-size-7 univer-items-center univer-justify-center univer-justify-self-center univer-overflow-hidden univer-rounded-md univer-border-2 univer-border-solid univer-border-transparent active:univer-scale-95"),
31373
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ColorWheelMultiIcon, { className: "univer-size-6" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
32029
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileDropdown, {
32030
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
32031
+ className: "univer-px-4 univer-pb-2",
32032
+ onPointerDown: (event) => event.stopPropagation(),
32033
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileColorPicker, {
32034
+ value: state.color,
32035
+ onChange: (color) => execute(SetInlineFormatTextColorCommand.id, { value: color })
32036
+ })
32037
+ }),
32038
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
32039
+ type: "button",
32040
+ variant: "text",
32041
+ size: "icon",
31374
32042
  "aria-label": localeService.t("docs-ui.toolbar.textColor.main"),
31375
- className: "univer-absolute univer-inset-0 univer-size-full univer-cursor-pointer univer-opacity-0",
31376
- type: "color",
31377
- defaultValue: defaultTextColor,
31378
- onChange: (event) => {
31379
- execute(SetInlineFormatTextColorCommand.id, { value: event.target.value });
31380
- }
31381
- })]
32043
+ className: "univer-size-7 univer-justify-self-center",
32044
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ColorWheelMultiIcon, { className: "!univer-size-6" })
32045
+ })
31382
32046
  })
31383
32047
  ]
31384
32048
  })
@@ -31397,35 +32061,6 @@ function FormatButton(props) {
31397
32061
  })
31398
32062
  });
31399
32063
  }
31400
- function resolveToolbarState(editor, defaultTextColor) {
31401
- var _style$ul, _style$st, _style$cl;
31402
- const body = editor === null || editor === void 0 ? void 0 : editor.getDocumentData().body;
31403
- const ranges = (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges()) ?? [];
31404
- const range = ranges.find((item) => item.isActive) ?? ranges[0];
31405
- if (!body || !range) return {
31406
- bold: false,
31407
- italic: false,
31408
- underline: false,
31409
- strike: false,
31410
- color: defaultTextColor,
31411
- bulletList: false,
31412
- orderList: false
31413
- };
31414
- const style = getStyleInTextRange(body, range, {});
31415
- const listTypes = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges([range], body.paragraphs ?? [], body.dataStream).map((paragraph) => {
31416
- var _paragraph$bullet;
31417
- return (_paragraph$bullet = paragraph.bullet) === null || _paragraph$bullet === void 0 ? void 0 : _paragraph$bullet.listType;
31418
- }).filter((listType) => typeof listType === "string");
31419
- return {
31420
- bold: style.bl === _univerjs_core.BooleanNumber.TRUE,
31421
- italic: style.it === _univerjs_core.BooleanNumber.TRUE,
31422
- underline: ((_style$ul = style.ul) === null || _style$ul === void 0 ? void 0 : _style$ul.s) === _univerjs_core.BooleanNumber.TRUE,
31423
- strike: ((_style$st = style.st) === null || _style$st === void 0 ? void 0 : _style$st.s) === _univerjs_core.BooleanNumber.TRUE,
31424
- color: ((_style$cl = style.cl) === null || _style$cl === void 0 ? void 0 : _style$cl.rgb) ?? defaultTextColor,
31425
- bulletList: Boolean(listTypes.length && listTypes.every((listType) => listType.startsWith(_univerjs_core.PresetListType.BULLET_LIST))),
31426
- orderList: Boolean(listTypes.length && listTypes.every((listType) => listType.startsWith(_univerjs_core.PresetListType.ORDER_LIST)))
31427
- };
31428
- }
31429
32064
 
31430
32065
  //#endregion
31431
32066
  //#region src/views/rich-text-editor/hooks/editor-undo-redo-keyboard.ts
@@ -32194,26 +32829,26 @@ exports.DeleteCurrentParagraphCommand = DeleteCurrentParagraphCommand;
32194
32829
  exports.DeleteCustomBlockCommand = DeleteCustomBlockCommand;
32195
32830
  exports.DeleteLeftCommand = DeleteLeftCommand;
32196
32831
  exports.DeleteRightCommand = DeleteRightCommand;
32197
- Object.defineProperty(exports, 'DocAutoFormatService', {
32832
+ Object.defineProperty(exports, "DocAutoFormatService", {
32198
32833
  enumerable: true,
32199
32834
  get: function () {
32200
32835
  return DocAutoFormatService;
32201
32836
  }
32202
32837
  });
32203
- Object.defineProperty(exports, 'DocBackScrollRenderController', {
32838
+ Object.defineProperty(exports, "DocBackScrollRenderController", {
32204
32839
  enumerable: true,
32205
32840
  get: function () {
32206
32841
  return DocBackScrollRenderController;
32207
32842
  }
32208
32843
  });
32209
- Object.defineProperty(exports, 'DocCanvasPopManagerService', {
32844
+ Object.defineProperty(exports, "DocCanvasPopManagerService", {
32210
32845
  enumerable: true,
32211
32846
  get: function () {
32212
32847
  return DocCanvasPopManagerService;
32213
32848
  }
32214
32849
  });
32215
32850
  exports.DocClipboardPasteAdapterService = DocClipboardPasteAdapterService;
32216
- Object.defineProperty(exports, 'DocContextualRibbonService', {
32851
+ Object.defineProperty(exports, "DocContextualRibbonService", {
32217
32852
  enumerable: true,
32218
32853
  get: function () {
32219
32854
  return DocContextualRibbonService;
@@ -32222,13 +32857,13 @@ Object.defineProperty(exports, 'DocContextualRibbonService', {
32222
32857
  exports.DocCopyCommand = DocCopyCommand;
32223
32858
  exports.DocCreateTableOperation = DocCreateTableOperation;
32224
32859
  exports.DocCutCommand = DocCutCommand;
32225
- Object.defineProperty(exports, 'DocEventManagerService', {
32860
+ Object.defineProperty(exports, "DocEventManagerService", {
32226
32861
  enumerable: true,
32227
32862
  get: function () {
32228
32863
  return DocEventManagerService;
32229
32864
  }
32230
32865
  });
32231
- Object.defineProperty(exports, 'DocFloatMenuService', {
32866
+ Object.defineProperty(exports, "DocFloatMenuService", {
32232
32867
  enumerable: true,
32233
32868
  get: function () {
32234
32869
  return DocFloatMenuService;
@@ -32237,25 +32872,25 @@ Object.defineProperty(exports, 'DocFloatMenuService', {
32237
32872
  exports.DocHtmlExportService = DocHtmlExportService;
32238
32873
  exports.DocIMEInputManagerService = DocIMEInputManagerService;
32239
32874
  exports.DocLayoutInteractionService = DocLayoutInteractionService;
32240
- Object.defineProperty(exports, 'DocMobileElementMenuService', {
32875
+ Object.defineProperty(exports, "DocMobileElementMenuService", {
32241
32876
  enumerable: true,
32242
32877
  get: function () {
32243
32878
  return DocMobileElementMenuService;
32244
32879
  }
32245
32880
  });
32246
- Object.defineProperty(exports, 'DocPageLayoutService', {
32881
+ Object.defineProperty(exports, "DocPageLayoutService", {
32247
32882
  enumerable: true,
32248
32883
  get: function () {
32249
32884
  return DocPageLayoutService;
32250
32885
  }
32251
32886
  });
32252
- Object.defineProperty(exports, 'DocParagraphMenuService', {
32887
+ Object.defineProperty(exports, "DocParagraphMenuService", {
32253
32888
  enumerable: true,
32254
32889
  get: function () {
32255
32890
  return DocParagraphMenuService;
32256
32891
  }
32257
32892
  });
32258
- Object.defineProperty(exports, 'DocParagraphPlaceholderRenderController', {
32893
+ Object.defineProperty(exports, "DocParagraphPlaceholderRenderController", {
32259
32894
  enumerable: true,
32260
32895
  get: function () {
32261
32896
  return DocParagraphPlaceholderRenderController;
@@ -32263,14 +32898,14 @@ Object.defineProperty(exports, 'DocParagraphPlaceholderRenderController', {
32263
32898
  });
32264
32899
  exports.DocPasteCommand = DocPasteCommand;
32265
32900
  exports.DocPrintInterceptorService = DocPrintInterceptorService;
32266
- Object.defineProperty(exports, 'DocRenderController', {
32901
+ Object.defineProperty(exports, "DocRenderController", {
32267
32902
  enumerable: true,
32268
32903
  get: function () {
32269
32904
  return DocRenderController;
32270
32905
  }
32271
32906
  });
32272
32907
  exports.DocSelectAllCommand = DocSelectAllCommand;
32273
- Object.defineProperty(exports, 'DocSelectionRenderService', {
32908
+ Object.defineProperty(exports, "DocSelectionRenderService", {
32274
32909
  enumerable: true,
32275
32910
  get: function () {
32276
32911
  return DocSelectionRenderService;
@@ -32286,19 +32921,19 @@ exports.DocTableInsertRowAboveCommand = DocTableInsertRowAboveCommand;
32286
32921
  exports.DocTableInsertRowBellowCommand = DocTableInsertRowBellowCommand;
32287
32922
  exports.DocTableInsertRowCommand = DocTableInsertRowCommand;
32288
32923
  exports.DocTableTabCommand = DocTableTabCommand;
32289
- Object.defineProperty(exports, 'DocUIController', {
32924
+ Object.defineProperty(exports, "DocUIController", {
32290
32925
  enumerable: true,
32291
32926
  get: function () {
32292
32927
  return DocUIController;
32293
32928
  }
32294
32929
  });
32295
- Object.defineProperty(exports, 'DocViewScaleService', {
32930
+ Object.defineProperty(exports, "DocViewScaleService", {
32296
32931
  enumerable: true,
32297
32932
  get: function () {
32298
32933
  return DocViewScaleService;
32299
32934
  }
32300
32935
  });
32301
- Object.defineProperty(exports, 'DocsRenderService', {
32936
+ Object.defineProperty(exports, "DocsRenderService", {
32302
32937
  enumerable: true,
32303
32938
  get: function () {
32304
32939
  return DocsRenderService;
@@ -32307,7 +32942,7 @@ Object.defineProperty(exports, 'DocsRenderService', {
32307
32942
  exports.DocsUIMenuSchema = menuSchema;
32308
32943
  exports.EMPTY_PARAGRAPH_MENU_ID = EMPTY_PARAGRAPH_MENU_ID;
32309
32944
  exports.Editor = Editor;
32310
- Object.defineProperty(exports, 'EditorService', {
32945
+ Object.defineProperty(exports, "EditorService", {
32311
32946
  enumerable: true,
32312
32947
  get: function () {
32313
32948
  return EditorService;
@@ -32345,6 +32980,7 @@ exports.NodePositionConvertToRectRange = NodePositionConvertToRectRange;
32345
32980
  exports.OrderListCommand = OrderListCommand;
32346
32981
  exports.OrderListTypePicker = OrderListTypePicker;
32347
32982
  exports.ParagraphMenuInsertBelowSubmenuItemFactory = ParagraphMenuInsertBelowSubmenuItemFactory;
32983
+ exports.ParagraphSettingMenuFactory = ParagraphSettingMenuFactory;
32348
32984
  exports.PastePluginLark = LarkPastePlugin;
32349
32985
  exports.PastePluginUniver = UniverPastePlugin;
32350
32986
  exports.PastePluginWord = WordPastePlugin;
@@ -32380,13 +33016,13 @@ exports.TextColorSelectorMenuItemFactory = TextColorSelectorMenuItemFactory;
32380
33016
  exports.TextRange = TextRange;
32381
33017
  exports.ToggleCheckListCommand = ToggleCheckListCommand;
32382
33018
  exports.UnderlineMenuItemFactory = UnderlineMenuItemFactory;
32383
- Object.defineProperty(exports, 'UniverDocsMobileUIPlugin', {
33019
+ Object.defineProperty(exports, "UniverDocsMobileUIPlugin", {
32384
33020
  enumerable: true,
32385
33021
  get: function () {
32386
33022
  return UniverDocsMobileUIPlugin;
32387
33023
  }
32388
33024
  });
32389
- Object.defineProperty(exports, 'UniverDocsUIPlugin', {
33025
+ Object.defineProperty(exports, "UniverDocsUIPlugin", {
32390
33026
  enumerable: true,
32391
33027
  get: function () {
32392
33028
  return UniverDocsUIPlugin;
@@ -32414,7 +33050,12 @@ exports.drawDocCustomRangeChrome = drawDocCustomRangeChrome;
32414
33050
  exports.executeEditorUndoRedoCommand = executeEditorUndoRedoCommand;
32415
33051
  exports.findDocRangeNodePositions = findDocRangeNodePositions;
32416
33052
  exports.genTableSource = genTableSource;
32417
- exports.generateParagraphs = _univerjs_docs.generateParagraphs;
33053
+ Object.defineProperty(exports, "generateParagraphs", {
33054
+ enumerable: true,
33055
+ get: function () {
33056
+ return _univerjs_docs.generateParagraphs;
33057
+ }
33058
+ });
32418
33059
  exports.getAnchorBounding = getAnchorBounding;
32419
33060
  exports.getCanvasOffsetByEngine = getCanvasOffsetByEngine;
32420
33061
  exports.getCommandSkeleton = getCommandSkeleton;