@univerjs/docs-ui 1.0.0-alpha.0 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -315,20 +315,20 @@ let DocAutoFormatService = class DocAutoFormatService extends _univerjs_core.Dis
315
315
  });
316
316
  }
317
317
  onAutoFormat(id, params) {
318
- var _this$_matches$get, _docRanges$find;
318
+ var _this$_matches$get, _docRanges$find, _selection$segmentId;
319
319
  const autoFormats = (_this$_matches$get = this._matches.get(id)) !== null && _this$_matches$get !== void 0 ? _this$_matches$get : [];
320
320
  const unit = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
321
321
  const docRanges = this._textSelectionManagerService.getDocRanges();
322
322
  const selection = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
323
- if (unit && selection) {
324
- var _doc$getBody$paragrap, _doc$getBody, _doc$getBody$dataStre, _doc$getBody2, _doc$getBody$customRa, _doc$getBody3, _matched$getMutations;
325
- const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId);
323
+ const documentDataModel = unit === null || unit === void 0 ? void 0 : unit.getSelfOrHeaderFooterModel((_selection$segmentId = selection === null || selection === void 0 ? void 0 : selection.segmentId) !== null && _selection$segmentId !== void 0 ? _selection$segmentId : "");
324
+ if (unit && selection && documentDataModel) {
325
+ var _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3, _documentDataModel$ge4, _documentDataModel$ge5, _documentDataModel$ge6, _matched$getMutations;
326
326
  const context = {
327
- unit: doc,
327
+ unit: documentDataModel,
328
328
  selection,
329
329
  isBody: !selection.segmentId,
330
- paragraphs: _univerjs_core.BuildTextUtils.range.getParagraphsInRange(selection, (_doc$getBody$paragrap = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) !== null && _doc$getBody$paragrap !== void 0 ? _doc$getBody$paragrap : [], (_doc$getBody$dataStre = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : ""),
331
- customRanges: _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_doc$getBody$customRa = (_doc$getBody3 = doc.getBody()) === null || _doc$getBody3 === void 0 ? void 0 : _doc$getBody3.customRanges) !== null && _doc$getBody$customRa !== void 0 ? _doc$getBody$customRa : []),
330
+ paragraphs: _univerjs_core.BuildTextUtils.range.getParagraphsInRange(selection, (_documentDataModel$ge = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.paragraphs) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : [], (_documentDataModel$ge3 = (_documentDataModel$ge4 = documentDataModel.getBody()) === null || _documentDataModel$ge4 === void 0 ? void 0 : _documentDataModel$ge4.dataStream) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : ""),
331
+ customRanges: _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_documentDataModel$ge5 = (_documentDataModel$ge6 = documentDataModel.getBody()) === null || _documentDataModel$ge6 === void 0 ? void 0 : _documentDataModel$ge6.customRanges) !== null && _documentDataModel$ge5 !== void 0 ? _documentDataModel$ge5 : []),
332
332
  commandId: id,
333
333
  commandParams: params
334
334
  };
