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

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