@univerjs/docs-ui 1.0.0-alpha.0 → 1.0.0-insiders.20260629-12f2e44

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
@@ -3595,14 +3595,36 @@ function hasVisibleHtml(html) {
3595
3595
  return /<(?:img|br)\b/i.test(html) || html.replace(/<[^>]+>/g, "").replace(/&nbsp;/gi, " ").trim().length > 0;
3596
3596
  }
3597
3597
  var UDMToHtmlService = class {
3598
+ constructor(_docHtmlExportService) {
3599
+ this._docHtmlExportService = _docHtmlExportService;
3600
+ }
3598
3601
  convert(docList) {
3599
3602
  if (docList.length === 0) throw new Error("The bodyList length at least to be 1");
3600
3603
  let html = "";
3601
- for (const doc of _univerjs_core.Tools.deepClone(docList)) html += convertBodyToHtml(doc);
3604
+ for (const doc of _univerjs_core.Tools.deepClone(docList)) {
3605
+ var _this$_docHtmlExportS, _this$_docHtmlExportS2;
3606
+ 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);
3607
+ }
3602
3608
  return html;
3603
3609
  }
3604
3610
  };
3605
3611
 
3612
+ //#endregion
3613
+ //#region src/services/clipboard/udm-to-html/doc-html-export.service.ts
3614
+ var DocHtmlExportService = class extends _univerjs_core.Disposable {
3615
+ constructor(..._args) {
3616
+ super(..._args);
3617
+ _defineProperty(this, "_transformers", []);
3618
+ }
3619
+ registerTransformer(transformer) {
3620
+ this._transformers.push(transformer);
3621
+ return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._transformers, transformer)));
3622
+ }
3623
+ transformDocumentForHtmlExport(documentData) {
3624
+ return this._transformers.reduce((doc, transformer) => transformer(doc), documentData);
3625
+ }
3626
+ };
3627
+
3606
3628
  //#endregion
3607
3629
  //#region src/services/clipboard/clipboard.service.ts
3608
3630
  HtmlToUDMService.use(LarkPastePlugin);
@@ -3640,7 +3662,7 @@ function getTableCellContentClipboardBodySlice(body, start, end) {
3640
3662
  }
3641
3663
  const IDocClipboardService = (0, _univerjs_core.createIdentifier)("doc.clipboard-service");
3642
3664
  let DocClipboardService = class DocClipboardService extends _univerjs_core.Disposable {
3643
- constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, _docSelectionManagerService) {
3665
+ constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, docHtmlExportService, _docSelectionManagerService) {
3644
3666
  super();
3645
3667
  this._univerInstanceService = _univerInstanceService;
3646
3668
  this._logService = _logService;
@@ -3649,7 +3671,8 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3649
3671
  this._docSelectionManagerService = _docSelectionManagerService;
3650
3672
  _defineProperty(this, "_clipboardHooks", []);
3651
3673
  _defineProperty(this, "_htmlToUDM", new HtmlToUDMService());
3652
- _defineProperty(this, "_umdToHtml", new UDMToHtmlService());
3674
+ _defineProperty(this, "_umdToHtml", void 0);
3675
+ this._umdToHtml = new UDMToHtmlService(docHtmlExportService);
3653
3676
  }