@@ -460,7 +460,7 @@ const BreakLineCommand = {
460
460
  id: "doc.command.break-line",
461
461
  type: _univerjs_core.CommandType.COMMAND,
462
462
  handler: (accessor, params) => {
463
- var _params$textRange, _originBody$paragraph, _prevParagraph$bullet, _prevParagraph$paragr;
463
+ var _params$textRange, _docDataModel$getSelf, _originBody$paragraph, _prevParagraph$bullet, _prevParagraph$paragr;
464
464
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
465
465
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
466
466
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -479,7 +479,7 @@ const BreakLineCommand = {
479
479
  const { horizontalLine } = params !== null && params !== void 0 ? params : {};
480
480
  const { segmentId } = activeTextRange;
481
481
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
482
- const originBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId !== null && segmentId !== void 0 ? segmentId : "").getBody();
482
+ const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId !== null && segmentId !== void 0 ? segmentId : "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
483
483
  if (docDataModel == null || originBody == null) return false;
484
484
  const unitId = docDataModel.getUnitId();
485
485
  const { startOffset, endOffset } = activeTextRange;
@@ -1099,7 +1099,7 @@ const InnerPasteCommand = {
1099
1099
  id: "doc.command.inner-paste",
1100
1100
  type: _univerjs_core.CommandType.COMMAND,
1101
1101
  handler: async (accessor, params) => {
1102
- var _body$tables, _body$customBlocks;
1102
+ var _docDataModel$getSelf, _body$tables, _body$customBlocks;
1103
1103
  const { segmentId, textRanges, doc } = params;
1104
1104
  const commandService = accessor.get(_univerjs_core.ICommandService);
1105
1105
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
@@ -1108,8 +1108,8 @@ const InnerPasteCommand = {
1108
1108
  const rectRanges = docSelectionManagerService.getRectRanges();
1109
1109
  const { body, tableSource, drawings } = doc;
1110
1110
  if (!Array.isArray(selections) || selections.length === 0 || body == null) return false;
1111
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
1112
- const originBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1111
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1112
+ const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
1113
1113
  if (docDataModel == null || originBody == null) return false;
1114
1114
  const unitId = docDataModel.getUnitId();
1115
1115
  const doMutation = {
@@ -1210,8 +1210,8 @@ function adjustSelectionByTable(selection, tables) {
1210
1210
  };
1211
1211
  }
1212
1212
  function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
1213
- var _docDataModel$getDraw, _docDataModel$getDraw2;
1214
- const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1213
+ var _docDataModel$getSelf2, _docDataModel$getDraw, _docDataModel$getDraw2;
1214
+ const originBody = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
1215
1215
  const textX = new _univerjs_core.TextX();
1216
1216
  const jsonX = _univerjs_core.JSONX.getInstance();
1217
1217
  const rawActions = [];
@@ -1255,8 +1255,9 @@ function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
1255
1255
  }, null);
1256
1256
  }
1257
1257
  function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId) {
1258
+ var _docDataModel$getSelf3;
1258
1259
  const rawActions = [];
1259
- if (docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody() == null) return rawActions;
1260
+ if (((_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody()) == null) return rawActions;
1260
1261
  const textX = new _univerjs_core.TextX();
1261
1262
  const jsonX = _univerjs_core.JSONX.getInstance();
1262
1263
  const memoryCursor = new _univerjs_core.MemoryCursor();
@@ -1351,16 +1352,14 @@ const CutContentCommand = {
1351
1352
  id: "doc.command.inner-cut",
1352
1353
  type: _univerjs_core.CommandType.COMMAND,
1353
1354
  handler: (accessor, params) => {
1354
- var _univerInstanceServic;
1355
1355
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1356
1356
  const commandService = accessor.get(_univerjs_core.ICommandService);
1357
1357
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1358
1358
  const { segmentId, textRanges, selections = docSelectionManagerService.getTextRanges(), rectRanges = docSelectionManagerService.getRectRanges() } = params;
1359
1359
  if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0)) return false;
1360
- const unitId = (_univerInstanceServic = univerInstanceService.getCurrentUniverDocInstance()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
1361
- if (!unitId) return false;
1362
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
1360
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1363
1361
  if (docDataModel == null) return false;
1362
+ const unitId = docDataModel.getUnitId();
1364
1363
  const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
1365
1364
  if (docSkeletonManagerService == null) return false;
1366
1365
  const viewModel = docSkeletonManagerService.getViewModel();
@@ -1399,10 +1398,10 @@ const DeleteCustomBlockCommand = {
1399
1398
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1400
1399
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1401
1400
  const commandService = accessor.get(_univerjs_core.ICommandService);
1401
+ const { direction, range, unitId, drawingId } = params;
1402
1402
  const activeRange = docSelectionManagerService.getActiveTextRange();
1403
- const documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
1403
+ const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
1404
1404
  if (activeRange == null || documentDataModel == null) return false;
1405
- const { direction, range, unitId, drawingId } = params;
1406
1405
  const { startOffset, segmentId, style } = activeRange;
1407
1406
  const cursor = direction === _univerjs_core.DeleteDirection.LEFT ? startOffset - 1 : startOffset;
1408
1407
  const textRanges = [{
@@ -1449,6 +1448,7 @@ const MergeTwoParagraphCommand = {
1449
1448
  id: "doc.command.merge-two-paragraph",
1450
1449
  type: _univerjs_core.CommandType.COMMAND,
1451
1450
  handler: async (accessor, params) => {
1451
+ var _docDataModel$getSelf;
1452
1452
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1453
1453
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1454
1454
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -1458,7 +1458,7 @@ const MergeTwoParagraphCommand = {
1458
1458
  if (activeRange == null || ranges == null) return false;
1459
1459
  const { segmentId, style } = activeRange;
1460
1460
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1461
- const originBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1461
+ const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
1462
1462
  if (docDataModel == null || originBody == null) return false;
1463
1463
  const dataStream = originBody.dataStream;
1464
1464
  const actualRange = activeRange;
@@ -1529,7 +1529,7 @@ const RemoveHorizontalLineCommand = {
1529
1529
  id: "doc.command.remove-horizontal-line",
1530
1530
  type: _univerjs_core.CommandType.COMMAND,
1531
1531
  handler: async (accessor) => {
1532
- var _originBody$paragraph;
1532
+ var _docDataModel$getSelf2, _originBody$paragraph;
1533
1533
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1534
1534
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1535
1535
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -1538,7 +1538,7 @@ const RemoveHorizontalLineCommand = {
1538
1538
  if (activeRange == null || ranges == null) return false;
1539
1539
  const { segmentId, style } = activeRange;
1540
1540
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1541
- const originBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1541
+ const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
1542
1542
  if (docDataModel == null || originBody == null) return false;
1543
1543
  const actualRange = activeRange;
1544
1544
  const unitId = docDataModel.getUnitId();
@@ -1628,11 +1628,12 @@ const DeleteLeftCommand = {
1628
1628
  id: "doc.command.delete-left",
1629
1629
  type: _univerjs_core.CommandType.COMMAND,
1630
1630
  handler: async (accessor) => {
1631
+ var _docDataModel$getSelf3;
1631
1632
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1632
1633
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1633
1634
  const commandService = accessor.get(_univerjs_core.ICommandService);
1634
1635
  let result = true;
1635
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
1636
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1636
1637
  if (docDataModel == null) return false;
1637
1638
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
1638
1639
  const activeRange = docSelectionManagerService.getActiveTextRange();
@@ -1656,7 +1657,7 @@ const DeleteLeftCommand = {
1656
1657
  const autoFormatResult = await executeDeleteAutoFormat(accessor, DeleteLeftCommand.id);
1657
1658
  if (autoFormatResult != null) return autoFormatResult;
1658
1659
  const { segmentId, style, segmentPage } = activeRange;
1659
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1660
+ const body = (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
1660
1661
  if (body == null) return false;
1661
1662
  const actualRange = activeRange;
1662
1663
  const { startOffset, collapsed } = actualRange;
@@ -1782,8 +1783,9 @@ const DeleteRightCommand = {
1782
1783
  id: "doc.command.delete-right",
1783
1784
  type: _univerjs_core.CommandType.COMMAND,
1784
1785
  handler: async (accessor) => {
1786
+ var _docDataModel$getSelf4;
1785
1787
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1786
- const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
1788
+ const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1787
1789
  if (!docDataModel) return false;
1788
1790
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
1789
1791
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -1807,7 +1809,7 @@ const DeleteRightCommand = {
1807
1809
  const autoFormatResult = await executeDeleteAutoFormat(accessor, DeleteRightCommand.id);
1808
1810
  if (autoFormatResult != null) return autoFormatResult;
1809
1811
  const { segmentId, style, segmentPage } = activeRange;
1810
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1812
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf4 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf4 === void 0 ? void 0 : _docDataModel$getSelf4.getBody();
1811
1813
  if (!docDataModel || !body) return false;
1812
1814
  const actualRange = activeRange;
1813
1815
  const { startOffset, endOffset, collapsed } = actualRange;
@@ -1930,6 +1932,9 @@ function resetEmptyCenteredParagraphAlignment(commandService, docDataModel, segm
1930
1932
  }
1931
1933
  const DeleteCurrentParagraphCommand = {
1932
1934
  id: "doc.command.delete-current-paragraph",
1935
+ name: "doc.command.delete-current-paragraph",
1936
+ multi: true,
1937
+ priority: 0,
1933
1938
  type: _univerjs_core.CommandType.COMMAND,
1934
1939
  handler: async (accessor) => {
1935
1940
  var _docDataModel$getBody2, _docDataModel$getBody3;
@@ -3595,14 +3600,36 @@ function hasVisibleHtml(html) {
3595
3600
  return /<(?:img|br)\b/i.test(html) || html.replace(/<[^>]+>/g, "").replace(/&nbsp;/gi, " ").trim().length > 0;
3596
3601
  }
3597
3602
  var UDMToHtmlService = class {
3603
+ constructor(_docHtmlExportService) {
3604
+ this._docHtmlExportService = _docHtmlExportService;
3605
+ }
3598
3606
  convert(docList) {
3599
3607
  if (docList.length === 0) throw new Error("The bodyList length at least to be 1");
3600
3608
  let html = "";
3601
- for (const doc of _univerjs_core.Tools.deepClone(docList)) html += convertBodyToHtml(doc);
3609
+ for (const doc of _univerjs_core.Tools.deepClone(docList)) {
3610
+ var _this$_docHtmlExportS, _this$_docHtmlExportS2;
3611
+ html += convertBodyToHtml((_this$_docHtmlExportS = (_this$_docHtmlExportS2 = this._docHtmlExportService) === null || _this$_docHtmlExportS2 === void 0 ? void 0 : _this$_docHtmlExportS2.transformDocumentForHtmlExport(doc)) !== null && _this$_docHtmlExportS !== void 0 ? _this$_docHtmlExportS : doc);
3612
+ }
3602
3613
  return html;
3603
3614
  }
3604
3615
  };
3605
3616
 
3617
+ //#endregion
3618
+ //#region src/services/clipboard/udm-to-html/doc-html-export.service.ts
3619
+ var DocHtmlExportService = class extends _univerjs_core.Disposable {
3620
+ constructor(..._args) {
3621
+ super(..._args);
3622
+ _defineProperty(this, "_transformers", []);
3623
+ }
3624
+ registerTransformer(transformer) {
3625
+ this._transformers.push(transformer);
3626
+ return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._transformers, transformer)));
3627
+ }
3628
+ transformDocumentForHtmlExport(documentData) {
3629
+ return this._transformers.reduce((doc, transformer) => transformer(doc), documentData);
3630
+ }
3631
+ };
3632
+
3606
3633
  //#endregion
3607
3634
  //#region src/services/clipboard/clipboard.service.ts
3608
3635
  HtmlToUDMService.use(LarkPastePlugin);
@@ -3640,7 +3667,7 @@ function getTableCellContentClipboardBodySlice(body, start, end) {
3640
3667
  }
3641
3668
  const IDocClipboardService = (0, _univerjs_core.createIdentifier)("doc.clipboard-service");
3642
3669
  let DocClipboardService = class DocClipboardService extends _univerjs_core.Disposable {
3643
- constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, _docSelectionManagerService) {
3670
+ constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, docHtmlExportService, _docSelectionManagerService) {
3644
3671
  super();
3645
3672
  this._univerInstanceService = _univerInstanceService;
3646
3673
  this._logService = _logService;
@@ -3649,7 +3676,8 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3649
3676
  this._docSelectionManagerService = _docSelectionManagerService;
3650
3677
  _defineProperty(this, "_clipboardHooks", []);
3651
3678
  _defineProperty(this, "_htmlToUDM", new HtmlToUDMService());
3652
- _defineProperty(this, "_umdToHtml", new UDMToHtmlService());
3679
+ _defineProperty(this, "_umdToHtml", void 0);
3680
+ this._umdToHtml = new UDMToHtmlService(docHtmlExportService);
3653
3681
  }
3654
3682
  async copy(sliceType = _univerjs_core.SliceBodyType.copy, ranges) {
3655
3683
  var _this$_getDocumentBod;
@@ -3801,7 +3829,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3801
3829
  }
3802
3830
  _getDocumentBodyInRanges(sliceType, ranges) {
3803
3831
  var _docDataModel$getSelf;
3804
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
3832
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
3805
3833
  const allRanges = ranges !== null && ranges !== void 0 ? ranges : this._docSelectionManagerService.getDocRanges();
3806
3834
  const results = [];
3807
3835
  let needCache = true;
@@ -3811,6 +3839,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3811
3839
  const snapshot = docDataModel.getSnapshot();
3812
3840
  if (body == null) return;
3813
3841
  for (const range of allRanges) {
3842
+ var _docDataModel$getSelf2;
3814
3843
  const { startOffset, endOffset, collapsed, rangeType } = range;
3815
3844
  if (collapsed || startOffset == null || endOffset == null) continue;
3816
3845
  if (rangeType === _univerjs_core.DOC_RANGE_TYPE.RECT) {
@@ -3824,7 +3853,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3824
3853
  endOffset,
3825
3854
  collapsed
3826
3855
  };
3827
- const docBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
3856
+ const docBody = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
3828
3857
  if (docBody == null) continue;
3829
3858
  results.push(docBody);
3830
3859
  }
@@ -4005,7 +4034,8 @@ DocClipboardService = __decorate([
4005
4034
  __decorateParam(1, _univerjs_core.ILogService),
4006
4035
  __decorateParam(2, _univerjs_core.ICommandService),
4007
4036
  __decorateParam(3, _univerjs_ui.IClipboardInterfaceService),
4008
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
4037
+ __decorateParam(4, (0, _univerjs_core.Inject)(DocHtmlExportService)),
4038
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
4009
4039
  ], DocClipboardService);
4010
4040
  function dataUrlToFile(dataUrl, fallbackName) {
4011
4041
  const match = /^data:([^;,]+)(;base64)?,(.*)$/i.exec(dataUrl);
@@ -4097,13 +4127,21 @@ const MoveDocBlockCommand = {
4097
4127
  if (!params) return false;
4098
4128
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4099
4129
  const commandService = accessor.get(_univerjs_core.ICommandService);
4100
- const doc = params.unitId ? univerInstanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUniverDocInstance();
4130
+ const { unitId, sourceRange, targetOffset } = params;
4131
+ const doc = unitId ? univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
4101
4132
  if (!doc) return false;
4102
4133
  const previousDocumentData = doc.getSnapshot();
4103
- const { nextDocumentData, movedRange } = buildMoveDocBlockActions({
4134
+ const moveResult = buildMoveDocBlockActions({
4104
4135
  documentData: previousDocumentData,
4105
- sourceRange: params.sourceRange,
4106
- targetOffset: params.targetOffset
4136
+ sourceRange,
4137
+ targetOffset
4138
+ });
4139
+ const { nextDocumentData, movedRange } = accessor.get(_univerjs_docs.DocBlockMoveValidatorService).transformMoveResult({
4140
+ unitId: doc.getUnitId(),
4141
+ sourceRange,
4142
+ targetOffset,
4143
+ previousDocumentData,
4144
+ result: moveResult
4107
4145
  });
4108
4146
  const actions = buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData);
4109
4147
  if (!actions) return false;
@@ -4161,6 +4199,7 @@ function buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData)
4161
4199
  jsonX.replaceOp(["body", "paragraphs"], previousBody.paragraphs, nextBody.paragraphs),
4162
4200
  jsonX.replaceOp(["body", "sectionBreaks"], previousBody.sectionBreaks, nextBody.sectionBreaks),
4163
4201
  jsonX.replaceOp(["body", "tables"], previousBody.tables, nextBody.tables),
4202
+ jsonX.replaceOp(["body", "columnGroups"], previousBody.columnGroups, nextBody.columnGroups),
4164
4203
  jsonX.replaceOp(["body", "customBlocks"], previousBody.customBlocks, nextBody.customBlocks),
4165
4204
  jsonX.replaceOp(["body", "blockRanges"], previousBody.blockRanges, nextBody.blockRanges),
4166
4205
  jsonX.replaceOp(["body", "customRanges"], previousBody.customRanges, nextBody.customRanges),
@@ -4169,7 +4208,7 @@ function buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData)
4169
4208
  ].filter(Boolean).reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur), null);
4170
4209
  }
4171
4210
  function remapBodyIndexesAfterMove(body, startOffset, endOffset, targetOffset, insertOffset, moveLength) {
4172
- var _body$paragraphs, _body$sectionBreaks, _body$customBlocks, _body$tables, _body$blockRanges, _body$customRanges, _body$customDecoratio, _body$textRuns;
4211
+ var _body$paragraphs, _body$sectionBreaks, _body$customBlocks, _body$tables, _body$columnGroups, _body$blockRanges, _body$customRanges, _body$customDecoratio, _body$textRuns;
4173
4212
  body.paragraphs = (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.map((paragraph) => ({
4174
4213
  ...paragraph,
4175
4214
  startIndex: remapIndexAfterMove(paragraph.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
@@ -4183,6 +4222,7 @@ function remapBodyIndexesAfterMove(body, startOffset, endOffset, targetOffset, i
4183
4222
  startIndex: remapIndexAfterMove(customBlock.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4184
4223
  })).sort((left, right) => left.startIndex - right.startIndex);
4185
4224
  body.tables = (_body$tables = body.tables) === null || _body$tables === void 0 ? void 0 : _body$tables.map((table) => remapExclusiveRange(table, startOffset, endOffset, targetOffset, insertOffset, moveLength)).sort((left, right) => left.startIndex - right.startIndex);
4225
+ body.columnGroups = (_body$columnGroups = body.columnGroups) === null || _body$columnGroups === void 0 ? void 0 : _body$columnGroups.map((columnGroup) => remapExclusiveRange(columnGroup, startOffset, endOffset, targetOffset, insertOffset, moveLength)).sort((left, right) => left.startIndex - right.startIndex);
4186
4226
  body.blockRanges = (_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.map((blockRange) => remapInclusiveRange(blockRange, startOffset, endOffset, targetOffset, insertOffset, moveLength)).sort((left, right) => left.startIndex - right.startIndex);
4187
4227
  body.customRanges = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.map((customRange) => remapInclusiveRange(customRange, startOffset, endOffset, targetOffset, insertOffset, moveLength)).sort((left, right) => left.startIndex - right.startIndex);
4188
4228
  body.customDecorations = (_body$customDecoratio = body.customDecorations) === null || _body$customDecoratio === void 0 ? void 0 : _body$customDecoratio.map((customDecoration) => remapInclusiveRange(customDecoration, startOffset, endOffset, targetOffset, insertOffset, moveLength)).sort((left, right) => left.startIndex - right.startIndex);
@@ -4207,7 +4247,7 @@ function remapExclusiveRange(range, startOffset, endOffset, targetOffset, insert
4207
4247
  return {
4208
4248
  ...range,
4209
4249
  startIndex: remapIndexAfterMove(range.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength),
4210
- endIndex: remapIndexAfterMove(range.endIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4250
+ endIndex: remapExclusiveEndIndexAfterMove(range.endIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4211
4251
  };
4212
4252
  }
4213
4253
  function remapInclusiveRange(range, startOffset, endOffset, targetOffset, insertOffset, moveLength) {
@@ -4228,6 +4268,11 @@ function remapIndexAfterMove(index, startOffset, endOffset, targetOffset, insert
4228
4268
  if (targetOffset > endOffset && index >= endOffset && index < targetOffset) return index - moveLength;
4229
4269
  return index;
4230
4270
  }
4271
+ function remapExclusiveEndIndexAfterMove(index, startOffset, endOffset, targetOffset, insertOffset, moveLength) {
4272
+ if (index > startOffset && index <= endOffset) return insertOffset + index - startOffset;
4273
+ if (targetOffset > endOffset && index >= endOffset && index <= targetOffset) return index - moveLength;
4274
+ return remapIndexAfterMove(index, startOffset, endOffset, targetOffset, insertOffset, moveLength);
4275
+ }
4231
4276
  function clamp$1(value, min, max) {
4232
4277
  return Math.min(Math.max(value, min), max);
4233
4278
  }
@@ -4280,7 +4325,7 @@ const DocSelectAllCommand = {
4280
4325
  id: "doc.command.select-all",
4281
4326
  type: _univerjs_core.CommandType.COMMAND,
4282
4327
  handler: async (accessor) => {
4283
- var _docRanges$find;
4328
+ var _docRanges$find, _docDataModel$getSelf;
4284
4329
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4285
4330
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
4286
4331
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
@@ -4289,7 +4334,7 @@ const DocSelectAllCommand = {
4289
4334
  if (docDataModel == null || activeRange == null) return false;
4290
4335
  const { segmentId } = activeRange;
4291
4336
  const unitId = docDataModel.getUnitId();
4292
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
4337
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
4293
4338
  if (body == null) return false;
4294
4339
  const { dataStream } = body;
4295
4340
  if (dataStream === "\r\n") return true;
@@ -4483,7 +4528,7 @@ const IMEInputCommand = {
4483
4528
  id: "doc.command.ime-input",
4484
4529
  type: _univerjs_core.CommandType.COMMAND,
4485
4530
  handler: async (accessor, params) => {
4486
- var _renderManagerService, _body$customRanges, _body$customDecoratio;
4531
+ var _renderManagerService, _docDataModel$getSelf, _body$customRanges, _body$customDecoratio;
4487
4532
  const { unitId, newText, oldTextLen, isCompositionEnd, isCompositionStart } = params;
4488
4533
  const commandService = accessor.get(_univerjs_core.ICommandService);
4489
4534
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
@@ -4495,7 +4540,7 @@ const IMEInputCommand = {
4495
4540
  const previousActiveRange = imeInputManagerService.getActiveRange();
4496
4541
  if (previousActiveRange == null) return false;
4497
4542
  const { style, segmentId } = previousActiveRange;
4498
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
4543
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
4499
4544
  if (body == null) return false;
4500
4545
  Object.assign(previousActiveRange, previousActiveRange);
4501
4546
  const { startOffset, endOffset } = previousActiveRange;
@@ -4699,7 +4744,7 @@ const SetInlineFormatCommand = {
4699
4744
  id: "doc.command.set-inline-format",
4700
4745
  type: _univerjs_core.CommandType.COMMAND,
4701
4746
  handler: async (accessor, params) => {
4702
- var _docSelectionManagerS, _docRanges$find;
4747
+ var _docSelectionManagerS, _docRanges$find, _docDataModel$getSelf;
4703
4748
  const { value, preCommandId } = params;
4704
4749
  const commandService = accessor.get(_univerjs_core.ICommandService);
4705
4750
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
@@ -4712,7 +4757,7 @@ const SetInlineFormatCommand = {
4712
4757
  const { segmentId } = docRanges[0];
4713
4758
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
4714
4759
  if (docDataModel == null) return false;
4715
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
4760
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
4716
4761
  if (body == null) return false;
4717
4762
  const unitId = docDataModel.getUnitId();
4718
4763
  let formatValue;
@@ -4900,12 +4945,13 @@ const ReplaceSnapshotCommand = {
4900
4945
  id: "doc.command-replace-snapshot",
4901
4946
  type: _univerjs_core.CommandType.COMMAND,
4902
4947
  handler: (accessor, params) => {
4948
+ var _docDataModel$getSelf;
4903
4949
  const { unitId, snapshot, textRanges, segmentId = "", options } = params;
4904
4950
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4905
4951
  const commandService = accessor.get(_univerjs_core.ICommandService);
4906
4952
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
4907
4953
  const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
4908
- const prevSnapshot = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot();
4954
+ const prevSnapshot = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getSnapshot();
4909
4955
  if (docDataModel == null || prevSnapshot == null) return false;
4910
4956
  const { body, tableSource, footers, headers, lists, drawings, drawingsOrder, documentStyle } = _univerjs_core.Tools.deepClone(snapshot);
4911
4957
  const { body: prevBody, tableSource: prevTableSource, footers: prevFooters, headers: prevHeaders, lists: prevLists, drawings: prevDrawings, drawingsOrder: prevDrawingsOrder, documentStyle: prevDocumentStyle } = prevSnapshot;
@@ -4974,12 +5020,13 @@ const ReplaceContentCommand = {
4974
5020
  id: "doc.command-replace-content",
4975
5021
  type: _univerjs_core.CommandType.COMMAND,
4976
5022
  handler: async (accessor, params) => {
5023
+ var _docDataModel$getSelf2;
4977
5024
  const { unitId, body, textRanges, segmentId = "", options } = params;
4978
5025
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4979
5026
  const commandService = accessor.get(_univerjs_core.ICommandService);
4980
5027
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
4981
5028
  const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
4982
- const prevBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
5029
+ const prevBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
4983
5030
  if (docDataModel == null || prevBody == null) return false;
4984
5031
  const doMutation = getMutationParams(unitId, segmentId, docDataModel, prevBody, body);
4985
5032
  doMutation.params.textRanges = textRanges;
@@ -5003,7 +5050,7 @@ const CoverContentCommand = {
5003
5050
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5004
5051
  const commandService = accessor.get(_univerjs_core.ICommandService);
5005
5052
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5006
- const docDatModel = univerInstanceService.getUniverDocInstance(unitId);
5053
+ const docDatModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
5007
5054
  const prevBody = docDatModel === null || docDatModel === void 0 ? void 0 : docDatModel.getSnapshot().body;
5008
5055
  if (docDatModel == null || prevBody == null) return false;
5009
5056
  const doMutation = getMutationParams(unitId, segmentId, docDatModel, prevBody, body);
@@ -5078,12 +5125,13 @@ const ReplaceTextRunsCommand = {
5078
5125
  id: "doc.command.replace-text-runs",
5079
5126
  type: _univerjs_core.CommandType.COMMAND,
5080
5127
  handler: (accessor, params) => {
5128
+ var _docDataModel$getSelf3;
5081
5129
  const { unitId, body, textRanges, segmentId = "", options } = params;
5082
5130
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5083
5131
  const commandService = accessor.get(_univerjs_core.ICommandService);
5084
5132
  const themeService = accessor.get(_univerjs_core.ThemeService);
5085
5133
  const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
5086
- const prevBody = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
5134
+ const prevBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
5087
5135
  if (docDataModel == null || prevBody == null) return false;
5088
5136
  const textX = _univerjs_core.BuildTextUtils.selection.replaceTextRuns({
5089
5137
  doc: docDataModel,
@@ -5159,8 +5207,8 @@ const ListOperationCommand = {
5159
5207
  if (docDataModel == null || docRanges.length === 0) return false;
5160
5208
  const segmentId = docRanges[0].segmentId;
5161
5209
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5162
- const paragraphs = (_segment$getBody$para = (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5163
- const dataStream = (_segment$getBody$data = (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5210
+ const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5211
+ const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5164
5212
  if (!paragraphs.length) return false;
5165
5213
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream);
5166
5214
  const unitId = docDataModel.getUnitId();
@@ -5201,8 +5249,8 @@ const ChangeListTypeCommand = {
5201
5249
  if (docDataModel == null || activeRanges == null || !activeRanges.length) return false;
5202
5250
  const { segmentId } = activeRanges[0];
5203
5251
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5204
- const paragraphs = (_segment$getBody$para2 = (_segment$getBody3 = segment.getBody()) === null || _segment$getBody3 === void 0 ? void 0 : _segment$getBody3.paragraphs) !== null && _segment$getBody$para2 !== void 0 ? _segment$getBody$para2 : [];
5205
- const dataStream = (_segment$getBody$data2 = (_segment$getBody4 = segment.getBody()) === null || _segment$getBody4 === void 0 ? void 0 : _segment$getBody4.dataStream) !== null && _segment$getBody$data2 !== void 0 ? _segment$getBody$data2 : "";
5252
+ const paragraphs = (_segment$getBody$para2 = segment === null || segment === void 0 || (_segment$getBody3 = segment.getBody()) === null || _segment$getBody3 === void 0 ? void 0 : _segment$getBody3.paragraphs) !== null && _segment$getBody$para2 !== void 0 ? _segment$getBody$para2 : [];
5253
+ const dataStream = (_segment$getBody$data2 = segment === null || segment === void 0 || (_segment$getBody4 = segment.getBody()) === null || _segment$getBody4 === void 0 ? void 0 : _segment$getBody4.dataStream) !== null && _segment$getBody$data2 !== void 0 ? _segment$getBody$data2 : "";
5206
5254
  if (!paragraphs.length) return false;
5207
5255
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(activeRanges, paragraphs, dataStream);
5208
5256
  const unitId = docDataModel.getUnitId();
@@ -5250,8 +5298,8 @@ const ChangeListNestingLevelCommand = {
5250
5298
  const { segmentId } = activeRange;
5251
5299
  const selections = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
5252
5300
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5253
- const paragraphs = (_segment$getBody$para3 = (_segment$getBody5 = segment.getBody()) === null || _segment$getBody5 === void 0 ? void 0 : _segment$getBody5.paragraphs) !== null && _segment$getBody$para3 !== void 0 ? _segment$getBody$para3 : [];
5254
- const dataStream = (_segment$getBody$data3 = (_segment$getBody6 = segment.getBody()) === null || _segment$getBody6 === void 0 ? void 0 : _segment$getBody6.dataStream) !== null && _segment$getBody$data3 !== void 0 ? _segment$getBody$data3 : "";
5301
+ const paragraphs = (_segment$getBody$para3 = segment === null || segment === void 0 || (_segment$getBody5 = segment.getBody()) === null || _segment$getBody5 === void 0 ? void 0 : _segment$getBody5.paragraphs) !== null && _segment$getBody$para3 !== void 0 ? _segment$getBody$para3 : [];
5302
+ const dataStream = (_segment$getBody$data3 = segment === null || segment === void 0 || (_segment$getBody6 = segment.getBody()) === null || _segment$getBody6 === void 0 ? void 0 : _segment$getBody6.dataStream) !== null && _segment$getBody$data3 !== void 0 ? _segment$getBody$data3 : "";
5255
5303
  if (!paragraphs.length) return false;
5256
5304
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(activeRange, paragraphs, dataStream);
5257
5305
  const unitId = docDataModel.getUnitId();
@@ -5318,7 +5366,7 @@ const ToggleCheckListCommand = {
5318
5366
  const { index, segmentId, textRanges } = params;
5319
5367
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5320
5368
  if (docDataModel == null) return false;
5321
- if (((_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.paragraphs) == null) return false;
5369
+ if (((_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 || (_docDataModel$getSelf = _docDataModel$getSelf.getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.paragraphs) == null) return false;
5322
5370
  const unitId = docDataModel.getUnitId();
5323
5371
  const doMutation = {
5324
5372
  id: _univerjs_docs.RichTextEditingMutation.id,
@@ -5532,14 +5580,14 @@ const AlignOperationCommand = {
5532
5580
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5533
5581
  const commandService = accessor.get(_univerjs_core.ICommandService);
5534
5582
  const { alignType } = params;
5535
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
5583
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5536
5584
  if (docDataModel == null) return false;
5537
5585
  const allRanges = docSelectionManagerService.getDocRanges();
5538
5586
  if (allRanges.length === 0) return false;
5539
5587
  const segmentId = allRanges[0].segmentId;
5540
5588
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5541
- const paragraphs = (_segment$getBody$para = (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5542
- const dataStream = (_segment$getBody$data = (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5589
+ const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5590
+ const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5543
5591
  if (paragraphs == null) return false;
5544
5592
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(allRanges, paragraphs, dataStream);
5545
5593
  const unitId = docDataModel.getUnitId();
@@ -5643,27 +5691,21 @@ const SetDocZoomRatioCommand = {
5643
5691
  type: _univerjs_core.CommandType.COMMAND,
5644
5692
  id: "doc.command.set-zoom-ratio",
5645
5693
  handler: async (accessor, params) => {
5646
- var _univerInstanceServic;
5647
5694
  const commandService = accessor.get(_univerjs_core.ICommandService);
5648
5695
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5649
5696
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5650
- let documentId = (_univerInstanceServic = univerInstanceService.getCurrentUniverDocInstance()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
5651
- if (!documentId) return false;
5652
- let zoomRatio = 1;
5653
- if (params) {
5654
- var _params$documentId, _params$zoomRatio;
5655
- documentId = (_params$documentId = params.documentId) !== null && _params$documentId !== void 0 ? _params$documentId : documentId;
5656
- zoomRatio = (_params$zoomRatio = params.zoomRatio) !== null && _params$zoomRatio !== void 0 ? _params$zoomRatio : zoomRatio;
5657
- }
5658
- if (!univerInstanceService.getUniverDocInstance(documentId)) return false;
5697
+ const { zoomRatio = 1, documentId } = params || {};
5698
+ const docDatModel = documentId ? univerInstanceService.getUnit(documentId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5699
+ if (!docDatModel) return false;
5700
+ const unitId = docDatModel.getUnitId();
5659
5701
  const setZoomRatioMutationParams = {
5660
5702
  zoomRatio,
5661
- unitId: documentId
5703
+ unitId
5662
5704
  };
5663
5705
  const undoMutationParams = SetDocZoomRatioUndoMutationFactory(accessor, setZoomRatioMutationParams);
5664
5706
  if (commandService.syncExecuteCommand(SetDocZoomRatioOperation.id, setZoomRatioMutationParams)) {
5665
5707
  undoRedoService.pushUndoRedo({
5666
- unitID: documentId,
5708
+ unitID: unitId,
5667
5709
  undoMutations: [{
5668
5710
  id: SetDocZoomRatioOperation.id,
5669
5711
  params: undoMutationParams
@@ -5691,7 +5733,7 @@ const SetParagraphNamedStyleCommand = {
5691
5733
  if (!doc) return false;
5692
5734
  const unitId = doc.getUnitId();
5693
5735
  const selectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5694
- const contentInsertRange = params.textRanges ? null : consumeContentInsertRange(accessor, unitId);
5736
+ const contentInsertRange = params.textRanges ? null : (0, _univerjs_docs.consumeContentInsertRange)(accessor, unitId);
5695
5737
  if (contentInsertRange) return insertNamedStyleParagraph(accessor, doc, params.value, contentInsertRange.startOffset, contentInsertRange.endOffset);
5696
5738
  const selections = (_params$textRanges = params.textRanges) !== null && _params$textRanges !== void 0 ? _params$textRanges : selectionService.getTextRanges({
5697
5739
  unitId,
@@ -5699,8 +5741,10 @@ const SetParagraphNamedStyleCommand = {
5699
5741
  });
5700
5742
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return false;
5701
5743
  const segmentId = selections[0].segmentId;
5744
+ const documentDataModel = doc.getSelfOrHeaderFooterModel(segmentId);
5745
+ if (!documentDataModel) return false;
5702
5746
  const textX = _univerjs_core.BuildTextUtils.paragraph.style.set({
5703
- document: doc.getSelfOrHeaderFooterModel(segmentId),
5747
+ document: documentDataModel,
5704
5748
  textRanges: selections,
5705
5749
  style: {
5706
5750
  namedStyleType: params.value,
@@ -5727,13 +5771,6 @@ const SetParagraphNamedStyleCommand = {
5727
5771
  return Boolean(result);
5728
5772
  }
5729
5773
  };
5730
- function consumeContentInsertRange(accessor, unitId) {
5731
- try {
5732
- return accessor.get(_univerjs_docs.DocContentInsertService).consumeInsertRange(unitId);
5733
- } catch {
5734
- return null;
5735
- }
5736
- }
5737
5774
  function insertNamedStyleParagraph(accessor, doc, namedStyleType, startOffset, endOffset) {
5738
5775
  const textX = _univerjs_core.BuildTextUtils.selection.replace({
5739
5776
  doc,
@@ -5783,8 +5820,8 @@ const QuickHeadingCommand = {
5783
5820
  if (docDataModel == null || activeRange == null || !activeRange.collapsed) return false;
5784
5821
  const { segmentId, startOffset } = activeRange;
5785
5822
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5786
- const paragraphs = (_segment$getBody$para = (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5787
- const dataStream = (_segment$getBody$data = (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5823
+ const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5824
+ const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5788
5825
  const paragraph = _univerjs_core.BuildTextUtils.paragraph.util.getParagraphsInRange(activeRange, paragraphs, dataStream)[0];
5789
5826
  if (!paragraph) return false;
5790
5827
  const { paragraphStart } = paragraph;
@@ -5911,6 +5948,8 @@ const NodePositionMap = {
5911
5948
  glyph: 5
5912
5949
  };
5913
5950
  function compareNodePositionLogic(pos1, pos2) {
5951
+ const nestedPagePathOrder = (0, _univerjs_engine_render.compareDocumentSkeletonNestedPagePathOrder)(pos1, pos2);
5952
+ if (nestedPagePathOrder != null) return nestedPagePathOrder;
5914
5953
  if (pos1.page > pos2.page) return false;
5915
5954
  if (pos1.page < pos2.page) return true;
5916
5955
  if (pos1.section > pos2.section) return false;
@@ -6167,14 +6206,17 @@ var NodePositionConvertToCursor = class {
6167
6206
  this._resetCurrentNodePositionState();
6168
6207
  if (this._documentOffsetConfig == null) return [];
6169
6208
  const { pageLayoutType, pageMarginLeft, pageMarginTop } = this._documentOffsetConfig;
6170
- const skipPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? pageIndex : segmentPage;
6209
+ const startRootPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL && pages[pageIndex] == null ? segmentPage : pageIndex;
6210
+ const endRootPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL && pages[endPageIndex] == null ? endSegmentPage : endPageIndex;
6211
+ const skipPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? startRootPageIndex : segmentPage;
6171
6212
  for (let p = 0; p < skipPageIndex; p++) {
6172
6213
  const page = pages[p];
6173
6214
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6174
6215
  }
6175
- const endIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? endPageIndex : endSegmentPage;
6216
+ const endIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? endRootPageIndex : endSegmentPage;
6176
6217
  for (let p = skipPageIndex; p <= endIndex; p++) {
6177
6218
  const page = pages[p];
6219
+ if (page == null) continue;
6178
6220
  const { headerId, footerId, pageWidth } = page;
6179
6221
  let segmentPage = page;
6180
6222
  if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.HEADER) {
@@ -6183,7 +6225,7 @@ var NodePositionConvertToCursor = class {
6183
6225
  } else if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.FOOTER) {
6184
6226
  var _skeFooters$get;
6185
6227
  segmentPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
6186
- } else if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL) segmentPage = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, path);
6228
+ } else if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL) segmentPage = path[0] === "pages" ? (0, _univerjs_engine_render.getPageFromPath)(skeletonData, path) : getCellPageFromSegmentPath(skeletonData, page, path);
6187
6229
  if (segmentPage == null) {
6188
6230
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6189
6231
  continue;
@@ -6206,9 +6248,17 @@ var NodePositionConvertToCursor = class {
6206
6248
  break;
6207
6249
  }
6208
6250
  case _univerjs_engine_render.DocumentSkeletonPageType.CELL: {
6209
- this._liquid.translatePagePadding(page);
6251
+ const nestedPageOffset = (0, _univerjs_engine_render.getDocumentSkeletonNestedPageOffset)(segmentPage);
6252
+ if (nestedPageOffset) {
6253
+ this._liquid.translatePagePadding(page);
6254
+ this._liquid.translate(nestedPageOffset.left, nestedPageOffset.top);
6255
+ this._liquid.translatePagePadding(segmentPage);
6256
+ break;
6257
+ }
6210
6258
  const rowSke = segmentPage.parent;
6211
6259
  const tableSke = rowSke.parent;
6260
+ const tablePage = tableSke.parent;
6261
+ const tablePageNestedOffset = tablePage ? (0, _univerjs_engine_render.getDocumentSkeletonNestedPageOffset)(tablePage) : void 0;
6212
6262
  const { left: cellLeft } = segmentPage;
6213
6263
  const { top: tableTop, left: tableLeft } = tableSke;
6214
6264
  const { top: rowTop } = rowSke;
@@ -6216,6 +6266,18 @@ var NodePositionConvertToCursor = class {
6216
6266
  const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(getDocumentUnitId$1(skeleton), sourceTableId);
6217
6267
  const hasHorizontalViewport = hasHorizontalTableViewport$2(viewport);
6218
6268
  const scrollLeft = hasHorizontalViewport ? viewport.scrollLeft : 0;
6269
+ if ((tablePage === null || tablePage === void 0 ? void 0 : tablePage.type) === _univerjs_engine_render.DocumentSkeletonPageType.HEADER) this._liquid.translatePagePadding({
6270
+ ...tablePage,
6271
+ marginLeft: page.marginLeft
6272
+ });
6273
+ else if ((tablePage === null || tablePage === void 0 ? void 0 : tablePage.type) === _univerjs_engine_render.DocumentSkeletonPageType.FOOTER) {
6274
+ const footerTop = page.pageHeight - tablePage.height - tablePage.marginBottom;
6275
+ this._liquid.translate(page.marginLeft, footerTop);
6276
+ } else this._liquid.translatePagePadding(page);
6277
+ if (tablePageNestedOffset) {
6278
+ this._liquid.translate(tablePageNestedOffset.left, tablePageNestedOffset.top);
6279
+ this._liquid.translatePagePadding(tablePage);
6280
+ }
6219
6281
  if (hasHorizontalViewport) {
6220
6282
  var _viewport$leadingInse;
6221
6283
  const visibleLeft = this._liquid.x + tableLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
@@ -6287,6 +6349,28 @@ function clipPositionToHorizontalRange(position, clip) {
6287
6349
  endX
6288
6350
  };
6289
6351
  }
6352
+ function getCellPageFromSegmentPath(skeletonData, rootPage, path) {
6353
+ var _skeletonData$skeHead, _skeletonData$skeFoot;
6354
+ if (path[0] === "pages") return null;
6355
+ const segmentPages = [];
6356
+ const { headerId, footerId, pageWidth } = rootPage;
6357
+ const headerPage = headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(pageWidth);
6358
+ const footerPage = footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(pageWidth);
6359
+ if (headerPage != null) segmentPages.push(headerPage);
6360
+ if (footerPage != null) segmentPages.push(footerPage);
6361
+ for (const segmentPage of segmentPages) {
6362
+ const page = (0, _univerjs_engine_render.getPageFromPath)({
6363
+ ...skeletonData,
6364
+ pages: [segmentPage]
6365
+ }, [
6366
+ "pages",
6367
+ 0,
6368
+ ...path
6369
+ ]);
6370
+ if (page != null) return page;
6371
+ }
6372
+ return null;
6373
+ }
6290
6374
  function getDocumentUnitId$1(docSkeleton) {
6291
6375
  var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3, _viewModel$getDataMod4;
6292
6376
  const viewModel = docSkeleton.getViewModel();
@@ -6317,8 +6401,14 @@ function isInSameTableCell(anchorNodePosition, focusNodePosition) {
6317
6401
  const { path: anchorPath } = anchorNodePosition;
6318
6402
  const { path: focusPath } = focusNodePosition;
6319
6403
  if (anchorPath.indexOf("cells") === -1 || focusPath.indexOf("cells") === -1) return false;
6320
- if (anchorPath.length !== focusPath.length) return false;
6321
- return _univerjs_core.Tools.diffValue(anchorPath, focusPath);
6404
+ const anchorTableIdIndex = anchorPath.indexOf("skeTables") + 1;
6405
+ const anchorRowIndex = anchorPath.indexOf("rows") + 1;
6406
+ const anchorCellIndex = anchorPath.indexOf("cells") + 1;
6407
+ const focusTableIdIndex = focusPath.indexOf("skeTables") + 1;
6408
+ const focusRowIndex = focusPath.indexOf("rows") + 1;
6409
+ const focusCellIndex = focusPath.indexOf("cells") + 1;
6410
+ if (anchorTableIdIndex === 0 || anchorRowIndex === 0 || anchorCellIndex === 0 || focusTableIdIndex === 0 || focusRowIndex === 0 || focusCellIndex === 0) return false;
6411
+ return anchorPath[anchorTableIdIndex] === focusPath[focusTableIdIndex] && anchorPath[anchorRowIndex] === focusPath[focusRowIndex] && anchorPath[anchorCellIndex] === focusPath[focusCellIndex];
6322
6412
  }
6323
6413
  function isInSameTableCellData(skeleton, anchorNodePosition, focusNodePosition) {
6324
6414
  var _anchorGlyph$parent, _focusGlyph$parent;
@@ -6353,7 +6443,7 @@ function compareNodePositionInTable(a, b) {
6353
6443
  if (aRowCount > bRowCount) return false;
6354
6444
  return aCellCount <= bCellCount;
6355
6445
  }
6356
- function isEmptyCellPage$1(cell) {
6446
+ function isEmptyCellPage(cell) {
6357
6447
  return cell.sections[0].columns[0].lines.length === 0;
6358
6448
  }
6359
6449
  function findNonEmptyCellPages(cells, startCol, endCol) {
@@ -6361,14 +6451,14 @@ function findNonEmptyCellPages(cells, startCol, endCol) {
6361
6451
  let e = endCol;
6362
6452
  let startCell = cells[s];
6363
6453
  let endCell = cells[e];
6364
- while (s < e && (isEmptyCellPage$1(startCell) || isEmptyCellPage$1(endCell))) if (isEmptyCellPage$1(startCell)) {
6454
+ while (s < e && (isEmptyCellPage(startCell) || isEmptyCellPage(endCell))) if (isEmptyCellPage(startCell)) {
6365
6455
  s++;
6366
6456
  startCell = cells[s];
6367
- } else if (isEmptyCellPage$1(endCell)) {
6457
+ } else if (isEmptyCellPage(endCell)) {
6368
6458
  e--;
6369
6459
  endCell = cells[e];
6370
6460
  }
6371
- if (!isEmptyCellPage$1(startCell) && !isEmptyCellPage$1(endCell)) return [startCell, endCell];
6461
+ if (!isEmptyCellPage(startCell) && !isEmptyCellPage(endCell)) return [startCell, endCell];
6372
6462
  }
6373
6463
  function getColumnBoundary(table, column) {
6374
6464
  var _table$tableSource;
@@ -6416,6 +6506,7 @@ var NodePositionConvertToRectRange = class {
6416
6506
  _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
6417
6507
  }
6418
6508
  getRangePointData(startNodePosition, endNodePosition) {
6509
+ var _this$_documentOffset, _this$_documentOffset2;
6419
6510
  const pointGroup = [];
6420
6511
  const docSkeleton = this._docSkeleton;
6421
6512
  const skeletonData = docSkeleton.getSkeletonData();
@@ -6429,7 +6520,16 @@ var NodePositionConvertToRectRange = class {
6429
6520
  const { pageLayoutType, pageMarginLeft, pageMarginTop } = this._documentOffsetConfig;
6430
6521
  const unitId = getDocumentUnitId(docSkeleton);
6431
6522
  const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
6432
- const skipPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? startPage : startSegmentPage;
6523
+ const nestedTableContexts = (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
6524
+ docsLeft: (_this$_documentOffset = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset !== void 0 ? _this$_documentOffset : 0,
6525
+ docsTop: (_this$_documentOffset2 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset2 !== void 0 ? _this$_documentOffset2 : 0,
6526
+ pageMarginTop,
6527
+ skeFooters: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeFooters,
6528
+ skeHeaders: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeHeaders,
6529
+ unitId
6530
+ });
6531
+ const startRootPage = pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL && pages[startPage] == null ? startSegmentPage : startPage;
6532
+ const skipPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? startRootPage : startSegmentPage;
6433
6533
  for (let p = 0; p < skipPageIndex; p++) {
6434
6534
  const page = pages[p];
6435
6535
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
@@ -6441,6 +6541,44 @@ var NodePositionConvertToRectRange = class {
6441
6541
  let table = null;
6442
6542
  for (const [id, tableSke] of skeTables.entries()) if (id.startsWith(tableId)) table = tableSke;
6443
6543
  if (table == null) {
6544
+ const nestedTableContext = nestedTableContexts.find((context) => context.pageIndex === p && (context.source === "column" || context.source === "header" || context.source === "footer") && context.tableId.startsWith(tableId));
6545
+ if (nestedTableContext) {
6546
+ var _this$_documentOffset3, _this$_documentOffset4;
6547
+ const nestedTable = nestedTableContext.table;
6548
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, sourceTableId);
6549
+ const nestedX = nestedTableContext.tableRect.left - nestedTable.left - ((_this$_documentOffset3 = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset3 !== void 0 ? _this$_documentOffset3 : 0);
6550
+ const nestedY = nestedTableContext.tableRect.top - ((_this$_documentOffset4 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset4 !== void 0 ? _this$_documentOffset4 : 0);
6551
+ if (intersectsMergedCell) {
6552
+ const rows = nestedTable.rows.filter((row) => row.index >= startRow && row.index <= endRow);
6553
+ const firstRow = rows[0];
6554
+ const lastRow = rows[rows.length - 1];
6555
+ const startX = getColumnBoundary(nestedTable, startColumn);
6556
+ const endX = getColumnBoundary(nestedTable, endColumn + 1);
6557
+ if (firstRow && lastRow && startX != null && endX != null) pushViewportClippedPoints(pointGroup, {
6558
+ startX: nestedX + nestedTable.left + startX,
6559
+ startY: nestedY + firstRow.top,
6560
+ endX: nestedX + nestedTable.left + endX,
6561
+ endY: nestedY + lastRow.top + lastRow.height
6562
+ }, viewport, nestedX + nestedTable.left);
6563
+ this._liquid.restorePagePadding(page);
6564
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6565
+ continue;
6566
+ }
6567
+ for (const row of nestedTable.rows) if (row.index >= startRow && row.index <= endRow) {
6568
+ const cells = findNonEmptyCellPages(row.cells, startColumn, endColumn);
6569
+ if (cells == null) continue;
6570
+ const [rowStartCell, rowEndCell] = cells;
6571
+ pushViewportClippedPoints(pointGroup, {
6572
+ startX: nestedX + rowStartCell.left + nestedTable.left,
6573
+ startY: nestedY + row.top,
6574
+ endX: nestedX + rowEndCell.left + rowEndCell.pageWidth + nestedTable.left,
6575
+ endY: nestedY + row.top + row.height
6576
+ }, viewport, nestedX + nestedTable.left);
6577
+ }
6578
+ this._liquid.restorePagePadding(page);
6579
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6580
+ continue;
6581
+ }
6444
6582
  this._liquid.restorePagePadding(page);
6445
6583
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6446
6584
  continue;
@@ -6539,19 +6677,23 @@ var NodePositionConvertToRectRange = class {
6539
6677
  const { pages } = skeletonData;
6540
6678
  const { path: anchorPath } = anchorPosition;
6541
6679
  const { path: focusPath } = focusPosition;
6542
- const anchorCell = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, anchorPath);
6543
- const focusCell = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, focusPath);
6680
+ if (anchorPath.indexOf("cells") === -1 || focusPath.indexOf("cells") === -1) return;
6681
+ const anchorCell = getCellPageFromPositionPath(skeletonData, anchorPosition);
6682
+ const focusCell = getCellPageFromPositionPath(skeletonData, focusPosition);
6544
6683
  if (anchorCell == null || focusCell == null) return;
6684
+ const anchorRow = anchorCell.parent;
6685
+ const focusRow = focusCell.parent;
6686
+ if (!Array.isArray(anchorRow === null || anchorRow === void 0 ? void 0 : anchorRow.cells) || !Array.isArray(focusRow === null || focusRow === void 0 ? void 0 : focusRow.cells)) return;
6545
6687
  const tableId = anchorCell.segmentId;
6546
- const anchorRow = anchorCell.parent.index;
6547
- const anchorColumn = anchorCell.parent.cells.indexOf(anchorCell);
6548
- const focusRow = (focusCell === null || focusCell === void 0 ? void 0 : focusCell.parent).index;
6549
- const focusColumn = (focusCell === null || focusCell === void 0 ? void 0 : focusCell.parent).cells.indexOf(focusCell);
6688
+ const anchorRowIndex = anchorRow.index;
6689
+ const anchorColumn = anchorRow.cells.indexOf(anchorCell);
6690
+ const focusRowIndex = focusRow.index;
6691
+ const focusColumn = focusRow.cells.indexOf(focusCell);
6550
6692
  const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
6551
6693
  const tableSource = (_docSkeleton$getViewM = docSkeleton.getViewModel().getSnapshot().tableSource) === null || _docSkeleton$getViewM === void 0 ? void 0 : _docSkeleton$getViewM[sourceTableId];
6552
6694
  const rawRange = {
6553
- startRowIndex: Math.min(anchorRow, focusRow),
6554
- endRowIndex: Math.max(anchorRow, focusRow),
6695
+ startRowIndex: Math.min(anchorRowIndex, focusRowIndex),
6696
+ endRowIndex: Math.max(anchorRowIndex, focusRowIndex),
6555
6697
  startColumnIndex: Math.min(anchorColumn, focusColumn),
6556
6698
  endColumnIndex: Math.max(anchorColumn, focusColumn)
6557
6699
  };
@@ -6613,6 +6755,28 @@ function rangeIntersectsMergedCell(table, range) {
6613
6755
  });
6614
6756
  }));
6615
6757
  }
6758
+ function getCellPageFromPositionPath(skeletonData, position) {
6759
+ var _skeletonData$skeHead, _skeletonData$skeFoot;
6760
+ const { path, segmentPage } = position;
6761
+ if (path[0] === "pages") return (0, _univerjs_engine_render.getPageFromPath)(skeletonData, path);
6762
+ const rootPage = skeletonData.pages[segmentPage];
6763
+ if (rootPage == null) return null;
6764
+ const { headerId, footerId, pageWidth } = rootPage;
6765
+ const segmentPages = [headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(pageWidth), footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(pageWidth)];
6766
+ for (const segmentPage of segmentPages) {
6767
+ if (segmentPage == null) continue;
6768
+ const page = (0, _univerjs_engine_render.getPageFromPath)({
6769
+ ...skeletonData,
6770
+ pages: [segmentPage]
6771
+ }, [
6772
+ "pages",
6773
+ 0,
6774
+ ...path
6775
+ ]);
6776
+ if (page != null) return page;
6777
+ }
6778
+ return null;
6779
+ }
6616
6780
  function normalizeRange(range) {
6617
6781
  return {
6618
6782
  startRowIndex: Math.min(range.startRowIndex, range.endRowIndex),
@@ -6705,17 +6869,17 @@ var TextRange = class {
6705
6869
  }, 1e3);
6706
6870
  }
6707
6871
  get startOffset() {
6708
- var _getOneTextSelectionR;
6872
+ var _getOneTextSelectionR, _this$_docSkeleton$ge;
6709
6873
  const { startOffset } = (_getOneTextSelectionR = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
6710
- const body = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();
6874
+ const body = (_this$_docSkeleton$ge = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId)) === null || _this$_docSkeleton$ge === void 0 ? void 0 : _this$_docSkeleton$ge.getBody();
6711
6875
  if (startOffset == null || body == null) return startOffset;
6712
6876
  const maxLength = body.dataStream.length - 2;
6713
6877
  return Math.min(maxLength, startOffset);
6714
6878
  }
6715
6879
  get endOffset() {
6716
- var _getOneTextSelectionR2;
6880
+ var _getOneTextSelectionR2, _this$_docSkeleton$ge2;
6717
6881
  const { endOffset } = (_getOneTextSelectionR2 = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
6718
- const body = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();
6882
+ const body = (_this$_docSkeleton$ge2 = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId)) === null || _this$_docSkeleton$ge2 === void 0 ? void 0 : _this$_docSkeleton$ge2.getBody();
6719
6883
  if (endOffset == null || body == null) return endOffset;
6720
6884
  const maxLength = body.dataStream.length - 2;
6721
6885
  return Math.min(endOffset, maxLength);
@@ -7077,6 +7241,20 @@ var RectRange = class {
7077
7241
 
7078
7242
  //#endregion
7079
7243
  //#region src/services/selection/selection-utils.ts
7244
+ function isInSameColumnPage(anchorPosition, focusPosition) {
7245
+ const anchorColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(anchorPosition);
7246
+ const focusColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(focusPosition);
7247
+ return !!anchorColumnInfo && !!focusColumnInfo && anchorColumnInfo.pageIndex === focusColumnInfo.pageIndex && anchorColumnInfo.columnGroupId === focusColumnInfo.columnGroupId && anchorColumnInfo.columnIndex === focusColumnInfo.columnIndex;
7248
+ }
7249
+ function getColumnInputBoundaryCollapsedPosition(anchorPosition, focusPosition, skeleton) {
7250
+ const anchorColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(anchorPosition);
7251
+ const focusColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(focusPosition);
7252
+ if (!anchorColumnInfo || !focusColumnInfo || anchorColumnInfo.pageIndex !== focusColumnInfo.pageIndex || anchorColumnInfo.columnGroupId !== focusColumnInfo.columnGroupId || anchorColumnInfo.columnIndex + 1 !== focusColumnInfo.columnIndex) return;
7253
+ const anchorOffset = skeleton.findCharIndexByPosition(anchorPosition);
7254
+ const focusOffset = skeleton.findCharIndexByPosition(focusPosition);
7255
+ if (anchorOffset == null || focusOffset == null || anchorOffset <= focusOffset) return;
7256
+ return anchorPosition;
7257
+ }
7080
7258
  function getTextRangeFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage, startIsBack = true, endIsBack = true) {
7081
7259
  const startNodePosition = skeleton.findNodePositionByCharIndex(startOffset, startIsBack, segmentId, segmentPage);
7082
7260
  const endNodePosition = skeleton.findNodePositionByCharIndex(endOffset, endIsBack, segmentId, segmentPage);
@@ -7108,6 +7286,21 @@ function getRangeListFromSelection(anchorPosition, focusPosition, scene, documen
7108
7286
  segmentId,
7109
7287
  segmentPage
7110
7288
  ];
7289
+ const collapsedColumnPosition = getColumnInputBoundaryCollapsedPosition(anchorPosition, focusPosition, skeleton);
7290
+ if (collapsedColumnPosition) {
7291
+ textRanges.push(new TextRange(scene, document, skeleton, collapsedColumnPosition, collapsedColumnPosition, style, segmentId, segmentPage));
7292
+ return {
7293
+ textRanges,
7294
+ rectRanges
7295
+ };
7296
+ }
7297
+ if (isInSameColumnPage(anchorPosition, focusPosition)) {
7298
+ textRanges.push(new TextRange(...rangeParams));
7299
+ return {
7300
+ textRanges,
7301
+ rectRanges
7302
+ };
7303
+ }
7111
7304
  if (isInSameTableCellData(skeleton, anchorPosition, focusPosition)) if (isInSameTableCell(anchorPosition, focusPosition)) {
7112
7305
  textRanges.push(new TextRange(...rangeParams));
7113
7306
  return {
@@ -8086,7 +8279,7 @@ const SwitchDocModeCommand = {
8086
8279
  const commandService = accessor.get(_univerjs_core.ICommandService);
8087
8280
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
8088
8281
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8089
- const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
8282
+ const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8090
8283
  if (docDataModel == null) return false;
8091
8284
  const unitId = docDataModel.getUnitId();
8092
8285
  const skeleton = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
@@ -8191,6 +8384,18 @@ function shouldCreateParagraphBeforeTable(body, startOffset) {
8191
8384
  function normalizeTableInsertOffset(body, startOffset) {
8192
8385
  return startOffset === 0 && body.dataStream[0] === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH ? 1 : startOffset;
8193
8386
  }
8387
+ function canInsertTableAtOffset(body, offset) {
8388
+ return !(isOffsetInTableRange(body.tables, offset) || isOffsetInIndexRange(body.blockRanges, offset) || isOffsetOnPointRange(body.customBlocks, offset));
8389
+ }
8390
+ function isOffsetInTableRange(ranges, offset) {
8391
+ return Boolean(ranges === null || ranges === void 0 ? void 0 : ranges.some((range) => range.startIndex <= offset && offset < range.endIndex));
8392
+ }
8393
+ function isOffsetInIndexRange(ranges, offset) {
8394
+ return Boolean(ranges === null || ranges === void 0 ? void 0 : ranges.some((range) => range.startIndex <= offset && offset <= range.endIndex));
8395
+ }
8396
+ function isOffsetOnPointRange(ranges, offset) {
8397
+ return Boolean(ranges === null || ranges === void 0 ? void 0 : ranges.some((range) => range.startIndex === offset));
8398
+ }
8194
8399
  /**
8195
8400
  * The command to create a table at cursor point.
8196
8401
  */
@@ -8198,13 +8403,13 @@ const CreateDocTableCommand = {
8198
8403
  id: CreateDocTableCommandId,
8199
8404
  type: _univerjs_core.CommandType.COMMAND,
8200
8405
  handler: async (accessor, params) => {
8201
- var _ref, _contentInsertRange$s, _contentInsertRange$s2, _body$paragraphs, _curGlyph$parent, _body$paragraphs2;
8406
+ var _ref, _contentInsertRange$s, _docDataModel$getSelf, _contentInsertRange$s2, _body$paragraphs, _curGlyph$parent, _body$paragraphs2;
8202
8407
  const { rowCount, colCount } = params;
8203
8408
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8204
8409
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
8205
8410
  const commandService = accessor.get(_univerjs_core.ICommandService);
8206
8411
  const docMenuStyleService = accessor.get(DocMenuStyleService);
8207
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8412
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8208
8413
  if (docDataModel == null) return false;
8209
8414
  let contentInsertRange = null;
8210
8415
  try {
@@ -8216,13 +8421,14 @@ const CreateDocTableCommand = {
8216
8421
  if (activeRange == null && contentInsertRange == null) return false;
8217
8422
  const segmentId = (_ref = (_contentInsertRange$s = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _ref !== void 0 ? _ref : "";
8218
8423
  const segmentPage = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentPage;
8219
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8424
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
8220
8425
  if (body == null) return false;
8221
8426
  const unitId = docDataModel.getUnitId();
8222
8427
  const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
8223
8428
  const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
8224
8429
  if (skeleton == null) return false;
8225
8430
  const startOffset = normalizeTableInsertOffset(body, (_contentInsertRange$s2 = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.startOffset) !== null && _contentInsertRange$s2 !== void 0 ? _contentInsertRange$s2 : activeRange.startOffset);
8431
+ if (!canInsertTableAtOffset(body, startOffset)) return false;
8226
8432
  const prevParagraph = ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).find((p) => p.startIndex >= startOffset);
8227
8433
  const curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
8228
8434
  if (curGlyph == null) return false;
@@ -8293,6 +8499,7 @@ const DocTableDeleteRowsCommand = {
8293
8499
  id: "doc.table.delete-rows",
8294
8500
  type: _univerjs_core.CommandType.COMMAND,
8295
8501
  handler: async (accessor) => {
8502
+ var _docDataModel$getSelf;
8296
8503
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8297
8504
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
8298
8505
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -8300,8 +8507,8 @@ const DocTableDeleteRowsCommand = {
8300
8507
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8301
8508
  if (rangeInfo == null) return false;
8302
8509
  const { segmentId } = rangeInfo;
8303
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8304
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8510
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8511
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
8305
8512
  if (docDataModel == null || body == null) return false;
8306
8513
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8307
8514
  if (docSkeletonManagerService == null) return false;
@@ -8357,6 +8564,7 @@ const DocTableDeleteColumnsCommand = {
8357
8564
  id: "doc.table.delete-columns",
8358
8565
  type: _univerjs_core.CommandType.COMMAND,
8359
8566
  handler: async (accessor) => {
8567
+ var _docDataModel$getSelf2;
8360
8568
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8361
8569
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
8362
8570
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -8364,8 +8572,8 @@ const DocTableDeleteColumnsCommand = {
8364
8572
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8365
8573
  if (rangeInfo == null) return false;
8366
8574
  const { segmentId } = rangeInfo;
8367
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8368
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8575
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8576
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
8369
8577
  if (docDataModel == null || body == null) return false;
8370
8578
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8371
8579
  if (docSkeletonManagerService == null) return false;
@@ -8436,6 +8644,7 @@ const DocTableDeleteTableCommand = {
8436
8644
  id: "doc.table.delete-table",
8437
8645
  type: _univerjs_core.CommandType.COMMAND,
8438
8646
  handler: async (accessor) => {
8647
+ var _docDataModel$getSelf3;
8439
8648
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8440
8649
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
8441
8650
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -8443,8 +8652,8 @@ const DocTableDeleteTableCommand = {
8443
8652
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8444
8653
  if (rangeInfo == null) return false;
8445
8654
  const { segmentId } = rangeInfo;
8446
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8447
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8655
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8656
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
8448
8657
  if (docDataModel == null || body == null) return false;
8449
8658
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8450
8659
  if (docSkeletonManagerService == null) return false;
@@ -8532,6 +8741,7 @@ const DocTableInsertRowCommand = {
8532
8741
  id: DocTableInsertRowCommandId,
8533
8742
  type: _univerjs_core.CommandType.COMMAND,
8534
8743
  handler: async (accessor, params) => {
8744
+ var _docDataModel$getSelf;
8535
8745
  const { position } = params;
8536
8746
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8537
8747
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -8541,7 +8751,7 @@ const DocTableInsertRowCommand = {
8541
8751
  if (rangeInfo == null) return false;
8542
8752
  const { segmentId } = rangeInfo;
8543
8753
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8544
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8754
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
8545
8755
  if (docDataModel == null || body == null) return false;
8546
8756
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8547
8757
  if (docSkeletonManagerService == null) return false;
@@ -8601,7 +8811,7 @@ const DocTableInsertColumnCommand = {
8601
8811
  id: DocTableInsertColumnCommandId,
8602
8812
  type: _univerjs_core.CommandType.COMMAND,
8603
8813
  handler: async (accessor, params) => {
8604
- var _documentStyle$pageSi, _documentStyle$pageSi2, _snapshot$tableSource;
8814
+ var _docDataModel$getSelf2, _snapshot$tableSource, _documentStyle$pageSi, _documentStyle$pageSi2;
8605
8815
  const { position } = params;
8606
8816
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8607
8817
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -8610,8 +8820,8 @@ const DocTableInsertColumnCommand = {
8610
8820
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8611
8821
  if (rangeInfo == null) return false;
8612
8822
  const { segmentId } = rangeInfo;
8613
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8614
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
8823
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8824
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
8615
8825
  if (docDataModel == null || body == null) return false;
8616
8826
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8617
8827
  if (docSkeletonManagerService == null) return false;
@@ -8666,10 +8876,11 @@ const DocTableInsertColumnCommand = {
8666
8876
  const snapshot = docDataModel.getSnapshot();
8667
8877
  const documentStyle = snapshot.documentStyle;
8668
8878
  const { marginLeft = 0, marginRight = 0 } = documentStyle;
8669
- const pageWidth = ((_documentStyle$pageSi = (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.width) !== null && _documentStyle$pageSi !== void 0 ? _documentStyle$pageSi : 800) - marginLeft - marginRight;
8670
8879
  const tableColumns = snapshot === null || snapshot === void 0 || (_snapshot$tableSource = snapshot.tableSource) === null || _snapshot$tableSource === void 0 || (_snapshot$tableSource = _snapshot$tableSource[tableId]) === null || _snapshot$tableSource === void 0 ? void 0 : _snapshot$tableSource.tableColumns;
8671
8880
  if (!tableColumns) return false;
8672
- const { newColWidth, widths } = getColumnWidths(pageWidth, tableColumns, columnIndex);
8881
+ const pageWidth = ((_documentStyle$pageSi = (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.width) !== null && _documentStyle$pageSi !== void 0 ? _documentStyle$pageSi : 800) - marginLeft - marginRight;
8882
+ const tableWidth = tableColumns.reduce((sum, column) => sum + column.size.width.v, 0);
8883
+ const { newColWidth, widths } = getColumnWidths(tableWidth > 0 ? tableWidth : pageWidth, tableColumns, columnIndex);
8673
8884
  for (let i = 0; i < widths.length; i++) {
8674
8885
  const action = jsonX.replaceOp([
8675
8886
  "tableSource",
@@ -8709,7 +8920,7 @@ const DocTableTabCommand = {
8709
8920
  const textSelectionManager = accessor.get(_univerjs_docs.DocSelectionManagerService);
8710
8921
  const docRanges = textSelectionManager.getDocRanges();
8711
8922
  const commandService = accessor.get(_univerjs_core.ICommandService);
8712
- const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
8923
+ const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
8713
8924
  if (!docDataModel) return false;
8714
8925
  const activeRange = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
8715
8926
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
@@ -9262,7 +9473,7 @@ let EditorService = class EditorService extends _univerjs_core.Disposable {
9262
9473
  this._univerInstanceService.disposeUnit(editorUnitId);
9263
9474
  }
9264
9475
  _getCurrentEditorUnitId() {
9265
- return this._univerInstanceService.getCurrentUniverDocInstance().getUnitId();
9476
+ return this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC).getUnitId();
9266
9477
  }
9267
9478
  _getBlank(id) {
9268
9479
  return {
@@ -9919,325 +10130,138 @@ function findFirstCursorOffset(snapshot) {
9919
10130
  }
9920
10131
 
9921
10132
  //#endregion
9922
- //#region src/views/header-footer/text-bubble.ts
9923
- const COLLAB_CURSOR_LABEL_HEIGHT = 18;
9924
- const COLLAB_CURSOR_LABEL_MAX_WIDTH = 200;
9925
- const COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 6;
9926
- const COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 4;
9927
- function drawBubble(ctx, props) {
9928
- var _radius, _width, _height;
9929
- let { radius, width, height } = props;
9930
- radius = (_radius = radius) !== null && _radius !== void 0 ? _radius : 0;
9931
- width = (_width = width) !== null && _width !== void 0 ? _width : 30;
9932
- height = (_height = height) !== null && _height !== void 0 ? _height : 30;
9933
- let bottomRight = 0;
9934
- bottomRight = Math.min(radius, width / 2, height / 2);
9935
- ctx.beginPath();
9936
- ctx.moveTo(0, 0);
9937
- ctx.lineTo(width, 0);
9938
- ctx.lineTo(width, height - bottomRight);
9939
- ctx.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
9940
- ctx.lineTo(0, height);
9941
- ctx.lineTo(0, 0);
9942
- ctx.closePath();
9943
- if (props.fill) {
9944
- ctx.save();
9945
- ctx.fillStyle = props.fill;
9946
- if (props.fillRule === "evenodd") ctx.fill("evenodd");
9947
- else ctx.fill();
9948
- ctx.restore();
9949
- }
9950
- }
10133
+ //#region src/views/header-footer/panel/component-name.ts
9951
10134
  /**
9952
- * Render a single collaborated cursor on the canvas.
10135
+ * Copyright 2023-present DreamNum Co., Ltd.
10136
+ *
10137
+ * Licensed under the Apache License, Version 2.0 (the "License");
10138
+ * you may not use this file except in compliance with the License.
10139
+ * You may obtain a copy of the License at
10140
+ *
10141
+ * http://www.apache.org/licenses/LICENSE-2.0
10142
+ *
10143
+ * Unless required by applicable law or agreed to in writing, software
10144
+ * distributed under the License is distributed on an "AS IS" BASIS,
10145
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10146
+ * See the License for the specific language governing permissions and
10147
+ * limitations under the License.
9953
10148
  */
9954
- var TextBubbleShape = class TextBubbleShape extends _univerjs_engine_render.Shape {
9955
- constructor(key, props) {
9956
- super(key, props);
9957
- _defineProperty(this, "color", void 0);
9958
- _defineProperty(this, "text", void 0);
9959
- this.color = props === null || props === void 0 ? void 0 : props.color;
9960
- this.text = props === null || props === void 0 ? void 0 : props.text;
9961
- }
9962
- static drawWith(ctx, props) {
9963
- const { text, color } = props;
9964
- ctx.save();
9965
- ctx.font = "13px Source Han Sans CN";
9966
- const textWidth = ctx.measureText(text).width;
9967
- drawBubble(ctx, {
9968
- height: 18,
9969
- width: Math.min(textWidth + 2 * 6, 200),
9970
- radius: 4,
9971
- fill: color,
9972
- evented: false
9973
- });
9974
- ctx.fillStyle = "rgba(58, 96, 247, 1)";
9975
- const offsetX = 6;
9976
- const offsetY = 18 - 4;
9977
- const maxTextWidth = 200 - 2 * 6;
9978
- if (textWidth > maxTextWidth) {
9979
- let truncatedText = "";
9980
- let currentWidth = 0;
9981
- for (const element of text) {
9982
- const charWidth = ctx.measureText(element).width;
9983
- if (currentWidth + charWidth <= maxTextWidth - ctx.measureText("...").width) {
9984
- truncatedText += element;
9985
- currentWidth += charWidth;
9986
- } else {
9987
- truncatedText += "...";
9988
- break;
9989
- }
9990
- }
9991
- ctx.fillText(truncatedText, offsetX, offsetY);
9992
- } else ctx.fillText(text, offsetX, offsetY);
9993
- ctx.restore();
9994
- }
9995
- _draw(ctx) {
9996
- TextBubbleShape.drawWith(ctx, this);
10149
+ const COMPONENT_DOC_HEADER_FOOTER_PANEL = "COMPONENT_DOC_HEADER_FOOTER_PANEL";
10150
+
10151
+ //#endregion
10152
+ //#region src/commands/operations/doc-header-footer-panel.operation.ts
10153
+ const SidebarDocHeaderFooterPanelOperation = {
10154
+ id: "sidebar.operation.doc-header-footer-panel",
10155
+ type: _univerjs_core.CommandType.OPERATION,
10156
+ handler: async (accessor, params) => {
10157
+ const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
10158
+ const localeService = accessor.get(_univerjs_core.LocaleService);
10159
+ switch (params.value) {
10160
+ case "open":
10161
+ sidebarService.open({
10162
+ header: { title: localeService.t("docs-ui.headerFooter.panel") },
10163
+ children: { label: COMPONENT_DOC_HEADER_FOOTER_PANEL },
10164
+ onClose: () => {},
10165
+ width: 400
10166
+ });
10167
+ break;
10168
+ default:
10169
+ sidebarService.close();
10170
+ break;
10171
+ }
10172
+ return true;
9997
10173
  }
9998
10174
  };
9999
10175
 
10000
10176
  //#endregion
10001
- //#region src/controllers/doc-header-footer.controller.ts
10002
- const HEADER_FOOTER_STROKE_COLOR = "rgba(58, 96, 247, 1)";
10003
- const HEADER_FOOTER_FILL_COLOR = "rgba(58, 96, 247, 0.08)";
10004
- function checkCreateHeaderFooterType(viewModel, editArea, segmentPage) {
10005
- const { documentStyle } = viewModel.getDataModel().getSnapshot();
10006
- const { defaultHeaderId, defaultFooterId, evenPageHeaderId, evenPageFooterId, firstPageHeaderId, firstPageFooterId, evenAndOddHeaders, useFirstPageHeaderFooter } = documentStyle;
10007
- switch (editArea) {
10008
- case _univerjs_engine_render.DocumentEditArea.BODY: return {
10009
- createType: null,
10010
- headerFooterId: null
10011
- };
10012
- case _univerjs_engine_render.DocumentEditArea.HEADER:
10013
- if (useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE && !firstPageHeaderId) return {
10014
- createType: 0,
10015
- headerFooterId: null
10016
- };
10017
- if (evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageHeaderId) return {
10018
- createType: 4,
10019
- headerFooterId: null
10020
- };
10021
- return defaultHeaderId ? {
10022
- createType: null,
10023
- headerFooterId: defaultHeaderId
10024
- } : {
10025
- createType: 2,
10026
- headerFooterId: null
10027
- };
10028
- case _univerjs_engine_render.DocumentEditArea.FOOTER:
10029
- if (useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE && !firstPageFooterId) return {
10030
- createType: 1,
10031
- headerFooterId: null
10032
- };
10033
- if (evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageFooterId) return {
10034
- createType: 5,
10035
- headerFooterId: null
10036
- };
10037
- return defaultFooterId ? {
10038
- createType: null,
10039
- headerFooterId: defaultFooterId
10040
- } : {
10041
- createType: 3,
10042
- headerFooterId: null
10043
- };
10044
- default: throw new Error(`Invalid editArea: ${editArea}`);
10177
+ //#region src/commands/commands/doc-header-footer.command.ts
10178
+ const CoreHeaderFooterCommandId = "doc.command.core-header-footer";
10179
+ /**
10180
+ * The command to update header and footer or create them.
10181
+ */
10182
+ const CoreHeaderFooterCommand = {
10183
+ id: CoreHeaderFooterCommandId,
10184
+ type: _univerjs_core.CommandType.COMMAND,
10185
+ handler: async (accessor, params) => {
10186
+ var _renderManagerService;
10187
+ const commandService = accessor.get(_univerjs_core.ICommandService);
10188
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
10189
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
10190
+ const { unitId, segmentId, createType, headerFooterProps } = params;
10191
+ const docSkeletonManagerService = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService);
10192
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
10193
+ const docViewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10194
+ if (docDataModel == null || docViewModel == null) return false;
10195
+ const editArea = docViewModel.getEditArea();
10196
+ const { documentStyle } = docDataModel.getSnapshot();
10197
+ let resolvedCreateType = createType;
10198
+ if (headerFooterProps != null) Object.keys(headerFooterProps).forEach((key) => {
10199
+ const value = headerFooterProps[key];
10200
+ if (resolvedCreateType == null && key === "useFirstPageHeaderFooter" && value === _univerjs_core.BooleanNumber.TRUE && !documentStyle.firstPageHeaderId) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.FIRST_PAGE_HEADER : _univerjs_docs.HeaderFooterType.FIRST_PAGE_FOOTER;
10201
+ else if (resolvedCreateType == null && key === "evenAndOddHeaders" && value === _univerjs_core.BooleanNumber.TRUE && !documentStyle.evenPageHeaderId) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.EVEN_PAGE_HEADER : _univerjs_docs.HeaderFooterType.EVEN_PAGE_FOOTER;
10202
+ });
10203
+ return commandService.syncExecuteCommand(_univerjs_docs.CreateHeaderFooterCommand.id, {
10204
+ unitId,
10205
+ segmentId,
10206
+ createType: resolvedCreateType,
10207
+ headerFooterProps,
10208
+ createMode: "pair"
10209
+ });
10045
10210
  }
10046
- }
10047
- let DocHeaderFooterController = class DocHeaderFooterController extends _univerjs_core.Disposable {
10048
- constructor(_context, _commandService, _editorService, _instanceSrv, _renderManagerService, _docSkeletonManagerService, _docSelectionRenderService, _localeService) {
10049
- super();
10050
- this._context = _context;
10051
- this._commandService = _commandService;
10052
- this._editorService = _editorService;
10053
- this._instanceSrv = _instanceSrv;
10054
- this._renderManagerService = _renderManagerService;
10055
- this._docSkeletonManagerService = _docSkeletonManagerService;
10056
- this._docSelectionRenderService = _docSelectionRenderService;
10057
- this._localeService = _localeService;
10058
- _defineProperty(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
10059
- this._initialize();
10060
- }
10061
- _initialize() {
10062
- this._init();
10063
- this._drawHeaderFooterLabel();
10064
- this._listenSwitchMode();
10065
- }
10066
- dispose() {
10067
- super.dispose();
10068
- }
10069
- _listenSwitchMode() {
10070
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
10071
- if (_univerjs_docs.RichTextEditingMutation.id === command.id) {
10072
- const docDataModel = this._context.unit;
10073
- const editArea = this._docSkeletonManagerService.getViewModel().getEditArea();
10074
- const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
10075
- if (editArea !== _univerjs_engine_render.DocumentEditArea.BODY && documentFlavor === _univerjs_core.DocumentFlavor.MODERN) this._commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId: this._context.unitId });
10076
- }
10077
- }));
10078
- }
10079
- _init() {
10080
- const { unitId } = this._context;
10081
- const docObject = neoGetDocObject(this._context);
10082
- if (docObject == null || docObject.document == null) return;
10083
- if (!this._loadedMap.has(docObject.document)) {
10084
- this._initialMain(unitId);
10085
- this._loadedMap.add(docObject.document);
10086
- }
10087
- }
10088
- _initialMain(unitId) {
10089
- const { document } = neoGetDocObject(this._context);
10090
- this.disposeWithMe(document.onDblclick$.subscribeEvent(async (evt) => {
10091
- if (this._isEditorReadOnly(unitId)) return;
10092
- if (!this._isTraditionalMode()) return;
10093
- const { offsetX, offsetY } = evt;
10094
- const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = document.getOffsetConfig();
10095
- const coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
10096
- if (coord == null) return;
10097
- const viewModel = this._docSkeletonManagerService.getViewModel();
10098
- const skeleton = this._docSkeletonManagerService.getSkeleton();
10099
- const preEditArea = viewModel.getEditArea();
10100
- const { editArea, pageNumber } = skeleton.findEditAreaByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop);
10101
- if (preEditArea === editArea) return;
10102
- viewModel.setEditArea(editArea);
10103
- const { createType, headerFooterId } = checkCreateHeaderFooterType(viewModel, editArea, pageNumber);
10104
- if (editArea === _univerjs_engine_render.DocumentEditArea.BODY) {
10105
- this._docSelectionRenderService.setSegment("");
10106
- this._docSelectionRenderService.setSegmentPage(-1);
10107
- this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
10108
- } else if (createType != null) {
10109
- const segmentId = (0, _univerjs_core.generateRandomId)(6);
10110
- this._docSelectionRenderService.setSegment(segmentId);
10111
- this._docSelectionRenderService.setSegmentPage(pageNumber);
10112
- await this._commandService.executeCommand(CoreHeaderFooterCommand.id, {
10113
- unitId,
10114
- createType,
10115
- segmentId
10116
- });
10117
- } else if (headerFooterId != null) {
10118
- this._docSelectionRenderService.setSegment(headerFooterId);
10119
- this._docSelectionRenderService.setSegmentPage(pageNumber);
10120
- this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
10121
- }
10122
- }));
10123
- }
10124
- _getTransformCoordForDocumentOffset(evtOffsetX, evtOffsetY) {
10125
- const { document, scene } = neoGetDocObject(this._context);
10126
- const { documentTransform } = document.getOffsetConfig();
10127
- const activeViewport = scene.getViewports()[0];
10128
- if (activeViewport == null) return;
10129
- const originCoord = activeViewport.transformVector2SceneCoord(_univerjs_engine_render.Vector2.FromArray([evtOffsetX, evtOffsetY]));
10130
- return documentTransform.clone().invert().applyPoint(originCoord);
10131
- }
10132
- _drawHeaderFooterLabel() {
10133
- const localeService = this._localeService;
10134
- this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).subscribe((unit) => {
10135
- if (unit == null) return;
10136
- const unitId = unit.getUnitId();
10137
- const currentRender = this._renderManagerService.getRenderById(unitId);
10138
- if (this._editorService.isEditor(unitId) || this._instanceSrv.getUniverDocInstance(unitId) == null) return;
10139
- if (currentRender == null) return;
10140
- const { mainComponent } = currentRender;
10141
- const docsComponent = mainComponent;
10142
- this.disposeWithMe((0, _univerjs_core.toDisposable)(docsComponent.pageRender$.subscribe((config) => {
10143
- if (this._editorService.isEditor(unitId)) return;
10144
- if (!this._isTraditionalMode()) return;
10145
- const isEditBody = this._docSkeletonManagerService.getViewModel().getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY;
10146
- const { page, pageLeft, pageTop, ctx } = config;
10147
- const { pageWidth, pageHeight, marginTop, marginBottom } = page;
10148
- ctx.save();
10149
- ctx.translate(pageLeft - .5, pageTop - .5);
10150
- if (isEditBody) {
10151
- _univerjs_engine_render.Rect.drawWith(ctx, {
10152
- left: 0,
10153
- top: 0,
10154
- width: pageWidth,
10155
- height: marginTop,
10156
- fill: "rgba(255, 255, 255, 0.5)"
10157
- });
10158
- ctx.save();
10159
- ctx.translate(0, pageHeight - marginBottom);
10160
- _univerjs_engine_render.Rect.drawWith(ctx, {
10161
- left: 0,
10162
- top: 0,
10163
- width: pageWidth,
10164
- height: marginBottom,
10165
- fill: "rgba(255, 255, 255, 0.5)"
10166
- });
10167
- ctx.restore();
10168
- } else {
10169
- ctx.save();
10170
- ctx.translate(0, marginTop);
10171
- _univerjs_engine_render.Rect.drawWith(ctx, {
10172
- left: 0,
10173
- top: marginTop,
10174
- width: pageWidth,
10175
- height: pageHeight - marginTop - marginBottom,
10176
- fill: "rgba(255, 255, 255, 0.5)"
10177
- });
10178
- ctx.restore();
10179
- }
10180
- if (!isEditBody) {
10181
- const headerPathConfigIPathProps = {
10182
- dataArray: [{
10183
- command: "M",
10184
- points: [0, marginTop]
10185
- }, {
10186
- command: "L",
10187
- points: [pageWidth, marginTop]
10188
- }],
10189
- strokeWidth: 1,
10190
- stroke: HEADER_FOOTER_STROKE_COLOR
10191
- };
10192
- const footerPathConfigIPathProps = {
10193
- dataArray: [{
10194
- command: "M",
10195
- points: [0, pageHeight - marginBottom]
10196
- }, {
10197
- command: "L",
10198
- points: [pageWidth, pageHeight - marginBottom]
10199
- }],
10200
- strokeWidth: 1,
10201
- stroke: HEADER_FOOTER_STROKE_COLOR
10202
- };
10203
- _univerjs_engine_render.Path.drawWith(ctx, headerPathConfigIPathProps);
10204
- _univerjs_engine_render.Path.drawWith(ctx, footerPathConfigIPathProps);
10205
- ctx.translate(0, marginTop + 1);
10206
- TextBubbleShape.drawWith(ctx, {
10207
- text: localeService.t("docs-ui.headerFooter.header"),
10208
- color: HEADER_FOOTER_FILL_COLOR
10209
- });
10210
- ctx.translate(0, pageHeight - marginTop - marginBottom);
10211
- TextBubbleShape.drawWith(ctx, {
10212
- text: localeService.t("docs-ui.headerFooter.footer"),
10213
- color: HEADER_FOOTER_FILL_COLOR
10214
- });
10215
- }
10216
- ctx.restore();
10217
- })));
10218
- }));
10219
- }
10220
- _isEditorReadOnly(unitId) {
10221
- const editor = this._editorService.getEditor(unitId);
10222
- if (!editor) return false;
10223
- return editor.isReadOnly();
10211
+ };
10212
+ const OpenHeaderFooterPanelCommand = {
10213
+ id: "doc.command.open-header-footer-panel",
10214
+ type: _univerjs_core.CommandType.COMMAND,
10215
+ handler: async (accessor, _params) => {
10216
+ return accessor.get(_univerjs_core.ICommandService).executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "open" });
10224
10217
  }
10225
- _isTraditionalMode() {
10226
- return this._context.unit.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL;
10218
+ };
10219
+ const CloseHeaderFooterCommand = {
10220
+ id: "doc.command.close-header-footer",
10221
+ type: _univerjs_core.CommandType.COMMAND,
10222
+ handler: async (accessor, params) => {
10223
+ var _params$unitId, _instanceService$getC, _renderObject$mainCom;
10224
+ const commandService = accessor.get(_univerjs_core.ICommandService);
10225
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
10226
+ const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
10227
+ const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
10228
+ const unitId = (_params$unitId = params === null || params === void 0 ? void 0 : params.unitId) !== null && _params$unitId !== void 0 ? _params$unitId : (_instanceService$getC = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _instanceService$getC === void 0 ? void 0 : _instanceService$getC.getUnitId();
10229
+ if (unitId == null) return false;
10230
+ const renderObject = renderManagerService.getRenderById(unitId);
10231
+ if (renderObject == null) return false;
10232
+ const docSkeletonManagerService = renderObject.with(_univerjs_docs.DocSkeletonManagerService);
10233
+ const viewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10234
+ if (viewModel == null) return false;
10235
+ if (viewModel.getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY) return false;
10236
+ const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
10237
+ if (skeleton == null) return false;
10238
+ const { scene } = renderObject;
10239
+ const transformer = scene.getTransformerByCreate();
10240
+ const docSelectionRenderService = renderObject.with(DocSelectionRenderService);
10241
+ docSelectionManagerService.replaceDocRanges([]);
10242
+ transformer.clearSelectedObjects();
10243
+ docSelectionRenderService.setSegment("");
10244
+ docSelectionRenderService.setSegmentPage(-1);
10245
+ viewModel.setEditArea(_univerjs_engine_render.DocumentEditArea.BODY);
10246
+ skeleton.calculate();
10247
+ (_renderObject$mainCom = renderObject.mainComponent) === null || _renderObject$mainCom === void 0 || _renderObject$mainCom.makeDirty(true);
10248
+ queueMicrotask(() => {
10249
+ const docDataModel = instanceService.getUnit(unitId);
10250
+ const snapshot = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot();
10251
+ if (snapshot == null) return;
10252
+ const offset = findFirstCursorOffset(snapshot);
10253
+ docSelectionManagerService.replaceDocRanges([{
10254
+ startOffset: offset,
10255
+ endOffset: offset
10256
+ }]);
10257
+ });
10258
+ commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "close" });
10259
+ return true;
10227
10260
  }
10228
10261
  };
10229
- DocHeaderFooterController = __decorate([
10230
- __decorateParam(1, _univerjs_core.ICommandService),
10231
- __decorateParam(2, IEditorService),
10232
- __decorateParam(3, _univerjs_core.IUniverInstanceService),
10233
- __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
10234
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
10235
- __decorateParam(6, (0, _univerjs_core.Inject)(DocSelectionRenderService)),
10236
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
10237
- ], DocHeaderFooterController);
10238
10262
 
10239
10263
  //#endregion
10240
- //#region src/views/header-footer/panel/component-name.ts
10264
+ //#region src/controllers/doc-paragraph-setting.controller.ts
10241
10265
  /**
10242
10266
  * Copyright 2023-present DreamNum Co., Ltd.
10243
10267
  *
@@ -10253,253 +10277,28 @@ DocHeaderFooterController = __decorate([
10253
10277
  * See the License for the specific language governing permissions and
10254
10278
  * limitations under the License.
10255
10279
  */
10256
- const COMPONENT_DOC_HEADER_FOOTER_PANEL = "COMPONENT_DOC_HEADER_FOOTER_PANEL";
10257
-
10258
- //#endregion
10259
- //#region src/commands/operations/doc-header-footer-panel.operation.ts
10260
- const SidebarDocHeaderFooterPanelOperation = {
10261
- id: "sidebar.operation.doc-header-footer-panel",
10262
- type: _univerjs_core.CommandType.OPERATION,
10263
- handler: async (accessor, params) => {
10264
- const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
10265
- const localeService = accessor.get(_univerjs_core.LocaleService);
10266
- switch (params.value) {
10267
- case "open":
10268
- sidebarService.open({
10269
- header: { title: localeService.t("docs-ui.headerFooter.panel") },
10270
- children: { label: COMPONENT_DOC_HEADER_FOOTER_PANEL },
10271
- onClose: () => {},
10272
- width: 400
10273
- });
10274
- break;
10275
- default:
10276
- sidebarService.close();
10277
- break;
10278
- }
10279
- return true;
10280
- }
10281
- };
10282
-
10283
- //#endregion
10284
- //#region src/commands/commands/doc-header-footer.command.ts
10285
- function getEmptyHeaderFooterBody() {
10286
- return {
10287
- dataStream: "\r\n",
10288
- textRuns: [{
10289
- st: 0,
10290
- ed: 0,
10291
- ts: { fs: 9 }
10292
- }],
10293
- customBlocks: [],
10294
- paragraphs: [{
10295
- startIndex: 0,
10296
- paragraphId: (0, _univerjs_core.createParagraphId)(/* @__PURE__ */ new Set()),
10297
- paragraphStyle: {
10298
- spaceAbove: { v: 0 },
10299
- lineSpacing: 1.5,
10300
- spaceBelow: { v: 0 }
10301
- }
10302
- }],
10303
- sectionBreaks: [{ startIndex: 1 }]
10304
- };
10305
- }
10306
- function createHeaderFooterAction(segmentId, createType, documentStyle, actions) {
10307
- const jsonX = _univerjs_core.JSONX.getInstance();
10308
- const ID_LEN = 6;
10309
- const firstSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : (0, _univerjs_core.generateRandomId)(ID_LEN);
10310
- const isHeader = createType === 2 || createType === 0 || createType === 4;
10311
- const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
10312
- [isHeader ? "headerId" : "footerId"]: firstSegmentId,
10313
- body: getEmptyHeaderFooterBody()
10314
- });
10315
- actions.push(insertAction);
10316
- const secondSegmentId = (0, _univerjs_core.generateRandomId)(ID_LEN);
10317
- const insertPairAction = jsonX.insertOp([isHeader ? "footers" : "headers", secondSegmentId], {
10318
- [isHeader ? "footerId" : "headerId"]: secondSegmentId,
10319
- body: getEmptyHeaderFooterBody()
10320
- });
10321
- actions.push(insertPairAction);
10322
- let key = "defaultHeaderId";
10323
- let pairKey = "defaultFooterId";
10324
- switch (createType) {
10325
- case 2:
10326
- key = "defaultHeaderId";
10327
- pairKey = "defaultFooterId";
10328
- break;
10329
- case 3:
10330
- key = "defaultFooterId";
10331
- pairKey = "defaultHeaderId";
10332
- break;
10333
- case 0:
10334
- key = "firstPageHeaderId";
10335
- pairKey = "firstPageFooterId";
10336
- break;
10337
- case 1:
10338
- key = "firstPageFooterId";
10339
- pairKey = "firstPageHeaderId";
10340
- break;
10341
- case 4:
10342
- key = "evenPageHeaderId";
10343
- pairKey = "evenPageFooterId";
10344
- break;
10345
- case 5:
10346
- key = "evenPageFooterId";
10347
- pairKey = "evenPageHeaderId";
10348
- break;
10349
- default: throw new Error(`Unknown header footer type: ${createType}`);
10350
- }
10351
- for (const [k, id] of [[key, firstSegmentId], [pairKey, secondSegmentId]]) if (documentStyle[k] != null) {
10352
- const replaceAction = jsonX.replaceOp(["documentStyle", k], documentStyle[k], id);
10353
- actions.push(replaceAction);
10354
- } else {
10355
- const insertAction = jsonX.insertOp(["documentStyle", k], id);
10356
- actions.push(insertAction);
10357
- }
10358
- return actions;
10359
- }
10360
- const CoreHeaderFooterCommandId = "doc.command.core-header-footer";
10361
- /**
10362
- * The command to update header and footer or create them.
10363
- */
10364
- const CoreHeaderFooterCommand = {
10365
- id: CoreHeaderFooterCommandId,
10366
- type: _univerjs_core.CommandType.COMMAND,
10367
- handler: async (accessor, params) => {
10368
- var _renderManagerService;
10369
- const commandService = accessor.get(_univerjs_core.ICommandService);
10370
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
10371
- const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
10372
- const { unitId, segmentId, createType, headerFooterProps } = params;
10373
- const docSkeletonManagerService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService);
10374
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
10375
- const docViewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10376
- if (docDataModel == null || docViewModel == null) return false;
10377
- const editArea = docViewModel.getEditArea();
10378
- const { documentStyle } = docDataModel.getSnapshot();
10379
- const isUpdateMargin = (headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginFooter) != null || (headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginHeader) != null;
10380
- const doMutation = {
10381
- id: _univerjs_docs.RichTextEditingMutation.id,
10382
- params: {
10383
- unitId,
10384
- actions: [],
10385
- textRanges: [{
10386
- startOffset: 0,
10387
- endOffset: 0,
10388
- collapsed: true
10389
- }],
10390
- debounce: true
10391
- }
10392
- };
10393
- if (isUpdateMargin) doMutation.params.noNeedSetTextRange = true;
10394
- const jsonX = _univerjs_core.JSONX.getInstance();
10395
- const rawActions = [];
10396
- if (createType != null) createHeaderFooterAction(segmentId, createType, documentStyle, rawActions);
10397
- if (headerFooterProps != null) Object.keys(headerFooterProps).forEach((key) => {
10398
- const value = headerFooterProps[key];
10399
- const oldValue = documentStyle[key];
10400
- if (value === oldValue) return;
10401
- let action;
10402
- if (oldValue === void 0) action = jsonX.insertOp(["documentStyle", key], value);
10403
- else action = jsonX.replaceOp(["documentStyle", key], oldValue, value);
10404
- rawActions.push(action);
10405
- if (key === "useFirstPageHeaderFooter" && value === _univerjs_core.BooleanNumber.TRUE && !documentStyle.firstPageHeaderId) createHeaderFooterAction(segmentId, editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? 0 : 1, documentStyle, rawActions);
10406
- else if (key === "evenAndOddHeaders" && value === _univerjs_core.BooleanNumber.TRUE && !documentStyle.evenPageHeaderId) createHeaderFooterAction(segmentId, editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? 4 : 5, documentStyle, rawActions);
10407
- });
10408
- if (rawActions.length === 0) return false;
10409
- doMutation.params.actions = rawActions.reduce((acc, cur) => {
10410
- return _univerjs_core.JSONX.compose(acc, cur);
10411
- }, null);
10412
- const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
10413
- return Boolean(result);
10414
- }
10415
- };
10416
- const OpenHeaderFooterPanelCommand = {
10417
- id: "doc.command.open-header-footer-panel",
10418
- type: _univerjs_core.CommandType.COMMAND,
10419
- handler: async (accessor, _params) => {
10420
- return accessor.get(_univerjs_core.ICommandService).executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "open" });
10421
- }
10422
- };
10423
- const CloseHeaderFooterCommand = {
10424
- id: "doc.command.close-header-footer",
10425
- type: _univerjs_core.CommandType.COMMAND,
10426
- handler: async (accessor, params) => {
10427
- var _renderObject$mainCom;
10428
- const commandService = accessor.get(_univerjs_core.ICommandService);
10429
- const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
10430
- const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
10431
- const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
10432
- const { unitId } = params;
10433
- const renderObject = renderManagerService.getRenderById(unitId);
10434
- if (renderObject == null) return false;
10435
- const { scene } = renderObject;
10436
- const transformer = scene.getTransformerByCreate();
10437
- const docSkeletonManagerService = renderObject.with(_univerjs_docs.DocSkeletonManagerService);
10438
- const docSelectionRenderService = renderObject.with(DocSelectionRenderService);
10439
- const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
10440
- const viewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10441
- if (viewModel == null || skeleton == null) return false;
10442
- docSelectionManagerService.replaceDocRanges([]);
10443
- transformer.clearSelectedObjects();
10444
- docSelectionRenderService.setSegment("");
10445
- docSelectionRenderService.setSegmentPage(-1);
10446
- viewModel.setEditArea(_univerjs_engine_render.DocumentEditArea.BODY);
10447
- skeleton.calculate();
10448
- (_renderObject$mainCom = renderObject.mainComponent) === null || _renderObject$mainCom === void 0 || _renderObject$mainCom.makeDirty(true);
10449
- queueMicrotask(() => {
10450
- const docDataModel = instanceService.getUnit(unitId);
10451
- const snapshot = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot();
10452
- if (snapshot == null) return;
10453
- const offset = findFirstCursorOffset(snapshot);
10454
- docSelectionManagerService.replaceDocRanges([{
10455
- startOffset: offset,
10456
- endOffset: offset
10457
- }]);
10458
- });
10459
- commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "close" });
10460
- return true;
10461
- }
10462
- };
10463
-
10464
- //#endregion
10465
- //#region src/controllers/doc-paragraph-setting.controller.ts
10466
- /**
10467
- * Copyright 2023-present DreamNum Co., Ltd.
10468
- *
10469
- * Licensed under the Apache License, Version 2.0 (the "License");
10470
- * you may not use this file except in compliance with the License.
10471
- * You may obtain a copy of the License at
10472
- *
10473
- * http://www.apache.org/licenses/LICENSE-2.0
10474
- *
10475
- * Unless required by applicable law or agreed to in writing, software
10476
- * distributed under the License is distributed on an "AS IS" BASIS,
10477
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10478
- * See the License for the specific language governing permissions and
10479
- * limitations under the License.
10480
- */
10481
- const paragraphSettingIndexKey$1 = "doc_ui_paragraph-setting-panel";
10482
- let DocParagraphSettingController = class DocParagraphSettingController extends _univerjs_core.Disposable {
10483
- constructor(_commandService, _sidebarService) {
10484
- super();
10485
- this._commandService = _commandService;
10486
- this._sidebarService = _sidebarService;
10487
- _defineProperty(this, "_id", void 0);
10488
- }
10489
- openPanel() {
10490
- const props = {
10491
- header: { title: "docs-ui.doc.slider.paragraphSetting" },
10492
- id: this._id,
10493
- children: { label: paragraphSettingIndexKey$1 },
10494
- width: 300
10495
- };
10496
- this._sidebarService.open(props);
10497
- }
10498
- closePanel() {
10499
- this._sidebarService.close(this._id);
10500
- }
10501
- };
10502
- DocParagraphSettingController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService))], DocParagraphSettingController);
10280
+ const paragraphSettingIndexKey$1 = "doc_ui_paragraph-setting-panel";
10281
+ let DocParagraphSettingController = class DocParagraphSettingController extends _univerjs_core.Disposable {
10282
+ constructor(_commandService, _sidebarService) {
10283
+ super();
10284
+ this._commandService = _commandService;
10285
+ this._sidebarService = _sidebarService;
10286
+ _defineProperty(this, "_id", void 0);
10287
+ }
10288
+ openPanel() {
10289
+ const props = {
10290
+ header: { title: "docs-ui.doc.slider.paragraphSetting" },
10291
+ id: this._id,
10292
+ children: { label: paragraphSettingIndexKey$1 },
10293
+ width: 300
10294
+ };
10295
+ this._sidebarService.open(props);
10296
+ }
10297
+ closePanel() {
10298
+ this._sidebarService.close(this._id);
10299
+ }
10300
+ };
10301
+ DocParagraphSettingController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService))], DocParagraphSettingController);
10503
10302
 
10504
10303
  //#endregion
10505
10304
  //#region src/commands/operations/doc-paragraph-setting-panel.operation.ts
@@ -10909,8 +10708,12 @@ function notInTableSubscriber(subscriber, docSelectionManagerService, univerInst
10909
10708
  if (activeRange && (rectRanges == null || rectRanges.length === 0)) {
10910
10709
  var _docDataModel$getSelf;
10911
10710
  const { segmentId, startOffset, endOffset } = activeRange;
10912
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
10913
- const tables = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.tables;
10711
+ if (!(activeRange.collapsed === true || startOffset === endOffset)) {
10712
+ subscriber.next(true);
10713
+ return;
10714
+ }
10715
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
10716
+ const tables = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 || (_docDataModel$getSelf = _docDataModel$getSelf.getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.tables;
10914
10717
  if (tables && tables.length) {
10915
10718
  if (tables.some((table) => {
10916
10719
  const { startIndex, endIndex } = table;
@@ -11236,6 +11039,46 @@ function getInsertTableHiddenObservable(accessor) {
11236
11039
  return () => subscription.unsubscribe();
11237
11040
  });
11238
11041
  }
11042
+ function disableMenuWhenHeaderFooterEditing(accessor) {
11043
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
11044
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
11045
+ return new rxjs.Observable((subscriber) => {
11046
+ let editAreaSubscription = null;
11047
+ let lastDisabled;
11048
+ const emit = (disabled) => {
11049
+ if (disabled !== lastDisabled) {
11050
+ lastDisabled = disabled;
11051
+ subscriber.next(disabled);
11052
+ }
11053
+ };
11054
+ const emitByUnit = (unitId) => {
11055
+ editAreaSubscription === null || editAreaSubscription === void 0 || editAreaSubscription.unsubscribe();
11056
+ editAreaSubscription = null;
11057
+ if (!unitId || univerInstanceService.getUnitType(unitId) !== _univerjs_core.UniverInstanceType.UNIVER_DOC) {
11058
+ emit(true);
11059
+ return;
11060
+ }
11061
+ const currentRender = renderManagerService.getRenderById(unitId);
11062
+ const skeletonManager = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService);
11063
+ const viewModel = skeletonManager === null || skeletonManager === void 0 ? void 0 : skeletonManager.getViewModel();
11064
+ if (!viewModel) {
11065
+ emit(true);
11066
+ return;
11067
+ }
11068
+ const emitDisabled = (editArea) => {
11069
+ const currentEditArea = editArea !== null && editArea !== void 0 ? editArea : viewModel.getEditArea();
11070
+ emit(currentEditArea === _univerjs_engine_render.DocumentEditArea.HEADER || currentEditArea === _univerjs_engine_render.DocumentEditArea.FOOTER);
11071
+ };
11072
+ emitDisabled();
11073
+ editAreaSubscription = viewModel.editAreaChange$.subscribe(emitDisabled);
11074
+ };
11075
+ const focusedSubscription = univerInstanceService.focused$.subscribe(emitByUnit);
11076
+ return () => {
11077
+ editAreaSubscription === null || editAreaSubscription === void 0 || editAreaSubscription.unsubscribe();
11078
+ focusedSubscription.unsubscribe();
11079
+ };
11080
+ });
11081
+ }
11239
11082
  function getHeaderFooterMenuHiddenObservable(accessor) {
11240
11083
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
11241
11084
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -11254,11 +11097,11 @@ function getHeaderFooterMenuHiddenObservable(accessor) {
11254
11097
  });
11255
11098
  const subscription = univerInstanceService.focused$.subscribe((unitId) => {
11256
11099
  if (unitId == null) return subscriber.next(true);
11257
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
11100
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
11258
11101
  const documentFlavor = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle.documentFlavor;
11259
11102
  subscriber.next(documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL);
11260
11103
  });
11261
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
11104
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
11262
11105
  if (docDataModel == null) return subscriber.next(true);
11263
11106
  const documentFlavor = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle.documentFlavor;
11264
11107
  subscriber.next(documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL);
@@ -11287,7 +11130,7 @@ function getTableDisabledObservable(accessor) {
11287
11130
  subscriber.next(true);
11288
11131
  return;
11289
11132
  }
11290
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
11133
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
11291
11134
  if (docDataModel == null) {
11292
11135
  subscriber.next(true);
11293
11136
  return;
@@ -12010,14 +11853,14 @@ const listValueFactory$ = (accessor) => {
12010
11853
  const subscription = univerInstanceService.focused$.subscribe((unitId) => {
12011
11854
  var _docRanges$find;
12012
11855
  if (unitId == null) return;
12013
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
11856
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
12014
11857
  if (docDataModel == null) return;
12015
11858
  const docRanges = docSelectionManagerService.getDocRanges();
12016
11859
  const range = (_docRanges$find = docRanges.find((r) => r.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
12017
11860
  if (range) {
12018
11861
  var _doc$getBody$paragrap, _doc$getBody, _doc$getBody$dataStre, _doc$getBody2;
12019
11862
  const doc = docDataModel.getSelfOrHeaderFooterModel(range === null || range === void 0 ? void 0 : range.segmentId);
12020
- const paragraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, (_doc$getBody$paragrap = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) !== null && _doc$getBody$paragrap !== void 0 ? _doc$getBody$paragrap : [], (_doc$getBody$dataStre = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "");
11863
+ const paragraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, (_doc$getBody$paragrap = doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) !== null && _doc$getBody$paragrap !== void 0 ? _doc$getBody$paragrap : [], (_doc$getBody$dataStre = doc === null || doc === void 0 || (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "");
12021
11864
  let listType;
12022
11865
  if (paragraphs.every((p) => {
12023
11866
  if (!listType) {
@@ -12177,7 +12020,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
12177
12020
  };
12178
12021
  }
12179
12022
  function getFontStyleAtCursor(accessor) {
12180
- var _docRanges$find2, _docMenuStyleService$, _paragraph$paragraphS11, _paragraph$paragraphS12;
12023
+ var _docRanges$find2, _docMenuStyleService$, _paragraph$paragraphS11, _paragraph$paragraphS12, _docDataModel$getSelf;
12181
12024
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12182
12025
  const textSelectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
12183
12026
  const docMenuStyleService = accessor.get(DocMenuStyleService);
@@ -12194,7 +12037,7 @@ function getFontStyleAtCursor(accessor) {
12194
12037
  ...cacheStyle
12195
12038
  } };
12196
12039
  const { segmentId } = activeRange;
12197
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
12040
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
12198
12041
  if (body == null) return { ts: {
12199
12042
  ...defaultTextStyle,
12200
12043
  ...namedStyle,
@@ -12210,15 +12053,15 @@ function getFontStyleAtCursor(accessor) {
12210
12053
  } };
12211
12054
  }
12212
12055
  function getParagraphStyleAtCursor(accessor) {
12213
- var _docRanges$find3, _docDataModel$getSelf;
12056
+ var _docRanges$find3, _docDataModel$getSelf2;
12214
12057
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12215
12058
  const textSelectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
12216
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
12059
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
12217
12060
  const docRanges = textSelectionService.getDocRanges();
12218
12061
  const activeRange = (_docRanges$find3 = docRanges.find((r) => r.isActive)) !== null && _docRanges$find3 !== void 0 ? _docRanges$find3 : docRanges[0];
12219
12062
  if (docDataModel == null || activeRange == null) return;
12220
12063
  const { startOffset, segmentId } = activeRange;
12221
- const paragraphs = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.paragraphs;
12064
+ const paragraphs = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 || (_docDataModel$getSelf2 = _docDataModel$getSelf2.getBody()) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.paragraphs;
12222
12065
  if (paragraphs == null) return;
12223
12066
  let prevIndex = -1;
12224
12067
  for (const paragraph of paragraphs) {
@@ -12659,7 +12502,6 @@ function ParagraphMenuInsertBelowHeadingH1MenuItemFactory(accessor) {
12659
12502
  tooltip: "docs-ui.toolbar.heading.leading1",
12660
12503
  params: {
12661
12504
  commandId: H1HeadingCommand.id,
12662
- paragraphMenuPlacement: "below",
12663
12505
  paragraphMenuInsertMode: "breakline"
12664
12506
  },
12665
12507
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12675,7 +12517,6 @@ function ParagraphMenuInsertBelowHeadingH2MenuItemFactory(accessor) {
12675
12517
  tooltip: "docs-ui.toolbar.heading.leading2",
12676
12518
  params: {
12677
12519
  commandId: H2HeadingCommand.id,
12678
- paragraphMenuPlacement: "below",
12679
12520
  paragraphMenuInsertMode: "breakline"
12680
12521
  },
12681
12522
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12691,7 +12532,6 @@ function ParagraphMenuInsertBelowHeadingH3MenuItemFactory(accessor) {
12691
12532
  tooltip: "docs-ui.toolbar.heading.leading3",
12692
12533
  params: {
12693
12534
  commandId: H3HeadingCommand.id,
12694
- paragraphMenuPlacement: "below",
12695
12535
  paragraphMenuInsertMode: "breakline"
12696
12536
  },
12697
12537
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12707,7 +12547,6 @@ function ParagraphMenuInsertBelowHeadingH4MenuItemFactory(accessor) {
12707
12547
  tooltip: "docs-ui.toolbar.heading.leading4",
12708
12548
  params: {
12709
12549
  commandId: H4HeadingCommand.id,
12710
- paragraphMenuPlacement: "below",
12711
12550
  paragraphMenuInsertMode: "breakline"
12712
12551
  },
12713
12552
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12723,7 +12562,6 @@ function ParagraphMenuInsertBelowHeadingH5MenuItemFactory(accessor) {
12723
12562
  tooltip: "docs-ui.toolbar.heading.leading5",
12724
12563
  params: {
12725
12564
  commandId: H5HeadingCommand.id,
12726
- paragraphMenuPlacement: "below",
12727
12565
  paragraphMenuInsertMode: "breakline"
12728
12566
  },
12729
12567
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12739,8 +12577,7 @@ function ParagraphMenuInsertBelowTableMenuItemFactory(accessor) {
12739
12577
  tooltip: "docs-ui.toolbar.table.insert",
12740
12578
  params: {
12741
12579
  rowCount: 3,
12742
- colCount: 5,
12743
- paragraphMenuPlacement: "below"
12580
+ colCount: 5
12744
12581
  },
12745
12582
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
12746
12583
  };
@@ -14025,6 +13862,50 @@ const calcDocParagraphPositions = (sections, top, left, pageWidth) => {
14025
13862
  }
14026
13863
  return paragraphBounds;
14027
13864
  };
13865
+ const calcParagraphPositionsFromLineContexts = (contexts, docsLeft, docsTop) => {
13866
+ const paragraphBounds = [];
13867
+ const currentParagraphs = /* @__PURE__ */ new Map();
13868
+ for (const context of contexts) {
13869
+ const { column, line, lineWidth, pageLeft, sectionTop } = context;
13870
+ const startIndex = line.paragraphIndex;
13871
+ const columnLeft = pageLeft + column.left + docsLeft;
13872
+ const lineTop = sectionTop + line.top + docsTop;
13873
+ const lineBottom = getParagraphLineBottom(context, lineTop);
13874
+ const key = `${context.source}:${context.pageIndex}:${pageLeft}:${column.left}:${startIndex}`;
13875
+ if (line.paragraphStart) {
13876
+ const currentParagraph = currentParagraphs.get(key);
13877
+ if (currentParagraph) paragraphBounds.push(currentParagraph);
13878
+ currentParagraphs.set(key, {
13879
+ paragraphStart: line.st,
13880
+ paragraphEnd: startIndex,
13881
+ startIndex,
13882
+ rect: {
13883
+ top: lineTop,
13884
+ left: columnLeft,
13885
+ right: columnLeft + lineWidth,
13886
+ bottom: lineBottom
13887
+ },
13888
+ fisrtLine: {
13889
+ top: lineTop + line.marginTop + line.paddingTop,
13890
+ left: columnLeft,
13891
+ right: columnLeft + lineWidth,
13892
+ bottom: lineTop + line.marginTop + line.paddingTop + line.contentHeight
13893
+ }
13894
+ });
13895
+ } else {
13896
+ const currentParagraph = currentParagraphs.get(key);
13897
+ if (currentParagraph) currentParagraph.rect.bottom = lineBottom;
13898
+ }
13899
+ }
13900
+ paragraphBounds.push(...currentParagraphs.values());
13901
+ return paragraphBounds;
13902
+ };
13903
+ function getParagraphLineBottom(context, lineTop) {
13904
+ const lineBottom = lineTop + context.line.lineHeight;
13905
+ if (context.source !== "column" || context.line !== context.column.lines.at(-1) || !Number.isFinite(context.page.pageHeight)) return lineBottom;
13906
+ const pageTop = lineTop - context.line.top - context.section.top;
13907
+ return Math.max(lineBottom, pageTop + context.page.pageHeight);
13908
+ }
14028
13909
  const calcDocGlyphPosition = (glyph, documents, skeleton, pageIndex = -1) => {
14029
13910
  const start = skeleton.findPositionByGlyph(glyph, pageIndex);
14030
13911
  if (!start) return;
@@ -14076,6 +13957,21 @@ function isPointInRect(x, y, rect) {
14076
13957
  if (x >= left && x <= right && y >= top && y <= bottom) return true;
14077
13958
  return false;
14078
13959
  }
13960
+ function getRectArea(rect) {
13961
+ return Math.max(0, rect.right - rect.left) * Math.max(0, rect.bottom - rect.top);
13962
+ }
13963
+ function isRectContainingRect(outer, inner) {
13964
+ return outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
13965
+ }
13966
+ function getParagraphTextRangeLength(bound) {
13967
+ return Math.max(0, bound.paragraphEnd - bound.paragraphStart);
13968
+ }
13969
+ function getMostSpecificParagraphBound(bounds) {
13970
+ return bounds.sort((left, right) => getRectArea(left.rect) - getRectArea(right.rect) || getParagraphTextRangeLength(left) - getParagraphTextRangeLength(right))[0];
13971
+ }
13972
+ function removeContainerParagraphBounds(bounds) {
13973
+ return bounds.filter((bound) => !bounds.some((other) => other !== bound && getRectArea(other.rect) < getRectArea(bound.rect) && isRectContainingRect(bound.rect, other.rect)));
13974
+ }
14079
13975
  function getTableBlockMenuHoverRect(tableRect) {
14080
13976
  return {
14081
13977
  bottom: tableRect.bottom,
@@ -14185,7 +14081,10 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14185
14081
  }));
14186
14082
  }
14187
14083
  _initEvents() {
14188
- this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.scene.onPointerMove$).pipe((0, rxjs.throttleTime)(30)).subscribe((evt) => {
14084
+ this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.scene.onPointerMove$).pipe((0, rxjs.throttleTime)(30, void 0, {
14085
+ leading: true,
14086
+ trailing: true
14087
+ })).subscribe((evt) => {
14189
14088
  if (evt.buttons > 0) {
14190
14089
  this._hoverBullet$.next(null);
14191
14090
  this._hoverCustomRanges$.next([]);
@@ -14379,9 +14278,9 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14379
14278
  if (!skeletonData) return null;
14380
14279
  const calc = (pages) => {
14381
14280
  const paragraphMap = /* @__PURE__ */ new Map();
14382
- const handlePage = (page, pageIndex, top, left) => {
14383
- calcDocParagraphPositions(page.sections, top, left, page.pageWidth - page.marginLeft - page.marginRight).forEach((bound) => {
14384
- if (!paragraphMap.has(bound.startIndex)) paragraphMap.set(bound.startIndex, {
14281
+ const addParagraphBoundsToMap = (map, bounds, pageIndex, segmentId) => {
14282
+ bounds.forEach((bound) => {
14283
+ if (!map.has(bound.startIndex)) map.set(bound.startIndex, {
14385
14284
  rect: bound.rect,
14386
14285
  paragraphStart: bound.paragraphStart,
14387
14286
  paragraphEnd: bound.paragraphEnd,
@@ -14392,7 +14291,7 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14392
14291
  firstLine: bound.fisrtLine
14393
14292
  });
14394
14293
  else {
14395
- const current = paragraphMap.get(bound.startIndex);
14294
+ const current = map.get(bound.startIndex);
14396
14295
  if (current) {
14397
14296
  current.rect.bottom = bound.rect.bottom;
14398
14297
  current.rects.push(bound.rect);
@@ -14400,76 +14299,73 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14400
14299
  }
14401
14300
  });
14402
14301
  };
14403
- for (let i = 0; i < pages.length; i++) {
14404
- const page = pages[i];
14405
- const top = ((page.pageHeight === Infinity ? 0 : page.pageHeight) + documentOffsetConfig.pageMarginTop) * i + page.marginTop + documentOffsetConfig.docsTop;
14406
- const left = page.marginLeft + documentOffsetConfig.docsLeft;
14407
- if (page.skeTables) Array.from(page.skeTables.values()).forEach((table) => {
14408
- const tableLeft = table.left + left;
14409
- const tableTop = table.top + top;
14410
- const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(table.tableId).tableId;
14411
- const tableViewport = getTableHorizontalViewportGeometry(tableLeft, table.width, (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, sourceTableId));
14412
- const tableRight = tableViewport.visibleRight;
14413
- const tableBottom = tableTop + table.height;
14414
- const tableId = table.tableId;
14415
- this._tableBounds.set(tableId, {
14416
- rect: {
14417
- left: tableLeft,
14418
- top: tableTop,
14419
- right: tableRight,
14420
- bottom: tableBottom
14421
- },
14422
- pageIndex: i,
14302
+ const lineContextsBySource = /* @__PURE__ */ new Map();
14303
+ (0, _univerjs_engine_render.documentSkeletonLineIterator)(pages, {
14304
+ docsLeft: documentOffsetConfig.docsLeft,
14305
+ pageMarginTop: documentOffsetConfig.pageMarginTop,
14306
+ unitId: this._context.unitId
14307
+ }, (context) => {
14308
+ var _lineContextsBySource;
14309
+ if (context.source === "table-cell") return;
14310
+ const lineContexts = (_lineContextsBySource = lineContextsBySource.get(context.pageIndex)) !== null && _lineContextsBySource !== void 0 ? _lineContextsBySource : [];
14311
+ lineContexts.push(context);
14312
+ lineContextsBySource.set(context.pageIndex, lineContexts);
14313
+ });
14314
+ lineContextsBySource.forEach((contexts, pageIndex) => {
14315
+ addParagraphBoundsToMap(paragraphMap, calcParagraphPositionsFromLineContexts(contexts, documentOffsetConfig.docsLeft, documentOffsetConfig.docsTop), pageIndex, segmentId);
14316
+ });
14317
+ for (const tableContext of (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
14318
+ docsLeft: documentOffsetConfig.docsLeft,
14319
+ docsTop: documentOffsetConfig.docsTop,
14320
+ pageMarginTop: documentOffsetConfig.pageMarginTop,
14321
+ unitId: this._context.unitId
14322
+ })) {
14323
+ const tableId = tableContext.tableId;
14324
+ const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
14325
+ const tableViewport = getTableHorizontalViewportGeometry(tableContext.tableRect.left, tableContext.table.width, (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, sourceTableId));
14326
+ this._tableBounds.set(tableId, {
14327
+ rect: {
14328
+ ...tableContext.tableRect,
14329
+ right: tableViewport.visibleRight
14330
+ },
14331
+ pageIndex: tableContext.pageIndex,
14332
+ tableId
14333
+ });
14334
+ for (const cellGeometry of tableContext.cells) {
14335
+ var _cell$pageWidth, _cell$marginLeft, _cell$marginRight;
14336
+ const cell = cellGeometry.cell;
14337
+ const cellContentWidth = ((_cell$pageWidth = cell.pageWidth) !== null && _cell$pageWidth !== void 0 ? _cell$pageWidth : 0) - ((_cell$marginLeft = cell.marginLeft) !== null && _cell$marginLeft !== void 0 ? _cell$marginLeft : 0) - ((_cell$marginRight = cell.marginRight) !== null && _cell$marginRight !== void 0 ? _cell$marginRight : 0);
14338
+ const bounds = calcDocParagraphPositions(cell.sections, cellGeometry.pageTop, cellGeometry.pageLeft, cellContentWidth).map((bound) => clipParagraphBoundHorizontally(bound, cellGeometry.clipLeft, cellGeometry.clipRight)).filter((bound) => bound != null);
14339
+ let arr = this._tableParagraphBounds.get(tableId);
14340
+ if (!arr) {
14341
+ arr = [];
14342
+ this._tableParagraphBounds.set(tableId, arr);
14343
+ }
14344
+ arr.push(...bounds.map((bound) => ({
14345
+ rect: bound.rect,
14346
+ paragraphStart: bound.paragraphStart,
14347
+ paragraphEnd: bound.paragraphEnd,
14348
+ startIndex: bound.startIndex,
14349
+ pageIndex: tableContext.pageIndex,
14350
+ segmentId,
14351
+ rowIndex: cellGeometry.rowIndex,
14352
+ colIndex: cellGeometry.columnIndex,
14353
+ firstLine: bound.fisrtLine,
14354
+ tableId
14355
+ })));
14356
+ let cellBounds = this._tableCellBounds.get(tableId);
14357
+ if (!cellBounds) {
14358
+ cellBounds = [];
14359
+ this._tableCellBounds.set(tableId, cellBounds);
14360
+ }
14361
+ cellBounds.push({
14362
+ rect: cellGeometry.cellRect,
14363
+ pageIndex: tableContext.pageIndex,
14364
+ rowIndex: cellGeometry.rowIndex,
14365
+ colIndex: cellGeometry.columnIndex,
14423
14366
  tableId
14424
14367
  });
14425
- table.rows.forEach((row, rowIndex) => {
14426
- row.cells.forEach((cell, colIndex) => {
14427
- const top = ((page.pageHeight === Infinity ? 0 : page.pageHeight) + documentOffsetConfig.pageMarginTop) * i + table.top + documentOffsetConfig.docsTop + page.marginTop + row.top + cell.marginTop;
14428
- const cellLeft = tableLeft + cell.left - tableViewport.scrollLeft + cell.marginLeft;
14429
- const cellContentWidth = cell.pageWidth - cell.marginLeft - cell.marginRight;
14430
- const cellRight = cellLeft + cellContentWidth;
14431
- const visibleCellLeft = Math.max(cellLeft, tableViewport.visibleLeft);
14432
- const visibleCellRight = Math.min(cellRight, tableViewport.visibleRight);
14433
- if (visibleCellRight <= visibleCellLeft) return;
14434
- const bounds = calcDocParagraphPositions(cell.sections, top, cellLeft, cellContentWidth).map((bound) => clipParagraphBoundHorizontally(bound, tableViewport.visibleLeft, tableViewport.visibleRight)).filter((bound) => bound != null);
14435
- let arr = this._tableParagraphBounds.get(tableId);
14436
- if (!arr) {
14437
- arr = [];
14438
- this._tableParagraphBounds.set(tableId, arr);
14439
- }
14440
- arr.push(...bounds.map((bound) => ({
14441
- rect: bound.rect,
14442
- paragraphStart: bound.paragraphStart,
14443
- paragraphEnd: bound.paragraphEnd,
14444
- startIndex: bound.startIndex,
14445
- pageIndex: i,
14446
- segmentId,
14447
- rowIndex,
14448
- colIndex,
14449
- firstLine: bound.fisrtLine,
14450
- tableId
14451
- })));
14452
- let cellBounds = this._tableCellBounds.get(tableId);
14453
- if (!cellBounds) {
14454
- cellBounds = [];
14455
- this._tableCellBounds.set(tableId, cellBounds);
14456
- }
14457
- cellBounds.push({
14458
- rect: {
14459
- top,
14460
- left: visibleCellLeft,
14461
- right: visibleCellRight,
14462
- bottom: top + cell.pageHeight - cell.marginBottom - cell.marginTop
14463
- },
14464
- pageIndex: i,
14465
- rowIndex,
14466
- colIndex,
14467
- tableId
14468
- });
14469
- });
14470
- });
14471
- });
14472
- handlePage(page, i, top, left);
14368
+ }
14473
14369
  }
14474
14370
  return paragraphMap;
14475
14371
  };
@@ -14526,20 +14422,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14526
14422
  rects: [paragraph.rect]
14527
14423
  };
14528
14424
  }
14529
- let paragraph;
14530
- for (const bounds of this._paragraphBounds) {
14531
- const bound = bounds[1];
14532
- if (bound.rects.some((rect) => isPointInRect(x, y, rect))) {
14533
- paragraph = bound;
14534
- break;
14535
- }
14536
- }
14537
- return paragraph;
14425
+ return getMostSpecificParagraphBound([...this._paragraphBounds.values()].filter((bound) => bound.rects.some((rect) => isPointInRect(x, y, rect))));
14538
14426
  }
14539
14427
  _calcActiveParagraphLeft(evt) {
14540
14428
  this._buildParagraphBounds();
14541
14429
  const { x, y } = evt;
14542
- return this._paragraphLeftBounds.find((bound) => isPointInRect(x, y, bound.rect));
14430
+ return getMostSpecificParagraphBound(this._paragraphLeftBounds.filter((bound) => isPointInRect(x, y, bound.rect)));
14543
14431
  }
14544
14432
  get paragraphBounds() {
14545
14433
  this._buildParagraphBounds();
@@ -14578,18 +14466,19 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14578
14466
  var _this$_skeleton$getSk4, _this$_skeleton$getSk5;
14579
14467
  const pages = (_this$_skeleton$getSk4 = (_this$_skeleton$getSk5 = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk5 === void 0 ? void 0 : _this$_skeleton$getSk5.pages) !== null && _this$_skeleton$getSk4 !== void 0 ? _this$_skeleton$getSk4 : [];
14580
14468
  const signatures = [];
14581
- pages.forEach((page) => {
14582
- var _page$skeTables;
14583
- (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
14584
- const tableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(table.tableId).tableId;
14585
- const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, tableId);
14586
- if (!viewport) {
14587
- signatures.push(`${tableId}:none`);
14588
- return;
14589
- }
14590
- signatures.push(`${tableId}:${viewport.contentWidth}:${viewport.viewportWidth}:${viewport.scrollLeft}`);
14591
- });
14592
- });
14469
+ for (const tableContext of (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
14470
+ pageMarginTop: this._documents.getOffsetConfig().pageMarginTop,
14471
+ resolveViewport: false,
14472
+ unitId: this._context.unitId
14473
+ })) {
14474
+ const tableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableContext.tableId).tableId;
14475
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, tableId);
14476
+ if (!viewport) {
14477
+ signatures.push(`${tableId}:none`);
14478
+ continue;
14479
+ }
14480
+ signatures.push(`${tableId}:${viewport.contentWidth}:${viewport.viewportWidth}:${viewport.scrollLeft}`);
14481
+ }
14593
14482
  return signatures.join("|");
14594
14483
  }
14595
14484
  };
@@ -14597,7 +14486,7 @@ DocEventManagerService = __decorate([__decorateParam(1, (0, _univerjs_core.Injec
14597
14486
  function getPreferredParagraphBoundsInRange(bodyBounds, tableBounds, startIndex, endIndex) {
14598
14487
  const matchedTableBounds = tableBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex));
14599
14488
  if (matchedTableBounds.length) return matchedTableBounds;
14600
- return bodyBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex));
14489
+ return removeContainerParagraphBounds(bodyBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex)));
14601
14490
  }
14602
14491
  function isRangeOverlappingParagraph(bound, startIndex, endIndex) {
14603
14492
  return Math.max(bound.paragraphStart, startIndex) <= Math.min(bound.paragraphEnd, endIndex);
@@ -14661,7 +14550,7 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
14661
14550
  onClick: () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(!open),
14662
14551
  className: (0, _univerjs_design.clsx)("univer-absolute univer-left-5 univer-top-4 univer-z-[100] univer-flex univer-size-8 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white univer-text-gray-800 univer-shadow-sm dark:!univer-bg-gray-600 dark:!univer-text-gray-200", iconClass),
14663
14552
  style: iconStyle,
14664
- children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LeftIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {})
14553
+ children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {})
14665
14554
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14666
14555
  className: (0, _univerjs_design.clsx)(className, "univer-absolute univer-left-0 univer-top-0 univer-box-border univer-flex univer-min-w-[180px] univer-flex-col univer-px-4 univer-pb-4 univer-pt-14 univer-transition-all univer-duration-300", { "univer-rounded-r-2xl univer-bg-white univer-shadow univer-backdrop-blur-[10px] dark:!univer-bg-gray-900": isSideBar }),
14667
14556
  style: {
@@ -14934,7 +14823,7 @@ DocUIController = __decorate([
14934
14823
  //#endregion
14935
14824
  //#region package.json
14936
14825
  var name = "@univerjs/docs-ui";
14937
- var version = "1.0.0-alpha.0";
14826
+ var version = "1.0.0-alpha.2";
14938
14827
 
14939
14828
  //#endregion
14940
14829
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -14952,8 +14841,8 @@ const DocParagraphSettingCommand = {
14952
14841
  const segmentId = docRanges[0].segmentId;
14953
14842
  const unitId = docDataModel.getUnitId();
14954
14843
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
14955
- const allParagraphs = (_segment$getBody$para = (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
14956
- const dataStream = (_segment$getBody$data = (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
14844
+ const allParagraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
14845
+ const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
14957
14846
  const paragraphs = (_BuildTextUtils$range = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, allParagraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
14958
14847
  const doMutation = {
14959
14848
  id: _univerjs_docs.RichTextEditingMutation.id,
@@ -15024,7 +14913,7 @@ const DocHeaderFooterOptions = (props) => {
15024
14913
  ...prev,
15025
14914
  [type]: val ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE
15026
14915
  }));
15027
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
14916
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
15028
14917
  const documentStyle = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle;
15029
14918
  const docSkeletonManagerService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService);
15030
14919
  const viewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
@@ -15082,7 +14971,7 @@ const DocHeaderFooterOptions = (props) => {
15082
14971
  commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId });
15083
14972
  };
15084
14973
  (0, react.useEffect)(() => {
15085
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
14974
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
15086
14975
  const documentStyle = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle;
15087
14976
  if (documentStyle) {
15088
14977
  const { marginHeader = 0, marginFooter = 0, useFirstPageHeaderFooter = _univerjs_core.BooleanNumber.FALSE, evenAndOddHeaders = _univerjs_core.BooleanNumber.FALSE } = documentStyle;
@@ -15152,8 +15041,8 @@ const DocHeaderFooterPanel = () => {
15152
15041
  var _renderManagerService;
15153
15042
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
15154
15043
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
15155
- const unitId = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance().getUnitId();
15156
- const viewModel = ((_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService)).getViewModel();
15044
+ const unitId = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC).getUnitId();
15045
+ const viewModel = ((_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs.DocSkeletonManagerService)).getViewModel();
15157
15046
  const [isEditHeaderFooter, setIsEditHeaderFooter] = (0, react.useState)(true);
15158
15047
  (0, react.useEffect)(() => {
15159
15048
  setIsEditHeaderFooter(viewModel.getEditArea() !== _univerjs_engine_render.DocumentEditArea.BODY);
@@ -15418,8 +15307,8 @@ const useCurrentParagraph = () => {
15418
15307
  if (!docDataModel || docRanges.length === 0) return [];
15419
15308
  const segmentId = docRanges[0].segmentId;
15420
15309
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
15421
- const paragraphs = (_segment$getBody$para = (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
15422
- const dataStream = (_segment$getBody$data = (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
15310
+ const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
15311
+ const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
15423
15312
  return (_BuildTextUtils$range = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
15424
15313
  };
15425
15314
  const useFirstParagraphHorizontalAlign = (paragraph, defaultValue) => {
@@ -16008,12 +15897,12 @@ const LIST_ICON_MAP = {
16008
15897
  };
16009
15898
  let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_core.Disposable {
16010
15899
  get activeParagraph() {
16011
- var _this$_paragrahMenu;
16012
- return (_this$_paragrahMenu = this._paragrahMenu) === null || _this$_paragrahMenu === void 0 ? void 0 : _this$_paragrahMenu.paragraph;
15900
+ var _this$_paragraphMenu;
15901
+ return (_this$_paragraphMenu = this._paragraphMenu) === null || _this$_paragraphMenu === void 0 ? void 0 : _this$_paragraphMenu.paragraph;
16013
15902
  }
16014
15903
  get activeTarget() {
16015
- var _this$_paragrahMenu$t, _this$_paragrahMenu2;
16016
- return (_this$_paragrahMenu$t = (_this$_paragrahMenu2 = this._paragrahMenu) === null || _this$_paragrahMenu2 === void 0 ? void 0 : _this$_paragrahMenu2.target) !== null && _this$_paragrahMenu$t !== void 0 ? _this$_paragrahMenu$t : null;
15904
+ var _this$_paragraphMenu$, _this$_paragraphMenu2;
15905
+ return (_this$_paragraphMenu$ = (_this$_paragraphMenu2 = this._paragraphMenu) === null || _this$_paragraphMenu2 === void 0 ? void 0 : _this$_paragraphMenu2.target) !== null && _this$_paragraphMenu$ !== void 0 ? _this$_paragraphMenu$ : null;
16017
15906
  }
16018
15907
  setBlockMenuDragging(isDragging) {
16019
15908
  this._isBlockMenuDragging = isDragging;
@@ -16030,7 +15919,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16030
15919
  this._docSkeletonManagerService = _docSkeletonManagerService;
16031
15920
  this._floatMenuService = _floatMenuService;
16032
15921
  this._docSelectionRenderService = _docSelectionRenderService;
16033
- _defineProperty(this, "_paragrahMenu", null);
15922
+ _defineProperty(this, "_paragraphMenu", null);
16034
15923
  _defineProperty(this, "_activeTarget$", new rxjs.BehaviorSubject(null));
16035
15924
  _defineProperty(this, "activeTarget$", this._activeTarget$.asObservable());
16036
15925
  _defineProperty(this, "_slashMenuRequest$", new rxjs.BehaviorSubject(null));
@@ -16042,10 +15931,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16042
15931
  this._init();
16043
15932
  }
16044
15933
  _isCursorInActiveParagraph() {
16045
- if (!this._paragrahMenu) return false;
15934
+ if (!this._paragraphMenu) return false;
16046
15935
  const activeTextRange = this._docSelectionManagerService.getActiveTextRange();
16047
15936
  if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed)) return false;
16048
- if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed) || activeTextRange.startOffset < this._paragrahMenu.paragraph.paragraphStart || activeTextRange.startOffset > this._paragrahMenu.paragraph.paragraphEnd) return false;
15937
+ if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed) || activeTextRange.startOffset < this._paragraphMenu.paragraph.paragraphStart || activeTextRange.startOffset > this._paragraphMenu.paragraph.paragraphEnd) return false;
16049
15938
  return true;
16050
15939
  }
16051
15940
  _getExpandedSelectionState(ranges) {
@@ -16076,30 +15965,34 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16076
15965
  return this._hasExpandedSelectionRanges(this._docSelectionManagerService.getDocRanges());
16077
15966
  }
16078
15967
  setParagraphMenuActive(active) {
16079
- if (this._paragrahMenu) this._paragrahMenu.active = active;
15968
+ if (this._paragraphMenu) this._paragraphMenu.active = active;
16080
15969
  }
16081
15970
  _init() {
16082
15971
  var _this$_docEventManage;
16083
15972
  const handleHoverTarget = (paragraph, tableBound) => {
16084
15973
  if (this._isBlockMenuDragging) return;
15974
+ if (this._docSelectionRenderService.isOnPointerEvent) {
15975
+ this.hideParagraphMenu(true);
15976
+ return;
15977
+ }
16085
15978
  const selectionState = this._getExpandedSelectionState(this._docSelectionManagerService.getDocRanges());
16086
15979
  if (selectionState.hasExpandedTextRange) {
16087
15980
  this.hideParagraphMenu(true);
16088
15981
  return;
16089
15982
  }
16090
15983
  if (selectionState.hasRectRange) {
16091
- var _this$_paragrahMenu3;
15984
+ var _this$_paragraphMenu3;
16092
15985
  if (tableBound) {
16093
15986
  this.showTableMenu(tableBound);
16094
15987
  return;
16095
15988
  }
16096
- if (((_this$_paragrahMenu3 = this._paragrahMenu) === null || _this$_paragrahMenu3 === void 0 ? void 0 : _this$_paragrahMenu3.target.kind) === "table") return;
15989
+ if (((_this$_paragraphMenu3 = this._paragraphMenu) === null || _this$_paragraphMenu3 === void 0 ? void 0 : _this$_paragraphMenu3.target.kind) === _univerjs_core.DocumentBlockType.TABLE) return;
16097
15990
  this.hideParagraphMenu(true);
16098
15991
  return;
16099
15992
  }
16100
15993
  if (this._docSkeletonManagerService.getViewModel().getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY && !this._floatMenuService.floatMenu && !this._context.unit.getDisabled()) {
16101
- var _this$_paragrahMenu4;
16102
- if ((_this$_paragrahMenu4 = this._paragrahMenu) === null || _this$_paragrahMenu4 === void 0 ? void 0 : _this$_paragrahMenu4.active) return;
15994
+ var _this$_paragraphMenu4;
15995
+ if ((_this$_paragraphMenu4 = this._paragraphMenu) === null || _this$_paragraphMenu4 === void 0 ? void 0 : _this$_paragraphMenu4.active) return;
16103
15996
  if (paragraph) {
16104
15997
  this.showParagraphMenu(paragraph);
16105
15998
  return;
@@ -16115,20 +16008,26 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16115
16008
  this._docEventManagerService.hoverParagraphRealTime$,
16116
16009
  this._docEventManagerService.hoverParagraphLeft$,
16117
16010
  (_this$_docEventManage = this._docEventManagerService.hoverTableRealTime$) !== null && _this$_docEventManage !== void 0 ? _this$_docEventManage : new rxjs.BehaviorSubject(null)
16118
- ]).pipe((0, rxjs.throttleTime)(16)).subscribe(([p, left, table]) => {
16011
+ ]).pipe((0, rxjs.throttleTime)(16, void 0, {
16012
+ leading: true,
16013
+ trailing: true
16014
+ })).subscribe(([p, left, table]) => {
16119
16015
  handleHoverTarget(p !== null && p !== void 0 ? p : left, table);
16120
16016
  }));
16017
+ this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(() => {
16018
+ this.hideParagraphMenu(true);
16019
+ }));
16121
16020
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
16122
- var _this$_paragrahMenu5;
16021
+ var _this$_paragraphMenu5;
16123
16022
  const selectionState = this._getExpandedSelectionState([...textRanges, ...rectRanges]);
16124
- if (selectionState.hasExpandedTextRange || selectionState.hasRectRange && ((_this$_paragrahMenu5 = this._paragrahMenu) === null || _this$_paragrahMenu5 === void 0 ? void 0 : _this$_paragrahMenu5.target.kind) !== "table") this.hideParagraphMenu(true);
16023
+ 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);
16125
16024
  }));
16126
16025
  let lastScrollY = 0;
16127
16026
  this.disposeWithMe(this._context.scene.getViewport("viewMain").onScrollAfter$.subscribeEvent((e) => {
16128
- var _this$_paragrahMenu6;
16027
+ var _this$_paragraphMenu6;
16129
16028
  if (lastScrollY === e.scrollY) return;
16130
16029
  lastScrollY = e.scrollY;
16131
- if ((_this$_paragrahMenu6 = this._paragrahMenu) === null || _this$_paragrahMenu6 === void 0 ? void 0 : _this$_paragrahMenu6.blockRange) return;
16030
+ if ((_this$_paragraphMenu6 = this._paragraphMenu) === null || _this$_paragraphMenu6 === void 0 ? void 0 : _this$_paragraphMenu6.blockRange) return;
16132
16031
  if (this._isBlockMenuDragging) return;
16133
16032
  this.hideParagraphMenu(true);
16134
16033
  }));
@@ -16192,10 +16091,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16192
16091
  return null;
16193
16092
  }
16194
16093
  _getSlashMenuParagraph(config) {
16195
- var _this$_paragrahMenu$p, _this$_paragrahMenu7, _find;
16094
+ var _this$_paragraphMenu$2, _this$_paragraphMenu7, _find;
16196
16095
  const activeRange = this._getCollapsedTextRange(config);
16197
16096
  const offset = activeRange === null || activeRange === void 0 ? void 0 : activeRange.startOffset;
16198
- const activeParagraph = (_this$_paragrahMenu$p = (_this$_paragrahMenu7 = this._paragrahMenu) === null || _this$_paragrahMenu7 === void 0 ? void 0 : _this$_paragrahMenu7.paragraph) !== null && _this$_paragrahMenu$p !== void 0 ? _this$_paragrahMenu$p : null;
16097
+ const activeParagraph = (_this$_paragraphMenu$2 = (_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.paragraph) !== null && _this$_paragraphMenu$2 !== void 0 ? _this$_paragraphMenu$2 : null;
16199
16098
  if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) return activeParagraph;
16200
16099
  if (activeParagraph && offset == null) return activeParagraph;
16201
16100
  if (offset == null) return null;
@@ -16216,7 +16115,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16216
16115
  }
16217
16116
  }
16218
16117
  showParagraphMenu(paragraph) {
16219
- var _this$_paragrahMenu8, _target$paragraph;
16118
+ var _this$_paragraphMenu8, _target$paragraph;
16220
16119
  if (this._hasExpandedSelection()) {
16221
16120
  this.hideParagraphMenu(true);
16222
16121
  return;
@@ -16226,7 +16125,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16226
16125
  this.hideParagraphMenu(true);
16227
16126
  return;
16228
16127
  }
16229
- if (((_this$_paragrahMenu8 = this._paragrahMenu) === null || _this$_paragrahMenu8 === void 0 ? void 0 : _this$_paragrahMenu8.target.key) === target.key) return;
16128
+ if (((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.target.key) === target.key) return;
16230
16129
  this.hideParagraphMenu(true);
16231
16130
  const targetParagraph = (_target$paragraph = target.paragraph) !== null && _target$paragraph !== void 0 ? _target$paragraph : paragraph;
16232
16131
  const blockRange = target.blockRange;
@@ -16251,7 +16150,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16251
16150
  },
16252
16151
  zIndex: 101
16253
16152
  }, this._context.unitId);
16254
- this._paragrahMenu = {
16153
+ this._paragraphMenu = {
16255
16154
  paragraph: targetParagraph,
16256
16155
  target,
16257
16156
  blockRange,
@@ -16261,7 +16160,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16261
16160
  this._activeTarget$.next(target);
16262
16161
  }
16263
16162
  showTableMenu(tableBound) {
16264
- var _body$tables, _this$_paragrahMenu9;
16163
+ var _body$tables, _this$_paragraphMenu9;
16265
16164
  if (this._hasExpandedTextSelection()) {
16266
16165
  this.hideParagraphMenu(true);
16267
16166
  return;
@@ -16270,8 +16169,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16270
16169
  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);
16271
16170
  if (!table) return;
16272
16171
  const target = {
16273
- kind: "table",
16274
- key: `table:${table.tableId}`,
16172
+ kind: _univerjs_core.DocumentBlockType.TABLE,
16173
+ key: `${_univerjs_core.DocumentBlockType.TABLE}:${table.tableId}`,
16275
16174
  table,
16276
16175
  icon: "GridIcon",
16277
16176
  menuRange: {
@@ -16287,7 +16186,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16287
16186
  draggable: true
16288
16187
  };
16289
16188
  if (this._shouldKeepCurrentCellMenuForTable(table)) return;
16290
- if (((_this$_paragrahMenu9 = this._paragrahMenu) === null || _this$_paragrahMenu9 === void 0 ? void 0 : _this$_paragrahMenu9.target.key) === target.key) return;
16189
+ if (((_this$_paragraphMenu9 = this._paragraphMenu) === null || _this$_paragraphMenu9 === void 0 ? void 0 : _this$_paragraphMenu9.target.key) === target.key) return;
16291
16190
  const anchorRect = getTableAnchorRect(tableBound);
16292
16191
  const paragraph = {
16293
16192
  rect: tableBound.rect,
@@ -16311,7 +16210,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16311
16210
  },
16312
16211
  zIndex: 101
16313
16212
  }, this._context.unitId);
16314
- this._paragrahMenu = {
16213
+ this._paragraphMenu = {
16315
16214
  paragraph,
16316
16215
  target,
16317
16216
  disposable,
@@ -16320,9 +16219,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16320
16219
  this._activeTarget$.next(target);
16321
16220
  }
16322
16221
  _shouldKeepCurrentCellMenuForTable(table) {
16323
- var _this$_paragrahMenu10;
16324
- const target = (_this$_paragrahMenu10 = this._paragrahMenu) === null || _this$_paragrahMenu10 === void 0 ? void 0 : _this$_paragrahMenu10.target;
16325
- if (!target || target.kind === "table" || !target.cellRange) return false;
16222
+ var _this$_paragraphMenu10;
16223
+ const target = (_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target;
16224
+ if (!target || target.kind === _univerjs_core.DocumentBlockType.TABLE || !target.cellRange) return false;
16326
16225
  return target.cellRange.startOffset >= table.startIndex && target.cellRange.startOffset <= table.endIndex;
16327
16226
  }
16328
16227
  getDropTargetFromClientPoint(clientX, clientY, sourceRange) {
@@ -16362,9 +16261,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16362
16261
  }
16363
16262
  hideParagraphMenu(force = false) {
16364
16263
  if (this._isBlockMenuDragging) return;
16365
- if (this._paragrahMenu && (this._paragrahMenu.disposable.canDispose() || force)) {
16366
- this._paragrahMenu.disposable.dispose();
16367
- this._paragrahMenu = null;
16264
+ if (this._paragraphMenu && (this._paragraphMenu.disposable.canDispose() || force)) {
16265
+ this._paragraphMenu.disposable.dispose();
16266
+ this._paragraphMenu = null;
16368
16267
  this._isSlashMenuActive = false;
16369
16268
  this._slashMenuRequest$.next(null);
16370
16269
  this._activeTarget$.next(null);
@@ -16386,8 +16285,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16386
16285
  blockRange
16387
16286
  };
16388
16287
  return {
16389
- kind: "blockRange",
16390
- key: `blockRange:${blockRange.blockId}`,
16288
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16289
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16391
16290
  paragraph: targetParagraph,
16392
16291
  blockRange,
16393
16292
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
@@ -16412,8 +16311,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16412
16311
  const customBlock = body === null || body === void 0 || (_body$customBlocks = body.customBlocks) === null || _body$customBlocks === void 0 ? void 0 : _body$customBlocks.find((item) => item.startIndex >= paragraph.paragraphStart && item.startIndex <= paragraph.paragraphEnd);
16413
16312
  const isCustomBlockOnly = (customBlock === null || customBlock === void 0 ? void 0 : customBlock.blockType) === _univerjs_core.BlockType.CUSTOM && paragraphDataStream.replace(/[\b\r\n]/g, "") === "";
16414
16313
  if (customBlock && customBlock.blockType === _univerjs_core.BlockType.CUSTOM && isCustomBlockOnly) return {
16415
- kind: "customBlock",
16416
- key: `customBlock:${customBlock.blockId}`,
16314
+ kind: _univerjs_core.DocumentBlockType.CUSTOM_BLOCK,
16315
+ key: `${_univerjs_core.DocumentBlockType.CUSTOM_BLOCK}:${customBlock.blockId}`,
16417
16316
  paragraph,
16418
16317
  customBlock,
16419
16318
  icon: "TextTypeIcon",
@@ -16429,8 +16328,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16429
16328
  };
16430
16329
  if (paragraphDataStream === "\b") return null;
16431
16330
  return {
16432
- kind: "paragraph",
16433
- key: `paragraph:${paragraph.startIndex}`,
16331
+ kind: _univerjs_core.DocumentBlockType.PARAGRAPH,
16332
+ key: `${_univerjs_core.DocumentBlockType.PARAGRAPH}:${paragraph.startIndex}`,
16434
16333
  paragraph,
16435
16334
  icon: isHorizontalRuleParagraph ? "ReduceIcon" : listIcon,
16436
16335
  cellRange: cellRange !== null && cellRange !== void 0 ? cellRange : void 0,
@@ -16456,8 +16355,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16456
16355
  const tableBound = this._docEventManagerService.tableBounds.get(table.tableId);
16457
16356
  if (!tableBound) continue;
16458
16357
  targets.push({
16459
- kind: "table",
16460
- key: `table:${table.tableId}`,
16358
+ kind: _univerjs_core.DocumentBlockType.TABLE,
16359
+ key: `${_univerjs_core.DocumentBlockType.TABLE}:${table.tableId}`,
16461
16360
  table,
16462
16361
  icon: "GridIcon",
16463
16362
  menuRange: {
@@ -16478,8 +16377,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16478
16377
  const rect = unionRects(paragraphBounds.filter((bound) => Math.max(bound.paragraphStart, blockRange.startIndex) <= Math.min(bound.paragraphEnd, blockRange.endIndex)).map((bound) => bound.rect));
16479
16378
  if (!rect) continue;
16480
16379
  targets.push({
16481
- kind: "blockRange",
16482
- key: `blockRange:${blockRange.blockId}`,
16380
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16381
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16483
16382
  blockRange,
16484
16383
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
16485
16384
  menuRange: {
@@ -16520,8 +16419,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16520
16419
  const rect = unionRects(paragraphBounds.filter((bound) => Math.max(bound.paragraphStart, blockRange.startIndex) <= Math.min(bound.paragraphEnd, blockRange.endIndex)).map((bound) => bound.rect));
16521
16420
  if (!rect) continue;
16522
16421
  targets.push({
16523
- kind: "blockRange",
16524
- key: `blockRange:${blockRange.blockId}`,
16422
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16423
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16525
16424
  blockRange,
16526
16425
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
16527
16426
  cellRange,
@@ -16656,6 +16555,9 @@ const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;
16656
16555
  function getParagraphMenuTriggerClassName(visible) {
16657
16556
  return (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-white 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 });
16658
16557
  }
16558
+ function shouldExecuteParagraphMenuMove(validatorService, context) {
16559
+ return validatorService.canMoveBlock(context);
16560
+ }
16659
16561
  function getParagraphMenuTriggerIconKey(namedStyleType) {
16660
16562
  switch (namedStyleType) {
16661
16563
  case _univerjs_core.NamedStyleType.HEADING_1: return "H1Icon";
@@ -16849,6 +16751,14 @@ function getParagraphMenuResolvedCommand(option, targetRange) {
16849
16751
  id: (_option$id = option.id) !== null && _option$id !== void 0 ? _option$id : commandId
16850
16752
  }, targetRange);
16851
16753
  }
16754
+ function getParagraphMenuCommandParams(commandId, commandParams, target, unitId) {
16755
+ if (commandId !== DeleteCurrentParagraphCommand.id || (target === null || target === void 0 ? void 0 : target.kind) !== "blockRange" || !target.blockRange) return commandParams;
16756
+ return {
16757
+ ...commandParams !== null && commandParams !== void 0 ? commandParams : {},
16758
+ unitId,
16759
+ blockRange: target.blockRange
16760
+ };
16761
+ }
16852
16762
  function getParagraphMenuType(target, emptyMode) {
16853
16763
  if ((target === null || target === void 0 ? void 0 : target.kind) === "table") return DOC_TABLE_BLOCK_MENU_ID;
16854
16764
  if (emptyMode) return DOC_PARAGRAPH_T_INSERT_MENU_ID;
@@ -16936,13 +16846,13 @@ function deleteBodyText(body, startOffset, endOffset) {
16936
16846
  }
16937
16847
  function stripBlockParagraphStyle(style, blockType) {
16938
16848
  const nextStyle = { ...style };
16939
- if (blockType === "quote") {
16849
+ if (blockType === _univerjs_core.DocumentBlockRangeType.QUOTE) {
16940
16850
  delete nextStyle.indentStart;
16941
16851
  delete nextStyle.spaceAbove;
16942
16852
  delete nextStyle.spaceBelow;
16943
16853
  return nextStyle;
16944
16854
  }
16945
- if (blockType === "code") {
16855
+ if (blockType === _univerjs_core.DocumentBlockRangeType.CODE) {
16946
16856
  var _nextStyle$textStyle, _nextStyle$textStyle2;
16947
16857
  delete nextStyle.indentStart;
16948
16858
  delete nextStyle.indentEnd;
@@ -16951,7 +16861,7 @@ function stripBlockParagraphStyle(style, blockType) {
16951
16861
  if (((_nextStyle$textStyle = nextStyle.textStyle) === null || _nextStyle$textStyle === void 0 ? void 0 : _nextStyle$textStyle.ff) === "monospace" && ((_nextStyle$textStyle2 = nextStyle.textStyle) === null || _nextStyle$textStyle2 === void 0 ? void 0 : _nextStyle$textStyle2.fs) === 12) delete nextStyle.textStyle;
16952
16862
  return nextStyle;
16953
16863
  }
16954
- if (blockType === "callout") {
16864
+ if (blockType === _univerjs_core.DocumentBlockRangeType.CALLOUT) {
16955
16865
  delete nextStyle.indentStart;
16956
16866
  delete nextStyle.indentEnd;
16957
16867
  delete nextStyle.spaceAbove;
@@ -17047,6 +16957,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17047
16957
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
17048
16958
  const docClipboardService = (0, _univerjs_ui.useDependency)(IDocClipboardService);
17049
16959
  const docContentInsertService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocContentInsertService);
16960
+ const docBlockMoveValidatorService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocBlockMoveValidatorService);
17050
16961
  const clipboardInterfaceService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IClipboardInterfaceService);
17051
16962
  const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
17052
16963
  const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
@@ -17285,7 +17196,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17285
17196
  await executeResolvedCommand({
17286
17197
  ...option,
17287
17198
  commandId,
17288
- params: commandParams
17199
+ params: getParagraphMenuCommandParams(commandId, commandParams, latestTarget, popup.unitId)
17289
17200
  }, getParagraphMenuCommandTargetRange(commandId, targetRange, formattingRange));
17290
17201
  } finally {
17291
17202
  restoreTextRanges(previousTextRanges);
@@ -17325,6 +17236,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17325
17236
  },
17326
17237
  onMouseLeave: () => {
17327
17238
  isMouseOver.current = false;
17239
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17328
17240
  cancelOpenMenu();
17329
17241
  scheduleHideMenu();
17330
17242
  },
@@ -17377,7 +17289,11 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17377
17289
  isDraggingRef.current = false;
17378
17290
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setBlockMenuDragging(false);
17379
17291
  setDropRect(null);
17380
- if (shouldDrop && range && targetOffset != null) commandService.executeCommand(MoveDocBlockCommand.id, {
17292
+ if (shouldDrop && range && targetOffset != null && shouldExecuteParagraphMenuMove(docBlockMoveValidatorService, {
17293
+ unitId: popup.unitId,
17294
+ sourceRange: range,
17295
+ targetOffset
17296
+ })) commandService.executeCommand(MoveDocBlockCommand.id, {
17381
17297
  unitId: popup.unitId,
17382
17298
  sourceRange: range,
17383
17299
  targetOffset
@@ -17416,6 +17332,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17416
17332
  },
17417
17333
  onMouseLeave: () => {
17418
17334
  isMouseOver.current = false;
17335
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17419
17336
  scheduleHideMenu();
17420
17337
  }
17421
17338
  }),
@@ -17433,6 +17350,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17433
17350
  },
17434
17351
  onMouseLeave: () => {
17435
17352
  isMouseOver.current = false;
17353
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17436
17354
  scheduleHideMenu();
17437
17355
  },
17438
17356
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.ContextMenuPanel, {
@@ -17450,6 +17368,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17450
17368
  },
17451
17369
  onMenuPointerLeave: () => {
17452
17370
  isMouseOver.current = false;
17371
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17453
17372
  scheduleHideMenu();
17454
17373
  },
17455
17374
  onCancel: () => {
@@ -17513,8 +17432,7 @@ const TableBlockMenu = ({ popup }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)
17513
17432
  });
17514
17433
  function shouldUseInsertBelowRange(commandId, params) {
17515
17434
  if (params.id === "doc.menu.insert-bellow") return true;
17516
- const rawParams = typeof params.params === "function" ? params.params() : params.params;
17517
- if (rawParams && typeof rawParams === "object" && "paragraphMenuPlacement" in rawParams && rawParams.paragraphMenuPlacement === "below") return true;
17435
+ if (typeof params.id === "string" && params.id.toLowerCase().includes("below")) return true;
17518
17436
  const normalized = commandId.toLowerCase();
17519
17437
  if (normalized.includes("insert") && (normalized.includes("below") || normalized.includes("bellow"))) return true;
17520
17438
  if (normalized.includes("insert") && normalized.includes("image")) return true;
@@ -17698,6 +17616,12 @@ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)
17698
17616
 
17699
17617
  //#endregion
17700
17618
  //#region src/controllers/doc-auto-format.controller.ts
17619
+ function hasQuickListType(text) {
17620
+ return Object.prototype.hasOwnProperty.call(_univerjs_core.QuickListTypeMap, text);
17621
+ }
17622
+ function hasQuickHeading(text) {
17623
+ return Object.prototype.hasOwnProperty.call(QUICK_HEADING_MAP, text);
17624
+ }
17701
17625
  let DocAutoFormatController = class DocAutoFormatController extends _univerjs_core.Disposable {
17702
17626
  constructor(_docAutoFormatService, _renderManagerService) {
17703
17627
  super();
@@ -17720,127 +17644,437 @@ let DocAutoFormatController = class DocAutoFormatController extends _univerjs_co
17720
17644
  var _p$bullet;
17721
17645
  return ((_p$bullet = p.bullet) === null || _p$bullet === void 0 ? void 0 : _p$bullet.listId) === paragraphs[0].bullet.listId;
17722
17646
  });
17723
- if ((bulletParagraphs === null || bulletParagraphs === void 0 ? void 0 : bulletParagraphs.findIndex((p) => p.startIndex === paragraphs[0].startIndex)) === 0) return false;
17724
- return true;
17725
- } else if (paragraphs.length > 1 && paragraphs.some((p) => p.bullet)) return true;
17726
- return false;
17727
- },
17728
- getMutations(context) {
17729
- const params = context.commandParams;
17730
- return [{
17731
- id: ChangeListNestingLevelCommand.id,
17732
- params: { type: (params === null || params === void 0 ? void 0 : params.shift) ? -1 : 1 }
17733
- }];
17734
- },
17735
- priority: 100
17736
- }));
17737
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17738
- id: TabCommand.id,
17739
- match: (context) => {
17740
- const { selection, unit } = context;
17741
- const { startNodePosition, endNodePosition } = selection;
17742
- const renderObject = this._renderManagerService.getRenderById(unit.getUnitId());
17743
- const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
17744
- if (skeleton == null) return false;
17745
- if (startNodePosition && endNodePosition && isInSameTableCellData(skeleton, startNodePosition, endNodePosition)) return true;
17746
- if (startNodePosition && !endNodePosition && startNodePosition.path.indexOf("cells") > -1) return true;
17747
- return false;
17748
- },
17749
- getMutations(context) {
17750
- const params = context.commandParams;
17751
- return [{
17752
- id: DocTableTabCommand.id,
17753
- params: { shift: !!(params === null || params === void 0 ? void 0 : params.shift) }
17754
- }];
17755
- },
17756
- priority: 99
17757
- }));
17758
- }
17759
- _initSpaceAutoFormat() {
17760
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17761
- id: AfterSpaceCommand.id,
17762
- match: (context) => {
17763
- var _unit$getBody2;
17764
- const { selection, paragraphs, unit } = context;
17765
- if (!selection.collapsed) return false;
17766
- if (paragraphs.length !== 1) return false;
17767
- if (!selection.collapsed) return false;
17768
- const text = (_unit$getBody2 = unit.getBody()) === null || _unit$getBody2 === void 0 ? void 0 : _unit$getBody2.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17769
- if (text && (Object.keys(_univerjs_core.QuickListTypeMap).includes(text) || Object.keys(QUICK_HEADING_MAP).includes(text))) return true;
17770
- return false;
17771
- },
17772
- getMutations(context) {
17773
- var _unit$getBody3;
17774
- const { paragraphs, unit, selection } = context;
17775
- const text = (_unit$getBody3 = unit.getBody()) === null || _unit$getBody3 === void 0 ? void 0 : _unit$getBody3.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17776
- if (text && Object.keys(_univerjs_core.QuickListTypeMap).includes(text)) {
17777
- const type = _univerjs_core.QuickListTypeMap[text];
17778
- return [{
17779
- id: QuickListCommand.id,
17780
- params: {
17781
- listType: type,
17782
- paragraph: paragraphs[0]
17783
- }
17784
- }];
17647
+ if ((bulletParagraphs === null || bulletParagraphs === void 0 ? void 0 : bulletParagraphs.findIndex((p) => p.startIndex === paragraphs[0].startIndex)) === 0) return false;
17648
+ return true;
17649
+ } else if (paragraphs.length > 1 && paragraphs.some((p) => p.bullet)) return true;
17650
+ return false;
17651
+ },
17652
+ getMutations(context) {
17653
+ const params = context.commandParams;
17654
+ return [{
17655
+ id: ChangeListNestingLevelCommand.id,
17656
+ params: { type: (params === null || params === void 0 ? void 0 : params.shift) ? -1 : 1 }
17657
+ }];
17658
+ },
17659
+ priority: 100
17660
+ }));
17661
+ this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17662
+ id: TabCommand.id,
17663
+ match: (context) => {
17664
+ const { selection, unit } = context;
17665
+ const { startNodePosition, endNodePosition } = selection;
17666
+ const renderObject = this._renderManagerService.getRenderById(unit.getUnitId());
17667
+ const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
17668
+ if (skeleton == null) return false;
17669
+ if (startNodePosition && endNodePosition && isInSameTableCellData(skeleton, startNodePosition, endNodePosition)) return true;
17670
+ if (startNodePosition && !endNodePosition && startNodePosition.path.indexOf("cells") > -1) return true;
17671
+ return false;
17672
+ },
17673
+ getMutations(context) {
17674
+ const params = context.commandParams;
17675
+ return [{
17676
+ id: DocTableTabCommand.id,
17677
+ params: { shift: !!(params === null || params === void 0 ? void 0 : params.shift) }
17678
+ }];
17679
+ },
17680
+ priority: 99
17681
+ }));
17682
+ }
17683
+ _initSpaceAutoFormat() {
17684
+ this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17685
+ id: AfterSpaceCommand.id,
17686
+ match: (context) => {
17687
+ var _unit$getBody2;
17688
+ const { selection, paragraphs, unit } = context;
17689
+ if (!selection.collapsed) return false;
17690
+ if (paragraphs.length !== 1) return false;
17691
+ if (!selection.collapsed) return false;
17692
+ const text = (_unit$getBody2 = unit.getBody()) === null || _unit$getBody2 === void 0 ? void 0 : _unit$getBody2.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17693
+ if (text && (hasQuickListType(text) || hasQuickHeading(text))) return true;
17694
+ return false;
17695
+ },
17696
+ getMutations(context) {
17697
+ var _unit$getBody3;
17698
+ const { paragraphs, unit, selection } = context;
17699
+ const text = (_unit$getBody3 = unit.getBody()) === null || _unit$getBody3 === void 0 ? void 0 : _unit$getBody3.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17700
+ if (text && hasQuickListType(text)) {
17701
+ const type = _univerjs_core.QuickListTypeMap[text];
17702
+ return [{
17703
+ id: QuickListCommand.id,
17704
+ params: {
17705
+ listType: type,
17706
+ paragraph: paragraphs[0]
17707
+ }
17708
+ }];
17709
+ }
17710
+ if (text && hasQuickHeading(text)) {
17711
+ const type = QUICK_HEADING_MAP[text];
17712
+ return [{
17713
+ id: QuickHeadingCommand.id,
17714
+ params: { value: type }
17715
+ }];
17716
+ }
17717
+ return [];
17718
+ }
17719
+ }));
17720
+ }
17721
+ _initExitListAutoFormat() {
17722
+ this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17723
+ id: EnterCommand.id,
17724
+ match: (context) => {
17725
+ const { paragraphs } = context;
17726
+ if (paragraphs.length === 1 && paragraphs[0].bullet && paragraphs[0].paragraphStart === paragraphs[0].paragraphEnd) return true;
17727
+ return false;
17728
+ },
17729
+ getMutations: (context) => {
17730
+ const bullet = context.paragraphs[0].bullet;
17731
+ if (!bullet) return [];
17732
+ if (bullet.nestingLevel > 0) return [{
17733
+ id: ChangeListNestingLevelCommand.id,
17734
+ params: { type: -1 }
17735
+ }];
17736
+ return [{
17737
+ id: ListOperationCommand.id,
17738
+ params: { listType: context.paragraphs[0].bullet.listType }
17739
+ }];
17740
+ }
17741
+ }));
17742
+ }
17743
+ _initDefaultEnterFormat() {
17744
+ this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17745
+ id: EnterCommand.id,
17746
+ match: () => {
17747
+ return true;
17748
+ },
17749
+ getMutations() {
17750
+ return [{ id: BreakLineCommand.id }];
17751
+ },
17752
+ priority: -9999
17753
+ }));
17754
+ }
17755
+ };
17756
+ DocAutoFormatController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(DocAutoFormatService)), __decorateParam(1, _univerjs_engine_render.IRenderManagerService)], DocAutoFormatController);
17757
+
17758
+ //#endregion
17759
+ //#region src/views/header-footer/text-bubble.ts
17760
+ const COLLAB_CURSOR_LABEL_HEIGHT = 18;
17761
+ const COLLAB_CURSOR_LABEL_MAX_WIDTH = 200;
17762
+ const COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 6;
17763
+ const COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 4;
17764
+ function drawBubble(ctx, props) {
17765
+ var _radius, _width, _height;
17766
+ let { radius, width, height } = props;
17767
+ radius = (_radius = radius) !== null && _radius !== void 0 ? _radius : 0;
17768
+ width = (_width = width) !== null && _width !== void 0 ? _width : 30;
17769
+ height = (_height = height) !== null && _height !== void 0 ? _height : 30;
17770
+ let bottomRight = 0;
17771
+ bottomRight = Math.min(radius, width / 2, height / 2);
17772
+ ctx.beginPath();
17773
+ ctx.moveTo(0, 0);
17774
+ ctx.lineTo(width, 0);
17775
+ ctx.lineTo(width, height - bottomRight);
17776
+ ctx.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
17777
+ ctx.lineTo(0, height);
17778
+ ctx.lineTo(0, 0);
17779
+ ctx.closePath();
17780
+ if (props.fill) {
17781
+ ctx.save();
17782
+ ctx.fillStyle = props.fill;
17783
+ if (props.fillRule === "evenodd") ctx.fill("evenodd");
17784
+ else ctx.fill();
17785
+ ctx.restore();
17786
+ }
17787
+ }
17788
+ /**
17789
+ * Render a single collaborated cursor on the canvas.
17790
+ */
17791
+ var TextBubbleShape = class TextBubbleShape extends _univerjs_engine_render.Shape {
17792
+ constructor(key, props) {
17793
+ super(key, props);
17794
+ _defineProperty(this, "color", void 0);
17795
+ _defineProperty(this, "text", void 0);
17796
+ this.color = props === null || props === void 0 ? void 0 : props.color;
17797
+ this.text = props === null || props === void 0 ? void 0 : props.text;
17798
+ }
17799
+ static drawWith(ctx, props) {
17800
+ const { text, color } = props;
17801
+ ctx.save();
17802
+ ctx.font = "13px Source Han Sans CN";
17803
+ const textWidth = ctx.measureText(text).width;
17804
+ drawBubble(ctx, {
17805
+ height: 18,
17806
+ width: Math.min(textWidth + 2 * 6, 200),
17807
+ radius: 4,
17808
+ fill: color,
17809
+ evented: false
17810
+ });
17811
+ ctx.fillStyle = "rgba(58, 96, 247, 1)";
17812
+ const offsetX = 6;
17813
+ const offsetY = 18 - 4;
17814
+ const maxTextWidth = 200 - 2 * 6;
17815
+ if (textWidth > maxTextWidth) {
17816
+ let truncatedText = "";
17817
+ let currentWidth = 0;
17818
+ for (const element of text) {
17819
+ const charWidth = ctx.measureText(element).width;
17820
+ if (currentWidth + charWidth <= maxTextWidth - ctx.measureText("...").width) {
17821
+ truncatedText += element;
17822
+ currentWidth += charWidth;
17823
+ } else {
17824
+ truncatedText += "...";
17825
+ break;
17826
+ }
17827
+ }
17828
+ ctx.fillText(truncatedText, offsetX, offsetY);
17829
+ } else ctx.fillText(text, offsetX, offsetY);
17830
+ ctx.restore();
17831
+ }
17832
+ _draw(ctx) {
17833
+ TextBubbleShape.drawWith(ctx, this);
17834
+ }
17835
+ };
17836
+
17837
+ //#endregion
17838
+ //#region src/controllers/doc-header-footer.controller.ts
17839
+ const HEADER_FOOTER_STROKE_COLOR = "rgba(58, 96, 247, 1)";
17840
+ const HEADER_FOOTER_FILL_COLOR = "rgba(58, 96, 247, 0.08)";
17841
+ function checkCreateHeaderFooterType(viewModel, editArea, segmentPage) {
17842
+ const { documentStyle } = viewModel.getDataModel().getSnapshot();
17843
+ const { defaultHeaderId, defaultFooterId, evenPageHeaderId, evenPageFooterId, firstPageHeaderId, firstPageFooterId, evenAndOddHeaders, useFirstPageHeaderFooter } = documentStyle;
17844
+ switch (editArea) {
17845
+ case _univerjs_engine_render.DocumentEditArea.BODY: return {
17846
+ createType: null,
17847
+ headerFooterId: null
17848
+ };
17849
+ case _univerjs_engine_render.DocumentEditArea.HEADER:
17850
+ if (useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE && !firstPageHeaderId) return {
17851
+ createType: _univerjs_docs.HeaderFooterType.FIRST_PAGE_HEADER,
17852
+ headerFooterId: null
17853
+ };
17854
+ if (evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageHeaderId) return {
17855
+ createType: _univerjs_docs.HeaderFooterType.EVEN_PAGE_HEADER,
17856
+ headerFooterId: null
17857
+ };
17858
+ return defaultHeaderId ? {
17859
+ createType: null,
17860
+ headerFooterId: defaultHeaderId
17861
+ } : {
17862
+ createType: _univerjs_docs.HeaderFooterType.DEFAULT_HEADER,
17863
+ headerFooterId: null
17864
+ };
17865
+ case _univerjs_engine_render.DocumentEditArea.FOOTER:
17866
+ if (useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE && !firstPageFooterId) return {
17867
+ createType: _univerjs_docs.HeaderFooterType.FIRST_PAGE_FOOTER,
17868
+ headerFooterId: null
17869
+ };
17870
+ if (evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageFooterId) return {
17871
+ createType: _univerjs_docs.HeaderFooterType.EVEN_PAGE_FOOTER,
17872
+ headerFooterId: null
17873
+ };
17874
+ return defaultFooterId ? {
17875
+ createType: null,
17876
+ headerFooterId: defaultFooterId
17877
+ } : {
17878
+ createType: _univerjs_docs.HeaderFooterType.DEFAULT_FOOTER,
17879
+ headerFooterId: null
17880
+ };
17881
+ default: throw new Error(`Invalid editArea: ${editArea}`);
17882
+ }
17883
+ }
17884
+ let DocHeaderFooterController = class DocHeaderFooterController extends _univerjs_core.Disposable {
17885
+ constructor(_context, _commandService, _editorService, _instanceSrv, _renderManagerService, _docSkeletonManagerService, _docSelectionRenderService, _localeService) {
17886
+ super();
17887
+ this._context = _context;
17888
+ this._commandService = _commandService;
17889
+ this._editorService = _editorService;
17890
+ this._instanceSrv = _instanceSrv;
17891
+ this._renderManagerService = _renderManagerService;
17892
+ this._docSkeletonManagerService = _docSkeletonManagerService;
17893
+ this._docSelectionRenderService = _docSelectionRenderService;
17894
+ this._localeService = _localeService;
17895
+ _defineProperty(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
17896
+ this._initialize();
17897
+ }
17898
+ _initialize() {
17899
+ this._init();
17900
+ this._drawHeaderFooterLabel();
17901
+ this._listenSwitchMode();
17902
+ }
17903
+ dispose() {
17904
+ super.dispose();
17905
+ }
17906
+ _listenSwitchMode() {
17907
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
17908
+ if (_univerjs_docs.RichTextEditingMutation.id === command.id) {
17909
+ const docDataModel = this._context.unit;
17910
+ const editArea = this._docSkeletonManagerService.getViewModel().getEditArea();
17911
+ const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
17912
+ if (editArea !== _univerjs_engine_render.DocumentEditArea.BODY && documentFlavor === _univerjs_core.DocumentFlavor.MODERN) this._commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId: this._context.unitId });
17913
+ }
17914
+ }));
17915
+ }
17916
+ _init() {
17917
+ const { unitId } = this._context;
17918
+ const docObject = neoGetDocObject(this._context);
17919
+ if (docObject == null || docObject.document == null) return;
17920
+ if (!this._loadedMap.has(docObject.document)) {
17921
+ this._initialMain(unitId);
17922
+ this._loadedMap.add(docObject.document);
17923
+ }
17924
+ }
17925
+ _initialMain(unitId) {
17926
+ const { document } = neoGetDocObject(this._context);
17927
+ this.disposeWithMe(document.onDblclick$.subscribeEvent(async (evt) => {
17928
+ if (this._isEditorReadOnly(unitId)) return;
17929
+ if (!this._isTraditionalMode()) return;
17930
+ const { offsetX, offsetY } = evt;
17931
+ const { pageLayoutType = _univerjs_engine_render.PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = document.getOffsetConfig();
17932
+ const coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
17933
+ if (coord == null) return;
17934
+ const viewModel = this._docSkeletonManagerService.getViewModel();
17935
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
17936
+ const preEditArea = viewModel.getEditArea();
17937
+ const { editArea, pageNumber } = skeleton.findEditAreaByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop);
17938
+ if (preEditArea === editArea) return;
17939
+ viewModel.setEditArea(editArea);
17940
+ const { createType, headerFooterId } = checkCreateHeaderFooterType(viewModel, editArea, pageNumber);
17941
+ if (editArea === _univerjs_engine_render.DocumentEditArea.BODY) {
17942
+ this._docSelectionRenderService.setSegment("");
17943
+ this._docSelectionRenderService.setSegmentPage(-1);
17944
+ this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
17945
+ } else if (createType != null) {
17946
+ const segmentId = (0, _univerjs_core.generateRandomId)(6);
17947
+ this._docSelectionRenderService.setSegment(segmentId);
17948
+ this._docSelectionRenderService.setSegmentPage(pageNumber);
17949
+ await this._commandService.executeCommand(CoreHeaderFooterCommand.id, {
17950
+ unitId,
17951
+ createType,
17952
+ segmentId
17953
+ });
17954
+ } else if (headerFooterId != null) {
17955
+ this._docSelectionRenderService.setSegment(headerFooterId);
17956
+ this._docSelectionRenderService.setSegmentPage(pageNumber);
17957
+ this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
17958
+ }
17959
+ }));
17960
+ }
17961
+ _getTransformCoordForDocumentOffset(evtOffsetX, evtOffsetY) {
17962
+ const { document, scene } = neoGetDocObject(this._context);
17963
+ const { documentTransform } = document.getOffsetConfig();
17964
+ const activeViewport = scene.getViewports()[0];
17965
+ if (activeViewport == null) return;
17966
+ const originCoord = activeViewport.transformVector2SceneCoord(_univerjs_engine_render.Vector2.FromArray([evtOffsetX, evtOffsetY]));
17967
+ return documentTransform.clone().invert().applyPoint(originCoord);
17968
+ }
17969
+ _drawHeaderFooterLabel() {
17970
+ const localeService = this._localeService;
17971
+ this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).subscribe((unit) => {
17972
+ if (unit == null) return;
17973
+ const unitId = unit.getUnitId();
17974
+ const currentRender = this._renderManagerService.getRenderUnitById(unitId);
17975
+ if (this._editorService.isEditor(unitId) || this._instanceSrv.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) == null) return;
17976
+ if (currentRender == null) return;
17977
+ const { mainComponent } = currentRender;
17978
+ const docsComponent = mainComponent;
17979
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(docsComponent.pageRender$.subscribe((config) => {
17980
+ if (this._editorService.isEditor(unitId)) return;
17981
+ if (!this._isTraditionalMode()) return;
17982
+ const isEditBody = this._docSkeletonManagerService.getViewModel().getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY;
17983
+ const { page, pageLeft, pageTop, ctx } = config;
17984
+ const { pageWidth, pageHeight, marginTop, marginBottom } = page;
17985
+ ctx.save();
17986
+ ctx.translate(pageLeft - .5, pageTop - .5);
17987
+ if (isEditBody) {
17988
+ _univerjs_engine_render.Rect.drawWith(ctx, {
17989
+ left: 0,
17990
+ top: 0,
17991
+ width: pageWidth,
17992
+ height: marginTop,
17993
+ fill: "rgba(255, 255, 255, 0.5)"
17994
+ });
17995
+ ctx.save();
17996
+ ctx.translate(0, pageHeight - marginBottom);
17997
+ _univerjs_engine_render.Rect.drawWith(ctx, {
17998
+ left: 0,
17999
+ top: 0,
18000
+ width: pageWidth,
18001
+ height: marginBottom,
18002
+ fill: "rgba(255, 255, 255, 0.5)"
18003
+ });
18004
+ ctx.restore();
18005
+ } else {
18006
+ ctx.save();
18007
+ ctx.translate(0, marginTop);
18008
+ _univerjs_engine_render.Rect.drawWith(ctx, {
18009
+ left: 0,
18010
+ top: marginTop,
18011
+ width: pageWidth,
18012
+ height: pageHeight - marginTop - marginBottom,
18013
+ fill: "rgba(255, 255, 255, 0.5)"
18014
+ });
18015
+ ctx.restore();
17785
18016
  }
17786
- if (text && Object.keys(QUICK_HEADING_MAP).includes(text)) {
17787
- const type = QUICK_HEADING_MAP[text];
17788
- return [{
17789
- id: QuickHeadingCommand.id,
17790
- params: { value: type }
17791
- }];
18017
+ if (!isEditBody) {
18018
+ const headerPathConfigIPathProps = {
18019
+ dataArray: [{
18020
+ command: "M",
18021
+ points: [0, marginTop]
18022
+ }, {
18023
+ command: "L",
18024
+ points: [pageWidth, marginTop]
18025
+ }],
18026
+ strokeWidth: 1,
18027
+ stroke: HEADER_FOOTER_STROKE_COLOR
18028
+ };
18029
+ const footerPathConfigIPathProps = {
18030
+ dataArray: [{
18031
+ command: "M",
18032
+ points: [0, pageHeight - marginBottom]
18033
+ }, {
18034
+ command: "L",
18035
+ points: [pageWidth, pageHeight - marginBottom]
18036
+ }],
18037
+ strokeWidth: 1,
18038
+ stroke: HEADER_FOOTER_STROKE_COLOR
18039
+ };
18040
+ _univerjs_engine_render.Path.drawWith(ctx, headerPathConfigIPathProps);
18041
+ _univerjs_engine_render.Path.drawWith(ctx, footerPathConfigIPathProps);
18042
+ ctx.translate(0, marginTop + 1);
18043
+ TextBubbleShape.drawWith(ctx, {
18044
+ text: localeService.t("docs-ui.headerFooter.header"),
18045
+ color: HEADER_FOOTER_FILL_COLOR
18046
+ });
18047
+ ctx.translate(0, pageHeight - marginTop - marginBottom);
18048
+ TextBubbleShape.drawWith(ctx, {
18049
+ text: localeService.t("docs-ui.headerFooter.footer"),
18050
+ color: HEADER_FOOTER_FILL_COLOR
18051
+ });
17792
18052
  }
17793
- return [];
17794
- }
18053
+ ctx.restore();
18054
+ })));
17795
18055
  }));
17796
18056
  }
17797
- _initExitListAutoFormat() {
17798
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17799
- id: EnterCommand.id,
17800
- match: (context) => {
17801
- const { paragraphs } = context;
17802
- if (paragraphs.length === 1 && paragraphs[0].bullet && paragraphs[0].paragraphStart === paragraphs[0].paragraphEnd) return true;
17803
- return false;
17804
- },
17805
- getMutations: (context) => {
17806
- const bullet = context.paragraphs[0].bullet;
17807
- if (!bullet) return [];
17808
- if (bullet.nestingLevel > 0) return [{
17809
- id: ChangeListNestingLevelCommand.id,
17810
- params: { type: -1 }
17811
- }];
17812
- return [{
17813
- id: ListOperationCommand.id,
17814
- params: { listType: context.paragraphs[0].bullet.listType }
17815
- }];
17816
- }
17817
- }));
18057
+ _isEditorReadOnly(unitId) {
18058
+ const editor = this._editorService.getEditor(unitId);
18059
+ if (!editor) return false;
18060
+ return editor.isReadOnly();
17818
18061
  }
17819
- _initDefaultEnterFormat() {
17820
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17821
- id: EnterCommand.id,
17822
- match: () => {
17823
- return true;
17824
- },
17825
- getMutations() {
17826
- return [{ id: BreakLineCommand.id }];
17827
- },
17828
- priority: -9999
17829
- }));
18062
+ _isTraditionalMode() {
18063
+ return this._context.unit.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL;
17830
18064
  }
17831
18065
  };
17832
- DocAutoFormatController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(DocAutoFormatService)), __decorateParam(1, _univerjs_engine_render.IRenderManagerService)], DocAutoFormatController);
18066
+ DocHeaderFooterController = __decorate([
18067
+ __decorateParam(1, _univerjs_core.ICommandService),
18068
+ __decorateParam(2, IEditorService),
18069
+ __decorateParam(3, _univerjs_core.IUniverInstanceService),
18070
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
18071
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
18072
+ __decorateParam(6, (0, _univerjs_core.Inject)(DocSelectionRenderService)),
18073
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
18074
+ ], DocHeaderFooterController);
17833
18075
 
17834
18076
  //#endregion
17835
18077
  //#region src/basics/table.ts
17836
- function firstLineInTable(table) {
17837
- return table.rows[0].cells[0].sections[0].columns[0].lines[0];
17838
- }
17839
- function lastLineInTable(table) {
17840
- const lastRow = table.rows[table.rows.length - 1];
17841
- const lastCell = lastRow.cells[lastRow.cells.length - 1];
17842
- return (0, _univerjs_engine_render.getLastLine)(lastCell);
17843
- }
17844
18078
  function findTableAfterLine(line, page) {
17845
18079
  const { ed } = line;
17846
18080
  const { skeTables } = page;
@@ -17851,86 +18085,6 @@ function findTableAfterLine(line, page) {
17851
18085
  }
17852
18086
  return table;
17853
18087
  }
17854
- function findLineBeforeAndAfterTable(table) {
17855
- const tablePage = table === null || table === void 0 ? void 0 : table.parent;
17856
- let lineBeforeTable = null;
17857
- let lineAfterTable = null;
17858
- if (table == null || tablePage == null) return {
17859
- lineBeforeTable,
17860
- lineAfterTable
17861
- };
17862
- const { st, ed } = table;
17863
- (0, _univerjs_engine_render.lineIterator)(tablePage.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? [tablePage] : tablePage.parent.pages, (l) => {
17864
- if (l.st === ed + 1) lineAfterTable = l;
17865
- else if (l.ed === st - 1) lineBeforeTable = l;
17866
- });
17867
- return {
17868
- lineBeforeTable,
17869
- lineAfterTable
17870
- };
17871
- }
17872
- function isEmptyCellPage(cell) {
17873
- return cell.sections[0].columns[0].lines.length === 0;
17874
- }
17875
- function findBellowCell(cell) {
17876
- const row = cell.parent;
17877
- const table = row === null || row === void 0 ? void 0 : row.parent;
17878
- const tableId = table === null || table === void 0 ? void 0 : table.tableId;
17879
- if (row == null || table == null) return;
17880
- const col = row.cells.indexOf(cell);
17881
- let bellowRow = table.rows[table.rows.indexOf(row) + 1];
17882
- if (bellowRow == null) {
17883
- if (tableId.indexOf("#-#")) {
17884
- var _table$parent;
17885
- const [id, index] = tableId.split("#-#");
17886
- const pages = (_table$parent = table.parent) === null || _table$parent === void 0 || (_table$parent = _table$parent.parent) === null || _table$parent === void 0 ? void 0 : _table$parent.pages;
17887
- const nextTableId = `${id}#-#${Number.parseInt(index) + 1}`;
17888
- if (pages) for (const page of pages) {
17889
- const { skeTables } = page;
17890
- if (skeTables.has(nextTableId)) {
17891
- const nextTable = skeTables.get(nextTableId);
17892
- if (nextTable === null || nextTable === void 0 ? void 0 : nextTable.rows.length) {
17893
- bellowRow = nextTable.rows.find((r) => !r.isRepeatRow);
17894
- break;
17895
- }
17896
- }
17897
- }
17898
- }
17899
- }
17900
- if (bellowRow != null) {
17901
- const cell = bellowRow.cells[col];
17902
- return isEmptyCellPage(cell) ? findBellowCell(cell) : cell;
17903
- }
17904
- }
17905
- function findAboveCell(cell) {
17906
- const row = cell.parent;
17907
- const table = row === null || row === void 0 ? void 0 : row.parent;
17908
- if (row == null || table == null) return;
17909
- let aboveRow = table.rows[table.rows.indexOf(row) - 1];
17910
- const col = row.cells.indexOf(cell);
17911
- if (aboveRow == null || aboveRow.isRepeatRow) {
17912
- if (table.tableId.indexOf("#-#")) {
17913
- var _table$parent2;
17914
- const [id, index] = table.tableId.split("#-#");
17915
- const pages = (_table$parent2 = table.parent) === null || _table$parent2 === void 0 || (_table$parent2 = _table$parent2.parent) === null || _table$parent2 === void 0 ? void 0 : _table$parent2.pages;
17916
- const nextTableId = `${id}#-#${Number.parseInt(index) - 1}`;
17917
- if (pages) for (const page of pages) {
17918
- const { skeTables } = page;
17919
- if (skeTables.has(nextTableId)) {
17920
- const nextTable = skeTables.get(nextTableId);
17921
- if (nextTable === null || nextTable === void 0 ? void 0 : nextTable.rows.length) {
17922
- aboveRow = nextTable.rows[nextTable.rows.length - 1];
17923
- break;
17924
- }
17925
- }
17926
- }
17927
- }
17928
- }
17929
- if (aboveRow != null) {
17930
- const cell = aboveRow.cells[col];
17931
- return isEmptyCellPage(cell) ? findAboveCell(cell) : cell;
17932
- }
17933
- }
17934
18088
  function findTableBeforeLine(line, page) {
17935
18089
  const { st } = line;
17936
18090
  const { skeTables } = page;
@@ -17983,10 +18137,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
17983
18137
  }));
17984
18138
  }
17985
18139
  _handleShiftMoveSelection(direction, granularity = "character") {
17986
- var _this$_renderManagerS, _dataStream$length;
18140
+ var _this$_renderManagerS, _docDataModel$getSelf, _body$dataStream$leng, _docDataModel$getCust;
17987
18141
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
17988
18142
  const allRanges = this._textSelectionManagerService.getTextRanges();
17989
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
18143
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
17990
18144
  if (docDataModel == null) return;
17991
18145
  const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(docDataModel.getUnitId())) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
17992
18146
  const docObject = this._getDocObject();
@@ -18010,16 +18164,21 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18010
18164
  }
18011
18165
  const anchorOffset = collapsed ? startOffset : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? startOffset : endOffset;
18012
18166
  let focusOffset = collapsed ? endOffset : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? endOffset : startOffset;
18013
- const dataStreamLength = (_dataStream$length = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody().dataStream.length) !== null && _dataStream$length !== void 0 ? _dataStream$length : Number.POSITIVE_INFINITY;
18167
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
18168
+ if (body == null) return;
18169
+ const dataStreamLength = (_body$dataStream$leng = body.dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : Number.POSITIVE_INFINITY;
18170
+ const customRanges = (_docDataModel$getCust = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust !== void 0 ? _docDataModel$getCust : [];
18014
18171
  if (granularity !== "character") {
18015
- const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength);
18172
+ const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
18016
18173
  if (nextOffset == null || nextOffset === focusOffset) return;
18174
+ const normalizedNextOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, nextOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18175
+ if (normalizedNextOffset == null || normalizedNextOffset === focusOffset) return;
18017
18176
  this._textSelectionManagerService.replaceTextRanges([{
18018
18177
  startOffset: anchorOffset,
18019
- endOffset: nextOffset,
18178
+ endOffset: normalizedNextOffset,
18020
18179
  style
18021
18180
  }], false);
18022
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), nextOffset);
18181
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), normalizedNextOffset);
18023
18182
  return;
18024
18183
  }
18025
18184
  if (direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.RIGHT) {
@@ -18040,8 +18199,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18040
18199
  const focusNodePosition = collapsed ? startNodePosition : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? endNodePosition : startNodePosition;
18041
18200
  const newPos = this._getTopOrBottomPosition(skeleton, focusGlyph, focusNodePosition, direction === _univerjs_core.Direction.DOWN, true);
18042
18201
  if (newPos == null) {
18043
- const newFocusOffset = direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18044
- if (newFocusOffset === focusOffset) return;
18202
+ const newFocusOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2, direction, normalizedSegmentId, normalizedSegmentPage);
18203
+ if (newFocusOffset == null || newFocusOffset === focusOffset) return;
18045
18204
  this._textSelectionManagerService.replaceTextRanges([{
18046
18205
  startOffset: anchorOffset,
18047
18206
  endOffset: newFocusOffset,
@@ -18050,19 +18209,21 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18050
18209
  return;
18051
18210
  }
18052
18211
  const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(newPos, newPos).cursorList[0];
18212
+ const newFocusOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, newActiveRange.endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18213
+ if (newFocusOffset == null || newFocusOffset === focusOffset) return;
18053
18214
  this._textSelectionManagerService.replaceTextRanges([{
18054
18215
  startOffset: anchorOffset,
18055
- endOffset: newActiveRange.endOffset,
18216
+ endOffset: newFocusOffset,
18056
18217
  style
18057
18218
  }], false);
18058
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), newActiveRange.endOffset);
18219
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), newFocusOffset);
18059
18220
  }
18060
18221
  }
18061
18222
  _handleMoveCursor(direction, granularity = "character") {
18062
- var _this$_renderManagerS2, _body$dataStream$leng, _docDataModel$getCust;
18223
+ var _this$_renderManagerS2, _docDataModel$getSelf2, _body$dataStream$leng2, _docDataModel$getCust2;
18063
18224
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
18064
18225
  const allRanges = this._textSelectionManagerService.getTextRanges();
18065
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
18226
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
18066
18227
  if (docDataModel == null) return false;
18067
18228
  const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
18068
18229
  const docObject = this._getDocObject();
@@ -18070,10 +18231,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18070
18231
  const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange;
18071
18232
  const normalizedSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : "";
18072
18233
  const normalizedSegmentPage = segmentPage !== null && segmentPage !== void 0 ? segmentPage : -1;
18073
- const body = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody();
18234
+ const body = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
18074
18235
  if (body == null) return;
18075
- const dataStreamLength = (_body$dataStream$leng = body.dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : Number.POSITIVE_INFINITY;
18076
- const customRanges = (_docDataModel$getCust = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust !== void 0 ? _docDataModel$getCust : [];
18236
+ const dataStreamLength = (_body$dataStream$leng2 = body.dataStream.length) !== null && _body$dataStream$leng2 !== void 0 ? _body$dataStream$leng2 : Number.POSITIVE_INFINITY;
18237
+ const customRanges = (_docDataModel$getCust2 = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust2 !== void 0 ? _docDataModel$getCust2 : [];
18077
18238
  if (granularity !== "character") {
18078
18239
  let cursorOffset;
18079
18240
  if (!activeRange.collapsed || allRanges.length > 1) {
@@ -18085,9 +18246,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18085
18246
  }
18086
18247
  cursorOffset = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? min : max;
18087
18248
  } else cursorOffset = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? startOffset : endOffset;
18088
- let cursor = this._getCursorOffsetByGranularity(skeleton, cursorOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength);
18249
+ let cursor = this._getCursorOffsetByGranularity(skeleton, cursorOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
18250
+ if (cursor == null) return;
18251
+ cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, cursor, direction, normalizedSegmentId, normalizedSegmentPage);
18089
18252
  if (cursor == null) return;
18090
- cursor = this._normalizeCursorOffset(body.dataStream, customRanges, cursor, direction);
18091
18253
  this._textSelectionManagerService.replaceTextRanges([{
18092
18254
  startOffset: cursor,
18093
18255
  endOffset: cursor,
@@ -18118,13 +18280,15 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18118
18280
  const skipTokens = [...this._getCursorSkipTokens()];
18119
18281
  if (direction === _univerjs_core.Direction.LEFT) while (skipTokens.includes(body.dataStream[cursor])) cursor--;
18120
18282
  else while (skipTokens.includes(body.dataStream[cursor])) cursor++;
18121
- cursor = this._normalizeWholeEntityRanges(customRanges, cursor, direction);
18283
+ cursor = this._normalizeCursorOffset(body.dataStream, customRanges, cursor, direction);
18284
+ const normalizedCursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, cursor, direction, normalizedSegmentId, normalizedSegmentPage);
18285
+ if (normalizedCursor == null) return;
18122
18286
  this._textSelectionManagerService.replaceTextRanges([{
18123
- startOffset: Math.max(0, cursor),
18124
- endOffset: Math.max(0, cursor),
18287
+ startOffset: normalizedCursor,
18288
+ endOffset: normalizedCursor,
18125
18289
  style
18126
18290
  }], false);
18127
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), cursor);
18291
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), normalizedCursor);
18128
18292
  } else {
18129
18293
  const startNode = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
18130
18294
  const endNode = skeleton.findNodeByCharIndex(endOffset, segmentId, segmentPage);
@@ -18132,31 +18296,55 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18132
18296
  const newPos = this._getTopOrBottomPosition(skeleton, direction === _univerjs_core.Direction.UP ? startNode : collapsed ? startNode : endNode, direction === _univerjs_core.Direction.UP ? startNodePosition : collapsed ? startNodePosition : endNodePosition, direction === _univerjs_core.Direction.DOWN);
18133
18297
  if (newPos == null) {
18134
18298
  let cursor;
18135
- if (collapsed) cursor = direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18136
- else cursor = direction === _univerjs_core.Direction.UP ? startOffset : endOffset;
18299
+ if (collapsed) cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2, direction, normalizedSegmentId, normalizedSegmentPage);
18300
+ else cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? startOffset : endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18301
+ if (cursor == null) return;
18137
18302
  this._textSelectionManagerService.replaceTextRanges([{
18138
- startOffset: Math.max(0, cursor),
18139
- endOffset: Math.max(0, cursor),
18303
+ startOffset: cursor,
18304
+ endOffset: cursor,
18140
18305
  style
18141
18306
  }], false);
18142
18307
  return;
18143
18308
  }
18144
18309
  const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(newPos, newPos).cursorList[0];
18310
+ const cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, newActiveRange.endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18311
+ if (cursor == null) return;
18145
18312
  this._textSelectionManagerService.replaceTextRanges([{
18146
- ...newActiveRange,
18313
+ startOffset: cursor,
18314
+ endOffset: cursor,
18147
18315
  style
18148
18316
  }], false);
18149
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), newActiveRange.endOffset);
18317
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), cursor);
18150
18318
  }
18151
18319
  }
18152
- _getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, segmentId, segmentPage, dataStreamLength) {
18320
+ _getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, segmentId, segmentPage, dataStreamLength, dataStream = "") {
18153
18321
  switch (granularity) {
18154
18322
  case "document": return direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18323
+ case "paragraph": return this._getParagraphBoundaryOffset(dataStream, focusOffset, direction);
18155
18324
  case "line": return this._getLineBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength);
18156
18325
  case "word": return this._getWordBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength);
18157
18326
  default: return null;
18158
18327
  }
18159
18328
  }
18329
+ _getParagraphBoundaryOffset(dataStream, focusOffset, direction) {
18330
+ if (direction !== _univerjs_core.Direction.UP && direction !== _univerjs_core.Direction.DOWN) return;
18331
+ if (dataStream.length === 0) return 0;
18332
+ const cursor = Math.min(Math.max(0, focusOffset), dataStream.length - 1);
18333
+ if (direction === _univerjs_core.Direction.UP) {
18334
+ const currentParagraphStart = this._getCurrentParagraphStartOffset(dataStream, cursor);
18335
+ if (cursor > currentParagraphStart) return currentParagraphStart;
18336
+ return this._getCurrentParagraphStartOffset(dataStream, Math.max(0, currentParagraphStart - 1));
18337
+ }
18338
+ const nextParagraphEnd = dataStream.indexOf(_univerjs_core.DataStreamTreeTokenType.PARAGRAPH, cursor);
18339
+ return nextParagraphEnd === -1 ? dataStream.length - 1 : nextParagraphEnd + 1;
18340
+ }
18341
+ _getCurrentParagraphStartOffset(dataStream, cursor) {
18342
+ for (let index = Math.min(cursor - 1, dataStream.length - 1); index >= 0; index--) {
18343
+ const token = dataStream[index];
18344
+ if (token === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || token === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK) return index + 1;
18345
+ }
18346
+ return 0;
18347
+ }
18160
18348
  _getWordBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength) {
18161
18349
  var _skeleton$findNodeByC;
18162
18350
  if (direction !== _univerjs_core.Direction.LEFT && direction !== _univerjs_core.Direction.RIGHT) return;
@@ -18207,6 +18395,30 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18207
18395
  else while (cursor < dataStream.length - 1 && skipTokens.includes(dataStream[cursor])) cursor++;
18208
18396
  return this._normalizeWholeEntityRanges(customRanges, cursor, direction);
18209
18397
  }
18398
+ _normalizeRenderableCursorOffset(skeleton, dataStream, customRanges, cursor, direction, segmentId, segmentPage) {
18399
+ const boundedCursor = Math.min(Math.max(0, cursor), Math.max(0, dataStream.length - 1));
18400
+ const primaryCursor = this._findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, boundedCursor, direction, segmentId, segmentPage);
18401
+ if (primaryCursor != null) return primaryCursor;
18402
+ const fallbackDirection = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? _univerjs_core.Direction.DOWN : _univerjs_core.Direction.UP;
18403
+ return this._findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, boundedCursor, fallbackDirection, segmentId, segmentPage);
18404
+ }
18405
+ _findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, cursor, direction, segmentId, segmentPage) {
18406
+ const step = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? -1 : 1;
18407
+ let current = Math.min(Math.max(0, cursor), Math.max(0, dataStream.length - 1));
18408
+ const visited = /* @__PURE__ */ new Set();
18409
+ while (current >= 0 && current < dataStream.length && !visited.has(current)) {
18410
+ visited.add(current);
18411
+ const normalizedCursor = this._normalizeCursorOffset(dataStream, customRanges, current, direction);
18412
+ if (normalizedCursor < 0 || normalizedCursor >= dataStream.length) return;
18413
+ if (this._isRenderableCursorOffset(skeleton, dataStream, normalizedCursor, segmentId, segmentPage)) return normalizedCursor;
18414
+ current = normalizedCursor + step;
18415
+ }
18416
+ }
18417
+ _isRenderableCursorOffset(skeleton, dataStream, cursor, segmentId, segmentPage) {
18418
+ if (cursor < 0 || cursor >= dataStream.length) return false;
18419
+ if (this._getNonRenderableCursorTokens().includes(dataStream[cursor])) return false;
18420
+ return skeleton.findNodePositionByCharIndex(cursor, true, segmentId, segmentPage) != null;
18421
+ }
18210
18422
  _normalizeWholeEntityRanges(customRanges, cursor, direction) {
18211
18423
  customRanges.filter((range) => range.wholeEntity && range.startIndex < cursor && range.endIndex >= cursor).forEach((range) => {
18212
18424
  if (direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP) cursor = Math.min(range.startIndex, cursor);
@@ -18229,12 +18441,21 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18229
18441
  if (includeParagraph) tokens.push(_univerjs_core.DataStreamTreeTokenType.PARAGRAPH);
18230
18442
  return tokens;
18231
18443
  }
18444
+ _getNonRenderableCursorTokens() {
18445
+ return [
18446
+ ...this._getCursorSkipTokens(),
18447
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_START,
18448
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_END,
18449
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_START,
18450
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_END
18451
+ ];
18452
+ }
18232
18453
  _getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction, skipCellContent = false) {
18233
18454
  if (glyph == null || nodePosition == null) return;
18234
18455
  const offsetLeft = this._getGlyphLeftOffsetInLine(glyph);
18235
- const line = this._getNextOrPrevLine(glyph, direction, skipCellContent);
18236
- if (line == null) return;
18237
- const position = this._matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition);
18456
+ const target = this._getNextOrPrevLineTarget(glyph, direction, offsetLeft, skipCellContent);
18457
+ if (target == null) return;
18458
+ const position = this._matchPositionByLeftOffset(docSkeleton, target.line, target.offsetLeft, nodePosition);
18238
18459
  if (position == null) return;
18239
18460
  return {
18240
18461
  ...position,
@@ -18249,11 +18470,24 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18249
18470
  return divideLeft + left;
18250
18471
  }
18251
18472
  _matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition) {
18473
+ var _nearestNode$glyph;
18252
18474
  const nearestNode = { distance: Number.POSITIVE_INFINITY };
18475
+ const nearestEmptyParagraphNode = { distance: Number.POSITIVE_INFINITY };
18253
18476
  for (const divide of line.divides) {
18254
18477
  const divideLeft = divide.left;
18255
18478
  for (const glyph of divide.glyphGroup) {
18256
- if (!this._isCursorAddressableGlyph(glyph)) continue;
18479
+ if (!this._isCursorAddressableGlyph(glyph)) {
18480
+ if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH && glyph.count > 0) {
18481
+ const { left } = glyph;
18482
+ const leftSide = divideLeft + left;
18483
+ const distance = Math.abs(offsetLeft - leftSide);
18484
+ if (distance < nearestEmptyParagraphNode.distance) {
18485
+ nearestEmptyParagraphNode.glyph = glyph;
18486
+ nearestEmptyParagraphNode.distance = distance;
18487
+ }
18488
+ }
18489
+ continue;
18490
+ }
18257
18491
  const { left } = glyph;
18258
18492
  const leftSide = divideLeft + left;
18259
18493
  const distance = Math.abs(offsetLeft - leftSide);
@@ -18263,11 +18497,12 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18263
18497
  }
18264
18498
  }
18265
18499
  }
18266
- if (nearestNode.glyph == null) return;
18500
+ const nearestGlyph = (_nearestNode$glyph = nearestNode.glyph) !== null && _nearestNode$glyph !== void 0 ? _nearestNode$glyph : nearestEmptyParagraphNode.glyph;
18501
+ if (nearestGlyph == null) return;
18267
18502
  const { segmentPage } = nodePosition;
18268
- return docSkeleton.findPositionByGlyph(nearestNode.glyph, segmentPage);
18503
+ return docSkeleton.findPositionByGlyph(nearestGlyph, segmentPage);
18269
18504
  }
18270
- _getNextOrPrevLine(glyph, direction, skipCellContent = false) {
18505
+ _getNextOrPrevLineTarget(glyph, direction, offsetLeft, skipCellContent = false) {
18271
18506
  const divide = glyph.parent;
18272
18507
  const line = divide === null || divide === void 0 ? void 0 : divide.parent;
18273
18508
  const column = line === null || line === void 0 ? void 0 : line.parent;
@@ -18277,26 +18512,25 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18277
18512
  const currentLineIndex = column.lines.indexOf(line);
18278
18513
  if (currentLineIndex === -1) return;
18279
18514
  let newLine;
18280
- if (page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL && skipCellContent) {
18281
- const nLine = findAboveOrBellowCellLine(page, direction);
18282
- if (nLine) return nLine;
18515
+ if (this._isTableCellContentPage(page) && skipCellContent) {
18516
+ const tableCellTarget = this._getAdjacentTableCellLineTarget(page, direction, offsetLeft);
18517
+ if (tableCellTarget != null) return tableCellTarget;
18283
18518
  }
18284
18519
  if (direction === true) {
18285
18520
  newLine = column.lines[currentLineIndex + 1];
18286
- const tableAfterLine = findTableAfterLine(line, page);
18287
- if (tableAfterLine) {
18288
- const firstLine = firstLineInTable(tableAfterLine);
18289
- if (firstLine) newLine = firstLine;
18290
- }
18521
+ const tableTarget = this._getTableLineTargetFromPageLine(line, page, direction, offsetLeft);
18522
+ if (tableTarget != null) return tableTarget;
18291
18523
  } else {
18292
18524
  newLine = column.lines[currentLineIndex - 1];
18293
- const tableBeforeLine = findTableBeforeLine(line, page);
18294
- if (tableBeforeLine) {
18295
- const lastLine = lastLineInTable(tableBeforeLine);
18296
- if (lastLine) newLine = lastLine;
18297
- }
18525
+ const tableTarget = this._getTableLineTargetFromPageLine(line, page, direction, offsetLeft);
18526
+ if (tableTarget != null) return tableTarget;
18298
18527
  }
18299
- if (newLine != null) return newLine;
18528
+ const columnGroupTarget = this._getColumnGroupLineTargetFromBlockLine(newLine, page, direction, offsetLeft);
18529
+ if (columnGroupTarget != null) return columnGroupTarget;
18530
+ if (newLine != null) return {
18531
+ line: newLine,
18532
+ offsetLeft
18533
+ };
18300
18534
  const currentColumnIndex = section.columns.indexOf(column);
18301
18535
  if (currentColumnIndex === -1) return;
18302
18536
  if (direction === true) {
@@ -18307,7 +18541,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18307
18541
  const prevColumnLines = (_section$columns2 = section.columns) === null || _section$columns2 === void 0 || (_section$columns2 = _section$columns2[currentColumnIndex - 1]) === null || _section$columns2 === void 0 ? void 0 : _section$columns2.lines;
18308
18542
  newLine = prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18309
18543
  }
18310
- if (newLine != null) return newLine;
18544
+ if (newLine != null) return {
18545
+ line: newLine,
18546
+ offsetLeft
18547
+ };
18311
18548
  const currentSectionIndex = page.sections.indexOf(section);
18312
18549
  if (currentSectionIndex === -1) return;
18313
18550
  if (direction === true) {
@@ -18320,8 +18557,15 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18320
18557
  const prevColumnLines = column === null || column === void 0 ? void 0 : column.lines;
18321
18558
  newLine = prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18322
18559
  }
18323
- if (newLine != null) return newLine;
18324
- if (page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL) return findAboveOrBellowCellLine(page, direction);
18560
+ if (newLine != null) return {
18561
+ line: newLine,
18562
+ offsetLeft
18563
+ };
18564
+ if (this._isColumnGroupContentPage(page)) {
18565
+ const exitTarget = this._getColumnGroupExitLineTarget(page, direction, offsetLeft);
18566
+ if (exitTarget != null) return exitTarget;
18567
+ }
18568
+ if (this._isTableCellContentPage(page)) return this._getAdjacentTableCellLineTarget(page, direction, offsetLeft);
18325
18569
  const skeleton = page.parent;
18326
18570
  if (skeleton == null) return;
18327
18571
  const currentPageIndex = skeleton.pages.indexOf(page);
@@ -18338,7 +18582,189 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18338
18582
  const prevColumnLines = column === null || column === void 0 ? void 0 : column.lines;
18339
18583
  newLine = prevColumnLines[prevColumnLines.length - 1];
18340
18584
  }
18341
- if (newLine != null) return newLine;
18585
+ if (newLine != null) return {
18586
+ line: newLine,
18587
+ offsetLeft
18588
+ };
18589
+ }
18590
+ _getTableLineTargetFromPageLine(line, page, direction, offsetLeft) {
18591
+ const table = direction ? findTableAfterLine(line, page) : findTableBeforeLine(line, page);
18592
+ if (table == null) return;
18593
+ return this._getTableBoundaryLineTarget(table, direction, offsetLeft);
18594
+ }
18595
+ _getTableBoundaryLineTarget(table, direction, offsetLeft) {
18596
+ const rows = direction ? table.rows : [...table.rows].reverse();
18597
+ for (const row of rows) {
18598
+ if (row.isRepeatRow) continue;
18599
+ const target = this._getNearestTableCellLineTarget(row.cells, direction, offsetLeft);
18600
+ if (target != null) return target;
18601
+ }
18602
+ }
18603
+ _getAdjacentTableCellLineTarget(cell, direction, offsetLeft) {
18604
+ const row = cell.parent;
18605
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18606
+ if (row == null || table == null) return;
18607
+ const hostOffsetLeft = this._getTableCellHostOffsetLeft(cell) + offsetLeft;
18608
+ const adjacentRow = this._findAdjacentTableRow(table, row, direction);
18609
+ if (adjacentRow != null) return this._getNearestTableCellLineTarget(adjacentRow.cells, direction, hostOffsetLeft);
18610
+ const line = this._findLineAroundTable(table, direction);
18611
+ if (line == null) return;
18612
+ return {
18613
+ line,
18614
+ offsetLeft: hostOffsetLeft
18615
+ };
18616
+ }
18617
+ _findAdjacentTableRow(table, row, direction) {
18618
+ const currentRowIndex = table.rows.indexOf(row);
18619
+ if (currentRowIndex === -1) return;
18620
+ const step = direction ? 1 : -1;
18621
+ let rowIndex = currentRowIndex + step;
18622
+ while (rowIndex >= 0 && rowIndex < table.rows.length) {
18623
+ const adjacentRow = table.rows[rowIndex];
18624
+ if (!adjacentRow.isRepeatRow) return adjacentRow;
18625
+ rowIndex += step;
18626
+ }
18627
+ return this._findAdjacentTableSliceRow(table, direction);
18628
+ }
18629
+ _findAdjacentTableSliceRow(table, direction) {
18630
+ if (!table.tableId.includes("#-#")) return;
18631
+ const [sourceTableId, sliceIndexText] = table.tableId.split("#-#");
18632
+ const sliceIndex = Number.parseInt(sliceIndexText);
18633
+ const tablePage = table.parent;
18634
+ const skeleton = tablePage === null || tablePage === void 0 ? void 0 : tablePage.parent;
18635
+ if (!Number.isFinite(sliceIndex) || (skeleton === null || skeleton === void 0 ? void 0 : skeleton.pages) == null) return;
18636
+ const nextTableId = `${sourceTableId}#-#${sliceIndex + (direction ? 1 : -1)}`;
18637
+ for (const page of skeleton.pages) {
18638
+ var _page$skeTables;
18639
+ const nextTable = (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 ? void 0 : _page$skeTables.get(nextTableId);
18640
+ const row = (nextTable == null ? [] : direction ? nextTable.rows : [...nextTable.rows].reverse()).find((item) => !item.isRepeatRow);
18641
+ if (row != null) return row;
18642
+ }
18643
+ }
18644
+ _getNearestTableCellLineTarget(cells, direction, hostOffsetLeft) {
18645
+ const candidates = cells.filter((cell) => !cell.isMergedCellCovered).map((cell) => ({
18646
+ cell,
18647
+ distance: this._getDistanceToTableCell(cell, hostOffsetLeft)
18648
+ })).sort((a, b) => a.distance - b.distance);
18649
+ for (const candidate of candidates) {
18650
+ const line = direction ? firstLineInCell(candidate.cell) : lastLineInCell(candidate.cell);
18651
+ if (line != null) return {
18652
+ line,
18653
+ offsetLeft: hostOffsetLeft - this._getTableCellHostOffsetLeft(candidate.cell)
18654
+ };
18655
+ }
18656
+ }
18657
+ _findLineAroundTable(table, direction) {
18658
+ var _pages, _tablePage$parent;
18659
+ const tablePage = table.parent;
18660
+ if (tablePage == null) return;
18661
+ const pages = (_pages = (_tablePage$parent = tablePage.parent) === null || _tablePage$parent === void 0 ? void 0 : _tablePage$parent.pages) !== null && _pages !== void 0 ? _pages : [tablePage];
18662
+ const lineMatcher = direction ? (line) => line.st === table.ed + 1 : (line) => line.ed === table.st - 1;
18663
+ for (const page of pages) for (const section of page.sections) for (const column of section.columns) {
18664
+ const line = (direction ? column.lines : [...column.lines].reverse()).find(lineMatcher);
18665
+ if (line != null) return line;
18666
+ }
18667
+ }
18668
+ _getDistanceToTableCell(cell, offsetLeft) {
18669
+ const left = this._getTableCellHostOffsetLeft(cell);
18670
+ const right = left + this._getTableCellContentWidth(cell);
18671
+ if (offsetLeft >= left && offsetLeft <= right) return 0;
18672
+ return Math.min(Math.abs(offsetLeft - left), Math.abs(offsetLeft - right));
18673
+ }
18674
+ _getTableCellHostOffsetLeft(cell) {
18675
+ var _table$left, _cell$left, _cell$marginLeft;
18676
+ const row = cell.parent;
18677
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18678
+ return ((_table$left = table === null || table === void 0 ? void 0 : table.left) !== null && _table$left !== void 0 ? _table$left : 0) + ((_cell$left = cell.left) !== null && _cell$left !== void 0 ? _cell$left : 0) + ((_cell$marginLeft = cell.marginLeft) !== null && _cell$marginLeft !== void 0 ? _cell$marginLeft : 0);
18679
+ }
18680
+ _getTableCellContentWidth(cell) {
18681
+ var _cell$pageWidth, _cell$marginLeft2, _cell$marginRight;
18682
+ return Math.max(0, ((_cell$pageWidth = cell.pageWidth) !== null && _cell$pageWidth !== void 0 ? _cell$pageWidth : 0) - ((_cell$marginLeft2 = cell.marginLeft) !== null && _cell$marginLeft2 !== void 0 ? _cell$marginLeft2 : 0) - ((_cell$marginRight = cell.marginRight) !== null && _cell$marginRight !== void 0 ? _cell$marginRight : 0));
18683
+ }
18684
+ _isTableCellContentPage(page) {
18685
+ var _table$rows;
18686
+ const row = page.parent;
18687
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18688
+ return page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL && row != null && (table === null || table === void 0 || (_table$rows = table.rows) === null || _table$rows === void 0 ? void 0 : _table$rows.includes(row)) === true && row.cells.includes(page);
18689
+ }
18690
+ _getColumnGroupLineTargetFromBlockLine(line, page, direction, offsetLeft) {
18691
+ if (line == null || line.type !== _univerjs_engine_render.LineType.BLOCK) return;
18692
+ const columnGroup = this._findColumnGroupByBlockLine(page, line);
18693
+ if (columnGroup == null) return;
18694
+ return this._getColumnGroupContentLineTarget(columnGroup, direction, offsetLeft);
18695
+ }
18696
+ _getColumnGroupContentLineTarget(columnGroup, direction, offsetLeft) {
18697
+ const candidates = columnGroup.columns.map((column) => ({
18698
+ column,
18699
+ distance: this._getDistanceToColumnGroupColumn(column, offsetLeft)
18700
+ })).sort((a, b) => a.distance - b.distance);
18701
+ for (const candidate of candidates) {
18702
+ const line = this._getColumnGroupColumnBoundaryLine(candidate.column, direction);
18703
+ if (line != null) return {
18704
+ line,
18705
+ offsetLeft: offsetLeft - candidate.column.left
18706
+ };
18707
+ }
18708
+ }
18709
+ _getColumnGroupExitLineTarget(page, direction, offsetLeft) {
18710
+ const columnGroupColumn = page.parent;
18711
+ const columnGroup = columnGroupColumn === null || columnGroupColumn === void 0 ? void 0 : columnGroupColumn.parent;
18712
+ const hostPage = columnGroup === null || columnGroup === void 0 ? void 0 : columnGroup.parent;
18713
+ if (columnGroupColumn == null || columnGroup == null || hostPage == null) return;
18714
+ const blockLine = this._findColumnGroupBlockLine(columnGroup);
18715
+ const line = blockLine == null ? void 0 : this._getAdjacentLineAroundBlockLine(blockLine, direction);
18716
+ if (line == null) return;
18717
+ return {
18718
+ line,
18719
+ offsetLeft: columnGroupColumn.left + offsetLeft
18720
+ };
18721
+ }
18722
+ _findColumnGroupByBlockLine(page, line) {
18723
+ var _page$skeColumnGroups, _page$skeColumnGroups2;
18724
+ for (const columnGroup of (_page$skeColumnGroups = (_page$skeColumnGroups2 = page.skeColumnGroups) === null || _page$skeColumnGroups2 === void 0 ? void 0 : _page$skeColumnGroups2.values()) !== null && _page$skeColumnGroups !== void 0 ? _page$skeColumnGroups : []) if (line.paragraphIndex === columnGroup.ed || line.st <= columnGroup.ed && line.ed >= columnGroup.st) return columnGroup;
18725
+ }
18726
+ _findColumnGroupBlockLine(columnGroup) {
18727
+ const page = columnGroup.parent;
18728
+ if (page == null) return;
18729
+ for (const section of page.sections) for (const column of section.columns) for (const line of column.lines) if (line.type === _univerjs_engine_render.LineType.BLOCK && this._findColumnGroupByBlockLine(page, line) === columnGroup) return line;
18730
+ }
18731
+ _getAdjacentLineAroundBlockLine(line, direction) {
18732
+ var _section$columns4;
18733
+ const column = line.parent;
18734
+ const section = column === null || column === void 0 ? void 0 : column.parent;
18735
+ const page = section === null || section === void 0 ? void 0 : section.parent;
18736
+ if (column == null || section == null || page == null) return;
18737
+ const lineIndex = column.lines.indexOf(line);
18738
+ if (lineIndex === -1) return;
18739
+ const sameColumnLine = column.lines[direction ? lineIndex + 1 : lineIndex - 1];
18740
+ if (sameColumnLine != null) return sameColumnLine;
18741
+ const columnIndex = section.columns.indexOf(column);
18742
+ if (columnIndex === -1) return;
18743
+ if (direction) {
18744
+ var _section$columns3;
18745
+ return (_section$columns3 = section.columns[columnIndex + 1]) === null || _section$columns3 === void 0 ? void 0 : _section$columns3.lines[0];
18746
+ }
18747
+ const prevColumnLines = (_section$columns4 = section.columns[columnIndex - 1]) === null || _section$columns4 === void 0 ? void 0 : _section$columns4.lines;
18748
+ return prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18749
+ }
18750
+ _getColumnGroupColumnBoundaryLine(column, direction) {
18751
+ const sections = direction ? column.page.sections : [...column.page.sections].reverse();
18752
+ for (const section of sections) {
18753
+ const columns = direction ? section.columns : [...section.columns].reverse();
18754
+ for (const skeletonColumn of columns) {
18755
+ const line = (direction ? skeletonColumn.lines : [...skeletonColumn.lines].reverse()).find((item) => item.type !== _univerjs_engine_render.LineType.BLOCK);
18756
+ if (line != null) return line;
18757
+ }
18758
+ }
18759
+ }
18760
+ _getDistanceToColumnGroupColumn(column, offsetLeft) {
18761
+ if (offsetLeft >= column.left && offsetLeft <= column.left + column.width) return 0;
18762
+ return Math.min(Math.abs(offsetLeft - column.left), Math.abs(offsetLeft - column.left - column.width));
18763
+ }
18764
+ _isColumnGroupContentPage(page) {
18765
+ var _parent$parent;
18766
+ const parent = page.parent;
18767
+ return (parent === null || parent === void 0 ? void 0 : parent.page) === page && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 || (_parent$parent = _parent$parent.columns) === null || _parent$parent === void 0 ? void 0 : _parent$parent.includes(parent)) === true;
18342
18768
  }
18343
18769
  _scrollToFocusNodePosition(unitId, offset) {
18344
18770
  var _this$_renderManagerS3;
@@ -18360,27 +18786,6 @@ DocMoveCursorController = __decorate([
18360
18786
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
18361
18787
  __decorateParam(3, _univerjs_core.ICommandService)
18362
18788
  ], DocMoveCursorController);
18363
- function findAboveOrBellowCellLine(page, direction) {
18364
- let newLine = null;
18365
- if (direction === true) {
18366
- const bellowCell = findBellowCell(page);
18367
- if (bellowCell) newLine = firstLineInCell(bellowCell);
18368
- else {
18369
- var _page$parent;
18370
- const { lineAfterTable } = findLineBeforeAndAfterTable((_page$parent = page.parent) === null || _page$parent === void 0 ? void 0 : _page$parent.parent);
18371
- if (lineAfterTable) newLine = lineAfterTable;
18372
- }
18373
- } else {
18374
- const aboveCell = findAboveCell(page);
18375
- if (aboveCell) newLine = lastLineInCell(aboveCell);
18376
- else {
18377
- var _page$parent2;
18378
- const { lineBeforeTable } = findLineBeforeAndAfterTable((_page$parent2 = page.parent) === null || _page$parent2 === void 0 ? void 0 : _page$parent2.parent);
18379
- if (lineBeforeTable) newLine = lineBeforeTable;
18380
- }
18381
- }
18382
- return newLine;
18383
- }
18384
18789
 
18385
18790
  //#endregion
18386
18791
  //#region src/controllers/doc-table.controller.ts
@@ -18594,7 +18999,7 @@ let DocEditorBridgeController = class DocEditorBridgeController extends _univerj
18594
18999
  if (unitId == null) return;
18595
19000
  const editor = this._editorService.getEditor(unitId);
18596
19001
  if ((editor === null || editor === void 0 ? void 0 : editor.cancelDefaultResizeListener) === true) return;
18597
- const editorDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
19002
+ const editorDataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
18598
19003
  if (!editorDataModel) return;
18599
19004
  const skeleton = this._docSkeletonManagerService.getSkeleton();
18600
19005
  if (editor == null || editor.render == null || skeleton == null || editorDataModel == null) return;
@@ -18809,7 +19214,7 @@ let DocInputController = class DocInputController extends _univerjs_core.Disposa
18809
19214
  }
18810
19215
  _initialNormalInput() {
18811
19216
  this._onInputSubscription = this._docSelectionRenderService.onInput$.subscribe(async (config) => {
18812
- var _originBody$customRan, _originBody$customDec;
19217
+ var _docDataModel$getSelf, _originBody$customRan, _originBody$customDec;
18813
19218
  if (config == null) return;
18814
19219
  const { unitId } = this._context;
18815
19220
  const { event, content = "", activeRange } = config;
@@ -18818,7 +19223,8 @@ let DocInputController = class DocInputController extends _univerjs_core.Disposa
18818
19223
  const skeleton = this._docSkeletonManagerService.getSkeleton();
18819
19224
  if (e.data == null || skeleton == null || activeRange == null) return;
18820
19225
  const { segmentId } = activeRange;
18821
- const originBody = this._context.unit.getSelfOrHeaderFooterModel(segmentId).getBody();
19226
+ const originBody = (_docDataModel$getSelf = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
19227
+ if (!originBody) return;
18822
19228
  const defaultTextStyle = this._docMenuStyleService.getDefaultStyle();
18823
19229
  const cacheStyle = this._docMenuStyleService.getStyleCache();
18824
19230
  const curCustomRange = getCustomRangeAtPosition((_originBody$customRan = originBody === null || originBody === void 0 ? void 0 : originBody.customRanges) !== null && _originBody$customRan !== void 0 ? _originBody$customRan : [], activeRange.endOffset, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
@@ -19075,11 +19481,11 @@ let DocZoomRenderController = class DocZoomRenderController extends _univerjs_co
19075
19481
  _initSkeletonListener() {
19076
19482
  this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((param) => {
19077
19483
  if (param == null) return;
19078
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
19484
+ const documentModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
19079
19485
  if (!documentModel) return;
19080
19486
  this._updateTimer = window.setTimeout(() => {
19081
19487
  const currentSheet = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
19082
- const sheetRenderer = currentSheet && this._renderManagerService.getRenderById(currentSheet.getUnitId());
19488
+ const sheetRenderer = currentSheet && this._renderManagerService.getRenderUnitById(currentSheet.getUnitId());
19083
19489
  const zoomRatio = !this._isSheetEditor ? getDocEffectiveZoomRatio(documentModel) : (sheetRenderer === null || sheetRenderer === void 0 ? void 0 : sheetRenderer.scene.scaleX) || 1;
19084
19490
  this.updateViewZoom(zoomRatio, false);
19085
19491
  });
@@ -19115,7 +19521,7 @@ let DocZoomRenderController = class DocZoomRenderController extends _univerjs_co
19115
19521
  _initZoomEventListener() {
19116
19522
  const scene = this._context.scene;
19117
19523
  this.disposeWithMe(scene.onMouseWheel$.subscribeEvent((e) => {
19118
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
19524
+ const documentModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
19119
19525
  if (!documentModel) return;
19120
19526
  const { documentFlavor } = documentModel.getSnapshot().documentStyle;
19121
19527
  if (!shouldHandleDocWheelZoom(e, Boolean(this._contextService.getContextValue(_univerjs_core.FOCUSING_DOC)), documentFlavor)) return;
@@ -19269,6 +19675,11 @@ const DeleteRightShortcut = {
19269
19675
  preconditions: whenDocAndEditorFocused,
19270
19676
  binding: _univerjs_ui.KeyCode.DELETE
19271
19677
  };
19678
+ const CloseHeaderFooterShortcut = {
19679
+ id: CloseHeaderFooterCommand.id,
19680
+ preconditions: whenDocAndEditorFocused,
19681
+ binding: _univerjs_ui.KeyCode.ESC
19682
+ };
19272
19683
 
19273
19684
  //#endregion
19274
19685
  //#region src/shortcuts/cursor.shortcut.ts
@@ -19360,6 +19771,10 @@ const MoveCursorWordLeftShortcut = moveCursorShortcut(_univerjs_core.Direction.L
19360
19771
  const MoveCursorWordRightShortcut = moveCursorShortcut(_univerjs_core.Direction.RIGHT, "word", _univerjs_ui.KeyCode.ARROW_RIGHT | _univerjs_ui.MetaKeys.CTRL_COMMAND, _univerjs_ui.KeyCode.ARROW_RIGHT | _univerjs_ui.MetaKeys.ALT);
19361
19772
  const MoveSelectionWordLeftShortcut = moveSelectionShortcut(_univerjs_core.Direction.LEFT, "word", _univerjs_ui.KeyCode.ARROW_LEFT | _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT, _univerjs_ui.KeyCode.ARROW_LEFT | _univerjs_ui.MetaKeys.ALT | _univerjs_ui.MetaKeys.SHIFT);
19362
19773
  const MoveSelectionWordRightShortcut = moveSelectionShortcut(_univerjs_core.Direction.RIGHT, "word", _univerjs_ui.KeyCode.ARROW_RIGHT | _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT, _univerjs_ui.KeyCode.ARROW_RIGHT | _univerjs_ui.MetaKeys.ALT | _univerjs_ui.MetaKeys.SHIFT);
19774
+ const MoveCursorParagraphUpShortcut = moveCursorShortcut(_univerjs_core.Direction.UP, "paragraph", _univerjs_ui.KeyCode.ARROW_UP | _univerjs_ui.MetaKeys.CTRL_COMMAND, _univerjs_ui.KeyCode.ARROW_UP | _univerjs_ui.MetaKeys.ALT);
19775
+ const MoveCursorParagraphDownShortcut = moveCursorShortcut(_univerjs_core.Direction.DOWN, "paragraph", _univerjs_ui.KeyCode.ARROW_DOWN | _univerjs_ui.MetaKeys.CTRL_COMMAND, _univerjs_ui.KeyCode.ARROW_DOWN | _univerjs_ui.MetaKeys.ALT);
19776
+ const MoveSelectionParagraphUpShortcut = moveSelectionShortcut(_univerjs_core.Direction.UP, "paragraph", _univerjs_ui.KeyCode.ARROW_UP | _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT, _univerjs_ui.KeyCode.ARROW_UP | _univerjs_ui.MetaKeys.ALT | _univerjs_ui.MetaKeys.SHIFT);
19777
+ const MoveSelectionParagraphDownShortcut = moveSelectionShortcut(_univerjs_core.Direction.DOWN, "paragraph", _univerjs_ui.KeyCode.ARROW_DOWN | _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT, _univerjs_ui.KeyCode.ARROW_DOWN | _univerjs_ui.MetaKeys.ALT | _univerjs_ui.MetaKeys.SHIFT);
19363
19778
  const SelectAllShortcut = {
19364
19779
  id: DocSelectAllCommand.id,
19365
19780
  binding: _univerjs_ui.KeyCode.A | _univerjs_ui.MetaKeys.CTRL_COMMAND,
@@ -19491,7 +19906,6 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19491
19906
  InsertCustomRangeCommand,
19492
19907
  SetParagraphNamedStyleCommand,
19493
19908
  QuickHeadingCommand,
19494
- DeleteCurrentParagraphCommand,
19495
19909
  DocCopyCurrentParagraphCommand,
19496
19910
  DocCutCurrentParagraphCommand,
19497
19911
  H1HeadingCommand,
@@ -19514,7 +19928,8 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19514
19928
  [
19515
19929
  DocCopyCommand,
19516
19930
  DocCutCommand,
19517
- DocPasteCommand
19931
+ DocPasteCommand,
19932
+ DeleteCurrentParagraphCommand
19518
19933
  ].forEach((command) => this.disposeWithMe(this._commandService.registerMultipleCommand(command)));
19519
19934
  }
19520
19935
  _initializeShortcut() {
@@ -19531,6 +19946,10 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19531
19946
  MoveCursorLineEndShortcut,
19532
19947
  MoveSelectionLineStartShortcut,
19533
19948
  MoveSelectionLineEndShortcut,
19949
+ MoveCursorParagraphUpShortcut,
19950
+ MoveCursorParagraphDownShortcut,
19951
+ MoveSelectionParagraphUpShortcut,
19952
+ MoveSelectionParagraphDownShortcut,
19534
19953
  MoveCursorDocumentStartShortcut,
19535
19954
  MoveCursorDocumentEndShortcut,
19536
19955
  MoveSelectionDocumentStartShortcut,
@@ -19542,6 +19961,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19542
19961
  SelectAllShortcut,
19543
19962
  DeleteLeftShortcut,
19544
19963
  DeleteRightShortcut,
19964
+ CloseHeaderFooterShortcut,
19545
19965
  BreakLineShortcut,
19546
19966
  SoftBreakLineShortcut,
19547
19967
  ShiftTabShortCut,
@@ -19568,6 +19988,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19568
19988
  [DocParagraphSettingController],
19569
19989
  [IEditorService, { useClass: EditorService }],
19570
19990
  [IDocClipboardService, { useClass: DocClipboardService }],
19991
+ [DocHtmlExportService],
19571
19992
  [DocCanvasPopManagerService],
19572
19993
  [DocsRenderService],
19573
19994
  [_univerjs_docs.IDocStateChangeInterceptorService, { useClass: DocIMEStateChangeInterceptorService }],
@@ -19626,7 +20047,7 @@ _defineProperty(UniverDocsUIPlugin, "pluginName", "DOC_UI_PLUGIN");
19626
20047
  _defineProperty(UniverDocsUIPlugin, "packageName", name);
19627
20048
  _defineProperty(UniverDocsUIPlugin, "version", version);
19628
20049
  UniverDocsUIPlugin = __decorate([
19629
- (0, _univerjs_core.DependentOn)(_univerjs_engine_render.UniverRenderEnginePlugin),
20050
+ (0, _univerjs_core.DependentOn)(_univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_docs.UniverDocsPlugin),
19630
20051
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
19631
20052
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
19632
20053
  __decorateParam(3, _univerjs_core.ICommandService),
@@ -20223,6 +20644,7 @@ exports.DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID = DOC_PARAGRAPH_T_INSERT_BELOW_MENU
20223
20644
  exports.DOC_PARAGRAPH_T_INSERT_MENU_ID = DOC_PARAGRAPH_T_INSERT_MENU_ID;
20224
20645
  exports.DOC_TABLE_BLOCK_MENU_ID = DOC_TABLE_BLOCK_MENU_ID;
20225
20646
  exports.DOC_VERTICAL_PADDING = DOC_VERTICAL_PADDING;
20647
+ exports.DeleteCurrentParagraphCommand = DeleteCurrentParagraphCommand;
20226
20648
  exports.DeleteCustomBlockCommand = DeleteCustomBlockCommand;
20227
20649
  exports.DeleteLeftCommand = DeleteLeftCommand;
20228
20650
  exports.DeleteRightCommand = DeleteRightCommand;
@@ -20253,6 +20675,7 @@ Object.defineProperty(exports, 'DocEventManagerService', {
20253
20675
  return DocEventManagerService;
20254
20676
  }
20255
20677
  });
20678
+ exports.DocHtmlExportService = DocHtmlExportService;
20256
20679
  exports.DocIMEInputManagerService = DocIMEInputManagerService;
20257
20680
  Object.defineProperty(exports, 'DocParagraphMenuService', {
20258
20681
  enumerable: true,
@@ -20393,6 +20816,7 @@ exports.convertBodyToHtml = convertBodyToHtml;
20393
20816
  exports.convertPositionsToRectRanges = convertPositionsToRectRanges;
20394
20817
  exports.createEditorUndoRedoKeyboardConfig = createEditorUndoRedoKeyboardConfig;
20395
20818
  exports.deleteCustomDecorationFactory = deleteCustomDecorationFactory;
20819
+ exports.disableMenuWhenHeaderFooterEditing = disableMenuWhenHeaderFooterEditing;
20396
20820
  exports.docDrawingPositionToTransform = docDrawingPositionToTransform;
20397
20821
  exports.executeEditorUndoRedoCommand = executeEditorUndoRedoCommand;
20398
20822
  exports.genTableSource = genTableSource;