3654
3677
  async copy(sliceType = _univerjs_core.SliceBodyType.copy, ranges) {
3655
3678
  var _this$_getDocumentBod;
@@ -4005,7 +4028,8 @@ DocClipboardService = __decorate([
4005
4028
  __decorateParam(1, _univerjs_core.ILogService),
4006
4029
  __decorateParam(2, _univerjs_core.ICommandService),
4007
4030
  __decorateParam(3, _univerjs_ui.IClipboardInterfaceService),
4008
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
4031
+ __decorateParam(4, (0, _univerjs_core.Inject)(DocHtmlExportService)),
4032
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
4009
4033
  ], DocClipboardService);
4010
4034
  function dataUrlToFile(dataUrl, fallbackName) {
4011
4035
  const match = /^data:([^;,]+)(;base64)?,(.*)$/i.exec(dataUrl);
@@ -4100,11 +4124,18 @@ const MoveDocBlockCommand = {
4100
4124
  const doc = params.unitId ? univerInstanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUniverDocInstance();
4101
4125
  if (!doc) return false;
4102
4126
  const previousDocumentData = doc.getSnapshot();
4103
- const { nextDocumentData, movedRange } = buildMoveDocBlockActions({
4127
+ const moveResult = buildMoveDocBlockActions({
4104
4128
  documentData: previousDocumentData,
4105
4129
  sourceRange: params.sourceRange,
4106
4130
  targetOffset: params.targetOffset
4107
4131
  });
4132
+ const { nextDocumentData, movedRange } = accessor.get(_univerjs_docs.DocBlockMoveValidatorService).transformMoveResult({
4133
+ unitId: doc.getUnitId(),
4134
+ sourceRange: params.sourceRange,
4135
+ targetOffset: params.targetOffset,
4136
+ previousDocumentData,
4137
+ result: moveResult
4138
+ });
4108
4139
  const actions = buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData);
4109
4140
  if (!actions) return false;
4110
4141
  const textRanges = [{
@@ -4161,6 +4192,7 @@ function buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData)
4161
4192
  jsonX.replaceOp(["body", "paragraphs"], previousBody.paragraphs, nextBody.paragraphs),
4162
4193
  jsonX.replaceOp(["body", "sectionBreaks"], previousBody.sectionBreaks, nextBody.sectionBreaks),
4163
4194
  jsonX.replaceOp(["body", "tables"], previousBody.tables, nextBody.tables),
4195
+ jsonX.replaceOp(["body", "columnGroups"], previousBody.columnGroups, nextBody.columnGroups),
4164
4196
  jsonX.replaceOp(["body", "customBlocks"], previousBody.customBlocks, nextBody.customBlocks),
4165
4197
  jsonX.replaceOp(["body", "blockRanges"], previousBody.blockRanges, nextBody.blockRanges),
4166
4198
  jsonX.replaceOp(["body", "customRanges"], previousBody.customRanges, nextBody.customRanges),
@@ -4169,7 +4201,7 @@ function buildReplaceDocumentBodyActions(previousDocumentData, nextDocumentData)
4169
4201
  ].filter(Boolean).reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur), null);
4170
4202
  }
4171
4203
  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;
4204
+ var _body$paragraphs, _body$sectionBreaks, _body$customBlocks, _body$tables, _body$columnGroups, _body$blockRanges, _body$customRanges, _body$customDecoratio, _body$textRuns;
4173
4205
  body.paragraphs = (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.map((paragraph) => ({
4174
4206
  ...paragraph,
4175
4207
  startIndex: remapIndexAfterMove(paragraph.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
@@ -4183,6 +4215,7 @@ function remapBodyIndexesAfterMove(body, startOffset, endOffset, targetOffset, i
4183
4215
  startIndex: remapIndexAfterMove(customBlock.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4184
4216
  })).sort((left, right) => left.startIndex - right.startIndex);
4185
4217
  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);
4218
+ 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
4219
  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
4220
  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
4221
  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 +4240,7 @@ function remapExclusiveRange(range, startOffset, endOffset, targetOffset, insert
4207
4240
  return {
4208
4241
  ...range,
4209
4242
  startIndex: remapIndexAfterMove(range.startIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength),
4210
- endIndex: remapIndexAfterMove(range.endIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4243
+ endIndex: remapExclusiveEndIndexAfterMove(range.endIndex, startOffset, endOffset, targetOffset, insertOffset, moveLength)
4211
4244
  };
4212
4245
  }
4213
4246
  function remapInclusiveRange(range, startOffset, endOffset, targetOffset, insertOffset, moveLength) {
@@ -4228,6 +4261,11 @@ function remapIndexAfterMove(index, startOffset, endOffset, targetOffset, insert
4228
4261
  if (targetOffset > endOffset && index >= endOffset && index < targetOffset) return index - moveLength;
4229
4262
  return index;
4230
4263
  }
4264
+ function remapExclusiveEndIndexAfterMove(index, startOffset, endOffset, targetOffset, insertOffset, moveLength) {
4265
+ if (index > startOffset && index <= endOffset) return insertOffset + index - startOffset;
4266
+ if (targetOffset > endOffset && index >= endOffset && index <= targetOffset) return index - moveLength;
4267
+ return remapIndexAfterMove(index, startOffset, endOffset, targetOffset, insertOffset, moveLength);
4268
+ }
4231
4269
  function clamp$1(value, min, max) {
4232
4270
  return Math.min(Math.max(value, min), max);
4233
4271
  }
@@ -5911,6 +5949,8 @@ const NodePositionMap = {
5911
5949
  glyph: 5
5912
5950
  };
5913
5951
  function compareNodePositionLogic(pos1, pos2) {
5952
+ const nestedPagePathOrder = (0, _univerjs_engine_render.compareDocumentSkeletonNestedPagePathOrder)(pos1, pos2);
5953
+ if (nestedPagePathOrder != null) return nestedPagePathOrder;
5914
5954
  if (pos1.page > pos2.page) return false;
5915
5955
  if (pos1.page < pos2.page) return true;
5916
5956
  if (pos1.section > pos2.section) return false;
@@ -6206,9 +6246,18 @@ var NodePositionConvertToCursor = class {
6206
6246
  break;
6207
6247
  }
6208
6248
  case _univerjs_engine_render.DocumentSkeletonPageType.CELL: {
6249
+ const nestedPageOffset = (0, _univerjs_engine_render.getDocumentSkeletonNestedPageOffset)(segmentPage);
6250
+ if (nestedPageOffset) {
6251
+ this._liquid.translatePagePadding(page);
6252
+ this._liquid.translate(nestedPageOffset.left, nestedPageOffset.top);
6253
+ this._liquid.translatePagePadding(segmentPage);
6254
+ break;
6255
+ }
6209
6256
  this._liquid.translatePagePadding(page);
6210
6257
  const rowSke = segmentPage.parent;
6211
6258
  const tableSke = rowSke.parent;
6259
+ const tablePage = tableSke.parent;
6260
+ const tablePageNestedOffset = tablePage ? (0, _univerjs_engine_render.getDocumentSkeletonNestedPageOffset)(tablePage) : void 0;
6212
6261
  const { left: cellLeft } = segmentPage;
6213
6262
  const { top: tableTop, left: tableLeft } = tableSke;
6214
6263
  const { top: rowTop } = rowSke;
@@ -6216,6 +6265,10 @@ var NodePositionConvertToCursor = class {
6216
6265
  const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(getDocumentUnitId$1(skeleton), sourceTableId);
6217
6266
  const hasHorizontalViewport = hasHorizontalTableViewport$2(viewport);
6218
6267
  const scrollLeft = hasHorizontalViewport ? viewport.scrollLeft : 0;
6268
+ if (tablePageNestedOffset) {
6269
+ this._liquid.translate(tablePageNestedOffset.left, tablePageNestedOffset.top);
6270
+ this._liquid.translatePagePadding(tablePage);
6271
+ }
6219
6272
  if (hasHorizontalViewport) {
6220
6273
  var _viewport$leadingInse;
6221
6274
  const visibleLeft = this._liquid.x + tableLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
@@ -6317,8 +6370,14 @@ function isInSameTableCell(anchorNodePosition, focusNodePosition) {
6317
6370
  const { path: anchorPath } = anchorNodePosition;
6318
6371
  const { path: focusPath } = focusNodePosition;
6319
6372
  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);
6373
+ const anchorTableIdIndex = anchorPath.indexOf("skeTables") + 1;
6374
+ const anchorRowIndex = anchorPath.indexOf("rows") + 1;
6375
+ const anchorCellIndex = anchorPath.indexOf("cells") + 1;
6376
+ const focusTableIdIndex = focusPath.indexOf("skeTables") + 1;
6377
+ const focusRowIndex = focusPath.indexOf("rows") + 1;
6378
+ const focusCellIndex = focusPath.indexOf("cells") + 1;
6379
+ if (anchorTableIdIndex === 0 || anchorRowIndex === 0 || anchorCellIndex === 0 || focusTableIdIndex === 0 || focusRowIndex === 0 || focusCellIndex === 0) return false;
6380
+ return anchorPath[anchorTableIdIndex] === focusPath[focusTableIdIndex] && anchorPath[anchorRowIndex] === focusPath[focusRowIndex] && anchorPath[anchorCellIndex] === focusPath[focusCellIndex];
6322
6381
  }
6323
6382
  function isInSameTableCellData(skeleton, anchorNodePosition, focusNodePosition) {
6324
6383
  var _anchorGlyph$parent, _focusGlyph$parent;
@@ -6353,7 +6412,7 @@ function compareNodePositionInTable(a, b) {
6353
6412
  if (aRowCount > bRowCount) return false;
6354
6413
  return aCellCount <= bCellCount;
6355
6414
  }
6356
- function isEmptyCellPage$1(cell) {
6415
+ function isEmptyCellPage(cell) {
6357
6416
  return cell.sections[0].columns[0].lines.length === 0;
6358
6417
  }
6359
6418
  function findNonEmptyCellPages(cells, startCol, endCol) {
@@ -6361,14 +6420,14 @@ function findNonEmptyCellPages(cells, startCol, endCol) {
6361
6420
  let e = endCol;
6362
6421
  let startCell = cells[s];
6363
6422
  let endCell = cells[e];
6364
- while (s < e && (isEmptyCellPage$1(startCell) || isEmptyCellPage$1(endCell))) if (isEmptyCellPage$1(startCell)) {
6423
+ while (s < e && (isEmptyCellPage(startCell) || isEmptyCellPage(endCell))) if (isEmptyCellPage(startCell)) {
6365
6424
  s++;
6366
6425
  startCell = cells[s];
6367
- } else if (isEmptyCellPage$1(endCell)) {
6426
+ } else if (isEmptyCellPage(endCell)) {
6368
6427
  e--;
6369
6428
  endCell = cells[e];
6370
6429
  }
6371
- if (!isEmptyCellPage$1(startCell) && !isEmptyCellPage$1(endCell)) return [startCell, endCell];
6430
+ if (!isEmptyCellPage(startCell) && !isEmptyCellPage(endCell)) return [startCell, endCell];
6372
6431
  }
6373
6432
  function getColumnBoundary(table, column) {
6374
6433
  var _table$tableSource;
@@ -6416,6 +6475,7 @@ var NodePositionConvertToRectRange = class {
6416
6475
  _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
6417
6476
  }
6418
6477
  getRangePointData(startNodePosition, endNodePosition) {
6478
+ var _this$_documentOffset, _this$_documentOffset2;
6419
6479
  const pointGroup = [];
6420
6480
  const docSkeleton = this._docSkeleton;
6421
6481
  const skeletonData = docSkeleton.getSkeletonData();
@@ -6429,6 +6489,12 @@ var NodePositionConvertToRectRange = class {
6429
6489
  const { pageLayoutType, pageMarginLeft, pageMarginTop } = this._documentOffsetConfig;
6430
6490
  const unitId = getDocumentUnitId(docSkeleton);
6431
6491
  const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
6492
+ const nestedTableContexts = (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
6493
+ docsLeft: (_this$_documentOffset = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset !== void 0 ? _this$_documentOffset : 0,
6494
+ docsTop: (_this$_documentOffset2 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset2 !== void 0 ? _this$_documentOffset2 : 0,
6495
+ pageMarginTop,
6496
+ unitId
6497
+ });
6432
6498
  const skipPageIndex = pageType === _univerjs_engine_render.DocumentSkeletonPageType.BODY || pageType === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? startPage : startSegmentPage;
6433
6499
  for (let p = 0; p < skipPageIndex; p++) {
6434
6500
  const page = pages[p];
@@ -6441,6 +6507,43 @@ var NodePositionConvertToRectRange = class {
6441
6507
  let table = null;
6442
6508
  for (const [id, tableSke] of skeTables.entries()) if (id.startsWith(tableId)) table = tableSke;
6443
6509
  if (table == null) {
6510
+ const nestedTableContext = nestedTableContexts.find((context) => context.pageIndex === p && context.source === "column" && context.tableId.startsWith(tableId));
6511
+ if (nestedTableContext) {
6512
+ const nestedTable = nestedTableContext.table;
6513
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, sourceTableId);
6514
+ const nestedX = nestedTableContext.tableRect.left - nestedTable.left;
6515
+ const nestedY = nestedTableContext.tableRect.top;
6516
+ if (intersectsMergedCell) {
6517
+ const rows = nestedTable.rows.filter((row) => row.index >= startRow && row.index <= endRow);
6518
+ const firstRow = rows[0];
6519
+ const lastRow = rows[rows.length - 1];
6520
+ const startX = getColumnBoundary(nestedTable, startColumn);
6521
+ const endX = getColumnBoundary(nestedTable, endColumn + 1);
6522
+ if (firstRow && lastRow && startX != null && endX != null) pushViewportClippedPoints(pointGroup, {
6523
+ startX: nestedX + nestedTable.left + startX,
6524
+ startY: nestedY + firstRow.top,
6525
+ endX: nestedX + nestedTable.left + endX,
6526
+ endY: nestedY + lastRow.top + lastRow.height
6527
+ }, viewport, nestedX + nestedTable.left);
6528
+ this._liquid.restorePagePadding(page);
6529
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6530
+ continue;
6531
+ }
6532
+ for (const row of nestedTable.rows) if (row.index >= startRow && row.index <= endRow) {
6533
+ const cells = findNonEmptyCellPages(row.cells, startColumn, endColumn);
6534
+ if (cells == null) continue;
6535
+ const [rowStartCell, rowEndCell] = cells;
6536
+ pushViewportClippedPoints(pointGroup, {
6537
+ startX: nestedX + rowStartCell.left + nestedTable.left,
6538
+ startY: nestedY + row.top,
6539
+ endX: nestedX + rowEndCell.left + rowEndCell.pageWidth + nestedTable.left,
6540
+ endY: nestedY + row.top + row.height
6541
+ }, viewport, nestedX + nestedTable.left);
6542
+ }
6543
+ this._liquid.restorePagePadding(page);
6544
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6545
+ continue;
6546
+ }
6444
6547
  this._liquid.restorePagePadding(page);
6445
6548
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6446
6549
  continue;
@@ -6539,19 +6642,23 @@ var NodePositionConvertToRectRange = class {
6539
6642
  const { pages } = skeletonData;
6540
6643
  const { path: anchorPath } = anchorPosition;
6541
6644
  const { path: focusPath } = focusPosition;
6645
+ if (anchorPath.indexOf("cells") === -1 || focusPath.indexOf("cells") === -1) return;
6542
6646
  const anchorCell = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, anchorPath);
6543
6647
  const focusCell = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, focusPath);
6544
6648
  if (anchorCell == null || focusCell == null) return;
6649
+ const anchorRow = anchorCell.parent;
6650
+ const focusRow = focusCell.parent;
6651
+ 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
6652
  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);
6653
+ const anchorRowIndex = anchorRow.index;
6654
+ const anchorColumn = anchorRow.cells.indexOf(anchorCell);
6655
+ const focusRowIndex = focusRow.index;
6656
+ const focusColumn = focusRow.cells.indexOf(focusCell);
6550
6657
  const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
6551
6658
  const tableSource = (_docSkeleton$getViewM = docSkeleton.getViewModel().getSnapshot().tableSource) === null || _docSkeleton$getViewM === void 0 ? void 0 : _docSkeleton$getViewM[sourceTableId];
6552
6659
  const rawRange = {
6553
- startRowIndex: Math.min(anchorRow, focusRow),
6554
- endRowIndex: Math.max(anchorRow, focusRow),
6660
+ startRowIndex: Math.min(anchorRowIndex, focusRowIndex),
6661
+ endRowIndex: Math.max(anchorRowIndex, focusRowIndex),
6555
6662
  startColumnIndex: Math.min(anchorColumn, focusColumn),
6556
6663
  endColumnIndex: Math.max(anchorColumn, focusColumn)
6557
6664
  };
@@ -7077,6 +7184,20 @@ var RectRange = class {
7077
7184
 
7078
7185
  //#endregion
7079
7186
  //#region src/services/selection/selection-utils.ts
7187
+ function isInSameColumnPage(anchorPosition, focusPosition) {
7188
+ const anchorColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(anchorPosition);
7189
+ const focusColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(focusPosition);
7190
+ return !!anchorColumnInfo && !!focusColumnInfo && anchorColumnInfo.pageIndex === focusColumnInfo.pageIndex && anchorColumnInfo.columnGroupId === focusColumnInfo.columnGroupId && anchorColumnInfo.columnIndex === focusColumnInfo.columnIndex;
7191
+ }
7192
+ function getColumnInputBoundaryCollapsedPosition(anchorPosition, focusPosition, skeleton) {
7193
+ const anchorColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(anchorPosition);
7194
+ const focusColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(focusPosition);
7195
+ if (!anchorColumnInfo || !focusColumnInfo || anchorColumnInfo.pageIndex !== focusColumnInfo.pageIndex || anchorColumnInfo.columnGroupId !== focusColumnInfo.columnGroupId || anchorColumnInfo.columnIndex + 1 !== focusColumnInfo.columnIndex) return;
7196
+ const anchorOffset = skeleton.findCharIndexByPosition(anchorPosition);
7197
+ const focusOffset = skeleton.findCharIndexByPosition(focusPosition);
7198
+ if (anchorOffset == null || focusOffset == null || anchorOffset <= focusOffset) return;
7199
+ return anchorPosition;
7200
+ }
7080
7201
  function getTextRangeFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage, startIsBack = true, endIsBack = true) {
7081
7202
  const startNodePosition = skeleton.findNodePositionByCharIndex(startOffset, startIsBack, segmentId, segmentPage);
7082
7203
  const endNodePosition = skeleton.findNodePositionByCharIndex(endOffset, endIsBack, segmentId, segmentPage);
@@ -7108,6 +7229,21 @@ function getRangeListFromSelection(anchorPosition, focusPosition, scene, documen
7108
7229
  segmentId,
7109
7230
  segmentPage
7110
7231
  ];
7232
+ const collapsedColumnPosition = getColumnInputBoundaryCollapsedPosition(anchorPosition, focusPosition, skeleton);
7233
+ if (collapsedColumnPosition) {
7234
+ textRanges.push(new TextRange(scene, document, skeleton, collapsedColumnPosition, collapsedColumnPosition, style, segmentId, segmentPage));
7235
+ return {
7236
+ textRanges,
7237
+ rectRanges
7238
+ };
7239
+ }
7240
+ if (isInSameColumnPage(anchorPosition, focusPosition)) {
7241
+ textRanges.push(new TextRange(...rangeParams));
7242
+ return {
7243
+ textRanges,
7244
+ rectRanges
7245
+ };
7246
+ }
7111
7247
  if (isInSameTableCellData(skeleton, anchorPosition, focusPosition)) if (isInSameTableCell(anchorPosition, focusPosition)) {
7112
7248
  textRanges.push(new TextRange(...rangeParams));
7113
7249
  return {
@@ -8601,7 +8737,7 @@ const DocTableInsertColumnCommand = {
8601
8737
  id: DocTableInsertColumnCommandId,
8602
8738
  type: _univerjs_core.CommandType.COMMAND,
8603
8739
  handler: async (accessor, params) => {
8604
- var _documentStyle$pageSi, _documentStyle$pageSi2, _snapshot$tableSource;
8740
+ var _snapshot$tableSource, _documentStyle$pageSi, _documentStyle$pageSi2;
8605
8741
  const { position } = params;
8606
8742
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
8607
8743
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -8666,10 +8802,11 @@ const DocTableInsertColumnCommand = {
8666
8802
  const snapshot = docDataModel.getSnapshot();
8667
8803
  const documentStyle = snapshot.documentStyle;
8668
8804
  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
8805
  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
8806
  if (!tableColumns) return false;
8672
- const { newColWidth, widths } = getColumnWidths(pageWidth, tableColumns, columnIndex);
8807
+ 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;
8808
+ const tableWidth = tableColumns.reduce((sum, column) => sum + column.size.width.v, 0);
8809
+ const { newColWidth, widths } = getColumnWidths(tableWidth > 0 ? tableWidth : pageWidth, tableColumns, columnIndex);
8673
8810
  for (let i = 0; i < widths.length; i++) {
8674
8811
  const action = jsonX.replaceOp([
8675
8812
  "tableSource",
@@ -10909,6 +11046,10 @@ function notInTableSubscriber(subscriber, docSelectionManagerService, univerInst
10909
11046
  if (activeRange && (rectRanges == null || rectRanges.length === 0)) {
10910
11047
  var _docDataModel$getSelf;
10911
11048
  const { segmentId, startOffset, endOffset } = activeRange;
11049
+ if (!(activeRange.collapsed === true || startOffset === endOffset)) {
11050
+ subscriber.next(true);
11051
+ return;
11052
+ }
10912
11053
  const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
10913
11054
  const tables = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.tables;
10914
11055
  if (tables && tables.length) {
@@ -12659,7 +12800,6 @@ function ParagraphMenuInsertBelowHeadingH1MenuItemFactory(accessor) {
12659
12800
  tooltip: "docs-ui.toolbar.heading.leading1",
12660
12801
  params: {
12661
12802
  commandId: H1HeadingCommand.id,
12662
- paragraphMenuPlacement: "below",
12663
12803
  paragraphMenuInsertMode: "breakline"
12664
12804
  },
12665
12805
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12675,7 +12815,6 @@ function ParagraphMenuInsertBelowHeadingH2MenuItemFactory(accessor) {
12675
12815
  tooltip: "docs-ui.toolbar.heading.leading2",
12676
12816
  params: {
12677
12817
  commandId: H2HeadingCommand.id,
12678
- paragraphMenuPlacement: "below",
12679
12818
  paragraphMenuInsertMode: "breakline"
12680
12819
  },
12681
12820
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12691,7 +12830,6 @@ function ParagraphMenuInsertBelowHeadingH3MenuItemFactory(accessor) {
12691
12830
  tooltip: "docs-ui.toolbar.heading.leading3",
12692
12831
  params: {
12693
12832
  commandId: H3HeadingCommand.id,
12694
- paragraphMenuPlacement: "below",
12695
12833
  paragraphMenuInsertMode: "breakline"
12696
12834
  },
12697
12835
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12707,7 +12845,6 @@ function ParagraphMenuInsertBelowHeadingH4MenuItemFactory(accessor) {
12707
12845
  tooltip: "docs-ui.toolbar.heading.leading4",
12708
12846
  params: {
12709
12847
  commandId: H4HeadingCommand.id,
12710
- paragraphMenuPlacement: "below",
12711
12848
  paragraphMenuInsertMode: "breakline"
12712
12849
  },
12713
12850
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12723,7 +12860,6 @@ function ParagraphMenuInsertBelowHeadingH5MenuItemFactory(accessor) {
12723
12860
  tooltip: "docs-ui.toolbar.heading.leading5",
12724
12861
  params: {
12725
12862
  commandId: H5HeadingCommand.id,
12726
- paragraphMenuPlacement: "below",
12727
12863
  paragraphMenuInsertMode: "breakline"
12728
12864
  },
12729
12865
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
@@ -12739,8 +12875,7 @@ function ParagraphMenuInsertBelowTableMenuItemFactory(accessor) {
12739
12875
  tooltip: "docs-ui.toolbar.table.insert",
12740
12876
  params: {
12741
12877
  rowCount: 3,
12742
- colCount: 5,
12743
- paragraphMenuPlacement: "below"
12878
+ colCount: 5
12744
12879
  },
12745
12880
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
12746
12881
  };
@@ -14025,6 +14160,50 @@ const calcDocParagraphPositions = (sections, top, left, pageWidth) => {
14025
14160
  }
14026
14161
  return paragraphBounds;
14027
14162
  };
14163
+ const calcParagraphPositionsFromLineContexts = (contexts, docsLeft, docsTop) => {
14164
+ const paragraphBounds = [];
14165
+ const currentParagraphs = /* @__PURE__ */ new Map();
14166
+ for (const context of contexts) {
14167
+ const { column, line, lineWidth, pageLeft, sectionTop } = context;
14168
+ const startIndex = line.paragraphIndex;
14169
+ const columnLeft = pageLeft + column.left + docsLeft;
14170
+ const lineTop = sectionTop + line.top + docsTop;
14171
+ const lineBottom = getParagraphLineBottom(context, lineTop);
14172
+ const key = `${context.source}:${context.pageIndex}:${pageLeft}:${column.left}:${startIndex}`;
14173
+ if (line.paragraphStart) {
14174
+ const currentParagraph = currentParagraphs.get(key);
14175
+ if (currentParagraph) paragraphBounds.push(currentParagraph);
14176
+ currentParagraphs.set(key, {
14177
+ paragraphStart: line.st,
14178
+ paragraphEnd: startIndex,
14179
+ startIndex,
14180
+ rect: {
14181
+ top: lineTop,
14182
+ left: columnLeft,
14183
+ right: columnLeft + lineWidth,
14184
+ bottom: lineBottom
14185
+ },
14186
+ fisrtLine: {
14187
+ top: lineTop + line.marginTop + line.paddingTop,
14188
+ left: columnLeft,
14189
+ right: columnLeft + lineWidth,
14190
+ bottom: lineTop + line.marginTop + line.paddingTop + line.contentHeight
14191
+ }
14192
+ });
14193
+ } else {
14194
+ const currentParagraph = currentParagraphs.get(key);
14195
+ if (currentParagraph) currentParagraph.rect.bottom = lineBottom;
14196
+ }
14197
+ }
14198
+ paragraphBounds.push(...currentParagraphs.values());
14199
+ return paragraphBounds;
14200
+ };
14201
+ function getParagraphLineBottom(context, lineTop) {
14202
+ const lineBottom = lineTop + context.line.lineHeight;
14203
+ if (context.source !== "column" || context.line !== context.column.lines.at(-1) || !Number.isFinite(context.page.pageHeight)) return lineBottom;
14204
+ const pageTop = lineTop - context.line.top - context.section.top;
14205
+ return Math.max(lineBottom, pageTop + context.page.pageHeight);
14206
+ }
14028
14207
  const calcDocGlyphPosition = (glyph, documents, skeleton, pageIndex = -1) => {
14029
14208
  const start = skeleton.findPositionByGlyph(glyph, pageIndex);
14030
14209
  if (!start) return;
@@ -14076,6 +14255,21 @@ function isPointInRect(x, y, rect) {
14076
14255
  if (x >= left && x <= right && y >= top && y <= bottom) return true;
14077
14256
  return false;
14078
14257
  }
14258
+ function getRectArea(rect) {
14259
+ return Math.max(0, rect.right - rect.left) * Math.max(0, rect.bottom - rect.top);
14260
+ }
14261
+ function isRectContainingRect(outer, inner) {
14262
+ return outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
14263
+ }
14264
+ function getParagraphTextRangeLength(bound) {
14265
+ return Math.max(0, bound.paragraphEnd - bound.paragraphStart);
14266
+ }
14267
+ function getMostSpecificParagraphBound(bounds) {
14268
+ return bounds.sort((left, right) => getRectArea(left.rect) - getRectArea(right.rect) || getParagraphTextRangeLength(left) - getParagraphTextRangeLength(right))[0];
14269
+ }
14270
+ function removeContainerParagraphBounds(bounds) {
14271
+ return bounds.filter((bound) => !bounds.some((other) => other !== bound && getRectArea(other.rect) < getRectArea(bound.rect) && isRectContainingRect(bound.rect, other.rect)));
14272
+ }
14079
14273
  function getTableBlockMenuHoverRect(tableRect) {
14080
14274
  return {
14081
14275
  bottom: tableRect.bottom,
@@ -14185,7 +14379,10 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14185
14379
  }));
14186
14380
  }
14187
14381
  _initEvents() {
14188
- this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.scene.onPointerMove$).pipe((0, rxjs.throttleTime)(30)).subscribe((evt) => {
14382
+ this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.scene.onPointerMove$).pipe((0, rxjs.throttleTime)(30, void 0, {
14383
+ leading: true,
14384
+ trailing: true
14385
+ })).subscribe((evt) => {
14189
14386
  if (evt.buttons > 0) {
14190
14387
  this._hoverBullet$.next(null);
14191
14388
  this._hoverCustomRanges$.next([]);
@@ -14379,9 +14576,9 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14379
14576
  if (!skeletonData) return null;
14380
14577
  const calc = (pages) => {
14381
14578
  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, {
14579
+ const addParagraphBoundsToMap = (map, bounds, pageIndex, segmentId) => {
14580
+ bounds.forEach((bound) => {
14581
+ if (!map.has(bound.startIndex)) map.set(bound.startIndex, {
14385
14582
  rect: bound.rect,
14386
14583
  paragraphStart: bound.paragraphStart,
14387
14584
  paragraphEnd: bound.paragraphEnd,
@@ -14392,7 +14589,7 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14392
14589
  firstLine: bound.fisrtLine
14393
14590
  });
14394
14591
  else {
14395
- const current = paragraphMap.get(bound.startIndex);
14592
+ const current = map.get(bound.startIndex);
14396
14593
  if (current) {
14397
14594
  current.rect.bottom = bound.rect.bottom;
14398
14595
  current.rects.push(bound.rect);
@@ -14400,76 +14597,73 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14400
14597
  }
14401
14598
  });
14402
14599
  };
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,
14600
+ const lineContextsBySource = /* @__PURE__ */ new Map();
14601
+ (0, _univerjs_engine_render.documentSkeletonLineIterator)(pages, {
14602
+ docsLeft: documentOffsetConfig.docsLeft,
14603
+ pageMarginTop: documentOffsetConfig.pageMarginTop,
14604
+ unitId: this._context.unitId
14605
+ }, (context) => {
14606
+ var _lineContextsBySource;
14607
+ if (context.source === "table-cell") return;
14608
+ const lineContexts = (_lineContextsBySource = lineContextsBySource.get(context.pageIndex)) !== null && _lineContextsBySource !== void 0 ? _lineContextsBySource : [];
14609
+ lineContexts.push(context);
14610
+ lineContextsBySource.set(context.pageIndex, lineContexts);
14611
+ });
14612
+ lineContextsBySource.forEach((contexts, pageIndex) => {
14613
+ addParagraphBoundsToMap(paragraphMap, calcParagraphPositionsFromLineContexts(contexts, documentOffsetConfig.docsLeft, documentOffsetConfig.docsTop), pageIndex, segmentId);
14614
+ });
14615
+ for (const tableContext of (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
14616
+ docsLeft: documentOffsetConfig.docsLeft,
14617
+ docsTop: documentOffsetConfig.docsTop,
14618
+ pageMarginTop: documentOffsetConfig.pageMarginTop,
14619
+ unitId: this._context.unitId
14620
+ })) {
14621
+ const tableId = tableContext.tableId;
14622
+ const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
14623
+ const tableViewport = getTableHorizontalViewportGeometry(tableContext.tableRect.left, tableContext.table.width, (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, sourceTableId));
14624
+ this._tableBounds.set(tableId, {
14625
+ rect: {
14626
+ ...tableContext.tableRect,
14627
+ right: tableViewport.visibleRight
14628
+ },
14629
+ pageIndex: tableContext.pageIndex,
14630
+ tableId
14631
+ });
14632
+ for (const cellGeometry of tableContext.cells) {
14633
+ var _cell$pageWidth, _cell$marginLeft, _cell$marginRight;
14634
+ const cell = cellGeometry.cell;
14635
+ 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);
14636
+ const bounds = calcDocParagraphPositions(cell.sections, cellGeometry.pageTop, cellGeometry.pageLeft, cellContentWidth).map((bound) => clipParagraphBoundHorizontally(bound, cellGeometry.clipLeft, cellGeometry.clipRight)).filter((bound) => bound != null);
14637
+ let arr = this._tableParagraphBounds.get(tableId);
14638
+ if (!arr) {
14639
+ arr = [];
14640
+ this._tableParagraphBounds.set(tableId, arr);
14641
+ }
14642
+ arr.push(...bounds.map((bound) => ({
14643
+ rect: bound.rect,
14644
+ paragraphStart: bound.paragraphStart,
14645
+ paragraphEnd: bound.paragraphEnd,
14646
+ startIndex: bound.startIndex,
14647
+ pageIndex: tableContext.pageIndex,
14648
+ segmentId,
14649
+ rowIndex: cellGeometry.rowIndex,
14650
+ colIndex: cellGeometry.columnIndex,
14651
+ firstLine: bound.fisrtLine,
14652
+ tableId
14653
+ })));
14654
+ let cellBounds = this._tableCellBounds.get(tableId);
14655
+ if (!cellBounds) {
14656
+ cellBounds = [];
14657
+ this._tableCellBounds.set(tableId, cellBounds);
14658
+ }
14659
+ cellBounds.push({
14660
+ rect: cellGeometry.cellRect,
14661
+ pageIndex: tableContext.pageIndex,
14662
+ rowIndex: cellGeometry.rowIndex,
14663
+ colIndex: cellGeometry.columnIndex,
14423
14664
  tableId
14424
14665
  });
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);
14666
+ }
14473
14667
  }
14474
14668
  return paragraphMap;
14475
14669
  };
@@ -14526,20 +14720,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14526
14720
  rects: [paragraph.rect]
14527
14721
  };
14528
14722
  }
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;
14723
+ return getMostSpecificParagraphBound([...this._paragraphBounds.values()].filter((bound) => bound.rects.some((rect) => isPointInRect(x, y, rect))));
14538
14724
  }
14539
14725
  _calcActiveParagraphLeft(evt) {
14540
14726
  this._buildParagraphBounds();
14541
14727
  const { x, y } = evt;
14542
- return this._paragraphLeftBounds.find((bound) => isPointInRect(x, y, bound.rect));
14728
+ return getMostSpecificParagraphBound(this._paragraphLeftBounds.filter((bound) => isPointInRect(x, y, bound.rect)));
14543
14729
  }
14544
14730
  get paragraphBounds() {
14545
14731
  this._buildParagraphBounds();
@@ -14578,18 +14764,19 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
14578
14764
  var _this$_skeleton$getSk4, _this$_skeleton$getSk5;
14579
14765
  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
14766
  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
- });
14767
+ for (const tableContext of (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
14768
+ pageMarginTop: this._documents.getOffsetConfig().pageMarginTop,
14769
+ resolveViewport: false,
14770
+ unitId: this._context.unitId
14771
+ })) {
14772
+ const tableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableContext.tableId).tableId;
14773
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(this._context.unitId, tableId);
14774
+ if (!viewport) {
14775
+ signatures.push(`${tableId}:none`);
14776
+ continue;
14777
+ }
14778
+ signatures.push(`${tableId}:${viewport.contentWidth}:${viewport.viewportWidth}:${viewport.scrollLeft}`);
14779
+ }
14593
14780
  return signatures.join("|");
14594
14781
  }
14595
14782
  };
@@ -14597,7 +14784,7 @@ DocEventManagerService = __decorate([__decorateParam(1, (0, _univerjs_core.Injec
14597
14784
  function getPreferredParagraphBoundsInRange(bodyBounds, tableBounds, startIndex, endIndex) {
14598
14785
  const matchedTableBounds = tableBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex));
14599
14786
  if (matchedTableBounds.length) return matchedTableBounds;
14600
- return bodyBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex));
14787
+ return removeContainerParagraphBounds(bodyBounds.filter((bound) => isRangeOverlappingParagraph(bound, startIndex, endIndex)));
14601
14788
  }
14602
14789
  function isRangeOverlappingParagraph(bound, startIndex, endIndex) {
14603
14790
  return Math.max(bound.paragraphStart, startIndex) <= Math.min(bound.paragraphEnd, endIndex);
@@ -14661,7 +14848,7 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
14661
14848
  onClick: () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(!open),
14662
14849
  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
14850
  style: iconStyle,
14664
- children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LeftIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {})
14851
+ children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {})
14665
14852
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14666
14853
  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
14854
  style: {
@@ -14934,7 +15121,7 @@ DocUIController = __decorate([
14934
15121
  //#endregion
14935
15122
  //#region package.json
14936
15123
  var name = "@univerjs/docs-ui";
14937
- var version = "1.0.0-alpha.0";
15124
+ var version = "1.0.0-insiders.20260629-12f2e44";
14938
15125
 
14939
15126
  //#endregion
14940
15127
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -16082,6 +16269,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16082
16269
  var _this$_docEventManage;
16083
16270
  const handleHoverTarget = (paragraph, tableBound) => {
16084
16271
  if (this._isBlockMenuDragging) return;
16272
+ if (this._docSelectionRenderService.isOnPointerEvent) {
16273
+ this.hideParagraphMenu(true);
16274
+ return;
16275
+ }
16085
16276
  const selectionState = this._getExpandedSelectionState(this._docSelectionManagerService.getDocRanges());
16086
16277
  if (selectionState.hasExpandedTextRange) {
16087
16278
  this.hideParagraphMenu(true);
@@ -16093,7 +16284,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16093
16284
  this.showTableMenu(tableBound);
16094
16285
  return;
16095
16286
  }
16096
- if (((_this$_paragrahMenu3 = this._paragrahMenu) === null || _this$_paragrahMenu3 === void 0 ? void 0 : _this$_paragrahMenu3.target.kind) === "table") return;
16287
+ if (((_this$_paragrahMenu3 = this._paragrahMenu) === null || _this$_paragrahMenu3 === void 0 ? void 0 : _this$_paragrahMenu3.target.kind) === _univerjs_core.DocumentBlockType.TABLE) return;
16097
16288
  this.hideParagraphMenu(true);
16098
16289
  return;
16099
16290
  }
@@ -16115,13 +16306,19 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16115
16306
  this._docEventManagerService.hoverParagraphRealTime$,
16116
16307
  this._docEventManagerService.hoverParagraphLeft$,
16117
16308
  (_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]) => {
16309
+ ]).pipe((0, rxjs.throttleTime)(16, void 0, {
16310
+ leading: true,
16311
+ trailing: true
16312
+ })).subscribe(([p, left, table]) => {
16119
16313
  handleHoverTarget(p !== null && p !== void 0 ? p : left, table);
16120
16314
  }));
16315
+ this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(() => {
16316
+ this.hideParagraphMenu(true);
16317
+ }));
16121
16318
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
16122
16319
  var _this$_paragrahMenu5;
16123
16320
  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);
16321
+ if (selectionState.hasExpandedTextRange || selectionState.hasRectRange && ((_this$_paragrahMenu5 = this._paragrahMenu) === null || _this$_paragrahMenu5 === void 0 ? void 0 : _this$_paragrahMenu5.target.kind) !== _univerjs_core.DocumentBlockType.TABLE) this.hideParagraphMenu(true);
16125
16322
  }));
16126
16323
  let lastScrollY = 0;
16127
16324
  this.disposeWithMe(this._context.scene.getViewport("viewMain").onScrollAfter$.subscribeEvent((e) => {
@@ -16270,8 +16467,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16270
16467
  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
16468
  if (!table) return;
16272
16469
  const target = {
16273
- kind: "table",
16274
- key: `table:${table.tableId}`,
16470
+ kind: _univerjs_core.DocumentBlockType.TABLE,
16471
+ key: `${_univerjs_core.DocumentBlockType.TABLE}:${table.tableId}`,
16275
16472
  table,
16276
16473
  icon: "GridIcon",
16277
16474
  menuRange: {
@@ -16322,7 +16519,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16322
16519
  _shouldKeepCurrentCellMenuForTable(table) {
16323
16520
  var _this$_paragrahMenu10;
16324
16521
  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;
16522
+ if (!target || target.kind === _univerjs_core.DocumentBlockType.TABLE || !target.cellRange) return false;
16326
16523
  return target.cellRange.startOffset >= table.startIndex && target.cellRange.startOffset <= table.endIndex;
16327
16524
  }
16328
16525
  getDropTargetFromClientPoint(clientX, clientY, sourceRange) {
@@ -16386,8 +16583,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16386
16583
  blockRange
16387
16584
  };
16388
16585
  return {
16389
- kind: "blockRange",
16390
- key: `blockRange:${blockRange.blockId}`,
16586
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16587
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16391
16588
  paragraph: targetParagraph,
16392
16589
  blockRange,
16393
16590
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
@@ -16412,8 +16609,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16412
16609
  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
16610
  const isCustomBlockOnly = (customBlock === null || customBlock === void 0 ? void 0 : customBlock.blockType) === _univerjs_core.BlockType.CUSTOM && paragraphDataStream.replace(/[\b\r\n]/g, "") === "";
16414
16611
  if (customBlock && customBlock.blockType === _univerjs_core.BlockType.CUSTOM && isCustomBlockOnly) return {
16415
- kind: "customBlock",
16416
- key: `customBlock:${customBlock.blockId}`,
16612
+ kind: _univerjs_core.DocumentBlockType.CUSTOM_BLOCK,
16613
+ key: `${_univerjs_core.DocumentBlockType.CUSTOM_BLOCK}:${customBlock.blockId}`,
16417
16614
  paragraph,
16418
16615
  customBlock,
16419
16616
  icon: "TextTypeIcon",
@@ -16429,8 +16626,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16429
16626
  };
16430
16627
  if (paragraphDataStream === "\b") return null;
16431
16628
  return {
16432
- kind: "paragraph",
16433
- key: `paragraph:${paragraph.startIndex}`,
16629
+ kind: _univerjs_core.DocumentBlockType.PARAGRAPH,
16630
+ key: `${_univerjs_core.DocumentBlockType.PARAGRAPH}:${paragraph.startIndex}`,
16434
16631
  paragraph,
16435
16632
  icon: isHorizontalRuleParagraph ? "ReduceIcon" : listIcon,
16436
16633
  cellRange: cellRange !== null && cellRange !== void 0 ? cellRange : void 0,
@@ -16456,8 +16653,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16456
16653
  const tableBound = this._docEventManagerService.tableBounds.get(table.tableId);
16457
16654
  if (!tableBound) continue;
16458
16655
  targets.push({
16459
- kind: "table",
16460
- key: `table:${table.tableId}`,
16656
+ kind: _univerjs_core.DocumentBlockType.TABLE,
16657
+ key: `${_univerjs_core.DocumentBlockType.TABLE}:${table.tableId}`,
16461
16658
  table,
16462
16659
  icon: "GridIcon",
16463
16660
  menuRange: {
@@ -16478,8 +16675,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16478
16675
  const rect = unionRects(paragraphBounds.filter((bound) => Math.max(bound.paragraphStart, blockRange.startIndex) <= Math.min(bound.paragraphEnd, blockRange.endIndex)).map((bound) => bound.rect));
16479
16676
  if (!rect) continue;
16480
16677
  targets.push({
16481
- kind: "blockRange",
16482
- key: `blockRange:${blockRange.blockId}`,
16678
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16679
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16483
16680
  blockRange,
16484
16681
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
16485
16682
  menuRange: {
@@ -16520,8 +16717,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
16520
16717
  const rect = unionRects(paragraphBounds.filter((bound) => Math.max(bound.paragraphStart, blockRange.startIndex) <= Math.min(bound.paragraphEnd, blockRange.endIndex)).map((bound) => bound.rect));
16521
16718
  if (!rect) continue;
16522
16719
  targets.push({
16523
- kind: "blockRange",
16524
- key: `blockRange:${blockRange.blockId}`,
16720
+ kind: _univerjs_core.DocumentBlockType.BLOCK_RANGE,
16721
+ key: `${_univerjs_core.DocumentBlockType.BLOCK_RANGE}:${blockRange.blockId}`,
16525
16722
  blockRange,
16526
16723
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
16527
16724
  cellRange,
@@ -16656,6 +16853,9 @@ const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;
16656
16853
  function getParagraphMenuTriggerClassName(visible) {
16657
16854
  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
16855
  }
16856
+ function shouldExecuteParagraphMenuMove(validatorService, context) {
16857
+ return validatorService.canMoveBlock(context);
16858
+ }
16659
16859
  function getParagraphMenuTriggerIconKey(namedStyleType) {
16660
16860
  switch (namedStyleType) {
16661
16861
  case _univerjs_core.NamedStyleType.HEADING_1: return "H1Icon";
@@ -16936,13 +17136,13 @@ function deleteBodyText(body, startOffset, endOffset) {
16936
17136
  }
16937
17137
  function stripBlockParagraphStyle(style, blockType) {
16938
17138
  const nextStyle = { ...style };
16939
- if (blockType === "quote") {
17139
+ if (blockType === _univerjs_core.DocumentBlockRangeType.QUOTE) {
16940
17140
  delete nextStyle.indentStart;
16941
17141
  delete nextStyle.spaceAbove;
16942
17142
  delete nextStyle.spaceBelow;
16943
17143
  return nextStyle;
16944
17144
  }
16945
- if (blockType === "code") {
17145
+ if (blockType === _univerjs_core.DocumentBlockRangeType.CODE) {
16946
17146
  var _nextStyle$textStyle, _nextStyle$textStyle2;
16947
17147
  delete nextStyle.indentStart;
16948
17148
  delete nextStyle.indentEnd;
@@ -16951,7 +17151,7 @@ function stripBlockParagraphStyle(style, blockType) {
16951
17151
  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
17152
  return nextStyle;
16953
17153
  }
16954
- if (blockType === "callout") {
17154
+ if (blockType === _univerjs_core.DocumentBlockRangeType.CALLOUT) {
16955
17155
  delete nextStyle.indentStart;
16956
17156
  delete nextStyle.indentEnd;
16957
17157
  delete nextStyle.spaceAbove;
@@ -17047,6 +17247,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17047
17247
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
17048
17248
  const docClipboardService = (0, _univerjs_ui.useDependency)(IDocClipboardService);
17049
17249
  const docContentInsertService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocContentInsertService);
17250
+ const docBlockMoveValidatorService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocBlockMoveValidatorService);
17050
17251
  const clipboardInterfaceService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IClipboardInterfaceService);
17051
17252
  const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
17052
17253
  const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
@@ -17325,6 +17526,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17325
17526
  },
17326
17527
  onMouseLeave: () => {
17327
17528
  isMouseOver.current = false;
17529
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17328
17530
  cancelOpenMenu();
17329
17531
  scheduleHideMenu();
17330
17532
  },
@@ -17377,7 +17579,11 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17377
17579
  isDraggingRef.current = false;
17378
17580
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setBlockMenuDragging(false);
17379
17581
  setDropRect(null);
17380
- if (shouldDrop && range && targetOffset != null) commandService.executeCommand(MoveDocBlockCommand.id, {
17582
+ if (shouldDrop && range && targetOffset != null && shouldExecuteParagraphMenuMove(docBlockMoveValidatorService, {
17583
+ unitId: popup.unitId,
17584
+ sourceRange: range,
17585
+ targetOffset
17586
+ })) commandService.executeCommand(MoveDocBlockCommand.id, {
17381
17587
  unitId: popup.unitId,
17382
17588
  sourceRange: range,
17383
17589
  targetOffset
@@ -17416,6 +17622,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17416
17622
  },
17417
17623
  onMouseLeave: () => {
17418
17624
  isMouseOver.current = false;
17625
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17419
17626
  scheduleHideMenu();
17420
17627
  }
17421
17628
  }),
@@ -17433,6 +17640,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17433
17640
  },
17434
17641
  onMouseLeave: () => {
17435
17642
  isMouseOver.current = false;
17643
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17436
17644
  scheduleHideMenu();
17437
17645
  },
17438
17646
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.ContextMenuPanel, {
@@ -17450,6 +17658,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17450
17658
  },
17451
17659
  onMenuPointerLeave: () => {
17452
17660
  isMouseOver.current = false;
17661
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
17453
17662
  scheduleHideMenu();
17454
17663
  },
17455
17664
  onCancel: () => {
@@ -17513,8 +17722,7 @@ const TableBlockMenu = ({ popup }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)
17513
17722
  });
17514
17723
  function shouldUseInsertBelowRange(commandId, params) {
17515
17724
  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;
17725
+ if (typeof params.id === "string" && params.id.toLowerCase().includes("below")) return true;
17518
17726
  const normalized = commandId.toLowerCase();
17519
17727
  if (normalized.includes("insert") && (normalized.includes("below") || normalized.includes("bellow"))) return true;
17520
17728
  if (normalized.includes("insert") && normalized.includes("image")) return true;
@@ -17698,6 +17906,12 @@ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)
17698
17906
 
17699
17907
  //#endregion
17700
17908
  //#region src/controllers/doc-auto-format.controller.ts
17909
+ function hasQuickListType(text) {
17910
+ return Object.prototype.hasOwnProperty.call(_univerjs_core.QuickListTypeMap, text);
17911
+ }
17912
+ function hasQuickHeading(text) {
17913
+ return Object.prototype.hasOwnProperty.call(QUICK_HEADING_MAP, text);
17914
+ }
17701
17915
  let DocAutoFormatController = class DocAutoFormatController extends _univerjs_core.Disposable {
17702
17916
  constructor(_docAutoFormatService, _renderManagerService) {
17703
17917
  super();
@@ -17766,14 +17980,14 @@ let DocAutoFormatController = class DocAutoFormatController extends _univerjs_co
17766
17980
  if (paragraphs.length !== 1) return false;
17767
17981
  if (!selection.collapsed) return false;
17768
17982
  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;
17983
+ if (text && (hasQuickListType(text) || hasQuickHeading(text))) return true;
17770
17984
  return false;
17771
17985
  },
17772
17986
  getMutations(context) {
17773
17987
  var _unit$getBody3;
17774
17988
  const { paragraphs, unit, selection } = context;
17775
17989
  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)) {
17990
+ if (text && hasQuickListType(text)) {
17777
17991
  const type = _univerjs_core.QuickListTypeMap[text];
17778
17992
  return [{
17779
17993
  id: QuickListCommand.id,
@@ -17783,7 +17997,7 @@ let DocAutoFormatController = class DocAutoFormatController extends _univerjs_co
17783
17997
  }
17784
17998
  }];
17785
17999
  }
17786
- if (text && Object.keys(QUICK_HEADING_MAP).includes(text)) {
18000
+ if (text && hasQuickHeading(text)) {
17787
18001
  const type = QUICK_HEADING_MAP[text];
17788
18002
  return [{
17789
18003
  id: QuickHeadingCommand.id,
@@ -17833,14 +18047,6 @@ DocAutoFormatController = __decorate([__decorateParam(0, (0, _univerjs_core.Inje
17833
18047
 
17834
18048
  //#endregion
17835
18049
  //#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
18050
  function findTableAfterLine(line, page) {
17845
18051
  const { ed } = line;
17846
18052
  const { skeTables } = page;
@@ -17851,86 +18057,6 @@ function findTableAfterLine(line, page) {
17851
18057
  }
17852
18058
  return table;
17853
18059
  }
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
18060
  function findTableBeforeLine(line, page) {
17935
18061
  const { st } = line;
17936
18062
  const { skeTables } = page;
@@ -17983,7 +18109,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
17983
18109
  }));
17984
18110
  }
17985
18111
  _handleShiftMoveSelection(direction, granularity = "character") {
17986
- var _this$_renderManagerS, _dataStream$length;
18112
+ var _this$_renderManagerS, _body$dataStream$leng, _docDataModel$getCust;
17987
18113
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
17988
18114
  const allRanges = this._textSelectionManagerService.getTextRanges();
17989
18115
  const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
@@ -18010,16 +18136,21 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18010
18136
  }
18011
18137
  const anchorOffset = collapsed ? startOffset : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? startOffset : endOffset;
18012
18138
  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;
18139
+ const body = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody();
18140
+ if (body == null) return;
18141
+ const dataStreamLength = (_body$dataStream$leng = body.dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : Number.POSITIVE_INFINITY;
18142
+ const customRanges = (_docDataModel$getCust = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust !== void 0 ? _docDataModel$getCust : [];
18014
18143
  if (granularity !== "character") {
18015
- const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength);
18144
+ const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
18016
18145
  if (nextOffset == null || nextOffset === focusOffset) return;
18146
+ const normalizedNextOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, nextOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18147
+ if (normalizedNextOffset == null || normalizedNextOffset === focusOffset) return;
18017
18148
  this._textSelectionManagerService.replaceTextRanges([{
18018
18149
  startOffset: anchorOffset,
18019
- endOffset: nextOffset,
18150
+ endOffset: normalizedNextOffset,
18020
18151
  style
18021
18152
  }], false);
18022
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), nextOffset);
18153
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), normalizedNextOffset);
18023
18154
  return;
18024
18155
  }
18025
18156
  if (direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.RIGHT) {
@@ -18040,8 +18171,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18040
18171
  const focusNodePosition = collapsed ? startNodePosition : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? endNodePosition : startNodePosition;
18041
18172
  const newPos = this._getTopOrBottomPosition(skeleton, focusGlyph, focusNodePosition, direction === _univerjs_core.Direction.DOWN, true);
18042
18173
  if (newPos == null) {
18043
- const newFocusOffset = direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18044
- if (newFocusOffset === focusOffset) return;
18174
+ const newFocusOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2, direction, normalizedSegmentId, normalizedSegmentPage);
18175
+ if (newFocusOffset == null || newFocusOffset === focusOffset) return;
18045
18176
  this._textSelectionManagerService.replaceTextRanges([{
18046
18177
  startOffset: anchorOffset,
18047
18178
  endOffset: newFocusOffset,
@@ -18050,16 +18181,18 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18050
18181
  return;
18051
18182
  }
18052
18183
  const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(newPos, newPos).cursorList[0];
18184
+ const newFocusOffset = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, newActiveRange.endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18185
+ if (newFocusOffset == null || newFocusOffset === focusOffset) return;
18053
18186
  this._textSelectionManagerService.replaceTextRanges([{
18054
18187
  startOffset: anchorOffset,
18055
- endOffset: newActiveRange.endOffset,
18188
+ endOffset: newFocusOffset,
18056
18189
  style
18057
18190
  }], false);
18058
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), newActiveRange.endOffset);
18191
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), newFocusOffset);
18059
18192
  }
18060
18193
  }
18061
18194
  _handleMoveCursor(direction, granularity = "character") {
18062
- var _this$_renderManagerS2, _body$dataStream$leng, _docDataModel$getCust;
18195
+ var _this$_renderManagerS2, _body$dataStream$leng2, _docDataModel$getCust2;
18063
18196
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
18064
18197
  const allRanges = this._textSelectionManagerService.getTextRanges();
18065
18198
  const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
@@ -18072,8 +18205,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18072
18205
  const normalizedSegmentPage = segmentPage !== null && segmentPage !== void 0 ? segmentPage : -1;
18073
18206
  const body = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody();
18074
18207
  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 : [];
18208
+ const dataStreamLength = (_body$dataStream$leng2 = body.dataStream.length) !== null && _body$dataStream$leng2 !== void 0 ? _body$dataStream$leng2 : Number.POSITIVE_INFINITY;
18209
+ const customRanges = (_docDataModel$getCust2 = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust2 !== void 0 ? _docDataModel$getCust2 : [];
18077
18210
  if (granularity !== "character") {
18078
18211
  let cursorOffset;
18079
18212
  if (!activeRange.collapsed || allRanges.length > 1) {
@@ -18085,9 +18218,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18085
18218
  }
18086
18219
  cursorOffset = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? min : max;
18087
18220
  } 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);
18221
+ let cursor = this._getCursorOffsetByGranularity(skeleton, cursorOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
18222
+ if (cursor == null) return;
18223
+ cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, cursor, direction, normalizedSegmentId, normalizedSegmentPage);
18089
18224
  if (cursor == null) return;
18090
- cursor = this._normalizeCursorOffset(body.dataStream, customRanges, cursor, direction);
18091
18225
  this._textSelectionManagerService.replaceTextRanges([{
18092
18226
  startOffset: cursor,
18093
18227
  endOffset: cursor,
@@ -18118,13 +18252,15 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18118
18252
  const skipTokens = [...this._getCursorSkipTokens()];
18119
18253
  if (direction === _univerjs_core.Direction.LEFT) while (skipTokens.includes(body.dataStream[cursor])) cursor--;
18120
18254
  else while (skipTokens.includes(body.dataStream[cursor])) cursor++;
18121
- cursor = this._normalizeWholeEntityRanges(customRanges, cursor, direction);
18255
+ cursor = this._normalizeCursorOffset(body.dataStream, customRanges, cursor, direction);
18256
+ const normalizedCursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, cursor, direction, normalizedSegmentId, normalizedSegmentPage);
18257
+ if (normalizedCursor == null) return;
18122
18258
  this._textSelectionManagerService.replaceTextRanges([{
18123
- startOffset: Math.max(0, cursor),
18124
- endOffset: Math.max(0, cursor),
18259
+ startOffset: normalizedCursor,
18260
+ endOffset: normalizedCursor,
18125
18261
  style
18126
18262
  }], false);
18127
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), cursor);
18263
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), normalizedCursor);
18128
18264
  } else {
18129
18265
  const startNode = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
18130
18266
  const endNode = skeleton.findNodeByCharIndex(endOffset, segmentId, segmentPage);
@@ -18132,31 +18268,55 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18132
18268
  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
18269
  if (newPos == null) {
18134
18270
  let cursor;
18135
- if (collapsed) cursor = direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18136
- else cursor = direction === _univerjs_core.Direction.UP ? startOffset : endOffset;
18271
+ if (collapsed) cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2, direction, normalizedSegmentId, normalizedSegmentPage);
18272
+ else cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, direction === _univerjs_core.Direction.UP ? startOffset : endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18273
+ if (cursor == null) return;
18137
18274
  this._textSelectionManagerService.replaceTextRanges([{
18138
- startOffset: Math.max(0, cursor),
18139
- endOffset: Math.max(0, cursor),
18275
+ startOffset: cursor,
18276
+ endOffset: cursor,
18140
18277
  style
18141
18278
  }], false);
18142
18279
  return;
18143
18280
  }
18144
18281
  const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(newPos, newPos).cursorList[0];
18282
+ const cursor = this._normalizeRenderableCursorOffset(skeleton, body.dataStream, customRanges, newActiveRange.endOffset, direction, normalizedSegmentId, normalizedSegmentPage);
18283
+ if (cursor == null) return;
18145
18284
  this._textSelectionManagerService.replaceTextRanges([{
18146
- ...newActiveRange,
18285
+ startOffset: cursor,
18286
+ endOffset: cursor,
18147
18287
  style
18148
18288
  }], false);
18149
- this._scrollToFocusNodePosition(docDataModel.getUnitId(), newActiveRange.endOffset);
18289
+ this._scrollToFocusNodePosition(docDataModel.getUnitId(), cursor);
18150
18290
  }
18151
18291
  }
18152
- _getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, segmentId, segmentPage, dataStreamLength) {
18292
+ _getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, segmentId, segmentPage, dataStreamLength, dataStream = "") {
18153
18293
  switch (granularity) {
18154
18294
  case "document": return direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? 0 : dataStreamLength - 2;
18295
+ case "paragraph": return this._getParagraphBoundaryOffset(dataStream, focusOffset, direction);
18155
18296
  case "line": return this._getLineBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength);
18156
18297
  case "word": return this._getWordBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength);
18157
18298
  default: return null;
18158
18299
  }
18159
18300
  }
18301
+ _getParagraphBoundaryOffset(dataStream, focusOffset, direction) {
18302
+ if (direction !== _univerjs_core.Direction.UP && direction !== _univerjs_core.Direction.DOWN) return;
18303
+ if (dataStream.length === 0) return 0;
18304
+ const cursor = Math.min(Math.max(0, focusOffset), dataStream.length - 1);
18305
+ if (direction === _univerjs_core.Direction.UP) {
18306
+ const currentParagraphStart = this._getCurrentParagraphStartOffset(dataStream, cursor);
18307
+ if (cursor > currentParagraphStart) return currentParagraphStart;
18308
+ return this._getCurrentParagraphStartOffset(dataStream, Math.max(0, currentParagraphStart - 1));
18309
+ }
18310
+ const nextParagraphEnd = dataStream.indexOf(_univerjs_core.DataStreamTreeTokenType.PARAGRAPH, cursor);
18311
+ return nextParagraphEnd === -1 ? dataStream.length - 1 : nextParagraphEnd + 1;
18312
+ }
18313
+ _getCurrentParagraphStartOffset(dataStream, cursor) {
18314
+ for (let index = Math.min(cursor - 1, dataStream.length - 1); index >= 0; index--) {
18315
+ const token = dataStream[index];
18316
+ if (token === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || token === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK) return index + 1;
18317
+ }
18318
+ return 0;
18319
+ }
18160
18320
  _getWordBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength) {
18161
18321
  var _skeleton$findNodeByC;
18162
18322
  if (direction !== _univerjs_core.Direction.LEFT && direction !== _univerjs_core.Direction.RIGHT) return;
@@ -18207,6 +18367,30 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18207
18367
  else while (cursor < dataStream.length - 1 && skipTokens.includes(dataStream[cursor])) cursor++;
18208
18368
  return this._normalizeWholeEntityRanges(customRanges, cursor, direction);
18209
18369
  }
18370
+ _normalizeRenderableCursorOffset(skeleton, dataStream, customRanges, cursor, direction, segmentId, segmentPage) {
18371
+ const boundedCursor = Math.min(Math.max(0, cursor), Math.max(0, dataStream.length - 1));
18372
+ const primaryCursor = this._findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, boundedCursor, direction, segmentId, segmentPage);
18373
+ if (primaryCursor != null) return primaryCursor;
18374
+ const fallbackDirection = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? _univerjs_core.Direction.DOWN : _univerjs_core.Direction.UP;
18375
+ return this._findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, boundedCursor, fallbackDirection, segmentId, segmentPage);
18376
+ }
18377
+ _findNearestRenderableCursorOffset(skeleton, dataStream, customRanges, cursor, direction, segmentId, segmentPage) {
18378
+ const step = direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP ? -1 : 1;
18379
+ let current = Math.min(Math.max(0, cursor), Math.max(0, dataStream.length - 1));
18380
+ const visited = /* @__PURE__ */ new Set();
18381
+ while (current >= 0 && current < dataStream.length && !visited.has(current)) {
18382
+ visited.add(current);
18383
+ const normalizedCursor = this._normalizeCursorOffset(dataStream, customRanges, current, direction);
18384
+ if (normalizedCursor < 0 || normalizedCursor >= dataStream.length) return;
18385
+ if (this._isRenderableCursorOffset(skeleton, dataStream, normalizedCursor, segmentId, segmentPage)) return normalizedCursor;
18386
+ current = normalizedCursor + step;
18387
+ }
18388
+ }
18389
+ _isRenderableCursorOffset(skeleton, dataStream, cursor, segmentId, segmentPage) {
18390
+ if (cursor < 0 || cursor >= dataStream.length) return false;
18391
+ if (this._getNonRenderableCursorTokens().includes(dataStream[cursor])) return false;
18392
+ return skeleton.findNodePositionByCharIndex(cursor, true, segmentId, segmentPage) != null;
18393
+ }
18210
18394
  _normalizeWholeEntityRanges(customRanges, cursor, direction) {
18211
18395
  customRanges.filter((range) => range.wholeEntity && range.startIndex < cursor && range.endIndex >= cursor).forEach((range) => {
18212
18396
  if (direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.UP) cursor = Math.min(range.startIndex, cursor);
@@ -18229,12 +18413,21 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18229
18413
  if (includeParagraph) tokens.push(_univerjs_core.DataStreamTreeTokenType.PARAGRAPH);
18230
18414
  return tokens;
18231
18415
  }
18416
+ _getNonRenderableCursorTokens() {
18417
+ return [
18418
+ ...this._getCursorSkipTokens(),
18419
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_START,
18420
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_END,
18421
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_START,
18422
+ _univerjs_core.DataStreamTreeTokenType.COLUMN_END
18423
+ ];
18424
+ }
18232
18425
  _getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction, skipCellContent = false) {
18233
18426
  if (glyph == null || nodePosition == null) return;
18234
18427
  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);
18428
+ const target = this._getNextOrPrevLineTarget(glyph, direction, offsetLeft, skipCellContent);
18429
+ if (target == null) return;
18430
+ const position = this._matchPositionByLeftOffset(docSkeleton, target.line, target.offsetLeft, nodePosition);
18238
18431
  if (position == null) return;
18239
18432
  return {
18240
18433
  ...position,
@@ -18249,11 +18442,24 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18249
18442
  return divideLeft + left;
18250
18443
  }
18251
18444
  _matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition) {
18445
+ var _nearestNode$glyph;
18252
18446
  const nearestNode = { distance: Number.POSITIVE_INFINITY };
18447
+ const nearestEmptyParagraphNode = { distance: Number.POSITIVE_INFINITY };
18253
18448
  for (const divide of line.divides) {
18254
18449
  const divideLeft = divide.left;
18255
18450
  for (const glyph of divide.glyphGroup) {
18256
- if (!this._isCursorAddressableGlyph(glyph)) continue;
18451
+ if (!this._isCursorAddressableGlyph(glyph)) {
18452
+ if (glyph.streamType === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH && glyph.count > 0) {
18453
+ const { left } = glyph;
18454
+ const leftSide = divideLeft + left;
18455
+ const distance = Math.abs(offsetLeft - leftSide);
18456
+ if (distance < nearestEmptyParagraphNode.distance) {
18457
+ nearestEmptyParagraphNode.glyph = glyph;
18458
+ nearestEmptyParagraphNode.distance = distance;
18459
+ }
18460
+ }
18461
+ continue;
18462
+ }
18257
18463
  const { left } = glyph;
18258
18464
  const leftSide = divideLeft + left;
18259
18465
  const distance = Math.abs(offsetLeft - leftSide);
@@ -18263,11 +18469,12 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18263
18469
  }
18264
18470
  }
18265
18471
  }
18266
- if (nearestNode.glyph == null) return;
18472
+ const nearestGlyph = (_nearestNode$glyph = nearestNode.glyph) !== null && _nearestNode$glyph !== void 0 ? _nearestNode$glyph : nearestEmptyParagraphNode.glyph;
18473
+ if (nearestGlyph == null) return;
18267
18474
  const { segmentPage } = nodePosition;
18268
- return docSkeleton.findPositionByGlyph(nearestNode.glyph, segmentPage);
18475
+ return docSkeleton.findPositionByGlyph(nearestGlyph, segmentPage);
18269
18476
  }
18270
- _getNextOrPrevLine(glyph, direction, skipCellContent = false) {
18477
+ _getNextOrPrevLineTarget(glyph, direction, offsetLeft, skipCellContent = false) {
18271
18478
  const divide = glyph.parent;
18272
18479
  const line = divide === null || divide === void 0 ? void 0 : divide.parent;
18273
18480
  const column = line === null || line === void 0 ? void 0 : line.parent;
@@ -18277,26 +18484,25 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18277
18484
  const currentLineIndex = column.lines.indexOf(line);
18278
18485
  if (currentLineIndex === -1) return;
18279
18486
  let newLine;
18280
- if (page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL && skipCellContent) {
18281
- const nLine = findAboveOrBellowCellLine(page, direction);
18282
- if (nLine) return nLine;
18487
+ if (this._isTableCellContentPage(page) && skipCellContent) {
18488
+ const tableCellTarget = this._getAdjacentTableCellLineTarget(page, direction, offsetLeft);
18489
+ if (tableCellTarget != null) return tableCellTarget;
18283
18490
  }
18284
18491
  if (direction === true) {
18285
18492
  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
- }
18493
+ const tableTarget = this._getTableLineTargetFromPageLine(line, page, direction, offsetLeft);
18494
+ if (tableTarget != null) return tableTarget;
18291
18495
  } else {
18292
18496
  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
- }
18497
+ const tableTarget = this._getTableLineTargetFromPageLine(line, page, direction, offsetLeft);
18498
+ if (tableTarget != null) return tableTarget;
18298
18499
  }
18299
- if (newLine != null) return newLine;
18500
+ const columnGroupTarget = this._getColumnGroupLineTargetFromBlockLine(newLine, page, direction, offsetLeft);
18501
+ if (columnGroupTarget != null) return columnGroupTarget;
18502
+ if (newLine != null) return {
18503
+ line: newLine,
18504
+ offsetLeft
18505
+ };
18300
18506
  const currentColumnIndex = section.columns.indexOf(column);
18301
18507
  if (currentColumnIndex === -1) return;
18302
18508
  if (direction === true) {
@@ -18307,7 +18513,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18307
18513
  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
18514
  newLine = prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18309
18515
  }
18310
- if (newLine != null) return newLine;
18516
+ if (newLine != null) return {
18517
+ line: newLine,
18518
+ offsetLeft
18519
+ };
18311
18520
  const currentSectionIndex = page.sections.indexOf(section);
18312
18521
  if (currentSectionIndex === -1) return;
18313
18522
  if (direction === true) {
@@ -18320,8 +18529,15 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18320
18529
  const prevColumnLines = column === null || column === void 0 ? void 0 : column.lines;
18321
18530
  newLine = prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18322
18531
  }
18323
- if (newLine != null) return newLine;
18324
- if (page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL) return findAboveOrBellowCellLine(page, direction);
18532
+ if (newLine != null) return {
18533
+ line: newLine,
18534
+ offsetLeft
18535
+ };
18536
+ if (this._isColumnGroupContentPage(page)) {
18537
+ const exitTarget = this._getColumnGroupExitLineTarget(page, direction, offsetLeft);
18538
+ if (exitTarget != null) return exitTarget;
18539
+ }
18540
+ if (this._isTableCellContentPage(page)) return this._getAdjacentTableCellLineTarget(page, direction, offsetLeft);
18325
18541
  const skeleton = page.parent;
18326
18542
  if (skeleton == null) return;
18327
18543
  const currentPageIndex = skeleton.pages.indexOf(page);
@@ -18338,7 +18554,189 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
18338
18554
  const prevColumnLines = column === null || column === void 0 ? void 0 : column.lines;
18339
18555
  newLine = prevColumnLines[prevColumnLines.length - 1];
18340
18556
  }
18341
- if (newLine != null) return newLine;
18557
+ if (newLine != null) return {
18558
+ line: newLine,
18559
+ offsetLeft
18560
+ };
18561
+ }
18562
+ _getTableLineTargetFromPageLine(line, page, direction, offsetLeft) {
18563
+ const table = direction ? findTableAfterLine(line, page) : findTableBeforeLine(line, page);
18564
+ if (table == null) return;
18565
+ return this._getTableBoundaryLineTarget(table, direction, offsetLeft);
18566
+ }
18567
+ _getTableBoundaryLineTarget(table, direction, offsetLeft) {
18568
+ const rows = direction ? table.rows : [...table.rows].reverse();
18569
+ for (const row of rows) {
18570
+ if (row.isRepeatRow) continue;
18571
+ const target = this._getNearestTableCellLineTarget(row.cells, direction, offsetLeft);
18572
+ if (target != null) return target;
18573
+ }
18574
+ }
18575
+ _getAdjacentTableCellLineTarget(cell, direction, offsetLeft) {
18576
+ const row = cell.parent;
18577
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18578
+ if (row == null || table == null) return;
18579
+ const hostOffsetLeft = this._getTableCellHostOffsetLeft(cell) + offsetLeft;
18580
+ const adjacentRow = this._findAdjacentTableRow(table, row, direction);
18581
+ if (adjacentRow != null) return this._getNearestTableCellLineTarget(adjacentRow.cells, direction, hostOffsetLeft);
18582
+ const line = this._findLineAroundTable(table, direction);
18583
+ if (line == null) return;
18584
+ return {
18585
+ line,
18586
+ offsetLeft: hostOffsetLeft
18587
+ };
18588
+ }
18589
+ _findAdjacentTableRow(table, row, direction) {
18590
+ const currentRowIndex = table.rows.indexOf(row);
18591
+ if (currentRowIndex === -1) return;
18592
+ const step = direction ? 1 : -1;
18593
+ let rowIndex = currentRowIndex + step;
18594
+ while (rowIndex >= 0 && rowIndex < table.rows.length) {
18595
+ const adjacentRow = table.rows[rowIndex];
18596
+ if (!adjacentRow.isRepeatRow) return adjacentRow;
18597
+ rowIndex += step;
18598
+ }
18599
+ return this._findAdjacentTableSliceRow(table, direction);
18600
+ }
18601
+ _findAdjacentTableSliceRow(table, direction) {
18602
+ if (!table.tableId.includes("#-#")) return;
18603
+ const [sourceTableId, sliceIndexText] = table.tableId.split("#-#");
18604
+ const sliceIndex = Number.parseInt(sliceIndexText);
18605
+ const tablePage = table.parent;
18606
+ const skeleton = tablePage === null || tablePage === void 0 ? void 0 : tablePage.parent;
18607
+ if (!Number.isFinite(sliceIndex) || (skeleton === null || skeleton === void 0 ? void 0 : skeleton.pages) == null) return;
18608
+ const nextTableId = `${sourceTableId}#-#${sliceIndex + (direction ? 1 : -1)}`;
18609
+ for (const page of skeleton.pages) {
18610
+ var _page$skeTables;
18611
+ const nextTable = (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 ? void 0 : _page$skeTables.get(nextTableId);
18612
+ const row = (nextTable == null ? [] : direction ? nextTable.rows : [...nextTable.rows].reverse()).find((item) => !item.isRepeatRow);
18613
+ if (row != null) return row;
18614
+ }
18615
+ }
18616
+ _getNearestTableCellLineTarget(cells, direction, hostOffsetLeft) {
18617
+ const candidates = cells.filter((cell) => !cell.isMergedCellCovered).map((cell) => ({
18618
+ cell,
18619
+ distance: this._getDistanceToTableCell(cell, hostOffsetLeft)
18620
+ })).sort((a, b) => a.distance - b.distance);
18621
+ for (const candidate of candidates) {
18622
+ const line = direction ? firstLineInCell(candidate.cell) : lastLineInCell(candidate.cell);
18623
+ if (line != null) return {
18624
+ line,
18625
+ offsetLeft: hostOffsetLeft - this._getTableCellHostOffsetLeft(candidate.cell)
18626
+ };
18627
+ }
18628
+ }
18629
+ _findLineAroundTable(table, direction) {
18630
+ var _pages, _tablePage$parent;
18631
+ const tablePage = table.parent;
18632
+ if (tablePage == null) return;
18633
+ const pages = (_pages = (_tablePage$parent = tablePage.parent) === null || _tablePage$parent === void 0 ? void 0 : _tablePage$parent.pages) !== null && _pages !== void 0 ? _pages : [tablePage];
18634
+ const lineMatcher = direction ? (line) => line.st === table.ed + 1 : (line) => line.ed === table.st - 1;
18635
+ for (const page of pages) for (const section of page.sections) for (const column of section.columns) {
18636
+ const line = (direction ? column.lines : [...column.lines].reverse()).find(lineMatcher);
18637
+ if (line != null) return line;
18638
+ }
18639
+ }
18640
+ _getDistanceToTableCell(cell, offsetLeft) {
18641
+ const left = this._getTableCellHostOffsetLeft(cell);
18642
+ const right = left + this._getTableCellContentWidth(cell);
18643
+ if (offsetLeft >= left && offsetLeft <= right) return 0;
18644
+ return Math.min(Math.abs(offsetLeft - left), Math.abs(offsetLeft - right));
18645
+ }
18646
+ _getTableCellHostOffsetLeft(cell) {
18647
+ var _table$left, _cell$left, _cell$marginLeft;
18648
+ const row = cell.parent;
18649
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18650
+ 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);
18651
+ }
18652
+ _getTableCellContentWidth(cell) {
18653
+ var _cell$pageWidth, _cell$marginLeft2, _cell$marginRight;
18654
+ 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));
18655
+ }
18656
+ _isTableCellContentPage(page) {
18657
+ var _table$rows;
18658
+ const row = page.parent;
18659
+ const table = row === null || row === void 0 ? void 0 : row.parent;
18660
+ 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);
18661
+ }
18662
+ _getColumnGroupLineTargetFromBlockLine(line, page, direction, offsetLeft) {
18663
+ if (line == null || line.type !== _univerjs_engine_render.LineType.BLOCK) return;
18664
+ const columnGroup = this._findColumnGroupByBlockLine(page, line);
18665
+ if (columnGroup == null) return;
18666
+ return this._getColumnGroupContentLineTarget(columnGroup, direction, offsetLeft);
18667
+ }
18668
+ _getColumnGroupContentLineTarget(columnGroup, direction, offsetLeft) {
18669
+ const candidates = columnGroup.columns.map((column) => ({
18670
+ column,
18671
+ distance: this._getDistanceToColumnGroupColumn(column, offsetLeft)
18672
+ })).sort((a, b) => a.distance - b.distance);
18673
+ for (const candidate of candidates) {
18674
+ const line = this._getColumnGroupColumnBoundaryLine(candidate.column, direction);
18675
+ if (line != null) return {
18676
+ line,
18677
+ offsetLeft: offsetLeft - candidate.column.left
18678
+ };
18679
+ }
18680
+ }
18681
+ _getColumnGroupExitLineTarget(page, direction, offsetLeft) {
18682
+ const columnGroupColumn = page.parent;
18683
+ const columnGroup = columnGroupColumn === null || columnGroupColumn === void 0 ? void 0 : columnGroupColumn.parent;
18684
+ const hostPage = columnGroup === null || columnGroup === void 0 ? void 0 : columnGroup.parent;
18685
+ if (columnGroupColumn == null || columnGroup == null || hostPage == null) return;
18686
+ const blockLine = this._findColumnGroupBlockLine(columnGroup);
18687
+ const line = blockLine == null ? void 0 : this._getAdjacentLineAroundBlockLine(blockLine, direction);
18688
+ if (line == null) return;
18689
+ return {
18690
+ line,
18691
+ offsetLeft: columnGroupColumn.left + offsetLeft
18692
+ };
18693
+ }
18694
+ _findColumnGroupByBlockLine(page, line) {
18695
+ var _page$skeColumnGroups, _page$skeColumnGroups2;
18696
+ 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;
18697
+ }
18698
+ _findColumnGroupBlockLine(columnGroup) {
18699
+ const page = columnGroup.parent;
18700
+ if (page == null) return;
18701
+ 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;
18702
+ }
18703
+ _getAdjacentLineAroundBlockLine(line, direction) {
18704
+ var _section$columns4;
18705
+ const column = line.parent;
18706
+ const section = column === null || column === void 0 ? void 0 : column.parent;
18707
+ const page = section === null || section === void 0 ? void 0 : section.parent;
18708
+ if (column == null || section == null || page == null) return;
18709
+ const lineIndex = column.lines.indexOf(line);
18710
+ if (lineIndex === -1) return;
18711
+ const sameColumnLine = column.lines[direction ? lineIndex + 1 : lineIndex - 1];
18712
+ if (sameColumnLine != null) return sameColumnLine;
18713
+ const columnIndex = section.columns.indexOf(column);
18714
+ if (columnIndex === -1) return;
18715
+ if (direction) {
18716
+ var _section$columns3;
18717
+ return (_section$columns3 = section.columns[columnIndex + 1]) === null || _section$columns3 === void 0 ? void 0 : _section$columns3.lines[0];
18718
+ }
18719
+ const prevColumnLines = (_section$columns4 = section.columns[columnIndex - 1]) === null || _section$columns4 === void 0 ? void 0 : _section$columns4.lines;
18720
+ return prevColumnLines === null || prevColumnLines === void 0 ? void 0 : prevColumnLines[prevColumnLines.length - 1];
18721
+ }
18722
+ _getColumnGroupColumnBoundaryLine(column, direction) {
18723
+ const sections = direction ? column.page.sections : [...column.page.sections].reverse();
18724
+ for (const section of sections) {
18725
+ const columns = direction ? section.columns : [...section.columns].reverse();
18726
+ for (const skeletonColumn of columns) {
18727
+ const line = (direction ? skeletonColumn.lines : [...skeletonColumn.lines].reverse()).find((item) => item.type !== _univerjs_engine_render.LineType.BLOCK);
18728
+ if (line != null) return line;
18729
+ }
18730
+ }
18731
+ }
18732
+ _getDistanceToColumnGroupColumn(column, offsetLeft) {
18733
+ if (offsetLeft >= column.left && offsetLeft <= column.left + column.width) return 0;
18734
+ return Math.min(Math.abs(offsetLeft - column.left), Math.abs(offsetLeft - column.left - column.width));
18735
+ }
18736
+ _isColumnGroupContentPage(page) {
18737
+ var _parent$parent;
18738
+ const parent = page.parent;
18739
+ 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
18740
  }
18343
18741
  _scrollToFocusNodePosition(unitId, offset) {
18344
18742
  var _this$_renderManagerS3;
@@ -18360,27 +18758,6 @@ DocMoveCursorController = __decorate([
18360
18758
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
18361
18759
  __decorateParam(3, _univerjs_core.ICommandService)
18362
18760
  ], 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
18761
 
18385
18762
  //#endregion
18386
18763
  //#region src/controllers/doc-table.controller.ts
@@ -19360,6 +19737,10 @@ const MoveCursorWordLeftShortcut = moveCursorShortcut(_univerjs_core.Direction.L
19360
19737
  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
19738
  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
19739
  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);
19740
+ 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);
19741
+ 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);
19742
+ 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);
19743
+ 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
19744
  const SelectAllShortcut = {
19364
19745
  id: DocSelectAllCommand.id,
19365
19746
  binding: _univerjs_ui.KeyCode.A | _univerjs_ui.MetaKeys.CTRL_COMMAND,
@@ -19531,6 +19912,10 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19531
19912
  MoveCursorLineEndShortcut,
19532
19913
  MoveSelectionLineStartShortcut,
19533
19914
  MoveSelectionLineEndShortcut,
19915
+ MoveCursorParagraphUpShortcut,
19916
+ MoveCursorParagraphDownShortcut,
19917
+ MoveSelectionParagraphUpShortcut,
19918
+ MoveSelectionParagraphDownShortcut,
19534
19919
  MoveCursorDocumentStartShortcut,
19535
19920
  MoveCursorDocumentEndShortcut,
19536
19921
  MoveSelectionDocumentStartShortcut,
@@ -19568,6 +19953,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
19568
19953
  [DocParagraphSettingController],
19569
19954
  [IEditorService, { useClass: EditorService }],
19570
19955
  [IDocClipboardService, { useClass: DocClipboardService }],
19956
+ [DocHtmlExportService],
19571
19957
  [DocCanvasPopManagerService],
19572
19958
  [DocsRenderService],
19573
19959
  [_univerjs_docs.IDocStateChangeInterceptorService, { useClass: DocIMEStateChangeInterceptorService }],
@@ -20253,6 +20639,7 @@ Object.defineProperty(exports, 'DocEventManagerService', {
20253
20639
  return DocEventManagerService;
20254
20640
  }
20255
20641
  });
20642
+ exports.DocHtmlExportService = DocHtmlExportService;
20256
20643
  exports.DocIMEInputManagerService = DocIMEInputManagerService;
20257
20644
  Object.defineProperty(exports, 'DocParagraphMenuService', {
20258
20645
  enumerable: true,